summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes24
-rw-r--r--.hooks-config.bash18
-rw-r--r--Auxiliary/CMakeLists.txt4
-rw-r--r--Auxiliary/bash-completion/CMakeLists.txt8
-rw-r--r--Auxiliary/bash-completion/cmake151
-rw-r--r--Auxiliary/bash-completion/cpack61
-rw-r--r--Auxiliary/bash-completion/ctest85
-rw-r--r--Auxiliary/cmake-help.vim21
-rw-r--r--Auxiliary/cmake-indent.vim93
-rw-r--r--Auxiliary/cmake-mode.el405
-rw-r--r--Auxiliary/cmake-syntax.vim89
-rw-r--r--Auxiliary/cmake.m453
-rw-r--r--CMakeCPack.cmake148
-rw-r--r--CMakeCPackOptions.cmake.in90
-rw-r--r--CMakeGraphVizOptions.cmake1
-rw-r--r--CMakeLists.txt650
-rw-r--r--CMakeLogo.gifbin0 -> 4481 bytes
-rw-r--r--CONTRIBUTING.rst34
-rw-r--r--CTestConfig.cmake20
-rw-r--r--CTestCustom.cmake.in93
-rw-r--r--CompileFlags.cmake83
-rw-r--r--Copyright.txt37
-rw-r--r--DartConfig.cmake18
-rw-r--r--Help/command/FIND_XXX.txt101
-rw-r--r--Help/command/FIND_XXX_MAC.txt24
-rw-r--r--Help/command/FIND_XXX_ORDER.txt12
-rw-r--r--Help/command/FIND_XXX_ROOT.txt23
-rw-r--r--Help/command/add_compile_options.rst22
-rw-r--r--Help/command/add_custom_command.rst169
-rw-r--r--Help/command/add_custom_target.rst45
-rw-r--r--Help/command/add_definitions.rst25
-rw-r--r--Help/command/add_dependencies.rst19
-rw-r--r--Help/command/add_executable.rst80
-rw-r--r--Help/command/add_library.rst151
-rw-r--r--Help/command/add_subdirectory.rst36
-rw-r--r--Help/command/add_test.rst59
-rw-r--r--Help/command/aux_source_directory.rst24
-rw-r--r--Help/command/break.rst10
-rw-r--r--Help/command/build_command.rst44
-rw-r--r--Help/command/build_name.rst14
-rw-r--r--Help/command/cmake_host_system_information.rst25
-rw-r--r--Help/command/cmake_minimum_required.rst30
-rw-r--r--Help/command/cmake_policy.rst94
-rw-r--r--Help/command/configure_file.rst46
-rw-r--r--Help/command/create_test_sourcelist.rst30
-rw-r--r--Help/command/ctest_build.rst29
-rw-r--r--Help/command/ctest_configure.rst21
-rw-r--r--Help/command/ctest_coverage.rst20
-rw-r--r--Help/command/ctest_empty_binary_directory.rst12
-rw-r--r--Help/command/ctest_memcheck.rst28
-rw-r--r--Help/command/ctest_read_custom_files.rst11
-rw-r--r--Help/command/ctest_run_script.rst15
-rw-r--r--Help/command/ctest_sleep.rst16
-rw-r--r--Help/command/ctest_start.rst24
-rw-r--r--Help/command/ctest_submit.rst35
-rw-r--r--Help/command/ctest_test.rst33
-rw-r--r--Help/command/ctest_update.rst13
-rw-r--r--Help/command/ctest_upload.rst11
-rw-r--r--Help/command/define_property.rst45
-rw-r--r--Help/command/else.rst10
-rw-r--r--Help/command/elseif.rst10
-rw-r--r--Help/command/enable_language.rst22
-rw-r--r--Help/command/enable_testing.rst13
-rw-r--r--Help/command/endforeach.rst10
-rw-r--r--Help/command/endfunction.rst10
-rw-r--r--Help/command/endif.rst10
-rw-r--r--Help/command/endmacro.rst10
-rw-r--r--Help/command/endwhile.rst10
-rw-r--r--Help/command/exec_program.rst24
-rw-r--r--Help/command/execute_process.rst75
-rw-r--r--Help/command/export.rst57
-rw-r--r--Help/command/export_library_dependencies.rst28
-rw-r--r--Help/command/file.rst307
-rw-r--r--Help/command/find_file.rst27
-rw-r--r--Help/command/find_library.rst44
-rw-r--r--Help/command/find_package.rst349
-rw-r--r--Help/command/find_path.rst32
-rw-r--r--Help/command/find_program.rst25
-rw-r--r--Help/command/fltk_wrap_ui.rst14
-rw-r--r--Help/command/foreach.rst47
-rw-r--r--Help/command/function.rst31
-rw-r--r--Help/command/get_cmake_property.rst15
-rw-r--r--Help/command/get_directory_property.rst24
-rw-r--r--Help/command/get_filename_component.rst37
-rw-r--r--Help/command/get_property.rst49
-rw-r--r--Help/command/get_source_file_property.rst16
-rw-r--r--Help/command/get_target_property.rst18
-rw-r--r--Help/command/get_test_property.rst15
-rw-r--r--Help/command/if.rst207
-rw-r--r--Help/command/include.rst25
-rw-r--r--Help/command/include_directories.rst35
-rw-r--r--Help/command/include_external_msproject.rst23
-rw-r--r--Help/command/include_regular_expression.rst18
-rw-r--r--Help/command/install.rst341
-rw-r--r--Help/command/install_files.rst39
-rw-r--r--Help/command/install_programs.rst33
-rw-r--r--Help/command/install_targets.rst17
-rw-r--r--Help/command/link_directories.rst19
-rw-r--r--Help/command/link_libraries.rst16
-rw-r--r--Help/command/list.rst61
-rw-r--r--Help/command/load_cache.rst27
-rw-r--r--Help/command/load_command.rst23
-rw-r--r--Help/command/macro.rst67
-rw-r--r--Help/command/make_directory.rst12
-rw-r--r--Help/command/mark_as_advanced.rst19
-rw-r--r--Help/command/math.rst13
-rw-r--r--Help/command/message.rst33
-rw-r--r--Help/command/option.rst15
-rw-r--r--Help/command/output_required_files.rst19
-rw-r--r--Help/command/project.rst57
-rw-r--r--Help/command/qt_wrap_cpp.rst12
-rw-r--r--Help/command/qt_wrap_ui.rst14
-rw-r--r--Help/command/remove.rst12
-rw-r--r--Help/command/remove_definitions.rst11
-rw-r--r--Help/command/return.rst18
-rw-r--r--Help/command/separate_arguments.rst31
-rw-r--r--Help/command/set.rst116
-rw-r--r--Help/command/set_directory_properties.rst15
-rw-r--r--Help/command/set_property.rst43
-rw-r--r--Help/command/set_source_files_properties.rst15
-rw-r--r--Help/command/set_target_properties.rst104
-rw-r--r--Help/command/set_tests_properties.rst36
-rw-r--r--Help/command/site_name.rst8
-rw-r--r--Help/command/source_group.rst44
-rw-r--r--Help/command/string.rst173
-rw-r--r--Help/command/subdir_depends.rst13
-rw-r--r--Help/command/subdirs.rst24
-rw-r--r--Help/command/target_compile_definitions.rst28
-rw-r--r--Help/command/target_compile_features.rst32
-rw-r--r--Help/command/target_compile_options.rst37
-rw-r--r--Help/command/target_include_directories.rst56
-rw-r--r--Help/command/target_link_libraries.rst152
-rw-r--r--Help/command/target_sources.rst28
-rw-r--r--Help/command/try_compile.rst72
-rw-r--r--Help/command/try_run.rst52
-rw-r--r--Help/command/unset.rst25
-rw-r--r--Help/command/use_mangled_mesa.rst15
-rw-r--r--Help/command/utility_source.rst24
-rw-r--r--Help/command/variable_requires.rst22
-rw-r--r--Help/command/variable_watch.rst13
-rw-r--r--Help/command/while.rst17
-rw-r--r--Help/command/write_file.rst20
-rw-r--r--Help/generator/Borland Makefiles.rst4
-rw-r--r--Help/generator/CodeBlocks.rst25
-rw-r--r--Help/generator/CodeLite.rst24
-rw-r--r--Help/generator/Eclipse CDT4.rst25
-rw-r--r--Help/generator/KDevelop3.rst25
-rw-r--r--Help/generator/Kate.rst26
-rw-r--r--Help/generator/MSYS Makefiles.rst7
-rw-r--r--Help/generator/MinGW Makefiles.rst7
-rw-r--r--Help/generator/NMake Makefiles JOM.rst4
-rw-r--r--Help/generator/NMake Makefiles.rst4
-rw-r--r--Help/generator/Ninja.rst8
-rw-r--r--Help/generator/Sublime Text 2.rst25
-rw-r--r--Help/generator/Unix Makefiles.rst8
-rw-r--r--Help/generator/Visual Studio 10 2010.rst19
-rw-r--r--Help/generator/Visual Studio 11 2012.rst22
-rw-r--r--Help/generator/Visual Studio 12 2013.rst19
-rw-r--r--Help/generator/Visual Studio 14.rst16
-rw-r--r--Help/generator/Visual Studio 6.rst4
-rw-r--r--Help/generator/Visual Studio 7 .NET 2003.rst4
-rw-r--r--Help/generator/Visual Studio 7.rst4
-rw-r--r--Help/generator/Visual Studio 8 2005.rst16
-rw-r--r--Help/generator/Visual Studio 9 2008.rst19
-rw-r--r--Help/generator/Watcom WMake.rst4
-rw-r--r--Help/generator/Xcode.rst4
-rw-r--r--Help/include/COMPILE_DEFINITIONS_DISCLAIMER.txt18
-rw-r--r--Help/index.rst59
-rw-r--r--Help/manual/LINKS.txt25
-rw-r--r--Help/manual/OPTIONS_BUILD.txt75
-rw-r--r--Help/manual/OPTIONS_HELP.txt136
-rw-r--r--Help/manual/ccmake.1.rst37
-rw-r--r--Help/manual/cmake-buildsystem.7.rst889
-rw-r--r--Help/manual/cmake-commands.7.rst153
-rw-r--r--Help/manual/cmake-compile-features.7.rst294
-rw-r--r--Help/manual/cmake-developer.7.rst1144
-rw-r--r--Help/manual/cmake-generator-expressions.7.rst226
-rw-r--r--Help/manual/cmake-generators.7.rst87
-rw-r--r--Help/manual/cmake-gui.1.rst35
-rw-r--r--Help/manual/cmake-language.7.rst490
-rw-r--r--Help/manual/cmake-modules.7.rst239
-rw-r--r--Help/manual/cmake-packages.7.rst634
-rw-r--r--Help/manual/cmake-policies.7.rst108
-rw-r--r--Help/manual/cmake-properties.7.rst349
-rw-r--r--Help/manual/cmake-qt.7.rst187
-rw-r--r--Help/manual/cmake-toolchains.7.rst242
-rw-r--r--Help/manual/cmake-variables.7.rst388
-rw-r--r--Help/manual/cmake.1.rst162
-rw-r--r--Help/manual/cpack.1.rst97
-rw-r--r--Help/manual/ctest.1.rst993
-rw-r--r--Help/module/AddFileDependencies.rst1
-rw-r--r--Help/module/BundleUtilities.rst1
-rw-r--r--Help/module/CMakeAddFortranSubdirectory.rst1
-rw-r--r--Help/module/CMakeBackwardCompatibilityCXX.rst1
-rw-r--r--Help/module/CMakeDependentOption.rst1
-rw-r--r--Help/module/CMakeDetermineVSServicePack.rst1
-rw-r--r--Help/module/CMakeExpandImportedTargets.rst1
-rw-r--r--Help/module/CMakeFindDependencyMacro.rst1
-rw-r--r--Help/module/CMakeFindFrameworks.rst1
-rw-r--r--Help/module/CMakeFindPackageMode.rst1
-rw-r--r--Help/module/CMakeForceCompiler.rst1
-rw-r--r--Help/module/CMakeGraphVizOptions.rst1
-rw-r--r--Help/module/CMakePackageConfigHelpers.rst1
-rw-r--r--Help/module/CMakeParseArguments.rst1
-rw-r--r--Help/module/CMakePrintHelpers.rst1
-rw-r--r--Help/module/CMakePrintSystemInformation.rst1
-rw-r--r--Help/module/CMakePushCheckState.rst1
-rw-r--r--Help/module/CMakeVerifyManifest.rst1
-rw-r--r--Help/module/CPack.rst1
-rw-r--r--Help/module/CPackBundle.rst1
-rw-r--r--Help/module/CPackComponent.rst1
-rw-r--r--Help/module/CPackCygwin.rst1
-rw-r--r--Help/module/CPackDMG.rst1
-rw-r--r--Help/module/CPackDeb.rst1
-rw-r--r--Help/module/CPackIFW.rst1
-rw-r--r--Help/module/CPackNSIS.rst1
-rw-r--r--Help/module/CPackPackageMaker.rst1
-rw-r--r--Help/module/CPackRPM.rst1
-rw-r--r--Help/module/CPackWIX.rst1
-rw-r--r--Help/module/CTest.rst1
-rw-r--r--Help/module/CTestScriptMode.rst1
-rw-r--r--Help/module/CTestUseLaunchers.rst1
-rw-r--r--Help/module/CheckCCompilerFlag.rst1
-rw-r--r--Help/module/CheckCSourceCompiles.rst1
-rw-r--r--Help/module/CheckCSourceRuns.rst1
-rw-r--r--Help/module/CheckCXXCompilerFlag.rst1
-rw-r--r--Help/module/CheckCXXSourceCompiles.rst1
-rw-r--r--Help/module/CheckCXXSourceRuns.rst1
-rw-r--r--Help/module/CheckCXXSymbolExists.rst1
-rw-r--r--Help/module/CheckFortranFunctionExists.rst1
-rw-r--r--Help/module/CheckFortranSourceCompiles.rst1
-rw-r--r--Help/module/CheckFunctionExists.rst1
-rw-r--r--Help/module/CheckIncludeFile.rst1
-rw-r--r--Help/module/CheckIncludeFileCXX.rst1
-rw-r--r--Help/module/CheckIncludeFiles.rst1
-rw-r--r--Help/module/CheckLanguage.rst1
-rw-r--r--Help/module/CheckLibraryExists.rst1
-rw-r--r--Help/module/CheckPrototypeDefinition.rst1
-rw-r--r--Help/module/CheckStructHasMember.rst1
-rw-r--r--Help/module/CheckSymbolExists.rst1
-rw-r--r--Help/module/CheckTypeSize.rst1
-rw-r--r--Help/module/CheckVariableExists.rst1
-rw-r--r--Help/module/Dart.rst1
-rw-r--r--Help/module/DeployQt4.rst1
-rw-r--r--Help/module/Documentation.rst1
-rw-r--r--Help/module/ExternalData.rst1
-rw-r--r--Help/module/ExternalProject.rst1
-rw-r--r--Help/module/FeatureSummary.rst1
-rw-r--r--Help/module/FindALSA.rst1
-rw-r--r--Help/module/FindASPELL.rst1
-rw-r--r--Help/module/FindAVIFile.rst1
-rw-r--r--Help/module/FindArmadillo.rst1
-rw-r--r--Help/module/FindBISON.rst1
-rw-r--r--Help/module/FindBLAS.rst1
-rw-r--r--Help/module/FindBZip2.rst1
-rw-r--r--Help/module/FindBacktrace.rst1
-rw-r--r--Help/module/FindBoost.rst1
-rw-r--r--Help/module/FindBullet.rst1
-rw-r--r--Help/module/FindCABLE.rst1
-rw-r--r--Help/module/FindCUDA.rst1
-rw-r--r--Help/module/FindCURL.rst1
-rw-r--r--Help/module/FindCVS.rst1
-rw-r--r--Help/module/FindCoin3D.rst1
-rw-r--r--Help/module/FindCups.rst1
-rw-r--r--Help/module/FindCurses.rst1
-rw-r--r--Help/module/FindCxxTest.rst1
-rw-r--r--Help/module/FindCygwin.rst1
-rw-r--r--Help/module/FindDCMTK.rst1
-rw-r--r--Help/module/FindDart.rst1
-rw-r--r--Help/module/FindDevIL.rst1
-rw-r--r--Help/module/FindDoxygen.rst1
-rw-r--r--Help/module/FindEXPAT.rst1
-rw-r--r--Help/module/FindFLEX.rst1
-rw-r--r--Help/module/FindFLTK.rst1
-rw-r--r--Help/module/FindFLTK2.rst1
-rw-r--r--Help/module/FindFreetype.rst1
-rw-r--r--Help/module/FindGCCXML.rst1
-rw-r--r--Help/module/FindGDAL.rst1
-rw-r--r--Help/module/FindGIF.rst1
-rw-r--r--Help/module/FindGLEW.rst1
-rw-r--r--Help/module/FindGLUT.rst1
-rw-r--r--Help/module/FindGTK.rst1
-rw-r--r--Help/module/FindGTK2.rst1
-rw-r--r--Help/module/FindGTest.rst1
-rw-r--r--Help/module/FindGettext.rst1
-rw-r--r--Help/module/FindGit.rst1
-rw-r--r--Help/module/FindGnuTLS.rst1
-rw-r--r--Help/module/FindGnuplot.rst1
-rw-r--r--Help/module/FindHDF5.rst1
-rw-r--r--Help/module/FindHSPELL.rst1
-rw-r--r--Help/module/FindHTMLHelp.rst1
-rw-r--r--Help/module/FindHg.rst1
-rw-r--r--Help/module/FindITK.rst10
-rw-r--r--Help/module/FindIce.rst1
-rw-r--r--Help/module/FindIcotool.rst1
-rw-r--r--Help/module/FindImageMagick.rst1
-rw-r--r--Help/module/FindJNI.rst1
-rw-r--r--Help/module/FindJPEG.rst1
-rw-r--r--Help/module/FindJasper.rst1
-rw-r--r--Help/module/FindJava.rst1
-rw-r--r--Help/module/FindKDE3.rst1
-rw-r--r--Help/module/FindKDE4.rst1
-rw-r--r--Help/module/FindLAPACK.rst1
-rw-r--r--Help/module/FindLATEX.rst1
-rw-r--r--Help/module/FindLibArchive.rst1
-rw-r--r--Help/module/FindLibLZMA.rst1
-rw-r--r--Help/module/FindLibXml2.rst1
-rw-r--r--Help/module/FindLibXslt.rst1
-rw-r--r--Help/module/FindLua.rst1
-rw-r--r--Help/module/FindLua50.rst1
-rw-r--r--Help/module/FindLua51.rst1
-rw-r--r--Help/module/FindMFC.rst1
-rw-r--r--Help/module/FindMPEG.rst1
-rw-r--r--Help/module/FindMPEG2.rst1
-rw-r--r--Help/module/FindMPI.rst1
-rw-r--r--Help/module/FindMatlab.rst1
-rw-r--r--Help/module/FindMotif.rst1
-rw-r--r--Help/module/FindOpenAL.rst1
-rw-r--r--Help/module/FindOpenCL.rst1
-rw-r--r--Help/module/FindOpenGL.rst1
-rw-r--r--Help/module/FindOpenMP.rst1
-rw-r--r--Help/module/FindOpenSSL.rst1
-rw-r--r--Help/module/FindOpenSceneGraph.rst1
-rw-r--r--Help/module/FindOpenThreads.rst1
-rw-r--r--Help/module/FindPHP4.rst1
-rw-r--r--Help/module/FindPNG.rst1
-rw-r--r--Help/module/FindPackageHandleStandardArgs.rst1
-rw-r--r--Help/module/FindPackageMessage.rst1
-rw-r--r--Help/module/FindPerl.rst1
-rw-r--r--Help/module/FindPerlLibs.rst1
-rw-r--r--Help/module/FindPhysFS.rst1
-rw-r--r--Help/module/FindPike.rst1
-rw-r--r--Help/module/FindPkgConfig.rst1
-rw-r--r--Help/module/FindPostgreSQL.rst1
-rw-r--r--Help/module/FindProducer.rst1
-rw-r--r--Help/module/FindProtobuf.rst1
-rw-r--r--Help/module/FindPythonInterp.rst1
-rw-r--r--Help/module/FindPythonLibs.rst1
-rw-r--r--Help/module/FindQt.rst1
-rw-r--r--Help/module/FindQt3.rst1
-rw-r--r--Help/module/FindQt4.rst1
-rw-r--r--Help/module/FindQuickTime.rst1
-rw-r--r--Help/module/FindRTI.rst1
-rw-r--r--Help/module/FindRuby.rst1
-rw-r--r--Help/module/FindSDL.rst1
-rw-r--r--Help/module/FindSDL_image.rst1
-rw-r--r--Help/module/FindSDL_mixer.rst1
-rw-r--r--Help/module/FindSDL_net.rst1
-rw-r--r--Help/module/FindSDL_sound.rst1
-rw-r--r--Help/module/FindSDL_ttf.rst1
-rw-r--r--Help/module/FindSWIG.rst1
-rw-r--r--Help/module/FindSelfPackers.rst1
-rw-r--r--Help/module/FindSquish.rst1
-rw-r--r--Help/module/FindSubversion.rst1
-rw-r--r--Help/module/FindTCL.rst1
-rw-r--r--Help/module/FindTIFF.rst1
-rw-r--r--Help/module/FindTclStub.rst1
-rw-r--r--Help/module/FindTclsh.rst1
-rw-r--r--Help/module/FindThreads.rst1
-rw-r--r--Help/module/FindUnixCommands.rst1
-rw-r--r--Help/module/FindVTK.rst10
-rw-r--r--Help/module/FindWget.rst1
-rw-r--r--Help/module/FindWish.rst1
-rw-r--r--Help/module/FindX11.rst1
-rw-r--r--Help/module/FindXMLRPC.rst1
-rw-r--r--Help/module/FindXerces.rst1
-rw-r--r--Help/module/FindZLIB.rst1
-rw-r--r--Help/module/Findosg.rst1
-rw-r--r--Help/module/FindosgAnimation.rst1
-rw-r--r--Help/module/FindosgDB.rst1
-rw-r--r--Help/module/FindosgFX.rst1
-rw-r--r--Help/module/FindosgGA.rst1
-rw-r--r--Help/module/FindosgIntrospection.rst1
-rw-r--r--Help/module/FindosgManipulator.rst1
-rw-r--r--Help/module/FindosgParticle.rst1
-rw-r--r--Help/module/FindosgPresentation.rst1
-rw-r--r--Help/module/FindosgProducer.rst1
-rw-r--r--Help/module/FindosgQt.rst1
-rw-r--r--Help/module/FindosgShadow.rst1
-rw-r--r--Help/module/FindosgSim.rst1
-rw-r--r--Help/module/FindosgTerrain.rst1
-rw-r--r--Help/module/FindosgText.rst1
-rw-r--r--Help/module/FindosgUtil.rst1
-rw-r--r--Help/module/FindosgViewer.rst1
-rw-r--r--Help/module/FindosgVolume.rst1
-rw-r--r--Help/module/FindosgWidget.rst1
-rw-r--r--Help/module/Findosg_functions.rst1
-rw-r--r--Help/module/FindwxWidgets.rst1
-rw-r--r--Help/module/FindwxWindows.rst1
-rw-r--r--Help/module/FortranCInterface.rst1
-rw-r--r--Help/module/GNUInstallDirs.rst1
-rw-r--r--Help/module/GenerateExportHeader.rst1
-rw-r--r--Help/module/GetPrerequisites.rst1
-rw-r--r--Help/module/InstallRequiredSystemLibraries.rst1
-rw-r--r--Help/module/MacroAddFileDependencies.rst1
-rw-r--r--Help/module/ProcessorCount.rst1
-rw-r--r--Help/module/SelectLibraryConfigurations.rst1
-rw-r--r--Help/module/SquishTestScript.rst1
-rw-r--r--Help/module/TestBigEndian.rst1
-rw-r--r--Help/module/TestCXXAcceptsFlag.rst1
-rw-r--r--Help/module/TestForANSIForScope.rst1
-rw-r--r--Help/module/TestForANSIStreamHeaders.rst1
-rw-r--r--Help/module/TestForSSTREAM.rst1
-rw-r--r--Help/module/TestForSTDNamespace.rst1
-rw-r--r--Help/module/UseEcos.rst1
-rw-r--r--Help/module/UseJava.rst1
-rw-r--r--Help/module/UseJavaClassFilelist.rst1
-rw-r--r--Help/module/UseJavaSymlinks.rst1
-rw-r--r--Help/module/UsePkgConfig.rst1
-rw-r--r--Help/module/UseSWIG.rst1
-rw-r--r--Help/module/Use_wxWindows.rst1
-rw-r--r--Help/module/UsewxWidgets.rst1
-rw-r--r--Help/module/WriteBasicConfigVersionFile.rst1
-rw-r--r--Help/module/WriteCompilerDetectionHeader.rst1
-rw-r--r--Help/policy/CMP0000.rst30
-rw-r--r--Help/policy/CMP0001.rst19
-rw-r--r--Help/policy/CMP0002.rst26
-rw-r--r--Help/policy/CMP0003.rst102
-rw-r--r--Help/policy/CMP0004.rst23
-rw-r--r--Help/policy/CMP0005.rst24
-rw-r--r--Help/policy/CMP0006.rst22
-rw-r--r--Help/policy/CMP0007.rst15
-rw-r--r--Help/policy/CMP0008.rst32
-rw-r--r--Help/policy/CMP0009.rst19
-rw-r--r--Help/policy/CMP0010.rst18
-rw-r--r--Help/policy/CMP0011.rst22
-rw-r--r--Help/policy/CMP0012.rst25
-rw-r--r--Help/policy/CMP0013.rst19
-rw-r--r--Help/policy/CMP0014.rst15
-rw-r--r--Help/policy/CMP0015.rst17
-rw-r--r--Help/policy/CMP0016.rst13
-rw-r--r--Help/policy/CMP0017.rst19
-rw-r--r--Help/policy/CMP0018.rst32
-rw-r--r--Help/policy/CMP0019.rst20
-rw-r--r--Help/policy/CMP0020.rst25
-rw-r--r--Help/policy/CMP0021.rst18
-rw-r--r--Help/policy/CMP0022.rst37
-rw-r--r--Help/policy/CMP0023.rst33
-rw-r--r--Help/policy/CMP0024.rst22
-rw-r--r--Help/policy/CMP0025.rst27
-rw-r--r--Help/policy/CMP0026.rst26
-rw-r--r--Help/policy/CMP0027.rst25
-rw-r--r--Help/policy/CMP0028.rst23
-rw-r--r--Help/policy/CMP0029.rst10
-rw-r--r--Help/policy/CMP0030.rst11
-rw-r--r--Help/policy/CMP0031.rst13
-rw-r--r--Help/policy/CMP0032.rst13
-rw-r--r--Help/policy/CMP0033.rst14
-rw-r--r--Help/policy/CMP0034.rst11
-rw-r--r--Help/policy/CMP0035.rst10
-rw-r--r--Help/policy/CMP0036.rst12
-rw-r--r--Help/policy/CMP0037.rst26
-rw-r--r--Help/policy/CMP0038.rst16
-rw-r--r--Help/policy/CMP0039.rst17
-rw-r--r--Help/policy/CMP0040.rst16
-rw-r--r--Help/policy/CMP0041.rst25
-rw-r--r--Help/policy/CMP0042.rst19
-rw-r--r--Help/policy/CMP0043.rst45
-rw-r--r--Help/policy/CMP0044.rst19
-rw-r--r--Help/policy/CMP0045.rst17
-rw-r--r--Help/policy/CMP0046.rst17
-rw-r--r--Help/policy/CMP0047.rst28
-rw-r--r--Help/policy/CMP0048.rst22
-rw-r--r--Help/policy/CMP0049.rst23
-rw-r--r--Help/policy/CMP0050.rst18
-rw-r--r--Help/policy/CMP0051.rst24
-rw-r--r--Help/policy/CMP0052.rst24
-rw-r--r--Help/policy/CMP0053.rst44
-rw-r--r--Help/policy/CMP0054.rst18
-rw-r--r--Help/policy/DISALLOWED_COMMAND.txt9
-rw-r--r--Help/prop_cache/ADVANCED.rst8
-rw-r--r--Help/prop_cache/HELPSTRING.rst7
-rw-r--r--Help/prop_cache/MODIFIED.rst7
-rw-r--r--Help/prop_cache/STRINGS.rst9
-rw-r--r--Help/prop_cache/TYPE.rst21
-rw-r--r--Help/prop_cache/VALUE.rst7
-rw-r--r--Help/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES.rst7
-rw-r--r--Help/prop_dir/CACHE_VARIABLES.rst7
-rw-r--r--Help/prop_dir/CLEAN_NO_CUSTOM.rst7
-rw-r--r--Help/prop_dir/CMAKE_CONFIGURE_DEPENDS.rst9
-rw-r--r--Help/prop_dir/COMPILE_DEFINITIONS.rst32
-rw-r--r--Help/prop_dir/COMPILE_DEFINITIONS_CONFIG.rst19
-rw-r--r--Help/prop_dir/COMPILE_OPTIONS.rst16
-rw-r--r--Help/prop_dir/DEFINITIONS.rst8
-rw-r--r--Help/prop_dir/EXCLUDE_FROM_ALL.rst9
-rw-r--r--Help/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst34
-rw-r--r--Help/prop_dir/INCLUDE_DIRECTORIES.rst26
-rw-r--r--Help/prop_dir/INCLUDE_REGULAR_EXPRESSION.rst8
-rw-r--r--Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION.rst7
-rw-r--r--Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst8
-rw-r--r--Help/prop_dir/LINK_DIRECTORIES.rst8
-rw-r--r--Help/prop_dir/LISTFILE_STACK.rst9
-rw-r--r--Help/prop_dir/MACROS.rst8
-rw-r--r--Help/prop_dir/PARENT_DIRECTORY.rst8
-rw-r--r--Help/prop_dir/RULE_LAUNCH_COMPILE.rst7
-rw-r--r--Help/prop_dir/RULE_LAUNCH_CUSTOM.rst7
-rw-r--r--Help/prop_dir/RULE_LAUNCH_LINK.rst7
-rw-r--r--Help/prop_dir/TEST_INCLUDE_FILE.rst7
-rw-r--r--Help/prop_dir/VARIABLES.rst7
-rw-r--r--Help/prop_dir/VS_GLOBAL_SECTION_POST_section.rst29
-rw-r--r--Help/prop_dir/VS_GLOBAL_SECTION_PRE_section.rst22
-rw-r--r--Help/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst19
-rw-r--r--Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst9
-rw-r--r--Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst11
-rw-r--r--Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst298
-rw-r--r--Help/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst26
-rw-r--r--Help/prop_gbl/DEBUG_CONFIGURATIONS.rst14
-rw-r--r--Help/prop_gbl/DISABLED_FEATURES.rst11
-rw-r--r--Help/prop_gbl/ECLIPSE_EXTRA_NATURES.rst8
-rw-r--r--Help/prop_gbl/ENABLED_FEATURES.rst11
-rw-r--r--Help/prop_gbl/ENABLED_LANGUAGES.rst6
-rw-r--r--Help/prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS.rst9
-rw-r--r--Help/prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING.rst9
-rw-r--r--Help/prop_gbl/GLOBAL_DEPENDS_DEBUG_MODE.rst8
-rw-r--r--Help/prop_gbl/GLOBAL_DEPENDS_NO_CYCLES.rst10
-rw-r--r--Help/prop_gbl/IN_TRY_COMPILE.rst6
-rw-r--r--Help/prop_gbl/JOB_POOLS.rst20
-rw-r--r--Help/prop_gbl/PACKAGES_FOUND.rst7
-rw-r--r--Help/prop_gbl/PACKAGES_NOT_FOUND.rst7
-rw-r--r--Help/prop_gbl/PREDEFINED_TARGETS_FOLDER.rst9
-rw-r--r--Help/prop_gbl/REPORT_UNDEFINED_PROPERTIES.rst8
-rw-r--r--Help/prop_gbl/RULE_LAUNCH_COMPILE.rst9
-rw-r--r--Help/prop_gbl/RULE_LAUNCH_CUSTOM.rst9
-rw-r--r--Help/prop_gbl/RULE_LAUNCH_LINK.rst9
-rw-r--r--Help/prop_gbl/RULE_MESSAGES.rst13
-rw-r--r--Help/prop_gbl/TARGET_ARCHIVES_MAY_BE_SHARED_LIBS.rst7
-rw-r--r--Help/prop_gbl/TARGET_SUPPORTS_SHARED_LIBS.rst9
-rw-r--r--Help/prop_gbl/USE_FOLDERS.rst9
-rw-r--r--Help/prop_inst/CPACK_NEVER_OVERWRITE.rst6
-rw-r--r--Help/prop_inst/CPACK_PERMANENT.rst6
-rw-r--r--Help/prop_inst/CPACK_WIX_ACL.rst18
-rw-r--r--Help/prop_sf/ABSTRACT.rst9
-rw-r--r--Help/prop_sf/AUTORCC_OPTIONS.rst13
-rw-r--r--Help/prop_sf/AUTOUIC_OPTIONS.rst14
-rw-r--r--Help/prop_sf/COMPILE_DEFINITIONS.rst20
-rw-r--r--Help/prop_sf/COMPILE_DEFINITIONS_CONFIG.rst10
-rw-r--r--Help/prop_sf/COMPILE_FLAGS.rst8
-rw-r--r--Help/prop_sf/EXTERNAL_OBJECT.rst8
-rw-r--r--Help/prop_sf/Fortran_FORMAT.rst9
-rw-r--r--Help/prop_sf/GENERATED.rst8
-rw-r--r--Help/prop_sf/HEADER_FILE_ONLY.rst9
-rw-r--r--Help/prop_sf/KEEP_EXTENSION.rst9
-rw-r--r--Help/prop_sf/LABELS.rst8
-rw-r--r--Help/prop_sf/LANGUAGE.rst10
-rw-r--r--Help/prop_sf/LOCATION.rst7
-rw-r--r--Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst19
-rw-r--r--Help/prop_sf/OBJECT_DEPENDS.rst18
-rw-r--r--Help/prop_sf/OBJECT_OUTPUTS.rst9
-rw-r--r--Help/prop_sf/SYMBOLIC.rst8
-rw-r--r--Help/prop_sf/VS_DEPLOYMENT_CONTENT.rst11
-rw-r--r--Help/prop_sf/VS_SHADER_TYPE.rst4
-rw-r--r--Help/prop_sf/WRAP_EXCLUDE.rst10
-rw-r--r--Help/prop_sf/XCODE_EXPLICIT_FILE_TYPE.rst8
-rw-r--r--Help/prop_sf/XCODE_LAST_KNOWN_FILE_TYPE.rst9
-rw-r--r--Help/prop_test/ATTACHED_FILES.rst7
-rw-r--r--Help/prop_test/ATTACHED_FILES_ON_FAIL.rst7
-rw-r--r--Help/prop_test/COST.rst7
-rw-r--r--Help/prop_test/DEPENDS.rst6
-rw-r--r--Help/prop_test/ENVIRONMENT.rst9
-rw-r--r--Help/prop_test/FAIL_REGULAR_EXPRESSION.rst8
-rw-r--r--Help/prop_test/LABELS.rst6
-rw-r--r--Help/prop_test/MEASUREMENT.rst8
-rw-r--r--Help/prop_test/PASS_REGULAR_EXPRESSION.rst8
-rw-r--r--Help/prop_test/PROCESSORS.rst8
-rw-r--r--Help/prop_test/REQUIRED_FILES.rst7
-rw-r--r--Help/prop_test/RESOURCE_LOCK.rst7
-rw-r--r--Help/prop_test/RUN_SERIAL.rst8
-rw-r--r--Help/prop_test/SKIP_RETURN_CODE.rst9
-rw-r--r--Help/prop_test/TIMEOUT.rst9
-rw-r--r--Help/prop_test/WILL_FAIL.rst7
-rw-r--r--Help/prop_test/WORKING_DIRECTORY.rst7
-rw-r--r--Help/prop_tgt/ALIASED_TARGET.rst7
-rw-r--r--Help/prop_tgt/ANDROID_API.rst7
-rw-r--r--Help/prop_tgt/ANDROID_GUI.rst9
-rw-r--r--Help/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY.rst7
-rw-r--r--Help/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY_CONFIG.rst11
-rw-r--r--Help/prop_tgt/ARCHIVE_OUTPUT_NAME.rst6
-rw-r--r--Help/prop_tgt/ARCHIVE_OUTPUT_NAME_CONFIG.rst6
-rw-r--r--Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst17
-rw-r--r--Help/prop_tgt/AUTOMOC.rst37
-rw-r--r--Help/prop_tgt/AUTOMOC_MOC_OPTIONS.rst15
-rw-r--r--Help/prop_tgt/AUTORCC.rst23
-rw-r--r--Help/prop_tgt/AUTORCC_OPTIONS.rst21
-rw-r--r--Help/prop_tgt/AUTOUIC.rst24
-rw-r--r--Help/prop_tgt/AUTOUIC_OPTIONS.rst25
-rw-r--r--Help/prop_tgt/BUILD_WITH_INSTALL_RPATH.rst11
-rw-r--r--Help/prop_tgt/BUNDLE.rst9
-rw-r--r--Help/prop_tgt/BUNDLE_EXTENSION.rst7
-rw-r--r--Help/prop_tgt/COMPATIBLE_INTERFACE_BOOL.rst20
-rw-r--r--Help/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MAX.rst18
-rw-r--r--Help/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MIN.rst18
-rw-r--r--Help/prop_tgt/COMPATIBLE_INTERFACE_STRING.rst16
-rw-r--r--Help/prop_tgt/COMPILE_DEFINITIONS.rst26
-rw-r--r--Help/prop_tgt/COMPILE_DEFINITIONS_CONFIG.rst16
-rw-r--r--Help/prop_tgt/COMPILE_FEATURES.rst12
-rw-r--r--Help/prop_tgt/COMPILE_FLAGS.rst11
-rw-r--r--Help/prop_tgt/COMPILE_OPTIONS.rst16
-rw-r--r--Help/prop_tgt/COMPILE_PDB_NAME.rst11
-rw-r--r--Help/prop_tgt/COMPILE_PDB_NAME_CONFIG.rst10
-rw-r--r--Help/prop_tgt/COMPILE_PDB_NOTE.txt8
-rw-r--r--Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY.rst13
-rw-r--r--Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst16
-rw-r--r--Help/prop_tgt/CONFIG_OUTPUT_NAME.rst7
-rw-r--r--Help/prop_tgt/CONFIG_POSTFIX.rst10
-rw-r--r--Help/prop_tgt/CXX_EXTENSIONS.rst16
-rw-r--r--Help/prop_tgt/CXX_STANDARD.rst30
-rw-r--r--Help/prop_tgt/CXX_STANDARD_REQUIRED.rst17
-rw-r--r--Help/prop_tgt/C_EXTENSIONS.rst16
-rw-r--r--Help/prop_tgt/C_STANDARD.rst30
-rw-r--r--Help/prop_tgt/C_STANDARD_REQUIRED.rst17
-rw-r--r--Help/prop_tgt/DEBUG_POSTFIX.rst7
-rw-r--r--Help/prop_tgt/DEFINE_SYMBOL.rst11
-rw-r--r--Help/prop_tgt/ENABLE_EXPORTS.rst19
-rw-r--r--Help/prop_tgt/EXCLUDE_FROM_ALL.rst10
-rw-r--r--Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.rst8
-rw-r--r--Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG.rst9
-rw-r--r--Help/prop_tgt/EXPORT_NAME.rst8
-rw-r--r--Help/prop_tgt/EchoString.rst7
-rw-r--r--Help/prop_tgt/FOLDER.rst10
-rw-r--r--Help/prop_tgt/FRAMEWORK.rst9
-rw-r--r--Help/prop_tgt/Fortran_FORMAT.rst11
-rw-r--r--Help/prop_tgt/Fortran_MODULE_DIRECTORY.rst17
-rw-r--r--Help/prop_tgt/GENERATOR_FILE_NAME.rst9
-rw-r--r--Help/prop_tgt/GNUtoMS.rst17
-rw-r--r--Help/prop_tgt/HAS_CXX.rst7
-rw-r--r--Help/prop_tgt/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst32
-rw-r--r--Help/prop_tgt/IMPORTED.rst8
-rw-r--r--Help/prop_tgt/IMPORTED_CONFIGURATIONS.rst11
-rw-r--r--Help/prop_tgt/IMPORTED_IMPLIB.rst7
-rw-r--r--Help/prop_tgt/IMPORTED_IMPLIB_CONFIG.rst7
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES.rst14
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES_CONFIG.rst8
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.rst14
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES_CONFIG.rst8
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.rst16
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG.rst13
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY.rst6
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY_CONFIG.rst7
-rw-r--r--Help/prop_tgt/IMPORTED_LOCATION.rst21
-rw-r--r--Help/prop_tgt/IMPORTED_LOCATION_CONFIG.rst7
-rw-r--r--Help/prop_tgt/IMPORTED_NO_SONAME.rst9
-rw-r--r--Help/prop_tgt/IMPORTED_NO_SONAME_CONFIG.rst7
-rw-r--r--Help/prop_tgt/IMPORTED_SONAME.rst8
-rw-r--r--Help/prop_tgt/IMPORTED_SONAME_CONFIG.rst7
-rw-r--r--Help/prop_tgt/IMPORT_PREFIX.rst9
-rw-r--r--Help/prop_tgt/IMPORT_SUFFIX.rst9
-rw-r--r--Help/prop_tgt/INCLUDE_DIRECTORIES.rst24
-rw-r--r--Help/prop_tgt/INSTALL_NAME_DIR.rst8
-rw-r--r--Help/prop_tgt/INSTALL_RPATH.rst9
-rw-r--r--Help/prop_tgt/INSTALL_RPATH_USE_LINK_PATH.rst10
-rw-r--r--Help/prop_tgt/INTERFACE_AUTOUIC_OPTIONS.rst14
-rw-r--r--Help/prop_tgt/INTERFACE_COMPILE_DEFINITIONS.rst15
-rw-r--r--Help/prop_tgt/INTERFACE_COMPILE_FEATURES.rst16
-rw-r--r--Help/prop_tgt/INTERFACE_COMPILE_OPTIONS.rst15
-rw-r--r--Help/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.rst33
-rw-r--r--Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst17
-rw-r--r--Help/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE.rst16
-rw-r--r--Help/prop_tgt/INTERFACE_SOURCES.rst15
-rw-r--r--Help/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.rst15
-rw-r--r--Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.rst7
-rw-r--r--Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst8
-rw-r--r--Help/prop_tgt/JOB_POOL_COMPILE.rst17
-rw-r--r--Help/prop_tgt/JOB_POOL_LINK.rst16
-rw-r--r--Help/prop_tgt/LABELS.rst6
-rw-r--r--Help/prop_tgt/LANG_VISIBILITY_PRESET.rst10
-rw-r--r--Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.rst7
-rw-r--r--Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG.rst11
-rw-r--r--Help/prop_tgt/LIBRARY_OUTPUT_NAME.rst6
-rw-r--r--Help/prop_tgt/LIBRARY_OUTPUT_NAME_CONFIG.rst6
-rw-r--r--Help/prop_tgt/LINKER_LANGUAGE.rst14
-rw-r--r--Help/prop_tgt/LINK_DEPENDS.rst12
-rw-r--r--Help/prop_tgt/LINK_DEPENDS_NO_SHARED.rst14
-rw-r--r--Help/prop_tgt/LINK_FLAGS.rst8
-rw-r--r--Help/prop_tgt/LINK_FLAGS_CONFIG.rst6
-rw-r--r--Help/prop_tgt/LINK_INTERFACE_LIBRARIES.rst22
-rw-r--r--Help/prop_tgt/LINK_INTERFACE_LIBRARIES_CONFIG.rst13
-rw-r--r--Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY.rst12
-rw-r--r--Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG.rst8
-rw-r--r--Help/prop_tgt/LINK_LIBRARIES.rst17
-rw-r--r--Help/prop_tgt/LINK_SEARCH_END_STATIC.rst14
-rw-r--r--Help/prop_tgt/LINK_SEARCH_START_STATIC.rst14
-rw-r--r--Help/prop_tgt/LOCATION.rst27
-rw-r--r--Help/prop_tgt/LOCATION_CONFIG.rst20
-rw-r--r--Help/prop_tgt/MACOSX_BUNDLE.rst12
-rw-r--r--Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst29
-rw-r--r--Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst25
-rw-r--r--Help/prop_tgt/MACOSX_RPATH.rst18
-rw-r--r--Help/prop_tgt/MAP_IMPORTED_CONFIG_CONFIG.rst19
-rw-r--r--Help/prop_tgt/NAME.rst6
-rw-r--r--Help/prop_tgt/NO_SONAME.rst14
-rw-r--r--Help/prop_tgt/NO_SYSTEM_FROM_IMPORTED.rst11
-rw-r--r--Help/prop_tgt/OSX_ARCHITECTURES.rst11
-rw-r--r--Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst7
-rw-r--r--Help/prop_tgt/OUTPUT_NAME.rst8
-rw-r--r--Help/prop_tgt/OUTPUT_NAME_CONFIG.rst6
-rw-r--r--Help/prop_tgt/PDB_NAME.rst11
-rw-r--r--Help/prop_tgt/PDB_NAME_CONFIG.rst10
-rw-r--r--Help/prop_tgt/PDB_NOTE.txt12
-rw-r--r--Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst13
-rw-r--r--Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst15
-rw-r--r--Help/prop_tgt/POSITION_INDEPENDENT_CODE.rst11
-rw-r--r--Help/prop_tgt/POST_INSTALL_SCRIPT.rst9
-rw-r--r--Help/prop_tgt/PREFIX.rst7
-rw-r--r--Help/prop_tgt/PRE_INSTALL_SCRIPT.rst9
-rw-r--r--Help/prop_tgt/PRIVATE_HEADER.rst11
-rw-r--r--Help/prop_tgt/PROJECT_LABEL.rst7
-rw-r--r--Help/prop_tgt/PUBLIC_HEADER.rst11
-rw-r--r--Help/prop_tgt/RESOURCE.rst11
-rw-r--r--Help/prop_tgt/RULE_LAUNCH_COMPILE.rst7
-rw-r--r--Help/prop_tgt/RULE_LAUNCH_CUSTOM.rst7
-rw-r--r--Help/prop_tgt/RULE_LAUNCH_LINK.rst7
-rw-r--r--Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.rst7
-rw-r--r--Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG.rst11
-rw-r--r--Help/prop_tgt/RUNTIME_OUTPUT_NAME.rst6
-rw-r--r--Help/prop_tgt/RUNTIME_OUTPUT_NAME_CONFIG.rst6
-rw-r--r--Help/prop_tgt/SKIP_BUILD_RPATH.rst9
-rw-r--r--Help/prop_tgt/SOURCES.rst6
-rw-r--r--Help/prop_tgt/SOVERSION.rst14
-rw-r--r--Help/prop_tgt/STATIC_LIBRARY_FLAGS.rst6
-rw-r--r--Help/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG.rst6
-rw-r--r--Help/prop_tgt/SUFFIX.rst7
-rw-r--r--Help/prop_tgt/TARGET_FILE_TYPES.txt9
-rw-r--r--Help/prop_tgt/TYPE.rst8
-rw-r--r--Help/prop_tgt/VERSION.rst16
-rw-r--r--Help/prop_tgt/VISIBILITY_INLINES_HIDDEN.rst11
-rw-r--r--Help/prop_tgt/VS_DOTNET_REFERENCES.rst7
-rw-r--r--Help/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION.rst7
-rw-r--r--Help/prop_tgt/VS_GLOBAL_KEYWORD.rst12
-rw-r--r--Help/prop_tgt/VS_GLOBAL_PROJECT_TYPES.rst15
-rw-r--r--Help/prop_tgt/VS_GLOBAL_ROOTNAMESPACE.rst7
-rw-r--r--Help/prop_tgt/VS_GLOBAL_variable.rst10
-rw-r--r--Help/prop_tgt/VS_KEYWORD.rst10
-rw-r--r--Help/prop_tgt/VS_SCC_AUXPATH.rst7
-rw-r--r--Help/prop_tgt/VS_SCC_LOCALPATH.rst7
-rw-r--r--Help/prop_tgt/VS_SCC_PROJECTNAME.rst7
-rw-r--r--Help/prop_tgt/VS_SCC_PROVIDER.rst7
-rw-r--r--Help/prop_tgt/VS_WINRT_COMPONENT.rst11
-rw-r--r--Help/prop_tgt/VS_WINRT_EXTENSIONS.rst5
-rw-r--r--Help/prop_tgt/VS_WINRT_REFERENCES.rst7
-rw-r--r--Help/prop_tgt/WIN32_EXECUTABLE.rst12
-rw-r--r--Help/prop_tgt/XCODE_ATTRIBUTE_an-attribute.rst7
-rw-r--r--Help/prop_tgt/XXX_OUTPUT_DIRECTORY.txt10
-rw-r--r--Help/prop_tgt/XXX_OUTPUT_NAME.txt6
-rw-r--r--Help/release/3.0.0.rst473
-rw-r--r--Help/release/3.1.0.rst381
-rw-r--r--Help/release/dev.txt16
-rw-r--r--Help/release/dev/0-sample-topic.rst7
-rw-r--r--Help/release/index.rst17
-rw-r--r--Help/variable/APPLE.rst6
-rw-r--r--Help/variable/BORLAND.rst6
-rw-r--r--Help/variable/BUILD_SHARED_LIBS.rst10
-rw-r--r--Help/variable/CMAKE_ABSOLUTE_DESTINATION_FILES.rst9
-rw-r--r--Help/variable/CMAKE_ANDROID_API.rst5
-rw-r--r--Help/variable/CMAKE_ANDROID_GUI.rst5
-rw-r--r--Help/variable/CMAKE_APPBUNDLE_PATH.rst5
-rw-r--r--Help/variable/CMAKE_AR.rst7
-rw-r--r--Help/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY.rst8
-rw-r--r--Help/variable/CMAKE_ARGC.rst7
-rw-r--r--Help/variable/CMAKE_ARGV0.rst9
-rw-r--r--Help/variable/CMAKE_AUTOMOC.rst7
-rw-r--r--Help/variable/CMAKE_AUTOMOC_MOC_OPTIONS.rst7
-rw-r--r--Help/variable/CMAKE_AUTOMOC_RELAXED_MODE.rst13
-rw-r--r--Help/variable/CMAKE_AUTORCC.rst7
-rw-r--r--Help/variable/CMAKE_AUTORCC_OPTIONS.rst7
-rw-r--r--Help/variable/CMAKE_AUTOUIC.rst7
-rw-r--r--Help/variable/CMAKE_AUTOUIC_OPTIONS.rst7
-rw-r--r--Help/variable/CMAKE_BACKWARDS_COMPATIBILITY.rst4
-rw-r--r--Help/variable/CMAKE_BINARY_DIR.rst8
-rw-r--r--Help/variable/CMAKE_BUILD_TOOL.rst6
-rw-r--r--Help/variable/CMAKE_BUILD_TYPE.rst19
-rw-r--r--Help/variable/CMAKE_BUILD_WITH_INSTALL_RPATH.rst11
-rw-r--r--Help/variable/CMAKE_CACHEFILE_DIR.rst7
-rw-r--r--Help/variable/CMAKE_CACHE_MAJOR_VERSION.rst8
-rw-r--r--Help/variable/CMAKE_CACHE_MINOR_VERSION.rst8
-rw-r--r--Help/variable/CMAKE_CACHE_PATCH_VERSION.rst8
-rw-r--r--Help/variable/CMAKE_CFG_INTDIR.rst45
-rw-r--r--Help/variable/CMAKE_CL_64.rst6
-rw-r--r--Help/variable/CMAKE_COLOR_MAKEFILE.rst7
-rw-r--r--Help/variable/CMAKE_COMMAND.rst8
-rw-r--r--Help/variable/CMAKE_COMPILER_2005.rst6
-rw-r--r--Help/variable/CMAKE_COMPILER_IS_GNULANG.rst15
-rw-r--r--Help/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY.rst8
-rw-r--r--Help/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst11
-rw-r--r--Help/variable/CMAKE_CONFIGURATION_TYPES.rst10
-rw-r--r--Help/variable/CMAKE_CONFIG_POSTFIX.rst7
-rw-r--r--Help/variable/CMAKE_CROSSCOMPILING.rst8
-rw-r--r--Help/variable/CMAKE_CTEST_COMMAND.rst8
-rw-r--r--Help/variable/CMAKE_CURRENT_BINARY_DIR.rst10
-rw-r--r--Help/variable/CMAKE_CURRENT_LIST_DIR.rst17
-rw-r--r--Help/variable/CMAKE_CURRENT_LIST_FILE.rst15
-rw-r--r--Help/variable/CMAKE_CURRENT_LIST_LINE.rst7
-rw-r--r--Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst7
-rw-r--r--Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst11
-rw-r--r--Help/variable/CMAKE_CXX_EXTENSIONS.rst11
-rw-r--r--Help/variable/CMAKE_CXX_STANDARD.rst11
-rw-r--r--Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst11
-rw-r--r--Help/variable/CMAKE_C_COMPILE_FEATURES.rst11
-rw-r--r--Help/variable/CMAKE_C_EXTENSIONS.rst11
-rw-r--r--Help/variable/CMAKE_C_STANDARD.rst11
-rw-r--r--Help/variable/CMAKE_C_STANDARD_REQUIRED.rst11
-rw-r--r--Help/variable/CMAKE_DEBUG_POSTFIX.rst7
-rw-r--r--Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst14
-rw-r--r--Help/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.rst15
-rw-r--r--Help/variable/CMAKE_DL_LIBS.rst7
-rw-r--r--Help/variable/CMAKE_EDIT_COMMAND.rst8
-rw-r--r--Help/variable/CMAKE_ERROR_DEPRECATED.rst8
-rw-r--r--Help/variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst9
-rw-r--r--Help/variable/CMAKE_EXECUTABLE_SUFFIX.rst9
-rw-r--r--Help/variable/CMAKE_EXE_LINKER_FLAGS.rst6
-rw-r--r--Help/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG.rst7
-rw-r--r--Help/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.rst11
-rw-r--r--Help/variable/CMAKE_EXTRA_GENERATOR.rst9
-rw-r--r--Help/variable/CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES.rst9
-rw-r--r--Help/variable/CMAKE_FIND_LIBRARY_PREFIXES.rst9
-rw-r--r--Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst9
-rw-r--r--Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst15
-rw-r--r--Help/variable/CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY.rst13
-rw-r--r--Help/variable/CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY.rst13
-rw-r--r--Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst19
-rw-r--r--Help/variable/CMAKE_FIND_ROOT_PATH.rst8
-rw-r--r--Help/variable/CMAKE_FIND_ROOT_PATH_MODE_INCLUDE.rst6
-rw-r--r--Help/variable/CMAKE_FIND_ROOT_PATH_MODE_LIBRARY.rst6
-rw-r--r--Help/variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE.rst6
-rw-r--r--Help/variable/CMAKE_FIND_ROOT_PATH_MODE_PROGRAM.rst6
-rw-r--r--Help/variable/CMAKE_FIND_ROOT_PATH_MODE_XXX.txt8
-rw-r--r--Help/variable/CMAKE_FRAMEWORK_PATH.rst6
-rw-r--r--Help/variable/CMAKE_Fortran_FORMAT.rst7
-rw-r--r--Help/variable/CMAKE_Fortran_MODDIR_DEFAULT.rst8
-rw-r--r--Help/variable/CMAKE_Fortran_MODDIR_FLAG.rst7
-rw-r--r--Help/variable/CMAKE_Fortran_MODOUT_FLAG.rst7
-rw-r--r--Help/variable/CMAKE_Fortran_MODULE_DIRECTORY.rst8
-rw-r--r--Help/variable/CMAKE_GENERATOR.rst7
-rw-r--r--Help/variable/CMAKE_GENERATOR_PLATFORM.rst15
-rw-r--r--Help/variable/CMAKE_GENERATOR_TOOLSET.rst15
-rw-r--r--Help/variable/CMAKE_GNUtoMS.rst8
-rw-r--r--Help/variable/CMAKE_HOME_DIRECTORY.rst6
-rw-r--r--Help/variable/CMAKE_HOST_APPLE.rst6
-rw-r--r--Help/variable/CMAKE_HOST_SYSTEM.rst10
-rw-r--r--Help/variable/CMAKE_HOST_SYSTEM_NAME.rst8
-rw-r--r--Help/variable/CMAKE_HOST_SYSTEM_PROCESSOR.rst8
-rw-r--r--Help/variable/CMAKE_HOST_SYSTEM_VERSION.rst8
-rw-r--r--Help/variable/CMAKE_HOST_UNIX.rst7
-rw-r--r--Help/variable/CMAKE_HOST_WIN32.rst6
-rw-r--r--Help/variable/CMAKE_IGNORE_PATH.rst17
-rw-r--r--Help/variable/CMAKE_IMPORT_LIBRARY_PREFIX.rst9
-rw-r--r--Help/variable/CMAKE_IMPORT_LIBRARY_SUFFIX.rst9
-rw-r--r--Help/variable/CMAKE_INCLUDE_CURRENT_DIR.rst13
-rw-r--r--Help/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.rst10
-rw-r--r--Help/variable/CMAKE_INCLUDE_DIRECTORIES_BEFORE.rst8
-rw-r--r--Help/variable/CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE.rst8
-rw-r--r--Help/variable/CMAKE_INCLUDE_PATH.rst10
-rw-r--r--Help/variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME.rst9
-rw-r--r--Help/variable/CMAKE_INSTALL_MESSAGE.rst30
-rw-r--r--Help/variable/CMAKE_INSTALL_NAME_DIR.rst8
-rw-r--r--Help/variable/CMAKE_INSTALL_PREFIX.rst29
-rw-r--r--Help/variable/CMAKE_INSTALL_RPATH.rst8
-rw-r--r--Help/variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH.rst9
-rw-r--r--Help/variable/CMAKE_INTERNAL_PLATFORM_ABI.rst6
-rw-r--r--Help/variable/CMAKE_JOB_POOL_COMPILE.rst6
-rw-r--r--Help/variable/CMAKE_JOB_POOL_LINK.rst6
-rw-r--r--Help/variable/CMAKE_LANG_ARCHIVE_APPEND.rst9
-rw-r--r--Help/variable/CMAKE_LANG_ARCHIVE_CREATE.rst9
-rw-r--r--Help/variable/CMAKE_LANG_ARCHIVE_FINISH.rst9
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER.rst7
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_ABI.rst6
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst13
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_ID.rst33
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_LOADED.rst7
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_TARGET.rst11
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_VERSION.rst8
-rw-r--r--Help/variable/CMAKE_LANG_COMPILE_OBJECT.rst7
-rw-r--r--Help/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.rst7
-rw-r--r--Help/variable/CMAKE_LANG_CREATE_SHARED_MODULE.rst7
-rw-r--r--Help/variable/CMAKE_LANG_CREATE_STATIC_LIBRARY.rst7
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS.rst6
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_DEBUG.rst6
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL.rst7
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_RELEASE.rst6
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO.rst7
-rw-r--r--Help/variable/CMAKE_LANG_IGNORE_EXTENSIONS.rst7
-rw-r--r--Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst9
-rw-r--r--Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst17
-rw-r--r--Help/variable/CMAKE_LANG_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES.rst8
-rw-r--r--Help/variable/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES.rst10
-rw-r--r--Help/variable/CMAKE_LANG_LIBRARY_ARCHITECTURE.rst8
-rw-r--r--Help/variable/CMAKE_LANG_LINKER_PREFERENCE.rst11
-rw-r--r--Help/variable/CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES.rst9
-rw-r--r--Help/variable/CMAKE_LANG_LINK_EXECUTABLE.rst6
-rw-r--r--Help/variable/CMAKE_LANG_OUTPUT_EXTENSION.rst7
-rw-r--r--Help/variable/CMAKE_LANG_PLATFORM_ID.rst6
-rw-r--r--Help/variable/CMAKE_LANG_SIMULATE_ID.rst9
-rw-r--r--Help/variable/CMAKE_LANG_SIMULATE_VERSION.rst9
-rw-r--r--Help/variable/CMAKE_LANG_SIZEOF_DATA_PTR.rst7
-rw-r--r--Help/variable/CMAKE_LANG_SOURCE_FILE_EXTENSIONS.rst6
-rw-r--r--Help/variable/CMAKE_LANG_VISIBILITY_PRESET.rst8
-rw-r--r--Help/variable/CMAKE_LIBRARY_ARCHITECTURE.rst7
-rw-r--r--Help/variable/CMAKE_LIBRARY_ARCHITECTURE_REGEX.rst7
-rw-r--r--Help/variable/CMAKE_LIBRARY_OUTPUT_DIRECTORY.rst8
-rw-r--r--Help/variable/CMAKE_LIBRARY_PATH.rst10
-rw-r--r--Help/variable/CMAKE_LIBRARY_PATH_FLAG.rst7
-rw-r--r--Help/variable/CMAKE_LINK_DEF_FILE_FLAG.rst7
-rw-r--r--Help/variable/CMAKE_LINK_DEPENDS_NO_SHARED.rst8
-rw-r--r--Help/variable/CMAKE_LINK_INTERFACE_LIBRARIES.rst8
-rw-r--r--Help/variable/CMAKE_LINK_LIBRARY_FILE_FLAG.rst7
-rw-r--r--Help/variable/CMAKE_LINK_LIBRARY_FLAG.rst7
-rw-r--r--Help/variable/CMAKE_LINK_LIBRARY_SUFFIX.rst6
-rw-r--r--Help/variable/CMAKE_MACOSX_BUNDLE.rst7
-rw-r--r--Help/variable/CMAKE_MACOSX_RPATH.rst7
-rw-r--r--Help/variable/CMAKE_MAJOR_VERSION.rst5
-rw-r--r--Help/variable/CMAKE_MAKE_PROGRAM.rst55
-rw-r--r--Help/variable/CMAKE_MAP_IMPORTED_CONFIG_CONFIG.rst8
-rw-r--r--Help/variable/CMAKE_MFC_FLAG.rst16
-rw-r--r--Help/variable/CMAKE_MINIMUM_REQUIRED_VERSION.rst7
-rw-r--r--Help/variable/CMAKE_MINOR_VERSION.rst5
-rw-r--r--Help/variable/CMAKE_MODULE_LINKER_FLAGS.rst6
-rw-r--r--Help/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG.rst6
-rw-r--r--Help/variable/CMAKE_MODULE_PATH.rst8
-rw-r--r--Help/variable/CMAKE_NOT_USING_CONFIG_FLAGS.rst7
-rw-r--r--Help/variable/CMAKE_NO_BUILTIN_CHRPATH.rst10
-rw-r--r--Help/variable/CMAKE_NO_SYSTEM_FROM_IMPORTED.rst8
-rw-r--r--Help/variable/CMAKE_OBJECT_PATH_MAX.rst16
-rw-r--r--Help/variable/CMAKE_OSX_ARCHITECTURES.rst10
-rw-r--r--Help/variable/CMAKE_OSX_DEPLOYMENT_TARGET.rst13
-rw-r--r--Help/variable/CMAKE_OSX_SYSROOT.rst13
-rw-r--r--Help/variable/CMAKE_OSX_VARIABLE.txt6
-rw-r--r--Help/variable/CMAKE_PARENT_LIST_FILE.rst9
-rw-r--r--Help/variable/CMAKE_PATCH_VERSION.rst5
-rw-r--r--Help/variable/CMAKE_PDB_OUTPUT_DIRECTORY.rst9
-rw-r--r--Help/variable/CMAKE_PDB_OUTPUT_DIRECTORY_CONFIG.rst11
-rw-r--r--Help/variable/CMAKE_POLICY_DEFAULT_CMPNNNN.rst16
-rw-r--r--Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst17
-rw-r--r--Help/variable/CMAKE_POSITION_INDEPENDENT_CODE.rst8
-rw-r--r--Help/variable/CMAKE_PREFIX_PATH.rst13
-rw-r--r--Help/variable/CMAKE_PROGRAM_PATH.rst10
-rw-r--r--Help/variable/CMAKE_PROJECT_NAME.rst7
-rw-r--r--Help/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE.rst6
-rw-r--r--Help/variable/CMAKE_RANLIB.rst7
-rw-r--r--Help/variable/CMAKE_ROOT.rst8
-rw-r--r--Help/variable/CMAKE_RUNTIME_OUTPUT_DIRECTORY.rst8
-rw-r--r--Help/variable/CMAKE_SCRIPT_MODE_FILE.rst8
-rw-r--r--Help/variable/CMAKE_SHARED_LIBRARY_PREFIX.rst8
-rw-r--r--Help/variable/CMAKE_SHARED_LIBRARY_SUFFIX.rst9
-rw-r--r--Help/variable/CMAKE_SHARED_LINKER_FLAGS.rst6
-rw-r--r--Help/variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG.rst7
-rw-r--r--Help/variable/CMAKE_SHARED_MODULE_PREFIX.rst8
-rw-r--r--Help/variable/CMAKE_SHARED_MODULE_SUFFIX.rst9
-rw-r--r--Help/variable/CMAKE_SIZEOF_VOID_P.rst8
-rw-r--r--Help/variable/CMAKE_SKIP_BUILD_RPATH.rst10
-rw-r--r--Help/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.rst11
-rw-r--r--Help/variable/CMAKE_SKIP_INSTALL_RPATH.rst14
-rw-r--r--Help/variable/CMAKE_SKIP_INSTALL_RULES.rst7
-rw-r--r--Help/variable/CMAKE_SKIP_RPATH.rst10
-rw-r--r--Help/variable/CMAKE_SOURCE_DIR.rst8
-rw-r--r--Help/variable/CMAKE_STAGING_PREFIX.rst13
-rw-r--r--Help/variable/CMAKE_STANDARD_LIBRARIES.rst7
-rw-r--r--Help/variable/CMAKE_STATIC_LIBRARY_PREFIX.rst8
-rw-r--r--Help/variable/CMAKE_STATIC_LIBRARY_SUFFIX.rst9
-rw-r--r--Help/variable/CMAKE_STATIC_LINKER_FLAGS.rst6
-rw-r--r--Help/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG.rst7
-rw-r--r--Help/variable/CMAKE_SYSROOT.rst12
-rw-r--r--Help/variable/CMAKE_SYSTEM.rst10
-rw-r--r--Help/variable/CMAKE_SYSTEM_IGNORE_PATH.rst15
-rw-r--r--Help/variable/CMAKE_SYSTEM_INCLUDE_PATH.rst11
-rw-r--r--Help/variable/CMAKE_SYSTEM_LIBRARY_PATH.rst11
-rw-r--r--Help/variable/CMAKE_SYSTEM_NAME.rst8
-rw-r--r--Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst16
-rw-r--r--Help/variable/CMAKE_SYSTEM_PROCESSOR.rst8
-rw-r--r--Help/variable/CMAKE_SYSTEM_PROGRAM_PATH.rst11
-rw-r--r--Help/variable/CMAKE_SYSTEM_VERSION.rst8
-rw-r--r--Help/variable/CMAKE_TOOLCHAIN_FILE.rst9
-rw-r--r--Help/variable/CMAKE_TRY_COMPILE_CONFIGURATION.rst9
-rw-r--r--Help/variable/CMAKE_TWEAK_VERSION.rst11
-rw-r--r--Help/variable/CMAKE_USER_MAKE_RULES_OVERRIDE.rst23
-rw-r--r--Help/variable/CMAKE_USER_MAKE_RULES_OVERRIDE_LANG.rst7
-rw-r--r--Help/variable/CMAKE_USE_RELATIVE_PATHS.rst10
-rw-r--r--Help/variable/CMAKE_VERBOSE_MAKEFILE.rst9
-rw-r--r--Help/variable/CMAKE_VERSION.rst51
-rw-r--r--Help/variable/CMAKE_VISIBILITY_INLINES_HIDDEN.rst8
-rw-r--r--Help/variable/CMAKE_VS_DEVENV_COMMAND.rst14
-rw-r--r--Help/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION.rst7
-rw-r--r--Help/variable/CMAKE_VS_MSBUILD_COMMAND.rst13
-rw-r--r--Help/variable/CMAKE_VS_MSDEV_COMMAND.rst10
-rw-r--r--Help/variable/CMAKE_VS_NsightTegra_VERSION.rst7
-rw-r--r--Help/variable/CMAKE_VS_PLATFORM_NAME.rst7
-rw-r--r--Help/variable/CMAKE_VS_PLATFORM_TOOLSET.rst10
-rw-r--r--Help/variable/CMAKE_WARN_DEPRECATED.rst7
-rw-r--r--Help/variable/CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION.rst8
-rw-r--r--Help/variable/CMAKE_WIN32_EXECUTABLE.rst7
-rw-r--r--Help/variable/CMAKE_XCODE_PLATFORM_TOOLSET.rst9
-rw-r--r--Help/variable/CPACK_ABSOLUTE_DESTINATION_FILES.rst10
-rw-r--r--Help/variable/CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY.rst8
-rw-r--r--Help/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst10
-rw-r--r--Help/variable/CPACK_INCLUDE_TOPLEVEL_DIRECTORY.rst19
-rw-r--r--Help/variable/CPACK_INSTALL_SCRIPT.rst8
-rw-r--r--Help/variable/CPACK_PACKAGING_INSTALL_PREFIX.rst13
-rw-r--r--Help/variable/CPACK_SET_DESTDIR.rst30
-rw-r--r--Help/variable/CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION.rst8
-rw-r--r--Help/variable/CTEST_BINARY_DIRECTORY.rst5
-rw-r--r--Help/variable/CTEST_BUILD_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_BUILD_NAME.rst5
-rw-r--r--Help/variable/CTEST_BZR_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_BZR_UPDATE_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_CHECKOUT_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_CONFIGURATION_TYPE.rst5
-rw-r--r--Help/variable/CTEST_CONFIGURE_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_COVERAGE_COMMAND.rst60
-rw-r--r--Help/variable/CTEST_COVERAGE_EXTRA_FLAGS.rst5
-rw-r--r--Help/variable/CTEST_CURL_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_CVS_CHECKOUT.rst4
-rw-r--r--Help/variable/CTEST_CVS_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_CVS_UPDATE_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_DROP_LOCATION.rst5
-rw-r--r--Help/variable/CTEST_DROP_METHOD.rst5
-rw-r--r--Help/variable/CTEST_DROP_SITE.rst5
-rw-r--r--Help/variable/CTEST_DROP_SITE_CDASH.rst5
-rw-r--r--Help/variable/CTEST_DROP_SITE_PASSWORD.rst5
-rw-r--r--Help/variable/CTEST_DROP_SITE_USER.rst5
-rw-r--r--Help/variable/CTEST_GIT_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_GIT_UPDATE_CUSTOM.rst5
-rw-r--r--Help/variable/CTEST_GIT_UPDATE_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_HG_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_HG_UPDATE_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_MEMORYCHECK_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_MEMORYCHECK_COMMAND_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_MEMORYCHECK_SANITIZER_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_MEMORYCHECK_SUPPRESSIONS_FILE.rst5
-rw-r--r--Help/variable/CTEST_MEMORYCHECK_TYPE.rst7
-rw-r--r--Help/variable/CTEST_NIGHTLY_START_TIME.rst5
-rw-r--r--Help/variable/CTEST_P4_CLIENT.rst5
-rw-r--r--Help/variable/CTEST_P4_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_P4_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_P4_UPDATE_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_SCP_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_SITE.rst5
-rw-r--r--Help/variable/CTEST_SOURCE_DIRECTORY.rst5
-rw-r--r--Help/variable/CTEST_SVN_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_SVN_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_SVN_UPDATE_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_TEST_TIMEOUT.rst5
-rw-r--r--Help/variable/CTEST_TRIGGER_SITE.rst5
-rw-r--r--Help/variable/CTEST_UPDATE_COMMAND.rst5
-rw-r--r--Help/variable/CTEST_UPDATE_OPTIONS.rst5
-rw-r--r--Help/variable/CTEST_UPDATE_VERSION_ONLY.rst5
-rw-r--r--Help/variable/CTEST_USE_LAUNCHERS.rst5
-rw-r--r--Help/variable/CYGWIN.rst6
-rw-r--r--Help/variable/ENV.rst7
-rw-r--r--Help/variable/EXECUTABLE_OUTPUT_PATH.rst8
-rw-r--r--Help/variable/LIBRARY_OUTPUT_PATH.rst9
-rw-r--r--Help/variable/MSVC.rst6
-rw-r--r--Help/variable/MSVC10.rst6
-rw-r--r--Help/variable/MSVC11.rst6
-rw-r--r--Help/variable/MSVC12.rst6
-rw-r--r--Help/variable/MSVC14.rst6
-rw-r--r--Help/variable/MSVC60.rst6
-rw-r--r--Help/variable/MSVC70.rst6
-rw-r--r--Help/variable/MSVC71.rst6
-rw-r--r--Help/variable/MSVC80.rst6
-rw-r--r--Help/variable/MSVC90.rst6
-rw-r--r--Help/variable/MSVC_IDE.rst7
-rw-r--r--Help/variable/MSVC_VERSION.rst16
-rw-r--r--Help/variable/PROJECT-NAME_BINARY_DIR.rst8
-rw-r--r--Help/variable/PROJECT-NAME_SOURCE_DIR.rst8
-rw-r--r--Help/variable/PROJECT-NAME_VERSION.rst11
-rw-r--r--Help/variable/PROJECT-NAME_VERSION_MAJOR.rst5
-rw-r--r--Help/variable/PROJECT-NAME_VERSION_MINOR.rst5
-rw-r--r--Help/variable/PROJECT-NAME_VERSION_PATCH.rst5
-rw-r--r--Help/variable/PROJECT-NAME_VERSION_TWEAK.rst5
-rw-r--r--Help/variable/PROJECT_BINARY_DIR.rst6
-rw-r--r--Help/variable/PROJECT_NAME.rst6
-rw-r--r--Help/variable/PROJECT_SOURCE_DIR.rst6
-rw-r--r--Help/variable/PROJECT_VERSION.rst11
-rw-r--r--Help/variable/PROJECT_VERSION_MAJOR.rst5
-rw-r--r--Help/variable/PROJECT_VERSION_MINOR.rst5
-rw-r--r--Help/variable/PROJECT_VERSION_PATCH.rst5
-rw-r--r--Help/variable/PROJECT_VERSION_TWEAK.rst5
-rw-r--r--Help/variable/UNIX.rst7
-rw-r--r--Help/variable/WIN32.rst6
-rw-r--r--Help/variable/WINCE.rst5
-rw-r--r--Help/variable/WINDOWS_PHONE.rst5
-rw-r--r--Help/variable/WINDOWS_STORE.rst5
-rw-r--r--Help/variable/XCODE_VERSION.rst7
-rw-r--r--Licenses/LGPLv2.1.txt502
-rw-r--r--Licenses/README.rst7
-rw-r--r--Modules/AddFileDependencies.cmake33
-rw-r--r--Modules/AutogenInfo.cmake.in25
-rw-r--r--Modules/BasicConfigVersion-AnyNewerVersion.cmake.in31
-rw-r--r--Modules/BasicConfigVersion-ExactVersion.cmake.in47
-rw-r--r--Modules/BasicConfigVersion-SameMajorVersion.cmake.in46
-rw-r--r--Modules/BundleUtilities.cmake952
-rw-r--r--Modules/CMake.cmake17
-rw-r--r--Modules/CMakeASM-ATTInformation.cmake25
-rw-r--r--Modules/CMakeASMCompiler.cmake.in12
-rw-r--r--Modules/CMakeASMInformation.cmake148
-rw-r--r--Modules/CMakeASM_MASMInformation.cmake24
-rw-r--r--Modules/CMakeASM_NASMInformation.cmake46
-rw-r--r--Modules/CMakeAddFortranSubdirectory.cmake214
-rw-r--r--Modules/CMakeAddFortranSubdirectory/build_mingw.cmake.in2
-rw-r--r--Modules/CMakeAddFortranSubdirectory/config_mingw.cmake.in9
-rw-r--r--Modules/CMakeAddNewLanguage.txt33
-rw-r--r--Modules/CMakeBackwardCompatibilityC.cmake100
-rw-r--r--Modules/CMakeBackwardCompatibilityCXX.cmake61
-rw-r--r--Modules/CMakeBorlandFindMake.cmake17
-rw-r--r--Modules/CMakeBuildSettings.cmake.in13
-rw-r--r--Modules/CMakeCCompiler.cmake.in63
-rw-r--r--Modules/CMakeCCompilerABI.c28
-rw-r--r--Modules/CMakeCCompilerId.c.in50
-rw-r--r--Modules/CMakeCInformation.cmake219
-rw-r--r--Modules/CMakeCXXCompiler.cmake.in64
-rw-r--r--Modules/CMakeCXXCompilerABI.cpp20
-rw-r--r--Modules/CMakeCXXCompilerId.cpp.in44
-rw-r--r--Modules/CMakeCXXInformation.cmake298
-rw-r--r--Modules/CMakeCheckCompilerFlagCommonPatterns.cmake43
-rw-r--r--Modules/CMakeClDeps.cmake34
-rw-r--r--Modules/CMakeCommonLanguageInclude.cmake133
-rw-r--r--Modules/CMakeCompilerABI.h36
-rw-r--r--Modules/CMakeCompilerIdDetection.cmake157
-rw-r--r--Modules/CMakeConfigurableFile.in1
-rw-r--r--Modules/CMakeDependentOption.cmake59
-rw-r--r--Modules/CMakeDetermineASM-ATTCompiler.cmake20
-rw-r--r--Modules/CMakeDetermineASMCompiler.cmake159
-rw-r--r--Modules/CMakeDetermineASM_MASMCompiler.cmake28
-rw-r--r--Modules/CMakeDetermineASM_NASMCompiler.cmake27
-rw-r--r--Modules/CMakeDetermineCCompiler.cmake176
-rw-r--r--Modules/CMakeDetermineCXXCompiler.cmake175
-rw-r--r--Modules/CMakeDetermineCompileFeatures.cmake94
-rw-r--r--Modules/CMakeDetermineCompiler.cmake115
-rw-r--r--Modules/CMakeDetermineCompilerABI.cmake137
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake581
-rw-r--r--Modules/CMakeDetermineFortranCompiler.cmake204
-rw-r--r--Modules/CMakeDetermineJavaCompiler.cmake104
-rw-r--r--Modules/CMakeDetermineRCCompiler.cmake67
-rw-r--r--Modules/CMakeDetermineSystem.cmake191
-rw-r--r--Modules/CMakeDetermineVSServicePack.cmake184
-rw-r--r--Modules/CMakeExpandImportedTargets.cmake145
-rw-r--r--Modules/CMakeExportBuildSettings.cmake36
-rw-r--r--Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake112
-rw-r--r--Modules/CMakeFindBinUtils.cmake78
-rw-r--r--Modules/CMakeFindCodeBlocks.cmake25
-rw-r--r--Modules/CMakeFindDependencyMacro.cmake85
-rw-r--r--Modules/CMakeFindEclipseCDT4.cmake95
-rw-r--r--Modules/CMakeFindFrameworks.cmake36
-rw-r--r--Modules/CMakeFindJavaCommon.cmake41
-rw-r--r--Modules/CMakeFindKDevelop3.cmake23
-rw-r--r--Modules/CMakeFindKate.cmake31
-rw-r--r--Modules/CMakeFindPackageMode.cmake199
-rw-r--r--Modules/CMakeFindWMake.cmake17
-rw-r--r--Modules/CMakeFindXCode.cmake20
-rw-r--r--Modules/CMakeForceCompiler.cmake100
-rw-r--r--Modules/CMakeFortranCompiler.cmake.in57
-rw-r--r--Modules/CMakeFortranCompilerABI.F46
-rw-r--r--Modules/CMakeFortranCompilerId.F.in137
-rw-r--r--Modules/CMakeFortranInformation.cmake245
-rw-r--r--Modules/CMakeGenericSystem.cmake187
-rw-r--r--Modules/CMakeGraphVizOptions.cmake123
-rw-r--r--Modules/CMakeImportBuildSettings.cmake23
-rw-r--r--Modules/CMakeJOMFindMake.cmake18
-rw-r--r--Modules/CMakeJavaCompiler.cmake.in13
-rw-r--r--Modules/CMakeJavaInformation.cmake59
-rw-r--r--Modules/CMakeMSYSFindMake.cmake20
-rw-r--r--Modules/CMakeMinGWFindMake.cmake26
-rw-r--r--Modules/CMakeNMakeFindMake.cmake18
-rw-r--r--Modules/CMakeNinjaFindMake.cmake17
-rw-r--r--Modules/CMakePackageConfigHelpers.cmake321
-rw-r--r--Modules/CMakeParseArguments.cmake160
-rw-r--r--Modules/CMakeParseImplicitLinkInfo.cmake168
-rw-r--r--Modules/CMakePlatformId.h.in206
-rw-r--r--Modules/CMakePrintHelpers.cmake162
-rw-r--r--Modules/CMakePrintSystemInformation.cmake50
-rw-r--r--Modules/CMakePushCheckState.cmake94
-rw-r--r--Modules/CMakeRCCompiler.cmake.in6
-rw-r--r--Modules/CMakeRCInformation.cmake54
-rw-r--r--Modules/CMakeSystem.cmake.in15
-rw-r--r--Modules/CMakeSystemSpecificInformation.cmake69
-rw-r--r--Modules/CMakeSystemSpecificInitialize.cmake20
-rw-r--r--Modules/CMakeTestASM-ATTCompiler.cmake23
-rw-r--r--Modules/CMakeTestASMCompiler.cmake35
-rw-r--r--Modules/CMakeTestASM_MASMCompiler.cmake23
-rw-r--r--Modules/CMakeTestASM_NASMCompiler.cmake23
-rw-r--r--Modules/CMakeTestCCompiler.cmake96
-rw-r--r--Modules/CMakeTestCXXCompiler.cmake89
-rw-r--r--Modules/CMakeTestCompilerCommon.cmake21
-rw-r--r--Modules/CMakeTestFortranCompiler.cmake111
-rw-r--r--Modules/CMakeTestGNU.c9
-rw-r--r--Modules/CMakeTestJavaCompiler.cmake20
-rw-r--r--Modules/CMakeTestRCCompiler.cmake23
-rw-r--r--Modules/CMakeTestWatcomVersion.c1
-rw-r--r--Modules/CMakeUnixFindMake.cmake26
-rw-r--r--Modules/CMakeVS6BackwardCompatibility.cmake26
-rw-r--r--Modules/CMakeVS7BackwardCompatibility.cmake26
-rw-r--r--Modules/CMakeVerifyManifest.cmake120
-rw-r--r--Modules/CPack.DS_Store.inbin0 -> 12292 bytes
-rw-r--r--Modules/CPack.Description.plist.in12
-rw-r--r--Modules/CPack.Info.plist.in37
-rwxr-xr-xModules/CPack.OSXScriptLauncher.inbin0 -> 29592 bytes
-rw-r--r--Modules/CPack.OSXScriptLauncher.rsrc.inbin0 -> 362 bytes
-rw-r--r--Modules/CPack.OSXX11.Info.plist.in49
-rw-r--r--Modules/CPack.OSXX11.main.scpt.inbin0 -> 1870 bytes
-rwxr-xr-xModules/CPack.RuntimeScript.in87
-rwxr-xr-xModules/CPack.STGZ_Header.sh.in141
-rw-r--r--Modules/CPack.VolumeIcon.icns.inbin0 -> 45739 bytes
-rw-r--r--Modules/CPack.background.png.inbin0 -> 47076 bytes
-rw-r--r--Modules/CPack.cmake613
-rw-r--r--Modules/CPack.distribution.dist.in9
-rw-r--r--Modules/CPackBundle.cmake50
-rw-r--r--Modules/CPackComponent.cmake539
-rw-r--r--Modules/CPackCygwin.cmake37
-rw-r--r--Modules/CPackDMG.cmake69
-rw-r--r--Modules/CPackDeb.cmake455
-rw-r--r--Modules/CPackIFW.cmake517
-rw-r--r--Modules/CPackNSIS.cmake135
-rw-r--r--Modules/CPackPackageMaker.cmake37
-rw-r--r--Modules/CPackRPM.cmake1102
-rw-r--r--Modules/CPackWIX.cmake264
-rw-r--r--Modules/CPackZIP.cmake41
-rw-r--r--Modules/CTest.cmake300
-rw-r--r--Modules/CTestScriptMode.cmake30
-rw-r--r--Modules/CTestTargets.cmake99
-rw-r--r--Modules/CTestUseLaunchers.cmake77
-rw-r--r--Modules/CheckCCompilerFlag.cmake64
-rw-r--r--Modules/CheckCSourceCompiles.cmake111
-rw-r--r--Modules/CheckCSourceRuns.cmake107
-rw-r--r--Modules/CheckCXXCompilerFlag.cmake64
-rw-r--r--Modules/CheckCXXSourceCompiles.cmake112
-rw-r--r--Modules/CheckCXXSourceRuns.cmake107
-rw-r--r--Modules/CheckCXXSymbolExists.cmake49
-rw-r--r--Modules/CheckForPthreads.c38
-rw-r--r--Modules/CheckFortranFunctionExists.cmake78
-rw-r--r--Modules/CheckFortranSourceCompiles.cmake111
-rw-r--r--Modules/CheckFunctionExists.c23
-rw-r--r--Modules/CheckFunctionExists.cmake86
-rw-r--r--Modules/CheckIncludeFile.c.in13
-rw-r--r--Modules/CheckIncludeFile.cmake95
-rw-r--r--Modules/CheckIncludeFile.cxx.in6
-rw-r--r--Modules/CheckIncludeFileCXX.cmake99
-rw-r--r--Modules/CheckIncludeFiles.cmake102
-rw-r--r--Modules/CheckLanguage.cmake78
-rw-r--r--Modules/CheckLibraryExists.cmake86
-rw-r--r--Modules/CheckLibraryExists.lists.in8
-rw-r--r--Modules/CheckPrototypeDefinition.c.in29
-rw-r--r--Modules/CheckPrototypeDefinition.cmake119
-rw-r--r--Modules/CheckSizeOf.cmake18
-rw-r--r--Modules/CheckStructHasMember.cmake85
-rw-r--r--Modules/CheckSymbolExists.cmake113
-rw-r--r--Modules/CheckTypeSize.c.in37
-rw-r--r--Modules/CheckTypeSize.cmake273
-rw-r--r--Modules/CheckTypeSizeMap.cmake.in1
-rw-r--r--Modules/CheckVariableExists.c20
-rw-r--r--Modules/CheckVariableExists.cmake85
-rw-r--r--Modules/Compiler/ADSP-DetermineCompiler.cmake10
-rw-r--r--Modules/Compiler/Absoft-Fortran.cmake10
-rw-r--r--Modules/Compiler/AppleClang-ASM.cmake1
-rw-r--r--Modules/Compiler/AppleClang-C.cmake1
-rw-r--r--Modules/Compiler/AppleClang-CXX.cmake6
-rw-r--r--Modules/Compiler/AppleClang-DetermineCompiler.cmake7
-rw-r--r--Modules/Compiler/Borland-DetermineCompiler.cmake7
-rw-r--r--Modules/Compiler/Clang-ASM.cmake5
-rw-r--r--Modules/Compiler/Clang-C-FeatureTests.cmake11
-rw-r--r--Modules/Compiler/Clang-C.cmake38
-rw-r--r--Modules/Compiler/Clang-CXX-FeatureTests.cmake86
-rw-r--r--Modules/Compiler/Clang-CXX.cmake52
-rw-r--r--Modules/Compiler/Clang-DetermineCompiler.cmake4
-rw-r--r--Modules/Compiler/Clang-DetermineCompilerInternal.cmake15
-rw-r--r--Modules/Compiler/Clang.cmake41
-rw-r--r--Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake7
-rw-r--r--Modules/Compiler/Compaq-C-DetermineCompiler.cmake8
-rw-r--r--Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake8
-rw-r--r--Modules/Compiler/Cray-C.cmake1
-rw-r--r--Modules/Compiler/Cray-CXX.cmake1
-rw-r--r--Modules/Compiler/Cray-DetermineCompiler.cmake6
-rw-r--r--Modules/Compiler/Cray-Fortran.cmake6
-rw-r--r--Modules/Compiler/Embarcadero-DetermineCompiler.cmake7
-rw-r--r--Modules/Compiler/Fujitsu-DetermineCompiler.cmake2
-rw-r--r--Modules/Compiler/G95-Fortran.cmake9
-rw-r--r--Modules/Compiler/GNU-ASM.cmake6
-rw-r--r--Modules/Compiler/GNU-C-FeatureTests.cmake12
-rw-r--r--Modules/Compiler/GNU-C.cmake34
-rw-r--r--Modules/Compiler/GNU-CXX-FeatureTests.cmake98
-rw-r--r--Modules/Compiler/GNU-CXX.cmake53
-rw-r--r--Modules/Compiler/GNU-DetermineCompiler.cmake9
-rw-r--r--Modules/Compiler/GNU-Fortran.cmake17
-rw-r--r--Modules/Compiler/GNU.cmake58
-rw-r--r--Modules/Compiler/HP-ASM.cmake3
-rw-r--r--Modules/Compiler/HP-C-DetermineCompiler.cmake8
-rw-r--r--Modules/Compiler/HP-C.cmake4
-rw-r--r--Modules/Compiler/HP-CXX-DetermineCompiler.cmake8
-rw-r--r--Modules/Compiler/HP-CXX.cmake13
-rw-r--r--Modules/Compiler/HP-Fortran.cmake3
-rw-r--r--Modules/Compiler/IAR-ASM.cmake14
-rw-r--r--Modules/Compiler/IAR-C.cmake34
-rw-r--r--Modules/Compiler/IAR-CXX.cmake34
-rw-r--r--Modules/Compiler/IAR-DetermineCompiler.cmake4
-rw-r--r--Modules/Compiler/IAR.cmake46
-rw-r--r--Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake6
-rw-r--r--Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake6
-rw-r--r--Modules/Compiler/Intel-ASM.cmake13
-rw-r--r--Modules/Compiler/Intel-C.cmake12
-rw-r--r--Modules/Compiler/Intel-CXX.cmake12
-rw-r--r--Modules/Compiler/Intel-DetermineCompiler.cmake26
-rw-r--r--Modules/Compiler/Intel-Fortran.cmake9
-rw-r--r--Modules/Compiler/MIPSpro-C.cmake1
-rw-r--r--Modules/Compiler/MIPSpro-CXX.cmake1
-rw-r--r--Modules/Compiler/MIPSpro-DetermineCompiler.cmake15
-rw-r--r--Modules/Compiler/MIPSpro-Fortran.cmake3
-rw-r--r--Modules/Compiler/MSVC-DetermineCompiler.cmake19
-rw-r--r--Modules/Compiler/NAG-Fortran.cmake35
-rw-r--r--Modules/Compiler/OpenWatcom-DetermineCompiler.cmake10
-rw-r--r--Modules/Compiler/PGI-C.cmake4
-rw-r--r--Modules/Compiler/PGI-CXX.cmake4
-rw-r--r--Modules/Compiler/PGI-DetermineCompiler.cmake9
-rw-r--r--Modules/Compiler/PGI-Fortran.cmake15
-rw-r--r--Modules/Compiler/PGI.cmake35
-rw-r--r--Modules/Compiler/PathScale-C.cmake4
-rw-r--r--Modules/Compiler/PathScale-CXX.cmake4
-rw-r--r--Modules/Compiler/PathScale-DetermineCompiler.cmake9
-rw-r--r--Modules/Compiler/PathScale-Fortran.cmake6
-rw-r--r--Modules/Compiler/PathScale.cmake31
-rw-r--r--Modules/Compiler/QCC-C.cmake2
-rw-r--r--Modules/Compiler/QCC-CXX.cmake12
-rw-r--r--Modules/Compiler/QCC.cmake24
-rw-r--r--Modules/Compiler/SCO-C.cmake2
-rw-r--r--Modules/Compiler/SCO-CXX.cmake2
-rw-r--r--Modules/Compiler/SCO-DetermineCompiler.cmake2
-rw-r--r--Modules/Compiler/SCO.cmake28
-rw-r--r--Modules/Compiler/SDCC-C-DetermineCompiler.cmake10
-rw-r--r--Modules/Compiler/SunPro-ASM.cmake24
-rw-r--r--Modules/Compiler/SunPro-C-DetermineCompiler.cmake15
-rw-r--r--Modules/Compiler/SunPro-C.cmake27
-rw-r--r--Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake15
-rw-r--r--Modules/Compiler/SunPro-CXX.cmake33
-rw-r--r--Modules/Compiler/SunPro-Fortran.cmake18
-rw-r--r--Modules/Compiler/TI-ASM.cmake8
-rw-r--r--Modules/Compiler/TI-C.cmake10
-rw-r--r--Modules/Compiler/TI-CXX.cmake10
-rw-r--r--Modules/Compiler/TI-DetermineCompiler.cmake8
-rw-r--r--Modules/Compiler/TinyCC-C-DetermineCompiler.cmake2
-rw-r--r--Modules/Compiler/TinyCC-C.cmake8
-rw-r--r--Modules/Compiler/VisualAge-C-DetermineCompiler.cmake4
-rw-r--r--Modules/Compiler/VisualAge-C.cmake1
-rw-r--r--Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake4
-rw-r--r--Modules/Compiler/VisualAge-CXX.cmake1
-rw-r--r--Modules/Compiler/VisualAge-Fortran.cmake1
-rw-r--r--Modules/Compiler/Watcom-DetermineCompiler.cmake10
-rw-r--r--Modules/Compiler/XL-ASM.cmake13
-rw-r--r--Modules/Compiler/XL-C-DetermineCompiler.cmake4
-rw-r--r--Modules/Compiler/XL-C.cmake9
-rw-r--r--Modules/Compiler/XL-CXX-DetermineCompiler.cmake4
-rw-r--r--Modules/Compiler/XL-CXX.cmake11
-rw-r--r--Modules/Compiler/XL-Fortran.cmake17
-rw-r--r--Modules/Compiler/XL.cmake54
-rw-r--r--Modules/Compiler/zOS-C-DetermineCompiler.cmake4
-rw-r--r--Modules/Compiler/zOS-CXX-DetermineCompiler.cmake4
-rw-r--r--Modules/CompilerId/VS-10.vcxproj.in55
-rw-r--r--Modules/CompilerId/VS-6.dsp.in48
-rw-r--r--Modules/CompilerId/VS-7.vcproj.in60
-rw-r--r--Modules/CompilerId/VS-Intel.vfproj.in42
-rw-r--r--Modules/CompilerId/VS-NsightTegra.vcxproj.in56
-rw-r--r--Modules/CompilerId/Xcode-1.pbxproj.in120
-rw-r--r--Modules/CompilerId/Xcode-2.pbxproj.in119
-rw-r--r--Modules/CompilerId/Xcode-3.pbxproj.in110
-rw-r--r--Modules/Dart.cmake134
-rw-r--r--Modules/DartConfiguration.tcl.in106
-rw-r--r--Modules/DeployQt4.cmake332
-rw-r--r--Modules/Documentation.cmake57
-rw-r--r--Modules/DummyCXXFile.cxx4
-rw-r--r--Modules/ExternalData.cmake828
-rw-r--r--Modules/ExternalData_config.cmake.in4
-rw-r--r--Modules/ExternalProject.cmake1992
-rw-r--r--Modules/FLTKCompatibility.cmake15
-rw-r--r--Modules/FeatureSummary.cmake573
-rw-r--r--Modules/FindALSA.cmake65
-rw-r--r--Modules/FindASPELL.cmake44
-rw-r--r--Modules/FindAVIFile.cmake55
-rw-r--r--Modules/FindArmadillo.cmake108
-rw-r--r--Modules/FindBISON.cmake196
-rw-r--r--Modules/FindBLAS.cmake694
-rw-r--r--Modules/FindBZip2.cmake67
-rw-r--r--Modules/FindBacktrace.cmake95
-rw-r--r--Modules/FindBoost.cmake1233
-rw-r--r--Modules/FindBullet.cmake105
-rw-r--r--Modules/FindCABLE.cmake91
-rw-r--r--Modules/FindCUDA.cmake1680
-rw-r--r--Modules/FindCUDA/make2cmake.cmake92
-rw-r--r--Modules/FindCUDA/parse_cubin.cmake111
-rw-r--r--Modules/FindCUDA/run_nvcc.cmake288
-rw-r--r--Modules/FindCURL.cmake68
-rw-r--r--Modules/FindCVS.cmake82
-rw-r--r--Modules/FindCoin3D.cmake91
-rw-r--r--Modules/FindCups.cmake79
-rw-r--r--Modules/FindCurses.cmake220
-rw-r--r--Modules/FindCxxTest.cmake250
-rw-r--r--Modules/FindCygwin.cmake31
-rw-r--r--Modules/FindDCMTK.cmake157
-rw-r--r--Modules/FindDart.cmake44
-rw-r--r--Modules/FindDevIL.cmake83
-rw-r--r--Modules/FindDoxygen.cmake171
-rw-r--r--Modules/FindEXPAT.cmake66
-rw-r--r--Modules/FindFLEX.cmake202
-rw-r--r--Modules/FindFLTK.cmake334
-rw-r--r--Modules/FindFLTK2.cmake277
-rw-r--r--Modules/FindFreetype.cmake164
-rw-r--r--Modules/FindGCCXML.cmake36
-rw-r--r--Modules/FindGDAL.cmake119
-rw-r--r--Modules/FindGIF.cmake86
-rw-r--r--Modules/FindGLEW.cmake54
-rw-r--r--Modules/FindGLU.cmake28
-rw-r--r--Modules/FindGLUT.cmake176
-rw-r--r--Modules/FindGTK.cmake168
-rw-r--r--Modules/FindGTK2.cmake902
-rw-r--r--Modules/FindGTest.cmake212
-rw-r--r--Modules/FindGettext.cmake234
-rw-r--r--Modules/FindGit.cmake75
-rw-r--r--Modules/FindGnuTLS.cmake77
-rw-r--r--Modules/FindGnuplot.cmake67
-rw-r--r--Modules/FindHDF5.cmake364
-rw-r--r--Modules/FindHSPELL.cmake58
-rw-r--r--Modules/FindHTMLHelp.cmake61
-rw-r--r--Modules/FindHg.cmake96
-rw-r--r--Modules/FindIce.cmake393
-rw-r--r--Modules/FindIcotool.cmake63
-rw-r--r--Modules/FindImageMagick.cmake297
-rw-r--r--Modules/FindJNI.cmake307
-rw-r--r--Modules/FindJPEG.cmake54
-rw-r--r--Modules/FindJasper.cmake60
-rw-r--r--Modules/FindJava.cmake226
-rw-r--r--Modules/FindKDE3.cmake367
-rw-r--r--Modules/FindKDE4.cmake113
-rw-r--r--Modules/FindLAPACK.cmake355
-rw-r--r--Modules/FindLATEX.cmake133
-rw-r--r--Modules/FindLibArchive.cmake74
-rw-r--r--Modules/FindLibLZMA.cmake80
-rw-r--r--Modules/FindLibXml2.cmake73
-rw-r--r--Modules/FindLibXslt.cmake86
-rw-r--r--Modules/FindLua.cmake171
-rw-r--r--Modules/FindLua50.cmake108
-rw-r--r--Modules/FindLua51.cmake99
-rw-r--r--Modules/FindMFC.cmake69
-rw-r--r--Modules/FindMPEG.cmake56
-rw-r--r--Modules/FindMPEG2.cmake66
-rw-r--r--Modules/FindMPI.cmake658
-rw-r--r--Modules/FindMatlab.cmake128
-rw-r--r--Modules/FindMotif.cmake52
-rw-r--r--Modules/FindOpenAL.cmake103
-rw-r--r--Modules/FindOpenCL.cmake136
-rw-r--r--Modules/FindOpenGL.cmake229
-rw-r--r--Modules/FindOpenMP.cmake239
-rw-r--r--Modules/FindOpenSSL.cmake334
-rw-r--r--Modules/FindOpenSceneGraph.cmake240
-rw-r--r--Modules/FindOpenThreads.cmake135
-rw-r--r--Modules/FindPHP4.cmake91
-rw-r--r--Modules/FindPNG.cmake122
-rw-r--r--Modules/FindPackageHandleStandardArgs.cmake380
-rw-r--r--Modules/FindPackageMessage.cmake57
-rw-r--r--Modules/FindPerl.cmake90
-rw-r--r--Modules/FindPerlLibs.cmake269
-rw-r--r--Modules/FindPhysFS.cmake60
-rw-r--r--Modules/FindPike.cmake43
-rw-r--r--Modules/FindPkgConfig.cmake577
-rw-r--r--Modules/FindPostgreSQL.cmake186
-rw-r--r--Modules/FindProducer.cmake81
-rw-r--r--Modules/FindProtobuf.cmake296
-rw-r--r--Modules/FindPythonInterp.cmake164
-rw-r--r--Modules/FindPythonLibs.cmake294
-rw-r--r--Modules/FindQt.cmake188
-rw-r--r--Modules/FindQt3.cmake326
-rw-r--r--Modules/FindQt4.cmake1343
-rw-r--r--Modules/FindQuickTime.cmake45
-rw-r--r--Modules/FindRTI.cmake112
-rw-r--r--Modules/FindRuby.cmake279
-rw-r--r--Modules/FindSDL.cmake201
-rw-r--r--Modules/FindSDL_image.cmake110
-rw-r--r--Modules/FindSDL_mixer.cmake110
-rw-r--r--Modules/FindSDL_net.cmake110
-rw-r--r--Modules/FindSDL_sound.cmake407
-rw-r--r--Modules/FindSDL_ttf.cmake110
-rw-r--r--Modules/FindSWIG.cmake78
-rw-r--r--Modules/FindSelfPackers.cmake75
-rw-r--r--Modules/FindSquish.cmake306
-rw-r--r--Modules/FindSubversion.cmake158
-rw-r--r--Modules/FindTCL.cmake235
-rw-r--r--Modules/FindTIFF.cmake59
-rw-r--r--Modules/FindTclStub.cmake150
-rw-r--r--Modules/FindTclsh.cmake109
-rw-r--r--Modules/FindThreads.cmake216
-rw-r--r--Modules/FindUnixCommands.cmake97
-rw-r--r--Modules/FindWget.cmake43
-rw-r--r--Modules/FindWish.cmake94
-rw-r--r--Modules/FindX11.cmake512
-rw-r--r--Modules/FindXMLRPC.cmake159
-rw-r--r--Modules/FindXerces.cmake85
-rw-r--r--Modules/FindZLIB.cmake123
-rw-r--r--Modules/Findosg.cmake60
-rw-r--r--Modules/FindosgAnimation.cmake55
-rw-r--r--Modules/FindosgDB.cmake55
-rw-r--r--Modules/FindosgFX.cmake55
-rw-r--r--Modules/FindosgGA.cmake55
-rw-r--r--Modules/FindosgIntrospection.cmake56
-rw-r--r--Modules/FindosgManipulator.cmake56
-rw-r--r--Modules/FindosgParticle.cmake55
-rw-r--r--Modules/FindosgPresentation.cmake57
-rw-r--r--Modules/FindosgProducer.cmake55
-rw-r--r--Modules/FindosgQt.cmake55
-rw-r--r--Modules/FindosgShadow.cmake55
-rw-r--r--Modules/FindosgSim.cmake55
-rw-r--r--Modules/FindosgTerrain.cmake55
-rw-r--r--Modules/FindosgText.cmake55
-rw-r--r--Modules/FindosgUtil.cmake55
-rw-r--r--Modules/FindosgViewer.cmake55
-rw-r--r--Modules/FindosgVolume.cmake55
-rw-r--r--Modules/FindosgWidget.cmake56
-rw-r--r--Modules/Findosg_functions.cmake118
-rw-r--r--Modules/FindwxWidgets.cmake1082
-rw-r--r--Modules/FindwxWindows.cmake737
-rw-r--r--Modules/FortranCInterface.cmake341
-rw-r--r--Modules/FortranCInterface/CMakeLists.txt108
-rw-r--r--Modules/FortranCInterface/Detect.cmake182
-rw-r--r--Modules/FortranCInterface/Input.cmake.in3
-rw-r--r--Modules/FortranCInterface/Macro.h.in4
-rw-r--r--Modules/FortranCInterface/Output.cmake.in33
-rw-r--r--Modules/FortranCInterface/Verify/CMakeLists.txt34
-rw-r--r--Modules/FortranCInterface/Verify/VerifyC.c5
-rw-r--r--Modules/FortranCInterface/Verify/VerifyCXX.cxx4
-rw-r--r--Modules/FortranCInterface/Verify/VerifyFortran.f3
-rw-r--r--Modules/FortranCInterface/Verify/main.c16
-rw-r--r--Modules/FortranCInterface/call_mod.f906
-rw-r--r--Modules/FortranCInterface/call_sub.f4
-rw-r--r--Modules/FortranCInterface/main.F6
-rw-r--r--Modules/FortranCInterface/my_module.f908
-rw-r--r--Modules/FortranCInterface/my_module_.c1
-rw-r--r--Modules/FortranCInterface/my_sub.f2
-rw-r--r--Modules/FortranCInterface/mymodule.f908
-rw-r--r--Modules/FortranCInterface/mymodule_.c1
-rw-r--r--Modules/FortranCInterface/mysub.f2
-rw-r--r--Modules/FortranCInterface/symbol.c.in4
-rw-r--r--Modules/GNUInstallDirs.cmake271
-rw-r--r--Modules/GenerateExportHeader.cmake403
-rw-r--r--Modules/GetPrerequisites.cmake955
-rw-r--r--Modules/ITKCompatibility.cmake17
-rw-r--r--Modules/InstallRequiredSystemLibraries.cmake483
-rw-r--r--Modules/IntelVSImplicitPath/CMakeLists.txt7
-rw-r--r--Modules/IntelVSImplicitPath/detect.cmake9
-rw-r--r--Modules/IntelVSImplicitPath/hello.f0
-rw-r--r--Modules/Internal/FeatureTesting.cmake60
-rw-r--r--Modules/KDE3Macros.cmake410
-rw-r--r--Modules/MacOSXBundleInfo.plist.in36
-rw-r--r--Modules/MacOSXFrameworkInfo.plist.in26
-rw-r--r--Modules/MacroAddFileDependencies.cmake39
-rw-r--r--Modules/NSIS.InstallOptions.ini.in46
-rw-r--r--Modules/NSIS.template.in977
-rw-r--r--Modules/Platform/AIX-GNU-ASM.cmake2
-rw-r--r--Modules/Platform/AIX-GNU-C.cmake2
-rw-r--r--Modules/Platform/AIX-GNU-CXX.cmake2
-rw-r--r--Modules/Platform/AIX-GNU-Fortran.cmake2
-rw-r--r--Modules/Platform/AIX-GNU.cmake27
-rw-r--r--Modules/Platform/AIX-VisualAge-C.cmake1
-rw-r--r--Modules/Platform/AIX-VisualAge-CXX.cmake1
-rw-r--r--Modules/Platform/AIX-VisualAge-Fortran.cmake1
-rw-r--r--Modules/Platform/AIX-XL-ASM.cmake2
-rw-r--r--Modules/Platform/AIX-XL-C.cmake2
-rw-r--r--Modules/Platform/AIX-XL-CXX.cmake2
-rw-r--r--Modules/Platform/AIX-XL-Fortran.cmake2
-rw-r--r--Modules/Platform/AIX-XL.cmake28
-rw-r--r--Modules/Platform/AIX.cmake29
-rw-r--r--Modules/Platform/Android.cmake15
-rw-r--r--Modules/Platform/BSDOS.cmake2
-rw-r--r--Modules/Platform/BeOS.cmake12
-rw-r--r--Modules/Platform/BlueGeneL.cmake40
-rw-r--r--Modules/Platform/BlueGeneP-base.cmake125
-rw-r--r--Modules/Platform/BlueGeneP-dynamic-GNU-C.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-dynamic-GNU-CXX.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-dynamic-GNU-Fortran.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-dynamic-XL-C.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-dynamic-XL-CXX.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-dynamic-XL-Fortran.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-dynamic.cmake19
-rw-r--r--Modules/Platform/BlueGeneP-static-GNU-C.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-static-GNU-CXX.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-static-GNU-Fortran.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-static-XL-C.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-static-XL-CXX.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-static-XL-Fortran.cmake16
-rw-r--r--Modules/Platform/BlueGeneP-static.cmake19
-rw-r--r--Modules/Platform/CYGWIN-CXX.cmake7
-rw-r--r--Modules/Platform/CYGWIN-GNU-C.cmake2
-rw-r--r--Modules/Platform/CYGWIN-GNU-CXX.cmake2
-rw-r--r--Modules/Platform/CYGWIN-GNU-Fortran.cmake2
-rw-r--r--Modules/Platform/CYGWIN-GNU.cmake56
-rw-r--r--Modules/Platform/CYGWIN-windres.cmake1
-rw-r--r--Modules/Platform/CYGWIN.cmake64
-rw-r--r--Modules/Platform/Catamount.cmake26
-rw-r--r--Modules/Platform/Darwin-Absoft-Fortran.cmake18
-rw-r--r--Modules/Platform/Darwin-AppleClang-C.cmake1
-rw-r--r--Modules/Platform/Darwin-AppleClang-CXX.cmake1
-rw-r--r--Modules/Platform/Darwin-CXX.cmake7
-rw-r--r--Modules/Platform/Darwin-Clang-C.cmake2
-rw-r--r--Modules/Platform/Darwin-Clang-CXX.cmake2
-rw-r--r--Modules/Platform/Darwin-Clang.cmake30
-rw-r--r--Modules/Platform/Darwin-GNU-C.cmake4
-rw-r--r--Modules/Platform/Darwin-GNU-CXX.cmake4
-rw-r--r--Modules/Platform/Darwin-GNU-Fortran.cmake19
-rw-r--r--Modules/Platform/Darwin-GNU.cmake70
-rw-r--r--Modules/Platform/Darwin-Initialize.cmake151
-rw-r--r--Modules/Platform/Darwin-Intel-C.cmake2
-rw-r--r--Modules/Platform/Darwin-Intel-CXX.cmake2
-rw-r--r--Modules/Platform/Darwin-Intel-Fortran.cmake18
-rw-r--r--Modules/Platform/Darwin-Intel.cmake29
-rw-r--r--Modules/Platform/Darwin-NAG-Fortran.cmake26
-rw-r--r--Modules/Platform/Darwin-VisualAge-C.cmake1
-rw-r--r--Modules/Platform/Darwin-VisualAge-CXX.cmake1
-rw-r--r--Modules/Platform/Darwin-XL-C.cmake5
-rw-r--r--Modules/Platform/Darwin-XL-CXX.cmake5
-rw-r--r--Modules/Platform/Darwin.cmake226
-rw-r--r--Modules/Platform/DragonFly.cmake5
-rw-r--r--Modules/Platform/FreeBSD.cmake26
-rw-r--r--Modules/Platform/GNU.cmake13
-rw-r--r--Modules/Platform/GNUtoMS_lib.bat.in3
-rw-r--r--Modules/Platform/GNUtoMS_lib.cmake10
-rw-r--r--Modules/Platform/Generic-ADSP-ASM.cmake7
-rw-r--r--Modules/Platform/Generic-ADSP-C.cmake20
-rw-r--r--Modules/Platform/Generic-ADSP-CXX.cmake18
-rw-r--r--Modules/Platform/Generic-ADSP-Common.cmake120
-rw-r--r--Modules/Platform/Generic-SDCC-C.cmake54
-rw-r--r--Modules/Platform/Generic.cmake17
-rw-r--r--Modules/Platform/HP-UX-GNU-C.cmake2
-rw-r--r--Modules/Platform/HP-UX-GNU-CXX.cmake2
-rw-r--r--Modules/Platform/HP-UX-GNU-Fortran.cmake2
-rw-r--r--Modules/Platform/HP-UX-GNU.cmake27
-rw-r--r--Modules/Platform/HP-UX-HP-ASM.cmake2
-rw-r--r--Modules/Platform/HP-UX-HP-C.cmake6
-rw-r--r--Modules/Platform/HP-UX-HP-CXX.cmake14
-rw-r--r--Modules/Platform/HP-UX-HP-Fortran.cmake2
-rw-r--r--Modules/Platform/HP-UX-HP.cmake31
-rw-r--r--Modules/Platform/HP-UX.cmake50
-rw-r--r--Modules/Platform/Haiku.cmake130
-rw-r--r--Modules/Platform/IRIX.cmake45
-rw-r--r--Modules/Platform/IRIX64.cmake73
-rw-r--r--Modules/Platform/Linux-Absoft-Fortran.cmake1
-rw-r--r--Modules/Platform/Linux-CXX.cmake3
-rw-r--r--Modules/Platform/Linux-Clang-C.cmake1
-rw-r--r--Modules/Platform/Linux-Clang-CXX.cmake1
-rw-r--r--Modules/Platform/Linux-GNU-C.cmake2
-rw-r--r--Modules/Platform/Linux-GNU-CXX.cmake2
-rw-r--r--Modules/Platform/Linux-GNU-Fortran.cmake2
-rw-r--r--Modules/Platform/Linux-GNU.cmake25
-rw-r--r--Modules/Platform/Linux-Intel-C.cmake3
-rw-r--r--Modules/Platform/Linux-Intel-CXX.cmake3
-rw-r--r--Modules/Platform/Linux-Intel-Fortran.cmake4
-rw-r--r--Modules/Platform/Linux-Intel.cmake54
-rw-r--r--Modules/Platform/Linux-NAG-Fortran.cmake10
-rw-r--r--Modules/Platform/Linux-PGI-C.cmake2
-rw-r--r--Modules/Platform/Linux-PGI-CXX.cmake2
-rw-r--r--Modules/Platform/Linux-PGI-Fortran.cmake2
-rw-r--r--Modules/Platform/Linux-PGI.cmake27
-rw-r--r--Modules/Platform/Linux-PathScale-C.cmake2
-rw-r--r--Modules/Platform/Linux-PathScale-CXX.cmake2
-rw-r--r--Modules/Platform/Linux-PathScale-Fortran.cmake2
-rw-r--r--Modules/Platform/Linux-PathScale.cmake27
-rw-r--r--Modules/Platform/Linux-SunPro-CXX.cmake9
-rw-r--r--Modules/Platform/Linux-TinyCC-C.cmake4
-rw-r--r--Modules/Platform/Linux-VisualAge-C.cmake1
-rw-r--r--Modules/Platform/Linux-VisualAge-CXX.cmake1
-rw-r--r--Modules/Platform/Linux-VisualAge-Fortran.cmake1
-rw-r--r--Modules/Platform/Linux-XL-C.cmake1
-rw-r--r--Modules/Platform/Linux-XL-CXX.cmake1
-rw-r--r--Modules/Platform/Linux-XL-Fortran.cmake1
-rw-r--r--Modules/Platform/Linux-como.cmake17
-rw-r--r--Modules/Platform/Linux.cmake57
-rw-r--r--Modules/Platform/MP-RAS.cmake14
-rw-r--r--Modules/Platform/MirBSD.cmake1
-rw-r--r--Modules/Platform/NetBSD.cmake13
-rw-r--r--Modules/Platform/OSF1.cmake47
-rw-r--r--Modules/Platform/OpenBSD.cmake38
-rw-r--r--Modules/Platform/OpenVMS.cmake8
-rw-r--r--Modules/Platform/QNX.cmake19
-rw-r--r--Modules/Platform/RISCos.cmake6
-rw-r--r--Modules/Platform/SCO_SV.cmake2
-rw-r--r--Modules/Platform/SINIX.cmake4
-rw-r--r--Modules/Platform/SunOS-GNU-C.cmake2
-rw-r--r--Modules/Platform/SunOS-GNU-CXX.cmake2
-rw-r--r--Modules/Platform/SunOS-GNU-Fortran.cmake2
-rw-r--r--Modules/Platform/SunOS-GNU.cmake34
-rw-r--r--Modules/Platform/SunOS.cmake32
-rw-r--r--Modules/Platform/Tru64.cmake2
-rw-r--r--Modules/Platform/ULTRIX.cmake5
-rw-r--r--Modules/Platform/UNIX_SV.cmake5
-rw-r--r--Modules/Platform/UnixPaths.cmake97
-rw-r--r--Modules/Platform/UnixWare.cmake5
-rw-r--r--Modules/Platform/Windows-Borland-C.cmake1
-rw-r--r--Modules/Platform/Windows-Borland-CXX.cmake1
-rw-r--r--Modules/Platform/Windows-CXX.cmake7
-rw-r--r--Modules/Platform/Windows-Clang-C.cmake2
-rw-r--r--Modules/Platform/Windows-Clang-CXX.cmake2
-rw-r--r--Modules/Platform/Windows-Clang.cmake32
-rw-r--r--Modules/Platform/Windows-Embarcadero-C.cmake3
-rw-r--r--Modules/Platform/Windows-Embarcadero-CXX.cmake3
-rw-r--r--Modules/Platform/Windows-Embarcadero.cmake131
-rw-r--r--Modules/Platform/Windows-G95-Fortran.cmake1
-rw-r--r--Modules/Platform/Windows-GNU-C-ABI.cmake1
-rw-r--r--Modules/Platform/Windows-GNU-C.cmake2
-rw-r--r--Modules/Platform/Windows-GNU-CXX-ABI.cmake1
-rw-r--r--Modules/Platform/Windows-GNU-CXX.cmake2
-rw-r--r--Modules/Platform/Windows-GNU-Fortran-ABI.cmake1
-rw-r--r--Modules/Platform/Windows-GNU-Fortran.cmake5
-rw-r--r--Modules/Platform/Windows-GNU.cmake196
-rw-r--r--Modules/Platform/Windows-Intel-ASM.cmake2
-rw-r--r--Modules/Platform/Windows-Intel-C.cmake2
-rw-r--r--Modules/Platform/Windows-Intel-CXX.cmake3
-rw-r--r--Modules/Platform/Windows-Intel-Fortran.cmake11
-rw-r--r--Modules/Platform/Windows-Intel.cmake28
-rw-r--r--Modules/Platform/Windows-MSVC-C.cmake5
-rw-r--r--Modules/Platform/Windows-MSVC-CXX.cmake6
-rw-r--r--Modules/Platform/Windows-MSVC.cmake277
-rw-r--r--Modules/Platform/Windows-NMcl.cmake4
-rw-r--r--Modules/Platform/Windows-df.cmake68
-rw-r--r--Modules/Platform/Windows-wcl386.cmake119
-rw-r--r--Modules/Platform/Windows-windres.cmake1
-rw-r--r--Modules/Platform/Windows.cmake44
-rw-r--r--Modules/Platform/WindowsCE-MSVC-C.cmake1
-rw-r--r--Modules/Platform/WindowsCE-MSVC-CXX.cmake1
-rw-r--r--Modules/Platform/WindowsCE.cmake1
-rw-r--r--Modules/Platform/WindowsPaths.cmake116
-rw-r--r--Modules/Platform/WindowsPhone-MSVC-C.cmake1
-rw-r--r--Modules/Platform/WindowsPhone-MSVC-CXX.cmake1
-rw-r--r--Modules/Platform/WindowsPhone.cmake1
-rw-r--r--Modules/Platform/WindowsStore-MSVC-C.cmake1
-rw-r--r--Modules/Platform/WindowsStore-MSVC-CXX.cmake1
-rw-r--r--Modules/Platform/WindowsStore.cmake1
-rw-r--r--Modules/Platform/Xenix.cmake2
-rw-r--r--Modules/Platform/eCos.cmake65
-rw-r--r--Modules/Platform/gas.cmake19
-rw-r--r--Modules/Platform/kFreeBSD.cmake4
-rw-r--r--Modules/Platform/syllable.cmake33
-rw-r--r--Modules/ProcessorCount.cmake231
-rw-r--r--Modules/Qt4ConfigDependentSettings.cmake301
-rw-r--r--Modules/Qt4Macros.cmake509
-rw-r--r--Modules/RepositoryInfo.txt.in3
-rw-r--r--Modules/SelectLibraryConfigurations.cmake81
-rwxr-xr-xModules/Squish4RunTestCase.bat24
-rwxr-xr-xModules/Squish4RunTestCase.sh28
-rwxr-xr-xModules/SquishRunTestCase.bat11
-rwxr-xr-xModules/SquishRunTestCase.sh13
-rw-r--r--Modules/SquishTestScript.cmake95
-rw-r--r--Modules/SystemInformation.cmake103
-rw-r--r--Modules/SystemInformation.in88
-rw-r--r--Modules/TestBigEndian.cmake119
-rw-r--r--Modules/TestCXXAcceptsFlag.cmake51
-rw-r--r--Modules/TestEndianess.c.in23
-rw-r--r--Modules/TestForANSIForScope.cmake52
-rw-r--r--Modules/TestForANSIStreamHeaders.cmake42
-rw-r--r--Modules/TestForANSIStreamHeaders.cxx6
-rw-r--r--Modules/TestForAnsiForScope.cxx7
-rw-r--r--Modules/TestForSSTREAM.cmake50
-rw-r--r--Modules/TestForSSTREAM.cxx11
-rw-r--r--Modules/TestForSTDNamespace.cmake50
-rw-r--r--Modules/TestForSTDNamespace.cxx6
-rw-r--r--Modules/UseEcos.cmake245
-rw-r--r--Modules/UseJava.cmake1075
-rw-r--r--Modules/UseJavaClassFilelist.cmake58
-rw-r--r--Modules/UseJavaSymlinks.cmake38
-rw-r--r--Modules/UsePkgConfig.cmake84
-rw-r--r--Modules/UseQt4.cmake117
-rw-r--r--Modules/UseSWIG.cmake299
-rw-r--r--Modules/UseVTK40.cmake29
-rw-r--r--Modules/UseVTKBuildSettings40.cmake38
-rw-r--r--Modules/UseVTKConfig40.cmake409
-rw-r--r--Modules/Use_wxWindows.cmake79
-rw-r--r--Modules/UsewxWidgets.cmake111
-rw-r--r--Modules/VTKCompatibility.cmake52
-rw-r--r--Modules/WIX.template.in46
-rw-r--r--Modules/WriteBasicConfigVersionFile.cmake58
-rw-r--r--Modules/WriteCompilerDetectionHeader.cmake535
-rw-r--r--Modules/ecos_clean.cmake26
-rw-r--r--Modules/exportheader.cmake.in41
-rw-r--r--Modules/kde3init_dummy.cpp.in6
-rw-r--r--Modules/kde3uic.cmake33
-rw-r--r--Modules/readme.txt4
-rw-r--r--README.rst99
-rw-r--r--Source/.cvsignore5
-rw-r--r--Source/.gitattributes2
-rw-r--r--Source/CMakeInstallDestinations.cmake38
-rw-r--r--Source/CMakeLists.txt674
-rw-r--r--Source/CMakeSourceDir.txt.in1
-rwxr-xr-xSource/CMakeVersion.bash7
-rw-r--r--Source/CMakeVersion.cmake5
-rw-r--r--Source/CMakeVersionCompute.cmake20
-rw-r--r--Source/CMakeVersionSource.cmake37
-rw-r--r--Source/CPack/IFW/cmCPackIFWGenerator.cxx552
-rw-r--r--Source/CPack/IFW/cmCPackIFWGenerator.h135
-rw-r--r--Source/CPack/IFW/cmCPackIFWInstaller.cxx406
-rw-r--r--Source/CPack/IFW/cmCPackIFWInstaller.h95
-rw-r--r--Source/CPack/IFW/cmCPackIFWPackage.cxx540
-rw-r--r--Source/CPack/IFW/cmCPackIFWPackage.h133
-rw-r--r--Source/CPack/OSXLauncherScript.scptbin0 -> 3102 bytes
-rw-r--r--Source/CPack/OSXScriptLauncher.cxx147
-rw-r--r--Source/CPack/WiX/cmCPackWIXGenerator.cxx1175
-rw-r--r--Source/CPack/WiX/cmCPackWIXGenerator.h173
-rw-r--r--Source/CPack/WiX/cmWIXAccessControlList.cxx149
-rw-r--r--Source/CPack/WiX/cmWIXAccessControlList.h46
-rw-r--r--Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx87
-rw-r--r--Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h42
-rw-r--r--Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx102
-rw-r--r--Source/CPack/WiX/cmWIXFeaturesSourceWriter.h39
-rw-r--r--Source/CPack/WiX/cmWIXFilesSourceWriter.cxx201
-rw-r--r--Source/CPack/WiX/cmWIXFilesSourceWriter.h68
-rw-r--r--Source/CPack/WiX/cmWIXPatch.cxx91
-rw-r--r--Source/CPack/WiX/cmWIXPatch.h45
-rw-r--r--Source/CPack/WiX/cmWIXPatchParser.cxx143
-rw-r--r--Source/CPack/WiX/cmWIXPatchParser.h75
-rw-r--r--Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx228
-rw-r--r--Source/CPack/WiX/cmWIXRichTextFormatWriter.h52
-rw-r--r--Source/CPack/WiX/cmWIXShortcut.h29
-rw-r--r--Source/CPack/WiX/cmWIXSourceWriter.cxx217
-rw-r--r--Source/CPack/WiX/cmWIXSourceWriter.h73
-rw-r--r--Source/CPack/bills-comments.txt68
-rw-r--r--Source/CPack/cmCPack7zGenerator.cxx25
-rw-r--r--Source/CPack/cmCPack7zGenerator.h36
-rw-r--r--Source/CPack/cmCPackArchiveGenerator.cxx314
-rw-r--r--Source/CPack/cmCPackArchiveGenerator.h74
-rw-r--r--Source/CPack/cmCPackBundleGenerator.cxx174
-rw-r--r--Source/CPack/cmCPackBundleGenerator.h40
-rw-r--r--Source/CPack/cmCPackComponentGroup.cxx45
-rw-r--r--Source/CPack/cmCPackComponentGroup.h140
-rw-r--r--Source/CPack/cmCPackConfigure.h.in11
-rw-r--r--Source/CPack/cmCPackCygwinBinaryGenerator.cxx92
-rw-r--r--Source/CPack/cmCPackCygwinBinaryGenerator.h38
-rw-r--r--Source/CPack/cmCPackCygwinSourceGenerator.cxx182
-rw-r--r--Source/CPack/cmCPackCygwinSourceGenerator.h40
-rw-r--r--Source/CPack/cmCPackDebGenerator.cxx869
-rw-r--r--Source/CPack/cmCPackDebGenerator.h77
-rw-r--r--Source/CPack/cmCPackDragNDropGenerator.cxx609
-rw-r--r--Source/CPack/cmCPackDragNDropGenerator.h47
-rw-r--r--Source/CPack/cmCPackGenerator.cxx1667
-rw-r--r--Source/CPack/cmCPackGenerator.h330
-rw-r--r--Source/CPack/cmCPackGeneratorFactory.cxx211
-rw-r--r--Source/CPack/cmCPackGeneratorFactory.h59
-rw-r--r--Source/CPack/cmCPackLog.cxx225
-rw-r--r--Source/CPack/cmCPackLog.h155
-rw-r--r--Source/CPack/cmCPackNSISGenerator.cxx1044
-rw-r--r--Source/CPack/cmCPackNSISGenerator.h87
-rw-r--r--Source/CPack/cmCPackOSXX11Generator.cxx311
-rw-r--r--Source/CPack/cmCPackOSXX11Generator.h47
-rw-r--r--Source/CPack/cmCPackPackageMakerGenerator.cxx1041
-rw-r--r--Source/CPack/cmCPackPackageMakerGenerator.h123
-rw-r--r--Source/CPack/cmCPackRPMGenerator.cxx283
-rw-r--r--Source/CPack/cmCPackRPMGenerator.h77
-rw-r--r--Source/CPack/cmCPackSTGZGenerator.cxx139
-rw-r--r--Source/CPack/cmCPackSTGZGenerator.h41
-rw-r--r--Source/CPack/cmCPackTGZGenerator.cxx26
-rw-r--r--Source/CPack/cmCPackTGZGenerator.h35
-rw-r--r--Source/CPack/cmCPackTXZGenerator.cxx25
-rw-r--r--Source/CPack/cmCPackTXZGenerator.h35
-rw-r--r--Source/CPack/cmCPackTarBZip2Generator.cxx25
-rw-r--r--Source/CPack/cmCPackTarBZip2Generator.h34
-rw-r--r--Source/CPack/cmCPackTarCompressGenerator.cxx26
-rw-r--r--Source/CPack/cmCPackTarCompressGenerator.h35
-rw-r--r--Source/CPack/cmCPackZIPGenerator.cxx26
-rw-r--r--Source/CPack/cmCPackZIPGenerator.h36
-rw-r--r--Source/CPack/cpack.cxx486
-rw-r--r--Source/CPack/cygwin.readme69
-rw-r--r--Source/CTest/cmCTestBZR.cxx523
-rw-r--r--Source/CTest/cmCTestBZR.h55
-rw-r--r--Source/CTest/cmCTestBatchTestHandler.cxx143
-rw-r--r--Source/CTest/cmCTestBatchTestHandler.h42
-rw-r--r--Source/CTest/cmCTestBuildAndTestHandler.cxx555
-rw-r--r--Source/CTest/cmCTestBuildAndTestHandler.h80
-rw-r--r--Source/CTest/cmCTestBuildCommand.cxx198
-rw-r--r--Source/CTest/cmCTestBuildCommand.h72
-rw-r--r--Source/CTest/cmCTestBuildHandler.cxx1316
-rw-r--r--Source/CTest/cmCTestBuildHandler.h152
-rw-r--r--Source/CTest/cmCTestCVS.cxx320
-rw-r--r--Source/CTest/cmCTestCVS.h51
-rw-r--r--Source/CTest/cmCTestCommand.h40
-rw-r--r--Source/CTest/cmCTestConfigureCommand.cxx164
-rw-r--r--Source/CTest/cmCTestConfigureCommand.h56
-rw-r--r--Source/CTest/cmCTestConfigureHandler.cxx132
-rw-r--r--Source/CTest/cmCTestConfigureHandler.h39
-rw-r--r--Source/CTest/cmCTestCoverageCommand.cxx74
-rw-r--r--Source/CTest/cmCTestCoverageCommand.h64
-rw-r--r--Source/CTest/cmCTestCoverageHandler.cxx2538
-rw-r--r--Source/CTest/cmCTestCoverageHandler.h150
-rw-r--r--Source/CTest/cmCTestEmptyBinaryDirectoryCommand.cxx36
-rw-r--r--Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h58
-rw-r--r--Source/CTest/cmCTestGIT.cxx653
-rw-r--r--Source/CTest/cmCTestGIT.h57
-rw-r--r--Source/CTest/cmCTestGenericHandler.cxx163
-rw-r--r--Source/CTest/cmCTestGenericHandler.h107
-rw-r--r--Source/CTest/cmCTestGlobalVC.cxx142
-rw-r--r--Source/CTest/cmCTestGlobalVC.h68
-rw-r--r--Source/CTest/cmCTestHG.cxx338
-rw-r--r--Source/CTest/cmCTestHG.h47
-rw-r--r--Source/CTest/cmCTestHandlerCommand.cxx198
-rw-r--r--Source/CTest/cmCTestHandlerCommand.h77
-rw-r--r--Source/CTest/cmCTestLaunch.cxx752
-rw-r--r--Source/CTest/cmCTestLaunch.h106
-rw-r--r--Source/CTest/cmCTestMemCheckCommand.cxx36
-rw-r--r--Source/CTest/cmCTestMemCheckCommand.h54
-rw-r--r--Source/CTest/cmCTestMemCheckHandler.cxx1300
-rw-r--r--Source/CTest/cmCTestMemCheckHandler.h157
-rw-r--r--Source/CTest/cmCTestMultiProcessHandler.cxx809
-rw-r--r--Source/CTest/cmCTestMultiProcessHandler.h123
-rw-r--r--Source/CTest/cmCTestP4.cxx568
-rw-r--r--Source/CTest/cmCTestP4.h71
-rw-r--r--Source/CTest/cmCTestReadCustomFilesCommand.cxx34
-rw-r--r--Source/CTest/cmCTestReadCustomFilesCommand.h56
-rw-r--r--Source/CTest/cmCTestRunScriptCommand.cxx65
-rw-r--r--Source/CTest/cmCTestRunScriptCommand.h56
-rw-r--r--Source/CTest/cmCTestRunTest.cxx736
-rw-r--r--Source/CTest/cmCTestRunTest.h112
-rw-r--r--Source/CTest/cmCTestSVN.cxx619
-rw-r--r--Source/CTest/cmCTestSVN.h100
-rw-r--r--Source/CTest/cmCTestScriptHandler.cxx1157
-rw-r--r--Source/CTest/cmCTestScriptHandler.h174
-rw-r--r--Source/CTest/cmCTestSleepCommand.cxx55
-rw-r--r--Source/CTest/cmCTestSleepCommand.h57
-rw-r--r--Source/CTest/cmCTestStartCommand.cxx170
-rw-r--r--Source/CTest/cmCTestStartCommand.h68
-rw-r--r--Source/CTest/cmCTestSubmitCommand.cxx255
-rw-r--r--Source/CTest/cmCTestSubmitCommand.h80
-rw-r--r--Source/CTest/cmCTestSubmitHandler.cxx1511
-rw-r--r--Source/CTest/cmCTestSubmitHandler.h98
-rw-r--r--Source/CTest/cmCTestTestCommand.cxx112
-rw-r--r--Source/CTest/cmCTestTestCommand.h68
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx2391
-rw-r--r--Source/CTest/cmCTestTestHandler.h290
-rw-r--r--Source/CTest/cmCTestUpdateCommand.cxx90
-rw-r--r--Source/CTest/cmCTestUpdateCommand.h51
-rw-r--r--Source/CTest/cmCTestUpdateHandler.cxx429
-rw-r--r--Source/CTest/cmCTestUpdateHandler.h77
-rw-r--r--Source/CTest/cmCTestUploadCommand.cxx69
-rw-r--r--Source/CTest/cmCTestUploadCommand.h66
-rw-r--r--Source/CTest/cmCTestUploadHandler.cxx78
-rw-r--r--Source/CTest/cmCTestUploadHandler.h45
-rw-r--r--Source/CTest/cmCTestVC.cxx248
-rw-r--r--Source/CTest/cmCTestVC.h137
-rw-r--r--Source/CTest/cmParseCacheCoverage.cxx233
-rw-r--r--Source/CTest/cmParseCacheCoverage.h42
-rw-r--r--Source/CTest/cmParseCoberturaCoverage.cxx169
-rw-r--r--Source/CTest/cmParseCoberturaCoverage.h51
-rw-r--r--Source/CTest/cmParseGTMCoverage.cxx289
-rw-r--r--Source/CTest/cmParseGTMCoverage.h49
-rw-r--r--Source/CTest/cmParseJacocoCoverage.cxx170
-rw-r--r--Source/CTest/cmParseJacocoCoverage.h59
-rw-r--r--Source/CTest/cmParseMumpsCoverage.cxx168
-rw-r--r--Source/CTest/cmParseMumpsCoverage.h52
-rw-r--r--Source/CTest/cmParsePHPCoverage.cxx254
-rw-r--r--Source/CTest/cmParsePHPCoverage.h45
-rw-r--r--Source/CTest/cmProcess.cxx280
-rw-r--r--Source/CTest/cmProcess.h82
-rw-r--r--Source/CursesDialog/.NoDartCoverage1
-rw-r--r--Source/CursesDialog/CMakeLists.txt38
-rw-r--r--Source/CursesDialog/ccmake.cxx216
-rw-r--r--Source/CursesDialog/cmCursesBoolWidget.cxx74
-rw-r--r--Source/CursesDialog/cmCursesBoolWidget.h40
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.cxx124
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.h43
-rw-r--r--Source/CursesDialog/cmCursesDummyWidget.cxx26
-rw-r--r--Source/CursesDialog/cmCursesDummyWidget.h36
-rw-r--r--Source/CursesDialog/cmCursesFilePathWidget.cxx20
-rw-r--r--Source/CursesDialog/cmCursesFilePathWidget.h28
-rw-r--r--Source/CursesDialog/cmCursesForm.cxx57
-rw-r--r--Source/CursesDialog/cmCursesForm.h76
-rw-r--r--Source/CursesDialog/cmCursesLabelWidget.cxx33
-rw-r--r--Source/CursesDialog/cmCursesLabelWidget.h38
-rw-r--r--Source/CursesDialog/cmCursesLongMessageForm.cxx207
-rw-r--r--Source/CursesDialog/cmCursesLongMessageForm.h58
-rw-r--r--Source/CursesDialog/cmCursesMainForm.cxx1303
-rw-r--r--Source/CursesDialog/cmCursesMainForm.h164
-rw-r--r--Source/CursesDialog/cmCursesOptionsWidget.cxx105
-rw-r--r--Source/CursesDialog/cmCursesOptionsWidget.h39
-rw-r--r--Source/CursesDialog/cmCursesPathWidget.cxx94
-rw-r--r--Source/CursesDialog/cmCursesPathWidget.h40
-rw-r--r--Source/CursesDialog/cmCursesStandardIncludes.h83
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.cxx249
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.h76
-rw-r--r--Source/CursesDialog/cmCursesWidget.cxx58
-rw-r--r--Source/CursesDialog/cmCursesWidget.h87
-rw-r--r--Source/CursesDialog/form/.NoDartCoverage1
-rw-r--r--Source/CursesDialog/form/CMakeLists.txt66
-rw-r--r--Source/CursesDialog/form/READ.ME15
-rw-r--r--Source/CursesDialog/form/cmFormConfigure.h.in21
-rw-r--r--Source/CursesDialog/form/eti.h52
-rw-r--r--Source/CursesDialog/form/fld_arg.c91
-rw-r--r--Source/CursesDialog/form/fld_attr.c116
-rw-r--r--Source/CursesDialog/form/fld_current.c124
-rw-r--r--Source/CursesDialog/form/fld_def.c346
-rw-r--r--Source/CursesDialog/form/fld_dup.c97
-rw-r--r--Source/CursesDialog/form/fld_ftchoice.c62
-rw-r--r--Source/CursesDialog/form/fld_ftlink.c83
-rw-r--r--Source/CursesDialog/form/fld_info.c91
-rw-r--r--Source/CursesDialog/form/fld_just.c81
-rw-r--r--Source/CursesDialog/form/fld_link.c90
-rw-r--r--Source/CursesDialog/form/fld_max.c74
-rw-r--r--Source/CursesDialog/form/fld_move.c62
-rw-r--r--Source/CursesDialog/form/fld_newftyp.c125
-rw-r--r--Source/CursesDialog/form/fld_opts.c124
-rw-r--r--Source/CursesDialog/form/fld_pad.c78
-rw-r--r--Source/CursesDialog/form/fld_page.c76
-rw-r--r--Source/CursesDialog/form/fld_stat.c73
-rw-r--r--Source/CursesDialog/form/fld_type.c51
-rw-r--r--Source/CursesDialog/form/fld_user.c67
-rw-r--r--Source/CursesDialog/form/form.h401
-rw-r--r--Source/CursesDialog/form/form.priv.h134
-rw-r--r--Source/CursesDialog/form/frm_cursor.c66
-rw-r--r--Source/CursesDialog/form/frm_data.c183
-rw-r--r--Source/CursesDialog/form/frm_def.c376
-rw-r--r--Source/CursesDialog/form/frm_driver.c3898
-rw-r--r--Source/CursesDialog/form/frm_hook.c140
-rw-r--r--Source/CursesDialog/form/frm_opts.c116
-rw-r--r--Source/CursesDialog/form/frm_page.c100
-rw-r--r--Source/CursesDialog/form/frm_post.c124
-rw-r--r--Source/CursesDialog/form/frm_req_name.c169
-rw-r--r--Source/CursesDialog/form/frm_scale.c63
-rw-r--r--Source/CursesDialog/form/frm_sub.c69
-rw-r--r--Source/CursesDialog/form/frm_user.c67
-rw-r--r--Source/CursesDialog/form/frm_win.c70
-rw-r--r--Source/CursesDialog/form/fty_alnum.c138
-rw-r--r--Source/CursesDialog/form/fty_alpha.c139
-rw-r--r--Source/CursesDialog/form/fty_enum.c295
-rw-r--r--Source/CursesDialog/form/fty_int.c161
-rw-r--r--Source/CursesDialog/form/fty_ipv4.c84
-rw-r--r--Source/CursesDialog/form/fty_num.c192
-rw-r--r--Source/CursesDialog/form/fty_regex.c264
-rw-r--r--Source/CursesDialog/form/llib-lform694
-rw-r--r--Source/CursesDialog/form/mf_common.h93
-rw-r--r--Source/CursesDialog/form/nc_alloc.h83
-rw-r--r--Source/QtDialog/AddCacheEntry.cxx113
-rw-r--r--Source/QtDialog/AddCacheEntry.h45
-rw-r--r--Source/QtDialog/AddCacheEntry.ui97
-rw-r--r--Source/QtDialog/CMake.desktop12
-rw-r--r--Source/QtDialog/CMakeLists.txt203
-rw-r--r--Source/QtDialog/CMakeSetup.cxx189
-rw-r--r--Source/QtDialog/CMakeSetup.icnsbin0 -> 138205 bytes
-rw-r--r--Source/QtDialog/CMakeSetup.icobin0 -> 24542 bytes
-rw-r--r--Source/QtDialog/CMakeSetup.qrc8
-rw-r--r--Source/QtDialog/CMakeSetup.rc1
-rw-r--r--Source/QtDialog/CMakeSetup128.pngbin0 -> 13269 bytes
-rw-r--r--Source/QtDialog/CMakeSetup32.pngbin0 -> 358 bytes
-rw-r--r--Source/QtDialog/CMakeSetupDialog.cxx1331
-rw-r--r--Source/QtDialog/CMakeSetupDialog.h139
-rw-r--r--Source/QtDialog/CMakeSetupDialog.ui313
-rw-r--r--Source/QtDialog/Compilers.h21
-rw-r--r--Source/QtDialog/Compilers.ui87
-rw-r--r--Source/QtDialog/CrossCompiler.ui213
-rw-r--r--Source/QtDialog/Delete16.pngbin0 -> 731 bytes
-rw-r--r--Source/QtDialog/FirstConfigure.cxx509
-rw-r--r--Source/QtDialog/FirstConfigure.h177
-rw-r--r--Source/QtDialog/Info.plist.in32
-rw-r--r--Source/QtDialog/MacInstallDialog.ui103
-rw-r--r--Source/QtDialog/Plus16.pngbin0 -> 358 bytes
-rw-r--r--Source/QtDialog/QCMake.cxx447
-rw-r--r--Source/QtDialog/QCMake.h156
-rw-r--r--Source/QtDialog/QCMakeCacheView.cxx739
-rw-r--r--Source/QtDialog/QCMakeCacheView.h172
-rw-r--r--Source/QtDialog/QCMakeWidgets.cxx136
-rw-r--r--Source/QtDialog/QCMakeWidgets.h87
-rw-r--r--Source/QtDialog/QMacInstallDialog.cxx121
-rw-r--r--Source/QtDialog/QMacInstallDialog.h20
-rw-r--r--Source/QtDialog/QtDialogCPack.cmake.in15
-rw-r--r--Source/QtDialog/cmakecache.xml8
-rw-r--r--Source/QtIFW/cmake.org.html7
-rw-r--r--Source/QtIFW/installscript.qs.in24
-rw-r--r--Source/cmAddCompileOptionsCommand.cxx28
-rw-r--r--Source/cmAddCompileOptionsCommand.h43
-rw-r--r--Source/cmAddCustomCommandCommand.cxx421
-rw-r--r--Source/cmAddCustomCommandCommand.h52
-rw-r--r--Source/cmAddCustomTargetCommand.cxx235
-rw-r--r--Source/cmAddCustomTargetCommand.h51
-rw-r--r--Source/cmAddDefinitionsCommand.cxx31
-rw-r--r--Source/cmAddDefinitionsCommand.h51
-rw-r--r--Source/cmAddDependenciesCommand.cxx66
-rw-r--r--Source/cmAddDependenciesCommand.h49
-rw-r--r--Source/cmAddExecutableCommand.cxx249
-rw-r--r--Source/cmAddExecutableCommand.h50
-rw-r--r--Source/cmAddLibraryCommand.cxx450
-rw-r--r--Source/cmAddLibraryCommand.h50
-rw-r--r--Source/cmAddSubDirectoryCommand.cxx128
-rw-r--r--Source/cmAddSubDirectoryCommand.h52
-rw-r--r--Source/cmAddTestCommand.cxx180
-rw-r--r--Source/cmAddTestCommand.h51
-rw-r--r--Source/cmArchiveWrite.cxx346
-rw-r--r--Source/cmArchiveWrite.h95
-rw-r--r--Source/cmAuxSourceDirectoryCommand.cxx89
-rw-r--r--Source/cmAuxSourceDirectoryCommand.h54
-rw-r--r--Source/cmBootstrapCommands1.cxx91
-rw-r--r--Source/cmBootstrapCommands2.cxx104
-rw-r--r--Source/cmBreakCommand.cxx21
-rw-r--r--Source/cmBreakCommand.h55
-rw-r--r--Source/cmBuildCommand.cxx152
-rw-r--r--Source/cmBuildCommand.h58
-rw-r--r--Source/cmBuildNameCommand.cxx80
-rw-r--r--Source/cmBuildNameCommand.h31
-rw-r--r--Source/cmCMakeHostSystemInformationCommand.cxx126
-rw-r--r--Source/cmCMakeHostSystemInformationCommand.h67
-rw-r--r--Source/cmCMakeMinimumRequired.cxx142
-rw-r--r--Source/cmCMakeMinimumRequired.h59
-rw-r--r--Source/cmCMakePolicyCommand.cxx172
-rw-r--r--Source/cmCMakePolicyCommand.h60
-rw-r--r--Source/cmCPackPropertiesGenerator.cxx45
-rw-r--r--Source/cmCPackPropertiesGenerator.h38
-rw-r--r--Source/cmCPluginAPI.cxx935
-rw-r--r--Source/cmCPluginAPI.h243
-rw-r--r--Source/cmCTest.cxx3207
-rw-r--r--Source/cmCTest.h592
-rw-r--r--Source/cmCacheManager.cxx938
-rw-r--r--Source/cmCacheManager.h187
-rw-r--r--Source/cmCallVisualStudioMacro.cxx540
-rw-r--r--Source/cmCallVisualStudioMacro.h45
-rw-r--r--Source/cmCommand.h204
-rw-r--r--Source/cmCommandArgumentLexer.cxx2077
-rw-r--r--Source/cmCommandArgumentLexer.h333
-rw-r--r--Source/cmCommandArgumentLexer.in.l162
-rw-r--r--Source/cmCommandArgumentParser.cxx1835
-rw-r--r--Source/cmCommandArgumentParser.y246
-rw-r--r--Source/cmCommandArgumentParserHelper.cxx367
-rw-r--r--Source/cmCommandArgumentParserHelper.h110
-rw-r--r--Source/cmCommandArgumentParserTokens.h92
-rw-r--r--Source/cmCommandArgumentsHelper.cxx307
-rw-r--r--Source/cmCommandArgumentsHelper.h204
-rw-r--r--Source/cmCommands.cxx.in19
-rw-r--r--Source/cmCommands.h29
-rw-r--r--Source/cmCommandsForBootstrap.cxx16
-rw-r--r--Source/cmComputeComponentGraph.cxx159
-rw-r--r--Source/cmComputeComponentGraph.h83
-rw-r--r--Source/cmComputeLinkDepends.cxx990
-rw-r--r--Source/cmComputeLinkDepends.h170
-rw-r--r--Source/cmComputeLinkInformation.cxx2046
-rw-r--r--Source/cmComputeLinkInformation.h188
-rw-r--r--Source/cmComputeTargetDepends.cxx686
-rw-r--r--Source/cmComputeTargetDepends.h91
-rw-r--r--Source/cmConditionEvaluator.cxx770
-rw-r--r--Source/cmConditionEvaluator.h96
-rw-r--r--Source/cmConfigure.cmake.h.in20
-rw-r--r--Source/cmConfigureFileCommand.cxx124
-rw-r--r--Source/cmConfigureFileCommand.h58
-rw-r--r--Source/cmCoreTryCompile.cxx667
-rw-r--r--Source/cmCoreTryCompile.h60
-rw-r--r--Source/cmCreateTestSourceList.cxx189
-rw-r--r--Source/cmCreateTestSourceList.h50
-rw-r--r--Source/cmCryptoHash.cxx131
-rw-r--r--Source/cmCryptoHash.h65
-rw-r--r--Source/cmCustomCommand.cxx186
-rw-r--r--Source/cmCustomCommand.h95
-rw-r--r--Source/cmCustomCommandGenerator.cxx121
-rw-r--r--Source/cmCustomCommandGenerator.h48
-rw-r--r--Source/cmDefinePropertyCommand.cxx136
-rw-r--r--Source/cmDefinePropertyCommand.h46
-rw-r--r--Source/cmDefinitions.cxx182
-rw-r--r--Source/cmDefinitions.h99
-rw-r--r--Source/cmDepends.cxx320
-rw-r--r--Source/cmDepends.h124
-rw-r--r--Source/cmDependsC.cxx581
-rw-r--r--Source/cmDependsC.h97
-rw-r--r--Source/cmDependsFortran.cxx1282
-rw-r--r--Source/cmDependsFortran.h92
-rw-r--r--Source/cmDependsFortranLexer.cxx2414
-rw-r--r--Source/cmDependsFortranLexer.h348
-rw-r--r--Source/cmDependsFortranLexer.in.l190
-rw-r--r--Source/cmDependsFortranParser.cxx2094
-rw-r--r--Source/cmDependsFortranParser.h96
-rw-r--r--Source/cmDependsFortranParser.y288
-rw-r--r--Source/cmDependsFortranParserTokens.h122
-rw-r--r--Source/cmDependsJava.cxx45
-rw-r--r--Source/cmDependsJava.h44
-rw-r--r--Source/cmDependsJavaLexer.cxx2542
-rw-r--r--Source/cmDependsJavaLexer.h334
-rw-r--r--Source/cmDependsJavaLexer.in.l189
-rw-r--r--Source/cmDependsJavaParser.cxx6021
-rw-r--r--Source/cmDependsJavaParser.y3227
-rw-r--r--Source/cmDependsJavaParserHelper.cxx430
-rw-r--r--Source/cmDependsJavaParserHelper.h128
-rw-r--r--Source/cmDependsJavaParserTokens.h254
-rw-r--r--Source/cmDocumentation.cxx945
-rw-r--r--Source/cmDocumentation.h146
-rw-r--r--Source/cmDocumentationFormatter.cxx230
-rw-r--r--Source/cmDocumentationFormatter.h57
-rw-r--r--Source/cmDocumentationSection.cxx45
-rw-r--r--Source/cmDocumentationSection.h66
-rw-r--r--Source/cmDynamicLoader.cxx112
-rw-r--r--Source/cmDynamicLoader.h47
-rw-r--r--Source/cmELF.cxx949
-rw-r--r--Source/cmELF.h108
-rw-r--r--Source/cmElseCommand.cxx21
-rw-r--r--Source/cmElseCommand.h54
-rw-r--r--Source/cmElseIfCommand.cxx20
-rw-r--r--Source/cmElseIfCommand.h54
-rw-r--r--Source/cmEnableLanguageCommand.cxx43
-rw-r--r--Source/cmEnableLanguageCommand.h53
-rw-r--r--Source/cmEnableTestingCommand.cxx22
-rw-r--r--Source/cmEnableTestingCommand.h58
-rw-r--r--Source/cmEndForEachCommand.cxx23
-rw-r--r--Source/cmEndForEachCommand.h61
-rw-r--r--Source/cmEndFunctionCommand.cxx23
-rw-r--r--Source/cmEndFunctionCommand.h61
-rw-r--r--Source/cmEndIfCommand.cxx29
-rw-r--r--Source/cmEndIfCommand.h54
-rw-r--r--Source/cmEndMacroCommand.cxx23
-rw-r--r--Source/cmEndMacroCommand.h61
-rw-r--r--Source/cmEndWhileCommand.cxx32
-rw-r--r--Source/cmEndWhileCommand.h61
-rw-r--r--Source/cmExecProgramCommand.cxx333
-rw-r--r--Source/cmExecProgramCommand.h66
-rw-r--r--Source/cmExecuteProcessCommand.cxx422
-rw-r--r--Source/cmExecuteProcessCommand.h55
-rw-r--r--Source/cmExecutionStatus.h55
-rw-r--r--Source/cmExpandedCommandArgument.cxx51
-rw-r--r--Source/cmExpandedCommandArgument.h45
-rw-r--r--Source/cmExportBuildFileGenerator.cxx339
-rw-r--r--Source/cmExportBuildFileGenerator.h86
-rw-r--r--Source/cmExportCommand.cxx411
-rw-r--r--Source/cmExportCommand.h76
-rw-r--r--Source/cmExportFileGenerator.cxx1186
-rw-r--r--Source/cmExportFileGenerator.h200
-rw-r--r--Source/cmExportInstallFileGenerator.cxx557
-rw-r--r--Source/cmExportInstallFileGenerator.h98
-rw-r--r--Source/cmExportLibraryDependenciesCommand.cxx206
-rw-r--r--Source/cmExportLibraryDependenciesCommand.h37
-rw-r--r--Source/cmExportSet.cxx32
-rw-r--r--Source/cmExportSet.h46
-rw-r--r--Source/cmExportSetMap.cxx40
-rw-r--r--Source/cmExportSetMap.h36
-rw-r--r--Source/cmExportTryCompileFileGenerator.cxx135
-rw-r--r--Source/cmExportTryCompileFileGenerator.h57
-rw-r--r--Source/cmExprLexer.cxx1928
-rw-r--r--Source/cmExprLexer.h334
-rw-r--r--Source/cmExprLexer.in.l74
-rw-r--r--Source/cmExprParser.cxx1433
-rw-r--r--Source/cmExprParser.y170
-rw-r--r--Source/cmExprParserHelper.cxx112
-rw-r--r--Source/cmExprParserHelper.h71
-rw-r--r--Source/cmExprParserTokens.h76
-rw-r--r--Source/cmExternalMakefileProjectGenerator.cxx70
-rw-r--r--Source/cmExternalMakefileProjectGenerator.h73
-rw-r--r--Source/cmExtraCodeBlocksGenerator.cxx804
-rw-r--r--Source/cmExtraCodeBlocksGenerator.h62
-rw-r--r--Source/cmExtraCodeLiteGenerator.cxx490
-rw-r--r--Source/cmExtraCodeLiteGenerator.h54
-rw-r--r--Source/cmExtraEclipseCDT4Generator.cxx1366
-rw-r--r--Source/cmExtraEclipseCDT4Generator.h122
-rw-r--r--Source/cmExtraKateGenerator.cxx350
-rw-r--r--Source/cmExtraKateGenerator.h62
-rw-r--r--Source/cmExtraSublimeTextGenerator.cxx451
-rw-r--r--Source/cmExtraSublimeTextGenerator.h89
-rw-r--r--Source/cmFLTKWrapUICommand.cxx177
-rw-r--r--Source/cmFLTKWrapUICommand.h72
-rw-r--r--Source/cmFileCommand.cxx3517
-rw-r--r--Source/cmFileCommand.h87
-rw-r--r--Source/cmFileTimeComparison.cxx277
-rw-r--r--Source/cmFileTimeComparison.h51
-rw-r--r--Source/cmFindBase.cxx495
-rw-r--r--Source/cmFindBase.h74
-rw-r--r--Source/cmFindCommon.cxx472
-rw-r--r--Source/cmFindCommon.h95
-rw-r--r--Source/cmFindFileCommand.cxx18
-rw-r--r--Source/cmFindFileCommand.h43
-rw-r--r--Source/cmFindLibraryCommand.cxx544
-rw-r--r--Source/cmFindLibraryCommand.h74
-rw-r--r--Source/cmFindPackageCommand.cxx2261
-rw-r--r--Source/cmFindPackageCommand.h137
-rw-r--r--Source/cmFindPathCommand.cxx197
-rw-r--r--Source/cmFindPathCommand.h66
-rw-r--r--Source/cmFindProgramCommand.cxx160
-rw-r--r--Source/cmFindProgramCommand.h66
-rw-r--r--Source/cmForEachCommand.cxx246
-rw-r--r--Source/cmForEachCommand.h70
-rw-r--r--Source/cmFunctionBlocker.h48
-rw-r--r--Source/cmFunctionCommand.cxx282
-rw-r--r--Source/cmFunctionCommand.h66
-rw-r--r--Source/cmGeneratedFileStream.cxx255
-rw-r--r--Source/cmGeneratedFileStream.h153
-rw-r--r--Source/cmGeneratorExpression.cxx494
-rw-r--r--Source/cmGeneratorExpression.h152
-rw-r--r--Source/cmGeneratorExpressionDAGChecker.cxx247
-rw-r--r--Source/cmGeneratorExpressionDAGChecker.h96
-rw-r--r--Source/cmGeneratorExpressionEvaluationFile.cxx140
-rw-r--r--Source/cmGeneratorExpressionEvaluationFile.h48
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx2069
-rw-r--r--Source/cmGeneratorExpressionEvaluator.h156
-rw-r--r--Source/cmGeneratorExpressionLexer.cxx83
-rw-r--r--Source/cmGeneratorExpressionLexer.h58
-rw-r--r--Source/cmGeneratorExpressionParser.cxx302
-rw-r--r--Source/cmGeneratorExpressionParser.h45
-rw-r--r--Source/cmGeneratorTarget.cxx1159
-rw-r--r--Source/cmGeneratorTarget.h161
-rw-r--r--Source/cmGetCMakePropertyCommand.cxx79
-rw-r--r--Source/cmGetCMakePropertyCommand.h47
-rw-r--r--Source/cmGetDirectoryPropertyCommand.cxx96
-rw-r--r--Source/cmGetDirectoryPropertyCommand.h47
-rw-r--r--Source/cmGetFilenameComponentCommand.cxx139
-rw-r--r--Source/cmGetFilenameComponentCommand.h56
-rw-r--r--Source/cmGetPropertyCommand.cxx432
-rw-r--r--Source/cmGetPropertyCommand.h66
-rw-r--r--Source/cmGetSourceFilePropertyCommand.cxx52
-rw-r--r--Source/cmGetSourceFilePropertyCommand.h42
-rw-r--r--Source/cmGetTargetPropertyCommand.cxx85
-rw-r--r--Source/cmGetTargetPropertyCommand.h42
-rw-r--r--Source/cmGetTestPropertyCommand.cxx42
-rw-r--r--Source/cmGetTestPropertyCommand.h42
-rw-r--r--Source/cmGlobalBorlandMakefileGenerator.cxx62
-rw-r--r--Source/cmGlobalBorlandMakefileGenerator.h51
-rw-r--r--Source/cmGlobalGenerator.cxx3067
-rw-r--r--Source/cmGlobalGenerator.h493
-rw-r--r--Source/cmGlobalGeneratorFactory.h61
-rw-r--r--Source/cmGlobalJOMMakefileGenerator.cxx68
-rw-r--r--Source/cmGlobalJOMMakefileGenerator.h50
-rw-r--r--Source/cmGlobalKdevelopGenerator.cxx612
-rw-r--r--Source/cmGlobalKdevelopGenerator.h92
-rw-r--r--Source/cmGlobalMSYSMakefileGenerator.cxx114
-rw-r--r--Source/cmGlobalMSYSMakefileGenerator.h52
-rw-r--r--Source/cmGlobalMinGWMakefileGenerator.cxx52
-rw-r--r--Source/cmGlobalMinGWMakefileGenerator.h48
-rw-r--r--Source/cmGlobalNMakeMakefileGenerator.cxx68
-rw-r--r--Source/cmGlobalNMakeMakefileGenerator.h48
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx1232
-rw-r--r--Source/cmGlobalNinjaGenerator.h386
-rw-r--r--Source/cmGlobalUnixMakefileGenerator3.cxx1098
-rw-r--r--Source/cmGlobalUnixMakefileGenerator3.h202
-rw-r--r--Source/cmGlobalVisualStudio10Generator.cxx636
-rw-r--r--Source/cmGlobalVisualStudio10Generator.h159
-rw-r--r--Source/cmGlobalVisualStudio11Generator.cxx258
-rw-r--r--Source/cmGlobalVisualStudio11Generator.h51
-rw-r--r--Source/cmGlobalVisualStudio12Generator.cxx182
-rw-r--r--Source/cmGlobalVisualStudio12Generator.h50
-rw-r--r--Source/cmGlobalVisualStudio14Generator.cxx113
-rw-r--r--Source/cmGlobalVisualStudio14Generator.h43
-rw-r--r--Source/cmGlobalVisualStudio6Generator.cxx431
-rw-r--r--Source/cmGlobalVisualStudio6Generator.h111
-rw-r--r--Source/cmGlobalVisualStudio71Generator.cxx316
-rw-r--r--Source/cmGlobalVisualStudio71Generator.h80
-rw-r--r--Source/cmGlobalVisualStudio7Generator.cxx1092
-rw-r--r--Source/cmGlobalVisualStudio7Generator.h193
-rw-r--r--Source/cmGlobalVisualStudio8Generator.cxx533
-rw-r--r--Source/cmGlobalVisualStudio8Generator.h104
-rw-r--r--Source/cmGlobalVisualStudio9Generator.cxx154
-rw-r--r--Source/cmGlobalVisualStudio9Generator.h58
-rw-r--r--Source/cmGlobalVisualStudioGenerator.cxx881
-rw-r--r--Source/cmGlobalVisualStudioGenerator.h135
-rw-r--r--Source/cmGlobalWatcomWMakeGenerator.cxx67
-rw-r--r--Source/cmGlobalWatcomWMakeGenerator.h50
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx3998
-rw-r--r--Source/cmGlobalXCodeGenerator.h248
-rw-r--r--Source/cmGraphAdjacencyList.h40
-rw-r--r--Source/cmGraphVizWriter.cxx599
-rw-r--r--Source/cmGraphVizWriter.h91
-rw-r--r--Source/cmHexFileConverter.cxx265
-rw-r--r--Source/cmHexFileConverter.h28
-rw-r--r--Source/cmIDEFlagTable.h41
-rw-r--r--Source/cmIDEOptions.cxx235
-rw-r--r--Source/cmIDEOptions.h85
-rw-r--r--Source/cmIfCommand.cxx230
-rw-r--r--Source/cmIfCommand.h81
-rw-r--r--Source/cmIncludeCommand.cxx158
-rw-r--r--Source/cmIncludeCommand.h56
-rw-r--r--Source/cmIncludeDirectoryCommand.cxx163
-rw-r--r--Source/cmIncludeDirectoryCommand.h56
-rw-r--r--Source/cmIncludeExternalMSProjectCommand.cxx101
-rw-r--r--Source/cmIncludeExternalMSProjectCommand.h52
-rw-r--r--Source/cmIncludeRegularExpressionCommand.cxx32
-rw-r--r--Source/cmIncludeRegularExpressionCommand.h51
-rw-r--r--Source/cmInstallCommand.cxx1438
-rw-r--r--Source/cmInstallCommand.h63
-rw-r--r--Source/cmInstallCommandArguments.cxx234
-rw-r--r--Source/cmInstallCommandArguments.h81
-rw-r--r--Source/cmInstallDirectoryGenerator.cxx54
-rw-r--r--Source/cmInstallDirectoryGenerator.h43
-rw-r--r--Source/cmInstallExportGenerator.cxx229
-rw-r--r--Source/cmInstallExportGenerator.h64
-rw-r--r--Source/cmInstallFilesCommand.cxx184
-rw-r--r--Source/cmInstallFilesCommand.h75
-rw-r--r--Source/cmInstallFilesGenerator.cxx98
-rw-r--r--Source/cmInstallFilesGenerator.h52
-rw-r--r--Source/cmInstallGenerator.cxx216
-rw-r--r--Source/cmInstallGenerator.h77
-rw-r--r--Source/cmInstallProgramsCommand.cxx145
-rw-r--r--Source/cmInstallProgramsCommand.h73
-rw-r--r--Source/cmInstallScriptGenerator.cxx47
-rw-r--r--Source/cmInstallScriptGenerator.h33
-rw-r--r--Source/cmInstallTargetGenerator.cxx840
-rw-r--r--Source/cmInstallTargetGenerator.h108
-rw-r--r--Source/cmInstallTargetsCommand.cxx66
-rw-r--r--Source/cmInstallTargetsCommand.h57
-rw-r--r--Source/cmInstallType.h29
-rw-r--r--Source/cmInstalledFile.cxx131
-rw-r--r--Source/cmInstalledFile.h88
-rw-r--r--Source/cmLinkDirectoriesCommand.cxx70
-rw-r--r--Source/cmLinkDirectoriesCommand.h55
-rw-r--r--Source/cmLinkLibrariesCommand.cxx59
-rw-r--r--Source/cmLinkLibrariesCommand.h58
-rw-r--r--Source/cmListCommand.cxx608
-rw-r--r--Source/cmListCommand.h68
-rw-r--r--Source/cmListFileCache.cxx442
-rw-r--r--Source/cmListFileCache.h109
-rw-r--r--Source/cmListFileLexer.c2670
-rw-r--r--Source/cmListFileLexer.h75
-rw-r--r--Source/cmListFileLexer.in.l619
-rw-r--r--Source/cmLoadCacheCommand.cxx197
-rw-r--r--Source/cmLoadCacheCommand.h56
-rw-r--r--Source/cmLoadCommandCommand.cxx283
-rw-r--r--Source/cmLoadCommandCommand.h30
-rw-r--r--Source/cmLocalGenerator.cxx3754
-rw-r--r--Source/cmLocalGenerator.h503
-rw-r--r--Source/cmLocalNinjaGenerator.cxx551
-rw-r--r--Source/cmLocalNinjaGenerator.h144
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx2353
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.h385
-rw-r--r--Source/cmLocalVisualStudio10Generator.cxx128
-rw-r--r--Source/cmLocalVisualStudio10Generator.h46
-rw-r--r--Source/cmLocalVisualStudio6Generator.cxx2010
-rw-r--r--Source/cmLocalVisualStudio6Generator.h104
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx2333
-rw-r--r--Source/cmLocalVisualStudio7Generator.h130
-rw-r--r--Source/cmLocalVisualStudioGenerator.cxx243
-rw-r--r--Source/cmLocalVisualStudioGenerator.h82
-rw-r--r--Source/cmLocalXCodeGenerator.cxx101
-rw-r--r--Source/cmLocalXCodeGenerator.h43
-rw-r--r--Source/cmMacroCommand.cxx339
-rw-r--r--Source/cmMacroCommand.h66
-rw-r--r--Source/cmMakeDepend.cxx365
-rw-r--r--Source/cmMakeDepend.h150
-rw-r--r--Source/cmMakeDirectoryCommand.cxx34
-rw-r--r--Source/cmMakeDirectoryCommand.h65
-rw-r--r--Source/cmMakefile.cxx5511
-rw-r--r--Source/cmMakefile.h1194
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx472
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.h31
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx815
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.h46
-rw-r--r--Source/cmMakefileTargetGenerator.cxx2131
-rw-r--r--Source/cmMakefileTargetGenerator.h287
-rw-r--r--Source/cmMakefileUtilityTargetGenerator.cxx120
-rw-r--r--Source/cmMakefileUtilityTargetGenerator.h32
-rw-r--r--Source/cmMarkAsAdvancedCommand.cxx62
-rw-r--r--Source/cmMarkAsAdvancedCommand.h58
-rw-r--r--Source/cmMathCommand.cxx61
-rw-r--r--Source/cmMathCommand.h54
-rw-r--r--Source/cmMessageCommand.cxx99
-rw-r--r--Source/cmMessageCommand.h53
-rw-r--r--Source/cmNewLineStyle.cxx93
-rw-r--r--Source/cmNewLineStyle.h46
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx693
-rw-r--r--Source/cmNinjaNormalTargetGenerator.h53
-rw-r--r--Source/cmNinjaTargetGenerator.cxx805
-rw-r--r--Source/cmNinjaTargetGenerator.h170
-rw-r--r--Source/cmNinjaTypes.h19
-rw-r--r--Source/cmNinjaUtilityTargetGenerator.cxx125
-rw-r--r--Source/cmNinjaUtilityTargetGenerator.h30
-rw-r--r--Source/cmOSXBundleGenerator.cxx234
-rw-r--r--Source/cmOSXBundleGenerator.h71
-rw-r--r--Source/cmObject.h51
-rw-r--r--Source/cmOptionCommand.cxx68
-rw-r--r--Source/cmOptionCommand.h55
-rw-r--r--Source/cmOrderDirectories.cxx648
-rw-r--r--Source/cmOrderDirectories.h88
-rw-r--r--Source/cmOutputRequiredFilesCommand.cxx244
-rw-r--r--Source/cmOutputRequiredFilesCommand.h38
-rw-r--r--Source/cmPolicies.cxx676
-rw-r--r--Source/cmPolicies.h168
-rw-r--r--Source/cmProcessTools.cxx90
-rw-r--r--Source/cmProcessTools.h82
-rw-r--r--Source/cmProjectCommand.cxx253
-rw-r--r--Source/cmProjectCommand.h53
-rw-r--r--Source/cmProperty.cxx41
-rw-r--r--Source/cmProperty.h42
-rw-r--r--Source/cmPropertyDefinition.cxx33
-rw-r--r--Source/cmPropertyDefinition.h61
-rw-r--r--Source/cmPropertyDefinitionMap.cxx52
-rw-r--r--Source/cmPropertyDefinitionMap.h37
-rw-r--r--Source/cmPropertyMap.cxx82
-rw-r--r--Source/cmPropertyMap.h43
-rw-r--r--Source/cmQTWrapCPPCommand.cxx115
-rw-r--r--Source/cmQTWrapCPPCommand.h53
-rw-r--r--Source/cmQTWrapUICommand.cxx166
-rw-r--r--Source/cmQTWrapUICommand.h51
-rw-r--r--Source/cmQtAutoGenerators.cxx2164
-rw-r--r--Source/cmQtAutoGenerators.h130
-rw-r--r--Source/cmRST.cxx511
-rw-r--r--Source/cmRST.h100
-rw-r--r--Source/cmRemoveCommand.cxx76
-rw-r--r--Source/cmRemoveCommand.h61
-rw-r--r--Source/cmRemoveDefinitionsCommand.cxx31
-rw-r--r--Source/cmRemoveDefinitionsCommand.h52
-rw-r--r--Source/cmReturnCommand.cxx21
-rw-r--r--Source/cmReturnCommand.h55
-rw-r--r--Source/cmScriptGenerator.cxx238
-rw-r--r--Source/cmScriptGenerator.h96
-rw-r--r--Source/cmSeparateArgumentsCommand.cxx109
-rw-r--r--Source/cmSeparateArgumentsCommand.h55
-rw-r--r--Source/cmSetCommand.cxx178
-rw-r--r--Source/cmSetCommand.h55
-rw-r--r--Source/cmSetDirectoryPropertiesCommand.cxx70
-rw-r--r--Source/cmSetDirectoryPropertiesCommand.h55
-rw-r--r--Source/cmSetPropertyCommand.cxx547
-rw-r--r--Source/cmSetPropertyCommand.h71
-rw-r--r--Source/cmSetSourceFilesPropertiesCommand.cxx170
-rw-r--r--Source/cmSetSourceFilesPropertiesCommand.h49
-rw-r--r--Source/cmSetTargetPropertiesCommand.cxx115
-rw-r--r--Source/cmSetTargetPropertiesCommand.h49
-rw-r--r--Source/cmSetTestsPropertiesCommand.cxx117
-rw-r--r--Source/cmSetTestsPropertiesCommand.h47
-rw-r--r--Source/cmSiteNameCommand.cxx95
-rw-r--r--Source/cmSiteNameCommand.h55
-rw-r--r--Source/cmSourceFile.cxx401
-rw-r--r--Source/cmSourceFile.h127
-rw-r--r--Source/cmSourceFileLocation.cxx312
-rw-r--r--Source/cmSourceFileLocation.h102
-rw-r--r--Source/cmSourceGroup.cxx205
-rw-r--r--Source/cmSourceGroup.h132
-rw-r--r--Source/cmSourceGroupCommand.cxx102
-rw-r--r--Source/cmSourceGroupCommand.h51
-rw-r--r--Source/cmStandardIncludes.cxx16
-rw-r--r--Source/cmStandardIncludes.h469
-rw-r--r--Source/cmStandardLexer.h73
-rw-r--r--Source/cmStringCommand.cxx1099
-rw-r--r--Source/cmStringCommand.h92
-rw-r--r--Source/cmSubdirCommand.cxx74
-rw-r--r--Source/cmSubdirCommand.h58
-rw-r--r--Source/cmSubdirDependsCommand.cxx20
-rw-r--r--Source/cmSubdirDependsCommand.h28
-rw-r--r--Source/cmSystemTools.cxx2923
-rw-r--r--Source/cmSystemTools.h486
-rw-r--r--Source/cmTarget.cxx6980
-rw-r--r--Source/cmTarget.h856
-rw-r--r--Source/cmTargetCompileDefinitionsCommand.cxx67
-rw-r--r--Source/cmTargetCompileDefinitionsCommand.h53
-rw-r--r--Source/cmTargetCompileFeaturesCommand.cxx70
-rw-r--r--Source/cmTargetCompileFeaturesCommand.h41
-rw-r--r--Source/cmTargetCompileOptionsCommand.cxx62
-rw-r--r--Source/cmTargetCompileOptionsCommand.h53
-rw-r--r--Source/cmTargetDepend.h48
-rw-r--r--Source/cmTargetExport.h42
-rw-r--r--Source/cmTargetIncludeDirectoriesCommand.cxx106
-rw-r--r--Source/cmTargetIncludeDirectoriesCommand.h58
-rw-r--r--Source/cmTargetLinkLibrariesCommand.cxx505
-rw-r--r--Source/cmTargetLinkLibrariesCommand.h70
-rw-r--r--Source/cmTargetPropCommandBase.cxx181
-rw-r--r--Source/cmTargetPropCommandBase.h60
-rw-r--r--Source/cmTargetSourcesCommand.cxx65
-rw-r--r--Source/cmTargetSourcesCommand.h55
-rw-r--r--Source/cmTest.cxx80
-rw-r--r--Source/cmTest.h78
-rw-r--r--Source/cmTestGenerator.cxx196
-rw-r--r--Source/cmTestGenerator.h45
-rw-r--r--Source/cmTimestamp.cxx132
-rw-r--r--Source/cmTimestamp.h40
-rw-r--r--Source/cmTryCompileCommand.cxx42
-rw-r--r--Source/cmTryCompileCommand.h50
-rw-r--r--Source/cmTryRunCommand.cxx388
-rw-r--r--Source/cmTryRunCommand.h61
-rw-r--r--Source/cmUnsetCommand.cxx65
-rw-r--r--Source/cmUnsetCommand.h55
-rw-r--r--Source/cmUseMangledMesaCommand.cxx134
-rw-r--r--Source/cmUseMangledMesaCommand.h32
-rw-r--r--Source/cmUtilitySourceCommand.cxx130
-rw-r--r--Source/cmUtilitySourceCommand.h28
-rw-r--r--Source/cmUuid.cxx214
-rw-r--r--Source/cmUuid.h55
-rw-r--r--Source/cmVS10CLFlagTable.h270
-rw-r--r--Source/cmVS10LibFlagTable.h102
-rw-r--r--Source/cmVS10LinkFlagTable.h302
-rw-r--r--Source/cmVS10MASMFlagTable.h96
-rw-r--r--Source/cmVS10RCFlagTable.h7
-rw-r--r--Source/cmVS11CLFlagTable.h288
-rw-r--r--Source/cmVS11LibFlagTable.h102
-rw-r--r--Source/cmVS11LinkFlagTable.h340
-rw-r--r--Source/cmVS11MASMFlagTable.h96
-rw-r--r--Source/cmVS11RCFlagTable.h7
-rw-r--r--Source/cmVS12CLFlagTable.h294
-rw-r--r--Source/cmVS12LibFlagTable.h102
-rw-r--r--Source/cmVS12LinkFlagTable.h340
-rw-r--r--Source/cmVS12MASMFlagTable.h96
-rw-r--r--Source/cmVS12RCFlagTable.h7
-rw-r--r--Source/cmVS14CLFlagTable.h296
-rw-r--r--Source/cmVS14LibFlagTable.h102
-rw-r--r--Source/cmVS14LinkFlagTable.h340
-rw-r--r--Source/cmVS14MASMFlagTable.h96
-rw-r--r--Source/cmVS14RCFlagTable.h7
-rw-r--r--Source/cmVariableRequiresCommand.cxx79
-rw-r--r--Source/cmVariableRequiresCommand.h29
-rw-r--r--Source/cmVariableWatch.cxx119
-rw-r--r--Source/cmVariableWatch.h89
-rw-r--r--Source/cmVariableWatchCommand.cxx159
-rw-r--r--Source/cmVariableWatchCommand.h68
-rw-r--r--Source/cmVersion.cxx24
-rw-r--r--Source/cmVersion.h44
-rw-r--r--Source/cmVersionConfig.h.in15
-rw-r--r--Source/cmVersionMacros.h22
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx3126
-rw-r--r--Source/cmVisualStudio10TargetGenerator.h159
-rw-r--r--Source/cmVisualStudioGeneratorOptions.cxx388
-rw-r--r--Source/cmVisualStudioGeneratorOptions.h82
-rw-r--r--Source/cmVisualStudioSlnData.cxx62
-rw-r--r--Source/cmVisualStudioSlnData.h58
-rw-r--r--Source/cmVisualStudioSlnParser.cxx713
-rw-r--r--Source/cmVisualStudioSlnParser.h118
-rw-r--r--Source/cmVisualStudioWCEPlatformParser.cxx179
-rw-r--r--Source/cmVisualStudioWCEPlatformParser.h68
-rw-r--r--Source/cmWhileCommand.cxx143
-rw-r--r--Source/cmWhileCommand.h75
-rw-r--r--Source/cmWriteFileCommand.cxx94
-rw-r--r--Source/cmWriteFileCommand.h59
-rw-r--r--Source/cmXCode21Object.cxx105
-rw-r--r--Source/cmXCode21Object.h28
-rw-r--r--Source/cmXCodeObject.cxx272
-rw-r--r--Source/cmXCodeObject.h162
-rw-r--r--Source/cmXMLParser.cxx247
-rw-r--r--Source/cmXMLParser.h119
-rw-r--r--Source/cmXMLSafe.cxx102
-rw-r--r--Source/cmXMLSafe.h44
-rw-r--r--Source/cm_sha2.c1617
-rw-r--r--Source/cm_sha2.h140
-rw-r--r--Source/cm_sha2_mangle.h51
-rw-r--r--Source/cm_utf8.c84
-rw-r--r--Source/cm_utf8.h29
-rw-r--r--Source/cmake.cxx2857
-rw-r--r--Source/cmake.h548
-rw-r--r--Source/cmakemain.cxx463
-rw-r--r--Source/cmakexbuild.cxx92
-rw-r--r--Source/cmcldeps.cxx307
-rw-r--r--Source/cmcmd.cxx1447
-rw-r--r--Source/cmcmd.h54
-rwxr-xr-xSource/cmparseMSBuildXML.py338
-rw-r--r--Source/ctest.cxx197
-rw-r--r--Source/kwsys/Base64.c279
-rw-r--r--Source/kwsys/Base64.h.in120
-rw-r--r--Source/kwsys/CMakeEmptyInputFile.in1
-rw-r--r--Source/kwsys/CMakeLists.txt1267
-rw-r--r--Source/kwsys/CPU.h.in129
-rw-r--r--Source/kwsys/CTestConfig.cmake17
-rw-r--r--Source/kwsys/CommandLineArguments.cxx859
-rw-r--r--Source/kwsys/CommandLineArguments.hxx.in286
-rw-r--r--Source/kwsys/Configure.h.in131
-rw-r--r--Source/kwsys/Configure.hxx.in179
-rw-r--r--Source/kwsys/Copyright.txt31
-rw-r--r--Source/kwsys/Directory.cxx253
-rw-r--r--Source/kwsys/Directory.hxx.in93
-rw-r--r--Source/kwsys/DynamicLoader.cxx527
-rw-r--r--Source/kwsys/DynamicLoader.hxx.in101
-rw-r--r--Source/kwsys/Encoding.h.in79
-rw-r--r--Source/kwsys/Encoding.hxx.in87
-rw-r--r--Source/kwsys/EncodingC.c79
-rw-r--r--Source/kwsys/EncodingCXX.cxx184
-rw-r--r--Source/kwsys/ExtraTest.cmake.in1
-rw-r--r--Source/kwsys/FStream.cxx76
-rw-r--r--Source/kwsys/FStream.hxx.in188
-rw-r--r--Source/kwsys/FundamentalType.h.in146
-rw-r--r--Source/kwsys/Glob.cxx513
-rw-r--r--Source/kwsys/Glob.hxx.in117
-rw-r--r--Source/kwsys/IOStream.cxx282
-rw-r--r--Source/kwsys/IOStream.hxx.in142
-rw-r--r--Source/kwsys/MD5.c523
-rw-r--r--Source/kwsys/MD5.h.in107
-rw-r--r--Source/kwsys/Process.h.in428
-rw-r--r--Source/kwsys/ProcessUNIX.c2765
-rw-r--r--Source/kwsys/ProcessWin32.c2736
-rw-r--r--Source/kwsys/README.txt10
-rw-r--r--Source/kwsys/RegularExpression.cxx1244
-rw-r--r--Source/kwsys/RegularExpression.hxx.in453
-rw-r--r--Source/kwsys/SharedForward.h.in922
-rw-r--r--Source/kwsys/String.c115
-rw-r--r--Source/kwsys/String.h.in67
-rw-r--r--Source/kwsys/String.hxx.in65
-rw-r--r--Source/kwsys/System.c882
-rw-r--r--Source/kwsys/System.h.in167
-rw-r--r--Source/kwsys/SystemInformation.cxx5374
-rw-r--r--Source/kwsys/SystemInformation.hxx.in159
-rw-r--r--Source/kwsys/SystemTools.cxx5110
-rw-r--r--Source/kwsys/SystemTools.hxx.in944
-rw-r--r--Source/kwsys/Terminal.c433
-rw-r--r--Source/kwsys/Terminal.h.in159
-rw-r--r--Source/kwsys/auto_ptr.hxx.in219
-rw-r--r--Source/kwsys/hash_fun.hxx.in149
-rw-r--r--Source/kwsys/hash_map.hxx.in461
-rw-r--r--Source/kwsys/hash_set.hxx.in445
-rw-r--r--Source/kwsys/hashtable.hxx.in1296
-rwxr-xr-xSource/kwsys/kwsysHeaderDump.pl50
-rw-r--r--Source/kwsys/kwsysPlatformTests.cmake219
-rw-r--r--Source/kwsys/kwsysPlatformTestsC.c100
-rw-r--r--Source/kwsys/kwsysPlatformTestsCXX.cxx682
-rw-r--r--Source/kwsys/kwsysPrivate.h41
-rw-r--r--Source/kwsys/kwsys_cstddef.hxx.in35
-rw-r--r--Source/kwsys/kwsys_ios_fstream.h.in46
-rw-r--r--Source/kwsys/kwsys_ios_iosfwd.h.in49
-rw-r--r--Source/kwsys/kwsys_ios_iostream.h.in99
-rw-r--r--Source/kwsys/kwsys_ios_sstream.h.in199
-rw-r--r--Source/kwsys/kwsys_stl.hxx.in49
-rw-r--r--Source/kwsys/kwsys_stl_string.hxx.in123
-rw-r--r--Source/kwsys/testAutoPtr.cxx166
-rw-r--r--Source/kwsys/testCommandLineArguments.cxx187
-rw-r--r--Source/kwsys/testCommandLineArguments1.cxx108
-rw-r--r--Source/kwsys/testDynamicLoader.cxx129
-rw-r--r--Source/kwsys/testDynload.c22
-rw-r--r--Source/kwsys/testEncode.c76
-rw-r--r--Source/kwsys/testEncoding.cxx199
-rw-r--r--Source/kwsys/testFStream.cxx190
-rw-r--r--Source/kwsys/testFail.c35
-rw-r--r--Source/kwsys/testHashSTL.cxx75
-rw-r--r--Source/kwsys/testIOS.cxx167
-rw-r--r--Source/kwsys/testProcess.c548
-rw-r--r--Source/kwsys/testSharedForward.c.in36
-rw-r--r--Source/kwsys/testSystemInformation.cxx118
-rw-r--r--Source/kwsys/testSystemTools.binbin0 -> 766 bytes
-rw-r--r--Source/kwsys/testSystemTools.cxx650
-rw-r--r--Source/kwsys/testSystemTools.h.in21
-rw-r--r--Source/kwsys/testTerminal.c31
-rw-r--r--Templates/AppleInfo.plist36
-rw-r--r--Templates/CMakeVSMacros1.vsmacrosbin0 -> 88064 bytes
-rw-r--r--Templates/CMakeVSMacros2.vsmacrosbin0 -> 63488 bytes
-rw-r--r--Templates/CMakeVisualStudio6Configurations.cmake3
-rw-r--r--Templates/CPack.GenericDescription.txt5
-rw-r--r--Templates/CPack.GenericLicense.txt5
-rw-r--r--Templates/CPack.GenericWelcome.txt1
-rw-r--r--Templates/CPackConfig.cmake.in20
-rw-r--r--Templates/CTestScript.cmake.in33
-rw-r--r--Templates/DLLFooter.dsptemplate4
-rw-r--r--Templates/DLLHeader.dsptemplate192
-rw-r--r--Templates/EXEFooter.dsptemplate4
-rw-r--r--Templates/EXEHeader.dsptemplate183
-rw-r--r--Templates/EXEWinHeader.dsptemplate187
-rw-r--r--Templates/TestDriver.cxx.in165
-rw-r--r--Templates/UtilityFooter.dsptemplate2
-rw-r--r--Templates/UtilityHeader.dsptemplate95
-rw-r--r--Templates/Windows/ApplicationIcon.pngbin0 -> 3392 bytes
-rw-r--r--Templates/Windows/Logo.pngbin0 -> 801 bytes
-rw-r--r--Templates/Windows/SmallLogo.pngbin0 -> 329 bytes
-rw-r--r--Templates/Windows/SplashScreen.pngbin0 -> 2146 bytes
-rw-r--r--Templates/Windows/StoreLogo.pngbin0 -> 429 bytes
-rw-r--r--Templates/Windows/Windows_TemporaryKey.pfxbin0 -> 2560 bytes
-rwxr-xr-xTemplates/cygwin-package.sh.in103
-rw-r--r--Templates/staticLibFooter.dsptemplate4
-rw-r--r--Templates/staticLibHeader.dsptemplate173
-rw-r--r--Tests/.NoDartCoverage1
-rw-r--r--Tests/AliasTarget/CMakeLists.txt80
-rw-r--r--Tests/AliasTarget/bat.cpp28
-rw-r--r--Tests/AliasTarget/commandgenerator.cpp15
-rw-r--r--Tests/AliasTarget/empty.cpp7
-rw-r--r--Tests/AliasTarget/object.cpp5
-rw-r--r--Tests/AliasTarget/object.h4
-rw-r--r--Tests/AliasTarget/targetgenerator.cpp13
-rw-r--r--Tests/Architecture/CMakeLists.txt59
-rw-r--r--Tests/Architecture/bar.c2
-rw-r--r--Tests/Architecture/foo.c1
-rw-r--r--Tests/ArgumentExpansion/CMakeLists.txt60
-rw-r--r--Tests/Assembler/CMakeLists.txt40
-rw-r--r--Tests/Assembler/main-linux-x86-gas.s28
-rw-r--r--Tests/Assembler/main.c12
-rw-r--r--Tests/BootstrapTest.cmake10
-rw-r--r--Tests/BuildDepends/CMakeLists.txt325
-rw-r--r--Tests/BuildDepends/Project/CMakeLists.txt153
-rw-r--r--Tests/BuildDepends/Project/External/CMakeLists.txt14
-rw-r--r--Tests/BuildDepends/Project/bar.cxx19
-rw-r--r--Tests/BuildDepends/Project/dep.cxx1
-rw-r--r--Tests/BuildDepends/Project/dep_custom.cxx1
-rw-r--r--Tests/BuildDepends/Project/dep_custom2.cxx2
-rw-r--r--Tests/BuildDepends/Project/generator.cxx24
-rw-r--r--Tests/BuildDepends/Project/link_depends_no_shared_check.cmake7
-rw-r--r--Tests/BuildDepends/Project/link_depends_no_shared_exe.c9
-rw-r--r--Tests/BuildDepends/Project/link_depends_no_shared_lib.c8
-rw-r--r--Tests/BuildDepends/Project/linkdep.cxx4
-rw-r--r--Tests/BuildDepends/Project/ninjadep.cpp6
-rw-r--r--Tests/BuildDepends/Project/zot.cxx14
-rw-r--r--Tests/BuildDepends/Project/zot_macro_dir.cxx7
-rw-r--r--Tests/BuildDepends/Project/zot_macro_tgt.cxx7
-rw-r--r--Tests/BundleGeneratorTest/BundleIcon.icnsbin0 -> 33452 bytes
-rw-r--r--Tests/BundleGeneratorTest/CMakeLists.txt33
-rw-r--r--Tests/BundleGeneratorTest/CustomVolumeIcon.icnsbin0 -> 37827 bytes
-rw-r--r--Tests/BundleGeneratorTest/Executable.cxx8
-rw-r--r--Tests/BundleGeneratorTest/Info.plist14
-rw-r--r--Tests/BundleGeneratorTest/Library.cxx7
-rwxr-xr-xTests/BundleGeneratorTest/StartupCommand12
-rw-r--r--Tests/BundleTest/BundleLib.cxx70
-rw-r--r--Tests/BundleTest/BundleSubDir/CMakeLists.txt36
-rw-r--r--Tests/BundleTest/BundleTest.cxx20
-rw-r--r--Tests/BundleTest/CMakeLists.txt104
-rw-r--r--Tests/BundleTest/SomeRandomFile.txt0
-rw-r--r--Tests/BundleTest/randomResourceFile.plist.in9
-rw-r--r--Tests/BundleUtilities/CMakeLists.txt127
-rw-r--r--Tests/BundleUtilities/bundleutils.cmake45
-rw-r--r--Tests/BundleUtilities/framework.cpp8
-rw-r--r--Tests/BundleUtilities/framework.h17
-rw-r--r--Tests/BundleUtilities/module.cpp10
-rw-r--r--Tests/BundleUtilities/module.h7
-rw-r--r--Tests/BundleUtilities/shared.cpp8
-rw-r--r--Tests/BundleUtilities/shared.h17
-rw-r--r--Tests/BundleUtilities/shared2.cpp8
-rw-r--r--Tests/BundleUtilities/shared2.h17
-rw-r--r--Tests/BundleUtilities/testbundleutils1.cpp33
-rw-r--r--Tests/BundleUtilities/testbundleutils2.cpp33
-rw-r--r--Tests/BundleUtilities/testbundleutils3.cpp33
-rw-r--r--Tests/CFBundleTest/CMakeLists.txt64
-rw-r--r--Tests/CFBundleTest/ExportList_plugin.txt3
-rw-r--r--Tests/CFBundleTest/Info.plist.in54
-rw-r--r--Tests/CFBundleTest/InfoPlist.strings.in4
-rw-r--r--Tests/CFBundleTest/Localized.r18
-rw-r--r--Tests/CFBundleTest/Localized.rsrcbin0 -> 496 bytes
-rw-r--r--Tests/CFBundleTest/PluginConfig.cmake21
-rw-r--r--Tests/CFBundleTest/README.txt16
-rw-r--r--Tests/CFBundleTest/VerifyResult.cmake32
-rw-r--r--Tests/CFBundleTest/np_macmain.cpp49
-rw-r--r--Tests/CMakeBuildTest.cmake.in61
-rw-r--r--Tests/CMakeCommands/add_compile_options/CMakeLists.txt21
-rw-r--r--Tests/CMakeCommands/add_compile_options/main.cpp11
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt34
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/consumer.cpp18
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/main.cpp14
-rw-r--r--Tests/CMakeCommands/target_compile_features/CMakeLists.txt45
-rw-r--r--Tests/CMakeCommands/target_compile_features/dummy.cpp5
-rw-r--r--Tests/CMakeCommands/target_compile_features/lib_auto_type.cpp6
-rw-r--r--Tests/CMakeCommands/target_compile_features/lib_auto_type.h8
-rw-r--r--Tests/CMakeCommands/target_compile_features/lib_restrict.c9
-rw-r--r--Tests/CMakeCommands/target_compile_features/lib_restrict.h7
-rw-r--r--Tests/CMakeCommands/target_compile_features/lib_user.cpp7
-rw-r--r--Tests/CMakeCommands/target_compile_features/main.c12
-rw-r--r--Tests/CMakeCommands/target_compile_features/main.cpp6
-rw-r--r--Tests/CMakeCommands/target_compile_features/restrict_user.c14
-rw-r--r--Tests/CMakeCommands/target_compile_options/CMakeLists.txt40
-rw-r--r--Tests/CMakeCommands/target_compile_options/consumer.cpp18
-rw-r--r--Tests/CMakeCommands/target_compile_options/main.cpp18
-rw-r--r--Tests/CMakeCommands/target_include_directories/CMakeLists.txt71
-rw-r--r--Tests/CMakeCommands/target_include_directories/consumer.cpp32
-rw-r--r--Tests/CMakeCommands/target_include_directories/main.cpp22
-rw-r--r--Tests/CMakeCommands/target_include_directories/relative_dir/consumer/consumer.h2
-rw-r--r--Tests/CMakeCommands/target_include_directories/relative_dir/relative_dir.h2
-rw-r--r--Tests/CMakeCommands/target_link_libraries/CMakeLists.txt132
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/CMakeLists.txt37
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022exe.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022ifacelib.cpp9
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022ifacelib.h9
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022lib.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022lib.h6
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib1.cpp13
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib1.h14
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib2.cpp8
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib2.h7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib_user.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib1.cpp2
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib1.h4
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib2.cpp2
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib2.h4
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib_exe.cpp8
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depA.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depA.h7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depB.cpp15
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depB.h7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depC.cpp13
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depC.h12
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depD.cpp13
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depD.h11
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depG.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depG.h7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depIfaceOnly.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depIfaceOnly.h7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/empty.cpp1
-rw-r--r--Tests/CMakeCommands/target_link_libraries/libgenex.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/libgenex.h12
-rw-r--r--Tests/CMakeCommands/target_link_libraries/newsignature1.cpp19
-rw-r--r--Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt5
-rw-r--r--Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h12
-rw-r--r--Tests/CMakeCommands/target_link_libraries/targetA.cpp19
-rw-r--r--Tests/CMakeCommands/target_link_libraries/targetB.cpp10
-rw-r--r--Tests/CMakeCommands/target_link_libraries/targetC.cpp16
-rw-r--r--Tests/CMakeCopyright.cmake22
-rw-r--r--Tests/CMakeInstall.cmake37
-rw-r--r--Tests/CMakeLib/CMakeLists.txt50
-rw-r--r--Tests/CMakeLib/run_compile_commands.cxx141
-rw-r--r--Tests/CMakeLib/testGeneratedFileStream.cxx100
-rw-r--r--Tests/CMakeLib/testRST.cxx101
-rw-r--r--Tests/CMakeLib/testRST.expect92
-rw-r--r--Tests/CMakeLib/testRST.rst99
-rw-r--r--Tests/CMakeLib/testRSTinclude1.rst6
-rw-r--r--Tests/CMakeLib/testRSTinclude2.rst3
-rw-r--r--Tests/CMakeLib/testRSTmod.cmake11
-rw-r--r--Tests/CMakeLib/testRSTtoc1.rst2
-rw-r--r--Tests/CMakeLib/testRSTtoc2.rst2
-rw-r--r--Tests/CMakeLib/testSystemTools.cxx33
-rw-r--r--Tests/CMakeLib/testUTF8.cxx125
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser.cxx185
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser.h.in7
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/.gitattributes1
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/bom.sln-file2
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-data.sln-file6
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-empty.sln-file0
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-global.sln-file9
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-header.sln-file4
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectArgs.sln-file4
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectContents.sln-file6
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectSection.sln-file11
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayParen.sln-file4
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayQuote.sln-file4
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayQuote2.sln-file4
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-topLevel.sln-file4
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-unclosed.sln-file5
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/nobom.sln-file2
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser_data/valid.sln-file680
-rw-r--r--Tests/CMakeLib/testXMLParser.cxx17
-rw-r--r--Tests/CMakeLib/testXMLParser.h.in6
-rw-r--r--Tests/CMakeLib/testXMLParser.xml4
-rw-r--r--Tests/CMakeLib/testXMLSafe.cxx47
-rw-r--r--Tests/CMakeLists.txt2993
-rw-r--r--Tests/CMakeOnly/AllFindModules/CMakeLists.txt95
-rw-r--r--Tests/CMakeOnly/CMakeLists.txt62
-rw-r--r--Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt58
-rw-r--r--Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt62
-rw-r--r--Tests/CMakeOnly/CheckLanguage/CMakeLists.txt22
-rw-r--r--Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt93
-rw-r--r--Tests/CMakeOnly/CheckStructHasMember/cm_cshm.h9
-rw-r--r--Tests/CMakeOnly/CheckStructHasMember/cm_cshm.hxx16
-rw-r--r--Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt51
-rw-r--r--Tests/CMakeOnly/CheckSymbolExists/cm_cse.h6
-rw-r--r--Tests/CMakeOnly/CompilerIdC/CMakeLists.txt14
-rw-r--r--Tests/CMakeOnly/CompilerIdCXX/CMakeLists.txt14
-rw-r--r--Tests/CMakeOnly/CompilerIdFortran/CMakeLists.txt22
-rw-r--r--Tests/CMakeOnly/LinkInterfaceLoop/CMakeLists.txt27
-rw-r--r--Tests/CMakeOnly/LinkInterfaceLoop/lib.c1
-rw-r--r--Tests/CMakeOnly/LinkInterfaceLoop/main.c1
-rw-r--r--Tests/CMakeOnly/MajorVersionSelection/CMakeLists.txt46
-rw-r--r--Tests/CMakeOnly/ProjectInclude/CMakeLists.txt4
-rw-r--r--Tests/CMakeOnly/ProjectInclude/include.cmake1
-rw-r--r--Tests/CMakeOnly/SelectLibraryConfigurations/CMakeLists.txt64
-rw-r--r--Tests/CMakeOnly/TargetScope/CMakeLists.txt13
-rw-r--r--Tests/CMakeOnly/TargetScope/Sib/CMakeLists.txt6
-rw-r--r--Tests/CMakeOnly/TargetScope/Sub/CMakeLists.txt9
-rw-r--r--Tests/CMakeOnly/TargetScope/Sub/Sub/CMakeLists.txt6
-rw-r--r--Tests/CMakeOnly/Test.cmake.in19
-rw-r--r--Tests/CMakeOnly/find_library/A/libtestA.a0
-rw-r--r--Tests/CMakeOnly/find_library/B/libtestB.a0
-rw-r--r--Tests/CMakeOnly/find_library/CMakeLists.txt74
-rw-r--r--Tests/CMakeOnly/find_library/lib/64/libtest2.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/A/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/libtest2.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/libtest3.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib64/A/lib64/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib64/A/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib64/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_path/CMakeLists.txt31
-rw-r--r--Tests/CMakeOnly/find_path/include/arch/test1arch.h0
-rw-r--r--Tests/CMakeOnly/find_path/include/test1.h0
-rw-r--r--Tests/CMakeTestAllGenerators/RunCMake.cmake117
-rw-r--r--Tests/CMakeTestBadCommandLines/RunCMake.cmake79
-rw-r--r--Tests/CMakeTestMultipleConfigures/RunCMake.cmake165
-rw-r--r--Tests/CMakeTests/.gitattributes1
-rw-r--r--Tests/CMakeTests/A/include/cmake_i_do_not_exist_in_the_system.h1
-rw-r--r--Tests/CMakeTests/CMakeHostSystemInformation-BadArg1.cmake1
-rw-r--r--Tests/CMakeTests/CMakeHostSystemInformation-BadArg2.cmake1
-rw-r--r--Tests/CMakeTests/CMakeHostSystemInformation-BadArg3.cmake1
-rw-r--r--Tests/CMakeTests/CMakeHostSystemInformation-QueryList.cmake5
-rw-r--r--Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in33
-rw-r--r--Tests/CMakeTests/CMakeLists.txt84
-rw-r--r--Tests/CMakeTests/CMakeMinimumRequiredTest.cmake.in18
-rw-r--r--Tests/CMakeTests/CMakeMinimumRequiredTestScript.cmake31
-rw-r--r--Tests/CMakeTests/CheckCMakeTest.cmake35
-rw-r--r--Tests/CMakeTests/CheckSourceTreeTest.cmake.in357
-rw-r--r--Tests/CMakeTests/CompilerIdVendorTest.cmake.in31
-rw-r--r--Tests/CMakeTests/ConfigureFile-BadArg.cmake1
-rw-r--r--Tests/CMakeTests/ConfigureFile-DirInput.cmake1
-rw-r--r--Tests/CMakeTests/ConfigureFile-DirOutput.cmake5
-rw-r--r--Tests/CMakeTests/ConfigureFile-NewLineStyle-COPYONLY.cmake3
-rw-r--r--Tests/CMakeTests/ConfigureFile-NewLineStyle-NoArg.cmake3
-rw-r--r--Tests/CMakeTests/ConfigureFile-NewLineStyle-ValidArg.cmake17
-rw-r--r--Tests/CMakeTests/ConfigureFile-NewLineStyle-WrongArg.cmake3
-rw-r--r--Tests/CMakeTests/ConfigureFile-Relative.cmake4
-rw-r--r--Tests/CMakeTests/ConfigureFileTest.cmake.in28
-rw-r--r--Tests/CMakeTests/DummyToolchain.cmake8
-rw-r--r--Tests/CMakeTests/ELF/elf32lsb.binbin0 -> 2824 bytes
-rw-r--r--Tests/CMakeTests/ELF/elf32msb.binbin0 -> 17984 bytes
-rw-r--r--Tests/CMakeTests/ELF/elf64lsb.binbin0 -> 4320 bytes
-rw-r--r--Tests/CMakeTests/ELF/elf64msb.binbin0 -> 18704 bytes
-rw-r--r--Tests/CMakeTests/ELFTest.cmake.in48
-rw-r--r--Tests/CMakeTests/EndStuffTest.cmake.in18
-rw-r--r--Tests/CMakeTests/EndStuffTestScript.cmake70
-rw-r--r--Tests/CMakeTests/ExecuteScriptTests.cmake63
-rw-r--r--Tests/CMakeTests/File-Copy-BadArg.cmake1
-rw-r--r--Tests/CMakeTests/File-Copy-BadPerm.cmake1
-rw-r--r--Tests/CMakeTests/File-Copy-BadRegex.cmake1
-rw-r--r--Tests/CMakeTests/File-Copy-EarlyArg.cmake1
-rw-r--r--Tests/CMakeTests/File-Copy-LateArg.cmake1
-rw-r--r--Tests/CMakeTests/File-Copy-NoDest.cmake1
-rw-r--r--Tests/CMakeTests/File-Copy-NoFile.cmake1
-rw-r--r--Tests/CMakeTests/File-Glob-NoArg.cmake2
-rw-r--r--Tests/CMakeTests/File-HASH-Input.txt1
-rw-r--r--Tests/CMakeTests/File-MD5-BadArg1.cmake1
-rw-r--r--Tests/CMakeTests/File-MD5-BadArg2.cmake1
-rw-r--r--Tests/CMakeTests/File-MD5-BadArg4.cmake1
-rw-r--r--Tests/CMakeTests/File-MD5-NoFile.cmake1
-rw-r--r--Tests/CMakeTests/File-MD5-Works.cmake2
-rw-r--r--Tests/CMakeTests/File-SHA1-Works.cmake2
-rw-r--r--Tests/CMakeTests/File-SHA224-Works.cmake2
-rw-r--r--Tests/CMakeTests/File-SHA256-Works.cmake2
-rw-r--r--Tests/CMakeTests/File-SHA384-Works.cmake2
-rw-r--r--Tests/CMakeTests/File-SHA512-Works.cmake2
-rw-r--r--Tests/CMakeTests/File-TIMESTAMP-BadArg1.cmake1
-rw-r--r--Tests/CMakeTests/File-TIMESTAMP-NoFile.cmake2
-rw-r--r--Tests/CMakeTests/File-TIMESTAMP-NotBogus.cmake24
-rw-r--r--Tests/CMakeTests/File-TIMESTAMP-Works.cmake2
-rw-r--r--Tests/CMakeTests/FileDownloadBadHashTest.cmake.in10
-rw-r--r--Tests/CMakeTests/FileDownloadInput.pngbin0 -> 358 bytes
-rw-r--r--Tests/CMakeTests/FileDownloadTest.cmake.in109
-rw-r--r--Tests/CMakeTests/FileTest.cmake.in97
-rw-r--r--Tests/CMakeTests/FileTestScript.cmake227
-rw-r--r--Tests/CMakeTests/FileUploadTest.cmake.in49
-rw-r--r--Tests/CMakeTests/FindBaseTest.cmake.in62
-rw-r--r--Tests/CMakeTests/GetFilenameComponentRealpathTest.cmake.in72
-rw-r--r--Tests/CMakeTests/GetPrerequisitesTest.cmake.in159
-rw-r--r--Tests/CMakeTests/GetProperty-Bad-Argument.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-Bad-Directory.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-Bad-Scope.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-Bad-Target.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-Bad-Test.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-Global-Name.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-Missing-Argument.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-No-Cache.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-No-Property.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-No-Source.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-No-Target.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-No-Test.cmake1
-rw-r--r--Tests/CMakeTests/GetProperty-Variable-Name.cmake1
-rw-r--r--Tests/CMakeTests/GetPropertyTest.cmake.in112
-rw-r--r--Tests/CMakeTests/If-Invalid-Argument.cmake2
-rw-r--r--Tests/CMakeTests/IfTest.cmake.in169
-rw-r--r--Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in529
-rw-r--r--Tests/CMakeTests/IncludeTest.cmake.in41
-rw-r--r--Tests/CMakeTests/List-Get-CMP0007-Warn.cmake6
-rw-r--r--Tests/CMakeTests/List-Get-Invalid-Index.cmake2
-rw-r--r--Tests/CMakeTests/List-Insert-Invalid-Index.cmake2
-rw-r--r--Tests/CMakeTests/List-Invalid-Subcommand.cmake1
-rw-r--r--Tests/CMakeTests/List-Length-Too-Many-Arguments.cmake1
-rw-r--r--Tests/CMakeTests/List-No-Arguments.cmake1
-rw-r--r--Tests/CMakeTests/List-Remove_At-Invalid-Index.cmake2
-rw-r--r--Tests/CMakeTests/List-Remove_At-Nonexistent-List.cmake2
-rw-r--r--Tests/CMakeTests/List-Remove_Duplicates-Nonexistent-List.cmake2
-rw-r--r--Tests/CMakeTests/List-Remove_Duplicates-Too-Many-Arguments.cmake1
-rw-r--r--Tests/CMakeTests/List-Remove_Item-Nonexistent-List.cmake2
-rw-r--r--Tests/CMakeTests/List-Reverse-Nonexistent-List.cmake2
-rw-r--r--Tests/CMakeTests/List-Reverse-Too-Many-Arguments.cmake1
-rw-r--r--Tests/CMakeTests/List-Sort-Nonexistent-List.cmake2
-rw-r--r--Tests/CMakeTests/List-Sort-Too-Many-Arguments.cmake1
-rw-r--r--Tests/CMakeTests/ListTest.cmake.in190
-rw-r--r--Tests/CMakeTests/Make_Directory-NoArg.cmake1
-rw-r--r--Tests/CMakeTests/MathTest.cmake.in18
-rw-r--r--Tests/CMakeTests/MathTestScript.cmake18
-rw-r--r--Tests/CMakeTests/MessageTest.cmake.in30
-rw-r--r--Tests/CMakeTests/MessageTestScript.cmake4
-rw-r--r--Tests/CMakeTests/ModuleNoticesTest.cmake.in46
-rw-r--r--Tests/CMakeTests/PolicyCheckTest.cmake.in154
-rw-r--r--Tests/CMakeTests/ProcessorCountTest.cmake.in79
-rw-r--r--Tests/CMakeTests/PushCheckStateTest.cmake.in30
-rw-r--r--Tests/CMakeTests/SeparateArgumentsTest.cmake.in25
-rw-r--r--Tests/CMakeTests/String-MD5-BadArg1.cmake1
-rw-r--r--Tests/CMakeTests/String-MD5-BadArg2.cmake1
-rw-r--r--Tests/CMakeTests/String-MD5-BadArg4.cmake1
-rw-r--r--Tests/CMakeTests/String-MD5-Works.cmake2
-rw-r--r--Tests/CMakeTests/String-SHA1-Works.cmake2
-rw-r--r--Tests/CMakeTests/String-SHA224-Works.cmake2
-rw-r--r--Tests/CMakeTests/String-SHA256-Works.cmake2
-rw-r--r--Tests/CMakeTests/String-SHA384-Works.cmake2
-rw-r--r--Tests/CMakeTests/String-SHA512-Works.cmake2
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-AllSpecifiers.cmake11
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-BadArg1.cmake1
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-BadArg2.cmake1
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-BadArg3.cmake1
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-CustomFormatLocal.cmake2
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-CustomFormatUTC.cmake2
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-DefaultFormatLocal.cmake2
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-DefaultFormatUTC.cmake2
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-IncompleteSpecifier.cmake2
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-UnknownSpecifier.cmake2
-rw-r--r--Tests/CMakeTests/StringTest.cmake.in80
-rw-r--r--Tests/CMakeTests/StringTestScript.cmake279
-rw-r--r--Tests/CMakeTests/ToolchainTest.cmake.in139
-rw-r--r--Tests/CMakeTests/VariableWatchTest.cmake.in31
-rw-r--r--Tests/CMakeTests/VersionTest.cmake.in16
-rw-r--r--Tests/CMakeTests/While-Endwhile-Alone-Args.cmake1
-rw-r--r--Tests/CMakeTests/While-Endwhile-Alone.cmake1
-rw-r--r--Tests/CMakeTests/While-Endwhile-Mismatch.cmake2
-rw-r--r--Tests/CMakeTests/While-Missing-Argument.cmake1
-rw-r--r--Tests/CMakeTests/While-Missing-Endwhile.cmake1
-rw-r--r--Tests/CMakeTests/WhileTest.cmake.in57
-rw-r--r--Tests/CMakeTests/include/cmake_i_do_not_exist_in_the_system.h1
-rw-r--r--Tests/COnly/CMakeLists.txt23
-rw-r--r--Tests/COnly/conly.c23
-rw-r--r--Tests/COnly/foo.c1
-rw-r--r--Tests/COnly/foo.h1
-rw-r--r--Tests/COnly/libc1.c4
-rw-r--r--Tests/COnly/libc1.h1
-rw-r--r--Tests/COnly/libc2.c6
-rw-r--r--Tests/COnly/libc2.h11
-rw-r--r--Tests/COnly/testCModule.c6
-rw-r--r--Tests/CPackComponents/CMakeLists.txt128
-rw-r--r--Tests/CPackComponents/Issue 7470.html9
-rw-r--r--Tests/CPackComponents/VerifyResult.cmake48
-rw-r--r--Tests/CPackComponents/mylib.cpp7
-rw-r--r--Tests/CPackComponents/mylib.h1
-rw-r--r--Tests/CPackComponents/mylibapp.cpp6
-rw-r--r--Tests/CPackComponentsForAll/CMakeLists.txt124
-rw-r--r--Tests/CPackComponentsForAll/MyLibCPackConfig-AllInOne.cmake.in22
-rw-r--r--Tests/CPackComponentsForAll/MyLibCPackConfig-IgnoreGroup.cmake.in23
-rw-r--r--Tests/CPackComponentsForAll/MyLibCPackConfig-OnePackPerGroup.cmake.in27
-rw-r--r--Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake125
-rw-r--r--Tests/CPackComponentsForAll/license.txt3
-rw-r--r--Tests/CPackComponentsForAll/mylib.cpp7
-rw-r--r--Tests/CPackComponentsForAll/mylib.h1
-rw-r--r--Tests/CPackComponentsForAll/mylibapp.cpp6
-rw-r--r--Tests/CPackTestAllGenerators/CMakeLists.txt5
-rw-r--r--Tests/CPackTestAllGenerators/RunCPack.cmake51
-rw-r--r--Tests/CPackWiXGenerator/CMakeLists.txt116
-rw-r--r--Tests/CPackWiXGenerator/RunCPackVerifyResult.cmake77
-rw-r--r--Tests/CPackWiXGenerator/file with spaces.h0
-rw-r--r--Tests/CPackWiXGenerator/license.txt9
-rw-r--r--Tests/CPackWiXGenerator/mylib.cpp7
-rw-r--r--Tests/CPackWiXGenerator/mylib.h1
-rw-r--r--Tests/CPackWiXGenerator/mylibapp.cpp6
-rw-r--r--Tests/CPackWiXGenerator/myotherapp.cpp1
-rw-r--r--Tests/CPackWiXGenerator/patch.xml7
-rw-r--r--Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in12
-rw-r--r--Tests/CTestConfig/CMakeLists.txt47
-rw-r--r--Tests/CTestConfig/CTestConfig.cxx20
-rw-r--r--Tests/CTestConfig/ScriptWithArgs.cmake16
-rw-r--r--Tests/CTestConfig/dashboard.cmake.in47
-rw-r--r--Tests/CTestConfig/script.cmake.in23
-rw-r--r--Tests/CTestLimitDashJ/CMakeLists.txt50
-rw-r--r--Tests/CTestLimitDashJ/CreateSleepDelete.cmake48
-rw-r--r--Tests/CTestScriptMode/CTestTestScriptMode.cmake.in14
-rw-r--r--Tests/CTestTest/SmallAndFast/CMakeLists.txt25
-rw-r--r--Tests/CTestTest/SmallAndFast/echoargs.c11
-rw-r--r--Tests/CTestTest/SmallAndFast/intentional_compile_error.cxx1
-rw-r--r--Tests/CTestTest/SmallAndFast/intentional_compile_warning.cxx11
-rw-r--r--Tests/CTestTest/test.cmake.in70
-rw-r--r--Tests/CTestTest2/test.cmake.in62
-rw-r--r--Tests/CTestTestBadExe/CMakeLists.txt7
-rw-r--r--Tests/CTestTestBadExe/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestBadExe/notAnExe.txt1
-rw-r--r--Tests/CTestTestBadExe/test.cmake.in23
-rw-r--r--Tests/CTestTestBadGenerator/CMakeLists.txt3
-rw-r--r--Tests/CTestTestBadGenerator/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestBadGenerator/test.cmake.in21
-rw-r--r--Tests/CTestTestChecksum/test.cmake.in27
-rw-r--r--Tests/CTestTestConfigFileInBuildDir/CMakeLists.txt3
-rw-r--r--Tests/CTestTestConfigFileInBuildDir/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestConfigFileInBuildDir/test1.cmake.in19
-rw-r--r--Tests/CTestTestConfigFileInBuildDir/test2.cmake.in19
-rw-r--r--Tests/CTestTestCostSerial/CMakeLists.txt13
-rw-r--r--Tests/CTestTestCostSerial/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestCostSerial/sleep.c16
-rw-r--r--Tests/CTestTestCostSerial/test.cmake.in30
-rw-r--r--Tests/CTestTestCrash/CMakeLists.txt7
-rw-r--r--Tests/CTestTestCrash/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestCrash/crash.cxx6
-rw-r--r--Tests/CTestTestCrash/test.cmake.in24
-rw-r--r--Tests/CTestTestCycle/CMakeLists.txt13
-rw-r--r--Tests/CTestTestCycle/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestCycle/simple.cxx5
-rw-r--r--Tests/CTestTestCycle/test.cmake.in21
-rw-r--r--Tests/CTestTestDepends/CMakeLists.txt13
-rw-r--r--Tests/CTestTestDepends/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestDepends/simple.cxx5
-rw-r--r--Tests/CTestTestDepends/test.cmake.in21
-rw-r--r--Tests/CTestTestEmptyBinaryDirectory/test.cmake.in66
-rw-r--r--Tests/CTestTestFailedSubmits/test.cmake.in49
-rw-r--r--Tests/CTestTestFailure/CMakeLists.txt8
-rw-r--r--Tests/CTestTestFailure/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestFailure/badCode.cxx4
-rw-r--r--Tests/CTestTestFailure/testNoBuild.cmake.in23
-rw-r--r--Tests/CTestTestFailure/testNoExe.cmake.in21
-rw-r--r--Tests/CTestTestFdSetSize/CMakeLists.txt9
-rw-r--r--Tests/CTestTestFdSetSize/CTestConfig.cmake1
-rw-r--r--Tests/CTestTestFdSetSize/sleep.c16
-rw-r--r--Tests/CTestTestFdSetSize/test.cmake.in24
-rw-r--r--Tests/CTestTestLabelRegExp/CTestTestfile.cmake.in8
-rw-r--r--Tests/CTestTestLabelRegExp/test.cmake.in37
-rw-r--r--Tests/CTestTestLaunchers/launcher_test_project/CMakeLists.txt19
-rw-r--r--Tests/CTestTestLaunchers/launcher_test_project/CTestConfig.cmake8
-rw-r--r--Tests/CTestTestLaunchers/launcher_test_project/command.cmake5
-rw-r--r--Tests/CTestTestLaunchers/test.cmake.in40
-rw-r--r--Tests/CTestTestMemcheck/CMakeLists.txt290
-rw-r--r--Tests/CTestTestMemcheck/CMakeLists.txt.in7
-rw-r--r--Tests/CTestTestMemcheck/CTestConfig.cmake.in9
-rw-r--r--Tests/CTestTestMemcheck/NoLogDummyChecker/CMakeLists.txt22
-rw-r--r--Tests/CTestTestMemcheck/memtester.cxx.in60
-rw-r--r--Tests/CTestTestMemcheck/test.cmake.in26
-rw-r--r--Tests/CTestTestMemcheck/testAddressSanitizer.cmake58
-rw-r--r--Tests/CTestTestMemcheck/testLeakSanitizer.cmake47
-rw-r--r--Tests/CTestTestMemcheck/testMemorySanitizer.cmake27
-rw-r--r--Tests/CTestTestMemcheck/testThreadSanitizer.cmake47
-rw-r--r--Tests/CTestTestMemcheck/testUndefinedBehaviorSanitizer.cmake21
-rw-r--r--Tests/CTestTestMissingDependsExe/CMakeLists.txt10
-rw-r--r--Tests/CTestTestParallel/CMakeLists.txt15
-rw-r--r--Tests/CTestTestParallel/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestParallel/lockFile.c20
-rw-r--r--Tests/CTestTestParallel/test.cmake.in23
-rw-r--r--Tests/CTestTestResourceLock/CMakeLists.txt13
-rw-r--r--Tests/CTestTestResourceLock/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestResourceLock/lockFile.c31
-rw-r--r--Tests/CTestTestResourceLock/test.cmake.in21
-rw-r--r--Tests/CTestTestRunScript/hello.cmake.in2
-rw-r--r--Tests/CTestTestRunScript/test.cmake.in2
-rw-r--r--Tests/CTestTestScheduler/CMakeLists.txt9
-rw-r--r--Tests/CTestTestScheduler/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestScheduler/sleep.c21
-rw-r--r--Tests/CTestTestScheduler/test.cmake.in30
-rw-r--r--Tests/CTestTestSerialInDepends/CMakeLists.txt23
-rw-r--r--Tests/CTestTestSerialInDepends/test.ctest16
-rw-r--r--Tests/CTestTestSerialOrder/CMakeLists.txt40
-rw-r--r--Tests/CTestTestSerialOrder/test.cmake31
-rw-r--r--Tests/CTestTestSkipReturnCode/CMakeLists.txt8
-rw-r--r--Tests/CTestTestSkipReturnCode/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestSkipReturnCode/test.cmake.in23
-rw-r--r--Tests/CTestTestStopTime/CMakeLists.txt11
-rw-r--r--Tests/CTestTestStopTime/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestStopTime/GetDate.cmake132
-rw-r--r--Tests/CTestTestStopTime/sleep.c21
-rw-r--r--Tests/CTestTestStopTime/test.cmake.in33
-rw-r--r--Tests/CTestTestSubdir/CMakeLists.txt7
-rw-r--r--Tests/CTestTestSubdir/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestSubdir/subdir/CMakeLists.txt2
-rw-r--r--Tests/CTestTestSubdir/subdir/main.c4
-rw-r--r--Tests/CTestTestSubdir/subdir2/CMakeLists.txt2
-rw-r--r--Tests/CTestTestSubdir/subdir2/main.c4
-rw-r--r--Tests/CTestTestSubdir/subdir3/CMakeLists.txt2
-rw-r--r--Tests/CTestTestSubdir/subdir3/main.c4
-rw-r--r--Tests/CTestTestSubdir/test.cmake.in23
-rw-r--r--Tests/CTestTestTimeout/CMakeLists.txt21
-rw-r--r--Tests/CTestTestTimeout/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestTimeout/sleep.c21
-rw-r--r--Tests/CTestTestTimeout/test.cmake.in40
-rw-r--r--Tests/CTestTestTimeout/timeout.cmake6
-rw-r--r--Tests/CTestTestUpload/CMakeLists.txt4
-rw-r--r--Tests/CTestTestUpload/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestUpload/sleep.c21
-rw-r--r--Tests/CTestTestUpload/test.cmake.in19
-rw-r--r--Tests/CTestTestZeroTimeout/CMakeLists.txt8
-rw-r--r--Tests/CTestTestZeroTimeout/CTestConfig.cmake7
-rw-r--r--Tests/CTestTestZeroTimeout/sleep.c16
-rw-r--r--Tests/CTestTestZeroTimeout/test.cmake.in22
-rw-r--r--Tests/CTestUpdateBZR.cmake.in153
-rw-r--r--Tests/CTestUpdateCVS.cmake.in172
-rw-r--r--Tests/CTestUpdateCommon.cmake279
-rw-r--r--Tests/CTestUpdateGIT.cmake.in336
-rwxr-xr-xTests/CTestUpdateGIT.sh.in6
-rw-r--r--Tests/CTestUpdateHG.cmake.in166
-rw-r--r--Tests/CTestUpdateP4.cmake.in261
-rw-r--r--Tests/CTestUpdateSVN.cmake.in149
-rw-r--r--Tests/CheckCompilerRelatedVariables/CMakeLists.txt109
-rw-r--r--Tests/CheckFortran.cmake50
-rw-r--r--Tests/CoberturaCoverage/DartConfiguration.tcl.in8
-rw-r--r--Tests/CoberturaCoverage/coverage.xml.in112
-rw-r--r--Tests/CoberturaCoverage/src/main/java/org/cmake/CoverageTest.java52
-rw-r--r--Tests/CommandLineTest/CMakeLists.txt79
-rw-r--r--Tests/CommandLineTest/CommandLineTest.cxx4
-rw-r--r--Tests/CommandLineTest/PreLoad.cmake1
-rw-r--r--Tests/CompatibleInterface/CMakeLists.txt130
-rw-r--r--Tests/CompatibleInterface/bar.cpp7
-rw-r--r--Tests/CompatibleInterface/empty.cpp1
-rw-r--r--Tests/CompatibleInterface/foo.cpp4
-rw-r--r--Tests/CompatibleInterface/iface2.cpp7
-rw-r--r--Tests/CompatibleInterface/iface2.h13
-rw-r--r--Tests/CompatibleInterface/main.cpp53
-rw-r--r--Tests/CompileCommandOutput/CMakeLists.txt16
-rw-r--r--Tests/CompileCommandOutput/compile_command_output.cxx9
-rw-r--r--Tests/CompileCommandOutput/file with spaces.cxx1
-rw-r--r--Tests/CompileCommandOutput/file_with_underscores.cxx3
-rw-r--r--Tests/CompileCommandOutput/file_with_underscores.h1
-rw-r--r--Tests/CompileCommandOutput/relative.cxx3
-rw-r--r--Tests/CompileCommandOutput/relative.h11
-rw-r--r--Tests/CompileDefinitions/CMakeLists.txt26
-rw-r--r--Tests/CompileDefinitions/add_definitions_command/CMakeLists.txt15
-rw-r--r--Tests/CompileDefinitions/add_definitions_command_with_target_prop/CMakeLists.txt19
-rw-r--r--Tests/CompileDefinitions/compiletest.c23
-rw-r--r--Tests/CompileDefinitions/compiletest.cpp104
-rw-r--r--Tests/CompileDefinitions/compiletest_mixed_c.c23
-rw-r--r--Tests/CompileDefinitions/compiletest_mixed_cxx.cpp23
-rw-r--r--Tests/CompileDefinitions/runtest.c47
-rw-r--r--Tests/CompileDefinitions/target_prop/CMakeLists.txt60
-rw-r--r--Tests/CompileDefinitions/target_prop/usetgt.c10
-rw-r--r--Tests/CompileFeatures/CMakeLists.txt112
-rw-r--r--Tests/CompileFeatures/c_function_prototypes.c9
-rw-r--r--Tests/CompileFeatures/c_restrict.c7
-rw-r--r--Tests/CompileFeatures/c_static_assert.c2
-rw-r--r--Tests/CompileFeatures/c_variadic_macros.c15
-rw-r--r--Tests/CompileFeatures/cxx_aggregate_default_initializers.cpp9
-rw-r--r--Tests/CompileFeatures/cxx_alias_templates.cpp11
-rw-r--r--Tests/CompileFeatures/cxx_alignas.cpp4
-rw-r--r--Tests/CompileFeatures/cxx_alignof.cpp5
-rw-r--r--Tests/CompileFeatures/cxx_attribute_deprecated.cpp11
-rw-r--r--Tests/CompileFeatures/cxx_attributes.cpp2
-rw-r--r--Tests/CompileFeatures/cxx_auto_type.cpp5
-rw-r--r--Tests/CompileFeatures/cxx_binary_literals.cpp6
-rw-r--r--Tests/CompileFeatures/cxx_constexpr.cpp5
-rw-r--r--Tests/CompileFeatures/cxx_contextual_conversions.cpp33
-rw-r--r--Tests/CompileFeatures/cxx_decltype.cpp7
-rw-r--r--Tests/CompileFeatures/cxx_decltype_auto.cpp6
-rw-r--r--Tests/CompileFeatures/cxx_decltype_incomplete_return_types.cpp14
-rw-r--r--Tests/CompileFeatures/cxx_default_function_template_args.cpp12
-rw-r--r--Tests/CompileFeatures/cxx_defaulted_functions.cpp9
-rw-r--r--Tests/CompileFeatures/cxx_defaulted_move_initializers.cpp7
-rw-r--r--Tests/CompileFeatures/cxx_delegating_constructors.cpp15
-rw-r--r--Tests/CompileFeatures/cxx_deleted_functions.cpp6
-rw-r--r--Tests/CompileFeatures/cxx_digit_separators.cpp6
-rw-r--r--Tests/CompileFeatures/cxx_enum_forward_declarations.cpp8
-rw-r--r--Tests/CompileFeatures/cxx_explicit_conversions.cpp10
-rw-r--r--Tests/CompileFeatures/cxx_extended_friend_declarations.cpp25
-rw-r--r--Tests/CompileFeatures/cxx_extern_templates.cpp12
-rw-r--r--Tests/CompileFeatures/cxx_final.cpp2
-rw-r--r--Tests/CompileFeatures/cxx_func_identifier.cpp6
-rw-r--r--Tests/CompileFeatures/cxx_generalized_initializers.cpp23
-rw-r--r--Tests/CompileFeatures/cxx_generic_lambdas.cpp6
-rw-r--r--Tests/CompileFeatures/cxx_inheriting_constructors.cpp18
-rw-r--r--Tests/CompileFeatures/cxx_inline_namespaces.cpp26
-rw-r--r--Tests/CompileFeatures/cxx_lambda_init_captures.cpp6
-rw-r--r--Tests/CompileFeatures/cxx_lambdas.cpp5
-rw-r--r--Tests/CompileFeatures/cxx_local_type_template_args.cpp21
-rw-r--r--Tests/CompileFeatures/cxx_long_long_type.cpp5
-rw-r--r--Tests/CompileFeatures/cxx_noexcept.cpp5
-rw-r--r--Tests/CompileFeatures/cxx_nonstatic_member_init.cpp4
-rw-r--r--Tests/CompileFeatures/cxx_nullptr.cpp10
-rw-r--r--Tests/CompileFeatures/cxx_override.cpp7
-rw-r--r--Tests/CompileFeatures/cxx_range_for.cpp10
-rw-r--r--Tests/CompileFeatures/cxx_raw_string_literals.cpp7
-rw-r--r--Tests/CompileFeatures/cxx_reference_qualified_functions.cpp11
-rw-r--r--Tests/CompileFeatures/cxx_relaxed_constexpr.cpp23
-rw-r--r--Tests/CompileFeatures/cxx_return_type_deduction.cpp10
-rw-r--r--Tests/CompileFeatures/cxx_right_angle_brackets.cpp12
-rw-r--r--Tests/CompileFeatures/cxx_rvalue_references.cpp5
-rw-r--r--Tests/CompileFeatures/cxx_sizeof_member.cpp10
-rw-r--r--Tests/CompileFeatures/cxx_static_assert.cpp2
-rw-r--r--Tests/CompileFeatures/cxx_strong_enums.cpp7
-rw-r--r--Tests/CompileFeatures/cxx_template_template_parameters.cpp18
-rw-r--r--Tests/CompileFeatures/cxx_thread_local.cpp2
-rw-r--r--Tests/CompileFeatures/cxx_trailing_return_types.cpp5
-rw-r--r--Tests/CompileFeatures/cxx_unicode_literals.cpp3
-rw-r--r--Tests/CompileFeatures/cxx_uniform_initialization.cpp9
-rw-r--r--Tests/CompileFeatures/cxx_unrestricted_unions.cpp11
-rw-r--r--Tests/CompileFeatures/cxx_user_literals.cpp7
-rw-r--r--Tests/CompileFeatures/cxx_variable_templates.cpp10
-rw-r--r--Tests/CompileFeatures/cxx_variadic_macros.cpp12
-rw-r--r--Tests/CompileFeatures/cxx_variadic_templates.cpp65
-rw-r--r--Tests/CompileFeatures/feature_test.cpp10
-rw-r--r--Tests/CompileFeatures/genex_test.cpp21
-rw-r--r--Tests/CompileFeatures/main.c12
-rw-r--r--Tests/CompileFeatures/main.cpp6
-rw-r--r--Tests/CompileOptions/CMakeLists.txt44
-rw-r--r--Tests/CompileOptions/main.cpp27
-rw-r--r--Tests/CompileOptions/other.cpp5
-rw-r--r--Tests/Complex/CMakeLists.txt441
-rw-r--r--Tests/Complex/Cache/CMakeCache.txt34
-rw-r--r--Tests/Complex/Executable/A.cxx9
-rw-r--r--Tests/Complex/Executable/A.h4
-rw-r--r--Tests/Complex/Executable/A.hh2
-rw-r--r--Tests/Complex/Executable/A.txt1
-rw-r--r--Tests/Complex/Executable/CMakeLists.txt169
-rw-r--r--Tests/Complex/Executable/Included.cmake2
-rw-r--r--Tests/Complex/Executable/Sub1/NameConflictTest.c4
-rw-r--r--Tests/Complex/Executable/Sub2/NameConflictTest.c4
-rw-r--r--Tests/Complex/Executable/Temp/CMakeLists.txt8
-rw-r--r--Tests/Complex/Executable/cmVersion.h.in1
-rw-r--r--Tests/Complex/Executable/complex.cxx946
-rw-r--r--Tests/Complex/Executable/complex.file.cxx8
-rw-r--r--Tests/Complex/Executable/complex_nobuild.c1
-rw-r--r--Tests/Complex/Executable/complex_nobuild.cxx1
-rw-r--r--Tests/Complex/Executable/notInAllExe.cxx10
-rw-r--r--Tests/Complex/Executable/testSystemDir.cxx3
-rw-r--r--Tests/Complex/Executable/testcflags.c26
-rw-r--r--Tests/Complex/Library/CMakeLists.txt140
-rw-r--r--Tests/Complex/Library/ExtraSources/file1.cxx4
-rw-r--r--Tests/Complex/Library/ExtraSources/file1.h1
-rw-r--r--Tests/Complex/Library/SystemDir/testSystemDir.h2
-rw-r--r--Tests/Complex/Library/TestLink.c8
-rw-r--r--Tests/Complex/Library/create_file.cxx28
-rw-r--r--Tests/Complex/Library/dummy0
-rw-r--r--Tests/Complex/Library/empty.h0
-rw-r--r--Tests/Complex/Library/file2.cxx10
-rw-r--r--Tests/Complex/Library/file2.h1
-rw-r--r--Tests/Complex/Library/notInAllLib.cxx5
-rw-r--r--Tests/Complex/Library/sharedFile.cxx6
-rw-r--r--Tests/Complex/Library/sharedFile.h12
-rw-r--r--Tests/Complex/Library/testConly.c13
-rw-r--r--Tests/Complex/Library/testConly.h13
-rw-r--r--Tests/Complex/Library/test_preprocess.cmake7
-rw-r--r--Tests/Complex/VarTests.cmake184
-rw-r--r--Tests/Complex/cmTestConfigure.h.in76
-rw-r--r--Tests/Complex/cmTestConfigureEscape.h.in1
-rw-r--r--Tests/Complex/cmTestGeneratedHeader.h.in1
-rw-r--r--Tests/ComplexOneConfig/CMakeLists.txt411
-rw-r--r--Tests/ComplexOneConfig/Cache/CMakeCache.txt34
-rw-r--r--Tests/ComplexOneConfig/Executable/A.cxx9
-rw-r--r--Tests/ComplexOneConfig/Executable/A.h4
-rw-r--r--Tests/ComplexOneConfig/Executable/A.hh2
-rw-r--r--Tests/ComplexOneConfig/Executable/A.txt1
-rw-r--r--Tests/ComplexOneConfig/Executable/CMakeLists.txt169
-rw-r--r--Tests/ComplexOneConfig/Executable/Included.cmake2
-rw-r--r--Tests/ComplexOneConfig/Executable/Sub1/NameConflictTest.c4
-rw-r--r--Tests/ComplexOneConfig/Executable/Sub2/NameConflictTest.c4
-rw-r--r--Tests/ComplexOneConfig/Executable/Temp/CMakeLists.txt8
-rw-r--r--Tests/ComplexOneConfig/Executable/cmVersion.h.in1
-rw-r--r--Tests/ComplexOneConfig/Executable/complex.cxx946
-rw-r--r--Tests/ComplexOneConfig/Executable/complex.file.cxx8
-rw-r--r--Tests/ComplexOneConfig/Executable/complex_nobuild.c1
-rw-r--r--Tests/ComplexOneConfig/Executable/complex_nobuild.cxx1
-rw-r--r--Tests/ComplexOneConfig/Executable/notInAllExe.cxx10
-rw-r--r--Tests/ComplexOneConfig/Executable/testSystemDir.cxx3
-rw-r--r--Tests/ComplexOneConfig/Executable/testcflags.c26
-rw-r--r--Tests/ComplexOneConfig/Library/CMakeLists.txt140
-rw-r--r--Tests/ComplexOneConfig/Library/ExtraSources/file1.cxx4
-rw-r--r--Tests/ComplexOneConfig/Library/ExtraSources/file1.h1
-rw-r--r--Tests/ComplexOneConfig/Library/SystemDir/testSystemDir.h2
-rw-r--r--Tests/ComplexOneConfig/Library/TestLink.c8
-rw-r--r--Tests/ComplexOneConfig/Library/create_file.cxx28
-rw-r--r--Tests/ComplexOneConfig/Library/dummy0
-rw-r--r--Tests/ComplexOneConfig/Library/empty.h0
-rw-r--r--Tests/ComplexOneConfig/Library/file2.cxx10
-rw-r--r--Tests/ComplexOneConfig/Library/file2.h1
-rw-r--r--Tests/ComplexOneConfig/Library/notInAllLib.cxx5
-rw-r--r--Tests/ComplexOneConfig/Library/sharedFile.cxx6
-rw-r--r--Tests/ComplexOneConfig/Library/sharedFile.h12
-rw-r--r--Tests/ComplexOneConfig/Library/testConly.c13
-rw-r--r--Tests/ComplexOneConfig/Library/testConly.h13
-rw-r--r--Tests/ComplexOneConfig/Library/test_preprocess.cmake7
-rw-r--r--Tests/ComplexOneConfig/VarTests.cmake184
-rw-r--r--Tests/ComplexOneConfig/cmTestConfigure.h.in76
-rw-r--r--Tests/ComplexOneConfig/cmTestConfigureEscape.h.in1
-rw-r--r--Tests/ComplexOneConfig/cmTestGeneratedHeader.h.in1
-rw-r--r--Tests/ConfigSources/CMakeLists.txt17
-rw-r--r--Tests/ConfigSources/iface_debug.h4
-rw-r--r--Tests/ConfigSources/iface_debug_src.cpp7
-rw-r--r--Tests/ConfigSources/iface_src.cpp5
-rw-r--r--Tests/ConfigSources/main.cpp7
-rw-r--r--Tests/Contracts/Trilinos/CMakeLists.txt103
-rw-r--r--Tests/Contracts/Trilinos/Dashboard.cmake.in63
-rw-r--r--Tests/Contracts/Trilinos/EnvScript.cmake32
-rw-r--r--Tests/Contracts/Trilinos/Patch.cmake38
-rw-r--r--Tests/Contracts/Trilinos/RunTest.cmake7
-rw-r--r--Tests/Contracts/Trilinos/ValidateBuild.cmake.in39
-rw-r--r--Tests/Contracts/VTK/CMakeLists.txt47
-rw-r--r--Tests/Contracts/VTK/Dashboard.cmake.in37
-rw-r--r--Tests/Contracts/VTK/RunTest.cmake3
-rw-r--r--Tests/Contracts/cse-snapshot/CMakeLists.txt114
-rw-r--r--Tests/Contracts/cse-snapshot/Dashboard.cmake.in76
-rw-r--r--Tests/Contracts/cse-snapshot/RunTest.cmake3
-rw-r--r--Tests/CrossCompile/CMakeLists.txt13
-rw-r--r--Tests/CrossCompile/main.c4
-rw-r--r--Tests/CustComDepend/CMakeLists.txt14
-rw-r--r--Tests/CustComDepend/bar.h9
-rw-r--r--Tests/CustComDepend/foo.cxx15
-rw-r--r--Tests/CustomCommand/CMakeLists.txt485
-rw-r--r--Tests/CustomCommand/GeneratedHeader/CMakeLists.txt13
-rw-r--r--Tests/CustomCommand/GeneratedHeader/generated.h.in1
-rw-r--r--Tests/CustomCommand/GeneratedHeader/main.cpp5
-rw-r--r--Tests/CustomCommand/GeneratorInExtraDir/CMakeLists.txt8
-rw-r--r--Tests/CustomCommand/check_command_line.c.in36
-rw-r--r--Tests/CustomCommand/check_mark.cmake5
-rw-r--r--Tests/CustomCommand/config.h.in1
-rw-r--r--Tests/CustomCommand/doc1.tex1
-rw-r--r--Tests/CustomCommand/foo.h.in1
-rw-r--r--Tests/CustomCommand/foo.in28
-rw-r--r--Tests/CustomCommand/gen_redirect_in.c5
-rw-r--r--Tests/CustomCommand/generator.cxx19
-rw-r--r--Tests/CustomCommand/main.cxx6
-rw-r--r--Tests/CustomCommand/source_in_custom_target.cpp0
-rw-r--r--Tests/CustomCommand/tcat.cxx11
-rw-r--r--Tests/CustomCommand/wrapped.h1
-rw-r--r--Tests/CustomCommand/wrapper.cxx36
-rw-r--r--Tests/CustomCommandWorkingDirectory/CMakeLists.txt42
-rw-r--r--Tests/CustomCommandWorkingDirectory/customTarget.c4
-rw-r--r--Tests/CustomCommandWorkingDirectory/working.c.in7
-rw-r--r--Tests/CxxDialect/CMakeLists.txt28
-rw-r--r--Tests/CxxDialect/use_constexpr.cxx10
-rw-r--r--Tests/CxxDialect/use_constexpr_and_typeof.cxx11
-rw-r--r--Tests/CxxDialect/use_typeof.cxx6
-rw-r--r--Tests/CxxOnly/CMakeLists.txt13
-rw-r--r--Tests/CxxOnly/cxxonly.cxx25
-rw-r--r--Tests/CxxOnly/libcxx1.cxx6
-rw-r--r--Tests/CxxOnly/libcxx1.h5
-rw-r--r--Tests/CxxOnly/libcxx2.cxx6
-rw-r--r--Tests/CxxOnly/libcxx2.h15
-rw-r--r--Tests/CxxOnly/test.CPP1
-rw-r--r--Tests/CxxOnly/testCxxModule.cxx6
-rw-r--r--Tests/Dependency/1/CMakeLists.txt3
-rw-r--r--Tests/Dependency/1/OneSrc.c3
-rw-r--r--Tests/Dependency/CMakeLists.txt53
-rw-r--r--Tests/Dependency/Case1/CMakeLists.txt19
-rw-r--r--Tests/Dependency/Case1/a.c5
-rw-r--r--Tests/Dependency/Case1/b.c6
-rw-r--r--Tests/Dependency/Case1/b2.c4
-rw-r--r--Tests/Dependency/Case1/c.c6
-rw-r--r--Tests/Dependency/Case1/c2.c6
-rw-r--r--Tests/Dependency/Case1/d.c7
-rw-r--r--Tests/Dependency/Case1/main.c10
-rw-r--r--Tests/Dependency/Case2/CMakeLists.txt22
-rw-r--r--Tests/Dependency/Case2/bar1.c4
-rw-r--r--Tests/Dependency/Case2/bar2.c2
-rw-r--r--Tests/Dependency/Case2/bar3.c2
-rw-r--r--Tests/Dependency/Case2/foo1.c2
-rw-r--r--Tests/Dependency/Case2/foo1b.c2
-rw-r--r--Tests/Dependency/Case2/foo1c.c2
-rw-r--r--Tests/Dependency/Case2/foo2.c2
-rw-r--r--Tests/Dependency/Case2/foo2b.c2
-rw-r--r--Tests/Dependency/Case2/foo2c.c2
-rw-r--r--Tests/Dependency/Case2/foo3.c2
-rw-r--r--Tests/Dependency/Case2/foo3b.c2
-rw-r--r--Tests/Dependency/Case2/foo3c.c1
-rw-r--r--Tests/Dependency/Case2/zot.c5
-rw-r--r--Tests/Dependency/Case3/CMakeLists.txt10
-rw-r--r--Tests/Dependency/Case3/bar.c5
-rw-r--r--Tests/Dependency/Case3/foo1.c2
-rw-r--r--Tests/Dependency/Case3/foo1b.c1
-rw-r--r--Tests/Dependency/Case3/foo2.c2
-rw-r--r--Tests/Dependency/Case4/CMakeLists.txt19
-rw-r--r--Tests/Dependency/Case4/bar.c2
-rw-r--r--Tests/Dependency/Case4/foo.c1
-rw-r--r--Tests/Dependency/Eight/CMakeLists.txt3
-rw-r--r--Tests/Dependency/Eight/EightSrc.c6
-rw-r--r--Tests/Dependency/Exec/CMakeLists.txt7
-rw-r--r--Tests/Dependency/Exec/ExecMain.c18
-rw-r--r--Tests/Dependency/Exec2/CMakeLists.txt12
-rw-r--r--Tests/Dependency/Exec2/ExecMain.c14
-rw-r--r--Tests/Dependency/Exec3/CMakeLists.txt6
-rw-r--r--Tests/Dependency/Exec3/ExecMain.c14
-rw-r--r--Tests/Dependency/Exec4/CMakeLists.txt6
-rw-r--r--Tests/Dependency/Exec4/ExecMain.c14
-rw-r--r--Tests/Dependency/Five/CMakeLists.txt3
-rw-r--r--Tests/Dependency/Five/FiveSrc.c6
-rw-r--r--Tests/Dependency/Four/CMakeLists.txt6
-rw-r--r--Tests/Dependency/Four/FourSrc.c15
-rw-r--r--Tests/Dependency/NoDepA/CMakeLists.txt1
-rw-r--r--Tests/Dependency/NoDepA/NoDepASrc.c3
-rw-r--r--Tests/Dependency/NoDepB/CMakeLists.txt3
-rw-r--r--Tests/Dependency/NoDepB/NoDepBSrc.c6
-rw-r--r--Tests/Dependency/NoDepC/CMakeLists.txt3
-rw-r--r--Tests/Dependency/NoDepC/NoDepCSrc.c6
-rw-r--r--Tests/Dependency/Seven/CMakeLists.txt3
-rw-r--r--Tests/Dependency/Seven/SevenSrc.c6
-rw-r--r--Tests/Dependency/Six/CMakeLists.txt12
-rw-r--r--Tests/Dependency/Six/SixASrc.c8
-rw-r--r--Tests/Dependency/Six/SixBSrc.c10
-rw-r--r--Tests/Dependency/Three/CMakeLists.txt3
-rw-r--r--Tests/Dependency/Three/ThreeSrc.c12
-rw-r--r--Tests/Dependency/Two/CMakeLists.txt20
-rw-r--r--Tests/Dependency/Two/TwoCustomSrc.c10
-rw-r--r--Tests/Dependency/Two/TwoSrc.c10
-rw-r--r--Tests/Dependency/Two/two-test.h.in1
-rw-r--r--Tests/DoubleProject/CMakeLists.txt3
-rw-r--r--Tests/DoubleProject/silly.c4
-rw-r--r--Tests/EmptyDepends/CMakeLists.txt15
-rw-r--r--Tests/EmptyLibrary/CMakeLists.txt4
-rw-r--r--Tests/EmptyLibrary/subdir/CMakeLists.txt1
-rw-r--r--Tests/EmptyLibrary/subdir/test.h1
-rw-r--r--Tests/EmptyProperty/CMakeLists.txt9
-rw-r--r--Tests/EmptyProperty/EmptyProperty.cxx1
-rw-r--r--Tests/EnforceConfig.cmake.in26
-rw-r--r--Tests/Environment/CMakeLists.txt26
-rw-r--r--Tests/Environment/main.cxx16
-rw-r--r--Tests/ExportImport/CMakeLists.txt82
-rw-r--r--Tests/ExportImport/Export/CMakeLists.txt510
-rw-r--r--Tests/ExportImport/Export/Interface/CMakeLists.txt58
-rw-r--r--Tests/ExportImport/Export/Interface/headeronly/headeronly.h7
-rw-r--r--Tests/ExportImport/Export/Interface/sharedlib.cpp7
-rw-r--r--Tests/ExportImport/Export/Interface/sharedlib/sharedlib.h7
-rw-r--r--Tests/ExportImport/Export/cmp0022.cpp7
-rw-r--r--Tests/ExportImport/Export/cmp0022.h4
-rw-r--r--Tests/ExportImport/Export/cmp0022_vs6_1.cpp1
-rw-r--r--Tests/ExportImport/Export/cmp0022_vs6_2.cpp1
-rw-r--r--Tests/ExportImport/Export/empty.cpp4
-rw-r--r--Tests/ExportImport/Export/renamed/CMakeLists.txt20
-rw-r--r--Tests/ExportImport/Export/renamed/renamed.cxx7
-rw-r--r--Tests/ExportImport/Export/renamed/renamed.h12
-rw-r--r--Tests/ExportImport/Export/sublib/CMakeLists.txt6
-rw-r--r--Tests/ExportImport/Export/sublib/subdir.cpp7
-rw-r--r--Tests/ExportImport/Export/sublib/subdir.h12
-rw-r--r--Tests/ExportImport/Export/systemlib.cpp7
-rw-r--r--Tests/ExportImport/Export/systemlib.h22
-rw-r--r--Tests/ExportImport/Export/testExe1.c26
-rw-r--r--Tests/ExportImport/Export/testExe1lib.c1
-rw-r--r--Tests/ExportImport/Export/testExe2.c12
-rw-r--r--Tests/ExportImport/Export/testExe2lib.c10
-rw-r--r--Tests/ExportImport/Export/testExe2libImp.c7
-rw-r--r--Tests/ExportImport/Export/testExe3.c24
-rw-r--r--Tests/ExportImport/Export/testLib1.c1
-rw-r--r--Tests/ExportImport/Export/testLib1file1.txt1
-rw-r--r--Tests/ExportImport/Export/testLib1file2.txt1
-rw-r--r--Tests/ExportImport/Export/testLib2.c4
-rw-r--r--Tests/ExportImport/Export/testLib3.c10
-rw-r--r--Tests/ExportImport/Export/testLib3Imp.c10
-rw-r--r--Tests/ExportImport/Export/testLib3ImpDep.c7
-rw-r--r--Tests/ExportImport/Export/testLib4.c7
-rw-r--r--Tests/ExportImport/Export/testLib4.h2
-rw-r--r--Tests/ExportImport/Export/testLib4lib.c4
-rw-r--r--Tests/ExportImport/Export/testLib4libdbg.c14
-rw-r--r--Tests/ExportImport/Export/testLib4libdbg1.c1
-rw-r--r--Tests/ExportImport/Export/testLib4libopt.c14
-rw-r--r--Tests/ExportImport/Export/testLib4libopt1.c1
-rw-r--r--Tests/ExportImport/Export/testLib5.c7
-rw-r--r--Tests/ExportImport/Export/testLib6.cxx6
-rw-r--r--Tests/ExportImport/Export/testLib6c.c5
-rw-r--r--Tests/ExportImport/Export/testLibCycleA1.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleA2.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleA3.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleB1.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleB2.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleB3.c1
-rw-r--r--Tests/ExportImport/Export/testLibDepends.c20
-rw-r--r--Tests/ExportImport/Export/testLibRequired.c1
-rw-r--r--Tests/ExportImport/Export/testSharedLibDepends.cpp9
-rw-r--r--Tests/ExportImport/Export/testSharedLibDepends.h15
-rw-r--r--Tests/ExportImport/Export/testSharedLibRequired.cpp7
-rw-r--r--Tests/ExportImport/Export/testSharedLibRequired.h12
-rw-r--r--Tests/ExportImport/Export/testSharedLibRequiredUser.cpp10
-rw-r--r--Tests/ExportImport/Export/testSharedLibRequiredUser.h12
-rw-r--r--Tests/ExportImport/Export/testSharedLibRequiredUser2.cpp8
-rw-r--r--Tests/ExportImport/Export/testSharedLibRequiredUser2.h14
-rw-r--r--Tests/ExportImport/Import/A/CMakeLists.txt320
-rw-r--r--Tests/ExportImport/Import/A/check_testLib1_genex.cmake11
-rw-r--r--Tests/ExportImport/Import/A/cmp0022NEW_test.cpp12
-rw-r--r--Tests/ExportImport/Import/A/cmp0022NEW_test_vs6_1.cpp1
-rw-r--r--Tests/ExportImport/Import/A/cmp0022NEW_test_vs6_2.cpp1
-rw-r--r--Tests/ExportImport/Import/A/cmp0022OLD_test.cpp12
-rw-r--r--Tests/ExportImport/Import/A/cmp0022OLD_test_vs6_1.cpp1
-rw-r--r--Tests/ExportImport/Import/A/cmp0022OLD_test_vs6_2.cpp1
-rw-r--r--Tests/ExportImport/Import/A/deps_iface.c34
-rw-r--r--Tests/ExportImport/Import/A/deps_shared_iface.cpp49
-rw-r--r--Tests/ExportImport/Import/A/excludedFromAll/CMakeLists.txt7
-rw-r--r--Tests/ExportImport/Import/A/excludedFromAll/excludedFromAll.cpp7
-rw-r--r--Tests/ExportImport/Import/A/excludedFromAll/excludedFromAll.h4
-rw-r--r--Tests/ExportImport/Import/A/framework_interface/CMakeLists.txt9
-rw-r--r--Tests/ExportImport/Import/A/framework_interface/framework_test.cpp6
-rw-r--r--Tests/ExportImport/Import/A/iface_test.cpp11
-rw-r--r--Tests/ExportImport/Import/A/imp_lib1.c6
-rw-r--r--Tests/ExportImport/Import/A/imp_mod1.c13
-rw-r--r--Tests/ExportImport/Import/A/imp_testExe1.c25
-rw-r--r--Tests/ExportImport/Import/A/renamed_test.cpp8
-rw-r--r--Tests/ExportImport/Import/A/test_system.cpp9
-rw-r--r--Tests/ExportImport/Import/CMakeLists.txt25
-rw-r--r--Tests/ExportImport/Import/Interface/CMakeLists.txt93
-rw-r--r--Tests/ExportImport/Import/Interface/headeronlytest.cpp17
-rw-r--r--Tests/ExportImport/Import/Interface/interfacetest.cpp20
-rw-r--r--Tests/ExportImport/Import/imp_testTransExe1.c6
-rw-r--r--Tests/ExportImport/Import/try_compile/CMakeLists.txt36
-rw-r--r--Tests/ExportImport/InitialCache.cmake.in16
-rw-r--r--Tests/ExportImport/main.c4
-rw-r--r--Tests/ExternalOBJ/CMakeLists.txt63
-rw-r--r--Tests/ExternalOBJ/Object/CMakeLists.txt13
-rw-r--r--Tests/ExternalOBJ/Object/external_main.cxx4
-rw-r--r--Tests/ExternalOBJ/Object/external_object.cxx4
-rw-r--r--Tests/ExternalOBJ/Sub/CMakeLists.txt3
-rw-r--r--Tests/ExternalOBJ/executable.cxx5
-rw-r--r--Tests/ExternalProject/CMakeLists.txt487
-rw-r--r--Tests/ExternalProject/Example/CMakeLists.txt11
-rw-r--r--Tests/ExternalProject/cvsrepo.tgzbin0 -> 1317 bytes
-rw-r--r--Tests/ExternalProject/gitrepo.tgzbin0 -> 1934 bytes
-rw-r--r--Tests/ExternalProject/hgrepo.tgzbin0 -> 2011 bytes
-rw-r--r--Tests/ExternalProject/svnrepo.tgzbin0 -> 3673 bytes
-rw-r--r--Tests/ExternalProjectLocal/CMakeLists.txt229
-rw-r--r--Tests/ExternalProjectLocal/Step1.tarbin0 -> 5632 bytes
-rw-r--r--Tests/ExternalProjectLocal/Step1.tar.bz2bin0 -> 904 bytes
-rw-r--r--Tests/ExternalProjectLocal/Step1.tgzbin0 -> 791 bytes
-rw-r--r--Tests/ExternalProjectLocal/Step1.zipbin0 -> 1074 bytes
-rw-r--r--Tests/ExternalProjectLocal/Step1NoDir.tarbin0 -> 5120 bytes
-rw-r--r--Tests/ExternalProjectLocal/Step1NoDir.tar.bz2bin0 -> 852 bytes
-rw-r--r--Tests/ExternalProjectLocal/Step1NoDir.tgzbin0 -> 770 bytes
-rw-r--r--Tests/ExternalProjectLocal/Step1NoDir.zipbin0 -> 1038 bytes
-rw-r--r--Tests/ExternalProjectLocal/Step1Patch.cmake25
-rw-r--r--Tests/ExternalProjectUpdate/CMakeLists.txt94
-rw-r--r--Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake95
-rw-r--r--Tests/ExternalProjectUpdate/gitrepo.tgzbin0 -> 3057 bytes
-rw-r--r--Tests/FindGTK2/CMakeLists.txt317
-rw-r--r--Tests/FindGTK2/atk/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/atk/main.c7
-rw-r--r--Tests/FindGTK2/atkmm/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/atkmm/main.cpp8
-rw-r--r--Tests/FindGTK2/cairo/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/cairo/main.c52
-rw-r--r--Tests/FindGTK2/cairomm/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/cairomm/main.cpp62
-rw-r--r--Tests/FindGTK2/gdk/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/gdk/main.c7
-rw-r--r--Tests/FindGTK2/gdk_pixbuf/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/gdk_pixbuf/main.c10
-rw-r--r--Tests/FindGTK2/gdkmm/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/gdkmm/main.cpp7
-rw-r--r--Tests/FindGTK2/gio/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/gio/main.c8
-rw-r--r--Tests/FindGTK2/giomm/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/giomm/main.cpp7
-rw-r--r--Tests/FindGTK2/glib/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/glib/main.c11
-rw-r--r--Tests/FindGTK2/glibmm/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/glibmm/main.cpp7
-rw-r--r--Tests/FindGTK2/gmodule/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/gmodule/main.c7
-rw-r--r--Tests/FindGTK2/gobject/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/gobject/main.c72
-rw-r--r--Tests/FindGTK2/gthread/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/gthread/main.c7
-rw-r--r--Tests/FindGTK2/gtk/CMakeLists.txt14
-rw-r--r--Tests/FindGTK2/gtk/main.c15
-rw-r--r--Tests/FindGTK2/gtkmm/CMakeLists.txt14
-rw-r--r--Tests/FindGTK2/gtkmm/helloworld.cpp29
-rw-r--r--Tests/FindGTK2/gtkmm/helloworld.h20
-rw-r--r--Tests/FindGTK2/gtkmm/main.cpp13
-rw-r--r--Tests/FindGTK2/pango/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/pango/main.c7
-rw-r--r--Tests/FindGTK2/pangocairo/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/pangocairo/main.c72
-rw-r--r--Tests/FindGTK2/pangoft2/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/pangoft2/main.c8
-rw-r--r--Tests/FindGTK2/pangomm/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/pangomm/main.cpp8
-rw-r--r--Tests/FindGTK2/pangoxft/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/pangoxft/main.c7
-rw-r--r--Tests/FindGTK2/sigc++/CMakeLists.txt10
-rw-r--r--Tests/FindGTK2/sigc++/main.cpp30
-rw-r--r--Tests/FindModulesExecuteAll/CMakeLists.txt30
-rw-r--r--Tests/FindModulesExecuteAll/main.c4
-rw-r--r--Tests/FindPackageModeMakefileTest/CMakeLists.txt39
-rw-r--r--Tests/FindPackageModeMakefileTest/FindFoo.cmake.in9
-rw-r--r--Tests/FindPackageModeMakefileTest/Makefile.in31
-rw-r--r--Tests/FindPackageModeMakefileTest/foo.cpp4
-rw-r--r--Tests/FindPackageModeMakefileTest/foo.h6
-rw-r--r--Tests/FindPackageModeMakefileTest/main.cpp8
-rw-r--r--Tests/FindPackageTest/A/wibble-config.cmake1
-rw-r--r--Tests/FindPackageTest/B/wibble-config.cmake1
-rw-r--r--Tests/FindPackageTest/Baz 1.1/BazConfig.cmake1
-rw-r--r--Tests/FindPackageTest/Baz 1.1/BazConfigVersion.cmake8
-rw-r--r--Tests/FindPackageTest/Baz 1.2/CMake/BazConfig.cmake1
-rw-r--r--Tests/FindPackageTest/Baz 1.2/CMake/BazConfigVersion.cmake8
-rw-r--r--Tests/FindPackageTest/CMakeLists.txt618
-rw-r--r--Tests/FindPackageTest/Exporter/CMakeLists.txt12
-rw-r--r--Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfig.cmake.in1
-rw-r--r--Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfigVersion.cmake.in6
-rw-r--r--Tests/FindPackageTest/Exporter/dummy.c1
-rw-r--r--Tests/FindPackageTest/FindLotsOfComponents.cmake10
-rw-r--r--Tests/FindPackageTest/FindPackageHandleStandardArgs.cmake1
-rw-r--r--Tests/FindPackageTest/FindPackageTest.cxx4
-rw-r--r--Tests/FindPackageTest/FindRecursiveA.cmake1
-rw-r--r--Tests/FindPackageTest/FindRecursiveB.cmake1
-rw-r--r--Tests/FindPackageTest/FindRecursiveC.cmake1
-rw-r--r--Tests/FindPackageTest/FindSomePackage.cmake6
-rw-r--r--Tests/FindPackageTest/FindUpperCasePackage.cmake6
-rw-r--r--Tests/FindPackageTest/FindVersionTestA.cmake18
-rw-r--r--Tests/FindPackageTest/FindVersionTestB.cmake18
-rw-r--r--Tests/FindPackageTest/FindVersionTestC.cmake18
-rw-r--r--Tests/FindPackageTest/FindVersionTestD.cmake18
-rw-r--r--Tests/FindPackageTest/RelocatableConfig.cmake.in11
-rw-r--r--Tests/FindPackageTest/SystemPackage/CMakeTestSystemPackageConfig.cmake1
-rw-r--r--Tests/FindPackageTest/TApp.app/Contents/Resources/TAppConfig.cmake1
-rw-r--r--Tests/FindPackageTest/TApp.app/Contents/Resources/cmake/tapp-config.cmake1
-rw-r--r--Tests/FindPackageTest/TFramework.framework/Versions/A/Resources/CMake/TFrameworkConfig.cmake1
-rw-r--r--Tests/FindPackageTest/TFramework.framework/Versions/A/Resources/tframework-config.cmake1
-rw-r--r--Tests/FindPackageTest/cmake/SetFoundFALSEConfig.cmake1
-rw-r--r--Tests/FindPackageTest/cmake/SetFoundTRUEConfig.cmake1
-rw-r--r--Tests/FindPackageTest/include/foo.h1
-rw-r--r--Tests/FindPackageTest/lib/Bar/BarConfig.cmake1
-rw-r--r--Tests/FindPackageTest/lib/Bar/cmake/bar-config.cmake1
-rw-r--r--Tests/FindPackageTest/lib/Blub/BlubConfig.cmake1
-rw-r--r--Tests/FindPackageTest/lib/RecursiveA/recursivea-config.cmake4
-rw-r--r--Tests/FindPackageTest/lib/TApp/TAppConfig.cmake2
-rw-r--r--Tests/FindPackageTest/lib/arch/Bar/BarConfig.cmake1
-rw-r--r--Tests/FindPackageTest/lib/arch/cmake/zot-4.0/zot-config-version.cmake7
-rw-r--r--Tests/FindPackageTest/lib/arch/cmake/zot-4.0/zot-config.cmake1
-rw-r--r--Tests/FindPackageTest/lib/arch/foo-1.2/CMake/FooConfig.cmake1
-rw-r--r--Tests/FindPackageTest/lib/arch/zot-3.1/zot-config-version.cmake7
-rw-r--r--Tests/FindPackageTest/lib/arch/zot-3.1/zot-config.cmake1
-rw-r--r--Tests/FindPackageTest/lib/cmake/zot-3.1/zot-config-version.cmake4
-rw-r--r--Tests/FindPackageTest/lib/cmake/zot-3.1/zot-config.cmake2
-rw-r--r--Tests/FindPackageTest/lib/cmake/zot-4.0/zot-config-version.cmake8
-rw-r--r--Tests/FindPackageTest/lib/cmake/zot-4.0/zot-config.cmake1
-rw-r--r--Tests/FindPackageTest/lib/foo-1.2/CMake/FooConfig.cmake1
-rw-r--r--Tests/FindPackageTest/lib/foo-1.2/foo-config.cmake1
-rw-r--r--Tests/FindPackageTest/lib/suffix/test/SuffixTestConfig.cmake1
-rw-r--r--Tests/FindPackageTest/lib/suffix/test/SuffixTestConfigVersion.cmake7
-rw-r--r--Tests/FindPackageTest/lib/zot-1.0/zot-config.cmake1
-rw-r--r--Tests/FindPackageTest/lib/zot-2.0/zot-config-version.cmake5
-rw-r--r--Tests/FindPackageTest/lib/zot-2.0/zot-config.cmake1
-rw-r--r--Tests/FindPackageTest/lib/zot-3.0/zot-config-version.cmake5
-rw-r--r--Tests/FindPackageTest/lib/zot-3.0/zot-config.cmake1
-rw-r--r--Tests/FindPackageTest/lib/zot-3.1/zot-config-version.cmake8
-rw-r--r--Tests/FindPackageTest/lib/zot-3.1/zot-config.cmake1
-rw-r--r--Tests/FindPackageTest/lib/zot/zot-config-version.cmake10
-rw-r--r--Tests/FindPackageTest/lib/zot/zot-config.cmake2
-rw-r--r--Tests/ForceInclude/CMakeLists.txt10
-rw-r--r--Tests/ForceInclude/foo.c7
-rw-r--r--Tests/ForceInclude/foo1.h1
-rw-r--r--Tests/ForceInclude/foo2.h1
-rw-r--r--Tests/Fortran/CMakeLists.txt227
-rw-r--r--Tests/Fortran/Executable/CMakeLists.txt8
-rw-r--r--Tests/Fortran/Executable/main.f906
-rw-r--r--Tests/Fortran/External/CMakeLists.txt4
-rw-r--r--Tests/Fortran/External/a.f907
-rw-r--r--Tests/Fortran/Library/CMakeLists.txt11
-rw-r--r--Tests/Fortran/Library/a.f903
-rw-r--r--Tests/Fortran/Library/b.f902
-rw-r--r--Tests/Fortran/Library/main.f903
-rw-r--r--Tests/Fortran/foo.f9
-rw-r--r--Tests/Fortran/hello.f6
-rw-r--r--Tests/Fortran/in_interface/main.f903
-rw-r--r--Tests/Fortran/in_interface/module.f9012
-rw-r--r--Tests/Fortran/include/test_preprocess.h5
-rw-r--r--Tests/Fortran/mainc.c5
-rw-r--r--Tests/Fortran/maincxx.c6
-rw-r--r--Tests/Fortran/myc.c12
-rw-r--r--Tests/Fortran/mycxx.cxx6
-rw-r--r--Tests/Fortran/mysub.f5
-rw-r--r--Tests/Fortran/test_module_implementation.f906
-rw-r--r--Tests/Fortran/test_module_interface.f909
-rw-r--r--Tests/Fortran/test_module_main.f904
-rw-r--r--Tests/Fortran/test_preprocess.F9051
-rw-r--r--Tests/Fortran/test_use_in_comment_fixedform.f7
-rw-r--r--Tests/Fortran/test_use_in_comment_freeform.f907
-rw-r--r--Tests/Fortran/testf.f7
-rw-r--r--Tests/Fortran/world.f6
-rw-r--r--Tests/Fortran/world_gnu.def2
-rw-r--r--Tests/Fortran/world_icl.def2
-rw-r--r--Tests/FortranC/CMakeLists.txt25
-rw-r--r--Tests/FortranC/Flags.cmake.in30
-rwxr-xr-xTests/FortranC/test_opt.sh.in18
-rw-r--r--Tests/FortranOnly/CMakeLists.txt68
-rw-r--r--Tests/FortranOnly/checksayhello.cmake7
-rw-r--r--Tests/FortranOnly/checktestf2.cmake8
-rw-r--r--Tests/FortranOnly/hello.f5
-rw-r--r--Tests/FortranOnly/testf.f6
-rw-r--r--Tests/FortranOnly/world.f4
-rw-r--r--Tests/Framework/CMakeLists.txt80
-rw-r--r--Tests/Framework/bar.cxx6
-rw-r--r--Tests/Framework/foo.cxx10
-rw-r--r--Tests/Framework/foo.h1
-rw-r--r--Tests/Framework/foo2.h1
-rw-r--r--Tests/Framework/fooBoth.h1
-rw-r--r--Tests/Framework/fooDeepPublic.h1
-rw-r--r--Tests/Framework/fooExtensionlessResource1
-rw-r--r--Tests/Framework/fooNeither.h1
-rw-r--r--Tests/Framework/fooPrivate.h1
-rw-r--r--Tests/Framework/fooPrivateExtensionlessHeader1
-rw-r--r--Tests/Framework/fooPublic.h1
-rw-r--r--Tests/Framework/fooPublicExtensionlessHeader1
-rw-r--r--Tests/Framework/test.lua1
-rw-r--r--Tests/FunctionTest/CMakeLists.txt176
-rw-r--r--Tests/FunctionTest/SubDirScope/CMakeLists.txt14
-rw-r--r--Tests/FunctionTest/Util.cmake3
-rw-r--r--Tests/FunctionTest/functionTest.c7
-rw-r--r--Tests/GeneratorExpression/CMP0044/CMakeLists.txt19
-rw-r--r--Tests/GeneratorExpression/CMP0044/cmp0044-check.cpp26
-rw-r--r--Tests/GeneratorExpression/CMakeLists.txt260
-rw-r--r--Tests/GeneratorExpression/check-common.cmake5
-rw-r--r--Tests/GeneratorExpression/check-part1.cmake59
-rw-r--r--Tests/GeneratorExpression/check-part2.cmake46
-rw-r--r--Tests/GeneratorExpression/check-part3.cmake62
-rw-r--r--Tests/GeneratorExpression/echo.c8
-rw-r--r--Tests/GeneratorExpression/empty.cpp4
-rw-r--r--Tests/GeneratorExpression/pwd.c34
-rw-r--r--Tests/IPO/CMakeLists.txt7
-rw-r--r--Tests/IncludeDirectories/CMP0021/CMakeLists.txt14
-rw-r--r--Tests/IncludeDirectories/CMP0021/includes/cmp0021/cmp0021.h2
-rw-r--r--Tests/IncludeDirectories/CMP0021/main.cpp11
-rw-r--r--Tests/IncludeDirectories/CMakeLists.txt92
-rw-r--r--Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt51
-rw-r--r--Tests/IncludeDirectories/SystemIncludeDirectories/consumer.cpp7
-rw-r--r--Tests/IncludeDirectories/SystemIncludeDirectories/imported_consumer.cpp7
-rw-r--r--Tests/IncludeDirectories/SystemIncludeDirectories/systemlib.cpp4
-rw-r--r--Tests/IncludeDirectories/SystemIncludeDirectories/systemlib/systemlib.h19
-rw-r--r--Tests/IncludeDirectories/SystemIncludeDirectories/systemlib_header_only/systemlib.h16
-rw-r--r--Tests/IncludeDirectories/SystemIncludeDirectories/upstream.cpp4
-rw-r--r--Tests/IncludeDirectories/SystemIncludeDirectories/upstream.h12
-rw-r--r--Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt170
-rw-r--r--Tests/IncludeDirectories/TargetIncludeDirectories/copy_includes.cpp7
-rw-r--r--Tests/IncludeDirectories/TargetIncludeDirectories/empty.cpp7
-rw-r--r--Tests/IncludeDirectories/TargetIncludeDirectories/main.c7
-rw-r--r--Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp19
-rw-r--r--Tests/IncludeDirectories/TargetIncludeDirectories/other.cpp6
-rw-r--r--Tests/IncludeDirectories/TargetIncludeDirectories/sing/ting/ting.h1
-rw-r--r--Tests/IncludeDirectories/empty.cpp4
-rw-r--r--Tests/IncludeDirectories/main.cpp9
-rw-r--r--Tests/InterfaceLibrary/CMakeLists.txt58
-rw-r--r--Tests/InterfaceLibrary/broken.cpp2
-rw-r--r--Tests/InterfaceLibrary/definetestexe.cpp24
-rw-r--r--Tests/InterfaceLibrary/dummy.cpp5
-rw-r--r--Tests/InterfaceLibrary/headerdir/CMakeLists.txt8
-rw-r--r--Tests/InterfaceLibrary/headerdir/iface_header.h1
-rw-r--r--Tests/InterfaceLibrary/ifacedir/CMakeLists.txt8
-rw-r--r--Tests/InterfaceLibrary/ifacedir/sub.cpp1
-rw-r--r--Tests/InterfaceLibrary/libsdir/CMakeLists.txt28
-rw-r--r--Tests/InterfaceLibrary/libsdir/shareddependlib.cpp7
-rw-r--r--Tests/InterfaceLibrary/libsdir/shareddependlib/shareddependlib.h12
-rw-r--r--Tests/InterfaceLibrary/libsdir/sharedlib.cpp12
-rw-r--r--Tests/InterfaceLibrary/libsdir/sharedlib/sharedlib.h15
-rw-r--r--Tests/InterfaceLibrary/map_config.cpp15
-rw-r--r--Tests/InterfaceLibrary/obj.cpp1
-rw-r--r--Tests/InterfaceLibrary/sharedlibtestexe.cpp19
-rw-r--r--Tests/InterfaceLinkLibraries/CMakeLists.txt61
-rw-r--r--Tests/InterfaceLinkLibraries/bang.cpp15
-rw-r--r--Tests/InterfaceLinkLibraries/bang.h4
-rw-r--r--Tests/InterfaceLinkLibraries/bang_vs6_1.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/bang_vs6_2.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/bar.cpp26
-rw-r--r--Tests/InterfaceLinkLibraries/bar.h7
-rw-r--r--Tests/InterfaceLinkLibraries/bar_vs6_1.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/bar_vs6_2.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/bar_vs6_3.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/bar_vs6_4.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/foo.cpp15
-rw-r--r--Tests/InterfaceLinkLibraries/foo.h4
-rw-r--r--Tests/InterfaceLinkLibraries/foo_vs6_1.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/foo_vs6_2.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/foo_vs6_3.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/foo_vs6_4.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/main.cpp23
-rw-r--r--Tests/InterfaceLinkLibraries/main_vs6_1.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/main_vs6_2.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/main_vs6_3.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/main_vs6_4.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/zot.cpp6
-rw-r--r--Tests/InterfaceLinkLibraries/zot.h7
-rw-r--r--Tests/InterfaceLinkLibraries/zot_vs6_1.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/zot_vs6_2.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/zot_vs6_3.cpp1
-rw-r--r--Tests/InterfaceLinkLibraries/zot_vs6_4.cpp1
-rw-r--r--Tests/JCTest/CMakeLists.txt9
-rw-r--r--Tests/JCTest/TestTime.cxx12
-rw-r--r--Tests/JacocoCoverage/Coverage/src/main/java/org/cmake/CoverageTest.java52
-rw-r--r--Tests/JacocoCoverage/Coverage/target/site/jacoco.xml1
-rw-r--r--Tests/JacocoCoverage/DartConfiguration.tcl.in8
-rw-r--r--Tests/Java/A.java11
-rw-r--r--Tests/Java/CMakeLists.txt9
-rw-r--r--Tests/Java/HelloWorld.java11
-rw-r--r--Tests/Jump/CMakeLists.txt6
-rw-r--r--Tests/Jump/Executable/CMakeLists.txt6
-rw-r--r--Tests/Jump/Executable/jumpExecutable.cxx12
-rw-r--r--Tests/Jump/Library/CMakeLists.txt2
-rw-r--r--Tests/Jump/Library/Shared/CMakeLists.txt26
-rw-r--r--Tests/Jump/Library/Shared/jumpShared.cxx7
-rw-r--r--Tests/Jump/Library/Static/CMakeLists.txt1
-rw-r--r--Tests/Jump/Library/Static/jumpStatic.cxx1
-rw-r--r--Tests/LibName/CMakeLists.txt26
-rw-r--r--Tests/LibName/bar.c7
-rw-r--r--Tests/LibName/foo.c11
-rw-r--r--Tests/LibName/foobar.c10
-rw-r--r--Tests/LinkDirectory/CMakeLists.txt45
-rw-r--r--Tests/LinkDirectory/External/CMakeLists.txt14
-rw-r--r--Tests/LinkDirectory/External/myexe.c3
-rw-r--r--Tests/LinkDirectory/mylibA.c1
-rw-r--r--Tests/LinkDirectory/mylibB.c1
-rw-r--r--Tests/LinkFlags/CMakeLists.txt37
-rw-r--r--Tests/LinkFlags/LinkFlags.c1
-rw-r--r--Tests/LinkFlags/LinkFlagsExe.c6
-rw-r--r--Tests/LinkFlags/LinkFlagsLib.c6
-rw-r--r--Tests/LinkFlags/LinkerFlags/CMakeLists.txt11
-rw-r--r--Tests/LinkFlags/LinkerFlagsConfig/CMakeLists.txt11
-rw-r--r--Tests/LinkLanguage/CMakeLists.txt15
-rw-r--r--Tests/LinkLanguage/LinkLanguage.c6
-rw-r--r--Tests/LinkLanguage/foo.cxx6
-rw-r--r--Tests/LinkLine/CMakeLists.txt12
-rw-r--r--Tests/LinkLine/Exec.c9
-rw-r--r--Tests/LinkLine/One.c10
-rw-r--r--Tests/LinkLine/Two.c10
-rw-r--r--Tests/LinkLineOrder/CMakeLists.txt36
-rw-r--r--Tests/LinkLineOrder/Exec1.c8
-rw-r--r--Tests/LinkLineOrder/Exec2.c8
-rw-r--r--Tests/LinkLineOrder/NoDepA.c7
-rw-r--r--Tests/LinkLineOrder/NoDepB.c4
-rw-r--r--Tests/LinkLineOrder/NoDepC.c7
-rw-r--r--Tests/LinkLineOrder/NoDepE.c11
-rw-r--r--Tests/LinkLineOrder/NoDepF.c11
-rw-r--r--Tests/LinkLineOrder/NoDepX.c7
-rw-r--r--Tests/LinkLineOrder/NoDepY.c4
-rw-r--r--Tests/LinkLineOrder/NoDepZ.c7
-rw-r--r--Tests/LinkLineOrder/One.c10
-rw-r--r--Tests/LinkLineOrder/Two.c8
-rw-r--r--Tests/LinkStatic/CMakeLists.txt27
-rw-r--r--Tests/LinkStatic/LinkStatic.c5
-rw-r--r--Tests/LoadCommand/CMakeCommands/CMakeLists.txt14
-rw-r--r--Tests/LoadCommand/CMakeCommands/cmTestCommand.c219
-rw-r--r--Tests/LoadCommand/CMakeLists.txt59
-rw-r--r--Tests/LoadCommand/LoadedCommand.cxx.in32
-rw-r--r--Tests/LoadCommand/LoadedCommand.h.in3
-rw-r--r--Tests/LoadCommandOneConfig/CMakeCommands/CMakeLists.txt17
-rw-r--r--Tests/LoadCommandOneConfig/CMakeCommands/cmTestCommand.c219
-rw-r--r--Tests/LoadCommandOneConfig/CMakeLists.txt65
-rw-r--r--Tests/LoadCommandOneConfig/LoadedCommand.cxx.in32
-rw-r--r--Tests/LoadCommandOneConfig/LoadedCommand.h.in9
-rw-r--r--Tests/MFC/CMakeLists.txt61
-rw-r--r--Tests/MFC/CMakeLists.txt.in62
-rw-r--r--Tests/MFC/ValidateBuild.cmake.in68
-rw-r--r--Tests/MFC/mfc1/.gitattributes6
-rw-r--r--Tests/MFC/mfc1/ChildFrm.cpp59
-rw-r--r--Tests/MFC/mfc1/ChildFrm.h34
-rw-r--r--Tests/MFC/mfc1/MainFrm.cpp98
-rw-r--r--Tests/MFC/mfc1/MainFrm.h38
-rw-r--r--Tests/MFC/mfc1/ReadMe.txt135
-rw-r--r--Tests/MFC/mfc1/Resource.h20
-rw-r--r--Tests/MFC/mfc1/mfc1.cpp144
-rw-r--r--Tests/MFC/mfc1/mfc1.h31
-rw-r--r--Tests/MFC/mfc1/mfc1.rc393
-rw-r--r--Tests/MFC/mfc1/mfc1.reg13
-rw-r--r--Tests/MFC/mfc1/mfc1.sln21
-rw-r--r--Tests/MFC/mfc1/mfc1.vcproj216
-rw-r--r--Tests/MFC/mfc1/mfc1Doc.cpp78
-rw-r--r--Tests/MFC/mfc1/mfc1Doc.h37
-rw-r--r--Tests/MFC/mfc1/mfc1View.cpp99
-rw-r--r--Tests/MFC/mfc1/mfc1View.h48
-rw-r--r--Tests/MFC/mfc1/res/Toolbar.bmpbin0 -> 1078 bytes
-rw-r--r--Tests/MFC/mfc1/res/mfc1.icobin0 -> 21630 bytes
-rw-r--r--Tests/MFC/mfc1/res/mfc1.manifest22
-rw-r--r--Tests/MFC/mfc1/res/mfc1.rc213
-rw-r--r--Tests/MFC/mfc1/res/mfc1Doc.icobin0 -> 1078 bytes
-rw-r--r--Tests/MFC/mfc1/stdafx.cpp5
-rw-r--r--Tests/MFC/mfc1/stdafx.h56
-rw-r--r--Tests/MFC/try_compile/CMakeLists.txt15
-rw-r--r--Tests/MacRuntimePath/A/CMakeLists.txt70
-rw-r--r--Tests/MacRuntimePath/A/framework.cpp8
-rw-r--r--Tests/MacRuntimePath/A/framework.h17
-rw-r--r--Tests/MacRuntimePath/A/framework2.cpp8
-rw-r--r--Tests/MacRuntimePath/A/framework2.h17
-rw-r--r--Tests/MacRuntimePath/A/shared.cpp8
-rw-r--r--Tests/MacRuntimePath/A/shared.h17
-rw-r--r--Tests/MacRuntimePath/A/test1.cpp8
-rw-r--r--Tests/MacRuntimePath/A/test2.cpp8
-rw-r--r--Tests/MacRuntimePath/A/test3.cpp8
-rw-r--r--Tests/MacRuntimePath/B/CMakeLists.txt18
-rw-r--r--Tests/MacRuntimePath/CMakeLists.txt74
-rw-r--r--Tests/MacRuntimePath/InitialCache.cmake.in14
-rw-r--r--Tests/MacroTest/CMakeLists.txt91
-rw-r--r--Tests/MacroTest/context.cmake10
-rw-r--r--Tests/MacroTest/macroTest.c7
-rw-r--r--Tests/MakeClean/CMakeLists.txt50
-rw-r--r--Tests/MakeClean/ToClean/CMakeLists.txt42
-rw-r--r--Tests/MakeClean/ToClean/ToCleanFiles.cmake.in1
-rw-r--r--Tests/MakeClean/ToClean/toclean.cxx4
-rw-r--r--Tests/MakeClean/check_clean.c.in26
-rw-r--r--Tests/MathTest/CMakeLists.txt29
-rw-r--r--Tests/MathTest/MathTestExec.cxx26
-rw-r--r--Tests/MathTest/MathTestTests.h.in1
-rw-r--r--Tests/MissingInstall/CMakeLists.txt25
-rw-r--r--Tests/MissingInstall/ExpectInstallFail.cmake18
-rw-r--r--Tests/MissingInstall/mybin.cpp1
-rw-r--r--Tests/MissingSourceFile/CMakeLists.txt3
-rw-r--r--Tests/Module/CheckTypeSize/CMakeLists.txt37
-rw-r--r--Tests/Module/CheckTypeSize/CheckTypeSize.c160
-rw-r--r--Tests/Module/CheckTypeSize/CheckTypeSize.cxx172
-rw-r--r--Tests/Module/CheckTypeSize/config.h.in51
-rw-r--r--Tests/Module/CheckTypeSize/config.hxx.in23
-rw-r--r--Tests/Module/CheckTypeSize/someclass.hxx14
-rw-r--r--Tests/Module/CheckTypeSize/somestruct.h10
-rw-r--r--Tests/Module/ExternalData/CMakeLists.txt47
-rw-r--r--Tests/Module/ExternalData/Data Space.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data1Check.cmake90
-rw-r--r--Tests/Module/ExternalData/Data2.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data2/CMakeLists.txt11
-rw-r--r--Tests/Module/ExternalData/Data2/Data2Check.cmake12
-rw-r--r--Tests/Module/ExternalData/Data2/SeriesC_1_.my.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data2/SeriesC_2_.my.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data2/SeriesC_3_.my.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data2b.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data3/CMakeLists.txt14
-rw-r--r--Tests/Module/ExternalData/Data3/Data.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data3/Data3Check.cmake25
-rw-r--r--Tests/Module/ExternalData/Data3/Other.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data4/CMakeLists.txt15
-rw-r--r--Tests/Module/ExternalData/Data4/Data.dat.md51
-rw-r--r--Tests/Module/ExternalData/Data4/Data4Check.cmake26
-rw-r--r--Tests/Module/ExternalData/Data4/Other.dat.md51
-rw-r--r--Tests/Module/ExternalData/Directory/A.dat.md51
-rw-r--r--Tests/Module/ExternalData/Directory/B.dat.md51
-rw-r--r--Tests/Module/ExternalData/Directory/C.dat.md51
-rw-r--r--Tests/Module/ExternalData/MD5/.gitattributes1
-rw-r--r--Tests/Module/ExternalData/MD5/08cfcf221f76ace7b906b312284e73d71
-rw-r--r--Tests/Module/ExternalData/MD5/30ba0acdee9096b3b9fc6c69362c6b421
-rw-r--r--Tests/Module/ExternalData/MD5/31eff09e84fca01415f8cd9d82ec432b1
-rw-r--r--Tests/Module/ExternalData/MD5/401767f22a456b3522953722090a2c361
-rw-r--r--Tests/Module/ExternalData/MD5/8c018830e3efa5caf3c7415028335a571
-rw-r--r--Tests/Module/ExternalData/MD5/8f4add4581551facf27237e6577fd6621
-rw-r--r--Tests/Module/ExternalData/MD5/9d980b06c2f0fec3d4872d68175b98221
-rw-r--r--Tests/Module/ExternalData/MD5/aaad162b85f60d1eb57ca71a23e8efd71
-rw-r--r--Tests/Module/ExternalData/MD5/c1030719c95f3435d8abc39c0d4429461
-rw-r--r--Tests/Module/ExternalData/MD5/ce38ea6c3c1e00fa6405dd64b8bf6da01
-rw-r--r--Tests/Module/ExternalData/MD5/ecfa1ecd417d4253af81ae04d1bd65811
-rw-r--r--Tests/Module/ExternalData/MD5/f41c94425d01ecbbee70440b951cb0581
-rw-r--r--Tests/Module/ExternalData/MD5/f7ab5a04aae9cb9a520e70b20b9c8ed71
-rw-r--r--Tests/Module/ExternalData/MetaA.dat.md51
-rw-r--r--Tests/Module/ExternalData/MetaB.dat.md51
-rw-r--r--Tests/Module/ExternalData/MetaC.dat.md51
-rw-r--r--Tests/Module/ExternalData/MetaTop.dat.md51
-rw-r--r--Tests/Module/ExternalData/PairedA.dat.md51
-rw-r--r--Tests/Module/ExternalData/PairedB.dat.md51
-rw-r--r--Tests/Module/ExternalData/SHA1/.gitattributes1
-rw-r--r--Tests/Module/ExternalData/SHA1/2af59a7022024974f3b8521b7ed8137c996a79f11
-rw-r--r--Tests/Module/ExternalData/SHA224/.gitattributes1
-rw-r--r--Tests/Module/ExternalData/SHA224/3b679da7908562fe1cc28db47ffb89bae025f4551dceb343a58691741
-rw-r--r--Tests/Module/ExternalData/SHA256/.gitattributes1
-rw-r--r--Tests/Module/ExternalData/SHA256/969171a0dd70d49ce096bd3e8178c7e26c711c9b20dbcaa3853d869d3871f1331
-rw-r--r--Tests/Module/ExternalData/SeriesA.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesA1.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesA2.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesA3.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesAn1.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesAn2.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesAn3.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesB.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesB_1.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesB_2.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesB_3.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesBn_1.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesBn_2.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesBn_3.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesC.1.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesC.2.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesC.3.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesC.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesCn.1.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesCn.2.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesCn.3.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesD-1.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesD-2.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesD-3.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesD.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesDn-1.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesDn-2.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesDn-3.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesMixed.1.dat.md51
-rw-r--r--Tests/Module/ExternalData/SeriesMixed.2.dat.sha11
-rw-r--r--Tests/Module/ExternalData/SeriesMixed.3.dat.sha2241
-rw-r--r--Tests/Module/ExternalData/SeriesMixed.4.dat.sha2561
-rw-r--r--Tests/Module/FindDependency/CMakeLists.txt11
-rw-r--r--Tests/Module/FindDependency/main.cpp29
-rw-r--r--Tests/Module/FindDependency/packages/Pack1/Pack1Config.cmake9
-rw-r--r--Tests/Module/FindDependency/packages/Pack1/Pack1ConfigVersion.cmake11
-rw-r--r--Tests/Module/FindDependency/packages/Pack2/Pack2Config.cmake5
-rw-r--r--Tests/Module/FindDependency/packages/Pack2/Pack2ConfigVersion.cmake11
-rw-r--r--Tests/Module/FindDependency/packages/Pack3/Pack3Config.cmake5
-rw-r--r--Tests/Module/FindDependency/packages/Pack3/Pack3ConfigVersion.cmake11
-rw-r--r--Tests/Module/FindDependency/packages/Pack4/Pack4Config.cmake9
-rw-r--r--Tests/Module/FindDependency/packages/Pack4/Pack4ConfigVersion.cmake11
-rw-r--r--Tests/Module/FindDependency/packages/Pack5/Pack5Config.cmake3
-rw-r--r--Tests/Module/FindDependency/packages/Pack5/Pack5ConfigVersion.cmake11
-rw-r--r--Tests/Module/FindDependency/packages/Pack6/Pack6Config.cmake3
-rw-r--r--Tests/Module/FindDependency/packages/Pack6/Pack6ConfigVersion.cmake11
-rw-r--r--Tests/Module/GenerateExportHeader/CMakeLists.txt129
-rw-r--r--Tests/Module/GenerateExportHeader/c_identifier/CMakeLists.txt13
-rw-r--r--Tests/Module/GenerateExportHeader/c_identifier/c_identifier_class.cpp7
-rw-r--r--Tests/Module/GenerateExportHeader/c_identifier/c_identifier_class.h13
-rw-r--r--Tests/Module/GenerateExportHeader/c_identifier/main.cpp8
-rw-r--r--Tests/Module/GenerateExportHeader/exportheader_test.cpp136
-rw-r--r--Tests/Module/GenerateExportHeader/lib_shared_and_static/CMakeLists.txt35
-rw-r--r--Tests/Module/GenerateExportHeader/lib_shared_and_static/libshared_and_static.cpp91
-rw-r--r--Tests/Module/GenerateExportHeader/lib_shared_and_static/libshared_and_static.h54
-rw-r--r--Tests/Module/GenerateExportHeader/libshared/CMakeLists.txt16
-rw-r--r--Tests/Module/GenerateExportHeader/libshared/libshared.cpp91
-rw-r--r--Tests/Module/GenerateExportHeader/libshared/libshared.h54
-rw-r--r--Tests/Module/GenerateExportHeader/libstatic/CMakeLists.txt18
-rw-r--r--Tests/Module/GenerateExportHeader/libstatic/libstatic.cpp87
-rw-r--r--Tests/Module/GenerateExportHeader/libstatic/libstatic.h54
-rw-r--r--Tests/Module/GenerateExportHeader/nodeprecated/CMakeLists.txt26
-rw-r--r--Tests/Module/GenerateExportHeader/nodeprecated/CMakeLists.txt.in15
-rw-r--r--Tests/Module/GenerateExportHeader/nodeprecated/src/main.cpp9
-rw-r--r--Tests/Module/GenerateExportHeader/nodeprecated/src/someclass.cpp9
-rw-r--r--Tests/Module/GenerateExportHeader/nodeprecated/src/someclass.h10
-rw-r--r--Tests/Module/GenerateExportHeader/reference/Empty/libshared_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/Empty/libstatic_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/MinGW/libshared_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/MinGW/libstatic_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/UNIX/libshared_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/UNIX/libstatic_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libshared_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libstatic_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/Win32/libshared_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/Win32/libstatic_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/WinEmpty/libshared_export.h41
-rw-r--r--Tests/Module/GenerateExportHeader/reference/WinEmpty/libstatic_export.h41
-rw-r--r--Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt88
-rw-r--r--Tests/Module/WriteCompilerDetectionHeader/main.cpp31
-rw-r--r--Tests/ModuleDefinition/CMakeLists.txt31
-rw-r--r--Tests/ModuleDefinition/example_dll.c1
-rw-r--r--Tests/ModuleDefinition/example_dll.def2
-rw-r--r--Tests/ModuleDefinition/example_dll_2.c1
-rw-r--r--Tests/ModuleDefinition/example_dll_2.def2
-rw-r--r--Tests/ModuleDefinition/example_dll_gen.c1
-rw-r--r--Tests/ModuleDefinition/example_dll_gen.def.in2
-rw-r--r--Tests/ModuleDefinition/example_exe.c16
-rw-r--r--Tests/ModuleDefinition/example_exe.def2
-rw-r--r--Tests/ModuleDefinition/example_mod_1.c21
-rw-r--r--Tests/MumpsCoverage/.gitattributes2
-rw-r--r--Tests/MumpsCoverage/DartConfiguration.cache.tcl.in8
-rw-r--r--Tests/MumpsCoverage/DartConfiguration.tcl.in8
-rw-r--r--Tests/MumpsCoverage/VistA-FOIA/Packages/Uncategorized/ZZCOVTST.m43
-rw-r--r--Tests/MumpsCoverage/ZZCOVTST.cmcov45
-rw-r--r--Tests/MumpsCoverage/ZZCOVTST.mcov38
-rw-r--r--Tests/MumpsCoverage/cache_coverage.cmcov.in2
-rw-r--r--Tests/MumpsCoverage/gtm_coverage.mcov.in2
-rw-r--r--Tests/NewlineArgs/CMakeLists.txt16
-rw-r--r--Tests/NewlineArgs/cxxonly.cxx19
-rw-r--r--Tests/NewlineArgs/libcxx1.cxx10
-rw-r--r--Tests/NewlineArgs/libcxx1.h9
-rw-r--r--Tests/NewlineArgs/libcxx2.h.in6
-rw-r--r--Tests/ObjC++/CMakeLists.txt6
-rw-r--r--Tests/ObjC++/objc++.mm23
-rw-r--r--Tests/ObjectLibrary/A/CMakeLists.txt26
-rw-r--r--Tests/ObjectLibrary/A/a.h6
-rw-r--r--Tests/ObjectLibrary/A/a1.c.in2
-rw-r--r--Tests/ObjectLibrary/A/a2.c2
-rw-r--r--Tests/ObjectLibrary/AB.def5
-rw-r--r--Tests/ObjectLibrary/B/CMakeLists.txt17
-rw-r--r--Tests/ObjectLibrary/B/b.h18
-rw-r--r--Tests/ObjectLibrary/B/b1.c2
-rw-r--r--Tests/ObjectLibrary/B/b1_vs6.c1
-rw-r--r--Tests/ObjectLibrary/B/b2.c2
-rw-r--r--Tests/ObjectLibrary/B/b2_vs6.c1
-rw-r--r--Tests/ObjectLibrary/CMakeLists.txt69
-rw-r--r--Tests/ObjectLibrary/ExportLanguages/CMakeLists.txt15
-rw-r--r--Tests/ObjectLibrary/ExportLanguages/ExportLanguagesTest/CMakeLists.txt14
-rw-r--r--Tests/ObjectLibrary/ExportLanguages/a.c1
-rw-r--r--Tests/ObjectLibrary/ExportLanguages/a.cxx1
-rw-r--r--Tests/ObjectLibrary/c.c19
-rw-r--r--Tests/ObjectLibrary/dummy.c1
-rw-r--r--Tests/ObjectLibrary/dummy.objbin0 -> 498 bytes
-rw-r--r--Tests/ObjectLibrary/main.c16
-rw-r--r--Tests/ObjectLibrary/mainAB.c20
-rw-r--r--Tests/OutDir/CMakeLists.txt35
-rw-r--r--Tests/OutDir/OutDir.c24
-rw-r--r--Tests/OutDir/OutDir.cmake28
-rw-r--r--Tests/OutOfBinary/CMakeLists.txt2
-rw-r--r--Tests/OutOfBinary/outlib.c2
-rw-r--r--Tests/OutOfSource/CMakeLists.txt18
-rw-r--r--Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt62
-rw-r--r--Tests/OutOfSource/OutOfSourceSubdir/simple.cxx39
-rw-r--r--Tests/OutOfSource/OutOfSourceSubdir/simple.cxx.in1
-rw-r--r--Tests/OutOfSource/OutOfSourceSubdir/testlib.cxx6
-rw-r--r--Tests/OutOfSource/OutOfSourceSubdir/testlib.h11
-rw-r--r--Tests/OutOfSource/SubDir/CMakeLists.txt8
-rw-r--r--Tests/OutOfSource/simple.cxx1
-rw-r--r--Tests/OutOfSource/testdp.h.in1
-rw-r--r--Tests/PDBDirectoryAndName/CMakeLists.txt92
-rw-r--r--Tests/PDBDirectoryAndName/check_pdbs.cmake10
-rw-r--r--Tests/PDBDirectoryAndName/myexe.c5
-rw-r--r--Tests/PDBDirectoryAndName/myexe2.c3
-rw-r--r--Tests/PDBDirectoryAndName/mylibA.c1
-rw-r--r--Tests/PDBDirectoryAndName/mylibB.c1
-rw-r--r--Tests/PDBDirectoryAndName/mylibC.c1
-rw-r--r--Tests/PDBDirectoryAndName/mylibD.c1
-rw-r--r--Tests/PerConfig/CMakeLists.txt34
-rw-r--r--Tests/PerConfig/pcShared.c5
-rw-r--r--Tests/PerConfig/pcShared.h16
-rw-r--r--Tests/PerConfig/pcStatic.c4
-rw-r--r--Tests/PerConfig/perconfig.c8
-rw-r--r--Tests/PerConfig/perconfig.cmake40
-rw-r--r--Tests/Plugin/CMakeLists.txt76
-rw-r--r--Tests/Plugin/PluginTest/CMakeLists.txt34
-rw-r--r--Tests/Plugin/check_mod_soname.cmake14
-rw-r--r--Tests/Plugin/include/example.h25
-rw-r--r--Tests/Plugin/src/example_exe.cxx60
-rw-r--r--Tests/Plugin/src/example_exe.h.in6
-rw-r--r--Tests/Plugin/src/example_mod_1.c22
-rw-r--r--Tests/Policy0002/A/CMakeLists.txt1
-rw-r--r--Tests/Policy0002/CMakeLists.txt5
-rw-r--r--Tests/Policy0002/policy0002.c4
-rw-r--r--Tests/PolicyScope/Bar.cmake8
-rw-r--r--Tests/PolicyScope/CMakeLists.txt104
-rw-r--r--Tests/PolicyScope/FindFoo.cmake2
-rw-r--r--Tests/PolicyScope/main.c4
-rw-r--r--Tests/PositionIndependentTargets/CMakeLists.txt14
-rw-r--r--Tests/PositionIndependentTargets/global/CMakeLists.txt37
-rw-r--r--Tests/PositionIndependentTargets/interface/CMakeLists.txt27
-rw-r--r--Tests/PositionIndependentTargets/main.cpp2
-rw-r--r--Tests/PositionIndependentTargets/pic_lib.cpp12
-rw-r--r--Tests/PositionIndependentTargets/pic_main.cpp4
-rw-r--r--Tests/PositionIndependentTargets/pic_test.h20
-rw-r--r--Tests/PositionIndependentTargets/targets/CMakeLists.txt20
-rw-r--r--Tests/PreOrder/CMakeLists.txt6
-rw-r--r--Tests/PreOrder/Library/CMakeLists.txt2
-rw-r--r--Tests/PreOrder/Library/simpleLib.cxx3
-rw-r--r--Tests/PreOrder/simple.cxx6
-rw-r--r--Tests/PrecompiledHeader/CMakeLists.txt59
-rw-r--r--Tests/PrecompiledHeader/foo1.c8
-rw-r--r--Tests/PrecompiledHeader/foo2.c9
-rw-r--r--Tests/PrecompiledHeader/foo_precompile.c5
-rw-r--r--Tests/PrecompiledHeader/include/foo.h4
-rw-r--r--Tests/PrecompiledHeader/include/foo_precompiled.h1
-rw-r--r--Tests/Preprocess/CMakeLists.txt275
-rw-r--r--Tests/Preprocess/file_def.h1
-rw-r--r--Tests/Preprocess/preprocess.c198
-rw-r--r--Tests/Preprocess/preprocess.cxx225
-rw-r--r--Tests/Preprocess/preprocess.h.in16
-rw-r--r--Tests/Preprocess/preprocess_vs6.cxx3
-rw-r--r--Tests/Preprocess/target_def.h1
-rw-r--r--Tests/Properties/CMakeLists.txt147
-rw-r--r--Tests/Properties/SubDir/properties3.cxx9
-rw-r--r--Tests/Properties/SubDir2/CMakeLists.txt5
-rw-r--r--Tests/Properties/properties.h.in1
-rw-r--r--Tests/Properties/properties2.h1
-rw-r--r--Tests/Properties/subdirtest.cxx9
-rw-r--r--Tests/PythonCoverage/DartConfiguration.tcl.in8
-rw-r--r--Tests/PythonCoverage/coverage.xml.in35
-rw-r--r--Tests/PythonCoverage/coveragetest/foo.py8
-rw-r--r--Tests/PythonCoverage/coveragetest/test_foo.py11
-rw-r--r--Tests/Qt4And5Automoc/CMakeLists.txt29
-rw-r--r--Tests/Qt4And5Automoc/main.cpp.in18
-rw-r--r--Tests/Qt4Deploy/CMakeLists.txt70
-rw-r--r--Tests/Qt4Deploy/testdeploy.cpp29
-rw-r--r--Tests/Qt4Targets/CMakeLists.txt80
-rw-r--r--Tests/Qt4Targets/IncrementalMoc/CMakeLists.txt21
-rw-r--r--Tests/Qt4Targets/IncrementalMoc/foo.cpp8
-rw-r--r--Tests/Qt4Targets/IncrementalMoc/foo.h9
-rw-r--r--Tests/Qt4Targets/activeqtexe.cpp36
-rw-r--r--Tests/Qt4Targets/interface/myinterface.h12
-rw-r--r--Tests/Qt4Targets/main.cpp24
-rw-r--r--Tests/Qt4Targets/main_gen_test.cpp21
-rw-r--r--Tests/Qt4Targets/main_wrap_test.cpp11
-rw-r--r--Tests/Qt4Targets/mywrapobject.h17
-rw-r--r--Tests/QtAutoUicInterface/CMakeLists.txt70
-rw-r--r--Tests/QtAutoUicInterface/klocalizedstring.cpp12
-rw-r--r--Tests/QtAutoUicInterface/klocalizedstring.h17
-rw-r--r--Tests/QtAutoUicInterface/libwidget.cpp9
-rw-r--r--Tests/QtAutoUicInterface/libwidget.h24
-rw-r--r--Tests/QtAutoUicInterface/libwidget.ui32
-rw-r--r--Tests/QtAutoUicInterface/main.cpp75
-rw-r--r--Tests/QtAutoUicInterface/mywidget.cpp9
-rw-r--r--Tests/QtAutoUicInterface/mywidget.h24
-rw-r--r--Tests/QtAutoUicInterface/mywidget.ui32
-rw-r--r--Tests/QtAutogen/Adir/CMakeLists.txt8
-rw-r--r--Tests/QtAutogen/Adir/libA.cpp13
-rw-r--r--Tests/QtAutogen/Adir/libA.h18
-rw-r--r--Tests/QtAutogen/Bdir/CMakeLists.txt10
-rw-r--r--Tests/QtAutogen/Bdir/libB.cpp13
-rw-r--r--Tests/QtAutogen/Bdir/libB.h21
-rw-r--r--Tests/QtAutogen/CMakeLists.txt115
-rw-r--r--Tests/QtAutogen/abc.cpp49
-rw-r--r--Tests/QtAutogen/abc.h28
-rw-r--r--Tests/QtAutogen/abc_p.h30
-rw-r--r--Tests/QtAutogen/bar.cpp28
-rw-r--r--Tests/QtAutogen/blub.cpp40
-rw-r--r--Tests/QtAutogen/blub.h26
-rw-r--r--Tests/QtAutogen/calwidget.cpp434
-rw-r--r--Tests/QtAutogen/calwidget.h128
-rw-r--r--Tests/QtAutogen/calwidget.ui32
-rw-r--r--Tests/QtAutogen/codeeditor.cpp153
-rw-r--r--Tests/QtAutogen/codeeditor.h99
-rw-r--r--Tests/QtAutogen/debug_class.cpp9
-rw-r--r--Tests/QtAutogen/debug_class.h20
-rw-r--r--Tests/QtAutogen/debug_class.ui45
-rw-r--r--Tests/QtAutogen/debug_resource.qrc5
-rw-r--r--Tests/QtAutogen/defines_test/CMakeLists.txt6
-rw-r--r--Tests/QtAutogen/defines_test/defines_test.cpp38
-rw-r--r--Tests/QtAutogen/empty.cpp1
-rw-r--r--Tests/QtAutogen/empty.h9
-rw-r--r--Tests/QtAutogen/foo.cpp39
-rw-r--r--Tests/QtAutogen/foo.h31
-rw-r--r--Tests/QtAutogen/gadget.cpp4
-rw-r--r--Tests/QtAutogen/gadget.h18
-rw-r--r--Tests/QtAutogen/generated.cpp10
-rw-r--r--Tests/QtAutogen/generated.h18
-rw-r--r--Tests/QtAutogen/libC.cpp13
-rw-r--r--Tests/QtAutogen/libC.h22
-rw-r--r--Tests/QtAutogen/main.cpp94
-rw-r--r--Tests/QtAutogen/multiplewidgets.cpp19
-rw-r--r--Tests/QtAutogen/multiplewidgets.h33
-rw-r--r--Tests/QtAutogen/myinterface.h.in14
-rw-r--r--Tests/QtAutogen/myotherinterface.h.in14
-rw-r--r--Tests/QtAutogen/not_generated_file.qrc5
-rw-r--r--Tests/QtAutogen/private_slot.cpp21
-rw-r--r--Tests/QtAutogen/private_slot.h20
-rw-r--r--Tests/QtAutogen/rcconly.cpp9
-rw-r--r--Tests/QtAutogen/resourcetester.cpp27
-rw-r--r--Tests/QtAutogen/resourcetester.h17
-rw-r--r--Tests/QtAutogen/second_resource.qrc5
-rw-r--r--Tests/QtAutogen/second_widget.cpp14
-rw-r--r--Tests/QtAutogen/second_widget.h19
-rw-r--r--Tests/QtAutogen/second_widget.ui32
-rw-r--r--Tests/QtAutogen/sub/bar.h28
-rw-r--r--Tests/QtAutogen/sub/uiconly.cpp13
-rw-r--r--Tests/QtAutogen/sub/uiconly.h20
-rw-r--r--Tests/QtAutogen/sub/uiconly.ui24
-rw-r--r--Tests/QtAutogen/test.qrc5
-rw-r--r--Tests/QtAutogen/widget1.ui45
-rw-r--r--Tests/QtAutogen/widget2.ui29
-rw-r--r--Tests/QtAutogen/xyz.cpp28
-rw-r--r--Tests/QtAutogen/xyz.h28
-rw-r--r--Tests/QtAutogen/yaf.cpp32
-rw-r--r--Tests/QtAutogen/yaf.h25
-rw-r--r--Tests/QtAutogen/yaf_p.h30
-rw-r--r--Tests/QtAutomocNoQt/CMakeLists.txt7
-rw-r--r--Tests/QtAutomocNoQt/main.c4
-rw-r--r--Tests/README39
-rw-r--r--Tests/RegexEscapeString.cmake4
-rw-r--r--Tests/ReturnTest/CMakeLists.txt147
-rw-r--r--Tests/ReturnTest/include_return.cmake3
-rw-r--r--Tests/ReturnTest/returnTest.c7
-rw-r--r--Tests/ReturnTest/subdir/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-NEW-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-NEW.cmake9
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-OLD-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-OLD.cmake21
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-WARN-stderr.txt0
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-policy-genex-result.txt1
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-policy-genex-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0004/CMP0004-policy-genex.cmake14
-rw-r--r--Tests/RunCMake/CMP0004/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0004/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0004/empty.cpp0
-rw-r--r--Tests/RunCMake/CMP0019/CMP0019-NEW.cmake2
-rw-r--r--Tests/RunCMake/CMP0019/CMP0019-OLD.cmake2
-rw-r--r--Tests/RunCMake/CMP0019/CMP0019-WARN-stderr.txt40
-rw-r--r--Tests/RunCMake/CMP0019/CMP0019-WARN.cmake1
-rw-r--r--Tests/RunCMake/CMP0019/CMP0019-code.cmake9
-rw-r--r--Tests/RunCMake/CMP0019/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0019/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-exe-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-exe.cmake7
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-shared-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-shared.cmake10
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-NEW-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-NEW.cmake14
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-link_libraries-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-link_libraries.cmake9
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-NOWARN-static.cmake8
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-result.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-stderr.txt19
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old.cmake10
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-static-result.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-static-stderr.txt19
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-static.cmake11
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-stderr.txt17
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-tll-result.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-tll-stderr.txt17
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN-tll.cmake11
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-WARN.cmake18
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-export-exe-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-export-exe.cmake9
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-export-result.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-export-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-export.cmake11
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-install-export-result.txt1
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-install-export-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0022/CMP0022-install-export.cmake12
-rw-r--r--Tests/RunCMake/CMP0022/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0022/RunCMakeTest.cmake14
-rw-r--r--Tests/RunCMake/CMP0022/dep1/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/CMP0022/dep2/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/CMP0022/dep3/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/CMP0022/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0022/empty_vs6_1.cpp1
-rw-r--r--Tests/RunCMake/CMP0022/empty_vs6_2.cpp1
-rw-r--r--Tests/RunCMake/CMP0022/empty_vs6_3.cpp1
-rw-r--r--Tests/RunCMake/CMP0022/empty_vs6_4.cpp1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt7
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW.cmake7
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD.cmake7
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN.cmake5
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-IMPORTED-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-IMPORTED-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-IMPORTED.cmake6
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt7
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW.cmake7
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD.cmake7
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN.cmake5
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt7
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-NEW.cmake7
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-WARN-Dir/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt25
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-WARN.cmake8
-rw-r--r--Tests/RunCMake/CMP0026/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0026/ObjlibNotDefined-result.txt1
-rw-r--r--Tests/RunCMake/CMP0026/ObjlibNotDefined-stderr.txt12
-rw-r--r--Tests/RunCMake/CMP0026/ObjlibNotDefined.cmake13
-rw-r--r--Tests/RunCMake/CMP0026/RunCMakeTest.cmake12
-rw-r--r--Tests/RunCMake/CMP0026/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0027/CMP0027-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0027/CMP0027-NEW-stderr.txt13
-rw-r--r--Tests/RunCMake/CMP0027/CMP0027-NEW.cmake10
-rw-r--r--Tests/RunCMake/CMP0027/CMP0027-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0027/CMP0027-OLD-stderr.txt13
-rw-r--r--Tests/RunCMake/CMP0027/CMP0027-OLD.cmake10
-rw-r--r--Tests/RunCMake/CMP0027/CMP0027-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0027/CMP0027-WARN-stderr.txt18
-rw-r--r--Tests/RunCMake/CMP0027/CMP0027-WARN.cmake8
-rw-r--r--Tests/RunCMake/CMP0027/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0027/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0027/empty.cpp0
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-NEW-iface-result.txt1
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-NEW-iface-stderr.txt6
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-NEW-iface.cmake7
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-NEW-stderr.txt6
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-NEW.cmake5
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-OLD-iface-result.txt1
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-OLD-iface-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-OLD-iface.cmake7
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-OLD.cmake5
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-WARN-iface-result.txt1
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-WARN-iface-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-WARN-iface.cmake5
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-WARN-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0028/CMP0028-WARN.cmake3
-rw-r--r--Tests/RunCMake/CMP0028/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0028/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/CMP0028/empty.cpp0
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-colon-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-colon-stderr.txt20
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake6
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-stderr.txt18
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake6
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-space-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-space-stderr.txt20
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake6
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-OLD-reserved-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-OLD-reserved-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake6
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-OLD-space-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-OLD-space-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake6
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-WARN-colon-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-WARN-colon-stderr.txt38
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake4
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-WARN-space-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-WARN-space-stderr.txt37
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake4
-rw-r--r--Tests/RunCMake/CMP0037/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0037/RunCMakeTest.cmake13
-rw-r--r--Tests/RunCMake/CMP0037/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0038/CMP0038-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0038/CMP0038-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0038/CMP0038-NEW.cmake4
-rw-r--r--Tests/RunCMake/CMP0038/CMP0038-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0038/CMP0038-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0038/CMP0038-OLD.cmake4
-rw-r--r--Tests/RunCMake/CMP0038/CMP0038-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0038/CMP0038-WARN-stderr.txt9
-rw-r--r--Tests/RunCMake/CMP0038/CMP0038-WARN.cmake3
-rw-r--r--Tests/RunCMake/CMP0038/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0038/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0038/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0039/CMP0039-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt5
-rw-r--r--Tests/RunCMake/CMP0039/CMP0039-NEW.cmake7
-rw-r--r--Tests/RunCMake/CMP0039/CMP0039-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0039/CMP0039-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0039/CMP0039-OLD.cmake7
-rw-r--r--Tests/RunCMake/CMP0039/CMP0039-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0039/CMP0039-WARN-stderr.txt10
-rw-r--r--Tests/RunCMake/CMP0039/CMP0039-WARN.cmake5
-rw-r--r--Tests/RunCMake/CMP0039/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0039/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-result.txt1
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target.cmake7
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-result.txt1
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target.cmake5
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-result.txt1
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target.cmake7
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-result.txt1
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target.cmake5
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-result.txt1
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt10
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target.cmake4
-rw-r--r--Tests/RunCMake/CMP0040/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0040/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/CMP0040/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-NEW-stderr.txt20
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-NEW.cmake12
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-OLD.cmake12
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-WARN-stderr.txt32
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-WARN.cmake10
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-tid-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-tid-NEW-stderr.txt22
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-tid-NEW.cmake11
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-tid-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-tid-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-tid-OLD.cmake11
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-tid-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-tid-WARN-stderr.txt34
-rw-r--r--Tests/RunCMake/CMP0041/CMP0041-tid-WARN.cmake9
-rw-r--r--Tests/RunCMake/CMP0041/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0041/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/CMP0041/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0042/CMP0042-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0042/CMP0042-NEW-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0042/CMP0042-NEW.cmake4
-rw-r--r--Tests/RunCMake/CMP0042/CMP0042-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0042/CMP0042-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0042/CMP0042-OLD.cmake4
-rw-r--r--Tests/RunCMake/CMP0042/CMP0042-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0042/CMP0042-WARN-stderr.txt10
-rw-r--r--Tests/RunCMake/CMP0042/CMP0042-WARN.cmake9
-rw-r--r--Tests/RunCMake/CMP0042/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0042/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0042/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0043/CMP0043-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0043/CMP0043-NEW-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0043/CMP0043-NEW.cmake7
-rw-r--r--Tests/RunCMake/CMP0043/CMP0043-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0043/CMP0043-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0043/CMP0043-OLD.cmake7
-rw-r--r--Tests/RunCMake/CMP0043/CMP0043-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0043/CMP0043-WARN-stderr.txt5
-rw-r--r--Tests/RunCMake/CMP0043/CMP0043-WARN.cmake5
-rw-r--r--Tests/RunCMake/CMP0043/CMakeLists.txt7
-rw-r--r--Tests/RunCMake/CMP0043/RunCMakeTest.cmake7
-rw-r--r--Tests/RunCMake/CMP0043/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0045/CMP0045-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0045/CMP0045-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0045/CMP0045-NEW.cmake4
-rw-r--r--Tests/RunCMake/CMP0045/CMP0045-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0045/CMP0045-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0045/CMP0045-OLD.cmake4
-rw-r--r--Tests/RunCMake/CMP0045/CMP0045-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0045/CMP0045-WARN-stderr.txt9
-rw-r--r--Tests/RunCMake/CMP0045/CMP0045-WARN.cmake2
-rw-r--r--Tests/RunCMake/CMP0045/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0045/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0045/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-Duplicate-result.txt1
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-Duplicate-stderr.txt10
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-Duplicate.cmake9
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-NEW-existing-dependency-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-NEW-existing-dependency.cmake5
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-result.txt1
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency.cmake4
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-OLD-existing-dependency-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-OLD-existing-dependency.cmake5
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-OLD-missing-dependency-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-OLD-missing-dependency.cmake4
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-WARN-missing-dependency-stderr.txt9
-rw-r--r--Tests/RunCMake/CMP0046/CMP0046-WARN-missing-dependency.cmake2
-rw-r--r--Tests/RunCMake/CMP0046/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0046/RunCMakeTest.cmake9
-rw-r--r--Tests/RunCMake/CMP0046/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0049/CMP0049-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0049/CMP0049-NEW-stderr.txt6
-rw-r--r--Tests/RunCMake/CMP0049/CMP0049-NEW.cmake5
-rw-r--r--Tests/RunCMake/CMP0049/CMP0049-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0049/CMP0049-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0049/CMP0049-OLD.cmake5
-rw-r--r--Tests/RunCMake/CMP0049/CMP0049-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0049/CMP0049-WARN-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0049/CMP0049-WARN.cmake3
-rw-r--r--Tests/RunCMake/CMP0049/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0049/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0049/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0050/CMP0050-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0050/CMP0050-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0050/CMP0050-NEW.cmake13
-rw-r--r--Tests/RunCMake/CMP0050/CMP0050-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0050/CMP0050-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0050/CMP0050-OLD.cmake13
-rw-r--r--Tests/RunCMake/CMP0050/CMP0050-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0050/CMP0050-WARN-stderr.txt9
-rw-r--r--Tests/RunCMake/CMP0050/CMP0050-WARN.cmake11
-rw-r--r--Tests/RunCMake/CMP0050/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0050/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0050/empty.cpp10
-rw-r--r--Tests/RunCMake/CMP0050/input.h.in2
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-NEW-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-NEW.cmake10
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-OLD.cmake10
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-WARN-Dir/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-WARN-result.txt1
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt31
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-WARN.cmake14
-rw-r--r--Tests/RunCMake/CMP0051/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0051/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0051/empty.cpp7
-rw-r--r--Tests/RunCMake/CMP0053/CMP0053-NEW-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0053/CMP0053-NEW.cmake8
-rw-r--r--Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0053/CMP0053-OLD.cmake8
-rw-r--r--Tests/RunCMake/CMP0053/CMP0053-WARN-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0053/CMP0053-WARN.cmake6
-rw-r--r--Tests/RunCMake/CMP0053/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0053/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-NEW-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-NEW.cmake47
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-OLD.cmake47
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-WARN-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-WARN.cmake5
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings-stderr.txt24
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings.cmake12
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-stderr.txt8
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-keywords-NEW.cmake25
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-keywords-OLD.cmake9
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-keywords-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-keywords-WARN.cmake3
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-command-scope.cmake53
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope.cmake49
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-nested-if-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-nested-if.cmake41
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-while-scope-stderr.txt1
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-while-scope.cmake65
-rw-r--r--Tests/RunCMake/CMP0054/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0054/RunCMakeTest.cmake13
-rw-r--r--Tests/RunCMake/CMakeLists.txt155
-rw-r--r--Tests/RunCMake/CPackInstallProperties/Append-check.cmake3
-rw-r--r--Tests/RunCMake/CPackInstallProperties/Append.cmake2
-rw-r--r--Tests/RunCMake/CPackInstallProperties/CMakeLists.txt6
-rw-r--r--Tests/RunCMake/CPackInstallProperties/FilenameGenex-check.cmake3
-rw-r--r--Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake7
-rw-r--r--Tests/RunCMake/CPackInstallProperties/MultipleValues-check.cmake3
-rw-r--r--Tests/RunCMake/CPackInstallProperties/MultipleValues.cmake1
-rw-r--r--Tests/RunCMake/CPackInstallProperties/PerConfigValue-check.cmake13
-rw-r--r--Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake14
-rw-r--r--Tests/RunCMake/CPackInstallProperties/Replace-check.cmake3
-rw-r--r--Tests/RunCMake/CPackInstallProperties/Replace.cmake2
-rw-r--r--Tests/RunCMake/CPackInstallProperties/RunCMakeTest.cmake9
-rw-r--r--Tests/RunCMake/CPackInstallProperties/Simple-check.cmake3
-rw-r--r--Tests/RunCMake/CPackInstallProperties/Simple.cmake1
-rw-r--r--Tests/RunCMake/CPackInstallProperties/ValueGenex-check.cmake3
-rw-r--r--Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake7
-rw-r--r--Tests/RunCMake/CPackInstallProperties/check.cmake12
-rw-r--r--Tests/RunCMake/CPackInstallProperties/test.cpp1
-rw-r--r--Tests/RunCMake/CTest/BeforeProject-result.txt1
-rw-r--r--Tests/RunCMake/CTest/BeforeProject-stderr.txt6
-rw-r--r--Tests/RunCMake/CTest/BeforeProject.cmake2
-rw-r--r--Tests/RunCMake/CTest/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/CTest/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CheckModules/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey-result.txt1
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey-stderr.txt8
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage-result.txt1
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage-stderr.txt8
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberOk.cmake6
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments-result.txt1
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments-stderr.txt8
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage-result.txt1
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage-stderr.txt10
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey-result.txt1
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey-stderr.txt8
-rw-r--r--Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage-result.txt1
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage-stderr.txt8
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs-result.txt1
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs-stderr.txt10
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeOk.cmake12
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeOkNoC.cmake4
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument-result.txt1
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument-stderr.txt8
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage-result.txt1
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage-stderr.txt10
-rw-r--r--Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/RunCMakeTest.cmake16
-rw-r--r--Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake6
-rw-r--r--Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake3
-rw-r--r--Tests/RunCMake/CommandLine/E_create_symlink-missing-dir-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_create_symlink-missing-dir-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_create_symlink-no-replace-dir-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_create_symlink-no-replace-dir-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_env-bad-arg1-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_env-bad-arg1-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_env-no-command0-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_env-no-command0-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_env-no-command1-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_env-no-command1-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_env-set-stdout.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_env-set.cmake5
-rw-r--r--Tests/RunCMake/CommandLine/E_env-unset-stdout.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_env-unset.cmake5
-rw-r--r--Tests/RunCMake/CommandLine/E_sleep-bad-arg1-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_sleep-bad-arg1-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_sleep-bad-arg2-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_sleep-bad-arg2-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_sleep-no-args-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_sleep-no-args-stderr.cmake2
-rw-r--r--Tests/RunCMake/CommandLine/P_directory-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/P_directory-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake45
-rw-r--r--Tests/RunCMake/CommandLine/build-bad-generator-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/build-bad-generator-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/build-no-cache-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/build-no-cache-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/build-no-generator-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/build-no-generator-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt1
-rw-r--r--Tests/RunCMake/CommandLine/cache-no-generator/CMakeCache.txt0
-rw-r--r--Tests/RunCMake/CompatibleInterface/AutoUic-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/AutoUic-stderr.txt11
-rw-r--r--Tests/RunCMake/CompatibleInterface/AutoUic.cmake19
-rw-r--r--Tests/RunCMake/CompatibleInterface/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CompatibleInterface/DebugProperties-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/DebugProperties-stderr.txt101
-rw-r--r--Tests/RunCMake/CompatibleInterface/DebugProperties.cmake74
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop-stderr.txt5
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop.cmake11
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self-stderr.txt3
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self.cmake11
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends-stderr.txt3
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends.cmake10
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use-stderr.txt4
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use.cmake9
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use-stderr.txt4
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use.cmake9
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict-stderr.txt6
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict.cmake8
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict-stderr.txt7
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict.cmake9
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop-stderr.txt5
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop.cmake9
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self-stderr.txt3
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self.cmake11
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends-stderr.txt3
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends.cmake10
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use-result.txt1
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use-stderr.txt4
-rw-r--r--Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use.cmake9
-rw-r--r--Tests/RunCMake/CompatibleInterface/RunCMakeTest.cmake19
-rw-r--r--Tests/RunCMake/CompatibleInterface/empty.cpp1
-rw-r--r--Tests/RunCMake/CompatibleInterface/main.cpp5
-rw-r--r--Tests/RunCMake/CompileFeatures/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-stderr.txt7
-rw-r--r--Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake15
-rw-r--r--Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-stderr.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved.cmake14
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCFeatures-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCFeatures-stderr.txt8
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCFeatures.cmake5
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex-stderr.txt6
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex.cmake5
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures-stderr.txt8
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures.cmake3
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex-stderr.txt6
-rw-r--r--Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex.cmake3
-rw-r--r--Tests/RunCMake/CompileFeatures/NonValidTarget1-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NonValidTarget1-stderr.txt9
-rw-r--r--Tests/RunCMake/CompileFeatures/NonValidTarget1.cmake17
-rw-r--r--Tests/RunCMake/CompileFeatures/NonValidTarget2-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NonValidTarget2-stderr.txt9
-rw-r--r--Tests/RunCMake/CompileFeatures/NonValidTarget2.cmake8
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature-stderr.txt2
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature.cmake3
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeatureGenex-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt2
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake3
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeatureTransitive-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeatureTransitive-stderr.txt2
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeatureTransitive.cmake6
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug-stderr.txt11
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug.cmake4
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex-stderr.txt11
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex.cmake4
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive-stderr.txt11
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive.cmake6
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-stderr.txt5
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features.cmake4
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11-stderr.txt3
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11.cmake5
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11Ext-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11Ext-stderr.txt3
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11Ext.cmake4
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-stderr.txt3
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable.cmake4
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11Variable-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11Variable-stderr.txt3
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX11Variable.cmake5
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98-stderr.txt3
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98.cmake5
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98Ext-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98Ext-stderr.txt3
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98Ext.cmake4
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-stderr.txt3
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable.cmake4
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98Variable-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98Variable-stderr.txt3
-rw-r--r--Tests/RunCMake/CompileFeatures/RequireCXX98Variable.cmake5
-rw-r--r--Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake54
-rw-r--r--Tests/RunCMake/CompileFeatures/empty.c7
-rw-r--r--Tests/RunCMake/CompileFeatures/empty.cpp7
-rw-r--r--Tests/RunCMake/CompileFeatures/generate_feature_list.cmake29
-rw-r--r--Tests/RunCMake/CompilerChange/CMakeLists.txt6
-rw-r--r--Tests/RunCMake/CompilerChange/EmptyCompiler-override.cmake2
-rw-r--r--Tests/RunCMake/CompilerChange/EmptyCompiler-result.txt1
-rw-r--r--Tests/RunCMake/CompilerChange/EmptyCompiler-stderr.txt13
-rw-r--r--Tests/RunCMake/CompilerChange/EmptyCompiler.cmake2
-rw-r--r--Tests/RunCMake/CompilerChange/FindCompiler.cmake2
-rw-r--r--Tests/RunCMake/CompilerChange/FirstCompiler-stdout.txt1
-rw-r--r--Tests/RunCMake/CompilerChange/FirstCompiler.cmake3
-rw-r--r--Tests/RunCMake/CompilerChange/RunCMakeTest.cmake58
-rw-r--r--Tests/RunCMake/CompilerChange/SecondCompiler-stderr.txt4
-rw-r--r--Tests/RunCMake/CompilerChange/SecondCompiler-stdout.txt1
-rw-r--r--Tests/RunCMake/CompilerChange/SecondCompiler.cmake3
-rwxr-xr-xTests/RunCMake/CompilerChange/cc.sh.in2
-rw-r--r--Tests/RunCMake/CompilerNotFound/BadCompilerC-result.txt1
-rw-r--r--Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr.txt12
-rw-r--r--Tests/RunCMake/CompilerNotFound/BadCompilerC.cmake3
-rw-r--r--Tests/RunCMake/CompilerNotFound/BadCompilerCXX-result.txt1
-rw-r--r--Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr.txt12
-rw-r--r--Tests/RunCMake/CompilerNotFound/BadCompilerCXX.cmake3
-rw-r--r--Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-result.txt1
-rw-r--r--Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr.txt25
-rw-r--r--Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX.cmake4
-rw-r--r--Tests/RunCMake/CompilerNotFound/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE-result.txt1
-rw-r--r--Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE-stderr.txt5
-rw-r--r--Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE.cmake3
-rw-r--r--Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE-result.txt1
-rw-r--r--Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE-stderr.txt5
-rw-r--r--Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE.cmake3
-rw-r--r--Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE-result.txt1
-rw-r--r--Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE-stderr.txt11
-rw-r--r--Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE.cmake4
-rw-r--r--Tests/RunCMake/CompilerNotFound/RunCMakeTest.cmake11
-rw-r--r--Tests/RunCMake/Configure/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/Configure/CustomTargetAfterError-result.txt1
-rw-r--r--Tests/RunCMake/Configure/CustomTargetAfterError-stderr.txt9
-rw-r--r--Tests/RunCMake/Configure/CustomTargetAfterError.cmake3
-rw-r--r--Tests/RunCMake/Configure/ErrorLogs-result.txt1
-rw-r--r--Tests/RunCMake/Configure/ErrorLogs-stderr.txt4
-rw-r--r--Tests/RunCMake/Configure/ErrorLogs-stdout.txt3
-rw-r--r--Tests/RunCMake/Configure/ErrorLogs.cmake3
-rw-r--r--Tests/RunCMake/Configure/FailCopyFileABI-check.cmake14
-rw-r--r--Tests/RunCMake/Configure/FailCopyFileABI-override.cmake6
-rw-r--r--Tests/RunCMake/Configure/FailCopyFileABI-stdout.txt4
-rw-r--r--Tests/RunCMake/Configure/FailCopyFileABI.cmake2
-rw-r--r--Tests/RunCMake/Configure/RerunCMake-build1-check.cmake9
-rw-r--r--Tests/RunCMake/Configure/RerunCMake-build2-check.cmake9
-rw-r--r--Tests/RunCMake/Configure/RerunCMake.cmake11
-rw-r--r--Tests/RunCMake/Configure/RerunCMake.txt1
-rw-r--r--Tests/RunCMake/Configure/RunCMakeTest.cmake25
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0029-NEW-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0029-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0029-NEW.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0029-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0029-OLD.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0029-WARN-stderr.txt7
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0029-WARN.cmake1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0030-NEW-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0030-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0030-NEW.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0030-OLD-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0030-OLD-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0030-OLD.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0030-WARN-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0030-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0030-WARN.cmake1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0031-NEW-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0031-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0031-NEW.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0031-OLD-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0031-OLD-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0031-OLD.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0031-WARN-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0031-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0031-WARN.cmake1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0032-NEW-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0032-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0032-NEW.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0032-OLD-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0032-OLD-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0032-OLD.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0032-WARN-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0032-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0032-WARN.cmake1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0033-NEW-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0033-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0033-NEW.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0033-OLD-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0033-OLD-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0033-OLD.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0033-WARN-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0033-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0033-WARN.cmake1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0034-NEW-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0034-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0034-NEW.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0034-OLD-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0034-OLD-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0034-OLD.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0034-WARN-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0034-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0034-WARN.cmake1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0035-NEW-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0035-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0035-NEW.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0035-OLD-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0035-OLD-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0035-OLD.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0035-WARN-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0035-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0035-WARN.cmake1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0036-NEW-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0036-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0036-NEW.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0036-OLD-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0036-OLD-stderr.txt4
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0036-OLD.cmake2
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0036-WARN-result.txt1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0036-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMP0036-WARN.cmake1
-rw-r--r--Tests/RunCMake/DisallowedCommands/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/DisallowedCommands/RunCMakeTest.cmake16
-rw-r--r--Tests/RunCMake/ExportWithoutLanguage/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/ExportWithoutLanguage/NoLanguage-result.txt1
-rw-r--r--Tests/RunCMake/ExportWithoutLanguage/NoLanguage-stderr.txt4
-rw-r--r--Tests/RunCMake/ExportWithoutLanguage/NoLanguage.cmake2
-rw-r--r--Tests/RunCMake/ExportWithoutLanguage/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/ExportWithoutLanguage/header.h2
-rw-r--r--Tests/RunCMake/ExternalData/BadHashAlgo1-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/BadHashAlgo1-stderr.txt8
-rw-r--r--Tests/RunCMake/ExternalData/BadHashAlgo1.cmake3
-rw-r--r--Tests/RunCMake/ExternalData/BadHashAlgo1.txt1
-rw-r--r--Tests/RunCMake/ExternalData/BadOption1-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/BadOption1-stderr.txt9
-rw-r--r--Tests/RunCMake/ExternalData/BadOption1.cmake5
-rw-r--r--Tests/RunCMake/ExternalData/BadOption2-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/BadOption2-stderr.txt9
-rw-r--r--Tests/RunCMake/ExternalData/BadOption2.cmake5
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries1-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries1-stderr.txt19
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries1.cmake3
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries2-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries2-stderr.txt16
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries2.cmake3
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries3-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries3-stderr.txt6
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries3.cmake2
-rw-r--r--Tests/RunCMake/ExternalData/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/ExternalData/Data.txt.md51
-rw-r--r--Tests/RunCMake/ExternalData/Directory1-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/Directory1-stderr.txt14
-rw-r--r--Tests/RunCMake/ExternalData/Directory1.cmake6
-rw-r--r--Tests/RunCMake/ExternalData/Directory1/DirData1.txt0
-rw-r--r--Tests/RunCMake/ExternalData/Directory2-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/Directory2-stderr.txt10
-rw-r--r--Tests/RunCMake/ExternalData/Directory2.cmake6
-rw-r--r--Tests/RunCMake/ExternalData/Directory2.md51
-rw-r--r--Tests/RunCMake/ExternalData/Directory2/DirData2.txt0
-rw-r--r--Tests/RunCMake/ExternalData/Directory3-stderr.txt15
-rw-r--r--Tests/RunCMake/ExternalData/Directory3.cmake6
-rw-r--r--Tests/RunCMake/ExternalData/Directory3/DirData3.txt0
-rw-r--r--Tests/RunCMake/ExternalData/Directory4-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/Directory4-stderr.txt6
-rw-r--r--Tests/RunCMake/ExternalData/Directory4.cmake6
-rw-r--r--Tests/RunCMake/ExternalData/Directory4/DirData4.txt0
-rw-r--r--Tests/RunCMake/ExternalData/Directory5-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/Directory5-stderr.txt14
-rw-r--r--Tests/RunCMake/ExternalData/Directory5.cmake6
-rw-r--r--Tests/RunCMake/ExternalData/LinkContentMD5-stdout.txt3
-rw-r--r--Tests/RunCMake/ExternalData/LinkContentMD5.cmake22
-rw-r--r--Tests/RunCMake/ExternalData/LinkContentSHA1-stdout.txt3
-rw-r--r--Tests/RunCMake/ExternalData/LinkContentSHA1.cmake22
-rw-r--r--Tests/RunCMake/ExternalData/LinkDirectory1-stdout.txt5
-rw-r--r--Tests/RunCMake/ExternalData/LinkDirectory1.cmake37
-rw-r--r--Tests/RunCMake/ExternalData/MissingData-stderr.txt15
-rw-r--r--Tests/RunCMake/ExternalData/MissingData-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/MissingData.cmake10
-rw-r--r--Tests/RunCMake/ExternalData/MissingDataWithAssociated-stderr.txt15
-rw-r--r--Tests/RunCMake/ExternalData/MissingDataWithAssociated-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/MissingDataWithAssociated.cmake10
-rw-r--r--Tests/RunCMake/ExternalData/NoLinkInSource-stderr.txt6
-rw-r--r--Tests/RunCMake/ExternalData/NoLinkInSource-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/NoLinkInSource.cmake14
-rw-r--r--Tests/RunCMake/ExternalData/NoURLTemplates-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/NoURLTemplates-stderr.txt5
-rw-r--r--Tests/RunCMake/ExternalData/NoURLTemplates.cmake2
-rw-r--r--Tests/RunCMake/ExternalData/NormalData1-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/NormalData1.cmake13
-rw-r--r--Tests/RunCMake/ExternalData/NormalData2-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/NormalData2.cmake14
-rw-r--r--Tests/RunCMake/ExternalData/NormalData3-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/NormalData3.cmake14
-rw-r--r--Tests/RunCMake/ExternalData/NormalDataSub1-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/NormalDataSub1.cmake13
-rw-r--r--Tests/RunCMake/ExternalData/NotUnderRoot-result.txt1
-rw-r--r--Tests/RunCMake/ExternalData/NotUnderRoot-stderr.txt12
-rw-r--r--Tests/RunCMake/ExternalData/NotUnderRoot.cmake5
-rw-r--r--Tests/RunCMake/ExternalData/ObjectStoreOnly.cmake3
-rw-r--r--Tests/RunCMake/ExternalData/RunCMakeTest.cmake30
-rw-r--r--Tests/RunCMake/ExternalData/Semicolon1-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/Semicolon1.cmake14
-rw-r--r--Tests/RunCMake/ExternalData/Semicolon2-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/Semicolon2.cmake14
-rw-r--r--Tests/RunCMake/ExternalData/Semicolon3-stdout.txt1
-rw-r--r--Tests/RunCMake/ExternalData/Semicolon3.cmake12
-rw-r--r--Tests/RunCMake/ExternalData/SubDirectory1-stdout.txt3
-rw-r--r--Tests/RunCMake/ExternalData/SubDirectory1.cmake5
-rw-r--r--Tests/RunCMake/ExternalData/SubDirectory1/CMakeLists.txt29
-rw-r--r--Tests/RunCMake/ExternalData/SubDirectory1/Data.txt.md51
-rw-r--r--Tests/RunCMake/FPHSA/BadFoundVar-result.txt1
-rw-r--r--Tests/RunCMake/FPHSA/BadFoundVar-stderr.txt7
-rw-r--r--Tests/RunCMake/FPHSA/BadFoundVar.cmake3
-rw-r--r--Tests/RunCMake/FPHSA/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/FPHSA/FindBadFoundVar.cmake6
-rw-r--r--Tests/RunCMake/FPHSA/FindPseudo.cmake6
-rw-r--r--Tests/RunCMake/FPHSA/RunCMakeTest.cmake28
-rw-r--r--Tests/RunCMake/FPHSA/any_version.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_0-result.txt1
-rw-r--r--Tests/RunCMake/FPHSA/exact_0.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_0_matching.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.1-result.txt1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.1.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.2-result.txt1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.2.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.3.3-result.txt1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.3.3.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.3.4.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.3.5-result.txt1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.3.5.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.3.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.4-result.txt1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.4.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.2.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.3-result.txt1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.3.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_1.cmake1
-rw-r--r--Tests/RunCMake/FPHSA/exact_2-result.txt1
-rw-r--r--Tests/RunCMake/FPHSA/exact_2.cmake1
-rw-r--r--Tests/RunCMake/FeatureSummary/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatAll-stdout.txt7
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatAll.cmake9
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatList-stdout.txt7
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatList.cmake9
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll-result.txt1
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll-stderr.txt6
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll.cmake9
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown-result.txt1
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown-stderr.txt6
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown.cmake9
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingle-stdout.txt1
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingle.cmake9
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown-result.txt1
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown-stderr.txt6
-rw-r--r--Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown.cmake9
-rw-r--r--Tests/RunCMake/FeatureSummary/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/File_Generate/BadCondition-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/BadCondition-stderr.txt3
-rw-r--r--Tests/RunCMake/File_Generate/BadCondition.cmake5
-rw-r--r--Tests/RunCMake/File_Generate/CMakeLists.txt6
-rw-r--r--Tests/RunCMake/File_Generate/CommandConflict-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/CommandConflict-stderr.txt1
-rw-r--r--Tests/RunCMake/File_Generate/CommandConflict.cmake9
-rw-r--r--Tests/RunCMake/File_Generate/DebugEvaluate.cmake5
-rw-r--r--Tests/RunCMake/File_Generate/EmptyCondition1-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/EmptyCondition1-stderr.txt4
-rw-r--r--Tests/RunCMake/File_Generate/EmptyCondition1.cmake5
-rw-r--r--Tests/RunCMake/File_Generate/EmptyCondition2-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/EmptyCondition2-stderr.txt4
-rw-r--r--Tests/RunCMake/File_Generate/EmptyCondition2.cmake5
-rw-r--r--Tests/RunCMake/File_Generate/OutputConflict-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/OutputConflict-stderr.txt5
-rw-r--r--Tests/RunCMake/File_Generate/OutputConflict.cmake4
-rw-r--r--Tests/RunCMake/File_Generate/RunCMakeTest.cmake37
-rw-r--r--Tests/RunCMake/File_Generate/WriteIfDifferent-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/WriteIfDifferent-stderr.txt1
-rw-r--r--Tests/RunCMake/File_Generate/WriteIfDifferent.cmake5
-rw-r--r--Tests/RunCMake/File_Generate/input.txt1
-rw-r--r--Tests/RunCMake/FindPkgConfig/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/FindPkgConfig/FindPkgConfig_NO_PKGCONFIG_PATH.cmake41
-rw-r--r--Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake51
-rw-r--r--Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake51
-rw-r--r--Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake51
-rw-r--r--Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake6
-rwxr-xr-xTests/RunCMake/FindPkgConfig/dummy-pkg-config.bat18
-rwxr-xr-xTests/RunCMake/FindPkgConfig/dummy-pkg-config.sh20
-rw-r--r--Tests/RunCMake/FindPkgConfig/pc-bar/lib/i386-linux-gnu/pkgconfig/.placeholder0
-rw-r--r--Tests/RunCMake/FindPkgConfig/pc-bar/lib/pkgconfig/.placeholder0
-rw-r--r--Tests/RunCMake/FindPkgConfig/pc-bar/lib/x86_64-linux-gnu/pkgconfig/.placeholder0
-rw-r--r--Tests/RunCMake/FindPkgConfig/pc-bar/lib64/pkgconfig/.placeholder0
-rw-r--r--Tests/RunCMake/FindPkgConfig/pc-foo/lib/i386-linux-gnu/pkgconfig/.placeholder0
-rw-r--r--Tests/RunCMake/FindPkgConfig/pc-foo/lib/pkgconfig/.placeholder0
-rw-r--r--Tests/RunCMake/FindPkgConfig/pc-foo/lib/x86_64-linux-gnu/pkgconfig/.placeholder0
-rw-r--r--Tests/RunCMake/FindPkgConfig/pc-foo/lib64/pkgconfig/.placeholder0
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadAND-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadAND-stderr.txt53
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadAND.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadCONFIG-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt35
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake6
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadInstallPrefix-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadInstallPrefix-stderr.txt9
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadInstallPrefix.cmake3
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadNOT-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt52
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadNOT.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadOR-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadOR-stderr.txt53
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadOR.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadStrEqual-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt38
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadStrEqual.cmake6
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadTargetName-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadTargetName-stderr.txt8
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadTargetName.cmake3
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-stderr.txt26
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadTargetTypeObject.cmake7
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadZero-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt17
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadZero.cmake5
-rw-r--r--Tests/RunCMake/GeneratorExpression/CMP0044-WARN-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/CMP0044-WARN-stderr.txt7
-rw-r--r--Tests/RunCMake/GeneratorExpression/CMP0044-WARN.cmake17
-rw-r--r--Tests/RunCMake/GeneratorExpression/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE-stderr.txt8
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE.cmake9
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt9
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt9
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt9
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt9
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE-stderr.txt8
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE.cmake9
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt9
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt11
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake25
-rw-r--r--Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE-check.cmake17
-rw-r--r--Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE-stderr.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE.cmake19
-rw-r--r--Tests/RunCMake/GeneratorExpression/empty.c0
-rw-r--r--Tests/RunCMake/GeneratorPlatform/BadPlatform-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/BadPlatform-stderr.txt10
-rw-r--r--Tests/RunCMake/GeneratorPlatform/BadPlatform-toolchain.cmake1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/BadPlatform.cmake1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain-stderr.txt10
-rw-r--r--Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain.cmake1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/GeneratorPlatform/NoPlatform-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/NoPlatform-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorPlatform/NoPlatform.cmake7
-rw-r--r--Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake28
-rw-r--r--Tests/RunCMake/GeneratorPlatform/TestPlatform-toolchain.cmake1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-stderr.txt9
-rw-r--r--Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain.cmake16
-rw-r--r--Tests/RunCMake/GeneratorPlatform/TwoPlatforms-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/TwoPlatforms-stderr.txt1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/TwoPlatforms.cmake1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/x64Platform-stdout.txt2
-rw-r--r--Tests/RunCMake/GeneratorPlatform/x64Platform.cmake7
-rw-r--r--Tests/RunCMake/GeneratorToolset/BadToolset-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorToolset/BadToolset-stderr.txt10
-rw-r--r--Tests/RunCMake/GeneratorToolset/BadToolset-toolchain.cmake1
-rw-r--r--Tests/RunCMake/GeneratorToolset/BadToolset.cmake1
-rw-r--r--Tests/RunCMake/GeneratorToolset/BadToolsetToolchain-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorToolset/BadToolsetToolchain-stderr.txt10
-rw-r--r--Tests/RunCMake/GeneratorToolset/BadToolsetToolchain.cmake1
-rw-r--r--Tests/RunCMake/GeneratorToolset/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/GeneratorToolset/NoToolset-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorToolset/NoToolset-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorToolset/NoToolset.cmake7
-rw-r--r--Tests/RunCMake/GeneratorToolset/RunCMakeTest.cmake28
-rw-r--r--Tests/RunCMake/GeneratorToolset/TestToolset-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorToolset/TestToolset-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorToolset/TestToolset-toolchain.cmake1
-rw-r--r--Tests/RunCMake/GeneratorToolset/TestToolset.cmake7
-rw-r--r--Tests/RunCMake/GeneratorToolset/TestToolsetToolchain-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorToolset/TestToolsetToolchain-stderr.txt9
-rw-r--r--Tests/RunCMake/GeneratorToolset/TestToolsetToolchain.cmake25
-rw-r--r--Tests/RunCMake/GeneratorToolset/TwoToolsets-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorToolset/TwoToolsets-stderr.txt1
-rw-r--r--Tests/RunCMake/GeneratorToolset/TwoToolsets.cmake1
-rw-r--r--Tests/RunCMake/IncompatibleQt/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/IncompatibleQt/IncompatibleQt-result.txt1
-rw-r--r--Tests/RunCMake/IncompatibleQt/IncompatibleQt-stderr.txt3
-rw-r--r--Tests/RunCMake/IncompatibleQt/IncompatibleQt.cmake6
-rw-r--r--Tests/RunCMake/IncompatibleQt/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/IncompatibleQt/main.cpp8
-rw-r--r--Tests/RunCMake/Languages/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/Languages/LINK_LANGUAGE-genex-result.txt1
-rw-r--r--Tests/RunCMake/Languages/LINK_LANGUAGE-genex-stderr.txt9
-rw-r--r--Tests/RunCMake/Languages/LINK_LANGUAGE-genex.cmake4
-rw-r--r--Tests/RunCMake/Languages/NoLangSHARED-result.txt1
-rw-r--r--Tests/RunCMake/Languages/NoLangSHARED-stderr.txt1
-rw-r--r--Tests/RunCMake/Languages/NoLangSHARED.cmake1
-rw-r--r--Tests/RunCMake/Languages/RunCMakeTest.cmake6
-rw-r--r--Tests/RunCMake/Languages/empty.cpp7
-rw-r--r--Tests/RunCMake/Languages/foo.nolang0
-rw-r--r--Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok-result.txt1
-rw-r--r--Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok.cmake6
-rw-r--r--Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-result.txt1
-rw-r--r--Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-stderr.txt9
-rw-r--r--Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex.cmake4
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt9
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt9
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt8
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt8
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt8
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake2
-rw-r--r--Tests/RunCMake/ObjectLibrary/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/ObjectLibrary/Export-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/Export-stderr.txt4
-rw-r--r--Tests/RunCMake/ObjectLibrary/Export.cmake2
-rw-r--r--Tests/RunCMake/ObjectLibrary/Import-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/Import-stderr.txt4
-rw-r--r--Tests/RunCMake/ObjectLibrary/Import.cmake1
-rw-r--r--Tests/RunCMake/ObjectLibrary/Install-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/Install-stderr.txt4
-rw-r--r--Tests/RunCMake/ObjectLibrary/Install.cmake2
-rw-r--r--Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt4
-rw-r--r--Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake2
-rw-r--r--Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt6
-rw-r--r--Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake3
-rw-r--r--Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt6
-rw-r--r--Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake3
-rw-r--r--Tests/RunCMake/ObjectLibrary/MissingSource-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/MissingSource-stderr.txt9
-rw-r--r--Tests/RunCMake/ObjectLibrary/MissingSource.cmake1
-rw-r--r--Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt4
-rw-r--r--Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake2
-rw-r--r--Tests/RunCMake/ObjectLibrary/PostBuild-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt5
-rw-r--r--Tests/RunCMake/ObjectLibrary/PostBuild.cmake4
-rw-r--r--Tests/RunCMake/ObjectLibrary/PreBuild-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt5
-rw-r--r--Tests/RunCMake/ObjectLibrary/PreBuild.cmake4
-rw-r--r--Tests/RunCMake/ObjectLibrary/PreLink-result.txt1
-rw-r--r--Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt5
-rw-r--r--Tests/RunCMake/ObjectLibrary/PreLink.cmake4
-rw-r--r--Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake18
-rw-r--r--Tests/RunCMake/ObjectLibrary/a.c1
-rw-r--r--Tests/RunCMake/ObjectLibrary/bad.def0
-rw-r--r--Tests/RunCMake/ObjectLibrary/bad.obj0
-rw-r--r--Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN-result.txt1
-rw-r--r--Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN-stderr.txt5
-rw-r--r--Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN.cmake7
-rw-r--r--Tests/RunCMake/ObsoleteQtMacros/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/ObsoleteQtMacros/RunCMakeTest.cmake6
-rw-r--r--Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN-result.txt1
-rw-r--r--Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN-stderr.txt6
-rw-r--r--Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN.cmake7
-rw-r--r--Tests/RunCMake/ObsoleteQtMacros/empty.cpp7
-rw-r--r--Tests/RunCMake/PositionIndependentCode/CMakeLists.txt8
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict1-result.txt1
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict1-stderr.txt3
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict1.cmake7
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict2-result.txt1
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict2-stderr.txt3
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict2.cmake9
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict3-result.txt1
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict3-stderr.txt4
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict3.cmake12
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict4-result.txt1
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict4-stderr.txt4
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict4.cmake8
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict5-result.txt1
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict5-stderr.txt3
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict5.cmake9
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict6-result.txt1
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict6-stderr.txt4
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Conflict6.cmake8
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Debug-result.txt1
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Debug-stderr.txt6
-rw-r--r--Tests/RunCMake/PositionIndependentCode/Debug.cmake8
-rw-r--r--Tests/RunCMake/PositionIndependentCode/RunCMakeTest.cmake9
-rw-r--r--Tests/RunCMake/PositionIndependentCode/main.cpp5
-rw-r--r--Tests/RunCMake/README.rst57
-rw-r--r--Tests/RunCMake/RunCMake.cmake107
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/MorePost-check.cmake5
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/MorePost.cmake2
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/MorePre-check.cmake5
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/MorePre.cmake2
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/OnePost-check.cmake4
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/OnePost.cmake1
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/OnePre-check.cmake4
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/OnePre.cmake1
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/Override1-check.cmake4
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/Override1.cmake2
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/Override2-check.cmake4
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/Override2.cmake2
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/PrePost-check.cmake6
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/PrePost.cmake4
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/RunCMakeTest.cmake10
-rw-r--r--Tests/RunCMake/SolutionGlobalSections/solution_parsing.cmake60
-rw-r--r--Tests/RunCMake/Syntax/.gitattributes3
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariable-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariable.cmake9
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableAtOnly-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableAtOnly.cmake8
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableAtOnlyFile-stderr.txt5
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableAtOnlyFile.cmake9
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableEmptyExpansion-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableEmptyExpansion.cmake8
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableEmptyExpansionAtOnly-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableEmptyExpansionAtOnly.cmake8
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableFile-stderr.txt5
-rw-r--r--Tests/RunCMake/Syntax/AtWithVariableFile.cmake8
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmakebin0 -> 54 bytes
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-16-LE-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmakebin0 -> 54 bytes
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-32-BE-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmakebin0 -> 108 bytes
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-32-LE-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmakebin0 -> 108 bytes
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt1
-rw-r--r--Tests/RunCMake/Syntax/BOM-UTF-8.cmake1
-rw-r--r--Tests/RunCMake/Syntax/Bracket0-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/Bracket0.cmake1
-rw-r--r--Tests/RunCMake/Syntax/Bracket1-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/Bracket1.cmake2
-rw-r--r--Tests/RunCMake/Syntax/Bracket2-stdout.txt2
-rw-r--r--Tests/RunCMake/Syntax/Bracket2.cmake2
-rw-r--r--Tests/RunCMake/Syntax/BracketBackslash-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketBackslash-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BracketBackslash.cmake2
-rw-r--r--Tests/RunCMake/Syntax/BracketCRLF-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketCRLF.cmake8
-rw-r--r--Tests/RunCMake/Syntax/BracketComment0-stdout.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketComment0.cmake5
-rw-r--r--Tests/RunCMake/Syntax/BracketComment1-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketComment1-stderr.txt4
-rw-r--r--Tests/RunCMake/Syntax/BracketComment1.cmake3
-rw-r--r--Tests/RunCMake/Syntax/BracketComment2-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketComment2-stderr.txt4
-rw-r--r--Tests/RunCMake/Syntax/BracketComment2.cmake3
-rw-r--r--Tests/RunCMake/Syntax/BracketComment3-stdout.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketComment3.cmake4
-rw-r--r--Tests/RunCMake/Syntax/BracketComment4-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketComment4-stderr.txt7
-rw-r--r--Tests/RunCMake/Syntax/BracketComment4.cmake3
-rw-r--r--Tests/RunCMake/Syntax/BracketComment5-stdout.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketComment5.cmake11
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace0-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace0.cmake1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace1-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace1.cmake1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace2-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace2.cmake1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace3-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace3.cmake1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace4-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace4.cmake1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace5-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/BracketNoSpace5.cmake1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-At-NEW-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-At-NEW.cmake9
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-At-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-At-OLD.cmake9
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-At-WARN-newlines-stderr.txt27
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-At-WARN-newlines.cmake6
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-At-WARN-stderr.txt21
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-At-WARN.cmake4
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NUL-stderr.txt56
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NUL.cmake6
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn-stderr.txt4
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturnQuoted.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces-stderr.txt4
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpacesQuoted.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs-stderr.txt4
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabsQuoted.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithNewline-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithNewline-stderr.txt4
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithNewline.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithNewlineQuoted.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithSpaces-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithSpaces-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithSpaces.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithTabs-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithTabs-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithTabs.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-ParenInENV-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-ParenInENV.cmake3
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-ParenInQuotedENV-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-ParenInQuotedENV.cmake3
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-WARN-stderr.txt28
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-WARN.cmake5
-rw-r--r--Tests/RunCMake/Syntax/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/Syntax/CommandComments-stderr.txt4
-rw-r--r--Tests/RunCMake/Syntax/CommandComments.cmake6
-rw-r--r--Tests/RunCMake/Syntax/CommandError0-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CommandError0-stderr.txt8
-rw-r--r--Tests/RunCMake/Syntax/CommandError0.cmake2
-rw-r--r--Tests/RunCMake/Syntax/CommandError1-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CommandError1-stderr.txt7
-rw-r--r--Tests/RunCMake/Syntax/CommandError1.cmake1
-rw-r--r--Tests/RunCMake/Syntax/CommandError2-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/CommandError2-stderr.txt7
-rw-r--r--Tests/RunCMake/Syntax/CommandError2.cmake1
-rw-r--r--Tests/RunCMake/Syntax/CommandNewlines-stderr.txt3
-rw-r--r--Tests/RunCMake/Syntax/CommandNewlines.cmake10
-rw-r--r--Tests/RunCMake/Syntax/CommandSpaces-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/CommandSpaces.cmake6
-rw-r--r--Tests/RunCMake/Syntax/CommandTabs-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/CommandTabs.cmake6
-rw-r--r--Tests/RunCMake/Syntax/Escape1-stderr.txt3
-rw-r--r--Tests/RunCMake/Syntax/Escape1.cmake3
-rw-r--r--Tests/RunCMake/Syntax/Escape2-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/Escape2-stderr.txt13
-rw-r--r--Tests/RunCMake/Syntax/Escape2.cmake7
-rw-r--r--Tests/RunCMake/Syntax/EscapeChar-char-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/EscapeChar-char-stderr.txt.in12
-rw-r--r--Tests/RunCMake/Syntax/EscapeChar-char.cmake.in3
-rw-r--r--Tests/RunCMake/Syntax/EscapeCharsAllowed-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/EscapeCharsAllowed.cmake26
-rw-r--r--Tests/RunCMake/Syntax/EscapeCharsDisallowed.cmake42
-rw-r--r--Tests/RunCMake/Syntax/EscapeQuotes-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/EscapeQuotes.cmake9
-rw-r--r--Tests/RunCMake/Syntax/EscapedAt-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/EscapedAt.cmake5
-rw-r--r--Tests/RunCMake/Syntax/ExpandInAt-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/ExpandInAt.cmake6
-rw-r--r--Tests/RunCMake/Syntax/ForEachBracket1-stderr.txt2
-rw-r--r--Tests/RunCMake/Syntax/ForEachBracket1.cmake3
-rw-r--r--Tests/RunCMake/Syntax/FunctionBracket1-stderr.txt2
-rw-r--r--Tests/RunCMake/Syntax/FunctionBracket1.cmake6
-rw-r--r--Tests/RunCMake/Syntax/MacroBracket1-stderr.txt2
-rw-r--r--Tests/RunCMake/Syntax/MacroBracket1.cmake6
-rw-r--r--Tests/RunCMake/Syntax/NameWithCarriageReturn-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithCarriageReturn-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithCarriageReturn.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedSpaces-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedSpaces-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedSpaces.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedTabs-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedTabs-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedTabs.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithNewline-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithNewline-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithNewline.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithNewlineQuoted-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithNewlineQuoted-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithNewlineQuoted.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithSpaces-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithSpaces-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithSpaces.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithSpacesQuoted-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithSpacesQuoted-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithSpacesQuoted.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithTabs-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithTabs-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithTabs.cmake1
-rw-r--r--Tests/RunCMake/Syntax/NameWithTabsQuoted-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/NameWithTabsQuoted-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/NameWithTabsQuoted.cmake1
-rw-r--r--Tests/RunCMake/Syntax/OneLetter-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/OneLetter.cmake7
-rw-r--r--Tests/RunCMake/Syntax/ParenInENV-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/ParenInENV-stderr.txt20
-rw-r--r--Tests/RunCMake/Syntax/ParenInENV.cmake2
-rw-r--r--Tests/RunCMake/Syntax/ParenInQuotedENV-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/ParenInQuotedENV.cmake2
-rw-r--r--Tests/RunCMake/Syntax/ParenInVarName0-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/ParenInVarName0-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/ParenInVarName0.cmake4
-rw-r--r--Tests/RunCMake/Syntax/ParenInVarName1-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/ParenInVarName1-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/ParenInVarName1.cmake4
-rw-r--r--Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt3
-rw-r--r--Tests/RunCMake/Syntax/ParenNoSpace0.cmake3
-rw-r--r--Tests/RunCMake/Syntax/ParenNoSpace1-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt22
-rw-r--r--Tests/RunCMake/Syntax/ParenNoSpace1.cmake3
-rw-r--r--Tests/RunCMake/Syntax/ParenNoSpace2-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/ParenNoSpace2-stdout.txt3
-rw-r--r--Tests/RunCMake/Syntax/ParenNoSpace2.cmake3
-rw-r--r--Tests/RunCMake/Syntax/RunCMakeTest.cmake110
-rw-r--r--Tests/RunCMake/Syntax/String0-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/String0.cmake2
-rw-r--r--Tests/RunCMake/Syntax/String1-stderr.txt3
-rw-r--r--Tests/RunCMake/Syntax/String1.cmake3
-rw-r--r--Tests/RunCMake/Syntax/StringBackslash-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/StringBackslash-stderr.txt6
-rw-r--r--Tests/RunCMake/Syntax/StringBackslash.cmake2
-rw-r--r--Tests/RunCMake/Syntax/StringCRLF-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/StringCRLF.cmake6
-rw-r--r--Tests/RunCMake/Syntax/StringContinuation1-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/StringContinuation1-stderr.txt4
-rw-r--r--Tests/RunCMake/Syntax/StringContinuation1.cmake2
-rw-r--r--Tests/RunCMake/Syntax/StringContinuation2-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/StringContinuation2-stderr.txt4
-rw-r--r--Tests/RunCMake/Syntax/StringContinuation2.cmake2
-rw-r--r--Tests/RunCMake/Syntax/StringNoSpace-stderr.txt19
-rw-r--r--Tests/RunCMake/Syntax/StringNoSpace.cmake4
-rw-r--r--Tests/RunCMake/Syntax/Unquoted0-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/Unquoted0.cmake2
-rw-r--r--Tests/RunCMake/Syntax/Unquoted1-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/Unquoted1.cmake1
-rw-r--r--Tests/RunCMake/Syntax/Unquoted2-stderr.txt1
-rw-r--r--Tests/RunCMake/Syntax/Unquoted2.cmake3
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBrace0-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBrace0-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBrace0.cmake2
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBrace1-stderr.txt13
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBrace1.cmake3
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBrace2-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBrace2-stderr.txt12
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBrace2.cmake4
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBracket0-stderr.txt8
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBracket0.cmake1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBracket1-stderr.txt8
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBracket1.cmake1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBracketComment-stderr.txt8
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake2
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall1-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt7
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall1.cmake1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall2-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt7
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall2.cmake3
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedString-result.txt1
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedString-stderr.txt8
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedString.cmake1
-rw-r--r--Tests/RunCMake/Syntax/atfile.txt.in4
-rw-r--r--Tests/RunCMake/TargetObjects/BadContext-result.txt1
-rw-r--r--Tests/RunCMake/TargetObjects/BadContext-stderr.txt27
-rw-r--r--Tests/RunCMake/TargetObjects/BadContext.cmake7
-rw-r--r--Tests/RunCMake/TargetObjects/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/TargetObjects/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/TargetPolicies/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/TargetPolicies/PolicyList-result.txt1
-rw-r--r--Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt22
-rw-r--r--Tests/RunCMake/TargetPolicies/PolicyList.cmake8
-rw-r--r--Tests/RunCMake/TargetPolicies/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/TargetPolicies/empty.cpp7
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1.cmake7
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2.cmake7
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3.cmake7
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4.cmake9
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-stderr.txt9
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5.cmake7
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6.cmake7
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7.cmake9
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8.cmake7
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget.cmake7
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-stderr.txt6
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1.cmake7
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-stderr.txt6
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2.cmake9
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-stderr.txt6
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3.cmake8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-stderr.txt6
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4.cmake10
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-stderr.txt6
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5.cmake10
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-stderr.txt6
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6.cmake10
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/CMakeLists.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-stderr.txt10
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1.cmake8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-stderr.txt10
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2.cmake8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3-stderr.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3.cmake10
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4.cmake14
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5.cmake10
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6-result.txt1
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6.cmake14
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake23
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/empty.cpp7
-rw-r--r--Tests/RunCMake/TargetSources/CMP0026-LOCATION-result.txt1
-rw-r--r--Tests/RunCMake/TargetSources/CMP0026-LOCATION-stderr.txt1
-rw-r--r--Tests/RunCMake/TargetSources/CMP0026-LOCATION.cmake13
-rw-r--r--Tests/RunCMake/TargetSources/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/TargetSources/ConfigNotAllowed-result.txt1
-rw-r--r--Tests/RunCMake/TargetSources/ConfigNotAllowed-stderr.txt14
-rw-r--r--Tests/RunCMake/TargetSources/ConfigNotAllowed.cmake2
-rw-r--r--Tests/RunCMake/TargetSources/OriginDebug-result.txt1
-rw-r--r--Tests/RunCMake/TargetSources/OriginDebug-stderr.txt31
-rw-r--r--Tests/RunCMake/TargetSources/OriginDebug.cmake20
-rw-r--r--Tests/RunCMake/TargetSources/OriginDebugIDE-result.txt1
-rw-r--r--Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt40
-rw-r--r--Tests/RunCMake/TargetSources/OriginDebugIDE.cmake4
-rw-r--r--Tests/RunCMake/TargetSources/RunCMakeTest.cmake10
-rw-r--r--Tests/RunCMake/TargetSources/empty_1.cpp7
-rw-r--r--Tests/RunCMake/TargetSources/empty_2.cpp7
-rw-r--r--Tests/RunCMake/TargetSources/empty_3.cpp7
-rw-r--r--Tests/RunCMake/TargetSources/empty_4.cpp7
-rw-r--r--Tests/RunCMake/VisibilityPreset/CMakeLists.txt8
-rw-r--r--Tests/RunCMake/VisibilityPreset/PropertyTypo-result.txt1
-rw-r--r--Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt1
-rw-r--r--Tests/RunCMake/VisibilityPreset/PropertyTypo.cmake3
-rw-r--r--Tests/RunCMake/VisibilityPreset/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/VisibilityPreset/lib.cpp5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo.cmake7
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs-stderr.txt11
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs.cmake6
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler-stderr.txt6
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature-stderr.txt6
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion-stderr.txt9
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo.cmake7
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/RunCMakeTest.cmake14
-rw-r--r--Tests/RunCMake/XcodeProject/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/XcodeProject/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/XcodeProject/XcodeFileType-check.cmake10
-rw-r--r--Tests/RunCMake/XcodeProject/XcodeFileType.cmake4
-rw-r--r--Tests/RunCMake/XcodeProject/main.c0
-rw-r--r--Tests/RunCMake/XcodeProject/src-default0
-rw-r--r--Tests/RunCMake/XcodeProject/src-explicit0
-rw-r--r--Tests/RunCMake/XcodeProject/src-lastKnown0
-rw-r--r--Tests/RunCMake/add_dependencies/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/add_dependencies/NoTarget-result.txt1
-rw-r--r--Tests/RunCMake/add_dependencies/NoTarget-stderr.txt9
-rw-r--r--Tests/RunCMake/add_dependencies/NoTarget.cmake1
-rw-r--r--Tests/RunCMake/add_dependencies/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/alias_targets/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/alias_targets/RunCMakeTest.cmake20
-rw-r--r--Tests/RunCMake/alias_targets/add_dependencies-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/add_dependencies-stderr.txt5
-rw-r--r--Tests/RunCMake/alias_targets/add_dependencies.cmake9
-rw-r--r--Tests/RunCMake/alias_targets/add_executable-library-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/add_executable-library-stderr.txt5
-rw-r--r--Tests/RunCMake/alias_targets/add_executable-library.cmake6
-rw-r--r--Tests/RunCMake/alias_targets/add_library-executable-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/add_library-executable-stderr.txt5
-rw-r--r--Tests/RunCMake/alias_targets/add_library-executable.cmake6
-rw-r--r--Tests/RunCMake/alias_targets/alias-target-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/alias-target-stderr.txt5
-rw-r--r--Tests/RunCMake/alias_targets/alias-target.cmake8
-rw-r--r--Tests/RunCMake/alias_targets/empty.cpp7
-rw-r--r--Tests/RunCMake/alias_targets/exclude-from-all-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/exclude-from-all-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/exclude-from-all.cmake6
-rw-r--r--Tests/RunCMake/alias_targets/export-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/export-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/export.cmake8
-rw-r--r--Tests/RunCMake/alias_targets/imported-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/imported-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/imported-target-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/imported-target-stderr.txt5
-rw-r--r--Tests/RunCMake/alias_targets/imported-target.cmake6
-rw-r--r--Tests/RunCMake/alias_targets/imported.cmake2
-rw-r--r--Tests/RunCMake/alias_targets/install-export-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/install-export-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/install-export.cmake9
-rw-r--r--Tests/RunCMake/alias_targets/invalid-name-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/invalid-name-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/invalid-name.cmake6
-rw-r--r--Tests/RunCMake/alias_targets/invalid-target-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/invalid-target-stderr.txt5
-rw-r--r--Tests/RunCMake/alias_targets/invalid-target.cmake2
-rw-r--r--Tests/RunCMake/alias_targets/multiple-targets-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/multiple-targets-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/multiple-targets.cmake7
-rw-r--r--Tests/RunCMake/alias_targets/name-conflict-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/name-conflict-stderr.txt5
-rw-r--r--Tests/RunCMake/alias_targets/name-conflict.cmake8
-rw-r--r--Tests/RunCMake/alias_targets/no-targets-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/no-targets-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/no-targets.cmake4
-rw-r--r--Tests/RunCMake/alias_targets/set_property-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/set_property-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/set_property.cmake8
-rw-r--r--Tests/RunCMake/alias_targets/set_target_properties-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/set_target_properties-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/set_target_properties.cmake8
-rw-r--r--Tests/RunCMake/alias_targets/target_include_directories-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/target_include_directories-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/target_include_directories.cmake8
-rw-r--r--Tests/RunCMake/alias_targets/target_link_libraries-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/target_link_libraries-stderr.txt4
-rw-r--r--Tests/RunCMake/alias_targets/target_link_libraries.cmake9
-rw-r--r--Tests/RunCMake/build_command/BeforeProject-stderr.txt7
-rw-r--r--Tests/RunCMake/build_command/BeforeProject.cmake3
-rw-r--r--Tests/RunCMake/build_command/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/build_command/ErrorsCommon.cmake55
-rw-r--r--Tests/RunCMake/build_command/ErrorsOFF-stderr.txt1
-rw-r--r--Tests/RunCMake/build_command/ErrorsOFF-stdout.txt1
-rw-r--r--Tests/RunCMake/build_command/ErrorsOFF.cmake2
-rw-r--r--Tests/RunCMake/build_command/ErrorsON-result.txt1
-rw-r--r--Tests/RunCMake/build_command/ErrorsON-stderr.txt21
-rw-r--r--Tests/RunCMake/build_command/ErrorsON-stdout.txt1
-rw-r--r--Tests/RunCMake/build_command/ErrorsON.cmake2
-rw-r--r--Tests/RunCMake/build_command/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/cmake_minimum_required/Before24-stderr.txt5
-rw-r--r--Tests/RunCMake/cmake_minimum_required/Before24.cmake1
-rw-r--r--Tests/RunCMake/cmake_minimum_required/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/cmake_minimum_required/CompatBefore24-result.txt1
-rw-r--r--Tests/RunCMake/cmake_minimum_required/CompatBefore24-stderr.txt5
-rw-r--r--Tests/RunCMake/cmake_minimum_required/CompatBefore24.cmake2
-rw-r--r--Tests/RunCMake/cmake_minimum_required/PolicyBefore24-result.txt1
-rw-r--r--Tests/RunCMake/cmake_minimum_required/PolicyBefore24-stderr.txt6
-rw-r--r--Tests/RunCMake/cmake_minimum_required/PolicyBefore24.cmake2
-rw-r--r--Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/configure_file/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/configure_file/NO-BOM.cmake2
-rw-r--r--Tests/RunCMake/configure_file/NO-BOM.txt.in1
-rw-r--r--Tests/RunCMake/configure_file/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/configure_file/UTF16BE-BOM-result.txt1
-rw-r--r--Tests/RunCMake/configure_file/UTF16BE-BOM-stderr.txt6
-rw-r--r--Tests/RunCMake/configure_file/UTF16BE-BOM.cmake2
-rw-r--r--Tests/RunCMake/configure_file/UTF16BE-BOM.txt.inbin0 -> 26 bytes
-rw-r--r--Tests/RunCMake/configure_file/UTF16LE-BOM-result.txt1
-rw-r--r--Tests/RunCMake/configure_file/UTF16LE-BOM-stderr.txt6
-rw-r--r--Tests/RunCMake/configure_file/UTF16LE-BOM.cmake2
-rw-r--r--Tests/RunCMake/configure_file/UTF16LE-BOM.txt.inbin0 -> 26 bytes
-rw-r--r--Tests/RunCMake/configure_file/UTF32BE-BOM-result.txt1
-rw-r--r--Tests/RunCMake/configure_file/UTF32BE-BOM-stderr.txt6
-rw-r--r--Tests/RunCMake/configure_file/UTF32BE-BOM.cmake2
-rw-r--r--Tests/RunCMake/configure_file/UTF32BE-BOM.txt.inbin0 -> 52 bytes
-rw-r--r--Tests/RunCMake/configure_file/UTF32LE-BOM-result.txt1
-rw-r--r--Tests/RunCMake/configure_file/UTF32LE-BOM-stderr.txt6
-rw-r--r--Tests/RunCMake/configure_file/UTF32LE-BOM.cmake2
-rw-r--r--Tests/RunCMake/configure_file/UTF32LE-BOM.txt.inbin0 -> 52 bytes
-rw-r--r--Tests/RunCMake/configure_file/UTF8-BOM.cmake2
-rw-r--r--Tests/RunCMake/configure_file/UTF8-BOM.txt.in1
-rw-r--r--Tests/RunCMake/export/AppendExport-result.txt1
-rw-r--r--Tests/RunCMake/export/AppendExport-stderr.txt4
-rw-r--r--Tests/RunCMake/export/AppendExport.cmake8
-rw-r--r--Tests/RunCMake/export/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/export/NoExportSet-result.txt1
-rw-r--r--Tests/RunCMake/export/NoExportSet-stderr.txt4
-rw-r--r--Tests/RunCMake/export/NoExportSet.cmake2
-rw-r--r--Tests/RunCMake/export/OldIface-result.txt1
-rw-r--r--Tests/RunCMake/export/OldIface-stderr.txt5
-rw-r--r--Tests/RunCMake/export/OldIface.cmake10
-rw-r--r--Tests/RunCMake/export/RunCMakeTest.cmake6
-rw-r--r--Tests/RunCMake/export/TargetNotFound-result.txt1
-rw-r--r--Tests/RunCMake/export/TargetNotFound-stderr.txt4
-rw-r--r--Tests/RunCMake/export/TargetNotFound.cmake1
-rw-r--r--Tests/RunCMake/file/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/file/FileOpenFailRead-result.txt1
-rw-r--r--Tests/RunCMake/file/FileOpenFailRead-stderr.txt6
-rw-r--r--Tests/RunCMake/file/FileOpenFailRead.cmake1
-rw-r--r--Tests/RunCMake/file/INSTALL-DIRECTORY-stdout.txt8
-rw-r--r--Tests/RunCMake/file/INSTALL-DIRECTORY.cmake10
-rw-r--r--Tests/RunCMake/file/INSTALL-MESSAGE-bad-result.txt1
-rw-r--r--Tests/RunCMake/file/INSTALL-MESSAGE-bad-stderr.txt32
-rw-r--r--Tests/RunCMake/file/INSTALL-MESSAGE-bad.cmake6
-rw-r--r--Tests/RunCMake/file/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/file/dir/empty.txt0
-rw-r--r--Tests/RunCMake/find_dependency/CMakeLists.txt4
-rw-r--r--Tests/RunCMake/find_dependency/EXACT-no-version-result.txt1
-rw-r--r--Tests/RunCMake/find_dependency/EXACT-no-version-stderr.txt6
-rw-r--r--Tests/RunCMake/find_dependency/EXACT-no-version.cmake4
-rw-r--r--Tests/RunCMake/find_dependency/Pack1/Pack1Config.cmake2
-rw-r--r--Tests/RunCMake/find_dependency/Pack1/Pack1ConfigVersion.cmake11
-rw-r--r--Tests/RunCMake/find_dependency/RunCMakeTest.cmake7
-rw-r--r--Tests/RunCMake/find_dependency/empty-arg-3-result.txt1
-rw-r--r--Tests/RunCMake/find_dependency/empty-arg-3-stderr.txt5
-rw-r--r--Tests/RunCMake/find_dependency/empty-arg-3.cmake4
-rw-r--r--Tests/RunCMake/find_dependency/empty-version-result.txt1
-rw-r--r--Tests/RunCMake/find_dependency/empty-version-stderr.txt5
-rw-r--r--Tests/RunCMake/find_dependency/empty-version.cmake4
-rw-r--r--Tests/RunCMake/find_dependency/extra-args-result.txt1
-rw-r--r--Tests/RunCMake/find_dependency/extra-args-stderr.txt5
-rw-r--r--Tests/RunCMake/find_dependency/extra-args.cmake4
-rw-r--r--Tests/RunCMake/find_dependency/invalid-arg-3-result.txt1
-rw-r--r--Tests/RunCMake/find_dependency/invalid-arg-3-stderr.txt5
-rw-r--r--Tests/RunCMake/find_dependency/invalid-arg-3.cmake4
-rw-r--r--Tests/RunCMake/find_package/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/find_package/ComponentRequiredAndOptional-result.txt1
-rw-r--r--Tests/RunCMake/find_package/ComponentRequiredAndOptional-stderr.txt8
-rw-r--r--Tests/RunCMake/find_package/ComponentRequiredAndOptional.cmake1
-rw-r--r--Tests/RunCMake/find_package/MissingConfig-stderr.txt19
-rw-r--r--Tests/RunCMake/find_package/MissingConfig.cmake2
-rw-r--r--Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt10
-rw-r--r--Tests/RunCMake/find_package/MissingConfigOneName.cmake1
-rw-r--r--Tests/RunCMake/find_package/MissingConfigRequired-result.txt1
-rw-r--r--Tests/RunCMake/find_package/MissingConfigRequired-stderr.txt13
-rw-r--r--Tests/RunCMake/find_package/MissingConfigRequired.cmake2
-rw-r--r--Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt13
-rw-r--r--Tests/RunCMake/find_package/MissingConfigVersion.cmake1
-rw-r--r--Tests/RunCMake/find_package/MissingModule-stderr.txt26
-rw-r--r--Tests/RunCMake/find_package/MissingModule.cmake2
-rw-r--r--Tests/RunCMake/find_package/MissingModuleRequired-result.txt1
-rw-r--r--Tests/RunCMake/find_package/MissingModuleRequired-stderr.txt21
-rw-r--r--Tests/RunCMake/find_package/MissingModuleRequired.cmake2
-rw-r--r--Tests/RunCMake/find_package/MissingNormal-stderr.txt23
-rw-r--r--Tests/RunCMake/find_package/MissingNormal.cmake2
-rw-r--r--Tests/RunCMake/find_package/MissingNormalRequired-result.txt1
-rw-r--r--Tests/RunCMake/find_package/MissingNormalRequired-stderr.txt17
-rw-r--r--Tests/RunCMake/find_package/MissingNormalRequired.cmake2
-rw-r--r--Tests/RunCMake/find_package/MissingNormalVersion-stderr.txt17
-rw-r--r--Tests/RunCMake/find_package/MissingNormalVersion.cmake1
-rw-r--r--Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew-stderr.txt30
-rw-r--r--Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew.cmake3
-rw-r--r--Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld-stderr.txt29
-rw-r--r--Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld.cmake2
-rw-r--r--Tests/RunCMake/find_package/MixedModeOptions-result.txt1
-rw-r--r--Tests/RunCMake/find_package/MixedModeOptions-stderr.txt14
-rw-r--r--Tests/RunCMake/find_package/MixedModeOptions.cmake1
-rw-r--r--Tests/RunCMake/find_package/RunCMakeTest.cmake16
-rw-r--r--Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt9
-rw-r--r--Tests/RunCMake/find_package/SetFoundFALSE.cmake2
-rw-r--r--Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake1
-rw-r--r--Tests/RunCMake/get_filename_component/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/get_filename_component/KnownComponents.cmake38
-rw-r--r--Tests/RunCMake/get_filename_component/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/get_filename_component/UnknownComponent-result.txt1
-rw-r--r--Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt4
-rw-r--r--Tests/RunCMake/get_filename_component/UnknownComponent.cmake1
-rw-r--r--Tests/RunCMake/if/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/if/IsDirectory-stdout.txt1
-rw-r--r--Tests/RunCMake/if/IsDirectory.cmake5
-rw-r--r--Tests/RunCMake/if/IsDirectoryLong-stdout.txt1
-rw-r--r--Tests/RunCMake/if/IsDirectoryLong.cmake10
-rw-r--r--Tests/RunCMake/if/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/include/CMP0024-NEW-result.txt1
-rw-r--r--Tests/RunCMake/include/CMP0024-NEW-stderr.txt8
-rw-r--r--Tests/RunCMake/include/CMP0024-NEW.cmake9
-rw-r--r--Tests/RunCMake/include/CMP0024-WARN-result.txt1
-rw-r--r--Tests/RunCMake/include/CMP0024-WARN-stderr.txt14
-rw-r--r--Tests/RunCMake/include/CMP0024-WARN.cmake7
-rw-r--r--Tests/RunCMake/include/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/include/EmptyString-stderr.txt5
-rw-r--r--Tests/RunCMake/include/EmptyString.cmake1
-rw-r--r--Tests/RunCMake/include/EmptyStringOptional-stderr.txt5
-rw-r--r--Tests/RunCMake/include/EmptyStringOptional.cmake1
-rw-r--r--Tests/RunCMake/include/ExportExportInclude-result.txt1
-rw-r--r--Tests/RunCMake/include/ExportExportInclude-stderr.txt6
-rw-r--r--Tests/RunCMake/include/ExportExportInclude.cmake6
-rw-r--r--Tests/RunCMake/include/RunCMakeTest.cmake7
-rw-r--r--Tests/RunCMake/include/empty.cpp7
-rw-r--r--Tests/RunCMake/include/subdir1/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/include/subdir2/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-NEW-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-NEW-stderr.txt6
-rw-r--r--Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-OLD-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-WARN-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-WARN-stderr.txt20
-rw-r--r--Tests/RunCMake/include_directories/BinaryDirectoryInInterface-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/BinaryDirectoryInInterface-stderr.txt6
-rw-r--r--Tests/RunCMake/include_directories/BinaryDirectoryInInterface.cmake11
-rw-r--r--Tests/RunCMake/include_directories/CMP0021-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/CMP0021-stderr.txt4
-rw-r--r--Tests/RunCMake/include_directories/CMP0021.cmake9
-rw-r--r--Tests/RunCMake/include_directories/CMakeLists.txt6
-rw-r--r--Tests/RunCMake/include_directories/DebugIncludes-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/DebugIncludes-stderr.txt53
-rw-r--r--Tests/RunCMake/include_directories/DebugIncludes.cmake55
-rw-r--r--Tests/RunCMake/include_directories/DirInInstallPrefix-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/DirInInstallPrefix-stderr.txt1
-rw-r--r--Tests/RunCMake/include_directories/DirInInstallPrefix.cmake9
-rw-r--r--Tests/RunCMake/include_directories/ImportedTarget-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/ImportedTarget-stderr.txt13
-rw-r--r--Tests/RunCMake/include_directories/ImportedTarget.cmake9
-rw-r--r--Tests/RunCMake/include_directories/InstallInBinDir-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/InstallInBinDir-stderr.txt6
-rw-r--r--Tests/RunCMake/include_directories/InstallInSrcDir-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/InstallInSrcDir-stderr.txt6
-rw-r--r--Tests/RunCMake/include_directories/InstallPrefixInInterface-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/InstallPrefixInInterface-stderr.txt1
-rw-r--r--Tests/RunCMake/include_directories/InstallPrefixInInterface.cmake11
-rw-r--r--Tests/RunCMake/include_directories/InstallToPrefixInSrcDirInSource-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/InstallToPrefixInSrcDirInSource-stderr.txt1
-rw-r--r--Tests/RunCMake/include_directories/InstallToPrefixInSrcDirOutOfSource-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/InstallToPrefixInSrcDirOutOfSource-stderr.txt1
-rw-r--r--Tests/RunCMake/include_directories/NotFoundContent-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/NotFoundContent-stderr.txt6
-rw-r--r--Tests/RunCMake/include_directories/NotFoundContent.cmake9
-rw-r--r--Tests/RunCMake/include_directories/RelativePathInGenex-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/RelativePathInGenex-stderr.txt5
-rw-r--r--Tests/RunCMake/include_directories/RelativePathInGenex.cmake8
-rw-r--r--Tests/RunCMake/include_directories/RelativePathInInterface-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/RelativePathInInterface-stderr.txt5
-rw-r--r--Tests/RunCMake/include_directories/RelativePathInInterface.cmake11
-rw-r--r--Tests/RunCMake/include_directories/RunCMakeTest.cmake150
-rw-r--r--Tests/RunCMake/include_directories/SourceDirectoryInInterface-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/SourceDirectoryInInterface-stderr.txt6
-rw-r--r--Tests/RunCMake/include_directories/SourceDirectoryInInterface.cmake11
-rw-r--r--Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-NEW-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-NEW-stderr.txt6
-rw-r--r--Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-OLD-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-OLD-stderr.txt1
-rw-r--r--Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-WARN-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-WARN-stderr.txt20
-rw-r--r--Tests/RunCMake/include_directories/TID-bad-target-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/TID-bad-target-stderr.txt4
-rw-r--r--Tests/RunCMake/include_directories/TID-bad-target.cmake6
-rw-r--r--Tests/RunCMake/include_directories/empty.cpp0
-rw-r--r--Tests/RunCMake/include_directories/export-NOWARN-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/export-NOWARN-stderr.txt1
-rw-r--r--Tests/RunCMake/include_directories/export-NOWARN.cmake62
-rw-r--r--Tests/RunCMake/include_directories/incomplete-genex.cmake23
-rw-r--r--Tests/RunCMake/include_directories/install_config-result.txt1
-rw-r--r--Tests/RunCMake/include_directories/install_config-stderr.txt5
-rw-r--r--Tests/RunCMake/include_directories/install_config.cmake6
-rw-r--r--Tests/RunCMake/include_external_msproject/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomGuid-check.cmake1
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomGuid.cmake2
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform-check.cmake1
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform.cmake5
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomTypePlatform-check.cmake1
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomTypePlatform.cmake3
-rw-r--r--Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake6
-rw-r--r--Tests/RunCMake/include_external_msproject/check_utils.cmake111
-rw-r--r--Tests/RunCMake/include_external_msproject/main.cpp3
-rw-r--r--Tests/RunCMake/install/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/install/DIRECTORY-MESSAGE_NEVER-check.cmake13
-rw-r--r--Tests/RunCMake/install/DIRECTORY-MESSAGE_NEVER.cmake3
-rw-r--r--Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-result.txt1
-rw-r--r--Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-stderr.txt4
-rw-r--r--Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER.cmake1
-rw-r--r--Tests/RunCMake/install/DIRECTORY-message-check.cmake28
-rw-r--r--Tests/RunCMake/install/DIRECTORY-message-lazy-check.cmake24
-rw-r--r--Tests/RunCMake/install/DIRECTORY-message-lazy.cmake3
-rw-r--r--Tests/RunCMake/install/DIRECTORY-message.cmake3
-rw-r--r--Tests/RunCMake/install/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/install/SkipInstallRulesNoWarning1-check.cmake9
-rw-r--r--Tests/RunCMake/install/SkipInstallRulesNoWarning1-stderr.txt1
-rw-r--r--Tests/RunCMake/install/SkipInstallRulesNoWarning1.cmake1
-rw-r--r--Tests/RunCMake/install/SkipInstallRulesNoWarning2-check.cmake9
-rw-r--r--Tests/RunCMake/install/SkipInstallRulesNoWarning2-stderr.txt1
-rw-r--r--Tests/RunCMake/install/SkipInstallRulesNoWarning2.cmake1
-rw-r--r--Tests/RunCMake/install/SkipInstallRulesWarning-check.cmake9
-rw-r--r--Tests/RunCMake/install/SkipInstallRulesWarning-stderr.txt3
-rw-r--r--Tests/RunCMake/install/SkipInstallRulesWarning.cmake2
-rw-r--r--Tests/RunCMake/install/dir/empty.txt0
-rw-r--r--Tests/RunCMake/interface_library/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/interface_library/RunCMakeTest.cmake11
-rw-r--r--Tests/RunCMake/interface_library/add_custom_command-TARGET-result.txt1
-rw-r--r--Tests/RunCMake/interface_library/add_custom_command-TARGET-stderr.txt5
-rw-r--r--Tests/RunCMake/interface_library/add_custom_command-TARGET.cmake6
-rw-r--r--Tests/RunCMake/interface_library/add_dependencies-result.txt1
-rw-r--r--Tests/RunCMake/interface_library/add_dependencies-stderr.txt6
-rw-r--r--Tests/RunCMake/interface_library/add_dependencies.cmake4
-rw-r--r--Tests/RunCMake/interface_library/genex_link-result.txt1
-rw-r--r--Tests/RunCMake/interface_library/genex_link-stderr.txt1
-rw-r--r--Tests/RunCMake/interface_library/genex_link.cmake22
-rw-r--r--Tests/RunCMake/interface_library/global-interface-result.txt1
-rw-r--r--Tests/RunCMake/interface_library/global-interface-stderr.txt9
-rw-r--r--Tests/RunCMake/interface_library/global-interface.cmake2
-rw-r--r--Tests/RunCMake/interface_library/invalid_name-result.txt1
-rw-r--r--Tests/RunCMake/interface_library/invalid_name-stderr.txt15
-rw-r--r--Tests/RunCMake/interface_library/invalid_name.cmake6
-rw-r--r--Tests/RunCMake/interface_library/invalid_signature-result.txt1
-rw-r--r--Tests/RunCMake/interface_library/invalid_signature-stderr.txt89
-rw-r--r--Tests/RunCMake/interface_library/invalid_signature.cmake20
-rw-r--r--Tests/RunCMake/interface_library/no_shared_libs-stderr.txt1
-rw-r--r--Tests/RunCMake/interface_library/no_shared_libs.cmake5
-rw-r--r--Tests/RunCMake/interface_library/target_commands-result.txt1
-rw-r--r--Tests/RunCMake/interface_library/target_commands-stderr.txt47
-rw-r--r--Tests/RunCMake/interface_library/target_commands.cmake13
-rw-r--r--Tests/RunCMake/interface_library/whitelist-result.txt1
-rw-r--r--Tests/RunCMake/interface_library/whitelist-stderr.txt19
-rw-r--r--Tests/RunCMake/interface_library/whitelist.cmake6
-rw-r--r--Tests/RunCMake/list/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/list/EmptyGet0-result.txt1
-rw-r--r--Tests/RunCMake/list/EmptyGet0-stderr.txt4
-rw-r--r--Tests/RunCMake/list/EmptyGet0.cmake2
-rw-r--r--Tests/RunCMake/list/EmptyInsert-1-result.txt1
-rw-r--r--Tests/RunCMake/list/EmptyInsert-1-stderr.txt4
-rw-r--r--Tests/RunCMake/list/EmptyInsert-1.cmake2
-rw-r--r--Tests/RunCMake/list/EmptyRemoveAt0-result.txt1
-rw-r--r--Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt4
-rw-r--r--Tests/RunCMake/list/EmptyRemoveAt0.cmake2
-rw-r--r--Tests/RunCMake/list/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/message/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/message/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/message/errormessage-result.txt1
-rw-r--r--Tests/RunCMake/message/errormessage-stderr.txt4
-rw-r--r--Tests/RunCMake/message/errormessage.cmake4
-rw-r--r--Tests/RunCMake/message/nomessage-result.txt1
-rw-r--r--Tests/RunCMake/message/nomessage-stderr.txt1
-rw-r--r--Tests/RunCMake/message/nomessage.cmake2
-rw-r--r--Tests/RunCMake/message/warnmessage-result.txt1
-rw-r--r--Tests/RunCMake/message/warnmessage-stderr.txt4
-rw-r--r--Tests/RunCMake/message/warnmessage.cmake4
-rw-r--r--Tests/RunCMake/no_install_prefix/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/no_install_prefix/RunCMakeTest.cmake15
-rw-r--r--Tests/RunCMake/no_install_prefix/do_test.cmake2
-rw-r--r--Tests/RunCMake/no_install_prefix/no_install_prefix-result.txt1
-rw-r--r--Tests/RunCMake/no_install_prefix/no_install_prefix-stderr.txt18
-rw-r--r--Tests/RunCMake/no_install_prefix/no_install_prefix.cmake2
-rw-r--r--Tests/RunCMake/no_install_prefix/with_install_prefix-result.txt1
-rw-r--r--Tests/RunCMake/no_install_prefix/with_install_prefix-stderr.txt1
-rw-r--r--Tests/RunCMake/no_install_prefix/with_install_prefix.cmake2
-rw-r--r--Tests/RunCMake/project/CMP0048-NEW-stderr.txt1
-rw-r--r--Tests/RunCMake/project/CMP0048-NEW-stdout.txt30
-rw-r--r--Tests/RunCMake/project/CMP0048-NEW.cmake19
-rw-r--r--Tests/RunCMake/project/CMP0048-OLD-VERSION-result.txt1
-rw-r--r--Tests/RunCMake/project/CMP0048-OLD-VERSION-stderr.txt4
-rw-r--r--Tests/RunCMake/project/CMP0048-OLD-VERSION.cmake2
-rw-r--r--Tests/RunCMake/project/CMP0048-OLD-stdout.txt2
-rw-r--r--Tests/RunCMake/project/CMP0048-OLD.cmake6
-rw-r--r--Tests/RunCMake/project/CMP0048-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/project/CMP0048-WARN.cmake3
-rw-r--r--Tests/RunCMake/project/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/project/LanguagesEmpty-stdout.txt1
-rw-r--r--Tests/RunCMake/project/LanguagesEmpty.cmake3
-rw-r--r--Tests/RunCMake/project/LanguagesImplicit-stdout.txt1
-rw-r--r--Tests/RunCMake/project/LanguagesImplicit.cmake3
-rw-r--r--Tests/RunCMake/project/LanguagesNONE-stdout.txt1
-rw-r--r--Tests/RunCMake/project/LanguagesNONE.cmake3
-rw-r--r--Tests/RunCMake/project/LanguagesTwice-result.txt1
-rw-r--r--Tests/RunCMake/project/LanguagesTwice-stderr.txt4
-rw-r--r--Tests/RunCMake/project/LanguagesTwice.cmake2
-rw-r--r--Tests/RunCMake/project/RunCMakeTest.cmake17
-rw-r--r--Tests/RunCMake/project/VersionAndLanguagesEmpty-stdout.txt2
-rw-r--r--Tests/RunCMake/project/VersionAndLanguagesEmpty.cmake5
-rw-r--r--Tests/RunCMake/project/VersionEmpty-stdout.txt2
-rw-r--r--Tests/RunCMake/project/VersionEmpty.cmake6
-rw-r--r--Tests/RunCMake/project/VersionInvalid-result.txt1
-rw-r--r--Tests/RunCMake/project/VersionInvalid-stderr.txt4
-rw-r--r--Tests/RunCMake/project/VersionInvalid.cmake3
-rw-r--r--Tests/RunCMake/project/VersionMissingLanguages-result.txt1
-rw-r--r--Tests/RunCMake/project/VersionMissingLanguages-stderr.txt4
-rw-r--r--Tests/RunCMake/project/VersionMissingLanguages.cmake3
-rw-r--r--Tests/RunCMake/project/VersionMissingValueOkay-stdout.txt2
-rw-r--r--Tests/RunCMake/project/VersionMissingValueOkay.cmake6
-rw-r--r--Tests/RunCMake/project/VersionTwice-result.txt1
-rw-r--r--Tests/RunCMake/project/VersionTwice-stderr.txt4
-rw-r--r--Tests/RunCMake/project/VersionTwice.cmake3
-rw-r--r--Tests/RunCMake/set/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/set/ParentScope-result.txt1
-rw-r--r--Tests/RunCMake/set/ParentScope.cmake33
-rw-r--r--Tests/RunCMake/set/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/string/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/string/Concat.cmake19
-rw-r--r--Tests/RunCMake/string/ConcatNoArgs-result.txt1
-rw-r--r--Tests/RunCMake/string/ConcatNoArgs-stderr.txt4
-rw-r--r--Tests/RunCMake/string/ConcatNoArgs.cmake1
-rw-r--r--Tests/RunCMake/string/RunCMakeTest.cmake12
-rw-r--r--Tests/RunCMake/string/Uuid.cmake17
-rw-r--r--Tests/RunCMake/string/UuidBadNamespace-result.txt1
-rw-r--r--Tests/RunCMake/string/UuidBadNamespace-stderr.txt4
-rw-r--r--Tests/RunCMake/string/UuidBadNamespace.cmake4
-rw-r--r--Tests/RunCMake/string/UuidBadType-result.txt1
-rw-r--r--Tests/RunCMake/string/UuidBadType-stderr.txt4
-rw-r--r--Tests/RunCMake/string/UuidBadType.cmake4
-rw-r--r--Tests/RunCMake/string/UuidMissingNameValue-result.txt1
-rw-r--r--Tests/RunCMake/string/UuidMissingNameValue-stderr.txt4
-rw-r--r--Tests/RunCMake/string/UuidMissingNameValue.cmake4
-rw-r--r--Tests/RunCMake/string/UuidMissingNamespace-result.txt1
-rw-r--r--Tests/RunCMake/string/UuidMissingNamespace-stderr.txt4
-rw-r--r--Tests/RunCMake/string/UuidMissingNamespace.cmake4
-rw-r--r--Tests/RunCMake/string/UuidMissingNamespaceValue-result.txt1
-rw-r--r--Tests/RunCMake/string/UuidMissingNamespaceValue-stderr.txt4
-rw-r--r--Tests/RunCMake/string/UuidMissingNamespaceValue.cmake4
-rw-r--r--Tests/RunCMake/string/UuidMissingTypeValue-result.txt1
-rw-r--r--Tests/RunCMake/string/UuidMissingTypeValue-stderr.txt4
-rw-r--r--Tests/RunCMake/string/UuidMissingTypeValue.cmake4
-rw-r--r--Tests/RunCMake/target_compile_features/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/target_compile_features/RunCMakeTest.cmake13
-rw-r--r--Tests/RunCMake/target_compile_features/alias_target-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/alias_target-stderr.txt4
-rw-r--r--Tests/RunCMake/target_compile_features/alias_target.cmake4
-rw-r--r--Tests/RunCMake/target_compile_features/empty.c7
-rw-r--r--Tests/RunCMake/target_compile_features/empty.cpp7
-rw-r--r--Tests/RunCMake/target_compile_features/imported_target-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/imported_target-stderr.txt4
-rw-r--r--Tests/RunCMake/target_compile_features/imported_target.cmake3
-rw-r--r--Tests/RunCMake/target_compile_features/invalid_args-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/invalid_args-stderr.txt4
-rw-r--r--Tests/RunCMake/target_compile_features/invalid_args.cmake3
-rw-r--r--Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt5
-rw-r--r--Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake3
-rw-r--r--Tests/RunCMake/target_compile_features/no_matching_c_feature-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/no_matching_c_feature-stderr.txt8
-rw-r--r--Tests/RunCMake/target_compile_features/no_matching_c_feature.cmake15
-rw-r--r--Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt8
-rw-r--r--Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake26
-rw-r--r--Tests/RunCMake/target_compile_features/no_target-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/no_target-stderr.txt5
-rw-r--r--Tests/RunCMake/target_compile_features/no_target.cmake2
-rw-r--r--Tests/RunCMake/target_compile_features/not_a_c_feature-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/not_a_c_feature-stderr.txt5
-rw-r--r--Tests/RunCMake/target_compile_features/not_a_c_feature.cmake6
-rw-r--r--Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt5
-rw-r--r--Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake6
-rw-r--r--Tests/RunCMake/target_compile_features/not_enough_args-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt4
-rw-r--r--Tests/RunCMake/target_compile_features/not_enough_args.cmake3
-rw-r--r--Tests/RunCMake/target_compile_features/utility_target-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/utility_target-stderr.txt4
-rw-r--r--Tests/RunCMake/target_compile_features/utility_target.cmake4
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-result.txt1
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt11
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-NEW-2.cmake11
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-NEW-result.txt1
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt11
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-NEW.cmake11
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-WARN-2-stderr.txt16
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-WARN-2.cmake9
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-WARN-stderr.txt16
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-WARN.cmake9
-rw-r--r--Tests/RunCMake/target_link_libraries/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/target_link_libraries/MixedSignature-result.txt1
-rw-r--r--Tests/RunCMake/target_link_libraries/MixedSignature-stderr.txt5
-rw-r--r--Tests/RunCMake/target_link_libraries/MixedSignature.cmake6
-rw-r--r--Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/target_link_libraries/Separate-PRIVATE-LINK_PRIVATE-uses-result.txt1
-rw-r--r--Tests/RunCMake/target_link_libraries/Separate-PRIVATE-LINK_PRIVATE-uses.cmake9
-rw-r--r--Tests/RunCMake/target_link_libraries/empty.cpp7
-rw-r--r--Tests/RunCMake/target_link_libraries/empty_vs6_1.cpp1
-rw-r--r--Tests/RunCMake/target_link_libraries/empty_vs6_2.cpp1
-rw-r--r--Tests/RunCMake/target_link_libraries/empty_vs6_3.cpp1
-rw-r--r--Tests/RunCMake/try_compile/BadLinkLibraries-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt5
-rw-r--r--Tests/RunCMake/try_compile/BadLinkLibraries.cmake3
-rw-r--r--Tests/RunCMake/try_compile/BadSources1-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/BadSources1-stderr.txt12
-rw-r--r--Tests/RunCMake/try_compile/BadSources1.cmake1
-rw-r--r--Tests/RunCMake/try_compile/BadSources2-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/BadSources2-stderr.txt12
-rw-r--r--Tests/RunCMake/try_compile/BadSources2.cmake5
-rw-r--r--Tests/RunCMake/try_compile/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile.cmake2
-rw-r--r--Tests/RunCMake/try_compile/NoArgs-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/NoArgs-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/NoArgs.cmake1
-rw-r--r--Tests/RunCMake/try_compile/NoCopyFile-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/NoCopyFile-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/NoCopyFile.cmake2
-rw-r--r--Tests/RunCMake/try_compile/NoCopyFile2-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/NoCopyFile2-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/NoCopyFile2.cmake2
-rw-r--r--Tests/RunCMake/try_compile/NoCopyFileError-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/NoCopyFileError-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/NoCopyFileError.cmake2
-rw-r--r--Tests/RunCMake/try_compile/NoOutputVariable-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/NoOutputVariable-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/NoOutputVariable.cmake2
-rw-r--r--Tests/RunCMake/try_compile/NoOutputVariable2-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/NoOutputVariable2-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/NoOutputVariable2.cmake2
-rw-r--r--Tests/RunCMake/try_compile/NoSources-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/NoSources-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/NoSources.cmake1
-rw-r--r--Tests/RunCMake/try_compile/NonSourceCompileDefinitions-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/NonSourceCompileDefinitions-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/NonSourceCompileDefinitions.cmake2
-rw-r--r--Tests/RunCMake/try_compile/NonSourceCopyFile-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/NonSourceCopyFile-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/NonSourceCopyFile.cmake2
-rw-r--r--Tests/RunCMake/try_compile/OneArg-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/OneArg-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/OneArg.cmake1
-rw-r--r--Tests/RunCMake/try_compile/RunCMakeTest.cmake17
-rw-r--r--Tests/RunCMake/try_compile/TwoArgs-result.txt1
-rw-r--r--Tests/RunCMake/try_compile/TwoArgs-stderr.txt4
-rw-r--r--Tests/RunCMake/try_compile/TwoArgs.cmake1
-rw-r--r--Tests/RunCMake/try_compile/proj/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/try_compile/src.c1
-rw-r--r--Tests/RunCMake/variable_watch/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/variable_watch/ModifiedAccess-stderr.txt4
-rw-r--r--Tests/RunCMake/variable_watch/ModifiedAccess.cmake3
-rw-r--r--Tests/RunCMake/variable_watch/NoWatcher-stderr.txt5
-rw-r--r--Tests/RunCMake/variable_watch/NoWatcher.cmake8
-rw-r--r--Tests/RunCMake/variable_watch/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/variable_watch/WatchTwice-stderr.txt2
-rw-r--r--Tests/RunCMake/variable_watch/WatchTwice.cmake11
-rw-r--r--Tests/RuntimePath/CMakeLists.txt33
-rw-r--r--Tests/RuntimePath/bar1.c2
-rw-r--r--Tests/RuntimePath/bar2.c2
-rw-r--r--Tests/RuntimePath/foo1.c1
-rw-r--r--Tests/RuntimePath/foo2.c1
-rw-r--r--Tests/RuntimePath/main.c5
-rw-r--r--Tests/SBCS/CMakeLists.txt6
-rw-r--r--Tests/SBCS/SBCS.cxx22
-rw-r--r--Tests/SameName/CMakeLists.txt7
-rw-r--r--Tests/SameName/Exe1/CMakeLists.txt11
-rw-r--r--Tests/SameName/Exe1/conly.c12
-rw-r--r--Tests/SameName/Lib1/CMakeLists.txt1
-rw-r--r--Tests/SameName/Lib1/libc1.c4
-rw-r--r--Tests/SameName/Lib1/libc1.h1
-rw-r--r--Tests/SetLang/CMakeLists.txt10
-rw-r--r--Tests/SetLang/bar.c21
-rw-r--r--Tests/SetLang/foo.c7
-rw-r--r--Tests/Simple/CMakeLists.txt17
-rw-r--r--Tests/Simple/simple.cxx11
-rw-r--r--Tests/Simple/simpleCLib.c12
-rw-r--r--Tests/Simple/simpleLib.cxx3
-rw-r--r--Tests/Simple/simpleWe.cpp17
-rw-r--r--Tests/SimpleCOnly/CMakeLists.txt17
-rw-r--r--Tests/SimpleCOnly/bar.c1
-rw-r--r--Tests/SimpleCOnly/foo.c1
-rw-r--r--Tests/SimpleCOnly/main.c12
-rw-r--r--Tests/SimpleExclude/CMakeLists.txt11
-rw-r--r--Tests/SimpleExclude/dirC/CMakeLists.txt3
-rw-r--r--Tests/SimpleExclude/dirC/dirA/CMakeLists.txt10
-rw-r--r--Tests/SimpleExclude/dirC/dirA/t1.c8
-rw-r--r--Tests/SimpleExclude/dirC/dirA/t2.c7
-rw-r--r--Tests/SimpleExclude/dirC/dirA/t3.c7
-rw-r--r--Tests/SimpleExclude/dirC/dirA/t4.c17
-rw-r--r--Tests/SimpleExclude/dirC/dirA/t5.c7
-rw-r--r--Tests/SimpleExclude/dirC/dirB/CMakeLists.txt5
-rw-r--r--Tests/SimpleExclude/dirC/dirB/t6.c8
-rw-r--r--Tests/SimpleExclude/dirC/dirB/t7.c16
-rw-r--r--Tests/SimpleExclude/dirD/CMakeLists.txt7
-rw-r--r--Tests/SimpleExclude/dirD/t8.c7
-rw-r--r--Tests/SimpleExclude/dirD/t9.c24
-rw-r--r--Tests/SimpleExclude/run.cmake.in13
-rw-r--r--Tests/SimpleInstall/CMakeLists.txt395
-rw-r--r--Tests/SimpleInstall/InstallScript1.cmake5
-rw-r--r--Tests/SimpleInstall/InstallScript2.cmake14
-rw-r--r--Tests/SimpleInstall/InstallScript3.cmake12
-rw-r--r--Tests/SimpleInstall/InstallScript4.cmake22
-rw-r--r--Tests/SimpleInstall/PackageScript.cmake10
-rw-r--r--Tests/SimpleInstall/PostInstall.cmake6
-rw-r--r--Tests/SimpleInstall/PreInstall.cmake2
-rw-r--r--Tests/SimpleInstall/TestSubDir/CMakeLists.txt3
-rw-r--r--Tests/SimpleInstall/TestSubDir/TSD.cxx10
-rw-r--r--Tests/SimpleInstall/TestSubDir/TSD.h1
-rw-r--r--Tests/SimpleInstall/TestSubDir/TSD_utils.cxx10
-rw-r--r--Tests/SimpleInstall/foo.c6
-rw-r--r--Tests/SimpleInstall/foo.h11
-rw-r--r--Tests/SimpleInstall/inst.cxx37
-rw-r--r--Tests/SimpleInstall/inst2.cxx2
-rw-r--r--Tests/SimpleInstall/lib1.cxx6
-rw-r--r--Tests/SimpleInstall/lib1.h1
-rw-r--r--Tests/SimpleInstall/lib2.cxx6
-rw-r--r--Tests/SimpleInstall/lib2.h11
-rw-r--r--Tests/SimpleInstall/lib3.cxx6
-rw-r--r--Tests/SimpleInstall/lib3.h11
-rw-r--r--Tests/SimpleInstall/lib4.cxx7
-rw-r--r--Tests/SimpleInstall/lib4.h12
-rw-r--r--Tests/SimpleInstall/scripts/.gitattributes1
-rw-r--r--Tests/SimpleInstall/scripts/CMakeLists.txt1
-rwxr-xr-xTests/SimpleInstall/scripts/sample_script2
-rwxr-xr-xTests/SimpleInstall/scripts/sample_script.bat1
-rw-r--r--Tests/SimpleInstallS2/CMakeLists.txt395
-rw-r--r--Tests/SimpleInstallS2/InstallScript1.cmake5
-rw-r--r--Tests/SimpleInstallS2/InstallScript2.cmake14
-rw-r--r--Tests/SimpleInstallS2/InstallScript3.cmake12
-rw-r--r--Tests/SimpleInstallS2/InstallScript4.cmake22
-rw-r--r--Tests/SimpleInstallS2/PackageScript.cmake10
-rw-r--r--Tests/SimpleInstallS2/PostInstall.cmake6
-rw-r--r--Tests/SimpleInstallS2/PreInstall.cmake2
-rw-r--r--Tests/SimpleInstallS2/TestSubDir/CMakeLists.txt3
-rw-r--r--Tests/SimpleInstallS2/TestSubDir/TSD.cxx10
-rw-r--r--Tests/SimpleInstallS2/TestSubDir/TSD.h1
-rw-r--r--Tests/SimpleInstallS2/TestSubDir/TSD_utils.cxx10
-rw-r--r--Tests/SimpleInstallS2/foo.c6
-rw-r--r--Tests/SimpleInstallS2/foo.h11
-rw-r--r--Tests/SimpleInstallS2/inst.cxx37
-rw-r--r--Tests/SimpleInstallS2/inst2.cxx2
-rw-r--r--Tests/SimpleInstallS2/lib1.cxx6
-rw-r--r--Tests/SimpleInstallS2/lib1.h1
-rw-r--r--Tests/SimpleInstallS2/lib2.cxx6
-rw-r--r--Tests/SimpleInstallS2/lib2.h11
-rw-r--r--Tests/SimpleInstallS2/lib3.cxx6
-rw-r--r--Tests/SimpleInstallS2/lib3.h11
-rw-r--r--Tests/SimpleInstallS2/lib4.cxx7
-rw-r--r--Tests/SimpleInstallS2/lib4.h12
-rw-r--r--Tests/SimpleInstallS2/scripts/.gitattributes1
-rw-r--r--Tests/SimpleInstallS2/scripts/CMakeLists.txt1
-rwxr-xr-xTests/SimpleInstallS2/scripts/sample_script2
-rwxr-xr-xTests/SimpleInstallS2/scripts/sample_script.bat1
-rw-r--r--Tests/SourceGroups/CMakeLists.txt35
-rw-r--r--Tests/SourceGroups/README.txt1
-rw-r--r--Tests/SourceGroups/bar.c4
-rw-r--r--Tests/SourceGroups/baz.c4
-rw-r--r--Tests/SourceGroups/foo.c4
-rw-r--r--Tests/SourceGroups/main.c13
-rw-r--r--Tests/SourceGroups/sub1/foo.c4
-rw-r--r--Tests/SourceGroups/sub1/foobar.c4
-rw-r--r--Tests/SourcesProperty/CMakeLists.txt12
-rw-r--r--Tests/SourcesProperty/iface.cpp5
-rw-r--r--Tests/SourcesProperty/iface.h4
-rw-r--r--Tests/SourcesProperty/main.cpp7
-rw-r--r--Tests/SourcesProperty/prop.cpp5
-rw-r--r--Tests/StagingPrefix/CMakeLists.txt91
-rw-r--r--Tests/StagingPrefix/Consumer/CMakeLists.txt22
-rw-r--r--Tests/StagingPrefix/Consumer/cmake/FindBar.cmake6
-rw-r--r--Tests/StagingPrefix/Consumer/main.cpp10
-rw-r--r--Tests/StagingPrefix/Producer/CMakeLists.txt26
-rw-r--r--Tests/StagingPrefix/Producer/bar.cpp7
-rw-r--r--Tests/StagingPrefix/Producer/bar.h10
-rw-r--r--Tests/StagingPrefix/Producer/foo.cpp7
-rw-r--r--Tests/StagingPrefix/Producer/foo.h10
-rw-r--r--Tests/StagingPrefix/main.cpp5
-rw-r--r--Tests/StringFileTest/CMakeLists.txt291
-rw-r--r--Tests/StringFileTest/InputFile.h.in38
-rw-r--r--Tests/StringFileTest/StringFile.cxx31
-rw-r--r--Tests/StringFileTest/main.ihx21
-rw-r--r--Tests/StringFileTest/main.srec21
-rw-r--r--Tests/StringFileTest/test.binbin0 -> 5 bytes
-rw-r--r--Tests/StringFileTest/test.utf83
-rw-r--r--Tests/SubDir/AnotherSubdir/pair+int.int.c6
-rw-r--r--Tests/SubDir/AnotherSubdir/pair_int.int.c6
-rw-r--r--Tests/SubDir/AnotherSubdir/secondone.c6
-rw-r--r--Tests/SubDir/AnotherSubdir/testfromsubdir.c14
-rw-r--r--Tests/SubDir/CMakeLists.txt46
-rw-r--r--Tests/SubDir/Examples/CMakeLists.txt3
-rw-r--r--Tests/SubDir/Examples/example1/CMakeLists.txt7
-rw-r--r--Tests/SubDir/Examples/example1/example1.cxx7
-rw-r--r--Tests/SubDir/Examples/example2/CMakeLists.txt2
-rw-r--r--Tests/SubDir/Examples/example2/example2.cxx7
-rw-r--r--Tests/SubDir/Executable/CMakeLists.txt1
-rw-r--r--Tests/SubDir/Executable/test.cxx49
-rw-r--r--Tests/SubDir/ThirdSubDir/pair+int.int1.c6
-rw-r--r--Tests/SubDir/ThirdSubDir/pair_int.int1.c6
-rw-r--r--Tests/SubDir/ThirdSubDir/pair_p_int.int1.c6
-rw-r--r--Tests/SubDir/ThirdSubDir/testfromauxsubdir.c16
-rw-r--r--Tests/SubDir/ThirdSubDir/thirdone.c6
-rw-r--r--Tests/SubDir/vcl_algorithm+vcl_pair+double.foo.c6
-rw-r--r--Tests/SubDir/vcl_algorithm_vcl_pair_double.foo.c6
-rw-r--r--Tests/SubDirSpaces/Another Subdir/pair+int.int.c6
-rw-r--r--Tests/SubDirSpaces/Another Subdir/pair_int.int.c6
-rw-r--r--Tests/SubDirSpaces/Another Subdir/secondone.c6
-rw-r--r--Tests/SubDirSpaces/Another Subdir/testfromsubdir.c14
-rw-r--r--Tests/SubDirSpaces/CMakeLists.txt77
-rw-r--r--Tests/SubDirSpaces/Executable Sources/CMakeLists.txt1
-rw-r--r--Tests/SubDirSpaces/Executable Sources/test.cxx49
-rw-r--r--Tests/SubDirSpaces/Executable/CMakeLists.txt1
-rw-r--r--Tests/SubDirSpaces/Executable/test.cxx49
-rw-r--r--Tests/SubDirSpaces/Some Examples/CMakeLists.txt3
-rw-r--r--Tests/SubDirSpaces/Some Examples/example1/CMakeLists.txt7
-rw-r--r--Tests/SubDirSpaces/Some Examples/example1/example1.cxx7
-rw-r--r--Tests/SubDirSpaces/Some Examples/example2/CMakeLists.txt2
-rw-r--r--Tests/SubDirSpaces/Some Examples/example2/example2.cxx7
-rw-r--r--Tests/SubDirSpaces/Some(x86) Sources/CMakeLists.txt1
-rw-r--r--Tests/SubDirSpaces/Some(x86) Sources/test.c3
-rw-r--r--Tests/SubDirSpaces/ThirdSubDir/pair+int.int1.c6
-rw-r--r--Tests/SubDirSpaces/ThirdSubDir/pair_int.int1.c6
-rw-r--r--Tests/SubDirSpaces/ThirdSubDir/pair_p_int.int1.c6
-rw-r--r--Tests/SubDirSpaces/ThirdSubDir/testfromauxsubdir.c21
-rw-r--r--Tests/SubDirSpaces/ThirdSubDir/thirdone.c6
-rw-r--r--Tests/SubDirSpaces/vcl_algorithm+vcl_pair+double.foo.c6
-rw-r--r--Tests/SubDirSpaces/vcl_algorithm_vcl_pair_double.foo.c6
-rw-r--r--Tests/SubProject/CMakeLists.txt15
-rw-r--r--Tests/SubProject/bar.cxx1
-rw-r--r--Tests/SubProject/car.cxx6
-rw-r--r--Tests/SubProject/foo/CMakeLists.txt3
-rw-r--r--Tests/SubProject/foo/foo.cxx15
-rw-r--r--Tests/SubProject/gen.cxx.in4
-rw-r--r--Tests/SwigTest/CMakeLists.txt50
-rw-r--r--Tests/SwigTest/example.cxx28
-rw-r--r--Tests/SwigTest/example.h39
-rw-r--r--Tests/SwigTest/example.i10
-rw-r--r--Tests/SwigTest/runme.php458
-rwxr-xr-xTests/SwigTest/runme.pike53
-rw-r--r--Tests/SwigTest/runme.pl57
-rw-r--r--Tests/SwigTest/runme.py51
-rw-r--r--Tests/SwigTest/runme.rb49
-rw-r--r--Tests/SwigTest/runme.tcl50
-rw-r--r--Tests/SwigTest/runme2.tcl70
-rw-r--r--Tests/SystemInformation/CMakeLists.txt59
-rw-r--r--Tests/SystemInformation/DumpInformation.cxx80
-rw-r--r--Tests/SystemInformation/DumpInformation.h.in6
-rw-r--r--Tests/SystemInformation/SystemInformation.in122
-rw-r--r--Tests/TarTest/CMakeLists.txt69
-rw-r--r--Tests/TarTest/TestTarExec.cxx5
-rw-r--r--Tests/TargetName/CMakeLists.txt5
-rw-r--r--Tests/TargetName/executables/CMakeLists.txt1
-rw-r--r--Tests/TargetName/executables/hello_world.c5
-rw-r--r--Tests/TargetName/scripts/.gitattributes1
-rw-r--r--Tests/TargetName/scripts/CMakeLists.txt13
-rwxr-xr-xTests/TargetName/scripts/hello_world2
-rw-r--r--Tests/TestDriver/CMakeLists.txt15
-rw-r--r--Tests/TestDriver/subdir/test3.cxx8
-rw-r--r--Tests/TestDriver/test1.cxx25
-rw-r--r--Tests/TestDriver/test2.cxx8
-rw-r--r--Tests/TestDriver/testArgs.h20
-rw-r--r--Tests/TestDriver/testExtraStuff.cxx4
-rw-r--r--Tests/TestDriver/testExtraStuff2.cxx4
-rw-r--r--Tests/TestDriver/testExtraStuff3.cxx4
-rw-r--r--Tests/Testing/CMakeLists.txt59
-rw-r--r--Tests/Testing/DartConfig.cmake24
-rw-r--r--Tests/Testing/Sub/Sub2/CMakeLists.txt17
-rw-r--r--Tests/Testing/Sub/Sub2/testing2.cxx4
-rw-r--r--Tests/Testing/testing.cxx4
-rw-r--r--Tests/TestsWorkingDirectory/CMakeLists.txt42
-rw-r--r--Tests/TestsWorkingDirectory/main.c64
-rw-r--r--Tests/TestsWorkingDirectory/subdir/CMakeLists.txt31
-rw-r--r--Tests/TryCompile/CMakeLists.txt300
-rw-r--r--Tests/TryCompile/Inner/CMakeLists.txt15
-rw-r--r--Tests/TryCompile/Inner/innerexe.c2
-rw-r--r--Tests/TryCompile/Inner/innerlib.c1
-rw-r--r--Tests/TryCompile/exit_success.c7
-rw-r--r--Tests/TryCompile/exit_with_error.c7
-rw-r--r--Tests/TryCompile/expect_arg.c22
-rw-r--r--Tests/TryCompile/fail.c1
-rw-r--r--Tests/TryCompile/fail2a.c1
-rw-r--r--Tests/TryCompile/fail2b.c1
-rw-r--r--Tests/TryCompile/pass.c6
-rw-r--r--Tests/TryCompile/pass2a.c2
-rw-r--r--Tests/TryCompile/pass2b.cxx1
-rw-r--r--Tests/TryCompile/testdef.c4
-rw-r--r--Tests/Tutorial/Step1/CMakeLists.txt20
-rw-r--r--Tests/Tutorial/Step1/TutorialConfig.h.in4
-rw-r--r--Tests/Tutorial/Step1/tutorial.cxx23
-rw-r--r--Tests/Tutorial/Step2/CMakeLists.txt31
-rw-r--r--Tests/Tutorial/Step2/MathFunctions/CMakeLists.txt1
-rw-r--r--Tests/Tutorial/Step2/MathFunctions/MathFunctions.h1
-rw-r--r--Tests/Tutorial/Step2/MathFunctions/mysqrt.cxx29
-rw-r--r--Tests/Tutorial/Step2/TutorialConfig.h.in5
-rw-r--r--Tests/Tutorial/Step2/tutorial.cxx34
-rw-r--r--Tests/Tutorial/Step3/CMakeLists.txt68
-rw-r--r--Tests/Tutorial/Step3/MathFunctions/CMakeLists.txt4
-rw-r--r--Tests/Tutorial/Step3/MathFunctions/MathFunctions.h1
-rw-r--r--Tests/Tutorial/Step3/MathFunctions/mysqrt.cxx29
-rw-r--r--Tests/Tutorial/Step3/TutorialConfig.h.in5
-rw-r--r--Tests/Tutorial/Step3/tutorial.cxx34
-rw-r--r--Tests/Tutorial/Step4/CMakeLists.txt68
-rw-r--r--Tests/Tutorial/Step4/MathFunctions/CMakeLists.txt4
-rw-r--r--Tests/Tutorial/Step4/MathFunctions/MathFunctions.h1
-rw-r--r--Tests/Tutorial/Step4/MathFunctions/mysqrt.cxx39
-rw-r--r--Tests/Tutorial/Step4/TutorialConfig.h.in9
-rw-r--r--Tests/Tutorial/Step4/tutorial.cxx34
-rw-r--r--Tests/Tutorial/Step5/CMakeLists.txt72
-rw-r--r--Tests/Tutorial/Step5/MathFunctions/CMakeLists.txt17
-rw-r--r--Tests/Tutorial/Step5/MathFunctions/MakeTable.cxx35
-rw-r--r--Tests/Tutorial/Step5/MathFunctions/MathFunctions.h1
-rw-r--r--Tests/Tutorial/Step5/MathFunctions/mysqrt.cxx44
-rw-r--r--Tests/Tutorial/Step5/TutorialConfig.h.in9
-rw-r--r--Tests/Tutorial/Step5/tutorial.cxx34
-rw-r--r--Tests/Tutorial/Step6/CMakeLists.txt78
-rw-r--r--Tests/Tutorial/Step6/License.txt2
-rw-r--r--Tests/Tutorial/Step6/MathFunctions/CMakeLists.txt24
-rw-r--r--Tests/Tutorial/Step6/MathFunctions/MakeTable.cxx35
-rw-r--r--Tests/Tutorial/Step6/MathFunctions/MathFunctions.h1
-rw-r--r--Tests/Tutorial/Step6/MathFunctions/mysqrt.cxx44
-rw-r--r--Tests/Tutorial/Step6/TutorialConfig.h.in9
-rw-r--r--Tests/Tutorial/Step6/tutorial.cxx34
-rw-r--r--Tests/Tutorial/Step7/CMakeLists.txt82
-rw-r--r--Tests/Tutorial/Step7/CTestConfig.cmake1
-rw-r--r--Tests/Tutorial/Step7/License.txt2
-rw-r--r--Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt24
-rw-r--r--Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx35
-rw-r--r--Tests/Tutorial/Step7/MathFunctions/MathFunctions.h1
-rw-r--r--Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx44
-rw-r--r--Tests/Tutorial/Step7/TutorialConfig.h.in9
-rw-r--r--Tests/Tutorial/Step7/build1.cmake5
-rw-r--r--Tests/Tutorial/Step7/build2.cmake9
-rw-r--r--Tests/Tutorial/Step7/tutorial.cxx34
-rw-r--r--Tests/Unset/CMakeLists.txt82
-rw-r--r--Tests/Unset/unset.c4
-rw-r--r--Tests/VSExcludeFromDefaultBuild/CMakeLists.txt32
-rw-r--r--Tests/VSExcludeFromDefaultBuild/ClearExes.cmake4
-rw-r--r--Tests/VSExcludeFromDefaultBuild/ResultTest.cmake23
-rw-r--r--Tests/VSExcludeFromDefaultBuild/main.c4
-rw-r--r--Tests/VSExternalInclude/CMakeLists.txt72
-rw-r--r--Tests/VSExternalInclude/Lib1/CMakeLists.txt6
-rw-r--r--Tests/VSExternalInclude/Lib1/lib1.cpp7
-rw-r--r--Tests/VSExternalInclude/Lib1/lib1.h8
-rw-r--r--Tests/VSExternalInclude/Lib2/CMakeLists.txt8
-rw-r--r--Tests/VSExternalInclude/Lib2/lib2.cpp9
-rw-r--r--Tests/VSExternalInclude/Lib2/lib2.h10
-rw-r--r--Tests/VSExternalInclude/main.cpp9
-rw-r--r--Tests/VSGNUFortran/CMakeLists.txt26
-rw-r--r--Tests/VSGNUFortran/c_code/CMakeLists.txt2
-rw-r--r--Tests/VSGNUFortran/c_code/main.c7
-rw-r--r--Tests/VSGNUFortran/runtest.cmake.in23
-rw-r--r--Tests/VSGNUFortran/subdir/CMakeLists.txt16
-rw-r--r--Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt46
-rw-r--r--Tests/VSGNUFortran/subdir/fortran/hello.f7
-rw-r--r--Tests/VSGNUFortran/subdir/fortran/world.f6
-rw-r--r--Tests/VSMASM/CMakeLists.txt10
-rw-r--r--Tests/VSMASM/foo.asm7
-rw-r--r--Tests/VSMASM/include/foo-proc.asm4
-rw-r--r--Tests/VSMASM/main.c2
-rw-r--r--Tests/VSMidl/CMakeLists.txt81
-rw-r--r--Tests/VSMidl/src/CMakeLists.txt12
-rw-r--r--Tests/VSMidl/src/main.cpp17
-rw-r--r--Tests/VSMidl/src/test.idl30
-rw-r--r--Tests/VSNsightTegra/AndroidManifest.xml16
-rw-r--r--Tests/VSNsightTegra/CMakeLists.txt39
-rw-r--r--Tests/VSNsightTegra/build.xml4
-rw-r--r--Tests/VSNsightTegra/jni/first.c22
-rw-r--r--Tests/VSNsightTegra/jni/first.h22
-rw-r--r--Tests/VSNsightTegra/jni/second.c27
-rw-r--r--Tests/VSNsightTegra/res/values/strings.xml4
-rw-r--r--Tests/VSNsightTegra/src/com/example/twolibs/TwoLibs.java46
-rw-r--r--Tests/VSProjectInSubdir/CMakeLists.txt3
-rw-r--r--Tests/VSProjectInSubdir/subdir/CMakeLists.txt1
-rw-r--r--Tests/VSResource/CMakeLists.txt52
-rw-r--r--Tests/VSResource/include.rc.in1
-rw-r--r--Tests/VSResource/main.cpp80
-rw-r--r--Tests/VSResource/test.rc20
-rw-r--r--Tests/VSResource/test.txt1
-rw-r--r--Tests/VSWinStorePhone/CMakeLists.txt114
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/ApplicationIcon.pngbin0 -> 3392 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Logo.pngbin0 -> 801 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo.pngbin0 -> 329 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/SplashScreen.pngbin0 -> 2146 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/StoreLogo.pngbin0 -> 429 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileLarge.pngbin0 -> 9930 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileMedium.pngbin0 -> 9070 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileSmall.pngbin0 -> 3674 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileMediumLarge.pngbin0 -> 4937 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileSmall.pngbin0 -> 3724 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/BasicTimer.h76
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp260
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.h44
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.cpp153
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.h40
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1_TemporaryKey.pfxbin0 -> 2560 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp384
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.h39
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h45
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.csobin0 -> 12796 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.hlsl10
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.csobin0 -> 16336 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.hlsl35
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/pch.cpp1
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/pch.h7
-rw-r--r--Tests/VSWinStorePhone/cmake/Package_vc11.store.appxmanifest.in24
-rw-r--r--Tests/VSWinStorePhone/cmake/Package_vc11.wp.appxmanifest.in35
-rw-r--r--Tests/VSWinStorePhone/cmake/Package_vc12.store.appxmanifest.in34
-rw-r--r--Tests/VSWinStorePhone/cmake/Package_vc12.wp.appxmanifest.in36
-rw-r--r--Tests/VSWindowsFormsResx/CMakeLists.txt45
-rw-r--r--Tests/VSWindowsFormsResx/WindowsFormsResx/Header.h0
-rw-r--r--Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.cpp1
-rw-r--r--Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.h78
-rw-r--r--Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.resx61
-rw-r--r--Tests/VSWindowsFormsResx/WindowsFormsResx/Source.cpp4
-rw-r--r--Tests/VariableUnusedViaSet/CMakeLists.txt4
-rw-r--r--Tests/VariableUnusedViaUnset/CMakeLists.txt8
-rw-r--r--Tests/VariableUsage/CMakeLists.txt1
-rw-r--r--Tests/VisibilityInlinesHidden/CMakeLists.txt14
-rw-r--r--Tests/VisibilityInlinesHidden/bar.c1
-rw-r--r--Tests/VisibilityInlinesHidden/foo.cpp11
-rw-r--r--Tests/VisibilityInlinesHidden/verify.cmake14
-rw-r--r--Tests/WarnUnusedCliUnused/CMakeLists.txt9
-rw-r--r--Tests/WarnUnusedCliUnused/empty.cpp7
-rw-r--r--Tests/Wrapping/CMakeLists.txt106
-rw-r--r--Tests/Wrapping/Wrap.c23
-rw-r--r--Tests/Wrapping/dummy0
-rw-r--r--Tests/Wrapping/fakefluid.cxx17
-rw-r--r--Tests/Wrapping/fltk1.fl0
-rw-r--r--Tests/Wrapping/foo.ui.in44
-rw-r--r--Tests/Wrapping/hints0
-rw-r--r--Tests/Wrapping/itkWrapperConfig.cxx0
-rw-r--r--Tests/Wrapping/qtnoqtmain.cxx5
-rw-r--r--Tests/Wrapping/qtwrapping.ui44
-rw-r--r--Tests/Wrapping/qtwrappingmain.cxx29
-rw-r--r--Tests/Wrapping/vtkExcluded.cxx0
-rw-r--r--Tests/Wrapping/vtkExcluded.h2
-rw-r--r--Tests/Wrapping/vtkIncluded.cxx0
-rw-r--r--Tests/Wrapping/vtkIncluded.h2
-rw-r--r--Tests/Wrapping/vtkTestMoc.h8
-rw-r--r--Tests/Wrapping/wrapping.cxx4
-rw-r--r--Tests/X11/CMakeLists.txt40
-rw-r--r--Tests/X11/HelloWorldX11.cxx146
-rw-r--r--Tests/X11/X11.c21
-rw-r--r--Tests/bootstrap.bat.in2
-rw-r--r--Tests/iOSNavApp/CMakeLists.txt38
-rw-r--r--Tests/iOSNavApp/Classes/NavApp3AppDelegate.h20
-rw-r--r--Tests/iOSNavApp/Classes/NavApp3AppDelegate.m88
-rw-r--r--Tests/iOSNavApp/Classes/RootViewController.h14
-rw-r--r--Tests/iOSNavApp/Classes/RootViewController.m168
-rw-r--r--Tests/iOSNavApp/Info.plist.in32
-rw-r--r--Tests/iOSNavApp/MainWindow.xib542
-rw-r--r--Tests/iOSNavApp/NavApp3_Prefix.pch14
-rw-r--r--Tests/iOSNavApp/RootViewController.xib384
-rw-r--r--Tests/iOSNavApp/TotalFunction.c14
-rw-r--r--Tests/iOSNavApp/TotalFunction.h14
-rw-r--r--Tests/iOSNavApp/main.m17
-rw-r--r--Tests/test_clean.cmake.in2
-rw-r--r--Utilities/.NoDartCoverage1
-rw-r--r--Utilities/.gitattributes2
-rw-r--r--Utilities/CMakeLists.txt35
-rw-r--r--Utilities/Doxygen/CMakeLists.txt39
-rw-r--r--Utilities/Doxygen/authors.txt17
-rwxr-xr-xUtilities/Doxygen/doc_makeall.sh.in248
-rw-r--r--Utilities/Doxygen/doxyfile.in84
-rwxr-xr-xUtilities/Git/commit-msg23
-rwxr-xr-xUtilities/Git/pre-commit65
-rwxr-xr-xUtilities/Git/prepare-commit-msg15
-rw-r--r--Utilities/GitSetup/.gitattributes7
-rw-r--r--Utilities/GitSetup/LICENSE202
-rw-r--r--Utilities/GitSetup/NOTICE5
-rw-r--r--Utilities/GitSetup/README80
-rw-r--r--Utilities/GitSetup/config9
-rw-r--r--Utilities/GitSetup/config.sample22
-rwxr-xr-xUtilities/GitSetup/setup-gerrit142
-rwxr-xr-xUtilities/GitSetup/setup-hooks63
-rwxr-xr-xUtilities/GitSetup/setup-ssh111
-rwxr-xr-xUtilities/GitSetup/setup-stage79
-rwxr-xr-xUtilities/GitSetup/setup-user39
-rwxr-xr-xUtilities/GitSetup/tips55
-rw-r--r--Utilities/KWIML/ABI.h.in (renamed from ABI.h.in)0
-rw-r--r--Utilities/KWIML/CMakeLists.txt79
-rw-r--r--Utilities/KWIML/Copyright.txt30
-rw-r--r--Utilities/KWIML/INT.h.in (renamed from INT.h.in)0
-rw-r--r--Utilities/KWIML/README.txt (renamed from README.txt)0
-rw-r--r--Utilities/KWIML/test/CMakeLists.txt (renamed from test/CMakeLists.txt)0
-rw-r--r--Utilities/KWIML/test/test.c (renamed from test/test.c)0
-rw-r--r--Utilities/KWIML/test/test.cxx (renamed from test/test.cxx)0
-rw-r--r--Utilities/KWIML/test/test.h (renamed from test/test.h)0
-rw-r--r--Utilities/KWIML/test/test_ABI_C.c (renamed from test/test_ABI_C.c)0
-rw-r--r--Utilities/KWIML/test/test_ABI_CXX.cxx (renamed from test/test_ABI_CXX.cxx)0
-rw-r--r--Utilities/KWIML/test/test_ABI_endian.h.in (renamed from test/test_ABI_endian.h.in)0
-rw-r--r--Utilities/KWIML/test/test_INT_C.c (renamed from test/test_INT_C.c)0
-rw-r--r--Utilities/KWIML/test/test_INT_CXX.cxx (renamed from test/test_INT_CXX.cxx)0
-rw-r--r--Utilities/KWIML/test/test_INT_format.h.in (renamed from test/test_INT_format.h.in)0
-rw-r--r--Utilities/KWIML/test/test_include_C.c (renamed from test/test_include_C.c)0
-rw-r--r--Utilities/KWIML/test/test_include_CXX.cxx (renamed from test/test_include_CXX.cxx)0
-rw-r--r--Utilities/KWStyle/CMake.kws.xml.in11
-rw-r--r--Utilities/KWStyle/CMakeFiles.txt.in15
-rw-r--r--Utilities/KWStyle/CMakeLists.txt78
-rw-r--r--Utilities/KWStyle/CMakeMoreChecks.kws.xml.in30
-rw-r--r--Utilities/KWStyle/CMakeOverwrite.txt0
-rw-r--r--Utilities/KWStyle/Headers/CMakeHeader.h11
-rw-r--r--Utilities/Release/CMakeInstall.bmpbin0 -> 25820 bytes
-rw-r--r--Utilities/Release/CMakeLogo.icobin0 -> 24542 bytes
-rw-r--r--Utilities/Release/Cygwin/CMakeLists.txt25
-rw-r--r--Utilities/Release/Cygwin/README.cygwin.in42
-rwxr-xr-xUtilities/Release/Cygwin/cygwin-package.sh.in90
-rw-r--r--Utilities/Release/Cygwin/cygwin-patch.diff.in0
-rw-r--r--Utilities/Release/Cygwin/cygwin-setup.hint.in5
-rw-r--r--Utilities/Release/README21
-rw-r--r--Utilities/Release/create-cmake-release.cmake78
-rw-r--r--Utilities/Release/dash2win64_cygwin.cmake29
-rw-r--r--Utilities/Release/dash2win64_release.cmake21
-rw-r--r--Utilities/Release/dashmacmini2_release.cmake24
-rw-r--r--Utilities/Release/dashmacmini5_release.cmake26
-rw-r--r--Utilities/Release/hythloth_release.cmake10
-rw-r--r--Utilities/Release/ibm_aix_release.cmake15
-rw-r--r--Utilities/Release/magrathea_release.cmake23
-rw-r--r--Utilities/Release/release_cmake.cmake145
-rwxr-xr-xUtilities/Release/release_cmake.sh.in161
-rw-r--r--Utilities/Release/upload_release.cmake39
-rwxr-xr-xUtilities/SetupForDevelopment.sh13
-rw-r--r--Utilities/Sphinx/.gitignore1
-rw-r--r--Utilities/Sphinx/CMakeLists.txt178
-rw-r--r--Utilities/Sphinx/apply_qthelp_css_workaround.cmake15
-rw-r--r--Utilities/Sphinx/cmake.py339
-rw-r--r--Utilities/Sphinx/conf.py.in67
-rwxr-xr-xUtilities/Sphinx/create_identifiers.py46
-rw-r--r--Utilities/Sphinx/fixup_qthelp_names.cmake32
-rw-r--r--Utilities/Sphinx/static/cmake-favicon.icobin0 -> 1150 bytes
-rw-r--r--Utilities/Sphinx/static/cmake-logo-16.pngbin0 -> 761 bytes
-rw-r--r--Utilities/Sphinx/static/cmake.css8
-rw-r--r--Utilities/Sphinx/templates/layout.html19
-rw-r--r--Utilities/cmThirdParty.h.in24
-rw-r--r--Utilities/cm_bzlib.h23
-rw-r--r--Utilities/cm_curl.h23
-rw-r--r--Utilities/cm_expat.h23
-rw-r--r--Utilities/cm_libarchive.h25
-rw-r--r--Utilities/cm_lzma.h23
-rw-r--r--Utilities/cm_xmlrpc.h22
-rw-r--r--Utilities/cm_zlib.h23
-rw-r--r--Utilities/cmbzip2/CHANGES319
-rw-r--r--Utilities/cmbzip2/CMakeLists.txt4
-rw-r--r--Utilities/cmbzip2/LICENSE42
-rw-r--r--Utilities/cmbzip2/Makefile-libbz2_so59
-rw-r--r--Utilities/cmbzip2/README210
-rw-r--r--Utilities/cmbzip2/README.COMPILATION.PROBLEMS58
-rw-r--r--Utilities/cmbzip2/README.XML.STUFF45
-rw-r--r--Utilities/cmbzip2/blocksort.c1094
-rw-r--r--Utilities/cmbzip2/bz-common.xsl39
-rw-r--r--Utilities/cmbzip2/bz-fo.xsl276
-rw-r--r--Utilities/cmbzip2/bz-html.xsl20
-rw-r--r--Utilities/cmbzip2/bzdiff76
-rw-r--r--Utilities/cmbzip2/bzdiff.147
-rw-r--r--Utilities/cmbzip2/bzgrep75
-rw-r--r--Utilities/cmbzip2/bzgrep.156
-rw-r--r--Utilities/cmbzip2/bzip.css74
-rw-r--r--Utilities/cmbzip2/bzip2.1454
-rw-r--r--Utilities/cmbzip2/bzip2.1.preformatted399
-rw-r--r--Utilities/cmbzip2/bzip2.c2034
-rw-r--r--Utilities/cmbzip2/bzip2.txt391
-rw-r--r--Utilities/cmbzip2/bzip2recover.c514
-rw-r--r--Utilities/cmbzip2/bzlib.c1575
-rw-r--r--Utilities/cmbzip2/bzlib.h282
-rw-r--r--Utilities/cmbzip2/bzlib_private.h526
-rw-r--r--Utilities/cmbzip2/bzmore61
-rw-r--r--Utilities/cmbzip2/bzmore.1152
-rw-r--r--Utilities/cmbzip2/compress.c672
-rw-r--r--Utilities/cmbzip2/crctable.c104
-rw-r--r--Utilities/cmbzip2/decompress.c626
-rw-r--r--Utilities/cmbzip2/dlltest.c175
-rw-r--r--Utilities/cmbzip2/dlltest.dsp93
-rw-r--r--Utilities/cmbzip2/entities.xml9
-rwxr-xr-xUtilities/cmbzip2/format.pl68
-rw-r--r--Utilities/cmbzip2/huffman.c205
-rw-r--r--Utilities/cmbzip2/libbz2.def27
-rw-r--r--Utilities/cmbzip2/libbz2.dsp130
-rw-r--r--Utilities/cmbzip2/libbz2.libbin0 -> 60774 bytes
-rw-r--r--Utilities/cmbzip2/makefile.msc63
-rw-r--r--Utilities/cmbzip2/manual.html2540
-rw-r--r--Utilities/cmbzip2/manual.pdfbin0 -> 289422 bytes
-rw-r--r--Utilities/cmbzip2/manual.ps82900
-rw-r--r--Utilities/cmbzip2/manual.xml2964
-rw-r--r--Utilities/cmbzip2/mk251.c31
-rw-r--r--Utilities/cmbzip2/randtable.c84
-rw-r--r--Utilities/cmbzip2/sample1.rb2bin0 -> 32558 bytes
-rw-r--r--Utilities/cmbzip2/sample1.refbin0 -> 98869 bytes
-rw-r--r--Utilities/cmbzip2/sample1.tstbin0 -> 98869 bytes
-rw-r--r--Utilities/cmbzip2/sample2.rb2bin0 -> 74143 bytes
-rw-r--r--Utilities/cmbzip2/sample2.refbin0 -> 212610 bytes
-rw-r--r--Utilities/cmbzip2/sample2.tstbin0 -> 212610 bytes
-rw-r--r--Utilities/cmbzip2/sample3.rb2bin0 -> 237 bytes
-rw-r--r--Utilities/cmbzip2/sample3.ref30007
-rw-r--r--Utilities/cmbzip2/sample3.tst30007
-rw-r--r--Utilities/cmbzip2/spewG.c54
-rw-r--r--Utilities/cmbzip2/unzcrash.c141
-rw-r--r--Utilities/cmbzip2/words09
-rw-r--r--Utilities/cmbzip2/words14
-rw-r--r--Utilities/cmbzip2/words25
-rw-r--r--Utilities/cmbzip2/words330
-rwxr-xr-xUtilities/cmbzip2/xmlproc.sh114
-rw-r--r--Utilities/cmcompress/CMakeLists.txt5
-rw-r--r--Utilities/cmcompress/Copyright.txt34
-rw-r--r--Utilities/cmcompress/cmcompress.c551
-rw-r--r--Utilities/cmcompress/cmcompress.h195
-rw-r--r--Utilities/cmcompress/compress.c.original1308
-rw-r--r--Utilities/cmcurl/CMake/CMakeConfigurableFile.in2
-rw-r--r--Utilities/cmcurl/CMake/CurlCheckCSourceCompiles.cmake74
-rw-r--r--Utilities/cmcurl/CMake/CurlCheckCSourceRuns.cmake82
-rw-r--r--Utilities/cmcurl/CMake/CurlTests.c526
-rw-r--r--Utilities/cmcurl/CMake/OtherTests.cmake242
-rw-r--r--Utilities/cmcurl/CMakeLists.txt740
-rw-r--r--Utilities/cmcurl/COPYING21
-rw-r--r--Utilities/cmcurl/Platforms/WindowsCache.cmake120
-rw-r--r--Utilities/cmcurl/Platforms/config-aix.h483
-rw-r--r--Utilities/cmcurl/Testing/CMakeLists.txt19
-rw-r--r--Utilities/cmcurl/Testing/curlgtk.c95
-rw-r--r--Utilities/cmcurl/Testing/curltest.c159
-rw-r--r--Utilities/cmcurl/Testing/ftpget.c84
-rw-r--r--Utilities/cmcurl/Testing/ftpgetresp.c64
-rw-r--r--Utilities/cmcurl/Testing/ftpupload.c93
-rw-r--r--Utilities/cmcurl/Testing/getinmemory.c83
-rw-r--r--Utilities/cmcurl/Testing/http-post.c35
-rw-r--r--Utilities/cmcurl/Testing/httpput.c100
-rw-r--r--Utilities/cmcurl/Testing/multithread.c70
-rw-r--r--Utilities/cmcurl/Testing/persistant.c53
-rw-r--r--Utilities/cmcurl/Testing/postit2.c92
-rw-r--r--Utilities/cmcurl/Testing/sepheaders.c80
-rw-r--r--Utilities/cmcurl/Testing/simple.c28
-rw-r--r--Utilities/cmcurl/Testing/simplessl.c120
-rw-r--r--Utilities/cmcurl/Testing/testconfig.h.in7
-rw-r--r--Utilities/cmcurl/Testing/win32sockets.c49
-rw-r--r--Utilities/cmcurl/amigaos.c74
-rw-r--r--Utilities/cmcurl/amigaos.h58
-rw-r--r--Utilities/cmcurl/arpa_telnet.h101
-rw-r--r--Utilities/cmcurl/base64.c366
-rw-r--r--Utilities/cmcurl/base64.h28
-rw-r--r--Utilities/cmcurl/ca-bundle.h1
-rw-r--r--Utilities/cmcurl/config.h.in720
-rw-r--r--Utilities/cmcurl/connect.c905
-rw-r--r--Utilities/cmcurl/connect.h46
-rw-r--r--Utilities/cmcurl/content_encoding.c424
-rw-r--r--Utilities/cmcurl/content_encoding.h41
-rw-r--r--Utilities/cmcurl/cookie.c1019
-rw-r--r--Utilities/cmcurl/cookie.h107
-rw-r--r--Utilities/cmcurl/curl/curl.h1644
-rw-r--r--Utilities/cmcurl/curl/curlver.h56
-rw-r--r--Utilities/cmcurl/curl/easy.h81
-rw-r--r--Utilities/cmcurl/curl/mprintf.h80
-rw-r--r--Utilities/cmcurl/curl/multi.h327
-rw-r--r--Utilities/cmcurl/curl/stdcheaders.h34
-rw-r--r--Utilities/cmcurl/curl/types.h1
-rw-r--r--Utilities/cmcurl/curlx.h107
-rw-r--r--Utilities/cmcurl/dict.c280
-rw-r--r--Utilities/cmcurl/dict.h30
-rw-r--r--Utilities/cmcurl/easy.c895
-rw-r--r--Utilities/cmcurl/easyif.h40
-rw-r--r--Utilities/cmcurl/escape.c181
-rw-r--r--Utilities/cmcurl/escape.h30
-rw-r--r--Utilities/cmcurl/file.c407
-rw-r--r--Utilities/cmcurl/file.h31
-rw-r--r--Utilities/cmcurl/formdata.c1694
-rw-r--r--Utilities/cmcurl/formdata.h97
-rw-r--r--Utilities/cmcurl/ftp.c3865
-rw-r--r--Utilities/cmcurl/ftp.h43
-rw-r--r--Utilities/cmcurl/getenv.c69
-rw-r--r--Utilities/cmcurl/getinfo.c234
-rw-r--r--Utilities/cmcurl/getinfo.h28
-rw-r--r--Utilities/cmcurl/gtls.c640
-rw-r--r--Utilities/cmcurl/gtls.h46
-rw-r--r--Utilities/cmcurl/hash.c315
-rw-r--r--Utilities/cmcurl/hash.h61
-rw-r--r--Utilities/cmcurl/hostares.c307
-rw-r--r--Utilities/cmcurl/hostasyn.c174
-rw-r--r--Utilities/cmcurl/hostip.c636
-rw-r--r--Utilities/cmcurl/hostip.h271
-rw-r--r--Utilities/cmcurl/hostip4.c389
-rw-r--r--Utilities/cmcurl/hostip6.c306
-rw-r--r--Utilities/cmcurl/hostsyn.c138
-rw-r--r--Utilities/cmcurl/hostthre.c840
-rw-r--r--Utilities/cmcurl/http.c2422
-rw-r--r--Utilities/cmcurl/http.h85
-rw-r--r--Utilities/cmcurl/http_chunks.c360
-rw-r--r--Utilities/cmcurl/http_chunks.h104
-rw-r--r--Utilities/cmcurl/http_digest.c504
-rw-r--r--Utilities/cmcurl/http_digest.h58
-rw-r--r--Utilities/cmcurl/http_negotiate.c327
-rw-r--r--Utilities/cmcurl/http_negotiate.h39
-rw-r--r--Utilities/cmcurl/http_ntlm.c1111
-rw-r--r--Utilities/cmcurl/http_ntlm.h146
-rw-r--r--Utilities/cmcurl/if2ip.c134
-rw-r--r--Utilities/cmcurl/if2ip.h67
-rw-r--r--Utilities/cmcurl/inet_ntoa_r.h44
-rw-r--r--Utilities/cmcurl/inet_ntop.c224
-rw-r--r--Utilities/cmcurl/inet_ntop.h37
-rw-r--r--Utilities/cmcurl/inet_pton.c241
-rw-r--r--Utilities/cmcurl/inet_pton.h42
-rw-r--r--Utilities/cmcurl/krb4.c425
-rw-r--r--Utilities/cmcurl/krb4.h70
-rw-r--r--Utilities/cmcurl/ldap.c702
-rw-r--r--Utilities/cmcurl/ldap.h29
-rw-r--r--Utilities/cmcurl/llist.c138
-rw-r--r--Utilities/cmcurl/llist.h60
-rw-r--r--Utilities/cmcurl/md5.c352
-rw-r--r--Utilities/cmcurl/md5.h29
-rw-r--r--Utilities/cmcurl/memdebug.c298
-rw-r--r--Utilities/cmcurl/memdebug.h125
-rw-r--r--Utilities/cmcurl/memory.h50
-rw-r--r--Utilities/cmcurl/mprintf.c1218
-rw-r--r--Utilities/cmcurl/multi.c1988
-rw-r--r--Utilities/cmcurl/multiif.h46
-rw-r--r--Utilities/cmcurl/netrc.c247
-rw-r--r--Utilities/cmcurl/netrc.h34
-rw-r--r--Utilities/cmcurl/nwlib.c300
-rw-r--r--Utilities/cmcurl/parsedate.c425
-rw-r--r--Utilities/cmcurl/parsedate.h28
-rw-r--r--Utilities/cmcurl/progress.c424
-rw-r--r--Utilities/cmcurl/progress.h70
-rw-r--r--Utilities/cmcurl/security.c493
-rw-r--r--Utilities/cmcurl/select.c315
-rw-r--r--Utilities/cmcurl/select.h60
-rw-r--r--Utilities/cmcurl/sendf.c663
-rw-r--r--Utilities/cmcurl/sendf.h72
-rw-r--r--Utilities/cmcurl/setup.h390
-rw-r--r--Utilities/cmcurl/setup_once.h153
-rw-r--r--Utilities/cmcurl/share.c219
-rw-r--r--Utilities/cmcurl/share.h56
-rw-r--r--Utilities/cmcurl/sockaddr.h38
-rw-r--r--Utilities/cmcurl/socks.c592
-rw-r--r--Utilities/cmcurl/socks.h41
-rw-r--r--Utilities/cmcurl/speedcheck.c75
-rw-r--r--Utilities/cmcurl/speedcheck.h34
-rw-r--r--Utilities/cmcurl/splay.c425
-rw-r--r--Utilities/cmcurl/splay.h54
-rw-r--r--Utilities/cmcurl/ssh.c979
-rw-r--r--Utilities/cmcurl/ssh.h49
-rw-r--r--Utilities/cmcurl/sslgen.c618
-rw-r--r--Utilities/cmcurl/sslgen.h84
-rw-r--r--Utilities/cmcurl/ssluse.c1950
-rw-r--r--Utilities/cmcurl/ssluse.h71
-rw-r--r--Utilities/cmcurl/strdup.c46
-rw-r--r--Utilities/cmcurl/strdup.h34
-rw-r--r--Utilities/cmcurl/strequal.c101
-rw-r--r--Utilities/cmcurl/strequal.h38
-rw-r--r--Utilities/cmcurl/strerror.c751
-rw-r--r--Utilities/cmcurl/strerror.h34
-rw-r--r--Utilities/cmcurl/strtok.c68
-rw-r--r--Utilities/cmcurl/strtok.h38
-rw-r--r--Utilities/cmcurl/strtoofft.c165
-rw-r--r--Utilities/cmcurl/strtoofft.h73
-rw-r--r--Utilities/cmcurl/telnet.c1403
-rw-r--r--Utilities/cmcurl/telnet.h30
-rw-r--r--Utilities/cmcurl/tftp.c816
-rw-r--r--Utilities/cmcurl/tftp.h31
-rw-r--r--Utilities/cmcurl/timeval.c116
-rw-r--r--Utilities/cmcurl/timeval.h76
-rw-r--r--Utilities/cmcurl/transfer.c2494
-rw-r--r--Utilities/cmcurl/transfer.h51
-rw-r--r--Utilities/cmcurl/url.c4252
-rw-r--r--Utilities/cmcurl/url.h85
-rw-r--r--Utilities/cmcurl/urldata.h1340
-rw-r--r--Utilities/cmcurl/version.c249
-rw-r--r--Utilities/cmexpat/.NoDartCoverage1
-rw-r--r--Utilities/cmexpat/CMakeLists.txt34
-rw-r--r--Utilities/cmexpat/COPYING21
-rw-r--r--Utilities/cmexpat/ascii.h86
-rw-r--r--Utilities/cmexpat/asciitab.h37
-rw-r--r--Utilities/cmexpat/cm_expat_mangle.h87
-rw-r--r--Utilities/cmexpat/expat.h740
-rw-r--r--Utilities/cmexpat/expatConfig.h.in43
-rw-r--r--Utilities/cmexpat/expatDllConfig.h.in6
-rw-r--r--Utilities/cmexpat/iasciitab.h38
-rw-r--r--Utilities/cmexpat/latin1tab.h37
-rw-r--r--Utilities/cmexpat/nametab.h150
-rw-r--r--Utilities/cmexpat/utf8tab.h38
-rw-r--r--Utilities/cmexpat/xmlparse.c4622
-rw-r--r--Utilities/cmexpat/xmlrole.c1401
-rw-r--r--Utilities/cmexpat/xmlrole.h100
-rw-r--r--Utilities/cmexpat/xmltok.c1584
-rw-r--r--Utilities/cmexpat/xmltok.h299
-rw-r--r--Utilities/cmexpat/xmltok_impl.c1775
-rw-r--r--Utilities/cmexpat/xmltok_impl.h46
-rw-r--r--Utilities/cmexpat/xmltok_ns.c98
-rw-r--r--Utilities/cmlibarchive/.gitattributes1
-rw-r--r--Utilities/cmlibarchive/CMakeLists.txt1334
-rw-r--r--Utilities/cmlibarchive/COPYING60
-rw-r--r--Utilities/cmlibarchive/CTestConfig.cmake11
-rw-r--r--Utilities/cmlibarchive/README-CMake.txt66
-rw-r--r--Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.c14
-rw-r--r--Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.cmake44
-rw-r--r--Utilities/cmlibarchive/build/cmake/CheckFuncs.cmake49
-rw-r--r--Utilities/cmlibarchive/build/cmake/CheckFuncs_stub.c.in16
-rw-r--r--Utilities/cmlibarchive/build/cmake/CheckHeaderDirent.cmake32
-rw-r--r--Utilities/cmlibarchive/build/cmake/CheckStructMember.cmake43
-rw-r--r--Utilities/cmlibarchive/build/cmake/CheckTypeExists.cmake42
-rw-r--r--Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake31
-rw-r--r--Utilities/cmlibarchive/build/cmake/FindLZMA.cmake48
-rw-r--r--Utilities/cmlibarchive/build/cmake/FindLibGCC.cmake22
-rw-r--r--Utilities/cmlibarchive/build/cmake/FindNettle.cmake23
-rw-r--r--Utilities/cmlibarchive/build/cmake/FindPCREPOSIX.cmake34
-rw-r--r--Utilities/cmlibarchive/build/cmake/LibarchiveCodeCoverage.cmake68
-rw-r--r--Utilities/cmlibarchive/build/cmake/config.h.in1157
-rw-r--r--Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in11
-rwxr-xr-xUtilities/cmlibarchive/build/utils/gen_archive_string_composition_h.sh455
-rw-r--r--Utilities/cmlibarchive/build/version1
-rw-r--r--Utilities/cmlibarchive/libarchive/CMakeLists.txt177
-rw-r--r--Utilities/cmlibarchive/libarchive/archive.h1116
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_acl.c1278
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_acl_private.h87
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_check_magic.c175
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_cmdline.c227
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_cmdline_private.h47
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_crc32.h78
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_crypto.c1429
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_crypto_private.h376
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_endian.h196
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry.3150
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry.c1753
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry.h616
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_acl.3235
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_copy_bhfi.c75
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_copy_stat.c79
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_link_resolver.c447
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_linkify.3224
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_locale.h88
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_paths.3153
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_perms.3209
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_private.h181
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_sparse.c156
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_stat.3274
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_stat.c118
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_strmode.c87
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_time.3129
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_xattr.c158
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_getdate.c1038
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_match.c1841
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_options.c211
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_options_private.h47
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_pack_dev.c329
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_pack_dev.h49
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_pathmatch.c459
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_pathmatch.h52
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_platform.h173
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_ppmd7.c1163
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h119
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_ppmd_private.h158
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_private.h152
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_rb.c709
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_rb.h100
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read.3252
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read.c1696
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_append_filter.c198
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_data.3130
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_data_into_fd.c139
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk.3317
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c1240
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c2606
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk_private.h92
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c311
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c2296
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_extract.3137
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_extract.c77
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_extract2.c137
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_filter.3129
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_format.3177
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_free.393
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_header.391
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_new.359
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_open.3233
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_open_fd.c182
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_open_file.c177
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_open_filename.c576
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_open_memory.c187
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_private.h257
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_set_format.c105
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_set_options.3231
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_set_options.c156
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c81
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_bzip2.c371
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c455
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_grzip.c121
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_gzip.c477
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_lrzip.c132
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c487
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_none.c52
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c516
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_rpm.c289
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c694
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c988
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c3862
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c87
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c628
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c74
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c3350
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c1068
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c96
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c3235
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c2750
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c1972
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c2919
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_raw.c190
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c2752
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c3337
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c2176
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_string.c4211
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_string.h239
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_string_composition.h2292
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_string_sprintf.c192
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_util.3224
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_util.c610
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_virtual.c162
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_windows.c908
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_windows.h318
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write.3263
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write.c725
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter.c70
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_b64encode.c314
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c75
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_bzip2.c407
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_compress.c455
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_grzip.c135
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c442
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_lrzip.c197
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_lzop.c486
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_none.c43
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c412
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_uuencode.c305
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c515
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_blocksize.3114
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_data.362
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk.3403
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk_acl.c263
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c3824
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk_private.h43
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c262
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c2502
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_filter.3100
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_finish_entry.376
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_format.3103
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_free.396
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_header.373
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_new.358
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_open.3235
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_open_fd.c144
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_open_file.c109
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_open_filename.c250
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_open_memory.c114
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_private.h145
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format.c77
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c2324
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c564
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c91
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c500
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c458
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_gnutar.c761
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c8148
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c2228
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c1900
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_raw.c125
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_shar.c643
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_ustar.c764
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_v7tar.c661
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c3181
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c1126
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_options.3437
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_options.c130
-rw-r--r--Utilities/cmlibarchive/libarchive/config_freebsd.h160
-rw-r--r--Utilities/cmlibarchive/libarchive/cpio.5325
-rw-r--r--Utilities/cmlibarchive/libarchive/filter_fork.h41
-rw-r--r--Utilities/cmlibarchive/libarchive/filter_fork_posix.c238
-rw-r--r--Utilities/cmlibarchive/libarchive/filter_fork_windows.c190
-rw-r--r--Utilities/cmlibarchive/libarchive/libarchive-formats.5431
-rw-r--r--Utilities/cmlibarchive/libarchive/libarchive.3289
-rw-r--r--Utilities/cmlibarchive/libarchive/libarchive_changes.3341
-rw-r--r--Utilities/cmlibarchive/libarchive/libarchive_internals.3365
-rw-r--r--Utilities/cmlibarchive/libarchive/mtree.5345
-rw-r--r--Utilities/cmlibarchive/libarchive/tar.5947
-rw-r--r--Utilities/cmliblzma/.gitattributes1
-rw-r--r--Utilities/cmliblzma/CMakeLists.txt215
-rw-r--r--Utilities/cmliblzma/COPYING65
-rw-r--r--Utilities/cmliblzma/README-CMake.txt66
-rw-r--r--Utilities/cmliblzma/common/common_w32res.rc50
-rw-r--r--Utilities/cmliblzma/common/sysdefs.h202
-rw-r--r--Utilities/cmliblzma/common/tuklib_integer.h514
-rw-r--r--Utilities/cmliblzma/config.h.in285
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma.h313
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/base.h601
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/bcj.h90
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/block.h530
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/check.h150
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/container.h424
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/delta.h77
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/filter.h424
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/hardware.h50
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/index.h682
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/index_hash.h107
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/lzma.h420
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/stream_flags.h223
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/version.h121
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/vli.h166
-rw-r--r--Utilities/cmliblzma/liblzma/check/check.c174
-rw-r--r--Utilities/cmliblzma/liblzma/check/check.h95
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc32_fast.c86
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc32_small.c61
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc32_table.c19
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc32_table_be.h525
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc32_table_le.h525
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc32_tablegen.c117
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc32_x86.S304
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc64_fast.c74
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc64_small.c53
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc64_table.c19
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc64_table_be.h521
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc64_table_le.h521
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc64_tablegen.c88
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc64_x86.S287
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc_macros.h30
-rw-r--r--Utilities/cmliblzma/liblzma/check/sha256.c204
-rw-r--r--Utilities/cmliblzma/liblzma/common/alone_decoder.c236
-rw-r--r--Utilities/cmliblzma/liblzma/common/alone_decoder.h23
-rw-r--r--Utilities/cmliblzma/liblzma/common/alone_encoder.c155
-rw-r--r--Utilities/cmliblzma/liblzma/common/auto_decoder.c186
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c82
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c315
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_decoder.c242
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_decoder.h22
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_encoder.c217
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_encoder.h47
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_header_decoder.c121
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_header_encoder.c137
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_util.c95
-rw-r--r--Utilities/cmliblzma/liblzma/common/common.c390
-rw-r--r--Utilities/cmliblzma/liblzma/common/common.h305
-rw-r--r--Utilities/cmliblzma/liblzma/common/easy_buffer_encoder.c27
-rw-r--r--Utilities/cmliblzma/liblzma/common/easy_decoder_memusage.c24
-rw-r--r--Utilities/cmliblzma/liblzma/common/easy_encoder.c25
-rw-r--r--Utilities/cmliblzma/liblzma/common/easy_encoder_memusage.c24
-rw-r--r--Utilities/cmliblzma/liblzma/common/easy_preset.c27
-rw-r--r--Utilities/cmliblzma/liblzma/common/easy_preset.h32
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c91
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c57
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_common.c342
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_common.h48
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_decoder.c185
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_decoder.h23
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_encoder.c297
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_encoder.h27
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c48
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c57
-rw-r--r--Utilities/cmliblzma/liblzma/common/hardware_physmem.c25
-rw-r--r--Utilities/cmliblzma/liblzma/common/index.c1276
-rw-r--r--Utilities/cmliblzma/liblzma/common/index.h73
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_decoder.c347
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_encoder.c257
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_encoder.h23
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_hash.c336
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c93
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c140
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_decoder.c459
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_decoder.h21
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_encoder.c338
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_encoder.h23
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_flags_common.c47
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_flags_common.h33
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c86
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c90
-rw-r--r--Utilities/cmliblzma/liblzma/common/vli_decoder.c86
-rw-r--r--Utilities/cmliblzma/liblzma/common/vli_encoder.c69
-rw-r--r--Utilities/cmliblzma/liblzma/common/vli_size.c31
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_common.c72
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_common.h20
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_decoder.c79
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_decoder.h25
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_encoder.c124
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_encoder.h23
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_private.h37
-rw-r--r--Utilities/cmliblzma/liblzma/liblzma.pc.in19
-rw-r--r--Utilities/cmliblzma/liblzma/liblzma_w32res.rc14
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_decoder.c307
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_decoder.h236
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_encoder.c594
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_encoder.h328
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h105
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_encoder_hash_table.h68
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c814
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/fastpos.h142
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/fastpos_table.c519
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/fastpos_tablegen.c56
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c305
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h28
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.c399
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.h41
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_common.h226
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c1075
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_decoder.h52
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder.c695
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder.h54
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_fast.c185
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_normal.c925
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder_presets.c63
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h148
-rw-r--r--Utilities/cmliblzma/liblzma/rangecoder/price.h92
-rw-r--r--Utilities/cmliblzma/liblzma/rangecoder/price_table.c22
-rw-r--r--Utilities/cmliblzma/liblzma/rangecoder/price_tablegen.c87
-rw-r--r--Utilities/cmliblzma/liblzma/rangecoder/range_common.h74
-rw-r--r--Utilities/cmliblzma/liblzma/rangecoder/range_decoder.h179
-rw-r--r--Utilities/cmliblzma/liblzma/rangecoder/range_encoder.h232
-rw-r--r--Utilities/cmliblzma/liblzma/simple/arm.c69
-rw-r--r--Utilities/cmliblzma/liblzma/simple/armthumb.c74
-rw-r--r--Utilities/cmliblzma/liblzma/simple/ia64.c116
-rw-r--r--Utilities/cmliblzma/liblzma/simple/powerpc.c73
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_coder.c283
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_coder.h60
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_decoder.c41
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_decoder.h22
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_encoder.c38
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_encoder.h23
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_private.h75
-rw-r--r--Utilities/cmliblzma/liblzma/simple/sparc.c82
-rw-r--r--Utilities/cmliblzma/liblzma/simple/x86.c161
-rw-r--r--Utilities/cmzlib/.NoDartCoverage1
-rw-r--r--Utilities/cmzlib/CMakeLists.txt43
-rw-r--r--Utilities/cmzlib/ChangeLog855
-rw-r--r--Utilities/cmzlib/Copyright.txt23
-rw-r--r--Utilities/cmzlib/FAQ339
-rw-r--r--Utilities/cmzlib/INDEX51
-rw-r--r--Utilities/cmzlib/README125
-rw-r--r--Utilities/cmzlib/README.Kitware.txt40
-rw-r--r--Utilities/cmzlib/adler32.c149
-rw-r--r--Utilities/cmzlib/cm_zlib_mangle.h93
-rw-r--r--Utilities/cmzlib/compress.c79
-rw-r--r--Utilities/cmzlib/crc32.c423
-rw-r--r--Utilities/cmzlib/crc32.h441
-rw-r--r--Utilities/cmzlib/deflate.c1743
-rw-r--r--Utilities/cmzlib/deflate.h331
-rw-r--r--Utilities/cmzlib/gzio.c1026
-rw-r--r--Utilities/cmzlib/inffast.c318
-rw-r--r--Utilities/cmzlib/inffast.h11
-rw-r--r--Utilities/cmzlib/inffixed.h94
-rw-r--r--Utilities/cmzlib/inflate.c1368
-rw-r--r--Utilities/cmzlib/inflate.h115
-rw-r--r--Utilities/cmzlib/inftrees.c329
-rw-r--r--Utilities/cmzlib/inftrees.h55
-rw-r--r--Utilities/cmzlib/trees.c1219
-rw-r--r--Utilities/cmzlib/trees.h128
-rw-r--r--Utilities/cmzlib/uncompr.c61
-rw-r--r--Utilities/cmzlib/zconf.h351
-rw-r--r--Utilities/cmzlib/zlib.def47
-rw-r--r--Utilities/cmzlib/zlib.h1357
-rw-r--r--Utilities/cmzlib/zlib.rc32
-rw-r--r--Utilities/cmzlib/zlibDllConfig.h.in6
-rw-r--r--Utilities/cmzlib/zutil.c318
-rw-r--r--Utilities/cmzlib/zutil.h269
-rwxr-xr-xbootstrap1704
-rw-r--r--cmake_uninstall.cmake.in22
-rwxr-xr-xconfigure3
-rw-r--r--doxygen.config697
7508 files changed, 819699 insertions, 59 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000000..d3f7280e25
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,24 @@
+.gitattributes export-ignore
+.hooks* export-ignore
+
+bootstrap crlf=input
+configure crlf=input
+*.[1-9] crlf=input
+*.sh crlf=input
+*.sh.in crlf=input
+
+*.bat -crlf
+*.bat.in -crlf
+*.dsp -crlf
+*.dsptemplate -crlf
+*.dsw -crlf
+*.pfx -crlf
+*.png -crlf
+*.sln -crlf
+*.vcproj -crlf
+
+*.c whitespace=tab-in-indent
+*.h whitespace=tab-in-indent
+*.cxx whitespace=tab-in-indent
+*.txt whitespace=tab-in-indent
+*.cmake whitespace=tab-in-indent
diff --git a/.hooks-config.bash b/.hooks-config.bash
new file mode 100644
index 0000000000..97152f6519
--- /dev/null
+++ b/.hooks-config.bash
@@ -0,0 +1,18 @@
+#=============================================================================
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2011 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.
+#=============================================================================
+
+# Loaded by .git/hooks/(pre-commit|commit-msg|prepare-commit-msg)
+# during git commit after local hooks have been installed.
+
+hooks_chain_pre_commit="Utilities/Git/pre-commit"
+hooks_chain_commit_msg="Utilities/Git/commit-msg"
+hooks_chain_prepare_commit_msg="Utilities/Git/prepare-commit-msg"
diff --git a/Auxiliary/CMakeLists.txt b/Auxiliary/CMakeLists.txt
new file mode 100644
index 0000000000..c003b28e71
--- /dev/null
+++ b/Auxiliary/CMakeLists.txt
@@ -0,0 +1,4 @@
+install(FILES cmake-help.vim cmake-indent.vim cmake-syntax.vim DESTINATION ${CMAKE_DATA_DIR}/editors/vim)
+install(FILES cmake-mode.el DESTINATION ${CMAKE_DATA_DIR}/editors/emacs)
+install(FILES cmake.m4 DESTINATION share/aclocal)
+add_subdirectory (bash-completion)
diff --git a/Auxiliary/bash-completion/CMakeLists.txt b/Auxiliary/bash-completion/CMakeLists.txt
new file mode 100644
index 0000000000..c0a88999ec
--- /dev/null
+++ b/Auxiliary/bash-completion/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Always install completion file in local dir
+# in order to be sure to always be able to install
+# in a local user directory rooted in a single directory.
+# packager should either patch that out or
+# add symlinks to the files in appropriate places
+# /etc/bash_completion.d/
+# DATADIR/completions (may be /usr/share/<package>/completions
+install(FILES cmake cpack ctest DESTINATION ${CMAKE_DATA_DIR}/completions)
diff --git a/Auxiliary/bash-completion/cmake b/Auxiliary/bash-completion/cmake
new file mode 100644
index 0000000000..59e02987b5
--- /dev/null
+++ b/Auxiliary/bash-completion/cmake
@@ -0,0 +1,151 @@
+# bash completion for cmake(1) -*- shell-script -*-
+
+_cmake()
+{
+ local cur prev words cword split=false
+ _init_completion -n := || return
+
+ # Workaround for options like -DCMAKE_BUILD_TYPE=Release
+ local prefix=
+ if [[ $cur == -D* ]]; then
+ prev=-D
+ prefix=-D
+ cur="${cur#-D}"
+ elif [[ $cur == -U* ]]; then
+ prev=-U
+ prefix=-U
+ cur="${cur#-U}"
+ fi
+
+ case "$prev" in
+ -D)
+ if [[ $cur == *=* ]]; then
+ # complete values for variables
+ local var type value
+ var="${cur%%[:=]*}"
+ value="${cur#*=}"
+
+ if [[ $cur == CMAKE_BUILD_TYPE* ]]; then # most widely used case
+ COMPREPLY=( $( compgen -W 'Debug Release RelWithDebInfo
+ MinSizeRel' -- "$value" ) )
+ return
+ fi
+
+ if [[ $cur == *:* ]]; then
+ type="${cur#*:}"
+ type="${type%%=*}"
+ else # get type from cache if it's not set explicitly
+ type=$( cmake -LA -N 2>/dev/null | grep "$var:" \
+ 2>/dev/null )
+ type="${type#*:}"
+ type="${type%%=*}"
+ fi
+ case "$type" in
+ FILEPATH)
+ cur="$value"
+ _filedir
+ return
+ ;;
+ PATH)
+ cur="$value"
+ _filedir -d
+ return
+ ;;
+ BOOL)
+ COMPREPLY=( $( compgen -W 'ON OFF TRUE FALSE' -- \
+ "$value" ) )
+ return
+ ;;
+ STRING|INTERNAL)
+ # no completion available
+ return
+ ;;
+ esac
+ elif [[ $cur == *:* ]]; then
+ # complete types
+ local type="${cur#*:}"
+ COMPREPLY=( $( compgen -W 'FILEPATH PATH STRING BOOL INTERNAL'\
+ -S = -- "$type" ) )
+ compopt -o nospace
+ else
+ # complete variable names
+ COMPREPLY=( $( compgen -W '$( cmake -LA -N | tail -n +2 |
+ cut -f1 -d: )' -P "$prefix" -- "$cur" ) )
+ compopt -o nospace
+ fi
+ return
+ ;;
+ -U)
+ COMPREPLY=( $( compgen -W '$( cmake -LA -N | tail -n +2 |
+ cut -f1 -d: )' -P "$prefix" -- "$cur" ) )
+ return
+ ;;
+ esac
+
+ _split_longopt && split=true
+
+ case "$prev" in
+ -C|-P|--graphviz|--system-information)
+ _filedir
+ return
+ ;;
+ --build)
+ _filedir -d
+ return
+ ;;
+ -E)
+ COMPREPLY=( $( compgen -W "$( cmake -E help |& sed -n \
+ '/^ /{s|^ \([^ ]\{1,\}\) .*$|\1|;p}' 2>/dev/null )" \
+ -- "$cur" ) )
+ return
+ ;;
+ -G)
+ local IFS=$'\n'
+ local quoted
+ printf -v quoted %q "$cur"
+ COMPREPLY=( $( compgen -W '$( cmake --help 2>/dev/null | sed -n \
+ -e "1,/^Generators/d" \
+ -e "/^ *[^ =]/{s|^ *\([^=]*[^ =]\).*$|\1|;s| |\\\\ |g;p}" \
+ 2>/dev/null )' -- "$quoted" ) )
+ return
+ ;;
+ --help-command)
+ COMPREPLY=( $( compgen -W '$( cmake --help-command-list 2>/dev/null|
+ grep -v "^cmake version " )' -- "$cur" ) )
+ return
+ ;;
+ --help-module)
+ COMPREPLY=( $( compgen -W '$( cmake --help-module-list 2>/dev/null|
+ grep -v "^cmake version " )' -- "$cur" ) )
+ return
+ ;;
+ --help-policy)
+ COMPREPLY=( $( compgen -W '$( cmake --help-policies 2>/dev/null |
+ grep "^ CMP" 2>/dev/null )' -- "$cur" ) )
+ return
+ ;;
+ --help-property)
+ COMPREPLY=( $( compgen -W '$( cmake --help-property-list \
+ 2>/dev/null | grep -v "^cmake version " )' -- "$cur" ) )
+ return
+ ;;
+ --help-variable)
+ COMPREPLY=( $( compgen -W '$( cmake --help-variable-list \
+ 2>/dev/null | grep -v "^cmake version " )' -- "$cur" ) )
+ return
+ ;;
+ esac
+
+ $split && return
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $(compgen -W '$( _parse_help "$1" --help )' -- ${cur}) )
+ [[ $COMPREPLY == *= ]] && compopt -o nospace
+ [[ $COMPREPLY ]] && return
+ fi
+
+ _filedir
+} &&
+complete -F _cmake cmake
+
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/Auxiliary/bash-completion/cpack b/Auxiliary/bash-completion/cpack
new file mode 100644
index 0000000000..9ab6048398
--- /dev/null
+++ b/Auxiliary/bash-completion/cpack
@@ -0,0 +1,61 @@
+# bash completion for cpack(1) -*- shell-script -*-
+
+_cpack()
+{
+ local cur prev words cword
+ _init_completion -n = || return
+
+ case "$prev" in
+ -G)
+ COMPREPLY=( $( compgen -W '$( cpack --help 2>/dev/null |
+ sed -e "1,/^Generators/d" -e "s|^ *\([^ ]*\) .*$|\1|" \
+ 2>/dev/null )' -- "$cur" ) )
+ return
+ ;;
+ -C)
+ COMPREPLY=( $( compgen -W 'Debug Release RelWithDebInfo
+ MinSizeRel' -- "$cur" ) )
+ return
+ ;;
+ -D)
+ [[ $cur == *=* ]] && return # no completion for values
+ COMPREPLY=( $( compgen -W '$( cpack --help-variable-list \
+ 2>/dev/null | grep -v "^cpack version " )' -S = -- "$cur" ) )
+ compopt -o nospace
+ return
+ ;;
+ -P|-R|--vendor)
+ # argument required but no completions available
+ return
+ ;;
+ -B)
+ _filedir -d
+ return
+ ;;
+ --config)
+ _filedir
+ return
+ ;;
+ --help-command)
+ COMPREPLY=( $( compgen -W '$( cpack --help-command-list 2>/dev/null|
+ grep -v "^cpack version " )' -- "$cur" ) )
+ return
+ ;;
+ --help-variable)
+ COMPREPLY=( $( compgen -W '$( cpack --help-variable-list \
+ 2>/dev/null | grep -v "^cpack version " )' -- "$cur" ) )
+ return
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $(compgen -W '$( _parse_help "$1" --help )' -- ${cur}) )
+ [[ $COMPREPLY == *= ]] && compopt -o nospace
+ [[ $COMPREPLY ]] && return
+ fi
+
+ _filedir
+} &&
+complete -F _cpack cpack
+
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/Auxiliary/bash-completion/ctest b/Auxiliary/bash-completion/ctest
new file mode 100644
index 0000000000..327e12c599
--- /dev/null
+++ b/Auxiliary/bash-completion/ctest
@@ -0,0 +1,85 @@
+# bash completion for ctest(1) -*- shell-script -*-
+
+_ctest()
+{
+ local cur prev words cword
+ _init_completion -n = || return
+
+ case "$prev" in
+ -C|--build-config)
+ COMPREPLY=( $( compgen -W 'Debug Release RelWithDebInfo
+ MinSizeRel' -- "$cur" ) )
+ return
+ ;;
+ -j|--parallel)
+ COMPREPLY=( $( compgen -W "{1..$(( $(_ncpus)*2 ))}" -- "$cur" ) )
+ return
+ ;;
+ -O|--output-log|-A|--add-notes|--extra-submit)
+ _filedir
+ return
+ ;;
+ -L|--label-regex|-LE|--label-exclude)
+ COMPREPLY=( $( compgen -W '$( ctest --print-labels 2>/dev/null |
+ grep "^ " 2>/dev/null | cut -d" " -f 3 )' -- "$cur" ) )
+ return
+ ;;
+ --track|-I|--tests-information|--max-width|--timeout|--stop-time)
+ # argument required but no completions available
+ return
+ ;;
+ -R|--tests-regex|-E|--exclude-regex)
+ COMPREPLY=( $( compgen -W '$( ctest -N 2>/dev/null |
+ grep "^ Test" 2>/dev/null | cut -d: -f 2 )' -- "$cur" ) )
+ return
+ ;;
+ -D|--dashboard)
+ if [[ $cur == @(Experimental|Nightly|Continuous)* ]]; then
+ local model action
+ action=${cur#@(Experimental|Nightly|Continuous)}
+ model=${cur%"$action"}
+ COMPREPLY=( $( compgen -W 'Start Update Configure Build Test
+ Coverage Submit MemCheck' -P "$model" -- "$action" ) )
+ else
+ COMPREPLY=( $( compgen -W 'Experimental Nightly Continuous' \
+ -- "$cur" ) )
+ compopt -o nospace
+ fi
+ return
+ ;;
+ -M|--test-model)
+ COMPREPLY=( $( compgen -W 'Experimental Nightly Continuous' -- \
+ "$cur" ) )
+ return
+ ;;
+ -T|--test-action)
+ COMPREPLY=( $( compgen -W 'Start Update Configure Build Test
+ Coverage Submit MemCheck' -- "$cur" ) )
+ return
+ ;;
+ -S|--script|-SP|--script-new-process)
+ _filedir '@(cmake|ctest)'
+ return
+ ;;
+ --interactive-debug-mode)
+ COMPREPLY=( $( compgen -W '0 1' -- "$cur" ) )
+ return
+ ;;
+ --help-command)
+ COMPREPLY=( $( compgen -W '$( ctest --help-command-list 2>/dev/null|
+ grep -v "^ctest version " )' -- "$cur" ) )
+ return
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $(compgen -W '$( _parse_help "$1" --help )' -- ${cur}) )
+ [[ $COMPREPLY == *= ]] && compopt -o nospace
+ [[ $COMPREPLY ]] && return
+ fi
+
+ _filedir
+} &&
+complete -F _ctest ctest
+
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/Auxiliary/cmake-help.vim b/Auxiliary/cmake-help.vim
new file mode 100644
index 0000000000..17cfa838e8
--- /dev/null
+++ b/Auxiliary/cmake-help.vim
@@ -0,0 +1,21 @@
+nmap ,hc :call OpenCmakeHelp()<CR>
+
+function! OpenCmakeHelp()
+ let s = getline( '.' )
+ let i = col( '.' ) - 1
+ while i > 0 && strpart( s, i, 1 ) =~ '[A-Za-z0-9_]'
+ let i = i - 1
+ endwhile
+ while i < col('$') && strpart( s, i, 1 ) !~ '[A-Za-z0-9_]'
+ let i = i + 1
+ endwhile
+ let start = match( s, '[A-Za-z0-9_]\+', i )
+ let end = matchend( s, '[A-Za-z0-9_]\+', i )
+ let ident = strpart( s, start, end - start )
+ execute "vertical new"
+ execute "%!cmake --help-command ".ident
+ set nomodified
+ set readonly
+endfunction
+
+autocmd BufRead,BufNewFile *.cmake,CMakeLists.txt,*.cmake.in nmap <F1> :call OpenCmakeHelp()<CR>
diff --git a/Auxiliary/cmake-indent.vim b/Auxiliary/cmake-indent.vim
new file mode 100644
index 0000000000..a26dd06a25
--- /dev/null
+++ b/Auxiliary/cmake-indent.vim
@@ -0,0 +1,93 @@
+" =============================================================================
+"
+" Program: CMake - Cross-Platform Makefile Generator
+" Module: $RCSfile$
+" Language: VIM
+" Date: $Date$
+" Version: $Revision$
+"
+" =============================================================================
+
+" Vim indent file
+" Language: CMake (ft=cmake)
+" Author: Andy Cedilnik <andy.cedilnik@kitware.com>
+" Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
+" Last Change: $Date$
+" Version: $Revision$
+"
+" Licence: The CMake license applies to this file. See
+" http://www.cmake.org/HTML/Copyright.html
+" This implies that distribution with Vim is allowed
+
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=CMakeGetIndent(v:lnum)
+setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE(
+
+" Only define the function once.
+if exists("*CMakeGetIndent")
+ finish
+endif
+
+fun! CMakeGetIndent(lnum)
+ let this_line = getline(a:lnum)
+
+ " Find a non-blank line above the current line.
+ let lnum = a:lnum
+ let lnum = prevnonblank(lnum - 1)
+ let previous_line = getline(lnum)
+
+ " Hit the start of the file, use zero indent.
+ if lnum == 0
+ return 0
+ endif
+
+ let ind = indent(lnum)
+
+ let or = '\|'
+ " Regular expressions used by line indentation function.
+ let cmake_regex_comment = '#.*'
+ let cmake_regex_identifier = '[A-Za-z][A-Za-z0-9_]*'
+ let cmake_regex_quoted = '"\([^"\\]\|\\.\)*"'
+ let cmake_regex_arguments = '\(' . cmake_regex_quoted .
+ \ or . '\$(' . cmake_regex_identifier . ')' .
+ \ or . '[^()\\#"]' . or . '\\.' . '\)*'
+
+ let cmake_indent_comment_line = '^\s*' . cmake_regex_comment
+ let cmake_indent_blank_regex = '^\s*$'
+ let cmake_indent_open_regex = '^\s*' . cmake_regex_identifier .
+ \ '\s*(' . cmake_regex_arguments .
+ \ '\(' . cmake_regex_comment . '\)\?$'
+
+ let cmake_indent_close_regex = '^' . cmake_regex_arguments .
+ \ ')\s*' .
+ \ '\(' . cmake_regex_comment . '\)\?$'
+
+ let cmake_indent_begin_regex = '^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*('
+ let cmake_indent_end_regex = '^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\|ENDFUNCTION\)\s*('
+
+ " Add
+ if previous_line =~? cmake_indent_comment_line " Handle comments
+ let ind = ind
+ else
+ if previous_line =~? cmake_indent_begin_regex
+ let ind = ind + &sw
+ endif
+ if previous_line =~? cmake_indent_open_regex
+ let ind = ind + &sw
+ endif
+ endif
+
+ " Subtract
+ if this_line =~? cmake_indent_end_regex
+ let ind = ind - &sw
+ endif
+ if previous_line =~? cmake_indent_close_regex
+ let ind = ind - &sw
+ endif
+
+ return ind
+endfun
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el
new file mode 100644
index 0000000000..c8b9f8bb8d
--- /dev/null
+++ b/Auxiliary/cmake-mode.el
@@ -0,0 +1,405 @@
+;;; cmake-mode.el --- major-mode for editing CMake sources
+
+;=============================================================================
+; 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.
+;=============================================================================
+
+;------------------------------------------------------------------------------
+
+;;; Commentary:
+
+;; Provides syntax highlighting and indentation for CMakeLists.txt and
+;; *.cmake source files.
+;;
+;; Add this code to your .emacs file to use the mode:
+;;
+;; (setq load-path (cons (expand-file-name "/dir/with/cmake-mode") load-path))
+;; (require 'cmake-mode)
+
+;------------------------------------------------------------------------------
+
+;;; Code:
+;;
+;; cmake executable variable used to run cmake --help-command
+;; on commands in cmake-mode
+;;
+;; cmake-command-help Written by James Bigler
+;;
+
+(defcustom cmake-mode-cmake-executable "cmake"
+ "*The name of the cmake executable.
+
+This can be either absolute or looked up in $PATH. You can also
+set the path with these commands:
+ (setenv \"PATH\" (concat (getenv \"PATH\") \";C:\\\\Program Files\\\\CMake 2.8\\\\bin\"))
+ (setenv \"PATH\" (concat (getenv \"PATH\") \":/usr/local/cmake/bin\"))"
+ :type 'file
+ :group 'cmake)
+;;
+;; Regular expressions used by line indentation function.
+;;
+(defconst cmake-regex-blank "^[ \t]*$")
+(defconst cmake-regex-comment "#.*")
+(defconst cmake-regex-paren-left "(")
+(defconst cmake-regex-paren-right ")")
+(defconst cmake-regex-argument-quoted
+ "\"\\([^\"\\\\]\\|\\\\\\(.\\|\n\\)\\)*\"")
+(defconst cmake-regex-argument-unquoted
+ "\\([^ \t\r\n()#\"\\\\]\\|\\\\.\\)\\([^ \t\r\n()#\\\\]\\|\\\\.\\)*")
+(defconst cmake-regex-token (concat "\\(" cmake-regex-comment
+ "\\|" cmake-regex-paren-left
+ "\\|" cmake-regex-paren-right
+ "\\|" cmake-regex-argument-unquoted
+ "\\|" cmake-regex-argument-quoted
+ "\\)"))
+(defconst cmake-regex-indented (concat "^\\("
+ cmake-regex-token
+ "\\|" "[ \t\r\n]"
+ "\\)*"))
+(defconst cmake-regex-block-open
+ "^\\(if\\|macro\\|foreach\\|else\\|elseif\\|while\\|function\\)$")
+(defconst cmake-regex-block-close
+ "^[ \t]*\\(endif\\|endforeach\\|endmacro\\|else\\|elseif\\|endwhile\\|endfunction\\)[ \t]*(")
+
+;------------------------------------------------------------------------------
+
+;;
+;; Helper functions for line indentation function.
+;;
+(defun cmake-line-starts-inside-string ()
+ "Determine whether the beginning of the current line is in a string."
+ (if (save-excursion
+ (beginning-of-line)
+ (let ((parse-end (point)))
+ (goto-char (point-min))
+ (nth 3 (parse-partial-sexp (point) parse-end))
+ )
+ )
+ t
+ nil
+ )
+ )
+
+(defun cmake-find-last-indented-line ()
+ "Move to the beginning of the last line that has meaningful indentation."
+ (let ((point-start (point))
+ region)
+ (forward-line -1)
+ (setq region (buffer-substring-no-properties (point) point-start))
+ (while (and (not (bobp))
+ (or (looking-at cmake-regex-blank)
+ (cmake-line-starts-inside-string)
+ (not (and (string-match cmake-regex-indented region)
+ (= (length region) (match-end 0))))))
+ (forward-line -1)
+ (setq region (buffer-substring-no-properties (point) point-start))
+ )
+ )
+ )
+
+;------------------------------------------------------------------------------
+
+;;
+;; Line indentation function.
+;;
+(defun cmake-indent ()
+ "Indent current line as CMAKE code."
+ (interactive)
+ (if (cmake-line-starts-inside-string)
+ ()
+ (if (bobp)
+ (cmake-indent-line-to 0)
+ (let (cur-indent)
+
+ (save-excursion
+ (beginning-of-line)
+
+ (let ((point-start (point))
+ (case-fold-search t) ;; case-insensitive
+ token)
+
+ ; Search back for the last indented line.
+ (cmake-find-last-indented-line)
+
+ ; Start with the indentation on this line.
+ (setq cur-indent (current-indentation))
+
+ ; Search forward counting tokens that adjust indentation.
+ (while (re-search-forward cmake-regex-token point-start t)
+ (setq token (match-string 0))
+ (if (string-match (concat "^" cmake-regex-paren-left "$") token)
+ (setq cur-indent (+ cur-indent cmake-tab-width))
+ )
+ (if (string-match (concat "^" cmake-regex-paren-right "$") token)
+ (setq cur-indent (- cur-indent cmake-tab-width))
+ )
+ (if (and
+ (string-match cmake-regex-block-open token)
+ (looking-at (concat "[ \t]*" cmake-regex-paren-left))
+ )
+ (setq cur-indent (+ cur-indent cmake-tab-width))
+ )
+ )
+ (goto-char point-start)
+
+ ; If this is the end of a block, decrease indentation.
+ (if (looking-at cmake-regex-block-close)
+ (setq cur-indent (- cur-indent cmake-tab-width))
+ )
+ )
+ )
+
+ ; Indent this line by the amount selected.
+ (if (< cur-indent 0)
+ (cmake-indent-line-to 0)
+ (cmake-indent-line-to cur-indent)
+ )
+ )
+ )
+ )
+ )
+
+(defun cmake-point-in-indendation ()
+ (string-match "^[ \\t]*$" (buffer-substring (point-at-bol) (point))))
+
+(defun cmake-indent-line-to (column)
+ "Indent the current line to COLUMN.
+If point is within the existing indentation it is moved to the end of
+the indentation. Otherwise it retains the same position on the line"
+ (if (cmake-point-in-indendation)
+ (indent-line-to column)
+ (save-excursion (indent-line-to column))))
+
+;------------------------------------------------------------------------------
+
+;;
+;; Helper functions for buffer
+;;
+(defun unscreamify-cmake-buffer ()
+ "Convert all CMake commands to lowercase in buffer."
+ (interactive)
+ (goto-char (point-min))
+ (while (re-search-forward "^\\([ \t]*\\)\\(\\w+\\)\\([ \t]*(\\)" nil t)
+ (replace-match
+ (concat
+ (match-string 1)
+ (downcase (match-string 2))
+ (match-string 3))
+ t))
+ )
+
+;------------------------------------------------------------------------------
+
+;;
+;; Keyword highlighting regex-to-face map.
+;;
+(defconst cmake-font-lock-keywords
+ (list '("^[ \t]*\\(\\w+\\)[ \t]*(" 1 font-lock-function-name-face))
+ "Highlighting expressions for CMAKE mode."
+ )
+
+;------------------------------------------------------------------------------
+
+;;
+;; Syntax table for this mode. Initialize to nil so that it is
+;; regenerated when the cmake-mode function is called.
+;;
+(defvar cmake-mode-syntax-table nil "Syntax table for cmake-mode.")
+(setq cmake-mode-syntax-table nil)
+
+;;
+;; User hook entry point.
+;;
+(defvar cmake-mode-hook nil)
+
+;;
+;; Indentation increment.
+;;
+(defvar cmake-tab-width 2)
+
+;------------------------------------------------------------------------------
+
+;;
+;; CMake mode startup function.
+;;
+;;;###autoload
+(defun cmake-mode ()
+ "Major mode for editing CMake listfiles."
+ (interactive)
+ (kill-all-local-variables)
+ (setq major-mode 'cmake-mode)
+ (setq mode-name "CMAKE")
+
+ ; Create the syntax table
+ (setq cmake-mode-syntax-table (make-syntax-table))
+ (set-syntax-table cmake-mode-syntax-table)
+ (modify-syntax-entry ?_ "w" cmake-mode-syntax-table)
+ (modify-syntax-entry ?\( "()" cmake-mode-syntax-table)
+ (modify-syntax-entry ?\) ")(" cmake-mode-syntax-table)
+ (modify-syntax-entry ?# "<" cmake-mode-syntax-table)
+ (modify-syntax-entry ?\n ">" cmake-mode-syntax-table)
+
+ ; Setup font-lock mode.
+ (make-local-variable 'font-lock-defaults)
+ (setq font-lock-defaults '(cmake-font-lock-keywords))
+
+ ; Setup indentation function.
+ (make-local-variable 'indent-line-function)
+ (setq indent-line-function 'cmake-indent)
+
+ ; Setup comment syntax.
+ (make-local-variable 'comment-start)
+ (setq comment-start "#")
+
+ ; Run user hooks.
+ (run-hooks 'cmake-mode-hook))
+
+; Help mode starts here
+
+
+;;;###autoload
+(defun cmake-command-run (type &optional topic buffer)
+ "Runs the command cmake with the arguments specified. The
+optional argument topic will be appended to the argument list."
+ (interactive "s")
+ (let* ((bufname (if buffer buffer (concat "*CMake" type (if topic "-") topic "*")))
+ (buffer (if (get-buffer bufname) (get-buffer bufname) (generate-new-buffer bufname)))
+ (command (concat cmake-mode-cmake-executable " " type " " topic))
+ ;; Turn of resizing of mini-windows for shell-command.
+ (resize-mini-windows nil)
+ )
+ (shell-command command buffer)
+ (save-selected-window
+ (select-window (display-buffer buffer 'not-this-window))
+ (cmake-mode)
+ (toggle-read-only t))
+ )
+ )
+
+;;;###autoload
+(defun cmake-help-list-commands ()
+ "Prints out a list of the cmake commands."
+ (interactive)
+ (cmake-command-run "--help-command-list")
+ )
+
+(defvar cmake-commands '() "List of available topics for --help-command.")
+(defvar cmake-help-command-history nil "Command read history.")
+(defvar cmake-modules '() "List of available topics for --help-module.")
+(defvar cmake-help-module-history nil "Module read history.")
+(defvar cmake-variables '() "List of available topics for --help-variable.")
+(defvar cmake-help-variable-history nil "Variable read history.")
+(defvar cmake-properties '() "List of available topics for --help-property.")
+(defvar cmake-help-property-history nil "Property read history.")
+(defvar cmake-help-complete-history nil "Complete help read history.")
+(defvar cmake-string-to-list-symbol
+ '(("command" cmake-commands cmake-help-command-history)
+ ("module" cmake-modules cmake-help-module-history)
+ ("variable" cmake-variables cmake-help-variable-history)
+ ("property" cmake-properties cmake-help-property-history)
+ ))
+
+(defun cmake-get-list (listname)
+ "If the value of LISTVAR is nil, run cmake --help-LISTNAME-list
+and store the result as a list in LISTVAR."
+ (let ((listvar (car (cdr (assoc listname cmake-string-to-list-symbol)))))
+ (if (not (symbol-value listvar))
+ (let ((temp-buffer-name "*CMake Temporary*"))
+ (save-window-excursion
+ (cmake-command-run (concat "--help-" listname "-list") nil temp-buffer-name)
+ (with-current-buffer temp-buffer-name
+ (set listvar (cdr (split-string (buffer-substring-no-properties (point-min) (point-max)) "\n" t))))))
+ (symbol-value listvar)
+ ))
+ )
+
+(require 'thingatpt)
+(defun cmake-help-type (type)
+ (let* ((default-entry (word-at-point))
+ (history (car (cdr (cdr (assoc type cmake-string-to-list-symbol)))))
+ (input (completing-read
+ (format "CMake %s: " type) ; prompt
+ (cmake-get-list type) ; completions
+ nil ; predicate
+ t ; require-match
+ default-entry ; initial-input
+ history
+ )))
+ (if (string= input "")
+ (error "No argument given")
+ input))
+ )
+
+;;;###autoload
+(defun cmake-help-command ()
+ "Prints out the help message for the command the cursor is on."
+ (interactive)
+ (cmake-command-run "--help-command" (cmake-help-type "command") "*CMake Help*"))
+
+;;;###autoload
+(defun cmake-help-module ()
+ "Prints out the help message for the module the cursor is on."
+ (interactive)
+ (cmake-command-run "--help-module" (cmake-help-type "module") "*CMake Help*"))
+
+;;;###autoload
+(defun cmake-help-variable ()
+ "Prints out the help message for the variable the cursor is on."
+ (interactive)
+ (cmake-command-run "--help-variable" (cmake-help-type "variable") "*CMake Help*"))
+
+;;;###autoload
+(defun cmake-help-property ()
+ "Prints out the help message for the property the cursor is on."
+ (interactive)
+ (cmake-command-run "--help-property" (cmake-help-type "property") "*CMake Help*"))
+
+;;;###autoload
+(defun cmake-help ()
+ "Queries for any of the four available help topics and prints out the approriate page."
+ (interactive)
+ (let* ((default-entry (word-at-point))
+ (command-list (cmake-get-list "command"))
+ (variable-list (cmake-get-list "variable"))
+ (module-list (cmake-get-list "module"))
+ (property-list (cmake-get-list "property"))
+ (all-words (append command-list variable-list module-list property-list))
+ (input (completing-read
+ "CMake command/module/variable/property: " ; prompt
+ all-words ; completions
+ nil ; predicate
+ t ; require-match
+ default-entry ; initial-input
+ 'cmake-help-complete-history
+ )))
+ (if (string= input "")
+ (error "No argument given")
+ (if (member input command-list)
+ (cmake-command-run "--help-command" input "*CMake Help*")
+ (if (member input variable-list)
+ (cmake-command-run "--help-variable" input "*CMake Help*")
+ (if (member input module-list)
+ (cmake-command-run "--help-module" input "*CMake Help*")
+ (if (member input property-list)
+ (cmake-command-run "--help-property" input "*CMake Help*")
+ (error "Not a know help topic.") ; this really should not happen
+ ))))))
+ )
+
+;;;###autoload
+(progn
+ (add-to-list 'auto-mode-alist '("CMakeLists\\.txt\\'" . cmake-mode))
+ (add-to-list 'auto-mode-alist '("\\.cmake\\'" . cmake-mode)))
+
+; This file provides cmake-mode.
+(provide 'cmake-mode)
+
+;;; cmake-mode.el ends here
diff --git a/Auxiliary/cmake-syntax.vim b/Auxiliary/cmake-syntax.vim
new file mode 100644
index 0000000000..782130d9ee
--- /dev/null
+++ b/Auxiliary/cmake-syntax.vim
@@ -0,0 +1,89 @@
+" =============================================================================
+"
+" Program: CMake - Cross-Platform Makefile Generator
+" Module: $RCSfile$
+" Language: VIM
+" Date: $Date$
+" Version: $Revision$
+"
+" =============================================================================
+
+" Vim syntax file
+" Language: CMake
+" Author: Andy Cedilnik <andy.cedilnik@kitware.com>
+" Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
+" Last Change: $Date$
+" Version: $Revision$
+"
+" Licence: The CMake license applies to this file. See
+" http://www.cmake.org/HTML/Copyright.html
+" This implies that distribution with Vim is allowed
+
+" For version 5.x: Clear all syntax items
+" For version 6.x: Quit when a syntax file was already loaded
+if version < 600
+ syntax clear
+elseif exists("b:current_syntax")
+ finish
+endif
+
+syn case ignore
+syn match cmakeEscaped /\(\\\\\|\\"\|\\n\|\\t\)/ contained
+syn region cmakeComment start="#" end="$" contains=cmakeTodo
+syn region cmakeRegistry start=/\[/ end=/]/
+ \ contained oneline contains=CONTAINED,cmakeTodo,cmakeEscaped
+syn region cmakeVariableValue start=/\${/ end=/}/
+ \ contained oneline contains=CONTAINED,cmakeTodo
+syn region cmakeEnvironment start=/\$ENV{/ end=/}/
+ \ contained oneline contains=CONTAINED,cmakeTodo
+syn region cmakeString start=/"/ end=/"/
+ \ contains=CONTAINED,cmakeTodo,cmakeOperators
+syn region cmakeArguments start=/(/ end=/)/
+ \ contains=ALLBUT,cmakeArguments,cmakeTodo
+syn keyword cmakeSystemVariables
+ \ WIN32 UNIX APPLE CYGWIN BORLAND MINGW MSVC MSVC_IDE MSVC60 MSVC70 MSVC71 MSVC80 MSVC90
+syn keyword cmakeOperators
+ \ ABSOLUTE AND BOOL CACHE COMMAND DEFINED DOC EQUAL EXISTS EXT FALSE GREATER INTERNAL LESS MATCHES NAME NAMES NAME_WE NOT OFF ON OR PATH PATHS PROGRAM STREQUAL STRGREATER STRING STRLESS TRUE
+ \ contained
+syn keyword cmakeDeprecated ABSTRACT_FILES BUILD_NAME SOURCE_FILES SOURCE_FILES_REMOVE VTK_MAKE_INSTANTIATOR VTK_WRAP_JAVA VTK_WRAP_PYTHON VTK_WRAP_TCL WRAP_EXCLUDE_FILES
+ \ nextgroup=cmakeArguments
+
+" The keywords are generated as: cmake --help-command-list | tr "\n" " " | tr "[:lower:]" "[:upper:]"
+syn keyword cmakeStatement
+ \ ADD_COMPILE_OPTIONS ADD_CUSTOM_COMMAND ADD_CUSTOM_TARGET ADD_DEFINITIONS ADD_DEPENDENCIES ADD_EXECUTABLE ADD_LIBRARY ADD_SUBDIRECTORY ADD_TEST AUX_SOURCE_DIRECTORY BREAK BUILD_COMMAND BUILD_NAME CMAKE_HOST_SYSTEM_INFORMATION CMAKE_MINIMUM_REQUIRED CMAKE_POLICY CONFIGURE_FILE CREATE_TEST_SOURCELIST CTEST_BUILD CTEST_CONFIGURE CTEST_COVERAGE CTEST_EMPTY_BINARY_DIRECTORY CTEST_MEMCHECK CTEST_READ_CUSTOM_FILES CTEST_RUN_SCRIPT CTEST_SLEEP CTEST_START CTEST_SUBMIT CTEST_TEST CTEST_UPDATE CTEST_UPLOAD DEFINE_PROPERTY ELSE ELSEIF ENABLE_LANGUAGE ENABLE_TESTING ENDFOREACH ENDFUNCTION ENDIF ENDMACRO ENDWHILE EXEC_PROGRAM EXECUTE_PROCESS EXPORT EXPORT_LIBRARY_DEPENDENCIES FILE FIND_FILE FIND_LIBRARY FIND_PACKAGE FIND_PATH FIND_PROGRAM FLTK_WRAP_UI FOREACH FUNCTION GET_CMAKE_PROPERTY GET_DIRECTORY_PROPERTY GET_FILENAME_COMPONENT GET_PROPERTY GET_SOURCE_FILE_PROPERTY GET_TARGET_PROPERTY GET_TEST_PROPERTY IF INCLUDE INCLUDE_DIRECTORIES INCLUDE_EXTERNAL_MSPROJECT INCLUDE_REGULAR_EXPRESSION INSTALL INSTALL_FILES INSTALL_PROGRAMS INSTALL_TARGETS LINK_DIRECTORIES LINK_LIBRARIES LIST LOAD_CACHE LOAD_COMMAND MACRO MAKE_DIRECTORY MARK_AS_ADVANCED MATH MESSAGE OPTION OUTPUT_REQUIRED_FILES PROJECT QT_WRAP_CPP QT_WRAP_UI REMOVE REMOVE_DEFINITIONS RETURN SEPARATE_ARGUMENTS SET SET_DIRECTORY_PROPERTIES SET_PROPERTY SET_SOURCE_FILES_PROPERTIES SET_TARGET_PROPERTIES SET_TESTS_PROPERTIES SITE_NAME SOURCE_GROUP STRING SUBDIR_DEPENDS SUBDIRS TARGET_COMPILE_DEFINITIONS TARGET_COMPILE_FEATURES TARGET_COMPILE_OPTIONS TARGET_INCLUDE_DIRECTORIES TARGET_LINK_LIBRARIES TARGET_SOURCES TRY_COMPILE TRY_RUN UNSET USE_MANGLED_MESA UTILITY_SOURCE VARIABLE_REQUIRES VARIABLE_WATCH WHILE WRITE_FILE
+ \ nextgroup=cmakeArguments
+syn keyword cmakeTodo
+ \ TODO FIXME XXX
+ \ contained
+
+" Define the default highlighting.
+" For version 5.7 and earlier: only when not done already
+" For version 5.8 and later: only when an item doesn't have highlighting yet
+if version >= 508 || !exists("did_cmake_syntax_inits")
+ if version < 508
+ let did_cmake_syntax_inits = 1
+ command -nargs=+ HiLink hi link <args>
+ else
+ command -nargs=+ HiLink hi def link <args>
+ endif
+
+ HiLink cmakeStatement Statement
+ HiLink cmakeComment Comment
+ HiLink cmakeString String
+ HiLink cmakeVariableValue Type
+ HiLink cmakeRegistry Underlined
+ HiLink cmakeArguments Identifier
+ HiLink cmakeArgument Constant
+ HiLink cmakeEnvironment Special
+ HiLink cmakeOperators Operator
+ HiLink cmakeMacro PreProc
+ HiLink cmakeError Error
+ HiLink cmakeTodo TODO
+ HiLink cmakeEscaped Special
+
+ delcommand HiLink
+endif
+
+let b:current_syntax = "cmake"
+
+"EOF"
diff --git a/Auxiliary/cmake.m4 b/Auxiliary/cmake.m4
new file mode 100644
index 0000000000..a374a3bfbf
--- /dev/null
+++ b/Auxiliary/cmake.m4
@@ -0,0 +1,53 @@
+dnl ============================================================================
+dnl CMake - Cross Platform Makefile Generator
+dnl Copyright 2011 Matthias Kretz, kretz@kde.org
+dnl
+dnl Distributed under the OSI-approved BSD License (the "License");
+dnl see accompanying file Copyright.txt for details.
+dnl
+dnl This software is distributed WITHOUT ANY WARRANTY; without even the
+dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+dnl See the License for more information.
+dnl ============================================================================
+
+AC_DEFUN([CMAKE_FIND_BINARY],
+[AC_ARG_VAR([CMAKE_BINARY], [path to the cmake binary])dnl
+
+if test "x$ac_cv_env_CMAKE_BINARY_set" != "xset"; then
+ AC_PATH_TOOL([CMAKE_BINARY], [cmake])dnl
+fi
+])dnl
+
+# $1: package name
+# $2: language (e.g. C/CXX/Fortran)
+# $3: The compiler ID, defaults to GNU.
+# Possible values are: GNU, Intel, Clang, SunPro, HP, XL, VisualAge, PGI,
+# PathScale, Cray, SCO, MIPSpro, MSVC
+# $4: optional extra arguments to cmake, e.g. "-DCMAKE_SIZEOF_VOID_P=8"
+# $5: optional path to cmake binary
+AC_DEFUN([CMAKE_FIND_PACKAGE], [
+AC_REQUIRE([CMAKE_FIND_BINARY])dnl
+
+AC_ARG_VAR([$1][_][$2][FLAGS], [$2 compiler flags for $1. This overrides the cmake output])dnl
+AC_ARG_VAR([$1][_LIBS], [linker flags for $1. This overrides the cmake output])dnl
+
+failed=false
+AC_MSG_CHECKING([for $1])
+if test -n "$1[]_$2[]FLAGS"; then
+ $1[]_$2[]FLAGS=`$CMAKE_BINARY --find-package "-DNAME=$1" "-DCOMPILER_ID=m4_default([$3], [GNU])" "-DLANGUAGE=$2" -DMODE=COMPILE $4` || failed=true
+fi
+if test -n "$1[]_LIBS"; then
+ $1[]_LIBS=`$CMAKE_BINARY --find-package "-DNAME=$1" "-DCOMPILER_ID=m4_default([$3], [GNU])" "-DLANGUAGE=$2" -DMODE=LINK $4` || failed=true
+fi
+
+if $failed; then
+ unset $1[]_$2[]FLAGS
+ unset $1[]_LIBS
+
+ AC_MSG_RESULT([no])
+ $6
+else
+ AC_MSG_RESULT([yes])
+ $5
+fi[]dnl
+])
diff --git a/CMakeCPack.cmake b/CMakeCPack.cmake
new file mode 100644
index 0000000000..22ca8cfa1a
--- /dev/null
+++ b/CMakeCPack.cmake
@@ -0,0 +1,148 @@
+#=============================================================================
+# 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.
+#=============================================================================
+
+# If the cmake version includes cpack, use it
+if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
+ if(EXISTS "${CMAKE_ROOT}/Modules/InstallRequiredSystemLibraries.cmake")
+ option(CMAKE_INSTALL_DEBUG_LIBRARIES
+ "Install Microsoft runtime debug libraries with CMake." FALSE)
+ mark_as_advanced(CMAKE_INSTALL_DEBUG_LIBRARIES)
+
+ # By default, do not warn when built on machines using only VS Express:
+ if(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
+ set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
+ endif()
+
+ include(${CMake_SOURCE_DIR}/Modules/InstallRequiredSystemLibraries.cmake)
+ endif()
+
+ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CMake is a build tool")
+ set(CPACK_PACKAGE_VENDOR "Kitware")
+ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
+ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
+ set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
+ set(CPACK_PACKAGE_VERSION "${CMake_VERSION}")
+ set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
+ set(CPACK_SOURCE_PACKAGE_FILE_NAME "cmake-${CMake_VERSION}")
+
+ # Installers for 32- vs. 64-bit CMake:
+ # - Root install directory (displayed to end user at installer-run time)
+ # - "NSIS package/display name" (text used in the installer GUI)
+ # - Registry key used to store info about the installation
+ if(CMAKE_CL_64)
+ set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
+ set(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION} (Win64)")
+ else()
+ set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES")
+ set(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}")
+ endif()
+ set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${CPACK_NSIS_PACKAGE_NAME}")
+
+ if(NOT DEFINED CPACK_SYSTEM_NAME)
+ # make sure package is not Cygwin-unknown, for Cygwin just
+ # cygwin is good for the system name
+ if("x${CMAKE_SYSTEM_NAME}" STREQUAL "xCYGWIN")
+ set(CPACK_SYSTEM_NAME Cygwin)
+ else()
+ set(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR})
+ endif()
+ endif()
+ if(${CPACK_SYSTEM_NAME} MATCHES Windows)
+ if(CMAKE_CL_64)
+ set(CPACK_SYSTEM_NAME win64-x64)
+ set(CPACK_IFW_TARGET_DIRECTORY "@RootDir@/Program Files/${CMAKE_PROJECT_NAME}")
+ else()
+ set(CPACK_SYSTEM_NAME win32-x86)
+ endif()
+ endif()
+
+ if(${CMAKE_SYSTEM_NAME} MATCHES Windows)
+ set(_CPACK_IFW_PACKAGE_ICON
+ "set(CPACK_IFW_PACKAGE_ICON \"${CMake_SOURCE_DIR}/Source/QtDialog/CMakeSetup.ico\")")
+ if(BUILD_QtDialog)
+ set(_CPACK_IFW_SHORTCUT_OPTIONAL "${_CPACK_IFW_SHORTCUT_OPTIONAL}component.addOperation(\"CreateShortcut\", \"@TargetDir@/bin/cmake-gui.exe\", \"@StartMenuDir@/CMake (cmake-gui).lnk\");\n")
+ endif()
+ if(SPHINX_HTML)
+ set(_CPACK_IFW_SHORTCUT_OPTIONAL "${_CPACK_IFW_SHORTCUT_OPTIONAL}component.addOperation(\"CreateShortcut\", \"@TargetDir@/doc/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}/html/index.html\", \"@StartMenuDir@/CMake Documentation.lnk\");\n")
+ endif()
+ configure_file("${CMake_SOURCE_DIR}/Source/QtIFW/installscript.qs.in"
+ "${CMake_BINARY_DIR}/installscript.qs" @ONLY
+ )
+ install(FILES "${CMake_SOURCE_DIR}/Source/QtIFW/cmake.org.html"
+ DESTINATION "."
+ )
+ set(_CPACK_IFW_PACKAGE_SCRIPT "set(CPACK_IFW_COMPONENT_GROUP_CMAKE_SCRIPT \"${CMake_BINARY_DIR}/installscript.qs\")")
+ endif()
+
+ if(${CMAKE_SYSTEM_NAME} MATCHES Linux)
+ set(CPACK_IFW_TARGET_DIRECTORY "@HomeDir@/${CMAKE_PROJECT_NAME}")
+ set(CPACK_IFW_ADMIN_TARGET_DIRECTORY "@ApplicationsDir@/${CMAKE_PROJECT_NAME}")
+ endif()
+
+ set(_CPACK_IFW_PACKAGE_VERSION ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH})
+
+ if(NOT DEFINED CPACK_PACKAGE_FILE_NAME)
+ # if the CPACK_PACKAGE_FILE_NAME is not defined by the cache
+ # default to source package - system, on cygwin system is not
+ # needed
+ if(CYGWIN)
+ set(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}")
+ else()
+ set(CPACK_PACKAGE_FILE_NAME
+ "${CPACK_SOURCE_PACKAGE_FILE_NAME}-${CPACK_SYSTEM_NAME}")
+ endif()
+ endif()
+
+ set(CPACK_PACKAGE_CONTACT "cmake@cmake.org")
+
+ if(UNIX)
+ set(CPACK_STRIP_FILES "bin/ccmake;bin/cmake;bin/cpack;bin/ctest")
+ set(CPACK_SOURCE_STRIP_FILES "")
+ set(CPACK_PACKAGE_EXECUTABLES "ccmake" "CMake")
+ endif()
+
+ # cygwin specific packaging stuff
+ if(CYGWIN)
+ # setup the cygwin package name
+ set(CPACK_PACKAGE_NAME cmake)
+ # setup the name of the package for cygwin cmake-2.4.3
+ set(CPACK_PACKAGE_FILE_NAME
+ "${CPACK_PACKAGE_NAME}-${CMake_VERSION}")
+ # the source has the same name as the binary
+ set(CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_FILE_NAME})
+ # Create a cygwin version number in case there are changes for cygwin
+ # that are not reflected upstream in CMake
+ set(CPACK_CYGWIN_PATCH_NUMBER 1 CACHE STRING "patch number for CMake cygwin packages")
+ mark_as_advanced(CPACK_CYGWIN_PATCH_NUMBER)
+ # These files are required by the cmCPackCygwinSourceGenerator and the files
+ # put into the release tar files.
+ set(CPACK_CYGWIN_BUILD_SCRIPT
+ "${CMake_BINARY_DIR}/${CPACK_PACKAGE_FILE_NAME}-${CPACK_CYGWIN_PATCH_NUMBER}.sh")
+ set(CPACK_CYGWIN_PATCH_FILE
+ "${CMake_BINARY_DIR}/${CPACK_PACKAGE_FILE_NAME}-${CPACK_CYGWIN_PATCH_NUMBER}.patch")
+ # include the sub directory cmake file for cygwin that
+ # configures some files and adds some install targets
+ # this file uses some of the package file name variables
+ include(Utilities/Release/Cygwin/CMakeLists.txt)
+ endif()
+
+ set(CPACK_WIX_UPGRADE_GUID "8ffd1d72-b7f1-11e2-8ee5-00238bca4991")
+
+ # 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"
+ "${CMake_BINARY_DIR}/CMakeCPackOptions.cmake" @ONLY)
+ set(CPACK_PROJECT_CONFIG_FILE "${CMake_BINARY_DIR}/CMakeCPackOptions.cmake")
+
+ # include CPack model once all variables are set
+ include(CPack)
+endif()
diff --git a/CMakeCPackOptions.cmake.in b/CMakeCPackOptions.cmake.in
new file mode 100644
index 0000000000..57ed4cafd5
--- /dev/null
+++ b/CMakeCPackOptions.cmake.in
@@ -0,0 +1,90 @@
+# This file is configured at cmake time, and loaded at cpack time.
+# To pass variables to cpack from cmake, they must be configured
+# in this file.
+
+if(CPACK_GENERATOR MATCHES "NSIS")
+ set(CPACK_NSIS_INSTALL_ROOT "@CPACK_NSIS_INSTALL_ROOT@")
+
+ # set the install/unistall icon used for the installer itself
+ # There is a bug in NSI that does not handle full unix paths properly.
+ set(CPACK_NSIS_MUI_ICON "@CMake_SOURCE_DIR@/Utilities/Release\\CMakeLogo.ico")
+ set(CPACK_NSIS_MUI_UNIICON "@CMake_SOURCE_DIR@/Utilities/Release\\CMakeLogo.ico")
+ # set the package header icon for MUI
+ set(CPACK_PACKAGE_ICON "@CMake_SOURCE_DIR@/Utilities/Release\\CMakeInstall.bmp")
+ # tell cpack to create links to the doc files
+ set(CPACK_NSIS_MENU_LINKS
+ "@CMAKE_DOC_DIR@/html/index.html" "CMake Documentation"
+ "http://www.cmake.org" "CMake Web Site"
+ )
+ # Use the icon from cmake-gui for add-remove programs
+ set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\cmake-gui.exe")
+
+ set(CPACK_NSIS_PACKAGE_NAME "@CPACK_NSIS_PACKAGE_NAME@")
+ set(CPACK_NSIS_DISPLAY_NAME "@CPACK_NSIS_PACKAGE_NAME@, a cross-platform, open-source build system")
+ set(CPACK_NSIS_HELP_LINK "http://www.cmake.org")
+ set(CPACK_NSIS_URL_INFO_ABOUT "http://www.kitware.com")
+ set(CPACK_NSIS_CONTACT @CPACK_PACKAGE_CONTACT@)
+ set(CPACK_NSIS_MODIFY_PATH ON)
+endif()
+
+# include the cpack options for qt dialog if they exist
+# they might not if qt was not enabled for the build
+include("@QT_DIALOG_CPACK_OPTIONS_FILE@" OPTIONAL)
+
+if(CPACK_GENERATOR MATCHES "IFW")
+ # Installer configuration
+ set(CPACK_IFW_PACKAGE_TITLE "CMake Build Tool")
+ set(CPACK_IFW_PRODUCT_URL "http://www.cmake.org")
+ @_CPACK_IFW_PACKAGE_ICON@
+ set(CPACK_IFW_PACKAGE_WINDOW_ICON
+ "@CMake_SOURCE_DIR@/Source/QtDialog/CMakeSetup128.png")
+ # Package configuration group
+ set(CPACK_IFW_PACKAGE_GROUP CMake)
+ # Group configuration
+ set(CPACK_COMPONENT_GROUP_CMAKE_DISPLAY_NAME
+ "@CPACK_PACKAGE_NAME@")
+ set(CPACK_COMPONENT_GROUP_CMAKE_DESCRIPTION
+ "@CPACK_PACKAGE_DESCRIPTION_SUMMARY@")
+ # IFW group configuration
+ set(CPACK_IFW_COMPONENT_GROUP_CMAKE_VERSION
+ "@_CPACK_IFW_PACKAGE_VERSION@")
+ set(CPACK_IFW_COMPONENT_GROUP_CMAKE_LICENSES
+ "@CPACK_PACKAGE_NAME@ Copyright" "@CPACK_RESOURCE_FILE_LICENSE@")
+ @_CPACK_IFW_PACKAGE_SCRIPT@
+endif()
+
+if(CPACK_GENERATOR MATCHES "CygwinSource")
+ # when packaging source make sure the .build directory is not included
+ set(CPACK_SOURCE_IGNORE_FILES
+ "/CVS/" "/\\.build/" "/\\.svn/" "\\.swp$" "\\.#" "/#" "~$")
+endif()
+
+if("${CPACK_GENERATOR}" STREQUAL "PackageMaker")
+ if(CMAKE_PACKAGE_QTGUI)
+ set(CPACK_PACKAGE_DEFAULT_LOCATION "/Applications")
+ else()
+ set(CPACK_PACKAGE_DEFAULT_LOCATION "/usr")
+ endif()
+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}-@CMake_VERSION@-${CPACK_SYSTEM_NAME}")
+ set(CPACK_SOURCE_PACKAGE_FILE_NAME
+ "${CPACK_PACKAGE_NAME}-@CMake_VERSION@-Source")
+
+ if(NOT CPACK_WIX_SIZEOF_VOID_P)
+ set(CPACK_WIX_SIZEOF_VOID_P "@CMAKE_SIZEOF_VOID_P@")
+ endif()
+
+ set(CPACK_PACKAGE_VERSION
+ "@CMake_VERSION_MAJOR@.@CMake_VERSION_MINOR@")
+ # WIX installers require at most a 4 component version number, where
+ # each component is an integer between 0 and 65534 inclusive
+ set(patch "@CMake_VERSION_PATCH@")
+ if(patch MATCHES "^[0-9]+$" AND patch LESS 65535)
+ set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}.${patch}")
+ endif()
+endif()
diff --git a/CMakeGraphVizOptions.cmake b/CMakeGraphVizOptions.cmake
new file mode 100644
index 0000000000..1add78c55b
--- /dev/null
+++ b/CMakeGraphVizOptions.cmake
@@ -0,0 +1 @@
+set(GRAPHVIZ_IGNORE_TARGETS "tartest;testSystemTools;testRegistry;testProcess;testIOS;testHashSTL;testFail;testCommandLineArguments;xrtest;LIBCURL;foo")
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6a8641adcf..71850de950 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
#=============================================================================
-# Kitware Information Macro Library
-# Copyright 2010-2011 Kitware, Inc.
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2012 Kitware, Inc., Insight Software Consortium
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
@@ -9,71 +9,613 @@
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
+cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
+if(POLICY CMP0025)
+ cmake_policy(SET CMP0025 NEW)
+endif()
+project(CMake)
+
+if(CMAKE_BOOTSTRAP)
+ # Running from bootstrap script. Set local variable and remove from cache.
+ set(CMAKE_BOOTSTRAP 1)
+ unset(CMAKE_BOOTSTRAP CACHE)
+endif()
+
+if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
+endif()
+
+if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
+ # Disallow architecture-specific try_run. It may not run on the host.
+ macro(TRY_RUN)
+ if(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
+ message(FATAL_ERROR "TRY_RUN not allowed with CMAKE_TRY_COMPILE_OSX_ARCHITECTURES=[${CMAKE_TRY_COMPILE_OSX_ARCHITECTURES}]")
+ else()
+ _TRY_RUN(${ARGV})
+ endif()
+ endmacro()
+endif()
+
+# option to set the internal encoding of CMake to UTF-8
+option(CMAKE_ENCODING_UTF8 "Use UTF-8 encoding internally (experimental)." OFF)
+mark_as_advanced(CMAKE_ENCODING_UTF8)
+if(CMAKE_ENCODING_UTF8)
+ set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
+endif()
+
+#-----------------------------------------------------------------------
+# a macro to deal with system libraries, implemented as a macro
+# simply to improve readability of the main script
+#-----------------------------------------------------------------------
+macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
+ # Options have dependencies.
+ include(CMakeDependentOption)
+
+ # Optionally use system xmlrpc. We no longer build or use it by default.
+ option(CTEST_USE_XMLRPC "Enable xmlrpc submission method in CTest." OFF)
+ mark_as_advanced(CTEST_USE_XMLRPC)
+
+ # Allow the user to enable/disable all system utility library options by
+ # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
+ set(UTILITIES BZIP2 CURL EXPAT LIBARCHIVE LIBLZMA ZLIB)
+ foreach(util ${UTILITIES})
+ if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
+ AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
+ set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
+ endif()
+ if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
+ if(CMAKE_USE_SYSTEM_LIBRARY_${util})
+ set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
+ else()
+ set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
+ endif()
+ if(CMAKE_BOOTSTRAP)
+ unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
+ endif()
+ string(TOLOWER "${util}" lutil)
+ set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
+ CACHE BOOL "Use system-installed ${lutil}" FORCE)
+ else()
+ set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
+ endif()
+ endforeach()
+ if(CMAKE_BOOTSTRAP)
+ unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
+ endif()
+
+ # Optionally use system utility libraries.
+ option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
+ CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_CURL "Use system-installed curl"
+ "${CMAKE_USE_SYSTEM_LIBRARY_CURL}" "NOT CTEST_USE_XMLRPC" ON)
+ CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat"
+ "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}" "NOT CTEST_USE_XMLRPC" ON)
+ CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
+ "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
+ CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
+ "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
+ CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
+ "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
+
+ # Mention to the user what system libraries are being used.
+ foreach(util ${UTILITIES})
+ if(CMAKE_USE_SYSTEM_${util})
+ message(STATUS "Using system-installed ${util}")
+ endif()
+ endforeach()
+
+ # Inform utility library header wrappers whether to use system versions.
+ configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
+ ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
+ @ONLY)
+
+endmacro()
+
+
+
+
+if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ set(CMAKE_BUILD_ON_VISUAL_STUDIO 0)
+ if(WIN32 AND NOT UNIX AND NOT BORLAND AND NOT MINGW )
+ set(CMAKE_BUILD_ON_VISUAL_STUDIO 1)
+ endif()
+endif()
-# Import the KWIML directory tree into a subdirectory under a parent
-# project and configure the library as follows:
+
+#-----------------------------------------------------------------------
+# a macro to determine the generator and ctest executable to use
+# for testing. Simply to improve readability of the main script.
+#-----------------------------------------------------------------------
+macro(CMAKE_SETUP_TESTING)
+ if(BUILD_TESTING)
+ set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
+ foreach(util CURL EXPAT XMLRPC ZLIB)
+ if(CMAKE_USE_SYSTEM_${util})
+ set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
+ endif()
+ endforeach()
+
+ # This variable is set by cmake, however to
+ # test cmake we want to make sure that
+ # the ctest from this cmake is used for testing
+ # and not the ctest from the cmake building and testing
+ # cmake.
+ if(CMake_TEST_EXTERNAL_CMAKE)
+ set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
+ set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
+ set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
+ foreach(exe cmake ctest cpack)
+ add_executable(${exe} IMPORTED)
+ set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
+ endforeach()
+ else()
+ set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
+ set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
+ set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
+ endif()
+ endif()
+
+ # configure some files for testing
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
+ @ONLY)
+ configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
+ ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
+ configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
+ ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
+ configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
+ ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
+ if(BUILD_TESTING AND DART_ROOT)
+ configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
+ ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
+ endif()
+ mark_as_advanced(DART_ROOT)
+ mark_as_advanced(CURL_TESTING)
+endmacro()
+
+
+# Provide a way for Visual Studio Express users to turn OFF the new FOLDER
+# organization feature. Default to ON for non-Express users. Express users must
+# explicitly turn off this option to build CMake in the Express IDE...
#
-# SET(KWIML myIML)
-# SUBDIRS(KWIML)
+option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
+mark_as_advanced(CMAKE_USE_FOLDERS)
+
+
+#-----------------------------------------------------------------------
+# a macro that only sets the FOLDER target property if it's
+# "appropriate"
+#-----------------------------------------------------------------------
+macro(CMAKE_SET_TARGET_FOLDER tgt folder)
+ if(CMAKE_USE_FOLDERS)
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+ if(MSVC AND TARGET ${tgt})
+ set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
+ endif()
+ else()
+ set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
+ endif()
+endmacro()
+
+
+#-----------------------------------------------------------------------
+# a macro to build the utilities used by CMake
+# Simply to improve readability of the main script.
+#-----------------------------------------------------------------------
+macro (CMAKE_BUILD_UTILITIES)
+ #---------------------------------------------------------------------
+ # Create the kwsys library for CMake.
+ set(KWSYS_NAMESPACE cmsys)
+ set(KWSYS_USE_SystemTools 1)
+ set(KWSYS_USE_Directory 1)
+ set(KWSYS_USE_RegularExpression 1)
+ set(KWSYS_USE_Base64 1)
+ set(KWSYS_USE_MD5 1)
+ set(KWSYS_USE_Process 1)
+ set(KWSYS_USE_CommandLineArguments 1)
+ set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
+ set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
+ add_subdirectory(Source/kwsys)
+ set(kwsys_folder "Utilities/KWSys")
+ CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
+ CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
+ if(BUILD_TESTING)
+ CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
+ CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
+ CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
+ CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
+ CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
+ endif()
+
+ #---------------------------------------------------------------------
+ # Setup third-party libraries.
+ # Everything in the tree should be able to include files from the
+ # Utilities directory.
+ include_directories(
+ ${CMake_BINARY_DIR}/Utilities
+ ${CMake_SOURCE_DIR}/Utilities
+ )
+
+ # check for the use of system libraries versus builtin ones
+ # (a macro defined in this file)
+ CMAKE_HANDLE_SYSTEM_LIBRARIES()
+
+ #---------------------------------------------------------------------
+ # Build zlib library for Curl, CMake, and CTest.
+ set(CMAKE_ZLIB_HEADER "cm_zlib.h")
+ if(CMAKE_USE_SYSTEM_ZLIB)
+ find_package(ZLIB)
+ if(NOT ZLIB_FOUND)
+ message(FATAL_ERROR
+ "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
+ endif()
+ set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
+ set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
+ else()
+ set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
+ set(CMAKE_ZLIB_LIBRARIES cmzlib)
+ add_subdirectory(Utilities/cmzlib)
+ CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
+ endif()
+
+ #---------------------------------------------------------------------
+ # Build Curl library for CTest.
+ if(CMAKE_USE_SYSTEM_CURL)
+ find_package(CURL)
+ if(NOT CURL_FOUND)
+ message(FATAL_ERROR
+ "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
+ endif()
+ set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
+ set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
+ else()
+ set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
+ set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
+ set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
+ option(CMAKE_BUILD_CURL_SHARED "Should curl be built shared" FALSE)
+ if(NOT CMAKE_BUILD_CURL_SHARED)
+ add_definitions(-DCURL_STATICLIB)
+ endif()
+ set(CMAKE_CURL_INCLUDES)
+ set(CMAKE_CURL_LIBRARIES cmcurl)
+ if(CMAKE_TESTS_CDASH_SERVER)
+ set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
+ endif()
+ add_subdirectory(Utilities/cmcurl)
+ CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
+ CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
+ endif()
+
+ #---------------------------------------------------------------------
+ # Build Compress library for CTest.
+ set(CMAKE_COMPRESS_INCLUDES
+ "${CMAKE_CURRENT_BINARY_DIR}/Utilities/cmcompress")
+ set(CMAKE_COMPRESS_LIBRARIES "cmcompress")
+ add_subdirectory(Utilities/cmcompress)
+ CMAKE_SET_TARGET_FOLDER(cmcompress "Utilities/3rdParty")
+ if(CMAKE_USE_SYSTEM_BZIP2)
+ find_package(BZip2)
+ else()
+ set(BZIP2_INCLUDE_DIR
+ "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
+ set(BZIP2_LIBRARIES cmbzip2)
+ add_subdirectory(Utilities/cmbzip2)
+ CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
+ endif()
+
+ #---------------------------------------------------------------------
+ # Build or use system liblzma for libarchive.
+ if(CMAKE_USE_SYSTEM_LIBLZMA)
+ find_package(LibLZMA)
+ if(NOT LIBLZMA_FOUND)
+ message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
+ endif()
+ set(LZMA_INCLUDE_DIR ${LIBLZMA_INCLUDE_DIRS})
+ set(LZMA_LIBRARY ${LIBLZMA_LIBRARIES})
+ else()
+ add_subdirectory(Utilities/cmliblzma)
+ CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
+ set(LZMA_INCLUDE_DIR
+ "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
+ set(LZMA_LIBRARY cmliblzma)
+ endif()
+
+ #---------------------------------------------------------------------
+ # Build or use system libarchive for CMake and CTest.
+ if(CMAKE_USE_SYSTEM_LIBARCHIVE)
+ find_package(LibArchive)
+ if(NOT LibArchive_FOUND)
+ message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
+ endif()
+ set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
+ set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
+ else()
+ set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
+ set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
+ add_definitions(-DLIBARCHIVE_STATIC)
+ set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
+ set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
+ 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_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")
+ add_subdirectory(Utilities/cmlibarchive)
+ CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
+ set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
+ endif()
+
+ #---------------------------------------------------------------------
+ # Build expat library for CMake and CTest.
+ if(CMAKE_USE_SYSTEM_EXPAT)
+ find_package(EXPAT)
+ if(NOT EXPAT_FOUND)
+ message(FATAL_ERROR
+ "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
+ endif()
+ set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
+ set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
+ else()
+ set(CMAKE_EXPAT_INCLUDES)
+ set(CMAKE_EXPAT_LIBRARIES cmexpat)
+ add_subdirectory(Utilities/cmexpat)
+ CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
+ endif()
+
+ #---------------------------------------------------------------------
+ # Build XMLRPC library for CMake and CTest.
+ if(CTEST_USE_XMLRPC)
+ find_package(XMLRPC QUIET REQUIRED libwww-client)
+ if(NOT XMLRPC_FOUND)
+ message(FATAL_ERROR
+ "CTEST_USE_XMLRPC is ON but xmlrpc is not found!")
+ endif()
+ set(CMAKE_XMLRPC_INCLUDES ${XMLRPC_INCLUDE_DIRS})
+ set(CMAKE_XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES})
+ endif()
+
+ #---------------------------------------------------------------------
+ # Use curses?
+ if (UNIX)
+ # there is a bug in the Syllable libraries which makes linking ccmake fail, Alex
+ if(NOT CMAKE_SYSTEM_NAME MATCHES syllable)
+ set(CURSES_NEED_NCURSES TRUE)
+ find_package(Curses QUIET)
+ if (CURSES_LIBRARY)
+ option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" ON)
+ else ()
+ message("Curses libraries were not found. Curses GUI for CMake will not be built.")
+ set(BUILD_CursesDialog 0)
+ endif ()
+ else()
+ set(BUILD_CursesDialog 0)
+ endif()
+ else ()
+ set(BUILD_CursesDialog 0)
+ endif ()
+ if(BUILD_CursesDialog)
+ add_subdirectory(Source/CursesDialog/form)
+ endif()
+endmacro ()
+
+#-----------------------------------------------------------------------
+if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
+ execute_process(COMMAND ${CMAKE_CXX_COMPILER}
+ ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
+ OUTPUT_VARIABLE _GXX_VERSION
+ )
+ string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
+ _GXX_VERSION_SHORT ${_GXX_VERSION})
+ if(_GXX_VERSION_SHORT EQUAL 33)
+ message(FATAL_ERROR
+ "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
+ "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
+ "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
+ endif()
+ endif()
+endif()
+
+#-----------------------------------------------------------------------
+# The main section of the CMakeLists file
#
-# Optional settings are as follows:
+#-----------------------------------------------------------------------
+# Compute CMake_VERSION, etc.
+include(Source/CMakeVersionCompute.cmake)
+
+# Include the standard Dart testing module
+enable_testing()
+include (${CMAKE_ROOT}/Modules/Dart.cmake)
+
+# Set up test-time configuration.
+set_directory_properties(PROPERTIES
+ TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
+
+if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ # where to write the resulting executables and libraries
+ set(BUILD_SHARED_LIBS OFF)
+ set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
+ set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
+ "Where to put the libraries for CMake")
+
+ # The CMake executables usually do not need any rpath to run in the build or
+ # install tree.
+ set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
+
+ # Load install destinations.
+ include(Source/CMakeInstallDestinations.cmake)
+
+ if(BUILD_TESTING)
+ include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
+ endif()
+
+ # include special compile flags for some compilers
+ include(CompileFlags.cmake)
+
+ # no clue why we are testing for this here
+ include(CheckSymbolExists)
+ CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
+ CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
+endif()
+
+# CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
#
-# KWIML_HEADER_ROOT = build tree directory to hold KWIML headers.
-# Headers will go in a directory called "${KWIML}" under this root.
-# For example:
+# If not defined or "", this variable defaults to the server at
+# "http://open.cdash.org".
#
-# SET(KWIML_HEADER_ROOT ${PROJECT_BINARY_DIR})
-# INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
+# If set explicitly to "NOTFOUND", curl tests and ctest tests that use
+# the network are skipped.
#
-# 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.
+# If set to something starting with "http://localhost/", the CDash is
+# expected to be an instance of CDash used for CDash testing, pointing
+# to a cdash4simpletest database. In these cases, the CDash dashboards
+# should be run first.
#
-# KWIML_LABELS_TEST = list of labels for KWIML tests
+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(NOT CMake_TEST_EXTERNAL_CMAKE)
+ # build the utilities (a macro defined in this file)
+ CMAKE_BUILD_UTILITIES()
-cmake_minimum_required(VERSION 2.6.3 FATAL_ERROR)
+ # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
+ # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
+ # which isn't in the default linker search path. So without RPATH ccmake
+ # doesn't run and the build doesn't succeed since ccmake is executed for
+ # generating the documentation.
+ if(BUILD_CursesDialog)
+ get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
+ set(CURSES_NEED_RPATH FALSE)
+ if(NOT "${_CURSES_DIR}" STREQUAL "/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/lib64" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib64")
+ set(CURSES_NEED_RPATH TRUE)
+ endif()
+ endif()
+
+ if(BUILD_QtDialog)
+ if(APPLE)
+ set(CMAKE_BUNDLE_VERSION
+ "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
+ set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
+ # make sure CMAKE_INSTALL_PREFIX ends in /
+ string(LENGTH "${CMAKE_INSTALL_PREFIX}" LEN)
+ math(EXPR LEN "${LEN} -1" )
+ string(SUBSTRING "${CMAKE_INSTALL_PREFIX}" ${LEN} 1 ENDCH)
+ if(NOT "${ENDCH}" STREQUAL "/")
+ set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
+ endif()
+ set(CMAKE_INSTALL_PREFIX
+ "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
+ endif()
-#-----------------------------------------------------------------------------
-if(NOT DEFINED KWIML)
- if(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
- message(FATAL_ERROR "Set KWIML namespace in parent directory!")
+ set(QT_NEED_RPATH FALSE)
+ if(NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib64" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib64")
+ set(QT_NEED_RPATH TRUE)
+ endif()
endif()
- set(KWIML KWIML)
- set(KWIML_STANDALONE 1)
- project(KWIML)
- include(CTest)
- mark_as_advanced(BUILD_TESTING)
+
+
+ # The same might be true on other systems for other libraries.
+ # Then only enable RPATH if we have are building at least with cmake 2.4,
+ # since this one has much better RPATH features than cmake 2.2.
+ # The executables are then built with the RPATH for the libraries outside
+ # the build tree, which is both the build and the install RPATH.
+ if (UNIX)
+ if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB
+ OR CMAKE_USE_SYSTEM_EXPAT OR CTEST_USE_XMLRPC OR CURSES_NEED_RPATH OR QT_NEED_RPATH)
+ set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
+ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+ set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
+ endif()
+ endif ()
+
+
+ # add the uninstall support
+ configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+ @ONLY)
+ add_custom_target(uninstall
+ "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
+
+ include (CMakeCPack.cmake)
+
endif()
-#-----------------------------------------------------------------------------
-get_property(KWIML_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
-foreach(lang ${KWIML_LANGUAGES})
- set(KWIML_LANGUAGE_${lang} 1)
-endforeach()
-if(NOT KWIML_LANGUAGE_C AND NOT KWIML_LANGUAGE_CXX)
- set(BUILD_TESTING OFF)
+# setup some Testing support (a macro defined in this file)
+CMAKE_SETUP_TESTING()
+
+if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ if(NOT CMake_VERSION_IS_RELEASE)
+ if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND
+ NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
+ set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
+ -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
+ -Wmissing-format-attribute -fno-common -Wundef
+ )
+ set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
+ -Wshadow -Wpointer-arith -Wformat-security -Wundef
+ )
+
+ foreach(FLAG_LANG C CXX)
+ foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
+ if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
+ set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
+ endif()
+ endforeach()
+ endforeach()
+
+ unset(C_FLAGS_LIST)
+ unset(CXX_FLAGS_LIST)
+ endif()
+ endif()
+
+ # build the remaining subdirectories
+ add_subdirectory(Source)
+ add_subdirectory(Utilities)
endif()
-#-----------------------------------------------------------------------------
-if(NOT KWIML_HEADER_ROOT)
- set(KWIML_HEADER_ROOT "${PROJECT_BINARY_DIR}")
+add_subdirectory(Tests)
+
+if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ if(BUILD_TESTING)
+ CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
+ endif()
+ CMAKE_SET_TARGET_FOLDER(cmw9xcom "Utilities/Win9xCompat")
+ if(TARGET documentation)
+ CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
+ endif()
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)
- add_subdirectory(test)
+
+# add a test
+add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
+ --system-information -G "${CMAKE_GENERATOR}" )
+
+if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ # Install license file as it requires.
+ install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
+
+ # Install script directories.
+ install(
+ DIRECTORY Help Modules Templates
+ DESTINATION ${CMAKE_DATA_DIR}
+ FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+ DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
+ GROUP_READ GROUP_EXECUTE
+ WORLD_READ WORLD_EXECUTE
+ PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
+ GROUP_READ GROUP_EXECUTE
+ WORLD_READ WORLD_EXECUTE
+ )
+
+ # Install auxiliary files integrating with other tools.
+ add_subdirectory(Auxiliary)
endif()
diff --git a/CMakeLogo.gif b/CMakeLogo.gif
new file mode 100644
index 0000000000..8426402a72
--- /dev/null
+++ b/CMakeLogo.gif
Binary files differ
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
new file mode 100644
index 0000000000..3499da889e
--- /dev/null
+++ b/CONTRIBUTING.rst
@@ -0,0 +1,34 @@
+Contributing to CMake
+*********************
+
+Community
+=========
+
+CMake is maintained and supported by `Kitware`_ and developed in
+collaboration with a productive community of contributors.
+
+.. _`Kitware`: http://www.kitware.com/cmake
+
+The preferred entry point for new contributors is the mailing list.
+Please subscribe and post to the `CMake Developers List`_ to offer
+contributions. Regular and productive contributors may be invited
+to gain direct push access.
+
+.. _`CMake Developers List`: http://www.cmake.org/mailman/listinfo/cmake-developers
+
+Patches
+=======
+
+Please base all new work on the ``master`` branch. Then use
+``git format-patch`` to produce patches suitable to post to
+the mailing list.
+
+License
+=======
+
+We do not require any formal copyright assignment or contributor license
+agreement. Any contributions intentionally sent upstream are presumed
+to be offerred under terms of the OSI-approved BSD 3-clause License.
+See `Copyright.txt`_ for details.
+
+.. _`Copyright.txt`: Copyright.txt
diff --git a/CTestConfig.cmake b/CTestConfig.cmake
new file mode 100644
index 0000000000..df2f94c2a6
--- /dev/null
+++ b/CTestConfig.cmake
@@ -0,0 +1,20 @@
+#=============================================================================
+# 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.
+#=============================================================================
+set(CTEST_PROJECT_NAME "CMake")
+set(CTEST_NIGHTLY_START_TIME "1:00:00 UTC")
+
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=CMake")
+set(CTEST_DROP_SITE_CDASH TRUE)
+set(CTEST_CDASH_VERSION "1.6")
+set(CTEST_CDASH_QUERY_VERSION TRUE)
diff --git a/CTestCustom.cmake.in b/CTestCustom.cmake.in
new file mode 100644
index 0000000000..f499be1d9b
--- /dev/null
+++ b/CTestCustom.cmake.in
@@ -0,0 +1,93 @@
+set(CTEST_CUSTOM_ERROR_MATCH
+ ${CTEST_CUSTOM_ERROR_MATCH}
+ "ERROR:")
+
+set(CTEST_CUSTOM_WARNING_EXCEPTION
+ ${CTEST_CUSTOM_WARNING_EXCEPTION}
+ "xtree.[0-9]+. : warning C4702: unreachable code"
+ "warning LNK4221"
+ "warning LNK4204" # Occurs by race condition with objects in small libs
+ "variable .var_args[2]*. is used before its value is set"
+ "jobserver unavailable"
+ "warning: \\(Long double usage is reported only once for each file"
+ "warning: To disable this warning use"
+ "could not be inlined"
+ "libcmcurl.*has no symbols"
+ "not sorted slower link editing will result"
+ "stl_deque.h:479"
+ "Utilities.cmzlib."
+ "Utilities.cmbzip2."
+ "Source.CTest.Curl"
+ "Source.CursesDialog.form"
+ "Source.cm_sha2.*warning.*cast increases required alignment of target type"
+ "Utilities.cmcurl"
+ "Utilities.cmexpat."
+ "Utilities.cmlibarchive"
+ "/usr/include.*warning.*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"
+ "Clock skew detected"
+ "remark\\(1209"
+ "remark: .*LOOP WAS VECTORIZED"
+ "warning .980: wrong number of actual arguments to intrinsic function .std::basic_"
+ "LINK : warning LNK4089: all references to.*ADVAPI32.dll.*discarded by /OPT:REF"
+ "LINK : warning LNK4089: all references to.*PSAPI.DLL.*discarded by /OPT:REF"
+ "LINK : warning LNK4089: all references to.*SHELL32.dll.*discarded by /OPT:REF"
+ "LINK : warning LNK4089: all references to.*USER32.dll.*discarded by /OPT:REF"
+ "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.*"
+ "Warning: public.*_archive.*clashes with prior module.*"
+ "Warning: LINN32: Last line.*is less.*"
+ "Warning: Olimit was exceeded on function.*"
+ "Warning: To override Olimit for all functions in file.*"
+ "warning.*directory name.*CMake-Xcode.*/bin/.*does not exist.*"
+ "stl_deque.h:1051"
+ "(Lexer|Parser).*warning.*conversion.*may (alter its value|change the sign)"
+ "(Lexer|Parser).*warning.*(statement is unreachable|will never be executed)"
+ "PGC-W-0095-Type cast required for this conversion.*ProcessUNIX.c"
+ "[Qq]t([Cc]ore|[Gg]ui|[Ww]idgets).*warning.*conversion.*may alter its value"
+ "warning:.*is.*very unsafe.*consider using.*"
+ "warning:.*is.*misused, please use.*"
+ "CMakeSetupManifest.xml.*manifest authoring warning.*Unrecognized Element"
+ "cc-3968 CC: WARNING File.*" # "implicit" truncation by static_cast
+ "ld: warning: directory not found for option .-(F|L)"
+ "warning.*This version of Mac OS X is unsupported"
+ "clang.*: warning: argument unused during compilation: .-g"
+ "note: in expansion of macro" # diagnostic context note
+ "cm(StringCommand|CTestTestHandler)\\.cxx.*warning.*rand.*isn.*t random" # we do not do crypto
+ "cm(StringCommand|CTestTestHandler)\\.cxx.*warning.*srand.*seed choices are.*poor" # we do not do crypto
+
+ # Ignore clang's summary warning, assuming prior text has matched some
+ # other warning expression:
+ "[0-9,]+ warnings? generated."
+ )
+
+if(NOT "@CMAKE_GENERATOR@" MATCHES "Xcode")
+ set(CTEST_CUSTOM_COVERAGE_EXCLUDE
+ ${CTEST_CUSTOM_COVERAGE_EXCLUDE}
+ "XCode"
+ )
+endif ()
+
+if(NOT "@CMAKE_GENERATOR@" MATCHES "KDevelop")
+ set(CTEST_CUSTOM_COVERAGE_EXCLUDE
+ ${CTEST_CUSTOM_COVERAGE_EXCLUDE}
+ "Kdevelop"
+ )
+endif ()
+
+set(CTEST_CUSTOM_COVERAGE_EXCLUDE
+ ${CTEST_CUSTOM_COVERAGE_EXCLUDE}
+
+ # Exclude kwsys files from coverage results. They are reported
+ # (with better coverage results) on kwsys dashboards...
+ "/Source/(cm|kw)sys/"
+
+ # Exclude try_compile sources from coverage results:
+ "/CMakeFiles/CMakeTmp/"
+
+ # Exclude Qt source files from coverage results:
+ "[A-Za-z]./[Qq]t/qt-.+-opensource-src"
+ )
diff --git a/CompileFlags.cmake b/CompileFlags.cmake
new file mode 100644
index 0000000000..a4a4a78c98
--- /dev/null
+++ b/CompileFlags.cmake
@@ -0,0 +1,83 @@
+#=============================================================================
+# 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.
+#=============================================================================
+
+#-----------------------------------------------------------------------------
+# set some special flags for different compilers
+#
+if(CMAKE_GENERATOR MATCHES "Visual Studio 7")
+ set(CMAKE_SKIP_COMPATIBILITY_TESTS 1)
+endif()
+if(CMAKE_GENERATOR MATCHES "Visual Studio 6")
+ set(CMAKE_SKIP_COMPATIBILITY_TESTS 1)
+endif()
+
+if(WIN32 AND "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")
+ set(_INTEL_WINDOWS 1)
+endif()
+
+# Disable deprecation warnings for standard C functions.
+# really only needed for newer versions of VS, but should
+# not hurt other versions, and this will work into the
+# future
+if(MSVC OR _INTEL_WINDOWS)
+ add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
+else()
+endif()
+
+#silence duplicate symbol warnings on AIX
+if(CMAKE_SYSTEM_NAME MATCHES "AIX")
+ if(NOT CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -bhalt:5 ")
+ endif()
+endif()
+
+if(CMAKE_SYSTEM_NAME MATCHES "IRIX")
+ if(NOT CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-woff84 -no_auto_include")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-woff15")
+ endif()
+endif()
+
+if(CMAKE_SYSTEM MATCHES "OSF1-V")
+ if(NOT CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local -no_implicit_include ")
+ endif()
+endif()
+
+if(CMAKE_SYSTEM_NAME MATCHES "HP-UX" AND CMAKE_CXX_COMPILER_ID MATCHES "HP")
+ # HP aCC since version 3.80 supports the flag +hpxstd98 to get ANSI C++98
+ # template support. It is known that version 6.25 doesn't need that flag.
+ # Versions prior to 3.80 will not be able to build CMake. Current assumption:
+ # it is needed for every version from 3.80 to 4 to get it working.
+ if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4 AND
+ NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.80)
+ # use new C++ library and improved template support
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA +hpxstd98")
+ endif()
+endif()
+
+# use the ansi CXX compile flag for building cmake
+if (CMAKE_ANSI_CXXFLAGS)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")
+endif ()
+
+if (CMAKE_ANSI_CFLAGS)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
+endif ()
+
+# avoid binutils problem with large binaries, e.g. when building CMake in debug mode
+# See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50230
+if (CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_SYSTEM_PROCESSOR STREQUAL parisc)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--unique=.text._*")
+endif ()
+
+include (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityCXX.cmake)
diff --git a/Copyright.txt b/Copyright.txt
index c1e5ebc3fa..214d7dea8e 100644
--- a/Copyright.txt
+++ b/Copyright.txt
@@ -1,5 +1,6 @@
-Kitware Information Macro Library
-Copyright 2010-2011 Kitware, Inc.
+CMake - Cross Platform Makefile Generator
+Copyright 2000-2014 Kitware, Inc.
+Copyright 2000-2011 Insight Software Consortium
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -13,9 +14,10 @@ are met:
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.
+* Neither the names of Kitware, Inc., the Insight Software Consortium,
+ nor the names of their 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
@@ -28,3 +30,28 @@ 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.
+
+------------------------------------------------------------------------------
+
+The above copyright and license notice applies to distributions of
+CMake in source and binary form. Some source files contain additional
+notices of original copyright by their contributors; see each source
+for details. Third-party software packages supplied with CMake under
+compatible licenses provide their own copyright notices documented in
+corresponding subdirectories.
+
+------------------------------------------------------------------------------
+
+CMake was initially developed by Kitware with the following sponsorship:
+
+ * National Library of Medicine at the National Institutes of Health
+ as part of the Insight Segmentation and Registration Toolkit (ITK).
+
+ * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel
+ Visualization Initiative.
+
+ * National Alliance for Medical Image Computing (NAMIC) is funded by the
+ National Institutes of Health through the NIH Roadmap for Medical Research,
+ Grant U54 EB005149.
+
+ * Kitware, Inc.
diff --git a/DartConfig.cmake b/DartConfig.cmake
new file mode 100644
index 0000000000..92dffca7aa
--- /dev/null
+++ b/DartConfig.cmake
@@ -0,0 +1,18 @@
+#=============================================================================
+# 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.
+#=============================================================================
+set(CTEST_PROJECT_NAME "CMake")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=CMake")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Help/command/FIND_XXX.txt b/Help/command/FIND_XXX.txt
new file mode 100644
index 0000000000..5889e90099
--- /dev/null
+++ b/Help/command/FIND_XXX.txt
@@ -0,0 +1,101 @@
+A short-hand signature is:
+
+.. parsed-literal::
+
+ |FIND_XXX| (<VAR> name1 [path1 path2 ...])
+
+The general signature is:
+
+.. parsed-literal::
+
+ |FIND_XXX| (
+ <VAR>
+ name | |NAMES|
+ [HINTS path1 [path2 ... ENV var]]
+ [PATHS path1 [path2 ... ENV var]]
+ [PATH_SUFFIXES suffix1 [suffix2 ...]]
+ [DOC "cache documentation string"]
+ [NO_DEFAULT_PATH]
+ [NO_CMAKE_ENVIRONMENT_PATH]
+ [NO_CMAKE_PATH]
+ [NO_SYSTEM_ENVIRONMENT_PATH]
+ [NO_CMAKE_SYSTEM_PATH]
+ [CMAKE_FIND_ROOT_PATH_BOTH |
+ ONLY_CMAKE_FIND_ROOT_PATH |
+ NO_CMAKE_FIND_ROOT_PATH]
+ )
+
+This command is used to find a |SEARCH_XXX_DESC|.
+A cache entry named by ``<VAR>`` is created to store the result
+of this command.
+If the |SEARCH_XXX| is found the result is stored in the variable
+and the search will not be repeated unless the variable is cleared.
+If nothing is found, the result will be
+``<VAR>-NOTFOUND``, and the search will be attempted again the
+next time |FIND_XXX| is invoked with the same variable.
+The name of the |SEARCH_XXX| that
+is searched for is specified by the names listed
+after the NAMES argument. Additional search locations
+can be specified after the PATHS argument. If ENV var is
+found in the HINTS or PATHS section the environment variable var
+will be read and converted from a system environment variable to
+a cmake style list of paths. For example ENV PATH would be a way
+to list the system path variable. The argument
+after DOC will be used for the documentation string in
+the cache.
+PATH_SUFFIXES specifies additional subdirectories to check below
+each search path.
+
+If NO_DEFAULT_PATH is specified, then no additional paths are
+added to the search.
+If NO_DEFAULT_PATH is not specified, the search process is as follows:
+
+.. |CMAKE_PREFIX_PATH_XXX_SUBDIR| replace::
+ <prefix>/|XXX_SUBDIR| for each <prefix> in CMAKE_PREFIX_PATH
+
+.. |CMAKE_SYSTEM_PREFIX_PATH_XXX_SUBDIR| replace::
+ <prefix>/|XXX_SUBDIR| for each <prefix> in CMAKE_SYSTEM_PREFIX_PATH
+
+1. Search paths specified in cmake-specific cache variables.
+ These are intended to be used on the command line with a -DVAR=value.
+ This can be skipped if NO_CMAKE_PATH is passed.
+
+ * |CMAKE_PREFIX_PATH_XXX|
+ * |CMAKE_XXX_PATH|
+ * |CMAKE_XXX_MAC_PATH|
+
+2. Search paths specified in cmake-specific environment variables.
+ These are intended to be set in the user's shell configuration.
+ This can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.
+
+ * |CMAKE_PREFIX_PATH_XXX|
+ * |CMAKE_XXX_PATH|
+ * |CMAKE_XXX_MAC_PATH|
+
+3. Search the paths specified by the HINTS option.
+ These should be paths computed by system introspection, such as a
+ hint provided by the location of another item already found.
+ Hard-coded guesses should be specified with the PATHS option.
+
+4. Search the standard system environment variables.
+ This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.
+
+ * |SYSTEM_ENVIRONMENT_PATH_XXX|
+
+5. Search cmake variables defined in the Platform files
+ for the current system. This can be skipped if NO_CMAKE_SYSTEM_PATH
+ is passed.
+
+ * |CMAKE_SYSTEM_PREFIX_PATH_XXX|
+ * |CMAKE_SYSTEM_XXX_PATH|
+ * |CMAKE_SYSTEM_XXX_MAC_PATH|
+
+6. Search the paths specified by the PATHS option
+ or in the short-hand version of the command.
+ These are typically hard-coded guesses.
+
+.. |FIND_ARGS_XXX| replace:: <VAR> NAMES name
+
+.. include:: FIND_XXX_MAC.txt
+.. include:: FIND_XXX_ROOT.txt
+.. include:: FIND_XXX_ORDER.txt
diff --git a/Help/command/FIND_XXX_MAC.txt b/Help/command/FIND_XXX_MAC.txt
new file mode 100644
index 0000000000..eb3900cbbb
--- /dev/null
+++ b/Help/command/FIND_XXX_MAC.txt
@@ -0,0 +1,24 @@
+On Darwin or systems supporting OS X Frameworks, the cmake variable
+CMAKE_FIND_FRAMEWORK can be set to empty or one of the following:
+
+* FIRST: Try to find frameworks before standard libraries or headers.
+ This is the default on Darwin.
+
+* LAST: Try to find frameworks after standard libraries or headers.
+
+* ONLY: Only try to find frameworks.
+
+* NEVER: Never try to find frameworks.
+
+On Darwin or systems supporting OS X Application Bundles, the cmake
+variable CMAKE_FIND_APPBUNDLE can be set to empty or one of the
+following:
+
+* FIRST: Try to find application bundles before standard programs.
+ This is the default on Darwin.
+
+* LAST: Try to find application bundles after standard programs.
+
+* ONLY: Only try to find application bundles.
+
+* NEVER: Never try to find application bundles.
diff --git a/Help/command/FIND_XXX_ORDER.txt b/Help/command/FIND_XXX_ORDER.txt
new file mode 100644
index 0000000000..bac2419645
--- /dev/null
+++ b/Help/command/FIND_XXX_ORDER.txt
@@ -0,0 +1,12 @@
+The default search order is designed to be most-specific to
+least-specific for common use cases.
+Projects may override the order by simply calling the command
+multiple times and using the ``NO_*`` options:
+
+.. parsed-literal::
+
+ |FIND_XXX| (|FIND_ARGS_XXX| PATHS paths... NO_DEFAULT_PATH)
+ |FIND_XXX| (|FIND_ARGS_XXX|)
+
+Once one of the calls succeeds the result variable will be set
+and stored in the cache so that no call will search again.
diff --git a/Help/command/FIND_XXX_ROOT.txt b/Help/command/FIND_XXX_ROOT.txt
new file mode 100644
index 0000000000..b5cab68b8a
--- /dev/null
+++ b/Help/command/FIND_XXX_ROOT.txt
@@ -0,0 +1,23 @@
+The CMake variable :variable:`CMAKE_FIND_ROOT_PATH` specifies one or more
+directories to be prepended to all other search directories. This
+effectively "re-roots" the entire search under given locations.
+Paths which are descendants of the :variable:`CMAKE_STAGING_PREFIX` are excluded
+from this re-rooting, because that variable is always a path on the host system.
+By default the :variable:`CMAKE_FIND_ROOT_PATH` is empty.
+
+The :variable:`CMAKE_SYSROOT` variable can also be used to specify exactly one
+directory to use as a prefix. Setting :variable:`CMAKE_SYSROOT` also has other
+effects. See the documentation for that variable for more.
+
+These variables are especially useful when cross-compiling to
+point to the root directory of the target environment and CMake will
+search there too. By default at first the directories listed in
+:variable:`CMAKE_FIND_ROOT_PATH` are searched, then the :variable:`CMAKE_SYSROOT`
+directory is searched, and then the non-rooted directories will be
+searched. The default behavior can be adjusted by setting
+|CMAKE_FIND_ROOT_PATH_MODE_XXX|. This behavior can be manually
+overridden on a per-call basis. By using CMAKE_FIND_ROOT_PATH_BOTH
+the search order will be as described above. If
+NO_CMAKE_FIND_ROOT_PATH is used then :variable:`CMAKE_FIND_ROOT_PATH` will not be
+used. If ONLY_CMAKE_FIND_ROOT_PATH is used then only the re-rooted
+directories and directories below :variable:`CMAKE_STAGING_PREFIX` will be searched.
diff --git a/Help/command/add_compile_options.rst b/Help/command/add_compile_options.rst
new file mode 100644
index 0000000000..214f4bef33
--- /dev/null
+++ b/Help/command/add_compile_options.rst
@@ -0,0 +1,22 @@
+add_compile_options
+-------------------
+
+Adds options to the compilation of source files.
+
+::
+
+ add_compile_options(<option> ...)
+
+Adds options to the compiler command line for sources in the current
+directory and below. This command can be used to add any options, but
+alternative commands exist to add preprocessor definitions
+(:command:`target_compile_definitions` and :command:`add_definitions`) or
+include directories (:command:`target_include_directories` and
+:command:`include_directories`). See documentation of the
+:prop_tgt:`directory <COMPILE_OPTIONS>` and
+:prop_tgt:`target <COMPILE_OPTIONS>` ``COMPILE_OPTIONS`` properties.
+
+Arguments to ``add_compile_options`` 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/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst
new file mode 100644
index 0000000000..e8b7cc8f5e
--- /dev/null
+++ b/Help/command/add_custom_command.rst
@@ -0,0 +1,169 @@
+add_custom_command
+------------------
+
+Add a custom build rule to the generated build system.
+
+There are two main signatures for ``add_custom_command``.
+
+Generating Files
+^^^^^^^^^^^^^^^^
+
+The first signature is for adding a custom command to produce an output::
+
+ add_custom_command(OUTPUT output1 [output2 ...]
+ COMMAND command1 [ARGS] [args1...]
+ [COMMAND command2 [ARGS] [args2...] ...]
+ [MAIN_DEPENDENCY depend]
+ [DEPENDS [depends...]]
+ [IMPLICIT_DEPENDS <lang1> depend1
+ [<lang2> depend2] ...]
+ [WORKING_DIRECTORY dir]
+ [COMMENT comment] [VERBATIM] [APPEND])
+
+This defines a command to generate specified ``OUTPUT`` file(s).
+A target created in the same directory (``CMakeLists.txt`` file)
+that specifies any output of the custom command as a source file
+is given a rule to generate the file using the command at build time.
+Do not list the output in more than one independent target that
+may build in parallel or the two instances of the rule may conflict
+(instead use the :command:`add_custom_target` command to drive the
+command and make the other targets depend on that one).
+In makefile terms this creates a new target in the following form::
+
+ OUTPUT: MAIN_DEPENDENCY DEPENDS
+ COMMAND
+
+The options are:
+
+``APPEND``
+ Append the ``COMMAND`` and ``DEPENDS`` option values to the custom
+ command for the first output specified. There must have already
+ been a previous call to this command with the same output.
+ The ``COMMENT``, ``MAIN_DEPENDENCY``, and ``WORKING_DIRECTORY``
+ options are currently ignored when APPEND is given, but may be
+ used in the future.
+
+``COMMAND``
+ Specify the command-line(s) to execute at build time.
+ If more than one ``COMMAND`` is specified they will be executed in order,
+ but *not* necessarily composed into a stateful shell or batch script.
+ (To run a full script, use the :command:`configure_file` command or the
+ :command:`file(GENERATE)` command to create it, and then specify
+ a ``COMMAND`` to launch it.)
+ The optional ``ARGS`` argument is for backward compatibility and
+ will be ignored.
+
+ If ``COMMAND`` specifies an executable target (created by the
+ :command:`add_executable` command) it will automatically be replaced
+ by the location of the executable created at build time.
+ Additionally a target-level dependency will be added so that the
+ executable target will be built before any target using this custom
+ command. However this does NOT add a file-level dependency that
+ would cause the custom command to re-run whenever the executable is
+ recompiled.
+
+ Arguments to ``COMMAND`` may use
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+ References to target names in generator expressions imply target-level
+ dependencies, but NOT file-level dependencies. List target names with
+ the ``DEPENDS`` option to add file-level dependencies.
+
+``COMMENT``
+ Display the given message before the commands are executed at
+ build time.
+
+``DEPENDS``
+ Specify files on which the command depends. If any dependency is
+ an ``OUTPUT`` of another custom command in the same directory
+ (``CMakeLists.txt`` file) CMake automatically brings the other
+ custom command into the target in which this command is built.
+ If ``DEPENDS`` is not specified the command will run whenever
+ the ``OUTPUT`` is missing; if the command does not actually
+ create the ``OUTPUT`` then the rule will always run.
+ If ``DEPENDS`` specifies any target (created by the
+ :command:`add_custom_target`, :command:`add_executable`, or
+ :command:`add_library` command) a target-level dependency is
+ created to make sure the target is built before any target
+ using this custom command. Additionally, if the target is an
+ executable or library a file-level dependency is created to
+ cause the custom command to re-run whenever the target is
+ recompiled.
+
+ Arguments to ``DEPENDS`` may use
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+``IMPLICIT_DEPENDS``
+ Request scanning of implicit dependencies of an input file.
+ The language given specifies the programming language whose
+ corresponding dependency scanner should be used.
+ Currently only ``C`` and ``CXX`` language scanners are supported.
+ The language has to be specified for every file in the
+ ``IMPLICIT_DEPENDS`` list. Dependencies discovered from the
+ scanning are added to those of the custom command at build time.
+ Note that the ``IMPLICIT_DEPENDS`` option is currently supported
+ only for Makefile generators and will be ignored by other generators.
+
+``MAIN_DEPENDENCY``
+ Specify the primary input source file to the command. This is
+ treated just like any value given to the ``DEPENDS`` option
+ but also suggests to Visual Studio generators where to hang
+ the custom command.
+
+``OUTPUT``
+ Specify the output files the command is expected to produce.
+ If an output name is a relative path it will be interpreted
+ relative to the build tree directory corresponding to the
+ current source directory.
+ If the output of the custom command is not actually created
+ as a file on disk it should be marked with the :prop_sf:`SYMBOLIC`
+ source file property.
+
+``VERBATIM``
+ All arguments to the commands will be escaped properly for the
+ build tool so that the invoked command receives each argument
+ unchanged. Note that one level of escapes is still used by the
+ CMake language processor before add_custom_command even sees the
+ arguments. Use of ``VERBATIM`` is recommended as it enables
+ correct behavior. When ``VERBATIM`` is not given the behavior
+ is platform specific because there is no protection of
+ tool-specific special characters.
+
+``WORKING_DIRECTORY``
+ Execute the command with the given current working directory.
+ If it is a relative path it will be interpreted relative to the
+ build tree directory corresponding to the current source directory.
+
+Build Events
+^^^^^^^^^^^^
+
+The second signature adds a custom command to a target such as a
+library or executable. This is useful for performing an operation
+before or after building the target. The command becomes part of the
+target and will only execute when the target itself is built. If the
+target is already built, the command will not execute.
+
+::
+
+ add_custom_command(TARGET target
+ PRE_BUILD | PRE_LINK | POST_BUILD
+ COMMAND command1 [ARGS] [args1...]
+ [COMMAND command2 [ARGS] [args2...] ...]
+ [WORKING_DIRECTORY dir]
+ [COMMENT comment] [VERBATIM])
+
+This defines a new command that will be associated with building the
+specified target. When the command will happen is determined by which
+of the following is specified:
+
+``PRE_BUILD``
+ Run before any other rules are executed within the target.
+ This is supported only on Visual Studio 7 or later.
+ For all other generators ``PRE_BUILD`` will be treated as
+ ``PRE_LINK``.
+``PRE_LINK``
+ Run after sources have been compiled but before linking the binary
+ or running the librarian or archiver tool of a static library.
+ This is not defined for targets created by the
+ :command:`add_custom_target` command.
+``POST_BUILD``
+ Run after all other rules within the target have been executed.
diff --git a/Help/command/add_custom_target.rst b/Help/command/add_custom_target.rst
new file mode 100644
index 0000000000..1bf70bffd9
--- /dev/null
+++ b/Help/command/add_custom_target.rst
@@ -0,0 +1,45 @@
+add_custom_target
+-----------------
+
+Add a target with no output so it will always be built.
+
+::
+
+ add_custom_target(Name [ALL] [command1 [args1...]]
+ [COMMAND command2 [args2...] ...]
+ [DEPENDS depend depend depend ... ]
+ [WORKING_DIRECTORY dir]
+ [COMMENT comment] [VERBATIM]
+ [SOURCES src1 [src2...]])
+
+Adds a target with the given name that executes the given commands.
+The target has no output file and is ALWAYS CONSIDERED OUT OF DATE
+even if the commands try to create a file with the name of the target.
+Use ADD_CUSTOM_COMMAND to generate a file with dependencies. By
+default nothing depends on the custom target. Use ADD_DEPENDENCIES to
+add dependencies to or from other targets. If the ALL option is
+specified it indicates that this target should be added to the default
+build target so that it will be run every time (the command cannot be
+called ALL). The command and arguments are optional and if not
+specified an empty target will be created. If WORKING_DIRECTORY is
+set, then the command will be run in that directory. If it is a
+relative path it will be interpreted relative to the build tree
+directory corresponding to the current source directory. If COMMENT
+is set, the value will be displayed as a message before the commands
+are executed at build time. Dependencies listed with the DEPENDS
+argument may reference files and outputs of custom commands created
+with add_custom_command() in the same directory (CMakeLists.txt file).
+
+If VERBATIM is given then all arguments to the commands will be
+escaped properly for the build tool so that the invoked command
+receives each argument unchanged. Note that one level of escapes is
+still used by the CMake language processor before add_custom_target
+even sees the arguments. Use of VERBATIM is recommended as it enables
+correct behavior. When VERBATIM is not given the behavior is platform
+specific because there is no protection of tool-specific special
+characters.
+
+The SOURCES option specifies additional source files to be included in
+the custom target. Specified source files will be added to IDE
+project files for convenience in editing even if they have not build
+rules.
diff --git a/Help/command/add_definitions.rst b/Help/command/add_definitions.rst
new file mode 100644
index 0000000000..2965c3774a
--- /dev/null
+++ b/Help/command/add_definitions.rst
@@ -0,0 +1,25 @@
+add_definitions
+---------------
+
+Adds -D define flags to the compilation of source files.
+
+::
+
+ add_definitions(-DFOO -DBAR ...)
+
+Adds definitions to the compiler command line for sources in the current
+directory and below. This command can be used to add any flags, but
+it is intended to add preprocessor definitions. Flags
+beginning in -D or /D that look like preprocessor definitions are
+automatically added to the :prop_dir:`COMPILE_DEFINITIONS` directory
+property for the current directory. Definitions with non-trivial values
+may be left in the set of flags instead of being converted for reasons of
+backwards compatibility. See documentation of the
+:prop_dir:`directory <COMPILE_DEFINITIONS>`,
+:prop_tgt:`target <COMPILE_DEFINITIONS>`,
+:prop_sf:`source file <COMPILE_DEFINITIONS>` ``COMPILE_DEFINITIONS``
+properties for details on adding preprocessor definitions to specific
+scopes and configurations.
+
+See the :manual:`cmake-buildsystem(7)` manual for more on defining
+buildsystem properties.
diff --git a/Help/command/add_dependencies.rst b/Help/command/add_dependencies.rst
new file mode 100644
index 0000000000..10997ec206
--- /dev/null
+++ b/Help/command/add_dependencies.rst
@@ -0,0 +1,19 @@
+add_dependencies
+----------------
+
+Add a dependency between top-level targets.
+
+::
+
+ add_dependencies(<target> [<target-dependency>]...)
+
+Make a top-level <target> depend on other top-level targets to ensure
+that they build before <target> does. A top-level target is one
+created by ADD_EXECUTABLE, ADD_LIBRARY, or ADD_CUSTOM_TARGET.
+Dependencies added to an IMPORTED target are followed transitively in
+its place since the target itself does not build.
+
+See the DEPENDS option of ADD_CUSTOM_TARGET and ADD_CUSTOM_COMMAND for
+adding file-level dependencies in custom rules. See the
+OBJECT_DEPENDS option in SET_SOURCE_FILES_PROPERTIES to add file-level
+dependencies to object files.
diff --git a/Help/command/add_executable.rst b/Help/command/add_executable.rst
new file mode 100644
index 0000000000..4ed10e1cff
--- /dev/null
+++ b/Help/command/add_executable.rst
@@ -0,0 +1,80 @@
+add_executable
+--------------
+
+Add an executable to the project using the specified source files.
+
+::
+
+ add_executable(<name> [WIN32] [MACOSX_BUNDLE]
+ [EXCLUDE_FROM_ALL]
+ source1 [source2 ...])
+
+Adds an executable target called ``<name>`` to be built from the source
+files listed in the command invocation. The ``<name>`` corresponds to the
+logical target name and must be globally unique within a project. The
+actual file name of the executable built is constructed based on
+conventions of the native platform (such as ``<name>.exe`` or just
+``<name>``.
+
+By default the executable file will be created in the build tree
+directory corresponding to the source tree directory in which the
+command was invoked. See documentation of the
+:prop_tgt:`RUNTIME_OUTPUT_DIRECTORY` target property to change this
+location. See documentation of the :prop_tgt:`OUTPUT_NAME` target property
+to change the ``<name>`` part of the final file name.
+
+If ``WIN32`` is given the property :prop_tgt:`WIN32_EXECUTABLE` will be
+set on the target created. See documentation of that target property for
+details.
+
+If ``MACOSX_BUNDLE`` is given the corresponding property will be set on
+the created target. See documentation of the :prop_tgt:`MACOSX_BUNDLE`
+target property for details.
+
+If ``EXCLUDE_FROM_ALL`` is given the corresponding property will be set on
+the created target. See documentation of the :prop_tgt:`EXCLUDE_FROM_ALL`
+target property for details.
+
+Source arguments to ``add_executable`` 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.
+
+
+--------------------------------------------------------------------------
+
+::
+
+ add_executable(<name> IMPORTED [GLOBAL])
+
+An :ref:`IMPORTED executable target <Imported Targets>` references an
+executable file located outside the project. No rules are generated to
+build it, and the :prop_tgt:`IMPORTED` target property is ``True``. The
+target name has scope in the directory in which it is created and below, but
+the ``GLOBAL`` option extends visibility. It may be referenced like any
+target built within the project. ``IMPORTED`` executables are useful
+for convenient reference from commands like :command:`add_custom_command`.
+Details about the imported executable are specified by setting properties
+whose names begin in ``IMPORTED_``. The most important such property is
+:prop_tgt:`IMPORTED_LOCATION` (and its per-configuration version
+:prop_tgt:`IMPORTED_LOCATION_<CONFIG>`) which specifies the location of
+the main executable file on disk. See documentation of the ``IMPORTED_*``
+properties for more information.
+
+--------------------------------------------------------------------------
+
+::
+
+ add_executable(<name> ALIAS <target>)
+
+Creates an :ref:`Alias Target <Alias Targets>`, such that ``<name>`` can
+be used to refer to ``<target>`` in subsequent commands. The ``<name>``
+does not appear in the generated buildsystem as a make target. The
+``<target>`` may not be an :ref:`Imported Target <Imported Targets>` or an
+``ALIAS``. ``ALIAS`` targets can be used as targets to read properties
+from, executables for custom commands and custom targets. They can also be
+tested for existance with the regular :command:`if(TARGET)` subcommand.
+The ``<name>`` may not be used to modify properties of ``<target>``, that
+is, it may not be used as the operand of :command:`set_property`,
+:command:`set_target_properties`, :command:`target_link_libraries` etc.
+An ``ALIAS`` target may not be installed or exported.
diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst
new file mode 100644
index 0000000000..f86f3c5ec3
--- /dev/null
+++ b/Help/command/add_library.rst
@@ -0,0 +1,151 @@
+add_library
+-----------
+
+.. only:: html
+
+ .. contents::
+
+Add a library to the project using the specified source files.
+
+Normal Libraries
+^^^^^^^^^^^^^^^^
+
+::
+
+ add_library(<name> [STATIC | SHARED | MODULE]
+ [EXCLUDE_FROM_ALL]
+ source1 [source2 ...])
+
+Adds a library target called ``<name>`` to be built from the source files
+listed in the command invocation. The ``<name>`` corresponds to the
+logical target name and must be globally unique within a project. The
+actual file name of the library built is constructed based on
+conventions of the native platform (such as ``lib<name>.a`` or
+``<name>.lib``).
+
+``STATIC``, ``SHARED``, or ``MODULE`` may be given to specify the type of
+library to be created. ``STATIC`` libraries are archives of object files
+for use when linking other targets. ``SHARED`` libraries are linked
+dynamically and loaded at runtime. ``MODULE`` libraries are plugins that
+are not linked into other targets but may be loaded dynamically at runtime
+using dlopen-like functionality. If no type is given explicitly the
+type is ``STATIC`` or ``SHARED`` based on whether the current value of the
+variable :variable:`BUILD_SHARED_LIBS` is ``ON``. For ``SHARED`` and
+``MODULE`` libraries the :prop_tgt:`POSITION_INDEPENDENT_CODE` target
+property is set to ``ON`` automatically.
+
+By default the library file will be created in the build tree directory
+corresponding to the source tree directory in which thecommand was
+invoked. See documentation of the :prop_tgt:`ARCHIVE_OUTPUT_DIRECTORY`,
+:prop_tgt:`LIBRARY_OUTPUT_DIRECTORY`, and
+:prop_tgt:`RUNTIME_OUTPUT_DIRECTORY` target properties to change this
+location. See documentation of the :prop_tgt:`OUTPUT_NAME` target
+property to change the ``<name>`` part of the final file name.
+
+If ``EXCLUDE_FROM_ALL`` is given the corresponding property will be set on
+the created target. See documentation of the :prop_tgt:`EXCLUDE_FROM_ALL`
+target property for details.
+
+Source arguments to ``add_library`` 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.
+
+Imported Libraries
+^^^^^^^^^^^^^^^^^^
+
+::
+
+ add_library(<name> <SHARED|STATIC|MODULE|UNKNOWN> IMPORTED
+ [GLOBAL])
+
+An :ref:`IMPORTED library target <Imported Targets>` references a library
+file located outside the project. No rules are generated to build it, and
+the :prop_tgt:`IMPORTED` target property is ``True``. The target name has
+scope in the directory in which it is created and below, but the ``GLOBAL``
+option extends visibility. It may be referenced like any target built
+within the project. ``IMPORTED`` libraries are useful for convenient
+reference from commands like :command:`target_link_libraries`. Details
+about the imported library are specified by setting properties whose names
+begin in ``IMPORTED_`` and ``INTERFACE_``. The most important such
+property is :prop_tgt:`IMPORTED_LOCATION` (and its per-configuration
+variant :prop_tgt:`IMPORTED_LOCATION_<CONFIG>`) which specifies the
+location of the main library file on disk. See documentation of the
+``IMPORTED_*`` and ``INTERFACE_*`` properties for more information.
+
+Object Libraries
+^^^^^^^^^^^^^^^^
+
+::
+
+ add_library(<name> OBJECT <src>...)
+
+Creates an :ref:`Object Library <Object Libraries>`. An object library
+compiles source files but does not archive or link their object files into a
+library. Instead other targets created by :command:`add_library` or
+:command:`add_executable` may reference the objects using an expression of the
+form ``$<TARGET_OBJECTS:objlib>`` as a source, where ``objlib`` is the
+object library name. For example:
+
+.. code-block:: cmake
+
+ add_library(... $<TARGET_OBJECTS:objlib> ...)
+ add_executable(... $<TARGET_OBJECTS:objlib> ...)
+
+will include objlib's object files in a library and an executable
+along with those compiled from their own sources. Object libraries
+may contain only sources that compile, header files, and other files
+that would not affect linking of a normal library (e.g. ``.txt``).
+They may contain custom commands generating such sources, but not
+``PRE_BUILD``, ``PRE_LINK``, or ``POST_BUILD`` commands. Object libraries
+cannot be imported, exported, installed, or linked. Some native build
+systems may not like targets that have only object files, so consider
+adding at least one real source file to any target that references
+``$<TARGET_OBJECTS:objlib>``.
+
+Alias Libraries
+^^^^^^^^^^^^^^^
+
+::
+
+ add_library(<name> ALIAS <target>)
+
+Creates an :ref:`Alias Target <Alias Targets>`, such that ``<name>`` can be
+used to refer to ``<target>`` in subsequent commands. The ``<name>`` does
+not appear in the generatedbuildsystem as a make target. The ``<target>``
+may not be an :ref:`Imported Target <Imported Targets>` or an ``ALIAS``.
+``ALIAS`` targets can be used as linkable targets and as targets to
+read properties from. They can also be tested for existance with the
+regular :command:`if(TARGET)` subcommand. The ``<name>`` may not be used
+to modify properties of ``<target>``, that is, it may not be used as the
+operand of :command:`set_property`, :command:`set_target_properties`,
+:command:`target_link_libraries` etc. An ``ALIAS`` target may not be
+installed or exported.
+
+Interface Libraries
+^^^^^^^^^^^^^^^^^^^
+
+::
+
+ add_library(<name> INTERFACE [IMPORTED [GLOBAL]])
+
+Creates an :ref:`Interface Library <Interface Libraries>`. An ``INTERFACE``
+library target does not directly create build output, though it may
+have properties set on it and it may be installed, exported and
+imported. Typically the ``INTERFACE_*`` properties are populated on
+the interface target using the :command:`set_property`,
+:command:`target_link_libraries(INTERFACE)`,
+:command:`target_include_directories(INTERFACE)`,
+:command:`target_compile_options(INTERFACE)`,
+:command:`target_compile_definitions(INTERFACE)`,
+and :command:`target_sources(INTERFACE)` commands, and then it
+is used as an argument to :command:`target_link_libraries` like any other
+target.
+
+An ``INTERFACE`` :ref:`Imported Target <Imported Targets>` may also be
+created with this signature. An ``IMPORTED`` library target references a
+library defined outside the project. The target name has scope in the
+directory in which it is created and below, but the ``GLOBAL`` option
+extends visibility. It may be referenced like any target built within
+the project. ``IMPORTED`` libraries are useful for convenient reference
+from commands like :command:`target_link_libraries`.
diff --git a/Help/command/add_subdirectory.rst b/Help/command/add_subdirectory.rst
new file mode 100644
index 0000000000..29b50174c6
--- /dev/null
+++ b/Help/command/add_subdirectory.rst
@@ -0,0 +1,36 @@
+add_subdirectory
+----------------
+
+Add a subdirectory to the build.
+
+::
+
+ add_subdirectory(source_dir [binary_dir]
+ [EXCLUDE_FROM_ALL])
+
+Add a subdirectory to the build. The source_dir specifies the
+directory in which the source CMakeLists.txt and code files are
+located. If it is a relative path it will be evaluated with respect
+to the current directory (the typical usage), but it may also be an
+absolute path. The binary_dir specifies the directory in which to
+place the output files. If it is a relative path it will be evaluated
+with respect to the current output directory, but it may also be an
+absolute path. If binary_dir is not specified, the value of
+source_dir, before expanding any relative path, will be used (the
+typical usage). The CMakeLists.txt file in the specified source
+directory will be processed immediately by CMake before processing in
+the current input file continues beyond this command.
+
+If the EXCLUDE_FROM_ALL argument is provided then targets in the
+subdirectory will not be included in the ALL target of the parent
+directory by default, and will be excluded from IDE project files.
+Users must explicitly build targets in the subdirectory. This is
+meant for use when the subdirectory contains a separate part of the
+project that is useful but not necessary, such as a set of examples.
+Typically the subdirectory should contain its own project() command
+invocation so that a full build system will be generated in the
+subdirectory (such as a VS IDE solution file). Note that inter-target
+dependencies supercede this exclusion. If a target built by the
+parent project depends on a target in the subdirectory, the dependee
+target will be included in the parent project build system to satisfy
+the dependency.
diff --git a/Help/command/add_test.rst b/Help/command/add_test.rst
new file mode 100644
index 0000000000..7e7e6bddd7
--- /dev/null
+++ b/Help/command/add_test.rst
@@ -0,0 +1,59 @@
+add_test
+--------
+
+Add a test to the project to be run by :manual:`ctest(1)`.
+
+::
+
+ add_test(NAME <name> COMMAND <command> [<arg>...]
+ [CONFIGURATIONS <config>...]
+ [WORKING_DIRECTORY <dir>])
+
+Add a test called ``<name>``. The test name may not contain spaces,
+quotes, or other characters special in CMake syntax. The options are:
+
+``COMMAND``
+ Specify the test command-line. If ``<command>`` specifies an
+ executable target (created by :command:`add_executable`) it will
+ automatically be replaced by the location of the executable created
+ at build time.
+
+``CONFIGURATIONS``
+ Restrict execution of the test only to the named configurations.
+
+``WORKING_DIRECTORY``
+ Set the :prop_test:`WORKING_DIRECTORY` test property to
+ specify the working directory in which to execute the test.
+ If not specified the test will be run with the current working
+ directory set to the build directory corresponding to the
+ current source directory.
+
+The ``COMMAND`` and ``WORKING_DIRECTORY`` options may use "generator
+expressions" with the syntax ``$<...>``. See the
+:manual:`cmake-generator-expressions(7)` manual for available expressions.
+
+Example usage::
+
+ add_test(NAME mytest
+ COMMAND testDriver --config $<CONFIGURATION>
+ --exe $<TARGET_FILE:myexe>)
+
+This creates a test ``mytest`` whose command runs a ``testDriver`` tool
+passing the configuration name and the full path to the executable
+file produced by target ``myexe``.
+
+.. note::
+
+ CMake will generate tests only if the :command:`enable_testing`
+ command has been invoked. The :module:`CTest` module invokes the
+ command automatically when the ``BUILD_TESTING`` option is ``ON``.
+
+---------------------------------------------------------------------
+
+::
+
+ add_test(<name> <command> [<arg>...])
+
+Add a test called ``<name>`` with the given command-line. Unlike
+the above ``NAME`` signature no transformation is performed on the
+command-line to support target names or generator expressions.
diff --git a/Help/command/aux_source_directory.rst b/Help/command/aux_source_directory.rst
new file mode 100644
index 0000000000..434d7a919e
--- /dev/null
+++ b/Help/command/aux_source_directory.rst
@@ -0,0 +1,24 @@
+aux_source_directory
+--------------------
+
+Find all source files in a directory.
+
+::
+
+ aux_source_directory(<dir> <variable>)
+
+Collects the names of all the source files in the specified directory
+and stores the list in the <variable> provided. This command is
+intended to be used by projects that use explicit template
+instantiation. Template instantiation files can be stored in a
+"Templates" subdirectory and collected automatically using this
+command to avoid manually listing all instantiations.
+
+It is tempting to use this command to avoid writing the list of source
+files for a library or executable target. While this seems to work,
+there is no way for CMake to generate a build system that knows when a
+new source file has been added. Normally the generated build system
+knows when it needs to rerun CMake because the CMakeLists.txt file is
+modified to add a new source. When the source is just added to the
+directory without modifying this file, one would have to manually
+rerun CMake to generate a build system incorporating the new file.
diff --git a/Help/command/break.rst b/Help/command/break.rst
new file mode 100644
index 0000000000..8f1067b1e9
--- /dev/null
+++ b/Help/command/break.rst
@@ -0,0 +1,10 @@
+break
+-----
+
+Break from an enclosing foreach or while loop.
+
+::
+
+ break()
+
+Breaks from an enclosing foreach loop or while loop
diff --git a/Help/command/build_command.rst b/Help/command/build_command.rst
new file mode 100644
index 0000000000..82a9a42b9f
--- /dev/null
+++ b/Help/command/build_command.rst
@@ -0,0 +1,44 @@
+build_command
+-------------
+
+Get a command line to build the current project.
+This is mainly intended for internal use by the :module:`CTest` module.
+
+.. code-block:: cmake
+
+ build_command(<variable>
+ [CONFIGURATION <config>]
+ [TARGET <target>]
+ [PROJECT_NAME <projname>] # legacy, causes warning
+ )
+
+Sets the given ``<variable>`` to a command-line string of the form::
+
+ <cmake> --build . [--config <config>] [--target <target>] [-- -i]
+
+where ``<cmake>`` is the location of the :manual:`cmake(1)` command-line
+tool, and ``<config>`` and ``<target>`` are the values provided to the
+``CONFIGURATION`` and ``TARGET`` options, if any. The trailing ``-- -i``
+option is added for Makefile generators.
+
+When invoked, this ``cmake --build`` command line will launch the
+underlying build system tool.
+
+.. code-block:: cmake
+
+ build_command(<cachevariable> <makecommand>)
+
+This second signature is deprecated, but still available for backwards
+compatibility. Use the first signature instead.
+
+It sets the given ``<cachevariable>`` to a command-line string as
+above but without the ``--config`` or ``--target`` options.
+The ``<makecommand>`` is ignored but should be the full path to
+msdev, devenv, nmake, make or one of the end user build tools
+for legacy invocations.
+
+.. note::
+ In CMake versions prior to 3.0 this command returned a command
+ line that directly invokes the native build tool for the current
+ generator. Their implementation of the ``PROJECT_NAME`` option
+ had no useful effects, so CMake now warns on use of the option.
diff --git a/Help/command/build_name.rst b/Help/command/build_name.rst
new file mode 100644
index 0000000000..53cd05ec1a
--- /dev/null
+++ b/Help/command/build_name.rst
@@ -0,0 +1,14 @@
+build_name
+----------
+
+Disallowed. See CMake Policy :policy:`CMP0036`.
+
+Use ${CMAKE_SYSTEM} and ${CMAKE_CXX_COMPILER} instead.
+
+::
+
+ build_name(variable)
+
+Sets the specified variable to a string representing the platform and
+compiler settings. These values are now available through the
+CMAKE_SYSTEM and CMAKE_CXX_COMPILER variables.
diff --git a/Help/command/cmake_host_system_information.rst b/Help/command/cmake_host_system_information.rst
new file mode 100644
index 0000000000..ba545d5e27
--- /dev/null
+++ b/Help/command/cmake_host_system_information.rst
@@ -0,0 +1,25 @@
+cmake_host_system_information
+-----------------------------
+
+Query host system specific information.
+
+::
+
+ cmake_host_system_information(RESULT <variable> QUERY <key> ...)
+
+Queries system information of the host system on which cmake runs.
+One or more <key> can be provided to select the information to be
+queried. The list of queried values is stored in <variable>.
+
+<key> can be one of the following values:
+
+::
+
+ NUMBER_OF_LOGICAL_CORES = Number of logical cores.
+ NUMBER_OF_PHYSICAL_CORES = Number of physical cores.
+ HOSTNAME = Hostname.
+ FQDN = Fully qualified domain name.
+ TOTAL_VIRTUAL_MEMORY = Total virtual memory in megabytes.
+ AVAILABLE_VIRTUAL_MEMORY = Available virtual memory in megabytes.
+ TOTAL_PHYSICAL_MEMORY = Total physical memory in megabytes.
+ AVAILABLE_PHYSICAL_MEMORY = Available physical memory in megabytes.
diff --git a/Help/command/cmake_minimum_required.rst b/Help/command/cmake_minimum_required.rst
new file mode 100644
index 0000000000..1bdffa46e3
--- /dev/null
+++ b/Help/command/cmake_minimum_required.rst
@@ -0,0 +1,30 @@
+cmake_minimum_required
+----------------------
+
+Set the minimum required version of cmake for a project.
+
+::
+
+ cmake_minimum_required(VERSION major[.minor[.patch[.tweak]]]
+ [FATAL_ERROR])
+
+If the current version of CMake is lower than that required it will
+stop processing the project and report an error. When a version
+higher than 2.4 is specified the command implicitly invokes
+
+::
+
+ cmake_policy(VERSION major[.minor[.patch[.tweak]]])
+
+which sets the cmake policy version level to the version specified.
+When version 2.4 or lower is given the command implicitly invokes
+
+::
+
+ cmake_policy(VERSION 2.4)
+
+which enables compatibility features for CMake 2.4 and lower.
+
+The FATAL_ERROR option is accepted but ignored by CMake 2.6 and
+higher. It should be specified so CMake versions 2.4 and lower fail
+with an error instead of just a warning.
diff --git a/Help/command/cmake_policy.rst b/Help/command/cmake_policy.rst
new file mode 100644
index 0000000000..2bc32870f1
--- /dev/null
+++ b/Help/command/cmake_policy.rst
@@ -0,0 +1,94 @@
+cmake_policy
+------------
+
+Manage CMake Policy settings. See the :manual:`cmake-policies(7)`
+manual for defined policies.
+
+As CMake evolves it is sometimes necessary to change existing behavior
+in order to fix bugs or improve implementations of existing features.
+The CMake Policy mechanism is designed to help keep existing projects
+building as new versions of CMake introduce changes in behavior. Each
+new policy (behavioral change) is given an identifier of the form
+``CMP<NNNN>`` where ``<NNNN>`` is an integer index. Documentation
+associated with each policy describes the ``OLD`` and ``NEW`` behavior
+and the reason the policy was introduced. Projects may set each policy
+to select the desired behavior. When CMake needs to know which behavior
+to use it checks for a setting specified by the project. If no
+setting is available the ``OLD`` behavior is assumed and a warning is
+produced requesting that the policy be set.
+
+Setting Policies by CMake Version
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The ``cmake_policy`` command is used to set policies to ``OLD`` or ``NEW``
+behavior. While setting policies individually is supported, we
+encourage projects to set policies based on CMake versions::
+
+ cmake_policy(VERSION major.minor[.patch[.tweak]])
+
+Specify that the current CMake code is written for the given
+version of CMake. All policies introduced in the specified version or
+earlier will be set to use ``NEW`` behavior. All policies introduced
+after the specified version will be unset (unless the
+:variable:`CMAKE_POLICY_DEFAULT_CMP<NNNN>` variable sets a default).
+This effectively requests behavior preferred as of a given CMake
+version and tells newer CMake versions to warn about their new policies.
+The policy version specified must be at least 2.4 or the command will
+report an error.
+
+Note that the :command:`cmake_minimum_required(VERSION)`
+command implicitly calls ``cmake_policy(VERSION)`` too.
+
+Setting Policies Explicitly
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+::
+
+ cmake_policy(SET CMP<NNNN> NEW)
+ cmake_policy(SET CMP<NNNN> OLD)
+
+Tell CMake to use the ``OLD`` or ``NEW`` behavior for a given policy.
+Projects depending on the old behavior of a given policy may silence a
+policy warning by setting the policy state to ``OLD``. Alternatively
+one may fix the project to work with the new behavior and set the
+policy state to ``NEW``.
+
+Checking Policy Settings
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+::
+
+ cmake_policy(GET CMP<NNNN> <variable>)
+
+Check whether a given policy is set to ``OLD`` or ``NEW`` behavior.
+The output ``<variable>`` value will be ``OLD`` or ``NEW`` if the
+policy is set, and empty otherwise.
+
+CMake Policy Stack
+^^^^^^^^^^^^^^^^^^
+
+CMake keeps policy settings on a stack, so changes made by the
+cmake_policy command affect only the top of the stack. A new entry on
+the policy stack is managed automatically for each subdirectory to
+protect its parents and siblings. CMake also manages a new entry for
+scripts loaded by :command:`include` and :command:`find_package` commands
+except when invoked with the ``NO_POLICY_SCOPE`` option
+(see also policy :policy:`CMP0011`).
+The ``cmake_policy`` command provides an interface to manage custom
+entries on the policy stack::
+
+ cmake_policy(PUSH)
+ cmake_policy(POP)
+
+Each ``PUSH`` must have a matching ``POP`` to erase any changes.
+This is useful to make temporary changes to policy settings.
+Calls to the :command:`cmake_minimum_required(VERSION)`,
+``cmake_policy(VERSION)``, or ``cmake_policy(SET)`` commands
+influence only the current top of the policy stack.
+
+Commands created by the :command:`function` and :command:`macro`
+commands record policy settings when they are created and
+use the pre-record policies when they are invoked. If the function or
+macro implementation sets policies, the changes automatically
+propagate up through callers until they reach the closest nested
+policy stack entry.
diff --git a/Help/command/configure_file.rst b/Help/command/configure_file.rst
new file mode 100644
index 0000000000..70357f2407
--- /dev/null
+++ b/Help/command/configure_file.rst
@@ -0,0 +1,46 @@
+configure_file
+--------------
+
+Copy a file to another location and modify its contents.
+
+::
+
+ configure_file(<input> <output>
+ [COPYONLY] [ESCAPE_QUOTES] [@ONLY]
+ [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
+
+Copies a file <input> to file <output> and substitutes variable values
+referenced in the file content. If <input> is a relative path it is
+evaluated with respect to the current source directory. The <input>
+must be a file, not a directory. If <output> is a relative path it is
+evaluated with respect to the current binary directory. If <output>
+names an existing directory the input file is placed in that directory
+with its original name.
+
+If the <input> file is modified the build system will re-run CMake to
+re-configure the file and generate the build system again.
+
+This command replaces any variables in the input file referenced as
+${VAR} or @VAR@ with their values as determined by CMake. If a
+variable is not defined, it will be replaced with nothing. If
+COPYONLY is specified, then no variable expansion will take place. If
+ESCAPE_QUOTES is specified then any substituted quotes will be C-style
+escaped. The file will be configured with the current values of CMake
+variables. If @ONLY is specified, only variables of the form @VAR@
+will be replaced and ${VAR} will be ignored. This is useful for
+configuring scripts that use ${VAR}.
+
+Input file lines of the form "#cmakedefine VAR ..." will be replaced
+with either "#define VAR ..." or ``/* #undef VAR */`` depending on
+whether VAR is set in CMake to any value not considered a false
+constant by the if() command. (Content of "...", if any, is processed
+as above.) Input file lines of the form "#cmakedefine01 VAR" will be
+replaced with either "#define VAR 1" or "#define VAR 0" similarly.
+
+With NEWLINE_STYLE the line ending could be adjusted:
+
+::
+
+ 'UNIX' or 'LF' for \n, 'DOS', 'WIN32' or 'CRLF' for \r\n.
+
+COPYONLY must not be used with NEWLINE_STYLE.
diff --git a/Help/command/create_test_sourcelist.rst b/Help/command/create_test_sourcelist.rst
new file mode 100644
index 0000000000..9addd6720c
--- /dev/null
+++ b/Help/command/create_test_sourcelist.rst
@@ -0,0 +1,30 @@
+create_test_sourcelist
+----------------------
+
+Create a test driver and source list for building test programs.
+
+::
+
+ create_test_sourcelist(sourceListName driverName
+ test1 test2 test3
+ EXTRA_INCLUDE include.h
+ FUNCTION function)
+
+A test driver is a program that links together many small tests into a
+single executable. This is useful when building static executables
+with large libraries to shrink the total required size. The list of
+source files needed to build the test driver will be in
+sourceListName. DriverName is the name of the test driver program.
+The rest of the arguments consist of a list of test source files, can
+be semicolon separated. Each test source file should have a function
+in it that is the same name as the file with no extension (foo.cxx
+should have int foo(int, char*[]);) DriverName will be able to call
+each of the tests by name on the command line. If EXTRA_INCLUDE is
+specified, then the next argument is included into the generated file.
+If FUNCTION is specified, then the next argument is taken as a
+function name that is passed a pointer to ac and av. This can be used
+to add extra command line processing to each test. The cmake variable
+CMAKE_TESTDRIVER_BEFORE_TESTMAIN can be set to have code that will be
+placed directly before calling the test main function.
+CMAKE_TESTDRIVER_AFTER_TESTMAIN can be set to have code that will be
+placed directly after the call to the test main function.
diff --git a/Help/command/ctest_build.rst b/Help/command/ctest_build.rst
new file mode 100644
index 0000000000..4a95cdde7f
--- /dev/null
+++ b/Help/command/ctest_build.rst
@@ -0,0 +1,29 @@
+ctest_build
+-----------
+
+Build the project.
+
+::
+
+ ctest_build([BUILD build_dir] [TARGET target] [RETURN_VALUE res]
+ [APPEND][NUMBER_ERRORS val] [NUMBER_WARNINGS val])
+
+Builds the given build directory and stores results in Build.xml. If
+no BUILD is given, the CTEST_BINARY_DIRECTORY variable is used.
+
+The TARGET variable can be used to specify a build target. If none is
+specified, the "all" target will be built.
+
+The RETURN_VALUE option specifies a variable in which to store the
+return value of the native build tool. The NUMBER_ERRORS and
+NUMBER_WARNINGS options specify variables in which to store the number
+of build errors and warnings detected.
+
+The APPEND option marks results for append to those previously
+submitted to a dashboard server since the last ctest_start. Append
+semantics are defined by the dashboard server in use.
+
+If set, the contents of the variable CTEST_BUILD_FLAGS are passed as
+additional arguments to the underlying build command. This can e.g. be
+used to trigger a parallel build using the -j option of make. See
+:module:`ProcessorCount` for an example.
diff --git a/Help/command/ctest_configure.rst b/Help/command/ctest_configure.rst
new file mode 100644
index 0000000000..2c4e305ff5
--- /dev/null
+++ b/Help/command/ctest_configure.rst
@@ -0,0 +1,21 @@
+ctest_configure
+---------------
+
+Configure the project build tree.
+
+::
+
+ ctest_configure([BUILD build_dir] [SOURCE source_dir] [APPEND]
+ [OPTIONS options] [RETURN_VALUE res])
+
+Configures the given build directory and stores results in
+Configure.xml. If no BUILD is given, the CTEST_BINARY_DIRECTORY
+variable is used. If no SOURCE is given, the CTEST_SOURCE_DIRECTORY
+variable is used. The OPTIONS argument specifies command line
+arguments to pass to the configuration tool. The RETURN_VALUE option
+specifies a variable in which to store the return value of the native
+build tool.
+
+The APPEND option marks results for append to those previously
+submitted to a dashboard server since the last ctest_start. Append
+semantics are defined by the dashboard server in use.
diff --git a/Help/command/ctest_coverage.rst b/Help/command/ctest_coverage.rst
new file mode 100644
index 0000000000..4c90f9c019
--- /dev/null
+++ b/Help/command/ctest_coverage.rst
@@ -0,0 +1,20 @@
+ctest_coverage
+--------------
+
+Collect coverage tool results.
+
+::
+
+ ctest_coverage([BUILD build_dir] [RETURN_VALUE res] [APPEND]
+ [LABELS label1 [label2 [...]]])
+
+Perform the coverage of the given build directory and stores results
+in Coverage.xml. The second argument is a variable that will hold
+value.
+
+The LABELS option filters the coverage report to include only source
+files labeled with at least one of the labels specified.
+
+The APPEND option marks results for append to those previously
+submitted to a dashboard server since the last ctest_start. Append
+semantics are defined by the dashboard server in use.
diff --git a/Help/command/ctest_empty_binary_directory.rst b/Help/command/ctest_empty_binary_directory.rst
new file mode 100644
index 0000000000..77536673ce
--- /dev/null
+++ b/Help/command/ctest_empty_binary_directory.rst
@@ -0,0 +1,12 @@
+ctest_empty_binary_directory
+----------------------------
+
+empties the binary directory
+
+::
+
+ ctest_empty_binary_directory( directory )
+
+Removes a binary directory. This command will perform some checks
+prior to deleting the directory in an attempt to avoid malicious or
+accidental directory deletion.
diff --git a/Help/command/ctest_memcheck.rst b/Help/command/ctest_memcheck.rst
new file mode 100644
index 0000000000..ca47ed0472
--- /dev/null
+++ b/Help/command/ctest_memcheck.rst
@@ -0,0 +1,28 @@
+ctest_memcheck
+--------------
+
+Run tests with a dynamic analysis tool.
+
+::
+
+ ctest_memcheck([BUILD build_dir] [RETURN_VALUE res] [APPEND]
+ [START start number] [END end number]
+ [STRIDE stride number] [EXCLUDE exclude regex ]
+ [INCLUDE include regex]
+ [EXCLUDE_LABEL exclude regex]
+ [INCLUDE_LABEL label regex]
+ [PARALLEL_LEVEL level] )
+
+Tests the given build directory and stores results in MemCheck.xml.
+The second argument is a variable that will hold value. Optionally,
+you can specify the starting test number START, the ending test number
+END, the number of tests to skip between each test STRIDE, a regular
+expression for tests to run INCLUDE, or a regular expression for tests
+not to run EXCLUDE. EXCLUDE_LABEL and INCLUDE_LABEL are regular
+expressions for tests to be included or excluded by the test property
+LABEL. PARALLEL_LEVEL should be set to a positive number representing
+the number of tests to be run in parallel.
+
+The APPEND option marks results for append to those previously
+submitted to a dashboard server since the last ctest_start. Append
+semantics are defined by the dashboard server in use.
diff --git a/Help/command/ctest_read_custom_files.rst b/Help/command/ctest_read_custom_files.rst
new file mode 100644
index 0000000000..0bc57cd935
--- /dev/null
+++ b/Help/command/ctest_read_custom_files.rst
@@ -0,0 +1,11 @@
+ctest_read_custom_files
+-----------------------
+
+read CTestCustom files.
+
+::
+
+ ctest_read_custom_files( directory ... )
+
+Read all the CTestCustom.ctest or CTestCustom.cmake files from the
+given directory.
diff --git a/Help/command/ctest_run_script.rst b/Help/command/ctest_run_script.rst
new file mode 100644
index 0000000000..0f3501928e
--- /dev/null
+++ b/Help/command/ctest_run_script.rst
@@ -0,0 +1,15 @@
+ctest_run_script
+----------------
+
+runs a ctest -S script
+
+::
+
+ ctest_run_script([NEW_PROCESS] script_file_name script_file_name1
+ script_file_name2 ... [RETURN_VALUE var])
+
+Runs a script or scripts much like if it was run from ctest -S. If no
+argument is provided then the current script is run using the current
+settings of the variables. If NEW_PROCESS is specified then each
+script will be run in a separate process.If RETURN_VALUE is specified
+the return value of the last script run will be put into var.
diff --git a/Help/command/ctest_sleep.rst b/Help/command/ctest_sleep.rst
new file mode 100644
index 0000000000..16a914c0b4
--- /dev/null
+++ b/Help/command/ctest_sleep.rst
@@ -0,0 +1,16 @@
+ctest_sleep
+-----------
+
+sleeps for some amount of time
+
+::
+
+ ctest_sleep(<seconds>)
+
+Sleep for given number of seconds.
+
+::
+
+ ctest_sleep(<time1> <duration> <time2>)
+
+Sleep for t=(time1 + duration - time2) seconds if t > 0.
diff --git a/Help/command/ctest_start.rst b/Help/command/ctest_start.rst
new file mode 100644
index 0000000000..d7472dbc7f
--- /dev/null
+++ b/Help/command/ctest_start.rst
@@ -0,0 +1,24 @@
+ctest_start
+-----------
+
+Starts the testing for a given model
+
+::
+
+ ctest_start(Model [TRACK <track>] [APPEND] [source [binary]])
+
+Starts the testing for a given model. The command should be called
+after the binary directory is initialized. If the 'source' and
+'binary' directory are not specified, it reads the
+:variable:`CTEST_SOURCE_DIRECTORY` and :variable:`CTEST_BINARY_DIRECTORY`.
+If the track is
+specified, the submissions will go to the specified track. If APPEND
+is used, the existing TAG is used rather than creating a new one based
+on the current time stamp.
+
+If the :variable:`CTEST_CHECKOUT_COMMAND` variable
+(or the :variable:`CTEST_CVS_CHECKOUT` variable)
+is set, its content is treated as command-line. The command is
+invoked with the current working directory set to the parent of the source
+directory, even if the source directory already exists. This can be used
+to create the source tree from a version control repository.
diff --git a/Help/command/ctest_submit.rst b/Help/command/ctest_submit.rst
new file mode 100644
index 0000000000..ed801bb61d
--- /dev/null
+++ b/Help/command/ctest_submit.rst
@@ -0,0 +1,35 @@
+ctest_submit
+------------
+
+Submit results to a dashboard server.
+
+::
+
+ ctest_submit([PARTS ...] [FILES ...] [RETRY_COUNT count] [RETRY_DELAY delay][RETURN_VALUE res])
+
+By default all available parts are submitted if no PARTS or FILES are
+specified. The PARTS option lists a subset of parts to be submitted.
+Valid part names are:
+
+::
+
+ Start = nothing
+ Update = ctest_update results, in Update.xml
+ Configure = ctest_configure results, in Configure.xml
+ Build = ctest_build results, in Build.xml
+ Test = ctest_test results, in Test.xml
+ Coverage = ctest_coverage results, in Coverage.xml
+ MemCheck = ctest_memcheck results, in DynamicAnalysis.xml
+ Notes = Files listed by CTEST_NOTES_FILES, in Notes.xml
+ ExtraFiles = Files listed by CTEST_EXTRA_SUBMIT_FILES
+ Upload = Files prepared for upload by ctest_upload(), in Upload.xml
+ Submit = nothing
+
+The FILES option explicitly lists specific files to be submitted.
+Each individual file must exist at the time of the call.
+
+The RETRY_DELAY option specifies how long in seconds to wait after a
+timed-out submission before attempting to re-submit.
+
+The RETRY_COUNT option specifies how many times to retry a timed-out
+submission.
diff --git a/Help/command/ctest_test.rst b/Help/command/ctest_test.rst
new file mode 100644
index 0000000000..5f28083810
--- /dev/null
+++ b/Help/command/ctest_test.rst
@@ -0,0 +1,33 @@
+ctest_test
+----------
+
+Run tests in the project build tree.
+
+::
+
+ ctest_test([BUILD build_dir] [APPEND]
+ [START start number] [END end number]
+ [STRIDE stride number] [EXCLUDE exclude regex ]
+ [INCLUDE include regex] [RETURN_VALUE res]
+ [EXCLUDE_LABEL exclude regex]
+ [INCLUDE_LABEL label regex]
+ [PARALLEL_LEVEL level]
+ [SCHEDULE_RANDOM on]
+ [STOP_TIME time of day])
+
+Tests the given build directory and stores results in Test.xml. The
+second argument is a variable that will hold value. Optionally, you
+can specify the starting test number START, the ending test number
+END, the number of tests to skip between each test STRIDE, a regular
+expression for tests to run INCLUDE, or a regular expression for tests
+to not run EXCLUDE. EXCLUDE_LABEL and INCLUDE_LABEL are regular
+expression for test to be included or excluded by the test property
+LABEL. PARALLEL_LEVEL should be set to a positive number representing
+the number of tests to be run in parallel. SCHEDULE_RANDOM will
+launch tests in a random order, and is typically used to detect
+implicit test dependencies. STOP_TIME is the time of day at which the
+tests should all stop running.
+
+The APPEND option marks results for append to those previously
+submitted to a dashboard server since the last ctest_start. Append
+semantics are defined by the dashboard server in use.
diff --git a/Help/command/ctest_update.rst b/Help/command/ctest_update.rst
new file mode 100644
index 0000000000..d34e192afb
--- /dev/null
+++ b/Help/command/ctest_update.rst
@@ -0,0 +1,13 @@
+ctest_update
+------------
+
+Update the work tree from version control.
+
+::
+
+ ctest_update([SOURCE source] [RETURN_VALUE res])
+
+Updates the given source directory and stores results in Update.xml.
+If no SOURCE is given, the CTEST_SOURCE_DIRECTORY variable is used.
+The RETURN_VALUE option specifies a variable in which to store the
+result, which is the number of files updated or -1 on error.
diff --git a/Help/command/ctest_upload.rst b/Help/command/ctest_upload.rst
new file mode 100644
index 0000000000..9156af56b9
--- /dev/null
+++ b/Help/command/ctest_upload.rst
@@ -0,0 +1,11 @@
+ctest_upload
+------------
+
+Upload files to a dashboard server.
+
+::
+
+ ctest_upload(FILES ...)
+
+Pass a list of files to be sent along with the build results to the
+dashboard server.
diff --git a/Help/command/define_property.rst b/Help/command/define_property.rst
new file mode 100644
index 0000000000..62bcd1bf12
--- /dev/null
+++ b/Help/command/define_property.rst
@@ -0,0 +1,45 @@
+define_property
+---------------
+
+Define and document custom properties.
+
+::
+
+ define_property(<GLOBAL | DIRECTORY | TARGET | SOURCE |
+ TEST | VARIABLE | CACHED_VARIABLE>
+ PROPERTY <name> [INHERITED]
+ BRIEF_DOCS <brief-doc> [docs...]
+ FULL_DOCS <full-doc> [docs...])
+
+Define one property in a scope for use with the set_property and
+get_property commands. This is primarily useful to associate
+documentation with property names that may be retrieved with the
+get_property command. The first argument determines the kind of scope
+in which the property should be used. It must be one of the
+following:
+
+::
+
+ GLOBAL = associated with the global namespace
+ DIRECTORY = associated with one directory
+ TARGET = associated with one target
+ SOURCE = associated with one source file
+ TEST = associated with a test named with add_test
+ VARIABLE = documents a CMake language variable
+ CACHED_VARIABLE = documents a CMake cache variable
+
+Note that unlike set_property and get_property no actual scope needs
+to be given; only the kind of scope is important.
+
+The required PROPERTY option is immediately followed by the name of
+the property being defined.
+
+If the INHERITED option then the get_property command will chain up to
+the next higher scope when the requested property is not set in the
+scope given to the command. DIRECTORY scope chains to GLOBAL.
+TARGET, SOURCE, and TEST chain to DIRECTORY.
+
+The BRIEF_DOCS and FULL_DOCS options are followed by strings to be
+associated with the property as its brief and full documentation.
+Corresponding options to the get_property command will retrieve the
+documentation.
diff --git a/Help/command/else.rst b/Help/command/else.rst
new file mode 100644
index 0000000000..5eece9566a
--- /dev/null
+++ b/Help/command/else.rst
@@ -0,0 +1,10 @@
+else
+----
+
+Starts the else portion of an if block.
+
+::
+
+ else(expression)
+
+See the if command.
diff --git a/Help/command/elseif.rst b/Help/command/elseif.rst
new file mode 100644
index 0000000000..96ee0e9246
--- /dev/null
+++ b/Help/command/elseif.rst
@@ -0,0 +1,10 @@
+elseif
+------
+
+Starts the elseif portion of an if block.
+
+::
+
+ elseif(expression)
+
+See the if command.
diff --git a/Help/command/enable_language.rst b/Help/command/enable_language.rst
new file mode 100644
index 0000000000..d46ff7ed1d
--- /dev/null
+++ b/Help/command/enable_language.rst
@@ -0,0 +1,22 @@
+enable_language
+---------------
+
+Enable a language (CXX/C/Fortran/etc)
+
+::
+
+ enable_language(<lang> [OPTIONAL] )
+
+This command enables support for the named language in CMake. This is
+the same as the project command but does not create any of the extra
+variables that are created by the project command. Example languages
+are CXX, C, Fortran.
+
+This command must be called in file scope, not in a function call.
+Furthermore, it must be called in the highest directory common to all
+targets using the named language directly for compiling sources or
+indirectly through link dependencies. It is simplest to enable all
+needed languages in the top-level directory of a project.
+
+The OPTIONAL keyword is a placeholder for future implementation and
+does not currently work.
diff --git a/Help/command/enable_testing.rst b/Help/command/enable_testing.rst
new file mode 100644
index 0000000000..41ecd5b1bd
--- /dev/null
+++ b/Help/command/enable_testing.rst
@@ -0,0 +1,13 @@
+enable_testing
+--------------
+
+Enable testing for current directory and below.
+
+::
+
+ enable_testing()
+
+Enables testing for this directory and below. See also the add_test
+command. Note that ctest expects to find a test file in the build
+directory root. Therefore, this command should be in the source
+directory root.
diff --git a/Help/command/endforeach.rst b/Help/command/endforeach.rst
new file mode 100644
index 0000000000..f23552d06a
--- /dev/null
+++ b/Help/command/endforeach.rst
@@ -0,0 +1,10 @@
+endforeach
+----------
+
+Ends a list of commands in a FOREACH block.
+
+::
+
+ endforeach(expression)
+
+See the FOREACH command.
diff --git a/Help/command/endfunction.rst b/Help/command/endfunction.rst
new file mode 100644
index 0000000000..63e70ba3cb
--- /dev/null
+++ b/Help/command/endfunction.rst
@@ -0,0 +1,10 @@
+endfunction
+-----------
+
+Ends a list of commands in a function block.
+
+::
+
+ endfunction(expression)
+
+See the function command.
diff --git a/Help/command/endif.rst b/Help/command/endif.rst
new file mode 100644
index 0000000000..4c9955c2e0
--- /dev/null
+++ b/Help/command/endif.rst
@@ -0,0 +1,10 @@
+endif
+-----
+
+Ends a list of commands in an if block.
+
+::
+
+ endif(expression)
+
+See the if command.
diff --git a/Help/command/endmacro.rst b/Help/command/endmacro.rst
new file mode 100644
index 0000000000..524fc80e7b
--- /dev/null
+++ b/Help/command/endmacro.rst
@@ -0,0 +1,10 @@
+endmacro
+--------
+
+Ends a list of commands in a macro block.
+
+::
+
+ endmacro(expression)
+
+See the macro command.
diff --git a/Help/command/endwhile.rst b/Help/command/endwhile.rst
new file mode 100644
index 0000000000..11fdc1be55
--- /dev/null
+++ b/Help/command/endwhile.rst
@@ -0,0 +1,10 @@
+endwhile
+--------
+
+Ends a list of commands in a while block.
+
+::
+
+ endwhile(expression)
+
+See the while command.
diff --git a/Help/command/exec_program.rst b/Help/command/exec_program.rst
new file mode 100644
index 0000000000..aaa0dacc1e
--- /dev/null
+++ b/Help/command/exec_program.rst
@@ -0,0 +1,24 @@
+exec_program
+------------
+
+Deprecated. Use the execute_process() command instead.
+
+Run an executable program during the processing of the CMakeList.txt
+file.
+
+::
+
+ exec_program(Executable [directory in which to run]
+ [ARGS <arguments to executable>]
+ [OUTPUT_VARIABLE <var>]
+ [RETURN_VALUE <var>])
+
+The executable is run in the optionally specified directory. The
+executable can include arguments if it is double quoted, but it is
+better to use the optional ARGS argument to specify arguments to the
+program. This is because cmake will then be able to escape spaces in
+the executable path. An optional argument OUTPUT_VARIABLE specifies a
+variable in which to store the output. To capture the return value of
+the execution, provide a RETURN_VALUE. If OUTPUT_VARIABLE is
+specified, then no output will go to the stdout/stderr of the console
+running cmake.
diff --git a/Help/command/execute_process.rst b/Help/command/execute_process.rst
new file mode 100644
index 0000000000..478b30e11d
--- /dev/null
+++ b/Help/command/execute_process.rst
@@ -0,0 +1,75 @@
+execute_process
+---------------
+
+Execute one or more child processes.
+
+.. code-block:: cmake
+
+ execute_process(COMMAND <cmd1> [args1...]]
+ [COMMAND <cmd2> [args2...] [...]]
+ [WORKING_DIRECTORY <directory>]
+ [TIMEOUT <seconds>]
+ [RESULT_VARIABLE <variable>]
+ [OUTPUT_VARIABLE <variable>]
+ [ERROR_VARIABLE <variable>]
+ [INPUT_FILE <file>]
+ [OUTPUT_FILE <file>]
+ [ERROR_FILE <file>]
+ [OUTPUT_QUIET]
+ [ERROR_QUIET]
+ [OUTPUT_STRIP_TRAILING_WHITESPACE]
+ [ERROR_STRIP_TRAILING_WHITESPACE])
+
+Runs the given sequence of one or more commands with the standard
+output of each process piped to the standard input of the next.
+A single standard error pipe is used for all processes.
+
+Options:
+
+COMMAND
+ A child process command line.
+
+ CMake executes the child process using operating system APIs directly.
+ All arguments are passed VERBATIM to the child process.
+ No intermediate shell is used, so shell operators such as ``>``
+ are treated as normal arguments.
+ (Use the ``INPUT_*``, ``OUTPUT_*``, and ``ERROR_*`` options to
+ redirect stdin, stdout, and stderr.)
+
+WORKING_DIRECTORY
+ The named directory will be set as the current working directory of
+ the child processes.
+
+TIMEOUT
+ The child processes will be terminated if they do not finish in the
+ specified number of seconds (fractions are allowed).
+
+RESULT_VARIABLE
+ The variable will be set to contain the result of running the processes.
+ This will be an integer return code from the last child or a string
+ describing an error condition.
+
+OUTPUT_VARIABLE, ERROR_VARIABLE
+ The variable named will be set with the contents of the standard output
+ and standard error pipes, respectively. If the same variable is named
+ for both pipes their output will be merged in the order produced.
+
+INPUT_FILE, OUTPUT_FILE, ERROR_FILE
+ The file named will be attached to the standard input of the first
+ process, standard output of the last process, or standard error of
+ all processes, respectively.
+
+OUTPUT_QUIET, ERROR_QUIET
+ The standard output or standard error results will be quietly ignored.
+
+If more than one ``OUTPUT_*`` or ``ERROR_*`` option is given for the
+same pipe the precedence is not specified.
+If no ``OUTPUT_*`` or ``ERROR_*`` options are given the output will
+be shared with the corresponding pipes of the CMake process itself.
+
+The :command:`execute_process` command is a newer more powerful version of
+:command:`exec_program`, but the old command has been kept for compatibility.
+Both commands run while CMake is processing the project prior to build
+system generation. Use :command:`add_custom_target` and
+:command:`add_custom_command` to create custom commands that run at
+build time.
diff --git a/Help/command/export.rst b/Help/command/export.rst
new file mode 100644
index 0000000000..d4bab352a7
--- /dev/null
+++ b/Help/command/export.rst
@@ -0,0 +1,57 @@
+export
+------
+
+Export targets from the build tree for use by outside projects.
+
+::
+
+ export(EXPORT <export-name> [NAMESPACE <namespace>] [FILE <filename>])
+
+Create a file <filename> that may be included by outside projects to
+import targets from the current project's build tree. This is useful
+during cross-compiling to build utility executables that can run on
+the host platform in one project and then import them into another
+project being compiled for the target platform. If the NAMESPACE
+option is given the <namespace> string will be prepended to all target
+names written to the file.
+
+Target installations are associated with the export <export-name>
+using the ``EXPORT`` option of the :command:`install(TARGETS)` command.
+
+The file created by this command is specific to the build tree and
+should never be installed. See the install(EXPORT) command to export
+targets from an installation tree.
+
+The properties set on the generated IMPORTED targets will have the
+same values as the final values of the input TARGETS.
+
+::
+
+ export(TARGETS [target1 [target2 [...]]] [NAMESPACE <namespace>]
+ [APPEND] FILE <filename> [EXPORT_LINK_INTERFACE_LIBRARIES])
+
+This signature is similar to the ``EXPORT`` signature, but targets are listed
+explicitly rather than specified as an export-name. If the APPEND option is
+given the generated code will be appended to the file instead of overwriting it.
+The EXPORT_LINK_INTERFACE_LIBRARIES keyword, if present, causes the
+contents of the properties matching
+``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?`` to be exported, when
+policy CMP0022 is NEW. If a library target is included in the export
+but a target to which it links is not included the behavior is
+unspecified.
+
+::
+
+ export(PACKAGE <name>)
+
+Store the current build directory in the CMake user package registry
+for package <name>. The find_package command may consider the
+directory while searching for package <name>. This helps dependent
+projects find and use a package from the current project's build tree
+without help from the user. Note that the entry in the package
+registry that this command creates works only in conjunction with a
+package configuration file (<name>Config.cmake) that works with the
+build tree. In some cases, for example for packaging and for system
+wide installations, it is not desirable to write the user package
+registry. If the :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable
+is enabled, the ``export(PACKAGE)`` command will do nothing.
diff --git a/Help/command/export_library_dependencies.rst b/Help/command/export_library_dependencies.rst
new file mode 100644
index 0000000000..73c0b42405
--- /dev/null
+++ b/Help/command/export_library_dependencies.rst
@@ -0,0 +1,28 @@
+export_library_dependencies
+---------------------------
+
+Disallowed. See CMake Policy :policy:`CMP0033`.
+
+Use :command:`install(EXPORT)` or :command:`export` command.
+
+This command generates an old-style library dependencies file.
+Projects requiring CMake 2.6 or later should not use the command. Use
+instead the install(EXPORT) command to help export targets from an
+installation tree and the export() command to export targets from a
+build tree.
+
+The old-style library dependencies file does not take into account
+per-configuration names of libraries or the LINK_INTERFACE_LIBRARIES
+target property.
+
+::
+
+ export_library_dependencies(<file> [APPEND])
+
+Create a file named <file> that can be included into a CMake listfile
+with the INCLUDE command. The file will contain a number of SET
+commands that will set all the variables needed for library dependency
+information. This should be the last command in the top level
+CMakeLists.txt file of the project. If the APPEND option is
+specified, the SET commands will be appended to the given file instead
+of replacing it.
diff --git a/Help/command/file.rst b/Help/command/file.rst
new file mode 100644
index 0000000000..dbc41497d3
--- /dev/null
+++ b/Help/command/file.rst
@@ -0,0 +1,307 @@
+file
+----
+
+File manipulation command.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(WRITE <filename> <content>...)
+ file(APPEND <filename> <content>...)
+
+Write ``<content>`` into a file called ``<filename>``. If the file does
+not exist, it will be created. If the file already exists, ``WRITE``
+mode will overwrite it and ``APPEND`` mode will append to the end.
+(If the file is a build input, use the :command:`configure_file` command
+to update the file only when its content changes.)
+
+------------------------------------------------------------------------------
+
+::
+
+ file(READ <filename> <variable>
+ [OFFSET <offset>] [LIMIT <max-in>] [HEX])
+
+Read content from a file called ``<filename>`` and store it in a
+``<variable>``. Optionally start from the given ``<offset>`` and
+read at most ``<max-in>`` bytes. The ``HEX`` option causes data to
+be converted to a hexadecimal representation (useful for binary data).
+
+------------------------------------------------------------------------------
+
+::
+
+ file(STRINGS <filename> <variable> [<options>...])
+
+Parse a list of ASCII strings from ``<filename>`` and store it in
+``<variable>``. Binary data in the file are ignored. Carriage return
+(``\r``, CR) characters are ignored. The options are:
+
+``LENGTH_MAXIMUM <max-len>``
+ Consider only strings of at most a given length.
+
+``LENGTH_MINIMUM <min-len>``
+ Consider only strings of at least a given length.
+
+``LIMIT_COUNT <max-num>``
+ Limit the number of distinct strings to be extracted.
+
+``LIMIT_INPUT <max-in>``
+ Limit the number of input bytes to read from the file.
+
+``LIMIT_OUTPUT <max-out>``
+ Limit the number of total bytes to store in the ``<variable>``.
+
+``NEWLINE_CONSUME``
+ Treat newline characters (``\n``, LF) as part of string content
+ instead of terminating at them.
+
+``NO_HEX_CONVERSION``
+ Intel Hex and Motorola S-record files are automatically converted to
+ binary while reading unless this option is given.
+
+``REGEX <regex>``
+ Consider only strings that match the given regular expression.
+
+``ENCODING <encoding-type>``
+ Consider strings of a given encoding. "UTF-8" is currently supported.
+
+For example, the code
+
+.. code-block:: cmake
+
+ file(STRINGS myfile.txt myfile)
+
+stores a list in the variable ``myfile`` in which each item is a line
+from the input file.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512> <filename> <variable>)
+
+Compute a cryptographic hash of the content of ``<filename>`` and
+store it in a ``<variable>``.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(GLOB <variable> [RELATIVE <path>] [<globbing-expressions>...])
+ file(GLOB_RECURSE <variable> [RELATIVE <path>]
+ [FOLLOW_SYMLINKS] [<globbing-expressions>...])
+
+Generate a list of files that match the ``<globbing-expressions>`` and
+store it into the ``<variable>``. Globbing expressions are similar to
+regular expressions, but much simpler. If ``RELATIVE`` flag is
+specified, the results will be returned as relative paths to the given
+path.
+
+.. note::
+ We do not recommend using GLOB to collect a list of source files from
+ your source tree. If no CMakeLists.txt file changes when a source is
+ added or removed then the generated build system cannot know when to
+ ask CMake to regenerate.
+
+Examples of globbing expressions include::
+
+ *.cxx - match all files with extension cxx
+ *.vt? - match all files with extension vta,...,vtz
+ f[3-5].txt - match files f3.txt, f4.txt, f5.txt
+
+The ``GLOB_RECURSE`` mode will traverse all the subdirectories of the
+matched directory and match the files. Subdirectories that are symlinks
+are only traversed if ``FOLLOW_SYMLINKS`` is given or policy
+:policy:`CMP0009` is not set to ``NEW``.
+
+Examples of recursive globbing include::
+
+ /dir/*.py - match all python files in /dir and subdirectories
+
+------------------------------------------------------------------------------
+
+::
+
+ file(RENAME <oldname> <newname>)
+
+Move a file or directory within a filesystem from ``<oldname>`` to
+``<newname>``, replacing the destination atomically.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(REMOVE [<files>...])
+ file(REMOVE_RECURSE [<files>...])
+
+Remove the given files. The ``REMOVE_RECURSE`` mode will remove the given
+files and directories, also non-empty directories
+
+------------------------------------------------------------------------------
+
+::
+
+ file(MAKE_DIRECTORY [<directories>...])
+
+Create the given directories and their parents as needed.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(RELATIVE_PATH <variable> <directory> <file>)
+
+Compute the relative path from a ``<directory>`` to a ``<file>`` and
+store it in the ``<variable>``.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(TO_CMAKE_PATH "<path>" <variable>)
+ file(TO_NATIVE_PATH "<path>" <variable>)
+
+The ``TO_CMAKE_PATH`` mode converts a native ``<path>`` into a cmake-style
+path with forward-slashes (``/``). The input can be a single path or a
+system search path like ``$ENV{PATH}``. A search path will be converted
+to a cmake-style list separated by ``;`` characters.
+
+The ``TO_NATIVE_PATH`` mode converts a cmake-style ``<path>`` into a native
+path with platform-specific slashes (``\`` on Windows and ``/`` elsewhere).
+
+Always use double quotes around the ``<path>`` to be sure it is treated
+as a single argument to this command.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(DOWNLOAD <url> <file> [<options>...])
+ file(UPLOAD <file> <url> [<options>...])
+
+The ``DOWNLOAD`` mode downloads the given ``<url>`` to a local ``<file>``.
+The ``UPLOAD`` mode uploads a local ``<file>`` to a given ``<url>``.
+
+Options to both ``DOWNLOAD`` and ``UPLOAD`` are:
+
+``INACTIVITY_TIMEOUT <seconds>``
+ Terminate the operation after a period of inactivity.
+
+``LOG <variable>``
+ Store a human-readable log of the operation in a variable.
+
+``SHOW_PROGRESS``
+ Print progress information as status messages until the operation is
+ complete.
+
+``STATUS <variable>``
+ Store the resulting status of the operation in a variable.
+ The status is a ``;`` separated list of length 2.
+ The first element is the numeric return value for the operation,
+ and the second element is a string value for the error.
+ A ``0`` numeric error means no error in the operation.
+
+``TIMEOUT <seconds>``
+ Terminate the operation after a given total time has elapsed.
+
+Additional options to ``DOWNLOAD`` are:
+
+``EXPECTED_HASH ALGO=<value>``
+
+ Verify that the downloaded content hash matches the expected value, where
+ ``ALGO`` is one of ``MD5``, ``SHA1``, ``SHA224``, ``SHA256``, ``SHA384``, or
+ ``SHA512``. If it does not match, the operation fails with an error.
+
+``EXPECTED_MD5 <value>``
+ Historical short-hand for ``EXPECTED_HASH MD5=<value>``.
+
+``TLS_VERIFY <ON|OFF>``
+ Specify whether to verify the server certificate for ``https://`` URLs.
+ The default is to *not* verify.
+
+``TLS_CAINFO <file>``
+ Specify a custom Certificate Authority file for ``https://`` URLs.
+
+For ``https://`` URLs CMake must be built with OpenSSL support. ``TLS/SSL``
+certificates are not checked by default. Set ``TLS_VERIFY`` to ``ON`` to
+check certificates and/or use ``EXPECTED_HASH`` to verify downloaded content.
+If neither ``TLS`` option is given CMake will check variables
+``CMAKE_TLS_VERIFY`` and ``CMAKE_TLS_CAINFO``, respectively.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(TIMESTAMP <filename> <variable> [<format>] [UTC])
+
+Compute a string representation of the modification time of ``<filename>``
+and store it in ``<variable>``. Should the command be unable to obtain a
+timestamp variable will be set to the empty string ("").
+
+See the :command:`string(TIMESTAMP)` command for documentation of
+the ``<format>`` and ``UTC`` options.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(GENERATE <options>...)
+
+Generate an output file for each build configuration supported by the current
+:manual:`CMake Generator <cmake-generators(7)>`. Evaluate
+:manual:`generator expressions <cmake-generator-expressions(7)>`
+from the input content to produce the output content. The options are:
+
+``CONDITION <condition>``
+ Generate the output file for a particular configuration only if
+ the condition is true. The condition must be either ``0`` or ``1``
+ after evaluating generator expressions.
+
+``CONTENT <content>``
+ Use the content given explicitly as input.
+
+``INPUT <input-file>``
+ Use the content from a given file as input.
+
+``OUTPUT <output-file>``
+ Specify the output file name to generate. Use generator expressions
+ such as ``$<CONFIG>`` to specify a configuration-specific output file
+ name. Multiple configurations may generate the same output file only
+ if the generated content is identical. Otherwise, the ``<output-file>``
+ must evaluate to an unique name for each configuration.
+
+Exactly one ``CONTENT`` or ``INPUT`` option must be given. A specific
+``OUTPUT`` file may be named by at most one invocation of ``file(GENERATE)``.
+Generated files are modified on subsequent cmake runs only if their content
+is changed.
+
+------------------------------------------------------------------------------
+
+::
+
+ file(<COPY|INSTALL> <files>... DESTINATION <dir>
+ [FILE_PERMISSIONS <permissions>...]
+ [DIRECTORY_PERMISSIONS <permissions>...]
+ [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS]
+ [FILES_MATCHING]
+ [[PATTERN <pattern> | REGEX <regex>]
+ [EXCLUDE] [PERMISSIONS <permissions>...]] [...])
+
+The ``COPY`` signature copies files, directories, and symlinks to a
+destination folder. Relative input paths are evaluated with respect
+to the current source directory, and a relative destination is
+evaluated with respect to the current build directory. Copying
+preserves input file timestamps, and optimizes out a file if it exists
+at the destination with the same timestamp. Copying preserves input
+permissions unless explicit permissions or ``NO_SOURCE_PERMISSIONS``
+are given (default is ``USE_SOURCE_PERMISSIONS``).
+See the :command:`install(DIRECTORY)` command for documentation of
+permissions, ``PATTERN``, ``REGEX``, and ``EXCLUDE`` options.
+
+The ``INSTALL`` signature differs slightly from ``COPY``: it prints
+status messages (subject to the :variable:`CMAKE_INSTALL_MESSAGE` variable),
+and ``NO_SOURCE_PERMISSIONS`` is default.
+Installation scripts generated by the :command:`install` command
+use this signature (with some undocumented options for internal use).
diff --git a/Help/command/find_file.rst b/Help/command/find_file.rst
new file mode 100644
index 0000000000..db7e1518ef
--- /dev/null
+++ b/Help/command/find_file.rst
@@ -0,0 +1,27 @@
+find_file
+---------
+
+.. |FIND_XXX| replace:: find_file
+.. |NAMES| replace:: NAMES name1 [name2 ...]
+.. |SEARCH_XXX| replace:: full path to a file
+.. |SEARCH_XXX_DESC| replace:: full path to named file
+.. |XXX_SUBDIR| replace:: include
+
+.. |CMAKE_PREFIX_PATH_XXX| replace::
+ <prefix>/include/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and
+ |CMAKE_PREFIX_PATH_XXX_SUBDIR|
+.. |CMAKE_XXX_PATH| replace:: CMAKE_INCLUDE_PATH
+.. |CMAKE_XXX_MAC_PATH| replace:: CMAKE_FRAMEWORK_PATH
+
+.. |SYSTEM_ENVIRONMENT_PATH_XXX| replace:: PATH and INCLUDE
+
+.. |CMAKE_SYSTEM_PREFIX_PATH_XXX| replace::
+ <prefix>/include/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and
+ |CMAKE_SYSTEM_PREFIX_PATH_XXX_SUBDIR|
+.. |CMAKE_SYSTEM_XXX_PATH| replace:: CMAKE_SYSTEM_INCLUDE_PATH
+.. |CMAKE_SYSTEM_XXX_MAC_PATH| replace:: CMAKE_SYSTEM_FRAMEWORK_PATH
+
+.. |CMAKE_FIND_ROOT_PATH_MODE_XXX| replace::
+ :variable:`CMAKE_FIND_ROOT_PATH_MODE_INCLUDE`
+
+.. include:: FIND_XXX.txt
diff --git a/Help/command/find_library.rst b/Help/command/find_library.rst
new file mode 100644
index 0000000000..91342bad3a
--- /dev/null
+++ b/Help/command/find_library.rst
@@ -0,0 +1,44 @@
+find_library
+------------
+
+.. |FIND_XXX| replace:: find_library
+.. |NAMES| replace:: NAMES name1 [name2 ...] [NAMES_PER_DIR]
+.. |SEARCH_XXX| replace:: library
+.. |SEARCH_XXX_DESC| replace:: library
+.. |XXX_SUBDIR| replace:: lib
+
+.. |CMAKE_PREFIX_PATH_XXX| replace::
+ <prefix>/lib/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and
+ |CMAKE_PREFIX_PATH_XXX_SUBDIR|
+.. |CMAKE_XXX_PATH| replace:: CMAKE_LIBRARY_PATH
+.. |CMAKE_XXX_MAC_PATH| replace:: CMAKE_FRAMEWORK_PATH
+
+.. |SYSTEM_ENVIRONMENT_PATH_XXX| replace:: PATH and LIB
+
+.. |CMAKE_SYSTEM_PREFIX_PATH_XXX| replace::
+ <prefix>/lib/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and
+ |CMAKE_SYSTEM_PREFIX_PATH_XXX_SUBDIR|
+.. |CMAKE_SYSTEM_XXX_PATH| replace:: CMAKE_SYSTEM_LIBRARY_PATH
+.. |CMAKE_SYSTEM_XXX_MAC_PATH| replace:: CMAKE_SYSTEM_FRAMEWORK_PATH
+
+.. |CMAKE_FIND_ROOT_PATH_MODE_XXX| replace::
+ :variable:`CMAKE_FIND_ROOT_PATH_MODE_LIBRARY`
+
+.. include:: FIND_XXX.txt
+
+When more than one value is given to the NAMES option this command by
+default will consider one name at a time and search every directory
+for it. The NAMES_PER_DIR option tells this command to consider one
+directory at a time and search for all names in it.
+
+If the library found is a framework, then VAR will be set to the full
+path to the framework <fullPath>/A.framework. When a full path to a
+framework is used as a library, CMake will use a -framework A, and a
+-F<fullPath> to link the framework to the target.
+
+If the global property FIND_LIBRARY_USE_LIB64_PATHS is set all search
+paths will be tested as normal, with "64/" appended, and with all
+matches of "lib/" replaced with "lib64/". This property is
+automatically set for the platforms that are known to need it if at
+least one of the languages supported by the PROJECT command is
+enabled.
diff --git a/Help/command/find_package.rst b/Help/command/find_package.rst
new file mode 100644
index 0000000000..190d05cf61
--- /dev/null
+++ b/Help/command/find_package.rst
@@ -0,0 +1,349 @@
+find_package
+------------
+
+Load settings for an external project.
+
+::
+
+ find_package(<package> [version] [EXACT] [QUIET] [MODULE]
+ [REQUIRED] [[COMPONENTS] [components...]]
+ [OPTIONAL_COMPONENTS components...]
+ [NO_POLICY_SCOPE])
+
+Finds and loads settings from an external project. ``<package>_FOUND``
+will be set to indicate whether the package was found. When the
+package is found package-specific information is provided through
+variables and :ref:`Imported Targets` documented by the package itself. The
+``QUIET`` option disables messages if the package cannot be found. The
+``MODULE`` option disables the second signature documented below. The
+``REQUIRED`` option stops processing with an error message if the package
+cannot be found.
+
+A package-specific list of required components may be listed after the
+``COMPONENTS`` option (or after the ``REQUIRED`` option if present).
+Additional optional components may be listed after
+``OPTIONAL_COMPONENTS``. Available components and their influence on
+whether a package is considered to be found are defined by the target
+package.
+
+The ``[version]`` argument requests a version with which the package found
+should be compatible (format is ``major[.minor[.patch[.tweak]]]``). The
+``EXACT`` option requests that the version be matched exactly. If no
+``[version]`` and/or component list is given to a recursive invocation
+inside a find-module, the corresponding arguments are forwarded
+automatically from the outer call (including the ``EXACT`` flag for
+``[version]``). Version support is currently provided only on a
+package-by-package basis (details below).
+
+User code should generally look for packages using the above simple
+signature. The remainder of this command documentation specifies the
+full command signature and details of the search process. Project
+maintainers wishing to provide a package to be found by this command
+are encouraged to read on.
+
+The command has two modes by which it searches for packages: "Module"
+mode and "Config" mode. Module mode is available when the command is
+invoked with the above reduced signature. CMake searches for a file
+called ``Find<package>.cmake`` in the :variable:`CMAKE_MODULE_PATH`
+followed by the CMake installation. If the file is found, it is read
+and processed by CMake. It is responsible for finding the package,
+checking the version, and producing any needed messages. Many
+find-modules provide limited or no support for versioning; check
+the module documentation. If no module is found and the ``MODULE``
+option is not given the command proceeds to Config mode.
+
+The complete Config mode command signature is::
+
+ find_package(<package> [version] [EXACT] [QUIET]
+ [REQUIRED] [[COMPONENTS] [components...]]
+ [CONFIG|NO_MODULE]
+ [NO_POLICY_SCOPE]
+ [NAMES name1 [name2 ...]]
+ [CONFIGS config1 [config2 ...]]
+ [HINTS path1 [path2 ... ]]
+ [PATHS path1 [path2 ... ]]
+ [PATH_SUFFIXES suffix1 [suffix2 ...]]
+ [NO_DEFAULT_PATH]
+ [NO_CMAKE_ENVIRONMENT_PATH]
+ [NO_CMAKE_PATH]
+ [NO_SYSTEM_ENVIRONMENT_PATH]
+ [NO_CMAKE_PACKAGE_REGISTRY]
+ [NO_CMAKE_BUILDS_PATH]
+ [NO_CMAKE_SYSTEM_PATH]
+ [NO_CMAKE_SYSTEM_PACKAGE_REGISTRY]
+ [CMAKE_FIND_ROOT_PATH_BOTH |
+ ONLY_CMAKE_FIND_ROOT_PATH |
+ NO_CMAKE_FIND_ROOT_PATH])
+
+The ``CONFIG`` option may be used to skip Module mode explicitly and
+switch to Config mode. It is synonymous to using ``NO_MODULE``. Config
+mode is also implied by use of options not specified in the reduced
+signature.
+
+Config mode attempts to locate a configuration file provided by the
+package to be found. A cache entry called ``<package>_DIR`` is created to
+hold the directory containing the file. By default the command
+searches for a package with the name ``<package>``. If the ``NAMES`` option
+is given the names following it are used instead of ``<package>``. The
+command searches for a file called ``<name>Config.cmake`` or
+``<lower-case-name>-config.cmake`` for each name specified. A
+replacement set of possible configuration file names may be given
+using the ``CONFIGS`` option. The search procedure is specified below.
+Once found, the configuration file is read and processed by CMake.
+Since the file is provided by the package it already knows the
+location of package contents. The full path to the configuration file
+is stored in the cmake variable ``<package>_CONFIG``.
+
+All configuration files which have been considered by CMake while
+searching for an installation of the package with an appropriate
+version are stored in the cmake variable ``<package>_CONSIDERED_CONFIGS``,
+the associated versions in ``<package>_CONSIDERED_VERSIONS``.
+
+If the package configuration file cannot be found CMake will generate
+an error describing the problem unless the ``QUIET`` argument is
+specified. If ``REQUIRED`` is specified and the package is not found a
+fatal error is generated and the configure step stops executing. If
+``<package>_DIR`` has been set to a directory not containing a
+configuration file CMake will ignore it and search from scratch.
+
+When the ``[version]`` argument is given Config mode will only find a
+version of the package that claims compatibility with the requested
+version (format is ``major[.minor[.patch[.tweak]]]``). If the ``EXACT``
+option is given only a version of the package claiming an exact match
+of the requested version may be found. CMake does not establish any
+convention for the meaning of version numbers. Package version
+numbers are checked by "version" files provided by the packages
+themselves. For a candidate package configuration file
+``<config-file>.cmake`` the corresponding version file is located next
+to it and named either ``<config-file>-version.cmake`` or
+``<config-file>Version.cmake``. If no such version file is available
+then the configuration file is assumed to not be compatible with any
+requested version. A basic version file containing generic version
+matching code can be created using the
+:module:`CMakePackageConfigHelpers` module. When a version file
+is found it is loaded to check the requested version number. The
+version file is loaded in a nested scope in which the following
+variables have been defined:
+
+``PACKAGE_FIND_NAME``
+ the ``<package>`` name
+``PACKAGE_FIND_VERSION``
+ full requested version string
+``PACKAGE_FIND_VERSION_MAJOR``
+ major version if requested, else 0
+``PACKAGE_FIND_VERSION_MINOR``
+ minor version if requested, else 0
+``PACKAGE_FIND_VERSION_PATCH``
+ patch version if requested, else 0
+``PACKAGE_FIND_VERSION_TWEAK``
+ tweak version if requested, else 0
+``PACKAGE_FIND_VERSION_COUNT``
+ number of version components, 0 to 4
+
+The version file checks whether it satisfies the requested version and
+sets these variables:
+
+``PACKAGE_VERSION``
+ full provided version string
+``PACKAGE_VERSION_EXACT``
+ true if version is exact match
+``PACKAGE_VERSION_COMPATIBLE``
+ true if version is compatible
+``PACKAGE_VERSION_UNSUITABLE``
+ true if unsuitable as any version
+
+These variables are checked by the ``find_package`` command to determine
+whether the configuration file provides an acceptable version. They
+are not available after the find_package call returns. If the version
+is acceptable the following variables are set:
+
+``<package>_VERSION``
+ full provided version string
+``<package>_VERSION_MAJOR``
+ major version if provided, else 0
+``<package>_VERSION_MINOR``
+ minor version if provided, else 0
+``<package>_VERSION_PATCH``
+ patch version if provided, else 0
+``<package>_VERSION_TWEAK``
+ tweak version if provided, else 0
+``<package>_VERSION_COUNT``
+ number of version components, 0 to 4
+
+and the corresponding package configuration file is loaded. When
+multiple package configuration files are available whose version files
+claim compatibility with the version requested it is unspecified which
+one is chosen. No attempt is made to choose a highest or closest
+version number.
+
+Config mode provides an elaborate interface and search procedure.
+Much of the interface is provided for completeness and for use
+internally by find-modules loaded by Module mode. Most user code
+should simply call::
+
+ find_package(<package> [major[.minor]] [EXACT] [REQUIRED|QUIET])
+
+in order to find a package. Package maintainers providing CMake
+package configuration files are encouraged to name and install them
+such that the procedure outlined below will find them without
+requiring use of additional options.
+
+CMake constructs a set of possible installation prefixes for the
+package. Under each prefix several directories are searched for a
+configuration file. The tables below show the directories searched.
+Each entry is meant for installation trees following Windows (W), UNIX
+(U), or Apple (A) conventions::
+
+ <prefix>/ (W)
+ <prefix>/(cmake|CMake)/ (W)
+ <prefix>/<name>*/ (W)
+ <prefix>/<name>*/(cmake|CMake)/ (W)
+ <prefix>/(lib/<arch>|lib|share)/cmake/<name>*/ (U)
+ <prefix>/(lib/<arch>|lib|share)/<name>*/ (U)
+ <prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/ (U)
+
+On systems supporting OS X Frameworks and Application Bundles the
+following directories are searched for frameworks or bundles
+containing a configuration file::
+
+ <prefix>/<name>.framework/Resources/ (A)
+ <prefix>/<name>.framework/Resources/CMake/ (A)
+ <prefix>/<name>.framework/Versions/*/Resources/ (A)
+ <prefix>/<name>.framework/Versions/*/Resources/CMake/ (A)
+ <prefix>/<name>.app/Contents/Resources/ (A)
+ <prefix>/<name>.app/Contents/Resources/CMake/ (A)
+
+In all cases the ``<name>`` is treated as case-insensitive and corresponds
+to any of the names specified (``<package>`` or names given by ``NAMES``).
+Paths with ``lib/<arch>`` are enabled if the
+:variable:`CMAKE_LIBRARY_ARCHITECTURE` variable is set. If ``PATH_SUFFIXES``
+is specified the suffixes are appended to each (W) or (U) directory entry
+one-by-one.
+
+This set of directories is intended to work in cooperation with
+projects that provide configuration files in their installation trees.
+Directories above marked with (W) are intended for installations on
+Windows where the prefix may point at the top of an application's
+installation directory. Those marked with (U) are intended for
+installations on UNIX platforms where the prefix is shared by multiple
+packages. This is merely a convention, so all (W) and (U) directories
+are still searched on all platforms. Directories marked with (A) are
+intended for installations on Apple platforms. The cmake variables
+``CMAKE_FIND_FRAMEWORK`` and ``CMAKE_FIND_APPBUNDLE``
+determine the order of preference as specified below.
+
+The set of installation prefixes is constructed using the following
+steps. If ``NO_DEFAULT_PATH`` is specified all ``NO_*`` options are
+enabled.
+
+1. Search paths specified in cmake-specific cache variables. These
+ are intended to be used on the command line with a ``-DVAR=value``.
+ This can be skipped if ``NO_CMAKE_PATH`` is passed::
+
+ CMAKE_PREFIX_PATH
+ CMAKE_FRAMEWORK_PATH
+ CMAKE_APPBUNDLE_PATH
+
+2. Search paths specified in cmake-specific environment variables.
+ These are intended to be set in the user's shell configuration.
+ This can be skipped if ``NO_CMAKE_ENVIRONMENT_PATH`` is passed::
+
+ <package>_DIR
+ CMAKE_PREFIX_PATH
+ CMAKE_FRAMEWORK_PATH
+ CMAKE_APPBUNDLE_PATH
+
+3. Search paths specified by the ``HINTS`` option. These should be paths
+ computed by system introspection, such as a hint provided by the
+ location of another item already found. Hard-coded guesses should
+ be specified with the ``PATHS`` option.
+
+4. Search the standard system environment variables. This can be
+ skipped if ``NO_SYSTEM_ENVIRONMENT_PATH`` is passed. Path entries
+ ending in ``/bin`` or ``/sbin`` are automatically converted to their
+ parent directories::
+
+ PATH
+
+5. Search project build trees recently configured in a :manual:`cmake-gui(1)`.
+ This can be skipped if ``NO_CMAKE_BUILDS_PATH`` is passed. It is intended
+ for the case when a user is building multiple dependent projects one
+ after another.
+ (This step is implemented only on Windows.)
+
+6. Search paths stored in the CMake :ref:`User Package Registry`.
+ This can be skipped if ``NO_CMAKE_PACKAGE_REGISTRY`` is passed or by
+ setting the :variable:`CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY`
+ to ``TRUE``.
+ See the :manual:`cmake-packages(7)` manual for details on the user
+ package registry.
+
+7. Search cmake variables defined in the Platform files for the
+ current system. This can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is
+ passed::
+
+ CMAKE_SYSTEM_PREFIX_PATH
+ CMAKE_SYSTEM_FRAMEWORK_PATH
+ CMAKE_SYSTEM_APPBUNDLE_PATH
+
+8. Search paths stored in the CMake :ref:`System Package Registry`.
+ This can be skipped if ``NO_CMAKE_SYSTEM_PACKAGE_REGISTRY`` is passed
+ or by setting the
+ :variable:`CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY` to ``TRUE``.
+ See the :manual:`cmake-packages(7)` manual for details on the system
+ package registry.
+
+9. Search paths specified by the ``PATHS`` option. These are typically
+ hard-coded guesses.
+
+.. |FIND_XXX| replace:: find_package
+.. |FIND_ARGS_XXX| replace:: <package>
+.. |CMAKE_FIND_ROOT_PATH_MODE_XXX| replace::
+ :variable:`CMAKE_FIND_ROOT_PATH_MODE_PACKAGE`
+
+.. include:: FIND_XXX_MAC.txt
+.. include:: FIND_XXX_ROOT.txt
+.. include:: FIND_XXX_ORDER.txt
+
+Every non-REQUIRED ``find_package`` call can be disabled by setting the
+:variable:`CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` variable to ``TRUE``.
+
+When loading a find module or package configuration file ``find_package``
+defines variables to provide information about the call arguments (and
+restores their original state before returning):
+
+``<package>_FIND_REQUIRED``
+ true if ``REQUIRED`` option was given
+``<package>_FIND_QUIETLY``
+ true if ``QUIET`` option was given
+``<package>_FIND_VERSION``
+ full requested version string
+``<package>_FIND_VERSION_MAJOR``
+ major version if requested, else 0
+``<package>_FIND_VERSION_MINOR``
+ minor version if requested, else 0
+``<package>_FIND_VERSION_PATCH``
+ patch version if requested, else 0
+``<package>_FIND_VERSION_TWEAK``
+ tweak version if requested, else 0
+``<package>_FIND_VERSION_COUNT``
+ number of version components, 0 to 4
+``<package>_FIND_VERSION_EXACT``
+ true if ``EXACT`` option was given
+``<package>_FIND_COMPONENTS``
+ list of requested components
+``<package>_FIND_REQUIRED_<c>``
+ true if component ``<c>`` is required,
+ false if component ``<c>`` is optional
+
+In Module mode the loaded find module is responsible to honor the
+request detailed by these variables; see the find module for details.
+In Config mode ``find_package`` handles ``REQUIRED``, ``QUIET``, and
+``[version]`` options automatically but leaves it to the package
+configuration file to handle components in a way that makes sense
+for the package. The package configuration file may set
+``<package>_FOUND`` to false to tell ``find_package`` that component
+requirements are not satisfied.
+
+See the :command:`cmake_policy` command documentation for discussion
+of the ``NO_POLICY_SCOPE`` option.
diff --git a/Help/command/find_path.rst b/Help/command/find_path.rst
new file mode 100644
index 0000000000..95d49e77aa
--- /dev/null
+++ b/Help/command/find_path.rst
@@ -0,0 +1,32 @@
+find_path
+---------
+
+.. |FIND_XXX| replace:: find_path
+.. |NAMES| replace:: NAMES name1 [name2 ...]
+.. |SEARCH_XXX| replace:: file in a directory
+.. |SEARCH_XXX_DESC| replace:: directory containing the named file
+.. |XXX_SUBDIR| replace:: include
+
+.. |CMAKE_PREFIX_PATH_XXX| replace::
+ <prefix>/include/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and
+ |CMAKE_PREFIX_PATH_XXX_SUBDIR|
+.. |CMAKE_XXX_PATH| replace:: CMAKE_INCLUDE_PATH
+.. |CMAKE_XXX_MAC_PATH| replace:: CMAKE_FRAMEWORK_PATH
+
+.. |SYSTEM_ENVIRONMENT_PATH_XXX| replace:: PATH and INCLUDE
+
+.. |CMAKE_SYSTEM_PREFIX_PATH_XXX| replace::
+ <prefix>/include/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and
+ |CMAKE_SYSTEM_PREFIX_PATH_XXX_SUBDIR|
+.. |CMAKE_SYSTEM_XXX_PATH| replace:: CMAKE_SYSTEM_INCLUDE_PATH
+.. |CMAKE_SYSTEM_XXX_MAC_PATH| replace:: CMAKE_SYSTEM_FRAMEWORK_PATH
+
+.. |CMAKE_FIND_ROOT_PATH_MODE_XXX| replace::
+ :variable:`CMAKE_FIND_ROOT_PATH_MODE_INCLUDE`
+
+.. include:: FIND_XXX.txt
+
+When searching for frameworks, if the file is specified as A/b.h, then
+the framework search will look for A.framework/Headers/b.h. If that
+is found the path will be set to the path to the framework. CMake
+will convert this to the correct -F option to include the file.
diff --git a/Help/command/find_program.rst b/Help/command/find_program.rst
new file mode 100644
index 0000000000..c62a8a5d24
--- /dev/null
+++ b/Help/command/find_program.rst
@@ -0,0 +1,25 @@
+find_program
+------------
+
+.. |FIND_XXX| replace:: find_program
+.. |NAMES| replace:: NAMES name1 [name2 ...]
+.. |SEARCH_XXX| replace:: program
+.. |SEARCH_XXX_DESC| replace:: program
+.. |XXX_SUBDIR| replace:: [s]bin
+
+.. |CMAKE_PREFIX_PATH_XXX| replace::
+ |CMAKE_PREFIX_PATH_XXX_SUBDIR|
+.. |CMAKE_XXX_PATH| replace:: CMAKE_PROGRAM_PATH
+.. |CMAKE_XXX_MAC_PATH| replace:: CMAKE_APPBUNDLE_PATH
+
+.. |SYSTEM_ENVIRONMENT_PATH_XXX| replace:: PATH
+
+.. |CMAKE_SYSTEM_PREFIX_PATH_XXX| replace::
+ |CMAKE_SYSTEM_PREFIX_PATH_XXX_SUBDIR|
+.. |CMAKE_SYSTEM_XXX_PATH| replace:: CMAKE_SYSTEM_PROGRAM_PATH
+.. |CMAKE_SYSTEM_XXX_MAC_PATH| replace:: CMAKE_SYSTEM_APPBUNDLE_PATH
+
+.. |CMAKE_FIND_ROOT_PATH_MODE_XXX| replace::
+ :variable:`CMAKE_FIND_ROOT_PATH_MODE_PROGRAM`
+
+.. include:: FIND_XXX.txt
diff --git a/Help/command/fltk_wrap_ui.rst b/Help/command/fltk_wrap_ui.rst
new file mode 100644
index 0000000000..448ae644db
--- /dev/null
+++ b/Help/command/fltk_wrap_ui.rst
@@ -0,0 +1,14 @@
+fltk_wrap_ui
+------------
+
+Create FLTK user interfaces Wrappers.
+
+::
+
+ fltk_wrap_ui(resultingLibraryName source1
+ source2 ... sourceN )
+
+Produce .h and .cxx files for all the .fl and .fld files listed. The
+resulting .h and .cxx files will be added to a variable named
+resultingLibraryName_FLTK_UI_SRCS which should be added to your
+library.
diff --git a/Help/command/foreach.rst b/Help/command/foreach.rst
new file mode 100644
index 0000000000..348ebd875c
--- /dev/null
+++ b/Help/command/foreach.rst
@@ -0,0 +1,47 @@
+foreach
+-------
+
+Evaluate a group of commands for each value in a list.
+
+::
+
+ foreach(loop_var arg1 arg2 ...)
+ COMMAND1(ARGS ...)
+ COMMAND2(ARGS ...)
+ ...
+ endforeach(loop_var)
+
+All commands between foreach and the matching endforeach are recorded
+without being invoked. Once the endforeach is evaluated, the recorded
+list of commands is invoked once for each argument listed in the
+original foreach command. Before each iteration of the loop
+"${loop_var}" will be set as a variable with the current value in the
+list.
+
+::
+
+ foreach(loop_var RANGE total)
+ foreach(loop_var RANGE start stop [step])
+
+Foreach can also iterate over a generated range of numbers. There are
+three types of this iteration:
+
+* When specifying single number, the range will have elements 0 to
+ "total".
+
+* When specifying two numbers, the range will have elements from the
+ first number to the second number.
+
+* The third optional number is the increment used to iterate from the
+ first number to the second number.
+
+::
+
+ foreach(loop_var IN [LISTS [list1 [...]]]
+ [ITEMS [item1 [...]]])
+
+Iterates over a precise list of items. The LISTS option names
+list-valued variables to be traversed, including empty elements (an
+empty string is a zero-length list). (Note macro
+arguments are not variables.) The ITEMS option ends argument
+parsing and includes all arguments following it in the iteration.
diff --git a/Help/command/function.rst b/Help/command/function.rst
new file mode 100644
index 0000000000..b18e03cfe3
--- /dev/null
+++ b/Help/command/function.rst
@@ -0,0 +1,31 @@
+function
+--------
+
+Start recording a function for later invocation as a command.
+
+::
+
+ function(<name> [arg1 [arg2 [arg3 ...]]])
+ COMMAND1(ARGS ...)
+ COMMAND2(ARGS ...)
+ ...
+ endfunction(<name>)
+
+Define a function named <name> that takes arguments named arg1 arg2
+arg3 (...). Commands listed after function, but before the matching
+endfunction, are not invoked until the function is invoked. When it
+is invoked, the commands recorded in the function are first modified
+by replacing formal parameters (${arg1}) with the arguments passed,
+and then invoked as normal commands. In addition to referencing the
+formal parameters you can reference the variable ARGC which will be
+set to the number of arguments passed into the function as well as
+ARGV0 ARGV1 ARGV2 ... which will have the actual values of the
+arguments passed in. This facilitates creating functions with
+optional arguments. Additionally ARGV holds the list of all arguments
+given to the function and ARGN holds the list of arguments past the
+last expected argument.
+
+A function opens a new scope: see set(var PARENT_SCOPE) for details.
+
+See the cmake_policy() command documentation for the behavior of
+policies inside functions.
diff --git a/Help/command/get_cmake_property.rst b/Help/command/get_cmake_property.rst
new file mode 100644
index 0000000000..bcfc5e8317
--- /dev/null
+++ b/Help/command/get_cmake_property.rst
@@ -0,0 +1,15 @@
+get_cmake_property
+------------------
+
+Get a property of the CMake instance.
+
+::
+
+ get_cmake_property(VAR property)
+
+Get a property from the CMake instance. The value of the property is
+stored in the variable VAR. If the property is not found, VAR will be
+set to "NOTFOUND". Some supported properties include: VARIABLES,
+CACHE_VARIABLES, COMMANDS, MACROS, and COMPONENTS.
+
+See also the more general get_property() command.
diff --git a/Help/command/get_directory_property.rst b/Help/command/get_directory_property.rst
new file mode 100644
index 0000000000..f2a0a803ed
--- /dev/null
+++ b/Help/command/get_directory_property.rst
@@ -0,0 +1,24 @@
+get_directory_property
+----------------------
+
+Get a property of DIRECTORY scope.
+
+::
+
+ get_directory_property(<variable> [DIRECTORY <dir>] <prop-name>)
+
+Store a property of directory scope in the named variable. If the
+property is not defined the empty-string is returned. The DIRECTORY
+argument specifies another directory from which to retrieve the
+property value. The specified directory must have already been
+traversed by CMake.
+
+::
+
+ get_directory_property(<variable> [DIRECTORY <dir>]
+ DEFINITION <var-name>)
+
+Get a variable definition from a directory. This form is useful to
+get a variable definition from another directory.
+
+See also the more general get_property() command.
diff --git a/Help/command/get_filename_component.rst b/Help/command/get_filename_component.rst
new file mode 100644
index 0000000000..5eec792293
--- /dev/null
+++ b/Help/command/get_filename_component.rst
@@ -0,0 +1,37 @@
+get_filename_component
+----------------------
+
+Get a specific component of a full filename.
+
+::
+
+ get_filename_component(<VAR> <FileName> <COMP> [CACHE])
+
+Set <VAR> to a component of <FileName>, where <COMP> is one of:
+
+::
+
+ DIRECTORY = Directory without file name
+ NAME = File name without directory
+ EXT = File name longest extension (.b.c from d/a.b.c)
+ NAME_WE = File name without directory or longest extension
+ ABSOLUTE = Full path to file
+ REALPATH = Full path to existing file with symlinks resolved
+ PATH = Legacy alias for DIRECTORY (use for CMake <= 2.8.11)
+
+Paths are returned with forward slashes and have no trailing slahes.
+The longest file extension is always considered. If the optional
+CACHE argument is specified, the result variable is added to the
+cache.
+
+::
+
+ get_filename_component(<VAR> FileName
+ PROGRAM [PROGRAM_ARGS <ARG_VAR>]
+ [CACHE])
+
+The program in FileName will be found in the system search path or
+left as a full path. If PROGRAM_ARGS is present with PROGRAM, then
+any command-line arguments present in the FileName string are split
+from the program name and stored in <ARG_VAR>. This is used to
+separate a program name from its arguments in a command line string.
diff --git a/Help/command/get_property.rst b/Help/command/get_property.rst
new file mode 100644
index 0000000000..c2937be6af
--- /dev/null
+++ b/Help/command/get_property.rst
@@ -0,0 +1,49 @@
+get_property
+------------
+
+Get a property.
+
+::
+
+ get_property(<variable>
+ <GLOBAL |
+ DIRECTORY [dir] |
+ TARGET <target> |
+ SOURCE <source> |
+ TEST <test> |
+ CACHE <entry> |
+ VARIABLE>
+ PROPERTY <name>
+ [SET | DEFINED | BRIEF_DOCS | FULL_DOCS])
+
+Get one property from one object in a scope. The first argument
+specifies the variable in which to store the result. The second
+argument determines the scope from which to get the property. It must
+be one of the following:
+
+GLOBAL scope is unique and does not accept a name.
+
+DIRECTORY scope defaults to the current directory but another
+directory (already processed by CMake) may be named by full or
+relative path.
+
+TARGET scope must name one existing target.
+
+SOURCE scope must name one source file.
+
+TEST scope must name one existing test.
+
+CACHE scope must name one cache entry.
+
+VARIABLE scope is unique and does not accept a name.
+
+The required PROPERTY option is immediately followed by the name of
+the property to get. If the property is not set an empty value is
+returned. If the SET option is given the variable is set to a boolean
+value indicating whether the property has been set. If the DEFINED
+option is given the variable is set to a boolean value indicating
+whether the property has been defined such as with define_property.
+If BRIEF_DOCS or FULL_DOCS is given then the variable is set to a
+string containing documentation for the requested property. If
+documentation is requested for a property that has not been defined
+NOTFOUND is returned.
diff --git a/Help/command/get_source_file_property.rst b/Help/command/get_source_file_property.rst
new file mode 100644
index 0000000000..80c512b4b6
--- /dev/null
+++ b/Help/command/get_source_file_property.rst
@@ -0,0 +1,16 @@
+get_source_file_property
+------------------------
+
+Get a property for a source file.
+
+::
+
+ get_source_file_property(VAR file property)
+
+Get a property from a source file. The value of the property is
+stored in the variable VAR. If the property is not found, VAR will be
+set to "NOTFOUND". Use set_source_files_properties to set property
+values. Source file properties usually control how the file is built.
+One property that is always there is LOCATION
+
+See also the more general get_property() command.
diff --git a/Help/command/get_target_property.rst b/Help/command/get_target_property.rst
new file mode 100644
index 0000000000..4017d31d4b
--- /dev/null
+++ b/Help/command/get_target_property.rst
@@ -0,0 +1,18 @@
+get_target_property
+-------------------
+
+Get a property from a target.
+
+::
+
+ get_target_property(VAR target property)
+
+Get a property from a target. The value of the property is stored in
+the variable VAR. If the property is not found, VAR will be set to
+"NOTFOUND". Use set_target_properties to set property values.
+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.
+
+See also the more general get_property() command.
diff --git a/Help/command/get_test_property.rst b/Help/command/get_test_property.rst
new file mode 100644
index 0000000000..2623755b36
--- /dev/null
+++ b/Help/command/get_test_property.rst
@@ -0,0 +1,15 @@
+get_test_property
+-----------------
+
+Get a property of the test.
+
+::
+
+ get_test_property(test property VAR)
+
+Get a property from the Test. The value of the property is stored in
+the variable VAR. If the property is not found, VAR will be set to
+"NOTFOUND". For a list of standard properties you can type cmake
+--help-property-list
+
+See also the more general get_property() command.
diff --git a/Help/command/if.rst b/Help/command/if.rst
new file mode 100644
index 0000000000..79e5d21c22
--- /dev/null
+++ b/Help/command/if.rst
@@ -0,0 +1,207 @@
+if
+--
+
+Conditionally execute a group of commands.
+
+.. code-block:: cmake
+
+ if(expression)
+ # then section.
+ COMMAND1(ARGS ...)
+ COMMAND2(ARGS ...)
+ ...
+ elseif(expression2)
+ # elseif section.
+ COMMAND1(ARGS ...)
+ COMMAND2(ARGS ...)
+ ...
+ else(expression)
+ # else section.
+ COMMAND1(ARGS ...)
+ COMMAND2(ARGS ...)
+ ...
+ endif(expression)
+
+Evaluates the given expression. If the result is true, the commands
+in the THEN section are invoked. Otherwise, the commands in the else
+section are invoked. The elseif and else sections are optional. You
+may have multiple elseif clauses. Note that the expression in the
+else and endif clause is optional. Long expressions can be used and
+there is a traditional order of precedence. Parenthetical expressions
+are evaluated first followed by unary tests such as ``EXISTS``,
+``COMMAND``, and ``DEFINED``. Then any binary tests such as
+``EQUAL``, ``LESS``, ``GREATER``, ``STRLESS``, ``STRGREATER``,
+``STREQUAL``, and ``MATCHES`` will be evaluated. Then boolean ``NOT``
+operators and finally boolean ``AND`` and then ``OR`` operators will
+be evaluated.
+
+Possible expressions are:
+
+``if(<constant>)``
+ True if the constant is ``1``, ``ON``, ``YES``, ``TRUE``, ``Y``,
+ or a non-zero number. False if the constant is ``0``, ``OFF``,
+ ``NO``, ``FALSE``, ``N``, ``IGNORE``, ``NOTFOUND``, the empty string,
+ or ends in the suffix ``-NOTFOUND``. Named boolean constants are
+ case-insensitive. If the argument is not one of these constants, it
+ is treated as a variable.
+
+``if(<variable>)``
+ True if the variable is defined to a value that is not a false
+ constant. False otherwise. (Note macro arguments are not variables.)
+
+``if(NOT <expression>)``
+ True if the expression is not true.
+
+``if(<expr1> AND <expr2>)``
+ True if both expressions would be considered true individually.
+
+``if(<expr1> OR <expr2>)``
+ True if either expression would be considered true individually.
+
+``if(COMMAND command-name)``
+ True if the given name is a command, macro or function that can be
+ invoked.
+
+``if(POLICY policy-id)``
+ 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.
+
+``if(EXISTS path-to-file-or-directory)``
+ True if the named file or directory exists. Behavior is well-defined
+ 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
+ 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
+ of a tie. This includes the case of passing the same file name for
+ both file1 and file2.
+
+``if(IS_DIRECTORY path-to-directory)``
+ True if the given name is a directory. Behavior is well-defined only
+ for full paths.
+
+``if(IS_SYMLINK file-name)``
+ True if the given name is a symbolic link. Behavior is well-defined
+ only for full paths.
+
+``if(IS_ABSOLUTE path)``
+ True if the given path is an absolute path.
+
+``if(<variable|string> MATCHES regex)``
+ True if the given string or variable's value matches the given regular
+ expression.
+
+``if(<variable|string> LESS <variable|string>)``
+ True if the given string or variable's value is a valid number and less
+ than that on the right.
+
+``if(<variable|string> GREATER <variable|string>)``
+ True if the given string or variable's value is a valid number and greater
+ than that on the right.
+
+``if(<variable|string> EQUAL <variable|string>)``
+ True if the given string or variable's value is a valid number and equal
+ to that on the right.
+
+``if(<variable|string> STRLESS <variable|string>)``
+ True if the given string or variable's value is lexicographically less
+ than the string or variable on the right.
+
+``if(<variable|string> STRGREATER <variable|string>)``
+ True if the given string or variable's value is lexicographically greater
+ than the string or variable on the right.
+
+``if(<variable|string> STREQUAL <variable|string>)``
+ True if the given string or variable's value is lexicographically equal
+ to the string or variable on the right.
+
+``if(<variable|string> VERSION_LESS <variable|string>)``
+ Component-wise integer version number comparison (version format is
+ ``major[.minor[.patch[.tweak]]]``).
+
+``if(<variable|string> VERSION_EQUAL <variable|string>)``
+ Component-wise integer version number comparison (version format is
+ ``major[.minor[.patch[.tweak]]]``).
+
+``if(<variable|string> VERSION_GREATER <variable|string>)``
+ Component-wise integer version number comparison (version format is
+ ``major[.minor[.patch[.tweak]]]``).
+
+``if(DEFINED <variable>)``
+ True if the given variable is defined. It does not matter if the
+ variable is true or false just if it has been set. (Note macro
+ arguments are not variables.)
+
+``if((expression) AND (expression OR (expression)))``
+ The expressions inside the parenthesis are evaluated first and then
+ the remaining expression is evaluated as in the previous examples.
+ Where there are nested parenthesis the innermost are evaluated as part
+ of evaluating the expression that contains them.
+
+The if command was written very early in CMake's history, predating
+the ``${}`` variable evaluation syntax, and for convenience evaluates
+variables named by its arguments as shown in the above signatures.
+Note that normal variable evaluation with ``${}`` applies before the if
+command even receives the arguments. Therefore code like::
+
+ set(var1 OFF)
+ set(var2 "var1")
+ if(${var2})
+
+appears to the if command as::
+
+ if(var1)
+
+and is evaluated according to the ``if(<variable>)`` case documented
+above. The result is ``OFF`` which is false. However, if we remove the
+``${}`` from the example then the command sees::
+
+ if(var2)
+
+which is true because ``var2`` is defined to "var1" which is not a false
+constant.
+
+Automatic evaluation applies in the other cases whenever the
+above-documented signature accepts ``<variable|string>``:
+
+* The left hand argument to ``MATCHES`` is first checked to see if it is
+ a defined variable, if so the variable's value is used, otherwise the
+ original value is used.
+
+* If the left hand argument to ``MATCHES`` is missing it returns false
+ without error
+
+* Both left and right hand arguments to ``LESS``, ``GREATER``, and
+ ``EQUAL`` are independently tested to see if they are defined
+ variables, if so their defined values are used otherwise the original
+ value is used.
+
+* Both left and right hand arguments to ``STRLESS``, ``STREQUAL``, and
+ ``STRGREATER`` are independently tested to see if they are defined
+ variables, if so their defined values are used otherwise the original
+ value is used.
+
+* Both left and right hand arguments to ``VERSION_LESS``,
+ ``VERSION_EQUAL``, and ``VERSION_GREATER`` are independently tested
+ to see if they are defined variables, if so their defined values are
+ used otherwise the original value is used.
+
+* The right hand argument to ``NOT`` is tested to see if it is a boolean
+ constant, if so the value is used, otherwise it is assumed to be a
+ variable and it is dereferenced.
+
+* The left and right hand arguments to ``AND`` and ``OR`` are independently
+ tested to see if they are boolean constants, if so they are used as
+ such, otherwise they are assumed to be variables and are dereferenced.
+
+To prevent ambiguity, potential variable or keyword names can be
+specified in a :ref:`Quoted Argument` or a :ref:`Bracket Argument`.
+A quoted or bracketed variable or keyword will be interpreted as a
+string and not dereferenced or interpreted.
+See policy :policy:`CMP0054`.
diff --git a/Help/command/include.rst b/Help/command/include.rst
new file mode 100644
index 0000000000..a9074c1b65
--- /dev/null
+++ b/Help/command/include.rst
@@ -0,0 +1,25 @@
+include
+-------
+
+Load and run CMake code from a file or module.
+
+::
+
+ include(<file|module> [OPTIONAL] [RESULT_VARIABLE <VAR>]
+ [NO_POLICY_SCOPE])
+
+Load and run CMake code from the file given. Variable reads and
+writes access the scope of the caller (dynamic scoping). If OPTIONAL
+is present, then no error is raised if the file does not exist. If
+RESULT_VARIABLE is given the variable will be set to the full filename
+which has been included or NOTFOUND if it failed.
+
+If a module is specified instead of a file, the file with name
+<modulename>.cmake is searched first in CMAKE_MODULE_PATH, then in the
+CMake module directory. There is one exception to this: if the file
+which calls include() is located itself in the CMake module directory,
+then first the CMake module directory is searched and
+CMAKE_MODULE_PATH afterwards. See also policy CMP0017.
+
+See the cmake_policy() command documentation for discussion of the
+NO_POLICY_SCOPE option.
diff --git a/Help/command/include_directories.rst b/Help/command/include_directories.rst
new file mode 100644
index 0000000000..f69493460e
--- /dev/null
+++ b/Help/command/include_directories.rst
@@ -0,0 +1,35 @@
+include_directories
+-------------------
+
+Add include directories to the build.
+
+::
+
+ include_directories([AFTER|BEFORE] [SYSTEM] dir1 [dir2 ...])
+
+Add the given directories to those the compiler uses to search for
+include files. Relative paths are interpreted as relative to the
+current source directory.
+
+The include directories are added to the :prop_dir:`INCLUDE_DIRECTORIES`
+directory property for the current ``CMakeLists`` file. They are also
+added to the :prop_tgt:`INCLUDE_DIRECTORIES` target property for each
+target in the current ``CMakeLists`` file. The target property values
+are the ones used by the generators.
+
+By default the directories specified are appended onto the current list of
+directories. This default behavior can be changed by setting
+:variable:`CMAKE_INCLUDE_DIRECTORIES_BEFORE` to ``ON``. By using
+``AFTER`` or ``BEFORE`` explicitly, you can select between appending and
+prepending, independent of the default.
+
+If the ``SYSTEM`` option is given, the compiler will be told the
+directories are meant as system include directories on some platforms.
+Signalling this setting might achieve effects such as the compiler
+skipping warnings, or these fixed-install system files not being
+considered in dependency calculations - see compiler docs.
+
+Arguments to ``include_directories`` 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/Help/command/include_external_msproject.rst b/Help/command/include_external_msproject.rst
new file mode 100644
index 0000000000..ba9a3934aa
--- /dev/null
+++ b/Help/command/include_external_msproject.rst
@@ -0,0 +1,23 @@
+include_external_msproject
+--------------------------
+
+Include an external Microsoft project file in a workspace.
+
+::
+
+ include_external_msproject(projectname location
+ [TYPE projectTypeGUID]
+ [GUID projectGUID]
+ [PLATFORM platformName]
+ dep1 dep2 ...)
+
+Includes an external Microsoft project in the generated workspace
+file. Currently does nothing on UNIX. This will create a target
+named [projectname]. This can be used in the add_dependencies command
+to make things depend on the external project.
+
+TYPE, GUID and PLATFORM are optional parameters that allow one to
+specify the type of project, id (GUID) of the project and the name of
+the target platform. This is useful for projects requiring values
+other than the default (e.g. WIX projects). These options are not
+supported by the Visual Studio 6 generator.
diff --git a/Help/command/include_regular_expression.rst b/Help/command/include_regular_expression.rst
new file mode 100644
index 0000000000..dd887df5d4
--- /dev/null
+++ b/Help/command/include_regular_expression.rst
@@ -0,0 +1,18 @@
+include_regular_expression
+--------------------------
+
+Set the regular expression used for dependency checking.
+
+::
+
+ include_regular_expression(regex_match [regex_complain])
+
+Set the regular expressions used in dependency checking. Only files
+matching regex_match will be traced as dependencies. Only files
+matching regex_complain will generate warnings if they cannot be found
+(standard header paths are not searched). The defaults are:
+
+::
+
+ regex_match = "^.*$" (match everything)
+ regex_complain = "^$" (match empty string only)
diff --git a/Help/command/install.rst b/Help/command/install.rst
new file mode 100644
index 0000000000..4c52abf71d
--- /dev/null
+++ b/Help/command/install.rst
@@ -0,0 +1,341 @@
+install
+-------
+
+.. only:: html
+
+ .. contents::
+
+Specify rules to run at install time.
+
+Introduction
+^^^^^^^^^^^^
+
+This command generates installation rules for a project. Rules
+specified by calls to this command within a source directory are
+executed in order during installation. The order across directories
+is not defined.
+
+There are multiple signatures for this command. Some of them define
+installation options for files and targets. Options common to
+multiple signatures are covered here but they are valid only for
+signatures that specify them. The common options are:
+
+``DESTINATION``
+ Specify the directory on disk to which a file will be installed.
+ If a full path (with a leading slash or drive letter) is given
+ it is used directly. If a relative path is given it is interpreted
+ relative to the value of the :variable:`CMAKE_INSTALL_PREFIX` variable.
+ The prefix can be relocated at install time using the ``DESTDIR``
+ mechanism explained in the :variable:`CMAKE_INSTALL_PREFIX` variable
+ documentation.
+
+``PERMISSIONS``
+ Specify permissions for installed files. Valid permissions are
+ ``OWNER_READ``, ``OWNER_WRITE``, ``OWNER_EXECUTE``, ``GROUP_READ``,
+ ``GROUP_WRITE``, ``GROUP_EXECUTE``, ``WORLD_READ``, ``WORLD_WRITE``,
+ ``WORLD_EXECUTE``, ``SETUID``, and ``SETGID``. Permissions that do
+ not make sense on certain platforms are ignored on those platforms.
+
+``CONFIGURATIONS``
+ Specify a list of build configurations for which the install rule
+ applies (Debug, Release, etc.).
+
+``COMPONENT``
+ Specify an installation component name with which the install rule
+ is associated, such as "runtime" or "development". During
+ component-specific installation only install rules associated with
+ the given component name will be executed. During a full installation
+ all components are installed. If ``COMPONENT`` is not provided a
+ default component "Unspecified" is created. The default component
+ name may be controlled with the
+ :variable:`CMAKE_INSTALL_DEFAULT_COMPONENT_NAME` variable.
+
+``RENAME``
+ Specify a name for an installed file that may be different from the
+ original file. Renaming is allowed only when a single file is
+ installed by the command.
+
+``OPTIONAL``
+ Specify that it is not an error if the file to be installed does
+ not exist.
+
+Command signatures that install files may print messages during
+installation. Use the :variable:`CMAKE_INSTALL_MESSAGE` variable
+to control which messages are printed.
+
+Installing Targets
+^^^^^^^^^^^^^^^^^^
+
+::
+
+ install(TARGETS targets... [EXPORT <export-name>]
+ [[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]
+ ] [...])
+
+The ``TARGETS`` form specifies rules for installing targets from a
+project. There are five kinds of target files that may be installed:
+``ARCHIVE``, ``LIBRARY``, ``RUNTIME``, ``FRAMEWORK``, and ``BUNDLE``.
+Executables are treated as ``RUNTIME`` targets, except that those
+marked with the ``MACOSX_BUNDLE`` property are treated as ``BUNDLE``
+targets on OS X. Static libraries are always treated as ``ARCHIVE``
+targets. Module libraries are always treated as ``LIBRARY`` targets.
+For non-DLL platforms shared libraries are treated as ``LIBRARY``
+targets, except that those marked with the ``FRAMEWORK`` property are
+treated as ``FRAMEWORK`` targets on OS X. For DLL platforms the DLL
+part of a shared library is treated as a ``RUNTIME`` target and the
+corresponding import library is treated as an ``ARCHIVE`` target.
+All Windows-based systems including Cygwin are DLL platforms.
+The ``ARCHIVE``, ``LIBRARY``, ``RUNTIME``, and ``FRAMEWORK`` arguments
+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>``.
+
+The ``PRIVATE_HEADER``, ``PUBLIC_HEADER``, and ``RESOURCE`` arguments
+cause subsequent properties to be applied to installing a ``FRAMEWORK``
+shared library target's associated files on non-Apple platforms. Rules
+defined by these arguments are ignored on Apple platforms because the
+associated files are installed into the appropriate locations inside
+the framework folder. See documentation of the
+:prop_tgt:`PRIVATE_HEADER`, :prop_tgt:`PUBLIC_HEADER`, and
+:prop_tgt:`RESOURCE` target properties for details.
+
+Either ``NAMELINK_ONLY`` or ``NAMELINK_SKIP`` may be specified as a
+``LIBRARY`` option. On some platforms a versioned shared library
+has a symbolic link such as::
+
+ lib<name>.so -> lib<name>.so.1
+
+where ``lib<name>.so.1`` is the soname of the library and ``lib<name>.so``
+is a "namelink" allowing linkers to find the library when given
+``-l<name>``. The ``NAMELINK_ONLY`` option causes installation of only the
+namelink when a library target is installed. The ``NAMELINK_SKIP`` option
+causes installation of library files other than the namelink when a
+library target is installed. When neither option is given both
+portions are installed. On platforms where versioned shared libraries
+do not have namelinks or when a library is not versioned the
+``NAMELINK_SKIP`` option installs the library and the ``NAMELINK_ONLY``
+option installs nothing. See the :prop_tgt:`VERSION` and
+:prop_tgt:`SOVERSION` target properties for details on creating versioned
+shared libraries.
+
+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``,
+``mySharedLib``, and ``myStaticLib``. The code:
+
+.. code-block:: cmake
+
+ install(TARGETS myExe mySharedLib myStaticLib
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib/static)
+ install(TARGETS mySharedLib DESTINATION /some/full/path)
+
+will install ``myExe`` to ``<prefix>/bin`` and ``myStaticLib`` to
+``<prefix>/lib/static``. On non-DLL platforms ``mySharedLib`` will be
+installed to ``<prefix>/lib`` and ``/some/full/path``. On DLL platforms
+the ``mySharedLib`` DLL will be installed to ``<prefix>/bin`` and
+``/some/full/path`` and its import library will be installed to
+``<prefix>/lib/static`` and ``/some/full/path``.
+
+The ``EXPORT`` option associates the installed target files with an
+export called ``<export-name>``. It must appear before any ``RUNTIME``,
+``LIBRARY``, or ``ARCHIVE`` options. To actually install the export
+file itself, call ``install(EXPORT)``, documented below.
+
+Installing a target with the :prop_tgt:`EXCLUDE_FROM_ALL` target property
+set to ``TRUE`` has undefined behavior.
+
+Installing Files
+^^^^^^^^^^^^^^^^
+
+::
+
+ install(<FILES|PROGRAMS> files... DESTINATION <dir>
+ [PERMISSIONS permissions...]
+ [CONFIGURATIONS [Debug|Release|...]]
+ [COMPONENT <component>]
+ [RENAME <name>] [OPTIONAL])
+
+The ``FILES`` form specifies rules for installing files for a project.
+File names given as relative paths are interpreted with respect to the
+current source directory. Files installed by this form are by default
+given permissions ``OWNER_WRITE``, ``OWNER_READ``, ``GROUP_READ``, and
+``WORLD_READ`` if no ``PERMISSIONS`` argument is given.
+
+The ``PROGRAMS`` form is identical to the ``FILES`` form except that the
+default permissions for the installed file also include ``OWNER_EXECUTE``,
+``GROUP_EXECUTE``, and ``WORLD_EXECUTE``. This form is intended to install
+programs that are not targets, such as shell scripts. Use the ``TARGETS``
+form to install targets built within the project.
+
+The list of ``files...`` given to ``FILES`` or ``PROGRAMS`` may use
+"generator expressions" with the syntax ``$<...>``. See the
+:manual:`cmake-generator-expressions(7)` manual for available expressions.
+However, if any item begins in a generator expression it must evaluate
+to a full path.
+
+Installing Directories
+^^^^^^^^^^^^^^^^^^^^^^
+
+::
+
+ install(DIRECTORY dirs... DESTINATION <dir>
+ [FILE_PERMISSIONS permissions...]
+ [DIRECTORY_PERMISSIONS permissions...]
+ [USE_SOURCE_PERMISSIONS] [OPTIONAL] [MESSAGE_NEVER]
+ [CONFIGURATIONS [Debug|Release|...]]
+ [COMPONENT <component>] [FILES_MATCHING]
+ [[PATTERN <pattern> | REGEX <regex>]
+ [EXCLUDE] [PERMISSIONS permissions...]] [...])
+
+The ``DIRECTORY`` form installs contents of one or more directories to a
+given destination. The directory structure is copied verbatim to the
+destination. The last component of each directory name is appended to
+the destination directory but a trailing slash may be used to avoid
+this because it leaves the last component empty. Directory names
+given as relative paths are interpreted with respect to the current
+source directory. If no input directory names are given the
+destination directory will be created but nothing will be installed
+into it. The ``FILE_PERMISSIONS`` and ``DIRECTORY_PERMISSIONS`` options
+specify permissions given to files and directories in the destination.
+If ``USE_SOURCE_PERMISSIONS`` is specified and ``FILE_PERMISSIONS`` is not,
+file permissions will be copied from the source directory structure.
+If no permissions are specified files will be given the default
+permissions specified in the ``FILES`` form of the command, and the
+directories will be given the default permissions specified in the
+``PROGRAMS`` form of the command.
+
+The ``MESSAGE_NEVER`` option disables file installation status output.
+
+Installation of directories may be controlled with fine granularity
+using the ``PATTERN`` or ``REGEX`` options. These "match" options specify a
+globbing pattern or regular expression to match directories or files
+encountered within input directories. They may be used to apply
+certain options (see below) to a subset of the files and directories
+encountered. The full path to each input file or directory (with
+forward slashes) is matched against the expression. A ``PATTERN`` will
+match only complete file names: the portion of the full path matching
+the pattern must occur at the end of the file name and be preceded by
+a slash. A ``REGEX`` will match any portion of the full path but it may
+use ``/`` and ``$`` to simulate the ``PATTERN`` behavior. By default all
+files and directories are installed whether or not they are matched.
+The ``FILES_MATCHING`` option may be given before the first match option
+to disable installation of files (but not directories) not matched by
+any expression. For example, the code
+
+.. code-block:: cmake
+
+ install(DIRECTORY src/ DESTINATION include/myproj
+ FILES_MATCHING PATTERN "*.h")
+
+will extract and install header files from a source tree.
+
+Some options may follow a ``PATTERN`` or ``REGEX`` expression and are applied
+only to files or directories matching them. The ``EXCLUDE`` option will
+skip the matched file or directory. The ``PERMISSIONS`` option overrides
+the permissions setting for the matched file or directory. For
+example the code
+
+.. code-block:: cmake
+
+ install(DIRECTORY icons scripts/ DESTINATION share/myproj
+ PATTERN "CVS" EXCLUDE
+ PATTERN "scripts/*"
+ PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
+ GROUP_EXECUTE GROUP_READ)
+
+will install the ``icons`` directory to ``share/myproj/icons`` and the
+``scripts`` directory to ``share/myproj``. The icons will get default
+file permissions, the scripts will be given specific permissions, and any
+``CVS`` directories will be excluded.
+
+Custom Installation Logic
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+::
+
+ install([[SCRIPT <file>] [CODE <code>]] [...])
+
+The ``SCRIPT`` form will invoke the given CMake script files during
+installation. If the script file name is a relative path it will be
+interpreted with respect to the current source directory. The ``CODE``
+form will invoke the given CMake code during installation. Code is
+specified as a single argument inside a double-quoted string. For
+example, the code
+
+.. code-block:: cmake
+
+ install(CODE "MESSAGE(\"Sample install message.\")")
+
+will print a message during installation.
+
+Installing Exports
+^^^^^^^^^^^^^^^^^^
+
+::
+
+ install(EXPORT <export-name> DESTINATION <dir>
+ [NAMESPACE <namespace>] [FILE <name>.cmake]
+ [PERMISSIONS permissions...]
+ [CONFIGURATIONS [Debug|Release|...]]
+ [EXPORT_LINK_INTERFACE_LIBRARIES]
+ [COMPONENT <component>])
+
+The ``EXPORT`` form generates and installs a CMake file containing code to
+import targets from the installation tree into another project.
+Target installations are associated with the export ``<export-name>``
+using the ``EXPORT`` option of the ``install(TARGETS)`` signature
+documented above. The ``NAMESPACE`` option will prepend ``<namespace>`` to
+the target names as they are written to the import file. By default
+the generated file will be called ``<export-name>.cmake`` but the ``FILE``
+option may be used to specify a different name. The value given to
+the ``FILE`` option must be a file name with the ``.cmake`` extension.
+If a ``CONFIGURATIONS`` option is given then the file will only be installed
+when one of the named configurations is installed. Additionally, the
+generated import file will reference only the matching target
+configurations. The ``EXPORT_LINK_INTERFACE_LIBRARIES`` keyword, if
+present, causes the contents of the properties matching
+``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?`` to be exported, when
+policy :policy:`CMP0022` is ``NEW``. If a ``COMPONENT`` option is
+specified that does not match that given to the targets associated with
+``<export-name>`` the behavior is undefined. If a library target is
+included in the export but a target to which it links is not included
+the behavior is unspecified.
+
+The ``EXPORT`` form is useful to help outside projects use targets built
+and installed by the current project. For example, the code
+
+.. code-block:: cmake
+
+ install(TARGETS myexe EXPORT myproj DESTINATION bin)
+ install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)
+
+will install the executable myexe to ``<prefix>/bin`` and code to import
+it in the file ``<prefix>/lib/myproj/myproj.cmake``. An outside project
+may load this file with the include command and reference the ``myexe``
+executable from the installation tree using the imported target name
+``mp_myexe`` as if the target were built in its own tree.
+
+.. note::
+ This command supercedes the :command:`install_targets` command and
+ the :prop_tgt:`PRE_INSTALL_SCRIPT` and :prop_tgt:`POST_INSTALL_SCRIPT`
+ target properties. It also replaces the ``FILES`` forms of the
+ :command:`install_files` and :command:`install_programs` commands.
+ The processing order of these install rules relative to
+ those generated by :command:`install_targets`,
+ :command:`install_files`, and :command:`install_programs` commands
+ is not defined.
diff --git a/Help/command/install_files.rst b/Help/command/install_files.rst
new file mode 100644
index 0000000000..7b6bd81141
--- /dev/null
+++ b/Help/command/install_files.rst
@@ -0,0 +1,39 @@
+install_files
+-------------
+
+Deprecated. Use the install(FILES ) command instead.
+
+This command has been superceded by the install command. It is
+provided for compatibility with older CMake code. The FILES form is
+directly replaced by the FILES form of the install command. The
+regexp form can be expressed more clearly using the GLOB form of the
+file command.
+
+::
+
+ install_files(<dir> extension file file ...)
+
+Create rules to install the listed files with the given extension into
+the given directory. Only files existing in the current source tree
+or its corresponding location in the binary tree may be listed. If a
+file specified already has an extension, that extension will be
+removed first. This is useful for providing lists of source files
+such as foo.cxx when you want the corresponding foo.h to be installed.
+A typical extension is '.h'.
+
+::
+
+ install_files(<dir> regexp)
+
+Any files in the current source directory that match the regular
+expression will be installed.
+
+::
+
+ install_files(<dir> FILES file file ...)
+
+Any files listed after the FILES keyword will be installed explicitly
+from the names given. Full paths are allowed in this form.
+
+The directory <dir> is relative to the installation prefix, which is
+stored in the variable CMAKE_INSTALL_PREFIX.
diff --git a/Help/command/install_programs.rst b/Help/command/install_programs.rst
new file mode 100644
index 0000000000..26789d8db4
--- /dev/null
+++ b/Help/command/install_programs.rst
@@ -0,0 +1,33 @@
+install_programs
+----------------
+
+Deprecated. Use the install(PROGRAMS ) command instead.
+
+This command has been superceded by the install command. It is
+provided for compatibility with older CMake code. The FILES form is
+directly replaced by the PROGRAMS form of the INSTALL command. The
+regexp form can be expressed more clearly using the GLOB form of the
+FILE command.
+
+::
+
+ install_programs(<dir> file1 file2 [file3 ...])
+ install_programs(<dir> FILES file1 [file2 ...])
+
+Create rules to install the listed programs into the given directory.
+Use the FILES argument to guarantee that the file list version of the
+command will be used even when there is only one argument.
+
+::
+
+ install_programs(<dir> regexp)
+
+In the second form any program in the current source directory that
+matches the regular expression will be installed.
+
+This command is intended to install programs that are not built by
+cmake, such as shell scripts. See the TARGETS form of the INSTALL
+command to create installation rules for targets built by cmake.
+
+The directory <dir> is relative to the installation prefix, which is
+stored in the variable CMAKE_INSTALL_PREFIX.
diff --git a/Help/command/install_targets.rst b/Help/command/install_targets.rst
new file mode 100644
index 0000000000..caa933f4bc
--- /dev/null
+++ b/Help/command/install_targets.rst
@@ -0,0 +1,17 @@
+install_targets
+---------------
+
+Deprecated. Use the install(TARGETS ) command instead.
+
+This command has been superceded by the install command. It is
+provided for compatibility with older CMake code.
+
+::
+
+ install_targets(<dir> [RUNTIME_DIRECTORY dir] target target)
+
+Create rules to install the listed targets into the given directory.
+The directory <dir> is relative to the installation prefix, which is
+stored in the variable CMAKE_INSTALL_PREFIX. If RUNTIME_DIRECTORY is
+specified, then on systems with special runtime files (Windows DLL),
+the files will be copied to that directory.
diff --git a/Help/command/link_directories.rst b/Help/command/link_directories.rst
new file mode 100644
index 0000000000..bdc94cd734
--- /dev/null
+++ b/Help/command/link_directories.rst
@@ -0,0 +1,19 @@
+link_directories
+----------------
+
+Specify directories in which the linker will look for libraries.
+
+::
+
+ link_directories(directory1 directory2 ...)
+
+Specify the paths in which the linker should search for libraries.
+The command will apply only to targets created after it is called.
+Relative paths given to this command are interpreted as relative to
+the current source directory, see CMP0015.
+
+Note that this command is rarely necessary. Library locations
+returned by find_package() and find_library() are absolute paths.
+Pass these absolute library file paths directly to the
+target_link_libraries() command. CMake will ensure the linker finds
+them.
diff --git a/Help/command/link_libraries.rst b/Help/command/link_libraries.rst
new file mode 100644
index 0000000000..d690c9b2d4
--- /dev/null
+++ b/Help/command/link_libraries.rst
@@ -0,0 +1,16 @@
+link_libraries
+--------------
+
+Deprecated. Use the target_link_libraries() command instead.
+
+Link libraries to all targets added later.
+
+::
+
+ link_libraries(library1 <debug | optimized> library2 ...)
+
+Specify a list of libraries to be linked into any following targets
+(typically added with the add_executable or add_library calls). This
+command is passed down to all subdirectories. The debug and optimized
+strings may be used to indicate that the next library listed is to be
+used only for that specific type of build.
diff --git a/Help/command/list.rst b/Help/command/list.rst
new file mode 100644
index 0000000000..aeb1e940a3
--- /dev/null
+++ b/Help/command/list.rst
@@ -0,0 +1,61 @@
+list
+----
+
+List operations.
+
+::
+
+ list(LENGTH <list> <output variable>)
+ list(GET <list> <element index> [<element index> ...]
+ <output variable>)
+ list(APPEND <list> [<element> ...])
+ list(FIND <list> <value> <output variable>)
+ list(INSERT <list> <element_index> <element> [<element> ...])
+ list(REMOVE_ITEM <list> <value> [<value> ...])
+ list(REMOVE_AT <list> <index> [<index> ...])
+ list(REMOVE_DUPLICATES <list>)
+ list(REVERSE <list>)
+ list(SORT <list>)
+
+LENGTH will return a given list's length.
+
+GET will return list of elements specified by indices from the list.
+
+APPEND will append elements to the list.
+
+FIND will return the index of the element specified in the list or -1
+if it wasn't found.
+
+INSERT will insert elements to the list to the specified location.
+
+REMOVE_AT and REMOVE_ITEM will remove items from the list. The
+difference is that REMOVE_ITEM will remove the given items, while
+REMOVE_AT will remove the items at the given indices.
+
+REMOVE_DUPLICATES will remove duplicated items in the list.
+
+REVERSE reverses the contents of the list in-place.
+
+SORT sorts the list in-place alphabetically.
+
+The list subcommands APPEND, INSERT, REMOVE_AT, REMOVE_ITEM,
+REMOVE_DUPLICATES, REVERSE and SORT may create new values for the list
+within the current CMake variable scope. Similar to the SET command,
+the LIST command creates new variable values in the current scope,
+even if the list itself is actually defined in a parent scope. To
+propagate the results of these operations upwards, use SET with
+PARENT_SCOPE, SET with CACHE INTERNAL, or some other means of value
+propagation.
+
+NOTES: A list in cmake is a ; separated group of strings. To create a
+list the set command can be used. For example, set(var a b c d e)
+creates a list with a;b;c;d;e, and set(var "a b c d e") creates a
+string or a list with one item in it. (Note macro arguments are not
+variables, and therefore cannot be used in LIST commands.)
+
+When specifying index values, if <element index> is 0 or greater, it
+is indexed from the beginning of the list, with 0 representing the
+first list element. If <element index> is -1 or lesser, it is indexed
+from the end of the list, with -1 representing the last list element.
+Be careful when counting with negative indices: they do not start from
+0. -0 is equivalent to 0, the first list element.
diff --git a/Help/command/load_cache.rst b/Help/command/load_cache.rst
new file mode 100644
index 0000000000..b7484cb6d9
--- /dev/null
+++ b/Help/command/load_cache.rst
@@ -0,0 +1,27 @@
+load_cache
+----------
+
+Load in the values from another project's CMake cache.
+
+::
+
+ load_cache(pathToCacheFile READ_WITH_PREFIX
+ prefix entry1...)
+
+Read the cache and store the requested entries in variables with their
+name prefixed with the given prefix. This only reads the values, and
+does not create entries in the local project's cache.
+
+::
+
+ load_cache(pathToCacheFile [EXCLUDE entry1...]
+ [INCLUDE_INTERNALS entry1...])
+
+Load in the values from another cache and store them in the local
+project's cache as internal entries. This is useful for a project
+that depends on another project built in a different tree. EXCLUDE
+option can be used to provide a list of entries to be excluded.
+INCLUDE_INTERNALS can be used to provide a list of internal entries to
+be included. Normally, no internal entries are brought in. Use of
+this form of the command is strongly discouraged, but it is provided
+for backward compatibility.
diff --git a/Help/command/load_command.rst b/Help/command/load_command.rst
new file mode 100644
index 0000000000..fc316d4d15
--- /dev/null
+++ b/Help/command/load_command.rst
@@ -0,0 +1,23 @@
+load_command
+------------
+
+Disallowed. See CMake Policy :policy:`CMP0031`.
+
+Load a command into a running CMake.
+
+::
+
+ load_command(COMMAND_NAME <loc1> [loc2 ...])
+
+The given locations are searched for a library whose name is
+cmCOMMAND_NAME. If found, it is loaded as a module and the command is
+added to the set of available CMake commands. Usually, TRY_COMPILE is
+used before this command to compile the module. If the command is
+successfully loaded a variable named
+
+::
+
+ CMAKE_LOADED_COMMAND_<COMMAND_NAME>
+
+will be set to the full path of the module that was loaded. Otherwise
+the variable will not be set.
diff --git a/Help/command/macro.rst b/Help/command/macro.rst
new file mode 100644
index 0000000000..258dc50aae
--- /dev/null
+++ b/Help/command/macro.rst
@@ -0,0 +1,67 @@
+macro
+-----
+
+Start recording a macro for later invocation as a command.
+
+::
+
+ macro(<name> [arg1 [arg2 [arg3 ...]]])
+ COMMAND1(ARGS ...)
+ COMMAND2(ARGS ...)
+ ...
+ endmacro(<name>)
+
+Define a macro named <name> that takes arguments named arg1 arg2 arg3
+(...). Commands listed after macro, but before the matching endmacro,
+are not invoked until the macro is invoked. When it is invoked, the
+commands recorded in the macro are first modified by replacing formal
+parameters (``${arg1}``) with the arguments passed, and then invoked as
+normal commands. In addition to referencing the formal parameters you
+can reference the values ``${ARGC}`` which will be set to the number of
+arguments passed into the function as well as ``${ARGV0}`` ``${ARGV1}``
+``${ARGV2}`` ... which will have the actual values of the arguments
+passed in. This facilitates creating macros with optional arguments.
+Additionally ``${ARGV}`` holds the list of all arguments given to the
+macro and ``${ARGN}`` holds the list of arguments past the last expected
+argument.
+
+See the cmake_policy() command documentation for the behavior of
+policies inside macros.
+
+Macro Argument Caveats
+^^^^^^^^^^^^^^^^^^^^^^
+
+Note that the parameters to a macro and values such as ``ARGN`` are
+not variables in the usual CMake sense. They are string
+replacements much like the C preprocessor would do with a macro.
+Therefore you will NOT be able to use commands like::
+
+ if(ARGV1) # ARGV1 is not a variable
+ foreach(loop_var IN LISTS ARGN) # ARGN is not a variable
+
+In the first case you can use ``if(${ARGV1})``, in the second case, you can
+use ``foreach(loop_var ${ARGN})`` but this will skip empty arguments.
+If you need to include them, you can use::
+
+ set(list_var "${ARGN}")
+ foreach(loop_var IN LISTS list_var)
+
+Note that if you have a variable with the same name in the scope from
+which the macro is called, using unreferenced names will use the
+existing variable instead of the arguments. For example::
+
+ macro(_BAR)
+ foreach(arg IN LISTS ARGN)
+ [...]
+ endforeach()
+ endmacro()
+
+ function(_FOO)
+ _bar(x y z)
+ endfunction()
+
+ _foo(a b c)
+
+Will loop over ``a;b;c`` and not over ``x;y;z`` as one might be expecting.
+If you want true CMake variables and/or better CMake scope control you
+should look at the function command.
diff --git a/Help/command/make_directory.rst b/Help/command/make_directory.rst
new file mode 100644
index 0000000000..44dbe970fb
--- /dev/null
+++ b/Help/command/make_directory.rst
@@ -0,0 +1,12 @@
+make_directory
+--------------
+
+Deprecated. Use the file(MAKE_DIRECTORY ) command instead.
+
+::
+
+ make_directory(directory)
+
+Creates the specified directory. Full paths should be given. Any
+parent directories that do not exist will also be created. Use with
+care.
diff --git a/Help/command/mark_as_advanced.rst b/Help/command/mark_as_advanced.rst
new file mode 100644
index 0000000000..30b1289f7b
--- /dev/null
+++ b/Help/command/mark_as_advanced.rst
@@ -0,0 +1,19 @@
+mark_as_advanced
+----------------
+
+Mark cmake cached variables as advanced.
+
+::
+
+ mark_as_advanced([CLEAR|FORCE] VAR [VAR2 ...])
+
+Mark the named cached variables as advanced. An advanced variable
+will not be displayed in any of the cmake GUIs unless the show
+advanced option is on. If CLEAR is the first argument advanced
+variables are changed back to unadvanced. If FORCE is the first
+argument, then the variable is made advanced. If neither FORCE nor
+CLEAR is specified, new values will be marked as advanced, but if the
+variable already has an advanced/non-advanced state, it will not be
+changed.
+
+It does nothing in script mode.
diff --git a/Help/command/math.rst b/Help/command/math.rst
new file mode 100644
index 0000000000..38fde1d9d0
--- /dev/null
+++ b/Help/command/math.rst
@@ -0,0 +1,13 @@
+math
+----
+
+Mathematical expressions.
+
+::
+
+ math(EXPR <output variable> <math expression>)
+
+EXPR evaluates mathematical expression and returns result in the
+output variable. Example mathematical expression is '5 * ( 10 + 13
+)'. Supported operators are + - * / % | & ^ ~ << >> * / %. They have
+the same meaning as they do in C code.
diff --git a/Help/command/message.rst b/Help/command/message.rst
new file mode 100644
index 0000000000..a20325a237
--- /dev/null
+++ b/Help/command/message.rst
@@ -0,0 +1,33 @@
+message
+-------
+
+Display a message to the user.
+
+::
+
+ message([<mode>] "message to display" ...)
+
+The optional <mode> keyword determines the type of message:
+
+::
+
+ (none) = Important information
+ STATUS = Incidental information
+ WARNING = CMake Warning, continue processing
+ AUTHOR_WARNING = CMake Warning (dev), continue processing
+ SEND_ERROR = CMake Error, continue processing,
+ but skip generation
+ FATAL_ERROR = CMake Error, stop processing and generation
+ DEPRECATION = CMake Deprecation Error or Warning if variable
+ CMAKE_ERROR_DEPRECATED or CMAKE_WARN_DEPRECATED
+ is enabled, respectively, else no message.
+
+The CMake command-line tool displays STATUS messages on stdout and all
+other message types on stderr. The CMake GUI displays all messages in
+its log area. The interactive dialogs (ccmake and CMakeSetup) show
+STATUS messages one at a time on a status line and other messages in
+interactive pop-up boxes.
+
+CMake Warning and Error message text displays using a simple markup
+language. Non-indented text is formatted in line-wrapped paragraphs
+delimited by newlines. Indented text is considered pre-formatted.
diff --git a/Help/command/option.rst b/Help/command/option.rst
new file mode 100644
index 0000000000..244ed07bab
--- /dev/null
+++ b/Help/command/option.rst
@@ -0,0 +1,15 @@
+option
+------
+
+Provides an option that the user can optionally select.
+
+::
+
+ option(<option_variable> "help string describing option"
+ [initial value])
+
+Provide an option for the user to select as ON or OFF. If no initial
+value is provided, OFF is used.
+
+If you have options that depend on the values of other options, see
+the module help for CMakeDependentOption.
diff --git a/Help/command/output_required_files.rst b/Help/command/output_required_files.rst
new file mode 100644
index 0000000000..5e13557632
--- /dev/null
+++ b/Help/command/output_required_files.rst
@@ -0,0 +1,19 @@
+output_required_files
+---------------------
+
+Disallowed. See CMake Policy :policy:`CMP0032`.
+
+Approximate C preprocessor dependency scanning.
+
+This command exists only because ancient CMake versions provided it.
+CMake handles preprocessor dependency scanning automatically using a
+more advanced scanner.
+
+::
+
+ output_required_files(srcfile outputfile)
+
+Outputs a list of all the source files that are required by the
+specified srcfile. This list is written into outputfile. This is
+similar to writing out the dependencies for srcfile except that it
+jumps from .h files into .cxx, .c and .cpp files if possible.
diff --git a/Help/command/project.rst b/Help/command/project.rst
new file mode 100644
index 0000000000..c601a0109b
--- /dev/null
+++ b/Help/command/project.rst
@@ -0,0 +1,57 @@
+project
+-------
+
+Set a name, version, and enable languages for the entire project.
+
+.. code-block:: cmake
+
+ project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])
+ project(<PROJECT-NAME>
+ [VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
+ [LANGUAGES <language-name>...])
+
+Sets the name of the project and stores the name in the
+:variable:`PROJECT_NAME` variable. Additionally this sets variables
+
+* :variable:`PROJECT_SOURCE_DIR`,
+ :variable:`<PROJECT-NAME>_SOURCE_DIR`
+* :variable:`PROJECT_BINARY_DIR`,
+ :variable:`<PROJECT-NAME>_BINARY_DIR`
+
+If ``VERSION`` is specified, given components must be non-negative integers.
+If ``VERSION`` is not specified, the default version is the empty string.
+The ``VERSION`` option may not be used unless policy :policy:`CMP0048` is
+set to ``NEW``.
+
+The :command:`project()` command stores the version number and its components
+in variables
+
+* :variable:`PROJECT_VERSION`,
+ :variable:`<PROJECT-NAME>_VERSION`
+* :variable:`PROJECT_VERSION_MAJOR`,
+ :variable:`<PROJECT-NAME>_VERSION_MAJOR`
+* :variable:`PROJECT_VERSION_MINOR`,
+ :variable:`<PROJECT-NAME>_VERSION_MINOR`
+* :variable:`PROJECT_VERSION_PATCH`,
+ :variable:`<PROJECT-NAME>_VERSION_PATCH`
+* :variable:`PROJECT_VERSION_TWEAK`,
+ :variable:`<PROJECT-NAME>_VERSION_TWEAK`
+
+Variables corresponding to unspecified versions are set to the empty string
+(if policy :policy:`CMP0048` is set to ``NEW``).
+
+Optionally you can specify which languages your project supports.
+Example languages are ``C``, ``CXX`` (i.e. C++), ``Fortran``, etc.
+By default ``C`` and ``CXX`` are enabled if no language options are
+given. Specify language ``NONE``, or use the ``LANGUAGES`` keyword
+and list no languages, to skip enabling any languages.
+
+If a variable exists called :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`,
+the file pointed to by that variable will be included as the last step of the
+project command.
+
+The top-level ``CMakeLists.txt`` file for a project must contain a
+literal, direct call to the :command:`project` command; loading one
+through the :command:`include` command is not sufficient. If no such
+call exists CMake will implicitly add one to the top that enables the
+default languages (``C`` and ``CXX``).
diff --git a/Help/command/qt_wrap_cpp.rst b/Help/command/qt_wrap_cpp.rst
new file mode 100644
index 0000000000..81bbc06474
--- /dev/null
+++ b/Help/command/qt_wrap_cpp.rst
@@ -0,0 +1,12 @@
+qt_wrap_cpp
+-----------
+
+Create Qt Wrappers.
+
+::
+
+ qt_wrap_cpp(resultingLibraryName DestName
+ SourceLists ...)
+
+Produce moc files for all the .h files listed in the SourceLists. The
+moc files will be added to the library using the DestName source list.
diff --git a/Help/command/qt_wrap_ui.rst b/Help/command/qt_wrap_ui.rst
new file mode 100644
index 0000000000..4e033a8b95
--- /dev/null
+++ b/Help/command/qt_wrap_ui.rst
@@ -0,0 +1,14 @@
+qt_wrap_ui
+----------
+
+Create Qt user interfaces Wrappers.
+
+::
+
+ qt_wrap_ui(resultingLibraryName HeadersDestName
+ SourcesDestName SourceLists ...)
+
+Produce .h and .cxx files for all the .ui files listed in the
+SourceLists. The .h files will be added to the library using the
+HeadersDestNamesource list. The .cxx files will be added to the
+library using the SourcesDestNamesource list.
diff --git a/Help/command/remove.rst b/Help/command/remove.rst
new file mode 100644
index 0000000000..ddf0e9a2dc
--- /dev/null
+++ b/Help/command/remove.rst
@@ -0,0 +1,12 @@
+remove
+------
+
+Deprecated. Use the list(REMOVE_ITEM ) command instead.
+
+::
+
+ remove(VAR VALUE VALUE ...)
+
+Removes VALUE from the variable VAR. This is typically used to remove
+entries from a vector (e.g. semicolon separated list). VALUE is
+expanded.
diff --git a/Help/command/remove_definitions.rst b/Help/command/remove_definitions.rst
new file mode 100644
index 0000000000..566da6e6b6
--- /dev/null
+++ b/Help/command/remove_definitions.rst
@@ -0,0 +1,11 @@
+remove_definitions
+------------------
+
+Removes -D define flags added by add_definitions.
+
+::
+
+ remove_definitions(-DFOO -DBAR ...)
+
+Removes flags (added by add_definitions) from the compiler command
+line for sources in the current directory and below.
diff --git a/Help/command/return.rst b/Help/command/return.rst
new file mode 100644
index 0000000000..899470c69a
--- /dev/null
+++ b/Help/command/return.rst
@@ -0,0 +1,18 @@
+return
+------
+
+Return from a file, directory or function.
+
+::
+
+ return()
+
+Returns from a file, directory or function. When this command is
+encountered in an included file (via include() or find_package()), it
+causes processing of the current file to stop and control is returned
+to the including file. If it is encountered in a file which is not
+included by another file, e.g. a CMakeLists.txt, control is returned
+to the parent directory if there is one. If return is called in a
+function, control is returned to the caller of the function. Note
+that a macro is not a function and does not handle return like a
+function does.
diff --git a/Help/command/separate_arguments.rst b/Help/command/separate_arguments.rst
new file mode 100644
index 0000000000..a876595ee3
--- /dev/null
+++ b/Help/command/separate_arguments.rst
@@ -0,0 +1,31 @@
+separate_arguments
+------------------
+
+Parse space-separated arguments into a semicolon-separated list.
+
+::
+
+ separate_arguments(<var> <UNIX|WINDOWS>_COMMAND "<args>")
+
+Parses a unix- or windows-style command-line string "<args>" and
+stores a semicolon-separated list of the arguments in <var>. The
+entire command line must be given in one "<args>" argument.
+
+The UNIX_COMMAND mode separates arguments by unquoted whitespace. It
+recognizes both single-quote and double-quote pairs. A backslash
+escapes the next literal character (\" is "); there are no special
+escapes (\n is just n).
+
+The WINDOWS_COMMAND mode parses a windows command-line using the same
+syntax the runtime library uses to construct argv at startup. It
+separates arguments by whitespace that is not double-quoted.
+Backslashes are literal unless they precede double-quotes. See the
+MSDN article "Parsing C Command-Line Arguments" for details.
+
+::
+
+ separate_arguments(VARIABLE)
+
+Convert the value of VARIABLE to a semi-colon separated list. All
+spaces are replaced with ';'. This helps with generating command
+lines.
diff --git a/Help/command/set.rst b/Help/command/set.rst
new file mode 100644
index 0000000000..7a595505fe
--- /dev/null
+++ b/Help/command/set.rst
@@ -0,0 +1,116 @@
+set
+---
+
+Set a CMake, cache or environment variable to a given value.
+
+::
+
+ set(<variable> <value>
+ [[CACHE <type> <docstring> [FORCE]] | PARENT_SCOPE])
+
+Within CMake sets <variable> to the value <value>. <value> is
+expanded before <variable> is set to it. Normally, set will set a
+regular CMake variable. If CACHE is present, then the <variable> is
+put in the cache instead, unless it is already in the cache. See
+section 'Variable types in CMake' below for details of regular and
+cache variables and their interactions. If CACHE is used, <type> and
+<docstring> are required. <type> is used by the CMake GUI to choose a
+widget with which the user sets a value. The value for <type> may be
+one of
+
+::
+
+ FILEPATH = File chooser dialog.
+ PATH = Directory chooser dialog.
+ STRING = Arbitrary string.
+ BOOL = Boolean ON/OFF checkbox.
+ INTERNAL = No GUI entry (used for persistent variables).
+
+If <type> is INTERNAL, the cache variable is marked as internal, and
+will not be shown to the user in tools like cmake-gui. This is
+intended for values that should be persisted in the cache, but which
+users should not normally change. INTERNAL implies FORCE.
+
+Normally, set(...CACHE...) creates cache variables, but does not
+modify them. If FORCE is specified, the value of the cache variable
+is set, even if the variable is already in the cache. This should
+normally be avoided, as it will remove any changes to the cache
+variable's value by the user.
+
+If PARENT_SCOPE is present, the variable will be set in the scope
+above the current scope. Each new directory or function creates a new
+scope. This command will set the value of a variable into the parent
+directory or calling function (whichever is applicable to the case at
+hand). PARENT_SCOPE cannot be combined with CACHE.
+
+If <value> is not specified then the variable is removed instead of
+set. See also: the unset() command.
+
+::
+
+ set(<variable> <value1> ... <valueN>)
+
+In this case <variable> is set to a semicolon separated list of
+values.
+
+<variable> can be an environment variable such as:
+
+::
+
+ set( ENV{PATH} /home/martink )
+
+in which case the environment variable will be set.
+
+*** Variable types in CMake ***
+
+In CMake there are two types of variables: normal variables and cache
+variables. Normal variables are meant for the internal use of the
+script (just like variables in most programming languages); they are
+not persisted across CMake runs. Cache variables (unless set with
+INTERNAL) are mostly intended for configuration settings where the
+first CMake run determines a suitable default value, which the user
+can then override, by editing the cache with tools such as ccmake or
+cmake-gui. Cache variables are stored in the CMake cache file, and
+are persisted across CMake runs.
+
+Both types can exist at the same time with the same name but different
+values. When ${FOO} is evaluated, CMake first looks for a normal
+variable 'FOO' in scope and uses it if set. If and only if no normal
+variable exists then it falls back to the cache variable 'FOO'.
+
+Some examples:
+
+The code 'set(FOO "x")' sets the normal variable 'FOO'. It does not
+touch the cache, but it will hide any existing cache value 'FOO'.
+
+The code 'set(FOO "x" CACHE ...)' checks for 'FOO' in the cache,
+ignoring any normal variable of the same name. If 'FOO' is in the
+cache then nothing happens to either the normal variable or the cache
+variable. If 'FOO' is not in the cache, then it is added to the
+cache.
+
+Finally, whenever a cache variable is added or modified by a command,
+CMake also *removes* the normal variable of the same name from the
+current scope so that an immediately following evaluation of it will
+expose the newly cached value.
+
+Normally projects should avoid using normal and cache variables of the
+same name, as this interaction can be hard to follow. However, in
+some situations it can be useful. One example (used by some
+projects):
+
+A project has a subproject in its source tree. The child project has
+its own CMakeLists.txt, which is included from the parent
+CMakeLists.txt using add_subdirectory(). Now, if the parent and the
+child project provide the same option (for example a compiler option),
+the parent gets the first chance to add a user-editable option to the
+cache. Normally, the child would then use the same value that the
+parent uses. However, it may be necessary to hard-code the value for
+the child project's option while still allowing the user to edit the
+value used by the parent project. The parent project can achieve this
+simply by setting a normal variable with the same name as the option
+in a scope sufficient to hide the option's cache variable from the
+child completely. The parent has already set the cache variable, so
+the child's set(...CACHE...) will do nothing, and evaluating the
+option variable will use the value from the normal variable, which
+hides the cache variable.
diff --git a/Help/command/set_directory_properties.rst b/Help/command/set_directory_properties.rst
new file mode 100644
index 0000000000..834013aab3
--- /dev/null
+++ b/Help/command/set_directory_properties.rst
@@ -0,0 +1,15 @@
+set_directory_properties
+------------------------
+
+Set a property of the directory.
+
+::
+
+ set_directory_properties(PROPERTIES prop1 value1 prop2 value2)
+
+Set a property for the current directory and subdirectories. If the
+property is not found, CMake will report an error. The properties
+include: INCLUDE_DIRECTORIES, LINK_DIRECTORIES,
+INCLUDE_REGULAR_EXPRESSION, and ADDITIONAL_MAKE_CLEAN_FILES.
+ADDITIONAL_MAKE_CLEAN_FILES is a list of files that will be cleaned as
+a part of "make clean" stage.
diff --git a/Help/command/set_property.rst b/Help/command/set_property.rst
new file mode 100644
index 0000000000..8cb963edf0
--- /dev/null
+++ b/Help/command/set_property.rst
@@ -0,0 +1,43 @@
+set_property
+------------
+
+Set a named property in a given scope.
+
+::
+
+ set_property(<GLOBAL |
+ DIRECTORY [dir] |
+ TARGET [target1 [target2 ...]] |
+ SOURCE [src1 [src2 ...]] |
+ TEST [test1 [test2 ...]] |
+ CACHE [entry1 [entry2 ...]]>
+ [APPEND] [APPEND_STRING]
+ PROPERTY <name> [value1 [value2 ...]])
+
+Set one property on zero or more objects of a scope. The first
+argument determines the scope in which the property is set. It must
+be one of the following:
+
+GLOBAL scope is unique and does not accept a name.
+
+DIRECTORY scope defaults to the current directory but another
+directory (already processed by CMake) may be named by full or
+relative path.
+
+TARGET scope may name zero or more existing targets.
+
+SOURCE scope may name zero or more source files. Note that source
+file properties are visible only to targets added in the same
+directory (CMakeLists.txt).
+
+TEST scope may name zero or more existing tests.
+
+CACHE scope must name zero or more cache existing entries.
+
+The required PROPERTY option is immediately followed by the name of
+the property to set. Remaining arguments are used to compose the
+property value in the form of a semicolon-separated list. If the
+APPEND option is given the list is appended to any existing property
+value.If the APPEND_STRING option is given the string is append to any
+existing property value as string, i.e. it results in a longer string
+and not a list of strings.
diff --git a/Help/command/set_source_files_properties.rst b/Help/command/set_source_files_properties.rst
new file mode 100644
index 0000000000..8ea02a375c
--- /dev/null
+++ b/Help/command/set_source_files_properties.rst
@@ -0,0 +1,15 @@
+set_source_files_properties
+---------------------------
+
+Source files can have properties that affect how they are built.
+
+::
+
+ set_source_files_properties([file1 [file2 [...]]]
+ PROPERTIES prop1 value1
+ [prop2 value2 [...]])
+
+Set properties associated with source files using a key/value paired
+list. See properties documentation for those known to CMake.
+Unrecognized properties are ignored. Source file properties are
+visible only to targets added in the same directory (CMakeLists.txt).
diff --git a/Help/command/set_target_properties.rst b/Help/command/set_target_properties.rst
new file mode 100644
index 0000000000..f65ee24946
--- /dev/null
+++ b/Help/command/set_target_properties.rst
@@ -0,0 +1,104 @@
+set_target_properties
+---------------------
+
+Targets can have properties that affect how they are built.
+
+::
+
+ set_target_properties(target1 target2 ...
+ PROPERTIES prop1 value1
+ prop2 value2 ...)
+
+Set properties on a target. The syntax for the command is to list all
+the files you want to change, and then provide the values you want to
+set next. You can use any prop value pair you want and extract it
+later with the GET_TARGET_PROPERTY command.
+
+Properties that affect the name of a target's output file are as
+follows. The PREFIX and SUFFIX properties override the default target
+name prefix (such as "lib") and suffix (such as ".so"). IMPORT_PREFIX
+and IMPORT_SUFFIX are the equivalent properties for the import library
+corresponding to a DLL (for SHARED library targets). OUTPUT_NAME sets
+the real name of a target when it is built and can be used to help
+create two targets of the same name even though CMake requires unique
+logical target names. There is also a <CONFIG>_OUTPUT_NAME that can
+set the output name on a per-configuration basis. <CONFIG>_POSTFIX
+sets a postfix for the real name of the target when it is built under
+the configuration named by <CONFIG> (in upper-case, such as
+"DEBUG_POSTFIX"). The value of this property is initialized when the
+target is created to the value of the variable CMAKE_<CONFIG>_POSTFIX
+(except for executable targets because earlier CMake versions which
+did not use this variable for executables).
+
+The LINK_FLAGS property can be used to add extra flags to the link
+step of a target. LINK_FLAGS_<CONFIG> will add to the configuration
+<CONFIG>, for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO.
+DEFINE_SYMBOL sets the name of the preprocessor symbol defined when
+compiling sources in a shared library. If not set here then it is set
+to target_EXPORTS by default (with some substitutions if the target is
+not a valid C identifier). This is useful for headers to know whether
+they are being included from inside their library or outside to
+properly setup dllexport/dllimport decorations. The COMPILE_FLAGS
+property sets additional compiler flags used to build sources within
+the target. It may also be used to pass additional preprocessor
+definitions.
+
+The LINKER_LANGUAGE property is used to change the tool used to link
+an executable or shared library. The default is set the language to
+match the files in the library. CXX and C are common values for this
+property.
+
+For shared libraries VERSION and SOVERSION can be used to specify the
+build version and API version respectively. When building or
+installing appropriate symlinks are created if the platform supports
+symlinks and the linker supports so-names. If only one of both is
+specified the missing is assumed to have the same version number. For
+executables VERSION can be used to specify the build version. When
+building or installing appropriate symlinks are created if the
+platform supports symlinks. For shared libraries and executables on
+Windows the VERSION attribute is parsed to extract a "major.minor"
+version number. These numbers are used as the image version of the
+binary.
+
+There are a few properties used to specify RPATH rules. INSTALL_RPATH
+is a semicolon-separated list specifying the rpath to use in installed
+targets (for platforms that support it). INSTALL_RPATH_USE_LINK_PATH
+is a boolean that if set to true will append directories in the linker
+search path and outside the project to the INSTALL_RPATH.
+SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic
+generation of an rpath allowing the target to run from the build tree.
+BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link the
+target in the build tree with the INSTALL_RPATH. This takes
+precedence over SKIP_BUILD_RPATH and avoids the need for relinking
+before installation. INSTALL_NAME_DIR is a string specifying the
+directory portion of the "install_name" field of shared libraries on
+Mac OSX to use in the installed targets. When the target is created
+the values of the variables CMAKE_INSTALL_RPATH,
+CMAKE_INSTALL_RPATH_USE_LINK_PATH, CMAKE_SKIP_BUILD_RPATH,
+CMAKE_BUILD_WITH_INSTALL_RPATH, and CMAKE_INSTALL_NAME_DIR are used to
+initialize these properties.
+
+PROJECT_LABEL can be used to change the name of the target in an IDE
+like visual studio. VS_KEYWORD can be set to change the visual studio
+keyword, for example Qt integration works better if this is set to
+Qt4VSv1.0.
+
+VS_SCC_PROJECTNAME, VS_SCC_LOCALPATH, VS_SCC_PROVIDER and
+VS_SCC_AUXPATH can be set to add support for source control bindings
+in a Visual Studio project file.
+
+VS_GLOBAL_<variable> can be set to add a Visual Studio
+project-specific global variable. Qt integration works better if
+VS_GLOBAL_QtVersion is set to the Qt version FindQt4.cmake found. For
+example, "4.7.3"
+
+The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the old
+way to specify CMake scripts to run before and after installing a
+target. They are used only when the old INSTALL_TARGETS command is
+used to install the target. Use the INSTALL command instead.
+
+The EXCLUDE_FROM_DEFAULT_BUILD property is used by the visual studio
+generators. If it is set to 1 the target will not be part of the
+default build when you select "Build Solution". This can also be set
+on a per-configuration basis using
+EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>.
diff --git a/Help/command/set_tests_properties.rst b/Help/command/set_tests_properties.rst
new file mode 100644
index 0000000000..e29d690476
--- /dev/null
+++ b/Help/command/set_tests_properties.rst
@@ -0,0 +1,36 @@
+set_tests_properties
+--------------------
+
+Set a property of the tests.
+
+::
+
+ set_tests_properties(test1 [test2...] PROPERTIES prop1 value1 prop2 value2)
+
+Set a property for the tests. If the property is not found, CMake
+will report an error. Generator expressions will be expanded the same
+as supported by the test's add_test call. The properties include:
+
+WILL_FAIL: If set to true, this will invert the pass/fail flag of the
+test.
+
+PASS_REGULAR_EXPRESSION: If set, the test output will be checked
+against the specified regular expressions and at least one of the
+regular expressions has to match, otherwise the test will fail.
+
+::
+
+ Example: PASS_REGULAR_EXPRESSION "TestPassed;All ok"
+
+FAIL_REGULAR_EXPRESSION: If set, if the output will match to one of
+specified regular expressions, the test will fail.
+
+::
+
+ Example: FAIL_REGULAR_EXPRESSION "[^a-z]Error;ERROR;Failed"
+
+Both PASS_REGULAR_EXPRESSION and FAIL_REGULAR_EXPRESSION expect a list
+of regular expressions.
+
+TIMEOUT: Setting this will limit the test runtime to the number of
+seconds specified.
diff --git a/Help/command/site_name.rst b/Help/command/site_name.rst
new file mode 100644
index 0000000000..e17c1ee682
--- /dev/null
+++ b/Help/command/site_name.rst
@@ -0,0 +1,8 @@
+site_name
+---------
+
+Set the given variable to the name of the computer.
+
+::
+
+ site_name(variable)
diff --git a/Help/command/source_group.rst b/Help/command/source_group.rst
new file mode 100644
index 0000000000..6e3829c044
--- /dev/null
+++ b/Help/command/source_group.rst
@@ -0,0 +1,44 @@
+source_group
+------------
+
+Define a grouping for source files in IDE project generation.
+
+.. code-block:: cmake
+
+ source_group(<name> [FILES <src>...] [REGULAR_EXPRESSION <regex>])
+
+Defines a group into which sources will be placed in project files.
+This is intended to set up file tabs in Visual Studio.
+The options are:
+
+``FILES``
+ Any source file specified explicitly will be placed in group
+ ``<name>``. Relative paths are interpreted with respect to the
+ current source directory.
+
+``REGULAR_EXPRESSION``
+ Any source file whose name matches the regular expression will
+ be placed in group ``<name>``.
+
+If a source file matches multiple groups, the *last* group that
+explicitly lists the file with ``FILES`` will be favored, if any.
+If no group explicitly lists the file, the *last* group whose
+regular expression matches the file will be favored.
+
+The ``<name>`` of the group may contain backslashes to specify subgroups:
+
+.. code-block:: cmake
+
+ source_group(outer\\inner ...)
+
+For backwards compatibility, the short-hand signature
+
+.. code-block:: cmake
+
+ source_group(<name> <regex>)
+
+is equivalent to
+
+.. code-block:: cmake
+
+ source_group(<name> REGULAR_EXPRESSION <regex>)
diff --git a/Help/command/string.rst b/Help/command/string.rst
new file mode 100644
index 0000000000..07d0ff3f2e
--- /dev/null
+++ b/Help/command/string.rst
@@ -0,0 +1,173 @@
+string
+------
+
+String operations.
+
+::
+
+ string(REGEX MATCH <regular_expression>
+ <output variable> <input> [<input>...])
+ string(REGEX MATCHALL <regular_expression>
+ <output variable> <input> [<input>...])
+ string(REGEX REPLACE <regular_expression>
+ <replace_expression> <output variable>
+ <input> [<input>...])
+ string(REPLACE <match_string>
+ <replace_string> <output variable>
+ <input> [<input>...])
+ string(CONCAT <output variable> [<input>...])
+ string(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512>
+ <output variable> <input>)
+ string(COMPARE EQUAL <string1> <string2> <output variable>)
+ string(COMPARE NOTEQUAL <string1> <string2> <output variable>)
+ string(COMPARE LESS <string1> <string2> <output variable>)
+ string(COMPARE GREATER <string1> <string2> <output variable>)
+ string(ASCII <number> [<number> ...] <output variable>)
+ string(CONFIGURE <string1> <output variable>
+ [@ONLY] [ESCAPE_QUOTES])
+ string(TOUPPER <string1> <output variable>)
+ string(TOLOWER <string1> <output variable>)
+ string(LENGTH <string> <output variable>)
+ string(SUBSTRING <string> <begin> <length> <output variable>)
+ string(STRIP <string> <output variable>)
+ string(RANDOM [LENGTH <length>] [ALPHABET <alphabet>]
+ [RANDOM_SEED <seed>] <output variable>)
+ string(FIND <string> <substring> <output variable> [REVERSE])
+ string(TIMESTAMP <output variable> [<format string>] [UTC])
+ string(MAKE_C_IDENTIFIER <input string> <output variable>)
+ string(GENEX_STRIP <input string> <output variable>)
+ string(UUID <output variable> NAMESPACE <namespace> NAME <name>
+ TYPE <MD5|SHA1> [UPPER])
+
+REGEX MATCH will match the regular expression once and store the match
+in the output variable.
+
+REGEX MATCHALL will match the regular expression as many times as
+possible and store the matches in the output variable as a list.
+
+REGEX REPLACE will match the regular expression as many times as
+possible and substitute the replacement expression for the match in
+the output. The replace expression may refer to paren-delimited
+subexpressions of the match using \1, \2, ..., \9. Note that two
+backslashes (\\1) are required in CMake code to get a backslash
+through argument parsing.
+
+REPLACE will replace all occurrences of match_string in the input with
+replace_string and store the result in the output.
+
+CONCAT will concatenate all the input arguments together and store
+the result in the named output variable.
+
+MD5, SHA1, SHA224, SHA256, SHA384, and SHA512 will compute a
+cryptographic hash of the input string.
+
+COMPARE EQUAL/NOTEQUAL/LESS/GREATER will compare the strings and store
+true or false in the output variable.
+
+ASCII will convert all numbers into corresponding ASCII characters.
+
+CONFIGURE will transform a string like CONFIGURE_FILE transforms a
+file.
+
+TOUPPER/TOLOWER will convert string to upper/lower characters.
+
+LENGTH will return a given string's length.
+
+SUBSTRING will return a substring of a given string. If length is -1
+the remainder of the string starting at begin will be returned.
+
+STRIP will return a substring of a given string with leading and
+trailing spaces removed.
+
+RANDOM will return a random string of given length consisting of
+characters from the given alphabet. Default length is 5 characters
+and default alphabet is all numbers and upper and lower case letters.
+If an integer RANDOM_SEED is given, its value will be used to seed the
+random number generator.
+
+FIND will return the position where the given substring was found in
+the supplied string. If the REVERSE flag was used, the command will
+search for the position of the last occurrence of the specified
+substring.
+
+The following characters have special meaning in regular expressions:
+
+::
+
+ ^ Matches at beginning of input
+ $ Matches at end of input
+ . Matches any single character
+ [ ] Matches any character(s) inside the brackets
+ [^ ] Matches any character(s) not inside the brackets
+ - Inside brackets, specifies an inclusive range between
+ characters on either side e.g. [a-f] is [abcdef]
+ To match a literal - using brackets, make it the first
+ or the last character e.g. [+*/-] matches basic
+ mathematical operators.
+ * Matches preceding pattern zero or more times
+ + Matches preceding pattern one or more times
+ ? Matches preceding pattern zero or once only
+ | Matches a pattern on either side of the |
+ () Saves a matched subexpression, which can be referenced
+ in the REGEX REPLACE operation. Additionally it is saved
+ by all regular expression-related commands, including
+ e.g. if( MATCHES ), in the variables CMAKE_MATCH_(0..9).
+
+``*``, ``+`` and ``?`` have higher precedence than concatenation. | has lower
+precedence than concatenation. This means that the regular expression
+"^ab+d$" matches "abbd" but not "ababd", and the regular expression
+"^(ab|cd)$" matches "ab" but not "abd".
+
+TIMESTAMP will write a string representation of the current date
+and/or time to the output variable.
+
+Should the command be unable to obtain a timestamp the output variable
+will be set to the empty string "".
+
+The optional UTC flag requests the current date/time representation to
+be in Coordinated Universal Time (UTC) rather than local time.
+
+The optional <format string> may contain the following format
+specifiers:
+
+::
+
+ %d The day of the current month (01-31).
+ %H The hour on a 24-hour clock (00-23).
+ %I The hour on a 12-hour clock (01-12).
+ %j The day of the current year (001-366).
+ %m The month of the current year (01-12).
+ %M The minute of the current hour (00-59).
+ %S The second of the current minute.
+ 60 represents a leap second. (00-60)
+ %U The week number of the current year (00-53).
+ %w The day of the current week. 0 is Sunday. (0-6)
+ %y The last two digits of the current year (00-99)
+ %Y The current year.
+
+Unknown format specifiers will be ignored and copied to the output
+as-is.
+
+If no explicit <format string> is given it will default to:
+
+::
+
+ %Y-%m-%dT%H:%M:%S for local time.
+ %Y-%m-%dT%H:%M:%SZ for UTC.
+
+MAKE_C_IDENTIFIER will write a string which can be used as an
+identifier in C.
+
+``GENEX_STRIP`` will strip any
+:manual:`generator expressions <cmake-generator-expressions(7)>` from the
+``input string`` and store the result in the ``output variable``.
+
+UUID creates a univerally unique identifier (aka GUID) as per RFC4122
+based on the hash of the combined values of <namespace>
+(which itself has to be a valid UUID) and <name>.
+The hash algorithm can be either ``MD5`` (Version 3 UUID) or
+``SHA1`` (Version 5 UUID).
+A UUID has the format ``xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx``
+where each `x` represents a lower case hexadecimal character.
+Where required an uppercase representation can be requested
+with the optional ``UPPER`` flag.
diff --git a/Help/command/subdir_depends.rst b/Help/command/subdir_depends.rst
new file mode 100644
index 0000000000..5676c8f40b
--- /dev/null
+++ b/Help/command/subdir_depends.rst
@@ -0,0 +1,13 @@
+subdir_depends
+--------------
+
+Disallowed. See CMake Policy :policy:`CMP0029`.
+
+Does nothing.
+
+::
+
+ subdir_depends(subdir dep1 dep2 ...)
+
+Does not do anything. This command used to help projects order
+parallel builds correctly. This functionality is now automatic.
diff --git a/Help/command/subdirs.rst b/Help/command/subdirs.rst
new file mode 100644
index 0000000000..dee49f8e05
--- /dev/null
+++ b/Help/command/subdirs.rst
@@ -0,0 +1,24 @@
+subdirs
+-------
+
+Deprecated. Use the add_subdirectory() command instead.
+
+Add a list of subdirectories to the build.
+
+::
+
+ subdirs(dir1 dir2 ...[EXCLUDE_FROM_ALL exclude_dir1 exclude_dir2 ...]
+ [PREORDER] )
+
+Add a list of subdirectories to the build. The add_subdirectory
+command should be used instead of subdirs although subdirs will still
+work. This will cause any CMakeLists.txt files in the sub directories
+to be processed by CMake. Any directories after the PREORDER flag are
+traversed first by makefile builds, the PREORDER flag has no effect on
+IDE projects. Any directories after the EXCLUDE_FROM_ALL marker will
+not be included in the top level makefile or project file. This is
+useful for having CMake create makefiles or projects for a set of
+examples in a project. You would want CMake to generate makefiles or
+project files for all the examples at the same time, but you would not
+want them to show up in the top level project or be built each time
+make is run from the top.
diff --git a/Help/command/target_compile_definitions.rst b/Help/command/target_compile_definitions.rst
new file mode 100644
index 0000000000..3c9fe87585
--- /dev/null
+++ b/Help/command/target_compile_definitions.rst
@@ -0,0 +1,28 @@
+target_compile_definitions
+--------------------------
+
+Add compile definitions to a target.
+
+::
+
+ target_compile_definitions(<target>
+ <INTERFACE|PUBLIC|PRIVATE> [items1...]
+ [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
+
+Specify compile definitions to use when compiling a given <target. The
+named ``<target>`` must have been created by a command such as
+:command:`add_executable` or :command:`add_library` and must not be an
+:ref:`Imported Target <Imported Targets>`.
+
+The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
+specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
+items will populate the :prop_tgt:`COMPILE_DEFINITIONS` property of
+``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
+:prop_tgt:`INTERFACE_COMPILE_DEFINITIONS` property of ``<target>``. The
+following arguments specify compile definitions. Repeated calls for the
+same ``<target>`` append items in the order called.
+
+Arguments to ``target_compile_definitions`` 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/Help/command/target_compile_features.rst b/Help/command/target_compile_features.rst
new file mode 100644
index 0000000000..29a8b413cb
--- /dev/null
+++ b/Help/command/target_compile_features.rst
@@ -0,0 +1,32 @@
+target_compile_features
+-----------------------
+
+Add expected compiler features to a target.
+
+::
+
+ target_compile_features(<target> <PRIVATE|PUBLIC|INTERFACE> <feature> [...])
+
+Specify compiler features required when compiling a given target. If the
+feature is not listed in the :variable:`CMAKE_C_COMPILE_FEATURES` variable
+or :variable:`CMAKE_CXX_COMPILE_FEATURES` variable,
+then an error will be reported by CMake. If the use of the feature requires
+an additional compiler flag, such as ``-std=gnu++11``, the flag will be added
+automatically.
+
+The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
+specify the scope of the features. ``PRIVATE`` and ``PUBLIC`` items will
+populate the :prop_tgt:`COMPILE_FEATURES` property of ``<target>``.
+``PUBLIC`` and ``INTERFACE`` items will populate the
+:prop_tgt:`INTERFACE_COMPILE_FEATURES` property of ``<target>``. Repeated
+calls for the same ``<target>`` append items.
+
+The named ``<target>`` must have been created by a command such as
+:command:`add_executable` or :command:`add_library` and must not be
+an ``IMPORTED`` target.
+
+Arguments to ``target_compile_features`` may use "generator expressions"
+with the syntax ``$<...>``.
+See the :manual:`cmake-generator-expressions(7)` manual for available
+expressions. See the :manual:`cmake-compile-features(7)` manual for
+information on compile features.
diff --git a/Help/command/target_compile_options.rst b/Help/command/target_compile_options.rst
new file mode 100644
index 0000000000..0fdeba6000
--- /dev/null
+++ b/Help/command/target_compile_options.rst
@@ -0,0 +1,37 @@
+target_compile_options
+----------------------
+
+Add compile options to a target.
+
+::
+
+ target_compile_options(<target> [BEFORE]
+ <INTERFACE|PUBLIC|PRIVATE> [items1...]
+ [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
+
+Specify compile options to use when compiling a given target. The
+named ``<target>`` must have been created by a command such as
+:command:`add_executable` or :command:`add_library` and must not be an
+:prop_tgt:`IMPORTED Target`. If ``BEFORE`` is specified, the content will
+be prepended to the property instead of being appended.
+
+This command can be used to add any options, but
+alternative commands exist to add preprocessor definitions
+(:command:`target_compile_definitions` and :command:`add_definitions`) or
+include directories (:command:`target_include_directories` and
+:command:`include_directories`). See documentation of the
+:prop_tgt:`directory <COMPILE_OPTIONS>` and
+:prop_tgt:` target <COMPILE_OPTIONS>` ``COMPILE_OPTIONS`` properties.
+
+The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
+specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
+items will populate the :prop_tgt:`COMPILE_OPTIONS` property of
+``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
+:prop_tgt:`INTERFACE_COMPILE_OPTIONS` property of ``<target>``. The
+following arguments specify compile options. Repeated calls for the same
+``<target>`` append items in the order called.
+
+Arguments to ``target_compile_options`` 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/Help/command/target_include_directories.rst b/Help/command/target_include_directories.rst
new file mode 100644
index 0000000000..581bacef56
--- /dev/null
+++ b/Help/command/target_include_directories.rst
@@ -0,0 +1,56 @@
+target_include_directories
+--------------------------
+
+Add include directories to a target.
+
+::
+
+ target_include_directories(<target> [SYSTEM] [BEFORE]
+ <INTERFACE|PUBLIC|PRIVATE> [items1...]
+ [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
+
+Specify include directories or targets to use when compiling a given
+target. The named ``<target>`` must have been created by a command such
+as :command:`add_executable` or :command:`add_library` and must not be an
+:prop_tgt:`IMPORTED` target.
+
+If ``BEFORE`` is specified, the content will be prepended to the property
+instead of being appended.
+
+The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to specify
+the scope of the following arguments. ``PRIVATE`` and ``PUBLIC`` items will
+populate the :prop_tgt:`INCLUDE_DIRECTORIES` property of ``<target>``.
+``PUBLIC`` and ``INTERFACE`` items will populate the
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`
+property of ``<target>``. The following arguments specify include
+directories.
+
+Specified include directories may be absolute paths or relative paths.
+Repeated calls for the same <target> append items in the order called. If
+``SYSTEM`` is specified, the compiler will be told the
+directories are meant as system include directories on some platforms
+(signalling this setting might achieve effects such as the compiler
+skipping warnings, or these fixed-install system files not being
+considered in dependency calculations - see compiler docs). If ``SYSTEM``
+is used together with ``PUBLIC`` or ``INTERFACE``, the
+:prop_tgt:`INTERFACE_SYSTEM_INCLUDE_DIRECTORIES` target property will be
+populated with the specified directories.
+
+Arguments to ``target_include_directories`` 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.
+
+Include directories usage requirements commonly differ between the build-tree
+and the install-tree. The ``BUILD_INTERFACE`` and ``INSTALL_INTERFACE``
+generator expressions can be used to describe separate usage requirements
+based on the usage location. Relative paths are allowed within the
+``INSTALL_INTERFACE`` expression and are interpreted relative to the
+installation prefix. For example:
+
+.. code-block:: cmake
+
+ target_include_directories(mylib PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/mylib>
+ $<INSTALL_INTERFACE:include/mylib> # <prefix>/include/mylib
+ )
diff --git a/Help/command/target_link_libraries.rst b/Help/command/target_link_libraries.rst
new file mode 100644
index 0000000000..39537a7035
--- /dev/null
+++ b/Help/command/target_link_libraries.rst
@@ -0,0 +1,152 @@
+target_link_libraries
+---------------------
+
+Link a target to given libraries.
+
+::
+
+ target_link_libraries(<target> [item1 [item2 [...]]]
+ [[debug|optimized|general] <item>] ...)
+
+Specify libraries or flags to use when linking a given target. The
+named ``<target>`` must have been created in the current directory by a
+command such as :command:`add_executable` or :command:`add_library`. The
+remaining arguments specify library names or flags. Repeated calls for
+the same ``<target>`` append items in the order called.
+
+If a library name matches that of another target in the project a
+dependency will automatically be added in the build system to make sure
+the library being linked is up-to-date before the target links. Item names
+starting with ``-``, but not ``-l`` or ``-framework``, are treated as
+linker flags. Note that such flags will be treated like any other library
+link item for purposes of transitive dependencies, so they are generally
+safe to specify only as private link items that will not propagate to
+dependents of ``<target>``.
+
+A ``debug``, ``optimized``, or ``general`` keyword indicates that the
+library immediately following it is to be used only for the
+corresponding build configuration. The ``debug`` keyword corresponds to
+the Debug configuration (or to configurations named in the
+:prop_gbl:`DEBUG_CONFIGURATIONS` global property if it is set). The
+``optimized`` keyword corresponds to all other configurations. The
+``general`` keyword corresponds to all configurations, and is purely
+optional (assumed if omitted). Higher granularity may be achieved for
+per-configuration rules by creating and linking to
+:ref:`IMPORTED library targets <Imported Targets>`.
+
+Library dependencies are transitive by default with this signature.
+When this target is linked into another target then the libraries
+linked to this target will appear on the link line for the other
+target too. This transitive "link interface" is stored in the
+:prop_tgt:`INTERFACE_LINK_LIBRARIES` target property and may be overridden
+by setting the property directly. When :policy:`CMP0022` is not set to
+``NEW``, transitive linking is built in but may be overridden by the
+:prop_tgt:`LINK_INTERFACE_LIBRARIES` property. Calls to other signatures
+of this command may set the property making any libraries linked
+exclusively by this signature private.
+
+CMake will also propagate :ref:`usage requirements <Target Usage Requirements>`
+from linked library targets. Usage requirements of dependencies affect
+compilation of sources in the ``<target>``.
+
+If an ``<item>`` is a library in a Mac OX framework, the ``Headers``
+directory of the framework will also be processed as a
+:ref:`usage requirement <Target Usage Requirements>`. This has the same
+effect as passing the framework directory as an include directory.
+
+--------------------------------------------------------------------------
+
+::
+
+ target_link_libraries(<target>
+ <PRIVATE|PUBLIC|INTERFACE> <lib> ...
+ [<PRIVATE|PUBLIC|INTERFACE> <lib> ... ] ...])
+
+The ``PUBLIC``, ``PRIVATE`` and ``INTERFACE`` keywords can be used to
+specify both the link dependencies and the link interface in one command.
+Libraries and targets following ``PUBLIC`` are linked to, and are made
+part of the link interface. Libraries and targets following ``PRIVATE``
+are linked to, but are not made part of the link interface. Libraries
+following ``INTERFACE`` are appended to the link interface and are not
+used for linking ``<target>``.
+
+--------------------------------------------------------------------------
+
+::
+
+ target_link_libraries(<target> LINK_INTERFACE_LIBRARIES
+ [[debug|optimized|general] <lib>] ...)
+
+The ``LINK_INTERFACE_LIBRARIES`` mode appends the libraries to the
+:prop_tgt:`INTERFACE_LINK_LIBRARIES` target property instead of using them
+for linking. If policy :policy:`CMP0022` is not ``NEW``, then this mode
+also appends libraries to the :prop_tgt:`LINK_INTERFACE_LIBRARIES` and its
+per-configuration equivalent.
+
+This signature is for compatibility only. Prefer the ``INTERFACE`` mode
+instead.
+
+Libraries specified as ``debug`` are wrapped in a generator expression to
+correspond to debug builds. If policy :policy:`CMP0022` is
+not ``NEW``, the libraries are also appended to the
+:prop_tgt:`LINK_INTERFACE_LIBRARIES_DEBUG <LINK_INTERFACE_LIBRARIES_<CONFIG>>`
+property (or to the properties corresponding to configurations listed in
+the :prop_gbl:`DEBUG_CONFIGURATIONS` global property if it is set).
+Libraries specified as ``optimized`` are appended to the
+:prop_tgt:`INTERFACE_LINK_LIBRARIES` property. If policy :policy:`CMP0022`
+is not ``NEW``, they are also appended to the
+:prop_tgt:`LINK_INTERFACE_LIBRARIES` property. Libraries specified as
+``general`` (or without any keyword) are treated as if specified for both
+``debug`` and ``optimized``.
+
+--------------------------------------------------------------------------
+
+::
+
+ target_link_libraries(<target>
+ <LINK_PRIVATE|LINK_PUBLIC>
+ [[debug|optimized|general] <lib>] ...
+ [<LINK_PRIVATE|LINK_PUBLIC>
+ [[debug|optimized|general] <lib>] ...])
+
+The ``LINK_PUBLIC`` and ``LINK_PRIVATE`` modes can be used to specify both
+the link dependencies and the link interface in one command.
+
+This signature is for compatibility only. Prefer the ``PUBLIC`` or
+``PRIVATE`` keywords instead.
+
+Libraries and targets following ``LINK_PUBLIC`` are linked to, and are
+made part of the :prop_tgt:`INTERFACE_LINK_LIBRARIES`. If policy
+:policy:`CMP0022` is not ``NEW``, they are also made part of the
+:prop_tgt:`LINK_INTERFACE_LIBRARIES`. Libraries and targets following
+``LINK_PRIVATE`` are linked to, but are not made part of the
+:prop_tgt:`INTERFACE_LINK_LIBRARIES` (or :prop_tgt:`LINK_INTERFACE_LIBRARIES`).
+
+The library dependency graph is normally acyclic (a DAG), but in the case
+of mutually-dependent ``STATIC`` libraries CMake allows the graph to
+contain cycles (strongly connected components). When another target links
+to one of the libraries, CMake repeats the entire connected component.
+For example, the code
+
+.. code-block:: cmake
+
+ add_library(A STATIC a.c)
+ add_library(B STATIC b.c)
+ target_link_libraries(A B)
+ target_link_libraries(B A)
+ add_executable(main main.c)
+ target_link_libraries(main A)
+
+links ``main`` to ``A B A B``. While one repetition is usually
+sufficient, pathological object file and symbol arrangements can require
+more. One may handle such cases by manually repeating the component in
+the last ``target_link_libraries`` call. However, if two archives are
+really so interdependent they should probably be combined into a single
+archive.
+
+Arguments to target_link_libraries may use "generator expressions"
+with the syntax ``$<...>``. Note however, that generator expressions
+will not be used in OLD handling of :policy:`CMP0003` or :policy:`CMP0004`.
+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/Help/command/target_sources.rst b/Help/command/target_sources.rst
new file mode 100644
index 0000000000..ff756b4ff6
--- /dev/null
+++ b/Help/command/target_sources.rst
@@ -0,0 +1,28 @@
+target_sources
+--------------
+
+Add sources to a target.
+
+::
+
+ target_sources(<target>
+ <INTERFACE|PUBLIC|PRIVATE> [items1...]
+ [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
+
+Specify sources to use when compiling a given target. The
+named ``<target>`` must have been created by a command such as
+:command:`add_executable` or :command:`add_library` and must not be an
+:prop_tgt:`IMPORTED Target`.
+
+The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
+specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
+items will populate the :prop_tgt:`SOURCES` property of
+``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
+:prop_tgt:`INTERFACE_SOURCES` property of ``<target>``. The
+following arguments specify sources. Repeated calls for the same
+``<target>`` append items in the order called.
+
+Arguments to ``target_sources`` 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/Help/command/try_compile.rst b/Help/command/try_compile.rst
new file mode 100644
index 0000000000..224c67b45d
--- /dev/null
+++ b/Help/command/try_compile.rst
@@ -0,0 +1,72 @@
+try_compile
+-----------
+
+Try building some code.
+
+::
+
+ try_compile(RESULT_VAR <bindir> <srcdir>
+ <projectName> [targetName] [CMAKE_FLAGS flags...]
+ [OUTPUT_VARIABLE <var>])
+
+Try building a project. In this form, srcdir should contain a
+complete CMake project with a CMakeLists.txt file and all sources.
+The bindir and srcdir will not be deleted after this command is run.
+Specify targetName to build a specific target instead of the 'all' or
+'ALL_BUILD' target.
+
+::
+
+ try_compile(RESULT_VAR <bindir> <srcfile|SOURCES srcfile...>
+ [CMAKE_FLAGS flags...]
+ [COMPILE_DEFINITIONS flags...]
+ [LINK_LIBRARIES libs...]
+ [OUTPUT_VARIABLE <var>]
+ [COPY_FILE <fileName> [COPY_FILE_ERROR <var>]])
+
+Try building an executable from one or more source files. In this
+form the user need only supply one or more source files that include a
+definition for 'main'. CMake will create a CMakeLists.txt file to
+build the source(s) as an executable. Specify COPY_FILE to get a copy
+of the linked executable at the given fileName and optionally
+COPY_FILE_ERROR to capture any error.
+
+In this version all files in bindir/CMakeFiles/CMakeTmp will be
+cleaned automatically. For debugging, --debug-trycompile can be
+passed to cmake to avoid this clean. However, multiple sequential
+try_compile operations reuse this single output directory. If you use
+--debug-trycompile, you can only debug one try_compile call at a time.
+The recommended procedure is to protect all try_compile calls in your
+project by ``if(NOT DEFINED RESULT_VAR)`` logic, configure with cmake
+all the way through once, then delete the cache entry associated with
+the try_compile call of interest, and then re-run cmake again with
+--debug-trycompile.
+
+Some extra flags that can be included are, INCLUDE_DIRECTORIES,
+LINK_DIRECTORIES, and LINK_LIBRARIES. COMPILE_DEFINITIONS are
+-Ddefinition that will be passed to the compile line.
+
+The srcfile signature also accepts a LINK_LIBRARIES argument which may
+contain a list of libraries or IMPORTED targets which will be linked
+to in the generated project. If LINK_LIBRARIES is specified as a
+parameter to try_compile, then any LINK_LIBRARIES passed as
+CMAKE_FLAGS will be ignored.
+
+try_compile creates a CMakeList.txt file on the fly that looks like
+this:
+
+::
+
+ add_definitions( <expanded COMPILE_DEFINITIONS from calling cmake>)
+ include_directories(${INCLUDE_DIRECTORIES})
+ link_directories(${LINK_DIRECTORIES})
+ add_executable(cmTryCompileExec sources)
+ target_link_libraries(cmTryCompileExec ${LINK_LIBRARIES})
+
+In both versions of the command, if OUTPUT_VARIABLE is specified, then
+the output from the build process is stored in the given variable.
+The success or failure of the try_compile, i.e. TRUE or FALSE
+respectively, is returned in RESULT_VAR. CMAKE_FLAGS can be used to
+pass -DVAR:TYPE=VALUE flags to the cmake that is run during the build.
+Set variable CMAKE_TRY_COMPILE_CONFIGURATION to choose a build
+configuration.
diff --git a/Help/command/try_run.rst b/Help/command/try_run.rst
new file mode 100644
index 0000000000..9a17ad9660
--- /dev/null
+++ b/Help/command/try_run.rst
@@ -0,0 +1,52 @@
+try_run
+-------
+
+Try compiling and then running some code.
+
+::
+
+ try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
+ bindir srcfile [CMAKE_FLAGS <Flags>]
+ [COMPILE_DEFINITIONS <flags>]
+ [COMPILE_OUTPUT_VARIABLE comp]
+ [RUN_OUTPUT_VARIABLE run]
+ [OUTPUT_VARIABLE var]
+ [ARGS <arg1> <arg2>...])
+
+Try compiling a srcfile. Return TRUE or FALSE for success or failure
+in COMPILE_RESULT_VAR. Then if the compile succeeded, run the
+executable and return its exit code in RUN_RESULT_VAR. If the
+executable was built, but failed to run, then RUN_RESULT_VAR will be
+set to FAILED_TO_RUN. COMPILE_OUTPUT_VARIABLE specifies the variable
+where the output from the compile step goes. RUN_OUTPUT_VARIABLE
+specifies the variable where the output from the running executable
+goes.
+
+For compatibility reasons OUTPUT_VARIABLE is still supported, which
+gives you the output from the compile and run step combined.
+
+Cross compiling issues
+
+When cross compiling, the executable compiled in the first step
+usually cannot be run on the build host. try_run() checks the
+CMAKE_CROSSCOMPILING variable to detect whether CMake is in
+crosscompiling mode. If that's the case, it will still try to compile
+the executable, but it will not try to run the executable. Instead it
+will create cache variables which must be filled by the user or by
+presetting them in some CMake script file to the values the executable
+would have produced if it had been run on its actual target platform.
+These variables are RUN_RESULT_VAR (explanation see above) and if
+RUN_OUTPUT_VARIABLE (or OUTPUT_VARIABLE) was used, an additional cache
+variable RUN_RESULT_VAR__COMPILE_RESULT_VAR__TRYRUN_OUTPUT.This is
+intended to hold stdout and stderr from the executable.
+
+In order to make cross compiling your project easier, use try_run only
+if really required. If you use try_run, use RUN_OUTPUT_VARIABLE (or
+OUTPUT_VARIABLE) only if really required. Using them will require
+that when crosscompiling, the cache variables will have to be set
+manually to the output of the executable. You can also "guard" the
+calls to try_run with if(CMAKE_CROSSCOMPILING) and provide an
+easy-to-preset alternative for this case.
+
+Set variable CMAKE_TRY_COMPILE_CONFIGURATION to choose a build
+configuration.
diff --git a/Help/command/unset.rst b/Help/command/unset.rst
new file mode 100644
index 0000000000..d8f0dcdb27
--- /dev/null
+++ b/Help/command/unset.rst
@@ -0,0 +1,25 @@
+unset
+-----
+
+Unset a variable, cache variable, or environment variable.
+
+::
+
+ unset(<variable> [CACHE | PARENT_SCOPE])
+
+Removes the specified variable causing it to become undefined. If
+CACHE is present then the variable is removed from the cache instead
+of the current scope.
+
+If PARENT_SCOPE is present then the variable is removed from the scope
+above the current scope. See the same option in the set() command for
+further details.
+
+<variable> can be an environment variable such as:
+
+::
+
+ unset(ENV{LD_LIBRARY_PATH})
+
+in which case the variable will be removed from the current
+environment.
diff --git a/Help/command/use_mangled_mesa.rst b/Help/command/use_mangled_mesa.rst
new file mode 100644
index 0000000000..6f4d7aca64
--- /dev/null
+++ b/Help/command/use_mangled_mesa.rst
@@ -0,0 +1,15 @@
+use_mangled_mesa
+----------------
+
+Disallowed. See CMake Policy :policy:`CMP0030`.
+
+Copy mesa headers for use in combination with system GL.
+
+::
+
+ use_mangled_mesa(PATH_TO_MESA OUTPUT_DIRECTORY)
+
+The path to mesa includes, should contain gl_mangle.h. The mesa
+headers are copied to the specified output directory. This allows
+mangled mesa headers to override other GL headers by being added to
+the include directory path earlier.
diff --git a/Help/command/utility_source.rst b/Help/command/utility_source.rst
new file mode 100644
index 0000000000..5122e520ac
--- /dev/null
+++ b/Help/command/utility_source.rst
@@ -0,0 +1,24 @@
+utility_source
+--------------
+
+Disallowed. See CMake Policy :policy:`CMP0034`.
+
+Specify the source tree of a third-party utility.
+
+::
+
+ utility_source(cache_entry executable_name
+ path_to_source [file1 file2 ...])
+
+When a third-party utility's source is included in the distribution,
+this command specifies its location and name. The cache entry will
+not be set unless the path_to_source and all listed files exist. It
+is assumed that the source tree of the utility will have been built
+before it is needed.
+
+When cross compiling CMake will print a warning if a utility_source()
+command is executed, because in many cases it is used to build an
+executable which is executed later on. This doesn't work when cross
+compiling, since the executable can run only on their target platform.
+So in this case the cache entry has to be adjusted manually so it
+points to an executable which is runnable on the build host.
diff --git a/Help/command/variable_requires.rst b/Help/command/variable_requires.rst
new file mode 100644
index 0000000000..831dd0023c
--- /dev/null
+++ b/Help/command/variable_requires.rst
@@ -0,0 +1,22 @@
+variable_requires
+-----------------
+
+Disallowed. See CMake Policy :policy:`CMP0035`.
+
+Use the if() command instead.
+
+Assert satisfaction of an option's required variables.
+
+::
+
+ variable_requires(TEST_VARIABLE RESULT_VARIABLE
+ REQUIRED_VARIABLE1
+ REQUIRED_VARIABLE2 ...)
+
+The first argument (TEST_VARIABLE) is the name of the variable to be
+tested, if that variable is false nothing else is done. If
+TEST_VARIABLE is true, then the next argument (RESULT_VARIABLE) is a
+variable that is set to true if all the required variables are set.
+The rest of the arguments are variables that must be true or not set
+to NOTFOUND to avoid an error. If any are not true, an error is
+reported.
diff --git a/Help/command/variable_watch.rst b/Help/command/variable_watch.rst
new file mode 100644
index 0000000000..a2df058eb3
--- /dev/null
+++ b/Help/command/variable_watch.rst
@@ -0,0 +1,13 @@
+variable_watch
+--------------
+
+Watch the CMake variable for change.
+
+::
+
+ variable_watch(<variable name> [<command to execute>])
+
+If the specified variable changes, the message will be printed about
+the variable being changed. If the command is specified, the command
+will be executed. The command will receive the following arguments:
+COMMAND(<variable> <access> <value> <current list file> <stack>)
diff --git a/Help/command/while.rst b/Help/command/while.rst
new file mode 100644
index 0000000000..72c055de1d
--- /dev/null
+++ b/Help/command/while.rst
@@ -0,0 +1,17 @@
+while
+-----
+
+Evaluate a group of commands while a condition is true
+
+::
+
+ while(condition)
+ COMMAND1(ARGS ...)
+ COMMAND2(ARGS ...)
+ ...
+ endwhile(condition)
+
+All commands between while and the matching endwhile are recorded
+without being invoked. Once the endwhile is evaluated, the recorded
+list of commands is invoked as long as the condition is true. The
+condition is evaluated using the same logic as the if command.
diff --git a/Help/command/write_file.rst b/Help/command/write_file.rst
new file mode 100644
index 0000000000..015514bb3c
--- /dev/null
+++ b/Help/command/write_file.rst
@@ -0,0 +1,20 @@
+write_file
+----------
+
+Deprecated. Use the file(WRITE ) command instead.
+
+::
+
+ write_file(filename "message to write"... [APPEND])
+
+The first argument is the file name, the rest of the arguments are
+messages to write. If the argument APPEND is specified, then the
+message will be appended.
+
+NOTE 1: file(WRITE ... and file(APPEND ... do exactly the same as
+this one but add some more functionality.
+
+NOTE 2: When using write_file the produced file cannot be used as an
+input to CMake (CONFIGURE_FILE, source file ...) because it will lead
+to an infinite loop. Use configure_file if you want to generate input
+files to CMake.
diff --git a/Help/generator/Borland Makefiles.rst b/Help/generator/Borland Makefiles.rst
new file mode 100644
index 0000000000..c00d00a86b
--- /dev/null
+++ b/Help/generator/Borland Makefiles.rst
@@ -0,0 +1,4 @@
+Borland Makefiles
+-----------------
+
+Generates Borland makefiles.
diff --git a/Help/generator/CodeBlocks.rst b/Help/generator/CodeBlocks.rst
new file mode 100644
index 0000000000..01798c7f05
--- /dev/null
+++ b/Help/generator/CodeBlocks.rst
@@ -0,0 +1,25 @@
+CodeBlocks
+----------
+
+Generates CodeBlocks project files.
+
+Project files for CodeBlocks will be created in the top directory and
+in every subdirectory which features a CMakeLists.txt file containing
+a PROJECT() call. Additionally a hierarchy of makefiles is generated
+into the build tree. The appropriate make program can build the
+project through the default make target. A "make install" target is
+also provided.
+
+This "extra" generator may be specified as:
+
+``CodeBlocks - MinGW Makefiles``
+ Generate with :generator:`MinGW Makefiles`.
+
+``CodeBlocks - NMake Makefiles``
+ Generate with :generator:`NMake Makefiles`.
+
+``CodeBlocks - Ninja``
+ Generate with :generator:`Ninja`.
+
+``CodeBlocks - Unix Makefiles``
+ Generate with :generator:`Unix Makefiles`.
diff --git a/Help/generator/CodeLite.rst b/Help/generator/CodeLite.rst
new file mode 100644
index 0000000000..dbc46d72be
--- /dev/null
+++ b/Help/generator/CodeLite.rst
@@ -0,0 +1,24 @@
+CodeLite
+----------
+
+Generates CodeLite project files.
+
+Project files for CodeLite will be created in the top directory and
+in every subdirectory which features a CMakeLists.txt file containing
+a PROJECT() call. The appropriate make program can build the
+project through the default make target. A "make install" target is
+also provided.
+
+This "extra" generator may be specified as:
+
+``CodeLite - MinGW Makefiles``
+ Generate with :generator:`MinGW Makefiles`.
+
+``CodeLite - NMake Makefiles``
+ Generate with :generator:`NMake Makefiles`.
+
+``CodeLite - Ninja``
+ Generate with :generator:`Ninja`.
+
+``CodeLite - Unix Makefiles``
+ Generate with :generator:`Unix Makefiles`.
diff --git a/Help/generator/Eclipse CDT4.rst b/Help/generator/Eclipse CDT4.rst
new file mode 100644
index 0000000000..eb68bf0945
--- /dev/null
+++ b/Help/generator/Eclipse CDT4.rst
@@ -0,0 +1,25 @@
+Eclipse CDT4
+------------
+
+Generates Eclipse CDT 4.0 project files.
+
+Project files for Eclipse will be created in the top directory. In
+out of source builds, a linked resource to the top level source
+directory will be created. Additionally a hierarchy of makefiles is
+generated into the build tree. The appropriate make program can build
+the project through the default make target. A "make install" target
+is also provided.
+
+This "extra" generator may be specified as:
+
+``Eclipse CDT4 - MinGW Makefiles``
+ Generate with :generator:`MinGW Makefiles`.
+
+``Eclipse CDT4 - NMake Makefiles``
+ Generate with :generator:`NMake Makefiles`.
+
+``Eclipse CDT4 - Ninja``
+ Generate with :generator:`Ninja`.
+
+``Eclipse CDT4 - Unix Makefiles``
+ Generate with :generator:`Unix Makefiles`.
diff --git a/Help/generator/KDevelop3.rst b/Help/generator/KDevelop3.rst
new file mode 100644
index 0000000000..eaa218bc8e
--- /dev/null
+++ b/Help/generator/KDevelop3.rst
@@ -0,0 +1,25 @@
+KDevelop3
+---------
+
+Generates KDevelop 3 project files.
+
+Project files for KDevelop 3 will be created in the top directory and
+in every subdirectory which features a CMakeLists.txt file containing
+a PROJECT() call. If you change the settings using KDevelop cmake
+will try its best to keep your changes when regenerating the project
+files. Additionally a hierarchy of UNIX makefiles is generated into
+the build tree. Any standard UNIX-style make program can build the
+project through the default make target. A "make install" target is
+also provided.
+
+This "extra" generator may be specified as:
+
+``KDevelop3 - Unix Makefiles``
+ Generate with :generator:`Unix Makefiles`.
+
+``KDevelop3``
+ Generate with :generator:`Unix Makefiles`.
+
+ For historical reasons this extra generator may be specified
+ directly as the main generator and it will be used as the
+ extra generator with :generator:`Unix Makefiles` automatically.
diff --git a/Help/generator/Kate.rst b/Help/generator/Kate.rst
new file mode 100644
index 0000000000..9b61a93b32
--- /dev/null
+++ b/Help/generator/Kate.rst
@@ -0,0 +1,26 @@
+Kate
+----
+
+Generates Kate project files.
+
+A project file for Kate will be created in the top directory in the top level
+build directory.
+To use it in kate, the Project plugin must be enabled.
+The project file is loaded in kate simply by opening the
+ProjectName.kateproject file in the editor.
+If the kate Build-plugin is enabled, all targets generated by CMake are
+available for building.
+
+This "extra" generator may be specified as:
+
+``Kate - MinGW Makefiles``
+ Generate with :generator:`MinGW Makefiles`.
+
+``Kate - NMake Makefiles``
+ Generate with :generator:`NMake Makefiles`.
+
+``Kate - Ninja``
+ Generate with :generator:`Ninja`.
+
+``Kate - Unix Makefiles``
+ Generate with :generator:`Unix Makefiles`.
diff --git a/Help/generator/MSYS Makefiles.rst b/Help/generator/MSYS Makefiles.rst
new file mode 100644
index 0000000000..0b89126925
--- /dev/null
+++ b/Help/generator/MSYS Makefiles.rst
@@ -0,0 +1,7 @@
+MSYS Makefiles
+--------------
+
+Generates MSYS makefiles.
+
+The makefiles use /bin/sh as the shell. They require msys to be
+installed on the machine.
diff --git a/Help/generator/MinGW Makefiles.rst b/Help/generator/MinGW Makefiles.rst
new file mode 100644
index 0000000000..ed4ccdd0f0
--- /dev/null
+++ b/Help/generator/MinGW Makefiles.rst
@@ -0,0 +1,7 @@
+MinGW Makefiles
+---------------
+
+Generates a make file for use with mingw32-make.
+
+The makefiles generated use cmd.exe as the shell. They do not require
+msys or a unix shell.
diff --git a/Help/generator/NMake Makefiles JOM.rst b/Help/generator/NMake Makefiles JOM.rst
new file mode 100644
index 0000000000..3a8744c1e1
--- /dev/null
+++ b/Help/generator/NMake Makefiles JOM.rst
@@ -0,0 +1,4 @@
+NMake Makefiles JOM
+-------------------
+
+Generates JOM makefiles.
diff --git a/Help/generator/NMake Makefiles.rst b/Help/generator/NMake Makefiles.rst
new file mode 100644
index 0000000000..89f2479b76
--- /dev/null
+++ b/Help/generator/NMake Makefiles.rst
@@ -0,0 +1,4 @@
+NMake Makefiles
+---------------
+
+Generates NMake makefiles.
diff --git a/Help/generator/Ninja.rst b/Help/generator/Ninja.rst
new file mode 100644
index 0000000000..08f74fbfdd
--- /dev/null
+++ b/Help/generator/Ninja.rst
@@ -0,0 +1,8 @@
+Ninja
+-----
+
+Generates build.ninja files (experimental).
+
+A build.ninja file is generated into the build tree. Recent versions
+of the ninja program can build the project through the "all" target.
+An "install" target is also provided.
diff --git a/Help/generator/Sublime Text 2.rst b/Help/generator/Sublime Text 2.rst
new file mode 100644
index 0000000000..0597a9528f
--- /dev/null
+++ b/Help/generator/Sublime Text 2.rst
@@ -0,0 +1,25 @@
+Sublime Text 2
+--------------
+
+Generates Sublime Text 2 project files.
+
+Project files for Sublime Text 2 will be created in the top directory
+and in every subdirectory which features a CMakeLists.txt file
+containing a PROJECT() call. Additionally Makefiles (or build.ninja
+files) are generated into the build tree. The appropriate make
+program can build the project through the default make target. A
+"make install" target is also provided.
+
+This "extra" generator may be specified as:
+
+``Sublime Text 2 - MinGW Makefiles``
+ Generate with :generator:`MinGW Makefiles`.
+
+``Sublime Text 2 - NMake Makefiles``
+ Generate with :generator:`NMake Makefiles`.
+
+``Sublime Text 2 - Ninja``
+ Generate with :generator:`Ninja`.
+
+``Sublime Text 2 - Unix Makefiles``
+ Generate with :generator:`Unix Makefiles`.
diff --git a/Help/generator/Unix Makefiles.rst b/Help/generator/Unix Makefiles.rst
new file mode 100644
index 0000000000..97d74a853e
--- /dev/null
+++ b/Help/generator/Unix Makefiles.rst
@@ -0,0 +1,8 @@
+Unix Makefiles
+--------------
+
+Generates standard UNIX makefiles.
+
+A hierarchy of UNIX makefiles is generated into the build tree. Any
+standard UNIX-style make program can build the project through the
+default make target. A "make install" target is also provided.
diff --git a/Help/generator/Visual Studio 10 2010.rst b/Help/generator/Visual Studio 10 2010.rst
new file mode 100644
index 0000000000..77ea9df02b
--- /dev/null
+++ b/Help/generator/Visual Studio 10 2010.rst
@@ -0,0 +1,19 @@
+Visual Studio 10 2010
+---------------------
+
+Generates Visual Studio 10 (VS 2010) project files.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 10 2010 Win64``
+ Specify target platform ``x64``.
+
+``Visual Studio 10 2010 IA64``
+ Specify target platform ``Itanium``.
+
+For compatibility with CMake versions prior to 3.0, one may specify this
+generator using the name ``Visual Studio 10`` without the year component.
diff --git a/Help/generator/Visual Studio 11 2012.rst b/Help/generator/Visual Studio 11 2012.rst
new file mode 100644
index 0000000000..5fa7f2c76b
--- /dev/null
+++ b/Help/generator/Visual Studio 11 2012.rst
@@ -0,0 +1,22 @@
+Visual Studio 11 2012
+---------------------
+
+Generates Visual Studio 11 (VS 2012) project files.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 11 2012 Win64``
+ Specify target platform ``x64``.
+
+``Visual Studio 11 2012 ARM``
+ Specify target platform ``ARM``.
+
+``Visual Studio 11 2012 <WinCE-SDK>``
+ Specify target platform matching a Windows CE SDK name.
+
+For compatibility with CMake versions prior to 3.0, one may specify this
+generator using the name "Visual Studio 11" without the year component.
diff --git a/Help/generator/Visual Studio 12 2013.rst b/Help/generator/Visual Studio 12 2013.rst
new file mode 100644
index 0000000000..2c3b119a4c
--- /dev/null
+++ b/Help/generator/Visual Studio 12 2013.rst
@@ -0,0 +1,19 @@
+Visual Studio 12 2013
+---------------------
+
+Generates Visual Studio 12 (VS 2013) project files.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 12 2013 Win64``
+ Specify target platform ``x64``.
+
+``Visual Studio 12 2013 ARM``
+ Specify target platform ``ARM``.
+
+For compatibility with CMake versions prior to 3.0, one may specify this
+generator using the name "Visual Studio 12" without the year component.
diff --git a/Help/generator/Visual Studio 14.rst b/Help/generator/Visual Studio 14.rst
new file mode 100644
index 0000000000..d621b7e5ba
--- /dev/null
+++ b/Help/generator/Visual Studio 14.rst
@@ -0,0 +1,16 @@
+Visual Studio 14
+----------------
+
+Generates Visual Studio 14 project files.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 14 Win64``
+ Specify target platform ``x64``.
+
+``Visual Studio 14 ARM``
+ Specify target platform ``ARM``.
diff --git a/Help/generator/Visual Studio 6.rst b/Help/generator/Visual Studio 6.rst
new file mode 100644
index 0000000000..d619354661
--- /dev/null
+++ b/Help/generator/Visual Studio 6.rst
@@ -0,0 +1,4 @@
+Visual Studio 6
+---------------
+
+Generates Visual Studio 6 project files.
diff --git a/Help/generator/Visual Studio 7 .NET 2003.rst b/Help/generator/Visual Studio 7 .NET 2003.rst
new file mode 100644
index 0000000000..20341402bb
--- /dev/null
+++ b/Help/generator/Visual Studio 7 .NET 2003.rst
@@ -0,0 +1,4 @@
+Visual Studio 7 .NET 2003
+-------------------------
+
+Generates Visual Studio .NET 2003 project files.
diff --git a/Help/generator/Visual Studio 7.rst b/Help/generator/Visual Studio 7.rst
new file mode 100644
index 0000000000..d0eb719e55
--- /dev/null
+++ b/Help/generator/Visual Studio 7.rst
@@ -0,0 +1,4 @@
+Visual Studio 7
+---------------
+
+Generates Visual Studio .NET 2002 project files.
diff --git a/Help/generator/Visual Studio 8 2005.rst b/Help/generator/Visual Studio 8 2005.rst
new file mode 100644
index 0000000000..29012c3715
--- /dev/null
+++ b/Help/generator/Visual Studio 8 2005.rst
@@ -0,0 +1,16 @@
+Visual Studio 8 2005
+--------------------
+
+Generates Visual Studio 8 2005 project files.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 8 2005 Win64``
+ Specify target platform ``x64``.
+
+``Visual Studio 8 2005 <WinCE-SDK>``
+ Specify target platform matching a Windows CE SDK name.
diff --git a/Help/generator/Visual Studio 9 2008.rst b/Help/generator/Visual Studio 9 2008.rst
new file mode 100644
index 0000000000..40471b92e6
--- /dev/null
+++ b/Help/generator/Visual Studio 9 2008.rst
@@ -0,0 +1,19 @@
+Visual Studio 9 2008
+--------------------
+
+Generates Visual Studio 9 2008 project files.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 9 2008 Win64``
+ Specify target platform ``x64``.
+
+``Visual Studio 9 2008 IA64``
+ Specify target platform ``Itanium``.
+
+``Visual Studio 9 2008 <WinCE-SDK>``
+ Specify target platform matching a Windows CE SDK name.
diff --git a/Help/generator/Watcom WMake.rst b/Help/generator/Watcom WMake.rst
new file mode 100644
index 0000000000..09bdc3d9f6
--- /dev/null
+++ b/Help/generator/Watcom WMake.rst
@@ -0,0 +1,4 @@
+Watcom WMake
+------------
+
+Generates Watcom WMake makefiles.
diff --git a/Help/generator/Xcode.rst b/Help/generator/Xcode.rst
new file mode 100644
index 0000000000..d8a6790644
--- /dev/null
+++ b/Help/generator/Xcode.rst
@@ -0,0 +1,4 @@
+Xcode
+-----
+
+Generate Xcode project files.
diff --git a/Help/include/COMPILE_DEFINITIONS_DISCLAIMER.txt b/Help/include/COMPILE_DEFINITIONS_DISCLAIMER.txt
new file mode 100644
index 0000000000..6797d0e2bc
--- /dev/null
+++ b/Help/include/COMPILE_DEFINITIONS_DISCLAIMER.txt
@@ -0,0 +1,18 @@
+Disclaimer: Most native build tools have poor support for escaping
+certain values. CMake has work-arounds for many cases but some values
+may just not be possible to pass correctly. If a value does not seem
+to be escaped correctly, do not attempt to work-around the problem by
+adding escape sequences to the value. Your work-around may break in a
+future version of CMake that has improved escape support. Instead
+consider defining the macro in a (configured) header file. Then
+report the limitation. Known limitations include::
+
+ # - broken almost everywhere
+ ; - broken in VS IDE 7.0 and Borland Makefiles
+ , - broken in VS IDE
+ % - broken in some cases in NMake
+ & | - broken in some cases on MinGW
+ ^ < > \" - broken in most Make tools on Windows
+
+CMake does not reject these values outright because they do work in
+some cases. Use with caution.
diff --git a/Help/index.rst b/Help/index.rst
new file mode 100644
index 0000000000..2d3f15645a
--- /dev/null
+++ b/Help/index.rst
@@ -0,0 +1,59 @@
+.. title:: CMake Reference Documentation
+
+Command-Line Tools
+##################
+
+.. toctree::
+ :maxdepth: 1
+
+ /manual/cmake.1
+ /manual/ctest.1
+ /manual/cpack.1
+
+Interactive Dialogs
+###################
+
+.. toctree::
+ :maxdepth: 1
+
+ /manual/cmake-gui.1
+ /manual/ccmake.1
+
+Reference Manuals
+#################
+
+.. toctree::
+ :maxdepth: 1
+
+ /manual/cmake-buildsystem.7
+ /manual/cmake-commands.7
+ /manual/cmake-compile-features.7
+ /manual/cmake-developer.7
+ /manual/cmake-generator-expressions.7
+ /manual/cmake-generators.7
+ /manual/cmake-language.7
+ /manual/cmake-modules.7
+ /manual/cmake-packages.7
+ /manual/cmake-policies.7
+ /manual/cmake-properties.7
+ /manual/cmake-qt.7
+ /manual/cmake-toolchains.7
+ /manual/cmake-variables.7
+
+.. only:: html or text
+
+ Release Notes
+ #############
+
+ .. toctree::
+ :maxdepth: 1
+
+ /release/index
+
+.. only:: html
+
+ Index and Search
+ ################
+
+ * :ref:`genindex`
+ * :ref:`search`
diff --git a/Help/manual/LINKS.txt b/Help/manual/LINKS.txt
new file mode 100644
index 0000000000..f6f707df50
--- /dev/null
+++ b/Help/manual/LINKS.txt
@@ -0,0 +1,25 @@
+The following resources are available to get help using CMake:
+
+Home Page
+ http://www.cmake.org
+
+ The primary starting point for learning about CMake.
+
+Frequently Asked Questions
+ http://www.cmake.org/Wiki/CMake_FAQ
+
+ A Wiki is provided containing answers to frequently asked questions.
+
+Online Documentation
+ http://www.cmake.org/HTML/Documentation.html
+
+ Links to available documentation may be found on this web page.
+
+Mailing List
+ http://www.cmake.org/HTML/MailingLists.html
+
+ For help and discussion about using cmake, a mailing list is
+ provided at cmake@cmake.org. The list is member-post-only but one
+ may sign up on the CMake web page. Please first read the full
+ documentation at http://www.cmake.org before posting questions to
+ the list.
diff --git a/Help/manual/OPTIONS_BUILD.txt b/Help/manual/OPTIONS_BUILD.txt
new file mode 100644
index 0000000000..363d0aaca4
--- /dev/null
+++ b/Help/manual/OPTIONS_BUILD.txt
@@ -0,0 +1,75 @@
+``-C <initial-cache>``
+ Pre-load a script to populate the cache.
+
+ When cmake is first run in an empty build tree, it creates a
+ CMakeCache.txt file and populates it with customizable settings for
+ the project. This option may be used to specify a file from which
+ to load cache entries before the first pass through the project's
+ cmake listfiles. The loaded entries take priority over the
+ project's default values. The given file should be a CMake script
+ containing SET commands that use the CACHE option, not a
+ cache-format file.
+
+``-D <var>:<type>=<value>``
+ Create a cmake cache entry.
+
+ When cmake is first run in an empty build tree, it creates a
+ CMakeCache.txt file and populates it with customizable settings for
+ the project. This option may be used to specify a setting that
+ takes priority over the project's default value. The option may be
+ repeated for as many cache entries as desired.
+
+``-U <globbing_expr>``
+ Remove matching entries from CMake cache.
+
+ This option may be used to remove one or more variables from the
+ CMakeCache.txt file, globbing expressions using * and ? are
+ supported. The option may be repeated for as many cache entries as
+ desired.
+
+ Use with care, you can make your CMakeCache.txt non-working.
+
+``-G <generator-name>``
+ Specify a build system generator.
+
+ CMake may support multiple native build systems on certain
+ platforms. A generator is responsible for generating a particular
+ build system. Possible generator names are specified in the
+ Generators section.
+
+``-T <toolset-name>``
+ Specify toolset name if supported by generator.
+
+ Some CMake generators support a toolset name to be given to the
+ native build system to choose a compiler. This is supported only on
+ specific generators:
+
+ ::
+
+ Visual Studio >= 10
+ Xcode >= 3.0
+
+ See native build system documentation for allowed toolset names.
+
+``-A <platform-name>``
+ Specify platform name if supported by generator.
+
+ Some CMake generators support a platform name to be given to the
+ native build system to choose a compiler or SDK. This is supported only on
+ specific generators::
+
+ Visual Studio >= 8
+
+ See native build system documentation for allowed platform names.
+
+``-Wno-dev``
+ Suppress developer warnings.
+
+ Suppress warnings that are meant for the author of the
+ CMakeLists.txt files.
+
+``-Wdev``
+ Enable developer warnings.
+
+ Enable warnings that are meant for the author of the CMakeLists.txt
+ files.
diff --git a/Help/manual/OPTIONS_HELP.txt b/Help/manual/OPTIONS_HELP.txt
new file mode 100644
index 0000000000..feeca7dc36
--- /dev/null
+++ b/Help/manual/OPTIONS_HELP.txt
@@ -0,0 +1,136 @@
+.. |file| replace:: The help is printed to a named <f>ile if given.
+
+``--help,-help,-usage,-h,-H,/?``
+ Print usage information and exit.
+
+ Usage describes the basic command line interface and its options.
+
+``--version,-version,/V [<f>]``
+ Show program name/version banner and exit.
+
+ If a file is specified, the version is written into it.
+ |file|
+
+``--help-full [<f>]``
+ Print all help manuals and exit.
+
+ All manuals are printed in a human-readable text format.
+ |file|
+
+``--help-manual <man> [<f>]``
+ Print one help manual and exit.
+
+ The specified manual is printed in a human-readable text format.
+ |file|
+
+``--help-manual-list [<f>]``
+ List help manuals available and exit.
+
+ The list contains all manuals for which help may be obtained by
+ using the ``--help-manual`` option followed by a manual name.
+ |file|
+
+``--help-command <cmd> [<f>]``
+ Print help for one command and exit.
+
+ The :manual:`cmake-commands(7)` manual entry for ``<cmd>`` is
+ printed in a human-readable text format.
+ |file|
+
+``--help-command-list [<f>]``
+ List commands with help available and exit.
+
+ The list contains all commands for which help may be obtained by
+ using the ``--help-command`` option followed by a command name.
+ |file|
+
+``--help-commands [<f>]``
+ Print cmake-commands manual and exit.
+
+ The :manual:`cmake-commands(7)` manual is printed in a
+ human-readable text format.
+ |file|
+
+``--help-module <mod> [<f>]``
+ Print help for one module and exit.
+
+ The :manual:`cmake-modules(7)` manual entry for ``<mod>`` is printed
+ in a human-readable text format.
+ |file|
+
+``--help-module-list [<f>]``
+ List modules with help available and exit.
+
+ The list contains all modules for which help may be obtained by
+ using the ``--help-module`` option followed by a module name.
+ |file|
+
+``--help-modules [<f>]``
+ Print cmake-modules manual and exit.
+
+ The :manual:`cmake-modules(7)` manual is printed in a human-readable
+ text format.
+ |file|
+
+``--help-policy <cmp> [<f>]``
+ Print help for one policy and exit.
+
+ The :manual:`cmake-policies(7)` manual entry for ``<cmp>`` is
+ printed in a human-readable text format.
+ |file|
+
+``--help-policy-list [<f>]``
+ List policies with help available and exit.
+
+ The list contains all policies for which help may be obtained by
+ using the ``--help-policy`` option followed by a policy name.
+ |file|
+
+``--help-policies [<f>]``
+ Print cmake-policies manual and exit.
+
+ The :manual:`cmake-policies(7)` manual is printed in a
+ human-readable text format.
+ |file|
+
+``--help-property <prop> [<f>]``
+ Print help for one property and exit.
+
+ The :manual:`cmake-properties(7)` manual entries for ``<prop>`` are
+ printed in a human-readable text format.
+ |file|
+
+``--help-property-list [<f>]``
+ List properties with help available and exit.
+
+ The list contains all properties for which help may be obtained by
+ using the ``--help-property`` option followed by a property name.
+ |file|
+
+``--help-properties [<f>]``
+ Print cmake-properties manual and exit.
+
+ The :manual:`cmake-properties(7)` manual is printed in a
+ human-readable text format.
+ |file|
+
+``--help-variable <var> [<f>]``
+ Print help for one variable and exit.
+
+ The :manual:`cmake-variables(7)` manual entry for ``<var>`` is
+ printed in a human-readable text format.
+ |file|
+
+``--help-variable-list [<f>]``
+ List variables with help available and exit.
+
+ The list contains all variables for which help may be obtained by
+ using the ``--help-variable`` option followed by a variable name.
+ |file|
+
+``--help-variables [<f>]``
+ Print cmake-variables manual and exit.
+
+ The :manual:`cmake-variables(7)` manual is printed in a
+ human-readable text format.
+ |file|
diff --git a/Help/manual/ccmake.1.rst b/Help/manual/ccmake.1.rst
new file mode 100644
index 0000000000..a5fe191683
--- /dev/null
+++ b/Help/manual/ccmake.1.rst
@@ -0,0 +1,37 @@
+.. cmake-manual-description: CMake Curses Dialog Command-Line Reference
+
+ccmake(1)
+*********
+
+Synopsis
+========
+
+.. parsed-literal::
+
+ ccmake [<options>] (<path-to-source> | <path-to-existing-build>)
+
+Description
+===========
+
+The "ccmake" executable is the CMake curses interface. Project
+configuration settings may be specified interactively through this
+GUI. Brief instructions are provided at the bottom of the terminal
+when the program is running.
+
+CMake is a cross-platform build system generator. Projects specify
+their build process with platform-independent CMake listfiles included
+in each directory of a source tree with the name CMakeLists.txt.
+Users build a project by using CMake to generate a build system for a
+native tool on their platform.
+
+Options
+=======
+
+.. include:: OPTIONS_BUILD.txt
+
+.. include:: OPTIONS_HELP.txt
+
+See Also
+========
+
+.. include:: LINKS.txt
diff --git a/Help/manual/cmake-buildsystem.7.rst b/Help/manual/cmake-buildsystem.7.rst
new file mode 100644
index 0000000000..1ce9a7ee69
--- /dev/null
+++ b/Help/manual/cmake-buildsystem.7.rst
@@ -0,0 +1,889 @@
+.. cmake-manual-description: CMake Buildsystem Reference
+
+cmake-buildsystem(7)
+********************
+
+.. only:: html or latex
+
+ .. contents::
+
+Introduction
+============
+
+A CMake-based buildsystem is organized as a set of high-level logical
+targets. Each target corresponds to an executable or library, or
+is a custom target containing custom commands. Dependencies between the
+targets are expressed in the buildsystem to determine the build order
+and the rules for regeneration in response to change.
+
+Binary Targets
+==============
+
+Executables and libraries are defined using the :command:`add_executable`
+and :command:`add_library` commands. The resulting binary files have
+appropriate prefixes, suffixes and extensions for the platform targeted.
+Dependencies between binary targets are expressed using the
+:command:`target_link_libraries` command:
+
+.. code-block:: cmake
+
+ add_library(archive archive.cpp zip.cpp lzma.cpp)
+ add_executable(zipapp zipapp.cpp)
+ target_link_libraries(zipapp archive)
+
+``archive`` is defined as a static library -- an archive containing objects
+compiled from ``archive.cpp``, ``zip.cpp``, and ``lzma.cpp``. ``zipapp``
+is defined as an executable formed by compiling and linking ``zipapp.cpp``.
+When linking the ``zipapp`` executable, the ``archive`` static library is
+linked in.
+
+Binary Executables
+------------------
+
+The :command:`add_executable` command defines an executable target:
+
+.. code-block:: cmake
+
+ add_executable(mytool mytool.cpp)
+
+Commands such as :command:`add_custom_command`, which generates rules to be
+run at build time can transparently use an :prop_tgt:`EXECUTABLE <TYPE>`
+target as a ``COMMAND`` executable. The buildsystem rules will ensure that
+the executable is built before attempting to run the command.
+
+Binary Library Types
+--------------------
+
+.. _`Normal Libraries`:
+
+Normal Libraries
+^^^^^^^^^^^^^^^^
+
+By default, the :command:`add_library` command defines a static library,
+unless a type is specified. A type may be specified when using the command:
+
+.. code-block:: cmake
+
+ add_library(archive SHARED archive.cpp zip.cpp lzma.cpp)
+
+.. code-block:: cmake
+
+ add_library(archive STATIC archive.cpp zip.cpp lzma.cpp)
+
+The :variable:`BUILD_SHARED_LIBS` variable may be enabled to change the
+behavior of :command:`add_library` to build shared libraries by default.
+
+In the context of the buildsystem definition as a whole, it is largely
+irrelevant whether particular libraries are ``SHARED`` or ``STATIC`` --
+the commands, dependency specifications and other APIs work similarly
+regardless of the library type. The ``MODULE`` library type is
+dissimilar in that it is generally not linked to -- it is not used in
+the right-hand-side of the :command:`target_link_libraries` command.
+It is a type which is loaded as a plugin using runtime techniques.
+
+.. code-block:: cmake
+
+ add_library(archive MODULE 7z.cpp)
+
+.. _`Object Libraries`:
+
+Object Libraries
+^^^^^^^^^^^^^^^^
+
+The ``OBJECT`` library type is also not linked to. It defines a non-archival
+collection of object files resulting from compiling the given source files.
+The object files collection can be used as source inputs to other targets:
+
+.. code-block:: cmake
+
+ add_library(archive OBJECT archive.cpp zip.cpp lzma.cpp)
+
+ add_library(archiveExtras STATIC $<TARGET_OBJECTS:archive> extras.cpp)
+
+ add_executable(test_exe $<TARGET_OBJECTS:archive> test.cpp)
+
+``OBJECT`` libraries may only be used locally as sources in a buildsystem --
+they may not be installed, exported, or used in the right hand side of
+:command:`target_link_libraries`. They also may not be used as the ``TARGET``
+in a use of the :command:`add_custom_command(TARGET)` command signature.
+
+Although object libraries may not be named directly in calls to
+the :command:`target_link_libraries` command, they can be "linked"
+indirectly by using an :ref:`Interface Library <Interface Libraries>`
+whose :prop_tgt:`INTERFACE_SOURCES` target property is set to name
+``$<TARGET_OBJECTS:objlib>``.
+
+Build Specification and Usage Requirements
+==========================================
+
+The :command:`target_include_directories`, :command:`target_compile_definitions`
+and :command:`target_compile_options` commands specify the build specifications
+and the usage requirements of binary targets. The commands populate the
+:prop_tgt:`INCLUDE_DIRECTORIES`, :prop_tgt:`COMPILE_DEFINITIONS` and
+:prop_tgt:`COMPILE_OPTIONS` target properties respectively, and/or the
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`, :prop_tgt:`INTERFACE_COMPILE_DEFINITIONS`
+and :prop_tgt:`INTERFACE_COMPILE_OPTIONS` target properties.
+
+Each of the commands has a ``PRIVATE``, ``PUBLIC`` and ``INTERFACE`` mode. The
+``PRIVATE`` mode populates only the non-``INTERFACE_`` variant of the target
+property and the ``INTERFACE`` mode populates only the ``INTERFACE_`` variants.
+The ``PUBLIC`` mode populates both variants of the repective target property.
+Each command may be invoked with multiple uses of each keyword:
+
+.. code-block:: cmake
+
+ target_compile_definitions(archive
+ PRIVATE BUILDING_WITH_LZMA
+ INTERFACE USING_ARCHIVE_LIB
+ )
+
+Note that usage requirements are not designed as a way to make downstreams
+use particular :prop_tgt:`COMPILE_OPTIONS` or
+:prop_tgt:`COMPILE_DEFINITIONS` etc for convenience only. The contents of
+the properties must be **requirements**, not merely recommendations or
+convenience.
+
+Target Properties
+-----------------
+
+The contents of the :prop_tgt:`INCLUDE_DIRECTORIES`,
+:prop_tgt:`COMPILE_DEFINITIONS` and :prop_tgt:`COMPILE_OPTIONS` target
+properties are used appropriately when compiling the source files of a
+binary target.
+
+Entries in the :prop_tgt:`INCLUDE_DIRECTORIES` are added to the compile line
+with ``-I`` or ``-isystem`` prefixes and in the order of appearance in the
+property value.
+
+Entries in the :prop_tgt:`COMPILE_DEFINITIONS` are prefixed with ``-D`` or
+``/D`` and added to the compile line in an unspecified order. The
+:prop_tgt:`DEFINE_SYMBOL` target property is also added as a compile
+definition as a special convenience case for ``SHARED`` and ``MODULE``
+library targets.
+
+Entries in the :prop_tgt:`COMPILE_OPTIONS` are escaped for the shell and added
+in the order of appearance in the property value. Several compile options have
+special separate handling, such as :prop_tgt:`POSITION_INDEPENDENT_CODE`.
+
+The contents of the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`,
+:prop_tgt:`INTERFACE_COMPILE_DEFINITIONS` and
+:prop_tgt:`INTERFACE_COMPILE_OPTIONS` target properties are
+*Usage Requirements* -- they specify content which consumers
+must use to correctly compile and link with the target they appear on.
+For any binary target, the contents of each ``INTERFACE_`` property on
+each target specified in a :command:`target_link_libraries` command is
+consumed:
+
+.. code-block:: cmake
+
+ set(srcs archive.cpp zip.cpp)
+ if (LZMA_FOUND)
+ list(APPEND srcs lzma.cpp)
+ endif()
+ add_library(archive SHARED ${srcs})
+ if (LZMA_FOUND)
+ # The archive library sources are compiled with -DBUILDING_WITH_LZMA
+ target_compile_definitions(archive PRIVATE BUILDING_WITH_LZMA)
+ endif()
+ target_compile_definitions(archive INTERFACE USING_ARCHIVE_LIB)
+
+ add_executable(consumer)
+ # Link consumer to archive and consume its usage requirements. The consumer
+ # executable sources are compiled with -DUSING_ARCHIVE_LIB.
+ target_link_libraries(consumer archive)
+
+Because it is common to require that the source directory and corresponding
+build directory are added to the :prop_tgt:`INCLUDE_DIRECTORIES`, the
+:variable:`CMAKE_INCLUDE_CURRENT_DIR` variable can be enabled to conveniently
+add the corresponding directories to the :prop_tgt:`INCLUDE_DIRECTORIES` of
+all targets. The variable :variable:`CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE`
+can be enabled to add the corresponding directories to the
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of all targets. This makes use of
+targets in multiple different directories convenient through use of the
+:command:`target_link_libraries` command.
+
+
+.. _`Target Usage Requirements`:
+
+Transitive Usage Requirements
+-----------------------------
+
+The usage requirements of a target can transitively propagate to dependents.
+The :command:`target_link_libraries` command has ``PRIVATE``,
+``INTERFACE`` and ``PUBLIC`` keywords to control the propagation.
+
+.. code-block:: cmake
+
+ add_library(archive archive.cpp)
+ target_compile_definitions(archive INTERFACE USING_ARCHIVE_LIB)
+
+ add_library(serialization serialization.cpp)
+ target_compile_definitions(serialization INTERFACE USING_SERIALIZATION_LIB)
+
+ add_library(archiveExtras extras.cpp)
+ target_link_libraries(archiveExtras PUBLIC archive)
+ target_link_libraries(archiveExtras PRIVATE serialization)
+ # archiveExtras is compiled with -DUSING_ARCHIVE_LIB
+ # and -DUSING_SERIALIZATION_LIB
+
+ add_executable(consumer consumer.cpp)
+ # consumer is compiled with -DUSING_ARCHIVE_LIB
+ target_link_libraries(consumer archiveExtras)
+
+Because ``archive`` is a ``PUBLIC`` dependency of ``archiveExtras``, the
+usage requirements of it are propagated to ``consumer`` too. Because
+``serialization`` is a ``PRIVATE`` dependency of ``archive``, the usage
+requirements of it are not propagated to ``consumer``.
+
+Generally, a dependency should be specified in a use of
+:command:`target_link_libraries` with the ``PRIVATE`` keyword if it is used by
+only the implementation of a library, and not in the header files. If a
+dependency is additionally used in the header files of a library (e.g. for
+class inheritance), then it should be specified as a ``PUBLIC`` dependency.
+A dependency which is not used by the implementation of a library, but only by
+its headers should be specified as an ``INTERFACE`` dependency. The
+:command:`target_link_libraries` command may be invoked with multiple uses of
+each keyword:
+
+.. code-block:: cmake
+
+ target_link_libraries(archiveExtras
+ PUBLIC archive
+ PRIVATE serialization
+ )
+
+Usage requirements are propagated by reading the ``INTERFACE_`` variants
+of target properties from dependencies and appending the values to the
+non-``INTERFACE_`` variants of the operand. For example, the
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of dependencies is read and
+appended to the :prop_tgt:`INCLUDE_DIRECTORIES` of the operand. In cases
+where order is relevant and maintained, and the order resulting from the
+:command:`target_link_libraries` calls does not allow correct compilation,
+use of an appropriate command to set the property directly may update the
+order.
+
+For example, if the linked libraries for a target must be specified
+in the order ``lib1`` ``lib2`` ``lib3`` , but the include directories must
+be specified in the order ``lib3`` ``lib1`` ``lib2``:
+
+.. code-block:: cmake
+
+ target_link_libraries(myExe lib1 lib2 lib3)
+ target_include_directories(myExe
+ PRIVATE $<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES:lib3>)
+
+.. _`Compatible Interface Properties`:
+
+Compatible Interface Properties
+-------------------------------
+
+Some target properties are required to be compatible between a target and
+the interface of each dependency. For example, the
+:prop_tgt:`POSITION_INDEPENDENT_CODE` target property may specify a
+boolean value of whether a target should be compiled as
+position-independent-code, which has platform-specific consequences.
+A target may also specify the usage requirement
+:prop_tgt:`INTERFACE_POSITION_INDEPENDENT_CODE` to communicate that
+consumers must be compiled as position-independent-code.
+
+.. code-block:: cmake
+
+ add_executable(exe1 exe1.cpp)
+ set_property(TARGET exe1 PROPERTY POSITION_INDEPENDENT_CODE ON)
+
+ add_library(lib1 SHARED lib1.cpp)
+ set_property(TARGET lib1 PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+ add_executable(exe2 exe2.cpp)
+ target_link_libraries(exe2 lib1)
+
+Here, both ``exe1`` and ``exe2`` will be compiled as position-independent-code.
+``lib1`` will also be compiled as position-independent-code because that is the
+default setting for ``SHARED`` libraries. If dependencies have conflicting,
+non-compatible requirements :manual:`cmake(1)` issues a diagnostic:
+
+.. code-block:: cmake
+
+ add_library(lib1 SHARED lib1.cpp)
+ set_property(TARGET lib1 PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+ add_library(lib2 SHARED lib2.cpp)
+ set_property(TARGET lib2 PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE OFF)
+
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 lib1)
+ set_property(TARGET exe1 PROPERTY POSITION_INDEPENDENT_CODE OFF)
+
+ add_executable(exe2 exe2.cpp)
+ target_link_libraries(exe2 lib1 lib2)
+
+The ``lib1`` requirement ``INTERFACE_POSITION_INDEPENDENT_CODE`` is not
+"compatible" with the ``POSITION_INDEPENDENT_CODE`` property of the ``exe1``
+target. The library requires that consumers are built as
+position-independent-code, while the executable specifies to not built as
+position-independent-code, so a diagnostic is issued.
+
+The ``lib1`` and ``lib2`` requirements are not "compatible". One of them
+requires that consumers are built as position-independent-code, while
+the other requires that consumers are not built as position-independent-code.
+Because ``exe2`` links to both and they are in conflict, a diagnostic is
+issued.
+
+To be "compatible", the :prop_tgt:`POSITION_INDEPENDENT_CODE` property,
+if set must be either the same, in a boolean sense, as the
+:prop_tgt:`INTERFACE_POSITION_INDEPENDENT_CODE` property of all transitively
+specified dependencies on which that property is set.
+
+This property of "compatible interface requirement" may be extended to other
+properties by specifying the property in the content of the
+:prop_tgt:`COMPATIBLE_INTERFACE_BOOL` target property. Each specified property
+must be compatible between the consuming target and the corresponding property
+with an ``INTERFACE_`` prefix from each dependency:
+
+.. code-block:: cmake
+
+ add_library(lib1Version2 SHARED lib1_v2.cpp)
+ set_property(TARGET lib1Version2 PROPERTY INTERFACE_CUSTOM_PROP ON)
+ set_property(TARGET lib1Version2 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_BOOL CUSTOM_PROP
+ )
+
+ add_library(lib1Version3 SHARED lib1_v3.cpp)
+ set_property(TARGET lib1Version3 PROPERTY INTERFACE_CUSTOM_PROP OFF)
+
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 lib1Version2) # CUSTOM_PROP will be ON
+
+ add_executable(exe2 exe2.cpp)
+ target_link_libraries(exe2 lib1Version2 lib1Version3) # Diagnostic
+
+Non-boolean properties may also participate in "compatible interface"
+computations. Properties specified in the
+:prop_tgt:`COMPATIBLE_INTERFACE_STRING`
+property must be either unspecified or compare to the same string among
+all transitively specified dependencies. This can be useful to ensure
+that multiple incompatible versions of a library are not linked together
+through transitive requirements of a target:
+
+.. code-block:: cmake
+
+ add_library(lib1Version2 SHARED lib1_v2.cpp)
+ set_property(TARGET lib1Version2 PROPERTY INTERFACE_LIB_VERSION 2)
+ set_property(TARGET lib1Version2 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_STRING LIB_VERSION
+ )
+
+ add_library(lib1Version3 SHARED lib1_v3.cpp)
+ set_property(TARGET lib1Version3 PROPERTY INTERFACE_LIB_VERSION 3)
+
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 lib1Version2) # LIB_VERSION will be "2"
+
+ add_executable(exe2 exe2.cpp)
+ target_link_libraries(exe2 lib1Version2 lib1Version3) # Diagnostic
+
+The :prop_tgt:`COMPATIBLE_INTERFACE_NUMBER_MAX` target property specifies
+that content will be evaluated numerically and the maximum number among all
+specified will be calculated:
+
+.. code-block:: cmake
+
+ add_library(lib1Version2 SHARED lib1_v2.cpp)
+ set_property(TARGET lib1Version2 PROPERTY INTERFACE_CONTAINER_SIZE_REQUIRED 200)
+ set_property(TARGET lib1Version2 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_NUMBER_MAX CONTAINER_SIZE_REQUIRED
+ )
+
+ add_library(lib1Version3 SHARED lib1_v3.cpp)
+ set_property(TARGET lib1Version2 PROPERTY INTERFACE_CONTAINER_SIZE_REQUIRED 1000)
+
+ add_executable(exe1 exe1.cpp)
+ # CONTAINER_SIZE_REQUIRED will be "200"
+ target_link_libraries(exe1 lib1Version2)
+
+ add_executable(exe2 exe2.cpp)
+ # CONTAINER_SIZE_REQUIRED will be "1000"
+ target_link_libraries(exe2 lib1Version2 lib1Version3)
+
+Similarly, the :prop_tgt:`COMPATIBLE_INTERFACE_NUMBER_MIN` may be used to
+calculate the numeric minimum value for a property from dependencies.
+
+Each calculated "compatible" property value may be read in the consumer at
+generate-time using generator expressions.
+
+Note that for each dependee, the set of properties specified in each
+compatible interface property must not intersect with the set specified in
+any of the other properties.
+
+Property Origin Debugging
+-------------------------
+
+Because build specifications can be determined by dependencies, the lack of
+locality of code which creates a target and code which is responsible for
+setting build specifications may make the code more difficult to reason about.
+:manual:`cmake(1)` provides a debugging facility to print the origin of the
+contents of properties which may be determined by dependencies. The properties
+which can be debugged are listed in the
+:variable:`CMAKE_DEBUG_TARGET_PROPERTIES` variable documentation:
+
+.. code-block:: cmake
+
+ set(CMAKE_DEBUG_TARGET_PROPERTIES
+ INCLUDE_DIRECTORIES
+ COMPILE_DEFINITIONS
+ POSITION_INDEPENDENT_CODE
+ CONTAINER_SIZE_REQUIRED
+ LIB_VERSION
+ )
+ add_executable(exe1 exe1.cpp)
+
+In the case of properties listed in :prop_tgt:`COMPATIBLE_INTERFACE_BOOL` or
+:prop_tgt:`COMPATIBLE_INTERFACE_STRING`, the debug output shows which target
+was responsible for setting the property, and which other dependencies also
+defined the property. In the case of
+:prop_tgt:`COMPATIBLE_INTERFACE_NUMBER_MAX` and
+:prop_tgt:`COMPATIBLE_INTERFACE_NUMBER_MIN`, the debug output shows the
+value of the property from each dependency, and whether the value determines
+the new extreme.
+
+Build Specification with Generator Expressions
+----------------------------------------------
+
+Build specifications may use
+:manual:`generator expressions <cmake-generator-expressions(7)>` containing
+content which may be conditional or known only at generate-time. For example,
+the calculated "compatible" value of a property may be read with the
+``TARGET_PROPERTY`` expression:
+
+.. code-block:: cmake
+
+ add_library(lib1Version2 SHARED lib1_v2.cpp)
+ set_property(TARGET lib1Version2 PROPERTY
+ INTERFACE_CONTAINER_SIZE_REQUIRED 200)
+ set_property(TARGET lib1Version2 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_NUMBER_MAX CONTAINER_SIZE_REQUIRED
+ )
+
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 lib1Version2)
+ target_compile_definitions(exe1 PRIVATE
+ CONTAINER_SIZE=$<TARGET_PROPERTY:CONTAINER_SIZE_REQUIRED>
+ )
+
+In this case, the ``exe1`` source files will be compiled with
+``-DCONTAINER_SIZE=200``.
+
+Configuration determined build specifications may be conveniently set using
+the ``CONFIG`` generator expression.
+
+.. code-block:: cmake
+
+ target_compile_definitions(exe1 PRIVATE
+ $<$<CONFIG:Debug>:DEBUG_BUILD>
+ )
+
+The ``CONFIG`` parameter is compared case-insensitively with the configuration
+being built. In the presence of :prop_tgt:`IMPORTED` targets, the content of
+:prop_tgt:`MAP_IMPORTED_CONFIG_DEBUG <MAP_IMPORTED_CONFIG_<CONFIG>>` is also
+accounted for by this expression.
+
+Some buildsystems generated by :manual:`cmake(1)` have a predetermined
+build-configuration set in the :variable:`CMAKE_BUILD_TYPE` variable. The
+buildsystem for the IDEs such as Visual Studio and Xcode are generated
+independent of the build-configuration, and the actual build configuration
+is not known until build-time. Therefore, code such as
+
+.. code-block:: cmake
+
+ string(TOLOWER ${CMAKE_BUILD_TYPE} _type)
+ if (_type STREQUAL debug)
+ target_compile_definitions(exe1 PRIVATE DEBUG_BUILD)
+ endif()
+
+may appear to work for ``Makefile`` based and ``Ninja`` generators, but is not
+portable to IDE generators. Additionally, the :prop_tgt:`IMPORTED`
+configuration-mappings are not accounted for with code like this, so it should
+be avoided.
+
+The unary ``TARGET_PROPERTY`` generator expression and the ``TARGET_POLICY``
+generator expression are evaluated with the consuming target context. This
+means that a usage requirement specification may be evaluated differently based
+on the consumer:
+
+.. code-block:: cmake
+
+ add_library(lib1 lib1.cpp)
+ target_compile_definitions(lib1 INTERFACE
+ $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:LIB1_WITH_EXE>
+ $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:LIB1_WITH_SHARED_LIB>
+ $<$<TARGET_POLICY:CMP0041>:CONSUMER_CMP0041_NEW>
+ )
+
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 lib1)
+
+ cmake_policy(SET CMP0041 NEW)
+
+ add_library(shared_lib shared_lib.cpp)
+ target_link_libraries(shared_lib lib1)
+
+The ``exe1`` executable will be compiled with ``-DLIB1_WITH_EXE``, while the
+``shared_lib`` shared library will be compiled with ``-DLIB1_WITH_SHARED_LIB``
+and ``-DCONSUMER_CMP0041_NEW``, because policy :policy:`CMP0041` is
+``NEW`` at the point where the ``shared_lib`` target is created.
+
+The ``BUILD_INTERFACE`` expression wraps requirements which are only used when
+consumed from a target in the same buildsystem, or when consumed from a target
+exported to the build directory using the :command:`export` command. The
+``INSTALL_INTERFACE`` expression wraps requirements which are only used when
+consumed from a target which has been installed and exported with the
+:command:`install(EXPORT)` command:
+
+.. code-block:: cmake
+
+ add_library(ClimbingStats climbingstats.cpp)
+ target_compile_definitions(ClimbingStats INTERFACE
+ $<BUILD_INTERFACE:ClimbingStats_FROM_BUILD_LOCATION>
+ $<INSTALL_INTERFACE:ClimbingStats_FROM_INSTALLED_LOCATION>
+ )
+ install(TARGETS ClimbingStats EXPORT libExport ${InstallArgs})
+ install(EXPORT libExport NAMESPACE Upstream::
+ DESTINATION lib/cmake/ClimbingStats)
+ export(EXPORT libExport NAMESPACE Upstream::)
+
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 ClimbingStats)
+
+In this case, the ``exe1`` executable will be compiled with
+``-DClimbingStats_FROM_BUILD_LOCATION``. The exporting commands generate
+:prop_tgt:`IMPORTED` targets with either the ``INSTALL_INTERFACE`` or the
+``BUILD_INTERFACE`` omitted, and the ``*_INTERFACE`` marker stripped away.
+A separate project consuming the ``ClimbingStats`` package would contain:
+
+.. code-block:: cmake
+
+ find_package(ClimbingStats REQUIRED)
+
+ add_executable(Downstream main.cpp)
+ target_link_libraries(Downstream Upstream::ClimbingStats)
+
+Depending on whether the ``ClimbingStats`` package was used from the build
+location or the install location, the ``Downstream`` target would be compiled
+with either ``-DClimbingStats_FROM_BUILD_LOCATION`` or
+``-DClimbingStats_FROM_INSTALL_LOCATION``. For more about packages and
+exporting see the :manual:`cmake-packages(7)` manual.
+
+.. _`Include Directories and Usage Requirements`:
+
+Include Directories and Usage Requirements
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Include directories require some special consideration when specified as usage
+requirements and when used with generator expressions. The
+:command:`target_include_directories` command accepts both relative and
+absolute include directories:
+
+.. code-block:: cmake
+
+ add_library(lib1 lib1.cpp)
+ target_include_directories(lib1 PRIVATE
+ /absolute/path
+ relative/path
+ )
+
+Relative paths are interpreted relative to the source directory where the
+command appears. Relative paths are not allowed in the
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of :prop_tgt:`IMPORTED` targets.
+
+In cases where a non-trivial generator expression is used, the
+``INSTALL_PREFIX`` expression may be used within the argument of an
+``INSTALL_INTERFACE`` expression. It is a replacement marker which
+expands to the installation prefix when imported by a consuming project.
+
+Include directories usage requirements commonly differ between the build-tree
+and the install-tree. The ``BUILD_INTERFACE`` and ``INSTALL_INTERFACE``
+generator expressions can be used to describe separate usage requirements
+based on the usage location. Relative paths are allowed within the
+``INSTALL_INTERFACE`` expression and are interpreted relative to the
+installation prefix. For example:
+
+.. code-block:: cmake
+
+ add_library(ClimbingStats climbingstats.cpp)
+ target_include_directories(ClimbingStats INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated>
+ $<INSTALL_INTERFACE:/absolute/path>
+ $<INSTALL_INTERFACE:relative/path>
+ $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/$<CONFIG>/generated>
+ )
+
+Two convenience APIs are provided relating to include directories usage
+requirements. The :variable:`CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE` variable
+may be enabled, with an equivalent effect to:
+
+.. code-block:: cmake
+
+ set_property(TARGET tgt APPEND PROPERTY
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR}>
+ )
+
+for each target affected. The convenience for installed targets is
+an ``INCLUDES DESTINATION`` component with the :command:`install(TARGETS)`
+command:
+
+.. code-block:: cmake
+
+ install(TARGETS foo bar bat EXPORT tgts ${dest_args}
+ INCLUDES DESTINATION include
+ )
+ install(EXPORT tgts ${other_args})
+ install(FILES ${headers} DESTINATION include)
+
+This is equivalent to appending ``${CMAKE_INSTALL_PREFIX}/include`` to the
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of each of the installed
+:prop_tgt:`IMPORTED` targets when generated by :command:`install(EXPORT)`.
+
+When the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of an
+:ref:`imported target <Imported targets>` is consumed, the entries in the
+property are treated as ``SYSTEM`` include directories, as if they were
+listed in the :prop_tgt:`INTERFACE_SYSTEM_INCLUDE_DIRECTORIES` of the
+dependency. This can result in omission of compiler warnings for headers
+found in those directories. This behavior for :ref:`imported targets` may
+be controlled with the :prop_tgt:`NO_SYSTEM_FROM_IMPORTED` target property.
+
+If a binary target is linked transitively to a Mac OX framework, the
+``Headers`` directory of the framework is also treated as a usage requirement.
+This has the same effect as passing the framework directory as an include
+directory.
+
+Link Libraries and Generator Expressions
+----------------------------------------
+
+Like build specifications, :prop_tgt:`link libraries <LINK_LIBRARIES>` may be
+specified with generator expression conditions. However, as consumption of
+usage requirements is based on collection from linked dependencies, there is
+an additional limitation that the link dependencies must form a "directed
+acyclic graph". That is, if linking to a target is dependent on the value of
+a target property, that target property may not be dependent on the linked
+dependencies:
+
+.. code-block:: cmake
+
+ add_library(lib1 lib1.cpp)
+ add_library(lib2 lib2.cpp)
+ target_link_libraries(lib1 PUBLIC
+ $<$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>:lib2>
+ )
+ add_library(lib3 lib3.cpp)
+ set_property(TARGET lib3 PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 lib1 lib3)
+
+As the value of the :prop_tgt:`POSITION_INDEPENDENT_CODE` property of
+the ``exe1`` target is dependent on the linked libraries (``lib3``), and the
+edge of linking ``exe1`` is determined by the same
+:prop_tgt:`POSITION_INDEPENDENT_CODE` property, the dependency graph above
+contains a cycle. :manual:`cmake(1)` issues a diagnostic in this case.
+
+Output Files
+------------
+
+The buildsystem targets created by the :command:`add_library` and
+:command:`add_executable` commands create rules to create binary outputs.
+The exact output location of the binaries can only be determined at
+generate-time because it can depend on the build-configuration and the
+link-language of linked dependencies etc. ``TARGET_FILE``,
+``TARGET_LINKER_FILE`` and related expressions can be used to access the
+name and location of generated binaries. These expressions do not work
+for ``OBJECT`` libraries however, as there is no single file generated
+by such libraries which is relevant to the expressions.
+
+Directory-Scoped Commands
+-------------------------
+
+The :command:`target_include_directories`,
+:command:`target_compile_definitions` and
+:command:`target_compile_options` commands have an effect on only one
+target at a time. The commands :command:`add_definitions`,
+:command:`add_compile_options` and :command:`include_directories` have
+a similar function, but operate at directory scope instead of target
+scope for convenience.
+
+Pseudo Targets
+==============
+
+Some target types do not represent outputs of the buildsystem, but only inputs
+such as external dependencies, aliases or other non-build artifacts. Pseudo
+targets are not represented in the generated buildsystem.
+
+.. _`Imported Targets`:
+
+Imported Targets
+----------------
+
+An :prop_tgt:`IMPORTED` target represents a pre-existing dependency. Usually
+such targets are defined by an upstream package and should be treated as
+immutable. It is not possible to use an :prop_tgt:`IMPORTED` target in the
+left-hand-side of the :command:`target_compile_definitions`,
+:command:`target_include_directories`, :command:`target_compile_options` or
+:command:`target_link_libraries` commands, as that would be an attempt to
+modify it. :prop_tgt:`IMPORTED` targets are designed to be used only in the
+right-hand-side of those commands.
+
+:prop_tgt:`IMPORTED` targets may have the same usage requirement properties
+populated as binary targets, such as
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`,
+:prop_tgt:`INTERFACE_COMPILE_DEFINITIONS`,
+:prop_tgt:`INTERFACE_COMPILE_OPTIONS`,
+:prop_tgt:`INTERFACE_LINK_LIBRARIES`, and
+:prop_tgt:`INTERFACE_POSITION_INDEPENDENT_CODE`.
+
+The :prop_tgt:`LOCATION` may also be read from an IMPORTED target, though there
+is rarely reason to do so. Commands such as :command:`add_custom_command` can
+transparently use an :prop_tgt:`IMPORTED` :prop_tgt:`EXECUTABLE <TYPE>` target
+as a ``COMMAND`` executable.
+
+The scope of the definition of an :prop_tgt:`IMPORTED` target is the directory
+where it was defined. It may be accessed and used from subdirectories, but
+not from parent directories or sibling directories. The scope is similar to
+the scope of a cmake variable.
+
+It is also possible to define a ``GLOBAL`` :prop_tgt:`IMPORTED` target which is
+accessible globally in the buildsystem.
+
+See the :manual:`cmake-packages(7)` manual for more on creating packages
+with :prop_tgt:`IMPORTED` targets.
+
+.. _`Alias Targets`:
+
+Alias Targets
+-------------
+
+An ``ALIAS`` target is a name which may be used interchangably with
+a binary target name in read-only contexts. A primary use-case for ``ALIAS``
+targets is for example or unit test executables accompanying a library, which
+may be part of the same buildsystem or built separately based on user
+configuration.
+
+.. code-block:: cmake
+
+ add_library(lib1 lib1.cpp)
+ install(TARGETS lib1 EXPORT lib1Export ${dest_args})
+ install(EXPORT lib1Export NAMESPACE Upstream:: ${other_args})
+
+ add_library(Upstream::lib1 ALIAS lib1)
+
+In another directory, we can link unconditionally to the ``Upstream::lib1``
+target, which may be an :prop_tgt:`IMPORTED` target from a package, or an
+``ALIAS`` target if built as part of the same buildsystem.
+
+.. code-block:: cmake
+
+ if (NOT TARGET Upstream::lib1)
+ find_package(lib1 REQUIRED)
+ endif()
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 Upstream::lib1)
+
+``ALIAS`` targets are not mutable, installable or exportable. They are
+entirely local to the buildsystem description. A name can be tested for
+whether it is an ``ALIAS`` name by reading the :prop_tgt:`ALIASED_TARGET`
+property from it:
+
+.. code-block:: cmake
+
+ get_target_property(_aliased Upstream::lib1 ALIASED_TARGET)
+ if(_aliased)
+ message(STATUS "The name Upstream::lib1 is an ALIAS for ${_aliased}.")
+ endif()
+
+.. _`Interface Libraries`:
+
+Interface Libraries
+-------------------
+
+An ``INTERFACE`` target has no :prop_tgt:`LOCATION` and is mutable, but is
+otherwise similar to an :prop_tgt:`IMPORTED` target.
+
+It may specify usage requirements such as
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`,
+:prop_tgt:`INTERFACE_COMPILE_DEFINITIONS`,
+:prop_tgt:`INTERFACE_COMPILE_OPTIONS`,
+:prop_tgt:`INTERFACE_LINK_LIBRARIES`, and
+:prop_tgt:`INTERFACE_SOURCES`,
+:prop_tgt:`INTERFACE_POSITION_INDEPENDENT_CODE`.
+Only the ``INTERFACE`` modes of the :command:`target_include_directories`,
+:command:`target_compile_definitions`, :command:`target_compile_options`,
+:command:`target_sources`, and :command:`target_link_libraries` commands
+may be used with ``INTERFACE`` libraries.
+
+A primary use-case for ``INTERFACE`` libraries is header-only libraries.
+
+.. code-block:: cmake
+
+ add_library(Eigen INTERFACE)
+ target_include_directories(Eigen INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
+ $<INSTALL_INTERFACE:include/Eigen>
+ )
+
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 Eigen)
+
+Here, the usage requirements from the ``Eigen`` target are consumed and used
+when compiling, but it has no effect on linking.
+
+Another use-case is to employ an entirely target-focussed design for usage
+requirements:
+
+.. code-block:: cmake
+
+ add_library(pic_on INTERFACE)
+ set_property(TARGET pic_on PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+ add_library(pic_off INTERFACE)
+ set_property(TARGET pic_off PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE OFF)
+
+ add_library(enable_rtti INTERFACE)
+ target_compile_options(enable_rtti INTERFACE
+ $<$<OR:$<COMPILER_ID:GNU>,$<COMPILER_ID:Clang>>:-rtti>
+ )
+
+ add_executable(exe1 exe1.cpp)
+ target_link_libraries(exe1 pic_on enable_rtti)
+
+This way, the build specification of ``exe1`` is expressed entirely as linked
+targets, and the complexity of compiler-specific flags is encapsulated in an
+``INTERFACE`` library target.
+
+The properties permitted to be set on or read from an ``INTERFACE`` library
+are:
+
+* Properties matching ``INTERFACE_*``
+* Built-in properties matching ``COMPATIBLE_INTERFACE_*``
+* ``EXPORT_NAME``
+* ``IMPORTED``
+* ``NAME``
+* Properties matching ``MAP_IMPORTED_CONFIG_*``
+
+``INTERFACE`` libraries may be installed and exported. Any content they refer
+to must be installed separately:
+
+.. code-block:: cmake
+
+ add_library(Eigen INTERFACE)
+ target_include_directories(Eigen INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
+ $<INSTALL_INTERFACE:include/Eigen>
+ )
+
+ install(TARGETS Eigen EXPORT eigenExport)
+ install(EXPORT eigenExport NAMESPACE Upstream::
+ DESTINATION lib/cmake/Eigen
+ )
+ install(FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/eigen.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/vector.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/matrix.h
+ DESTINATION include/Eigen
+ )
diff --git a/Help/manual/cmake-commands.7.rst b/Help/manual/cmake-commands.7.rst
new file mode 100644
index 0000000000..8ff73a4605
--- /dev/null
+++ b/Help/manual/cmake-commands.7.rst
@@ -0,0 +1,153 @@
+.. cmake-manual-description: CMake Language Command Reference
+
+cmake-commands(7)
+*****************
+
+.. only:: html or latex
+
+ .. contents::
+
+Normal Commands
+===============
+
+These commands may be used freely in CMake projects.
+
+.. toctree::
+ :maxdepth: 1
+
+ /command/add_compile_options
+ /command/add_custom_command
+ /command/add_custom_target
+ /command/add_definitions
+ /command/add_dependencies
+ /command/add_executable
+ /command/add_library
+ /command/add_subdirectory
+ /command/add_test
+ /command/aux_source_directory
+ /command/break
+ /command/build_command
+ /command/cmake_host_system_information
+ /command/cmake_minimum_required
+ /command/cmake_policy
+ /command/configure_file
+ /command/create_test_sourcelist
+ /command/define_property
+ /command/elseif
+ /command/else
+ /command/enable_language
+ /command/enable_testing
+ /command/endforeach
+ /command/endfunction
+ /command/endif
+ /command/endmacro
+ /command/endwhile
+ /command/execute_process
+ /command/export
+ /command/file
+ /command/find_file
+ /command/find_library
+ /command/find_package
+ /command/find_path
+ /command/find_program
+ /command/fltk_wrap_ui
+ /command/foreach
+ /command/function
+ /command/get_cmake_property
+ /command/get_directory_property
+ /command/get_filename_component
+ /command/get_property
+ /command/get_source_file_property
+ /command/get_target_property
+ /command/get_test_property
+ /command/if
+ /command/include_directories
+ /command/include_external_msproject
+ /command/include_regular_expression
+ /command/include
+ /command/install
+ /command/link_directories
+ /command/list
+ /command/load_cache
+ /command/load_command
+ /command/macro
+ /command/mark_as_advanced
+ /command/math
+ /command/message
+ /command/option
+ /command/project
+ /command/qt_wrap_cpp
+ /command/qt_wrap_ui
+ /command/remove_definitions
+ /command/return
+ /command/separate_arguments
+ /command/set_directory_properties
+ /command/set_property
+ /command/set
+ /command/set_source_files_properties
+ /command/set_target_properties
+ /command/set_tests_properties
+ /command/site_name
+ /command/source_group
+ /command/string
+ /command/target_compile_definitions
+ /command/target_compile_features
+ /command/target_compile_options
+ /command/target_include_directories
+ /command/target_link_libraries
+ /command/target_sources
+ /command/try_compile
+ /command/try_run
+ /command/unset
+ /command/variable_watch
+ /command/while
+
+Deprecated Commands
+===================
+
+These commands are available only for compatibility with older
+versions of CMake. Do not use them in new code.
+
+.. toctree::
+ :maxdepth: 1
+
+ /command/build_name
+ /command/exec_program
+ /command/export_library_dependencies
+ /command/install_files
+ /command/install_programs
+ /command/install_targets
+ /command/link_libraries
+ /command/make_directory
+ /command/output_required_files
+ /command/remove
+ /command/subdir_depends
+ /command/subdirs
+ /command/use_mangled_mesa
+ /command/utility_source
+ /command/variable_requires
+ /command/write_file
+
+.. _`CTest Commands`:
+
+CTest Commands
+==============
+
+These commands are available only in ctest scripts.
+
+.. toctree::
+ :maxdepth: 1
+
+ /command/ctest_build
+ /command/ctest_configure
+ /command/ctest_coverage
+ /command/ctest_empty_binary_directory
+ /command/ctest_memcheck
+ /command/ctest_read_custom_files
+ /command/ctest_run_script
+ /command/ctest_sleep
+ /command/ctest_start
+ /command/ctest_submit
+ /command/ctest_test
+ /command/ctest_update
+ /command/ctest_upload
diff --git a/Help/manual/cmake-compile-features.7.rst b/Help/manual/cmake-compile-features.7.rst
new file mode 100644
index 0000000000..8a2fe30a45
--- /dev/null
+++ b/Help/manual/cmake-compile-features.7.rst
@@ -0,0 +1,294 @@
+.. cmake-manual-description: CMake Compile Features Reference
+
+cmake-compile-features(7)
+*************************
+
+.. only:: html or latex
+
+ .. contents::
+
+Introduction
+============
+
+Project source code may depend on, or be conditional on, the availability
+of certain features of the compiler. There are three use-cases which arise:
+`Compile Feature Requirements`_, `Optional Compile Features`_
+and `Conditional Compilation Options`_.
+
+While features are typically specified in programming language standards,
+CMake provides a primary user interface based on granular handling of
+the features, not the language standard that introduced the feature.
+
+The :prop_gbl:`CMAKE_C_KNOWN_FEATURES` and
+:prop_gbl:`CMAKE_CXX_KNOWN_FEATURES` global properties contain all the
+features known to CMake, regardless of compiler support for the feature.
+The :variable:`CMAKE_C_COMPILE_FEATURES` and
+:variable:`CMAKE_CXX_COMPILE_FEATURES` variables contain all features
+CMake knows are known to the compiler, regardless of language standard
+or compile flags needed to use them.
+
+Features known to CMake are named mostly following the same convention
+as the Clang feature test macros. The are some execptions, such as
+CMake using ``cxx_final`` and ``cxx_override`` instead of the single
+``cxx_override_control`` used by Clang.
+
+Compile Feature Requirements
+============================
+
+Compile feature requirements may be specified with the
+:command:`target_compile_features` command. For example, if a target must
+be compiled with compiler support for the
+:prop_gbl:`cxx_constexpr <CMAKE_CXX_KNOWN_FEATURES>` feature:
+
+.. code-block:: cmake
+
+ add_library(mylib requires_constexpr.cpp)
+ target_compile_features(mylib PRIVATE cxx_constexpr)
+
+In processing the requirement for the ``cxx_constexpr`` feature,
+:manual:`cmake(1)` will ensure that the in-use C++ compiler is capable
+of the feature, and will add any necessary flags such as ``-std=gnu++11``
+to the compile lines of C++ files in the ``mylib`` target. A
+``FATAL_ERROR`` is issued if the compiler is not capable of the
+feature.
+
+The exact compile flags and language standard are deliberately not part
+of the user interface for this use-case. CMake will compute the
+appropriate compile flags to use by considering the features specified
+for each target.
+
+Such compile flags are added even if the compiler supports the
+particular feature without the flag. For example, the GNU compiler
+supports variadic templates (with a warning) even if ``-std=gnu++98`` is
+used. CMake adds the ``-std=gnu++11`` flag if ``cxx_variadic_templates``
+is specified as a requirement.
+
+In the above example, ``mylib`` requires ``cxx_constexpr`` when it
+is built itself, but consumers of ``mylib`` are not required to use a
+compiler which supports ``cxx_constexpr``. If the interface of
+``mylib`` does require the ``cxx_constexpr`` feature (or any other
+known feature), that may be specified with the ``PUBLIC`` or
+``INTERFACE`` signatures of :command:`target_compile_features`:
+
+.. code-block:: cmake
+
+ add_library(mylib requires_constexpr.cpp)
+ # cxx_constexpr is a usage-requirement
+ target_compile_features(mylib PUBLIC cxx_constexpr)
+
+ # main.cpp will be compiled with -std=gnu++11 on GNU for cxx_constexpr.
+ add_executable(myexe main.cpp)
+ target_link_libraries(myexe mylib)
+
+Feature requirements are evaluated transitively by consuming the link
+implementation. See :manual:`cmake-buildsystem(7)` for more on
+transitive behavior of build properties and usage requirements.
+
+Because the :prop_tgt:`CXX_EXTENSIONS` target property is ``ON`` by default,
+CMake uses extended variants of language dialects by default, such as
+``-std=gnu++11`` instead of ``-std=c++11``. That target property may be
+set to ``OFF`` to use the non-extended variant of the dialect flag. Note
+that because most compilers enable extensions by default, this could
+expose cross-platform bugs in user code or in the headers of third-party
+dependencies.
+
+Optional Compile Features
+=========================
+
+Compile features may be preferred if available, without creating a hard
+requirement. For example, a library may provides alternative
+implementations depending on whether the ``cxx_variadic_templates``
+feature is available:
+
+.. code-block:: c++
+
+ #if Foo_COMPILER_CXX_VARIADIC_TEMPLATES
+ template<int I, int... Is>
+ struct Interface;
+
+ template<int I>
+ struct Interface<I>
+ {
+ static int accumulate()
+ {
+ return I;
+ }
+ };
+
+ template<int I, int... Is>
+ struct Interface
+ {
+ static int accumulate()
+ {
+ return I + Interface<Is...>::accumulate();
+ }
+ };
+ #else
+ template<int I1, int I2 = 0, int I3 = 0, int I4 = 0>
+ struct Interface
+ {
+ static int accumulate() { return I1 + I2 + I3 + I4; }
+ };
+ #endif
+
+Such an interface depends on using the correct preprocessor defines for the
+compiler features. CMake can generate a header file containing such
+defines using the :module:`WriteCompilerDetectionHeader` module. The
+module contains the ``write_compiler_detection_header`` function which
+accepts parameters to control the content of the generated header file:
+
+.. code-block:: cmake
+
+ write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/foo_compiler_detection.h"
+ PREFIX Foo
+ COMPILERS GNU
+ FEATURES
+ cxx_variadic_templates
+ )
+
+Such a header file may be used internally in the source code of a project,
+and it may be installed and used in the interface of library code.
+
+For each feature listed in ``FEATURES``, a preprocessor definition
+is created in the header file, and defined to either ``1`` or ``0``.
+
+Additionally, some features call for additional defines, such as the
+``cxx_final`` and ``cxx_override`` features. Rather than being used in
+``#ifdef`` code, the ``final`` keyword is abstracted by a symbol
+which is defined to either ``final``, a compiler-specific equivalent, or
+to empty. That way, C++ code can be written to unconditionally use the
+symbol, and compiler support determines what it is expanded to:
+
+.. code-block:: c++
+
+ struct Interface {
+ virtual void Execute() = 0;
+ };
+
+ struct Concrete Foo_FINAL {
+ void Execute() Foo_OVERRIDE;
+ };
+
+In this case, ``Foo_FINAL`` will expand to ``final`` if the
+compiler supports the keyword, or to empty otherwise.
+
+In this use-case, the CMake code will wish to enable a particular language
+standard if available from the compiler. The :prop_tgt:`CXX_STANDARD`
+target property variable may be set to the desired language standard
+for a particular target, and the :variable:`CMAKE_CXX_STANDARD` may be
+set to influence all following targets:
+
+.. code-block:: cmake
+
+ write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/foo_compiler_detection.h"
+ PREFIX Foo
+ COMPILERS GNU
+ FEATURES
+ cxx_final cxx_override
+ )
+
+ # Includes foo_compiler_detection.h and uses the Foo_FINAL symbol
+ # which will expand to 'final' if the compiler supports the requested
+ # CXX_STANDARD.
+ add_library(foo foo.cpp)
+ set_property(TARGET foo PROPERTY CXX_STANDARD 11)
+
+ # Includes foo_compiler_detection.h and uses the Foo_FINAL symbol
+ # which will expand to 'final' if the compiler supports the feature,
+ # even though CXX_STANDARD is not set explicitly. The requirement of
+ # cxx_constexpr causes CMake to set CXX_STANDARD internally, which
+ # affects the compile flags.
+ add_library(foo_impl foo_impl.cpp)
+ target_compile_features(foo_impl PRIVATE cxx_constexpr)
+
+The ``write_compiler_detection_header`` function also creates compatibility
+code for other features which have standard equivalents. For example, the
+``cxx_static_assert`` feature is emulated with a template and abstracted
+via the ``<PREFIX>_STATIC_ASSERT`` and ``<PREFIX>_STATIC_ASSERT_MSG``
+function-macros.
+
+Conditional Compilation Options
+===============================
+
+Libraries may provide entirely different header files depending on
+requested compiler features.
+
+For example, a header at ``with_variadics/interface.h`` may contain:
+
+.. code-block:: c++
+
+ template<int I, int... Is>
+ struct Interface;
+
+ template<int I>
+ struct Interface<I>
+ {
+ static int accumulate()
+ {
+ return I;
+ }
+ };
+
+ template<int I, int... Is>
+ struct Interface
+ {
+ static int accumulate()
+ {
+ return I + Interface<Is...>::accumulate();
+ }
+ };
+
+while a header at ``no_variadics/interface.h`` may contain:
+
+.. code-block:: c++
+
+ template<int I1, int I2 = 0, int I3 = 0, int I4 = 0>
+ struct Interface
+ {
+ static int accumulate() { return I1 + I2 + I3 + I4; }
+ };
+
+It would be possible to write a abstraction ``interface.h`` header
+containing something like:
+
+.. code-block:: c++
+
+ #include "foo_compiler_detection.h"
+ #if Foo_COMPILER_CXX_VARIADIC_TEMPLATES
+ #include "with_variadics/interface.h"
+ #else
+ #include "no_variadics/interface.h"
+ #endif
+
+However this could be unmaintainable if there are many files to
+abstract. What is needed is to use alternative include directories
+depending on the compiler capabilities.
+
+CMake provides a ``COMPILE_FEATURES``
+:manual:`generator expression <cmake-generator-expressions(7)>` to implement
+such conditions. This may be used with the build-property commands such as
+:command:`target_include_directories` and :command:`target_link_libraries`
+to set the appropriate :manual:`buildsystem <cmake-buildsystem(7)>`
+properties:
+
+.. code-block:: cmake
+
+ add_library(foo INTERFACE)
+ target_link_libraries(foo
+ INTERFACE
+ "$<$<COMPILE_FEATURES:cxx_variadic_templates>:${CMAKE_CURRENT_SOURCE_DIR}/with_variadics>"
+ "$<$<NOT:$<COMPILE_FEATURES:cxx_variadic_templates>>:${CMAKE_CURRENT_SOURCE_DIR}/no_variadics>")
+
+Consuming code then simply links to the ``foo`` target as usual and uses
+the feature-appropriate include directory
+
+.. code-block:: cmake
+
+ add_executable(consumer_with consumer_with.cpp)
+ target_link_libraries(consumer_with foo)
+ set_property(TARGET consumer_with CXX_STANDARD 11)
+
+ add_executable(consumer_no consumer_no.cpp)
+ target_link_libraries(consumer_no foo)
diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst
new file mode 100644
index 0000000000..625dac06b0
--- /dev/null
+++ b/Help/manual/cmake-developer.7.rst
@@ -0,0 +1,1144 @@
+.. cmake-manual-description: CMake Developer Reference
+
+cmake-developer(7)
+******************
+
+.. only:: html or latex
+
+ .. contents::
+
+Introduction
+============
+
+This manual is intended for reference by developers modifying the CMake
+source tree itself.
+
+
+Permitted C++ Subset
+====================
+
+CMake is required to build with ancient C++ compilers and standard library
+implementations. Some common C++ constructs may not be used in CMake in order
+to build with such toolchains.
+
+std::vector::at
+---------------
+
+The ``at()`` member function of ``std::vector`` may not be used. Use
+``operator[]`` instead:
+
+.. code-block:: c++
+
+ std::vector<int> someVec = getVec();
+ int i1 = someVec.at(5); // Wrong
+ int i2 = someVec[5]; // Ok
+
+std::string::append and std::string::clear
+------------------------------------------
+
+The ``append()`` and ``clear()`` member functions of ``std::string`` may not
+be used. Use ``operator+=`` and ``operator=`` instead:
+
+.. code-block:: c++
+
+ std::string stringBuilder;
+ stringBuilder.append("chunk"); // Wrong
+ stringBuilder.clear(); // Wrong
+ stringBuilder += "chunk"; // Ok
+ stringBuilder = ""; // Ok
+
+std::set const iterators
+------------------------
+
+The ``find()`` member function of a ``const`` ``std::set`` instance may not be
+used in a comparison with the iterator returned by ``end()``:
+
+.. code-block:: c++
+
+ const std::set<std::string>& someSet = getSet();
+ if (someSet.find("needle") == someSet.end()) // Wrong
+ {
+ // ...
+ }
+
+The return value of ``find()`` must be assigned to an intermediate
+``const_iterator`` for comparison:
+
+.. code-block:: c++
+
+ const std::set<std::string>& someSet;
+ const std::set<std::string>::const_iterator i = someSet.find("needle");
+ if (i != propSet.end()) // Ok
+ {
+ // ...
+ }
+
+Char Array to ``string`` Conversions with Algorithms
+----------------------------------------------------
+
+In some implementations, algorithms operating on iterators to a container of
+``std::string`` can not accept a ``const char*`` value:
+
+.. code-block:: c++
+
+ const char* dir = /*...*/;
+ std::vector<std::string> vec;
+ // ...
+ std::binary_search(vec.begin(), vec.end(), dir); // Wrong
+
+The ``std::string`` may need to be explicitly constructed:
+
+.. code-block:: c++
+
+ const char* dir = /*...*/;
+ std::vector<std::string> vec;
+ // ...
+ std::binary_search(vec.begin(), vec.end(), std::string(dir)); // Ok
+
+std::auto_ptr
+-------------
+
+Some implementations have a ``std::auto_ptr`` which can not be used as a
+return value from a function. ``std::auto_ptr`` may not be used. Use
+``cmsys::auto_ptr`` instead.
+
+std::vector::insert and std::set
+--------------------------------
+
+Use of ``std::vector::insert`` with an iterator whose ``element_type`` requires
+conversion is not allowed:
+
+.. code-block:: c++
+
+ std::set<const char*> theSet;
+ std::vector<std::string> theVector;
+ theVector.insert(theVector.end(), theSet.begin(), theSet.end()); // Wrong
+
+A loop must be used instead:
+
+.. code-block:: c++
+
+ std::set<const char*> theSet;
+ std::vector<std::string> theVector;
+ for(std::set<const char*>::iterator li = theSet.begin();
+ li != theSet.end(); ++li)
+ {
+ theVector.push_back(*li);
+ }
+
+std::set::insert
+----------------
+
+Use of ``std::set::insert`` is not allowed with any source container:
+
+.. code-block:: c++
+
+ std::set<cmTarget*> theSet;
+ theSet.insert(targets.begin(), targets.end()); // Wrong
+
+A loop must be used instead:
+
+.. code-block:: c++
+
+ ConstIterator it = targets.begin();
+ const ConstIterator end = targets.end();
+ for ( ; it != end; ++it)
+ {
+ theSet.insert(*it);
+ }
+
+.. MSVC6, SunCC 5.9
+
+Template Parameter Defaults
+---------------------------
+
+On ancient compilers, C++ template must use template parameters in function
+arguments. If no parameter of that type is needed, the common workaround is
+to add a defaulted pointer to the type to the templated function. However,
+this does not work with other ancient compilers:
+
+.. code-block:: c++
+
+ template<typename PropertyType>
+ PropertyType getTypedProperty(cmTarget* tgt, const char* prop,
+ PropertyType* = 0) // Wrong
+ {
+
+ }
+
+.. code-block:: c++
+
+ template<typename PropertyType>
+ PropertyType getTypedProperty(cmTarget* tgt, const char* prop,
+ PropertyType*) // Ok
+ {
+
+ }
+
+and invoke it with the value ``0`` explicitly in all cases.
+
+std::min and std::max
+---------------------
+
+``min`` and ``max`` are defined as macros on some systems. ``std::min`` and
+``std::max`` may not be used. Use ``cmMinimum`` and ``cmMaximum`` instead.
+
+size_t
+------
+
+Various implementations have differing implementation of ``size_t``. When
+assigning the result of ``.size()`` on a container for example, the result
+should be assigned to ``size_t`` not to ``std::size_t``, ``unsigned int`` or
+similar types.
+
+Templates
+---------
+
+Some template code is permitted, but with some limitations. Member templates
+may not be used, and template friends may not be used.
+
+Adding Compile Features
+=======================
+
+CMake reports an error if a compiler whose features are known does not report
+support for a particular requested feature. A compiler is considered to have
+known features if it reports support for at least one feature.
+
+When adding a new compile feature to CMake, it is therefore necessary to list
+support for the feature for all CompilerIds which already have one or more
+feature supported, if the new feature is available for any version of the
+compiler.
+
+When adding the first supported feature to a particular CompilerId, it is
+necessary to list support for all features known to cmake (See
+:variable:`CMAKE_C_COMPILE_FEATURES` and
+:variable:`CMAKE_CXX_COMPILE_FEATURES` as appropriate), where available for
+the compiler.
+
+It is sensible to record the features for the most recent version of a
+particular CompilerId first, and then work backwards. It is sensible to
+try to create a continuous range of versions of feature releases of the
+compiler. Gaps in the range indicate incorrect features recorded for
+intermediate releases.
+
+Generally, features are made available for a particular version if the
+compiler vendor documents availability of the feature with that
+version. Note that sometimes partially implemented features appear to
+be functional in previous releases (such as ``cxx_constexpr`` in GNU 4.6,
+though availability is documented in GNU 4.7), and sometimes compiler vendors
+document availability of features, though supporting infrastructure is
+not available (such as ``__has_feature(cxx_generic_lambdas)`` indicating
+non-availability in Clang 3.4, though it is documented as available, and
+fixed in Clang 3.5). Similar cases for other compilers and versions
+need to be investigated when extending CMake to support them.
+
+When a vendor releases a new version of a known compiler which supports
+a previously unsupported feature, and there are already known features for
+that compiler, the feature should be listed as supported in CMake for
+that version of the compiler as soon as reasonably possible.
+
+Standard-specific/compiler-specific variables such
+``CMAKE_CXX98_COMPILE_FEATURES`` are deliberately not documented. They
+only exist for the compiler-specific implementation of adding the ``-std``
+compile flag for compilers which need that.
+
+Help
+====
+
+The ``Help`` directory contains CMake help manual source files.
+They are written using the `reStructuredText`_ markup syntax and
+processed by `Sphinx`_ to generate the CMake help manuals.
+
+.. _`reStructuredText`: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
+.. _`Sphinx`: http://sphinx-doc.org
+
+Markup Constructs
+-----------------
+
+In addition to using Sphinx to generate the CMake help manuals, we
+also use a C++-implemented document processor to print documents for
+the ``--help-*`` command-line help options. It supports a subset of
+reStructuredText markup. When authoring or modifying documents,
+please verify that the command-line help looks good in addition to the
+Sphinx-generated html and man pages.
+
+The command-line help processor supports the following constructs
+defined by reStructuredText, Sphinx, and a CMake extension to Sphinx.
+
+..
+ Note: This list must be kept consistent with the cmRST implementation.
+
+CMake Domain directives
+ Directives defined in the `CMake Domain`_ for defining CMake
+ documentation objects are printed in command-line help output as
+ if the lines were normal paragraph text with interpretation.
+
+CMake Domain interpreted text roles
+ Interpreted text roles defined in the `CMake Domain`_ for
+ cross-referencing CMake documentation objects are replaced by their
+ link text in command-line help output. Other roles are printed
+ literally and not processed.
+
+``code-block`` directive
+ Add a literal code block without interpretation. The command-line
+ help processor prints the block content without the leading directive
+ line and with common indentation replaced by one space.
+
+``include`` directive
+ Include another document source file. The command-line help
+ processor prints the included document inline with the referencing
+ document.
+
+literal block after ``::``
+ A paragraph ending in ``::`` followed by a blank line treats
+ the following indented block as literal text without interpretation.
+ The command-line help processor prints the ``::`` literally and
+ prints the block content with common indentation replaced by one
+ space.
+
+``note`` directive
+ Call out a side note. The command-line help processor prints the
+ block content as if the lines were normal paragraph text with
+ interpretation.
+
+``parsed-literal`` directive
+ Add a literal block with markup interpretation. The command-line
+ help processor prints the block content without the leading
+ directive line and with common indentation replaced by one space.
+
+``productionlist`` directive
+ Render context-free grammar productions. The command-line help
+ processor prints the block content as if the lines were normal
+ paragraph text with interpretation.
+
+``replace`` directive
+ Define a ``|substitution|`` replacement.
+ The command-line help processor requires a substitution replacement
+ to be defined before it is referenced.
+
+``|substitution|`` reference
+ Reference a substitution replacement previously defined by
+ the ``replace`` directive. The command-line help processor
+ performs the substitution and replaces all newlines in the
+ replacement text with spaces.
+
+``toctree`` directive
+ Include other document sources in the Table-of-Contents
+ document tree. The command-line help processor prints
+ the referenced documents inline as part of the referencing
+ document.
+
+Inline markup constructs not listed above are printed literally in the
+command-line help output. We prefer to use inline markup constructs that
+look correct in source form, so avoid use of \\-escapes in favor of inline
+literals when possible.
+
+Explicit markup blocks not matching directives listed above are removed from
+command-line help output. Do not use them, except for plain ``..`` comments
+that are removed by Sphinx too.
+
+Note that nested indentation of blocks is not recognized by the
+command-line help processor. Therefore:
+
+* Explicit markup blocks are recognized only when not indented
+ inside other blocks.
+
+* Literal blocks after paragraphs ending in ``::`` but not
+ at the top indentation level may consume all indented lines
+ following them.
+
+Try to avoid these cases in practice.
+
+CMake Domain
+------------
+
+CMake adds a `Sphinx Domain`_ called ``cmake``, also called the
+"CMake Domain". It defines several "object" types for CMake
+documentation:
+
+``command``
+ A CMake language command.
+
+``generator``
+ A CMake native build system generator.
+ See the :manual:`cmake(1)` command-line tool's ``-G`` option.
+
+``manual``
+ A CMake manual page, like this :manual:`cmake-developer(7)` manual.
+
+``module``
+ A CMake module.
+ See the :manual:`cmake-modules(7)` manual
+ and the :command:`include` command.
+
+``policy``
+ A CMake policy.
+ See the :manual:`cmake-policies(7)` manual
+ and the :command:`cmake_policy` command.
+
+``prop_cache, prop_dir, prop_gbl, prop_sf, prop_inst, prop_test, prop_tgt``
+ A CMake cache, directory, global, source file, installed file, test,
+ or target property, respectively. See the :manual:`cmake-properties(7)`
+ manual and the :command:`set_property` command.
+
+``variable``
+ A CMake language variable.
+ See the :manual:`cmake-variables(7)` manual
+ and the :command:`set` command.
+
+Documentation objects in the CMake Domain come from two sources.
+First, the CMake extension to Sphinx transforms every document named
+with the form ``Help/<type>/<file-name>.rst`` to a domain object with
+type ``<type>``. The object name is extracted from the document title,
+which is expected to be of the form::
+
+ <object-name>
+ -------------
+
+and to appear at or near the top of the ``.rst`` file before any other
+lines starting in a letter, digit, or ``<``. If no such title appears
+literally in the ``.rst`` file, the object name is the ``<file-name>``.
+If a title does appear, it is expected that ``<file-name>`` is equal
+to ``<object-name>`` with any ``<`` and ``>`` characters removed.
+
+Second, the CMake Domain provides directives to define objects inside
+other documents:
+
+.. code-block:: rst
+
+ .. command:: <command-name>
+
+ This indented block documents <command-name>.
+
+ .. variable:: <variable-name>
+
+ This indented block documents <variable-name>.
+
+Object types for which no directive is available must be defined using
+the first approach above.
+
+.. _`Sphinx Domain`: http://sphinx-doc.org/domains.html
+
+Cross-References
+----------------
+
+Sphinx uses reStructuredText interpreted text roles to provide
+cross-reference syntax. The `CMake Domain`_ provides for each
+domain object type a role of the same name to cross-reference it.
+CMake Domain roles are inline markup of the forms::
+
+ :type:`name`
+ :type:`text <name>`
+
+where ``type`` is the domain object type and ``name`` is the
+domain object name. In the first form the link text will be
+``name`` (or ``name()`` if the type is ``command``) and in
+the second form the link text will be the explicit ``text``.
+For example, the code:
+
+.. code-block:: rst
+
+ * The :command:`list` command.
+ * The :command:`list(APPEND)` sub-command.
+ * The :command:`list() command <list>`.
+ * The :command:`list(APPEND) sub-command <list>`.
+ * The :variable:`CMAKE_VERSION` variable.
+ * The :prop_tgt:`OUTPUT_NAME_<CONFIG>` target property.
+
+produces:
+
+* The :command:`list` command.
+* The :command:`list(APPEND)` sub-command.
+* The :command:`list() command <list>`.
+* The :command:`list(APPEND) sub-command <list>`.
+* The :variable:`CMAKE_VERSION` variable.
+* The :prop_tgt:`OUTPUT_NAME_<CONFIG>` target property.
+
+Note that CMake Domain roles differ from Sphinx and reStructuredText
+convention in that the form ``a<b>``, without a space preceding ``<``,
+is interpreted as a name instead of link text with an explicit target.
+This is necessary because we use ``<placeholders>`` frequently in
+object names like ``OUTPUT_NAME_<CONFIG>``. The form ``a <b>``,
+with a space preceding ``<``, is still interpreted as a link text
+with an explicit target.
+
+Style
+-----
+
+Style: Section Headers
+^^^^^^^^^^^^^^^^^^^^^^
+
+When marking section titles, make the section decoration line as long as
+the title text. Use only a line below the title, not above. For
+example:
+
+.. code-block:: rst
+
+ Title Text
+ ----------
+
+Capitalize the first letter of each non-minor word in the title.
+
+The section header underline character hierarchy is
+
+* ``#``: Manual group (part) in the master document
+* ``*``: Manual (chapter) title
+* ``=``: Section within a manual
+* ``-``: Subsection or `CMake Domain`_ object document title
+* ``^``: Subsubsection or `CMake Domain`_ object document section
+* ``"``: Paragraph or `CMake Domain`_ object document subsection
+
+Style: Whitespace
+^^^^^^^^^^^^^^^^^
+
+Use two spaces for indentation. Use two spaces between sentences in
+prose.
+
+Style: Line Length
+^^^^^^^^^^^^^^^^^^
+
+Prefer to restrict the width of lines to 75-80 columns. This is not a
+hard restriction, but writing new paragraphs wrapped at 75 columns
+allows space for adding minor content without significant re-wrapping of
+content.
+
+Style: Prose
+^^^^^^^^^^^^
+
+Use American English spellings in prose.
+
+Style: Starting Literal Blocks
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Prefer to mark the start of literal blocks with ``::`` at the end of
+the preceding paragraph. In cases where the following block gets
+a ``code-block`` marker, put a single ``:`` at the end of the preceding
+paragraph.
+
+Style: CMake Command Signatures
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Command signatures should be marked up as plain literal blocks, not as
+cmake ``code-blocks``.
+
+Signatures are separated from preceding content by a section header.
+That is, use:
+
+.. code-block:: rst
+
+ ... preceding paragraph.
+
+ Normal Libraries
+ ^^^^^^^^^^^^^^^^
+
+ ::
+
+ add_library(<lib> ...)
+
+ This signature is used for ...
+
+Signatures of commands should wrap optional parts with square brackets,
+and should mark list of optional arguments with an ellipsis (``...``).
+Elements of the signature which are specified by the user should be
+specified with angle brackets, and may be referred to in prose using
+``inline-literal`` syntax.
+
+Style: Boolean Constants
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+Use "``OFF``" and "``ON``" for boolean values which can be modified by
+the user, such as :prop_tgt:`POSITION_INDEPENDENT_CODE`. Such properties
+may be "enabled" and "disabled". Use "``True``" and "``False``" for
+inherent values which can't be modified after being set, such as the
+:prop_tgt:`IMPORTED` property of a build target.
+
+Style: Inline Literals
+^^^^^^^^^^^^^^^^^^^^^^
+
+Mark up references to keywords in signatures, file names, and other
+technical terms with ``inline-literal`` syntax, for example:
+
+.. code-block:: rst
+
+ If ``WIN32`` is used with :command:`add_executable`, the
+ :prop_tgt:`WIN32_EXECUTABLE` target property is enabled. That command
+ creates the file ``<name>.exe`` on Windows.
+
+Style: Cross-References
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Mark up linkable references as links, including repeats.
+An alternative, which is used by wikipedia
+(`<http://en.wikipedia.org/wiki/WP:REPEATLINK>`_),
+is to link to a reference only once per article. That style is not used
+in CMake documentation.
+
+Style: Referencing CMake Concepts
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+If referring to a concept which corresponds to a property, and that
+concept is described in a high-level manual, prefer to link to the
+manual section instead of the property. For example:
+
+.. code-block:: rst
+
+ This command creates an :ref:`Imported Target <Imported Targets>`.
+
+instead of:
+
+.. code-block:: rst
+
+ This command creates an :prop_tgt:`IMPORTED` target.
+
+The latter should be used only when referring specifically to the
+property.
+
+References to manual sections are not automatically created by creating
+a section, but code such as:
+
+.. code-block:: rst
+
+ .. _`Imported Targets`:
+
+creates a suitable anchor. Use an anchor name which matches the name
+of the corresponding section. Refer to the anchor using a
+cross-reference with specified text.
+
+Imported Targets need the ``IMPORTED`` term marked up with care in
+particular because the term may refer to a command keyword
+(``IMPORTED``), a target property (:prop_tgt:`IMPORTED`), or a
+concept (:ref:`Imported Targets`).
+
+Where a property, command or variable is related conceptually to others,
+by for example, being related to the buildsystem description, generator
+expressions or Qt, each relevant property, command or variable should
+link to the primary manual, which provides high-level information. Only
+particular information relating to the command should be in the
+documentation of the command.
+
+Style: Referencing CMake Domain Objects
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+When referring to `CMake Domain`_ objects such as properties, variables,
+commands etc, prefer to link to the target object and follow that with
+the type of object it is. For example:
+
+.. code-block:: rst
+
+ Set the :prop_tgt:`AUTOMOC` target property to ``ON``.
+
+Instead of
+
+.. code-block:: rst
+
+ Set the target property :prop_tgt:`AUTOMOC` to ``ON``.
+
+The ``policy`` directive is an exception, and the type us usually
+referred to before the link:
+
+.. code-block:: rst
+
+ If policy :prop_tgt:`CMP0022` is set to ``NEW`` the behavior is ...
+
+However, markup self-references with ``inline-literal`` syntax.
+For example, within the :command:`add_executable` command
+documentation, use
+
+.. code-block:: rst
+
+ ``add_executable``
+
+not
+
+.. code-block:: rst
+
+ :command:`add_executable`
+
+which is used elsewhere.
+
+Modules
+=======
+
+The ``Modules`` directory contains CMake-language ``.cmake`` module files.
+
+Module Documentation
+--------------------
+
+To document CMake module ``Modules/<module-name>.cmake``, modify
+``Help/manual/cmake-modules.7.rst`` to reference the module in the
+``toctree`` directive, in sorted order, as::
+
+ /module/<module-name>
+
+Then add the module document file ``Help/module/<module-name>.rst``
+containing just the line::
+
+ .. cmake-module:: ../../Modules/<module-name>.cmake
+
+The ``cmake-module`` directive will scan the module file to extract
+reStructuredText markup from comment blocks that start in ``.rst:``.
+Add to the top of ``Modules/<module-name>.cmake`` a
+:ref:`Line Comment` block of the form:
+
+.. code-block:: cmake
+
+ #.rst:
+ # <module-name>
+ # -------------
+ #
+ # <reStructuredText documentation of module>
+
+or a :ref:`Bracket Comment` of the form:
+
+.. code-block:: cmake
+
+ #[[.rst:
+ <module-name>
+ -------------
+
+ <reStructuredText documentation of module>
+ #]]
+
+Any number of ``=`` may be used in the opening and closing brackets
+as long as they match. Content on the line containing the closing
+bracket is excluded if and only if the line starts in ``#``.
+
+Additional such ``.rst:`` comments may appear anywhere in the module file.
+All such comments must start with ``#`` in the first column.
+
+For example, a ``Modules/Findxxx.cmake`` module may contain:
+
+.. code-block:: cmake
+
+ #.rst:
+ # FindXxx
+ # -------
+ #
+ # This is a cool module.
+ # This module does really cool stuff.
+ # It can do even more than you think.
+ #
+ # It even needs two paragraphs to tell you about it.
+ # And it defines the following variables:
+ #
+ # * VAR_COOL: this is great isn't it?
+ # * VAR_REALLY_COOL: cool right?
+
+ <code>
+
+ #[========================================[.rst:
+ .. command:: xxx_do_something
+
+ This command does something for Xxx::
+
+ xxx_do_something(some arguments)
+ #]========================================]
+ macro(xxx_do_something)
+ <code>
+ endmacro()
+
+After the top documentation block, leave a *BLANK* line, and then add a
+copyright and licence notice block like this one (change only the year
+range and name)
+
+.. code-block:: cmake
+
+ #=============================================================================
+ # Copyright 2009-2011 Your Name
+ #
+ # 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.)
+
+Test the documentation formatting by running
+``cmake --help-module <module-name>``, and also by enabling the
+``SPHINX_HTML`` and ``SPHINX_MAN`` options to build the documentation.
+Edit the comments until generated documentation looks satisfactory. To
+have a .cmake file in this directory NOT show up in the modules
+documentation, simply leave out the ``Help/module/<module-name>.rst``
+file and the ``Help/manual/cmake-modules.7.rst`` toctree entry.
+
+
+Find Modules
+------------
+
+A "find module" is a ``Modules/Find<package>.cmake`` file to be loaded
+by the :command:`find_package` command when invoked for ``<package>``.
+
+The primary task of a find module is to determine whether a package
+exists on the system, set the ``<package>_FOUND`` variable to reflect
+this and provide any variables, macros and imported targets required to
+use the package.
+
+The traditional approach is to use variables for everything, including
+libraries and executables: see the `Standard Variable Names`_ section
+below. This is what most of the existing find modules provided by CMake
+do.
+
+The more modern approach is to behave as much like
+``<package>Config.cmake`` files as possible, by providing imported
+targets. As well as matching how ``*Config.cmake`` files work, the
+libraries, include directories and compile definitions are all set just
+by using the target in a :command:`target_link_libraries` call. The
+disadvantage is that ``*Config.cmake`` files of projects that use
+imported targets from find modules may require more work to make sure
+those imported targets that are in the link interface are available.
+
+In either case (or even when providing both variables and imported
+targets), find modules should provide backwards compatibility with old
+versions that had the same name.
+
+A FindFoo.cmake module will typically be loaded by the command::
+
+ find_package(Foo [major[.minor[.patch[.tweak]]]]
+ [EXACT] [QUIET] [REQUIRED]
+ [[COMPONENTS] [components...]]
+ [OPTIONAL_COMPONENTS components...]
+ [NO_POLICY_SCOPE])
+
+See the :command:`find_package` documentation for details on what
+variables are set for the find module. Most of these are dealt with by
+using :module:`FindPackageHandleStandardArgs`.
+
+Briefly, the module should only locate versions of the package
+compatible with the requested version, as described by the
+``Foo_FIND_VERSION`` family of variables. If ``Foo_FIND_QUIETLY`` is
+set to true, it should avoid printing messages, including anything
+complaining about the package not being found. If ``Foo_FIND_REQUIRED``
+is set to true, the module should issue a ``FATAL_ERROR`` if the package
+cannot be found. If neither are set to true, it should print a
+non-fatal message if it cannot find the package.
+
+Packages that find multiple semi-independent parts (like bundles of
+libraries) should search for the components listed in
+``Foo_FIND_COMPONENTS`` if it is set , and only set ``Foo_FOUND`` to
+true if for each searched-for component ``<c>`` that was not found,
+``Foo_FIND_REQUIRED_<c>`` is not set to true. The ``HANDLE_COMPONENTS``
+argument of ``find_package_handle_standard_args()`` can be used to
+implement this.
+
+If ``Foo_FIND_COMPONENTS`` is not set, which modules are searched for
+and required is up to the find module, but should be documented.
+
+For internal implementation, it is a generally accepted convention that
+variables starting with underscore are for temporary use only.
+
+Like all modules, find modules should be properly documented. To add a
+module to the CMake documentation, follow the steps in the `Module
+Documentation`_ section above.
+
+
+
+Standard Variable Names
+^^^^^^^^^^^^^^^^^^^^^^^
+
+For a ``FindXxx.cmake`` module that takes the approach of setting
+variables (either instead of or in addition to creating imported
+targets), the following variable names should be used to keep things
+consistent between find modules. Note that all variables start with
+``Xxx_`` to make sure they do not interfere with other find modules; the
+same consideration applies to macros, functions and imported targets.
+
+``Xxx_INCLUDE_DIRS``
+ The final set of include directories listed in one variable for use by
+ client code. This should not be a cache entry.
+
+``Xxx_LIBRARIES``
+ The libraries to link against to use Xxx. These should include full
+ paths. This should not be a cache entry.
+
+``Xxx_DEFINITIONS``
+ Definitions to use when compiling code that uses Xxx. This really
+ shouldn't include options such as ``-DHAS_JPEG`` that a client
+ source-code file uses to decide whether to ``#include <jpeg.h>``
+
+``Xxx_EXECUTABLE``
+ Where to find the Xxx tool.
+
+``Xxx_Yyy_EXECUTABLE``
+ Where to find the Yyy tool that comes with Xxx.
+
+``Xxx_LIBRARY_DIRS``
+ Optionally, the final set of library directories listed in one
+ variable for use by client code. This should not be a cache entry.
+
+``Xxx_ROOT_DIR``
+ Where to find the base directory of Xxx.
+
+``Xxx_VERSION_Yy``
+ Expect Version Yy if true. Make sure at most one of these is ever true.
+
+``Xxx_WRAP_Yy``
+ 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.
+
+``Xxx_FOUND``
+ Set to false, or undefined, if we haven't found, or don't want to use
+ Xxx.
+
+``Xxx_NOT_FOUND_MESSAGE``
+ Should be set by config-files in the case that it has set
+ ``Xxx_FOUND`` to FALSE. The contained message will be printed by the
+ :command:`find_package` command and by
+ ``find_package_handle_standard_args()`` to inform the user about the
+ problem.
+
+``Xxx_RUNTIME_LIBRARY_DIRS``
+ Optionally, the runtime library search path for use when running an
+ executable linked to shared libraries. The list should be used by
+ user code to create the ``PATH`` on windows or ``LD_LIBRARY_PATH`` on
+ UNIX. This should not be a cache entry.
+
+``Xxx_VERSION``
+ The full version string of the package found, if any. Note that many
+ existing modules provide ``Xxx_VERSION_STRING`` instead.
+
+``Xxx_VERSION_MAJOR``
+ The major version of the package found, if any.
+
+``Xxx_VERSION_MINOR``
+ The minor version of the package found, if any.
+
+``Xxx_VERSION_PATCH``
+ The patch version of the package found, if any.
+
+The following names should not usually be used in CMakeLists.txt files, but
+are typically cache variables for users to edit and control the
+behaviour of find modules (like entering the path to a library manually)
+
+``Xxx_LIBRARY``
+ The path of the Xxx library (as used with :command:`find_library`, for
+ example).
+
+``Xxx_Yy_LIBRARY``
+ The path of the Yy library that is part of the Xxx system. It may or
+ may not be required to use Xxx.
+
+``Xxx_INCLUDE_DIR``
+ Where to find headers for using the Xxx library.
+
+``Xxx_Yy_INCLUDE_DIR``
+ Where to find headers for using the Yy library of the Xxx system.
+
+To prevent users being overwhelmed with settings to configure, try to
+keep as many options as possible out of the cache, leaving at least one
+option which can be used to disable use of the module, or locate a
+not-found library (e.g. ``Xxx_ROOT_DIR``). For the same reason, mark
+most cache options as advanced.
+
+While these are the standard variable names, you should provide
+backwards compatibility for any old names that were actually in use.
+Make sure you comment them as deprecated, so that no-one starts using
+them.
+
+
+
+A Sample Find Module
+^^^^^^^^^^^^^^^^^^^^
+
+We will describe how to create a simple find module for a library
+``Foo``.
+
+The first thing that is needed is documentation. CMake's documentation
+system requires you to start the file with a documentation marker and
+the name of the module. You should follow this with a simple statement
+of what the module does.
+
+.. code-block:: cmake
+
+ #.rst:
+ # FindFoo
+ # -------
+ #
+ # Finds the Foo library
+ #
+
+More description may be required for some packages. If there are
+caveats or other details users of the module should be aware of, you can
+add further paragraphs below this. Then you need to document what
+variables and imported targets are set by the module, such as
+
+.. code-block:: cmake
+
+ # This will define the following variables::
+ #
+ # Foo_FOUND - True if the system has the Foo library
+ # Foo_VERSION - The version of the Foo library which was found
+ #
+ # and the following imported targets::
+ #
+ # Foo::Foo - The Foo library
+
+If the package provides any macros, they should be listed here, but can
+be documented where they are defined. See the `Module
+Documentation`_ section above for more details.
+
+After the documentation, leave a blank line, and then add a copyright and
+licence notice block
+
+.. code-block:: cmake
+
+ #=============================================================================
+ # Copyright 2009-2011 Your Name
+ #
+ # 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.)
+
+If the module is new to CMake, you may want to provide a warning for
+projects that do not require a high enough CMake version.
+
+.. code-block:: cmake
+
+ if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 3.0.0)
+ message(AUTHOR_WARNING "Your project should require at least CMake 3.0.0 to use FindFoo.cmake")
+ endif()
+
+Now the actual libraries and so on have to be found. The code here will
+obviously vary from module to module (dealing with that, after all, is the
+point of find modules), but there tends to be a common pattern for libraries.
+
+First, we try to use ``pkg-config`` to find the library. Note that we
+cannot rely on this, as it may not be available, but it provides a good
+starting point.
+
+.. code-block:: cmake
+
+ find_package(PkgConfig)
+ pkg_check_modules(PC_Foo QUIET Foo)
+
+This should define some variables starting ``PC_Foo_`` that contain the
+information from the ``Foo.pc`` file.
+
+Now we need to find the libraries and include files; we use the
+information from ``pkg-config`` to provide hints to CMake about where to
+look.
+
+.. code-block:: cmake
+
+ find_path(Foo_INCLUDE_DIR
+ NAMES foo.h
+ PATHS ${PC_Foo_INCLUDE_DIRS}
+ # if you need to put #include <Foo/foo.h> in your code, add:
+ PATH_SUFFIXES Foo
+ )
+ find_library(Foo_LIBRARY
+ NAMES foo
+ PATHS ${PC_Foo_LIBRARY_DIRS}
+ )
+
+If you have a good way of getting the version (from a header file, for
+example), you can use that information to set ``Foo_VERSION`` (although
+note that find modules have traditionally used ``Foo_VERSION_STRING``,
+so you may want to set both). Otherwise, attempt to use the information
+from ``pkg-config``
+
+.. code-block:: cmake
+
+ set(Foo_VERSION ${PC_Foo_VERSION})
+
+Now we can use :module:`FindPackageHandleStandardArgs` to do most of the
+rest of the work for us
+
+.. code-block:: cmake
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(Foo
+ FOUND_VAR Foo_FOUND
+ REQUIRED_VARS
+ Foo_LIBRARY
+ Foo_INCLUDE_DIR
+ VERSION_VAR Foo_VERSION
+ )
+
+This will check that the ``REQUIRED_VARS`` contain values (that do not
+end in ``-NOTFOUND``) and set ``Foo_FOUND`` appropriately. It will also
+cache those values. If ``Foo_VERSION`` is set, and a required version
+was passed to :command:`find_package`, it will check the requested version
+against the one in ``Foo_VERSION``. It will also print messages as
+appropriate; note that if the package was found, it will print the
+contents of the first required variable to indicate where it was found.
+
+At this point, we have to provide a way for users of the find module to
+link to the library or libraries that were found. There are two
+approaches, as discussed in the `Find Modules`_ section above. The
+traditional variable approach looks like
+
+.. code-block:: cmake
+
+ if(Foo_FOUND)
+ set(Foo_LIBRARIES ${Foo_LIBRARY})
+ set(Foo_INCLUDE_DIRS ${Foo_INCLUDE_DIR})
+ set(Foo_DEFINITIONS ${PC_Foo_CFLAGS_OTHER})
+ endif()
+
+If more than one library was found, all of them should be included in
+these variables (see the `Standard Variable Names`_ section for more
+information).
+
+When providing imported targets, these should be namespaced (hence the
+``Foo::`` prefix); CMake will recognize that values passed to
+:command:`target_link_libraries` that contain ``::`` in their name are
+supposed to be imported targets (rather than just library names), and
+will produce appropriate diagnostic messages if that target does not
+exist (see policy :policy:`CMP0028`).
+
+.. code-block:: cmake
+
+ if(Foo_FOUND AND NOT TARGET Foo::Foo)
+ add_library(Foo::Foo UNKNOWN IMPORTED)
+ set_target_properties(Foo::Foo PROPERTIES
+ IMPORTED_LOCATION "${Foo_LIBRARY}"
+ INTERFACE_COMPILE_OPTIONS "${PC_Foo_CFLAGS_OTHER}"
+ INTERFACE_INCLUDE_DIRECTORIES "${Foo_INCLUDE_DIR}"
+ )
+ endif()
+
+One thing to note about this is that the ``INTERFACE_INCLUDE_DIRECTORIES`` and
+similar properties should only contain information about the target itself, and
+not any of its dependencies. Instead, those dependencies should also be
+targets, and CMake should be told that they are dependencies of this target.
+CMake will then combine all the necessary information automatically.
+
+We should also provide some information about the package, such as where to
+download it.
+
+.. code-block:: cmake
+
+ include(FeatureSummary)
+ set_package_properties(Foo PROPERTIES
+ URL "http://www.foo.example.com/"
+ DESCRIPTION "A library for doing useful things"
+ )
+
+Most of the cache variables should be hidden in the ``ccmake`` interface unless
+the user explicitly asks to edit them.
+
+.. code-block:: cmake
+
+ mark_as_advanced(
+ Foo_INCLUDE_DIR
+ Foo_LIBRARY
+ )
+
+If this module replaces an older version, you should set compatibility variables
+to cause the least disruption possible.
+
+.. code-block:: cmake
+
+ # compatibility variables
+ set(Foo_VERSION_STRING ${Foo_VERSION})
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst
new file mode 100644
index 0000000000..77259a0f37
--- /dev/null
+++ b/Help/manual/cmake-generator-expressions.7.rst
@@ -0,0 +1,226 @@
+.. cmake-manual-description: CMake Generator Expressions
+
+cmake-generator-expressions(7)
+******************************
+
+.. only:: html or latex
+
+ .. contents::
+
+Introduction
+============
+
+Generator expressions are evaluated during build system generation to produce
+information specific to each build configuration.
+
+Generator expressions are allowed in the context of many target properties,
+such as :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INCLUDE_DIRECTORIES`,
+:prop_tgt:`COMPILE_DEFINITIONS` and others. They may also be used when using
+commands to populate those properties, such as :command:`target_link_libraries`,
+:command:`target_include_directories`, :command:`target_compile_definitions`
+and others.
+
+This means that they enable conditional linking, conditional
+definitions used when compiling, and conditional include directories and
+more. The conditions may be based on the build configuration, target
+properties, platform information or any other queryable information.
+
+Logical Expressions
+===================
+
+Logical expressions are used to create conditional output. The basic
+expressions are the ``0`` and ``1`` expressions. Because other logical
+expressions evaluate to either ``0`` or ``1``, they can be composed to
+create conditional output::
+
+ $<$<CONFIG:Debug>:DEBUG_MODE>
+
+expands to ``DEBUG_MODE`` when the ``Debug`` configuration is used, and
+otherwise expands to nothing.
+
+``$<0:...>``
+ Empty string (ignores ``...``)
+``$<1:...>``
+ Content of ``...``
+``$<BOOL:...>``
+ ``1`` if the ``...`` is true, else ``0``
+``$<AND:?[,?]...>``
+ ``1`` if all ``?`` are ``1``, else ``0``
+
+ The ``?`` must always be either ``0`` or ``1`` in boolean expressions.
+
+``$<OR:?[,?]...>``
+ ``0`` if all ``?`` are ``0``, else ``1``
+``$<NOT:?>``
+ ``0`` if ``?`` is ``1``, else ``1``
+``$<STREQUAL:a,b>``
+ ``1`` if ``a`` is STREQUAL ``b``, else ``0``
+``$<EQUAL:a,b>``
+ ``1`` if ``a`` is EQUAL ``b`` in a numeric comparison, else ``0``
+``$<CONFIG:cfg>``
+ ``1`` if config is ``cfg``, else ``0``. This is a case-insensitive comparison.
+ The mapping in :prop_tgt:`MAP_IMPORTED_CONFIG_<CONFIG>` is also considered by
+ this expression when it is evaluated on a property on an :prop_tgt:`IMPORTED`
+ target.
+``$<PLATFORM_ID:comp>``
+ ``1`` if the CMake-id of the platform matches ``comp``, otherwise ``0``.
+``$<C_COMPILER_ID:comp>``
+ ``1`` if the CMake-id of the C compiler matches ``comp``, otherwise ``0``.
+``$<CXX_COMPILER_ID:comp>``
+ ``1`` if the CMake-id of the CXX compiler matches ``comp``, otherwise ``0``.
+``$<VERSION_GREATER:v1,v2>``
+ ``1`` if ``v1`` is a version greater than ``v2``, else ``0``.
+``$<VERSION_LESS:v1,v2>``
+ ``1`` if ``v1`` is a version less than ``v2``, else ``0``.
+``$<VERSION_EQUAL:v1,v2>``
+ ``1`` if ``v1`` is the same version as ``v2``, else ``0``.
+``$<C_COMPILER_VERSION:ver>``
+ ``1`` if the version of the C compiler matches ``ver``, otherwise ``0``.
+``$<CXX_COMPILER_VERSION:ver>``
+ ``1`` if the version of the CXX compiler matches ``ver``, otherwise ``0``.
+``$<TARGET_POLICY:pol>``
+ ``1`` if the policy ``pol`` was NEW when the 'head' target was created,
+ else ``0``. If the policy was not set, the warning message for the policy
+ will be emitted. This generator expression only works for a subset of
+ policies.
+``$<COMPILE_FEATURES:feature[,feature]...>``
+ ``1`` if all of the ``feature`` features are available for the 'head'
+ target, and ``0`` otherwise. If this expression is used while evaluating
+ the link implementation of a target and if any dependency transitively
+ increases the required :prop_tgt:`C_STANDARD` or :prop_tgt:`CXX_STANDARD`
+ for the 'head' target, an error is reported. See the
+ :manual:`cmake-compile-features(7)` manual for information on
+ compile features.
+
+Informational Expressions
+=========================
+
+These expressions expand to some information. The information may be used
+directly, eg::
+
+ include_directories(/usr/include/$<CXX_COMPILER_ID>/)
+
+expands to ``/usr/include/GNU/`` or ``/usr/include/Clang/`` etc, depending on
+the Id of the compiler.
+
+These expressions may also may be combined with logical expressions::
+
+ $<$<VERSION_LESS:$<CXX_COMPILER_VERSION>,4.2.0>:OLD_COMPILER>
+
+expands to ``OLD_COMPILER`` if the
+:variable:`CMAKE_CXX_COMPILER_VERSION <CMAKE_<LANG>_COMPILER_VERSION>` is less
+than 4.2.0.
+
+``$<CONFIGURATION>``
+ Configuration name. Deprecated. Use ``CONFIG`` instead.
+``$<CONFIG>``
+ Configuration name
+``$<PLATFORM_ID>``
+ The CMake-id of the platform.
+ See also the :variable:`CMAKE_SYSTEM_NAME` variable.
+``$<C_COMPILER_ID>``
+ The CMake-id of the C compiler used.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
+``$<CXX_COMPILER_ID>``
+ The CMake-id of the CXX compiler used.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
+``$<C_COMPILER_VERSION>``
+ The version of the C compiler used.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
+``$<CXX_COMPILER_VERSION>``
+ The version of the CXX compiler used.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
+``$<TARGET_FILE:tgt>``
+ Full path to main file (.exe, .so.1.2, .a) where ``tgt`` is the name of a target.
+``$<TARGET_FILE_NAME:tgt>``
+ Name of main file (.exe, .so.1.2, .a).
+``$<TARGET_FILE_DIR:tgt>``
+ Directory of main file (.exe, .so.1.2, .a).
+``$<TARGET_LINKER_FILE:tgt>``
+ File used to link (.a, .lib, .so) where ``tgt`` is the name of a target.
+``$<TARGET_LINKER_FILE_NAME:tgt>``
+ Name of file used to link (.a, .lib, .so).
+``$<TARGET_LINKER_FILE_DIR:tgt>``
+ Directory of file used to link (.a, .lib, .so).
+``$<TARGET_SONAME_FILE:tgt>``
+ File with soname (.so.3) where ``tgt`` is the name of a target.
+``$<TARGET_SONAME_FILE_NAME:tgt>``
+ Name of file with soname (.so.3).
+``$<TARGET_SONAME_FILE_DIR:tgt>``
+ Directory of with soname (.so.3).
+``$<TARGET_PDB_FILE:tgt>``
+ Full path to the linker generated program database file (.pdb)
+ where ``tgt`` is the name of a target.
+
+ See also the :prop_tgt:`PDB_NAME` and :prop_tgt:`PDB_OUTPUT_DIRECTORY`
+ target properties and their configuration specific variants
+ :prop_tgt:`PDB_NAME_<CONFIG>` and :prop_tgt:`PDB_OUTPUT_DIRECTORY_<CONFIG>`.
+``$<TARGET_PDB_FILE_NAME:tgt>``
+ Name of the linker generated program database file (.pdb).
+``$<TARGET_PDB_FILE_DIR:tgt>``
+ Directory of the linker generated program database file (.pdb).
+``$<TARGET_PROPERTY:tgt,prop>``
+ Value of the property ``prop`` on the target ``tgt``.
+
+ Note that ``tgt`` is not added as a dependency of the target this
+ expression is evaluated on.
+``$<TARGET_PROPERTY:prop>``
+ Value of the property ``prop`` on the target on which the generator
+ expression is evaluated.
+``$<INSTALL_PREFIX>``
+ Content of the install prefix when the target is exported via
+ :command:`install(EXPORT)` and empty otherwise.
+
+Output Expressions
+==================
+
+These expressions generate output, in some cases depending on an input. These
+expressions may be combined with other expressions for information or logical
+comparison::
+
+ -I$<JOIN:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>, -I>
+
+generates a string of the entries in the :prop_tgt:`INCLUDE_DIRECTORIES` target
+property with each entry preceeded by ``-I``. Note that a more-complete use
+in this situation would require first checking if the INCLUDE_DIRECTORIES
+property is non-empty::
+
+ $<$<BOOL:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>>:-I$<JOIN:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>, -I>>
+
+``$<JOIN:list,...>``
+ Joins the list with the content of ``...``
+``$<ANGLE-R>``
+ A literal ``>``. Used to compare strings which contain a ``>`` for example.
+``$<COMMA>``
+ A literal ``,``. Used to compare strings which contain a ``,`` for example.
+``$<SEMICOLON>``
+ A literal ``;``. Used to prevent list expansion on an argument with ``;``.
+``$<TARGET_NAME:...>``
+ Marks ``...`` as being the name of a target. This is required if exporting
+ targets to multiple dependent export sets. The ``...`` must be a literal
+ name of a target- it may not contain generator expressions.
+``$<LINK_ONLY:...>``
+ Content of ``...`` except when evaluated in a link interface while
+ propagating :ref:`Target Usage Requirements`, in which case it is the
+ empty string.
+ Intended for use only in an :prop_tgt:`INTERFACE_LINK_LIBRARIES` target
+ property, perhaps via the :command:`target_link_libraries` command,
+ to specify private link dependencies without other usage requirements.
+``$<INSTALL_INTERFACE:...>``
+ Content of ``...`` when the property is exported using :command:`install(EXPORT)`,
+ and empty otherwise.
+``$<BUILD_INTERFACE:...>``
+ Content of ``...`` when the property is exported using :command:`export`, or
+ when the target is used by another target in the same buildsystem. Expands to
+ the empty string otherwise.
+``$<LOWER_CASE:...>``
+ Content of ``...`` converted to lower case.
+``$<UPPER_CASE:...>``
+ Content of ``...`` converted to upper case.
+``$<MAKE_C_IDENTIFIER:...>``
+ Content of ``...`` converted to a C identifier.
+``$<TARGET_OBJECTS:objLib>``
+ List of objects resulting from build of ``objLib``. ``objLib`` must be an
+ object of type ``OBJECT_LIBRARY``. This expression may only be used in
+ the sources of :command:`add_library` and :command:`add_executable`
+ commands.
diff --git a/Help/manual/cmake-generators.7.rst b/Help/manual/cmake-generators.7.rst
new file mode 100644
index 0000000000..7f5093f0c8
--- /dev/null
+++ b/Help/manual/cmake-generators.7.rst
@@ -0,0 +1,87 @@
+.. cmake-manual-description: CMake Generators Reference
+
+cmake-generators(7)
+*******************
+
+.. only:: html or latex
+
+ .. contents::
+
+Introduction
+============
+
+A *CMake Generator* is responsible for writing the input files for
+a native build system. Exactly one of the `CMake Generators`_ must be
+selected for a build tree to determine what native build system is to
+be used. Optionally one of the `Extra Generators`_ may be selected
+as a variant of some of the `Command-Line Build Tool Generators`_ to
+produce project files for an auxiliary IDE.
+
+CMake Generators are platform-specific so each may be available only
+on certain platforms. The :manual:`cmake(1)` command-line tool ``--help``
+output lists available generators on the current platform. Use its ``-G``
+option to specify the generator for a new build tree.
+The :manual:`cmake-gui(1)` offers interactive selection of a generator
+when creating a new build tree.
+
+CMake Generators
+================
+
+Command-Line Build Tool Generators
+----------------------------------
+
+These generators support command-line build tools. In order to use them,
+one must launch CMake from a command-line prompt whose environment is
+already configured for the chosen compiler and build tool.
+
+.. toctree::
+ :maxdepth: 1
+
+ /generator/Borland Makefiles
+ /generator/MSYS Makefiles
+ /generator/MinGW Makefiles
+ /generator/NMake Makefiles
+ /generator/NMake Makefiles JOM
+ /generator/Ninja
+ /generator/Unix Makefiles
+ /generator/Watcom WMake
+
+IDE Build Tool Generators
+-------------------------
+
+These generators support Integrated Development Environment (IDE)
+project files. Since the IDEs configure their own environment
+one may launch CMake from any environment.
+
+.. toctree::
+ :maxdepth: 1
+
+ /generator/Visual Studio 6
+ /generator/Visual Studio 7
+ /generator/Visual Studio 7 .NET 2003
+ /generator/Visual Studio 8 2005
+ /generator/Visual Studio 9 2008
+ /generator/Visual Studio 10 2010
+ /generator/Visual Studio 11 2012
+ /generator/Visual Studio 12 2013
+ /generator/Visual Studio 14
+ /generator/Xcode
+
+Extra Generators
+================
+
+Some of the `CMake Generators`_ listed in the :manual:`cmake(1)`
+command-line tool ``--help`` output may have variants that specify
+an extra generator for an auxiliary IDE tool. Such generator
+names have the form ``<extra-generator> - <main-generator>``.
+The following extra generators are known to CMake.
+
+.. toctree::
+ :maxdepth: 1
+
+ /generator/CodeBlocks
+ /generator/CodeLite
+ /generator/Eclipse CDT4
+ /generator/KDevelop3
+ /generator/Kate
+ /generator/Sublime Text 2
diff --git a/Help/manual/cmake-gui.1.rst b/Help/manual/cmake-gui.1.rst
new file mode 100644
index 0000000000..032b51fda8
--- /dev/null
+++ b/Help/manual/cmake-gui.1.rst
@@ -0,0 +1,35 @@
+.. cmake-manual-description: CMake GUI Command-Line Reference
+
+cmake-gui(1)
+************
+
+Synopsis
+========
+
+.. parsed-literal::
+
+ cmake-gui [<options>]
+ cmake-gui [<options>] (<path-to-source> | <path-to-existing-build>)
+
+Description
+===========
+
+The "cmake-gui" executable is the CMake GUI. Project configuration
+settings may be specified interactively. Brief instructions are
+provided at the bottom of the window when the program is running.
+
+CMake is a cross-platform build system generator. Projects specify
+their build process with platform-independent CMake listfiles included
+in each directory of a source tree with the name CMakeLists.txt.
+Users build a project by using CMake to generate a build system for a
+native tool on their platform.
+
+Options
+=======
+
+.. include:: OPTIONS_HELP.txt
+
+See Also
+========
+
+.. include:: LINKS.txt
diff --git a/Help/manual/cmake-language.7.rst b/Help/manual/cmake-language.7.rst
new file mode 100644
index 0000000000..b83dcad4b3
--- /dev/null
+++ b/Help/manual/cmake-language.7.rst
@@ -0,0 +1,490 @@
+.. cmake-manual-description: CMake Language Reference
+
+cmake-language(7)
+*****************
+
+.. only:: html or latex
+
+ .. contents::
+
+Organization
+============
+
+CMake input files are written in the "CMake Language" in source files
+named ``CMakeLists.txt`` or ending in a ``.cmake`` file name extension.
+
+CMake Language source files in a project are organized into:
+
+* `Directories`_ (``CMakeLists.txt``),
+* `Scripts`_ (``<script>.cmake``), and
+* `Modules`_ (``<module>.cmake``).
+
+Directories
+-----------
+
+When CMake processes a project source tree, the entry point is
+a source file called ``CMakeLists.txt`` in the top-level source
+directory. This file may contain the entire build specification
+or use the :command:`add_subdirectory` command to add subdirectories
+to the build. Each subdirectory added by the command must also
+contain a ``CMakeLists.txt`` file as the entry point to that
+directory. For each source directory whose ``CMakeLists.txt`` file
+is processed CMake generates a corresponding directory in the build
+tree to act as the default working and output directory.
+
+Scripts
+-------
+
+An individual ``<script>.cmake`` source file may be processed
+in *script mode* by using the :manual:`cmake(1)` command-line tool
+with the ``-P`` option. Script mode simply runs the commands in
+the given CMake Language source file and does not generate a
+build system. It does not allow CMake commands that define build
+targets or actions.
+
+Modules
+-------
+
+CMake Language code in either `Directories`_ or `Scripts`_ may
+use the :command:`include` command to load a ``<module>.cmake``
+source file in the scope of the including context.
+See the :manual:`cmake-modules(7)` manual page for documentation
+of modules included with the CMake distribution.
+Project source trees may also provide their own modules and
+specify their location(s) in the :variable:`CMAKE_MODULE_PATH`
+variable.
+
+Syntax
+======
+
+Encoding
+--------
+
+A CMake Language source file must be written in 7-bit ASCII text
+to be portable across all supported platforms. Newlines may be
+encoded as either ``\n`` or ``\r\n`` but will be converted to ``\n``
+as input files are read.
+
+Note that the implementation is 8-bit clean so source files may
+be encoded as UTF-8 on platforms with system APIs supporting this
+encoding. Furthermore, CMake 3.0 and above allow a leading UTF-8
+`Byte-Order Mark`_ in source files.
+
+.. _`Byte-Order Mark`: http://en.wikipedia.org/wiki/Byte_order_mark
+
+Source Files
+------------
+
+A CMake Language source file consists of zero or more
+`Command Invocations`_ separated by newlines and optionally
+spaces and `Comments`_:
+
+.. productionlist::
+ file: `file_element`*
+ file_element: `command_invocation` `line_ending` |
+ : (`bracket_comment`|`space`)* `line_ending`
+ line_ending: `line_comment`? `newline`
+ space: <match '[ \t]+'>
+ newline: <match '\n'>
+
+Note that any source file line not inside `Command Arguments`_ or
+a `Bracket Comment`_ can end in a `Line Comment`_.
+
+.. _`Command Invocations`:
+
+Command Invocations
+-------------------
+
+A *command invocation* is a name followed by paren-enclosed arguments
+separated by whitespace:
+
+.. productionlist::
+ command_invocation: `space`* `identifier` `space`* '(' `arguments` ')'
+ identifier: <match '[A-Za-z_][A-Za-z0-9_]*'>
+ arguments: `argument`? `separated_arguments`*
+ separated_arguments: `separation`+ `argument`? |
+ : `separation`* '(' `arguments` ')'
+ separation: `space` | `line_ending`
+
+For example:
+
+.. code-block:: cmake
+
+ add_executable(hello world.c)
+
+Command names are case-insensitive.
+Nested unquoted parentheses in the arguments must balance.
+Each ``(`` or ``)`` is given to the command invocation as
+a literal `Unquoted Argument`_. This may be used in calls
+to the :command:`if` command to enclose conditions.
+For example:
+
+.. code-block:: cmake
+
+ if(FALSE AND (FALSE OR TRUE)) # evaluates to FALSE
+
+.. note::
+ CMake versions prior to 3.0 require command name identifiers
+ to be at least 2 characters.
+
+ CMake versions prior to 2.8.12 silently accept an `Unquoted Argument`_
+ or a `Quoted Argument`_ immediately following a `Quoted Argument`_ and
+ not separated by any whitespace. For compatibility, CMake 2.8.12 and
+ higher accept such code but produce a warning.
+
+Command Arguments
+-----------------
+
+There are three types of arguments within `Command Invocations`_:
+
+.. productionlist::
+ argument: `bracket_argument` | `quoted_argument` | `unquoted_argument`
+
+.. _`Bracket Argument`:
+
+Bracket Argument
+^^^^^^^^^^^^^^^^
+
+A *bracket argument*, inspired by `Lua`_ long bracket syntax,
+encloses content between opening and closing "brackets" of the
+same length:
+
+.. productionlist::
+ bracket_argument: `bracket_open` `bracket_content` `bracket_close`
+ bracket_open: '[' '='{len} '['
+ bracket_content: <any text not containing a `bracket_close`
+ : of the same {len} as the `bracket_open`>
+ bracket_close: ']' '='{len} ']'
+
+An opening bracket of length *len >= 0* is written ``[`` followed
+by *len* ``=`` followed by ``[`` and the corresponding closing
+bracket is written ``]`` followed by *len* ``=`` followed by ``]``.
+Brackets do not nest. A unique length may always be chosen
+for the opening and closing brackets to contain closing brackets
+of other lengths.
+
+Bracket argument content consists of all text between the opening
+and closing brackets, except that one newline immediately following
+the opening bracket, if any, is ignored. No evaluation of the
+enclosed content, such as `Escape Sequences`_ or `Variable References`_,
+is performed. A bracket argument is always given to the command
+invocation as exactly one argument.
+
+For example:
+
+.. code-block:: cmake
+
+ message([=[
+ This is the first line in a bracket argument with bracket length 1.
+ No \-escape sequences or ${variable} references are evaluated.
+ This is always one argument even though it contains a ; character.
+ The text does not end on a closing bracket of length 0 like ]].
+ It does end in a closing bracket of length 1.
+ ]=])
+
+.. note::
+ CMake versions prior to 3.0 do not support bracket arguments.
+ They interpret the opening bracket as the start of an
+ `Unquoted Argument`_.
+
+.. _`Lua`: http://www.lua.org/
+
+.. _`Quoted Argument`:
+
+Quoted Argument
+^^^^^^^^^^^^^^^
+
+A *quoted argument* encloses content between opening and closing
+double-quote characters:
+
+.. productionlist::
+ quoted_argument: '"' `quoted_element`* '"'
+ quoted_element: <any character except '\' or '"'> |
+ : `escape_sequence` |
+ : `quoted_continuation`
+ quoted_continuation: '\' `newline`
+
+Quoted argument content consists of all text between opening and
+closing quotes. Both `Escape Sequences`_ and `Variable References`_
+are evaluated. A quoted argument is always given to the command
+invocation as exactly one argument.
+
+For example:
+
+.. code-block:: cmake
+
+ message("This is a quoted argument containing multiple lines.
+ This is always one argument even though it contains a ; character.
+ Both \\-escape sequences and ${variable} references are evaluated.
+ The text does not end on an escaped double-quote like \".
+ It does end in an unescaped double quote.
+ ")
+
+The final ``\`` on any line ending in an odd number of backslashes
+is treated as a line continuation and ignored along with the
+immediately following newline character. For example:
+
+.. code-block:: cmake
+
+ message("\
+ This is the first line of a quoted argument. \
+ In fact it is the only line but since it is long \
+ the source code uses line continuation.\
+ ")
+
+.. note::
+ CMake versions prior to 3.0 do not support continuation with ``\``.
+ They report errors in quoted arguments containing lines ending in
+ an odd number of ``\`` characters.
+
+.. _`Unquoted Argument`:
+
+Unquoted Argument
+^^^^^^^^^^^^^^^^^
+
+An *unquoted argument* is not enclosed by any quoting syntax.
+It may not contain any whitespace, ``(``, ``)``, ``#``, ``"``, or ``\``
+except when escaped by a backslash:
+
+.. productionlist::
+ unquoted_argument: `unquoted_element`+ | `unquoted_legacy`
+ unquoted_element: <any character except whitespace or one of '()#"\'> |
+ : `escape_sequence`
+ unquoted_legacy: <see note in text>
+
+Unquoted argument content consists of all text in a contiguous block
+of allowed or escaped characters. Both `Escape Sequences`_ and
+`Variable References`_ are evaluated. The resulting value is divided
+in the same way `Lists`_ divide into elements. Each non-empty element
+is given to the command invocation as an argument. Therefore an
+unquoted argument may be given to a command invocation as zero or
+more arguments.
+
+For example:
+
+.. code-block:: cmake
+
+ foreach(arg
+ NoSpace
+ Escaped\ Space
+ This;Divides;Into;Five;Arguments
+ Escaped\;Semicolon
+ )
+ message("${arg}")
+ endforeach()
+
+.. note::
+ To support legacy CMake code, unquoted arguments may also contain
+ double-quoted strings (``"..."``, possibly enclosing horizontal
+ whitespace), and make-style variable references (``$(MAKEVAR)``).
+ Unescaped double-quotes must balance, may not appear at the
+ beginning of an unquoted argument, and are treated as part of the
+ content. For example, the unquoted arguments ``-Da="b c"``,
+ ``-Da=$(v)``, and ``a" "b"c"d`` are each interpreted literally.
+
+ The above "unquoted_legacy" production represents such arguments.
+ We do not recommend using legacy unquoted arguments in new code.
+ Instead use a `Quoted Argument`_ or a `Bracket Argument`_ to
+ represent the content.
+
+.. _`Escape Sequences`:
+
+Escape Sequences
+----------------
+
+An *escape sequence* is a ``\`` followed by one character:
+
+.. productionlist::
+ escape_sequence: `escape_identity` | `escape_encoded` | `escape_semicolon`
+ escape_identity: '\' <match '[^A-Za-z0-9;]'>
+ escape_encoded: '\t' | '\r' | '\n'
+ escape_semicolon: '\;'
+
+A ``\`` followed by a non-alphanumeric character simply encodes the literal
+character without interpreting it as syntax. A ``\t``, ``\r``, or ``\n``
+encodes a tab, carriage return, or newline character, respectively. A ``\;``
+outside of any `Variable References`_ encodes itself but may be used in an
+`Unquoted Argument`_ to encode the ``;`` without dividing the argument
+value on it. A ``\;`` inside `Variable References`_ encodes the literal
+``;`` character. (See also policy :policy:`CMP0053` documentation for
+historical considerations.)
+
+.. _`Variable References`:
+
+Variable References
+-------------------
+
+A *variable reference* has the form ``${variable_name}`` and is
+evaluated inside a `Quoted Argument`_ or an `Unquoted Argument`_.
+A variable reference is replaced by the value of the variable,
+or by the empty string if the variable is not set.
+Variable references can nest and are evaluated from the
+inside out, e.g. ``${outer_${inner_variable}_variable}``.
+
+Literal variable references may consist of alphanumeric characters,
+the characters ``/_.+-``, and `Escape Sequences`_. Nested references
+may be used to evaluate variables of any name. (See also policy
+:policy:`CMP0053` documentation for historical considerations.)
+
+The `Variables`_ section documents the scope of variable names
+and how their values are set.
+
+An *environment variable reference* has the form ``$ENV{VAR}`` and
+is evaluated in the same contexts as a normal variable reference.
+
+Comments
+--------
+
+A comment starts with a ``#`` character that is not inside a
+`Bracket Argument`_, `Quoted Argument`_, or escaped with ``\``
+as part of an `Unquoted Argument`_. There are two types of
+comments: a `Bracket Comment`_ and a `Line Comment`_.
+
+.. _`Bracket Comment`:
+
+Bracket Comment
+^^^^^^^^^^^^^^^
+
+A ``#`` immediately followed by a `Bracket Argument`_ forms a
+*bracket comment* consisting of the entire bracket enclosure:
+
+.. productionlist::
+ bracket_comment: '#' `bracket_argument`
+
+For example:
+
+.. code-block:: cmake
+
+ #[[This is a bracket comment.
+ It runs until the close bracket.]]
+ message("First Argument\n" #[[Bracket Comment]] "Second Argument")
+
+.. note::
+ CMake versions prior to 3.0 do not support bracket comments.
+ They interpret the opening ``#`` as the start of a `Line Comment`_.
+
+.. _`Line Comment`:
+
+Line Comment
+^^^^^^^^^^^^
+
+A ``#`` not immediately followed by a `Bracket Argument`_ forms a
+*line comment* that runs until the end of the line:
+
+.. productionlist::
+ line_comment: '#' <any text not starting in a `bracket_argument`
+ : and not containing a `newline`>
+
+For example:
+
+.. code-block:: cmake
+
+ # This is a line comment.
+ message("First Argument\n" # This is a line comment :)
+ "Second Argument") # This is a line comment.
+
+Control Structures
+==================
+
+Conditional Blocks
+------------------
+
+The :command:`if`/:command:`elseif`/:command:`else`/:command:`endif`
+commands delimit code blocks to be executed conditionally.
+
+Loops
+-----
+
+The :command:`foreach`/:command:`endforeach` and
+:command:`while`/:command:`endwhile` commands delimit code
+blocks to be executed in a loop. The :command:`break` command
+may be used inside such blocks to terminate the loop early.
+
+Command Definitions
+-------------------
+
+The :command:`macro`/:command:`endmacro`, and
+:command:`function`/:command:`endfunction` commands delimit
+code blocks to be recorded for later invocation as commands.
+
+Variables
+=========
+
+Variables are the basic unit of storage in the CMake Language.
+Their values are always of string type, though some commands may
+interpret the strings as values of other types.
+The :command:`set` and :command:`unset` commands explicitly
+set or unset a variable, but other commands have semantics
+that modify variables as well.
+Variable names are case-sensitive and may consist of almost
+any text, but we recommend sticking to names consisting only
+of alphanumeric characters plus ``_`` and ``-``.
+
+Variables have dynamic scope. Each variable "set" or "unset"
+creates a binding in the current scope:
+
+Function Scope
+ `Command Definitions`_ created by the :command:`function` command
+ create commands that, when invoked, process the recorded commands
+ in a new variable binding scope. A variable "set" or "unset"
+ binds in this scope and is visible for the current function and
+ any nested calls, but not after the function returns.
+
+Directory Scope
+ Each of the `Directories`_ in a source tree has its own variable
+ bindings. Before processing the ``CMakeLists.txt`` file for a
+ directory, CMake copies all variable bindings currently defined
+ in the parent directory, if any, to initialize the new directory
+ scope. CMake `Scripts`_, when processed with ``cmake -P``, bind
+ variables in one "directory" scope.
+
+ A variable "set" or "unset" not inside a function call binds
+ to the current directory scope.
+
+Persistent Cache
+ CMake stores a separate set of "cache" variables, or "cache entries",
+ whose values persist across multiple runs within a project build
+ tree. Cache entries have an isolated binding scope modified only
+ by explicit request, such as by the ``CACHE`` option of the
+ :command:`set` and :command:`unset` commands.
+
+When evaluating `Variable References`_, CMake first searches the
+function call stack, if any, for a binding and then falls back
+to the binding in the current directory scope, if any. If a
+"set" binding is found, its value is used. If an "unset" binding
+is found, or no binding is found, CMake then searches for a
+cache entry. If a cache entry is found, its value is used.
+Otherwise, the variable reference evaluates to an empty string.
+
+The :manual:`cmake-variables(7)` manual documents many variables
+that are provided by CMake or have meaning to CMake when set
+by project code.
+
+Lists
+=====
+
+Although all values in CMake are stored as strings, a string
+may be treated as a list in certain contexts, such as during
+evaluation of an `Unquoted Argument`_. In such contexts, a string
+is divided into list elements by splitting on ``;`` characters not
+following an unequal number of ``[`` and ``]`` characters and not
+immediately preceded by a ``\``. The sequence ``\;`` does not
+divide a value but is replaced by ``;`` in the resulting element.
+
+A list of elements is represented as a string by concatenating
+the elements separated by ``;``. For example, the :command:`set`
+command stores multiple values into the destination variable
+as a list:
+
+.. code-block:: cmake
+
+ set(srcs a.c b.c c.c) # sets "srcs" to "a.c;b.c;c.c"
+
+Lists are meant for simple use cases such as a list of source
+files and should not be used for complex data processing tasks.
+Most commands that construct lists do not escape ``;`` characters
+in list elements, thus flattening nested lists:
+
+.. code-block:: cmake
+
+ set(x a "b;c") # sets "x" to "a;b;c", not "a;b\;c"
diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst
new file mode 100644
index 0000000000..61e4bb490e
--- /dev/null
+++ b/Help/manual/cmake-modules.7.rst
@@ -0,0 +1,239 @@
+.. cmake-manual-description: CMake Modules Reference
+
+cmake-modules(7)
+****************
+
+.. only:: html or latex
+
+ .. contents::
+
+All Modules
+===========
+
+.. toctree::
+ :maxdepth: 1
+
+ /module/AddFileDependencies
+ /module/BundleUtilities
+ /module/CheckCCompilerFlag
+ /module/CheckCSourceCompiles
+ /module/CheckCSourceRuns
+ /module/CheckCXXCompilerFlag
+ /module/CheckCXXSourceCompiles
+ /module/CheckCXXSourceRuns
+ /module/CheckCXXSymbolExists
+ /module/CheckFortranFunctionExists
+ /module/CheckFortranSourceCompiles
+ /module/CheckFunctionExists
+ /module/CheckIncludeFileCXX
+ /module/CheckIncludeFile
+ /module/CheckIncludeFiles
+ /module/CheckLanguage
+ /module/CheckLibraryExists
+ /module/CheckPrototypeDefinition
+ /module/CheckStructHasMember
+ /module/CheckSymbolExists
+ /module/CheckTypeSize
+ /module/CheckVariableExists
+ /module/CMakeAddFortranSubdirectory
+ /module/CMakeBackwardCompatibilityCXX
+ /module/CMakeDependentOption
+ /module/CMakeDetermineVSServicePack
+ /module/CMakeExpandImportedTargets
+ /module/CMakeFindDependencyMacro
+ /module/CMakeFindFrameworks
+ /module/CMakeFindPackageMode
+ /module/CMakeForceCompiler
+ /module/CMakeGraphVizOptions
+ /module/CMakePackageConfigHelpers
+ /module/CMakeParseArguments
+ /module/CMakePrintHelpers
+ /module/CMakePrintSystemInformation
+ /module/CMakePushCheckState
+ /module/CMakeVerifyManifest
+ /module/CPackBundle
+ /module/CPackComponent
+ /module/CPackCygwin
+ /module/CPackDeb
+ /module/CPackDMG
+ /module/CPackIFW
+ /module/CPackNSIS
+ /module/CPackPackageMaker
+ /module/CPackRPM
+ /module/CPack
+ /module/CPackWIX
+ /module/CTest
+ /module/CTestScriptMode
+ /module/CTestUseLaunchers
+ /module/Dart
+ /module/DeployQt4
+ /module/Documentation
+ /module/ExternalData
+ /module/ExternalProject
+ /module/FeatureSummary
+ /module/FindALSA
+ /module/FindArmadillo
+ /module/FindASPELL
+ /module/FindAVIFile
+ /module/FindBISON
+ /module/FindBLAS
+ /module/FindBacktrace
+ /module/FindBoost
+ /module/FindBullet
+ /module/FindBZip2
+ /module/FindCABLE
+ /module/FindCoin3D
+ /module/FindCUDA
+ /module/FindCups
+ /module/FindCURL
+ /module/FindCurses
+ /module/FindCVS
+ /module/FindCxxTest
+ /module/FindCygwin
+ /module/FindDart
+ /module/FindDCMTK
+ /module/FindDevIL
+ /module/FindDoxygen
+ /module/FindEXPAT
+ /module/FindFLEX
+ /module/FindFLTK2
+ /module/FindFLTK
+ /module/FindFreetype
+ /module/FindGCCXML
+ /module/FindGDAL
+ /module/FindGettext
+ /module/FindGIF
+ /module/FindGit
+ /module/FindGLEW
+ /module/FindGLUT
+ /module/FindGnuplot
+ /module/FindGnuTLS
+ /module/FindGTest
+ /module/FindGTK2
+ /module/FindGTK
+ /module/FindHDF5
+ /module/FindHg
+ /module/FindHSPELL
+ /module/FindHTMLHelp
+ /module/FindIce
+ /module/FindIcotool
+ /module/FindImageMagick
+ /module/FindITK
+ /module/FindJasper
+ /module/FindJava
+ /module/FindJNI
+ /module/FindJPEG
+ /module/FindKDE3
+ /module/FindKDE4
+ /module/FindLAPACK
+ /module/FindLATEX
+ /module/FindLibArchive
+ /module/FindLibLZMA
+ /module/FindLibXml2
+ /module/FindLibXslt
+ /module/FindLua50
+ /module/FindLua51
+ /module/FindLua
+ /module/FindMatlab
+ /module/FindMFC
+ /module/FindMotif
+ /module/FindMPEG2
+ /module/FindMPEG
+ /module/FindMPI
+ /module/FindOpenAL
+ /module/FindOpenCL
+ /module/FindOpenGL
+ /module/FindOpenMP
+ /module/FindOpenSceneGraph
+ /module/FindOpenSSL
+ /module/FindOpenThreads
+ /module/FindosgAnimation
+ /module/FindosgDB
+ /module/Findosg_functions
+ /module/FindosgFX
+ /module/FindosgGA
+ /module/FindosgIntrospection
+ /module/FindosgManipulator
+ /module/FindosgParticle
+ /module/FindosgPresentation
+ /module/FindosgProducer
+ /module/FindosgQt
+ /module/Findosg
+ /module/FindosgShadow
+ /module/FindosgSim
+ /module/FindosgTerrain
+ /module/FindosgText
+ /module/FindosgUtil
+ /module/FindosgViewer
+ /module/FindosgVolume
+ /module/FindosgWidget
+ /module/FindPackageHandleStandardArgs
+ /module/FindPackageMessage
+ /module/FindPerlLibs
+ /module/FindPerl
+ /module/FindPHP4
+ /module/FindPhysFS
+ /module/FindPike
+ /module/FindPkgConfig
+ /module/FindPNG
+ /module/FindPostgreSQL
+ /module/FindProducer
+ /module/FindProtobuf
+ /module/FindPythonInterp
+ /module/FindPythonLibs
+ /module/FindQt3
+ /module/FindQt4
+ /module/FindQt
+ /module/FindQuickTime
+ /module/FindRTI
+ /module/FindRuby
+ /module/FindSDL_image
+ /module/FindSDL_mixer
+ /module/FindSDL_net
+ /module/FindSDL
+ /module/FindSDL_sound
+ /module/FindSDL_ttf
+ /module/FindSelfPackers
+ /module/FindSquish
+ /module/FindSubversion
+ /module/FindSWIG
+ /module/FindTCL
+ /module/FindTclsh
+ /module/FindTclStub
+ /module/FindThreads
+ /module/FindTIFF
+ /module/FindUnixCommands
+ /module/FindVTK
+ /module/FindWget
+ /module/FindWish
+ /module/FindwxWidgets
+ /module/FindwxWindows
+ /module/FindXerces
+ /module/FindX11
+ /module/FindXMLRPC
+ /module/FindZLIB
+ /module/FortranCInterface
+ /module/GenerateExportHeader
+ /module/GetPrerequisites
+ /module/GNUInstallDirs
+ /module/InstallRequiredSystemLibraries
+ /module/MacroAddFileDependencies
+ /module/ProcessorCount
+ /module/SelectLibraryConfigurations
+ /module/SquishTestScript
+ /module/TestBigEndian
+ /module/TestCXXAcceptsFlag
+ /module/TestForANSIForScope
+ /module/TestForANSIStreamHeaders
+ /module/TestForSSTREAM
+ /module/TestForSTDNamespace
+ /module/UseEcos
+ /module/UseJavaClassFilelist
+ /module/UseJava
+ /module/UseJavaSymlinks
+ /module/UsePkgConfig
+ /module/UseSWIG
+ /module/UsewxWidgets
+ /module/Use_wxWindows
+ /module/WriteBasicConfigVersionFile
+ /module/WriteCompilerDetectionHeader
diff --git a/Help/manual/cmake-packages.7.rst b/Help/manual/cmake-packages.7.rst
new file mode 100644
index 0000000000..c4cca6d053
--- /dev/null
+++ b/Help/manual/cmake-packages.7.rst
@@ -0,0 +1,634 @@
+.. cmake-manual-description: CMake Packages Reference
+
+cmake-packages(7)
+*****************
+
+.. only:: html or latex
+
+ .. contents::
+
+Introduction
+============
+
+Packages provide dependency information to CMake based buildsystems. Packages
+are found with the :command:`find_package` command. The result of
+using ``find_package`` is either a set of :prop_tgt:`IMPORTED` targets, or
+a set of variables corresponding to build-relevant information.
+
+Using Packages
+==============
+
+CMake provides direct support for two forms of packages,
+`Config-file Packages`_ and `Find-module Packages`_.
+Indirect support for ``pkg-config`` packages is also provided via
+the :module:`FindPkgConfig` module. In all cases, the basic form
+of :command:`find_package` calls is the same:
+
+.. code-block:: cmake
+
+ find_package(Qt4 4.7.0 REQUIRED) # CMake provides a Qt4 find-module
+ find_package(Qt5Core 5.1.0 REQUIRED) # Qt provides a Qt5 package config file.
+ find_package(LibXml2 REQUIRED) # Use pkg-config via the LibXml2 find-module
+
+In cases where it is known that a package configuration file is provided by
+upstream, and only that should be used, the ``CONFIG`` keyword may be passed
+to :command:`find_package`:
+
+.. code-block:: cmake
+
+ find_package(Qt5Core 5.1.0 CONFIG REQUIRED)
+ find_package(Qt5Gui 5.1.0 CONFIG)
+
+Similarly, the ``MODULE`` keyword says to use only a find-module:
+
+.. code-block:: cmake
+
+ find_package(Qt4 4.7.0 MODULE REQUIRED)
+
+Specifying the type of package explicitly improves the error message shown to
+the user if it is not found.
+
+Both types of packages also support specifying components of a package,
+either after the ``REQUIRED`` keyword:
+
+.. code-block:: cmake
+
+ find_package(Qt5 5.1.0 CONFIG REQUIRED Widgets Xml Sql)
+
+or as a separate ``COMPONENTS`` list:
+
+.. code-block:: cmake
+
+ find_package(Qt5 5.1.0 COMPONENTS Widgets Xml Sql)
+
+or as a separate ``OPTIONAL_COMPONENTS`` list:
+
+.. code-block:: cmake
+
+ find_package(Qt5 5.1.0 COMPONENTS Widgets
+ OPTIONAL_COMPONENTS Xml Sql
+ )
+
+Handling of ``COMPONENTS`` and ``OPTIONAL_COMPONENTS`` is defined by the
+package.
+
+By setting the :variable:`CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` variable to
+``TRUE``, the ``PackageName`` package will not be searched, and will always
+be ``NOTFOUND``.
+
+Config-file Packages
+--------------------
+
+A config-file package is a set of files provided by upstreams for downstreams
+to use. CMake searches in a number of locations for package configuration files, as
+described in the :command:`find_package` documentation. The most simple way for
+a CMake user to tell :manual:`cmake(1)` to search in a non-standard prefix for
+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.
+
+A set of variables which provide package status information are also set
+automatically when using a config-file package. The ``<Package>_FOUND``
+variable is set to true or false, depending on whether the package was
+found. The ``<Package>_DIR`` cache variable is set to the location of the
+package configuration file.
+
+Find-module Packages
+--------------------
+
+A find module is a file with a set of rules for finding the required pieces of
+a dependency, primarily header files and libraries. Typically, a find module
+is needed when the upstream is not built with CMake, or is not CMake-aware
+enough to otherwise provide a package configuration file. Unlike a package configuration
+file, it is not shipped with upstream, but is used by downstream to find the
+files by guessing locations of files with platform-specific hints.
+
+Unlike the case of an upstream-provided package configuration file, no single point
+of reference identifies the package as being found, so the ``<Package>_FOUND``
+variable is not automatically set by the :command:`find_package` command. It
+can still be expected to be set by convention however and should be set by
+the author of the Find-module. Similarly there is no ``<Package>_DIR`` variable,
+but each of the artifacts such as library locations and header file locations
+provide a separate cache variable.
+
+See the :manual:`cmake-developer(7)` manual for more information about creating
+Find-module files.
+
+Package Layout
+==============
+
+A config-file package consists of a `Package Configuration File`_ and
+optionally a `Package Version File`_ provided with the project distribution.
+
+Package Configuration File
+--------------------------
+
+Consider a project ``Foo`` that installs the following files::
+
+ <prefix>/include/foo-1.2/foo.h
+ <prefix>/lib/foo-1.2/libfoo.a
+
+It may also provide a CMake package configuration file::
+
+ <prefix>/lib/cmake/foo-1.2/FooConfig.cmake
+
+with content defining :prop_tgt:`IMPORTED` targets, or defining variables, such
+as:
+
+.. code-block:: cmake
+
+ # ...
+ # (compute PREFIX relative to file location)
+ # ...
+ set(Foo_INCLUDE_DIRS ${PREFIX}/include/foo-1.2)
+ set(Foo_LIBRARIES ${PREFIX}/lib/foo-1.2/libfoo.a)
+
+If another project wishes to use ``Foo`` it need only to locate the ``FooConfig.cmake``
+file and load it to get all the information it needs about package content
+locations. Since the package configuration file is provided by the package
+installation it already knows all the file locations.
+
+The :command:`find_package` command may be used to search for the package
+configuration file. This command constructs a set of installation prefixes
+and searches under each prefix in several locations. Given the name ``Foo``,
+it looks for a file called ``FooConfig.cmake`` or ``foo-config.cmake``.
+The full set of locations is specified in the :command:`find_package` command
+documentation. One place it looks is::
+
+ <prefix>/lib/cmake/Foo*/
+
+where ``Foo*`` is a case-insensitive globbing expression. In our example the
+globbing expression will match ``<prefix>/lib/cmake/foo-1.2`` and the package
+configuration file will be found.
+
+Once found, a package configuration file is immediately loaded. It, together
+with a package version file, contains all the information the project needs to
+use the package.
+
+Package Version File
+--------------------
+
+When the :command:`find_package` command finds a candidate package configuration
+file it looks next to it for a version file. The version file is loaded to test
+whether the package version is an acceptable match for the version requested.
+If the version file claims compatibility the configuration file is accepted.
+Otherwise it is ignored.
+
+The name of the package version file must match that of the package configuration
+file but has either ``-version`` or ``Version`` appended to the name before
+the ``.cmake`` extension. For example, the files::
+
+ <prefix>/lib/cmake/foo-1.3/foo-config.cmake
+ <prefix>/lib/cmake/foo-1.3/foo-config-version.cmake
+
+and::
+
+ <prefix>/lib/cmake/bar-4.2/BarConfig.cmake
+ <prefix>/lib/cmake/bar-4.2/BarConfigVersion.cmake
+
+are each pairs of package configuration files and corresponding package version
+files.
+
+When the :command:`find_package` command loads a version file it first sets the
+following variables:
+
+``PACKAGE_FIND_NAME``
+ The <package> name
+
+``PACKAGE_FIND_VERSION``
+ Full requested version string
+
+``PACKAGE_FIND_VERSION_MAJOR``
+ Major version if requested, else 0
+
+``PACKAGE_FIND_VERSION_MINOR``
+ Minor version if requested, else 0
+
+``PACKAGE_FIND_VERSION_PATCH``
+ Patch version if requested, else 0
+
+``PACKAGE_FIND_VERSION_TWEAK``
+ Tweak version if requested, else 0
+
+``PACKAGE_FIND_VERSION_COUNT``
+ Number of version components, 0 to 4
+
+The version file must use these variables to check whether it is compatible or
+an exact match for the requested version and set the following variables with
+results:
+
+``PACKAGE_VERSION``
+ Full provided version string
+
+``PACKAGE_VERSION_EXACT``
+ True if version is exact match
+
+``PACKAGE_VERSION_COMPATIBLE``
+ True if version is compatible
+
+``PACKAGE_VERSION_UNSUITABLE``
+ True if unsuitable as any version
+
+Version files are loaded in a nested scope so they are free to set any variables
+they wish as part of their computation. The find_package command wipes out the
+scope when the version file has completed and it has checked the output
+variables. When the version file claims to be an acceptable match for the
+requested version the find_package command sets the following variables for
+use by the project:
+
+``<package>_VERSION``
+ Full provided version string
+
+``<package>_VERSION_MAJOR``
+ Major version if provided, else 0
+
+``<package>_VERSION_MINOR``
+ Minor version if provided, else 0
+
+``<package>_VERSION_PATCH``
+ Patch version if provided, else 0
+
+``<package>_VERSION_TWEAK``
+ Tweak version if provided, else 0
+
+``<package>_VERSION_COUNT``
+ Number of version components, 0 to 4
+
+The variables report the version of the package that was actually found.
+The ``<package>`` part of their name matches the argument given to the
+:command:`find_package` command.
+
+Creating Packages
+=================
+
+Usually, the upstream depends on CMake itself and can use some CMake facilities
+for creating the package files. Consider an upstream which provides a single
+shared library:
+
+.. code-block:: cmake
+
+ project(UpstreamLib)
+
+ set(CMAKE_INCLUDE_CURRENT_DIR ON)
+ set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+
+ set(Upstream_VERSION 3.4.1)
+
+ include(GenerateExportHeader)
+
+ add_library(ClimbingStats SHARED climbingstats.cpp)
+ generate_export_header(ClimbingStats)
+ set_property(TARGET ClimbingStats PROPERTY VERSION ${Upstream_VERSION})
+ set_property(TARGET ClimbingStats PROPERTY SOVERSION 3)
+ set_property(TARGET ClimbingStats PROPERTY INTERFACE_ClimbingStats_MAJOR_VERSION 3)
+ set_property(TARGET ClimbingStats APPEND PROPERTY
+ COMPATIBLE_INTERFACE_STRING ClimbingStats_MAJOR_VERSION
+ )
+
+ install(TARGETS ClimbingStats EXPORT ClimbingStatsTargets
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+ RUNTIME DESTINATION bin
+ INCLUDES DESTINATION include
+ )
+ install(
+ FILES
+ climbingstats.h
+ "${CMAKE_CURRENT_BINARY_DIR}/climbingstats_export.h"
+ DESTINATION
+ include
+ COMPONENT
+ Devel
+ )
+
+ include(CMakePackageConfigHelpers)
+ write_basic_package_version_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/ClimbingStats/ClimbingStatsConfigVersion.cmake"
+ VERSION ${Upstream_VERSION}
+ COMPATIBILITY AnyNewerVersion
+ )
+
+ export(EXPORT ClimbingStatsTargets
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/ClimbingStats/ClimbingStatsTargets.cmake"
+ NAMESPACE Upstream::
+ )
+ configure_file(cmake/ClimbingStatsConfig.cmake
+ "${CMAKE_CURRENT_BINARY_DIR}/ClimbingStats/ClimbingStatsConfig.cmake"
+ COPY_ONLY
+ )
+
+ set(ConfigPackageLocation lib/cmake/ClimbingStats)
+ install(EXPORT ClimbingStatsTargets
+ FILE
+ ClimbingStatsTargets.cmake
+ NAMESPACE
+ Upstream::
+ DESTINATION
+ ${ConfigPackageLocation}
+ )
+ install(
+ FILES
+ cmake/ClimbingStatsConfig.cmake
+ "${CMAKE_CURRENT_BINARY_DIR}/ClimbingStats/ClimbingStatsConfigVersion.cmake"
+ DESTINATION
+ ${ConfigPackageLocation}
+ COMPONENT
+ Devel
+ )
+
+The :module:`CMakePackageConfigHelpers` module provides a macro for creating
+a simple ``ConfigVersion.cmake`` file. This file sets the version of the
+package. It is read by CMake when :command:`find_package` is called to
+determine the compatibility with the requested version, and to set some
+version-specific variables ``<Package>_VERSION``, ``<Package>_VERSION_MAJOR``,
+``<Package>_VERSION_MINOR`` etc. The :command:`install(EXPORT)` command is
+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
+``lib/cmake/ClimbingStats``. The generated ``ClimbingStatsConfigVersion.cmake``
+and a ``cmake/ClimbingStatsConfig.cmake`` are installed to the same location,
+completing the package.
+
+The generated :prop_tgt:`IMPORTED` targets have appropriate properties set
+to define their usage requirements, such as
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`,
+:prop_tgt:`INTERFACE_COMPILE_DEFINITIONS` and other relevant built-in
+``INTERFACE_`` properties. The ``INTERFACE`` variant of user-defined
+properties listed in :prop_tgt:`COMPATIBLE_INTERFACE_STRING` and
+other :ref:`Compatible Interface Properties` are also propagated to the
+generated :prop_tgt:`IMPORTED` targets. In the above case,
+``ClimbingStats_MAJOR_VERSION`` is defined as a string which must be
+compatible among the dependencies of any depender. By setting this custom
+defined user property in this version and in the next version of
+``ClimbingStats``, :manual:`cmake(1)` will issue a diagnostic if there is an
+attempt to use version 3 together with version 4. Packages can choose to
+employ such a pattern if different major versions of the package are designed
+to be incompatible.
+
+A ``NAMESPACE`` with double-colons is specified when exporting the targets
+for installation. This convention of double-colons gives CMake a hint that
+the name is an :prop_tgt:`IMPORTED` target when it is used by downstreams
+with the :command:`target_link_libraries` command. This way, CMake can
+issue a diagnostic if the package providing it has not yet been found.
+
+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
+that property.
+
+In this case, the ``ClimbingStatsConfig.cmake`` file could be as simple as:
+
+.. code-block:: cmake
+
+ include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake")
+
+As this allows downstreams to use the ``IMPORTED`` targets. If any macros
+should be provided by the ``ClimbingStats`` package, they should
+be in a separate file which is installed to the same location as the
+``ClimbingStatsConfig.cmake`` file, and included from there.
+
+Packages created by :command:`install(EXPORT)` are designed to be relocatable,
+using paths relative to the location of the package itself. When defining
+the interface of a target for ``EXPORT``, keep in mind that the include
+directories should be specified as relative paths which are relative to the
+:variable:`CMAKE_INSTALL_PREFIX`:
+
+.. code-block:: cmake
+
+ target_include_directories(tgt INTERFACE
+ # Wrong, not relocatable:
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/TgtName>
+ )
+
+ target_include_directories(tgt INTERFACE
+ # Ok, relocatable:
+ $<INSTALL_INTERFACE:include/TgtName>
+ )
+
+The ``$<INSTALL_PREFIX>``
+:manual:`generator expression <cmake-generator-expressions(7)>` may be used as
+a placeholder for the install prefix without resulting in a non-relocatable
+package. This is necessary if complex generator expressions are used:
+
+.. code-block:: cmake
+
+ target_include_directories(tgt INTERFACE
+ # Ok, relocatable:
+ $<INSTALL_INTERFACE:$<$<CONFIG:Debug>:$<INSTALL_PREFIX>/include/TgtName>>
+ )
+
+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
+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
+``ClimbingStats_DIR`` to ``<build_dir>/ClimbingStats`` in the cache.
+
+This can also be extended to cover dependencies:
+
+.. code-block:: cmake
+
+ # ...
+ add_library(ClimbingStats SHARED climbingstats.cpp)
+ generate_export_header(ClimbingStats)
+
+ find_package(Stats 2.6.4 REQUIRED)
+ 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``
+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
+whether the package is ``REQUIRED``, or ``QUIET`` etc. All ``REQUIRED``
+dependencies of a package should be found in the ``Config.cmake`` file:
+
+.. code-block:: cmake
+
+ include(CMakeFindDependencyMacro)
+ find_dependency(Stats 2.6.4)
+
+ include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake")
+ include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsMacros.cmake")
+
+The ``find_dependency`` macro also sets ``ClimbingStats_FOUND`` to ``False`` if
+the dependency is not found, along with a diagnostic that the ``ClimbingStats``
+package can not be used without the ``Stats`` package.
+
+If ``COMPONENTS`` are specified when the downstream uses :command:`find_package`,
+they are listed in the ``<Package>_FIND_COMPONENTS`` variable. If a particular
+component is non-optional, then the ``<Package>_FIND_REQUIRED_<comp>`` will
+be true. This can be tested with logic in the package configuration file:
+
+.. code-block:: cmake
+
+ include(CMakeFindDependencyMacro)
+ find_dependency(Stats 2.6.4)
+
+ include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake")
+ include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsMacros.cmake")
+
+ set(_supported_components Plot Table)
+
+ foreach(_comp ${ClimbingStats_FIND_COMPONENTS})
+ if (NOT ";${_supported_components};" MATCHES _comp)
+ set(ClimbingStats_FOUND False)
+ set(ClimbingStats_NOTFOUND_MESSAGE "Specified unsupported component: ${_comp}")
+ endif()
+ include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStats${_comp}Targets.cmake")
+ endforeach()
+
+Here, the ``ClimbingStats_NOTFOUND_MESSAGE`` is set to a diagnosis that the package
+could not be found because an invalid component was specified. This message
+variable can be set for any case where the ``_FOUND`` variable is set to ``False``,
+and will be displayed to the user.
+
+.. _`Package Registry`:
+
+Package Registry
+================
+
+CMake provides two central locations to register packages that have
+been built or installed anywhere on a system:
+
+* `User Package Registry`_
+* `System Package Registry`_
+
+The registries are especially useful to help projects find packages in
+non-standard install locations or directly in their own build trees.
+A project may populate either the user or system registry (using its own
+means, see below) to refer to its location.
+In either case the package should store at the registered location a
+`Package Configuration File`_ (``<package>Config.cmake``) and optionally a
+`Package Version File`_ (``<package>ConfigVersion.cmake``).
+
+The :command:`find_package` command searches the two package registries
+as two of the search steps specified in its documentation. If it has
+sufficient permissions it also removes stale package registry entries
+that refer to directories that do not exist or do not contain a matching
+package configuration file.
+
+.. _`User Package Registry`:
+
+User Package Registry
+---------------------
+
+The User Package Registry is stored in a per-user location.
+The :command:`export(PACKAGE)` command may be used to register a project
+build tree in the user package registry. CMake currently provides no
+interface to add install trees to the user package registry. Installers
+must be manually taught to register their packages if desired.
+
+On Windows the user package registry is stored in the Windows registry
+under a key in ``HKEY_CURRENT_USER``.
+
+A ``<package>`` may appear under registry key::
+
+ HKEY_CURRENT_USER\Software\Kitware\CMake\Packages\<package>
+
+as a ``REG_SZ`` value, with arbitrary name, that specifies the directory
+containing the package configuration file.
+
+On UNIX platforms the user package registry is stored in the user home
+directory under ``~/.cmake/packages``. A ``<package>`` may appear under
+the directory::
+
+ ~/.cmake/packages/<package>
+
+as a file, with arbitrary name, whose content specifies the directory
+containing the package configuration file.
+
+.. _`System Package Registry`:
+
+System Package Registry
+-----------------------
+
+The System Package Registry is stored in a system-wide location.
+CMake currently provides no interface to add to the system package registry.
+Installers must be manually taught to register their packages if desired.
+
+On Windows the system package registry is stored in the Windows registry
+under a key in ``HKEY_LOCAL_MACHINE``. A ``<package>`` may appear under
+registry key::
+
+ HKEY_LOCAL_MACHINE\Software\Kitware\CMake\Packages\<package>
+
+as a ``REG_SZ`` value, with arbitrary name, that specifies the directory
+containing the package configuration file.
+
+There is no system package registry on non-Windows platforms.
+
+.. _`Disabling the Package Registry`:
+
+Disabling the Package Registry
+------------------------------
+
+In some cases using the Package Registries is not desirable. CMake
+allows to disable them using the following variables:
+
+ * :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` disables the
+ :command:`export(PACKAGE)` command.
+ * :variable:`CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY` disables the
+ User Package Registry in all the :command:`find_package` calls.
+ * :variable:`CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY` disables
+ the System Package Registry in all the :command:`find_package` calls.
+
+Package Registry Example
+------------------------
+
+A simple convention for naming package registry entries is to use content
+hashes. They are deterministic and unlikely to collide
+(:command:`export(PACKAGE)` uses this approach).
+The name of an entry referencing a specific directory is simply the content
+hash of the directory path itself.
+
+If a project arranges for package registry entries to exist, such as::
+
+ > reg query HKCU\Software\Kitware\CMake\Packages\MyPackage
+ HKEY_CURRENT_USER\Software\Kitware\CMake\Packages\MyPackage
+ 45e7d55f13b87179bb12f907c8de6fc4 REG_SZ c:/Users/Me/Work/lib/cmake/MyPackage
+ 7b4a9844f681c80ce93190d4e3185db9 REG_SZ c:/Users/Me/Work/MyPackage-build
+
+or::
+
+ $ cat ~/.cmake/packages/MyPackage/7d1fb77e07ce59a81bed093bbee945bd
+ /home/me/work/lib/cmake/MyPackage
+ $ cat ~/.cmake/packages/MyPackage/f92c1db873a1937f3100706657c63e07
+ /home/me/work/MyPackage-build
+
+then the ``CMakeLists.txt`` code:
+
+.. code-block:: cmake
+
+ find_package(MyPackage)
+
+will search the registered locations for package configuration files
+(``MyPackageConfig.cmake``). The search order among package registry
+entries for a single package is unspecified and the entry names
+(hashes in this example) have no meaning. Registered locations may
+contain package version files (``MyPackageConfigVersion.cmake``) to
+tell :command:`find_package` whether a specific location is suitable
+for the version requested.
+
+Package Registry Ownership
+--------------------------
+
+Package registry entries are individually owned by the project installations
+that they reference. A package installer is responsible for adding its own
+entry and the corresponding uninstaller is responsible for removing it.
+
+The :command:`export(PACKAGE)` command populates the user package registry
+with the location of a project build tree. Build trees tend to be deleted by
+developers and have no "uninstall" event that could trigger removal of their
+entries. In order to keep the registries clean the :command:`find_package`
+command automatically removes stale entries it encounters if it has sufficient
+permissions. CMake provides no interface to remove an entry referencing an
+existing build tree once :command:`export(PACKAGE)` has been invoked.
+However, if the project removes its package configuration file from the build
+tree then the entry referencing the location will be considered stale.
diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
new file mode 100644
index 0000000000..f1717a08cc
--- /dev/null
+++ b/Help/manual/cmake-policies.7.rst
@@ -0,0 +1,108 @@
+.. cmake-manual-description: CMake Policies Reference
+
+cmake-policies(7)
+*****************
+
+.. only:: html or latex
+
+ .. contents::
+
+Introduction
+============
+
+Policies in CMake are used to preserve backward compatible behavior
+across multiple releases. When a new policy is introduced, newer CMake
+versions will begin to warn about the backward compatible behavior. It
+is possible to disable the warning by explicitly requesting the OLD, or
+backward compatible behavior using the :command:`cmake_policy` command.
+It is also possible to request ``NEW``, or non-backward compatible behavior
+for a policy, also avoiding the warning. Each policy can also be set to
+either ``NEW`` or ``OLD`` behavior explicitly on the command line with the
+:variable:`CMAKE_POLICY_DEFAULT_CMP<NNNN>` variable.
+
+The :command:`cmake_minimum_required` command does more than report an
+error if a too-old version of CMake is used to build a project. It
+also sets all policies introduced in that CMake version or earlier to
+``NEW`` behavior. To manage policies without increasing the minimum required
+CMake version, the :command:`if(POLICY)` command may be used:
+
+.. code-block:: cmake
+
+ if(POLICY CMP0990)
+ cmake_policy(SET CMP0990 NEW)
+ endif()
+
+This has the effect of using the ``NEW`` behavior with newer CMake releases which
+users may be using and not issuing a compatibility warning.
+
+The setting of a policy is confined in some cases to not propagate to the
+parent scope. For example, if the files read by the :command:`include` command
+or the :command:`find_package` command contain a use of :command:`cmake_policy`,
+that policy setting will not affect the caller by default. Both commands accept
+an optional ``NO_POLICY_SCOPE`` keyword to control this behavior.
+
+The :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable may also be used
+to determine whether to report an error on use of deprecated macros or
+functions.
+
+All Policies
+============
+
+.. toctree::
+ :maxdepth: 1
+
+ /policy/CMP0000
+ /policy/CMP0001
+ /policy/CMP0002
+ /policy/CMP0003
+ /policy/CMP0004
+ /policy/CMP0005
+ /policy/CMP0006
+ /policy/CMP0007
+ /policy/CMP0008
+ /policy/CMP0009
+ /policy/CMP0010
+ /policy/CMP0011
+ /policy/CMP0012
+ /policy/CMP0013
+ /policy/CMP0014
+ /policy/CMP0015
+ /policy/CMP0016
+ /policy/CMP0017
+ /policy/CMP0018
+ /policy/CMP0019
+ /policy/CMP0020
+ /policy/CMP0021
+ /policy/CMP0022
+ /policy/CMP0023
+ /policy/CMP0024
+ /policy/CMP0025
+ /policy/CMP0026
+ /policy/CMP0027
+ /policy/CMP0028
+ /policy/CMP0029
+ /policy/CMP0030
+ /policy/CMP0031
+ /policy/CMP0032
+ /policy/CMP0033
+ /policy/CMP0034
+ /policy/CMP0035
+ /policy/CMP0036
+ /policy/CMP0037
+ /policy/CMP0038
+ /policy/CMP0039
+ /policy/CMP0040
+ /policy/CMP0041
+ /policy/CMP0042
+ /policy/CMP0043
+ /policy/CMP0044
+ /policy/CMP0045
+ /policy/CMP0046
+ /policy/CMP0047
+ /policy/CMP0048
+ /policy/CMP0049
+ /policy/CMP0050
+ /policy/CMP0051
+ /policy/CMP0052
+ /policy/CMP0053
+ /policy/CMP0054
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
new file mode 100644
index 0000000000..38bcd042d1
--- /dev/null
+++ b/Help/manual/cmake-properties.7.rst
@@ -0,0 +1,349 @@
+.. cmake-manual-description: CMake Properties Reference
+
+cmake-properties(7)
+*******************
+
+.. only:: html or latex
+
+ .. contents::
+
+Properties of Global Scope
+==========================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS
+ /prop_gbl/AUTOGEN_TARGETS_FOLDER
+ /prop_gbl/AUTOMOC_TARGETS_FOLDER
+ /prop_gbl/CMAKE_C_KNOWN_FEATURES
+ /prop_gbl/CMAKE_CXX_KNOWN_FEATURES
+ /prop_gbl/DEBUG_CONFIGURATIONS
+ /prop_gbl/DISABLED_FEATURES
+ /prop_gbl/ENABLED_FEATURES
+ /prop_gbl/ENABLED_LANGUAGES
+ /prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS
+ /prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING
+ /prop_gbl/GLOBAL_DEPENDS_DEBUG_MODE
+ /prop_gbl/GLOBAL_DEPENDS_NO_CYCLES
+ /prop_gbl/IN_TRY_COMPILE
+ /prop_gbl/PACKAGES_FOUND
+ /prop_gbl/PACKAGES_NOT_FOUND
+ /prop_gbl/JOB_POOLS
+ /prop_gbl/PREDEFINED_TARGETS_FOLDER
+ /prop_gbl/ECLIPSE_EXTRA_NATURES
+ /prop_gbl/REPORT_UNDEFINED_PROPERTIES
+ /prop_gbl/RULE_LAUNCH_COMPILE
+ /prop_gbl/RULE_LAUNCH_CUSTOM
+ /prop_gbl/RULE_LAUNCH_LINK
+ /prop_gbl/RULE_MESSAGES
+ /prop_gbl/TARGET_ARCHIVES_MAY_BE_SHARED_LIBS
+ /prop_gbl/TARGET_SUPPORTS_SHARED_LIBS
+ /prop_gbl/USE_FOLDERS
+
+Properties on Directories
+=========================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_dir/ADDITIONAL_MAKE_CLEAN_FILES
+ /prop_dir/CACHE_VARIABLES
+ /prop_dir/CLEAN_NO_CUSTOM
+ /prop_dir/CMAKE_CONFIGURE_DEPENDS
+ /prop_dir/COMPILE_DEFINITIONS
+ /prop_dir/COMPILE_OPTIONS
+ /prop_dir/DEFINITIONS
+ /prop_dir/EXCLUDE_FROM_ALL
+ /prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
+ /prop_dir/INCLUDE_DIRECTORIES
+ /prop_dir/INCLUDE_REGULAR_EXPRESSION
+ /prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG
+ /prop_dir/INTERPROCEDURAL_OPTIMIZATION
+ /prop_dir/LINK_DIRECTORIES
+ /prop_dir/LISTFILE_STACK
+ /prop_dir/MACROS
+ /prop_dir/PARENT_DIRECTORY
+ /prop_dir/RULE_LAUNCH_COMPILE
+ /prop_dir/RULE_LAUNCH_CUSTOM
+ /prop_dir/RULE_LAUNCH_LINK
+ /prop_dir/TEST_INCLUDE_FILE
+ /prop_dir/VARIABLES
+ /prop_dir/VS_GLOBAL_SECTION_POST_section
+ /prop_dir/VS_GLOBAL_SECTION_PRE_section
+
+Properties on Targets
+=====================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_tgt/ALIASED_TARGET
+ /prop_tgt/ANDROID_API
+ /prop_tgt/ANDROID_GUI
+ /prop_tgt/ARCHIVE_OUTPUT_DIRECTORY_CONFIG
+ /prop_tgt/ARCHIVE_OUTPUT_DIRECTORY
+ /prop_tgt/ARCHIVE_OUTPUT_NAME_CONFIG
+ /prop_tgt/ARCHIVE_OUTPUT_NAME
+ /prop_tgt/AUTOGEN_TARGET_DEPENDS
+ /prop_tgt/AUTOMOC_MOC_OPTIONS
+ /prop_tgt/AUTOMOC
+ /prop_tgt/AUTOUIC
+ /prop_tgt/AUTOUIC_OPTIONS
+ /prop_tgt/AUTORCC
+ /prop_tgt/AUTORCC_OPTIONS
+ /prop_tgt/BUILD_WITH_INSTALL_RPATH
+ /prop_tgt/BUNDLE_EXTENSION
+ /prop_tgt/BUNDLE
+ /prop_tgt/C_EXTENSIONS
+ /prop_tgt/C_STANDARD
+ /prop_tgt/C_STANDARD_REQUIRED
+ /prop_tgt/COMPATIBLE_INTERFACE_BOOL
+ /prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MAX
+ /prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MIN
+ /prop_tgt/COMPATIBLE_INTERFACE_STRING
+ /prop_tgt/COMPILE_DEFINITIONS
+ /prop_tgt/COMPILE_FEATURES
+ /prop_tgt/COMPILE_FLAGS
+ /prop_tgt/COMPILE_OPTIONS
+ /prop_tgt/COMPILE_PDB_NAME
+ /prop_tgt/COMPILE_PDB_NAME_CONFIG
+ /prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY
+ /prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG
+ /prop_tgt/CONFIG_OUTPUT_NAME
+ /prop_tgt/CONFIG_POSTFIX
+ /prop_tgt/CXX_EXTENSIONS
+ /prop_tgt/CXX_STANDARD
+ /prop_tgt/CXX_STANDARD_REQUIRED
+ /prop_tgt/DEBUG_POSTFIX
+ /prop_tgt/DEFINE_SYMBOL
+ /prop_tgt/EchoString
+ /prop_tgt/ENABLE_EXPORTS
+ /prop_tgt/EXCLUDE_FROM_ALL
+ /prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG
+ /prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD
+ /prop_tgt/EXPORT_NAME
+ /prop_tgt/FOLDER
+ /prop_tgt/Fortran_FORMAT
+ /prop_tgt/Fortran_MODULE_DIRECTORY
+ /prop_tgt/FRAMEWORK
+ /prop_tgt/GENERATOR_FILE_NAME
+ /prop_tgt/GNUtoMS
+ /prop_tgt/HAS_CXX
+ /prop_tgt/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
+ /prop_tgt/IMPORTED_CONFIGURATIONS
+ /prop_tgt/IMPORTED_IMPLIB_CONFIG
+ /prop_tgt/IMPORTED_IMPLIB
+ /prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES_CONFIG
+ /prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES
+ /prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES_CONFIG
+ /prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES
+ /prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG
+ /prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES
+ /prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY_CONFIG
+ /prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY
+ /prop_tgt/IMPORTED_LOCATION_CONFIG
+ /prop_tgt/IMPORTED_LOCATION
+ /prop_tgt/IMPORTED_NO_SONAME_CONFIG
+ /prop_tgt/IMPORTED_NO_SONAME
+ /prop_tgt/IMPORTED
+ /prop_tgt/IMPORTED_SONAME_CONFIG
+ /prop_tgt/IMPORTED_SONAME
+ /prop_tgt/IMPORT_PREFIX
+ /prop_tgt/IMPORT_SUFFIX
+ /prop_tgt/INCLUDE_DIRECTORIES
+ /prop_tgt/INSTALL_NAME_DIR
+ /prop_tgt/INSTALL_RPATH
+ /prop_tgt/INSTALL_RPATH_USE_LINK_PATH
+ /prop_tgt/INTERFACE_AUTOUIC_OPTIONS
+ /prop_tgt/INTERFACE_COMPILE_DEFINITIONS
+ /prop_tgt/INTERFACE_COMPILE_FEATURES
+ /prop_tgt/INTERFACE_COMPILE_OPTIONS
+ /prop_tgt/INTERFACE_INCLUDE_DIRECTORIES
+ /prop_tgt/INTERFACE_LINK_LIBRARIES
+ /prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE
+ /prop_tgt/INTERFACE_SOURCES
+ /prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
+ /prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG
+ /prop_tgt/INTERPROCEDURAL_OPTIMIZATION
+ /prop_tgt/JOB_POOL_COMPILE
+ /prop_tgt/JOB_POOL_LINK
+ /prop_tgt/LABELS
+ /prop_tgt/LANG_VISIBILITY_PRESET
+ /prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG
+ /prop_tgt/LIBRARY_OUTPUT_DIRECTORY
+ /prop_tgt/LIBRARY_OUTPUT_NAME_CONFIG
+ /prop_tgt/LIBRARY_OUTPUT_NAME
+ /prop_tgt/LINK_DEPENDS_NO_SHARED
+ /prop_tgt/LINK_DEPENDS
+ /prop_tgt/LINKER_LANGUAGE
+ /prop_tgt/LINK_FLAGS_CONFIG
+ /prop_tgt/LINK_FLAGS
+ /prop_tgt/LINK_INTERFACE_LIBRARIES_CONFIG
+ /prop_tgt/LINK_INTERFACE_LIBRARIES
+ /prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG
+ /prop_tgt/LINK_INTERFACE_MULTIPLICITY
+ /prop_tgt/LINK_LIBRARIES
+ /prop_tgt/LINK_SEARCH_END_STATIC
+ /prop_tgt/LINK_SEARCH_START_STATIC
+ /prop_tgt/LOCATION_CONFIG
+ /prop_tgt/LOCATION
+ /prop_tgt/MACOSX_BUNDLE_INFO_PLIST
+ /prop_tgt/MACOSX_BUNDLE
+ /prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST
+ /prop_tgt/MACOSX_RPATH
+ /prop_tgt/MAP_IMPORTED_CONFIG_CONFIG
+ /prop_tgt/NAME
+ /prop_tgt/NO_SONAME
+ /prop_tgt/NO_SYSTEM_FROM_IMPORTED
+ /prop_tgt/OSX_ARCHITECTURES_CONFIG
+ /prop_tgt/OSX_ARCHITECTURES
+ /prop_tgt/OUTPUT_NAME_CONFIG
+ /prop_tgt/OUTPUT_NAME
+ /prop_tgt/PDB_NAME_CONFIG
+ /prop_tgt/PDB_NAME
+ /prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG
+ /prop_tgt/PDB_OUTPUT_DIRECTORY
+ /prop_tgt/POSITION_INDEPENDENT_CODE
+ /prop_tgt/PREFIX
+ /prop_tgt/PRIVATE_HEADER
+ /prop_tgt/PROJECT_LABEL
+ /prop_tgt/PUBLIC_HEADER
+ /prop_tgt/RESOURCE
+ /prop_tgt/RULE_LAUNCH_COMPILE
+ /prop_tgt/RULE_LAUNCH_CUSTOM
+ /prop_tgt/RULE_LAUNCH_LINK
+ /prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG
+ /prop_tgt/RUNTIME_OUTPUT_DIRECTORY
+ /prop_tgt/RUNTIME_OUTPUT_NAME_CONFIG
+ /prop_tgt/RUNTIME_OUTPUT_NAME
+ /prop_tgt/SKIP_BUILD_RPATH
+ /prop_tgt/SOURCES
+ /prop_tgt/SOVERSION
+ /prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG
+ /prop_tgt/STATIC_LIBRARY_FLAGS
+ /prop_tgt/SUFFIX
+ /prop_tgt/TYPE
+ /prop_tgt/VERSION
+ /prop_tgt/VISIBILITY_INLINES_HIDDEN
+ /prop_tgt/VS_DOTNET_REFERENCES
+ /prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION
+ /prop_tgt/VS_GLOBAL_KEYWORD
+ /prop_tgt/VS_GLOBAL_PROJECT_TYPES
+ /prop_tgt/VS_GLOBAL_ROOTNAMESPACE
+ /prop_tgt/VS_GLOBAL_variable
+ /prop_tgt/VS_KEYWORD
+ /prop_tgt/VS_SCC_AUXPATH
+ /prop_tgt/VS_SCC_LOCALPATH
+ /prop_tgt/VS_SCC_PROJECTNAME
+ /prop_tgt/VS_SCC_PROVIDER
+ /prop_tgt/VS_WINRT_COMPONENT
+ /prop_tgt/VS_WINRT_EXTENSIONS
+ /prop_tgt/VS_WINRT_REFERENCES
+ /prop_tgt/WIN32_EXECUTABLE
+ /prop_tgt/XCODE_ATTRIBUTE_an-attribute
+
+Properties on Tests
+===================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_test/ATTACHED_FILES_ON_FAIL
+ /prop_test/ATTACHED_FILES
+ /prop_test/COST
+ /prop_test/DEPENDS
+ /prop_test/ENVIRONMENT
+ /prop_test/FAIL_REGULAR_EXPRESSION
+ /prop_test/LABELS
+ /prop_test/MEASUREMENT
+ /prop_test/PASS_REGULAR_EXPRESSION
+ /prop_test/PROCESSORS
+ /prop_test/REQUIRED_FILES
+ /prop_test/RESOURCE_LOCK
+ /prop_test/RUN_SERIAL
+ /prop_test/SKIP_RETURN_CODE
+ /prop_test/TIMEOUT
+ /prop_test/WILL_FAIL
+ /prop_test/WORKING_DIRECTORY
+
+Properties on Source Files
+==========================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_sf/ABSTRACT
+ /prop_sf/AUTOUIC_OPTIONS
+ /prop_sf/AUTORCC_OPTIONS
+ /prop_sf/COMPILE_DEFINITIONS
+ /prop_sf/COMPILE_FLAGS
+ /prop_sf/EXTERNAL_OBJECT
+ /prop_sf/Fortran_FORMAT
+ /prop_sf/GENERATED
+ /prop_sf/HEADER_FILE_ONLY
+ /prop_sf/KEEP_EXTENSION
+ /prop_sf/LABELS
+ /prop_sf/LANGUAGE
+ /prop_sf/LOCATION
+ /prop_sf/MACOSX_PACKAGE_LOCATION
+ /prop_sf/OBJECT_DEPENDS
+ /prop_sf/OBJECT_OUTPUTS
+ /prop_sf/SYMBOLIC
+ /prop_sf/VS_DEPLOYMENT_CONTENT
+ /prop_sf/VS_SHADER_TYPE
+ /prop_sf/WRAP_EXCLUDE
+ /prop_sf/XCODE_EXPLICIT_FILE_TYPE
+ /prop_sf/XCODE_LAST_KNOWN_FILE_TYPE
+
+Properties on Cache Entries
+===========================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_cache/ADVANCED
+ /prop_cache/HELPSTRING
+ /prop_cache/MODIFIED
+ /prop_cache/STRINGS
+ /prop_cache/TYPE
+ /prop_cache/VALUE
+
+Properties on Installed Files
+=============================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_inst/CPACK_NEVER_OVERWRITE.rst
+ /prop_inst/CPACK_PERMANENT.rst
+ /prop_inst/CPACK_WIX_ACL.rst
+
+
+Deprecated Properties on Directories
+=====================================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_dir/COMPILE_DEFINITIONS_CONFIG
+
+
+Deprecated Properties on Targets
+================================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_tgt/COMPILE_DEFINITIONS_CONFIG
+ /prop_tgt/POST_INSTALL_SCRIPT
+ /prop_tgt/PRE_INSTALL_SCRIPT
+
+
+Deprecated Properties on Source Files
+=====================================
+
+.. toctree::
+ :maxdepth: 1
+
+ /prop_sf/COMPILE_DEFINITIONS_CONFIG
diff --git a/Help/manual/cmake-qt.7.rst b/Help/manual/cmake-qt.7.rst
new file mode 100644
index 0000000000..fe8d62db51
--- /dev/null
+++ b/Help/manual/cmake-qt.7.rst
@@ -0,0 +1,187 @@
+.. cmake-manual-description: CMake Qt Features Reference
+
+cmake-qt(7)
+***********
+
+.. only:: html or latex
+
+ .. contents::
+
+Introduction
+============
+
+CMake can find and use Qt 4 and Qt 5 libraries. The Qt 4 libraries are found
+by the :module:`FindQt4` find-module shipped with CMake, whereas the
+Qt 5 libraries are found using "Config-file Packages" shipped with Qt 5. See
+:manual:`cmake-packages(7)` for more information about CMake packages, and
+see `the Qt cmake manual <http://qt-project.org/doc/qt-5/cmake-manual.html>`_
+for your Qt version.
+
+Qt 4 and Qt 5 may be used together in the same
+:manual:`CMake buildsystem <cmake-buildsystem(7)>`:
+
+.. code-block:: cmake
+
+ cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
+
+ project(Qt4And5)
+
+ set(CMAKE_AUTOMOC ON)
+ set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+ find_package(Qt5Widgets REQUIRED)
+ add_executable(publisher publisher.cpp)
+ target_link_libraries(publisher Qt5::Widgets Qt5::DBus)
+
+ find_package(Qt4 REQUIRED)
+ add_executable(subscriber subscriber.cpp)
+ target_link_libraries(subscriber Qt4::QtGui Qt4::QtDBus)
+
+A CMake target may not link to both Qt 4 and Qt 5. A diagnostic is issued if
+this is attempted or results from transitive target dependency evaluation.
+
+Qt Build Tools
+==============
+
+Qt relies on some bundled tools for code generation, such as ``moc`` for
+meta-object code generation, ``uic`` for widget layout and population,
+and ``rcc`` for virtual filesystem content generation. These tools may be
+automatically invoked by :manual:`cmake(1)` if the appropriate conditions
+are met. The automatic tool invocation may be used with both Qt 4 and Qt 5.
+
+The tools are executed as part of a synthesized custom target generated by
+CMake. Target dependencies may be added to that custom target by adding them
+to the :prop_tgt:`AUTOGEN_TARGET_DEPENDS` target property.
+
+AUTOMOC
+^^^^^^^
+
+The :prop_tgt:`AUTOMOC` target property controls whether :manual:`cmake(1)`
+inspects the C++ files in the target to determine if they require ``moc`` to
+be run, and to create rules to execute ``moc`` at the appropriate time.
+
+If a ``Q_OBJECT`` or ``Q_GADGET`` macro is found in a header file, ``moc``
+will be run on the file. The result will be put into a file named according
+to ``moc_<basename>.cpp``. If the macro is found in a C++ implementation
+file, the moc output will be put into a file named according to
+``<basename>.moc``, following the Qt conventions. The ``moc file`` may be
+included by the user in the C++ implementation file with a preprocessor
+``#include``. If it is not so included, it will be added to a separate file
+which is compiled into the target.
+
+The ``moc`` command line will consume the :prop_tgt:`COMPILE_DEFINITIONS` and
+:prop_tgt:`INCLUDE_DIRECTORIES` target properties from the target it is being
+invoked for, and for the appropriate build configuration.
+
+Generated ``moc_*.cpp`` and ``*.moc`` files are placed in the build directory
+so it is convenient to set the :variable:`CMAKE_INCLUDE_CURRENT_DIR`
+variable. The :prop_tgt:`AUTOMOC` target property may be pre-set for all
+following targets by setting the :variable:`CMAKE_AUTOMOC` variable. The
+:prop_tgt:`AUTOMOC_MOC_OPTIONS` target property may be populated to set
+options to pass to ``moc``. The :variable:`CMAKE_AUTOMOC_MOC_OPTIONS`
+variable may be populated to pre-set the options for all following targets.
+
+.. _`Qt AUTOUIC`:
+
+AUTOUIC
+^^^^^^^
+
+The :prop_tgt:`AUTOUIC` target property controls whether :manual:`cmake(1)`
+inspects the C++ files in the target to determine if they require ``uic`` to
+be run, and to create rules to execute ``uic`` at the appropriate time.
+
+If a preprocessor ``#include`` directive is found which matches
+``ui_<basename>.h``, and a ``<basename>.ui`` file exists, then ``uic`` will
+be executed to generate the appropriate file.
+
+Generated ``ui_*.h`` files are placed in the build directory so it is
+convenient to set the :variable:`CMAKE_INCLUDE_CURRENT_DIR` variable. The
+:prop_tgt:`AUTOUIC` target property may be pre-set for all following targets
+by setting the :variable:`CMAKE_AUTOUIC` variable. The
+:prop_tgt:`AUTOUIC_OPTIONS` target property may be populated to set options
+to pass to ``uic``. The :variable:`CMAKE_AUTOUIC_OPTIONS` variable may be
+populated to pre-set the options for all following targets. The
+:prop_sf:`AUTOUIC_OPTIONS` source file property may be set on the
+``<basename>.ui`` file to set particular options for the file. This
+overrides options from the :prop_tgt:`AUTOUIC_OPTIONS` target property.
+
+A target may populate the :prop_tgt:`INTERFACE_AUTOUIC_OPTIONS` target
+property with options that should be used when invoking ``uic``. This must be
+consistent with the :prop_tgt:`AUTOUIC_OPTIONS` target property content of the
+depender target. The :variable:`CMAKE_DEBUG_TARGET_PROPERTIES` variable may
+be used to track the origin target of such
+:prop_tgt:`INTERFACE_AUTOUIC_OPTIONS`. This means that a library which
+provides an alternative translation system for Qt may specify options which
+should be used when running ``uic``:
+
+.. code-block:: cmake
+
+ add_library(KI18n klocalizedstring.cpp)
+ target_link_libraries(KI18n Qt5::Core)
+
+ # KI18n uses the tr2i18n() function instead of tr(). That function is
+ # declared in the klocalizedstring.h header.
+ set(autouic_options
+ -tr tr2i18n
+ -include klocalizedstring.h
+ )
+
+ set_property(TARGET KI18n APPEND PROPERTY
+ INTERFACE_AUTOUIC_OPTIONS ${autouic_options}
+ )
+
+A consuming project linking to the target exported from upstream automatically
+uses appropriate options when ``uic`` is run by :prop_tgt:`AUTOUIC`, as a
+result of linking with the :prop_tgt:`IMPORTED` target:
+
+.. code-block:: cmake
+
+ set(CMAKE_AUTOUIC ON)
+ # Uses a libwidget.ui file:
+ add_library(LibWidget libwidget.cpp)
+ target_link_libraries(LibWidget
+ KF5::KI18n
+ Qt5::Widgets
+ )
+
+.. _`Qt AUTORCC`:
+
+AUTORCC
+^^^^^^^
+
+The :prop_tgt:`AUTORCC` target property controls whether :manual:`cmake(1)`
+creates rules to execute ``rcc`` at the appropriate time on source files
+which have the suffix ``.qrc``.
+
+.. code-block:: cmake
+
+ add_executable(myexe main.cpp resource_file.qrc)
+
+The :prop_tgt:`AUTORCC` target property may be pre-set for all following targets
+by setting the :variable:`CMAKE_AUTORCC` variable. The
+:prop_tgt:`AUTORCC_OPTIONS` target property may be populated to set options
+to pass to ``rcc``. The :variable:`CMAKE_AUTORCC_OPTIONS` variable may be
+populated to pre-set the options for all following targets. The
+:prop_sf:`AUTORCC_OPTIONS` source file property may be set on the
+``<name>.qrc`` file to set particular options for the file. This
+overrides options from the :prop_tgt:`AUTORCC_OPTIONS` target property.
+
+qtmain.lib on Windows
+=====================
+
+The Qt 4 and 5 :prop_tgt:`IMPORTED` targets for the QtGui libraries specify
+that the qtmain.lib static library shipped with Qt will be linked by all
+dependent executables which have the :prop_tgt:`WIN32_EXECUTABLE` enabled.
+
+To disable this behavior, enable the ``Qt5_NO_LINK_QTMAIN`` target property for
+Qt 5 based targets or ``QT4_NO_LINK_QTMAIN`` target property for Qt 4 based
+targets.
+
+.. code-block:: cmake
+
+ add_executable(myexe WIN32 main.cpp)
+ target_link_libraries(myexe Qt4::QtGui)
+
+ add_executable(myexe_no_qtmain WIN32 main_no_qtmain.cpp)
+ set_property(TARGET main_no_qtmain PROPERTY QT4_NO_LINK_QTMAIN ON)
+ target_link_libraries(main_no_qtmain Qt4::QtGui)
diff --git a/Help/manual/cmake-toolchains.7.rst b/Help/manual/cmake-toolchains.7.rst
new file mode 100644
index 0000000000..1621b5ffd6
--- /dev/null
+++ b/Help/manual/cmake-toolchains.7.rst
@@ -0,0 +1,242 @@
+.. cmake-manual-description: CMake Toolchains Reference
+
+cmake-toolchains(7)
+*******************
+
+.. only:: html or latex
+
+ .. contents::
+
+Introduction
+============
+
+CMake uses a toolchain of utilities to compile, link libraries and create
+archives, and other tasks to drive the build. The toolchain utilities available
+are determined by the languages enabled. In normal builds, CMake automatically
+determines the toolchain for host builds based on system introspection and
+defaults. In cross-compiling scenarios, a toolchain file may be specified
+with information about compiler and utility paths.
+
+Languages
+=========
+
+Languages are enabled by the :command:`project` command. Language-specific
+built-in variables, such as
+:variable:`CMAKE_CXX_COMPILER <CMAKE_<LANG>_COMPILER>`,
+:variable:`CMAKE_CXX_COMPILER_ID <CMAKE_<LANG>_COMPILER_ID>` etc are set by
+invoking the :command:`project` command. If no project command
+is in the top-level CMakeLists file, one will be implicitly generated. By default
+the enabled languages are C and CXX:
+
+.. code-block:: cmake
+
+ project(C_Only C)
+
+A special value of NONE can also be used with the :command:`project` command
+to enable no languages:
+
+.. code-block:: cmake
+
+ project(MyProject NONE)
+
+The :command:`enable_language` command can be used to enable languages after the
+:command:`project` command:
+
+.. code-block:: cmake
+
+ enable_language(CXX)
+
+When a language is enabled, CMake finds a compiler for that language, and
+determines some information, such as the vendor and version of the compiler,
+the target architecture and bitwidth, the location of corresponding utilities
+etc.
+
+The :prop_gbl:`ENABLED_LANGUAGES` global property contains the languages which
+are currently enabled.
+
+Variables and Properties
+========================
+
+Several variables relate to the language components of a toolchain which are
+enabled. :variable:`CMAKE_<LANG>_COMPILER` is the full path to the compiler used
+for ``<LANG>``. :variable:`CMAKE_<LANG>_COMPILER_ID` is the identifier used
+by CMake for the compiler and :variable:`CMAKE_<LANG>_COMPILER_VERSION` is the
+version of the compiler.
+
+The :variable:`CMAKE_<LANG>_FLAGS` variables and the configuration-specific
+equivalents contain flags that will be added to the compile command when
+compiling a file of a particular language.
+
+As the linker is invoked by the compiler driver, CMake needs a way to determine
+which compiler to use to invoke the linker. This is calculated by the
+:prop_sf:`LANGUAGE` of source files in the target, and in the case of static
+libraries, the language of the dependent libraries. The choice CMake makes may
+be overridden with the :prop_tgt:`LINKER_LANGUAGE` target property.
+
+Toolchain Features
+==================
+
+CMake provides the :command:`try_compile` command and wrapper macros such as
+:module:`CheckCXXSourceCompiles`, :module:`CheckCXXSymbolExists` and
+:module:`CheckIncludeFile` to test capability and availability of various
+toolchain features. These APIs test the toolchain in some way and cache the
+result so that the test does not have to be performed again the next time
+CMake runs.
+
+Some toolchain features have built-in handling in CMake, and do not require
+compile-tests. For example, :prop_tgt:`POSITION_INDEPENDENT_CODE` allows
+specifying that a target should be built as position-independent code, if
+the compiler supports that feature. The :prop_tgt:`<LANG>_VISIBILITY_PRESET`
+and :prop_tgt:`VISIBILITY_INLINES_HIDDEN` target properties add flags for
+hidden visibility, if supported by the compiler.
+
+.. _`Cross Compiling Toolchain`:
+
+Cross Compiling
+===============
+
+If :manual:`cmake(1)` is invoked with the command line parameter
+``-DCMAKE_TOOLCHAIN_FILE=path/to/file``, the file will be loaded early to set
+values for the compilers.
+The :variable:`CMAKE_CROSSCOMPILING` variable is set to true when CMake is
+cross-compiling.
+
+Cross Compiling for Linux
+-------------------------
+
+A typical cross-compiling toolchain for Linux has content such
+as:
+
+.. code-block:: cmake
+
+ set(CMAKE_SYSTEM_NAME Linux)
+ set(CMAKE_SYSTEM_PROCESSOR arm)
+
+ set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs)
+ set(CMAKE_STAGING_PREFIX /home/devel/stage)
+
+ set(CMAKE_C_COMPILER /home/devel/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gcc)
+ set(CMAKE_CXX_COMPILER /home/devel/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-g++)
+
+ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+
+The :variable:`CMAKE_SYSTEM_NAME` is the CMake-identifier of the target platform
+to build for.
+
+The :variable:`CMAKE_SYSTEM_PROCESSOR` is the CMake-identifier of the target architecture
+to build for.
+
+The :variable:`CMAKE_SYSROOT` is optional, and may be specified if a sysroot
+is available.
+
+The :variable:`CMAKE_STAGING_PREFIX` is also optional. It may be used to specify
+a path on the host to install to. The :variable:`CMAKE_INSTALL_PREFIX` is always
+the runtime installation location, even when cross-compiling.
+
+The :variable:`CMAKE_<LANG>_COMPILER` variables may be set to full paths, or to
+names of compilers to search for in standard locations. In cases where CMake does
+not have enough information to extract information from the compiler, the
+:module:`CMakeForceCompiler` module can be used to bypass some of the checks.
+
+CMake ``find_*`` commands will look in the sysroot, and the :variable:`CMAKE_FIND_ROOT_PATH`
+entries by default in all cases, as well as looking in the host system root prefix.
+Although this can be controlled on a case-by-case basis, when cross-compiling, it
+can be useful to exclude looking in either the host or the target for particular
+artifacts. Generally, includes, libraries and packages should be found in the
+target system prefixes, whereas executables which must be run as part of the build
+should be found only on the host and not on the target. This is the purpose of
+the ``CMAKE_FIND_ROOT_PATH_MODE_*`` variables.
+
+Cross Compiling using Clang
+---------------------------
+
+Some compilers such as Clang are inherently cross compilers.
+The :variable:`CMAKE_<LANG>_COMPILER_TARGET` can be set to pass a
+value to those supported compilers when compiling:
+
+.. code-block:: cmake
+
+ set(CMAKE_SYSTEM_NAME Linux)
+ set(CMAKE_SYSTEM_PROCESSOR arm)
+
+ set(triple arm-linux-gnueabihf)
+
+ set(CMAKE_C_COMPILER clang)
+ set(CMAKE_C_COMPILER_TARGET ${triple})
+ set(CMAKE_CXX_COMPILER clang++)
+ set(CMAKE_CXX_COMPILER_TARGET ${triple})
+
+Similarly, some compilers do not ship their own supplementary utilities
+such as linkers, but provide a way to specify the location of the external
+toolchain which will be used by the compiler driver. The
+:variable:`CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN` variable can be set in a
+toolchain file to pass the path to the compiler driver.
+
+Cross Compiling for QNX
+-----------------------
+
+As the Clang compiler the QNX QCC compile is inherently a cross compiler.
+And the :variable:`CMAKE_<LANG>_COMPILER_TARGET` can be set to pass a
+value to those supported compilers when compiling:
+
+.. code-block:: cmake
+
+ set(CMAKE_SYSTEM_NAME QNX)
+
+ set(arch gcc_ntoarmv7le)
+
+ set(CMAKE_C_COMPILER qcc)
+ set(CMAKE_C_COMPILER_TARGET ${arch})
+ set(CMAKE_CXX_COMPILER QCC)
+ set(CMAKE_CXX_COMPILER_TARGET ${arch})
+
+Cross Compiling for Windows CE
+------------------------------
+
+Cross compiling for Windows CE requires the corresponding SDK being
+installed on your system. These SDKs are usually installed under
+``C:/Program Files (x86)/Windows CE Tools/SDKs``.
+
+A toolchain file to configure a Visual Studio generator for
+Windows CE may look like this:
+
+.. code-block:: cmake
+
+ set(CMAKE_SYSTEM_NAME WindowsCE)
+
+ set(CMAKE_SYSTEM_VERSION 8.0)
+ set(CMAKE_SYSTEM_PROCESSOR arm)
+
+ set(CMAKE_GENERATOR_TOOLSET CE800) # Can be omitted for 8.0
+ set(CMAKE_GENERATOR_PLATFORM SDK_AM335X_SK_WEC2013_V310)
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` tells the generator which SDK to use.
+Further :variable:`CMAKE_SYSTEM_VERSION` tells the generator what version of
+Windows CE to use. Currently version 8.0 (Windows Embedded Compact 2013) is
+supported out of the box. Other versions may require one to set
+:variable:`CMAKE_GENERATOR_TOOLSET` to the correct value.
+
+Cross Compiling for Windows Phone
+---------------------------------
+
+A toolchain file to configure a Visual Studio generator for
+Windows Phone may look like this:
+
+.. code-block:: cmake
+
+ set(CMAKE_SYSTEM_NAME WindowsPhone)
+ set(CMAKE_SYSTEM_VERSION 8.1)
+
+Cross Compiling for Windows Store
+---------------------------------
+
+A toolchain file to configure a Visual Studio generator for
+Windows Store may look like this:
+
+.. code-block:: cmake
+
+ set(CMAKE_SYSTEM_NAME WindowsStore)
+ set(CMAKE_SYSTEM_VERSION 8.1)
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
new file mode 100644
index 0000000000..864ea6eca2
--- /dev/null
+++ b/Help/manual/cmake-variables.7.rst
@@ -0,0 +1,388 @@
+.. cmake-manual-description: CMake Variables Reference
+
+cmake-variables(7)
+******************
+
+.. only:: html or latex
+
+ .. contents::
+
+Variables that Provide Information
+==================================
+
+.. toctree::
+ :maxdepth: 1
+
+ /variable/CMAKE_ARGC
+ /variable/CMAKE_ARGV0
+ /variable/CMAKE_AR
+ /variable/CMAKE_BINARY_DIR
+ /variable/CMAKE_BUILD_TOOL
+ /variable/CMAKE_CACHEFILE_DIR
+ /variable/CMAKE_CACHE_MAJOR_VERSION
+ /variable/CMAKE_CACHE_MINOR_VERSION
+ /variable/CMAKE_CACHE_PATCH_VERSION
+ /variable/CMAKE_CFG_INTDIR
+ /variable/CMAKE_COMMAND
+ /variable/CMAKE_CROSSCOMPILING
+ /variable/CMAKE_CTEST_COMMAND
+ /variable/CMAKE_CURRENT_BINARY_DIR
+ /variable/CMAKE_CURRENT_LIST_DIR
+ /variable/CMAKE_CURRENT_LIST_FILE
+ /variable/CMAKE_CURRENT_LIST_LINE
+ /variable/CMAKE_CURRENT_SOURCE_DIR
+ /variable/CMAKE_DL_LIBS
+ /variable/CMAKE_EDIT_COMMAND
+ /variable/CMAKE_EXECUTABLE_SUFFIX
+ /variable/CMAKE_EXTRA_GENERATOR
+ /variable/CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES
+ /variable/CMAKE_GENERATOR
+ /variable/CMAKE_GENERATOR_PLATFORM
+ /variable/CMAKE_GENERATOR_TOOLSET
+ /variable/CMAKE_HOME_DIRECTORY
+ /variable/CMAKE_IMPORT_LIBRARY_PREFIX
+ /variable/CMAKE_IMPORT_LIBRARY_SUFFIX
+ /variable/CMAKE_JOB_POOL_COMPILE
+ /variable/CMAKE_JOB_POOL_LINK
+ /variable/CMAKE_LINK_LIBRARY_SUFFIX
+ /variable/CMAKE_MAJOR_VERSION
+ /variable/CMAKE_MAKE_PROGRAM
+ /variable/CMAKE_MINIMUM_REQUIRED_VERSION
+ /variable/CMAKE_MINOR_VERSION
+ /variable/CMAKE_PARENT_LIST_FILE
+ /variable/CMAKE_PATCH_VERSION
+ /variable/CMAKE_PROJECT_NAME
+ /variable/CMAKE_RANLIB
+ /variable/CMAKE_ROOT
+ /variable/CMAKE_SCRIPT_MODE_FILE
+ /variable/CMAKE_SHARED_LIBRARY_PREFIX
+ /variable/CMAKE_SHARED_LIBRARY_SUFFIX
+ /variable/CMAKE_SHARED_MODULE_PREFIX
+ /variable/CMAKE_SHARED_MODULE_SUFFIX
+ /variable/CMAKE_SIZEOF_VOID_P
+ /variable/CMAKE_SKIP_INSTALL_RULES
+ /variable/CMAKE_SKIP_RPATH
+ /variable/CMAKE_SOURCE_DIR
+ /variable/CMAKE_STANDARD_LIBRARIES
+ /variable/CMAKE_STATIC_LIBRARY_PREFIX
+ /variable/CMAKE_STATIC_LIBRARY_SUFFIX
+ /variable/CMAKE_TOOLCHAIN_FILE
+ /variable/CMAKE_TWEAK_VERSION
+ /variable/CMAKE_VERBOSE_MAKEFILE
+ /variable/CMAKE_VERSION
+ /variable/CMAKE_VS_DEVENV_COMMAND
+ /variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION
+ /variable/CMAKE_VS_MSBUILD_COMMAND
+ /variable/CMAKE_VS_MSDEV_COMMAND
+ /variable/CMAKE_VS_NsightTegra_VERSION
+ /variable/CMAKE_VS_PLATFORM_NAME
+ /variable/CMAKE_VS_PLATFORM_TOOLSET
+ /variable/CMAKE_XCODE_PLATFORM_TOOLSET
+ /variable/PROJECT_BINARY_DIR
+ /variable/PROJECT-NAME_BINARY_DIR
+ /variable/PROJECT_NAME
+ /variable/PROJECT-NAME_SOURCE_DIR
+ /variable/PROJECT-NAME_VERSION
+ /variable/PROJECT-NAME_VERSION_MAJOR
+ /variable/PROJECT-NAME_VERSION_MINOR
+ /variable/PROJECT-NAME_VERSION_PATCH
+ /variable/PROJECT-NAME_VERSION_TWEAK
+ /variable/PROJECT_SOURCE_DIR
+ /variable/PROJECT_VERSION
+ /variable/PROJECT_VERSION_MAJOR
+ /variable/PROJECT_VERSION_MINOR
+ /variable/PROJECT_VERSION_PATCH
+ /variable/PROJECT_VERSION_TWEAK
+
+Variables that Change Behavior
+==============================
+
+.. toctree::
+ :maxdepth: 1
+
+ /variable/BUILD_SHARED_LIBS
+ /variable/CMAKE_ABSOLUTE_DESTINATION_FILES
+ /variable/CMAKE_APPBUNDLE_PATH
+ /variable/CMAKE_AUTOMOC_RELAXED_MODE
+ /variable/CMAKE_BACKWARDS_COMPATIBILITY
+ /variable/CMAKE_BUILD_TYPE
+ /variable/CMAKE_COLOR_MAKEFILE
+ /variable/CMAKE_CONFIGURATION_TYPES
+ /variable/CMAKE_DEBUG_TARGET_PROPERTIES
+ /variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName
+ /variable/CMAKE_ERROR_DEPRECATED
+ /variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
+ /variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY
+ /variable/CMAKE_SYSROOT
+ /variable/CMAKE_FIND_LIBRARY_PREFIXES
+ /variable/CMAKE_FIND_LIBRARY_SUFFIXES
+ /variable/CMAKE_FIND_NO_INSTALL_PREFIX
+ /variable/CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY
+ /variable/CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY
+ /variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE
+ /variable/CMAKE_FIND_ROOT_PATH
+ /variable/CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
+ /variable/CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
+ /variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE
+ /variable/CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
+ /variable/CMAKE_FRAMEWORK_PATH
+ /variable/CMAKE_IGNORE_PATH
+ /variable/CMAKE_INCLUDE_PATH
+ /variable/CMAKE_INCLUDE_DIRECTORIES_BEFORE
+ /variable/CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE
+ /variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME
+ /variable/CMAKE_INSTALL_MESSAGE
+ /variable/CMAKE_INSTALL_PREFIX
+ /variable/CMAKE_LIBRARY_PATH
+ /variable/CMAKE_MFC_FLAG
+ /variable/CMAKE_MODULE_PATH
+ /variable/CMAKE_NOT_USING_CONFIG_FLAGS
+ /variable/CMAKE_POLICY_DEFAULT_CMPNNNN
+ /variable/CMAKE_POLICY_WARNING_CMPNNNN
+ /variable/CMAKE_PREFIX_PATH
+ /variable/CMAKE_PROGRAM_PATH
+ /variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE
+ /variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY
+ /variable/CMAKE_STAGING_PREFIX
+ /variable/CMAKE_SYSTEM_IGNORE_PATH
+ /variable/CMAKE_SYSTEM_INCLUDE_PATH
+ /variable/CMAKE_SYSTEM_LIBRARY_PATH
+ /variable/CMAKE_SYSTEM_PREFIX_PATH
+ /variable/CMAKE_SYSTEM_PROGRAM_PATH
+ /variable/CMAKE_USER_MAKE_RULES_OVERRIDE
+ /variable/CMAKE_WARN_DEPRECATED
+ /variable/CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION
+
+Variables that Describe the System
+==================================
+
+.. toctree::
+ :maxdepth: 1
+
+ /variable/APPLE
+ /variable/BORLAND
+ /variable/CMAKE_CL_64
+ /variable/CMAKE_COMPILER_2005
+ /variable/CMAKE_HOST_APPLE
+ /variable/CMAKE_HOST_SYSTEM_NAME
+ /variable/CMAKE_HOST_SYSTEM_PROCESSOR
+ /variable/CMAKE_HOST_SYSTEM
+ /variable/CMAKE_HOST_SYSTEM_VERSION
+ /variable/CMAKE_HOST_UNIX
+ /variable/CMAKE_HOST_WIN32
+ /variable/CMAKE_LIBRARY_ARCHITECTURE_REGEX
+ /variable/CMAKE_LIBRARY_ARCHITECTURE
+ /variable/CMAKE_OBJECT_PATH_MAX
+ /variable/CMAKE_SYSTEM_NAME
+ /variable/CMAKE_SYSTEM_PROCESSOR
+ /variable/CMAKE_SYSTEM
+ /variable/CMAKE_SYSTEM_VERSION
+ /variable/CYGWIN
+ /variable/ENV
+ /variable/MSVC10
+ /variable/MSVC11
+ /variable/MSVC12
+ /variable/MSVC14
+ /variable/MSVC60
+ /variable/MSVC70
+ /variable/MSVC71
+ /variable/MSVC80
+ /variable/MSVC90
+ /variable/MSVC_IDE
+ /variable/MSVC
+ /variable/MSVC_VERSION
+ /variable/UNIX
+ /variable/WIN32
+ /variable/WINCE
+ /variable/WINDOWS_PHONE
+ /variable/WINDOWS_STORE
+ /variable/XCODE_VERSION
+
+Variables that Control the Build
+================================
+
+.. toctree::
+ :maxdepth: 1
+
+ /variable/CMAKE_ANDROID_API
+ /variable/CMAKE_ANDROID_GUI
+ /variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY
+ /variable/CMAKE_AUTOMOC_MOC_OPTIONS
+ /variable/CMAKE_AUTOMOC
+ /variable/CMAKE_AUTORCC
+ /variable/CMAKE_AUTORCC_OPTIONS
+ /variable/CMAKE_AUTOUIC
+ /variable/CMAKE_AUTOUIC_OPTIONS
+ /variable/CMAKE_BUILD_WITH_INSTALL_RPATH
+ /variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY
+ /variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG
+ /variable/CMAKE_CONFIG_POSTFIX
+ /variable/CMAKE_DEBUG_POSTFIX
+ /variable/CMAKE_EXE_LINKER_FLAGS_CONFIG
+ /variable/CMAKE_EXE_LINKER_FLAGS
+ /variable/CMAKE_Fortran_FORMAT
+ /variable/CMAKE_Fortran_MODULE_DIRECTORY
+ /variable/CMAKE_GNUtoMS
+ /variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE
+ /variable/CMAKE_INCLUDE_CURRENT_DIR
+ /variable/CMAKE_INSTALL_NAME_DIR
+ /variable/CMAKE_INSTALL_RPATH
+ /variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH
+ /variable/CMAKE_LANG_VISIBILITY_PRESET
+ /variable/CMAKE_LIBRARY_OUTPUT_DIRECTORY
+ /variable/CMAKE_LIBRARY_PATH_FLAG
+ /variable/CMAKE_LINK_DEF_FILE_FLAG
+ /variable/CMAKE_LINK_DEPENDS_NO_SHARED
+ /variable/CMAKE_LINK_INTERFACE_LIBRARIES
+ /variable/CMAKE_LINK_LIBRARY_FILE_FLAG
+ /variable/CMAKE_LINK_LIBRARY_FLAG
+ /variable/CMAKE_MACOSX_BUNDLE
+ /variable/CMAKE_MACOSX_RPATH
+ /variable/CMAKE_MAP_IMPORTED_CONFIG_CONFIG
+ /variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG
+ /variable/CMAKE_MODULE_LINKER_FLAGS
+ /variable/CMAKE_NO_BUILTIN_CHRPATH
+ /variable/CMAKE_NO_SYSTEM_FROM_IMPORTED
+ /variable/CMAKE_OSX_ARCHITECTURES
+ /variable/CMAKE_OSX_DEPLOYMENT_TARGET
+ /variable/CMAKE_OSX_SYSROOT
+ /variable/CMAKE_PDB_OUTPUT_DIRECTORY
+ /variable/CMAKE_PDB_OUTPUT_DIRECTORY_CONFIG
+ /variable/CMAKE_POSITION_INDEPENDENT_CODE
+ /variable/CMAKE_RUNTIME_OUTPUT_DIRECTORY
+ /variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG
+ /variable/CMAKE_SHARED_LINKER_FLAGS
+ /variable/CMAKE_SKIP_BUILD_RPATH
+ /variable/CMAKE_SKIP_INSTALL_RPATH
+ /variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG
+ /variable/CMAKE_STATIC_LINKER_FLAGS
+ /variable/CMAKE_TRY_COMPILE_CONFIGURATION
+ /variable/CMAKE_USE_RELATIVE_PATHS
+ /variable/CMAKE_VISIBILITY_INLINES_HIDDEN
+ /variable/CMAKE_WIN32_EXECUTABLE
+ /variable/EXECUTABLE_OUTPUT_PATH
+ /variable/LIBRARY_OUTPUT_PATH
+
+Variables for Languages
+=======================
+
+.. toctree::
+ :maxdepth: 1
+
+ /variable/CMAKE_COMPILER_IS_GNULANG
+ /variable/CMAKE_C_COMPILE_FEATURES
+ /variable/CMAKE_C_EXTENSIONS
+ /variable/CMAKE_C_STANDARD
+ /variable/CMAKE_C_STANDARD_REQUIRED
+ /variable/CMAKE_CXX_COMPILE_FEATURES
+ /variable/CMAKE_CXX_EXTENSIONS
+ /variable/CMAKE_CXX_STANDARD
+ /variable/CMAKE_CXX_STANDARD_REQUIRED
+ /variable/CMAKE_Fortran_MODDIR_DEFAULT
+ /variable/CMAKE_Fortran_MODDIR_FLAG
+ /variable/CMAKE_Fortran_MODOUT_FLAG
+ /variable/CMAKE_INTERNAL_PLATFORM_ABI
+ /variable/CMAKE_LANG_ARCHIVE_APPEND
+ /variable/CMAKE_LANG_ARCHIVE_CREATE
+ /variable/CMAKE_LANG_ARCHIVE_FINISH
+ /variable/CMAKE_LANG_COMPILE_OBJECT
+ /variable/CMAKE_LANG_COMPILER_ABI
+ /variable/CMAKE_LANG_COMPILER_ID
+ /variable/CMAKE_LANG_COMPILER_LOADED
+ /variable/CMAKE_LANG_COMPILER
+ /variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN
+ /variable/CMAKE_LANG_COMPILER_TARGET
+ /variable/CMAKE_LANG_COMPILER_VERSION
+ /variable/CMAKE_LANG_CREATE_SHARED_LIBRARY
+ /variable/CMAKE_LANG_CREATE_SHARED_MODULE
+ /variable/CMAKE_LANG_CREATE_STATIC_LIBRARY
+ /variable/CMAKE_LANG_FLAGS_DEBUG
+ /variable/CMAKE_LANG_FLAGS_MINSIZEREL
+ /variable/CMAKE_LANG_FLAGS_RELEASE
+ /variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO
+ /variable/CMAKE_LANG_FLAGS
+ /variable/CMAKE_LANG_IGNORE_EXTENSIONS
+ /variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES
+ /variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES
+ /variable/CMAKE_LANG_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ /variable/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES
+ /variable/CMAKE_LANG_LIBRARY_ARCHITECTURE
+ /variable/CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES
+ /variable/CMAKE_LANG_LINKER_PREFERENCE
+ /variable/CMAKE_LANG_LINK_EXECUTABLE
+ /variable/CMAKE_LANG_OUTPUT_EXTENSION
+ /variable/CMAKE_LANG_PLATFORM_ID
+ /variable/CMAKE_LANG_SIMULATE_ID
+ /variable/CMAKE_LANG_SIMULATE_VERSION
+ /variable/CMAKE_LANG_SIZEOF_DATA_PTR
+ /variable/CMAKE_LANG_SOURCE_FILE_EXTENSIONS
+ /variable/CMAKE_USER_MAKE_RULES_OVERRIDE_LANG
+
+Variables for CTest
+===================
+
+.. toctree::
+ :maxdepth: 1
+
+ /variable/CTEST_BINARY_DIRECTORY
+ /variable/CTEST_BUILD_COMMAND
+ /variable/CTEST_BUILD_NAME
+ /variable/CTEST_BZR_COMMAND
+ /variable/CTEST_BZR_UPDATE_OPTIONS
+ /variable/CTEST_CHECKOUT_COMMAND
+ /variable/CTEST_CONFIGURATION_TYPE
+ /variable/CTEST_CONFIGURE_COMMAND
+ /variable/CTEST_COVERAGE_COMMAND
+ /variable/CTEST_COVERAGE_EXTRA_FLAGS
+ /variable/CTEST_CURL_OPTIONS
+ /variable/CTEST_CVS_CHECKOUT
+ /variable/CTEST_CVS_COMMAND
+ /variable/CTEST_CVS_UPDATE_OPTIONS
+ /variable/CTEST_DROP_LOCATION
+ /variable/CTEST_DROP_METHOD
+ /variable/CTEST_DROP_SITE
+ /variable/CTEST_DROP_SITE_CDASH
+ /variable/CTEST_DROP_SITE_PASSWORD
+ /variable/CTEST_DROP_SITE_USER
+ /variable/CTEST_GIT_COMMAND
+ /variable/CTEST_GIT_UPDATE_CUSTOM
+ /variable/CTEST_GIT_UPDATE_OPTIONS
+ /variable/CTEST_HG_COMMAND
+ /variable/CTEST_HG_UPDATE_OPTIONS
+ /variable/CTEST_MEMORYCHECK_COMMAND
+ /variable/CTEST_MEMORYCHECK_COMMAND_OPTIONS
+ /variable/CTEST_MEMORYCHECK_SANITIZER_OPTIONS
+ /variable/CTEST_MEMORYCHECK_SUPPRESSIONS_FILE
+ /variable/CTEST_MEMORYCHECK_TYPE
+ /variable/CTEST_NIGHTLY_START_TIME
+ /variable/CTEST_P4_CLIENT
+ /variable/CTEST_P4_COMMAND
+ /variable/CTEST_P4_OPTIONS
+ /variable/CTEST_P4_UPDATE_OPTIONS
+ /variable/CTEST_SCP_COMMAND
+ /variable/CTEST_SITE
+ /variable/CTEST_SOURCE_DIRECTORY
+ /variable/CTEST_SVN_COMMAND
+ /variable/CTEST_SVN_OPTIONS
+ /variable/CTEST_SVN_UPDATE_OPTIONS
+ /variable/CTEST_TEST_TIMEOUT
+ /variable/CTEST_TRIGGER_SITE
+ /variable/CTEST_UPDATE_COMMAND
+ /variable/CTEST_UPDATE_OPTIONS
+ /variable/CTEST_UPDATE_VERSION_ONLY
+ /variable/CTEST_USE_LAUNCHERS
+
+Variables for CPack
+===================
+
+.. toctree::
+ :maxdepth: 1
+
+ /variable/CPACK_ABSOLUTE_DESTINATION_FILES
+ /variable/CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY
+ /variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
+ /variable/CPACK_INCLUDE_TOPLEVEL_DIRECTORY
+ /variable/CPACK_INSTALL_SCRIPT
+ /variable/CPACK_PACKAGING_INSTALL_PREFIX
+ /variable/CPACK_SET_DESTDIR
+ /variable/CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst
new file mode 100644
index 0000000000..8dfc16ac6c
--- /dev/null
+++ b/Help/manual/cmake.1.rst
@@ -0,0 +1,162 @@
+.. cmake-manual-description: CMake Command-Line Reference
+
+cmake(1)
+********
+
+Synopsis
+========
+
+.. parsed-literal::
+
+ cmake [<options>] (<path-to-source> | <path-to-existing-build>)
+ cmake [(-D<var>=<value>)...] -P <cmake-script-file>
+ cmake --build <dir> [<options>] [-- <build-tool-options>...]
+ cmake -E <command> [<options>]
+ cmake --find-package <options>...
+
+Description
+===========
+
+The "cmake" executable is the CMake command-line interface. It may be
+used to configure projects in scripts. Project configuration settings
+may be specified on the command line with the -D option.
+
+CMake is a cross-platform build system generator. Projects specify
+their build process with platform-independent CMake listfiles included
+in each directory of a source tree with the name CMakeLists.txt.
+Users build a project by using CMake to generate a build system for a
+native tool on their platform.
+
+Options
+=======
+
+.. include:: OPTIONS_BUILD.txt
+
+``-E``
+ CMake command mode.
+
+ For true platform independence, CMake provides a list of commands
+ that can be used on all systems. Run with -E help for the usage
+ information. Commands available are: chdir, compare_files, copy,
+ copy_directory, copy_if_different, echo, echo_append, env, environment,
+ make_directory, md5sum, remove, remove_directory, rename, sleep, tar, time,
+ touch, touch_nocreate. In addition, some platform specific commands
+ are available. On Windows: delete_regv, write_regv. On
+ UNIX: create_symlink.
+
+``-L[A][H]``
+ List non-advanced cached variables.
+
+ List cache variables will run CMake and list all the variables from
+ the CMake cache that are not marked as INTERNAL or ADVANCED. This
+ will effectively display current CMake settings, which can then be
+ changed with -D option. Changing some of the variables may result
+ in more variables being created. If A is specified, then it will
+ display also advanced variables. If H is specified, it will also
+ display help for each variable.
+
+``--build <dir>``
+ Build a CMake-generated project binary tree.
+
+ This abstracts a native build tool's command-line interface with the
+ following options:
+
+ ::
+
+ <dir> = Project binary directory to be built.
+ --target <tgt> = Build <tgt> instead of default targets.
+ --config <cfg> = For multi-configuration tools, choose <cfg>.
+ --clean-first = Build target 'clean' first, then build.
+ (To clean only, use --target 'clean'.)
+ --use-stderr = Ignored. Behavior is default in CMake >= 3.0.
+ -- = Pass remaining options to the native tool.
+
+ Run cmake --build with no options for quick help.
+
+``-N``
+ View mode only.
+
+ Only load the cache. Do not actually run configure and generate
+ steps.
+
+``-P <file>``
+ Process script mode.
+
+ Process the given cmake file as a script written in the CMake
+ language. No configure or generate step is performed and the cache
+ is not modified. If variables are defined using -D, this must be
+ done before the -P argument.
+
+``--find-package``
+ Run in pkg-config like mode.
+
+ Search a package using find_package() and print the resulting flags
+ to stdout. This can be used to use cmake instead of pkg-config to
+ find installed libraries in plain Makefile-based projects or in
+ autoconf-based projects (via share/aclocal/cmake.m4).
+
+``--graphviz=[file]``
+ Generate graphviz of dependencies, see CMakeGraphVizOptions.cmake for more.
+
+ Generate a graphviz input file that will contain all the library and
+ executable dependencies in the project. See the documentation for
+ CMakeGraphVizOptions.cmake for more details.
+
+``--system-information [file]``
+ Dump information about this system.
+
+ Dump a wide range of information about the current system. If run
+ from the top of a binary tree for a CMake project it will dump
+ additional information such as the cache, log files etc.
+
+``--debug-trycompile``
+ Do not delete the try_compile build tree. Only useful on one try_compile at a time.
+
+ Do not delete the files and directories created for try_compile
+ calls. This is useful in debugging failed try_compiles. It may
+ however change the results of the try-compiles as old junk from a
+ previous try-compile may cause a different test to either pass or
+ fail incorrectly. This option is best used for one try-compile at a
+ time, and only when debugging.
+
+``--debug-output``
+ Put cmake in a debug mode.
+
+ Print extra stuff during the cmake run like stack traces with
+ message(send_error ) calls.
+
+``--trace``
+ Put cmake in trace mode.
+
+ Print a trace of all calls made and from where with
+ message(send_error ) calls.
+
+``--warn-uninitialized``
+ Warn about uninitialized values.
+
+ Print a warning when an uninitialized variable is used.
+
+``--warn-unused-vars``
+ Warn about unused variables.
+
+ Find variables that are declared or set, but not used.
+
+``--no-warn-unused-cli``
+ Don't warn about command line options.
+
+ Don't find variables that are declared on the command line, but not
+ used.
+
+``--check-system-vars``
+ Find problems with variable usage in system files.
+
+ Normally, unused and uninitialized variables are searched for only
+ in CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR. This flag tells CMake to
+ warn about other files as well.
+
+.. include:: OPTIONS_HELP.txt
+
+See Also
+========
+
+.. include:: LINKS.txt
diff --git a/Help/manual/cpack.1.rst b/Help/manual/cpack.1.rst
new file mode 100644
index 0000000000..ba2086e98a
--- /dev/null
+++ b/Help/manual/cpack.1.rst
@@ -0,0 +1,97 @@
+.. cmake-manual-description: CPack Command-Line Reference
+
+cpack(1)
+********
+
+Synopsis
+========
+
+.. parsed-literal::
+
+ cpack -G <generator> [<options>]
+
+Description
+===========
+
+The "cpack" executable is the CMake packaging program.
+CMake-generated build trees created for projects that use the
+INSTALL_* commands have packaging support. This program will generate
+the package.
+
+CMake is a cross-platform build system generator. Projects specify
+their build process with platform-independent CMake listfiles included
+in each directory of a source tree with the name CMakeLists.txt.
+Users build a project by using CMake to generate a build system for a
+native tool on their platform.
+
+Options
+=======
+
+``-G <generator>``
+ Use the specified generator to generate package.
+
+ CPack may support multiple native packaging systems on certain
+ platforms. A generator is responsible for generating input files
+ for particular system and invoking that systems. Possible generator
+ names are specified in the Generators section.
+
+``-C <Configuration>``
+ Specify the project configuration
+
+ This option specifies the configuration that the project was build
+ with, for example 'Debug', 'Release'.
+
+``-D <var>=<value>``
+ Set a CPack variable.
+
+ Set a variable that can be used by the generator.
+
+``--config <config file>``
+ Specify the config file.
+
+ Specify the config file to use to create the package. By default
+ CPackConfig.cmake in the current directory will be used.
+
+``--verbose,-V``
+ enable verbose output
+
+ Run cpack with verbose output.
+
+``--debug``
+ enable debug output (for CPack developers)
+
+ Run cpack with debug output (for CPack developers).
+
+``-P <package name>``
+ override/define CPACK_PACKAGE_NAME
+
+ If the package name is not specified on cpack commmand line
+ thenCPack.cmake defines it as CMAKE_PROJECT_NAME
+
+``-R <package version>``
+ override/define CPACK_PACKAGE_VERSION
+
+ If version is not specified on cpack command line thenCPack.cmake
+ defines it from CPACK_PACKAGE_VERSION_[MAJOR|MINOR|PATCH]look into
+ CPack.cmake for detail
+
+``-B <package directory>``
+ override/define CPACK_PACKAGE_DIRECTORY
+
+ The directory where CPack will be doing its packaging work.The
+ resulting package will be found there. Inside this directoryCPack
+ creates '_CPack_Packages' sub-directory which is theCPack temporary
+ directory.
+
+``--vendor <vendor name>``
+ override/define CPACK_PACKAGE_VENDOR
+
+ If vendor is not specified on cpack command line (or inside
+ CMakeLists.txt) thenCPack.cmake defines it with a default value
+
+.. include:: OPTIONS_HELP.txt
+
+See Also
+========
+
+.. include:: LINKS.txt
diff --git a/Help/manual/ctest.1.rst b/Help/manual/ctest.1.rst
new file mode 100644
index 0000000000..03e86af4f6
--- /dev/null
+++ b/Help/manual/ctest.1.rst
@@ -0,0 +1,993 @@
+.. cmake-manual-description: CTest Command-Line Reference
+
+ctest(1)
+********
+
+Synopsis
+========
+
+.. parsed-literal::
+
+ ctest [<options>]
+
+Description
+===========
+
+The "ctest" executable is the CMake test driver program.
+CMake-generated build trees created for projects that use the
+ENABLE_TESTING and ADD_TEST commands have testing support. This
+program will run the tests and report results.
+
+Options
+=======
+
+``-C <cfg>, --build-config <cfg>``
+ Choose configuration to test.
+
+ Some CMake-generated build trees can have multiple build
+ configurations in the same tree. This option can be used to specify
+ which one should be tested. Example configurations are "Debug" and
+ "Release".
+
+``-V,--verbose``
+ Enable verbose output from tests.
+
+ Test output is normally suppressed and only summary information is
+ displayed. This option will show all test output.
+
+``-VV,--extra-verbose``
+ Enable more verbose output from tests.
+
+ Test output is normally suppressed and only summary information is
+ displayed. This option will show even more test output.
+
+``--debug``
+ Displaying more verbose internals of CTest.
+
+ This feature will result in a large number of output that is mostly
+ useful for debugging dashboard problems.
+
+``--output-on-failure``
+ Output anything outputted by the test program if the test should fail. This option can also be enabled by setting the environment variable CTEST_OUTPUT_ON_FAILURE
+
+``-F``
+ Enable failover.
+
+ This option allows ctest to resume a test set execution that was
+ previously interrupted. If no interruption occurred, the -F option
+ will have no effect.
+
+``-j <jobs>, --parallel <jobs>``
+ Run the tests in parallel using thegiven number of jobs.
+
+ This option tells ctest to run the tests in parallel using given
+ number of jobs. This option can also be set by setting the
+ environment variable CTEST_PARALLEL_LEVEL.
+
+``-Q,--quiet``
+ Make ctest quiet.
+
+ This option will suppress all the output. The output log file will
+ still be generated if the --output-log is specified. Options such
+ as --verbose, --extra-verbose, and --debug are ignored if --quiet is
+ specified.
+
+``-O <file>, --output-log <file>``
+ Output to log file
+
+ This option tells ctest to write all its output to a log file.
+
+``-N,--show-only``
+ Disable actual execution of tests.
+
+ This option tells ctest to list the tests that would be run but not
+ actually run them. Useful in conjunction with the -R and -E
+ options.
+
+``-L <regex>, --label-regex <regex>``
+ Run tests with labels matching regular expression.
+
+ This option tells ctest to run only the tests whose labels match the
+ given regular expression.
+
+``-R <regex>, --tests-regex <regex>``
+ Run tests matching regular expression.
+
+ This option tells ctest to run only the tests whose names match the
+ given regular expression.
+
+``-E <regex>, --exclude-regex <regex>``
+ Exclude tests matching regular expression.
+
+ This option tells ctest to NOT run the tests whose names match the
+ given regular expression.
+
+``-LE <regex>, --label-exclude <regex>``
+ Exclude tests with labels matching regular expression.
+
+ This option tells ctest to NOT run the tests whose labels match the
+ given regular expression.
+
+``-D <dashboard>, --dashboard <dashboard>``
+ Execute dashboard test
+
+ This option tells ctest to act as a CDash client and perform a
+ dashboard test. All tests are <Mode><Test>, where Mode can be
+ Experimental, Nightly, and Continuous, and Test can be Start,
+ Update, Configure, Build, Test, Coverage, and Submit.
+
+``-D <var>:<type>=<value>``
+ Define a variable for script mode
+
+ Pass in variable values on the command line. Use in conjunction
+ with -S to pass variable values to a dashboard script. Parsing -D
+ arguments as variable values is only attempted if the value
+ following -D does not match any of the known dashboard types.
+
+``-M <model>, --test-model <model>``
+ Sets the model for a dashboard
+
+ This option tells ctest to act as a CDash client where the TestModel
+ can be Experimental, Nightly, and Continuous. Combining -M and -T
+ is similar to -D
+
+``-T <action>, --test-action <action>``
+ Sets the dashboard action to perform
+
+ This option tells ctest to act as a CDash client and perform some
+ action such as start, build, test etc. Combining -M and -T is
+ similar to -D
+
+``--track <track>``
+ Specify the track to submit dashboard to
+
+ Submit dashboard to specified track instead of default one. By
+ default, the dashboard is submitted to Nightly, Experimental, or
+ Continuous track, but by specifying this option, the track can be
+ arbitrary.
+
+``-S <script>, --script <script>``
+ Execute a dashboard for a configuration
+
+ This option tells ctest to load in a configuration script which sets
+ a number of parameters such as the binary and source directories.
+ Then ctest will do what is required to create and run a dashboard.
+ This option basically sets up a dashboard and then runs ctest -D
+ with the appropriate options.
+
+``-SP <script>, --script-new-process <script>``
+ Execute a dashboard for a configuration
+
+ This option does the same operations as -S but it will do them in a
+ separate process. This is primarily useful in cases where the
+ script may modify the environment and you do not want the modified
+ environment to impact other -S scripts.
+
+``-A <file>, --add-notes <file>``
+ Add a notes file with submission
+
+ This option tells ctest to include a notes file when submitting
+ dashboard.
+
+``-I [Start,End,Stride,test#,test#|Test file], --tests-information``
+ Run a specific number of tests by number.
+
+ This option causes ctest to run tests starting at number Start,
+ ending at number End, and incrementing by Stride. Any additional
+ numbers after Stride are considered individual test numbers. Start,
+ End,or stride can be empty. Optionally a file can be given that
+ contains the same syntax as the command line.
+
+``-U, --union``
+ Take the Union of -I and -R
+
+ When both -R and -I are specified by default the intersection of
+ tests are run. By specifying -U the union of tests is run instead.
+
+``--rerun-failed``
+ Run only the tests that failed previously
+
+ This option tells ctest to perform only the tests that failed during
+ its previous run. When this option is specified, ctest ignores all
+ other options intended to modify the list of tests to run (-L, -R,
+ -E, -LE, -I, etc). In the event that CTest runs and no tests fail,
+ subsequent calls to ctest with the --rerun-failed option will run
+ the set of tests that most recently failed (if any).
+
+``--max-width <width>``
+ Set the max width for a test name to output
+
+ Set the maximum width for each test name to show in the output.
+ This allows the user to widen the output to avoid clipping the test
+ name which can be very annoying.
+
+``--interactive-debug-mode [0|1]``
+ Set the interactive mode to 0 or 1.
+
+ This option causes ctest to run tests in either an interactive mode
+ or a non-interactive mode. On Windows this means that in
+ non-interactive mode, all system debug pop up windows are blocked.
+ In dashboard mode (Experimental, Nightly, Continuous), the default
+ is non-interactive. When just running tests not for a dashboard the
+ default is to allow popups and interactive debugging.
+
+``--no-label-summary``
+ Disable timing summary information for labels.
+
+ This option tells ctest not to print summary information for each
+ label associated with the tests run. If there are no labels on the
+ tests, nothing extra is printed.
+
+``--build-and-test``
+ Configure, build and run a test.
+
+ This option tells ctest to configure (i.e. run cmake on), build,
+ and or execute a test. The configure and test steps are optional.
+ The arguments to this command line are the source and binary
+ directories. By default this will run CMake on the Source/Bin
+ directories specified unless --build-nocmake is specified.
+ The --build-generator option *must* be provided to use
+ --build-and-test. If --test-command is specified then that will be
+ run after the build is complete. Other options that affect this
+ mode are --build-target --build-nocmake, --build-run-dir,
+ --build-two-config, --build-exe-dir,
+ --build-project,--build-noclean, --build-options
+
+``--build-target``
+ Specify a specific target to build.
+
+ This option goes with the --build-and-test option, if left out the
+ all target is built.
+
+``--build-nocmake``
+ Run the build without running cmake first.
+
+ Skip the cmake step.
+
+``--build-run-dir``
+ Specify directory to run programs from.
+
+ Directory where programs will be after it has been compiled.
+
+``--build-two-config``
+ Run CMake twice
+
+``--build-exe-dir``
+ Specify the directory for the executable.
+
+``--build-generator``
+ Specify the generator to use.
+
+``--build-generator-platform``
+ Specify the generator-specific platform.
+
+``--build-generator-toolset``
+ Specify the generator-specific toolset.
+
+``--build-project``
+ Specify the name of the project to build.
+
+``--build-makeprogram``
+ Override the make program chosen by CTest with a given one.
+
+``--build-noclean``
+ Skip the make clean step.
+
+``--build-config-sample``
+ A sample executable to use to determine the configuration
+
+ A sample executable to use to determine the configuration that
+ should be used. e.g. Debug/Release/etc
+
+``--build-options``
+ Add extra options to the build step.
+
+ This option must be the last option with the exception of
+ --test-command
+
+``--test-command``
+ The test to run with the --build-and-test option.
+
+``--test-timeout``
+ The time limit in seconds, internal use only.
+
+``--tomorrow-tag``
+ Nightly or experimental starts with next day tag.
+
+ This is useful if the build will not finish in one day.
+
+``--ctest-config``
+ The configuration file used to initialize CTest state when submitting dashboards.
+
+ This option tells CTest to use different initialization file instead
+ of CTestConfiguration.tcl. This way multiple initialization files
+ can be used for example to submit to multiple dashboards.
+
+``--overwrite``
+ Overwrite CTest configuration option.
+
+ By default ctest uses configuration options from configuration file.
+ This option will overwrite the configuration option.
+
+``--extra-submit <file>[;<file>]``
+ Submit extra files to the dashboard.
+
+ This option will submit extra files to the dashboard.
+
+``--force-new-ctest-process``
+ Run child CTest instances as new processes
+
+ By default CTest will run child CTest instances within the same
+ process. If this behavior is not desired, this argument will
+ enforce new processes for child CTest processes.
+
+``--schedule-random``
+ Use a random order for scheduling tests
+
+ This option will run the tests in a random order. It is commonly
+ used to detect implicit dependencies in a test suite.
+
+``--submit-index``
+ Legacy option for old Dart2 dashboard server feature.
+ Do not use.
+
+``--timeout <seconds>``
+ Set a global timeout on all tests.
+
+ This option will set a global timeout on all tests that do not
+ already have a timeout set on them.
+
+``--stop-time <time>``
+ Set a time at which all tests should stop running.
+
+ Set a real time of day at which all tests should timeout. Example:
+ 7:00:00 -0400. Any time format understood by the curl date parser
+ is accepted. Local time is assumed if no timezone is specified.
+
+``--http1.0``
+ Submit using HTTP 1.0.
+
+ This option will force CTest to use HTTP 1.0 to submit files to the
+ dashboard, instead of HTTP 1.1.
+
+``--no-compress-output``
+ Do not compress test output when submitting.
+
+ This flag will turn off automatic compression of test output. Use
+ this to maintain compatibility with an older version of CDash which
+ doesn't support compressed test output.
+
+``--print-labels``
+ Print all available test labels.
+
+ This option will not run any tests, it will simply print the list of
+ all labels associated with the test set.
+
+.. include:: OPTIONS_HELP.txt
+
+Dashboard Client
+================
+
+CTest can operate as a client for the `CDash`_ software quality dashboard
+application. As a dashboard client, CTest performs a sequence of steps
+to configure, build, and test software, and then submits the results to
+a `CDash`_ server.
+
+.. _`CDash`: http://cdash.org/
+
+Dashboard Client Steps
+----------------------
+
+CTest defines an ordered list of testing steps of which some or all may
+be run as a dashboard client:
+
+``Start``
+ Start a new dashboard submission to be composed of results recorded
+ by the following steps.
+ See the `CTest Start Step`_ section below.
+
+``Update``
+ Update the source tree from its version control repository.
+ Record the old and new versions and the list of updated source files.
+ See the `CTest Update Step`_ section below.
+
+``Configure``
+ Configure the software by running a command in the build tree.
+ Record the configuration output log.
+ See the `CTest Configure Step`_ section below.
+
+``Build``
+ Build the software by running a command in the build tree.
+ Record the build output log and detect warnings and errors.
+ See the `CTest Build Step`_ section below.
+
+``Test``
+ Test the software by loading a ``CTestTestfile.cmake``
+ from the build tree and executing the defined tests.
+ Record the output and result of each test.
+ See the `CTest Test Step`_ section below.
+
+``Coverage``
+ Compute coverage of the source code by running a coverage
+ analysis tool and recording its output.
+ See the `CTest Coverage Step`_ section below.
+
+``MemCheck``
+ Run the software test suite through a memory check tool.
+ Record the test output, results, and issues reported by the tool.
+ See the `CTest MemCheck Step`_ section below.
+
+``Submit``
+ Submit results recorded from other testing steps to the
+ software quality dashboard server.
+ See the `CTest Submit Step`_ section below.
+
+Dashboard Client Modes
+----------------------
+
+CTest defines three modes of operation as a dashboard client:
+
+``Nightly``
+ This mode is intended to be invoked once per day, typically at night.
+ It enables the ``Start``, ``Update``, ``Configure``, ``Build``, ``Test``,
+ ``Coverage``, and ``Submit`` steps by default. Selected steps run even
+ if the ``Update`` step reports no changes to the source tree.
+
+``Continuous``
+ This mode is intended to be invoked repeatedly throughout the day.
+ It enables the ``Start``, ``Update``, ``Configure``, ``Build``, ``Test``,
+ ``Coverage``, and ``Submit`` steps by default, but exits after the
+ ``Update`` step if it reports no changes to the source tree.
+
+``Experimental``
+ This mode is intended to be invoked by a developer to test local changes.
+ It enables the ``Start``, ``Configure``, ``Build``, ``Test``, ``Coverage``,
+ and ``Submit`` steps by default.
+
+Dashboard Client via CTest Command-Line
+---------------------------------------
+
+CTest can perform testing on an already-generated build tree.
+Run the ``ctest`` command with the current working directory set
+to the build tree and use one of these signatures::
+
+ ctest -D <mode>[<step>]
+ ctest -M <mode> [ -T <step> ]...
+
+The ``<mode>`` must be one of the above `Dashboard Client Modes`_,
+and each ``<step>`` must be one of the above `Dashboard Client Steps`_.
+
+CTest reads the `Dashboard Client Configuration`_ settings from
+a file in the build tree called either ``CTestConfiguration.ini``
+or ``DartConfiguration.tcl`` (the names are historical). The format
+of the file is::
+
+ # Lines starting in '#' are comments.
+ # Other non-blank lines are key-value pairs.
+ <setting>: <value>
+
+where ``<setting>`` is the setting name and ``<value>`` is the
+setting value.
+
+In build trees generated by CMake, this configuration file is
+generated by the :module:`CTest` module if included by the project.
+The module uses variables to obtain a value for each setting
+as documented with the settings below.
+
+.. _`CTest Script`:
+
+Dashboard Client via CTest Script
+---------------------------------
+
+CTest can perform testing driven by a :manual:`cmake-language(7)`
+script that creates and maintains the source and build tree as
+well as performing the testing steps. Run the ``ctest`` command
+with the current working directory set outside of any build tree
+and use one of these signatures::
+
+ ctest -S <script>
+ ctest -SP <script>
+
+The ``<script>`` file must call :ref:`CTest Commands` commands
+to run testing steps explicitly as documented below. The commands
+obtain `Dashboard Client Configuration`_ settings from their
+arguments or from variables set in the script.
+
+Dashboard Client Configuration
+==============================
+
+The `Dashboard Client Steps`_ may be configured by named
+settings as documented in the following sections.
+
+.. _`CTest Start Step`:
+
+CTest Start Step
+----------------
+
+Start a new dashboard submission to be composed of results recorded
+by the following steps.
+
+In a `CTest Script`_, the :command:`ctest_start` command runs this step.
+Arguments to the command may specify some of the step settings.
+The command first runs the command-line specified by the
+``CTEST_CHECKOUT_COMMAND`` variable, if set, to initialize the source
+directory.
+
+Configuration settings include:
+
+``BuildDirectory``
+ The full path to the project build tree.
+
+ * `CTest Script`_ variable: :variable:`CTEST_BINARY_DIRECTORY`
+ * :module:`CTest` module variable: :variable:`PROJECT_BINARY_DIR`
+
+``SourceDirectory``
+ The full path to the project source tree.
+
+ * `CTest Script`_ variable: :variable:`CTEST_SOURCE_DIRECTORY`
+ * :module:`CTest` module variable: :variable:`PROJECT_SOURCE_DIR`
+
+.. _`CTest Update Step`:
+
+CTest Update Step
+-----------------
+
+In a `CTest Script`_, the :command:`ctest_update` command runs this step.
+Arguments to the command may specify some of the step settings.
+
+Configuration settings to specify the version control tool include:
+
+``BZRCommand``
+ ``bzr`` command-line tool to use if source tree is managed by Bazaar.
+
+ * `CTest Script`_ variable: :variable:`CTEST_BZR_COMMAND`
+ * :module:`CTest` module variable: none
+
+``BZRUpdateOptions``
+ Command-line options to the ``BZRCommand`` when updating the source.
+
+ * `CTest Script`_ variable: :variable:`CTEST_BZR_UPDATE_OPTIONS`
+ * :module:`CTest` module variable: none
+
+``CVSCommand``
+ ``cvs`` command-line tool to use if source tree is managed by CVS.
+
+ * `CTest Script`_ variable: :variable:`CTEST_CVS_COMMAND`
+ * :module:`CTest` module variable: ``CVSCOMMAND``
+
+``CVSUpdateOptions``
+ Command-line options to the ``CVSCommand`` when updating the source.
+
+ * `CTest Script`_ variable: :variable:`CTEST_CVS_UPDATE_OPTIONS`
+ * :module:`CTest` module variable: ``CVS_UPDATE_OPTIONS``
+
+``GITCommand``
+ ``git`` command-line tool to use if source tree is managed by Git.
+
+ * `CTest Script`_ variable: :variable:`CTEST_GIT_COMMAND`
+ * :module:`CTest` module variable: ``GITCOMMAND``
+
+``GITUpdateCustom``
+ Specify a semicolon-separated list of custom command lines to run
+ in the source tree (Git work tree) to update it instead of running
+ the ``GITCommand``.
+
+ * `CTest Script`_ variable: :variable:`CTEST_GIT_UPDATE_CUSTOM`
+ * :module:`CTest` module variable: ``CTEST_GIT_UPDATE_CUSTOM``
+
+``GITUpdateOptions``
+ Command-line options to the ``GITCommand`` when updating the source.
+
+ * `CTest Script`_ variable: :variable:`CTEST_GIT_UPDATE_OPTIONS`
+ * :module:`CTest` module variable: ``GIT_UPDATE_OPTIONS``
+
+``HGCommand``
+ ``hg`` command-line tool to use if source tree is managed by Mercurial.
+
+ * `CTest Script`_ variable: :variable:`CTEST_HG_COMMAND`
+ * :module:`CTest` module variable: none
+
+``HGUpdateOptions``
+ Command-line options to the ``HGCommand`` when updating the source.
+
+ * `CTest Script`_ variable: :variable:`CTEST_HG_UPDATE_OPTIONS`
+ * :module:`CTest` module variable: none
+
+``P4Client``
+ Value of the ``-c`` option to the ``P4Command``.
+
+ * `CTest Script`_ variable: :variable:`CTEST_P4_CLIENT`
+ * :module:`CTest` module variable: ``CTEST_P4_CLIENT``
+
+``P4Command``
+ ``p4`` command-line tool to use if source tree is managed by Perforce.
+
+ * `CTest Script`_ variable: :variable:`CTEST_P4_COMMAND`
+ * :module:`CTest` module variable: ``P4COMMAND``
+
+``P4Options``
+ Command-line options to the ``P4Command`` for all invocations.
+
+ * `CTest Script`_ variable: :variable:`CTEST_P4_OPTIONS`
+ * :module:`CTest` module variable: ``CTEST_P4_OPTIONS``
+
+``P4UpdateCustom``
+ Specify a semicolon-separated list of custom command lines to run
+ in the source tree (Perforce tree) to update it instead of running
+ the ``P4Command``.
+
+ * `CTest Script`_ variable: none
+ * :module:`CTest` module variable: ``CTEST_P4_UPDATE_CUSTOM``
+
+``P4UpdateOptions``
+ Command-line options to the ``P4Command`` when updating the source.
+
+ * `CTest Script`_ variable: :variable:`CTEST_P4_UPDATE_OPTIONS`
+ * :module:`CTest` module variable: ``CTEST_P4_UPDATE_OPTIONS``
+
+``SVNCommand``
+ ``svn`` command-line tool to use if source tree is managed by Subversion.
+
+ * `CTest Script`_ variable: :variable:`CTEST_SVN_COMMAND`
+ * :module:`CTest` module variable: ``SVNCOMMAND``
+
+``SVNOptions``
+ Command-line options to the ``SVNCommand`` for all invocations.
+
+ * `CTest Script`_ variable: :variable:`CTEST_SVN_OPTIONS`
+ * :module:`CTest` module variable: ``CTEST_SVN_OPTIONS``
+
+``SVNUpdateOptions``
+ Command-line options to the ``SVNCommand`` when updating the source.
+
+ * `CTest Script`_ variable: :variable:`CTEST_SVN_UPDATE_OPTIONS`
+ * :module:`CTest` module variable: ``SVN_UPDATE_OPTIONS``
+
+``UpdateCommand``
+ Specify the version-control command-line tool to use without
+ detecting the VCS that manages the source tree.
+
+ * `CTest Script`_ variable: :variable:`CTEST_UPDATE_COMMAND`
+ * :module:`CTest` module variable: ``<VCS>COMMAND``
+ when ``UPDATE_TYPE`` is ``<vcs>``, else ``UPDATE_COMMAND``
+
+``UpdateOptions``
+ Command-line options to the ``UpdateCommand``.
+
+ * `CTest Script`_ variable: :variable:`CTEST_UPDATE_OPTIONS`
+ * :module:`CTest` module variable: ``<VCS>_UPDATE_OPTIONS``
+ when ``UPDATE_TYPE`` is ``<vcs>``, else ``UPDATE_OPTIONS``
+
+``UpdateType``
+ Specify the version-control system that manages the source
+ tree if it cannot be detected automatically.
+ The value may be ``bzr``, ``cvs``, ``git``, ``hg``,
+ ``p4``, or ``svn``.
+
+ * `CTest Script`_ variable: none, detected from source tree
+ * :module:`CTest` module variable: ``UPDATE_TYPE`` if set,
+ else ``CTEST_UPDATE_TYPE``
+
+``UpdateVersionOnly``
+ Specify that you want the version control update command to only
+ discover the current version that is checked out, and not to update
+ to a different version.
+
+ * `CTest Script`_ variable: :variable:`CTEST_UPDATE_VERSION_ONLY`
+
+
+
+Additional configuration settings include:
+
+``NightlyStartTime``
+ In the ``Nightly`` dashboard mode, specify the "nightly start time".
+ With centralized version control systems (``cvs`` and ``svn``),
+ the ``Update`` step checks out the version of the software as of
+ this time so that multiple clients choose a common version to test.
+ This is not well-defined in distributed version-control systems so
+ the setting is ignored.
+
+ * `CTest Script`_ variable: :variable:`CTEST_NIGHTLY_START_TIME`
+ * :module:`CTest` module variable: ``NIGHTLY_START_TIME`` if set,
+ else ``CTEST_NIGHTLY_START_TIME``
+
+.. _`CTest Configure Step`:
+
+CTest Configure Step
+--------------------
+
+In a `CTest Script`_, the :command:`ctest_configure` command runs this step.
+Arguments to the command may specify some of the step settings.
+
+Configuration settings include:
+
+``ConfigureCommand``
+ Command-line to launch the software configuration process.
+ It will be executed in the location specified by the
+ ``BuildDirectory`` setting.
+
+ * `CTest Script`_ variable: :variable:`CTEST_CONFIGURE_COMMAND`
+ * :module:`CTest` module variable: :variable:`CMAKE_COMMAND`
+ followed by :variable:`PROJECT_SOURCE_DIR`
+
+.. _`CTest Build Step`:
+
+CTest Build Step
+----------------
+
+In a `CTest Script`_, the :command:`ctest_build` command runs this step.
+Arguments to the command may specify some of the step settings.
+
+Configuration settings include:
+
+``DefaultCTestConfigurationType``
+ When the build system to be launched allows build-time selection
+ of the configuration (e.g. ``Debug``, ``Release``), this specifies
+ the default configuration to be built when no ``-C`` option is
+ given to the ``ctest`` command. The value will be substituted into
+ the value of ``MakeCommand`` to replace the literal string
+ ``${CTEST_CONFIGURATION_TYPE}`` if it appears.
+
+ * `CTest Script`_ variable: :variable:`CTEST_CONFIGURATION_TYPE`
+ * :module:`CTest` module variable: ``DEFAULT_CTEST_CONFIGURATION_TYPE``,
+ initialized by the ``CMAKE_CONFIG_TYPE`` environment variable
+
+``MakeCommand``
+ Command-line to launch the software build process.
+ It will be executed in the location specified by the
+ ``BuildDirectory`` setting.
+
+ * `CTest Script`_ variable: :variable:`CTEST_BUILD_COMMAND`
+ * :module:`CTest` module variable: ``MAKECOMMAND``,
+ initialized by the :command:`build_command` command
+
+``UseLaunchers``
+ For build trees generated by CMake using a Makefile generator
+ or the :generator:`Ninja` generator, specify whether the
+ ``CTEST_USE_LAUNCHERS`` feature is enabled by the
+ :module:`CTestUseLaunchers` module (also included by the
+ :module:`CTest` module). When enabled, the generated build
+ system wraps each invocation of the compiler, linker, or
+ custom command line with a "launcher" that communicates
+ with CTest via environment variables and files to report
+ granular build warning and error information. Otherwise,
+ CTest must "scrape" the build output log for diagnostics.
+
+ * `CTest Script`_ variable: :variable:`CTEST_USE_LAUNCHERS`
+ * :module:`CTest` module variable: ``CTEST_USE_LAUNCHERS``
+
+.. _`CTest Test Step`:
+
+CTest Test Step
+---------------
+
+In a `CTest Script`_, the :command:`ctest_test` command runs this step.
+Arguments to the command may specify some of the step settings.
+
+Configuration settings include:
+
+``TimeOut``
+ The default timeout for each test if not specified by the
+ :prop_test:`TIMEOUT` test property.
+
+ * `CTest Script`_ variable: :variable:`CTEST_TEST_TIMEOUT`
+ * :module:`CTest` module variable: ``DART_TESTING_TIMEOUT``
+
+.. _`CTest Coverage Step`:
+
+CTest Coverage Step
+-------------------
+
+In a `CTest Script`_, the :command:`ctest_coverage` command runs this step.
+Arguments to the command may specify some of the step settings.
+
+Configuration settings include:
+
+``CoverageCommand``
+ Command-line tool to perform software coverage analysis.
+ It will be executed in the location specified by the
+ ``BuildDirectory`` setting.
+
+ * `CTest Script`_ variable: :variable:`CTEST_COVERAGE_COMMAND`
+ * :module:`CTest` module variable: ``COVERAGE_COMMAND``
+
+``CoverageExtraFlags``
+ Specify command-line options to the ``CoverageCommand`` tool.
+
+ * `CTest Script`_ variable: :variable:`CTEST_COVERAGE_EXTRA_FLAGS`
+ * :module:`CTest` module variable: ``COVERAGE_EXTRA_FLAGS``
+
+.. _`CTest MemCheck Step`:
+
+CTest MemCheck Step
+-------------------
+
+In a `CTest Script`_, the :command:`ctest_memcheck` command runs this step.
+Arguments to the command may specify some of the step settings.
+
+Configuration settings include:
+
+``MemoryCheckCommand``
+ Command-line tool to perform dynamic analysis. Test command lines
+ will be launched through this tool.
+
+ * `CTest Script`_ variable: :variable:`CTEST_MEMORYCHECK_COMMAND`
+ * :module:`CTest` module variable: ``MEMORYCHECK_COMMAND``
+
+``MemoryCheckCommandOptions``
+ Specify command-line options to the ``MemoryCheckCommand`` tool.
+ They will be placed prior to the test command line.
+
+ * `CTest Script`_ variable: :variable:`CTEST_MEMORYCHECK_COMMAND_OPTIONS`
+ * :module:`CTest` module variable: ``MEMORYCHECK_COMMAND_OPTIONS``
+
+``MemoryCheckType``
+ Specify the type of memory checking to perform.
+
+ * `CTest Script`_ variable: :variable:`CTEST_MEMORYCHECK_TYPE`
+ * :module:`CTest` module variable: ``MEMORYCHECK_TYPE``
+
+``MemoryCheckSanitizerOptions``
+ Specify options to sanitizers when running with a sanitize-enabled build.
+
+ * `CTest Script`_ variable: :variable:`CTEST_MEMORYCHECK_SANITIZER_OPTIONS`
+ * :module:`CTest` module variable: ``MEMORYCHECK_SANITIZER_OPTIONS``
+
+``MemoryCheckSuppressionFile``
+ Specify a file containing suppression rules for the
+ ``MemoryCheckCommand`` tool. It will be passed with options
+ appropriate to the tool.
+
+ * `CTest Script`_ variable: :variable:`CTEST_MEMORYCHECK_SUPPRESSIONS_FILE`
+ * :module:`CTest` module variable: ``MEMORYCHECK_SUPPRESSIONS_FILE``
+
+Additional configuration settings include:
+
+``BoundsCheckerCommand``
+ Specify a ``MemoryCheckCommand`` that is known to be command-line
+ compatible with Bounds Checker.
+
+ * `CTest Script`_ variable: none
+ * :module:`CTest` module variable: none
+
+``PurifyCommand``
+ Specify a ``MemoryCheckCommand`` that is known to be command-line
+ compatible with Purify.
+
+ * `CTest Script`_ variable: none
+ * :module:`CTest` module variable: ``PURIFYCOMMAND``
+
+``ValgrindCommand``
+ Specify a ``MemoryCheckCommand`` that is known to be command-line
+ compatible with Valgrind.
+
+ * `CTest Script`_ variable: none
+ * :module:`CTest` module variable: ``VALGRIND_COMMAND``
+
+``ValgrindCommandOptions``
+ Specify command-line options to the ``ValgrindCommand`` tool.
+ They will be placed prior to the test command line.
+
+ * `CTest Script`_ variable: none
+ * :module:`CTest` module variable: ``VALGRIND_COMMAND_OPTIONS``
+
+.. _`CTest Submit Step`:
+
+CTest Submit Step
+-----------------
+
+In a `CTest Script`_, the :command:`ctest_submit` command runs this step.
+Arguments to the command may specify some of the step settings.
+
+Configuration settings include:
+
+``BuildName``
+ Describe the dashboard client platform with a short string.
+ (Operating system, compiler, etc.)
+
+ * `CTest Script`_ variable: :variable:`CTEST_BUILD_NAME`
+ * :module:`CTest` module variable: ``BUILDNAME``
+
+``CDashVersion``
+ Specify the version of `CDash`_ on the server.
+
+ * `CTest Script`_ variable: none, detected from server
+ * :module:`CTest` module variable: ``CTEST_CDASH_VERSION``
+
+``CTestSubmitRetryCount``
+ Specify a number of attempts to retry submission on network failure.
+
+ * `CTest Script`_ variable: none,
+ use the :command:`ctest_submit` ``RETRY_COUNT`` option.
+ * :module:`CTest` module variable: ``CTEST_SUBMIT_RETRY_COUNT``
+
+``CTestSubmitRetryDelay``
+ Specify a delay before retrying submission on network failure.
+
+ * `CTest Script`_ variable: none,
+ use the :command:`ctest_submit` ``RETRY_DELAY`` option.
+ * :module:`CTest` module variable: ``CTEST_SUBMIT_RETRY_DELAY``
+
+``CurlOptions``
+ Specify a semicolon-separated list of options to control the
+ Curl library that CTest uses internally to connect to the
+ server. Possible options are ``CURLOPT_SSL_VERIFYPEER_OFF``
+ and ``CURLOPT_SSL_VERIFYHOST_OFF``.
+
+ * `CTest Script`_ variable: :variable:`CTEST_CURL_OPTIONS`
+ * :module:`CTest` module variable: ``CTEST_CURL_OPTIONS``
+
+``DropLocation``
+ The path on the dashboard server to send the submission.
+
+ * `CTest Script`_ variable: :variable:`CTEST_DROP_LOCATION`
+ * :module:`CTest` module variable: ``DROP_LOCATION`` if set,
+ else ``CTEST_DROP_LOCATION``
+
+``DropMethod``
+ Specify the method by which results should be submitted to the
+ dashboard server. The value may be ``cp``, ``ftp``, ``http``,
+ ``https``, ``scp``, or ``xmlrpc`` (if CMake was built with
+ support for it).
+
+ * `CTest Script`_ variable: :variable:`CTEST_DROP_METHOD`
+ * :module:`CTest` module variable: ``DROP_METHOD`` if set,
+ else ``CTEST_DROP_METHOD``
+
+``DropSite``
+ The dashboard server name
+ (for ``ftp``, ``http``, and ``https``, ``scp``, and ``xmlrpc``).
+
+ * `CTest Script`_ variable: :variable:`CTEST_DROP_SITE`
+ * :module:`CTest` module variable: ``DROP_SITE`` if set,
+ else ``CTEST_DROP_SITE``
+
+``DropSitePassword``
+ The dashboard server login password, if any
+ (for ``ftp``, ``http``, and ``https``).
+
+ * `CTest Script`_ variable: :variable:`CTEST_DROP_SITE_PASSWORD`
+ * :module:`CTest` module variable: ``DROP_SITE_PASSWORD`` if set,
+ else ``CTEST_DROP_SITE_PASWORD``
+
+``DropSiteUser``
+ The dashboard server login user name, if any
+ (for ``ftp``, ``http``, and ``https``).
+
+ * `CTest Script`_ variable: :variable:`CTEST_DROP_SITE_USER`
+ * :module:`CTest` module variable: ``DROP_SITE_USER`` if set,
+ else ``CTEST_DROP_SITE_USER``
+
+``IsCDash``
+ Specify whether the dashboard server is `CDash`_ or an older
+ dashboard server implementation requiring ``TriggerSite``.
+
+ * `CTest Script`_ variable: :variable:`CTEST_DROP_SITE_CDASH`
+ * :module:`CTest` module variable: ``CTEST_DROP_SITE_CDASH``
+
+``ScpCommand``
+ ``scp`` command-line tool to use when ``DropMethod`` is ``scp``.
+
+ * `CTest Script`_ variable: :variable:`CTEST_SCP_COMMAND`
+ * :module:`CTest` module variable: ``SCPCOMMAND``
+
+``Site``
+ Describe the dashboard client host site with a short string.
+ (Hostname, domain, etc.)
+
+ * `CTest Script`_ variable: :variable:`CTEST_SITE`
+ * :module:`CTest` module variable: ``SITE``,
+ initialized by the :command:`site_name` command
+
+``TriggerSite``
+ Legacy option to support older dashboard server implementations.
+ Not used when ``IsCDash`` is true.
+
+ * `CTest Script`_ variable: :variable:`CTEST_TRIGGER_SITE`
+ * :module:`CTest` module variable: ``TRIGGER_SITE`` if set,
+ else ``CTEST_TRIGGER_SITE``
+
+See Also
+========
+
+.. include:: LINKS.txt
diff --git a/Help/module/AddFileDependencies.rst b/Help/module/AddFileDependencies.rst
new file mode 100644
index 0000000000..3cbce33ac7
--- /dev/null
+++ b/Help/module/AddFileDependencies.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/AddFileDependencies.cmake
diff --git a/Help/module/BundleUtilities.rst b/Help/module/BundleUtilities.rst
new file mode 100644
index 0000000000..5d9c840178
--- /dev/null
+++ b/Help/module/BundleUtilities.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/BundleUtilities.cmake
diff --git a/Help/module/CMakeAddFortranSubdirectory.rst b/Help/module/CMakeAddFortranSubdirectory.rst
new file mode 100644
index 0000000000..9abf571af2
--- /dev/null
+++ b/Help/module/CMakeAddFortranSubdirectory.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeAddFortranSubdirectory.cmake
diff --git a/Help/module/CMakeBackwardCompatibilityCXX.rst b/Help/module/CMakeBackwardCompatibilityCXX.rst
new file mode 100644
index 0000000000..05e5f4abe2
--- /dev/null
+++ b/Help/module/CMakeBackwardCompatibilityCXX.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeBackwardCompatibilityCXX.cmake
diff --git a/Help/module/CMakeDependentOption.rst b/Help/module/CMakeDependentOption.rst
new file mode 100644
index 0000000000..fd071b55b1
--- /dev/null
+++ b/Help/module/CMakeDependentOption.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeDependentOption.cmake
diff --git a/Help/module/CMakeDetermineVSServicePack.rst b/Help/module/CMakeDetermineVSServicePack.rst
new file mode 100644
index 0000000000..176853372c
--- /dev/null
+++ b/Help/module/CMakeDetermineVSServicePack.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeDetermineVSServicePack.cmake
diff --git a/Help/module/CMakeExpandImportedTargets.rst b/Help/module/CMakeExpandImportedTargets.rst
new file mode 100644
index 0000000000..1084280342
--- /dev/null
+++ b/Help/module/CMakeExpandImportedTargets.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeExpandImportedTargets.cmake
diff --git a/Help/module/CMakeFindDependencyMacro.rst b/Help/module/CMakeFindDependencyMacro.rst
new file mode 100644
index 0000000000..5b5b550a35
--- /dev/null
+++ b/Help/module/CMakeFindDependencyMacro.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeFindDependencyMacro.cmake
diff --git a/Help/module/CMakeFindFrameworks.rst b/Help/module/CMakeFindFrameworks.rst
new file mode 100644
index 0000000000..c2c219b3e1
--- /dev/null
+++ b/Help/module/CMakeFindFrameworks.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeFindFrameworks.cmake
diff --git a/Help/module/CMakeFindPackageMode.rst b/Help/module/CMakeFindPackageMode.rst
new file mode 100644
index 0000000000..d099d19e37
--- /dev/null
+++ b/Help/module/CMakeFindPackageMode.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeFindPackageMode.cmake
diff --git a/Help/module/CMakeForceCompiler.rst b/Help/module/CMakeForceCompiler.rst
new file mode 100644
index 0000000000..3277426944
--- /dev/null
+++ b/Help/module/CMakeForceCompiler.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeForceCompiler.cmake
diff --git a/Help/module/CMakeGraphVizOptions.rst b/Help/module/CMakeGraphVizOptions.rst
new file mode 100644
index 0000000000..2cd97b3c46
--- /dev/null
+++ b/Help/module/CMakeGraphVizOptions.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeGraphVizOptions.cmake
diff --git a/Help/module/CMakePackageConfigHelpers.rst b/Help/module/CMakePackageConfigHelpers.rst
new file mode 100644
index 0000000000..a291aff0c3
--- /dev/null
+++ b/Help/module/CMakePackageConfigHelpers.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakePackageConfigHelpers.cmake
diff --git a/Help/module/CMakeParseArguments.rst b/Help/module/CMakeParseArguments.rst
new file mode 100644
index 0000000000..810a9dd3ce
--- /dev/null
+++ b/Help/module/CMakeParseArguments.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeParseArguments.cmake
diff --git a/Help/module/CMakePrintHelpers.rst b/Help/module/CMakePrintHelpers.rst
new file mode 100644
index 0000000000..a75a34f0a1
--- /dev/null
+++ b/Help/module/CMakePrintHelpers.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakePrintHelpers.cmake
diff --git a/Help/module/CMakePrintSystemInformation.rst b/Help/module/CMakePrintSystemInformation.rst
new file mode 100644
index 0000000000..0b5d8489a1
--- /dev/null
+++ b/Help/module/CMakePrintSystemInformation.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakePrintSystemInformation.cmake
diff --git a/Help/module/CMakePushCheckState.rst b/Help/module/CMakePushCheckState.rst
new file mode 100644
index 0000000000..e897929592
--- /dev/null
+++ b/Help/module/CMakePushCheckState.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakePushCheckState.cmake
diff --git a/Help/module/CMakeVerifyManifest.rst b/Help/module/CMakeVerifyManifest.rst
new file mode 100644
index 0000000000..eeff1bf493
--- /dev/null
+++ b/Help/module/CMakeVerifyManifest.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CMakeVerifyManifest.cmake
diff --git a/Help/module/CPack.rst b/Help/module/CPack.rst
new file mode 100644
index 0000000000..bfbda1f890
--- /dev/null
+++ b/Help/module/CPack.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPack.cmake
diff --git a/Help/module/CPackBundle.rst b/Help/module/CPackBundle.rst
new file mode 100644
index 0000000000..651e874267
--- /dev/null
+++ b/Help/module/CPackBundle.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackBundle.cmake
diff --git a/Help/module/CPackComponent.rst b/Help/module/CPackComponent.rst
new file mode 100644
index 0000000000..df82836ca6
--- /dev/null
+++ b/Help/module/CPackComponent.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackComponent.cmake
diff --git a/Help/module/CPackCygwin.rst b/Help/module/CPackCygwin.rst
new file mode 100644
index 0000000000..21f4473482
--- /dev/null
+++ b/Help/module/CPackCygwin.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackCygwin.cmake
diff --git a/Help/module/CPackDMG.rst b/Help/module/CPackDMG.rst
new file mode 100644
index 0000000000..784262c5e1
--- /dev/null
+++ b/Help/module/CPackDMG.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackDMG.cmake
diff --git a/Help/module/CPackDeb.rst b/Help/module/CPackDeb.rst
new file mode 100644
index 0000000000..d1526ee49c
--- /dev/null
+++ b/Help/module/CPackDeb.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackDeb.cmake
diff --git a/Help/module/CPackIFW.rst b/Help/module/CPackIFW.rst
new file mode 100644
index 0000000000..ea05796ada
--- /dev/null
+++ b/Help/module/CPackIFW.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackIFW.cmake
diff --git a/Help/module/CPackNSIS.rst b/Help/module/CPackNSIS.rst
new file mode 100644
index 0000000000..bb35ed60a3
--- /dev/null
+++ b/Help/module/CPackNSIS.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackNSIS.cmake
diff --git a/Help/module/CPackPackageMaker.rst b/Help/module/CPackPackageMaker.rst
new file mode 100644
index 0000000000..de5544869d
--- /dev/null
+++ b/Help/module/CPackPackageMaker.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackPackageMaker.cmake
diff --git a/Help/module/CPackRPM.rst b/Help/module/CPackRPM.rst
new file mode 100644
index 0000000000..28d0e69129
--- /dev/null
+++ b/Help/module/CPackRPM.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackRPM.cmake
diff --git a/Help/module/CPackWIX.rst b/Help/module/CPackWIX.rst
new file mode 100644
index 0000000000..1f5e451e9b
--- /dev/null
+++ b/Help/module/CPackWIX.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CPackWIX.cmake
diff --git a/Help/module/CTest.rst b/Help/module/CTest.rst
new file mode 100644
index 0000000000..11a6af7d7d
--- /dev/null
+++ b/Help/module/CTest.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CTest.cmake
diff --git a/Help/module/CTestScriptMode.rst b/Help/module/CTestScriptMode.rst
new file mode 100644
index 0000000000..be1b0447e2
--- /dev/null
+++ b/Help/module/CTestScriptMode.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CTestScriptMode.cmake
diff --git a/Help/module/CTestUseLaunchers.rst b/Help/module/CTestUseLaunchers.rst
new file mode 100644
index 0000000000..688da0870f
--- /dev/null
+++ b/Help/module/CTestUseLaunchers.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CTestUseLaunchers.cmake
diff --git a/Help/module/CheckCCompilerFlag.rst b/Help/module/CheckCCompilerFlag.rst
new file mode 100644
index 0000000000..1be1491ccb
--- /dev/null
+++ b/Help/module/CheckCCompilerFlag.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckCCompilerFlag.cmake
diff --git a/Help/module/CheckCSourceCompiles.rst b/Help/module/CheckCSourceCompiles.rst
new file mode 100644
index 0000000000..1fa02f9b1e
--- /dev/null
+++ b/Help/module/CheckCSourceCompiles.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckCSourceCompiles.cmake
diff --git a/Help/module/CheckCSourceRuns.rst b/Help/module/CheckCSourceRuns.rst
new file mode 100644
index 0000000000..16b47e66da
--- /dev/null
+++ b/Help/module/CheckCSourceRuns.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckCSourceRuns.cmake
diff --git a/Help/module/CheckCXXCompilerFlag.rst b/Help/module/CheckCXXCompilerFlag.rst
new file mode 100644
index 0000000000..cfd1f457bb
--- /dev/null
+++ b/Help/module/CheckCXXCompilerFlag.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckCXXCompilerFlag.cmake
diff --git a/Help/module/CheckCXXSourceCompiles.rst b/Help/module/CheckCXXSourceCompiles.rst
new file mode 100644
index 0000000000..d701c4e541
--- /dev/null
+++ b/Help/module/CheckCXXSourceCompiles.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckCXXSourceCompiles.cmake
diff --git a/Help/module/CheckCXXSourceRuns.rst b/Help/module/CheckCXXSourceRuns.rst
new file mode 100644
index 0000000000..caab975893
--- /dev/null
+++ b/Help/module/CheckCXXSourceRuns.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckCXXSourceRuns.cmake
diff --git a/Help/module/CheckCXXSymbolExists.rst b/Help/module/CheckCXXSymbolExists.rst
new file mode 100644
index 0000000000..fc192e8197
--- /dev/null
+++ b/Help/module/CheckCXXSymbolExists.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckCXXSymbolExists.cmake
diff --git a/Help/module/CheckFortranFunctionExists.rst b/Help/module/CheckFortranFunctionExists.rst
new file mode 100644
index 0000000000..3395d05c48
--- /dev/null
+++ b/Help/module/CheckFortranFunctionExists.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckFortranFunctionExists.cmake
diff --git a/Help/module/CheckFortranSourceCompiles.rst b/Help/module/CheckFortranSourceCompiles.rst
new file mode 100644
index 0000000000..b749a2a30c
--- /dev/null
+++ b/Help/module/CheckFortranSourceCompiles.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckFortranSourceCompiles.cmake
diff --git a/Help/module/CheckFunctionExists.rst b/Help/module/CheckFunctionExists.rst
new file mode 100644
index 0000000000..ed89dc407f
--- /dev/null
+++ b/Help/module/CheckFunctionExists.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckFunctionExists.cmake
diff --git a/Help/module/CheckIncludeFile.rst b/Help/module/CheckIncludeFile.rst
new file mode 100644
index 0000000000..6b831089e3
--- /dev/null
+++ b/Help/module/CheckIncludeFile.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckIncludeFile.cmake
diff --git a/Help/module/CheckIncludeFileCXX.rst b/Help/module/CheckIncludeFileCXX.rst
new file mode 100644
index 0000000000..fdbf39fd16
--- /dev/null
+++ b/Help/module/CheckIncludeFileCXX.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckIncludeFileCXX.cmake
diff --git a/Help/module/CheckIncludeFiles.rst b/Help/module/CheckIncludeFiles.rst
new file mode 100644
index 0000000000..b56f14565f
--- /dev/null
+++ b/Help/module/CheckIncludeFiles.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckIncludeFiles.cmake
diff --git a/Help/module/CheckLanguage.rst b/Help/module/CheckLanguage.rst
new file mode 100644
index 0000000000..16f1a3f79b
--- /dev/null
+++ b/Help/module/CheckLanguage.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckLanguage.cmake
diff --git a/Help/module/CheckLibraryExists.rst b/Help/module/CheckLibraryExists.rst
new file mode 100644
index 0000000000..7512f46c59
--- /dev/null
+++ b/Help/module/CheckLibraryExists.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckLibraryExists.cmake
diff --git a/Help/module/CheckPrototypeDefinition.rst b/Help/module/CheckPrototypeDefinition.rst
new file mode 100644
index 0000000000..073fcb59f7
--- /dev/null
+++ b/Help/module/CheckPrototypeDefinition.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckPrototypeDefinition.cmake
diff --git a/Help/module/CheckStructHasMember.rst b/Help/module/CheckStructHasMember.rst
new file mode 100644
index 0000000000..5277ad2f6f
--- /dev/null
+++ b/Help/module/CheckStructHasMember.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckStructHasMember.cmake
diff --git a/Help/module/CheckSymbolExists.rst b/Help/module/CheckSymbolExists.rst
new file mode 100644
index 0000000000..68ae70009f
--- /dev/null
+++ b/Help/module/CheckSymbolExists.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckSymbolExists.cmake
diff --git a/Help/module/CheckTypeSize.rst b/Help/module/CheckTypeSize.rst
new file mode 100644
index 0000000000..6ad03456fc
--- /dev/null
+++ b/Help/module/CheckTypeSize.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckTypeSize.cmake
diff --git a/Help/module/CheckVariableExists.rst b/Help/module/CheckVariableExists.rst
new file mode 100644
index 0000000000..07f0777927
--- /dev/null
+++ b/Help/module/CheckVariableExists.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/CheckVariableExists.cmake
diff --git a/Help/module/Dart.rst b/Help/module/Dart.rst
new file mode 100644
index 0000000000..524ac33df5
--- /dev/null
+++ b/Help/module/Dart.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/Dart.cmake
diff --git a/Help/module/DeployQt4.rst b/Help/module/DeployQt4.rst
new file mode 100644
index 0000000000..3c0ef444a0
--- /dev/null
+++ b/Help/module/DeployQt4.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/DeployQt4.cmake
diff --git a/Help/module/Documentation.rst b/Help/module/Documentation.rst
new file mode 100644
index 0000000000..08e2ffb6d5
--- /dev/null
+++ b/Help/module/Documentation.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/Documentation.cmake
diff --git a/Help/module/ExternalData.rst b/Help/module/ExternalData.rst
new file mode 100644
index 0000000000..f0f8f1d075
--- /dev/null
+++ b/Help/module/ExternalData.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/ExternalData.cmake
diff --git a/Help/module/ExternalProject.rst b/Help/module/ExternalProject.rst
new file mode 100644
index 0000000000..fce70567eb
--- /dev/null
+++ b/Help/module/ExternalProject.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/ExternalProject.cmake
diff --git a/Help/module/FeatureSummary.rst b/Help/module/FeatureSummary.rst
new file mode 100644
index 0000000000..6fd8f3805e
--- /dev/null
+++ b/Help/module/FeatureSummary.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FeatureSummary.cmake
diff --git a/Help/module/FindALSA.rst b/Help/module/FindALSA.rst
new file mode 100644
index 0000000000..2a73786b48
--- /dev/null
+++ b/Help/module/FindALSA.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindALSA.cmake
diff --git a/Help/module/FindASPELL.rst b/Help/module/FindASPELL.rst
new file mode 100644
index 0000000000..56dedc4280
--- /dev/null
+++ b/Help/module/FindASPELL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindASPELL.cmake
diff --git a/Help/module/FindAVIFile.rst b/Help/module/FindAVIFile.rst
new file mode 100644
index 0000000000..71282a684d
--- /dev/null
+++ b/Help/module/FindAVIFile.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindAVIFile.cmake
diff --git a/Help/module/FindArmadillo.rst b/Help/module/FindArmadillo.rst
new file mode 100644
index 0000000000..f0ac933d17
--- /dev/null
+++ b/Help/module/FindArmadillo.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindArmadillo.cmake
diff --git a/Help/module/FindBISON.rst b/Help/module/FindBISON.rst
new file mode 100644
index 0000000000..c6e5791be2
--- /dev/null
+++ b/Help/module/FindBISON.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindBISON.cmake
diff --git a/Help/module/FindBLAS.rst b/Help/module/FindBLAS.rst
new file mode 100644
index 0000000000..41f67711cc
--- /dev/null
+++ b/Help/module/FindBLAS.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindBLAS.cmake
diff --git a/Help/module/FindBZip2.rst b/Help/module/FindBZip2.rst
new file mode 100644
index 0000000000..281b1d10dc
--- /dev/null
+++ b/Help/module/FindBZip2.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindBZip2.cmake
diff --git a/Help/module/FindBacktrace.rst b/Help/module/FindBacktrace.rst
new file mode 100644
index 0000000000..e1ca48c775
--- /dev/null
+++ b/Help/module/FindBacktrace.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindBacktrace.cmake
diff --git a/Help/module/FindBoost.rst b/Help/module/FindBoost.rst
new file mode 100644
index 0000000000..139254055f
--- /dev/null
+++ b/Help/module/FindBoost.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindBoost.cmake
diff --git a/Help/module/FindBullet.rst b/Help/module/FindBullet.rst
new file mode 100644
index 0000000000..4ed2b855b8
--- /dev/null
+++ b/Help/module/FindBullet.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindBullet.cmake
diff --git a/Help/module/FindCABLE.rst b/Help/module/FindCABLE.rst
new file mode 100644
index 0000000000..716d5abd55
--- /dev/null
+++ b/Help/module/FindCABLE.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCABLE.cmake
diff --git a/Help/module/FindCUDA.rst b/Help/module/FindCUDA.rst
new file mode 100644
index 0000000000..46ffa9fc27
--- /dev/null
+++ b/Help/module/FindCUDA.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCUDA.cmake
diff --git a/Help/module/FindCURL.rst b/Help/module/FindCURL.rst
new file mode 100644
index 0000000000..e2acc49878
--- /dev/null
+++ b/Help/module/FindCURL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCURL.cmake
diff --git a/Help/module/FindCVS.rst b/Help/module/FindCVS.rst
new file mode 100644
index 0000000000..c891c07d70
--- /dev/null
+++ b/Help/module/FindCVS.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCVS.cmake
diff --git a/Help/module/FindCoin3D.rst b/Help/module/FindCoin3D.rst
new file mode 100644
index 0000000000..fc70a74d6d
--- /dev/null
+++ b/Help/module/FindCoin3D.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCoin3D.cmake
diff --git a/Help/module/FindCups.rst b/Help/module/FindCups.rst
new file mode 100644
index 0000000000..10d0646fd4
--- /dev/null
+++ b/Help/module/FindCups.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCups.cmake
diff --git a/Help/module/FindCurses.rst b/Help/module/FindCurses.rst
new file mode 100644
index 0000000000..73dd01171c
--- /dev/null
+++ b/Help/module/FindCurses.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCurses.cmake
diff --git a/Help/module/FindCxxTest.rst b/Help/module/FindCxxTest.rst
new file mode 100644
index 0000000000..4f17c39bcf
--- /dev/null
+++ b/Help/module/FindCxxTest.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCxxTest.cmake
diff --git a/Help/module/FindCygwin.rst b/Help/module/FindCygwin.rst
new file mode 100644
index 0000000000..2e529dd03a
--- /dev/null
+++ b/Help/module/FindCygwin.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCygwin.cmake
diff --git a/Help/module/FindDCMTK.rst b/Help/module/FindDCMTK.rst
new file mode 100644
index 0000000000..8437d5557f
--- /dev/null
+++ b/Help/module/FindDCMTK.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindDCMTK.cmake
diff --git a/Help/module/FindDart.rst b/Help/module/FindDart.rst
new file mode 100644
index 0000000000..6f21ad4bec
--- /dev/null
+++ b/Help/module/FindDart.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindDart.cmake
diff --git a/Help/module/FindDevIL.rst b/Help/module/FindDevIL.rst
new file mode 100644
index 0000000000..91a28ddc45
--- /dev/null
+++ b/Help/module/FindDevIL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindDevIL.cmake
diff --git a/Help/module/FindDoxygen.rst b/Help/module/FindDoxygen.rst
new file mode 100644
index 0000000000..cffe734534
--- /dev/null
+++ b/Help/module/FindDoxygen.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindDoxygen.cmake
diff --git a/Help/module/FindEXPAT.rst b/Help/module/FindEXPAT.rst
new file mode 100644
index 0000000000..5063680bb1
--- /dev/null
+++ b/Help/module/FindEXPAT.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindEXPAT.cmake
diff --git a/Help/module/FindFLEX.rst b/Help/module/FindFLEX.rst
new file mode 100644
index 0000000000..cc90791d90
--- /dev/null
+++ b/Help/module/FindFLEX.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindFLEX.cmake
diff --git a/Help/module/FindFLTK.rst b/Help/module/FindFLTK.rst
new file mode 100644
index 0000000000..cc1964cc47
--- /dev/null
+++ b/Help/module/FindFLTK.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindFLTK.cmake
diff --git a/Help/module/FindFLTK2.rst b/Help/module/FindFLTK2.rst
new file mode 100644
index 0000000000..5c2acc4aec
--- /dev/null
+++ b/Help/module/FindFLTK2.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindFLTK2.cmake
diff --git a/Help/module/FindFreetype.rst b/Help/module/FindFreetype.rst
new file mode 100644
index 0000000000..424c3fcb3f
--- /dev/null
+++ b/Help/module/FindFreetype.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindFreetype.cmake
diff --git a/Help/module/FindGCCXML.rst b/Help/module/FindGCCXML.rst
new file mode 100644
index 0000000000..15fd4d0d68
--- /dev/null
+++ b/Help/module/FindGCCXML.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGCCXML.cmake
diff --git a/Help/module/FindGDAL.rst b/Help/module/FindGDAL.rst
new file mode 100644
index 0000000000..81fcb3a20b
--- /dev/null
+++ b/Help/module/FindGDAL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGDAL.cmake
diff --git a/Help/module/FindGIF.rst b/Help/module/FindGIF.rst
new file mode 100644
index 0000000000..03d3a75389
--- /dev/null
+++ b/Help/module/FindGIF.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGIF.cmake
diff --git a/Help/module/FindGLEW.rst b/Help/module/FindGLEW.rst
new file mode 100644
index 0000000000..77755da1f1
--- /dev/null
+++ b/Help/module/FindGLEW.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGLEW.cmake
diff --git a/Help/module/FindGLUT.rst b/Help/module/FindGLUT.rst
new file mode 100644
index 0000000000..40263eeb96
--- /dev/null
+++ b/Help/module/FindGLUT.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGLUT.cmake
diff --git a/Help/module/FindGTK.rst b/Help/module/FindGTK.rst
new file mode 100644
index 0000000000..1ce6a86750
--- /dev/null
+++ b/Help/module/FindGTK.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGTK.cmake
diff --git a/Help/module/FindGTK2.rst b/Help/module/FindGTK2.rst
new file mode 100644
index 0000000000..67c1ba9e23
--- /dev/null
+++ b/Help/module/FindGTK2.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGTK2.cmake
diff --git a/Help/module/FindGTest.rst b/Help/module/FindGTest.rst
new file mode 100644
index 0000000000..0e3b4d770a
--- /dev/null
+++ b/Help/module/FindGTest.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGTest.cmake
diff --git a/Help/module/FindGettext.rst b/Help/module/FindGettext.rst
new file mode 100644
index 0000000000..e880dc038d
--- /dev/null
+++ b/Help/module/FindGettext.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGettext.cmake
diff --git a/Help/module/FindGit.rst b/Help/module/FindGit.rst
new file mode 100644
index 0000000000..dd540ef2f5
--- /dev/null
+++ b/Help/module/FindGit.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGit.cmake
diff --git a/Help/module/FindGnuTLS.rst b/Help/module/FindGnuTLS.rst
new file mode 100644
index 0000000000..de0c1d4f8d
--- /dev/null
+++ b/Help/module/FindGnuTLS.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGnuTLS.cmake
diff --git a/Help/module/FindGnuplot.rst b/Help/module/FindGnuplot.rst
new file mode 100644
index 0000000000..93a18b6084
--- /dev/null
+++ b/Help/module/FindGnuplot.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindGnuplot.cmake
diff --git a/Help/module/FindHDF5.rst b/Help/module/FindHDF5.rst
new file mode 100644
index 0000000000..8ac1b8be9d
--- /dev/null
+++ b/Help/module/FindHDF5.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindHDF5.cmake
diff --git a/Help/module/FindHSPELL.rst b/Help/module/FindHSPELL.rst
new file mode 100644
index 0000000000..c1905a2e32
--- /dev/null
+++ b/Help/module/FindHSPELL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindHSPELL.cmake
diff --git a/Help/module/FindHTMLHelp.rst b/Help/module/FindHTMLHelp.rst
new file mode 100644
index 0000000000..47d9c8c497
--- /dev/null
+++ b/Help/module/FindHTMLHelp.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindHTMLHelp.cmake
diff --git a/Help/module/FindHg.rst b/Help/module/FindHg.rst
new file mode 100644
index 0000000000..94aba6f7e6
--- /dev/null
+++ b/Help/module/FindHg.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindHg.cmake
diff --git a/Help/module/FindITK.rst b/Help/module/FindITK.rst
new file mode 100644
index 0000000000..21a922f617
--- /dev/null
+++ b/Help/module/FindITK.rst
@@ -0,0 +1,10 @@
+FindITK
+-------
+
+This module no longer exists.
+
+This module existed in versions of CMake prior to 3.1, but became
+only a thin wrapper around ``find_package(ITK NO_MODULE)`` to
+provide compatibility for projects using long-outdated conventions.
+Now ``find_package(ITK)`` will search for ``ITKConfig.cmake``
+directly.
diff --git a/Help/module/FindIce.rst b/Help/module/FindIce.rst
new file mode 100644
index 0000000000..3af9405e00
--- /dev/null
+++ b/Help/module/FindIce.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindIce.cmake
diff --git a/Help/module/FindIcotool.rst b/Help/module/FindIcotool.rst
new file mode 100644
index 0000000000..c139f58cc2
--- /dev/null
+++ b/Help/module/FindIcotool.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindIcotool.cmake
diff --git a/Help/module/FindImageMagick.rst b/Help/module/FindImageMagick.rst
new file mode 100644
index 0000000000..3a3596e5ec
--- /dev/null
+++ b/Help/module/FindImageMagick.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindImageMagick.cmake
diff --git a/Help/module/FindJNI.rst b/Help/module/FindJNI.rst
new file mode 100644
index 0000000000..b753cf8914
--- /dev/null
+++ b/Help/module/FindJNI.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindJNI.cmake
diff --git a/Help/module/FindJPEG.rst b/Help/module/FindJPEG.rst
new file mode 100644
index 0000000000..80363529af
--- /dev/null
+++ b/Help/module/FindJPEG.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindJPEG.cmake
diff --git a/Help/module/FindJasper.rst b/Help/module/FindJasper.rst
new file mode 100644
index 0000000000..725a87fc43
--- /dev/null
+++ b/Help/module/FindJasper.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindJasper.cmake
diff --git a/Help/module/FindJava.rst b/Help/module/FindJava.rst
new file mode 100644
index 0000000000..39e6b6b215
--- /dev/null
+++ b/Help/module/FindJava.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindJava.cmake
diff --git a/Help/module/FindKDE3.rst b/Help/module/FindKDE3.rst
new file mode 100644
index 0000000000..13ac15c8c7
--- /dev/null
+++ b/Help/module/FindKDE3.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindKDE3.cmake
diff --git a/Help/module/FindKDE4.rst b/Help/module/FindKDE4.rst
new file mode 100644
index 0000000000..8b22f7fc82
--- /dev/null
+++ b/Help/module/FindKDE4.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindKDE4.cmake
diff --git a/Help/module/FindLAPACK.rst b/Help/module/FindLAPACK.rst
new file mode 100644
index 0000000000..6e9909016f
--- /dev/null
+++ b/Help/module/FindLAPACK.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLAPACK.cmake
diff --git a/Help/module/FindLATEX.rst b/Help/module/FindLATEX.rst
new file mode 100644
index 0000000000..4b14c7136e
--- /dev/null
+++ b/Help/module/FindLATEX.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLATEX.cmake
diff --git a/Help/module/FindLibArchive.rst b/Help/module/FindLibArchive.rst
new file mode 100644
index 0000000000..c46b1d0043
--- /dev/null
+++ b/Help/module/FindLibArchive.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLibArchive.cmake
diff --git a/Help/module/FindLibLZMA.rst b/Help/module/FindLibLZMA.rst
new file mode 100644
index 0000000000..88801580cb
--- /dev/null
+++ b/Help/module/FindLibLZMA.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLibLZMA.cmake
diff --git a/Help/module/FindLibXml2.rst b/Help/module/FindLibXml2.rst
new file mode 100644
index 0000000000..bbb3225909
--- /dev/null
+++ b/Help/module/FindLibXml2.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLibXml2.cmake
diff --git a/Help/module/FindLibXslt.rst b/Help/module/FindLibXslt.rst
new file mode 100644
index 0000000000..4107170cf5
--- /dev/null
+++ b/Help/module/FindLibXslt.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLibXslt.cmake
diff --git a/Help/module/FindLua.rst b/Help/module/FindLua.rst
new file mode 100644
index 0000000000..977e5bfce2
--- /dev/null
+++ b/Help/module/FindLua.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLua.cmake
diff --git a/Help/module/FindLua50.rst b/Help/module/FindLua50.rst
new file mode 100644
index 0000000000..0353fc35e2
--- /dev/null
+++ b/Help/module/FindLua50.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLua50.cmake
diff --git a/Help/module/FindLua51.rst b/Help/module/FindLua51.rst
new file mode 100644
index 0000000000..672ff357b5
--- /dev/null
+++ b/Help/module/FindLua51.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLua51.cmake
diff --git a/Help/module/FindMFC.rst b/Help/module/FindMFC.rst
new file mode 100644
index 0000000000..a3226a690d
--- /dev/null
+++ b/Help/module/FindMFC.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindMFC.cmake
diff --git a/Help/module/FindMPEG.rst b/Help/module/FindMPEG.rst
new file mode 100644
index 0000000000..c9ce48142c
--- /dev/null
+++ b/Help/module/FindMPEG.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindMPEG.cmake
diff --git a/Help/module/FindMPEG2.rst b/Help/module/FindMPEG2.rst
new file mode 100644
index 0000000000..f843c8971c
--- /dev/null
+++ b/Help/module/FindMPEG2.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindMPEG2.cmake
diff --git a/Help/module/FindMPI.rst b/Help/module/FindMPI.rst
new file mode 100644
index 0000000000..fad10c7325
--- /dev/null
+++ b/Help/module/FindMPI.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindMPI.cmake
diff --git a/Help/module/FindMatlab.rst b/Help/module/FindMatlab.rst
new file mode 100644
index 0000000000..43f861adc0
--- /dev/null
+++ b/Help/module/FindMatlab.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindMatlab.cmake
diff --git a/Help/module/FindMotif.rst b/Help/module/FindMotif.rst
new file mode 100644
index 0000000000..e602a501c2
--- /dev/null
+++ b/Help/module/FindMotif.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindMotif.cmake
diff --git a/Help/module/FindOpenAL.rst b/Help/module/FindOpenAL.rst
new file mode 100644
index 0000000000..f0865569d8
--- /dev/null
+++ b/Help/module/FindOpenAL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindOpenAL.cmake
diff --git a/Help/module/FindOpenCL.rst b/Help/module/FindOpenCL.rst
new file mode 100644
index 0000000000..e87e289bda
--- /dev/null
+++ b/Help/module/FindOpenCL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindOpenCL.cmake
diff --git a/Help/module/FindOpenGL.rst b/Help/module/FindOpenGL.rst
new file mode 100644
index 0000000000..85e89bcb32
--- /dev/null
+++ b/Help/module/FindOpenGL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindOpenGL.cmake
diff --git a/Help/module/FindOpenMP.rst b/Help/module/FindOpenMP.rst
new file mode 100644
index 0000000000..01362abfba
--- /dev/null
+++ b/Help/module/FindOpenMP.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindOpenMP.cmake
diff --git a/Help/module/FindOpenSSL.rst b/Help/module/FindOpenSSL.rst
new file mode 100644
index 0000000000..f622bb14e5
--- /dev/null
+++ b/Help/module/FindOpenSSL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindOpenSSL.cmake
diff --git a/Help/module/FindOpenSceneGraph.rst b/Help/module/FindOpenSceneGraph.rst
new file mode 100644
index 0000000000..434649257f
--- /dev/null
+++ b/Help/module/FindOpenSceneGraph.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindOpenSceneGraph.cmake
diff --git a/Help/module/FindOpenThreads.rst b/Help/module/FindOpenThreads.rst
new file mode 100644
index 0000000000..bb3f0f97b0
--- /dev/null
+++ b/Help/module/FindOpenThreads.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindOpenThreads.cmake
diff --git a/Help/module/FindPHP4.rst b/Help/module/FindPHP4.rst
new file mode 100644
index 0000000000..1de62e8d4b
--- /dev/null
+++ b/Help/module/FindPHP4.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPHP4.cmake
diff --git a/Help/module/FindPNG.rst b/Help/module/FindPNG.rst
new file mode 100644
index 0000000000..e6d161875f
--- /dev/null
+++ b/Help/module/FindPNG.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPNG.cmake
diff --git a/Help/module/FindPackageHandleStandardArgs.rst b/Help/module/FindPackageHandleStandardArgs.rst
new file mode 100644
index 0000000000..feda7ef612
--- /dev/null
+++ b/Help/module/FindPackageHandleStandardArgs.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPackageHandleStandardArgs.cmake
diff --git a/Help/module/FindPackageMessage.rst b/Help/module/FindPackageMessage.rst
new file mode 100644
index 0000000000..b682d8c0f2
--- /dev/null
+++ b/Help/module/FindPackageMessage.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPackageMessage.cmake
diff --git a/Help/module/FindPerl.rst b/Help/module/FindPerl.rst
new file mode 100644
index 0000000000..098f4b5456
--- /dev/null
+++ b/Help/module/FindPerl.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPerl.cmake
diff --git a/Help/module/FindPerlLibs.rst b/Help/module/FindPerlLibs.rst
new file mode 100644
index 0000000000..8d8bbab7b3
--- /dev/null
+++ b/Help/module/FindPerlLibs.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPerlLibs.cmake
diff --git a/Help/module/FindPhysFS.rst b/Help/module/FindPhysFS.rst
new file mode 100644
index 0000000000..21d928baba
--- /dev/null
+++ b/Help/module/FindPhysFS.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPhysFS.cmake
diff --git a/Help/module/FindPike.rst b/Help/module/FindPike.rst
new file mode 100644
index 0000000000..b096ca4da2
--- /dev/null
+++ b/Help/module/FindPike.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPike.cmake
diff --git a/Help/module/FindPkgConfig.rst b/Help/module/FindPkgConfig.rst
new file mode 100644
index 0000000000..b8caf7442a
--- /dev/null
+++ b/Help/module/FindPkgConfig.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPkgConfig.cmake
diff --git a/Help/module/FindPostgreSQL.rst b/Help/module/FindPostgreSQL.rst
new file mode 100644
index 0000000000..b45c07e7f5
--- /dev/null
+++ b/Help/module/FindPostgreSQL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPostgreSQL.cmake
diff --git a/Help/module/FindProducer.rst b/Help/module/FindProducer.rst
new file mode 100644
index 0000000000..1c0c575ff6
--- /dev/null
+++ b/Help/module/FindProducer.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindProducer.cmake
diff --git a/Help/module/FindProtobuf.rst b/Help/module/FindProtobuf.rst
new file mode 100644
index 0000000000..b978e010fe
--- /dev/null
+++ b/Help/module/FindProtobuf.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindProtobuf.cmake
diff --git a/Help/module/FindPythonInterp.rst b/Help/module/FindPythonInterp.rst
new file mode 100644
index 0000000000..3be2306922
--- /dev/null
+++ b/Help/module/FindPythonInterp.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPythonInterp.cmake
diff --git a/Help/module/FindPythonLibs.rst b/Help/module/FindPythonLibs.rst
new file mode 100644
index 0000000000..8f0015d33a
--- /dev/null
+++ b/Help/module/FindPythonLibs.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindPythonLibs.cmake
diff --git a/Help/module/FindQt.rst b/Help/module/FindQt.rst
new file mode 100644
index 0000000000..3aa8a26de0
--- /dev/null
+++ b/Help/module/FindQt.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindQt.cmake
diff --git a/Help/module/FindQt3.rst b/Help/module/FindQt3.rst
new file mode 100644
index 0000000000..b933059096
--- /dev/null
+++ b/Help/module/FindQt3.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindQt3.cmake
diff --git a/Help/module/FindQt4.rst b/Help/module/FindQt4.rst
new file mode 100644
index 0000000000..28036b2fd9
--- /dev/null
+++ b/Help/module/FindQt4.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindQt4.cmake
diff --git a/Help/module/FindQuickTime.rst b/Help/module/FindQuickTime.rst
new file mode 100644
index 0000000000..735f7d29fd
--- /dev/null
+++ b/Help/module/FindQuickTime.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindQuickTime.cmake
diff --git a/Help/module/FindRTI.rst b/Help/module/FindRTI.rst
new file mode 100644
index 0000000000..a93ad1658e
--- /dev/null
+++ b/Help/module/FindRTI.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindRTI.cmake
diff --git a/Help/module/FindRuby.rst b/Help/module/FindRuby.rst
new file mode 100644
index 0000000000..a1e7922410
--- /dev/null
+++ b/Help/module/FindRuby.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindRuby.cmake
diff --git a/Help/module/FindSDL.rst b/Help/module/FindSDL.rst
new file mode 100644
index 0000000000..79893c03ce
--- /dev/null
+++ b/Help/module/FindSDL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSDL.cmake
diff --git a/Help/module/FindSDL_image.rst b/Help/module/FindSDL_image.rst
new file mode 100644
index 0000000000..dc69d7070b
--- /dev/null
+++ b/Help/module/FindSDL_image.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSDL_image.cmake
diff --git a/Help/module/FindSDL_mixer.rst b/Help/module/FindSDL_mixer.rst
new file mode 100644
index 0000000000..1c9c446742
--- /dev/null
+++ b/Help/module/FindSDL_mixer.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSDL_mixer.cmake
diff --git a/Help/module/FindSDL_net.rst b/Help/module/FindSDL_net.rst
new file mode 100644
index 0000000000..079d0bbe3a
--- /dev/null
+++ b/Help/module/FindSDL_net.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSDL_net.cmake
diff --git a/Help/module/FindSDL_sound.rst b/Help/module/FindSDL_sound.rst
new file mode 100644
index 0000000000..077edf7005
--- /dev/null
+++ b/Help/module/FindSDL_sound.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSDL_sound.cmake
diff --git a/Help/module/FindSDL_ttf.rst b/Help/module/FindSDL_ttf.rst
new file mode 100644
index 0000000000..40c5ec4c4a
--- /dev/null
+++ b/Help/module/FindSDL_ttf.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSDL_ttf.cmake
diff --git a/Help/module/FindSWIG.rst b/Help/module/FindSWIG.rst
new file mode 100644
index 0000000000..9b25b94b3e
--- /dev/null
+++ b/Help/module/FindSWIG.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSWIG.cmake
diff --git a/Help/module/FindSelfPackers.rst b/Help/module/FindSelfPackers.rst
new file mode 100644
index 0000000000..5f2c689ca8
--- /dev/null
+++ b/Help/module/FindSelfPackers.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSelfPackers.cmake
diff --git a/Help/module/FindSquish.rst b/Help/module/FindSquish.rst
new file mode 100644
index 0000000000..dc2c86d53e
--- /dev/null
+++ b/Help/module/FindSquish.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSquish.cmake
diff --git a/Help/module/FindSubversion.rst b/Help/module/FindSubversion.rst
new file mode 100644
index 0000000000..aa15857d1e
--- /dev/null
+++ b/Help/module/FindSubversion.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindSubversion.cmake
diff --git a/Help/module/FindTCL.rst b/Help/module/FindTCL.rst
new file mode 100644
index 0000000000..cbd203589e
--- /dev/null
+++ b/Help/module/FindTCL.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindTCL.cmake
diff --git a/Help/module/FindTIFF.rst b/Help/module/FindTIFF.rst
new file mode 100644
index 0000000000..69f8ca585a
--- /dev/null
+++ b/Help/module/FindTIFF.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindTIFF.cmake
diff --git a/Help/module/FindTclStub.rst b/Help/module/FindTclStub.rst
new file mode 100644
index 0000000000..6cc5b2df20
--- /dev/null
+++ b/Help/module/FindTclStub.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindTclStub.cmake
diff --git a/Help/module/FindTclsh.rst b/Help/module/FindTclsh.rst
new file mode 100644
index 0000000000..23e7d6b397
--- /dev/null
+++ b/Help/module/FindTclsh.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindTclsh.cmake
diff --git a/Help/module/FindThreads.rst b/Help/module/FindThreads.rst
new file mode 100644
index 0000000000..91967a7a3b
--- /dev/null
+++ b/Help/module/FindThreads.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindThreads.cmake
diff --git a/Help/module/FindUnixCommands.rst b/Help/module/FindUnixCommands.rst
new file mode 100644
index 0000000000..9ad05ad2d8
--- /dev/null
+++ b/Help/module/FindUnixCommands.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindUnixCommands.cmake
diff --git a/Help/module/FindVTK.rst b/Help/module/FindVTK.rst
new file mode 100644
index 0000000000..3bc67c5c9e
--- /dev/null
+++ b/Help/module/FindVTK.rst
@@ -0,0 +1,10 @@
+FindVTK
+-------
+
+This module no longer exists.
+
+This module existed in versions of CMake prior to 3.1, but became
+only a thin wrapper around ``find_package(VTK NO_MODULE)`` to
+provide compatibility for projects using long-outdated conventions.
+Now ``find_package(VTK)`` will search for ``VTKConfig.cmake``
+directly.
diff --git a/Help/module/FindWget.rst b/Help/module/FindWget.rst
new file mode 100644
index 0000000000..06affd4eb4
--- /dev/null
+++ b/Help/module/FindWget.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindWget.cmake
diff --git a/Help/module/FindWish.rst b/Help/module/FindWish.rst
new file mode 100644
index 0000000000..76be4cf548
--- /dev/null
+++ b/Help/module/FindWish.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindWish.cmake
diff --git a/Help/module/FindX11.rst b/Help/module/FindX11.rst
new file mode 100644
index 0000000000..906efd7389
--- /dev/null
+++ b/Help/module/FindX11.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindX11.cmake
diff --git a/Help/module/FindXMLRPC.rst b/Help/module/FindXMLRPC.rst
new file mode 100644
index 0000000000..5d11a0ca8a
--- /dev/null
+++ b/Help/module/FindXMLRPC.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindXMLRPC.cmake
diff --git a/Help/module/FindXerces.rst b/Help/module/FindXerces.rst
new file mode 100644
index 0000000000..166d8dd1a9
--- /dev/null
+++ b/Help/module/FindXerces.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindXerces.cmake
diff --git a/Help/module/FindZLIB.rst b/Help/module/FindZLIB.rst
new file mode 100644
index 0000000000..ded863463a
--- /dev/null
+++ b/Help/module/FindZLIB.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindZLIB.cmake
diff --git a/Help/module/Findosg.rst b/Help/module/Findosg.rst
new file mode 100644
index 0000000000..6b407aca5c
--- /dev/null
+++ b/Help/module/Findosg.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/Findosg.cmake
diff --git a/Help/module/FindosgAnimation.rst b/Help/module/FindosgAnimation.rst
new file mode 100644
index 0000000000..f14a1e7f39
--- /dev/null
+++ b/Help/module/FindosgAnimation.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgAnimation.cmake
diff --git a/Help/module/FindosgDB.rst b/Help/module/FindosgDB.rst
new file mode 100644
index 0000000000..9f72bc7943
--- /dev/null
+++ b/Help/module/FindosgDB.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgDB.cmake
diff --git a/Help/module/FindosgFX.rst b/Help/module/FindosgFX.rst
new file mode 100644
index 0000000000..0e1edfba19
--- /dev/null
+++ b/Help/module/FindosgFX.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgFX.cmake
diff --git a/Help/module/FindosgGA.rst b/Help/module/FindosgGA.rst
new file mode 100644
index 0000000000..562d73fd56
--- /dev/null
+++ b/Help/module/FindosgGA.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgGA.cmake
diff --git a/Help/module/FindosgIntrospection.rst b/Help/module/FindosgIntrospection.rst
new file mode 100644
index 0000000000..53621a71ee
--- /dev/null
+++ b/Help/module/FindosgIntrospection.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgIntrospection.cmake
diff --git a/Help/module/FindosgManipulator.rst b/Help/module/FindosgManipulator.rst
new file mode 100644
index 0000000000..b9d615d379
--- /dev/null
+++ b/Help/module/FindosgManipulator.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgManipulator.cmake
diff --git a/Help/module/FindosgParticle.rst b/Help/module/FindosgParticle.rst
new file mode 100644
index 0000000000..9cf191c37b
--- /dev/null
+++ b/Help/module/FindosgParticle.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgParticle.cmake
diff --git a/Help/module/FindosgPresentation.rst b/Help/module/FindosgPresentation.rst
new file mode 100644
index 0000000000..cb47841bd7
--- /dev/null
+++ b/Help/module/FindosgPresentation.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgPresentation.cmake
diff --git a/Help/module/FindosgProducer.rst b/Help/module/FindosgProducer.rst
new file mode 100644
index 0000000000..c502851b47
--- /dev/null
+++ b/Help/module/FindosgProducer.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgProducer.cmake
diff --git a/Help/module/FindosgQt.rst b/Help/module/FindosgQt.rst
new file mode 100644
index 0000000000..08c870453f
--- /dev/null
+++ b/Help/module/FindosgQt.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgQt.cmake
diff --git a/Help/module/FindosgShadow.rst b/Help/module/FindosgShadow.rst
new file mode 100644
index 0000000000..fbb22e1087
--- /dev/null
+++ b/Help/module/FindosgShadow.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgShadow.cmake
diff --git a/Help/module/FindosgSim.rst b/Help/module/FindosgSim.rst
new file mode 100644
index 0000000000..9e47b65676
--- /dev/null
+++ b/Help/module/FindosgSim.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgSim.cmake
diff --git a/Help/module/FindosgTerrain.rst b/Help/module/FindosgTerrain.rst
new file mode 100644
index 0000000000..dd401d8b24
--- /dev/null
+++ b/Help/module/FindosgTerrain.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgTerrain.cmake
diff --git a/Help/module/FindosgText.rst b/Help/module/FindosgText.rst
new file mode 100644
index 0000000000..bb028fb157
--- /dev/null
+++ b/Help/module/FindosgText.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgText.cmake
diff --git a/Help/module/FindosgUtil.rst b/Help/module/FindosgUtil.rst
new file mode 100644
index 0000000000..bb11bdf4dd
--- /dev/null
+++ b/Help/module/FindosgUtil.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgUtil.cmake
diff --git a/Help/module/FindosgViewer.rst b/Help/module/FindosgViewer.rst
new file mode 100644
index 0000000000..5def375445
--- /dev/null
+++ b/Help/module/FindosgViewer.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgViewer.cmake
diff --git a/Help/module/FindosgVolume.rst b/Help/module/FindosgVolume.rst
new file mode 100644
index 0000000000..d836906e35
--- /dev/null
+++ b/Help/module/FindosgVolume.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgVolume.cmake
diff --git a/Help/module/FindosgWidget.rst b/Help/module/FindosgWidget.rst
new file mode 100644
index 0000000000..bdd11355dc
--- /dev/null
+++ b/Help/module/FindosgWidget.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindosgWidget.cmake
diff --git a/Help/module/Findosg_functions.rst b/Help/module/Findosg_functions.rst
new file mode 100644
index 0000000000..522e1ac164
--- /dev/null
+++ b/Help/module/Findosg_functions.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/Findosg_functions.cmake
diff --git a/Help/module/FindwxWidgets.rst b/Help/module/FindwxWidgets.rst
new file mode 100644
index 0000000000..519beb725d
--- /dev/null
+++ b/Help/module/FindwxWidgets.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindwxWidgets.cmake
diff --git a/Help/module/FindwxWindows.rst b/Help/module/FindwxWindows.rst
new file mode 100644
index 0000000000..35c9728135
--- /dev/null
+++ b/Help/module/FindwxWindows.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindwxWindows.cmake
diff --git a/Help/module/FortranCInterface.rst b/Help/module/FortranCInterface.rst
new file mode 100644
index 0000000000..7afcf154b3
--- /dev/null
+++ b/Help/module/FortranCInterface.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FortranCInterface.cmake
diff --git a/Help/module/GNUInstallDirs.rst b/Help/module/GNUInstallDirs.rst
new file mode 100644
index 0000000000..79d357040f
--- /dev/null
+++ b/Help/module/GNUInstallDirs.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/GNUInstallDirs.cmake
diff --git a/Help/module/GenerateExportHeader.rst b/Help/module/GenerateExportHeader.rst
new file mode 100644
index 0000000000..115713ecdd
--- /dev/null
+++ b/Help/module/GenerateExportHeader.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/GenerateExportHeader.cmake
diff --git a/Help/module/GetPrerequisites.rst b/Help/module/GetPrerequisites.rst
new file mode 100644
index 0000000000..84b20c8761
--- /dev/null
+++ b/Help/module/GetPrerequisites.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/GetPrerequisites.cmake
diff --git a/Help/module/InstallRequiredSystemLibraries.rst b/Help/module/InstallRequiredSystemLibraries.rst
new file mode 100644
index 0000000000..5ea9af33e7
--- /dev/null
+++ b/Help/module/InstallRequiredSystemLibraries.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/InstallRequiredSystemLibraries.cmake
diff --git a/Help/module/MacroAddFileDependencies.rst b/Help/module/MacroAddFileDependencies.rst
new file mode 100644
index 0000000000..5f0bf6bbfa
--- /dev/null
+++ b/Help/module/MacroAddFileDependencies.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/MacroAddFileDependencies.cmake
diff --git a/Help/module/ProcessorCount.rst b/Help/module/ProcessorCount.rst
new file mode 100644
index 0000000000..0149d0924b
--- /dev/null
+++ b/Help/module/ProcessorCount.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/ProcessorCount.cmake
diff --git a/Help/module/SelectLibraryConfigurations.rst b/Help/module/SelectLibraryConfigurations.rst
new file mode 100644
index 0000000000..14fd6f88ae
--- /dev/null
+++ b/Help/module/SelectLibraryConfigurations.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/SelectLibraryConfigurations.cmake
diff --git a/Help/module/SquishTestScript.rst b/Help/module/SquishTestScript.rst
new file mode 100644
index 0000000000..47da404f1f
--- /dev/null
+++ b/Help/module/SquishTestScript.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/SquishTestScript.cmake
diff --git a/Help/module/TestBigEndian.rst b/Help/module/TestBigEndian.rst
new file mode 100644
index 0000000000..f9e4d2f106
--- /dev/null
+++ b/Help/module/TestBigEndian.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/TestBigEndian.cmake
diff --git a/Help/module/TestCXXAcceptsFlag.rst b/Help/module/TestCXXAcceptsFlag.rst
new file mode 100644
index 0000000000..ee3d70a714
--- /dev/null
+++ b/Help/module/TestCXXAcceptsFlag.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/TestCXXAcceptsFlag.cmake
diff --git a/Help/module/TestForANSIForScope.rst b/Help/module/TestForANSIForScope.rst
new file mode 100644
index 0000000000..00d923803a
--- /dev/null
+++ b/Help/module/TestForANSIForScope.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/TestForANSIForScope.cmake
diff --git a/Help/module/TestForANSIStreamHeaders.rst b/Help/module/TestForANSIStreamHeaders.rst
new file mode 100644
index 0000000000..212a30b79b
--- /dev/null
+++ b/Help/module/TestForANSIStreamHeaders.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/TestForANSIStreamHeaders.cmake
diff --git a/Help/module/TestForSSTREAM.rst b/Help/module/TestForSSTREAM.rst
new file mode 100644
index 0000000000..d1547519e6
--- /dev/null
+++ b/Help/module/TestForSSTREAM.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/TestForSSTREAM.cmake
diff --git a/Help/module/TestForSTDNamespace.rst b/Help/module/TestForSTDNamespace.rst
new file mode 100644
index 0000000000..ad989e3670
--- /dev/null
+++ b/Help/module/TestForSTDNamespace.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/TestForSTDNamespace.cmake
diff --git a/Help/module/UseEcos.rst b/Help/module/UseEcos.rst
new file mode 100644
index 0000000000..0e578685a0
--- /dev/null
+++ b/Help/module/UseEcos.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/UseEcos.cmake
diff --git a/Help/module/UseJava.rst b/Help/module/UseJava.rst
new file mode 100644
index 0000000000..fa2f1bd6ff
--- /dev/null
+++ b/Help/module/UseJava.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/UseJava.cmake
diff --git a/Help/module/UseJavaClassFilelist.rst b/Help/module/UseJavaClassFilelist.rst
new file mode 100644
index 0000000000..b9cd4769e4
--- /dev/null
+++ b/Help/module/UseJavaClassFilelist.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/UseJavaClassFilelist.cmake
diff --git a/Help/module/UseJavaSymlinks.rst b/Help/module/UseJavaSymlinks.rst
new file mode 100644
index 0000000000..2fab8e8dd3
--- /dev/null
+++ b/Help/module/UseJavaSymlinks.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/UseJavaSymlinks.cmake
diff --git a/Help/module/UsePkgConfig.rst b/Help/module/UsePkgConfig.rst
new file mode 100644
index 0000000000..668f7662b3
--- /dev/null
+++ b/Help/module/UsePkgConfig.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/UsePkgConfig.cmake
diff --git a/Help/module/UseSWIG.rst b/Help/module/UseSWIG.rst
new file mode 100644
index 0000000000..0007c355c1
--- /dev/null
+++ b/Help/module/UseSWIG.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/UseSWIG.cmake
diff --git a/Help/module/Use_wxWindows.rst b/Help/module/Use_wxWindows.rst
new file mode 100644
index 0000000000..a489e9849e
--- /dev/null
+++ b/Help/module/Use_wxWindows.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/Use_wxWindows.cmake
diff --git a/Help/module/UsewxWidgets.rst b/Help/module/UsewxWidgets.rst
new file mode 100644
index 0000000000..6829c2d2b3
--- /dev/null
+++ b/Help/module/UsewxWidgets.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/UsewxWidgets.cmake
diff --git a/Help/module/WriteBasicConfigVersionFile.rst b/Help/module/WriteBasicConfigVersionFile.rst
new file mode 100644
index 0000000000..c637d5dc21
--- /dev/null
+++ b/Help/module/WriteBasicConfigVersionFile.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/WriteBasicConfigVersionFile.cmake
diff --git a/Help/module/WriteCompilerDetectionHeader.rst b/Help/module/WriteCompilerDetectionHeader.rst
new file mode 100644
index 0000000000..4c81b48838
--- /dev/null
+++ b/Help/module/WriteCompilerDetectionHeader.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/WriteCompilerDetectionHeader.cmake
diff --git a/Help/policy/CMP0000.rst b/Help/policy/CMP0000.rst
new file mode 100644
index 0000000000..9fbf842be1
--- /dev/null
+++ b/Help/policy/CMP0000.rst
@@ -0,0 +1,30 @@
+CMP0000
+-------
+
+A minimum required CMake version must be specified.
+
+CMake requires that projects specify the version of CMake to which
+they have been written. This policy has been put in place so users
+trying to build the project may be told when they need to update their
+CMake. Specifying a version also helps the project build with CMake
+versions newer than that specified. Use the cmake_minimum_required
+command at the top of your main CMakeLists.txt file:
+
+::
+
+ cmake_minimum_required(VERSION <major>.<minor>)
+
+where "<major>.<minor>" is the version of CMake you want to support
+(such as "2.6"). The command will ensure that at least the given
+version of CMake is running and help newer versions be compatible with
+the project. See documentation of cmake_minimum_required for details.
+
+Note that the command invocation must appear in the CMakeLists.txt
+file itself; a call in an included file is not sufficient. However,
+the cmake_policy command may be called to set policy CMP0000 to OLD or
+NEW behavior explicitly. The OLD behavior is to silently ignore the
+missing invocation. The NEW behavior is to issue an error instead of
+a warning. An included file may set CMP0000 explicitly to affect how
+this policy is enforced for the main CMakeLists.txt file.
+
+This policy was introduced in CMake version 2.6.0.
diff --git a/Help/policy/CMP0001.rst b/Help/policy/CMP0001.rst
new file mode 100644
index 0000000000..344f1e2ae3
--- /dev/null
+++ b/Help/policy/CMP0001.rst
@@ -0,0 +1,19 @@
+CMP0001
+-------
+
+CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.
+
+The OLD behavior is to check CMAKE_BACKWARDS_COMPATIBILITY and present
+it to the user. The NEW behavior is to ignore
+CMAKE_BACKWARDS_COMPATIBILITY completely.
+
+In CMake 2.4 and below the variable CMAKE_BACKWARDS_COMPATIBILITY was
+used to request compatibility with earlier versions of CMake. In
+CMake 2.6 and above all compatibility issues are handled by policies
+and the cmake_policy command. However, CMake must still check
+CMAKE_BACKWARDS_COMPATIBILITY for projects written for CMake 2.4 and
+below.
+
+This policy was introduced in CMake version 2.6.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.
diff --git a/Help/policy/CMP0002.rst b/Help/policy/CMP0002.rst
new file mode 100644
index 0000000000..2c15bd44cc
--- /dev/null
+++ b/Help/policy/CMP0002.rst
@@ -0,0 +1,26 @@
+CMP0002
+-------
+
+Logical target names must be globally unique.
+
+Targets names created with add_executable, add_library, or
+add_custom_target are logical build target names. Logical target
+names must be globally unique because:
+
+::
+
+ - Unique names may be referenced unambiguously both in CMake
+ code and on make tool command lines.
+ - Logical names are used by Xcode and VS IDE generators
+ to produce meaningful project names for the targets.
+
+The logical name of executable and library targets does not have to
+correspond to the physical file names built. Consider using the
+OUTPUT_NAME target property to create two targets with the same
+physical name while keeping logical names distinct. Custom targets
+must simply have globally unique names (unless one uses the global
+property ALLOW_DUPLICATE_CUSTOM_TARGETS with a Makefiles generator).
+
+This policy was introduced in CMake version 2.6.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.
diff --git a/Help/policy/CMP0003.rst b/Help/policy/CMP0003.rst
new file mode 100644
index 0000000000..27b83f8ad1
--- /dev/null
+++ b/Help/policy/CMP0003.rst
@@ -0,0 +1,102 @@
+CMP0003
+-------
+
+Libraries linked via full path no longer produce linker search paths.
+
+This policy affects how libraries whose full paths are NOT known are
+found at link time, but was created due to a change in how CMake deals
+with libraries whose full paths are known. Consider the code
+
+::
+
+ target_link_libraries(myexe /path/to/libA.so)
+
+CMake 2.4 and below implemented linking to libraries whose full paths
+are known by splitting them on the link line into separate components
+consisting of the linker search path and the library name. The
+example code might have produced something like
+
+::
+
+ ... -L/path/to -lA ...
+
+in order to link to library A. An analysis was performed to order
+multiple link directories such that the linker would find library A in
+the desired location, but there are cases in which this does not work.
+CMake versions 2.6 and above use the more reliable approach of passing
+the full path to libraries directly to the linker in most cases. The
+example code now produces something like
+
+::
+
+ ... /path/to/libA.so ....
+
+Unfortunately this change can break code like
+
+::
+
+ target_link_libraries(myexe /path/to/libA.so B)
+
+where "B" is meant to find "/path/to/libB.so". This code is wrong
+because the user is asking the linker to find library B but has not
+provided a linker search path (which may be added with the
+link_directories command). However, with the old linking
+implementation the code would work accidentally because the linker
+search path added for library A allowed library B to be found.
+
+In order to support projects depending on linker search paths added by
+linking to libraries with known full paths, the OLD behavior for this
+policy will add the linker search paths even though they are not
+needed for their own libraries. When this policy is set to OLD, CMake
+will produce a link line such as
+
+::
+
+ ... -L/path/to /path/to/libA.so -lB ...
+
+which will allow library B to be found as it was previously. When
+this policy is set to NEW, CMake will produce a link line such as
+
+::
+
+ ... /path/to/libA.so -lB ...
+
+which more accurately matches what the project specified.
+
+The setting for this policy used when generating the link line is that
+in effect when the target is created by an add_executable or
+add_library command. For the example described above, the code
+
+::
+
+ cmake_policy(SET CMP0003 OLD) # or cmake_policy(VERSION 2.4)
+ add_executable(myexe myexe.c)
+ target_link_libraries(myexe /path/to/libA.so B)
+
+will work and suppress the warning for this policy. It may also be
+updated to work with the corrected linking approach:
+
+::
+
+ cmake_policy(SET CMP0003 NEW) # or cmake_policy(VERSION 2.6)
+ link_directories(/path/to) # needed to find library B
+ add_executable(myexe myexe.c)
+ target_link_libraries(myexe /path/to/libA.so B)
+
+Even better, library B may be specified with a full path:
+
+::
+
+ add_executable(myexe myexe.c)
+ target_link_libraries(myexe /path/to/libA.so /path/to/libB.so)
+
+When all items on the link line have known paths CMake does not check
+this policy so it has no effect.
+
+Note that the warning for this policy will be issued for at most one
+target. This avoids flooding users with messages for every target
+when setting the policy once will probably fix all targets.
+
+This policy was introduced in CMake version 2.6.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.
diff --git a/Help/policy/CMP0004.rst b/Help/policy/CMP0004.rst
new file mode 100644
index 0000000000..80045f5a1a
--- /dev/null
+++ b/Help/policy/CMP0004.rst
@@ -0,0 +1,23 @@
+CMP0004
+-------
+
+Libraries linked may not have leading or trailing whitespace.
+
+CMake versions 2.4 and below silently removed leading and trailing
+whitespace from libraries linked with code like
+
+::
+
+ target_link_libraries(myexe " A ")
+
+This could lead to subtle errors in user projects.
+
+The OLD behavior for this policy is to silently remove leading and
+trailing whitespace. The NEW behavior for this policy is to diagnose
+the existence of such whitespace as an error. The setting for this
+policy used when checking the library names is that in effect when the
+target is created by an add_executable or add_library command.
+
+This policy was introduced in CMake version 2.6.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.
diff --git a/Help/policy/CMP0005.rst b/Help/policy/CMP0005.rst
new file mode 100644
index 0000000000..c11a9e6eff
--- /dev/null
+++ b/Help/policy/CMP0005.rst
@@ -0,0 +1,24 @@
+CMP0005
+-------
+
+Preprocessor definition values are now escaped automatically.
+
+This policy determines whether or not CMake should generate escaped
+preprocessor definition values added via add_definitions. CMake
+versions 2.4 and below assumed that only trivial values would be given
+for macros in add_definitions calls. It did not attempt to escape
+non-trivial values such as string literals in generated build rules.
+CMake versions 2.6 and above support escaping of most values, but
+cannot assume the user has not added escapes already in an attempt to
+work around limitations in earlier versions.
+
+The OLD behavior for this policy is to place definition values given
+to add_definitions directly in the generated build rules without
+attempting to escape anything. The NEW behavior for this policy is to
+generate correct escapes for all native build tools automatically.
+See documentation of the COMPILE_DEFINITIONS target property for
+limitations of the escaping implementation.
+
+This policy was introduced in CMake version 2.6.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.
diff --git a/Help/policy/CMP0006.rst b/Help/policy/CMP0006.rst
new file mode 100644
index 0000000000..8d1e5bdd3d
--- /dev/null
+++ b/Help/policy/CMP0006.rst
@@ -0,0 +1,22 @@
+CMP0006
+-------
+
+Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.
+
+This policy determines whether the install(TARGETS) command must be
+given a BUNDLE DESTINATION when asked to install a target with the
+MACOSX_BUNDLE property set. CMake 2.4 and below did not distinguish
+application bundles from normal executables when installing targets.
+CMake 2.6 provides a BUNDLE option to the install(TARGETS) command
+that specifies rules specific to application bundles on the Mac.
+Projects should use this option when installing a target with the
+MACOSX_BUNDLE property set.
+
+The OLD behavior for this policy is to fall back to the RUNTIME
+DESTINATION if a BUNDLE DESTINATION is not given. The NEW behavior
+for this policy is to produce an error if a bundle target is installed
+without a BUNDLE DESTINATION.
+
+This policy was introduced in CMake version 2.6.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.
diff --git a/Help/policy/CMP0007.rst b/Help/policy/CMP0007.rst
new file mode 100644
index 0000000000..f0d8c1603f
--- /dev/null
+++ b/Help/policy/CMP0007.rst
@@ -0,0 +1,15 @@
+CMP0007
+-------
+
+list command no longer ignores empty elements.
+
+This policy determines whether the list command will ignore empty
+elements in the list. CMake 2.4 and below list commands ignored all
+empty elements in the list. For example, a;b;;c would have length 3
+and not 4. The OLD behavior for this policy is to ignore empty list
+elements. The NEW behavior for this policy is to correctly count
+empty elements in a list.
+
+This policy was introduced in CMake version 2.6.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.
diff --git a/Help/policy/CMP0008.rst b/Help/policy/CMP0008.rst
new file mode 100644
index 0000000000..b118ece143
--- /dev/null
+++ b/Help/policy/CMP0008.rst
@@ -0,0 +1,32 @@
+CMP0008
+-------
+
+Libraries linked by full-path must have a valid library file name.
+
+In CMake 2.4 and below it is possible to write code like
+
+::
+
+ target_link_libraries(myexe /full/path/to/somelib)
+
+where "somelib" is supposed to be a valid library file name such as
+"libsomelib.a" or "somelib.lib". For Makefile generators this
+produces an error at build time because the dependency on the full
+path cannot be found. For VS IDE and Xcode generators this used to
+work by accident because CMake would always split off the library
+directory and ask the linker to search for the library by name
+(-lsomelib or somelib.lib). Despite the failure with Makefiles, some
+projects have code like this and build only with VS and/or Xcode.
+This version of CMake prefers to pass the full path directly to the
+native build tool, which will fail in this case because it does not
+name a valid library file.
+
+This policy determines what to do with full paths that do not appear
+to name a valid library file. The OLD behavior for this policy is to
+split the library name from the path and ask the linker to search for
+it. The NEW behavior for this policy is to trust the given path and
+pass it directly to the native build tool unchanged.
+
+This policy was introduced in CMake version 2.6.1. 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.
diff --git a/Help/policy/CMP0009.rst b/Help/policy/CMP0009.rst
new file mode 100644
index 0000000000..481af1a54c
--- /dev/null
+++ b/Help/policy/CMP0009.rst
@@ -0,0 +1,19 @@
+CMP0009
+-------
+
+FILE GLOB_RECURSE calls should not follow symlinks by default.
+
+In CMake 2.6.1 and below, FILE GLOB_RECURSE calls would follow through
+symlinks, sometimes coming up with unexpectedly large result sets
+because of symlinks to top level directories that contain hundreds of
+thousands of files.
+
+This policy determines whether or not to follow symlinks encountered
+during a FILE GLOB_RECURSE call. The OLD behavior for this policy is
+to follow the symlinks. The NEW behavior for this policy is not to
+follow the symlinks by default, but only if FOLLOW_SYMLINKS is given
+as an additional argument to the FILE command.
+
+This policy was introduced in CMake version 2.6.2. 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.
diff --git a/Help/policy/CMP0010.rst b/Help/policy/CMP0010.rst
new file mode 100644
index 0000000000..9d2eb7636c
--- /dev/null
+++ b/Help/policy/CMP0010.rst
@@ -0,0 +1,18 @@
+CMP0010
+-------
+
+Bad variable reference syntax is an error.
+
+In CMake 2.6.2 and below, incorrect variable reference syntax such as
+a missing close-brace ("${FOO") was reported but did not stop
+processing of CMake code. This policy determines whether a bad
+variable reference is an error. The OLD behavior for this policy is
+to warn about the error, leave the string untouched, and continue.
+The NEW behavior for this policy is to report an error.
+
+If :policy:`CMP0053` is set to ``NEW``, this policy has no effect
+and is treated as always being ``NEW``.
+
+This policy was introduced in CMake version 2.6.3. 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.
diff --git a/Help/policy/CMP0011.rst b/Help/policy/CMP0011.rst
new file mode 100644
index 0000000000..0f41fffad3
--- /dev/null
+++ b/Help/policy/CMP0011.rst
@@ -0,0 +1,22 @@
+CMP0011
+-------
+
+Included scripts do automatic cmake_policy PUSH and POP.
+
+In CMake 2.6.2 and below, CMake Policy settings in scripts loaded by
+the include() and find_package() commands would affect the includer.
+Explicit invocations of cmake_policy(PUSH) and cmake_policy(POP) were
+required to isolate policy changes and protect the includer. While
+some scripts intend to affect the policies of their includer, most do
+not. In CMake 2.6.3 and above, include() and find_package() by
+default PUSH and POP an entry on the policy stack around an included
+script, but provide a NO_POLICY_SCOPE option to disable it. This
+policy determines whether or not to imply NO_POLICY_SCOPE for
+compatibility. The OLD behavior for this policy is to imply
+NO_POLICY_SCOPE for include() and find_package() commands. The NEW
+behavior for this policy is to allow the commands to do their default
+cmake_policy PUSH and POP.
+
+This policy was introduced in CMake version 2.6.3. 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.
diff --git a/Help/policy/CMP0012.rst b/Help/policy/CMP0012.rst
new file mode 100644
index 0000000000..7a749bf0d7
--- /dev/null
+++ b/Help/policy/CMP0012.rst
@@ -0,0 +1,25 @@
+CMP0012
+-------
+
+if() recognizes numbers and boolean constants.
+
+In CMake versions 2.6.4 and lower the if() command implicitly
+dereferenced arguments corresponding to variables, even those named
+like numbers or boolean constants, except for 0 and 1. Numbers and
+boolean constants such as true, false, yes, no, on, off, y, n,
+notfound, ignore (all case insensitive) were recognized in some cases
+but not all. For example, the code "if(TRUE)" might have evaluated as
+false. Numbers such as 2 were recognized only in boolean expressions
+like "if(NOT 2)" (leading to false) but not as a single-argument like
+"if(2)" (also leading to false). Later versions of CMake prefer to
+treat numbers and boolean constants literally, so they should not be
+used as variable names.
+
+The OLD behavior for this policy is to implicitly dereference
+variables named like numbers and boolean constants. The NEW behavior
+for this policy is to recognize numbers and boolean constants without
+dereferencing variables with such names.
+
+This policy was introduced in CMake version 2.8.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.
diff --git a/Help/policy/CMP0013.rst b/Help/policy/CMP0013.rst
new file mode 100644
index 0000000000..e99997b6b1
--- /dev/null
+++ b/Help/policy/CMP0013.rst
@@ -0,0 +1,19 @@
+CMP0013
+-------
+
+Duplicate binary directories are not allowed.
+
+CMake 2.6.3 and below silently permitted add_subdirectory() calls to
+create the same binary directory multiple times. During build system
+generation files would be written and then overwritten in the build
+tree and could lead to strange behavior. CMake 2.6.4 and above
+explicitly detect duplicate binary directories. CMake 2.6.4 always
+considers this case an error. In CMake 2.8.0 and above this policy
+determines whether or not the case is an error. The OLD behavior for
+this policy is to allow duplicate binary directories. The NEW
+behavior for this policy is to disallow duplicate binary directories
+with an error.
+
+This policy was introduced in CMake version 2.8.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.
diff --git a/Help/policy/CMP0014.rst b/Help/policy/CMP0014.rst
new file mode 100644
index 0000000000..37178d12de
--- /dev/null
+++ b/Help/policy/CMP0014.rst
@@ -0,0 +1,15 @@
+CMP0014
+-------
+
+Input directories must have CMakeLists.txt.
+
+CMake versions before 2.8 silently ignored missing CMakeLists.txt
+files in directories referenced by add_subdirectory() or subdirs(),
+treating them as if present but empty. In CMake 2.8.0 and above this
+policy determines whether or not the case is an error. The OLD
+behavior for this policy is to silently ignore the problem. The NEW
+behavior for this policy is to report an error.
+
+This policy was introduced in CMake version 2.8.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.
diff --git a/Help/policy/CMP0015.rst b/Help/policy/CMP0015.rst
new file mode 100644
index 0000000000..1b549790a6
--- /dev/null
+++ b/Help/policy/CMP0015.rst
@@ -0,0 +1,17 @@
+CMP0015
+-------
+
+link_directories() treats paths relative to the source dir.
+
+In CMake 2.8.0 and lower the link_directories() command passed
+relative paths unchanged to the linker. In CMake 2.8.1 and above the
+link_directories() command prefers to interpret relative paths with
+respect to CMAKE_CURRENT_SOURCE_DIR, which is consistent with
+include_directories() and other commands. The OLD behavior for this
+policy is to use relative paths verbatim in the linker command. The
+NEW behavior for this policy is to convert relative paths to absolute
+paths by appending the relative path to CMAKE_CURRENT_SOURCE_DIR.
+
+This policy was introduced in CMake version 2.8.1. 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.
diff --git a/Help/policy/CMP0016.rst b/Help/policy/CMP0016.rst
new file mode 100644
index 0000000000..743b1a9c55
--- /dev/null
+++ b/Help/policy/CMP0016.rst
@@ -0,0 +1,13 @@
+CMP0016
+-------
+
+target_link_libraries() reports error if its only argument is not a target.
+
+In CMake 2.8.2 and lower the target_link_libraries() command silently
+ignored if it was called with only one argument, and this argument
+wasn't a valid target. In CMake 2.8.3 and above it reports an error
+in this case.
+
+This policy was introduced in CMake version 2.8.3. 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.
diff --git a/Help/policy/CMP0017.rst b/Help/policy/CMP0017.rst
new file mode 100644
index 0000000000..f74e6f0cfb
--- /dev/null
+++ b/Help/policy/CMP0017.rst
@@ -0,0 +1,19 @@
+CMP0017
+-------
+
+Prefer files from the CMake module directory when including from there.
+
+Starting with CMake 2.8.4, if a cmake-module shipped with CMake (i.e.
+located in the CMake module directory) calls include() or
+find_package(), the files located in the CMake module directory are
+preferred over the files in CMAKE_MODULE_PATH. This makes sure that
+the modules belonging to CMake always get those files included which
+they expect, and against which they were developed and tested. In all
+other cases, the files found in CMAKE_MODULE_PATH still take
+precedence over the ones in the CMake module directory. The OLD
+behavior is to always prefer files from CMAKE_MODULE_PATH over files
+from the CMake modules directory.
+
+This policy was introduced in CMake version 2.8.4. 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.
diff --git a/Help/policy/CMP0018.rst b/Help/policy/CMP0018.rst
new file mode 100644
index 0000000000..0f6826771c
--- /dev/null
+++ b/Help/policy/CMP0018.rst
@@ -0,0 +1,32 @@
+CMP0018
+-------
+
+Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.
+
+CMake 2.8.8 and lower compiled sources in SHARED and MODULE libraries
+using the value of the undocumented CMAKE_SHARED_LIBRARY_<Lang>_FLAGS
+platform variable. The variable contained platform-specific flags
+needed to compile objects for shared libraries. Typically it included
+a flag such as -fPIC for position independent code but also included
+other flags needed on certain platforms. CMake 2.8.9 and higher
+prefer instead to use the POSITION_INDEPENDENT_CODE target property to
+determine what targets should be position independent, and new
+undocumented platform variables to select flags while ignoring
+CMAKE_SHARED_LIBRARY_<Lang>_FLAGS completely.
+
+The default for either approach produces identical compilation flags,
+but if a project modifies CMAKE_SHARED_LIBRARY_<Lang>_FLAGS from its
+original value this policy determines which approach to use.
+
+The OLD behavior for this policy is to ignore the
+POSITION_INDEPENDENT_CODE property for all targets and use the
+modified value of CMAKE_SHARED_LIBRARY_<Lang>_FLAGS for SHARED and
+MODULE libraries.
+
+The NEW behavior for this policy is to ignore
+CMAKE_SHARED_LIBRARY_<Lang>_FLAGS whether it is modified or not and
+honor the POSITION_INDEPENDENT_CODE target property.
+
+This policy was introduced in CMake version 2.8.9. 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.
diff --git a/Help/policy/CMP0019.rst b/Help/policy/CMP0019.rst
new file mode 100644
index 0000000000..2b37fa1d7c
--- /dev/null
+++ b/Help/policy/CMP0019.rst
@@ -0,0 +1,20 @@
+CMP0019
+-------
+
+Do not re-expand variables in include and link information.
+
+CMake 2.8.10 and lower re-evaluated values given to the
+include_directories, link_directories, and link_libraries commands to
+expand any leftover variable references at the end of the
+configuration step. This was for strict compatibility with VERY early
+CMake versions because all variable references are now normally
+evaluated during CMake language processing. CMake 2.8.11 and higher
+prefer to skip the extra evaluation.
+
+The OLD behavior for this policy is to re-evaluate the values for
+strict compatibility. The NEW behavior for this policy is to leave
+the values untouched.
+
+This policy was introduced in CMake version 2.8.11. 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.
diff --git a/Help/policy/CMP0020.rst b/Help/policy/CMP0020.rst
new file mode 100644
index 0000000000..6767d08bb6
--- /dev/null
+++ b/Help/policy/CMP0020.rst
@@ -0,0 +1,25 @@
+CMP0020
+-------
+
+Automatically link Qt executables to qtmain target on Windows.
+
+CMake 2.8.10 and lower required users of Qt to always specify a link
+dependency to the qtmain.lib static library manually on Windows.
+CMake 2.8.11 gained the ability to evaluate generator expressions
+while determining the link dependencies from IMPORTED targets. This
+allows CMake itself to automatically link executables which link to Qt
+to the qtmain.lib library when using IMPORTED Qt targets. For
+applications already linking to qtmain.lib, this should have little
+impact. For applications which supply their own alternative WinMain
+implementation and for applications which use the QAxServer library,
+this automatic linking will need to be disabled as per the
+documentation.
+
+The OLD behavior for this policy is not to link executables to
+qtmain.lib automatically when they link to the QtCore IMPORTED target.
+The NEW behavior for this policy is to link executables to qtmain.lib
+automatically when they link to QtCore IMPORTED target.
+
+This policy was introduced in CMake version 2.8.11. 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.
diff --git a/Help/policy/CMP0021.rst b/Help/policy/CMP0021.rst
new file mode 100644
index 0000000000..3f5bd03168
--- /dev/null
+++ b/Help/policy/CMP0021.rst
@@ -0,0 +1,18 @@
+CMP0021
+-------
+
+Fatal error on relative paths in INCLUDE_DIRECTORIES target property.
+
+CMake 2.8.10.2 and lower allowed the INCLUDE_DIRECTORIES target
+property to contain relative paths. The base path for such relative
+entries is not well defined. CMake 2.8.12 issues a FATAL_ERROR if the
+INCLUDE_DIRECTORIES property contains a relative path.
+
+The OLD behavior for this policy is not to warn about relative paths
+in the INCLUDE_DIRECTORIES target property. The NEW behavior for this
+policy is to issue a FATAL_ERROR if INCLUDE_DIRECTORIES contains a
+relative path.
+
+This policy was introduced in CMake version 2.8.12. 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.
diff --git a/Help/policy/CMP0022.rst b/Help/policy/CMP0022.rst
new file mode 100644
index 0000000000..22c7c4fdc1
--- /dev/null
+++ b/Help/policy/CMP0022.rst
@@ -0,0 +1,37 @@
+CMP0022
+-------
+
+INTERFACE_LINK_LIBRARIES defines the link interface.
+
+CMake 2.8.11 constructed the 'link interface' of a target from
+properties matching ``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?``.
+The modern way to specify config-sensitive content is to use generator
+expressions and the ``IMPORTED_`` prefix makes uniform processing of the
+link interface with generator expressions impossible. The
+INTERFACE_LINK_LIBRARIES target property was introduced as a
+replacement in CMake 2.8.12. This new property is named consistently
+with the INTERFACE_COMPILE_DEFINITIONS, INTERFACE_INCLUDE_DIRECTORIES
+and INTERFACE_COMPILE_OPTIONS properties. For in-build targets, CMake
+will use the INTERFACE_LINK_LIBRARIES property as the source of the
+link interface only if policy CMP0022 is NEW. When exporting a target
+which has this policy set to NEW, only the INTERFACE_LINK_LIBRARIES
+property will be processed and generated for the IMPORTED target by
+default. A new option to the install(EXPORT) and export commands
+allows export of the old-style properties for compatibility with
+downstream users of CMake versions older than 2.8.12. The
+target_link_libraries command will no longer populate the properties
+matching LINK_INTERFACE_LIBRARIES(_<CONFIG>)? if this policy is NEW.
+
+Warning-free future-compatible code which works with CMake 2.8.7 onwards
+can be written by using the ``LINK_PRIVATE`` and ``LINK_PUBLIC`` keywords
+of :command:`target_link_libraries`.
+
+The OLD behavior for this policy is to ignore the
+INTERFACE_LINK_LIBRARIES property for in-build targets. The NEW
+behavior for this policy is to use the INTERFACE_LINK_LIBRARIES
+property for in-build targets, and ignore the old properties matching
+``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?``.
+
+This policy was introduced in CMake version 2.8.12. 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.
diff --git a/Help/policy/CMP0023.rst b/Help/policy/CMP0023.rst
new file mode 100644
index 0000000000..962b624cf5
--- /dev/null
+++ b/Help/policy/CMP0023.rst
@@ -0,0 +1,33 @@
+CMP0023
+-------
+
+Plain and keyword target_link_libraries signatures cannot be mixed.
+
+CMake 2.8.12 introduced the target_link_libraries signature using the
+PUBLIC, PRIVATE, and INTERFACE keywords to generalize the LINK_PUBLIC
+and LINK_PRIVATE keywords introduced in CMake 2.8.7. Use of
+signatures with any of these keywords sets the link interface of a
+target explicitly, even if empty. This produces confusing behavior
+when used in combination with the historical behavior of the plain
+target_link_libraries signature. For example, consider the code:
+
+::
+
+ target_link_libraries(mylib A)
+ target_link_libraries(mylib PRIVATE B)
+
+After the first line the link interface has not been set explicitly so
+CMake would use the link implementation, A, as the link interface.
+However, the second line sets the link interface to empty. In order
+to avoid this subtle behavior CMake now prefers to disallow mixing the
+plain and keyword signatures of target_link_libraries for a single
+target.
+
+The OLD behavior for this policy is to allow keyword and plain
+target_link_libraries signatures to be mixed. The NEW behavior for
+this policy is to not to allow mixing of the keyword and plain
+signatures.
+
+This policy was introduced in CMake version 2.8.12. 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.
diff --git a/Help/policy/CMP0024.rst b/Help/policy/CMP0024.rst
new file mode 100644
index 0000000000..ee53d5f5ee
--- /dev/null
+++ b/Help/policy/CMP0024.rst
@@ -0,0 +1,22 @@
+CMP0024
+-------
+
+Disallow include export result.
+
+CMake 2.8.12 and lower allowed use of the include() command with the
+result of the export() command. This relies on the assumption that
+the export() command has an immediate effect at configure-time during
+a cmake run. Certain properties of targets are not fully determined
+until later at generate-time, such as the link language and complete
+list of link libraries. Future refactoring will change the effect of
+the export() command to be executed at generate-time. Use ALIAS
+targets instead in cases where the goal is to refer to targets by
+another name.
+
+The OLD behavior for this policy is to allow including the result of
+an export() command. The NEW behavior for this policy is not to
+allow including the result of an export() command.
+
+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.
diff --git a/Help/policy/CMP0025.rst b/Help/policy/CMP0025.rst
new file mode 100644
index 0000000000..8d19edfa68
--- /dev/null
+++ b/Help/policy/CMP0025.rst
@@ -0,0 +1,27 @@
+CMP0025
+-------
+
+Compiler id for Apple Clang is now ``AppleClang``.
+
+CMake 3.0 and above recognize that Apple Clang is a different compiler
+than upstream Clang and that they have different version numbers.
+CMake now prefers to present this to projects by setting the
+:variable:`CMAKE_<LANG>_COMPILER_ID` variable to ``AppleClang`` instead
+of ``Clang``. However, existing projects may assume the compiler id for
+Apple Clang is just ``Clang`` as it was in CMake versions prior to 3.0.
+Therefore this policy determines for Apple Clang which compiler id to
+report in the :variable:`CMAKE_<LANG>_COMPILER_ID` variable after
+language ``<LANG>`` is enabled by the :command:`project` or
+:command:`enable_language` command. The policy must be set prior
+to the invocation of either command.
+
+The OLD behavior for this policy is to use compiler id ``Clang``. The
+NEW behavior for this policy is to use compiler id ``AppleClang``.
+
+This policy was introduced in CMake version 3.0. Use the
+:command:`cmake_policy` command to set this policy to OLD or NEW explicitly.
+Unlike most policies, CMake version |release| does *not* warn
+by default when this policy is not set and simply uses OLD behavior.
+See documentation of the
+:variable:`CMAKE_POLICY_WARNING_CMP0025 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
+variable to control the warning.
diff --git a/Help/policy/CMP0026.rst b/Help/policy/CMP0026.rst
new file mode 100644
index 0000000000..177b6555d8
--- /dev/null
+++ b/Help/policy/CMP0026.rst
@@ -0,0 +1,26 @@
+CMP0026
+-------
+
+Disallow use of the LOCATION target property.
+
+CMake 2.8.12 and lower allowed reading the LOCATION target
+property (and configuration-specific variants) to
+determine the eventual location of build targets. This relies on the
+assumption that all necessary information is available at
+configure-time to determine the final location and filename of the
+target. However, this property is not fully determined until later at
+generate-time. At generate time, the $<TARGET_FILE> generator
+expression can be used to determine the eventual LOCATION of a target
+output.
+
+Code which reads the LOCATION target property can be ported to use the
+$<TARGET_FILE> generator expression together with the file(GENERATE)
+subcommand to generate a file containing the target location.
+
+The OLD behavior for this policy is to allow reading the LOCATION
+properties from build-targets. The NEW behavior for this policy is to
+not to allow reading the LOCATION properties from build-targets.
+
+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.
diff --git a/Help/policy/CMP0027.rst b/Help/policy/CMP0027.rst
new file mode 100644
index 0000000000..bedaffeecd
--- /dev/null
+++ b/Help/policy/CMP0027.rst
@@ -0,0 +1,25 @@
+CMP0027
+-------
+
+Conditionally linked imported targets with missing include directories.
+
+CMake 2.8.11 introduced introduced the concept of
+INTERFACE_INCLUDE_DIRECTORIES, and a check at cmake time that the
+entries in the INTERFACE_INCLUDE_DIRECTORIES of an IMPORTED target
+actually exist. CMake 2.8.11 also introduced generator expression
+support in the target_link_libraries command. However, if an imported
+target is linked as a result of a generator expression evaluation, the
+entries in the INTERFACE_INCLUDE_DIRECTORIES of that target were not
+checked for existence as they should be.
+
+The OLD behavior of this policy is to report a warning if an entry in
+the INTERFACE_INCLUDE_DIRECTORIES of a generator-expression
+conditionally linked IMPORTED target does not exist.
+
+The NEW behavior of this policy is to report an error if an entry in
+the INTERFACE_INCLUDE_DIRECTORIES of a generator-expression
+conditionally linked IMPORTED target does not exist.
+
+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.
diff --git a/Help/policy/CMP0028.rst b/Help/policy/CMP0028.rst
new file mode 100644
index 0000000000..24889ec081
--- /dev/null
+++ b/Help/policy/CMP0028.rst
@@ -0,0 +1,23 @@
+CMP0028
+-------
+
+Double colon in target name means ALIAS or IMPORTED target.
+
+CMake 2.8.12 and lower allowed the use of targets and files with double
+colons in target_link_libraries, with some buildsystem generators.
+
+The use of double-colons is a common pattern used to namespace IMPORTED
+targets and ALIAS targets. When computing the link dependencies of a target,
+the name of each dependency could either be a target, or a file on disk.
+Previously, if a target was not found with a matching name, the name was
+considered to refer to a file on disk. This can lead to confusing error
+messages if there is a typo in what should be a target name.
+
+The OLD behavior for this policy is to search for targets, then files on disk,
+even if the search term contains double-colons. The NEW behavior for this
+policy is to issue a FATAL_ERROR if a link dependency contains
+double-colons but is not an IMPORTED target or an ALIAS target.
+
+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.
diff --git a/Help/policy/CMP0029.rst b/Help/policy/CMP0029.rst
new file mode 100644
index 0000000000..8f58a12209
--- /dev/null
+++ b/Help/policy/CMP0029.rst
@@ -0,0 +1,10 @@
+CMP0029
+-------
+
+The :command:`subdir_depends` command should not be called.
+
+The implementation of this command has been empty since December 2001
+but was kept in CMake for compatibility for a long time.
+
+.. |disallowed_version| replace:: 3.0
+.. include:: DISALLOWED_COMMAND.txt
diff --git a/Help/policy/CMP0030.rst b/Help/policy/CMP0030.rst
new file mode 100644
index 0000000000..9e31b3854c
--- /dev/null
+++ b/Help/policy/CMP0030.rst
@@ -0,0 +1,11 @@
+CMP0030
+-------
+
+The :command:`use_mangled_mesa` command should not be called.
+
+This command was created in September 2001 to support VTK before
+modern CMake language and custom command capabilities. VTK has
+not used it in years.
+
+.. |disallowed_version| replace:: 3.0
+.. include:: DISALLOWED_COMMAND.txt
diff --git a/Help/policy/CMP0031.rst b/Help/policy/CMP0031.rst
new file mode 100644
index 0000000000..6b89558f59
--- /dev/null
+++ b/Help/policy/CMP0031.rst
@@ -0,0 +1,13 @@
+CMP0031
+-------
+
+The :command:`load_command` command should not be called.
+
+This command was added in August 2002 to allow projects to add
+arbitrary commands implemented in C or C++. However, it does
+not work when the toolchain in use does not match the ABI of
+the CMake process. It has been mostly superseded by the
+:command:`macro` and :command:`function` commands.
+
+.. |disallowed_version| replace:: 3.0
+.. include:: DISALLOWED_COMMAND.txt
diff --git a/Help/policy/CMP0032.rst b/Help/policy/CMP0032.rst
new file mode 100644
index 0000000000..f394a064ee
--- /dev/null
+++ b/Help/policy/CMP0032.rst
@@ -0,0 +1,13 @@
+CMP0032
+-------
+
+The :command:`output_required_files` command should not be called.
+
+This command was added in June 2001 to expose the then-current CMake
+implicit dependency scanner. CMake's real implicit dependency scanner
+has evolved since then but is not exposed through this command. The
+scanning capabilities of this command are very limited and this
+functionality is better achieved through dedicated outside tools.
+
+.. |disallowed_version| replace:: 3.0
+.. include:: DISALLOWED_COMMAND.txt
diff --git a/Help/policy/CMP0033.rst b/Help/policy/CMP0033.rst
new file mode 100644
index 0000000000..b420065074
--- /dev/null
+++ b/Help/policy/CMP0033.rst
@@ -0,0 +1,14 @@
+CMP0033
+-------
+
+The :command:`export_library_dependencies` command should not be called.
+
+This command was added in January 2003 to export ``<tgt>_LIB_DEPENDS``
+internal CMake cache entries to a file for installation with a project.
+This was used at the time to allow transitive link dependencies to
+work for applications outside of the original build tree of a project.
+The functionality has been superseded by the :command:`export` and
+:command:`install(EXPORT)` commands.
+
+.. |disallowed_version| replace:: 3.0
+.. include:: DISALLOWED_COMMAND.txt
diff --git a/Help/policy/CMP0034.rst b/Help/policy/CMP0034.rst
new file mode 100644
index 0000000000..21339974bb
--- /dev/null
+++ b/Help/policy/CMP0034.rst
@@ -0,0 +1,11 @@
+CMP0034
+-------
+
+The :command:`utility_source` command should not be called.
+
+This command was introduced in March 2001 to help build executables used to
+generate other files. This approach has long been replaced by
+:command:`add_executable` combined with :command:`add_custom_command`.
+
+.. |disallowed_version| replace:: 3.0
+.. include:: DISALLOWED_COMMAND.txt
diff --git a/Help/policy/CMP0035.rst b/Help/policy/CMP0035.rst
new file mode 100644
index 0000000000..7335b221ad
--- /dev/null
+++ b/Help/policy/CMP0035.rst
@@ -0,0 +1,10 @@
+CMP0035
+-------
+
+The :command:`variable_requires` command should not be called.
+
+This command was introduced in November 2001 to perform some conditional
+logic. It has long been replaced by the :command:`if` command.
+
+.. |disallowed_version| replace:: 3.0
+.. include:: DISALLOWED_COMMAND.txt
diff --git a/Help/policy/CMP0036.rst b/Help/policy/CMP0036.rst
new file mode 100644
index 0000000000..817f156e45
--- /dev/null
+++ b/Help/policy/CMP0036.rst
@@ -0,0 +1,12 @@
+CMP0036
+-------
+
+The :command:`build_name` command should not be called.
+
+This command was added in May 2001 to compute a name for the current
+operating system and compiler combination. The command has long been
+documented as discouraged and replaced by the :variable:`CMAKE_SYSTEM`
+and :variable:`CMAKE_<LANG>_COMPILER` variables.
+
+.. |disallowed_version| replace:: 3.0
+.. include:: DISALLOWED_COMMAND.txt
diff --git a/Help/policy/CMP0037.rst b/Help/policy/CMP0037.rst
new file mode 100644
index 0000000000..4d485bf262
--- /dev/null
+++ b/Help/policy/CMP0037.rst
@@ -0,0 +1,26 @@
+CMP0037
+-------
+
+Target names should not be reserved and should match a validity pattern.
+
+CMake 2.8.12 and lower allowed creating targets using :command:`add_library`,
+:command:`add_executable` and :command:`add_custom_target` with unrestricted
+choice for the target name. Newer cmake features such
+as :manual:`cmake-generator-expressions(7)` and some
+diagnostics expect target names to match a restricted pattern.
+
+Target names may contain upper and lower case letters, numbers, the underscore
+character (_), dot(.), plus(+) and minus(-). As a special case, ALIAS
+targets and IMPORTED targets may contain two consequtive colons.
+
+Target names reserved by one or more CMake generators are not allowed.
+Among others these include "all", "help" and "test".
+
+The OLD behavior for this policy is to allow creating targets with
+reserved names or which do not match the validity pattern.
+The NEW behavior for this policy is to report an error
+if an add_* command is used with an invalid target name.
+
+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.
diff --git a/Help/policy/CMP0038.rst b/Help/policy/CMP0038.rst
new file mode 100644
index 0000000000..df5af6aec2
--- /dev/null
+++ b/Help/policy/CMP0038.rst
@@ -0,0 +1,16 @@
+CMP0038
+-------
+
+Targets may not link directly to themselves.
+
+CMake 2.8.12 and lower allowed a build target to link to itself directly with
+a :command:`target_link_libraries` call. This is an indicator of a bug in
+user code.
+
+The OLD behavior for this policy is to ignore targets which list themselves
+in their own link implementation. The NEW behavior for this policy is to
+report an error if a target attempts to link to itself.
+
+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.
diff --git a/Help/policy/CMP0039.rst b/Help/policy/CMP0039.rst
new file mode 100644
index 0000000000..58ccc4186a
--- /dev/null
+++ b/Help/policy/CMP0039.rst
@@ -0,0 +1,17 @@
+CMP0039
+-------
+
+Utility targets may not have link dependencies.
+
+CMake 2.8.12 and lower allowed using utility targets in the left hand side
+position of the :command:`target_link_libraries` command. This is an indicator
+of a bug in user code.
+
+The OLD behavior for this policy is to ignore attempts to set the link
+libraries of utility targets. The NEW behavior for this policy is to
+report an error if an attempt is made to set the link libraries of a
+utility target.
+
+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.
diff --git a/Help/policy/CMP0040.rst b/Help/policy/CMP0040.rst
new file mode 100644
index 0000000000..77a3c81631
--- /dev/null
+++ b/Help/policy/CMP0040.rst
@@ -0,0 +1,16 @@
+CMP0040
+-------
+
+The target in the TARGET signature of add_custom_command() must exist.
+
+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 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.
+
+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.
diff --git a/Help/policy/CMP0041.rst b/Help/policy/CMP0041.rst
new file mode 100644
index 0000000000..5a47de0a16
--- /dev/null
+++ b/Help/policy/CMP0041.rst
@@ -0,0 +1,25 @@
+CMP0041
+-------
+
+Error on relative include with generator expression.
+
+Diagnostics in CMake 2.8.12 and lower silently ignored an entry in the
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of a target if it contained a generator
+expression at any position.
+
+The path entries in that target property should not be relative. High-level
+API should ensure that by adding either a source directory or a install
+directory prefix, as appropriate.
+
+As an additional diagnostic, the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` generated
+on an :prop_tgt:`IMPORTED` target for the install location should not contain
+paths in the source directory or the build directory.
+
+The OLD behavior for this policy is to ignore relative path entries if they
+contain a generator expression. The NEW behavior for this policy is to report
+an error if a generator expression appears in another location and the path is
+relative.
+
+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.
diff --git a/Help/policy/CMP0042.rst b/Help/policy/CMP0042.rst
new file mode 100644
index 0000000000..fce870c7ca
--- /dev/null
+++ b/Help/policy/CMP0042.rst
@@ -0,0 +1,19 @@
+CMP0042
+-------
+
+:prop_tgt:`MACOSX_RPATH` is enabled by default.
+
+CMake 2.8.12 and newer has support for using ``@rpath`` in a target's install
+name. This was enabled by setting the target property
+:prop_tgt:`MACOSX_RPATH`. The ``@rpath`` in an install name is a more
+flexible and powerful mechanism than ``@executable_path`` or ``@loader_path``
+for locating shared libraries.
+
+CMake 3.0 and later prefer this property to be ON by default. Projects
+wanting ``@rpath`` in a target's install name may remove any setting of
+the :prop_tgt:`INSTALL_NAME_DIR` and :variable:`CMAKE_INSTALL_NAME_DIR`
+variables.
+
+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.
diff --git a/Help/policy/CMP0043.rst b/Help/policy/CMP0043.rst
new file mode 100644
index 0000000000..629e5022a4
--- /dev/null
+++ b/Help/policy/CMP0043.rst
@@ -0,0 +1,45 @@
+CMP0043
+-------
+
+Ignore COMPILE_DEFINITIONS_<Config> properties
+
+CMake 2.8.12 and lower allowed setting the
+:prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property and
+:prop_dir:`COMPILE_DEFINITIONS_<CONFIG>` directory property to apply
+configuration-specific compile definitions.
+
+Since CMake 2.8.10, the :prop_tgt:`COMPILE_DEFINITIONS` property has supported
+:manual:`generator expressions <cmake-generator-expressions(7)>` for setting
+configuration-dependent content. The continued existence of the suffixed
+variables is redundant, and causes a maintenance burden. Population of the
+:prop_tgt:`COMPILE_DEFINITIONS_DEBUG <COMPILE_DEFINITIONS_<CONFIG>>` property
+may be replaced with a population of :prop_tgt:`COMPILE_DEFINITIONS` directly
+or via :command:`target_compile_definitions`:
+
+.. code-block:: cmake
+
+ # Old Interfaces:
+ set_property(TARGET tgt APPEND PROPERTY
+ COMPILE_DEFINITIONS_DEBUG DEBUG_MODE
+ )
+ set_property(DIRECTORY APPEND PROPERTY
+ COMPILE_DEFINITIONS_DEBUG DIR_DEBUG_MODE
+ )
+
+ # New Interfaces:
+ set_property(TARGET tgt APPEND PROPERTY
+ COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUG_MODE>
+ )
+ target_compile_definitions(tgt PRIVATE $<$<CONFIG:Debug>:DEBUG_MODE>)
+ set_property(DIRECTORY APPEND PROPERTY
+ COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DIR_DEBUG_MODE>
+ )
+
+The OLD behavior for this policy is to consume the content of the suffixed
+:prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property when generating the
+compilation command. The NEW behavior for this policy is to ignore the content
+of the :prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property .
+
+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.
diff --git a/Help/policy/CMP0044.rst b/Help/policy/CMP0044.rst
new file mode 100644
index 0000000000..4a3e21527e
--- /dev/null
+++ b/Help/policy/CMP0044.rst
@@ -0,0 +1,19 @@
+CMP0044
+-------
+
+Case sensitive ``<LANG>_COMPILER_ID`` generator expressions
+
+CMake 2.8.12 introduced the ``<LANG>_COMPILER_ID``
+:manual:`generator expressions <cmake-generator-expressions(7)>` to allow
+comparison of the :variable:`CMAKE_<LANG>_COMPILER_ID` with a test value. The
+possible valid values are lowercase, but the comparison with the test value
+was performed case-insensitively.
+
+The OLD behavior for this policy is to perform a case-insensitive comparison
+with the value in the ``<LANG>_COMPILER_ID`` expression. The NEW behavior
+for this policy is to perform a case-sensitive comparison with the value in
+the ``<LANG>_COMPILER_ID`` expression.
+
+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.
diff --git a/Help/policy/CMP0045.rst b/Help/policy/CMP0045.rst
new file mode 100644
index 0000000000..58c422fad1
--- /dev/null
+++ b/Help/policy/CMP0045.rst
@@ -0,0 +1,17 @@
+CMP0045
+-------
+
+Error on non-existent target in get_target_property.
+
+In CMake 2.8.12 and lower, the :command:`get_target_property` command accepted
+a non-existent target argument without issuing any error or warning. The
+result variable is set to a ``-NOTFOUND`` value.
+
+The OLD behavior for this policy is to issue no warning and set the result
+variable to a ``-NOTFOUND`` value. The NEW behavior
+for this policy is to issue a ``FATAL_ERROR`` if the command is called with a
+non-existent target.
+
+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.
diff --git a/Help/policy/CMP0046.rst b/Help/policy/CMP0046.rst
new file mode 100644
index 0000000000..1a3bc65ec4
--- /dev/null
+++ b/Help/policy/CMP0046.rst
@@ -0,0 +1,17 @@
+CMP0046
+-------
+
+Error on non-existent dependency in add_dependencies.
+
+CMake 2.8.12 and lower silently ignored non-existent dependencies
+listed in the :command:`add_dependencies` command.
+
+The OLD behavior for this policy is to silently ignore non-existent
+dependencies. The NEW behavior for this policy is to report an error
+if non-existent dependencies are listed in the :command:`add_dependencies`
+command.
+
+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.
diff --git a/Help/policy/CMP0047.rst b/Help/policy/CMP0047.rst
new file mode 100644
index 0000000000..26ae439392
--- /dev/null
+++ b/Help/policy/CMP0047.rst
@@ -0,0 +1,28 @@
+CMP0047
+-------
+
+Use ``QCC`` compiler id for the qcc drivers on QNX.
+
+CMake 3.0 and above recognize that the QNX qcc compiler driver is
+different from the GNU compiler.
+CMake now prefers to present this to projects by setting the
+:variable:`CMAKE_<LANG>_COMPILER_ID` variable to ``QCC`` instead
+of ``GNU``. However, existing projects may assume the compiler id for
+QNX qcc is just ``GNU`` as it was in CMake versions prior to 3.0.
+Therefore this policy determines for QNX qcc which compiler id to
+report in the :variable:`CMAKE_<LANG>_COMPILER_ID` variable after
+language ``<LANG>`` is enabled by the :command:`project` or
+:command:`enable_language` command. The policy must be set prior
+to the invocation of either command.
+
+The OLD behavior for this policy is to use the ``GNU`` compiler id
+for the qcc and QCC compiler drivers. The NEW behavior for this policy
+is to use the ``QCC`` compiler id for those drivers.
+
+This policy was introduced in CMake version 3.0. Use the
+:command:`cmake_policy` command to set this policy to OLD or NEW explicitly.
+Unlike most policies, CMake version |release| does *not* warn
+by default when this policy is not set and simply uses OLD behavior.
+See documentation of the
+:variable:`CMAKE_POLICY_WARNING_CMP0047 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
+variable to control the warning.
diff --git a/Help/policy/CMP0048.rst b/Help/policy/CMP0048.rst
new file mode 100644
index 0000000000..a54205ee8f
--- /dev/null
+++ b/Help/policy/CMP0048.rst
@@ -0,0 +1,22 @@
+CMP0048
+-------
+
+The :command:`project` command manages VERSION variables.
+
+CMake version 3.0 introduced the ``VERSION`` option of the :command:`project`
+command to specify a project version as well as the name. In order to keep
+:variable:`PROJECT_VERSION` and related variables consistent with variable
+:variable:`PROJECT_NAME` it is necessary to set the VERSION variables
+to the empty string when no ``VERSION`` is given to :command:`project`.
+However, this can change behavior for existing projects that set VERSION
+variables themselves since :command:`project` may now clear them.
+This policy controls the behavior for compatibility with such projects.
+
+The OLD behavior for this policy is to leave VERSION variables untouched.
+The NEW behavior for this policy is to set VERSION as documented by the
+:command:`project` command.
+
+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.
diff --git a/Help/policy/CMP0049.rst b/Help/policy/CMP0049.rst
new file mode 100644
index 0000000000..5c8d4a8af4
--- /dev/null
+++ b/Help/policy/CMP0049.rst
@@ -0,0 +1,23 @@
+CMP0049
+-------
+
+Do not expand variables in target source entries.
+
+CMake 2.8.12 and lower performed and extra layer of variable expansion
+when evaluating source file names:
+
+.. code-block:: cmake
+
+ set(a_source foo.c)
+ add_executable(foo \${a_source})
+
+This was undocumented behavior.
+
+The OLD behavior for this policy is to expand such variables when processing
+the target sources. The NEW behavior for this policy is to issue an error
+if such variables need to be expanded.
+
+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.
diff --git a/Help/policy/CMP0050.rst b/Help/policy/CMP0050.rst
new file mode 100644
index 0000000000..76ae0aa75b
--- /dev/null
+++ b/Help/policy/CMP0050.rst
@@ -0,0 +1,18 @@
+CMP0050
+-------
+
+Disallow add_custom_command SOURCE signatures.
+
+CMake 2.8.12 and lower allowed a signature for :command:`add_custom_command`
+which specified an input to a command. This was undocumented behavior.
+Modern use of CMake associates custom commands with their output, rather
+than their input.
+
+The OLD behavior for this policy is to allow the use of
+:command:`add_custom_command` SOURCE signatures. The NEW behavior for this
+policy is to issue an error if such a signature is used.
+
+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.
diff --git a/Help/policy/CMP0051.rst b/Help/policy/CMP0051.rst
new file mode 100644
index 0000000000..1b56cb0a71
--- /dev/null
+++ b/Help/policy/CMP0051.rst
@@ -0,0 +1,24 @@
+CMP0051
+-------
+
+List TARGET_OBJECTS in SOURCES target property.
+
+CMake 3.0 and lower did not include the ``TARGET_OBJECTS``
+:manual:`generator expression <cmake-generator-expressions(7)>` when
+returning the :prop_tgt:`SOURCES` target property.
+
+Configure-time CMake code is not able to handle generator expressions. If
+using the :prop_tgt:`SOURCES` target property at configure time, it may be
+necessary to first remove generator expressions using the
+:command:`string(GENEX_STRIP)` command. Generate-time CMake code such as
+:command:`file(GENERATE)` can handle the content without stripping.
+
+The ``OLD`` behavior for this policy is to omit ``TARGET_OBJECTS``
+expressions from the :prop_tgt:`SOURCES` target property. The ``NEW``
+behavior for this policy is to include ``TARGET_OBJECTS`` expressions
+in the output.
+
+This policy was introduced in CMake version 3.1.
+CMake version |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.
diff --git a/Help/policy/CMP0052.rst b/Help/policy/CMP0052.rst
new file mode 100644
index 0000000000..48cfc9c70e
--- /dev/null
+++ b/Help/policy/CMP0052.rst
@@ -0,0 +1,24 @@
+CMP0052
+-------
+
+Reject source and build dirs in installed INTERFACE_INCLUDE_DIRECTORIES.
+
+CMake 3.0 and lower allowed subdirectories of the source directory or build
+directory to be in the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of
+installed and exported targets, if the directory was also a subdirectory of
+the installation prefix. This makes the installation depend on the
+existence of the source dir or binary dir, and the installation will be
+broken if either are removed after installation.
+
+See :ref:`Include Directories and Usage Requirements` for more on
+specifying include directories for targets.
+
+The OLD behavior for this policy is to export the content of the
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` with the source or binary
+directory. The NEW behavior for this
+policy is to issue an error if such a directory is used.
+
+This policy was introduced in CMake version 3.1.
+CMake version |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.
diff --git a/Help/policy/CMP0053.rst b/Help/policy/CMP0053.rst
new file mode 100644
index 0000000000..fac430e6e4
--- /dev/null
+++ b/Help/policy/CMP0053.rst
@@ -0,0 +1,44 @@
+CMP0053
+-------
+
+Simplify variable reference and escape sequence evaluation.
+
+CMake 3.1 introduced a much faster implementation of evaluation of the
+:ref:`Variable References` and :ref:`Escape Sequences` documented in the
+:manual:`cmake-language(7)` manual. While the behavior is identical
+to the legacy implementation in most cases, some corner cases were
+cleaned up to simplify the behavior. Specifically:
+
+* Expansion of ``@VAR@`` reference syntax defined by the
+ :command:`configure_file` and :command:`string(CONFIGURE)`
+ commands is no longer performed in other contexts.
+
+* Literal ``${VAR}`` reference syntax may contain only
+ alphanumeric characters (``A-Z``, ``a-z``, ``0-9``) and
+ the characters ``_``, ``.``, ``/``, ``-``, and ``+``.
+ Variables with other characters in their name may still
+ be referenced indirectly, e.g.
+
+ .. code-block:: cmake
+
+ set(varname "otherwise & disallowed $ characters")
+ message("${${varname}}")
+
+* The setting of policy :policy:`CMP0010` is not considered,
+ so improper variable reference syntax is always an error.
+
+* More characters are allowed to be escaped in variable names.
+ Previously, only ``()#" \#@^`` were valid characters to
+ escape. Now any non-alphanumeric, non-semicolon, non-NUL
+ character may be escaped following the ``escape_identity``
+ production in the :ref:`Escape Sequences` section of the
+ :manual:`cmake-language(7)` manual.
+
+The ``OLD`` behavior for this policy is to honor the legacy behavior for
+variable references and escape sequences. The ``NEW`` behavior is to
+use the simpler variable expansion and escape sequence evaluation rules.
+
+This policy was introduced in CMake version 3.1.
+CMake version |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.
diff --git a/Help/policy/CMP0054.rst b/Help/policy/CMP0054.rst
new file mode 100644
index 0000000000..dffee5e81a
--- /dev/null
+++ b/Help/policy/CMP0054.rst
@@ -0,0 +1,18 @@
+CMP0054
+-------
+
+Only interpret :command:`if` arguments as variables or keywords when unquoted.
+
+CMake 3.1 and above no longer dereference variables or interpret keywords
+in an :command:`if` command argument when it is a :ref:`Quoted Argument`
+or a :ref:`Bracket Argument`.
+
+The ``OLD`` behavior for this policy is to dereference variables and
+interpret keywords even if they are quoted or bracketed.
+The ``NEW`` behavior is to not dereference variables or interpret keywords
+that have been quoted or bracketed.
+
+This policy was introduced in CMake version 3.1.
+CMake version |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.
diff --git a/Help/policy/DISALLOWED_COMMAND.txt b/Help/policy/DISALLOWED_COMMAND.txt
new file mode 100644
index 0000000000..36280d2b63
--- /dev/null
+++ b/Help/policy/DISALLOWED_COMMAND.txt
@@ -0,0 +1,9 @@
+CMake >= |disallowed_version| prefer that this command never be called.
+The OLD behavior for this policy is to allow the command to be called.
+The NEW behavior for this policy is to issue a FATAL_ERROR when the
+command is called.
+
+This policy was introduced in CMake version |disallowed_version|.
+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.
diff --git a/Help/prop_cache/ADVANCED.rst b/Help/prop_cache/ADVANCED.rst
new file mode 100644
index 0000000000..a0a4f73bb2
--- /dev/null
+++ b/Help/prop_cache/ADVANCED.rst
@@ -0,0 +1,8 @@
+ADVANCED
+--------
+
+True if entry should be hidden by default in GUIs.
+
+This is a boolean value indicating whether the entry is considered
+interesting only for advanced configuration. The mark_as_advanced()
+command modifies this property.
diff --git a/Help/prop_cache/HELPSTRING.rst b/Help/prop_cache/HELPSTRING.rst
new file mode 100644
index 0000000000..71a86d0551
--- /dev/null
+++ b/Help/prop_cache/HELPSTRING.rst
@@ -0,0 +1,7 @@
+HELPSTRING
+----------
+
+Help associated with entry in GUIs.
+
+This string summarizes the purpose of an entry to help users set it
+through a CMake GUI.
diff --git a/Help/prop_cache/MODIFIED.rst b/Help/prop_cache/MODIFIED.rst
new file mode 100644
index 0000000000..3ad70354da
--- /dev/null
+++ b/Help/prop_cache/MODIFIED.rst
@@ -0,0 +1,7 @@
+MODIFIED
+--------
+
+Internal management property. Do not set or get.
+
+This is an internal cache entry property managed by CMake to track
+interactive user modification of entries. Ignore it.
diff --git a/Help/prop_cache/STRINGS.rst b/Help/prop_cache/STRINGS.rst
new file mode 100644
index 0000000000..2f8e32e3fc
--- /dev/null
+++ b/Help/prop_cache/STRINGS.rst
@@ -0,0 +1,9 @@
+STRINGS
+-------
+
+Enumerate possible STRING entry values for GUI selection.
+
+For cache entries with type STRING, this enumerates a set of values.
+CMake GUIs may use this to provide a selection widget instead of a
+generic string entry field. This is for convenience only. CMake does
+not enforce that the value matches one of those listed.
diff --git a/Help/prop_cache/TYPE.rst b/Help/prop_cache/TYPE.rst
new file mode 100644
index 0000000000..eb75c2ab2f
--- /dev/null
+++ b/Help/prop_cache/TYPE.rst
@@ -0,0 +1,21 @@
+TYPE
+----
+
+Widget type for entry in GUIs.
+
+Cache entry values are always strings, but CMake GUIs present widgets
+to help users set values. The GUIs use this property as a hint to
+determine the widget type. Valid TYPE values are:
+
+::
+
+ BOOL = Boolean ON/OFF value.
+ PATH = Path to a directory.
+ FILEPATH = Path to a file.
+ STRING = Generic string value.
+ INTERNAL = Do not present in GUI at all.
+ STATIC = Value managed by CMake, do not change.
+ UNINITIALIZED = Type not yet specified.
+
+Generally the TYPE of a cache entry should be set by the command which
+creates it (set, option, find_library, etc.).
diff --git a/Help/prop_cache/VALUE.rst b/Help/prop_cache/VALUE.rst
new file mode 100644
index 0000000000..59aabd431a
--- /dev/null
+++ b/Help/prop_cache/VALUE.rst
@@ -0,0 +1,7 @@
+VALUE
+-----
+
+Value of a cache entry.
+
+This property maps to the actual value of a cache entry. Setting this
+property always sets the value without checking, so use with care.
diff --git a/Help/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES.rst b/Help/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES.rst
new file mode 100644
index 0000000000..e32eed3ed5
--- /dev/null
+++ b/Help/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES.rst
@@ -0,0 +1,7 @@
+ADDITIONAL_MAKE_CLEAN_FILES
+---------------------------
+
+Additional files to clean during the make clean stage.
+
+A list of files that will be cleaned as a part of the "make clean"
+stage.
diff --git a/Help/prop_dir/CACHE_VARIABLES.rst b/Help/prop_dir/CACHE_VARIABLES.rst
new file mode 100644
index 0000000000..2c66f939e5
--- /dev/null
+++ b/Help/prop_dir/CACHE_VARIABLES.rst
@@ -0,0 +1,7 @@
+CACHE_VARIABLES
+---------------
+
+List of cache variables available in the current directory.
+
+This read-only property specifies the list of CMake cache variables
+currently defined. It is intended for debugging purposes.
diff --git a/Help/prop_dir/CLEAN_NO_CUSTOM.rst b/Help/prop_dir/CLEAN_NO_CUSTOM.rst
new file mode 100644
index 0000000000..9a4173e81e
--- /dev/null
+++ b/Help/prop_dir/CLEAN_NO_CUSTOM.rst
@@ -0,0 +1,7 @@
+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.
diff --git a/Help/prop_dir/CMAKE_CONFIGURE_DEPENDS.rst b/Help/prop_dir/CMAKE_CONFIGURE_DEPENDS.rst
new file mode 100644
index 0000000000..b1aef1966c
--- /dev/null
+++ b/Help/prop_dir/CMAKE_CONFIGURE_DEPENDS.rst
@@ -0,0 +1,9 @@
+CMAKE_CONFIGURE_DEPENDS
+-----------------------
+
+Tell CMake about additional input files to the configuration process.
+If any named file is modified the build system will re-run CMake to
+re-configure the file and generate the build system again.
+
+Specify files as a semicolon-separated list of paths. Relative paths
+are interpreted as relative to the current source directory.
diff --git a/Help/prop_dir/COMPILE_DEFINITIONS.rst b/Help/prop_dir/COMPILE_DEFINITIONS.rst
new file mode 100644
index 0000000000..ab7e7f0581
--- /dev/null
+++ b/Help/prop_dir/COMPILE_DEFINITIONS.rst
@@ -0,0 +1,32 @@
+COMPILE_DEFINITIONS
+-------------------
+
+Preprocessor definitions for compiling a directory's sources.
+
+This property specifies the list of options given so far to the
+:command:`add_definitions` command.
+
+The ``COMPILE_DEFINITIONS`` property may be set to a semicolon-separated
+list of preprocessor definitions using the syntax ``VAR`` or ``VAR=value``.
+Function-style definitions are not supported. CMake will
+automatically escape the value correctly for the native build system
+(note that CMake language syntax may require escapes to specify some
+values).
+
+This property will be initialized in each directory by its value in the
+directory's parent.
+
+CMake will automatically drop some definitions that are not supported
+by the native build tool. The VS6 IDE does not support definition
+values with spaces (but NMake does).
+
+.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
+
+Contents of ``COMPILE_DEFINITIONS`` 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.
+
+The corresponding :prop_dir:`COMPILE_DEFINITIONS_<CONFIG>` property may
+be set to specify per-configuration definitions. Generator expressions
+should be preferred instead of setting the alternative property.
diff --git a/Help/prop_dir/COMPILE_DEFINITIONS_CONFIG.rst b/Help/prop_dir/COMPILE_DEFINITIONS_CONFIG.rst
new file mode 100644
index 0000000000..a6af45f35b
--- /dev/null
+++ b/Help/prop_dir/COMPILE_DEFINITIONS_CONFIG.rst
@@ -0,0 +1,19 @@
+COMPILE_DEFINITIONS_<CONFIG>
+----------------------------
+
+Ignored. See CMake Policy :policy:`CMP0043`.
+
+Per-configuration preprocessor definitions in a directory.
+
+This is the configuration-specific version of :prop_dir:`COMPILE_DEFINITIONS`
+where ``<CONFIG>`` is an upper-case name (ex. ``COMPILE_DEFINITIONS_DEBUG``).
+
+This property will be initialized in each directory by its value in
+the directory's parent.
+
+Contents of ``COMPILE_DEFINITIONS_<CONFIG>`` 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.
+
+Generator expressions should be preferred instead of setting this property.
diff --git a/Help/prop_dir/COMPILE_OPTIONS.rst b/Help/prop_dir/COMPILE_OPTIONS.rst
new file mode 100644
index 0000000000..59530597dc
--- /dev/null
+++ b/Help/prop_dir/COMPILE_OPTIONS.rst
@@ -0,0 +1,16 @@
+COMPILE_OPTIONS
+---------------
+
+List of options to pass to the compiler.
+
+This property specifies the list of options given so far to the
+:command:`add_compile_options` command.
+
+This property is used to populate the :prop_tgt:`COMPILE_OPTIONS` target
+property, which is used by the generators to set the options for the
+compiler.
+
+Contents of ``COMPILE_OPTIONS`` 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/Help/prop_dir/DEFINITIONS.rst b/Help/prop_dir/DEFINITIONS.rst
new file mode 100644
index 0000000000..22f7c1542b
--- /dev/null
+++ b/Help/prop_dir/DEFINITIONS.rst
@@ -0,0 +1,8 @@
+DEFINITIONS
+-----------
+
+For CMake 2.4 compatibility only. Use COMPILE_DEFINITIONS instead.
+
+This read-only property specifies the list of flags given so far to
+the add_definitions command. It is intended for debugging purposes.
+Use the COMPILE_DEFINITIONS instead.
diff --git a/Help/prop_dir/EXCLUDE_FROM_ALL.rst b/Help/prop_dir/EXCLUDE_FROM_ALL.rst
new file mode 100644
index 0000000000..1aa24e44bf
--- /dev/null
+++ b/Help/prop_dir/EXCLUDE_FROM_ALL.rst
@@ -0,0 +1,9 @@
+EXCLUDE_FROM_ALL
+----------------
+
+Exclude the directory from the all target of its parent.
+
+A property on a directory that indicates if its targets are excluded
+from the default build target. If it is not, then with a Makefile for
+example typing make will cause the targets to be built. The same
+concept applies to the default build of other generators.
diff --git a/Help/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst b/Help/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst
new file mode 100644
index 0000000000..993f6200ef
--- /dev/null
+++ b/Help/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst
@@ -0,0 +1,34 @@
+IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
+----------------------------------
+
+Specify #include line transforms for dependencies in a directory.
+
+This property specifies rules to transform macro-like #include lines
+during implicit dependency scanning of C and C++ source files. The
+list of rules must be semicolon-separated with each entry of the form
+"A_MACRO(%)=value-with-%" (the % must be literal). During dependency
+scanning occurrences of A_MACRO(...) on #include lines will be
+replaced by the value given with the macro argument substituted for
+'%'. For example, the entry
+
+::
+
+ MYDIR(%)=<mydir/%>
+
+will convert lines of the form
+
+::
+
+ #include MYDIR(myheader.h)
+
+to
+
+::
+
+ #include <mydir/myheader.h>
+
+allowing the dependency to be followed.
+
+This property applies to sources in all targets within a directory.
+The property value is initialized in each directory by its value in
+the directory's parent.
diff --git a/Help/prop_dir/INCLUDE_DIRECTORIES.rst b/Help/prop_dir/INCLUDE_DIRECTORIES.rst
new file mode 100644
index 0000000000..baba49bf35
--- /dev/null
+++ b/Help/prop_dir/INCLUDE_DIRECTORIES.rst
@@ -0,0 +1,26 @@
+INCLUDE_DIRECTORIES
+-------------------
+
+List of preprocessor include file search directories.
+
+This property specifies the list of directories given so far to the
+:command:`include_directories` command.
+
+This property is used to populate the :prop_tgt:`INCLUDE_DIRECTORIES`
+target property, which is used by the generators to set the include
+directories for the compiler.
+
+In addition to accepting values from that command, values may be set
+directly on any directory using the :command:`set_property` command. A
+directory gets its initial value from its parent directory if it has one.
+The intial value of the :prop_tgt:`INCLUDE_DIRECTORIES` target property
+comes from the value of this property. Both directory and target property
+values are adjusted by calls to the :command:`include_directories` command.
+
+The target property values are used by the generators to set the
+include paths for the compiler.
+
+Contents of ``INCLUDE_DIRECTORIES`` 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/Help/prop_dir/INCLUDE_REGULAR_EXPRESSION.rst b/Help/prop_dir/INCLUDE_REGULAR_EXPRESSION.rst
new file mode 100644
index 0000000000..befafa58c5
--- /dev/null
+++ b/Help/prop_dir/INCLUDE_REGULAR_EXPRESSION.rst
@@ -0,0 +1,8 @@
+INCLUDE_REGULAR_EXPRESSION
+--------------------------
+
+Include file scanning regular expression.
+
+This read-only property specifies the regular expression used during
+dependency scanning to match include files that should be followed.
+See the include_regular_expression command.
diff --git a/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION.rst b/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION.rst
new file mode 100644
index 0000000000..0c78dfbe7f
--- /dev/null
+++ b/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION.rst
@@ -0,0 +1,7 @@
+INTERPROCEDURAL_OPTIMIZATION
+----------------------------
+
+Enable interprocedural optimization for targets in a directory.
+
+If set to true, enables interprocedural optimizations if they are
+known to be supported by the compiler.
diff --git a/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst b/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
new file mode 100644
index 0000000000..325208656a
--- /dev/null
+++ b/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
@@ -0,0 +1,8 @@
+INTERPROCEDURAL_OPTIMIZATION_<CONFIG>
+-------------------------------------
+
+Per-configuration interprocedural optimization for a directory.
+
+This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION.
+If set, this property overrides the generic property for the named
+configuration.
diff --git a/Help/prop_dir/LINK_DIRECTORIES.rst b/Help/prop_dir/LINK_DIRECTORIES.rst
new file mode 100644
index 0000000000..fa375766d6
--- /dev/null
+++ b/Help/prop_dir/LINK_DIRECTORIES.rst
@@ -0,0 +1,8 @@
+LINK_DIRECTORIES
+----------------
+
+List of linker search directories.
+
+This read-only property specifies the list of directories given so far
+to the link_directories command. It is intended for debugging
+purposes.
diff --git a/Help/prop_dir/LISTFILE_STACK.rst b/Help/prop_dir/LISTFILE_STACK.rst
new file mode 100644
index 0000000000..f729c1e784
--- /dev/null
+++ b/Help/prop_dir/LISTFILE_STACK.rst
@@ -0,0 +1,9 @@
+LISTFILE_STACK
+--------------
+
+The current stack of listfiles being processed.
+
+This property is mainly useful when trying to debug errors in your
+CMake scripts. It returns a list of what list files are currently
+being processed, in order. So if one listfile does an INCLUDE command
+then that is effectively pushing the included listfile onto the stack.
diff --git a/Help/prop_dir/MACROS.rst b/Help/prop_dir/MACROS.rst
new file mode 100644
index 0000000000..e4feadaa57
--- /dev/null
+++ b/Help/prop_dir/MACROS.rst
@@ -0,0 +1,8 @@
+MACROS
+------
+
+List of macro commands available in the current directory.
+
+This read-only property specifies the list of CMake macros currently
+defined. It is intended for debugging purposes. See the macro
+command.
diff --git a/Help/prop_dir/PARENT_DIRECTORY.rst b/Help/prop_dir/PARENT_DIRECTORY.rst
new file mode 100644
index 0000000000..3bc5824c94
--- /dev/null
+++ b/Help/prop_dir/PARENT_DIRECTORY.rst
@@ -0,0 +1,8 @@
+PARENT_DIRECTORY
+----------------
+
+Source directory that added current subdirectory.
+
+This read-only property specifies the source directory that added the
+current source directory as a subdirectory of the build. In the
+top-level directory the value is the empty-string.
diff --git a/Help/prop_dir/RULE_LAUNCH_COMPILE.rst b/Help/prop_dir/RULE_LAUNCH_COMPILE.rst
new file mode 100644
index 0000000000..342d0ae79a
--- /dev/null
+++ b/Help/prop_dir/RULE_LAUNCH_COMPILE.rst
@@ -0,0 +1,7 @@
+RULE_LAUNCH_COMPILE
+-------------------
+
+Specify a launcher for compile rules.
+
+See the global property of the same name for details. This overrides
+the global property for a directory.
diff --git a/Help/prop_dir/RULE_LAUNCH_CUSTOM.rst b/Help/prop_dir/RULE_LAUNCH_CUSTOM.rst
new file mode 100644
index 0000000000..93d1e0111e
--- /dev/null
+++ b/Help/prop_dir/RULE_LAUNCH_CUSTOM.rst
@@ -0,0 +1,7 @@
+RULE_LAUNCH_CUSTOM
+------------------
+
+Specify a launcher for custom rules.
+
+See the global property of the same name for details. This overrides
+the global property for a directory.
diff --git a/Help/prop_dir/RULE_LAUNCH_LINK.rst b/Help/prop_dir/RULE_LAUNCH_LINK.rst
new file mode 100644
index 0000000000..3cfb2369bc
--- /dev/null
+++ b/Help/prop_dir/RULE_LAUNCH_LINK.rst
@@ -0,0 +1,7 @@
+RULE_LAUNCH_LINK
+----------------
+
+Specify a launcher for link rules.
+
+See the global property of the same name for details. This overrides
+the global property for a directory.
diff --git a/Help/prop_dir/TEST_INCLUDE_FILE.rst b/Help/prop_dir/TEST_INCLUDE_FILE.rst
new file mode 100644
index 0000000000..e47795191a
--- /dev/null
+++ b/Help/prop_dir/TEST_INCLUDE_FILE.rst
@@ -0,0 +1,7 @@
+TEST_INCLUDE_FILE
+-----------------
+
+A cmake file that will be included when ctest is run.
+
+If you specify TEST_INCLUDE_FILE, that file will be included and
+processed when ctest is run on the directory.
diff --git a/Help/prop_dir/VARIABLES.rst b/Help/prop_dir/VARIABLES.rst
new file mode 100644
index 0000000000..0328295c3f
--- /dev/null
+++ b/Help/prop_dir/VARIABLES.rst
@@ -0,0 +1,7 @@
+VARIABLES
+---------
+
+List of variables defined in the current directory.
+
+This read-only property specifies the list of CMake variables
+currently defined. It is intended for debugging purposes.
diff --git a/Help/prop_dir/VS_GLOBAL_SECTION_POST_section.rst b/Help/prop_dir/VS_GLOBAL_SECTION_POST_section.rst
new file mode 100644
index 0000000000..eb91832887
--- /dev/null
+++ b/Help/prop_dir/VS_GLOBAL_SECTION_POST_section.rst
@@ -0,0 +1,29 @@
+VS_GLOBAL_SECTION_POST_<section>
+--------------------------------
+
+Specify a postSolution global section in Visual Studio.
+
+Setting a property like this generates an entry of the following form
+in the solution file:
+
+::
+
+ GlobalSection(<section>) = postSolution
+ <contents based on property value>
+ EndGlobalSection
+
+The property must be set to a semicolon-separated list of key=value
+pairs. Each such pair will be transformed into an entry in the
+solution global section. Whitespace around key and value is ignored.
+List elements which do not contain an equal sign are skipped.
+
+This property only works for Visual Studio 7 and above; it is ignored
+on other generators. The property only applies when set on a
+directory whose CMakeLists.txt contains a project() command.
+
+Note that CMake generates postSolution sections ExtensibilityGlobals
+and ExtensibilityAddIns by default. If you set the corresponding
+property, it will override the default section. For example, setting
+VS_GLOBAL_SECTION_POST_ExtensibilityGlobals will override the default
+contents of the ExtensibilityGlobals section, while keeping
+ExtensibilityAddIns on its default.
diff --git a/Help/prop_dir/VS_GLOBAL_SECTION_PRE_section.rst b/Help/prop_dir/VS_GLOBAL_SECTION_PRE_section.rst
new file mode 100644
index 0000000000..fbcd9e6f3d
--- /dev/null
+++ b/Help/prop_dir/VS_GLOBAL_SECTION_PRE_section.rst
@@ -0,0 +1,22 @@
+VS_GLOBAL_SECTION_PRE_<section>
+-------------------------------
+
+Specify a preSolution global section in Visual Studio.
+
+Setting a property like this generates an entry of the following form
+in the solution file:
+
+::
+
+ GlobalSection(<section>) = preSolution
+ <contents based on property value>
+ EndGlobalSection
+
+The property must be set to a semicolon-separated list of key=value
+pairs. Each such pair will be transformed into an entry in the
+solution global section. Whitespace around key and value is ignored.
+List elements which do not contain an equal sign are skipped.
+
+This property only works for Visual Studio 7 and above; it is ignored
+on other generators. The property only applies when set on a
+directory whose CMakeLists.txt contains a project() command.
diff --git a/Help/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst b/Help/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst
new file mode 100644
index 0000000000..8fab503455
--- /dev/null
+++ b/Help/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst
@@ -0,0 +1,19 @@
+ALLOW_DUPLICATE_CUSTOM_TARGETS
+------------------------------
+
+Allow duplicate custom targets to be created.
+
+Normally CMake requires that all targets built in a project have
+globally unique logical names (see policy CMP0002). This is necessary
+to generate meaningful project file names in Xcode and VS IDE
+generators. It also allows the target names to be referenced
+unambiguously.
+
+Makefile generators are capable of supporting duplicate custom target
+names. For projects that care only about Makefile generators and do
+not wish to support Xcode or VS IDE generators, one may set this
+property to true to allow duplicate custom targets. The property
+allows multiple add_custom_target command calls in different
+directories to specify the same target name. However, setting this
+property will cause non-Makefile generators to produce an error and
+refuse to generate the project.
diff --git a/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst b/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst
new file mode 100644
index 0000000000..5a69ef31d8
--- /dev/null
+++ b/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst
@@ -0,0 +1,9 @@
+AUTOGEN_TARGETS_FOLDER
+----------------------
+
+Name of :prop_tgt:`FOLDER` for ``*_automoc`` targets that are added automatically by
+CMake for targets for which :prop_tgt:`AUTOMOC` is enabled.
+
+If not set, CMake uses the :prop_tgt:`FOLDER` property of the parent target as a
+default value for this property. See also the documentation for the
+:prop_tgt:`FOLDER` target property and the :prop_tgt:`AUTOMOC` target property.
diff --git a/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst b/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst
new file mode 100644
index 0000000000..671f86a855
--- /dev/null
+++ b/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst
@@ -0,0 +1,11 @@
+AUTOMOC_TARGETS_FOLDER
+----------------------
+
+Name of :prop_tgt:`FOLDER` for ``*_automoc`` targets that are added automatically by
+CMake for targets for which :prop_tgt:`AUTOMOC` is enabled.
+
+This property is obsolete. Use :prop_gbl:`AUTOGEN_TARGETS_FOLDER` instead.
+
+If not set, CMake uses the :prop_tgt:`FOLDER` property of the parent target as a
+default value for this property. See also the documentation for the
+:prop_tgt:`FOLDER` target property and the :prop_tgt:`AUTOMOC` target property.
diff --git a/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst b/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst
new file mode 100644
index 0000000000..bdeabdb2c6
--- /dev/null
+++ b/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst
@@ -0,0 +1,298 @@
+CMAKE_CXX_KNOWN_FEATURES
+------------------------
+
+List of C++ features known to this version of CMake.
+
+The features listed in this global property may be known to be available to the
+C++ compiler. If the feature is available with the C++ compiler, it will
+be listed in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable.
+
+The features listed here may be used with the :command:`target_compile_features`
+command. See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
+
+
+The features known to this version of CMake are:
+
+``cxx_aggregate_default_initializers``
+ Aggregate default initializers, as defined in N3605_.
+
+ .. _N3605: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3605.html
+
+``cxx_alias_templates``
+ Template aliases, as defined in N2258_.
+
+ .. _N2258: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2258.pdf
+
+``cxx_alignas``
+ Alignment control ``alignas``, as defined in N2341_.
+
+ .. _N2341: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf
+
+``cxx_alignof``
+ Alignment control ``alignof``, as defined in N2341_.
+
+ .. _N2341: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf
+
+``cxx_attributes``
+ Generic attributes, as defined in N2761_.
+
+ .. _N2761: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2761.pdf
+
+``cxx_attribute_deprecated``
+ ``[[deprecated]]`` attribute, as defined in N3760_.
+
+ .. _N3760: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3760.html
+
+``cxx_auto_type``
+ Automatic type deduction, as defined in N1984_.
+
+ .. _N1984: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1984.pdf
+
+``cxx_binary_literals``
+ Binary literals, as defined in N3472_.
+
+ .. _N3472: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3472.pdf
+
+``cxx_constexpr``
+ Constant expressions, as defined in N2235_.
+
+ .. _N2235: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf
+
+``cxx_contextual_conversions``
+ Contextual conversions, as defined in N3323_.
+
+ .. _N3323: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3323.pdf
+
+``cxx_decltype_incomplete_return_types``
+ Decltype on incomplete return types, as defined in N3276_.
+
+ .. _N3276 : http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3276.pdf
+
+``cxx_decltype``
+ Decltype, as defined in N2343_.
+
+ .. _N2343: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2343.pdf
+
+``cxx_decltype_auto``
+ ``decltype(auto)`` semantics, as defined in N3638_.
+
+ .. _N3638: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3638.html
+
+``cxx_default_function_template_args``
+ Default template arguments for function templates, as defined in DR226_
+
+ .. _DR226: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#226
+
+``cxx_defaulted_functions``
+ Defaulted functions, as defined in N2346_.
+
+ .. _N2346: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm
+
+``cxx_defaulted_move_initializers``
+ Defaulted move initializers, as defined in N3053_.
+
+ .. _N3053: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3053.html
+
+``cxx_delegating_constructors``
+ Delegating constructors, as defined in N1986_.
+
+ .. _N1986: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1986.pdf
+
+``cxx_deleted_functions``
+ Deleted functions, as defined in N2346_.
+
+ .. _N2346: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm
+
+``cxx_digit_separators``
+ Digit separators, as defined in N3781_.
+
+ .. _N3781: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3781.pdf
+
+``cxx_enum_forward_declarations``
+ Enum forward declarations, as defined in N2764_.
+
+ .. _N2764: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf
+
+``cxx_explicit_conversions``
+ Explicit conversion operators, as defined in N2437_.
+
+ .. _N2437: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2437.pdf
+
+``cxx_extended_friend_declarations``
+ Extended friend declarations, as defined in N1791_.
+
+ .. _N1791: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1791.pdf
+
+``cxx_extern_templates``
+ Extern templates, as defined in N1987_.
+
+ .. _N1987: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1987.htm
+
+``cxx_final``
+ Override control ``final`` keyword, as defined in N2928_.
+
+ .. _N2928: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2928.htm
+
+``cxx_func_identifier``
+ Predefined ``__func__`` identifier, as defined in N2340_.
+
+ .. _N2340: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2340.htm
+
+``cxx_generalized_initializers``
+ Initializer lists, as defined in N2672_.
+
+ .. _N2672: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2672.htm
+
+``cxx_generic_lambdas``
+ Generic lambdas, ss defined in N3649_.
+
+ .. _N3649: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3649.html
+
+``cxx_inheriting_constructors``
+ Inheriting constructors, as defined in N2540_.
+
+ .. _N2540: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2540.htm
+
+``cxx_inline_namespaces``
+ Inline namespaces, as defined in N2535_.
+
+ .. _N2535: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2535.htm
+
+``cxx_lambdas``
+ Lambda functions, as defined in N2927_.
+
+ .. _N2927: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2927.pdf
+
+``cxx_lambda_init_captures``
+ Initialized lambda captures, as defined in N3648_.
+
+ .. _N3648: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3648.html
+
+``cxx_local_type_template_args``
+ Local and unnamed types as template arguments, as defined in N2657_.
+
+ .. _N2657: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm
+
+``cxx_long_long_type``
+ ``long long`` type, as defined in N1811_.
+
+ .. _N1811: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1811.pdf
+
+``cxx_noexcept``
+ Exception specifications, as defined in N3050_.
+
+ .. _N3050: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3050.html
+
+``cxx_nonstatic_member_init``
+ Non-static data member initialization, as defined in N2756_.
+
+ .. _N2756: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2756.htm
+
+``cxx_nullptr``
+ Null pointer, as defined in N2431_.
+
+ .. _N2431: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf
+
+``cxx_override``
+ Override control ``override`` keyword, as defined in N2928_.
+
+ .. _N2928: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2928.htm
+
+``cxx_range_for``
+ Range-based for, as defined in N2930_.
+
+ .. _N2930: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2930.html
+
+``cxx_raw_string_literals``
+ Raw string literals, as defined in N2442_.
+
+ .. _N2442: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2442.htm
+
+``cxx_reference_qualified_functions``
+ Reference qualified functions, as defined in N2439_.
+
+ .. _N2439: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2439.htm
+
+``cxx_relaxed_constexpr``
+ Relaxed constexpr, as defined in N3652_.
+
+ .. _N3652: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3652.html
+
+``cxx_return_type_deduction``
+ Return type deduction on normal functions, as defined in N3386_.
+
+ .. _N3386: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3386.html
+
+``cxx_right_angle_brackets``
+ Right angle bracket parsing, as defined in N1757_.
+
+ .. _N1757: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html
+
+``cxx_rvalue_references``
+ R-value references, as defined in N2118_.
+
+ .. _N2118: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2118.html
+
+``cxx_sizeof_member``
+ Size of non-static data members, as defined in N2253_.
+
+ .. _N2253: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2253.html
+
+``cxx_static_assert``
+ Static assert, as defined in N1720_.
+
+ .. _N1720: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html
+
+``cxx_strong_enums``
+ Strongly typed enums, as defined in N2347_.
+
+ .. _N2347: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf
+
+``cxx_thread_local``
+ Thread-local variables, as defined in N2659_.
+
+ .. _N2659: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2659.htm
+
+``cxx_trailing_return_types``
+ Automatic function return type, as defined in N2541_.
+
+ .. _N2541: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2541.htm
+
+``cxx_unicode_literals``
+ Unicode string literals, as defined in N2442_.
+
+ .. _N2442: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2442.htm
+
+``cxx_uniform_initialization``
+ Uniform intialization, as defined in N2640_.
+
+ .. _N2640: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2640.pdf
+
+``cxx_unrestricted_unions``
+ Unrestricted unions, as defined in N2544_.
+
+ .. _N2544: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2544.pdf
+
+``cxx_user_literals``
+ User-defined literals, as defined in N2765_.
+
+ .. _N2765: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf
+
+``cxx_variable_templates``
+ Variable templates, as defined in N3651_.
+
+ .. _N3651: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3651.pdf
+
+``cxx_variadic_macros``
+ Variadic macros, as defined in N1653_.
+
+ .. _N1653: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1653.htm
+
+``cxx_variadic_templates``
+ Variadic templates, as defined in N2242_.
+
+ .. _N2242: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2242.pdf
+
+``cxx_template_template_parameters``
+ Template template parameters, as defined in ``ISO/IEC 14882:1998``.
diff --git a/Help/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst b/Help/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst
new file mode 100644
index 0000000000..18cd030556
--- /dev/null
+++ b/Help/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst
@@ -0,0 +1,26 @@
+CMAKE_C_KNOWN_FEATURES
+----------------------
+
+List of C features known to this version of CMake.
+
+The features listed in this global property may be known to be available to the
+C compiler. If the feature is available with the C compiler, it will
+be listed in the :variable:`CMAKE_C_COMPILE_FEATURES` variable.
+
+The features listed here may be used with the :command:`target_compile_features`
+command. See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
+
+The features known to this version of CMake are:
+
+``c_function_prototypes``
+ Function prototypes, as defined in ``ISO/IEC 9899:1990``.
+
+``c_restrict``
+ ``restrict`` keyword, as defined in ``ISO/IEC 9899:1999``.
+
+``c_static_assert``
+ Static assert, as defined in ``ISO/IEC 9899:2011``.
+
+``c_variadic_macros``
+ Variadic macros, as defined in ``ISO/IEC 9899:1999``.
diff --git a/Help/prop_gbl/DEBUG_CONFIGURATIONS.rst b/Help/prop_gbl/DEBUG_CONFIGURATIONS.rst
new file mode 100644
index 0000000000..690143f826
--- /dev/null
+++ b/Help/prop_gbl/DEBUG_CONFIGURATIONS.rst
@@ -0,0 +1,14 @@
+DEBUG_CONFIGURATIONS
+--------------------
+
+Specify which configurations are for debugging.
+
+The value must be a semi-colon separated list of configuration names.
+Currently this property is used only by the target_link_libraries
+command (see its documentation for details). Additional uses may be
+defined in the future.
+
+This property must be set at the top level of the project and before
+the first target_link_libraries command invocation. If any entry in
+the list does not match a valid configuration for the project the
+behavior is undefined.
diff --git a/Help/prop_gbl/DISABLED_FEATURES.rst b/Help/prop_gbl/DISABLED_FEATURES.rst
new file mode 100644
index 0000000000..111cdf67e9
--- /dev/null
+++ b/Help/prop_gbl/DISABLED_FEATURES.rst
@@ -0,0 +1,11 @@
+DISABLED_FEATURES
+-----------------
+
+List of features which are disabled during the CMake run.
+
+List of features which are disabled during the CMake run. By default
+it contains the names of all packages which were not found. This is
+determined using the <NAME>_FOUND variables. Packages which are
+searched QUIET are not listed. A project can add its own features to
+this list. This property is used by the macros in
+FeatureSummary.cmake.
diff --git a/Help/prop_gbl/ECLIPSE_EXTRA_NATURES.rst b/Help/prop_gbl/ECLIPSE_EXTRA_NATURES.rst
new file mode 100644
index 0000000000..6d1529d3aa
--- /dev/null
+++ b/Help/prop_gbl/ECLIPSE_EXTRA_NATURES.rst
@@ -0,0 +1,8 @@
+ECLIPSE_EXTRA_NATURES
+---------------------
+
+List of natures to add to the generated Eclipse project file.
+
+Eclipse projects specify language plugins by using natures. This property
+should be set to the unique identifier for a nature (which looks like a Java
+package name).
diff --git a/Help/prop_gbl/ENABLED_FEATURES.rst b/Help/prop_gbl/ENABLED_FEATURES.rst
new file mode 100644
index 0000000000..b03da5a458
--- /dev/null
+++ b/Help/prop_gbl/ENABLED_FEATURES.rst
@@ -0,0 +1,11 @@
+ENABLED_FEATURES
+----------------
+
+List of features which are enabled during the CMake run.
+
+List of features which are enabled during the CMake run. By default
+it contains the names of all packages which were found. This is
+determined using the <NAME>_FOUND variables. Packages which are
+searched QUIET are not listed. A project can add its own features to
+this list. This property is used by the macros in
+FeatureSummary.cmake.
diff --git a/Help/prop_gbl/ENABLED_LANGUAGES.rst b/Help/prop_gbl/ENABLED_LANGUAGES.rst
new file mode 100644
index 0000000000..43e3c09f7f
--- /dev/null
+++ b/Help/prop_gbl/ENABLED_LANGUAGES.rst
@@ -0,0 +1,6 @@
+ENABLED_LANGUAGES
+-----------------
+
+Read-only property that contains the list of currently enabled languages
+
+Set to list of currently enabled languages.
diff --git a/Help/prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS.rst b/Help/prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS.rst
new file mode 100644
index 0000000000..185246cda0
--- /dev/null
+++ b/Help/prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS.rst
@@ -0,0 +1,9 @@
+FIND_LIBRARY_USE_LIB64_PATHS
+----------------------------
+
+Whether FIND_LIBRARY should automatically search lib64 directories.
+
+FIND_LIBRARY_USE_LIB64_PATHS is a boolean specifying whether the
+FIND_LIBRARY command should automatically search the lib64 variant of
+directories called lib in the search path when building 64-bit
+binaries.
diff --git a/Help/prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING.rst b/Help/prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING.rst
new file mode 100644
index 0000000000..9a3edd869c
--- /dev/null
+++ b/Help/prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING.rst
@@ -0,0 +1,9 @@
+FIND_LIBRARY_USE_OPENBSD_VERSIONING
+-----------------------------------
+
+Whether FIND_LIBRARY should find OpenBSD-style shared libraries.
+
+This property is a boolean specifying whether the FIND_LIBRARY command
+should find shared libraries with OpenBSD-style versioned extension:
+".so.<major>.<minor>". The property is set to true on OpenBSD and
+false on other platforms.
diff --git a/Help/prop_gbl/GLOBAL_DEPENDS_DEBUG_MODE.rst b/Help/prop_gbl/GLOBAL_DEPENDS_DEBUG_MODE.rst
new file mode 100644
index 0000000000..832503b512
--- /dev/null
+++ b/Help/prop_gbl/GLOBAL_DEPENDS_DEBUG_MODE.rst
@@ -0,0 +1,8 @@
+GLOBAL_DEPENDS_DEBUG_MODE
+-------------------------
+
+Enable global target dependency graph debug mode.
+
+CMake automatically analyzes the global inter-target dependency graph
+at the beginning of native build system generation. This property
+causes it to display details of its analysis to stderr.
diff --git a/Help/prop_gbl/GLOBAL_DEPENDS_NO_CYCLES.rst b/Help/prop_gbl/GLOBAL_DEPENDS_NO_CYCLES.rst
new file mode 100644
index 0000000000..d10661e629
--- /dev/null
+++ b/Help/prop_gbl/GLOBAL_DEPENDS_NO_CYCLES.rst
@@ -0,0 +1,10 @@
+GLOBAL_DEPENDS_NO_CYCLES
+------------------------
+
+Disallow global target dependency graph cycles.
+
+CMake automatically analyzes the global inter-target dependency graph
+at the beginning of native build system generation. It reports an
+error if the dependency graph contains a cycle that does not consist
+of all STATIC library targets. This property tells CMake to disallow
+all cycles completely, even among static libraries.
diff --git a/Help/prop_gbl/IN_TRY_COMPILE.rst b/Help/prop_gbl/IN_TRY_COMPILE.rst
new file mode 100644
index 0000000000..3a2ef5b652
--- /dev/null
+++ b/Help/prop_gbl/IN_TRY_COMPILE.rst
@@ -0,0 +1,6 @@
+IN_TRY_COMPILE
+--------------
+
+Read-only property that is true during a try-compile configuration.
+
+True when building a project inside a TRY_COMPILE or TRY_RUN command.
diff --git a/Help/prop_gbl/JOB_POOLS.rst b/Help/prop_gbl/JOB_POOLS.rst
new file mode 100644
index 0000000000..98b9f7eaef
--- /dev/null
+++ b/Help/prop_gbl/JOB_POOLS.rst
@@ -0,0 +1,20 @@
+JOB_POOLS
+---------
+
+Ninja only: List of available pools.
+
+A pool is a named integer property and defines the maximum number
+of concurrent jobs which can be started by a rule assigned to the pool.
+The :prop_gbl:`JOB_POOLS` property is a semicolon-separated list of
+pairs using the syntax NAME=integer (without a space after the equality sign).
+
+For instance:
+
+.. code-block:: cmake
+
+ set_property(GLOBAL PROPERTY JOB_POOLS two_jobs=2 ten_jobs=10)
+
+Defined pools could be used globally by setting
+:variable:`CMAKE_JOB_POOL_COMPILE` and :variable:`CMAKE_JOB_POOL_LINK`
+or per target by setting the target properties
+:prop_tgt:`JOB_POOL_COMPILE` and :prop_tgt:`JOB_POOL_LINK`.
diff --git a/Help/prop_gbl/PACKAGES_FOUND.rst b/Help/prop_gbl/PACKAGES_FOUND.rst
new file mode 100644
index 0000000000..61cce1fd8d
--- /dev/null
+++ b/Help/prop_gbl/PACKAGES_FOUND.rst
@@ -0,0 +1,7 @@
+PACKAGES_FOUND
+--------------
+
+List of packages which were found during the CMake run.
+
+List of packages which were found during the CMake run. Whether a
+package has been found is determined using the <NAME>_FOUND variables.
diff --git a/Help/prop_gbl/PACKAGES_NOT_FOUND.rst b/Help/prop_gbl/PACKAGES_NOT_FOUND.rst
new file mode 100644
index 0000000000..ca3c5bac6f
--- /dev/null
+++ b/Help/prop_gbl/PACKAGES_NOT_FOUND.rst
@@ -0,0 +1,7 @@
+PACKAGES_NOT_FOUND
+------------------
+
+List of packages which were not found during the CMake run.
+
+List of packages which were not found during the CMake run. Whether a
+package has been found is determined using the <NAME>_FOUND variables.
diff --git a/Help/prop_gbl/PREDEFINED_TARGETS_FOLDER.rst b/Help/prop_gbl/PREDEFINED_TARGETS_FOLDER.rst
new file mode 100644
index 0000000000..e85b823b18
--- /dev/null
+++ b/Help/prop_gbl/PREDEFINED_TARGETS_FOLDER.rst
@@ -0,0 +1,9 @@
+PREDEFINED_TARGETS_FOLDER
+-------------------------
+
+Name of FOLDER for targets that are added automatically by CMake.
+
+If not set, CMake uses "CMakePredefinedTargets" as a default value for
+this property. Targets such as INSTALL, PACKAGE and RUN_TESTS will be
+organized into this FOLDER. See also the documentation for the FOLDER
+target property.
diff --git a/Help/prop_gbl/REPORT_UNDEFINED_PROPERTIES.rst b/Help/prop_gbl/REPORT_UNDEFINED_PROPERTIES.rst
new file mode 100644
index 0000000000..29ba36557f
--- /dev/null
+++ b/Help/prop_gbl/REPORT_UNDEFINED_PROPERTIES.rst
@@ -0,0 +1,8 @@
+REPORT_UNDEFINED_PROPERTIES
+---------------------------
+
+If set, report any undefined properties to this file.
+
+If this property is set to a filename then when CMake runs it will
+report any properties or variables that were accessed but not defined
+into the filename specified in this property.
diff --git a/Help/prop_gbl/RULE_LAUNCH_COMPILE.rst b/Help/prop_gbl/RULE_LAUNCH_COMPILE.rst
new file mode 100644
index 0000000000..980843bf89
--- /dev/null
+++ b/Help/prop_gbl/RULE_LAUNCH_COMPILE.rst
@@ -0,0 +1,9 @@
+RULE_LAUNCH_COMPILE
+-------------------
+
+Specify a launcher for compile rules.
+
+Makefile generators prefix compiler commands with the given launcher
+command line. This is intended to allow launchers to intercept build
+problems with high granularity. Non-Makefile generators currently
+ignore this property.
diff --git a/Help/prop_gbl/RULE_LAUNCH_CUSTOM.rst b/Help/prop_gbl/RULE_LAUNCH_CUSTOM.rst
new file mode 100644
index 0000000000..9d4a25ce77
--- /dev/null
+++ b/Help/prop_gbl/RULE_LAUNCH_CUSTOM.rst
@@ -0,0 +1,9 @@
+RULE_LAUNCH_CUSTOM
+------------------
+
+Specify a launcher for custom rules.
+
+Makefile generators prefix custom commands with the given launcher
+command line. This is intended to allow launchers to intercept build
+problems with high granularity. Non-Makefile generators currently
+ignore this property.
diff --git a/Help/prop_gbl/RULE_LAUNCH_LINK.rst b/Help/prop_gbl/RULE_LAUNCH_LINK.rst
new file mode 100644
index 0000000000..191f1d504a
--- /dev/null
+++ b/Help/prop_gbl/RULE_LAUNCH_LINK.rst
@@ -0,0 +1,9 @@
+RULE_LAUNCH_LINK
+----------------
+
+Specify a launcher for link rules.
+
+Makefile generators prefix link and archive commands with the given
+launcher command line. This is intended to allow launchers to
+intercept build problems with high granularity. Non-Makefile
+generators currently ignore this property.
diff --git a/Help/prop_gbl/RULE_MESSAGES.rst b/Help/prop_gbl/RULE_MESSAGES.rst
new file mode 100644
index 0000000000..38d83a36b3
--- /dev/null
+++ b/Help/prop_gbl/RULE_MESSAGES.rst
@@ -0,0 +1,13 @@
+RULE_MESSAGES
+-------------
+
+Specify whether to report a message for each make rule.
+
+This property specifies whether Makefile generators should add a
+progress message describing what each build rule does. If the
+property is not set the default is ON. Set the property to OFF to
+disable granular messages and report only as each target completes.
+This is intended to allow scripted builds to avoid the build time cost
+of detailed reports. If a CMAKE_RULE_MESSAGES cache entry exists its
+value initializes the value of this property. Non-Makefile generators
+currently ignore this property.
diff --git a/Help/prop_gbl/TARGET_ARCHIVES_MAY_BE_SHARED_LIBS.rst b/Help/prop_gbl/TARGET_ARCHIVES_MAY_BE_SHARED_LIBS.rst
new file mode 100644
index 0000000000..930febae71
--- /dev/null
+++ b/Help/prop_gbl/TARGET_ARCHIVES_MAY_BE_SHARED_LIBS.rst
@@ -0,0 +1,7 @@
+TARGET_ARCHIVES_MAY_BE_SHARED_LIBS
+----------------------------------
+
+Set if shared libraries may be named like archives.
+
+On AIX shared libraries may be named "lib<name>.a". This property is
+set to true on such platforms.
diff --git a/Help/prop_gbl/TARGET_SUPPORTS_SHARED_LIBS.rst b/Help/prop_gbl/TARGET_SUPPORTS_SHARED_LIBS.rst
new file mode 100644
index 0000000000..f6e89fb833
--- /dev/null
+++ b/Help/prop_gbl/TARGET_SUPPORTS_SHARED_LIBS.rst
@@ -0,0 +1,9 @@
+TARGET_SUPPORTS_SHARED_LIBS
+---------------------------
+
+Does the target platform support shared libraries.
+
+TARGET_SUPPORTS_SHARED_LIBS is a boolean specifying whether the target
+platform supports shared libraries. Basically all current general
+general purpose OS do so, the exception are usually embedded systems
+with no or special OSs.
diff --git a/Help/prop_gbl/USE_FOLDERS.rst b/Help/prop_gbl/USE_FOLDERS.rst
new file mode 100644
index 0000000000..fdbca9f4ad
--- /dev/null
+++ b/Help/prop_gbl/USE_FOLDERS.rst
@@ -0,0 +1,9 @@
+USE_FOLDERS
+-----------
+
+Use the FOLDER target property to organize targets into folders.
+
+If not set, CMake treats this property as OFF by default. CMake
+generators that are capable of organizing into a hierarchy of folders
+use the values of the FOLDER target property to name those folders.
+See also the documentation for the FOLDER target property.
diff --git a/Help/prop_inst/CPACK_NEVER_OVERWRITE.rst b/Help/prop_inst/CPACK_NEVER_OVERWRITE.rst
new file mode 100644
index 0000000000..11f44d0df5
--- /dev/null
+++ b/Help/prop_inst/CPACK_NEVER_OVERWRITE.rst
@@ -0,0 +1,6 @@
+CPACK_NEVER_OVERWRITE
+---------------------
+
+Request that this file not be overwritten on install or reinstall.
+
+The property is currently only supported by the WIX generator.
diff --git a/Help/prop_inst/CPACK_PERMANENT.rst b/Help/prop_inst/CPACK_PERMANENT.rst
new file mode 100644
index 0000000000..5e191d08e5
--- /dev/null
+++ b/Help/prop_inst/CPACK_PERMANENT.rst
@@ -0,0 +1,6 @@
+CPACK_PERMANENT
+---------------
+
+Request that this file not be removed on uninstall.
+
+The property is currently only supported by the WIX generator.
diff --git a/Help/prop_inst/CPACK_WIX_ACL.rst b/Help/prop_inst/CPACK_WIX_ACL.rst
new file mode 100644
index 0000000000..ee42666dab
--- /dev/null
+++ b/Help/prop_inst/CPACK_WIX_ACL.rst
@@ -0,0 +1,18 @@
+CPACK_WIX_ACL
+-------------
+
+Specifies access permissions for files or directories
+installed by a WiX installer.
+
+The property can contain multiple list entries,
+each of which has to match the following format.
+
+::
+
+ <user>[@<domain>]=<permission>[,<permission>]
+
+``<user>`` and ``<domain>`` specify the windows user and domain for which the
+``<Permission>`` element should be generated.
+
+``<permission>`` is any of the YesNoType attributes listed here:
+http://wixtoolset.org/documentation/manual/v3/xsd/wix/permission.html
diff --git a/Help/prop_sf/ABSTRACT.rst b/Help/prop_sf/ABSTRACT.rst
new file mode 100644
index 0000000000..339d115287
--- /dev/null
+++ b/Help/prop_sf/ABSTRACT.rst
@@ -0,0 +1,9 @@
+ABSTRACT
+--------
+
+Is this source file an abstract class.
+
+A property on a source file that indicates if the source file
+represents a class that is abstract. This only makes sense for
+languages that have a notion of an abstract class and it is only used
+by some tools that wrap classes into other languages.
diff --git a/Help/prop_sf/AUTORCC_OPTIONS.rst b/Help/prop_sf/AUTORCC_OPTIONS.rst
new file mode 100644
index 0000000000..d9dc4d33ed
--- /dev/null
+++ b/Help/prop_sf/AUTORCC_OPTIONS.rst
@@ -0,0 +1,13 @@
+AUTORCC_OPTIONS
+---------------
+
+Additional options for ``rcc`` when using :prop_tgt:`AUTORCC`
+
+This property holds additional command line options which will be used when
+``rcc`` is executed during the build via :prop_tgt:`AUTORCC`, i.e. it is equivalent to the
+optional ``OPTIONS`` argument of the :module:`qt4_add_resources() <FindQt4>` macro.
+
+By default it is empty.
+
+The options set on the ``.qrc`` source file may override :prop_tgt:`AUTORCC_OPTIONS` set
+on the target.
diff --git a/Help/prop_sf/AUTOUIC_OPTIONS.rst b/Help/prop_sf/AUTOUIC_OPTIONS.rst
new file mode 100644
index 0000000000..6dfabb0782
--- /dev/null
+++ b/Help/prop_sf/AUTOUIC_OPTIONS.rst
@@ -0,0 +1,14 @@
+AUTOUIC_OPTIONS
+---------------
+
+Additional options for ``uic`` when using :prop_tgt:`AUTOUIC`
+
+This property holds additional command line options
+which will be used when ``uic`` is executed during the build via :prop_tgt:`AUTOUIC`,
+i.e. it is equivalent to the optional ``OPTIONS`` argument of the
+:module:`qt4_wrap_ui()<FindQt4>` macro.
+
+By default it is empty.
+
+The options set on the ``.ui`` source file may override :prop_tgt:`AUTOUIC_OPTIONS` set
+on the target.
diff --git a/Help/prop_sf/COMPILE_DEFINITIONS.rst b/Help/prop_sf/COMPILE_DEFINITIONS.rst
new file mode 100644
index 0000000000..7f7e7c7954
--- /dev/null
+++ b/Help/prop_sf/COMPILE_DEFINITIONS.rst
@@ -0,0 +1,20 @@
+COMPILE_DEFINITIONS
+-------------------
+
+Preprocessor definitions for compiling a source file.
+
+The COMPILE_DEFINITIONS property may be set to a semicolon-separated
+list of preprocessor definitions using the syntax VAR or VAR=value.
+Function-style definitions are not supported. CMake will
+automatically escape the value correctly for the native build system
+(note that CMake language syntax may require escapes to specify some
+values). This property may be set on a per-configuration basis using
+the name COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case
+name (ex. "COMPILE_DEFINITIONS_DEBUG").
+
+CMake will automatically drop some definitions that are not supported
+by the native build tool. The VS6 IDE does not support definition
+values with spaces (but NMake does). Xcode does not support
+per-configuration definitions on source files.
+
+.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
diff --git a/Help/prop_sf/COMPILE_DEFINITIONS_CONFIG.rst b/Help/prop_sf/COMPILE_DEFINITIONS_CONFIG.rst
new file mode 100644
index 0000000000..8487076478
--- /dev/null
+++ b/Help/prop_sf/COMPILE_DEFINITIONS_CONFIG.rst
@@ -0,0 +1,10 @@
+COMPILE_DEFINITIONS_<CONFIG>
+----------------------------
+
+Ignored. See CMake Policy :policy:`CMP0043`.
+
+Per-configuration preprocessor definitions on a source file.
+
+This is the configuration-specific version of COMPILE_DEFINITIONS.
+Note that Xcode does not support per-configuration source file flags
+so this property will be ignored by the Xcode generator.
diff --git a/Help/prop_sf/COMPILE_FLAGS.rst b/Help/prop_sf/COMPILE_FLAGS.rst
new file mode 100644
index 0000000000..daba50231f
--- /dev/null
+++ b/Help/prop_sf/COMPILE_FLAGS.rst
@@ -0,0 +1,8 @@
+COMPILE_FLAGS
+-------------
+
+Additional flags to be added when compiling this source file.
+
+These flags will be added to the list of compile flags when this
+source file builds. Use COMPILE_DEFINITIONS to pass additional
+preprocessor definitions.
diff --git a/Help/prop_sf/EXTERNAL_OBJECT.rst b/Help/prop_sf/EXTERNAL_OBJECT.rst
new file mode 100644
index 0000000000..efa0e9bea1
--- /dev/null
+++ b/Help/prop_sf/EXTERNAL_OBJECT.rst
@@ -0,0 +1,8 @@
+EXTERNAL_OBJECT
+---------------
+
+If set to true then this is an object file.
+
+If this property is set to true then the source file is really an
+object file and should not be compiled. It will still be linked into
+the target though.
diff --git a/Help/prop_sf/Fortran_FORMAT.rst b/Help/prop_sf/Fortran_FORMAT.rst
new file mode 100644
index 0000000000..69e34aafd7
--- /dev/null
+++ b/Help/prop_sf/Fortran_FORMAT.rst
@@ -0,0 +1,9 @@
+Fortran_FORMAT
+--------------
+
+Set to FIXED or FREE to indicate the Fortran source layout.
+
+This property tells CMake whether a given Fortran source file uses
+fixed-format or free-format. CMake will pass the corresponding format
+flag to the compiler. Consider using the target-wide Fortran_FORMAT
+property if all source files in a target share the same format.
diff --git a/Help/prop_sf/GENERATED.rst b/Help/prop_sf/GENERATED.rst
new file mode 100644
index 0000000000..a3aa127471
--- /dev/null
+++ b/Help/prop_sf/GENERATED.rst
@@ -0,0 +1,8 @@
+GENERATED
+---------
+
+Is this source file generated as part of the build process.
+
+If a source file is generated by the build process CMake will handle
+it differently in terms of dependency checking etc. Otherwise having
+a non-existent source file could create problems.
diff --git a/Help/prop_sf/HEADER_FILE_ONLY.rst b/Help/prop_sf/HEADER_FILE_ONLY.rst
new file mode 100644
index 0000000000..b4fb2db22e
--- /dev/null
+++ b/Help/prop_sf/HEADER_FILE_ONLY.rst
@@ -0,0 +1,9 @@
+HEADER_FILE_ONLY
+----------------
+
+Is this source file only a header file.
+
+A property on a source file that indicates if the source file is a
+header file with no associated implementation. This is set
+automatically based on the file extension and is used by CMake to
+determine if certain dependency information should be computed.
diff --git a/Help/prop_sf/KEEP_EXTENSION.rst b/Help/prop_sf/KEEP_EXTENSION.rst
new file mode 100644
index 0000000000..d6167e5a9a
--- /dev/null
+++ b/Help/prop_sf/KEEP_EXTENSION.rst
@@ -0,0 +1,9 @@
+KEEP_EXTENSION
+--------------
+
+Make the output file have the same extension as the source file.
+
+If this property is set then the file extension of the output file
+will be the same as that of the source file. Normally the output file
+extension is computed based on the language of the source file, for
+example .cxx will go to a .o extension.
diff --git a/Help/prop_sf/LABELS.rst b/Help/prop_sf/LABELS.rst
new file mode 100644
index 0000000000..e1c10696a5
--- /dev/null
+++ b/Help/prop_sf/LABELS.rst
@@ -0,0 +1,8 @@
+LABELS
+------
+
+Specify a list of text labels associated with a source file.
+
+This property has meaning only when the source file is listed in a
+target whose LABELS property is also set. No other semantics are
+currently specified.
diff --git a/Help/prop_sf/LANGUAGE.rst b/Help/prop_sf/LANGUAGE.rst
new file mode 100644
index 0000000000..97bfa20f46
--- /dev/null
+++ b/Help/prop_sf/LANGUAGE.rst
@@ -0,0 +1,10 @@
+LANGUAGE
+--------
+
+What programming language is the file.
+
+A property that can be set to indicate what programming language the
+source file is. If it is not set the language is determined based on
+the file extension. Typical values are CXX C etc. Setting this
+property for a file means this file will be compiled. Do not set this
+for headers or files that should not be compiled.
diff --git a/Help/prop_sf/LOCATION.rst b/Help/prop_sf/LOCATION.rst
new file mode 100644
index 0000000000..252d680240
--- /dev/null
+++ b/Help/prop_sf/LOCATION.rst
@@ -0,0 +1,7 @@
+LOCATION
+--------
+
+The full path to a source file.
+
+A read only property on a SOURCE FILE that contains the full path to
+the source file.
diff --git a/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst b/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst
new file mode 100644
index 0000000000..27f292961f
--- /dev/null
+++ b/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst
@@ -0,0 +1,19 @@
+MACOSX_PACKAGE_LOCATION
+-----------------------
+
+Place a source file inside a Mac OS X bundle, CFBundle, or framework.
+
+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.
diff --git a/Help/prop_sf/OBJECT_DEPENDS.rst b/Help/prop_sf/OBJECT_DEPENDS.rst
new file mode 100644
index 0000000000..18022de23b
--- /dev/null
+++ b/Help/prop_sf/OBJECT_DEPENDS.rst
@@ -0,0 +1,18 @@
+OBJECT_DEPENDS
+--------------
+
+Additional files on which a compiled object file depends.
+
+Specifies a semicolon-separated list of full-paths to files on which
+any object files compiled from this source file depend. An object
+file will be recompiled if any of the named files is newer than it.
+
+This property need not be used to specify the dependency of a source
+file on a generated header file that it includes. Although the
+property was originally introduced for this purpose, it is no longer
+necessary. If the generated header file is created by a custom
+command in the same target as the source file, the automatic
+dependency scanning process will recognize the dependency. If the
+generated header file is created by another target, an inter-target
+dependency should be created with the add_dependencies command (if one
+does not already exist due to linking relationships).
diff --git a/Help/prop_sf/OBJECT_OUTPUTS.rst b/Help/prop_sf/OBJECT_OUTPUTS.rst
new file mode 100644
index 0000000000..6a28553740
--- /dev/null
+++ b/Help/prop_sf/OBJECT_OUTPUTS.rst
@@ -0,0 +1,9 @@
+OBJECT_OUTPUTS
+--------------
+
+Additional outputs for a Makefile rule.
+
+Additional outputs created by compilation of this source file. If any
+of these outputs is missing the object will be recompiled. This is
+supported only on Makefile generators and will be ignored on other
+generators.
diff --git a/Help/prop_sf/SYMBOLIC.rst b/Help/prop_sf/SYMBOLIC.rst
new file mode 100644
index 0000000000..c7d0b2603c
--- /dev/null
+++ b/Help/prop_sf/SYMBOLIC.rst
@@ -0,0 +1,8 @@
+SYMBOLIC
+--------
+
+Is this just a name for a rule.
+
+If SYMBOLIC (boolean) is set to true the build system will be informed
+that the source file is not actually created on disk but instead used
+as a symbolic name for a build rule.
diff --git a/Help/prop_sf/VS_DEPLOYMENT_CONTENT.rst b/Help/prop_sf/VS_DEPLOYMENT_CONTENT.rst
new file mode 100644
index 0000000000..9fb3ba3d03
--- /dev/null
+++ b/Help/prop_sf/VS_DEPLOYMENT_CONTENT.rst
@@ -0,0 +1,11 @@
+VS_DEPLOYMENT_CONTENT
+---------------------
+
+Mark a source file as content for deployment with a Windows Phone or
+Windows Store application when built with a Visual Studio generator.
+The value must evaluate to either ``1`` or ``0`` and may use
+:manual:`generator expressions <cmake-generator-expressions(7)>`
+to make the choice based on the build configuration.
+The ``.vcxproj`` file entry for the source file will be
+marked either ``DeploymentContent`` or ``ExcludedFromBuild``
+for values ``1`` and ``0``, respectively.
diff --git a/Help/prop_sf/VS_SHADER_TYPE.rst b/Help/prop_sf/VS_SHADER_TYPE.rst
new file mode 100644
index 0000000000..6880256080
--- /dev/null
+++ b/Help/prop_sf/VS_SHADER_TYPE.rst
@@ -0,0 +1,4 @@
+VS_SHADER_TYPE
+--------------
+
+Set the VS shader type of a ``.hlsl`` source file.
diff --git a/Help/prop_sf/WRAP_EXCLUDE.rst b/Help/prop_sf/WRAP_EXCLUDE.rst
new file mode 100644
index 0000000000..2c79f72a2e
--- /dev/null
+++ b/Help/prop_sf/WRAP_EXCLUDE.rst
@@ -0,0 +1,10 @@
+WRAP_EXCLUDE
+------------
+
+Exclude this source file from any code wrapping techniques.
+
+Some packages can wrap source files into alternate languages to
+provide additional functionality. For example, C++ code can be
+wrapped into Java or Python etc using SWIG etc. If WRAP_EXCLUDE is
+set to true (1 etc) that indicates that this source file should not be
+wrapped.
diff --git a/Help/prop_sf/XCODE_EXPLICIT_FILE_TYPE.rst b/Help/prop_sf/XCODE_EXPLICIT_FILE_TYPE.rst
new file mode 100644
index 0000000000..1b24701a3a
--- /dev/null
+++ b/Help/prop_sf/XCODE_EXPLICIT_FILE_TYPE.rst
@@ -0,0 +1,8 @@
+XCODE_EXPLICIT_FILE_TYPE
+------------------------
+
+Set the Xcode ``explicitFileType`` attribute on its reference to a
+source file. CMake computes a default based on file extension but
+can be told explicitly with this property.
+
+See also :prop_sf:`XCODE_LAST_KNOWN_FILE_TYPE`.
diff --git a/Help/prop_sf/XCODE_LAST_KNOWN_FILE_TYPE.rst b/Help/prop_sf/XCODE_LAST_KNOWN_FILE_TYPE.rst
new file mode 100644
index 0000000000..42e37574db
--- /dev/null
+++ b/Help/prop_sf/XCODE_LAST_KNOWN_FILE_TYPE.rst
@@ -0,0 +1,9 @@
+XCODE_LAST_KNOWN_FILE_TYPE
+--------------------------
+
+Set the Xcode ``lastKnownFileType`` attribute on its reference to a
+source file. CMake computes a default based on file extension but
+can be told explicitly with this property.
+
+See also :prop_sf:`XCODE_EXPLICIT_FILE_TYPE`, which is preferred
+over this property if set.
diff --git a/Help/prop_test/ATTACHED_FILES.rst b/Help/prop_test/ATTACHED_FILES.rst
new file mode 100644
index 0000000000..496d800710
--- /dev/null
+++ b/Help/prop_test/ATTACHED_FILES.rst
@@ -0,0 +1,7 @@
+ATTACHED_FILES
+--------------
+
+Attach a list of files to a dashboard submission.
+
+Set this property to a list of files that will be encoded and
+submitted to the dashboard as an addition to the test result.
diff --git a/Help/prop_test/ATTACHED_FILES_ON_FAIL.rst b/Help/prop_test/ATTACHED_FILES_ON_FAIL.rst
new file mode 100644
index 0000000000..6819143340
--- /dev/null
+++ b/Help/prop_test/ATTACHED_FILES_ON_FAIL.rst
@@ -0,0 +1,7 @@
+ATTACHED_FILES_ON_FAIL
+----------------------
+
+Attach a list of files to a dashboard submission if the test fails.
+
+Same as ATTACHED_FILES, but these files will only be included if the
+test does not pass.
diff --git a/Help/prop_test/COST.rst b/Help/prop_test/COST.rst
new file mode 100644
index 0000000000..3236a02958
--- /dev/null
+++ b/Help/prop_test/COST.rst
@@ -0,0 +1,7 @@
+COST
+----
+
+Set this to a floating point value. Tests in a test set will be run in descending order of cost.
+
+This property describes the cost of a test. You can explicitly set
+this value; tests with higher COST values will run first.
diff --git a/Help/prop_test/DEPENDS.rst b/Help/prop_test/DEPENDS.rst
new file mode 100644
index 0000000000..ee946d938b
--- /dev/null
+++ b/Help/prop_test/DEPENDS.rst
@@ -0,0 +1,6 @@
+DEPENDS
+-------
+
+Specifies that this test should only be run after the specified list of tests.
+
+Set this to a list of tests that must finish before this test is run.
diff --git a/Help/prop_test/ENVIRONMENT.rst b/Help/prop_test/ENVIRONMENT.rst
new file mode 100644
index 0000000000..df9bc9e14e
--- /dev/null
+++ b/Help/prop_test/ENVIRONMENT.rst
@@ -0,0 +1,9 @@
+ENVIRONMENT
+-----------
+
+Specify environment variables that should be defined for running a test.
+
+If set to a list of environment variables and values of the form
+MYVAR=value those environment variables will be defined while running
+the test. The environment is restored to its previous state after the
+test is done.
diff --git a/Help/prop_test/FAIL_REGULAR_EXPRESSION.rst b/Help/prop_test/FAIL_REGULAR_EXPRESSION.rst
new file mode 100644
index 0000000000..b02d17dbbf
--- /dev/null
+++ b/Help/prop_test/FAIL_REGULAR_EXPRESSION.rst
@@ -0,0 +1,8 @@
+FAIL_REGULAR_EXPRESSION
+-----------------------
+
+If the output matches this regular expression the test will fail.
+
+If set, if the output matches one of specified regular expressions,
+the test will fail.For example: FAIL_REGULAR_EXPRESSION
+"[^a-z]Error;ERROR;Failed"
diff --git a/Help/prop_test/LABELS.rst b/Help/prop_test/LABELS.rst
new file mode 100644
index 0000000000..8d75570959
--- /dev/null
+++ b/Help/prop_test/LABELS.rst
@@ -0,0 +1,6 @@
+LABELS
+------
+
+Specify a list of text labels associated with a test.
+
+The list is reported in dashboard submissions.
diff --git a/Help/prop_test/MEASUREMENT.rst b/Help/prop_test/MEASUREMENT.rst
new file mode 100644
index 0000000000..bc4936e97c
--- /dev/null
+++ b/Help/prop_test/MEASUREMENT.rst
@@ -0,0 +1,8 @@
+MEASUREMENT
+-----------
+
+Specify a CDASH measurement and value to be reported for a test.
+
+If set to a name then that name will be reported to CDASH as a named
+measurement with a value of 1. You may also specify a value by
+setting MEASUREMENT to "measurement=value".
diff --git a/Help/prop_test/PASS_REGULAR_EXPRESSION.rst b/Help/prop_test/PASS_REGULAR_EXPRESSION.rst
new file mode 100644
index 0000000000..bb35f77345
--- /dev/null
+++ b/Help/prop_test/PASS_REGULAR_EXPRESSION.rst
@@ -0,0 +1,8 @@
+PASS_REGULAR_EXPRESSION
+-----------------------
+
+The output must match this regular expression for the test to pass.
+
+If set, the test output will be checked against the specified regular
+expressions and at least one of the regular expressions has to match,
+otherwise the test will fail.
diff --git a/Help/prop_test/PROCESSORS.rst b/Help/prop_test/PROCESSORS.rst
new file mode 100644
index 0000000000..763b6d0036
--- /dev/null
+++ b/Help/prop_test/PROCESSORS.rst
@@ -0,0 +1,8 @@
+PROCESSORS
+----------
+
+How many process slots this test requires
+
+Denotes the number of processors that this test will require. This is
+typically used for MPI tests, and should be used in conjunction with
+the ctest_test PARALLEL_LEVEL option.
diff --git a/Help/prop_test/REQUIRED_FILES.rst b/Help/prop_test/REQUIRED_FILES.rst
new file mode 100644
index 0000000000..fac357c1e0
--- /dev/null
+++ b/Help/prop_test/REQUIRED_FILES.rst
@@ -0,0 +1,7 @@
+REQUIRED_FILES
+--------------
+
+List of files required to run the test.
+
+If set to a list of files, the test will not be run unless all of the
+files exist.
diff --git a/Help/prop_test/RESOURCE_LOCK.rst b/Help/prop_test/RESOURCE_LOCK.rst
new file mode 100644
index 0000000000..8c30f0177c
--- /dev/null
+++ b/Help/prop_test/RESOURCE_LOCK.rst
@@ -0,0 +1,7 @@
+RESOURCE_LOCK
+-------------
+
+Specify a list of resources that are locked by this test.
+
+If multiple tests specify the same resource lock, they are guaranteed
+not to run concurrently.
diff --git a/Help/prop_test/RUN_SERIAL.rst b/Help/prop_test/RUN_SERIAL.rst
new file mode 100644
index 0000000000..8f65ae18a7
--- /dev/null
+++ b/Help/prop_test/RUN_SERIAL.rst
@@ -0,0 +1,8 @@
+RUN_SERIAL
+----------
+
+Do not run this test in parallel with any other test.
+
+Use this option in conjunction with the ctest_test PARALLEL_LEVEL
+option to specify that this test should not be run in parallel with
+any other tests.
diff --git a/Help/prop_test/SKIP_RETURN_CODE.rst b/Help/prop_test/SKIP_RETURN_CODE.rst
new file mode 100644
index 0000000000..c61273c56c
--- /dev/null
+++ b/Help/prop_test/SKIP_RETURN_CODE.rst
@@ -0,0 +1,9 @@
+SKIP_RETURN_CODE
+----------------
+
+Return code to mark a test as skipped.
+
+Sometimes only a test itself can determine if all requirements for the
+test are met. If such a situation should not be considered a hard failure
+a return code of the process can be specified that will mark the test as
+"Not Run" if it is encountered.
diff --git a/Help/prop_test/TIMEOUT.rst b/Help/prop_test/TIMEOUT.rst
new file mode 100644
index 0000000000..0b247b8601
--- /dev/null
+++ b/Help/prop_test/TIMEOUT.rst
@@ -0,0 +1,9 @@
+TIMEOUT
+-------
+
+How many seconds to allow for this test.
+
+This property if set will limit a test to not take more than the
+specified number of seconds to run. If it exceeds that the test
+process will be killed and ctest will move to the next test. This
+setting takes precedence over CTEST_TESTING_TIMEOUT.
diff --git a/Help/prop_test/WILL_FAIL.rst b/Help/prop_test/WILL_FAIL.rst
new file mode 100644
index 0000000000..f1f94a43a7
--- /dev/null
+++ b/Help/prop_test/WILL_FAIL.rst
@@ -0,0 +1,7 @@
+WILL_FAIL
+---------
+
+If set to true, this will invert the pass/fail flag of the test.
+
+This property can be used for tests that are expected to fail and
+return a non zero return code.
diff --git a/Help/prop_test/WORKING_DIRECTORY.rst b/Help/prop_test/WORKING_DIRECTORY.rst
new file mode 100644
index 0000000000..5222a197bd
--- /dev/null
+++ b/Help/prop_test/WORKING_DIRECTORY.rst
@@ -0,0 +1,7 @@
+WORKING_DIRECTORY
+-----------------
+
+The directory from which the test executable will be called.
+
+If this is not set it is called from the directory the test executable
+is located in.
diff --git a/Help/prop_tgt/ALIASED_TARGET.rst b/Help/prop_tgt/ALIASED_TARGET.rst
new file mode 100644
index 0000000000..f9e60348db
--- /dev/null
+++ b/Help/prop_tgt/ALIASED_TARGET.rst
@@ -0,0 +1,7 @@
+ALIASED_TARGET
+--------------
+
+Name of target aliased by this target.
+
+If this is an :ref:`Alias Target <Alias Targets>`, this property contains
+the name of the target aliased.
diff --git a/Help/prop_tgt/ANDROID_API.rst b/Help/prop_tgt/ANDROID_API.rst
new file mode 100644
index 0000000000..714ad584af
--- /dev/null
+++ b/Help/prop_tgt/ANDROID_API.rst
@@ -0,0 +1,7 @@
+ANDROID_API
+-----------
+
+Set the Android Target API version (e.g. ``15``). The version number
+must be a positive decimal integer. This property is initialized by
+the value of the :variable:`CMAKE_ANDROID_API` variable if it is set
+when a target is created.
diff --git a/Help/prop_tgt/ANDROID_GUI.rst b/Help/prop_tgt/ANDROID_GUI.rst
new file mode 100644
index 0000000000..90d2428b1f
--- /dev/null
+++ b/Help/prop_tgt/ANDROID_GUI.rst
@@ -0,0 +1,9 @@
+ANDROID_GUI
+-----------
+
+Build an executable as an application package on Android.
+
+When this property is set to true the executable when built for Android
+will be created as an application package. This property is initialized
+by the value of the :variable:`CMAKE_ANDROID_GUI` variable if it is set
+when a target is created.
diff --git a/Help/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY.rst b/Help/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..df57dbaafe
--- /dev/null
+++ b/Help/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,7 @@
+ARCHIVE_OUTPUT_DIRECTORY
+------------------------
+
+.. |XXX| replace:: ARCHIVE
+.. |xxx| replace:: archive
+.. |CMAKE_XXX_OUTPUT_DIRECTORY| replace:: CMAKE_ARCHIVE_OUTPUT_DIRECTORY
+.. include:: XXX_OUTPUT_DIRECTORY.txt
diff --git a/Help/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY_CONFIG.rst b/Help/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY_CONFIG.rst
new file mode 100644
index 0000000000..3c0c4fdffe
--- /dev/null
+++ b/Help/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY_CONFIG.rst
@@ -0,0 +1,11 @@
+ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>
+---------------------------------
+
+Per-configuration output directory for ARCHIVE target files.
+
+This is a per-configuration version of ARCHIVE_OUTPUT_DIRECTORY, but
+multi-configuration generators (VS, Xcode) do NOT append a
+per-configuration subdirectory to the specified directory. This
+property is initialized by the value of the variable
+CMAKE_ARCHIVE_OUTPUT_DIRECTORY_<CONFIG> if it is set when a target is
+created.
diff --git a/Help/prop_tgt/ARCHIVE_OUTPUT_NAME.rst b/Help/prop_tgt/ARCHIVE_OUTPUT_NAME.rst
new file mode 100644
index 0000000000..a137bb8911
--- /dev/null
+++ b/Help/prop_tgt/ARCHIVE_OUTPUT_NAME.rst
@@ -0,0 +1,6 @@
+ARCHIVE_OUTPUT_NAME
+-------------------
+
+.. |XXX| replace:: ARCHIVE
+.. |xxx| replace:: archive
+.. include:: XXX_OUTPUT_NAME.txt
diff --git a/Help/prop_tgt/ARCHIVE_OUTPUT_NAME_CONFIG.rst b/Help/prop_tgt/ARCHIVE_OUTPUT_NAME_CONFIG.rst
new file mode 100644
index 0000000000..314fa58b6b
--- /dev/null
+++ b/Help/prop_tgt/ARCHIVE_OUTPUT_NAME_CONFIG.rst
@@ -0,0 +1,6 @@
+ARCHIVE_OUTPUT_NAME_<CONFIG>
+----------------------------
+
+Per-configuration output name for ARCHIVE target files.
+
+This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.
diff --git a/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst b/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst
new file mode 100644
index 0000000000..5063244b53
--- /dev/null
+++ b/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst
@@ -0,0 +1,17 @@
+AUTOGEN_TARGET_DEPENDS
+----------------------
+
+Target dependencies of the corresponding ``_automoc`` target.
+
+Targets which have their :prop_tgt:`AUTOMOC` target ``ON`` have a
+corresponding ``_automoc`` target which is used to autogenerate generate moc
+files. As this ``_automoc`` target is created at generate-time, it is not
+possible to define dependencies of it, such as to create inputs for the ``moc``
+executable.
+
+The ``AUTOGEN_TARGET_DEPENDS`` target property can be set instead to a list of
+dependencies for the ``_automoc`` target. The buildsystem will be generated to
+depend on its contents.
+
+See the :manual:`cmake-qt(7)` manual for more information on using CMake
+with Qt.
diff --git a/Help/prop_tgt/AUTOMOC.rst b/Help/prop_tgt/AUTOMOC.rst
new file mode 100644
index 0000000000..045ebb275f
--- /dev/null
+++ b/Help/prop_tgt/AUTOMOC.rst
@@ -0,0 +1,37 @@
+AUTOMOC
+-------
+
+Should the target be processed with automoc (for Qt projects).
+
+AUTOMOC is a boolean specifying whether CMake will handle the Qt ``moc``
+preprocessor automatically, i.e. without having to use the
+:module:`QT4_WRAP_CPP() <FindQt4>` or QT5_WRAP_CPP() macro. Currently Qt4 and Qt5 are
+supported. When this property is set ``ON``, CMake will scan the
+source files at build time and invoke moc accordingly. If an ``#include``
+statement like ``#include "moc_foo.cpp"`` is found, the ``Q_OBJECT`` class
+declaration is expected in the header, and ``moc`` is run on the header
+file. If an ``#include`` statement like ``#include "foo.moc"`` is found, then
+a ``Q_OBJECT`` is expected in the current source file and ``moc`` is run on
+the file itself. Additionally, header files with the same base name (like
+``foo.h``) or ``_p`` appended to the base name (like ``foo_p.h``) are parsed
+for ``Q_OBJECT`` macros, and if found, ``moc`` is also executed on those files.
+``AUTOMOC`` checks multiple header alternative extensions, such as
+``hpp``, ``hxx`` etc when searching for headers.
+The resulting moc files, which are not included as shown above in any
+of the source files are included in a generated
+``<targetname>_automoc.cpp`` file, which is compiled as part of the
+target. This property is initialized by the value of the
+:variable:`CMAKE_AUTOMOC` variable if it is set when a target is created.
+
+Additional command line options for moc can be set via the
+:prop_tgt:`AUTOMOC_MOC_OPTIONS` property.
+
+By enabling the :variable:`CMAKE_AUTOMOC_RELAXED_MODE` variable the
+rules for searching the files which will be processed by moc can be relaxed.
+See the documentation for this variable for more details.
+
+The global property :prop_gbl:`AUTOGEN_TARGETS_FOLDER` can be used to group the
+automoc targets together in an IDE, e.g. in MSVS.
+
+See the :manual:`cmake-qt(7)` manual for more information on using CMake
+with Qt.
diff --git a/Help/prop_tgt/AUTOMOC_MOC_OPTIONS.rst b/Help/prop_tgt/AUTOMOC_MOC_OPTIONS.rst
new file mode 100644
index 0000000000..ebd5c4951b
--- /dev/null
+++ b/Help/prop_tgt/AUTOMOC_MOC_OPTIONS.rst
@@ -0,0 +1,15 @@
+AUTOMOC_MOC_OPTIONS
+-------------------
+
+Additional options for moc when using :prop_tgt:`AUTOMOC`
+
+This property is only used if the :prop_tgt:`AUTOMOC` property is ``ON``
+for this target. In this case, it holds additional command line
+options which will be used when ``moc`` is executed during the build, i.e.
+it is equivalent to the optional ``OPTIONS`` argument of the
+:module:`qt4_wrap_cpp() <FindQt4>` macro.
+
+By default it is empty.
+
+See the :manual:`cmake-qt(7)` manual for more information on using CMake
+with Qt.
diff --git a/Help/prop_tgt/AUTORCC.rst b/Help/prop_tgt/AUTORCC.rst
new file mode 100644
index 0000000000..8dce6b184f
--- /dev/null
+++ b/Help/prop_tgt/AUTORCC.rst
@@ -0,0 +1,23 @@
+AUTORCC
+-------
+
+Should the target be processed with autorcc (for Qt projects).
+
+``AUTORCC`` is a boolean specifying whether CMake will handle
+the Qt ``rcc`` code generator automatically, i.e. without having to use
+the :module:`QT4_ADD_RESOURCES() <FindQt4>` or ``QT5_ADD_RESOURCES()``
+macro. Currently Qt4 and Qt5 are supported.
+
+When this property is ``ON``, CMake will handle ``.qrc`` files added
+as target sources at build time and invoke ``rcc`` accordingly.
+This property is initialized by the value of the :variable:`CMAKE_AUTORCC`
+variable if it is set when a target is created.
+
+Additional command line options for rcc can be set via the
+:prop_sf:`AUTORCC_OPTIONS` source file property on the ``.qrc`` file.
+
+The global property :prop_gbl:`AUTOGEN_TARGETS_FOLDER` can be used to group
+the autorcc targets together in an IDE, e.g. in MSVS.
+
+See the :manual:`cmake-qt(7)` manual for more information on using CMake
+with Qt.
diff --git a/Help/prop_tgt/AUTORCC_OPTIONS.rst b/Help/prop_tgt/AUTORCC_OPTIONS.rst
new file mode 100644
index 0000000000..8a0f632c23
--- /dev/null
+++ b/Help/prop_tgt/AUTORCC_OPTIONS.rst
@@ -0,0 +1,21 @@
+AUTORCC_OPTIONS
+---------------
+
+Additional options for ``rcc`` when using :prop_tgt:`AUTORCC`
+
+This property holds additional command line options which will be used
+when ``rcc`` is executed during the build via :prop_tgt:`AUTORCC`,
+i.e. it is equivalent to the optional ``OPTIONS`` argument of the
+:module:`qt4_add_resources() <FindQt4>` macro.
+
+By default it is empty.
+
+This property is initialized by the value of the
+:variable:`CMAKE_AUTORCC_OPTIONS` variable if it is set when a target is
+created.
+
+The options set on the target may be overridden by :prop_sf:`AUTORCC_OPTIONS`
+set on the ``.qrc`` source file.
+
+See the :manual:`cmake-qt(7)` manual for more information on using CMake
+with Qt.
diff --git a/Help/prop_tgt/AUTOUIC.rst b/Help/prop_tgt/AUTOUIC.rst
new file mode 100644
index 0000000000..4e60ec33ab
--- /dev/null
+++ b/Help/prop_tgt/AUTOUIC.rst
@@ -0,0 +1,24 @@
+AUTOUIC
+-------
+
+Should the target be processed with autouic (for Qt projects).
+
+``AUTOUIC`` is a boolean specifying whether CMake will handle
+the Qt ``uic`` code generator automatically, i.e. without having to use
+the :module:`QT4_WRAP_UI() <FindQt4>` or ``QT5_WRAP_UI()`` macro. Currently
+Qt4 and Qt5 are supported.
+
+When this property is ``ON``, CMake will scan the source files at build time
+and invoke ``uic`` accordingly. If an ``#include`` statement like
+``#include "ui_foo.h"`` is found in ``foo.cpp``, a ``foo.ui`` file is
+expected next to ``foo.cpp``, and ``uic`` is run on the ``foo.ui`` file.
+This property is initialized by the value of the :variable:`CMAKE_AUTOUIC`
+variable if it is set when a target is created.
+
+Additional command line options for ``uic`` can be set via the
+:prop_sf:`AUTOUIC_OPTIONS` source file property on the ``foo.ui`` file.
+The global property :prop_gbl:`AUTOGEN_TARGETS_FOLDER` can be used to group the
+autouic targets together in an IDE, e.g. in MSVS.
+
+See the :manual:`cmake-qt(7)` manual for more information on using CMake
+with Qt.
diff --git a/Help/prop_tgt/AUTOUIC_OPTIONS.rst b/Help/prop_tgt/AUTOUIC_OPTIONS.rst
new file mode 100644
index 0000000000..dc3bee55f5
--- /dev/null
+++ b/Help/prop_tgt/AUTOUIC_OPTIONS.rst
@@ -0,0 +1,25 @@
+AUTOUIC_OPTIONS
+---------------
+
+Additional options for uic when using :prop_tgt:`AUTOUIC`
+
+This property holds additional command line options which will be used when
+``uic`` is executed during the build via :prop_tgt:`AUTOUIC`, i.e. it is
+equivalent to the optional ``OPTIONS`` argument of the
+:module:`qt4_wrap_ui() <FindQt4>` macro.
+
+By default it is empty.
+
+This property is initialized by the value of the
+:variable:`CMAKE_AUTOUIC_OPTIONS` variable if it is set when a target is
+created.
+
+The options set on the target may be overridden by :prop_sf:`AUTOUIC_OPTIONS`
+set on the ``.ui`` source file.
+
+This property may use "generator expressions" with the syntax ``$<...>``.
+See the :manual:`cmake-generator-expressions(7)` manual for available
+expressions.
+
+See the :manual:`cmake-qt(7)` manual for more information on using CMake
+with Qt.
diff --git a/Help/prop_tgt/BUILD_WITH_INSTALL_RPATH.rst b/Help/prop_tgt/BUILD_WITH_INSTALL_RPATH.rst
new file mode 100644
index 0000000000..abcf28ffdb
--- /dev/null
+++ b/Help/prop_tgt/BUILD_WITH_INSTALL_RPATH.rst
@@ -0,0 +1,11 @@
+BUILD_WITH_INSTALL_RPATH
+------------------------
+
+Should build tree targets have install tree rpaths.
+
+BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link the
+target in the build tree with the INSTALL_RPATH. This takes
+precedence over SKIP_BUILD_RPATH and avoids the need for relinking
+before installation. This property is initialized by the value of the
+variable CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is
+created.
diff --git a/Help/prop_tgt/BUNDLE.rst b/Help/prop_tgt/BUNDLE.rst
new file mode 100644
index 0000000000..166659fb29
--- /dev/null
+++ b/Help/prop_tgt/BUNDLE.rst
@@ -0,0 +1,9 @@
+BUNDLE
+------
+
+This target is a CFBundle on the Mac.
+
+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
+creating Browser Plugins or other application resources.
diff --git a/Help/prop_tgt/BUNDLE_EXTENSION.rst b/Help/prop_tgt/BUNDLE_EXTENSION.rst
new file mode 100644
index 0000000000..94ac935bcf
--- /dev/null
+++ b/Help/prop_tgt/BUNDLE_EXTENSION.rst
@@ -0,0 +1,7 @@
+BUNDLE_EXTENSION
+----------------
+
+The file extension used to name a BUNDLE target on the Mac.
+
+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/COMPATIBLE_INTERFACE_BOOL.rst b/Help/prop_tgt/COMPATIBLE_INTERFACE_BOOL.rst
new file mode 100644
index 0000000000..6910367e4e
--- /dev/null
+++ b/Help/prop_tgt/COMPATIBLE_INTERFACE_BOOL.rst
@@ -0,0 +1,20 @@
+COMPATIBLE_INTERFACE_BOOL
+-------------------------
+
+Properties which must be compatible with their link interface
+
+The ``COMPATIBLE_INTERFACE_BOOL`` property may contain a list of
+properties for this target which must be consistent when evaluated as a
+boolean with the ``INTERFACE`` variant of the property in all linked
+dependees. For example, if a property ``FOO`` appears in the list, then
+for each dependee, the ``INTERFACE_FOO`` property content in all of its
+dependencies must be consistent with each other, and with the ``FOO``
+property in the depender.
+
+Consistency in this sense has the meaning that if the property is set,
+then it must have the same boolean value as all others, and if the
+property is not set, then it is ignored.
+
+Note that for each dependee, the set of properties specified in this
+property must not intersect with the set specified in any of the other
+:ref:`Compatible Interface Properties`.
diff --git a/Help/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MAX.rst b/Help/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MAX.rst
new file mode 100644
index 0000000000..298acf1ba3
--- /dev/null
+++ b/Help/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MAX.rst
@@ -0,0 +1,18 @@
+COMPATIBLE_INTERFACE_NUMBER_MAX
+-------------------------------
+
+Properties whose maximum value from the link interface will be used.
+
+The ``COMPATIBLE_INTERFACE_NUMBER_MAX`` property may contain a list of
+properties for this target whose maximum value may be read at generate
+time when evaluated in the ``INTERFACE`` variant of the property in all
+linked dependees. For example, if a property ``FOO`` appears in the list,
+then for each dependee, the ``INTERFACE_FOO`` property content in all of
+its dependencies will be compared with each other and with the ``FOO``
+property in the depender. When reading the ``FOO`` property at generate
+time, the maximum value will be returned. If the property is not set,
+then it is ignored.
+
+Note that for each dependee, the set of properties specified in this
+property must not intersect with the set specified in any of the other
+:ref:`Compatible Interface Properties`.
diff --git a/Help/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MIN.rst b/Help/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MIN.rst
new file mode 100644
index 0000000000..d5fd8252a8
--- /dev/null
+++ b/Help/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MIN.rst
@@ -0,0 +1,18 @@
+COMPATIBLE_INTERFACE_NUMBER_MIN
+-------------------------------
+
+Properties whose maximum value from the link interface will be used.
+
+The ``COMPATIBLE_INTERFACE_NUMBER_MIN`` property may contain a list of
+properties for this target whose minimum value may be read at generate
+time when evaluated in the ``INTERFACE`` variant of the property of all
+linked dependees. For example, if a
+property ``FOO`` appears in the list, then for each dependee, the
+``INTERFACE_FOO`` property content in all of its dependencies will be
+compared with each other and with the ``FOO`` property in the depender.
+When reading the ``FOO`` property at generate time, the minimum value
+will be returned. If the property is not set, then it is ignored.
+
+Note that for each dependee, the set of properties specified in this
+property must not intersect with the set specified in any of the other
+:ref:`Compatible Interface Properties`.
diff --git a/Help/prop_tgt/COMPATIBLE_INTERFACE_STRING.rst b/Help/prop_tgt/COMPATIBLE_INTERFACE_STRING.rst
new file mode 100644
index 0000000000..a0050b9418
--- /dev/null
+++ b/Help/prop_tgt/COMPATIBLE_INTERFACE_STRING.rst
@@ -0,0 +1,16 @@
+COMPATIBLE_INTERFACE_STRING
+---------------------------
+
+Properties which must be string-compatible with their link interface
+
+The ``COMPATIBLE_INTERFACE_STRING`` property may contain a list of
+properties for this target which must be the same when evaluated as a
+string in the ``INTERFACE`` variant of the property all linked dependees.
+For example, if a property ``FOO`` appears in the list, then for each
+dependee, the ``INTERFACE_FOO`` property content in all of its
+dependencies must be equal with each other, and with the ``FOO`` property
+in the depender. If the property is not set, then it is ignored.
+
+Note that for each dependee, the set of properties specified in this
+property must not intersect with the set specified in any of the other
+:ref:`Compatible Interface Properties`.
diff --git a/Help/prop_tgt/COMPILE_DEFINITIONS.rst b/Help/prop_tgt/COMPILE_DEFINITIONS.rst
new file mode 100644
index 0000000000..00c49c3795
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_DEFINITIONS.rst
@@ -0,0 +1,26 @@
+COMPILE_DEFINITIONS
+-------------------
+
+Preprocessor definitions for compiling a target's sources.
+
+The ``COMPILE_DEFINITIONS`` property may be set to a semicolon-separated
+list of preprocessor definitions using the syntax ``VAR`` or ``VAR=value``.
+Function-style definitions are not supported. CMake will
+automatically escape the value correctly for the native build system
+(note that CMake language syntax may require escapes to specify some
+values).
+
+CMake will automatically drop some definitions that are not supported
+by the native build tool. The VS6 IDE does not support definition
+values with spaces (but NMake does).
+
+.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
+
+Contents of ``COMPILE_DEFINITIONS`` 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.
+
+The corresponding :prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` property may
+be set to specify per-configuration definitions. Generator expressions
+should be preferred instead of setting the alternative property.
diff --git a/Help/prop_tgt/COMPILE_DEFINITIONS_CONFIG.rst b/Help/prop_tgt/COMPILE_DEFINITIONS_CONFIG.rst
new file mode 100644
index 0000000000..84bd5e4831
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_DEFINITIONS_CONFIG.rst
@@ -0,0 +1,16 @@
+COMPILE_DEFINITIONS_<CONFIG>
+----------------------------
+
+Ignored. See CMake Policy :policy:`CMP0043`.
+
+Per-configuration preprocessor definitions on a target.
+
+This is the configuration-specific version of :prop_tgt:`COMPILE_DEFINITIONS`
+where ``<CONFIG>`` is an upper-case name (ex. ``COMPILE_DEFINITIONS_DEBUG``).
+
+Contents of ``COMPILE_DEFINITIONS_<CONFIG>`` 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.
+
+Generator expressions should be preferred instead of setting this property.
diff --git a/Help/prop_tgt/COMPILE_FEATURES.rst b/Help/prop_tgt/COMPILE_FEATURES.rst
new file mode 100644
index 0000000000..225ffeecae
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_FEATURES.rst
@@ -0,0 +1,12 @@
+COMPILE_FEATURES
+----------------
+
+Compiler features enabled for this target.
+
+The list of features in this property are a subset of the features listed
+in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable.
+
+Contents of ``COMPILE_FEATURES`` may use "generator expressions" with the
+syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` manual for
+available expressions. See the :manual:`cmake-compile-features(7)` manual
+for information on compile features.
diff --git a/Help/prop_tgt/COMPILE_FLAGS.rst b/Help/prop_tgt/COMPILE_FLAGS.rst
new file mode 100644
index 0000000000..6ee6c51486
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_FLAGS.rst
@@ -0,0 +1,11 @@
+COMPILE_FLAGS
+-------------
+
+Additional flags to use when compiling this target's sources.
+
+The COMPILE_FLAGS property sets additional compiler flags used to
+build sources within the target. Use COMPILE_DEFINITIONS to pass
+additional preprocessor definitions.
+
+This property is deprecated. Use the COMPILE_OPTIONS property or the
+target_compile_options command instead.
diff --git a/Help/prop_tgt/COMPILE_OPTIONS.rst b/Help/prop_tgt/COMPILE_OPTIONS.rst
new file mode 100644
index 0000000000..27cbec15f2
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_OPTIONS.rst
@@ -0,0 +1,16 @@
+COMPILE_OPTIONS
+---------------
+
+List of options to pass to the compiler.
+
+This property specifies the list of options specified so far for this
+property.
+
+This property is intialized by the :prop_dir:`COMPILE_OPTIONS` directory
+property, which is used by the generators to set the options for the
+compiler.
+
+Contents of ``COMPILE_OPTIONS`` 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/Help/prop_tgt/COMPILE_PDB_NAME.rst b/Help/prop_tgt/COMPILE_PDB_NAME.rst
new file mode 100644
index 0000000000..24a9f62d6e
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_PDB_NAME.rst
@@ -0,0 +1,11 @@
+COMPILE_PDB_NAME
+----------------
+
+Output name for the MS debug symbol ``.pdb`` file generated by the
+compiler while building source files.
+
+This property specifies the base name for the debug symbols file.
+If not set, the default is unspecified.
+
+.. |PDB_XXX| replace:: :prop_tgt:`PDB_NAME`
+.. include:: COMPILE_PDB_NOTE.txt
diff --git a/Help/prop_tgt/COMPILE_PDB_NAME_CONFIG.rst b/Help/prop_tgt/COMPILE_PDB_NAME_CONFIG.rst
new file mode 100644
index 0000000000..e4077f559a
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_PDB_NAME_CONFIG.rst
@@ -0,0 +1,10 @@
+COMPILE_PDB_NAME_<CONFIG>
+-------------------------
+
+Per-configuration output name for the MS debug symbol ``.pdb`` file
+generated by the compiler while building source files.
+
+This is the configuration-specific version of :prop_tgt:`COMPILE_PDB_NAME`.
+
+.. |PDB_XXX| replace:: :prop_tgt:`PDB_NAME_<CONFIG>`
+.. include:: COMPILE_PDB_NOTE.txt
diff --git a/Help/prop_tgt/COMPILE_PDB_NOTE.txt b/Help/prop_tgt/COMPILE_PDB_NOTE.txt
new file mode 100644
index 0000000000..5941d72efe
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_PDB_NOTE.txt
@@ -0,0 +1,8 @@
+.. note::
+ The compiler-generated program database files are specified by the
+ ``/Fd`` compiler flag and are not the same as linker-generated
+ program database files specified by the ``/pdb`` linker flag.
+ Use the |PDB_XXX| property to specify the latter.
+
+ This property is not implemented by the :generator:`Visual Studio 6`
+ generator.
diff --git a/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY.rst b/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..34f49bebef
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,13 @@
+COMPILE_PDB_OUTPUT_DIRECTORY
+----------------------------
+
+Output directory for the MS debug symbol ``.pdb`` file
+generated by the compiler while building source files.
+
+This property specifies the directory into which the MS debug symbols
+will be placed by the compiler. This property is initialized by the
+value of the :variable:`CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY` variable
+if it is set when a target is created.
+
+.. |PDB_XXX| replace:: :prop_tgt:`PDB_OUTPUT_DIRECTORY`
+.. include:: COMPILE_PDB_NOTE.txt
diff --git a/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst b/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst
new file mode 100644
index 0000000000..52ef013da1
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst
@@ -0,0 +1,16 @@
+COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>
+-------------------------------------
+
+Per-configuration output directory for the MS debug symbol ``.pdb`` file
+generated by the compiler while building source files.
+
+This is a per-configuration version of
+:prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY`,
+but multi-configuration generators (VS, Xcode) do NOT append a
+per-configuration subdirectory to the specified directory. This
+property is initialized by the value of the
+:variable:`CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>` variable
+if it is set when a target is created.
+
+.. |PDB_XXX| replace:: :prop_tgt:`PDB_OUTPUT_DIRECTORY_<CONFIG>`
+.. include:: COMPILE_PDB_NOTE.txt
diff --git a/Help/prop_tgt/CONFIG_OUTPUT_NAME.rst b/Help/prop_tgt/CONFIG_OUTPUT_NAME.rst
new file mode 100644
index 0000000000..f2c875ef55
--- /dev/null
+++ b/Help/prop_tgt/CONFIG_OUTPUT_NAME.rst
@@ -0,0 +1,7 @@
+<CONFIG>_OUTPUT_NAME
+--------------------
+
+Old per-configuration target file base name.
+
+This is a configuration-specific version of OUTPUT_NAME. Use
+OUTPUT_NAME_<CONFIG> instead.
diff --git a/Help/prop_tgt/CONFIG_POSTFIX.rst b/Help/prop_tgt/CONFIG_POSTFIX.rst
new file mode 100644
index 0000000000..11b50b900f
--- /dev/null
+++ b/Help/prop_tgt/CONFIG_POSTFIX.rst
@@ -0,0 +1,10 @@
+<CONFIG>_POSTFIX
+----------------
+
+Postfix to append to the target file name for configuration <CONFIG>.
+
+When building with configuration <CONFIG> the value of this property
+is appended to the target file name built on disk. For non-executable
+targets, this property is initialized by the value of the variable
+CMAKE_<CONFIG>_POSTFIX if it is set when a target is created. This
+property is ignored on the Mac for Frameworks and App Bundles.
diff --git a/Help/prop_tgt/CXX_EXTENSIONS.rst b/Help/prop_tgt/CXX_EXTENSIONS.rst
new file mode 100644
index 0000000000..67c5cb0153
--- /dev/null
+++ b/Help/prop_tgt/CXX_EXTENSIONS.rst
@@ -0,0 +1,16 @@
+CXX_EXTENSIONS
+--------------
+
+Boolean specifying whether compiler specific extensions are requested.
+
+This property specifies whether compiler specific extensions should be
+used. For some compilers, this results in adding a flag such
+as ``-std=gnu++11`` instead of ``-std=c++11`` to the compile line. This
+property is ``ON`` by default.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
+
+This property is initialized by the value of
+the :variable:`CMAKE_CXX_EXTENSIONS` variable if it is set when a target
+is created.
diff --git a/Help/prop_tgt/CXX_STANDARD.rst b/Help/prop_tgt/CXX_STANDARD.rst
new file mode 100644
index 0000000000..b50cdf9c75
--- /dev/null
+++ b/Help/prop_tgt/CXX_STANDARD.rst
@@ -0,0 +1,30 @@
+CXX_STANDARD
+------------
+
+The C++ standard whose features are requested to build this target.
+
+This property specifies the C++ standard whose features are requested
+to build this target. For some compilers, this results in adding a
+flag such as ``-std=gnu++11`` to the compile line.
+
+Supported values are ``98`` and ``11``.
+
+If the value requested does not result in a compile flag being added for
+the compiler in use, a previous standard flag will be added instead. This
+means that using:
+
+.. code-block:: cmake
+
+ set_property(TARGET tgt PROPERTY CXX_STANDARD 11)
+
+with a compiler which does not support ``-std=gnu++11`` or an equivalent
+flag will not result in an error or warning, but will instead add the
+``-std=gnu++98`` flag if supported. This "decay" behavior may be controlled
+with the :prop_tgt:`CXX_STANDARD_REQUIRED` target property.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
+
+This property is initialized by the value of
+the :variable:`CMAKE_CXX_STANDARD` variable if it is set when a target
+is created.
diff --git a/Help/prop_tgt/CXX_STANDARD_REQUIRED.rst b/Help/prop_tgt/CXX_STANDARD_REQUIRED.rst
new file mode 100644
index 0000000000..ac103a46cc
--- /dev/null
+++ b/Help/prop_tgt/CXX_STANDARD_REQUIRED.rst
@@ -0,0 +1,17 @@
+CXX_STANDARD_REQUIRED
+---------------------
+
+Boolean describing whether the value of :prop_tgt:`CXX_STANDARD` is a requirement.
+
+If this property is set to ``ON``, then the value of the
+:prop_tgt:`CXX_STANDARD` target property is treated as a requirement. If this
+property is ``OFF`` or unset, the :prop_tgt:`CXX_STANDARD` target property is
+treated as optional and may "decay" to a previous standard if the requested is
+not available.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
+
+This property is initialized by the value of
+the :variable:`CMAKE_CXX_STANDARD_REQUIRED` variable if it is set when a
+target is created.
diff --git a/Help/prop_tgt/C_EXTENSIONS.rst b/Help/prop_tgt/C_EXTENSIONS.rst
new file mode 100644
index 0000000000..dc48cc6438
--- /dev/null
+++ b/Help/prop_tgt/C_EXTENSIONS.rst
@@ -0,0 +1,16 @@
+C_EXTENSIONS
+------------
+
+Boolean specifying whether compiler specific extensions are requested.
+
+This property specifies whether compiler specific extensions should be
+used. For some compilers, this results in adding a flag such
+as ``-std=gnu11`` instead of ``-std=c11`` to the compile line. This
+property is ``ON`` by default.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
+
+This property is initialized by the value of
+the :variable:`CMAKE_C_EXTENSIONS` variable if it is set when a target
+is created.
diff --git a/Help/prop_tgt/C_STANDARD.rst b/Help/prop_tgt/C_STANDARD.rst
new file mode 100644
index 0000000000..88ca9264db
--- /dev/null
+++ b/Help/prop_tgt/C_STANDARD.rst
@@ -0,0 +1,30 @@
+C_STANDARD
+----------
+
+The C standard whose features are requested to build this target.
+
+This property specifies the C standard whose features are requested
+to build this target. For some compilers, this results in adding a
+flag such as ``-std=gnu11`` to the compile line.
+
+Supported values are ``90``, ``99`` and ``11``.
+
+If the value requested does not result in a compile flag being added for
+the compiler in use, a previous standard flag will be added instead. This
+means that using:
+
+.. code-block:: cmake
+
+ set_property(TARGET tgt PROPERTY C_STANDARD 11)
+
+with a compiler which does not support ``-std=gnu11`` or an equivalent
+flag will not result in an error or warning, but will instead add the
+``-std=gnu99`` or ``-std=gnu90`` flag if supported. This "decay" behavior may
+be controlled with the :prop_tgt:`C_STANDARD_REQUIRED` target property.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
+
+This property is initialized by the value of
+the :variable:`CMAKE_C_STANDARD` variable if it is set when a target
+is created.
diff --git a/Help/prop_tgt/C_STANDARD_REQUIRED.rst b/Help/prop_tgt/C_STANDARD_REQUIRED.rst
new file mode 100644
index 0000000000..a7304f4386
--- /dev/null
+++ b/Help/prop_tgt/C_STANDARD_REQUIRED.rst
@@ -0,0 +1,17 @@
+C_STANDARD_REQUIRED
+-------------------
+
+Boolean describing whether the value of :prop_tgt:`C_STANDARD` is a requirement.
+
+If this property is set to ``ON``, then the value of the
+:prop_tgt:`C_STANDARD` target property is treated as a requirement. If this
+property is ``OFF`` or unset, the :prop_tgt:`C_STANDARD` target property is
+treated as optional and may "decay" to a previous standard if the requested is
+not available.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
+
+This property is initialized by the value of
+the :variable:`CMAKE_C_STANDARD_REQUIRED` variable if it is set when a
+target is created.
diff --git a/Help/prop_tgt/DEBUG_POSTFIX.rst b/Help/prop_tgt/DEBUG_POSTFIX.rst
new file mode 100644
index 0000000000..1487656d95
--- /dev/null
+++ b/Help/prop_tgt/DEBUG_POSTFIX.rst
@@ -0,0 +1,7 @@
+DEBUG_POSTFIX
+-------------
+
+See target property <CONFIG>_POSTFIX.
+
+This property is a special case of the more-general <CONFIG>_POSTFIX
+property for the DEBUG configuration.
diff --git a/Help/prop_tgt/DEFINE_SYMBOL.rst b/Help/prop_tgt/DEFINE_SYMBOL.rst
new file mode 100644
index 0000000000..f47f135eaa
--- /dev/null
+++ b/Help/prop_tgt/DEFINE_SYMBOL.rst
@@ -0,0 +1,11 @@
+DEFINE_SYMBOL
+-------------
+
+Define a symbol when compiling this target's sources.
+
+DEFINE_SYMBOL sets the name of the preprocessor symbol defined when
+compiling sources in a shared library. If not set here then it is set
+to target_EXPORTS by default (with some substitutions if the target is
+not a valid C identifier). This is useful for headers to know whether
+they are being included from inside their library or outside to
+properly setup dllexport/dllimport decorations.
diff --git a/Help/prop_tgt/ENABLE_EXPORTS.rst b/Help/prop_tgt/ENABLE_EXPORTS.rst
new file mode 100644
index 0000000000..283f5a8b23
--- /dev/null
+++ b/Help/prop_tgt/ENABLE_EXPORTS.rst
@@ -0,0 +1,19 @@
+ENABLE_EXPORTS
+--------------
+
+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
+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
+ignored since the dynamic loader will automatically bind symbols when
+the module is loaded.
diff --git a/Help/prop_tgt/EXCLUDE_FROM_ALL.rst b/Help/prop_tgt/EXCLUDE_FROM_ALL.rst
new file mode 100644
index 0000000000..caa5741f85
--- /dev/null
+++ b/Help/prop_tgt/EXCLUDE_FROM_ALL.rst
@@ -0,0 +1,10 @@
+EXCLUDE_FROM_ALL
+----------------
+
+Exclude the target from the all target.
+
+A property on a target that indicates if the target is excluded from
+the default build target. If it is not, then with a Makefile for
+example typing make will cause this target to be built. The same
+concept applies to the default build of other generators. Installing
+a target with EXCLUDE_FROM_ALL set to true has undefined behavior.
diff --git a/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.rst b/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.rst
new file mode 100644
index 0000000000..19270a59d9
--- /dev/null
+++ b/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.rst
@@ -0,0 +1,8 @@
+EXCLUDE_FROM_DEFAULT_BUILD
+--------------------------
+
+Exclude target from "Build Solution".
+
+This property is only used by Visual Studio generators 7 and above.
+When set to TRUE, the target will not be built when you press "Build
+Solution".
diff --git a/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG.rst b/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG.rst
new file mode 100644
index 0000000000..655a9dee0c
--- /dev/null
+++ b/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG.rst
@@ -0,0 +1,9 @@
+EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>
+-----------------------------------
+
+Per-configuration version of target exclusion from "Build Solution".
+
+This is the configuration-specific version of
+EXCLUDE_FROM_DEFAULT_BUILD. If the generic EXCLUDE_FROM_DEFAULT_BUILD
+is also set on a target, EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG> takes
+precedence in configurations for which it has a value.
diff --git a/Help/prop_tgt/EXPORT_NAME.rst b/Help/prop_tgt/EXPORT_NAME.rst
new file mode 100644
index 0000000000..1b4247cc5b
--- /dev/null
+++ b/Help/prop_tgt/EXPORT_NAME.rst
@@ -0,0 +1,8 @@
+EXPORT_NAME
+-----------
+
+Exported name for target files.
+
+This sets the name for the IMPORTED target generated when it this
+target is is exported. If not set, the logical target name is used by
+default.
diff --git a/Help/prop_tgt/EchoString.rst b/Help/prop_tgt/EchoString.rst
new file mode 100644
index 0000000000..32ae2aa8ff
--- /dev/null
+++ b/Help/prop_tgt/EchoString.rst
@@ -0,0 +1,7 @@
+EchoString
+----------
+
+A message to be displayed when the target is built.
+
+A message to display on some generators (such as makefiles) when the
+target is built.
diff --git a/Help/prop_tgt/FOLDER.rst b/Help/prop_tgt/FOLDER.rst
new file mode 100644
index 0000000000..bfe4e8e166
--- /dev/null
+++ b/Help/prop_tgt/FOLDER.rst
@@ -0,0 +1,10 @@
+FOLDER
+------
+
+Set the folder name. Use to organize targets in an IDE.
+
+Targets with no FOLDER property will appear as top level entities in
+IDEs like Visual Studio. Targets with the same FOLDER property value
+will appear next to each other in a folder of that name. To nest
+folders, use FOLDER values such as 'GUI/Dialogs' with '/' characters
+separating folder levels.
diff --git a/Help/prop_tgt/FRAMEWORK.rst b/Help/prop_tgt/FRAMEWORK.rst
new file mode 100644
index 0000000000..9f472c025a
--- /dev/null
+++ b/Help/prop_tgt/FRAMEWORK.rst
@@ -0,0 +1,9 @@
+FRAMEWORK
+---------
+
+This target is a framework on the Mac.
+
+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
+directory structure required for a framework and will be suitable to
+be used with the -framework option
diff --git a/Help/prop_tgt/Fortran_FORMAT.rst b/Help/prop_tgt/Fortran_FORMAT.rst
new file mode 100644
index 0000000000..0a11d91caa
--- /dev/null
+++ b/Help/prop_tgt/Fortran_FORMAT.rst
@@ -0,0 +1,11 @@
+Fortran_FORMAT
+--------------
+
+Set to FIXED or FREE to indicate the Fortran source layout.
+
+This property tells CMake whether the Fortran source files in a target
+use fixed-format or free-format. CMake will pass the corresponding
+format flag to the compiler. Use the source-specific Fortran_FORMAT
+property to change the format of a specific source file. If the
+variable CMAKE_Fortran_FORMAT is set when a target is created its
+value is used to initialize this property.
diff --git a/Help/prop_tgt/Fortran_MODULE_DIRECTORY.rst b/Help/prop_tgt/Fortran_MODULE_DIRECTORY.rst
new file mode 100644
index 0000000000..9c86437644
--- /dev/null
+++ b/Help/prop_tgt/Fortran_MODULE_DIRECTORY.rst
@@ -0,0 +1,17 @@
+Fortran_MODULE_DIRECTORY
+------------------------
+
+Specify output directory for Fortran modules provided by the target.
+
+If the target contains Fortran source files that provide modules and
+the compiler supports a module output directory this specifies the
+directory in which the modules will be placed. When this property is
+not set the modules will be placed in the build directory
+corresponding to the target's source directory. If the variable
+CMAKE_Fortran_MODULE_DIRECTORY is set when a target is created its
+value is used to initialize this property.
+
+Note that some compilers will automatically search the module output
+directory for modules USEd during compilation but others will not. If
+your sources USE modules their location must be specified by
+INCLUDE_DIRECTORIES regardless of this property.
diff --git a/Help/prop_tgt/GENERATOR_FILE_NAME.rst b/Help/prop_tgt/GENERATOR_FILE_NAME.rst
new file mode 100644
index 0000000000..032b22acf4
--- /dev/null
+++ b/Help/prop_tgt/GENERATOR_FILE_NAME.rst
@@ -0,0 +1,9 @@
+GENERATOR_FILE_NAME
+-------------------
+
+Generator's file for this target.
+
+An internal property used by some generators to record the name of the
+project or dsp file associated with this target. Note that at
+configure time, this property is only set for targets created by
+include_external_msproject().
diff --git a/Help/prop_tgt/GNUtoMS.rst b/Help/prop_tgt/GNUtoMS.rst
new file mode 100644
index 0000000000..cf34da9c3e
--- /dev/null
+++ b/Help/prop_tgt/GNUtoMS.rst
@@ -0,0 +1,17 @@
+GNUtoMS
+-------
+
+Convert GNU import library (.dll.a) to MS format (.lib).
+
+When linking a shared library or executable that exports symbols using
+GNU tools on Windows (MinGW/MSYS) with Visual Studio installed convert
+the import library (.dll.a) from GNU to MS format (.lib). Both import
+libraries will be installed by install(TARGETS) and exported by
+install(EXPORT) and export() to be linked by applications with either
+GNU- or MS-compatible tools.
+
+If the variable CMAKE_GNUtoMS is set when a target is created its
+value is used to initialize this property. The variable must be set
+prior to the first command that enables a language such as project()
+or enable_language(). CMake provides the variable as an option to the
+user automatically when configuring on Windows with GNU tools.
diff --git a/Help/prop_tgt/HAS_CXX.rst b/Help/prop_tgt/HAS_CXX.rst
new file mode 100644
index 0000000000..7790932aea
--- /dev/null
+++ b/Help/prop_tgt/HAS_CXX.rst
@@ -0,0 +1,7 @@
+HAS_CXX
+-------
+
+Link the target using the C++ linker tool (obsolete).
+
+This is equivalent to setting the LINKER_LANGUAGE property to CXX.
+See that property's documentation for details.
diff --git a/Help/prop_tgt/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst b/Help/prop_tgt/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst
new file mode 100644
index 0000000000..dc738071d4
--- /dev/null
+++ b/Help/prop_tgt/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst
@@ -0,0 +1,32 @@
+IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
+----------------------------------
+
+Specify #include line transforms for dependencies in a target.
+
+This property specifies rules to transform macro-like #include lines
+during implicit dependency scanning of C and C++ source files. The
+list of rules must be semicolon-separated with each entry of the form
+"A_MACRO(%)=value-with-%" (the % must be literal). During dependency
+scanning occurrences of A_MACRO(...) on #include lines will be
+replaced by the value given with the macro argument substituted for
+'%'. For example, the entry
+
+::
+
+ MYDIR(%)=<mydir/%>
+
+will convert lines of the form
+
+::
+
+ #include MYDIR(myheader.h)
+
+to
+
+::
+
+ #include <mydir/myheader.h>
+
+allowing the dependency to be followed.
+
+This property applies to sources in the target on which it is set.
diff --git a/Help/prop_tgt/IMPORTED.rst b/Help/prop_tgt/IMPORTED.rst
new file mode 100644
index 0000000000..605c1ce6cb
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED.rst
@@ -0,0 +1,8 @@
+IMPORTED
+--------
+
+Read-only indication of whether a target is IMPORTED.
+
+The boolean value of this property is ``True`` for targets created with
+the IMPORTED option to :command:`add_executable` or :command:`add_library`.
+It is ``False`` for targets built within the project.
diff --git a/Help/prop_tgt/IMPORTED_CONFIGURATIONS.rst b/Help/prop_tgt/IMPORTED_CONFIGURATIONS.rst
new file mode 100644
index 0000000000..6de1baa235
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_CONFIGURATIONS.rst
@@ -0,0 +1,11 @@
+IMPORTED_CONFIGURATIONS
+-----------------------
+
+Configurations provided for an IMPORTED target.
+
+Set this to the list of configuration names available for an IMPORTED
+target. The names correspond to configurations defined in the project
+from which the target is imported. If the importing project uses a
+different set of configurations the names may be mapped using the
+MAP_IMPORTED_CONFIG_<CONFIG> property. Ignored for non-imported
+targets.
diff --git a/Help/prop_tgt/IMPORTED_IMPLIB.rst b/Help/prop_tgt/IMPORTED_IMPLIB.rst
new file mode 100644
index 0000000000..acf4b321f8
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_IMPLIB.rst
@@ -0,0 +1,7 @@
+IMPORTED_IMPLIB
+---------------
+
+Full path to the import library for an IMPORTED target.
+
+Set this to the location of the ".lib" part of a windows DLL. Ignored
+for non-imported targets.
diff --git a/Help/prop_tgt/IMPORTED_IMPLIB_CONFIG.rst b/Help/prop_tgt/IMPORTED_IMPLIB_CONFIG.rst
new file mode 100644
index 0000000000..b4b3f0228d
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_IMPLIB_CONFIG.rst
@@ -0,0 +1,7 @@
+IMPORTED_IMPLIB_<CONFIG>
+------------------------
+
+<CONFIG>-specific version of IMPORTED_IMPLIB property.
+
+Configuration names correspond to those provided by the project from
+which the target is imported.
diff --git a/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES.rst b/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES.rst
new file mode 100644
index 0000000000..2db2b0e58c
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES.rst
@@ -0,0 +1,14 @@
+IMPORTED_LINK_DEPENDENT_LIBRARIES
+---------------------------------
+
+Dependent shared libraries of an imported shared library.
+
+Shared libraries may be linked to other shared libraries as part of
+their implementation. On some platforms the linker searches for the
+dependent libraries of shared libraries they are including in the
+link. Set this property to the list of dependent shared libraries of
+an imported library. The list should be disjoint from the list of
+interface libraries in the INTERFACE_LINK_LIBRARIES property. On
+platforms requiring dependent shared libraries to be found at link
+time CMake uses this list to add appropriate files or paths to the
+link command line. Ignored for non-imported targets.
diff --git a/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES_CONFIG.rst b/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES_CONFIG.rst
new file mode 100644
index 0000000000..ee243c75da
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES_CONFIG.rst
@@ -0,0 +1,8 @@
+IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>
+------------------------------------------
+
+<CONFIG>-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.
+
+Configuration names correspond to those provided by the project from
+which the target is imported. If set, this property completely
+overrides the generic property for the named configuration.
diff --git a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.rst b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.rst
new file mode 100644
index 0000000000..5ca9c8b6f7
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.rst
@@ -0,0 +1,14 @@
+IMPORTED_LINK_INTERFACE_LANGUAGES
+---------------------------------
+
+Languages compiled into an IMPORTED static library.
+
+Set this to the list of languages of source files compiled to produce
+a STATIC IMPORTED library (such as "C" or "CXX"). CMake accounts for
+these languages when computing how to link a target to the imported
+library. For example, when a C executable links to an imported C++
+static library CMake chooses the C++ linker to satisfy language
+runtime dependencies of the static library.
+
+This property is ignored for targets that are not STATIC libraries.
+This property is ignored for non-imported targets.
diff --git a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES_CONFIG.rst b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES_CONFIG.rst
new file mode 100644
index 0000000000..d4a10fbddc
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES_CONFIG.rst
@@ -0,0 +1,8 @@
+IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>
+------------------------------------------
+
+<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.
+
+Configuration names correspond to those provided by the project from
+which the target is imported. If set, this property completely
+overrides the generic property for the named configuration.
diff --git a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.rst b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.rst
new file mode 100644
index 0000000000..61134a4019
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.rst
@@ -0,0 +1,16 @@
+IMPORTED_LINK_INTERFACE_LIBRARIES
+---------------------------------
+
+Transitive link interface of an IMPORTED target.
+
+Set this to the list of libraries whose interface is included when an
+IMPORTED library target is linked to another target. The libraries
+will be included on the link line for the target. Unlike the
+LINK_INTERFACE_LIBRARIES property, this property applies to all
+imported target types, including STATIC libraries. This property is
+ignored for non-imported targets.
+
+This property is ignored if the target also has a non-empty
+INTERFACE_LINK_LIBRARIES property.
+
+This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.
diff --git a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG.rst b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG.rst
new file mode 100644
index 0000000000..13b93ba98d
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG.rst
@@ -0,0 +1,13 @@
+IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>
+------------------------------------------
+
+<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.
+
+Configuration names correspond to those provided by the project from
+which the target is imported. If set, this property completely
+overrides the generic property for the named configuration.
+
+This property is ignored if the target also has a non-empty
+INTERFACE_LINK_LIBRARIES property.
+
+This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.
diff --git a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY.rst b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY.rst
new file mode 100644
index 0000000000..3a86b9985f
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY.rst
@@ -0,0 +1,6 @@
+IMPORTED_LINK_INTERFACE_MULTIPLICITY
+------------------------------------
+
+Repetition count for cycles of IMPORTED static libraries.
+
+This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.
diff --git a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY_CONFIG.rst b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY_CONFIG.rst
new file mode 100644
index 0000000000..33b9b84199
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY_CONFIG.rst
@@ -0,0 +1,7 @@
+IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>
+---------------------------------------------
+
+<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.
+
+If set, this property completely overrides the generic property for
+the named configuration.
diff --git a/Help/prop_tgt/IMPORTED_LOCATION.rst b/Help/prop_tgt/IMPORTED_LOCATION.rst
new file mode 100644
index 0000000000..8cfef7343b
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LOCATION.rst
@@ -0,0 +1,21 @@
+IMPORTED_LOCATION
+-----------------
+
+Full path to the main file on disk for an IMPORTED target.
+
+Set this to the location of an IMPORTED target file on disk. For
+executables this is the location of the executable file. For bundles
+on OS X this is the location of the executable file inside
+Contents/MacOS under the application bundle folder. For static
+libraries and modules this is the location of the library or module.
+For shared libraries on non-DLL platforms this is the location of the
+shared library. For frameworks on OS X this is the location of the
+library file symlink just inside the framework folder. For DLLs this
+is the location of the ".dll" part of the library. For UNKNOWN
+libraries this is the location of the file to be linked. Ignored for
+non-imported targets.
+
+Projects may skip IMPORTED_LOCATION if the configuration-specific
+property IMPORTED_LOCATION_<CONFIG> is set. To get the location of an
+imported target read one of the LOCATION or LOCATION_<CONFIG>
+properties.
diff --git a/Help/prop_tgt/IMPORTED_LOCATION_CONFIG.rst b/Help/prop_tgt/IMPORTED_LOCATION_CONFIG.rst
new file mode 100644
index 0000000000..f85bb19c93
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_LOCATION_CONFIG.rst
@@ -0,0 +1,7 @@
+IMPORTED_LOCATION_<CONFIG>
+--------------------------
+
+<CONFIG>-specific version of IMPORTED_LOCATION property.
+
+Configuration names correspond to those provided by the project from
+which the target is imported.
diff --git a/Help/prop_tgt/IMPORTED_NO_SONAME.rst b/Help/prop_tgt/IMPORTED_NO_SONAME.rst
new file mode 100644
index 0000000000..4a1bb447ac
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_NO_SONAME.rst
@@ -0,0 +1,9 @@
+IMPORTED_NO_SONAME
+------------------
+
+Specifies that an IMPORTED shared library target has no "soname".
+
+Set this property to true for an imported shared library file that has
+no "soname" field. CMake may adjust generated link commands for some
+platforms to prevent the linker from using the path to the library in
+place of its missing soname. Ignored for non-imported targets.
diff --git a/Help/prop_tgt/IMPORTED_NO_SONAME_CONFIG.rst b/Help/prop_tgt/IMPORTED_NO_SONAME_CONFIG.rst
new file mode 100644
index 0000000000..22d68220c8
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_NO_SONAME_CONFIG.rst
@@ -0,0 +1,7 @@
+IMPORTED_NO_SONAME_<CONFIG>
+---------------------------
+
+<CONFIG>-specific version of IMPORTED_NO_SONAME property.
+
+Configuration names correspond to those provided by the project from
+which the target is imported.
diff --git a/Help/prop_tgt/IMPORTED_SONAME.rst b/Help/prop_tgt/IMPORTED_SONAME.rst
new file mode 100644
index 0000000000..d80907e3e8
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_SONAME.rst
@@ -0,0 +1,8 @@
+IMPORTED_SONAME
+---------------
+
+The "soname" of an IMPORTED target of shared library type.
+
+Set this to the "soname" embedded in an imported shared library. This
+is meaningful only on platforms supporting the feature. Ignored for
+non-imported targets.
diff --git a/Help/prop_tgt/IMPORTED_SONAME_CONFIG.rst b/Help/prop_tgt/IMPORTED_SONAME_CONFIG.rst
new file mode 100644
index 0000000000..6ec9af3f83
--- /dev/null
+++ b/Help/prop_tgt/IMPORTED_SONAME_CONFIG.rst
@@ -0,0 +1,7 @@
+IMPORTED_SONAME_<CONFIG>
+------------------------
+
+<CONFIG>-specific version of IMPORTED_SONAME property.
+
+Configuration names correspond to those provided by the project from
+which the target is imported.
diff --git a/Help/prop_tgt/IMPORT_PREFIX.rst b/Help/prop_tgt/IMPORT_PREFIX.rst
new file mode 100644
index 0000000000..deede97880
--- /dev/null
+++ b/Help/prop_tgt/IMPORT_PREFIX.rst
@@ -0,0 +1,9 @@
+IMPORT_PREFIX
+-------------
+
+What comes before the import library name.
+
+Similar to the target property PREFIX, but used for import libraries
+(typically corresponding to a DLL) instead of regular libraries. A
+target property that can be set to override the prefix (such as "lib")
+on an import library name.
diff --git a/Help/prop_tgt/IMPORT_SUFFIX.rst b/Help/prop_tgt/IMPORT_SUFFIX.rst
new file mode 100644
index 0000000000..bd01250378
--- /dev/null
+++ b/Help/prop_tgt/IMPORT_SUFFIX.rst
@@ -0,0 +1,9 @@
+IMPORT_SUFFIX
+-------------
+
+What comes after the import library name.
+
+Similar to the target property SUFFIX, but used for import libraries
+(typically corresponding to a DLL) instead of regular libraries. A
+target property that can be set to override the suffix (such as
+".lib") on an import library name.
diff --git a/Help/prop_tgt/INCLUDE_DIRECTORIES.rst b/Help/prop_tgt/INCLUDE_DIRECTORIES.rst
new file mode 100644
index 0000000000..8b40d9c346
--- /dev/null
+++ b/Help/prop_tgt/INCLUDE_DIRECTORIES.rst
@@ -0,0 +1,24 @@
+INCLUDE_DIRECTORIES
+-------------------
+
+List of preprocessor include file search directories.
+
+This property specifies the list of directories given so far to the
+:command:`target_include_directories` command. In addition to accepting
+values from that command, values may be set directly on any
+target using the :command:`set_property` command. A target gets its
+initial value for this property from the value of the
+:prop_dir:`INCLUDE_DIRECTORIES` directory property. Both directory and
+target property values are adjusted by calls to the
+:command:`include_directories` command.
+
+The value of this property is used by the generators to set the include
+paths for the compiler.
+
+Relative paths should not be added to this property directly. Use one of
+the commands above instead to handle relative paths.
+
+Contents of ``INCLUDE_DIRECTORIES`` 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/Help/prop_tgt/INSTALL_NAME_DIR.rst b/Help/prop_tgt/INSTALL_NAME_DIR.rst
new file mode 100644
index 0000000000..a67ec15849
--- /dev/null
+++ b/Help/prop_tgt/INSTALL_NAME_DIR.rst
@@ -0,0 +1,8 @@
+INSTALL_NAME_DIR
+----------------
+
+Mac OSX directory name for installed targets.
+
+INSTALL_NAME_DIR is a string specifying the directory portion of the
+"install_name" field of shared libraries on Mac OSX to use in the
+installed targets.
diff --git a/Help/prop_tgt/INSTALL_RPATH.rst b/Help/prop_tgt/INSTALL_RPATH.rst
new file mode 100644
index 0000000000..6206b6889b
--- /dev/null
+++ b/Help/prop_tgt/INSTALL_RPATH.rst
@@ -0,0 +1,9 @@
+INSTALL_RPATH
+-------------
+
+The rpath to use for installed targets.
+
+A semicolon-separated list specifying the rpath to use in installed
+targets (for platforms that support it). This property is initialized
+by the value of the variable CMAKE_INSTALL_RPATH if it is set when a
+target is created.
diff --git a/Help/prop_tgt/INSTALL_RPATH_USE_LINK_PATH.rst b/Help/prop_tgt/INSTALL_RPATH_USE_LINK_PATH.rst
new file mode 100644
index 0000000000..f0006f85b3
--- /dev/null
+++ b/Help/prop_tgt/INSTALL_RPATH_USE_LINK_PATH.rst
@@ -0,0 +1,10 @@
+INSTALL_RPATH_USE_LINK_PATH
+---------------------------
+
+Add paths to linker search and installed rpath.
+
+INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will
+append directories in the linker search path and outside the project
+to the INSTALL_RPATH. This property is initialized by the value of
+the variable CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a
+target is created.
diff --git a/Help/prop_tgt/INTERFACE_AUTOUIC_OPTIONS.rst b/Help/prop_tgt/INTERFACE_AUTOUIC_OPTIONS.rst
new file mode 100644
index 0000000000..e97d293180
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_AUTOUIC_OPTIONS.rst
@@ -0,0 +1,14 @@
+INTERFACE_AUTOUIC_OPTIONS
+-------------------------
+
+List of interface options to pass to uic.
+
+Targets may populate this property to publish the options
+required to use when invoking ``uic``. Consuming targets can add entries to their
+own :prop_tgt:`AUTOUIC_OPTIONS` property such as
+``$<TARGET_PROPERTY:foo,INTERFACE_AUTOUIC_OPTIONS>`` to use the uic options
+specified in the interface of ``foo``. This is done automatically by
+the :command:`target_link_libraries` command.
+
+This property supports generator expressions. See the
+:manual:`cmake-generator-expressions(7)` manual for available expressions.
diff --git a/Help/prop_tgt/INTERFACE_COMPILE_DEFINITIONS.rst b/Help/prop_tgt/INTERFACE_COMPILE_DEFINITIONS.rst
new file mode 100644
index 0000000000..910b661fed
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_COMPILE_DEFINITIONS.rst
@@ -0,0 +1,15 @@
+INTERFACE_COMPILE_DEFINITIONS
+-----------------------------
+
+List of public compile definitions for a library.
+
+Targets may populate this property to publish the compile definitions
+required to compile against the headers for the target. Consuming
+targets can add entries to their own :prop_tgt:`COMPILE_DEFINITIONS`
+property such as ``$<TARGET_PROPERTY:foo,INTERFACE_COMPILE_DEFINITIONS>``
+to use the compile definitions specified in the interface of ``foo``.
+
+Contents of ``INTERFACE_COMPILE_DEFINITIONS`` 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/Help/prop_tgt/INTERFACE_COMPILE_FEATURES.rst b/Help/prop_tgt/INTERFACE_COMPILE_FEATURES.rst
new file mode 100644
index 0000000000..7abdecbdbd
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_COMPILE_FEATURES.rst
@@ -0,0 +1,16 @@
+INTERFACE_COMPILE_FEATURES
+--------------------------
+
+List of public compile requirements for a library.
+
+Targets may populate this property to publish the compiler features
+required to compile against the headers for the target. Consuming
+targets can add entries to their own :prop_tgt:`COMPILE_FEATURES`
+property such as ``$<TARGET_PROPERTY:foo,INTERFACE_COMPILE_FEATURES>``
+to require the features specified in the interface of ``foo``.
+
+Contents of ``INTERFACE_COMPILE_FEATURES`` may use "generator expressions"
+with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
+manual for available expressions. See the
+:manual:`cmake-compile-features(7)` manual for information on compile
+features.
diff --git a/Help/prop_tgt/INTERFACE_COMPILE_OPTIONS.rst b/Help/prop_tgt/INTERFACE_COMPILE_OPTIONS.rst
new file mode 100644
index 0000000000..d0a38d6a26
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_COMPILE_OPTIONS.rst
@@ -0,0 +1,15 @@
+INTERFACE_COMPILE_OPTIONS
+-------------------------
+
+List of interface options to pass to the compiler.
+
+Targets may populate this property to publish the compile options
+required to compile against the headers for the target. Consuming
+targets can add entries to their own :prop_tgt:`COMPILE_OPTIONS` property
+such as ``$<TARGET_PROPERTY:foo,INTERFACE_COMPILE_OPTIONS>`` to use the
+compile options specified in the interface of ``foo``.
+
+Contents of ``INTERFACE_COMPILE_OPTIONS`` 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/Help/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.rst b/Help/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.rst
new file mode 100644
index 0000000000..899e821f7c
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.rst
@@ -0,0 +1,33 @@
+INTERFACE_INCLUDE_DIRECTORIES
+-----------------------------
+
+List of public include directories for a library.
+
+The :command:`target_include_directories` command populates this property
+with values given to the ``PUBLIC`` and ``INTERFACE`` keywords. Projects
+may also get and set the property directly.
+
+Targets may populate this property to publish the include directories
+required to compile against the headers for the target. Consuming
+targets can add entries to their own :prop_tgt:`INCLUDE_DIRECTORIES`
+property such as ``$<TARGET_PROPERTY:foo,INTERFACE_INCLUDE_DIRECTORIES>``
+to use the include directories specified in the interface of ``foo``.
+
+Contents of ``INTERFACE_INCLUDE_DIRECTORIES`` 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.
+
+Include directories usage requirements commonly differ between the build-tree
+and the install-tree. The ``BUILD_INTERFACE`` and ``INSTALL_INTERFACE``
+generator expressions can be used to describe separate usage requirements
+based on the usage location. Relative paths are allowed within the
+``INSTALL_INTERFACE`` expression and are interpreted relative to the
+installation prefix. For example:
+
+.. code-block:: cmake
+
+ set_property(TARGET mylib APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/mylib>
+ $<INSTALL_INTERFACE:include/mylib> # <prefix>/include/mylib
+ )
diff --git a/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst b/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst
new file mode 100644
index 0000000000..8e4843b481
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst
@@ -0,0 +1,17 @@
+INTERFACE_LINK_LIBRARIES
+------------------------
+
+List public interface libraries for a library.
+
+This property contains the list of transitive link dependencies. When
+the target is linked into another target the libraries listed (and
+recursively their link interface libraries) will be provided to the
+other target also. This property is overridden by the
+:prop_tgt:`LINK_INTERFACE_LIBRARIES` or
+:prop_tgt:`LINK_INTERFACE_LIBRARIES_<CONFIG>` property if policy
+:policy:`CMP0022` is ``OLD`` or unset.
+
+Contents of ``INTERFACE_LINK_LIBRARIES`` 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/Help/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE.rst b/Help/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE.rst
new file mode 100644
index 0000000000..ea700dfe98
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE.rst
@@ -0,0 +1,16 @@
+INTERFACE_POSITION_INDEPENDENT_CODE
+-----------------------------------
+
+Whether consumers need to create a position-independent target
+
+The ``INTERFACE_POSITION_INDEPENDENT_CODE`` property informs consumers of
+this target whether they must set their
+:prop_tgt:`POSITION_INDEPENDENT_CODE` property to ``ON``. If this
+property is set to ``ON``, then the :prop_tgt:`POSITION_INDEPENDENT_CODE`
+property on all consumers will be set to ``ON``. Similarly, if this
+property is set to ``OFF``, then the :prop_tgt:`POSITION_INDEPENDENT_CODE`
+property on all consumers will be set to ``OFF``. If this property is
+undefined, then consumers will determine their
+:prop_tgt:`POSITION_INDEPENDENT_CODE` property by other means. Consumers
+must ensure that the targets that they link to have a consistent
+requirement for their ``INTERFACE_POSITION_INDEPENDENT_CODE`` property.
diff --git a/Help/prop_tgt/INTERFACE_SOURCES.rst b/Help/prop_tgt/INTERFACE_SOURCES.rst
new file mode 100644
index 0000000000..fb28231a31
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_SOURCES.rst
@@ -0,0 +1,15 @@
+INTERFACE_SOURCES
+-----------------
+
+List of interface sources to pass to the compiler.
+
+Targets may populate this property to publish the sources
+for consuming targets to compile. Consuming
+targets can add entries to their own :prop_tgt:`SOURCES` property
+such as ``$<TARGET_PROPERTY:foo,INTERFACE_SOURCES>`` to use the
+sources specified in the interface of ``foo``.
+
+Contents of ``INTERFACE_SOURCES`` 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/Help/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.rst b/Help/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.rst
new file mode 100644
index 0000000000..9e603ee5ac
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.rst
@@ -0,0 +1,15 @@
+INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
+------------------------------------
+
+List of public system include directories for a library.
+
+Targets may populate this property to publish the include directories
+which contain system headers, and therefore should not result in
+compiler warnings. Consuming targets will then mark the same include
+directories as system headers.
+
+Contents of ``INTERFACE_SYSTEM_INCLUDE_DIRECTORIES`` 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/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.rst b/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.rst
new file mode 100644
index 0000000000..effa3b01f8
--- /dev/null
+++ b/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.rst
@@ -0,0 +1,7 @@
+INTERPROCEDURAL_OPTIMIZATION
+----------------------------
+
+Enable interprocedural optimization for a target.
+
+If set to true, enables interprocedural optimizations if they are
+known to be supported by the compiler.
diff --git a/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst b/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
new file mode 100644
index 0000000000..492fee0789
--- /dev/null
+++ b/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
@@ -0,0 +1,8 @@
+INTERPROCEDURAL_OPTIMIZATION_<CONFIG>
+-------------------------------------
+
+Per-configuration interprocedural optimization for a target.
+
+This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION.
+If set, this property overrides the generic property for the named
+configuration.
diff --git a/Help/prop_tgt/JOB_POOL_COMPILE.rst b/Help/prop_tgt/JOB_POOL_COMPILE.rst
new file mode 100644
index 0000000000..5d8e940387
--- /dev/null
+++ b/Help/prop_tgt/JOB_POOL_COMPILE.rst
@@ -0,0 +1,17 @@
+JOB_POOL_COMPILE
+----------------
+
+Ninja only: Pool used for compiling.
+
+The number of parallel compile processes could be limited by defining
+pools with the global :prop_gbl:`JOB_POOLS`
+property and then specifying here the pool name.
+
+For instance:
+
+.. code-block:: cmake
+
+ set_property(TARGET myexe PROPERTY JOB_POOL_COMPILE ten_jobs)
+
+This property is initialized by the value of
+:variable:`CMAKE_JOB_POOL_COMPILE`.
diff --git a/Help/prop_tgt/JOB_POOL_LINK.rst b/Help/prop_tgt/JOB_POOL_LINK.rst
new file mode 100644
index 0000000000..716f53f71a
--- /dev/null
+++ b/Help/prop_tgt/JOB_POOL_LINK.rst
@@ -0,0 +1,16 @@
+JOB_POOL_LINK
+-------------
+
+Ninja only: Pool used for linking.
+
+The number of parallel link processes could be limited by defining
+pools with the global :prop_gbl:`JOB_POOLS`
+property and then specifing here the pool name.
+
+For instance:
+
+.. code-block:: cmake
+
+ set_property(TARGET myexe PROPERTY JOB_POOL_LINK two_jobs)
+
+This property is initialized by the value of :variable:`CMAKE_JOB_POOL_LINK`.
diff --git a/Help/prop_tgt/LABELS.rst b/Help/prop_tgt/LABELS.rst
new file mode 100644
index 0000000000..5e464696dc
--- /dev/null
+++ b/Help/prop_tgt/LABELS.rst
@@ -0,0 +1,6 @@
+LABELS
+------
+
+Specify a list of text labels associated with a target.
+
+Target label semantics are currently unspecified.
diff --git a/Help/prop_tgt/LANG_VISIBILITY_PRESET.rst b/Help/prop_tgt/LANG_VISIBILITY_PRESET.rst
new file mode 100644
index 0000000000..d4bde179b7
--- /dev/null
+++ b/Help/prop_tgt/LANG_VISIBILITY_PRESET.rst
@@ -0,0 +1,10 @@
+<LANG>_VISIBILITY_PRESET
+------------------------
+
+Value for symbol visibility compile flags
+
+The <LANG>_VISIBILITY_PRESET property determines the value passed in a
+visibility related compile option, such as -fvisibility= for <LANG>.
+This property only has an affect for libraries and executables with
+exports. This property is initialized by the value of the variable
+CMAKE_<LANG>_VISIBILITY_PRESET if it is set when a target is created.
diff --git a/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.rst b/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..e1d3a82ad8
--- /dev/null
+++ b/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,7 @@
+LIBRARY_OUTPUT_DIRECTORY
+------------------------
+
+.. |XXX| replace:: LIBRARY
+.. |xxx| replace:: library
+.. |CMAKE_XXX_OUTPUT_DIRECTORY| replace:: CMAKE_LIBRARY_OUTPUT_DIRECTORY
+.. include:: XXX_OUTPUT_DIRECTORY.txt
diff --git a/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG.rst b/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG.rst
new file mode 100644
index 0000000000..2a38373054
--- /dev/null
+++ b/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG.rst
@@ -0,0 +1,11 @@
+LIBRARY_OUTPUT_DIRECTORY_<CONFIG>
+---------------------------------
+
+Per-configuration output directory for LIBRARY target files.
+
+This is a per-configuration version of LIBRARY_OUTPUT_DIRECTORY, but
+multi-configuration generators (VS, Xcode) do NOT append a
+per-configuration subdirectory to the specified directory. This
+property is initialized by the value of the variable
+CMAKE_LIBRARY_OUTPUT_DIRECTORY_<CONFIG> if it is set when a target is
+created.
diff --git a/Help/prop_tgt/LIBRARY_OUTPUT_NAME.rst b/Help/prop_tgt/LIBRARY_OUTPUT_NAME.rst
new file mode 100644
index 0000000000..9e9d4018c1
--- /dev/null
+++ b/Help/prop_tgt/LIBRARY_OUTPUT_NAME.rst
@@ -0,0 +1,6 @@
+LIBRARY_OUTPUT_NAME
+-------------------
+
+.. |XXX| replace:: LIBRARY
+.. |xxx| replace:: library
+.. include:: XXX_OUTPUT_NAME.txt
diff --git a/Help/prop_tgt/LIBRARY_OUTPUT_NAME_CONFIG.rst b/Help/prop_tgt/LIBRARY_OUTPUT_NAME_CONFIG.rst
new file mode 100644
index 0000000000..785d1b2dc3
--- /dev/null
+++ b/Help/prop_tgt/LIBRARY_OUTPUT_NAME_CONFIG.rst
@@ -0,0 +1,6 @@
+LIBRARY_OUTPUT_NAME_<CONFIG>
+----------------------------
+
+Per-configuration output name for LIBRARY target files.
+
+This is the configuration-specific version of LIBRARY_OUTPUT_NAME.
diff --git a/Help/prop_tgt/LINKER_LANGUAGE.rst b/Help/prop_tgt/LINKER_LANGUAGE.rst
new file mode 100644
index 0000000000..b1ca86710e
--- /dev/null
+++ b/Help/prop_tgt/LINKER_LANGUAGE.rst
@@ -0,0 +1,14 @@
+LINKER_LANGUAGE
+---------------
+
+Specifies language whose compiler will invoke the linker.
+
+For executables, shared libraries, and modules, this sets the language
+whose compiler is used to link the target (such as "C" or "CXX"). A
+typical value for an executable is the language of the source file
+providing the program entry point (main). If not set, the language
+with the highest linker preference value is the default. See
+documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables.
+
+If this property is not set by the user, it will be calculated at
+generate-time by CMake.
diff --git a/Help/prop_tgt/LINK_DEPENDS.rst b/Help/prop_tgt/LINK_DEPENDS.rst
new file mode 100644
index 0000000000..5576b85fa6
--- /dev/null
+++ b/Help/prop_tgt/LINK_DEPENDS.rst
@@ -0,0 +1,12 @@
+LINK_DEPENDS
+------------
+
+Additional files on which a target binary depends for linking.
+
+Specifies a semicolon-separated list of full-paths to files on which
+the link rule for this target depends. The target binary will be
+linked if any of the named files is newer than it.
+
+This property is ignored by non-Makefile generators. It is intended
+to specify dependencies on "linker scripts" for custom Makefile link
+rules.
diff --git a/Help/prop_tgt/LINK_DEPENDS_NO_SHARED.rst b/Help/prop_tgt/LINK_DEPENDS_NO_SHARED.rst
new file mode 100644
index 0000000000..5c6778d245
--- /dev/null
+++ b/Help/prop_tgt/LINK_DEPENDS_NO_SHARED.rst
@@ -0,0 +1,14 @@
+LINK_DEPENDS_NO_SHARED
+----------------------
+
+Do not depend on linked shared library files.
+
+Set this property to true to tell CMake generators not to add
+file-level dependencies on the shared library files linked by this
+target. Modification to the shared libraries will not be sufficient
+to re-link this target. Logical target-level dependencies will not be
+affected so the linked shared libraries will still be brought up to
+date before this target is built.
+
+This property is initialized by the value of the variable
+CMAKE_LINK_DEPENDS_NO_SHARED if it is set when a target is created.
diff --git a/Help/prop_tgt/LINK_FLAGS.rst b/Help/prop_tgt/LINK_FLAGS.rst
new file mode 100644
index 0000000000..409d00a291
--- /dev/null
+++ b/Help/prop_tgt/LINK_FLAGS.rst
@@ -0,0 +1,8 @@
+LINK_FLAGS
+----------
+
+Additional flags to use when linking this target.
+
+The LINK_FLAGS property can be used to add extra flags to the link
+step of a target. LINK_FLAGS_<CONFIG> will add to the configuration
+<CONFIG>, for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO.
diff --git a/Help/prop_tgt/LINK_FLAGS_CONFIG.rst b/Help/prop_tgt/LINK_FLAGS_CONFIG.rst
new file mode 100644
index 0000000000..ba7adc84f6
--- /dev/null
+++ b/Help/prop_tgt/LINK_FLAGS_CONFIG.rst
@@ -0,0 +1,6 @@
+LINK_FLAGS_<CONFIG>
+-------------------
+
+Per-configuration linker flags for a target.
+
+This is the configuration-specific version of LINK_FLAGS.
diff --git a/Help/prop_tgt/LINK_INTERFACE_LIBRARIES.rst b/Help/prop_tgt/LINK_INTERFACE_LIBRARIES.rst
new file mode 100644
index 0000000000..435e25e2fb
--- /dev/null
+++ b/Help/prop_tgt/LINK_INTERFACE_LIBRARIES.rst
@@ -0,0 +1,22 @@
+LINK_INTERFACE_LIBRARIES
+------------------------
+
+List public interface libraries for a shared library or executable.
+
+By default linking to a shared library target transitively links to
+targets with which the library itself was linked. For an executable
+with exports (see the ENABLE_EXPORTS property) no default transitive
+link dependencies are used. This property replaces the default
+transitive link dependencies with an explicit list. When the target
+is linked into another target the libraries listed (and recursively
+their link interface libraries) will be provided to the other target
+also. If the list is empty then no transitive link dependencies will
+be incorporated when this target is linked into another target even if
+the default set is non-empty. This property is initialized by the
+value of the variable CMAKE_LINK_INTERFACE_LIBRARIES if it is set when
+a target is created. This property is ignored for STATIC libraries.
+
+This property is overridden by the INTERFACE_LINK_LIBRARIES property if
+policy CMP0022 is NEW.
+
+This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.
diff --git a/Help/prop_tgt/LINK_INTERFACE_LIBRARIES_CONFIG.rst b/Help/prop_tgt/LINK_INTERFACE_LIBRARIES_CONFIG.rst
new file mode 100644
index 0000000000..08bd6501b3
--- /dev/null
+++ b/Help/prop_tgt/LINK_INTERFACE_LIBRARIES_CONFIG.rst
@@ -0,0 +1,13 @@
+LINK_INTERFACE_LIBRARIES_<CONFIG>
+---------------------------------
+
+Per-configuration list of public interface libraries for a target.
+
+This is the configuration-specific version of
+LINK_INTERFACE_LIBRARIES. If set, this property completely overrides
+the generic property for the named configuration.
+
+This property is overridden by the INTERFACE_LINK_LIBRARIES property if
+policy CMP0022 is NEW.
+
+This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.
diff --git a/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY.rst b/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY.rst
new file mode 100644
index 0000000000..4e26388a93
--- /dev/null
+++ b/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY.rst
@@ -0,0 +1,12 @@
+LINK_INTERFACE_MULTIPLICITY
+---------------------------
+
+Repetition count for STATIC libraries with cyclic dependencies.
+
+When linking to a STATIC library target with cyclic dependencies the
+linker may need to scan more than once through the archives in the
+strongly connected component of the dependency graph. CMake by
+default constructs the link line so that the linker will scan through
+the component at least twice. This property specifies the minimum
+number of scans if it is larger than the default. CMake uses the
+largest value specified by any target in a component.
diff --git a/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG.rst b/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG.rst
new file mode 100644
index 0000000000..5ea4a45cf6
--- /dev/null
+++ b/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG.rst
@@ -0,0 +1,8 @@
+LINK_INTERFACE_MULTIPLICITY_<CONFIG>
+------------------------------------
+
+Per-configuration repetition count for cycles of STATIC libraries.
+
+This is the configuration-specific version of
+LINK_INTERFACE_MULTIPLICITY. If set, this property completely
+overrides the generic property for the named configuration.
diff --git a/Help/prop_tgt/LINK_LIBRARIES.rst b/Help/prop_tgt/LINK_LIBRARIES.rst
new file mode 100644
index 0000000000..aa4b9f55f4
--- /dev/null
+++ b/Help/prop_tgt/LINK_LIBRARIES.rst
@@ -0,0 +1,17 @@
+LINK_LIBRARIES
+--------------
+
+List of direct link dependencies.
+
+This property specifies the list of libraries or targets which will be
+used for linking. In addition to accepting values from the
+:command:`target_link_libraries` command, values may be set directly on
+any target using the :command:`set_property` command.
+
+The value of this property is used by the generators to set the link
+libraries for the compiler.
+
+Contents of ``LINK_LIBRARIES`` 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/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst b/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst
new file mode 100644
index 0000000000..fe105bd6c4
--- /dev/null
+++ b/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst
@@ -0,0 +1,14 @@
+LINK_SEARCH_END_STATIC
+----------------------
+
+End a link line such that static system libraries are used.
+
+Some linkers support switches such as -Bstatic and -Bdynamic to
+determine whether to use static or shared libraries for -lXXX options.
+CMake uses these options to set the link type for libraries whose full
+paths are not known or (in some cases) are in implicit link
+directories for the platform. By default CMake adds an option at the
+end of the library list (if necessary) to set the linker search type
+back to its starting type. This property switches the final linker
+search type to -Bstatic regardless of how it started. See also
+LINK_SEARCH_START_STATIC.
diff --git a/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst b/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst
new file mode 100644
index 0000000000..ca899feaa0
--- /dev/null
+++ b/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst
@@ -0,0 +1,14 @@
+LINK_SEARCH_START_STATIC
+------------------------
+
+Assume the linker looks for static libraries by default.
+
+Some linkers support switches such as -Bstatic and -Bdynamic to
+determine whether to use static or shared libraries for -lXXX options.
+CMake uses these options to set the link type for libraries whose full
+paths are not known or (in some cases) are in implicit link
+directories for the platform. By default the linker search type is
+assumed to be -Bdynamic at the beginning of the library list. This
+property switches the assumption to -Bstatic. It is intended for use
+when linking an executable statically (e.g. with the GNU -static
+option). See also LINK_SEARCH_END_STATIC.
diff --git a/Help/prop_tgt/LOCATION.rst b/Help/prop_tgt/LOCATION.rst
new file mode 100644
index 0000000000..16d5696e59
--- /dev/null
+++ b/Help/prop_tgt/LOCATION.rst
@@ -0,0 +1,27 @@
+LOCATION
+--------
+
+Read-only location of a target on disk.
+
+For an imported target, this read-only property returns the value of
+the LOCATION_<CONFIG> property for an unspecified configuration
+<CONFIG> provided by the target.
+
+For a non-imported target, this property is provided for compatibility
+with CMake 2.4 and below. It was meant to get the location of an
+executable target's output file for use in add_custom_command. The
+path may contain a build-system-specific portion that is replaced at
+build time with the configuration getting built (such as
+"$(ConfigurationName)" in VS). In CMake 2.6 and above
+add_custom_command automatically recognizes a target name in its
+COMMAND and DEPENDS options and computes the target location. In
+CMake 2.8.4 and above add_custom_command recognizes generator
+expressions to refer to target locations anywhere in the command.
+Therefore this property is not needed for creating custom commands.
+
+Do not set properties that affect the location of a target after
+reading this property. These include properties whose names match
+"(RUNTIME|LIBRARY|ARCHIVE)_OUTPUT_(NAME|DIRECTORY)(_<CONFIG>)?",
+``(IMPLIB_)?(PREFIX|SUFFIX)``, or "LINKER_LANGUAGE". Failure to follow
+this rule is not diagnosed and leaves the location of the target
+undefined.
diff --git a/Help/prop_tgt/LOCATION_CONFIG.rst b/Help/prop_tgt/LOCATION_CONFIG.rst
new file mode 100644
index 0000000000..ac6bdb7867
--- /dev/null
+++ b/Help/prop_tgt/LOCATION_CONFIG.rst
@@ -0,0 +1,20 @@
+LOCATION_<CONFIG>
+-----------------
+
+Read-only property providing a target location on disk.
+
+A read-only property that indicates where a target's main file is
+located on disk for the configuration <CONFIG>. The property is
+defined only for library and executable targets. An imported target
+may provide a set of configurations different from that of the
+importing project. By default CMake looks for an exact-match but
+otherwise uses an arbitrary available configuration. Use the
+MAP_IMPORTED_CONFIG_<CONFIG> property to map imported configurations
+explicitly.
+
+Do not set properties that affect the location of a target after
+reading this property. These include properties whose names match
+"(RUNTIME|LIBRARY|ARCHIVE)_OUTPUT_(NAME|DIRECTORY)(_<CONFIG>)?",
+``(IMPLIB_)?(PREFIX|SUFFIX)``, or "LINKER_LANGUAGE". Failure to follow
+this rule is not diagnosed and leaves the location of the target
+undefined.
diff --git a/Help/prop_tgt/MACOSX_BUNDLE.rst b/Help/prop_tgt/MACOSX_BUNDLE.rst
new file mode 100644
index 0000000000..ff21e61473
--- /dev/null
+++ b/Help/prop_tgt/MACOSX_BUNDLE.rst
@@ -0,0 +1,12 @@
+MACOSX_BUNDLE
+-------------
+
+Build an executable as an application bundle on Mac OS X.
+
+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.
diff --git a/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst b/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst
new file mode 100644
index 0000000000..097cce1869
--- /dev/null
+++ b/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst
@@ -0,0 +1,29 @@
+MACOSX_BUNDLE_INFO_PLIST
+------------------------
+
+Specify a custom Info.plist template for a Mac OS X App Bundle.
+
+An executable target with MACOSX_BUNDLE enabled will be built as an
+application bundle on Mac OS X. By default its Info.plist file is
+created by configuring a template called MacOSXBundleInfo.plist.in
+located in the CMAKE_MODULE_PATH. This property specifies an
+alternative template file name which may be a full path.
+
+The following target properties may be set to specify content to be
+configured into the file:
+
+::
+
+ MACOSX_BUNDLE_INFO_STRING
+ MACOSX_BUNDLE_ICON_FILE
+ MACOSX_BUNDLE_GUI_IDENTIFIER
+ MACOSX_BUNDLE_LONG_VERSION_STRING
+ MACOSX_BUNDLE_BUNDLE_NAME
+ MACOSX_BUNDLE_SHORT_VERSION_STRING
+ MACOSX_BUNDLE_BUNDLE_VERSION
+ MACOSX_BUNDLE_COPYRIGHT
+
+CMake variables of the same name may be set to affect all targets in a
+directory that do not have each specific property set. If a custom
+Info.plist is specified by this property it may of course hard-code
+all the settings instead of using the target properties.
diff --git a/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst b/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst
new file mode 100644
index 0000000000..729d929022
--- /dev/null
+++ b/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst
@@ -0,0 +1,25 @@
+MACOSX_FRAMEWORK_INFO_PLIST
+---------------------------
+
+Specify a custom Info.plist template for a Mac OS X Framework.
+
+A library target with FRAMEWORK enabled will be built as a framework
+on Mac OS X. By default its Info.plist file is created by configuring
+a template called MacOSXFrameworkInfo.plist.in located in the
+CMAKE_MODULE_PATH. This property specifies an alternative template
+file name which may be a full path.
+
+The following target properties may be set to specify content to be
+configured into the file:
+
+::
+
+ MACOSX_FRAMEWORK_ICON_FILE
+ MACOSX_FRAMEWORK_IDENTIFIER
+ MACOSX_FRAMEWORK_SHORT_VERSION_STRING
+ MACOSX_FRAMEWORK_BUNDLE_VERSION
+
+CMake variables of the same name may be set to affect all targets in a
+directory that do not have each specific property set. If a custom
+Info.plist is specified by this property it may of course hard-code
+all the settings instead of using the target properties.
diff --git a/Help/prop_tgt/MACOSX_RPATH.rst b/Help/prop_tgt/MACOSX_RPATH.rst
new file mode 100644
index 0000000000..d3934bae28
--- /dev/null
+++ b/Help/prop_tgt/MACOSX_RPATH.rst
@@ -0,0 +1,18 @@
+MACOSX_RPATH
+------------
+
+Whether to use rpaths on Mac OS X.
+
+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
+more flexible and powerful alternative to ``@executable_path`` and
+``@loader_path``.
diff --git a/Help/prop_tgt/MAP_IMPORTED_CONFIG_CONFIG.rst b/Help/prop_tgt/MAP_IMPORTED_CONFIG_CONFIG.rst
new file mode 100644
index 0000000000..09ff0cee65
--- /dev/null
+++ b/Help/prop_tgt/MAP_IMPORTED_CONFIG_CONFIG.rst
@@ -0,0 +1,19 @@
+MAP_IMPORTED_CONFIG_<CONFIG>
+----------------------------
+
+Map from project configuration to IMPORTED target's configuration.
+
+Set this to the list of configurations of an imported target that may
+be used for the current project's <CONFIG> configuration. Targets
+imported from another project may not provide the same set of
+configuration names available in the current project. Setting this
+property tells CMake what imported configurations are suitable for use
+when building the <CONFIG> configuration. The first configuration in
+the list found to be provided by the imported target is selected. If
+this property is set and no matching configurations are available,
+then the imported target is considered to be not found. This property
+is ignored for non-imported targets.
+
+This property is initialized by the value of the variable
+CMAKE_MAP_IMPORTED_CONFIG_<CONFIG> if it is set when a target is
+created.
diff --git a/Help/prop_tgt/NAME.rst b/Help/prop_tgt/NAME.rst
new file mode 100644
index 0000000000..ddd84f23c5
--- /dev/null
+++ b/Help/prop_tgt/NAME.rst
@@ -0,0 +1,6 @@
+NAME
+----
+
+Logical name for the target.
+
+Read-only logical name for the target as used by CMake.
diff --git a/Help/prop_tgt/NO_SONAME.rst b/Help/prop_tgt/NO_SONAME.rst
new file mode 100644
index 0000000000..fc668b588e
--- /dev/null
+++ b/Help/prop_tgt/NO_SONAME.rst
@@ -0,0 +1,14 @@
+NO_SONAME
+---------
+
+Whether to set "soname" when linking a shared library or module.
+
+Enable this boolean property if a generated shared library or module
+should not have "soname" set. Default is to set "soname" on all
+shared libraries and modules as long as the platform supports it.
+Generally, use this property only for leaf private libraries or
+plugins. If you use it on normal shared libraries which other targets
+link against, on some platforms a linker will insert a full path to
+the library (as specified at link time) into the dynamic section of
+the dependent binary. Therefore, once installed, dynamic loader may
+eventually fail to locate the library for the binary.
diff --git a/Help/prop_tgt/NO_SYSTEM_FROM_IMPORTED.rst b/Help/prop_tgt/NO_SYSTEM_FROM_IMPORTED.rst
new file mode 100644
index 0000000000..070dd3018b
--- /dev/null
+++ b/Help/prop_tgt/NO_SYSTEM_FROM_IMPORTED.rst
@@ -0,0 +1,11 @@
+NO_SYSTEM_FROM_IMPORTED
+-----------------------
+
+Do not treat includes from IMPORTED target interfaces as SYSTEM.
+
+The contents of the INTERFACE_INCLUDE_DIRECTORIES of IMPORTED targets
+are treated as SYSTEM includes by default. If this property is
+enabled, the contents of the INTERFACE_INCLUDE_DIRECTORIES of IMPORTED
+targets are not treated as system includes. This property is
+initialized by the value of the variable CMAKE_NO_SYSTEM_FROM_IMPORTED
+if it is set when a target is created.
diff --git a/Help/prop_tgt/OSX_ARCHITECTURES.rst b/Help/prop_tgt/OSX_ARCHITECTURES.rst
new file mode 100644
index 0000000000..cefe03f5b5
--- /dev/null
+++ b/Help/prop_tgt/OSX_ARCHITECTURES.rst
@@ -0,0 +1,11 @@
+OSX_ARCHITECTURES
+-----------------
+
+Target specific architectures for OS X.
+
+The ``OSX_ARCHITECTURES`` property sets the target binary architecture for
+targets on OS X (``-arch``). This property is initialized by the value of the
+variable :variable:`CMAKE_OSX_ARCHITECTURES` if it is set when a target is
+created. Use :prop_tgt:`OSX_ARCHITECTURES_<CONFIG>` to set the binary
+architectures on a per-configuration basis, where ``<CONFIG>`` is an
+upper-case name (e.g. ``OSX_ARCHITECTURES_DEBUG``).
diff --git a/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst b/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst
new file mode 100644
index 0000000000..f8fdcff6fa
--- /dev/null
+++ b/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst
@@ -0,0 +1,7 @@
+OSX_ARCHITECTURES_<CONFIG>
+--------------------------
+
+Per-configuration OS X binary architectures for a target.
+
+This property is the configuration-specific version of
+:prop_tgt:`OSX_ARCHITECTURES`.
diff --git a/Help/prop_tgt/OUTPUT_NAME.rst b/Help/prop_tgt/OUTPUT_NAME.rst
new file mode 100644
index 0000000000..97bf01094e
--- /dev/null
+++ b/Help/prop_tgt/OUTPUT_NAME.rst
@@ -0,0 +1,8 @@
+OUTPUT_NAME
+-----------
+
+Output name for target files.
+
+This sets the base name for output files created for an executable or
+library target. If not set, the logical target name is used by
+default.
diff --git a/Help/prop_tgt/OUTPUT_NAME_CONFIG.rst b/Help/prop_tgt/OUTPUT_NAME_CONFIG.rst
new file mode 100644
index 0000000000..7bfbcbccfe
--- /dev/null
+++ b/Help/prop_tgt/OUTPUT_NAME_CONFIG.rst
@@ -0,0 +1,6 @@
+OUTPUT_NAME_<CONFIG>
+--------------------
+
+Per-configuration target file base name.
+
+This is the configuration-specific version of OUTPUT_NAME.
diff --git a/Help/prop_tgt/PDB_NAME.rst b/Help/prop_tgt/PDB_NAME.rst
new file mode 100644
index 0000000000..479dec3f93
--- /dev/null
+++ b/Help/prop_tgt/PDB_NAME.rst
@@ -0,0 +1,11 @@
+PDB_NAME
+--------
+
+Output name for the MS debug symbol ``.pdb`` file generated by the
+linker for an executable or shared library target.
+
+This property specifies the base name for the debug symbols file.
+If not set, the logical target name is used by default.
+
+.. |COMPILE_PDB_XXX| replace:: :prop_tgt:`COMPILE_PDB_NAME`
+.. include:: PDB_NOTE.txt
diff --git a/Help/prop_tgt/PDB_NAME_CONFIG.rst b/Help/prop_tgt/PDB_NAME_CONFIG.rst
new file mode 100644
index 0000000000..cb3121c2f3
--- /dev/null
+++ b/Help/prop_tgt/PDB_NAME_CONFIG.rst
@@ -0,0 +1,10 @@
+PDB_NAME_<CONFIG>
+-----------------
+
+Per-configuration output name for the MS debug symbol ``.pdb`` file
+generated by the linker for an executable or shared library target.
+
+This is the configuration-specific version of :prop_tgt:`PDB_NAME`.
+
+.. |COMPILE_PDB_XXX| replace:: :prop_tgt:`COMPILE_PDB_NAME_<CONFIG>`
+.. include:: PDB_NOTE.txt
diff --git a/Help/prop_tgt/PDB_NOTE.txt b/Help/prop_tgt/PDB_NOTE.txt
new file mode 100644
index 0000000000..f90ea81175
--- /dev/null
+++ b/Help/prop_tgt/PDB_NOTE.txt
@@ -0,0 +1,12 @@
+.. note::
+ This property does not apply to STATIC library targets because no linker
+ is invoked to produce them so they have no linker-generated ``.pdb`` file
+ containing debug symbols.
+
+ The linker-generated program database files are specified by the
+ ``/pdb`` linker flag and are not the same as compiler-generated
+ program database files specified by the ``/Fd`` compiler flag.
+ Use the |COMPILE_PDB_XXX| property to specify the latter.
+
+ This property is not implemented by the :generator:`Visual Studio 6`
+ generator.
diff --git a/Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst b/Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..730cf57767
--- /dev/null
+++ b/Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,13 @@
+PDB_OUTPUT_DIRECTORY
+--------------------
+
+Output directory for the MS debug symbols ``.pdb`` file
+generated by the linker for an executable or shared library target.
+
+This property specifies the directory into which the MS debug symbols
+will be placed by the linker. This property is initialized by the
+value of the :variable:`CMAKE_PDB_OUTPUT_DIRECTORY` variable if it is
+set when a target is created.
+
+.. |COMPILE_PDB_XXX| replace:: :prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY`
+.. include:: PDB_NOTE.txt
diff --git a/Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst b/Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst
new file mode 100644
index 0000000000..6037fa0c7b
--- /dev/null
+++ b/Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst
@@ -0,0 +1,15 @@
+PDB_OUTPUT_DIRECTORY_<CONFIG>
+-----------------------------
+
+Per-configuration output directory for the MS debug symbol ``.pdb`` file
+generated by the linker for an executable or shared library target.
+
+This is a per-configuration version of :prop_tgt:`PDB_OUTPUT_DIRECTORY`,
+but multi-configuration generators (VS, Xcode) do NOT append a
+per-configuration subdirectory to the specified directory. This
+property is initialized by the value of the
+:variable:`CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG>` variable if it is
+set when a target is created.
+
+.. |COMPILE_PDB_XXX| replace:: :prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>`
+.. include:: PDB_NOTE.txt
diff --git a/Help/prop_tgt/POSITION_INDEPENDENT_CODE.rst b/Help/prop_tgt/POSITION_INDEPENDENT_CODE.rst
new file mode 100644
index 0000000000..54af8c6ded
--- /dev/null
+++ b/Help/prop_tgt/POSITION_INDEPENDENT_CODE.rst
@@ -0,0 +1,11 @@
+POSITION_INDEPENDENT_CODE
+-------------------------
+
+Whether to create a position-independent target
+
+The ``POSITION_INDEPENDENT_CODE`` property determines whether position
+independent executables or shared libraries will be created. This
+property is ``True`` by default for ``SHARED`` and ``MODULE`` library
+targets and ``False`` otherwise. This property is initialized by the value
+of the :variable:`CMAKE_POSITION_INDEPENDENT_CODE` variable if it is set
+when a target is created.
diff --git a/Help/prop_tgt/POST_INSTALL_SCRIPT.rst b/Help/prop_tgt/POST_INSTALL_SCRIPT.rst
new file mode 100644
index 0000000000..f1adb40b7d
--- /dev/null
+++ b/Help/prop_tgt/POST_INSTALL_SCRIPT.rst
@@ -0,0 +1,9 @@
+POST_INSTALL_SCRIPT
+-------------------
+
+Deprecated install support.
+
+The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the old
+way to specify CMake scripts to run before and after installing a
+target. They are used only when the old INSTALL_TARGETS command is
+used to install the target. Use the INSTALL command instead.
diff --git a/Help/prop_tgt/PREFIX.rst b/Help/prop_tgt/PREFIX.rst
new file mode 100644
index 0000000000..a16510461d
--- /dev/null
+++ b/Help/prop_tgt/PREFIX.rst
@@ -0,0 +1,7 @@
+PREFIX
+------
+
+What comes before the library name.
+
+A target property that can be set to override the prefix (such as
+"lib") on a library name.
diff --git a/Help/prop_tgt/PRE_INSTALL_SCRIPT.rst b/Help/prop_tgt/PRE_INSTALL_SCRIPT.rst
new file mode 100644
index 0000000000..113d7c56ae
--- /dev/null
+++ b/Help/prop_tgt/PRE_INSTALL_SCRIPT.rst
@@ -0,0 +1,9 @@
+PRE_INSTALL_SCRIPT
+------------------
+
+Deprecated install support.
+
+The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the old
+way to specify CMake scripts to run before and after installing a
+target. They are used only when the old INSTALL_TARGETS command is
+used to install the target. Use the INSTALL command instead.
diff --git a/Help/prop_tgt/PRIVATE_HEADER.rst b/Help/prop_tgt/PRIVATE_HEADER.rst
new file mode 100644
index 0000000000..da2127b180
--- /dev/null
+++ b/Help/prop_tgt/PRIVATE_HEADER.rst
@@ -0,0 +1,11 @@
+PRIVATE_HEADER
+--------------
+
+Specify private header 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 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.
diff --git a/Help/prop_tgt/PROJECT_LABEL.rst b/Help/prop_tgt/PROJECT_LABEL.rst
new file mode 100644
index 0000000000..a1491ee139
--- /dev/null
+++ b/Help/prop_tgt/PROJECT_LABEL.rst
@@ -0,0 +1,7 @@
+PROJECT_LABEL
+-------------
+
+Change the name of a target in an IDE.
+
+Can be used to change the name of the target in an IDE like Visual
+Studio.
diff --git a/Help/prop_tgt/PUBLIC_HEADER.rst b/Help/prop_tgt/PUBLIC_HEADER.rst
new file mode 100644
index 0000000000..6e25d94d53
--- /dev/null
+++ b/Help/prop_tgt/PUBLIC_HEADER.rst
@@ -0,0 +1,11 @@
+PUBLIC_HEADER
+-------------
+
+Specify public header 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 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.
diff --git a/Help/prop_tgt/RESOURCE.rst b/Help/prop_tgt/RESOURCE.rst
new file mode 100644
index 0000000000..1e9921de3b
--- /dev/null
+++ b/Help/prop_tgt/RESOURCE.rst
@@ -0,0 +1,11 @@
+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.
diff --git a/Help/prop_tgt/RULE_LAUNCH_COMPILE.rst b/Help/prop_tgt/RULE_LAUNCH_COMPILE.rst
new file mode 100644
index 0000000000..e92ab86aff
--- /dev/null
+++ b/Help/prop_tgt/RULE_LAUNCH_COMPILE.rst
@@ -0,0 +1,7 @@
+RULE_LAUNCH_COMPILE
+-------------------
+
+Specify a launcher for compile rules.
+
+See the global property of the same name for details. This overrides
+the global and directory property for a target.
diff --git a/Help/prop_tgt/RULE_LAUNCH_CUSTOM.rst b/Help/prop_tgt/RULE_LAUNCH_CUSTOM.rst
new file mode 100644
index 0000000000..2db03177f8
--- /dev/null
+++ b/Help/prop_tgt/RULE_LAUNCH_CUSTOM.rst
@@ -0,0 +1,7 @@
+RULE_LAUNCH_CUSTOM
+------------------
+
+Specify a launcher for custom rules.
+
+See the global property of the same name for details. This overrides
+the global and directory property for a target.
diff --git a/Help/prop_tgt/RULE_LAUNCH_LINK.rst b/Help/prop_tgt/RULE_LAUNCH_LINK.rst
new file mode 100644
index 0000000000..f330033678
--- /dev/null
+++ b/Help/prop_tgt/RULE_LAUNCH_LINK.rst
@@ -0,0 +1,7 @@
+RULE_LAUNCH_LINK
+----------------
+
+Specify a launcher for link rules.
+
+See the global property of the same name for details. This overrides
+the global and directory property for a target.
diff --git a/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.rst b/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..af5ef447e6
--- /dev/null
+++ b/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,7 @@
+RUNTIME_OUTPUT_DIRECTORY
+------------------------
+
+.. |XXX| replace:: RUNTIME
+.. |xxx| replace:: runtime
+.. |CMAKE_XXX_OUTPUT_DIRECTORY| replace:: CMAKE_RUNTIME_OUTPUT_DIRECTORY
+.. include:: XXX_OUTPUT_DIRECTORY.txt
diff --git a/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG.rst b/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG.rst
new file mode 100644
index 0000000000..10be6cf0cd
--- /dev/null
+++ b/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG.rst
@@ -0,0 +1,11 @@
+RUNTIME_OUTPUT_DIRECTORY_<CONFIG>
+---------------------------------
+
+Per-configuration output directory for RUNTIME target files.
+
+This is a per-configuration version of RUNTIME_OUTPUT_DIRECTORY, but
+multi-configuration generators (VS, Xcode) do NOT append a
+per-configuration subdirectory to the specified directory. This
+property is initialized by the value of the variable
+CMAKE_RUNTIME_OUTPUT_DIRECTORY_<CONFIG> if it is set when a target is
+created.
diff --git a/Help/prop_tgt/RUNTIME_OUTPUT_NAME.rst b/Help/prop_tgt/RUNTIME_OUTPUT_NAME.rst
new file mode 100644
index 0000000000..dc7dba412b
--- /dev/null
+++ b/Help/prop_tgt/RUNTIME_OUTPUT_NAME.rst
@@ -0,0 +1,6 @@
+RUNTIME_OUTPUT_NAME
+-------------------
+
+.. |XXX| replace:: RUNTIME
+.. |xxx| replace:: runtime
+.. include:: XXX_OUTPUT_NAME.txt
diff --git a/Help/prop_tgt/RUNTIME_OUTPUT_NAME_CONFIG.rst b/Help/prop_tgt/RUNTIME_OUTPUT_NAME_CONFIG.rst
new file mode 100644
index 0000000000..f9029e5d4e
--- /dev/null
+++ b/Help/prop_tgt/RUNTIME_OUTPUT_NAME_CONFIG.rst
@@ -0,0 +1,6 @@
+RUNTIME_OUTPUT_NAME_<CONFIG>
+----------------------------
+
+Per-configuration output name for RUNTIME target files.
+
+This is the configuration-specific version of RUNTIME_OUTPUT_NAME.
diff --git a/Help/prop_tgt/SKIP_BUILD_RPATH.rst b/Help/prop_tgt/SKIP_BUILD_RPATH.rst
new file mode 100644
index 0000000000..a91fa9ca39
--- /dev/null
+++ b/Help/prop_tgt/SKIP_BUILD_RPATH.rst
@@ -0,0 +1,9 @@
+SKIP_BUILD_RPATH
+----------------
+
+Should rpaths be used for the build tree.
+
+SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic
+generation of an rpath allowing the target to run from the build tree.
+This property is initialized by the value of the variable
+CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.
diff --git a/Help/prop_tgt/SOURCES.rst b/Help/prop_tgt/SOURCES.rst
new file mode 100644
index 0000000000..493643e841
--- /dev/null
+++ b/Help/prop_tgt/SOURCES.rst
@@ -0,0 +1,6 @@
+SOURCES
+-------
+
+Source names specified for a target.
+
+List of sources specified for a target.
diff --git a/Help/prop_tgt/SOVERSION.rst b/Help/prop_tgt/SOVERSION.rst
new file mode 100644
index 0000000000..672ff23a8d
--- /dev/null
+++ b/Help/prop_tgt/SOVERSION.rst
@@ -0,0 +1,14 @@
+SOVERSION
+---------
+
+What version number is this target.
+
+For shared libraries VERSION and SOVERSION can be used to specify the
+build version and API version respectively. When building or
+installing appropriate symlinks are created if the platform supports
+symlinks and the linker supports so-names. If only one of both is
+specified the missing is assumed to have the same version number.
+SOVERSION is ignored if NO_SONAME property is set. For shared
+libraries and executables on Windows the VERSION attribute is parsed
+to extract a "major.minor" version number. These numbers are used as
+the image version of the binary.
diff --git a/Help/prop_tgt/STATIC_LIBRARY_FLAGS.rst b/Help/prop_tgt/STATIC_LIBRARY_FLAGS.rst
new file mode 100644
index 0000000000..d3b2cd4788
--- /dev/null
+++ b/Help/prop_tgt/STATIC_LIBRARY_FLAGS.rst
@@ -0,0 +1,6 @@
+STATIC_LIBRARY_FLAGS
+--------------------
+
+Extra flags to use when linking static libraries.
+
+Extra flags to use when linking a static library.
diff --git a/Help/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG.rst b/Help/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG.rst
new file mode 100644
index 0000000000..cca353ddce
--- /dev/null
+++ b/Help/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG.rst
@@ -0,0 +1,6 @@
+STATIC_LIBRARY_FLAGS_<CONFIG>
+-----------------------------
+
+Per-configuration flags for creating a static library.
+
+This is the configuration-specific version of STATIC_LIBRARY_FLAGS.
diff --git a/Help/prop_tgt/SUFFIX.rst b/Help/prop_tgt/SUFFIX.rst
new file mode 100644
index 0000000000..70844be5cc
--- /dev/null
+++ b/Help/prop_tgt/SUFFIX.rst
@@ -0,0 +1,7 @@
+SUFFIX
+------
+
+What comes after the target name.
+
+A target property that can be set to override the suffix (such as
+".so" or ".exe") on the name of a library, module or executable.
diff --git a/Help/prop_tgt/TARGET_FILE_TYPES.txt b/Help/prop_tgt/TARGET_FILE_TYPES.txt
new file mode 100644
index 0000000000..18489c7dc5
--- /dev/null
+++ b/Help/prop_tgt/TARGET_FILE_TYPES.txt
@@ -0,0 +1,9 @@
+There are three kinds of target files that may be built: archive,
+library, and runtime. Executables are always treated as runtime
+targets. Static libraries are always treated as archive targets.
+Module libraries are always treated as library targets. For
+non-DLL platforms shared libraries are treated as library
+targets. For DLL platforms the DLL part of a shared library is
+treated as a runtime target and the corresponding import library
+is treated as an archive target. All Windows-based systems
+including Cygwin are DLL platforms.
diff --git a/Help/prop_tgt/TYPE.rst b/Help/prop_tgt/TYPE.rst
new file mode 100644
index 0000000000..1951d46bed
--- /dev/null
+++ b/Help/prop_tgt/TYPE.rst
@@ -0,0 +1,8 @@
+TYPE
+----
+
+The type of the target.
+
+This read-only property can be used to test the type of the given
+target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY,
+SHARED_LIBRARY, EXECUTABLE or one of the internal target types.
diff --git a/Help/prop_tgt/VERSION.rst b/Help/prop_tgt/VERSION.rst
new file mode 100644
index 0000000000..87f6c49766
--- /dev/null
+++ b/Help/prop_tgt/VERSION.rst
@@ -0,0 +1,16 @@
+VERSION
+-------
+
+What version number is this target.
+
+For shared libraries VERSION and SOVERSION can be used to specify the
+build version and API version respectively. When building or
+installing appropriate symlinks are created if the platform supports
+symlinks and the linker supports so-names. If only one of both is
+specified the missing is assumed to have the same version number. For
+executables VERSION can be used to specify the build version. When
+building or installing appropriate symlinks are created if the
+platform supports symlinks. For shared libraries and executables on
+Windows the VERSION attribute is parsed to extract a "major.minor"
+version number. These numbers are used as the image version of the
+binary.
diff --git a/Help/prop_tgt/VISIBILITY_INLINES_HIDDEN.rst b/Help/prop_tgt/VISIBILITY_INLINES_HIDDEN.rst
new file mode 100644
index 0000000000..e06d35c5fa
--- /dev/null
+++ b/Help/prop_tgt/VISIBILITY_INLINES_HIDDEN.rst
@@ -0,0 +1,11 @@
+VISIBILITY_INLINES_HIDDEN
+-------------------------
+
+Whether to add a compile flag to hide symbols of inline functions
+
+The VISIBILITY_INLINES_HIDDEN property determines whether a flag for
+hiding symbols for inline functions, such as -fvisibility-inlines-hidden,
+should be used when invoking the compiler. This property only has an affect
+for libraries and executables with exports. This property is initialized by
+the value of the :variable:`CMAKE_VISIBILITY_INLINES_HIDDEN` if it is set
+when a target is created.
diff --git a/Help/prop_tgt/VS_DOTNET_REFERENCES.rst b/Help/prop_tgt/VS_DOTNET_REFERENCES.rst
new file mode 100644
index 0000000000..a661ad926a
--- /dev/null
+++ b/Help/prop_tgt/VS_DOTNET_REFERENCES.rst
@@ -0,0 +1,7 @@
+VS_DOTNET_REFERENCES
+--------------------
+
+Visual Studio managed project .NET references
+
+Adds one or more semicolon-delimited .NET references to a generated
+Visual Studio project. For example, "System;System.Windows.Forms".
diff --git a/Help/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION.rst b/Help/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION.rst
new file mode 100644
index 0000000000..829d696d57
--- /dev/null
+++ b/Help/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION.rst
@@ -0,0 +1,7 @@
+VS_DOTNET_TARGET_FRAMEWORK_VERSION
+----------------------------------
+
+Specify the .NET target framework version.
+
+Used to specify the .NET target framework version for C++/CLI. For
+example, "v4.5".
diff --git a/Help/prop_tgt/VS_GLOBAL_KEYWORD.rst b/Help/prop_tgt/VS_GLOBAL_KEYWORD.rst
new file mode 100644
index 0000000000..ce49316d8b
--- /dev/null
+++ b/Help/prop_tgt/VS_GLOBAL_KEYWORD.rst
@@ -0,0 +1,12 @@
+VS_GLOBAL_KEYWORD
+-----------------
+
+Visual Studio project keyword for VS 10 (2010) and newer.
+
+Sets the "keyword" attribute for a generated Visual Studio project.
+Defaults to "Win32Proj". You may wish to override this value with
+"ManagedCProj", for example, in a Visual Studio managed C++ unit test
+project.
+
+Use the :prop_tgt:`VS_KEYWORD` target property to set the
+keyword for Visual Studio 9 (2008) and older.
diff --git a/Help/prop_tgt/VS_GLOBAL_PROJECT_TYPES.rst b/Help/prop_tgt/VS_GLOBAL_PROJECT_TYPES.rst
new file mode 100644
index 0000000000..f4d9efc8eb
--- /dev/null
+++ b/Help/prop_tgt/VS_GLOBAL_PROJECT_TYPES.rst
@@ -0,0 +1,15 @@
+VS_GLOBAL_PROJECT_TYPES
+-----------------------
+
+Visual Studio project type(s).
+
+Can be set to one or more UUIDs recognized by Visual Studio to
+indicate the type of project. This value is copied verbatim into the
+generated project file. Example for a managed C++ unit testing
+project:
+
+::
+
+ {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}
+
+UUIDs are semicolon-delimited.
diff --git a/Help/prop_tgt/VS_GLOBAL_ROOTNAMESPACE.rst b/Help/prop_tgt/VS_GLOBAL_ROOTNAMESPACE.rst
new file mode 100644
index 0000000000..a23c54005e
--- /dev/null
+++ b/Help/prop_tgt/VS_GLOBAL_ROOTNAMESPACE.rst
@@ -0,0 +1,7 @@
+VS_GLOBAL_ROOTNAMESPACE
+-----------------------
+
+Visual Studio project root namespace.
+
+Sets the "RootNamespace" attribute for a generated Visual Studio
+project. The attribute will be generated only if this is set.
diff --git a/Help/prop_tgt/VS_GLOBAL_variable.rst b/Help/prop_tgt/VS_GLOBAL_variable.rst
new file mode 100644
index 0000000000..56b8021bef
--- /dev/null
+++ b/Help/prop_tgt/VS_GLOBAL_variable.rst
@@ -0,0 +1,10 @@
+VS_GLOBAL_<variable>
+--------------------
+
+Visual Studio project-specific global variable.
+
+Tell the Visual Studio generator to set the global variable
+'<variable>' to a given value in the generated Visual Studio project.
+Ignored on other generators. Qt integration works better if
+VS_GLOBAL_QtVersion is set to the version FindQt4.cmake found. For
+example, "4.7.3"
diff --git a/Help/prop_tgt/VS_KEYWORD.rst b/Help/prop_tgt/VS_KEYWORD.rst
new file mode 100644
index 0000000000..6c2e0420e3
--- /dev/null
+++ b/Help/prop_tgt/VS_KEYWORD.rst
@@ -0,0 +1,10 @@
+VS_KEYWORD
+----------
+
+Visual Studio project keyword for VS 9 (2008) and older.
+
+Can be set to change the visual studio keyword, for example Qt
+integration works better if this is set to Qt4VSv1.0.
+
+Use the :prop_tgt:`VS_GLOBAL_KEYWORD` target property to set the
+keyword for Visual Studio 10 (2010) and newer.
diff --git a/Help/prop_tgt/VS_SCC_AUXPATH.rst b/Help/prop_tgt/VS_SCC_AUXPATH.rst
new file mode 100644
index 0000000000..054f59e3ad
--- /dev/null
+++ b/Help/prop_tgt/VS_SCC_AUXPATH.rst
@@ -0,0 +1,7 @@
+VS_SCC_AUXPATH
+--------------
+
+Visual Studio Source Code Control Aux Path.
+
+Can be set to change the visual studio source code control auxpath
+property.
diff --git a/Help/prop_tgt/VS_SCC_LOCALPATH.rst b/Help/prop_tgt/VS_SCC_LOCALPATH.rst
new file mode 100644
index 0000000000..b5b7721c5e
--- /dev/null
+++ b/Help/prop_tgt/VS_SCC_LOCALPATH.rst
@@ -0,0 +1,7 @@
+VS_SCC_LOCALPATH
+----------------
+
+Visual Studio Source Code Control Local Path.
+
+Can be set to change the visual studio source code control local path
+property.
diff --git a/Help/prop_tgt/VS_SCC_PROJECTNAME.rst b/Help/prop_tgt/VS_SCC_PROJECTNAME.rst
new file mode 100644
index 0000000000..6d7f628d92
--- /dev/null
+++ b/Help/prop_tgt/VS_SCC_PROJECTNAME.rst
@@ -0,0 +1,7 @@
+VS_SCC_PROJECTNAME
+------------------
+
+Visual Studio Source Code Control Project.
+
+Can be set to change the visual studio source code control project
+name property.
diff --git a/Help/prop_tgt/VS_SCC_PROVIDER.rst b/Help/prop_tgt/VS_SCC_PROVIDER.rst
new file mode 100644
index 0000000000..80475af1f0
--- /dev/null
+++ b/Help/prop_tgt/VS_SCC_PROVIDER.rst
@@ -0,0 +1,7 @@
+VS_SCC_PROVIDER
+---------------
+
+Visual Studio Source Code Control Provider.
+
+Can be set to change the visual studio source code control provider
+property.
diff --git a/Help/prop_tgt/VS_WINRT_COMPONENT.rst b/Help/prop_tgt/VS_WINRT_COMPONENT.rst
new file mode 100644
index 0000000000..e160bd64be
--- /dev/null
+++ b/Help/prop_tgt/VS_WINRT_COMPONENT.rst
@@ -0,0 +1,11 @@
+VS_WINRT_COMPONENT
+------------------
+
+Mark a target as a Windows Runtime component for the Visual Studio generator.
+Compile the target with ``C++/CX`` language extensions for Windows Runtime.
+For ``SHARED`` and ``MODULE`` libraries, this also defines the
+``_WINRT_DLL`` preprocessor macro.
+
+.. note::
+ Currently this is implemented only by Visual Studio generators.
+ Support may be added to other generators in the future.
diff --git a/Help/prop_tgt/VS_WINRT_EXTENSIONS.rst b/Help/prop_tgt/VS_WINRT_EXTENSIONS.rst
new file mode 100644
index 0000000000..d1cba3471f
--- /dev/null
+++ b/Help/prop_tgt/VS_WINRT_EXTENSIONS.rst
@@ -0,0 +1,5 @@
+VS_WINRT_EXTENSIONS
+-------------------
+
+Deprecated. Use :prop_tgt:`VS_WINRT_COMPONENT` instead.
+This property was an experimental partial implementation of that one.
diff --git a/Help/prop_tgt/VS_WINRT_REFERENCES.rst b/Help/prop_tgt/VS_WINRT_REFERENCES.rst
new file mode 100644
index 0000000000..af98b2f7b7
--- /dev/null
+++ b/Help/prop_tgt/VS_WINRT_REFERENCES.rst
@@ -0,0 +1,7 @@
+VS_WINRT_REFERENCES
+-------------------
+
+Visual Studio project Windows Runtime Metadata references
+
+Adds one or more semicolon-delimited WinRT references to a generated
+Visual Studio project. For example, "Windows;Windows.UI.Core".
diff --git a/Help/prop_tgt/WIN32_EXECUTABLE.rst b/Help/prop_tgt/WIN32_EXECUTABLE.rst
new file mode 100644
index 0000000000..336d5f7f38
--- /dev/null
+++ b/Help/prop_tgt/WIN32_EXECUTABLE.rst
@@ -0,0 +1,12 @@
+WIN32_EXECUTABLE
+----------------
+
+Build an executable with a WinMain entry point on windows.
+
+When this property is set to true the executable when linked on
+Windows will be created with a WinMain() entry point instead of just
+main(). This makes it a GUI executable instead of a console
+application. See the CMAKE_MFC_FLAG variable documentation to
+configure use of MFC for WinMain executables. This property is
+initialized by the value of the variable CMAKE_WIN32_EXECUTABLE if it
+is set when a target is created.
diff --git a/Help/prop_tgt/XCODE_ATTRIBUTE_an-attribute.rst b/Help/prop_tgt/XCODE_ATTRIBUTE_an-attribute.rst
new file mode 100644
index 0000000000..0be313c866
--- /dev/null
+++ b/Help/prop_tgt/XCODE_ATTRIBUTE_an-attribute.rst
@@ -0,0 +1,7 @@
+XCODE_ATTRIBUTE_<an-attribute>
+------------------------------
+
+Set Xcode target attributes directly.
+
+Tell the Xcode generator to set '<an-attribute>' to a given value in
+the generated Xcode project. Ignored on other generators.
diff --git a/Help/prop_tgt/XXX_OUTPUT_DIRECTORY.txt b/Help/prop_tgt/XXX_OUTPUT_DIRECTORY.txt
new file mode 100644
index 0000000000..65abbceae5
--- /dev/null
+++ b/Help/prop_tgt/XXX_OUTPUT_DIRECTORY.txt
@@ -0,0 +1,10 @@
+Output directory in which to build |XXX| target files.
+
+This property specifies the directory into which |xxx| target files
+should be built. Multi-configuration generators (VS, Xcode) append a
+per-configuration subdirectory to the specified directory.
+
+.. include:: TARGET_FILE_TYPES.txt
+
+This property is initialized by the value of the variable
+|CMAKE_XXX_OUTPUT_DIRECTORY| if it is set when a target is created.
diff --git a/Help/prop_tgt/XXX_OUTPUT_NAME.txt b/Help/prop_tgt/XXX_OUTPUT_NAME.txt
new file mode 100644
index 0000000000..9c4fc7c4ae
--- /dev/null
+++ b/Help/prop_tgt/XXX_OUTPUT_NAME.txt
@@ -0,0 +1,6 @@
+Output name for |XXX| target files.
+
+This property specifies the base name for |xxx| target files. It
+overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties.
+
+.. include:: TARGET_FILE_TYPES.txt
diff --git a/Help/release/3.0.0.rst b/Help/release/3.0.0.rst
new file mode 100644
index 0000000000..e92c293289
--- /dev/null
+++ b/Help/release/3.0.0.rst
@@ -0,0 +1,473 @@
+CMake 3.0.0 Release Notes
+*************************
+
+.. only:: html
+
+ .. contents::
+
+Changes made since CMake 2.8.12.2 include the following.
+
+Documentation Changes
+=====================
+
+* The CMake documentation has been converted to reStructuredText and
+ now transforms via Sphinx (`<http://sphinx-doc.org>`__) into man and
+ html pages. This allows the documentation to be properly indexed
+ and to contain cross-references.
+
+ Conversion from the old internal documentation format was done by
+ an automatic process so some documents may still contain artifacts.
+ They will be updated incrementally over time.
+
+ A basic reStructuredText processor has been implemented to support
+ ``cmake --help-command`` and similar command-line options.
+
+* New manuals were added:
+
+ - :manual:`cmake-buildsystem(7)`
+ - :manual:`cmake-commands(7)`, replacing ``cmakecommands(1)``
+ and ``cmakecompat(1)``
+ - :manual:`cmake-developer(7)`
+ - :manual:`cmake-generator-expressions(7)`
+ - :manual:`cmake-generators(7)`
+ - :manual:`cmake-language(7)`
+ - :manual:`cmake-modules(7)`, replacing ``cmakemodules(1)``
+ - :manual:`cmake-packages(7)`
+ - :manual:`cmake-policies(7)`, replacing ``cmakepolicies(1)``
+ - :manual:`cmake-properties(7)`, replacing ``cmakeprops(1)``
+ - :manual:`cmake-qt(7)`
+ - :manual:`cmake-toolchains(7)`
+ - :manual:`cmake-variables(7)`, replacing ``cmakevars(1)``
+
+* Release notes for CMake 3.0.0 and above will now be included with
+ the html documentation.
+
+New Features
+============
+
+Syntax
+------
+
+* The CMake language has been extended with
+ :ref:`Bracket Argument` and :ref:`Bracket Comment`
+ syntax inspired by Lua long brackets::
+
+ set(x [===[bracket argument]===] #[[bracket comment]])
+
+ Content between equal-length open- and close-brackets is taken
+ literally with no variable replacements.
+
+ .. warning::
+ This syntax change could not be made in a fully compatible
+ way. No policy is possible because syntax parsing occurs before
+ any chance to set a policy. Existing code using an unquoted
+ argument that starts with an open bracket will be interpreted
+ differently without any diagnostic. Fortunately the syntax is
+ obscure enough that this problem is unlikely in practice.
+
+Generators
+----------
+
+* A new :generator:`CodeLite` extra generator is available
+ for use with the Makefile or Ninja generators.
+
+* A new :generator:`Kate` extra generator is available
+ for use with the Makefile or Ninja generators.
+
+* The :generator:`Ninja` generator learned to use ``ninja`` job pools
+ when specified by a new :prop_gbl:`JOB_POOLS` global property.
+
+Commands
+--------
+
+* The :command:`add_library` command learned a new ``INTERFACE``
+ library type. Interface libraries have no build rules but may
+ have properties defining
+ :manual:`usage requirements <cmake-buildsystem(7)>`
+ and may be installed, exported, and imported. This is useful to
+ create header-only libraries that have concrete link dependencies
+ on other libraries.
+
+* The :command:`export()` command learned a new ``EXPORT`` mode that
+ retrieves the list of targets to export from an export set configured
+ by the :command:`install(TARGETS)` command ``EXPORT`` option. This
+ makes it easy to export from the build tree the same targets that
+ are exported from the install tree.
+
+* The :command:`export` command learned to work with multiple dependent
+ export sets, thus allowing multiple packages to be built and exported
+ from a single tree. The feature requires CMake to wait until the
+ generation step to write the output file. This means one should not
+ :command:`include` the generated targets file later during project
+ configuration because it will not be available.
+ Use :ref:`Alias Targets` instead. See policy :policy:`CMP0024`.
+
+* The :command:`install(FILES)` command learned to support
+ :manual:`generator expressions <cmake-generator-expressions(7)>`
+ in the list of files.
+
+* The :command:`project` command learned to set some version variables
+ to values specified by the new ``VERSION`` option or to empty strings.
+ See policy :policy:`CMP0048`.
+
+* The :command:`string` command learned a new ``CONCAT`` mode.
+ It is particularly useful in combination with the new
+ :ref:`Bracket Argument` syntax.
+
+* The :command:`unset` command learned a ``PARENT_SCOPE`` option
+ matching that of the :command:`set` command.
+
+* The :command:`include_external_msproject` command learned
+ to handle non-C++ projects like ``.vbproj`` or ``.csproj``.
+
+* The :command:`ctest_update` command learned to update work trees
+ managed by the Perforce (p4) version control tool.
+
+* The :command:`message` command learned a ``DEPRECATION`` mode. Such
+ messages are not issued by default, but may be issued as a warning if
+ :variable:`CMAKE_WARN_DEPRECATED` is enabled, or as an error if
+ :variable:`CMAKE_ERROR_DEPRECATED` is enabled.
+
+* The :command:`target_link_libraries` command now allows repeated use of
+ the ``LINK_PUBLIC`` and ``LINK_PRIVATE`` keywords.
+
+Variables
+---------
+
+* Variable :variable:`CMAKE_FIND_NO_INSTALL_PREFIX` has been
+ introduced to tell CMake not to add the value of
+ :variable:`CMAKE_INSTALL_PREFIX` to the
+ :variable:`CMAKE_SYSTEM_PREFIX_PATH` variable by default.
+ This is useful when building a project that installs some
+ of its own dependencies to avoid finding files it is about
+ to replace.
+
+* Variable :variable:`CMAKE_STAGING_PREFIX` was introduced for use
+ when cross-compiling to specify an installation prefix on the
+ host system that differs from a :variable:`CMAKE_INSTALL_PREFIX`
+ value meant for the target system.
+
+* Variable :variable:`CMAKE_SYSROOT` was introduced to specify the
+ toolchain SDK installation prefix, typically for cross-compiling.
+ This is used to pass a ``--sysroot`` option to the compiler and
+ as a prefix searched by ``find_*`` commands.
+
+* Variable :variable:`CMAKE_<LANG>_COMPILER_TARGET` was introduced
+ for use when cross-compiling to specify the target platform in the
+ :ref:`toolchain file <Cross Compiling Toolchain>` specified by the
+ :variable:`CMAKE_TOOLCHAIN_FILE` variable.
+ This is used to pass an option such as ``--target=<triple>`` to some
+ cross-compiling compiler drivers.
+
+* Variable :variable:`CMAKE_MAP_IMPORTED_CONFIG_<CONFIG>` has been
+ introduced to optionally initialize the
+ :prop_tgt:`MAP_IMPORTED_CONFIG_<CONFIG>` target property.
+
+Properties
+----------
+
+* The :prop_dir:`ADDITIONAL_MAKE_CLEAN_FILES` directory property
+ learned to support
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+* A new directory property :prop_dir:`CMAKE_CONFIGURE_DEPENDS`
+ was introduced to allow projects to specify additional
+ files on which the configuration process depends. CMake will
+ re-run at build time when one of these files is modified.
+ Previously this was only possible to achieve by specifying
+ such files as the input to a :command:`configure_file` command.
+
+* A new :ref:`Qt AUTORCC` feature replaces the need to
+ invoke ``qt4_add_resources()`` by allowing ``.qrc`` files to
+ be listed as target sources.
+
+* A new :ref:`Qt AUTOUIC` feature replaces the need to
+ invoke ``qt4_wrap_ui()``.
+
+* Test properties learned to support
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+ This is useful to specify per-configuration values for test
+ properties like :prop_test:`REQUIRED_FILES` and
+ :prop_test:`WORKING_DIRECTORY`.
+
+* A new :prop_test:`SKIP_RETURN_CODE` test property was introduced
+ to tell :manual:`ctest(1)` to treat a particular test return code as
+ if the test were not run. This is useful for test drivers to report
+ that certain test requirements were not available.
+
+* New types of :ref:`Compatible Interface Properties` were introduced,
+ namely the :prop_tgt:`COMPATIBLE_INTERFACE_NUMBER_MAX` and
+ :prop_tgt:`COMPATIBLE_INTERFACE_NUMBER_MIN` for calculating numeric
+ maximum and minimum values respectively.
+
+Modules
+-------
+
+* The :module:`CheckTypeSize` module ``check_type_size`` macro and
+ the :module:`CheckStructHasMember` module ``check_struct_has_member``
+ macro learned a new ``LANGUAGE`` option to optionally check C++ types.
+
+* The :module:`ExternalData` module learned to work with no
+ URL templates if a local store is available.
+
+* The :module:`ExternalProject` function ``ExternalProject_Add``
+ learned a new ``GIT_SUBMODULES`` option to specify a subset
+ of available submodules to checkout.
+
+* A new :module:`FindBacktrace` module has been added to support
+ :command:`find_package(Backtrace)` calls.
+
+* A new :module:`FindLua` module has been added to support
+ :command:`find_package(Lua)` calls.
+
+* The :module:`FindBoost` module learned a new ``Boost_NAMESPACE``
+ option to change the ``boost`` prefix on library names.
+
+* The :module:`FindBoost` module learned to control search
+ for libraies with the ``g`` tag (for MS debug runtime) with
+ a new ``Boost_USE_DEBUG_RUNTIME`` option. It is ``ON`` by
+ default to preserve existing behavior.
+
+* The :module:`FindJava` and :module:`FindJNI` modules learned
+ to use a ``JAVA_HOME`` CMake variable or environment variable,
+ and then try ``/usr/libexec/java_home`` on OS X.
+
+* The :module:`UseJava` module ``add_jar`` function learned a new
+ ``MANIFEST`` option to pass the ``-m`` option to ``jar``.
+
+* A new :module:`CMakeFindDependencyMacro` module was introduced with
+ a ``find_dependency`` macro to find transitive dependencies in
+ a :manual:`package configuration file <cmake-packages(7)>`. Such
+ dependencies are omitted by the listing of the :module:`FeatureSummary`
+ module.
+
+* The :module:`FindQt4` module learned to create :ref:`Imported Targets`
+ for Qt executables. This helps disambiguate when using multiple
+ :manual:`Qt versions <cmake-qt(7)>` in the same buildsystem.
+
+* The :module:`FindRuby` module learned to search for Ruby 2.0 and 2.1.
+
+Generator Expressions
+---------------------
+
+* New ``$<PLATFORM_ID>`` and ``$<PLATFORM_ID:...>``
+ :manual:`generator expressions <cmake-generator-expressions(7)>`
+ have been added.
+
+* The ``$<CONFIG>``
+ :manual:`generator expression <cmake-generator-expressions(7)>` now has
+ a variant which takes no argument. This is equivalent to the
+ ``$<CONFIGURATION>`` expression.
+
+* New ``$<UPPER_CASE:...>`` and ``$<LOWER_CASE:...>``
+ :manual:`generator expressions <cmake-generator-expressions(7)>`
+ generator expressions have been added.
+
+* A new ``$<MAKE_C_IDENTIFIER:...>``
+ :manual:`generator expression <cmake-generator-expressions(7)>` has
+ been added.
+
+Other
+-----
+
+* The :manual:`cmake(1)` ``-E`` option learned a new ``sleep`` command.
+
+* The :manual:`ccmake(1)` dialog learned to honor the
+ :prop_cache:`STRINGS` cache entry property to cycle through
+ the enumerated list of possible values.
+
+* The :manual:`cmake-gui(1)` dialog learned to remember window
+ settings between sessions.
+
+* The :manual:`cmake-gui(1)` dialog learned to remember the type
+ of a cache entry for completion in the ``Add Entry`` dialog.
+
+New Diagnostics
+===============
+
+* Directories named in the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`
+ target property of imported targets linked conditionally by a
+ :manual:`generator expression <cmake-generator-expressions(7)>`
+ were not checked for existence. Now they are checked.
+ See policy :policy:`CMP0027`.
+
+* Build target names must now match a validity pattern and may no longer
+ conflict with CMake-defined targets. See policy :policy:`CMP0037`.
+
+* Build targets that specify themselves as a link dependency were
+ silently accepted but are now diagnosed. See :policy:`CMP0038`.
+
+* The :command:`target_link_libraries` command used to silently ignore
+ calls specifying as their first argument build targets created by
+ :command:`add_custom_target` but now diagnoses this mistake.
+ See policy :policy:`CMP0039`.
+
+* The :command:`add_custom_command` command used to silently ignore
+ calls specifying the ``TARGET`` option with a non-existent target
+ but now diagnoses this mistake. See policy :policy:`CMP0040`.
+
+* Relative paths in the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`
+ target property used to be silently accepted if they contained a
+ :manual:`generator expression <cmake-generator-expressions(7)>`
+ but are now rejected. See policy :policy:`CMP0041`.
+
+* The :command:`get_target_property` command learned to reject calls
+ specifying a non-existent target. See policy :policy:`CMP0045`.
+
+* The :command:`add_dependencies` command learned to reject calls
+ specifying a dependency on a non-existent target.
+ See policy :policy:`CMP0046`.
+
+* Link dependency analysis learned to assume names containing ``::``
+ refer to :ref:`Alias Targets` or :ref:`Imported Targets`. It will
+ now produce an error if such a linked target is missing. Previously
+ in this case CMake generated a link line that failed at build time.
+ See policy :policy:`CMP0028`.
+
+* When the :command:`project` or :command:`enable_language` commands
+ initialize support for a language, it is now an error if the full
+ path to the compiler cannot be found and stored in the corresponding
+ :variable:`CMAKE_<LANG>_COMPILER` variable. This produces nicer error
+ messages up front and stops processing when no working compiler
+ is known to be available.
+
+* Target sources specified with the :command:`add_library` or
+ :command:`add_executable` command learned to reject items which
+ require an undocumented extra layer of variable expansion.
+ See policy :policy:`CMP0049`.
+
+* Use of :command:`add_custom_command` undocumented ``SOURCE``
+ signatures now results in an error. See policy :policy:`CMP0050`.
+
+Deprecated and Removed Features
+===============================
+
+* Compatibility options supporting code written for CMake versions
+ prior to 2.4 have been removed.
+
+* Several long-outdated commands that should no longer be called
+ have been disallowed in new code by policies:
+
+ - Policy :policy:`CMP0029` disallows :command:`subdir_depends`
+ - Policy :policy:`CMP0030` disallows :command:`use_mangled_mesa`
+ - Policy :policy:`CMP0031` disallows :command:`load_command`
+ - Policy :policy:`CMP0032` disallows :command:`output_required_files`
+ - Policy :policy:`CMP0033` disallows :command:`export_library_dependencies`
+ - Policy :policy:`CMP0034` disallows :command:`utility_source`
+ - Policy :policy:`CMP0035` disallows :command:`variable_requires`
+ - Policy :policy:`CMP0036` disallows :command:`build_name`
+
+* The :manual:`cmake(1)` ``-i`` wizard mode has been removed.
+ Instead use an interactive dialog such as :manual:`ccmake(1)`
+ or use the ``-D`` option to set cache values from the command line.
+
+* The builtin documentation formatters that supported command-line
+ options such as ``--help-man`` and ``--help-html`` have been removed
+ in favor of the above-mentioned new documentation system. These and
+ other command-line options that used to generate man- and html-
+ formatted pages no longer work. The :manual:`cmake(1)`
+ ``--help-custom-modules`` option now produces a warning at runtime
+ and generates a minimal document that reports the limitation.
+
+* The :prop_dir:`COMPILE_DEFINITIONS_<CONFIG>` directory properties and the
+ :prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target properties have been
+ deprecated. Instead set the corresponding :prop_dir:`COMPILE_DEFINITIONS`
+ directory property or :prop_tgt:`COMPILE_DEFINITIONS` target property and
+ use :manual:`generator expressions <cmake-generator-expressions(7)>` like
+ ``$<CONFIG:...>`` to specify per-configuration definitions.
+ See policy :policy:`CMP0043`.
+
+* The :prop_tgt:`LOCATION` target property should no longer be read from
+ non-IMPORTED targets. It does not make sense in multi-configuration
+ generators since the build configuration is not known while configuring
+ the project. It has been superseded by the ``$<TARGET_FILE>`` generator
+ expression. See policy :policy:`CMP0026`.
+
+* The :prop_tgt:`COMPILE_FLAGS` target property is now documented
+ as deprecated, though no warning is issued. Use the
+ :prop_tgt:`COMPILE_OPTIONS` target property or the
+ :command:`target_compile_options` command instead.
+
+* The :module:`GenerateExportHeader` module ``add_compiler_export_flags``
+ function is now deprecated. It has been superseded by the
+ :prop_tgt:`<LANG>_VISIBILITY_PRESET` and
+ :prop_tgt:`VISIBILITY_INLINES_HIDDEN` target properties.
+
+Other Changes
+=============
+
+* The version scheme was changed to use only two components for
+ the feature level instead of three. The third component will
+ now be used for bug-fix releases or the date of development versions.
+ See the :variable:`CMAKE_VERSION` variable documentation for details.
+
+* The default install locations of CMake itself on Windows and
+ OS X no longer contain the CMake version number. This allows
+ for easy replacement without re-generating local build trees
+ manually.
+
+* Generators for Visual Studio 10 (2010) and later were renamed to
+ include the product year like generators for older VS versions:
+
+ - ``Visual Studio 10`` -> :generator:`Visual Studio 10 2010`
+ - ``Visual Studio 11`` -> :generator:`Visual Studio 11 2012`
+ - ``Visual Studio 12`` -> :generator:`Visual Studio 12 2013`
+
+ This clarifies which generator goes with each Visual Studio
+ version. The old names are recognized for compatibility.
+
+* The :variable:`CMAKE_<LANG>_COMPILER_ID` value for Apple-provided
+ Clang is now ``AppleClang``. It must be distinct from upstream
+ Clang because the version numbers differ.
+ See policy :policy:`CMP0025`.
+
+* The :variable:`CMAKE_<LANG>_COMPILER_ID` value for ``qcc`` on QNX
+ is now ``QCC``. It must be distinct from ``GNU`` because the
+ command-line options differ. See policy :policy:`CMP0047`.
+
+* On 64-bit OS X the :variable:`CMAKE_HOST_SYSTEM_PROCESSOR` value
+ is now correctly detected as ``x86_64`` instead of ``i386``.
+
+* On OS X, CMake learned to enable behavior specified by the
+ :prop_tgt:`MACOSX_RPATH` target property by default. This activates
+ use of ``@rpath`` for runtime shared library searches.
+ See policy :policy:`CMP0042`.
+
+* The :command:`build_command` command now returns a :manual:`cmake(1)`
+ ``--build`` command line instead of a direct invocation of the native
+ build tool. When using ``Visual Studio`` generators, CMake and CTest
+ no longer require :variable:`CMAKE_MAKE_PROGRAM` to be located up front.
+ Selection of the proper msbuild or devenv tool is now performed as
+ late as possible when the solution (``.sln``) file is available so
+ it can depend on project content.
+
+* The :manual:`cmake(1)` ``--build`` command now shares its own stdout
+ and stderr pipes with the native build tool by default.
+ The ``--use-stderr`` option that once activated this is now ignored.
+
+* The ``$<C_COMPILER_ID:...>`` and ``$<CXX_COMPILER_ID:...>``
+ :manual:`generator expressions <cmake-generator-expressions(7)>`
+ used to perform case-insensitive comparison but have now been
+ corrected to perform case-sensitive comparison.
+ See policy :policy:`CMP0044`.
+
+* The builtin ``edit_cache`` target will no longer select
+ :manual:`ccmake(1)` by default when no interactive terminal will
+ be available (e.g. with :generator:`Ninja` or an IDE generator).
+ Instead :manual:`cmake-gui(1)` will be preferred if available.
+
+* The :module:`ExternalProject` download step learned to
+ re-attempt download in certain cases to be more robust to
+ temporary network failure.
+
+* The :module:`FeatureSummary` no longer lists transitive
+ dependencies since they were not directly requested by the
+ current project.
+
+* The ``cmake-mode.el`` major Emacs editing mode has been cleaned
+ up and enhanced in several ways.
+
+* Include directories specified in the
+ :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of :ref:`Imported Targets`
+ are treated as ``SYSTEM`` includes by default when handled as
+ :ref:`usage requirements <Include Directories and Usage Requirements>`.
diff --git a/Help/release/3.1.0.rst b/Help/release/3.1.0.rst
new file mode 100644
index 0000000000..652bcd3769
--- /dev/null
+++ b/Help/release/3.1.0.rst
@@ -0,0 +1,381 @@
+CMake 3.1.0 Release Notes
+*************************
+
+.. only:: html
+
+ .. contents::
+
+Changes made since CMake 3.0.0 include the following.
+
+Documentation Changes
+=====================
+
+* A new :manual:`cmake-compile-features(7)` manual was added.
+
+New Features
+============
+
+Generators
+----------
+
+* A :generator:`Visual Studio 14` generator was added.
+
+Windows Phone and Windows Store
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+* Generators for Visual Studio 11 (2012) and above learned to generate
+ projects for Windows Phone and Windows Store. One may set the
+ :variable:`CMAKE_SYSTEM_NAME` variable to ``WindowsPhone``
+ or ``WindowsStore`` on the :manual:`cmake(1)` command-line
+ or in a :variable:`CMAKE_TOOLCHAIN_FILE` to activate these platforms.
+ Also set :variable:`CMAKE_SYSTEM_VERSION` to ``8.0`` or ``8.1`` to
+ specify the version of Windows to be targeted.
+
+NVIDIA Nsight Tegra
+^^^^^^^^^^^^^^^^^^^
+
+* Generators for Visual Studio 10 (2010) and above learned to generate
+ projects for NVIDIA Nsight Tegra Visual Studio Edition. One may set
+ the :variable:`CMAKE_SYSTEM_NAME` variable to ``Android`` on the
+ :manual:`cmake(1)` command-line or in a :variable:`CMAKE_TOOLCHAIN_FILE`
+ to activate this platform.
+
+Syntax
+------
+
+* The :manual:`cmake-language(7)` syntax for :ref:`Variable References` and
+ :ref:`Escape Sequences` was simplified in order to allow a much faster
+ implementation. See policy :policy:`CMP0053`.
+
+* The :command:`if` command no longer automatically dereferences
+ variables named in quoted or bracket arguments. See policy
+ :policy:`CMP0054`.
+
+Commands
+--------
+
+* The :command:`add_custom_command` command learned to interpret
+ :manual:`cmake-generator-expressions(7)` in arguments to ``DEPENDS``.
+
+* The :command:`export(PACKAGE)` command learned to check the
+ :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable to skip
+ exporting the package.
+
+* The :command:`file(STRINGS)` command gained a new ``ENCODING``
+ option to enable extraction of ``UTF-8`` strings.
+
+* The :command:`find_package` command learned to check the
+ :variable:`CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY` and
+ :variable:`CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY`
+ variables to skip searching the package registries.
+
+* The :command:`install` command learned a ``MESSAGE_NEVER`` option
+ to avoid output during installation.
+
+* The :command:`string` command learned a new ``GENEX_STRIP`` subcommand
+ which removes
+ :manual:`generator expression <cmake-generator-expressions(7)>`.
+
+* The :command:`string` command learned a new ``UUID`` subcommand
+ to generate a univerally unique identifier.
+
+* New :command:`target_compile_features` command allows populating the
+ :prop_tgt:`COMPILE_FEATURES` target property, just like any other
+ build variable.
+
+* The :command:`target_sources` command was added to add to the
+ :prop_tgt:`SOURCES` target property.
+
+Variables
+---------
+
+* The Visual Studio generators for versions 8 (2005) and above
+ learned to read the target platform name from a new
+ :variable:`CMAKE_GENERATOR_PLATFORM` variable when it is
+ not specified as part of the generator name. The platform
+ name may be specified on the :manual:`cmake(1)` command line
+ with the ``-A`` option, e.g. ``-G "Visual Studio 12 2013" -A x64``.
+
+* The :variable:`CMAKE_GENERATOR_TOOLSET` variable may now be
+ initialized in a toolchain file specified by the
+ :variable:`CMAKE_TOOLCHAIN_FILE` variable. This is useful
+ when cross-compiling with the Xcode or Visual Studio
+ generators.
+
+* The :variable:`CMAKE_INSTALL_MESSAGE` variable was introduced to
+ optionally reduce output installation.
+
+Properties
+----------
+
+* New :prop_tgt:`CXX_STANDARD` and :prop_tgt:`CXX_EXTENSIONS` target
+ properties may specify values which CMake uses to compute required
+ compile options such as ``-std=c++11`` or ``-std=gnu++11``. The
+ :variable:`CMAKE_CXX_STANDARD` and :variable:`CMAKE_CXX_EXTENSIONS`
+ variables may be set to initialize the target properties.
+
+* New :prop_tgt:`C_STANDARD` and :prop_tgt:`C_EXTENSIONS` target
+ properties may specify values which CMake uses to compute required
+ compile options such as ``-std=c11`` or ``-std=gnu11``. The
+ :variable:`CMAKE_C_STANDARD` and :variable:`CMAKE_C_EXTENSIONS`
+ variables may be set to initialize the target properties.
+
+* New :prop_tgt:`COMPILE_FEATURES` target property may contain a list
+ of features required to compile a target. CMake uses this
+ information to ensure that the compiler in use is capable of building
+ the target, and to add any necessary compile flags to support language
+ features.
+
+* New :prop_tgt:`COMPILE_PDB_NAME` and
+ :prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY` target properties
+ were introduced to specify the MSVC compiler program database
+ file location (``cl /Fd``). This complements the existing
+ :prop_tgt:`PDB_NAME` and :prop_tgt:`PDB_OUTPUT_DIRECTORY`
+ target properties that specify the linker program database
+ file location (``link /pdb``).
+
+* The :prop_tgt:`INTERFACE_LINK_LIBRARIES` target property now supports
+ a ``$<LINK_ONLY:...>``
+ :manual:`generator expression <cmake-generator-expressions(7)>`.
+
+* A new :prop_tgt:`INTERFACE_SOURCES` target property was introduced. This is
+ consumed by dependent targets, which compile and link the listed sources.
+
+* The :prop_tgt:`SOURCES` target property now contains
+ :manual:`generator expression <cmake-generator-expressions(7)>`
+ such as ``TARGET_OBJECTS`` when read at configure time, if
+ policy :policy:`CMP0051` is ``NEW``.
+
+* The :prop_tgt:`SOURCES` target property now generally supports
+ :manual:`generator expression <cmake-generator-expressions(7)>`. The
+ generator expressions may be used in the :command:`add_library` and
+ :command:`add_executable` commands.
+
+* It is now possible to write and append to the :prop_tgt:`SOURCES` target
+ property. The :variable:`CMAKE_DEBUG_TARGET_PROPERTIES` variable may be
+ used to trace the origin of sources.
+
+* A :prop_sf:`VS_DEPLOYMENT_CONTENT` source file property was added
+ to tell the Visual Studio generators to mark content for deployment
+ in Windows Phone and Windows Store projects.
+
+* The :prop_tgt:`VS_WINRT_COMPONENT` target property was created to
+ tell Visual Studio generators to compile a shared library as a
+ Windows Runtime (WinRT) component.
+
+* The :generator:`Xcode` generator learned to check source
+ file properties :prop_sf:`XCODE_EXPLICIT_FILE_TYPE` and
+ :prop_sf:`XCODE_LAST_KNOWN_FILE_TYPE` for a custom Xcode
+ file reference type.
+
+Modules
+-------
+
+* The :module:`BundleUtilities` module learned to resolve and replace
+ ``@rpath`` placeholders on OS X to correctly bundle applications
+ using them.
+
+* The :module:`CMakePackageConfigHelpers` module
+ :command:`configure_package_config_file` command learned a new
+ ``INSTALL_PREFIX`` option to generate package configuration files
+ meant for a prefix other than :variable:`CMAKE_INSTALL_PREFIX`.
+
+* The :module:`CheckFortranSourceCompiles` module was added to
+ provide a ``CHECK_Fortran_SOURCE_COMPILES`` macro.
+
+* The :module:`ExternalData` module learned to tolerate a ``DATA{}``
+ reference to a missing source file with a warning instead of
+ rejecting it with an error. This helps developers write new
+ ``DATA{}`` references to test reference outputs that have not
+ yet been created.
+
+* The :module:`ExternalProject` module learned to support lzma-compressed
+ source tarballs with ``.7z``, ``.tar.xz``, and ``.txz`` extensions.
+
+* The :module:`ExternalProject` module ``ExternalProject_Add`` command
+ learned a new ``BUILD_ALWAYS`` option to cause the external project
+ build step to run every time the host project is built.
+
+* The :module:`ExternalProject` module ``ExternalProject_Add`` command
+ learned a new ``EXCLUDE_FROM_ALL`` option to cause the external
+ project target to have the :prop_tgt:`EXCLUDE_FROM_ALL` target
+ property set.
+
+* The :module:`ExternalProject` module ``ExternalProject_Add_Step`` command
+ learned a new ``EXCLUDE_FROM_MAIN`` option to cause the step to not be
+ a direct dependency of the main external project target.
+
+* The :module:`ExternalProject` module ``ExternalProject_Add`` command
+ learned a new ``DOWNLOAD_NO_PROGRESS`` option to disable progress
+ output while downloading the source tarball.
+
+* The :module:`FeatureSummary` module ``feature_summary`` API
+ learned to accept multiple values for the ``WHAT`` option and
+ combine them appropriately.
+
+* The :module:`FindCUDA` module learned to support ``fatbin`` and ``cubin``
+ modules.
+
+* The :module:`FindGTest` module ``gtest_add_tests`` macro learned
+ a new ``AUTO`` option to automatically read the :prop_tgt:`SOURCES`
+ target property of the test executable and scan the source files
+ for tests to be added.
+
+* The :module:`FindGLEW` module now provides imported targets.
+
+* The :module:`FindGLUT` module now provides imported targets.
+
+* The :module:`FindHg` module gained a new ``Hg_WC_INFO`` macro to
+ help run ``hg`` to extract information about a Mercurial work copy.
+
+* The :module:`FindOpenCL` module was introduced.
+
+* The :module:`FindOpenGL` module now provides imported targets
+ ``OpenGL::GL`` and ``OpenGL::GLU`` when the libraries are found.
+
+* The :module:`FindOpenMP` module learned to support Fortran.
+
+* The :module:`FindPkgConfig` module learned to use the ``PKG_CONFIG``
+ environment variable value as the ``pkg-config`` executable, if set.
+
+* The :module:`FindVTK` module dropped support for finding VTK 4.0.
+ It is now a thin-wrapper around ``find_package(VTK ... NO_MODULE)``.
+ This produces much clearer error messages when VTK is not found.
+
+* The :module:`FindZLIB` module now provides imported targets.
+
+* The :module:`GenerateExportHeader` module ``generate_export_header``
+ function learned to allow use with :ref:`Object Libraries`.
+
+* The :module:`InstallRequiredSystemLibraries` module gained a new
+ ``CMAKE_INSTALL_OPENMP_LIBRARIES`` option to install MSVC OpenMP
+ runtime libraries.
+
+* The :module:`UseSWIG` module learned to detect the module name
+ from ``.i`` source files if possible to avoid the need to set
+ the ``SWIG_MODULE_NAME`` source file property explicitly.
+
+* The :module:`WriteCompilerDetectionHeader` module was added to allow
+ creation of a portable header file for compiler optional feature detection.
+
+Generator Expressions
+---------------------
+
+* New ``COMPILE_FEATURES``
+ :manual:`generator expression <cmake-generator-expressions(7)>` allows
+ setting build properties based on available compiler features.
+
+CTest
+-----
+
+* The :command:`ctest_coverage` command learned to read variable
+ ``CTEST_COVERAGE_EXTRA_FLAGS`` to set ``CoverageExtraFlags``.
+
+* The :command:`ctest_coverage` command learned to support
+ Intel coverage files with the ``codecov`` tool.
+
+* The :command:`ctest_memcheck` command learned to support sanitizer
+ modes, including ``AddressSanitizer``, ``MemorySanitizer``,
+ ``ThreadSanitizer``, and ``UndefinedBehaviorSanitizer``.
+ Options may be set using the new
+ :variable:`CTEST_MEMORYCHECK_SANITIZER_OPTIONS` variable.
+
+CPack
+-----
+
+* :manual:`cpack(1)` gained an ``IFW`` generator to package using
+ Qt Framework Installer tools. See the :module:`CPackIFW` module.
+
+* :manual:`cpack(1)` gained ``7Z`` and ``TXZ`` generators supporting
+ lzma-compressed archives.
+
+* The :module:`CPackDeb` module learned a new
+ :variable:`CPACK_DEBIAN_COMPRESSION_TYPE` variable to set the
+ tarball compression type.
+
+* The :manual:`cpack(1)` ``WiX`` generator learned to support
+ a :prop_inst:`CPACK_WIX_ACL` installed file property to
+ specify an Access Control List.
+
+Other
+-----
+
+* The :manual:`cmake(1)` ``-E`` option learned a new ``env`` command.
+
+* The :manual:`cmake(1)` ``-E tar`` command learned to support
+ lzma-compressed files.
+
+* :ref:`Object Libraries` may now have extra sources that do not
+ compile to object files so long as they would not affect linking
+ of a normal library (e.g. ``.dat`` is okay but not ``.def``).
+
+* Visual Studio generators for VS 8 and later learned to support
+ the ``ASM_MASM`` language.
+
+* The Visual Studio generators learned to treat ``.hlsl`` source
+ files as High Level Shading Language sources (using ``FXCompile``
+ in ``.vcxproj`` files). A :prop_sf:`VS_SHADER_TYPE` source file
+ property was added to specify the Shader Type.
+
+New Diagnostics
+===============
+
+* Policy :policy:`CMP0052` introduced to control directories in the
+ :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of exported targets.
+
+Deprecated and Removed Features
+===============================
+
+* In CMake 3.0 the :command:`target_link_libraries` command
+ accidentally began allowing unquoted arguments to use
+ :manual:`generator expressions <cmake-generator-expressions(7)>`
+ containing a (``;`` separated) list within them. For example::
+
+ set(libs B C)
+ target_link_libraries(A PUBLIC $<BUILD_INTERFACE:${libs}>)
+
+ This is equivalent to writing::
+
+ target_link_libraries(A PUBLIC $<BUILD_INTERFACE:B C>)
+
+ and was never intended to work. It did not work in CMake 2.8.12.
+ Such generator expressions should be in quoted arguments::
+
+ set(libs B C)
+ target_link_libraries(A PUBLIC "$<BUILD_INTERFACE:${libs}>")
+
+ CMake 3.1 again requires the quotes for this to work correctly.
+
+* Callbacks established by the :command:`variable_watch` command will no
+ longer receive the ``ALLOWED_UNKNOWN_READ_ACCESS`` access type when
+ the undocumented ``CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS`` variable is
+ set. Uninitialized variable accesses will always be reported as
+ ``UNKNOWN_READ_ACCESS``.
+
+* The :module:`CMakeDetermineVSServicePack` module now warns that
+ it is deprecated and should not longer be used. Use the
+ :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable instead.
+
+Other Changes
+=============
+
+* The :manual:`cmake-gui(1)` learned to capture output from child
+ processes started by the :command:`execute_process` command
+ and display it in the output window.
+
+* The :manual:`cmake-language(7)` internal implementation of generator
+ expression and list expansion parsers have been optimized and shows
+ non-trivial speedup on large projects.
+
+* The Makefile generators learned to use response files with GNU tools
+ on Windows to pass library directories and names to the linker.
+
+* When generating linker command-lines, CMake now avoids repeating
+ items corresponding to SHARED library targets.
+
+* Support for the Open Watcom compiler has been overhauled.
+ The :variable:`CMAKE_<LANG>_COMPILER_ID` is now ``OpenWatcom``,
+ and the :variable:`CMAKE_<LANG>_COMPILER_VERSION` now uses
+ the Open Watcom external version numbering. The external
+ version numbers are lower than the internal version number
+ by 11.
diff --git a/Help/release/dev.txt b/Help/release/dev.txt
new file mode 100644
index 0000000000..2cf9193e1c
--- /dev/null
+++ b/Help/release/dev.txt
@@ -0,0 +1,16 @@
+..
+ This file should be included by the adjacent "index.rst"
+ in development versions but not in release versions.
+
+Changes Since Release
+=====================
+
+The following noteworthy changes have been made in this development
+version since the preceding release but have not yet been consolidated
+into notes for a specific release version:
+
+.. toctree::
+ :maxdepth: 1
+ :glob:
+
+ dev/*
diff --git a/Help/release/dev/0-sample-topic.rst b/Help/release/dev/0-sample-topic.rst
new file mode 100644
index 0000000000..e4cc01e23f
--- /dev/null
+++ b/Help/release/dev/0-sample-topic.rst
@@ -0,0 +1,7 @@
+0-sample-topic
+--------------
+
+* This is a sample release note for the change in a topic.
+ Developers should add similar notes for each topic branch
+ making a noteworthy change. Each document should be named
+ and titled to match the topic name to avoid merge conflicts.
diff --git a/Help/release/index.rst b/Help/release/index.rst
new file mode 100644
index 0000000000..abc19b8e8f
--- /dev/null
+++ b/Help/release/index.rst
@@ -0,0 +1,17 @@
+CMake Release Notes
+*******************
+
+..
+ This file should include the adjacent "dev.txt" file
+ in development versions but not in release versions.
+
+.. include:: dev.txt
+
+Releases
+========
+
+.. toctree::
+ :maxdepth: 1
+
+ 3.1.0 <3.1.0>
+ 3.0.0 <3.0.0>
diff --git a/Help/variable/APPLE.rst b/Help/variable/APPLE.rst
new file mode 100644
index 0000000000..3afdee867d
--- /dev/null
+++ b/Help/variable/APPLE.rst
@@ -0,0 +1,6 @@
+APPLE
+-----
+
+True if running on Mac OS X.
+
+Set to true on Mac OS X.
diff --git a/Help/variable/BORLAND.rst b/Help/variable/BORLAND.rst
new file mode 100644
index 0000000000..4af6085bf9
--- /dev/null
+++ b/Help/variable/BORLAND.rst
@@ -0,0 +1,6 @@
+BORLAND
+-------
+
+True if the Borland compiler is being used.
+
+This is set to true if the Borland compiler is being used.
diff --git a/Help/variable/BUILD_SHARED_LIBS.rst b/Help/variable/BUILD_SHARED_LIBS.rst
new file mode 100644
index 0000000000..6f30efba14
--- /dev/null
+++ b/Help/variable/BUILD_SHARED_LIBS.rst
@@ -0,0 +1,10 @@
+BUILD_SHARED_LIBS
+-----------------
+
+Global flag to cause add_library to create shared libraries if on.
+
+If present and true, this will cause all libraries to be built shared
+unless the library was explicitly added as a static library. This
+variable is often added to projects as an OPTION so that each user of
+a project can decide if they want to build the project using shared or
+static libraries.
diff --git a/Help/variable/CMAKE_ABSOLUTE_DESTINATION_FILES.rst b/Help/variable/CMAKE_ABSOLUTE_DESTINATION_FILES.rst
new file mode 100644
index 0000000000..36914536c2
--- /dev/null
+++ b/Help/variable/CMAKE_ABSOLUTE_DESTINATION_FILES.rst
@@ -0,0 +1,9 @@
+CMAKE_ABSOLUTE_DESTINATION_FILES
+--------------------------------
+
+List of files which have been installed using an ABSOLUTE DESTINATION path.
+
+This variable is defined by CMake-generated cmake_install.cmake
+scripts. It can be used (read-only) by programs or scripts that
+source those install scripts. This is used by some CPack generators
+(e.g. RPM).
diff --git a/Help/variable/CMAKE_ANDROID_API.rst b/Help/variable/CMAKE_ANDROID_API.rst
new file mode 100644
index 0000000000..c8264e0f8e
--- /dev/null
+++ b/Help/variable/CMAKE_ANDROID_API.rst
@@ -0,0 +1,5 @@
+CMAKE_ANDROID_API
+-----------------
+
+Default value for the :prop_tgt:`ANDROID_API` target property.
+See that target property for additional information.
diff --git a/Help/variable/CMAKE_ANDROID_GUI.rst b/Help/variable/CMAKE_ANDROID_GUI.rst
new file mode 100644
index 0000000000..175537527d
--- /dev/null
+++ b/Help/variable/CMAKE_ANDROID_GUI.rst
@@ -0,0 +1,5 @@
+CMAKE_ANDROID_GUI
+-----------------
+
+Default value for the :prop_tgt:`ANDROID_GUI` target property of
+executables. See that target property for additional information.
diff --git a/Help/variable/CMAKE_APPBUNDLE_PATH.rst b/Help/variable/CMAKE_APPBUNDLE_PATH.rst
new file mode 100644
index 0000000000..469b3162ba
--- /dev/null
+++ b/Help/variable/CMAKE_APPBUNDLE_PATH.rst
@@ -0,0 +1,5 @@
+CMAKE_APPBUNDLE_PATH
+--------------------
+
+Search path for OS X application bundles used by the :command:`find_program`,
+and :command:`find_package` commands.
diff --git a/Help/variable/CMAKE_AR.rst b/Help/variable/CMAKE_AR.rst
new file mode 100644
index 0000000000..5893677ff8
--- /dev/null
+++ b/Help/variable/CMAKE_AR.rst
@@ -0,0 +1,7 @@
+CMAKE_AR
+--------
+
+Name of archiving tool for static libraries.
+
+This specifies the name of the program that creates archive or static
+libraries.
diff --git a/Help/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY.rst b/Help/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..6a22f73528
--- /dev/null
+++ b/Help/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,8 @@
+CMAKE_ARCHIVE_OUTPUT_DIRECTORY
+------------------------------
+
+Where to put all the ARCHIVE targets when built.
+
+This variable is used to initialize the ARCHIVE_OUTPUT_DIRECTORY
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_ARGC.rst b/Help/variable/CMAKE_ARGC.rst
new file mode 100644
index 0000000000..be120b8fed
--- /dev/null
+++ b/Help/variable/CMAKE_ARGC.rst
@@ -0,0 +1,7 @@
+CMAKE_ARGC
+----------
+
+Number of command line arguments passed to CMake in script mode.
+
+When run in -P script mode, CMake sets this variable to the number of
+command line arguments. See also CMAKE_ARGV0, 1, 2 ...
diff --git a/Help/variable/CMAKE_ARGV0.rst b/Help/variable/CMAKE_ARGV0.rst
new file mode 100644
index 0000000000..e5ed419637
--- /dev/null
+++ b/Help/variable/CMAKE_ARGV0.rst
@@ -0,0 +1,9 @@
+CMAKE_ARGV0
+-----------
+
+Command line argument passed to CMake in script mode.
+
+When run in -P script mode, CMake sets this variable to the first
+command line argument. It then also sets CMAKE_ARGV1, CMAKE_ARGV2,
+... and so on, up to the number of command line arguments given. See
+also CMAKE_ARGC.
diff --git a/Help/variable/CMAKE_AUTOMOC.rst b/Help/variable/CMAKE_AUTOMOC.rst
new file mode 100644
index 0000000000..02e5eb57aa
--- /dev/null
+++ b/Help/variable/CMAKE_AUTOMOC.rst
@@ -0,0 +1,7 @@
+CMAKE_AUTOMOC
+-------------
+
+Whether to handle ``moc`` automatically for Qt targets.
+
+This variable is used to initialize the :prop_tgt:`AUTOMOC` property on all the
+targets. See that target property for additional information.
diff --git a/Help/variable/CMAKE_AUTOMOC_MOC_OPTIONS.rst b/Help/variable/CMAKE_AUTOMOC_MOC_OPTIONS.rst
new file mode 100644
index 0000000000..09bf5cd2fc
--- /dev/null
+++ b/Help/variable/CMAKE_AUTOMOC_MOC_OPTIONS.rst
@@ -0,0 +1,7 @@
+CMAKE_AUTOMOC_MOC_OPTIONS
+-------------------------
+
+Additional options for ``moc`` when using :variable:`CMAKE_AUTOMOC`.
+
+This variable is used to initialize the :prop_tgt:`AUTOMOC_MOC_OPTIONS` property
+on all the targets. See that target property for additional information.
diff --git a/Help/variable/CMAKE_AUTOMOC_RELAXED_MODE.rst b/Help/variable/CMAKE_AUTOMOC_RELAXED_MODE.rst
new file mode 100644
index 0000000000..a814d408b3
--- /dev/null
+++ b/Help/variable/CMAKE_AUTOMOC_RELAXED_MODE.rst
@@ -0,0 +1,13 @@
+CMAKE_AUTOMOC_RELAXED_MODE
+--------------------------
+
+Switch between strict and relaxed automoc mode.
+
+By default, :prop_tgt:`AUTOMOC` behaves exactly as described in the documentation
+of the :prop_tgt:`AUTOMOC` target property. When set to ``TRUE``, it accepts more
+input and tries to find the correct input file for ``moc`` even if it
+differs from the documented behaviour. In this mode it e.g. also
+checks whether a header file is intended to be processed by moc when a
+``"foo.moc"`` file has been included.
+
+Relaxed mode has to be enabled for KDE4 compatibility.
diff --git a/Help/variable/CMAKE_AUTORCC.rst b/Help/variable/CMAKE_AUTORCC.rst
new file mode 100644
index 0000000000..067f766115
--- /dev/null
+++ b/Help/variable/CMAKE_AUTORCC.rst
@@ -0,0 +1,7 @@
+CMAKE_AUTORCC
+-------------
+
+Whether to handle ``rcc`` automatically for Qt targets.
+
+This variable is used to initialize the :prop_tgt:`AUTORCC` property on all the targets.
+See that target property for additional information.
diff --git a/Help/variable/CMAKE_AUTORCC_OPTIONS.rst b/Help/variable/CMAKE_AUTORCC_OPTIONS.rst
new file mode 100644
index 0000000000..298cb6be70
--- /dev/null
+++ b/Help/variable/CMAKE_AUTORCC_OPTIONS.rst
@@ -0,0 +1,7 @@
+CMAKE_AUTORCC_OPTIONS
+---------------------
+
+Whether to handle ``rcc`` automatically for Qt targets.
+
+This variable is used to initialize the :prop_tgt:`AUTORCC_OPTIONS` property on
+all the targets. See that target property for additional information.
diff --git a/Help/variable/CMAKE_AUTOUIC.rst b/Help/variable/CMAKE_AUTOUIC.rst
new file mode 100644
index 0000000000..0beb55590e
--- /dev/null
+++ b/Help/variable/CMAKE_AUTOUIC.rst
@@ -0,0 +1,7 @@
+CMAKE_AUTOUIC
+-------------
+
+Whether to handle ``uic`` automatically for Qt targets.
+
+This variable is used to initialize the :prop_tgt:`AUTOUIC` property on all the targets.
+See that target property for additional information.
diff --git a/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst b/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst
new file mode 100644
index 0000000000..3c9b8c4f5d
--- /dev/null
+++ b/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst
@@ -0,0 +1,7 @@
+CMAKE_AUTOUIC_OPTIONS
+---------------------
+
+Whether to handle ``uic`` automatically for Qt targets.
+
+This variable is used to initialize the :prop_tgt:`AUTOUIC_OPTIONS` property on
+all the targets. See that target property for additional information.
diff --git a/Help/variable/CMAKE_BACKWARDS_COMPATIBILITY.rst b/Help/variable/CMAKE_BACKWARDS_COMPATIBILITY.rst
new file mode 100644
index 0000000000..05c366a950
--- /dev/null
+++ b/Help/variable/CMAKE_BACKWARDS_COMPATIBILITY.rst
@@ -0,0 +1,4 @@
+CMAKE_BACKWARDS_COMPATIBILITY
+-----------------------------
+
+Deprecated. See CMake Policy :policy:`CMP0001` documentation.
diff --git a/Help/variable/CMAKE_BINARY_DIR.rst b/Help/variable/CMAKE_BINARY_DIR.rst
new file mode 100644
index 0000000000..703bb58c7f
--- /dev/null
+++ b/Help/variable/CMAKE_BINARY_DIR.rst
@@ -0,0 +1,8 @@
+CMAKE_BINARY_DIR
+----------------
+
+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
+CMAKE_SOURCE_DIR.
diff --git a/Help/variable/CMAKE_BUILD_TOOL.rst b/Help/variable/CMAKE_BUILD_TOOL.rst
new file mode 100644
index 0000000000..61334917bb
--- /dev/null
+++ b/Help/variable/CMAKE_BUILD_TOOL.rst
@@ -0,0 +1,6 @@
+CMAKE_BUILD_TOOL
+----------------
+
+This variable exists only for backwards compatibility.
+It contains the same value as :variable:`CMAKE_MAKE_PROGRAM`.
+Use that variable instead.
diff --git a/Help/variable/CMAKE_BUILD_TYPE.rst b/Help/variable/CMAKE_BUILD_TYPE.rst
new file mode 100644
index 0000000000..68f08baba0
--- /dev/null
+++ b/Help/variable/CMAKE_BUILD_TYPE.rst
@@ -0,0 +1,19 @@
+CMAKE_BUILD_TYPE
+----------------
+
+Specifies the build type on single-configuration generators.
+
+This statically specifies what build type (configuration) will be
+built in this build tree. Possible values are empty, Debug, Release,
+RelWithDebInfo and MinSizeRel. This variable is only meaningful to
+single-configuration generators (such as make and Ninja) i.e. those
+which choose a single configuration when CMake runs to generate a
+build tree as opposed to multi-configuration generators which offer
+selection of the build configuration within the generated build
+environment. There are many per-config properties and variables
+(usually following clean SOME_VAR_<CONFIG> order conventions), such as
+CMAKE_C_FLAGS_<CONFIG>, specified as uppercase:
+CMAKE_C_FLAGS_[DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL]. For example,
+in a build tree configured to build type Debug, CMake will see to
+having CMAKE_C_FLAGS_DEBUG settings get added to the CMAKE_C_FLAGS
+settings. See also CMAKE_CONFIGURATION_TYPES.
diff --git a/Help/variable/CMAKE_BUILD_WITH_INSTALL_RPATH.rst b/Help/variable/CMAKE_BUILD_WITH_INSTALL_RPATH.rst
new file mode 100644
index 0000000000..6875da6aa8
--- /dev/null
+++ b/Help/variable/CMAKE_BUILD_WITH_INSTALL_RPATH.rst
@@ -0,0 +1,11 @@
+CMAKE_BUILD_WITH_INSTALL_RPATH
+------------------------------
+
+Use the install path for the RPATH
+
+Normally CMake uses the build tree for the RPATH when building
+executables etc on systems that use RPATH. When the software is
+installed the executables etc are relinked by CMake to have the
+install RPATH. If this variable is set to true then the software is
+always built with the install path for the RPATH and does not need to
+be relinked when installed.
diff --git a/Help/variable/CMAKE_CACHEFILE_DIR.rst b/Help/variable/CMAKE_CACHEFILE_DIR.rst
new file mode 100644
index 0000000000..78c7d93d12
--- /dev/null
+++ b/Help/variable/CMAKE_CACHEFILE_DIR.rst
@@ -0,0 +1,7 @@
+CMAKE_CACHEFILE_DIR
+-------------------
+
+The directory with the CMakeCache.txt file.
+
+This is the full path to the directory that has the CMakeCache.txt
+file in it. This is the same as CMAKE_BINARY_DIR.
diff --git a/Help/variable/CMAKE_CACHE_MAJOR_VERSION.rst b/Help/variable/CMAKE_CACHE_MAJOR_VERSION.rst
new file mode 100644
index 0000000000..e6887d9ed1
--- /dev/null
+++ b/Help/variable/CMAKE_CACHE_MAJOR_VERSION.rst
@@ -0,0 +1,8 @@
+CMAKE_CACHE_MAJOR_VERSION
+-------------------------
+
+Major version of CMake used to create the CMakeCache.txt file
+
+This stores the major version of CMake used to write a CMake cache
+file. It is only different when a different version of CMake is run
+on a previously created cache file.
diff --git a/Help/variable/CMAKE_CACHE_MINOR_VERSION.rst b/Help/variable/CMAKE_CACHE_MINOR_VERSION.rst
new file mode 100644
index 0000000000..799f0a98a0
--- /dev/null
+++ b/Help/variable/CMAKE_CACHE_MINOR_VERSION.rst
@@ -0,0 +1,8 @@
+CMAKE_CACHE_MINOR_VERSION
+-------------------------
+
+Minor version of CMake used to create the CMakeCache.txt file
+
+This stores the minor version of CMake used to write a CMake cache
+file. It is only different when a different version of CMake is run
+on a previously created cache file.
diff --git a/Help/variable/CMAKE_CACHE_PATCH_VERSION.rst b/Help/variable/CMAKE_CACHE_PATCH_VERSION.rst
new file mode 100644
index 0000000000..e67d5444ec
--- /dev/null
+++ b/Help/variable/CMAKE_CACHE_PATCH_VERSION.rst
@@ -0,0 +1,8 @@
+CMAKE_CACHE_PATCH_VERSION
+-------------------------
+
+Patch version of CMake used to create the CMakeCache.txt file
+
+This stores the patch version of CMake used to write a CMake cache
+file. It is only different when a different version of CMake is run
+on a previously created cache file.
diff --git a/Help/variable/CMAKE_CFG_INTDIR.rst b/Help/variable/CMAKE_CFG_INTDIR.rst
new file mode 100644
index 0000000000..20435e590b
--- /dev/null
+++ b/Help/variable/CMAKE_CFG_INTDIR.rst
@@ -0,0 +1,45 @@
+CMAKE_CFG_INTDIR
+----------------
+
+Build-time reference to per-configuration output subdirectory.
+
+For native build systems supporting multiple configurations in the
+build tree (such as Visual Studio and Xcode), the value is a reference
+to a build-time variable specifying the name of the per-configuration
+output subdirectory. On Makefile generators this evaluates to "."
+because there is only one configuration in a build tree. Example
+values:
+
+::
+
+ $(IntDir) = Visual Studio 6
+ $(OutDir) = Visual Studio 7, 8, 9
+ $(Configuration) = Visual Studio 10
+ $(CONFIGURATION) = Xcode
+ . = Make-based tools
+
+Since these values are evaluated by the native build system, this
+variable is suitable only for use in command lines that will be
+evaluated at build time. Example of intended usage:
+
+::
+
+ add_executable(mytool mytool.c)
+ add_custom_command(
+ OUTPUT out.txt
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/mytool
+ ${CMAKE_CURRENT_SOURCE_DIR}/in.txt out.txt
+ DEPENDS mytool in.txt
+ )
+ add_custom_target(drive ALL DEPENDS out.txt)
+
+Note that CMAKE_CFG_INTDIR is no longer necessary for this purpose but
+has been left for compatibility with existing projects. Instead
+add_custom_command() recognizes executable target names in its COMMAND
+option, so "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/mytool"
+can be replaced by just "mytool".
+
+This variable is read-only. Setting it is undefined behavior. In
+multi-configuration build systems the value of this variable is passed
+as the value of preprocessor symbol "CMAKE_INTDIR" to the compilation
+of all source files.
diff --git a/Help/variable/CMAKE_CL_64.rst b/Help/variable/CMAKE_CL_64.rst
new file mode 100644
index 0000000000..5096829618
--- /dev/null
+++ b/Help/variable/CMAKE_CL_64.rst
@@ -0,0 +1,6 @@
+CMAKE_CL_64
+-----------
+
+Using the 64 bit compiler from Microsoft
+
+Set to true when using the 64 bit cl compiler from Microsoft.
diff --git a/Help/variable/CMAKE_COLOR_MAKEFILE.rst b/Help/variable/CMAKE_COLOR_MAKEFILE.rst
new file mode 100644
index 0000000000..170baf3b2e
--- /dev/null
+++ b/Help/variable/CMAKE_COLOR_MAKEFILE.rst
@@ -0,0 +1,7 @@
+CMAKE_COLOR_MAKEFILE
+--------------------
+
+Enables color output when using the Makefile generator.
+
+When enabled, the generated Makefiles will produce colored output.
+Default is ON.
diff --git a/Help/variable/CMAKE_COMMAND.rst b/Help/variable/CMAKE_COMMAND.rst
new file mode 100644
index 0000000000..f4e5f1e441
--- /dev/null
+++ b/Help/variable/CMAKE_COMMAND.rst
@@ -0,0 +1,8 @@
+CMAKE_COMMAND
+-------------
+
+The full path to the cmake executable.
+
+This is the full path to the CMake executable cmake which is useful
+from custom commands that want to use the cmake -E option for portable
+system commands. (e.g. /usr/local/bin/cmake
diff --git a/Help/variable/CMAKE_COMPILER_2005.rst b/Help/variable/CMAKE_COMPILER_2005.rst
new file mode 100644
index 0000000000..134559b6cd
--- /dev/null
+++ b/Help/variable/CMAKE_COMPILER_2005.rst
@@ -0,0 +1,6 @@
+CMAKE_COMPILER_2005
+-------------------
+
+Using the Visual Studio 2005 compiler from Microsoft
+
+Set to true when using the Visual Studio 2005 compiler from Microsoft.
diff --git a/Help/variable/CMAKE_COMPILER_IS_GNULANG.rst b/Help/variable/CMAKE_COMPILER_IS_GNULANG.rst
new file mode 100644
index 0000000000..bc5652f008
--- /dev/null
+++ b/Help/variable/CMAKE_COMPILER_IS_GNULANG.rst
@@ -0,0 +1,15 @@
+CMAKE_COMPILER_IS_GNU<LANG>
+---------------------------
+
+True if the compiler is GNU.
+
+If the selected <LANG> compiler is the GNU compiler then this is TRUE,
+if not it is FALSE. Unlike the other per-language variables, this
+uses the GNU syntax for identifying languages instead of the CMake
+syntax. Recognized values of the <LANG> suffix are:
+
+::
+
+ CC = C compiler
+ CXX = C++ compiler
+ G77 = Fortran compiler
diff --git a/Help/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY.rst b/Help/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..ea33c7d646
--- /dev/null
+++ b/Help/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,8 @@
+CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY
+----------------------------------
+
+Output directory for MS debug symbol ``.pdb`` files
+generated by the compiler while building source files.
+
+This variable is used to initialize the
+:prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY` property on all the targets.
diff --git a/Help/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst b/Help/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst
new file mode 100644
index 0000000000..fdeb9abdd3
--- /dev/null
+++ b/Help/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst
@@ -0,0 +1,11 @@
+CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>
+-------------------------------------------
+
+Per-configuration output directory for MS debug symbol ``.pdb`` files
+generated by the compiler while building source files.
+
+This is a per-configuration version of
+:variable:`CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY`.
+This variable is used to initialize the
+:prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>`
+property on all the targets.
diff --git a/Help/variable/CMAKE_CONFIGURATION_TYPES.rst b/Help/variable/CMAKE_CONFIGURATION_TYPES.rst
new file mode 100644
index 0000000000..986b969ee3
--- /dev/null
+++ b/Help/variable/CMAKE_CONFIGURATION_TYPES.rst
@@ -0,0 +1,10 @@
+CMAKE_CONFIGURATION_TYPES
+-------------------------
+
+Specifies the available build types on multi-config generators.
+
+This specifies what build types (configurations) will be available
+such as Debug, Release, RelWithDebInfo etc. This has reasonable
+defaults on most platforms, but can be extended to provide other build
+types. See also CMAKE_BUILD_TYPE for details of managing
+configuration data, and CMAKE_CFG_INTDIR.
diff --git a/Help/variable/CMAKE_CONFIG_POSTFIX.rst b/Help/variable/CMAKE_CONFIG_POSTFIX.rst
new file mode 100644
index 0000000000..af38bed4b2
--- /dev/null
+++ b/Help/variable/CMAKE_CONFIG_POSTFIX.rst
@@ -0,0 +1,7 @@
+CMAKE_<CONFIG>_POSTFIX
+----------------------
+
+Default filename postfix for libraries under configuration <CONFIG>.
+
+When a non-executable target is created its <CONFIG>_POSTFIX target
+property is initialized with the value of this variable if it is set.
diff --git a/Help/variable/CMAKE_CROSSCOMPILING.rst b/Help/variable/CMAKE_CROSSCOMPILING.rst
new file mode 100644
index 0000000000..cf9865b619
--- /dev/null
+++ b/Help/variable/CMAKE_CROSSCOMPILING.rst
@@ -0,0 +1,8 @@
+CMAKE_CROSSCOMPILING
+--------------------
+
+Is CMake currently cross compiling.
+
+This variable will be set to true by CMake if CMake is cross
+compiling. Specifically if the build platform is different from the
+target platform.
diff --git a/Help/variable/CMAKE_CTEST_COMMAND.rst b/Help/variable/CMAKE_CTEST_COMMAND.rst
new file mode 100644
index 0000000000..d5dd2c3bb8
--- /dev/null
+++ b/Help/variable/CMAKE_CTEST_COMMAND.rst
@@ -0,0 +1,8 @@
+CMAKE_CTEST_COMMAND
+-------------------
+
+Full path to ctest command installed with cmake.
+
+This is the full path to the CTest executable ctest which is useful
+from custom commands that want to use the cmake -E option for portable
+system commands.
diff --git a/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst b/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst
new file mode 100644
index 0000000000..fb55a11c66
--- /dev/null
+++ b/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst
@@ -0,0 +1,10 @@
+CMAKE_CURRENT_BINARY_DIR
+------------------------
+
+The path to the binary directory currently being processed.
+
+This the full path to the build directory that is currently being
+processed by cmake. Each directory added by 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.
diff --git a/Help/variable/CMAKE_CURRENT_LIST_DIR.rst b/Help/variable/CMAKE_CURRENT_LIST_DIR.rst
new file mode 100644
index 0000000000..b8168211cc
--- /dev/null
+++ b/Help/variable/CMAKE_CURRENT_LIST_DIR.rst
@@ -0,0 +1,17 @@
+CMAKE_CURRENT_LIST_DIR
+----------------------
+
+Full directory of the listfile currently being processed.
+
+As CMake processes the listfiles in your project this variable will
+always be set to the directory where the listfile which is currently
+being processed (CMAKE_CURRENT_LIST_FILE) is located. The value has
+dynamic scope. When CMake starts processing commands in a source file
+it sets this variable to the directory where this file is located.
+When CMake finishes processing commands from the file it restores the
+previous value. Therefore the value of the variable inside a macro or
+function is the directory of the file invoking the bottom-most entry
+on the call stack, not the directory of the file containing the macro
+or function definition.
+
+See also CMAKE_CURRENT_LIST_FILE.
diff --git a/Help/variable/CMAKE_CURRENT_LIST_FILE.rst b/Help/variable/CMAKE_CURRENT_LIST_FILE.rst
new file mode 100644
index 0000000000..910d7b4557
--- /dev/null
+++ b/Help/variable/CMAKE_CURRENT_LIST_FILE.rst
@@ -0,0 +1,15 @@
+CMAKE_CURRENT_LIST_FILE
+-----------------------
+
+Full path to the listfile currently being processed.
+
+As CMake processes the listfiles in your project this variable will
+always be set to the one currently being processed. The value has
+dynamic scope. When CMake starts processing commands in a source file
+it sets this variable to the location of the file. When CMake
+finishes processing commands from the file it restores the previous
+value. Therefore the value of the variable inside a macro or function
+is the file invoking the bottom-most entry on the call stack, not the
+file containing the macro or function definition.
+
+See also CMAKE_PARENT_LIST_FILE.
diff --git a/Help/variable/CMAKE_CURRENT_LIST_LINE.rst b/Help/variable/CMAKE_CURRENT_LIST_LINE.rst
new file mode 100644
index 0000000000..60e8e26ce6
--- /dev/null
+++ b/Help/variable/CMAKE_CURRENT_LIST_LINE.rst
@@ -0,0 +1,7 @@
+CMAKE_CURRENT_LIST_LINE
+-----------------------
+
+The line number of the current file being processed.
+
+This is the line number of the file currently being processed by
+cmake.
diff --git a/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst b/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst
new file mode 100644
index 0000000000..db063a4b7d
--- /dev/null
+++ b/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst
@@ -0,0 +1,7 @@
+CMAKE_CURRENT_SOURCE_DIR
+------------------------
+
+The path to the source directory currently being processed.
+
+This the full path to the source directory that is currently being
+processed by cmake.
diff --git a/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst b/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst
new file mode 100644
index 0000000000..460c78ccc5
--- /dev/null
+++ b/Help/variable/CMAKE_CXX_COMPILE_FEATURES.rst
@@ -0,0 +1,11 @@
+CMAKE_CXX_COMPILE_FEATURES
+--------------------------
+
+List of features known to the C++ compiler
+
+These features are known to be available for use with the C++ compiler. This
+list is a subset of the features listed in the :prop_gbl:`CMAKE_CXX_KNOWN_FEATURES`
+global property.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
diff --git a/Help/variable/CMAKE_CXX_EXTENSIONS.rst b/Help/variable/CMAKE_CXX_EXTENSIONS.rst
new file mode 100644
index 0000000000..64483713e4
--- /dev/null
+++ b/Help/variable/CMAKE_CXX_EXTENSIONS.rst
@@ -0,0 +1,11 @@
+CMAKE_CXX_EXTENSIONS
+--------------------
+
+Default value for ``CXX_EXTENSIONS`` property of targets.
+
+This variable is used to initialize the :prop_tgt:`CXX_EXTENSIONS`
+property on all targets. See that target property for additional
+information.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
diff --git a/Help/variable/CMAKE_CXX_STANDARD.rst b/Help/variable/CMAKE_CXX_STANDARD.rst
new file mode 100644
index 0000000000..963a42a409
--- /dev/null
+++ b/Help/variable/CMAKE_CXX_STANDARD.rst
@@ -0,0 +1,11 @@
+CMAKE_CXX_STANDARD
+------------------
+
+Default value for ``CXX_STANDARD`` property of targets.
+
+This variable is used to initialize the :prop_tgt:`CXX_STANDARD`
+property on all targets. See that target property for additional
+information.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
diff --git a/Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst b/Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst
new file mode 100644
index 0000000000..f7750fa0ec
--- /dev/null
+++ b/Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst
@@ -0,0 +1,11 @@
+CMAKE_CXX_STANDARD_REQUIRED
+---------------------------
+
+Default value for ``CXX_STANDARD_REQUIRED`` property of targets.
+
+This variable is used to initialize the :prop_tgt:`CXX_STANDARD_REQUIRED`
+property on all targets. See that target property for additional
+information.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
diff --git a/Help/variable/CMAKE_C_COMPILE_FEATURES.rst b/Help/variable/CMAKE_C_COMPILE_FEATURES.rst
new file mode 100644
index 0000000000..1106246878
--- /dev/null
+++ b/Help/variable/CMAKE_C_COMPILE_FEATURES.rst
@@ -0,0 +1,11 @@
+CMAKE_C_COMPILE_FEATURES
+------------------------
+
+List of features known to the C compiler
+
+These features are known to be available for use with the C compiler. This
+list is a subset of the features listed in the :prop_gbl:`CMAKE_C_KNOWN_FEATURES`
+global property.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
diff --git a/Help/variable/CMAKE_C_EXTENSIONS.rst b/Help/variable/CMAKE_C_EXTENSIONS.rst
new file mode 100644
index 0000000000..5e935fcc39
--- /dev/null
+++ b/Help/variable/CMAKE_C_EXTENSIONS.rst
@@ -0,0 +1,11 @@
+CMAKE_C_EXTENSIONS
+------------------
+
+Default value for ``C_EXTENSIONS`` property of targets.
+
+This variable is used to initialize the :prop_tgt:`C_EXTENSIONS`
+property on all targets. See that target property for additional
+information.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
diff --git a/Help/variable/CMAKE_C_STANDARD.rst b/Help/variable/CMAKE_C_STANDARD.rst
new file mode 100644
index 0000000000..3098ce5d4a
--- /dev/null
+++ b/Help/variable/CMAKE_C_STANDARD.rst
@@ -0,0 +1,11 @@
+CMAKE_C_STANDARD
+----------------
+
+Default value for ``C_STANDARD`` property of targets.
+
+This variable is used to initialize the :prop_tgt:`C_STANDARD`
+property on all targets. See that target property for additional
+information.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
diff --git a/Help/variable/CMAKE_C_STANDARD_REQUIRED.rst b/Help/variable/CMAKE_C_STANDARD_REQUIRED.rst
new file mode 100644
index 0000000000..c24eea4304
--- /dev/null
+++ b/Help/variable/CMAKE_C_STANDARD_REQUIRED.rst
@@ -0,0 +1,11 @@
+CMAKE_C_STANDARD_REQUIRED
+-------------------------
+
+Default value for ``C_STANDARD_REQUIRED`` property of targets.
+
+This variable is used to initialize the :prop_tgt:`C_STANDARD_REQUIRED`
+property on all targets. See that target property for additional
+information.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
diff --git a/Help/variable/CMAKE_DEBUG_POSTFIX.rst b/Help/variable/CMAKE_DEBUG_POSTFIX.rst
new file mode 100644
index 0000000000..fde24b2b5a
--- /dev/null
+++ b/Help/variable/CMAKE_DEBUG_POSTFIX.rst
@@ -0,0 +1,7 @@
+CMAKE_DEBUG_POSTFIX
+-------------------
+
+See variable CMAKE_<CONFIG>_POSTFIX.
+
+This variable is a special case of the more-general
+CMAKE_<CONFIG>_POSTFIX variable for the DEBUG configuration.
diff --git a/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst b/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst
new file mode 100644
index 0000000000..e200b8680f
--- /dev/null
+++ b/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst
@@ -0,0 +1,14 @@
+CMAKE_DEBUG_TARGET_PROPERTIES
+-----------------------------
+
+Enables tracing output for target properties.
+
+This variable can be populated with a list of properties to generate
+debug output for when evaluating target properties. Currently it can
+only be used when evaluating the :prop_tgt:`INCLUDE_DIRECTORIES`,
+:prop_tgt:`COMPILE_DEFINITIONS`, :prop_tgt:`COMPILE_OPTIONS`,
+:prop_tgt:`AUTOUIC_OPTIONS`, :prop_tgt:`SOURCES`, :prop_tgt:`COMPILE_FEATURES`,
+:prop_tgt:`POSITION_INDEPENDENT_CODE` target properties and any other property
+listed in :prop_tgt:`COMPATIBLE_INTERFACE_STRING` and other ``COMPATIBLE_INTERFACE_``
+properties. It outputs an origin for each entry in the target property.
+Default is unset.
diff --git a/Help/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.rst b/Help/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.rst
new file mode 100644
index 0000000000..bcb277c999
--- /dev/null
+++ b/Help/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.rst
@@ -0,0 +1,15 @@
+CMAKE_DISABLE_FIND_PACKAGE_<PackageName>
+----------------------------------------
+
+Variable for disabling find_package() calls.
+
+Every non-REQUIRED find_package() call in a project can be disabled by
+setting the variable CMAKE_DISABLE_FIND_PACKAGE_<PackageName> to TRUE.
+This can be used to build a project without an optional package,
+although that package is installed.
+
+This switch should be used during the initial CMake run. Otherwise if
+the package has already been found in a previous CMake run, the
+variables which have been stored in the cache will still be there. In
+that case it is recommended to remove the cache variables for this
+package from the cache using the cache editor or cmake -U
diff --git a/Help/variable/CMAKE_DL_LIBS.rst b/Help/variable/CMAKE_DL_LIBS.rst
new file mode 100644
index 0000000000..cae4565b8d
--- /dev/null
+++ b/Help/variable/CMAKE_DL_LIBS.rst
@@ -0,0 +1,7 @@
+CMAKE_DL_LIBS
+-------------
+
+Name of library containing dlopen and dlcose.
+
+The name of the library that has dlopen and dlclose in it, usually
+-ldl on most UNIX machines.
diff --git a/Help/variable/CMAKE_EDIT_COMMAND.rst b/Help/variable/CMAKE_EDIT_COMMAND.rst
new file mode 100644
index 0000000000..562aa0bc62
--- /dev/null
+++ b/Help/variable/CMAKE_EDIT_COMMAND.rst
@@ -0,0 +1,8 @@
+CMAKE_EDIT_COMMAND
+------------------
+
+Full path to cmake-gui or ccmake. Defined only for Makefile generators
+when not using an "extra" generator for an IDE.
+
+This is the full path to the CMake executable that can graphically
+edit the cache. For example, cmake-gui or ccmake.
diff --git a/Help/variable/CMAKE_ERROR_DEPRECATED.rst b/Help/variable/CMAKE_ERROR_DEPRECATED.rst
new file mode 100644
index 0000000000..43ab282a3d
--- /dev/null
+++ b/Help/variable/CMAKE_ERROR_DEPRECATED.rst
@@ -0,0 +1,8 @@
+CMAKE_ERROR_DEPRECATED
+----------------------
+
+Whether to issue deprecation errors for macros and functions.
+
+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.
diff --git a/Help/variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst b/Help/variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst
new file mode 100644
index 0000000000..651d68d1f8
--- /dev/null
+++ b/Help/variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst
@@ -0,0 +1,9 @@
+CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
+-------------------------------------------
+
+Ask cmake_install.cmake script to error out as soon as a file with absolute INSTALL DESTINATION is encountered.
+
+The fatal error is emitted before the installation of the offending
+file takes place. This variable is used by CMake-generated
+cmake_install.cmake scripts. If one sets this variable to ON while
+running the script, it may get fatal error messages from the script.
diff --git a/Help/variable/CMAKE_EXECUTABLE_SUFFIX.rst b/Help/variable/CMAKE_EXECUTABLE_SUFFIX.rst
new file mode 100644
index 0000000000..45c313c047
--- /dev/null
+++ b/Help/variable/CMAKE_EXECUTABLE_SUFFIX.rst
@@ -0,0 +1,9 @@
+CMAKE_EXECUTABLE_SUFFIX
+-----------------------
+
+The suffix for executables on this platform.
+
+The suffix to use for the end of an executable filename if any, .exe
+on Windows.
+
+CMAKE_EXECUTABLE_SUFFIX_<LANG> overrides this for language <LANG>.
diff --git a/Help/variable/CMAKE_EXE_LINKER_FLAGS.rst b/Help/variable/CMAKE_EXE_LINKER_FLAGS.rst
new file mode 100644
index 0000000000..9e108f83f0
--- /dev/null
+++ b/Help/variable/CMAKE_EXE_LINKER_FLAGS.rst
@@ -0,0 +1,6 @@
+CMAKE_EXE_LINKER_FLAGS
+----------------------
+
+Linker flags to be used to create executables.
+
+These flags will be used by the linker when creating an executable.
diff --git a/Help/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG.rst b/Help/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG.rst
new file mode 100644
index 0000000000..dcaf300626
--- /dev/null
+++ b/Help/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG.rst
@@ -0,0 +1,7 @@
+CMAKE_EXE_LINKER_FLAGS_<CONFIG>
+-------------------------------
+
+Flags to be used when linking an executable.
+
+Same as CMAKE_C_FLAGS_* but used by the linker when creating
+executables.
diff --git a/Help/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.rst b/Help/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.rst
new file mode 100644
index 0000000000..ee109ba1a8
--- /dev/null
+++ b/Help/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.rst
@@ -0,0 +1,11 @@
+CMAKE_EXPORT_NO_PACKAGE_REGISTRY
+--------------------------------
+
+Disable the :command:`export(PACKAGE)` command.
+
+In some cases, for example for packaging and for system wide
+installations, it is not desirable to write the user package registry.
+If the :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable is enabled,
+the :command:`export(PACKAGE)` command will do nothing.
+
+See also :ref:`Disabling the Package Registry`.
diff --git a/Help/variable/CMAKE_EXTRA_GENERATOR.rst b/Help/variable/CMAKE_EXTRA_GENERATOR.rst
new file mode 100644
index 0000000000..71aec92c56
--- /dev/null
+++ b/Help/variable/CMAKE_EXTRA_GENERATOR.rst
@@ -0,0 +1,9 @@
+CMAKE_EXTRA_GENERATOR
+---------------------
+
+The extra generator used to build the project.
+
+When using the Eclipse, CodeBlocks or KDevelop generators, CMake
+generates Makefiles (CMAKE_GENERATOR) and additionally project files
+for the respective IDE. This IDE project file generator is stored in
+CMAKE_EXTRA_GENERATOR (e.g. "Eclipse CDT4").
diff --git a/Help/variable/CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES.rst b/Help/variable/CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES.rst
new file mode 100644
index 0000000000..6187a7ac84
--- /dev/null
+++ b/Help/variable/CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES.rst
@@ -0,0 +1,9 @@
+CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES
+-----------------------------------
+
+Additional suffixes for shared libraries.
+
+Extensions for shared libraries other than that specified by
+CMAKE_SHARED_LIBRARY_SUFFIX, if any. CMake uses this to recognize
+external shared library files during analysis of libraries linked by a
+target.
diff --git a/Help/variable/CMAKE_FIND_LIBRARY_PREFIXES.rst b/Help/variable/CMAKE_FIND_LIBRARY_PREFIXES.rst
new file mode 100644
index 0000000000..1a9e7ce914
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_LIBRARY_PREFIXES.rst
@@ -0,0 +1,9 @@
+CMAKE_FIND_LIBRARY_PREFIXES
+---------------------------
+
+Prefixes to prepend when looking for libraries.
+
+This specifies what prefixes to add to library names when the
+find_library command looks for libraries. On UNIX systems this is
+typically lib, meaning that when trying to find the foo library it
+will look for libfoo.
diff --git a/Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst b/Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst
new file mode 100644
index 0000000000..c533909f43
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst
@@ -0,0 +1,9 @@
+CMAKE_FIND_LIBRARY_SUFFIXES
+---------------------------
+
+Suffixes to append when looking for libraries.
+
+This specifies what suffixes to add to library names when the
+find_library command looks for libraries. On Windows systems this is
+typically .lib and .dll, meaning that when trying to find the foo
+library it will look for foo.dll etc.
diff --git a/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst b/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst
new file mode 100644
index 0000000000..70d920bcea
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst
@@ -0,0 +1,15 @@
+CMAKE_FIND_NO_INSTALL_PREFIX
+----------------------------
+
+Ignore the :variable:`CMAKE_INSTALL_PREFIX` when searching for assets.
+
+CMake adds the :variable:`CMAKE_INSTALL_PREFIX` and the
+:variable:`CMAKE_STAGING_PREFIX` variable to the
+:variable:`CMAKE_SYSTEM_PREFIX_PATH` by default. This variable may be set
+on the command line to control that behavior.
+
+Set :variable:`CMAKE_FIND_NO_INSTALL_PREFIX` to TRUE to tell find_package not
+to search in the :variable:`CMAKE_INSTALL_PREFIX` or
+:variable:`CMAKE_STAGING_PREFIX` by default. Note that the
+prefix may still be searched for other reasons, such as being the same prefix
+as the CMake installation, or for being a built-in system prefix.
diff --git a/Help/variable/CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY.rst b/Help/variable/CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY.rst
new file mode 100644
index 0000000000..90584710ed
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY.rst
@@ -0,0 +1,13 @@
+CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY
+--------------------------------------
+
+Skip :ref:`User Package Registry` in :command:`find_package` calls.
+
+In some cases, for example to locate only system wide installations, it
+is not desirable to use the :ref:`User Package Registry` when searching
+for packages. If the :variable:`CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY`
+variable is enabled, all the :command:`find_package` commands will skip
+the :ref:`User Package Registry` as if they were called with the
+``NO_CMAKE_PACKAGE_REGISTRY`` argument.
+
+See also :ref:`Disabling the Package Registry`.
diff --git a/Help/variable/CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY.rst b/Help/variable/CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY.rst
new file mode 100644
index 0000000000..44588b17ab
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY.rst
@@ -0,0 +1,13 @@
+CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY
+---------------------------------------------
+
+Skip :ref:`System Package Registry` in :command:`find_package` calls.
+
+In some cases, it is not desirable to use the
+:ref:`System Package Registry` when searching for packages. If the
+:variable:`CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY` variable is
+enabled, all the :command:`find_package` commands will skip
+the :ref:`System Package Registry` as if they were called with the
+``NO_CMAKE_SYSTEM_PACKAGE_REGISTRY`` argument.
+
+See also :ref:`Disabling the Package Registry`.
diff --git a/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst b/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst
new file mode 100644
index 0000000000..5d7599c0cd
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst
@@ -0,0 +1,19 @@
+CMAKE_FIND_PACKAGE_WARN_NO_MODULE
+---------------------------------
+
+Tell find_package to warn if called without an explicit mode.
+
+If find_package is called without an explicit mode option (MODULE,
+CONFIG or NO_MODULE) and no Find<pkg>.cmake module is in
+CMAKE_MODULE_PATH then CMake implicitly assumes that the caller
+intends to search for a package configuration file. If no package
+configuration file is found then the wording of the failure message
+must account for both the case that the package is really missing and
+the case that the project has a bug and failed to provide the intended
+Find module. If instead the caller specifies an explicit mode option
+then the failure message can be more specific.
+
+Set CMAKE_FIND_PACKAGE_WARN_NO_MODULE to TRUE to tell find_package to
+warn when it implicitly assumes Config mode. This helps developers
+enforce use of an explicit mode in all calls to find_package within a
+project.
diff --git a/Help/variable/CMAKE_FIND_ROOT_PATH.rst b/Help/variable/CMAKE_FIND_ROOT_PATH.rst
new file mode 100644
index 0000000000..67948f7cee
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_ROOT_PATH.rst
@@ -0,0 +1,8 @@
+CMAKE_FIND_ROOT_PATH
+--------------------
+
+List of root paths to search on the filesystem.
+
+This variable is most useful when cross-compiling. CMake uses the paths in
+this list as alternative roots to find filesystem items with :command:`find_package`,
+:command:`find_library` etc.
diff --git a/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_INCLUDE.rst b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_INCLUDE.rst
new file mode 100644
index 0000000000..df1af5a88e
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_INCLUDE.rst
@@ -0,0 +1,6 @@
+CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
+---------------------------------
+
+.. |FIND_XXX| replace:: :command:`find_file` and :command:`find_path`
+
+.. include:: CMAKE_FIND_ROOT_PATH_MODE_XXX.txt
diff --git a/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_LIBRARY.rst b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_LIBRARY.rst
new file mode 100644
index 0000000000..52ab89dc52
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_LIBRARY.rst
@@ -0,0 +1,6 @@
+CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
+---------------------------------
+
+.. |FIND_XXX| replace:: :command:`find_library`
+
+.. include:: CMAKE_FIND_ROOT_PATH_MODE_XXX.txt
diff --git a/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE.rst b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE.rst
new file mode 100644
index 0000000000..387294797d
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE.rst
@@ -0,0 +1,6 @@
+CMAKE_FIND_ROOT_PATH_MODE_PACKAGE
+---------------------------------
+
+.. |FIND_XXX| replace:: :command:`find_package`
+
+.. include:: CMAKE_FIND_ROOT_PATH_MODE_XXX.txt
diff --git a/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_PROGRAM.rst b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_PROGRAM.rst
new file mode 100644
index 0000000000..d24a78a3fc
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_PROGRAM.rst
@@ -0,0 +1,6 @@
+CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
+---------------------------------
+
+.. |FIND_XXX| replace:: :command:`find_program`
+
+.. include:: CMAKE_FIND_ROOT_PATH_MODE_XXX.txt
diff --git a/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_XXX.txt b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_XXX.txt
new file mode 100644
index 0000000000..ab65e090e7
--- /dev/null
+++ b/Help/variable/CMAKE_FIND_ROOT_PATH_MODE_XXX.txt
@@ -0,0 +1,8 @@
+This variable controls whether the :variable:`CMAKE_FIND_ROOT_PATH` and
+:variable:`CMAKE_SYSROOT` are used by |FIND_XXX|.
+
+If set to ``ONLY``, then only the roots in :variable:`CMAKE_FIND_ROOT_PATH`
+will be searched. If set to ``NEVER``, then the roots in
+:variable:`CMAKE_FIND_ROOT_PATH` will be ignored and only the host system
+root will be used. If set to ``BOTH``, then the host system paths and the
+paths in :variable:`CMAKE_FIND_ROOT_PATH` will be searched.
diff --git a/Help/variable/CMAKE_FRAMEWORK_PATH.rst b/Help/variable/CMAKE_FRAMEWORK_PATH.rst
new file mode 100644
index 0000000000..f1bc75e908
--- /dev/null
+++ b/Help/variable/CMAKE_FRAMEWORK_PATH.rst
@@ -0,0 +1,6 @@
+CMAKE_FRAMEWORK_PATH
+--------------------
+
+Search path for OS X frameworks used by the :command:`find_library`,
+:command:`find_package`, :command:`find_path`, and :command:`find_file`
+commands.
diff --git a/Help/variable/CMAKE_Fortran_FORMAT.rst b/Help/variable/CMAKE_Fortran_FORMAT.rst
new file mode 100644
index 0000000000..c0e971ce96
--- /dev/null
+++ b/Help/variable/CMAKE_Fortran_FORMAT.rst
@@ -0,0 +1,7 @@
+CMAKE_Fortran_FORMAT
+--------------------
+
+Set to FIXED or FREE to indicate the Fortran source layout.
+
+This variable is used to initialize the Fortran_FORMAT property on all
+the targets. See that target property for additional information.
diff --git a/Help/variable/CMAKE_Fortran_MODDIR_DEFAULT.rst b/Help/variable/CMAKE_Fortran_MODDIR_DEFAULT.rst
new file mode 100644
index 0000000000..a8dfcdf343
--- /dev/null
+++ b/Help/variable/CMAKE_Fortran_MODDIR_DEFAULT.rst
@@ -0,0 +1,8 @@
+CMAKE_Fortran_MODDIR_DEFAULT
+----------------------------
+
+Fortran default module output directory.
+
+Most Fortran compilers write .mod files to the current working
+directory. For those that do not, this is set to "." and used when
+the Fortran_MODULE_DIRECTORY target property is not set.
diff --git a/Help/variable/CMAKE_Fortran_MODDIR_FLAG.rst b/Help/variable/CMAKE_Fortran_MODDIR_FLAG.rst
new file mode 100644
index 0000000000..4b32df328c
--- /dev/null
+++ b/Help/variable/CMAKE_Fortran_MODDIR_FLAG.rst
@@ -0,0 +1,7 @@
+CMAKE_Fortran_MODDIR_FLAG
+-------------------------
+
+Fortran flag for module output directory.
+
+This stores the flag needed to pass the value of the
+Fortran_MODULE_DIRECTORY target property to the compiler.
diff --git a/Help/variable/CMAKE_Fortran_MODOUT_FLAG.rst b/Help/variable/CMAKE_Fortran_MODOUT_FLAG.rst
new file mode 100644
index 0000000000..a232213a15
--- /dev/null
+++ b/Help/variable/CMAKE_Fortran_MODOUT_FLAG.rst
@@ -0,0 +1,7 @@
+CMAKE_Fortran_MODOUT_FLAG
+-------------------------
+
+Fortran flag to enable module output.
+
+Most Fortran compilers write .mod files out by default. For others,
+this stores the flag needed to enable module output.
diff --git a/Help/variable/CMAKE_Fortran_MODULE_DIRECTORY.rst b/Help/variable/CMAKE_Fortran_MODULE_DIRECTORY.rst
new file mode 100644
index 0000000000..b1d49d8767
--- /dev/null
+++ b/Help/variable/CMAKE_Fortran_MODULE_DIRECTORY.rst
@@ -0,0 +1,8 @@
+CMAKE_Fortran_MODULE_DIRECTORY
+------------------------------
+
+Fortran module output directory.
+
+This variable is used to initialize the Fortran_MODULE_DIRECTORY
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_GENERATOR.rst b/Help/variable/CMAKE_GENERATOR.rst
new file mode 100644
index 0000000000..a4e70a590d
--- /dev/null
+++ b/Help/variable/CMAKE_GENERATOR.rst
@@ -0,0 +1,7 @@
+CMAKE_GENERATOR
+---------------
+
+The generator used to build the project.
+
+The name of the generator that is being used to generate the build
+files. (e.g. "Unix Makefiles", "Visual Studio 6", etc.)
diff --git a/Help/variable/CMAKE_GENERATOR_PLATFORM.rst b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst
new file mode 100644
index 0000000000..5809b6af8d
--- /dev/null
+++ b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst
@@ -0,0 +1,15 @@
+CMAKE_GENERATOR_PLATFORM
+------------------------
+
+Generator-specific target platform name specified by user.
+
+Some CMake generators support a target platform name to be given
+to the native build system to choose a compiler toolchain.
+If the user specifies a toolset name (e.g. via the cmake -A option)
+the value will be available in this variable.
+
+The value of this variable should never be modified by project code.
+A toolchain file specified by the :variable:`CMAKE_TOOLCHAIN_FILE`
+variable may initialize ``CMAKE_GENERATOR_PLATFORM``. Once a given
+build tree has been initialized with a particular value for this
+variable, changing the value has undefined behavior.
diff --git a/Help/variable/CMAKE_GENERATOR_TOOLSET.rst b/Help/variable/CMAKE_GENERATOR_TOOLSET.rst
new file mode 100644
index 0000000000..9ccc8b312e
--- /dev/null
+++ b/Help/variable/CMAKE_GENERATOR_TOOLSET.rst
@@ -0,0 +1,15 @@
+CMAKE_GENERATOR_TOOLSET
+-----------------------
+
+Native build system toolset name specified by user.
+
+Some CMake generators support a toolset name to be given to the native
+build system to choose a compiler. If the user specifies a toolset
+name (e.g. via the cmake -T option) the value will be available in
+this variable.
+
+The value of this variable should never be modified by project code.
+A toolchain file specified by the :variable:`CMAKE_TOOLCHAIN_FILE`
+variable may initialize ``CMAKE_GENERATOR_TOOLSET``. Once a given
+build tree has been initialized with a particular value for this
+variable, changing the value has undefined behavior.
diff --git a/Help/variable/CMAKE_GNUtoMS.rst b/Help/variable/CMAKE_GNUtoMS.rst
new file mode 100644
index 0000000000..e253f59d19
--- /dev/null
+++ b/Help/variable/CMAKE_GNUtoMS.rst
@@ -0,0 +1,8 @@
+CMAKE_GNUtoMS
+-------------
+
+Convert GNU import libraries (.dll.a) to MS format (.lib).
+
+This variable is used to initialize the GNUtoMS property on targets
+when they are created. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_HOME_DIRECTORY.rst b/Help/variable/CMAKE_HOME_DIRECTORY.rst
new file mode 100644
index 0000000000..fdc5d81901
--- /dev/null
+++ b/Help/variable/CMAKE_HOME_DIRECTORY.rst
@@ -0,0 +1,6 @@
+CMAKE_HOME_DIRECTORY
+--------------------
+
+Path to top of source tree.
+
+This is the path to the top level of the source tree.
diff --git a/Help/variable/CMAKE_HOST_APPLE.rst b/Help/variable/CMAKE_HOST_APPLE.rst
new file mode 100644
index 0000000000..d4b848344d
--- /dev/null
+++ b/Help/variable/CMAKE_HOST_APPLE.rst
@@ -0,0 +1,6 @@
+CMAKE_HOST_APPLE
+----------------
+
+True for Apple OS X operating systems.
+
+Set to true when the host system is Apple OS X.
diff --git a/Help/variable/CMAKE_HOST_SYSTEM.rst b/Help/variable/CMAKE_HOST_SYSTEM.rst
new file mode 100644
index 0000000000..c2a8f1a5f3
--- /dev/null
+++ b/Help/variable/CMAKE_HOST_SYSTEM.rst
@@ -0,0 +1,10 @@
+CMAKE_HOST_SYSTEM
+-----------------
+
+Composit Name of OS CMake is being run on.
+
+This variable is the composite of :variable:`CMAKE_HOST_SYSTEM_NAME` and
+:variable:`CMAKE_HOST_SYSTEM_VERSION`, e.g.
+``${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_VERSION}``. If
+:variable:`CMAKE_HOST_SYSTEM_VERSION` is not set, then this variable is
+the same as :variable:`CMAKE_HOST_SYSTEM_NAME`.
diff --git a/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst b/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst
new file mode 100644
index 0000000000..a221de9c06
--- /dev/null
+++ b/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst
@@ -0,0 +1,8 @@
+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
+are the values found on the big three operating systems.
diff --git a/Help/variable/CMAKE_HOST_SYSTEM_PROCESSOR.rst b/Help/variable/CMAKE_HOST_SYSTEM_PROCESSOR.rst
new file mode 100644
index 0000000000..790565a845
--- /dev/null
+++ b/Help/variable/CMAKE_HOST_SYSTEM_PROCESSOR.rst
@@ -0,0 +1,8 @@
+CMAKE_HOST_SYSTEM_PROCESSOR
+---------------------------
+
+The name of the CPU CMake is running on.
+
+On systems that support uname, this variable is set to the output of
+uname -p, on windows it is set to the value of the environment variable
+``PROCESSOR_ARCHITECTURE``.
diff --git a/Help/variable/CMAKE_HOST_SYSTEM_VERSION.rst b/Help/variable/CMAKE_HOST_SYSTEM_VERSION.rst
new file mode 100644
index 0000000000..e7e00529a5
--- /dev/null
+++ b/Help/variable/CMAKE_HOST_SYSTEM_VERSION.rst
@@ -0,0 +1,8 @@
+CMAKE_HOST_SYSTEM_VERSION
+-------------------------
+
+The OS version CMake is running on.
+
+A numeric version string for the system. On systems that support
+uname, this variable is set to the output of uname -r. On other
+systems this is set to major-minor version numbers.
diff --git a/Help/variable/CMAKE_HOST_UNIX.rst b/Help/variable/CMAKE_HOST_UNIX.rst
new file mode 100644
index 0000000000..bbefba7d9a
--- /dev/null
+++ b/Help/variable/CMAKE_HOST_UNIX.rst
@@ -0,0 +1,7 @@
+CMAKE_HOST_UNIX
+---------------
+
+True for UNIX and UNIX like operating systems.
+
+Set to true when the host system is UNIX or UNIX like (i.e. APPLE and
+CYGWIN).
diff --git a/Help/variable/CMAKE_HOST_WIN32.rst b/Help/variable/CMAKE_HOST_WIN32.rst
new file mode 100644
index 0000000000..92ee45658f
--- /dev/null
+++ b/Help/variable/CMAKE_HOST_WIN32.rst
@@ -0,0 +1,6 @@
+CMAKE_HOST_WIN32
+----------------
+
+True on windows systems, including win64.
+
+Set to true when the host system is Windows and on Cygwin.
diff --git a/Help/variable/CMAKE_IGNORE_PATH.rst b/Help/variable/CMAKE_IGNORE_PATH.rst
new file mode 100644
index 0000000000..a818f74c69
--- /dev/null
+++ b/Help/variable/CMAKE_IGNORE_PATH.rst
@@ -0,0 +1,17 @@
+CMAKE_IGNORE_PATH
+-----------------
+
+Path to be ignored by FIND_XXX() commands.
+
+Specifies directories to be ignored by searches in FIND_XXX()
+commands. This is useful in cross-compiled environments where some
+system directories contain incompatible but possibly linkable
+libraries. For example, on cross-compiled cluster environments, this
+allows a user to ignore directories containing libraries meant for the
+front-end machine that modules like FindX11 (and others) would
+normally search. By default this is empty; it is intended to be set
+by the project. Note that CMAKE_IGNORE_PATH takes a list of directory
+names, NOT a list of prefixes. If you want to ignore paths under
+prefixes (bin, include, lib, etc.), you'll need to specify them
+explicitly. See also CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH,
+CMAKE_INCLUDE_PATH, CMAKE_PROGRAM_PATH.
diff --git a/Help/variable/CMAKE_IMPORT_LIBRARY_PREFIX.rst b/Help/variable/CMAKE_IMPORT_LIBRARY_PREFIX.rst
new file mode 100644
index 0000000000..1d16a3764f
--- /dev/null
+++ b/Help/variable/CMAKE_IMPORT_LIBRARY_PREFIX.rst
@@ -0,0 +1,9 @@
+CMAKE_IMPORT_LIBRARY_PREFIX
+---------------------------
+
+The prefix for import libraries that you link to.
+
+The prefix to use for the name of an import library if used on this
+platform.
+
+CMAKE_IMPORT_LIBRARY_PREFIX_<LANG> overrides this for language <LANG>.
diff --git a/Help/variable/CMAKE_IMPORT_LIBRARY_SUFFIX.rst b/Help/variable/CMAKE_IMPORT_LIBRARY_SUFFIX.rst
new file mode 100644
index 0000000000..c16825eb99
--- /dev/null
+++ b/Help/variable/CMAKE_IMPORT_LIBRARY_SUFFIX.rst
@@ -0,0 +1,9 @@
+CMAKE_IMPORT_LIBRARY_SUFFIX
+---------------------------
+
+The suffix for import libraries that you link to.
+
+The suffix to use for the end of an import library filename if used on
+this platform.
+
+CMAKE_IMPORT_LIBRARY_SUFFIX_<LANG> overrides this for language <LANG>.
diff --git a/Help/variable/CMAKE_INCLUDE_CURRENT_DIR.rst b/Help/variable/CMAKE_INCLUDE_CURRENT_DIR.rst
new file mode 100644
index 0000000000..79f3952fc1
--- /dev/null
+++ b/Help/variable/CMAKE_INCLUDE_CURRENT_DIR.rst
@@ -0,0 +1,13 @@
+CMAKE_INCLUDE_CURRENT_DIR
+-------------------------
+
+Automatically add the current source- and build directories to the include path.
+
+If this variable is enabled, CMake automatically adds in each
+directory ${CMAKE_CURRENT_SOURCE_DIR} and ${CMAKE_CURRENT_BINARY_DIR}
+to the include path for this directory. These additional include
+directories do not propagate down to subdirectories. This is useful
+mainly for out-of-source builds, where files generated into the build
+tree are included by files located in the source tree.
+
+By default CMAKE_INCLUDE_CURRENT_DIR is OFF.
diff --git a/Help/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.rst b/Help/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.rst
new file mode 100644
index 0000000000..948db50d5d
--- /dev/null
+++ b/Help/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.rst
@@ -0,0 +1,10 @@
+CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE
+--------------------------------------
+
+Automatically add the current source- and build directories to the INTERFACE_INCLUDE_DIRECTORIES.
+
+If this variable is enabled, CMake automatically adds for each shared
+library target, static library target, module target and executable
+target, ${CMAKE_CURRENT_SOURCE_DIR} and ${CMAKE_CURRENT_BINARY_DIR} to
+the INTERFACE_INCLUDE_DIRECTORIES.By default
+CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE is OFF.
diff --git a/Help/variable/CMAKE_INCLUDE_DIRECTORIES_BEFORE.rst b/Help/variable/CMAKE_INCLUDE_DIRECTORIES_BEFORE.rst
new file mode 100644
index 0000000000..3c1fbcfb4d
--- /dev/null
+++ b/Help/variable/CMAKE_INCLUDE_DIRECTORIES_BEFORE.rst
@@ -0,0 +1,8 @@
+CMAKE_INCLUDE_DIRECTORIES_BEFORE
+--------------------------------
+
+Whether to append or prepend directories by default in :command:`include_directories`.
+
+This variable affects the default behavior of the :command:`include_directories`
+command. Setting this variable to 'ON' is equivalent to using the BEFORE option
+in all uses of that command.
diff --git a/Help/variable/CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE.rst b/Help/variable/CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE.rst
new file mode 100644
index 0000000000..cbd04d7d2a
--- /dev/null
+++ b/Help/variable/CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE.rst
@@ -0,0 +1,8 @@
+CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE
+----------------------------------------
+
+Whether to force prepending of project include directories.
+
+This variable affects the order of include directories generated in compiler
+command lines. If set to 'ON', it causes the :variable:`CMAKE_SOURCE_DIR` and
+the :variable:`CMAKE_BINARY_DIR` to appear first.
diff --git a/Help/variable/CMAKE_INCLUDE_PATH.rst b/Help/variable/CMAKE_INCLUDE_PATH.rst
new file mode 100644
index 0000000000..360b403fee
--- /dev/null
+++ b/Help/variable/CMAKE_INCLUDE_PATH.rst
@@ -0,0 +1,10 @@
+CMAKE_INCLUDE_PATH
+------------------
+
+Path used for searching by FIND_FILE() and FIND_PATH().
+
+Specifies a path which will be used both by FIND_FILE() and
+FIND_PATH(). Both commands will check each of the contained
+directories for the existence of the file which is currently searched.
+By default it is empty, it is intended to be set by the project. See
+also CMAKE_SYSTEM_INCLUDE_PATH, CMAKE_PREFIX_PATH.
diff --git a/Help/variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME.rst b/Help/variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME.rst
new file mode 100644
index 0000000000..2ad0689aa8
--- /dev/null
+++ b/Help/variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME.rst
@@ -0,0 +1,9 @@
+CMAKE_INSTALL_DEFAULT_COMPONENT_NAME
+------------------------------------
+
+Default component used in install() commands.
+
+If an install() command is used without the COMPONENT argument, these
+files will be grouped into a default component. The name of this
+default install component will be taken from this variable. It
+defaults to "Unspecified".
diff --git a/Help/variable/CMAKE_INSTALL_MESSAGE.rst b/Help/variable/CMAKE_INSTALL_MESSAGE.rst
new file mode 100644
index 0000000000..304df268c7
--- /dev/null
+++ b/Help/variable/CMAKE_INSTALL_MESSAGE.rst
@@ -0,0 +1,30 @@
+CMAKE_INSTALL_MESSAGE
+---------------------
+
+Specify verbosity of installation script code generated by the
+:command:`install` command (using the :command:`file(INSTALL)` command).
+For paths that are newly installed or updated, installation
+may print lines like::
+
+ -- Installing: /some/destination/path
+
+For paths that are already up to date, installation may print
+lines like::
+
+ -- Up-to-date: /some/destination/path
+
+The ``CMAKE_INSTALL_MESSAGE`` variable may be set to control
+which messages are printed:
+
+``ALWAYS``
+ Print both ``Installing`` and ``Up-to-date`` messages.
+
+``LAZY``
+ Print ``Installing`` but not ``Up-to-date`` messages.
+
+``NEVER``
+ Print neither ``Installing`` nor ``Up-to-date`` messages.
+
+Other values have undefined behavior and may not be diagnosed.
+
+If this variable is not set, the default behavior is ``ALWAYS``.
diff --git a/Help/variable/CMAKE_INSTALL_NAME_DIR.rst b/Help/variable/CMAKE_INSTALL_NAME_DIR.rst
new file mode 100644
index 0000000000..540df6b731
--- /dev/null
+++ b/Help/variable/CMAKE_INSTALL_NAME_DIR.rst
@@ -0,0 +1,8 @@
+CMAKE_INSTALL_NAME_DIR
+----------------------
+
+Mac OS X directory name for installed targets.
+
+CMAKE_INSTALL_NAME_DIR is used to initialize the INSTALL_NAME_DIR
+property on all targets. See that target property for more
+information.
diff --git a/Help/variable/CMAKE_INSTALL_PREFIX.rst b/Help/variable/CMAKE_INSTALL_PREFIX.rst
new file mode 100644
index 0000000000..72c8d4167b
--- /dev/null
+++ b/Help/variable/CMAKE_INSTALL_PREFIX.rst
@@ -0,0 +1,29 @@
+CMAKE_INSTALL_PREFIX
+--------------------
+
+Install directory used by install.
+
+If "make install" is invoked or INSTALL is built, this directory is
+prepended onto all install directories. This variable defaults to
+/usr/local on UNIX and c:/Program Files on Windows.
+
+On UNIX one can use the DESTDIR mechanism in order to relocate the
+whole installation. DESTDIR means DESTination DIRectory. It is
+commonly used by makefile users in order to install software at
+non-default location. It is usually invoked like this:
+
+::
+
+ make DESTDIR=/home/john install
+
+which will install the concerned software using the installation
+prefix, e.g. "/usr/local" prepended with the DESTDIR value which
+finally gives "/home/john/usr/local".
+
+WARNING: DESTDIR may not be used on Windows because installation
+prefix usually contains a drive letter like in "C:/Program Files"
+which cannot be prepended with some other prefix.
+
+The installation prefix is also added to CMAKE_SYSTEM_PREFIX_PATH so
+that find_package, find_program, find_library, find_path, and
+find_file will search the prefix for other software.
diff --git a/Help/variable/CMAKE_INSTALL_RPATH.rst b/Help/variable/CMAKE_INSTALL_RPATH.rst
new file mode 100644
index 0000000000..0992d57ebd
--- /dev/null
+++ b/Help/variable/CMAKE_INSTALL_RPATH.rst
@@ -0,0 +1,8 @@
+CMAKE_INSTALL_RPATH
+-------------------
+
+The rpath to use for installed targets.
+
+A semicolon-separated list specifying the rpath to use in installed
+targets (for platforms that support it). This is used to initialize
+the target property INSTALL_RPATH for all targets.
diff --git a/Help/variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH.rst b/Help/variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH.rst
new file mode 100644
index 0000000000..9277a3ba40
--- /dev/null
+++ b/Help/variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH.rst
@@ -0,0 +1,9 @@
+CMAKE_INSTALL_RPATH_USE_LINK_PATH
+---------------------------------
+
+Add paths to linker search and installed rpath.
+
+CMAKE_INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true
+will append directories in the linker search path and outside the
+project to the INSTALL_RPATH. This is used to initialize the target
+property INSTALL_RPATH_USE_LINK_PATH for all targets.
diff --git a/Help/variable/CMAKE_INTERNAL_PLATFORM_ABI.rst b/Help/variable/CMAKE_INTERNAL_PLATFORM_ABI.rst
new file mode 100644
index 0000000000..9693bf658a
--- /dev/null
+++ b/Help/variable/CMAKE_INTERNAL_PLATFORM_ABI.rst
@@ -0,0 +1,6 @@
+CMAKE_INTERNAL_PLATFORM_ABI
+---------------------------
+
+An internal variable subject to change.
+
+This is used in determining the compiler ABI and is subject to change.
diff --git a/Help/variable/CMAKE_JOB_POOL_COMPILE.rst b/Help/variable/CMAKE_JOB_POOL_COMPILE.rst
new file mode 100644
index 0000000000..e5c2d9a819
--- /dev/null
+++ b/Help/variable/CMAKE_JOB_POOL_COMPILE.rst
@@ -0,0 +1,6 @@
+CMAKE_JOB_POOL_COMPILE
+----------------------
+
+This variable is used to initialize the :prop_tgt:`JOB_POOL_COMPILE`
+property on all the targets. See :prop_tgt:`JOB_POOL_COMPILE`
+for additional information.
diff --git a/Help/variable/CMAKE_JOB_POOL_LINK.rst b/Help/variable/CMAKE_JOB_POOL_LINK.rst
new file mode 100644
index 0000000000..338f7714e2
--- /dev/null
+++ b/Help/variable/CMAKE_JOB_POOL_LINK.rst
@@ -0,0 +1,6 @@
+CMAKE_JOB_POOL_LINK
+----------------------
+
+This variable is used to initialize the :prop_tgt:`JOB_POOL_LINK`
+property on all the targets. See :prop_tgt:`JOB_POOL_LINK`
+for additional information.
diff --git a/Help/variable/CMAKE_LANG_ARCHIVE_APPEND.rst b/Help/variable/CMAKE_LANG_ARCHIVE_APPEND.rst
new file mode 100644
index 0000000000..2c3abaebaa
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_ARCHIVE_APPEND.rst
@@ -0,0 +1,9 @@
+CMAKE_<LANG>_ARCHIVE_APPEND
+---------------------------
+
+Rule variable to append to a static archive.
+
+This is a rule variable that tells CMake how to append to a static
+archive. It is used in place of CMAKE_<LANG>_CREATE_STATIC_LIBRARY on
+some platforms in order to support large object counts. See also
+CMAKE_<LANG>_ARCHIVE_CREATE and CMAKE_<LANG>_ARCHIVE_FINISH.
diff --git a/Help/variable/CMAKE_LANG_ARCHIVE_CREATE.rst b/Help/variable/CMAKE_LANG_ARCHIVE_CREATE.rst
new file mode 100644
index 0000000000..f93dd1119f
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_ARCHIVE_CREATE.rst
@@ -0,0 +1,9 @@
+CMAKE_<LANG>_ARCHIVE_CREATE
+---------------------------
+
+Rule variable to create a new static archive.
+
+This is a rule variable that tells CMake how to create a static
+archive. It is used in place of CMAKE_<LANG>_CREATE_STATIC_LIBRARY on
+some platforms in order to support large object counts. See also
+CMAKE_<LANG>_ARCHIVE_APPEND and CMAKE_<LANG>_ARCHIVE_FINISH.
diff --git a/Help/variable/CMAKE_LANG_ARCHIVE_FINISH.rst b/Help/variable/CMAKE_LANG_ARCHIVE_FINISH.rst
new file mode 100644
index 0000000000..fff4128a46
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_ARCHIVE_FINISH.rst
@@ -0,0 +1,9 @@
+CMAKE_<LANG>_ARCHIVE_FINISH
+---------------------------
+
+Rule variable to finish an existing static archive.
+
+This is a rule variable that tells CMake how to finish a static
+archive. It is used in place of CMAKE_<LANG>_CREATE_STATIC_LIBRARY on
+some platforms in order to support large object counts. See also
+CMAKE_<LANG>_ARCHIVE_CREATE and CMAKE_<LANG>_ARCHIVE_APPEND.
diff --git a/Help/variable/CMAKE_LANG_COMPILER.rst b/Help/variable/CMAKE_LANG_COMPILER.rst
new file mode 100644
index 0000000000..fffc347bd0
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_COMPILER.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_COMPILER
+---------------------
+
+The full path to the compiler for LANG.
+
+This is the command that will be used as the <LANG> compiler. Once
+set, you can not change this variable.
diff --git a/Help/variable/CMAKE_LANG_COMPILER_ABI.rst b/Help/variable/CMAKE_LANG_COMPILER_ABI.rst
new file mode 100644
index 0000000000..be946c01b2
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_COMPILER_ABI.rst
@@ -0,0 +1,6 @@
+CMAKE_<LANG>_COMPILER_ABI
+-------------------------
+
+An internal variable subject to change.
+
+This is used in determining the compiler ABI and is subject to change.
diff --git a/Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst b/Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst
new file mode 100644
index 0000000000..033998d0c3
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst
@@ -0,0 +1,13 @@
+CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN
+----------------------------------------
+
+The external toolchain for cross-compiling, if supported.
+
+Some compiler toolchains do not ship their own auxilliary utilities such as
+archivers and linkers. The compiler driver may support a command-line argument
+to specify the location of such tools. CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN
+may be set to a path to a path to the external toolchain and will be passed
+to the compiler driver if supported.
+
+This variable may only be set in a toolchain file specified by
+the :variable:`CMAKE_TOOLCHAIN_FILE` variable.
diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst
new file mode 100644
index 0000000000..f554f4ec49
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_COMPILER_ID.rst
@@ -0,0 +1,33 @@
+CMAKE_<LANG>_COMPILER_ID
+------------------------
+
+Compiler identification string.
+
+A short string unique to the compiler vendor. Possible values
+include:
+
+::
+
+ Absoft = Absoft Fortran (absoft.com)
+ ADSP = Analog VisualDSP++ (analog.com)
+ AppleClang = Apple Clang (apple.com)
+ Clang = LLVM Clang (clang.llvm.org)
+ Cray = Cray Compiler (cray.com)
+ Embarcadero, Borland = Embarcadero (embarcadero.com)
+ G95 = G95 Fortran (g95.org)
+ GNU = GNU Compiler Collection (gcc.gnu.org)
+ HP = Hewlett-Packard Compiler (hp.com)
+ Intel = Intel Compiler (intel.com)
+ MIPSpro = SGI MIPSpro (sgi.com)
+ MSVC = Microsoft Visual Studio (microsoft.com)
+ OpenWatcom = Open Watcom (openwatcom.org)
+ PGI = The Portland Group (pgroup.com)
+ PathScale = PathScale (pathscale.com)
+ SDCC = Small Device C Compiler (sdcc.sourceforge.net)
+ SunPro = Oracle Solaris Studio (oracle.com)
+ TI = Texas Instruments (ti.com)
+ TinyCC = Tiny C Compiler (tinycc.org)
+ XL, VisualAge, zOS = IBM XL (ibm.com)
+
+This variable is not guaranteed to be defined for all compilers or
+languages.
diff --git a/Help/variable/CMAKE_LANG_COMPILER_LOADED.rst b/Help/variable/CMAKE_LANG_COMPILER_LOADED.rst
new file mode 100644
index 0000000000..3b8e9aac62
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_COMPILER_LOADED.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_COMPILER_LOADED
+----------------------------
+
+Defined to true if the language is enabled.
+
+When language <LANG> is enabled by project() or enable_language() this
+variable is defined to 1.
diff --git a/Help/variable/CMAKE_LANG_COMPILER_TARGET.rst b/Help/variable/CMAKE_LANG_COMPILER_TARGET.rst
new file mode 100644
index 0000000000..656c57d2b2
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_COMPILER_TARGET.rst
@@ -0,0 +1,11 @@
+CMAKE_<LANG>_COMPILER_TARGET
+----------------------------
+
+The target for cross-compiling, if supported.
+
+Some compiler drivers are inherently cross-compilers, such as clang and
+QNX qcc. These compiler drivers support a command-line argument to specify
+the target to cross-compile for.
+
+This variable may only be set in a toolchain file specified by
+the :variable:`CMAKE_TOOLCHAIN_FILE` variable.
diff --git a/Help/variable/CMAKE_LANG_COMPILER_VERSION.rst b/Help/variable/CMAKE_LANG_COMPILER_VERSION.rst
new file mode 100644
index 0000000000..50e77eba0f
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_COMPILER_VERSION.rst
@@ -0,0 +1,8 @@
+CMAKE_<LANG>_COMPILER_VERSION
+-----------------------------
+
+Compiler version string.
+
+Compiler version in major[.minor[.patch[.tweak]]] format. This
+variable is not guaranteed to be defined for all compilers or
+languages.
diff --git a/Help/variable/CMAKE_LANG_COMPILE_OBJECT.rst b/Help/variable/CMAKE_LANG_COMPILE_OBJECT.rst
new file mode 100644
index 0000000000..f43ed6df8a
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_COMPILE_OBJECT.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_COMPILE_OBJECT
+---------------------------
+
+Rule variable to compile a single object file.
+
+This is a rule variable that tells CMake how to compile a single
+object file for the language <LANG>.
diff --git a/Help/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.rst b/Help/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.rst
new file mode 100644
index 0000000000..adf1624e53
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_CREATE_SHARED_LIBRARY
+----------------------------------
+
+Rule variable to create a shared library.
+
+This is a rule variable that tells CMake how to create a shared
+library for the language <LANG>.
diff --git a/Help/variable/CMAKE_LANG_CREATE_SHARED_MODULE.rst b/Help/variable/CMAKE_LANG_CREATE_SHARED_MODULE.rst
new file mode 100644
index 0000000000..406b4daba0
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_CREATE_SHARED_MODULE.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_CREATE_SHARED_MODULE
+---------------------------------
+
+Rule variable to create a shared module.
+
+This is a rule variable that tells CMake how to create a shared
+library for the language <LANG>.
diff --git a/Help/variable/CMAKE_LANG_CREATE_STATIC_LIBRARY.rst b/Help/variable/CMAKE_LANG_CREATE_STATIC_LIBRARY.rst
new file mode 100644
index 0000000000..8114432933
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_CREATE_STATIC_LIBRARY.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_CREATE_STATIC_LIBRARY
+----------------------------------
+
+Rule variable to create a static library.
+
+This is a rule variable that tells CMake how to create a static
+library for the language <LANG>.
diff --git a/Help/variable/CMAKE_LANG_FLAGS.rst b/Help/variable/CMAKE_LANG_FLAGS.rst
new file mode 100644
index 0000000000..6aa0a3e186
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_FLAGS.rst
@@ -0,0 +1,6 @@
+CMAKE_<LANG>_FLAGS
+------------------
+
+Flags for all build types.
+
+<LANG> flags used regardless of the value of CMAKE_BUILD_TYPE.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_DEBUG.rst b/Help/variable/CMAKE_LANG_FLAGS_DEBUG.rst
new file mode 100644
index 0000000000..a727641874
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_FLAGS_DEBUG.rst
@@ -0,0 +1,6 @@
+CMAKE_<LANG>_FLAGS_DEBUG
+------------------------
+
+Flags for Debug build type or configuration.
+
+<LANG> flags used when CMAKE_BUILD_TYPE is Debug.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL.rst b/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL.rst
new file mode 100644
index 0000000000..fbb851697a
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_FLAGS_MINSIZEREL
+-----------------------------
+
+Flags for MinSizeRel build type or configuration.
+
+<LANG> flags used when CMAKE_BUILD_TYPE is MinSizeRel.Short for
+minimum size release.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_RELEASE.rst b/Help/variable/CMAKE_LANG_FLAGS_RELEASE.rst
new file mode 100644
index 0000000000..4b2c926d5f
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_FLAGS_RELEASE.rst
@@ -0,0 +1,6 @@
+CMAKE_<LANG>_FLAGS_RELEASE
+--------------------------
+
+Flags for Release build type or configuration.
+
+<LANG> flags used when CMAKE_BUILD_TYPE is Release
diff --git a/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO.rst b/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO.rst
new file mode 100644
index 0000000000..16bd4e9014
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_FLAGS_RELWITHDEBINFO
+---------------------------------
+
+Flags for RelWithDebInfo type or configuration.
+
+<LANG> flags used when CMAKE_BUILD_TYPE is RelWithDebInfo. Short for
+Release With Debug Information.
diff --git a/Help/variable/CMAKE_LANG_IGNORE_EXTENSIONS.rst b/Help/variable/CMAKE_LANG_IGNORE_EXTENSIONS.rst
new file mode 100644
index 0000000000..3d07e912be
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_IGNORE_EXTENSIONS.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_IGNORE_EXTENSIONS
+------------------------------
+
+File extensions that should be ignored by the build.
+
+This is a list of file extensions that may be part of a project for a
+given language but are not compiled.
diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst
new file mode 100644
index 0000000000..c60e18c04f
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst
@@ -0,0 +1,9 @@
+CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES
+-----------------------------------------
+
+Directories implicitly searched by the compiler for header files.
+
+CMake does not explicitly specify these directories on compiler
+command lines for language <LANG>. This prevents system include
+directories from being treated as user include directories on some
+compilers.
diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst
new file mode 100644
index 0000000000..568950c0f0
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst
@@ -0,0 +1,17 @@
+CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES
+--------------------------------------
+
+Implicit linker search path detected for language <LANG>.
+
+Compilers typically pass directories containing language runtime
+libraries and default library search paths when they invoke a linker.
+These paths are implicit linker search directories for the compiler's
+language. CMake automatically detects these directories for each
+language and reports the results in this variable.
+
+When a library in one of these directories is given by full path to
+target_link_libraries() CMake will generate the -l<name> form on link
+lines to ensure the linker searches its implicit directories for the
+library. Note that some toolchains read implicit directories from an
+environment variable such as LIBRARY_PATH so keep its value consistent
+when operating in a given build tree.
diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES.rst
new file mode 100644
index 0000000000..05e6ddbd04
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES.rst
@@ -0,0 +1,8 @@
+CMAKE_<LANG>_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+------------------------------------------------
+
+Implicit linker framework search path detected for language <LANG>.
+
+These paths are implicit linker framework search directories for the
+compiler's language. CMake automatically detects these directories
+for each language and reports the results in this variable.
diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES.rst
new file mode 100644
index 0000000000..fddfed8bc1
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES.rst
@@ -0,0 +1,10 @@
+CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES
+------------------------------------
+
+Implicit link libraries and flags detected for language <LANG>.
+
+Compilers typically pass language runtime library names and other
+flags when they invoke a linker. These flags are implicit link
+options for the compiler's language. CMake automatically detects
+these libraries and flags for each language and reports the results in
+this variable.
diff --git a/Help/variable/CMAKE_LANG_LIBRARY_ARCHITECTURE.rst b/Help/variable/CMAKE_LANG_LIBRARY_ARCHITECTURE.rst
new file mode 100644
index 0000000000..4f3149464e
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_LIBRARY_ARCHITECTURE.rst
@@ -0,0 +1,8 @@
+CMAKE_<LANG>_LIBRARY_ARCHITECTURE
+---------------------------------
+
+Target architecture library directory name detected for <lang>.
+
+If the <lang> compiler passes to the linker an architecture-specific
+system library search directory such as <prefix>/lib/<arch> this
+variable contains the <arch> name if/as detected by CMake.
diff --git a/Help/variable/CMAKE_LANG_LINKER_PREFERENCE.rst b/Help/variable/CMAKE_LANG_LINKER_PREFERENCE.rst
new file mode 100644
index 0000000000..af7ee60f71
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_LINKER_PREFERENCE.rst
@@ -0,0 +1,11 @@
+CMAKE_<LANG>_LINKER_PREFERENCE
+------------------------------
+
+Preference value for linker language selection.
+
+The "linker language" for executable, shared library, and module
+targets is the language whose compiler will invoke the linker. The
+LINKER_LANGUAGE target property sets the language explicitly.
+Otherwise, the linker language is that whose linker preference value
+is highest among languages compiled and linked into the target. See
+also the CMAKE_<LANG>_LINKER_PREFERENCE_PROPAGATES variable.
diff --git a/Help/variable/CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES.rst b/Help/variable/CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES.rst
new file mode 100644
index 0000000000..d513767f77
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES.rst
@@ -0,0 +1,9 @@
+CMAKE_<LANG>_LINKER_PREFERENCE_PROPAGATES
+-----------------------------------------
+
+True if CMAKE_<LANG>_LINKER_PREFERENCE propagates across targets.
+
+This is used when CMake selects a linker language for a target.
+Languages compiled directly into the target are always considered. A
+language compiled into static libraries linked by the target is
+considered if this variable is true.
diff --git a/Help/variable/CMAKE_LANG_LINK_EXECUTABLE.rst b/Help/variable/CMAKE_LANG_LINK_EXECUTABLE.rst
new file mode 100644
index 0000000000..abd5891479
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_LINK_EXECUTABLE.rst
@@ -0,0 +1,6 @@
+CMAKE_<LANG>_LINK_EXECUTABLE
+----------------------------
+
+Rule variable to link an executable.
+
+Rule variable to link an executable for the given language.
diff --git a/Help/variable/CMAKE_LANG_OUTPUT_EXTENSION.rst b/Help/variable/CMAKE_LANG_OUTPUT_EXTENSION.rst
new file mode 100644
index 0000000000..22fac2900a
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_OUTPUT_EXTENSION.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_OUTPUT_EXTENSION
+-----------------------------
+
+Extension for the output of a compile for a single file.
+
+This is the extension for an object file for the given <LANG>. For
+example .obj for C on Windows.
diff --git a/Help/variable/CMAKE_LANG_PLATFORM_ID.rst b/Help/variable/CMAKE_LANG_PLATFORM_ID.rst
new file mode 100644
index 0000000000..1b243e39a3
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_PLATFORM_ID.rst
@@ -0,0 +1,6 @@
+CMAKE_<LANG>_PLATFORM_ID
+------------------------
+
+An internal variable subject to change.
+
+This is used in determining the platform and is subject to change.
diff --git a/Help/variable/CMAKE_LANG_SIMULATE_ID.rst b/Help/variable/CMAKE_LANG_SIMULATE_ID.rst
new file mode 100644
index 0000000000..646c0db7e7
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_SIMULATE_ID.rst
@@ -0,0 +1,9 @@
+CMAKE_<LANG>_SIMULATE_ID
+------------------------
+
+Identification string of "simulated" compiler.
+
+Some compilers simulate other compilers to serve as drop-in
+replacements. When CMake detects such a compiler it sets this
+variable to what would have been the CMAKE_<LANG>_COMPILER_ID for the
+simulated compiler.
diff --git a/Help/variable/CMAKE_LANG_SIMULATE_VERSION.rst b/Help/variable/CMAKE_LANG_SIMULATE_VERSION.rst
new file mode 100644
index 0000000000..982053df2d
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_SIMULATE_VERSION.rst
@@ -0,0 +1,9 @@
+CMAKE_<LANG>_SIMULATE_VERSION
+-----------------------------
+
+Version string of "simulated" compiler.
+
+Some compilers simulate other compilers to serve as drop-in
+replacements. When CMake detects such a compiler it sets this
+variable to what would have been the CMAKE_<LANG>_COMPILER_VERSION for
+the simulated compiler.
diff --git a/Help/variable/CMAKE_LANG_SIZEOF_DATA_PTR.rst b/Help/variable/CMAKE_LANG_SIZEOF_DATA_PTR.rst
new file mode 100644
index 0000000000..c85b5e078e
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_SIZEOF_DATA_PTR.rst
@@ -0,0 +1,7 @@
+CMAKE_<LANG>_SIZEOF_DATA_PTR
+----------------------------
+
+Size of pointer-to-data types for language <LANG>.
+
+This holds the size (in bytes) of pointer-to-data types in the target
+platform ABI. It is defined for languages C and CXX (C++).
diff --git a/Help/variable/CMAKE_LANG_SOURCE_FILE_EXTENSIONS.rst b/Help/variable/CMAKE_LANG_SOURCE_FILE_EXTENSIONS.rst
new file mode 100644
index 0000000000..e085fee675
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_SOURCE_FILE_EXTENSIONS.rst
@@ -0,0 +1,6 @@
+CMAKE_<LANG>_SOURCE_FILE_EXTENSIONS
+-----------------------------------
+
+Extensions of source files for the given language.
+
+This is the list of extensions for a given language's source files.
diff --git a/Help/variable/CMAKE_LANG_VISIBILITY_PRESET.rst b/Help/variable/CMAKE_LANG_VISIBILITY_PRESET.rst
new file mode 100644
index 0000000000..bef670fd1d
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_VISIBILITY_PRESET.rst
@@ -0,0 +1,8 @@
+CMAKE_<LANG>_VISIBILITY_PRESET
+------------------------------
+
+Default value for <LANG>_VISIBILITY_PRESET of targets.
+
+This variable is used to initialize the <LANG>_VISIBILITY_PRESET
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_LIBRARY_ARCHITECTURE.rst b/Help/variable/CMAKE_LIBRARY_ARCHITECTURE.rst
new file mode 100644
index 0000000000..c9a15f3155
--- /dev/null
+++ b/Help/variable/CMAKE_LIBRARY_ARCHITECTURE.rst
@@ -0,0 +1,7 @@
+CMAKE_LIBRARY_ARCHITECTURE
+--------------------------
+
+Target architecture library directory name, if detected.
+
+This is the value of CMAKE_<lang>_LIBRARY_ARCHITECTURE as detected for
+one of the enabled languages.
diff --git a/Help/variable/CMAKE_LIBRARY_ARCHITECTURE_REGEX.rst b/Help/variable/CMAKE_LIBRARY_ARCHITECTURE_REGEX.rst
new file mode 100644
index 0000000000..6c41269033
--- /dev/null
+++ b/Help/variable/CMAKE_LIBRARY_ARCHITECTURE_REGEX.rst
@@ -0,0 +1,7 @@
+CMAKE_LIBRARY_ARCHITECTURE_REGEX
+--------------------------------
+
+Regex matching possible target architecture library directory names.
+
+This is used to detect CMAKE_<lang>_LIBRARY_ARCHITECTURE from the
+implicit linker search path by matching the <arch> name.
diff --git a/Help/variable/CMAKE_LIBRARY_OUTPUT_DIRECTORY.rst b/Help/variable/CMAKE_LIBRARY_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..3bdd3484a5
--- /dev/null
+++ b/Help/variable/CMAKE_LIBRARY_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,8 @@
+CMAKE_LIBRARY_OUTPUT_DIRECTORY
+------------------------------
+
+Where to put all the LIBRARY targets when built.
+
+This variable is used to initialize the LIBRARY_OUTPUT_DIRECTORY
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_LIBRARY_PATH.rst b/Help/variable/CMAKE_LIBRARY_PATH.rst
new file mode 100644
index 0000000000..e77dd348c1
--- /dev/null
+++ b/Help/variable/CMAKE_LIBRARY_PATH.rst
@@ -0,0 +1,10 @@
+CMAKE_LIBRARY_PATH
+------------------
+
+Path used for searching by FIND_LIBRARY().
+
+Specifies a path which will be used by FIND_LIBRARY(). FIND_LIBRARY()
+will check each of the contained directories for the existence of the
+library which is currently searched. By default it is empty, it is
+intended to be set by the project. See also
+CMAKE_SYSTEM_LIBRARY_PATH, CMAKE_PREFIX_PATH.
diff --git a/Help/variable/CMAKE_LIBRARY_PATH_FLAG.rst b/Help/variable/CMAKE_LIBRARY_PATH_FLAG.rst
new file mode 100644
index 0000000000..ede39e9d64
--- /dev/null
+++ b/Help/variable/CMAKE_LIBRARY_PATH_FLAG.rst
@@ -0,0 +1,7 @@
+CMAKE_LIBRARY_PATH_FLAG
+-----------------------
+
+The flag to be used to add a library search path to a compiler.
+
+The flag will be used to specify a library directory to the compiler.
+On most compilers this is "-L".
diff --git a/Help/variable/CMAKE_LINK_DEF_FILE_FLAG.rst b/Help/variable/CMAKE_LINK_DEF_FILE_FLAG.rst
new file mode 100644
index 0000000000..382447c983
--- /dev/null
+++ b/Help/variable/CMAKE_LINK_DEF_FILE_FLAG.rst
@@ -0,0 +1,7 @@
+CMAKE_LINK_DEF_FILE_FLAG
+------------------------
+
+Linker flag to be used to specify a .def file for dll creation.
+
+The flag will be used to add a .def file when creating a dll on
+Windows; this is only defined on Windows.
diff --git a/Help/variable/CMAKE_LINK_DEPENDS_NO_SHARED.rst b/Help/variable/CMAKE_LINK_DEPENDS_NO_SHARED.rst
new file mode 100644
index 0000000000..6ae7df68d0
--- /dev/null
+++ b/Help/variable/CMAKE_LINK_DEPENDS_NO_SHARED.rst
@@ -0,0 +1,8 @@
+CMAKE_LINK_DEPENDS_NO_SHARED
+----------------------------
+
+Whether to skip link dependencies on shared library files.
+
+This variable initializes the LINK_DEPENDS_NO_SHARED property on
+targets when they are created. See that target property for
+additional information.
diff --git a/Help/variable/CMAKE_LINK_INTERFACE_LIBRARIES.rst b/Help/variable/CMAKE_LINK_INTERFACE_LIBRARIES.rst
new file mode 100644
index 0000000000..efe6fd74c6
--- /dev/null
+++ b/Help/variable/CMAKE_LINK_INTERFACE_LIBRARIES.rst
@@ -0,0 +1,8 @@
+CMAKE_LINK_INTERFACE_LIBRARIES
+------------------------------
+
+Default value for LINK_INTERFACE_LIBRARIES of targets.
+
+This variable is used to initialize the LINK_INTERFACE_LIBRARIES
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_LINK_LIBRARY_FILE_FLAG.rst b/Help/variable/CMAKE_LINK_LIBRARY_FILE_FLAG.rst
new file mode 100644
index 0000000000..6858e2c15d
--- /dev/null
+++ b/Help/variable/CMAKE_LINK_LIBRARY_FILE_FLAG.rst
@@ -0,0 +1,7 @@
+CMAKE_LINK_LIBRARY_FILE_FLAG
+----------------------------
+
+Flag to be used to link a library specified by a path to its file.
+
+The flag will be used before a library file path is given to the
+linker. This is needed only on very few platforms.
diff --git a/Help/variable/CMAKE_LINK_LIBRARY_FLAG.rst b/Help/variable/CMAKE_LINK_LIBRARY_FLAG.rst
new file mode 100644
index 0000000000..c3e02d7366
--- /dev/null
+++ b/Help/variable/CMAKE_LINK_LIBRARY_FLAG.rst
@@ -0,0 +1,7 @@
+CMAKE_LINK_LIBRARY_FLAG
+-----------------------
+
+Flag to be used to link a library into an executable.
+
+The flag will be used to specify a library to link to an executable.
+On most compilers this is "-l".
diff --git a/Help/variable/CMAKE_LINK_LIBRARY_SUFFIX.rst b/Help/variable/CMAKE_LINK_LIBRARY_SUFFIX.rst
new file mode 100644
index 0000000000..390298d85a
--- /dev/null
+++ b/Help/variable/CMAKE_LINK_LIBRARY_SUFFIX.rst
@@ -0,0 +1,6 @@
+CMAKE_LINK_LIBRARY_SUFFIX
+-------------------------
+
+The suffix for libraries that you link to.
+
+The suffix to use for the end of a library filename, .lib on Windows.
diff --git a/Help/variable/CMAKE_MACOSX_BUNDLE.rst b/Help/variable/CMAKE_MACOSX_BUNDLE.rst
new file mode 100644
index 0000000000..e4768f3694
--- /dev/null
+++ b/Help/variable/CMAKE_MACOSX_BUNDLE.rst
@@ -0,0 +1,7 @@
+CMAKE_MACOSX_BUNDLE
+-------------------
+
+Default value for MACOSX_BUNDLE of targets.
+
+This variable is used to initialize the MACOSX_BUNDLE property on all
+the targets. See that target property for additional information.
diff --git a/Help/variable/CMAKE_MACOSX_RPATH.rst b/Help/variable/CMAKE_MACOSX_RPATH.rst
new file mode 100644
index 0000000000..ac897c0f72
--- /dev/null
+++ b/Help/variable/CMAKE_MACOSX_RPATH.rst
@@ -0,0 +1,7 @@
+CMAKE_MACOSX_RPATH
+-------------------
+
+Whether to use rpaths on Mac OS X.
+
+This variable is used to initialize the :prop_tgt:`MACOSX_RPATH` property on
+all targets.
diff --git a/Help/variable/CMAKE_MAJOR_VERSION.rst b/Help/variable/CMAKE_MAJOR_VERSION.rst
new file mode 100644
index 0000000000..079ad70680
--- /dev/null
+++ b/Help/variable/CMAKE_MAJOR_VERSION.rst
@@ -0,0 +1,5 @@
+CMAKE_MAJOR_VERSION
+-------------------
+
+First version number component of the :variable:`CMAKE_VERSION`
+variable.
diff --git a/Help/variable/CMAKE_MAKE_PROGRAM.rst b/Help/variable/CMAKE_MAKE_PROGRAM.rst
new file mode 100644
index 0000000000..97caa8a647
--- /dev/null
+++ b/Help/variable/CMAKE_MAKE_PROGRAM.rst
@@ -0,0 +1,55 @@
+CMAKE_MAKE_PROGRAM
+------------------
+
+Tool that can launch the native build system.
+The value may be the full path to an executable or just the tool
+name if it is expected to be in the ``PATH``.
+
+The tool selected depends on the :variable:`CMAKE_GENERATOR` used
+to configure the project:
+
+* The Makefile generators set this to ``make``, ``gmake``, or
+ a generator-specific tool (e.g. ``nmake`` for "NMake Makefiles").
+
+ These generators store ``CMAKE_MAKE_PROGRAM`` in the CMake cache
+ so that it may be edited by the user.
+
+* The Ninja generator sets this to ``ninja``.
+
+ This generator stores ``CMAKE_MAKE_PROGRAM`` in the CMake cache
+ so that it may be edited by the user.
+
+* The Xcode generator sets this to ``xcodebuild`` (or possibly an
+ otherwise undocumented ``cmakexbuild`` wrapper implementing some
+ workarounds).
+
+ This generator stores ``CMAKE_MAKE_PROGRAM`` in the CMake cache
+ so that it may be edited by the user.
+
+* The Visual Studio generators set this to the full path to
+ ``MSBuild.exe`` (VS >= 10), ``devenv.com`` (VS 7,8,9),
+ ``VCExpress.exe`` (VS Express 8,9), or ``msdev.exe`` (VS 6).
+ (See also variables
+ :variable:`CMAKE_VS_MSBUILD_COMMAND`,
+ :variable:`CMAKE_VS_DEVENV_COMMAND`, and
+ :variable:`CMAKE_VS_MSDEV_COMMAND`.)
+
+ These generators prefer to lookup the build tool at build time
+ rather than to store ``CMAKE_MAKE_PROGRAM`` in the CMake cache
+ ahead of time. This is because the tools are version-specific
+ and can be located using the Windows Registry. It is also
+ necessary because the proper build tool may depend on the
+ project content (e.g. the Intel Fortran plugin to VS 10 and 11
+ requires ``devenv.com`` to build its ``.vfproj`` project files
+ even though ``MSBuild.exe`` is normally preferred to support
+ the :variable:`CMAKE_GENERATOR_TOOLSET`).
+
+ For compatibility with versions of CMake prior to 3.0, if
+ a user or project explicitly adds ``CMAKE_MAKE_PROGRAM`` to
+ the CMake cache then CMake will use the specified value if
+ possible.
+
+The ``CMAKE_MAKE_PROGRAM`` variable is set for use by project code.
+The value is also used by the :manual:`cmake(1)` ``--build`` and
+:manual:`ctest(1)` ``--build-and-test`` tools to launch the native
+build process.
diff --git a/Help/variable/CMAKE_MAP_IMPORTED_CONFIG_CONFIG.rst b/Help/variable/CMAKE_MAP_IMPORTED_CONFIG_CONFIG.rst
new file mode 100644
index 0000000000..41ccde1c58
--- /dev/null
+++ b/Help/variable/CMAKE_MAP_IMPORTED_CONFIG_CONFIG.rst
@@ -0,0 +1,8 @@
+CMAKE_MAP_IMPORTED_CONFIG_<CONFIG>
+----------------------------------
+
+Default value for MAP_IMPORTED_CONFIG_<CONFIG> of targets.
+
+This variable is used to initialize the MAP_IMPORTED_CONFIG_<CONFIG>
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_MFC_FLAG.rst b/Help/variable/CMAKE_MFC_FLAG.rst
new file mode 100644
index 0000000000..221d26e4fa
--- /dev/null
+++ b/Help/variable/CMAKE_MFC_FLAG.rst
@@ -0,0 +1,16 @@
+CMAKE_MFC_FLAG
+--------------
+
+Tell cmake to use MFC for an executable or dll.
+
+This can be set in a CMakeLists.txt file and will enable MFC in the
+application. It should be set to 1 for the static MFC library, and 2
+for the shared MFC library. This is used in Visual Studio 6 and 7
+project files. The CMakeSetup dialog used MFC and the CMakeLists.txt
+looks like this:
+
+::
+
+ add_definitions(-D_AFXDLL)
+ set(CMAKE_MFC_FLAG 2)
+ add_executable(CMakeSetup WIN32 ${SRCS})
diff --git a/Help/variable/CMAKE_MINIMUM_REQUIRED_VERSION.rst b/Help/variable/CMAKE_MINIMUM_REQUIRED_VERSION.rst
new file mode 100644
index 0000000000..351de442c7
--- /dev/null
+++ b/Help/variable/CMAKE_MINIMUM_REQUIRED_VERSION.rst
@@ -0,0 +1,7 @@
+CMAKE_MINIMUM_REQUIRED_VERSION
+------------------------------
+
+Version specified to cmake_minimum_required command
+
+Variable containing the VERSION component specified in the
+cmake_minimum_required command.
diff --git a/Help/variable/CMAKE_MINOR_VERSION.rst b/Help/variable/CMAKE_MINOR_VERSION.rst
new file mode 100644
index 0000000000..f67cfb9557
--- /dev/null
+++ b/Help/variable/CMAKE_MINOR_VERSION.rst
@@ -0,0 +1,5 @@
+CMAKE_MINOR_VERSION
+-------------------
+
+Second version number component of the :variable:`CMAKE_VERSION`
+variable.
diff --git a/Help/variable/CMAKE_MODULE_LINKER_FLAGS.rst b/Help/variable/CMAKE_MODULE_LINKER_FLAGS.rst
new file mode 100644
index 0000000000..6372bbdb99
--- /dev/null
+++ b/Help/variable/CMAKE_MODULE_LINKER_FLAGS.rst
@@ -0,0 +1,6 @@
+CMAKE_MODULE_LINKER_FLAGS
+-------------------------
+
+Linker flags to be used to create modules.
+
+These flags will be used by the linker when creating a module.
diff --git a/Help/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG.rst b/Help/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG.rst
new file mode 100644
index 0000000000..87a19011f0
--- /dev/null
+++ b/Help/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG.rst
@@ -0,0 +1,6 @@
+CMAKE_MODULE_LINKER_FLAGS_<CONFIG>
+----------------------------------
+
+Flags to be used when linking a module.
+
+Same as CMAKE_C_FLAGS_* but used by the linker when creating modules.
diff --git a/Help/variable/CMAKE_MODULE_PATH.rst b/Help/variable/CMAKE_MODULE_PATH.rst
new file mode 100644
index 0000000000..a2dde4537b
--- /dev/null
+++ b/Help/variable/CMAKE_MODULE_PATH.rst
@@ -0,0 +1,8 @@
+CMAKE_MODULE_PATH
+-----------------
+
+List of directories to search for CMake modules.
+
+Commands like include() and find_package() search for files in
+directories listed by this variable before checking the default
+modules that come with CMake.
diff --git a/Help/variable/CMAKE_NOT_USING_CONFIG_FLAGS.rst b/Help/variable/CMAKE_NOT_USING_CONFIG_FLAGS.rst
new file mode 100644
index 0000000000..cbe035022a
--- /dev/null
+++ b/Help/variable/CMAKE_NOT_USING_CONFIG_FLAGS.rst
@@ -0,0 +1,7 @@
+CMAKE_NOT_USING_CONFIG_FLAGS
+----------------------------
+
+Skip _BUILD_TYPE flags if true.
+
+This is an internal flag used by the generators in CMake to tell CMake
+to skip the _BUILD_TYPE flags.
diff --git a/Help/variable/CMAKE_NO_BUILTIN_CHRPATH.rst b/Help/variable/CMAKE_NO_BUILTIN_CHRPATH.rst
new file mode 100644
index 0000000000..189f59fa3b
--- /dev/null
+++ b/Help/variable/CMAKE_NO_BUILTIN_CHRPATH.rst
@@ -0,0 +1,10 @@
+CMAKE_NO_BUILTIN_CHRPATH
+------------------------
+
+Do not use the builtin ELF editor to fix RPATHs on installation.
+
+When an ELF binary needs to have a different RPATH after installation
+than it does in the build tree, CMake uses a builtin editor to change
+the RPATH in the installed copy. If this variable is set to true then
+CMake will relink the binary before installation instead of using its
+builtin editor.
diff --git a/Help/variable/CMAKE_NO_SYSTEM_FROM_IMPORTED.rst b/Help/variable/CMAKE_NO_SYSTEM_FROM_IMPORTED.rst
new file mode 100644
index 0000000000..c1919afd2e
--- /dev/null
+++ b/Help/variable/CMAKE_NO_SYSTEM_FROM_IMPORTED.rst
@@ -0,0 +1,8 @@
+CMAKE_NO_SYSTEM_FROM_IMPORTED
+-----------------------------
+
+Default value for NO_SYSTEM_FROM_IMPORTED of targets.
+
+This variable is used to initialize the NO_SYSTEM_FROM_IMPORTED
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_OBJECT_PATH_MAX.rst b/Help/variable/CMAKE_OBJECT_PATH_MAX.rst
new file mode 100644
index 0000000000..9e30cbbdb4
--- /dev/null
+++ b/Help/variable/CMAKE_OBJECT_PATH_MAX.rst
@@ -0,0 +1,16 @@
+CMAKE_OBJECT_PATH_MAX
+---------------------
+
+Maximum object file full-path length allowed by native build tools.
+
+CMake computes for every source file an object file name that is
+unique to the source file and deterministic with respect to the full
+path to the source file. This allows multiple source files in a
+target to share the same name if they lie in different directories
+without rebuilding when one is added or removed. However, it can
+produce long full paths in a few cases, so CMake shortens the path
+using a hashing scheme when the full path to an object file exceeds a
+limit. CMake has a built-in limit for each platform that is
+sufficient for common tools, but some native tools may have a lower
+limit. This variable may be set to specify the limit explicitly. The
+value must be an integer no less than 128.
diff --git a/Help/variable/CMAKE_OSX_ARCHITECTURES.rst b/Help/variable/CMAKE_OSX_ARCHITECTURES.rst
new file mode 100644
index 0000000000..b9de518627
--- /dev/null
+++ b/Help/variable/CMAKE_OSX_ARCHITECTURES.rst
@@ -0,0 +1,10 @@
+CMAKE_OSX_ARCHITECTURES
+-----------------------
+
+Target specific architectures for OS X.
+
+This variable is used to initialize the :prop_tgt:`OSX_ARCHITECTURES`
+property on each target as it is creaed. See that target property
+for additional information.
+
+.. include:: CMAKE_OSX_VARIABLE.txt
diff --git a/Help/variable/CMAKE_OSX_DEPLOYMENT_TARGET.rst b/Help/variable/CMAKE_OSX_DEPLOYMENT_TARGET.rst
new file mode 100644
index 0000000000..4fb2caa4f2
--- /dev/null
+++ b/Help/variable/CMAKE_OSX_DEPLOYMENT_TARGET.rst
@@ -0,0 +1,13 @@
+CMAKE_OSX_DEPLOYMENT_TARGET
+---------------------------
+
+Specify the minimum version of OS X on which the target binaries are
+to be deployed. CMake uses this value for the ``-mmacosx-version-min``
+flag and to help choose the default SDK
+(see :variable:`CMAKE_OSX_SYSROOT`).
+
+If not set explicitly the value is initialized by the
+``MACOSX_DEPLOYMENT_TARGET`` environment variable, if set,
+and otherwise computed based on the host platform.
+
+.. include:: CMAKE_OSX_VARIABLE.txt
diff --git a/Help/variable/CMAKE_OSX_SYSROOT.rst b/Help/variable/CMAKE_OSX_SYSROOT.rst
new file mode 100644
index 0000000000..f1d58c6b52
--- /dev/null
+++ b/Help/variable/CMAKE_OSX_SYSROOT.rst
@@ -0,0 +1,13 @@
+CMAKE_OSX_SYSROOT
+-----------------
+
+Specify the location or name of the OS X platform SDK to be used.
+CMake uses this value to compute the value of the ``-isysroot`` flag
+or equivalent and to help the ``find_*`` commands locate files in
+the SDK.
+
+If not set explicitly the value is initialized by the ``SDKROOT``
+environment variable, if set, and otherwise computed based on the
+:variable:`CMAKE_OSX_DEPLOYMENT_TARGET` or the host platform.
+
+.. include:: CMAKE_OSX_VARIABLE.txt
diff --git a/Help/variable/CMAKE_OSX_VARIABLE.txt b/Help/variable/CMAKE_OSX_VARIABLE.txt
new file mode 100644
index 0000000000..385f871f3e
--- /dev/null
+++ b/Help/variable/CMAKE_OSX_VARIABLE.txt
@@ -0,0 +1,6 @@
+The value of this variable should be set prior to the first
+:command:`project` or :command:`enable_language` command invocation
+because it may influence configuration of the toolchain and flags.
+It is intended to be set locally by the user creating a build tree.
+
+This variable is ignored on platforms other than OS X.
diff --git a/Help/variable/CMAKE_PARENT_LIST_FILE.rst b/Help/variable/CMAKE_PARENT_LIST_FILE.rst
new file mode 100644
index 0000000000..5566a7222a
--- /dev/null
+++ b/Help/variable/CMAKE_PARENT_LIST_FILE.rst
@@ -0,0 +1,9 @@
+CMAKE_PARENT_LIST_FILE
+----------------------
+
+Full path to the CMake file that included the current one.
+
+While processing a CMake file loaded by include() or find_package()
+this variable contains the full path to the file including it. The
+top of the include stack is always the CMakeLists.txt for the current
+directory. See also CMAKE_CURRENT_LIST_FILE.
diff --git a/Help/variable/CMAKE_PATCH_VERSION.rst b/Help/variable/CMAKE_PATCH_VERSION.rst
new file mode 100644
index 0000000000..991ae76187
--- /dev/null
+++ b/Help/variable/CMAKE_PATCH_VERSION.rst
@@ -0,0 +1,5 @@
+CMAKE_PATCH_VERSION
+-------------------
+
+Third version number component of the :variable:`CMAKE_VERSION`
+variable.
diff --git a/Help/variable/CMAKE_PDB_OUTPUT_DIRECTORY.rst b/Help/variable/CMAKE_PDB_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..763bcb34f0
--- /dev/null
+++ b/Help/variable/CMAKE_PDB_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,9 @@
+CMAKE_PDB_OUTPUT_DIRECTORY
+--------------------------
+
+Output directory for MS debug symbol ``.pdb`` files generated by the
+linker for executable and shared library targets.
+
+This variable is used to initialize the :prop_tgt:`PDB_OUTPUT_DIRECTORY`
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_PDB_OUTPUT_DIRECTORY_CONFIG.rst b/Help/variable/CMAKE_PDB_OUTPUT_DIRECTORY_CONFIG.rst
new file mode 100644
index 0000000000..4d18eec5dc
--- /dev/null
+++ b/Help/variable/CMAKE_PDB_OUTPUT_DIRECTORY_CONFIG.rst
@@ -0,0 +1,11 @@
+CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG>
+-----------------------------------
+
+Per-configuration output directory for MS debug symbol ``.pdb`` files
+generated by the linker for executable and shared library targets.
+
+This is a per-configuration version of :variable:`CMAKE_PDB_OUTPUT_DIRECTORY`.
+This variable is used to initialize the
+:prop_tgt:`PDB_OUTPUT_DIRECTORY_<CONFIG>`
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_POLICY_DEFAULT_CMPNNNN.rst b/Help/variable/CMAKE_POLICY_DEFAULT_CMPNNNN.rst
new file mode 100644
index 0000000000..e401aa5000
--- /dev/null
+++ b/Help/variable/CMAKE_POLICY_DEFAULT_CMPNNNN.rst
@@ -0,0 +1,16 @@
+CMAKE_POLICY_DEFAULT_CMP<NNNN>
+------------------------------
+
+Default for CMake Policy CMP<NNNN> when it is otherwise left unset.
+
+Commands cmake_minimum_required(VERSION) and cmake_policy(VERSION) by
+default leave policies introduced after the given version unset. Set
+CMAKE_POLICY_DEFAULT_CMP<NNNN> to OLD or NEW to specify the default
+for policy CMP<NNNN>, where <NNNN> is the policy number.
+
+This variable should not be set by a project in CMake code; use
+cmake_policy(SET) instead. Users running CMake may set this variable
+in the cache (e.g. -DCMAKE_POLICY_DEFAULT_CMP<NNNN>=<OLD|NEW>) to set
+a policy not otherwise set by the project. Set to OLD to quiet a
+policy warning while using old behavior or to NEW to try building the
+project with new behavior.
diff --git a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
new file mode 100644
index 0000000000..b563aeaec0
--- /dev/null
+++ b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
@@ -0,0 +1,17 @@
+CMAKE_POLICY_WARNING_CMP<NNNN>
+------------------------------
+
+Explicitly enable or disable the warning when CMake Policy ``CMP<NNNN>``
+is not set. This is meaningful only for the few policies that do not
+warn by default:
+
+* ``CMAKE_POLICY_WARNING_CMP0025`` controls the warning for
+ policy :policy:`CMP0025`.
+* ``CMAKE_POLICY_WARNING_CMP0047`` controls the warning for
+ policy :policy:`CMP0047`.
+
+This variable should not be set by a project in CMake code. Project
+developers running CMake may set this variable in their cache to
+enable the warning (e.g. ``-DCMAKE_POLICY_WARNING_CMP<NNNN>=ON``).
+Alternatively, running :manual:`cmake(1)` with the ``--debug-output``
+or ``--trace`` option will also enable the warning.
diff --git a/Help/variable/CMAKE_POSITION_INDEPENDENT_CODE.rst b/Help/variable/CMAKE_POSITION_INDEPENDENT_CODE.rst
new file mode 100644
index 0000000000..5e71665670
--- /dev/null
+++ b/Help/variable/CMAKE_POSITION_INDEPENDENT_CODE.rst
@@ -0,0 +1,8 @@
+CMAKE_POSITION_INDEPENDENT_CODE
+-------------------------------
+
+Default value for POSITION_INDEPENDENT_CODE of targets.
+
+This variable is used to initialize the POSITION_INDEPENDENT_CODE
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_PREFIX_PATH.rst b/Help/variable/CMAKE_PREFIX_PATH.rst
new file mode 100644
index 0000000000..4c21d5e11d
--- /dev/null
+++ b/Help/variable/CMAKE_PREFIX_PATH.rst
@@ -0,0 +1,13 @@
+CMAKE_PREFIX_PATH
+-----------------
+
+Path used for searching by FIND_XXX(), with appropriate suffixes added.
+
+Specifies a path which will be used by the FIND_XXX() commands. It
+contains the "base" directories, the FIND_XXX() commands append
+appropriate subdirectories to the base directories. So FIND_PROGRAM()
+adds /bin to each of the directories in the path, FIND_LIBRARY()
+appends /lib to each of the directories, and FIND_PATH() and
+FIND_FILE() append /include . By default it is empty, it is intended
+to be set by the project. See also CMAKE_SYSTEM_PREFIX_PATH,
+CMAKE_INCLUDE_PATH, CMAKE_LIBRARY_PATH, CMAKE_PROGRAM_PATH.
diff --git a/Help/variable/CMAKE_PROGRAM_PATH.rst b/Help/variable/CMAKE_PROGRAM_PATH.rst
new file mode 100644
index 0000000000..02c5e028d8
--- /dev/null
+++ b/Help/variable/CMAKE_PROGRAM_PATH.rst
@@ -0,0 +1,10 @@
+CMAKE_PROGRAM_PATH
+------------------
+
+Path used for searching by FIND_PROGRAM().
+
+Specifies a path which will be used by FIND_PROGRAM(). FIND_PROGRAM()
+will check each of the contained directories for the existence of the
+program which is currently searched. By default it is empty, it is
+intended to be set by the project. See also
+CMAKE_SYSTEM_PROGRAM_PATH, CMAKE_PREFIX_PATH.
diff --git a/Help/variable/CMAKE_PROJECT_NAME.rst b/Help/variable/CMAKE_PROJECT_NAME.rst
new file mode 100644
index 0000000000..47347051ad
--- /dev/null
+++ b/Help/variable/CMAKE_PROJECT_NAME.rst
@@ -0,0 +1,7 @@
+CMAKE_PROJECT_NAME
+------------------
+
+The name of the current project.
+
+This specifies name of the current project from the closest inherited
+PROJECT command.
diff --git a/Help/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE.rst b/Help/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE.rst
new file mode 100644
index 0000000000..ba9df5a342
--- /dev/null
+++ b/Help/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE.rst
@@ -0,0 +1,6 @@
+CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE
+------------------------------------
+
+A CMake language file or module to be included by the :command:`project`
+command. This is is intended for injecting custom code into project
+builds without modifying their source.
diff --git a/Help/variable/CMAKE_RANLIB.rst b/Help/variable/CMAKE_RANLIB.rst
new file mode 100644
index 0000000000..82672e9ae6
--- /dev/null
+++ b/Help/variable/CMAKE_RANLIB.rst
@@ -0,0 +1,7 @@
+CMAKE_RANLIB
+------------
+
+Name of randomizing tool for static libraries.
+
+This specifies name of the program that randomizes libraries on UNIX,
+not used on Windows, but may be present.
diff --git a/Help/variable/CMAKE_ROOT.rst b/Help/variable/CMAKE_ROOT.rst
new file mode 100644
index 0000000000..f963a7f835
--- /dev/null
+++ b/Help/variable/CMAKE_ROOT.rst
@@ -0,0 +1,8 @@
+CMAKE_ROOT
+----------
+
+Install directory for running cmake.
+
+This is the install root for the running CMake and the Modules
+directory can be found here. This is commonly used in this format:
+${CMAKE_ROOT}/Modules
diff --git a/Help/variable/CMAKE_RUNTIME_OUTPUT_DIRECTORY.rst b/Help/variable/CMAKE_RUNTIME_OUTPUT_DIRECTORY.rst
new file mode 100644
index 0000000000..366ca6679b
--- /dev/null
+++ b/Help/variable/CMAKE_RUNTIME_OUTPUT_DIRECTORY.rst
@@ -0,0 +1,8 @@
+CMAKE_RUNTIME_OUTPUT_DIRECTORY
+------------------------------
+
+Where to put all the RUNTIME targets when built.
+
+This variable is used to initialize the RUNTIME_OUTPUT_DIRECTORY
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_SCRIPT_MODE_FILE.rst b/Help/variable/CMAKE_SCRIPT_MODE_FILE.rst
new file mode 100644
index 0000000000..ad73cc0275
--- /dev/null
+++ b/Help/variable/CMAKE_SCRIPT_MODE_FILE.rst
@@ -0,0 +1,8 @@
+CMAKE_SCRIPT_MODE_FILE
+----------------------
+
+Full path to the -P script file currently being processed.
+
+When run in -P script mode, CMake sets this variable to the full path
+of the script file. When run to configure a CMakeLists.txt file, this
+variable is not set.
diff --git a/Help/variable/CMAKE_SHARED_LIBRARY_PREFIX.rst b/Help/variable/CMAKE_SHARED_LIBRARY_PREFIX.rst
new file mode 100644
index 0000000000..a863e2a6ce
--- /dev/null
+++ b/Help/variable/CMAKE_SHARED_LIBRARY_PREFIX.rst
@@ -0,0 +1,8 @@
+CMAKE_SHARED_LIBRARY_PREFIX
+---------------------------
+
+The prefix for shared libraries that you link to.
+
+The prefix to use for the name of a shared library, lib on UNIX.
+
+CMAKE_SHARED_LIBRARY_PREFIX_<LANG> overrides this for language <LANG>.
diff --git a/Help/variable/CMAKE_SHARED_LIBRARY_SUFFIX.rst b/Help/variable/CMAKE_SHARED_LIBRARY_SUFFIX.rst
new file mode 100644
index 0000000000..c296ecd816
--- /dev/null
+++ b/Help/variable/CMAKE_SHARED_LIBRARY_SUFFIX.rst
@@ -0,0 +1,9 @@
+CMAKE_SHARED_LIBRARY_SUFFIX
+---------------------------
+
+The suffix for shared libraries that you link to.
+
+The suffix to use for the end of a shared library filename, .dll on
+Windows.
+
+CMAKE_SHARED_LIBRARY_SUFFIX_<LANG> overrides this for language <LANG>.
diff --git a/Help/variable/CMAKE_SHARED_LINKER_FLAGS.rst b/Help/variable/CMAKE_SHARED_LINKER_FLAGS.rst
new file mode 100644
index 0000000000..fce950c75d
--- /dev/null
+++ b/Help/variable/CMAKE_SHARED_LINKER_FLAGS.rst
@@ -0,0 +1,6 @@
+CMAKE_SHARED_LINKER_FLAGS
+-------------------------
+
+Linker flags to be used to create shared libraries.
+
+These flags will be used by the linker when creating a shared library.
diff --git a/Help/variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG.rst b/Help/variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG.rst
new file mode 100644
index 0000000000..fedc6264a3
--- /dev/null
+++ b/Help/variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG.rst
@@ -0,0 +1,7 @@
+CMAKE_SHARED_LINKER_FLAGS_<CONFIG>
+----------------------------------
+
+Flags to be used when linking a shared library.
+
+Same as CMAKE_C_FLAGS_* but used by the linker when creating shared
+libraries.
diff --git a/Help/variable/CMAKE_SHARED_MODULE_PREFIX.rst b/Help/variable/CMAKE_SHARED_MODULE_PREFIX.rst
new file mode 100644
index 0000000000..a5a2428b1b
--- /dev/null
+++ b/Help/variable/CMAKE_SHARED_MODULE_PREFIX.rst
@@ -0,0 +1,8 @@
+CMAKE_SHARED_MODULE_PREFIX
+--------------------------
+
+The prefix for loadable modules that you link to.
+
+The prefix to use for the name of a loadable module on this platform.
+
+CMAKE_SHARED_MODULE_PREFIX_<LANG> overrides this for language <LANG>.
diff --git a/Help/variable/CMAKE_SHARED_MODULE_SUFFIX.rst b/Help/variable/CMAKE_SHARED_MODULE_SUFFIX.rst
new file mode 100644
index 0000000000..32a3c3460a
--- /dev/null
+++ b/Help/variable/CMAKE_SHARED_MODULE_SUFFIX.rst
@@ -0,0 +1,9 @@
+CMAKE_SHARED_MODULE_SUFFIX
+--------------------------
+
+The suffix for shared libraries that you link to.
+
+The suffix to use for the end of a loadable module filename on this
+platform
+
+CMAKE_SHARED_MODULE_SUFFIX_<LANG> overrides this for language <LANG>.
diff --git a/Help/variable/CMAKE_SIZEOF_VOID_P.rst b/Help/variable/CMAKE_SIZEOF_VOID_P.rst
new file mode 100644
index 0000000000..2697fad6a5
--- /dev/null
+++ b/Help/variable/CMAKE_SIZEOF_VOID_P.rst
@@ -0,0 +1,8 @@
+CMAKE_SIZEOF_VOID_P
+-------------------
+
+Size of a void pointer.
+
+This is set to the size of a pointer on the machine, and is determined
+by a try compile. If a 64 bit size is found, then the library search
+path is modified to look for 64 bit libraries first.
diff --git a/Help/variable/CMAKE_SKIP_BUILD_RPATH.rst b/Help/variable/CMAKE_SKIP_BUILD_RPATH.rst
new file mode 100644
index 0000000000..8da6100300
--- /dev/null
+++ b/Help/variable/CMAKE_SKIP_BUILD_RPATH.rst
@@ -0,0 +1,10 @@
+CMAKE_SKIP_BUILD_RPATH
+----------------------
+
+Do not include RPATHs in the build tree.
+
+Normally CMake uses the build tree for the RPATH when building
+executables etc on systems that use RPATH. When the software is
+installed the executables etc are relinked by CMake to have the
+install RPATH. If this variable is set to true then the software is
+always built with no RPATH.
diff --git a/Help/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.rst b/Help/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.rst
new file mode 100644
index 0000000000..33ee8a892f
--- /dev/null
+++ b/Help/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.rst
@@ -0,0 +1,11 @@
+CMAKE_SKIP_INSTALL_ALL_DEPENDENCY
+---------------------------------
+
+Don't make the install target depend on the all target.
+
+By default, the "install" target depends on the "all" target. This
+has the effect, that when "make install" is invoked or INSTALL is
+built, first the "all" target is built, then the installation starts.
+If CMAKE_SKIP_INSTALL_ALL_DEPENDENCY is set to TRUE, this dependency
+is not created, so the installation process will start immediately,
+independent from whether the project has been completely built or not.
diff --git a/Help/variable/CMAKE_SKIP_INSTALL_RPATH.rst b/Help/variable/CMAKE_SKIP_INSTALL_RPATH.rst
new file mode 100644
index 0000000000..f16b2120f4
--- /dev/null
+++ b/Help/variable/CMAKE_SKIP_INSTALL_RPATH.rst
@@ -0,0 +1,14 @@
+CMAKE_SKIP_INSTALL_RPATH
+------------------------
+
+Do not include RPATHs in the install tree.
+
+Normally CMake uses the build tree for the RPATH when building
+executables etc on systems that use RPATH. When the software is
+installed the executables etc are relinked by CMake to have the
+install RPATH. If this variable is set to true then the software is
+always installed without RPATH, even if RPATH is enabled when
+building. This can be useful for example to allow running tests from
+the build directory with RPATH enabled before the installation step.
+To omit RPATH in both the build and install steps, use
+CMAKE_SKIP_RPATH instead.
diff --git a/Help/variable/CMAKE_SKIP_INSTALL_RULES.rst b/Help/variable/CMAKE_SKIP_INSTALL_RULES.rst
new file mode 100644
index 0000000000..5eda254425
--- /dev/null
+++ b/Help/variable/CMAKE_SKIP_INSTALL_RULES.rst
@@ -0,0 +1,7 @@
+CMAKE_SKIP_INSTALL_RULES
+------------------------
+
+Whether to disable generation of installation rules.
+
+If TRUE, cmake will neither generate installaton rules nor
+will it generate cmake_install.cmake files. This variable is FALSE by default.
diff --git a/Help/variable/CMAKE_SKIP_RPATH.rst b/Help/variable/CMAKE_SKIP_RPATH.rst
new file mode 100644
index 0000000000..c93f67f53a
--- /dev/null
+++ b/Help/variable/CMAKE_SKIP_RPATH.rst
@@ -0,0 +1,10 @@
+CMAKE_SKIP_RPATH
+----------------
+
+If true, do not add run time path information.
+
+If this is set to TRUE, then the rpath information is not added to
+compiled executables. The default is to add rpath information if the
+platform supports it. This allows for easy running from the build
+tree. To omit RPATH in the install step, but not the build step, use
+CMAKE_SKIP_INSTALL_RPATH instead.
diff --git a/Help/variable/CMAKE_SOURCE_DIR.rst b/Help/variable/CMAKE_SOURCE_DIR.rst
new file mode 100644
index 0000000000..088fa8361c
--- /dev/null
+++ b/Help/variable/CMAKE_SOURCE_DIR.rst
@@ -0,0 +1,8 @@
+CMAKE_SOURCE_DIR
+----------------
+
+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
+CMAKE_BINARY_DIR.
diff --git a/Help/variable/CMAKE_STAGING_PREFIX.rst b/Help/variable/CMAKE_STAGING_PREFIX.rst
new file mode 100644
index 0000000000..c4de7da859
--- /dev/null
+++ b/Help/variable/CMAKE_STAGING_PREFIX.rst
@@ -0,0 +1,13 @@
+CMAKE_STAGING_PREFIX
+--------------------
+
+This variable may be set to a path to install to when cross-compiling. This can
+be useful if the path in :variable:`CMAKE_SYSROOT` is read-only, or otherwise
+should remain pristine.
+
+The CMAKE_STAGING_PREFIX location is also used as a search prefix by the ``find_*``
+commands. This can be controlled by setting the :variable:`CMAKE_FIND_NO_INSTALL_PREFIX`
+variable.
+
+If any RPATH/RUNPATH entries passed to the linker contain the CMAKE_STAGING_PREFIX,
+the matching path fragments are replaced with the :variable:`CMAKE_INSTALL_PREFIX`.
diff --git a/Help/variable/CMAKE_STANDARD_LIBRARIES.rst b/Help/variable/CMAKE_STANDARD_LIBRARIES.rst
new file mode 100644
index 0000000000..9c728cdbc1
--- /dev/null
+++ b/Help/variable/CMAKE_STANDARD_LIBRARIES.rst
@@ -0,0 +1,7 @@
+CMAKE_STANDARD_LIBRARIES
+------------------------
+
+Libraries linked into every executable and shared library.
+
+This is the list of libraries that are linked into all executables and
+libraries.
diff --git a/Help/variable/CMAKE_STATIC_LIBRARY_PREFIX.rst b/Help/variable/CMAKE_STATIC_LIBRARY_PREFIX.rst
new file mode 100644
index 0000000000..0a3095d0b2
--- /dev/null
+++ b/Help/variable/CMAKE_STATIC_LIBRARY_PREFIX.rst
@@ -0,0 +1,8 @@
+CMAKE_STATIC_LIBRARY_PREFIX
+---------------------------
+
+The prefix for static libraries that you link to.
+
+The prefix to use for the name of a static library, lib on UNIX.
+
+CMAKE_STATIC_LIBRARY_PREFIX_<LANG> overrides this for language <LANG>.
diff --git a/Help/variable/CMAKE_STATIC_LIBRARY_SUFFIX.rst b/Help/variable/CMAKE_STATIC_LIBRARY_SUFFIX.rst
new file mode 100644
index 0000000000..4d07671e1d
--- /dev/null
+++ b/Help/variable/CMAKE_STATIC_LIBRARY_SUFFIX.rst
@@ -0,0 +1,9 @@
+CMAKE_STATIC_LIBRARY_SUFFIX
+---------------------------
+
+The suffix for static libraries that you link to.
+
+The suffix to use for the end of a static library filename, .lib on
+Windows.
+
+CMAKE_STATIC_LIBRARY_SUFFIX_<LANG> overrides this for language <LANG>.
diff --git a/Help/variable/CMAKE_STATIC_LINKER_FLAGS.rst b/Help/variable/CMAKE_STATIC_LINKER_FLAGS.rst
new file mode 100644
index 0000000000..9c38673aa4
--- /dev/null
+++ b/Help/variable/CMAKE_STATIC_LINKER_FLAGS.rst
@@ -0,0 +1,6 @@
+CMAKE_STATIC_LINKER_FLAGS
+-------------------------
+
+Linker flags to be used to create static libraries.
+
+These flags will be used by the linker when creating a static library.
diff --git a/Help/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG.rst b/Help/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG.rst
new file mode 100644
index 0000000000..6cde24ddda
--- /dev/null
+++ b/Help/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG.rst
@@ -0,0 +1,7 @@
+CMAKE_STATIC_LINKER_FLAGS_<CONFIG>
+----------------------------------
+
+Flags to be used when linking a static library.
+
+Same as CMAKE_C_FLAGS_* but used by the linker when creating static
+libraries.
diff --git a/Help/variable/CMAKE_SYSROOT.rst b/Help/variable/CMAKE_SYSROOT.rst
new file mode 100644
index 0000000000..7aa04506cd
--- /dev/null
+++ b/Help/variable/CMAKE_SYSROOT.rst
@@ -0,0 +1,12 @@
+CMAKE_SYSROOT
+-------------
+
+Path to pass to the compiler in the ``--sysroot`` flag.
+
+The ``CMAKE_SYSROOT`` content is passed to the compiler in the ``--sysroot``
+flag, if supported. The path is also stripped from the RPATH/RUNPATH if
+necessary on installation. The ``CMAKE_SYSROOT`` is also used to prefix
+paths searched by the ``find_*`` commands.
+
+This variable may only be set in a toolchain file specified by
+the :variable:`CMAKE_TOOLCHAIN_FILE` variable.
diff --git a/Help/variable/CMAKE_SYSTEM.rst b/Help/variable/CMAKE_SYSTEM.rst
new file mode 100644
index 0000000000..23f5980874
--- /dev/null
+++ b/Help/variable/CMAKE_SYSTEM.rst
@@ -0,0 +1,10 @@
+CMAKE_SYSTEM
+------------
+
+Composit Name of OS CMake is compiling for.
+
+This variable is the composite of :variable:`CMAKE_SYSTEM_NAME` and
+:variable:`CMAKE_SYSTEM_VERSION`, e.g.
+``${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}``. If
+:variable:`CMAKE_SYSTEM_VERSION` is not set, then this variable is
+the same as :variable:`CMAKE_SYSTEM_NAME`.
diff --git a/Help/variable/CMAKE_SYSTEM_IGNORE_PATH.rst b/Help/variable/CMAKE_SYSTEM_IGNORE_PATH.rst
new file mode 100644
index 0000000000..9e6b19564c
--- /dev/null
+++ b/Help/variable/CMAKE_SYSTEM_IGNORE_PATH.rst
@@ -0,0 +1,15 @@
+CMAKE_SYSTEM_IGNORE_PATH
+------------------------
+
+Path to be ignored by FIND_XXX() commands.
+
+Specifies directories to be ignored by searches in FIND_XXX()
+commands. This is useful in cross-compiled environments where some
+system directories contain incompatible but possibly linkable
+libraries. For example, on cross-compiled cluster environments, this
+allows a user to ignore directories containing libraries meant for the
+front-end machine that modules like FindX11 (and others) would
+normally search. By default this contains a list of directories
+containing incompatible binaries for the host system. See also
+CMAKE_SYSTEM_PREFIX_PATH, CMAKE_SYSTEM_LIBRARY_PATH,
+CMAKE_SYSTEM_INCLUDE_PATH, and CMAKE_SYSTEM_PROGRAM_PATH.
diff --git a/Help/variable/CMAKE_SYSTEM_INCLUDE_PATH.rst b/Help/variable/CMAKE_SYSTEM_INCLUDE_PATH.rst
new file mode 100644
index 0000000000..1734185ffe
--- /dev/null
+++ b/Help/variable/CMAKE_SYSTEM_INCLUDE_PATH.rst
@@ -0,0 +1,11 @@
+CMAKE_SYSTEM_INCLUDE_PATH
+-------------------------
+
+Path used for searching by FIND_FILE() and FIND_PATH().
+
+Specifies a path which will be used both by FIND_FILE() and
+FIND_PATH(). Both commands will check each of the contained
+directories for the existence of the file which is currently searched.
+By default it contains the standard directories for the current
+system. It is NOT intended to be modified by the project, use
+CMAKE_INCLUDE_PATH for this. See also CMAKE_SYSTEM_PREFIX_PATH.
diff --git a/Help/variable/CMAKE_SYSTEM_LIBRARY_PATH.rst b/Help/variable/CMAKE_SYSTEM_LIBRARY_PATH.rst
new file mode 100644
index 0000000000..4778646cc7
--- /dev/null
+++ b/Help/variable/CMAKE_SYSTEM_LIBRARY_PATH.rst
@@ -0,0 +1,11 @@
+CMAKE_SYSTEM_LIBRARY_PATH
+-------------------------
+
+Path used for searching by FIND_LIBRARY().
+
+Specifies a path which will be used by FIND_LIBRARY(). FIND_LIBRARY()
+will check each of the contained directories for the existence of the
+library which is currently searched. By default it contains the
+standard directories for the current system. It is NOT intended to be
+modified by the project, use CMAKE_LIBRARY_PATH for this. See also
+CMAKE_SYSTEM_PREFIX_PATH.
diff --git a/Help/variable/CMAKE_SYSTEM_NAME.rst b/Help/variable/CMAKE_SYSTEM_NAME.rst
new file mode 100644
index 0000000000..189dc18fcd
--- /dev/null
+++ b/Help/variable/CMAKE_SYSTEM_NAME.rst
@@ -0,0 +1,8 @@
+CMAKE_SYSTEM_NAME
+-----------------
+
+Name of the OS CMake is building for.
+
+This is the name of the OS on which CMake is targeting. This variable
+is the same as :variable:`CMAKE_HOST_SYSTEM_NAME` if you build for the
+host system instead of the target system when cross compiling.
diff --git a/Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst b/Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst
new file mode 100644
index 0000000000..537eaba304
--- /dev/null
+++ b/Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst
@@ -0,0 +1,16 @@
+CMAKE_SYSTEM_PREFIX_PATH
+------------------------
+
+Path used for searching by FIND_XXX(), with appropriate suffixes added.
+
+Specifies a path which will be used by the FIND_XXX() commands. It
+contains the "base" directories, the FIND_XXX() commands append
+appropriate subdirectories to the base directories. So FIND_PROGRAM()
+adds /bin to each of the directories in the path, FIND_LIBRARY()
+appends /lib to each of the directories, and FIND_PATH() and
+FIND_FILE() append /include . By default this contains the standard
+directories for the current system, the CMAKE_INSTALL_PREFIX and
+the :variable:`CMAKE_STAGING_PREFIX`. It is NOT intended to be modified by
+the project, use CMAKE_PREFIX_PATH for this. See also CMAKE_SYSTEM_INCLUDE_PATH,
+CMAKE_SYSTEM_LIBRARY_PATH, CMAKE_SYSTEM_PROGRAM_PATH, and
+CMAKE_SYSTEM_IGNORE_PATH.
diff --git a/Help/variable/CMAKE_SYSTEM_PROCESSOR.rst b/Help/variable/CMAKE_SYSTEM_PROCESSOR.rst
new file mode 100644
index 0000000000..8ad89f128c
--- /dev/null
+++ b/Help/variable/CMAKE_SYSTEM_PROCESSOR.rst
@@ -0,0 +1,8 @@
+CMAKE_SYSTEM_PROCESSOR
+----------------------
+
+The name of the CPU CMake is building for.
+
+This variable is the same as :variable:`CMAKE_HOST_SYSTEM_PROCESSOR` if
+you build for the host system instead of the target system when
+cross compiling.
diff --git a/Help/variable/CMAKE_SYSTEM_PROGRAM_PATH.rst b/Help/variable/CMAKE_SYSTEM_PROGRAM_PATH.rst
new file mode 100644
index 0000000000..e1fad632a9
--- /dev/null
+++ b/Help/variable/CMAKE_SYSTEM_PROGRAM_PATH.rst
@@ -0,0 +1,11 @@
+CMAKE_SYSTEM_PROGRAM_PATH
+-------------------------
+
+Path used for searching by FIND_PROGRAM().
+
+Specifies a path which will be used by FIND_PROGRAM(). FIND_PROGRAM()
+will check each of the contained directories for the existence of the
+program which is currently searched. By default it contains the
+standard directories for the current system. It is NOT intended to be
+modified by the project, use CMAKE_PROGRAM_PATH for this. See also
+CMAKE_SYSTEM_PREFIX_PATH.
diff --git a/Help/variable/CMAKE_SYSTEM_VERSION.rst b/Help/variable/CMAKE_SYSTEM_VERSION.rst
new file mode 100644
index 0000000000..33510bbf99
--- /dev/null
+++ b/Help/variable/CMAKE_SYSTEM_VERSION.rst
@@ -0,0 +1,8 @@
+CMAKE_SYSTEM_VERSION
+--------------------
+
+The OS version CMake is building for.
+
+This variable is the same as :variable:`CMAKE_HOST_SYSTEM_VERSION` if
+you build for the host system instead of the target system when
+cross compiling.
diff --git a/Help/variable/CMAKE_TOOLCHAIN_FILE.rst b/Help/variable/CMAKE_TOOLCHAIN_FILE.rst
new file mode 100644
index 0000000000..e1a65e12b7
--- /dev/null
+++ b/Help/variable/CMAKE_TOOLCHAIN_FILE.rst
@@ -0,0 +1,9 @@
+CMAKE_TOOLCHAIN_FILE
+--------------------
+
+Path to toolchain file supplied to :manual:`cmake(1)`.
+
+This variable is specified on the command line when cross-compiling with CMake.
+It is the path to a file which is read early in the CMake run and which specifies
+locations for compilers and toolchain utilities, and other target platform and
+compiler related information.
diff --git a/Help/variable/CMAKE_TRY_COMPILE_CONFIGURATION.rst b/Help/variable/CMAKE_TRY_COMPILE_CONFIGURATION.rst
new file mode 100644
index 0000000000..a92feab5eb
--- /dev/null
+++ b/Help/variable/CMAKE_TRY_COMPILE_CONFIGURATION.rst
@@ -0,0 +1,9 @@
+CMAKE_TRY_COMPILE_CONFIGURATION
+-------------------------------
+
+Build configuration used for try_compile and try_run projects.
+
+Projects built by try_compile and try_run are built synchronously
+during the CMake configuration step. Therefore a specific build
+configuration must be chosen even if the generated build system
+supports multiple configurations.
diff --git a/Help/variable/CMAKE_TWEAK_VERSION.rst b/Help/variable/CMAKE_TWEAK_VERSION.rst
new file mode 100644
index 0000000000..be2e0500f8
--- /dev/null
+++ b/Help/variable/CMAKE_TWEAK_VERSION.rst
@@ -0,0 +1,11 @@
+CMAKE_TWEAK_VERSION
+-------------------
+
+Defined to ``0`` for compatibility with code written for older
+CMake versions that may have defined higher values.
+
+.. note::
+
+ In CMake versions 2.8.2 through 2.8.12, this variable holds
+ the fourth version number component of the
+ :variable:`CMAKE_VERSION` variable.
diff --git a/Help/variable/CMAKE_USER_MAKE_RULES_OVERRIDE.rst b/Help/variable/CMAKE_USER_MAKE_RULES_OVERRIDE.rst
new file mode 100644
index 0000000000..5a4c86bd10
--- /dev/null
+++ b/Help/variable/CMAKE_USER_MAKE_RULES_OVERRIDE.rst
@@ -0,0 +1,23 @@
+CMAKE_USER_MAKE_RULES_OVERRIDE
+------------------------------
+
+Specify a CMake file that overrides platform information.
+
+CMake loads the specified file while enabling support for each
+language from either the project() or enable_language() commands. It
+is loaded after CMake's builtin compiler and platform information
+modules have been loaded but before the information is used. The file
+may set platform information variables to override CMake's defaults.
+
+This feature is intended for use only in overriding information
+variables that must be set before CMake builds its first test project
+to check that the compiler for a language works. It should not be
+used to load a file in cases that a normal include() will work. Use
+it only as a last resort for behavior that cannot be achieved any
+other way. For example, one may set CMAKE_C_FLAGS_INIT to change the
+default value used to initialize CMAKE_C_FLAGS before it is cached.
+The override file should NOT be used to set anything that could be set
+after languages are enabled, such as variables like
+CMAKE_RUNTIME_OUTPUT_DIRECTORY that affect the placement of binaries.
+Information set in the file will be used for try_compile and try_run
+builds too.
diff --git a/Help/variable/CMAKE_USER_MAKE_RULES_OVERRIDE_LANG.rst b/Help/variable/CMAKE_USER_MAKE_RULES_OVERRIDE_LANG.rst
new file mode 100644
index 0000000000..e6d2c68c64
--- /dev/null
+++ b/Help/variable/CMAKE_USER_MAKE_RULES_OVERRIDE_LANG.rst
@@ -0,0 +1,7 @@
+CMAKE_USER_MAKE_RULES_OVERRIDE_<LANG>
+-------------------------------------
+
+Specify a CMake file that overrides platform information for <LANG>.
+
+This is a language-specific version of CMAKE_USER_MAKE_RULES_OVERRIDE
+loaded only when enabling language <LANG>.
diff --git a/Help/variable/CMAKE_USE_RELATIVE_PATHS.rst b/Help/variable/CMAKE_USE_RELATIVE_PATHS.rst
new file mode 100644
index 0000000000..af6f08c54c
--- /dev/null
+++ b/Help/variable/CMAKE_USE_RELATIVE_PATHS.rst
@@ -0,0 +1,10 @@
+CMAKE_USE_RELATIVE_PATHS
+------------------------
+
+Use relative paths (May not work!).
+
+If this is set to TRUE, then CMake will use relative paths between the
+source and binary tree. This option does not work for more
+complicated projects, and relative paths are used when possible. In
+general, it is not possible to move CMake generated makefiles to a
+different location regardless of the value of this variable.
diff --git a/Help/variable/CMAKE_VERBOSE_MAKEFILE.rst b/Help/variable/CMAKE_VERBOSE_MAKEFILE.rst
new file mode 100644
index 0000000000..2420a25e1e
--- /dev/null
+++ b/Help/variable/CMAKE_VERBOSE_MAKEFILE.rst
@@ -0,0 +1,9 @@
+CMAKE_VERBOSE_MAKEFILE
+----------------------
+
+Enable verbose output from Makefile builds.
+
+This variable is a cache entry initialized (to FALSE) by
+the :command:`project` command. Users may enable the option
+in their local build tree to get more verbose output from
+Makefile builds and show each command line as it is launched.
diff --git a/Help/variable/CMAKE_VERSION.rst b/Help/variable/CMAKE_VERSION.rst
new file mode 100644
index 0000000000..bbb1d91beb
--- /dev/null
+++ b/Help/variable/CMAKE_VERSION.rst
@@ -0,0 +1,51 @@
+CMAKE_VERSION
+-------------
+
+The CMake version string as three non-negative integer components
+separated by ``.`` and possibly followed by ``-`` and other information.
+The first two components represent the feature level and the third
+component represents either a bug-fix level or development date.
+
+Release versions and release candidate versions of CMake use the format::
+
+ <major>.<minor>.<patch>[-rc<n>]
+
+where the ``<patch>`` component is less than ``20000000``. Development
+versions of CMake use the format::
+
+ <major>.<minor>.<date>[-<id>]
+
+where the ``<date>`` component is of format ``CCYYMMDD`` and ``<id>``
+may contain arbitrary text. This represents development as of a
+particular date following the ``<major>.<minor>`` feature release.
+
+Individual component values are also available in variables:
+
+* :variable:`CMAKE_MAJOR_VERSION`
+* :variable:`CMAKE_MINOR_VERSION`
+* :variable:`CMAKE_PATCH_VERSION`
+* :variable:`CMAKE_TWEAK_VERSION`
+
+Use the :command:`if` command ``VERSION_LESS``, ``VERSION_EQUAL``, or
+``VERSION_GREATER`` operators to compare version string values against
+``CMAKE_VERSION`` using a component-wise test. Version component
+values may be 10 or larger so do not attempt to compare version
+strings as floating-point numbers.
+
+.. note::
+
+ CMake versions 2.8.2 through 2.8.12 used three components for the
+ feature level. Release versions represented the bug-fix level in a
+ fourth component, i.e. ``<major>.<minor>.<patch>[.<tweak>][-rc<n>]``.
+ Development versions represented the development date in the fourth
+ component, i.e. ``<major>.<minor>.<patch>.<date>[-<id>]``.
+
+ CMake versions prior to 2.8.2 used three components for the
+ feature level and had no bug-fix component. Release versions
+ used an even-valued second component, i.e.
+ ``<major>.<even-minor>.<patch>[-rc<n>]``. Development versions
+ used an odd-valued second component with the development date as
+ the third component, i.e. ``<major>.<odd-minor>.<date>``.
+
+ The ``CMAKE_VERSION`` variable is defined by CMake 2.6.3 and higher.
+ Earlier versions defined only the individual component variables.
diff --git a/Help/variable/CMAKE_VISIBILITY_INLINES_HIDDEN.rst b/Help/variable/CMAKE_VISIBILITY_INLINES_HIDDEN.rst
new file mode 100644
index 0000000000..f55c7b177b
--- /dev/null
+++ b/Help/variable/CMAKE_VISIBILITY_INLINES_HIDDEN.rst
@@ -0,0 +1,8 @@
+CMAKE_VISIBILITY_INLINES_HIDDEN
+-------------------------------
+
+Default value for VISIBILITY_INLINES_HIDDEN of targets.
+
+This variable is used to initialize the VISIBILITY_INLINES_HIDDEN
+property on all the targets. See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_VS_DEVENV_COMMAND.rst b/Help/variable/CMAKE_VS_DEVENV_COMMAND.rst
new file mode 100644
index 0000000000..14cc50ac61
--- /dev/null
+++ b/Help/variable/CMAKE_VS_DEVENV_COMMAND.rst
@@ -0,0 +1,14 @@
+CMAKE_VS_DEVENV_COMMAND
+-----------------------
+
+The generators for :generator:`Visual Studio 7` and above set this
+variable to the ``devenv.com`` command installed with the corresponding
+Visual Studio version. Note that this variable may be empty on
+Visual Studio Express editions because they do not provide this tool.
+
+This variable is not defined by other generators even if ``devenv.com``
+is installed on the computer.
+
+The :variable:`CMAKE_VS_MSBUILD_COMMAND` is also provided for
+:generator:`Visual Studio 10 2010` and above.
+See also the :variable:`CMAKE_MAKE_PROGRAM` variable.
diff --git a/Help/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION.rst b/Help/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION.rst
new file mode 100644
index 0000000000..7e9d317f1f
--- /dev/null
+++ b/Help/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION.rst
@@ -0,0 +1,7 @@
+CMAKE_VS_INTEL_Fortran_PROJECT_VERSION
+--------------------------------------
+
+When generating for Visual Studio 7 or greater with the Intel Fortran
+plugin installed, this specifies the .vfproj project file format
+version. This is intended for internal use by CMake and should not be
+used by project code.
diff --git a/Help/variable/CMAKE_VS_MSBUILD_COMMAND.rst b/Help/variable/CMAKE_VS_MSBUILD_COMMAND.rst
new file mode 100644
index 0000000000..58f2bef4c3
--- /dev/null
+++ b/Help/variable/CMAKE_VS_MSBUILD_COMMAND.rst
@@ -0,0 +1,13 @@
+CMAKE_VS_MSBUILD_COMMAND
+------------------------
+
+The generators for :generator:`Visual Studio 10 2010` and above set this
+variable to the ``MSBuild.exe`` command installed with the corresponding
+Visual Studio version.
+
+This variable is not defined by other generators even if ``MSBuild.exe``
+is installed on the computer.
+
+The :variable:`CMAKE_VS_DEVENV_COMMAND` is also provided for the
+non-Express editions of Visual Studio.
+See also the :variable:`CMAKE_MAKE_PROGRAM` variable.
diff --git a/Help/variable/CMAKE_VS_MSDEV_COMMAND.rst b/Help/variable/CMAKE_VS_MSDEV_COMMAND.rst
new file mode 100644
index 0000000000..718baaf825
--- /dev/null
+++ b/Help/variable/CMAKE_VS_MSDEV_COMMAND.rst
@@ -0,0 +1,10 @@
+CMAKE_VS_MSDEV_COMMAND
+----------------------
+
+The :generator:`Visual Studio 6` generator sets this variable to the
+``msdev.exe`` command installed with Visual Studio 6.
+
+This variable is not defined by other generators even if ``msdev.exe``
+is installed on the computer.
+
+See also the :variable:`CMAKE_MAKE_PROGRAM` variable.
diff --git a/Help/variable/CMAKE_VS_NsightTegra_VERSION.rst b/Help/variable/CMAKE_VS_NsightTegra_VERSION.rst
new file mode 100644
index 0000000000..386c3a9de6
--- /dev/null
+++ b/Help/variable/CMAKE_VS_NsightTegra_VERSION.rst
@@ -0,0 +1,7 @@
+CMAKE_VS_NsightTegra_VERSION
+----------------------------
+
+When using a Visual Studio generator with the
+:variable:`CMAKE_SYSTEM_NAME` variable set to ``Android``,
+this variable contains the version number of the
+installed NVIDIA Nsight Tegra Visual Studio Edition.
diff --git a/Help/variable/CMAKE_VS_PLATFORM_NAME.rst b/Help/variable/CMAKE_VS_PLATFORM_NAME.rst
new file mode 100644
index 0000000000..c6f8d411cc
--- /dev/null
+++ b/Help/variable/CMAKE_VS_PLATFORM_NAME.rst
@@ -0,0 +1,7 @@
+CMAKE_VS_PLATFORM_NAME
+----------------------
+
+Visual Studio target platform name.
+
+VS 8 and above allow project files to specify a target platform.
+CMake provides the name of the chosen platform in this variable.
diff --git a/Help/variable/CMAKE_VS_PLATFORM_TOOLSET.rst b/Help/variable/CMAKE_VS_PLATFORM_TOOLSET.rst
new file mode 100644
index 0000000000..08c6061725
--- /dev/null
+++ b/Help/variable/CMAKE_VS_PLATFORM_TOOLSET.rst
@@ -0,0 +1,10 @@
+CMAKE_VS_PLATFORM_TOOLSET
+-------------------------
+
+Visual Studio Platform Toolset name.
+
+VS 10 and above use MSBuild under the hood and support multiple
+compiler toolchains. CMake may specify a toolset explicitly, such as
+"v110" for VS 11 or "Windows7.1SDK" for 64-bit support in VS 10
+Express. CMake provides the name of the chosen toolset in this
+variable.
diff --git a/Help/variable/CMAKE_WARN_DEPRECATED.rst b/Help/variable/CMAKE_WARN_DEPRECATED.rst
new file mode 100644
index 0000000000..7b2510b667
--- /dev/null
+++ b/Help/variable/CMAKE_WARN_DEPRECATED.rst
@@ -0,0 +1,7 @@
+CMAKE_WARN_DEPRECATED
+---------------------
+
+Whether to issue deprecation warnings for macros and functions.
+
+If TRUE, this can be used by macros and functions to issue deprecation
+warnings. This variable is FALSE by default.
diff --git a/Help/variable/CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION.rst b/Help/variable/CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION.rst
new file mode 100644
index 0000000000..f6a188d1c9
--- /dev/null
+++ b/Help/variable/CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION.rst
@@ -0,0 +1,8 @@
+CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION
+------------------------------------------
+
+Ask cmake_install.cmake script to warn each time a file with absolute INSTALL DESTINATION is encountered.
+
+This variable is used by CMake-generated cmake_install.cmake scripts.
+If one sets this variable to ON while running the script, it may get
+warning messages from the script.
diff --git a/Help/variable/CMAKE_WIN32_EXECUTABLE.rst b/Help/variable/CMAKE_WIN32_EXECUTABLE.rst
new file mode 100644
index 0000000000..3e1e0dd71e
--- /dev/null
+++ b/Help/variable/CMAKE_WIN32_EXECUTABLE.rst
@@ -0,0 +1,7 @@
+CMAKE_WIN32_EXECUTABLE
+----------------------
+
+Default value for WIN32_EXECUTABLE of targets.
+
+This variable is used to initialize the WIN32_EXECUTABLE property on
+all the targets. See that target property for additional information.
diff --git a/Help/variable/CMAKE_XCODE_PLATFORM_TOOLSET.rst b/Help/variable/CMAKE_XCODE_PLATFORM_TOOLSET.rst
new file mode 100644
index 0000000000..f0a4841f7f
--- /dev/null
+++ b/Help/variable/CMAKE_XCODE_PLATFORM_TOOLSET.rst
@@ -0,0 +1,9 @@
+CMAKE_XCODE_PLATFORM_TOOLSET
+----------------------------
+
+Xcode compiler selection.
+
+Xcode supports selection of a compiler from one of the installed
+toolsets. CMake provides the name of the chosen toolset in this
+variable, if any is explicitly selected (e.g. via the cmake -T
+option).
diff --git a/Help/variable/CPACK_ABSOLUTE_DESTINATION_FILES.rst b/Help/variable/CPACK_ABSOLUTE_DESTINATION_FILES.rst
new file mode 100644
index 0000000000..d83662937f
--- /dev/null
+++ b/Help/variable/CPACK_ABSOLUTE_DESTINATION_FILES.rst
@@ -0,0 +1,10 @@
+CPACK_ABSOLUTE_DESTINATION_FILES
+--------------------------------
+
+List of files which have been installed using an ABSOLUTE DESTINATION path.
+
+This variable is a Read-Only variable which is set internally by CPack
+during installation and before packaging using
+CMAKE_ABSOLUTE_DESTINATION_FILES defined in cmake_install.cmake
+scripts. The value can be used within CPack project configuration
+file and/or CPack<GEN>.cmake file of <GEN> generator.
diff --git a/Help/variable/CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY.rst b/Help/variable/CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY.rst
new file mode 100644
index 0000000000..e938978040
--- /dev/null
+++ b/Help/variable/CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY.rst
@@ -0,0 +1,8 @@
+CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY
+------------------------------------------
+
+Boolean toggle to include/exclude top level directory (component case).
+
+Similar usage as CPACK_INCLUDE_TOPLEVEL_DIRECTORY but for the
+component case. See CPACK_INCLUDE_TOPLEVEL_DIRECTORY documentation
+for the detail.
diff --git a/Help/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst b/Help/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst
new file mode 100644
index 0000000000..4d96385342
--- /dev/null
+++ b/Help/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst
@@ -0,0 +1,10 @@
+CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
+-------------------------------------------
+
+Ask CPack to error out as soon as a file with absolute INSTALL DESTINATION is encountered.
+
+The fatal error is emitted before the installation of the offending
+file takes place. Some CPack generators, like NSIS,enforce this
+internally. This variable triggers the definition
+ofCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION when CPack runsVariables
+common to all CPack generators
diff --git a/Help/variable/CPACK_INCLUDE_TOPLEVEL_DIRECTORY.rst b/Help/variable/CPACK_INCLUDE_TOPLEVEL_DIRECTORY.rst
new file mode 100644
index 0000000000..4f96bff57c
--- /dev/null
+++ b/Help/variable/CPACK_INCLUDE_TOPLEVEL_DIRECTORY.rst
@@ -0,0 +1,19 @@
+CPACK_INCLUDE_TOPLEVEL_DIRECTORY
+--------------------------------
+
+Boolean toggle to include/exclude top level directory.
+
+When preparing a package CPack installs the item under the so-called
+top level directory. The purpose of is to include (set to 1 or ON or
+TRUE) the top level directory in the package or not (set to 0 or OFF
+or FALSE).
+
+Each CPack generator has a built-in default value for this variable.
+E.g. Archive generators (ZIP, TGZ, ...) includes the top level
+whereas RPM or DEB don't. The user may override the default value by
+setting this variable.
+
+There is a similar variable CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY
+which may be used to override the behavior for the component packaging
+case which may have different default value for historical (now
+backward compatibility) reason.
diff --git a/Help/variable/CPACK_INSTALL_SCRIPT.rst b/Help/variable/CPACK_INSTALL_SCRIPT.rst
new file mode 100644
index 0000000000..59b8cd724f
--- /dev/null
+++ b/Help/variable/CPACK_INSTALL_SCRIPT.rst
@@ -0,0 +1,8 @@
+CPACK_INSTALL_SCRIPT
+--------------------
+
+Extra CMake script provided by the user.
+
+If set this CMake script will be executed by CPack during its local
+[CPack-private] installation which is done right before packaging the
+files. The script is not called by e.g.: make install.
diff --git a/Help/variable/CPACK_PACKAGING_INSTALL_PREFIX.rst b/Help/variable/CPACK_PACKAGING_INSTALL_PREFIX.rst
new file mode 100644
index 0000000000..f9cfa1b88f
--- /dev/null
+++ b/Help/variable/CPACK_PACKAGING_INSTALL_PREFIX.rst
@@ -0,0 +1,13 @@
+CPACK_PACKAGING_INSTALL_PREFIX
+------------------------------
+
+The prefix used in the built package.
+
+Each CPack generator has a default value (like /usr). This default
+value may be overwritten from the CMakeLists.txt or the cpack command
+line by setting an alternative value.
+
+e.g. set(CPACK_PACKAGING_INSTALL_PREFIX "/opt")
+
+This is not the same purpose as CMAKE_INSTALL_PREFIX which is used
+when installing from the build tree without building a package.
diff --git a/Help/variable/CPACK_SET_DESTDIR.rst b/Help/variable/CPACK_SET_DESTDIR.rst
new file mode 100644
index 0000000000..69d82e6dcf
--- /dev/null
+++ b/Help/variable/CPACK_SET_DESTDIR.rst
@@ -0,0 +1,30 @@
+CPACK_SET_DESTDIR
+-----------------
+
+Boolean toggle to make CPack use DESTDIR mechanism when packaging.
+
+DESTDIR means DESTination DIRectory. It is commonly used by makefile
+users in order to install software at non-default location. It is a
+basic relocation mechanism that should not be used on Windows (see
+CMAKE_INSTALL_PREFIX documentation). It is usually invoked like this:
+
+::
+
+ make DESTDIR=/home/john install
+
+which will install the concerned software using the installation
+prefix, e.g. "/usr/local" prepended with the DESTDIR value which
+finally gives "/home/john/usr/local". When preparing a package, CPack
+first installs the items to be packaged in a local (to the build tree)
+directory by using the same DESTDIR mechanism. Nevertheless, if
+CPACK_SET_DESTDIR is set then CPack will set DESTDIR before doing the
+local install. The most noticeable difference is that without
+CPACK_SET_DESTDIR, CPack uses CPACK_PACKAGING_INSTALL_PREFIX as a
+prefix whereas with CPACK_SET_DESTDIR set, CPack will use
+CMAKE_INSTALL_PREFIX as a prefix.
+
+Manually setting CPACK_SET_DESTDIR may help (or simply be necessary)
+if some install rules uses absolute DESTINATION (see CMake INSTALL
+command). However, starting with CPack/CMake 2.8.3 RPM and DEB
+installers tries to handle DESTDIR automatically so that it is seldom
+necessary for the user to set it.
diff --git a/Help/variable/CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION.rst b/Help/variable/CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION.rst
new file mode 100644
index 0000000000..8d6f54fc1c
--- /dev/null
+++ b/Help/variable/CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION.rst
@@ -0,0 +1,8 @@
+CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION
+------------------------------------------
+
+Ask CPack to warn each time a file with absolute INSTALL DESTINATION is encountered.
+
+This variable triggers the definition of
+CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION when CPack runs
+cmake_install.cmake scripts.
diff --git a/Help/variable/CTEST_BINARY_DIRECTORY.rst b/Help/variable/CTEST_BINARY_DIRECTORY.rst
new file mode 100644
index 0000000000..fd8461fd6a
--- /dev/null
+++ b/Help/variable/CTEST_BINARY_DIRECTORY.rst
@@ -0,0 +1,5 @@
+CTEST_BINARY_DIRECTORY
+----------------------
+
+Specify the CTest ``BuildDirectory`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_BUILD_COMMAND.rst b/Help/variable/CTEST_BUILD_COMMAND.rst
new file mode 100644
index 0000000000..7b13ba06bb
--- /dev/null
+++ b/Help/variable/CTEST_BUILD_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_BUILD_COMMAND
+-------------------
+
+Specify the CTest ``MakeCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_BUILD_NAME.rst b/Help/variable/CTEST_BUILD_NAME.rst
new file mode 100644
index 0000000000..d25d84c0a8
--- /dev/null
+++ b/Help/variable/CTEST_BUILD_NAME.rst
@@ -0,0 +1,5 @@
+CTEST_BUILD_NAME
+----------------
+
+Specify the CTest ``BuildName`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_BZR_COMMAND.rst b/Help/variable/CTEST_BZR_COMMAND.rst
new file mode 100644
index 0000000000..474d6213e2
--- /dev/null
+++ b/Help/variable/CTEST_BZR_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_BZR_COMMAND
+-----------------
+
+Specify the CTest ``BZRCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_BZR_UPDATE_OPTIONS.rst b/Help/variable/CTEST_BZR_UPDATE_OPTIONS.rst
new file mode 100644
index 0000000000..d0f9579804
--- /dev/null
+++ b/Help/variable/CTEST_BZR_UPDATE_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_BZR_UPDATE_OPTIONS
+------------------------
+
+Specify the CTest ``BZRUpdateOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_CHECKOUT_COMMAND.rst b/Help/variable/CTEST_CHECKOUT_COMMAND.rst
new file mode 100644
index 0000000000..da256f24f5
--- /dev/null
+++ b/Help/variable/CTEST_CHECKOUT_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_CHECKOUT_COMMAND
+----------------------
+
+Tell the :command:`ctest_start` command how to checkout or initialize
+the source directory in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_CONFIGURATION_TYPE.rst b/Help/variable/CTEST_CONFIGURATION_TYPE.rst
new file mode 100644
index 0000000000..c905480c0f
--- /dev/null
+++ b/Help/variable/CTEST_CONFIGURATION_TYPE.rst
@@ -0,0 +1,5 @@
+CTEST_CONFIGURATION_TYPE
+------------------------
+
+Specify the CTest ``DefaultCTestConfigurationType`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_CONFIGURE_COMMAND.rst b/Help/variable/CTEST_CONFIGURE_COMMAND.rst
new file mode 100644
index 0000000000..5561b6dcfe
--- /dev/null
+++ b/Help/variable/CTEST_CONFIGURE_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_CONFIGURE_COMMAND
+-----------------------
+
+Specify the CTest ``ConfigureCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_COVERAGE_COMMAND.rst b/Help/variable/CTEST_COVERAGE_COMMAND.rst
new file mode 100644
index 0000000000..a669dd78de
--- /dev/null
+++ b/Help/variable/CTEST_COVERAGE_COMMAND.rst
@@ -0,0 +1,60 @@
+CTEST_COVERAGE_COMMAND
+----------------------
+
+Specify the CTest ``CoverageCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
+
+Cobertura
+'''''''''
+
+Using `Cobertura`_ as the coverage generation within your multi-module
+Java project can generate a series of XML files.
+
+The Cobertura Coverage parser expects to read the coverage data from a
+single XML file which contains the coverage data for all modules.
+Cobertura has a program with the ability to merge given cobertura.ser files
+and then another program to generate a combined XML file from the previous
+merged file. For command line testing, this can be done by hand prior to
+CTest looking for the coverage files. For script builds,
+set the ``CTEST_COVERAGE_COMMAND`` variable to point to a file which will
+perform these same steps, such as a .sh or .bat file.
+
+.. code-block:: cmake
+
+ set(CTEST_COVERAGE_COMMAND .../run-coverage-and-consolidate.sh)
+
+where the ``run-coverage-and-consolidate.sh`` script is perhaps created by
+the :command:`configure_file` command and might contain the following code:
+
+.. code-block:: bash
+
+ #!/usr/bin/env bash
+ CoberturaFiles="$(find "/path/to/source" -name "cobertura.ser")"
+ SourceDirs="$(find "/path/to/source" -name "java" -type d)"
+ cobertura-merge --datafile coberturamerge.ser $CoberturaFiles
+ cobertura-report --datafile coberturamerge.ser --destination . \
+ --format xml $SourceDirs
+
+The script uses ``find`` to capture the paths to all of the cobertura.ser files
+found below the project's source directory. It keeps the list of files and
+supplies it as an argument to the ``cobertura-merge`` program. The ``--datafile``
+argument signifies where the result of the merge will be kept.
+
+The combined ``coberturamerge.ser`` file is then used to generate the XML report
+using the ``cobertura-report`` program. The call to the cobertura-report program
+requires some named arguments.
+
+``--datafila``
+ path to the merged .ser file
+
+``--destination``
+ path to put the output files(s)
+
+``--format``
+ file format to write output in: xml or html
+
+The rest of the supplied arguments consist of the full paths to the
+/src/main/java directories of each module within the souce tree. These
+directories are needed and should not be forgotten.
+
+.. _`Cobertura`: http://cobertura.github.io/cobertura/
diff --git a/Help/variable/CTEST_COVERAGE_EXTRA_FLAGS.rst b/Help/variable/CTEST_COVERAGE_EXTRA_FLAGS.rst
new file mode 100644
index 0000000000..298195508b
--- /dev/null
+++ b/Help/variable/CTEST_COVERAGE_EXTRA_FLAGS.rst
@@ -0,0 +1,5 @@
+CTEST_COVERAGE_EXTRA_FLAGS
+--------------------------
+
+Specify the CTest ``CoverageExtraFlags`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_CURL_OPTIONS.rst b/Help/variable/CTEST_CURL_OPTIONS.rst
new file mode 100644
index 0000000000..fc5dfc488d
--- /dev/null
+++ b/Help/variable/CTEST_CURL_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_CURL_OPTIONS
+------------------
+
+Specify the CTest ``CurlOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_CVS_CHECKOUT.rst b/Help/variable/CTEST_CVS_CHECKOUT.rst
new file mode 100644
index 0000000000..6431c0266e
--- /dev/null
+++ b/Help/variable/CTEST_CVS_CHECKOUT.rst
@@ -0,0 +1,4 @@
+CTEST_CVS_CHECKOUT
+------------------
+
+Deprecated. Use :variable:`CTEST_CHECKOUT_COMMAND` instead.
diff --git a/Help/variable/CTEST_CVS_COMMAND.rst b/Help/variable/CTEST_CVS_COMMAND.rst
new file mode 100644
index 0000000000..049700b3a1
--- /dev/null
+++ b/Help/variable/CTEST_CVS_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_CVS_COMMAND
+-----------------
+
+Specify the CTest ``CVSCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_CVS_UPDATE_OPTIONS.rst b/Help/variable/CTEST_CVS_UPDATE_OPTIONS.rst
new file mode 100644
index 0000000000..d7f2f7c2c9
--- /dev/null
+++ b/Help/variable/CTEST_CVS_UPDATE_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_CVS_UPDATE_OPTIONS
+------------------------
+
+Specify the CTest ``CVSUpdateOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_DROP_LOCATION.rst b/Help/variable/CTEST_DROP_LOCATION.rst
new file mode 100644
index 0000000000..c0f22158dc
--- /dev/null
+++ b/Help/variable/CTEST_DROP_LOCATION.rst
@@ -0,0 +1,5 @@
+CTEST_DROP_LOCATION
+-------------------
+
+Specify the CTest ``DropLocation`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_DROP_METHOD.rst b/Help/variable/CTEST_DROP_METHOD.rst
new file mode 100644
index 0000000000..50fbd4de9e
--- /dev/null
+++ b/Help/variable/CTEST_DROP_METHOD.rst
@@ -0,0 +1,5 @@
+CTEST_DROP_METHOD
+-----------------
+
+Specify the CTest ``DropMethod`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_DROP_SITE.rst b/Help/variable/CTEST_DROP_SITE.rst
new file mode 100644
index 0000000000..d15d99be24
--- /dev/null
+++ b/Help/variable/CTEST_DROP_SITE.rst
@@ -0,0 +1,5 @@
+CTEST_DROP_SITE
+---------------
+
+Specify the CTest ``DropSite`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_DROP_SITE_CDASH.rst b/Help/variable/CTEST_DROP_SITE_CDASH.rst
new file mode 100644
index 0000000000..22b9776325
--- /dev/null
+++ b/Help/variable/CTEST_DROP_SITE_CDASH.rst
@@ -0,0 +1,5 @@
+CTEST_DROP_SITE_CDASH
+---------------------
+
+Specify the CTest ``IsCDash`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_DROP_SITE_PASSWORD.rst b/Help/variable/CTEST_DROP_SITE_PASSWORD.rst
new file mode 100644
index 0000000000..904d2c8a82
--- /dev/null
+++ b/Help/variable/CTEST_DROP_SITE_PASSWORD.rst
@@ -0,0 +1,5 @@
+CTEST_DROP_SITE_PASSWORD
+------------------------
+
+Specify the CTest ``DropSitePassword`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_DROP_SITE_USER.rst b/Help/variable/CTEST_DROP_SITE_USER.rst
new file mode 100644
index 0000000000..a860a03fe5
--- /dev/null
+++ b/Help/variable/CTEST_DROP_SITE_USER.rst
@@ -0,0 +1,5 @@
+CTEST_DROP_SITE_USER
+--------------------
+
+Specify the CTest ``DropSiteUser`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_GIT_COMMAND.rst b/Help/variable/CTEST_GIT_COMMAND.rst
new file mode 100644
index 0000000000..eb83792ecf
--- /dev/null
+++ b/Help/variable/CTEST_GIT_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_GIT_COMMAND
+-----------------
+
+Specify the CTest ``GITCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_GIT_UPDATE_CUSTOM.rst b/Help/variable/CTEST_GIT_UPDATE_CUSTOM.rst
new file mode 100644
index 0000000000..0c479e604a
--- /dev/null
+++ b/Help/variable/CTEST_GIT_UPDATE_CUSTOM.rst
@@ -0,0 +1,5 @@
+CTEST_GIT_UPDATE_CUSTOM
+-----------------------
+
+Specify the CTest ``GITUpdateCustom`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_GIT_UPDATE_OPTIONS.rst b/Help/variable/CTEST_GIT_UPDATE_OPTIONS.rst
new file mode 100644
index 0000000000..4590a786de
--- /dev/null
+++ b/Help/variable/CTEST_GIT_UPDATE_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_GIT_UPDATE_OPTIONS
+------------------------
+
+Specify the CTest ``GITUpdateOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_HG_COMMAND.rst b/Help/variable/CTEST_HG_COMMAND.rst
new file mode 100644
index 0000000000..3854950af8
--- /dev/null
+++ b/Help/variable/CTEST_HG_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_HG_COMMAND
+----------------
+
+Specify the CTest ``HGCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_HG_UPDATE_OPTIONS.rst b/Help/variable/CTEST_HG_UPDATE_OPTIONS.rst
new file mode 100644
index 0000000000..9049c1f45e
--- /dev/null
+++ b/Help/variable/CTEST_HG_UPDATE_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_HG_UPDATE_OPTIONS
+-----------------------
+
+Specify the CTest ``HGUpdateOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_MEMORYCHECK_COMMAND.rst b/Help/variable/CTEST_MEMORYCHECK_COMMAND.rst
new file mode 100644
index 0000000000..8c199bac20
--- /dev/null
+++ b/Help/variable/CTEST_MEMORYCHECK_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_MEMORYCHECK_COMMAND
+-------------------------
+
+Specify the CTest ``MemoryCheckCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_MEMORYCHECK_COMMAND_OPTIONS.rst b/Help/variable/CTEST_MEMORYCHECK_COMMAND_OPTIONS.rst
new file mode 100644
index 0000000000..3e26ab5151
--- /dev/null
+++ b/Help/variable/CTEST_MEMORYCHECK_COMMAND_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_MEMORYCHECK_COMMAND_OPTIONS
+---------------------------------
+
+Specify the CTest ``MemoryCheckCommandOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_MEMORYCHECK_SANITIZER_OPTIONS.rst b/Help/variable/CTEST_MEMORYCHECK_SANITIZER_OPTIONS.rst
new file mode 100644
index 0000000000..2de5fb6b83
--- /dev/null
+++ b/Help/variable/CTEST_MEMORYCHECK_SANITIZER_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_MEMORYCHECK_SANITIZER_OPTIONS
+-----------------------------------
+
+Specify the CTest ``MemoryCheckSanitizerOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_MEMORYCHECK_SUPPRESSIONS_FILE.rst b/Help/variable/CTEST_MEMORYCHECK_SUPPRESSIONS_FILE.rst
new file mode 100644
index 0000000000..1147ee8e84
--- /dev/null
+++ b/Help/variable/CTEST_MEMORYCHECK_SUPPRESSIONS_FILE.rst
@@ -0,0 +1,5 @@
+CTEST_MEMORYCHECK_SUPPRESSIONS_FILE
+-----------------------------------
+
+Specify the CTest ``MemoryCheckSuppressionFile`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_MEMORYCHECK_TYPE.rst b/Help/variable/CTEST_MEMORYCHECK_TYPE.rst
new file mode 100644
index 0000000000..f1087c0a13
--- /dev/null
+++ b/Help/variable/CTEST_MEMORYCHECK_TYPE.rst
@@ -0,0 +1,7 @@
+CTEST_MEMORYCHECK_TYPE
+----------------------
+
+Specify the CTest ``MemoryCheckType`` setting
+in a :manual:`ctest(1)` dashboard client script.
+Valid values are Valgrind, Purify, BoundsChecker, and ThreadSanitizer,
+AddressSanitizer, MemorySanitizer, and UndefinedBehaviorSanitizer.
diff --git a/Help/variable/CTEST_NIGHTLY_START_TIME.rst b/Help/variable/CTEST_NIGHTLY_START_TIME.rst
new file mode 100644
index 0000000000..bc802764e4
--- /dev/null
+++ b/Help/variable/CTEST_NIGHTLY_START_TIME.rst
@@ -0,0 +1,5 @@
+CTEST_NIGHTLY_START_TIME
+------------------------
+
+Specify the CTest ``NightlyStartTime`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_P4_CLIENT.rst b/Help/variable/CTEST_P4_CLIENT.rst
new file mode 100644
index 0000000000..347ea549e5
--- /dev/null
+++ b/Help/variable/CTEST_P4_CLIENT.rst
@@ -0,0 +1,5 @@
+CTEST_P4_CLIENT
+---------------
+
+Specify the CTest ``P4Client`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_P4_COMMAND.rst b/Help/variable/CTEST_P4_COMMAND.rst
new file mode 100644
index 0000000000..defab12be9
--- /dev/null
+++ b/Help/variable/CTEST_P4_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_P4_COMMAND
+----------------
+
+Specify the CTest ``P4Command`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_P4_OPTIONS.rst b/Help/variable/CTEST_P4_OPTIONS.rst
new file mode 100644
index 0000000000..fee4ce2d80
--- /dev/null
+++ b/Help/variable/CTEST_P4_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_P4_OPTIONS
+----------------
+
+Specify the CTest ``P4Options`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_P4_UPDATE_OPTIONS.rst b/Help/variable/CTEST_P4_UPDATE_OPTIONS.rst
new file mode 100644
index 0000000000..0e2790fb56
--- /dev/null
+++ b/Help/variable/CTEST_P4_UPDATE_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_P4_UPDATE_OPTIONS
+-----------------------
+
+Specify the CTest ``P4UpdateOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_SCP_COMMAND.rst b/Help/variable/CTEST_SCP_COMMAND.rst
new file mode 100644
index 0000000000..0f128b14af
--- /dev/null
+++ b/Help/variable/CTEST_SCP_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_SCP_COMMAND
+-----------------
+
+Specify the CTest ``SCPCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_SITE.rst b/Help/variable/CTEST_SITE.rst
new file mode 100644
index 0000000000..8a5ec253d6
--- /dev/null
+++ b/Help/variable/CTEST_SITE.rst
@@ -0,0 +1,5 @@
+CTEST_SITE
+----------
+
+Specify the CTest ``Site`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_SOURCE_DIRECTORY.rst b/Help/variable/CTEST_SOURCE_DIRECTORY.rst
new file mode 100644
index 0000000000..b6837d1a0d
--- /dev/null
+++ b/Help/variable/CTEST_SOURCE_DIRECTORY.rst
@@ -0,0 +1,5 @@
+CTEST_SOURCE_DIRECTORY
+----------------------
+
+Specify the CTest ``SourceDirectory`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_SVN_COMMAND.rst b/Help/variable/CTEST_SVN_COMMAND.rst
new file mode 100644
index 0000000000..af9014361f
--- /dev/null
+++ b/Help/variable/CTEST_SVN_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_SVN_COMMAND
+-----------------
+
+Specify the CTest ``SVNCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_SVN_OPTIONS.rst b/Help/variable/CTEST_SVN_OPTIONS.rst
new file mode 100644
index 0000000000..76551dc110
--- /dev/null
+++ b/Help/variable/CTEST_SVN_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_SVN_OPTIONS
+-----------------
+
+Specify the CTest ``SVNOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_SVN_UPDATE_OPTIONS.rst b/Help/variable/CTEST_SVN_UPDATE_OPTIONS.rst
new file mode 100644
index 0000000000..5f01a193a0
--- /dev/null
+++ b/Help/variable/CTEST_SVN_UPDATE_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_SVN_UPDATE_OPTIONS
+------------------------
+
+Specify the CTest ``SVNUpdateOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_TEST_TIMEOUT.rst b/Help/variable/CTEST_TEST_TIMEOUT.rst
new file mode 100644
index 0000000000..c031437f0c
--- /dev/null
+++ b/Help/variable/CTEST_TEST_TIMEOUT.rst
@@ -0,0 +1,5 @@
+CTEST_TEST_TIMEOUT
+------------------
+
+Specify the CTest ``TimeOut`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_TRIGGER_SITE.rst b/Help/variable/CTEST_TRIGGER_SITE.rst
new file mode 100644
index 0000000000..de9242807b
--- /dev/null
+++ b/Help/variable/CTEST_TRIGGER_SITE.rst
@@ -0,0 +1,5 @@
+CTEST_TRIGGER_SITE
+------------------
+
+Specify the CTest ``TriggerSite`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_UPDATE_COMMAND.rst b/Help/variable/CTEST_UPDATE_COMMAND.rst
new file mode 100644
index 0000000000..90155d07f2
--- /dev/null
+++ b/Help/variable/CTEST_UPDATE_COMMAND.rst
@@ -0,0 +1,5 @@
+CTEST_UPDATE_COMMAND
+--------------------
+
+Specify the CTest ``UpdateCommand`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_UPDATE_OPTIONS.rst b/Help/variable/CTEST_UPDATE_OPTIONS.rst
new file mode 100644
index 0000000000..e43d61d1cd
--- /dev/null
+++ b/Help/variable/CTEST_UPDATE_OPTIONS.rst
@@ -0,0 +1,5 @@
+CTEST_UPDATE_OPTIONS
+--------------------
+
+Specify the CTest ``UpdateOptions`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_UPDATE_VERSION_ONLY.rst b/Help/variable/CTEST_UPDATE_VERSION_ONLY.rst
new file mode 100644
index 0000000000..e646e6eeab
--- /dev/null
+++ b/Help/variable/CTEST_UPDATE_VERSION_ONLY.rst
@@ -0,0 +1,5 @@
+CTEST_UPDATE_VERSION_ONLY
+-------------------------
+
+Specify the CTest ``UpdateVersionOnly`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CTEST_USE_LAUNCHERS.rst b/Help/variable/CTEST_USE_LAUNCHERS.rst
new file mode 100644
index 0000000000..9f48a2e426
--- /dev/null
+++ b/Help/variable/CTEST_USE_LAUNCHERS.rst
@@ -0,0 +1,5 @@
+CTEST_USE_LAUNCHERS
+-------------------
+
+Specify the CTest ``UseLaunchers`` setting
+in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/CYGWIN.rst b/Help/variable/CYGWIN.rst
new file mode 100644
index 0000000000..c16887855a
--- /dev/null
+++ b/Help/variable/CYGWIN.rst
@@ -0,0 +1,6 @@
+CYGWIN
+------
+
+True for Cygwin.
+
+Set to true when using Cygwin.
diff --git a/Help/variable/ENV.rst b/Help/variable/ENV.rst
new file mode 100644
index 0000000000..977afc3c2a
--- /dev/null
+++ b/Help/variable/ENV.rst
@@ -0,0 +1,7 @@
+ENV
+---
+
+Access environment variables.
+
+Use the syntax $ENV{VAR} to read environment variable VAR. See also
+the set() command to set ENV{VAR}.
diff --git a/Help/variable/EXECUTABLE_OUTPUT_PATH.rst b/Help/variable/EXECUTABLE_OUTPUT_PATH.rst
new file mode 100644
index 0000000000..7079230566
--- /dev/null
+++ b/Help/variable/EXECUTABLE_OUTPUT_PATH.rst
@@ -0,0 +1,8 @@
+EXECUTABLE_OUTPUT_PATH
+----------------------
+
+Old executable location variable.
+
+The target property RUNTIME_OUTPUT_DIRECTORY supercedes this variable
+for a target if it is set. Executable targets are otherwise placed in
+this directory.
diff --git a/Help/variable/LIBRARY_OUTPUT_PATH.rst b/Help/variable/LIBRARY_OUTPUT_PATH.rst
new file mode 100644
index 0000000000..1c1f8ae9a7
--- /dev/null
+++ b/Help/variable/LIBRARY_OUTPUT_PATH.rst
@@ -0,0 +1,9 @@
+LIBRARY_OUTPUT_PATH
+-------------------
+
+Old library location variable.
+
+The target properties ARCHIVE_OUTPUT_DIRECTORY,
+LIBRARY_OUTPUT_DIRECTORY, and RUNTIME_OUTPUT_DIRECTORY supercede this
+variable for a target if they are set. Library targets are otherwise
+placed in this directory.
diff --git a/Help/variable/MSVC.rst b/Help/variable/MSVC.rst
new file mode 100644
index 0000000000..e9f931b508
--- /dev/null
+++ b/Help/variable/MSVC.rst
@@ -0,0 +1,6 @@
+MSVC
+----
+
+True when using Microsoft Visual C
+
+Set to true when the compiler is some version of Microsoft Visual C.
diff --git a/Help/variable/MSVC10.rst b/Help/variable/MSVC10.rst
new file mode 100644
index 0000000000..894c5aab08
--- /dev/null
+++ b/Help/variable/MSVC10.rst
@@ -0,0 +1,6 @@
+MSVC10
+------
+
+True when using Microsoft Visual C 10.0
+
+Set to true when the compiler is version 10.0 of Microsoft Visual C.
diff --git a/Help/variable/MSVC11.rst b/Help/variable/MSVC11.rst
new file mode 100644
index 0000000000..fe25297535
--- /dev/null
+++ b/Help/variable/MSVC11.rst
@@ -0,0 +1,6 @@
+MSVC11
+------
+
+True when using Microsoft Visual C 11.0
+
+Set to true when the compiler is version 11.0 of Microsoft Visual C.
diff --git a/Help/variable/MSVC12.rst b/Help/variable/MSVC12.rst
new file mode 100644
index 0000000000..216d3d3222
--- /dev/null
+++ b/Help/variable/MSVC12.rst
@@ -0,0 +1,6 @@
+MSVC12
+------
+
+True when using Microsoft Visual C 12.0
+
+Set to true when the compiler is version 12.0 of Microsoft Visual C.
diff --git a/Help/variable/MSVC14.rst b/Help/variable/MSVC14.rst
new file mode 100644
index 0000000000..33c782b746
--- /dev/null
+++ b/Help/variable/MSVC14.rst
@@ -0,0 +1,6 @@
+MSVC14
+------
+
+True when using Microsoft Visual C 14.0
+
+Set to true when the compiler is version 14.0 of Microsoft Visual C.
diff --git a/Help/variable/MSVC60.rst b/Help/variable/MSVC60.rst
new file mode 100644
index 0000000000..572e9f47fb
--- /dev/null
+++ b/Help/variable/MSVC60.rst
@@ -0,0 +1,6 @@
+MSVC60
+------
+
+True when using Microsoft Visual C 6.0
+
+Set to true when the compiler is version 6.0 of Microsoft Visual C.
diff --git a/Help/variable/MSVC70.rst b/Help/variable/MSVC70.rst
new file mode 100644
index 0000000000..b1b7a8817d
--- /dev/null
+++ b/Help/variable/MSVC70.rst
@@ -0,0 +1,6 @@
+MSVC70
+------
+
+True when using Microsoft Visual C 7.0
+
+Set to true when the compiler is version 7.0 of Microsoft Visual C.
diff --git a/Help/variable/MSVC71.rst b/Help/variable/MSVC71.rst
new file mode 100644
index 0000000000..af309a6a67
--- /dev/null
+++ b/Help/variable/MSVC71.rst
@@ -0,0 +1,6 @@
+MSVC71
+------
+
+True when using Microsoft Visual C 7.1
+
+Set to true when the compiler is version 7.1 of Microsoft Visual C.
diff --git a/Help/variable/MSVC80.rst b/Help/variable/MSVC80.rst
new file mode 100644
index 0000000000..306c67f5e8
--- /dev/null
+++ b/Help/variable/MSVC80.rst
@@ -0,0 +1,6 @@
+MSVC80
+------
+
+True when using Microsoft Visual C 8.0
+
+Set to true when the compiler is version 8.0 of Microsoft Visual C.
diff --git a/Help/variable/MSVC90.rst b/Help/variable/MSVC90.rst
new file mode 100644
index 0000000000..3cfcc672d4
--- /dev/null
+++ b/Help/variable/MSVC90.rst
@@ -0,0 +1,6 @@
+MSVC90
+------
+
+True when using Microsoft Visual C 9.0
+
+Set to true when the compiler is version 9.0 of Microsoft Visual C.
diff --git a/Help/variable/MSVC_IDE.rst b/Help/variable/MSVC_IDE.rst
new file mode 100644
index 0000000000..055f876be1
--- /dev/null
+++ b/Help/variable/MSVC_IDE.rst
@@ -0,0 +1,7 @@
+MSVC_IDE
+--------
+
+True when using the Microsoft Visual C IDE
+
+Set to true when the target platform is the Microsoft Visual C IDE, as
+opposed to the command line compiler.
diff --git a/Help/variable/MSVC_VERSION.rst b/Help/variable/MSVC_VERSION.rst
new file mode 100644
index 0000000000..ef3b0b5582
--- /dev/null
+++ b/Help/variable/MSVC_VERSION.rst
@@ -0,0 +1,16 @@
+MSVC_VERSION
+------------
+
+The version of Microsoft Visual C/C++ being used if any.
+
+Known version numbers are::
+
+ 1200 = VS 6.0
+ 1300 = VS 7.0
+ 1310 = VS 7.1
+ 1400 = VS 8.0
+ 1500 = VS 9.0
+ 1600 = VS 10.0
+ 1700 = VS 11.0
+ 1800 = VS 12.0
+ 1900 = VS 14.0
diff --git a/Help/variable/PROJECT-NAME_BINARY_DIR.rst b/Help/variable/PROJECT-NAME_BINARY_DIR.rst
new file mode 100644
index 0000000000..49bc55878d
--- /dev/null
+++ b/Help/variable/PROJECT-NAME_BINARY_DIR.rst
@@ -0,0 +1,8 @@
+<PROJECT-NAME>_BINARY_DIR
+-------------------------
+
+Top level binary directory for the named project.
+
+A variable is created with the name used in the :command:`project` command,
+and is the binary directory for the project. This can be useful when
+:command:`add_subdirectory` is used to connect several projects.
diff --git a/Help/variable/PROJECT-NAME_SOURCE_DIR.rst b/Help/variable/PROJECT-NAME_SOURCE_DIR.rst
new file mode 100644
index 0000000000..4df3e223c1
--- /dev/null
+++ b/Help/variable/PROJECT-NAME_SOURCE_DIR.rst
@@ -0,0 +1,8 @@
+<PROJECT-NAME>_SOURCE_DIR
+-------------------------
+
+Top level source directory for the named project.
+
+A variable is created with the name used in the :command:`project` command,
+and is the source directory for the project. This can be useful when
+:command:`add_subdirectory` is used to connect several projects.
diff --git a/Help/variable/PROJECT-NAME_VERSION.rst b/Help/variable/PROJECT-NAME_VERSION.rst
new file mode 100644
index 0000000000..0f6ed514b5
--- /dev/null
+++ b/Help/variable/PROJECT-NAME_VERSION.rst
@@ -0,0 +1,11 @@
+<PROJECT-NAME>_VERSION
+----------------------
+
+Value given to the ``VERSION`` option of the most recent call to the
+:command:`project` command with project name ``<PROJECT-NAME>``, if any.
+
+See also the component-wise version variables
+:variable:`<PROJECT-NAME>_VERSION_MAJOR`,
+:variable:`<PROJECT-NAME>_VERSION_MINOR`,
+:variable:`<PROJECT-NAME>_VERSION_PATCH`, and
+:variable:`<PROJECT-NAME>_VERSION_TWEAK`.
diff --git a/Help/variable/PROJECT-NAME_VERSION_MAJOR.rst b/Help/variable/PROJECT-NAME_VERSION_MAJOR.rst
new file mode 100644
index 0000000000..9e2d755a6d
--- /dev/null
+++ b/Help/variable/PROJECT-NAME_VERSION_MAJOR.rst
@@ -0,0 +1,5 @@
+<PROJECT-NAME>_VERSION_MAJOR
+----------------------------
+
+First version number component of the :variable:`<PROJECT-NAME>_VERSION`
+variable as set by the :command:`project` command.
diff --git a/Help/variable/PROJECT-NAME_VERSION_MINOR.rst b/Help/variable/PROJECT-NAME_VERSION_MINOR.rst
new file mode 100644
index 0000000000..fa2cdab580
--- /dev/null
+++ b/Help/variable/PROJECT-NAME_VERSION_MINOR.rst
@@ -0,0 +1,5 @@
+<PROJECT-NAME>_VERSION_MINOR
+----------------------------
+
+Second version number component of the :variable:`<PROJECT-NAME>_VERSION`
+variable as set by the :command:`project` command.
diff --git a/Help/variable/PROJECT-NAME_VERSION_PATCH.rst b/Help/variable/PROJECT-NAME_VERSION_PATCH.rst
new file mode 100644
index 0000000000..85b5e6bdb1
--- /dev/null
+++ b/Help/variable/PROJECT-NAME_VERSION_PATCH.rst
@@ -0,0 +1,5 @@
+<PROJECT-NAME>_VERSION_PATCH
+----------------------------
+
+Third version number component of the :variable:`<PROJECT-NAME>_VERSION`
+variable as set by the :command:`project` command.
diff --git a/Help/variable/PROJECT-NAME_VERSION_TWEAK.rst b/Help/variable/PROJECT-NAME_VERSION_TWEAK.rst
new file mode 100644
index 0000000000..65c404482a
--- /dev/null
+++ b/Help/variable/PROJECT-NAME_VERSION_TWEAK.rst
@@ -0,0 +1,5 @@
+<PROJECT-NAME>_VERSION_TWEAK
+----------------------------
+
+Fourth version number component of the :variable:`<PROJECT-NAME>_VERSION`
+variable as set by the :command:`project` command.
diff --git a/Help/variable/PROJECT_BINARY_DIR.rst b/Help/variable/PROJECT_BINARY_DIR.rst
new file mode 100644
index 0000000000..09e9ef2185
--- /dev/null
+++ b/Help/variable/PROJECT_BINARY_DIR.rst
@@ -0,0 +1,6 @@
+PROJECT_BINARY_DIR
+------------------
+
+Full path to build directory for project.
+
+This is the binary directory of the most recent :command:`project` command.
diff --git a/Help/variable/PROJECT_NAME.rst b/Help/variable/PROJECT_NAME.rst
new file mode 100644
index 0000000000..61aa8bc003
--- /dev/null
+++ b/Help/variable/PROJECT_NAME.rst
@@ -0,0 +1,6 @@
+PROJECT_NAME
+------------
+
+Name of the project given to the project command.
+
+This is the name given to the most recent :command:`project` command.
diff --git a/Help/variable/PROJECT_SOURCE_DIR.rst b/Help/variable/PROJECT_SOURCE_DIR.rst
new file mode 100644
index 0000000000..27f2838eed
--- /dev/null
+++ b/Help/variable/PROJECT_SOURCE_DIR.rst
@@ -0,0 +1,6 @@
+PROJECT_SOURCE_DIR
+------------------
+
+Top level source directory for the current project.
+
+This is the source directory of the most recent :command:`project` command.
diff --git a/Help/variable/PROJECT_VERSION.rst b/Help/variable/PROJECT_VERSION.rst
new file mode 100644
index 0000000000..234558dbd6
--- /dev/null
+++ b/Help/variable/PROJECT_VERSION.rst
@@ -0,0 +1,11 @@
+PROJECT_VERSION
+---------------
+
+Value given to the ``VERSION`` option of the most recent call to the
+:command:`project` command, if any.
+
+See also the component-wise version variables
+:variable:`PROJECT_VERSION_MAJOR`,
+:variable:`PROJECT_VERSION_MINOR`,
+:variable:`PROJECT_VERSION_PATCH`, and
+:variable:`PROJECT_VERSION_TWEAK`.
diff --git a/Help/variable/PROJECT_VERSION_MAJOR.rst b/Help/variable/PROJECT_VERSION_MAJOR.rst
new file mode 100644
index 0000000000..4b6072c549
--- /dev/null
+++ b/Help/variable/PROJECT_VERSION_MAJOR.rst
@@ -0,0 +1,5 @@
+PROJECT_VERSION_MAJOR
+---------------------
+
+First version number component of the :variable:`PROJECT_VERSION`
+variable as set by the :command:`project` command.
diff --git a/Help/variable/PROJECT_VERSION_MINOR.rst b/Help/variable/PROJECT_VERSION_MINOR.rst
new file mode 100644
index 0000000000..5f31220f46
--- /dev/null
+++ b/Help/variable/PROJECT_VERSION_MINOR.rst
@@ -0,0 +1,5 @@
+PROJECT_VERSION_MINOR
+---------------------
+
+Second version number component of the :variable:`PROJECT_VERSION`
+variable as set by the :command:`project` command.
diff --git a/Help/variable/PROJECT_VERSION_PATCH.rst b/Help/variable/PROJECT_VERSION_PATCH.rst
new file mode 100644
index 0000000000..ac72ec051e
--- /dev/null
+++ b/Help/variable/PROJECT_VERSION_PATCH.rst
@@ -0,0 +1,5 @@
+PROJECT_VERSION_PATCH
+---------------------
+
+Third version number component of the :variable:`PROJECT_VERSION`
+variable as set by the :command:`project` command.
diff --git a/Help/variable/PROJECT_VERSION_TWEAK.rst b/Help/variable/PROJECT_VERSION_TWEAK.rst
new file mode 100644
index 0000000000..d7f96d6ce9
--- /dev/null
+++ b/Help/variable/PROJECT_VERSION_TWEAK.rst
@@ -0,0 +1,5 @@
+PROJECT_VERSION_TWEAK
+---------------------
+
+Fourth version number component of the :variable:`PROJECT_VERSION`
+variable as set by the :command:`project` command.
diff --git a/Help/variable/UNIX.rst b/Help/variable/UNIX.rst
new file mode 100644
index 0000000000..82e3454273
--- /dev/null
+++ b/Help/variable/UNIX.rst
@@ -0,0 +1,7 @@
+UNIX
+----
+
+True for UNIX and UNIX like operating systems.
+
+Set to true when the target system is UNIX or UNIX like (i.e. APPLE
+and CYGWIN).
diff --git a/Help/variable/WIN32.rst b/Help/variable/WIN32.rst
new file mode 100644
index 0000000000..8cf7bf35e2
--- /dev/null
+++ b/Help/variable/WIN32.rst
@@ -0,0 +1,6 @@
+WIN32
+-----
+
+True on windows systems, including win64.
+
+Set to true when the target system is Windows.
diff --git a/Help/variable/WINCE.rst b/Help/variable/WINCE.rst
new file mode 100644
index 0000000000..54ff7dee27
--- /dev/null
+++ b/Help/variable/WINCE.rst
@@ -0,0 +1,5 @@
+WINCE
+-----
+
+True when the :variable:`CMAKE_SYSTEM_NAME` variable is set
+to ``WindowsCE``.
diff --git a/Help/variable/WINDOWS_PHONE.rst b/Help/variable/WINDOWS_PHONE.rst
new file mode 100644
index 0000000000..61d91b00aa
--- /dev/null
+++ b/Help/variable/WINDOWS_PHONE.rst
@@ -0,0 +1,5 @@
+WINDOWS_PHONE
+-------------
+
+True when the :variable:`CMAKE_SYSTEM_NAME` variable is set
+to ``WindowsPhone``.
diff --git a/Help/variable/WINDOWS_STORE.rst b/Help/variable/WINDOWS_STORE.rst
new file mode 100644
index 0000000000..dae3b539b7
--- /dev/null
+++ b/Help/variable/WINDOWS_STORE.rst
@@ -0,0 +1,5 @@
+WINDOWS_STORE
+-------------
+
+True when the :variable:`CMAKE_SYSTEM_NAME` variable is set
+to ``WindowsStore``.
diff --git a/Help/variable/XCODE_VERSION.rst b/Help/variable/XCODE_VERSION.rst
new file mode 100644
index 0000000000..b6f04037d1
--- /dev/null
+++ b/Help/variable/XCODE_VERSION.rst
@@ -0,0 +1,7 @@
+XCODE_VERSION
+-------------
+
+Version of Xcode (Xcode generator only).
+
+Under the Xcode generator, this is the version of Xcode as specified
+in "Xcode.app/Contents/version.plist" (such as "3.1.2").
diff --git a/Licenses/LGPLv2.1.txt b/Licenses/LGPLv2.1.txt
new file mode 100644
index 0000000000..4362b49151
--- /dev/null
+++ b/Licenses/LGPLv2.1.txt
@@ -0,0 +1,502 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/Licenses/README.rst b/Licenses/README.rst
new file mode 100644
index 0000000000..e798f7821f
--- /dev/null
+++ b/Licenses/README.rst
@@ -0,0 +1,7 @@
+Licenses
+========
+
+The CMake source tree is distributed under terms of the BSD 3-Clause license.
+
+This directory contains other license files that need to be packaged with
+binary distributions when certain third-party libraries are included.
diff --git a/Modules/AddFileDependencies.cmake b/Modules/AddFileDependencies.cmake
new file mode 100644
index 0000000000..4d01a526c7
--- /dev/null
+++ b/Modules/AddFileDependencies.cmake
@@ -0,0 +1,33 @@
+#.rst:
+# AddFileDependencies
+# -------------------
+#
+# ADD_FILE_DEPENDENCIES(source_file depend_files...)
+#
+# Adds the given files as dependencies to source_file
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+macro(ADD_FILE_DEPENDENCIES _file)
+
+ get_source_file_property(_deps ${_file} OBJECT_DEPENDS)
+ if (_deps)
+ set(_deps ${_deps} ${ARGN})
+ else ()
+ set(_deps ${ARGN})
+ endif ()
+
+ set_source_files_properties(${_file} PROPERTIES OBJECT_DEPENDS "${_deps}")
+
+endmacro()
diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in
new file mode 100644
index 0000000000..602b065c66
--- /dev/null
+++ b/Modules/AutogenInfo.cmake.in
@@ -0,0 +1,25 @@
+set(AM_SOURCES @_cpp_files@ )
+set(AM_RCC_SOURCES @_rcc_files@ )
+set(AM_SKIP_MOC @_skip_moc@ )
+set(AM_SKIP_UIC @_skip_uic@ )
+set(AM_HEADERS @_moc_headers@ )
+set(AM_MOC_COMPILE_DEFINITIONS @_moc_compile_defs@)
+set(AM_MOC_INCLUDES @_moc_incs@)
+set(AM_MOC_OPTIONS @_moc_options@)
+set(AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE "@CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE@")
+set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/")
+set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/")
+set(AM_QT_MOC_EXECUTABLE "@_qt_moc_executable@")
+set(AM_QT_UIC_EXECUTABLE "@_qt_uic_executable@")
+set(AM_QT_RCC_EXECUTABLE "@_qt_rcc_executable@")
+set(AM_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@/")
+set(AM_CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@/")
+set(AM_QT_VERSION_MAJOR "@_target_qt_version@")
+set(AM_TARGET_NAME @_moc_target_name@)
+set(AM_ORIGIN_TARGET_NAME @_origin_target_name@)
+set(AM_RELAXED_MODE "@_moc_relaxed_mode@")
+set(AM_UIC_TARGET_OPTIONS @_uic_target_options@)
+set(AM_UIC_OPTIONS_FILES @_qt_uic_options_files@)
+set(AM_UIC_OPTIONS_OPTIONS @_qt_uic_options_options@)
+set(AM_RCC_OPTIONS_FILES @_qt_rcc_options_files@)
+set(AM_RCC_OPTIONS_OPTIONS @_qt_rcc_options_options@)
diff --git a/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in b/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in
new file mode 100644
index 0000000000..b1c4fdf817
--- /dev/null
+++ b/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in
@@ -0,0 +1,31 @@
+# This is a basic version file for the Config-mode of find_package().
+# It is used by write_basic_package_version_file() as input file for configure_file()
+# to create a version-file which can be installed along a config.cmake file.
+#
+# The created file sets PACKAGE_VERSION_EXACT if the current version string and
+# the requested version string are exactly the same and it sets
+# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version.
+# The variable CVF_VERSION must be set before calling configure_file().
+
+set(PACKAGE_VERSION "@CVF_VERSION@")
+
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
+
+# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
+if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "")
+ return()
+endif()
+
+# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
+if(NOT "${CMAKE_SIZEOF_VOID_P}" STREQUAL "@CMAKE_SIZEOF_VOID_P@")
+ math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8")
+ set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
+ set(PACKAGE_VERSION_UNSUITABLE TRUE)
+endif()
diff --git a/Modules/BasicConfigVersion-ExactVersion.cmake.in b/Modules/BasicConfigVersion-ExactVersion.cmake.in
new file mode 100644
index 0000000000..9fd0136b00
--- /dev/null
+++ b/Modules/BasicConfigVersion-ExactVersion.cmake.in
@@ -0,0 +1,47 @@
+# This is a basic version file for the Config-mode of find_package().
+# It is used by write_basic_package_version_file() as input file for configure_file()
+# to create a version-file which can be installed along a config.cmake file.
+#
+# The created file sets PACKAGE_VERSION_EXACT if the current version string and
+# the requested version string are exactly the same and it sets
+# PACKAGE_VERSION_COMPATIBLE if the current version is equal to the requested version.
+# The tweak version component is ignored.
+# The variable CVF_VERSION must be set before calling configure_file().
+
+
+set(PACKAGE_VERSION "@CVF_VERSION@")
+
+if("@CVF_VERSION@" MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)\\.") # strip the tweak version
+ set(CVF_VERSION_NO_TWEAK "${CMAKE_MATCH_1}")
+else()
+ set(CVF_VERSION_NO_TWEAK "@CVF_VERSION@")
+endif()
+
+if("${PACKAGE_FIND_VERSION}" MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)\\.") # strip the tweak version
+ set(REQUESTED_VERSION_NO_TWEAK "${CMAKE_MATCH_1}")
+else()
+ set(REQUESTED_VERSION_NO_TWEAK "${PACKAGE_FIND_VERSION}")
+endif()
+
+if("${REQUESTED_VERSION_NO_TWEAK}" STREQUAL "${CVF_VERSION_NO_TWEAK}")
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+endif()
+
+if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+endif()
+
+
+# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
+if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "")
+ return()
+endif()
+
+# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
+if(NOT "${CMAKE_SIZEOF_VOID_P}" STREQUAL "@CMAKE_SIZEOF_VOID_P@")
+ math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8")
+ set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
+ set(PACKAGE_VERSION_UNSUITABLE TRUE)
+endif()
diff --git a/Modules/BasicConfigVersion-SameMajorVersion.cmake.in b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
new file mode 100644
index 0000000000..4acd9bb5ee
--- /dev/null
+++ b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
@@ -0,0 +1,46 @@
+# This is a basic version file for the Config-mode of find_package().
+# It is used by write_basic_package_version_file() as input file for configure_file()
+# to create a version-file which can be installed along a config.cmake file.
+#
+# The created file sets PACKAGE_VERSION_EXACT if the current version string and
+# the requested version string are exactly the same and it sets
+# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version,
+# but only if the requested major version is the same as the current one.
+# The variable CVF_VERSION must be set before calling configure_file().
+
+
+set(PACKAGE_VERSION "@CVF_VERSION@")
+
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+
+ if("@CVF_VERSION@" MATCHES "^([0-9]+)\\.")
+ set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
+ else()
+ set(CVF_VERSION_MAJOR "@CVF_VERSION@")
+ endif()
+
+ if("${PACKAGE_FIND_VERSION_MAJOR}" STREQUAL "${CVF_VERSION_MAJOR}")
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ else()
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ endif()
+
+ if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
+
+
+# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
+if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "")
+ return()
+endif()
+
+# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
+if(NOT "${CMAKE_SIZEOF_VOID_P}" STREQUAL "@CMAKE_SIZEOF_VOID_P@")
+ math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8")
+ set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
+ set(PACKAGE_VERSION_UNSUITABLE TRUE)
+endif()
diff --git a/Modules/BundleUtilities.cmake b/Modules/BundleUtilities.cmake
new file mode 100644
index 0000000000..445c71953e
--- /dev/null
+++ b/Modules/BundleUtilities.cmake
@@ -0,0 +1,952 @@
+#.rst:
+# BundleUtilities
+# ---------------
+#
+# Functions to help assemble a standalone bundle application.
+#
+# A collection of CMake utility functions useful for dealing with .app
+# bundles on the Mac and bundle-like directories on any OS.
+#
+# The following functions are provided by this module:
+#
+# ::
+#
+# fixup_bundle
+# copy_and_fixup_bundle
+# verify_app
+# get_bundle_main_executable
+# get_dotapp_dir
+# get_bundle_and_executable
+# get_bundle_all_executables
+# get_item_key
+# get_item_rpaths
+# clear_bundle_keys
+# set_bundle_key_values
+# get_bundle_keys
+# copy_resolved_item_into_bundle
+# copy_resolved_framework_into_bundle
+# fixup_bundle_item
+# verify_bundle_prerequisites
+# verify_bundle_symlinks
+#
+# Requires CMake 2.6 or greater because it uses function, break and
+# PARENT_SCOPE. Also depends on GetPrerequisites.cmake.
+#
+# ::
+#
+# FIXUP_BUNDLE(<app> <libs> <dirs>)
+#
+# Fix up a bundle in-place and make it standalone, such that it can be
+# drag-n-drop copied to another machine and run on that machine as long
+# as all of the system libraries are compatible.
+#
+# If you pass plugins to fixup_bundle as the libs parameter, you should
+# install them or copy them into the bundle before calling fixup_bundle.
+# The "libs" parameter is a list of libraries that must be fixed up, but
+# that cannot be determined by otool output analysis. (i.e., plugins)
+#
+# Gather all the keys for all the executables and libraries in a bundle,
+# and then, for each key, copy each prerequisite into the bundle. Then
+# fix each one up according to its own list of prerequisites.
+#
+# Then clear all the keys and call verify_app on the final bundle to
+# ensure that it is truly standalone.
+#
+# ::
+#
+# COPY_AND_FIXUP_BUNDLE(<src> <dst> <libs> <dirs>)
+#
+# Makes a copy of the bundle <src> at location <dst> and then fixes up
+# the new copied bundle in-place at <dst>...
+#
+# ::
+#
+# VERIFY_APP(<app>)
+#
+# Verifies that an application <app> appears valid based on running
+# analysis tools on it. Calls "message(FATAL_ERROR" if the application
+# is not verified.
+#
+# ::
+#
+# GET_BUNDLE_MAIN_EXECUTABLE(<bundle> <result_var>)
+#
+# The result will be the full path name of the bundle's main executable
+# file or an "error:" prefixed string if it could not be determined.
+#
+# ::
+#
+# GET_DOTAPP_DIR(<exe> <dotapp_dir_var>)
+#
+# Returns the nearest parent dir whose name ends with ".app" given the
+# full path to an executable. If there is no such parent dir, then
+# simply return the dir containing the executable.
+#
+# The returned directory may or may not exist.
+#
+# ::
+#
+# GET_BUNDLE_AND_EXECUTABLE(<app> <bundle_var> <executable_var> <valid_var>)
+#
+# Takes either a ".app" directory name or the name of an executable
+# nested inside a ".app" directory and returns the path to the ".app"
+# directory in <bundle_var> and the path to its main executable in
+# <executable_var>
+#
+# ::
+#
+# GET_BUNDLE_ALL_EXECUTABLES(<bundle> <exes_var>)
+#
+# Scans the given bundle recursively for all executable files and
+# accumulates them into a variable.
+#
+# ::
+#
+# GET_ITEM_KEY(<item> <key_var>)
+#
+# Given a file (item) name, generate a key that should be unique
+# considering the set of libraries that need copying or fixing up to
+# make a bundle standalone. This is essentially the file name including
+# extension with "." replaced by "_"
+#
+# This key is used as a prefix for CMake variables so that we can
+# associate a set of variables with a given item based on its key.
+#
+# ::
+#
+# CLEAR_BUNDLE_KEYS(<keys_var>)
+#
+# Loop over the list of keys, clearing all the variables associated with
+# each key. After the loop, clear the list of keys itself.
+#
+# Caller of get_bundle_keys should call clear_bundle_keys when done with
+# list of keys.
+#
+# ::
+#
+# SET_BUNDLE_KEY_VALUES(<keys_var> <context> <item> <exepath> <dirs>
+# <copyflag> [<rpaths>])
+#
+# Add a key to the list (if necessary) for the given item. If added,
+# also set all the variables associated with that key.
+#
+# ::
+#
+# GET_BUNDLE_KEYS(<app> <libs> <dirs> <keys_var>)
+#
+# Loop over all the executable and library files within the bundle (and
+# given as extra <libs>) and accumulate a list of keys representing
+# them. Set values associated with each key such that we can loop over
+# all of them and copy prerequisite libs into the bundle and then do
+# appropriate install_name_tool fixups.
+#
+# ::
+#
+# COPY_RESOLVED_ITEM_INTO_BUNDLE(<resolved_item> <resolved_embedded_item>)
+#
+# Copy a resolved item into the bundle if necessary. Copy is not
+# necessary if the resolved_item is "the same as" the
+# resolved_embedded_item.
+#
+# ::
+#
+# COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE(<resolved_item> <resolved_embedded_item>)
+#
+# Copy a resolved framework into the bundle if necessary. Copy is not
+# necessary if the resolved_item is "the same as" the
+# resolved_embedded_item.
+#
+# By default, BU_COPY_FULL_FRAMEWORK_CONTENTS is not set. If you want
+# full frameworks embedded in your bundles, set
+# BU_COPY_FULL_FRAMEWORK_CONTENTS to ON before calling fixup_bundle. By
+# default, COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE copies the framework
+# dylib itself plus the framework Resources directory.
+#
+# ::
+#
+# FIXUP_BUNDLE_ITEM(<resolved_embedded_item> <exepath> <dirs>)
+#
+# Get the direct/non-system prerequisites of the resolved embedded item.
+# For each prerequisite, change the way it is referenced to the value of
+# the _EMBEDDED_ITEM keyed variable for that prerequisite. (Most likely
+# changing to an "@executable_path" style reference.)
+#
+# This function requires that the resolved_embedded_item be "inside" the
+# bundle already. In other words, if you pass plugins to fixup_bundle
+# as the libs parameter, you should install them or copy them into the
+# bundle before calling fixup_bundle. The "libs" parameter is a list of
+# libraries that must be fixed up, but that cannot be determined by
+# otool output analysis. (i.e., plugins)
+#
+# Also, change the id of the item being fixed up to its own
+# _EMBEDDED_ITEM value.
+#
+# Accumulate changes in a local variable and make *one* call to
+# install_name_tool at the end of the function with all the changes at
+# once.
+#
+# If the BU_CHMOD_BUNDLE_ITEMS variable is set then bundle items will be
+# marked writable before install_name_tool tries to change them.
+#
+# ::
+#
+# VERIFY_BUNDLE_PREREQUISITES(<bundle> <result_var> <info_var>)
+#
+# Verifies that the sum of all prerequisites of all files inside the
+# bundle are contained within the bundle or are "system" libraries,
+# presumed to exist everywhere.
+#
+# ::
+#
+# VERIFY_BUNDLE_SYMLINKS(<bundle> <result_var> <info_var>)
+#
+# Verifies that any symlinks found in the bundle point to other files
+# that are already also in the bundle... Anything that points to an
+# external file causes this function to fail the verification.
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+# The functions defined in this file depend on the get_prerequisites function
+# (and possibly others) found in:
+#
+get_filename_component(BundleUtilities_cmake_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+include("${BundleUtilities_cmake_dir}/GetPrerequisites.cmake")
+
+
+function(get_bundle_main_executable bundle result_var)
+ set(result "error: '${bundle}/Contents/Info.plist' file does not exist")
+
+ if(EXISTS "${bundle}/Contents/Info.plist")
+ set(result "error: no CFBundleExecutable in '${bundle}/Contents/Info.plist' file")
+ set(line_is_main_executable 0)
+ set(bundle_executable "")
+
+ # Read Info.plist as a list of lines:
+ #
+ set(eol_char "E")
+ file(READ "${bundle}/Contents/Info.plist" info_plist)
+ string(REPLACE ";" "\\;" info_plist "${info_plist}")
+ string(REPLACE "\n" "${eol_char};" info_plist "${info_plist}")
+ string(REPLACE "\r" "${eol_char};" info_plist "${info_plist}")
+
+ # Scan the lines for "<key>CFBundleExecutable</key>" - the line after that
+ # is the name of the main executable.
+ #
+ foreach(line ${info_plist})
+ if(line_is_main_executable)
+ string(REGEX REPLACE "^.*<string>(.*)</string>.*$" "\\1" bundle_executable "${line}")
+ break()
+ endif()
+
+ if(line MATCHES "<key>CFBundleExecutable</key>")
+ set(line_is_main_executable 1)
+ endif()
+ endforeach()
+
+ if(NOT "${bundle_executable}" STREQUAL "")
+ if(EXISTS "${bundle}/Contents/MacOS/${bundle_executable}")
+ set(result "${bundle}/Contents/MacOS/${bundle_executable}")
+ else()
+
+ # Ultimate goal:
+ # If not in "Contents/MacOS" then scan the bundle for matching files. If
+ # there is only one executable file that matches, then use it, otherwise
+ # it's an error...
+ #
+ #file(GLOB_RECURSE file_list "${bundle}/${bundle_executable}")
+
+ # But for now, pragmatically, it's an error. Expect the main executable
+ # for the bundle to be in Contents/MacOS, it's an error if it's not:
+ #
+ set(result "error: '${bundle}/Contents/MacOS/${bundle_executable}' does not exist")
+ endif()
+ endif()
+ else()
+ #
+ # More inclusive technique... (This one would work on Windows and Linux
+ # too, if a developer followed the typical Mac bundle naming convention...)
+ #
+ # If there is no Info.plist file, try to find an executable with the same
+ # base name as the .app directory:
+ #
+ endif()
+
+ set(${result_var} "${result}" PARENT_SCOPE)
+endfunction()
+
+
+function(get_dotapp_dir exe dotapp_dir_var)
+ set(s "${exe}")
+
+ if(s MATCHES "/.*\\.app/")
+ # If there is a ".app" parent directory,
+ # ascend until we hit it:
+ # (typical of a Mac bundle executable)
+ #
+ set(done 0)
+ while(NOT ${done})
+ get_filename_component(snamewe "${s}" NAME_WE)
+ get_filename_component(sname "${s}" NAME)
+ get_filename_component(sdir "${s}" PATH)
+ set(s "${sdir}")
+ if(sname MATCHES "\\.app$")
+ set(done 1)
+ set(dotapp_dir "${sdir}/${sname}")
+ endif()
+ endwhile()
+ else()
+ # Otherwise use a directory containing the exe
+ # (typical of a non-bundle executable on Mac, Windows or Linux)
+ #
+ is_file_executable("${s}" is_executable)
+ if(is_executable)
+ get_filename_component(sdir "${s}" PATH)
+ set(dotapp_dir "${sdir}")
+ else()
+ set(dotapp_dir "${s}")
+ endif()
+ endif()
+
+
+ set(${dotapp_dir_var} "${dotapp_dir}" PARENT_SCOPE)
+endfunction()
+
+
+function(get_bundle_and_executable app bundle_var executable_var valid_var)
+ set(valid 0)
+
+ if(EXISTS "${app}")
+ # Is it a directory ending in .app?
+ if(IS_DIRECTORY "${app}")
+ if(app MATCHES "\\.app$")
+ get_bundle_main_executable("${app}" executable)
+ if(EXISTS "${app}" AND EXISTS "${executable}")
+ set(${bundle_var} "${app}" PARENT_SCOPE)
+ set(${executable_var} "${executable}" PARENT_SCOPE)
+ set(valid 1)
+ #message(STATUS "info: handled .app directory case...")
+ else()
+ message(STATUS "warning: *NOT* handled - .app directory case...")
+ endif()
+ else()
+ message(STATUS "warning: *NOT* handled - directory but not .app case...")
+ endif()
+ else()
+ # Is it an executable file?
+ is_file_executable("${app}" is_executable)
+ if(is_executable)
+ get_dotapp_dir("${app}" dotapp_dir)
+ if(EXISTS "${dotapp_dir}")
+ set(${bundle_var} "${dotapp_dir}" PARENT_SCOPE)
+ set(${executable_var} "${app}" PARENT_SCOPE)
+ set(valid 1)
+ #message(STATUS "info: handled executable file in .app dir case...")
+ else()
+ get_filename_component(app_dir "${app}" PATH)
+ set(${bundle_var} "${app_dir}" PARENT_SCOPE)
+ set(${executable_var} "${app}" PARENT_SCOPE)
+ set(valid 1)
+ #message(STATUS "info: handled executable file in any dir case...")
+ endif()
+ else()
+ message(STATUS "warning: *NOT* handled - not .app dir, not executable file...")
+ endif()
+ endif()
+ else()
+ message(STATUS "warning: *NOT* handled - directory/file does not exist...")
+ endif()
+
+ if(NOT valid)
+ set(${bundle_var} "error: not a bundle" PARENT_SCOPE)
+ set(${executable_var} "error: not a bundle" PARENT_SCOPE)
+ endif()
+
+ set(${valid_var} ${valid} PARENT_SCOPE)
+endfunction()
+
+
+function(get_bundle_all_executables bundle exes_var)
+ set(exes "")
+
+ if(UNIX)
+ find_program(find_cmd "find")
+ mark_as_advanced(find_cmd)
+ endif()
+
+ # find command is much quicker than checking every file one by one on Unix
+ # which can take long time for large bundles, and since anyway we expect
+ # executable to have execute flag set we can narrow the list much quicker.
+ if(find_cmd)
+ execute_process(COMMAND "${find_cmd}" "${bundle}"
+ -type f \( -perm -0100 -o -perm -0010 -o -perm -0001 \)
+ OUTPUT_VARIABLE file_list
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ string(REPLACE "\n" ";" file_list "${file_list}")
+ else()
+ file(GLOB_RECURSE file_list "${bundle}/*")
+ endif()
+
+ foreach(f ${file_list})
+ is_file_executable("${f}" is_executable)
+ if(is_executable)
+ set(exes ${exes} "${f}")
+ endif()
+ endforeach()
+
+ set(${exes_var} "${exes}" PARENT_SCOPE)
+endfunction()
+
+
+function(get_item_rpaths item rpaths_var)
+ if(APPLE)
+ find_program(otool_cmd "otool")
+ mark_as_advanced(otool_cmd)
+ endif()
+
+ if(otool_cmd)
+ execute_process(
+ COMMAND "${otool_cmd}" -l "${item}"
+ OUTPUT_VARIABLE load_cmds_ov
+ )
+ string(REGEX REPLACE "[^\n]+cmd LC_RPATH\n[^\n]+\n[^\n]+path ([^\n]+) \\(offset[^\n]+\n" "rpath \\1\n" load_cmds_ov "${load_cmds_ov}")
+ 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}")
+ endif()
+ endif()
+
+ set(${rpaths_var} ${${rpaths_var}} PARENT_SCOPE)
+endfunction()
+
+
+function(get_item_key item key_var)
+ get_filename_component(item_name "${item}" NAME)
+ if(WIN32)
+ string(TOLOWER "${item_name}" item_name)
+ endif()
+ string(REPLACE "." "_" ${key_var} "${item_name}")
+ set(${key_var} ${${key_var}} PARENT_SCOPE)
+endfunction()
+
+
+function(clear_bundle_keys keys_var)
+ foreach(key ${${keys_var}})
+ set(${key}_ITEM PARENT_SCOPE)
+ set(${key}_RESOLVED_ITEM PARENT_SCOPE)
+ set(${key}_DEFAULT_EMBEDDED_PATH PARENT_SCOPE)
+ set(${key}_EMBEDDED_ITEM PARENT_SCOPE)
+ set(${key}_RESOLVED_EMBEDDED_ITEM PARENT_SCOPE)
+ set(${key}_COPYFLAG PARENT_SCOPE)
+ set(${key}_RPATHS PARENT_SCOPE)
+ endforeach()
+ set(${keys_var} PARENT_SCOPE)
+endfunction()
+
+
+function(set_bundle_key_values keys_var context item exepath dirs copyflag)
+ set(rpaths "${ARGV6}")
+ get_filename_component(item_name "${item}" NAME)
+
+ get_item_key("${item}" key)
+
+ list(LENGTH ${keys_var} length_before)
+ gp_append_unique(${keys_var} "${key}")
+ list(LENGTH ${keys_var} length_after)
+
+ if(NOT length_before EQUAL length_after)
+ gp_resolve_item("${context}" "${item}" "${exepath}" "${dirs}" resolved_item "${rpaths}")
+
+ gp_item_default_embedded_path("${item}" default_embedded_path)
+
+ get_item_rpaths("${resolved_item}" item_rpaths)
+
+ if(item MATCHES "[^/]+\\.framework/")
+ # For frameworks, construct the name under the embedded path from the
+ # opening "${item_name}.framework/" to the closing "/${item_name}":
+ #
+ string(REGEX REPLACE "^.*(${item_name}.framework/.*/?${item_name}).*$" "${default_embedded_path}/\\1" embedded_item "${item}")
+ else()
+ # For other items, just use the same name as the original, but in the
+ # embedded path:
+ #
+ set(embedded_item "${default_embedded_path}/${item_name}")
+ endif()
+
+ # Replace @executable_path and resolve ".." references:
+ #
+ string(REPLACE "@executable_path" "${exepath}" resolved_embedded_item "${embedded_item}")
+ get_filename_component(resolved_embedded_item "${resolved_embedded_item}" ABSOLUTE)
+
+ # *But* -- if we are not copying, then force resolved_embedded_item to be
+ # the same as resolved_item. In the case of multiple executables in the
+ # original bundle, using the default_embedded_path results in looking for
+ # the resolved executable next to the main bundle executable. This is here
+ # so that exes in the other sibling directories (like "bin") get fixed up
+ # properly...
+ #
+ if(NOT copyflag)
+ set(resolved_embedded_item "${resolved_item}")
+ endif()
+
+ set(${keys_var} ${${keys_var}} PARENT_SCOPE)
+ set(${key}_ITEM "${item}" PARENT_SCOPE)
+ set(${key}_RESOLVED_ITEM "${resolved_item}" PARENT_SCOPE)
+ set(${key}_DEFAULT_EMBEDDED_PATH "${default_embedded_path}" PARENT_SCOPE)
+ set(${key}_EMBEDDED_ITEM "${embedded_item}" PARENT_SCOPE)
+ set(${key}_RESOLVED_EMBEDDED_ITEM "${resolved_embedded_item}" PARENT_SCOPE)
+ set(${key}_COPYFLAG "${copyflag}" PARENT_SCOPE)
+ set(${key}_RPATHS "${item_rpaths}" PARENT_SCOPE)
+ set(${key}_RDEP_RPATHS "${rpaths}" PARENT_SCOPE)
+ else()
+ #message("warning: item key '${key}' already in the list, subsequent references assumed identical to first")
+ endif()
+endfunction()
+
+
+function(get_bundle_keys app libs dirs keys_var)
+ set(${keys_var} PARENT_SCOPE)
+
+ get_bundle_and_executable("${app}" bundle executable valid)
+ if(valid)
+ # Always use the exepath of the main bundle executable for @executable_path
+ # replacements:
+ #
+ get_filename_component(exepath "${executable}" PATH)
+
+ # But do fixups on all executables in the bundle:
+ #
+ get_bundle_all_executables("${bundle}" exes)
+
+ # Set keys for main executable first:
+ #
+ set_bundle_key_values(${keys_var} "${executable}" "${executable}" "${exepath}" "${dirs}" 0)
+
+ # Get rpaths specified by main executable:
+ #
+ get_item_key("${executable}" executable_key)
+ set(main_rpaths "${${executable_key}_RPATHS}")
+
+ # For each extra lib, accumulate a key as well and then also accumulate
+ # any of its prerequisites. (Extra libs are typically dynamically loaded
+ # plugins: libraries that are prerequisites for full runtime functionality
+ # but that do not show up in otool -L output...)
+ #
+ foreach(lib ${libs})
+ set_bundle_key_values(${keys_var} "${lib}" "${lib}" "${exepath}" "${dirs}" 0 "${main_rpaths}")
+
+ set(prereqs "")
+ get_prerequisites("${lib}" prereqs 1 1 "${exepath}" "${dirs}" "${main_rpaths}")
+ foreach(pr ${prereqs})
+ set_bundle_key_values(${keys_var} "${lib}" "${pr}" "${exepath}" "${dirs}" 1 "${main_rpaths}")
+ endforeach()
+ endforeach()
+
+ # For each executable found in the bundle, accumulate keys as we go.
+ # The list of keys should be complete when all prerequisites of all
+ # binaries in the bundle have been analyzed.
+ #
+ foreach(exe ${exes})
+ # Main executable is scanned first above:
+ #
+ if(NOT "${exe}" STREQUAL "${executable}")
+ # Add the exe itself to the keys:
+ #
+ set_bundle_key_values(${keys_var} "${exe}" "${exe}" "${exepath}" "${dirs}" 0 "${main_rpaths}")
+
+ # Get rpaths specified by executable:
+ #
+ get_item_key("${exe}" exe_key)
+ set(exe_rpaths "${main_rpaths}" "${${exe_key}_RPATHS}")
+ else()
+ set(exe_rpaths "${main_rpaths}")
+ endif()
+
+ # Add each prerequisite to the keys:
+ #
+ set(prereqs "")
+ get_prerequisites("${exe}" prereqs 1 1 "${exepath}" "${dirs}" "${exe_rpaths}")
+ foreach(pr ${prereqs})
+ set_bundle_key_values(${keys_var} "${exe}" "${pr}" "${exepath}" "${dirs}" 1 "${exe_rpaths}")
+ endforeach()
+ endforeach()
+
+ # Propagate values to caller's scope:
+ #
+ set(${keys_var} ${${keys_var}} PARENT_SCOPE)
+ foreach(key ${${keys_var}})
+ set(${key}_ITEM "${${key}_ITEM}" PARENT_SCOPE)
+ set(${key}_RESOLVED_ITEM "${${key}_RESOLVED_ITEM}" PARENT_SCOPE)
+ set(${key}_DEFAULT_EMBEDDED_PATH "${${key}_DEFAULT_EMBEDDED_PATH}" PARENT_SCOPE)
+ set(${key}_EMBEDDED_ITEM "${${key}_EMBEDDED_ITEM}" PARENT_SCOPE)
+ set(${key}_RESOLVED_EMBEDDED_ITEM "${${key}_RESOLVED_EMBEDDED_ITEM}" PARENT_SCOPE)
+ set(${key}_COPYFLAG "${${key}_COPYFLAG}" PARENT_SCOPE)
+ set(${key}_RPATHS "${${key}_RPATHS}" PARENT_SCOPE)
+ set(${key}_RDEP_RPATHS "${${key}_RDEP_RPATHS}" PARENT_SCOPE)
+ endforeach()
+ endif()
+endfunction()
+
+
+function(copy_resolved_item_into_bundle resolved_item resolved_embedded_item)
+ if(WIN32)
+ # ignore case on Windows
+ string(TOLOWER "${resolved_item}" resolved_item_compare)
+ string(TOLOWER "${resolved_embedded_item}" resolved_embedded_item_compare)
+ else()
+ set(resolved_item_compare "${resolved_item}")
+ set(resolved_embedded_item_compare "${resolved_embedded_item}")
+ endif()
+
+ if("${resolved_item_compare}" STREQUAL "${resolved_embedded_item_compare}")
+ message(STATUS "warning: resolved_item == resolved_embedded_item - not copying...")
+ else()
+ #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy ${resolved_item} ${resolved_embedded_item}")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${resolved_item}" "${resolved_embedded_item}")
+ if(UNIX AND NOT APPLE)
+ file(RPATH_REMOVE FILE "${resolved_embedded_item}")
+ endif()
+ endif()
+
+endfunction()
+
+
+function(copy_resolved_framework_into_bundle resolved_item resolved_embedded_item)
+ if(WIN32)
+ # ignore case on Windows
+ string(TOLOWER "${resolved_item}" resolved_item_compare)
+ string(TOLOWER "${resolved_embedded_item}" resolved_embedded_item_compare)
+ else()
+ set(resolved_item_compare "${resolved_item}")
+ set(resolved_embedded_item_compare "${resolved_embedded_item}")
+ endif()
+
+ if("${resolved_item_compare}" STREQUAL "${resolved_embedded_item_compare}")
+ message(STATUS "warning: resolved_item == resolved_embedded_item - not copying...")
+ else()
+ if(BU_COPY_FULL_FRAMEWORK_CONTENTS)
+ # Full Framework (everything):
+ get_filename_component(resolved_dir "${resolved_item}" PATH)
+ get_filename_component(resolved_dir "${resolved_dir}/../.." ABSOLUTE)
+ get_filename_component(resolved_embedded_dir "${resolved_embedded_item}" PATH)
+ get_filename_component(resolved_embedded_dir "${resolved_embedded_dir}/../.." ABSOLUTE)
+ #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy_directory '${resolved_dir}' '${resolved_embedded_dir}'")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${resolved_dir}" "${resolved_embedded_dir}")
+ else()
+ # Framework lib itself:
+ #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy ${resolved_item} ${resolved_embedded_item}")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${resolved_item}" "${resolved_embedded_item}")
+
+ # Plus Resources, if they exist:
+ string(REGEX REPLACE "^(.*)/[^/]+$" "\\1/Resources" resolved_resources "${resolved_item}")
+ string(REGEX REPLACE "^(.*)/[^/]+$" "\\1/Resources" resolved_embedded_resources "${resolved_embedded_item}")
+ if(EXISTS "${resolved_resources}")
+ #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy_directory '${resolved_resources}' '${resolved_embedded_resources}'")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${resolved_resources}" "${resolved_embedded_resources}")
+ else()
+ # Otherwise try at least copy Contents/Info.plist to Resources/Info.plist, if it exists:
+ string(REGEX REPLACE "^(.*)/[^/]+/[^/]+/[^/]+$" "\\1/Contents/Info.plist" resolved_info_plist "${resolved_item}")
+ string(REGEX REPLACE "^(.*)/[^/]+$" "\\1/Resources/Info.plist" resolved_embedded_info_plist "${resolved_embedded_item}")
+ if(EXISTS "${resolved_info_plist}")
+ #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy_directory '${resolved_info_plist}' '${resolved_embedded_info_plist}'")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${resolved_info_plist}" "${resolved_embedded_info_plist}")
+ endif()
+ endif()
+
+ # Check if framework is versioned and fix it layout
+ string(REGEX REPLACE "^.*/([^/]+)/[^/]+$" "\\1" resolved_embedded_version "${resolved_embedded_item}")
+ string(REGEX REPLACE "^(.*)/[^/]+/[^/]+$" "\\1" resolved_embedded_versions "${resolved_embedded_item}")
+ string(REGEX REPLACE "^.*/([^/]+)/[^/]+/[^/]+$" "\\1" resolved_embedded_versions_basename "${resolved_embedded_item}")
+ if(resolved_embedded_versions_basename STREQUAL "Versions")
+ # Ensure Current symlink points to the framework version
+ if(NOT EXISTS "${resolved_embedded_versions}/Current")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${resolved_embedded_version}" "${resolved_embedded_versions}/Current")
+ endif()
+ endif()
+ endif()
+ if(UNIX AND NOT APPLE)
+ file(RPATH_REMOVE FILE "${resolved_embedded_item}")
+ endif()
+ endif()
+
+endfunction()
+
+
+function(fixup_bundle_item resolved_embedded_item exepath dirs)
+ # This item's key is "ikey":
+ #
+ get_item_key("${resolved_embedded_item}" ikey)
+
+ # Ensure the item is "inside the .app bundle" -- it should not be fixed up if
+ # it is not in the .app bundle... Otherwise, we'll modify files in the build
+ # tree, or in other varied locations around the file system, with our call to
+ # install_name_tool. Make sure that doesn't happen here:
+ #
+ get_dotapp_dir("${exepath}" exe_dotapp_dir)
+ string(LENGTH "${exe_dotapp_dir}/" exe_dotapp_dir_length)
+ string(LENGTH "${resolved_embedded_item}" resolved_embedded_item_length)
+ set(path_too_short 0)
+ set(is_embedded 0)
+ if(${resolved_embedded_item_length} LESS ${exe_dotapp_dir_length})
+ set(path_too_short 1)
+ endif()
+ if(NOT path_too_short)
+ string(SUBSTRING "${resolved_embedded_item}" 0 ${exe_dotapp_dir_length} item_substring)
+ if("${exe_dotapp_dir}/" STREQUAL "${item_substring}")
+ set(is_embedded 1)
+ endif()
+ endif()
+ if(NOT is_embedded)
+ message(" exe_dotapp_dir/='${exe_dotapp_dir}/'")
+ message(" item_substring='${item_substring}'")
+ message(" resolved_embedded_item='${resolved_embedded_item}'")
+ message("")
+ message("Install or copy the item into the bundle before calling fixup_bundle.")
+ message("Or maybe there's a typo or incorrect path in one of the args to fixup_bundle?")
+ message("")
+ message(FATAL_ERROR "cannot fixup an item that is not in the bundle...")
+ endif()
+
+ set(rpaths "${${ikey}_RPATHS}" "${${ikey}_RDEP_RPATHS}")
+
+ set(prereqs "")
+ get_prerequisites("${resolved_embedded_item}" prereqs 1 0 "${exepath}" "${dirs}" "${rpaths}")
+
+ set(changes "")
+
+ foreach(pr ${prereqs})
+ # Each referenced item's key is "rkey" in the loop:
+ #
+ get_item_key("${pr}" rkey)
+
+ if(NOT "${${rkey}_EMBEDDED_ITEM}" STREQUAL "")
+ set(changes ${changes} "-change" "${pr}" "${${rkey}_EMBEDDED_ITEM}")
+ else()
+ message("warning: unexpected reference to '${pr}'")
+ endif()
+ endforeach()
+
+ if(BU_CHMOD_BUNDLE_ITEMS)
+ execute_process(COMMAND chmod u+w "${resolved_embedded_item}")
+ endif()
+
+ # Only if install_name_tool supports -delete_rpath:
+ #
+ execute_process(COMMAND install_name_tool
+ OUTPUT_VARIABLE install_name_tool_usage
+ ERROR_VARIABLE install_name_tool_usage
+ )
+ if(install_name_tool_usage MATCHES ".*-delete_rpath.*")
+ foreach(rpath ${${ikey}_RPATHS})
+ set(changes ${changes} -delete_rpath "${rpath}")
+ endforeach()
+ endif()
+
+ if(${ikey}_EMBEDDED_ITEM)
+ set(changes ${changes} -id "${${ikey}_EMBEDDED_ITEM}")
+ endif()
+
+ # Change this item's id and all of its references in one call
+ # to install_name_tool:
+ #
+ if(changes)
+ execute_process(COMMAND install_name_tool ${changes} "${resolved_embedded_item}")
+ endif()
+endfunction()
+
+
+function(fixup_bundle app libs dirs)
+ message(STATUS "fixup_bundle")
+ message(STATUS " app='${app}'")
+ message(STATUS " libs='${libs}'")
+ message(STATUS " dirs='${dirs}'")
+
+ get_bundle_and_executable("${app}" bundle executable valid)
+ if(valid)
+ get_filename_component(exepath "${executable}" PATH)
+
+ message(STATUS "fixup_bundle: preparing...")
+ get_bundle_keys("${app}" "${libs}" "${dirs}" keys)
+
+ message(STATUS "fixup_bundle: copying...")
+ list(LENGTH keys n)
+ math(EXPR n ${n}*2)
+
+ set(i 0)
+ foreach(key ${keys})
+ math(EXPR i ${i}+1)
+ if(${${key}_COPYFLAG})
+ message(STATUS "${i}/${n}: copying '${${key}_RESOLVED_ITEM}'")
+ else()
+ message(STATUS "${i}/${n}: *NOT* copying '${${key}_RESOLVED_ITEM}'")
+ endif()
+
+ set(show_status 0)
+ if(show_status)
+ message(STATUS "key='${key}'")
+ message(STATUS "item='${${key}_ITEM}'")
+ message(STATUS "resolved_item='${${key}_RESOLVED_ITEM}'")
+ message(STATUS "default_embedded_path='${${key}_DEFAULT_EMBEDDED_PATH}'")
+ message(STATUS "embedded_item='${${key}_EMBEDDED_ITEM}'")
+ message(STATUS "resolved_embedded_item='${${key}_RESOLVED_EMBEDDED_ITEM}'")
+ message(STATUS "copyflag='${${key}_COPYFLAG}'")
+ message(STATUS "")
+ endif()
+
+ if(${${key}_COPYFLAG})
+ set(item "${${key}_ITEM}")
+ if(item MATCHES "[^/]+\\.framework/")
+ copy_resolved_framework_into_bundle("${${key}_RESOLVED_ITEM}"
+ "${${key}_RESOLVED_EMBEDDED_ITEM}")
+ else()
+ copy_resolved_item_into_bundle("${${key}_RESOLVED_ITEM}"
+ "${${key}_RESOLVED_EMBEDDED_ITEM}")
+ endif()
+ endif()
+ endforeach()
+
+ message(STATUS "fixup_bundle: fixing...")
+ foreach(key ${keys})
+ math(EXPR i ${i}+1)
+ if(APPLE)
+ message(STATUS "${i}/${n}: fixing up '${${key}_RESOLVED_EMBEDDED_ITEM}'")
+ fixup_bundle_item("${${key}_RESOLVED_EMBEDDED_ITEM}" "${exepath}" "${dirs}")
+ else()
+ message(STATUS "${i}/${n}: fix-up not required on this platform '${${key}_RESOLVED_EMBEDDED_ITEM}'")
+ endif()
+ endforeach()
+
+ message(STATUS "fixup_bundle: cleaning up...")
+ clear_bundle_keys(keys)
+
+ message(STATUS "fixup_bundle: verifying...")
+ verify_app("${app}")
+ else()
+ message(SEND_ERROR "error: fixup_bundle: not a valid bundle")
+ endif()
+
+ message(STATUS "fixup_bundle: done")
+endfunction()
+
+
+function(copy_and_fixup_bundle src dst libs dirs)
+ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${src}" "${dst}")
+ fixup_bundle("${dst}" "${libs}" "${dirs}")
+endfunction()
+
+
+function(verify_bundle_prerequisites bundle result_var info_var)
+ set(result 1)
+ set(info "")
+ set(count 0)
+
+ get_bundle_main_executable("${bundle}" main_bundle_exe)
+
+ get_bundle_all_executables("${bundle}" file_list)
+ foreach(f ${file_list})
+ get_filename_component(exepath "${f}" PATH)
+ math(EXPR count "${count} + 1")
+
+ message(STATUS "executable file ${count}: ${f}")
+
+ set(prereqs "")
+ get_prerequisites("${f}" prereqs 1 1 "${exepath}" "")
+
+ # On the Mac,
+ # "embedded" and "system" prerequisites are fine... anything else means
+ # the bundle's prerequisites are not verified (i.e., the bundle is not
+ # really "standalone")
+ #
+ # On Windows (and others? Linux/Unix/...?)
+ # "local" and "system" prereqs are fine...
+ #
+ set(external_prereqs "")
+
+ foreach(p ${prereqs})
+ set(p_type "")
+ gp_file_type("${f}" "${p}" p_type)
+
+ if(APPLE)
+ if(NOT "${p_type}" STREQUAL "embedded" AND NOT "${p_type}" STREQUAL "system")
+ set(external_prereqs ${external_prereqs} "${p}")
+ endif()
+ else()
+ if(NOT "${p_type}" STREQUAL "local" AND NOT "${p_type}" STREQUAL "system")
+ set(external_prereqs ${external_prereqs} "${p}")
+ endif()
+ endif()
+ endforeach()
+
+ if(external_prereqs)
+ # Found non-system/somehow-unacceptable prerequisites:
+ set(result 0)
+ set(info ${info} "external prerequisites found:\nf='${f}'\nexternal_prereqs='${external_prereqs}'\n")
+ endif()
+ endforeach()
+
+ if(result)
+ set(info "Verified ${count} executable files in '${bundle}'")
+ endif()
+
+ set(${result_var} "${result}" PARENT_SCOPE)
+ set(${info_var} "${info}" PARENT_SCOPE)
+endfunction()
+
+
+function(verify_bundle_symlinks bundle result_var info_var)
+ set(result 1)
+ set(info "")
+ set(count 0)
+
+ # TODO: implement this function for real...
+ # Right now, it is just a stub that verifies unconditionally...
+
+ set(${result_var} "${result}" PARENT_SCOPE)
+ set(${info_var} "${info}" PARENT_SCOPE)
+endfunction()
+
+
+function(verify_app app)
+ set(verified 0)
+ set(info "")
+
+ get_bundle_and_executable("${app}" bundle executable valid)
+
+ message(STATUS "===========================================================================")
+ message(STATUS "Analyzing app='${app}'")
+ message(STATUS "bundle='${bundle}'")
+ message(STATUS "executable='${executable}'")
+ message(STATUS "valid='${valid}'")
+
+ # Verify that the bundle does not have any "external" prerequisites:
+ #
+ verify_bundle_prerequisites("${bundle}" verified info)
+ message(STATUS "verified='${verified}'")
+ message(STATUS "info='${info}'")
+ message(STATUS "")
+
+ if(verified)
+ # Verify that the bundle does not have any symlinks to external files:
+ #
+ verify_bundle_symlinks("${bundle}" verified info)
+ message(STATUS "verified='${verified}'")
+ message(STATUS "info='${info}'")
+ message(STATUS "")
+ endif()
+
+ if(NOT verified)
+ message(FATAL_ERROR "error: verify_app failed")
+ endif()
+endfunction()
diff --git a/Modules/CMake.cmake b/Modules/CMake.cmake
new file mode 100644
index 0000000000..53a0ddf999
--- /dev/null
+++ b/Modules/CMake.cmake
@@ -0,0 +1,17 @@
+
+#=============================================================================
+# Copyright 2004-2009 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 is used by cmake.cxx to compute the CMAKE_ROOT location.
+# Do not remove this file from cvs without updating cmake.cxx to look
+# for a different file.
diff --git a/Modules/CMakeASM-ATTInformation.cmake b/Modules/CMakeASM-ATTInformation.cmake
new file mode 100644
index 0000000000..675c13bb36
--- /dev/null
+++ b/Modules/CMakeASM-ATTInformation.cmake
@@ -0,0 +1,25 @@
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# support for AT&T syntax assemblers, e.g. GNU as
+
+set(ASM_DIALECT "-ATT")
+# *.S files are supposed to be preprocessed, so they should not be passed to
+# assembler but should be processed by gcc
+set(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS s;asm)
+
+set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <FLAGS> -o <OBJECT> <SOURCE>")
+
+include(CMakeASMInformation)
+set(ASM_DIALECT)
diff --git a/Modules/CMakeASMCompiler.cmake.in b/Modules/CMakeASMCompiler.cmake.in
new file mode 100644
index 0000000000..8e58307e9f
--- /dev/null
+++ b/Modules/CMakeASMCompiler.cmake.in
@@ -0,0 +1,12 @@
+set(CMAKE_ASM@ASM_DIALECT@_COMPILER "@_CMAKE_ASM_COMPILER@")
+set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ARG1 "@_CMAKE_ASM_COMPILER_ARG1@")
+set(CMAKE_AR "@CMAKE_AR@")
+set(CMAKE_RANLIB "@CMAKE_RANLIB@")
+set(CMAKE_LINKER "@CMAKE_LINKER@")
+set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LOADED 1)
+set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ID "@_CMAKE_ASM_COMPILER_ID@")
+set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ENV_VAR "@_CMAKE_ASM_COMPILER_ENV_VAR@")
+
+set(CMAKE_ASM@ASM_DIALECT@_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC)
+set(CMAKE_ASM@ASM_DIALECT@_LINKER_PREFERENCE 0)
+
diff --git a/Modules/CMakeASMInformation.cmake b/Modules/CMakeASMInformation.cmake
new file mode 100644
index 0000000000..62ef972a3a
--- /dev/null
+++ b/Modules/CMakeASMInformation.cmake
@@ -0,0 +1,148 @@
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+if(UNIX)
+ set(CMAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION .o)
+else()
+ set(CMAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION .obj)
+endif()
+
+set(CMAKE_INCLUDE_FLAG_ASM${ASM_DIALECT} "-I") # -I
+set(CMAKE_BASE_NAME)
+get_filename_component(CMAKE_BASE_NAME "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" NAME_WE)
+
+if("${CMAKE_BASE_NAME}" STREQUAL "as")
+ set(CMAKE_BASE_NAME gas)
+endif()
+
+# Load compiler-specific information.
+set(_INCLUDED_FILE "")
+if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
+ include(Compiler/${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}-ASM${ASM_DIALECT} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
+endif()
+if(NOT _INCLUDED_FILE)
+ if("ASM${ASM_DIALECT}" STREQUAL "ASM")
+ message(STATUS "Warning: Did not find file Compiler/${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}-ASM${ASM_DIALECT}")
+ endif()
+ include(Platform/${CMAKE_BASE_NAME} OPTIONAL)
+endif()
+
+if(CMAKE_SYSTEM_PROCESSOR)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}-ASM${ASM_DIALECT}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
+ if(NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
+ endif()
+endif()
+
+include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}-ASM${ASM_DIALECT} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
+if(NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
+endif()
+
+# This should be included before the _INIT variables are
+# used to initialize the cache. Since the rule variables
+# have if blocks on them, users can still define them here.
+# But, it should still be after the platform file so changes can
+# be made to those values.
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
+endif()
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE_ASM)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE_ASM} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE_ASM "${_override}")
+endif()
+
+# Set default assembler file extensions:
+if(NOT CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS)
+ set(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS s;S;asm)
+endif()
+
+
+# Support for CMAKE_ASM${ASM_DIALECT}_FLAGS_INIT and friends:
+set(CMAKE_ASM${ASM_DIALECT}_FLAGS_INIT "$ENV{ASM${ASM_DIALECT}FLAGS} ${CMAKE_ASM${ASM_DIALECT}_FLAGS_INIT}")
+# avoid just having a space as the initial value for the cache
+if(CMAKE_ASM${ASM_DIALECT}_FLAGS_INIT STREQUAL " ")
+ set(CMAKE_ASM${ASM_DIALECT}_FLAGS_INIT)
+endif()
+set (CMAKE_ASM${ASM_DIALECT}_FLAGS "${CMAKE_ASM${ASM_DIALECT}_FLAGS_INIT}" CACHE STRING
+ "Flags used by the assembler during all build types.")
+
+if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
+# default build type is none
+ if(NOT CMAKE_NO_BUILD_TYPE)
+ set (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
+ "Choose the type of build, options are: None, Debug Release RelWithDebInfo MinSizeRel.")
+ endif()
+ set (CMAKE_ASM${ASM_DIALECT}_FLAGS_DEBUG "${CMAKE_ASM${ASM_DIALECT}_FLAGS_DEBUG_INIT}" CACHE STRING
+ "Flags used by the assembler during debug builds.")
+ set (CMAKE_ASM${ASM_DIALECT}_FLAGS_MINSIZEREL "${CMAKE_ASM${ASM_DIALECT}_FLAGS_MINSIZEREL_INIT}" CACHE STRING
+ "Flags used by the assembler during release minsize builds.")
+ set (CMAKE_ASM${ASM_DIALECT}_FLAGS_RELEASE "${CMAKE_ASM${ASM_DIALECT}_FLAGS_RELEASE_INIT}" CACHE STRING
+ "Flags used by the assembler during release builds.")
+ set (CMAKE_ASM${ASM_DIALECT}_FLAGS_RELWITHDEBINFO "${CMAKE_ASM${ASM_DIALECT}_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
+ "Flags used by the assembler during Release with Debug Info builds.")
+endif()
+
+mark_as_advanced(CMAKE_ASM${ASM_DIALECT}_FLAGS
+ CMAKE_ASM${ASM_DIALECT}_FLAGS_DEBUG
+ CMAKE_ASM${ASM_DIALECT}_FLAGS_MINSIZEREL
+ CMAKE_ASM${ASM_DIALECT}_FLAGS_RELEASE
+ CMAKE_ASM${ASM_DIALECT}_FLAGS_RELWITHDEBINFO
+ )
+
+
+if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT)
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+endif()
+
+if(NOT CMAKE_ASM${ASM_DIALECT}_CREATE_STATIC_LIBRARY)
+ set(CMAKE_ASM${ASM_DIALECT}_CREATE_STATIC_LIBRARY
+ "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
+ "<CMAKE_RANLIB> <TARGET> ")
+endif()
+
+if(NOT CMAKE_ASM${ASM_DIALECT}_LINK_EXECUTABLE)
+ set(CMAKE_ASM${ASM_DIALECT}_LINK_EXECUTABLE
+ "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <FLAGS> <CMAKE_ASM${ASM_DIALECT}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+endif()
+
+if(NOT CMAKE_EXECUTABLE_RUNTIME_ASM${ASM_DIALECT}_FLAG)
+ set(CMAKE_EXECUTABLE_RUNTIME_ASM${ASM_DIALECT}_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_ASM${ASM_DIALECT}_FLAG})
+endif()
+
+if(NOT CMAKE_EXECUTABLE_RUNTIME_ASM${ASM_DIALECT}_FLAG_SEP)
+ set(CMAKE_EXECUTABLE_RUNTIME_ASM${ASM_DIALECT}_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_ASM${ASM_DIALECT}_FLAG_SEP})
+endif()
+
+if(NOT CMAKE_EXECUTABLE_RPATH_LINK_ASM${ASM_DIALECT}_FLAG)
+ set(CMAKE_EXECUTABLE_RPATH_LINK_ASM${ASM_DIALECT}_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_ASM${ASM_DIALECT}_FLAG})
+endif()
+
+# to be done
+if(NOT CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_LIBRARY)
+ set(CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_LIBRARY)
+endif()
+
+if(NOT CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_MODULE)
+ set(CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_MODULE)
+endif()
+
+
+set(CMAKE_ASM${ASM_DIALECT}_INFOMATION_LOADED 1)
+
diff --git a/Modules/CMakeASM_MASMInformation.cmake b/Modules/CMakeASM_MASMInformation.cmake
new file mode 100644
index 0000000000..972883cdf3
--- /dev/null
+++ b/Modules/CMakeASM_MASMInformation.cmake
@@ -0,0 +1,24 @@
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+# support for the MS assembler, masm and masm64
+
+set(ASM_DIALECT "_MASM")
+
+set(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS asm)
+
+set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <DEFINES> <FLAGS> /c /Fo <OBJECT> <SOURCE>")
+
+include(CMakeASMInformation)
+set(ASM_DIALECT)
diff --git a/Modules/CMakeASM_NASMInformation.cmake b/Modules/CMakeASM_NASMInformation.cmake
new file mode 100644
index 0000000000..7058fc7ae4
--- /dev/null
+++ b/Modules/CMakeASM_NASMInformation.cmake
@@ -0,0 +1,46 @@
+
+#=============================================================================
+# Copyright 2010 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.)
+
+# support for the nasm assembler
+
+set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS nasm asm)
+
+if(NOT CMAKE_ASM_NASM_OBJECT_FORMAT)
+ if(WIN32)
+ if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
+ set(CMAKE_ASM_NASM_OBJECT_FORMAT win64)
+ else()
+ set(CMAKE_ASM_NASM_OBJECT_FORMAT win32)
+ endif()
+ elseif(APPLE)
+ if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
+ set(CMAKE_ASM_NASM_OBJECT_FORMAT macho64)
+ else()
+ set(CMAKE_ASM_NASM_OBJECT_FORMAT macho)
+ endif()
+ else()
+ if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
+ set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
+ else()
+ set(CMAKE_ASM_NASM_OBJECT_FORMAT elf)
+ endif()
+ endif()
+endif()
+
+set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> <FLAGS> -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o <OBJECT> <SOURCE>")
+
+# Load the generic ASMInformation file:
+set(ASM_DIALECT "_NASM")
+include(CMakeASMInformation)
+set(ASM_DIALECT)
diff --git a/Modules/CMakeAddFortranSubdirectory.cmake b/Modules/CMakeAddFortranSubdirectory.cmake
new file mode 100644
index 0000000000..2e5a76f4c8
--- /dev/null
+++ b/Modules/CMakeAddFortranSubdirectory.cmake
@@ -0,0 +1,214 @@
+#.rst:
+# CMakeAddFortranSubdirectory
+# ---------------------------
+#
+# Use MinGW gfortran from VS if a fortran compiler is not found.
+#
+# The 'add_fortran_subdirectory' function adds a subdirectory to a
+# project that contains a fortran only sub-project. The module will
+# check the current compiler and see if it can support fortran. If no
+# fortran compiler is found and the compiler is MSVC, then this module
+# will find the MinGW gfortran. It will then use an external project to
+# build with the MinGW tools. It will also create imported targets for
+# the libraries created. This will only work if the fortran code is
+# built into a dll, so BUILD_SHARED_LIBS is turned on in the project.
+# In addition the CMAKE_GNUtoMS option is set to on, so that the MS .lib
+# files are created. Usage is as follows:
+#
+# ::
+#
+# cmake_add_fortran_subdirectory(
+# <subdir> # name of subdirectory
+# PROJECT <project_name> # project name in subdir top CMakeLists.txt
+# ARCHIVE_DIR <dir> # dir where project places .lib files
+# RUNTIME_DIR <dir> # dir where project places .dll files
+# LIBRARIES <lib>... # names of library targets to import
+# LINK_LIBRARIES # link interface libraries for LIBRARIES
+# [LINK_LIBS <lib> <dep>...]...
+# CMAKE_COMMAND_LINE ... # extra command line flags to pass to cmake
+# NO_EXTERNAL_INSTALL # skip installation of external project
+# )
+#
+# Relative paths in ARCHIVE_DIR and RUNTIME_DIR are interpreted with
+# respect to the build directory corresponding to the source directory
+# in which the function is invoked.
+#
+# Limitations:
+#
+# NO_EXTERNAL_INSTALL is required for forward compatibility with a
+# future version that supports installation of the external project
+# binaries during "make install".
+
+#=============================================================================
+# Copyright 2011-2012 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.)
+
+
+set(_MS_MINGW_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
+include(CheckLanguage)
+include(ExternalProject)
+include(CMakeParseArguments)
+
+function(_setup_mingw_config_and_build source_dir build_dir)
+ # Look for a MinGW gfortran.
+ find_program(MINGW_GFORTRAN
+ NAMES gfortran
+ PATHS
+ c:/MinGW/bin
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MinGW;InstallLocation]/bin"
+ )
+ if(NOT MINGW_GFORTRAN)
+ message(FATAL_ERROR
+ "gfortran not found, please install MinGW with the gfortran option."
+ "Or set the cache variable MINGW_GFORTRAN to the full path. "
+ " This is required to build")
+ endif()
+
+ # Validate the MinGW gfortran we found.
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(_mingw_target "Target:.*64.*mingw")
+ else()
+ set(_mingw_target "Target:.*mingw32")
+ endif()
+ execute_process(COMMAND "${MINGW_GFORTRAN}" -v
+ ERROR_VARIABLE out ERROR_STRIP_TRAILING_WHITESPACE)
+ if(NOT "${out}" MATCHES "${_mingw_target}")
+ string(REPLACE "\n" "\n " out " ${out}")
+ message(FATAL_ERROR
+ "MINGW_GFORTRAN is set to\n"
+ " ${MINGW_GFORTRAN}\n"
+ "which is not a MinGW gfortran for this architecture. "
+ "The output from -v does not match \"${_mingw_target}\":\n"
+ "${out}\n"
+ "Set MINGW_GFORTRAN to a proper MinGW gfortran for this architecture."
+ )
+ endif()
+
+ # Configure scripts to run MinGW tools with the proper PATH.
+ get_filename_component(MINGW_PATH ${MINGW_GFORTRAN} PATH)
+ file(TO_NATIVE_PATH "${MINGW_PATH}" MINGW_PATH)
+ string(REPLACE "\\" "\\\\" MINGW_PATH "${MINGW_PATH}")
+ configure_file(
+ ${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/config_mingw.cmake.in
+ ${build_dir}/config_mingw.cmake
+ @ONLY)
+ configure_file(
+ ${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/build_mingw.cmake.in
+ ${build_dir}/build_mingw.cmake
+ @ONLY)
+endfunction()
+
+function(_add_fortran_library_link_interface library depend_library)
+ set_target_properties(${library} PROPERTIES
+ IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG "${depend_library}")
+endfunction()
+
+
+function(cmake_add_fortran_subdirectory subdir)
+ # Parse arguments to function
+ set(options NO_EXTERNAL_INSTALL)
+ set(oneValueArgs PROJECT ARCHIVE_DIR RUNTIME_DIR)
+ set(multiValueArgs LIBRARIES LINK_LIBRARIES CMAKE_COMMAND_LINE)
+ cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ if(NOT ARGS_NO_EXTERNAL_INSTALL)
+ message(FATAL_ERROR
+ "Option NO_EXTERNAL_INSTALL is required (for forward compatibility) "
+ "but was not given."
+ )
+ endif()
+
+ # if we are not using MSVC without fortran support
+ # then just use the usual add_subdirectory to build
+ # the fortran library
+ check_language(Fortran)
+ if(NOT (MSVC AND (NOT CMAKE_Fortran_COMPILER)))
+ add_subdirectory(${subdir})
+ return()
+ endif()
+
+ # if we have MSVC without Intel fortran then setup
+ # external projects to build with mingw fortran
+
+ set(source_dir "${CMAKE_CURRENT_SOURCE_DIR}/${subdir}")
+ set(project_name "${ARGS_PROJECT}")
+ set(library_dir "${ARGS_ARCHIVE_DIR}")
+ set(binary_dir "${ARGS_RUNTIME_DIR}")
+ set(libraries ${ARGS_LIBRARIES})
+ # use the same directory that add_subdirectory would have used
+ set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${subdir}")
+ foreach(dir_var library_dir binary_dir)
+ if(NOT IS_ABSOLUTE "${${dir_var}}")
+ get_filename_component(${dir_var}
+ "${CMAKE_CURRENT_BINARY_DIR}/${${dir_var}}" ABSOLUTE)
+ endif()
+ endforeach()
+ # create build and configure wrapper scripts
+ _setup_mingw_config_and_build("${source_dir}" "${build_dir}")
+ # create the external project
+ externalproject_add(${project_name}_build
+ SOURCE_DIR ${source_dir}
+ BINARY_DIR ${build_dir}
+ CONFIGURE_COMMAND ${CMAKE_COMMAND}
+ -P ${build_dir}/config_mingw.cmake
+ BUILD_COMMAND ${CMAKE_COMMAND}
+ -P ${build_dir}/build_mingw.cmake
+ INSTALL_COMMAND ""
+ )
+ # make the external project always run make with each build
+ externalproject_add_step(${project_name}_build forcebuild
+ COMMAND ${CMAKE_COMMAND}
+ -E remove
+ ${CMAKE_CURRENT_BUILD_DIR}/${project_name}-prefix/src/${project_name}-stamp/${project_name}-build
+ DEPENDEES configure
+ DEPENDERS build
+ ALWAYS 1
+ )
+ # create imported targets for all libraries
+ foreach(lib ${libraries})
+ add_library(${lib} SHARED IMPORTED GLOBAL)
+ set_property(TARGET ${lib} APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
+ set_target_properties(${lib} PROPERTIES
+ IMPORTED_IMPLIB_NOCONFIG "${library_dir}/lib${lib}.lib"
+ IMPORTED_LOCATION_NOCONFIG "${binary_dir}/lib${lib}.dll"
+ )
+ add_dependencies(${lib} ${project_name}_build)
+ endforeach()
+
+ # now setup link libraries for targets
+ set(start FALSE)
+ set(target)
+ foreach(lib ${ARGS_LINK_LIBRARIES})
+ if("${lib}" STREQUAL "LINK_LIBS")
+ set(start TRUE)
+ else()
+ if(start)
+ if(DEFINED target)
+ # process current target and target_libs
+ _add_fortran_library_link_interface(${target} "${target_libs}")
+ # zero out target and target_libs
+ set(target)
+ set(target_libs)
+ endif()
+ # save the current target and set start to FALSE
+ set(target ${lib})
+ set(start FALSE)
+ else()
+ # append the lib to target_libs
+ list(APPEND target_libs "${lib}")
+ endif()
+ endif()
+ endforeach()
+ # process anything that is left in target and target_libs
+ if(DEFINED target)
+ _add_fortran_library_link_interface(${target} "${target_libs}")
+ endif()
+endfunction()
diff --git a/Modules/CMakeAddFortranSubdirectory/build_mingw.cmake.in b/Modules/CMakeAddFortranSubdirectory/build_mingw.cmake.in
new file mode 100644
index 0000000000..55b271a2d0
--- /dev/null
+++ b/Modules/CMakeAddFortranSubdirectory/build_mingw.cmake.in
@@ -0,0 +1,2 @@
+set(ENV{PATH} "@MINGW_PATH@\;$ENV{PATH}")
+execute_process(COMMAND "@CMAKE_COMMAND@" --build . )
diff --git a/Modules/CMakeAddFortranSubdirectory/config_mingw.cmake.in b/Modules/CMakeAddFortranSubdirectory/config_mingw.cmake.in
new file mode 100644
index 0000000000..97f67693af
--- /dev/null
+++ b/Modules/CMakeAddFortranSubdirectory/config_mingw.cmake.in
@@ -0,0 +1,9 @@
+set(ENV{PATH} "@MINGW_PATH@\;$ENV{PATH}")
+set(CMAKE_COMMAND_LINE "@ARGS_CMAKE_COMMAND_LINE@")
+execute_process(
+ COMMAND "@CMAKE_COMMAND@" "-GMinGW Makefiles"
+ -DCMAKE_Fortran_COMPILER:PATH=@MINGW_GFORTRAN@
+ -DBUILD_SHARED_LIBS=ON
+ -DCMAKE_GNUtoMS=ON
+ ${CMAKE_COMMAND_LINE}
+ "@source_dir@")
diff --git a/Modules/CMakeAddNewLanguage.txt b/Modules/CMakeAddNewLanguage.txt
new file mode 100644
index 0000000000..612e1a3a56
--- /dev/null
+++ b/Modules/CMakeAddNewLanguage.txt
@@ -0,0 +1,33 @@
+This file provides a few notes to CMake developers about how to add
+support for a new language to CMake. It is also possible to place
+these files in CMAKE_MODULE_PATH within an outside project to add
+languages not supported by upstream CMake. However, this is not
+a fully supported use case.
+
+The implementation behind the scenes of project/enable_language,
+including the compiler/platform modules, is an *internal* API that
+does not make any compatibility guarantees. It is not covered in the
+official reference documentation that is versioned with the source code.
+Maintainers of external language support are responsible for porting
+it to each version of CMake as upstream changes are made. Since
+the API is internal we will not necessarily include notice of any
+changes in release notes.
+
+
+CMakeDetermine(LANG)Compiler.cmake -> this should find the compiler for LANG and configure CMake(LANG)Compiler.cmake.in
+
+CMake(LANG)Compiler.cmake.in -> used by CMakeDetermine(LANG)Compiler.cmake
+ This file is used to store compiler information and is copied down into try
+ compile directories so that try compiles do not need to re-determine and test the LANG
+
+CMakeTest(LANG)Compiler.cmake -> test the compiler and set:
+ SET(CMAKE_(LANG)_COMPILER_WORKS 1 CACHE INTERNAL "")
+
+CMake(LANG)Information.cmake -> set up rule variables for LANG :
+ CMAKE_(LANG)_CREATE_SHARED_LIBRARY
+ CMAKE_(LANG)_CREATE_SHARED_MODULE
+ CMAKE_(LANG)_CREATE_STATIC_LIBRARY
+ CMAKE_(LANG)_COMPILE_OBJECT
+ CMAKE_(LANG)_LINK_EXECUTABLE
+
+
diff --git a/Modules/CMakeBackwardCompatibilityC.cmake b/Modules/CMakeBackwardCompatibilityC.cmake
new file mode 100644
index 0000000000..4783d68cdc
--- /dev/null
+++ b/Modules/CMakeBackwardCompatibilityC.cmake
@@ -0,0 +1,100 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+# Nothing here yet
+if(CMAKE_GENERATOR MATCHES "Visual Studio 7")
+ include(CMakeVS7BackwardCompatibility)
+ set(CMAKE_SKIP_COMPATIBILITY_TESTS 1)
+endif()
+if(CMAKE_GENERATOR MATCHES "Visual Studio 6")
+ include(CMakeVS6BackwardCompatibility)
+ set(CMAKE_SKIP_COMPATIBILITY_TESTS 1)
+endif()
+
+if(NOT CMAKE_SKIP_COMPATIBILITY_TESTS)
+ # Old CMake versions did not support OS X universal binaries anyway,
+ # so just get through this with at least some size for the types.
+ list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHS)
+ if(${NUM_ARCHS} GREATER 1)
+ if(NOT DEFINED CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
+ message(WARNING "This module does not work with OS X universal binaries.")
+ set(__ERASE_CMAKE_TRY_COMPILE_OSX_ARCHITECTURES 1)
+ list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
+ endif()
+ endif()
+
+ include (CheckTypeSize)
+ CHECK_TYPE_SIZE(int CMAKE_SIZEOF_INT)
+ CHECK_TYPE_SIZE(long CMAKE_SIZEOF_LONG)
+ CHECK_TYPE_SIZE("void*" CMAKE_SIZEOF_VOID_P)
+ CHECK_TYPE_SIZE(char CMAKE_SIZEOF_CHAR)
+ CHECK_TYPE_SIZE(short CMAKE_SIZEOF_SHORT)
+ CHECK_TYPE_SIZE(float CMAKE_SIZEOF_FLOAT)
+ CHECK_TYPE_SIZE(double CMAKE_SIZEOF_DOUBLE)
+
+ include (CheckIncludeFile)
+ CHECK_INCLUDE_FILE("limits.h" CMAKE_HAVE_LIMITS_H)
+ CHECK_INCLUDE_FILE("unistd.h" CMAKE_HAVE_UNISTD_H)
+ CHECK_INCLUDE_FILE("pthread.h" CMAKE_HAVE_PTHREAD_H)
+
+ include (CheckIncludeFiles)
+ CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SYS_PRCTL_H)
+
+ include (TestBigEndian)
+ TEST_BIG_ENDIAN(CMAKE_WORDS_BIGENDIAN)
+ include (FindX11)
+
+ if("${X11_X11_INCLUDE_PATH}" STREQUAL "/usr/include")
+ set (CMAKE_X_CFLAGS "" CACHE STRING "X11 extra flags.")
+ else()
+ set (CMAKE_X_CFLAGS "-I${X11_X11_INCLUDE_PATH}" CACHE STRING
+ "X11 extra flags.")
+ endif()
+ set (CMAKE_X_LIBS "${X11_LIBRARIES}" CACHE STRING
+ "Libraries and options used in X11 programs.")
+ set (CMAKE_HAS_X "${X11_FOUND}" CACHE INTERNAL "Is X11 around.")
+
+ include (FindThreads)
+
+ set (CMAKE_THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}" CACHE STRING
+ "Thread library used.")
+
+ set (CMAKE_USE_PTHREADS "${CMAKE_USE_PTHREADS_INIT}" CACHE BOOL
+ "Use the pthreads library.")
+
+ set (CMAKE_USE_WIN32_THREADS "${CMAKE_USE_WIN32_THREADS_INIT}" CACHE BOOL
+ "Use the win32 thread library.")
+
+ set (CMAKE_HP_PTHREADS ${CMAKE_HP_PTHREADS_INIT} CACHE BOOL
+ "Use HP pthreads.")
+
+ set (CMAKE_USE_SPROC ${CMAKE_USE_SPROC_INIT} CACHE BOOL
+ "Use sproc libs.")
+
+ if(__ERASE_CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
+ set(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
+ set(__ERASE_CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
+ endif()
+endif()
+
+mark_as_advanced(
+CMAKE_HP_PTHREADS
+CMAKE_THREAD_LIBS
+CMAKE_USE_PTHREADS
+CMAKE_USE_SPROC
+CMAKE_USE_WIN32_THREADS
+CMAKE_X_CFLAGS
+CMAKE_X_LIBS
+)
+
diff --git a/Modules/CMakeBackwardCompatibilityCXX.cmake b/Modules/CMakeBackwardCompatibilityCXX.cmake
new file mode 100644
index 0000000000..f1db46e545
--- /dev/null
+++ b/Modules/CMakeBackwardCompatibilityCXX.cmake
@@ -0,0 +1,61 @@
+#.rst:
+# CMakeBackwardCompatibilityCXX
+# -----------------------------
+#
+# define a bunch of backwards compatibility variables
+#
+# ::
+#
+# CMAKE_ANSI_CXXFLAGS - flag for ansi c++
+# CMAKE_HAS_ANSI_STRING_STREAM - has <strstream>
+# include(TestForANSIStreamHeaders)
+# include(CheckIncludeFileCXX)
+# include(TestForSTDNamespace)
+# include(TestForANSIForScope)
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+if(NOT CMAKE_SKIP_COMPATIBILITY_TESTS)
+ # check for some ANSI flags in the CXX compiler if it is not gnu
+ if(NOT CMAKE_COMPILER_IS_GNUCXX)
+ include(TestCXXAcceptsFlag)
+ set(CMAKE_TRY_ANSI_CXX_FLAGS "")
+ if(CMAKE_SYSTEM_NAME MATCHES "IRIX")
+ set(CMAKE_TRY_ANSI_CXX_FLAGS "-LANG:std")
+ endif()
+ if(CMAKE_SYSTEM_NAME MATCHES "OSF")
+ set(CMAKE_TRY_ANSI_CXX_FLAGS "-std strict_ansi -nopure_cname")
+ endif()
+ # if CMAKE_TRY_ANSI_CXX_FLAGS has something in it, see
+ # if the compiler accepts it
+ if(NOT CMAKE_TRY_ANSI_CXX_FLAGS STREQUAL "")
+ CHECK_CXX_ACCEPTS_FLAG(${CMAKE_TRY_ANSI_CXX_FLAGS} CMAKE_CXX_ACCEPTS_FLAGS)
+ # if the compiler liked the flag then set CMAKE_ANSI_CXXFLAGS
+ # to the flag
+ if(CMAKE_CXX_ACCEPTS_FLAGS)
+ set(CMAKE_ANSI_CXXFLAGS ${CMAKE_TRY_ANSI_CXX_FLAGS} CACHE INTERNAL
+ "What flags are required by the c++ compiler to make it ansi." )
+ endif()
+ endif()
+ endif()
+ set(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")
+ include(TestForANSIStreamHeaders)
+ include(CheckIncludeFileCXX)
+ include(TestForSTDNamespace)
+ include(TestForANSIForScope)
+ include(TestForSSTREAM)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_SAVE}")
+endif()
+
diff --git a/Modules/CMakeBorlandFindMake.cmake b/Modules/CMakeBorlandFindMake.cmake
new file mode 100644
index 0000000000..43b31c6950
--- /dev/null
+++ b/Modules/CMakeBorlandFindMake.cmake
@@ -0,0 +1,17 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+set (CMAKE_MAKE_PROGRAM "make" CACHE STRING
+ "Program used to build from makefiles.")
+mark_as_advanced(CMAKE_MAKE_PROGRAM)
diff --git a/Modules/CMakeBuildSettings.cmake.in b/Modules/CMakeBuildSettings.cmake.in
new file mode 100644
index 0000000000..7c4aa148a2
--- /dev/null
+++ b/Modules/CMakeBuildSettings.cmake.in
@@ -0,0 +1,13 @@
+
+# The command CMAKE_EXPORT_BUILD_SETTINGS(...) was used by
+# @PROJECT_NAME@ to generate this file. As of CMake 2.8 the
+# functionality of this command has been dropped as it was deemed
+# harmful (confusing users by changing their compiler).
+
+# CMake 2.6 and below do not support loading their equivalent of this
+# file if it was produced by a newer version of CMake. CMake 2.8 and
+# above simply do not load this file. Therefore we simply error out.
+message(FATAL_ERROR
+ "This @PROJECT_NAME@ was built by CMake @CMAKE_VERSION@, but this is CMake "
+ "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}. "
+ "Please upgrade CMake to a more recent version.")
diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in
new file mode 100644
index 0000000000..86cd894505
--- /dev/null
+++ b/Modules/CMakeCCompiler.cmake.in
@@ -0,0 +1,63 @@
+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_COMPILE_FEATURES "@CMAKE_C_COMPILE_FEATURES@")
+set(CMAKE_C90_COMPILE_FEATURES "@CMAKE_C90_COMPILE_FEATURES@")
+set(CMAKE_C99_COMPILE_FEATURES "@CMAKE_C99_COMPILE_FEATURES@")
+set(CMAKE_C11_COMPILE_FEATURES "@CMAKE_C11_COMPILE_FEATURES@")
+
+set(CMAKE_C_PLATFORM_ID "@CMAKE_C_PLATFORM_ID@")
+set(CMAKE_C_SIMULATE_ID "@CMAKE_C_SIMULATE_ID@")
+set(CMAKE_C_SIMULATE_VERSION "@CMAKE_C_SIMULATE_VERSION@")
+@SET_MSVC_C_ARCHITECTURE_ID@
+set(CMAKE_AR "@CMAKE_AR@")
+set(CMAKE_RANLIB "@CMAKE_RANLIB@")
+set(CMAKE_LINKER "@CMAKE_LINKER@")
+set(CMAKE_COMPILER_IS_GNUCC @CMAKE_COMPILER_IS_GNUCC@)
+set(CMAKE_C_COMPILER_LOADED 1)
+set(CMAKE_C_COMPILER_WORKS @CMAKE_C_COMPILER_WORKS@)
+set(CMAKE_C_ABI_COMPILED @CMAKE_C_ABI_COMPILED@)
+set(CMAKE_COMPILER_IS_MINGW @CMAKE_COMPILER_IS_MINGW@)
+set(CMAKE_COMPILER_IS_CYGWIN @CMAKE_COMPILER_IS_CYGWIN@)
+if(CMAKE_COMPILER_IS_CYGWIN)
+ set(CYGWIN 1)
+ set(UNIX 1)
+endif()
+
+set(CMAKE_C_COMPILER_ENV_VAR "CC")
+
+if(CMAKE_COMPILER_IS_MINGW)
+ set(MINGW 1)
+endif()
+set(CMAKE_C_COMPILER_ID_RUN 1)
+set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m)
+set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC)
+set(CMAKE_C_LINKER_PREFERENCE 10)
+
+# Save compiler ABI information.
+set(CMAKE_C_SIZEOF_DATA_PTR "@CMAKE_C_SIZEOF_DATA_PTR@")
+set(CMAKE_C_COMPILER_ABI "@CMAKE_C_COMPILER_ABI@")
+set(CMAKE_C_LIBRARY_ARCHITECTURE "@CMAKE_C_LIBRARY_ARCHITECTURE@")
+
+if(CMAKE_C_SIZEOF_DATA_PTR)
+ set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}")
+endif()
+
+if(CMAKE_C_COMPILER_ABI)
+ set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}")
+endif()
+
+if(CMAKE_C_LIBRARY_ARCHITECTURE)
+ set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_C_LIBRARY_ARCHITECTURE@")
+endif()
+
+@CMAKE_C_SYSROOT_FLAG_CODE@
+@CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG_CODE@
+
+set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "@CMAKE_C_IMPLICIT_LINK_LIBRARIES@")
+set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "@CMAKE_C_IMPLICIT_LINK_DIRECTORIES@")
+set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@")
+
+@SET_CMAKE_CMCLDEPS_EXECUTABLE@
+@SET_CMAKE_CL_SHOWINCLUDES_PREFIX@
diff --git a/Modules/CMakeCCompilerABI.c b/Modules/CMakeCCompilerABI.c
new file mode 100644
index 0000000000..e6a07f4c4c
--- /dev/null
+++ b/Modules/CMakeCCompilerABI.c
@@ -0,0 +1,28 @@
+#ifdef __cplusplus
+# error "A C++ compiler has been selected for C."
+#endif
+
+#ifdef __CLASSIC_C__
+# define const
+#endif
+
+/*--------------------------------------------------------------------------*/
+
+#include "CMakeCompilerABI.h"
+
+/*--------------------------------------------------------------------------*/
+
+#ifdef __CLASSIC_C__
+int main(argc, argv) int argc; char *argv[];
+#else
+int main(int argc, char *argv[])
+#endif
+{
+ int require = 0;
+ require += info_sizeof_dptr[argc];
+#if defined(ABI_ID)
+ require += info_abi[argc];
+#endif
+ (void)argv;
+ return require;
+}
diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in
new file mode 100644
index 0000000000..0221cbd465
--- /dev/null
+++ b/Modules/CMakeCCompilerId.c.in
@@ -0,0 +1,50 @@
+#ifdef __cplusplus
+# error "A C++ compiler has been selected for C."
+#endif
+
+#if defined(__18CXX)
+# define ID_VOID_MAIN
+#endif
+
+@CMAKE_C_COMPILER_ID_CONTENT@
+
+/* Construct the string literal in pieces to prevent the source from
+ getting matched. Store it in a pointer rather than an array
+ because some compilers will just produce instructions to fill the
+ array rather than assigning a pointer to a static array. */
+char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
+#ifdef SIMULATE_ID
+char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
+#endif
+
+#ifdef __QNXNTO__
+char const* qnxnto = "INFO" ":" "qnxnto";
+#endif
+
+@CMAKE_C_COMPILER_ID_PLATFORM_CONTENT@
+@CMAKE_C_COMPILER_ID_ERROR_FOR_TEST@
+
+/*--------------------------------------------------------------------------*/
+
+#ifdef ID_VOID_MAIN
+void main() {}
+#else
+int main(int argc, char* argv[])
+{
+ int require = 0;
+ require += info_compiler[argc];
+ require += info_platform[argc];
+ require += info_arch[argc];
+#ifdef COMPILER_VERSION_MAJOR
+ require += info_version[argc];
+#endif
+#ifdef SIMULATE_ID
+ require += info_simulate[argc];
+#endif
+#ifdef SIMULATE_VERSION_MAJOR
+ require += info_simulate_version[argc];
+#endif
+ (void)argv;
+ return require;
+}
+#endif
diff --git a/Modules/CMakeCInformation.cmake b/Modules/CMakeCInformation.cmake
new file mode 100644
index 0000000000..332b26ee22
--- /dev/null
+++ b/Modules/CMakeCInformation.cmake
@@ -0,0 +1,219 @@
+
+#=============================================================================
+# Copyright 2004-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# This file sets the basic flags for the C language in CMake.
+# It also loads the available platform file for the system-compiler
+# if it exists.
+# It also loads a system - compiler - processor (or target hardware)
+# specific file, which is mainly useful for crosscompiling and embedded systems.
+
+# 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)
+ set(CMAKE_C_OUTPUT_EXTENSION .o)
+else()
+ set(CMAKE_C_OUTPUT_EXTENSION .obj)
+endif()
+
+set(_INCLUDED_FILE 0)
+
+# Load compiler-specific information.
+if(CMAKE_C_COMPILER_ID)
+ include(Compiler/${CMAKE_C_COMPILER_ID}-C OPTIONAL)
+endif()
+
+set(CMAKE_BASE_NAME)
+get_filename_component(CMAKE_BASE_NAME "${CMAKE_C_COMPILER}" NAME_WE)
+if(CMAKE_COMPILER_IS_GNUCC)
+ set(CMAKE_BASE_NAME gcc)
+endif()
+
+
+# load a hardware specific file, mostly useful for embedded compilers
+if(CMAKE_SYSTEM_PROCESSOR)
+ if(CMAKE_C_COMPILER_ID)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
+ endif()
+ if (NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
+ endif ()
+endif()
+
+
+# load the system- and compiler specific files
+if(CMAKE_C_COMPILER_ID)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C
+ OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
+endif()
+if (NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}
+ OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
+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.
+# Remove this when all compiler info is removed from system files.
+if (NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
+endif ()
+
+if(CMAKE_C_SIZEOF_DATA_PTR)
+ foreach(f ${CMAKE_C_ABI_FILES})
+ include(${f})
+ endforeach()
+ unset(CMAKE_C_ABI_FILES)
+endif()
+
+# This should be included before the _INIT variables are
+# used to initialize the cache. Since the rule variables
+# have if blocks on them, users can still define them here.
+# But, it should still be after the platform file so changes can
+# be made to those values.
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
+endif()
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE_C} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE_C "${_override}")
+endif()
+
+
+# for most systems a module is the same as a shared library
+# so unless the variable CMAKE_MODULE_EXISTS is set just
+# copy the values from the LIBRARY variables
+if(NOT CMAKE_MODULE_EXISTS)
+ set(CMAKE_SHARED_MODULE_C_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
+ set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
+endif()
+
+set(CMAKE_C_FLAGS_INIT "$ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}")
+# avoid just having a space as the initial value for the cache
+if(CMAKE_C_FLAGS_INIT STREQUAL " ")
+ set(CMAKE_C_FLAGS_INIT)
+endif()
+set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_INIT}" CACHE STRING
+ "Flags used by the compiler during all build types.")
+
+if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
+# default build type is none
+ if(NOT CMAKE_NO_BUILD_TYPE)
+ set (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
+ "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
+ endif()
+ set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING
+ "Flags used by the compiler during debug builds.")
+ set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL_INIT}" CACHE STRING
+ "Flags used by the compiler during release builds for minimum size.")
+ set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT}" CACHE STRING
+ "Flags used by the compiler during release builds.")
+ set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
+ "Flags used by the compiler during release builds with debug info.")
+endif()
+
+if(CMAKE_C_STANDARD_LIBRARIES_INIT)
+ set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES_INIT}"
+ CACHE STRING "Libraries linked by default with all C applications.")
+ mark_as_advanced(CMAKE_C_STANDARD_LIBRARIES)
+endif()
+
+include(CMakeCommonLanguageInclude)
+
+# now define the following rule variables
+
+# CMAKE_C_CREATE_SHARED_LIBRARY
+# CMAKE_C_CREATE_SHARED_MODULE
+# CMAKE_C_COMPILE_OBJECT
+# CMAKE_C_LINK_EXECUTABLE
+
+# variables supplied by the generator at use time
+# <TARGET>
+# <TARGET_BASE> the target without the suffix
+# <OBJECTS>
+# <OBJECT>
+# <LINK_LIBRARIES>
+# <FLAGS>
+# <LINK_FLAGS>
+
+# C compiler information
+# <CMAKE_C_COMPILER>
+# <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>
+# <CMAKE_SHARED_MODULE_CREATE_C_FLAGS>
+# <CMAKE_C_LINK_FLAGS>
+
+# Static library tools
+# <CMAKE_AR>
+# <CMAKE_RANLIB>
+
+
+# create a C shared library
+if(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
+ set(CMAKE_C_CREATE_SHARED_LIBRARY
+ "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+endif()
+
+# create a C shared module just copy the shared library rule
+if(NOT CMAKE_C_CREATE_SHARED_MODULE)
+ set(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
+endif()
+
+# Create a static archive incrementally for large object file counts.
+# If CMAKE_C_CREATE_STATIC_LIBRARY is set it will override these.
+if(NOT DEFINED CMAKE_C_ARCHIVE_CREATE)
+ set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> cq <TARGET> <LINK_FLAGS> <OBJECTS>")
+endif()
+if(NOT DEFINED CMAKE_C_ARCHIVE_APPEND)
+ set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
+endif()
+if(NOT DEFINED CMAKE_C_ARCHIVE_FINISH)
+ set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
+endif()
+
+# compile a C file into an object file
+if(NOT CMAKE_C_COMPILE_OBJECT)
+ set(CMAKE_C_COMPILE_OBJECT
+ "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+endif()
+
+if(NOT CMAKE_C_LINK_EXECUTABLE)
+ set(CMAKE_C_LINK_EXECUTABLE
+ "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+endif()
+
+if(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
+ set(CMAKE_EXECUTABLE_RUNTIME_C_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
+endif()
+
+if(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
+ set(CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
+endif()
+
+if(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
+ set(CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
+endif()
+
+mark_as_advanced(
+CMAKE_C_FLAGS
+CMAKE_C_FLAGS_DEBUG
+CMAKE_C_FLAGS_MINSIZEREL
+CMAKE_C_FLAGS_RELEASE
+CMAKE_C_FLAGS_RELWITHDEBINFO
+)
+set(CMAKE_C_INFORMATION_LOADED 1)
+
+
diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in
new file mode 100644
index 0000000000..af79a31bb3
--- /dev/null
+++ b/Modules/CMakeCXXCompiler.cmake.in
@@ -0,0 +1,64 @@
+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_COMPILE_FEATURES "@CMAKE_CXX_COMPILE_FEATURES@")
+set(CMAKE_CXX98_COMPILE_FEATURES "@CMAKE_CXX98_COMPILE_FEATURES@")
+set(CMAKE_CXX11_COMPILE_FEATURES "@CMAKE_CXX11_COMPILE_FEATURES@")
+set(CMAKE_CXX14_COMPILE_FEATURES "@CMAKE_CXX14_COMPILE_FEATURES@")
+
+set(CMAKE_CXX_PLATFORM_ID "@CMAKE_CXX_PLATFORM_ID@")
+set(CMAKE_CXX_SIMULATE_ID "@CMAKE_CXX_SIMULATE_ID@")
+set(CMAKE_CXX_SIMULATE_VERSION "@CMAKE_CXX_SIMULATE_VERSION@")
+@SET_MSVC_CXX_ARCHITECTURE_ID@
+set(CMAKE_AR "@CMAKE_AR@")
+set(CMAKE_RANLIB "@CMAKE_RANLIB@")
+set(CMAKE_LINKER "@CMAKE_LINKER@")
+set(CMAKE_COMPILER_IS_GNUCXX @CMAKE_COMPILER_IS_GNUCXX@)
+set(CMAKE_CXX_COMPILER_LOADED 1)
+set(CMAKE_CXX_COMPILER_WORKS @CMAKE_CXX_COMPILER_WORKS@)
+set(CMAKE_CXX_ABI_COMPILED @CMAKE_CXX_ABI_COMPILED@)
+set(CMAKE_COMPILER_IS_MINGW @CMAKE_COMPILER_IS_MINGW@)
+set(CMAKE_COMPILER_IS_CYGWIN @CMAKE_COMPILER_IS_CYGWIN@)
+if(CMAKE_COMPILER_IS_CYGWIN)
+ set(CYGWIN 1)
+ set(UNIX 1)
+endif()
+
+set(CMAKE_CXX_COMPILER_ENV_VAR "CXX")
+
+if(CMAKE_COMPILER_IS_MINGW)
+ set(MINGW 1)
+endif()
+set(CMAKE_CXX_COMPILER_ID_RUN 1)
+set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC)
+set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;mm;CPP)
+set(CMAKE_CXX_LINKER_PREFERENCE 30)
+set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1)
+
+# Save compiler ABI information.
+set(CMAKE_CXX_SIZEOF_DATA_PTR "@CMAKE_CXX_SIZEOF_DATA_PTR@")
+set(CMAKE_CXX_COMPILER_ABI "@CMAKE_CXX_COMPILER_ABI@")
+set(CMAKE_CXX_LIBRARY_ARCHITECTURE "@CMAKE_CXX_LIBRARY_ARCHITECTURE@")
+
+if(CMAKE_CXX_SIZEOF_DATA_PTR)
+ set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}")
+endif()
+
+if(CMAKE_CXX_COMPILER_ABI)
+ set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}")
+endif()
+
+if(CMAKE_CXX_LIBRARY_ARCHITECTURE)
+ set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_CXX_LIBRARY_ARCHITECTURE@")
+endif()
+
+@CMAKE_CXX_SYSROOT_FLAG_CODE@
+@CMAKE_CXX_OSX_DEPLOYMENT_TARGET_FLAG_CODE@
+
+set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "@CMAKE_CXX_IMPLICIT_LINK_LIBRARIES@")
+set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES@")
+set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@")
+
+@SET_CMAKE_CMCLDEPS_EXECUTABLE@
+@SET_CMAKE_CL_SHOWINCLUDES_PREFIX@
diff --git a/Modules/CMakeCXXCompilerABI.cpp b/Modules/CMakeCXXCompilerABI.cpp
new file mode 100644
index 0000000000..c9b0440b8e
--- /dev/null
+++ b/Modules/CMakeCXXCompilerABI.cpp
@@ -0,0 +1,20 @@
+#ifndef __cplusplus
+# error "A C compiler has been selected for C++."
+#endif
+
+/*--------------------------------------------------------------------------*/
+
+#include "CMakeCompilerABI.h"
+
+/*--------------------------------------------------------------------------*/
+
+int main(int argc, char* argv[])
+{
+ int require = 0;
+ require += info_sizeof_dptr[argc];
+#if defined(ABI_ID)
+ require += info_abi[argc];
+#endif
+ (void)argv;
+ return require;
+}
diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in
new file mode 100644
index 0000000000..9ece26def9
--- /dev/null
+++ b/Modules/CMakeCXXCompilerId.cpp.in
@@ -0,0 +1,44 @@
+/* This source file must have a .cpp extension so that all C++ compilers
+ recognize the extension without flags. Borland does not know .cxx for
+ example. */
+#ifndef __cplusplus
+# error "A C compiler has been selected for C++."
+#endif
+
+@CMAKE_CXX_COMPILER_ID_CONTENT@
+
+/* Construct the string literal in pieces to prevent the source from
+ getting matched. Store it in a pointer rather than an array
+ because some compilers will just produce instructions to fill the
+ array rather than assigning a pointer to a static array. */
+char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
+#ifdef SIMULATE_ID
+char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
+#endif
+
+#ifdef __QNXNTO__
+char const* qnxnto = "INFO" ":" "qnxnto";
+#endif
+
+@CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@
+@CMAKE_CXX_COMPILER_ID_ERROR_FOR_TEST@
+
+/*--------------------------------------------------------------------------*/
+
+int main(int argc, char* argv[])
+{
+ int require = 0;
+ require += info_compiler[argc];
+ require += info_platform[argc];
+#ifdef COMPILER_VERSION_MAJOR
+ require += info_version[argc];
+#endif
+#ifdef SIMULATE_ID
+ require += info_simulate[argc];
+#endif
+#ifdef SIMULATE_VERSION_MAJOR
+ require += info_simulate_version[argc];
+#endif
+ (void)argv;
+ return require;
+}
diff --git a/Modules/CMakeCXXInformation.cmake b/Modules/CMakeCXXInformation.cmake
new file mode 100644
index 0000000000..72b2857db9
--- /dev/null
+++ b/Modules/CMakeCXXInformation.cmake
@@ -0,0 +1,298 @@
+
+#=============================================================================
+# Copyright 2004-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# This file sets the basic flags for the C++ language in CMake.
+# It also loads the available platform file for the system-compiler
+# if it exists.
+# It also loads a system - compiler - processor (or target hardware)
+# specific file, which is mainly useful for crosscompiling and embedded systems.
+
+# 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)
+ set(CMAKE_CXX_OUTPUT_EXTENSION .o)
+else()
+ set(CMAKE_CXX_OUTPUT_EXTENSION .obj)
+endif()
+
+set(_INCLUDED_FILE 0)
+
+# Load compiler-specific information.
+if(CMAKE_CXX_COMPILER_ID)
+ include(Compiler/${CMAKE_CXX_COMPILER_ID}-CXX OPTIONAL)
+endif()
+
+set(CMAKE_BASE_NAME)
+get_filename_component(CMAKE_BASE_NAME "${CMAKE_CXX_COMPILER}" NAME_WE)
+# since the gnu compiler has several names force g++
+if(CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_BASE_NAME g++)
+endif()
+
+
+# load a hardware specific file, mostly useful for embedded compilers
+if(CMAKE_SYSTEM_PROCESSOR)
+ if(CMAKE_CXX_COMPILER_ID)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-CXX-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
+ endif()
+ if (NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
+ endif ()
+endif()
+
+# load the system- and compiler specific files
+if(CMAKE_CXX_COMPILER_ID)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-CXX OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
+endif()
+if (NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
+ RESULT_VARIABLE _INCLUDED_FILE)
+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.
+# Remove this when all compiler info is removed from system files.
+if (NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
+endif ()
+
+if(CMAKE_CXX_SIZEOF_DATA_PTR)
+ foreach(f ${CMAKE_CXX_ABI_FILES})
+ include(${f})
+ endforeach()
+ unset(CMAKE_CXX_ABI_FILES)
+endif()
+
+# This should be included before the _INIT variables are
+# used to initialize the cache. Since the rule variables
+# have if blocks on them, users can still define them here.
+# But, it should still be after the platform file so changes can
+# be made to those values.
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
+endif()
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX "${_override}")
+endif()
+
+
+# Create a set of shared library variable specific to C++
+# For 90% of the systems, these are the same flags as the C versions
+# so if these are not set just copy the flags from the c version
+if(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
+ set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
+endif()
+
+if(NOT CMAKE_CXX_COMPILE_OPTIONS_PIC)
+ set(CMAKE_CXX_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
+endif()
+
+if(NOT CMAKE_CXX_COMPILE_OPTIONS_PIE)
+ set(CMAKE_CXX_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
+endif()
+
+if(NOT CMAKE_CXX_COMPILE_OPTIONS_DLL)
+ set(CMAKE_CXX_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL})
+endif()
+
+if(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
+ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
+ set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
+endif()
+
+if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG)
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
+endif()
+
+if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP)
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
+endif()
+
+if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG)
+ set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
+endif()
+
+if(NOT DEFINED CMAKE_EXE_EXPORTS_CXX_FLAG)
+ set(CMAKE_EXE_EXPORTS_CXX_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG)
+ set(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
+endif()
+
+if(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG)
+ set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG})
+endif()
+
+if(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG_SEP)
+ set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP})
+endif()
+
+if(NOT CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG)
+ set(CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_WITH_RUNTIME_PATH)
+ set(CMAKE_SHARED_LIBRARY_LINK_CXX_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
+endif()
+
+if(NOT CMAKE_INCLUDE_FLAG_CXX)
+ set(CMAKE_INCLUDE_FLAG_CXX ${CMAKE_INCLUDE_FLAG_C})
+endif()
+
+if(NOT CMAKE_INCLUDE_FLAG_SEP_CXX)
+ set(CMAKE_INCLUDE_FLAG_SEP_CXX ${CMAKE_INCLUDE_FLAG_SEP_C})
+endif()
+
+# for most systems a module is the same as a shared library
+# so unless the variable CMAKE_MODULE_EXISTS is set just
+# copy the values from the LIBRARY variables
+if(NOT CMAKE_MODULE_EXISTS)
+ set(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS})
+ set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS})
+endif()
+
+# repeat for modules
+if(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS)
+ set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
+endif()
+
+if(NOT CMAKE_SHARED_MODULE_CXX_FLAGS)
+ set(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
+endif()
+
+# Initialize CXX link type selection flags from C versions.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ if(NOT CMAKE_${type}_LINK_STATIC_CXX_FLAGS)
+ set(CMAKE_${type}_LINK_STATIC_CXX_FLAGS
+ ${CMAKE_${type}_LINK_STATIC_C_FLAGS})
+ endif()
+ if(NOT CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS)
+ set(CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS
+ ${CMAKE_${type}_LINK_DYNAMIC_C_FLAGS})
+ endif()
+endforeach()
+
+# add the flags to the cache based
+# on the initial values computed in the platform/*.cmake files
+# use _INIT variables so that this only happens the first time
+# and you can set these flags in the cmake cache
+set(CMAKE_CXX_FLAGS_INIT "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}")
+# avoid just having a space as the initial value for the cache
+if(CMAKE_CXX_FLAGS_INIT STREQUAL " ")
+ set(CMAKE_CXX_FLAGS_INIT)
+endif()
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT}" CACHE STRING
+ "Flags used by the compiler during all build types.")
+
+if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
+ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT}" CACHE STRING
+ "Flags used by the compiler during debug builds.")
+ set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT}" CACHE STRING
+ "Flags used by the compiler during release builds for minimum size.")
+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT}" CACHE STRING
+ "Flags used by the compiler during release builds.")
+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
+ "Flags used by the compiler during release builds with debug info.")
+
+endif()
+
+if(CMAKE_CXX_STANDARD_LIBRARIES_INIT)
+ set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES_INIT}"
+ CACHE STRING "Libraries linked by default with all C++ applications.")
+ mark_as_advanced(CMAKE_CXX_STANDARD_LIBRARIES)
+endif()
+
+include(CMakeCommonLanguageInclude)
+
+# now define the following rules:
+# CMAKE_CXX_CREATE_SHARED_LIBRARY
+# CMAKE_CXX_CREATE_SHARED_MODULE
+# CMAKE_CXX_COMPILE_OBJECT
+# CMAKE_CXX_LINK_EXECUTABLE
+
+# variables supplied by the generator at use time
+# <TARGET>
+# <TARGET_BASE> the target without the suffix
+# <OBJECTS>
+# <OBJECT>
+# <LINK_LIBRARIES>
+# <FLAGS>
+# <LINK_FLAGS>
+
+# CXX compiler information
+# <CMAKE_CXX_COMPILER>
+# <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>
+# <CMAKE_CXX_SHARED_MODULE_CREATE_FLAGS>
+# <CMAKE_CXX_LINK_FLAGS>
+
+# Static library tools
+# <CMAKE_AR>
+# <CMAKE_RANLIB>
+
+
+# create a shared C++ library
+if(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
+ set(CMAKE_CXX_CREATE_SHARED_LIBRARY
+ "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+endif()
+
+# create a c++ shared module copy the shared library rule by default
+if(NOT CMAKE_CXX_CREATE_SHARED_MODULE)
+ set(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
+endif()
+
+
+# Create a static archive incrementally for large object file counts.
+# If CMAKE_CXX_CREATE_STATIC_LIBRARY is set it will override these.
+if(NOT DEFINED CMAKE_CXX_ARCHIVE_CREATE)
+ set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> cq <TARGET> <LINK_FLAGS> <OBJECTS>")
+endif()
+if(NOT DEFINED CMAKE_CXX_ARCHIVE_APPEND)
+ set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
+endif()
+if(NOT DEFINED CMAKE_CXX_ARCHIVE_FINISH)
+ set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
+endif()
+
+# compile a C++ file into an object file
+if(NOT CMAKE_CXX_COMPILE_OBJECT)
+ set(CMAKE_CXX_COMPILE_OBJECT
+ "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+endif()
+
+if(NOT CMAKE_CXX_LINK_EXECUTABLE)
+ set(CMAKE_CXX_LINK_EXECUTABLE
+ "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+endif()
+
+mark_as_advanced(
+CMAKE_VERBOSE_MAKEFILE
+CMAKE_CXX_FLAGS
+CMAKE_CXX_FLAGS_RELEASE
+CMAKE_CXX_FLAGS_RELWITHDEBINFO
+CMAKE_CXX_FLAGS_MINSIZEREL
+CMAKE_CXX_FLAGS_DEBUG)
+
+set(CMAKE_CXX_INFORMATION_LOADED 1)
+
diff --git a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake
new file mode 100644
index 0000000000..19b2bbcf31
--- /dev/null
+++ b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake
@@ -0,0 +1,43 @@
+
+#=============================================================================
+# Copyright 2006-2011 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
+# Copyright 2011 Matthias Kretz <kretz@kde.org>
+# Copyright 2013 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+# Do NOT include this module directly into any of your code. It is meant as
+# a library for Check*CompilerFlag.cmake modules. It's content may change in
+# any way between releases.
+
+macro (CHECK_COMPILER_FLAG_COMMON_PATTERNS _VAR)
+ set(${_VAR}
+ FAIL_REGEX "unrecognized .*option" # GNU
+ FAIL_REGEX "unknown .*option" # Clang
+ FAIL_REGEX "ignoring unknown option" # MSVC
+ FAIL_REGEX "warning D9002" # MSVC, any lang
+ FAIL_REGEX "option.*not supported" # Intel
+ FAIL_REGEX "invalid argument .*option" # Intel
+ FAIL_REGEX "ignoring option .*argument required" # Intel
+ FAIL_REGEX "ignoring option .*argument is of wrong type" # Intel
+ FAIL_REGEX "[Uu]nknown option" # HP
+ FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
+ FAIL_REGEX "command option .* is not recognized" # XL
+ FAIL_REGEX "command option .* contains an incorrect subargument" # XL
+ FAIL_REGEX "not supported in this configuration. ignored" # AIX
+ FAIL_REGEX "File with unknown suffix passed to linker" # PGI
+ FAIL_REGEX "WARNING: unknown flag:" # Open64
+ FAIL_REGEX "Incorrect command line option:" # Borland
+ FAIL_REGEX "Warning: illegal option" # SunStudio 12
+ FAIL_REGEX "[Ww]arning: Invalid suboption" # Fujitsu
+ )
+endmacro ()
diff --git a/Modules/CMakeClDeps.cmake b/Modules/CMakeClDeps.cmake
new file mode 100644
index 0000000000..b46e7c254c
--- /dev/null
+++ b/Modules/CMakeClDeps.cmake
@@ -0,0 +1,34 @@
+
+#=============================================================================
+# Copyright 2012 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.)
+
+#
+# When using Ninja cl.exe is wrapped by cmcldeps to extract the included
+# headers for dependency tracking.
+#
+# cmcldeps path is set, and cmcldeps needs to know the localized string
+# in front of each include path, so it can remove it.
+#
+
+if(CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_C_COMPILER AND CMAKE_COMMAND)
+ string(REPLACE "cmake.exe" "cmcldeps.exe" CMAKE_CMCLDEPS_EXECUTABLE ${CMAKE_COMMAND})
+ set(showdir ${CMAKE_BINARY_DIR}/CMakeFiles/ShowIncludes)
+ file(WRITE ${showdir}/foo.h "\n")
+ file(WRITE ${showdir}/main.c "#include \"foo.h\" \nint main(){}\n")
+ execute_process(COMMAND ${CMAKE_C_COMPILER} /nologo /showIncludes ${showdir}/main.c
+ WORKING_DIRECTORY ${showdir} OUTPUT_VARIABLE outLine)
+ string(REGEX MATCH "\n([^:]*:[^:]*:[ \t]*)" tmp "${outLine}")
+ set(localizedPrefix "${CMAKE_MATCH_1}")
+ set(SET_CMAKE_CMCLDEPS_EXECUTABLE "set(CMAKE_CMCLDEPS_EXECUTABLE \"${CMAKE_CMCLDEPS_EXECUTABLE}\")")
+ set(SET_CMAKE_CL_SHOWINCLUDES_PREFIX "set(CMAKE_CL_SHOWINCLUDES_PREFIX \"${localizedPrefix}\")")
+endif()
diff --git a/Modules/CMakeCommonLanguageInclude.cmake b/Modules/CMakeCommonLanguageInclude.cmake
new file mode 100644
index 0000000000..fa025a8928
--- /dev/null
+++ b/Modules/CMakeCommonLanguageInclude.cmake
@@ -0,0 +1,133 @@
+
+#=============================================================================
+# Copyright 2004-2009 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 has flags that are shared across languages and sets
+# cache values that can be initialized in the platform-compiler.cmake file
+# it may be included by more than one language.
+
+if(NOT "x$ENV{LDFLAGS}" STREQUAL "x")
+ set (CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} $ENV{LDFLAGS}")
+ set (CMAKE_SHARED_LINKER_FLAGS_INIT "${CMAKE_SHARED_LINKER_FLAGS_INIT} $ENV{LDFLAGS}")
+ set (CMAKE_MODULE_LINKER_FLAGS_INIT "${CMAKE_MODULE_LINKER_FLAGS_INIT} $ENV{LDFLAGS}")
+endif()
+
+if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
+# default build type is none
+ if(NOT CMAKE_NO_BUILD_TYPE)
+ set (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
+ "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
+ endif()
+
+ set (CMAKE_EXE_LINKER_FLAGS_DEBUG ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT} CACHE STRING
+ "Flags used by the linker during debug builds.")
+
+ set (CMAKE_EXE_LINKER_FLAGS_MINSIZEREL ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT} CACHE STRING
+ "Flags used by the linker during release minsize builds.")
+
+ set (CMAKE_EXE_LINKER_FLAGS_RELEASE ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT} CACHE STRING
+ "Flags used by the linker during release builds.")
+
+ set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
+ ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT} CACHE STRING
+ "Flags used by the linker during Release with Debug Info builds.")
+
+ set (CMAKE_SHARED_LINKER_FLAGS_DEBUG ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT} CACHE STRING
+ "Flags used by the linker during debug builds.")
+
+ set (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL ${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT}
+ CACHE STRING
+ "Flags used by the linker during release minsize builds.")
+
+ set (CMAKE_SHARED_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT} CACHE STRING
+ "Flags used by the linker during release builds.")
+
+ set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
+ ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT} CACHE STRING
+ "Flags used by the linker during Release with Debug Info builds.")
+
+ set (CMAKE_MODULE_LINKER_FLAGS_DEBUG ${CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT} CACHE STRING
+ "Flags used by the linker during debug builds.")
+
+ set (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL ${CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT}
+ CACHE STRING
+ "Flags used by the linker during release minsize builds.")
+
+ set (CMAKE_MODULE_LINKER_FLAGS_RELEASE ${CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT} CACHE STRING
+ "Flags used by the linker during release builds.")
+
+ set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
+ ${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT} CACHE STRING
+ "Flags used by the linker during Release with Debug Info builds.")
+
+ set (CMAKE_STATIC_LINKER_FLAGS_DEBUG ${CMAKE_STATIC_LINKER_FLAGS_DEBUG_INIT} CACHE STRING
+ "Flags used by the linker during debug builds.")
+
+ set (CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL ${CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL_INIT}
+ CACHE STRING
+ "Flags used by the linker during release minsize builds.")
+
+ set (CMAKE_STATIC_LINKER_FLAGS_RELEASE ${CMAKE_STATIC_LINKER_FLAGS_RELEASE_INIT} CACHE STRING
+ "Flags used by the linker during release builds.")
+
+ set (CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO
+ ${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO_INIT} CACHE STRING
+ "Flags used by the linker during Release with Debug Info builds.")
+endif()
+
+# executable linker flags
+set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_INIT}"
+ CACHE STRING "Flags used by the linker.")
+
+# shared linker flags
+set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_INIT}"
+ CACHE STRING "Flags used by the linker during the creation of dll's.")
+
+# module linker flags
+set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS_INIT}"
+ CACHE STRING "Flags used by the linker during the creation of modules.")
+
+# static linker flags
+set (CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS_INIT}"
+ CACHE STRING "Flags used by the linker during the creation of static libraries.")
+
+# Alias the build tool variable for backward compatibility.
+set(CMAKE_BUILD_TOOL ${CMAKE_MAKE_PROGRAM})
+
+mark_as_advanced(
+CMAKE_VERBOSE_MAKEFILE
+
+CMAKE_EXE_LINKER_FLAGS
+CMAKE_EXE_LINKER_FLAGS_DEBUG
+CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
+CMAKE_EXE_LINKER_FLAGS_RELEASE
+CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
+
+CMAKE_SHARED_LINKER_FLAGS
+CMAKE_SHARED_LINKER_FLAGS_DEBUG
+CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
+CMAKE_SHARED_LINKER_FLAGS_RELEASE
+CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
+
+CMAKE_MODULE_LINKER_FLAGS
+CMAKE_MODULE_LINKER_FLAGS_DEBUG
+CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL
+CMAKE_MODULE_LINKER_FLAGS_RELEASE
+CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
+
+CMAKE_STATIC_LINKER_FLAGS
+CMAKE_STATIC_LINKER_FLAGS_DEBUG
+CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL
+CMAKE_STATIC_LINKER_FLAGS_RELEASE
+CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO
+)
diff --git a/Modules/CMakeCompilerABI.h b/Modules/CMakeCompilerABI.h
new file mode 100644
index 0000000000..26ae4db6a6
--- /dev/null
+++ b/Modules/CMakeCompilerABI.h
@@ -0,0 +1,36 @@
+/*--------------------------------------------------------------------------*/
+
+/* Size of a pointer-to-data in bytes. */
+#define SIZEOF_DPTR (sizeof(void*))
+const char info_sizeof_dptr[] = {
+ 'I', 'N', 'F', 'O', ':', 's', 'i', 'z', 'e', 'o', 'f', '_', 'd', 'p', 't', 'r', '[',
+ ('0' + ((SIZEOF_DPTR / 10)%10)),
+ ('0' + (SIZEOF_DPTR % 10)),
+ ']','\0'};
+
+/*--------------------------------------------------------------------------*/
+
+/* Application Binary Interface. */
+#if defined(__sgi) && defined(_ABIO32)
+# define ABI_ID "ELF O32"
+#elif defined(__sgi) && defined(_ABIN32)
+# define ABI_ID "ELF N32"
+#elif defined(__sgi) && defined(_ABI64)
+# define ABI_ID "ELF 64"
+
+/* Check for (some) ARM ABIs.
+ * See e.g. http://wiki.debian.org/ArmEabiPort for some information on this. */
+#elif defined(__GNU__) && defined(__ELF__) && defined(__ARM_EABI__)
+# define ABI_ID "ELF ARMEABI"
+#elif defined(__GNU__) && defined(__ELF__) && defined(__ARMEB__)
+# define ABI_ID "ELF ARM"
+#elif defined(__GNU__) && defined(__ELF__) && defined(__ARMEL__)
+# define ABI_ID "ELF ARM"
+
+#elif defined(__ELF__)
+# define ABI_ID "ELF"
+#endif
+
+#if defined(ABI_ID)
+static char const info_abi[] = "INFO:abi[" ABI_ID "]";
+#endif
diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake
new file mode 100644
index 0000000000..19bcbcc284
--- /dev/null
+++ b/Modules/CMakeCompilerIdDetection.cmake
@@ -0,0 +1,157 @@
+
+#=============================================================================
+# Copyright 2014 Stephen Kelly <steveire@gmail.com>
+#
+# 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(_readFile file)
+ include(${file})
+ get_filename_component(name ${file} NAME_WE)
+ string(REGEX REPLACE "-.*" "" CompilerId ${name})
+ set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE)
+ set(_compiler_id_simulate_${CompilerId} ${_compiler_id_simulate} PARENT_SCOPE)
+ set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE)
+endfunction()
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
+
+function(compiler_id_detection outvar lang)
+
+ if (NOT lang STREQUAL Fortran)
+ file(GLOB lang_files
+ "${CMAKE_ROOT}/Modules/Compiler/*-DetermineCompiler.cmake")
+ set(nonlang CXX)
+ if (lang STREQUAL CXX)
+ set(nonlang C)
+ endif()
+
+ file(GLOB nonlang_files
+ "${CMAKE_ROOT}/Modules/Compiler/*-${nonlang}-DetermineCompiler.cmake")
+ list(REMOVE_ITEM lang_files ${nonlang_files})
+ endif()
+
+ set(files ${lang_files})
+ if (files)
+ foreach(file ${files})
+ _readFile(${file})
+ endforeach()
+
+ set(options ID_STRING VERSION_STRINGS ID_DEFINE PLATFORM_DEFAULT_COMPILER)
+ set(oneValueArgs PREFIX)
+ cmake_parse_arguments(CID "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ if (CID_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unrecognized arguments: \"${CID_UNPARSED_ARGUMENTS}\"")
+ endif()
+
+ # Order is relevant here. For example, compilers which pretend to be
+ # GCC must appear before the actual GCC.
+ if (lang STREQUAL CXX)
+ list(APPEND ordered_compilers
+ Comeau
+ )
+ endif()
+ list(APPEND ordered_compilers
+ Intel
+ PathScale
+ Embarcadero
+ Borland
+ Watcom
+ OpenWatcom
+ SunPro
+ HP
+ Compaq
+ zOS
+ XL
+ VisualAge
+ PGI
+ Cray
+ TI
+ Fujitsu
+ )
+ if (lang STREQUAL C)
+ list(APPEND ordered_compilers
+ TinyCC
+ )
+ endif()
+ list(APPEND ordered_compilers
+ SCO
+ AppleClang
+ Clang
+ GNU
+ MSVC
+ ADSP
+ IAR
+ )
+ if (lang STREQUAL C)
+ list(APPEND ordered_compilers
+ SDCC
+ )
+ endif()
+ list(APPEND ordered_compilers
+ MIPSpro)
+
+ if(CID_ID_DEFINE)
+ foreach(Id ${ordered_compilers})
+ set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}# define ${CID_PREFIX}COMPILER_IS_${Id} 0\n")
+ endforeach()
+ endif()
+
+ set(pp_if "#if")
+ if (CID_VERSION_STRINGS)
+ set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n/* Version number components: V=Version, R=Revision, P=Patch
+ Version date components: YYYY=Year, MM=Month, DD=Day */\n")
+ endif()
+
+ foreach(Id ${ordered_compilers})
+ if (NOT _compiler_id_pp_test_${Id})
+ message(FATAL_ERROR "No preprocessor test for \"${Id}\"")
+ endif()
+ set(id_content "${pp_if} ${_compiler_id_pp_test_${Id}}\n")
+ if (CID_ID_STRING)
+ set(PREFIX ${CID_PREFIX})
+ string(CONFIGURE "${_compiler_id_simulate_${Id}}" SIMULATE_BLOCK @ONLY)
+ set(id_content "${id_content}# define ${CID_PREFIX}COMPILER_ID \"${Id}\"${SIMULATE_BLOCK}")
+ endif()
+ if (CID_ID_DEFINE)
+ set(id_content "${id_content}# undef ${CID_PREFIX}COMPILER_IS_${Id}\n")
+ set(id_content "${id_content}# define ${CID_PREFIX}COMPILER_IS_${Id} 1\n")
+ endif()
+ if (CID_VERSION_STRINGS)
+ set(PREFIX ${CID_PREFIX})
+ set(MACRO_DEC DEC)
+ set(MACRO_HEX HEX)
+ string(CONFIGURE "${_compiler_id_version_compute_${Id}}" VERSION_BLOCK @ONLY)
+ set(id_content "${id_content}${VERSION_BLOCK}\n")
+ endif()
+ set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${id_content}")
+ set(pp_if "#elif")
+ endforeach()
+
+ if (CID_PLATFORM_DEFAULT_COMPILER)
+ set(platform_compiler_detection "
+/* These compilers are either not known or too old to define an
+ identification macro. Try to identify the platform and guess that
+ it is the native compiler. */
+#elif defined(__sgi)
+# define ${CID_PREFIX}COMPILER_ID \"MIPSpro\"
+
+#elif defined(__hpux) || defined(__hpua)
+# define ${CID_PREFIX}COMPILER_ID \"HP\"
+
+#else /* unknown compiler */
+# define ${CID_PREFIX}COMPILER_ID \"\"")
+ endif()
+
+ set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${platform_compiler_detection}\n#endif")
+ endif()
+
+ set(${outvar} ${CMAKE_${lang}_COMPILER_ID_CONTENT} PARENT_SCOPE)
+endfunction()
diff --git a/Modules/CMakeConfigurableFile.in b/Modules/CMakeConfigurableFile.in
new file mode 100644
index 0000000000..df2c382e9b
--- /dev/null
+++ b/Modules/CMakeConfigurableFile.in
@@ -0,0 +1 @@
+@CMAKE_CONFIGURABLE_FILE_CONTENT@
diff --git a/Modules/CMakeDependentOption.cmake b/Modules/CMakeDependentOption.cmake
new file mode 100644
index 0000000000..7e9f183f11
--- /dev/null
+++ b/Modules/CMakeDependentOption.cmake
@@ -0,0 +1,59 @@
+#.rst:
+# CMakeDependentOption
+# --------------------
+#
+# Macro to provide an option dependent on other options.
+#
+# This macro presents an option to the user only if a set of other
+# conditions are true. When the option is not presented a default value
+# is used, but any value set by the user is preserved for when the
+# option is presented again. Example invocation:
+#
+# ::
+#
+# CMAKE_DEPENDENT_OPTION(USE_FOO "Use Foo" ON
+# "USE_BAR;NOT USE_ZOT" OFF)
+#
+# If USE_BAR is true and USE_ZOT is false, this provides an option
+# called USE_FOO that defaults to ON. Otherwise, it sets USE_FOO to
+# OFF. If the status of USE_BAR or USE_ZOT ever changes, any value for
+# the USE_FOO option is saved so that when the option is re-enabled it
+# retains its old value.
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+macro(CMAKE_DEPENDENT_OPTION option doc default depends force)
+ if(${option}_ISSET MATCHES "^${option}_ISSET$")
+ set(${option}_AVAILABLE 1)
+ foreach(d ${depends})
+ string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
+ if(${CMAKE_DEPENDENT_OPTION_DEP})
+ else()
+ set(${option}_AVAILABLE 0)
+ endif()
+ endforeach()
+ if(${option}_AVAILABLE)
+ option(${option} "${doc}" "${default}")
+ set(${option} "${${option}}" CACHE BOOL "${doc}" FORCE)
+ else()
+ if(${option} MATCHES "^${option}$")
+ else()
+ set(${option} "${${option}}" CACHE INTERNAL "${doc}")
+ endif()
+ set(${option} ${force})
+ endif()
+ else()
+ set(${option} "${${option}_ISSET}")
+ endif()
+endmacro()
diff --git a/Modules/CMakeDetermineASM-ATTCompiler.cmake b/Modules/CMakeDetermineASM-ATTCompiler.cmake
new file mode 100644
index 0000000000..03c5668109
--- /dev/null
+++ b/Modules/CMakeDetermineASM-ATTCompiler.cmake
@@ -0,0 +1,20 @@
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# determine the compiler to use for ASM using AT&T syntax, e.g. GNU as
+
+set(ASM_DIALECT "-ATT")
+set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}gas ${_CMAKE_TOOLCHAIN_PREFIX}as)
+include(CMakeDetermineASMCompiler)
+set(ASM_DIALECT)
diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake
new file mode 100644
index 0000000000..25af3e39e4
--- /dev/null
+++ b/Modules/CMakeDetermineASMCompiler.cmake
@@ -0,0 +1,159 @@
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# determine the compiler to use for ASM programs
+
+include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+
+if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
+ # prefer the environment variable ASM
+ if(NOT $ENV{ASM${ASM_DIALECT}} STREQUAL "")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT "$ENV{ASM${ASM_DIALECT}}")
+ endif()
+
+ # finally list compilers to try
+ if("ASM${ASM_DIALECT}" STREQUAL "ASM") # the generic assembler support
+ if(NOT CMAKE_ASM_COMPILER_INIT)
+ if(CMAKE_C_COMPILER)
+ set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}" CACHE FILEPATH "The ASM compiler")
+ set(CMAKE_ASM_COMPILER_ID "${CMAKE_C_COMPILER_ID}")
+ elseif(CMAKE_CXX_COMPILER)
+ set(CMAKE_ASM_COMPILER "${CMAKE_CXX_COMPILER}" CACHE FILEPATH "The ASM compiler")
+ set(CMAKE_ASM_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}")
+ else()
+ # List all default C and CXX compilers
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST
+ ${_CMAKE_TOOLCHAIN_PREFIX}cc ${_CMAKE_TOOLCHAIN_PREFIX}gcc cl bcc xlc
+ CC ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ aCC cl bcc xlC)
+ endif()
+ endif()
+ else() # some specific assembler "dialect"
+ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT AND NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST)
+ message(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT or CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST must be preset !")
+ endif()
+ endif()
+
+ # Find the compiler.
+ _cmake_find_compiler(ASM${ASM_DIALECT})
+
+else()
+ _cmake_find_compiler_path(ASM${ASM_DIALECT})
+endif()
+mark_as_advanced(CMAKE_ASM${ASM_DIALECT}_COMPILER)
+
+if (NOT _CMAKE_TOOLCHAIN_LOCATION)
+ get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
+endif ()
+
+
+if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
+
+ # Table of per-vendor compiler id flags with expected output.
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_GNU "--version")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_GNU "(GNU assembler)|(GCC)|(Free Software Foundation)")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS HP )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_HP "-V")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_HP "HP C")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS Intel )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_Intel "--version")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_Intel "(ICC)")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS SunPro )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_SunPro "-V")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_SunPro "Sun C")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS XL )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_XL "-qversion")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_XL "XL C")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS MSVC )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_MSVC "/?")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_MSVC "Microsoft")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS TI )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_TI "-h")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_TI "Texas Instruments")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU IAR)
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_IAR )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_IAR "IAR Assembler")
+
+ include(CMakeDetermineCompilerId)
+ CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT})
+
+endif()
+
+if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
+ message(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
+else()
+ message(STATUS "The ASM${ASM_DIALECT} compiler identification is unknown")
+endif()
+
+
+
+# If we have a gas/as cross compiler, they have usually some prefix, like
+# e.g. powerpc-linux-gas, arm-elf-gas or i586-mingw32msvc-gas , optionally
+# with a 3-component version number at the end
+# The other tools of the toolchain usually have the same prefix
+# NAME_WE cannot be used since then this test will fail for names like
+# "arm-unknown-nto-qnx6.3.0-gas.exe", where BASENAME would be
+# "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
+if (NOT _CMAKE_TOOLCHAIN_PREFIX)
+ get_filename_component(COMPILER_BASENAME "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" NAME)
+ if (COMPILER_BASENAME MATCHES "^(.+-)g?as(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ endif ()
+endif ()
+
+# Now try the C compiler regexp:
+if (NOT _CMAKE_TOOLCHAIN_PREFIX)
+ if (COMPILER_BASENAME MATCHES "^(.+-)g?cc(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ endif ()
+endif ()
+
+# Finally try the CXX compiler regexp:
+if (NOT _CMAKE_TOOLCHAIN_PREFIX)
+ if (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ endif ()
+endif ()
+
+
+include(CMakeFindBinUtils)
+
+set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR "ASM${ASM_DIALECT}")
+
+if(CMAKE_ASM${ASM_DIALECT}_COMPILER)
+ message(STATUS "Found assembler: ${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
+else()
+ message(STATUS "Didn't find assembler")
+endif()
+
+
+set(_CMAKE_ASM_COMPILER "${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
+set(_CMAKE_ASM_COMPILER_ID "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
+set(_CMAKE_ASM_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1}")
+set(_CMAKE_ASM_COMPILER_ENV_VAR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR}")
+
+# configure variables set in this file for fast reload later on
+configure_file(${CMAKE_ROOT}/Modules/CMakeASMCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeASM${ASM_DIALECT}Compiler.cmake @ONLY)
+
+set(_CMAKE_ASM_COMPILER)
+set(_CMAKE_ASM_COMPILER_ARG1)
+set(_CMAKE_ASM_COMPILER_ENV_VAR)
diff --git a/Modules/CMakeDetermineASM_MASMCompiler.cmake b/Modules/CMakeDetermineASM_MASMCompiler.cmake
new file mode 100644
index 0000000000..142ef950a6
--- /dev/null
+++ b/Modules/CMakeDetermineASM_MASMCompiler.cmake
@@ -0,0 +1,28 @@
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+# Find the MS assembler (masm or masm64)
+
+set(ASM_DIALECT "_MASM")
+
+# if we are using the 64bit cl compiler, assume we also want the 64bit assembler
+if(";${CMAKE_VS_PLATFORM_NAME};${MSVC_C_ARCHITECTURE_ID};${MSVC_CXX_ARCHITECTURE_ID};"
+ MATCHES ";(Win64|Itanium|x64|IA64);")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT ml64)
+else()
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT ml)
+endif()
+
+include(CMakeDetermineASMCompiler)
+set(ASM_DIALECT)
diff --git a/Modules/CMakeDetermineASM_NASMCompiler.cmake b/Modules/CMakeDetermineASM_NASMCompiler.cmake
new file mode 100644
index 0000000000..5d783b1556
--- /dev/null
+++ b/Modules/CMakeDetermineASM_NASMCompiler.cmake
@@ -0,0 +1,27 @@
+
+#=============================================================================
+# Copyright 2010 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.)
+
+# Find the nasm assembler. yasm (http://www.tortall.net/projects/yasm/) is nasm compatible
+
+set(CMAKE_ASM_NASM_COMPILER_LIST nasm yasm)
+
+if(NOT CMAKE_ASM_NASM_COMPILER)
+ find_program(CMAKE_ASM_NASM_COMPILER nasm
+ "$ENV{ProgramFiles}/NASM")
+endif()
+
+# Load the generic DetermineASM compiler file with the DIALECT set properly:
+set(ASM_DIALECT "_NASM")
+include(CMakeDetermineASMCompiler)
+set(ASM_DIALECT)
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake
new file mode 100644
index 0000000000..6b425c696a
--- /dev/null
+++ b/Modules/CMakeDetermineCCompiler.cmake
@@ -0,0 +1,176 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+# determine the compiler to use for C programs
+# NOTE, a generator may set CMAKE_C_COMPILER before
+# loading this file to force a compiler.
+# use environment variable CC first if defined by user, next use
+# the cmake variable CMAKE_GENERATOR_CC which can be defined by a generator
+# as a default compiler
+# If the internal cmake variable _CMAKE_TOOLCHAIN_PREFIX is set, this is used
+# as prefix for the tools (e.g. arm-elf-gcc, arm-elf-ar etc.). This works
+# currently with the GNU crosscompilers.
+#
+# Sets the following variables:
+# CMAKE_C_COMPILER
+# CMAKE_AR
+# CMAKE_RANLIB
+# CMAKE_COMPILER_IS_GNUCC
+#
+# If not already set before, it also sets
+# _CMAKE_TOOLCHAIN_PREFIX
+
+include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+
+# Load system-specific compiler preferences for this language.
+include(Platform/${CMAKE_SYSTEM_NAME}-C OPTIONAL)
+if(NOT CMAKE_C_COMPILER_NAMES)
+ set(CMAKE_C_COMPILER_NAMES cc)
+endif()
+
+if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
+elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
+ set(CMAKE_C_COMPILER_XCODE_TYPE sourcecode.c.c)
+ _cmake_find_compiler_path(C)
+else()
+ if(NOT CMAKE_C_COMPILER)
+ set(CMAKE_C_COMPILER_INIT NOTFOUND)
+
+ # prefer the environment variable CC
+ if(NOT $ENV{CC} STREQUAL "")
+ get_filename_component(CMAKE_C_COMPILER_INIT $ENV{CC} PROGRAM PROGRAM_ARGS CMAKE_C_FLAGS_ENV_INIT)
+ if(CMAKE_C_FLAGS_ENV_INIT)
+ set(CMAKE_C_COMPILER_ARG1 "${CMAKE_C_FLAGS_ENV_INIT}" CACHE STRING "First argument to C compiler")
+ endif()
+ if(NOT EXISTS ${CMAKE_C_COMPILER_INIT})
+ message(FATAL_ERROR "Could not find compiler set in environment variable CC:\n$ENV{CC}.")
+ endif()
+ endif()
+
+ # next try prefer the compiler specified by the generator
+ if(CMAKE_GENERATOR_CC)
+ if(NOT CMAKE_C_COMPILER_INIT)
+ set(CMAKE_C_COMPILER_INIT ${CMAKE_GENERATOR_CC})
+ endif()
+ endif()
+
+ # finally list compilers to try
+ if(NOT CMAKE_C_COMPILER_INIT)
+ set(CMAKE_C_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}cc ${_CMAKE_TOOLCHAIN_PREFIX}gcc cl bcc xlc clang)
+ endif()
+
+ _cmake_find_compiler(C)
+
+ else()
+ _cmake_find_compiler_path(C)
+ endif()
+ mark_as_advanced(CMAKE_C_COMPILER)
+
+ # Each entry in this list is a set of extra flags to try
+ # adding to the compile line to see if it helps produce
+ # a valid identification file.
+ set(CMAKE_C_COMPILER_ID_TEST_FLAGS
+ # Try compiling to an object file only.
+ "-c"
+
+ # Try enabling ANSI mode on HP.
+ "-Aa"
+ )
+endif()
+
+# Build a small source file to identify the compiler.
+if(NOT CMAKE_C_COMPILER_ID_RUN)
+ set(CMAKE_C_COMPILER_ID_RUN 1)
+
+ # Try to identify the compiler.
+ set(CMAKE_C_COMPILER_ID)
+ file(READ ${CMAKE_ROOT}/Modules/CMakePlatformId.h.in
+ CMAKE_C_COMPILER_ID_PLATFORM_CONTENT)
+
+ # The IAR compiler produces weird output.
+ # See http://www.cmake.org/Bug/view.php?id=10176#c19598
+ list(APPEND CMAKE_C_COMPILER_ID_VENDORS IAR)
+ set(CMAKE_C_COMPILER_ID_VENDOR_FLAGS_IAR )
+ set(CMAKE_C_COMPILER_ID_VENDOR_REGEX_IAR "IAR .+ Compiler")
+
+ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
+ CMAKE_DETERMINE_COMPILER_ID(C CFLAGS CMakeCCompilerId.c)
+
+ # Set old compiler and platform id variables.
+ if("${CMAKE_C_COMPILER_ID}" MATCHES "GNU")
+ set(CMAKE_COMPILER_IS_GNUCC 1)
+ endif()
+ if("${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
+ set(CMAKE_COMPILER_IS_MINGW 1)
+ elseif("${CMAKE_C_PLATFORM_ID}" MATCHES "Cygwin")
+ set(CMAKE_COMPILER_IS_CYGWIN 1)
+ endif()
+endif()
+
+if (NOT _CMAKE_TOOLCHAIN_LOCATION)
+ get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_C_COMPILER}" PATH)
+endif ()
+
+# If we have a gcc cross compiler, they have usually some prefix, like
+# e.g. powerpc-linux-gcc, arm-elf-gcc or i586-mingw32msvc-gcc, optionally
+# with a 3-component version number at the end (e.g. arm-eabi-gcc-4.5.2).
+# The other tools of the toolchain usually have the same prefix
+# NAME_WE cannot be used since then this test will fail for names like
+# "arm-unknown-nto-qnx6.3.0-gcc.exe", where BASENAME would be
+# "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
+if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX)
+
+ if("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
+ get_filename_component(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME)
+ if (COMPILER_BASENAME MATCHES "^(.+-)(clang|g?cc)(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ elseif("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
+ if(CMAKE_C_COMPILER_TARGET)
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_C_COMPILER_TARGET}-)
+ endif()
+ elseif(COMPILER_BASENAME MATCHES "qcc(\\.exe)?$")
+ if(CMAKE_C_COMPILER_TARGET MATCHES "gcc_nto([^_le]+)(le)?")
+ set(_CMAKE_TOOLCHAIN_PREFIX nto${CMAKE_MATCH_1}-)
+ endif()
+ endif ()
+
+ # if "llvm-" is part of the prefix, remove it, since llvm doesn't have its own binutils
+ # but uses the regular ar, objcopy, etc. (instead of llvm-objcopy etc.)
+ if ("${_CMAKE_TOOLCHAIN_PREFIX}" MATCHES "(.+-)?llvm-$")
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ endif ()
+ elseif("${CMAKE_C_COMPILER_ID}" MATCHES "TI")
+ # TI compilers are named e.g. cl6x, cl470 or armcl.exe
+ get_filename_component(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME)
+ if (COMPILER_BASENAME MATCHES "^(.+)?cl([^.]+)?(\\.exe)?$")
+ set(_CMAKE_TOOLCHAIN_PREFIX "${CMAKE_MATCH_1}")
+ set(_CMAKE_TOOLCHAIN_SUFFIX "${CMAKE_MATCH_2}")
+ endif ()
+ endif()
+
+endif ()
+
+include(CMakeFindBinUtils)
+if(MSVC_C_ARCHITECTURE_ID)
+ include(${CMAKE_ROOT}/Modules/CMakeClDeps.cmake)
+ set(SET_MSVC_C_ARCHITECTURE_ID
+ "set(MSVC_C_ARCHITECTURE_ID ${MSVC_C_ARCHITECTURE_ID})")
+endif()
+
+# configure variables set in this file for fast reload later on
+configure_file(${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeCCompiler.cmake
+ @ONLY
+ )
+set(CMAKE_C_COMPILER_ENV_VAR "CC")
diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake
new file mode 100644
index 0000000000..893c454ccc
--- /dev/null
+++ b/Modules/CMakeDetermineCXXCompiler.cmake
@@ -0,0 +1,175 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+# determine the compiler to use for C++ programs
+# NOTE, a generator may set CMAKE_CXX_COMPILER before
+# loading this file to force a compiler.
+# use environment variable CXX first if defined by user, next use
+# the cmake variable CMAKE_GENERATOR_CXX which can be defined by a generator
+# as a default compiler
+# If the internal cmake variable _CMAKE_TOOLCHAIN_PREFIX is set, this is used
+# as prefix for the tools (e.g. arm-elf-g++, arm-elf-ar etc.)
+#
+# Sets the following variables:
+# CMAKE_CXX_COMPILER
+# CMAKE_COMPILER_IS_GNUCXX
+# CMAKE_AR
+# CMAKE_RANLIB
+#
+# If not already set before, it also sets
+# _CMAKE_TOOLCHAIN_PREFIX
+
+include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+
+# Load system-specific compiler preferences for this language.
+include(Platform/${CMAKE_SYSTEM_NAME}-CXX OPTIONAL)
+if(NOT CMAKE_CXX_COMPILER_NAMES)
+ set(CMAKE_CXX_COMPILER_NAMES CC)
+endif()
+
+if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
+elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
+ set(CMAKE_CXX_COMPILER_XCODE_TYPE sourcecode.cpp.cpp)
+ _cmake_find_compiler_path(CXX)
+else()
+ if(NOT CMAKE_CXX_COMPILER)
+ set(CMAKE_CXX_COMPILER_INIT NOTFOUND)
+
+ # prefer the environment variable CXX
+ if(NOT $ENV{CXX} STREQUAL "")
+ get_filename_component(CMAKE_CXX_COMPILER_INIT $ENV{CXX} PROGRAM PROGRAM_ARGS CMAKE_CXX_FLAGS_ENV_INIT)
+ if(CMAKE_CXX_FLAGS_ENV_INIT)
+ set(CMAKE_CXX_COMPILER_ARG1 "${CMAKE_CXX_FLAGS_ENV_INIT}" CACHE STRING "First argument to CXX compiler")
+ endif()
+ if(NOT EXISTS ${CMAKE_CXX_COMPILER_INIT})
+ message(FATAL_ERROR "Could not find compiler set in environment variable CXX:\n$ENV{CXX}.\n${CMAKE_CXX_COMPILER_INIT}")
+ endif()
+ endif()
+
+ # next prefer the generator specified compiler
+ if(CMAKE_GENERATOR_CXX)
+ if(NOT CMAKE_CXX_COMPILER_INIT)
+ set(CMAKE_CXX_COMPILER_INIT ${CMAKE_GENERATOR_CXX})
+ endif()
+ endif()
+
+ # finally list compilers to try
+ if(NOT CMAKE_CXX_COMPILER_INIT)
+ set(CMAKE_CXX_COMPILER_LIST CC ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ aCC cl bcc xlC clang++)
+ endif()
+
+ _cmake_find_compiler(CXX)
+ else()
+ _cmake_find_compiler_path(CXX)
+ endif()
+ mark_as_advanced(CMAKE_CXX_COMPILER)
+
+ # Each entry in this list is a set of extra flags to try
+ # adding to the compile line to see if it helps produce
+ # a valid identification file.
+ set(CMAKE_CXX_COMPILER_ID_TEST_FLAGS
+ # Try compiling to an object file only.
+ "-c"
+ )
+endif()
+
+# Build a small source file to identify the compiler.
+if(NOT CMAKE_CXX_COMPILER_ID_RUN)
+ set(CMAKE_CXX_COMPILER_ID_RUN 1)
+
+ # Try to identify the compiler.
+ set(CMAKE_CXX_COMPILER_ID)
+ file(READ ${CMAKE_ROOT}/Modules/CMakePlatformId.h.in
+ CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT)
+
+ # The IAR compiler produces weird output.
+ # See http://www.cmake.org/Bug/view.php?id=10176#c19598
+ list(APPEND CMAKE_CXX_COMPILER_ID_VENDORS IAR)
+ set(CMAKE_CXX_COMPILER_ID_VENDOR_FLAGS_IAR )
+ set(CMAKE_CXX_COMPILER_ID_VENDOR_REGEX_IAR "IAR .+ Compiler")
+
+ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
+ CMAKE_DETERMINE_COMPILER_ID(CXX CXXFLAGS CMakeCXXCompilerId.cpp)
+
+ # Set old compiler and platform id variables.
+ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
+ set(CMAKE_COMPILER_IS_GNUCXX 1)
+ endif()
+ if("${CMAKE_CXX_PLATFORM_ID}" MATCHES "MinGW")
+ set(CMAKE_COMPILER_IS_MINGW 1)
+ elseif("${CMAKE_CXX_PLATFORM_ID}" MATCHES "Cygwin")
+ set(CMAKE_COMPILER_IS_CYGWIN 1)
+ endif()
+endif()
+
+if (NOT _CMAKE_TOOLCHAIN_LOCATION)
+ get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_CXX_COMPILER}" PATH)
+endif ()
+
+# if we have a g++ cross compiler, they have usually some prefix, like
+# e.g. powerpc-linux-g++, arm-elf-g++ or i586-mingw32msvc-g++ , optionally
+# with a 3-component version number at the end (e.g. arm-eabi-gcc-4.5.2).
+# The other tools of the toolchain usually have the same prefix
+# NAME_WE cannot be used since then this test will fail for names like
+# "arm-unknown-nto-qnx6.3.0-gcc.exe", where BASENAME would be
+# "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
+
+
+if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX)
+
+ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+ get_filename_component(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME)
+ if (COMPILER_BASENAME MATCHES "^(.+-)(clan)?[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+ if(CMAKE_CXX_COMPILER_TARGET)
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_CXX_COMPILER_TARGET}-)
+ endif()
+ elseif(COMPILER_BASENAME MATCHES "QCC(\\.exe)?$")
+ if(CMAKE_CXX_COMPILER_TARGET MATCHES "gcc_nto([^_le]+)(le)?")
+ set(_CMAKE_TOOLCHAIN_PREFIX nto${CMAKE_MATCH_1}-)
+ endif()
+ endif ()
+
+ # if "llvm-" is part of the prefix, remove it, since llvm doesn't have its own binutils
+ # but uses the regular ar, objcopy, etc. (instead of llvm-objcopy etc.)
+ if ("${_CMAKE_TOOLCHAIN_PREFIX}" MATCHES "(.+-)?llvm-$")
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ endif ()
+ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "TI")
+ # TI compilers are named e.g. cl6x, cl470 or armcl.exe
+ get_filename_component(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME)
+ if (COMPILER_BASENAME MATCHES "^(.+)?cl([^.]+)?(\\.exe)?$")
+ set(_CMAKE_TOOLCHAIN_PREFIX "${CMAKE_MATCH_1}")
+ set(_CMAKE_TOOLCHAIN_SUFFIX "${CMAKE_MATCH_2}")
+ endif ()
+
+ endif()
+
+endif ()
+
+include(CMakeFindBinUtils)
+if(MSVC_CXX_ARCHITECTURE_ID)
+ include(${CMAKE_ROOT}/Modules/CMakeClDeps.cmake)
+ set(SET_MSVC_CXX_ARCHITECTURE_ID
+ "set(MSVC_CXX_ARCHITECTURE_ID ${MSVC_CXX_ARCHITECTURE_ID})")
+endif()
+
+# configure all variables set in this file
+configure_file(${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake
+ @ONLY
+ )
+
+set(CMAKE_CXX_COMPILER_ENV_VAR "CXX")
diff --git a/Modules/CMakeDetermineCompileFeatures.cmake b/Modules/CMakeDetermineCompileFeatures.cmake
new file mode 100644
index 0000000000..2bb7a74e7c
--- /dev/null
+++ b/Modules/CMakeDetermineCompileFeatures.cmake
@@ -0,0 +1,94 @@
+
+#=============================================================================
+# Copyright 2013 Stephen Kelly <steveire@gmail.com>
+#
+# 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(cmake_determine_compile_features lang)
+
+ if(lang STREQUAL C AND COMMAND cmake_record_c_compile_features)
+ message(STATUS "Detecting ${lang} compile features")
+
+ set(CMAKE_C90_COMPILE_FEATURES)
+ set(CMAKE_C99_COMPILE_FEATURES)
+ set(CMAKE_C11_COMPILE_FEATURES)
+
+ include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
+
+ cmake_record_c_compile_features()
+
+ if(NOT _result EQUAL 0)
+ message(STATUS "Detecting ${lang} compile features - failed")
+ return()
+ endif()
+
+ if (CMAKE_C99_COMPILE_FEATURES AND CMAKE_C11_COMPILE_FEATURES)
+ list(REMOVE_ITEM CMAKE_C11_COMPILE_FEATURES ${CMAKE_C99_COMPILE_FEATURES})
+ endif()
+ if (CMAKE_C90_COMPILE_FEATURES AND CMAKE_C99_COMPILE_FEATURES)
+ list(REMOVE_ITEM CMAKE_C99_COMPILE_FEATURES ${CMAKE_C90_COMPILE_FEATURES})
+ endif()
+
+ if(NOT CMAKE_C_COMPILE_FEATURES)
+ set(CMAKE_C_COMPILE_FEATURES
+ ${CMAKE_C90_COMPILE_FEATURES}
+ ${CMAKE_C99_COMPILE_FEATURES}
+ ${CMAKE_C11_COMPILE_FEATURES}
+ )
+ endif()
+
+ set(CMAKE_C_COMPILE_FEATURES ${CMAKE_C_COMPILE_FEATURES} PARENT_SCOPE)
+ set(CMAKE_C90_COMPILE_FEATURES ${CMAKE_C90_COMPILE_FEATURES} PARENT_SCOPE)
+ set(CMAKE_C99_COMPILE_FEATURES ${CMAKE_C99_COMPILE_FEATURES} PARENT_SCOPE)
+ set(CMAKE_C11_COMPILE_FEATURES ${CMAKE_C11_COMPILE_FEATURES} PARENT_SCOPE)
+
+ message(STATUS "Detecting ${lang} compile features - done")
+
+ elseif(lang STREQUAL CXX AND COMMAND cmake_record_cxx_compile_features)
+ message(STATUS "Detecting ${lang} compile features")
+
+ set(CMAKE_CXX98_COMPILE_FEATURES)
+ set(CMAKE_CXX11_COMPILE_FEATURES)
+ set(CMAKE_CXX14_COMPILE_FEATURES)
+
+ include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
+
+ cmake_record_cxx_compile_features()
+
+ if(NOT _result EQUAL 0)
+ message(STATUS "Detecting ${lang} compile features - failed")
+ return()
+ endif()
+
+ if (CMAKE_CXX11_COMPILE_FEATURES AND CMAKE_CXX14_COMPILE_FEATURES)
+ list(REMOVE_ITEM CMAKE_CXX14_COMPILE_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES})
+ endif()
+ if (CMAKE_CXX98_COMPILE_FEATURES AND CMAKE_CXX11_COMPILE_FEATURES)
+ list(REMOVE_ITEM CMAKE_CXX11_COMPILE_FEATURES ${CMAKE_CXX98_COMPILE_FEATURES})
+ endif()
+
+ if(NOT CMAKE_CXX_COMPILE_FEATURES)
+ set(CMAKE_CXX_COMPILE_FEATURES
+ ${CMAKE_CXX98_COMPILE_FEATURES}
+ ${CMAKE_CXX11_COMPILE_FEATURES}
+ ${CMAKE_CXX14_COMPILE_FEATURES}
+ )
+ endif()
+
+ set(CMAKE_CXX_COMPILE_FEATURES ${CMAKE_CXX_COMPILE_FEATURES} PARENT_SCOPE)
+ set(CMAKE_CXX98_COMPILE_FEATURES ${CMAKE_CXX98_COMPILE_FEATURES} PARENT_SCOPE)
+ set(CMAKE_CXX11_COMPILE_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES} PARENT_SCOPE)
+ set(CMAKE_CXX14_COMPILE_FEATURES ${CMAKE_CXX14_COMPILE_FEATURES} PARENT_SCOPE)
+
+ message(STATUS "Detecting ${lang} compile features - done")
+ endif()
+
+endfunction()
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake
new file mode 100644
index 0000000000..0ab3af62c8
--- /dev/null
+++ b/Modules/CMakeDetermineCompiler.cmake
@@ -0,0 +1,115 @@
+
+#=============================================================================
+# Copyright 2004-2012 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.)
+
+macro(_cmake_find_compiler lang)
+ # Use already-enabled languages for reference.
+ get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
+ list(REMOVE_ITEM _languages "${lang}")
+
+ if(CMAKE_${lang}_COMPILER_INIT)
+ # Search only for the specified compiler.
+ set(CMAKE_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_INIT}")
+ else()
+ # Re-order the compiler list with preferred vendors first.
+ set(_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_LIST}")
+ set(CMAKE_${lang}_COMPILER_LIST "")
+ # Prefer vendors of compilers from reference languages.
+ foreach(l ${_languages})
+ list(APPEND CMAKE_${lang}_COMPILER_LIST
+ ${_${lang}_COMPILER_NAMES_${CMAKE_${l}_COMPILER_ID}})
+ endforeach()
+ # Prefer vendors based on the platform.
+ list(APPEND CMAKE_${lang}_COMPILER_LIST ${CMAKE_${lang}_COMPILER_NAMES})
+ # Append the rest of the list and remove duplicates.
+ list(APPEND CMAKE_${lang}_COMPILER_LIST ${_${lang}_COMPILER_LIST})
+ unset(_${lang}_COMPILER_LIST)
+ list(REMOVE_DUPLICATES CMAKE_${lang}_COMPILER_LIST)
+ if(CMAKE_${lang}_COMPILER_EXCLUDE)
+ list(REMOVE_ITEM CMAKE_${lang}_COMPILER_LIST
+ ${CMAKE_${lang}_COMPILER_EXCLUDE})
+ endif()
+ endif()
+
+ # Look for directories containing compilers of reference languages.
+ set(_${lang}_COMPILER_HINTS)
+ foreach(l ${_languages})
+ if(CMAKE_${l}_COMPILER AND IS_ABSOLUTE "${CMAKE_${l}_COMPILER}")
+ get_filename_component(_hint "${CMAKE_${l}_COMPILER}" PATH)
+ if(IS_DIRECTORY "${_hint}")
+ list(APPEND _${lang}_COMPILER_HINTS "${_hint}")
+ endif()
+ unset(_hint)
+ endif()
+ endforeach()
+
+ # Find the compiler.
+ if(_${lang}_COMPILER_HINTS)
+ # Prefer directories containing compilers of reference languages.
+ list(REMOVE_DUPLICATES _${lang}_COMPILER_HINTS)
+ find_program(CMAKE_${lang}_COMPILER
+ NAMES ${CMAKE_${lang}_COMPILER_LIST}
+ PATHS ${_${lang}_COMPILER_HINTS}
+ NO_DEFAULT_PATH
+ DOC "${lang} compiler")
+ endif()
+ find_program(CMAKE_${lang}_COMPILER NAMES ${CMAKE_${lang}_COMPILER_LIST} DOC "${lang} compiler")
+ if(CMAKE_${lang}_COMPILER_INIT AND NOT CMAKE_${lang}_COMPILER)
+ set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${CMAKE_${lang}_COMPILER_INIT}")
+ endif()
+ unset(_${lang}_COMPILER_HINTS)
+ unset(_languages)
+
+ # Look for a make tool provided by Xcode
+ if(CMAKE_${lang}_COMPILER STREQUAL "CMAKE_${lang}_COMPILER-NOTFOUND" AND CMAKE_HOST_APPLE)
+ foreach(comp ${CMAKE_${lang}_COMPILER_LIST})
+ execute_process(COMMAND xcrun --find ${comp}
+ OUTPUT_VARIABLE _xcrun_out OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE _xcrun_err)
+ if(_xcrun_out)
+ set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${_xcrun_out}")
+ break()
+ endif()
+ endforeach()
+ endif()
+endmacro()
+
+macro(_cmake_find_compiler_path lang)
+ if(CMAKE_${lang}_COMPILER)
+ # we only get here if CMAKE_${lang}_COMPILER was specified using -D or a pre-made CMakeCache.txt
+ # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE
+ # if CMAKE_${lang}_COMPILER is a list of length 2, use the first item as
+ # CMAKE_${lang}_COMPILER and the 2nd one as CMAKE_${lang}_COMPILER_ARG1
+ list(LENGTH CMAKE_${lang}_COMPILER _CMAKE_${lang}_COMPILER_LIST_LENGTH)
+ if("${_CMAKE_${lang}_COMPILER_LIST_LENGTH}" EQUAL 2)
+ list(GET CMAKE_${lang}_COMPILER 1 CMAKE_${lang}_COMPILER_ARG1)
+ list(GET CMAKE_${lang}_COMPILER 0 CMAKE_${lang}_COMPILER)
+ endif()
+ unset(_CMAKE_${lang}_COMPILER_LIST_LENGTH)
+
+ # find the compiler in the PATH if necessary
+ get_filename_component(_CMAKE_USER_${lang}_COMPILER_PATH "${CMAKE_${lang}_COMPILER}" PATH)
+ if(NOT _CMAKE_USER_${lang}_COMPILER_PATH)
+ find_program(CMAKE_${lang}_COMPILER_WITH_PATH NAMES ${CMAKE_${lang}_COMPILER})
+ if(CMAKE_${lang}_COMPILER_WITH_PATH)
+ set(CMAKE_${lang}_COMPILER ${CMAKE_${lang}_COMPILER_WITH_PATH})
+ get_property(_CMAKE_${lang}_COMPILER_CACHED CACHE CMAKE_${lang}_COMPILER PROPERTY TYPE)
+ if(_CMAKE_${lang}_COMPILER_CACHED)
+ set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE STRING "${lang} compiler" FORCE)
+ endif()
+ unset(_CMAKE_${lang}_COMPILER_CACHED)
+ endif()
+ unset(CMAKE_${lang}_COMPILER_WITH_PATH CACHE)
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake
new file mode 100644
index 0000000000..4bc42dd9ee
--- /dev/null
+++ b/Modules/CMakeDetermineCompilerABI.cmake
@@ -0,0 +1,137 @@
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+# Function to compile a source file to identify the compiler ABI.
+# This is used internally by CMake and should not be included by user
+# code.
+
+include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
+
+function(CMAKE_DETERMINE_COMPILER_ABI lang src)
+ if(NOT DEFINED CMAKE_${lang}_ABI_COMPILED)
+ message(STATUS "Detecting ${lang} compiler ABI info")
+
+ # Compile the ABI identification source.
+ set(BIN "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_${lang}.bin")
+ set(CMAKE_FLAGS )
+ if(DEFINED CMAKE_${lang}_VERBOSE_FLAG)
+ set(CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}")
+ endif()
+ if(NOT "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC")
+ # Avoid adding our own platform standard libraries for compilers
+ # from which we might detect implicit link libraries.
+ list(APPEND CMAKE_FLAGS "-DCMAKE_${lang}_STANDARD_LIBRARIES=")
+ endif()
+ try_compile(CMAKE_${lang}_ABI_COMPILED
+ ${CMAKE_BINARY_DIR} ${src}
+ CMAKE_FLAGS ${CMAKE_FLAGS}
+ # Ignore unused flags when we are just determining the ABI.
+ "--no-warn-unused-cli"
+ OUTPUT_VARIABLE OUTPUT
+ COPY_FILE "${BIN}"
+ COPY_FILE_ERROR _copy_error
+ )
+ # Move result from cache to normal variable.
+ set(CMAKE_${lang}_ABI_COMPILED ${CMAKE_${lang}_ABI_COMPILED})
+ unset(CMAKE_${lang}_ABI_COMPILED CACHE)
+ set(CMAKE_${lang}_ABI_COMPILED ${CMAKE_${lang}_ABI_COMPILED} PARENT_SCOPE)
+
+ # Load the resulting information strings.
+ if(CMAKE_${lang}_ABI_COMPILED AND NOT _copy_error)
+ message(STATUS "Detecting ${lang} compiler ABI info - done")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Detecting ${lang} compiler ABI info compiled with the following output:\n${OUTPUT}\n\n")
+ file(STRINGS "${BIN}" ABI_STRINGS LIMIT_COUNT 2 REGEX "INFO:[A-Za-z0-9_]+\\[[^]]*\\]")
+ foreach(info ${ABI_STRINGS})
+ if("${info}" MATCHES "INFO:sizeof_dptr\\[0*([^]]*)\\]")
+ set(ABI_SIZEOF_DPTR "${CMAKE_MATCH_1}")
+ endif()
+ if("${info}" MATCHES "INFO:abi\\[([^]]*)\\]")
+ set(ABI_NAME "${CMAKE_MATCH_1}")
+ endif()
+ endforeach()
+
+ if(ABI_SIZEOF_DPTR)
+ set(CMAKE_${lang}_SIZEOF_DATA_PTR "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
+ elseif(CMAKE_${lang}_SIZEOF_DATA_PTR_DEFAULT)
+ set(CMAKE_${lang}_SIZEOF_DATA_PTR "${CMAKE_${lang}_SIZEOF_DATA_PTR_DEFAULT}" PARENT_SCOPE)
+ endif()
+
+ if(ABI_NAME)
+ set(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
+ endif()
+
+ # Parse implicit linker information for this language, if available.
+ set(implicit_dirs "")
+ set(implicit_libs "")
+ set(implicit_fwks "")
+ if(CMAKE_${lang}_VERBOSE_FLAG)
+ CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs implicit_fwks log
+ "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Parsed ${lang} implicit link information from above output:\n${log}\n\n")
+ endif()
+ # for VS IDE Intel Fortran we have to figure out the
+ # implicit link path for the fortran run time using
+ # a try-compile
+ if("${lang}" MATCHES "Fortran"
+ AND "${CMAKE_GENERATOR}" MATCHES "Visual Studio")
+ set(_desc "Determine Intel Fortran Compiler Implicit Link Path")
+ message(STATUS "${_desc}")
+ # Build a sample project which reports symbols.
+ try_compile(IFORT_LIB_PATH_COMPILED
+ ${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath
+ ${CMAKE_ROOT}/Modules/IntelVSImplicitPath
+ IntelFortranImplicit
+ CMAKE_FLAGS
+ "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}"
+ OUTPUT_VARIABLE _output)
+ file(WRITE
+ "${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.txt"
+ "${_output}")
+ include(${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.cmake OPTIONAL)
+ set(_desc "Determine Intel Fortran Compiler Implicit Link Path -- done")
+ message(STATUS "${_desc}")
+ endif()
+
+ # Implicit link libraries cannot be used explicitly for multiple
+ # OS X architectures, so we skip it.
+ if(DEFINED CMAKE_OSX_ARCHITECTURES)
+ if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ";")
+ set(implicit_libs "")
+ endif()
+ endif()
+
+ set(CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES "${implicit_libs}" PARENT_SCOPE)
+ set(CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES "${implicit_dirs}" PARENT_SCOPE)
+ set(CMAKE_${lang}_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "${implicit_fwks}" PARENT_SCOPE)
+
+ # Detect library architecture directory name.
+ if(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
+ foreach(dir ${implicit_dirs})
+ if("${dir}" MATCHES "/lib/${CMAKE_LIBRARY_ARCHITECTURE_REGEX}$")
+ get_filename_component(arch "${dir}" NAME)
+ set(CMAKE_${lang}_LIBRARY_ARCHITECTURE "${arch}" PARENT_SCOPE)
+ break()
+ endif()
+ endforeach()
+ endif()
+
+ else()
+ message(STATUS "Detecting ${lang} compiler ABI info - failed")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Detecting ${lang} compiler ABI info failed to compile with the following output:\n${OUTPUT}\n${_copy_error}\n\n")
+ endif()
+ endif()
+endfunction()
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
new file mode 100644
index 0000000000..a7b5760ba4
--- /dev/null
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -0,0 +1,581 @@
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Function to compile a source file to identify the compiler. This is
+# used internally by CMake and should not be included by user code.
+# If successful, sets CMAKE_<lang>_COMPILER_ID and CMAKE_<lang>_PLATFORM_ID
+
+function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
+ # Make sure the compiler arguments are clean.
+ string(STRIP "${CMAKE_${lang}_COMPILER_ARG1}" CMAKE_${lang}_COMPILER_ID_ARG1)
+ string(REGEX REPLACE " +" ";" CMAKE_${lang}_COMPILER_ID_ARG1 "${CMAKE_${lang}_COMPILER_ID_ARG1}")
+
+ # Make sure user-specified compiler flags are used.
+ if(CMAKE_${lang}_FLAGS)
+ set(CMAKE_${lang}_COMPILER_ID_FLAGS ${CMAKE_${lang}_FLAGS})
+ else()
+ set(CMAKE_${lang}_COMPILER_ID_FLAGS $ENV{${flagvar}})
+ endif()
+ string(REPLACE " " ";" CMAKE_${lang}_COMPILER_ID_FLAGS_LIST "${CMAKE_${lang}_COMPILER_ID_FLAGS}")
+
+ # Compute the directory in which to run the test.
+ set(CMAKE_${lang}_COMPILER_ID_DIR ${CMAKE_PLATFORM_INFO_DIR}/CompilerId${lang})
+
+ # Try building with no extra flags and then try each set
+ # of helper flags. Stop when the compiler is identified.
+ foreach(flags "" ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS})
+ if(NOT CMAKE_${lang}_COMPILER_ID)
+ CMAKE_DETERMINE_COMPILER_ID_BUILD("${lang}" "${flags}" "${src}")
+ foreach(file ${COMPILER_${lang}_PRODUCED_FILES})
+ CMAKE_DETERMINE_COMPILER_ID_CHECK("${lang}" "${CMAKE_${lang}_COMPILER_ID_DIR}/${file}" "${src}")
+ endforeach()
+ endif()
+ endforeach()
+
+ # If the compiler is still unknown, try to query its vendor.
+ if(CMAKE_${lang}_COMPILER AND NOT CMAKE_${lang}_COMPILER_ID)
+ CMAKE_DETERMINE_COMPILER_ID_VENDOR(${lang})
+ endif()
+
+ if (COMPILER_QNXNTO AND CMAKE_${lang}_COMPILER_ID STREQUAL GNU)
+ execute_process(
+ COMMAND "${CMAKE_${lang}_COMPILER}"
+ -V
+ OUTPUT_VARIABLE output ERROR_VARIABLE output
+ RESULT_VARIABLE result
+ TIMEOUT 10
+ )
+ if (output MATCHES "targets available")
+ set(CMAKE_${lang}_COMPILER_ID QCC)
+ # http://community.qnx.com/sf/discussion/do/listPosts/projects.community/discussion.qnx_momentics_community_support.topc3555?_pagenum=2
+ # The qcc driver does not itself have a version.
+ endif()
+ endif()
+
+ # if the format is unknown after all files have been checked, put "Unknown" in the cache
+ if(NOT CMAKE_EXECUTABLE_FORMAT)
+ set(CMAKE_EXECUTABLE_FORMAT "Unknown" CACHE INTERNAL "Executable file format")
+ endif()
+
+ # Display the final identification result.
+ if(CMAKE_${lang}_COMPILER_ID)
+ if(CMAKE_${lang}_COMPILER_VERSION)
+ set(_version " ${CMAKE_${lang}_COMPILER_VERSION}")
+ else()
+ set(_version "")
+ endif()
+ message(STATUS "The ${lang} compiler identification is "
+ "${CMAKE_${lang}_COMPILER_ID}${_version}")
+ else()
+ message(STATUS "The ${lang} compiler identification is unknown")
+ endif()
+
+ # Check if compiler id detection gave us the compiler tool.
+ if(CMAKE_${lang}_COMPILER_ID_TOOL)
+ set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_ID_TOOL}" PARENT_SCOPE)
+ elseif(NOT CMAKE_${lang}_COMPILER)
+ set(CMAKE_${lang}_COMPILER "CMAKE_${lang}_COMPILER-NOTFOUND" PARENT_SCOPE)
+ endif()
+
+ set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE)
+ set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE)
+ 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}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
+ set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
+endfunction()
+
+include(CMakeCompilerIdDetection)
+
+#-----------------------------------------------------------------------------
+# Function to write the compiler id source file.
+function(CMAKE_DETERMINE_COMPILER_ID_WRITE lang src)
+ find_file(src_in ${src}.in PATHS ${CMAKE_ROOT}/Modules ${CMAKE_MODULE_PATH} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+ file(READ ${src_in} ID_CONTENT_IN)
+
+ compiler_id_detection(CMAKE_${lang}_COMPILER_ID_CONTENT ${lang}
+ ID_STRING
+ VERSION_STRINGS
+ PLATFORM_DEFAULT_COMPILER
+ )
+
+ unset(src_in CACHE)
+ string(CONFIGURE "${ID_CONTENT_IN}" ID_CONTENT_OUT @ONLY)
+ file(WRITE ${CMAKE_${lang}_COMPILER_ID_DIR}/${src} "${ID_CONTENT_OUT}")
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to build the compiler id source file and look for output
+# files.
+function(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags src)
+ # Create a clean working directory.
+ file(REMOVE_RECURSE ${CMAKE_${lang}_COMPILER_ID_DIR})
+ file(MAKE_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR})
+ CMAKE_DETERMINE_COMPILER_ID_WRITE("${lang}" "${src}")
+
+ # Construct a description of this test case.
+ set(COMPILER_DESCRIPTION
+ "Compiler: ${CMAKE_${lang}_COMPILER} ${CMAKE_${lang}_COMPILER_ID_ARG1}
+Build flags: ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}
+Id flags: ${testflags}
+")
+
+ # Compile the compiler identification source.
+ if(CMAKE_GENERATOR STREQUAL "Visual Studio 6" AND
+ lang STREQUAL "Fortran")
+ set(CMAKE_${lang}_COMPILER_ID_RESULT 1)
+ set(CMAKE_${lang}_COMPILER_ID_OUTPUT "No Intel Fortran in VS 6")
+ elseif("${CMAKE_GENERATOR}" MATCHES "Visual Studio ([0-9]+)")
+ set(vs_version ${CMAKE_MATCH_1})
+ set(id_platform ${CMAKE_VS_PLATFORM_NAME})
+ set(id_lang "${lang}")
+ set(id_cl cl.exe)
+ if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
+ set(v NsightTegra)
+ set(ext vcxproj)
+ if(lang STREQUAL CXX)
+ set(id_gcc g++)
+ set(id_clang clang++)
+ else()
+ set(id_gcc gcc)
+ set(id_clang clang)
+ endif()
+ elseif(lang STREQUAL Fortran)
+ set(v Intel)
+ set(ext vfproj)
+ set(id_cl ifort.exe)
+ elseif(NOT "${vs_version}" VERSION_LESS 10)
+ set(v 10)
+ set(ext vcxproj)
+ elseif(NOT "${vs_version}" VERSION_LESS 7)
+ set(id_version ${vs_version}.00)
+ set(v 7)
+ set(ext vcproj)
+ else()
+ 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>")
+ else()
+ set(id_toolset "<PlatformToolset>${CMAKE_VS_PLATFORM_TOOLSET}</PlatformToolset>")
+ if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "Intel")
+ set(id_cl icl.exe)
+ endif()
+ endif()
+ else()
+ set(id_toolset "")
+ endif()
+ if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone")
+ set(id_system "<ApplicationType>Windows Phone</ApplicationType>")
+ elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
+ set(id_system "<ApplicationType>Windows Store</ApplicationType>")
+ else()
+ set(id_system "")
+ endif()
+ if(id_system AND CMAKE_SYSTEM_VERSION)
+ set(id_system_version "<ApplicationTypeRevision>${CMAKE_SYSTEM_VERSION}</ApplicationTypeRevision>")
+ else()
+ set(id_system_version "")
+ endif()
+ if(id_platform STREQUAL ARM)
+ set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>")
+ else()
+ set(id_WindowsSDKDesktopARMSupport "")
+ endif()
+ if(CMAKE_VS_WINCE_VERSION)
+ set(id_entrypoint "mainACRTStartup")
+ if("${vs_version}" VERSION_LESS 9)
+ set(id_subsystem 9)
+ else()
+ set(id_subsystem 8)
+ endif()
+ else()
+ set(id_subsystem 1)
+ endif()
+ set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR})
+ get_filename_component(id_src "${src}" NAME)
+ configure_file(${CMAKE_ROOT}/Modules/CompilerId/VS-${v}.${ext}.in
+ ${id_dir}/CompilerId${lang}.${ext} @ONLY)
+ if(CMAKE_VS_MSBUILD_COMMAND AND NOT lang STREQUAL "Fortran")
+ set(command "${CMAKE_VS_MSBUILD_COMMAND}" "CompilerId${lang}.${ext}"
+ "/p:Configuration=Debug" "/p:Platform=${id_platform}" "/p:VisualStudioVersion=${vs_version}.0"
+ )
+ elseif(CMAKE_VS_DEVENV_COMMAND)
+ set(command "${CMAKE_VS_DEVENV_COMMAND}" "CompilerId${lang}.${ext}" "/build" "Debug")
+ elseif(CMAKE_VS_MSDEV_COMMAND)
+ set(command "${CMAKE_VS_MSDEV_COMMAND}" "CompilerId${lang}.${ext}" "/make")
+ else()
+ set(command "")
+ endif()
+ if(command)
+ execute_process(
+ COMMAND ${command}
+ WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}
+ OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
+ ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
+ RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT
+ )
+ else()
+ set(CMAKE_${lang}_COMPILER_ID_RESULT 1)
+ set(CMAKE_${lang}_COMPILER_ID_OUTPUT "VS environment not known to support ${lang}")
+ endif()
+ # Match the compiler location line printed out.
+ if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "CMAKE_${lang}_COMPILER=([^%\r\n]+)[\r\n]")
+ # Strip VS diagnostic output from the end of the line.
+ string(REGEX REPLACE " \\(TaskId:[0-9]*\\)$" "" _comp "${CMAKE_MATCH_1}")
+ if(EXISTS "${_comp}")
+ file(TO_CMAKE_PATH "${_comp}" _comp)
+ set(CMAKE_${lang}_COMPILER_ID_TOOL "${_comp}" PARENT_SCOPE)
+ endif()
+ endif()
+ elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
+ set(id_lang "${lang}")
+ set(id_type ${CMAKE_${lang}_COMPILER_XCODE_TYPE})
+ set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR})
+ get_filename_component(id_src "${src}" NAME)
+ if(CMAKE_XCODE_PLATFORM_TOOLSET)
+ set(id_toolset "GCC_VERSION = ${CMAKE_XCODE_PLATFORM_TOOLSET};")
+ else()
+ set(id_toolset "")
+ endif()
+ if(CMAKE_OSX_DEPLOYMENT_TARGET)
+ set(id_deployment_target
+ "MACOSX_DEPLOYMENT_TARGET = \"${CMAKE_OSX_DEPLOYMENT_TARGET}\";")
+ else()
+ set(id_deployment_target "")
+ endif()
+ if(CMAKE_OSX_SYSROOT)
+ set(id_sdkroot "SDKROOT = \"${CMAKE_OSX_SYSROOT}\";")
+ else()
+ set(id_sdkroot "")
+ endif()
+ if(NOT ${XCODE_VERSION} VERSION_LESS 3)
+ set(v 3)
+ set(ext xcodeproj)
+ elseif(NOT ${XCODE_VERSION} VERSION_LESS 2)
+ set(v 2)
+ set(ext xcodeproj)
+ else()
+ set(v 1)
+ set(ext xcode)
+ endif()
+ configure_file(${CMAKE_ROOT}/Modules/CompilerId/Xcode-${v}.pbxproj.in
+ ${id_dir}/CompilerId${lang}.${ext}/project.pbxproj @ONLY)
+ unset(_ENV_MACOSX_DEPLOYMENT_TARGET)
+ if(DEFINED ENV{MACOSX_DEPLOYMENT_TARGET})
+ set(_ENV_MACOSX_DEPLOYMENT_TARGET "$ENV{MACOSX_DEPLOYMENT_TARGET}")
+ set(ENV{MACOSX_DEPLOYMENT_TARGET} "")
+ endif()
+ execute_process(COMMAND xcodebuild
+ WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}
+ OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
+ ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
+ RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT
+ )
+ if(DEFINED _ENV_MACOSX_DEPLOYMENT_TARGET)
+ set(ENV{MACOSX_DEPLOYMENT_TARGET} "${_ENV_MACOSX_DEPLOYMENT_TARGET}")
+ endif()
+
+ # Match the link line from xcodebuild output of the form
+ # Ld ...
+ # ...
+ # /path/to/cc ...CompilerId${lang}/...
+ # to extract the compiler front-end for the language.
+ if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "\nLd[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]*-o[^\r\n]*CompilerId${lang}/(\\./)?CompilerId${lang}[ \t\n\\\"]")
+ set(_comp "${CMAKE_MATCH_2}")
+ if(EXISTS "${_comp}")
+ set(CMAKE_${lang}_COMPILER_ID_TOOL "${_comp}" PARENT_SCOPE)
+ endif()
+ endif()
+ else()
+ if(COMMAND EXECUTE_PROCESS)
+ execute_process(
+ COMMAND "${CMAKE_${lang}_COMPILER}"
+ ${CMAKE_${lang}_COMPILER_ID_ARG1}
+ ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}
+ ${testflags}
+ "${src}"
+ WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}
+ OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
+ ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
+ RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT
+ )
+ else()
+ exec_program(
+ "${CMAKE_${lang}_COMPILER}" ${CMAKE_${lang}_COMPILER_ID_DIR}
+ ARGS ${CMAKE_${lang}_COMPILER_ID_ARG1}
+ ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}
+ ${testflags}
+ \"${src}\"
+ OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
+ RETURN_VALUE CMAKE_${lang}_COMPILER_ID_RESULT
+ )
+ endif()
+ endif()
+
+ # Check the result of compilation.
+ if(CMAKE_${lang}_COMPILER_ID_RESULT
+ # Intel Fortran warns and ignores preprocessor lines without /fpp
+ OR CMAKE_${lang}_COMPILER_ID_OUTPUT MATCHES "Bad # preprocessor line"
+ )
+ # Compilation failed.
+ set(MSG
+ "Compiling the ${lang} compiler identification source file \"${src}\" failed.
+${COMPILER_DESCRIPTION}
+The output was:
+${CMAKE_${lang}_COMPILER_ID_RESULT}
+${CMAKE_${lang}_COMPILER_ID_OUTPUT}
+
+")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "${MSG}")
+ #if(NOT CMAKE_${lang}_COMPILER_ID_ALLOW_FAIL)
+ # message(FATAL_ERROR "${MSG}")
+ #endif()
+
+ # No output files should be inspected.
+ set(COMPILER_${lang}_PRODUCED_FILES)
+ else()
+ # Compilation succeeded.
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Compiling the ${lang} compiler identification source file \"${src}\" succeeded.
+${COMPILER_DESCRIPTION}
+The output was:
+${CMAKE_${lang}_COMPILER_ID_RESULT}
+${CMAKE_${lang}_COMPILER_ID_OUTPUT}
+
+")
+
+ # Find the executable produced by the compiler, try all files in the
+ # binary dir.
+ file(GLOB files
+ RELATIVE ${CMAKE_${lang}_COMPILER_ID_DIR}
+ ${CMAKE_${lang}_COMPILER_ID_DIR}/*)
+ list(REMOVE_ITEM files "${src}")
+ set(COMPILER_${lang}_PRODUCED_FILES "")
+ foreach(file ${files})
+ if(NOT IS_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}/${file})
+ list(APPEND COMPILER_${lang}_PRODUCED_FILES ${file})
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Compilation of the ${lang} compiler identification source \""
+ "${src}\" produced \"${file}\"\n\n")
+ endif()
+ endforeach()
+
+ if(NOT COMPILER_${lang}_PRODUCED_FILES)
+ # No executable was found.
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Compilation of the ${lang} compiler identification source \""
+ "${src}\" did not produce an executable in \""
+ "${CMAKE_${lang}_COMPILER_ID_DIR}\".\n\n")
+ endif()
+ endif()
+
+ # Return the files produced by the compilation.
+ set(COMPILER_${lang}_PRODUCED_FILES "${COMPILER_${lang}_PRODUCED_FILES}" PARENT_SCOPE)
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to extract the compiler id from an executable.
+function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
+ # Look for a compiler id if not yet known.
+ if(NOT CMAKE_${lang}_COMPILER_ID)
+ # Read the compiler identification string from the executable file.
+ set(COMPILER_ID)
+ set(COMPILER_VERSION)
+ set(PLATFORM_ID)
+ set(ARCHITECTURE_ID)
+ set(SIMULATE_ID)
+ set(SIMULATE_VERSION)
+ file(STRINGS ${file}
+ CMAKE_${lang}_COMPILER_ID_STRINGS LIMIT_COUNT 6 REGEX "INFO:[A-Za-z0-9_]+\\[[^]]*\\]")
+ set(COMPILER_ID_TWICE)
+ foreach(info ${CMAKE_${lang}_COMPILER_ID_STRINGS})
+ if("${info}" MATCHES "INFO:compiler\\[([^]\"]*)\\]")
+ if(COMPILER_ID)
+ set(COMPILER_ID_TWICE 1)
+ endif()
+ set(COMPILER_ID "${CMAKE_MATCH_1}")
+ endif()
+ if("${info}" MATCHES "INFO:platform\\[([^]\"]*)\\]")
+ set(PLATFORM_ID "${CMAKE_MATCH_1}")
+ endif()
+ if("${info}" MATCHES "INFO:arch\\[([^]\"]*)\\]")
+ set(ARCHITECTURE_ID "${CMAKE_MATCH_1}")
+ endif()
+ if("${info}" MATCHES "INFO:compiler_version\\[([^]\"]*)\\]")
+ string(REGEX REPLACE "^0+([0-9])" "\\1" COMPILER_VERSION "${CMAKE_MATCH_1}")
+ string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION "${COMPILER_VERSION}")
+ endif()
+ if("${info}" MATCHES "INFO:simulate\\[([^]\"]*)\\]")
+ set(SIMULATE_ID "${CMAKE_MATCH_1}")
+ endif()
+ if("${info}" MATCHES "INFO:simulate_version\\[([^]\"]*)\\]")
+ string(REGEX REPLACE "^0+([0-9])" "\\1" SIMULATE_VERSION "${CMAKE_MATCH_1}")
+ string(REGEX REPLACE "\\.0+([0-9])" ".\\1" SIMULATE_VERSION "${SIMULATE_VERSION}")
+ endif()
+ if("${info}" MATCHES "INFO:qnxnto")
+ set(COMPILER_QNXNTO 1)
+ endif()
+ endforeach()
+
+ # Detect the exact architecture from the PE header.
+ if(WIN32)
+ # The offset to the PE signature is stored at 0x3c.
+ file(READ ${file} peoffsethex LIMIT 1 OFFSET 60 HEX)
+ string(SUBSTRING "${peoffsethex}" 0 1 peoffsethex1)
+ string(SUBSTRING "${peoffsethex}" 1 1 peoffsethex2)
+ set(peoffsetexpression "${peoffsethex1} * 16 + ${peoffsethex2}")
+ string(REPLACE "a" "10" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "b" "11" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "c" "12" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "d" "13" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "e" "14" peoffsetexpression "${peoffsetexpression}")
+ string(REPLACE "f" "15" peoffsetexpression "${peoffsetexpression}")
+ math(EXPR peoffset "${peoffsetexpression}")
+
+ file(READ ${file} peheader LIMIT 6 OFFSET ${peoffset} HEX)
+ if(peheader STREQUAL "50450000a201")
+ set(ARCHITECTURE_ID "SH3")
+ elseif(peheader STREQUAL "50450000a301")
+ set(ARCHITECTURE_ID "SH3DSP")
+ elseif(peheader STREQUAL "50450000a601")
+ set(ARCHITECTURE_ID "SH4")
+ elseif(peheader STREQUAL "50450000a801")
+ set(ARCHITECTURE_ID "SH5")
+ elseif(peheader STREQUAL "50450000c201")
+ set(ARCHITECTURE_ID "THUMB")
+ endif()
+ endif()
+
+ # Check if a valid compiler and platform were found.
+ if(COMPILER_ID AND NOT COMPILER_ID_TWICE)
+ set(CMAKE_${lang}_COMPILER_ID "${COMPILER_ID}")
+ set(CMAKE_${lang}_PLATFORM_ID "${PLATFORM_ID}")
+ set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
+ set(CMAKE_${lang}_COMPILER_VERSION "${COMPILER_VERSION}")
+ set(CMAKE_${lang}_SIMULATE_ID "${SIMULATE_ID}")
+ set(CMAKE_${lang}_SIMULATE_VERSION "${SIMULATE_VERSION}")
+ endif()
+
+ # Check the compiler identification string.
+ if(CMAKE_${lang}_COMPILER_ID)
+ # The compiler identification was found.
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "The ${lang} compiler identification is ${CMAKE_${lang}_COMPILER_ID}, found in \""
+ "${file}\"\n\n")
+ else()
+ # The compiler identification could not be found.
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "The ${lang} compiler identification could not be found in \""
+ "${file}\"\n\n")
+ endif()
+ endif()
+
+ # try to figure out the executable format: ELF, COFF, Mach-O
+ if(NOT CMAKE_EXECUTABLE_FORMAT)
+ file(READ ${file} CMAKE_EXECUTABLE_MAGIC LIMIT 4 HEX)
+
+ # ELF files start with 0x7f"ELF"
+ if("${CMAKE_EXECUTABLE_MAGIC}" STREQUAL "7f454c46")
+ set(CMAKE_EXECUTABLE_FORMAT "ELF" CACHE INTERNAL "Executable file format")
+ endif()
+
+# # COFF (.exe) files start with "MZ"
+# if("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "4d5a....")
+# set(CMAKE_EXECUTABLE_FORMAT "COFF" CACHE STRING "Executable file format")
+# endif()
+#
+# # Mach-O files start with CAFEBABE or FEEDFACE, according to http://radio.weblogs.com/0100490/2003/01/28.html
+# if("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "cafebabe")
+# set(CMAKE_EXECUTABLE_FORMAT "MACHO" CACHE STRING "Executable file format")
+# endif()
+# if("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "feedface")
+# set(CMAKE_EXECUTABLE_FORMAT "MACHO" CACHE STRING "Executable file format")
+# endif()
+
+ endif()
+ if(NOT DEFINED CMAKE_EXECUTABLE_FORMAT)
+ set(CMAKE_EXECUTABLE_FORMAT)
+ endif()
+ # Return the information extracted.
+ set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE)
+ set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE)
+ 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}_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)
+ set(COMPILER_QNXNTO "${COMPILER_QNXNTO}" PARENT_SCOPE)
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to query the compiler vendor.
+# This uses a table with entries of the form
+# list(APPEND CMAKE_${lang}_COMPILER_ID_VENDORS ${vendor})
+# set(CMAKE_${lang}_COMPILER_ID_VENDOR_FLAGS_${vendor} -some-vendor-flag)
+# set(CMAKE_${lang}_COMPILER_ID_VENDOR_REGEX_${vendor} "Some Vendor Output")
+# We try running the compiler with the flag for each vendor and
+# matching its regular expression in the output.
+function(CMAKE_DETERMINE_COMPILER_ID_VENDOR lang)
+
+ if(NOT CMAKE_${lang}_COMPILER_ID_DIR)
+ # We get here when this function is called not from within CMAKE_DETERMINE_COMPILER_ID()
+ # This is done e.g. for detecting the compiler ID for assemblers.
+ # Compute the directory in which to run the test and Create a clean working directory.
+ set(CMAKE_${lang}_COMPILER_ID_DIR ${CMAKE_PLATFORM_INFO_DIR}/CompilerId${lang})
+ file(REMOVE_RECURSE ${CMAKE_${lang}_COMPILER_ID_DIR})
+ file(MAKE_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR})
+ endif()
+
+
+ foreach(vendor ${CMAKE_${lang}_COMPILER_ID_VENDORS})
+ set(flags ${CMAKE_${lang}_COMPILER_ID_VENDOR_FLAGS_${vendor}})
+ set(regex ${CMAKE_${lang}_COMPILER_ID_VENDOR_REGEX_${vendor}})
+ execute_process(
+ COMMAND "${CMAKE_${lang}_COMPILER}"
+ ${CMAKE_${lang}_COMPILER_ID_ARG1}
+ ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}
+ ${flags}
+ WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}
+ OUTPUT_VARIABLE output ERROR_VARIABLE output
+ RESULT_VARIABLE result
+ TIMEOUT 10
+ )
+
+ if("${output}" MATCHES "${regex}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Checking whether the ${lang} compiler is ${vendor} using \"${flags}\" "
+ "matched \"${regex}\":\n${output}")
+ set(CMAKE_${lang}_COMPILER_ID "${vendor}" PARENT_SCOPE)
+ break()
+ else()
+ if("${result}" MATCHES "timeout")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Checking whether the ${lang} compiler is ${vendor} using \"${flags}\" "
+ "terminated after 10 s due to timeout.")
+ else()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Checking whether the ${lang} compiler is ${vendor} using \"${flags}\" "
+ "did not match \"${regex}\":\n${output}")
+ endif()
+ endif()
+ endforeach()
+endfunction()
diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake
new file mode 100644
index 0000000000..96df6a2f3e
--- /dev/null
+++ b/Modules/CMakeDetermineFortranCompiler.cmake
@@ -0,0 +1,204 @@
+
+#=============================================================================
+# Copyright 2004-2009 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.)
+
+# determine the compiler to use for Fortran programs
+# NOTE, a generator may set CMAKE_Fortran_COMPILER before
+# loading this file to force a compiler.
+# use environment variable FC first if defined by user, next use
+# the cmake variable CMAKE_GENERATOR_FC which can be defined by a generator
+# as a default compiler
+
+include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+include(Platform/${CMAKE_SYSTEM_NAME}-Fortran OPTIONAL)
+if(NOT CMAKE_Fortran_COMPILER_NAMES)
+ set(CMAKE_Fortran_COMPILER_NAMES f95)
+endif()
+
+if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
+elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
+ set(CMAKE_Fortran_COMPILER_XCODE_TYPE sourcecode.fortran.f90)
+ _cmake_find_compiler_path(Fortran)
+else()
+ if(NOT CMAKE_Fortran_COMPILER)
+ # prefer the environment variable CC
+ if(NOT $ENV{FC} STREQUAL "")
+ get_filename_component(CMAKE_Fortran_COMPILER_INIT $ENV{FC} PROGRAM PROGRAM_ARGS CMAKE_Fortran_FLAGS_ENV_INIT)
+ if(CMAKE_Fortran_FLAGS_ENV_INIT)
+ set(CMAKE_Fortran_COMPILER_ARG1 "${CMAKE_Fortran_FLAGS_ENV_INIT}" CACHE STRING "First argument to Fortran compiler")
+ endif()
+ if(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
+ else()
+ message(FATAL_ERROR "Could not find compiler set in environment variable FC:\n$ENV{FC}.")
+ endif()
+ endif()
+
+ # next try prefer the compiler specified by the generator
+ if(CMAKE_GENERATOR_FC)
+ if(NOT CMAKE_Fortran_COMPILER_INIT)
+ set(CMAKE_Fortran_COMPILER_INIT ${CMAKE_GENERATOR_FC})
+ endif()
+ endif()
+
+ # finally list compilers to try
+ if(NOT CMAKE_Fortran_COMPILER_INIT)
+ # Known compilers:
+ # f77/f90/f95: generic compiler names
+ # g77: GNU Fortran 77 compiler
+ # gfortran: putative GNU Fortran 95+ compiler (in progress)
+ # fort77: native F77 compiler under HP-UX (and some older Crays)
+ # frt: Fujitsu F77 compiler
+ # pathf90/pathf95/pathf2003: PathScale Fortran compiler
+ # pgf77/pgf90/pgf95/pgfortran: Portland Group F77/F90/F95 compilers
+ # xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
+ # lf95: Lahey-Fujitsu F95 compiler
+ # fl32: Microsoft Fortran 77 "PowerStation" compiler
+ # af77: Apogee F77 compiler for Intergraph hardware running CLIX
+ # epcf90: "Edinburgh Portable Compiler" F90
+ # fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
+ # ifc: Intel Fortran 95 compiler for Linux/x86
+ # efc: Intel Fortran 95 compiler for IA64
+ #
+ # The order is 95 or newer compilers first, then 90,
+ # 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
+ 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
+ )
+
+ # Vendor-specific compiler names.
+ set(_Fortran_COMPILER_NAMES_GNU gfortran gfortran-4 g95 g77)
+ set(_Fortran_COMPILER_NAMES_Intel ifort ifc efc)
+ set(_Fortran_COMPILER_NAMES_Absoft af95 af90 af77)
+ set(_Fortran_COMPILER_NAMES_PGI pgf95 pgfortran pgf90 pgf77)
+ set(_Fortran_COMPILER_NAMES_PathScale pathf2003 pathf95 pathf90)
+ set(_Fortran_COMPILER_NAMES_XL xlf)
+ set(_Fortran_COMPILER_NAMES_VisualAge xlf95 xlf90 xlf)
+ endif()
+
+ _cmake_find_compiler(Fortran)
+
+ else()
+ _cmake_find_compiler_path(Fortran)
+ endif()
+ mark_as_advanced(CMAKE_Fortran_COMPILER)
+
+ # Each entry in this list is a set of extra flags to try
+ # adding to the compile line to see if it helps produce
+ # a valid identification executable.
+ set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS
+ # Try compiling to an object file only.
+ "-c"
+
+ # Intel on windows does not preprocess by default.
+ "-fpp"
+ )
+endif()
+
+# Build a small source file to identify the compiler.
+if(NOT CMAKE_Fortran_COMPILER_ID_RUN)
+ set(CMAKE_Fortran_COMPILER_ID_RUN 1)
+
+ # Table of per-vendor compiler id flags with expected output.
+ list(APPEND CMAKE_Fortran_COMPILER_ID_VENDORS Compaq)
+ set(CMAKE_Fortran_COMPILER_ID_VENDOR_FLAGS_Compaq "-what")
+ set(CMAKE_Fortran_COMPILER_ID_VENDOR_REGEX_Compaq "Compaq Visual Fortran")
+ list(APPEND CMAKE_Fortran_COMPILER_ID_VENDORS NAG) # Numerical Algorithms Group
+ set(CMAKE_Fortran_COMPILER_ID_VENDOR_FLAGS_NAG "-V")
+ set(CMAKE_Fortran_COMPILER_ID_VENDOR_REGEX_NAG "NAG Fortran Compiler")
+
+ # Try to identify the compiler.
+ set(CMAKE_Fortran_COMPILER_ID)
+ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
+ CMAKE_DETERMINE_COMPILER_ID(Fortran FFLAGS CMakeFortranCompilerId.F)
+
+ # Fall back to old is-GNU test.
+ if(NOT CMAKE_Fortran_COMPILER_ID)
+ exec_program(${CMAKE_Fortran_COMPILER}
+ ARGS ${CMAKE_Fortran_COMPILER_ID_FLAGS_LIST} -E "\"${CMAKE_ROOT}/Modules/CMakeTestGNU.c\""
+ OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT RETURN_VALUE CMAKE_COMPILER_RETURN)
+ if(NOT CMAKE_COMPILER_RETURN)
+ if("${CMAKE_COMPILER_OUTPUT}" MATCHES "THIS_IS_GNU")
+ set(CMAKE_Fortran_COMPILER_ID "GNU")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the Fortran compiler is GNU succeeded with "
+ "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
+ else()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the Fortran compiler is GNU failed with "
+ "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
+ endif()
+ if(NOT CMAKE_Fortran_PLATFORM_ID)
+ if("${CMAKE_COMPILER_OUTPUT}" MATCHES "THIS_IS_MINGW")
+ set(CMAKE_Fortran_PLATFORM_ID "MinGW")
+ endif()
+ if("${CMAKE_COMPILER_OUTPUT}" MATCHES "THIS_IS_CYGWIN")
+ set(CMAKE_Fortran_PLATFORM_ID "Cygwin")
+ endif()
+ endif()
+ endif()
+ endif()
+
+ # Set old compiler and platform id variables.
+ if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
+ set(CMAKE_COMPILER_IS_GNUG77 1)
+ endif()
+ if("${CMAKE_Fortran_PLATFORM_ID}" MATCHES "MinGW")
+ set(CMAKE_COMPILER_IS_MINGW 1)
+ elseif("${CMAKE_Fortran_PLATFORM_ID}" MATCHES "Cygwin")
+ set(CMAKE_COMPILER_IS_CYGWIN 1)
+ endif()
+endif()
+
+if (NOT _CMAKE_TOOLCHAIN_LOCATION)
+ get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Fortran_COMPILER}" PATH)
+endif ()
+
+# if we have a fortran cross compiler, they have usually some prefix, like
+# e.g. powerpc-linux-gfortran, arm-elf-gfortran or i586-mingw32msvc-gfortran , optionally
+# with a 3-component version number at the end (e.g. arm-eabi-gcc-4.5.2).
+# The other tools of the toolchain usually have the same prefix
+# NAME_WE cannot be used since then this test will fail for names like
+# "arm-unknown-nto-qnx6.3.0-gcc.exe", where BASENAME would be
+# "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
+if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX)
+
+ if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
+ get_filename_component(COMPILER_BASENAME "${CMAKE_Fortran_COMPILER}" NAME)
+ if (COMPILER_BASENAME MATCHES "^(.+-)g?fortran(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ endif ()
+
+ # if "llvm-" is part of the prefix, remove it, since llvm doesn't have its own binutils
+ # but uses the regular ar, objcopy, etc. (instead of llvm-objcopy etc.)
+ if ("${_CMAKE_TOOLCHAIN_PREFIX}" MATCHES "(.+-)?llvm-$")
+ set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ endif ()
+ endif()
+
+endif ()
+
+include(CMakeFindBinUtils)
+
+if(MSVC_Fortran_ARCHITECTURE_ID)
+ set(SET_MSVC_Fortran_ARCHITECTURE_ID
+ "set(MSVC_Fortran_ARCHITECTURE_ID ${MSVC_Fortran_ARCHITECTURE_ID})")
+endif()
+# configure variables set in this file for fast reload later on
+configure_file(${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake
+ @ONLY
+ )
+set(CMAKE_Fortran_COMPILER_ENV_VAR "FC")
diff --git a/Modules/CMakeDetermineJavaCompiler.cmake b/Modules/CMakeDetermineJavaCompiler.cmake
new file mode 100644
index 0000000000..f6578016a1
--- /dev/null
+++ b/Modules/CMakeDetermineJavaCompiler.cmake
@@ -0,0 +1,104 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+# determine the compiler to use for Java programs
+# NOTE, a generator may set CMAKE_Java_COMPILER before
+# loading this file to force a compiler.
+
+if(NOT CMAKE_Java_COMPILER)
+ # prefer the environment variable CC
+ if(NOT $ENV{JAVA_COMPILER} STREQUAL "")
+ get_filename_component(CMAKE_Java_COMPILER_INIT $ENV{JAVA_COMPILER} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT)
+ if(CMAKE_Java_FLAGS_ENV_INIT)
+ set(CMAKE_Java_COMPILER_ARG1 "${CMAKE_Java_FLAGS_ENV_INIT}" CACHE STRING "First argument to Java compiler")
+ endif()
+ if(NOT EXISTS ${CMAKE_Java_COMPILER_INIT})
+ message(SEND_ERROR "Could not find compiler set in environment variable JAVA_COMPILER:\n$ENV{JAVA_COMPILER}.")
+ endif()
+ endif()
+
+ if(NOT $ENV{JAVA_RUNTIME} STREQUAL "")
+ get_filename_component(CMAKE_Java_RUNTIME_INIT $ENV{JAVA_RUNTIME} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT)
+ if(NOT EXISTS ${CMAKE_Java_RUNTIME_INIT})
+ message(SEND_ERROR "Could not find compiler set in environment variable JAVA_RUNTIME:\n$ENV{JAVA_RUNTIME}.")
+ endif()
+ endif()
+
+ if(NOT $ENV{JAVA_ARCHIVE} STREQUAL "")
+ get_filename_component(CMAKE_Java_ARCHIVE_INIT $ENV{JAVA_ARCHIVE} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT)
+ if(NOT EXISTS ${CMAKE_Java_ARCHIVE_INIT})
+ message(SEND_ERROR "Could not find compiler set in environment variable JAVA_ARCHIVE:\n$ENV{JAVA_ARCHIVE}.")
+ endif()
+ endif()
+
+ set(Java_BIN_PATH
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\2.0;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.9;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.8;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.7;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.6;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.5;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/bin"
+ $ENV{JAVA_HOME}/bin
+ /usr/bin
+ /usr/lib/java/bin
+ /usr/share/java/bin
+ /usr/local/bin
+ /usr/local/java/bin
+ /usr/local/java/share/bin
+ /usr/java/j2sdk1.4.2_04
+ /usr/lib/j2sdk1.4-sun/bin
+ /usr/java/j2sdk1.4.2_09/bin
+ /usr/lib/j2sdk1.5-sun/bin
+ /opt/sun-jdk-1.5.0.04/bin
+ /usr/local/jdk-1.7.0/bin
+ /usr/local/jdk-1.6.0/bin
+ )
+ # if no compiler has been specified yet, then look for one
+ if(CMAKE_Java_COMPILER_INIT)
+ set(CMAKE_Java_COMPILER ${CMAKE_Java_COMPILER_INIT} CACHE PATH "Java Compiler")
+ else()
+ find_program(CMAKE_Java_COMPILER
+ NAMES javac
+ PATHS ${Java_BIN_PATH}
+ )
+ endif()
+
+ # if no runtime has been specified yet, then look for one
+ if(CMAKE_Java_RUNTIME_INIT)
+ set(CMAKE_Java_RUNTIME ${CMAKE_Java_RUNTIME_INIT} CACHE PATH "Java Compiler")
+ else()
+ find_program(CMAKE_Java_RUNTIME
+ NAMES java
+ PATHS ${Java_BIN_PATH}
+ )
+ endif()
+
+ # if no archive has been specified yet, then look for one
+ if(CMAKE_Java_ARCHIVE_INIT)
+ set(CMAKE_Java_ARCHIVE ${CMAKE_Java_ARCHIVE_INIT} CACHE PATH "Java Compiler")
+ else()
+ find_program(CMAKE_Java_ARCHIVE
+ NAMES jar
+ PATHS ${Java_BIN_PATH}
+ )
+ endif()
+endif()
+mark_as_advanced(CMAKE_Java_COMPILER)
+
+# configure variables set in this file for fast reload later on
+configure_file(${CMAKE_ROOT}/Modules/CMakeJavaCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeJavaCompiler.cmake @ONLY)
+set(CMAKE_Java_COMPILER_ENV_VAR "JAVA_COMPILER")
diff --git a/Modules/CMakeDetermineRCCompiler.cmake b/Modules/CMakeDetermineRCCompiler.cmake
new file mode 100644
index 0000000000..e5414eb996
--- /dev/null
+++ b/Modules/CMakeDetermineRCCompiler.cmake
@@ -0,0 +1,67 @@
+
+#=============================================================================
+# Copyright 2004-2009 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.)
+
+# determine the compiler to use for RC programs
+# NOTE, a generator may set CMAKE_RC_COMPILER before
+# loading this file to force a compiler.
+# use environment variable RC first if defined by user, next use
+# the cmake variable CMAKE_GENERATOR_RC which can be defined by a generator
+# as a default compiler
+if(NOT CMAKE_RC_COMPILER)
+ # prefer the environment variable RC
+ if(NOT $ENV{RC} STREQUAL "")
+ get_filename_component(CMAKE_RC_COMPILER_INIT $ENV{RC} PROGRAM PROGRAM_ARGS CMAKE_RC_FLAGS_ENV_INIT)
+ if(CMAKE_RC_FLAGS_ENV_INIT)
+ set(CMAKE_RC_COMPILER_ARG1 "${CMAKE_RC_FLAGS_ENV_INIT}" CACHE STRING "First argument to RC compiler")
+ endif()
+ if(EXISTS ${CMAKE_RC_COMPILER_INIT})
+ else()
+ message(FATAL_ERROR "Could not find compiler set in environment variable RC:\n$ENV{RC}.")
+ endif()
+ endif()
+
+ # next try prefer the compiler specified by the generator
+ if(CMAKE_GENERATOR_RC)
+ if(NOT CMAKE_RC_COMPILER_INIT)
+ set(CMAKE_RC_COMPILER_INIT ${CMAKE_GENERATOR_RC})
+ endif()
+ endif()
+
+ # finally list compilers to try
+ if(CMAKE_RC_COMPILER_INIT)
+ set(CMAKE_RC_COMPILER_LIST ${CMAKE_RC_COMPILER_INIT})
+ else()
+ set(CMAKE_RC_COMPILER_LIST rc)
+ endif()
+
+ # Find the compiler.
+ find_program(CMAKE_RC_COMPILER NAMES ${CMAKE_RC_COMPILER_LIST} DOC "RC compiler")
+ if(CMAKE_RC_COMPILER_INIT AND NOT CMAKE_RC_COMPILER)
+ set(CMAKE_RC_COMPILER "${CMAKE_RC_COMPILER_INIT}" CACHE FILEPATH "RC compiler" FORCE)
+ endif()
+endif()
+
+mark_as_advanced(CMAKE_RC_COMPILER)
+
+get_filename_component(_CMAKE_RC_COMPILER_NAME_WE ${CMAKE_RC_COMPILER} NAME_WE)
+if(_CMAKE_RC_COMPILER_NAME_WE STREQUAL "windres")
+ set(CMAKE_RC_OUTPUT_EXTENSION .obj)
+else()
+ set(CMAKE_RC_OUTPUT_EXTENSION .res)
+endif()
+
+# configure variables set in this file for fast reload later on
+configure_file(${CMAKE_ROOT}/Modules/CMakeRCCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeRCCompiler.cmake)
+set(CMAKE_RC_COMPILER_ENV_VAR "RC")
diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake
new file mode 100644
index 0000000000..fe292ea4a4
--- /dev/null
+++ b/Modules/CMakeDetermineSystem.cmake
@@ -0,0 +1,191 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is used by the Makefile generator to determin the following variables:
+# CMAKE_SYSTEM_NAME - on unix this is uname -s, for windows it is Windows
+# CMAKE_SYSTEM_VERSION - on unix this is uname -r, for windows it is empty
+# CMAKE_SYSTEM - ${CMAKE_SYSTEM}-${CMAKE_SYSTEM_VERSION}, for windows: ${CMAKE_SYSTEM}
+#
+# Expected uname -s output:
+#
+# AIX AIX
+# BSD/OS BSD/OS
+# FreeBSD FreeBSD
+# HP-UX HP-UX
+# IRIX IRIX
+# Linux Linux
+# GNU/kFreeBSD GNU/kFreeBSD
+# NetBSD NetBSD
+# OpenBSD OpenBSD
+# OFS/1 (Digital Unix) OSF1
+# SCO OpenServer 5 SCO_SV
+# SCO UnixWare 7 UnixWare
+# SCO UnixWare (pre release 7) UNIX_SV
+# SCO XENIX Xenix
+# Solaris SunOS
+# SunOS SunOS
+# Tru64 Tru64
+# Ultrix ULTRIX
+# cygwin CYGWIN_NT-5.1
+# MacOSX Darwin
+
+
+# find out on which system cmake runs
+if(CMAKE_HOST_UNIX)
+ find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
+ if(CMAKE_UNAME)
+ exec_program(uname ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_NAME)
+ exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
+ if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|CYGWIN.*|Darwin|^GNU$")
+ exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
+ RETURN_VALUE val)
+ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND
+ CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "Power Macintosh")
+ # OS X ppc 'uname -m' may report 'Power Macintosh' instead of 'powerpc'
+ set(CMAKE_HOST_SYSTEM_PROCESSOR "powerpc")
+ endif()
+ elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD")
+ exec_program(arch ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
+ RETURN_VALUE val)
+ else()
+ exec_program(uname ARGS -p OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
+ RETURN_VALUE val)
+ if("${val}" GREATER 0)
+ exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
+ RETURN_VALUE val)
+ endif()
+ endif()
+ # check the return of the last uname -m or -p
+ if("${val}" GREATER 0)
+ set(CMAKE_HOST_SYSTEM_PROCESSOR "unknown")
+ endif()
+ set(CMAKE_UNAME ${CMAKE_UNAME} CACHE INTERNAL "uname command")
+ # processor may have double quote in the name, and that needs to be removed
+ string(REPLACE "\"" "" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
+ string(REPLACE "/" "_" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
+ endif()
+else()
+ if(CMAKE_HOST_WIN32)
+ set (CMAKE_HOST_SYSTEM_NAME "Windows")
+ if (DEFINED ENV{PROCESSOR_ARCHITEW6432})
+ set (CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}")
+ else()
+ set (CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
+ endif()
+ endif()
+endif()
+
+# if a toolchain file is used, the user wants to cross compile.
+# in this case read the toolchain file and keep the CMAKE_HOST_SYSTEM_*
+# variables around so they can be used in CMakeLists.txt.
+# In all other cases, the host and target platform are the same.
+if(CMAKE_TOOLCHAIN_FILE)
+ # at first try to load it as path relative to the directory from which cmake has been run
+ include("${CMAKE_BINARY_DIR}/${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
+ if(NOT _INCLUDED_TOOLCHAIN_FILE)
+ # if the file isn't found there, check the default locations
+ include("${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
+ endif()
+
+ if(_INCLUDED_TOOLCHAIN_FILE)
+ set(CMAKE_TOOLCHAIN_FILE "${_INCLUDED_TOOLCHAIN_FILE}" CACHE FILEPATH "The CMake toolchain file" FORCE)
+ else()
+ message(FATAL_ERROR "Could not find toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
+ set(CMAKE_TOOLCHAIN_FILE "NOTFOUND" CACHE FILEPATH "The CMake toolchain file" FORCE)
+ endif()
+endif()
+
+
+# if CMAKE_SYSTEM_NAME is here already set, either it comes from a toolchain file
+# or it was set via -DCMAKE_SYSTEM_NAME=...
+# if that's the case, assume we are crosscompiling
+if(CMAKE_SYSTEM_NAME)
+ if(NOT DEFINED CMAKE_CROSSCOMPILING)
+ set(CMAKE_CROSSCOMPILING TRUE)
+ endif()
+ set(PRESET_CMAKE_SYSTEM_NAME TRUE)
+elseif(CMAKE_VS_WINCE_VERSION)
+ set(CMAKE_SYSTEM_NAME "WindowsCE")
+ set(CMAKE_SYSTEM_VERSION "${CMAKE_VS_WINCE_VERSION}")
+ set(CMAKE_SYSTEM_PROCESSOR "${MSVC_C_ARCHITECTURE_ID}")
+ set(CMAKE_CROSSCOMPILING TRUE)
+ set(PRESET_CMAKE_SYSTEM_NAME TRUE)
+else()
+ set(CMAKE_SYSTEM_NAME "${CMAKE_HOST_SYSTEM_NAME}")
+ set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
+ set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
+ set(CMAKE_CROSSCOMPILING FALSE)
+ set(PRESET_CMAKE_SYSTEM_NAME FALSE)
+endif()
+
+
+macro(ADJUST_CMAKE_SYSTEM_VARIABLES _PREFIX)
+ if(NOT ${_PREFIX}_NAME)
+ set(${_PREFIX}_NAME "UnknownOS")
+ endif()
+
+ # fix for BSD/OS , remove the /
+ if(${_PREFIX}_NAME MATCHES BSD.OS)
+ set(${_PREFIX}_NAME BSDOS)
+ endif()
+
+ # fix for GNU/kFreeBSD, remove the GNU/
+ if(${_PREFIX}_NAME MATCHES kFreeBSD)
+ set(${_PREFIX}_NAME kFreeBSD)
+ endif()
+
+ # fix for CYGWIN which has windows version in it
+ if(${_PREFIX}_NAME MATCHES CYGWIN)
+ set(${_PREFIX}_NAME CYGWIN)
+ endif()
+
+ # set CMAKE_SYSTEM to the CMAKE_SYSTEM_NAME
+ set(${_PREFIX} ${${_PREFIX}_NAME})
+ # if there is a CMAKE_SYSTEM_VERSION then add a -${CMAKE_SYSTEM_VERSION}
+ if(${_PREFIX}_VERSION)
+ set(${_PREFIX} ${${_PREFIX}}-${${_PREFIX}_VERSION})
+ endif()
+
+endmacro()
+
+ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_SYSTEM)
+ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_HOST_SYSTEM)
+
+# this file is also executed from cpack, then we don't need to generate these files
+# in this case there is no CMAKE_BINARY_DIR
+if(CMAKE_BINARY_DIR)
+ # write entry to the log file
+ if(PRESET_CMAKE_SYSTEM_NAME)
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "The target system is: ${CMAKE_SYSTEM_NAME} - ${CMAKE_SYSTEM_VERSION} - ${CMAKE_SYSTEM_PROCESSOR}\n")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "The host system is: ${CMAKE_HOST_SYSTEM_NAME} - ${CMAKE_HOST_SYSTEM_VERSION} - ${CMAKE_HOST_SYSTEM_PROCESSOR}\n")
+ else()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "The system is: ${CMAKE_SYSTEM_NAME} - ${CMAKE_SYSTEM_VERSION} - ${CMAKE_SYSTEM_PROCESSOR}\n")
+ endif()
+
+ # if a toolchain file is used, it needs to be included in the configured file,
+ # so settings done there are also available if they don't go in the cache and in try_compile()
+ set(INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED)
+ if(DEFINED CMAKE_TOOLCHAIN_FILE)
+ set(INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED "include(\"${CMAKE_TOOLCHAIN_FILE}\")")
+ endif()
+
+ # configure variables set in this file for fast reload, the template file is defined at the top of this file
+ configure_file(${CMAKE_ROOT}/Modules/CMakeSystem.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeSystem.cmake
+ @ONLY)
+
+endif()
diff --git a/Modules/CMakeDetermineVSServicePack.cmake b/Modules/CMakeDetermineVSServicePack.cmake
new file mode 100644
index 0000000000..6886084796
--- /dev/null
+++ b/Modules/CMakeDetermineVSServicePack.cmake
@@ -0,0 +1,184 @@
+#.rst:
+# CMakeDetermineVSServicePack
+# ---------------------------
+#
+# Deprecated. Do not use.
+#
+# The functionality of this module has been superseded by the
+# :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable that contains
+# the compiler version number.
+#
+# Determine the Visual Studio service pack of the 'cl' in use.
+#
+# Usage::
+#
+# if(MSVC)
+# include(CMakeDetermineVSServicePack)
+# DetermineVSServicePack( my_service_pack )
+# if( my_service_pack )
+# message(STATUS "Detected: ${my_service_pack}")
+# endif()
+# endif()
+#
+# Function DetermineVSServicePack sets the given variable to one of the
+# following values or an empty string if unknown::
+#
+# vc80, vc80sp1
+# vc90, vc90sp1
+# vc100, vc100sp1
+# vc110, vc110sp1, vc110sp2, vc110sp3, vc110sp4
+
+#=============================================================================
+# Copyright 2009-2013 Kitware, Inc.
+# Copyright 2009-2010 Philip Lowman <philip@yhbt.com>
+# Copyright 2010-2011 Aaron C. meadows <cmake@shadowguarddev.com>
+#
+# 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.)
+
+if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
+ message(DEPRECATION
+ "This module is deprecated and should not be used. "
+ "Use the CMAKE_<LANG>_COMPILER_VERSION variable instead."
+ )
+endif()
+
+# [INTERNAL]
+# Please do not call this function directly
+function(_DetermineVSServicePackFromCompiler _OUT_VAR _cl_version)
+ if (${_cl_version} VERSION_EQUAL "14.00.50727.42")
+ set(_version "vc80")
+ elseif(${_cl_version} VERSION_EQUAL "14.00.50727.762")
+ set(_version "vc80sp1")
+ elseif(${_cl_version} VERSION_EQUAL "15.00.21022.08")
+ set(_version "vc90")
+ elseif(${_cl_version} VERSION_EQUAL "15.00.30729.01")
+ set(_version "vc90sp1")
+ elseif(${_cl_version} VERSION_EQUAL "16.00.30319.01")
+ set(_version "vc100")
+ elseif(${_cl_version} VERSION_EQUAL "16.00.40219.01")
+ set(_version "vc100sp1")
+ elseif(${_cl_version} VERSION_EQUAL "17.00.50727.1")
+ set(_version "vc110")
+ elseif(${_cl_version} VERSION_EQUAL "17.00.51106.1")
+ set(_version "vc110sp1")
+ elseif(${_cl_version} VERSION_EQUAL "17.00.60315.1")
+ set(_version "vc110sp2")
+ elseif(${_cl_version} VERSION_EQUAL "17.00.60610.1")
+ set(_version "vc110sp3")
+ elseif(${_cl_version} VERSION_EQUAL "17.00.61030")
+ set(_version "vc110sp4")
+ else()
+ set(_version "")
+ endif()
+ set(${_OUT_VAR} ${_version} PARENT_SCOPE)
+endfunction()
+
+
+############################################################
+# [INTERNAL]
+# Please do not call this function directly
+function(_DetermineVSServicePack_FastCheckVersionWithCompiler _SUCCESS_VAR _VERSION_VAR)
+ if(EXISTS ${CMAKE_CXX_COMPILER})
+ execute_process(
+ COMMAND ${CMAKE_CXX_COMPILER} /?
+ ERROR_VARIABLE _output
+ OUTPUT_QUIET
+ )
+
+ if(_output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)")
+ set(_cl_version ${CMAKE_MATCH_1})
+ set(_major ${CMAKE_MATCH_2})
+ set(_minor ${CMAKE_MATCH_3})
+ if("${_major}${_minor}" STREQUAL "${MSVC_VERSION}")
+ set(${_SUCCESS_VAR} true PARENT_SCOPE)
+ set(${_VERSION_VAR} ${_cl_version} PARENT_SCOPE)
+ endif()
+ endif()
+ endif()
+endfunction()
+
+############################################################
+# [INTERNAL]
+# Please do not call this function directly
+function(_DetermineVSServicePack_CheckVersionWithTryCompile _SUCCESS_VAR _VERSION_VAR)
+ file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
+ "int main() { return 0; }\n")
+
+ try_compile(
+ _CompileResult
+ "${CMAKE_BINARY_DIR}"
+ "${CMAKE_BINARY_DIR}/return0.cc"
+ OUTPUT_VARIABLE _output
+ COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc")
+
+ file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
+
+ if(_output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)")
+ set(${_SUCCESS_VAR} true PARENT_SCOPE)
+ set(${_VERSION_VAR} "${CMAKE_MATCH_1}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+############################################################
+# [INTERNAL]
+# Please do not call this function directly
+function(_DetermineVSServicePack_CheckVersionWithTryRun _SUCCESS_VAR _VERSION_VAR)
+ file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
+ "#include <stdio.h>\n\nconst unsigned int CompilerVersion=_MSC_FULL_VER;\n\nint main(int argc, char* argv[])\n{\n int M( CompilerVersion/10000000);\n int m((CompilerVersion%10000000)/100000);\n int b(CompilerVersion%100000);\n\n printf(\"%d.%02d.%05d.01\",M,m,b);\n return 0;\n}\n")
+
+ try_run(
+ _RunResult
+ _CompileResult
+ "${CMAKE_BINARY_DIR}"
+ "${CMAKE_BINARY_DIR}/return0.cc"
+ RUN_OUTPUT_VARIABLE _runoutput
+ )
+
+ file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
+
+ string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
+ _cl_version "${_runoutput}")
+
+ if(_cl_version)
+ set(${_SUCCESS_VAR} true PARENT_SCOPE)
+ set(${_VERSION_VAR} ${_cl_version} PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+#
+# A function to call to determine the Visual Studio service pack
+# in use. See documentation above.
+function(DetermineVSServicePack _pack)
+ if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack})
+
+ _DetermineVSServicePack_FastCheckVersionWithCompiler(DETERMINED_VS_SERVICE_PACK _cl_version)
+ if(NOT DETERMINED_VS_SERVICE_PACK)
+ _DetermineVSServicePack_CheckVersionWithTryCompile(DETERMINED_VS_SERVICE_PACK _cl_version)
+ if(NOT DETERMINED_VS_SERVICE_PACK)
+ _DetermineVSServicePack_CheckVersionWithTryRun(DETERMINED_VS_SERVICE_PACK _cl_version)
+ endif()
+ endif()
+
+ if(DETERMINED_VS_SERVICE_PACK)
+
+ if(_cl_version)
+ # Call helper function to determine VS version
+ _DetermineVSServicePackFromCompiler(_sp "${_cl_version}")
+ if(_sp)
+ set(${_pack} ${_sp} CACHE INTERNAL
+ "The Visual Studio Release with Service Pack")
+ endif()
+ endif()
+ endif()
+ endif()
+endfunction()
+
diff --git a/Modules/CMakeExpandImportedTargets.cmake b/Modules/CMakeExpandImportedTargets.cmake
new file mode 100644
index 0000000000..b6ab7efb57
--- /dev/null
+++ b/Modules/CMakeExpandImportedTargets.cmake
@@ -0,0 +1,145 @@
+#.rst:
+# CMakeExpandImportedTargets
+# --------------------------
+#
+# ::
+#
+# CMAKE_EXPAND_IMPORTED_TARGETS(<var> LIBRARIES lib1 lib2...libN
+# [CONFIGURATION <config>])
+#
+# CMAKE_EXPAND_IMPORTED_TARGETS() takes a list of libraries and replaces
+# all imported targets contained in this list with their actual file
+# paths of the referenced libraries on disk, including the libraries
+# from their link interfaces. If a CONFIGURATION is given, it uses the
+# respective configuration of the imported targets if it exists. If no
+# CONFIGURATION is given, it uses the first configuration from
+# ${CMAKE_CONFIGURATION_TYPES} if set, otherwise ${CMAKE_BUILD_TYPE}.
+# This macro is used by all Check*.cmake files which use try_compile()
+# or try_run() and support CMAKE_REQUIRED_LIBRARIES , so that these
+# checks support imported targets in CMAKE_REQUIRED_LIBRARIES:
+#
+# ::
+#
+# cmake_expand_imported_targets(expandedLibs LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
+# CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}" )
+
+
+#=============================================================================
+# Copyright 2012 Kitware, Inc.
+# Copyright 2009-2012 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
+
+function(CMAKE_EXPAND_IMPORTED_TARGETS _RESULT )
+
+ set(options )
+ set(oneValueArgs CONFIGURATION )
+ set(multiValueArgs LIBRARIES )
+
+ cmake_parse_arguments(CEIT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if(CEIT_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown keywords given to CMAKE_EXPAND_IMPORTED_TARGETS(): \"${CEIT_UNPARSED_ARGUMENTS}\"")
+ endif()
+
+ if(NOT CEIT_CONFIGURATION)
+ if(CMAKE_CONFIGURATION_TYPES)
+ list(GET CMAKE_CONFIGURATION_TYPES 0 CEIT_CONFIGURATION)
+ else()
+ set(CEIT_CONFIGURATION ${CMAKE_BUILD_TYPE})
+ endif()
+ endif()
+
+ # handle imported library targets
+
+ set(_CCSR_REQ_LIBS ${CEIT_LIBRARIES})
+
+ set(_CHECK_FOR_IMPORTED_TARGETS TRUE)
+ set(_CCSR_LOOP_COUNTER 0)
+ while(_CHECK_FOR_IMPORTED_TARGETS)
+ math(EXPR _CCSR_LOOP_COUNTER "${_CCSR_LOOP_COUNTER} + 1 ")
+ set(_CCSR_NEW_REQ_LIBS )
+ set(_CHECK_FOR_IMPORTED_TARGETS FALSE)
+ foreach(_CURRENT_LIB ${_CCSR_REQ_LIBS})
+ if(TARGET "${_CURRENT_LIB}")
+ get_target_property(_importedConfigs "${_CURRENT_LIB}" IMPORTED_CONFIGURATIONS)
+ else()
+ set(_importedConfigs "")
+ endif()
+ if (_importedConfigs)
+# message(STATUS "Detected imported target ${_CURRENT_LIB}")
+ # Ok, so this is an imported target.
+ # First we get the imported configurations.
+ # Then we get the location of the actual library on disk of the first configuration.
+ # then we'll get its link interface libraries property,
+ # iterate through it and replace all imported targets we find there
+ # with there actual location.
+
+ # guard against infinite loop: abort after 100 iterations ( 100 is arbitrary chosen)
+ if ("${_CCSR_LOOP_COUNTER}" LESS 100)
+ set(_CHECK_FOR_IMPORTED_TARGETS TRUE)
+# else ()
+# message(STATUS "********* aborting loop, counter : ${_CCSR_LOOP_COUNTER}")
+ endif ()
+
+ # if one of the imported configurations equals ${CMAKE_TRY_COMPILE_CONFIGURATION},
+ # use it, otherwise simply use the first one:
+ list(FIND _importedConfigs "${CEIT_CONFIGURATION}" _configIndexToUse)
+ if("${_configIndexToUse}" EQUAL -1)
+ set(_configIndexToUse 0)
+ endif()
+ list(GET _importedConfigs ${_configIndexToUse} _importedConfigToUse)
+
+ get_target_property(_importedLocation "${_CURRENT_LIB}" IMPORTED_LOCATION_${_importedConfigToUse})
+ get_target_property(_linkInterfaceLibs "${_CURRENT_LIB}" IMPORTED_LINK_INTERFACE_LIBRARIES_${_importedConfigToUse} )
+
+ list(APPEND _CCSR_NEW_REQ_LIBS "${_importedLocation}")
+# message(STATUS "Appending lib ${_CURRENT_LIB} as ${_importedLocation}")
+ if(_linkInterfaceLibs)
+ foreach(_currentLinkInterfaceLib ${_linkInterfaceLibs})
+# message(STATUS "Appending link interface lib ${_currentLinkInterfaceLib}")
+ if(_currentLinkInterfaceLib)
+ list(APPEND _CCSR_NEW_REQ_LIBS "${_currentLinkInterfaceLib}" )
+ endif()
+ endforeach()
+ endif()
+ else()
+ # "Normal" libraries are just used as they are.
+ list(APPEND _CCSR_NEW_REQ_LIBS "${_CURRENT_LIB}" )
+# message(STATUS "Appending lib directly: ${_CURRENT_LIB}")
+ endif()
+ endforeach()
+
+ set(_CCSR_REQ_LIBS ${_CCSR_NEW_REQ_LIBS} )
+ endwhile()
+
+ # Finally we iterate once more over all libraries. This loop only removes
+ # all remaining imported target names (there shouldn't be any left anyway).
+ set(_CCSR_NEW_REQ_LIBS )
+ foreach(_CURRENT_LIB ${_CCSR_REQ_LIBS})
+ if(TARGET "${_CURRENT_LIB}")
+ get_target_property(_importedConfigs "${_CURRENT_LIB}" IMPORTED_CONFIGURATIONS)
+ else()
+ set(_importedConfigs "")
+ endif()
+ if (NOT _importedConfigs)
+ list(APPEND _CCSR_NEW_REQ_LIBS "${_CURRENT_LIB}" )
+# message(STATUS "final: appending ${_CURRENT_LIB}")
+ else ()
+# message(STATUS "final: skipping ${_CURRENT_LIB}")
+ endif ()
+ endforeach()
+# message(STATUS "setting -${_RESULT}- to -${_CCSR_NEW_REQ_LIBS}-")
+ set(${_RESULT} "${_CCSR_NEW_REQ_LIBS}" PARENT_SCOPE)
+
+endfunction()
diff --git a/Modules/CMakeExportBuildSettings.cmake b/Modules/CMakeExportBuildSettings.cmake
new file mode 100644
index 0000000000..a8dd8c282c
--- /dev/null
+++ b/Modules/CMakeExportBuildSettings.cmake
@@ -0,0 +1,36 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is purposely no longer documented. It does nothing useful.
+if(NOT "${CMAKE_MINIMUM_REQUIRED_VERSION}" VERSION_LESS 2.7)
+ message(FATAL_ERROR
+ "The functionality of this module has been dropped as of CMake 2.8. "
+ "It was deemed harmful (confusing users by changing their compiler). "
+ "Please remove calls to the CMAKE_EXPORT_BUILD_SETTINGS macro and "
+ "stop including this module. "
+ "If this project generates any files for use by external projects, "
+ "remove any use of the CMakeImportBuildSettings module from them.")
+endif()
+
+# This macro used to store build settings of a project in a file to be
+# loaded by another project using CMAKE_IMPORT_BUILD_SETTINGS. Now it
+# creates a file that refuses to load (with comment explaining why).
+macro(CMAKE_EXPORT_BUILD_SETTINGS SETTINGS_FILE)
+ if(NOT ${SETTINGS_FILE} STREQUAL "")
+ configure_file(${CMAKE_ROOT}/Modules/CMakeBuildSettings.cmake.in
+ ${SETTINGS_FILE} @ONLY)
+ else()
+ message(SEND_ERROR "CMAKE_EXPORT_BUILD_SETTINGS called with no argument.")
+ endif()
+endmacro()
diff --git a/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake b/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake
new file mode 100644
index 0000000000..365d381ef9
--- /dev/null
+++ b/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake
@@ -0,0 +1,112 @@
+
+#=============================================================================
+# Copyright 2009 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 is included by CMakeFindEclipseCDT4.cmake and CMakeFindCodeBlocks.cmake
+
+# The Eclipse and the CodeBlocks generators need to know the standard include path
+# so that they can find the headers at runtime and parsing etc. works better
+# This is done here by actually running gcc with the options so it prints its
+# system include directories, which are parsed then and stored in the cache.
+macro(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang _resultIncludeDirs _resultDefines)
+ set(${_resultIncludeDirs})
+ set(_gccOutput)
+ file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy" "\n" )
+
+ if (${_lang} STREQUAL "c++")
+ set(_compilerExecutable "${CMAKE_CXX_COMPILER}")
+ set(_arg1 "${CMAKE_CXX_COMPILER_ARG1}")
+ else ()
+ set(_compilerExecutable "${CMAKE_C_COMPILER}")
+ set(_arg1 "${CMAKE_C_COMPILER_ARG1}")
+ endif ()
+ execute_process(COMMAND ${_compilerExecutable} ${_arg1} -v -E -x ${_lang} -dD dummy
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles
+ ERROR_VARIABLE _gccOutput
+ OUTPUT_VARIABLE _gccStdout )
+ file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy")
+
+ # First find the system include dirs:
+ if( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+ *\n) *End of (search) list" )
+
+ # split the output into lines and then remove leading and trailing spaces from each of them:
+ string(REGEX MATCHALL "[^\n]+\n" _includeLines "${CMAKE_MATCH_1}")
+ foreach(nextLine ${_includeLines})
+ # on OSX, gcc says things like this: "/System/Library/Frameworks (framework directory)", strip the last part
+ string(REGEX REPLACE "\\(framework directory\\)" "" nextLineNoFramework "${nextLine}")
+ # strip spaces at the beginning and the end
+ string(STRIP "${nextLineNoFramework}" _includePath)
+ list(APPEND ${_resultIncludeDirs} "${_includePath}")
+ endforeach()
+
+ endif()
+
+
+ # now find the builtin macros:
+ string(REGEX MATCHALL "#define[^\n]+\n" _defineLines "${_gccStdout}")
+# A few example lines which the regexp below has to match properly:
+# #define MAX(a,b) ((a) > (b) ? (a) : (b))
+# #define __fastcall __attribute__((__fastcall__))
+# #define FOO (23)
+# #define __UINTMAX_TYPE__ long long unsigned int
+# #define __UINTMAX_TYPE__ long long unsigned int
+# #define __i386__ 1
+
+ foreach(nextLine ${_defineLines})
+ string(REGEX MATCH "^#define +([A-Za-z_][A-Za-z0-9_]*)(\\([^\\)]+\\))? +(.+) *$" _dummy "${nextLine}")
+ set(_name "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
+ string(STRIP "${CMAKE_MATCH_3}" _value)
+ #message(STATUS "m1: -${CMAKE_MATCH_1}- m2: -${CMAKE_MATCH_2}- m3: -${CMAKE_MATCH_3}-")
+
+ list(APPEND ${_resultDefines} "${_name}")
+ if(_value)
+ list(APPEND ${_resultDefines} "${_value}")
+ else()
+ list(APPEND ${_resultDefines} " ")
+ endif()
+ endforeach()
+
+endmacro()
+
+# Save the current LC_ALL, LC_MESSAGES, and LANG environment variables and set them
+# to "C" that way GCC's "search starts here" text is in English and we can grok it.
+set(_orig_lc_all $ENV{LC_ALL})
+set(_orig_lc_messages $ENV{LC_MESSAGES})
+set(_orig_lang $ENV{LANG})
+
+set(ENV{LC_ALL} C)
+set(ENV{LC_MESSAGES} C)
+set(ENV{LANG} C)
+
+# Now check for C, works for gcc and Intel compiler at least
+if (NOT CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS)
+ if ("${CMAKE_C_COMPILER_ID}" MATCHES GNU OR "${CMAKE_C_COMPILER_ID}" MATCHES Intel OR "${CMAKE_C_COMPILER_ID}" MATCHES Clang)
+ _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c _dirs _defines)
+ set(CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "C compiler system include directories")
+ set(CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "C compiler system defined macros")
+ endif ()
+endif ()
+
+# And now the same for C++
+if (NOT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS)
+ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Clang)
+ _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c++ _dirs _defines)
+ set(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "CXX compiler system include directories")
+ set(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "CXX compiler system defined macros")
+ endif ()
+endif ()
+
+# Restore original LC_ALL, LC_MESSAGES, and LANG
+set(ENV{LC_ALL} ${_orig_lc_all})
+set(ENV{LC_MESSAGES} ${_orig_lc_messages})
+set(ENV{LANG} ${_orig_lang})
diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake
new file mode 100644
index 0000000000..e0ba131518
--- /dev/null
+++ b/Modules/CMakeFindBinUtils.cmake
@@ -0,0 +1,78 @@
+
+# search for additional tools required for C/C++ (and other languages ?)
+#
+# If the internal cmake variable _CMAKE_TOOLCHAIN_PREFIX is set, this is used
+# as prefix for the tools (e.g. arm-elf-gcc etc.)
+# If the cmake variable _CMAKE_TOOLCHAIN_LOCATION is set, the compiler is
+# searched only there. The other tools are at first searched there, then
+# also in the default locations.
+#
+# Sets the following variables:
+# CMAKE_AR
+# CMAKE_RANLIB
+# CMAKE_LINKER
+# CMAKE_STRIP
+# CMAKE_INSTALL_NAME_TOOL
+
+# on UNIX, cygwin and mingw
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# if it's the MS C/CXX compiler, search for link
+if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC"
+ OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC"
+ OR "${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "MSVC"
+ OR "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"
+ OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC"
+ OR ("${CMAKE_GENERATOR}" MATCHES "Visual Studio"
+ AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android"))
+
+ find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+
+ mark_as_advanced(CMAKE_LINKER)
+
+# in all other cases search for ar, ranlib, etc.
+else()
+ if(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN)
+ set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
+ endif()
+ if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
+ set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
+ endif()
+ find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+
+ find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+ if(NOT CMAKE_RANLIB)
+ set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
+ endif()
+
+ find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+ find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+ find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+ find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+ find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+
+ mark_as_advanced(CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY)
+
+endif()
+
+if(CMAKE_PLATFORM_HAS_INSTALLNAME)
+ find_program(CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+
+ if(NOT CMAKE_INSTALL_NAME_TOOL)
+ message(FATAL_ERROR "Could not find install_name_tool, please check your installation.")
+ endif()
+
+ mark_as_advanced(CMAKE_INSTALL_NAME_TOOL)
+endif()
diff --git a/Modules/CMakeFindCodeBlocks.cmake b/Modules/CMakeFindCodeBlocks.cmake
new file mode 100644
index 0000000000..f8d8d5908c
--- /dev/null
+++ b/Modules/CMakeFindCodeBlocks.cmake
@@ -0,0 +1,25 @@
+
+#=============================================================================
+# Copyright 2009 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 is included in CMakeSystemSpecificInformation.cmake if
+# the CodeBlocks extra generator has been selected.
+
+find_program(CMAKE_CODEBLOCKS_EXECUTABLE NAMES codeblocks DOC "The CodeBlocks executable")
+
+if(CMAKE_CODEBLOCKS_EXECUTABLE)
+ set(CMAKE_OPEN_PROJECT_COMMAND "${CMAKE_CODEBLOCKS_EXECUTABLE} <PROJECT_FILE>" )
+endif()
+
+# Determine builtin macros and include dirs:
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake)
diff --git a/Modules/CMakeFindDependencyMacro.cmake b/Modules/CMakeFindDependencyMacro.cmake
new file mode 100644
index 0000000000..73efaae7cd
--- /dev/null
+++ b/Modules/CMakeFindDependencyMacro.cmake
@@ -0,0 +1,85 @@
+#.rst:
+# CMakeFindDependencyMacro
+# -------------------------
+#
+# ::
+#
+# find_dependency(<dep> [<version> [EXACT]])
+#
+#
+# ``find_dependency()`` wraps a :command:`find_package` call for a package
+# dependency. It is designed to be used in a <package>Config.cmake file, and it
+# forwards the correct parameters for EXACT, QUIET and REQUIRED which were
+# passed to the original :command:`find_package` call. It also sets an
+# informative diagnostic message if the dependency could not be found.
+#
+
+#=============================================================================
+# Copyright 2013 Stephen Kelly <steveire@gmail.com>
+#
+# 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.)
+
+macro(find_dependency dep)
+ if (NOT ${dep}_FOUND)
+ set(cmake_fd_version)
+ if (${ARGC} GREATER 1)
+ if ("${ARGV1}" STREQUAL "")
+ message(FATAL_ERROR "Invalid arguments to find_dependency. VERSION is empty")
+ endif()
+ if ("${ARGV1}" STREQUAL EXACT)
+ message(FATAL_ERROR "Invalid arguments to find_dependency. EXACT may only be specified if a VERSION is specified")
+ endif()
+ set(cmake_fd_version ${ARGV1})
+ endif()
+ set(cmake_fd_exact_arg)
+ if(${ARGC} GREATER 2)
+ if (NOT "${ARGV2}" STREQUAL EXACT)
+ message(FATAL_ERROR "Invalid arguments to find_dependency")
+ endif()
+ set(cmake_fd_exact_arg EXACT)
+ endif()
+ if(${ARGC} GREATER 3)
+ message(FATAL_ERROR "Invalid arguments to find_dependency")
+ endif()
+ set(cmake_fd_quiet_arg)
+ if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
+ set(cmake_fd_quiet_arg QUIET)
+ endif()
+ set(cmake_fd_required_arg)
+ if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
+ set(cmake_fd_required_arg REQUIRED)
+ endif()
+
+ get_property(cmake_fd_alreadyTransitive GLOBAL PROPERTY
+ _CMAKE_${dep}_TRANSITIVE_DEPENDENCY
+ )
+
+ find_package(${dep} ${cmake_fd_version}
+ ${cmake_fd_exact_arg}
+ ${cmake_fd_quiet_arg}
+ ${cmake_fd_required_arg}
+ )
+
+ if(NOT DEFINED cmake_fd_alreadyTransitive OR cmake_fd_alreadyTransitive)
+ set_property(GLOBAL PROPERTY _CMAKE_${dep}_TRANSITIVE_DEPENDENCY TRUE)
+ endif()
+
+ if (NOT ${dep}_FOUND)
+ set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency ${dep} could not be found.")
+ set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
+ return()
+ endif()
+ set(cmake_fd_version)
+ set(cmake_fd_required_arg)
+ set(cmake_fd_quiet_arg)
+ set(cmake_fd_exact_arg)
+ endif()
+endmacro()
diff --git a/Modules/CMakeFindEclipseCDT4.cmake b/Modules/CMakeFindEclipseCDT4.cmake
new file mode 100644
index 0000000000..85c1fdf5b3
--- /dev/null
+++ b/Modules/CMakeFindEclipseCDT4.cmake
@@ -0,0 +1,95 @@
+
+#=============================================================================
+# Copyright 2009 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 is included in CMakeSystemSpecificInformation.cmake if
+# the Eclipse CDT4 extra generator has been selected.
+
+find_program(CMAKE_ECLIPSE_EXECUTABLE NAMES eclipse DOC "The Eclipse executable")
+
+function(_FIND_ECLIPSE_VERSION)
+ # This code is in a function so the variables used here have only local scope
+
+ # Set up a map with the names of the Eclipse releases:
+ set(_ECLIPSE_VERSION_NAME_ "Unknown" )
+ set(_ECLIPSE_VERSION_NAME_3.2 "Callisto" )
+ set(_ECLIPSE_VERSION_NAME_3.3 "Europa" )
+ set(_ECLIPSE_VERSION_NAME_3.4 "Ganymede" )
+ set(_ECLIPSE_VERSION_NAME_3.5 "Galileo" )
+ set(_ECLIPSE_VERSION_NAME_3.6 "Helios" )
+ set(_ECLIPSE_VERSION_NAME_3.7 "Indigo" )
+ set(_ECLIPSE_VERSION_NAME_4.2 "Juno" )
+ set(_ECLIPSE_VERSION_NAME_4.3 "Kepler" )
+
+ if(NOT DEFINED CMAKE_ECLIPSE_VERSION)
+ if(CMAKE_ECLIPSE_EXECUTABLE)
+ # use REALPATH to resolve symlinks (http://public.kitware.com/Bug/view.php?id=13036)
+ get_filename_component(_REALPATH_CMAKE_ECLIPSE_EXECUTABLE "${CMAKE_ECLIPSE_EXECUTABLE}" REALPATH)
+ get_filename_component(_ECLIPSE_DIR "${_REALPATH_CMAKE_ECLIPSE_EXECUTABLE}" PATH)
+ file(GLOB _ECLIPSE_FEATURE_DIR "${_ECLIPSE_DIR}/features/org.eclipse.platform*")
+ if(APPLE AND NOT _ECLIPSE_FEATURE_DIR)
+ file(GLOB _ECLIPSE_FEATURE_DIR "${_ECLIPSE_DIR}/../../../features/org.eclipse.platform*")
+ endif()
+ if("${_ECLIPSE_FEATURE_DIR}" MATCHES ".+org.eclipse.platform_([0-9]+\\.[0-9]+).+")
+ set(_ECLIPSE_VERSION ${CMAKE_MATCH_1})
+ endif()
+ endif()
+
+ if(_ECLIPSE_VERSION)
+ message(STATUS "Found Eclipse version ${_ECLIPSE_VERSION} (${_ECLIPSE_VERSION_NAME_${_ECLIPSE_VERSION}})")
+ else()
+ set(_ECLIPSE_VERSION "3.6" )
+ message(STATUS "Could not determine Eclipse version, assuming at least ${_ECLIPSE_VERSION} (${_ECLIPSE_VERSION_NAME_${_ECLIPSE_VERSION}}). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.")
+ endif()
+
+ set(CMAKE_ECLIPSE_VERSION "${_ECLIPSE_VERSION} (${_ECLIPSE_VERSION_NAME_${_ECLIPSE_VERSION}})" CACHE STRING "The version of Eclipse. If Eclipse has not been found, 3.6 (Helios) is assumed.")
+ else()
+ message(STATUS "Eclipse version is set to ${CMAKE_ECLIPSE_VERSION}. Adjust CMAKE_ECLIPSE_VERSION if this is wrong.")
+ endif()
+
+ set_property(CACHE CMAKE_ECLIPSE_VERSION PROPERTY STRINGS "3.2 (${_ECLIPSE_VERSION_NAME_3.2})"
+ "3.3 (${_ECLIPSE_VERSION_NAME_3.3})"
+ "3.4 (${_ECLIPSE_VERSION_NAME_3.4})"
+ "3.5 (${_ECLIPSE_VERSION_NAME_3.5})"
+ "3.6 (${_ECLIPSE_VERSION_NAME_3.6})"
+ "3.7 (${_ECLIPSE_VERSION_NAME_3.7})"
+ "4.2 (${_ECLIPSE_VERSION_NAME_4.2})"
+ "4.3 (${_ECLIPSE_VERSION_NAME_4.3})"
+ )
+endfunction()
+
+_find_eclipse_version()
+
+# Try to find out how many CPUs we have and set the -j argument for make accordingly
+set(_CMAKE_ECLIPSE_INITIAL_MAKE_ARGS "")
+
+include(ProcessorCount)
+processorcount(_CMAKE_ECLIPSE_PROCESSOR_COUNT)
+
+# Only set -j if we are under UNIX and if the make-tool used actually has "make" in the name
+# (we may also get here in the future e.g. for ninja)
+if("${_CMAKE_ECLIPSE_PROCESSOR_COUNT}" GREATER 1 AND CMAKE_HOST_UNIX AND "${CMAKE_MAKE_PROGRAM}" MATCHES make)
+ set(_CMAKE_ECLIPSE_INITIAL_MAKE_ARGS "-j${_CMAKE_ECLIPSE_PROCESSOR_COUNT}")
+endif()
+
+# This variable is used by the Eclipse generator and appended to the make invocation commands.
+set(CMAKE_ECLIPSE_MAKE_ARGUMENTS "${_CMAKE_ECLIPSE_INITIAL_MAKE_ARGS}" CACHE STRING "Additional command line arguments when Eclipse invokes make. Enter e.g. -j<some_number> to get parallel builds")
+
+set(CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES TRUE CACHE BOOL "If disabled, CMake will not generate linked resource to the subprojects and to the source files within targets")
+
+# This variable is used by the Eclipse generator in out-of-source builds only.
+set(CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT FALSE CACHE BOOL "If enabled, CMake will generate a source project for Eclipse in CMAKE_SOURCE_DIR")
+mark_as_advanced(CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT)
+
+# Determine builtin macros and include dirs:
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake)
diff --git a/Modules/CMakeFindFrameworks.cmake b/Modules/CMakeFindFrameworks.cmake
new file mode 100644
index 0000000000..6a8bcd4548
--- /dev/null
+++ b/Modules/CMakeFindFrameworks.cmake
@@ -0,0 +1,36 @@
+#.rst:
+# CMakeFindFrameworks
+# -------------------
+#
+# helper module to find OSX frameworks
+
+#=============================================================================
+# Copyright 2003-2009 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.)
+
+if(NOT CMAKE_FIND_FRAMEWORKS_INCLUDED)
+ set(CMAKE_FIND_FRAMEWORKS_INCLUDED 1)
+ macro(CMAKE_FIND_FRAMEWORKS fwk)
+ set(${fwk}_FRAMEWORKS)
+ if(APPLE)
+ foreach(dir
+ ~/Library/Frameworks/${fwk}.framework
+ /Library/Frameworks/${fwk}.framework
+ /System/Library/Frameworks/${fwk}.framework
+ /Network/Library/Frameworks/${fwk}.framework)
+ if(EXISTS ${dir})
+ set(${fwk}_FRAMEWORKS ${${fwk}_FRAMEWORKS} ${dir})
+ endif()
+ endforeach()
+ endif()
+ endmacro()
+endif()
diff --git a/Modules/CMakeFindJavaCommon.cmake b/Modules/CMakeFindJavaCommon.cmake
new file mode 100644
index 0000000000..fcf038970b
--- /dev/null
+++ b/Modules/CMakeFindJavaCommon.cmake
@@ -0,0 +1,41 @@
+
+#=============================================================================
+# Copyright 2013-2014 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.)
+
+# Do not include this module directly from code outside CMake!
+set(_JAVA_HOME "")
+if(JAVA_HOME AND IS_DIRECTORY "${JAVA_HOME}")
+ set(_JAVA_HOME "${JAVA_HOME}")
+ set(_JAVA_HOME_EXPLICIT 1)
+else()
+ set(_ENV_JAVA_HOME "")
+ if(DEFINED ENV{JAVA_HOME})
+ file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _ENV_JAVA_HOME)
+ endif()
+ if(_ENV_JAVA_HOME AND IS_DIRECTORY "${_ENV_JAVA_HOME}")
+ set(_JAVA_HOME "${_ENV_JAVA_HOME}")
+ set(_JAVA_HOME_EXPLICIT 1)
+ else()
+ set(_CMD_JAVA_HOME "")
+ if(APPLE AND EXISTS /usr/libexec/java_home)
+ execute_process(COMMAND /usr/libexec/java_home
+ OUTPUT_VARIABLE _CMD_JAVA_HOME OUTPUT_STRIP_TRAILING_WHITESPACE)
+ endif()
+ if(_CMD_JAVA_HOME AND IS_DIRECTORY "${_CMD_JAVA_HOME}")
+ set(_JAVA_HOME "${_CMD_JAVA_HOME}")
+ set(_JAVA_HOME_EXPLICIT 0)
+ endif()
+ unset(_CMD_JAVA_HOME)
+ endif()
+ unset(_ENV_JAVA_HOME)
+endif()
diff --git a/Modules/CMakeFindKDevelop3.cmake b/Modules/CMakeFindKDevelop3.cmake
new file mode 100644
index 0000000000..2abd52376f
--- /dev/null
+++ b/Modules/CMakeFindKDevelop3.cmake
@@ -0,0 +1,23 @@
+
+#=============================================================================
+# Copyright 2009 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 is included in CMakeSystemSpecificInformation.cmake if
+# the KDevelop3 extra generator has been selected.
+
+find_program(CMAKE_KDEVELOP3_EXECUTABLE NAMES kdevelop DOC "The KDevelop3 executable")
+
+if(CMAKE_KDEVELOP3_EXECUTABLE)
+ set(CMAKE_OPEN_PROJECT_COMMAND "${CMAKE_KDEVELOP3_EXECUTABLE} <PROJECT_FILE>" )
+endif()
+
diff --git a/Modules/CMakeFindKate.cmake b/Modules/CMakeFindKate.cmake
new file mode 100644
index 0000000000..4dcdb28410
--- /dev/null
+++ b/Modules/CMakeFindKate.cmake
@@ -0,0 +1,31 @@
+
+#=============================================================================
+# Copyright 2009 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 is included in CMakeSystemSpecificInformation.cmake if
+# the Eclipse CDT4 extra generator has been selected.
+
+
+# Try to find out how many CPUs we have and set the -j argument for make accordingly
+
+include(ProcessorCount)
+processorcount(_CMAKE_KATE_PROCESSOR_COUNT)
+
+# Only set -j if we are under UNIX and if the make-tool used actually has "make" in the name
+# (we may also get here in the future e.g. for ninja)
+if("${_CMAKE_KATE_PROCESSOR_COUNT}" GREATER 1 AND CMAKE_HOST_UNIX AND "${CMAKE_MAKE_PROGRAM}" MATCHES make)
+ set(_CMAKE_KATE_INITIAL_MAKE_ARGS "-j${_CMAKE_KATE_PROCESSOR_COUNT}")
+endif()
+
+# This variable is used by the Eclipse generator and appended to the make invocation commands.
+set(CMAKE_KATE_MAKE_ARGUMENTS "${_CMAKE_KATE_INITIAL_MAKE_ARGS}" CACHE STRING "Additional command line arguments when Kate invokes make. Enter e.g. -j<some_number> to get parallel builds")
diff --git a/Modules/CMakeFindPackageMode.cmake b/Modules/CMakeFindPackageMode.cmake
new file mode 100644
index 0000000000..9f97ee5728
--- /dev/null
+++ b/Modules/CMakeFindPackageMode.cmake
@@ -0,0 +1,199 @@
+#.rst:
+# CMakeFindPackageMode
+# --------------------
+#
+#
+#
+# This file is executed by cmake when invoked with --find-package. It
+# expects that the following variables are set using -D:
+#
+# ::
+#
+# NAME = name of the package
+# COMPILER_ID = the CMake compiler ID for which the result is, i.e. GNU/Intel/Clang/MSVC, etc.
+# LANGUAGE = language for which the result will be used, i.e. C/CXX/Fortan/ASM
+# MODE = EXIST : only check for existence of the given package
+# COMPILE : print the flags needed for compiling an object file which uses the given package
+# LINK : print the flags needed for linking when using the given package
+# QUIET = if TRUE, don't print anything
+
+#=============================================================================
+# Copyright 2006-2011 Alexander Neundorf, <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+if(NOT NAME)
+ message(FATAL_ERROR "Name of the package to be searched not specified. Set the CMake variable NAME, e.g. -DNAME=JPEG .")
+endif()
+
+if(NOT COMPILER_ID)
+ message(FATAL_ERROR "COMPILER_ID argument not specified. In doubt, use GNU.")
+endif()
+
+if(NOT LANGUAGE)
+ message(FATAL_ERROR "LANGUAGE argument not specified. Use C, CXX or Fortran.")
+endif()
+
+if(NOT MODE)
+ message(FATAL_ERROR "MODE argument not specified. Use either EXIST, COMPILE or LINK.")
+endif()
+
+# require the current version. If we don't do this, Platforms/CYGWIN.cmake complains because
+# it doesn't know whether it should set WIN32 or not:
+cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} )
+
+macro(ENABLE_LANGUAGE)
+ # disable the enable_language() command, otherwise --find-package breaks on Windows.
+ # On Windows, enable_language(RC) is called in the platform files unconditionally.
+ # But in --find-package mode, we don't want (and can't) enable any language.
+endmacro()
+
+set(CMAKE_PLATFORM_INFO_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY})
+
+include(CMakeDetermineSystem)
+
+# short-cut some tests on Darwin, see Darwin-GNU.cmake:
+if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin AND "${COMPILER_ID}" MATCHES GNU)
+ set(CMAKE_${LANGUAGE}_SYSROOT_FLAG "")
+ set(CMAKE_${LANGUAGE}_OSX_DEPLOYMENT_TARGET_FLAG "")
+endif()
+
+# Also load the system specific file, which sets up e.g. the search paths.
+# This makes the FIND_XXX() calls work much better
+include(CMakeSystemSpecificInformation)
+
+if(UNIX)
+
+ # try to guess whether we have a 64bit system, if it has not been set
+ # from the outside
+ if(NOT CMAKE_SIZEOF_VOID_P)
+ set(CMAKE_SIZEOF_VOID_P 4)
+ if(EXISTS /usr/lib64)
+ set(CMAKE_SIZEOF_VOID_P 8)
+ else()
+ # use the file utility to check whether itself is 64 bit:
+ find_program(FILE_EXECUTABLE file)
+ if(FILE_EXECUTABLE)
+ get_filename_component(FILE_ABSPATH "${FILE_EXECUTABLE}" ABSOLUTE)
+ execute_process(COMMAND "${FILE_ABSPATH}" "${FILE_ABSPATH}" OUTPUT_VARIABLE fileOutput ERROR_QUIET)
+ if("${fileOutput}" MATCHES "64-bit")
+ set(CMAKE_SIZEOF_VOID_P 8)
+ endif()
+ endif()
+ endif()
+ endif()
+
+ # guess Debian multiarch if it has not been set:
+ if(EXISTS /etc/debian_version)
+ if(NOT CMAKE_${LANGUAGE}_LANGUAGE_ARCHITECTURE )
+ file(GLOB filesInLib RELATIVE /lib /lib/*-linux-gnu* )
+ foreach(file ${filesInLib})
+ if("${file}" MATCHES "${CMAKE_LIBRARY_ARCHITECTURE_REGEX}")
+ set(CMAKE_${LANGUAGE}_LANGUAGE_ARCHITECTURE ${file})
+ break()
+ endif()
+ endforeach()
+ endif()
+ endif()
+
+endif()
+
+set(CMAKE_${LANGUAGE}_COMPILER "dummy")
+set(CMAKE_${LANGUAGE}_COMPILER_ID "${COMPILER_ID}")
+include(CMake${LANGUAGE}Information)
+
+
+function(set_compile_flags_var _packageName)
+ string(TOUPPER "${_packageName}" PACKAGE_NAME)
+ # Check the following variables:
+ # FOO_INCLUDE_DIRS
+ # Foo_INCLUDE_DIRS
+ # FOO_INCLUDES
+ # Foo_INCLUDES
+ # FOO_INCLUDE_DIR
+ # Foo_INCLUDE_DIR
+ set(includes)
+ if(DEFINED ${_packageName}_INCLUDE_DIRS)
+ set(includes ${_packageName}_INCLUDE_DIRS)
+ elseif(DEFINED ${PACKAGE_NAME}_INCLUDE_DIRS)
+ set(includes ${PACKAGE_NAME}_INCLUDE_DIRS)
+ elseif(DEFINED ${_packageName}_INCLUDES)
+ set(includes ${_packageName}_INCLUDES)
+ elseif(DEFINED ${PACKAGE_NAME}_INCLUDES)
+ set(includes ${PACKAGE_NAME}_INCLUDES)
+ elseif(DEFINED ${_packageName}_INCLUDE_DIR)
+ set(includes ${_packageName}_INCLUDE_DIR)
+ elseif(DEFINED ${PACKAGE_NAME}_INCLUDE_DIR)
+ set(includes ${PACKAGE_NAME}_INCLUDE_DIR)
+ endif()
+
+ set(PACKAGE_INCLUDE_DIRS "${${includes}}" PARENT_SCOPE)
+
+ # Check the following variables:
+ # FOO_DEFINITIONS
+ # Foo_DEFINITIONS
+ set(definitions)
+ if(DEFINED ${_packageName}_DEFINITIONS)
+ set(definitions ${_packageName}_DEFINITIONS)
+ elseif(DEFINED ${PACKAGE_NAME}_DEFINITIONS)
+ set(definitions ${PACKAGE_NAME}_DEFINITIONS)
+ endif()
+
+ set(PACKAGE_DEFINITIONS "${${definitions}}" )
+
+endfunction()
+
+
+function(set_link_flags_var _packageName)
+ string(TOUPPER "${_packageName}" PACKAGE_NAME)
+ # Check the following variables:
+ # FOO_LIBRARIES
+ # Foo_LIBRARIES
+ # FOO_LIBS
+ # Foo_LIBS
+ set(libs)
+ if(DEFINED ${_packageName}_LIBRARIES)
+ set(libs ${_packageName}_LIBRARIES)
+ elseif(DEFINED ${PACKAGE_NAME}_LIBRARIES)
+ set(libs ${PACKAGE_NAME}_LIBRARIES)
+ elseif(DEFINED ${_packageName}_LIBS)
+ set(libs ${_packageName}_LIBS)
+ elseif(DEFINED ${PACKAGE_NAME}_LIBS)
+ set(libs ${PACKAGE_NAME}_LIBS)
+ endif()
+
+ set(PACKAGE_LIBRARIES "${${libs}}" PARENT_SCOPE )
+
+endfunction()
+
+
+find_package("${NAME}" QUIET)
+
+set(PACKAGE_FOUND FALSE)
+
+string(TOUPPER "${NAME}" UPPERCASE_NAME)
+
+if(${NAME}_FOUND OR ${UPPERCASE_NAME}_FOUND)
+ set(PACKAGE_FOUND TRUE)
+
+ if("${MODE}" STREQUAL "EXIST")
+ # do nothing
+ elseif("${MODE}" STREQUAL "COMPILE")
+ set_compile_flags_var(${NAME})
+ elseif("${MODE}" STREQUAL "LINK")
+ set_link_flags_var(${NAME})
+ else()
+ message(FATAL_ERROR "Invalid mode argument ${MODE} given.")
+ endif()
+
+endif()
+
+set(PACKAGE_QUIET ${SILENT} )
diff --git a/Modules/CMakeFindWMake.cmake b/Modules/CMakeFindWMake.cmake
new file mode 100644
index 0000000000..60275aea4e
--- /dev/null
+++ b/Modules/CMakeFindWMake.cmake
@@ -0,0 +1,17 @@
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+set (CMAKE_MAKE_PROGRAM "wmake" CACHE STRING
+ "Program used to build from makefiles.")
+mark_as_advanced(CMAKE_MAKE_PROGRAM)
diff --git a/Modules/CMakeFindXCode.cmake b/Modules/CMakeFindXCode.cmake
new file mode 100644
index 0000000000..5c4f596393
--- /dev/null
+++ b/Modules/CMakeFindXCode.cmake
@@ -0,0 +1,20 @@
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+find_program(CMAKE_MAKE_PROGRAM
+ NAMES xcodebuild
+ PATHS
+ /usr/bin
+ )
+mark_as_advanced(CMAKE_MAKE_PROGRAM)
diff --git a/Modules/CMakeForceCompiler.cmake b/Modules/CMakeForceCompiler.cmake
new file mode 100644
index 0000000000..0e6b5af3cb
--- /dev/null
+++ b/Modules/CMakeForceCompiler.cmake
@@ -0,0 +1,100 @@
+#.rst:
+# CMakeForceCompiler
+# ------------------
+#
+#
+#
+# This module defines macros intended for use by cross-compiling
+# toolchain files when CMake is not able to automatically detect the
+# compiler identification.
+#
+# Macro CMAKE_FORCE_C_COMPILER has the following signature:
+#
+# ::
+#
+# CMAKE_FORCE_C_COMPILER(<compiler> <compiler-id>)
+#
+# It sets CMAKE_C_COMPILER to the given compiler and the cmake internal
+# variable CMAKE_C_COMPILER_ID to the given compiler-id. It also
+# bypasses the check for working compiler and basic compiler information
+# tests.
+#
+# Macro CMAKE_FORCE_CXX_COMPILER has the following signature:
+#
+# ::
+#
+# CMAKE_FORCE_CXX_COMPILER(<compiler> <compiler-id>)
+#
+# It sets CMAKE_CXX_COMPILER to the given compiler and the cmake
+# internal variable CMAKE_CXX_COMPILER_ID to the given compiler-id. It
+# also bypasses the check for working compiler and basic compiler
+# information tests.
+#
+# Macro CMAKE_FORCE_Fortran_COMPILER has the following signature:
+#
+# ::
+#
+# CMAKE_FORCE_Fortran_COMPILER(<compiler> <compiler-id>)
+#
+# It sets CMAKE_Fortran_COMPILER to the given compiler and the cmake
+# internal variable CMAKE_Fortran_COMPILER_ID to the given compiler-id.
+# It also bypasses the check for working compiler and basic compiler
+# information tests.
+#
+# So a simple toolchain file could look like this:
+#
+# ::
+#
+# include (CMakeForceCompiler)
+# set(CMAKE_SYSTEM_NAME Generic)
+# CMAKE_FORCE_C_COMPILER (chc12 MetrowerksHicross)
+# CMAKE_FORCE_CXX_COMPILER (chc12 MetrowerksHicross)
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+macro(CMAKE_FORCE_C_COMPILER compiler id)
+ set(CMAKE_C_COMPILER "${compiler}")
+ set(CMAKE_C_COMPILER_ID_RUN TRUE)
+ set(CMAKE_C_COMPILER_ID ${id})
+ set(CMAKE_C_COMPILER_FORCED TRUE)
+
+ # Set old compiler id variables.
+ if("${CMAKE_C_COMPILER_ID}" MATCHES "GNU")
+ set(CMAKE_COMPILER_IS_GNUCC 1)
+ endif()
+endmacro()
+
+macro(CMAKE_FORCE_CXX_COMPILER compiler id)
+ set(CMAKE_CXX_COMPILER "${compiler}")
+ set(CMAKE_CXX_COMPILER_ID_RUN TRUE)
+ set(CMAKE_CXX_COMPILER_ID ${id})
+ set(CMAKE_CXX_COMPILER_FORCED TRUE)
+
+ # Set old compiler id variables.
+ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
+ set(CMAKE_COMPILER_IS_GNUCXX 1)
+ endif()
+endmacro()
+
+macro(CMAKE_FORCE_Fortran_COMPILER compiler id)
+ set(CMAKE_Fortran_COMPILER "${compiler}")
+ set(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
+ set(CMAKE_Fortran_COMPILER_ID ${id})
+ set(CMAKE_Fortran_COMPILER_FORCED TRUE)
+
+ # Set old compiler id variables.
+ if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
+ set(CMAKE_COMPILER_IS_GNUG77 1)
+ endif()
+endmacro()
diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in
new file mode 100644
index 0000000000..e4c76180a5
--- /dev/null
+++ b/Modules/CMakeFortranCompiler.cmake.in
@@ -0,0 +1,57 @@
+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_PLATFORM_ID "@CMAKE_Fortran_PLATFORM_ID@")
+set(CMAKE_Fortran_SIMULATE_ID "@CMAKE_Fortran_SIMULATE_ID@")
+set(CMAKE_Fortran_SIMULATE_VERSION "@CMAKE_Fortran_SIMULATE_VERSION@")
+@SET_MSVC_Fortran_ARCHITECTURE_ID@
+set(CMAKE_AR "@CMAKE_AR@")
+set(CMAKE_RANLIB "@CMAKE_RANLIB@")
+set(CMAKE_COMPILER_IS_GNUG77 @CMAKE_COMPILER_IS_GNUG77@)
+set(CMAKE_Fortran_COMPILER_LOADED 1)
+set(CMAKE_Fortran_COMPILER_WORKS @CMAKE_Fortran_COMPILER_WORKS@)
+set(CMAKE_Fortran_ABI_COMPILED @CMAKE_Fortran_ABI_COMPILED@)
+set(CMAKE_COMPILER_IS_MINGW @CMAKE_COMPILER_IS_MINGW@)
+set(CMAKE_COMPILER_IS_CYGWIN @CMAKE_COMPILER_IS_CYGWIN@)
+if(CMAKE_COMPILER_IS_CYGWIN)
+ set(CYGWIN 1)
+ set(UNIX 1)
+endif()
+
+set(CMAKE_Fortran_COMPILER_ENV_VAR "FC")
+
+set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 @CMAKE_Fortran_COMPILER_SUPPORTS_F90@)
+
+if(CMAKE_COMPILER_IS_MINGW)
+ set(MINGW 1)
+endif()
+set(CMAKE_Fortran_COMPILER_ID_RUN 1)
+set(CMAKE_Fortran_SOURCE_FILE_EXTENSIONS f;F;f77;F77;f90;F90;for;For;FOR;f95;F95)
+set(CMAKE_Fortran_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC)
+set(CMAKE_Fortran_LINKER_PREFERENCE 20)
+if(UNIX)
+ set(CMAKE_Fortran_OUTPUT_EXTENSION .o)
+else()
+ set(CMAKE_Fortran_OUTPUT_EXTENSION .obj)
+endif()
+
+# Save compiler ABI information.
+set(CMAKE_Fortran_SIZEOF_DATA_PTR "@CMAKE_Fortran_SIZEOF_DATA_PTR@")
+set(CMAKE_Fortran_COMPILER_ABI "@CMAKE_Fortran_COMPILER_ABI@")
+set(CMAKE_Fortran_LIBRARY_ARCHITECTURE "@CMAKE_Fortran_LIBRARY_ARCHITECTURE@")
+
+if(CMAKE_Fortran_SIZEOF_DATA_PTR AND NOT CMAKE_SIZEOF_VOID_P)
+ set(CMAKE_SIZEOF_VOID_P "${CMAKE_Fortran_SIZEOF_DATA_PTR}")
+endif()
+
+if(CMAKE_Fortran_COMPILER_ABI)
+ set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_Fortran_COMPILER_ABI}")
+endif()
+
+if(CMAKE_Fortran_LIBRARY_ARCHITECTURE)
+ set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_Fortran_LIBRARY_ARCHITECTURE@")
+endif()
+
+set(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "@CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES@")
+set(CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES "@CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES@")
+set(CMAKE_Fortran_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_Fortran_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@")
diff --git a/Modules/CMakeFortranCompilerABI.F b/Modules/CMakeFortranCompilerABI.F
new file mode 100644
index 0000000000..b34c284843
--- /dev/null
+++ b/Modules/CMakeFortranCompilerABI.F
@@ -0,0 +1,46 @@
+ PROGRAM CMakeFortranCompilerABI
+#if 0
+! Address Size
+#endif
+#if defined(_LP64)
+ PRINT *, 'INFO:sizeof_dptr[8]'
+#elif defined(_M_IA64)
+ PRINT *, 'INFO:sizeof_dptr[8]'
+#elif defined(_M_X64)
+ PRINT *, 'INFO:sizeof_dptr[8]'
+#elif defined(_M_AMD64)
+ PRINT *, 'INFO:sizeof_dptr[8]'
+#elif defined(__x86_64__)
+ PRINT *, 'INFO:sizeof_dptr[8]'
+
+#elif defined(_ILP32)
+ PRINT *, 'INFO:sizeof_dptr[4]'
+#elif defined(_M_IX86)
+ PRINT *, 'INFO:sizeof_dptr[4]'
+#elif defined(__i386__)
+ PRINT *, 'INFO:sizeof_dptr[4]'
+
+#elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8
+ PRINT *, 'INFO:sizeof_dptr[8]'
+#elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4
+ PRINT *, 'INFO:sizeof_dptr[4]'
+#elif defined(__SIZEOF_SIZE_T__) && __SIZEOF_SIZE_T__ == 8
+ PRINT *, 'INFO:sizeof_dptr[8]'
+#elif defined(__SIZEOF_SIZE_T__) && __SIZEOF_SIZE_T__ == 4
+ PRINT *, 'INFO:sizeof_dptr[4]'
+#endif
+
+#if 0
+! Application Binary Interface
+#endif
+#if defined(__sgi) && defined(_ABIO32)
+ PRINT *, 'INFO:abi[ELF O32]'
+#elif defined(__sgi) && defined(_ABIN32)
+ PRINT *, 'INFO:abi[ELF N32]'
+#elif defined(__sgi) && defined(_ABI64)
+ PRINT *, 'INFO:abi[ELF 64]'
+#elif defined(__ELF__)
+ PRINT *, 'INFO:abi[ELF]'
+#endif
+ PRINT *, 'ABI Detection'
+ END
diff --git a/Modules/CMakeFortranCompilerId.F.in b/Modules/CMakeFortranCompilerId.F.in
new file mode 100644
index 0000000000..53495051db
--- /dev/null
+++ b/Modules/CMakeFortranCompilerId.F.in
@@ -0,0 +1,137 @@
+ PROGRAM CMakeFortranCompilerId
+#if 0
+! Identify the compiler
+#endif
+#if defined(__INTEL_COMPILER) || defined(__ICC)
+ PRINT *, 'INFO:compiler[Intel]'
+# if defined(_MSC_VER)
+ PRINT *, 'INFO:simulate[MSVC]'
+# if _MSC_VER >= 1800
+ PRINT *, 'INFO:simulate_version[018.00]'
+# elif _MSC_VER >= 1700
+ PRINT *, 'INFO:simulate_version[017.00]'
+# elif _MSC_VER >= 1600
+ PRINT *, 'INFO:simulate_version[016.00]'
+# elif _MSC_VER >= 1500
+ PRINT *, 'INFO:simulate_version[015.00]'
+# elif _MSC_VER >= 1400
+ PRINT *, 'INFO:simulate_version[014.00]'
+# elif _MSC_VER >= 1310
+ PRINT *, 'INFO:simulate_version[013.01]'
+# else
+ PRINT *, 'INFO:simulate_version[013.00]'
+# endif
+# endif
+#elif defined(__SUNPRO_F90) || defined(__SUNPRO_F95)
+ PRINT *, 'INFO:compiler[SunPro]'
+#elif defined(_CRAYFTN)
+ PRINT *, 'INFO:compiler[Cray]'
+#elif defined(__G95__)
+ PRINT *, 'INFO:compiler[G95]'
+#elif defined(__PATHSCALE__)
+ PRINT *, 'INFO:compiler[PathScale]'
+#elif defined(__ABSOFT__)
+ PRINT *, 'INFO:compiler[Absoft]'
+#elif defined(__GNUC__)
+ PRINT *, 'INFO:compiler[GNU]'
+#elif defined(__IBMC__)
+# if defined(__COMPILER_VER__)
+ PRINT *, 'INFO:compiler[zOS]'
+# elif __IBMC__ >= 800
+ PRINT *, 'INFO:compiler[XL]'
+# else
+ PRINT *, 'INFO:compiler[VisualAge]'
+# endif
+#elif defined(__PGI)
+ PRINT *, 'INFO:compiler[PGI]'
+#elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION)
+ PRINT *, 'INFO:compiler[MIPSpro]'
+# if 0
+! This compiler is either not known or is too old to define an
+! identification macro. Try to identify the platform and guess that
+! it is the native compiler.
+# endif
+#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
+ PRINT *, 'INFO:compiler[VisualAge]'
+#elif defined(__sgi) || defined(__sgi__) || defined(_SGI)
+ PRINT *, 'INFO:compiler[MIPSpro]'
+#elif defined(__hpux) || defined(__hpux__)
+ PRINT *, 'INFO:compiler[HP]'
+#elif 1
+# if 0
+! The above 'elif 1' instead of 'else' is to work around a bug in the
+! SGI preprocessor which produces both the __sgi and else blocks.
+# endif
+ PRINT *, 'INFO:compiler[]'
+#endif
+
+#if 0
+! Identify the platform
+#endif
+#if defined(__linux) || defined(__linux__) || defined(linux)
+ PRINT *, 'INFO:platform[Linux]'
+#elif defined(__CYGWIN__)
+ PRINT *, 'INFO:platform[Cygwin]'
+#elif defined(__MINGW32__)
+ PRINT *, 'INFO:platform[MinGW]'
+#elif defined(__APPLE__)
+ PRINT *, 'INFO:platform[Darwin]'
+#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+ PRINT *, 'INFO:platform[Windows]'
+#elif defined(__FreeBSD__) || defined(__FreeBSD)
+ PRINT *, 'INFO:platform[FreeBSD]'
+#elif defined(__NetBSD__) || defined(__NetBSD)
+ PRINT *, 'INFO:platform[NetBSD]'
+#elif defined(__OpenBSD__) || defined(__OPENBSD)
+ PRINT *, 'INFO:platform[OpenBSD]'
+#elif defined(__sun) || defined(sun)
+ PRINT *, 'INFO:platform[SunOS]'
+#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
+ PRINT *, 'INFO:platform[AIX]'
+#elif defined(__sgi) || defined(__sgi__) || defined(_SGI)
+ PRINT *, 'INFO:platform[IRIX]'
+#elif defined(__hpux) || defined(__hpux__)
+ PRINT *, 'INFO:platform[HP-UX]'
+#elif defined(__HAIKU__)
+ PRINT *, 'INFO:platform[Haiku]'
+#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
+ PRINT *, 'INFO:platform[BeOS]'
+#elif defined(__QNX__) || defined(__QNXNTO__)
+ PRINT *, 'INFO:platform[QNX]'
+#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__)
+ PRINT *, 'INFO:platform[Tru64]'
+#elif defined(__riscos) || defined(__riscos__)
+ PRINT *, 'INFO:platform[RISCos]'
+#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__)
+ PRINT *, 'INFO:platform[SINIX]'
+#elif defined(__UNIX_SV__)
+ PRINT *, 'INFO:platform[UNIX_SV]'
+#elif defined(__bsdos__)
+ PRINT *, 'INFO:platform[BSDOS]'
+#elif defined(_MPRAS) || defined(MPRAS)
+ PRINT *, 'INFO:platform[MP-RAS]'
+#elif defined(__osf) || defined(__osf__)
+ PRINT *, 'INFO:platform[OSF1]'
+#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv)
+ PRINT *, 'INFO:platform[SCO_SV]'
+#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX)
+ PRINT *, 'INFO:platform[ULTRIX]'
+#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX)
+ PRINT *, 'INFO:platform[Xenix]'
+#elif 1
+# if 0
+! The above 'elif 1' instead of 'else' is to work around a bug in the
+! SGI preprocessor which produces both the __sgi and else blocks.
+# endif
+ PRINT *, 'INFO:platform[]'
+#endif
+#if defined(_WIN32) && (defined(__INTEL_COMPILER) || defined(__ICC))
+# if defined(_M_IA64)
+ PRINT *, 'INFO:arch[IA64]'
+# elif defined(_M_X64) || defined(_M_AMD64)
+ PRINT *, 'INFO:arch[x64]'
+# elif defined(_M_IX86)
+ PRINT *, 'INFO:arch[X86]'
+# endif
+#endif
+ END
diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake
new file mode 100644
index 0000000000..d6382078b7
--- /dev/null
+++ b/Modules/CMakeFortranInformation.cmake
@@ -0,0 +1,245 @@
+
+#=============================================================================
+# Copyright 2004-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# 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.
+
+set(_INCLUDED_FILE 0)
+
+# Load compiler-specific information.
+if(CMAKE_Fortran_COMPILER_ID)
+ include(Compiler/${CMAKE_Fortran_COMPILER_ID}-Fortran OPTIONAL)
+endif()
+
+set(CMAKE_BASE_NAME)
+get_filename_component(CMAKE_BASE_NAME "${CMAKE_Fortran_COMPILER}" NAME_WE)
+# since the gnu compiler has several names force g++
+if(CMAKE_COMPILER_IS_GNUG77)
+ set(CMAKE_BASE_NAME g77)
+endif()
+if(CMAKE_Fortran_COMPILER_ID)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
+endif()
+if (NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
+ RESULT_VARIABLE _INCLUDED_FILE)
+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.
+# Remove this when all compiler info is removed from system files.
+if (NOT _INCLUDED_FILE)
+ include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
+endif ()
+
+if(CMAKE_Fortran_SIZEOF_DATA_PTR)
+ foreach(f ${CMAKE_Fortran_ABI_FILES})
+ include(${f})
+ endforeach()
+ unset(CMAKE_Fortran_ABI_FILES)
+endif()
+
+# This should be included before the _INIT variables are
+# used to initialize the cache. Since the rule variables
+# have if blocks on them, users can still define them here.
+# But, it should still be after the platform file so changes can
+# be made to those values.
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
+endif()
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran "${_override}")
+endif()
+
+
+# Fortran needs cmake to do a requires step during its build process to
+# catch any modules
+set(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
+
+if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
+ set(CMAKE_Fortran_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
+endif()
+
+if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIE)
+ set(CMAKE_Fortran_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
+endif()
+
+if(NOT CMAKE_Fortran_COMPILE_OPTIONS_DLL)
+ set(CMAKE_Fortran_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL})
+endif()
+
+# Create a set of shared library variable specific to Fortran
+# For 90% of the systems, these are the same flags as the C versions
+# so if these are not set just copy the flags from the c version
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
+ set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
+ set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
+ set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
+ set(CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
+endif()
+
+if(NOT DEFINED CMAKE_EXE_EXPORTS_Fortran_FLAG)
+ set(CMAKE_EXE_EXPORTS_Fortran_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG)
+ set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
+endif()
+
+# for most systems a module is the same as a shared library
+# so unless the variable CMAKE_MODULE_EXISTS is set just
+# copy the values from the LIBRARY variables
+if(NOT CMAKE_MODULE_EXISTS)
+ set(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_Fortran_FLAGS})
+ set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS})
+endif()
+
+# repeat for modules
+if(NOT DEFINED CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
+ set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_MODULE_Fortran_FLAGS)
+ set(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
+endif()
+
+if(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
+ set(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG})
+endif()
+
+if(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
+ set(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP})
+endif()
+
+if(NOT DEFINED CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
+ set(CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG})
+endif()
+
+if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
+ set(CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
+endif()
+
+if(NOT CMAKE_INCLUDE_FLAG_Fortran)
+ set(CMAKE_INCLUDE_FLAG_Fortran ${CMAKE_INCLUDE_FLAG_C})
+endif()
+
+if(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
+ set(CMAKE_INCLUDE_FLAG_SEP_Fortran ${CMAKE_INCLUDE_FLAG_SEP_C})
+endif()
+
+set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.")
+
+set(CMAKE_Fortran_FLAGS_INIT "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
+# avoid just having a space as the initial value for the cache
+if(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
+ set(CMAKE_Fortran_FLAGS_INIT)
+endif()
+set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING
+ "Flags for Fortran compiler.")
+
+include(CMakeCommonLanguageInclude)
+
+# now define the following rule variables
+# CMAKE_Fortran_CREATE_SHARED_LIBRARY
+# CMAKE_Fortran_CREATE_SHARED_MODULE
+# CMAKE_Fortran_COMPILE_OBJECT
+# CMAKE_Fortran_LINK_EXECUTABLE
+
+# create a Fortran shared library
+if(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
+ set(CMAKE_Fortran_CREATE_SHARED_LIBRARY
+ "<CMAKE_Fortran_COMPILER> <CMAKE_SHARED_LIBRARY_Fortran_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+endif()
+
+# create a Fortran shared module just copy the shared library rule
+if(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
+ set(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
+endif()
+
+# Create a static archive incrementally for large object file counts.
+# If CMAKE_Fortran_CREATE_STATIC_LIBRARY is set it will override these.
+if(NOT DEFINED CMAKE_Fortran_ARCHIVE_CREATE)
+ set(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> cq <TARGET> <LINK_FLAGS> <OBJECTS>")
+endif()
+if(NOT DEFINED CMAKE_Fortran_ARCHIVE_APPEND)
+ set(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
+endif()
+if(NOT DEFINED CMAKE_Fortran_ARCHIVE_FINISH)
+ set(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
+endif()
+
+# compile a Fortran file into an object file
+# (put -o after -c to workaround bug in at least one mpif77 wrapper)
+if(NOT CMAKE_Fortran_COMPILE_OBJECT)
+ set(CMAKE_Fortran_COMPILE_OBJECT
+ "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -c <SOURCE> -o <OBJECT>")
+endif()
+
+# link a fortran program
+if(NOT CMAKE_Fortran_LINK_EXECUTABLE)
+ set(CMAKE_Fortran_LINK_EXECUTABLE
+ "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+endif()
+
+if(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
+ set(CMAKE_Fortran_STANDARD_LIBRARIES "${CMAKE_Fortran_STANDARD_LIBRARIES_INIT}"
+ CACHE STRING "Libraries linked by default with all Fortran applications.")
+ mark_as_advanced(CMAKE_Fortran_STANDARD_LIBRARIES)
+endif()
+
+if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
+ set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG_INIT}" CACHE STRING
+ "Flags used by the compiler during debug builds.")
+ set (CMAKE_Fortran_FLAGS_MINSIZEREL "${CMAKE_Fortran_FLAGS_MINSIZEREL_INIT}" CACHE STRING
+ "Flags used by the compiler during release builds for minimum size.")
+ set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE_INIT}" CACHE STRING
+ "Flags used by the compiler during release builds.")
+ set (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
+ "Flags used by the compiler during release builds with debug info.")
+
+endif()
+
+mark_as_advanced(
+CMAKE_Fortran_FLAGS
+CMAKE_Fortran_FLAGS_DEBUG
+CMAKE_Fortran_FLAGS_MINSIZEREL
+CMAKE_Fortran_FLAGS_RELEASE
+CMAKE_Fortran_FLAGS_RELWITHDEBINFO)
+
+# set this variable so we can avoid loading this more than once.
+set(CMAKE_Fortran_INFORMATION_LOADED 1)
diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake
new file mode 100644
index 0000000000..8a14aea604
--- /dev/null
+++ b/Modules/CMakeGenericSystem.cmake
@@ -0,0 +1,187 @@
+
+#=============================================================================
+# Copyright 2004-2009 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.)
+
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "") # -pic
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "") # -rpath
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "") # : or empty
+set(CMAKE_INCLUDE_FLAG_C "-I") # -I
+set(CMAKE_INCLUDE_FLAG_C_SEP "") # , or empty
+set(CMAKE_LIBRARY_PATH_FLAG "-L")
+set(CMAKE_LIBRARY_PATH_TERMINATOR "") # for the Digital Mars D compiler the link paths have to be terminated with a "/"
+set(CMAKE_LINK_LIBRARY_FLAG "-l")
+
+set(CMAKE_LINK_LIBRARY_SUFFIX "")
+set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+set(CMAKE_SHARED_LIBRARY_PREFIX "lib") # lib
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") # .so
+set(CMAKE_EXECUTABLE_SUFFIX "") # .exe
+set(CMAKE_DL_LIBS "dl")
+
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
+
+# basically all general purpose OSs support shared libs
+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
+
+set (CMAKE_SKIP_RPATH "NO" CACHE BOOL
+ "If set, runtime paths are not added when using shared libraries.")
+set (CMAKE_SKIP_INSTALL_RPATH "NO" CACHE BOOL
+ "If set, runtime paths are not added when installing shared libraries, but are added when building.")
+
+set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.")
+
+if(CMAKE_GENERATOR MATCHES "Makefiles")
+ set(CMAKE_COLOR_MAKEFILE ON CACHE BOOL
+ "Enable/Disable color output during build."
+ )
+ mark_as_advanced(CMAKE_COLOR_MAKEFILE)
+ if(DEFINED CMAKE_RULE_MESSAGES)
+ set_property(GLOBAL PROPERTY RULE_MESSAGES ${CMAKE_RULE_MESSAGES})
+ endif()
+ if(CMAKE_GENERATOR MATCHES "Unix Makefiles")
+ set(CMAKE_EXPORT_COMPILE_COMMANDS OFF CACHE BOOL
+ "Enable/Disable output of compile commands during generation."
+ )
+ mark_as_advanced(CMAKE_EXPORT_COMPILE_COMMANDS)
+ endif()
+endif()
+
+if(CMAKE_GENERATOR MATCHES "Ninja")
+ set(CMAKE_EXPORT_COMPILE_COMMANDS OFF CACHE BOOL
+ "Enable/Disable output of compile commands during generation."
+ )
+ mark_as_advanced(CMAKE_EXPORT_COMPILE_COMMANDS)
+endif()
+
+# GetDefaultWindowsPrefixBase
+#
+# Compute the base directory for CMAKE_INSTALL_PREFIX based on:
+# - is this 32-bit or 64-bit Windows
+# - is this 32-bit or 64-bit CMake running
+# - what architecture targets will be built
+#
+function(GetDefaultWindowsPrefixBase var)
+
+ # Try to guess what architecture targets will end up being built as,
+ # even if CMAKE_SIZEOF_VOID_P is not computed yet... We need to know
+ # the architecture of the targets being built to choose the right
+ # default value for CMAKE_INSTALL_PREFIX.
+ #
+ if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
+ set(arch_hint "x64")
+ elseif("${CMAKE_GENERATOR}" MATCHES "ARM")
+ set(arch_hint "ARM")
+ elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
+ set(arch_hint "x64")
+ elseif("$ENV{LIB}" MATCHES "(amd64|ia64)")
+ set(arch_hint "x64")
+ endif()
+
+ if(NOT arch_hint)
+ set(arch_hint "x86")
+ endif()
+
+ # default env in a 64-bit app on Win64:
+ # ProgramFiles=C:\Program Files
+ # ProgramFiles(x86)=C:\Program Files (x86)
+ # ProgramW6432=C:\Program Files
+ #
+ # default env in a 32-bit app on Win64:
+ # ProgramFiles=C:\Program Files (x86)
+ # ProgramFiles(x86)=C:\Program Files (x86)
+ # ProgramW6432=C:\Program Files
+ #
+ # default env in a 32-bit app on Win32:
+ # ProgramFiles=C:\Program Files
+ # ProgramFiles(x86) NOT DEFINED
+ # ProgramW6432 NOT DEFINED
+
+ # By default, use the ProgramFiles env var as the base value of
+ # CMAKE_INSTALL_PREFIX:
+ #
+ set(_PREFIX_ENV_VAR "ProgramFiles")
+
+ if ("$ENV{ProgramW6432}" STREQUAL "")
+ # running on 32-bit Windows
+ # must be a 32-bit CMake, too...
+ #message("guess: this is a 32-bit CMake running on 32-bit Windows")
+ else()
+ # running on 64-bit Windows
+ if ("$ENV{ProgramW6432}" STREQUAL "$ENV{ProgramFiles}")
+ # 64-bit CMake
+ #message("guess: this is a 64-bit CMake running on 64-bit Windows")
+ if(NOT "${arch_hint}" STREQUAL "x64")
+ # building 32-bit targets
+ set(_PREFIX_ENV_VAR "ProgramFiles(x86)")
+ endif()
+ else()
+ # 32-bit CMake
+ #message("guess: this is a 32-bit CMake running on 64-bit Windows")
+ if("${arch_hint}" STREQUAL "x64")
+ # building 64-bit targets
+ set(_PREFIX_ENV_VAR "ProgramW6432")
+ endif()
+ endif()
+ endif()
+
+ #if("${arch_hint}" STREQUAL "x64")
+ # message("guess: you are building a 64-bit app")
+ #else()
+ # message("guess: you are building a 32-bit app")
+ #endif()
+
+ if(NOT "$ENV{${_PREFIX_ENV_VAR}}" STREQUAL "")
+ file(TO_CMAKE_PATH "$ENV{${_PREFIX_ENV_VAR}}" _base)
+ elseif(NOT "$ENV{SystemDrive}" STREQUAL "")
+ set(_base "$ENV{SystemDrive}/Program Files")
+ else()
+ set(_base "C:/Program Files")
+ endif()
+
+ set(${var} "${_base}" PARENT_SCOPE)
+endfunction()
+
+
+# Set a variable to indicate whether the value of CMAKE_INSTALL_PREFIX
+# was initialized by the block below. This is useful for user
+# projects to change the default prefix while still allowing the
+# command line to override it.
+if(NOT DEFINED CMAKE_INSTALL_PREFIX)
+ set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT 1)
+endif()
+
+# Choose a default install prefix for this platform.
+if(CMAKE_HOST_UNIX)
+ set(CMAKE_INSTALL_PREFIX "/usr/local"
+ CACHE PATH "Install path prefix, prepended onto install directories.")
+else()
+ GetDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
+ set(CMAKE_INSTALL_PREFIX
+ "${CMAKE_GENERIC_PROGRAM_FILES}/${PROJECT_NAME}"
+ CACHE PATH "Install path prefix, prepended onto install directories.")
+ set(CMAKE_GENERIC_PROGRAM_FILES)
+endif()
+
+# Set a variable which will be used as component name in install() commands
+# where no COMPONENT has been given:
+set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "Unspecified")
+
+mark_as_advanced(
+ CMAKE_SKIP_RPATH
+ CMAKE_SKIP_INSTALL_RPATH
+ CMAKE_VERBOSE_MAKEFILE
+)
diff --git a/Modules/CMakeGraphVizOptions.cmake b/Modules/CMakeGraphVizOptions.cmake
new file mode 100644
index 0000000000..64c89b91d8
--- /dev/null
+++ b/Modules/CMakeGraphVizOptions.cmake
@@ -0,0 +1,123 @@
+#.rst:
+# CMakeGraphVizOptions
+# --------------------
+#
+# The builtin graphviz support of CMake.
+#
+# Variables specific to the graphviz support
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# CMake
+# can generate graphviz files, showing the dependencies between the
+# targets in a project and also external libraries which are linked
+# against. When CMake is run with the --graphiz=foo option, it will
+# produce
+#
+# * a foo.dot file showing all dependencies in the project
+# * a foo.dot.<target> file for each target, file showing on which other targets the respective target depends
+# * a foo.dot.<target>.dependers file, showing which other targets depend on the respective target
+#
+# This can result in huge graphs. Using the file
+# CMakeGraphVizOptions.cmake the look and content of the generated
+# graphs can be influenced. This file is searched first in
+# ${CMAKE_BINARY_DIR} and then in ${CMAKE_SOURCE_DIR}. If found, it is
+# read and the variables set in it are used to adjust options for the
+# generated graphviz files.
+#
+# .. variable:: GRAPHVIZ_GRAPH_TYPE
+#
+# The graph type
+#
+# * Mandatory : NO
+# * Default : "digraph"
+#
+# .. variable:: GRAPHVIZ_GRAPH_NAME
+#
+# The graph name.
+#
+# * Mandatory : NO
+# * Default : "GG"
+#
+# .. variable:: GRAPHVIZ_GRAPH_HEADER
+#
+# The header written at the top of the graphviz file.
+#
+# * Mandatory : NO
+# * Default : "node [n fontsize = "12"];"
+#
+# .. variable:: GRAPHVIZ_NODE_PREFIX
+#
+# The prefix for each node in the graphviz file.
+#
+# * Mandatory : NO
+# * Default : "node"
+#
+# .. variable:: GRAPHVIZ_EXECUTABLES
+#
+# Set this to FALSE to exclude executables from the generated graphs.
+#
+# * Mandatory : NO
+# * Default : TRUE
+#
+# .. variable:: GRAPHVIZ_STATIC_LIBS
+#
+# Set this to FALSE to exclude static libraries from the generated graphs.
+#
+# * Mandatory : NO
+# * Default : TRUE
+#
+# .. variable:: GRAPHVIZ_SHARED_LIBS
+#
+# Set this to FALSE to exclude shared libraries from the generated graphs.
+#
+# * Mandatory : NO
+# * Default : TRUE
+#
+# .. variable:: GRAPHVIZ_MODULE_LIBS
+#
+# Set this to FALSE to exclude module libraries from the generated graphs.
+#
+# * Mandatory : NO
+# * Default : TRUE
+#
+# .. variable:: GRAPHVIZ_EXTERNAL_LIBS
+#
+# Set this to FALSE to exclude external libraries from the generated graphs.
+#
+# * Mandatory : NO
+# * Default : TRUE
+#
+# .. variable:: GRAPHVIZ_IGNORE_TARGETS
+#
+# A list of regular expressions for ignoring targets.
+#
+# * Mandatory : NO
+# * Default : empty
+#
+# .. variable:: GRAPHVIZ_GENERATE_PER_TARGET
+#
+# Set this to FALSE to exclude per target graphs ``foo.dot.<target>``.
+#
+# * Mandatory : NO
+# * Default : TRUE
+#
+# .. variable:: GRAPHVIZ_GENERATE_DEPENDERS
+#
+# Set this to FALSE to exclude depender graphs ``foo.dot.<target>.dependers``.
+#
+# * Mandatory : NO
+# * Default : TRUE
+
+#=============================================================================
+# Copyright 2007-2009 Kitware, Inc.
+# Copyright 2013 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
diff --git a/Modules/CMakeImportBuildSettings.cmake b/Modules/CMakeImportBuildSettings.cmake
new file mode 100644
index 0000000000..edecc1fa08
--- /dev/null
+++ b/Modules/CMakeImportBuildSettings.cmake
@@ -0,0 +1,23 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is purposely no longer documented. It does nothing useful.
+
+# This macro used to load build settings from another project that
+# stored settings using the CMAKE_EXPORT_BUILD_SETTINGS macro.
+macro(CMAKE_IMPORT_BUILD_SETTINGS SETTINGS_FILE)
+ if("${SETTINGS_FILE}" STREQUAL "")
+ message(SEND_ERROR "CMAKE_IMPORT_BUILD_SETTINGS called with no argument.")
+ endif()
+endmacro()
diff --git a/Modules/CMakeJOMFindMake.cmake b/Modules/CMakeJOMFindMake.cmake
new file mode 100644
index 0000000000..cb3cf12c81
--- /dev/null
+++ b/Modules/CMakeJOMFindMake.cmake
@@ -0,0 +1,18 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+
+set (CMAKE_MAKE_PROGRAM "jom" CACHE STRING
+ "Program used to build from makefiles.")
+mark_as_advanced(CMAKE_MAKE_PROGRAM)
diff --git a/Modules/CMakeJavaCompiler.cmake.in b/Modules/CMakeJavaCompiler.cmake.in
new file mode 100644
index 0000000000..cd4158c8e7
--- /dev/null
+++ b/Modules/CMakeJavaCompiler.cmake.in
@@ -0,0 +1,13 @@
+set(CMAKE_Java_COMPILER "@CMAKE_Java_COMPILER@")
+set(CMAKE_Java_COMPILER_ARG1 "@CMAKE_Java_COMPILER_ARG1@")
+set(CMAKE_Java_RUNTIME "@CMAKE_Java_RUNTIME@")
+set(CMAKE_Java_ARCHIVE "@CMAKE_Java_ARCHIVE@")
+set(CMAKE_Java_COMPILER_LOADED 1)
+
+set(CMAKE_Java_SOURCE_FILE_EXTENSIONS java)
+set(CMAKE_Java_LINKER_PREFERENCE 40)
+set(CMAKE_Java_OUTPUT_EXTENSION .class)
+set(CMAKE_Java_OUTPUT_EXTENSION_REPLACE 1)
+set(CMAKE_STATIC_LIBRARY_PREFIX_Java "")
+set(CMAKE_STATIC_LIBRARY_SUFFIX_Java ".jar")
+set(CMAKE_Java_COMPILER_ENV_VAR "JAVA_COMPILER")
diff --git a/Modules/CMakeJavaInformation.cmake b/Modules/CMakeJavaInformation.cmake
new file mode 100644
index 0000000000..928c6ac32a
--- /dev/null
+++ b/Modules/CMakeJavaInformation.cmake
@@ -0,0 +1,59 @@
+
+#=============================================================================
+# Copyright 2004-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# This should be included before the _INIT variables are
+# used to initialize the cache. Since the rule variables
+# have if blocks on them, users can still define them here.
+# But, it should still be after the platform file so changes can
+# be made to those values.
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
+endif()
+
+if(CMAKE_USER_MAKE_RULES_OVERRIDE_Java)
+ # Save the full path of the file so try_compile can use it.
+ include(${CMAKE_USER_MAKE_RULES_OVERRIDE_Java} RESULT_VARIABLE _override)
+ set(CMAKE_USER_MAKE_RULES_OVERRIDE_Java "${_override}")
+endif()
+
+# this is a place holder if java needed flags for javac they would go here.
+if(NOT CMAKE_Java_CREATE_STATIC_LIBRARY)
+# if(WIN32)
+# set(class_files_mask "*.class")
+# else()
+ set(class_files_mask ".")
+# endif()
+
+ set(CMAKE_Java_CREATE_STATIC_LIBRARY
+ "<CMAKE_Java_ARCHIVE> -cf <TARGET> -C <OBJECT_DIR> ${class_files_mask}")
+ # "${class_files_mask}" should really be "<OBJECTS>" but compling a *.java
+ # file can create more than one *.class file...
+endif()
+
+# compile a Java file into an object file
+if(NOT CMAKE_Java_COMPILE_OBJECT)
+ set(CMAKE_Java_COMPILE_OBJECT
+ "<CMAKE_Java_COMPILER> <FLAGS> <SOURCE> -d <OBJECT_DIR>")
+endif()
+
+# set java include flag option and the separator for multiple include paths
+set(CMAKE_INCLUDE_FLAG_Java "-classpath ")
+if(WIN32 AND NOT CYGWIN)
+ set(CMAKE_INCLUDE_FLAG_SEP_Java ";")
+else()
+ set(CMAKE_INCLUDE_FLAG_SEP_Java ":")
+endif()
diff --git a/Modules/CMakeMSYSFindMake.cmake b/Modules/CMakeMSYSFindMake.cmake
new file mode 100644
index 0000000000..bc0f89fffd
--- /dev/null
+++ b/Modules/CMakeMSYSFindMake.cmake
@@ -0,0 +1,20 @@
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+find_program(CMAKE_MAKE_PROGRAM make
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MSYS-1.0_is1;Inno Setup: App Path]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MinGW;InstallLocation]/bin"
+ c:/msys/1.0/bin /msys/1.0/bin)
+mark_as_advanced(CMAKE_MAKE_PROGRAM)
diff --git a/Modules/CMakeMinGWFindMake.cmake b/Modules/CMakeMinGWFindMake.cmake
new file mode 100644
index 0000000000..d7298dcefc
--- /dev/null
+++ b/Modules/CMakeMinGWFindMake.cmake
@@ -0,0 +1,26 @@
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+find_program(CMAKE_MAKE_PROGRAM mingw32-make.exe PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MinGW;InstallLocation]/bin"
+ c:/MinGW/bin /MinGW/bin
+ "[HKEY_CURRENT_USER\\Software\\CodeBlocks;Path]/MinGW/bin"
+ )
+find_program(CMAKE_SH sh.exe )
+if(CMAKE_SH)
+ message(FATAL_ERROR "sh.exe was found in your PATH, here:\n${CMAKE_SH}\nFor MinGW make to work correctly sh.exe must NOT be in your path.\nRun cmake from a shell that does not have sh.exe in your PATH.\nIf you want to use a UNIX shell, then use MSYS Makefiles.\n")
+ set(CMAKE_MAKE_PROGRAM NOTFOUND)
+endif()
+
+mark_as_advanced(CMAKE_MAKE_PROGRAM CMAKE_SH)
diff --git a/Modules/CMakeNMakeFindMake.cmake b/Modules/CMakeNMakeFindMake.cmake
new file mode 100644
index 0000000000..d807df82b4
--- /dev/null
+++ b/Modules/CMakeNMakeFindMake.cmake
@@ -0,0 +1,18 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+
+set (CMAKE_MAKE_PROGRAM "nmake" CACHE STRING
+ "Program used to build from makefiles.")
+mark_as_advanced(CMAKE_MAKE_PROGRAM)
diff --git a/Modules/CMakeNinjaFindMake.cmake b/Modules/CMakeNinjaFindMake.cmake
new file mode 100644
index 0000000000..c3ca7671c5
--- /dev/null
+++ b/Modules/CMakeNinjaFindMake.cmake
@@ -0,0 +1,17 @@
+
+#=============================================================================
+# Copyright 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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+find_program(CMAKE_MAKE_PROGRAM ninja
+ DOC "Program used to build from build.ninja files.")
+mark_as_advanced(CMAKE_MAKE_PROGRAM)
diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake
new file mode 100644
index 0000000000..c6dc14199e
--- /dev/null
+++ b/Modules/CMakePackageConfigHelpers.cmake
@@ -0,0 +1,321 @@
+#.rst:
+# CMakePackageConfigHelpers
+# -------------------------
+#
+# Helpers functions for creating config files that can be included by other
+# projects to find and use a package.
+#
+# Adds the :command:`configure_package_config_file()` and
+# :command:`write_basic_package_version_file()` commands.
+#
+# Generating a Package Configuration File
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# .. command:: configure_package_config_file
+#
+# Create a config file for a project::
+#
+# configure_package_config_file(<input> <output> INSTALL_DESTINATION <path>
+# [PATH_VARS <var1> <var2> ... <varN>]
+# [NO_SET_AND_CHECK_MACRO]
+# [NO_CHECK_REQUIRED_COMPONENTS_MACRO]
+# [INSTALL_PREFIX <path>])
+#
+#
+# ``configure_package_config_file()`` should be used instead of the plain
+# :command:`configure_file()` command when creating the ``<Name>Config.cmake``
+# or ``<Name>-config.cmake`` file for installing a project or library. It helps
+# making the resulting package relocatable by avoiding hardcoded paths in the
+# installed ``Config.cmake`` file.
+#
+# In a ``FooConfig.cmake`` file there may be code like this to make the install
+# destinations know to the using project:
+#
+# .. code-block:: cmake
+#
+# set(FOO_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@" )
+# set(FOO_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" )
+# set(FOO_ICONS_DIR "@CMAKE_INSTALL_PREFIX@/share/icons" )
+# ...logic to determine installedPrefix from the own location...
+# set(FOO_CONFIG_DIR "${installedPrefix}/@CONFIG_INSTALL_DIR@" )
+#
+# All 4 options shown above are not sufficient, since the first 3 hardcode the
+# absolute directory locations, and the 4th case works only if the logic to
+# determine the ``installedPrefix`` is correct, and if ``CONFIG_INSTALL_DIR``
+# contains a relative path, which in general cannot be guaranteed. This has the
+# effect that the resulting ``FooConfig.cmake`` file would work poorly under
+# Windows and OSX, where users are used to choose the install location of a
+# binary package at install time, independent from how
+# :variable:`CMAKE_INSTALL_PREFIX` was set at build/cmake time.
+#
+# Using ``configure_package_config_file`` helps. If used correctly, it makes
+# the resulting ``FooConfig.cmake`` file relocatable. Usage:
+#
+# 1. write a ``FooConfig.cmake.in`` file as you are used to
+# 2. insert a line containing only the string ``@PACKAGE_INIT@``
+# 3. instead of ``set(FOO_DIR "@SOME_INSTALL_DIR@")``, use
+# ``set(FOO_DIR "@PACKAGE_SOME_INSTALL_DIR@")`` (this must be after the
+# ``@PACKAGE_INIT@`` line)
+# 4. instead of using the normal :command:`configure_file()`, use
+# ``configure_package_config_file()``
+#
+#
+#
+# The ``<input>`` and ``<output>`` arguments are the input and output file, the
+# same way as in :command:`configure_file()`.
+#
+# The ``<path>`` given to ``INSTALL_DESTINATION`` must be the destination where
+# the ``FooConfig.cmake`` file will be installed to. This path can either be
+# absolute, or relative to the ``INSTALL_PREFIX`` path.
+#
+# The variables ``<var1>`` to ``<varN>`` given as ``PATH_VARS`` are the
+# variables which contain install destinations. For each of them the macro will
+# create a helper variable ``PACKAGE_<var...>``. These helper variables must be
+# used in the ``FooConfig.cmake.in`` file for setting the installed location.
+# They are calculated by ``configure_package_config_file`` so that they are
+# always relative to the installed location of the package. This works both for
+# relative and also for absolute locations. For absolute locations it works
+# only if the absolute location is a subdirectory of ``INSTALL_PREFIX``.
+#
+# If the ``INSTALL_PREFIX`` argument is passed, this is used as base path to
+# calculate all the relative paths. The ``<path>`` argument must be an absolute
+# path. If this argument is not passed, the :variable:`CMAKE_INSTALL_PREFIX`
+# variable will be used instead. The default value is good when generating a
+# FooConfig.cmake file to use your package from the install tree. When
+# generating a FooConfig.cmake file to use your package from the build tree this
+# option should be used.
+#
+# By default ``configure_package_config_file`` also generates two helper macros,
+# ``set_and_check()`` and ``check_required_components()`` into the
+# ``FooConfig.cmake`` file.
+#
+# ``set_and_check()`` should be used instead of the normal ``set()`` command for
+# setting directories and file locations. Additionally to setting the variable
+# it also checks that the referenced file or directory actually exists and fails
+# with a ``FATAL_ERROR`` otherwise. This makes sure that the created
+# ``FooConfig.cmake`` file does not contain wrong references.
+# When using the ``NO_SET_AND_CHECK_MACRO``, this macro is not generated
+# into the ``FooConfig.cmake`` file.
+#
+# ``check_required_components(<package_name>)`` should be called at the end of
+# the ``FooConfig.cmake`` file if the package supports components. This macro
+# checks whether all requested, non-optional components have been found, and if
+# this is not the case, sets the ``Foo_FOUND`` variable to ``FALSE``, so that
+# the package is considered to be not found. It does that by testing the
+# ``Foo_<Component>_FOUND`` variables for all requested required components.
+# When using the ``NO_CHECK_REQUIRED_COMPONENTS_MACRO`` option, this macro is
+# not generated into the ``FooConfig.cmake`` file.
+#
+# For an example see below the documentation for
+# :command:`write_basic_package_version_file()`.
+#
+# Generating a Package Version File
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# .. command:: write_basic_package_version_file
+#
+# Create a version file for a project::
+#
+# write_basic_package_version_file(<filename>
+# [VERSION <major.minor.patch>]
+# COMPATIBILITY <AnyNewerVersion|SameMajorVersion|ExactVersion> )
+#
+#
+# Writes a file for use as ``<package>ConfigVersion.cmake`` file to
+# ``<filename>``. See the documentation of :command:`find_package()` for
+# details on this.
+#
+# ``<filename>`` is the output filename, it should be in the build tree.
+# ``<major.minor.patch>`` is the version number of the project to be installed.
+#
+# If no ``VERSION`` is given, the :variable:`PROJECT_VERSION` variable is used.
+# If this hasn't been set, it errors out.
+#
+# The ``COMPATIBILITY`` mode ``AnyNewerVersion`` means that the installed
+# package version will be considered compatible if it is newer or exactly the
+# same as the requested version. This mode should be used for packages which
+# are fully backward compatible, also across major versions.
+# If ``SameMajorVersion`` is used instead, then the behaviour differs from
+# ``AnyNewerVersion`` in that the major version number must be the same as
+# requested, e.g. version 2.0 will not be considered compatible if 1.0 is
+# requested. This mode should be used for packages which guarantee backward
+# compatibility within the same major version.
+# If ``ExactVersion`` is used, then the package is only considered compatible if
+# the requested version matches exactly its own version number (not considering
+# the tweak version). For example, version 1.2.3 of a package is only
+# considered compatible to requested version 1.2.3. This mode is for packages
+# without compatibility guarantees.
+# If your project has more elaborated version matching rules, you will need to
+# write your own custom ``ConfigVersion.cmake`` file instead of using this
+# macro.
+#
+# Internally, this macro executes :command:`configure_file()` to create the
+# resulting version file. Depending on the ``COMPATIBLITY``, either the file
+# ``BasicConfigVersion-SameMajorVersion.cmake.in`` or
+# ``BasicConfigVersion-AnyNewerVersion.cmake.in`` is used. Please note that
+# these two files are internal to CMake and you should not call
+# :command:`configure_file()` on them yourself, but they can be used as starting
+# point to create more sophisticted custom ``ConfigVersion.cmake`` files.
+#
+# Example Generating Package Files
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# Example using both :command:`configure_package_config_file` and
+# ``write_basic_package_version_file()``:
+#
+# ``CMakeLists.txt``:
+#
+# .. code-block:: cmake
+#
+# set(INCLUDE_INSTALL_DIR include/ ... CACHE )
+# set(LIB_INSTALL_DIR lib/ ... CACHE )
+# set(SYSCONFIG_INSTALL_DIR etc/foo/ ... CACHE )
+# ...
+# include(CMakePackageConfigHelpers)
+# configure_package_config_file(FooConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake
+# INSTALL_DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake
+# PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR)
+# write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
+# VERSION 1.2.3
+# COMPATIBILITY SameMajorVersion )
+# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
+# DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake )
+#
+# ``FooConfig.cmake.in``:
+#
+# .. code-block:: cmake
+#
+# set(FOO_VERSION x.y.z)
+# ...
+# @PACKAGE_INIT@
+# ...
+# set_and_check(FOO_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
+# set_and_check(FOO_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@")
+#
+# check_required_components(Foo)
+
+
+#=============================================================================
+# Copyright 2012 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+include(CMakeParseArguments)
+
+include(WriteBasicConfigVersionFile)
+
+macro(WRITE_BASIC_PACKAGE_VERSION_FILE)
+ write_basic_config_version_file(${ARGN})
+endmacro()
+
+function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
+ set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
+ set(oneValueArgs INSTALL_DESTINATION INSTALL_PREFIX)
+ set(multiValueArgs PATH_VARS )
+
+ cmake_parse_arguments(CCF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if(CCF_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown keywords given to CONFIGURE_PACKAGE_CONFIG_FILE(): \"${CCF_UNPARSED_ARGUMENTS}\"")
+ endif()
+
+ if(NOT CCF_INSTALL_DESTINATION)
+ message(FATAL_ERROR "No INSTALL_DESTINATION given to CONFIGURE_PACKAGE_CONFIG_FILE()")
+ endif()
+
+ if(DEFINED CCF_INSTALL_PREFIX)
+ if(IS_ABSOLUTE "${CCF_INSTALL_PREFIX}")
+ set(installPrefix "${CCF_INSTALL_PREFIX}")
+ else()
+ message(FATAL_ERROR "INSTALL_PREFIX must be an absolute path")
+ endif()
+ else()
+ set(installPrefix "${CMAKE_INSTALL_PREFIX}")
+ endif()
+
+ if(IS_ABSOLUTE "${CCF_INSTALL_DESTINATION}")
+ set(absInstallDir "${CCF_INSTALL_DESTINATION}")
+ else()
+ set(absInstallDir "${installPrefix}/${CCF_INSTALL_DESTINATION}")
+ endif()
+
+ file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${installPrefix}" )
+
+ foreach(var ${CCF_PATH_VARS})
+ if(NOT DEFINED ${var})
+ message(FATAL_ERROR "Variable ${var} does not exist")
+ else()
+ if(IS_ABSOLUTE "${${var}}")
+ string(REPLACE "${installPrefix}" "\${PACKAGE_PREFIX_DIR}"
+ PACKAGE_${var} "${${var}}")
+ else()
+ set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}")
+ endif()
+ endif()
+ endforeach()
+
+ get_filename_component(inputFileName "${_inputFile}" NAME)
+
+ set(PACKAGE_INIT "
+####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
+####### Any changes to this file will be overwritten by the next CMake run ####
+####### The input file was ${inputFileName} ########
+
+get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELATIVE_PATH}\" ABSOLUTE)
+")
+
+ if("${absInstallDir}" MATCHES "^(/usr)?/lib(64)?/.+")
+ # Handle "/usr move" symlinks created by some Linux distros.
+ set(PACKAGE_INIT "${PACKAGE_INIT}
+# Use original install prefix when loaded through a \"/usr move\"
+# cross-prefix symbolic link such as /lib -> /usr/lib.
+get_filename_component(_realCurr \"\${CMAKE_CURRENT_LIST_DIR}\" REALPATH)
+get_filename_component(_realOrig \"${absInstallDir}\" REALPATH)
+if(_realCurr STREQUAL _realOrig)
+ set(PACKAGE_PREFIX_DIR \"${installPrefix}\")
+endif()
+unset(_realOrig)
+unset(_realCurr)
+")
+ endif()
+
+ if(NOT CCF_NO_SET_AND_CHECK_MACRO)
+ set(PACKAGE_INIT "${PACKAGE_INIT}
+macro(set_and_check _var _file)
+ set(\${_var} \"\${_file}\")
+ if(NOT EXISTS \"\${_file}\")
+ message(FATAL_ERROR \"File or directory \${_file} referenced by variable \${_var} does not exist !\")
+ endif()
+endmacro()
+")
+ endif()
+
+
+ if(NOT CCF_NO_CHECK_REQUIRED_COMPONENTS_MACRO)
+ set(PACKAGE_INIT "${PACKAGE_INIT}
+macro(check_required_components _NAME)
+ foreach(comp \${\${_NAME}_FIND_COMPONENTS})
+ if(NOT \${_NAME}_\${comp}_FOUND)
+ if(\${_NAME}_FIND_REQUIRED_\${comp})
+ set(\${_NAME}_FOUND FALSE)
+ endif()
+ endif()
+ endforeach()
+endmacro()
+")
+ endif()
+
+ set(PACKAGE_INIT "${PACKAGE_INIT}
+####################################################################################")
+
+ configure_file("${_inputFile}" "${_outputFile}" @ONLY)
+
+endfunction()
diff --git a/Modules/CMakeParseArguments.cmake b/Modules/CMakeParseArguments.cmake
new file mode 100644
index 0000000000..4248176ad6
--- /dev/null
+++ b/Modules/CMakeParseArguments.cmake
@@ -0,0 +1,160 @@
+#.rst:
+# 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.
+
+#=============================================================================
+# Copyright 2010 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (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/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake
new file mode 100644
index 0000000000..bfcf455823
--- /dev/null
+++ b/Modules/CMakeParseImplicitLinkInfo.cmake
@@ -0,0 +1,168 @@
+
+#=============================================================================
+# Copyright 2009 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.)
+
+# Function parse implicit linker options.
+# This is used internally by CMake and should not be included by user
+# code.
+
+function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj_regex)
+ set(implicit_libs_tmp "")
+ set(implicit_dirs_tmp)
+ set(implicit_fwks_tmp)
+ set(log "")
+
+ # Parse implicit linker arguments.
+ set(linker "CMAKE_LINKER-NOTFOUND")
+ if(CMAKE_LINKER)
+ get_filename_component(linker ${CMAKE_LINKER} NAME)
+ string(REGEX REPLACE "([][+.*?()^$])" "\\\\\\1" linker "${linker}")
+ endif()
+ # Construct a regex to match linker lines. It must match both the
+ # whole line and just the command (argv[0]).
+ set(linker_regex "^( *|.*[/\\])(${linker}|([^/\\]+-)?ld|collect2)[^/\\]*( |$)")
+ set(linker_exclude_regex "collect2 version ")
+ set(log "${log} link line regex: [${linker_regex}]\n")
+ string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
+ foreach(line IN LISTS output_lines)
+ set(cmd)
+ if("${line}" MATCHES "${linker_regex}" AND
+ NOT "${line}" MATCHES "${linker_exclude_regex}")
+ if(XCODE)
+ # Xcode unconditionally adds a path under the project build tree and
+ # on older versions it is not reported with proper quotes. Remove it.
+ string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" _dir_regex "${CMAKE_BINARY_DIR}")
+ string(REGEX REPLACE " -[FL]${_dir_regex}/([^ ]| [^-])+( |$)" " " xline "${line}")
+ if(NOT "x${xline}" STREQUAL "x${line}")
+ set(log "${log} reduced line: [${line}]\n to: [${xline}]\n")
+ set(line "${xline}")
+ endif()
+ endif()
+ if(UNIX)
+ separate_arguments(args UNIX_COMMAND "${line}")
+ else()
+ separate_arguments(args WINDOWS_COMMAND "${line}")
+ endif()
+ list(GET args 0 cmd)
+ endif()
+ if("${cmd}" MATCHES "${linker_regex}")
+ set(log "${log} link line: [${line}]\n")
+ string(REGEX REPLACE ";-([LYz]);" ";-\\1" args "${args}")
+ foreach(arg IN LISTS args)
+ if("${arg}" MATCHES "^-L(.:)?[/\\]")
+ # Unix search path.
+ string(REGEX REPLACE "^-L" "" dir "${arg}")
+ list(APPEND implicit_dirs_tmp ${dir})
+ set(log "${log} arg [${arg}] ==> dir [${dir}]\n")
+ elseif("${arg}" MATCHES "^-l([^:].*)$")
+ # Unix library.
+ list(APPEND implicit_libs_tmp ${CMAKE_MATCH_1})
+ set(log "${log} arg [${arg}] ==> lib [${lib}]\n")
+ elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.a$")
+ # Unix library full path.
+ list(APPEND implicit_libs_tmp ${arg})
+ set(log "${log} arg [${arg}] ==> lib [${arg}]\n")
+ elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.o$"
+ AND obj_regex AND "${arg}" MATCHES "${obj_regex}")
+ # Object file full path.
+ list(APPEND implicit_libs_tmp ${arg})
+ set(log "${log} arg [${arg}] ==> obj [${arg}]\n")
+ elseif("${arg}" MATCHES "^-Y(P,)?[^0-9]")
+ # Sun search path ([^0-9] avoids conflict with Mac -Y<num>).
+ string(REGEX REPLACE "^-Y(P,)?" "" dirs "${arg}")
+ string(REPLACE ":" ";" dirs "${dirs}")
+ list(APPEND implicit_dirs_tmp ${dirs})
+ set(log "${log} arg [${arg}] ==> dirs [${dirs}]\n")
+ elseif("${arg}" MATCHES "^-l:")
+ # HP named library.
+ list(APPEND implicit_libs_tmp ${arg})
+ set(log "${log} arg [${arg}] ==> lib [${arg}]\n")
+ elseif("${arg}" MATCHES "^-z(all|default|weak)extract")
+ # Link editor option.
+ list(APPEND implicit_libs_tmp ${arg})
+ set(log "${log} arg [${arg}] ==> opt [${arg}]\n")
+ else()
+ set(log "${log} arg [${arg}] ==> ignore\n")
+ endif()
+ endforeach()
+ break()
+ elseif("${line}" MATCHES "LPATH(=| is:? *)(.*)$")
+ set(log "${log} LPATH line: [${line}]\n")
+ # HP search path.
+ string(REPLACE ":" ";" paths "${CMAKE_MATCH_2}")
+ list(APPEND implicit_dirs_tmp ${paths})
+ set(log "${log} dirs [${paths}]\n")
+ else()
+ set(log "${log} ignore line: [${line}]\n")
+ endif()
+ endforeach()
+
+ # Look for library search paths reported by linker.
+ if("${output_lines}" MATCHES ";Library search paths:((;\t[^;]+)+)")
+ string(REPLACE ";\t" ";" implicit_dirs_match "${CMAKE_MATCH_1}")
+ set(log "${log} Library search paths: [${implicit_dirs_match}]\n")
+ list(APPEND implicit_dirs_tmp ${implicit_dirs_match})
+ endif()
+ if("${output_lines}" MATCHES ";Framework search paths:((;\t[^;]+)+)")
+ string(REPLACE ";\t" ";" implicit_fwks_match "${CMAKE_MATCH_1}")
+ set(log "${log} Framework search paths: [${implicit_fwks_match}]\n")
+ list(APPEND implicit_fwks_tmp ${implicit_fwks_match})
+ endif()
+
+ # Cleanup list of libraries and flags.
+ # We remove items that are not language-specific.
+ set(implicit_libs "")
+ foreach(lib IN LISTS implicit_libs_tmp)
+ if("${lib}" MATCHES "^(crt.*\\.o|gcc.*|System.*)$")
+ set(log "${log} remove lib [${lib}]\n")
+ elseif(IS_ABSOLUTE "${lib}")
+ get_filename_component(abs "${lib}" ABSOLUTE)
+ if(NOT "x${lib}" STREQUAL "x${abs}")
+ set(log "${log} collapse lib [${lib}] ==> [${abs}]\n")
+ endif()
+ list(APPEND implicit_libs "${abs}")
+ else()
+ list(APPEND implicit_libs "${lib}")
+ endif()
+ endforeach()
+
+ # Cleanup list of library and framework directories.
+ set(desc_dirs "library")
+ set(desc_fwks "framework")
+ foreach(t dirs fwks)
+ set(implicit_${t} "")
+ foreach(d IN LISTS implicit_${t}_tmp)
+ get_filename_component(dir "${d}" ABSOLUTE)
+ string(FIND "${dir}" "${CMAKE_FILES_DIRECTORY}/" pos)
+ if(NOT pos LESS 0)
+ set(msg ", skipping non-system directory")
+ else()
+ set(msg "")
+ list(APPEND implicit_${t} "${dir}")
+ endif()
+ set(log "${log} collapse ${desc_${t}} dir [${d}] ==> [${dir}]${msg}\n")
+ endforeach()
+ list(REMOVE_DUPLICATES implicit_${t})
+ endforeach()
+
+ # Log results.
+ set(log "${log} implicit libs: [${implicit_libs}]\n")
+ set(log "${log} implicit dirs: [${implicit_dirs}]\n")
+ set(log "${log} implicit fwks: [${implicit_fwks}]\n")
+
+ # Return results.
+ set(${lib_var} "${implicit_libs}" PARENT_SCOPE)
+ set(${dir_var} "${implicit_dirs}" PARENT_SCOPE)
+ set(${fwk_var} "${implicit_fwks}" PARENT_SCOPE)
+ set(${log_var} "${log}" PARENT_SCOPE)
+endfunction()
diff --git a/Modules/CMakePlatformId.h.in b/Modules/CMakePlatformId.h.in
new file mode 100644
index 0000000000..bc26c0773e
--- /dev/null
+++ b/Modules/CMakePlatformId.h.in
@@ -0,0 +1,206 @@
+/* Identify known platforms by name. */
+#if defined(__linux) || defined(__linux__) || defined(linux)
+# define PLATFORM_ID "Linux"
+
+#elif defined(__CYGWIN__)
+# define PLATFORM_ID "Cygwin"
+
+#elif defined(__MINGW32__)
+# define PLATFORM_ID "MinGW"
+
+#elif defined(__APPLE__)
+# define PLATFORM_ID "Darwin"
+
+#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+# define PLATFORM_ID "Windows"
+
+#elif defined(__FreeBSD__) || defined(__FreeBSD)
+# define PLATFORM_ID "FreeBSD"
+
+#elif defined(__NetBSD__) || defined(__NetBSD)
+# define PLATFORM_ID "NetBSD"
+
+#elif defined(__OpenBSD__) || defined(__OPENBSD)
+# define PLATFORM_ID "OpenBSD"
+
+#elif defined(__sun) || defined(sun)
+# define PLATFORM_ID "SunOS"
+
+#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
+# define PLATFORM_ID "AIX"
+
+#elif defined(__sgi) || defined(__sgi__) || defined(_SGI)
+# define PLATFORM_ID "IRIX"
+
+#elif defined(__hpux) || defined(__hpux__)
+# define PLATFORM_ID "HP-UX"
+
+#elif defined(__HAIKU__)
+# define PLATFORM_ID "Haiku"
+
+#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
+# define PLATFORM_ID "BeOS"
+
+#elif defined(__QNX__) || defined(__QNXNTO__)
+# define PLATFORM_ID "QNX"
+
+#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__)
+# define PLATFORM_ID "Tru64"
+
+#elif defined(__riscos) || defined(__riscos__)
+# define PLATFORM_ID "RISCos"
+
+#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__)
+# define PLATFORM_ID "SINIX"
+
+#elif defined(__UNIX_SV__)
+# define PLATFORM_ID "UNIX_SV"
+
+#elif defined(__bsdos__)
+# define PLATFORM_ID "BSDOS"
+
+#elif defined(_MPRAS) || defined(MPRAS)
+# define PLATFORM_ID "MP-RAS"
+
+#elif defined(__osf) || defined(__osf__)
+# define PLATFORM_ID "OSF1"
+
+#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv)
+# define PLATFORM_ID "SCO_SV"
+
+#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX)
+# define PLATFORM_ID "ULTRIX"
+
+#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX)
+# define PLATFORM_ID "Xenix"
+
+#elif defined(__WATCOMC__)
+# if defined(__LINUX__)
+# define PLATFORM_ID "Linux"
+
+# elif defined(__DOS__)
+# define PLATFORM_ID "DOS"
+
+# elif defined(__OS2__)
+# define PLATFORM_ID "OS2"
+
+# elif defined(__WINDOWS__)
+# define PLATFORM_ID "Windows3x"
+
+# else /* unknown platform */
+# define PLATFORM_ID ""
+# endif
+
+#else /* unknown platform */
+# define PLATFORM_ID ""
+
+#endif
+
+/* For windows compilers MSVC and Intel we can determine
+ the architecture of the compiler being used. This is because
+ the compilers do not have flags that can change the architecture,
+ but rather depend on which compiler is being used
+*/
+#if defined(_WIN32) && defined(_MSC_VER)
+# if defined(_M_IA64)
+# define ARCHITECTURE_ID "IA64"
+
+# elif defined(_M_X64) || defined(_M_AMD64)
+# define ARCHITECTURE_ID "x64"
+
+# elif defined(_M_IX86)
+# define ARCHITECTURE_ID "X86"
+
+# elif defined(_M_ARM)
+# define ARCHITECTURE_ID "ARM"
+
+# elif defined(_M_MIPS)
+# define ARCHITECTURE_ID "MIPS"
+
+# elif defined(_M_SH)
+# define ARCHITECTURE_ID "SHx"
+
+# else /* unknown architecture */
+# define ARCHITECTURE_ID ""
+# endif
+
+#elif defined(__WATCOMC__)
+# if defined(_M_I86)
+# define ARCHITECTURE_ID "I86"
+
+# elif defined(_M_IX86)
+# define ARCHITECTURE_ID "X86"
+
+# else /* unknown architecture */
+# define ARCHITECTURE_ID ""
+# endif
+
+#else
+# define ARCHITECTURE_ID ""
+#endif
+
+/* Convert integer to decimal digit literals. */
+#define DEC(n) \
+ ('0' + (((n) / 10000000)%10)), \
+ ('0' + (((n) / 1000000)%10)), \
+ ('0' + (((n) / 100000)%10)), \
+ ('0' + (((n) / 10000)%10)), \
+ ('0' + (((n) / 1000)%10)), \
+ ('0' + (((n) / 100)%10)), \
+ ('0' + (((n) / 10)%10)), \
+ ('0' + ((n) % 10))
+
+/* Convert integer to hex digit literals. */
+#define HEX(n) \
+ ('0' + ((n)>>28 & 0xF)), \
+ ('0' + ((n)>>24 & 0xF)), \
+ ('0' + ((n)>>20 & 0xF)), \
+ ('0' + ((n)>>16 & 0xF)), \
+ ('0' + ((n)>>12 & 0xF)), \
+ ('0' + ((n)>>8 & 0xF)), \
+ ('0' + ((n)>>4 & 0xF)), \
+ ('0' + ((n) & 0xF))
+
+/* Construct a string literal encoding the version number components. */
+#ifdef COMPILER_VERSION_MAJOR
+char const info_version[] = {
+ 'I', 'N', 'F', 'O', ':',
+ 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[',
+ COMPILER_VERSION_MAJOR,
+# ifdef COMPILER_VERSION_MINOR
+ '.', COMPILER_VERSION_MINOR,
+# ifdef COMPILER_VERSION_PATCH
+ '.', COMPILER_VERSION_PATCH,
+# ifdef COMPILER_VERSION_TWEAK
+ '.', COMPILER_VERSION_TWEAK,
+# endif
+# endif
+# endif
+ ']','\0'};
+#endif
+
+/* Construct a string literal encoding the version number components. */
+#ifdef SIMULATE_VERSION_MAJOR
+char const info_simulate_version[] = {
+ 'I', 'N', 'F', 'O', ':',
+ 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[',
+ SIMULATE_VERSION_MAJOR,
+# ifdef SIMULATE_VERSION_MINOR
+ '.', SIMULATE_VERSION_MINOR,
+# ifdef SIMULATE_VERSION_PATCH
+ '.', SIMULATE_VERSION_PATCH,
+# ifdef SIMULATE_VERSION_TWEAK
+ '.', SIMULATE_VERSION_TWEAK,
+# endif
+# endif
+# endif
+ ']','\0'};
+#endif
+
+/* Construct the string literal in pieces to prevent the source from
+ getting matched. Store it in a pointer rather than an array
+ because some compilers will just produce instructions to fill the
+ array rather than assigning a pointer to a static array. */
+char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]";
+char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]";
+
diff --git a/Modules/CMakePrintHelpers.cmake b/Modules/CMakePrintHelpers.cmake
new file mode 100644
index 0000000000..ad3b0d585b
--- /dev/null
+++ b/Modules/CMakePrintHelpers.cmake
@@ -0,0 +1,162 @@
+#.rst:
+# CMakePrintHelpers
+# -----------------
+#
+# Convenience macros for printing properties and variables, useful e.g. for debugging.
+#
+# ::
+#
+# CMAKE_PRINT_PROPERTIES([TARGETS target1 .. targetN]
+# [SOURCES source1 .. sourceN]
+# [DIRECTORIES dir1 .. dirN]
+# [TESTS test1 .. testN]
+# [CACHE_ENTRIES entry1 .. entryN]
+# PROPERTIES prop1 .. propN )
+#
+# This macro prints the values of the properties of the given targets,
+# source files, directories, tests or cache entries. Exactly one of the
+# scope keywords must be used. Example:
+#
+# ::
+#
+# cmake_print_properties(TARGETS foo bar PROPERTIES LOCATION INTERFACE_INCLUDE_DIRS)
+#
+# This will print the LOCATION and INTERFACE_INCLUDE_DIRS properties for
+# both targets foo and bar.
+#
+#
+#
+# CMAKE_PRINT_VARIABLES(var1 var2 .. varN)
+#
+# This macro will print the name of each variable followed by its value.
+# Example:
+#
+# ::
+#
+# cmake_print_variables(CMAKE_C_COMPILER CMAKE_MAJOR_VERSION THIS_ONE_DOES_NOT_EXIST)
+#
+# Gives:
+#
+# ::
+#
+# -- CMAKE_C_COMPILER="/usr/bin/gcc" ; CMAKE_MAJOR_VERSION="2" ; THIS_ONE_DOES_NOT_EXIST=""
+
+#=============================================================================
+# Copyright 2013 Alexander Neundorf, <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+include(CMakeParseArguments)
+
+function(CMAKE_PRINT_VARIABLES)
+ set(msg "")
+ foreach(var ${ARGN})
+ if(msg)
+ set(msg "${msg} ; ")
+ endif()
+ set(msg "${msg}${var}=\"${${var}}\"")
+ endforeach()
+ message(STATUS "${msg}")
+endfunction()
+
+
+function(CMAKE_PRINT_PROPERTIES )
+ set(options )
+ set(oneValueArgs )
+ set(multiValueArgs TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES PROPERTIES )
+
+ cmake_parse_arguments(CPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if(CPP_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown keywords given to cmake_print_properties(): \"${CPP_UNPARSED_ARGUMENTS}\"")
+ return()
+ endif()
+
+ if(NOT CPP_PROPERTIES)
+ message(FATAL_ERROR "Required argument PROPERTIES missing in cmake_print_properties() call")
+ return()
+ endif()
+
+ set(mode)
+ set(items)
+ set(keyword)
+
+ if(CPP_TARGETS)
+ set(items ${CPP_TARGETS})
+ set(mode ${mode} TARGETS)
+ set(keyword TARGET)
+ endif()
+
+ if(CPP_SOURCES)
+ set(items ${CPP_SOURCES})
+ set(mode ${mode} SOURCES)
+ set(keyword SOURCE)
+ endif()
+
+ if(CPP_TESTS)
+ set(items ${CPP_TESTS})
+ set(mode ${mode} TESTS)
+ set(keyword TEST)
+ endif()
+
+ if(CPP_DIRECTORIES)
+ set(items ${CPP_DIRECTORIES})
+ set(mode ${mode} DIRECTORIES)
+ set(keyword DIRECTORY)
+ endif()
+
+ if(CPP_CACHE_ENTRIES)
+ set(items ${CPP_CACHE_ENTRIES})
+ set(mode ${mode} CACHE_ENTRIES)
+ set(keyword CACHE)
+ endif()
+
+ if(NOT mode)
+ message(FATAL_ERROR "Mode keyword missing in cmake_print_properties() call, must be one of TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES PROPERTIES")
+ return()
+ endif()
+
+ list(LENGTH mode modeLength)
+ if("${modeLength}" GREATER 1)
+ message(FATAL_ERROR "Multiple mode keyword used in cmake_print_properties() call, it must be exactly one of TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES PROPERTIES")
+ return()
+ endif()
+
+ set(msg "\n")
+ foreach(item ${items})
+
+ set(itemExists TRUE)
+ if(keyword STREQUAL "TARGET")
+ if(NOT TARGET ${item})
+ set(itemExists FALSE)
+ set(msg "${msg}\n No such TARGET \"${item}\" !\n\n")
+ endif()
+ endif()
+
+ if (itemExists)
+ set(msg "${msg} Properties for ${keyword} ${item}:\n")
+ foreach(prop ${CPP_PROPERTIES})
+
+ get_property(propertySet ${keyword} ${item} PROPERTY "${prop}" SET)
+
+ if(propertySet)
+ get_property(property ${keyword} ${item} PROPERTY "${prop}")
+ set(msg "${msg} ${item}.${prop} = \"${property}\"\n")
+ else()
+ set(msg "${msg} ${item}.${prop} = <NOTFOUND>\n")
+ endif()
+ endforeach()
+ endif()
+
+ endforeach()
+ message(STATUS "${msg}")
+
+endfunction()
diff --git a/Modules/CMakePrintSystemInformation.cmake b/Modules/CMakePrintSystemInformation.cmake
new file mode 100644
index 0000000000..355c47dacc
--- /dev/null
+++ b/Modules/CMakePrintSystemInformation.cmake
@@ -0,0 +1,50 @@
+#.rst:
+# CMakePrintSystemInformation
+# ---------------------------
+#
+# print system information
+#
+# This file can be used for diagnostic purposes just include it in a
+# project to see various internal CMake variables.
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+message("CMAKE_SYSTEM is ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
+message("CMAKE_SYSTEM file is ${CMAKE_SYSTEM_INFO_FILE}")
+message("CMAKE_C_COMPILER is ${CMAKE_C_COMPILER}")
+message("CMAKE_CXX_COMPILER is ${CMAKE_CXX_COMPILER}")
+
+
+message("CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS is ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
+message("CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS is ${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}")
+message("CMAKE_DL_LIBS is ${CMAKE_DL_LIBS}")
+message("CMAKE_SHARED_LIBRARY_PREFIX is ${CMAKE_SHARED_LIBRARY_PREFIX}")
+message("CMAKE_SHARED_LIBRARY_SUFFIX is ${CMAKE_SHARED_LIBRARY_SUFFIX}")
+message("CMAKE_COMPILER_IS_GNUCC = ${CMAKE_COMPILER_IS_GNUCC}")
+message("CMAKE_COMPILER_IS_GNUCXX = ${CMAKE_COMPILER_IS_GNUCXX}")
+
+message("CMAKE_CXX_CREATE_SHARED_LIBRARY is ${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
+message("CMAKE_CXX_CREATE_SHARED_MODULE is ${CMAKE_CXX_CREATE_SHARED_MODULE}")
+message("CMAKE_CXX_CREATE_STATIC_LIBRARY is ${CMAKE_CXX_CREATE_STATIC_LIBRARY}")
+message("CMAKE_CXX_COMPILE_OBJECT is ${CMAKE_CXX_COMPILE_OBJECT}")
+message("CMAKE_CXX_LINK_EXECUTABLE ${CMAKE_CXX_LINK_EXECUTABLE}")
+
+message("CMAKE_C_CREATE_SHARED_LIBRARY is ${CMAKE_C_CREATE_SHARED_LIBRARY}")
+message("CMAKE_C_CREATE_SHARED_MODULE is ${CMAKE_C_CREATE_SHARED_MODULE}")
+message("CMAKE_C_CREATE_STATIC_LIBRARY is ${CMAKE_C_CREATE_STATIC_LIBRARY}")
+message("CMAKE_C_COMPILE_OBJECT is ${CMAKE_C_COMPILE_OBJECT}")
+message("CMAKE_C_LINK_EXECUTABLE ${CMAKE_C_LINK_EXECUTABLE}")
+
+message("CMAKE_SYSTEM_AND_CXX_COMPILER_INFO_FILE ${CMAKE_SYSTEM_AND_CXX_COMPILER_INFO_FILE}")
+message("CMAKE_SYSTEM_AND_C_COMPILER_INFO_FILE ${CMAKE_SYSTEM_AND_C_COMPILER_INFO_FILE}")
diff --git a/Modules/CMakePushCheckState.cmake b/Modules/CMakePushCheckState.cmake
new file mode 100644
index 0000000000..bf4ec0e9c9
--- /dev/null
+++ b/Modules/CMakePushCheckState.cmake
@@ -0,0 +1,94 @@
+#.rst:
+# CMakePushCheckState
+# -------------------
+#
+#
+#
+# This module defines three macros: CMAKE_PUSH_CHECK_STATE()
+# CMAKE_POP_CHECK_STATE() and CMAKE_RESET_CHECK_STATE() These macros can
+# be used to save, restore and reset (i.e., clear contents) the state of
+# the variables CMAKE_REQUIRED_FLAGS, CMAKE_REQUIRED_DEFINITIONS,
+# CMAKE_REQUIRED_LIBRARIES and CMAKE_REQUIRED_INCLUDES used by the
+# various Check-files coming with CMake, like e.g.
+# check_function_exists() etc. The variable contents are pushed on a
+# stack, pushing multiple times is supported. This is useful e.g. when
+# executing such tests in a Find-module, where they have to be set, but
+# after the Find-module has been executed they should have the same
+# value as they had before.
+#
+# CMAKE_PUSH_CHECK_STATE() macro receives optional argument RESET.
+# Whether it's specified, CMAKE_PUSH_CHECK_STATE() will set all
+# CMAKE_REQUIRED_* variables to empty values, same as
+# CMAKE_RESET_CHECK_STATE() call will do.
+#
+# Usage:
+#
+# ::
+#
+# cmake_push_check_state(RESET)
+# set(CMAKE_REQUIRED_DEFINITIONS -DSOME_MORE_DEF)
+# check_function_exists(...)
+# cmake_reset_check_state()
+# set(CMAKE_REQUIRED_DEFINITIONS -DANOTHER_DEF)
+# check_function_exists(...)
+# cmake_pop_check_state()
+
+#=============================================================================
+# Copyright 2006-2011 Alexander Neundorf, <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+
+macro(CMAKE_RESET_CHECK_STATE)
+
+ set(CMAKE_REQUIRED_INCLUDES)
+ set(CMAKE_REQUIRED_DEFINITIONS)
+ set(CMAKE_REQUIRED_LIBRARIES)
+ set(CMAKE_REQUIRED_FLAGS)
+ set(CMAKE_REQUIRED_QUIET)
+
+endmacro()
+
+macro(CMAKE_PUSH_CHECK_STATE)
+
+ if(NOT DEFINED _CMAKE_PUSH_CHECK_STATE_COUNTER)
+ set(_CMAKE_PUSH_CHECK_STATE_COUNTER 0)
+ endif()
+
+ math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}+1")
+
+ set(_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_INCLUDES})
+ set(_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_DEFINITIONS})
+ set(_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_LIBRARIES})
+ set(_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_FLAGS})
+ set(_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_QUIET})
+
+ if (ARGC GREATER 0 AND ARGV0 STREQUAL "RESET")
+ cmake_reset_check_state()
+ endif()
+
+endmacro()
+
+macro(CMAKE_POP_CHECK_STATE)
+
+# don't pop more than we pushed
+ if("${_CMAKE_PUSH_CHECK_STATE_COUNTER}" GREATER "0")
+
+ set(CMAKE_REQUIRED_INCLUDES ${_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
+ set(CMAKE_REQUIRED_DEFINITIONS ${_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
+ set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
+ set(CMAKE_REQUIRED_FLAGS ${_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
+ set(CMAKE_REQUIRED_QUIET ${_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
+
+ math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}-1")
+ endif()
+
+endmacro()
diff --git a/Modules/CMakeRCCompiler.cmake.in b/Modules/CMakeRCCompiler.cmake.in
new file mode 100644
index 0000000000..8257cd6a1c
--- /dev/null
+++ b/Modules/CMakeRCCompiler.cmake.in
@@ -0,0 +1,6 @@
+set(CMAKE_RC_COMPILER "@CMAKE_RC_COMPILER@")
+set(CMAKE_RC_COMPILER_ARG1 "@CMAKE_RC_COMPILER_ARG1@")
+set(CMAKE_RC_COMPILER_LOADED 1)
+set(CMAKE_RC_SOURCE_FILE_EXTENSIONS rc;RC)
+set(CMAKE_RC_OUTPUT_EXTENSION @CMAKE_RC_OUTPUT_EXTENSION@)
+set(CMAKE_RC_COMPILER_ENV_VAR "RC")
diff --git a/Modules/CMakeRCInformation.cmake b/Modules/CMakeRCInformation.cmake
new file mode 100644
index 0000000000..6bb2636f1f
--- /dev/null
+++ b/Modules/CMakeRCInformation.cmake
@@ -0,0 +1,54 @@
+
+#=============================================================================
+# Copyright 2004-2009 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 sets the basic flags for the Windows Resource Compiler.
+# It also loads the available platform file for the system-compiler
+# if it exists.
+
+# make sure we don't use CMAKE_BASE_NAME from somewhere else
+set(CMAKE_BASE_NAME)
+if(CMAKE_RC_COMPILER MATCHES "windres[^/]*$")
+ set(CMAKE_BASE_NAME "windres")
+else()
+ get_filename_component(CMAKE_BASE_NAME ${CMAKE_RC_COMPILER} NAME_WE)
+endif()
+set(CMAKE_SYSTEM_AND_RC_COMPILER_INFO_FILE
+ ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
+include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
+
+
+
+set (CMAKE_RC_FLAGS "$ENV{RCFLAGS} ${CMAKE_RC_FLAGS_INIT}" CACHE STRING
+ "Flags for Windows Resource Compiler.")
+
+# These are the only types of flags that should be passed to the rc
+# command, if COMPILE_FLAGS is used on a target this will be used
+# to filter out any other flags
+set(CMAKE_RC_FLAG_REGEX "^[-/](D|I)")
+
+# now define the following rule variables
+# CMAKE_RC_COMPILE_OBJECT
+set(CMAKE_INCLUDE_FLAG_RC "-I")
+# compile a Resource file into an object file
+if(NOT CMAKE_RC_COMPILE_OBJECT)
+ set(CMAKE_RC_COMPILE_OBJECT
+ "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> /fo<OBJECT> <SOURCE>")
+endif()
+
+mark_as_advanced(
+CMAKE_RC_FLAGS
+)
+# set this variable so we can avoid loading this more than once.
+set(CMAKE_RC_INFORMATION_LOADED 1)
diff --git a/Modules/CMakeSystem.cmake.in b/Modules/CMakeSystem.cmake.in
new file mode 100644
index 0000000000..70c98d5ca3
--- /dev/null
+++ b/Modules/CMakeSystem.cmake.in
@@ -0,0 +1,15 @@
+set(CMAKE_HOST_SYSTEM "@CMAKE_HOST_SYSTEM@")
+set(CMAKE_HOST_SYSTEM_NAME "@CMAKE_HOST_SYSTEM_NAME@")
+set(CMAKE_HOST_SYSTEM_VERSION "@CMAKE_HOST_SYSTEM_VERSION@")
+set(CMAKE_HOST_SYSTEM_PROCESSOR "@CMAKE_HOST_SYSTEM_PROCESSOR@")
+
+@INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED@
+
+set(CMAKE_SYSTEM "@CMAKE_SYSTEM@")
+set(CMAKE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@")
+set(CMAKE_SYSTEM_VERSION "@CMAKE_SYSTEM_VERSION@")
+set(CMAKE_SYSTEM_PROCESSOR "@CMAKE_SYSTEM_PROCESSOR@")
+
+set(CMAKE_CROSSCOMPILING "@CMAKE_CROSSCOMPILING@")
+
+set(CMAKE_SYSTEM_LOADED 1)
diff --git a/Modules/CMakeSystemSpecificInformation.cmake b/Modules/CMakeSystemSpecificInformation.cmake
new file mode 100644
index 0000000000..b9f8e0aaa0
--- /dev/null
+++ b/Modules/CMakeSystemSpecificInformation.cmake
@@ -0,0 +1,69 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 is included by cmGlobalGenerator::EnableLanguage.
+# It is included after the compiler has been determined, so
+# we know things like the compiler name and if the compiler is gnu.
+
+# before cmake 2.6 these variables were set in cmMakefile.cxx. This is still
+# done to keep scripts and custom language and compiler modules working.
+# But they are reset here and set again in the platform files for the target
+# platform, so they can be used for testing the target platform instead
+# of testing the host platform.
+set(APPLE )
+set(UNIX )
+set(CYGWIN )
+set(WIN32 )
+
+
+# include Generic system information
+include(CMakeGenericSystem)
+
+# 2. now include SystemName.cmake file to set the system specific information
+set(CMAKE_SYSTEM_INFO_FILE Platform/${CMAKE_SYSTEM_NAME})
+
+include(${CMAKE_SYSTEM_INFO_FILE} OPTIONAL RESULT_VARIABLE _INCLUDED_SYSTEM_INFO_FILE)
+
+if(NOT _INCLUDED_SYSTEM_INFO_FILE)
+ message("System is unknown to cmake, create:\n${CMAKE_SYSTEM_INFO_FILE}"
+ " to use this system, please send your config file to "
+ "cmake@www.cmake.org so it can be added to cmake")
+ if(EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
+ configure_file(${CMAKE_BINARY_DIR}/CMakeCache.txt
+ ${CMAKE_BINARY_DIR}/CopyOfCMakeCache.txt COPYONLY)
+ message("Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. "
+ "Please send that file to cmake@www.cmake.org.")
+ endif()
+endif()
+
+
+# optionally include a file which can do extra-generator specific things, e.g.
+# CMakeFindEclipseCDT4.cmake asks gcc for the system include dirs for the Eclipse CDT4 generator
+if(CMAKE_EXTRA_GENERATOR)
+ string(REPLACE " " "" _CMAKE_EXTRA_GENERATOR_NO_SPACES ${CMAKE_EXTRA_GENERATOR} )
+ include("CMakeFind${_CMAKE_EXTRA_GENERATOR_NO_SPACES}" OPTIONAL)
+endif()
+
+
+# for most systems a module is the same as a shared library
+# so unless the variable CMAKE_MODULE_EXISTS is set just
+# copy the values from the LIBRARY variables
+# this has to be done after the system information has been loaded
+if(NOT CMAKE_MODULE_EXISTS)
+ set(CMAKE_SHARED_MODULE_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}")
+ set(CMAKE_SHARED_MODULE_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}")
+endif()
+
+
+set(CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED 1)
diff --git a/Modules/CMakeSystemSpecificInitialize.cmake b/Modules/CMakeSystemSpecificInitialize.cmake
new file mode 100644
index 0000000000..5327ac19be
--- /dev/null
+++ b/Modules/CMakeSystemSpecificInitialize.cmake
@@ -0,0 +1,20 @@
+
+#=============================================================================
+# Copyright 2002-2014 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 is included by cmGlobalGenerator::EnableLanguage.
+# It is included before the compiler has been determined.
+
+include(Platform/${CMAKE_SYSTEM_NAME}-Initialize OPTIONAL)
+
+set(CMAKE_SYSTEM_SPECIFIC_INITIALIZE_LOADED 1)
diff --git a/Modules/CMakeTestASM-ATTCompiler.cmake b/Modules/CMakeTestASM-ATTCompiler.cmake
new file mode 100644
index 0000000000..0cc68573ef
--- /dev/null
+++ b/Modules/CMakeTestASM-ATTCompiler.cmake
@@ -0,0 +1,23 @@
+
+#=============================================================================
+# Copyright 2007-2009 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 is used by EnableLanguage in cmGlobalGenerator to
+# determine that the selected ASM-ATT "compiler" works.
+# For assembler this can only check whether the compiler has been found,
+# because otherwise there would have to be a separate assembler source file
+# for each assembler on every architecture.
+
+set(ASM_DIALECT "-ATT")
+include(CMakeTestASMCompiler)
+set(ASM_DIALECT)
diff --git a/Modules/CMakeTestASMCompiler.cmake b/Modules/CMakeTestASMCompiler.cmake
new file mode 100644
index 0000000000..9381619c4b
--- /dev/null
+++ b/Modules/CMakeTestASMCompiler.cmake
@@ -0,0 +1,35 @@
+
+#=============================================================================
+# Copyright 2007-2009 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 is used by EnableLanguage in cmGlobalGenerator to
+# determine that the selected ASM compiler works.
+# For assembler this can only check whether the compiler has been found,
+# because otherwise there would have to be a separate assembler source file
+# for each assembler on every architecture.
+
+
+set(_ASM_COMPILER_WORKS 0)
+
+if(CMAKE_ASM${ASM_DIALECT}_COMPILER)
+ set(_ASM_COMPILER_WORKS 1)
+endif()
+
+# when using generic "ASM" support, we must have detected the compiler ID, fail otherwise:
+if("ASM${ASM_DIALECT}" STREQUAL "ASM")
+ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
+ set(_ASM_COMPILER_WORKS 0)
+ endif()
+endif()
+
+set(CMAKE_ASM${ASM_DIALECT}_COMPILER_WORKS ${_ASM_COMPILER_WORKS} CACHE INTERNAL "")
diff --git a/Modules/CMakeTestASM_MASMCompiler.cmake b/Modules/CMakeTestASM_MASMCompiler.cmake
new file mode 100644
index 0000000000..462b1fc072
--- /dev/null
+++ b/Modules/CMakeTestASM_MASMCompiler.cmake
@@ -0,0 +1,23 @@
+
+#=============================================================================
+# Copyright 2008-2009 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 is used by EnableLanguage in cmGlobalGenerator to
+# determine that the selected ASM_MASM "compiler" (should be masm or masm64)
+# works. For assembler this can only check whether the compiler has been found,
+# because otherwise there would have to be a separate assembler source file
+# for each assembler on every architecture.
+
+set(ASM_DIALECT "_MASM")
+include(CMakeTestASMCompiler)
+set(ASM_DIALECT)
diff --git a/Modules/CMakeTestASM_NASMCompiler.cmake b/Modules/CMakeTestASM_NASMCompiler.cmake
new file mode 100644
index 0000000000..414c2f550e
--- /dev/null
+++ b/Modules/CMakeTestASM_NASMCompiler.cmake
@@ -0,0 +1,23 @@
+
+#=============================================================================
+# Copyright 2010 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 is used by EnableLanguage in cmGlobalGenerator to
+# determine that the selected ASM_NASM "compiler" works.
+# For assembler this can only check whether the compiler has been found,
+# because otherwise there would have to be a separate assembler source file
+# for each assembler on every architecture.
+
+set(ASM_DIALECT "_NASM")
+include(CMakeTestASMCompiler)
+set(ASM_DIALECT)
diff --git a/Modules/CMakeTestCCompiler.cmake b/Modules/CMakeTestCCompiler.cmake
new file mode 100644
index 0000000000..29a58bdc91
--- /dev/null
+++ b/Modules/CMakeTestCCompiler.cmake
@@ -0,0 +1,96 @@
+
+#=============================================================================
+# Copyright 2003-2012 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.)
+
+if(CMAKE_C_COMPILER_FORCED)
+ # The compiler configuration was forced by the user.
+ # Assume the user has configured all compiler information.
+ set(CMAKE_C_COMPILER_WORKS TRUE)
+ return()
+endif()
+
+include(CMakeTestCompilerCommon)
+
+# Remove any cached result from an older CMake version.
+# We now store this in CMakeCCompiler.cmake.
+unset(CMAKE_C_COMPILER_WORKS CACHE)
+
+# This file is used by EnableLanguage in cmGlobalGenerator to
+# determine that that selected C compiler can actually compile
+# and link the most basic of programs. If not, a fatal error
+# is set and cmake stops processing commands and will not generate
+# any makefiles or projects.
+if(NOT CMAKE_C_COMPILER_WORKS)
+ PrintTestCompilerStatus("C" "")
+ file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler.c
+ "#ifdef __cplusplus\n"
+ "# error \"The CMAKE_C_COMPILER is set to a C++ compiler\"\n"
+ "#endif\n"
+ "#if defined(__CLASSIC_C__)\n"
+ "int main(argc, argv)\n"
+ " int argc;\n"
+ " char* argv[];\n"
+ "#else\n"
+ "int main(int argc, char* argv[])\n"
+ "#endif\n"
+ "{ (void)argv; return argc-1;}\n")
+ try_compile(CMAKE_C_COMPILER_WORKS ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler.c
+ OUTPUT_VARIABLE __CMAKE_C_COMPILER_OUTPUT)
+ # Move result from cache to normal variable.
+ set(CMAKE_C_COMPILER_WORKS ${CMAKE_C_COMPILER_WORKS})
+ unset(CMAKE_C_COMPILER_WORKS CACHE)
+ set(C_TEST_WAS_RUN 1)
+endif()
+
+if(NOT CMAKE_C_COMPILER_WORKS)
+ PrintTestCompilerStatus("C" " -- broken")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the C compiler works failed with "
+ "the following output:\n${__CMAKE_C_COMPILER_OUTPUT}\n\n")
+ message(FATAL_ERROR "The C compiler \"${CMAKE_C_COMPILER}\" "
+ "is not able to compile a simple test program.\nIt fails "
+ "with the following output:\n ${__CMAKE_C_COMPILER_OUTPUT}\n\n"
+ "CMake will not be able to correctly generate this project.")
+else()
+ if(C_TEST_WAS_RUN)
+ PrintTestCompilerStatus("C" " -- works")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the C compiler works passed with "
+ "the following output:\n${__CMAKE_C_COMPILER_OUTPUT}\n\n")
+ endif()
+
+ # Try to identify the ABI and configure it into CMakeCCompiler.cmake
+ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
+ CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c)
+ # Try to identify the compiler features
+ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
+ CMAKE_DETERMINE_COMPILE_FEATURES(C)
+
+ # Re-configure to save learned information.
+ configure_file(
+ ${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeCCompiler.cmake
+ @ONLY
+ )
+ include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCCompiler.cmake)
+
+ if(CMAKE_C_SIZEOF_DATA_PTR)
+ foreach(f ${CMAKE_C_ABI_FILES})
+ include(${f})
+ endforeach()
+ unset(CMAKE_C_ABI_FILES)
+ endif()
+endif()
+
+unset(__CMAKE_C_COMPILER_OUTPUT)
diff --git a/Modules/CMakeTestCXXCompiler.cmake b/Modules/CMakeTestCXXCompiler.cmake
new file mode 100644
index 0000000000..81561b2cbd
--- /dev/null
+++ b/Modules/CMakeTestCXXCompiler.cmake
@@ -0,0 +1,89 @@
+
+#=============================================================================
+# Copyright 2003-2012 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.)
+
+if(CMAKE_CXX_COMPILER_FORCED)
+ # The compiler configuration was forced by the user.
+ # Assume the user has configured all compiler information.
+ set(CMAKE_CXX_COMPILER_WORKS TRUE)
+ return()
+endif()
+
+include(CMakeTestCompilerCommon)
+
+# Remove any cached result from an older CMake version.
+# We now store this in CMakeCXXCompiler.cmake.
+unset(CMAKE_CXX_COMPILER_WORKS CACHE)
+
+# This file is used by EnableLanguage in cmGlobalGenerator to
+# determine that that selected C++ compiler can actually compile
+# and link the most basic of programs. If not, a fatal error
+# is set and cmake stops processing commands and will not generate
+# any makefiles or projects.
+if(NOT CMAKE_CXX_COMPILER_WORKS)
+ PrintTestCompilerStatus("CXX" "")
+ file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
+ "#ifndef __cplusplus\n"
+ "# error \"The CMAKE_CXX_COMPILER is set to a C compiler\"\n"
+ "#endif\n"
+ "int main(){return 0;}\n")
+ try_compile(CMAKE_CXX_COMPILER_WORKS ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
+ OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT)
+ # Move result from cache to normal variable.
+ set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})
+ unset(CMAKE_CXX_COMPILER_WORKS CACHE)
+ set(CXX_TEST_WAS_RUN 1)
+endif()
+
+if(NOT CMAKE_CXX_COMPILER_WORKS)
+ PrintTestCompilerStatus("CXX" " -- broken")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the CXX compiler works failed with "
+ "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
+ message(FATAL_ERROR "The C++ compiler \"${CMAKE_CXX_COMPILER}\" "
+ "is not able to compile a simple test program.\nIt fails "
+ "with the following output:\n ${__CMAKE_CXX_COMPILER_OUTPUT}\n\n"
+ "CMake will not be able to correctly generate this project.")
+else()
+ if(CXX_TEST_WAS_RUN)
+ PrintTestCompilerStatus("CXX" " -- works")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the CXX compiler works passed with "
+ "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
+ endif()
+
+ # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
+ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
+ CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
+ # Try to identify the compiler features
+ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
+ CMAKE_DETERMINE_COMPILE_FEATURES(CXX)
+
+ # Re-configure to save learned information.
+ configure_file(
+ ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake
+ @ONLY
+ )
+ include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake)
+
+ if(CMAKE_CXX_SIZEOF_DATA_PTR)
+ foreach(f ${CMAKE_CXX_ABI_FILES})
+ include(${f})
+ endforeach()
+ unset(CMAKE_CXX_ABI_FILES)
+ endif()
+endif()
+
+unset(__CMAKE_CXX_COMPILER_OUTPUT)
diff --git a/Modules/CMakeTestCompilerCommon.cmake b/Modules/CMakeTestCompilerCommon.cmake
new file mode 100644
index 0000000000..d51b503a1b
--- /dev/null
+++ b/Modules/CMakeTestCompilerCommon.cmake
@@ -0,0 +1,21 @@
+
+#=============================================================================
+# Copyright 2010 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.)
+
+function(PrintTestCompilerStatus LANG MSG)
+ if(CMAKE_GENERATOR MATCHES Make)
+ message(STATUS "Check for working ${LANG} compiler: ${CMAKE_${LANG}_COMPILER}${MSG}")
+ else()
+ message(STATUS "Check for working ${LANG} compiler using: ${CMAKE_GENERATOR}${MSG}")
+ endif()
+endfunction()
diff --git a/Modules/CMakeTestFortranCompiler.cmake b/Modules/CMakeTestFortranCompiler.cmake
new file mode 100644
index 0000000000..b50e832763
--- /dev/null
+++ b/Modules/CMakeTestFortranCompiler.cmake
@@ -0,0 +1,111 @@
+
+#=============================================================================
+# Copyright 2004-2012 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.)
+
+if(CMAKE_Fortran_COMPILER_FORCED)
+ # The compiler configuration was forced by the user.
+ # Assume the user has configured all compiler information.
+ set(CMAKE_Fortran_COMPILER_WORKS TRUE)
+ return()
+endif()
+
+include(CMakeTestCompilerCommon)
+
+# Remove any cached result from an older CMake version.
+# We now store this in CMakeFortranCompiler.cmake.
+unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
+
+# This file is used by EnableLanguage in cmGlobalGenerator to
+# determine that that selected Fortran compiler can actually compile
+# and link the most basic of programs. If not, a fatal error
+# is set and cmake stops processing commands and will not generate
+# any makefiles or projects.
+if(NOT CMAKE_Fortran_COMPILER_WORKS)
+ PrintTestCompilerStatus("Fortran" "")
+ file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f "
+ PROGRAM TESTFortran
+ PRINT *, 'Hello'
+ END
+ ")
+ try_compile(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
+ OUTPUT_VARIABLE OUTPUT)
+ # Move result from cache to normal variable.
+ set(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_Fortran_COMPILER_WORKS})
+ unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
+ set(FORTRAN_TEST_WAS_RUN 1)
+endif()
+
+if(NOT CMAKE_Fortran_COMPILER_WORKS)
+ PrintTestCompilerStatus("Fortran" " -- broken")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the Fortran compiler works failed with "
+ "the following output:\n${OUTPUT}\n\n")
+ message(FATAL_ERROR "The Fortran compiler \"${CMAKE_Fortran_COMPILER}\" "
+ "is not able to compile a simple test program.\nIt fails "
+ "with the following output:\n ${OUTPUT}\n\n"
+ "CMake will not be able to correctly generate this project.")
+else()
+ if(FORTRAN_TEST_WAS_RUN)
+ PrintTestCompilerStatus("Fortran" " -- works")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the Fortran compiler works passed with "
+ "the following output:\n${OUTPUT}\n\n")
+ endif()
+
+ # Try to identify the ABI and configure it into CMakeFortranCompiler.cmake
+ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
+ CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F)
+
+ # Test for Fortran 90 support by using an f90-specific construct.
+ if(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
+ message(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90")
+ file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 "
+ PROGRAM TESTFortran90
+ integer stop ; stop = 1 ; do while ( stop .eq. 0 ) ; end do
+ END PROGRAM TESTFortran90
+")
+ try_compile(CMAKE_Fortran_COMPILER_SUPPORTS_F90 ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90
+ OUTPUT_VARIABLE OUTPUT)
+ if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
+ message(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- yes")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the Fortran compiler supports Fortran 90 passed with "
+ "the following output:\n${OUTPUT}\n\n")
+ set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1)
+ else()
+ message(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- no")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the Fortran compiler supports Fortran 90 failed with "
+ "the following output:\n${OUTPUT}\n\n")
+ set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0)
+ endif()
+ unset(CMAKE_Fortran_COMPILER_SUPPORTS_F90 CACHE)
+ endif()
+
+ # Re-configure to save learned information.
+ configure_file(
+ ${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake
+ @ONLY
+ )
+ include(${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake)
+
+ if(CMAKE_Fortran_SIZEOF_DATA_PTR)
+ foreach(f ${CMAKE_Fortran_ABI_FILES})
+ include(${f})
+ endforeach()
+ unset(CMAKE_Fortran_ABI_FILES)
+ endif()
+endif()
diff --git a/Modules/CMakeTestGNU.c b/Modules/CMakeTestGNU.c
new file mode 100644
index 0000000000..933e5a212b
--- /dev/null
+++ b/Modules/CMakeTestGNU.c
@@ -0,0 +1,9 @@
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
+void THIS_IS_GNU();
+#endif
+#ifdef __MINGW32__
+void THIS_IS_MINGW();
+#endif
+#ifdef __CYGWIN__
+void THIS_IS_CYGWIN();
+#endif
diff --git a/Modules/CMakeTestJavaCompiler.cmake b/Modules/CMakeTestJavaCompiler.cmake
new file mode 100644
index 0000000000..d763412bff
--- /dev/null
+++ b/Modules/CMakeTestJavaCompiler.cmake
@@ -0,0 +1,20 @@
+
+#=============================================================================
+# Copyright 2004-2009 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 is used by EnableLanguage in cmGlobalGenerator to
+# determine that that selected Fortran compiler can actually compile
+# and link the most basic of programs. If not, a fatal error
+# is set and cmake stops processing commands and will not generate
+# any makefiles or projects.
+set(CMAKE_Java_COMPILER_WORKS 1 CACHE INTERNAL "")
diff --git a/Modules/CMakeTestRCCompiler.cmake b/Modules/CMakeTestRCCompiler.cmake
new file mode 100644
index 0000000000..7969da1de3
--- /dev/null
+++ b/Modules/CMakeTestRCCompiler.cmake
@@ -0,0 +1,23 @@
+
+#=============================================================================
+# Copyright 2004-2009 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 is used by EnableLanguage in cmGlobalGenerator to
+# determine that that selected RC compiler can actually compile
+# and link the most basic of programs. If not, a fatal error
+# is set and cmake stops processing commands and will not generate
+# any makefiles or projects.
+
+# For now there is no way to do a try compile on just a .rc file
+# so just do nothing in here.
+set(CMAKE_RC_COMPILER_WORKS 1 CACHE INTERNAL "")
diff --git a/Modules/CMakeTestWatcomVersion.c b/Modules/CMakeTestWatcomVersion.c
new file mode 100644
index 0000000000..0343fb1279
--- /dev/null
+++ b/Modules/CMakeTestWatcomVersion.c
@@ -0,0 +1 @@
+VERSION=__WATCOMC__
diff --git a/Modules/CMakeUnixFindMake.cmake b/Modules/CMakeUnixFindMake.cmake
new file mode 100644
index 0000000000..3714926570
--- /dev/null
+++ b/Modules/CMakeUnixFindMake.cmake
@@ -0,0 +1,26 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+find_program(CMAKE_MAKE_PROGRAM NAMES gmake make smake)
+mark_as_advanced(CMAKE_MAKE_PROGRAM)
+
+# Look for a make tool provided by Xcode
+if(NOT CMAKE_MAKE_PROGRAM AND CMAKE_HOST_APPLE)
+ execute_process(COMMAND xcrun --find make
+ OUTPUT_VARIABLE _xcrun_out OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE _xcrun_err)
+ if(_xcrun_out)
+ set_property(CACHE CMAKE_MAKE_PROGRAM PROPERTY VALUE "${_xcrun_out}")
+ endif()
+endif()
diff --git a/Modules/CMakeVS6BackwardCompatibility.cmake b/Modules/CMakeVS6BackwardCompatibility.cmake
new file mode 100644
index 0000000000..ca48b8587a
--- /dev/null
+++ b/Modules/CMakeVS6BackwardCompatibility.cmake
@@ -0,0 +1,26 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+# hard code these for fast backwards compatibility tests
+set (CMAKE_SIZEOF_INT 4 CACHE INTERNAL "Size of int data type")
+set (CMAKE_SIZEOF_LONG 4 CACHE INTERNAL "Size of long data type")
+set (CMAKE_SIZEOF_VOID_P 4 CACHE INTERNAL "Size of void* data type")
+set (CMAKE_SIZEOF_CHAR 1 CACHE INTERNAL "Size of char data type")
+set (CMAKE_SIZEOF_SHORT 2 CACHE INTERNAL "Size of short data type")
+set (CMAKE_SIZEOF_FLOAT 4 CACHE INTERNAL "Size of float data type")
+set (CMAKE_SIZEOF_DOUBLE 8 CACHE INTERNAL "Size of double data type")
+set (CMAKE_NO_ANSI_FOR_SCOPE 1 CACHE INTERNAL
+ "Does the compiler support ansi for scope.")
+set (CMAKE_USE_WIN32_THREADS TRUE CACHE BOOL "Use the win32 thread library.")
+set (CMAKE_WORDS_BIGENDIAN 0 CACHE INTERNAL "endianness of bytes")
diff --git a/Modules/CMakeVS7BackwardCompatibility.cmake b/Modules/CMakeVS7BackwardCompatibility.cmake
new file mode 100644
index 0000000000..e9622eecfe
--- /dev/null
+++ b/Modules/CMakeVS7BackwardCompatibility.cmake
@@ -0,0 +1,26 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+# hard code these for fast backwards compatibility tests
+set (CMAKE_SIZEOF_INT 4 CACHE INTERNAL "Size of int data type")
+set (CMAKE_SIZEOF_LONG 4 CACHE INTERNAL "Size of long data type")
+set (CMAKE_SIZEOF_VOID_P 4 CACHE INTERNAL "Size of void* data type")
+set (CMAKE_SIZEOF_CHAR 1 CACHE INTERNAL "Size of char data type")
+set (CMAKE_SIZEOF_SHORT 2 CACHE INTERNAL "Size of short data type")
+set (CMAKE_SIZEOF_FLOAT 4 CACHE INTERNAL "Size of float data type")
+set (CMAKE_SIZEOF_DOUBLE 8 CACHE INTERNAL "Size of double data type")
+set (CMAKE_NO_ANSI_FOR_SCOPE 0 CACHE INTERNAL
+ "Does the compiler support ansi for scope.")
+set (CMAKE_USE_WIN32_THREADS TRUE CACHE BOOL "Use the win32 thread library.")
+set (CMAKE_WORDS_BIGENDIAN 0 CACHE INTERNAL "endianness of bytes")
diff --git a/Modules/CMakeVerifyManifest.cmake b/Modules/CMakeVerifyManifest.cmake
new file mode 100644
index 0000000000..bff4e1e941
--- /dev/null
+++ b/Modules/CMakeVerifyManifest.cmake
@@ -0,0 +1,120 @@
+#.rst:
+# CMakeVerifyManifest
+# -------------------
+#
+#
+#
+# CMakeVerifyManifest.cmake
+#
+# This script is used to verify that embeded manifests and side by side
+# manifests for a project match. To run this script, cd to a directory
+# and run the script with cmake -P. On the command line you can pass in
+# versions that are OK even if not found in the .manifest files. For
+# example, cmake -Dallow_versions=8.0.50608.0
+# -PCmakeVerifyManifest.cmake could be used to allow an embeded manifest
+# of 8.0.50608.0 to be used in a project even if that version was not
+# found in the .manifest file.
+
+# This script first recursively globs *.manifest files from
+# the current directory. Then globs *.exe and *.dll. Each
+# .exe and .dll is scanned for embeded manifests and the versions
+# of CRT are compared to those found in the .manifest files
+# from the first glob.
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+
+# crt_version:
+# function to extract the CRT version from a file
+# this can be passed a .exe, .dll, or a .manifest file
+# it will put the list of versions found into the variable
+# specified by list_var
+function(crt_version file list_var)
+ file(STRINGS "${file}" strings REGEX "Microsoft.VC...CRT" NEWLINE_CONSUME)
+ foreach(s ${strings})
+ set(has_match 1)
+ string(REGEX
+ REPLACE ".*<assembly.*\"Microsoft.VC...CRT\".*version=\"([^\"]*)\".*</assembly>.*$" "\\1"
+ version "${s}")
+ if(NOT "${version}" STREQUAL "")
+ list(APPEND version_list ${version})
+ else()
+ message(FATAL_ERROR "Parse error could not find version in [${s}]")
+ endif()
+ endforeach()
+ if(NOT DEFINED has_match)
+ message("Information: no embeded manifest in: ${file}")
+ return()
+ endif()
+ list(APPEND version_list ${${list_var}})
+ list(REMOVE_DUPLICATES version_list)
+ if(version_list)
+ set(${list_var} ${version_list} PARENT_SCOPE)
+ endif()
+endfunction()
+set(fatal_error FALSE)
+
+# check_version:
+#
+# test a file against the shipped manifest versions
+# for a directory
+function(check_version file manifest_versions)
+ set(manifest_versions ${manifest_versions} ${allow_versions})
+ # collect versions for a given file
+ crt_version(${file} file_versions)
+ # see if the versions
+ foreach(ver ${file_versions})
+ list(FIND manifest_versions "${ver}" found_version)
+ if("${found_version}" EQUAL -1)
+ message("ERROR: ${file} uses ${ver} not found in shipped manifests:[${manifest_versions}].")
+ set(fatal_error TRUE PARENT_SCOPE)
+ endif()
+ endforeach()
+ list(LENGTH file_versions len)
+ if(${len} GREATER 1)
+ message("WARNING: found more than one version of MICROSOFT.VC80.CRT referenced in ${file}: [${file_versions}]")
+ endif()
+endfunction()
+
+# collect up the versions of CRT that are shipped
+# in .manifest files
+set(manifest_version_list )
+file(GLOB_RECURSE manifest_files "*.manifest")
+foreach(f ${manifest_files})
+ crt_version("${f}" manifest_version_list)
+endforeach()
+list(LENGTH manifest_version_list LEN)
+if(LEN EQUAL 0)
+ message(FATAL_ERROR "No .manifest files found, no version check can be done.")
+endif()
+message("Versions found in ${manifest_files}: ${manifest_version_list}")
+if(DEFINED allow_versions)
+ message("Extra versions allowed: ${allow_versions}")
+endif()
+
+# now find all .exe and .dll files
+# and call check_version on each of them
+file(GLOB_RECURSE exe_files "*.exe")
+file(GLOB_RECURSE dll_files "*.dll")
+set(exe_files ${exe_files} ${dll_files})
+foreach(f ${exe_files})
+ check_version(${f} "${manifest_version_list}")
+endforeach()
+
+# report a fatal error if there were any so that cmake will return
+# a non zero value
+if(fatal_error)
+ message(FATAL_ERROR "This distribution embeds dll "
+ " versions that it does not ship, and may not work on other machines.")
+endif()
diff --git a/Modules/CPack.DS_Store.in b/Modules/CPack.DS_Store.in
new file mode 100644
index 0000000000..5be0eeb180
--- /dev/null
+++ b/Modules/CPack.DS_Store.in
Binary files differ
diff --git a/Modules/CPack.Description.plist.in b/Modules/CPack.Description.plist.in
new file mode 100644
index 0000000000..3d1147686d
--- /dev/null
+++ b/Modules/CPack.Description.plist.in
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.4">
+<dict>
+ <key>IFPkgDescriptionTitle</key>
+ <string>@CPACK_PACKAGE_NAME@</string>
+ <key>IFPkgDescriptionVersion</key>
+ <string>@CPACK_PACKAGE_VERSION@</string>
+ <key>IFPkgDescriptionDescription</key>
+ <string>@CPACK_PACKAGE_DESCRIPTION@</string>
+</dict>
+</plist>
diff --git a/Modules/CPack.Info.plist.in b/Modules/CPack.Info.plist.in
new file mode 100644
index 0000000000..6e325001cf
--- /dev/null
+++ b/Modules/CPack.Info.plist.in
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+
+<plist version="1.0">
+<dict>
+<key>IFMajorVersion</key>
+<integer>@CPACK_PACKAGE_VERSION_MAJOR@</integer>
+<key>IFMinorVersion</key>
+<integer>@CPACK_PACKAGE_VERSION_MINOR@</integer>
+<key>IFPkgFlagAllowBackRev</key>
+<false/>
+<key>IFPkgFlagAuthorizationAction</key>
+<string>AdminAuthorization</string>
+<key>IFPkgFlagDefaultLocation</key>
+<string>@CPACK_PACKAGE_DEFAULT_LOCATION@</string>
+<key>IFPkgFlagInstallFat</key>
+<false/>
+<key>IFPkgFlagIsRequired</key>
+<false/>
+<key>IFPkgFlagOverwritePermissions</key>
+<true/>
+<key>IFPkgFlagRelocatable</key>
+<@CPACK_PACKAGE_RELOCATABLE@/>
+<key>IFPkgFlagRestartAction</key>
+<string>NoRestart</string>
+<key>IFPkgFlagRootVolumeOnly</key>
+<false/>
+<key>IFPkgFlagUpdateInstalledLanguages</key>
+<false/>
+<key>IFPkgFlagUseUserMask</key>
+<false/>
+<key>IFPkgFormatVersion</key>
+<real>0.10000000149011612</real>
+<key>CFBundleIdentifier</key>
+<string>com.@CPACK_PACKAGE_VENDOR@.@CPACK_PACKAGE_NAME@@CPACK_MODULE_VERSION_SUFFIX@</string>
+</dict>
+</plist>
diff --git a/Modules/CPack.OSXScriptLauncher.in b/Modules/CPack.OSXScriptLauncher.in
new file mode 100755
index 0000000000..c715860463
--- /dev/null
+++ b/Modules/CPack.OSXScriptLauncher.in
Binary files differ
diff --git a/Modules/CPack.OSXScriptLauncher.rsrc.in b/Modules/CPack.OSXScriptLauncher.rsrc.in
new file mode 100644
index 0000000000..5f5f17a1c7
--- /dev/null
+++ b/Modules/CPack.OSXScriptLauncher.rsrc.in
Binary files differ
diff --git a/Modules/CPack.OSXX11.Info.plist.in b/Modules/CPack.OSXX11.Info.plist.in
new file mode 100644
index 0000000000..851b67ba82
--- /dev/null
+++ b/Modules/CPack.OSXX11.Info.plist.in
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleDocumentTypes</key>
+ <array>
+ <dict>
+ <key>CFBundleTypeExtensions</key>
+ <array>
+ <string>@CPACK_FILE_ASSOCIATION_EXTENSION@</string>
+ </array>
+ <key>CFBundleTypeName</key>
+ <string>@CPACK_FILE_ASSOCIATION_TYPE@</string>
+ <key>CFBundleTypeRole</key>
+ <string>Editor</string>
+ </dict>
+ </array>
+ <key>CFBundleExecutable</key>
+ <string>@CPACK_PACKAGE_FILE_NAME@</string>
+ <key>CFBundleGetInfoString</key>
+ <string>@CPACK_APPLE_GUI_INFO_STRING@</string>
+ <key>CFBundleIconFile</key>
+ <string>@CPACK_APPLE_GUI_ICON@</string>
+ <key>CFBundleIdentifier</key>
+ <string>@CPACK_APPLE_GUI_IDENTIFIER@</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleLongVersionString</key>
+ <string>@CPACK_APPLE_GUI_LONG_VERSION_STRING@</string>
+ <key>CFBundleName</key>
+ <string>@CPACK_APPLE_GUI_BUNDLE_NAME@</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>@CPACK_APPLE_GUI_SHORT_VERSION_STRING@</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>@CPACK_APPLE_GUI_BUNDLE_VERSION@</string>
+ <key>CSResourcesFileMapped</key>
+ <true/>
+ <key>LSRequiresCarbon</key>
+ <true/>
+ <key>NSHumanReadableCopyright</key>
+ <string>@CPACK_APPLE_GUI_COPYRIGHT@</string>
+</dict>
+</plist>
diff --git a/Modules/CPack.OSXX11.main.scpt.in b/Modules/CPack.OSXX11.main.scpt.in
new file mode 100644
index 0000000000..de30ea11b4
--- /dev/null
+++ b/Modules/CPack.OSXX11.main.scpt.in
Binary files differ
diff --git a/Modules/CPack.RuntimeScript.in b/Modules/CPack.RuntimeScript.in
new file mode 100755
index 0000000000..f27444fd9d
--- /dev/null
+++ b/Modules/CPack.RuntimeScript.in
@@ -0,0 +1,87 @@
+#!/bin/sh
+#
+# Modified from: Aaron Voisine <aaron@voisine.org>
+
+CWD="`dirname \"$0\"`"
+TMP=/tmp/$(id -ru)/TemporaryItems
+
+version=`sw_vers -productVersion`
+if [ "$?" = "0" ]; then
+ major=${version%%\.*}
+ rest=${version#*\.}
+ minor=${rest%%\.*}
+ build=${rest#*\.}
+else
+ major=10
+ minor=4
+ build=0
+fi
+
+echo $version
+echo "Major = $major"
+echo "Minor = $minor"
+echo "Build = $build"
+
+
+# if 10.5 or greater, then all the open-x11 stuff need not occur
+if [ "$major" -lt 10 ] || ([ "$major" -eq 10 ] && [ "$minor" -lt 5 ]); then
+version=`sw_vers -productVersion`
+if [ "$?" = "0" ]; then
+ major=${version%%\.*}
+ rest=${version#*\.}
+ minor=${rest%%\.*}
+ build=${rest#*\.}
+else
+ major=10
+ minor=4
+ build=0
+fi
+
+echo $version
+echo "Major = $major"
+echo "Minor = $minor"
+echo "Build = $build"
+
+
+# if 10.5 or greater, then all the open-x11 stuff need not occur
+if [ "$major" -lt 10 ] || ([ "$major" -eq 10 ] && [ "$minor" -lt 5 ]); then
+ps -wx -ocommand | grep -e '[X]11.app' > /dev/null
+if [ "$?" != "0" -a ! -f ~/.xinitrc ]; then
+ echo "rm -f ~/.xinitrc" > ~/.xinitrc
+ sed 's/xterm/# xterm/' /usr/X11R6/lib/X11/xinit/xinitrc >> ~/.xinitrc
+fi
+
+mkdir -p $TMP
+cat << __END_OF_GETDISPLAY_SCRIPT__ > "$TMP/getdisplay.sh"
+#!/bin/sh
+mkdir -p "$TMP"
+
+if [ "\$DISPLAY"x = "x" ]; then
+ echo :0 > "$TMP/display"
+else
+ echo \$DISPLAY > "$TMP/display"
+fi
+__END_OF_GETDISPLAY_SCRIPT__
+fi
+chmod +x "$TMP/getdisplay.sh"
+rm -f $TMP/display
+open-x11 $TMP/getdisplay.sh || \
+open -a XDarwin $TMP/getdisplay.sh || \
+echo ":0" > $TMP/display
+
+while [ "$?" = "0" -a ! -f $TMP/display ];
+do
+ #echo "Waiting for display $TMP/display"
+ sleep 1;
+done
+export "DISPLAY=`cat $TMP/display`"
+
+ps -wx -ocommand | grep -e '[X]11' > /dev/null || exit 11
+
+cd ~/
+echo "$@" > /tmp/arguments.log
+if echo $1 | grep -- "^-psn_"; then
+ shift
+fi
+fi
+exec "$CWD/bin/@CPACK_EXECUTABLE_NAME@" "$@" > /tmp/slicer.output 2>&1
diff --git a/Modules/CPack.STGZ_Header.sh.in b/Modules/CPack.STGZ_Header.sh.in
new file mode 100755
index 0000000000..dee576fb57
--- /dev/null
+++ b/Modules/CPack.STGZ_Header.sh.in
@@ -0,0 +1,141 @@
+#!/bin/sh
+
+# Display usage
+cpack_usage()
+{
+ cat <<EOF
+Usage: $0 [options]
+Options: [defaults in brackets after descriptions]
+ --help print this message
+ --prefix=dir directory in which to install
+ --include-subdir include the @CPACK_PACKAGE_FILE_NAME@ subdirectory
+ --exclude-subdir exclude the @CPACK_PACKAGE_FILE_NAME@ subdirectory
+EOF
+ exit 1
+}
+
+cpack_echo_exit()
+{
+ echo $1
+ exit 1
+}
+
+# Display version
+cpack_version()
+{
+ echo "@CPACK_PACKAGE_NAME@ Installer Version: @CPACK_PACKAGE_VERSION@, Copyright (c) @CPACK_PACKAGE_VENDOR@"
+}
+
+# Helper function to fix windows paths.
+cpack_fix_slashes ()
+{
+ echo "$1" | sed 's/\\/\//g'
+}
+
+interactive=TRUE
+cpack_skip_license=FALSE
+cpack_include_subdir=""
+for a in "$@CPACK_AT_SIGN@"; do
+ if echo $a | grep "^--prefix=" > /dev/null 2> /dev/null; then
+ cpack_prefix_dir=`echo $a | sed "s/^--prefix=//"`
+ cpack_prefix_dir=`cpack_fix_slashes "${cpack_prefix_dir}"`
+ fi
+ if echo $a | grep "^--help" > /dev/null 2> /dev/null; then
+ cpack_usage
+ fi
+ if echo $a | grep "^--version" > /dev/null 2> /dev/null; then
+ cpack_version
+ exit 2
+ fi
+ if echo $a | grep "^--include-subdir" > /dev/null 2> /dev/null; then
+ cpack_include_subdir=TRUE
+ fi
+ if echo $a | grep "^--exclude-subdir" > /dev/null 2> /dev/null; then
+ cpack_include_subdir=FALSE
+ fi
+ if echo $a | grep "^--skip-license" > /dev/null 2> /dev/null; then
+ cpack_skip_license=TRUE
+ fi
+done
+
+if [ "x${cpack_include_subdir}x" != "xx" -o "x${cpack_skip_license}x" = "xTRUEx" ]
+then
+ interactive=FALSE
+fi
+
+cpack_version
+echo "This is a self-extracting archive."
+toplevel="`pwd`"
+if [ "x${cpack_prefix_dir}x" != "xx" ]
+then
+ toplevel="${cpack_prefix_dir}"
+fi
+
+echo "The archive will be extracted to: ${toplevel}"
+
+if [ "x${interactive}x" = "xTRUEx" ]
+then
+ echo ""
+ echo "If you want to stop extracting, please press <ctrl-C>."
+
+ if [ "x${cpack_skip_license}x" != "xTRUEx" ]
+ then
+ more << '____cpack__here_doc____'
+@CPACK_RESOURCE_FILE_LICENSE_CONTENT@
+____cpack__here_doc____
+ echo
+ echo "Do you accept the license? [yN]: "
+ read line leftover
+ case ${line} in
+ y* | Y*)
+ cpack_license_accepted=TRUE;;
+ *)
+ echo "License not accepted. Exiting ..."
+ exit 1;;
+ esac
+ fi
+
+ if [ "x${cpack_include_subdir}x" = "xx" ]
+ then
+ echo "By default the @CPACK_PACKAGE_NAME@ will be installed in:"
+ echo " \"${toplevel}/@CPACK_PACKAGE_FILE_NAME@\""
+ echo "Do you want to include the subdirectory @CPACK_PACKAGE_FILE_NAME@?"
+ echo "Saying no will install in: \"${toplevel}\" [Yn]: "
+ read line leftover
+ cpack_include_subdir=TRUE
+ case ${line} in
+ n* | N*)
+ cpack_include_subdir=FALSE
+ esac
+ fi
+fi
+
+if [ "x${cpack_include_subdir}x" = "xTRUEx" ]
+then
+ toplevel="${toplevel}/@CPACK_PACKAGE_FILE_NAME@"
+ mkdir -p "${toplevel}"
+fi
+echo
+echo "Using target directory: ${toplevel}"
+echo "Extracting, please wait..."
+echo ""
+
+# take the archive portion of this file and pipe it to tar
+# the NUMERIC parameter in this command should be one more
+# than the number of lines in this header file
+# there are tails which don't understand the "-n" argument, e.g. on SunOS
+# OTOH there are tails which complain when not using the "-n" argument (e.g. GNU)
+# so at first try to tail some file to see if tail fails if used with "-n"
+# if so, don't use "-n"
+use_new_tail_syntax="-n"
+tail $use_new_tail_syntax +1 "$0" > /dev/null 2> /dev/null || use_new_tail_syntax=""
+
+tail $use_new_tail_syntax +###CPACK_HEADER_LENGTH### "$0" | gunzip | (cd "${toplevel}" && tar xf -) || cpack_echo_exit "Problem unpacking the @CPACK_PACKAGE_FILE_NAME@"
+
+echo "Unpacking finished successfully"
+
+exit 0
+#-----------------------------------------------------------
+# Start of TAR.GZ file
+#-----------------------------------------------------------;
+
diff --git a/Modules/CPack.VolumeIcon.icns.in b/Modules/CPack.VolumeIcon.icns.in
new file mode 100644
index 0000000000..c59217eaef
--- /dev/null
+++ b/Modules/CPack.VolumeIcon.icns.in
Binary files differ
diff --git a/Modules/CPack.background.png.in b/Modules/CPack.background.png.in
new file mode 100644
index 0000000000..9339e7cad2
--- /dev/null
+++ b/Modules/CPack.background.png.in
Binary files differ
diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake
new file mode 100644
index 0000000000..35259c493e
--- /dev/null
+++ b/Modules/CPack.cmake
@@ -0,0 +1,613 @@
+#.rst:
+# CPack
+# -----
+#
+# Build binary and source package installers.
+#
+# Variables common to all CPack generators
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# The
+# CPack module generates binary and source installers in a variety of
+# formats using the cpack program. Inclusion of the CPack module adds
+# two new targets to the resulting makefiles, package and
+# package_source, which build the binary and source installers,
+# respectively. The generated binary installers contain everything
+# installed via CMake's INSTALL command (and the deprecated
+# INSTALL_FILES, INSTALL_PROGRAMS, and INSTALL_TARGETS commands).
+#
+# For certain kinds of binary installers (including the graphical
+# installers on Mac OS X and Windows), CPack generates installers that
+# allow users to select individual application components to install.
+# See CPackComponent module for that.
+#
+# The CPACK_GENERATOR variable has different meanings in different
+# contexts. In your CMakeLists.txt file, CPACK_GENERATOR is a *list of
+# generators*: when run with no other arguments, CPack will iterate over
+# that list and produce one package for each generator. In a
+# CPACK_PROJECT_CONFIG_FILE, though, CPACK_GENERATOR is a *string naming
+# a single generator*. If you need per-cpack- generator logic to
+# control *other* cpack settings, then you need a
+# CPACK_PROJECT_CONFIG_FILE.
+#
+# The CMake source tree itself contains a CPACK_PROJECT_CONFIG_FILE.
+# See the top level file CMakeCPackOptions.cmake.in for an example.
+#
+# If set, the CPACK_PROJECT_CONFIG_FILE is included automatically on a
+# per-generator basis. It only need contain overrides.
+#
+# Here's how it works:
+#
+# * cpack runs
+# * it includes CPackConfig.cmake
+# * it iterates over the generators listed in that file's
+# CPACK_GENERATOR list variable (unless told to use just a
+# specific one via -G on the command line...)
+# * foreach generator, it then
+#
+# - sets CPACK_GENERATOR to the one currently being iterated
+# - includes the CPACK_PROJECT_CONFIG_FILE
+# - produces the package for that generator
+#
+# This is the key: For each generator listed in CPACK_GENERATOR in
+# CPackConfig.cmake, cpack will *reset* CPACK_GENERATOR internally to
+# *the one currently being used* and then include the
+# CPACK_PROJECT_CONFIG_FILE.
+#
+# Before including this CPack module in your CMakeLists.txt file, there
+# are a variety of variables that can be set to customize the resulting
+# installers. The most commonly-used variables are:
+#
+# .. variable:: CPACK_PACKAGE_NAME
+#
+# The name of the package (or application). If not specified, defaults to
+# the project name.
+#
+# .. variable:: CPACK_PACKAGE_VENDOR
+#
+# The name of the package vendor. (e.g., "Kitware").
+#
+# .. variable:: CPACK_PACKAGE_DIRECTORY
+#
+# The directory in which CPack is doing its packaging. If it is not set
+# then this will default (internally) to the build dir. This variable may
+# be defined in CPack config file or from the cpack command line option
+# "-B". If set the command line option override the value found in the
+# config file.
+#
+# .. variable:: CPACK_PACKAGE_VERSION_MAJOR
+#
+# Package major Version
+#
+# .. variable:: CPACK_PACKAGE_VERSION_MINOR
+#
+# Package minor Version
+#
+# .. variable:: CPACK_PACKAGE_VERSION_PATCH
+#
+# Package patch Version
+#
+# .. variable:: CPACK_PACKAGE_DESCRIPTION_FILE
+#
+# A text file used to describe the project. Used, for example, the
+# introduction screen of a CPack-generated Windows installer to describe
+# the project.
+#
+# .. variable:: CPACK_PACKAGE_DESCRIPTION_SUMMARY
+#
+# Short description of the project (only a few words).
+#
+# .. variable:: CPACK_PACKAGE_FILE_NAME
+#
+# The name of the package file to generate, not including the
+# extension. For example, cmake-2.6.1-Linux-i686. The default value is::
+#
+# ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}.
+#
+# .. variable:: CPACK_PACKAGE_INSTALL_DIRECTORY
+#
+# Installation directory on the target system. This may be used by some
+# CPack generators like NSIS to create an installation directory e.g.,
+# "CMake 2.5" below the installation prefix. All installed element will be
+# put inside this directory.
+#
+# .. variable:: CPACK_PACKAGE_ICON
+#
+# A branding image that will be displayed inside the installer (used by GUI
+# installers).
+#
+# .. variable:: CPACK_PROJECT_CONFIG_FILE
+#
+# CPack-time project CPack configuration file. This file included at cpack
+# time, once per generator after CPack has set CPACK_GENERATOR to the
+# actual generator being used. It allows per-generator setting of CPACK_*
+# variables at cpack time.
+#
+# .. variable:: CPACK_RESOURCE_FILE_LICENSE
+#
+# License to be embedded in the installer. It will typically be displayed
+# to the user by the produced installer (often with an explicit "Accept"
+# button, for graphical installers) prior to installation. This license
+# file is NOT added to installed file but is used by some CPack generators
+# like NSIS. If you want to install a license file (may be the same as this
+# one) along with your project you must add an appropriate CMake INSTALL
+# command in your CMakeLists.txt.
+#
+# .. variable:: CPACK_RESOURCE_FILE_README
+#
+# ReadMe file to be embedded in the installer. It typically describes in
+# some detail the purpose of the project during the installation. Not all
+# CPack generators uses this file.
+#
+# .. variable:: CPACK_RESOURCE_FILE_WELCOME
+#
+# Welcome file to be embedded in the installer. It welcomes users to this
+# installer. Typically used in the graphical installers on Windows and Mac
+# OS X.
+#
+# .. variable:: CPACK_MONOLITHIC_INSTALL
+#
+# Disables the component-based installation mechanism. When set the
+# component specification is ignored and all installed items are put in a
+# single "MONOLITHIC" package. Some CPack generators do monolithic
+# packaging by default and may be asked to do component packaging by
+# setting CPACK_<GENNAME>_COMPONENT_INSTALL to 1/TRUE.
+#
+# .. variable:: CPACK_GENERATOR
+#
+# List of CPack generators to use. If not specified, CPack will create a
+# set of options CPACK_BINARY_<GENNAME> (e.g., CPACK_BINARY_NSIS) allowing
+# the user to enable/disable individual generators. This variable may be
+# used on the command line as well as in::
+#
+# cpack -D CPACK_GENERATOR="ZIP;TGZ" /path/to/build/tree
+#
+# .. variable:: CPACK_OUTPUT_CONFIG_FILE
+#
+# The name of the CPack binary configuration file. This file is the CPack
+# configuration generated by the CPack module for binary
+# installers. Defaults to CPackConfig.cmake.
+#
+# .. variable:: CPACK_PACKAGE_EXECUTABLES
+#
+# Lists each of the executables and associated text label to be used to
+# create Start Menu shortcuts. For example, setting this to the list
+# ccmake;CMake will create a shortcut named "CMake" that will execute the
+# installed executable ccmake. Not all CPack generators use it (at least
+# NSIS, WIX and OSXX11 do).
+#
+# .. variable:: CPACK_STRIP_FILES
+#
+# List of files to be stripped. Starting with CMake 2.6.0 CPACK_STRIP_FILES
+# will be a boolean variable which enables stripping of all files (a list
+# of files evaluates to TRUE in CMake, so this change is compatible).
+#
+# The following CPack variables are specific to source packages, and
+# will not affect binary packages:
+#
+# .. variable:: CPACK_SOURCE_PACKAGE_FILE_NAME
+#
+# The name of the source package. For example cmake-2.6.1.
+#
+# .. variable:: CPACK_SOURCE_STRIP_FILES
+#
+# List of files in the source tree that will be stripped. Starting with
+# CMake 2.6.0 CPACK_SOURCE_STRIP_FILES will be a boolean variable which
+# enables stripping of all files (a list of files evaluates to TRUE in
+# CMake, so this change is compatible).
+#
+# .. variable:: CPACK_SOURCE_GENERATOR
+#
+# List of generators used for the source packages. As with CPACK_GENERATOR,
+# if this is not specified then CPack will create a set of options (e.g.,
+# CPACK_SOURCE_ZIP) allowing users to select which packages will be
+# generated.
+#
+# .. variable:: CPACK_SOURCE_OUTPUT_CONFIG_FILE
+#
+# The name of the CPack source configuration file. This file is the CPack
+# configuration generated by the CPack module for source
+# installers. Defaults to CPackSourceConfig.cmake.
+#
+# .. variable:: CPACK_SOURCE_IGNORE_FILES
+#
+# Pattern of files in the source tree that won't be packaged when building
+# a source package. This is a list of regular expression patterns (that
+# must be properly escaped), e.g.,
+# /CVS/;/\\.svn/;\\.swp$;\\.#;/#;.*~;cscope.*
+#
+# The following variables are for advanced uses of CPack:
+#
+# .. variable:: CPACK_CMAKE_GENERATOR
+#
+# What CMake generator should be used if the project is CMake
+# project. Defaults to the value of CMAKE_GENERATOR few users will want to
+# change this setting.
+#
+# .. variable:: CPACK_INSTALL_CMAKE_PROJECTS
+#
+# List of four values that specify what project to install. The four values
+# are: Build directory, Project Name, Project Component, Directory. If
+# omitted, CPack will build an installer that installers everything.
+#
+# .. variable:: CPACK_SYSTEM_NAME
+#
+# System name, defaults to the value of ${CMAKE_SYSTEM_NAME}.
+#
+# .. variable:: CPACK_PACKAGE_VERSION
+#
+# Package full version, used internally. By default, this is built from
+# CPACK_PACKAGE_VERSION_MAJOR, CPACK_PACKAGE_VERSION_MINOR, and
+# CPACK_PACKAGE_VERSION_PATCH.
+#
+# .. variable:: CPACK_TOPLEVEL_TAG
+#
+# Directory for the installed files.
+#
+# .. variable:: CPACK_INSTALL_COMMANDS
+#
+# Extra commands to install components.
+#
+# .. variable:: CPACK_INSTALLED_DIRECTORIES
+#
+# Extra directories to install.
+#
+# .. variable:: CPACK_PACKAGE_INSTALL_REGISTRY_KEY
+#
+# Registry key used when installing this project. This is only used by
+# installer for Windows. The default value is based on the installation
+# directory.
+#
+# .. variable:: CPACK_CREATE_DESKTOP_LINKS
+#
+# List of desktop links to create.
+# Each desktop link requires a corresponding start menu shortcut
+# as created by :variable:`CPACK_PACKAGE_EXECUTABLES`.
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+# Define this var in order to avoid (or warn) concerning multiple inclusion
+if(CPack_CMake_INCLUDED)
+ message(WARNING "CPack.cmake has already been included!!")
+else()
+ set(CPack_CMake_INCLUDED 1)
+endif()
+
+# Pick a configuration file
+set(cpack_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in")
+if(EXISTS "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in")
+ set(cpack_input_file "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in")
+endif()
+set(cpack_source_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in")
+if(EXISTS "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in")
+ set(cpack_source_input_file "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in")
+endif()
+
+# Backward compatibility
+# Include CPackComponent macros if it has not already been included before.
+include(CPackComponent)
+
+# Macro for setting values if a user did not overwrite them
+macro(cpack_set_if_not_set name value)
+ if(NOT DEFINED "${name}")
+ set(${name} "${value}")
+ endif()
+endmacro()
+
+# cpack_encode_variables - Macro to encode variables for the configuration file
+# find any variable that starts with CPACK and create a variable
+# _CPACK_OTHER_VARIABLES_ that contains SET commands for
+# each cpack variable. _CPACK_OTHER_VARIABLES_ is then
+# used as an @ replacment in configure_file for the CPackConfig.
+macro(cpack_encode_variables)
+ set(_CPACK_OTHER_VARIABLES_)
+ get_cmake_property(res VARIABLES)
+ foreach(var ${res})
+ if("xxx${var}" MATCHES "xxxCPACK")
+ set(_CPACK_OTHER_VARIABLES_
+ "${_CPACK_OTHER_VARIABLES_}\nSET(${var} \"${${var}}\")")
+ endif()
+ endforeach()
+endmacro()
+
+# Set the package name
+cpack_set_if_not_set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
+cpack_set_if_not_set(CPACK_PACKAGE_VERSION_MAJOR "0")
+cpack_set_if_not_set(CPACK_PACKAGE_VERSION_MINOR "1")
+cpack_set_if_not_set(CPACK_PACKAGE_VERSION_PATCH "1")
+cpack_set_if_not_set(CPACK_PACKAGE_VERSION
+ "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
+cpack_set_if_not_set(CPACK_PACKAGE_VENDOR "Humanity")
+cpack_set_if_not_set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
+ "${CMAKE_PROJECT_NAME} built using CMake")
+
+cpack_set_if_not_set(CPACK_PACKAGE_DESCRIPTION_FILE
+ "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
+cpack_set_if_not_set(CPACK_RESOURCE_FILE_LICENSE
+ "${CMAKE_ROOT}/Templates/CPack.GenericLicense.txt")
+cpack_set_if_not_set(CPACK_RESOURCE_FILE_README
+ "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
+cpack_set_if_not_set(CPACK_RESOURCE_FILE_WELCOME
+ "${CMAKE_ROOT}/Templates/CPack.GenericWelcome.txt")
+
+cpack_set_if_not_set(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}")
+
+if(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL)
+ set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
+endif()
+
+if(CPACK_NSIS_MODIFY_PATH)
+ set(CPACK_NSIS_MODIFY_PATH ON)
+endif()
+
+set(__cpack_system_name ${CMAKE_SYSTEM_NAME})
+if(${__cpack_system_name} MATCHES Windows)
+ if(CMAKE_CL_64)
+ set(__cpack_system_name win64)
+ else()
+ set(__cpack_system_name win32)
+ endif()
+endif()
+cpack_set_if_not_set(CPACK_SYSTEM_NAME "${__cpack_system_name}")
+
+# Root dir: default value should be the string literal "$PROGRAMFILES"
+# for backwards compatibility. Projects may set this value to anything.
+set(__cpack_root_default "$PROGRAMFILES")
+cpack_set_if_not_set(CPACK_NSIS_INSTALL_ROOT "${__cpack_root_default}")
+
+# <project>-<major>.<minor>.<patch>-<release>-<platform>.<pkgtype>
+cpack_set_if_not_set(CPACK_PACKAGE_FILE_NAME
+ "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
+cpack_set_if_not_set(CPACK_PACKAGE_INSTALL_DIRECTORY
+ "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}")
+cpack_set_if_not_set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
+ "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
+cpack_set_if_not_set(CPACK_PACKAGE_DEFAULT_LOCATION "/")
+cpack_set_if_not_set(CPACK_PACKAGE_RELOCATABLE "true")
+
+# always force to exactly "true" or "false" for CPack.Info.plist.in:
+if(CPACK_PACKAGE_RELOCATABLE)
+ set(CPACK_PACKAGE_RELOCATABLE "true")
+else()
+ set(CPACK_PACKAGE_RELOCATABLE "false")
+endif()
+
+macro(cpack_check_file_exists file description)
+ if(NOT EXISTS "${file}")
+ message(SEND_ERROR "CPack ${description} file: \"${file}\" could not be found.")
+ endif()
+endmacro()
+
+cpack_check_file_exists("${CPACK_PACKAGE_DESCRIPTION_FILE}" "package description")
+cpack_check_file_exists("${CPACK_RESOURCE_FILE_LICENSE}" "license resource")
+cpack_check_file_exists("${CPACK_RESOURCE_FILE_README}" "readme resource")
+cpack_check_file_exists("${CPACK_RESOURCE_FILE_WELCOME}" "welcome resource")
+
+macro(cpack_optional_append _list _cond _item)
+ if(${_cond})
+ set(${_list} ${${_list}} ${_item})
+ endif()
+endmacro()
+
+#.rst:
+# .. variable:: CPACK_BINARY_<GENNAME>
+#
+# CPack generated options for binary generators. The CPack.cmake module
+# generates (when CPACK_GENERATOR is not set) a set of CMake options (see
+# CMake option command) which may then be used to select the CPack
+# generator(s) to be used when launching the package target.
+#
+# Provide options to choose generators we might check here if the required
+# tools for the generates exist and set the defaults according to the results
+if(NOT CPACK_GENERATOR)
+ if(UNIX)
+ if(CYGWIN)
+ option(CPACK_BINARY_CYGWIN "Enable to build Cygwin binary packages" ON)
+ else()
+ if(APPLE)
+ option(CPACK_BINARY_BUNDLE "Enable to build OSX bundles" OFF)
+ option(CPACK_BINARY_DRAGNDROP "Enable to build OSX Drag And Drop package" OFF)
+ option(CPACK_BINARY_OSXX11 "Enable to build OSX X11 packages" OFF)
+ option(CPACK_BINARY_PACKAGEMAKER "Enable to build PackageMaker packages" OFF)
+ else()
+ option(CPACK_BINARY_TZ "Enable to build TZ packages" ON)
+ endif()
+ option(CPACK_BINARY_DEB "Enable to build Debian packages" OFF)
+ option(CPACK_BINARY_NSIS "Enable to build NSIS packages" OFF)
+ option(CPACK_BINARY_RPM "Enable to build RPM packages" OFF)
+ option(CPACK_BINARY_STGZ "Enable to build STGZ packages" ON)
+ option(CPACK_BINARY_TBZ2 "Enable to build TBZ2 packages" OFF)
+ option(CPACK_BINARY_TGZ "Enable to build TGZ packages" ON)
+ option(CPACK_BINARY_TXZ "Enable to build TXZ packages" OFF)
+ endif()
+ else()
+ option(CPACK_BINARY_7Z "Enable to build 7-Zip packages" OFF)
+ option(CPACK_BINARY_NSIS "Enable to build NSIS packages" ON)
+ option(CPACK_BINARY_WIX "Enable to build WiX packages" OFF)
+ option(CPACK_BINARY_ZIP "Enable to build ZIP packages" OFF)
+ endif()
+ option(CPACK_BINARY_IFW "Enable to build IFW packages" OFF)
+
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_7Z 7Z)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_BUNDLE Bundle)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_CYGWIN CygwinBinary)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_DEB DEB)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_DRAGNDROP DragNDrop)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_IFW IFW)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_NSIS NSIS)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_OSXX11 OSXX11)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_PACKAGEMAKER PackageMaker)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_RPM RPM)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_STGZ STGZ)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_TBZ2 TBZ2)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_TGZ TGZ)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_TXZ TXZ)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_TZ TZ)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_WIX WIX)
+ cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_ZIP ZIP)
+
+endif()
+
+# Provide options to choose source generators
+if(NOT CPACK_SOURCE_GENERATOR)
+ if(UNIX)
+ if(CYGWIN)
+ option(CPACK_SOURCE_CYGWIN "Enable to build Cygwin source packages" ON)
+ else()
+ option(CPACK_SOURCE_TBZ2 "Enable to build TBZ2 source packages" ON)
+ option(CPACK_SOURCE_TGZ "Enable to build TGZ source packages" ON)
+ option(CPACK_SOURCE_TXZ "Enable to build TXZ source packages" ON)
+ option(CPACK_SOURCE_TZ "Enable to build TZ source packages" ON)
+ option(CPACK_SOURCE_ZIP "Enable to build ZIP source packages" OFF)
+ endif()
+ else()
+ option(CPACK_SOURCE_7Z "Enable to build 7-Zip source packages" ON)
+ option(CPACK_SOURCE_ZIP "Enable to build ZIP source packages" ON)
+ endif()
+
+ cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_7Z 7Z)
+ cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_CYGWIN CygwinSource)
+ cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_TBZ2 TBZ2)
+ cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_TGZ TGZ)
+ cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_TXZ TXZ)
+ cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_TZ TZ)
+ cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_ZIP ZIP)
+endif()
+
+# mark the above options as advanced
+mark_as_advanced(
+ CPACK_BINARY_7Z
+ CPACK_BINARY_BUNDLE
+ CPACK_BINARY_CYGWIN
+ CPACK_BINARY_DEB
+ CPACK_BINARY_DRAGNDROP
+ CPACK_BINARY_IFW
+ CPACK_BINARY_NSIS
+ CPACK_BINARY_OSXX11
+ CPACK_BINARY_PACKAGEMAKER
+ CPACK_BINARY_RPM
+ CPACK_BINARY_STGZ
+ CPACK_BINARY_TBZ2
+ CPACK_BINARY_TGZ
+ CPACK_BINARY_TXZ
+ CPACK_BINARY_TZ
+ CPACK_BINARY_WIX
+ CPACK_BINARY_ZIP
+ CPACK_SOURCE_7Z
+ CPACK_SOURCE_CYGWIN
+ CPACK_SOURCE_TBZ2
+ CPACK_SOURCE_TGZ
+ CPACK_SOURCE_TXZ
+ CPACK_SOURCE_TZ
+ CPACK_SOURCE_ZIP
+ )
+
+# Set some other variables
+cpack_set_if_not_set(CPACK_INSTALL_CMAKE_PROJECTS
+ "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};ALL;/")
+cpack_set_if_not_set(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}")
+cpack_set_if_not_set(CPACK_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}")
+# if the user has set CPACK_NSIS_DISPLAY_NAME remember it
+if(DEFINED CPACK_NSIS_DISPLAY_NAME)
+ set(CPACK_NSIS_DISPLAY_NAME_SET TRUE)
+endif()
+# if the user has set CPACK_NSIS_DISPLAY
+# explicitly, then use that as the default
+# value of CPACK_NSIS_PACKAGE_NAME instead
+# of CPACK_PACKAGE_INSTALL_DIRECTORY
+cpack_set_if_not_set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
+
+if(CPACK_NSIS_DISPLAY_NAME_SET)
+ string(REPLACE "\\" "\\\\"
+ _NSIS_DISPLAY_NAME_TMP "${CPACK_NSIS_DISPLAY_NAME}")
+ cpack_set_if_not_set(CPACK_NSIS_PACKAGE_NAME "${_NSIS_DISPLAY_NAME_TMP}")
+else()
+ cpack_set_if_not_set(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
+endif()
+
+cpack_set_if_not_set(CPACK_OUTPUT_CONFIG_FILE
+ "${CMAKE_BINARY_DIR}/CPackConfig.cmake")
+
+cpack_set_if_not_set(CPACK_SOURCE_OUTPUT_CONFIG_FILE
+ "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake")
+
+cpack_set_if_not_set(CPACK_SET_DESTDIR OFF)
+cpack_set_if_not_set(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
+
+cpack_set_if_not_set(CPACK_NSIS_INSTALLER_ICON_CODE "")
+cpack_set_if_not_set(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "")
+
+# WiX specific variables
+cpack_set_if_not_set(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
+
+# set sysroot so SDK tools can be used
+if(CMAKE_OSX_SYSROOT)
+ cpack_set_if_not_set(CPACK_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
+endif()
+
+if(DEFINED CPACK_COMPONENTS_ALL)
+ if(CPACK_MONOLITHIC_INSTALL)
+ message("CPack warning: both CPACK_COMPONENTS_ALL and CPACK_MONOLITHIC_INSTALL have been set.\nDefaulting to a monolithic installation.")
+ set(CPACK_COMPONENTS_ALL)
+ else()
+ # The user has provided the set of components to be installed as
+ # part of a component-based installation; trust her.
+ set(CPACK_COMPONENTS_ALL_SET_BY_USER TRUE)
+ endif()
+else()
+ # If the user has not specifically requested a monolithic installer
+ # but has specified components in various "install" commands, tell
+ # CPack about those components.
+ if(NOT CPACK_MONOLITHIC_INSTALL)
+ get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
+ list(LENGTH CPACK_COMPONENTS_ALL CPACK_COMPONENTS_LEN)
+ if(CPACK_COMPONENTS_LEN EQUAL 1)
+ # Only one component: this is not a component-based installation
+ # (at least, it isn't a component-based installation, but may
+ # become one later if the user uses the cpack_add_* commands).
+ set(CPACK_COMPONENTS_ALL)
+ endif()
+ set(CPACK_COMPONENTS_LEN)
+ endif()
+endif()
+
+# CMake always generates a component named "Unspecified", which is
+# used to install everything that doesn't have an explicitly-provided
+# component. Since these files should always be installed, we'll make
+# them hidden and required.
+set(CPACK_COMPONENT_UNSPECIFIED_HIDDEN TRUE)
+set(CPACK_COMPONENT_UNSPECIFIED_REQUIRED TRUE)
+
+cpack_encode_variables()
+configure_file("${cpack_input_file}" "${CPACK_OUTPUT_CONFIG_FILE}" @ONLY)
+
+# Generate source file
+cpack_set_if_not_set(CPACK_SOURCE_INSTALLED_DIRECTORIES
+ "${CMAKE_SOURCE_DIR};/")
+cpack_set_if_not_set(CPACK_SOURCE_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}-Source")
+cpack_set_if_not_set(CPACK_SOURCE_PACKAGE_FILE_NAME
+ "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source")
+cpack_set_if_not_set(CPACK_SOURCE_IGNORE_FILES
+ "/CVS/;/\\\\\\\\.svn/;/\\\\\\\\.bzr/;/\\\\\\\\.hg/;/\\\\\\\\.git/;\\\\\\\\.swp$;\\\\\\\\.#;/#")
+set(CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_SOURCE_INSTALL_CMAKE_PROJECTS}")
+set(CPACK_INSTALLED_DIRECTORIES "${CPACK_SOURCE_INSTALLED_DIRECTORIES}")
+set(CPACK_GENERATOR "${CPACK_SOURCE_GENERATOR}")
+set(CPACK_TOPLEVEL_TAG "${CPACK_SOURCE_TOPLEVEL_TAG}")
+set(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}")
+set(CPACK_IGNORE_FILES "${CPACK_SOURCE_IGNORE_FILES}")
+set(CPACK_STRIP_FILES "${CPACK_SOURCE_STRIP_FILES}")
+
+cpack_encode_variables()
+configure_file("${cpack_source_input_file}"
+ "${CPACK_SOURCE_OUTPUT_CONFIG_FILE}" @ONLY)
diff --git a/Modules/CPack.distribution.dist.in b/Modules/CPack.distribution.dist.in
new file mode 100644
index 0000000000..f20e66c170
--- /dev/null
+++ b/Modules/CPack.distribution.dist.in
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<installer-gui-script minSpecVersion="1.0">
+ <title>@CPACK_PACKAGE_NAME@</title>
+ <welcome file="@CPACK_RESOURCE_FILE_WELCOME_NOPATH@"/>
+ <readme file="@CPACK_RESOURCE_FILE_README_NOPATH@"/>
+ <license file="@CPACK_RESOURCE_FILE_LICENSE_NOPATH@"/>
+ <options allow-external-scripts="no" customize="allow" rootVolumeOnly="false"></options>
+ @CPACK_PACKAGEMAKER_CHOICES@
+</installer-gui-script>
diff --git a/Modules/CPackBundle.cmake b/Modules/CPackBundle.cmake
new file mode 100644
index 0000000000..d8293c01e0
--- /dev/null
+++ b/Modules/CPackBundle.cmake
@@ -0,0 +1,50 @@
+#.rst:
+# CPackBundle
+# -----------
+#
+# CPack Bundle generator (Mac OS X) specific options
+#
+# Variables specific to CPack Bundle generator
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# Installers built on Mac OS X using the Bundle generator use the
+# aforementioned DragNDrop (CPACK_DMG_xxx) variables, plus the following
+# Bundle-specific parameters (CPACK_BUNDLE_xxx).
+#
+# .. variable:: CPACK_BUNDLE_NAME
+#
+# The name of the generated bundle. This appears in the OSX finder as the
+# bundle name. Required.
+#
+# .. variable:: CPACK_BUNDLE_PLIST
+#
+# Path to an OSX plist file that will be used for the generated bundle. This
+# assumes that the caller has generated or specified their own Info.plist
+# file. Required.
+#
+# .. variable:: CPACK_BUNDLE_ICON
+#
+# Path to an OSX icon file that will be used as the icon for the generated
+# bundle. This is the icon that appears in the OSX finder for the bundle, and
+# in the OSX dock when the bundle is opened. Required.
+#
+# .. variable:: CPACK_BUNDLE_STARTUP_COMMAND
+#
+# Path to a startup script. This is a path to an executable or script that
+# will be run whenever an end-user double-clicks the generated bundle in the
+# OSX Finder. Optional.
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+#Bundle Generator specific code should be put here
diff --git a/Modules/CPackComponent.cmake b/Modules/CPackComponent.cmake
new file mode 100644
index 0000000000..5524a3f484
--- /dev/null
+++ b/Modules/CPackComponent.cmake
@@ -0,0 +1,539 @@
+#.rst:
+# CPackComponent
+# --------------
+#
+# Build binary and source package installers
+#
+# Variables concerning CPack Components
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# The CPackComponent module is the module which handles the component
+# part of CPack. See CPack module for general information about CPack.
+#
+# For certain kinds of binary installers (including the graphical
+# installers on Mac OS X and Windows), CPack generates installers that
+# allow users to select individual application components to install.
+# The contents of each of the components are identified by the COMPONENT
+# argument of CMake's INSTALL command. These components can be
+# annotated with user-friendly names and descriptions, inter-component
+# dependencies, etc., and grouped in various ways to customize the
+# resulting installer. See the cpack_add_* commands, described below,
+# for more information about component-specific installations.
+#
+# Component-specific installation allows users to select specific sets
+# of components to install during the install process. Installation
+# components are identified by the COMPONENT argument of CMake's INSTALL
+# commands, and should be further described by the following CPack
+# commands:
+#
+# .. variable:: CPACK_COMPONENTS_ALL
+#
+# The list of component to install.
+#
+# The default value of this variable is computed by CPack and contains all
+# components defined by the project. The user may set it to only include the
+# specified components.
+#
+# .. variable:: CPACK_<GENNAME>_COMPONENT_INSTALL
+#
+# Enable/Disable component install for CPack generator <GENNAME>.
+#
+# Each CPack Generator (RPM, DEB, ARCHIVE, NSIS, DMG, etc...) has a legacy
+# default behavior. e.g. RPM builds monolithic whereas NSIS builds
+# component. One can change the default behavior by setting this variable to
+# 0/1 or OFF/ON.
+#
+# .. variable:: CPACK_COMPONENTS_GROUPING
+#
+# Specify how components are grouped for multi-package component-aware CPack
+# generators.
+#
+# Some generators like RPM or ARCHIVE family (TGZ, ZIP, ...) generates
+# several packages files when asked for component packaging. They group
+# the component differently depending on the value of this variable:
+#
+# * ONE_PER_GROUP (default): creates one package file per component group
+# * ALL_COMPONENTS_IN_ONE : creates a single package with all (requested) component
+# * IGNORE : creates one package per component, i.e. IGNORE component group
+#
+# One can specify different grouping for different CPack generator by
+# using a CPACK_PROJECT_CONFIG_FILE.
+#
+# .. variable:: CPACK_COMPONENT_<compName>_DISPLAY_NAME
+#
+# The name to be displayed for a component.
+#
+# .. variable:: CPACK_COMPONENT_<compName>_DESCRIPTION
+#
+# The description of a component.
+#
+# .. variable:: CPACK_COMPONENT_<compName>_GROUP
+#
+# The group of a component.
+#
+# .. variable:: CPACK_COMPONENT_<compName>_DEPENDS
+#
+# The dependencies (list of components) on which this component depends.
+#
+# .. variable:: CPACK_COMPONENT_<compName>_REQUIRED
+#
+# True is this component is required.
+#
+# .. command:: cpack_add_component
+#
+# Describes a CPack installation
+# component named by the COMPONENT argument to a CMake INSTALL command.
+#
+# ::
+#
+# cpack_add_component(compname
+# [DISPLAY_NAME name]
+# [DESCRIPTION description]
+# [HIDDEN | REQUIRED | DISABLED ]
+# [GROUP group]
+# [DEPENDS comp1 comp2 ... ]
+# [INSTALL_TYPES type1 type2 ... ]
+# [DOWNLOADED]
+# [ARCHIVE_FILE filename])
+#
+#
+#
+# The cmake_add_component command describes an installation component,
+# which the user can opt to install or remove as part of the graphical
+# installation process. compname is the name of the component, as
+# provided to the COMPONENT argument of one or more CMake INSTALL
+# commands.
+#
+# DISPLAY_NAME is the displayed name of the component, used in graphical
+# installers to display the component name. This value can be any
+# string.
+#
+# DESCRIPTION is an extended description of the component, used in
+# graphical installers to give the user additional information about the
+# component. Descriptions can span multiple lines using "\n" as the
+# line separator. Typically, these descriptions should be no more than
+# a few lines long.
+#
+# HIDDEN indicates that this component will be hidden in the graphical
+# installer, so that the user cannot directly change whether it is
+# installed or not.
+#
+# REQUIRED indicates that this component is required, and therefore will
+# always be installed. It will be visible in the graphical installer,
+# but it cannot be unselected. (Typically, required components are
+# shown greyed out).
+#
+# DISABLED indicates that this component should be disabled (unselected)
+# by default. The user is free to select this component for
+# installation, unless it is also HIDDEN.
+#
+# DEPENDS lists the components on which this component depends. If this
+# component is selected, then each of the components listed must also be
+# selected. The dependency information is encoded within the installer
+# itself, so that users cannot install inconsistent sets of components.
+#
+# GROUP names the component group of which this component is a part. If
+# not provided, the component will be a standalone component, not part
+# of any component group. Component groups are described with the
+# cpack_add_component_group command, detailed below.
+#
+# INSTALL_TYPES lists the installation types of which this component is
+# a part. When one of these installations types is selected, this
+# component will automatically be selected. Installation types are
+# described with the cpack_add_install_type command, detailed below.
+#
+# DOWNLOADED indicates that this component should be downloaded
+# on-the-fly by the installer, rather than packaged in with the
+# installer itself. For more information, see the
+# cpack_configure_downloads command.
+#
+# ARCHIVE_FILE provides a name for the archive file created by CPack to
+# be used for downloaded components. If not supplied, CPack will create
+# a file with some name based on CPACK_PACKAGE_FILE_NAME and the name of
+# the component. See cpack_configure_downloads for more information.
+#
+# .. command:: cpack_add_component_group
+#
+# Describes a group of related CPack installation components.
+#
+# ::
+#
+# cpack_add_component_group(groupname
+# [DISPLAY_NAME name]
+# [DESCRIPTION description]
+# [PARENT_GROUP parent]
+# [EXPANDED]
+# [BOLD_TITLE])
+#
+#
+#
+# The cpack_add_component_group describes a group of installation
+# components, which will be placed together within the listing of
+# options. Typically, component groups allow the user to
+# select/deselect all of the components within a single group via a
+# single group-level option. Use component groups to reduce the
+# complexity of installers with many options. groupname is an arbitrary
+# name used to identify the group in the GROUP argument of the
+# cpack_add_component command, which is used to place a component in a
+# group. The name of the group must not conflict with the name of any
+# component.
+#
+# DISPLAY_NAME is the displayed name of the component group, used in
+# graphical installers to display the component group name. This value
+# can be any string.
+#
+# DESCRIPTION is an extended description of the component group, used in
+# graphical installers to give the user additional information about the
+# components within that group. Descriptions can span multiple lines
+# using "\n" as the line separator. Typically, these descriptions
+# should be no more than a few lines long.
+#
+# PARENT_GROUP, if supplied, names the parent group of this group.
+# Parent groups are used to establish a hierarchy of groups, providing
+# an arbitrary hierarchy of groups.
+#
+# EXPANDED indicates that, by default, the group should show up as
+# "expanded", so that the user immediately sees all of the components
+# within the group. Otherwise, the group will initially show up as a
+# single entry.
+#
+# BOLD_TITLE indicates that the group title should appear in bold, to
+# call the user's attention to the group.
+#
+# .. command:: cpack_add_install_type
+#
+# Add a new installation type containing
+# a set of predefined component selections to the graphical installer.
+#
+# ::
+#
+# cpack_add_install_type(typename
+# [DISPLAY_NAME name])
+#
+#
+#
+# The cpack_add_install_type command identifies a set of preselected
+# components that represents a common use case for an application. For
+# example, a "Developer" install type might include an application along
+# with its header and library files, while an "End user" install type
+# might just include the application's executable. Each component
+# identifies itself with one or more install types via the INSTALL_TYPES
+# argument to cpack_add_component.
+#
+# DISPLAY_NAME is the displayed name of the install type, which will
+# typically show up in a drop-down box within a graphical installer.
+# This value can be any string.
+#
+# .. command:: cpack_configure_downloads
+#
+# Configure CPack to download
+# selected components on-the-fly as part of the installation process.
+#
+# ::
+#
+# cpack_configure_downloads(site
+# [UPLOAD_DIRECTORY dirname]
+# [ALL]
+# [ADD_REMOVE|NO_ADD_REMOVE])
+#
+#
+#
+# The cpack_configure_downloads command configures installation-time
+# downloads of selected components. For each downloadable component,
+# CPack will create an archive containing the contents of that
+# component, which should be uploaded to the given site. When the user
+# selects that component for installation, the installer will download
+# and extract the component in place. This feature is useful for
+# creating small installers that only download the requested components,
+# saving bandwidth. Additionally, the installers are small enough that
+# they will be installed as part of the normal installation process, and
+# the "Change" button in Windows Add/Remove Programs control panel will
+# allow one to add or remove parts of the application after the original
+# installation. On Windows, the downloaded-components functionality
+# requires the ZipDLL plug-in for NSIS, available at:
+#
+# ::
+#
+# http://nsis.sourceforge.net/ZipDLL_plug-in
+#
+#
+#
+# On Mac OS X, installers that download components on-the-fly can only
+# be built and installed on system using Mac OS X 10.5 or later.
+#
+# The site argument is a URL where the archives for downloadable
+# components will reside, e.g.,
+# http://www.cmake.org/files/2.6.1/installer/ All of the archives
+# produced by CPack should be uploaded to that location.
+#
+# UPLOAD_DIRECTORY is the local directory where CPack will create the
+# various archives for each of the components. The contents of this
+# directory should be uploaded to a location accessible by the URL given
+# in the site argument. If omitted, CPack will use the directory
+# CPackUploads inside the CMake binary directory to store the generated
+# archives.
+#
+# The ALL flag indicates that all components be downloaded. Otherwise,
+# only those components explicitly marked as DOWNLOADED or that have a
+# specified ARCHIVE_FILE will be downloaded. Additionally, the ALL
+# option implies ADD_REMOVE (unless NO_ADD_REMOVE is specified).
+#
+# ADD_REMOVE indicates that CPack should install a copy of the installer
+# that can be called from Windows' Add/Remove Programs dialog (via the
+# "Modify" button) to change the set of installed components.
+# NO_ADD_REMOVE turns off this behavior. This option is ignored on Mac
+# OS X.
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+# Define var in order to avoid multiple inclusion
+if(NOT CPackComponent_CMake_INCLUDED)
+set(CPackComponent_CMake_INCLUDED 1)
+
+# Argument-parsing macro from http://www.cmake.org/Wiki/CMakeMacroParseArguments
+macro(cpack_parse_arguments prefix arg_names option_names)
+ set(${prefix}_DEFAULT_ARGS)
+ foreach(arg_name ${arg_names})
+ set(${prefix}_${arg_name})
+ endforeach()
+ foreach(option ${option_names})
+ set(${prefix}_${option} FALSE)
+ endforeach()
+
+ set(current_arg_name DEFAULT_ARGS)
+ set(current_arg_list)
+ foreach(arg ${ARGN})
+ set(larg_names ${arg_names})
+ list(FIND larg_names "${arg}" is_arg_name)
+ if (is_arg_name GREATER -1)
+ set(${prefix}_${current_arg_name} ${current_arg_list})
+ set(current_arg_name ${arg})
+ set(current_arg_list)
+ else ()
+ set(loption_names ${option_names})
+ list(FIND loption_names "${arg}" is_option)
+ if (is_option GREATER -1)
+ set(${prefix}_${arg} TRUE)
+ else ()
+ set(current_arg_list ${current_arg_list} ${arg})
+ endif ()
+ endif ()
+ endforeach()
+ set(${prefix}_${current_arg_name} ${current_arg_list})
+endmacro()
+
+# Macro that appends a SET command for the given variable name (var)
+# to the macro named strvar, but only if the variable named "var"
+# has been defined. The string will eventually be appended to a CPack
+# configuration file.
+macro(cpack_append_variable_set_command var strvar)
+ if (DEFINED ${var})
+ set(${strvar} "${${strvar}}set(${var}")
+ foreach(APPENDVAL ${${var}})
+ set(${strvar} "${${strvar}} ${APPENDVAL}")
+ endforeach()
+ set(${strvar} "${${strvar}})\n")
+ endif ()
+endmacro()
+
+# Macro that appends a SET command for the given variable name (var)
+# to the macro named strvar, but only if the variable named "var"
+# has been defined and is a string. The string will eventually be
+# appended to a CPack configuration file.
+macro(cpack_append_string_variable_set_command var strvar)
+ if (DEFINED ${var})
+ list(LENGTH ${var} CPACK_APP_VALUE_LEN)
+ if(${CPACK_APP_VALUE_LEN} EQUAL 1)
+ set(${strvar} "${${strvar}}set(${var} \"${${var}}\")\n")
+ endif()
+ endif ()
+endmacro()
+
+# Macro that appends a SET command for the given variable name (var)
+# to the macro named strvar, but only if the variable named "var"
+# has been set to true. The string will eventually be
+# appended to a CPack configuration file.
+macro(cpack_append_option_set_command var strvar)
+ if (${var})
+ list(LENGTH ${var} CPACK_APP_VALUE_LEN)
+ if(${CPACK_APP_VALUE_LEN} EQUAL 1)
+ set(${strvar} "${${strvar}}set(${var} TRUE)\n")
+ endif()
+ endif ()
+endmacro()
+
+# Macro that adds a component to the CPack installer
+macro(cpack_add_component compname)
+ string(TOUPPER ${compname} _CPACK_ADDCOMP_UNAME)
+ cpack_parse_arguments(CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}
+ "DISPLAY_NAME;DESCRIPTION;GROUP;DEPENDS;INSTALL_TYPES;ARCHIVE_FILE"
+ "HIDDEN;REQUIRED;DISABLED;DOWNLOADED"
+ ${ARGN}
+ )
+
+ if (CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_DOWNLOADED)
+ set(_CPACK_ADDCOMP_STR "\n# Configuration for downloaded component \"${compname}\"\n")
+ else ()
+ set(_CPACK_ADDCOMP_STR "\n# Configuration for component \"${compname}\"\n")
+ endif ()
+
+ if(NOT CPACK_MONOLITHIC_INSTALL)
+ # If the user didn't set CPACK_COMPONENTS_ALL explicitly, update the
+ # value of CPACK_COMPONENTS_ALL in the configuration file. This will
+ # take care of any components that have been added after the CPack
+ # moduled was included.
+ if(NOT CPACK_COMPONENTS_ALL_SET_BY_USER)
+ get_cmake_property(_CPACK_ADDCOMP_COMPONENTS COMPONENTS)
+ set(_CPACK_ADDCOMP_STR "${_CPACK_ADDCOMP_STR}\nSET(CPACK_COMPONENTS_ALL")
+ foreach(COMP ${_CPACK_ADDCOMP_COMPONENTS})
+ set(_CPACK_ADDCOMP_STR "${_CPACK_ADDCOMP_STR} ${COMP}")
+ endforeach()
+ set(_CPACK_ADDCOMP_STR "${_CPACK_ADDCOMP_STR})\n")
+ endif()
+ endif()
+
+ cpack_append_string_variable_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_DISPLAY_NAME
+ _CPACK_ADDCOMP_STR)
+ cpack_append_string_variable_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_DESCRIPTION
+ _CPACK_ADDCOMP_STR)
+ cpack_append_variable_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_GROUP
+ _CPACK_ADDCOMP_STR)
+ cpack_append_variable_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_DEPENDS
+ _CPACK_ADDCOMP_STR)
+ cpack_append_variable_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_INSTALL_TYPES
+ _CPACK_ADDCOMP_STR)
+ cpack_append_string_variable_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_ARCHIVE_FILE
+ _CPACK_ADDCOMP_STR)
+ cpack_append_option_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_HIDDEN
+ _CPACK_ADDCOMP_STR)
+ cpack_append_option_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_REQUIRED
+ _CPACK_ADDCOMP_STR)
+ cpack_append_option_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_DISABLED
+ _CPACK_ADDCOMP_STR)
+ cpack_append_option_set_command(
+ CPACK_COMPONENT_${_CPACK_ADDCOMP_UNAME}_DOWNLOADED
+ _CPACK_ADDCOMP_STR)
+ # Backward compatibility issue.
+ # Write to config iff the macros is used after CPack.cmake has been
+ # included, other it's not necessary because the variables
+ # will be encoded by cpack_encode_variables.
+ if(CPack_CMake_INCLUDED)
+ file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${_CPACK_ADDCOMP_STR}")
+ endif()
+endmacro()
+
+# Macro that adds a component group to the CPack installer
+macro(cpack_add_component_group grpname)
+ string(TOUPPER ${grpname} CPACK_ADDGRP_UNAME)
+ cpack_parse_arguments(CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}
+ "DISPLAY_NAME;DESCRIPTION;PARENT_GROUP"
+ "EXPANDED;BOLD_TITLE"
+ ${ARGN}
+ )
+
+ set(CPACK_ADDGRP_STR "\n# Configuration for component group \"${grpname}\"\n")
+ cpack_append_string_variable_set_command(
+ CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}_DISPLAY_NAME
+ CPACK_ADDGRP_STR)
+ cpack_append_string_variable_set_command(
+ CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}_DESCRIPTION
+ CPACK_ADDGRP_STR)
+ cpack_append_string_variable_set_command(
+ CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}_PARENT_GROUP
+ CPACK_ADDGRP_STR)
+ cpack_append_option_set_command(
+ CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}_EXPANDED
+ CPACK_ADDGRP_STR)
+ cpack_append_option_set_command(
+ CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}_BOLD_TITLE
+ CPACK_ADDGRP_STR)
+ # Backward compatibility issue.
+ # Write to config iff the macros is used after CPack.cmake has been
+ # included, other it's not necessary because the variables
+ # will be encoded by cpack_encode_variables.
+ if(CPack_CMake_INCLUDED)
+ file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${CPACK_ADDGRP_STR}")
+ endif()
+endmacro()
+
+# Macro that adds an installation type to the CPack installer
+macro(cpack_add_install_type insttype)
+ string(TOUPPER ${insttype} CPACK_INSTTYPE_UNAME)
+ cpack_parse_arguments(CPACK_INSTALL_TYPE_${CPACK_INSTTYPE_UNAME}
+ "DISPLAY_NAME"
+ ""
+ ${ARGN}
+ )
+
+ set(CPACK_INSTTYPE_STR
+ "\n# Configuration for installation type \"${insttype}\"\n")
+ set(CPACK_INSTTYPE_STR
+ "${CPACK_INSTTYPE_STR}list(APPEND CPACK_ALL_INSTALL_TYPES ${insttype})\n")
+ cpack_append_string_variable_set_command(
+ CPACK_INSTALL_TYPE_${CPACK_INSTTYPE_UNAME}_DISPLAY_NAME
+ CPACK_INSTTYPE_STR)
+ # Backward compatibility issue.
+ # Write to config iff the macros is used after CPack.cmake has been
+ # included, other it's not necessary because the variables
+ # will be encoded by cpack_encode_variables.
+ if(CPack_CMake_INCLUDED)
+ file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${CPACK_INSTTYPE_STR}")
+ endif()
+endmacro()
+
+macro(cpack_configure_downloads site)
+ cpack_parse_arguments(CPACK_DOWNLOAD
+ "UPLOAD_DIRECTORY"
+ "ALL;ADD_REMOVE;NO_ADD_REMOVE"
+ ${ARGN}
+ )
+
+ set(CPACK_CONFIG_DL_STR
+ "\n# Downloaded components configuration\n")
+ set(CPACK_UPLOAD_DIRECTORY ${CPACK_DOWNLOAD_UPLOAD_DIRECTORY})
+ set(CPACK_DOWNLOAD_SITE ${site})
+ cpack_append_string_variable_set_command(
+ CPACK_DOWNLOAD_SITE
+ CPACK_CONFIG_DL_STR)
+ cpack_append_string_variable_set_command(
+ CPACK_UPLOAD_DIRECTORY
+ CPACK_CONFIG_DL_STR)
+ cpack_append_option_set_command(
+ CPACK_DOWNLOAD_ALL
+ CPACK_CONFIG_DL_STR)
+ if (${CPACK_DOWNLOAD_ALL} AND NOT ${CPACK_DOWNLOAD_NO_ADD_REMOVE})
+ set(CPACK_DOWNLOAD_ADD_REMOVE ON)
+ endif ()
+ set(CPACK_ADD_REMOVE ${CPACK_DOWNLOAD_ADD_REMOVE})
+ cpack_append_option_set_command(
+ CPACK_ADD_REMOVE
+ CPACK_CONFIG_DL_STR)
+ # Backward compatibility issue.
+ # Write to config iff the macros is used after CPack.cmake has been
+ # included, other it's not necessary because the variables
+ # will be encoded by cpack_encode_variables.
+ if(CPack_CMake_INCLUDED)
+ file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${CPACK_CONFIG_DL_STR}")
+ endif()
+endmacro()
+endif()
diff --git a/Modules/CPackCygwin.cmake b/Modules/CPackCygwin.cmake
new file mode 100644
index 0000000000..abfc1f6197
--- /dev/null
+++ b/Modules/CPackCygwin.cmake
@@ -0,0 +1,37 @@
+#.rst:
+# CPackCygwin
+# -----------
+#
+# Cygwin CPack generator (Cygwin).
+#
+# Variables specific to CPack Cygwin generator
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# The
+# following variable is specific to installers build on and/or for
+# Cygwin:
+#
+# .. variable:: CPACK_CYGWIN_PATCH_NUMBER
+#
+# The Cygwin patch number. FIXME: This documentation is incomplete.
+#
+# .. variable:: CPACK_CYGWIN_PATCH_FILE
+#
+# The Cygwin patch file. FIXME: This documentation is incomplete.
+#
+# .. variable:: CPACK_CYGWIN_BUILD_SCRIPT
+#
+# The Cygwin build script. FIXME: This documentation is incomplete.
+
+#=============================================================================
+# Copyright 2006-2012 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.)
diff --git a/Modules/CPackDMG.cmake b/Modules/CPackDMG.cmake
new file mode 100644
index 0000000000..b7a6ba5399
--- /dev/null
+++ b/Modules/CPackDMG.cmake
@@ -0,0 +1,69 @@
+#.rst:
+# CPackDMG
+# --------
+#
+# DragNDrop CPack generator (Mac OS X).
+#
+# Variables specific to CPack DragNDrop generator
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# The following variables are specific to the DragNDrop installers built
+# on Mac OS X:
+#
+# .. variable:: CPACK_DMG_VOLUME_NAME
+#
+# The volume name of the generated disk image. Defaults to
+# CPACK_PACKAGE_FILE_NAME.
+#
+# .. variable:: CPACK_DMG_FORMAT
+#
+# The disk image format. Common values are UDRO (UDIF read-only), UDZO (UDIF
+# zlib-compressed) or UDBZ (UDIF bzip2-compressed). Refer to hdiutil(1) for
+# more information on other available formats.
+#
+# .. variable:: CPACK_DMG_DS_STORE
+#
+# 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
+# from which the .DS_Store file can then be extracted.
+#
+# .. 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.
+#
+# .. variable:: CPACK_COMMAND_HDIUTIL
+#
+# Path to the hdiutil(1) command used to operate on disk image files on Mac
+# OS X. This variable can be used to override the automatically detected
+# command (or specify its location if the auto-detection fails to find it.)
+#
+# .. variable:: CPACK_COMMAND_SETFILE
+#
+# Path to the SetFile(1) command used to set extended attributes on files and
+# directories on Mac OS X. This variable can be used to override the
+# automatically detected command (or specify its location if the
+# auto-detection fails to find it.)
+#
+# .. variable:: CPACK_COMMAND_REZ
+#
+# Path to the Rez(1) command used to compile resources on Mac OS X. This
+# variable can be used to override the automatically detected command (or
+# specify its location if the auto-detection fails to find it.)
+
+#=============================================================================
+# Copyright 2006-2012 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.)
diff --git a/Modules/CPackDeb.cmake b/Modules/CPackDeb.cmake
new file mode 100644
index 0000000000..8a4fa49c12
--- /dev/null
+++ b/Modules/CPackDeb.cmake
@@ -0,0 +1,455 @@
+#.rst:
+# CPackDeb
+# --------
+#
+# The builtin (binary) CPack Deb generator (Unix only)
+#
+# Variables specific to CPack Debian (DEB) generator
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# CPackDeb may be used to create Deb package using CPack.
+# CPackDeb is a CPack generator thus it uses the CPACK_XXX variables
+# used by CPack : http://www.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
+# the build system.
+#
+# CPackDeb has specific features which are controlled by the specifics
+# CPACK_DEBIAN_XXX variables.You'll find a detailed usage on the wiki:
+# http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29
+#
+# However as a handy reminder here comes the list of specific variables:
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_NAME
+#
+# * Mandatory : YES
+# * Default : CPACK_PACKAGE_NAME (lower case)
+#
+# The debian package summary
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_VERSION
+#
+# * Mandatory : YES
+# * Default : CPACK_PACKAGE_VERSION
+#
+# The debian package version
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_ARCHITECTURE
+#
+# * Mandatory : YES
+# * Default : Output of dpkg --print-architecture (or i386 if dpkg is not found)
+#
+# The debian package architecture
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_DEPENDS
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to set deb dependencies.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_MAINTAINER
+#
+# * Mandatory : YES
+# * Default : CPACK_PACKAGE_CONTACT
+#
+# The debian package maintainer
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_DESCRIPTION
+#
+# * Mandatory : YES
+# * Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY
+#
+# The debian package description
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_SECTION
+#
+# * Mandatory : YES
+# * Default : 'devel'
+#
+# .. variable:: CPACK_DEBIAN_COMPRESSION_TYPE
+#
+# * Mandatory : YES
+# * Default : 'gzip'
+#
+# Possible values are: lzma, xz, bzip2 and gzip.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_PRIORITY
+#
+# * Mandatory : YES
+# * Default : 'optional'
+#
+# The debian package priority
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_HOMEPAGE
+#
+# * Mandatory : NO
+# * Default : -
+#
+# The URL of the web site for this package, preferably (when applicable) the
+# site from which the original source can be obtained and any additional
+# upstream documentation or information may be found.
+# The content of this field is a simple URL without any surrounding
+# characters such as <>.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_SHLIBDEPS
+#
+# * Mandatory : NO
+# * Default : OFF
+#
+# May be set to ON in order to use dpkg-shlibdeps to generate
+# better package dependency list.
+# You may need set CMAKE_INSTALL_RPATH toi appropriate value
+# if you use this feature, because if you don't dpkg-shlibdeps
+# may fail to find your own shared libs.
+# See http://www.cmake.org/Wiki/CMake_RPATH_handling.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_DEBUG
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be set when invoking cpack in order to trace debug information
+# during CPackDeb run.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_PREDEPENDS
+#
+# * Mandatory : NO
+# * Default : -
+#
+# see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
+# This field is like Depends, except that it also forces dpkg to complete installation of
+# the packages named before even starting the installation of the package which declares
+# the pre-dependency.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_ENHANCES
+#
+# * Mandatory : NO
+# * Default : -
+#
+# see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
+# This field is similar to Suggests but works in the opposite direction.
+# It is used to declare that a package can enhance the functionality of another package.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_BREAKS
+#
+# * Mandatory : NO
+# * Default : -
+#
+# see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
+# When one binary package declares that it breaks another, dpkg will refuse to allow the
+# package which declares Breaks be installed unless the broken package is deconfigured first,
+# and it will refuse to allow the broken package to be reconfigured.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_CONFLICTS
+#
+# * Mandatory : NO
+# * Default : -
+#
+# see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
+# When one binary package declares a conflict with another using a Conflicts field,
+# dpkg will refuse to allow them to be installed on the system at the same time.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_PROVIDES
+#
+# * Mandatory : NO
+# * Default : -
+#
+# see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
+# A virtual package is one which appears in the Provides control field of another package.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_REPLACES
+#
+# * Mandatory : NO
+# * Default : -
+#
+# see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
+# Packages can declare in their control file that they should overwrite
+# files in certain other packages, or completely replace other packages.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_RECOMMENDS
+#
+# * Mandatory : NO
+# * Default : -
+#
+# see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
+# Allows packages to declare a strong, but not absolute, dependency on other packages.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_SUGGESTS
+#
+# * Mandatory : NO
+# * Default : -
+#
+# see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
+# Allows packages to declare a suggested package install grouping.
+#
+# .. variable:: CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
+#
+# * Mandatory : NO
+# * Default : -
+#
+# This variable allow advanced user to add custom script to the
+# control.tar.gz Typical usage is for conffiles, postinst, postrm, prerm.
+# Usage::
+#
+# set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
+# "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
+
+
+#=============================================================================
+# Copyright 2007-2009 Kitware, Inc.
+# Copyright 2007-2009 Mathieu Malaterre <mathieu.malaterre@gmail.com>
+#
+# 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.)
+
+# CPack script for creating Debian package
+# Author: Mathieu Malaterre
+#
+# http://wiki.debian.org/HowToPackageForDebian
+
+if(CMAKE_BINARY_DIR)
+ message(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.")
+endif()
+
+if(NOT UNIX)
+ message(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.")
+endif()
+
+# CPACK_DEBIAN_PACKAGE_SHLIBDEPS
+# If specify OFF, only user depends are used
+if(NOT DEFINED CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
+ set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF)
+endif()
+
+find_program(FAKEROOT_EXECUTABLE fakeroot)
+if(FAKEROOT_EXECUTABLE)
+ set(CPACK_DEBIAN_FAKEROOT_EXECUTABLE ${FAKEROOT_EXECUTABLE})
+endif()
+
+if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS)
+ # dpkg-shlibdeps is a Debian utility for generating dependency list
+ find_program(SHLIBDEPS_EXECUTABLE dpkg-shlibdeps)
+
+ # Check version of the dpkg-shlibdeps tool using CPackRPM method
+ if(SHLIBDEPS_EXECUTABLE)
+ execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --version
+ OUTPUT_VARIABLE _TMP_VERSION
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX MATCH "dpkg-shlibdeps version ([0-9]+\\.[0-9]+\\.[0-9]+)"
+ SHLIBDEPS_EXECUTABLE_VERSION
+ ${_TMP_VERSION})
+ set(SHLIBDEPS_EXECUTABLE_VERSION "${CMAKE_MATCH_1}")
+ if(CPACK_DEBIAN_PACKAGE_DEBUG)
+ message( "CPackDeb Debug: dpkg-shlibdeps version is <${SHLIBDEPS_EXECUTABLE_VERSION}>")
+ endif()
+
+ # Generating binary list - Get type of all install files
+ execute_process(COMMAND find -type f
+ COMMAND xargs file
+ WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
+ OUTPUT_VARIABLE CPACK_DEB_INSTALL_FILES)
+
+ # Convert to CMake list
+ string(REPLACE "\n" ";" CPACK_DEB_INSTALL_FILES ${CPACK_DEB_INSTALL_FILES})
+
+ # Only dynamically linked ELF files are included
+ # Extract only file name infront of ":"
+ foreach ( _FILE ${CPACK_DEB_INSTALL_FILES})
+ if ( ${_FILE} MATCHES "ELF.*dynamically linked")
+ string(REGEX MATCH "(^.*):" _FILE_NAME ${_FILE})
+ list(APPEND CPACK_DEB_BINARY_FILES ${CMAKE_MATCH_1})
+ endif()
+ endforeach()
+
+ message( "CPackDeb: - Generating dependency list")
+
+ # Create blank control file for running dpkg-shlibdeps
+ # There might be some other way to invoke dpkg-shlibdeps without creating this file
+ # but standard debian package should not have anything that can collide with this file or directory
+ file(MAKE_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}/debian)
+ file(WRITE ${CPACK_TEMPORARY_DIRECTORY}/debian/control "")
+
+ # Execute dpkg-shlibdeps
+ # --ignore-missing-info : allow dpkg-shlibdeps to run even if some libs do not belong to a package
+ # -O : print to STDOUT
+ execute_process(COMMAND ${SHLIBDEPS_EXECUTABLE} --ignore-missing-info -O ${CPACK_DEB_BINARY_FILES}
+ WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
+ OUTPUT_VARIABLE SHLIBDEPS_OUTPUT
+ RESULT_VARIABLE SHLIBDEPS_RESULT
+ ERROR_VARIABLE SHLIBDEPS_ERROR
+ OUTPUT_STRIP_TRAILING_WHITESPACE )
+ if(CPACK_DEBIAN_PACKAGE_DEBUG)
+ # dpkg-shlibdeps will throw some warnings if some input files are not binary
+ message( "CPackDeb Debug: dpkg-shlibdeps warnings \n${SHLIBDEPS_ERROR}")
+ endif()
+ if (NOT SHLIBDEPS_RESULT EQUAL 0)
+ message (FATAL_ERROR "CPackDeb: dpkg-shlibdeps: ${SHLIBDEPS_ERROR}")
+ endif ()
+
+ #Get rid of prefix generated by dpkg-shlibdeps
+ string (REGEX REPLACE "^.*Depends=" "" CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS ${SHLIBDEPS_OUTPUT})
+
+ if(CPACK_DEBIAN_PACKAGE_DEBUG)
+ message( "CPackDeb Debug: Found dependency: ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}")
+ endif()
+
+ # Remove blank control file
+ # Might not be safe if package actual contain file or directory named debian
+ file(REMOVE_RECURSE "${CPACK_TEMPORARY_DIRECTORY}/debian")
+
+ # Append user depend if set
+ if (CPACK_DEBIAN_PACKAGE_DEPENDS)
+ set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_DEPENDS}")
+ else ()
+ set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}")
+ endif ()
+
+ else ()
+ if(CPACK_DEBIAN_PACKAGE_DEBUG)
+ message( "CPackDeb Debug: Using only user-provided depends because dpkg-shlibdeps is not found.")
+ endif()
+ endif()
+
+else ()
+ if(CPACK_DEBIAN_PACKAGE_DEBUG)
+ message( "CPackDeb Debug: Using only user-provided depends")
+ endif()
+endif()
+
+# Let's define the control file found in debian package:
+
+# Binary package:
+# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
+
+# DEBIAN/control
+# debian policy enforce lower case for package name
+# Package: (mandatory)
+if(NOT CPACK_DEBIAN_PACKAGE_NAME)
+ string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
+endif()
+
+# Version: (mandatory)
+if(NOT CPACK_DEBIAN_PACKAGE_VERSION)
+ if(NOT CPACK_PACKAGE_VERSION)
+ message(FATAL_ERROR "CPackDeb: Debian package requires a package version")
+ endif()
+ set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
+endif()
+
+# Architecture: (mandatory)
+if(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
+ # There is no such thing as i686 architecture on debian, you should use i386 instead
+ # $ dpkg --print-architecture
+ find_program(DPKG_CMD dpkg)
+ if(NOT DPKG_CMD)
+ message(STATUS "CPackDeb: Can not find dpkg in your path, default to i386.")
+ set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
+ endif()
+ execute_process(COMMAND "${DPKG_CMD}" --print-architecture
+ OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+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(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
+ message(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.")
+endif()
+
+# Maintainer: (mandatory)
+if(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
+ if(NOT CPACK_PACKAGE_CONTACT)
+ message(FATAL_ERROR "CPackDeb: Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER")
+ endif()
+ set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
+endif()
+
+# Description: (mandatory)
+if(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
+ if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
+ message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION")
+ endif()
+ set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
+endif()
+
+# Section: (recommended)
+if(NOT CPACK_DEBIAN_PACKAGE_SECTION)
+ set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
+endif()
+
+# Priority: (recommended)
+if(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
+ set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
+endif()
+
+# Compression: (recommended)
+if(NOT CPACK_DEBIAN_COMPRESSION_TYPE)
+ set(CPACK_DEBIAN_COMPRESSION_TYPE "gzip")
+endif()
+
+
+# Recommends:
+# You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS
+
+# Suggests:
+# You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS
+
+# CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
+# This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive)
+# Typical examples are:
+# - conffiles
+# - postinst
+# - postrm
+# - prerm"
+# Usage:
+# set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
+# "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
+
+# Are we packaging components ?
+if(CPACK_DEB_PACKAGE_COMPONENT)
+ 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 "")
+endif()
+
+set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_PATH}")
+
+# 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}")
+endif()
+
+# For debian source packages:
+# debian/control
+# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles
+
+# .dsc
+# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles
+
+# Builds-Depends:
+#if(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
+# set(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS
+# "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4"
+# )
+#endif()
diff --git a/Modules/CPackIFW.cmake b/Modules/CPackIFW.cmake
new file mode 100644
index 0000000000..4b8dc1e674
--- /dev/null
+++ b/Modules/CPackIFW.cmake
@@ -0,0 +1,517 @@
+#.rst:
+# CPackIFW
+# --------
+#
+# .. _QtIFW: http://qt-project.org/doc/qtinstallerframework/index.html
+#
+# This module looks for the location of the command line utilities supplied with
+# the Qt Installer Framework (QtIFW_).
+#
+# The module also defines several commands to control the behavior of the
+# CPack ``IFW`` generator.
+#
+#
+# Overview
+# ^^^^^^^^
+#
+# CPack ``IFW`` generator helps you create online and offline
+# binary cross-platform installers with a graphical user interface.
+#
+# CPack IFW generator prepare project installation and generate configuration
+# and meta information for QtIFW_ tools.
+#
+# The QtIFW_ provides a set of tools and utilities to create
+# installers for the supported desktop Qt platforms: Linux, Microsoft Windows,
+# and Mac OS X.
+#
+# To use CPack ``IFW`` generator you must also install QtIFW_.
+# If you are not using the default path for the installation, please set
+# the path to the variable ``QTIFWDIR``.
+#
+# Variables
+# ^^^^^^^^^
+#
+# You can use the following variables to change behavior of CPack ``IFW`` generator.
+#
+# Package
+# """""""
+#
+# .. variable:: CPACK_IFW_PACKAGE_TITLE
+#
+# Name of the installer as displayed on the title bar.
+# By default used :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY`
+#
+# .. variable:: CPACK_IFW_PACKAGE_PUBLISHER
+#
+# Publisher of the software (as shown in the Windows Control Panel).
+# By default used :variable:`CPACK_PACKAGE_VENDOR`
+#
+# .. variable:: CPACK_IFW_PRODUCT_URL
+#
+# URL to a page that contains product information on your web site.
+#
+# .. variable:: CPACK_IFW_PACKAGE_ICON
+#
+# Filename for a custom installer icon. The actual file is '.icns' (Mac OS X),
+# '.ico' (Windows). No functionality on Unix.
+#
+# .. variable:: CPACK_IFW_PACKAGE_WINDOW_ICON
+#
+# Filename for a custom window icon in PNG format for the Installer application.
+#
+# .. variable:: CPACK_IFW_PACKAGE_LOGO
+#
+# Filename for a logo used as QWizard::LogoPixmap.
+#
+# .. variable:: CPACK_IFW_TARGET_DIRECTORY
+#
+# Default target directory for installation.
+# By default used "@ApplicationsDir@/:variable:`CPACK_PACKAGE_INSTALL_DIRECTORY`"
+#
+# You can use predefined variables.
+#
+# .. variable:: CPACK_IFW_ADMIN_TARGET_DIRECTORY
+#
+# Default target directory for installation with administrator rights.
+#
+# You can use predefined variables.
+#
+# .. variable:: CPACK_IFW_PACKAGE_GROUP
+#
+# The group, which will be used to configure the root package
+#
+# .. variable:: CPACK_IFW_PACKAGE_NAME
+#
+# The root package name, which will be used if configuration group is not
+# specified
+#
+# .. variable:: CPACK_IFW_REPOSITORIES_ALL
+#
+# The list of remote repositories.
+#
+# The default value of this variable is computed by CPack and contains
+# all repositories added with command :command:`cpack_ifw_add_repository`
+#
+# .. variable:: CPACK_IFW_DOWNLOAD_ALL
+#
+# If this is ``ON`` all components will be downloaded.
+# By default is ``OFF`` or used value
+# from :variable:`CPACK_DOWNLOAD_ALL` if set
+#
+# Components
+# """"""""""
+#
+# .. variable:: CPACK_IFW_RESOLVE_DUPLICATE_NAMES
+#
+# Resolve duplicate names when installing components with groups.
+#
+# .. variable:: CPACK_IFW_PACKAGES_DIRECTORIES
+#
+# Additional prepared packages dirs that will be used to resolve
+# dependent components.
+#
+# Tools
+# """"""""
+#
+# .. variable:: CPACK_IFW_BINARYCREATOR_EXECUTABLE
+#
+# The path to "binarycreator" command line client.
+#
+# This variable is cached and can be configured user if need.
+#
+# .. variable:: CPACK_IFW_REPOGEN_EXECUTABLE
+#
+# The path to "repogen" command line client.
+#
+# This variable is cached and can be configured user if need.
+#
+# Commands
+# ^^^^^^^^^
+#
+# The module defines the following commands:
+#
+# --------------------------------------------------------------------------
+#
+# .. command:: cpack_ifw_configure_component
+#
+# Sets the arguments specific to the CPack IFW generator.
+#
+# ::
+#
+# cpack_ifw_configure_component(<compname> [COMMON]
+# [NAME <name>]
+# [VERSION <version>]
+# [SCRIPT <script>]
+# [PRIORITY <priority>]
+# [DEPENDS <com_id> ...]
+# [LICENSES <display_name> <file_path> ...])
+#
+# This command should be called after cpack_add_component command.
+#
+# ``COMMON`` if set, then the component will be packaged and installed as part
+# of a group to which he belongs.
+#
+# ``VERSION`` is version of component.
+# By default used :variable:`CPACK_PACKAGE_VERSION`.
+#
+# ``SCRIPT`` is relative or absolute path to operations script
+# for this component.
+#
+# ``NAME`` is used to create domain-like identification for this component.
+# By default used origin component name.
+#
+# ``PRIORITY`` is priority of the component in the tree.
+#
+# ``DEPENDS`` list of dependency component identifiers in QtIFW_ style.
+#
+# ``LICENSES`` pair of <display_name> and <file_path> of license text for this
+# component. You can specify more then one license.
+#
+# --------------------------------------------------------------------------
+#
+# .. command:: cpack_ifw_configure_component_group
+#
+# Sets the arguments specific to the CPack IFW generator.
+#
+# ::
+#
+# cpack_ifw_configure_component_group(<grpname>
+# [VERSION <version>]
+# [NAME <name>]
+# [SCRIPT <script>]
+# [PRIORITY <priority>]
+# [LICENSES <display_name> <file_path> ...])
+#
+# This command should be called after cpack_add_component_group command.
+#
+# ``VERSION`` is version of component group.
+# By default used :variable:`CPACK_PACKAGE_VERSION`.
+#
+# ``NAME`` is used to create domain-like identification for this component group.
+# By default used origin component group name.
+#
+# ``SCRIPT`` is relative or absolute path to operations script
+# for this component group.
+#
+# ``PRIORITY`` is priority of the component group in the tree.
+#
+# ``LICENSES`` pair of <display_name> and <file_path> of license text for this
+# component group. You can specify more then one license.
+#
+# --------------------------------------------------------------------------
+#
+# .. command:: cpack_ifw_add_repository
+#
+# Add QtIFW_ specific remote repository.
+#
+# ::
+#
+# cpack_ifw_add_repository(<reponame> [DISABLED]
+# URL <url>
+# [USERNAME <username>]
+# [PASSWORD <password>]
+# [DISPLAY_NAME <display_name>])
+#
+# This macro will also add the <reponame> repository
+# to a variable :variable:`CPACK_IFW_REPOSITORIES_ALL`
+#
+# ``DISABLED`` if set, then the repository will be disabled by default.
+#
+# ``URL`` is points to a list of available components.
+#
+# ``USERNAME`` is used as user on a protected repository.
+#
+# ``PASSWORD`` is password to use on a protected repository.
+#
+# ``DISPLAY_NAME`` is string to display instead of the URL.
+#
+# Example usage
+# ^^^^^^^^^^^^^
+#
+# .. code-block:: cmake
+#
+# set(CPACK_PACKAGE_NAME "MyPackage")
+# set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyPackage Installation Example")
+# set(CPACK_PACKAGE_VERSION "1.0.0") # Version of installer
+#
+# include(CPack)
+# include(CPackIFW)
+#
+# cpack_add_component(myapp
+# DISPLAY_NAME "MyApp"
+# DESCRIPTION "My Application")
+# cpack_ifw_configure_component(myapp
+# VERSION "1.2.3" # Version of component
+# SCRIPT "operations.qs")
+# cpack_add_component(mybigplugin
+# DISPLAY_NAME "MyBigPlugin"
+# DESCRIPTION "My Big Downloadable Plugin"
+# DOWNLOADED)
+# cpack_ifw_add_repository(myrepo
+# URL "http://example.com/ifw/repo/myapp"
+# DISPLAY_NAME "My Application Repository")
+#
+#
+# Online installer
+# ^^^^^^^^^^^^^^^^
+#
+# By defaul CPack IFW generator make offline installer. This means that all
+# components will be packaged into a binary file.
+#
+# To make a component downloaded, you must set the ``DOWNLOADED`` option in
+# :command:`cpack_add_component`.
+#
+# Then you would use the command :command:`cpack_configure_downloads`.
+# If you set ``ALL`` option all components will be downloaded.
+#
+# You also can use command :command:`cpack_ifw_add_repository` and
+# variable :variable:`CPACK_IFW_DOWNLOAD_ALL` for more specific configuration.
+#
+# CPack IFW generator create "repository" dir in current binary dir. You
+# would copy content of this dir to specified ``site`` (``url``).
+#
+# See Also
+# ^^^^^^^^
+#
+# Qt Installer Framework Manual:
+#
+# Index page
+# http://qt-project.org/doc/qtinstallerframework/index.html
+#
+# Component Scripting
+# http://qt-project.org/doc/qtinstallerframework/scripting.html
+#
+# Predefined Variables
+# http://qt-project.org/doc/qtinstallerframework/scripting.html#predefined-variables
+#
+# Download Qt Installer Framework for you platform from Qt Project site:
+# http://download.qt-project.org/official_releases/qt-installer-framework/
+#
+
+#=============================================================================
+# Copyright 2014 Kitware, Inc.
+# Copyright 2014 Konstantin Podsvirov <konstantin@podsvirov.pro>
+#
+# 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.)
+
+#=============================================================================
+# Search Qt Installer Framework tools
+#=============================================================================
+
+# Default path
+
+set(_CPACK_IFW_PATHS
+ "${QTIFWDIR}"
+ "$ENV{QTIFWDIR}"
+ "${QTDIR}"
+ "$ENV{QTIFWDIR}")
+if(WIN32)
+ list(APPEND _CPACK_IFW_PATHS
+ "$ENV{HOMEDRIVE}/Qt"
+ "C:/Qt")
+else()
+ list(APPEND _CPACK_IFW_PATHS
+ "$ENV{HOME}/Qt"
+ "/opt/Qt")
+endif()
+
+set(_CPACK_IFW_SUFFIXES
+ "bin"
+ "QtIFW-1.7.0/bin"
+ "QtIFW-1.6.0/bin"
+ "QtIFW-1.5.0/bin"
+ "QtIFW-1.4.0/bin"
+ "QtIFW-1.3.0/bin")
+
+# Look for 'binarycreator'
+
+find_program(CPACK_IFW_BINARYCREATOR_EXECUTABLE
+ NAMES binarycreator
+ PATHS ${_CPACK_IFW_PATHS}
+ PATH_SUFFIXES ${_CPACK_IFW_SUFFIXES}
+ DOC "QtIFW binarycreator command line client")
+
+mark_as_advanced(CPACK_IFW_BINARYCREATOR_EXECUTABLE)
+
+# Look for 'repogen'
+
+find_program(CPACK_IFW_REPOGEN_EXECUTABLE
+ NAMES repogen
+ PATHS ${_CPACK_IFW_PATHS}
+ PATH_SUFFIXES ${_CPACK_IFW_SUFFIXES}
+ DOC "QtIFW repogen command line client"
+ )
+mark_as_advanced(CPACK_IFW_REPOGEN_EXECUTABLE)
+
+#
+## Next code is included only once
+#
+
+if(NOT CPackIFW_CMake_INCLUDED)
+set(CPackIFW_CMake_INCLUDED 1)
+
+#=============================================================================
+# Macro definition
+#=============================================================================
+
+# Macro definition based on CPackComponent
+
+if(NOT CPackComponent_CMake_INCLUDED)
+ include(CPackComponent)
+endif()
+
+if(NOT __CMAKE_PARSE_ARGUMENTS_INCLUDED)
+ include(CMakeParseArguments)
+endif()
+
+# Resolve full filename for script file
+macro(_cpack_ifw_resolve_script _variable)
+ set(_ifw_script_macro ${_variable})
+ set(_ifw_script_file ${${_ifw_script_macro}})
+ if(DEFINED ${_ifw_script_macro})
+ get_filename_component(${_ifw_script_macro} ${_ifw_script_file} ABSOLUTE)
+ set(_ifw_script_file ${${_ifw_script_macro}})
+ if(NOT EXISTS ${_ifw_script_file})
+ message(WARNING "CPack IFW: script file \"${_ifw_script_file}\" is not exists")
+ set(${_ifw_script_macro})
+ endif()
+ endif()
+endmacro()
+
+# Resolve full path to lisense file
+macro(_cpack_ifw_resolve_lisenses _variable)
+ if(${_variable})
+ set(_ifw_license_file FALSE)
+ set(_ifw_licenses_fix)
+ foreach(_ifw_licenses_arg ${${_variable}})
+ if(_ifw_license_file)
+ get_filename_component(_ifw_licenses_arg "${_ifw_licenses_arg}" ABSOLUTE)
+ set(_ifw_license_file FALSE)
+ else()
+ set(_ifw_license_file TRUE)
+ endif()
+ list(APPEND _ifw_licenses_fix "${_ifw_licenses_arg}")
+ endforeach(_ifw_licenses_arg)
+ set(${_variable} "${_ifw_licenses_fix}")
+ endif()
+endmacro()
+
+# Macro for configure component
+macro(cpack_ifw_configure_component compname)
+
+ string(TOUPPER ${compname} _CPACK_IFWCOMP_UNAME)
+
+ set(_IFW_OPT COMMON)
+ set(_IFW_ARGS VERSION SCRIPT NAME PRIORITY)
+ set(_IFW_MULTI_ARGS DEPENDS LICENSES)
+ cmake_parse_arguments(CPACK_IFW_COMPONENT_${_CPACK_IFWCOMP_UNAME} "${_IFW_OPT}" "${_IFW_ARGS}" "${_IFW_MULTI_ARGS}" ${ARGN})
+
+ _cpack_ifw_resolve_script(CPACK_IFW_COMPONENT_${_CPACK_IFWCOMP_UNAME}_SCRIPT)
+ _cpack_ifw_resolve_lisenses(CPACK_IFW_COMPONENT_${_CPACK_IFWCOMP_UNAME}_LICENSES)
+
+ set(_CPACK_IFWCOMP_STR "\n# Configuration for IFW component \"${compname}\"\n")
+
+ foreach(_IFW_ARG_NAME ${_IFW_OPT})
+ cpack_append_option_set_command(
+ CPACK_IFW_COMPONENT_${_CPACK_IFWCOMP_UNAME}_${_IFW_ARG_NAME}
+ _CPACK_IFWCOMP_STR)
+ endforeach()
+
+ foreach(_IFW_ARG_NAME ${_IFW_ARGS})
+ cpack_append_string_variable_set_command(
+ CPACK_IFW_COMPONENT_${_CPACK_IFWCOMP_UNAME}_${_IFW_ARG_NAME}
+ _CPACK_IFWCOMP_STR)
+ endforeach()
+
+ foreach(_IFW_ARG_NAME ${_IFW_MULTI_ARGS})
+ cpack_append_variable_set_command(
+ CPACK_IFW_COMPONENT_${_CPACK_IFWCOMP_UNAME}_${_IFW_ARG_NAME}
+ _CPACK_IFWCOMP_STR)
+ endforeach()
+
+ if(CPack_CMake_INCLUDED)
+ file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${_CPACK_IFWCOMP_STR}")
+ endif()
+
+endmacro()
+
+# Macro for configure group
+macro(cpack_ifw_configure_component_group grpname)
+
+ string(TOUPPER ${grpname} _CPACK_IFWGRP_UNAME)
+
+ set(_IFW_OPT)
+ set(_IFW_ARGS NAME VERSION SCRIPT PRIORITY)
+ set(_IFW_MULTI_ARGS LICENSES)
+ cmake_parse_arguments(CPACK_IFW_COMPONENT_GROUP_${_CPACK_IFWGRP_UNAME} "${_IFW_OPT}" "${_IFW_ARGS}" "${_IFW_MULTI_ARGS}" ${ARGN})
+
+ _cpack_ifw_resolve_script(CPACK_IFW_COMPONENT_GROUP_${_CPACK_IFWGRP_UNAME}_SCRIPT)
+ _cpack_ifw_resolve_lisenses(CPACK_IFW_COMPONENT_GROUP_${_CPACK_IFWGRP_UNAME}_LICENSES)
+
+ set(_CPACK_IFWGRP_STR "\n# Configuration for IFW component group \"${grpname}\"\n")
+
+ foreach(_IFW_ARG_NAME ${_IFW_ARGS})
+ cpack_append_string_variable_set_command(
+ CPACK_IFW_COMPONENT_GROUP_${_CPACK_IFWGRP_UNAME}_${_IFW_ARG_NAME}
+ _CPACK_IFWGRP_STR)
+ endforeach()
+
+ foreach(_IFW_ARG_NAME ${_IFW_MULTI_ARGS})
+ cpack_append_variable_set_command(
+ CPACK_IFW_COMPONENT_GROUP_${_CPACK_IFWGRP_UNAME}_${_IFW_ARG_NAME}
+ _CPACK_IFWGRP_STR)
+ endforeach()
+
+ if(CPack_CMake_INCLUDED)
+ file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${_CPACK_IFWGRP_STR}")
+ endif()
+endmacro()
+
+# Macro for adding repository
+macro(cpack_ifw_add_repository reponame)
+
+ string(TOUPPER ${reponame} _CPACK_IFWREPO_UNAME)
+
+ set(_IFW_OPT DISABLED)
+ set(_IFW_ARGS URL USERNAME PASSWORD DISPLAY_NAME)
+ set(_IFW_MULTI_ARGS)
+ cmake_parse_arguments(CPACK_IFW_REPOSITORY_${_CPACK_IFWREPO_UNAME} "${_IFW_OPT}" "${_IFW_ARGS}" "${_IFW_MULTI_ARGS}" ${ARGN})
+
+ set(_CPACK_IFWREPO_STR "\n# Configuration for IFW repository \"${reponame}\"\n")
+
+ foreach(_IFW_ARG_NAME ${_IFW_OPT})
+ cpack_append_option_set_command(
+ CPACK_IFW_REPOSITORY_${_CPACK_IFWREPO_UNAME}_${_IFW_ARG_NAME}
+ _CPACK_IFWREPO_STR)
+ endforeach()
+
+ foreach(_IFW_ARG_NAME ${_IFW_ARGS})
+ cpack_append_string_variable_set_command(
+ CPACK_IFW_REPOSITORY_${_CPACK_IFWREPO_UNAME}_${_IFW_ARG_NAME}
+ _CPACK_IFWREPO_STR)
+ endforeach()
+
+ foreach(_IFW_ARG_NAME ${_IFW_MULTI_ARGS})
+ cpack_append_variable_set_command(
+ CPACK_IFW_REPOSITORY_${_CPACK_IFWREPO_UNAME}_${_IFW_ARG_NAME}
+ _CPACK_IFWREPO_STR)
+ endforeach()
+
+ list(APPEND CPACK_IFW_REPOSITORIES_ALL ${reponame})
+ set(_CPACK_IFWREPO_STR "${_CPACK_IFWREPO_STR}list(APPEND CPACK_IFW_REPOSITORIES_ALL ${reponame})\n")
+
+ if(CPack_CMake_INCLUDED)
+ file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${_CPACK_IFWREPO_STR}")
+ endif()
+
+endmacro()
+
+endif() # NOT CPackIFW_CMake_INCLUDED
diff --git a/Modules/CPackNSIS.cmake b/Modules/CPackNSIS.cmake
new file mode 100644
index 0000000000..9d23ec001b
--- /dev/null
+++ b/Modules/CPackNSIS.cmake
@@ -0,0 +1,135 @@
+#.rst:
+# CPackNSIS
+# ---------
+#
+# CPack NSIS generator specific options
+#
+# Variables specific to CPack NSIS generator
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# The following variables are specific to the graphical installers built
+# on Windows using the Nullsoft Installation System.
+#
+# .. variable:: CPACK_NSIS_INSTALL_ROOT
+#
+# The default installation directory presented to the end user by the NSIS
+# installer is under this root dir. The full directory presented to the end
+# user is: ${CPACK_NSIS_INSTALL_ROOT}/${CPACK_PACKAGE_INSTALL_DIRECTORY}
+#
+# .. variable:: CPACK_NSIS_MUI_ICON
+#
+# An icon filename. The name of a ``*.ico`` file used as the main icon for the
+# generated install program.
+#
+# .. variable:: CPACK_NSIS_MUI_UNIICON
+#
+# An icon filename. The name of a ``*.ico`` file used as the main icon for the
+# generated uninstall program.
+#
+# .. variable:: CPACK_NSIS_INSTALLER_MUI_ICON_CODE
+#
+# undocumented.
+#
+# .. variable:: CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS
+#
+# Extra NSIS commands that will be added to the beginning of the install
+# Section, before your install tree is available on the target system.
+#
+# .. variable:: CPACK_NSIS_EXTRA_INSTALL_COMMANDS
+#
+# Extra NSIS commands that will be added to the end of the install Section,
+# after your install tree is available on the target system.
+#
+# .. variable:: CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
+#
+# Extra NSIS commands that will be added to the uninstall Section, before
+# your install tree is removed from the target system.
+#
+# .. variable:: CPACK_NSIS_COMPRESSOR
+#
+# The arguments that will be passed to the NSIS SetCompressor command.
+#
+# .. variable:: CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL
+#
+# Ask about uninstalling previous versions first. If this is set to "ON",
+# then an installer will look for previous installed versions and if one is
+# found, ask the user whether to uninstall it before proceeding with the
+# install.
+#
+# .. variable:: CPACK_NSIS_MODIFY_PATH
+#
+# Modify PATH toggle. If this is set to "ON", then an extra page will appear
+# in the installer that will allow the user to choose whether the program
+# directory should be added to the system PATH variable.
+#
+# .. variable:: CPACK_NSIS_DISPLAY_NAME
+#
+# The display name string that appears in the Windows Add/Remove Program
+# control panel
+#
+# .. variable:: CPACK_NSIS_PACKAGE_NAME
+#
+# The title displayed at the top of the installer.
+#
+# .. variable:: CPACK_NSIS_INSTALLED_ICON_NAME
+#
+# A path to the executable that contains the installer icon.
+#
+# .. variable:: CPACK_NSIS_HELP_LINK
+#
+# URL to a web site providing assistance in installing your application.
+#
+# .. variable:: CPACK_NSIS_URL_INFO_ABOUT
+#
+# URL to a web site providing more information about your application.
+#
+# .. variable:: CPACK_NSIS_CONTACT
+#
+# Contact information for questions and comments about the installation
+# process.
+#
+# .. variable:: CPACK_NSIS_CREATE_ICONS_EXTRA
+#
+# Additional NSIS commands for creating start menu shortcuts.
+#
+# .. variable:: CPACK_NSIS_DELETE_ICONS_EXTRA
+#
+# Additional NSIS commands to uninstall start menu shortcuts.
+#
+# .. variable:: CPACK_NSIS_EXECUTABLES_DIRECTORY
+#
+# Creating NSIS start menu links assumes that they are in 'bin' unless this
+# variable is set. For example, you would set this to 'exec' if your
+# executables are in an exec directory.
+#
+# .. variable:: CPACK_NSIS_MUI_FINISHPAGE_RUN
+#
+# Specify an executable to add an option to run on the finish page of the
+# NSIS installer.
+#
+# .. variable:: CPACK_NSIS_MENU_LINKS
+#
+# Specify links in [application] menu. This should contain a list of pair
+# "link" "link name". The link may be an URL or a path relative to
+# installation prefix. Like::
+#
+# set(CPACK_NSIS_MENU_LINKS
+# "doc/cmake-@CMake_VERSION_MAJOR@.@CMake_VERSION_MINOR@/cmake.html" "CMake Help"
+# "http://www.cmake.org" "CMake Web Site")
+#
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+#FIXME we should put NSIS specific code here
+#FIXME but I'm not doing it because I'm not able to test it...
diff --git a/Modules/CPackPackageMaker.cmake b/Modules/CPackPackageMaker.cmake
new file mode 100644
index 0000000000..4160425198
--- /dev/null
+++ b/Modules/CPackPackageMaker.cmake
@@ -0,0 +1,37 @@
+#.rst:
+# CPackPackageMaker
+# -----------------
+#
+# PackageMaker CPack generator (Mac OS X).
+#
+# Variables specific to CPack PackageMaker generator
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# The following variable is specific to installers built on Mac
+# OS X using PackageMaker:
+#
+# .. variable:: CPACK_OSX_PACKAGE_VERSION
+#
+# The version of Mac OS X that the resulting PackageMaker archive should be
+# compatible with. Different versions of Mac OS X support different
+# features. For example, CPack can only build component-based installers for
+# Mac OS X 10.4 or newer, and can only build installers that download
+# component son-the-fly for Mac OS X 10.5 or newer. If left blank, this value
+# will be set to the minimum version of Mac OS X that supports the requested
+# features. Set this variable to some value (e.g., 10.4) only if you want to
+# guarantee that your installer will work on that version of Mac OS X, and
+# don't mind missing extra features available in the installer shipping with
+# later versions of Mac OS X.
+
+#=============================================================================
+# Copyright 2006-2012 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.)
diff --git a/Modules/CPackRPM.cmake b/Modules/CPackRPM.cmake
new file mode 100644
index 0000000000..2864b214f1
--- /dev/null
+++ b/Modules/CPackRPM.cmake
@@ -0,0 +1,1102 @@
+#.rst:
+# CPackRPM
+# --------
+#
+# The builtin (binary) CPack RPM generator (Unix only)
+#
+# Variables specific to CPack RPM generator
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# CPackRPM may be used to create RPM package using CPack. CPackRPM is a
+# CPack generator thus it uses the CPACK_XXX variables used by CPack :
+# http://www.cmake.org/Wiki/CMake:CPackConfiguration
+#
+# However CPackRPM has specific features which are controlled by the
+# specifics CPACK_RPM_XXX variables. CPackRPM is a component aware
+# generator so when CPACK_RPM_COMPONENT_INSTALL is ON some more
+# CPACK_RPM_<ComponentName>_XXXX variables may be used in order to have
+# component specific values. Note however that <componentName> refers
+# to the **grouping name**. This may be either a component name or a
+# component GROUP name. Usually those vars correspond to RPM spec file
+# entities, one may find information about spec files here
+# http://www.rpm.org/wiki/Docs. You'll find a detailed usage of
+# CPackRPM on the wiki:
+#
+# ::
+#
+# http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#RPM_.28Unix_Only.29
+#
+# However as a handy reminder here comes the list of specific variables:
+#
+# .. variable:: CPACK_RPM_PACKAGE_SUMMARY
+#
+# The RPM package summary.
+#
+# * Mandatory : YES
+# * Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY
+#
+# .. variable:: CPACK_RPM_PACKAGE_NAME
+#
+# The RPM package name.
+#
+# * Mandatory : YES
+# * Default : CPACK_PACKAGE_NAME
+#
+# .. variable:: CPACK_RPM_PACKAGE_VERSION
+#
+# The RPM package version.
+#
+# * Mandatory : YES
+# * Default : CPACK_PACKAGE_VERSION
+#
+# .. variable:: CPACK_RPM_PACKAGE_ARCHITECTURE
+#
+# The RPM package architecture.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# This may be set to "noarch" if you know you are building a noarch package.
+#
+# .. variable:: CPACK_RPM_PACKAGE_RELEASE
+#
+# The RPM package release.
+#
+# * Mandatory : YES
+# * Default : 1
+#
+# This is the numbering of the RPM package itself, i.e. the version of the
+# packaging and not the version of the content (see
+# CPACK_RPM_PACKAGE_VERSION). One may change the default value if the
+# previous packaging was buggy and/or you want to put here a fancy Linux
+# distro specific numbering.
+#
+# .. variable:: CPACK_RPM_PACKAGE_LICENSE
+#
+# The RPM package license policy.
+#
+# * Mandatory : YES
+# * Default : "unknown"
+#
+# .. variable:: CPACK_RPM_PACKAGE_GROUP
+#
+# The RPM package group.
+#
+# * Mandatory : YES
+# * Default : "unknown"
+#
+# .. variable:: CPACK_RPM_PACKAGE_VENDOR
+#
+# The RPM package vendor.
+#
+# * Mandatory : YES
+# * Default : CPACK_PACKAGE_VENDOR if set or "unknown"
+#
+# .. variable:: CPACK_RPM_PACKAGE_URL
+#
+# The projects URL.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# .. variable:: CPACK_RPM_PACKAGE_DESCRIPTION
+#
+# RPM package description.
+#
+# * Mandatory : YES
+# * Default : CPACK_PACKAGE_DESCRIPTION_FILE if set or "no package
+# description available"
+#
+# .. variable:: CPACK_RPM_COMPRESSION_TYPE
+#
+# RPM compression type.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to override RPM compression type to be used to build the
+# RPM. For example some Linux distribution now default to lzma or xz
+# compression whereas older cannot use such RPM. Using this one can enforce
+# compression type to be used. Possible value are: lzma, xz, bzip2 and gzip.
+#
+# .. variable:: CPACK_RPM_PACKAGE_REQUIRES
+#
+# RPM spec requires field.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to set RPM dependencies (requires). Note that you must enclose
+# the complete requires string between quotes, for example::
+#
+# set(CPACK_RPM_PACKAGE_REQUIRES "python >= 2.5.0, cmake >= 2.8")
+#
+# The required package list of an RPM file could be printed with::
+#
+# rpm -qp --requires file.rpm
+#
+# .. variable:: CPACK_RPM_PACKAGE_SUGGESTS
+#
+# RPM spec suggest field.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to set weak RPM dependencies (suggests). Note that you must
+# enclose the complete requires string between quotes.
+#
+# .. variable:: CPACK_RPM_PACKAGE_PROVIDES
+#
+# RPM spec provides field.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to set RPM dependencies (provides). The provided package list
+# of an RPM file could be printed with::
+#
+# rpm -qp --provides file.rpm
+#
+# .. variable:: CPACK_RPM_PACKAGE_OBSOLETES
+#
+# RPM spec obsoletes field.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to set RPM packages that are obsoleted by this one.
+#
+# .. variable:: CPACK_RPM_PACKAGE_RELOCATABLE
+#
+# build a relocatable RPM.
+#
+# * Mandatory : NO
+# * Default : CPACK_PACKAGE_RELOCATABLE
+#
+# If this variable is set to TRUE or ON CPackRPM will try
+# to build a relocatable RPM package. A relocatable RPM may
+# be installed using::
+#
+# rpm --prefix or --relocate
+#
+# in order to install it at an alternate place see rpm(8). Note that
+# currently this may fail if CPACK_SET_DESTDIR is set to ON. If
+# CPACK_SET_DESTDIR is set then you will get a warning message but if there
+# is file installed with absolute path you'll get unexpected behavior.
+#
+# .. variable:: CPACK_RPM_SPEC_INSTALL_POST
+#
+# * Mandatory : NO
+# * Default : -
+# * Deprecated: YES
+#
+# This way of specifying post-install script is deprecated, use
+# CPACK_RPM_POST_INSTALL_SCRIPT_FILE.
+# May be used to set an RPM post-install command inside the spec file.
+# For example setting it to "/bin/true" may be used to prevent
+# rpmbuild to strip binaries.
+#
+# .. variable:: CPACK_RPM_SPEC_MORE_DEFINE
+#
+# RPM extended spec definitions lines.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to add any %define lines to the generated spec file.
+#
+# .. variable:: CPACK_RPM_PACKAGE_DEBUG
+#
+# Toggle CPackRPM debug output.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be set when invoking cpack in order to trace debug information
+# during CPack RPM run. For example you may launch CPack like this::
+#
+# cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM
+#
+# .. variable:: CPACK_RPM_USER_BINARY_SPECFILE
+#
+# A user provided spec file.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be set by the user in order to specify a USER binary spec file
+# to be used by CPackRPM instead of generating the file.
+# The specified file will be processed by configure_file( @ONLY).
+# One can provide a component specific file by setting
+# CPACK_RPM_<componentName>_USER_BINARY_SPECFILE.
+#
+# .. variable:: CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
+#
+# Spec file template.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# If set CPack will generate a template for USER specified binary
+# spec file and stop with an error. For example launch CPack like this::
+#
+# cpack -D CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE=1 -G RPM
+#
+# The user may then use this file in order to hand-craft is own
+# binary spec file which may be used with CPACK_RPM_USER_BINARY_SPECFILE.
+#
+# .. variable:: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
+# CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to embed a pre (un)installation script in the spec file.
+# The refered script file(s) will be read and directly
+# put after the %pre or %preun section
+# If CPACK_RPM_COMPONENT_INSTALL is set to ON the (un)install script for
+# each component can be overridden with
+# CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE and
+# CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE.
+# One may verify which scriptlet has been included with::
+#
+# rpm -qp --scripts package.rpm
+#
+# .. variable:: CPACK_RPM_POST_INSTALL_SCRIPT_FILE
+# CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to embed a post (un)installation script in the spec file.
+# The refered script file(s) will be read and directly
+# put after the %post or %postun section.
+# If CPACK_RPM_COMPONENT_INSTALL is set to ON the (un)install script for
+# each component can be overridden with
+# CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE and
+# CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE.
+# One may verify which scriptlet has been included with::
+#
+# rpm -qp --scripts package.rpm
+#
+# .. variable:: CPACK_RPM_USER_FILELIST
+# CPACK_RPM_<COMPONENT>_USER_FILELIST
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to explicitly specify %(<directive>) file line
+# in the spec file. Like %config(noreplace) or any other directive
+# that be found in the %files section. Since CPackRPM is generating
+# the list of files (and directories) the user specified files of
+# the CPACK_RPM_<COMPONENT>_USER_FILELIST list will be removed from
+# the generated list.
+#
+# .. variable:: CPACK_RPM_CHANGELOG_FILE
+#
+# RPM changelog file.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to embed a changelog in the spec file.
+# The refered file will be read and directly put after the %changelog
+# section.
+#
+# .. variable:: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST
+#
+# list of path to be excluded.
+#
+# * Mandatory : NO
+# * Default : /etc /etc/init.d /usr /usr/share /usr/share/doc /usr/bin /usr/lib /usr/lib64 /usr/include
+#
+# May be used to exclude path (directories or files) from the auto-generated
+# list of paths discovered by CPack RPM. The defaut value contains a
+# reasonable set of values if the variable is not defined by the user. If the
+# variable is defined by the user then CPackRPM will NOT any of the default
+# path. If you want to add some path to the default list then you can use
+# CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION variable.
+#
+# .. variable:: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
+#
+# additional list of path to be excluded.
+#
+# * Mandatory : NO
+# * Default : -
+#
+# May be used to add more exclude path (directories or files) from the initial
+# default list of excluded paths. See CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Author: Eric Noulard with the help of Alexander Neundorf.
+
+if(CMAKE_BINARY_DIR)
+ message(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
+endif()
+
+if(NOT UNIX)
+ message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
+endif()
+
+# rpmbuild is the basic command for building RPM package
+# it may be a simple (symbolic) link to rpm command.
+find_program(RPMBUILD_EXECUTABLE rpmbuild)
+
+# Check version of the rpmbuild tool this would be easier to
+# track bugs with users and CPackRPM debug mode.
+# We may use RPM version in order to check for available version dependent features
+if(RPMBUILD_EXECUTABLE)
+ execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
+ OUTPUT_VARIABLE _TMP_VERSION
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX REPLACE "^.* " ""
+ RPMBUILD_EXECUTABLE_VERSION
+ ${_TMP_VERSION})
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
+ endif()
+endif()
+
+if(NOT RPMBUILD_EXECUTABLE)
+ message(FATAL_ERROR "RPM package requires rpmbuild executable")
+endif()
+
+# Display lsb_release output if DEBUG mode enable
+# This will help to diagnose problem with CPackRPM
+# because we will know on which kind of Linux we are
+if(CPACK_RPM_PACKAGE_DEBUG)
+ find_program(LSB_RELEASE_EXECUTABLE lsb_release)
+ if(LSB_RELEASE_EXECUTABLE)
+ execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a
+ OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REPLACE "\n" ", "
+ LSB_RELEASE_OUTPUT
+ ${_TMP_LSB_RELEASE_OUTPUT})
+ else ()
+ set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!")
+ endif()
+ message("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}")
+endif()
+
+# We may use RPM version in the future in order
+# to shut down warning about space in buildtree
+# some recent RPM version should support space in different places.
+# not checked [yet].
+if(CPACK_TOPLEVEL_DIRECTORY MATCHES " ")
+ message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
+endif()
+
+# If rpmbuild is found
+# we try to discover alien since we may be on non RPM distro like Debian.
+# In this case we may try to to use more advanced features
+# like generating RPM directly from DEB using alien.
+# FIXME feature not finished (yet)
+find_program(ALIEN_EXECUTABLE alien)
+if(ALIEN_EXECUTABLE)
+ message(STATUS "alien found, we may be on a Debian based distro.")
+endif()
+
+# Are we packaging components ?
+if(CPACK_RPM_PACKAGE_COMPONENT)
+ set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}")
+else()
+ set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "")
+endif()
+
+set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
+
+#
+# Use user-defined RPM specific variables value
+# or generate reasonable default value from
+# CPACK_xxx generic values.
+# The variables comes from the needed (mandatory or not)
+# values found in the RPM specification file aka ".spec" file.
+# The variables which may/should be defined are:
+#
+
+# CPACK_RPM_PACKAGE_SUMMARY (mandatory)
+if(NOT CPACK_RPM_PACKAGE_SUMMARY)
+ # if neither var is defined lets use the name as summary
+ if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
+ string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
+ else()
+ set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
+ endif()
+endif()
+
+# CPACK_RPM_PACKAGE_NAME (mandatory)
+if(NOT CPACK_RPM_PACKAGE_NAME)
+ string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
+endif()
+
+# CPACK_RPM_PACKAGE_VERSION (mandatory)
+if(NOT CPACK_RPM_PACKAGE_VERSION)
+ if(NOT CPACK_PACKAGE_VERSION)
+ message(FATAL_ERROR "RPM package requires a package version")
+ endif()
+ set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
+endif()
+# Replace '-' in version with '_'
+# '-' character is an Illegal RPM version character
+# it is illegal because it is used to separate
+# RPM "Version" from RPM "Release"
+string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
+
+# CPACK_RPM_PACKAGE_ARCHITECTURE (optional)
+if(CPACK_RPM_PACKAGE_ARCHITECTURE)
+ set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
+ endif()
+else()
+ set(TMP_RPM_BUILDARCH "")
+endif()
+
+# CPACK_RPM_PACKAGE_RELEASE
+# The RPM release is the numbering of the RPM package ITSELF
+# this is the version of the PACKAGING and NOT the version
+# of the CONTENT of the package.
+# You may well need to generate a new RPM package release
+# without changing the version of the packaged software.
+# This is the case when the packaging is buggy (not) the software :=)
+# If not set, 1 is a good candidate
+if(NOT CPACK_RPM_PACKAGE_RELEASE)
+ set(CPACK_RPM_PACKAGE_RELEASE 1)
+endif()
+
+# CPACK_RPM_PACKAGE_LICENSE
+if(NOT CPACK_RPM_PACKAGE_LICENSE)
+ set(CPACK_RPM_PACKAGE_LICENSE "unknown")
+endif()
+
+# CPACK_RPM_PACKAGE_GROUP
+if(NOT CPACK_RPM_PACKAGE_GROUP)
+ set(CPACK_RPM_PACKAGE_GROUP "unknown")
+endif()
+
+# CPACK_RPM_PACKAGE_VENDOR
+if(NOT CPACK_RPM_PACKAGE_VENDOR)
+ if(CPACK_PACKAGE_VENDOR)
+ set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
+ else()
+ set(CPACK_RPM_PACKAGE_VENDOR "unknown")
+ endif()
+endif()
+
+# CPACK_RPM_PACKAGE_SOURCE
+# The name of the source tarball in case we generate a source RPM
+
+# CPACK_RPM_PACKAGE_DESCRIPTION
+# The variable content may be either
+# - explicitly given by the user or
+# - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
+# if it is defined
+# - set to a default value
+#
+if (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
+ if (CPACK_PACKAGE_DESCRIPTION_FILE)
+ file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
+ else ()
+ set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
+ endif ()
+endif ()
+
+# CPACK_RPM_COMPRESSION_TYPE
+#
+if (CPACK_RPM_COMPRESSION_TYPE)
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}")
+ endif()
+ if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma")
+ set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.lzdio")
+ endif()
+ if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz")
+ set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w7.xzdio")
+ endif()
+ if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2")
+ set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.bzdio")
+ endif()
+ if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip")
+ set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio")
+ endif()
+else()
+ set(CPACK_RPM_COMPRESSION_TYPE_TMP "")
+endif()
+
+if(CPACK_PACKAGE_RELOCATABLE)
+ set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE)
+endif()
+if(CPACK_RPM_PACKAGE_RELOCATABLE)
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: Trying to build a relocatable package")
+ endif()
+ if(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON"))
+ message("CPackRPM:Warning: CPACK_SET_DESTDIR is set (=${CPACK_SET_DESTDIR}) while requesting a relocatable package (CPACK_RPM_PACKAGE_RELOCATABLE is set): this is not supported, the package won't be relocatable.")
+ else()
+ set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX})
+ endif()
+endif()
+
+# Check if additional fields for RPM spec header are given
+# There may be some COMPONENT specific variables as well
+# If component specific var is not provided we use the global one
+# for each component
+foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV)
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}")
+ endif()
+ if(CPACK_RPM_PACKAGE_COMPONENT)
+ if(DEFINED CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER})
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: using CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}")
+ endif()
+ set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}})
+ else()
+ if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER} not defined")
+ message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}")
+ endif()
+ set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}})
+ endif()
+ endif()
+ else()
+ if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}")
+ endif()
+ set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}})
+ endif()
+ endif()
+
+ # Treat the RPM Spec keyword iff it has been properly defined
+ if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
+ # Transform NAME --> Name e.g. PROVIDES --> Provides
+ # The Upper-case first letter and lowercase tail is the
+ # appropriate value required in the final RPM spec file.
+ string(LENGTH ${_RPM_SPEC_HEADER} _PACKAGE_HEADER_STRLENGTH)
+ math(EXPR _PACKAGE_HEADER_STRLENGTH "${_PACKAGE_HEADER_STRLENGTH} - 1")
+ string(SUBSTRING ${_RPM_SPEC_HEADER} 1 ${_PACKAGE_HEADER_STRLENGTH} _PACKAGE_HEADER_TAIL)
+ string(TOLOWER "${_PACKAGE_HEADER_TAIL}" _PACKAGE_HEADER_TAIL)
+ string(SUBSTRING ${_RPM_SPEC_HEADER} 0 1 _PACKAGE_HEADER_NAME)
+ set(_PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_NAME}${_PACKAGE_HEADER_TAIL}")
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: User defined ${_PACKAGE_HEADER_NAME}:\n ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
+ endif()
+ set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
+ else()
+ # Do not forget to unset previously set header (from previous component)
+ unset(TMP_RPM_${_RPM_SPEC_HEADER})
+ endif()
+endforeach()
+
+# CPACK_RPM_SPEC_INSTALL_POST
+# May be used to define a RPM post intallation script
+# for example setting it to "/bin/true" may prevent
+# rpmbuild from stripping binaries.
+if(CPACK_RPM_SPEC_INSTALL_POST)
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
+ endif()
+ set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
+endif()
+
+# CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE)
+# CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE)
+# May be used to embed a post (un)installation script in the spec file.
+# The refered script file(s) will be read and directly
+# put after the %post or %postun section
+if(CPACK_RPM_PACKAGE_COMPONENT)
+ if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE)
+ set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE})
+ else()
+ set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
+ endif()
+ if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_UNINSTALL_SCRIPT_FILE)
+ set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_UNINSTALL_SCRIPT_FILE})
+ else()
+ set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
+ endif()
+else()
+ set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
+ set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
+endif()
+
+# Handle post-install file if it has been specified
+if(CPACK_RPM_POST_INSTALL_READ_FILE)
+ if(EXISTS ${CPACK_RPM_POST_INSTALL_READ_FILE})
+ file(READ ${CPACK_RPM_POST_INSTALL_READ_FILE} CPACK_RPM_SPEC_POSTINSTALL)
+ else()
+ message("CPackRPM:Warning: CPACK_RPM_POST_INSTALL_SCRIPT_FILE <${CPACK_RPM_POST_INSTALL_READ_FILE}> does not exists - ignoring")
+ endif()
+else()
+ # reset SPEC var value if no post install file has been specified
+ # (either globally or component-wise)
+ set(CPACK_RPM_SPEC_POSTINSTALL "")
+endif()
+
+# Handle post-uninstall file if it has been specified
+if(CPACK_RPM_POST_UNINSTALL_READ_FILE)
+ if(EXISTS ${CPACK_RPM_POST_UNINSTALL_READ_FILE})
+ file(READ ${CPACK_RPM_POST_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_POSTUNINSTALL)
+ else()
+ message("CPackRPM:Warning: CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_POST_UNINSTALL_READ_FILE}> does not exists - ignoring")
+ endif()
+else()
+ # reset SPEC var value if no post uninstall file has been specified
+ # (either globally or component-wise)
+ set(CPACK_RPM_SPEC_POSTUNINSTALL "")
+endif()
+
+# CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE)
+# CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE)
+# May be used to embed a pre (un)installation script in the spec file.
+# The refered script file(s) will be read and directly
+# put after the %pre or %preun section
+if(CPACK_RPM_PACKAGE_COMPONENT)
+ if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE)
+ set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE})
+ else()
+ set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
+ endif()
+ if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_UNINSTALL_SCRIPT_FILE)
+ set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_UNINSTALL_SCRIPT_FILE})
+ else()
+ set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
+ endif()
+else()
+ set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
+ set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
+endif()
+
+# Handle pre-install file if it has been specified
+if(CPACK_RPM_PRE_INSTALL_READ_FILE)
+ if(EXISTS ${CPACK_RPM_PRE_INSTALL_READ_FILE})
+ file(READ ${CPACK_RPM_PRE_INSTALL_READ_FILE} CPACK_RPM_SPEC_PREINSTALL)
+ else()
+ message("CPackRPM:Warning: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_INSTALL_READ_FILE}> does not exists - ignoring")
+ endif()
+else()
+ # reset SPEC var value if no pre-install file has been specified
+ # (either globally or component-wise)
+ set(CPACK_RPM_SPEC_PREINSTALL "")
+endif()
+
+# Handle pre-uninstall file if it has been specified
+if(CPACK_RPM_PRE_UNINSTALL_READ_FILE)
+ if(EXISTS ${CPACK_RPM_PRE_UNINSTALL_READ_FILE})
+ file(READ ${CPACK_RPM_PRE_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_PREUNINSTALL)
+ else()
+ message("CPackRPM:Warning: CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_UNINSTALL_READ_FILE}> does not exists - ignoring")
+ endif()
+else()
+ # reset SPEC var value if no pre-uninstall file has been specified
+ # (either globally or component-wise)
+ set(CPACK_RPM_SPEC_PREUNINSTALL "")
+endif()
+
+# CPACK_RPM_CHANGELOG_FILE
+# May be used to embed a changelog in the spec file.
+# The refered file will be read and directly put after the %changelog section
+if(CPACK_RPM_CHANGELOG_FILE)
+ if(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
+ file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG)
+ else()
+ message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring")
+ endif()
+else()
+ set(CPACK_RPM_SPEC_CHANGELOG "* Sun Jul 4 2010 Eric Noulard <eric.noulard@gmail.com> - ${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}\n Generated by CPack RPM (no Changelog file were provided)")
+endif()
+
+# CPACK_RPM_SPEC_MORE_DEFINE
+# This is a generated spec rpm file spaceholder
+if(CPACK_RPM_SPEC_MORE_DEFINE)
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
+ endif()
+endif()
+
+# Now we may create the RPM build tree structure
+set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
+message(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
+# Prepare RPM build tree
+file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
+file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
+file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
+file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
+file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
+file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
+file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
+
+#set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
+set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
+# it seems rpmbuild can't handle spaces in the path
+# neither escaping (as below) nor putting quotes around the path seem to help
+#string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
+set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
+
+# if we are creating a relocatable package, omit parent directories of
+# CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list"
+# which is passed to the find command that generates the content-list
+if(CPACK_RPM_PACKAGE_RELOCATABLE)
+ # get a list of the elements in CPACK_RPM_PACKAGE_PREFIX and remove
+ # the final element (so the install-prefix dir itself is not omitted
+ # from the RPM's content-list)
+ string(REPLACE "/" ";" _CPACK_RPM_PACKAGE_PREFIX_ELEMS ".${CPACK_RPM_PACKAGE_PREFIX}")
+ list(REMOVE_AT _CPACK_RPM_PACKAGE_PREFIX_ELEMS -1)
+ # Now generate all of the parent dirs of CPACK_RPM_PACKAGE_PREFIX
+ foreach(_ELEM ${_CPACK_RPM_PACKAGE_PREFIX_ELEMS})
+ list(APPEND _TMP_LIST "${_ELEM}")
+ string(REPLACE ";" "/" _OMIT_DIR "${_TMP_LIST}")
+ set(_OMIT_DIR "-o -path ${_OMIT_DIR}")
+ separate_arguments(_OMIT_DIR)
+ list(APPEND _RPM_DIRS_TO_OMIT ${_OMIT_DIR})
+ endforeach()
+endif()
+
+if (CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: Initial list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
+endif()
+
+if (NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
+ set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST /etc /etc/init.d /usr /usr/share /usr/share/doc /usr/bin /usr/lib /usr/lib64 /usr/include)
+ if (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION)
+ message("CPackRPM:Debug: Adding ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION} to builtin omit list.")
+ list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}")
+ endif()
+endif()
+
+if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
+ if (CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST= ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}")
+ endif()
+ foreach(_DIR ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST})
+ list(APPEND _RPM_DIRS_TO_OMIT "-o;-path;.${_DIR}")
+ endforeach()
+endif()
+if (CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: Final list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
+endif()
+
+# Use files tree to construct files command (spec file)
+# We should not forget to include symlinks (thus -o -type l)
+# We should include directory as well (thus -type d)
+# but not the main local dir "." (thus -a -not -name ".")
+# We must remove the './' due to the local search and escape the
+# file name by enclosing it between double quotes (thus the sed)
+# Then we must authorize any man pages extension (adding * at the end)
+# because rpmbuild may automatically compress those files
+execute_process(COMMAND find . -type f -o -type l -o (-type d -a -not ( -name "." ${_RPM_DIRS_TO_OMIT} ) )
+ COMMAND sed s:.*/man.*/.*:&*:
+ COMMAND sed s/\\.\\\(.*\\\)/\"\\1\"/
+ WORKING_DIRECTORY "${WDIR}"
+ OUTPUT_VARIABLE CPACK_RPM_INSTALL_FILES)
+
+# In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_<COMPONENT>
+# into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
+# otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES
+# This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling
+if(CPACK_RPM_PACKAGE_COMPONENT)
+ if(CPACK_ABSOLUTE_DESTINATION_FILES)
+ set(COMPONENT_FILES_TAG "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}")
+ set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}")
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: Handling Absolute Destination Files: <${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}>")
+ message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
+ endif()
+ endif()
+else()
+ if(CPACK_ABSOLUTE_DESTINATION_FILES)
+ set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}")
+ endif()
+endif()
+
+# In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM_<COMPONENT>_USER_FILELIST.
+if(CPACK_RPM_PACKAGE_COMPONENT)
+ if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST)
+ set(CPACK_RPM_USER_FILELIST_INTERNAL ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST})
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
+ message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
+ endif()
+ else()
+ set(CPACK_RPM_USER_FILELIST_INTERNAL "")
+ endif()
+else()
+ if(CPACK_RPM_USER_FILELIST)
+ set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}")
+ else()
+ set(CPACK_RPM_USER_FILELIST_INTERNAL "")
+ endif()
+endif()
+
+# Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL
+# Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
+# or CPACK_RPM_INSTALL_FILES,
+# hence it must be done before these auto-generated lists are processed.
+if(CPACK_RPM_USER_FILELIST_INTERNAL)
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
+ endif()
+
+ # Create CMake list from CPACK_RPM_INSTALL_FILES
+ string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
+ string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
+ "${CPACK_RPM_INSTALL_FILES_LIST}")
+ string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
+ "${CPACK_RPM_INSTALL_FILES_LIST}")
+
+ set(CPACK_RPM_USER_INSTALL_FILES "")
+ foreach(F IN LISTS CPACK_RPM_USER_FILELIST_INTERNAL)
+ string(REGEX REPLACE "%[A-Za-z0-9\(\),-]* " "" F_PATH ${F})
+ string(REGEX MATCH "%[A-Za-z0-9\(\),-]*" F_PREFIX ${F})
+
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: F_PREFIX=<${F_PREFIX}>, F_PATH=<${F_PATH}>")
+ endif()
+ if(F_PREFIX)
+ set(F_PREFIX "${F_PREFIX} ")
+ endif()
+ # Rebuild the user list file
+ set(CPACK_RPM_USER_INSTALL_FILES "${CPACK_RPM_USER_INSTALL_FILES}${F_PREFIX}\"${F_PATH}\"\n")
+
+ # Remove from CPACK_RPM_INSTALL_FILES and CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
+ list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${F_PATH})
+ # ABSOLUTE destination files list may not exists at all
+ if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
+ list(REMOVE_ITEM CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL ${F_PATH})
+ endif()
+
+ endforeach()
+
+ # Rebuild CPACK_RPM_INSTALL_FILES
+ set(CPACK_RPM_INSTALL_FILES "")
+ foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
+ set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
+ endforeach()
+else()
+ set(CPACK_RPM_USER_INSTALL_FILES "")
+endif()
+
+if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}")
+ endif()
+ # Remove trailing space
+ string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
+ # Transform endline separated - string into CMake List
+ string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
+ # Remove unecessary quotes
+ string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
+ # Remove ABSOLUTE install file from INSTALL FILE LIST
+ list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL})
+ # Rebuild INSTALL_FILES
+ set(CPACK_RPM_INSTALL_FILES "")
+ foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
+ set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
+ endforeach()
+ # Build ABSOLUTE_INSTALL_FILES
+ set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
+ foreach(F IN LISTS CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
+ set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "${CPACK_RPM_ABSOLUTE_INSTALL_FILES}%config \"${F}\"\n")
+ endforeach()
+ if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}")
+ message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}")
+ endif()
+else()
+ # reset vars in order to avoid leakage of value(s) from one component to another
+ set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
+endif()
+
+# Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir
+# This is necessary to avoid duplicate files since rpmbuild do
+# recursion on its own when encountering a pathname which is a directory
+# which is not flagged as %dir
+string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
+string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
+ "${CPACK_RPM_INSTALL_FILES_LIST}")
+string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
+ "${CPACK_RPM_INSTALL_FILES_LIST}")
+set(CPACK_RPM_INSTALL_FILES "")
+foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
+ if(IS_DIRECTORY "${WDIR}/${F}")
+ set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}%dir \"${F}\"\n")
+ else()
+ set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
+ endif()
+endforeach()
+set(CPACK_RPM_INSTALL_FILES_LIST "")
+
+# 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")
+
+# Print out some debug information if we were asked for that
+if(CPACK_RPM_PACKAGE_DEBUG)
+ message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
+ message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
+ message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
+ message("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}")
+ message("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}")
+ message("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
+ message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
+ message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
+ message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
+endif()
+
+# protect @ in pathname in order to avoid their
+# interpretation during the configure_file step
+set(CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES}")
+set(PROTECTED_AT "@")
+string(REPLACE "@" "\@PROTECTED_AT\@" CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES_LIST}")
+set(CPACK_RPM_INSTALL_FILES_LIST "")
+
+#
+# USER generated/provided spec file handling.
+#
+
+# We can have a component specific spec file.
+if(CPACK_RPM_PACKAGE_COMPONENT AND CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE)
+ set(CPACK_RPM_USER_BINARY_SPECFILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE})
+endif()
+
+# We should generate a USER spec file template:
+# - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
+# - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE
+if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
+ file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
+ "# -*- 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\@
+Version: \@CPACK_RPM_PACKAGE_VERSION\@
+Release: \@CPACK_RPM_PACKAGE_RELEASE\@
+License: \@CPACK_RPM_PACKAGE_LICENSE\@
+Group: \@CPACK_RPM_PACKAGE_GROUP\@
+Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
+\@TMP_RPM_URL\@
+\@TMP_RPM_REQUIRES\@
+\@TMP_RPM_PROVIDES\@
+\@TMP_RPM_OBSOLETES\@
+\@TMP_RPM_CONFLICTS\@
+\@TMP_RPM_AUTOPROV\@
+\@TMP_RPM_AUTOREQ\@
+\@TMP_RPM_AUTOREQPROV\@
+\@TMP_RPM_BUILDARCH\@
+\@TMP_RPM_PREFIX\@
+
+%define _rpmdir \@CPACK_RPM_DIRECTORY\@
+%define _rpmfilename \@CPACK_RPM_FILE_NAME\@
+%define _unpackaged_files_terminate_build 0
+%define _topdir \@CPACK_RPM_DIRECTORY\@
+\@TMP_RPM_SPEC_INSTALL_POST\@
+\@CPACK_RPM_SPEC_MORE_DEFINE\@
+\@CPACK_RPM_COMPRESSION_TYPE_TMP\@
+
+%description
+\@CPACK_RPM_PACKAGE_DESCRIPTION\@
+
+# This is a shortcutted spec file generated by CMake RPM generator
+# we skip _install step because CPack does that for us.
+# We do only save CPack installed tree in _prepr
+# and then restore it in build.
+%prep
+mv $RPM_BUILD_ROOT \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\"
+
+#p build
+
+%install
+if [ -e $RPM_BUILD_ROOT ];
+then
+ rm -rf $RPM_BUILD_ROOT
+fi
+mv \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\" $RPM_BUILD_ROOT
+
+%clean
+
+%post
+\@CPACK_RPM_SPEC_POSTINSTALL\@
+
+%postun
+\@CPACK_RPM_SPEC_POSTUNINSTALL\@
+
+%pre
+\@CPACK_RPM_SPEC_PREINSTALL\@
+
+%preun
+\@CPACK_RPM_SPEC_PREUNINSTALL\@
+
+%files
+%defattr(-,root,root,-)
+\@CPACK_RPM_INSTALL_FILES\@
+\@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@
+\@CPACK_RPM_USER_INSTALL_FILES\@
+
+%changelog
+\@CPACK_RPM_SPEC_CHANGELOG\@
+")
+ # Stop here if we were asked to only generate a template USER spec file
+ # The generated file may then be used as a template by user who wants
+ # to customize their own spec file.
+ if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
+ message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file templare is: ${CPACK_RPM_BINARY_SPECFILE}.in")
+ endif()
+endif()
+
+# After that we may either use a user provided spec file
+# or generate one using appropriate variables value.
+if(CPACK_RPM_USER_BINARY_SPECFILE)
+ # User may have specified SPECFILE just use it
+ message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
+ # The user provided file is processed for @var replacement
+ configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
+else()
+ # No User specified spec file, will use the generated spec file
+ message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}")
+ # Note the just created file is processed for @var replacement
+ configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
+endif()
+
+# remove AT protection
+unset(PROTECTED_AT)
+
+if(RPMBUILD_EXECUTABLE)
+ # Now call rpmbuild using the SPECFILE
+ execute_process(
+ COMMAND "${RPMBUILD_EXECUTABLE}" -bb
+ --define "_topdir ${CPACK_RPM_DIRECTORY}"
+ --buildroot "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
+ "${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")
+ 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)
+ 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: *** ${RPMBUILDERR} ***")
+ message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
+ message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
+ endif()
+else()
+ if(ALIEN_EXECUTABLE)
+ message(FATAL_ERROR "RPM packaging through alien not done (yet)")
+ endif()
+endif()
diff --git a/Modules/CPackWIX.cmake b/Modules/CPackWIX.cmake
new file mode 100644
index 0000000000..0a47e196f8
--- /dev/null
+++ b/Modules/CPackWIX.cmake
@@ -0,0 +1,264 @@
+#.rst:
+# CPackWIX
+# --------
+#
+# CPack WiX generator specific options
+#
+# Variables specific to CPack WiX generator
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# The following variables are specific to the installers built on
+# Windows using WiX.
+#
+# .. variable:: CPACK_WIX_UPGRADE_GUID
+#
+# Upgrade GUID (``Product/@UpgradeCode``)
+#
+# Will be automatically generated unless explicitly provided.
+#
+# It should be explicitly set to a constant generated gloabally unique
+# identifier (GUID) to allow your installers to replace existing
+# installations that use the same GUID.
+#
+# You may for example explicitly set this variable in your
+# CMakeLists.txt to the value that has been generated per default. You
+# should not use GUIDs that you did not generate yourself or which may
+# belong to other projects.
+#
+# A GUID shall have the following fixed length syntax::
+#
+# XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
+#
+# (each X represents an uppercase hexadecimal digit)
+#
+# .. variable:: CPACK_WIX_PRODUCT_GUID
+#
+# Product GUID (``Product/@Id``)
+#
+# Will be automatically generated unless explicitly provided.
+#
+# If explicitly provided this will set the Product Id of your installer.
+#
+# The installer will abort if it detects a pre-existing installation that
+# uses the same GUID.
+#
+# The GUID shall use the syntax described for CPACK_WIX_UPGRADE_GUID.
+#
+# .. variable:: CPACK_WIX_LICENSE_RTF
+#
+# RTF License File
+#
+# If CPACK_RESOURCE_FILE_LICENSE has an .rtf extension it is used as-is.
+#
+# If CPACK_RESOURCE_FILE_LICENSE has an .txt extension it is implicitly
+# converted to RTF by the WiX Generator.
+# The expected encoding of the .txt file is UTF-8.
+#
+# With CPACK_WIX_LICENSE_RTF you can override the license file used by the
+# WiX Generator in case CPACK_RESOURCE_FILE_LICENSE is in an unsupported
+# format or the .txt -> .rtf conversion does not work as expected.
+#
+# .. variable:: CPACK_WIX_PRODUCT_ICON
+#
+# The Icon shown next to the program name in Add/Remove programs.
+#
+# If set, this icon is used in place of the default icon.
+#
+# .. variable:: CPACK_WIX_UI_REF
+#
+# This variable allows you to override the Id of the ``<UIRef>`` element
+# in the WiX template.
+#
+# The default is ``WixUI_InstallDir`` in case no CPack components have
+# been defined and ``WixUI_FeatureTree`` otherwise.
+#
+# .. variable:: CPACK_WIX_UI_BANNER
+#
+# The bitmap will appear at the top of all installer pages other than the
+# welcome and completion dialogs.
+#
+# If set, this image will replace the default banner image.
+#
+# This image must be 493 by 58 pixels.
+#
+# .. variable:: CPACK_WIX_UI_DIALOG
+#
+# Background bitmap used on the welcome and completion dialogs.
+#
+# If this variable is set, the installer will replace the default dialog
+# image.
+#
+# This image must be 493 by 312 pixels.
+#
+# .. variable:: CPACK_WIX_PROGRAM_MENU_FOLDER
+#
+# Start menu folder name for launcher.
+#
+# If this variable is not set, it will be initialized with CPACK_PACKAGE_NAME
+#
+# .. variable:: CPACK_WIX_CULTURES
+#
+# Language(s) of the installer
+#
+# Languages are compiled into the WixUI extension library. To use them,
+# simply provide the name of the culture. If you specify more than one
+# culture identifier in a comma or semicolon delimited list, the first one
+# that is found will be used. You can find a list of supported languages at:
+# http://wix.sourceforge.net/manual-wix3/WixUI_localization.htm
+#
+# .. variable:: CPACK_WIX_TEMPLATE
+#
+# Template file for WiX generation
+#
+# If this variable is set, the specified template will be used to generate
+# the WiX wxs file. This should be used if further customization of the
+# output is required.
+#
+# If this variable is not set, the default MSI template included with CMake
+# will be used.
+#
+# .. variable:: CPACK_WIX_PATCH_FILE
+#
+# Optional XML file 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
+# source files.
+#
+# Patch files understood by the CPack WiX generator
+# roughly follow this RELAX NG compact schema:
+#
+# .. code-block:: none
+#
+# start = CPackWiXPatch
+#
+# CPackWiXPatch = element CPackWiXPatch { CPackWiXFragment* }
+#
+# CPackWiXFragment = element CPackWiXFragment
+# {
+# attribute Id { string },
+# fragmentContent*
+# }
+#
+# fragmentContent = element * - CPackWiXFragment
+# {
+# (attribute * { text } | text | fragmentContent)*
+# }
+#
+# Currently fragments can be injected into most
+# Component, File and Directory elements.
+#
+# The following example illustrates how this works.
+#
+# Given that the WiX generator creates the following XML element:
+#
+# .. code-block:: xml
+#
+# <Component Id="CM_CP_applications.bin.my_libapp.exe" Guid="*"/>
+#
+# The following XML patch file may be used to inject an Environment element
+# into it:
+#
+# .. code-block:: xml
+#
+# <CPackWiXPatch>
+# <CPackWiXFragment Id="CM_CP_applications.bin.my_libapp.exe">
+# <Environment Id="MyEnvironment" Action="set"
+# Name="MyVariableName" Value="MyVariableValue"/>
+# </CPackWiXFragment>
+# </CPackWiXPatch>
+#
+# .. variable:: CPACK_WIX_EXTRA_SOURCES
+#
+# Extra WiX source files
+#
+# This variable provides an optional list of extra WiX source files (.wxs)
+# that should be compiled and linked. The full path to source files is
+# required.
+#
+# .. variable:: CPACK_WIX_EXTRA_OBJECTS
+#
+# Extra WiX object files or libraries
+#
+# This variable provides an optional list of extra WiX object (.wixobj)
+# and/or WiX library (.wixlib) files. The full path to objects and libraries
+# is required.
+#
+# .. variable:: CPACK_WIX_EXTENSIONS
+#
+# This variable provides a list of additional extensions for the WiX
+# tools light and candle.
+#
+# .. variable:: CPACK_WIX_<TOOL>_EXTENSIONS
+#
+# This is the tool specific version of CPACK_WIX_EXTENSIONS.
+# ``<TOOL>`` can be either LIGHT or CANDLE.
+#
+# .. variable:: CPACK_WIX_<TOOL>_EXTRA_FLAGS
+#
+# This list variable allows you to pass additional
+# flags to the WiX tool ``<TOOL>``.
+#
+# Use it at your own risk.
+# Future versions of CPack may generate flags which may be in conflict
+# with your own flags.
+#
+# ``<TOOL>`` can be either LIGHT or CANDLE.
+#
+# .. variable:: CPACK_WIX_CMAKE_PACKAGE_REGISTRY
+#
+# If this variable is set the generated installer will create
+# an entry in the windows registry key
+# ``HKEY_LOCAL_MACHINE\Software\Kitware\CMake\Packages\<package>``
+# The value for ``<package>`` is provided by this variable.
+#
+# Assuming you also install a CMake configuration file this will
+# allow other CMake projects to find your package with
+# the :command:`find_package` command.
+#
+# .. variable:: CPACK_WIX_PROPERTY_<PROPERTY>
+#
+# This variable can be used to provide a value for
+# the Windows Installer property ``<PROPERTY>``
+#
+# The follwing list contains some example properties that can be used to
+# customize information under
+# "Programs and Features" (also known as "Add or Remove Programs")
+#
+# * ARPCOMMENTS - Comments
+# * ARPHELPLINK - Help and support information URL
+# * ARPURLINFOABOUT - General information URL
+# * URLUPDATEINFO - Update information URL
+# * ARPHELPTELEPHONE - Help and support telephone number
+# * ARPSIZE - Size (in kilobytes) of the application
+
+#=============================================================================
+# Copyright 2014 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.)
+
+if(NOT CPACK_WIX_ROOT)
+ file(TO_CMAKE_PATH "$ENV{WIX}" CPACK_WIX_ROOT)
+endif()
+
+find_program(CPACK_WIX_CANDLE_EXECUTABLE candle
+ PATHS "${CPACK_WIX_ROOT}/bin")
+
+if(NOT CPACK_WIX_CANDLE_EXECUTABLE)
+ message(FATAL_ERROR "Could not find the WiX candle executable.")
+endif()
+
+find_program(CPACK_WIX_LIGHT_EXECUTABLE light
+ PATHS "${CPACK_WIX_ROOT}/bin")
+
+if(NOT CPACK_WIX_LIGHT_EXECUTABLE)
+ message(FATAL_ERROR "Could not find the WiX light executable.")
+endif()
diff --git a/Modules/CPackZIP.cmake b/Modules/CPackZIP.cmake
new file mode 100644
index 0000000000..a36589bd63
--- /dev/null
+++ b/Modules/CPackZIP.cmake
@@ -0,0 +1,41 @@
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+if(CMAKE_BINARY_DIR)
+ message(FATAL_ERROR "CPackZIP.cmake may only be used by CPack internally.")
+endif()
+
+find_program(ZIP_EXECUTABLE wzzip PATHS "$ENV{ProgramFiles}/WinZip")
+if(ZIP_EXECUTABLE)
+ set(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" -P \"<ARCHIVE>\" @<FILELIST>")
+ set(CPACK_ZIP_NEED_QUOTES TRUE)
+endif()
+
+if(NOT ZIP_EXECUTABLE)
+ find_program(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip")
+ if(ZIP_EXECUTABLE)
+ set(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" a -tzip \"<ARCHIVE>\" @<FILELIST>")
+ set(CPACK_ZIP_NEED_QUOTES TRUE)
+ endif()
+endif()
+
+if(NOT ZIP_EXECUTABLE)
+ find_package(Cygwin)
+ find_program(ZIP_EXECUTABLE zip PATHS "${CYGWIN_INSTALL_PATH}/bin")
+ if(ZIP_EXECUTABLE)
+ set(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" -r \"<ARCHIVE>\" . -i@<FILELIST>")
+ set(CPACK_ZIP_NEED_QUOTES FALSE)
+ endif()
+endif()
+
diff --git a/Modules/CTest.cmake b/Modules/CTest.cmake
new file mode 100644
index 0000000000..7759ead6da
--- /dev/null
+++ b/Modules/CTest.cmake
@@ -0,0 +1,300 @@
+#.rst:
+# CTest
+# -----
+#
+# Configure a project for testing with CTest/CDash
+#
+# Include this module in the top CMakeLists.txt file of a project to
+# enable testing with CTest and dashboard submissions to CDash:
+#
+# ::
+#
+# project(MyProject)
+# ...
+# include(CTest)
+#
+# The module automatically creates a BUILD_TESTING option that selects
+# whether to enable testing support (ON by default). After including
+# the module, use code like
+#
+# ::
+#
+# if(BUILD_TESTING)
+# # ... CMake code to create tests ...
+# endif()
+#
+# to creating tests when testing is enabled.
+#
+# To enable submissions to a CDash server, create a CTestConfig.cmake
+# file at the top of the project with content such as
+#
+# ::
+#
+# set(CTEST_PROJECT_NAME "MyProject")
+# set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
+# set(CTEST_DROP_METHOD "http")
+# set(CTEST_DROP_SITE "my.cdash.org")
+# set(CTEST_DROP_LOCATION "/submit.php?project=MyProject")
+# set(CTEST_DROP_SITE_CDASH TRUE)
+#
+# (the CDash server can provide the file to a project administrator who
+# configures 'MyProject'). Settings in the config file are shared by
+# both this CTest module and the CTest command-line tool's dashboard
+# script mode (ctest -S).
+#
+# While building a project for submission to CDash, CTest scans the
+# build output for errors and warnings and reports them with surrounding
+# context from the build log. This generic approach works for all build
+# tools, but does not give details about the command invocation that
+# produced a given problem. One may get more detailed reports by adding
+#
+# ::
+#
+# set(CTEST_USE_LAUNCHERS 1)
+#
+# to the CTestConfig.cmake file. When this option is enabled, the CTest
+# module tells CMake's Makefile generators to invoke every command in
+# the generated build system through a CTest launcher program.
+# (Currently the CTEST_USE_LAUNCHERS option is ignored on non-Makefile
+# generators.) During a manual build each launcher transparently runs
+# the command it wraps. During a CTest-driven build for submission to
+# CDash each launcher reports detailed information when its command
+# fails or warns. (Setting CTEST_USE_LAUNCHERS in CTestConfig.cmake is
+# convenient, but also adds the launcher overhead even for manual
+# builds. One may instead set it in a CTest dashboard script and add it
+# to the CMake cache for the build tree.)
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+option(BUILD_TESTING "Build the testing tree." ON)
+
+# function to turn generator name into a version string
+# like vs7 vs71 vs8 vs9
+function(GET_VS_VERSION_STRING generator var)
+ string(REGEX REPLACE "Visual Studio ([0-9][0-9]?)($|.*)" "\\1"
+ NUMBER "${generator}")
+ if("${generator}" MATCHES "Visual Studio 7 .NET 2003")
+ set(ver_string "vs71")
+ else()
+ set(ver_string "vs${NUMBER}")
+ endif()
+ set(${var} ${ver_string} PARENT_SCOPE)
+endfunction()
+
+include(CTestUseLaunchers)
+
+if(BUILD_TESTING)
+ # Setup some auxilary macros
+ macro(SET_IF_NOT_SET var val)
+ if(NOT DEFINED "${var}")
+ set("${var}" "${val}")
+ endif()
+ endmacro()
+
+ macro(SET_IF_SET var val)
+ if(NOT "${val}" STREQUAL "")
+ set("${var}" "${val}")
+ endif()
+ endmacro()
+
+ macro(SET_IF_SET_AND_NOT_SET var val)
+ if(NOT "${val}" STREQUAL "")
+ SET_IF_NOT_SET("${var}" "${val}")
+ endif()
+ endmacro()
+
+ # Make sure testing is enabled
+ enable_testing()
+
+ if(EXISTS "${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
+ include("${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
+ SET_IF_SET_AND_NOT_SET(NIGHTLY_START_TIME "${CTEST_NIGHTLY_START_TIME}")
+ SET_IF_SET_AND_NOT_SET(DROP_METHOD "${CTEST_DROP_METHOD}")
+ SET_IF_SET_AND_NOT_SET(DROP_SITE "${CTEST_DROP_SITE}")
+ SET_IF_SET_AND_NOT_SET(DROP_SITE_USER "${CTEST_DROP_SITE_USER}")
+ SET_IF_SET_AND_NOT_SET(DROP_SITE_PASSWORD "${CTEST_DROP_SITE_PASWORD}")
+ SET_IF_SET_AND_NOT_SET(DROP_SITE_MODE "${CTEST_DROP_SITE_MODE}")
+ SET_IF_SET_AND_NOT_SET(DROP_LOCATION "${CTEST_DROP_LOCATION}")
+ SET_IF_SET_AND_NOT_SET(TRIGGER_SITE "${CTEST_TRIGGER_SITE}")
+ SET_IF_SET_AND_NOT_SET(UPDATE_TYPE "${CTEST_UPDATE_TYPE}")
+ endif()
+
+ # the project can have a DartConfig.cmake file
+ if(EXISTS "${PROJECT_SOURCE_DIR}/DartConfig.cmake")
+ include("${PROJECT_SOURCE_DIR}/DartConfig.cmake")
+ else()
+ # Dashboard is opened for submissions for a 24 hour period starting at
+ # the specified NIGHTLY_START_TIME. Time is specified in 24 hour format.
+ SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
+ SET_IF_NOT_SET(DROP_METHOD "http")
+ SET_IF_NOT_SET (COMPRESS_SUBMISSION ON)
+ endif()
+ SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
+
+ find_program(CVSCOMMAND cvs )
+ set(CVS_UPDATE_OPTIONS "-d -A -P" CACHE STRING
+ "Options passed to the cvs update command.")
+ find_program(SVNCOMMAND svn)
+ find_program(BZRCOMMAND bzr)
+ find_program(HGCOMMAND hg)
+ find_program(GITCOMMAND git)
+ find_program(P4COMMAND p4)
+
+ if(NOT UPDATE_TYPE)
+ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CVS")
+ set(UPDATE_TYPE cvs)
+ elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn")
+ set(UPDATE_TYPE svn)
+ elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.bzr")
+ set(UPDATE_TYPE bzr)
+ elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.hg")
+ set(UPDATE_TYPE hg)
+ elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
+ set(UPDATE_TYPE git)
+ endif()
+ endif()
+
+ string(TOLOWER "${UPDATE_TYPE}" _update_type)
+ if("${_update_type}" STREQUAL "cvs")
+ set(UPDATE_COMMAND "${CVSCOMMAND}")
+ set(UPDATE_OPTIONS "${CVS_UPDATE_OPTIONS}")
+ elseif("${_update_type}" STREQUAL "svn")
+ set(UPDATE_COMMAND "${SVNCOMMAND}")
+ set(UPDATE_OPTIONS "${SVN_UPDATE_OPTIONS}")
+ elseif("${_update_type}" STREQUAL "bzr")
+ set(UPDATE_COMMAND "${BZRCOMMAND}")
+ set(UPDATE_OPTIONS "${BZR_UPDATE_OPTIONS}")
+ elseif("${_update_type}" STREQUAL "hg")
+ set(UPDATE_COMMAND "${HGCOMMAND}")
+ set(UPDATE_OPTIONS "${HG_UPDATE_OPTIONS}")
+ elseif("${_update_type}" STREQUAL "git")
+ set(UPDATE_COMMAND "${GITCOMMAND}")
+ set(UPDATE_OPTIONS "${GIT_UPDATE_OPTIONS}")
+ elseif("${_update_type}" STREQUAL "p4")
+ set(UPDATE_COMMAND "${P4COMMAND}")
+ set(UPDATE_OPTIONS "${P4_UPDATE_OPTIONS}")
+ endif()
+
+ set(DART_TESTING_TIMEOUT 1500 CACHE STRING
+ "Maximum time allowed before CTest will kill the test.")
+
+ set(CTEST_SUBMIT_RETRY_DELAY 5 CACHE STRING
+ "How long to wait between timed-out CTest submissions.")
+ set(CTEST_SUBMIT_RETRY_COUNT 3 CACHE STRING
+ "How many times to retry timed-out CTest submissions.")
+
+ find_program(MEMORYCHECK_COMMAND
+ NAMES purify valgrind boundscheck
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder]"
+ DOC "Path to the memory checking command, used for memory error detection."
+ )
+ find_program(SLURM_SBATCH_COMMAND sbatch DOC
+ "Path to the SLURM sbatch executable"
+ )
+ find_program(SLURM_SRUN_COMMAND srun DOC
+ "Path to the SLURM srun executable"
+ )
+ set(MEMORYCHECK_SUPPRESSIONS_FILE "" CACHE FILEPATH
+ "File that contains suppressions for the memory checker")
+ find_program(SCPCOMMAND scp DOC
+ "Path to scp command, used by CTest for submitting results to a Dart server"
+ )
+ find_program(COVERAGE_COMMAND gcov DOC
+ "Path to the coverage program that CTest uses for performing coverage inspection"
+ )
+ set(COVERAGE_EXTRA_FLAGS "-l" CACHE STRING
+ "Extra command line flags to pass to the coverage tool")
+
+ # set the site name
+ site_name(SITE)
+ # set the build name
+ if(NOT BUILDNAME)
+ set(DART_COMPILER "${CMAKE_CXX_COMPILER}")
+ if(NOT DART_COMPILER)
+ set(DART_COMPILER "${CMAKE_C_COMPILER}")
+ endif()
+ if(NOT DART_COMPILER)
+ set(DART_COMPILER "unknown")
+ endif()
+ if(WIN32)
+ set(DART_NAME_COMPONENT "NAME_WE")
+ else()
+ set(DART_NAME_COMPONENT "NAME")
+ endif()
+ if(NOT BUILD_NAME_SYSTEM_NAME)
+ set(BUILD_NAME_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
+ endif()
+ if(WIN32)
+ set(BUILD_NAME_SYSTEM_NAME "Win32")
+ endif()
+ if(UNIX OR BORLAND)
+ get_filename_component(DART_CXX_NAME
+ "${CMAKE_CXX_COMPILER}" ${DART_NAME_COMPONENT})
+ else()
+ get_filename_component(DART_CXX_NAME
+ "${CMAKE_MAKE_PROGRAM}" ${DART_NAME_COMPONENT})
+ endif()
+ if(DART_CXX_NAME MATCHES "msdev")
+ set(DART_CXX_NAME "vs60")
+ endif()
+ if(DART_CXX_NAME MATCHES "devenv")
+ GET_VS_VERSION_STRING("${CMAKE_GENERATOR}" DART_CXX_NAME)
+ endif()
+ set(BUILDNAME "${BUILD_NAME_SYSTEM_NAME}-${DART_CXX_NAME}")
+ endif()
+
+ # the build command
+ build_command(MAKECOMMAND_DEFAULT_VALUE
+ CONFIGURATION "\${CTEST_CONFIGURATION_TYPE}")
+ set(MAKECOMMAND ${MAKECOMMAND_DEFAULT_VALUE}
+ CACHE STRING "Command to build the project")
+
+ # the default build configuration the ctest build handler will use
+ # if there is no -C arg given to ctest:
+ set(DEFAULT_CTEST_CONFIGURATION_TYPE "$ENV{CMAKE_CONFIG_TYPE}")
+ if(DEFAULT_CTEST_CONFIGURATION_TYPE STREQUAL "")
+ set(DEFAULT_CTEST_CONFIGURATION_TYPE "Release")
+ endif()
+
+ mark_as_advanced(
+ BZRCOMMAND
+ BZR_UPDATE_OPTIONS
+ COVERAGE_COMMAND
+ COVERAGE_EXTRA_FLAGS
+ CTEST_SUBMIT_RETRY_DELAY
+ CTEST_SUBMIT_RETRY_COUNT
+ CVSCOMMAND
+ CVS_UPDATE_OPTIONS
+ DART_TESTING_TIMEOUT
+ GITCOMMAND
+ P4COMMAND
+ HGCOMMAND
+ MAKECOMMAND
+ MEMORYCHECK_COMMAND
+ MEMORYCHECK_SUPPRESSIONS_FILE
+ PURIFYCOMMAND
+ SCPCOMMAND
+ SLURM_SBATCH_COMMAND
+ SLURM_SRUN_COMMAND
+ SITE
+ SVNCOMMAND
+ SVN_UPDATE_OPTIONS
+ )
+ if(NOT RUN_FROM_DART)
+ set(RUN_FROM_CTEST_OR_DART 1)
+ include(CTestTargets)
+ set(RUN_FROM_CTEST_OR_DART)
+ endif()
+endif()
diff --git a/Modules/CTestScriptMode.cmake b/Modules/CTestScriptMode.cmake
new file mode 100644
index 0000000000..b4347242df
--- /dev/null
+++ b/Modules/CTestScriptMode.cmake
@@ -0,0 +1,30 @@
+#.rst:
+# CTestScriptMode
+# ---------------
+#
+#
+#
+# This file is read by ctest in script mode (-S)
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2009 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# Determine the current system, so this information can be used
+# in ctest scripts
+include(CMakeDetermineSystem)
+
+# Also load the system specific file, which sets up e.g. the search paths.
+# This makes the FIND_XXX() calls work much better
+include(CMakeSystemSpecificInformation)
+
diff --git a/Modules/CTestTargets.cmake b/Modules/CTestTargets.cmake
new file mode 100644
index 0000000000..5b6e062d0b
--- /dev/null
+++ b/Modules/CTestTargets.cmake
@@ -0,0 +1,99 @@
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+if(NOT RUN_FROM_CTEST_OR_DART)
+ message(FATAL_ERROR "Do not incldue CTestTargets.cmake directly")
+endif()
+
+if(NOT PROJECT_BINARY_DIR)
+ message(FATAL_ERROR "Do not include(CTest) before calling project().")
+endif()
+
+# make directories in the binary tree
+file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Testing/Temporary)
+get_filename_component(CMAKE_HOST_PATH ${CMAKE_COMMAND} PATH)
+set(CMAKE_TARGET_PATH ${EXECUTABLE_OUTPUT_PATH})
+find_program(CMAKE_CTEST_COMMAND ctest ${CMAKE_HOST_PATH} ${CMAKE_TARGET_PATH})
+mark_as_advanced(CMAKE_CTEST_COMMAND)
+
+# Use CTest
+# configure files
+
+if(CTEST_NEW_FORMAT)
+ configure_file(
+ ${CMAKE_ROOT}/Modules/DartConfiguration.tcl.in
+ ${PROJECT_BINARY_DIR}/CTestConfiguration.ini )
+else()
+ configure_file(
+ ${CMAKE_ROOT}/Modules/DartConfiguration.tcl.in
+ ${PROJECT_BINARY_DIR}/DartConfiguration.tcl )
+endif()
+
+#
+# Section 3:
+#
+# Custom targets to perform dashboard builds and submissions.
+# These should NOT need to be modified from project to project.
+#
+
+set(__conf_types "")
+if(CMAKE_CONFIGURATION_TYPES)
+ # We need to pass the configuration type on the test command line.
+ set(__conf_types -C "${CMAKE_CFG_INTDIR}")
+endif()
+
+# Add convenience targets. Do this at most once in case of nested
+# projects.
+define_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED
+ BRIEF_DOCS "Internal property used by CTestTargets module."
+ FULL_DOCS "Set by the CTestTargets module to track addition of testing targets."
+ )
+get_property(_CTEST_TARGETS_ADDED GLOBAL PROPERTY CTEST_TARGETS_ADDED)
+if(NOT _CTEST_TARGETS_ADDED)
+ set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
+
+ # For all generators add basic testing targets.
+ foreach(mode Experimental Nightly Continuous NightlyMemoryCheck)
+ add_custom_target(${mode}
+ ${CMAKE_CTEST_COMMAND} ${__conf_types} -D ${mode}
+ )
+ set_property(TARGET ${mode} PROPERTY RULE_LAUNCH_CUSTOM "")
+ set_property(TARGET ${mode} PROPERTY FOLDER "CTestDashboardTargets")
+ endforeach()
+
+ # For Makefile generators add more granular targets.
+ if("${CMAKE_GENERATOR}" MATCHES "(Ninja|Make)")
+ # Make targets for Experimental builds
+ foreach(mode Nightly Experimental Continuous)
+ foreach(testtype
+ Start Update Configure Build Test Coverage MemCheck Submit
+ # missing purify
+ )
+ add_custom_target(${mode}${testtype}
+ ${CMAKE_CTEST_COMMAND} ${__conf_types} -D ${mode}${testtype}
+ )
+ set_property(TARGET ${mode}${testtype} PROPERTY RULE_LAUNCH_CUSTOM "")
+ set_property(TARGET ${mode}${testtype} PROPERTY FOLDER "CTestDashboardTargets")
+ endforeach()
+ endforeach()
+ endif()
+
+ # If requested, add an alias that is the equivalent of the built-in "test"
+ # or "RUN_TESTS" target:
+ if(CTEST_TEST_TARGET_ALIAS)
+ add_custom_target(${CTEST_TEST_TARGET_ALIAS}
+ ${CMAKE_CTEST_COMMAND} ${__conf_types}
+ )
+ endif()
+endif()
diff --git a/Modules/CTestUseLaunchers.cmake b/Modules/CTestUseLaunchers.cmake
new file mode 100644
index 0000000000..c79119f954
--- /dev/null
+++ b/Modules/CTestUseLaunchers.cmake
@@ -0,0 +1,77 @@
+#.rst:
+# CTestUseLaunchers
+# -----------------
+#
+# Set the RULE_LAUNCH_* global properties when CTEST_USE_LAUNCHERS is on.
+#
+# CTestUseLaunchers is automatically included when you include(CTest).
+# However, it is split out into its own module file so projects can use
+# the CTEST_USE_LAUNCHERS functionality independently.
+#
+# To use launchers, set CTEST_USE_LAUNCHERS to ON in a ctest -S
+# dashboard script, and then also set it in the cache of the configured
+# project. Both cmake and ctest need to know the value of it for the
+# launchers to work properly. CMake needs to know in order to generate
+# proper build rules, and ctest, in order to produce the proper error
+# and warning analysis.
+#
+# For convenience, you may set the ENV variable
+# CTEST_USE_LAUNCHERS_DEFAULT in your ctest -S script, too. Then, as
+# long as your CMakeLists uses include(CTest) or
+# include(CTestUseLaunchers), it will use the value of the ENV variable
+# to initialize a CTEST_USE_LAUNCHERS cache variable. This cache
+# variable initialization only occurs if CTEST_USE_LAUNCHERS is not
+# already defined.
+
+#=============================================================================
+# Copyright 2008-2012 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.)
+
+if(NOT DEFINED CTEST_USE_LAUNCHERS AND DEFINED ENV{CTEST_USE_LAUNCHERS_DEFAULT})
+ set(CTEST_USE_LAUNCHERS "$ENV{CTEST_USE_LAUNCHERS_DEFAULT}"
+ CACHE INTERNAL "CTEST_USE_LAUNCHERS initial value from ENV")
+endif()
+
+if(NOT "${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
+ set(CTEST_USE_LAUNCHERS 0)
+endif()
+
+if(CTEST_USE_LAUNCHERS)
+ set(__launch_common_options
+ "--target-name <TARGET_NAME> --build-dir <CMAKE_CURRENT_BINARY_DIR>")
+
+ set(__launch_compile_options
+ "${__launch_common_options} --output <OBJECT> --source <SOURCE> --language <LANGUAGE>")
+
+ set(__launch_link_options
+ "${__launch_common_options} --output <TARGET> --target-type <TARGET_TYPE> --language <LANGUAGE>")
+
+ set(__launch_custom_options
+ "${__launch_common_options} --output <OUTPUT>")
+
+ if("${CMAKE_GENERATOR}" MATCHES "Ninja")
+ set(__launch_compile_options "${__launch_compile_options} --filter-prefix <CMAKE_CL_SHOWINCLUDES_PREFIX>")
+ endif()
+
+ set(CTEST_LAUNCH_COMPILE
+ "\"${CMAKE_CTEST_COMMAND}\" --launch ${__launch_compile_options} --")
+
+ set(CTEST_LAUNCH_LINK
+ "\"${CMAKE_CTEST_COMMAND}\" --launch ${__launch_link_options} --")
+
+ set(CTEST_LAUNCH_CUSTOM
+ "\"${CMAKE_CTEST_COMMAND}\" --launch ${__launch_custom_options} --")
+
+ set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CTEST_LAUNCH_COMPILE}")
+ set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CTEST_LAUNCH_LINK}")
+ set_property(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "${CTEST_LAUNCH_CUSTOM}")
+endif()
diff --git a/Modules/CheckCCompilerFlag.cmake b/Modules/CheckCCompilerFlag.cmake
new file mode 100644
index 0000000000..53f3454734
--- /dev/null
+++ b/Modules/CheckCCompilerFlag.cmake
@@ -0,0 +1,64 @@
+#.rst:
+# CheckCCompilerFlag
+# ------------------
+#
+# Check whether the C compiler supports a given flag.
+#
+# CHECK_C_COMPILER_FLAG(<flag> <var>)
+#
+# ::
+#
+# <flag> - the compiler flag
+# <var> - variable to store the result
+# Will be created as an internal cache variable.
+#
+# This internally calls the check_c_source_compiles macro and sets
+# CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for
+# CheckCSourceCompiles for a listing of variables that can otherwise
+# modify the build. The result only tells that the compiler does not
+# give an error message when it encounters the flag. If the flag has
+# any effect or even a specific one is beyond the scope of this module.
+
+#=============================================================================
+# Copyright 2006-2011 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
+# Copyright 2011 Matthias Kretz <kretz@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+include(CheckCSourceCompiles)
+include(CMakeCheckCompilerFlagCommonPatterns)
+
+macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
+ set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
+ set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
+
+ # Normalize locale during test compilation.
+ set(_CheckCCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG)
+ foreach(v ${_CheckCCompilerFlag_LOCALE_VARS})
+ set(_CheckCCompilerFlag_SAVED_${v} "$ENV{${v}}")
+ set(ENV{${v}} C)
+ endforeach()
+ CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckCCompilerFlag_COMMON_PATTERNS)
+ CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${_RESULT}
+ # Some compilers do not fail with a bad flag
+ FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU
+ ${_CheckCCompilerFlag_COMMON_PATTERNS}
+ )
+ foreach(v ${_CheckCCompilerFlag_LOCALE_VARS})
+ set(ENV{${v}} ${_CheckCCompilerFlag_SAVED_${v}})
+ unset(_CheckCCompilerFlag_SAVED_${v})
+ endforeach()
+ unset(_CheckCCompilerFlag_LOCALE_VARS)
+ unset(_CheckCCompilerFlag_COMMON_PATTERNS)
+
+ set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
+endmacro ()
diff --git a/Modules/CheckCSourceCompiles.cmake b/Modules/CheckCSourceCompiles.cmake
new file mode 100644
index 0000000000..6e80fb535c
--- /dev/null
+++ b/Modules/CheckCSourceCompiles.cmake
@@ -0,0 +1,111 @@
+#.rst:
+# CheckCSourceCompiles
+# --------------------
+#
+# Check if given C source compiles and links into an executable
+#
+# CHECK_C_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>])
+#
+# ::
+#
+# <code> - source code to try to compile, must define 'main'
+# <var> - variable to store whether the source code compiled
+# Will be created as an internal cache variable.
+# <fail-regex> - fail if test output matches this regex
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+
+
+macro(CHECK_C_SOURCE_COMPILES SOURCE VAR)
+ if(NOT DEFINED "${VAR}")
+ set(_FAIL_REGEX)
+ set(_key)
+ foreach(arg ${ARGN})
+ if("${arg}" MATCHES "^(FAIL_REGEX)$")
+ set(_key "${arg}")
+ elseif(_key)
+ list(APPEND _${_key} "${arg}")
+ else()
+ message(FATAL_ERROR "Unknown argument:\n ${arg}\n")
+ endif()
+ endforeach()
+ set(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES)
+ endif()
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES)
+ endif()
+ file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c"
+ "${SOURCE}\n")
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR}")
+ endif()
+ try_compile(${VAR}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ foreach(_regex ${_FAIL_REGEX})
+ if("${OUTPUT}" MATCHES "${_regex}")
+ set(${VAR} 0)
+ endif()
+ endforeach()
+
+ if(${VAR})
+ set(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ 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"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ else()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR} - Failed")
+ endif()
+ set(${VAR} "" CACHE INTERNAL "Test ${VAR}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Performing C SOURCE FILE Test ${VAR} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ endif()
+ endif()
+endmacro()
+
diff --git a/Modules/CheckCSourceRuns.cmake b/Modules/CheckCSourceRuns.cmake
new file mode 100644
index 0000000000..0ce423c1f6
--- /dev/null
+++ b/Modules/CheckCSourceRuns.cmake
@@ -0,0 +1,107 @@
+#.rst:
+# CheckCSourceRuns
+# ----------------
+#
+# Check if the given C source code compiles and runs.
+#
+# CHECK_C_SOURCE_RUNS(<code> <var>)
+#
+# ::
+#
+# <code> - source code to try to compile
+# <var> - variable to store the result
+# (1 for success, empty for failure)
+# Will be created as an internal cache variable.
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+
+
+macro(CHECK_C_SOURCE_RUNS SOURCE VAR)
+ if(NOT DEFINED "${VAR}")
+ set(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES)
+ endif()
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES)
+ endif()
+ file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c"
+ "${SOURCE}\n")
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR}")
+ endif()
+ try_run(${VAR}_EXITCODE ${VAR}_COMPILED
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH}
+ "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}"
+ COMPILE_OUTPUT_VARIABLE OUTPUT)
+ # if it did not compile make the return value fail code of 1
+ if(NOT ${VAR}_COMPILED)
+ set(${VAR}_EXITCODE 1)
+ endif()
+ # if the return value was 0 then it worked
+ if("${${VAR}_EXITCODE}" EQUAL 0)
+ set(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ 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"
+ "${OUTPUT}\n"
+ "Return value: ${${VAR}}\n"
+ "Source file was:\n${SOURCE}\n")
+ else()
+ if(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN")
+ set(${VAR} "${${VAR}_EXITCODE}")
+ else()
+ set(${VAR} "" CACHE INTERNAL "Test ${VAR}")
+ endif()
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR} - Failed")
+ endif()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Performing C SOURCE FILE Test ${VAR} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Return value: ${${VAR}_EXITCODE}\n"
+ "Source file was:\n${SOURCE}\n")
+
+ endif()
+ endif()
+endmacro()
+
diff --git a/Modules/CheckCXXCompilerFlag.cmake b/Modules/CheckCXXCompilerFlag.cmake
new file mode 100644
index 0000000000..fab3a053d0
--- /dev/null
+++ b/Modules/CheckCXXCompilerFlag.cmake
@@ -0,0 +1,64 @@
+#.rst:
+# CheckCXXCompilerFlag
+# --------------------
+#
+# Check whether the CXX compiler supports a given flag.
+#
+# CHECK_CXX_COMPILER_FLAG(<flag> <var>)
+#
+# ::
+#
+# <flag> - the compiler flag
+# <var> - variable to store the result
+#
+# This internally calls the check_cxx_source_compiles macro and sets
+# CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for
+# CheckCXXSourceCompiles for a listing of variables that can otherwise
+# modify the build. The result only tells that the compiler does not
+# give an error message when it encounters the flag. If the flag has
+# any effect or even a specific one is beyond the scope of this module.
+
+#=============================================================================
+# Copyright 2006-2010 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
+# Copyright 2011 Matthias Kretz <kretz@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+include(CheckCXXSourceCompiles)
+include(CMakeCheckCompilerFlagCommonPatterns)
+
+macro (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
+ set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
+ set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
+
+ # Normalize locale during test compilation.
+ set(_CheckCXXCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG)
+ foreach(v ${_CheckCXXCompilerFlag_LOCALE_VARS})
+ set(_CheckCXXCompilerFlag_SAVED_${v} "$ENV{${v}}")
+ set(ENV{${v}} C)
+ endforeach()
+ CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckCXXCompilerFlag_COMMON_PATTERNS)
+ CHECK_CXX_SOURCE_COMPILES("int main() { return 0; }" ${_RESULT}
+ # Some compilers do not fail with a bad flag
+ FAIL_REGEX "command line option .* is valid for .* but not for C\\\\+\\\\+" # GNU
+ ${_CheckCXXCompilerFlag_COMMON_PATTERNS}
+ )
+ foreach(v ${_CheckCXXCompilerFlag_LOCALE_VARS})
+ set(ENV{${v}} ${_CheckCXXCompilerFlag_SAVED_${v}})
+ unset(_CheckCXXCompilerFlag_SAVED_${v})
+ endforeach()
+ unset(_CheckCXXCompilerFlag_LOCALE_VARS)
+ unset(_CheckCXXCompilerFlag_COMMON_PATTERNS)
+
+ set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
+endmacro ()
+
diff --git a/Modules/CheckCXXSourceCompiles.cmake b/Modules/CheckCXXSourceCompiles.cmake
new file mode 100644
index 0000000000..6d52ec6b8d
--- /dev/null
+++ b/Modules/CheckCXXSourceCompiles.cmake
@@ -0,0 +1,112 @@
+#.rst:
+# CheckCXXSourceCompiles
+# ----------------------
+#
+# Check if given C++ source compiles and links into an executable
+#
+# CHECK_CXX_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>])
+#
+# ::
+#
+# <code> - source code to try to compile, must define 'main'
+# <var> - variable to store whether the source code compiled
+# Will be created as an internal cache variable.
+# <fail-regex> - fail if test output matches this regex
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+
+
+macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
+ if(NOT DEFINED "${VAR}")
+ set(_FAIL_REGEX)
+ set(_key)
+ foreach(arg ${ARGN})
+ if("${arg}" MATCHES "^(FAIL_REGEX)$")
+ set(_key "${arg}")
+ elseif(_key)
+ list(APPEND _${_key} "${arg}")
+ else()
+ message(FATAL_ERROR "Unknown argument:\n ${arg}\n")
+ endif()
+ endforeach()
+
+ set(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES)
+ endif()
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES)
+ endif()
+ file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx"
+ "${SOURCE}\n")
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR}")
+ endif()
+ try_compile(${VAR}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ "${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ foreach(_regex ${_FAIL_REGEX})
+ if("${OUTPUT}" MATCHES "${_regex}")
+ set(${VAR} 0)
+ endif()
+ endforeach()
+
+ if(${VAR})
+ set(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ 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"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ else()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR} - Failed")
+ endif()
+ set(${VAR} "" CACHE INTERNAL "Test ${VAR}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Performing C++ SOURCE FILE Test ${VAR} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ endif()
+ endif()
+endmacro()
+
diff --git a/Modules/CheckCXXSourceRuns.cmake b/Modules/CheckCXXSourceRuns.cmake
new file mode 100644
index 0000000000..3c06d75403
--- /dev/null
+++ b/Modules/CheckCXXSourceRuns.cmake
@@ -0,0 +1,107 @@
+#.rst:
+# CheckCXXSourceRuns
+# ------------------
+#
+# Check if the given C++ source code compiles and runs.
+#
+# CHECK_CXX_SOURCE_RUNS(<code> <var>)
+#
+# ::
+#
+# <code> - source code to try to compile
+# <var> - variable to store the result
+# (1 for success, empty for failure)
+# Will be created as an internal cache variable.
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+
+
+macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR)
+ if(NOT DEFINED "${VAR}")
+ set(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES)
+ endif()
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES)
+ endif()
+ file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx"
+ "${SOURCE}\n")
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR}")
+ endif()
+ try_run(${VAR}_EXITCODE ${VAR}_COMPILED
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH}
+ "${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}"
+ COMPILE_OUTPUT_VARIABLE OUTPUT)
+
+ # if it did not compile make the return value fail code of 1
+ if(NOT ${VAR}_COMPILED)
+ set(${VAR}_EXITCODE 1)
+ endif()
+ # if the return value was 0 then it worked
+ if("${${VAR}_EXITCODE}" EQUAL 0)
+ set(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ 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"
+ "${OUTPUT}\n"
+ "Return value: ${${VAR}}\n"
+ "Source file was:\n${SOURCE}\n")
+ else()
+ if(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN")
+ set(${VAR} "${${VAR}_EXITCODE}")
+ else()
+ set(${VAR} "" CACHE INTERNAL "Test ${VAR}")
+ endif()
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR} - Failed")
+ endif()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Performing C++ SOURCE FILE Test ${VAR} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Return value: ${${VAR}_EXITCODE}\n"
+ "Source file was:\n${SOURCE}\n")
+ endif()
+ endif()
+endmacro()
+
diff --git a/Modules/CheckCXXSymbolExists.cmake b/Modules/CheckCXXSymbolExists.cmake
new file mode 100644
index 0000000000..084fbb422f
--- /dev/null
+++ b/Modules/CheckCXXSymbolExists.cmake
@@ -0,0 +1,49 @@
+#.rst:
+# CheckCXXSymbolExists
+# --------------------
+#
+# Check if a symbol exists as a function, variable, or macro in C++
+#
+# CHECK_CXX_SYMBOL_EXISTS(<symbol> <files> <variable>)
+#
+# Check that the <symbol> is available after including given header
+# <files> and store the result in a <variable>. Specify the list of
+# files in one argument as a semicolon-separated list.
+# CHECK_CXX_SYMBOL_EXISTS() can be used to check in C++ files, as
+# opposed to CHECK_SYMBOL_EXISTS(), which works only for C.
+#
+# If the header files define the symbol as a macro it is considered
+# available and assumed to work. If the header files declare the symbol
+# as a function or variable then the symbol must also be available for
+# linking. If the symbol is a type or enum value it will not be
+# recognized (consider using CheckTypeSize or CheckCSourceCompiles).
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2003-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+include(CheckSymbolExists)
+
+macro(CHECK_CXX_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
+ _CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
+endmacro()
diff --git a/Modules/CheckForPthreads.c b/Modules/CheckForPthreads.c
new file mode 100644
index 0000000000..7250fbff63
--- /dev/null
+++ b/Modules/CheckForPthreads.c
@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
+
+void* runner(void*);
+
+int res = 0;
+#ifdef __CLASSIC_C__
+int main(){
+ int ac;
+ char*av[];
+#else
+int main(int ac, char*av[]){
+#endif
+ pthread_t tid[2];
+ 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
+#endif
+
+ pthread_join(tid[0], 0);
+ pthread_join(tid[1], 0);
+ if(ac > 1000){return *av[0];}
+ return res;
+}
+
+void* runner(void* args)
+{
+ int cc;
+ for ( cc = 0; cc < 10; cc ++ )
+ {
+ printf("%d CC: %d\n", (int)args, cc);
+ }
+ res ++;
+ return 0;
+}
diff --git a/Modules/CheckFortranFunctionExists.cmake b/Modules/CheckFortranFunctionExists.cmake
new file mode 100644
index 0000000000..bd52f61b65
--- /dev/null
+++ b/Modules/CheckFortranFunctionExists.cmake
@@ -0,0 +1,78 @@
+#.rst:
+# CheckFortranFunctionExists
+# --------------------------
+#
+# macro which checks if the Fortran function exists
+#
+# CHECK_FORTRAN_FUNCTION_EXISTS(FUNCTION VARIABLE)
+#
+# ::
+#
+# FUNCTION - the name of the Fortran function
+# VARIABLE - variable to store the result
+# Will be created as an internal cache variable.
+#
+#
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+
+
+macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE)
+ if(NOT DEFINED ${VARIABLE})
+ message(STATUS "Looking for Fortran ${FUNCTION}")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
+ endif()
+ file(WRITE
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
+ "
+ program TESTFortran
+ external ${FUNCTION}
+ call ${FUNCTION}()
+ end program TESTFortran
+ "
+ )
+ try_compile(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
+ ${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}
+ OUTPUT_VARIABLE OUTPUT
+ )
+# message(STATUS "${OUTPUT}")
+ if(${VARIABLE})
+ set(${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}")
+ message(STATUS "Looking for Fortran ${FUNCTION} - found")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the Fortran ${FUNCTION} exists passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else()
+ message(STATUS "Looking for Fortran ${FUNCTION} - not found")
+ set(${VARIABLE} "" CACHE INTERNAL "Have Fortran function ${FUNCTION}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the Fortran ${FUNCTION} exists failed with the following output:\n"
+ "${OUTPUT}\n\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/CheckFortranSourceCompiles.cmake b/Modules/CheckFortranSourceCompiles.cmake
new file mode 100644
index 0000000000..f90d05bd6f
--- /dev/null
+++ b/Modules/CheckFortranSourceCompiles.cmake
@@ -0,0 +1,111 @@
+#.rst:
+# CheckFortranSourceCompiles
+# --------------------------
+#
+# Check if given Fortran source compiles and links into an executable::
+#
+# CHECK_Fortran_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>])
+#
+# The arguments are:
+#
+# ``<code>``
+# Source code to try to compile. It must define a PROGRAM entry point.
+# ``<var>``
+# Variable to store whether the source code compiled.
+# Will be created as an internal cache variable.
+# ``<fail-regex>``
+# Fail if test output matches this regex.
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+
+
+macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
+ if(NOT DEFINED "${VAR}")
+ set(_FAIL_REGEX)
+ set(_key)
+ foreach(arg ${ARGN})
+ if("${arg}" MATCHES "^(FAIL_REGEX)$")
+ set(_key "${arg}")
+ elseif(_key)
+ list(APPEND _${_key} "${arg}")
+ else()
+ message(FATAL_ERROR "Unknown argument:\n ${arg}\n")
+ endif()
+ endforeach()
+ set(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES)
+ endif()
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES)
+ endif()
+ file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.F"
+ "${SOURCE}\n")
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR}")
+ endif()
+ try_compile(${VAR}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.F
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ "${CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ foreach(_regex ${_FAIL_REGEX})
+ if("${OUTPUT}" MATCHES "${_regex}")
+ set(${VAR} 0)
+ endif()
+ endforeach()
+
+ if(${VAR})
+ set(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ 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"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ else()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VAR} - Failed")
+ endif()
+ set(${VAR} "" CACHE INTERNAL "Test ${VAR}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Performing Fortran SOURCE FILE Test ${VAR} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/CheckFunctionExists.c b/Modules/CheckFunctionExists.c
new file mode 100644
index 0000000000..607b3e8c6a
--- /dev/null
+++ b/Modules/CheckFunctionExists.c
@@ -0,0 +1,23 @@
+#ifdef CHECK_FUNCTION_EXISTS
+
+char CHECK_FUNCTION_EXISTS();
+#ifdef __CLASSIC_C__
+int main(){
+ int ac;
+ char*av[];
+#else
+int main(int ac, char*av[]){
+#endif
+ CHECK_FUNCTION_EXISTS();
+ if(ac > 1000)
+ {
+ return *av[0];
+ }
+ return 0;
+}
+
+#else /* CHECK_FUNCTION_EXISTS */
+
+# error "CHECK_FUNCTION_EXISTS has to specify the function"
+
+#endif /* CHECK_FUNCTION_EXISTS */
diff --git a/Modules/CheckFunctionExists.cmake b/Modules/CheckFunctionExists.cmake
new file mode 100644
index 0000000000..d277c32822
--- /dev/null
+++ b/Modules/CheckFunctionExists.cmake
@@ -0,0 +1,86 @@
+#.rst:
+# CheckFunctionExists
+# -------------------
+#
+# Check if a C function can be linked
+#
+# CHECK_FUNCTION_EXISTS(<function> <variable>)
+#
+# Check that the <function> is provided by libraries on the system and
+# store the result in a <variable>. This does not verify that any
+# system header file declares the function, only that it can be found at
+# link time (consider using CheckSymbolExists).
+# <variable> will be created as an internal cache variable.
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2002-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+
+
+macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
+ if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
+ set(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${FUNCTION}")
+ endif()
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
+ endif()
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_FUNCTION_EXISTS_ADD_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_FUNCTION_EXISTS_ADD_INCLUDES)
+ endif()
+ try_compile(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ "${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+ if(${VARIABLE})
+ set(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${FUNCTION} - found")
+ endif()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the function ${FUNCTION} exists passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${FUNCTION} - not found")
+ endif()
+ set(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the function ${FUNCTION} exists failed with the following output:\n"
+ "${OUTPUT}\n\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/CheckIncludeFile.c.in b/Modules/CheckIncludeFile.c.in
new file mode 100644
index 0000000000..ddfbee8be7
--- /dev/null
+++ b/Modules/CheckIncludeFile.c.in
@@ -0,0 +1,13 @@
+#include <${CHECK_INCLUDE_FILE_VAR}>
+
+#ifdef __CLASSIC_C__
+int main()
+{
+ return 0;
+}
+#else
+int main(void)
+{
+ return 0;
+}
+#endif
diff --git a/Modules/CheckIncludeFile.cmake b/Modules/CheckIncludeFile.cmake
new file mode 100644
index 0000000000..402b37c6aa
--- /dev/null
+++ b/Modules/CheckIncludeFile.cmake
@@ -0,0 +1,95 @@
+#.rst:
+# CheckIncludeFile
+# ----------------
+#
+# macro which checks the include file exists.
+#
+# CHECK_INCLUDE_FILE(INCLUDE VARIABLE)
+#
+# ::
+#
+# INCLUDE - name of include file
+# VARIABLE - variable to return result
+# Will be created as an internal cache variable.
+#
+#
+#
+# an optional third argument is the CFlags to add to the compile line or
+# you can use CMAKE_REQUIRED_FLAGS
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+macro(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
+ if(NOT DEFINED "${VARIABLE}")
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS)
+ endif()
+ set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
+ configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.c.in
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c)
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${INCLUDE}")
+ endif()
+ if(${ARGC} EQUAL 3)
+ set(CMAKE_C_FLAGS_SAVE ${CMAKE_C_FLAGS})
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGV2}")
+ endif()
+
+ try_compile(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ CMAKE_FLAGS
+ -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
+ "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ if(${ARGC} EQUAL 3)
+ set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE})
+ endif()
+
+ if(${VARIABLE})
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${INCLUDE} - found")
+ endif()
+ set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the include file ${INCLUDE} "
+ "exists passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${INCLUDE} - not found")
+ endif()
+ set(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the include file ${INCLUDE} "
+ "exists failed with the following output:\n"
+ "${OUTPUT}\n\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/CheckIncludeFile.cxx.in b/Modules/CheckIncludeFile.cxx.in
new file mode 100644
index 0000000000..40441f15ab
--- /dev/null
+++ b/Modules/CheckIncludeFile.cxx.in
@@ -0,0 +1,6 @@
+#include <${CHECK_INCLUDE_FILE_VAR}>
+
+int main()
+{
+ return 0;
+}
diff --git a/Modules/CheckIncludeFileCXX.cmake b/Modules/CheckIncludeFileCXX.cmake
new file mode 100644
index 0000000000..eae1730fb8
--- /dev/null
+++ b/Modules/CheckIncludeFileCXX.cmake
@@ -0,0 +1,99 @@
+#.rst:
+# CheckIncludeFileCXX
+# -------------------
+#
+# Check if the include file exists.
+#
+# ::
+#
+# CHECK_INCLUDE_FILE_CXX(INCLUDE VARIABLE)
+#
+#
+#
+# ::
+#
+# INCLUDE - name of include file
+# VARIABLE - variable to return result
+# Will be created as an internal cache variable.
+#
+#
+#
+# An optional third argument is the CFlags to add to the compile line or
+# you can use CMAKE_REQUIRED_FLAGS.
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+macro(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE)
+ if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
+ endif()
+ set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
+ configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx)
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for C++ include ${INCLUDE}")
+ endif()
+ if(${ARGC} EQUAL 3)
+ set(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
+ endif()
+
+ try_compile(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ CMAKE_FLAGS
+ -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
+ "${CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ if(${ARGC} EQUAL 3)
+ set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
+ endif()
+
+ if(${VARIABLE})
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for C++ include ${INCLUDE} - found")
+ endif()
+ set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the include file ${INCLUDE} "
+ "exists passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for C++ include ${INCLUDE} - not found")
+ endif()
+ set(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the include file ${INCLUDE} "
+ "exists failed with the following output:\n"
+ "${OUTPUT}\n\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/CheckIncludeFiles.cmake b/Modules/CheckIncludeFiles.cmake
new file mode 100644
index 0000000000..2494862457
--- /dev/null
+++ b/Modules/CheckIncludeFiles.cmake
@@ -0,0 +1,102 @@
+#.rst:
+# CheckIncludeFiles
+# -----------------
+#
+# Check if the files can be included
+#
+#
+#
+# CHECK_INCLUDE_FILES(INCLUDE VARIABLE)
+#
+# ::
+#
+# INCLUDE - list of files to include
+# VARIABLE - variable to return result
+# Will be created as an internal cache variable.
+#
+#
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2003-2012 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.)
+
+macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
+ if(NOT DEFINED "${VARIABLE}")
+ set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_INCLUDE_FILES_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_INCLUDE_FILES_INCLUDE_DIRS)
+ endif()
+ set(CHECK_INCLUDE_FILES_CONTENT "/* */\n")
+ set(MACRO_CHECK_INCLUDE_FILES_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ foreach(FILE ${INCLUDE})
+ set(CMAKE_CONFIGURABLE_FILE_CONTENT
+ "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
+ endforeach()
+ set(CMAKE_CONFIGURABLE_FILE_CONTENT
+ "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(void){return 0;}\n")
+ configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c" @ONLY)
+
+ set(_INCLUDE ${INCLUDE}) # remove empty elements
+ if("${_INCLUDE}" MATCHES "^([^;]+);.+;([^;]+)$")
+ list(LENGTH _INCLUDE _INCLUDE_LEN)
+ set(_description "${_INCLUDE_LEN} include files ${CMAKE_MATCH_1}, ..., ${CMAKE_MATCH_2}")
+ elseif("${_INCLUDE}" MATCHES "^([^;]+);([^;]+)$")
+ set(_description "include files ${CMAKE_MATCH_1}, ${CMAKE_MATCH_2}")
+ else()
+ set(_description "include file ${_INCLUDE}")
+ endif()
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${_description}")
+ endif()
+ try_compile(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ CMAKE_FLAGS
+ -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS}
+ "${CHECK_INCLUDE_FILES_INCLUDE_DIRS}"
+ OUTPUT_VARIABLE OUTPUT)
+ if(${VARIABLE})
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${_description} - found")
+ endif()
+ set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if files ${INCLUDE} "
+ "exist passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${_description} - not found")
+ endif()
+ set(${VARIABLE} "" CACHE INTERNAL "Have includes ${INCLUDE}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if files ${INCLUDE} "
+ "exist failed with the following output:\n"
+ "${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake
new file mode 100644
index 0000000000..99c809b7a3
--- /dev/null
+++ b/Modules/CheckLanguage.cmake
@@ -0,0 +1,78 @@
+#.rst:
+# CheckLanguage
+# -------------
+#
+# Check if a language can be enabled
+#
+# Usage:
+#
+# ::
+#
+# check_language(<lang>)
+#
+# where <lang> is a language that may be passed to enable_language()
+# such as "Fortran". If CMAKE_<lang>_COMPILER is already defined the
+# check does nothing. Otherwise it tries enabling the language in a
+# test project. The result is cached in CMAKE_<lang>_COMPILER as the
+# compiler that was found, or NOTFOUND if the language cannot be
+# enabled.
+#
+# Example:
+#
+# ::
+#
+# check_language(Fortran)
+# if(CMAKE_Fortran_COMPILER)
+# enable_language(Fortran)
+# else()
+# message(STATUS "No Fortran support")
+# endif()
+
+#=============================================================================
+# Copyright 2009-2012 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.)
+
+macro(check_language lang)
+ if(NOT DEFINED CMAKE_${lang}_COMPILER)
+ set(_desc "Looking for a ${lang} compiler")
+ message(STATUS ${_desc})
+ file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang})
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/CMakeLists.txt"
+ "cmake_minimum_required(VERSION ${CMAKE_VERSION})
+project(Check${lang} ${lang})
+file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
+ \"set(CMAKE_${lang}_COMPILER \\\"\${CMAKE_${lang}_COMPILER}\\\")\\n\"
+ )
+")
+ execute_process(
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}
+ COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR}
+ OUTPUT_VARIABLE output
+ ERROR_VARIABLE output
+ RESULT_VARIABLE result
+ )
+ include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/result.cmake OPTIONAL)
+ if(CMAKE_${lang}_COMPILER AND "${result}" STREQUAL "0")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "${_desc} passed with the following output:\n"
+ "${output}\n")
+ else()
+ set(CMAKE_${lang}_COMPILER NOTFOUND)
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "${_desc} failed with the following output:\n"
+ "${output}\n")
+ endif()
+ message(STATUS "${_desc} - ${CMAKE_${lang}_COMPILER}")
+ set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE FILEPATH "${lang} compiler")
+ mark_as_advanced(CMAKE_${lang}_COMPILER)
+ endif()
+endmacro()
diff --git a/Modules/CheckLibraryExists.cmake b/Modules/CheckLibraryExists.cmake
new file mode 100644
index 0000000000..95c595a21d
--- /dev/null
+++ b/Modules/CheckLibraryExists.cmake
@@ -0,0 +1,86 @@
+#.rst:
+# CheckLibraryExists
+# ------------------
+#
+# Check if the function exists.
+#
+# CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE)
+#
+# ::
+#
+# LIBRARY - the name of the library you are looking for
+# FUNCTION - the name of the function
+# LOCATION - location where the library should be found
+# VARIABLE - variable to store the result
+# Will be created as an internal cache variable.
+#
+#
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+
+
+macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
+ if(NOT DEFINED "${VARIABLE}")
+ set(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
+ "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
+ endif()
+ set(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_LIBRARY_EXISTS_LIBRARIES
+ ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
+ endif()
+ try_compile(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES}
+ CMAKE_FLAGS
+ -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
+ -DLINK_DIRECTORIES:STRING=${LOCATION}
+ OUTPUT_VARIABLE OUTPUT)
+
+ if(${VARIABLE})
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
+ endif()
+ set(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
+ "passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
+ endif()
+ set(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
+ "failed with the following output:\n"
+ "${OUTPUT}\n\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/CheckLibraryExists.lists.in b/Modules/CheckLibraryExists.lists.in
new file mode 100644
index 0000000000..741b87d72c
--- /dev/null
+++ b/Modules/CheckLibraryExists.lists.in
@@ -0,0 +1,8 @@
+PROJECT(CHECK_LIBRARY_EXISTS)
+
+
+ADD_DEFINITIONS(-DCHECK_FUNCTION_EXISTS=${CHECK_LIBRARY_EXISTS_FUNCTION})
+LINK_DIRECTORIES(${CHECK_LIBRARY_EXISTS_LOCATION})
+ADD_EXECUTABLE(CheckLibraryExists ${CHECK_LIBRARY_EXISTS_SOURCE})
+TARGET_LINK_LIBRARIES(CheckLibraryExists ${CHECK_LIBRARY_EXISTS_LIBRARY})
+
diff --git a/Modules/CheckPrototypeDefinition.c.in b/Modules/CheckPrototypeDefinition.c.in
new file mode 100644
index 0000000000..a97344ac3e
--- /dev/null
+++ b/Modules/CheckPrototypeDefinition.c.in
@@ -0,0 +1,29 @@
+@CHECK_PROTOTYPE_DEFINITION_HEADER@
+
+static void cmakeRequireSymbol(int dummy, ...) {
+ (void) dummy;
+}
+
+static void checkSymbol(void) {
+#ifndef @CHECK_PROTOTYPE_DEFINITION_SYMBOL@
+ cmakeRequireSymbol(0, &@CHECK_PROTOTYPE_DEFINITION_SYMBOL@);
+#endif
+}
+
+@CHECK_PROTOTYPE_DEFINITION_PROTO@ {
+ return @CHECK_PROTOTYPE_DEFINITION_RETURN@;
+}
+
+#ifdef __CLASSIC_C__
+int main() {
+ int ac;
+ char*av[];
+#else
+int main(int ac, char *av[]) {
+#endif
+ checkSymbol();
+ if (ac > 1000) {
+ return *av[0];
+ }
+ return 0;
+}
diff --git a/Modules/CheckPrototypeDefinition.cmake b/Modules/CheckPrototypeDefinition.cmake
new file mode 100644
index 0000000000..e203d4c3fb
--- /dev/null
+++ b/Modules/CheckPrototypeDefinition.cmake
@@ -0,0 +1,119 @@
+#.rst:
+# CheckPrototypeDefinition
+# ------------------------
+#
+# Check if the protoype we expect is correct.
+#
+# check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE)
+#
+# ::
+#
+# FUNCTION - The name of the function (used to check if prototype exists)
+# PROTOTYPE- The prototype to check.
+# RETURN - The return value of the function.
+# HEADER - The header files required.
+# VARIABLE - The variable to store the result.
+# Will be created as an internal cache variable.
+#
+# Example:
+#
+# ::
+#
+# check_prototype_definition(getpwent_r
+# "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)"
+# "NULL"
+# "unistd.h;pwd.h"
+# SOLARIS_GETPWENT_R)
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2005-2009 Kitware, Inc.
+# Copyright 2010-2011 Andreas Schneider <asn@cryptomilk.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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+#
+
+
+get_filename_component(__check_proto_def_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+
+function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE)
+
+ if (NOT DEFINED ${_VARIABLE})
+ set(CHECK_PROTOTYPE_DEFINITION_CONTENT "/* */\n")
+
+ set(CHECK_PROTOTYPE_DEFINITION_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ if (CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_PROTOTYPE_DEFINITION_LIBS
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_PROTOTYPE_DEFINITION_LIBS)
+ endif()
+ if (CMAKE_REQUIRED_INCLUDES)
+ set(CMAKE_SYMBOL_EXISTS_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CMAKE_SYMBOL_EXISTS_INCLUDES)
+ endif()
+
+ foreach(_FILE ${_HEADER})
+ set(CHECK_PROTOTYPE_DEFINITION_HEADER
+ "${CHECK_PROTOTYPE_DEFINITION_HEADER}#include <${_FILE}>\n")
+ endforeach()
+
+ set(CHECK_PROTOTYPE_DEFINITION_SYMBOL ${_FUNCTION})
+ set(CHECK_PROTOTYPE_DEFINITION_PROTO ${_PROTOTYPE})
+ set(CHECK_PROTOTYPE_DEFINITION_RETURN ${_RETURN})
+
+ configure_file("${__check_proto_def_dir}/CheckPrototypeDefinition.c.in"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c" @ONLY)
+
+ file(READ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c _SOURCE)
+
+ try_compile(${_VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_PROTOTYPE_DEFINITION_LIBS}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CHECK_PROTOTYPE_DEFINITION_FLAGS}
+ "${CMAKE_SYMBOL_EXISTS_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ if (${_VARIABLE})
+ set(${_VARIABLE} 1 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - True")
+ endif()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else ()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - False")
+ endif()
+ set(${_VARIABLE} 0 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} failed with the following output:\n"
+ "${OUTPUT}\n\n${_SOURCE}\n\n")
+ endif ()
+ endif()
+
+endfunction()
diff --git a/Modules/CheckSizeOf.cmake b/Modules/CheckSizeOf.cmake
new file mode 100644
index 0000000000..f0707df4e3
--- /dev/null
+++ b/Modules/CheckSizeOf.cmake
@@ -0,0 +1,18 @@
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+message(SEND_ERROR
+ "Modules/CheckSizeOf.cmake has been removed. "
+ "Use Modules/CheckTypeSize.cmake instead. This "
+ "compatibility check may be removed before the next release!")
diff --git a/Modules/CheckStructHasMember.cmake b/Modules/CheckStructHasMember.cmake
new file mode 100644
index 0000000000..c8949cf26b
--- /dev/null
+++ b/Modules/CheckStructHasMember.cmake
@@ -0,0 +1,85 @@
+#.rst:
+# CheckStructHasMember
+# --------------------
+#
+# Check if the given struct or class has the specified member variable
+#
+# ::
+#
+# CHECK_STRUCT_HAS_MEMBER(<struct> <member> <header> <variable>
+# [LANGUAGE <language>])
+#
+# ::
+#
+# <struct> - the name of the struct or class you are interested in
+# <member> - the member which existence you want to check
+# <header> - the header(s) where the prototype should be declared
+# <variable> - variable to store the result
+# <language> - the compiler to use (C or CXX)
+#
+#
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+#
+#
+#
+# Example: CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h
+# HAVE_TIMEVAL_TV_SEC LANGUAGE C)
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+include(CheckCSourceCompiles)
+include(CheckCXXSourceCompiles)
+
+macro (CHECK_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
+ set(_INCLUDE_FILES)
+ foreach (it ${_HEADER})
+ set(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
+ endforeach ()
+
+ if("x${ARGN}" STREQUAL "x")
+ set(_lang C)
+ elseif("x${ARGN}" MATCHES "^xLANGUAGE;([a-zA-Z]+)$")
+ set(_lang "${CMAKE_MATCH_1}")
+ else()
+ message(FATAL_ERROR "Unknown arguments:\n ${ARGN}\n")
+ endif()
+
+ set(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
+${_INCLUDE_FILES}
+int main()
+{
+ ${_STRUCT}* tmp;
+ (void) tmp->${_MEMBER};
+ return 0;
+}
+")
+
+ if("${_lang}" STREQUAL "C")
+ CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
+ elseif("${_lang}" STREQUAL "CXX")
+ CHECK_CXX_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
+ else()
+ message(FATAL_ERROR "Unknown language:\n ${_lang}\nSupported languages: C, CXX.\n")
+ endif()
+endmacro ()
diff --git a/Modules/CheckSymbolExists.cmake b/Modules/CheckSymbolExists.cmake
new file mode 100644
index 0000000000..79c5ba78ee
--- /dev/null
+++ b/Modules/CheckSymbolExists.cmake
@@ -0,0 +1,113 @@
+#.rst:
+# CheckSymbolExists
+# -----------------
+#
+# Check if a symbol exists as a function, variable, or macro
+#
+# CHECK_SYMBOL_EXISTS(<symbol> <files> <variable>)
+#
+# Check that the <symbol> is available after including given header
+# <files> and store the result in a <variable>. Specify the list of
+# files in one argument as a semicolon-separated list.
+# <variable> will be created as an internal cache variable.
+#
+# If the header files define the symbol as a macro it is considered
+# available and assumed to work. If the header files declare the symbol
+# as a function or variable then the symbol must also be available for
+# linking. If the symbol is a type or enum value it will not be
+# recognized (consider using CheckTypeSize or CheckCSourceCompiles). If
+# the check needs to be done in C++, consider using
+# CHECK_CXX_SYMBOL_EXISTS(), which does the same as
+# CHECK_SYMBOL_EXISTS(), but in C++.
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2003-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+
+
+macro(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
+ _CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
+endmacro()
+
+macro(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE)
+ if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
+ set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
+ set(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_SYMBOL_EXISTS_LIBS
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_SYMBOL_EXISTS_LIBS)
+ endif()
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CMAKE_SYMBOL_EXISTS_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CMAKE_SYMBOL_EXISTS_INCLUDES)
+ endif()
+ foreach(FILE ${FILES})
+ set(CMAKE_CONFIGURABLE_FILE_CONTENT
+ "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
+ endforeach()
+ set(CMAKE_CONFIGURABLE_FILE_CONTENT
+ "${CMAKE_CONFIGURABLE_FILE_CONTENT}\nint main(int argc, char** argv)\n{\n (void)argv;\n#ifndef ${SYMBOL}\n return ((int*)(&${SYMBOL}))[argc];\n#else\n (void)argc;\n return 0;\n#endif\n}\n")
+
+ configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
+ "${SOURCEFILE}" @ONLY)
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${SYMBOL}")
+ endif()
+ try_compile(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ "${SOURCEFILE}"
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_SYMBOL_EXISTS_LIBS}
+ CMAKE_FLAGS
+ -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS}
+ "${CMAKE_SYMBOL_EXISTS_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+ if(${VARIABLE})
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${SYMBOL} - found")
+ endif()
+ set(${VARIABLE} 1 CACHE INTERNAL "Have symbol ${SYMBOL}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the ${SYMBOL} "
+ "exist passed with the following output:\n"
+ "${OUTPUT}\nFile ${SOURCEFILE}:\n"
+ "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
+ else()
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${SYMBOL} - not found")
+ endif()
+ set(${VARIABLE} "" CACHE INTERNAL "Have symbol ${SYMBOL}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the ${SYMBOL} "
+ "exist failed with the following output:\n"
+ "${OUTPUT}\nFile ${SOURCEFILE}:\n"
+ "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/CheckTypeSize.c.in b/Modules/CheckTypeSize.c.in
new file mode 100644
index 0000000000..b6c3688011
--- /dev/null
+++ b/Modules/CheckTypeSize.c.in
@@ -0,0 +1,37 @@
+@headers@
+
+#undef KEY
+#if defined(__i386)
+# define KEY '_','_','i','3','8','6'
+#elif defined(__x86_64)
+# define KEY '_','_','x','8','6','_','6','4'
+#elif defined(__ppc__)
+# define KEY '_','_','p','p','c','_','_'
+#elif defined(__ppc64__)
+# define KEY '_','_','p','p','c','6','4','_','_'
+#endif
+
+#define SIZE (sizeof(@type@))
+char info_size[] = {'I', 'N', 'F', 'O', ':', 's','i','z','e','[',
+ ('0' + ((SIZE / 10000)%10)),
+ ('0' + ((SIZE / 1000)%10)),
+ ('0' + ((SIZE / 100)%10)),
+ ('0' + ((SIZE / 10)%10)),
+ ('0' + (SIZE % 10)),
+ ']',
+#ifdef KEY
+ ' ','k','e','y','[', KEY, ']',
+#endif
+ '\0'};
+
+#ifdef __CLASSIC_C__
+int main(argc, argv) int argc; char *argv[];
+#else
+int main(int argc, char *argv[])
+#endif
+{
+ int require = 0;
+ require += info_size[argc];
+ (void)argv;
+ return require;
+}
diff --git a/Modules/CheckTypeSize.cmake b/Modules/CheckTypeSize.cmake
new file mode 100644
index 0000000000..73ad86ebb2
--- /dev/null
+++ b/Modules/CheckTypeSize.cmake
@@ -0,0 +1,273 @@
+#.rst:
+# CheckTypeSize
+# -------------
+#
+# Check sizeof a type
+#
+# ::
+#
+# CHECK_TYPE_SIZE(TYPE VARIABLE [BUILTIN_TYPES_ONLY]
+# [LANGUAGE <language>])
+#
+# Check if the type exists and determine its size. On return,
+# "HAVE_${VARIABLE}" holds the existence of the type, and "${VARIABLE}"
+# holds one of the following:
+#
+# ::
+#
+# <size> = type has non-zero size <size>
+# "0" = type has arch-dependent size (see below)
+# "" = type does not exist
+#
+# Both ``HAVE_${VARIABLE}`` and ``${VARIABLE}`` will be created as internal
+# cache variables.
+#
+# Furthermore, the variable "${VARIABLE}_CODE" holds C preprocessor code
+# to define the macro "${VARIABLE}" to the size of the type, or leave
+# the macro undefined if the type does not exist.
+#
+# The variable "${VARIABLE}" may be "0" when CMAKE_OSX_ARCHITECTURES has
+# multiple architectures for building OS X universal binaries. This
+# indicates that the type size varies across architectures. In this
+# case "${VARIABLE}_CODE" contains C preprocessor tests mapping from
+# each architecture macro to the corresponding type size. The list of
+# architecture macros is stored in "${VARIABLE}_KEYS", and the value for
+# each key is stored in "${VARIABLE}-${KEY}".
+#
+# If the BUILTIN_TYPES_ONLY option is not given, the macro checks for
+# headers <sys/types.h>, <stdint.h>, and <stddef.h>, and saves results
+# in HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H. The type size
+# check automatically includes the available headers, thus supporting
+# checks of types defined in the headers.
+#
+# If LANGUAGE is set, the specified compiler will be used to perform the
+# check. Acceptable values are C and CXX
+#
+# Despite the name of the macro you may use it to check the size of more
+# complex expressions, too. To check e.g. for the size of a struct
+# member you can do something like this:
+#
+# ::
+#
+# check_type_size("((struct something*)0)->member" SIZEOF_MEMBER)
+#
+#
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+# CMAKE_EXTRA_INCLUDE_FILES = list of extra headers to include
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+include(CheckIncludeFile)
+include(CheckIncludeFileCXX)
+
+cmake_policy(PUSH)
+cmake_policy(VERSION 3.0)
+
+get_filename_component(__check_type_size_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+#-----------------------------------------------------------------------------
+# Helper function. DO NOT CALL DIRECTLY.
+function(__check_type_size_impl type var map builtin language)
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Check size of ${type}")
+ endif()
+
+ # Include header files.
+ set(headers)
+ if(builtin)
+ if(HAVE_SYS_TYPES_H)
+ set(headers "${headers}#include <sys/types.h>\n")
+ endif()
+ if(HAVE_STDINT_H)
+ set(headers "${headers}#include <stdint.h>\n")
+ endif()
+ if(HAVE_STDDEF_H)
+ set(headers "${headers}#include <stddef.h>\n")
+ endif()
+ endif()
+ foreach(h ${CMAKE_EXTRA_INCLUDE_FILES})
+ set(headers "${headers}#include \"${h}\"\n")
+ endforeach()
+
+ # Perform the check.
+
+ if("${language}" STREQUAL "C")
+ set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c)
+ elseif("${language}" STREQUAL "CXX")
+ set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp)
+ else()
+ message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n")
+ endif()
+ set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin)
+ configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY)
+ try_compile(HAVE_${var} ${CMAKE_BINARY_DIR} ${src}
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
+ CMAKE_FLAGS
+ "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}"
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
+ OUTPUT_VARIABLE output
+ COPY_FILE ${bin}
+ )
+
+ if(HAVE_${var})
+ # The check compiled. Load information from the binary.
+ file(STRINGS ${bin} strings LIMIT_COUNT 10 REGEX "INFO:size")
+
+ # Parse the information strings.
+ set(regex_size ".*INFO:size\\[0*([^]]*)\\].*")
+ set(regex_key " key\\[([^]]*)\\]")
+ set(keys)
+ set(code)
+ set(mismatch)
+ set(first 1)
+ foreach(info ${strings})
+ if("${info}" MATCHES "${regex_size}")
+ # Get the type size.
+ set(size "${CMAKE_MATCH_1}")
+ if(first)
+ set(${var} ${size})
+ elseif(NOT "${size}" STREQUAL "${${var}}")
+ set(mismatch 1)
+ endif()
+ set(first 0)
+
+ # Get the architecture map key.
+ string(REGEX MATCH "${regex_key}" key "${info}")
+ string(REGEX REPLACE "${regex_key}" "\\1" key "${key}")
+ if(key)
+ set(code "${code}\nset(${var}-${key} \"${size}\")")
+ list(APPEND keys ${key})
+ endif()
+ endif()
+ endforeach()
+
+ # Update the architecture-to-size map.
+ if(mismatch AND keys)
+ configure_file(${__check_type_size_dir}/CheckTypeSizeMap.cmake.in ${map} @ONLY)
+ set(${var} 0)
+ else()
+ file(REMOVE ${map})
+ endif()
+
+ if(mismatch AND NOT keys)
+ message(SEND_ERROR "CHECK_TYPE_SIZE found different results, consider setting CMAKE_OSX_ARCHITECTURES or CMAKE_TRY_COMPILE_OSX_ARCHITECTURES to one or no architecture !")
+ endif()
+
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Check size of ${type} - done")
+ endif()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining size of ${type} passed with the following output:\n${output}\n\n")
+ set(${var} "${${var}}" CACHE INTERNAL "CHECK_TYPE_SIZE: sizeof(${type})")
+ else()
+ # The check failed to compile.
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Check size of ${type} - failed")
+ endif()
+ file(READ ${src} content)
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining size of ${type} failed with the following output:\n${output}\n${src}:\n${content}\n\n")
+ set(${var} "" CACHE INTERNAL "CHECK_TYPE_SIZE: ${type} unknown")
+ file(REMOVE ${map})
+ endif()
+endfunction()
+
+#-----------------------------------------------------------------------------
+macro(CHECK_TYPE_SIZE TYPE VARIABLE)
+ # parse arguments
+ unset(doing)
+ foreach(arg ${ARGN})
+ if("x${arg}" STREQUAL "xBUILTIN_TYPES_ONLY")
+ set(_CHECK_TYPE_SIZE_${arg} 1)
+ unset(doing)
+ elseif("x${arg}" STREQUAL "xLANGUAGE") # change to MATCHES for more keys
+ set(doing "${arg}")
+ set(_CHECK_TYPE_SIZE_${doing} "")
+ elseif("x${doing}" STREQUAL "xLANGUAGE")
+ set(_CHECK_TYPE_SIZE_${doing} "${arg}")
+ unset(doing)
+ else()
+ message(FATAL_ERROR "Unknown argument:\n ${arg}\n")
+ endif()
+ endforeach()
+ if("x${doing}" MATCHES "^x(LANGUAGE)$")
+ message(FATAL_ERROR "Missing argument:\n ${doing} arguments requires a value\n")
+ endif()
+ if(DEFINED _CHECK_TYPE_SIZE_LANGUAGE)
+ if(NOT "x${_CHECK_TYPE_SIZE_LANGUAGE}" MATCHES "^x(C|CXX)$")
+ message(FATAL_ERROR "Unknown language:\n ${_CHECK_TYPE_SIZE_LANGUAGE}.\nSupported languages: C, CXX.\n")
+ endif()
+ set(_language ${_CHECK_TYPE_SIZE_LANGUAGE})
+ else()
+ set(_language C)
+ endif()
+
+ # Optionally check for standard headers.
+ if(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY)
+ set(_builtin 0)
+ else()
+ set(_builtin 1)
+ if("${_language}" STREQUAL "C")
+ check_include_file(sys/types.h HAVE_SYS_TYPES_H)
+ check_include_file(stdint.h HAVE_STDINT_H)
+ check_include_file(stddef.h HAVE_STDDEF_H)
+ elseif("${_language}" STREQUAL "CXX")
+ check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H)
+ check_include_file_cxx(stdint.h HAVE_STDINT_H)
+ check_include_file_cxx(stddef.h HAVE_STDDEF_H)
+ endif()
+ endif()
+ unset(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY)
+ unset(_CHECK_TYPE_SIZE_LANGUAGE)
+
+ # Compute or load the size or size map.
+ set(${VARIABLE}_KEYS)
+ set(_map_file ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${VARIABLE}.cmake)
+ if(NOT DEFINED HAVE_${VARIABLE})
+ __check_type_size_impl(${TYPE} ${VARIABLE} ${_map_file} ${_builtin} ${_language})
+ endif()
+ include(${_map_file} OPTIONAL)
+ set(_map_file)
+ set(_builtin)
+
+ # Create preprocessor code.
+ if(${VARIABLE}_KEYS)
+ set(${VARIABLE}_CODE)
+ set(_if if)
+ foreach(key ${${VARIABLE}_KEYS})
+ set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#${_if} defined(${key})\n# define ${VARIABLE} ${${VARIABLE}-${key}}\n")
+ set(_if elif)
+ endforeach()
+ set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#else\n# error ${VARIABLE} unknown\n#endif")
+ set(_if)
+ elseif(${VARIABLE})
+ set(${VARIABLE}_CODE "#define ${VARIABLE} ${${VARIABLE}}")
+ else()
+ set(${VARIABLE}_CODE "/* #undef ${VARIABLE} */")
+ endif()
+endmacro()
+
+#-----------------------------------------------------------------------------
+cmake_policy(POP)
diff --git a/Modules/CheckTypeSizeMap.cmake.in b/Modules/CheckTypeSizeMap.cmake.in
new file mode 100644
index 0000000000..1e73cfff18
--- /dev/null
+++ b/Modules/CheckTypeSizeMap.cmake.in
@@ -0,0 +1 @@
+set(@var@_KEYS "@keys@")@code@
diff --git a/Modules/CheckVariableExists.c b/Modules/CheckVariableExists.c
new file mode 100644
index 0000000000..752f6e486b
--- /dev/null
+++ b/Modules/CheckVariableExists.c
@@ -0,0 +1,20 @@
+#ifdef CHECK_VARIABLE_EXISTS
+
+extern int CHECK_VARIABLE_EXISTS;
+
+#ifdef __CLASSIC_C__
+int main(){
+ int ac;
+ char*av[];
+#else
+int main(int ac, char*av[]){
+#endif
+ if(ac > 1000){return *av[0];}
+ return CHECK_VARIABLE_EXISTS;
+}
+
+#else /* CHECK_VARIABLE_EXISTS */
+
+# error "CHECK_VARIABLE_EXISTS has to specify the variable"
+
+#endif /* CHECK_VARIABLE_EXISTS */
diff --git a/Modules/CheckVariableExists.cmake b/Modules/CheckVariableExists.cmake
new file mode 100644
index 0000000000..f3e05e41b3
--- /dev/null
+++ b/Modules/CheckVariableExists.cmake
@@ -0,0 +1,85 @@
+#.rst:
+# CheckVariableExists
+# -------------------
+#
+# Check if the variable exists.
+#
+# ::
+#
+# CHECK_VARIABLE_EXISTS(VAR VARIABLE)
+#
+#
+#
+# ::
+#
+# VAR - the name of the variable
+# VARIABLE - variable to store the result
+# Will be created as an internal cache variable.
+#
+#
+# This macro is only for C variables.
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+# CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+
+
+macro(CHECK_VARIABLE_EXISTS VAR VARIABLE)
+ if(NOT DEFINED "${VARIABLE}")
+ set(MACRO_CHECK_VARIABLE_DEFINITIONS
+ "-DCHECK_VARIABLE_EXISTS=${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${VAR}")
+ endif()
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES)
+ endif()
+ try_compile(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_ROOT}/Modules/CheckVariableExists.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_VARIABLE_EXISTS_ADD_LIBRARIES}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_VARIABLE_DEFINITIONS}
+ OUTPUT_VARIABLE OUTPUT)
+ if(${VARIABLE})
+ set(${VARIABLE} 1 CACHE INTERNAL "Have variable ${VAR}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${VAR} - found")
+ endif()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the variable ${VAR} exists passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else()
+ set(${VARIABLE} "" CACHE INTERNAL "Have variable ${VAR}")
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Looking for ${VAR} - not found")
+ endif()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the variable ${VAR} exists failed with the following output:\n"
+ "${OUTPUT}\n\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/Compiler/ADSP-DetermineCompiler.cmake b/Modules/Compiler/ADSP-DetermineCompiler.cmake
new file mode 100644
index 0000000000..0340f6904f
--- /dev/null
+++ b/Modules/Compiler/ADSP-DetermineCompiler.cmake
@@ -0,0 +1,10 @@
+
+set(_compiler_id_pp_test "defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)")
+
+set(_compiler_id_version_compute "
+#if defined(__VISUALDSPVERSION__)
+ /* __VISUALDSPVERSION__ = 0xVVRRPP00 */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_HEX@(__VISUALDSPVERSION__>>24)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_HEX@(__VISUALDSPVERSION__>>16 & 0xFF)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_HEX@(__VISUALDSPVERSION__>>8 & 0xFF)
+#endif")
diff --git a/Modules/Compiler/Absoft-Fortran.cmake b/Modules/Compiler/Absoft-Fortran.cmake
new file mode 100644
index 0000000000..2e1666fbf1
--- /dev/null
+++ b/Modules/Compiler/Absoft-Fortran.cmake
@@ -0,0 +1,10 @@
+set(CMAKE_Fortran_FLAGS_INIT "")
+set(CMAKE_Fortran_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "")
+set(CMAKE_Fortran_FLAGS_RELEASE_INIT "-O3")
+set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
+set(CMAKE_Fortran_MODDIR_FLAG "-YMOD_OUT_DIR=")
+set(CMAKE_Fortran_MODPATH_FLAG "-p")
+set(CMAKE_Fortran_VERBOSE_FLAG "-v")
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree")
diff --git a/Modules/Compiler/AppleClang-ASM.cmake b/Modules/Compiler/AppleClang-ASM.cmake
new file mode 100644
index 0000000000..f52bde05eb
--- /dev/null
+++ b/Modules/Compiler/AppleClang-ASM.cmake
@@ -0,0 +1 @@
+include(Compiler/Clang-ASM)
diff --git a/Modules/Compiler/AppleClang-C.cmake b/Modules/Compiler/AppleClang-C.cmake
new file mode 100644
index 0000000000..44070b83fe
--- /dev/null
+++ b/Modules/Compiler/AppleClang-C.cmake
@@ -0,0 +1 @@
+include(Compiler/Clang-C)
diff --git a/Modules/Compiler/AppleClang-CXX.cmake b/Modules/Compiler/AppleClang-CXX.cmake
new file mode 100644
index 0000000000..0372e18b10
--- /dev/null
+++ b/Modules/Compiler/AppleClang-CXX.cmake
@@ -0,0 +1,6 @@
+include(Compiler/Clang)
+__compiler_clang(CXX)
+
+if(NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
+ set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
+endif()
diff --git a/Modules/Compiler/AppleClang-DetermineCompiler.cmake b/Modules/Compiler/AppleClang-DetermineCompiler.cmake
new file mode 100644
index 0000000000..397f95cbe1
--- /dev/null
+++ b/Modules/Compiler/AppleClang-DetermineCompiler.cmake
@@ -0,0 +1,7 @@
+
+set(_compiler_id_pp_test "defined(__clang__) && defined(__apple_build_version__)")
+
+include("${CMAKE_CURRENT_LIST_DIR}/Clang-DetermineCompilerInternal.cmake")
+
+set(_compiler_id_version_compute "${_compiler_id_version_compute}
+# define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(__apple_build_version__)")
diff --git a/Modules/Compiler/Borland-DetermineCompiler.cmake b/Modules/Compiler/Borland-DetermineCompiler.cmake
new file mode 100644
index 0000000000..ef3083b4d1
--- /dev/null
+++ b/Modules/Compiler/Borland-DetermineCompiler.cmake
@@ -0,0 +1,7 @@
+
+set(_compiler_id_pp_test "defined(__BORLANDC__)")
+
+set(_compiler_id_version_compute "
+ /* __BORLANDC__ = 0xVRR */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_HEX@(__BORLANDC__>>8)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_HEX@(__BORLANDC__ & 0xFF)")
diff --git a/Modules/Compiler/Clang-ASM.cmake b/Modules/Compiler/Clang-ASM.cmake
new file mode 100644
index 0000000000..16c9c159c2
--- /dev/null
+++ b/Modules/Compiler/Clang-ASM.cmake
@@ -0,0 +1,5 @@
+include(Compiler/Clang)
+
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;S;asm)
+
+__compiler_clang(ASM)
diff --git a/Modules/Compiler/Clang-C-FeatureTests.cmake b/Modules/Compiler/Clang-C-FeatureTests.cmake
new file mode 100644
index 0000000000..4a72e87f71
--- /dev/null
+++ b/Modules/Compiler/Clang-C-FeatureTests.cmake
@@ -0,0 +1,11 @@
+
+set(_cmake_oldestSupported "((__clang_major__ * 100) + __clang_minor__) >= 304")
+
+set(Clang_C11 "${_cmake_oldestSupported} && __STDC_VERSION__ >= 201112L")
+set(_cmake_feature_test_c_static_assert "${Clang_C11}")
+set(Clang_C99 "${_cmake_oldestSupported} && __STDC_VERSION__ >= 199901L")
+set(_cmake_feature_test_c_restrict "${Clang_C99}")
+set(_cmake_feature_test_c_variadic_macros "${Clang_C99}")
+
+set(Clang_C90 "${_cmake_oldestSupported} && !defined(__STDC_VERSION__)")
+set(_cmake_feature_test_c_function_prototypes "${Clang_C90}")
diff --git a/Modules/Compiler/Clang-C.cmake b/Modules/Compiler/Clang-C.cmake
new file mode 100644
index 0000000000..05d3c0b02e
--- /dev/null
+++ b/Modules/Compiler/Clang-C.cmake
@@ -0,0 +1,38 @@
+include(Compiler/Clang)
+__compiler_clang(C)
+
+cmake_policy(GET CMP0025 appleClangPolicy)
+if(WIN32 OR (APPLE AND NOT appleClangPolicy STREQUAL NEW))
+ return()
+endif()
+
+if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
+ set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90")
+ set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90")
+
+ set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
+ set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99")
+
+ set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
+ set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
+endif()
+
+set(CMAKE_C_STANDARD_DEFAULT 90)
+
+macro(cmake_record_c_compile_features)
+ macro(_get_clang_features std_version list)
+ record_compiler_features(C "-std=${std_version}" ${list})
+ endmacro()
+
+ if (UNIX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
+ _get_clang_features(c11 CMAKE_C11_COMPILE_FEATURES)
+ if (_result EQUAL 0)
+ _get_clang_features(c99 CMAKE_C99_COMPILE_FEATURES)
+ endif()
+ if (_result EQUAL 0)
+ _get_clang_features(c90 CMAKE_C90_COMPILE_FEATURES)
+ endif()
+ else()
+ set(_result 0)
+ endif()
+endmacro()
diff --git a/Modules/Compiler/Clang-CXX-FeatureTests.cmake b/Modules/Compiler/Clang-CXX-FeatureTests.cmake
new file mode 100644
index 0000000000..4c532fb01b
--- /dev/null
+++ b/Modules/Compiler/Clang-CXX-FeatureTests.cmake
@@ -0,0 +1,86 @@
+
+# Reference: http://clang.llvm.org/cxx_status.html
+# http://clang.llvm.org/docs/LanguageExtensions.html
+
+set(testable_features
+ cxx_alias_templates
+ cxx_alignas
+ cxx_attributes
+ cxx_auto_type
+ cxx_binary_literals
+ cxx_constexpr
+ cxx_contextual_conversions
+ cxx_decltype
+ cxx_decltype_incomplete_return_types
+ cxx_default_function_template_args
+ cxx_defaulted_functions
+ cxx_delegating_constructors
+ cxx_deleted_functions
+ cxx_explicit_conversions
+ cxx_generalized_initializers
+ cxx_inheriting_constructors
+ cxx_lambdas
+ cxx_local_type_template_args
+ cxx_noexcept
+ cxx_nonstatic_member_init
+ cxx_nullptr
+ cxx_range_for
+ cxx_raw_string_literals
+ cxx_reference_qualified_functions
+ cxx_relaxed_constexpr
+ cxx_return_type_deduction
+ cxx_rvalue_references
+ cxx_static_assert
+ cxx_strong_enums
+ cxx_thread_local
+ cxx_unicode_literals
+ cxx_unrestricted_unions
+ cxx_user_literals
+ cxx_variable_templates
+ cxx_variadic_templates
+)
+
+set(_cmake_oldestSupported "((__clang_major__ * 100) + __clang_minor__) >= 304")
+
+foreach(feature ${testable_features})
+ set(_cmake_feature_test_${feature} "${_cmake_oldestSupported} && __has_feature(${feature})")
+endforeach()
+
+unset(testable_features)
+
+set(_cmake_feature_test_cxx_aggregate_default_initializers "${_cmake_oldestSupported} && __has_feature(cxx_aggregate_nsdmi)")
+
+set(_cmake_feature_test_cxx_trailing_return_types "${_cmake_oldestSupported} && __has_feature(cxx_trailing_return)")
+set(_cmake_feature_test_cxx_alignof "${_cmake_oldestSupported} && __has_feature(cxx_alignas)")
+set(_cmake_feature_test_cxx_final "${_cmake_oldestSupported} && __has_feature(cxx_override_control)")
+set(_cmake_feature_test_cxx_override "${_cmake_oldestSupported} && __has_feature(cxx_override_control)")
+set(_cmake_feature_test_cxx_uniform_initialization "${_cmake_oldestSupported} && __has_feature(cxx_generalized_initializers)")
+set(_cmake_feature_test_cxx_defaulted_move_initializers "${_cmake_oldestSupported} && __has_feature(cxx_defaulted_functions)")
+set(_cmake_feature_test_cxx_lambda_init_captures "${_cmake_oldestSupported} && __has_feature(cxx_init_captures)")
+
+set(Clang34_CXX14 "((__clang_major__ * 100) + __clang_minor__) >= 304 && __cplusplus > 201103L")
+# http://llvm.org/bugs/show_bug.cgi?id=19242
+set(_cmake_feature_test_cxx_attribute_deprecated "${Clang34_CXX14}")
+# http://llvm.org/bugs/show_bug.cgi?id=19698
+set(_cmake_feature_test_cxx_decltype_auto "${Clang34_CXX14}")
+set(_cmake_feature_test_cxx_digit_separators "${Clang34_CXX14}")
+# http://llvm.org/bugs/show_bug.cgi?id=19674
+set(_cmake_feature_test_cxx_generic_lambdas "${Clang34_CXX14}")
+
+# TODO: Should be supported by Clang 3.1
+set(Clang31_CXX11 "${_cmake_oldestSupported} && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_enum_forward_declarations "${Clang31_CXX11}")
+set(_cmake_feature_test_cxx_sizeof_member "${Clang31_CXX11}")
+# TODO: Should be supported by Clang 2.9
+set(Clang29_CXX11 "${_cmake_oldestSupported} && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_extended_friend_declarations "${Clang29_CXX11}")
+set(_cmake_feature_test_cxx_extern_templates "${Clang29_CXX11}")
+set(_cmake_feature_test_cxx_func_identifier "${Clang29_CXX11}")
+set(_cmake_feature_test_cxx_inline_namespaces "${Clang29_CXX11}")
+set(_cmake_feature_test_cxx_long_long_type "${Clang29_CXX11}")
+set(_cmake_feature_test_cxx_right_angle_brackets "${Clang29_CXX11}")
+set(_cmake_feature_test_cxx_variadic_macros "${Clang29_CXX11}")
+
+# TODO: Should be supported forever?
+set(Clang_CXX98 "${_cmake_oldestSupported} && __cplusplus >= 199711L")
+set(_cmake_feature_test_cxx_template_template_parameters "${Clang_CXX98}")
diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake
new file mode 100644
index 0000000000..5dd7b4a2ac
--- /dev/null
+++ b/Modules/Compiler/Clang-CXX.cmake
@@ -0,0 +1,52 @@
+include(Compiler/Clang)
+__compiler_clang(CXX)
+
+if(NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
+ set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
+endif()
+
+cmake_policy(GET CMP0025 appleClangPolicy)
+if(WIN32 OR (APPLE AND NOT appleClangPolicy STREQUAL NEW))
+ return()
+endif()
+
+if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
+endif()
+
+if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
+elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
+endif()
+
+if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14")
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14")
+elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y")
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y")
+endif()
+
+set(CMAKE_CXX_STANDARD_DEFAULT 98)
+
+macro(cmake_record_cxx_compile_features)
+ macro(_get_clang_features std_version list)
+ record_compiler_features(CXX "-std=${std_version}" ${list})
+ endmacro()
+
+ if (UNIX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
+ _get_clang_features(c++1y CMAKE_CXX14_COMPILE_FEATURES)
+ if (_result EQUAL 0)
+ _get_clang_features(c++11 CMAKE_CXX11_COMPILE_FEATURES)
+ endif()
+ if (_result EQUAL 0)
+ _get_clang_features(c++98 CMAKE_CXX98_COMPILE_FEATURES)
+ endif()
+ else()
+ set(_result 0)
+ endif()
+endmacro()
diff --git a/Modules/Compiler/Clang-DetermineCompiler.cmake b/Modules/Compiler/Clang-DetermineCompiler.cmake
new file mode 100644
index 0000000000..89df1b6dc5
--- /dev/null
+++ b/Modules/Compiler/Clang-DetermineCompiler.cmake
@@ -0,0 +1,4 @@
+
+set(_compiler_id_pp_test "defined(__clang__)")
+
+include("${CMAKE_CURRENT_LIST_DIR}/Clang-DetermineCompilerInternal.cmake")
diff --git a/Modules/Compiler/Clang-DetermineCompilerInternal.cmake b/Modules/Compiler/Clang-DetermineCompilerInternal.cmake
new file mode 100644
index 0000000000..08c12305d8
--- /dev/null
+++ b/Modules/Compiler/Clang-DetermineCompilerInternal.cmake
@@ -0,0 +1,15 @@
+
+set(_compiler_id_version_compute "
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__clang_major__)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__clang_minor__)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__clang_patchlevel__)
+# if defined(_MSC_VER)
+ /* _MSC_VER = VVRR */
+# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(_MSC_VER / 100)
+# define @PREFIX@SIMULATE_VERSION_MINOR @MACRO_DEC@(_MSC_VER % 100)
+# endif")
+
+set(_compiler_id_simulate "
+# if defined(_MSC_VER)
+# define @PREFIX@SIMULATE_ID \"MSVC\"
+# endif")
diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake
new file mode 100644
index 0000000000..eeba11925b
--- /dev/null
+++ b/Modules/Compiler/Clang.cmake
@@ -0,0 +1,41 @@
+
+#=============================================================================
+# Copyright 2002-2012 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 module is shared by multiple languages; use include blocker.
+if(__COMPILER_CLANG)
+ return()
+endif()
+set(__COMPILER_CLANG 1)
+
+if(CMAKE_C_SIMULATE_ID STREQUAL "MSVC"
+ OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
+ macro(__compiler_clang lang)
+ endmacro()
+else()
+ include(Compiler/GNU)
+
+ macro(__compiler_clang lang)
+ __compiler_gnu(${lang})
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
+ if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4.0)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "-target ")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "-gcc-toolchain ")
+ else()
+ set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "--target=")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "--gcc-toolchain=")
+ endif()
+ endmacro()
+endif()
diff --git a/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake b/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake
new file mode 100644
index 0000000000..2265e5ea8f
--- /dev/null
+++ b/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake
@@ -0,0 +1,7 @@
+
+set(_compiler_id_pp_test "defined(__COMO__)")
+
+set(_compiler_id_version_compute "
+ /* __COMO_VERSION__ = VRR */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__COMO_VERSION__ / 100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__COMO_VERSION__ % 100)")
diff --git a/Modules/Compiler/Compaq-C-DetermineCompiler.cmake b/Modules/Compiler/Compaq-C-DetermineCompiler.cmake
new file mode 100644
index 0000000000..02e99dca0f
--- /dev/null
+++ b/Modules/Compiler/Compaq-C-DetermineCompiler.cmake
@@ -0,0 +1,8 @@
+
+set(_compiler_id_pp_test "defined(__DECC)")
+
+set(_compiler_id_version_compute "
+ /* __DECC_VER = VVRRTPPPP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__DECC_VER/10000000)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__DECC_VER/100000 % 100)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__DECC_VER % 10000)")
diff --git a/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake b/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake
new file mode 100644
index 0000000000..c7d0565ce2
--- /dev/null
+++ b/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake
@@ -0,0 +1,8 @@
+
+set(_compiler_id_pp_test "defined(__DECCXX)")
+
+set(_compiler_id_version_compute "
+ /* __DECCXX_VER = VVRRTPPPP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__DECCXX_VER/10000000)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__DECCXX_VER/100000 % 100)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__DECCXX_VER % 10000)")
diff --git a/Modules/Compiler/Cray-C.cmake b/Modules/Compiler/Cray-C.cmake
new file mode 100644
index 0000000000..675560c2a4
--- /dev/null
+++ b/Modules/Compiler/Cray-C.cmake
@@ -0,0 +1 @@
+set(CMAKE_C_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/Cray-CXX.cmake b/Modules/Compiler/Cray-CXX.cmake
new file mode 100644
index 0000000000..9fb191c754
--- /dev/null
+++ b/Modules/Compiler/Cray-CXX.cmake
@@ -0,0 +1 @@
+set(CMAKE_CXX_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/Cray-DetermineCompiler.cmake b/Modules/Compiler/Cray-DetermineCompiler.cmake
new file mode 100644
index 0000000000..881b82c0bf
--- /dev/null
+++ b/Modules/Compiler/Cray-DetermineCompiler.cmake
@@ -0,0 +1,6 @@
+
+set(_compiler_id_pp_test "defined(_CRAYC)")
+
+set(_compiler_id_version_compute "
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(_RELEASE)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(_RELEASE_MINOR)")
diff --git a/Modules/Compiler/Cray-Fortran.cmake b/Modules/Compiler/Cray-Fortran.cmake
new file mode 100644
index 0000000000..5d81bb02c4
--- /dev/null
+++ b/Modules/Compiler/Cray-Fortran.cmake
@@ -0,0 +1,6 @@
+set(CMAKE_Fortran_VERBOSE_FLAG "-v")
+set(CMAKE_Fortran_MODOUT_FLAG -em)
+set(CMAKE_Fortran_MODDIR_FLAG -J)
+set(CMAKE_Fortran_MODDIR_DEFAULT .)
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-f fixed")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-f free")
diff --git a/Modules/Compiler/Embarcadero-DetermineCompiler.cmake b/Modules/Compiler/Embarcadero-DetermineCompiler.cmake
new file mode 100644
index 0000000000..2feedac358
--- /dev/null
+++ b/Modules/Compiler/Embarcadero-DetermineCompiler.cmake
@@ -0,0 +1,7 @@
+
+set(_compiler_id_pp_test "defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)")
+
+set(_compiler_id_version_compute "
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_HEX@(__CODEGEARC_VERSION__>>24 & 0x00FF)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_HEX@(__CODEGEARC_VERSION__>>16 & 0x00FF)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_HEX@(__CODEGEARC_VERSION__ & 0xFFFF)")
diff --git a/Modules/Compiler/Fujitsu-DetermineCompiler.cmake b/Modules/Compiler/Fujitsu-DetermineCompiler.cmake
new file mode 100644
index 0000000000..73ee38c87e
--- /dev/null
+++ b/Modules/Compiler/Fujitsu-DetermineCompiler.cmake
@@ -0,0 +1,2 @@
+
+set(_compiler_id_pp_test "defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version)")
diff --git a/Modules/Compiler/G95-Fortran.cmake b/Modules/Compiler/G95-Fortran.cmake
new file mode 100644
index 0000000000..fd84848b43
--- /dev/null
+++ b/Modules/Compiler/G95-Fortran.cmake
@@ -0,0 +1,9 @@
+set(CMAKE_Fortran_FLAGS_INIT "")
+set(CMAKE_Fortran_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "-Os")
+set(CMAKE_Fortran_FLAGS_RELEASE_INIT "-O3")
+set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
+set(CMAKE_Fortran_MODDIR_FLAG "-fmod=")
+set(CMAKE_Fortran_VERBOSE_FLAG "-v")
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form")
diff --git a/Modules/Compiler/GNU-ASM.cmake b/Modules/Compiler/GNU-ASM.cmake
new file mode 100644
index 0000000000..e07401d54f
--- /dev/null
+++ b/Modules/Compiler/GNU-ASM.cmake
@@ -0,0 +1,6 @@
+# This file is loaded when gcc/g++ is used for assembler files (the "ASM" cmake language)
+include(Compiler/GNU)
+
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;S;asm)
+
+__compiler_gnu(ASM)
diff --git a/Modules/Compiler/GNU-C-FeatureTests.cmake b/Modules/Compiler/GNU-C-FeatureTests.cmake
new file mode 100644
index 0000000000..dc1695c791
--- /dev/null
+++ b/Modules/Compiler/GNU-C-FeatureTests.cmake
@@ -0,0 +1,12 @@
+
+set(_cmake_oldestSupported "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407")
+
+set(GNU46_C11 "${_cmake_oldestSupported} && __STDC_VERSION__ >= 201112L")
+set(_cmake_feature_test_c_static_assert "${GNU46_C11}")
+# Since 4.4 at least:
+set(GNU44_C99 "${_cmake_oldestSupported} && __STDC_VERSION__ >= 199901L")
+set(_cmake_feature_test_c_restrict "${GNU44_C99}")
+set(_cmake_feature_test_c_variadic_macros "${GNU44_C99}")
+
+set(GNU_C90 "${_cmake_oldestSupported} && !defined(__STDC_VERSION__)")
+set(_cmake_feature_test_c_function_prototypes "${GNU_C90}")
diff --git a/Modules/Compiler/GNU-C.cmake b/Modules/Compiler/GNU-C.cmake
new file mode 100644
index 0000000000..35954be525
--- /dev/null
+++ b/Modules/Compiler/GNU-C.cmake
@@ -0,0 +1,34 @@
+include(Compiler/GNU)
+__compiler_gnu(C)
+
+if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.7)
+ set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90")
+ set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90")
+
+ set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
+ set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99")
+
+ set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
+ set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
+endif()
+
+# This may change in a future GNU version.
+set(CMAKE_C_STANDARD_DEFAULT 90)
+
+macro(cmake_record_c_compile_features)
+ macro(_get_gcc_features std_version list)
+ record_compiler_features(C "-std=${std_version}" ${list})
+ endmacro()
+
+ if (UNIX AND NOT APPLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.7)
+ _get_gcc_features(c90 CMAKE_C90_COMPILE_FEATURES)
+ if (_result EQUAL 0)
+ _get_gcc_features(c99 CMAKE_C99_COMPILE_FEATURES)
+ endif()
+ if (_result EQUAL 0)
+ _get_gcc_features(c11 CMAKE_C11_COMPILE_FEATURES)
+ endif()
+ else()
+ set(_result 0)
+ endif()
+endmacro()
diff --git a/Modules/Compiler/GNU-CXX-FeatureTests.cmake b/Modules/Compiler/GNU-CXX-FeatureTests.cmake
new file mode 100644
index 0000000000..9c98e4476b
--- /dev/null
+++ b/Modules/Compiler/GNU-CXX-FeatureTests.cmake
@@ -0,0 +1,98 @@
+
+# Reference: http://gcc.gnu.org/projects/cxx0x.html
+
+set(_cmake_oldestSupported "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407")
+
+set(GNU49_CXX14 "(__GNUC__ * 100 + __GNUC_MINOR__) >= 409 && __cplusplus > 201103L")
+set(_cmake_feature_test_cxx_contextual_conversions "${GNU49_CXX14}")
+set(_cmake_feature_test_cxx_attribute_deprecated "${GNU49_CXX14}")
+set(_cmake_feature_test_cxx_decltype_auto "${GNU49_CXX14}")
+set(_cmake_feature_test_cxx_digit_separators "${GNU49_CXX14}")
+set(_cmake_feature_test_cxx_generic_lambdas "${GNU49_CXX14}")
+set(_cmake_feature_test_cxx_lambda_init_captures "${GNU49_CXX14}")
+# GNU 4.3 supports binary literals as an extension, but may warn about
+# use of extensions prior to GNU 4.9
+# http://stackoverflow.com/questions/16334024/difference-between-gcc-binary-literals-and-c14-ones
+set(_cmake_feature_test_cxx_binary_literals "${GNU49_CXX14}")
+# The feature below is documented as available in GNU 4.8 (by implementing an
+# earlier draft of the standard paper), but that version of the compiler
+# does not set __cplusplus to a value greater than 201103L until GNU 4.9:
+# http://gcc.gnu.org/onlinedocs/gcc-4.8.2/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros
+# http://gcc.gnu.org/onlinedocs/gcc-4.9.0/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros
+# So, CMake only reports availability for it with GNU 4.9 or later.
+set(_cmake_feature_test_cxx_return_type_deduction "${GNU49_CXX14}")
+
+# Introduced in GCC 4.8.1
+set(GNU481_CXX11 "((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40801) && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_decltype_incomplete_return_types "${GNU481_CXX11}")
+set(_cmake_feature_test_cxx_reference_qualified_functions "${GNU481_CXX11}")
+set(GNU48_CXX11 "(__GNUC__ * 100 + __GNUC_MINOR__) >= 408 && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_alignas "${GNU48_CXX11}")
+# The alignof feature works with GNU 4.7 and -std=c++11, but it is documented
+# as available with GNU 4.8, so treat that as true.
+set(_cmake_feature_test_cxx_alignof "${GNU48_CXX11}")
+set(_cmake_feature_test_cxx_attributes "${GNU48_CXX11}")
+set(_cmake_feature_test_cxx_inheriting_constructors "${GNU48_CXX11}")
+set(_cmake_feature_test_cxx_thread_local "${GNU48_CXX11}")
+set(GNU47_CXX11 "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_alias_templates "${GNU47_CXX11}")
+set(_cmake_feature_test_cxx_delegating_constructors "${GNU47_CXX11}")
+set(_cmake_feature_test_cxx_extended_friend_declarations "${GNU47_CXX11}")
+set(_cmake_feature_test_cxx_final "${GNU47_CXX11}")
+set(_cmake_feature_test_cxx_noexcept "${GNU47_CXX11}")
+set(_cmake_feature_test_cxx_nonstatic_member_init "${GNU47_CXX11}")
+set(_cmake_feature_test_cxx_override "${GNU47_CXX11}")
+set(_cmake_feature_test_cxx_user_literals "${GNU47_CXX11}")
+# NOTE: C++11 was ratified in September 2011. GNU 4.7 is the first minor
+# release following that (March 2012), and the first minor release to
+# support -std=c++11. Prior to that, support for C++11 features is technically
+# experiemental and possibly incomplete (see for example the note below about
+# cxx_variadic_template_template_parameters)
+# TODO: Should be supported by GNU 4.6
+set(GNU46_CXX11 "${_cmake_oldestSupported} && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_constexpr "${GNU46_CXX11}")
+set(_cmake_feature_test_cxx_defaulted_move_initializers "${GNU46_CXX11}")
+set(_cmake_feature_test_cxx_enum_forward_declarations "${GNU46_CXX11}")
+set(_cmake_feature_test_cxx_nullptr "${GNU46_CXX11}")
+set(_cmake_feature_test_cxx_range_for "${GNU46_CXX11}")
+set(_cmake_feature_test_cxx_unrestricted_unions "${GNU46_CXX11}")
+# TODO: Should be supported by GNU 4.5
+set(GNU45_CXX11 "${_cmake_oldestSupported} && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_explicit_conversions "${GNU45_CXX11}")
+set(_cmake_feature_test_cxx_lambdas "${GNU45_CXX11}")
+set(_cmake_feature_test_cxx_local_type_template_args "${GNU45_CXX11}")
+set(_cmake_feature_test_cxx_raw_string_literals "${GNU45_CXX11}")
+# TODO: Should be supported by GNU 4.4
+set(GNU44_CXX11 "${_cmake_oldestSupported} && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_auto_type "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_defaulted_functions "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_deleted_functions "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_generalized_initializers "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_inline_namespaces "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_sizeof_member "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_strong_enums "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_trailing_return_types "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_unicode_literals "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_uniform_initialization "${GNU44_CXX11}")
+set(_cmake_feature_test_cxx_variadic_templates "${GNU44_CXX11}")
+# TODO: If features are ever recorded for GNU 4.3, there should possibly
+# be a new feature added like cxx_variadic_template_template_parameters,
+# which is implemented by GNU 4.4, but not 4.3. cxx_variadic_templates is
+# actually implemented by GNU 4.3, but variadic template template parameters
+# 'completes' it, so that is the version we record as having the variadic
+# templates capability in CMake. See
+# http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2555.pdf
+# TODO: Should be supported by GNU 4.3
+set(GNU43_CXX11 "${_cmake_oldestSupported} && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_decltype "${GNU43_CXX11}")
+set(_cmake_feature_test_cxx_default_function_template_args "${GNU43_CXX11}")
+set(_cmake_feature_test_cxx_long_long_type "${GNU43_CXX11}")
+set(_cmake_feature_test_cxx_right_angle_brackets "${GNU43_CXX11}")
+set(_cmake_feature_test_cxx_rvalue_references "${GNU43_CXX11}")
+set(_cmake_feature_test_cxx_static_assert "${GNU43_CXX11}")
+# TODO: Should be supported since GNU 3.4?
+set(_cmake_feature_test_cxx_extern_templates "${_cmake_oldestSupported} && __cplusplus >= 201103L")
+# TODO: Should be supported forever?
+set(_cmake_feature_test_cxx_func_identifier "${_cmake_oldestSupported} && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_variadic_macros "${_cmake_oldestSupported} && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_template_template_parameters "${_cmake_oldestSupported} && __cplusplus >= 199711L")
diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake
new file mode 100644
index 0000000000..14dc76a9a3
--- /dev/null
+++ b/Modules/Compiler/GNU-CXX.cmake
@@ -0,0 +1,53 @@
+include(Compiler/GNU)
+__compiler_gnu(CXX)
+
+if (WIN32)
+ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
+ set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fno-keep-inline-dllexport")
+ endif()
+else()
+ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.2)
+ set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
+ endif()
+endif()
+
+if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
+endif()
+
+if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
+elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
+endif()
+
+if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y")
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y")
+endif()
+
+set(CMAKE_CXX_STANDARD_DEFAULT 98)
+
+macro(cmake_record_cxx_compile_features)
+ macro(_get_gcc_features std_version list)
+ record_compiler_features(CXX "-std=${std_version}" ${list})
+ endmacro()
+
+ set(_result 0)
+ if (UNIX AND NOT APPLE AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
+ _get_gcc_features(c++1y CMAKE_CXX14_COMPILE_FEATURES)
+ endif()
+ if (UNIX AND NOT APPLE AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+ if (_result EQUAL 0)
+ _get_gcc_features(c++11 CMAKE_CXX11_COMPILE_FEATURES)
+ endif()
+ if (_result EQUAL 0)
+ _get_gcc_features(c++98 CMAKE_CXX98_COMPILE_FEATURES)
+ endif()
+ else()
+ set(_result 0)
+ endif()
+endmacro()
diff --git a/Modules/Compiler/GNU-DetermineCompiler.cmake b/Modules/Compiler/GNU-DetermineCompiler.cmake
new file mode 100644
index 0000000000..261f148cdf
--- /dev/null
+++ b/Modules/Compiler/GNU-DetermineCompiler.cmake
@@ -0,0 +1,9 @@
+
+set(_compiler_id_pp_test "defined(__GNUC__)")
+
+set(_compiler_id_version_compute "
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__GNUC__)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__GNUC_MINOR__)
+# if defined(__GNUC_PATCHLEVEL__)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__GNUC_PATCHLEVEL__)
+# endif")
diff --git a/Modules/Compiler/GNU-Fortran.cmake b/Modules/Compiler/GNU-Fortran.cmake
new file mode 100644
index 0000000000..313ccbd027
--- /dev/null
+++ b/Modules/Compiler/GNU-Fortran.cmake
@@ -0,0 +1,17 @@
+include(Compiler/GNU)
+__compiler_gnu(Fortran)
+
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form")
+
+# No -DNDEBUG for Fortran.
+set(CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "-Os")
+set(CMAKE_Fortran_FLAGS_RELEASE_INIT "-O3")
+
+# We require updates to CMake C++ code to support preprocessing rules
+# for Fortran.
+set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE)
+set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE)
+
+# Fortran-specific feature flags.
+set(CMAKE_Fortran_MODDIR_FLAG -J)
diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake
new file mode 100644
index 0000000000..f01255cf65
--- /dev/null
+++ b/Modules/Compiler/GNU.cmake
@@ -0,0 +1,58 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__COMPILER_GNU)
+ return()
+endif()
+set(__COMPILER_GNU 1)
+
+macro(__compiler_gnu lang)
+ # Feature flags.
+ set(CMAKE_${lang}_VERBOSE_FLAG "-v")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ endif()
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.2)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
+ endif()
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_SYSROOT "--sysroot=")
+
+ # Older versions of gcc (< 4.5) contain a bug causing them to report a missing
+ # header file as a warning if depfiles are enabled, causing check_header_file
+ # tests to always succeed. Work around this by disabling dependency tracking
+ # in try_compile mode.
+ get_property(_IN_TC GLOBAL PROPERTY IN_TRY_COMPILE)
+ if(NOT _IN_TC OR CMAKE_FORCE_DEPFILES)
+ # distcc does not transform -o to -MT when invoking the preprocessor
+ # internally, as it ought to. Work around this bug by setting -MT here
+ # even though it isn't strictly necessary.
+ set(CMAKE_DEPFILE_FLAGS_${lang} "-MMD -MT <OBJECT> -MF <DEPFILE>")
+ endif()
+
+ # Initial configuration flags.
+ set(CMAKE_${lang}_FLAGS_INIT "")
+ set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-g")
+ set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
+ set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
+ set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG")
+ set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+ set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+ if(NOT APPLE)
+ set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
+ endif()
+endmacro()
diff --git a/Modules/Compiler/HP-ASM.cmake b/Modules/Compiler/HP-ASM.cmake
new file mode 100644
index 0000000000..b60f207b4b
--- /dev/null
+++ b/Modules/Compiler/HP-ASM.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_ASM_VERBOSE_FLAG "-v")
+
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s )
diff --git a/Modules/Compiler/HP-C-DetermineCompiler.cmake b/Modules/Compiler/HP-C-DetermineCompiler.cmake
new file mode 100644
index 0000000000..4269799908
--- /dev/null
+++ b/Modules/Compiler/HP-C-DetermineCompiler.cmake
@@ -0,0 +1,8 @@
+
+set(_compiler_id_pp_test "defined(__HP_cc)")
+
+set(_compiler_id_version_compute "
+ /* __HP_cc = VVRRPP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__HP_cc/10000)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__HP_cc/100 % 100)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__HP_cc % 100)")
diff --git a/Modules/Compiler/HP-C.cmake b/Modules/Compiler/HP-C.cmake
new file mode 100644
index 0000000000..6dddcbae12
--- /dev/null
+++ b/Modules/Compiler/HP-C.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_C_VERBOSE_FLAG "-v")
+
+set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
diff --git a/Modules/Compiler/HP-CXX-DetermineCompiler.cmake b/Modules/Compiler/HP-CXX-DetermineCompiler.cmake
new file mode 100644
index 0000000000..3d4d7e4944
--- /dev/null
+++ b/Modules/Compiler/HP-CXX-DetermineCompiler.cmake
@@ -0,0 +1,8 @@
+
+set(_compiler_id_pp_test "defined(__HP_aCC)")
+
+set(_compiler_id_version_compute "
+ /* __HP_aCC = VVRRPP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__HP_aCC/10000)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__HP_aCC/100 % 100)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__HP_aCC % 100)")
diff --git a/Modules/Compiler/HP-CXX.cmake b/Modules/Compiler/HP-CXX.cmake
new file mode 100644
index 0000000000..6411dac6bb
--- /dev/null
+++ b/Modules/Compiler/HP-CXX.cmake
@@ -0,0 +1,13 @@
+set(CMAKE_CXX_VERBOSE_FLAG "-v")
+
+set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+
+# HP aCC since version 3.80 supports the flag +hpxstd98 to get ANSI C++98
+# template support. It is known that version 6.25 doesn't need that flag.
+# Current assumption: the flag is needed for every version from 3.80 to 4
+# to get it working.
+if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4 AND
+ NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.80)
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "+hpxstd98")
+endif()
diff --git a/Modules/Compiler/HP-Fortran.cmake b/Modules/Compiler/HP-Fortran.cmake
new file mode 100644
index 0000000000..cc56b46114
--- /dev/null
+++ b/Modules/Compiler/HP-Fortran.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_Fortran_VERBOSE_FLAG "-v")
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "+source=fixed")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "+source=free")
diff --git a/Modules/Compiler/IAR-ASM.cmake b/Modules/Compiler/IAR-ASM.cmake
new file mode 100644
index 0000000000..66fb052df2
--- /dev/null
+++ b/Modules/Compiler/IAR-ASM.cmake
@@ -0,0 +1,14 @@
+# This file is processed when the IAR compiler is used for an assembler file
+
+include(Compiler/IAR)
+
+set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <SOURCE> <DEFINES> <FLAGS> -o <OBJECT>")
+
+if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "ARM")
+ set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa)
+endif()
+
+
+if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR")
+ set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s90;asm;msa)
+endif()
diff --git a/Modules/Compiler/IAR-C.cmake b/Modules/Compiler/IAR-C.cmake
new file mode 100644
index 0000000000..da29447c4c
--- /dev/null
+++ b/Modules/Compiler/IAR-C.cmake
@@ -0,0 +1,34 @@
+# This file is processed when the IAR compiler is used for a C file
+
+
+include(Compiler/IAR)
+
+set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <FLAGS> -o <OBJECT>")
+set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>")
+set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy")
+
+# The toolchains for ARM and AVR are quite different:
+if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "ARM")
+
+ set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
+ set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> <TARGET> --create <LINK_FLAGS> <OBJECTS> ")
+
+endif()
+
+
+if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR")
+ set(CMAKE_C_OUTPUT_EXTENSION ".r90")
+
+ if(NOT CMAKE_C_LINK_FLAGS)
+ set(CMAKE_C_LINK_FLAGS "-Fmotorola")
+ endif()
+
+ set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
+ set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> -o <TARGET> <OBJECTS> ")
+
+endif()
+
+# add the target specific include directory:
+get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH)
+get_filename_component(_compilerDir "${_compilerDir}" PATH)
+include_directories("${_compilerDir}/inc" )
diff --git a/Modules/Compiler/IAR-CXX.cmake b/Modules/Compiler/IAR-CXX.cmake
new file mode 100644
index 0000000000..eae9d1b774
--- /dev/null
+++ b/Modules/Compiler/IAR-CXX.cmake
@@ -0,0 +1,34 @@
+# This file is processed when the IAR compiler is used for a C++ file
+
+include(Compiler/IAR)
+
+set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <SOURCE> <DEFINES> <FLAGS> -o <OBJECT>")
+
+set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <SOURCE> <DEFINES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>")
+set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <SOURCE> <DEFINES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy")
+
+
+
+if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "ARM")
+
+ set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
+ set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> <TARGET> --create <LINK_FLAGS> <OBJECTS> ")
+
+endif()
+
+
+if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR")
+ set(CMAKE_CXX_OUTPUT_EXTENSION ".r90")
+ if(NOT CMAKE_CXX_LINK_FLAGS)
+ set(CMAKE_CXX_LINK_FLAGS "-Fmotorola")
+ endif()
+
+ set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
+ set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> -o <TARGET> <OBJECTS> ")
+
+endif()
+
+# add the target specific include directory:
+get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH)
+get_filename_component(_compilerDir "${_compilerDir}" PATH)
+include_directories("${_compilerDir}/inc")
diff --git a/Modules/Compiler/IAR-DetermineCompiler.cmake b/Modules/Compiler/IAR-DetermineCompiler.cmake
new file mode 100644
index 0000000000..c39810a240
--- /dev/null
+++ b/Modules/Compiler/IAR-DetermineCompiler.cmake
@@ -0,0 +1,4 @@
+
+# IAR Systems compiler for embedded systems.
+# http://www.iar.com
+set(_compiler_id_pp_test "defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC)")
diff --git a/Modules/Compiler/IAR.cmake b/Modules/Compiler/IAR.cmake
new file mode 100644
index 0000000000..00e47133cd
--- /dev/null
+++ b/Modules/Compiler/IAR.cmake
@@ -0,0 +1,46 @@
+# This file is processed when the IAR compiler is used for a C or C++ file
+# Documentation can be downloaded here: http://www.iar.com/website1/1.0.1.0/675/1/
+# The initial feature request is here: http://www.cmake.org/Bug/view.php?id=10176
+# It also contains additional links and information.
+
+if(_IAR_CMAKE_LOADED)
+ return()
+endif()
+set(_IAR_CMAKE_LOADED TRUE)
+
+
+get_filename_component(_CMAKE_C_TOOLCHAIN_LOCATION "${CMAKE_C_COMPILER}" PATH)
+get_filename_component(_CMAKE_CXX_TOOLCHAIN_LOCATION "${CMAKE_CXX_COMPILER}" PATH)
+get_filename_component(_CMAKE_ASM_TOOLCHAIN_LOCATION "${CMAKE_ASM_COMPILER}" PATH)
+
+
+if("${CMAKE_C_COMPILER}" MATCHES "arm" OR "${CMAKE_CXX_COMPILER}" MATCHES "arm" OR "${CMAKE_ASM_COMPILER}" MATCHES "arm")
+ set(CMAKE_EXECUTABLE_SUFFIX ".elf")
+
+ # For arm, IAR uses the "ilinkarm" linker and "iarchive" archiver:
+ find_program(CMAKE_IAR_LINKER ilinkarm HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" "${_CMAKE_ASM_TOOLCHAIN_LOCATION}")
+ find_program(CMAKE_IAR_AR iarchive HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" "${_CMAKE_ASM_TOOLCHAIN_LOCATION}" )
+
+ set(IAR_TARGET_ARCHITECTURE "ARM" CACHE STRING "IAR compiler target architecture")
+endif()
+
+if("${CMAKE_C_COMPILER}" MATCHES "avr" OR "${CMAKE_CXX_COMPILER}" MATCHES "avr" OR "${CMAKE_ASM_COMPILER}" MATCHES "avr")
+ set(CMAKE_EXECUTABLE_SUFFIX ".bin")
+
+ # For AVR and AVR32, IAR uses the "xlink" linker and the "xar" archiver:
+ find_program(CMAKE_IAR_LINKER xlink HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" "${_CMAKE_ASM_TOOLCHAIN_LOCATION}" )
+ find_program(CMAKE_IAR_AR xar HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" "${_CMAKE_ASM_TOOLCHAIN_LOCATION}" )
+
+ set(IAR_TARGET_ARCHITECTURE "AVR" CACHE STRING "IAR compiler target architecture")
+
+ set(CMAKE_LIBRARY_PATH_FLAG "-I")
+
+endif()
+
+if(NOT IAR_TARGET_ARCHITECTURE)
+ message(FATAL_ERROR "The IAR compiler for this architecture is not yet supported "
+ " by CMake. Please go to http://www.cmake.org/Bug and enter a feature request there.")
+endif()
+
+set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE)
+set(CMAKE_AR "${CMAKE_IAR_AR}" CACHE FILEPATH "The IAR archiver" FORCE)
diff --git a/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake b/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake
new file mode 100644
index 0000000000..899e284add
--- /dev/null
+++ b/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake
@@ -0,0 +1,6 @@
+
+set(_compiler_id_version_compute "
+ /* __IBMC__ = VRP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__IBMC__/100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__IBMC__/10 % 10)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__IBMC__ % 10)")
diff --git a/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake b/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake
new file mode 100644
index 0000000000..73aa2b4f93
--- /dev/null
+++ b/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake
@@ -0,0 +1,6 @@
+
+set(_compiler_id_version_compute "
+ /* __IBMCPP__ = VRP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__IBMCPP__/100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__IBMCPP__/10 % 10)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__IBMCPP__ % 10)")
diff --git a/Modules/Compiler/Intel-ASM.cmake b/Modules/Compiler/Intel-ASM.cmake
new file mode 100644
index 0000000000..74ceb0a6a6
--- /dev/null
+++ b/Modules/Compiler/Intel-ASM.cmake
@@ -0,0 +1,13 @@
+set(CMAKE_ASM_VERBOSE_FLAG "-v")
+
+set(CMAKE_ASM_FLAGS_INIT "")
+set(CMAKE_ASM_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_ASM_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
+set(CMAKE_ASM_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
+set(CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG")
+
+if(UNIX)
+ set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;S)
+else()
+ set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS asm)
+endif()
diff --git a/Modules/Compiler/Intel-C.cmake b/Modules/Compiler/Intel-C.cmake
new file mode 100644
index 0000000000..1d651e368d
--- /dev/null
+++ b/Modules/Compiler/Intel-C.cmake
@@ -0,0 +1,12 @@
+set(CMAKE_C_VERBOSE_FLAG "-v")
+
+set(CMAKE_C_FLAGS_INIT "")
+set(CMAKE_C_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
+set(CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG")
+
+set(CMAKE_DEPFILE_FLAGS_C "-MMD -MT <OBJECT> -MF <DEPFILE>")
+
+set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
diff --git a/Modules/Compiler/Intel-CXX.cmake b/Modules/Compiler/Intel-CXX.cmake
new file mode 100644
index 0000000000..020e862c69
--- /dev/null
+++ b/Modules/Compiler/Intel-CXX.cmake
@@ -0,0 +1,12 @@
+set(CMAKE_CXX_VERBOSE_FLAG "-v")
+
+set(CMAKE_CXX_FLAGS_INIT "")
+set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
+set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG")
+
+set(CMAKE_DEPFILE_FLAGS_CXX "-MMD -MT <OBJECT> -MF <DEPFILE>")
+
+set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
diff --git a/Modules/Compiler/Intel-DetermineCompiler.cmake b/Modules/Compiler/Intel-DetermineCompiler.cmake
new file mode 100644
index 0000000000..d7e453211b
--- /dev/null
+++ b/Modules/Compiler/Intel-DetermineCompiler.cmake
@@ -0,0 +1,26 @@
+
+set(_compiler_id_pp_test "defined(__INTEL_COMPILER) || defined(__ICC)")
+
+set(_compiler_id_version_compute "
+ /* __INTEL_COMPILER = VRP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__INTEL_COMPILER/100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__INTEL_COMPILER/10 % 10)
+# if defined(__INTEL_COMPILER_UPDATE)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__INTEL_COMPILER_UPDATE)
+# else
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__INTEL_COMPILER % 10)
+# endif
+# if defined(__INTEL_COMPILER_BUILD_DATE)
+ /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */
+# define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(__INTEL_COMPILER_BUILD_DATE)
+# endif
+# if defined(_MSC_VER)
+ /* _MSC_VER = VVRR */
+# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(_MSC_VER / 100)
+# define @PREFIX@SIMULATE_VERSION_MINOR @MACRO_DEC@(_MSC_VER % 100)
+# endif")
+
+set(_compiler_id_simulate "
+# if defined(_MSC_VER)
+# define @PREFIX@SIMULATE_ID \"MSVC\"
+# endif")
diff --git a/Modules/Compiler/Intel-Fortran.cmake b/Modules/Compiler/Intel-Fortran.cmake
new file mode 100644
index 0000000000..84f6182a72
--- /dev/null
+++ b/Modules/Compiler/Intel-Fortran.cmake
@@ -0,0 +1,9 @@
+set(CMAKE_Fortran_FLAGS_INIT "")
+set(CMAKE_Fortran_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "-Os")
+set(CMAKE_Fortran_FLAGS_RELEASE_INIT "-O3")
+set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
+set(CMAKE_Fortran_MODDIR_FLAG "-module ")
+set(CMAKE_Fortran_VERBOSE_FLAG "-v")
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
diff --git a/Modules/Compiler/MIPSpro-C.cmake b/Modules/Compiler/MIPSpro-C.cmake
new file mode 100644
index 0000000000..675560c2a4
--- /dev/null
+++ b/Modules/Compiler/MIPSpro-C.cmake
@@ -0,0 +1 @@
+set(CMAKE_C_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/MIPSpro-CXX.cmake b/Modules/Compiler/MIPSpro-CXX.cmake
new file mode 100644
index 0000000000..9fb191c754
--- /dev/null
+++ b/Modules/Compiler/MIPSpro-CXX.cmake
@@ -0,0 +1 @@
+set(CMAKE_CXX_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/MIPSpro-DetermineCompiler.cmake b/Modules/Compiler/MIPSpro-DetermineCompiler.cmake
new file mode 100644
index 0000000000..9e485532b0
--- /dev/null
+++ b/Modules/Compiler/MIPSpro-DetermineCompiler.cmake
@@ -0,0 +1,15 @@
+
+set(_compiler_id_pp_test "defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION)")
+
+set(_compiler_id_version_compute "
+# if defined(_SGI_COMPILER_VERSION)
+ /* _SGI_COMPILER_VERSION = VRP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(_SGI_COMPILER_VERSION/100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(_SGI_COMPILER_VERSION/10 % 10)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(_SGI_COMPILER_VERSION % 10)
+# else
+ /* _COMPILER_VERSION = VRP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(_COMPILER_VERSION/100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(_COMPILER_VERSION/10 % 10)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(_COMPILER_VERSION % 10)
+# endif")
diff --git a/Modules/Compiler/MIPSpro-Fortran.cmake b/Modules/Compiler/MIPSpro-Fortran.cmake
new file mode 100644
index 0000000000..ffceea80de
--- /dev/null
+++ b/Modules/Compiler/MIPSpro-Fortran.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_Fortran_VERBOSE_FLAG "-v")
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixedform")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-freeform")
diff --git a/Modules/Compiler/MSVC-DetermineCompiler.cmake b/Modules/Compiler/MSVC-DetermineCompiler.cmake
new file mode 100644
index 0000000000..313de89fa0
--- /dev/null
+++ b/Modules/Compiler/MSVC-DetermineCompiler.cmake
@@ -0,0 +1,19 @@
+
+set(_compiler_id_pp_test "defined(_MSC_VER)")
+
+set(_compiler_id_version_compute "
+ /* _MSC_VER = VVRR */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(_MSC_VER / 100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(_MSC_VER % 100)
+# if defined(_MSC_FULL_VER)
+# if _MSC_VER >= 1400
+ /* _MSC_FULL_VER = VVRRPPPPP */
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(_MSC_FULL_VER % 100000)
+# else
+ /* _MSC_FULL_VER = VVRRPPPP */
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(_MSC_FULL_VER % 10000)
+# endif
+# endif
+# if defined(_MSC_BUILD)
+# define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(_MSC_BUILD)
+# endif")
diff --git a/Modules/Compiler/NAG-Fortran.cmake b/Modules/Compiler/NAG-Fortran.cmake
new file mode 100644
index 0000000000..18f141ed38
--- /dev/null
+++ b/Modules/Compiler/NAG-Fortran.cmake
@@ -0,0 +1,35 @@
+# Help CMAKE_PARSE_IMPLICIT_LINK_INFO detect NAG Fortran object files.
+if(NOT CMAKE_Fortran_COMPILER_WORKS AND NOT CMAKE_Fortran_COMPILER_FORCED)
+ message(STATUS "Detecting NAG Fortran directory")
+ # Run with -dryrun to see sample "link" line.
+ execute_process(
+ COMMAND ${CMAKE_Fortran_COMPILER} dummy.o -dryrun
+ OUTPUT_VARIABLE _dryrun
+ ERROR_VARIABLE _dryrun
+ )
+ # Match an object file.
+ string(REGEX MATCH "/[^ ]*/[^ /][^ /]*\\.o" _nag_obj "${_dryrun}")
+ if(_nag_obj)
+ # Parse object directory and convert to a regex.
+ string(REGEX REPLACE "/[^/]*$" "" _nag_dir "${_nag_obj}")
+ string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" _nag_regex "${_nag_dir}")
+ set(CMAKE_Fortran_IMPLICIT_OBJECT_REGEX "^${_nag_regex}/")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Detecting NAG Fortran directory with -dryrun found\n"
+ " object: ${_nag_obj}\n"
+ " directory: ${_nag_dir}\n"
+ " regex: ${CMAKE_Fortran_IMPLICIT_OBJECT_REGEX}\n"
+ "from output:\n${_dryrun}\n\n")
+ message(STATUS "Detecting NAG Fortran directory - ${_nag_dir}")
+ else()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Detecting NAG Fortran directory with -dryrun failed:\n${_dryrun}\n\n")
+ message(STATUS "Detecting NAG Fortran directory - failed")
+ endif()
+endif()
+
+set(CMAKE_Fortran_MODDIR_FLAG "-mdir ")
+set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS "-PIC")
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
+set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-PIC")
diff --git a/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake b/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake
new file mode 100644
index 0000000000..2ed116c092
--- /dev/null
+++ b/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake
@@ -0,0 +1,10 @@
+
+set(_compiler_id_pp_test "defined(__WATCOMC__)")
+
+set(_compiler_id_version_compute "
+ /* __WATCOMC__ = VVRP + 1100 */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@((__WATCOMC__ - 1100) / 100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@((__WATCOMC__ / 10) % 10)
+# if (__WATCOMC__ % 10) > 0
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__WATCOMC__ % 10)
+# endif")
diff --git a/Modules/Compiler/PGI-C.cmake b/Modules/Compiler/PGI-C.cmake
new file mode 100644
index 0000000000..da88c01164
--- /dev/null
+++ b/Modules/Compiler/PGI-C.cmake
@@ -0,0 +1,4 @@
+include(Compiler/PGI)
+__compiler_pgi(C)
+set(CMAKE_C_FLAGS_MINSIZEREL_INIT "${CMAKE_C_FLAGS_MINSIZEREL_INIT} -DNDEBUG")
+set(CMAKE_C_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT} -DNDEBUG")
diff --git a/Modules/Compiler/PGI-CXX.cmake b/Modules/Compiler/PGI-CXX.cmake
new file mode 100644
index 0000000000..97c9555b10
--- /dev/null
+++ b/Modules/Compiler/PGI-CXX.cmake
@@ -0,0 +1,4 @@
+include(Compiler/PGI)
+__compiler_pgi(CXX)
+set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT} -DNDEBUG")
+set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_CXX_FLAGS_RELEASE_INIT} -DNDEBUG")
diff --git a/Modules/Compiler/PGI-DetermineCompiler.cmake b/Modules/Compiler/PGI-DetermineCompiler.cmake
new file mode 100644
index 0000000000..8d3dc9ca64
--- /dev/null
+++ b/Modules/Compiler/PGI-DetermineCompiler.cmake
@@ -0,0 +1,9 @@
+
+set(_compiler_id_pp_test "defined(__PGI)")
+
+set(_compiler_id_version_compute "
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__PGIC__)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__PGIC_MINOR__)
+# if defined(__PGIC_PATCHLEVEL__)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__PGIC_PATCHLEVEL__)
+# endif")
diff --git a/Modules/Compiler/PGI-Fortran.cmake b/Modules/Compiler/PGI-Fortran.cmake
new file mode 100644
index 0000000000..264c23e74c
--- /dev/null
+++ b/Modules/Compiler/PGI-Fortran.cmake
@@ -0,0 +1,15 @@
+include(Compiler/PGI)
+__compiler_pgi(Fortran)
+
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-Mnofreeform")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-Mfreeform")
+
+set(CMAKE_Fortran_FLAGS_INIT "${CMAKE_Fortran_FLAGS_INIT} -Mpreprocess -Kieee")
+set(CMAKE_Fortran_FLAGS_DEBUG_INIT "${CMAKE_Fortran_FLAGS_DEBUG_INIT} -Mbounds")
+
+# We require updates to CMake C++ code to support preprocessing rules
+# for Fortran.
+set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE)
+set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE)
+
+set(CMAKE_Fortran_MODDIR_FLAG "-module ")
diff --git a/Modules/Compiler/PGI.cmake b/Modules/Compiler/PGI.cmake
new file mode 100644
index 0000000000..162e3c9b80
--- /dev/null
+++ b/Modules/Compiler/PGI.cmake
@@ -0,0 +1,35 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__COMPILER_PGI)
+ return()
+endif()
+set(__COMPILER_PGI 1)
+
+macro(__compiler_pgi lang)
+ # Feature flags.
+ set(CMAKE_${lang}_VERBOSE_FLAG "-v")
+
+ # Initial configuration flags.
+ set(CMAKE_${lang}_FLAGS_INIT "")
+ set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-g -O0")
+ set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-O2 -s")
+ set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-fast -O3 -Mipa=fast")
+ set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-O2 -gopt")
+
+ # Preprocessing and assembly rules.
+ set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+ set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+endmacro()
diff --git a/Modules/Compiler/PathScale-C.cmake b/Modules/Compiler/PathScale-C.cmake
new file mode 100644
index 0000000000..9db54afa06
--- /dev/null
+++ b/Modules/Compiler/PathScale-C.cmake
@@ -0,0 +1,4 @@
+include(Compiler/PathScale)
+__compiler_pathscale(C)
+set(CMAKE_C_FLAGS_MINSIZEREL_INIT "${CMAKE_C_FLAGS_MINSIZEREL_INIT} -DNDEBUG")
+set(CMAKE_C_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT} -DNDEBUG")
diff --git a/Modules/Compiler/PathScale-CXX.cmake b/Modules/Compiler/PathScale-CXX.cmake
new file mode 100644
index 0000000000..4dd766048e
--- /dev/null
+++ b/Modules/Compiler/PathScale-CXX.cmake
@@ -0,0 +1,4 @@
+include(Compiler/PathScale)
+__compiler_pathscale(CXX)
+set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT} -DNDEBUG")
+set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_CXX_FLAGS_RELEASE_INIT} -DNDEBUG")
diff --git a/Modules/Compiler/PathScale-DetermineCompiler.cmake b/Modules/Compiler/PathScale-DetermineCompiler.cmake
new file mode 100644
index 0000000000..4eb81dec73
--- /dev/null
+++ b/Modules/Compiler/PathScale-DetermineCompiler.cmake
@@ -0,0 +1,9 @@
+
+set(_compiler_id_pp_test "defined(__PATHCC__)")
+
+set(_compiler_id_version_compute "
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__PATHCC__)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__PATHCC_MINOR__)
+# if defined(__PATHCC_PATCHLEVEL__)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__PATHCC_PATCHLEVEL__)
+# endif")
diff --git a/Modules/Compiler/PathScale-Fortran.cmake b/Modules/Compiler/PathScale-Fortran.cmake
new file mode 100644
index 0000000000..d903621046
--- /dev/null
+++ b/Modules/Compiler/PathScale-Fortran.cmake
@@ -0,0 +1,6 @@
+include(Compiler/PathScale)
+__compiler_pathscale(Fortran)
+
+set(CMAKE_Fortran_MODDIR_FLAG "-module ")
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixedform")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-freeform")
diff --git a/Modules/Compiler/PathScale.cmake b/Modules/Compiler/PathScale.cmake
new file mode 100644
index 0000000000..107f779a92
--- /dev/null
+++ b/Modules/Compiler/PathScale.cmake
@@ -0,0 +1,31 @@
+
+#=============================================================================
+# Copyright 2002-2010 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 module is shared by multiple languages; use include blocker.
+if(__COMPILER_PATHSCALE)
+ return()
+endif()
+set(__COMPILER_PATHSCALE 1)
+
+macro(__compiler_pathscale lang)
+ # Feature flags.
+ set(CMAKE_${lang}_VERBOSE_FLAG "-v")
+
+ # Initial configuration flags.
+ set(CMAKE_${lang}_FLAGS_INIT "")
+ set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-g -O0")
+ set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-Os")
+ set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-O3")
+ set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-g -O2")
+endmacro()
diff --git a/Modules/Compiler/QCC-C.cmake b/Modules/Compiler/QCC-C.cmake
new file mode 100644
index 0000000000..ae4a2f491d
--- /dev/null
+++ b/Modules/Compiler/QCC-C.cmake
@@ -0,0 +1,2 @@
+include(Compiler/QCC)
+__compiler_qcc(C)
diff --git a/Modules/Compiler/QCC-CXX.cmake b/Modules/Compiler/QCC-CXX.cmake
new file mode 100644
index 0000000000..a676bbedbc
--- /dev/null
+++ b/Modules/Compiler/QCC-CXX.cmake
@@ -0,0 +1,12 @@
+include(Compiler/QCC)
+__compiler_qcc(CXX)
+
+# If the toolchain uses qcc for CMAKE_CXX_COMPILER instead of QCC, the
+# default for the driver is not c++.
+set(CMAKE_CXX_COMPILE_OBJECT
+ "<CMAKE_CXX_COMPILER> -lang-c++ <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+
+set(CMAKE_CXX_LINK_EXECUTABLE
+ "<CMAKE_CXX_COMPILER> -lang-c++ <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+
+set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
diff --git a/Modules/Compiler/QCC.cmake b/Modules/Compiler/QCC.cmake
new file mode 100644
index 0000000000..76477e4bba
--- /dev/null
+++ b/Modules/Compiler/QCC.cmake
@@ -0,0 +1,24 @@
+
+#=============================================================================
+# Copyright 2002-2014 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.)
+include(Compiler/GNU)
+
+macro(__compiler_qcc lang)
+ __compiler_gnu(${lang})
+
+ # http://www.qnx.com/developers/docs/6.4.0/neutrino/utilities/q/qcc.html#examples
+ set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "-V")
+
+ set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-Wp,-isystem,")
+ set(CMAKE_DEPFILE_FLAGS_${lang} "-Wc,-MMD,<DEPFILE>,-MT,<OBJECT>,-MF,<DEPFILE>")
+endmacro()
diff --git a/Modules/Compiler/SCO-C.cmake b/Modules/Compiler/SCO-C.cmake
new file mode 100644
index 0000000000..6e762ccae8
--- /dev/null
+++ b/Modules/Compiler/SCO-C.cmake
@@ -0,0 +1,2 @@
+include(Compiler/SCO)
+__compiler_sco(C)
diff --git a/Modules/Compiler/SCO-CXX.cmake b/Modules/Compiler/SCO-CXX.cmake
new file mode 100644
index 0000000000..5b713a0df9
--- /dev/null
+++ b/Modules/Compiler/SCO-CXX.cmake
@@ -0,0 +1,2 @@
+include(Compiler/SCO)
+__compiler_sco(CXX)
diff --git a/Modules/Compiler/SCO-DetermineCompiler.cmake b/Modules/Compiler/SCO-DetermineCompiler.cmake
new file mode 100644
index 0000000000..a44b22b71e
--- /dev/null
+++ b/Modules/Compiler/SCO-DetermineCompiler.cmake
@@ -0,0 +1,2 @@
+
+set(_compiler_id_pp_test "defined(__SCO_VERSION__)")
diff --git a/Modules/Compiler/SCO.cmake b/Modules/Compiler/SCO.cmake
new file mode 100644
index 0000000000..f673c8f806
--- /dev/null
+++ b/Modules/Compiler/SCO.cmake
@@ -0,0 +1,28 @@
+
+#=============================================================================
+# Copyright 2002-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# This module is shared by multiple languages; use include blocker.
+if(__COMPILER_SCO)
+ return()
+endif()
+set(__COMPILER_SCO 1)
+
+macro(__compiler_sco lang)
+ # Feature flags.
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC -Kpic)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE -Kpie)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_DLL -belf)
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-Kpic -belf")
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-belf -Wl,-Bexport")
+endmacro()
diff --git a/Modules/Compiler/SDCC-C-DetermineCompiler.cmake b/Modules/Compiler/SDCC-C-DetermineCompiler.cmake
new file mode 100644
index 0000000000..1d7dd78d88
--- /dev/null
+++ b/Modules/Compiler/SDCC-C-DetermineCompiler.cmake
@@ -0,0 +1,10 @@
+
+# sdcc, the small devices C compiler for embedded systems,
+# http://sdcc.sourceforge.net */
+set(_compiler_id_pp_test "defined(SDCC)")
+
+set(_compiler_id_version_compute "
+ /* SDCC = VRP */
+# define COMPILER_VERSION_MAJOR @MACRO_DEC@(SDCC/100)
+# define COMPILER_VERSION_MINOR @MACRO_DEC@(SDCC/10 % 10)
+# define COMPILER_VERSION_PATCH @MACRO_DEC@(SDCC % 10)")
diff --git a/Modules/Compiler/SunPro-ASM.cmake b/Modules/Compiler/SunPro-ASM.cmake
new file mode 100644
index 0000000000..2fa8b99500
--- /dev/null
+++ b/Modules/Compiler/SunPro-ASM.cmake
@@ -0,0 +1,24 @@
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s )
+
+set(CMAKE_ASM_VERBOSE_FLAG "-#")
+
+set(CMAKE_SHARED_LIBRARY_ASM_FLAGS "-KPIC")
+set(CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS "-G")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_ASM_FLAG "-R")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_ASM_FLAG_SEP ":")
+set(CMAKE_SHARED_LIBRARY_SONAME_ASM_FLAG "-h")
+
+set(CMAKE_ASM_FLAGS_INIT "")
+set(CMAKE_ASM_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_ASM_FLAGS_MINSIZEREL_INIT "-xO2 -xspace -DNDEBUG")
+set(CMAKE_ASM_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
+set(CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
+
+# Initialize ASM link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_ASM_FLAGS "-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_ASM_FLAGS "-Bdynamic")
+endforeach()
diff --git a/Modules/Compiler/SunPro-C-DetermineCompiler.cmake b/Modules/Compiler/SunPro-C-DetermineCompiler.cmake
new file mode 100644
index 0000000000..e9d7457e74
--- /dev/null
+++ b/Modules/Compiler/SunPro-C-DetermineCompiler.cmake
@@ -0,0 +1,15 @@
+
+set(_compiler_id_pp_test "defined(__SUNPRO_C)")
+
+set(_compiler_id_version_compute "
+# if __SUNPRO_C >= 0x5100
+ /* __SUNPRO_C = 0xVRRP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_HEX@(__SUNPRO_C>>12)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_HEX@(__SUNPRO_C>>4 & 0xFF)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_HEX@(__SUNPRO_C & 0xF)
+# else
+ /* __SUNPRO_CC = 0xVRP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_HEX@(__SUNPRO_C>>8)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_HEX@(__SUNPRO_C>>4 & 0xF)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_HEX@(__SUNPRO_C & 0xF)
+# endif")
diff --git a/Modules/Compiler/SunPro-C.cmake b/Modules/Compiler/SunPro-C.cmake
new file mode 100644
index 0000000000..c5b5203fd6
--- /dev/null
+++ b/Modules/Compiler/SunPro-C.cmake
@@ -0,0 +1,27 @@
+set(CMAKE_C_VERBOSE_FLAG "-#")
+
+set(CMAKE_C_COMPILE_OPTIONS_PIC -KPIC)
+set(CMAKE_C_COMPILE_OPTIONS_PIE -KPIE)
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-KPIC")
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-G")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-R")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-h")
+
+set(CMAKE_C_FLAGS_INIT "")
+set(CMAKE_C_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-xO2 -xspace -DNDEBUG")
+set(CMAKE_C_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
+
+# Initialize C link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Bdynamic")
+endforeach()
+
+set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
diff --git a/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake b/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake
new file mode 100644
index 0000000000..5c23a957e0
--- /dev/null
+++ b/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake
@@ -0,0 +1,15 @@
+
+set(_compiler_id_pp_test "defined(__SUNPRO_CC)")
+
+set(_compiler_id_version_compute "
+# if __SUNPRO_CC >= 0x5100
+ /* __SUNPRO_CC = 0xVRRP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_HEX@(__SUNPRO_CC>>12)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_HEX@(__SUNPRO_CC>>4 & 0xFF)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_HEX@(__SUNPRO_CC & 0xF)
+# else
+ /* __SUNPRO_CC = 0xVRP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_HEX@(__SUNPRO_CC>>8)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_HEX@(__SUNPRO_CC>>4 & 0xF)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_HEX@(__SUNPRO_CC & 0xF)
+# endif")
diff --git a/Modules/Compiler/SunPro-CXX.cmake b/Modules/Compiler/SunPro-CXX.cmake
new file mode 100644
index 0000000000..59687129af
--- /dev/null
+++ b/Modules/Compiler/SunPro-CXX.cmake
@@ -0,0 +1,33 @@
+set(CMAKE_CXX_VERBOSE_FLAG "-v")
+
+set(CMAKE_CXX_COMPILE_OPTIONS_PIC -KPIC)
+set(CMAKE_CXX_COMPILE_OPTIONS_PIE -KPIE)
+set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-KPIC")
+set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-G")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-R")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP ":")
+set(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-h")
+
+set(CMAKE_CXX_FLAGS_INIT "")
+set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-xO2 -xspace -DNDEBUG")
+set(CMAKE_CXX_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
+
+# Initialize C link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_CXX_FLAGS "-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS "-Bdynamic")
+endforeach()
+
+set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+
+# Create archives with "CC -xar" in case user adds "-instances=extern"
+# so that template instantiations are available to archive members.
+set(CMAKE_CXX_CREATE_STATIC_LIBRARY
+ "<CMAKE_CXX_COMPILER> -xar -o <TARGET> <OBJECTS> "
+ "<CMAKE_RANLIB> <TARGET> ")
diff --git a/Modules/Compiler/SunPro-Fortran.cmake b/Modules/Compiler/SunPro-Fortran.cmake
new file mode 100644
index 0000000000..18e75b9e32
--- /dev/null
+++ b/Modules/Compiler/SunPro-Fortran.cmake
@@ -0,0 +1,18 @@
+set(CMAKE_Fortran_VERBOSE_FLAG "-v")
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
+
+set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS "-KPIC")
+set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-G")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG "-R")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ":")
+set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-h")
+set(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG "-R")
+
+set(CMAKE_Fortran_FLAGS_INIT "")
+set(CMAKE_Fortran_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "-xO2 -xspace -DNDEBUG")
+set(CMAKE_Fortran_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
+set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
+set(CMAKE_Fortran_MODDIR_FLAG "-moddir=")
+set(CMAKE_Fortran_MODPATH_FLAG "-M")
diff --git a/Modules/Compiler/TI-ASM.cmake b/Modules/Compiler/TI-ASM.cmake
new file mode 100644
index 0000000000..e097626b60
--- /dev/null
+++ b/Modules/Compiler/TI-ASM.cmake
@@ -0,0 +1,8 @@
+set(CMAKE_LIBRARY_PATH_FLAG "--search_path=")
+set(CMAKE_LINK_LIBRARY_FLAG "--library=")
+set(CMAKE_INCLUDE_FLAG_ASM "--include_path=")
+
+set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> --compile_only --asm_file=<SOURCE> <DEFINES> <FLAGS> --output_file=<OBJECT>")
+set(CMAKE_ASM_LINK_EXECUTABLE "<CMAKE_ASM_COMPILER> <OBJECTS> --run_linker --output_file=<TARGET> <CMAKE_ASM_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")
+
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS asm;s;abs)
diff --git a/Modules/Compiler/TI-C.cmake b/Modules/Compiler/TI-C.cmake
new file mode 100644
index 0000000000..b5809942ec
--- /dev/null
+++ b/Modules/Compiler/TI-C.cmake
@@ -0,0 +1,10 @@
+set(CMAKE_LIBRARY_PATH_FLAG "--search_path=")
+set(CMAKE_LINK_LIBRARY_FLAG "--library=")
+set(CMAKE_INCLUDE_FLAG_C "--include_path=")
+
+set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> --compile_only --skip_assembler --c_file=<SOURCE> <DEFINES> <FLAGS> --output_file=<ASSEMBLY_SOURCE>")
+set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> --preproc_only --c_file=<SOURCE> <DEFINES> <FLAGS> --output_file=<PREPROCESSED_SOURCE>")
+
+set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> --compile_only --c_file=<SOURCE> <DEFINES> <FLAGS> --output_file=<OBJECT>")
+set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -r <TARGET> <OBJECTS>")
+set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET>.map <CMAKE_C_LINK_FLAGS> <LINK_LIBRARIES> <LINK_FLAGS> <OBJECTS>")
diff --git a/Modules/Compiler/TI-CXX.cmake b/Modules/Compiler/TI-CXX.cmake
new file mode 100644
index 0000000000..8cf5ac37e5
--- /dev/null
+++ b/Modules/Compiler/TI-CXX.cmake
@@ -0,0 +1,10 @@
+set(CMAKE_LIBRARY_PATH_FLAG "--search_path=")
+set(CMAKE_LINK_LIBRARY_FLAG "--library=")
+set(CMAKE_INCLUDE_FLAG_CXX "--include_path=")
+
+set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> --compile_only --skip_assembler --cpp_file=<SOURCE> <DEFINES> <FLAGS> --output_file=<ASSEMBLY_SOURCE>")
+set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> --preproc_only --cpp_file=<SOURCE> <DEFINES> <FLAGS> --output_file=<PREPROCESSED_SOURCE>")
+
+set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> --compile_only --cpp_file=<SOURCE> <DEFINES> <FLAGS> --output_file=<OBJECT>")
+set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -r <TARGET> <OBJECTS>")
+set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_LIBRARIES> <LINK_FLAGS> <OBJECTS>")
diff --git a/Modules/Compiler/TI-DetermineCompiler.cmake b/Modules/Compiler/TI-DetermineCompiler.cmake
new file mode 100644
index 0000000000..19aa9e3d42
--- /dev/null
+++ b/Modules/Compiler/TI-DetermineCompiler.cmake
@@ -0,0 +1,8 @@
+
+set(_compiler_id_pp_test "defined(__TI_COMPILER_VERSION__)")
+
+set(_compiler_id_version_compute "
+ /* __TI_COMPILER_VERSION__ = VVVRRRPPP */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__TI_COMPILER_VERSION__/1000000)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__TI_COMPILER_VERSION__/1000 % 1000)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__TI_COMPILER_VERSION__ % 1000)")
diff --git a/Modules/Compiler/TinyCC-C-DetermineCompiler.cmake b/Modules/Compiler/TinyCC-C-DetermineCompiler.cmake
new file mode 100644
index 0000000000..8d6de7e441
--- /dev/null
+++ b/Modules/Compiler/TinyCC-C-DetermineCompiler.cmake
@@ -0,0 +1,2 @@
+
+set(_compiler_id_pp_test "defined(__TINYC__)")
diff --git a/Modules/Compiler/TinyCC-C.cmake b/Modules/Compiler/TinyCC-C.cmake
new file mode 100644
index 0000000000..f7937acdf5
--- /dev/null
+++ b/Modules/Compiler/TinyCC-C.cmake
@@ -0,0 +1,8 @@
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")
+
+# no optimization in tcc:
+set (CMAKE_C_FLAGS_INIT "")
+set (CMAKE_C_FLAGS_DEBUG_INIT "-g")
+set (CMAKE_C_FLAGS_MINSIZEREL_INIT "-DNDEBUG")
+set (CMAKE_C_FLAGS_RELEASE_INIT "-DNDEBUG")
+set (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-g -DNDEBUG")
diff --git a/Modules/Compiler/VisualAge-C-DetermineCompiler.cmake b/Modules/Compiler/VisualAge-C-DetermineCompiler.cmake
new file mode 100644
index 0000000000..97c226313a
--- /dev/null
+++ b/Modules/Compiler/VisualAge-C-DetermineCompiler.cmake
@@ -0,0 +1,4 @@
+
+set(_compiler_id_pp_test "defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800")
+
+include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-C-DetermineVersionInternal.cmake")
diff --git a/Modules/Compiler/VisualAge-C.cmake b/Modules/Compiler/VisualAge-C.cmake
new file mode 100644
index 0000000000..40b609e9a8
--- /dev/null
+++ b/Modules/Compiler/VisualAge-C.cmake
@@ -0,0 +1 @@
+include(Compiler/XL-C)
diff --git a/Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake b/Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake
new file mode 100644
index 0000000000..cd53499689
--- /dev/null
+++ b/Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake
@@ -0,0 +1,4 @@
+
+set(_compiler_id_pp_test "defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ < 800")
+
+include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-CXX-DetermineVersionInternal.cmake")
diff --git a/Modules/Compiler/VisualAge-CXX.cmake b/Modules/Compiler/VisualAge-CXX.cmake
new file mode 100644
index 0000000000..2509b43967
--- /dev/null
+++ b/Modules/Compiler/VisualAge-CXX.cmake
@@ -0,0 +1 @@
+include(Compiler/XL-CXX)
diff --git a/Modules/Compiler/VisualAge-Fortran.cmake b/Modules/Compiler/VisualAge-Fortran.cmake
new file mode 100644
index 0000000000..3ef3178d9f
--- /dev/null
+++ b/Modules/Compiler/VisualAge-Fortran.cmake
@@ -0,0 +1 @@
+include(Compiler/XL-Fortran)
diff --git a/Modules/Compiler/Watcom-DetermineCompiler.cmake b/Modules/Compiler/Watcom-DetermineCompiler.cmake
new file mode 100644
index 0000000000..153e350dbf
--- /dev/null
+++ b/Modules/Compiler/Watcom-DetermineCompiler.cmake
@@ -0,0 +1,10 @@
+
+set(_compiler_id_pp_test "defined(__WATCOMC__) && __WATCOMC__ < 1200")
+
+set(_compiler_id_version_compute "
+ /* __WATCOMC__ = VVRR */
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__WATCOMC__ / 100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@((__WATCOMC__ / 10) % 10)
+# if (__WATCOMC__ % 10) > 0
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__WATCOMC__ % 10)
+# endif")
diff --git a/Modules/Compiler/XL-ASM.cmake b/Modules/Compiler/XL-ASM.cmake
new file mode 100644
index 0000000000..07507f9be1
--- /dev/null
+++ b/Modules/Compiler/XL-ASM.cmake
@@ -0,0 +1,13 @@
+set(CMAKE_ASM_VERBOSE_FLAG "-V")
+
+# -qthreaded = Ensures that all optimizations will be thread-safe
+# -qalias=noansi = Turns off type-based aliasing completely (safer optimizer)
+# -qhalt=e = Halt on error messages (rather than just severe errors)
+set(CMAKE_ASM_FLAGS_INIT "-qthreaded -qalias=noansi -qhalt=e -qsourcetype=assembler")
+
+set(CMAKE_ASM_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_ASM_FLAGS_RELEASE_INIT "-O -DNDEBUG")
+set(CMAKE_ASM_FLAGS_MINSIZEREL_INIT "-O -DNDEBUG")
+set(CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT "-g -DNDEBUG")
+
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s )
diff --git a/Modules/Compiler/XL-C-DetermineCompiler.cmake b/Modules/Compiler/XL-C-DetermineCompiler.cmake
new file mode 100644
index 0000000000..3f4e05c554
--- /dev/null
+++ b/Modules/Compiler/XL-C-DetermineCompiler.cmake
@@ -0,0 +1,4 @@
+
+set(_compiler_id_pp_test "defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800")
+
+include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-C-DetermineVersionInternal.cmake")
diff --git a/Modules/Compiler/XL-C.cmake b/Modules/Compiler/XL-C.cmake
new file mode 100644
index 0000000000..09a55291e8
--- /dev/null
+++ b/Modules/Compiler/XL-C.cmake
@@ -0,0 +1,9 @@
+include(Compiler/XL)
+__compiler_xl(C)
+set(CMAKE_C_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT} -DNDEBUG")
+set(CMAKE_C_FLAGS_MINSIZEREL_INIT "${CMAKE_C_FLAGS_MINSIZEREL_INIT} -DNDEBUG")
+
+# -qthreaded = Ensures that all optimizations will be thread-safe
+# -qalias=noansi = Turns off type-based aliasing completely (safer optimizer)
+# -qhalt=e = Halt on error messages (rather than just severe errors)
+set(CMAKE_C_FLAGS_INIT "-qthreaded -qalias=noansi -qhalt=e")
diff --git a/Modules/Compiler/XL-CXX-DetermineCompiler.cmake b/Modules/Compiler/XL-CXX-DetermineCompiler.cmake
new file mode 100644
index 0000000000..dffa4bc21e
--- /dev/null
+++ b/Modules/Compiler/XL-CXX-DetermineCompiler.cmake
@@ -0,0 +1,4 @@
+
+set(_compiler_id_pp_test "defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ >= 800")
+
+include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-CXX-DetermineVersionInternal.cmake")
diff --git a/Modules/Compiler/XL-CXX.cmake b/Modules/Compiler/XL-CXX.cmake
new file mode 100644
index 0000000000..6c842cd77c
--- /dev/null
+++ b/Modules/Compiler/XL-CXX.cmake
@@ -0,0 +1,11 @@
+include(Compiler/XL)
+__compiler_xl(CXX)
+set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_CXX_FLAGS_RELEASE_INIT} -DNDEBUG")
+set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT} -DNDEBUG")
+
+# -qthreaded = Ensures that all optimizations will be thread-safe
+# -qhalt=e = Halt on error messages (rather than just severe errors)
+set(CMAKE_CXX_FLAGS_INIT "-qthreaded -qhalt=e")
+
+set(CMAKE_CXX_COMPILE_OBJECT
+ "<CMAKE_CXX_COMPILER> -+ <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
diff --git a/Modules/Compiler/XL-Fortran.cmake b/Modules/Compiler/XL-Fortran.cmake
new file mode 100644
index 0000000000..f1c9158b25
--- /dev/null
+++ b/Modules/Compiler/XL-Fortran.cmake
@@ -0,0 +1,17 @@
+include(Compiler/XL)
+__compiler_xl(Fortran)
+
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-qfixed") # [=<right_margin>]
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-qfree") # [=f90|ibm]
+
+set(CMAKE_Fortran_MODDIR_FLAG "-qmoddir=")
+
+set(CMAKE_Fortran_DEFINE_FLAG "-WF,-D")
+
+# -qthreaded = Ensures that all optimizations will be thread-safe
+# -qhalt=e = Halt on error messages (rather than just severe errors)
+set(CMAKE_Fortran_FLAGS_INIT "-qthreaded -qhalt=e")
+
+# We require updates to CMake C++ code to support preprocessing rules for Fortran.
+set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE)
+set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE)
diff --git a/Modules/Compiler/XL.cmake b/Modules/Compiler/XL.cmake
new file mode 100644
index 0000000000..7bf5020ac9
--- /dev/null
+++ b/Modules/Compiler/XL.cmake
@@ -0,0 +1,54 @@
+
+#=============================================================================
+# Copyright 2002-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# This module is shared by multiple languages; use include blocker.
+if(__COMPILER_XL)
+ return()
+endif()
+set(__COMPILER_XL 1)
+
+# Find the CreateExportList program that comes with this toolchain.
+find_program(CMAKE_XL_CreateExportList
+ NAMES CreateExportList
+ DOC "IBM XL CreateExportList tool"
+ )
+
+macro(__compiler_xl lang)
+ # Feature flags.
+ set(CMAKE_${lang}_VERBOSE_FLAG "-V")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-qpic")
+
+ set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-g")
+ set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-O")
+ set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-O")
+ set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-g")
+ set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+ set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+
+ # CMAKE_XL_CreateExportList is part of the AIX XL compilers but not the linux ones.
+ # If we found the tool, we'll use it to create exports, otherwise stick with the regular
+ # create shared library compile line.
+ if (CMAKE_XL_CreateExportList)
+ # The compiler front-end passes all object files, archive files, and shared
+ # library files named on the command line to CreateExportList to create a
+ # list of all symbols to be exported from the shared library. This causes
+ # all archive members to be copied into the shared library whether they are
+ # needed or not. Instead we run the tool ourselves to pass only the object
+ # files so that we export only the symbols actually provided by the sources.
+ set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
+ "${CMAKE_XL_CreateExportList} <OBJECT_DIR>/objects.exp <OBJECTS>"
+ "<CMAKE_${lang}_COMPILER> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -Wl,-bE:<OBJECT_DIR>/objects.exp <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
+ )
+ endif()
+endmacro()
diff --git a/Modules/Compiler/zOS-C-DetermineCompiler.cmake b/Modules/Compiler/zOS-C-DetermineCompiler.cmake
new file mode 100644
index 0000000000..daa378198c
--- /dev/null
+++ b/Modules/Compiler/zOS-C-DetermineCompiler.cmake
@@ -0,0 +1,4 @@
+
+set(_compiler_id_pp_test "defined(__IBMC__) && defined(__COMPILER_VER__)")
+
+include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-C-DetermineVersionInternal.cmake")
diff --git a/Modules/Compiler/zOS-CXX-DetermineCompiler.cmake b/Modules/Compiler/zOS-CXX-DetermineCompiler.cmake
new file mode 100644
index 0000000000..a08ff57133
--- /dev/null
+++ b/Modules/Compiler/zOS-CXX-DetermineCompiler.cmake
@@ -0,0 +1,4 @@
+
+set(_compiler_id_pp_test "defined(__IBMCPP__) && defined(__COMPILER_VER__)")
+
+include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-CXX-DetermineVersionInternal.cmake")
diff --git a/Modules/CompilerId/VS-10.vcxproj.in b/Modules/CompilerId/VS-10.vcxproj.in
new file mode 100644
index 0000000000..a17d03d0d2
--- /dev/null
+++ b/Modules/CompilerId/VS-10.vcxproj.in
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|@id_platform@">
+ <Configuration>Debug</Configuration>
+ <Platform>@id_platform@</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{CAE07175-D007-4FC3-BFE8-47B392814159}</ProjectGuid>
+ <RootNamespace>CompilerId@id_lang@</RootNamespace>
+ <Keyword>Win32Proj</Keyword>
+ @id_system@
+ @id_system_version@
+ @id_WindowsSDKDesktopARMSupport@
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ @id_toolset@
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">.\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">$(Configuration)\</IntDir>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>TurnOffAllWarnings</WarningLevel>
+ <DebugInformationFormat>
+ </DebugInformationFormat>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ <PostBuildEvent>
+ <Command>for %%i in (@id_cl@) do %40echo CMAKE_@id_lang@_COMPILER=%%~$PATH:i</Command>
+ </PostBuildEvent>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="@id_src@" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+</Project>
diff --git a/Modules/CompilerId/VS-6.dsp.in b/Modules/CompilerId/VS-6.dsp.in
new file mode 100644
index 0000000000..48c9a236ba
--- /dev/null
+++ b/Modules/CompilerId/VS-6.dsp.in
@@ -0,0 +1,48 @@
+# Microsoft Developer Studio Project File - Name="CompilerId@id_lang@" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=CompilerId@id_lang@ - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "CompilerId@id_lang@.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "CompilerId@id_lang@.mak" CFG="CompilerId@id_lang@ - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "CompilerId@id_lang@ - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+CPP=cl.exe
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "."
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD CPP /nologo /MDd /c
+LINK32=link.exe
+# ADD LINK32 /nologo /version:0.0 /subsystem:console /machine:x86 /out:"CompilerId@id_lang@.exe" /IGNORE:4089
+# Begin Special Build Tool
+SOURCE="$(InputPath)"
+PostBuild_Cmds=for %%i in (@id_cl@) do @echo CMAKE_@id_lang@_COMPILER=%%~$PATH:i
+# End Special Build Tool
+# Begin Target
+
+# Name "CompilerId@id_lang@ - Win32 Debug"
+# Begin Group "Source Files"
+
+# Begin Source File
+
+SOURCE="@id_src@"
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/Modules/CompilerId/VS-7.vcproj.in b/Modules/CompilerId/VS-7.vcproj.in
new file mode 100644
index 0000000000..9e3c3c3ced
--- /dev/null
+++ b/Modules/CompilerId/VS-7.vcproj.in
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="@id_version@"
+ Name="CompilerId@id_lang@"
+ ProjectGUID="{CAE07175-D007-4FC3-BFE8-47B392814159}"
+ RootNamespace="CompilerId@id_lang@"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="@id_platform@"
+ />
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|@id_platform@"
+ OutputDirectory="."
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="0"
+ DebugInformationFormat="0"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ IgnoreDefaultLibraryNames="libc"
+ GenerateDebugInformation="false"
+ SubSystem="@id_subsystem@"
+ EntryPointSymbol="@id_entrypoint@"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine="for %%i in (@id_cl@) do @echo CMAKE_@id_lang@_COMPILER=%%~$PATH:i"
+ />
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="@id_src@"
+ >
+ </File>
+ </Filter>
+ </Files>
+</VisualStudioProject>
diff --git a/Modules/CompilerId/VS-Intel.vfproj.in b/Modules/CompilerId/VS-Intel.vfproj.in
new file mode 100644
index 0000000000..044dd202dd
--- /dev/null
+++ b/Modules/CompilerId/VS-Intel.vfproj.in
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<VisualStudioProject
+ ProjectCreator="Intel Fortran"
+ Keyword="Console Application"
+ Version="@CMAKE_VS_INTEL_Fortran_PROJECT_VERSION@"
+ ProjectIdGuid="{AB67BAB7-D7AE-4E97-B492-FE5420447509}"
+ >
+ <Platforms>
+ <Platform Name="@id_platform@"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|@id_platform@"
+ OutputDirectory="."
+ IntermediateDirectory="$(ConfigurationName)"
+ >
+ <Tool
+ Name="VFFortranCompilerTool"
+ DebugInformationFormat="debugEnabled"
+ Optimization="optimizeDisabled"
+ Preprocess="preprocessYes"
+ RuntimeLibrary="rtMultiThreadedDebugDLL"
+ />
+ <Tool
+ Name="VFLinkerTool"
+ LinkIncremental="linkIncrementalNo"
+ GenerateDebugInformation="true"
+ SubSystem="subSystemConsole"
+ />
+ <Tool
+ Name="VFPostBuildEventTool"
+ CommandLine="for %%i in (@id_cl@) do @echo CMAKE_@id_lang@_COMPILER=%%~$PATH:i"
+ />
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter Name="Source Files" Filter="F">
+ <File RelativePath="@id_src@"/>
+ </Filter>
+ </Files>
+ <Globals/>
+</VisualStudioProject>
diff --git a/Modules/CompilerId/VS-NsightTegra.vcxproj.in b/Modules/CompilerId/VS-NsightTegra.vcxproj.in
new file mode 100644
index 0000000000..b7389ebabb
--- /dev/null
+++ b/Modules/CompilerId/VS-NsightTegra.vcxproj.in
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup Label="NsightTegraProject">
+ <NsightTegraProjectRevisionNumber>6</NsightTegraProjectRevisionNumber>
+ </PropertyGroup>
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|@id_platform@">
+ <Configuration>Debug</Configuration>
+ <Platform>@id_platform@</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{CAE07175-D007-4FC3-BFE8-47B392814159}</ProjectGuid>
+ <RootNamespace>CompilerId@id_lang@</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ @id_toolset@
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">.\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">$(Configuration)\</IntDir>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">
+ <ClCompile>
+ <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ </Link>
+ <PostBuildEvent>
+ <Command>
+if "$(ToolchainName)"=="gcc" (
+ for %%i in ($(ToolchainPrebuiltRoot)\bin\*@id_gcc@.exe) do (
+ @echo CMAKE_@id_lang@_COMPILER=%%i
+ goto :done
+ )
+)
+if "$(ToolchainName)"=="clang" (
+ for %%i in ($(ToolchainPrebuiltRoot)\bin\*@id_clang@.exe) do (
+ @echo CMAKE_@id_lang@_COMPILER=%%i
+ goto :done
+ )
+)
+:done
+</Command>
+ </PostBuildEvent>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="@id_src@" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+</Project>
diff --git a/Modules/CompilerId/Xcode-1.pbxproj.in b/Modules/CompilerId/Xcode-1.pbxproj.in
new file mode 100644
index 0000000000..793ad0280d
--- /dev/null
+++ b/Modules/CompilerId/Xcode-1.pbxproj.in
@@ -0,0 +1,120 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 39;
+ objects = {
+ 014CEA460018CE2711CA2923 = {
+ buildSettings = {
+ };
+ isa = PBXBuildStyle;
+ name = Development;
+ };
+ 08FB7793FE84155DC02AAC07 = {
+ buildSettings = {
+ };
+ buildStyles = (
+ 014CEA460018CE2711CA2923,
+ );
+ hasScannedForEncodings = 1;
+ isa = PBXProject;
+ mainGroup = 08FB7794FE84155DC02AAC07;
+ projectDirPath = "";
+ targets = (
+ 8DD76FA90486AB0100D96B5E,
+ );
+ };
+ 08FB7794FE84155DC02AAC07 = {
+ children = (
+ 08FB7795FE84155DC02AAC07,
+ 1AB674ADFE9D54B511CA2CBB,
+ );
+ isa = PBXGroup;
+ name = CompilerId@id_lang@;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 08FB7795FE84155DC02AAC07 = {
+ children = (
+ 2C18F0B415DC1DC700593670,
+ );
+ isa = PBXGroup;
+ name = Source;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 1AB674ADFE9D54B511CA2CBB = {
+ children = (
+ 8DD76F6C0486A84900D96B5E,
+ );
+ isa = PBXGroup;
+ name = Products;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 2C18F0B415DC1DC700593670 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ explicitFileType = @id_type@;
+ path = @id_src@;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 2C18F0B615DC1E0300593670 = {
+ fileRef = 2C18F0B415DC1DC700593670;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 2C8FEB8E15DC1A1A00E56A5D = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "echo \"GCC_VERSION=$GCC_VERSION\"";
+ };
+ 8DD76FA90486AB0100D96B5E = {
+ buildPhases = (
+ 2C18F0B515DC1DCE00593670,
+ 2C8FEB8E15DC1A1A00E56A5D,
+ );
+ buildRules = (
+ );
+ buildSettings = {
+ PRODUCT_NAME = CompilerId@id_lang@;
+ SYMROOT = .;
+ };
+ dependencies = (
+ );
+ isa = PBXNativeTarget;
+ name = CompilerId@id_lang@;
+ productName = CompilerId@id_lang@;
+ productReference = 8DD76F6C0486A84900D96B5E;
+ productType = "com.apple.product-type.tool";
+ };
+ 2C18F0B515DC1DCE00593670 = {
+ buildActionMask = 2147483647;
+ files = (
+ 2C18F0B615DC1E0300593670,
+ );
+ isa = PBXSourcesBuildPhase;
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8DD76F6C0486A84900D96B5E = {
+ explicitFileType = "compiled.mach-o.executable";
+ includeInIndex = 0;
+ isa = PBXFileReference;
+ path = CompilerId@id_lang@;
+ refType = 3;
+ sourceTree = BUILT_PRODUCTS_DIR;
+ };
+ };
+ rootObject = 08FB7793FE84155DC02AAC07;
+}
diff --git a/Modules/CompilerId/Xcode-2.pbxproj.in b/Modules/CompilerId/Xcode-2.pbxproj.in
new file mode 100644
index 0000000000..226b413fd2
--- /dev/null
+++ b/Modules/CompilerId/Xcode-2.pbxproj.in
@@ -0,0 +1,119 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 42;
+ objects = {
+
+ 2C18F0B615DC1E0300593670 = {isa = PBXBuildFile; fileRef = 2C18F0B415DC1DC700593670; };
+ 2C18F0B415DC1DC700593670 = {isa = PBXFileReference; fileEncoding = 4; explicitFileType = @id_type@; path = @id_src@; sourceTree = "<group>"; };
+ 8DD76F6C0486A84900D96B5E = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CompilerId@id_lang@; sourceTree = BUILT_PRODUCTS_DIR; };
+
+ 08FB7794FE84155DC02AAC07 = {
+ isa = PBXGroup;
+ children = (
+ 08FB7795FE84155DC02AAC07,
+ 1AB674ADFE9D54B511CA2CBB,
+ );
+ name = CompilerId@id_lang@;
+ sourceTree = "<group>";
+ };
+ 08FB7795FE84155DC02AAC07 = {
+ isa = PBXGroup;
+ children = (
+ 2C18F0B415DC1DC700593670,
+ );
+ name = Source;
+ sourceTree = "<group>";
+ };
+ 1AB674ADFE9D54B511CA2CBB = {
+ isa = PBXGroup;
+ children = (
+ 8DD76F6C0486A84900D96B5E,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+
+ 8DD76FA90486AB0100D96B5E = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 1DEB928508733DD80010E9CD;
+ buildPhases = (
+ 2C18F0B515DC1DCE00593670,
+ 2C8FEB8E15DC1A1A00E56A5D,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = CompilerId@id_lang@;
+ productName = CompilerId@id_lang@;
+ productReference = 8DD76F6C0486A84900D96B5E;
+ productType = "com.apple.product-type.tool";
+ };
+ 08FB7793FE84155DC02AAC07 = {
+ isa = PBXProject;
+ buildConfigurationList = 1DEB928908733DD80010E9CD;
+ hasScannedForEncodings = 1;
+ mainGroup = 08FB7794FE84155DC02AAC07;
+ projectDirPath = "";
+ targets = (
+ 8DD76FA90486AB0100D96B5E,
+ );
+ };
+ 2C8FEB8E15DC1A1A00E56A5D = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "echo \"GCC_VERSION=$GCC_VERSION\"";
+ };
+ 2C18F0B515DC1DCE00593670 = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 2C18F0B615DC1E0300593670,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 1DEB928608733DD80010E9CD = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ PRODUCT_NAME = CompilerId@id_lang@;
+ };
+ name = Debug;
+ };
+ 1DEB928A08733DD80010E9CD = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)";
+ SYMROOT = .;
+ };
+ name = Debug;
+ };
+ 1DEB928508733DD80010E9CD = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB928608733DD80010E9CD,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Debug;
+ };
+ 1DEB928908733DD80010E9CD = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB928A08733DD80010E9CD,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Debug;
+ };
+ };
+ rootObject = 08FB7793FE84155DC02AAC07;
+}
diff --git a/Modules/CompilerId/Xcode-3.pbxproj.in b/Modules/CompilerId/Xcode-3.pbxproj.in
new file mode 100644
index 0000000000..eabfc6b1c1
--- /dev/null
+++ b/Modules/CompilerId/Xcode-3.pbxproj.in
@@ -0,0 +1,110 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 45;
+ objects = {
+
+ 2C18F0B615DC1E0300593670 = {isa = PBXBuildFile; fileRef = 2C18F0B415DC1DC700593670; };
+ 2C18F0B415DC1DC700593670 = {isa = PBXFileReference; fileEncoding = 4; explicitFileType = @id_type@; path = @id_src@; sourceTree = "<group>"; };
+ 08FB7794FE84155DC02AAC07 = {
+ isa = PBXGroup;
+ children = (
+ 2C18F0B415DC1DC700593670,
+ );
+ name = CompilerId@id_lang@;
+ sourceTree = "<group>";
+ };
+ 8DD76FA90486AB0100D96B5E = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 1DEB928508733DD80010E9CD;
+ buildPhases = (
+ 2C18F0B515DC1DCE00593670,
+ 2C8FEB8E15DC1A1A00E56A5D,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = CompilerId@id_lang@;
+ productName = CompilerId@id_lang@;
+ productType = "com.apple.product-type.tool";
+ };
+ 08FB7793FE84155DC02AAC07 = {
+ isa = PBXProject;
+ buildConfigurationList = 1DEB928908733DD80010E9CD;
+ compatibilityVersion = "Xcode 3.1";
+ developmentRegion = English;
+ hasScannedForEncodings = 1;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 08FB7794FE84155DC02AAC07;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 8DD76FA90486AB0100D96B5E,
+ );
+ };
+ 2C8FEB8E15DC1A1A00E56A5D = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "echo \"GCC_VERSION=$GCC_VERSION\"";
+ showEnvVarsInLog = 0;
+ };
+ 2C18F0B515DC1DCE00593670 = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 2C18F0B615DC1E0300593670,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 1DEB928608733DD80010E9CD = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ PRODUCT_NAME = CompilerId@id_lang@;
+ };
+ name = Debug;
+ };
+ 1DEB928A08733DD80010E9CD = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ ONLY_ACTIVE_ARCH = YES;
+ CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)";
+ SYMROOT = .;
+ @id_toolset@
+ @id_deployment_target@
+ @id_sdkroot@
+ };
+ name = Debug;
+ };
+ 1DEB928508733DD80010E9CD = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB928608733DD80010E9CD,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Debug;
+ };
+ 1DEB928908733DD80010E9CD = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB928A08733DD80010E9CD,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Debug;
+ };
+ };
+ rootObject = 08FB7793FE84155DC02AAC07;
+}
diff --git a/Modules/Dart.cmake b/Modules/Dart.cmake
new file mode 100644
index 0000000000..db487d8f58
--- /dev/null
+++ b/Modules/Dart.cmake
@@ -0,0 +1,134 @@
+#.rst:
+# Dart
+# ----
+#
+# Configure a project for testing with CTest or old Dart Tcl Client
+#
+# This file is the backwards-compatibility version of the CTest module.
+# It supports using the old Dart 1 Tcl client for driving dashboard
+# submissions as well as testing with CTest. This module should be
+# included in the CMakeLists.txt file at the top of a project. Typical
+# usage:
+#
+# ::
+#
+# include(Dart)
+# if(BUILD_TESTING)
+# # ... testing related CMake code ...
+# endif()
+#
+# The BUILD_TESTING option is created by the Dart module to determine
+# whether testing support should be enabled. The default is ON.
+
+# This file configures a project to use the Dart testing/dashboard process.
+# It is broken into 3 sections.
+#
+# Section #1: Locate programs on the client and determine site and build name
+# Section #2: Configure or copy Tcl scripts from the source tree to build tree
+# Section #3: Custom targets for performing dashboard builds.
+#
+#
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+option(BUILD_TESTING "Build the testing tree." ON)
+
+if(BUILD_TESTING)
+ find_package(Dart QUIET)
+
+ #
+ # Section #1:
+ #
+ # CMake commands that will not vary from project to project. Locates programs
+ # on the client and configure site name and build name.
+ #
+
+ set(RUN_FROM_DART 1)
+ include(CTest)
+ set(RUN_FROM_DART)
+
+ find_program(COMPRESSIONCOMMAND NAMES gzip compress zip
+ DOC "Path to program used to compress files for transfer to the dart server")
+ find_program(GUNZIPCOMMAND gunzip DOC "Path to gunzip executable")
+ find_program(JAVACOMMAND java DOC "Path to java command, used by the Dart server to create html.")
+ option(DART_VERBOSE_BUILD "Show the actual output of the build, or if off show a . for each 1024 bytes."
+ OFF)
+ option(DART_BUILD_ERROR_REPORT_LIMIT "Limit of reported errors, -1 reports all." -1 )
+ option(DART_BUILD_WARNING_REPORT_LIMIT "Limit of reported warnings, -1 reports all." -1 )
+
+ set(VERBOSE_BUILD ${DART_VERBOSE_BUILD})
+ set(BUILD_ERROR_REPORT_LIMIT ${DART_BUILD_ERROR_REPORT_LIMIT})
+ set(BUILD_WARNING_REPORT_LIMIT ${DART_BUILD_WARNING_REPORT_LIMIT})
+ set (DELIVER_CONTINUOUS_EMAIL "Off" CACHE BOOL "Should Dart server send email when build errors are found in Continuous builds?")
+
+ mark_as_advanced(
+ COMPRESSIONCOMMAND
+ DART_BUILD_ERROR_REPORT_LIMIT
+ DART_BUILD_WARNING_REPORT_LIMIT
+ DART_TESTING_TIMEOUT
+ DART_VERBOSE_BUILD
+ DELIVER_CONTINUOUS_EMAIL
+ GUNZIPCOMMAND
+ JAVACOMMAND
+ )
+
+ set(HAVE_DART)
+ if(EXISTS "${DART_ROOT}/Source/Client/Dart.conf.in")
+ set(HAVE_DART 1)
+ endif()
+
+ #
+ # Section #2:
+ #
+ # Make necessary directories and configure testing scripts
+ #
+ # find a tcl shell command
+ if(HAVE_DART)
+ find_package(Tclsh)
+ endif()
+
+
+ if (HAVE_DART)
+ # make directories in the binary tree
+ file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/Testing/HTML/TestingResults/Dashboard"
+ "${PROJECT_BINARY_DIR}/Testing/HTML/TestingResults/Sites/${SITE}/${BUILDNAME}")
+
+ # configure files
+ configure_file(
+ "${DART_ROOT}/Source/Client/Dart.conf.in"
+ "${PROJECT_BINARY_DIR}/DartConfiguration.tcl" )
+
+ #
+ # Section 3:
+ #
+ # Custom targets to perform dashboard builds and submissions.
+ # These should NOT need to be modified from project to project.
+ #
+
+ # add testing targets
+ set(DART_EXPERIMENTAL_NAME Experimental)
+ if(DART_EXPERIMENTAL_USE_PROJECT_NAME)
+ set(DART_EXPERIMENTAL_NAME "${DART_EXPERIMENTAL_NAME}${PROJECT_NAME}")
+ endif()
+ endif ()
+
+ set(RUN_FROM_CTEST_OR_DART 1)
+ include(CTestTargets)
+ set(RUN_FROM_CTEST_OR_DART)
+endif()
+
+#
+# End of Dart.cmake
+#
+
diff --git a/Modules/DartConfiguration.tcl.in b/Modules/DartConfiguration.tcl.in
new file mode 100644
index 0000000000..37a0a408ed
--- /dev/null
+++ b/Modules/DartConfiguration.tcl.in
@@ -0,0 +1,106 @@
+# This file is configured by CMake automatically as DartConfiguration.tcl
+# If you choose not to use CMake, this file may be hand configured, by
+# filling in the required variables.
+
+
+# Configuration directories and files
+SourceDirectory: @PROJECT_SOURCE_DIR@
+BuildDirectory: @PROJECT_BINARY_DIR@
+
+# Where to place the cost data store
+CostDataFile: @CTEST_COST_DATA_FILE@
+
+# Site is something like machine.domain, i.e. pragmatic.crd
+Site: @SITE@
+
+# Build name is osname-revision-compiler, i.e. Linux-2.4.2-2smp-c++
+BuildName: @BUILDNAME@
+
+# Submission information
+IsCDash: @CTEST_DROP_SITE_CDASH@
+CDashVersion: @CTEST_CDASH_VERSION@
+QueryCDashVersion: @CTEST_CDASH_QUERY_VERSION@
+DropSite: @DROP_SITE@
+DropLocation: @DROP_LOCATION@
+DropSiteUser: @DROP_SITE_USER@
+DropSitePassword: @DROP_SITE_PASSWORD@
+DropSiteMode: @DROP_SITE_MODE@
+DropMethod: @DROP_METHOD@
+TriggerSite: @TRIGGER_SITE@
+ScpCommand: @SCPCOMMAND@
+
+# Dashboard start time
+NightlyStartTime: @NIGHTLY_START_TIME@
+
+# Commands for the build/test/submit cycle
+ConfigureCommand: "@CMAKE_COMMAND@" "@PROJECT_SOURCE_DIR@"
+MakeCommand: @MAKECOMMAND@
+DefaultCTestConfigurationType: @DEFAULT_CTEST_CONFIGURATION_TYPE@
+
+# version control
+UpdateVersionOnly: @CTEST_UPDATE_VERSION_ONLY@
+
+# CVS options
+# Default is "-d -P -A"
+CVSCommand: @CVSCOMMAND@
+CVSUpdateOptions: @CVS_UPDATE_OPTIONS@
+
+# Subversion options
+SVNCommand: @SVNCOMMAND@
+SVNOptions: @CTEST_SVN_OPTIONS@
+SVNUpdateOptions: @SVN_UPDATE_OPTIONS@
+
+# Git options
+GITCommand: @GITCOMMAND@
+GITUpdateOptions: @GIT_UPDATE_OPTIONS@
+GITUpdateCustom: @CTEST_GIT_UPDATE_CUSTOM@
+
+# Perforce options
+P4Command: @P4COMMAND@
+P4Client: @CTEST_P4_CLIENT@
+P4Options: @CTEST_P4_OPTIONS@
+P4UpdateOptions: @CTEST_P4_UPDATE_OPTIONS@
+P4UpdateCustom: @CTEST_P4_UPDATE_CUSTOM@
+
+# Generic update command
+UpdateCommand: @UPDATE_COMMAND@
+UpdateOptions: @UPDATE_OPTIONS@
+UpdateType: @UPDATE_TYPE@
+
+# Compiler info
+Compiler: @CMAKE_CXX_COMPILER@
+
+# Dynamic analysis (MemCheck)
+PurifyCommand: @PURIFYCOMMAND@
+ValgrindCommand: @VALGRIND_COMMAND@
+ValgrindCommandOptions: @VALGRIND_COMMAND_OPTIONS@
+MemoryCheckType: @MEMORYCHECK_TYPE@
+MemoryCheckSanitizerOptions: @MEMORYCHECK_SANITIZER_OPTIONS@
+MemoryCheckCommand: @MEMORYCHECK_COMMAND@
+MemoryCheckCommandOptions: @MEMORYCHECK_COMMAND_OPTIONS@
+MemoryCheckSuppressionFile: @MEMORYCHECK_SUPPRESSIONS_FILE@
+
+# Coverage
+CoverageCommand: @COVERAGE_COMMAND@
+CoverageExtraFlags: @COVERAGE_EXTRA_FLAGS@
+
+# Cluster commands
+SlurmBatchCommand: @SLURM_SBATCH_COMMAND@
+SlurmRunCommand: @SLURM_SRUN_COMMAND@
+
+# Testing options
+# TimeOut is the amount of time in seconds to wait for processes
+# to complete during testing. After TimeOut seconds, the
+# process will be summarily terminated.
+# Currently set to 25 minutes
+TimeOut: @DART_TESTING_TIMEOUT@
+
+UseLaunchers: @CTEST_USE_LAUNCHERS@
+CurlOptions: @CTEST_CURL_OPTIONS@
+# warning, if you add new options here that have to do with submit,
+# you have to update cmCTestSubmitCommand.cxx
+
+# For CTest submissions that timeout, these options
+# specify behavior for retrying the submission
+CTestSubmitRetryDelay: @CTEST_SUBMIT_RETRY_DELAY@
+CTestSubmitRetryCount: @CTEST_SUBMIT_RETRY_COUNT@
diff --git a/Modules/DeployQt4.cmake b/Modules/DeployQt4.cmake
new file mode 100644
index 0000000000..9b31567c90
--- /dev/null
+++ b/Modules/DeployQt4.cmake
@@ -0,0 +1,332 @@
+#.rst:
+# DeployQt4
+# ---------
+#
+# Functions to help assemble a standalone Qt4 executable.
+#
+# A collection of CMake utility functions useful for deploying Qt4
+# executables.
+#
+# The following functions are provided by this module:
+#
+# ::
+#
+# write_qt4_conf
+# resolve_qt4_paths
+# fixup_qt4_executable
+# install_qt4_plugin_path
+# install_qt4_plugin
+# install_qt4_executable
+#
+# Requires CMake 2.6 or greater because it uses function and
+# PARENT_SCOPE. Also depends on BundleUtilities.cmake.
+#
+# ::
+#
+# WRITE_QT4_CONF(<qt_conf_dir> <qt_conf_contents>)
+#
+# Writes a qt.conf file with the <qt_conf_contents> into <qt_conf_dir>.
+#
+# ::
+#
+# RESOLVE_QT4_PATHS(<paths_var> [<executable_path>])
+#
+# Loop through <paths_var> list and if any don't exist resolve them
+# relative to the <executable_path> (if supplied) or the
+# CMAKE_INSTALL_PREFIX.
+#
+# ::
+#
+# FIXUP_QT4_EXECUTABLE(<executable> [<qtplugins> <libs> <dirs> <plugins_dir> <request_qt_conf>])
+#
+# Copies Qt plugins, writes a Qt configuration file (if needed) and
+# fixes up a Qt4 executable using BundleUtilities so it is standalone
+# and can be drag-and-drop copied to another machine as long as all of
+# the system libraries are compatible.
+#
+# <executable> should point to the executable to be fixed-up.
+#
+# <qtplugins> should contain a list of the names or paths of any Qt
+# plugins to be installed.
+#
+# <libs> will be passed to BundleUtilities and should be a list of any
+# already installed plugins, libraries or executables to also be
+# fixed-up.
+#
+# <dirs> will be passed to BundleUtilities and should contain and
+# directories to be searched to find library dependencies.
+#
+# <plugins_dir> allows an custom plugins directory to be used.
+#
+# <request_qt_conf> will force a qt.conf file to be written even if not
+# needed.
+#
+# ::
+#
+# INSTALL_QT4_PLUGIN_PATH(plugin executable copy installed_plugin_path_var <plugins_dir> <component> <configurations>)
+#
+# Install (or copy) a resolved <plugin> to the default plugins directory
+# (or <plugins_dir>) relative to <executable> and store the result in
+# <installed_plugin_path_var>.
+#
+# If <copy> is set to TRUE then the plugins will be copied rather than
+# installed. This is to allow this module to be used at CMake time
+# rather than install time.
+#
+# If <component> is set then anything installed will use this COMPONENT.
+#
+# ::
+#
+# INSTALL_QT4_PLUGIN(plugin executable copy installed_plugin_path_var <plugins_dir> <component>)
+#
+# Install (or copy) an unresolved <plugin> to the default plugins
+# directory (or <plugins_dir>) relative to <executable> and store the
+# result in <installed_plugin_path_var>. See documentation of
+# INSTALL_QT4_PLUGIN_PATH.
+#
+# ::
+#
+# INSTALL_QT4_EXECUTABLE(<executable> [<qtplugins> <libs> <dirs> <plugins_dir> <request_qt_conf> <component>])
+#
+# Installs Qt plugins, writes a Qt configuration file (if needed) and
+# fixes up a Qt4 executable using BundleUtilities so it is standalone
+# and can be drag-and-drop copied to another machine as long as all of
+# the system libraries are compatible. The executable will be fixed-up
+# at install time. <component> is the COMPONENT used for bundle fixup
+# and plugin installation. See documentation of FIXUP_QT4_BUNDLE.
+
+#=============================================================================
+# Copyright 2011 Mike McQuaid <mike@mikemcquaid.com>
+#
+# 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.)
+
+# The functions defined in this file depend on the fixup_bundle function
+# (and others) found in BundleUtilities.cmake
+
+include("${CMAKE_CURRENT_LIST_DIR}/BundleUtilities.cmake")
+set(DeployQt4_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")
+set(DeployQt4_apple_plugins_dir "PlugIns")
+
+function(write_qt4_conf qt_conf_dir qt_conf_contents)
+ set(qt_conf_path "${qt_conf_dir}/qt.conf")
+ message(STATUS "Writing ${qt_conf_path}")
+ file(WRITE "${qt_conf_path}" "${qt_conf_contents}")
+endfunction()
+
+function(resolve_qt4_paths paths_var)
+ set(executable_path ${ARGV1})
+
+ set(paths_resolved)
+ foreach(path ${${paths_var}})
+ if(EXISTS "${path}")
+ list(APPEND paths_resolved "${path}")
+ else()
+ if(${executable_path})
+ list(APPEND paths_resolved "${executable_path}/${path}")
+ else()
+ list(APPEND paths_resolved "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${path}")
+ endif()
+ endif()
+ endforeach()
+ set(${paths_var} ${paths_resolved} PARENT_SCOPE)
+endfunction()
+
+function(fixup_qt4_executable executable)
+ set(qtplugins ${ARGV1})
+ set(libs ${ARGV2})
+ set(dirs ${ARGV3})
+ set(plugins_dir ${ARGV4})
+ set(request_qt_conf ${ARGV5})
+
+ message(STATUS "fixup_qt4_executable")
+ message(STATUS " executable='${executable}'")
+ message(STATUS " qtplugins='${qtplugins}'")
+ message(STATUS " libs='${libs}'")
+ message(STATUS " dirs='${dirs}'")
+ message(STATUS " plugins_dir='${plugins_dir}'")
+ message(STATUS " request_qt_conf='${request_qt_conf}'")
+
+ if(QT_LIBRARY_DIR)
+ list(APPEND dirs "${QT_LIBRARY_DIR}")
+ endif()
+ if(QT_BINARY_DIR)
+ list(APPEND dirs "${QT_BINARY_DIR}")
+ endif()
+
+ if(APPLE)
+ set(qt_conf_dir "${executable}/Contents/Resources")
+ set(executable_path "${executable}")
+ set(write_qt_conf TRUE)
+ if(NOT plugins_dir)
+ set(plugins_dir "${DeployQt4_apple_plugins_dir}")
+ endif()
+ else()
+ get_filename_component(executable_path "${executable}" PATH)
+ if(NOT executable_path)
+ set(executable_path ".")
+ endif()
+ set(qt_conf_dir "${executable_path}")
+ set(write_qt_conf ${request_qt_conf})
+ endif()
+
+ foreach(plugin ${qtplugins})
+ set(installed_plugin_path "")
+ install_qt4_plugin("${plugin}" "${executable}" 1 installed_plugin_path)
+ list(APPEND libs ${installed_plugin_path})
+ endforeach()
+
+ foreach(lib ${libs})
+ if(NOT EXISTS "${lib}")
+ message(FATAL_ERROR "Library does not exist: ${lib}")
+ endif()
+ endforeach()
+
+ resolve_qt4_paths(libs "${executable_path}")
+
+ if(write_qt_conf)
+ set(qt_conf_contents "[Paths]\nPlugins = ${plugins_dir}")
+ write_qt4_conf("${qt_conf_dir}" "${qt_conf_contents}")
+ endif()
+
+ fixup_bundle("${executable}" "${libs}" "${dirs}")
+endfunction()
+
+function(install_qt4_plugin_path plugin executable copy installed_plugin_path_var)
+ set(plugins_dir ${ARGV4})
+ set(component ${ARGV5})
+ set(configurations ${ARGV6})
+ if(EXISTS "${plugin}")
+ if(APPLE)
+ if(NOT plugins_dir)
+ set(plugins_dir "${DeployQt4_apple_plugins_dir}")
+ endif()
+ set(plugins_path "${executable}/Contents/${plugins_dir}")
+ else()
+ get_filename_component(plugins_path "${executable}" PATH)
+ if(NOT plugins_path)
+ set(plugins_path ".")
+ endif()
+ if(plugins_dir)
+ set(plugins_path "${plugins_path}/${plugins_dir}")
+ endif()
+ endif()
+
+ set(plugin_group "")
+
+ get_filename_component(plugin_path "${plugin}" PATH)
+ get_filename_component(plugin_parent_path "${plugin_path}" PATH)
+ get_filename_component(plugin_parent_dir_name "${plugin_parent_path}" NAME)
+ get_filename_component(plugin_name "${plugin}" NAME)
+ string(TOLOWER "${plugin_parent_dir_name}" plugin_parent_dir_name)
+
+ if("${plugin_parent_dir_name}" STREQUAL "plugins")
+ get_filename_component(plugin_group "${plugin_path}" NAME)
+ set(${plugin_group_var} "${plugin_group}")
+ endif()
+ set(plugins_path "${plugins_path}/${plugin_group}")
+
+ if(${copy})
+ file(MAKE_DIRECTORY "${plugins_path}")
+ file(COPY "${plugin}" DESTINATION "${plugins_path}")
+ else()
+ if(configurations AND (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE))
+ set(configurations CONFIGURATIONS ${configurations})
+ else()
+ unset(configurations)
+ endif()
+ install(FILES "${plugin}" DESTINATION "${plugins_path}" ${configurations} ${component})
+ endif()
+ set(${installed_plugin_path_var} "${plugins_path}/${plugin_name}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(install_qt4_plugin plugin executable copy installed_plugin_path_var)
+ set(plugins_dir ${ARGV4})
+ set(component ${ARGV5})
+ if(EXISTS "${plugin}")
+ install_qt4_plugin_path("${plugin}" "${executable}" "${copy}" "${installed_plugin_path_var}" "${plugins_dir}" "${component}")
+ else()
+ string(TOUPPER "QT_${plugin}_PLUGIN" plugin_var)
+ set(plugin_release_var "${plugin_var}_RELEASE")
+ set(plugin_debug_var "${plugin_var}_DEBUG")
+ set(plugin_release "${${plugin_release_var}}")
+ set(plugin_debug "${${plugin_debug_var}}")
+ if(DEFINED "${plugin_release_var}" AND DEFINED "${plugin_debug_var}" AND NOT EXISTS "${plugin_release}" AND NOT EXISTS "${plugin_debug}")
+ message(WARNING "Qt plugin \"${plugin}\" not recognized or found.")
+ endif()
+ if(NOT EXISTS "${${plugin_debug_var}}")
+ set(plugin_debug "${plugin_release}")
+ endif()
+
+ if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
+ install_qt4_plugin_path("${plugin_release}" "${executable}" "${copy}" "${installed_plugin_path_var}_release" "${plugins_dir}" "${component}" "Release|RelWithDebInfo|MinSizeRel")
+ install_qt4_plugin_path("${plugin_debug}" "${executable}" "${copy}" "${installed_plugin_path_var}_debug" "${plugins_dir}" "${component}" "Debug")
+
+ if(CMAKE_BUILD_TYPE MATCHES "^Debug$")
+ set(${installed_plugin_path_var} ${${installed_plugin_path_var}_debug})
+ else()
+ set(${installed_plugin_path_var} ${${installed_plugin_path_var}_release})
+ endif()
+ else()
+ install_qt4_plugin_path("${plugin_release}" "${executable}" "${copy}" "${installed_plugin_path_var}" "${plugins_dir}" "${component}")
+ endif()
+ endif()
+ set(${installed_plugin_path_var} ${${installed_plugin_path_var}} PARENT_SCOPE)
+endfunction()
+
+function(install_qt4_executable executable)
+ set(qtplugins ${ARGV1})
+ set(libs ${ARGV2})
+ set(dirs ${ARGV3})
+ set(plugins_dir ${ARGV4})
+ set(request_qt_conf ${ARGV5})
+ set(component ${ARGV6})
+ if(QT_LIBRARY_DIR)
+ list(APPEND dirs "${QT_LIBRARY_DIR}")
+ endif()
+ if(QT_BINARY_DIR)
+ list(APPEND dirs "${QT_BINARY_DIR}")
+ endif()
+ if(component)
+ set(component COMPONENT ${component})
+ else()
+ unset(component)
+ endif()
+
+ get_filename_component(executable_absolute "${executable}" ABSOLUTE)
+ if(EXISTS "${QT_QTCORE_LIBRARY_RELEASE}")
+ gp_file_type("${executable_absolute}" "${QT_QTCORE_LIBRARY_RELEASE}" qtcore_type)
+ elseif(EXISTS "${QT_QTCORE_LIBRARY_DEBUG}")
+ gp_file_type("${executable_absolute}" "${QT_QTCORE_LIBRARY_DEBUG}" qtcore_type)
+ endif()
+ if(qtcore_type STREQUAL "system")
+ set(qt_plugins_dir "")
+ endif()
+
+ if(QT_IS_STATIC)
+ message(WARNING "Qt built statically: not installing plugins.")
+ else()
+ foreach(plugin ${qtplugins})
+ set(installed_plugin_paths "")
+ install_qt4_plugin("${plugin}" "${executable}" 0 installed_plugin_paths "${plugins_dir}" "${component}")
+ list(APPEND libs ${installed_plugin_paths})
+ endforeach()
+ endif()
+
+ resolve_qt4_paths(libs "")
+
+ install(CODE
+ "include(\"${DeployQt4_cmake_dir}/DeployQt4.cmake\")
+ set(BU_CHMOD_BUNDLE_ITEMS TRUE)
+ FIXUP_QT4_EXECUTABLE(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${executable}\" \"\" \"${libs}\" \"${dirs}\" \"${plugins_dir}\" \"${request_qt_conf}\")"
+ ${component}
+ )
+endfunction()
diff --git a/Modules/Documentation.cmake b/Modules/Documentation.cmake
new file mode 100644
index 0000000000..be6aaea69d
--- /dev/null
+++ b/Modules/Documentation.cmake
@@ -0,0 +1,57 @@
+#.rst:
+# Documentation
+# -------------
+#
+# DocumentationVTK.cmake
+#
+# This file provides support for the VTK documentation framework. It
+# relies on several tools (Doxygen, Perl, etc).
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+#
+# Build the documentation ?
+#
+option(BUILD_DOCUMENTATION "Build the documentation (Doxygen)." OFF)
+mark_as_advanced(BUILD_DOCUMENTATION)
+
+if (BUILD_DOCUMENTATION)
+
+ #
+ # Check for the tools
+ #
+ find_package(UnixCommands)
+ find_package(Doxygen)
+ find_package(Gnuplot)
+ find_package(HTMLHelp)
+ find_package(Perl)
+ find_package(Wget)
+
+ option(DOCUMENTATION_HTML_HELP
+ "Build the HTML Help file (CHM)." OFF)
+
+ option(DOCUMENTATION_HTML_TARZ
+ "Build a compressed tar archive of the HTML doc." OFF)
+
+ mark_as_advanced(
+ DOCUMENTATION_HTML_HELP
+ DOCUMENTATION_HTML_TARZ
+ )
+
+ #
+ # The documentation process is controled by a batch file.
+ # We will probably need bash to create the custom target
+ #
+
+endif ()
diff --git a/Modules/DummyCXXFile.cxx b/Modules/DummyCXXFile.cxx
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Modules/DummyCXXFile.cxx
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Modules/ExternalData.cmake b/Modules/ExternalData.cmake
new file mode 100644
index 0000000000..79bb064689
--- /dev/null
+++ b/Modules/ExternalData.cmake
@@ -0,0 +1,828 @@
+#.rst:
+# ExternalData
+# ------------
+#
+# Manage data files stored outside source tree
+#
+# Use this module to unambiguously reference data files stored outside
+# the source tree and fetch them at build time from arbitrary local and
+# remote content-addressed locations. Functions provided by this module
+# recognize arguments with the syntax ``DATA{<name>}`` as references to
+# external data, replace them with full paths to local copies of those
+# data, and create build rules to fetch and update the local copies.
+#
+# The ``DATA{}`` syntax is literal and the ``<name>`` is a full or relative path
+# within the source tree. The source tree must contain either a real
+# data file at ``<name>`` or a "content link" at ``<name><ext>`` containing a
+# hash of the real file using a hash algorithm corresponding to ``<ext>``.
+# For example, the argument ``DATA{img.png}`` may be satisfied by either a
+# real ``img.png`` file in the current source directory or a ``img.png.md5``
+# file containing its MD5 sum.
+#
+# The ``ExternalData_Expand_Arguments`` function evaluates ``DATA{}``
+# references in its arguments and constructs a new list of arguments:
+#
+# .. code-block:: cmake
+#
+# ExternalData_Expand_Arguments(
+# <target> # Name of data management target
+# <outVar> # Output variable
+# [args...] # Input arguments, DATA{} allowed
+# )
+#
+# It replaces each ``DATA{}`` reference in an argument with the full path of
+# a real data file on disk that will exist after the ``<target>`` builds.
+#
+# The ``ExternalData_Add_Test`` function wraps around the CMake
+# :command:`add_test` command but supports ``DATA{}`` references in
+# its arguments:
+#
+# .. code-block:: cmake
+#
+# ExternalData_Add_Test(
+# <target> # Name of data management target
+# ... # Arguments of add_test(), DATA{} allowed
+# )
+#
+# It passes its arguments through ``ExternalData_Expand_Arguments`` and then
+# invokes the :command:`add_test` command using the results.
+#
+# The ``ExternalData_Add_Target`` function creates a custom target to
+# manage local instances of data files stored externally:
+#
+# .. code-block:: cmake
+#
+# ExternalData_Add_Target(
+# <target> # Name of data management target
+# )
+#
+# It creates custom commands in the target as necessary to make data
+# files available for each ``DATA{}`` reference previously evaluated by
+# other functions provided by this module. A list of URL templates may
+# be provided in the variable ``ExternalData_URL_TEMPLATES`` using the
+# placeholders ``%(algo)`` and ``%(hash)`` in each template. Data fetch
+# rules try each URL template in order by substituting the hash
+# algorithm name for ``%(algo)`` and the hash value for ``%(hash)``.
+#
+# The following hash algorithms are supported::
+#
+# %(algo) <ext> Description
+# ------- ----- -----------
+# MD5 .md5 Message-Digest Algorithm 5, RFC 1321
+# SHA1 .sha1 US Secure Hash Algorithm 1, RFC 3174
+# SHA224 .sha224 US Secure Hash Algorithms, RFC 4634
+# SHA256 .sha256 US Secure Hash Algorithms, RFC 4634
+# SHA384 .sha384 US Secure Hash Algorithms, RFC 4634
+# SHA512 .sha512 US Secure Hash Algorithms, RFC 4634
+#
+# Note that the hashes are used only for unique data identification and
+# download verification.
+#
+# Example usage:
+#
+# .. code-block:: cmake
+#
+# include(ExternalData)
+# set(ExternalData_URL_TEMPLATES "file:///local/%(algo)/%(hash)"
+# "file:////host/share/%(algo)/%(hash)"
+# "http://data.org/%(algo)/%(hash)")
+# ExternalData_Add_Test(MyData
+# NAME MyTest
+# COMMAND MyExe DATA{MyInput.png}
+# )
+# ExternalData_Add_Target(MyData)
+#
+# When test ``MyTest`` runs the ``DATA{MyInput.png}`` argument will be
+# replaced by the full path to a real instance of the data file
+# ``MyInput.png`` on disk. If the source tree contains a content link
+# such as ``MyInput.png.md5`` then the ``MyData`` target creates a real
+# ``MyInput.png`` in the build tree.
+#
+# The ``DATA{}`` syntax can be told to fetch a file series using the form
+# ``DATA{<name>,:}``, where the ``:`` is literal. If the source tree
+# contains a group of files or content links named like a series then a
+# reference to one member adds rules to fetch all of them. Although all
+# members of a series are fetched, only the file originally named by the
+# ``DATA{}`` argument is substituted for it. The default configuration
+# recognizes file series names ending with ``#.ext``, ``_#.ext``, ``.#.ext``,
+# or ``-#.ext`` where ``#`` is a sequence of decimal digits and ``.ext`` is
+# any single extension. Configure it with a regex that parses ``<number>``
+# and ``<suffix>`` parts from the end of ``<name>``::
+#
+# ExternalData_SERIES_PARSE = regex of the form (<number>)(<suffix>)$
+#
+# For more complicated cases set::
+#
+# ExternalData_SERIES_PARSE = regex with at least two () groups
+# ExternalData_SERIES_PARSE_PREFIX = <prefix> regex group number, if any
+# ExternalData_SERIES_PARSE_NUMBER = <number> regex group number
+# ExternalData_SERIES_PARSE_SUFFIX = <suffix> regex group number
+#
+# Configure series number matching with a regex that matches the
+# ``<number>`` part of series members named ``<prefix><number><suffix>``::
+#
+# ExternalData_SERIES_MATCH = regex matching <number> in all series members
+#
+# Note that the ``<suffix>`` of a series does not include a hash-algorithm
+# extension.
+#
+# The ``DATA{}`` syntax can alternatively match files associated with the
+# named file and contained in the same directory. Associated files may
+# be specified by options using the syntax
+# ``DATA{<name>,<opt1>,<opt2>,...}``. Each option may specify one file by
+# name or specify a regular expression to match file names using the
+# syntax ``REGEX:<regex>``. For example, the arguments::
+#
+# DATA{MyData/MyInput.mhd,MyInput.img} # File pair
+# DATA{MyData/MyFrames00.png,REGEX:MyFrames[0-9]+\\.png} # Series
+#
+# will pass ``MyInput.mha`` and ``MyFrames00.png`` on the command line but
+# ensure that the associated files are present next to them.
+#
+# The ``DATA{}`` syntax may reference a directory using a trailing slash and
+# a list of associated files. The form ``DATA{<name>/,<opt1>,<opt2>,...}``
+# adds rules to fetch any files in the directory that match one of the
+# associated file options. For example, the argument
+# ``DATA{MyDataDir/,REGEX:.*}`` will pass the full path to a ``MyDataDir``
+# directory on the command line and ensure that the directory contains
+# files corresponding to every file or content link in the ``MyDataDir``
+# source directory.
+#
+# The variable ``ExternalData_LINK_CONTENT`` may be set to the name of a
+# supported hash algorithm to enable automatic conversion of real data
+# files referenced by the ``DATA{}`` syntax into content links. For each
+# such ``<file>`` a content link named ``<file><ext>`` is created. The
+# original file is renamed to the form ``.ExternalData_<algo>_<hash>`` to
+# stage it for future transmission to one of the locations in the list
+# of URL templates (by means outside the scope of this module). The
+# data fetch rule created for the content link will use the staged
+# object if it cannot be found using any URL template.
+#
+# The variable ``ExternalData_OBJECT_STORES`` may be set to a list of local
+# directories that store objects using the layout ``<dir>/%(algo)/%(hash)``.
+# These directories will be searched first for a needed object. If the
+# object is not available in any store then it will be fetched remotely
+# using the URL templates and added to the first local store listed. If
+# no stores are specified the default is a location inside the build
+# tree.
+#
+# The variable ``ExternalData_SOURCE_ROOT`` may be set to the highest source
+# directory containing any path named by a ``DATA{}`` reference. The
+# default is ``CMAKE_SOURCE_DIR``. ``ExternalData_SOURCE_ROOT`` and
+# ``CMAKE_SOURCE_DIR`` must refer to directories within a single source
+# distribution (e.g. they come together in one tarball).
+#
+# The variable ``ExternalData_BINARY_ROOT`` may be set to the directory to
+# hold the real data files named by expanded ``DATA{}`` references. The
+# default is ``CMAKE_BINARY_DIR``. The directory layout will mirror that of
+# content links under ``ExternalData_SOURCE_ROOT``.
+#
+# Variables ``ExternalData_TIMEOUT_INACTIVITY`` and
+# ``ExternalData_TIMEOUT_ABSOLUTE`` set the download inactivity and absolute
+# timeouts, in seconds. The defaults are 60 seconds and 300 seconds,
+# respectively. Set either timeout to 0 seconds to disable enforcement.
+
+#=============================================================================
+# Copyright 2010-2013 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.)
+
+function(ExternalData_add_test target)
+ # Expand all arguments as a single string to preserve escaped semicolons.
+ ExternalData_expand_arguments("${target}" testArgs "${ARGN}")
+ add_test(${testArgs})
+endfunction()
+
+function(ExternalData_add_target target)
+ if(NOT ExternalData_URL_TEMPLATES AND NOT ExternalData_OBJECT_STORES)
+ message(FATAL_ERROR
+ "Neither ExternalData_URL_TEMPLATES nor ExternalData_OBJECT_STORES is set!")
+ endif()
+ if(NOT ExternalData_OBJECT_STORES)
+ set(ExternalData_OBJECT_STORES ${CMAKE_BINARY_DIR}/ExternalData/Objects)
+ endif()
+ set(config ${CMAKE_CURRENT_BINARY_DIR}/${target}_config.cmake)
+ configure_file(${_ExternalData_SELF_DIR}/ExternalData_config.cmake.in ${config} @ONLY)
+
+ set(files "")
+
+ # Set "_ExternalData_FILE_${file}" for each output file to avoid duplicate
+ # rules. Use local data first to prefer real files over content links.
+
+ # Custom commands to copy or link local data.
+ get_property(data_local GLOBAL PROPERTY _ExternalData_${target}_LOCAL)
+ foreach(entry IN LISTS data_local)
+ string(REPLACE "|" ";" tuple "${entry}")
+ list(GET tuple 0 file)
+ list(GET tuple 1 name)
+ if(NOT DEFINED "_ExternalData_FILE_${file}")
+ set("_ExternalData_FILE_${file}" 1)
+ add_custom_command(
+ COMMENT "Generating ${file}"
+ OUTPUT "${file}"
+ COMMAND ${CMAKE_COMMAND} -Drelative_top=${CMAKE_BINARY_DIR}
+ -Dfile=${file} -Dname=${name}
+ -DExternalData_ACTION=local
+ -DExternalData_CONFIG=${config}
+ -P ${_ExternalData_SELF}
+ MAIN_DEPENDENCY "${name}"
+ )
+ list(APPEND files "${file}")
+ endif()
+ endforeach()
+
+ # Custom commands to fetch remote data.
+ get_property(data_fetch GLOBAL PROPERTY _ExternalData_${target}_FETCH)
+ foreach(entry IN LISTS data_fetch)
+ string(REPLACE "|" ";" tuple "${entry}")
+ list(GET tuple 0 file)
+ list(GET tuple 1 name)
+ list(GET tuple 2 ext)
+ set(stamp "${ext}-stamp")
+ if(NOT DEFINED "_ExternalData_FILE_${file}")
+ set("_ExternalData_FILE_${file}" 1)
+ add_custom_command(
+ # Users care about the data file, so hide the hash/timestamp file.
+ COMMENT "Generating ${file}"
+ # The hash/timestamp file is the output from the build perspective.
+ # List the real file as a second output in case it is a broken link.
+ # The files must be listed in this order so CMake can hide from the
+ # make tool that a symlink target may not be newer than the input.
+ OUTPUT "${file}${stamp}" "${file}"
+ # Run the data fetch/update script.
+ COMMAND ${CMAKE_COMMAND} -Drelative_top=${CMAKE_BINARY_DIR}
+ -Dfile=${file} -Dname=${name} -Dext=${ext}
+ -DExternalData_ACTION=fetch
+ -DExternalData_CONFIG=${config}
+ -P ${_ExternalData_SELF}
+ # Update whenever the object hash changes.
+ MAIN_DEPENDENCY "${name}${ext}"
+ )
+ list(APPEND files "${file}${stamp}")
+ endif()
+ endforeach()
+
+ # Custom target to drive all update commands.
+ add_custom_target(${target} ALL DEPENDS ${files})
+endfunction()
+
+function(ExternalData_expand_arguments target outArgsVar)
+ # Replace DATA{} references with real arguments.
+ set(data_regex "DATA{([^;{}\r\n]*)}")
+ set(other_regex "([^D]|D[^A]|DA[^T]|DAT[^A]|DATA[^{])+|.")
+ set(outArgs "")
+ # This list expansion un-escapes semicolons in list element values so we
+ # must re-escape them below anywhere a new list expansion will occur.
+ foreach(arg IN LISTS ARGN)
+ if("x${arg}" MATCHES "${data_regex}")
+ # Re-escape in-value semicolons before expansion in foreach below.
+ string(REPLACE ";" "\\;" tmp "${arg}")
+ # Split argument into DATA{}-pieces and other pieces.
+ string(REGEX MATCHALL "${data_regex}|${other_regex}" pieces "${tmp}")
+ # Compose output argument with DATA{}-pieces replaced.
+ set(outArg "")
+ foreach(piece IN LISTS pieces)
+ if("x${piece}" MATCHES "^x${data_regex}$")
+ # Replace this DATA{}-piece with a file path.
+ _ExternalData_arg("${target}" "${piece}" "${CMAKE_MATCH_1}" file)
+ set(outArg "${outArg}${file}")
+ else()
+ # No replacement needed for this piece.
+ set(outArg "${outArg}${piece}")
+ endif()
+ endforeach()
+ else()
+ # No replacements needed in this argument.
+ set(outArg "${arg}")
+ endif()
+ # Re-escape in-value semicolons in resulting list.
+ string(REPLACE ";" "\\;" outArg "${outArg}")
+ list(APPEND outArgs "${outArg}")
+ endforeach()
+ set("${outArgsVar}" "${outArgs}" PARENT_SCOPE)
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Private helper interface
+
+set(_ExternalData_REGEX_ALGO "MD5|SHA1|SHA224|SHA256|SHA384|SHA512")
+set(_ExternalData_REGEX_EXT "md5|sha1|sha224|sha256|sha384|sha512")
+set(_ExternalData_SELF "${CMAKE_CURRENT_LIST_FILE}")
+get_filename_component(_ExternalData_SELF_DIR "${_ExternalData_SELF}" PATH)
+
+function(_ExternalData_compute_hash var_hash algo file)
+ if("${algo}" MATCHES "^${_ExternalData_REGEX_ALGO}$")
+ file("${algo}" "${file}" hash)
+ set("${var_hash}" "${hash}" PARENT_SCOPE)
+ else()
+ message(FATAL_ERROR "Hash algorithm ${algo} unimplemented.")
+ endif()
+endfunction()
+
+function(_ExternalData_random var)
+ string(RANDOM LENGTH 6 random)
+ set("${var}" "${random}" PARENT_SCOPE)
+endfunction()
+
+function(_ExternalData_exact_regex regex_var string)
+ string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" regex "${string}")
+ set("${regex_var}" "${regex}" PARENT_SCOPE)
+endfunction()
+
+function(_ExternalData_atomic_write file content)
+ _ExternalData_random(random)
+ set(tmp "${file}.tmp${random}")
+ file(WRITE "${tmp}" "${content}")
+ file(RENAME "${tmp}" "${file}")
+endfunction()
+
+function(_ExternalData_link_content name var_ext)
+ if("${ExternalData_LINK_CONTENT}" MATCHES "^(${_ExternalData_REGEX_ALGO})$")
+ set(algo "${ExternalData_LINK_CONTENT}")
+ else()
+ message(FATAL_ERROR
+ "Unknown hash algorithm specified by ExternalData_LINK_CONTENT:\n"
+ " ${ExternalData_LINK_CONTENT}")
+ endif()
+ _ExternalData_compute_hash(hash "${algo}" "${name}")
+ get_filename_component(dir "${name}" PATH)
+ set(staged "${dir}/.ExternalData_${algo}_${hash}")
+ string(TOLOWER ".${algo}" ext)
+ _ExternalData_atomic_write("${name}${ext}" "${hash}\n")
+ file(RENAME "${name}" "${staged}")
+ set("${var_ext}" "${ext}" PARENT_SCOPE)
+
+ file(RELATIVE_PATH relname "${ExternalData_SOURCE_ROOT}" "${name}${ext}")
+ message(STATUS "Linked ${relname} to ExternalData ${algo}/${hash}")
+endfunction()
+
+function(_ExternalData_arg target arg options var_file)
+ # Separate data path from the options.
+ string(REPLACE "," ";" options "${options}")
+ list(GET options 0 data)
+ list(REMOVE_AT options 0)
+
+ # Interpret trailing slashes as directories.
+ set(data_is_directory 0)
+ if("x${data}" MATCHES "^x(.*)([/\\])$")
+ set(data_is_directory 1)
+ set(data "${CMAKE_MATCH_1}")
+ endif()
+
+ # Convert to full path.
+ if(IS_ABSOLUTE "${data}")
+ set(absdata "${data}")
+ else()
+ set(absdata "${CMAKE_CURRENT_SOURCE_DIR}/${data}")
+ endif()
+ get_filename_component(absdata "${absdata}" ABSOLUTE)
+
+ # Convert to relative path under the source tree.
+ if(NOT ExternalData_SOURCE_ROOT)
+ set(ExternalData_SOURCE_ROOT "${CMAKE_SOURCE_DIR}")
+ endif()
+ set(top_src "${ExternalData_SOURCE_ROOT}")
+ file(RELATIVE_PATH reldata "${top_src}" "${absdata}")
+ if(IS_ABSOLUTE "${reldata}" OR "${reldata}" MATCHES "^\\.\\./")
+ message(FATAL_ERROR "Data file referenced by argument\n"
+ " ${arg}\n"
+ "does not lie under the top-level source directory\n"
+ " ${top_src}\n")
+ endif()
+ if(data_is_directory AND NOT IS_DIRECTORY "${top_src}/${reldata}")
+ message(FATAL_ERROR "Data directory referenced by argument\n"
+ " ${arg}\n"
+ "corresponds to source tree path\n"
+ " ${reldata}\n"
+ "that does not exist as a directory!")
+ endif()
+ if(NOT ExternalData_BINARY_ROOT)
+ set(ExternalData_BINARY_ROOT "${CMAKE_BINARY_DIR}")
+ endif()
+ set(top_bin "${ExternalData_BINARY_ROOT}")
+
+ # Handle in-source builds gracefully.
+ if("${top_src}" STREQUAL "${top_bin}")
+ if(ExternalData_LINK_CONTENT)
+ message(WARNING "ExternalData_LINK_CONTENT cannot be used in-source")
+ set(ExternalData_LINK_CONTENT 0)
+ endif()
+ set(top_same 1)
+ endif()
+
+ set(external "") # Entries external to the source tree.
+ set(internal "") # Entries internal to the source tree.
+ set(have_original ${data_is_directory})
+ set(have_original_as_dir 0)
+
+ # Process options.
+ set(series_option "")
+ set(associated_files "")
+ set(associated_regex "")
+ foreach(opt ${options})
+ # Regular expression to match associated files.
+ if("x${opt}" MATCHES "^xREGEX:([^:/]+)$")
+ list(APPEND associated_regex "${CMAKE_MATCH_1}")
+ elseif(opt STREQUAL ":")
+ # Activate series matching.
+ set(series_option "${opt}")
+ elseif("x${opt}" MATCHES "^[^][:/*?]+$")
+ # Specific associated file.
+ list(APPEND associated_files "${opt}")
+ else()
+ message(FATAL_ERROR "Unknown option \"${opt}\" in argument\n"
+ " ${arg}\n")
+ endif()
+ endforeach()
+
+ if(series_option)
+ if(data_is_directory)
+ message(FATAL_ERROR "Series option \"${series_option}\" not allowed with directories.")
+ endif()
+ if(associated_files OR associated_regex)
+ message(FATAL_ERROR "Series option \"${series_option}\" not allowed with associated files.")
+ endif()
+ # Load a whole file series.
+ _ExternalData_arg_series()
+ elseif(data_is_directory)
+ if(associated_files OR associated_regex)
+ # Load listed/matching associated files in the directory.
+ _ExternalData_arg_associated()
+ else()
+ message(FATAL_ERROR "Data directory referenced by argument\n"
+ " ${arg}\n"
+ "must list associated files.")
+ endif()
+ else()
+ # Load the named data file.
+ _ExternalData_arg_single()
+ if(associated_files OR associated_regex)
+ # Load listed/matching associated files.
+ _ExternalData_arg_associated()
+ endif()
+ endif()
+
+ if(NOT have_original)
+ if(have_original_as_dir)
+ set(msg_kind FATAL_ERROR)
+ set(msg "that is directory instead of a file!")
+ else()
+ set(msg_kind AUTHOR_WARNING)
+ set(msg "that does not exist as a file (with or without an extension)!")
+ endif()
+ message(${msg_kind} "Data file referenced by argument\n"
+ " ${arg}\n"
+ "corresponds to source tree path\n"
+ " ${reldata}\n"
+ "${msg}")
+ endif()
+
+ if(external)
+ # Make the series available in the build tree.
+ set_property(GLOBAL APPEND PROPERTY
+ _ExternalData_${target}_FETCH "${external}")
+ set_property(GLOBAL APPEND PROPERTY
+ _ExternalData_${target}_LOCAL "${internal}")
+ set("${var_file}" "${top_bin}/${reldata}" PARENT_SCOPE)
+ else()
+ # The whole series is in the source tree.
+ set("${var_file}" "${top_src}/${reldata}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+macro(_ExternalData_arg_associated)
+ # Associated files lie in the same directory.
+ if(data_is_directory)
+ set(reldir "${reldata}")
+ else()
+ get_filename_component(reldir "${reldata}" PATH)
+ endif()
+ if(reldir)
+ set(reldir "${reldir}/")
+ endif()
+ _ExternalData_exact_regex(reldir_regex "${reldir}")
+
+ # Find files named explicitly.
+ foreach(file ${associated_files})
+ _ExternalData_exact_regex(file_regex "${file}")
+ _ExternalData_arg_find_files("${reldir}${file}" "${reldir_regex}${file_regex}")
+ endforeach()
+
+ # Find files matching the given regular expressions.
+ set(all "")
+ set(sep "")
+ foreach(regex ${associated_regex})
+ set(all "${all}${sep}${reldir_regex}${regex}")
+ set(sep "|")
+ endforeach()
+ _ExternalData_arg_find_files("${reldir}" "${all}")
+endmacro()
+
+macro(_ExternalData_arg_single)
+ # Match only the named data by itself.
+ _ExternalData_exact_regex(data_regex "${reldata}")
+ _ExternalData_arg_find_files("${reldata}" "${data_regex}")
+endmacro()
+
+macro(_ExternalData_arg_series)
+ # Configure series parsing and matching.
+ set(series_parse_prefix "")
+ set(series_parse_number "\\1")
+ set(series_parse_suffix "\\2")
+ if(ExternalData_SERIES_PARSE)
+ if(ExternalData_SERIES_PARSE_NUMBER AND ExternalData_SERIES_PARSE_SUFFIX)
+ if(ExternalData_SERIES_PARSE_PREFIX)
+ set(series_parse_prefix "\\${ExternalData_SERIES_PARSE_PREFIX}")
+ endif()
+ set(series_parse_number "\\${ExternalData_SERIES_PARSE_NUMBER}")
+ set(series_parse_suffix "\\${ExternalData_SERIES_PARSE_SUFFIX}")
+ elseif(NOT "x${ExternalData_SERIES_PARSE}" MATCHES "^x\\([^()]*\\)\\([^()]*\\)\\$$")
+ message(FATAL_ERROR
+ "ExternalData_SERIES_PARSE is set to\n"
+ " ${ExternalData_SERIES_PARSE}\n"
+ "which is not of the form\n"
+ " (<number>)(<suffix>)$\n"
+ "Fix the regular expression or set variables\n"
+ " ExternalData_SERIES_PARSE_PREFIX = <prefix> regex group number, if any\n"
+ " ExternalData_SERIES_PARSE_NUMBER = <number> regex group number\n"
+ " ExternalData_SERIES_PARSE_SUFFIX = <suffix> regex group number\n"
+ )
+ endif()
+ set(series_parse "${ExternalData_SERIES_PARSE}")
+ else()
+ set(series_parse "([0-9]*)(\\.[^./]*)$")
+ endif()
+ if(ExternalData_SERIES_MATCH)
+ set(series_match "${ExternalData_SERIES_MATCH}")
+ else()
+ set(series_match "[_.-]?[0-9]*")
+ endif()
+
+ # Parse the base, number, and extension components of the series.
+ string(REGEX REPLACE "${series_parse}" "${series_parse_prefix};${series_parse_number};${series_parse_suffix}" tuple "${reldata}")
+ list(LENGTH tuple len)
+ if(NOT "${len}" EQUAL 3)
+ message(FATAL_ERROR "Data file referenced by argument\n"
+ " ${arg}\n"
+ "corresponds to path\n"
+ " ${reldata}\n"
+ "that does not match regular expression\n"
+ " ${series_parse}")
+ endif()
+ list(GET tuple 0 relbase)
+ list(GET tuple 2 ext)
+
+ # Glob files that might match the series.
+ # Then match base, number, and extension.
+ _ExternalData_exact_regex(series_base "${relbase}")
+ _ExternalData_exact_regex(series_ext "${ext}")
+ _ExternalData_arg_find_files("${relbase}*${ext}"
+ "${series_base}${series_match}${series_ext}")
+endmacro()
+
+function(_ExternalData_arg_find_files pattern regex)
+ file(GLOB globbed RELATIVE "${top_src}" "${top_src}/${pattern}*")
+ foreach(entry IN LISTS globbed)
+ if("x${entry}" MATCHES "^x(.*)(\\.(${_ExternalData_REGEX_EXT}))$")
+ set(relname "${CMAKE_MATCH_1}")
+ set(alg "${CMAKE_MATCH_2}")
+ else()
+ set(relname "${entry}")
+ set(alg "")
+ endif()
+ if("x${relname}" MATCHES "^x${regex}$" # matches
+ AND NOT "x${relname}" MATCHES "(^x|/)\\.ExternalData_" # not staged obj
+ )
+ if(IS_DIRECTORY "${top_src}/${entry}")
+ if("${relname}" STREQUAL "${reldata}")
+ set(have_original_as_dir 1)
+ endif()
+ else()
+ set(name "${top_src}/${relname}")
+ set(file "${top_bin}/${relname}")
+ if(alg)
+ list(APPEND external "${file}|${name}|${alg}")
+ elseif(ExternalData_LINK_CONTENT)
+ _ExternalData_link_content("${name}" alg)
+ list(APPEND external "${file}|${name}|${alg}")
+ elseif(NOT top_same)
+ list(APPEND internal "${file}|${name}")
+ endif()
+ if("${relname}" STREQUAL "${reldata}")
+ set(have_original 1)
+ endif()
+ endif()
+ endif()
+ endforeach()
+ set(external "${external}" PARENT_SCOPE)
+ set(internal "${internal}" PARENT_SCOPE)
+ set(have_original "${have_original}" PARENT_SCOPE)
+ set(have_original_as_dir "${have_original_as_dir}" PARENT_SCOPE)
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Private script mode interface
+
+if(CMAKE_GENERATOR OR NOT ExternalData_ACTION)
+ return()
+endif()
+
+if(ExternalData_CONFIG)
+ include(${ExternalData_CONFIG})
+endif()
+if(NOT ExternalData_URL_TEMPLATES AND NOT ExternalData_OBJECT_STORES)
+ message(FATAL_ERROR
+ "Neither ExternalData_URL_TEMPLATES nor ExternalData_OBJECT_STORES is set!")
+endif()
+
+function(_ExternalData_link_or_copy src dst)
+ # Create a temporary file first.
+ get_filename_component(dst_dir "${dst}" PATH)
+ file(MAKE_DIRECTORY "${dst_dir}")
+ _ExternalData_random(random)
+ set(tmp "${dst}.tmp${random}")
+ if(UNIX)
+ # Create a symbolic link.
+ set(tgt "${src}")
+ if(relative_top)
+ # Use relative path if files are close enough.
+ file(RELATIVE_PATH relsrc "${relative_top}" "${src}")
+ file(RELATIVE_PATH relfile "${relative_top}" "${dst}")
+ if(NOT IS_ABSOLUTE "${relsrc}" AND NOT "${relsrc}" MATCHES "^\\.\\./" AND
+ NOT IS_ABSOLUTE "${reldst}" AND NOT "${reldst}" MATCHES "^\\.\\./")
+ file(RELATIVE_PATH tgt "${dst_dir}" "${src}")
+ endif()
+ endif()
+ execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${tgt}" "${tmp}" RESULT_VARIABLE result)
+ else()
+ # Create a copy.
+ execute_process(COMMAND "${CMAKE_COMMAND}" -E copy "${src}" "${tmp}" RESULT_VARIABLE result)
+ endif()
+ if(result)
+ file(REMOVE "${tmp}")
+ message(FATAL_ERROR "Failed to create\n ${tmp}\nfrom\n ${obj}")
+ endif()
+
+ # Atomically create/replace the real destination.
+ file(RENAME "${tmp}" "${dst}")
+endfunction()
+
+function(_ExternalData_download_file url file err_var msg_var)
+ set(retry 3)
+ while(retry)
+ math(EXPR retry "${retry} - 1")
+ if(ExternalData_TIMEOUT_INACTIVITY)
+ set(inactivity_timeout INACTIVITY_TIMEOUT ${ExternalData_TIMEOUT_INACTIVITY})
+ elseif(NOT "${ExternalData_TIMEOUT_INACTIVITY}" EQUAL 0)
+ set(inactivity_timeout INACTIVITY_TIMEOUT 60)
+ else()
+ set(inactivity_timeout "")
+ endif()
+ if(ExternalData_TIMEOUT_ABSOLUTE)
+ set(absolute_timeout TIMEOUT ${ExternalData_TIMEOUT_ABSOLUTE})
+ elseif(NOT "${ExternalData_TIMEOUT_ABSOLUTE}" EQUAL 0)
+ set(absolute_timeout TIMEOUT 300)
+ else()
+ set(absolute_timeout "")
+ endif()
+ file(DOWNLOAD "${url}" "${file}" STATUS status LOG log ${inactivity_timeout} ${absolute_timeout} SHOW_PROGRESS)
+ list(GET status 0 err)
+ list(GET status 1 msg)
+ if(err)
+ if("${msg}" MATCHES "HTTP response code said error" AND
+ "${log}" MATCHES "error: 503")
+ set(msg "temporarily unavailable")
+ endif()
+ elseif("${log}" MATCHES "\nHTTP[^\n]* 503")
+ set(err TRUE)
+ set(msg "temporarily unavailable")
+ endif()
+ if(NOT err OR NOT "${msg}" MATCHES "partial|timeout|temporarily")
+ break()
+ elseif(retry)
+ message(STATUS "[download terminated: ${msg}, retries left: ${retry}]")
+ endif()
+ endwhile()
+ set("${err_var}" "${err}" PARENT_SCOPE)
+ set("${msg_var}" "${msg}" PARENT_SCOPE)
+endfunction()
+
+function(_ExternalData_download_object name hash algo var_obj)
+ # Search all object stores for an existing object.
+ foreach(dir ${ExternalData_OBJECT_STORES})
+ set(obj "${dir}/${algo}/${hash}")
+ if(EXISTS "${obj}")
+ message(STATUS "Found object: \"${obj}\"")
+ set("${var_obj}" "${obj}" PARENT_SCOPE)
+ return()
+ endif()
+ endforeach()
+
+ # Download object to the first store.
+ list(GET ExternalData_OBJECT_STORES 0 store)
+ set(obj "${store}/${algo}/${hash}")
+
+ _ExternalData_random(random)
+ set(tmp "${obj}.tmp${random}")
+ set(found 0)
+ set(tried "")
+ foreach(url_template IN LISTS ExternalData_URL_TEMPLATES)
+ string(REPLACE "%(hash)" "${hash}" url_tmp "${url_template}")
+ string(REPLACE "%(algo)" "${algo}" url "${url_tmp}")
+ message(STATUS "Fetching \"${url}\"")
+ _ExternalData_download_file("${url}" "${tmp}" err errMsg)
+ set(tried "${tried}\n ${url}")
+ if(err)
+ set(tried "${tried} (${errMsg})")
+ else()
+ # Verify downloaded object.
+ _ExternalData_compute_hash(dl_hash "${algo}" "${tmp}")
+ if("${dl_hash}" STREQUAL "${hash}")
+ set(found 1)
+ break()
+ else()
+ set(tried "${tried} (wrong hash ${algo}=${dl_hash})")
+ if("$ENV{ExternalData_DEBUG_DOWNLOAD}" MATCHES ".")
+ file(RENAME "${tmp}" "${store}/${algo}/${dl_hash}")
+ endif()
+ endif()
+ endif()
+ file(REMOVE "${tmp}")
+ endforeach()
+
+ get_filename_component(dir "${name}" PATH)
+ set(staged "${dir}/.ExternalData_${algo}_${hash}")
+
+ if(found)
+ file(RENAME "${tmp}" "${obj}")
+ message(STATUS "Downloaded object: \"${obj}\"")
+ elseif(EXISTS "${staged}")
+ set(obj "${staged}")
+ message(STATUS "Staged object: \"${obj}\"")
+ else()
+ if(NOT tried)
+ set(tried "\n (No ExternalData_URL_TEMPLATES given)")
+ endif()
+ message(FATAL_ERROR "Object ${algo}=${hash} not found at:${tried}")
+ endif()
+
+ set("${var_obj}" "${obj}" PARENT_SCOPE)
+endfunction()
+
+if("${ExternalData_ACTION}" STREQUAL "fetch")
+ foreach(v ExternalData_OBJECT_STORES file name ext)
+ if(NOT DEFINED "${v}")
+ message(FATAL_ERROR "No \"-D${v}=\" value provided!")
+ endif()
+ endforeach()
+
+ file(READ "${name}${ext}" hash)
+ string(STRIP "${hash}" hash)
+
+ if("${ext}" MATCHES "^\\.(${_ExternalData_REGEX_EXT})$")
+ string(TOUPPER "${CMAKE_MATCH_1}" algo)
+ else()
+ message(FATAL_ERROR "Unknown hash algorithm extension \"${ext}\"")
+ endif()
+
+ _ExternalData_download_object("${name}" "${hash}" "${algo}" obj)
+
+ # Check if file already corresponds to the object.
+ set(stamp "${ext}-stamp")
+ set(file_up_to_date 0)
+ if(EXISTS "${file}" AND EXISTS "${file}${stamp}")
+ file(READ "${file}${stamp}" f_hash)
+ string(STRIP "${f_hash}" f_hash)
+ if("${f_hash}" STREQUAL "${hash}")
+ #message(STATUS "File already corresponds to object")
+ set(file_up_to_date 1)
+ endif()
+ endif()
+
+ if(file_up_to_date)
+ # Touch the file to convince the build system it is up to date.
+ execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${file}")
+ else()
+ _ExternalData_link_or_copy("${obj}" "${file}")
+ endif()
+
+ # Atomically update the hash/timestamp file to record the object referenced.
+ _ExternalData_atomic_write("${file}${stamp}" "${hash}\n")
+elseif("${ExternalData_ACTION}" STREQUAL "local")
+ foreach(v file name)
+ if(NOT DEFINED "${v}")
+ message(FATAL_ERROR "No \"-D${v}=\" value provided!")
+ endif()
+ endforeach()
+ _ExternalData_link_or_copy("${name}" "${file}")
+else()
+ message(FATAL_ERROR "Unknown ExternalData_ACTION=[${ExternalData_ACTION}]")
+endif()
diff --git a/Modules/ExternalData_config.cmake.in b/Modules/ExternalData_config.cmake.in
new file mode 100644
index 0000000000..0858f53688
--- /dev/null
+++ b/Modules/ExternalData_config.cmake.in
@@ -0,0 +1,4 @@
+set(ExternalData_OBJECT_STORES "@ExternalData_OBJECT_STORES@")
+set(ExternalData_URL_TEMPLATES "@ExternalData_URL_TEMPLATES@")
+set(ExternalData_TIMEOUT_INACTIVITY "@ExternalData_TIMEOUT_INACTIVITY@")
+set(ExternalData_TIMEOUT_ABSOLUTE "@ExternalData_TIMEOUT_ABSOLUTE@")
diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
new file mode 100644
index 0000000000..d6a6b7275a
--- /dev/null
+++ b/Modules/ExternalProject.cmake
@@ -0,0 +1,1992 @@
+#.rst:
+# ExternalProject
+# ---------------
+#
+# Create custom targets to build projects in external trees
+#
+# The ``ExternalProject_Add`` function creates a custom target to drive
+# download, update/patch, configure, build, install and test steps of an
+# external project:
+#
+# .. code-block:: cmake
+#
+# ExternalProject_Add(<name> # Name for custom target
+# [DEPENDS projects...] # Targets on which the project depends
+# [PREFIX dir] # Root dir for entire project
+# [LIST_SEPARATOR sep] # Sep to be replaced by ; in cmd lines
+# [TMP_DIR dir] # Directory to store temporary files
+# [STAMP_DIR dir] # Directory to store step timestamps
+# [EXCLUDE_FROM_ALL 1] # The "all" target does not depend on this
+# #--Download step--------------
+# [DOWNLOAD_NAME fname] # File name to store (if not end of URL)
+# [DOWNLOAD_DIR dir] # Directory to store downloaded files
+# [DOWNLOAD_COMMAND cmd...] # Command to download source tree
+# [DOWNLOAD_NO_PROGRESS 1] # Disable download progress reports
+# [CVS_REPOSITORY cvsroot] # CVSROOT of CVS repository
+# [CVS_MODULE mod] # Module to checkout from CVS repo
+# [CVS_TAG tag] # Tag to checkout from CVS repo
+# [SVN_REPOSITORY url] # URL of Subversion repo
+# [SVN_REVISION -r<rev>] # Revision to checkout from Subversion repo
+# [SVN_USERNAME john ] # Username for Subversion checkout and update
+# [SVN_PASSWORD doe ] # Password for Subversion checkout and update
+# [SVN_TRUST_CERT 1 ] # Trust the Subversion server site certificate
+# [GIT_REPOSITORY url] # URL of git repo
+# [GIT_TAG tag] # Git branch name, commit id or tag
+# [GIT_SUBMODULES modules...] # Git submodules that shall be updated, all if empty
+# [HG_REPOSITORY url] # URL of mercurial repo
+# [HG_TAG tag] # Mercurial branch name, commit id or tag
+# [URL /.../src.tgz] # Full path or URL of source
+# [URL_HASH ALGO=value] # Hash of file at URL
+# [URL_MD5 md5] # Equivalent to URL_HASH MD5=md5
+# [TLS_VERIFY bool] # Should certificate for https be checked
+# [TLS_CAINFO file] # Path to a certificate authority file
+# [TIMEOUT seconds] # Time allowed for file download operations
+# #--Update/Patch step----------
+# [UPDATE_COMMAND cmd...] # Source work-tree update command
+# [PATCH_COMMAND cmd...] # Command to patch downloaded source
+# #--Configure step-------------
+# [SOURCE_DIR dir] # Source dir to be used for build
+# [CONFIGURE_COMMAND cmd...] # Build tree configuration command
+# [CMAKE_COMMAND /.../cmake] # Specify alternative cmake executable
+# [CMAKE_GENERATOR gen] # Specify generator for native build
+# [CMAKE_GENERATOR_PLATFORM p] # Generator-specific platform name
+# [CMAKE_GENERATOR_TOOLSET t] # Generator-specific toolset name
+# [CMAKE_ARGS args...] # Arguments to CMake command line
+# [CMAKE_CACHE_ARGS args...] # Initial cache arguments, of the form -Dvar:string=on
+# #--Build step-----------------
+# [BINARY_DIR dir] # Specify build dir location
+# [BUILD_COMMAND cmd...] # Command to drive the native build
+# [BUILD_IN_SOURCE 1] # Use source dir for build dir
+# [BUILD_ALWAYS 1] # No stamp file, build step always runs
+# #--Install step---------------
+# [INSTALL_DIR dir] # Installation prefix
+# [INSTALL_COMMAND cmd...] # Command to drive install after build
+# #--Test step------------------
+# [TEST_BEFORE_INSTALL 1] # Add test step executed before install step
+# [TEST_AFTER_INSTALL 1] # Add test step executed after install step
+# [TEST_COMMAND cmd...] # Command to drive test
+# #--Output logging-------------
+# [LOG_DOWNLOAD 1] # Wrap download in script to log output
+# [LOG_UPDATE 1] # Wrap update in script to log output
+# [LOG_CONFIGURE 1] # Wrap configure in script to log output
+# [LOG_BUILD 1] # Wrap build in script to log output
+# [LOG_TEST 1] # Wrap test in script to log output
+# [LOG_INSTALL 1] # Wrap install in script to log output
+# #--Custom targets-------------
+# [STEP_TARGETS st1 st2 ...] # Generate custom targets for these steps
+# )
+#
+# The ``*_DIR`` options specify directories for the project, with default
+# directories computed as follows. If the ``PREFIX`` option is given to
+# ``ExternalProject_Add()`` or the ``EP_PREFIX`` directory property is set,
+# then an external project is built and installed under the specified prefix::
+#
+# TMP_DIR = <prefix>/tmp
+# STAMP_DIR = <prefix>/src/<name>-stamp
+# DOWNLOAD_DIR = <prefix>/src
+# SOURCE_DIR = <prefix>/src/<name>
+# BINARY_DIR = <prefix>/src/<name>-build
+# INSTALL_DIR = <prefix>
+#
+# Otherwise, if the ``EP_BASE`` directory property is set then components
+# of an external project are stored under the specified base::
+#
+# TMP_DIR = <base>/tmp/<name>
+# STAMP_DIR = <base>/Stamp/<name>
+# DOWNLOAD_DIR = <base>/Download/<name>
+# SOURCE_DIR = <base>/Source/<name>
+# BINARY_DIR = <base>/Build/<name>
+# INSTALL_DIR = <base>/Install/<name>
+#
+# If no ``PREFIX``, ``EP_PREFIX``, or ``EP_BASE`` is specified then the
+# default is to set ``PREFIX`` to ``<name>-prefix``. Relative paths are
+# interpreted with respect to the build directory corresponding to the
+# source directory in which ``ExternalProject_Add`` is invoked.
+#
+# If ``SOURCE_DIR`` is explicitly set to an existing directory the project
+# will be built from it. Otherwise a download step must be specified
+# using one of the ``DOWNLOAD_COMMAND``, ``CVS_*``, ``SVN_*``, or ``URL``
+# options. The ``URL`` option may refer locally to a directory or source
+# tarball, or refer to a remote tarball (e.g. ``http://.../src.tgz``).
+#
+# The ``ExternalProject_Add_Step`` function adds a custom step to an
+# external project:
+#
+# .. code-block:: cmake
+#
+# ExternalProject_Add_Step(<name> <step> # Names of project and custom step
+# [COMMAND cmd...] # Command line invoked by this step
+# [COMMENT "text..."] # Text printed when step executes
+# [DEPENDEES steps...] # Steps on which this step depends
+# [DEPENDERS steps...] # Steps that depend on this step
+# [DEPENDS files...] # Files on which this step depends
+# [ALWAYS 1] # No stamp file, step always runs
+# [EXCLUDE_FROM_MAIN 1] # Main target does not depend on this step
+# [WORKING_DIRECTORY dir] # Working directory for command
+# [LOG 1] # Wrap step in script to log output
+# )
+#
+# The command line, comment, and working directory of every standard and
+# custom step is processed to replace tokens ``<SOURCE_DIR>``,
+# ``<BINARY_DIR>``, ``<INSTALL_DIR>``, and ``<TMP_DIR>`` with
+# corresponding property values.
+#
+# Any builtin step that specifies a ``<step>_COMMAND cmd...`` or custom
+# step that specifies a ``COMMAND cmd...`` may specify additional command
+# lines using the form ``COMMAND cmd...``. At build time the commands
+# will be executed in order and aborted if any one fails. For example::
+#
+# ... BUILD_COMMAND make COMMAND echo done ...
+#
+# specifies to run ``make`` and then ``echo done`` during the build step.
+# Whether the current working directory is preserved between commands is
+# not defined. Behavior of shell operators like ``&&`` is not defined.
+#
+# The ``ExternalProject_Get_Property`` function retrieves external project
+# target properties::
+#
+# ExternalProject_Get_Property(<name> [prop1 [prop2 [...]]])
+#
+# It stores property values in variables of the same name. Property
+# names correspond to the keyword argument names of
+# ``ExternalProject_Add``.
+#
+# The ``ExternalProject_Add_StepTargets`` function generates custom
+# targets for the steps listed::
+#
+# ExternalProject_Add_StepTargets(<name> [step1 [step2 [...]]])
+#
+# If ``STEP_TARGETS`` is set then ``ExternalProject_Add_StepTargets`` is
+# automatically called at the end of matching calls to
+# ``ExternalProject_Add_Step``. Pass ``STEP_TARGETS`` explicitly to
+# individual ``ExternalProject_Add`` calls, or implicitly to all
+# ``ExternalProject_Add`` calls by setting the directory property
+# ``EP_STEP_TARGETS``.
+#
+# If ``STEP_TARGETS`` is not set, clients may still manually call
+# ``ExternalProject_Add_StepTargets`` after calling
+# ``ExternalProject_Add`` or ``ExternalProject_Add_Step``.
+#
+# This functionality is provided to make it easy to drive the steps
+# independently of each other by specifying targets on build command
+# lines. For example, you may be submitting to a sub-project based
+# dashboard, where you want to drive the configure portion of the build,
+# then submit to the dashboard, followed by the build portion, followed
+# by tests. If you invoke a custom target that depends on a step
+# halfway through the step dependency chain, then all the previous steps
+# will also run to ensure everything is up to date.
+#
+# For example, to drive configure, build and test steps independently
+# for each ``ExternalProject_Add`` call in your project, write the following
+# line prior to any ``ExternalProject_Add`` calls in your ``CMakeLists.txt``
+# file::
+#
+# set_property(DIRECTORY PROPERTY EP_STEP_TARGETS configure build test)
+
+#=============================================================================
+# Copyright 2008-2013 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.)
+
+# Pre-compute a regex to match documented keywords for each command.
+math(EXPR _ep_documentation_line_count "${CMAKE_CURRENT_LIST_LINE} - 16")
+file(STRINGS "${CMAKE_CURRENT_LIST_FILE}" lines
+ LIMIT_COUNT ${_ep_documentation_line_count}
+ REGEX "^# ( \\[[A-Z0-9_]+ [^]]*\\] +#.*$|[A-Za-z0-9_]+\\()")
+foreach(line IN LISTS lines)
+ if("${line}" MATCHES "^# ([A-Za-z0-9_]+)\\(")
+ if(_ep_func)
+ set(_ep_keywords_${_ep_func} "${_ep_keywords_${_ep_func}})$")
+ endif()
+ set(_ep_func "${CMAKE_MATCH_1}")
+ #message("function [${_ep_func}]")
+ set(_ep_keywords_${_ep_func} "^(")
+ set(_ep_keyword_sep)
+ else()
+ string(REGEX REPLACE "^# \\[([A-Z0-9_]+) .*" "\\1" _ep_key "${line}")
+ #message(" keyword [${_ep_key}]")
+ set(_ep_keywords_${_ep_func}
+ "${_ep_keywords_${_ep_func}}${_ep_keyword_sep}${_ep_key}")
+ set(_ep_keyword_sep "|")
+ endif()
+endforeach()
+if(_ep_func)
+ set(_ep_keywords_${_ep_func} "${_ep_keywords_${_ep_func}})$")
+endif()
+
+# Save regex matching supported hash algorithm names.
+set(_ep_hash_algos "MD5|SHA1|SHA224|SHA256|SHA384|SHA512")
+set(_ep_hash_regex "^(${_ep_hash_algos})=([0-9A-Fa-f]+)$")
+
+function(_ep_parse_arguments f name ns args)
+ # Transfer the arguments to this function into target properties for the
+ # new custom target we just added so that we can set up all the build steps
+ # correctly based on target properties.
+ #
+ # We loop through ARGN and consider the namespace starting with an
+ # upper-case letter followed by at least two more upper-case letters,
+ # numbers or underscores to be keywords.
+ set(key)
+
+ foreach(arg IN LISTS args)
+ set(is_value 1)
+
+ if(arg MATCHES "^[A-Z][A-Z0-9_][A-Z0-9_]+$" AND
+ NOT (("x${arg}x" STREQUAL "x${key}x") AND ("x${key}x" STREQUAL "xCOMMANDx")) AND
+ NOT arg MATCHES "^(TRUE|FALSE)$")
+ if(_ep_keywords_${f} AND arg MATCHES "${_ep_keywords_${f}}")
+ set(is_value 0)
+ endif()
+ endif()
+
+ if(is_value)
+ if(key)
+ # Value
+ if(NOT arg STREQUAL "")
+ set_property(TARGET ${name} APPEND PROPERTY ${ns}${key} "${arg}")
+ else()
+ get_property(have_key TARGET ${name} PROPERTY ${ns}${key} SET)
+ if(have_key)
+ get_property(value TARGET ${name} PROPERTY ${ns}${key})
+ set_property(TARGET ${name} PROPERTY ${ns}${key} "${value};${arg}")
+ else()
+ set_property(TARGET ${name} PROPERTY ${ns}${key} "${arg}")
+ endif()
+ endif()
+ else()
+ # Missing Keyword
+ message(AUTHOR_WARNING "value '${arg}' with no previous keyword in ${f}")
+ endif()
+ else()
+ set(key "${arg}")
+ endif()
+ endforeach()
+endfunction()
+
+
+define_property(DIRECTORY PROPERTY "EP_BASE" INHERITED
+ BRIEF_DOCS "Base directory for External Project storage."
+ FULL_DOCS
+ "See documentation of the ExternalProject_Add() function in the "
+ "ExternalProject module."
+ )
+
+define_property(DIRECTORY PROPERTY "EP_PREFIX" INHERITED
+ BRIEF_DOCS "Top prefix for External Project storage."
+ FULL_DOCS
+ "See documentation of the ExternalProject_Add() function in the "
+ "ExternalProject module."
+ )
+
+define_property(DIRECTORY PROPERTY "EP_STEP_TARGETS" INHERITED
+ BRIEF_DOCS
+ "List of ExternalProject steps that automatically get corresponding targets"
+ FULL_DOCS
+ "See documentation of the ExternalProject_Add_StepTargets() function in the "
+ "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)
+ file(WRITE ${script_filename}
+"if(\"${git_tag}\" STREQUAL \"\")
+ message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
+endif()
+
+set(run 0)
+
+if(\"${gitclone_infofile}\" IS_NEWER_THAN \"${gitclone_stampfile}\")
+ set(run 1)
+endif()
+
+if(NOT run)
+ message(STATUS \"Avoiding repeated git clone, stamp file is up to date: '${gitclone_stampfile}'\")
+ return()
+endif()
+
+execute_process(
+ COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
+ RESULT_VARIABLE error_code
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
+endif()
+
+# try the clone 3 times incase there is an odd git clone issue
+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}\"
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ )
+ math(EXPR number_of_tries \"\${number_of_tries} + 1\")
+endwhile()
+if(number_of_tries GREATER 1)
+ message(STATUS \"Had to git clone more than once:
+ \${number_of_tries} times.\")
+endif()
+if(error_code)
+ message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\")
+endif()
+
+execute_process(
+ COMMAND \"${git_EXECUTABLE}\" checkout ${git_tag}
+ WORKING_DIRECTORY \"${work_dir}/${src_name}\"
+ RESULT_VARIABLE error_code
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
+endif()
+
+execute_process(
+ COMMAND \"${git_EXECUTABLE}\" submodule init
+ WORKING_DIRECTORY \"${work_dir}/${src_name}\"
+ RESULT_VARIABLE error_code
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to init submodules in: '${work_dir}/${src_name}'\")
+endif()
+
+execute_process(
+ COMMAND \"${git_EXECUTABLE}\" submodule update --recursive ${git_submodules}
+ WORKING_DIRECTORY \"${work_dir}/${src_name}\"
+ RESULT_VARIABLE error_code
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\")
+endif()
+
+# Complete success, update the script-last-run stamp file:
+#
+execute_process(
+ COMMAND \${CMAKE_COMMAND} -E copy
+ \"${gitclone_infofile}\"
+ \"${gitclone_stampfile}\"
+ WORKING_DIRECTORY \"${work_dir}/${src_name}\"
+ RESULT_VARIABLE error_code
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to copy script-last-run stamp file: '${gitclone_stampfile}'\")
+endif()
+
+"
+)
+
+endfunction()
+
+function(_ep_write_hgclone_script script_filename source_dir hg_EXECUTABLE hg_repository hg_tag src_name work_dir hgclone_infofile hgclone_stampfile)
+ file(WRITE ${script_filename}
+"if(\"${hg_tag}\" STREQUAL \"\")
+ message(FATAL_ERROR \"Tag for hg checkout should not be empty.\")
+endif()
+
+set(run 0)
+
+if(\"${hgclone_infofile}\" IS_NEWER_THAN \"${hgclone_stampfile}\")
+ set(run 1)
+endif()
+
+if(NOT run)
+ message(STATUS \"Avoiding repeated hg clone, stamp file is up to date: '${hgclone_stampfile}'\")
+ return()
+endif()
+
+execute_process(
+ COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
+ RESULT_VARIABLE error_code
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
+endif()
+
+execute_process(
+ COMMAND \"${hg_EXECUTABLE}\" clone \"${hg_repository}\" \"${src_name}\"
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to clone repository: '${hg_repository}'\")
+endif()
+
+execute_process(
+ COMMAND \"${hg_EXECUTABLE}\" update ${hg_tag}
+ WORKING_DIRECTORY \"${work_dir}/${src_name}\"
+ RESULT_VARIABLE error_code
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to checkout tag: '${hg_tag}'\")
+endif()
+
+# Complete success, update the script-last-run stamp file:
+#
+execute_process(
+ COMMAND \${CMAKE_COMMAND} -E copy
+ \"${hgclone_infofile}\"
+ \"${hgclone_stampfile}\"
+ WORKING_DIRECTORY \"${work_dir}/${src_name}\"
+ RESULT_VARIABLE error_code
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to copy script-last-run stamp file: '${hgclone_stampfile}'\")
+endif()
+
+"
+)
+
+endfunction()
+
+
+function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_submodules git_repository work_dir)
+ file(WRITE ${script_filename}
+"if(\"${git_tag}\" STREQUAL \"\")
+ message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
+endif()
+
+execute_process(
+ COMMAND \"${git_EXECUTABLE}\" rev-list --max-count=1 HEAD
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ OUTPUT_VARIABLE head_sha
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+if(error_code)
+ message(FATAL_ERROR \"Failed to get the hash for HEAD\")
+endif()
+
+execute_process(
+ COMMAND \"${git_EXECUTABLE}\" show-ref ${git_tag}
+ WORKING_DIRECTORY \"${work_dir}\"
+ OUTPUT_VARIABLE show_ref_output
+ )
+# If a remote ref is asked for, which can possibly move around,
+# we must always do a fetch and checkout.
+if(\"\${show_ref_output}\" MATCHES \"remotes\")
+ set(is_remote_ref 1)
+else()
+ set(is_remote_ref 0)
+endif()
+
+# Tag is in the form <remote>/<tag> (i.e. origin/master) we must strip
+# the remote from the tag.
+if(\"\${show_ref_output}\" MATCHES \"refs/remotes/${git_tag}\")
+ string(REGEX MATCH \"^([^/]+)/(.+)$\" _unused \"${git_tag}\")
+ set(git_remote \"\${CMAKE_MATCH_1}\")
+ set(git_tag \"\${CMAKE_MATCH_2}\")
+else()
+ set(git_remote \"origin\")
+ set(git_tag \"${git_tag}\")
+endif()
+
+# This will fail if the tag does not exist (it probably has not been fetched
+# yet).
+execute_process(
+ COMMAND \"${git_EXECUTABLE}\" rev-list --max-count=1 ${git_tag}
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ OUTPUT_VARIABLE tag_sha
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+# Is the hash checkout out that we want?
+if(error_code OR is_remote_ref OR NOT (\"\${tag_sha}\" STREQUAL \"\${head_sha}\"))
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" fetch
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ )
+ if(error_code)
+ message(FATAL_ERROR \"Failed to fetch repository '${git_repository}'\")
+ endif()
+
+ if(is_remote_ref)
+ # Check if stash is needed
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" status --porcelain
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ OUTPUT_VARIABLE repo_status
+ )
+ if(error_code)
+ message(FATAL_ERROR \"Failed to get the status\")
+ endif()
+ string(LENGTH \"\${repo_status}\" need_stash)
+
+ # If not in clean state, stash changes in order to be able to be able to
+ # perform git pull --rebase
+ if(need_stash)
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" stash save --all --quiet
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ )
+ if(error_code)
+ message(FATAL_ERROR \"Failed to stash changes\")
+ endif()
+ endif()
+
+ # Pull changes from the remote branch
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" rebase \${git_remote}/\${git_tag}
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ )
+ if(error_code)
+ # Rebase failed: Restore previous state.
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" rebase --abort
+ WORKING_DIRECTORY \"${work_dir}\"
+ )
+ if(need_stash)
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet
+ WORKING_DIRECTORY \"${work_dir}\"
+ )
+ endif()
+ message(FATAL_ERROR \"\\nFailed to rebase in: '${work_dir}/${src_name}'.\\nYou will have to resolve the conflicts manually\")
+ endif()
+
+ if(need_stash)
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ )
+ if(error_code)
+ # Stash pop --index failed: Try again dropping the index
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" reset --hard --quiet
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ )
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" stash pop --quiet
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ )
+ if(error_code)
+ # Stash pop failed: Restore previous state.
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" reset --hard --quiet \${head_sha}
+ WORKING_DIRECTORY \"${work_dir}\"
+ )
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet
+ WORKING_DIRECTORY \"${work_dir}\"
+ )
+ message(FATAL_ERROR \"\\nFailed to unstash changes in: '${work_dir}/${src_name}'.\\nYou will have to resolve the conflicts manually\")
+ endif()
+ endif()
+ endif()
+ else()
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" checkout ${git_tag}
+ WORKING_DIRECTORY \"${work_dir}\"
+ RESULT_VARIABLE error_code
+ )
+ if(error_code)
+ message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
+ endif()
+ endif()
+
+ execute_process(
+ COMMAND \"${git_EXECUTABLE}\" submodule update --recursive ${git_submodules}
+ WORKING_DIRECTORY \"${work_dir}/${src_name}\"
+ RESULT_VARIABLE error_code
+ )
+ if(error_code)
+ message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\")
+ endif()
+endif()
+
+"
+)
+
+endfunction(_ep_write_gitupdate_script)
+
+function(_ep_write_downloadfile_script script_filename remote local timeout no_progress hash tls_verify tls_cainfo)
+ if(timeout)
+ set(timeout_args TIMEOUT ${timeout})
+ set(timeout_msg "${timeout} seconds")
+ else()
+ set(timeout_args "# no TIMEOUT")
+ set(timeout_msg "none")
+ endif()
+
+ if(no_progress)
+ set(show_progress "")
+ else()
+ set(show_progress "SHOW_PROGRESS")
+ endif()
+
+ # check for curl globals in the project
+ if(DEFINED CMAKE_TLS_VERIFY)
+ set(tls_verify "set(CMAKE_TLS_VERIFY ${CMAKE_TLS_VERIFY})")
+ endif()
+ if(DEFINED CMAKE_TLS_CAINFO)
+ set(tls_cainfo "set(CMAKE_TLS_CAINFO \"${CMAKE_TLS_CAINFO}\")")
+ endif()
+
+ # now check for curl locals so that the local values
+ # will override the globals
+
+ # check for tls_verify argument
+ string(LENGTH "${tls_verify}" tls_verify_len)
+ if(tls_verify_len GREATER 0)
+ set(tls_verify "set(CMAKE_TLS_VERIFY ${tls_verify})")
+ endif()
+ # check for tls_cainfo argument
+ string(LENGTH "${tls_cainfo}" tls_cainfo_len)
+ if(tls_cainfo_len GREATER 0)
+ set(tls_cainfo "set(CMAKE_TLS_CAINFO \"${tls_cainfo}\")")
+ endif()
+
+ file(WRITE ${script_filename}
+"message(STATUS \"downloading...
+ src='${remote}'
+ dst='${local}'
+ timeout='${timeout_msg}'\")
+
+${tls_verify}
+${tls_cainfo}
+
+file(DOWNLOAD
+ \"${remote}\"
+ \"${local}\"
+ ${show_progress}
+ ${timeout_args}
+ STATUS status
+ LOG log)
+
+list(GET status 0 status_code)
+list(GET status 1 status_string)
+
+if(NOT status_code EQUAL 0)
+ message(FATAL_ERROR \"error: downloading '${remote}' failed
+ status_code: \${status_code}
+ status_string: \${status_string}
+ log: \${log}
+\")
+endif()
+
+message(STATUS \"downloading... done\")
+"
+)
+
+endfunction()
+
+
+function(_ep_write_verifyfile_script script_filename local hash retries download_script)
+ if("${hash}" MATCHES "${_ep_hash_regex}")
+ set(algo "${CMAKE_MATCH_1}")
+ string(TOLOWER "${CMAKE_MATCH_2}" expect_value)
+ set(script_content "set(expect_value \"${expect_value}\")
+set(attempt 0)
+set(succeeded 0)
+while(\${attempt} LESS ${retries} OR \${attempt} EQUAL ${retries} AND NOT \${succeeded})
+ file(${algo} \"\${file}\" actual_value)
+ if(\"\${actual_value}\" STREQUAL \"\${expect_value}\")
+ set(succeeded 1)
+ elseif(\${attempt} LESS ${retries})
+ message(STATUS \"${algo} hash of \${file}
+does not match expected value
+ expected: \${expect_value}
+ actual: \${actual_value}
+Retrying download.
+\")
+ file(REMOVE \"\${file}\")
+ execute_process(COMMAND \${CMAKE_COMMAND} -P \"${download_script}\")
+ endif()
+ math(EXPR attempt \"\${attempt} + 1\")
+endwhile()
+
+if(\${succeeded})
+ message(STATUS \"verifying file... done\")
+else()
+ message(FATAL_ERROR \"error: ${algo} hash of
+ \${file}
+does not match expected value
+ expected: \${expect_value}
+ actual: \${actual_value}
+\")
+endif()")
+ else()
+ set(script_content "message(STATUS \"verifying file... warning: did not verify file - no URL_HASH specified?\")")
+ endif()
+ file(WRITE ${script_filename} "set(file \"${local}\")
+message(STATUS \"verifying file...
+ file='\${file}'\")
+${script_content}
+")
+endfunction()
+
+
+function(_ep_write_extractfile_script script_filename name filename directory)
+ set(args "")
+
+ if(filename MATCHES "(\\.|=)(7z|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
+ set(args xfz)
+ endif()
+
+ if(filename MATCHES "(\\.|=)tar$")
+ set(args xf)
+ endif()
+
+ if(args STREQUAL "")
+ message(SEND_ERROR "error: do not know how to extract '${filename}' -- known types are .7z, .tar, .tar.bz2, .tar.gz, .tar.xz, .tbz2, .tgz, .txz and .zip")
+ return()
+ endif()
+
+ file(WRITE ${script_filename}
+"# Make file names absolute:
+#
+get_filename_component(filename \"${filename}\" ABSOLUTE)
+get_filename_component(directory \"${directory}\" ABSOLUTE)
+
+message(STATUS \"extracting...
+ src='\${filename}'
+ dst='\${directory}'\")
+
+if(NOT EXISTS \"\${filename}\")
+ message(FATAL_ERROR \"error: file to extract does not exist: '\${filename}'\")
+endif()
+
+# Prepare a space for extracting:
+#
+set(i 1234)
+while(EXISTS \"\${directory}/../ex-${name}\${i}\")
+ math(EXPR i \"\${i} + 1\")
+endwhile()
+set(ut_dir \"\${directory}/../ex-${name}\${i}\")
+file(MAKE_DIRECTORY \"\${ut_dir}\")
+
+# Extract it:
+#
+message(STATUS \"extracting... [tar ${args}]\")
+execute_process(COMMAND \${CMAKE_COMMAND} -E tar ${args} \${filename}
+ WORKING_DIRECTORY \${ut_dir}
+ RESULT_VARIABLE rv)
+
+if(NOT rv EQUAL 0)
+ message(STATUS \"extracting... [error clean up]\")
+ file(REMOVE_RECURSE \"\${ut_dir}\")
+ message(FATAL_ERROR \"error: extract of '\${filename}' failed\")
+endif()
+
+# Analyze what came out of the tar file:
+#
+message(STATUS \"extracting... [analysis]\")
+file(GLOB contents \"\${ut_dir}/*\")
+list(LENGTH contents n)
+if(NOT n EQUAL 1 OR NOT IS_DIRECTORY \"\${contents}\")
+ set(contents \"\${ut_dir}\")
+endif()
+
+# Move \"the one\" directory to the final directory:
+#
+message(STATUS \"extracting... [rename]\")
+file(REMOVE_RECURSE \${directory})
+get_filename_component(contents \${contents} ABSOLUTE)
+file(RENAME \${contents} \${directory})
+
+# Clean up:
+#
+message(STATUS \"extracting... [clean up]\")
+file(REMOVE_RECURSE \"\${ut_dir}\")
+
+message(STATUS \"extracting... done\")
+"
+)
+
+endfunction()
+
+
+function(_ep_set_directories name)
+ get_property(prefix TARGET ${name} PROPERTY _EP_PREFIX)
+ if(NOT prefix)
+ get_property(prefix DIRECTORY PROPERTY EP_PREFIX)
+ if(NOT prefix)
+ get_property(base DIRECTORY PROPERTY EP_BASE)
+ if(NOT base)
+ set(prefix "${name}-prefix")
+ endif()
+ endif()
+ endif()
+ if(prefix)
+ set(tmp_default "${prefix}/tmp")
+ set(download_default "${prefix}/src")
+ set(source_default "${prefix}/src/${name}")
+ set(binary_default "${prefix}/src/${name}-build")
+ set(stamp_default "${prefix}/src/${name}-stamp")
+ set(install_default "${prefix}")
+ else()
+ set(tmp_default "${base}/tmp/${name}")
+ set(download_default "${base}/Download/${name}")
+ set(source_default "${base}/Source/${name}")
+ set(binary_default "${base}/Build/${name}")
+ set(stamp_default "${base}/Stamp/${name}")
+ set(install_default "${base}/Install/${name}")
+ endif()
+ get_property(build_in_source TARGET ${name} PROPERTY _EP_BUILD_IN_SOURCE)
+ if(build_in_source)
+ get_property(have_binary_dir TARGET ${name} PROPERTY _EP_BINARY_DIR SET)
+ if(have_binary_dir)
+ message(FATAL_ERROR
+ "External project ${name} has both BINARY_DIR and BUILD_IN_SOURCE!")
+ endif()
+ endif()
+ set(top "${CMAKE_CURRENT_BINARY_DIR}")
+ set(places stamp download source binary install tmp)
+ foreach(var ${places})
+ string(TOUPPER "${var}" VAR)
+ get_property(${var}_dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
+ if(NOT ${var}_dir)
+ set(${var}_dir "${${var}_default}")
+ endif()
+ if(NOT IS_ABSOLUTE "${${var}_dir}")
+ get_filename_component(${var}_dir "${top}/${${var}_dir}" ABSOLUTE)
+ endif()
+ set_property(TARGET ${name} PROPERTY _EP_${VAR}_DIR "${${var}_dir}")
+ endforeach()
+ if(build_in_source)
+ get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
+ set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}")
+ endif()
+
+ # Make the directories at CMake configure time *and* add a custom command
+ # to make them at build time. They need to exist at makefile generation
+ # time for Borland make and wmake so that CMake may generate makefiles
+ # with "cd C:\short\paths\with\no\spaces" commands in them.
+ #
+ # Additionally, the add_custom_command is still used in case somebody
+ # removes one of the necessary directories and tries to rebuild without
+ # re-running cmake.
+ foreach(var ${places})
+ string(TOUPPER "${var}" VAR)
+ get_property(dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
+ file(MAKE_DIRECTORY "${dir}")
+ if(NOT EXISTS "${dir}")
+ message(FATAL_ERROR "dir '${dir}' does not exist after file(MAKE_DIRECTORY)")
+ endif()
+ endforeach()
+endfunction()
+
+
+# IMPORTANT: this MUST be a macro and not a function because of the
+# in-place replacements that occur in each ${var}
+#
+macro(_ep_replace_location_tags target_name)
+ set(vars ${ARGN})
+ foreach(var ${vars})
+ if(${var})
+ foreach(dir SOURCE_DIR BINARY_DIR INSTALL_DIR TMP_DIR)
+ get_property(val TARGET ${target_name} PROPERTY _EP_${dir})
+ string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
+ endforeach()
+ endif()
+ endforeach()
+endmacro()
+
+
+function(_ep_write_initial_cache target_name script_filename args)
+ # Write out values into an initial cache, that will be passed to CMake with -C
+ set(script_initial_cache "")
+ set(regex "^([^:]+):([^=]+)=(.*)$")
+ set(setArg "")
+ foreach(line ${args})
+ if("${line}" MATCHES "^-D(.*)")
+ set(line "${CMAKE_MATCH_1}")
+ if(setArg)
+ # This is required to build up lists in variables, or complete an entry
+ set(setArg "${setArg}${accumulator}\" CACHE ${type} \"Initial cache\" FORCE)")
+ set(script_initial_cache "${script_initial_cache}\n${setArg}")
+ set(accumulator "")
+ set(setArg "")
+ endif()
+ if("${line}" MATCHES "${regex}")
+ set(name "${CMAKE_MATCH_1}")
+ set(type "${CMAKE_MATCH_2}")
+ set(value "${CMAKE_MATCH_3}")
+ set(setArg "set(${name} \"${value}")
+ else()
+ message(WARNING "Line '${line}' does not match regex. Ignoring.")
+ endif()
+ else()
+ # Assume this is a list to append to the last var
+ set(accumulator "${accumulator};${line}")
+ endif()
+ endforeach()
+ # Catch the final line of the args
+ if(setArg)
+ set(setArg "${setArg}${accumulator}\" CACHE ${type} \"Initial cache\" FORCE)")
+ set(script_initial_cache "${script_initial_cache}\n${setArg}")
+ endif()
+ # Replace location tags.
+ _ep_replace_location_tags(${target_name} script_initial_cache)
+ # Write out the initial cache file to the location specified.
+ if(NOT EXISTS "${script_filename}.in")
+ file(WRITE "${script_filename}.in" "\@script_initial_cache\@\n")
+ endif()
+ configure_file("${script_filename}.in" "${script_filename}")
+endfunction()
+
+
+function(ExternalProject_Get_Property name)
+ foreach(var ${ARGN})
+ string(TOUPPER "${var}" VAR)
+ get_property(${var} TARGET ${name} PROPERTY _EP_${VAR})
+ if(NOT ${var})
+ message(FATAL_ERROR "External project \"${name}\" has no ${var}")
+ endif()
+ set(${var} "${${var}}" PARENT_SCOPE)
+ endforeach()
+endfunction()
+
+
+function(_ep_get_configure_command_id name cfg_cmd_id_var)
+ get_target_property(cmd ${name} _EP_CONFIGURE_COMMAND)
+
+ if(cmd STREQUAL "")
+ # Explicit empty string means no configure step for this project
+ set(${cfg_cmd_id_var} "none" PARENT_SCOPE)
+ else()
+ if(NOT cmd)
+ # Default is "use cmake":
+ set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
+ else()
+ # Otherwise we have to analyze the value:
+ if(cmd MATCHES "^[^;]*/configure")
+ set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
+ elseif(cmd MATCHES "^[^;]*/cmake" AND NOT cmd MATCHES ";-[PE];")
+ set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
+ elseif(cmd MATCHES "config")
+ set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
+ else()
+ set(${cfg_cmd_id_var} "unknown:${cmd}" PARENT_SCOPE)
+ endif()
+ endif()
+ endif()
+endfunction()
+
+
+function(_ep_get_build_command name step cmd_var)
+ set(cmd "${${cmd_var}}")
+ if(NOT cmd)
+ set(args)
+ _ep_get_configure_command_id(${name} cfg_cmd_id)
+ if(cfg_cmd_id STREQUAL "cmake")
+ # CMake project. Select build command based on generator.
+ get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
+ if("${CMAKE_GENERATOR}" MATCHES "Make" AND
+ ("${cmake_generator}" MATCHES "Make" OR NOT cmake_generator))
+ # The project uses the same Makefile generator. Use recursive make.
+ set(cmd "$(MAKE)")
+ if(step STREQUAL "INSTALL")
+ set(args install)
+ endif()
+ if(step STREQUAL "TEST")
+ set(args test)
+ endif()
+ else()
+ # Drive the project with "cmake --build".
+ get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
+ if(cmake_command)
+ set(cmd "${cmake_command}")
+ else()
+ set(cmd "${CMAKE_COMMAND}")
+ endif()
+ set(args --build ${binary_dir} --config ${CMAKE_CFG_INTDIR})
+ if(step STREQUAL "INSTALL")
+ list(APPEND args --target install)
+ endif()
+ # But for "TEST" drive the project with corresponding "ctest".
+ if(step STREQUAL "TEST")
+ string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
+ set(args "")
+ endif()
+ endif()
+ else()
+ # Non-CMake project. Guess "make" and "make install" and "make test".
+ if("${CMAKE_GENERATOR}" MATCHES "Makefiles")
+ # Try to get the parallel arguments
+ set(cmd "$(MAKE)")
+ else()
+ set(cmd "make")
+ endif()
+ if(step STREQUAL "INSTALL")
+ set(args install)
+ endif()
+ if(step STREQUAL "TEST")
+ set(args test)
+ endif()
+ endif()
+
+ # Use user-specified arguments instead of default arguments, if any.
+ get_property(have_args TARGET ${name} PROPERTY _EP_${step}_ARGS SET)
+ if(have_args)
+ get_target_property(args ${name} _EP_${step}_ARGS)
+ endif()
+
+ list(APPEND cmd ${args})
+ endif()
+
+ set(${cmd_var} "${cmd}" PARENT_SCOPE)
+endfunction()
+
+function(_ep_write_log_script name step cmd_var)
+ ExternalProject_Get_Property(${name} stamp_dir)
+ set(command "${${cmd_var}}")
+
+ set(make "")
+ set(code_cygpath_make "")
+ if("${command}" MATCHES "^\\$\\(MAKE\\)")
+ # GNU make recognizes the string "$(MAKE)" as recursive make, so
+ # ensure that it appears directly in the makefile.
+ string(REGEX REPLACE "^\\$\\(MAKE\\)" "\${make}" command "${command}")
+ set(make "-Dmake=$(MAKE)")
+
+ if(WIN32 AND NOT CYGWIN)
+ set(code_cygpath_make "
+if(\${make} MATCHES \"^/\")
+ execute_process(
+ COMMAND cygpath -w \${make}
+ OUTPUT_VARIABLE cygpath_make
+ ERROR_VARIABLE cygpath_make
+ RESULT_VARIABLE cygpath_error
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(NOT cygpath_error)
+ set(make \${cygpath_make})
+ endif()
+endif()
+")
+ endif()
+ endif()
+
+ set(config "")
+ if("${CMAKE_CFG_INTDIR}" MATCHES "^\\$")
+ string(REPLACE "${CMAKE_CFG_INTDIR}" "\${config}" command "${command}")
+ set(config "-Dconfig=${CMAKE_CFG_INTDIR}")
+ endif()
+
+ # Wrap multiple 'COMMAND' lines up into a second-level wrapper
+ # script so all output can be sent to one log file.
+ if("${command}" MATCHES ";COMMAND;")
+ set(code_execute_process "
+${code_cygpath_make}
+execute_process(COMMAND \${command} RESULT_VARIABLE result)
+if(result)
+ set(msg \"Command failed (\${result}):\\n\")
+ foreach(arg IN LISTS command)
+ set(msg \"\${msg} '\${arg}'\")
+ endforeach()
+ message(FATAL_ERROR \"\${msg}\")
+endif()
+")
+ set(code "")
+ set(cmd "")
+ set(sep "")
+ foreach(arg IN LISTS command)
+ if("x${arg}" STREQUAL "xCOMMAND")
+ set(code "${code}set(command \"${cmd}\")${code_execute_process}")
+ set(cmd "")
+ set(sep "")
+ else()
+ set(cmd "${cmd}${sep}${arg}")
+ set(sep ";")
+ endif()
+ endforeach()
+ set(code "${code}set(command \"${cmd}\")${code_execute_process}")
+ file(WRITE ${stamp_dir}/${name}-${step}-impl.cmake "${code}")
+ set(command ${CMAKE_COMMAND} "-Dmake=\${make}" "-Dconfig=\${config}" -P ${stamp_dir}/${name}-${step}-impl.cmake)
+ endif()
+
+ # Wrap the command in a script to log output to files.
+ set(script ${stamp_dir}/${name}-${step}.cmake)
+ set(logbase ${stamp_dir}/${name}-${step})
+ file(WRITE ${script} "
+${code_cygpath_make}
+set(command \"${command}\")
+execute_process(
+ COMMAND \${command}
+ RESULT_VARIABLE result
+ OUTPUT_FILE \"${logbase}-out.log\"
+ ERROR_FILE \"${logbase}-err.log\"
+ )
+if(result)
+ set(msg \"Command failed: \${result}\\n\")
+ foreach(arg IN LISTS command)
+ set(msg \"\${msg} '\${arg}'\")
+ endforeach()
+ set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\\n\")
+ message(FATAL_ERROR \"\${msg}\")
+else()
+ set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\\n\")
+ message(STATUS \"\${msg}\")
+endif()
+")
+ set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script})
+ set(${cmd_var} "${command}" PARENT_SCOPE)
+endfunction()
+
+# This module used to use "/${CMAKE_CFG_INTDIR}" directly and produced
+# makefiles with "/./" in paths for custom command dependencies. Which
+# resulted in problems with parallel make -j invocations.
+#
+# This function was added so that the suffix (search below for ${cfgdir}) is
+# only set to "/${CMAKE_CFG_INTDIR}" when ${CMAKE_CFG_INTDIR} is not going to
+# be "." (multi-configuration build systems like Visual Studio and Xcode...)
+#
+function(_ep_get_configuration_subdir_suffix suffix_var)
+ set(suffix "")
+ if(CMAKE_CONFIGURATION_TYPES)
+ set(suffix "/${CMAKE_CFG_INTDIR}")
+ endif()
+ set(${suffix_var} "${suffix}" PARENT_SCOPE)
+endfunction()
+
+
+function(_ep_get_step_stampfile name step stampfile_var)
+ ExternalProject_Get_Property(${name} stamp_dir)
+
+ _ep_get_configuration_subdir_suffix(cfgdir)
+ set(stampfile "${stamp_dir}${cfgdir}/${name}-${step}")
+
+ set(${stampfile_var} "${stampfile}" PARENT_SCOPE)
+endfunction()
+
+
+function(ExternalProject_Add_StepTargets name)
+ set(steps ${ARGN})
+
+ foreach(step ${steps})
+ _ep_get_step_stampfile(${name} ${step} stamp_file)
+ add_custom_target(${name}-${step}
+ DEPENDS ${stamp_file})
+ set_property(TARGET ${name}-${step} PROPERTY LABELS ${name})
+ set_property(TARGET ${name}-${step} PROPERTY FOLDER "ExternalProjectTargets/${name}")
+
+ # Depend on other external projects (target-level).
+ get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
+ foreach(arg IN LISTS deps)
+ add_dependencies(${name}-${step} ${arg})
+ endforeach()
+ endforeach()
+endfunction()
+
+
+function(ExternalProject_Add_Step name step)
+ set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
+ _ep_get_configuration_subdir_suffix(cfgdir)
+
+ set(complete_stamp_file "${cmf_dir}${cfgdir}/${name}-complete")
+ _ep_get_step_stampfile(${name} ${step} stamp_file)
+
+ _ep_parse_arguments(ExternalProject_Add_Step
+ ${name} _EP_${step}_ "${ARGN}")
+
+ get_property(exclude_from_main TARGET ${name} PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN)
+ if(NOT exclude_from_main)
+ add_custom_command(APPEND
+ OUTPUT ${complete_stamp_file}
+ DEPENDS ${stamp_file}
+ )
+ endif()
+
+ # Steps depending on this step.
+ get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS)
+ foreach(depender IN LISTS dependers)
+ _ep_get_step_stampfile(${name} ${depender} depender_stamp_file)
+ add_custom_command(APPEND
+ OUTPUT ${depender_stamp_file}
+ DEPENDS ${stamp_file}
+ )
+ endforeach()
+
+ # Dependencies on files.
+ get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS)
+
+ # Dependencies on steps.
+ get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES)
+ foreach(dependee IN LISTS dependees)
+ _ep_get_step_stampfile(${name} ${dependee} dependee_stamp_file)
+ list(APPEND depends ${dependee_stamp_file})
+ endforeach()
+
+ # The command to run.
+ get_property(command TARGET ${name} PROPERTY _EP_${step}_COMMAND)
+ if(command)
+ set(comment "Performing ${step} step for '${name}'")
+ else()
+ set(comment "No ${step} step for '${name}'")
+ endif()
+ get_property(work_dir TARGET ${name} PROPERTY _EP_${step}_WORKING_DIRECTORY)
+
+ # Replace list separators.
+ get_property(sep TARGET ${name} PROPERTY _EP_LIST_SEPARATOR)
+ if(sep AND command)
+ string(REPLACE "${sep}" "\\;" command "${command}")
+ endif()
+
+ # Replace location tags.
+ _ep_replace_location_tags(${name} comment command work_dir)
+
+ # Custom comment?
+ get_property(comment_set TARGET ${name} PROPERTY _EP_${step}_COMMENT SET)
+ if(comment_set)
+ get_property(comment TARGET ${name} PROPERTY _EP_${step}_COMMENT)
+ endif()
+
+ # Run every time?
+ get_property(always TARGET ${name} PROPERTY _EP_${step}_ALWAYS)
+ if(always)
+ set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
+ set(touch)
+ else()
+ set(touch ${CMAKE_COMMAND} -E touch ${stamp_file})
+ endif()
+
+ # Wrap with log script?
+ get_property(log TARGET ${name} PROPERTY _EP_${step}_LOG)
+ if(command AND log)
+ _ep_write_log_script(${name} ${step} command)
+ endif()
+
+ add_custom_command(
+ OUTPUT ${stamp_file}
+ COMMENT ${comment}
+ COMMAND ${command}
+ COMMAND ${touch}
+ DEPENDS ${depends}
+ WORKING_DIRECTORY ${work_dir}
+ VERBATIM
+ )
+
+ # Add custom "step target"?
+ get_property(step_targets TARGET ${name} PROPERTY _EP_STEP_TARGETS)
+ if(NOT step_targets)
+ get_property(step_targets DIRECTORY PROPERTY EP_STEP_TARGETS)
+ endif()
+ foreach(st ${step_targets})
+ if("${st}" STREQUAL "${step}")
+ ExternalProject_Add_StepTargets(${name} ${step})
+ break()
+ endif()
+ endforeach()
+endfunction()
+
+
+function(_ep_add_mkdir_command name)
+ ExternalProject_Get_Property(${name}
+ source_dir binary_dir install_dir stamp_dir download_dir tmp_dir)
+
+ _ep_get_configuration_subdir_suffix(cfgdir)
+
+ ExternalProject_Add_Step(${name} mkdir
+ COMMENT "Creating directories for '${name}'"
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${source_dir}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${binary_dir}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${tmp_dir}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${stamp_dir}${cfgdir}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${download_dir}
+ )
+endfunction()
+
+
+function(_ep_get_git_version git_EXECUTABLE git_version_var)
+ if(git_EXECUTABLE)
+ execute_process(
+ COMMAND "${git_EXECUTABLE}" --version
+ OUTPUT_VARIABLE ov
+ ERROR_VARIABLE ev
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ string(REGEX REPLACE "^git version (.+)$" "\\1" version "${ov}")
+ set(${git_version_var} "${version}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+function(_ep_is_dir_empty dir empty_var)
+ file(GLOB gr "${dir}/*")
+ if("${gr}" STREQUAL "")
+ set(${empty_var} 1 PARENT_SCOPE)
+ else()
+ set(${empty_var} 0 PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+function(_ep_add_download_command name)
+ ExternalProject_Get_Property(${name} source_dir stamp_dir download_dir tmp_dir)
+
+ get_property(cmd_set TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND SET)
+ get_property(cmd TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND)
+ get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
+ get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
+ get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
+ get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
+ get_property(url TARGET ${name} PROPERTY _EP_URL)
+ get_property(fname TARGET ${name} PROPERTY _EP_DOWNLOAD_NAME)
+
+ # TODO: Perhaps file:// should be copied to download dir before extraction.
+ string(REGEX REPLACE "^file://" "" url "${url}")
+
+ set(depends)
+ set(comment)
+ set(work_dir)
+
+ if(cmd_set)
+ set(work_dir ${download_dir})
+ elseif(cvs_repository)
+ find_package(CVS QUIET)
+ if(NOT CVS_EXECUTABLE)
+ message(FATAL_ERROR "error: could not find cvs for checkout of ${name}")
+ endif()
+
+ get_target_property(cvs_module ${name} _EP_CVS_MODULE)
+ if(NOT cvs_module)
+ message(FATAL_ERROR "error: no CVS_MODULE")
+ endif()
+
+ get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
+
+ set(repository ${cvs_repository})
+ set(module ${cvs_module})
+ set(tag ${cvs_tag})
+ configure_file(
+ "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
+ "${stamp_dir}/${name}-cvsinfo.txt"
+ @ONLY
+ )
+
+ get_filename_component(src_name "${source_dir}" NAME)
+ get_filename_component(work_dir "${source_dir}" PATH)
+ set(comment "Performing download step (CVS checkout) for '${name}'")
+ set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q co ${cvs_tag} -d ${src_name} ${cvs_module})
+ list(APPEND depends ${stamp_dir}/${name}-cvsinfo.txt)
+ elseif(svn_repository)
+ find_package(Subversion QUIET)
+ if(NOT Subversion_SVN_EXECUTABLE)
+ message(FATAL_ERROR "error: could not find svn for checkout of ${name}")
+ endif()
+
+ get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
+ get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
+ get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
+ get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
+
+ set(repository "${svn_repository} user=${svn_username} password=${svn_password}")
+ set(module)
+ set(tag ${svn_revision})
+ configure_file(
+ "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
+ "${stamp_dir}/${name}-svninfo.txt"
+ @ONLY
+ )
+
+ get_filename_component(src_name "${source_dir}" NAME)
+ get_filename_component(work_dir "${source_dir}" PATH)
+ set(comment "Performing download step (SVN checkout) for '${name}'")
+ set(svn_user_pw_args "")
+ if(DEFINED svn_username)
+ set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
+ endif()
+ if(DEFINED svn_password)
+ set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
+ endif()
+ if(svn_trust_cert)
+ set(svn_trust_cert_args --trust-server-cert)
+ endif()
+ set(cmd ${Subversion_SVN_EXECUTABLE} co ${svn_repository} ${svn_revision}
+ --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args} ${src_name})
+ list(APPEND depends ${stamp_dir}/${name}-svninfo.txt)
+ elseif(git_repository)
+ find_package(Git QUIET)
+ if(NOT GIT_EXECUTABLE)
+ message(FATAL_ERROR "error: could not find git for clone of ${name}")
+ endif()
+
+ # The git submodule update '--recursive' flag requires git >= v1.6.5
+ #
+ _ep_get_git_version("${GIT_EXECUTABLE}" git_version)
+ if(git_version VERSION_LESS 1.6.5)
+ message(FATAL_ERROR "error: git version 1.6.5 or later required for 'git submodule update --recursive': git_version='${git_version}'")
+ endif()
+
+ get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
+ if(NOT git_tag)
+ set(git_tag "master")
+ endif()
+ get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
+
+ # 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
+ # changes, avoid running the clone script again. Let the 'always' running
+ # update step checkout the new tag.
+ #
+ set(repository ${git_repository})
+ set(module)
+ set(tag)
+ configure_file(
+ "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
+ "${stamp_dir}/${name}-gitinfo.txt"
+ @ONLY
+ )
+
+ get_filename_component(src_name "${source_dir}" NAME)
+ get_filename_component(work_dir "${source_dir}" PATH)
+
+ # Since git clone doesn't succeed if the non-empty source_dir exists,
+ # create a cmake script to invoke as download command.
+ # 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}
+ ${stamp_dir}/${name}-gitinfo.txt ${stamp_dir}/${name}-gitclone-lastrun.txt
+ )
+ set(comment "Performing download step (git clone) for '${name}'")
+ set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
+ list(APPEND depends ${stamp_dir}/${name}-gitinfo.txt)
+ elseif(hg_repository)
+ find_package(Hg QUIET)
+ if(NOT HG_EXECUTABLE)
+ message(FATAL_ERROR "error: could not find hg for clone of ${name}")
+ endif()
+
+ get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
+ if(NOT hg_tag)
+ set(hg_tag "tip")
+ endif()
+
+ # For the download step, and the hg 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
+ # changes, avoid running the clone script again. Let the 'always' running
+ # update step checkout the new tag.
+ #
+ set(repository ${hg_repository})
+ set(module)
+ set(tag)
+ configure_file(
+ "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
+ "${stamp_dir}/${name}-hginfo.txt"
+ @ONLY
+ )
+
+ get_filename_component(src_name "${source_dir}" NAME)
+ get_filename_component(work_dir "${source_dir}" PATH)
+
+ # Since hg clone doesn't succeed if the non-empty source_dir exists,
+ # create a cmake script to invoke as download command.
+ # The script will delete the source directory and then call hg clone.
+ #
+ _ep_write_hgclone_script(${tmp_dir}/${name}-hgclone.cmake ${source_dir}
+ ${HG_EXECUTABLE} ${hg_repository} ${hg_tag} ${src_name} ${work_dir}
+ ${stamp_dir}/${name}-hginfo.txt ${stamp_dir}/${name}-hgclone-lastrun.txt
+ )
+ set(comment "Performing download step (hg clone) for '${name}'")
+ set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-hgclone.cmake)
+ list(APPEND depends ${stamp_dir}/${name}-hginfo.txt)
+ elseif(url)
+ get_filename_component(work_dir "${source_dir}" PATH)
+ get_property(hash TARGET ${name} PROPERTY _EP_URL_HASH)
+ if(hash AND NOT "${hash}" MATCHES "${_ep_hash_regex}")
+ message(FATAL_ERROR "URL_HASH is set to\n ${hash}\n"
+ "but must be ALGO=value where ALGO is\n ${_ep_hash_algos}\n"
+ "and value is a hex string.")
+ endif()
+ get_property(md5 TARGET ${name} PROPERTY _EP_URL_MD5)
+ if(md5 AND NOT "MD5=${md5}" MATCHES "${_ep_hash_regex}")
+ message(FATAL_ERROR "URL_MD5 is set to\n ${md5}\nbut must be a hex string.")
+ endif()
+ if(md5 AND NOT hash)
+ set(hash "MD5=${md5}")
+ endif()
+ set(repository "external project URL")
+ set(module "${url}")
+ set(tag "${hash}")
+ set(retries 0)
+ set(download_script "")
+ configure_file(
+ "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
+ "${stamp_dir}/${name}-urlinfo.txt"
+ @ONLY
+ )
+ list(APPEND depends ${stamp_dir}/${name}-urlinfo.txt)
+ if(IS_DIRECTORY "${url}")
+ get_filename_component(abs_dir "${url}" ABSOLUTE)
+ set(comment "Performing download step (DIR copy) for '${name}'")
+ set(cmd ${CMAKE_COMMAND} -E remove_directory ${source_dir}
+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir})
+ else()
+ if("${url}" MATCHES "^[a-z]+://")
+ # TODO: Should download and extraction be different steps?
+ if("x${fname}" STREQUAL "x")
+ string(REGEX MATCH "[^/\\?]*$" fname "${url}")
+ endif()
+ if(NOT "${fname}" MATCHES "(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
+ string(REGEX MATCH "([^/\\?]+(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip))/.*$" match_result "${url}")
+ set(fname "${CMAKE_MATCH_1}")
+ endif()
+ if(NOT "${fname}" MATCHES "(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
+ message(FATAL_ERROR "Could not extract tarball filename from url:\n ${url}")
+ endif()
+ string(REPLACE ";" "-" fname "${fname}")
+ set(file ${download_dir}/${fname})
+ get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT)
+ get_property(no_progress TARGET ${name} PROPERTY _EP_DOWNLOAD_NO_PROGRESS)
+ get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
+ get_property(tls_cainfo TARGET ${name} PROPERTY _EP_TLS_CAINFO)
+ set(download_script "${stamp_dir}/download-${name}.cmake")
+ _ep_write_downloadfile_script("${download_script}" "${url}" "${file}" "${timeout}" "${no_progress}" "${hash}" "${tls_verify}" "${tls_cainfo}")
+ set(cmd ${CMAKE_COMMAND} -P "${download_script}"
+ COMMAND)
+ set(retries 3)
+ set(comment "Performing download step (download, verify and extract) for '${name}'")
+ else()
+ set(file "${url}")
+ set(comment "Performing download step (verify and extract) for '${name}'")
+ endif()
+ _ep_write_verifyfile_script("${stamp_dir}/verify-${name}.cmake" "${file}" "${hash}" "${retries}" "${download_script}")
+ list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake
+ COMMAND)
+ _ep_write_extractfile_script("${stamp_dir}/extract-${name}.cmake" "${name}" "${file}" "${source_dir}")
+ list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake)
+ endif()
+ else()
+ _ep_is_dir_empty("${source_dir}" empty)
+ if(${empty})
+ message(SEND_ERROR "error: no download info for '${name}' -- please specify existing/non-empty SOURCE_DIR or one of URL, CVS_REPOSITORY and CVS_MODULE, SVN_REPOSITORY, GIT_REPOSITORY, HG_REPOSITORY or DOWNLOAD_COMMAND")
+ endif()
+ endif()
+
+ get_property(log TARGET ${name} PROPERTY _EP_LOG_DOWNLOAD)
+ if(log)
+ set(log LOG 1)
+ else()
+ set(log "")
+ endif()
+
+ ExternalProject_Add_Step(${name} download
+ COMMENT ${comment}
+ COMMAND ${cmd}
+ WORKING_DIRECTORY ${work_dir}
+ DEPENDS ${depends}
+ DEPENDEES mkdir
+ ${log}
+ )
+endfunction()
+
+
+function(_ep_add_update_command name)
+ ExternalProject_Get_Property(${name} source_dir tmp_dir)
+
+ get_property(cmd_set TARGET ${name} PROPERTY _EP_UPDATE_COMMAND SET)
+ get_property(cmd TARGET ${name} PROPERTY _EP_UPDATE_COMMAND)
+ get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
+ get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
+ get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
+ get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
+
+ set(work_dir)
+ set(comment)
+ set(always)
+
+ if(cmd_set)
+ set(work_dir ${source_dir})
+ elseif(cvs_repository)
+ if(NOT CVS_EXECUTABLE)
+ message(FATAL_ERROR "error: could not find cvs for update of ${name}")
+ endif()
+ set(work_dir ${source_dir})
+ set(comment "Performing update step (CVS update) for '${name}'")
+ get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
+ set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag})
+ set(always 1)
+ elseif(svn_repository)
+ if(NOT Subversion_SVN_EXECUTABLE)
+ message(FATAL_ERROR "error: could not find svn for update of ${name}")
+ endif()
+ set(work_dir ${source_dir})
+ set(comment "Performing update step (SVN update) for '${name}'")
+ get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
+ get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
+ get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
+ get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
+ set(svn_user_pw_args "")
+ if(DEFINED svn_username)
+ set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
+ endif()
+ if(DEFINED svn_password)
+ set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
+ endif()
+ if(svn_trust_cert)
+ set(svn_trust_cert_args --trust-server-cert)
+ endif()
+ set(cmd ${Subversion_SVN_EXECUTABLE} up ${svn_revision}
+ --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args})
+ set(always 1)
+ elseif(git_repository)
+ if(NOT GIT_EXECUTABLE)
+ message(FATAL_ERROR "error: could not find git for fetch of ${name}")
+ endif()
+ set(work_dir ${source_dir})
+ set(comment "Performing update step for '${name}'")
+ get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
+ if(NOT git_tag)
+ set(git_tag "master")
+ 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}
+ )
+ set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitupdate.cmake)
+ set(always 1)
+ elseif(hg_repository)
+ if(NOT HG_EXECUTABLE)
+ message(FATAL_ERROR "error: could not find hg for pull of ${name}")
+ endif()
+ set(work_dir ${source_dir})
+ set(comment "Performing update step (hg pull) for '${name}'")
+ get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
+ if(NOT hg_tag)
+ set(hg_tag "tip")
+ endif()
+ if("${HG_VERSION_STRING}" STREQUAL "2.1")
+ message(WARNING "Mercurial 2.1 does not distinguish an empty pull from a failed pull:
+ http://mercurial.selenic.com/wiki/UpgradeNotes#A2.1.1:_revert_pull_return_code_change.2C_compile_issue_on_OS_X
+ http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/47656
+Update to Mercurial >= 2.1.1.
+")
+ endif()
+ set(cmd ${HG_EXECUTABLE} pull
+ COMMAND ${HG_EXECUTABLE} update ${hg_tag}
+ )
+ set(always 1)
+ endif()
+
+ get_property(log TARGET ${name} PROPERTY _EP_LOG_UPDATE)
+ if(log)
+ set(log LOG 1)
+ else()
+ set(log "")
+ endif()
+
+ ExternalProject_Add_Step(${name} update
+ COMMENT ${comment}
+ COMMAND ${cmd}
+ ALWAYS ${always}
+ WORKING_DIRECTORY ${work_dir}
+ DEPENDEES download
+ ${log}
+ )
+endfunction()
+
+
+function(_ep_add_patch_command name)
+ ExternalProject_Get_Property(${name} source_dir)
+
+ get_property(cmd_set TARGET ${name} PROPERTY _EP_PATCH_COMMAND SET)
+ get_property(cmd TARGET ${name} PROPERTY _EP_PATCH_COMMAND)
+
+ set(work_dir)
+
+ if(cmd_set)
+ set(work_dir ${source_dir})
+ endif()
+
+ ExternalProject_Add_Step(${name} patch
+ COMMAND ${cmd}
+ WORKING_DIRECTORY ${work_dir}
+ DEPENDEES download
+ )
+endfunction()
+
+
+# TODO: Make sure external projects use the proper compiler
+function(_ep_add_configure_command name)
+ ExternalProject_Get_Property(${name} source_dir binary_dir tmp_dir)
+
+ # Depend on other external projects (file-level).
+ set(file_deps)
+ get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
+ foreach(dep IN LISTS deps)
+ get_property(is_ep TARGET ${dep} PROPERTY _EP_IS_EXTERNAL_PROJECT)
+ if(is_ep)
+ _ep_get_step_stampfile(${dep} "done" done_stamp_file)
+ list(APPEND file_deps ${done_stamp_file})
+ endif()
+ endforeach()
+
+ get_property(cmd_set TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND SET)
+ if(cmd_set)
+ get_property(cmd TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND)
+ else()
+ get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
+ if(cmake_command)
+ set(cmd "${cmake_command}")
+ else()
+ set(cmd "${CMAKE_COMMAND}")
+ endif()
+
+ get_property(cmake_args TARGET ${name} PROPERTY _EP_CMAKE_ARGS)
+ list(APPEND cmd ${cmake_args})
+
+ # If there are any CMAKE_CACHE_ARGS, write an initial cache and use it
+ get_property(cmake_cache_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_ARGS)
+ if(cmake_cache_args)
+ set(_ep_cache_args_script "${tmp_dir}/${name}-cache.cmake")
+ _ep_write_initial_cache(${name} "${_ep_cache_args_script}" "${cmake_cache_args}")
+ list(APPEND cmd "-C${_ep_cache_args_script}")
+ endif()
+
+ get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
+ get_target_property(cmake_generator_platform ${name} _EP_CMAKE_GENERATOR_PLATFORM)
+ get_target_property(cmake_generator_toolset ${name} _EP_CMAKE_GENERATOR_TOOLSET)
+ if(cmake_generator)
+ list(APPEND cmd "-G${cmake_generator}")
+ if(cmake_generator_platform)
+ list(APPEND cmd "-A${cmake_generator_platform}")
+ endif()
+ if(cmake_generator_toolset)
+ list(APPEND cmd "-T${cmake_generator_toolset}")
+ endif()
+ else()
+ if(CMAKE_EXTRA_GENERATOR)
+ list(APPEND cmd "-G${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
+ else()
+ list(APPEND cmd "-G${CMAKE_GENERATOR}")
+ endif()
+ if(cmake_generator_platform)
+ message(FATAL_ERROR "Option CMAKE_GENERATOR_PLATFORM not allowed without CMAKE_GENERATOR.")
+ endif()
+ if(CMAKE_GENERATOR_PLATFORM)
+ list(APPEND cmd "-A${CMAKE_GENERATOR_PLATFORM}")
+ endif()
+ if(cmake_generator_toolset)
+ message(FATAL_ERROR "Option CMAKE_GENERATOR_TOOLSET not allowed without CMAKE_GENERATOR.")
+ endif()
+ if(CMAKE_GENERATOR_TOOLSET)
+ list(APPEND cmd "-T${CMAKE_GENERATOR_TOOLSET}")
+ endif()
+ endif()
+
+ list(APPEND cmd "${source_dir}")
+ endif()
+
+ # If anything about the configure command changes, (command itself, cmake
+ # used, cmake args or cmake generator) then re-run the configure step.
+ # Fixes issue http://public.kitware.com/Bug/view.php?id=10258
+ #
+ if(NOT EXISTS ${tmp_dir}/${name}-cfgcmd.txt.in)
+ file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='\@cmd\@'\n")
+ endif()
+ configure_file(${tmp_dir}/${name}-cfgcmd.txt.in ${tmp_dir}/${name}-cfgcmd.txt)
+ list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt)
+ list(APPEND file_deps ${_ep_cache_args_script})
+
+ get_property(log TARGET ${name} PROPERTY _EP_LOG_CONFIGURE)
+ if(log)
+ set(log LOG 1)
+ else()
+ set(log "")
+ endif()
+
+ ExternalProject_Add_Step(${name} configure
+ COMMAND ${cmd}
+ WORKING_DIRECTORY ${binary_dir}
+ DEPENDEES update patch
+ DEPENDS ${file_deps}
+ ${log}
+ )
+endfunction()
+
+
+function(_ep_add_build_command name)
+ ExternalProject_Get_Property(${name} binary_dir)
+
+ get_property(cmd_set TARGET ${name} PROPERTY _EP_BUILD_COMMAND SET)
+ if(cmd_set)
+ get_property(cmd TARGET ${name} PROPERTY _EP_BUILD_COMMAND)
+ else()
+ _ep_get_build_command(${name} BUILD cmd)
+ endif()
+
+ get_property(log TARGET ${name} PROPERTY _EP_LOG_BUILD)
+ if(log)
+ set(log LOG 1)
+ else()
+ set(log "")
+ endif()
+
+ get_property(build_always TARGET ${name} PROPERTY _EP_BUILD_ALWAYS)
+ if(build_always)
+ set(always 1)
+ else()
+ set(always 0)
+ endif()
+
+ ExternalProject_Add_Step(${name} build
+ COMMAND ${cmd}
+ WORKING_DIRECTORY ${binary_dir}
+ DEPENDEES configure
+ ALWAYS ${always}
+ ${log}
+ )
+endfunction()
+
+
+function(_ep_add_install_command name)
+ ExternalProject_Get_Property(${name} binary_dir)
+
+ get_property(cmd_set TARGET ${name} PROPERTY _EP_INSTALL_COMMAND SET)
+ if(cmd_set)
+ get_property(cmd TARGET ${name} PROPERTY _EP_INSTALL_COMMAND)
+ else()
+ _ep_get_build_command(${name} INSTALL cmd)
+ endif()
+
+ get_property(log TARGET ${name} PROPERTY _EP_LOG_INSTALL)
+ if(log)
+ set(log LOG 1)
+ else()
+ set(log "")
+ endif()
+
+ ExternalProject_Add_Step(${name} install
+ COMMAND ${cmd}
+ WORKING_DIRECTORY ${binary_dir}
+ DEPENDEES build
+ ${log}
+ )
+endfunction()
+
+
+function(_ep_add_test_command name)
+ ExternalProject_Get_Property(${name} binary_dir)
+
+ get_property(before TARGET ${name} PROPERTY _EP_TEST_BEFORE_INSTALL)
+ get_property(after TARGET ${name} PROPERTY _EP_TEST_AFTER_INSTALL)
+ get_property(cmd_set TARGET ${name} PROPERTY _EP_TEST_COMMAND SET)
+
+ # Only actually add the test step if one of the test related properties is
+ # explicitly set. (i.e. the test step is omitted unless requested...)
+ #
+ if(cmd_set OR before OR after)
+ if(cmd_set)
+ get_property(cmd TARGET ${name} PROPERTY _EP_TEST_COMMAND)
+ else()
+ _ep_get_build_command(${name} TEST cmd)
+ endif()
+
+ if(before)
+ set(dep_args DEPENDEES build DEPENDERS install)
+ else()
+ set(dep_args DEPENDEES install)
+ endif()
+
+ get_property(log TARGET ${name} PROPERTY _EP_LOG_TEST)
+ if(log)
+ set(log LOG 1)
+ else()
+ set(log "")
+ endif()
+
+ ExternalProject_Add_Step(${name} test
+ COMMAND ${cmd}
+ WORKING_DIRECTORY ${binary_dir}
+ ${dep_args}
+ ${log}
+ )
+ endif()
+endfunction()
+
+
+function(ExternalProject_Add name)
+ _ep_get_configuration_subdir_suffix(cfgdir)
+
+ # Add a custom target for the external project.
+ set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
+ set(complete_stamp_file "${cmf_dir}${cfgdir}/${name}-complete")
+
+ # The "ALL" option to add_custom_target just tells it to not set the
+ # EXCLUDE_FROM_ALL target property. Later, if the EXCLUDE_FROM_ALL
+ # argument was passed, we explicitly set it for the target.
+ add_custom_target(${name} ALL DEPENDS ${complete_stamp_file})
+ set_property(TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT 1)
+ set_property(TARGET ${name} PROPERTY LABELS ${name})
+ set_property(TARGET ${name} PROPERTY FOLDER "ExternalProjectTargets/${name}")
+
+ _ep_parse_arguments(ExternalProject_Add ${name} _EP_ "${ARGN}")
+ _ep_set_directories(${name})
+ _ep_get_step_stampfile(${name} "done" done_stamp_file)
+ _ep_get_step_stampfile(${name} "install" install_stamp_file)
+
+ # Set the EXCLUDE_FROM_ALL target property if required.
+ get_property(exclude_from_all TARGET ${name} PROPERTY _EP_EXCLUDE_FROM_ALL)
+ if(exclude_from_all)
+ set_property(TARGET ${name} PROPERTY EXCLUDE_FROM_ALL TRUE)
+ endif()
+
+ # The 'complete' step depends on all other steps and creates a
+ # 'done' mark. A dependent external project's 'configure' step
+ # depends on the 'done' mark so that it rebuilds when this project
+ # rebuilds. It is important that 'done' is not the output of any
+ # custom command so that CMake does not propagate build rules to
+ # other external project targets, which may cause problems during
+ # parallel builds. However, the Ninja generator needs to see the entire
+ # dependency graph, and can cope with custom commands belonging to
+ # multiple targets, so we add the 'done' mark as an output for Ninja only.
+ set(complete_outputs ${complete_stamp_file})
+ if(${CMAKE_GENERATOR} MATCHES "Ninja")
+ set(complete_outputs ${complete_outputs} ${done_stamp_file})
+ endif()
+
+ add_custom_command(
+ OUTPUT ${complete_outputs}
+ COMMENT "Completed '${name}'"
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir}
+ COMMAND ${CMAKE_COMMAND} -E touch ${complete_stamp_file}
+ COMMAND ${CMAKE_COMMAND} -E touch ${done_stamp_file}
+ DEPENDS ${install_stamp_file}
+ VERBATIM
+ )
+
+
+ # Depend on other external projects (target-level).
+ get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
+ foreach(arg IN LISTS deps)
+ add_dependencies(${name} ${arg})
+ endforeach()
+
+ # Set up custom build steps based on the target properties.
+ # Each step depends on the previous one.
+ #
+ # The target depends on the output of the final step.
+ # (Already set up above in the DEPENDS of the add_custom_target command.)
+ #
+ _ep_add_mkdir_command(${name})
+ _ep_add_download_command(${name})
+ _ep_add_update_command(${name})
+ _ep_add_patch_command(${name})
+ _ep_add_configure_command(${name})
+ _ep_add_build_command(${name})
+ _ep_add_install_command(${name})
+
+ # Test is special in that it might depend on build, or it might depend
+ # on install.
+ #
+ _ep_add_test_command(${name})
+endfunction()
diff --git a/Modules/FLTKCompatibility.cmake b/Modules/FLTKCompatibility.cmake
new file mode 100644
index 0000000000..58c52da344
--- /dev/null
+++ b/Modules/FLTKCompatibility.cmake
@@ -0,0 +1,15 @@
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+include(CheckIncludeFile)
diff --git a/Modules/FeatureSummary.cmake b/Modules/FeatureSummary.cmake
new file mode 100644
index 0000000000..12ea384773
--- /dev/null
+++ b/Modules/FeatureSummary.cmake
@@ -0,0 +1,573 @@
+#.rst:
+# FeatureSummary
+# --------------
+#
+# Macros for generating a summary of enabled/disabled features
+#
+#
+#
+# This module provides the macros feature_summary(),
+# set_package_properties() and add_feature_info(). For compatibility it
+# also still provides set_package_info(), set_feature_info(),
+# print_enabled_features() and print_disabled_features().
+#
+# These macros can be used to generate a summary of enabled and disabled
+# packages and/or feature for a build tree:
+#
+# ::
+#
+# -- The following OPTIONAL packages have been found:
+# LibXml2 (required version >= 2.4) , XML processing library. , <http://xmlsoft.org>
+# * Enables HTML-import in MyWordProcessor
+# * Enables odt-export in MyWordProcessor
+# PNG , A PNG image library. , <http://www.libpng.org/pub/png/>
+# * Enables saving screenshots
+# -- The following OPTIONAL packages have not been found:
+# Lua51 , The Lua scripting language. , <http://www.lua.org>
+# * Enables macros in MyWordProcessor
+# Foo , Foo provides cool stuff.
+#
+#
+#
+#
+#
+# ::
+#
+# FEATURE_SUMMARY( [FILENAME <file>]
+# [APPEND]
+# [VAR <variable_name>]
+# [INCLUDE_QUIET_PACKAGES]
+# [FATAL_ON_MISSING_REQUIRED_PACKAGES]
+# [DESCRIPTION "Found packages:"]
+# WHAT (ALL | PACKAGES_FOUND | PACKAGES_NOT_FOUND
+# | ENABLED_FEATURES | DISABLED_FEATURES]
+# )
+#
+#
+#
+# The FEATURE_SUMMARY() macro can be used to print information about
+# enabled or disabled packages or features of a project. By default,
+# only the names of the features/packages will be printed and their
+# required version when one was specified. Use SET_PACKAGE_PROPERTIES()
+# to add more useful information, like e.g. a download URL for the
+# respective package or their purpose in the project.
+#
+# The WHAT option is the only mandatory option. Here you specify what
+# information will be printed:
+#
+# ::
+#
+# ALL: print everything
+# ENABLED_FEATURES: the list of all features which are enabled
+# DISABLED_FEATURES: the list of all features which are disabled
+# PACKAGES_FOUND: the list of all packages which have been found
+# PACKAGES_NOT_FOUND: the list of all packages which have not been found
+# OPTIONAL_PACKAGES_FOUND: only those packages which have been found which have the type OPTIONAL
+# OPTIONAL_PACKAGES_NOT_FOUND: only those packages which have not been found which have the type OPTIONAL
+# RECOMMENDED_PACKAGES_FOUND: only those packages which have been found which have the type RECOMMENDED
+# RECOMMENDED_PACKAGES_NOT_FOUND: only those packages which have not been found which have the type RECOMMENDED
+# REQUIRED_PACKAGES_FOUND: only those packages which have been found which have the type REQUIRED
+# REQUIRED_PACKAGES_NOT_FOUND: only those packages which have not been found which have the type REQUIRED
+# RUNTIME_PACKAGES_FOUND: only those packages which have been found which have the type RUNTIME
+# RUNTIME_PACKAGES_NOT_FOUND: only those packages which have not been found which have the type RUNTIME
+#
+# With the exception of the ``ALL`` value, these values can be combined
+# in order to customize the output. For example:
+#
+# ::
+#
+# feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
+#
+#
+#
+# If a FILENAME is given, the information is printed into this file. If
+# APPEND is used, it is appended to this file, otherwise the file is
+# overwritten if it already existed. If the VAR option is used, the
+# information is "printed" into the specified variable. If FILENAME is
+# not used, the information is printed to the terminal. Using the
+# DESCRIPTION option a description or headline can be set which will be
+# printed above the actual content. If INCLUDE_QUIET_PACKAGES is given,
+# packages which have been searched with find_package(... QUIET) will
+# also be listed. By default they are skipped. If
+# FATAL_ON_MISSING_REQUIRED_PACKAGES is given, CMake will abort if a
+# package which is marked as REQUIRED has not been found.
+#
+# Example 1, append everything to a file:
+#
+# ::
+#
+# feature_summary(WHAT ALL
+# FILENAME ${CMAKE_BINARY_DIR}/all.log APPEND)
+#
+#
+#
+# Example 2, print the enabled features into the variable
+# enabledFeaturesText, including QUIET packages:
+#
+# ::
+#
+# feature_summary(WHAT ENABLED_FEATURES
+# INCLUDE_QUIET_PACKAGES
+# DESCRIPTION "Enabled Features:"
+# VAR enabledFeaturesText)
+# message(STATUS "${enabledFeaturesText}")
+#
+#
+#
+#
+#
+# ::
+#
+# SET_PACKAGE_PROPERTIES(<name> PROPERTIES [ URL <url> ]
+# [ DESCRIPTION <description> ]
+# [ TYPE (RUNTIME|OPTIONAL|RECOMMENDED|REQUIRED) ]
+# [ PURPOSE <purpose> ]
+# )
+#
+#
+#
+# Use this macro to set up information about the named package, which
+# can then be displayed via FEATURE_SUMMARY(). This can be done either
+# directly in the Find-module or in the project which uses the module
+# after the find_package() call. The features for which information can
+# be set are added automatically by the find_package() command.
+#
+# URL: this should be the homepage of the package, or something similar.
+# Ideally this is set already directly in the Find-module.
+#
+# DESCRIPTION: A short description what that package is, at most one
+# sentence. Ideally this is set already directly in the Find-module.
+#
+# TYPE: What type of dependency has the using project on that package.
+# Default is OPTIONAL. In this case it is a package which can be used
+# by the project when available at buildtime, but it also work without.
+# RECOMMENDED is similar to OPTIONAL, i.e. the project will build if
+# the package is not present, but the functionality of the resulting
+# binaries will be severly limited. If a REQUIRED package is not
+# available at buildtime, the project may not even build. This can be
+# combined with the FATAL_ON_MISSING_REQUIRED_PACKAGES argument for
+# feature_summary(). Last, a RUNTIME package is a package which is
+# actually not used at all during the build, but which is required for
+# actually running the resulting binaries. So if such a package is
+# missing, the project can still be built, but it may not work later on.
+# If set_package_properties() is called multiple times for the same
+# package with different TYPEs, the TYPE is only changed to higher TYPEs
+# ( RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED ), lower TYPEs are
+# ignored. The TYPE property is project-specific, so it cannot be set
+# by the Find-module, but must be set in the project.
+#
+# PURPOSE: This describes which features this package enables in the
+# project, i.e. it tells the user what functionality he gets in the
+# resulting binaries. If set_package_properties() is called multiple
+# times for a package, all PURPOSE properties are appended to a list of
+# purposes of the package in the project. As the TYPE property, also
+# the PURPOSE property is project-specific, so it cannot be set by the
+# Find-module, but must be set in the project.
+#
+#
+#
+# Example for setting the info for a package:
+#
+# ::
+#
+# find_package(LibXml2)
+# set_package_properties(LibXml2 PROPERTIES DESCRIPTION "A XML processing library."
+# URL "http://xmlsoft.org/")
+#
+#
+#
+# ::
+#
+# set_package_properties(LibXml2 PROPERTIES TYPE RECOMMENDED
+# PURPOSE "Enables HTML-import in MyWordProcessor")
+# ...
+# set_package_properties(LibXml2 PROPERTIES TYPE OPTIONAL
+# PURPOSE "Enables odt-export in MyWordProcessor")
+#
+#
+#
+# ::
+#
+# find_package(DBUS)
+# set_package_properties(DBUS PROPERTIES TYPE RUNTIME
+# PURPOSE "Necessary to disable the screensaver during a presentation" )
+#
+#
+#
+# ::
+#
+# ADD_FEATURE_INFO(<name> <enabled> <description>)
+#
+# Use this macro to add information about a feature with the given
+# <name>. <enabled> contains whether this feature is enabled or not,
+# <description> is a text describing the feature. The information can
+# be displayed using feature_summary() for ENABLED_FEATURES and
+# DISABLED_FEATURES respectively.
+#
+# Example for setting the info for a feature:
+#
+# ::
+#
+# option(WITH_FOO "Help for foo" ON)
+# add_feature_info(Foo WITH_FOO "The Foo feature provides very cool stuff.")
+#
+#
+#
+#
+#
+# The following macros are provided for compatibility with previous
+# CMake versions:
+#
+# ::
+#
+# SET_PACKAGE_INFO(<name> <description> [<url> [<purpose>] ] )
+#
+# Use this macro to set up information about the named package, which
+# can then be displayed via FEATURE_SUMMARY(). This can be done either
+# directly in the Find-module or in the project which uses the module
+# after the find_package() call. The features for which information can
+# be set are added automatically by the find_package() command.
+#
+# ::
+#
+# PRINT_ENABLED_FEATURES()
+#
+# Does the same as FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION
+# "Enabled features:")
+#
+# ::
+#
+# PRINT_DISABLED_FEATURES()
+#
+# Does the same as FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION
+# "Disabled features:")
+#
+# ::
+#
+# SET_FEATURE_INFO(<name> <description> [<url>] )
+#
+# Does the same as SET_PACKAGE_INFO(<name> <description> <url> )
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+include("${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake")
+
+
+function(ADD_FEATURE_INFO _name _enabled _desc)
+ if (${_enabled})
+ set_property(GLOBAL APPEND PROPERTY ENABLED_FEATURES "${_name}")
+ else ()
+ set_property(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${_name}")
+ endif ()
+
+ set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
+endfunction()
+
+
+
+function(SET_PACKAGE_PROPERTIES _name _props)
+ if(NOT "${_props}" STREQUAL "PROPERTIES")
+ message(FATAL_ERROR "PROPERTIES keyword is missing in SET_PACKAGE_PROPERTIES() call.")
+ endif()
+
+ set(options ) # none
+ set(oneValueArgs DESCRIPTION URL TYPE PURPOSE )
+ set(multiValueArgs ) # none
+
+ CMAKE_PARSE_ARGUMENTS(_SPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if(_SPP_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown keywords given to SET_PACKAGE_PROPERTIES(): \"${_SPP_UNPARSED_ARGUMENTS}\"")
+ endif()
+
+ if(_SPP_DESCRIPTION)
+ get_property(_info GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION)
+ if(_info AND NOT "${_info}" STREQUAL "${_SPP_DESCRIPTION}")
+ message(STATUS "Warning: Property DESCRIPTION for package ${_name} already set to \"${_info}\", overriding it with \"${_SPP_DESCRIPTION}\"")
+ endif()
+
+ set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_SPP_DESCRIPTION}" )
+ endif()
+
+
+ if(_SPP_URL)
+ get_property(_info GLOBAL PROPERTY _CMAKE_${_name}_URL)
+ if(_info AND NOT "${_info}" STREQUAL "${_SPP_URL}")
+ message(STATUS "Warning: Property URL already set to \"${_info}\", overriding it with \"${_SPP_URL}\"")
+ endif()
+
+ set_property(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_SPP_URL}" )
+ endif()
+
+
+ # handle the PURPOSE: use APPEND, since there can be multiple purposes for one package inside a project
+ if(_SPP_PURPOSE)
+ set_property(GLOBAL APPEND PROPERTY _CMAKE_${_name}_PURPOSE "${_SPP_PURPOSE}" )
+ endif()
+
+ # handle the TYPE
+ if(NOT _SPP_TYPE)
+ set(_SPP_TYPE OPTIONAL)
+ endif()
+
+ # List the supported types, according to their priority
+ set(validTypes "RUNTIME" "OPTIONAL" "RECOMMENDED" "REQUIRED" )
+ list(FIND validTypes ${_SPP_TYPE} _typeIndexInList)
+ if("${_typeIndexInList}" STREQUAL "-1" )
+ message(FATAL_ERROR "Bad package property type ${_SPP_TYPE} used in SET_PACKAGE_PROPERTIES(). "
+ "Valid types are OPTIONAL, RECOMMENDED, REQUIRED and RUNTIME." )
+ endif()
+
+ get_property(_previousType GLOBAL PROPERTY _CMAKE_${_name}_TYPE)
+ list(FIND validTypes "${_previousType}" _prevTypeIndexInList)
+
+ # make sure a previously set TYPE is not overridden with a lower new TYPE:
+ if("${_typeIndexInList}" GREATER "${_prevTypeIndexInList}")
+ set_property(GLOBAL PROPERTY _CMAKE_${_name}_TYPE "${_SPP_TYPE}" )
+ endif()
+
+endfunction()
+
+
+
+function(_FS_GET_FEATURE_SUMMARY _property _var _includeQuiet)
+
+ set(_type "ANY")
+ if("${_property}" MATCHES "REQUIRED_")
+ set(_type "REQUIRED")
+ elseif("${_property}" MATCHES "RECOMMENDED_")
+ set(_type "RECOMMENDED")
+ elseif("${_property}" MATCHES "RUNTIME_")
+ set(_type "RUNTIME")
+ elseif("${_property}" MATCHES "OPTIONAL_")
+ set(_type "OPTIONAL")
+ endif()
+
+ if("${_property}" MATCHES "PACKAGES_FOUND")
+ set(_property "PACKAGES_FOUND")
+ elseif("${_property}" MATCHES "PACKAGES_NOT_FOUND")
+ set(_property "PACKAGES_NOT_FOUND")
+ endif()
+
+
+ set(_currentFeatureText "")
+ get_property(_EnabledFeatures GLOBAL PROPERTY ${_property})
+
+ foreach(_currentFeature ${_EnabledFeatures})
+
+ # does this package belong to the type we currently want to list ?
+ get_property(_currentType GLOBAL PROPERTY _CMAKE_${_currentFeature}_TYPE)
+ if(NOT _currentType)
+ set(_currentType OPTIONAL)
+ endif()
+
+ if("${_type}" STREQUAL ANY OR "${_type}" STREQUAL "${_currentType}")
+
+ # check whether the current feature/package should be in the output depending on whether it was QUIET or not
+ set(includeThisOne TRUE)
+ # skip QUIET packages, except if they are REQUIRED or INCLUDE_QUIET_PACKAGES has been set
+ if((NOT "${_currentType}" STREQUAL "REQUIRED") AND NOT _includeQuiet)
+ get_property(_isQuiet GLOBAL PROPERTY _CMAKE_${_currentFeature}_QUIET)
+ if(_isQuiet)
+ set(includeThisOne FALSE)
+ endif()
+ endif()
+ get_property(_isTransitiveDepend
+ GLOBAL PROPERTY _CMAKE_${_currentFeature}_TRANSITIVE_DEPENDENCY
+ )
+ if(_isTransitiveDepend)
+ set(includeThisOne FALSE)
+ endif()
+
+ if(includeThisOne)
+
+ set(_currentFeatureText "${_currentFeatureText}\n * ${_currentFeature}")
+ get_property(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_REQUIRED_VERSION)
+ if(_info)
+ set(_currentFeatureText "${_currentFeatureText} (required version ${_info})")
+ endif()
+ get_property(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_DESCRIPTION)
+ if(_info)
+ set(_currentFeatureText "${_currentFeatureText} , ${_info}")
+ endif()
+ get_property(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_URL)
+ if(_info)
+ set(_currentFeatureText "${_currentFeatureText} , <${_info}>")
+ endif()
+
+ get_property(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_PURPOSE)
+ foreach(_purpose ${_info})
+ set(_currentFeatureText "${_currentFeatureText}\n ${_purpose}")
+ endforeach()
+
+ endif()
+
+ endif()
+
+ endforeach()
+ set(${_var} "${_currentFeatureText}" PARENT_SCOPE)
+endfunction()
+
+
+
+function(FEATURE_SUMMARY)
+# CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
+ set(options APPEND INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
+ set(oneValueArgs FILENAME VAR DESCRIPTION)
+ set(multiValueArgs WHAT)
+
+ CMAKE_PARSE_ARGUMENTS(_FS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
+
+ if(_FS_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown keywords given to FEATURE_SUMMARY(): \"${_FS_UNPARSED_ARGUMENTS}\"")
+ endif()
+
+ if(NOT _FS_WHAT)
+ message(FATAL_ERROR "The call to FEATURE_SUMMARY() doesn't set the required WHAT argument.")
+ endif()
+
+ set(validWhatParts "ENABLED_FEATURES"
+ "DISABLED_FEATURES"
+ "PACKAGES_FOUND"
+ "PACKAGES_NOT_FOUND"
+ "OPTIONAL_PACKAGES_FOUND"
+ "OPTIONAL_PACKAGES_NOT_FOUND"
+ "RECOMMENDED_PACKAGES_FOUND"
+ "RECOMMENDED_PACKAGES_NOT_FOUND"
+ "REQUIRED_PACKAGES_FOUND"
+ "REQUIRED_PACKAGES_NOT_FOUND"
+ "RUNTIME_PACKAGES_FOUND"
+ "RUNTIME_PACKAGES_NOT_FOUND")
+
+ list(FIND validWhatParts "${_FS_WHAT}" indexInList)
+ if(NOT "${indexInList}" STREQUAL "-1")
+ _FS_GET_FEATURE_SUMMARY( ${_FS_WHAT} _featureSummary ${_FS_INCLUDE_QUIET_PACKAGES} )
+ set(_fullText "${_FS_DESCRIPTION}${_featureSummary}\n")
+ if (("${_FS_WHAT}" STREQUAL "REQUIRED_PACKAGES_NOT_FOUND") AND _featureSummary)
+ set(requiredPackagesNotFound TRUE)
+ endif()
+
+ else()
+ if("${_FS_WHAT}" STREQUAL "ALL")
+
+ set(allWhatParts "ENABLED_FEATURES"
+ "RUNTIME_PACKAGES_FOUND"
+ "OPTIONAL_PACKAGES_FOUND"
+ "RECOMMENDED_PACKAGES_FOUND"
+ "REQUIRED_PACKAGES_FOUND"
+
+ "DISABLED_FEATURES"
+ "RUNTIME_PACKAGES_NOT_FOUND"
+ "OPTIONAL_PACKAGES_NOT_FOUND"
+ "RECOMMENDED_PACKAGES_NOT_FOUND"
+ "REQUIRED_PACKAGES_NOT_FOUND"
+ )
+
+ else()
+ set(allWhatParts)
+ foreach(part ${_FS_WHAT})
+ list(FIND validWhatParts "${part}" indexInList)
+ if(NOT "${indexInList}" STREQUAL "-1")
+ list(APPEND allWhatParts "${part}")
+ else()
+ if("${part}" STREQUAL "ALL")
+ message(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() contains ALL, which cannot be combined with other values.")
+ else()
+ message(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() contains ${part}, which is not a valid value.")
+ endif()
+ endif()
+ endforeach()
+ endif()
+
+ set(title_ENABLED_FEATURES "The following features have been enabled:")
+ set(title_DISABLED_FEATURES "The following features have been disabled:")
+ set(title_PACKAGES_FOUND "The following packages have been found:")
+ set(title_PACKAGES_NOT_FOUND "The following packages have not been found:")
+ set(title_OPTIONAL_PACKAGES_FOUND "The following OPTIONAL packages have been found:")
+ set(title_OPTIONAL_PACKAGES_NOT_FOUND "The following OPTIONAL packages have not been found:")
+ set(title_RECOMMENDED_PACKAGES_FOUND "The following RECOMMENDED packages have been found:")
+ set(title_RECOMMENDED_PACKAGES_NOT_FOUND "The following RECOMMENDED packages have not been found:")
+ set(title_REQUIRED_PACKAGES_FOUND "The following REQUIRED packages have been found:")
+ set(title_REQUIRED_PACKAGES_NOT_FOUND "The following REQUIRED packages have not been found:")
+ set(title_RUNTIME_PACKAGES_FOUND "The following RUNTIME packages have been found:")
+ set(title_RUNTIME_PACKAGES_NOT_FOUND "The following RUNTIME packages have not been found:")
+
+ set(_fullText "${_FS_DESCRIPTION}")
+ foreach(part ${allWhatParts})
+ set(_tmp)
+ _FS_GET_FEATURE_SUMMARY( ${part} _tmp ${_FS_INCLUDE_QUIET_PACKAGES})
+ if(_tmp)
+ set(_fullText "${_fullText}\n-- ${title_${part}}\n${_tmp}\n")
+ if("${part}" STREQUAL "REQUIRED_PACKAGES_NOT_FOUND")
+ set(requiredPackagesNotFound TRUE)
+ endif()
+ endif()
+ endforeach()
+ endif()
+
+ if(_FS_FILENAME)
+ if(_FS_APPEND)
+ file(APPEND "${_FS_FILENAME}" "${_fullText}")
+ else()
+ file(WRITE "${_FS_FILENAME}" "${_fullText}")
+ endif()
+
+ else()
+ if(NOT _FS_VAR)
+ message(STATUS "${_fullText}")
+ endif()
+ endif()
+
+ if(_FS_VAR)
+ set(${_FS_VAR} "${_fullText}" PARENT_SCOPE)
+ endif()
+
+ if(requiredPackagesNotFound AND _FS_FATAL_ON_MISSING_REQUIRED_PACKAGES)
+ message(FATAL_ERROR "feature_summary() Error: REQUIRED package(s) are missing, aborting CMake run.")
+ endif()
+
+endfunction()
+
+
+# The stuff below is only kept for compatibility
+
+function(SET_PACKAGE_INFO _name _desc)
+ set(_url "${ARGV2}")
+ set(_purpose "${ARGV3}")
+ set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
+ if(NOT _url STREQUAL "")
+ set_property(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_url}" )
+ endif()
+ if(NOT _purpose STREQUAL "")
+ set_property(GLOBAL APPEND PROPERTY _CMAKE_${_name}_PURPOSE "${_purpose}" )
+ endif()
+endfunction()
+
+
+
+function(SET_FEATURE_INFO)
+ SET_PACKAGE_INFO(${ARGN})
+endfunction()
+
+
+
+function(PRINT_ENABLED_FEATURES)
+ FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
+endfunction()
+
+
+
+function(PRINT_DISABLED_FEATURES)
+ FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
+endfunction()
diff --git a/Modules/FindALSA.cmake b/Modules/FindALSA.cmake
new file mode 100644
index 0000000000..5c30eb9232
--- /dev/null
+++ b/Modules/FindALSA.cmake
@@ -0,0 +1,65 @@
+#.rst:
+# FindALSA
+# --------
+#
+# Find alsa
+#
+# Find the alsa libraries (asound)
+#
+# ::
+#
+# This module defines the following variables:
+# ALSA_FOUND - True if ALSA_INCLUDE_DIR & ALSA_LIBRARY are found
+# ALSA_LIBRARIES - Set when ALSA_LIBRARY is found
+# ALSA_INCLUDE_DIRS - Set when ALSA_INCLUDE_DIR is found
+#
+#
+#
+# ::
+#
+# ALSA_INCLUDE_DIR - where to find asoundlib.h, etc.
+# ALSA_LIBRARY - the asound library
+# ALSA_VERSION_STRING - the version of alsa found (since CMake 2.8.8)
+
+#=============================================================================
+# Copyright 2009-2011 Kitware, Inc.
+# Copyright 2009-2011 Philip Lowman <philip@yhbt.com>
+#
+# 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.)
+
+find_path(ALSA_INCLUDE_DIR NAMES alsa/asoundlib.h
+ DOC "The ALSA (asound) include directory"
+)
+
+find_library(ALSA_LIBRARY NAMES asound
+ DOC "The ALSA (asound) library"
+)
+
+if(ALSA_INCLUDE_DIR AND EXISTS "${ALSA_INCLUDE_DIR}/alsa/version.h")
+ file(STRINGS "${ALSA_INCLUDE_DIR}/alsa/version.h" alsa_version_str REGEX "^#define[\t ]+SND_LIB_VERSION_STR[\t ]+\".*\"")
+
+ string(REGEX REPLACE "^.*SND_LIB_VERSION_STR[\t ]+\"([^\"]*)\".*$" "\\1" ALSA_VERSION_STRING "${alsa_version_str}")
+ unset(alsa_version_str)
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set ALSA_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALSA
+ REQUIRED_VARS ALSA_LIBRARY ALSA_INCLUDE_DIR
+ VERSION_VAR ALSA_VERSION_STRING)
+
+if(ALSA_FOUND)
+ set( ALSA_LIBRARIES ${ALSA_LIBRARY} )
+ set( ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIR} )
+endif()
+
+mark_as_advanced(ALSA_INCLUDE_DIR ALSA_LIBRARY)
diff --git a/Modules/FindASPELL.cmake b/Modules/FindASPELL.cmake
new file mode 100644
index 0000000000..2a3f228fd4
--- /dev/null
+++ b/Modules/FindASPELL.cmake
@@ -0,0 +1,44 @@
+#.rst:
+# FindASPELL
+# ----------
+#
+# Try to find ASPELL
+#
+# Once done this will define
+#
+# ::
+#
+# ASPELL_FOUND - system has ASPELL
+# ASPELL_EXECUTABLE - the ASPELL executable
+# ASPELL_INCLUDE_DIR - the ASPELL include directory
+# ASPELL_LIBRARIES - The libraries needed to use ASPELL
+# ASPELL_DEFINITIONS - Compiler switches required for using ASPELL
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+find_path(ASPELL_INCLUDE_DIR aspell.h )
+
+find_program(ASPELL_EXECUTABLE
+ NAMES aspell
+)
+
+find_library(ASPELL_LIBRARIES NAMES aspell aspell-15 libaspell-15 libaspell)
+
+# handle the QUIETLY and REQUIRED arguments and set ASPELL_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ASPELL DEFAULT_MSG ASPELL_LIBRARIES ASPELL_INCLUDE_DIR ASPELL_EXECUTABLE)
+
+mark_as_advanced(ASPELL_INCLUDE_DIR ASPELL_LIBRARIES ASPELL_EXECUTABLE)
diff --git a/Modules/FindAVIFile.cmake b/Modules/FindAVIFile.cmake
new file mode 100644
index 0000000000..566107585d
--- /dev/null
+++ b/Modules/FindAVIFile.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindAVIFile
+# -----------
+#
+# Locate AVIFILE library and include paths
+#
+# AVIFILE (http://avifile.sourceforge.net/)is a set of libraries for
+# i386 machines to use various AVI codecs. Support is limited beyond
+# Linux. Windows provides native AVI support, and so doesn't need this
+# library. This module defines
+#
+# ::
+#
+# AVIFILE_INCLUDE_DIR, where to find avifile.h , etc.
+# AVIFILE_LIBRARIES, the libraries to link against
+# AVIFILE_DEFINITIONS, definitions to use when compiling
+# AVIFILE_FOUND, If false, don't try to use AVIFILE
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+if (UNIX)
+
+ find_path(AVIFILE_INCLUDE_DIR avifile.h
+ /usr/local/avifile/include
+ /usr/local/include/avifile
+ )
+
+ find_library(AVIFILE_AVIPLAY_LIBRARY aviplay
+ /usr/local/avifile/lib
+ )
+
+endif ()
+
+# handle the QUIETLY and REQUIRED arguments and set AVIFILE_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(AVIFile DEFAULT_MSG AVIFILE_INCLUDE_DIR AVIFILE_AVIPLAY_LIBRARY)
+
+if (AVIFILE_FOUND)
+ set(AVIFILE_LIBRARIES ${AVIFILE_AVIPLAY_LIBRARY})
+ set(AVIFILE_DEFINITIONS "")
+endif()
+
+mark_as_advanced(AVIFILE_INCLUDE_DIR AVIFILE_AVIPLAY_LIBRARY)
diff --git a/Modules/FindArmadillo.cmake b/Modules/FindArmadillo.cmake
new file mode 100644
index 0000000000..4549771977
--- /dev/null
+++ b/Modules/FindArmadillo.cmake
@@ -0,0 +1,108 @@
+#.rst:
+# FindArmadillo
+# -------------
+#
+# Find Armadillo
+#
+# Find the Armadillo C++ library
+#
+# Using Armadillo:
+#
+# ::
+#
+# find_package(Armadillo REQUIRED)
+# include_directories(${ARMADILLO_INCLUDE_DIRS})
+# add_executable(foo foo.cc)
+# target_link_libraries(foo ${ARMADILLO_LIBRARIES})
+#
+# This module sets the following variables:
+#
+# ::
+#
+# ARMADILLO_FOUND - set to true if the library is found
+# ARMADILLO_INCLUDE_DIRS - list of required include directories
+# ARMADILLO_LIBRARIES - list of libraries to be linked
+# ARMADILLO_VERSION_MAJOR - major version number
+# ARMADILLO_VERSION_MINOR - minor version number
+# ARMADILLO_VERSION_PATCH - patch version number
+# ARMADILLO_VERSION_STRING - version number as a string (ex: "1.0.4")
+# ARMADILLO_VERSION_NAME - name of the version (ex: "Antipodean Antileech")
+
+#=============================================================================
+# Copyright 2011 Clement Creusot <creusot@cs.york.ac.uk>
+#
+# 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.)
+
+
+# UNIX paths are standard, no need to write.
+find_library(ARMADILLO_LIBRARY
+ NAMES armadillo
+ PATHS "$ENV{ProgramFiles}/Armadillo/lib" "$ENV{ProgramFiles}/Armadillo/lib64" "$ENV{ProgramFiles}/Armadillo"
+ )
+find_path(ARMADILLO_INCLUDE_DIR
+ NAMES armadillo
+ PATHS "$ENV{ProgramFiles}/Armadillo/include"
+ )
+
+
+if(ARMADILLO_INCLUDE_DIR)
+
+ # ------------------------------------------------------------------------
+ # Extract version information from <armadillo>
+ # ------------------------------------------------------------------------
+
+ # WARNING: Early releases of Armadillo didn't have the arma_version.hpp file.
+ # (e.g. v.0.9.8-1 in ubuntu maverick packages (2001-03-15))
+ # If the file is missing, set all values to 0
+ set(ARMADILLO_VERSION_MAJOR 0)
+ set(ARMADILLO_VERSION_MINOR 0)
+ set(ARMADILLO_VERSION_PATCH 0)
+ set(ARMADILLO_VERSION_NAME "EARLY RELEASE")
+
+ if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp")
+
+ # Read and parse armdillo version header file for version number
+ file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _armadillo_HEADER_CONTENTS REGEX "#define ARMA_VERSION_[A-Z]+ ")
+ string(REGEX REPLACE ".*#define ARMA_VERSION_MAJOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MAJOR "${_armadillo_HEADER_CONTENTS}")
+ string(REGEX REPLACE ".*#define ARMA_VERSION_MINOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MINOR "${_armadillo_HEADER_CONTENTS}")
+ string(REGEX REPLACE ".*#define ARMA_VERSION_PATCH ([0-9]+).*" "\\1" ARMADILLO_VERSION_PATCH "${_armadillo_HEADER_CONTENTS}")
+
+ # WARNING: The number of spaces before the version name is not one.
+ string(REGEX REPLACE ".*#define ARMA_VERSION_NAME +\"([0-9a-zA-Z _-]+)\".*" "\\1" ARMADILLO_VERSION_NAME "${_armadillo_HEADER_CONTENTS}")
+
+ unset(_armadillo_HEADER_CONTENTS)
+ endif()
+
+ set(ARMADILLO_VERSION_STRING "${ARMADILLO_VERSION_MAJOR}.${ARMADILLO_VERSION_MINOR}.${ARMADILLO_VERSION_PATCH}")
+endif ()
+
+#======================
+
+
+# Checks 'REQUIRED', 'QUIET' and versions.
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(Armadillo
+ REQUIRED_VARS ARMADILLO_LIBRARY ARMADILLO_INCLUDE_DIR
+ VERSION_VAR ARMADILLO_VERSION_STRING)
+# version_var fails with cmake < 2.8.4.
+
+if (ARMADILLO_FOUND)
+ set(ARMADILLO_INCLUDE_DIRS ${ARMADILLO_INCLUDE_DIR})
+ set(ARMADILLO_LIBRARIES ${ARMADILLO_LIBRARY})
+endif ()
+
+
+# Hide internal variables
+mark_as_advanced(
+ ARMADILLO_INCLUDE_DIR
+ ARMADILLO_LIBRARY)
+
+#======================
diff --git a/Modules/FindBISON.cmake b/Modules/FindBISON.cmake
new file mode 100644
index 0000000000..ec3ee78e85
--- /dev/null
+++ b/Modules/FindBISON.cmake
@@ -0,0 +1,196 @@
+#.rst:
+# FindBISON
+# ---------
+#
+# Find bison executable and provides macros to generate custom build rules
+#
+# The module defines the following variables:
+#
+# ::
+#
+# BISON_EXECUTABLE - path to the bison program
+# BISON_VERSION - version of bison
+# BISON_FOUND - true if the program was found
+#
+#
+#
+# The minimum required version of bison can be specified using the
+# standard CMake syntax, e.g. find_package(BISON 2.1.3)
+#
+# If bison is found, the module defines the macros:
+#
+# ::
+#
+# BISON_TARGET(<Name> <YaccInput> <CodeOutput> [VERBOSE <file>]
+# [COMPILE_FLAGS <string>])
+#
+# which will create a custom rule to generate a parser. <YaccInput> is
+# the path to a yacc file. <CodeOutput> is the name of the source file
+# generated by bison. A header file is also be generated, and contains
+# the token list. If COMPILE_FLAGS option is specified, the next
+# parameter is added in the bison command line. if VERBOSE option is
+# specified, <file> is created and contains verbose descriptions of the
+# grammar and parser. The macro defines a set of variables:
+#
+# ::
+#
+# BISON_${Name}_DEFINED - true is the macro ran successfully
+# BISON_${Name}_INPUT - The input source file, an alias for <YaccInput>
+# BISON_${Name}_OUTPUT_SOURCE - The source file generated by bison
+# BISON_${Name}_OUTPUT_HEADER - The header file generated by bison
+# BISON_${Name}_OUTPUTS - The sources files generated by bison
+# BISON_${Name}_COMPILE_FLAGS - Options used in the bison command line
+#
+#
+#
+# ::
+#
+# ====================================================================
+# Example:
+#
+#
+#
+# ::
+#
+# find_package(BISON)
+# BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
+# add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS})
+# ====================================================================
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2006 Tristan Carel
+#
+# 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.)
+
+find_program(BISON_EXECUTABLE NAMES bison win_bison DOC "path to the bison executable")
+mark_as_advanced(BISON_EXECUTABLE)
+
+if(BISON_EXECUTABLE)
+ # the bison commands should be executed with the C locale, otherwise
+ # the message (which are parsed) may be translated
+ set(_Bison_SAVED_LC_ALL "$ENV{LC_ALL}")
+ set(ENV{LC_ALL} C)
+
+ execute_process(COMMAND ${BISON_EXECUTABLE} --version
+ OUTPUT_VARIABLE BISON_version_output
+ ERROR_VARIABLE BISON_version_error
+ RESULT_VARIABLE BISON_version_result
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ set(ENV{LC_ALL} ${_Bison_SAVED_LC_ALL})
+
+ if(NOT ${BISON_version_result} EQUAL 0)
+ message(SEND_ERROR "Command \"${BISON_EXECUTABLE} --version\" failed with output:\n${BISON_version_error}")
+ else()
+ # Bison++
+ if("${BISON_version_output}" MATCHES "^bison\\+\\+ Version ([^,]+)")
+ set(BISON_VERSION "${CMAKE_MATCH_1}")
+ # GNU Bison
+ elseif("${BISON_version_output}" MATCHES "^bison \\(GNU Bison\\) ([^\n]+)\n")
+ set(BISON_VERSION "${CMAKE_MATCH_1}")
+ elseif("${BISON_version_output}" MATCHES "^GNU Bison (version )?([^\n]+)")
+ set(BISON_VERSION "${CMAKE_MATCH_2}")
+ endif()
+ endif()
+
+ # internal macro
+ macro(BISON_TARGET_option_verbose Name BisonOutput filename)
+ list(APPEND BISON_TARGET_cmdopt "--verbose")
+ get_filename_component(BISON_TARGET_output_path "${BisonOutput}" PATH)
+ get_filename_component(BISON_TARGET_output_name "${BisonOutput}" NAME_WE)
+ add_custom_command(OUTPUT ${filename}
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy
+ "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output"
+ "${filename}"
+ DEPENDS
+ "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output"
+ COMMENT "[BISON][${Name}] Copying bison verbose table to ${filename}"
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
+ set(BISON_${Name}_VERBOSE_FILE ${filename})
+ list(APPEND BISON_TARGET_extraoutputs
+ "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output")
+ endmacro()
+
+ # internal macro
+ macro(BISON_TARGET_option_extraopts Options)
+ set(BISON_TARGET_extraopts "${Options}")
+ separate_arguments(BISON_TARGET_extraopts)
+ list(APPEND BISON_TARGET_cmdopt ${BISON_TARGET_extraopts})
+ endmacro()
+
+ #============================================================
+ # BISON_TARGET (public macro)
+ #============================================================
+ #
+ macro(BISON_TARGET Name BisonInput BisonOutput)
+ set(BISON_TARGET_output_header "")
+ set(BISON_TARGET_cmdopt "")
+ set(BISON_TARGET_outputs "${BisonOutput}")
+ if(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7)
+ message(SEND_ERROR "Usage")
+ else()
+ # Parsing parameters
+ if(${ARGC} GREATER 5 OR ${ARGC} EQUAL 5)
+ if("${ARGV3}" STREQUAL "VERBOSE")
+ BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV4}")
+ endif()
+ if("${ARGV3}" STREQUAL "COMPILE_FLAGS")
+ BISON_TARGET_option_extraopts("${ARGV4}")
+ endif()
+ endif()
+
+ if(${ARGC} EQUAL 7)
+ if("${ARGV5}" STREQUAL "VERBOSE")
+ BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV6}")
+ endif()
+
+ if("${ARGV5}" STREQUAL "COMPILE_FLAGS")
+ BISON_TARGET_option_extraopts("${ARGV6}")
+ endif()
+ endif()
+
+ # Header's name generated by bison (see option -d)
+ list(APPEND BISON_TARGET_cmdopt "-d")
+ string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${ARGV2}")
+ string(REPLACE "c" "h" _fileext ${_fileext})
+ string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}"
+ BISON_${Name}_OUTPUT_HEADER "${ARGV2}")
+ list(APPEND BISON_TARGET_outputs "${BISON_${Name}_OUTPUT_HEADER}")
+
+ add_custom_command(OUTPUT ${BISON_TARGET_outputs}
+ ${BISON_TARGET_extraoutputs}
+ COMMAND ${BISON_EXECUTABLE}
+ ARGS ${BISON_TARGET_cmdopt} -o ${ARGV2} ${ARGV1}
+ DEPENDS ${ARGV1}
+ COMMENT "[BISON][${Name}] Building parser with bison ${BISON_VERSION}"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+ # define target variables
+ set(BISON_${Name}_DEFINED TRUE)
+ set(BISON_${Name}_INPUT ${ARGV1})
+ set(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs})
+ set(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt})
+ set(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}")
+
+ endif()
+ endmacro()
+ #
+ #============================================================
+
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(BISON REQUIRED_VARS BISON_EXECUTABLE
+ VERSION_VAR BISON_VERSION)
+
+# FindBISON.cmake ends here
diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake
new file mode 100644
index 0000000000..6a583d9571
--- /dev/null
+++ b/Modules/FindBLAS.cmake
@@ -0,0 +1,694 @@
+#.rst:
+# FindBLAS
+# --------
+#
+# Find BLAS library
+#
+# This module finds an installed fortran library that implements the
+# BLAS linear-algebra interface (see http://www.netlib.org/blas/). The
+# list of libraries searched for is taken from the autoconf macro file,
+# acx_blas.m4 (distributed at
+# http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
+#
+# This module sets the following variables:
+#
+# ::
+#
+# BLAS_FOUND - set to true if a library implementing the BLAS interface
+# is found
+# BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
+# and -L).
+# BLAS_LIBRARIES - uncached list of libraries (using full path name) to
+# link against to use BLAS
+# BLAS95_LIBRARIES - uncached list of libraries (using full path name)
+# to link against to use BLAS95 interface
+# BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
+# is found
+# BLA_STATIC if set on this determines what kind of linkage we do (static)
+# BLA_VENDOR if set checks only the specified vendor, if not set checks
+# all the possibilities
+# BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK
+#
+# ######### ## List of vendors (BLA_VENDOR) valid in this module #
+# Goto,ATLAS PhiPACK,CXML,DXML,SunPerf,SCSL,SGIMATH,IBMESSL,Intel10_32
+# (intel mkl v10 32 bit),Intel10_64lp (intel mkl v10 64 bit,lp thread
+# model, lp64 model), # Intel10_64lp_seq (intel mkl v10 64
+# bit,sequential code, lp64 model), # Intel( older versions of mkl 32
+# and 64 bit), ACML,ACML_MP,ACML_GPU,Apple, NAS, Generic C/CXX should be
+# enabled to use Intel mkl
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
+cmake_push_check_state()
+set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
+
+set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+
+# Check the language being used
+get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES )
+if( _LANGUAGES_ MATCHES Fortran )
+ set( _CHECK_FORTRAN TRUE )
+elseif( (_LANGUAGES_ MATCHES C) OR (_LANGUAGES_ MATCHES CXX) )
+ set( _CHECK_FORTRAN FALSE )
+else()
+ if(BLAS_FIND_REQUIRED)
+ message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
+ else()
+ message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
+ return()
+ endif()
+endif()
+
+macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
+# This macro checks for the existence of the combination of fortran libraries
+# given by _list. If the combination is found, this macro checks (using the
+# Check_Fortran_Function_Exists macro) whether can link against that library
+# combination using the name of a routine given by _name using the linker
+# flags given by _flags. If the combination of libraries is found and passes
+# the link test, LIBRARIES is set to the list of complete library paths that
+# have been found. Otherwise, LIBRARIES is set to FALSE.
+
+# N.B. _prefix is the prefix applied to the names of all cached variables that
+# are generated internally and marked advanced by this macro.
+
+set(_libdir ${ARGN})
+
+set(_libraries_work TRUE)
+set(${LIBRARIES})
+set(_combined_name)
+if (NOT _libdir)
+ if (WIN32)
+ set(_libdir ENV LIB)
+ elseif (APPLE)
+ set(_libdir ENV DYLD_LIBRARY_PATH)
+ else ()
+ set(_libdir ENV LD_LIBRARY_PATH)
+ endif ()
+endif ()
+
+foreach(_library ${_list})
+ set(_combined_name ${_combined_name}_${_library})
+
+ if(_libraries_work)
+ if (BLA_STATIC)
+ if (WIN32)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ endif ()
+ if (APPLE)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ else ()
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ endif ()
+ else ()
+ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ # for ubuntu's libblas3gf and liblapack3gf packages
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
+ endif ()
+ endif ()
+ find_library(${_prefix}_${_library}_LIBRARY
+ NAMES ${_library}
+ PATHS ${_libdir}
+ )
+ mark_as_advanced(${_prefix}_${_library}_LIBRARY)
+ set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
+ set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
+ endif()
+endforeach()
+if(_libraries_work)
+ # Test this combination of libraries.
+ set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_thread})
+# message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
+ if (_CHECK_FORTRAN)
+ check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
+ else()
+ check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
+ endif()
+ set(CMAKE_REQUIRED_LIBRARIES)
+ mark_as_advanced(${_prefix}${_combined_name}_WORKS)
+ set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
+endif()
+if(NOT _libraries_work)
+ set(${LIBRARIES} FALSE)
+endif()
+#message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
+endmacro()
+
+set(BLAS_LINKER_FLAGS)
+set(BLAS_LIBRARIES)
+set(BLAS95_LIBRARIES)
+if (NOT $ENV{BLA_VENDOR} STREQUAL "")
+ set(BLA_VENDOR $ENV{BLA_VENDOR})
+else ()
+ if(NOT BLA_VENDOR)
+ set(BLA_VENDOR "All")
+ endif()
+endif ()
+
+if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "goto2"
+ ""
+ )
+ endif()
+endif ()
+
+if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ dgemm
+ ""
+ "f77blas;atlas"
+ ""
+ )
+ endif()
+endif ()
+
+# BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
+if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "sgemm;dgemm;blas"
+ ""
+ )
+ endif()
+endif ()
+
+# BLAS in Alpha CXML library?
+if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "cxml"
+ ""
+ )
+ endif()
+endif ()
+
+# BLAS in Alpha DXML library? (now called CXML, see above)
+if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "dxml"
+ ""
+ )
+ endif()
+endif ()
+
+# BLAS in Sun Performance library?
+if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ "-xlic_lib=sunperf"
+ "sunperf;sunmath"
+ ""
+ )
+ if(BLAS_LIBRARIES)
+ set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
+ endif()
+ endif()
+endif ()
+
+# BLAS in SCSL library? (SGI/Cray Scientific Library)
+if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "scsl"
+ ""
+ )
+ endif()
+endif ()
+
+# BLAS in SGIMATH library?
+if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "complib.sgimath"
+ ""
+ )
+ endif()
+endif ()
+
+# BLAS in IBM ESSL library? (requires generic BLAS lib, too)
+if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "essl;blas"
+ ""
+ )
+ endif()
+endif ()
+
+#BLAS in acml library?
+if (BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All")
+ if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
+ ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
+ ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS))
+ )
+ # try to find acml in "standard" paths
+ if( WIN32 )
+ file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
+ else()
+ file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
+ endif()
+ if( WIN32 )
+ file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
+ else()
+ file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
+ endif()
+ list(GET _ACML_ROOT 0 _ACML_ROOT)
+ list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
+ if( _ACML_ROOT )
+ get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
+ if( SIZEOF_INTEGER EQUAL 8 )
+ set( _ACML_PATH_SUFFIX "_int64" )
+ else()
+ set( _ACML_PATH_SUFFIX "" )
+ endif()
+ if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
+ set( _ACML_COMPILER32 "ifort32" )
+ set( _ACML_COMPILER64 "ifort64" )
+ elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
+ set( _ACML_COMPILER32 "sun32" )
+ set( _ACML_COMPILER64 "sun64" )
+ elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
+ set( _ACML_COMPILER32 "pgi32" )
+ if( WIN32 )
+ set( _ACML_COMPILER64 "win64" )
+ else()
+ set( _ACML_COMPILER64 "pgi64" )
+ endif()
+ elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
+ # 32 bit builds not supported on Open64 but for code simplicity
+ # We'll just use the same directory twice
+ set( _ACML_COMPILER32 "open64_64" )
+ set( _ACML_COMPILER64 "open64_64" )
+ elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
+ set( _ACML_COMPILER32 "nag32" )
+ set( _ACML_COMPILER64 "nag64" )
+ else()
+ set( _ACML_COMPILER32 "gfortran32" )
+ set( _ACML_COMPILER64 "gfortran64" )
+ endif()
+
+ if( BLA_VENDOR STREQUAL "ACML_MP" )
+ set(_ACML_MP_LIB_DIRS
+ "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
+ "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
+ else()
+ set(_ACML_LIB_DIRS
+ "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
+ "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
+ endif()
+ endif()
+ elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
+ set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
+ endif()
+
+ if( BLA_VENDOR STREQUAL "ACML_MP" )
+ foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
+ check_fortran_libraries (
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS}
+ )
+ if( BLAS_LIBRARIES )
+ break()
+ endif()
+ endforeach()
+ elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
+ foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
+ check_fortran_libraries (
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
+ )
+ if( BLAS_LIBRARIES )
+ break()
+ endif()
+ endforeach()
+ else()
+ foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
+ check_fortran_libraries (
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
+ )
+ if( BLAS_LIBRARIES )
+ break()
+ endif()
+ endforeach()
+ endif()
+
+ # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "acml;acml_mv"
+ ""
+ )
+ endif()
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "acml_mp;acml_mv"
+ ""
+ )
+ endif()
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "acml;acml_mv;CALBLAS"
+ ""
+ )
+ endif()
+endif () # ACML
+
+# Apple BLAS library?
+if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
+if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ dgemm
+ ""
+ "Accelerate"
+ ""
+ )
+ endif()
+endif ()
+
+if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
+ if ( NOT BLAS_LIBRARIES )
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ dgemm
+ ""
+ "vecLib"
+ ""
+ )
+ endif ()
+endif ()
+# Generic BLAS library?
+if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "blas"
+ ""
+ )
+ endif()
+endif ()
+
+#BLAS in intel mkl 10 library? (em64t 64bit)
+if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
+ if (NOT WIN32)
+ set(LM "-lm")
+ endif ()
+ if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
+ if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
+ find_package(Threads)
+ else()
+ find_package(Threads REQUIRED)
+ endif()
+
+ set(BLAS_SEARCH_LIBS "")
+
+ if(BLA_F95)
+ set(BLAS_mkl_SEARCH_SYMBOL SGEMM)
+ set(_LIBRARIES BLAS95_LIBRARIES)
+ if (WIN32)
+ if (BLA_STATIC)
+ set(BLAS_mkl_DLL_SUFFIX "")
+ else()
+ set(BLAS_mkl_DLL_SUFFIX "_dll")
+ endif()
+
+ # Find the main file (32-bit or 64-bit)
+ set(BLAS_SEARCH_LIBS_WIN_MAIN "")
+ if (BLA_VENDOR STREQUAL "Intel10_32" 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")
+ 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")
+ 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")
+ # old version
+ list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+ "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
+ # mkl >= 10.3
+ list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+ "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
+ endif()
+
+ # Cartesian product of the above
+ foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
+ foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
+ list(APPEND BLAS_SEARCH_LIBS
+ "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
+ endforeach()
+ endforeach()
+ else ()
+ if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide")
+ endif ()
+ if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
+ # old version
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_blas95 mkl_intel_lp64 mkl_intel_thread mkl_core guide")
+
+ # mkl >= 10.3
+ if (CMAKE_C_COMPILER MATCHES ".+gcc")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_blas95_lp64 mkl_intel_lp64 mkl_gnu_thread mkl_core gomp")
+ else ()
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_blas95_lp64 mkl_intel_lp64 mkl_intel_thread mkl_core iomp5")
+ endif ()
+ endif ()
+ if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_intel_lp64 mkl_sequential mkl_core")
+ endif ()
+ endif ()
+ else ()
+ set(BLAS_mkl_SEARCH_SYMBOL sgemm)
+ set(_LIBRARIES BLAS_LIBRARIES)
+ if (WIN32)
+ if (BLA_STATIC)
+ set(BLAS_mkl_DLL_SUFFIX "")
+ else()
+ set(BLAS_mkl_DLL_SUFFIX "_dll")
+ endif()
+
+ # Find the main file (32-bit or 64-bit)
+ set(BLAS_SEARCH_LIBS_WIN_MAIN "")
+ if (BLA_VENDOR STREQUAL "Intel10_32" 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")
+ 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")
+ # old version
+ list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+ "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
+ # mkl >= 10.3
+ 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")
+ list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+ "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
+ endif()
+
+ # Cartesian product of the above
+ foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
+ foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
+ list(APPEND BLAS_SEARCH_LIBS
+ "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
+ endforeach()
+ endforeach()
+ else ()
+ if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_intel mkl_intel_thread mkl_core guide")
+ endif ()
+ if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
+
+ # old version
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_intel_lp64 mkl_intel_thread mkl_core guide")
+
+ # mkl >= 10.3
+ if (CMAKE_C_COMPILER MATCHES ".+gcc")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_intel_lp64 mkl_gnu_thread mkl_core gomp")
+ else ()
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_intel_lp64 mkl_intel_thread mkl_core iomp5")
+ endif ()
+ endif ()
+ if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_intel_lp64 mkl_sequential mkl_core")
+ endif ()
+
+ #older vesions of intel mkl libs
+ if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_ia32")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_em64t")
+ endif ()
+ endif ()
+ endif ()
+
+ foreach (IT ${BLAS_SEARCH_LIBS})
+ string(REPLACE " " ";" SEARCH_LIBS ${IT})
+ if (${_LIBRARIES})
+ else ()
+ check_fortran_libraries(
+ ${_LIBRARIES}
+ BLAS
+ ${BLAS_mkl_SEARCH_SYMBOL}
+ ""
+ "${SEARCH_LIBS}"
+ "${CMAKE_THREAD_LIBS_INIT};${LM}"
+ )
+ endif ()
+ endforeach ()
+
+ endif ()
+endif ()
+
+
+if(BLA_F95)
+ if(BLAS95_LIBRARIES)
+ set(BLAS95_FOUND TRUE)
+ else()
+ set(BLAS95_FOUND FALSE)
+ endif()
+
+ if(NOT BLAS_FIND_QUIETLY)
+ if(BLAS95_FOUND)
+ message(STATUS "A library with BLAS95 API found.")
+ else()
+ if(BLAS_FIND_REQUIRED)
+ message(FATAL_ERROR
+ "A required library with BLAS95 API not found. Please specify library location.")
+ else()
+ message(STATUS
+ "A library with BLAS95 API not found. Please specify library location.")
+ endif()
+ endif()
+ endif()
+ set(BLAS_FOUND TRUE)
+ set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
+else()
+ if(BLAS_LIBRARIES)
+ set(BLAS_FOUND TRUE)
+ else()
+ set(BLAS_FOUND FALSE)
+ endif()
+
+ if(NOT BLAS_FIND_QUIETLY)
+ if(BLAS_FOUND)
+ message(STATUS "A library with BLAS API found.")
+ else()
+ if(BLAS_FIND_REQUIRED)
+ message(FATAL_ERROR
+ "A required library with BLAS API not found. Please specify library location."
+ )
+ else()
+ message(STATUS
+ "A library with BLAS API not found. Please specify library location."
+ )
+ endif()
+ endif()
+ endif()
+endif()
+
+cmake_pop_check_state()
+set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
diff --git a/Modules/FindBZip2.cmake b/Modules/FindBZip2.cmake
new file mode 100644
index 0000000000..b4793327d9
--- /dev/null
+++ b/Modules/FindBZip2.cmake
@@ -0,0 +1,67 @@
+#.rst:
+# FindBZip2
+# ---------
+#
+# Try to find BZip2
+#
+# Once done this will define
+#
+# ::
+#
+# BZIP2_FOUND - system has BZip2
+# BZIP2_INCLUDE_DIR - the BZip2 include directory
+# BZIP2_LIBRARIES - Link these to use BZip2
+# BZIP2_NEED_PREFIX - this is set if the functions are prefixed with BZ2_
+# BZIP2_VERSION_STRING - the version of BZip2 found (since CMake 2.8.8)
+
+#=============================================================================
+# Copyright 2006-2012 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+set(_BZIP2_PATHS PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Bzip2;InstallPath]"
+ )
+
+find_path(BZIP2_INCLUDE_DIR bzlib.h ${_BZIP2_PATHS} PATH_SUFFIXES include)
+
+if (NOT BZIP2_LIBRARIES)
+ find_library(BZIP2_LIBRARY_RELEASE NAMES bz2 bzip2 ${_BZIP2_PATHS} PATH_SUFFIXES lib)
+ find_library(BZIP2_LIBRARY_DEBUG NAMES bzip2d ${_BZIP2_PATHS} PATH_SUFFIXES lib)
+
+ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+ SELECT_LIBRARY_CONFIGURATIONS(BZIP2)
+endif ()
+
+if (BZIP2_INCLUDE_DIR AND EXISTS "${BZIP2_INCLUDE_DIR}/bzlib.h")
+ file(STRINGS "${BZIP2_INCLUDE_DIR}/bzlib.h" BZLIB_H REGEX "bzip2/libbzip2 version [0-9]+\\.[^ ]+ of [0-9]+ ")
+ string(REGEX REPLACE ".* bzip2/libbzip2 version ([0-9]+\\.[^ ]+) of [0-9]+ .*" "\\1" BZIP2_VERSION_STRING "${BZLIB_H}")
+endif ()
+
+# handle the QUIETLY and REQUIRED arguments and set BZip2_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(BZip2
+ REQUIRED_VARS BZIP2_LIBRARIES BZIP2_INCLUDE_DIR
+ VERSION_VAR BZIP2_VERSION_STRING)
+
+if (BZIP2_FOUND)
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
+ include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
+ cmake_push_check_state()
+ set(CMAKE_REQUIRED_QUIET ${BZip2_FIND_QUIETLY})
+ CHECK_LIBRARY_EXISTS("${BZIP2_LIBRARIES}" BZ2_bzCompressInit "" BZIP2_NEED_PREFIX)
+ cmake_pop_check_state()
+endif ()
+
+mark_as_advanced(BZIP2_INCLUDE_DIR)
diff --git a/Modules/FindBacktrace.cmake b/Modules/FindBacktrace.cmake
new file mode 100644
index 0000000000..07109b01f9
--- /dev/null
+++ b/Modules/FindBacktrace.cmake
@@ -0,0 +1,95 @@
+#.rst:
+# FindBacktrace
+# -------------
+#
+# Find provider for backtrace(3).
+#
+# Checks if OS supports backtrace(3) via either libc or custom library.
+# This module defines the following variables::
+#
+# Backtrace_HEADER - The header file needed for backtrace(3). Cached.
+# Could be forcibly set by user.
+# Backtrace_INCLUDE_DIRS - The include directories needed to use backtrace(3) header.
+# Backtrace_LIBRARIES - The libraries (linker flags) needed to use backtrace(3), if any.
+# Backtrace_FOUND - Is set if and only if backtrace(3) support detected.
+#
+# The following cache variables are also available to set or use::
+#
+# Backtrace_LIBRARY - The external library providing backtrace, if any.
+# Backtrace_INCLUDE_DIR - The directory holding the backtrace(3) header.
+#
+# Typical usage is to generate of header file using configure_file() with the
+# contents like the following::
+#
+# #cmakedefine01 Backtrace_FOUND
+# #if Backtrace_FOUND
+# # include <${Backtrace_HEADER}>
+# #endif
+#
+# And then reference that generated header file in actual source.
+
+#=============================================================================
+# Copyright 2013 Vadim Zhukov
+#
+# 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.)
+
+
+include(CMakePushCheckState)
+include(CheckSymbolExists)
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+# List of variables to be provided to find_package_handle_standard_args()
+set(_Backtrace_STD_ARGS Backtrace_INCLUDE_DIR)
+
+if(Backtrace_HEADER)
+ set(_Backtrace_HEADER_TRY "${Backtrace_HEADER}")
+else(Backtrace_HEADER)
+ set(_Backtrace_HEADER_TRY "execinfo.h")
+endif(Backtrace_HEADER)
+
+find_path(Backtrace_INCLUDE_DIR "${_Backtrace_HEADER_TRY}")
+set(Backtrace_INCLUDE_DIRS ${Backtrace_INCLUDE_DIR})
+
+if (NOT DEFINED Backtrace_LIBRARY)
+ # First, check if we already have backtrace(), e.g., in libc
+ cmake_push_check_state(RESET)
+ set(CMAKE_REQUIRED_INCLUDES ${Backtrace_INCLUDE_DIRS})
+ set(CMAKE_REQUIRED_QUIET ${Backtrace_FIND_QUIETLY})
+ check_symbol_exists("backtrace" "${_Backtrace_HEADER_TRY}" _Backtrace_SYM_FOUND)
+ cmake_pop_check_state()
+endif()
+
+if(_Backtrace_SYM_FOUND)
+ # Avoid repeating the message() call below each time CMake is run.
+ if(NOT Backtrace_FIND_QUIETLY AND NOT DEFINED Backtrace_LIBRARY)
+ message(STATUS "backtrace facility detected in default set of libraries")
+ endif()
+ set(Backtrace_LIBRARY "" CACHE FILEPATH "Library providing backtrace(3), empty for default set of libraries")
+else()
+ # Check for external library, for non-glibc systems
+ if(Backtrace_INCLUDE_DIR)
+ # OpenBSD has libbacktrace renamed to libexecinfo
+ find_library(Backtrace_LIBRARY "execinfo")
+ elseif() # respect user wishes
+ set(_Backtrace_HEADER_TRY "backtrace.h")
+ find_path(Backtrace_INCLUDE_DIR ${_Backtrace_HEADER_TRY})
+ find_library(Backtrace_LIBRARY "backtrace")
+ endif()
+
+ # Prepend list with library path as it's more common practice
+ set(_Backtrace_STD_ARGS Backtrace_LIBRARY ${_Backtrace_STD_ARGS})
+endif()
+
+set(Backtrace_LIBRARIES ${Backtrace_LIBRARY})
+set(Backtrace_HEADER "${_Backtrace_HEADER_TRY}" CACHE STRING "Header providing backtrace(3) facility")
+
+find_package_handle_standard_args(Backtrace FOUND_VAR Backtrace_FOUND REQUIRED_VARS ${_Backtrace_STD_ARGS})
+mark_as_advanced(Backtrace_HEADER Backtrace_INCLUDE_DIR Backtrace_LIBRARY)
diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake
new file mode 100644
index 0000000000..3642b3eeb3
--- /dev/null
+++ b/Modules/FindBoost.cmake
@@ -0,0 +1,1233 @@
+#.rst:
+# FindBoost
+# ---------
+#
+# Find Boost include dirs and libraries
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package(Boost
+# [version] [EXACT] # Minimum or EXACT version e.g. 1.36.0
+# [REQUIRED] # Fail with error if Boost is not found
+# [COMPONENTS <libs>...] # Boost libraries by their canonical name
+# ) # e.g. "date_time" for "libboost_date_time"
+#
+# This module finds headers and requested component libraries OR a CMake
+# package configuration file provided by a "Boost CMake" build. For the
+# latter case skip to the "Boost CMake" section below. For the former
+# case results are reported in variables::
+#
+# Boost_FOUND - True if headers and requested libraries were found
+# Boost_INCLUDE_DIRS - Boost include directories
+# Boost_LIBRARY_DIRS - Link directories for Boost libraries
+# Boost_LIBRARIES - Boost component libraries to be linked
+# Boost_<C>_FOUND - True if component <C> was found (<C> is upper-case)
+# Boost_<C>_LIBRARY - Libraries to link for component <C> (may include
+# target_link_libraries debug/optimized keywords)
+# Boost_VERSION - BOOST_VERSION value from boost/version.hpp
+# Boost_LIB_VERSION - Version string appended to library filenames
+# Boost_MAJOR_VERSION - Boost major version number (X in X.y.z)
+# Boost_MINOR_VERSION - Boost minor version number (Y in x.Y.z)
+# Boost_SUBMINOR_VERSION - Boost subminor version number (Z in x.y.Z)
+# Boost_LIB_DIAGNOSTIC_DEFINITIONS (Windows)
+# - Pass to add_definitions() to have diagnostic
+# information about Boost's automatic linking
+# displayed during compilation
+#
+# This module reads hints about search locations from variables::
+#
+# BOOST_ROOT - Preferred installation prefix
+# (or BOOSTROOT)
+# BOOST_INCLUDEDIR - Preferred include directory e.g. <prefix>/include
+# BOOST_LIBRARYDIR - Preferred library directory e.g. <prefix>/lib
+# Boost_NO_SYSTEM_PATHS - Set to ON to disable searching in locations not
+# specified by these hint variables. Default is OFF.
+# Boost_ADDITIONAL_VERSIONS
+# - List of Boost versions not known to this module
+# (Boost install locations may contain the version)
+#
+# and saves search results persistently in CMake cache entries::
+#
+# Boost_INCLUDE_DIR - Directory containing Boost headers
+# Boost_LIBRARY_DIR - Directory containing Boost libraries
+# Boost_<C>_LIBRARY_DEBUG - Component <C> library debug variant
+# Boost_<C>_LIBRARY_RELEASE - Component <C> library release variant
+#
+# 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
+# "BOOST". One may specify these as environment variables if they are
+# not specified as CMake variables or cache entries.
+#
+# This module first searches for the Boost header files using the above
+# hint variables (excluding BOOST_LIBRARYDIR) and saves the result in
+# Boost_INCLUDE_DIR. Then it searches for requested component libraries
+# using the above hints (excluding BOOST_INCLUDEDIR and
+# Boost_ADDITIONAL_VERSIONS), "lib" directories near Boost_INCLUDE_DIR,
+# and the library name configuration settings below. It saves the
+# library directory in Boost_LIBRARY_DIR and individual library
+# locations in Boost_<C>_LIBRARY_DEBUG and Boost_<C>_LIBRARY_RELEASE.
+# When one changes settings used by previous searches in the same build
+# tree (excluding environment variables) this module discards previous
+# search results affected by the changes and searches again.
+#
+# Boost libraries come in many variants encoded in their file name.
+# Users or projects may tell this module which variant to find by
+# setting variables::
+#
+# Boost_USE_MULTITHREADED - Set to OFF to use the non-multithreaded
+# libraries ('mt' tag). Default is ON.
+# Boost_USE_STATIC_LIBS - Set to ON to force the use of the static
+# libraries. Default is OFF.
+# Boost_USE_STATIC_RUNTIME - Set to ON or OFF to specify whether to use
+# libraries linked statically to the C++ runtime
+# ('s' tag). Default is platform dependent.
+# Boost_USE_DEBUG_RUNTIME - Set to ON or OFF to specify whether to use
+# libraries linked to the MS debug C++ runtime
+# ('g' tag). Default is ON.
+# Boost_USE_DEBUG_PYTHON - Set to ON to use libraries compiled with a
+# debug Python build ('y' tag). Default is OFF.
+# Boost_USE_STLPORT - Set to ON to use libraries compiled with
+# STLPort ('p' tag). Default is OFF.
+# Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS
+# - Set to ON to use libraries compiled with
+# STLPort deprecated "native iostreams"
+# ('n' tag). Default is OFF.
+# Boost_COMPILER - Set to the compiler-specific library suffix
+# (e.g. "-gcc43"). Default is auto-computed
+# for the C++ compiler in use.
+# Boost_THREADAPI - Suffix for "thread" component library name,
+# such as "pthread" or "win32". Names with
+# and without this suffix will both be tried.
+# Boost_NAMESPACE - Alternate namespace used to build boost with
+# e.g. if set to "myboost", will search for
+# myboost_thread instead of boost_thread.
+#
+# Other variables one may set to control this module are::
+#
+# Boost_DEBUG - Set to ON to enable debug output from FindBoost.
+# Please enable this before filing any bug report.
+# Boost_DETAILED_FAILURE_MSG
+# - Set to ON to add detailed information to the
+# failure message even when the REQUIRED option
+# is not given to the find_package call.
+# Boost_REALPATH - Set to ON to resolve symlinks for discovered
+# libraries to assist with packaging. For example,
+# the "system" component library may be resolved to
+# "/usr/lib/libboost_system.so.1.42.0" instead of
+# "/usr/lib/libboost_system.so". This does not
+# affect linking and should not be enabled unless
+# the user needs this information.
+#
+# On Visual Studio and Borland compilers Boost headers request automatic
+# linking to corresponding libraries. This requires matching libraries
+# to be linked explicitly or available in the link library search path.
+# In this case setting Boost_USE_STATIC_LIBS to OFF may not achieve
+# dynamic linking. Boost automatic linking typically requests static
+# libraries with a few exceptions (such as Boost.Python). Use::
+#
+# add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
+#
+# to ask Boost to report information about automatic linking requests.
+#
+# Example to find Boost headers only::
+#
+# find_package(Boost 1.36.0)
+# if(Boost_FOUND)
+# include_directories(${Boost_INCLUDE_DIRS})
+# add_executable(foo foo.cc)
+# endif()
+#
+# Example to find Boost headers and some *static* libraries::
+#
+# set(Boost_USE_STATIC_LIBS ON) # only find static libs
+# set(Boost_USE_MULTITHREADED ON)
+# set(Boost_USE_STATIC_RUNTIME OFF)
+# find_package(Boost 1.36.0 COMPONENTS date_time filesystem system ...)
+# if(Boost_FOUND)
+# include_directories(${Boost_INCLUDE_DIRS})
+# add_executable(foo foo.cc)
+# target_link_libraries(foo ${Boost_LIBRARIES})
+# endif()
+#
+# Boost CMake
+# ^^^^^^^^^^^
+#
+# If Boost was built using the boost-cmake project it provides a package
+# configuration file for use with find_package's Config mode. This
+# module looks for the package configuration file called
+# BoostConfig.cmake or boost-config.cmake and stores the result in cache
+# entry "Boost_DIR". If found, the package configuration file is loaded
+# and this module returns with no further action. See documentation of
+# the Boost CMake package configuration for details on what it provides.
+#
+# Set Boost_NO_BOOST_CMAKE to ON to disable the search for boost-cmake.
+
+#=============================================================================
+# Copyright 2006-2012 Kitware, Inc.
+# Copyright 2006-2008 Andreas Schneider <mail@cynapses.org>
+# Copyright 2007 Wengo
+# Copyright 2007 Mike Jackson
+# Copyright 2008 Andreas Pakulat <apaku@gmx.de>
+# Copyright 2008-2012 Philip Lowman <philip@yhbt.com>
+#
+# 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.)
+
+
+#-------------------------------------------------------------------------------
+# Before we go searching, check whether boost-cmake is available, unless the
+# user specifically asked NOT to search for boost-cmake.
+#
+# If Boost_DIR is set, this behaves as any find_package call would. If not,
+# it looks at BOOST_ROOT and BOOSTROOT to find Boost.
+#
+if (NOT Boost_NO_BOOST_CMAKE)
+ # If Boost_DIR is not set, look for BOOSTROOT and BOOST_ROOT as alternatives,
+ # since these are more conventional for Boost.
+ if ("$ENV{Boost_DIR}" STREQUAL "")
+ if (NOT "$ENV{BOOST_ROOT}" STREQUAL "")
+ set(ENV{Boost_DIR} $ENV{BOOST_ROOT})
+ elseif (NOT "$ENV{BOOSTROOT}" STREQUAL "")
+ set(ENV{Boost_DIR} $ENV{BOOSTROOT})
+ endif()
+ endif()
+
+ # Do the same find_package call but look specifically for the CMake version.
+ # Note that args are passed in the Boost_FIND_xxxxx variables, so there is no
+ # need to delegate them to this find_package call.
+ find_package(Boost QUIET NO_MODULE)
+ mark_as_advanced(Boost_DIR)
+
+ # If we found boost-cmake, then we're done. Print out what we found.
+ # Otherwise let the rest of the module try to find it.
+ if (Boost_FOUND)
+ message("Boost ${Boost_FIND_VERSION} found.")
+ if (Boost_FIND_COMPONENTS)
+ message("Found Boost components:")
+ message(" ${Boost_FIND_COMPONENTS}")
+ endif()
+ return()
+ endif()
+endif()
+
+
+#-------------------------------------------------------------------------------
+# FindBoost functions & macros
+#
+
+############################################
+#
+# Check the existence of the libraries.
+#
+############################################
+# This macro was taken directly from the FindQt4.cmake file that is included
+# with the CMake distribution. This is NOT my work. All work was done by the
+# original authors of the FindQt4.cmake file. Only minor modifications were
+# made to remove references to Qt and make this file more generally applicable
+# And ELSE/ENDIF pairs were removed for readability.
+#########################################################################
+
+macro(_Boost_ADJUST_LIB_VARS basename)
+ if(Boost_INCLUDE_DIR )
+ if(Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
+ # if the generator supports configuration types then set
+ # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
+ if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
+ set(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
+ else()
+ # if there are no configuration types and CMAKE_BUILD_TYPE has no value
+ # then just use the release libraries
+ set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} )
+ endif()
+ # FIXME: This probably should be set for both cases
+ set(Boost_${basename}_LIBRARIES optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
+ endif()
+
+ # if only the release version was found, set the debug variable also to the release version
+ if(Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
+ set(Boost_${basename}_LIBRARY_DEBUG ${Boost_${basename}_LIBRARY_RELEASE})
+ set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE})
+ set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE})
+ endif()
+
+ # if only the debug version was found, set the release variable also to the debug version
+ if(Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
+ set(Boost_${basename}_LIBRARY_RELEASE ${Boost_${basename}_LIBRARY_DEBUG})
+ set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_DEBUG})
+ set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_DEBUG})
+ endif()
+
+ # If the debug & release library ends up being the same, omit the keywords
+ if(${Boost_${basename}_LIBRARY_RELEASE} STREQUAL ${Boost_${basename}_LIBRARY_DEBUG})
+ set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} )
+ set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE} )
+ endif()
+
+ if(Boost_${basename}_LIBRARY)
+ set(Boost_${basename}_FOUND ON)
+ endif()
+
+ endif()
+ # Make variables changeable to the advanced user
+ mark_as_advanced(
+ Boost_${basename}_LIBRARY_RELEASE
+ Boost_${basename}_LIBRARY_DEBUG
+ )
+endmacro()
+
+macro(_Boost_CHANGE_DETECT changed_var)
+ set(${changed_var} 0)
+ foreach(v ${ARGN})
+ if(DEFINED _Boost_COMPONENTS_SEARCHED)
+ if(${v})
+ if(_${v}_LAST)
+ string(COMPARE NOTEQUAL "${${v}}" "${_${v}_LAST}" _${v}_CHANGED)
+ else()
+ set(_${v}_CHANGED 1)
+ endif()
+ elseif(_${v}_LAST)
+ set(_${v}_CHANGED 1)
+ endif()
+ if(_${v}_CHANGED)
+ set(${changed_var} 1)
+ endif()
+ else()
+ set(_${v}_CHANGED 0)
+ endif()
+ endforeach()
+endmacro()
+
+macro(_Boost_FIND_LIBRARY var)
+ find_library(${var} ${ARGN})
+
+ if(${var})
+ # If this is the first library found then save Boost_LIBRARY_DIR.
+ if(NOT Boost_LIBRARY_DIR)
+ get_filename_component(_dir "${${var}}" PATH)
+ set(Boost_LIBRARY_DIR "${_dir}" CACHE PATH "Boost library directory" FORCE)
+ endif()
+ elseif(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT)
+ # Try component-specific hints but do not save Boost_LIBRARY_DIR.
+ find_library(${var} HINTS ${_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT} ${ARGN})
+ endif()
+
+ # If Boost_LIBRARY_DIR is known then search only there.
+ if(Boost_LIBRARY_DIR)
+ set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH)
+ endif()
+endmacro()
+
+#-------------------------------------------------------------------------------
+
+#
+# Runs compiler with "-dumpversion" and parses major/minor
+# version with a regex.
+#
+function(_Boost_COMPILER_DUMPVERSION _OUTPUT_VERSION)
+
+ exec_program(${CMAKE_CXX_COMPILER}
+ ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
+ OUTPUT_VARIABLE _boost_COMPILER_VERSION
+ )
+ string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
+ _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION})
+
+ set(${_OUTPUT_VERSION} ${_boost_COMPILER_VERSION} PARENT_SCOPE)
+endfunction()
+
+#
+# Take a list of libraries with "thread" in it
+# and prepend duplicates with "thread_${Boost_THREADAPI}"
+# at the front of the list
+#
+function(_Boost_PREPEND_LIST_WITH_THREADAPI _output)
+ set(_orig_libnames ${ARGN})
+ string(REPLACE "thread" "thread_${Boost_THREADAPI}" _threadapi_libnames "${_orig_libnames}")
+ set(${_output} ${_threadapi_libnames} ${_orig_libnames} PARENT_SCOPE)
+endfunction()
+
+#
+# If a library is found, replace its cache entry with its REALPATH
+#
+function(_Boost_SWAP_WITH_REALPATH _library _docstring)
+ if(${_library})
+ get_filename_component(_boost_filepathreal ${${_library}} REALPATH)
+ unset(${_library} CACHE)
+ set(${_library} ${_boost_filepathreal} CACHE FILEPATH "${_docstring}")
+ endif()
+endfunction()
+
+function(_Boost_CHECK_SPELLING _var)
+ if(${_var})
+ string(TOUPPER ${_var} _var_UC)
+ message(FATAL_ERROR "ERROR: ${_var} is not the correct spelling. The proper spelling is ${_var_UC}.")
+ endif()
+endfunction()
+
+# Guesses Boost's compiler prefix used in built library names
+# Returns the guess by setting the variable pointed to by _ret
+function(_Boost_GUESS_COMPILER_PREFIX _ret)
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel"
+ OR CMAKE_CXX_COMPILER MATCHES "icl"
+ OR CMAKE_CXX_COMPILER MATCHES "icpc")
+ if(WIN32)
+ set (_boost_COMPILER "-iw")
+ else()
+ set (_boost_COMPILER "-il")
+ endif()
+ elseif (MSVC14)
+ set(_boost_COMPILER "-vc140")
+ elseif (MSVC12)
+ set(_boost_COMPILER "-vc120")
+ elseif (MSVC11)
+ set(_boost_COMPILER "-vc110")
+ elseif (MSVC10)
+ set(_boost_COMPILER "-vc100")
+ elseif (MSVC90)
+ set(_boost_COMPILER "-vc90")
+ elseif (MSVC80)
+ set(_boost_COMPILER "-vc80")
+ elseif (MSVC71)
+ set(_boost_COMPILER "-vc71")
+ elseif (MSVC70) # Good luck!
+ set(_boost_COMPILER "-vc7") # yes, this is correct
+ elseif (MSVC60) # Good luck!
+ set(_boost_COMPILER "-vc6") # yes, this is correct
+ elseif (BORLAND)
+ set(_boost_COMPILER "-bcb")
+ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
+ set(_boost_COMPILER "-sw")
+ elseif (MINGW)
+ if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34)
+ set(_boost_COMPILER "-mgw") # no GCC version encoding prior to 1.34
+ else()
+ _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION)
+ set(_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}")
+ endif()
+ elseif (UNIX)
+ if (CMAKE_COMPILER_IS_GNUCXX)
+ if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34)
+ set(_boost_COMPILER "-gcc") # no GCC version encoding prior to 1.34
+ else()
+ _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION)
+ # Determine which version of GCC we have.
+ if(APPLE)
+ if(Boost_MINOR_VERSION)
+ if(${Boost_MINOR_VERSION} GREATER 35)
+ # In Boost 1.36.0 and newer, the mangled compiler name used
+ # on Mac OS X/Darwin is "xgcc".
+ set(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}")
+ else()
+ # In Boost <= 1.35.0, there is no mangled compiler name for
+ # the Mac OS X/Darwin version of GCC.
+ set(_boost_COMPILER "")
+ endif()
+ else()
+ # We don't know the Boost version, so assume it's
+ # pre-1.36.0.
+ set(_boost_COMPILER "")
+ endif()
+ else()
+ set(_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}")
+ endif()
+ endif()
+ endif ()
+ else()
+ # TODO at least Boost_DEBUG here?
+ set(_boost_COMPILER "")
+ endif()
+ set(${_ret} ${_boost_COMPILER} PARENT_SCOPE)
+endfunction()
+
+#
+# End functions/macros
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+# main.
+#-------------------------------------------------------------------------------
+
+if(NOT DEFINED Boost_USE_MULTITHREADED)
+ set(Boost_USE_MULTITHREADED TRUE)
+endif()
+if(NOT DEFINED Boost_USE_DEBUG_RUNTIME)
+ set(Boost_USE_DEBUG_RUNTIME TRUE)
+endif()
+
+# Check the version of Boost against the requested version.
+if(Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR)
+ message(SEND_ERROR "When requesting a specific version of Boost, you must provide at least the major and minor version numbers, e.g., 1.34")
+endif()
+
+if(Boost_FIND_VERSION_EXACT)
+ # The version may appear in a directory with or without the patch
+ # level, even when the patch level is non-zero.
+ set(_boost_TEST_VERSIONS
+ "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}.${Boost_FIND_VERSION_PATCH}"
+ "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
+else()
+ # The user has not requested an exact version. Among known
+ # versions, find those that are acceptable to the user request.
+ set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS}
+ "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"
+ "1.46.0" "1.46" "1.45.0" "1.45" "1.44.0" "1.44" "1.43.0" "1.43" "1.42.0" "1.42"
+ "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37"
+ "1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0"
+ "1.34" "1.33.1" "1.33.0" "1.33")
+ set(_boost_TEST_VERSIONS)
+ if(Boost_FIND_VERSION)
+ set(_Boost_FIND_VERSION_SHORT "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
+ # Select acceptable versions.
+ foreach(version ${_Boost_KNOWN_VERSIONS})
+ if(NOT "${version}" VERSION_LESS "${Boost_FIND_VERSION}")
+ # This version is high enough.
+ list(APPEND _boost_TEST_VERSIONS "${version}")
+ elseif("${version}.99" VERSION_EQUAL "${_Boost_FIND_VERSION_SHORT}.99")
+ # This version is a short-form for the requested version with
+ # the patch level dropped.
+ list(APPEND _boost_TEST_VERSIONS "${version}")
+ endif()
+ endforeach()
+ else()
+ # Any version is acceptable.
+ set(_boost_TEST_VERSIONS "${_Boost_KNOWN_VERSIONS}")
+ endif()
+endif()
+
+# The reason that we failed to find Boost. This will be set to a
+# user-friendly message when we fail to find some necessary piece of
+# Boost.
+set(Boost_ERROR_REASON)
+
+if(Boost_DEBUG)
+ # Output some of their choices
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_USE_MULTITHREADED = ${Boost_USE_MULTITHREADED}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_USE_STATIC_LIBS = ${Boost_USE_STATIC_LIBS}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_USE_STATIC_RUNTIME = ${Boost_USE_STATIC_RUNTIME}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_ADDITIONAL_VERSIONS = ${Boost_ADDITIONAL_VERSIONS}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_NO_SYSTEM_PATHS = ${Boost_NO_SYSTEM_PATHS}")
+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
+ # runtime, then you can choose to link to either a static or a
+ # dynamic Boost library, the default is to do a static link. You
+ # can alter this for a specific library "whatever" by defining
+ # BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to be
+ # linked dynamically. Alternatively you can force all Boost
+ # libraries to dynamic link by defining BOOST_ALL_DYN_LINK.
+
+ # This feature can be disabled for Boost library "whatever" by
+ # defining BOOST_WHATEVER_NO_LIB, or for all of Boost by defining
+ # BOOST_ALL_NO_LIB.
+
+ # If you want to observe which libraries are being linked against
+ # then defining BOOST_LIB_DIAGNOSTIC will cause the auto-linking
+ # code to emit a #pragma message each time a library is selected
+ # for linking.
+ set(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC")
+endif()
+
+_Boost_CHECK_SPELLING(Boost_ROOT)
+_Boost_CHECK_SPELLING(Boost_LIBRARYDIR)
+_Boost_CHECK_SPELLING(Boost_INCLUDEDIR)
+
+# Collect environment variable inputs as hints. Do not consider changes.
+foreach(v BOOSTROOT BOOST_ROOT BOOST_INCLUDEDIR BOOST_LIBRARYDIR)
+ set(_env $ENV{${v}})
+ if(_env)
+ file(TO_CMAKE_PATH "${_env}" _ENV_${v})
+ else()
+ set(_ENV_${v} "")
+ endif()
+endforeach()
+if(NOT _ENV_BOOST_ROOT AND _ENV_BOOSTROOT)
+ set(_ENV_BOOST_ROOT "${_ENV_BOOSTROOT}")
+endif()
+
+# Collect inputs and cached results. Detect changes since the last run.
+if(NOT BOOST_ROOT AND BOOSTROOT)
+ set(BOOST_ROOT "${BOOSTROOT}")
+endif()
+set(_Boost_VARS_DIR
+ BOOST_ROOT
+ Boost_NO_SYSTEM_PATHS
+ )
+
+if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Declared as CMake or Environmental Variables:")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " BOOST_ROOT = ${BOOST_ROOT}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " BOOST_INCLUDEDIR = ${BOOST_INCLUDEDIR}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " BOOST_LIBRARYDIR = ${BOOST_LIBRARYDIR}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}")
+endif()
+
+# ------------------------------------------------------------------------
+# Search for Boost include DIR
+# ------------------------------------------------------------------------
+
+set(_Boost_VARS_INC BOOST_INCLUDEDIR Boost_INCLUDE_DIR Boost_ADDITIONAL_VERSIONS)
+_Boost_CHANGE_DETECT(_Boost_CHANGE_INCDIR ${_Boost_VARS_DIR} ${_Boost_VARS_INC})
+# Clear Boost_INCLUDE_DIR if it did not change but other input affecting the
+# location did. We will find a new one based on the new inputs.
+if(_Boost_CHANGE_INCDIR AND NOT _Boost_INCLUDE_DIR_CHANGED)
+ unset(Boost_INCLUDE_DIR CACHE)
+endif()
+
+if(NOT Boost_INCLUDE_DIR)
+ set(_boost_INCLUDE_SEARCH_DIRS "")
+ if(BOOST_INCLUDEDIR)
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_INCLUDEDIR})
+ elseif(_ENV_BOOST_INCLUDEDIR)
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_INCLUDEDIR})
+ endif()
+
+ if( BOOST_ROOT )
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_ROOT}/include ${BOOST_ROOT})
+ elseif( _ENV_BOOST_ROOT )
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_ROOT}/include ${_ENV_BOOST_ROOT})
+ endif()
+
+ if( Boost_NO_SYSTEM_PATHS)
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH)
+ else()
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS PATHS
+ C:/boost/include
+ C:/boost
+ /sw/local/include
+ )
+ endif()
+
+ # Try to find Boost by stepping backwards through the Boost versions
+ # we know about.
+ # Build a list of path suffixes for each version.
+ set(_boost_PATH_SUFFIXES)
+ foreach(_boost_VER ${_boost_TEST_VERSIONS})
+ # Add in a path suffix, based on the required version, ideally
+ # we could read this from version.hpp, but for that to work we'd
+ # need to know the include dir already
+ set(_boost_BOOSTIFIED_VERSION)
+
+ # Transform 1.35 => 1_35 and 1.36.0 => 1_36_0
+ if(_boost_VER MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
+ set(_boost_BOOSTIFIED_VERSION
+ "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}_${CMAKE_MATCH_3}")
+ elseif(_boost_VER MATCHES "([0-9]+)\\.([0-9]+)")
+ set(_boost_BOOSTIFIED_VERSION
+ "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}")
+ endif()
+
+ list(APPEND _boost_PATH_SUFFIXES
+ "boost-${_boost_BOOSTIFIED_VERSION}"
+ "boost_${_boost_BOOSTIFIED_VERSION}"
+ "boost/boost-${_boost_BOOSTIFIED_VERSION}"
+ "boost/boost_${_boost_BOOSTIFIED_VERSION}"
+ )
+
+ endforeach()
+
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Include debugging info:")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " _boost_INCLUDE_SEARCH_DIRS = ${_boost_INCLUDE_SEARCH_DIRS}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " _boost_PATH_SUFFIXES = ${_boost_PATH_SUFFIXES}")
+ endif()
+
+ # Look for a standard boost header file.
+ find_path(Boost_INCLUDE_DIR
+ NAMES boost/config.hpp
+ HINTS ${_boost_INCLUDE_SEARCH_DIRS}
+ PATH_SUFFIXES ${_boost_PATH_SUFFIXES}
+ )
+endif()
+
+# ------------------------------------------------------------------------
+# Extract version information from version.hpp
+# ------------------------------------------------------------------------
+
+# Set Boost_FOUND based only on header location and version.
+# It will be updated below for component libraries.
+if(Boost_INCLUDE_DIR)
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "location of version.hpp: ${Boost_INCLUDE_DIR}/boost/version.hpp")
+ endif()
+
+ # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
+ set(Boost_VERSION 0)
+ set(Boost_LIB_VERSION "")
+ file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS REGEX "#define BOOST_(LIB_)?VERSION ")
+ set(_Boost_VERSION_REGEX "([0-9]+)")
+ set(_Boost_LIB_VERSION_REGEX "\"([0-9_]+)\"")
+ foreach(v VERSION LIB_VERSION)
+ if("${_boost_VERSION_HPP_CONTENTS}" MATCHES "#define BOOST_${v} ${_Boost_${v}_REGEX}")
+ set(Boost_${v} "${CMAKE_MATCH_1}")
+ endif()
+ endforeach()
+ unset(_boost_VERSION_HPP_CONTENTS)
+
+ math(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000")
+ math(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000")
+ math(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100")
+
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}\nBoost include path: ${Boost_INCLUDE_DIR}")
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "version.hpp reveals boost "
+ "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
+ endif()
+
+ if(Boost_FIND_VERSION)
+ # Set Boost_FOUND based on requested version.
+ set(_Boost_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
+ if("${_Boost_VERSION}" VERSION_LESS "${Boost_FIND_VERSION}")
+ set(Boost_FOUND 0)
+ set(_Boost_VERSION_AGE "old")
+ elseif(Boost_FIND_VERSION_EXACT AND
+ NOT "${_Boost_VERSION}" VERSION_EQUAL "${Boost_FIND_VERSION}")
+ set(Boost_FOUND 0)
+ set(_Boost_VERSION_AGE "new")
+ else()
+ set(Boost_FOUND 1)
+ endif()
+ if(NOT Boost_FOUND)
+ # State that we found a version of Boost that is too new or too old.
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}\nDetected version of Boost is too ${_Boost_VERSION_AGE}. Requested version was ${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
+ if (Boost_FIND_VERSION_PATCH)
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}.${Boost_FIND_VERSION_PATCH}")
+ endif ()
+ if (NOT Boost_FIND_VERSION_EXACT)
+ set(Boost_ERROR_REASON "${Boost_ERROR_REASON} (or newer)")
+ endif ()
+ set(Boost_ERROR_REASON "${Boost_ERROR_REASON}.")
+ endif ()
+ else()
+ # Caller will accept any Boost version.
+ set(Boost_FOUND 1)
+ endif()
+else()
+ set(Boost_FOUND 0)
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.")
+endif()
+
+# ------------------------------------------------------------------------
+# Prefix initialization
+# ------------------------------------------------------------------------
+
+set(Boost_LIB_PREFIX "")
+if ( WIN32 AND Boost_USE_STATIC_LIBS AND NOT CYGWIN)
+ set(Boost_LIB_PREFIX "lib")
+endif()
+
+if ( NOT Boost_NAMESPACE )
+ set(Boost_NAMESPACE "boost")
+endif()
+
+# ------------------------------------------------------------------------
+# Suffix initialization and compiler suffix detection.
+# ------------------------------------------------------------------------
+
+set(_Boost_VARS_NAME
+ Boost_NAMESPACE
+ Boost_COMPILER
+ Boost_THREADAPI
+ Boost_USE_DEBUG_PYTHON
+ Boost_USE_MULTITHREADED
+ Boost_USE_STATIC_LIBS
+ Boost_USE_STATIC_RUNTIME
+ Boost_USE_STLPORT
+ Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS
+ )
+_Boost_CHANGE_DETECT(_Boost_CHANGE_LIBNAME ${_Boost_VARS_NAME})
+
+# Setting some more suffixes for the library
+if (Boost_COMPILER)
+ set(_boost_COMPILER ${Boost_COMPILER})
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "using user-specified Boost_COMPILER = ${_boost_COMPILER}")
+ endif()
+else()
+ # Attempt to guess the compiler suffix
+ # NOTE: this is not perfect yet, if you experience any issues
+ # please report them and use the Boost_COMPILER variable
+ # to work around the problems.
+ _Boost_GUESS_COMPILER_PREFIX(_boost_COMPILER)
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "guessed _boost_COMPILER = ${_boost_COMPILER}")
+ endif()
+endif()
+
+set (_boost_MULTITHREADED "-mt")
+if( NOT Boost_USE_MULTITHREADED )
+ set (_boost_MULTITHREADED "")
+endif()
+if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_MULTITHREADED = ${_boost_MULTITHREADED}")
+endif()
+
+#======================
+# Systematically build up the Boost ABI tag
+# http://boost.org/doc/libs/1_41_0/more/getting_started/windows.html#library-naming
+set( _boost_RELEASE_ABI_TAG "-")
+set( _boost_DEBUG_ABI_TAG "-")
+# Key Use this library when:
+# s linking statically to the C++ standard library and
+# compiler runtime support libraries.
+if(Boost_USE_STATIC_RUNTIME)
+ set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}s")
+ set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}s")
+endif()
+# g using debug versions of the standard and runtime
+# support libraries
+if(WIN32 AND Boost_USE_DEBUG_RUNTIME)
+ if(MSVC OR "${CMAKE_CXX_COMPILER}" MATCHES "icl"
+ OR "${CMAKE_CXX_COMPILER}" MATCHES "icpc")
+ set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}g")
+ endif()
+endif()
+# y using special debug build of python
+if(Boost_USE_DEBUG_PYTHON)
+ set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}y")
+endif()
+# d using a debug version of your code
+set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}d")
+# p using the STLport standard library rather than the
+# default one supplied with your compiler
+if(Boost_USE_STLPORT)
+ set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}p")
+ set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}p")
+endif()
+# n using the STLport deprecated "native iostreams" feature
+if(Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS)
+ set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}n")
+ set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}n")
+endif()
+
+if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_RELEASE_ABI_TAG = ${_boost_RELEASE_ABI_TAG}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_DEBUG_ABI_TAG = ${_boost_DEBUG_ABI_TAG}")
+endif()
+
+# ------------------------------------------------------------------------
+# Begin finding boost libraries
+# ------------------------------------------------------------------------
+set(_Boost_VARS_LIB BOOST_LIBRARYDIR Boost_LIBRARY_DIR)
+_Boost_CHANGE_DETECT(_Boost_CHANGE_LIBDIR ${_Boost_VARS_DIR} ${_Boost_VARS_LIB} Boost_INCLUDE_DIR)
+# Clear Boost_LIBRARY_DIR if it did not change but other input affecting the
+# location did. We will find a new one based on the new inputs.
+if(_Boost_CHANGE_LIBDIR AND NOT _Boost_LIBRARY_DIR_CHANGED)
+ unset(Boost_LIBRARY_DIR CACHE)
+endif()
+
+if(Boost_LIBRARY_DIR)
+ set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH)
+else()
+ set(_boost_LIBRARY_SEARCH_DIRS "")
+ if(BOOST_LIBRARYDIR)
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS ${BOOST_LIBRARYDIR})
+ elseif(_ENV_BOOST_LIBRARYDIR)
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS ${_ENV_BOOST_LIBRARYDIR})
+ endif()
+
+ if(BOOST_ROOT)
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS ${BOOST_ROOT}/lib ${BOOST_ROOT}/stage/lib)
+ elseif(_ENV_BOOST_ROOT)
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS ${_ENV_BOOST_ROOT}/lib ${_ENV_BOOST_ROOT}/stage/lib)
+ endif()
+
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS
+ ${Boost_INCLUDE_DIR}/lib
+ ${Boost_INCLUDE_DIR}/../lib
+ ${Boost_INCLUDE_DIR}/stage/lib
+ )
+ if( Boost_NO_SYSTEM_PATHS )
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH)
+ else()
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS PATHS
+ C:/boost/lib
+ C:/boost
+ /sw/local/lib
+ )
+ endif()
+endif()
+
+if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_LIBRARY_SEARCH_DIRS = ${_boost_LIBRARY_SEARCH_DIRS}")
+endif()
+
+# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
+if( Boost_USE_STATIC_LIBS )
+ set( _boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ if(WIN32)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ else()
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
+ endif()
+endif()
+
+# We want to use the tag inline below without risking double dashes
+if(_boost_RELEASE_ABI_TAG)
+ if(${_boost_RELEASE_ABI_TAG} STREQUAL "-")
+ set(_boost_RELEASE_ABI_TAG "")
+ endif()
+endif()
+if(_boost_DEBUG_ABI_TAG)
+ if(${_boost_DEBUG_ABI_TAG} STREQUAL "-")
+ set(_boost_DEBUG_ABI_TAG "")
+ endif()
+endif()
+
+# The previous behavior of FindBoost when Boost_USE_STATIC_LIBS was enabled
+# on WIN32 was to:
+# 1. Search for static libs compiled against a SHARED C++ standard runtime library (use if found)
+# 2. Search for static libs compiled against a STATIC C++ standard runtime library (use if found)
+# We maintain this behavior since changing it could break people's builds.
+# To disable the ambiguous behavior, the user need only
+# set Boost_USE_STATIC_RUNTIME either ON or OFF.
+set(_boost_STATIC_RUNTIME_WORKAROUND false)
+if(WIN32 AND Boost_USE_STATIC_LIBS)
+ if(NOT DEFINED Boost_USE_STATIC_RUNTIME)
+ set(_boost_STATIC_RUNTIME_WORKAROUND true)
+ endif()
+endif()
+
+# On versions < 1.35, remove the System library from the considered list
+# since it wasn't added until 1.35.
+if(Boost_VERSION AND Boost_FIND_COMPONENTS)
+ if(Boost_VERSION LESS 103500)
+ list(REMOVE_ITEM Boost_FIND_COMPONENTS system)
+ endif()
+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})
+ string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+ foreach(c DEBUG RELEASE)
+ set(_var Boost_${UPPERCOMPONENT}_LIBRARY_${c})
+ unset(${_var} CACHE)
+ set(${_var} "${_var}-NOTFOUND")
+ endforeach()
+ endforeach()
+ set(_Boost_COMPONENTS_SEARCHED "")
+endif()
+
+foreach(COMPONENT ${Boost_FIND_COMPONENTS})
+ string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+
+ set( _boost_docstring_release "Boost ${COMPONENT} library (release)")
+ set( _boost_docstring_debug "Boost ${COMPONENT} library (debug)")
+
+ # Compute component-specific hints.
+ set(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT "")
+ if(${COMPONENT} STREQUAL "mpi" OR ${COMPONENT} STREQUAL "mpi_python" OR
+ ${COMPONENT} STREQUAL "graph_parallel")
+ foreach(lib ${MPI_CXX_LIBRARIES} ${MPI_C_LIBRARIES})
+ if(IS_ABSOLUTE "${lib}")
+ get_filename_component(libdir "${lib}" PATH)
+ string(REPLACE "\\" "/" libdir "${libdir}")
+ list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT ${libdir})
+ endif()
+ endforeach()
+ endif()
+
+ # Consolidate and report component-specific hints.
+ if(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT)
+ list(REMOVE_DUPLICATES _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT)
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Component-specific library search paths for ${COMPONENT}: "
+ "${_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT}")
+ endif()
+ endif()
+
+ #
+ # Find RELEASE libraries
+ #
+ set(_boost_RELEASE_NAMES
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT} )
+ if(_boost_STATIC_RUNTIME_WORKAROUND)
+ set(_boost_RELEASE_STATIC_ABI_TAG "-s${_boost_RELEASE_ABI_TAG}")
+ list(APPEND _boost_RELEASE_NAMES
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} )
+ endif()
+ if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread")
+ _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_RELEASE_NAMES ${_boost_RELEASE_NAMES})
+ endif()
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Searching for ${UPPERCOMPONENT}_LIBRARY_RELEASE: ${_boost_RELEASE_NAMES}")
+ endif()
+
+ # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing.
+ string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS}")
+
+ _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE
+ NAMES ${_boost_RELEASE_NAMES}
+ HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp}
+ NAMES_PER_DIR
+ DOC "${_boost_docstring_release}"
+ )
+
+ #
+ # Find DEBUG libraries
+ #
+ set(_boost_DEBUG_NAMES
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT} )
+ if(_boost_STATIC_RUNTIME_WORKAROUND)
+ set(_boost_DEBUG_STATIC_ABI_TAG "-s${_boost_DEBUG_ABI_TAG}")
+ list(APPEND _boost_DEBUG_NAMES
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} )
+ endif()
+ if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread")
+ _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_DEBUG_NAMES ${_boost_DEBUG_NAMES})
+ endif()
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Searching for ${UPPERCOMPONENT}_LIBRARY_DEBUG: ${_boost_DEBUG_NAMES}")
+ endif()
+
+ # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing.
+ string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS}")
+
+ _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG
+ NAMES ${_boost_DEBUG_NAMES}
+ HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp}
+ NAMES_PER_DIR
+ DOC "${_boost_docstring_debug}"
+ )
+
+ if(Boost_REALPATH)
+ _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE "${_boost_docstring_release}")
+ _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG "${_boost_docstring_debug}" )
+ endif()
+
+ _Boost_ADJUST_LIB_VARS(${UPPERCOMPONENT})
+
+endforeach()
+
+# Restore the original find library ordering
+if( Boost_USE_STATIC_LIBS )
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${_boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
+endif()
+
+# ------------------------------------------------------------------------
+# End finding boost libraries
+# ------------------------------------------------------------------------
+
+set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
+set(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR})
+
+# The above setting of Boost_FOUND was based only on the header files.
+# Update it for the requested component libraries.
+if(Boost_FOUND)
+ # The headers were found. Check for requested component libs.
+ set(_boost_CHECKED_COMPONENT FALSE)
+ set(_Boost_MISSING_COMPONENTS "")
+ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
+ string(TOUPPER ${COMPONENT} COMPONENT)
+ set(_boost_CHECKED_COMPONENT TRUE)
+ if(NOT Boost_${COMPONENT}_FOUND)
+ string(TOLOWER ${COMPONENT} COMPONENT)
+ list(APPEND _Boost_MISSING_COMPONENTS ${COMPONENT})
+ endif()
+ endforeach()
+
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] Boost_FOUND = ${Boost_FOUND}")
+ endif()
+
+ if (_Boost_MISSING_COMPONENTS)
+ set(Boost_FOUND 0)
+ # We were unable to find some libraries, so generate a sensible
+ # error message that lists the libraries we were unable to find.
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}\nCould not find the following")
+ if(Boost_USE_STATIC_LIBS)
+ set(Boost_ERROR_REASON "${Boost_ERROR_REASON} static")
+ endif()
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON} Boost libraries:\n")
+ foreach(COMPONENT ${_Boost_MISSING_COMPONENTS})
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON} ${Boost_NAMESPACE}_${COMPONENT}\n")
+ endforeach()
+
+ list(LENGTH Boost_FIND_COMPONENTS Boost_NUM_COMPONENTS_WANTED)
+ list(LENGTH _Boost_MISSING_COMPONENTS Boost_NUM_MISSING_COMPONENTS)
+ if (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS})
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.")
+ else ()
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}Some (but not all) of the required Boost libraries were found. You may need to install these additional Boost libraries. Alternatively, set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.")
+ endif ()
+ endif ()
+
+ if( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT )
+ # Compatibility Code for backwards compatibility with CMake
+ # 2.4's FindBoost module.
+
+ # Look for the boost library path.
+ # Note that the user may not have installed any libraries
+ # so it is quite possible the Boost_LIBRARY_DIRS may not exist.
+ set(_boost_LIB_DIR ${Boost_INCLUDE_DIR})
+
+ if("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+")
+ get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH)
+ endif()
+
+ if("${_boost_LIB_DIR}" MATCHES "/include$")
+ # Strip off the trailing "/include" in the path.
+ get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH)
+ endif()
+
+ if(EXISTS "${_boost_LIB_DIR}/lib")
+ set(_boost_LIB_DIR ${_boost_LIB_DIR}/lib)
+ else()
+ if(EXISTS "${_boost_LIB_DIR}/stage/lib")
+ set(_boost_LIB_DIR ${_boost_LIB_DIR}/stage/lib)
+ else()
+ set(_boost_LIB_DIR "")
+ endif()
+ endif()
+
+ if(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}")
+ set(Boost_LIBRARY_DIRS ${_boost_LIB_DIR})
+ endif()
+
+ endif()
+else()
+ # Boost headers were not found so no components were found.
+ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
+ string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+ set(Boost_${UPPERCOMPONENT}_FOUND 0)
+ endforeach()
+endif()
+
+# ------------------------------------------------------------------------
+# Notification to end user about what was found
+# ------------------------------------------------------------------------
+
+set(Boost_LIBRARIES "")
+if(Boost_FOUND)
+ if(NOT Boost_FIND_QUIETLY)
+ message(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
+ if(Boost_FIND_COMPONENTS)
+ message(STATUS "Found the following Boost libraries:")
+ endif()
+ endif()
+ foreach( COMPONENT ${Boost_FIND_COMPONENTS} )
+ string( TOUPPER ${COMPONENT} UPPERCOMPONENT )
+ if( Boost_${UPPERCOMPONENT}_FOUND )
+ if(NOT Boost_FIND_QUIETLY)
+ message (STATUS " ${COMPONENT}")
+ endif()
+ list(APPEND Boost_LIBRARIES ${Boost_${UPPERCOMPONENT}_LIBRARY})
+ endif()
+ endforeach()
+else()
+ if(Boost_FIND_REQUIRED)
+ message(SEND_ERROR "Unable to find the requested Boost libraries.\n${Boost_ERROR_REASON}")
+ else()
+ if(NOT Boost_FIND_QUIETLY)
+ # we opt not to automatically output Boost_ERROR_REASON here as
+ # it could be quite lengthy and somewhat imposing in its requests
+ # Since Boost is not always a required dependency we'll leave this
+ # up to the end-user.
+ if(Boost_DEBUG OR Boost_DETAILED_FAILURE_MSG)
+ message(STATUS "Could NOT find Boost\n${Boost_ERROR_REASON}")
+ else()
+ message(STATUS "Could NOT find Boost")
+ endif()
+ endif()
+ endif()
+endif()
+
+# Configure display of cache entries in GUI.
+foreach(v BOOSTROOT BOOST_ROOT ${_Boost_VARS_INC} ${_Boost_VARS_LIB})
+ get_property(_type CACHE ${v} PROPERTY TYPE)
+ if(_type)
+ set_property(CACHE ${v} PROPERTY ADVANCED 1)
+ if("x${_type}" STREQUAL "xUNINITIALIZED")
+ if("x${v}" STREQUAL "xBoost_ADDITIONAL_VERSIONS")
+ set_property(CACHE ${v} PROPERTY TYPE STRING)
+ else()
+ set_property(CACHE ${v} PROPERTY TYPE PATH)
+ endif()
+ endif()
+ endif()
+endforeach()
+
+# Record last used values of input variables so we can
+# detect on the next run if the user changed them.
+foreach(v
+ ${_Boost_VARS_INC} ${_Boost_VARS_LIB}
+ ${_Boost_VARS_DIR} ${_Boost_VARS_NAME}
+ )
+ if(DEFINED ${v})
+ set(_${v}_LAST "${${v}}" CACHE INTERNAL "Last used ${v} value.")
+ else()
+ unset(_${v}_LAST CACHE)
+ endif()
+endforeach()
+
+# Maintain a persistent list of components requested anywhere since
+# the last flush.
+set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}")
+list(APPEND _Boost_COMPONENTS_SEARCHED ${Boost_FIND_COMPONENTS})
+list(REMOVE_DUPLICATES _Boost_COMPONENTS_SEARCHED)
+list(SORT _Boost_COMPONENTS_SEARCHED)
+set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}"
+ CACHE INTERNAL "Components requested for this build tree.")
diff --git a/Modules/FindBullet.cmake b/Modules/FindBullet.cmake
new file mode 100644
index 0000000000..fc848fae02
--- /dev/null
+++ b/Modules/FindBullet.cmake
@@ -0,0 +1,105 @@
+#.rst:
+# FindBullet
+# ----------
+#
+# Try to find the Bullet physics engine
+#
+#
+#
+# ::
+#
+# This module defines the following variables
+#
+#
+#
+# ::
+#
+# BULLET_FOUND - Was bullet found
+# BULLET_INCLUDE_DIRS - the Bullet include directories
+# BULLET_LIBRARIES - Link to this, by default it includes
+# all bullet components (Dynamics,
+# Collision, LinearMath, & SoftBody)
+#
+#
+#
+# ::
+#
+# This module accepts the following variables
+#
+#
+#
+# ::
+#
+# BULLET_ROOT - Can be set to bullet install path or Windows build path
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2009 Philip Lowman <philip@yhbt.com>
+#
+# 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.)
+
+macro(_FIND_BULLET_LIBRARY _var)
+ find_library(${_var}
+ NAMES
+ ${ARGN}
+ HINTS
+ ${BULLET_ROOT}
+ ${BULLET_ROOT}/lib/Release
+ ${BULLET_ROOT}/lib/Debug
+ ${BULLET_ROOT}/out/release8/libs
+ ${BULLET_ROOT}/out/debug8/libs
+ PATH_SUFFIXES lib
+ )
+ mark_as_advanced(${_var})
+endmacro()
+
+macro(_BULLET_APPEND_LIBRARIES _list _release)
+ set(_debug ${_release}_DEBUG)
+ if(${_debug})
+ set(${_list} ${${_list}} optimized ${${_release}} debug ${${_debug}})
+ else()
+ set(${_list} ${${_list}} ${${_release}})
+ endif()
+endmacro()
+
+find_path(BULLET_INCLUDE_DIR NAMES btBulletCollisionCommon.h
+ HINTS
+ ${BULLET_ROOT}/include
+ ${BULLET_ROOT}/src
+ PATH_SUFFIXES bullet
+)
+
+# Find the libraries
+
+_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY BulletDynamics)
+_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY_DEBUG BulletDynamics_Debug BulletDynamics_d)
+_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY BulletCollision)
+_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY_DEBUG BulletCollision_Debug BulletCollision_d)
+_FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY BulletMath LinearMath)
+_FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY_DEBUG BulletMath_Debug BulletMath_d LinearMath_Debug LinearMath_d)
+_FIND_BULLET_LIBRARY(BULLET_SOFTBODY_LIBRARY BulletSoftBody)
+_FIND_BULLET_LIBRARY(BULLET_SOFTBODY_LIBRARY_DEBUG BulletSoftBody_Debug BulletSoftBody_d)
+
+
+# handle the QUIETLY and REQUIRED arguments and set BULLET_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Bullet DEFAULT_MSG
+ BULLET_DYNAMICS_LIBRARY BULLET_COLLISION_LIBRARY BULLET_MATH_LIBRARY
+ BULLET_SOFTBODY_LIBRARY BULLET_INCLUDE_DIR)
+
+set(BULLET_INCLUDE_DIRS ${BULLET_INCLUDE_DIR})
+if(BULLET_FOUND)
+ _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_DYNAMICS_LIBRARY)
+ _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_COLLISION_LIBRARY)
+ _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_MATH_LIBRARY)
+ _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_SOFTBODY_LIBRARY)
+endif()
diff --git a/Modules/FindCABLE.cmake b/Modules/FindCABLE.cmake
new file mode 100644
index 0000000000..5cea109ad7
--- /dev/null
+++ b/Modules/FindCABLE.cmake
@@ -0,0 +1,91 @@
+#.rst:
+# FindCABLE
+# ---------
+#
+# Find CABLE
+#
+# This module finds if CABLE is installed and determines where the
+# include files and libraries are. This code sets the following
+# variables:
+#
+# ::
+#
+# CABLE the path to the cable executable
+# CABLE_TCL_LIBRARY the path to the Tcl wrapper library
+# CABLE_INCLUDE_DIR the path to the include directory
+#
+#
+#
+# To build Tcl wrappers, you should add shared library and link it to
+# ${CABLE_TCL_LIBRARY}. You should also add ${CABLE_INCLUDE_DIR} as an
+# include directory.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+if(NOT CABLE)
+ find_path(CABLE_BUILD_DIR cableVersion.h)
+endif()
+
+if(CABLE_BUILD_DIR)
+ load_cache(${CABLE_BUILD_DIR}
+ EXCLUDE
+ BUILD_SHARED_LIBS
+ LIBRARY_OUTPUT_PATH
+ EXECUTABLE_OUTPUT_PATH
+ MAKECOMMAND
+ CMAKE_INSTALL_PREFIX
+ INCLUDE_INTERNALS
+ CABLE_LIBRARY_PATH
+ CABLE_EXECUTABLE_PATH)
+
+ if(CABLE_LIBRARY_PATH)
+ find_library(CABLE_TCL_LIBRARY NAMES CableTclFacility PATHS
+ ${CABLE_LIBRARY_PATH}
+ ${CABLE_LIBRARY_PATH}/*)
+ else()
+ find_library(CABLE_TCL_LIBRARY NAMES CableTclFacility PATHS
+ ${CABLE_BINARY_DIR}/CableTclFacility
+ ${CABLE_BINARY_DIR}/CableTclFacility/*)
+ endif()
+
+ if(CABLE_EXECUTABLE_PATH)
+ find_program(CABLE NAMES cable PATHS
+ ${CABLE_EXECUTABLE_PATH}
+ ${CABLE_EXECUTABLE_PATH}/*)
+ else()
+ find_program(CABLE NAMES cable PATHS
+ ${CABLE_BINARY_DIR}/Executables
+ ${CABLE_BINARY_DIR}/Executables/*)
+ endif()
+
+ find_path(CABLE_INCLUDE_DIR CableTclFacility/ctCalls.h
+ ${CABLE_SOURCE_DIR})
+else()
+ # Find the cable executable in the path.
+ find_program(CABLE NAMES cable)
+
+ # Get the path where the executable sits, but without the executable
+ # name on it.
+ get_filename_component(CABLE_ROOT_BIN ${CABLE} PATH)
+
+ # Find the cable include directory in a path relative to the cable
+ # executable.
+ find_path(CABLE_INCLUDE_DIR CableTclFacility/ctCalls.h
+ ${CABLE_ROOT_BIN}/../include/Cable)
+
+ # Find the WrapTclFacility library in a path relative to the cable
+ # executable.
+ find_library(CABLE_TCL_LIBRARY NAMES CableTclFacility PATHS
+ ${CABLE_ROOT_BIN}/../lib/Cable)
+endif()
diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake
new file mode 100644
index 0000000000..2e2b21c926
--- /dev/null
+++ b/Modules/FindCUDA.cmake
@@ -0,0 +1,1680 @@
+#.rst:
+# FindCUDA
+# --------
+#
+# Tools for building CUDA C files: libraries and build dependencies.
+#
+# This script locates the NVIDIA CUDA C tools. It should work on linux,
+# windows, and mac and should be reasonably up to date with CUDA C
+# releases.
+#
+# This script makes use of the standard find_package arguments of
+# <VERSION>, REQUIRED and QUIET. CUDA_FOUND will report if an
+# acceptable version of CUDA was found.
+#
+# The script will prompt the user to specify CUDA_TOOLKIT_ROOT_DIR if
+# the prefix cannot be determined by the location of nvcc in the system
+# path and REQUIRED is specified to find_package(). To use a different
+# installed version of the toolkit set the environment variable
+# CUDA_BIN_PATH before running cmake (e.g.
+# CUDA_BIN_PATH=/usr/local/cuda1.0 instead of the default
+# /usr/local/cuda) or set CUDA_TOOLKIT_ROOT_DIR after configuring. If
+# you change the value of CUDA_TOOLKIT_ROOT_DIR, various components that
+# depend on the path will be relocated.
+#
+# It might be necessary to set CUDA_TOOLKIT_ROOT_DIR manually on certain
+# platforms, or to use a cuda runtime not installed in the default
+# location. In newer versions of the toolkit the cuda library is
+# included with the graphics driver- be sure that the driver version
+# matches what is needed by the cuda runtime version.
+#
+# The following variables affect the behavior of the macros in the
+# script (in alphebetical order). Note that any of these flags can be
+# changed multiple times in the same directory before calling
+# CUDA_ADD_EXECUTABLE, CUDA_ADD_LIBRARY, CUDA_COMPILE, CUDA_COMPILE_PTX,
+# CUDA_COMPILE_FATBIN, CUDA_COMPILE_CUBIN or CUDA_WRAP_SRCS::
+#
+# CUDA_64_BIT_DEVICE_CODE (Default matches host bit size)
+# -- Set to ON to compile for 64 bit device code, OFF for 32 bit device code.
+# Note that making this different from the host code when generating object
+# or C files from CUDA code just won't work, because size_t gets defined by
+# nvcc in the generated source. If you compile to PTX and then load the
+# file yourself, you can mix bit sizes between device and host.
+#
+# CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE (Default ON)
+# -- Set to ON if you want the custom build rule to be attached to the source
+# file in Visual Studio. Turn OFF if you add the same cuda file to multiple
+# targets.
+#
+# This allows the user to build the target from the CUDA file; however, bad
+# things can happen if the CUDA source file is added to multiple targets.
+# When performing parallel builds it is possible for the custom build
+# command to be run more than once and in parallel causing cryptic build
+# errors. VS runs the rules for every source file in the target, and a
+# source can have only one rule no matter how many projects it is added to.
+# When the rule is run from multiple targets race conditions can occur on
+# the generated file. Eventually everything will get built, but if the user
+# is unaware of this behavior, there may be confusion. It would be nice if
+# this script could detect the reuse of source files across multiple targets
+# and turn the option off for the user, but no good solution could be found.
+#
+# CUDA_BUILD_CUBIN (Default OFF)
+# -- Set to ON to enable and extra compilation pass with the -cubin option in
+# Device mode. The output is parsed and register, shared memory usage is
+# printed during build.
+#
+# CUDA_BUILD_EMULATION (Default OFF for device mode)
+# -- Set to ON for Emulation mode. -D_DEVICEEMU is defined for CUDA C files
+# when CUDA_BUILD_EMULATION is TRUE.
+#
+# CUDA_GENERATED_OUTPUT_DIR (Default CMAKE_CURRENT_BINARY_DIR)
+# -- Set to the path you wish to have the generated files placed. If it is
+# blank output files will be placed in CMAKE_CURRENT_BINARY_DIR.
+# Intermediate files will always be placed in
+# CMAKE_CURRENT_BINARY_DIR/CMakeFiles.
+#
+# CUDA_HOST_COMPILATION_CPP (Default ON)
+# -- Set to OFF for C compilation of host code.
+#
+# CUDA_HOST_COMPILER (Default CMAKE_C_COMPILER, $(VCInstallDir)/bin for VS)
+# -- Set the host compiler to be used by nvcc. Ignored if -ccbin or
+# --compiler-bindir is already present in the CUDA_NVCC_FLAGS or
+# CUDA_NVCC_FLAGS_<CONFIG> variables. For Visual Studio targets
+# $(VCInstallDir)/bin is a special value that expands out to the path when
+# the command is run from withing VS.
+#
+# CUDA_NVCC_FLAGS
+# CUDA_NVCC_FLAGS_<CONFIG>
+# -- Additional NVCC command line arguments. NOTE: multiple arguments must be
+# semi-colon delimited (e.g. --compiler-options;-Wall)
+#
+# CUDA_PROPAGATE_HOST_FLAGS (Default ON)
+# -- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration
+# dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the
+# host compiler through nvcc's -Xcompiler flag. This helps make the
+# generated host code match the rest of the system better. Sometimes
+# certain flags give nvcc problems, and this will help you turn the flag
+# propagation off. This does not affect the flags supplied directly to nvcc
+# via CUDA_NVCC_FLAGS or through the OPTION flags specified through
+# CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS. Flags used for
+# shared library compilation are not affected by this flag.
+#
+# CUDA_SEPARABLE_COMPILATION (Default OFF)
+# -- If set this will enable separable compilation for all CUDA runtime object
+# files. If used outside of CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY
+# (e.g. calling CUDA_WRAP_SRCS directly),
+# CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME and
+# CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS should be called.
+#
+# CUDA_VERBOSE_BUILD (Default OFF)
+# -- Set to ON to see all the commands used when building the CUDA file. When
+# using a Makefile generator the value defaults to VERBOSE (run make
+# VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will
+# always print the output.
+#
+# The script creates the following macros (in alphebetical order)::
+#
+# CUDA_ADD_CUFFT_TO_TARGET( cuda_target )
+# -- Adds the cufft library to the target (can be any target). Handles whether
+# you are in emulation mode or not.
+#
+# CUDA_ADD_CUBLAS_TO_TARGET( cuda_target )
+# -- Adds the cublas library to the target (can be any target). Handles
+# whether you are in emulation mode or not.
+#
+# CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ...
+# [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [OPTIONS ...] )
+# -- Creates an executable "cuda_target" which is made up of the files
+# specified. All of the non CUDA C files are compiled using the standard
+# build rules specified by CMAKE and the cuda files are compiled to object
+# files using nvcc and the host compiler. In addition CUDA_INCLUDE_DIRS is
+# added automatically to include_directories(). Some standard CMake target
+# calls can be used on the target after calling this macro
+# (e.g. set_target_properties and target_link_libraries), but setting
+# properties that adjust compilation flags will not affect code compiled by
+# nvcc. Such flags should be modified before calling CUDA_ADD_EXECUTABLE,
+# CUDA_ADD_LIBRARY or CUDA_WRAP_SRCS.
+#
+# CUDA_ADD_LIBRARY( cuda_target file0 file1 ...
+# [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] [OPTIONS ...] )
+# -- Same as CUDA_ADD_EXECUTABLE except that a library is created.
+#
+# CUDA_BUILD_CLEAN_TARGET()
+# -- Creates a convience target that deletes all the dependency files
+# generated. You should make clean after running this target to ensure the
+# dependency files get regenerated.
+#
+# CUDA_COMPILE( generated_files file0 file1 ... [STATIC | SHARED | MODULE]
+# [OPTIONS ...] )
+# -- Returns a list of generated files from the input source files to be used
+# with ADD_LIBRARY or ADD_EXECUTABLE.
+#
+# CUDA_COMPILE_PTX( generated_files file0 file1 ... [OPTIONS ...] )
+# -- Returns a list of PTX files generated from the input source files.
+#
+# CUDA_COMPILE_FATBIN( generated_files file0 file1 ... [OPTIONS ...] )
+# -- Returns a list of FATBIN files generated from the input source files.
+#
+# CUDA_COMPILE_CUBIN( generated_files file0 file1 ... [OPTIONS ...] )
+# -- Returns a list of CUBIN files generated from the input source files.
+#
+# CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME( output_file_var
+# cuda_target
+# object_files )
+# -- Compute the name of the intermediate link file used for separable
+# compilation. This file name is typically passed into
+# CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS. output_file_var is produced
+# based on cuda_target the list of objects files that need separable
+# compilation as specified by object_files. If the object_files list is
+# empty, then output_file_var will be empty. This function is called
+# automatically for CUDA_ADD_LIBRARY and CUDA_ADD_EXECUTABLE. Note that
+# this is a function and not a macro.
+#
+# CUDA_INCLUDE_DIRECTORIES( path0 path1 ... )
+# -- Sets the directories that should be passed to nvcc
+# (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu
+# files.
+#
+#
+#
+# CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS( output_file_var cuda_target
+# nvcc_flags object_files)
+#
+# -- Generates the link object required by separable compilation from the given
+# object files. This is called automatically for CUDA_ADD_EXECUTABLE and
+# CUDA_ADD_LIBRARY, but can be called manually when using CUDA_WRAP_SRCS
+# directly. When called from CUDA_ADD_LIBRARY or CUDA_ADD_EXECUTABLE the
+# nvcc_flags passed in are the same as the flags passed in via the OPTIONS
+# argument. The only nvcc flag added automatically is the bitness flag as
+# specified by CUDA_64_BIT_DEVICE_CODE. Note that this is a function
+# instead of a macro.
+#
+# CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ...
+# [STATIC | SHARED | MODULE] [OPTIONS ...] )
+# -- This is where all the magic happens. CUDA_ADD_EXECUTABLE,
+# CUDA_ADD_LIBRARY, CUDA_COMPILE, and CUDA_COMPILE_PTX all call this
+# function under the hood.
+#
+# Given the list of files (file0 file1 ... fileN) this macro generates
+# custom commands that generate either PTX or linkable objects (use "PTX" or
+# "OBJ" for the format argument to switch). Files that don't end with .cu
+# or have the HEADER_FILE_ONLY property are ignored.
+#
+# The arguments passed in after OPTIONS are extra command line options to
+# give to nvcc. You can also specify per configuration options by
+# specifying the name of the configuration followed by the options. General
+# options must preceed configuration specific options. Not all
+# configurations need to be specified, only the ones provided will be used.
+#
+# OPTIONS -DFLAG=2 "-DFLAG_OTHER=space in flag"
+# DEBUG -g
+# RELEASE --use_fast_math
+# RELWITHDEBINFO --use_fast_math;-g
+# MINSIZEREL --use_fast_math
+#
+# For certain configurations (namely VS generating object files with
+# CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON), no generated file will
+# be produced for the given cuda file. This is because when you add the
+# cuda file to Visual Studio it knows that this file produces an object file
+# and will link in the resulting object file automatically.
+#
+# This script will also generate a separate cmake script that is used at
+# build time to invoke nvcc. This is for several reasons.
+#
+# 1. nvcc can return negative numbers as return values which confuses
+# Visual Studio into thinking that the command succeeded. The script now
+# checks the error codes and produces errors when there was a problem.
+#
+# 2. nvcc has been known to not delete incomplete results when it
+# encounters problems. This confuses build systems into thinking the
+# target was generated when in fact an unusable file exists. The script
+# now deletes the output files if there was an error.
+#
+# 3. By putting all the options that affect the build into a file and then
+# make the build rule dependent on the file, the output files will be
+# regenerated when the options change.
+#
+# This script also looks at optional arguments STATIC, SHARED, or MODULE to
+# determine when to target the object compilation for a shared library.
+# BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS, but it is respected in
+# CUDA_ADD_LIBRARY. On some systems special flags are added for building
+# objects intended for shared libraries. A preprocessor macro,
+# <target_name>_EXPORTS is defined when a shared library compilation is
+# detected.
+#
+# Flags passed into add_definitions with -D or /D are passed along to nvcc.
+#
+#
+#
+# The script defines the following variables::
+#
+# CUDA_VERSION_MAJOR -- The major version of cuda as reported by nvcc.
+# CUDA_VERSION_MINOR -- The minor version.
+# CUDA_VERSION
+# CUDA_VERSION_STRING -- CUDA_VERSION_MAJOR.CUDA_VERSION_MINOR
+#
+# CUDA_TOOLKIT_ROOT_DIR -- Path to the CUDA Toolkit (defined if not set).
+# CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the
+# SDK. This script will not directly support finding
+# specific libraries or headers, as that isn't
+# supported by NVIDIA. If you want to change
+# libraries when the path changes see the
+# FindCUDA.cmake script for an example of how to clear
+# these variables. There are also examples of how to
+# use the CUDA_SDK_ROOT_DIR to locate headers or
+# libraries, if you so choose (at your own risk).
+# CUDA_INCLUDE_DIRS -- Include directory for cuda headers. Added automatically
+# for CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY.
+# CUDA_LIBRARIES -- Cuda RT library.
+# CUDA_CUFFT_LIBRARIES -- Device or emulation library for the Cuda FFT
+# implementation (alternative to:
+# CUDA_ADD_CUFFT_TO_TARGET macro)
+# CUDA_CUBLAS_LIBRARIES -- Device or emulation library for the Cuda BLAS
+# implementation (alterative to:
+# CUDA_ADD_CUBLAS_TO_TARGET macro).
+# CUDA_cupti_LIBRARY -- CUDA Profiling Tools Interface library.
+# Only available for CUDA version 4.0+.
+# CUDA_curand_LIBRARY -- CUDA Random Number Generation library.
+# Only available for CUDA version 3.2+.
+# CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library.
+# Only available for CUDA version 3.2+.
+# CUDA_npp_LIBRARY -- NVIDIA Performance Primitives library.
+# Only available for CUDA version 4.0+.
+# CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives library (core).
+# Only available for CUDA version 5.5+.
+# CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives library (image processing).
+# Only available for CUDA version 5.5+.
+# CUDA_npps_LIBRARY -- NVIDIA Performance Primitives library (signal processing).
+# Only available for CUDA version 5.5+.
+# CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library.
+# Only available for CUDA version 3.2+.
+# Windows only.
+# CUDA_nvcuvid_LIBRARY -- CUDA Video Decoder library.
+# Only available for CUDA version 3.2+.
+# Windows only.
+#
+
+# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
+# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
+#
+# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
+#
+# Copyright (c) 2007-2009
+# Scientific Computing and Imaging Institute, University of Utah
+#
+# This code is licensed under the MIT License. See the FindCUDA.cmake script
+# for the text of the license.
+
+# The MIT License
+#
+# License for the specific language governing rights and limitations under
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+#
+###############################################################################
+
+# FindCUDA.cmake
+
+# This macro helps us find the location of helper files we will need the full path to
+macro(CUDA_FIND_HELPER_FILE _name _extension)
+ set(_full_name "${_name}.${_extension}")
+ # CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being
+ # processed. Using this variable, we can pull out the current path, and
+ # provide a way to get access to the other files we need local to here.
+ get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+ set(CUDA_${_name} "${CMAKE_CURRENT_LIST_DIR}/FindCUDA/${_full_name}")
+ if(NOT EXISTS "${CUDA_${_name}}")
+ set(error_message "${_full_name} not found in ${CMAKE_CURRENT_LIST_DIR}/FindCUDA")
+ if(CUDA_FIND_REQUIRED)
+ message(FATAL_ERROR "${error_message}")
+ else()
+ if(NOT CUDA_FIND_QUIETLY)
+ message(STATUS "${error_message}")
+ endif()
+ endif()
+ endif()
+ # Set this variable as internal, so the user isn't bugged with it.
+ set(CUDA_${_name} ${CUDA_${_name}} CACHE INTERNAL "Location of ${_full_name}" FORCE)
+endmacro()
+
+#####################################################################
+## CUDA_INCLUDE_NVCC_DEPENDENCIES
+##
+
+# So we want to try and include the dependency file if it exists. If
+# it doesn't exist then we need to create an empty one, so we can
+# include it.
+
+# If it does exist, then we need to check to see if all the files it
+# depends on exist. If they don't then we should clear the dependency
+# file and regenerate it later. This covers the case where a header
+# file has disappeared or moved.
+
+macro(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file)
+ set(CUDA_NVCC_DEPEND)
+ set(CUDA_NVCC_DEPEND_REGENERATE FALSE)
+
+
+ # Include the dependency file. Create it first if it doesn't exist . The
+ # INCLUDE puts a dependency that will force CMake to rerun and bring in the
+ # new info when it changes. DO NOT REMOVE THIS (as I did and spent a few
+ # hours figuring out why it didn't work.
+ if(NOT EXISTS ${dependency_file})
+ file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n")
+ endif()
+ # Always include this file to force CMake to run again next
+ # invocation and rebuild the dependencies.
+ #message("including dependency_file = ${dependency_file}")
+ include(${dependency_file})
+
+ # Now we need to verify the existence of all the included files
+ # here. If they aren't there we need to just blank this variable and
+ # make the file regenerate again.
+# if(DEFINED CUDA_NVCC_DEPEND)
+# message("CUDA_NVCC_DEPEND set")
+# else()
+# message("CUDA_NVCC_DEPEND NOT set")
+# endif()
+ if(CUDA_NVCC_DEPEND)
+ #message("CUDA_NVCC_DEPEND found")
+ foreach(f ${CUDA_NVCC_DEPEND})
+ # message("searching for ${f}")
+ if(NOT EXISTS ${f})
+ #message("file ${f} not found")
+ set(CUDA_NVCC_DEPEND_REGENERATE TRUE)
+ endif()
+ endforeach()
+ else()
+ #message("CUDA_NVCC_DEPEND false")
+ # No dependencies, so regenerate the file.
+ set(CUDA_NVCC_DEPEND_REGENERATE TRUE)
+ endif()
+
+ #message("CUDA_NVCC_DEPEND_REGENERATE = ${CUDA_NVCC_DEPEND_REGENERATE}")
+ # No incoming dependencies, so we need to generate them. Make the
+ # output depend on the dependency file itself, which should cause the
+ # rule to re-run.
+ if(CUDA_NVCC_DEPEND_REGENERATE)
+ set(CUDA_NVCC_DEPEND ${dependency_file})
+ #message("Generating an empty dependency_file: ${dependency_file}")
+ file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n")
+ endif()
+
+endmacro()
+
+###############################################################################
+###############################################################################
+# Setup variables' defaults
+###############################################################################
+###############################################################################
+
+# Allow the user to specify if the device code is supposed to be 32 or 64 bit.
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(CUDA_64_BIT_DEVICE_CODE_DEFAULT ON)
+else()
+ set(CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF)
+endif()
+option(CUDA_64_BIT_DEVICE_CODE "Compile device code in 64 bit mode" ${CUDA_64_BIT_DEVICE_CODE_DEFAULT})
+
+# Attach the build rule to the source file in VS. This option
+option(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE "Attach the build rule to the CUDA source file. Enable only when the CUDA source file is added to at most one target." ON)
+
+# Prints out extra information about the cuda file during compilation
+option(CUDA_BUILD_CUBIN "Generate and parse .cubin files in Device mode." OFF)
+
+# Set whether we are using emulation or device mode.
+option(CUDA_BUILD_EMULATION "Build in Emulation mode" OFF)
+
+# Where to put the generated output.
+set(CUDA_GENERATED_OUTPUT_DIR "" CACHE PATH "Directory to put all the output files. If blank it will default to the CMAKE_CURRENT_BINARY_DIR")
+
+# Parse HOST_COMPILATION mode.
+option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON)
+
+# Extra user settable flags
+set(CUDA_NVCC_FLAGS "" CACHE STRING "Semi-colon delimit multiple arguments.")
+
+if(CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(CUDA_HOST_COMPILER "$(VCInstallDir)bin" CACHE FILEPATH "Host side compiler used by NVCC")
+else()
+ # Using cc which is symlink to clang may let NVCC think it is GCC and issue
+ # unhandled -dumpspecs option to clang. Also in case neither
+ # CMAKE_C_COMPILER is defined (project does not use C language) nor
+ # CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let
+ # nvcc use its own default C compiler.
+ if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER)
+ get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
+ else()
+ set(c_compiler_realpath "")
+ endif()
+ set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC")
+endif()
+
+# Propagate the host flags to the host compiler via -Xcompiler
+option(CUDA_PROPAGATE_HOST_FLAGS "Propage C/CXX_FLAGS and friends to the host compiler via -Xcompile" ON)
+
+# Enable CUDA_SEPARABLE_COMPILATION
+option(CUDA_SEPARABLE_COMPILATION "Compile CUDA objects with separable compilation enabled. Requires CUDA 5.0+" OFF)
+
+# Specifies whether the commands used when compiling the .cu file will be printed out.
+option(CUDA_VERBOSE_BUILD "Print out the commands run while compiling the CUDA source file. With the Makefile generator this defaults to VERBOSE variable specified on the command line, but can be forced on with this option." OFF)
+
+mark_as_advanced(
+ CUDA_64_BIT_DEVICE_CODE
+ CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE
+ CUDA_GENERATED_OUTPUT_DIR
+ CUDA_HOST_COMPILATION_CPP
+ CUDA_NVCC_FLAGS
+ CUDA_PROPAGATE_HOST_FLAGS
+ )
+
+# Makefile and similar generators don't define CMAKE_CONFIGURATION_TYPES, so we
+# need to add another entry for the CMAKE_BUILD_TYPE. We also need to add the
+# standerd set of 4 build types (Debug, MinSizeRel, Release, and RelWithDebInfo)
+# for completeness. We need run this loop in order to accomodate the addition
+# of extra configuration types. Duplicate entries will be removed by
+# REMOVE_DUPLICATES.
+set(CUDA_configuration_types ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug MinSizeRel Release RelWithDebInfo)
+list(REMOVE_DUPLICATES CUDA_configuration_types)
+foreach(config ${CUDA_configuration_types})
+ string(TOUPPER ${config} config_upper)
+ set(CUDA_NVCC_FLAGS_${config_upper} "" CACHE STRING "Semi-colon delimit multiple arguments.")
+ mark_as_advanced(CUDA_NVCC_FLAGS_${config_upper})
+endforeach()
+
+###############################################################################
+###############################################################################
+# Locate CUDA, Set Build Type, etc.
+###############################################################################
+###############################################################################
+
+macro(cuda_unset_include_and_libraries)
+ unset(CUDA_TOOLKIT_INCLUDE CACHE)
+ unset(CUDA_CUDART_LIBRARY CACHE)
+ unset(CUDA_CUDA_LIBRARY CACHE)
+ # Make sure you run this before you unset CUDA_VERSION.
+ if(CUDA_VERSION VERSION_EQUAL "3.0")
+ # This only existed in the 3.0 version of the CUDA toolkit
+ unset(CUDA_CUDARTEMU_LIBRARY CACHE)
+ endif()
+ unset(CUDA_cupti_LIBRARY CACHE)
+ unset(CUDA_cublas_LIBRARY CACHE)
+ unset(CUDA_cublasemu_LIBRARY CACHE)
+ unset(CUDA_cufft_LIBRARY CACHE)
+ unset(CUDA_cufftemu_LIBRARY CACHE)
+ unset(CUDA_curand_LIBRARY CACHE)
+ unset(CUDA_cusparse_LIBRARY CACHE)
+ unset(CUDA_npp_LIBRARY CACHE)
+ unset(CUDA_nppc_LIBRARY CACHE)
+ unset(CUDA_nppi_LIBRARY CACHE)
+ unset(CUDA_npps_LIBRARY CACHE)
+ unset(CUDA_nvcuvenc_LIBRARY CACHE)
+ unset(CUDA_nvcuvid_LIBRARY CACHE)
+endmacro()
+
+# Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed,
+# if they have then clear the cache variables, so that will be detected again.
+if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}")
+ unset(CUDA_TOOLKIT_TARGET_DIR CACHE)
+ unset(CUDA_NVCC_EXECUTABLE CACHE)
+ unset(CUDA_VERSION CACHE)
+ cuda_unset_include_and_libraries()
+endif()
+
+if(NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}")
+ cuda_unset_include_and_libraries()
+endif()
+
+if(NOT "${CUDA_SDK_ROOT_DIR}" STREQUAL "${CUDA_SDK_ROOT_DIR_INTERNAL}")
+ # No specific variables to catch. Use this kind of code before calling
+ # find_package(CUDA) to clean up any variables that may depend on this path.
+
+ # unset(MY_SPECIAL_CUDA_SDK_INCLUDE_DIR CACHE)
+ # unset(MY_SPECIAL_CUDA_SDK_LIBRARY CACHE)
+endif()
+
+# Search for the cuda distribution.
+if(NOT CUDA_TOOLKIT_ROOT_DIR)
+
+ # Search in the CUDA_BIN_PATH first.
+ find_path(CUDA_TOOLKIT_ROOT_DIR
+ NAMES nvcc nvcc.exe
+ PATHS
+ ENV CUDA_PATH
+ ENV CUDA_BIN_PATH
+ PATH_SUFFIXES bin bin64
+ DOC "Toolkit location."
+ NO_DEFAULT_PATH
+ )
+ # Now search default paths
+ find_path(CUDA_TOOLKIT_ROOT_DIR
+ NAMES nvcc nvcc.exe
+ PATHS /usr/local/bin
+ /usr/local/cuda/bin
+ DOC "Toolkit location."
+ )
+
+ if (CUDA_TOOLKIT_ROOT_DIR)
+ string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR})
+ # We need to force this back into the cache.
+ set(CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR} CACHE PATH "Toolkit location." FORCE)
+ endif()
+ if (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR})
+ if(CUDA_FIND_REQUIRED)
+ message(FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR")
+ elseif(NOT CUDA_FIND_QUIETLY)
+ message("CUDA_TOOLKIT_ROOT_DIR not found or specified")
+ endif()
+ endif ()
+endif ()
+
+# CUDA_NVCC_EXECUTABLE
+find_program(CUDA_NVCC_EXECUTABLE
+ NAMES nvcc
+ PATHS "${CUDA_TOOLKIT_ROOT_DIR}"
+ ENV CUDA_PATH
+ ENV CUDA_BIN_PATH
+ PATH_SUFFIXES bin bin64
+ NO_DEFAULT_PATH
+ )
+# Search default search paths, after we search our own set of paths.
+find_program(CUDA_NVCC_EXECUTABLE nvcc)
+mark_as_advanced(CUDA_NVCC_EXECUTABLE)
+
+if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION)
+ # Compute the version.
+ execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
+ string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT})
+ string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT})
+ set(CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc.")
+ mark_as_advanced(CUDA_VERSION)
+else()
+ # Need to set these based off of the cached value
+ string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${CUDA_VERSION}")
+ string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${CUDA_VERSION}")
+endif()
+
+# Always set this convenience variable
+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.")
+else()
+ set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}" CACHE PATH "Toolkit target location.")
+endif()
+mark_as_advanced(CUDA_TOOLKIT_TARGET_DIR)
+
+# Target CPU architecture
+if(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
+ set(_cuda_target_cpu_arch_initial "ARM")
+else()
+ set(_cuda_target_cpu_arch_initial "")
+endif()
+set(CUDA_TARGET_CPU_ARCH ${_cuda_target_cpu_arch_initial} CACHE STRING "Specify the name of the class of CPU architecture for which the input files must be compiled.")
+mark_as_advanced(CUDA_TARGET_CPU_ARCH)
+
+# CUDA_TOOLKIT_INCLUDE
+find_path(CUDA_TOOLKIT_INCLUDE
+ device_functions.h # Header included in toolkit
+ PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}"
+ ENV CUDA_PATH
+ ENV CUDA_INC_PATH
+ PATH_SUFFIXES include
+ NO_DEFAULT_PATH
+ )
+# Search default search paths, after we search our own set of paths.
+find_path(CUDA_TOOLKIT_INCLUDE device_functions.h)
+mark_as_advanced(CUDA_TOOLKIT_INCLUDE)
+
+# Set the user list of include dir to nothing to initialize it.
+set (CUDA_NVCC_INCLUDE_ARGS_USER "")
+set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE})
+
+macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext )
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ # CUDA 3.2+ on Windows moved the library directories, so we need the new
+ # and old paths.
+ set(_cuda_64bit_lib_dir "${_path_ext}lib/x64" "${_path_ext}lib64" "${_path_ext}libx64" )
+ endif()
+ # CUDA 3.2+ on Windows moved the library directories, so we need to new
+ # (lib/Win32) and the old path (lib).
+ find_library(${_var}
+ NAMES ${_names}
+ PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}"
+ ENV CUDA_PATH
+ ENV CUDA_LIB_PATH
+ PATH_SUFFIXES ${_cuda_64bit_lib_dir} "${_path_ext}lib/Win32" "${_path_ext}lib" "${_path_ext}libWin32"
+ DOC ${_doc}
+ NO_DEFAULT_PATH
+ )
+ # Search default search paths, after we search our own set of paths.
+ find_library(${_var}
+ NAMES ${_names}
+ PATHS "/usr/lib/nvidia-current"
+ DOC ${_doc}
+ )
+endmacro()
+
+macro(cuda_find_library_local_first _var _names _doc)
+ cuda_find_library_local_first_with_path_ext( "${_var}" "${_names}" "${_doc}" "" )
+endmacro()
+
+macro(find_library_local_first _var _names _doc )
+ cuda_find_library_local_first( "${_var}" "${_names}" "${_doc}" "" )
+endmacro()
+
+
+# CUDA_LIBRARIES
+cuda_find_library_local_first(CUDA_CUDART_LIBRARY cudart "\"cudart\" library")
+if(CUDA_VERSION VERSION_EQUAL "3.0")
+ # The cudartemu library only existed for the 3.0 version of CUDA.
+ cuda_find_library_local_first(CUDA_CUDARTEMU_LIBRARY cudartemu "\"cudartemu\" library")
+ mark_as_advanced(
+ CUDA_CUDARTEMU_LIBRARY
+ )
+endif()
+
+# CUPTI library showed up in cuda toolkit 4.0
+if(NOT CUDA_VERSION VERSION_LESS "4.0")
+ cuda_find_library_local_first_with_path_ext(CUDA_cupti_LIBRARY cupti "\"cupti\" library" "extras/CUPTI/")
+ mark_as_advanced(CUDA_cupti_LIBRARY)
+endif()
+
+# If we are using emulation mode and we found the cudartemu library then use
+# that one instead of cudart.
+if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY)
+ set(CUDA_LIBRARIES ${CUDA_CUDARTEMU_LIBRARY})
+else()
+ set(CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY})
+endif()
+if(APPLE)
+ # We need to add the path to cudart to the linker using rpath, since the
+ # library name for the cuda libraries is prepended with @rpath.
+ if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY)
+ get_filename_component(_cuda_path_to_cudart "${CUDA_CUDARTEMU_LIBRARY}" PATH)
+ else()
+ get_filename_component(_cuda_path_to_cudart "${CUDA_CUDART_LIBRARY}" PATH)
+ endif()
+ if(_cuda_path_to_cudart)
+ list(APPEND CUDA_LIBRARIES -Wl,-rpath "-Wl,${_cuda_path_to_cudart}")
+ endif()
+endif()
+
+# 1.1 toolkit on linux doesn't appear to have a separate library on
+# some platforms.
+cuda_find_library_local_first(CUDA_CUDA_LIBRARY cuda "\"cuda\" library (older versions only).")
+
+mark_as_advanced(
+ CUDA_CUDA_LIBRARY
+ CUDA_CUDART_LIBRARY
+ )
+
+#######################
+# Look for some of the toolkit helper libraries
+macro(FIND_CUDA_HELPER_LIBS _name)
+ cuda_find_library_local_first(CUDA_${_name}_LIBRARY ${_name} "\"${_name}\" library")
+ mark_as_advanced(CUDA_${_name}_LIBRARY)
+endmacro()
+
+#######################
+# Disable emulation for v3.1 onward
+if(CUDA_VERSION VERSION_GREATER "3.0")
+ if(CUDA_BUILD_EMULATION)
+ message(FATAL_ERROR "CUDA_BUILD_EMULATION is not supported in version 3.1 and onwards. You must disable it to proceed. You have version ${CUDA_VERSION}.")
+ endif()
+endif()
+
+# Search for additional CUDA toolkit libraries.
+if(CUDA_VERSION VERSION_LESS "3.1")
+ # Emulation libraries aren't available in version 3.1 onward.
+ find_cuda_helper_libs(cufftemu)
+ find_cuda_helper_libs(cublasemu)
+endif()
+find_cuda_helper_libs(cufft)
+find_cuda_helper_libs(cublas)
+if(NOT CUDA_VERSION VERSION_LESS "3.2")
+ # cusparse showed up in version 3.2
+ find_cuda_helper_libs(cusparse)
+ find_cuda_helper_libs(curand)
+ if (WIN32)
+ find_cuda_helper_libs(nvcuvenc)
+ find_cuda_helper_libs(nvcuvid)
+ endif()
+endif()
+if(CUDA_VERSION VERSION_GREATER "5.0")
+ # In CUDA 5.5 NPP was splitted onto 3 separate libraries.
+ find_cuda_helper_libs(nppc)
+ find_cuda_helper_libs(nppi)
+ find_cuda_helper_libs(npps)
+ set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")
+elseif(NOT CUDA_VERSION VERSION_LESS "4.0")
+ find_cuda_helper_libs(npp)
+endif()
+
+if (CUDA_BUILD_EMULATION)
+ set(CUDA_CUFFT_LIBRARIES ${CUDA_cufftemu_LIBRARY})
+ set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublasemu_LIBRARY})
+else()
+ set(CUDA_CUFFT_LIBRARIES ${CUDA_cufft_LIBRARY})
+ set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublas_LIBRARY})
+endif()
+
+########################
+# Look for the SDK stuff. As of CUDA 3.0 NVSDKCUDA_ROOT has been replaced with
+# NVSDKCOMPUTE_ROOT with the old CUDA C contents moved into the C subdirectory
+find_path(CUDA_SDK_ROOT_DIR common/inc/cutil.h
+ HINTS
+ "$ENV{NVSDKCOMPUTE_ROOT}/C"
+ ENV NVSDKCUDA_ROOT
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]"
+ PATHS
+ "/Developer/GPU\ Computing/C"
+ )
+
+# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the
+# environment variables.
+set(CUDA_SDK_SEARCH_PATH
+ "${CUDA_SDK_ROOT_DIR}"
+ "${CUDA_TOOLKIT_ROOT_DIR}/local/NVSDK0.2"
+ "${CUDA_TOOLKIT_ROOT_DIR}/NVSDK0.2"
+ "${CUDA_TOOLKIT_ROOT_DIR}/NV_CUDA_SDK"
+ "$ENV{HOME}/NVIDIA_CUDA_SDK"
+ "$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX"
+ "/Developer/CUDA"
+ )
+
+# Example of how to find an include file from the CUDA_SDK_ROOT_DIR
+
+# find_path(CUDA_CUT_INCLUDE_DIR
+# cutil.h
+# PATHS ${CUDA_SDK_SEARCH_PATH}
+# PATH_SUFFIXES "common/inc"
+# DOC "Location of cutil.h"
+# NO_DEFAULT_PATH
+# )
+# # Now search system paths
+# find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h")
+
+# mark_as_advanced(CUDA_CUT_INCLUDE_DIR)
+
+
+# Example of how to find a library in the CUDA_SDK_ROOT_DIR
+
+# # cutil library is called cutil64 for 64 bit builds on windows. We don't want
+# # to get these confused, so we are setting the name based on the word size of
+# # the build.
+
+# if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+# set(cuda_cutil_name cutil64)
+# else()
+# set(cuda_cutil_name cutil32)
+# endif()
+
+# find_library(CUDA_CUT_LIBRARY
+# NAMES cutil ${cuda_cutil_name}
+# PATHS ${CUDA_SDK_SEARCH_PATH}
+# # The new version of the sdk shows up in common/lib, but the old one is in lib
+# PATH_SUFFIXES "common/lib" "lib"
+# DOC "Location of cutil library"
+# NO_DEFAULT_PATH
+# )
+# # Now search system paths
+# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library")
+# mark_as_advanced(CUDA_CUT_LIBRARY)
+# set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY})
+
+
+
+#############################
+# Check for required components
+set(CUDA_FOUND TRUE)
+
+set(CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL
+ "This is the value of the last time CUDA_TOOLKIT_ROOT_DIR was set successfully." FORCE)
+set(CUDA_TOOLKIT_TARGET_DIR_INTERNAL "${CUDA_TOOLKIT_TARGET_DIR}" CACHE INTERNAL
+ "This is the value of the last time CUDA_TOOLKIT_TARGET_DIR was set successfully." FORCE)
+set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL
+ "This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(CUDA
+ REQUIRED_VARS
+ CUDA_TOOLKIT_ROOT_DIR
+ CUDA_NVCC_EXECUTABLE
+ CUDA_INCLUDE_DIRS
+ CUDA_CUDART_LIBRARY
+ VERSION_VAR
+ CUDA_VERSION
+ )
+
+
+
+###############################################################################
+###############################################################################
+# Macros
+###############################################################################
+###############################################################################
+
+###############################################################################
+# Add include directories to pass to the nvcc command.
+macro(CUDA_INCLUDE_DIRECTORIES)
+ foreach(dir ${ARGN})
+ list(APPEND CUDA_NVCC_INCLUDE_ARGS_USER -I${dir})
+ endforeach()
+endmacro()
+
+
+##############################################################################
+cuda_find_helper_file(parse_cubin cmake)
+cuda_find_helper_file(make2cmake cmake)
+cuda_find_helper_file(run_nvcc cmake)
+
+##############################################################################
+# Separate the OPTIONS out from the sources
+#
+macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options)
+ set( ${_sources} )
+ set( ${_cmake_options} )
+ set( ${_options} )
+ set( _found_options FALSE )
+ foreach(arg ${ARGN})
+ if("x${arg}" STREQUAL "xOPTIONS")
+ set( _found_options TRUE )
+ elseif(
+ "x${arg}" STREQUAL "xWIN32" OR
+ "x${arg}" STREQUAL "xMACOSX_BUNDLE" OR
+ "x${arg}" STREQUAL "xEXCLUDE_FROM_ALL" OR
+ "x${arg}" STREQUAL "xSTATIC" OR
+ "x${arg}" STREQUAL "xSHARED" OR
+ "x${arg}" STREQUAL "xMODULE"
+ )
+ list(APPEND ${_cmake_options} ${arg})
+ else()
+ if ( _found_options )
+ list(APPEND ${_options} ${arg})
+ else()
+ # Assume this is a file
+ list(APPEND ${_sources} ${arg})
+ endif()
+ endif()
+ endforeach()
+endmacro()
+
+##############################################################################
+# Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix
+#
+macro(CUDA_PARSE_NVCC_OPTIONS _option_prefix)
+ set( _found_config )
+ foreach(arg ${ARGN})
+ # Determine if we are dealing with a perconfiguration flag
+ foreach(config ${CUDA_configuration_types})
+ string(TOUPPER ${config} config_upper)
+ if (arg STREQUAL "${config_upper}")
+ set( _found_config _${arg})
+ # Set arg to nothing to keep it from being processed further
+ set( arg )
+ endif()
+ endforeach()
+
+ if ( arg )
+ list(APPEND ${_option_prefix}${_found_config} "${arg}")
+ endif()
+ endforeach()
+endmacro()
+
+##############################################################################
+# Helper to add the include directory for CUDA only once
+function(CUDA_ADD_CUDA_INCLUDE_ONCE)
+ get_directory_property(_include_directories INCLUDE_DIRECTORIES)
+ set(_add TRUE)
+ if(_include_directories)
+ foreach(dir ${_include_directories})
+ if("${dir}" STREQUAL "${CUDA_INCLUDE_DIRS}")
+ set(_add FALSE)
+ endif()
+ endforeach()
+ endif()
+ if(_add)
+ include_directories(${CUDA_INCLUDE_DIRS})
+ endif()
+endfunction()
+
+function(CUDA_BUILD_SHARED_LIBRARY shared_flag)
+ set(cmake_args ${ARGN})
+ # If SHARED, MODULE, or STATIC aren't already in the list of arguments, then
+ # add SHARED or STATIC based on the value of BUILD_SHARED_LIBS.
+ list(FIND cmake_args SHARED _cuda_found_SHARED)
+ list(FIND cmake_args MODULE _cuda_found_MODULE)
+ list(FIND cmake_args STATIC _cuda_found_STATIC)
+ if( _cuda_found_SHARED GREATER -1 OR
+ _cuda_found_MODULE GREATER -1 OR
+ _cuda_found_STATIC GREATER -1)
+ set(_cuda_build_shared_libs)
+ else()
+ if (BUILD_SHARED_LIBS)
+ set(_cuda_build_shared_libs SHARED)
+ else()
+ set(_cuda_build_shared_libs STATIC)
+ endif()
+ endif()
+ set(${shared_flag} ${_cuda_build_shared_libs} PARENT_SCOPE)
+endfunction()
+
+##############################################################################
+# Helper to avoid clashes of files with the same basename but different paths.
+# This doesn't attempt to do exactly what CMake internals do, which is to only
+# add this path when there is a conflict, since by the time a second collision
+# in names is detected it's already too late to fix the first one. For
+# consistency sake the relative path will be added to all files.
+function(CUDA_COMPUTE_BUILD_PATH path build_path)
+ #message("CUDA_COMPUTE_BUILD_PATH([${path}] ${build_path})")
+ # Only deal with CMake style paths from here on out
+ file(TO_CMAKE_PATH "${path}" bpath)
+ if (IS_ABSOLUTE "${bpath}")
+ # Absolute paths are generally unnessary, especially if something like
+ # file(GLOB_RECURSE) is used to pick up the files.
+
+ string(FIND "${bpath}" "${CMAKE_CURRENT_BINARY_DIR}" _binary_dir_pos)
+ if (_binary_dir_pos EQUAL 0)
+ file(RELATIVE_PATH bpath "${CMAKE_CURRENT_BINARY_DIR}" "${bpath}")
+ else()
+ file(RELATIVE_PATH bpath "${CMAKE_CURRENT_SOURCE_DIR}" "${bpath}")
+ endif()
+ endif()
+
+ # This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the
+ # CMake source.
+
+ # Remove leading /
+ string(REGEX REPLACE "^[/]+" "" bpath "${bpath}")
+ # Avoid absolute paths by removing ':'
+ string(REPLACE ":" "_" bpath "${bpath}")
+ # Avoid relative paths that go up the tree
+ string(REPLACE "../" "__/" bpath "${bpath}")
+ # Avoid spaces
+ string(REPLACE " " "_" bpath "${bpath}")
+
+ # Strip off the filename. I wait until here to do it, since removin the
+ # basename can make a path that looked like path/../basename turn into
+ # path/.. (notice the trailing slash).
+ get_filename_component(bpath "${bpath}" PATH)
+
+ set(${build_path} "${bpath}" PARENT_SCOPE)
+ #message("${build_path} = ${bpath}")
+endfunction()
+
+##############################################################################
+# This helper macro populates the following variables and setups up custom
+# commands and targets to invoke the nvcc compiler to generate C or PTX source
+# dependent upon the format parameter. The compiler is invoked once with -M
+# to generate a dependency file and a second time with -cuda or -ptx to generate
+# a .cpp or .ptx file.
+# INPUT:
+# cuda_target - Target name
+# format - PTX, CUBIN, FATBIN or OBJ
+# FILE1 .. FILEN - The remaining arguments are the sources to be wrapped.
+# OPTIONS - Extra options to NVCC
+# OUTPUT:
+# generated_files - List of generated files
+##############################################################################
+##############################################################################
+
+macro(CUDA_WRAP_SRCS cuda_target format generated_files)
+
+ # If CMake doesn't support separable compilation, complain
+ if(CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS "2.8.10.1")
+ message(SEND_ERROR "CUDA_SEPARABLE_COMPILATION isn't supported for CMake versions less than 2.8.10.1")
+ endif()
+
+ # Set up all the command line flags here, so that they can be overridden on a per target basis.
+
+ set(nvcc_flags "")
+
+ # Emulation if the card isn't present.
+ if (CUDA_BUILD_EMULATION)
+ # Emulation.
+ set(nvcc_flags ${nvcc_flags} --device-emulation -D_DEVICEEMU -g)
+ else()
+ # Device mode. No flags necessary.
+ endif()
+
+ if(CUDA_HOST_COMPILATION_CPP)
+ set(CUDA_C_OR_CXX CXX)
+ else()
+ if(CUDA_VERSION VERSION_LESS "3.0")
+ set(nvcc_flags ${nvcc_flags} --host-compilation C)
+ else()
+ message(WARNING "--host-compilation flag is deprecated in CUDA version >= 3.0. Removing --host-compilation C flag" )
+ endif()
+ set(CUDA_C_OR_CXX C)
+ endif()
+
+ set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION})
+
+ if(CUDA_64_BIT_DEVICE_CODE)
+ set(nvcc_flags ${nvcc_flags} -m64)
+ else()
+ set(nvcc_flags ${nvcc_flags} -m32)
+ endif()
+
+ if(CUDA_TARGET_CPU_ARCH)
+ set(nvcc_flags ${nvcc_flags} "--target-cpu-architecture=${CUDA_TARGET_CPU_ARCH}")
+ endif()
+
+ # This needs to be passed in at this stage, because VS needs to fill out the
+ # value of VCInstallDir from within VS. Note that CCBIN is only used if
+ # -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches
+ # $(VCInstallDir)/bin.
+ if(CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(ccbin_flags -D "\"CCBIN:PATH=$(VCInstallDir)bin\"" )
+ else()
+ set(ccbin_flags)
+ endif()
+
+ # Figure out which configure we will use and pass that in as an argument to
+ # the script. We need to defer the decision until compilation time, because
+ # for VS projects we won't know if we are making a debug or release build
+ # until build time.
+ if(CMAKE_GENERATOR MATCHES "Visual Studio")
+ set( CUDA_build_configuration "$(ConfigurationName)" )
+ else()
+ set( CUDA_build_configuration "${CMAKE_BUILD_TYPE}")
+ endif()
+
+ # Initialize our list of includes with the user ones followed by the CUDA system ones.
+ set(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS_USER} "-I${CUDA_INCLUDE_DIRS}")
+ # Get the include directories for this directory and use them for our nvcc command.
+ # Remove duplicate entries which may be present since include_directories
+ # in CMake >= 2.8.8 does not remove them.
+ get_directory_property(CUDA_NVCC_INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES)
+ list(REMOVE_DUPLICATES CUDA_NVCC_INCLUDE_DIRECTORIES)
+ if(CUDA_NVCC_INCLUDE_DIRECTORIES)
+ foreach(dir ${CUDA_NVCC_INCLUDE_DIRECTORIES})
+ list(APPEND CUDA_NVCC_INCLUDE_ARGS -I${dir})
+ endforeach()
+ endif()
+
+ # Reset these variables
+ set(CUDA_WRAP_OPTION_NVCC_FLAGS)
+ foreach(config ${CUDA_configuration_types})
+ string(TOUPPER ${config} config_upper)
+ set(CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper})
+ endforeach()
+
+ CUDA_GET_SOURCES_AND_OPTIONS(_cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options ${ARGN})
+ CUDA_PARSE_NVCC_OPTIONS(CUDA_WRAP_OPTION_NVCC_FLAGS ${_cuda_wrap_options})
+
+ # Figure out if we are building a shared library. BUILD_SHARED_LIBS is
+ # respected in CUDA_ADD_LIBRARY.
+ set(_cuda_build_shared_libs FALSE)
+ # SHARED, MODULE
+ list(FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED)
+ list(FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE)
+ if(_cuda_found_SHARED GREATER -1 OR _cuda_found_MODULE GREATER -1)
+ set(_cuda_build_shared_libs TRUE)
+ endif()
+ # STATIC
+ list(FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC)
+ if(_cuda_found_STATIC GREATER -1)
+ set(_cuda_build_shared_libs FALSE)
+ endif()
+
+ # CUDA_HOST_FLAGS
+ if(_cuda_build_shared_libs)
+ # If we are setting up code for a shared library, then we need to add extra flags for
+ # compiling objects for shared libraries.
+ set(CUDA_HOST_SHARED_FLAGS ${CMAKE_SHARED_LIBRARY_${CUDA_C_OR_CXX}_FLAGS})
+ else()
+ set(CUDA_HOST_SHARED_FLAGS)
+ endif()
+ # Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags. We
+ # always need to set the SHARED_FLAGS, though.
+ if(CUDA_PROPAGATE_HOST_FLAGS)
+ set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})")
+ else()
+ set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})")
+ endif()
+
+ set(_cuda_nvcc_flags_config "# Build specific configuration flags")
+ # Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake
+ foreach(config ${CUDA_configuration_types})
+ string(TOUPPER ${config} config_upper)
+ # CMAKE_FLAGS are strings and not lists. By not putting quotes around CMAKE_FLAGS
+ # we convert the strings to lists (like we want).
+
+ if(CUDA_PROPAGATE_HOST_FLAGS)
+ # nvcc chokes on -g3 in versions previous to 3.0, so replace it with -g
+ set(_cuda_fix_g3 FALSE)
+
+ if(CMAKE_COMPILER_IS_GNUCC)
+ if (CUDA_VERSION VERSION_LESS "3.0" OR
+ CUDA_VERSION VERSION_EQUAL "4.1" OR
+ CUDA_VERSION VERSION_EQUAL "4.2"
+ )
+ set(_cuda_fix_g3 TRUE)
+ endif()
+ endif()
+ if(_cuda_fix_g3)
+ string(REPLACE "-g3" "-g" _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}")
+ else()
+ set(_cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}")
+ endif()
+
+ set(_cuda_host_flags "${_cuda_host_flags}\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})")
+ endif()
+
+ # Note that if we ever want CUDA_NVCC_FLAGS_<CONFIG> to be string (instead of a list
+ # like it is currently), we can remove the quotes around the
+ # ${CUDA_NVCC_FLAGS_${config_upper}} variable like the CMAKE_HOST_FLAGS_<CONFIG> variable.
+ set(_cuda_nvcc_flags_config "${_cuda_nvcc_flags_config}\nset(CUDA_NVCC_FLAGS_${config_upper} ${CUDA_NVCC_FLAGS_${config_upper}} ;; ${CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}})")
+ endforeach()
+
+ # Get the list of definitions from the directory property
+ get_directory_property(CUDA_NVCC_DEFINITIONS COMPILE_DEFINITIONS)
+ if(CUDA_NVCC_DEFINITIONS)
+ foreach(_definition ${CUDA_NVCC_DEFINITIONS})
+ list(APPEND nvcc_flags "-D${_definition}")
+ endforeach()
+ endif()
+
+ if(_cuda_build_shared_libs)
+ list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS")
+ endif()
+
+ # Reset the output variable
+ set(_cuda_wrap_generated_files "")
+
+ # Iterate over the macro arguments and create custom
+ # commands for all the .cu files.
+ foreach(file ${ARGN})
+ # Ignore any file marked as a HEADER_FILE_ONLY
+ get_source_file_property(_is_header ${file} HEADER_FILE_ONLY)
+ if(${file} MATCHES "\\.cu$" AND NOT _is_header)
+
+ # Allow per source file overrides of the format.
+ get_source_file_property(_cuda_source_format ${file} CUDA_SOURCE_PROPERTY_FORMAT)
+ if(NOT _cuda_source_format)
+ set(_cuda_source_format ${format})
+ endif()
+
+ if( ${_cuda_source_format} MATCHES "OBJ")
+ set( cuda_compile_to_external_module OFF )
+ else()
+ set( cuda_compile_to_external_module ON )
+ if( ${_cuda_source_format} MATCHES "PTX" )
+ set( cuda_compile_to_external_module_type "ptx" )
+ elseif( ${_cuda_source_format} MATCHES "CUBIN")
+ set( cuda_compile_to_external_module_type "cubin" )
+ elseif( ${_cuda_source_format} MATCHES "FATBIN")
+ set( cuda_compile_to_external_module_type "fatbin" )
+ else()
+ message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS for file '${file}': '${_cuda_source_format}'. Use OBJ, PTX, CUBIN or FATBIN.")
+ endif()
+ endif()
+
+ if(cuda_compile_to_external_module)
+ # Don't use any of the host compilation flags for PTX targets.
+ set(CUDA_HOST_FLAGS)
+ set(CUDA_NVCC_FLAGS_CONFIG)
+ else()
+ set(CUDA_HOST_FLAGS ${_cuda_host_flags})
+ set(CUDA_NVCC_FLAGS_CONFIG ${_cuda_nvcc_flags_config})
+ endif()
+
+ # Determine output directory
+ cuda_compute_build_path("${file}" cuda_build_path)
+ set(cuda_compile_intermediate_directory "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${cuda_build_path}")
+ if(CUDA_GENERATED_OUTPUT_DIR)
+ set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}")
+ else()
+ if ( cuda_compile_to_external_module )
+ set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}")
+ else()
+ set(cuda_compile_output_dir "${cuda_compile_intermediate_directory}")
+ endif()
+ endif()
+
+ # Add a custom target to generate a c or ptx file. ######################
+
+ get_filename_component( basename ${file} NAME )
+ if( cuda_compile_to_external_module )
+ set(generated_file_path "${cuda_compile_output_dir}")
+ set(generated_file_basename "${cuda_target}_generated_${basename}.${cuda_compile_to_external_module_type}")
+ set(format_flag "-${cuda_compile_to_external_module_type}")
+ file(MAKE_DIRECTORY "${cuda_compile_output_dir}")
+ else()
+ set(generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}")
+ set(generated_file_basename "${cuda_target}_generated_${basename}${generated_extension}")
+ if(CUDA_SEPARABLE_COMPILATION)
+ set(format_flag "-dc")
+ else()
+ set(format_flag "-c")
+ endif()
+ endif()
+
+ # Set all of our file names. Make sure that whatever filenames that have
+ # generated_file_path in them get passed in through as a command line
+ # argument, so that the ${CMAKE_CFG_INTDIR} gets expanded at run time
+ # instead of configure time.
+ set(generated_file "${generated_file_path}/${generated_file_basename}")
+ set(cmake_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.depend")
+ set(NVCC_generated_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.NVCC-depend")
+ set(generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt")
+ set(custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake")
+
+ # Setup properties for obj files:
+ if( NOT cuda_compile_to_external_module )
+ set_source_files_properties("${generated_file}"
+ PROPERTIES
+ EXTERNAL_OBJECT true # This is an object file not to be compiled, but only be linked.
+ )
+ endif()
+
+ # Don't add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path.
+ get_filename_component(file_path "${file}" PATH)
+ if(IS_ABSOLUTE "${file_path}")
+ set(source_file "${file}")
+ else()
+ set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
+ endif()
+
+ if( NOT cuda_compile_to_external_module AND CUDA_SEPARABLE_COMPILATION)
+ list(APPEND ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS "${generated_file}")
+ endif()
+
+ # Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND #######
+ cuda_include_nvcc_dependencies(${cmake_dependency_file})
+
+ # Convience string for output ###########################################
+ if(CUDA_BUILD_EMULATION)
+ set(cuda_build_type "Emulation")
+ else()
+ set(cuda_build_type "Device")
+ endif()
+
+ # Build the NVCC made dependency file ###################################
+ set(build_cubin OFF)
+ if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN )
+ if ( NOT cuda_compile_to_external_module )
+ set ( build_cubin ON )
+ endif()
+ endif()
+
+ # Configure the build script
+ configure_file("${CUDA_run_nvcc}" "${custom_target_script}" @ONLY)
+
+ # So if a user specifies the same cuda file as input more than once, you
+ # can have bad things happen with dependencies. Here we check an option
+ # to see if this is the behavior they want.
+ if(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE)
+ set(main_dep MAIN_DEPENDENCY ${source_file})
+ else()
+ set(main_dep DEPENDS ${source_file})
+ endif()
+
+ if(CUDA_VERBOSE_BUILD)
+ set(verbose_output ON)
+ elseif(CMAKE_GENERATOR MATCHES "Makefiles")
+ set(verbose_output "$(VERBOSE)")
+ else()
+ set(verbose_output OFF)
+ endif()
+
+ # Create up the comment string
+ file(RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}")
+ if(cuda_compile_to_external_module)
+ set(cuda_build_comment_string "Building NVCC ${cuda_compile_to_external_module_type} file ${generated_file_relative_path}")
+ else()
+ set(cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}")
+ endif()
+
+ # Build the generated file and dependency file ##########################
+ add_custom_command(
+ OUTPUT ${generated_file}
+ # These output files depend on the source_file and the contents of cmake_dependency_file
+ ${main_dep}
+ DEPENDS ${CUDA_NVCC_DEPEND}
+ DEPENDS ${custom_target_script}
+ # Make sure the output directory exists before trying to write to it.
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${generated_file_path}"
+ COMMAND ${CMAKE_COMMAND} ARGS
+ -D verbose:BOOL=${verbose_output}
+ ${ccbin_flags}
+ -D build_configuration:STRING=${CUDA_build_configuration}
+ -D "generated_file:STRING=${generated_file}"
+ -D "generated_cubin_file:STRING=${generated_cubin_file}"
+ -P "${custom_target_script}"
+ WORKING_DIRECTORY "${cuda_compile_intermediate_directory}"
+ COMMENT "${cuda_build_comment_string}"
+ )
+
+ # Make sure the build system knows the file is generated.
+ set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE)
+
+ list(APPEND _cuda_wrap_generated_files ${generated_file})
+
+ # Add the other files that we want cmake to clean on a cleanup ##########
+ list(APPEND CUDA_ADDITIONAL_CLEAN_FILES "${cmake_dependency_file}")
+ list(REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES)
+ set(CUDA_ADDITIONAL_CLEAN_FILES ${CUDA_ADDITIONAL_CLEAN_FILES} CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.")
+
+ endif()
+ endforeach()
+
+ # Set the return parameter
+ set(${generated_files} ${_cuda_wrap_generated_files})
+endmacro()
+
+function(_cuda_get_important_host_flags important_flags flag_string)
+ if(CMAKE_GENERATOR MATCHES "Visual Studio")
+ string(REGEX MATCHALL "/M[DT][d]?" flags ${flag_string})
+ list(APPEND ${important_flags} ${flags})
+ else()
+ string(REGEX MATCHALL "-fPIC" flags ${flag_string})
+ list(APPEND ${important_flags} ${flags})
+ endif()
+ set(${important_flags} ${${important_flags}} PARENT_SCOPE)
+endfunction()
+
+###############################################################################
+###############################################################################
+# Separable Compilation Link
+###############################################################################
+###############################################################################
+
+# Compute the filename to be used by CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS
+function(CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME output_file_var cuda_target object_files)
+ if (object_files)
+ set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION})
+ set(output_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${CMAKE_CFG_INTDIR}/${cuda_target}_intermediate_link${generated_extension}")
+ else()
+ set(output_file)
+ endif()
+
+ set(${output_file_var} "${output_file}" PARENT_SCOPE)
+endfunction()
+
+# Setup the build rule for the separable compilation intermediate link file.
+function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files)
+ if (object_files)
+
+ set_source_files_properties("${output_file}"
+ PROPERTIES
+ EXTERNAL_OBJECT TRUE # This is an object file not to be compiled, but only
+ # be linked.
+ GENERATED TRUE # This file is generated during the build
+ )
+
+ # For now we are ignoring all the configuration specific flags.
+ set(nvcc_flags)
+ CUDA_PARSE_NVCC_OPTIONS(nvcc_flags ${options})
+ if(CUDA_64_BIT_DEVICE_CODE)
+ list(APPEND nvcc_flags -m64)
+ else()
+ list(APPEND nvcc_flags -m32)
+ endif()
+ # If -ccbin, --compiler-bindir has been specified, don't do anything. Otherwise add it here.
+ list( FIND nvcc_flags "-ccbin" ccbin_found0 )
+ list( FIND nvcc_flags "--compiler-bindir" ccbin_found1 )
+ if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER )
+ list(APPEND nvcc_flags -ccbin "\"${CUDA_HOST_COMPILER}\"")
+ endif()
+ # Create a list of flags specified by CUDA_NVCC_FLAGS_${CONFIG}
+ set(config_specific_flags)
+ set(flags)
+ foreach(config ${CUDA_configuration_types})
+ string(TOUPPER ${config} config_upper)
+ # Add config specific flags
+ foreach(f ${CUDA_NVCC_FLAGS_${config_upper}})
+ list(APPEND config_specific_flags $<$<CONFIG:${config}>:${f}>)
+ endforeach()
+ set(important_host_flags)
+ _cuda_get_important_host_flags(important_host_flags ${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}})
+ foreach(f ${important_host_flags})
+ list(APPEND flags $<$<CONFIG:${config}>:-Xcompiler> $<$<CONFIG:${config}>:${f}>)
+ endforeach()
+ endforeach()
+ # Add our general CUDA_NVCC_FLAGS with the configuration specifig flags
+ set(nvcc_flags ${CUDA_NVCC_FLAGS} ${config_specific_flags} ${nvcc_flags})
+
+ file(RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}")
+
+ # Some generators don't handle the multiple levels of custom command
+ # dependencies correctly (obj1 depends on file1, obj2 depends on obj1), so
+ # we work around that issue by compiling the intermediate link object as a
+ # pre-link custom command in that situation.
+ set(do_obj_build_rule TRUE)
+ if (MSVC_VERSION GREATER 1599)
+ # VS 2010 and 2012 have this problem. If future versions fix this issue,
+ # it should still work, it just won't be as nice as the other method.
+ set(do_obj_build_rule FALSE)
+ endif()
+
+ if (do_obj_build_rule)
+ add_custom_command(
+ OUTPUT ${output_file}
+ DEPENDS ${object_files}
+ COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file}
+ ${flags}
+ COMMENT "Building NVCC intermediate link file ${output_file_relative_path}"
+ )
+ else()
+ add_custom_command(
+ TARGET ${cuda_target}
+ PRE_LINK
+ COMMAND ${CMAKE_COMMAND} -E echo "Building NVCC intermediate link file ${output_file_relative_path}"
+ COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}"
+ )
+ endif()
+ endif()
+endfunction()
+
+###############################################################################
+###############################################################################
+# ADD LIBRARY
+###############################################################################
+###############################################################################
+macro(CUDA_ADD_LIBRARY cuda_target)
+
+ CUDA_ADD_CUDA_INCLUDE_ONCE()
+
+ # Separate the sources from the options
+ CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
+ CUDA_BUILD_SHARED_LIBRARY(_cuda_shared_flag ${ARGN})
+ # Create custom commands and targets for each file.
+ CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources}
+ ${_cmake_options} ${_cuda_shared_flag}
+ OPTIONS ${_options} )
+
+ # Compute the file name of the intermedate link file used for separable
+ # compilation.
+ CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
+
+ # Add the library.
+ add_library(${cuda_target} ${_cmake_options}
+ ${_generated_files}
+ ${_sources}
+ ${link_file}
+ )
+
+ # Add a link phase for the separable compilation if it has been enabled. If
+ # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS
+ # variable will have been defined.
+ CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
+
+ target_link_libraries(${cuda_target}
+ ${CUDA_LIBRARIES}
+ )
+
+ # We need to set the linker language based on what the expected generated file
+ # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
+ set_target_properties(${cuda_target}
+ PROPERTIES
+ LINKER_LANGUAGE ${CUDA_C_OR_CXX}
+ )
+
+endmacro()
+
+
+###############################################################################
+###############################################################################
+# ADD EXECUTABLE
+###############################################################################
+###############################################################################
+macro(CUDA_ADD_EXECUTABLE cuda_target)
+
+ CUDA_ADD_CUDA_INCLUDE_ONCE()
+
+ # Separate the sources from the options
+ CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
+ # Create custom commands and targets for each file.
+ CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} OPTIONS ${_options} )
+
+ # Compute the file name of the intermedate link file used for separable
+ # compilation.
+ CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
+
+ # Add the library.
+ add_executable(${cuda_target} ${_cmake_options}
+ ${_generated_files}
+ ${_sources}
+ ${link_file}
+ )
+
+ # Add a link phase for the separable compilation if it has been enabled. If
+ # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS
+ # variable will have been defined.
+ CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
+
+ target_link_libraries(${cuda_target}
+ ${CUDA_LIBRARIES}
+ )
+
+ # We need to set the linker language based on what the expected generated file
+ # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
+ set_target_properties(${cuda_target}
+ PROPERTIES
+ LINKER_LANGUAGE ${CUDA_C_OR_CXX}
+ )
+
+endmacro()
+
+
+###############################################################################
+###############################################################################
+# (Internal) helper for manually added cuda source files with specific targets
+###############################################################################
+###############################################################################
+macro(cuda_compile_base cuda_target format generated_files)
+
+ # Separate the sources from the options
+ CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
+ # Create custom commands and targets for each file.
+ CUDA_WRAP_SRCS( ${cuda_target} ${format} _generated_files ${_sources} ${_cmake_options}
+ OPTIONS ${_options} )
+
+ set( ${generated_files} ${_generated_files})
+
+endmacro()
+
+###############################################################################
+###############################################################################
+# CUDA COMPILE
+###############################################################################
+###############################################################################
+macro(CUDA_COMPILE generated_files)
+ cuda_compile_base(cuda_compile OBJ ${generated_files} ${ARGN})
+endmacro()
+
+###############################################################################
+###############################################################################
+# CUDA COMPILE PTX
+###############################################################################
+###############################################################################
+macro(CUDA_COMPILE_PTX generated_files)
+ cuda_compile_base(cuda_compile_ptx PTX ${generated_files} ${ARGN})
+endmacro()
+
+###############################################################################
+###############################################################################
+# CUDA COMPILE FATBIN
+###############################################################################
+###############################################################################
+macro(CUDA_COMPILE_FATBIN generated_files)
+ cuda_compile_base(cuda_compile_fatbin FATBIN ${generated_files} ${ARGN})
+endmacro()
+
+###############################################################################
+###############################################################################
+# CUDA COMPILE CUBIN
+###############################################################################
+###############################################################################
+macro(CUDA_COMPILE_CUBIN generated_files)
+ cuda_compile_base(cuda_compile_cubin CUBIN ${generated_files} ${ARGN})
+endmacro()
+
+
+###############################################################################
+###############################################################################
+# CUDA ADD CUFFT TO TARGET
+###############################################################################
+###############################################################################
+macro(CUDA_ADD_CUFFT_TO_TARGET target)
+ if (CUDA_BUILD_EMULATION)
+ target_link_libraries(${target} ${CUDA_cufftemu_LIBRARY})
+ else()
+ target_link_libraries(${target} ${CUDA_cufft_LIBRARY})
+ endif()
+endmacro()
+
+###############################################################################
+###############################################################################
+# CUDA ADD CUBLAS TO TARGET
+###############################################################################
+###############################################################################
+macro(CUDA_ADD_CUBLAS_TO_TARGET target)
+ if (CUDA_BUILD_EMULATION)
+ target_link_libraries(${target} ${CUDA_cublasemu_LIBRARY})
+ else()
+ target_link_libraries(${target} ${CUDA_cublas_LIBRARY})
+ endif()
+endmacro()
+
+###############################################################################
+###############################################################################
+# CUDA BUILD CLEAN TARGET
+###############################################################################
+###############################################################################
+macro(CUDA_BUILD_CLEAN_TARGET)
+ # Call this after you add all your CUDA targets, and you will get a convience
+ # target. You should also make clean after running this target to get the
+ # build system to generate all the code again.
+
+ set(cuda_clean_target_name clean_cuda_depends)
+ if (CMAKE_GENERATOR MATCHES "Visual Studio")
+ string(TOUPPER ${cuda_clean_target_name} cuda_clean_target_name)
+ endif()
+ add_custom_target(${cuda_clean_target_name}
+ COMMAND ${CMAKE_COMMAND} -E remove ${CUDA_ADDITIONAL_CLEAN_FILES})
+
+ # Clear out the variable, so the next time we configure it will be empty.
+ # This is useful so that the files won't persist in the list after targets
+ # have been removed.
+ set(CUDA_ADDITIONAL_CLEAN_FILES "" CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.")
+endmacro()
diff --git a/Modules/FindCUDA/make2cmake.cmake b/Modules/FindCUDA/make2cmake.cmake
new file mode 100644
index 0000000000..c433fa8ed4
--- /dev/null
+++ b/Modules/FindCUDA/make2cmake.cmake
@@ -0,0 +1,92 @@
+# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
+# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
+#
+# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
+#
+# Copyright (c) 2007-2009
+# Scientific Computing and Imaging Institute, University of Utah
+#
+# This code is licensed under the MIT License. See the FindCUDA.cmake script
+# for the text of the license.
+
+# The MIT License
+#
+# License for the specific language governing rights and limitations under
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+#
+
+#######################################################################
+# This converts a file written in makefile syntax into one that can be included
+# by CMake.
+
+file(READ ${input_file} depend_text)
+
+if (NOT "${depend_text}" STREQUAL "")
+
+ # message("FOUND DEPENDS")
+
+ string(REPLACE "\\ " " " depend_text ${depend_text})
+
+ # This works for the nvcc -M generated dependency files.
+ string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
+ string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
+
+ set(dependency_list "")
+
+ foreach(file ${depend_text})
+
+ string(REGEX REPLACE "^ +" "" file ${file})
+
+ # OK, now if we had a UNC path, nvcc has a tendency to only output the first '/'
+ # instead of '//'. Here we will test to see if the file exists, if it doesn't then
+ # try to prepend another '/' to the path and test again. If it still fails remove the
+ # path.
+
+ if(NOT EXISTS "${file}")
+ if (EXISTS "/${file}")
+ set(file "/${file}")
+ else()
+ message(WARNING " Removing non-existent dependency file: ${file}")
+ set(file "")
+ endif()
+ endif()
+
+ if(NOT IS_DIRECTORY "${file}")
+ # If softlinks start to matter, we should change this to REALPATH. For now we need
+ # to flatten paths, because nvcc can generate stuff like /bin/../include instead of
+ # just /include.
+ get_filename_component(file_absolute "${file}" ABSOLUTE)
+ list(APPEND dependency_list "${file_absolute}")
+ endif()
+
+ endforeach()
+
+else()
+ # message("FOUND NO DEPENDS")
+endif()
+
+# Remove the duplicate entries and sort them.
+list(REMOVE_DUPLICATES dependency_list)
+list(SORT dependency_list)
+
+foreach(file ${dependency_list})
+ set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
+endforeach()
+
+file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")
diff --git a/Modules/FindCUDA/parse_cubin.cmake b/Modules/FindCUDA/parse_cubin.cmake
new file mode 100644
index 0000000000..626c8a2e47
--- /dev/null
+++ b/Modules/FindCUDA/parse_cubin.cmake
@@ -0,0 +1,111 @@
+# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
+# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
+#
+# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
+#
+# Copyright (c) 2007-2009
+# Scientific Computing and Imaging Institute, University of Utah
+#
+# This code is licensed under the MIT License. See the FindCUDA.cmake script
+# for the text of the license.
+
+# The MIT License
+#
+# License for the specific language governing rights and limitations under
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+#
+
+#######################################################################
+# Parses a .cubin file produced by nvcc and reports statistics about the file.
+
+
+file(READ ${input_file} file_text)
+
+if (NOT "${file_text}" STREQUAL "")
+
+ string(REPLACE ";" "\\;" file_text ${file_text})
+ string(REPLACE "\ncode" ";code" file_text ${file_text})
+
+ list(LENGTH file_text len)
+
+ foreach(line ${file_text})
+
+ # Only look at "code { }" blocks.
+ if(line MATCHES "^code")
+
+ # Break into individual lines.
+ string(REGEX REPLACE "\n" ";" line ${line})
+
+ foreach(entry ${line})
+
+ # Extract kernel names.
+ if (${entry} MATCHES "[^g]name = ([^ ]+)")
+ set(entry "${CMAKE_MATCH_1}")
+
+ # Check to see if the kernel name starts with "_"
+ set(skip FALSE)
+ # if (${entry} MATCHES "^_")
+ # Skip the rest of this block.
+ # message("Skipping ${entry}")
+ # set(skip TRUE)
+ # else ()
+ message("Kernel: ${entry}")
+ # endif ()
+
+ endif()
+
+ # Skip the rest of the block if necessary
+ if(NOT skip)
+
+ # Registers
+ if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)")
+ set(entry "${CMAKE_MATCH_3}")
+ message("Registers: ${entry}")
+ endif()
+
+ # Local memory
+ if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)")
+ set(entry "${CMAKE_MATCH_3}")
+ message("Local: ${entry}")
+ endif()
+
+ # Shared memory
+ if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)")
+ set(entry "${CMAKE_MATCH_3}")
+ message("Shared: ${entry}")
+ endif()
+
+ if (${entry} MATCHES "^}")
+ message("")
+ endif()
+
+ endif()
+
+
+ endforeach()
+
+ endif()
+
+ endforeach()
+
+else()
+ # message("FOUND NO DEPENDS")
+endif()
+
+
diff --git a/Modules/FindCUDA/run_nvcc.cmake b/Modules/FindCUDA/run_nvcc.cmake
new file mode 100644
index 0000000000..abdd3079e1
--- /dev/null
+++ b/Modules/FindCUDA/run_nvcc.cmake
@@ -0,0 +1,288 @@
+# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
+#
+# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
+#
+# This code is licensed under the MIT License. See the FindCUDA.cmake script
+# for the text of the license.
+
+# The MIT License
+#
+# License for the specific language governing rights and limitations under
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+
+##########################################################################
+# This file runs the nvcc commands to produce the desired output file along with
+# the dependency file needed by CMake to compute dependencies. In addition the
+# file checks the output of each command and if the command fails it deletes the
+# output files.
+
+# Input variables
+#
+# verbose:BOOL=<> OFF: Be as quiet as possible (default)
+# ON : Describe each step
+#
+# build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or
+# RelWithDebInfo, but it should match one of the
+# entries in CUDA_HOST_FLAGS. This is the build
+# configuration used when compiling the code. If
+# blank or unspecified Debug is assumed as this is
+# what CMake does.
+#
+# generated_file:STRING=<> File to generate. This argument must be passed in.
+#
+# generated_cubin_file:STRING=<> File to generate. This argument must be passed
+# in if build_cubin is true.
+
+if(NOT generated_file)
+ message(FATAL_ERROR "You must specify generated_file on the command line")
+endif()
+
+# Set these up as variables to make reading the generated file easier
+set(CMAKE_COMMAND "@CMAKE_COMMAND@") # path
+set(source_file "@source_file@") # path
+set(NVCC_generated_dependency_file "@NVCC_generated_dependency_file@") # path
+set(cmake_dependency_file "@cmake_dependency_file@") # path
+set(CUDA_make2cmake "@CUDA_make2cmake@") # path
+set(CUDA_parse_cubin "@CUDA_parse_cubin@") # path
+set(build_cubin @build_cubin@) # bool
+set(CUDA_HOST_COMPILER "@CUDA_HOST_COMPILER@") # path
+# We won't actually use these variables for now, but we need to set this, in
+# order to force this file to be run again if it changes.
+set(generated_file_path "@generated_file_path@") # path
+set(generated_file_internal "@generated_file@") # path
+set(generated_cubin_file_internal "@generated_cubin_file@") # path
+
+set(CUDA_NVCC_EXECUTABLE "@CUDA_NVCC_EXECUTABLE@") # path
+set(CUDA_NVCC_FLAGS @CUDA_NVCC_FLAGS@ ;; @CUDA_WRAP_OPTION_NVCC_FLAGS@) # list
+@CUDA_NVCC_FLAGS_CONFIG@
+set(nvcc_flags @nvcc_flags@) # list
+set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@") # list (needs to be in quotes to handle spaces properly).
+set(format_flag "@format_flag@") # string
+
+if(build_cubin AND NOT generated_cubin_file)
+ message(FATAL_ERROR "You must specify generated_cubin_file on the command line")
+endif()
+
+# This is the list of host compilation flags. It C or CXX should already have
+# been chosen by FindCUDA.cmake.
+@CUDA_HOST_FLAGS@
+
+# Take the compiler flags and package them up to be sent to the compiler via -Xcompiler
+set(nvcc_host_compiler_flags "")
+# If we weren't given a build_configuration, use Debug.
+if(NOT build_configuration)
+ set(build_configuration Debug)
+endif()
+string(TOUPPER "${build_configuration}" build_configuration)
+#message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}")
+foreach(flag ${CMAKE_HOST_FLAGS} ${CMAKE_HOST_FLAGS_${build_configuration}})
+ # Extra quotes are added around each flag to help nvcc parse out flags with spaces.
+ set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"")
+endforeach()
+if (nvcc_host_compiler_flags)
+ set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags})
+endif()
+#message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"")
+# Add the build specific configuration flags
+list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}})
+
+# Any -ccbin existing in CUDA_NVCC_FLAGS gets highest priority
+list( FIND CUDA_NVCC_FLAGS "-ccbin" ccbin_found0 )
+list( FIND CUDA_NVCC_FLAGS "--compiler-bindir" ccbin_found1 )
+if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER )
+ if (CUDA_HOST_COMPILER STREQUAL "$(VCInstallDir)bin" AND DEFINED CCBIN)
+ set(CCBIN -ccbin "${CCBIN}")
+ else()
+ set(CCBIN -ccbin "${CUDA_HOST_COMPILER}")
+ endif()
+endif()
+
+# cuda_execute_process - Executes a command with optional command echo and status message.
+#
+# status - Status message to print if verbose is true
+# command - COMMAND argument from the usual execute_process argument structure
+# ARGN - Remaining arguments are the command with arguments
+#
+# CUDA_result - return value from running the command
+#
+# Make this a macro instead of a function, so that things like RESULT_VARIABLE
+# and other return variables are present after executing the process.
+macro(cuda_execute_process status command)
+ set(_command ${command})
+ if(NOT "x${_command}" STREQUAL "xCOMMAND")
+ message(FATAL_ERROR "Malformed call to cuda_execute_process. Missing COMMAND as second argument. (command = ${command})")
+ endif()
+ if(verbose)
+ execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status})
+ # Now we need to build up our command string. We are accounting for quotes
+ # and spaces, anything else is left up to the user to fix if they want to
+ # copy and paste a runnable command line.
+ set(cuda_execute_process_string)
+ foreach(arg ${ARGN})
+ # If there are quotes, excape them, so they come through.
+ string(REPLACE "\"" "\\\"" arg ${arg})
+ # Args with spaces need quotes around them to get them to be parsed as a single argument.
+ if(arg MATCHES " ")
+ list(APPEND cuda_execute_process_string "\"${arg}\"")
+ else()
+ list(APPEND cuda_execute_process_string ${arg})
+ endif()
+ endforeach()
+ # Echo the command
+ execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string})
+ endif()
+ # Run the command
+ execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result )
+endmacro()
+
+# Delete the target file
+cuda_execute_process(
+ "Removing ${generated_file}"
+ COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
+ )
+
+# For CUDA 2.3 and below, -G -M doesn't work, so remove the -G flag
+# for dependency generation and hope for the best.
+set(depends_CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}")
+set(CUDA_VERSION @CUDA_VERSION@)
+if(CUDA_VERSION VERSION_LESS "3.0")
+ cmake_policy(PUSH)
+ # CMake policy 0007 NEW states that empty list elements are not
+ # ignored. I'm just setting it to avoid the warning that's printed.
+ cmake_policy(SET CMP0007 NEW)
+ # Note that this will remove all occurances of -G.
+ list(REMOVE_ITEM depends_CUDA_NVCC_FLAGS "-G")
+ cmake_policy(POP)
+endif()
+
+# nvcc doesn't define __CUDACC__ for some reason when generating dependency files. This
+# can cause incorrect dependencies when #including files based on this macro which is
+# defined in the generating passes of nvcc invokation. We will go ahead and manually
+# define this for now until a future version fixes this bug.
+set(CUDACC_DEFINE -D__CUDACC__)
+
+# Generate the dependency file
+cuda_execute_process(
+ "Generating dependency file: ${NVCC_generated_dependency_file}"
+ COMMAND "${CUDA_NVCC_EXECUTABLE}"
+ -M
+ ${CUDACC_DEFINE}
+ "${source_file}"
+ -o "${NVCC_generated_dependency_file}"
+ ${CCBIN}
+ ${nvcc_flags}
+ ${nvcc_host_compiler_flags}
+ ${depends_CUDA_NVCC_FLAGS}
+ -DNVCC
+ ${CUDA_NVCC_INCLUDE_ARGS}
+ )
+
+if(CUDA_result)
+ message(FATAL_ERROR "Error generating ${generated_file}")
+endif()
+
+# Generate the cmake readable dependency file to a temp file. Don't put the
+# quotes just around the filenames for the input_file and output_file variables.
+# CMake will pass the quotes through and not be able to find the file.
+cuda_execute_process(
+ "Generating temporary cmake readable file: ${cmake_dependency_file}.tmp"
+ COMMAND "${CMAKE_COMMAND}"
+ -D "input_file:FILEPATH=${NVCC_generated_dependency_file}"
+ -D "output_file:FILEPATH=${cmake_dependency_file}.tmp"
+ -P "${CUDA_make2cmake}"
+ )
+
+if(CUDA_result)
+ message(FATAL_ERROR "Error generating ${generated_file}")
+endif()
+
+# Copy the file if it is different
+cuda_execute_process(
+ "Copy if different ${cmake_dependency_file}.tmp to ${cmake_dependency_file}"
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${cmake_dependency_file}.tmp" "${cmake_dependency_file}"
+ )
+
+if(CUDA_result)
+ message(FATAL_ERROR "Error generating ${generated_file}")
+endif()
+
+# Delete the temporary file
+cuda_execute_process(
+ "Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}"
+ COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}"
+ )
+
+if(CUDA_result)
+ message(FATAL_ERROR "Error generating ${generated_file}")
+endif()
+
+# Generate the code
+cuda_execute_process(
+ "Generating ${generated_file}"
+ COMMAND "${CUDA_NVCC_EXECUTABLE}"
+ "${source_file}"
+ ${format_flag} -o "${generated_file}"
+ ${CCBIN}
+ ${nvcc_flags}
+ ${nvcc_host_compiler_flags}
+ ${CUDA_NVCC_FLAGS}
+ -DNVCC
+ ${CUDA_NVCC_INCLUDE_ARGS}
+ )
+
+if(CUDA_result)
+ # Since nvcc can sometimes leave half done files make sure that we delete the output file.
+ cuda_execute_process(
+ "Removing ${generated_file}"
+ COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
+ )
+ message(FATAL_ERROR "Error generating file ${generated_file}")
+else()
+ if(verbose)
+ message("Generated ${generated_file} successfully.")
+ endif()
+endif()
+
+# Cubin resource report commands.
+if( build_cubin )
+ # Run with -cubin to produce resource usage report.
+ cuda_execute_process(
+ "Generating ${generated_cubin_file}"
+ COMMAND "${CUDA_NVCC_EXECUTABLE}"
+ "${source_file}"
+ ${CUDA_NVCC_FLAGS}
+ ${nvcc_flags}
+ ${CCBIN}
+ ${nvcc_host_compiler_flags}
+ -DNVCC
+ -cubin
+ -o "${generated_cubin_file}"
+ ${CUDA_NVCC_INCLUDE_ARGS}
+ )
+
+ # Execute the parser script.
+ cuda_execute_process(
+ "Executing the parser script"
+ COMMAND "${CMAKE_COMMAND}"
+ -D "input_file:STRING=${generated_cubin_file}"
+ -P "${CUDA_parse_cubin}"
+ )
+
+endif()
diff --git a/Modules/FindCURL.cmake b/Modules/FindCURL.cmake
new file mode 100644
index 0000000000..209fd877de
--- /dev/null
+++ b/Modules/FindCURL.cmake
@@ -0,0 +1,68 @@
+#.rst:
+# FindCURL
+# --------
+#
+# Find curl
+#
+# Find the native CURL headers and libraries.
+#
+# ::
+#
+# CURL_INCLUDE_DIRS - where to find curl/curl.h, etc.
+# CURL_LIBRARIES - List of libraries when using curl.
+# CURL_FOUND - True if curl found.
+# CURL_VERSION_STRING - the version of curl found (since CMake 2.8.8)
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+# Look for the header file.
+find_path(CURL_INCLUDE_DIR NAMES curl/curl.h)
+mark_as_advanced(CURL_INCLUDE_DIR)
+
+# Look for the library (sorted from most current/relevant entry to least).
+find_library(CURL_LIBRARY NAMES
+ curl
+ # Windows MSVC prebuilts:
+ curllib
+ libcurl_imp
+ curllib_static
+ # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip):
+ libcurl
+)
+mark_as_advanced(CURL_LIBRARY)
+
+if(CURL_INCLUDE_DIR)
+ foreach(_curl_version_header curlver.h curl.h)
+ if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}")
+ file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"")
+
+ string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}")
+ unset(curl_version_str)
+ break()
+ endif()
+ endforeach()
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL
+ REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR
+ VERSION_VAR CURL_VERSION_STRING)
+
+if(CURL_FOUND)
+ set(CURL_LIBRARIES ${CURL_LIBRARY})
+ set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
+endif()
diff --git a/Modules/FindCVS.cmake b/Modules/FindCVS.cmake
new file mode 100644
index 0000000000..6f545dfd5a
--- /dev/null
+++ b/Modules/FindCVS.cmake
@@ -0,0 +1,82 @@
+#.rst:
+# FindCVS
+# -------
+#
+#
+#
+# The module defines the following variables:
+#
+# ::
+#
+# CVS_EXECUTABLE - path to cvs command line client
+# CVS_FOUND - true if the command line client was found
+#
+# Example usage:
+#
+# ::
+#
+# find_package(CVS)
+# if(CVS_FOUND)
+# message("CVS found: ${CVS_EXECUTABLE}")
+# endif()
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+# CVSNT
+
+get_filename_component(
+ CVSNT_TypeLib_Win32
+ "[HKEY_CLASSES_ROOT\\TypeLib\\{2BDF7A65-0BFE-4B1A-9205-9AB900C7D0DA}\\1.0\\0\\win32]"
+ PATH)
+
+get_filename_component(
+ CVSNT_Services_EventMessagePath
+ "[HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Services\\Eventlog\\Application\\cvsnt;EventMessageFile]"
+ PATH)
+
+# WinCVS (in case CVSNT was installed in the same directory)
+
+get_filename_component(
+ WinCVS_Folder_Command
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\Folder\\shell\\wincvs\\command]"
+ PATH)
+
+# TortoiseCVS (in case CVSNT was installed in the same directory)
+
+get_filename_component(
+ TortoiseCVS_Folder_Command
+ "[HKEY_CLASSES_ROOT\\CVS\\shell\\open\\command]"
+ PATH)
+
+get_filename_component(
+ TortoiseCVS_DefaultIcon
+ "[HKEY_CLASSES_ROOT\\CVS\\DefaultIcon]"
+ PATH)
+
+find_program(CVS_EXECUTABLE cvs
+ ${TortoiseCVS_DefaultIcon}
+ ${TortoiseCVS_Folder_Command}
+ ${WinCVS_Folder_Command}
+ ${CVSNT_Services_EventMessagePath}
+ ${CVSNT_TypeLib_Win32}
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\CVS\\Pserver;InstallPath]"
+ DOC "CVS command line client"
+ )
+mark_as_advanced(CVS_EXECUTABLE)
+
+# Handle the QUIETLY and REQUIRED arguments and set CVS_FOUND to TRUE if
+# all listed variables are TRUE
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(CVS DEFAULT_MSG CVS_EXECUTABLE)
diff --git a/Modules/FindCoin3D.cmake b/Modules/FindCoin3D.cmake
new file mode 100644
index 0000000000..b5c3a96791
--- /dev/null
+++ b/Modules/FindCoin3D.cmake
@@ -0,0 +1,91 @@
+#.rst:
+# FindCoin3D
+# ----------
+#
+# Find Coin3D (Open Inventor)
+#
+# Coin3D is an implementation of the Open Inventor API. It provides
+# data structures and algorithms for 3D visualization
+# http://www.coin3d.org/
+#
+# This module defines the following variables
+#
+# ::
+#
+# COIN3D_FOUND - system has Coin3D - Open Inventor
+# COIN3D_INCLUDE_DIRS - where the Inventor include directory can be found
+# COIN3D_LIBRARIES - Link to this to use Coin3D
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+if (WIN32)
+ if (CYGWIN)
+
+ find_path(COIN3D_INCLUDE_DIRS Inventor/So.h)
+ find_library(COIN3D_LIBRARIES Coin)
+
+ else ()
+
+ find_path(COIN3D_INCLUDE_DIRS Inventor/So.h
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SIM\\Coin3D\\2;Installation Path]/include"
+ )
+
+ find_library(COIN3D_LIBRARY_DEBUG coin2d
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SIM\\Coin3D\\2;Installation Path]/lib"
+ )
+
+ find_library(COIN3D_LIBRARY_RELEASE coin2
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SIM\\Coin3D\\2;Installation Path]/lib"
+ )
+
+ if (COIN3D_LIBRARY_DEBUG AND COIN3D_LIBRARY_RELEASE)
+ set(COIN3D_LIBRARIES optimized ${COIN3D_LIBRARY_RELEASE}
+ debug ${COIN3D_LIBRARY_DEBUG})
+ else ()
+ if (COIN3D_LIBRARY_DEBUG)
+ set (COIN3D_LIBRARIES ${COIN3D_LIBRARY_DEBUG})
+ endif ()
+ if (COIN3D_LIBRARY_RELEASE)
+ set (COIN3D_LIBRARIES ${COIN3D_LIBRARY_RELEASE})
+ endif ()
+ endif ()
+
+ endif ()
+
+else ()
+ if(APPLE)
+ find_path(COIN3D_INCLUDE_DIRS Inventor/So.h
+ /Library/Frameworks/Inventor.framework/Headers
+ )
+ find_library(COIN3D_LIBRARIES Coin
+ /Library/Frameworks/Inventor.framework/Libraries
+ )
+ set(COIN3D_LIBRARIES "-framework Coin3d" CACHE STRING "Coin3D library for OSX")
+ else()
+
+ find_path(COIN3D_INCLUDE_DIRS Inventor/So.h)
+ find_library(COIN3D_LIBRARIES Coin)
+
+ endif()
+
+endif ()
+
+# handle the QUIETLY and REQUIRED arguments and set COIN3D_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Coin3D DEFAULT_MSG COIN3D_LIBRARIES COIN3D_INCLUDE_DIRS)
+
+mark_as_advanced(COIN3D_INCLUDE_DIRS COIN3D_LIBRARIES )
+
+
diff --git a/Modules/FindCups.cmake b/Modules/FindCups.cmake
new file mode 100644
index 0000000000..51eb7c58e7
--- /dev/null
+++ b/Modules/FindCups.cmake
@@ -0,0 +1,79 @@
+#.rst:
+# FindCups
+# --------
+#
+# Try to find the Cups printing system
+#
+# Once done this will define
+#
+# ::
+#
+# CUPS_FOUND - system has Cups
+# CUPS_INCLUDE_DIR - the Cups include directory
+# CUPS_LIBRARIES - Libraries needed to use Cups
+# CUPS_VERSION_STRING - version of Cups found (since CMake 2.8.8)
+# Set CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE to TRUE if you need a version which
+# features this function (i.e. at least 1.1.19)
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+find_path(CUPS_INCLUDE_DIR cups/cups.h )
+
+find_library(CUPS_LIBRARIES NAMES cups )
+
+if (CUPS_INCLUDE_DIR AND CUPS_LIBRARIES AND CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE)
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
+ include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
+ cmake_push_check_state()
+ set(CMAKE_REQUIRED_QUIET ${Cups_FIND_QUIETLY})
+
+ # ippDeleteAttribute is new in cups-1.1.19 (and used by kdeprint)
+ CHECK_LIBRARY_EXISTS(cups ippDeleteAttribute "" CUPS_HAS_IPP_DELETE_ATTRIBUTE)
+ cmake_pop_check_state()
+endif ()
+
+if (CUPS_INCLUDE_DIR AND EXISTS "${CUPS_INCLUDE_DIR}/cups/cups.h")
+ file(STRINGS "${CUPS_INCLUDE_DIR}/cups/cups.h" cups_version_str
+ REGEX "^#[\t ]*define[\t ]+CUPS_VERSION_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
+
+ unset(CUPS_VERSION_STRING)
+ foreach(VPART MAJOR MINOR PATCH)
+ foreach(VLINE ${cups_version_str})
+ if(VLINE MATCHES "^#[\t ]*define[\t ]+CUPS_VERSION_${VPART}[\t ]+([0-9]+)$")
+ set(CUPS_VERSION_PART "${CMAKE_MATCH_1}")
+ if(CUPS_VERSION_STRING)
+ set(CUPS_VERSION_STRING "${CUPS_VERSION_STRING}.${CUPS_VERSION_PART}")
+ else()
+ set(CUPS_VERSION_STRING "${CUPS_VERSION_PART}")
+ endif()
+ endif()
+ endforeach()
+ endforeach()
+endif ()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+if (CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cups
+ REQUIRED_VARS CUPS_LIBRARIES CUPS_INCLUDE_DIR CUPS_HAS_IPP_DELETE_ATTRIBUTE
+ VERSION_VAR CUPS_VERSION_STRING)
+else ()
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cups
+ REQUIRED_VARS CUPS_LIBRARIES CUPS_INCLUDE_DIR
+ VERSION_VAR CUPS_VERSION_STRING)
+endif ()
+
+mark_as_advanced(CUPS_INCLUDE_DIR CUPS_LIBRARIES)
diff --git a/Modules/FindCurses.cmake b/Modules/FindCurses.cmake
new file mode 100644
index 0000000000..0184c39def
--- /dev/null
+++ b/Modules/FindCurses.cmake
@@ -0,0 +1,220 @@
+#.rst:
+# FindCurses
+# ----------
+#
+# Find the curses or ncurses include file and library.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following variables:
+#
+# ``CURSES_FOUND``
+# True if Curses is found.
+# ``CURSES_INCLUDE_DIRS``
+# The include directories needed to use Curses.
+# ``CURSES_LIBRARIES``
+# The libraries needed to use Curses.
+# ``CURSES_HAVE_CURSES_H``
+# True if curses.h is available.
+# ``CURSES_HAVE_NCURSES_H``
+# True if ncurses.h is available.
+# ``CURSES_HAVE_NCURSES_NCURSES_H``
+# True if ``ncurses/ncurses.h`` is available.
+# ``CURSES_HAVE_NCURSES_CURSES_H``
+# True if ``ncurses/curses.h`` is available.
+#
+# Set ``CURSES_NEED_NCURSES`` to ``TRUE`` before the
+# ``find_package(Curses)`` call if NCurses functionality is required.
+#
+# Backward Compatibility
+# ^^^^^^^^^^^^^^^^^^^^^^
+#
+# The following variable are provided for backward compatibility:
+#
+# ``CURSES_INCLUDE_DIR``
+# Path to Curses include. Use ``CURSES_INCLUDE_DIRS`` instead.
+# ``CURSES_LIBRARY``
+# Path to Curses library. Use ``CURSES_LIBRARIES`` instead.
+
+#=============================================================================
+# Copyright 2001-2014 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.)
+
+find_library(CURSES_CURSES_LIBRARY NAMES curses )
+
+find_library(CURSES_NCURSES_LIBRARY NAMES ncurses )
+set(CURSES_USE_NCURSES FALSE)
+
+if(CURSES_NCURSES_LIBRARY AND ((NOT CURSES_CURSES_LIBRARY) OR CURSES_NEED_NCURSES))
+ set(CURSES_USE_NCURSES TRUE)
+endif()
+# http://cygwin.com/ml/cygwin-announce/2010-01/msg00002.html
+# cygwin ncurses stopped providing curses.h symlinks see above
+# message. Cygwin is an ncurses package, so force ncurses on
+# cygwin if the curses.h is missing
+if(CYGWIN)
+ if(NOT EXISTS /usr/include/curses.h)
+ set(CURSES_USE_NCURSES TRUE)
+ endif()
+endif()
+
+
+# Not sure the logic is correct here.
+# If NCurses is required, use the function wsyncup() to check if the library
+# has NCurses functionality (at least this is where it breaks on NetBSD).
+# If wsyncup is in curses, use this one.
+# If not, try to find ncurses and check if this has the symbol.
+# Once the ncurses library is found, search the ncurses.h header first, but
+# some web pages also say that even with ncurses there is not always a ncurses.h:
+# http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
+# So at first try ncurses.h, if not found, try to find curses.h under the same
+# prefix as the library was found, if still not found, try curses.h with the
+# default search paths.
+if(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
+ include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
+ cmake_push_check_state()
+ set(CMAKE_REQUIRED_QUIET ${Curses_FIND_QUIETLY})
+ CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}"
+ wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
+
+ if(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
+ CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
+ wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
+ if( CURSES_NCURSES_HAS_WSYNCUP)
+ set(CURSES_USE_NCURSES TRUE)
+ endif()
+ endif()
+ cmake_pop_check_state()
+
+endif()
+
+if(CURSES_USE_NCURSES)
+ get_filename_component(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
+ get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
+
+ # Use CURSES_NCURSES_INCLUDE_PATH if set, for compatibility.
+ if(CURSES_NCURSES_INCLUDE_PATH)
+ find_path(CURSES_INCLUDE_PATH
+ NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h
+ PATHS ${CURSES_NCURSES_INCLUDE_PATH}
+ NO_DEFAULT_PATH
+ )
+ endif()
+
+ find_path(CURSES_INCLUDE_PATH
+ NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h
+ HINTS "${_cursesParentDir}/include"
+ )
+
+ # Previous versions of FindCurses provided these values.
+ if(NOT DEFINED CURSES_LIBRARY)
+ set(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}")
+ endif()
+
+ CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
+ cbreak "" CURSES_NCURSES_HAS_CBREAK)
+ if(NOT CURSES_NCURSES_HAS_CBREAK)
+ find_library(CURSES_EXTRA_LIBRARY tinfo HINTS "${_cursesLibDir}")
+ find_library(CURSES_EXTRA_LIBRARY tinfo )
+ CHECK_LIBRARY_EXISTS("${CURSES_EXTRA_LIBRARY}"
+ cbreak "" CURSES_TINFO_HAS_CBREAK)
+ endif()
+else()
+ get_filename_component(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
+ get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
+
+ find_path(CURSES_INCLUDE_PATH
+ NAMES curses.h
+ HINTS "${_cursesParentDir}/include"
+ )
+
+ # Previous versions of FindCurses provided these values.
+ if(NOT DEFINED CURSES_CURSES_H_PATH)
+ set(CURSES_CURSES_H_PATH "${CURSES_INCLUDE_PATH}")
+ endif()
+ if(NOT DEFINED CURSES_LIBRARY)
+ set(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}")
+ endif()
+endif()
+
+# Report whether each possible header name exists in the include directory.
+if(NOT DEFINED CURSES_HAVE_NCURSES_NCURSES_H)
+ if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h")
+ set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h")
+ else()
+ set(CURSES_HAVE_NCURSES_NCURSES_H "CURSES_HAVE_NCURSES_NCURSES_H-NOTFOUND")
+ endif()
+endif()
+if(NOT DEFINED CURSES_HAVE_NCURSES_CURSES_H)
+ if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/curses.h")
+ set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncurses/curses.h")
+ else()
+ set(CURSES_HAVE_NCURSES_CURSES_H "CURSES_HAVE_NCURSES_CURSES_H-NOTFOUND")
+ endif()
+endif()
+if(NOT DEFINED CURSES_HAVE_NCURSES_H)
+ if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses.h")
+ set(CURSES_HAVE_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses.h")
+ else()
+ set(CURSES_HAVE_NCURSES_H "CURSES_HAVE_NCURSES_H-NOTFOUND")
+ endif()
+endif()
+if(NOT DEFINED CURSES_HAVE_CURSES_H)
+ if(EXISTS "${CURSES_INCLUDE_PATH}/curses.h")
+ set(CURSES_HAVE_CURSES_H "${CURSES_INCLUDE_PATH}/curses.h")
+ else()
+ set(CURSES_HAVE_CURSES_H "CURSES_HAVE_CURSES_H-NOTFOUND")
+ endif()
+endif()
+
+if (NOT CURSES_TINFO_HAS_CBREAK)
+ find_library(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}")
+ find_library(CURSES_EXTRA_LIBRARY cur_colr )
+endif()
+
+find_library(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}")
+find_library(CURSES_FORM_LIBRARY form )
+
+# Previous versions of FindCurses provided these values.
+if(NOT DEFINED FORM_LIBRARY)
+ set(FORM_LIBRARY "${CURSES_FORM_LIBRARY}")
+endif()
+
+# Need to provide the *_LIBRARIES
+set(CURSES_LIBRARIES ${CURSES_LIBRARY})
+
+if(CURSES_EXTRA_LIBRARY)
+ set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
+endif()
+
+if(CURSES_FORM_LIBRARY)
+ set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
+endif()
+
+# Provide the *_INCLUDE_DIRS result.
+set(CURSES_INCLUDE_DIRS ${CURSES_INCLUDE_PATH})
+set(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH}) # compatibility
+
+# handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
+ CURSES_LIBRARY CURSES_INCLUDE_PATH)
+
+mark_as_advanced(
+ CURSES_INCLUDE_PATH
+ CURSES_CURSES_LIBRARY
+ CURSES_NCURSES_LIBRARY
+ CURSES_EXTRA_LIBRARY
+ )
diff --git a/Modules/FindCxxTest.cmake b/Modules/FindCxxTest.cmake
new file mode 100644
index 0000000000..bc0dfbcca0
--- /dev/null
+++ b/Modules/FindCxxTest.cmake
@@ -0,0 +1,250 @@
+#.rst:
+# FindCxxTest
+# -----------
+#
+# Find CxxTest
+#
+# Find the CxxTest suite and declare a helper macro for creating unit
+# tests and integrating them with CTest. For more details on CxxTest
+# see http://cxxtest.tigris.org
+#
+# INPUT Variables
+#
+# ::
+#
+# CXXTEST_USE_PYTHON [deprecated since 1.3]
+# Only used in the case both Python & Perl
+# are detected on the system to control
+# which CxxTest code generator is used.
+# Valid only for CxxTest version 3.
+#
+#
+#
+# ::
+#
+# NOTE: In older versions of this Find Module,
+# this variable controlled if the Python test
+# generator was used instead of the Perl one,
+# regardless of which scripting language the
+# user had installed.
+#
+#
+#
+# ::
+#
+# CXXTEST_TESTGEN_ARGS (since CMake 2.8.3)
+# Specify a list of options to pass to the CxxTest code
+# generator. If not defined, --error-printer is
+# passed.
+#
+#
+#
+# OUTPUT Variables
+#
+# ::
+#
+# CXXTEST_FOUND
+# True if the CxxTest framework was found
+# CXXTEST_INCLUDE_DIRS
+# Where to find the CxxTest include directory
+# CXXTEST_PERL_TESTGEN_EXECUTABLE
+# The perl-based test generator
+# CXXTEST_PYTHON_TESTGEN_EXECUTABLE
+# The python-based test generator
+# CXXTEST_TESTGEN_EXECUTABLE (since CMake 2.8.3)
+# The test generator that is actually used (chosen using user preferences
+# and interpreters found in the system)
+# CXXTEST_TESTGEN_INTERPRETER (since CMake 2.8.3)
+# The full path to the Perl or Python executable on the system
+#
+#
+#
+# MACROS for optional use by CMake users:
+#
+# ::
+#
+# CXXTEST_ADD_TEST(<test_name> <gen_source_file> <input_files_to_testgen...>)
+# Creates a CxxTest runner and adds it to the CTest testing suite
+# Parameters:
+# test_name The name of the test
+# gen_source_file The generated source filename to be
+# generated by CxxTest
+# input_files_to_testgen The list of header files containing the
+# CxxTest::TestSuite's to be included in
+# this runner
+#
+#
+#
+# ::
+#
+# #==============
+# Example Usage:
+#
+#
+#
+# ::
+#
+# find_package(CxxTest)
+# if(CXXTEST_FOUND)
+# include_directories(${CXXTEST_INCLUDE_DIR})
+# enable_testing()
+#
+#
+#
+# ::
+#
+# CXXTEST_ADD_TEST(unittest_foo foo_test.cc
+# ${CMAKE_CURRENT_SOURCE_DIR}/foo_test.h)
+# target_link_libraries(unittest_foo foo) # as needed
+# endif()
+#
+#
+#
+# ::
+#
+# This will (if CxxTest is found):
+# 1. Invoke the testgen executable to autogenerate foo_test.cc in the
+# binary tree from "foo_test.h" in the current source directory.
+# 2. Create an executable and test called unittest_foo.
+#
+#
+#
+# ::
+#
+# #=============
+# Example foo_test.h:
+#
+#
+#
+# ::
+#
+# #include <cxxtest/TestSuite.h>
+#
+#
+#
+# ::
+#
+# class MyTestSuite : public CxxTest::TestSuite
+# {
+# public:
+# void testAddition( void )
+# {
+# TS_ASSERT( 1 + 1 > 1 );
+# TS_ASSERT_EQUALS( 1 + 1, 2 );
+# }
+# };
+
+#=============================================================================
+# Copyright 2008-2010 Kitware, Inc.
+# Copyright 2008-2010 Philip Lowman <philip@yhbt.com>
+#
+# 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.)
+
+# Version 1.4 (11/18/10) (CMake 2.8.4)
+# Issue 11384: Added support to the CXX_ADD_TEST macro so header
+# files (containing the tests themselves) show up in
+# Visual Studio and other IDEs.
+#
+# Version 1.3 (8/19/10) (CMake 2.8.3)
+# Included patch by Simone Rossetto to check if either Python or Perl
+# are present in the system. Whichever intepreter that is detected
+# is now used to run the test generator program. If both interpreters
+# are detected, the CXXTEST_USE_PYTHON variable is obeyed.
+#
+# Also added support for CXXTEST_TESTGEN_ARGS, for manually specifying
+# options to the CxxTest code generator.
+# Version 1.2 (3/2/08)
+# Included patch from Tyler Roscoe to have the perl & python binaries
+# detected based on CXXTEST_INCLUDE_DIR
+# Version 1.1 (2/9/08)
+# Clarified example to illustrate need to call target_link_libraries()
+# Changed commands to lowercase
+# Added licensing info
+# Version 1.0 (1/8/08)
+# Fixed CXXTEST_INCLUDE_DIRS so it will work properly
+# Eliminated superfluous CXXTEST_FOUND assignment
+# Cleaned up and added more documentation
+
+#=============================================================
+# CXXTEST_ADD_TEST (public macro)
+#=============================================================
+macro(CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname)
+ set(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_outfname})
+
+ add_custom_command(
+ OUTPUT ${_cxxtest_real_outfname}
+ DEPENDS ${ARGN}
+ COMMAND ${CXXTEST_TESTGEN_INTERPRETER}
+ ${CXXTEST_TESTGEN_EXECUTABLE} ${CXXTEST_TESTGEN_ARGS} -o ${_cxxtest_real_outfname} ${ARGN}
+ )
+
+ set_source_files_properties(${_cxxtest_real_outfname} PROPERTIES GENERATED true)
+ add_executable(${_cxxtest_testname} ${_cxxtest_real_outfname} ${ARGN})
+
+ if(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
+ add_test(${_cxxtest_testname} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_cxxtest_testname})
+ elseif(EXECUTABLE_OUTPUT_PATH)
+ add_test(${_cxxtest_testname} ${EXECUTABLE_OUTPUT_PATH}/${_cxxtest_testname})
+ else()
+ add_test(${_cxxtest_testname} ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_testname})
+ endif()
+
+endmacro()
+
+#=============================================================
+# main()
+#=============================================================
+if(NOT DEFINED CXXTEST_TESTGEN_ARGS)
+ set(CXXTEST_TESTGEN_ARGS --error-printer)
+endif()
+
+find_package(PythonInterp QUIET)
+find_package(Perl QUIET)
+
+find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h)
+find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE
+ NAMES cxxtestgen cxxtestgen.py
+ PATHS ${CXXTEST_INCLUDE_DIR})
+find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl
+ PATHS ${CXXTEST_INCLUDE_DIR})
+
+if(PYTHONINTERP_FOUND OR PERL_FOUND)
+ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+ if(PYTHONINTERP_FOUND AND (CXXTEST_USE_PYTHON OR NOT PERL_FOUND OR NOT DEFINED CXXTEST_USE_PYTHON))
+ set(CXXTEST_TESTGEN_EXECUTABLE ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE})
+ set(CXXTEST_TESTGEN_INTERPRETER ${PYTHON_EXECUTABLE})
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG
+ CXXTEST_INCLUDE_DIR CXXTEST_PYTHON_TESTGEN_EXECUTABLE)
+
+ elseif(PERL_FOUND)
+ set(CXXTEST_TESTGEN_EXECUTABLE ${CXXTEST_PERL_TESTGEN_EXECUTABLE})
+ set(CXXTEST_TESTGEN_INTERPRETER ${PERL_EXECUTABLE})
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG
+ CXXTEST_INCLUDE_DIR CXXTEST_PERL_TESTGEN_EXECUTABLE)
+ endif()
+
+ if(CXXTEST_FOUND)
+ set(CXXTEST_INCLUDE_DIRS ${CXXTEST_INCLUDE_DIR})
+ endif()
+
+else()
+
+ set(CXXTEST_FOUND false)
+ if(NOT CxxTest_FIND_QUIETLY)
+ if(CxxTest_FIND_REQUIRED)
+ message(FATAL_ERROR "Neither Python nor Perl found, cannot use CxxTest, aborting!")
+ else()
+ message(STATUS "Neither Python nor Perl found, CxxTest will not be used.")
+ endif()
+ endif()
+
+endif()
diff --git a/Modules/FindCygwin.cmake b/Modules/FindCygwin.cmake
new file mode 100644
index 0000000000..5cb533b0b8
--- /dev/null
+++ b/Modules/FindCygwin.cmake
@@ -0,0 +1,31 @@
+#.rst:
+# FindCygwin
+# ----------
+#
+# this module looks for Cygwin
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+if (WIN32)
+ find_path(CYGWIN_INSTALL_PATH
+ cygwin.bat
+ "C:/Cygwin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup;rootdir]"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/;native]"
+ )
+
+ mark_as_advanced(
+ CYGWIN_INSTALL_PATH
+ )
+endif ()
diff --git a/Modules/FindDCMTK.cmake b/Modules/FindDCMTK.cmake
new file mode 100644
index 0000000000..91aafbbd02
--- /dev/null
+++ b/Modules/FindDCMTK.cmake
@@ -0,0 +1,157 @@
+#.rst:
+# FindDCMTK
+# ---------
+#
+# find DCMTK libraries and applications
+
+# 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/)
+
+#=============================================================================
+# Copyright 2004-2009 Kitware, Inc.
+# Copyright 2009-2010 Mathieu Malaterre <mathieu.malaterre@gmail.com>
+# Copyright 2010 Thomas Sondergaard <ts@medical-insight.com>
+#
+# 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.)
+
+#
+# Written for VXL by Amitha Perera.
+# Upgraded for GDCM by Mathieu Malaterre.
+# 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)
+endif()
+
+
+foreach(lib
+ dcmdata
+ dcmimage
+ dcmimgle
+ dcmjpeg
+ dcmnet
+ dcmpstat
+ dcmqrdb
+ dcmsign
+ dcmsr
+ dcmtls
+ ijg12
+ ijg16
+ ijg8
+ ofstd)
+
+ find_library(DCMTK_${lib}_LIBRARY
+ ${lib}
+ PATHS
+ ${DCMTK_DIR}/${lib}/libsrc
+ ${DCMTK_DIR}/${lib}/libsrc/Release
+ ${DCMTK_DIR}/${lib}/libsrc/Debug
+ ${DCMTK_DIR}/${lib}/Release
+ ${DCMTK_DIR}/${lib}/Debug
+ ${DCMTK_DIR}/lib)
+
+ mark_as_advanced(DCMTK_${lib}_LIBRARY)
+
+ if(DCMTK_${lib}_LIBRARY)
+ list(APPEND DCMTK_LIBRARIES ${DCMTK_${lib}_LIBRARY})
+ endif()
+
+endforeach()
+
+
+set(DCMTK_config_TEST_HEADER osconfig.h)
+set(DCMTK_dcmdata_TEST_HEADER dctypes.h)
+set(DCMTK_dcmimage_TEST_HEADER dicoimg.h)
+set(DCMTK_dcmimgle_TEST_HEADER dcmimage.h)
+set(DCMTK_dcmjpeg_TEST_HEADER djdecode.h)
+set(DCMTK_dcmnet_TEST_HEADER assoc.h)
+set(DCMTK_dcmpstat_TEST_HEADER dcmpstat.h)
+set(DCMTK_dcmqrdb_TEST_HEADER dcmqrdba.h)
+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)
+
+foreach(dir
+ config
+ dcmdata
+ dcmimage
+ dcmimgle
+ dcmjpeg
+ dcmnet
+ dcmpstat
+ dcmqrdb
+ dcmsign
+ dcmsr
+ dcmtls
+ ofstd)
+ 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}
+ )
+ mark_as_advanced(DCMTK_${dir}_INCLUDE_DIR)
+
+ if(DCMTK_${dir}_INCLUDE_DIR)
+ list(APPEND
+ DCMTK_INCLUDE_DIRS
+ ${DCMTK_${dir}_INCLUDE_DIR})
+ endif()
+endforeach()
+
+if(WIN32)
+ list(APPEND DCMTK_LIBRARIES netapi32 wsock32)
+endif()
+
+if(DCMTK_ofstd_INCLUDE_DIR)
+ get_filename_component(DCMTK_dcmtk_INCLUDE_DIR
+ ${DCMTK_ofstd_INCLUDE_DIR}
+ PATH
+ CACHE)
+ list(APPEND DCMTK_INCLUDE_DIRS ${DCMTK_dcmtk_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()
diff --git a/Modules/FindDart.cmake b/Modules/FindDart.cmake
new file mode 100644
index 0000000000..ea01fc2230
--- /dev/null
+++ b/Modules/FindDart.cmake
@@ -0,0 +1,44 @@
+#.rst:
+# FindDart
+# --------
+#
+# Find DART
+#
+# This module looks for the dart testing software and sets DART_ROOT to
+# point to where it found it.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+find_path(DART_ROOT README.INSTALL
+ HINTS
+ ENV DART_ROOT
+ PATHS
+ ${PROJECT_SOURCE_DIR}
+ /usr/share
+ C:/
+ "C:/Program Files"
+ ${PROJECT_SOURCE_DIR}/..
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Dart\\InstallPath]
+ ENV ProgramFiles
+ PATH_SUFFIXES
+ Dart
+ DOC "If you have Dart installed, where is it located?"
+ )
+
+# handle the QUIETLY and REQUIRED arguments and set DART_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Dart DEFAULT_MSG DART_ROOT)
+
+mark_as_advanced(DART_ROOT)
diff --git a/Modules/FindDevIL.cmake b/Modules/FindDevIL.cmake
new file mode 100644
index 0000000000..865d061c51
--- /dev/null
+++ b/Modules/FindDevIL.cmake
@@ -0,0 +1,83 @@
+#.rst:
+# FindDevIL
+# ---------
+#
+#
+#
+# This module locates the developer's image library.
+# http://openil.sourceforge.net/
+#
+# This module sets:
+#
+# ::
+#
+# IL_LIBRARIES - the name of the IL library. These include the full path to
+# the core DevIL library. This one has to be linked into the
+# application.
+# ILU_LIBRARIES - the name of the ILU library. Again, the full path. This
+# library is for filters and effects, not actual loading. It
+# doesn't have to be linked if the functionality it provides
+# is not used.
+# ILUT_LIBRARIES - the name of the ILUT library. Full path. This part of the
+# library interfaces with OpenGL. It is not strictly needed
+# in applications.
+# IL_INCLUDE_DIR - where to find the il.h, ilu.h and ilut.h files.
+# IL_FOUND - this is set to TRUE if all the above variables were set.
+# This will be set to false if ILU or ILUT are not found,
+# even if they are not needed. In most systems, if one
+# library is found all the others are as well. That's the
+# way the DevIL developers release it.
+
+#=============================================================================
+# Copyright 2008-2009 Kitware, Inc.
+# Copyright 2008 Christopher Harvey
+#
+# 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.)
+
+# TODO: Add version support.
+# Tested under Linux and Windows (MSVC)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+find_path(IL_INCLUDE_DIR il.h
+ PATH_SUFFIXES include IL
+ DOC "The path to the directory that contains il.h"
+)
+
+#message("IL_INCLUDE_DIR is ${IL_INCLUDE_DIR}")
+
+find_library(IL_LIBRARIES
+ NAMES IL DEVIL
+ PATH_SUFFIXES lib64 lib lib32
+ DOC "The file that corresponds to the base il library."
+)
+
+#message("IL_LIBRARIES is ${IL_LIBRARIES}")
+
+find_library(ILUT_LIBRARIES
+ NAMES ILUT
+ PATH_SUFFIXES lib64 lib lib32
+ DOC "The file that corresponds to the il (system?) utility library."
+)
+
+#message("ILUT_LIBRARIES is ${ILUT_LIBRARIES}")
+
+find_library(ILU_LIBRARIES
+ NAMES ILU
+ PATH_SUFFIXES lib64 lib lib32
+ DOC "The file that corresponds to the il utility library."
+)
+
+#message("ILU_LIBRARIES is ${ILU_LIBRARIES}")
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(IL DEFAULT_MSG
+ IL_LIBRARIES ILU_LIBRARIES
+ ILUT_LIBRARIES IL_INCLUDE_DIR)
diff --git a/Modules/FindDoxygen.cmake b/Modules/FindDoxygen.cmake
new file mode 100644
index 0000000000..d34941aa2c
--- /dev/null
+++ b/Modules/FindDoxygen.cmake
@@ -0,0 +1,171 @@
+#.rst:
+# FindDoxygen
+# -----------
+#
+# This module looks for Doxygen and the path to Graphviz's dot
+#
+# Doxygen is a documentation generation tool. Please see
+# http://www.doxygen.org
+#
+# This module accepts the following optional variables:
+#
+# ::
+#
+# DOXYGEN_SKIP_DOT = If true this module will skip trying to find Dot
+# (an optional component often used by Doxygen)
+#
+#
+#
+# This modules defines the following variables:
+#
+# ::
+#
+# DOXYGEN_EXECUTABLE = The path to the doxygen command.
+# DOXYGEN_FOUND = Was Doxygen found or not?
+# DOXYGEN_VERSION = The version reported by doxygen --version
+#
+#
+#
+# ::
+#
+# DOXYGEN_DOT_EXECUTABLE = The path to the dot program used by doxygen.
+# DOXYGEN_DOT_FOUND = Was Dot found or not?
+#
+# For compatibility with older versions of CMake, the now-deprecated
+# variable ``DOXYGEN_DOT_PATH`` is set to the path to the directory
+# containing ``dot`` as reported in ``DOXYGEN_DOT_EXECUTABLE``.
+# The path may have forward slashes even on Windows and is not
+# suitable for direct substitution into a ``Doxyfile.in`` template.
+# If you need this value, use :command:`get_filename_component`
+# to compute it from ``DOXYGEN_DOT_EXECUTABLE`` directly, and
+# perhaps the :command:`file(TO_NATIVE_PATH)` command to prepare
+# the path for a Doxygen configuration file.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+# For backwards compatibility support
+if(Doxygen_FIND_QUIETLY)
+ set(DOXYGEN_FIND_QUIETLY TRUE)
+endif()
+
+# ===== Rationale for OS X AppBundle mods below =====
+# With the OS X GUI version, Doxygen likes to be installed to /Applications and
+# it contains the doxygen executable in the bundle. In the versions I've
+# seen, it is located in Resources, but in general, more often binaries are
+# located in MacOS.
+#
+# NOTE: The official Doxygen.app that is distributed for OS X uses non-standard
+# conventions. Instead of the command-line "doxygen" tool being placed in
+# Doxygen.app/Contents/MacOS, "Doxywizard" is placed there instead and
+# "doxygen" is placed in Contents/Resources. This is most likely done
+# so that something happens when people double-click on the Doxygen.app
+# package. Unfortunately, CMake gets confused by this as when it sees the
+# bundle it uses "Doxywizard" as the executable to use instead of
+# "doxygen". Therefore to work-around this issue we temporarily disable
+# the app-bundle feature, just for this CMake module:
+if(APPLE)
+ # Save the old setting
+ set(TEMP_DOXYGEN_SAVE_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
+ # Disable the App-bundle detection feature
+ set(CMAKE_FIND_APPBUNDLE "NEVER")
+endif()
+# FYI:
+# In the older versions of OS X Doxygen, dot was included with the
+# Doxygen bundle. But the new versions require you to download
+# Graphviz.app which contains "dot" in it's bundle.
+# ============== End OSX stuff ================
+
+#
+# Find Doxygen...
+#
+
+find_program(DOXYGEN_EXECUTABLE
+ NAMES doxygen
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\doxygen_is1;Inno Setup: App Path]/bin"
+ /Applications/Doxygen.app/Contents/Resources
+ /Applications/Doxygen.app/Contents/MacOS
+ DOC "Doxygen documentation generation tool (http://www.doxygen.org)"
+)
+
+if(DOXYGEN_EXECUTABLE)
+ execute_process(COMMAND ${DOXYGEN_EXECUTABLE} "--version" OUTPUT_VARIABLE DOXYGEN_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Doxygen REQUIRED_VARS DOXYGEN_EXECUTABLE VERSION_VAR DOXYGEN_VERSION)
+
+#
+# Find Dot...
+#
+
+set(_x86 "(x86)")
+file(GLOB _Doxygen_GRAPHVIZ_BIN_DIRS
+ "$ENV{ProgramFiles}/Graphviz*/bin"
+ "$ENV{ProgramFiles${_x86}}/Graphviz*/bin"
+ )
+unset(_x86)
+
+if(NOT DOXYGEN_SKIP_DOT)
+ find_program(DOXYGEN_DOT_EXECUTABLE
+ NAMES dot
+ PATHS
+ ${_Doxygen_GRAPHVIZ_BIN_DIRS}
+ "$ENV{ProgramFiles}/ATT/Graphviz/bin"
+ "C:/Program Files/ATT/Graphviz/bin"
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\ATT\\Graphviz;InstallPath]/bin
+ /Applications/Graphviz.app/Contents/MacOS
+ /Applications/Doxygen.app/Contents/Resources
+ /Applications/Doxygen.app/Contents/MacOS
+ DOC "Graphviz Dot tool for using Doxygen"
+ )
+
+ if(DOXYGEN_DOT_EXECUTABLE)
+ set(DOXYGEN_DOT_FOUND TRUE)
+ # The Doxyfile wants the path to Dot, not the entire path and executable
+ get_filename_component(DOXYGEN_DOT_PATH "${DOXYGEN_DOT_EXECUTABLE}" PATH)
+ endif()
+
+endif()
+
+#
+# Backwards compatibility...
+#
+
+if(APPLE)
+ # Restore the old app-bundle setting setting
+ set(CMAKE_FIND_APPBUNDLE ${TEMP_DOXYGEN_SAVE_CMAKE_FIND_APPBUNDLE})
+endif()
+
+# Maintain the _FOUND variables as "YES" or "NO" for backwards compatibility
+# (allows people to stuff them directly into Doxyfile with configure_file())
+if(DOXYGEN_FOUND)
+ set(DOXYGEN_FOUND "YES")
+else()
+ set(DOXYGEN_FOUND "NO")
+endif()
+if(DOXYGEN_DOT_FOUND)
+ set(DOXYGEN_DOT_FOUND "YES")
+else()
+ set(DOXYGEN_DOT_FOUND "NO")
+endif()
+
+# For backwards compatibility support
+set (DOXYGEN ${DOXYGEN_EXECUTABLE} )
+set (DOT ${DOXYGEN_DOT_EXECUTABLE} )
+
+mark_as_advanced(
+ DOXYGEN_EXECUTABLE
+ DOXYGEN_DOT_EXECUTABLE
+ )
diff --git a/Modules/FindEXPAT.cmake b/Modules/FindEXPAT.cmake
new file mode 100644
index 0000000000..653094cd32
--- /dev/null
+++ b/Modules/FindEXPAT.cmake
@@ -0,0 +1,66 @@
+#.rst:
+# FindEXPAT
+# ---------
+#
+# Find expat
+#
+# Find the native EXPAT headers and libraries.
+#
+# ::
+#
+# EXPAT_INCLUDE_DIRS - where to find expat.h, etc.
+# EXPAT_LIBRARIES - List of libraries when using expat.
+# EXPAT_FOUND - True if expat found.
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+# Look for the header file.
+find_path(EXPAT_INCLUDE_DIR NAMES expat.h)
+
+# Look for the library.
+find_library(EXPAT_LIBRARY NAMES expat libexpat)
+
+if (EXPAT_INCLUDE_DIR AND EXISTS "${EXPAT_INCLUDE_DIR}/expat.h")
+ file(STRINGS "${EXPAT_INCLUDE_DIR}/expat.h" expat_version_str
+ REGEX "^#[\t ]*define[\t ]+XML_(MAJOR|MINOR|MICRO)_VERSION[\t ]+[0-9]+$")
+
+ unset(EXPAT_VERSION_STRING)
+ foreach(VPART MAJOR MINOR MICRO)
+ foreach(VLINE ${expat_version_str})
+ if(VLINE MATCHES "^#[\t ]*define[\t ]+XML_${VPART}_VERSION[\t ]+([0-9]+)$")
+ set(EXPAT_VERSION_PART "${CMAKE_MATCH_1}")
+ if(EXPAT_VERSION_STRING)
+ set(EXPAT_VERSION_STRING "${EXPAT_VERSION_STRING}.${EXPAT_VERSION_PART}")
+ else()
+ set(EXPAT_VERSION_STRING "${EXPAT_VERSION_PART}")
+ endif()
+ endif()
+ endforeach()
+ endforeach()
+endif ()
+
+# handle the QUIETLY and REQUIRED arguments and set EXPAT_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT
+ REQUIRED_VARS EXPAT_LIBRARY EXPAT_INCLUDE_DIR
+ VERSION_VAR EXPAT_VERSION_STRING)
+
+# Copy the results to the output variables.
+if(EXPAT_FOUND)
+ set(EXPAT_LIBRARIES ${EXPAT_LIBRARY})
+ set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR})
+endif()
+
+mark_as_advanced(EXPAT_INCLUDE_DIR EXPAT_LIBRARY)
diff --git a/Modules/FindFLEX.cmake b/Modules/FindFLEX.cmake
new file mode 100644
index 0000000000..c837c52c7e
--- /dev/null
+++ b/Modules/FindFLEX.cmake
@@ -0,0 +1,202 @@
+#.rst:
+# FindFLEX
+# --------
+#
+# Find flex executable and provides a macro to generate custom build rules
+#
+#
+#
+# The module defines the following variables:
+#
+# ::
+#
+# FLEX_FOUND - true is flex executable is found
+# FLEX_EXECUTABLE - the path to the flex executable
+# FLEX_VERSION - the version of flex
+# FLEX_LIBRARIES - The flex libraries
+# FLEX_INCLUDE_DIRS - The path to the flex headers
+#
+#
+#
+# The minimum required version of flex can be specified using the
+# standard syntax, e.g. find_package(FLEX 2.5.13)
+#
+#
+#
+# If flex is found on the system, the module provides the macro:
+#
+# ::
+#
+# FLEX_TARGET(Name FlexInput FlexOutput [COMPILE_FLAGS <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:
+#
+# ::
+#
+# FLEX_${Name}_DEFINED - true is the macro ran successfully
+# 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 scanners oftenly use tokens defined by Bison: the code generated
+# by Flex depends of the header generated by Bison. This module also
+# defines a macro:
+#
+# ::
+#
+# ADD_FLEX_BISON_DEPENDENCY(FlexTarget BisonTarget)
+#
+# which adds the required dependency between a scanner and a parser
+# where <FlexTarget> and <BisonTarget> are the first parameters of
+# respectively FLEX_TARGET and BISON_TARGET macros.
+#
+# ::
+#
+# ====================================================================
+# Example:
+#
+#
+#
+# ::
+#
+# find_package(BISON)
+# find_package(FLEX)
+#
+#
+#
+# ::
+#
+# BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
+# FLEX_TARGET(MyScanner lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp)
+# ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)
+#
+#
+#
+# ::
+#
+# include_directories(${CMAKE_CURRENT_BINARY_DIR})
+# add_executable(Foo
+# Foo.cc
+# ${BISON_MyParser_OUTPUTS}
+# ${FLEX_MyScanner_OUTPUTS}
+# )
+# ====================================================================
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2006 Tristan Carel
+#
+# 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.)
+
+find_program(FLEX_EXECUTABLE NAMES flex win_flex DOC "path to the flex executable")
+mark_as_advanced(FLEX_EXECUTABLE)
+
+find_library(FL_LIBRARY NAMES fl
+ DOC "Path to the fl library")
+
+find_path(FLEX_INCLUDE_DIR FlexLexer.h
+ DOC "Path to the flex headers")
+
+mark_as_advanced(FL_LIBRARY FLEX_INCLUDE_DIR)
+
+set(FLEX_INCLUDE_DIRS ${FLEX_INCLUDE_DIR})
+set(FLEX_LIBRARIES ${FL_LIBRARY})
+
+if(FLEX_EXECUTABLE)
+
+ execute_process(COMMAND ${FLEX_EXECUTABLE} --version
+ OUTPUT_VARIABLE FLEX_version_output
+ ERROR_VARIABLE FLEX_version_error
+ RESULT_VARIABLE FLEX_version_result
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if(NOT ${FLEX_version_result} EQUAL 0)
+ if(FLEX_FIND_REQUIRED)
+ message(SEND_ERROR "Command \"${FLEX_EXECUTABLE} --version\" failed with output:\n${FLEX_version_output}\n${FLEX_version_error}")
+ else()
+ message("Command \"${FLEX_EXECUTABLE} --version\" failed with output:\n${FLEX_version_output}\n${FLEX_version_error}\nFLEX_VERSION will not be available")
+ endif()
+ else()
+ # older versions of flex printed "/full/path/to/executable version X.Y"
+ # newer versions use "basename(executable) X.Y"
+ get_filename_component(FLEX_EXE_NAME_WE "${FLEX_EXECUTABLE}" NAME_WE)
+ get_filename_component(FLEX_EXE_EXT "${FLEX_EXECUTABLE}" EXT)
+ string(REGEX REPLACE "^.*${FLEX_EXE_NAME_WE}(${FLEX_EXE_EXT})?\"? (version )?([0-9]+[^ ]*)( .*)?$" "\\3"
+ FLEX_VERSION "${FLEX_version_output}")
+ unset(FLEX_EXE_EXT)
+ unset(FLEX_EXE_NAME_WE)
+ endif()
+
+ #============================================================
+ # FLEX_TARGET (public macro)
+ #============================================================
+ #
+ 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()
+ else()
+ message(SEND_ERROR ${FLEX_TARGET_usage})
+ 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()
+ #============================================================
+
+
+ #============================================================
+ # ADD_FLEX_BISON_DEPENDENCY (public macro)
+ #============================================================
+ #
+ macro(ADD_FLEX_BISON_DEPENDENCY FlexTarget BisonTarget)
+
+ if(NOT FLEX_${FlexTarget}_OUTPUTS)
+ message(SEND_ERROR "Flex target `${FlexTarget}' does not exists.")
+ endif()
+
+ if(NOT BISON_${BisonTarget}_OUTPUT_HEADER)
+ message(SEND_ERROR "Bison target `${BisonTarget}' does not exists.")
+ endif()
+
+ set_source_files_properties(${FLEX_${FlexTarget}_OUTPUTS}
+ PROPERTIES OBJECT_DEPENDS ${BISON_${BisonTarget}_OUTPUT_HEADER})
+ endmacro()
+ #============================================================
+
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLEX REQUIRED_VARS FLEX_EXECUTABLE
+ VERSION_VAR FLEX_VERSION)
+
+# FindFLEX.cmake ends here
diff --git a/Modules/FindFLTK.cmake b/Modules/FindFLTK.cmake
new file mode 100644
index 0000000000..76f702e2b6
--- /dev/null
+++ b/Modules/FindFLTK.cmake
@@ -0,0 +1,334 @@
+#.rst:
+# FindFLTK
+# --------
+#
+# Find the native FLTK includes and library
+#
+#
+#
+# By default FindFLTK.cmake will search for all of the FLTK components
+# and add them to the FLTK_LIBRARIES variable.
+#
+# ::
+#
+# You can limit the components which get placed in FLTK_LIBRARIES by
+# defining one or more of the following three options:
+#
+#
+#
+# ::
+#
+# FLTK_SKIP_OPENGL, set to true to disable searching for opengl and
+# the FLTK GL library
+# FLTK_SKIP_FORMS, set to true to disable searching for fltk_forms
+# FLTK_SKIP_IMAGES, set to true to disable searching for fltk_images
+#
+#
+#
+# ::
+#
+# FLTK_SKIP_FLUID, set to true if the fluid binary need not be present
+# at build time
+#
+#
+#
+# The following variables will be defined:
+#
+# ::
+#
+# FLTK_FOUND, True if all components not skipped were found
+# FLTK_INCLUDE_DIR, where to find include files
+# FLTK_LIBRARIES, list of fltk libraries you should link against
+# FLTK_FLUID_EXECUTABLE, where to find the Fluid tool
+# FLTK_WRAP_UI, This enables the FLTK_WRAP_UI command
+#
+#
+#
+# The following cache variables are assigned but should not be used.
+# See the FLTK_LIBRARIES variable instead.
+#
+# ::
+#
+# FLTK_BASE_LIBRARY = the full path to fltk.lib
+# FLTK_GL_LIBRARY = the full path to fltk_gl.lib
+# FLTK_FORMS_LIBRARY = the full path to fltk_forms.lib
+# FLTK_IMAGES_LIBRARY = the full path to fltk_images.lib
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+if(NOT FLTK_SKIP_OPENGL)
+ find_package(OpenGL)
+endif()
+
+# Platform dependent libraries required by FLTK
+if(WIN32)
+ if(NOT CYGWIN)
+ if(BORLAND)
+ set( FLTK_PLATFORM_DEPENDENT_LIBS import32 )
+ else()
+ set( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
+ endif()
+ endif()
+endif()
+
+if(UNIX)
+ include(${CMAKE_CURRENT_LIST_DIR}/FindX11.cmake)
+ find_library(FLTK_MATH_LIBRARY m)
+ set( FLTK_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} ${FLTK_MATH_LIBRARY})
+endif()
+
+if(APPLE)
+ set( FLTK_PLATFORM_DEPENDENT_LIBS "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
+endif()
+
+# If FLTK_INCLUDE_DIR is already defined we assigne its value to FLTK_DIR
+if(FLTK_INCLUDE_DIR)
+ set(FLTK_DIR ${FLTK_INCLUDE_DIR})
+endif()
+
+
+# If FLTK has been built using CMake we try to find everything directly
+set(FLTK_DIR_STRING "directory containing FLTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
+
+# Search only if the location is not already known.
+if(NOT FLTK_DIR)
+ # Get the system search path as a list.
+ file(TO_CMAKE_PATH "$ENV{PATH}" FLTK_DIR_SEARCH2)
+
+ # Construct a set of paths relative to the system search path.
+ set(FLTK_DIR_SEARCH "")
+ foreach(dir ${FLTK_DIR_SEARCH2})
+ set(FLTK_DIR_SEARCH ${FLTK_DIR_SEARCH} "${dir}/../lib/fltk")
+ endforeach()
+ string(REPLACE "//" "/" FLTK_DIR_SEARCH "${FLTK_DIR_SEARCH}")
+
+ #
+ # Look for an installation or build tree.
+ #
+ find_path(FLTK_DIR FLTKConfig.cmake
+ # Look for an environment variable FLTK_DIR.
+ HINTS
+ ENV FLTK_DIR
+
+ # Look in places relative to the system executable search path.
+ ${FLTK_DIR_SEARCH}
+
+ PATHS
+ # Look in standard UNIX install locations.
+ /usr/local/lib/fltk
+ /usr/lib/fltk
+ /usr/local/fltk
+ /usr/X11R6/include
+
+ # Read from the CMakeSetup registry entries. It is likely that
+ # FLTK will have been recently built.
+ # TODO: Is this really a good idea? I can already hear the user screaming, "But
+ # it worked when I configured the build LAST week!"
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
+
+ # Help the user find it if we cannot.
+ DOC "The ${FLTK_DIR_STRING}"
+ )
+endif()
+
+ # Check if FLTK was built using CMake
+ if(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
+ set(FLTK_BUILT_WITH_CMAKE 1)
+ endif()
+
+ if(FLTK_BUILT_WITH_CMAKE)
+ set(FLTK_FOUND 1)
+ include(${FLTK_DIR}/FLTKConfig.cmake)
+
+ # Fluid
+ if(FLUID_COMMAND)
+ set(FLTK_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
+ else()
+ find_program(FLTK_FLUID_EXECUTABLE fluid PATHS
+ ${FLTK_EXECUTABLE_DIRS}
+ ${FLTK_EXECUTABLE_DIRS}/RelWithDebInfo
+ ${FLTK_EXECUTABLE_DIRS}/Debug
+ ${FLTK_EXECUTABLE_DIRS}/Release
+ NO_SYSTEM_PATH)
+ endif()
+ # mark_as_advanced(FLTK_FLUID_EXECUTABLE)
+
+ set(FLTK_INCLUDE_DIR ${FLTK_DIR})
+ link_directories(${FLTK_LIBRARY_DIRS})
+
+ set(FLTK_BASE_LIBRARY fltk)
+ set(FLTK_GL_LIBRARY fltk_gl)
+ set(FLTK_FORMS_LIBRARY fltk_forms)
+ set(FLTK_IMAGES_LIBRARY fltk_images)
+
+ # Add the extra libraries
+ load_cache(${FLTK_DIR}
+ READ_WITH_PREFIX
+ FL FLTK_USE_SYSTEM_JPEG
+ FL FLTK_USE_SYSTEM_PNG
+ FL FLTK_USE_SYSTEM_ZLIB
+ )
+
+ set(FLTK_IMAGES_LIBS "")
+ if(FLFLTK_USE_SYSTEM_JPEG)
+ set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_jpeg)
+ endif()
+ if(FLFLTK_USE_SYSTEM_PNG)
+ set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_png)
+ endif()
+ if(FLFLTK_USE_SYSTEM_ZLIB)
+ set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_zlib)
+ endif()
+ set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
+ "Extra libraries for fltk_images library.")
+
+ else()
+
+ # if FLTK was not built using CMake
+ # Find fluid executable.
+ find_program(FLTK_FLUID_EXECUTABLE fluid ${FLTK_INCLUDE_DIR}/fluid)
+
+ # Use location of fluid to help find everything else.
+ set(FLTK_INCLUDE_SEARCH_PATH "")
+ set(FLTK_LIBRARY_SEARCH_PATH "")
+ if(FLTK_FLUID_EXECUTABLE)
+ get_filename_component(FLTK_BIN_DIR "${FLTK_FLUID_EXECUTABLE}" PATH)
+ set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
+ ${FLTK_BIN_DIR}/../include ${FLTK_BIN_DIR}/..)
+ set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
+ ${FLTK_BIN_DIR}/../lib)
+ set(FLTK_WRAP_UI 1)
+ endif()
+
+ #
+ # Try to find FLTK include dir using fltk-config
+ #
+ if(UNIX)
+ # Use fltk-config to generate a list of possible include directories
+ find_program(FLTK_CONFIG_SCRIPT fltk-config PATHS ${FLTK_BIN_DIR})
+ if(FLTK_CONFIG_SCRIPT)
+ if(NOT FLTK_INCLUDE_DIR)
+ exec_program(${FLTK_CONFIG_SCRIPT} ARGS --cxxflags OUTPUT_VARIABLE FLTK_CXXFLAGS)
+ if(FLTK_CXXFLAGS)
+ string(REGEX MATCHALL "-I[^ ]*" _fltk_temp_dirs ${FLTK_CXXFLAGS})
+ string(REPLACE "-I" "" _fltk_temp_dirs "${_fltk_temp_dirs}")
+ foreach(_dir ${_fltk_temp_dirs})
+ string(STRIP ${_dir} _output)
+ list(APPEND _FLTK_POSSIBLE_INCLUDE_DIRS ${_output})
+ endforeach()
+ endif()
+ endif()
+ endif()
+ endif()
+
+ set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
+ /usr/local/fltk
+ /usr/X11R6/include
+ ${_FLTK_POSSIBLE_INCLUDE_DIRS}
+ )
+
+ find_path(FLTK_INCLUDE_DIR
+ NAMES FL/Fl.h FL/Fl.H # fltk 1.1.9 has Fl.H (#8376)
+ PATHS ${FLTK_INCLUDE_SEARCH_PATH})
+
+ #
+ # Try to find FLTK library
+ if(UNIX)
+ if(FLTK_CONFIG_SCRIPT)
+ exec_program(${FLTK_CONFIG_SCRIPT} ARGS --libs OUTPUT_VARIABLE _FLTK_POSSIBLE_LIBS)
+ if(_FLTK_POSSIBLE_LIBS)
+ get_filename_component(_FLTK_POSSIBLE_LIBRARY_DIR ${_FLTK_POSSIBLE_LIBS} PATH)
+ endif()
+ endif()
+ endif()
+
+ set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
+ /usr/local/fltk/lib
+ /usr/X11R6/lib
+ ${FLTK_INCLUDE_DIR}/lib
+ ${_FLTK_POSSIBLE_LIBRARY_DIR}
+ )
+
+ find_library(FLTK_BASE_LIBRARY NAMES fltk fltkd
+ PATHS ${FLTK_LIBRARY_SEARCH_PATH})
+ find_library(FLTK_GL_LIBRARY NAMES fltkgl fltkgld fltk_gl
+ PATHS ${FLTK_LIBRARY_SEARCH_PATH})
+ find_library(FLTK_FORMS_LIBRARY NAMES fltkforms fltkformsd fltk_forms
+ PATHS ${FLTK_LIBRARY_SEARCH_PATH})
+ find_library(FLTK_IMAGES_LIBRARY NAMES fltkimages fltkimagesd fltk_images
+ PATHS ${FLTK_LIBRARY_SEARCH_PATH})
+
+ # Find the extra libraries needed for the fltk_images library.
+ if(UNIX)
+ if(FLTK_CONFIG_SCRIPT)
+ exec_program(${FLTK_CONFIG_SCRIPT} ARGS --use-images --ldflags
+ OUTPUT_VARIABLE FLTK_IMAGES_LDFLAGS)
+ set(FLTK_LIBS_EXTRACT_REGEX ".*-lfltk_images (.*) -lfltk.*")
+ if("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
+ string(REGEX REPLACE " +" ";" FLTK_IMAGES_LIBS "${CMAKE_MATCH_1}")
+ # The EXEC_PROGRAM will not be inherited into subdirectories from
+ # the file that originally included this module. Save the answer.
+ set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
+ "Extra libraries for fltk_images library.")
+ endif()
+ endif()
+ endif()
+
+ endif()
+
+ # Append all of the required libraries together (by default, everything)
+ set(FLTK_LIBRARIES)
+ if(NOT FLTK_SKIP_IMAGES)
+ list(APPEND FLTK_LIBRARIES ${FLTK_IMAGES_LIBRARY})
+ endif()
+ if(NOT FLTK_SKIP_FORMS)
+ list(APPEND FLTK_LIBRARIES ${FLTK_FORMS_LIBRARY})
+ endif()
+ if(NOT FLTK_SKIP_OPENGL)
+ list(APPEND FLTK_LIBRARIES ${FLTK_GL_LIBRARY} ${OPENGL_gl_LIBRARY})
+ list(APPEND FLTK_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
+ list(REMOVE_DUPLICATES FLTK_INCLUDE_DIR)
+ endif()
+ list(APPEND FLTK_LIBRARIES ${FLTK_BASE_LIBRARY})
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+if(FLTK_SKIP_FLUID)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR)
+else()
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR FLTK_FLUID_EXECUTABLE)
+endif()
+
+if(FLTK_FOUND)
+ if(APPLE)
+ set(FLTK_LIBRARIES ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES})
+ else()
+ set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_PLATFORM_DEPENDENT_LIBS})
+ endif()
+
+ # The following deprecated settings are for compatibility with CMake 1.4
+ set (HAS_FLTK ${FLTK_FOUND})
+ set (FLTK_INCLUDE_PATH ${FLTK_INCLUDE_DIR})
+ set (FLTK_FLUID_EXE ${FLTK_FLUID_EXECUTABLE})
+ set (FLTK_LIBRARY ${FLTK_LIBRARIES})
+endif()
+
diff --git a/Modules/FindFLTK2.cmake b/Modules/FindFLTK2.cmake
new file mode 100644
index 0000000000..930accabf5
--- /dev/null
+++ b/Modules/FindFLTK2.cmake
@@ -0,0 +1,277 @@
+#.rst:
+# FindFLTK2
+# ---------
+#
+# Find the native FLTK2 includes and library
+#
+# The following settings are defined
+#
+# ::
+#
+# FLTK2_FLUID_EXECUTABLE, where to find the Fluid tool
+# FLTK2_WRAP_UI, This enables the FLTK2_WRAP_UI command
+# FLTK2_INCLUDE_DIR, where to find include files
+# FLTK2_LIBRARIES, list of fltk2 libraries
+# FLTK2_FOUND, Don't use FLTK2 if false.
+#
+# The following settings should not be used in general.
+#
+# ::
+#
+# FLTK2_BASE_LIBRARY = the full path to fltk2.lib
+# FLTK2_GL_LIBRARY = the full path to fltk2_gl.lib
+# FLTK2_IMAGES_LIBRARY = the full path to fltk2_images.lib
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+set (FLTK2_DIR $ENV{FLTK2_DIR} )
+
+# Platform dependent libraries required by FLTK2
+if(WIN32)
+ if(NOT CYGWIN)
+ if(BORLAND)
+ set( FLTK2_PLATFORM_DEPENDENT_LIBS import32 )
+ else()
+ set( FLTK2_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
+ endif()
+ endif()
+endif()
+
+if(UNIX)
+ include(${CMAKE_ROOT}/Modules/FindX11.cmake)
+ set( FLTK2_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} -lm)
+endif()
+
+if(APPLE)
+ set( FLTK2_PLATFORM_DEPENDENT_LIBS "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
+endif()
+
+# If FLTK2_INCLUDE_DIR is already defined we assign its value to FLTK2_DIR
+if(FLTK2_INCLUDE_DIR)
+ set(FLTK2_DIR ${FLTK2_INCLUDE_DIR})
+else()
+ set(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
+endif()
+
+
+# If FLTK2 has been built using CMake we try to find everything directly
+set(FLTK2_DIR_STRING "directory containing FLTK2Config.cmake. This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
+
+# Search only if the location is not already known.
+if(NOT FLTK2_DIR)
+ # Get the system search path as a list.
+ file(TO_CMAKE_PATH "$ENV{PATH}" FLTK2_DIR_SEARCH2)
+
+ # Construct a set of paths relative to the system search path.
+ set(FLTK2_DIR_SEARCH "")
+ foreach(dir ${FLTK2_DIR_SEARCH2})
+ set(FLTK2_DIR_SEARCH ${FLTK2_DIR_SEARCH} "${dir}/../lib/fltk")
+ endforeach()
+ string(REPLACE "//" "/" FLTK2_DIR_SEARCH "${FLTK2_DIR_SEARCH}")
+
+ #
+ # Look for an installation or build tree.
+ #
+ find_path(FLTK2_DIR FLTK2Config.cmake
+ # Look for an environment variable FLTK2_DIR.
+ ENV FLTK2_DIR
+
+ # Look in places relative to the system executable search path.
+ ${FLTK2_DIR_SEARCH}
+
+ # Look in standard UNIX install locations.
+ /usr/local/lib/fltk2
+ /usr/lib/fltk2
+ /usr/local/fltk2
+ /usr/X11R6/include
+
+ # Read from the CMakeSetup registry entries. It is likely that
+ # FLTK2 will have been recently built.
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
+ [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
+
+ # Help the user find it if we cannot.
+ DOC "The ${FLTK2_DIR_STRING}"
+ )
+
+ if(NOT FLTK2_DIR)
+ find_path(FLTK2_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH})
+ endif()
+
+endif()
+
+
+# If FLTK2 was found, load the configuration file to get the rest of the
+# settings.
+if(FLTK2_DIR)
+
+ # Check if FLTK2 was built using CMake
+ if(EXISTS ${FLTK2_DIR}/FLTK2Config.cmake)
+ set(FLTK2_BUILT_WITH_CMAKE 1)
+ endif()
+
+ if(FLTK2_BUILT_WITH_CMAKE)
+ set(FLTK2_FOUND 1)
+ include(${FLTK2_DIR}/FLTK2Config.cmake)
+
+ # Fluid
+ if(FLUID_COMMAND)
+ set(FLTK2_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
+ else()
+ find_program(FLTK2_FLUID_EXECUTABLE fluid2 PATHS
+ ${FLTK2_EXECUTABLE_DIRS}
+ ${FLTK2_EXECUTABLE_DIRS}/RelWithDebInfo
+ ${FLTK2_EXECUTABLE_DIRS}/Debug
+ ${FLTK2_EXECUTABLE_DIRS}/Release
+ NO_SYSTEM_PATH)
+ endif()
+
+ mark_as_advanced(FLTK2_FLUID_EXECUTABLE)
+ set( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
+
+
+
+
+ set(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
+ link_directories(${FLTK2_LIBRARY_DIRS})
+
+ set(FLTK2_BASE_LIBRARY fltk2)
+ set(FLTK2_GL_LIBRARY fltk2_gl)
+ set(FLTK2_IMAGES_LIBRARY fltk2_images)
+
+ # Add the extra libraries
+ load_cache(${FLTK2_DIR}
+ READ_WITH_PREFIX
+ FL FLTK2_USE_SYSTEM_JPEG
+ FL FLTK2_USE_SYSTEM_PNG
+ FL FLTK2_USE_SYSTEM_ZLIB
+ )
+
+ set(FLTK2_IMAGES_LIBS "")
+ if(FLFLTK2_USE_SYSTEM_JPEG)
+ set(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_jpeg)
+ endif()
+ if(FLFLTK2_USE_SYSTEM_PNG)
+ set(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_png)
+ endif()
+ if(FLFLTK2_USE_SYSTEM_ZLIB)
+ set(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_zlib)
+ endif()
+ set(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
+ "Extra libraries for fltk2_images library.")
+
+ else()
+
+ # if FLTK2 was not built using CMake
+ # Find fluid executable.
+ find_program(FLTK2_FLUID_EXECUTABLE fluid2 ${FLTK2_INCLUDE_DIR}/fluid)
+
+ # Use location of fluid to help find everything else.
+ set(FLTK2_INCLUDE_SEARCH_PATH "")
+ set(FLTK2_LIBRARY_SEARCH_PATH "")
+ if(FLTK2_FLUID_EXECUTABLE)
+ set( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
+ get_filename_component(FLTK2_BIN_DIR "${FLTK2_FLUID_EXECUTABLE}" PATH)
+ set(FLTK2_INCLUDE_SEARCH_PATH ${FLTK2_INCLUDE_SEARCH_PATH}
+ ${FLTK2_BIN_DIR}/../include ${FLTK2_BIN_DIR}/..)
+ set(FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_LIBRARY_SEARCH_PATH}
+ ${FLTK2_BIN_DIR}/../lib)
+ set(FLTK2_WRAP_UI 1)
+ endif()
+
+ set(FLTK2_INCLUDE_SEARCH_PATH ${FLTK2_INCLUDE_SEARCH_PATH}
+ /usr/local/fltk2
+ /usr/X11R6/include
+ )
+
+ find_path(FLTK2_INCLUDE_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH})
+
+ set(FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_LIBRARY_SEARCH_PATH}
+ /usr/local/fltk2/lib
+ /usr/X11R6/lib
+ ${FLTK2_INCLUDE_DIR}/lib
+ )
+
+ find_library(FLTK2_BASE_LIBRARY NAMES fltk2
+ PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
+ find_library(FLTK2_GL_LIBRARY NAMES fltk2_gl
+ PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
+ find_library(FLTK2_IMAGES_LIBRARY NAMES fltk2_images
+ PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
+
+ # Find the extra libraries needed for the fltk_images library.
+ if(UNIX)
+ find_program(FLTK2_CONFIG_SCRIPT fltk2-config PATHS ${FLTK2_BIN_DIR})
+ if(FLTK2_CONFIG_SCRIPT)
+ exec_program(${FLTK2_CONFIG_SCRIPT} ARGS --use-images --ldflags
+ OUTPUT_VARIABLE FLTK2_IMAGES_LDFLAGS)
+ set(FLTK2_LIBS_EXTRACT_REGEX ".*-lfltk2_images (.*) -lfltk2.*")
+ if("${FLTK2_IMAGES_LDFLAGS}" MATCHES "${FLTK2_LIBS_EXTRACT_REGEX}")
+ string(REGEX REPLACE " +" ";" FLTK2_IMAGES_LIBS "${CMAKE_MATCH_1}")
+ # The EXEC_PROGRAM will not be inherited into subdirectories from
+ # the file that originally included this module. Save the answer.
+ set(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
+ "Extra libraries for fltk_images library.")
+ endif()
+ endif()
+ endif()
+
+ endif()
+endif()
+
+
+set(FLTK2_FOUND 1)
+foreach(var FLTK2_FLUID_EXECUTABLE FLTK2_INCLUDE_DIR
+ FLTK2_BASE_LIBRARY FLTK2_GL_LIBRARY
+ FLTK2_IMAGES_LIBRARY)
+ if(NOT ${var})
+ message( STATUS "${var} not found" )
+ set(FLTK2_FOUND 0)
+ endif()
+endforeach()
+
+
+if(FLTK2_FOUND)
+ set(FLTK2_LIBRARIES ${FLTK2_IMAGES_LIBRARY} ${FLTK2_IMAGES_LIBS} ${FLTK2_BASE_LIBRARY} ${FLTK2_GL_LIBRARY} )
+ if(APPLE)
+ set(FLTK2_LIBRARIES ${FLTK2_PLATFORM_DEPENDENT_LIBS} ${FLTK2_LIBRARIES})
+ else()
+ set(FLTK2_LIBRARIES ${FLTK2_LIBRARIES} ${FLTK2_PLATFORM_DEPENDENT_LIBS})
+ endif()
+
+ # The following deprecated settings are for compatibility with CMake 1.4
+ set (HAS_FLTK2 ${FLTK2_FOUND})
+ set (FLTK2_INCLUDE_PATH ${FLTK2_INCLUDE_DIR})
+ set (FLTK2_FLUID_EXE ${FLTK2_FLUID_EXECUTABLE})
+ set (FLTK2_LIBRARY ${FLTK2_LIBRARIES})
+else()
+ # make FIND_PACKAGE friendly
+ if(NOT FLTK2_FIND_QUIETLY)
+ if(FLTK2_FIND_REQUIRED)
+ message(FATAL_ERROR
+ "FLTK2 required, please specify its location with FLTK2_DIR.")
+ else()
+ message(STATUS "FLTK2 was not found.")
+ endif()
+ endif()
+endif()
+
diff --git a/Modules/FindFreetype.cmake b/Modules/FindFreetype.cmake
new file mode 100644
index 0000000000..7d46d1563f
--- /dev/null
+++ b/Modules/FindFreetype.cmake
@@ -0,0 +1,164 @@
+#.rst:
+# FindFreetype
+# ------------
+#
+# Locate FreeType library
+#
+# This module defines
+#
+# ::
+#
+# FREETYPE_LIBRARIES, the library to link against
+# FREETYPE_FOUND, if false, do not try to link to FREETYPE
+# FREETYPE_INCLUDE_DIRS, where to find headers.
+# FREETYPE_VERSION_STRING, the version of freetype found (since CMake 2.8.8)
+# This is the concatenation of the paths:
+# FREETYPE_INCLUDE_DIR_ft2build
+# FREETYPE_INCLUDE_DIR_freetype2
+#
+#
+#
+# $FREETYPE_DIR is an environment variable that would correspond to the
+# ./configure --prefix=$FREETYPE_DIR used in building FREETYPE.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Created by Eric Wing.
+# Modifications by Alexander Neundorf.
+# This file has been renamed to "FindFreetype.cmake" instead of the correct
+# "FindFreeType.cmake" in order to be compatible with the one from KDE4, Alex.
+
+# Ugh, FreeType seems to use some #include trickery which
+# makes this harder than it should be. It looks like they
+# put ft2build.h in a common/easier-to-find location which
+# then contains a #include to a more specific header in a
+# more specific location (#include <freetype/config/ftheader.h>).
+# Then from there, they need to set a bunch of #define's
+# so you can do something like:
+# #include FT_FREETYPE_H
+# Unfortunately, using CMake's mechanisms like include_directories()
+# wants explicit full paths and this trickery doesn't work too well.
+# I'm going to attempt to cut out the middleman and hope
+# everything still works.
+find_path(
+ FREETYPE_INCLUDE_DIR_ft2build
+ ft2build.h
+ HINTS
+ ENV FREETYPE_DIR
+ PATHS
+ /usr/X11R6
+ /usr/local/X11R6
+ /usr/local/X11
+ /usr/freeware
+ ENV GTKMM_BASEPATH
+ [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
+ PATH_SUFFIXES
+ include/freetype2
+ include
+ freetype2
+)
+
+find_path(
+ FREETYPE_INCLUDE_DIR_freetype2
+ NAMES
+ freetype/config/ftheader.h
+ config/ftheader.h
+ HINTS
+ ENV FREETYPE_DIR
+ PATHS
+ /usr/X11R6
+ /usr/local/X11R6
+ /usr/local/X11
+ /usr/freeware
+ ENV GTKMM_BASEPATH
+ [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
+ PATH_SUFFIXES
+ include/freetype2
+ include
+ freetype2
+)
+
+find_library(FREETYPE_LIBRARY
+ NAMES
+ freetype
+ libfreetype
+ freetype219
+ HINTS
+ ENV FREETYPE_DIR
+ PATHS
+ /usr/X11R6
+ /usr/local/X11R6
+ /usr/local/X11
+ /usr/freeware
+ ENV GTKMM_BASEPATH
+ [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
+ PATH_SUFFIXES
+ lib
+)
+
+# set the user variables
+if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
+ set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}")
+ list(REMOVE_DUPLICATES FREETYPE_INCLUDE_DIRS)
+endif()
+set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}")
+
+if(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
+ set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
+elseif(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
+ set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
+endif()
+
+if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H)
+ file(STRINGS "${FREETYPE_H}" freetype_version_str
+ REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
+
+ unset(FREETYPE_VERSION_STRING)
+ foreach(VPART MAJOR MINOR PATCH)
+ foreach(VLINE ${freetype_version_str})
+ if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$")
+ set(FREETYPE_VERSION_PART "${CMAKE_MATCH_1}")
+ if(FREETYPE_VERSION_STRING)
+ set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_STRING}.${FREETYPE_VERSION_PART}")
+ else()
+ set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}")
+ endif()
+ unset(FREETYPE_VERSION_PART)
+ endif()
+ endforeach()
+ endforeach()
+endif()
+
+
+# handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+find_package_handle_standard_args(
+ Freetype
+ REQUIRED_VARS
+ FREETYPE_LIBRARY
+ FREETYPE_INCLUDE_DIRS
+ VERSION_VAR
+ FREETYPE_VERSION_STRING
+)
+
+mark_as_advanced(
+ FREETYPE_LIBRARY
+ FREETYPE_INCLUDE_DIR_freetype2
+ FREETYPE_INCLUDE_DIR_ft2build
+)
diff --git a/Modules/FindGCCXML.cmake b/Modules/FindGCCXML.cmake
new file mode 100644
index 0000000000..48618e2898
--- /dev/null
+++ b/Modules/FindGCCXML.cmake
@@ -0,0 +1,36 @@
+#.rst:
+# FindGCCXML
+# ----------
+#
+# Find the GCC-XML front-end executable.
+#
+#
+#
+# This module will define the following variables:
+#
+# ::
+#
+# GCCXML - the GCC-XML front-end executable.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+find_program(GCCXML
+ NAMES gccxml
+ ../GCC_XML/gccxml
+ PATHS [HKEY_CURRENT_USER\\Software\\Kitware\\GCC_XML;loc]
+ "$ENV{ProgramFiles}/GCC_XML"
+ "C:/Program Files/GCC_XML"
+)
+
+mark_as_advanced(GCCXML)
diff --git a/Modules/FindGDAL.cmake b/Modules/FindGDAL.cmake
new file mode 100644
index 0000000000..bf374f9307
--- /dev/null
+++ b/Modules/FindGDAL.cmake
@@ -0,0 +1,119 @@
+#.rst:
+# FindGDAL
+# --------
+#
+#
+#
+# Locate gdal
+#
+# This module accepts the following environment variables:
+#
+# ::
+#
+# GDAL_DIR or GDAL_ROOT - Specify the location of GDAL
+#
+#
+#
+# This module defines the following CMake variables:
+#
+# ::
+#
+# GDAL_FOUND - True if libgdal is found
+# GDAL_LIBRARY - A variable pointing to the GDAL library
+# GDAL_INCLUDE_DIR - Where to find the headers
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+#
+# $GDALDIR is an environment variable that would
+# correspond to the ./configure --prefix=$GDAL_DIR
+# used in building gdal.
+#
+# Created by Eric Wing. I'm not a gdal user, but OpenSceneGraph uses it
+# for osgTerrain so I whipped this module together for completeness.
+# I actually don't know the conventions or where files are typically
+# placed in distros.
+# Any real gdal users are encouraged to correct this (but please don't
+# break the OS X framework stuff when doing so which is what usually seems
+# to happen).
+
+# This makes the presumption that you are include gdal.h like
+#
+#include "gdal.h"
+
+find_path(GDAL_INCLUDE_DIR gdal.h
+ HINTS
+ ENV GDAL_DIR
+ ENV GDAL_ROOT
+ PATH_SUFFIXES
+ include/gdal
+ include/GDAL
+ include
+ PATHS
+ ~/Library/Frameworks/gdal.framework/Headers
+ /Library/Frameworks/gdal.framework/Headers
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+)
+
+if(UNIX)
+ # Use gdal-config to obtain the library version (this should hopefully
+ # allow us to -lgdal1.x.y where x.y are correct version)
+ # For some reason, libgdal development packages do not contain
+ # libgdal.so...
+ find_program(GDAL_CONFIG gdal-config
+ HINTS
+ ENV GDAL_DIR
+ ENV GDAL_ROOT
+ PATH_SUFFIXES bin
+ PATHS
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+ )
+
+ if(GDAL_CONFIG)
+ exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS)
+ if(GDAL_CONFIG_LIBS)
+ string(REGEX MATCHALL "-l[^ ]+" _gdal_dashl ${GDAL_CONFIG_LIBS})
+ string(REPLACE "-l" "" _gdal_lib "${_gdal_dashl}")
+ string(REGEX MATCHALL "-L[^ ]+" _gdal_dashL ${GDAL_CONFIG_LIBS})
+ string(REPLACE "-L" "" _gdal_libpath "${_gdal_dashL}")
+ endif()
+ endif()
+endif()
+
+find_library(GDAL_LIBRARY
+ NAMES ${_gdal_lib} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
+ HINTS
+ ENV GDAL_DIR
+ ENV GDAL_ROOT
+ ${_gdal_libpath}
+ PATH_SUFFIXES lib
+ PATHS
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ /usr/freeware
+)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL DEFAULT_MSG GDAL_LIBRARY GDAL_INCLUDE_DIR)
+
+set(GDAL_LIBRARIES ${GDAL_LIBRARY})
+set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR})
diff --git a/Modules/FindGIF.cmake b/Modules/FindGIF.cmake
new file mode 100644
index 0000000000..7bbb8cfcdc
--- /dev/null
+++ b/Modules/FindGIF.cmake
@@ -0,0 +1,86 @@
+#.rst:
+# FindGIF
+# -------
+#
+#
+#
+# This module searches giflib and defines GIF_LIBRARIES - libraries to
+# link to in order to use GIF GIF_FOUND, if false, do not try to link
+# GIF_INCLUDE_DIR, where to find the headers GIF_VERSION, reports either
+# version 4 or 3 (for everything before version 4)
+#
+# The minimum required version of giflib can be specified using the
+# standard syntax, e.g. find_package(GIF 4)
+#
+# $GIF_DIR is an environment variable that would correspond to the
+# ./configure --prefix=$GIF_DIR
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Created by Eric Wing.
+# Modifications by Alexander Neundorf
+
+find_path(GIF_INCLUDE_DIR gif_lib.h
+ HINTS
+ ENV GIF_DIR
+ PATH_SUFFIXES include
+ PATHS
+ ~/Library/Frameworks
+ /usr/freeware
+)
+
+# the gif library can have many names :-/
+set(POTENTIAL_GIF_LIBS gif libgif ungif libungif giflib giflib4)
+
+find_library(GIF_LIBRARY
+ NAMES ${POTENTIAL_GIF_LIBS}
+ HINTS
+ ENV GIF_DIR
+ PATH_SUFFIXES lib
+ PATHS
+ ~/Library/Frameworks
+ /usr/freeware
+)
+
+# see readme.txt
+set(GIF_LIBRARIES ${GIF_LIBRARY})
+
+# Very basic version detection.
+# The GIF_LIB_VERSION string in gif_lib.h seems to be unreliable, since it seems
+# to be always " Version 2.0, " in versions 3.x of giflib.
+# In version 4 the member UserData was added to GifFileType, so we check for this
+# one.
+# http://giflib.sourcearchive.com/documentation/4.1.4/files.html
+if(GIF_INCLUDE_DIR)
+ include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckStructHasMember.cmake)
+ CMAKE_PUSH_CHECK_STATE()
+ set(CMAKE_REQUIRED_QUIET ${GIF_FIND_QUIETLY})
+ set(GIF_VERSION 3)
+ set(CMAKE_REQUIRED_INCLUDES "${GIF_INCLUDE_DIR}")
+ CHECK_STRUCT_HAS_MEMBER(GifFileType UserData gif_lib.h GIF_GifFileType_UserData )
+ if(GIF_GifFileType_UserData)
+ set(GIF_VERSION 4)
+ endif()
+ CMAKE_POP_CHECK_STATE()
+endif()
+
+
+# handle the QUIETLY and REQUIRED arguments and set GIF_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GIF REQUIRED_VARS GIF_LIBRARY GIF_INCLUDE_DIR
+ VERSION_VAR GIF_VERSION )
+
+mark_as_advanced(GIF_INCLUDE_DIR GIF_LIBRARY)
diff --git a/Modules/FindGLEW.cmake b/Modules/FindGLEW.cmake
new file mode 100644
index 0000000000..f42182fca4
--- /dev/null
+++ b/Modules/FindGLEW.cmake
@@ -0,0 +1,54 @@
+#.rst:
+# FindGLEW
+# --------
+#
+# Find the OpenGL Extension Wrangler Library (GLEW)
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the :prop_tgt:`IMPORTED` target ``GLEW::GLEW``,
+# if GLEW has been found.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following variables:
+#
+# ::
+#
+# GLEW_INCLUDE_DIRS - include directories for GLEW
+# GLEW_LIBRARIES - libraries to link against GLEW
+# GLEW_FOUND - true if GLEW has been found and can be used
+
+#=============================================================================
+# Copyright 2012 Benjamin Eikel
+#
+# 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.)
+
+find_path(GLEW_INCLUDE_DIR GL/glew.h)
+find_library(GLEW_LIBRARY NAMES GLEW glew32 glew glew32s PATH_SUFFIXES lib64)
+
+set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDE_DIR})
+set(GLEW_LIBRARIES ${GLEW_LIBRARY})
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(GLEW
+ REQUIRED_VARS GLEW_INCLUDE_DIR GLEW_LIBRARY)
+
+if(GLEW_FOUND AND NOT TARGET GLEW::GLEW)
+ add_library(GLEW::GLEW UNKNOWN IMPORTED)
+ set_target_properties(GLEW::GLEW PROPERTIES
+ IMPORTED_LOCATION "${GLEW_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}")
+endif()
+
+mark_as_advanced(GLEW_INCLUDE_DIR GLEW_LIBRARY)
diff --git a/Modules/FindGLU.cmake b/Modules/FindGLU.cmake
new file mode 100644
index 0000000000..0d36fad3d8
--- /dev/null
+++ b/Modules/FindGLU.cmake
@@ -0,0 +1,28 @@
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+# Use of this file is deprecated, and is here for backwards compatibility with CMake 1.4
+# GLU library is now found by FindOpenGL.cmake
+#
+
+message(STATUS
+ "WARNING: you are using the obsolete 'GLU' package, please use 'OpenGL' instead")
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindOpenGL.cmake)
+
+if (OPENGL_GLU_FOUND)
+ set (GLU_LIBRARY ${OPENGL_LIBRARIES})
+ set (GLU_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
+endif ()
+
diff --git a/Modules/FindGLUT.cmake b/Modules/FindGLUT.cmake
new file mode 100644
index 0000000000..c9f7597f4a
--- /dev/null
+++ b/Modules/FindGLUT.cmake
@@ -0,0 +1,176 @@
+#.rst:
+# FindGLUT
+# --------
+#
+# try to find glut library and include files.
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the :prop_tgt:`IMPORTED` targets:
+#
+# ``GLUT::GLUT``
+# Defined if the system has GLUT.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module sets the following variables:
+#
+# ::
+#
+# GLUT_INCLUDE_DIR, where to find GL/glut.h, etc.
+# GLUT_LIBRARIES, the libraries to link against
+# GLUT_FOUND, If false, do not try to use GLUT.
+#
+# Also defined, but not for general use are:
+#
+# ::
+#
+# GLUT_glut_LIBRARY = the full path to the glut library.
+# GLUT_Xmu_LIBRARY = the full path to the Xmu library.
+# GLUT_Xi_LIBRARY = the full path to the Xi Library.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+if (WIN32)
+ find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
+ PATHS ${GLUT_ROOT_PATH}/include )
+ find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
+ PATHS
+ ${OPENGL_LIBRARY_DIR}
+ ${GLUT_ROOT_PATH}/Release
+ )
+else ()
+
+ if (APPLE)
+ find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR})
+ find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX")
+ find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX")
+
+ if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
+ add_library(GLUT::Cocoa UNKNOWN IMPORTED)
+ # Cocoa should always be a Framework, but we check to make sure.
+ if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$")
+ set_target_properties(GLUT::Cocoa PROPERTIES
+ IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}")
+ else()
+ set_target_properties(GLUT::Cocoa PROPERTIES
+ IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}")
+ endif()
+ endif()
+ else ()
+
+ if (BEOS)
+
+ set(_GLUT_INC_DIR /boot/develop/headers/os/opengl)
+ set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86)
+
+ else()
+
+ find_library( GLUT_Xi_LIBRARY Xi
+ /usr/openwin/lib
+ )
+
+ find_library( GLUT_Xmu_LIBRARY Xmu
+ /usr/openwin/lib
+ )
+
+ if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
+ add_library(GLUT::Xi UNKNOWN IMPORTED)
+ set_target_properties(GLUT::Xi PROPERTIES
+ IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}")
+ endif()
+
+ if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu)
+ add_library(GLUT::Xmu UNKNOWN IMPORTED)
+ set_target_properties(GLUT::Xmu PROPERTIES
+ IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}")
+ endif()
+
+ endif ()
+
+ find_path( GLUT_INCLUDE_DIR GL/glut.h
+ /usr/include/GL
+ /usr/openwin/share/include
+ /usr/openwin/include
+ /opt/graphics/OpenGL/include
+ /opt/graphics/OpenGL/contrib/libglut
+ ${_GLUT_INC_DIR}
+ )
+
+ find_library( GLUT_glut_LIBRARY glut
+ /usr/openwin/lib
+ ${_GLUT_glut_LIB_DIR}
+ )
+
+ unset(_GLUT_INC_DIR)
+ unset(_GLUT_glut_LIB_DIR)
+
+ endif ()
+
+endif ()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
+
+if (GLUT_FOUND)
+ # Is -lXi and -lXmu required on all platforms that have it?
+ # If not, we need some way to figure out what platform we are on.
+ set( GLUT_LIBRARIES
+ ${GLUT_glut_LIBRARY}
+ ${GLUT_Xmu_LIBRARY}
+ ${GLUT_Xi_LIBRARY}
+ ${GLUT_cocoa_LIBRARY}
+ )
+
+ if(NOT TARGET GLUT::GLUT)
+ add_library(GLUT::GLUT UNKNOWN IMPORTED)
+ set_target_properties(GLUT::GLUT PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIR}")
+ if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$")
+ set_target_properties(GLUT::GLUT PROPERTIES
+ IMPORTED_LOCATION "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}")
+ else()
+ set_target_properties(GLUT::GLUT PROPERTIES
+ IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
+ endif()
+
+ if(TARGET GLUT::Xmu)
+ set_property(TARGET GLUT::GLUT APPEND
+ PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu)
+ endif()
+
+ if(TARGET GLUT::Xi)
+ set_property(TARGET GLUT::GLUT APPEND
+ PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi)
+ endif()
+
+ if(TARGET GLUT::Cocoa)
+ set_property(TARGET GLUT::GLUT APPEND
+ PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa)
+ endif()
+ endif()
+
+ #The following deprecated settings are for backwards compatibility with CMake1.4
+ set (GLUT_LIBRARY ${GLUT_LIBRARIES})
+ set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
+endif()
+
+mark_as_advanced(
+ GLUT_INCLUDE_DIR
+ GLUT_glut_LIBRARY
+ GLUT_Xmu_LIBRARY
+ GLUT_Xi_LIBRARY
+ )
diff --git a/Modules/FindGTK.cmake b/Modules/FindGTK.cmake
new file mode 100644
index 0000000000..01bca76c41
--- /dev/null
+++ b/Modules/FindGTK.cmake
@@ -0,0 +1,168 @@
+#.rst:
+# FindGTK
+# -------
+#
+# try to find GTK (and glib) and GTKGLArea
+#
+# ::
+#
+# GTK_INCLUDE_DIR - Directories to include to use GTK
+# GTK_LIBRARIES - Files to link against to use GTK
+# GTK_FOUND - GTK was found
+# GTK_GL_FOUND - GTK's GL features were found
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+# don't even bother under WIN32
+if(UNIX)
+
+ find_path( GTK_gtk_INCLUDE_PATH NAMES gtk/gtk.h
+ PATH_SUFFIXES gtk-1.2 gtk12
+ PATHS
+ /usr/openwin/share/include
+ /usr/openwin/include
+ /opt/gnome/include
+ )
+
+ # Some Linux distributions (e.g. Red Hat) have glibconfig.h
+ # and glib.h in different directories, so we need to look
+ # for both.
+ # - Atanas Georgiev <atanas@cs.columbia.edu>
+
+ find_path( GTK_glibconfig_INCLUDE_PATH NAMES glibconfig.h
+ PATHS
+ /usr/openwin/share/include
+ /usr/local/include/glib12
+ /usr/lib/glib/include
+ /usr/local/lib/glib/include
+ /opt/gnome/include
+ /opt/gnome/lib/glib/include
+ )
+
+ find_path( GTK_glib_INCLUDE_PATH NAMES glib.h
+ PATH_SUFFIXES gtk-1.2 glib-1.2 glib12
+ PATHS
+ /usr/openwin/share/include
+ /usr/lib/glib/include
+ /opt/gnome/include
+ )
+
+ find_path( GTK_gtkgl_INCLUDE_PATH NAMES gtkgl/gtkglarea.h
+ PATHS /usr/openwin/share/include
+ /opt/gnome/include
+ )
+
+ find_library( GTK_gtkgl_LIBRARY gtkgl
+ /usr/openwin/lib
+ /opt/gnome/lib
+ )
+
+ #
+ # The 12 suffix is thanks to the FreeBSD ports collection
+ #
+
+ find_library( GTK_gtk_LIBRARY
+ NAMES gtk gtk12
+ PATHS /usr/openwin/lib
+ /opt/gnome/lib
+ )
+
+ find_library( GTK_gdk_LIBRARY
+ NAMES gdk gdk12
+ PATHS /usr/openwin/lib
+ /opt/gnome/lib
+ )
+
+ find_library( GTK_gmodule_LIBRARY
+ NAMES gmodule gmodule12
+ PATHS /usr/openwin/lib
+ /opt/gnome/lib
+ )
+
+ find_library( GTK_glib_LIBRARY
+ NAMES glib glib12
+ PATHS /usr/openwin/lib
+ /opt/gnome/lib
+ )
+
+ find_library( GTK_Xi_LIBRARY
+ NAMES Xi
+ PATHS /usr/openwin/lib
+ /opt/gnome/lib
+ )
+
+ find_library( GTK_gthread_LIBRARY
+ NAMES gthread gthread12
+ PATHS /usr/openwin/lib
+ /opt/gnome/lib
+ )
+
+ if(GTK_gtk_INCLUDE_PATH
+ AND GTK_glibconfig_INCLUDE_PATH
+ AND GTK_glib_INCLUDE_PATH
+ AND GTK_gtk_LIBRARY
+ AND GTK_glib_LIBRARY)
+
+ # Assume that if gtk and glib were found, the other
+ # supporting libraries have also been found.
+
+ set( GTK_FOUND "YES" )
+ set( GTK_INCLUDE_DIR ${GTK_gtk_INCLUDE_PATH}
+ ${GTK_glibconfig_INCLUDE_PATH}
+ ${GTK_glib_INCLUDE_PATH} )
+ set( GTK_LIBRARIES ${GTK_gtk_LIBRARY}
+ ${GTK_gdk_LIBRARY}
+ ${GTK_glib_LIBRARY} )
+
+ if(GTK_gmodule_LIBRARY)
+ set(GTK_LIBRARIES ${GTK_LIBRARIES} ${GTK_gmodule_LIBRARY})
+ endif()
+ if(GTK_gthread_LIBRARY)
+ set(GTK_LIBRARIES ${GTK_LIBRARIES} ${GTK_gthread_LIBRARY})
+ endif()
+ if(GTK_Xi_LIBRARY)
+ set(GTK_LIBRARIES ${GTK_LIBRARIES} ${GTK_Xi_LIBRARY})
+ endif()
+
+ if(GTK_gtkgl_INCLUDE_PATH AND GTK_gtkgl_LIBRARY)
+ set( GTK_GL_FOUND "YES" )
+ set( GTK_INCLUDE_DIR ${GTK_INCLUDE_DIR}
+ ${GTK_gtkgl_INCLUDE_PATH} )
+ set( GTK_LIBRARIES ${GTK_gtkgl_LIBRARY} ${GTK_LIBRARIES} )
+ mark_as_advanced(
+ GTK_gtkgl_LIBRARY
+ GTK_gtkgl_INCLUDE_PATH
+ )
+ endif()
+
+ endif()
+
+ mark_as_advanced(
+ GTK_gdk_LIBRARY
+ GTK_glib_INCLUDE_PATH
+ GTK_glib_LIBRARY
+ GTK_glibconfig_INCLUDE_PATH
+ GTK_gmodule_LIBRARY
+ GTK_gthread_LIBRARY
+ GTK_Xi_LIBRARY
+ GTK_gtk_INCLUDE_PATH
+ GTK_gtk_LIBRARY
+ GTK_gtkgl_INCLUDE_PATH
+ GTK_gtkgl_LIBRARY
+ )
+
+endif()
+
+
+
diff --git a/Modules/FindGTK2.cmake b/Modules/FindGTK2.cmake
new file mode 100644
index 0000000000..72bb8ebb08
--- /dev/null
+++ b/Modules/FindGTK2.cmake
@@ -0,0 +1,902 @@
+#.rst:
+# FindGTK2
+# --------
+#
+# FindGTK2.cmake
+#
+# This module can find the GTK2 widget libraries and several of its
+# other optional components like gtkmm, glade, and glademm.
+#
+# NOTE: If you intend to use version checking, CMake 2.6.2 or later is
+#
+# ::
+#
+# required.
+#
+#
+#
+# Specify one or more of the following components as you call this find
+# module. See example below.
+#
+# ::
+#
+# gtk
+# gtkmm
+# glade
+# glademm
+#
+#
+#
+# The following variables will be defined for your use
+#
+# ::
+#
+# GTK2_FOUND - Were all of your specified components found?
+# GTK2_INCLUDE_DIRS - All include directories
+# GTK2_LIBRARIES - All libraries
+# GTK2_DEFINITIONS - Additional compiler flags
+#
+#
+#
+# ::
+#
+# GTK2_VERSION - The version of GTK2 found (x.y.z)
+# GTK2_MAJOR_VERSION - The major version of GTK2
+# GTK2_MINOR_VERSION - The minor version of GTK2
+# GTK2_PATCH_VERSION - The patch version of GTK2
+#
+#
+#
+# Optional variables you can define prior to calling this module:
+#
+# ::
+#
+# GTK2_DEBUG - Enables verbose debugging of the module
+# GTK2_ADDITIONAL_SUFFIXES - Allows defining additional directories to
+# search for include files
+#
+#
+#
+# ================= Example Usage:
+#
+# ::
+#
+# Call find_package() once, here are some examples to pick from:
+#
+#
+#
+# ::
+#
+# Require GTK 2.6 or later
+# find_package(GTK2 2.6 REQUIRED gtk)
+#
+#
+#
+# ::
+#
+# Require GTK 2.10 or later and Glade
+# find_package(GTK2 2.10 REQUIRED gtk glade)
+#
+#
+#
+# ::
+#
+# Search for GTK/GTKMM 2.8 or later
+# find_package(GTK2 2.8 COMPONENTS gtk gtkmm)
+#
+#
+#
+# ::
+#
+# if(GTK2_FOUND)
+# include_directories(${GTK2_INCLUDE_DIRS})
+# add_executable(mygui mygui.cc)
+# target_link_libraries(mygui ${GTK2_LIBRARIES})
+# endif()
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2008-2012 Philip Lowman <philip@yhbt.com>
+#
+# 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.)
+
+# Version 1.6 (CMake 3.0)
+# * Create targets for each library
+# * Do not link libfreetype
+# Version 1.5 (CMake 2.8.12)
+# * 14236: Detect gthread library
+# Detect pangocairo on windows
+# Detect pangocairo with gtk module instead of with gtkmm
+# * 14259: Use vc100 libraries with MSVC11
+# * 14260: Export a GTK2_DEFINITIONS variable to set /vd2 when appropriate
+# (i.e. MSVC)
+# * Use the optimized/debug syntax for _LIBRARY and _LIBRARIES variables when
+# appropriate. A new set of _RELEASE variables was also added.
+# * Remove GTK2_SKIP_MARK_AS_ADVANCED option, as now the variables are
+# marked as advanced by SelectLibraryConfigurations
+# * Detect gmodule, pangoft2 and pangoxft libraries
+# Version 1.4 (10/4/2012) (CMake 2.8.10)
+# * 12596: Missing paths for FindGTK2 on NetBSD
+# * 12049: Fixed detection of GTK include files in the lib folder on
+# multiarch systems.
+# Version 1.3 (11/9/2010) (CMake 2.8.4)
+# * 11429: Add support for detecting GTK2 built with Visual Studio 10.
+# Thanks to Vincent Levesque for the patch.
+# Version 1.2 (8/30/2010) (CMake 2.8.3)
+# * Merge patch for detecting gdk-pixbuf library (split off
+# from core GTK in 2.21). Thanks to Vincent Untz for the patch
+# and Ricardo Cruz for the heads up.
+# Version 1.1 (8/19/2010) (CMake 2.8.3)
+# * Add support for detecting GTK2 under macports (thanks to Gary Kramlich)
+# Version 1.0 (8/12/2010) (CMake 2.8.3)
+# * Add support for detecting new pangommconfig.h header file
+# (Thanks to Sune Vuorela & the Debian Project for the patch)
+# * Add support for detecting fontconfig.h header
+# * Call find_package(Freetype) since it's required
+# * Add support for allowing users to add additional library directories
+# via the GTK2_ADDITIONAL_SUFFIXES variable (kind of a future-kludge in
+# case the GTK developers change versions on any of the directories in the
+# future).
+# Version 0.8 (1/4/2010)
+# * Get module working under MacOSX fink by adding /sw/include, /sw/lib
+# to PATHS and the gobject library
+# Version 0.7 (3/22/09)
+# * Checked into CMake CVS
+# * Added versioning support
+# * Module now defaults to searching for GTK if COMPONENTS not specified.
+# * Added HKCU prior to HKLM registry key and GTKMM specific environment
+# variable as per mailing list discussion.
+# * Added lib64 to include search path and a few other search paths where GTK
+# may be installed on Unix systems.
+# * Switched to lowercase CMake commands
+# * Prefaced internal variables with _GTK2 to prevent collision
+# * Changed internal macros to functions
+# * Enhanced documentation
+# Version 0.6 (1/8/08)
+# Added GTK2_SKIP_MARK_AS_ADVANCED option
+# Version 0.5 (12/19/08)
+# Second release to cmake mailing list
+
+#=============================================================
+# _GTK2_GET_VERSION
+# Internal function to parse the version number in gtkversion.h
+# _OUT_major = Major version number
+# _OUT_minor = Minor version number
+# _OUT_micro = Micro version number
+# _gtkversion_hdr = Header file to parse
+#=============================================================
+
+include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
+
+function(_GTK2_GET_VERSION _OUT_major _OUT_minor _OUT_micro _gtkversion_hdr)
+ file(STRINGS ${_gtkversion_hdr} _contents REGEX "#define GTK_M[A-Z]+_VERSION[ \t]+")
+ if(_contents)
+ string(REGEX REPLACE ".*#define GTK_MAJOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_major} "${_contents}")
+ string(REGEX REPLACE ".*#define GTK_MINOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_minor} "${_contents}")
+ string(REGEX REPLACE ".*#define GTK_MICRO_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_micro} "${_contents}")
+
+ if(NOT ${_OUT_major} MATCHES "[0-9]+")
+ message(FATAL_ERROR "Version parsing failed for GTK2_MAJOR_VERSION!")
+ endif()
+ if(NOT ${_OUT_minor} MATCHES "[0-9]+")
+ message(FATAL_ERROR "Version parsing failed for GTK2_MINOR_VERSION!")
+ endif()
+ if(NOT ${_OUT_micro} MATCHES "[0-9]+")
+ message(FATAL_ERROR "Version parsing failed for GTK2_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
+# _var = variable to set (_INCLUDE_DIR is appended)
+# _hdr = header file to look for
+#=============================================================
+function(_GTK2_FIND_INCLUDE_DIR _var _hdr)
+
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "_GTK2_FIND_INCLUDE_DIR( ${_var} ${_hdr} )")
+ endif()
+
+ set(_gtk_packages
+ # If these ever change, things will break.
+ ${GTK2_ADDITIONAL_SUFFIXES}
+ glibmm-2.4
+ glib-2.0
+ atk-1.0
+ atkmm-1.6
+ cairo
+ cairomm-1.0
+ gdk-pixbuf-2.0
+ gdkmm-2.4
+ giomm-2.4
+ gtk-2.0
+ gtkmm-2.4
+ libglade-2.0
+ libglademm-2.4
+ pango-1.0
+ pangomm-1.4
+ sigc++-2.0
+ )
+
+ #
+ # NOTE: The following suffixes cause searching for header files in both of
+ # these directories:
+ # /usr/include/<pkg>
+ # /usr/lib/<pkg>/include
+ #
+
+ set(_suffixes)
+ foreach(_d ${_gtk_packages})
+ list(APPEND _suffixes ${_d})
+ list(APPEND _suffixes ${_d}/include) # for /usr/lib/gtk-2.0/include
+ endforeach()
+
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "include suffixes = ${_suffixes}")
+ endif()
+
+ if(CMAKE_LIBRARY_ARCHITECTURE)
+ set(_gtk2_arch_dir /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE})
+ if(GTK2_DEBUG)
+ message(STATUS "Adding ${_gtk2_arch_dir} to search path for multiarch support")
+ endif()
+ endif()
+ find_path(GTK2_${_var}_INCLUDE_DIR ${_hdr}
+ PATHS
+ ${_gtk2_arch_dir}
+ /usr/local/lib64
+ /usr/local/lib
+ /usr/lib64
+ /usr/lib
+ /usr/X11R6/include
+ /usr/X11R6/lib
+ /opt/gnome/include
+ /opt/gnome/lib
+ /opt/openwin/include
+ /usr/openwin/lib
+ /sw/include
+ /sw/lib
+ /opt/local/include
+ /opt/local/lib
+ /usr/pkg/lib
+ /usr/pkg/include/glib
+ $ENV{GTKMM_BASEPATH}/include
+ $ENV{GTKMM_BASEPATH}/lib
+ [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/include
+ [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/include
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
+ PATH_SUFFIXES
+ ${_suffixes}
+ )
+ mark_as_advanced(GTK2_${_var}_INCLUDE_DIR)
+
+ if(GTK2_${_var}_INCLUDE_DIR)
+ set(GTK2_INCLUDE_DIRS ${GTK2_INCLUDE_DIRS} ${GTK2_${_var}_INCLUDE_DIR} PARENT_SCOPE)
+ endif()
+
+endfunction()
+
+#=============================================================
+# _GTK2_FIND_LIBRARY
+# Internal function to find libraries packaged with GTK2
+# _var = library variable to create (_LIBRARY is appended)
+#=============================================================
+function(_GTK2_FIND_LIBRARY _var _lib _expand_vc _append_version)
+
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "_GTK2_FIND_LIBRARY( ${_var} ${_lib} ${_expand_vc} ${_append_version} )")
+ endif()
+
+ # Not GTK versions per se but the versions encoded into Windows
+ # import libraries (GtkMM 2.14.1 has a gtkmm-vc80-2_4.lib for example)
+ # Also the MSVC libraries use _ for . (this is handled below)
+ set(_versions 2.20 2.18 2.16 2.14 2.12
+ 2.10 2.8 2.6 2.4 2.2 2.0
+ 1.20 1.18 1.16 1.14 1.12
+ 1.10 1.8 1.6 1.4 1.2 1.0)
+
+ set(_library)
+ set(_library_d)
+
+ set(_library ${_lib})
+
+ if(_expand_vc AND MSVC)
+ # Add vc80/vc90/vc100 midfixes
+ if(MSVC80)
+ set(_library ${_library}-vc80)
+ elseif(MSVC90)
+ set(_library ${_library}-vc90)
+ elseif(MSVC10)
+ set(_library ${_library}-vc100)
+ elseif(MSVC11)
+ # Up to gtkmm-win 2.22.0-2 there are no vc110 libraries but vc100 can be used
+ set(_library ${_library}-vc100)
+ endif()
+ set(_library_d ${_library}-d)
+ endif()
+
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "After midfix addition = ${_library} and ${_library_d}")
+ endif()
+
+ set(_lib_list)
+ set(_libd_list)
+ if(_append_version)
+ foreach(_ver ${_versions})
+ list(APPEND _lib_list "${_library}-${_ver}")
+ list(APPEND _libd_list "${_library_d}-${_ver}")
+ endforeach()
+ else()
+ set(_lib_list ${_library})
+ set(_libd_list ${_library_d})
+ endif()
+
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "library list = ${_lib_list} and library debug list = ${_libd_list}")
+ endif()
+
+ # For some silly reason the MSVC libraries use _ instead of .
+ # in the version fields
+ if(_expand_vc AND MSVC)
+ set(_no_dots_lib_list)
+ set(_no_dots_libd_list)
+ foreach(_l ${_lib_list})
+ string(REPLACE "." "_" _no_dots_library ${_l})
+ list(APPEND _no_dots_lib_list ${_no_dots_library})
+ endforeach()
+ # And for debug
+ set(_no_dots_libsd_list)
+ foreach(_l ${_libd_list})
+ string(REPLACE "." "_" _no_dots_libraryd ${_l})
+ list(APPEND _no_dots_libd_list ${_no_dots_libraryd})
+ endforeach()
+
+ # Copy list back to original names
+ set(_lib_list ${_no_dots_lib_list})
+ set(_libd_list ${_no_dots_libd_list})
+ endif()
+
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "While searching for GTK2_${_var}_LIBRARY, our proposed library list is ${_lib_list}")
+ endif()
+
+ find_library(GTK2_${_var}_LIBRARY_RELEASE
+ NAMES ${_lib_list}
+ PATHS
+ /opt/gnome/lib
+ /usr/openwin/lib
+ /sw/lib
+ $ENV{GTKMM_BASEPATH}/lib
+ [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
+ )
+
+ if(_expand_vc AND MSVC)
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "While searching for GTK2_${_var}_LIBRARY_DEBUG our proposed library list is ${_libd_list}")
+ endif()
+
+ find_library(GTK2_${_var}_LIBRARY_DEBUG
+ NAMES ${_libd_list}
+ PATHS
+ $ENV{GTKMM_BASEPATH}/lib
+ [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
+ )
+ endif()
+
+ select_library_configurations(GTK2_${_var})
+
+ set(GTK2_${_var}_LIBRARY ${GTK2_${_var}_LIBRARY} PARENT_SCOPE)
+ set(GTK2_${_var}_FOUND ${GTK2_${_var}_FOUND} PARENT_SCOPE)
+
+ if(GTK2_${_var}_FOUND)
+ set(GTK2_LIBRARIES ${GTK2_LIBRARIES} ${GTK2_${_var}_LIBRARY})
+ set(GTK2_LIBRARIES ${GTK2_LIBRARIES} PARENT_SCOPE)
+ endif()
+
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "GTK2_${_var}_LIBRARY_RELEASE = \"${GTK2_${_var}_LIBRARY_RELEASE}\"")
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "GTK2_${_var}_LIBRARY_DEBUG = \"${GTK2_${_var}_LIBRARY_DEBUG}\"")
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "GTK2_${_var}_LIBRARY = \"${GTK2_${_var}_LIBRARY}\"")
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "GTK2_${_var}_FOUND = \"${GTK2_${_var}_FOUND}\"")
+ endif()
+
+endfunction()
+
+
+function(_GTK2_ADD_TARGET_DEPENDS_INTERNAL _var _property)
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "_GTK2_ADD_TARGET_DEPENDS_INTERNAL( ${_var} ${_property} )")
+ endif()
+
+ string(TOLOWER "${_var}" _basename)
+
+ if (TARGET GTK2::${_basename})
+ foreach(_depend ${ARGN})
+ set(_valid_depends)
+ if (TARGET GTK2::${_depend})
+ list(APPEND _valid_depends GTK2::${_depend})
+ endif()
+ if (_valid_depends)
+ set_property(TARGET GTK2::${_basename} APPEND PROPERTY ${_property} "${_valid_depends}")
+ endif()
+ set(_valid_depends)
+ endforeach()
+ endif()
+endfunction()
+
+function(_GTK2_ADD_TARGET_DEPENDS _var)
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "_GTK2_ADD_TARGET_DEPENDS( ${_var} )")
+ endif()
+
+ string(TOLOWER "${_var}" _basename)
+
+ if(TARGET GTK2::${_basename})
+ get_target_property(_configs GTK2::${_basename} IMPORTED_CONFIGURATIONS)
+ _GTK2_ADD_TARGET_DEPENDS_INTERNAL(${_var} INTERFACE_LINK_LIBRARIES ${ARGN})
+ foreach(_config ${_configs})
+ _GTK2_ADD_TARGET_DEPENDS_INTERNAL(${_var} IMPORTED_LINK_INTERFACE_LIBRARIES_${_config} ${ARGN})
+ endforeach()
+ endif()
+endfunction()
+
+function(_GTK2_ADD_TARGET_INCLUDE_DIRS _var)
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "_GTK2_ADD_TARGET_INCLUDE_DIRS( ${_var} )")
+ endif()
+
+ string(TOLOWER "${_var}" _basename)
+
+ if(TARGET GTK2::${_basename})
+ foreach(_include ${ARGN})
+ set_property(TARGET GTK2::${_basename} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${_include}")
+ endforeach()
+ endif()
+endfunction()
+
+#=============================================================
+# _GTK2_ADD_TARGET
+# Internal function to create targets for GTK2
+# _var = target to create
+#=============================================================
+function(_GTK2_ADD_TARGET _var)
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "_GTK2_ADD_TARGET( ${_var} )")
+ endif()
+
+ string(TOLOWER "${_var}" _basename)
+
+ cmake_parse_arguments(_${_var} "" "" "GTK2_DEPENDS;GTK2_OPTIONAL_DEPENDS;OPTIONAL_INCLUDES" ${ARGN})
+
+ if(GTK2_${_var}_FOUND AND NOT TARGET GTK2::${_basename})
+ # Do not create the target if dependencies are missing
+ foreach(_dep ${_${_var}_GTK2_DEPENDS})
+ if(NOT TARGET GTK2::${_dep})
+ return()
+ endif()
+ endforeach()
+
+ add_library(GTK2::${_basename} UNKNOWN IMPORTED)
+
+ 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}" )
+ endif()
+
+ if(GTK2_${_var}_LIBRARY_DEBUG)
+ set_property(TARGET GTK2::${_basename} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+ set_property(TARGET GTK2::${_basename} PROPERTY IMPORTED_LOCATION_DEBUG "${GTK2_${_var}_LIBRARY_DEBUG}" )
+ endif()
+
+ if(GTK2_${_var}_INCLUDE_DIR)
+ set_property(TARGET GTK2::${_basename} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GTK2_${_var}_INCLUDE_DIR}")
+ endif()
+
+ if(GTK2_${_var}CONFIG_INCLUDE_DIR AND NOT "x${GTK2_${_var}CONFIG_INCLUDE_DIR}" STREQUAL "x${GTK2_${_var}_INCLUDE_DIR}")
+ set_property(TARGET GTK2::${_basename} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GTK2_${_var}CONFIG_INCLUDE_DIR}")
+ endif()
+
+ if(GTK2_DEFINITIONS)
+ set_property(TARGET GTK2::${_basename} PROPERTY INTERFACE_COMPILE_DEFINITIONS "${GTK2_DEFINITIONS}")
+ endif()
+
+ if(_${_var}_GTK2_DEPENDS)
+ _GTK2_ADD_TARGET_DEPENDS(${_var} ${_${_var}_GTK2_DEPENDS} ${_${_var}_GTK2_OPTIONAL_DEPENDS})
+ endif()
+
+ if(_${_var}_OPTIONAL_INCLUDES)
+ foreach(_D ${_${_var}_OPTIONAL_INCLUDES})
+ if(_D)
+ _GTK2_ADD_TARGET_INCLUDE_DIRS(${_var} ${_D})
+ endif()
+ endforeach()
+ endif()
+
+ if(GTK2_USE_IMPORTED_TARGETS)
+ set(GTK2_${_var}_LIBRARY GTK2::${_basename} PARENT_SCOPE)
+ endif()
+
+ endif()
+endfunction()
+
+
+
+#=============================================================
+
+#
+# main()
+#
+
+set(GTK2_FOUND)
+set(GTK2_INCLUDE_DIRS)
+set(GTK2_LIBRARIES)
+set(GTK2_DEFINITIONS)
+
+if(NOT GTK2_FIND_COMPONENTS)
+ # Assume they only want GTK
+ set(GTK2_FIND_COMPONENTS gtk)
+endif()
+
+#
+# If specified, enforce version number
+#
+if(GTK2_FIND_VERSION)
+ set(GTK2_FAILED_VERSION_CHECK true)
+ if(GTK2_DEBUG)
+ message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
+ "Searching for version ${GTK2_FIND_VERSION}")
+ endif()
+ _GTK2_FIND_INCLUDE_DIR(GTK gtk/gtk.h)
+ if(GTK2_GTK_INCLUDE_DIR)
+ _GTK2_GET_VERSION(GTK2_MAJOR_VERSION
+ GTK2_MINOR_VERSION
+ GTK2_PATCH_VERSION
+ ${GTK2_GTK_INCLUDE_DIR}/gtk/gtkversion.h)
+ set(GTK2_VERSION
+ ${GTK2_MAJOR_VERSION}.${GTK2_MINOR_VERSION}.${GTK2_PATCH_VERSION})
+ if(GTK2_FIND_VERSION_EXACT)
+ if(GTK2_VERSION VERSION_EQUAL GTK2_FIND_VERSION)
+ set(GTK2_FAILED_VERSION_CHECK false)
+ endif()
+ else()
+ if(GTK2_VERSION VERSION_EQUAL GTK2_FIND_VERSION OR
+ GTK2_VERSION VERSION_GREATER GTK2_FIND_VERSION)
+ set(GTK2_FAILED_VERSION_CHECK false)
+ endif()
+ endif()
+ else()
+ # If we can't find the GTK include dir, we can't do version checking
+ if(GTK2_FIND_REQUIRED AND NOT GTK2_FIND_QUIETLY)
+ message(FATAL_ERROR "Could not find GTK2 include directory")
+ endif()
+ return()
+ endif()
+
+ if(GTK2_FAILED_VERSION_CHECK)
+ if(GTK2_FIND_REQUIRED AND NOT GTK2_FIND_QUIETLY)
+ if(GTK2_FIND_VERSION_EXACT)
+ message(FATAL_ERROR "GTK2 version check failed. Version ${GTK2_VERSION} was found, version ${GTK2_FIND_VERSION} is needed exactly.")
+ else()
+ message(FATAL_ERROR "GTK2 version check failed. Version ${GTK2_VERSION} was found, at least version ${GTK2_FIND_VERSION} is required")
+ endif()
+ endif()
+
+ # If the version check fails, exit out of the module here
+ return()
+ endif()
+endif()
+
+#
+# On MSVC, according to https://wiki.gnome.org/gtkmm/MSWindows, the /vd2 flag needs to be
+# passed to the compiler in order to use gtkmm
+#
+if(MSVC)
+ foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
+ if(_GTK2_component STREQUAL "gtkmm")
+ set(GTK2_DEFINITIONS "/vd2")
+ elseif(_GTK2_component STREQUAL "glademm")
+ set(GTK2_DEFINITIONS "/vd2")
+ endif()
+ endforeach()
+endif()
+
+#
+# Find all components
+#
+
+find_package(Freetype QUIET)
+if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
+ list(APPEND GTK2_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2})
+endif()
+
+foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
+ if(_GTK2_component STREQUAL "gtk")
+ # Left for compatibility with previous versions.
+ _GTK2_FIND_INCLUDE_DIR(FONTCONFIG fontconfig/fontconfig.h)
+ _GTK2_FIND_INCLUDE_DIR(X11 X11/Xlib.h)
+
+ _GTK2_FIND_INCLUDE_DIR(GLIB glib.h)
+ _GTK2_FIND_INCLUDE_DIR(GLIBCONFIG glibconfig.h)
+ _GTK2_FIND_LIBRARY (GLIB glib false true)
+ _GTK2_ADD_TARGET (GLIB)
+
+ _GTK2_FIND_INCLUDE_DIR(GOBJECT glib-object.h)
+ _GTK2_FIND_LIBRARY (GOBJECT gobject false true)
+ _GTK2_ADD_TARGET (GOBJECT GTK2_DEPENDS glib)
+
+ _GTK2_FIND_INCLUDE_DIR(ATK atk/atk.h)
+ _GTK2_FIND_LIBRARY (ATK atk false true)
+ _GTK2_ADD_TARGET (ATK GTK2_DEPENDS gobject glib)
+
+ _GTK2_FIND_LIBRARY (GIO gio false true)
+ _GTK2_ADD_TARGET (GIO GTK2_DEPENDS gobject glib)
+
+ _GTK2_FIND_LIBRARY (GTHREAD gthread false true)
+ _GTK2_ADD_TARGET (GTHREAD GTK2_DEPENDS glib)
+
+ _GTK2_FIND_LIBRARY (GMODULE gmodule false true)
+ _GTK2_ADD_TARGET (GMODULE GTK2_DEPENDS glib)
+
+ _GTK2_FIND_INCLUDE_DIR(GDK_PIXBUF gdk-pixbuf/gdk-pixbuf.h)
+ _GTK2_FIND_LIBRARY (GDK_PIXBUF gdk_pixbuf false true)
+ _GTK2_ADD_TARGET (GDK_PIXBUF GTK2_DEPENDS gobject glib)
+
+ _GTK2_FIND_INCLUDE_DIR(CAIRO cairo.h)
+ _GTK2_FIND_LIBRARY (CAIRO cairo false false)
+ _GTK2_ADD_TARGET (CAIRO)
+
+ _GTK2_FIND_INCLUDE_DIR(PANGO pango/pango.h)
+ _GTK2_FIND_LIBRARY (PANGO pango false true)
+ _GTK2_ADD_TARGET (PANGO GTK2_DEPENDS gobject glib)
+
+ _GTK2_FIND_LIBRARY (PANGOCAIRO pangocairo false true)
+ _GTK2_ADD_TARGET (PANGOCAIRO GTK2_DEPENDS pango cairo gobject glib)
+
+ _GTK2_FIND_LIBRARY (PANGOFT2 pangoft2 false true)
+ _GTK2_ADD_TARGET (PANGOFT2 GTK2_DEPENDS pango gobject glib
+ OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
+ ${GTK2_FONTCONFIG_INCLUDE_DIR}
+ ${GTK2_X11_INCLUDE_DIR})
+
+ _GTK2_FIND_LIBRARY (PANGOXFT pangoxft false true)
+ _GTK2_ADD_TARGET (PANGOXFT GTK2_DEPENDS pangoft2 pango gobject glib
+ OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
+ ${GTK2_FONTCONFIG_INCLUDE_DIR}
+ ${GTK2_X11_INCLUDE_DIR})
+
+ _GTK2_FIND_INCLUDE_DIR(GDK gdk/gdk.h)
+ _GTK2_FIND_INCLUDE_DIR(GDKCONFIG gdkconfig.h)
+ if(UNIX)
+ if(APPLE)
+ _GTK2_FIND_LIBRARY (GDK gdk-quartz false true)
+ endif()
+ if(NOT GTK2_GDK_FOUND)
+ _GTK2_FIND_LIBRARY (GDK gdk-x11 false true)
+ endif()
+ else()
+ _GTK2_FIND_LIBRARY (GDK gdk-win32 false true)
+ endif()
+ _GTK2_ADD_TARGET (GDK GTK2_DEPENDS pango gdk_pixbuf gobject glib
+ GTK2_OPTIONAL_DEPENDS pangocairo cairo)
+
+ _GTK2_FIND_INCLUDE_DIR(GTK gtk/gtk.h)
+ if(UNIX)
+ if(APPLE)
+ _GTK2_FIND_LIBRARY (GTK gtk-quartz false true)
+ endif()
+ if(NOT GTK2_GTK_FOUND)
+ _GTK2_FIND_LIBRARY (GTK gtk-x11 false true)
+ endif()
+ else()
+ _GTK2_FIND_LIBRARY (GTK gtk-win32 false true)
+ endif()
+ _GTK2_ADD_TARGET (GTK GTK2_DEPENDS gdk atk pangoft2 pango gdk_pixbuf gthread gobject glib
+ GTK2_OPTIONAL_DEPENDS gio pangocairo cairo)
+
+ elseif(_GTK2_component STREQUAL "gtkmm")
+
+ _GTK2_FIND_INCLUDE_DIR(SIGC++ sigc++/sigc++.h)
+ _GTK2_FIND_INCLUDE_DIR(SIGC++CONFIG sigc++config.h)
+ _GTK2_FIND_LIBRARY (SIGC++ sigc true true)
+ _GTK2_ADD_TARGET (SIGC++)
+
+ _GTK2_FIND_INCLUDE_DIR(GLIBMM glibmm.h)
+ _GTK2_FIND_INCLUDE_DIR(GLIBMMCONFIG glibmmconfig.h)
+ _GTK2_FIND_LIBRARY (GLIBMM glibmm true true)
+ _GTK2_ADD_TARGET (GLIBMM GTK2_DEPENDS gobject sigc++ glib)
+
+ _GTK2_FIND_INCLUDE_DIR(GIOMM giomm.h)
+ _GTK2_FIND_INCLUDE_DIR(GIOMMCONFIG giommconfig.h)
+ _GTK2_FIND_LIBRARY (GIOMM giomm true true)
+ _GTK2_ADD_TARGET (GIOMM GTK2_DEPENDS gio glibmm gobject sigc++ glib)
+
+ _GTK2_FIND_INCLUDE_DIR(ATKMM atkmm.h)
+ _GTK2_FIND_LIBRARY (ATKMM atkmm true true)
+ _GTK2_ADD_TARGET (ATKMM GTK2_DEPENDS atk glibmm gobject sigc++ glib)
+
+ _GTK2_FIND_INCLUDE_DIR(CAIROMM cairomm/cairomm.h)
+ _GTK2_FIND_INCLUDE_DIR(CAIROMMCONFIG cairommconfig.h)
+ _GTK2_FIND_LIBRARY (CAIROMM cairomm true true)
+ _GTK2_ADD_TARGET (CAIROMM GTK2_DEPENDS cairo sigc++
+ OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
+ ${GTK2_FONTCONFIG_INCLUDE_DIR}
+ ${GTK2_X11_INCLUDE_DIR})
+
+ _GTK2_FIND_INCLUDE_DIR(PANGOMM pangomm.h)
+ _GTK2_FIND_INCLUDE_DIR(PANGOMMCONFIG pangommconfig.h)
+ _GTK2_FIND_LIBRARY (PANGOMM pangomm true true)
+ _GTK2_ADD_TARGET (PANGOMM GTK2_DEPENDS glibmm sigc++ pango gobject glib
+ GTK2_OPTIONAL_DEPENDS cairomm pangocairo cairo
+ OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
+ ${GTK2_FONTCONFIG_INCLUDE_DIR}
+ ${GTK2_X11_INCLUDE_DIR})
+
+ _GTK2_FIND_INCLUDE_DIR(GDKMM gdkmm.h)
+ _GTK2_FIND_INCLUDE_DIR(GDKMMCONFIG gdkmmconfig.h)
+ _GTK2_FIND_LIBRARY (GDKMM gdkmm true true)
+ _GTK2_ADD_TARGET (GDKMM GTK2_DEPENDS pangomm gtk glibmm sigc++ gdk atk pangoft2 gdk_pixbuf pango gobject glib
+ GTK2_OPTIONAL_DEPENDS giomm cairomm gio pangocairo cairo
+ OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
+ ${GTK2_FONTCONFIG_INCLUDE_DIR}
+ ${GTK2_X11_INCLUDE_DIR})
+
+ _GTK2_FIND_INCLUDE_DIR(GTKMM gtkmm.h)
+ _GTK2_FIND_INCLUDE_DIR(GTKMMCONFIG gtkmmconfig.h)
+ _GTK2_FIND_LIBRARY (GTKMM gtkmm true true)
+ _GTK2_ADD_TARGET (GTKMM GTK2_DEPENDS atkmm gdkmm pangomm gtk glibmm sigc++ gdk atk pangoft2 gdk_pixbuf pango gthread gobject glib
+ GTK2_OPTIONAL_DEPENDS giomm cairomm gio pangocairo cairo
+ OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
+ ${GTK2_FONTCONFIG_INCLUDE_DIR}
+ ${GTK2_X11_INCLUDE_DIR})
+
+ elseif(_GTK2_component STREQUAL "glade")
+
+ _GTK2_FIND_INCLUDE_DIR(GLADE glade/glade.h)
+ _GTK2_FIND_LIBRARY (GLADE glade false true)
+ _GTK2_ADD_TARGET (GLADE GTK2_DEPENDS gtk gdk atk gio pangoft2 gdk_pixbuf pango gobject glib
+ GTK2_OPTIONAL_DEPENDS pangocairo cairo
+ OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
+ ${GTK2_FONTCONFIG_INCLUDE_DIR}
+ ${GTK2_X11_INCLUDE_DIR})
+
+ elseif(_GTK2_component STREQUAL "glademm")
+
+ _GTK2_FIND_INCLUDE_DIR(GLADEMM libglademm.h)
+ _GTK2_FIND_INCLUDE_DIR(GLADEMMCONFIG libglademmconfig.h)
+ _GTK2_FIND_LIBRARY (GLADEMM glademm true true)
+ _GTK2_ADD_TARGET (GLADEMM GTK2_DEPENDS gtkmm glade atkmm gdkmm giomm pangomm glibmm sigc++ gtk gdk atk pangoft2 gdk_pixbuf pango gthread gobject glib
+ GTK2_OPTIONAL_DEPENDS giomm cairomm gio pangocairo cairo
+ OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
+ ${GTK2_FONTCONFIG_INCLUDE_DIR}
+ ${GTK2_X11_INCLUDE_DIR})
+
+ else()
+ message(FATAL_ERROR "Unknown GTK2 component ${_component}")
+ endif()
+endforeach()
+
+#
+# Solve for the GTK2 version if we haven't already
+#
+if(NOT GTK2_FIND_VERSION AND GTK2_GTK_INCLUDE_DIR)
+ _GTK2_GET_VERSION(GTK2_MAJOR_VERSION
+ GTK2_MINOR_VERSION
+ GTK2_PATCH_VERSION
+ ${GTK2_GTK_INCLUDE_DIR}/gtk/gtkversion.h)
+ set(GTK2_VERSION ${GTK2_MAJOR_VERSION}.${GTK2_MINOR_VERSION}.${GTK2_PATCH_VERSION})
+endif()
+
+#
+# Try to enforce components
+#
+
+set(_GTK2_did_we_find_everything true) # This gets set to GTK2_FOUND
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
+ string(TOUPPER ${_GTK2_component} _COMPONENT_UPPER)
+
+ set(GTK2_${_COMPONENT_UPPER}_FIND_QUIETLY ${GTK2_FIND_QUIETLY})
+
+ if(_GTK2_component STREQUAL "gtk")
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtk libraries were not found."
+ GTK2_GTK_LIBRARY
+ GTK2_GTK_INCLUDE_DIR
+
+ GTK2_GDK_INCLUDE_DIR
+ GTK2_GDKCONFIG_INCLUDE_DIR
+ GTK2_GDK_LIBRARY
+
+ GTK2_GLIB_INCLUDE_DIR
+ GTK2_GLIBCONFIG_INCLUDE_DIR
+ GTK2_GLIB_LIBRARY
+ )
+ elseif(_GTK2_component STREQUAL "gtkmm")
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtkmm libraries were not found."
+ GTK2_GTKMM_LIBRARY
+ GTK2_GTKMM_INCLUDE_DIR
+ GTK2_GTKMMCONFIG_INCLUDE_DIR
+
+ GTK2_GDKMM_INCLUDE_DIR
+ GTK2_GDKMMCONFIG_INCLUDE_DIR
+ GTK2_GDKMM_LIBRARY
+
+ GTK2_GLIBMM_INCLUDE_DIR
+ GTK2_GLIBMMCONFIG_INCLUDE_DIR
+ GTK2_GLIBMM_LIBRARY
+
+ FREETYPE_INCLUDE_DIR_ft2build
+ FREETYPE_INCLUDE_DIR_freetype2
+ )
+ elseif(_GTK2_component STREQUAL "glade")
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glade library was not found."
+ GTK2_GLADE_LIBRARY
+ GTK2_GLADE_INCLUDE_DIR
+ )
+ elseif(_GTK2_component STREQUAL "glademm")
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glademm library was not found."
+ GTK2_GLADEMM_LIBRARY
+ GTK2_GLADEMM_INCLUDE_DIR
+ GTK2_GLADEMMCONFIG_INCLUDE_DIR
+ )
+ endif()
+
+ if(NOT GTK2_${_COMPONENT_UPPER}_FOUND)
+ set(_GTK2_did_we_find_everything false)
+ endif()
+endforeach()
+
+if(_GTK2_did_we_find_everything AND NOT GTK2_VERSION_CHECK_FAILED)
+ set(GTK2_FOUND true)
+else()
+ # Unset our variables.
+ set(GTK2_FOUND false)
+ set(GTK2_VERSION)
+ set(GTK2_VERSION_MAJOR)
+ set(GTK2_VERSION_MINOR)
+ set(GTK2_VERSION_PATCH)
+ set(GTK2_INCLUDE_DIRS)
+ set(GTK2_LIBRARIES)
+ set(GTK2_DEFINITIONS)
+endif()
+
+if(GTK2_INCLUDE_DIRS)
+ list(REMOVE_DUPLICATES GTK2_INCLUDE_DIRS)
+endif()
+
diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake
new file mode 100644
index 0000000000..e6b5b0aaf3
--- /dev/null
+++ b/Modules/FindGTest.cmake
@@ -0,0 +1,212 @@
+#.rst:
+# FindGTest
+# ---------
+#
+# Locate the Google C++ Testing Framework.
+#
+# Defines the following variables:
+#
+# ::
+#
+# GTEST_FOUND - Found the Google Testing framework
+# GTEST_INCLUDE_DIRS - Include directories
+#
+#
+#
+# Also defines the library variables below as normal variables. These
+# contain debug/optimized keywords when a debugging library is found.
+#
+# ::
+#
+# GTEST_BOTH_LIBRARIES - Both libgtest & libgtest-main
+# GTEST_LIBRARIES - libgtest
+# GTEST_MAIN_LIBRARIES - libgtest-main
+#
+#
+#
+# Accepts the following variables as input:
+#
+# ::
+#
+# GTEST_ROOT - (as a CMake or environment variable)
+# The root directory of the gtest install prefix
+#
+#
+#
+# ::
+#
+# 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")
+#
+#
+#
+# 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})
+#
+#
+#
+# ::
+#
+# add_test(AllTestsInFoo foo)
+#
+#
+#
+#
+#
+# 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)
+#
+# ::
+#
+# 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.
+#
+#
+#
+# ::
+#
+# Example:
+# set(FooTestArgs --foo 1 --bar 2)
+# add_executable(FooTest FooUnitTest.cc)
+# GTEST_ADD_TESTS(FooTest "${FooTestArgs}" AUTO)
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2009 Philip Lowman <philip@yhbt.com>
+# Copyright 2009 Daniel Blezek <blezek@gmail.com>
+#
+# 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.)
+#
+# Thanks to Daniel Blezek <blezek@gmail.com> for the GTEST_ADD_TESTS code
+
+function(GTEST_ADD_TESTS executable extra_args)
+ if(NOT ARGN)
+ message(FATAL_ERROR "Missing ARGN: Read the documentation for GTEST_ADD_TESTS")
+ endif()
+ if(ARGN STREQUAL "AUTO")
+ # obtain sources used for building that executable
+ get_property(ARGN TARGET ${executable} PROPERTY SOURCES)
+ endif()
+ set(gtest_case_name_regex ".*\\( *([A-Za-z_0-9]+), *([A-Za-z_0-9]+) *\\).*")
+ set(gtest_test_type_regex "(TYPED_TEST|TEST_?[FP]?)")
+ foreach(source ${ARGN})
+ file(READ "${source}" contents)
+ string(REGEX MATCHALL "${gtest_test_type_regex}\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
+ foreach(hit ${found_tests})
+ string(REGEX MATCH "${gtest_test_type_regex}" test_type ${hit})
+
+ # Parameterized tests have a different signature for the filter
+ if(${test_type} STREQUAL "TEST_P")
+ string(REGEX REPLACE ${gtest_case_name_regex} "*/\\1.\\2/*" test_name ${hit})
+ elseif(${test_type} STREQUAL "TEST_F" OR ${test_type} STREQUAL "TEST")
+ string(REGEX REPLACE ${gtest_case_name_regex} "\\1.\\2" test_name ${hit})
+ elseif(${test_type} STREQUAL "TYPED_TEST")
+ string(REGEX REPLACE ${gtest_case_name_regex} "\\1/*.\\2" test_name ${hit})
+ else()
+ message(WARNING "Could not parse GTest ${hit} for adding to CTest.")
+ continue()
+ endif()
+ add_test(NAME ${test_name} COMMAND ${executable} --gtest_filter=${test_name} ${extra_args})
+ endforeach()
+ endforeach()
+endfunction()
+
+function(_gtest_append_debugs _endvar _library)
+ if(${_library} AND ${_library}_DEBUG)
+ set(_output optimized ${${_library}} debug ${${_library}_DEBUG})
+ else()
+ set(_output ${${_library}})
+ endif()
+ set(${_endvar} ${_output} PARENT_SCOPE)
+endfunction()
+
+function(_gtest_find_library _name)
+ find_library(${_name}
+ NAMES ${ARGN}
+ HINTS
+ ENV GTEST_ROOT
+ ${GTEST_ROOT}
+ PATH_SUFFIXES ${_gtest_libpath_suffixes}
+ )
+ mark_as_advanced(${_name})
+endfunction()
+
+#
+
+if(NOT DEFINED GTEST_MSVC_SEARCH)
+ set(GTEST_MSVC_SEARCH MD)
+endif()
+
+set(_gtest_libpath_suffixes lib)
+if(MSVC)
+ if(GTEST_MSVC_SEARCH STREQUAL "MD")
+ list(APPEND _gtest_libpath_suffixes
+ msvc/gtest-md/Debug
+ msvc/gtest-md/Release)
+ elseif(GTEST_MSVC_SEARCH STREQUAL "MT")
+ list(APPEND _gtest_libpath_suffixes
+ msvc/gtest/Debug
+ msvc/gtest/Release)
+ endif()
+endif()
+
+
+find_path(GTEST_INCLUDE_DIR gtest/gtest.h
+ HINTS
+ $ENV{GTEST_ROOT}/include
+ ${GTEST_ROOT}/include
+)
+mark_as_advanced(GTEST_INCLUDE_DIR)
+
+if(MSVC AND GTEST_MSVC_SEARCH STREQUAL "MD")
+ # The provided /MD project files for Google Test add -md suffixes to the
+ # library names.
+ _gtest_find_library(GTEST_LIBRARY gtest-md gtest)
+ _gtest_find_library(GTEST_LIBRARY_DEBUG gtest-mdd gtestd)
+ _gtest_find_library(GTEST_MAIN_LIBRARY gtest_main-md gtest_main)
+ _gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_main-mdd gtest_maind)
+else()
+ _gtest_find_library(GTEST_LIBRARY gtest)
+ _gtest_find_library(GTEST_LIBRARY_DEBUG gtestd)
+ _gtest_find_library(GTEST_MAIN_LIBRARY gtest_main)
+ _gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_maind)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTest DEFAULT_MSG GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
+
+if(GTEST_FOUND)
+ set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIR})
+ _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()
+
diff --git a/Modules/FindGettext.cmake b/Modules/FindGettext.cmake
new file mode 100644
index 0000000000..16478cbdf4
--- /dev/null
+++ b/Modules/FindGettext.cmake
@@ -0,0 +1,234 @@
+#.rst:
+# FindGettext
+# -----------
+#
+# Find GNU gettext tools
+#
+# This module looks for the GNU gettext tools. This module defines the
+# following values:
+#
+# ::
+#
+# GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool.
+# GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool.
+# GETTEXT_FOUND: True if gettext has been found.
+# GETTEXT_VERSION_STRING: the version of gettext found (since CMake 2.8.8)
+#
+#
+#
+# Additionally it provides the following macros:
+# GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] file1 ... fileN )
+#
+# ::
+#
+# This will create a target "translations" which will convert the
+# given input po files into the binary output mo file. If the
+# ALL option is used, the translations will also be created when
+# building the default target.
+#
+# GETTEXT_PROCESS_POT_FILE( <potfile> [ALL] [INSTALL_DESTINATION <destdir>]
+# LANGUAGES <lang1> <lang2> ... )
+#
+# ::
+#
+# Process the given pot file to mo files.
+# If INSTALL_DESTINATION is given then automatically install rules will be created,
+# the language subdirectory will be taken into account (by default use share/locale/).
+# If ALL is specified, the pot file is processed when building the all traget.
+# It creates a custom target "potfile".
+#
+# GETTEXT_PROCESS_PO_FILES( <lang> [ALL] [INSTALL_DESTINATION <dir>]
+# PO_FILES <po1> <po2> ... )
+#
+# ::
+#
+# Process the given po files to mo files for the given language.
+# If INSTALL_DESTINATION is given then automatically install rules will be created,
+# the language subdirectory will be taken into account (by default use share/locale/).
+# If ALL is specified, the po files are processed when building the all traget.
+# It creates a custom target "pofiles".
+
+#=============================================================================
+# Copyright 2007-2009 Kitware, Inc.
+# Copyright 2007 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+find_program(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
+
+find_program(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
+
+if(GETTEXT_MSGMERGE_EXECUTABLE)
+ execute_process(COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --version
+ OUTPUT_VARIABLE gettext_version
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if (gettext_version MATCHES "^msgmerge \\([^\\)]*\\) ([0-9\\.]+[^ \n]*)")
+ set(GETTEXT_VERSION_STRING "${CMAKE_MATCH_1}")
+ endif()
+ unset(gettext_version)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gettext
+ REQUIRED_VARS GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE
+ VERSION_VAR GETTEXT_VERSION_STRING)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
+
+function(_GETTEXT_GET_UNIQUE_TARGET_NAME _name _unique_name)
+ set(propertyName "_GETTEXT_UNIQUE_COUNTER_${_name}")
+ get_property(currentCounter GLOBAL PROPERTY "${propertyName}")
+ if(NOT currentCounter)
+ set(currentCounter 1)
+ endif()
+ set(${_unique_name} "${_name}_${currentCounter}" PARENT_SCOPE)
+ math(EXPR currentCounter "${currentCounter} + 1")
+ set_property(GLOBAL PROPERTY ${propertyName} ${currentCounter} )
+endfunction()
+
+macro(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg)
+ # make it a real variable, so we can modify it here
+ set(_firstPoFile "${_firstPoFileArg}")
+
+ set(_gmoFiles)
+ get_filename_component(_potName ${_potFile} NAME)
+ string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _potBasename ${_potName})
+ get_filename_component(_absPotFile ${_potFile} ABSOLUTE)
+
+ set(_addToAll)
+ if(${_firstPoFile} STREQUAL "ALL")
+ set(_addToAll "ALL")
+ set(_firstPoFile)
+ endif()
+
+ foreach (_currentPoFile ${_firstPoFile} ${ARGN})
+ get_filename_component(_absFile ${_currentPoFile} ABSOLUTE)
+ get_filename_component(_abs_PATH ${_absFile} PATH)
+ get_filename_component(_lang ${_absFile} NAME_WE)
+ set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
+
+ add_custom_command(
+ OUTPUT ${_gmoFile}
+ COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile}
+ COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
+ DEPENDS ${_absPotFile} ${_absFile}
+ )
+
+ install(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
+ set(_gmoFiles ${_gmoFiles} ${_gmoFile})
+
+ endforeach ()
+
+ if(NOT TARGET translations)
+ add_custom_target(translations)
+ endif()
+
+ _GETTEXT_GET_UNIQUE_TARGET_NAME(translations uniqueTargetName)
+
+ add_custom_target(${uniqueTargetName} ${_addToAll} DEPENDS ${_gmoFiles})
+
+ add_dependencies(translations ${uniqueTargetName})
+
+endmacro()
+
+
+function(GETTEXT_PROCESS_POT_FILE _potFile)
+ set(_gmoFiles)
+ set(_options ALL)
+ set(_oneValueArgs INSTALL_DESTINATION)
+ set(_multiValueArgs LANGUAGES)
+
+ CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
+
+ get_filename_component(_potName ${_potFile} NAME)
+ string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _potBasename ${_potName})
+ get_filename_component(_absPotFile ${_potFile} ABSOLUTE)
+
+ foreach (_lang ${_parsedArguments_LANGUAGES})
+ set(_poFile "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.po")
+ set(_gmoFile "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo")
+
+ add_custom_command(
+ OUTPUT "${_poFile}"
+ COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_poFile} ${_absPotFile}
+ DEPENDS ${_absPotFile}
+ )
+
+ add_custom_command(
+ OUTPUT "${_gmoFile}"
+ COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_poFile}
+ DEPENDS ${_absPotFile} ${_poFile}
+ )
+
+ if(_parsedArguments_INSTALL_DESTINATION)
+ install(FILES ${_gmoFile} DESTINATION ${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
+ endif()
+ list(APPEND _gmoFiles ${_gmoFile})
+ endforeach ()
+
+ if(NOT TARGET potfiles)
+ add_custom_target(potfiles)
+ endif()
+
+ _GETTEXT_GET_UNIQUE_TARGET_NAME( potfiles uniqueTargetName)
+
+ if(_parsedArguments_ALL)
+ add_custom_target(${uniqueTargetName} ALL DEPENDS ${_gmoFiles})
+ else()
+ add_custom_target(${uniqueTargetName} DEPENDS ${_gmoFiles})
+ endif()
+
+ add_dependencies(potfiles ${uniqueTargetName})
+
+endfunction()
+
+
+function(GETTEXT_PROCESS_PO_FILES _lang)
+ set(_options ALL)
+ set(_oneValueArgs INSTALL_DESTINATION)
+ set(_multiValueArgs PO_FILES)
+ set(_gmoFiles)
+
+ CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
+
+ foreach(_current_PO_FILE ${_parsedArguments_PO_FILES})
+ get_filename_component(_name ${_current_PO_FILE} NAME)
+ string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _basename ${_name})
+ set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo)
+ add_custom_command(OUTPUT ${_gmoFile}
+ COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_current_PO_FILE}
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ DEPENDS ${_current_PO_FILE}
+ )
+
+ if(_parsedArguments_INSTALL_DESTINATION)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo DESTINATION ${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES/ RENAME ${_basename}.mo)
+ endif()
+ list(APPEND _gmoFiles ${_gmoFile})
+ endforeach()
+
+
+ if(NOT TARGET pofiles)
+ add_custom_target(pofiles)
+ endif()
+
+ _GETTEXT_GET_UNIQUE_TARGET_NAME( pofiles uniqueTargetName)
+
+ if(_parsedArguments_ALL)
+ add_custom_target(${uniqueTargetName} ALL DEPENDS ${_gmoFiles})
+ else()
+ add_custom_target(${uniqueTargetName} DEPENDS ${_gmoFiles})
+ endif()
+
+ add_dependencies(pofiles ${uniqueTargetName})
+
+endfunction()
diff --git a/Modules/FindGit.cmake b/Modules/FindGit.cmake
new file mode 100644
index 0000000000..570538d7d4
--- /dev/null
+++ b/Modules/FindGit.cmake
@@ -0,0 +1,75 @@
+#.rst:
+# 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)
+#
+# Example usage:
+#
+# ::
+#
+# find_package(Git)
+# if(GIT_FOUND)
+# message("git found: ${GIT_EXECUTABLE}")
+# endif()
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+# Look for 'git' or 'eg' (easy git)
+#
+set(git_names git eg)
+
+# Prefer .cmd variants on Windows unless running in a Makefile
+# in the MSYS shell.
+#
+if(WIN32)
+ if(NOT CMAKE_GENERATOR MATCHES "MSYS")
+ set(git_names git.cmd git eg.cmd eg)
+ endif()
+endif()
+
+find_program(GIT_EXECUTABLE
+ NAMES ${git_names}
+ PATH_SUFFIXES Git/cmd Git/bin
+ DOC "git command line client"
+ )
+mark_as_advanced(GIT_EXECUTABLE)
+
+if(GIT_EXECUTABLE)
+ execute_process(COMMAND ${GIT_EXECUTABLE} --version
+ OUTPUT_VARIABLE git_version
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if (git_version MATCHES "^git version [0-9]")
+ string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}")
+ endif()
+ unset(git_version)
+endif()
+
+# 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)
+find_package_handle_standard_args(Git
+ REQUIRED_VARS GIT_EXECUTABLE
+ VERSION_VAR GIT_VERSION_STRING)
diff --git a/Modules/FindGnuTLS.cmake b/Modules/FindGnuTLS.cmake
new file mode 100644
index 0000000000..4d94ffc5d9
--- /dev/null
+++ b/Modules/FindGnuTLS.cmake
@@ -0,0 +1,77 @@
+#.rst:
+# FindGnuTLS
+# ----------
+#
+# Try to find the GNU Transport Layer Security library (gnutls)
+#
+#
+#
+# Once done this will define
+#
+# ::
+#
+# GNUTLS_FOUND - System has gnutls
+# GNUTLS_INCLUDE_DIR - The gnutls include directory
+# GNUTLS_LIBRARIES - The libraries needed to use gnutls
+# GNUTLS_DEFINITIONS - Compiler switches required for using gnutls
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2009 Philip Lowman <philip@yhbt.com>
+# Copyright 2009 Brad Hards <bradh@kde.org>
+# Copyright 2006 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# Note that this doesn't try to find the gnutls-extra package.
+
+
+if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARY)
+ # in cache already
+ set(gnutls_FIND_QUIETLY TRUE)
+endif ()
+
+if (NOT WIN32)
+ # try using pkg-config to get the directories and then use these values
+ # in the find_path() and find_library() calls
+ # also fills in GNUTLS_DEFINITIONS, although that isn't normally useful
+ find_package(PkgConfig QUIET)
+ PKG_CHECK_MODULES(PC_GNUTLS QUIET gnutls)
+ set(GNUTLS_DEFINITIONS ${PC_GNUTLS_CFLAGS_OTHER})
+ set(GNUTLS_VERSION_STRING ${PC_GNUTLS_VERSION})
+endif ()
+
+find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h
+ HINTS
+ ${PC_GNUTLS_INCLUDEDIR}
+ ${PC_GNUTLS_INCLUDE_DIRS}
+ )
+
+find_library(GNUTLS_LIBRARY NAMES gnutls libgnutls
+ HINTS
+ ${PC_GNUTLS_LIBDIR}
+ ${PC_GNUTLS_LIBRARY_DIRS}
+ )
+
+mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY)
+
+# handle the QUIETLY and REQUIRED arguments and set GNUTLS_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GnuTLS
+ REQUIRED_VARS GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR
+ VERSION_VAR GNUTLS_VERSION_STRING)
+
+if(GNUTLS_FOUND)
+ set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY})
+ set(GNUTLS_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR})
+endif()
+
diff --git a/Modules/FindGnuplot.cmake b/Modules/FindGnuplot.cmake
new file mode 100644
index 0000000000..067604fc1c
--- /dev/null
+++ b/Modules/FindGnuplot.cmake
@@ -0,0 +1,67 @@
+#.rst:
+# FindGnuplot
+# -----------
+#
+# this module looks for gnuplot
+#
+#
+#
+# Once done this will define
+#
+# ::
+#
+# GNUPLOT_FOUND - system has Gnuplot
+# GNUPLOT_EXECUTABLE - the Gnuplot executable
+# GNUPLOT_VERSION_STRING - the version of Gnuplot found (since CMake 2.8.8)
+#
+#
+#
+# GNUPLOT_VERSION_STRING will not work for old versions like 3.7.1.
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
+
+find_program(GNUPLOT_EXECUTABLE
+ NAMES
+ gnuplot
+ pgnuplot
+ wgnupl32
+ PATHS
+ ${CYGWIN_INSTALL_PATH}/bin
+)
+
+if (GNUPLOT_EXECUTABLE)
+ execute_process(COMMAND "${GNUPLOT_EXECUTABLE}" --version
+ OUTPUT_VARIABLE GNUPLOT_OUTPUT_VARIABLE
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ string(REGEX REPLACE "^gnuplot ([0-9\\.]+)( patchlevel )?" "\\1." GNUPLOT_VERSION_STRING "${GNUPLOT_OUTPUT_VARIABLE}")
+ string(REGEX REPLACE "\\.$" "" GNUPLOT_VERSION_STRING "${GNUPLOT_VERSION_STRING}")
+ unset(GNUPLOT_OUTPUT_VARIABLE)
+endif()
+
+# for compatibility
+set(GNUPLOT ${GNUPLOT_EXECUTABLE})
+
+# handle the QUIETLY and REQUIRED arguments and set GNUPLOT_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gnuplot
+ REQUIRED_VARS GNUPLOT_EXECUTABLE
+ VERSION_VAR GNUPLOT_VERSION_STRING)
+
+mark_as_advanced( GNUPLOT_EXECUTABLE )
+
diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake
new file mode 100644
index 0000000000..0d58e132cc
--- /dev/null
+++ b/Modules/FindHDF5.cmake
@@ -0,0 +1,364 @@
+#.rst:
+# FindHDF5
+# --------
+#
+# Find HDF5, a library for reading and writing self describing array data.
+#
+#
+#
+# This module invokes the HDF5 wrapper compiler that should be installed
+# alongside HDF5. Depending upon the HDF5 Configuration, the wrapper
+# compiler is called either h5cc or h5pcc. If this succeeds, the module
+# will then call the compiler with the -show argument to see what flags
+# are used when compiling an HDF5 client application.
+#
+# The module will optionally accept the COMPONENTS argument. If no
+# COMPONENTS are specified, then the find module will default to finding
+# only the HDF5 C library. If one or more COMPONENTS are specified, the
+# module will attempt to find the language bindings for the specified
+# components. The only valid components are C, CXX, Fortran, HL, and
+# Fortran_HL. If the COMPONENTS argument is not given, the module will
+# attempt to find only the C bindings.
+#
+# On UNIX systems, this module will read the variable
+# HDF5_USE_STATIC_LIBRARIES to determine whether or not to prefer a
+# static link to a dynamic link for HDF5 and all of it's dependencies.
+# To use this feature, make sure that the HDF5_USE_STATIC_LIBRARIES
+# variable is set before the call to find_package.
+#
+# To provide the module with a hint about where to find your HDF5
+# installation, you can set the environment variable HDF5_ROOT. The
+# Find module will then look in this path when searching for HDF5
+# executables, paths, and libraries.
+#
+# In addition to finding the includes and libraries required to compile
+# an HDF5 client application, this module also makes an effort to find
+# tools that come with the HDF5 distribution that may be useful for
+# regression testing.
+#
+# This module will define the following variables:
+#
+# ::
+#
+# HDF5_INCLUDE_DIRS - Location of the hdf5 includes
+# HDF5_INCLUDE_DIR - Location of the hdf5 includes (deprecated)
+# HDF5_DEFINITIONS - Required compiler definitions for HDF5
+# HDF5_C_LIBRARIES - Required libraries for the HDF5 C bindings.
+# HDF5_CXX_LIBRARIES - Required libraries for the HDF5 C++ bindings
+# HDF5_Fortran_LIBRARIES - Required libraries for the HDF5 Fortran bindings
+# HDF5_HL_LIBRARIES - Required libraries for the HDF5 high level API
+# HDF5_Fortran_HL_LIBRARIES - Required libraries for the high level Fortran
+# bindings.
+# HDF5_LIBRARIES - Required libraries for all requested bindings
+# HDF5_FOUND - true if HDF5 was found on the system
+# HDF5_LIBRARY_DIRS - the full set of library directories
+# HDF5_IS_PARALLEL - Whether or not HDF5 was found with parallel IO support
+# HDF5_C_COMPILER_EXECUTABLE - the path to the HDF5 C wrapper compiler
+# HDF5_CXX_COMPILER_EXECUTABLE - the path to the HDF5 C++ wrapper compiler
+# HDF5_Fortran_COMPILER_EXECUTABLE - the path to the HDF5 Fortran wrapper compiler
+# HDF5_DIFF_EXECUTABLE - the path to the HDF5 dataset comparison tool
+
+#=============================================================================
+# Copyright 2009 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 module is maintained by Will Dicharry <wdicharry@stellarscience.com>.
+
+include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+# List of the valid HDF5 components
+set( HDF5_VALID_COMPONENTS
+ C
+ CXX
+ Fortran
+ HL
+ Fortran_HL
+)
+
+# Validate the list of find components.
+if( NOT HDF5_FIND_COMPONENTS )
+ set( HDF5_LANGUAGE_BINDINGS "C" )
+else()
+ # add the extra specified components, ensuring that they are valid.
+ foreach( component ${HDF5_FIND_COMPONENTS} )
+ list( FIND HDF5_VALID_COMPONENTS ${component} component_location )
+ if( ${component_location} EQUAL -1 )
+ message( FATAL_ERROR
+ "\"${component}\" is not a valid HDF5 component." )
+ else()
+ list( APPEND HDF5_LANGUAGE_BINDINGS ${component} )
+ endif()
+ endforeach()
+endif()
+
+# try to find the HDF5 wrapper compilers
+find_program( HDF5_C_COMPILER_EXECUTABLE
+ NAMES h5cc h5pcc
+ HINTS ENV HDF5_ROOT
+ PATH_SUFFIXES bin Bin
+ DOC "HDF5 Wrapper compiler. Used only to detect HDF5 compile flags." )
+mark_as_advanced( HDF5_C_COMPILER_EXECUTABLE )
+
+find_program( HDF5_CXX_COMPILER_EXECUTABLE
+ NAMES h5c++ h5pc++
+ HINTS ENV HDF5_ROOT
+ PATH_SUFFIXES bin Bin
+ DOC "HDF5 C++ Wrapper compiler. Used only to detect HDF5 compile flags." )
+mark_as_advanced( HDF5_CXX_COMPILER_EXECUTABLE )
+
+find_program( HDF5_Fortran_COMPILER_EXECUTABLE
+ NAMES h5fc h5pfc
+ HINTS ENV HDF5_ROOT
+ PATH_SUFFIXES bin Bin
+ DOC "HDF5 Fortran Wrapper compiler. Used only to detect HDF5 compile flags." )
+mark_as_advanced( HDF5_Fortran_COMPILER_EXECUTABLE )
+
+find_program( HDF5_DIFF_EXECUTABLE
+ NAMES h5diff
+ HINTS ENV HDF5_ROOT
+ PATH_SUFFIXES bin Bin
+ DOC "HDF5 file differencing tool." )
+mark_as_advanced( HDF5_DIFF_EXECUTABLE )
+
+# Invoke the HDF5 wrapper compiler. The compiler return value is stored to the
+# return_value argument, the text output is stored to the output variable.
+macro( _HDF5_invoke_compiler language output return_value )
+ if( HDF5_${language}_COMPILER_EXECUTABLE )
+ exec_program( ${HDF5_${language}_COMPILER_EXECUTABLE}
+ ARGS -show
+ OUTPUT_VARIABLE ${output}
+ RETURN_VALUE ${return_value}
+ )
+ if( ${${return_value}} EQUAL 0 )
+ # do nothing
+ else()
+ message( STATUS
+ "Unable to determine HDF5 ${language} flags from HDF5 wrapper." )
+ endif()
+ endif()
+endmacro()
+
+# Parse a compile line for definitions, includes, library paths, and libraries.
+macro( _HDF5_parse_compile_line
+ compile_line_var
+ include_paths
+ definitions
+ library_paths
+ libraries )
+
+ # Match the include paths
+ string( REGEX MATCHALL "-I([^\" ]+)" include_path_flags
+ "${${compile_line_var}}"
+ )
+ foreach( IPATH ${include_path_flags} )
+ string( REGEX REPLACE "^-I" "" IPATH ${IPATH} )
+ string( REPLACE "//" "/" IPATH ${IPATH} )
+ list( APPEND ${include_paths} ${IPATH} )
+ endforeach()
+
+ # Match the definitions
+ string( REGEX MATCHALL "-D[^ ]*" definition_flags "${${compile_line_var}}" )
+ foreach( DEF ${definition_flags} )
+ list( APPEND ${definitions} ${DEF} )
+ endforeach()
+
+ # Match the library paths
+ string( REGEX MATCHALL "-L([^\" ]+|\"[^\"]+\")" library_path_flags
+ "${${compile_line_var}}"
+ )
+
+ foreach( LPATH ${library_path_flags} )
+ string( REGEX REPLACE "^-L" "" LPATH ${LPATH} )
+ string( REPLACE "//" "/" LPATH ${LPATH} )
+ list( APPEND ${library_paths} ${LPATH} )
+ endforeach()
+
+ # now search for the library names specified in the compile line (match -l...)
+ # match only -l's preceded by a space or comma
+ # this is to exclude directory names like xxx-linux/
+ string( REGEX MATCHALL "[, ]-l([^\", ]+)" library_name_flags
+ "${${compile_line_var}}" )
+ # strip the -l from all of the library flags and add to the search list
+ foreach( LIB ${library_name_flags} )
+ string( REGEX REPLACE "^[, ]-l" "" LIB ${LIB} )
+ list( APPEND ${libraries} ${LIB} )
+ endforeach()
+endmacro()
+
+# Try to find HDF5 using an installed hdf5-config.cmake
+if( NOT HDF5_FOUND )
+ find_package( HDF5 QUIET NO_MODULE )
+ if( HDF5_FOUND )
+ set( HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR} )
+ set( HDF5_LIBRARIES )
+ set( HDF5_C_TARGET hdf5 )
+ set( HDF5_CXX_TARGET hdf5_cpp )
+ set( HDF5_HL_TARGET hdf5_hl )
+ set( HDF5_Fortran_TARGET hdf5_fortran )
+ set( HDF5_Fortran_HL_TARGET hdf5_hl_fortran )
+ foreach( _component ${HDF5_LANGUAGE_BINDINGS} )
+ list( FIND HDF5_VALID_COMPONENTS ${_component} _component_location )
+ get_target_property( _comp_location ${HDF5_${_component}_TARGET} LOCATION )
+ if( _comp_location )
+ set( HDF5_${_component}_LIBRARY ${_comp_location} CACHE PATH
+ "HDF5 ${_component} library" )
+ mark_as_advanced( HDF5_${_component}_LIBRARY )
+ list( APPEND HDF5_LIBRARIES ${HDF5_${_component}_LIBRARY} )
+ endif()
+ endforeach()
+ endif()
+endif()
+
+if( NOT HDF5_FOUND )
+ _HDF5_invoke_compiler( C HDF5_C_COMPILE_LINE HDF5_C_RETURN_VALUE )
+ _HDF5_invoke_compiler( CXX HDF5_CXX_COMPILE_LINE HDF5_CXX_RETURN_VALUE )
+ _HDF5_invoke_compiler( Fortran HDF5_Fortran_COMPILE_LINE HDF5_Fortran_RETURN_VALUE )
+
+ # seed the initial lists of libraries to find with items we know we need
+ set( HDF5_C_LIBRARY_NAMES_INIT hdf5 )
+ set( HDF5_HL_LIBRARY_NAMES_INIT hdf5_hl ${HDF5_C_LIBRARY_NAMES_INIT} )
+ set( HDF5_CXX_LIBRARY_NAMES_INIT hdf5_cpp ${HDF5_C_LIBRARY_NAMES_INIT} )
+ set( HDF5_Fortran_LIBRARY_NAMES_INIT hdf5_fortran
+ ${HDF5_C_LIBRARY_NAMES_INIT} )
+ set( HDF5_Fortran_HL_LIBRARY_NAMES_INIT hdf5hl_fortran
+ ${HDF5_Fortran_LIBRARY_NAMES_INIT} )
+
+ foreach( LANGUAGE ${HDF5_LANGUAGE_BINDINGS} )
+ if( HDF5_${LANGUAGE}_COMPILE_LINE )
+ _HDF5_parse_compile_line( HDF5_${LANGUAGE}_COMPILE_LINE
+ HDF5_${LANGUAGE}_INCLUDE_FLAGS
+ HDF5_${LANGUAGE}_DEFINITIONS
+ HDF5_${LANGUAGE}_LIBRARY_DIRS
+ HDF5_${LANGUAGE}_LIBRARY_NAMES
+ )
+
+ # take a guess that the includes may be in the 'include' sibling
+ # directory of a library directory.
+ foreach( dir ${HDF5_${LANGUAGE}_LIBRARY_DIRS} )
+ list( APPEND HDF5_${LANGUAGE}_INCLUDE_FLAGS ${dir}/../include )
+ endforeach()
+ endif()
+
+ # set the definitions for the language bindings.
+ list( APPEND HDF5_DEFINITIONS ${HDF5_${LANGUAGE}_DEFINITIONS} )
+
+ # find the HDF5 include directories
+ if(${LANGUAGE} MATCHES "Fortran")
+ set(HDF5_INCLUDE_FILENAME hdf5.mod)
+ else()
+ set(HDF5_INCLUDE_FILENAME hdf5.h)
+ endif()
+
+ find_path( HDF5_${LANGUAGE}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME}
+ HINTS
+ ${HDF5_${LANGUAGE}_INCLUDE_FLAGS}
+ ENV
+ HDF5_ROOT
+ PATHS
+ $ENV{HOME}/.local/include
+ PATH_SUFFIXES
+ include
+ Include
+ )
+ mark_as_advanced( HDF5_${LANGUAGE}_INCLUDE_DIR )
+ list( APPEND HDF5_INCLUDE_DIRS ${HDF5_${LANGUAGE}_INCLUDE_DIR} )
+
+ set( HDF5_${LANGUAGE}_LIBRARY_NAMES
+ ${HDF5_${LANGUAGE}_LIBRARY_NAMES_INIT}
+ ${HDF5_${LANGUAGE}_LIBRARY_NAMES} )
+
+ # find the HDF5 libraries
+ foreach( LIB ${HDF5_${LANGUAGE}_LIBRARY_NAMES} )
+ if( UNIX AND HDF5_USE_STATIC_LIBRARIES )
+ # According to bug 1643 on the CMake bug tracker, this is the
+ # preferred method for searching for a static library.
+ # See http://www.cmake.org/Bug/view.php?id=1643. We search
+ # first for the full static library name, but fall back to a
+ # generic search on the name if the static search fails.
+ set( THIS_LIBRARY_SEARCH_DEBUG lib${LIB}d.a ${LIB}d )
+ set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB} )
+ else()
+ set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d )
+ set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} )
+ endif()
+ find_library( HDF5_${LIB}_LIBRARY_DEBUG
+ NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
+ HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS}
+ ENV HDF5_ROOT
+ PATH_SUFFIXES lib Lib )
+ find_library( HDF5_${LIB}_LIBRARY_RELEASE
+ NAMES ${THIS_LIBRARY_SEARCH_RELEASE}
+ HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS}
+ ENV HDF5_ROOT
+ PATH_SUFFIXES lib Lib )
+ select_library_configurations( HDF5_${LIB} )
+ list(APPEND HDF5_${LANGUAGE}_LIBRARIES ${HDF5_${LIB}_LIBRARY})
+ endforeach()
+ list( APPEND HDF5_LIBRARY_DIRS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} )
+
+ # Append the libraries for this language binding to the list of all
+ # required libraries.
+ list(APPEND HDF5_LIBRARIES ${HDF5_${LANGUAGE}_LIBRARIES})
+ endforeach()
+
+ # We may have picked up some duplicates in various lists during the above
+ # process for the language bindings (both the C and C++ bindings depend on
+ # libz for example). Remove the duplicates. It appears that the default
+ # CMake behavior is to remove duplicates from the end of a list. However,
+ # for link lines, this is incorrect since unresolved symbols are searched
+ # for down the link line. Therefore, we reverse the list, remove the
+ # duplicates, and then reverse it again to get the duplicates removed from
+ # the beginning.
+ macro( _remove_duplicates_from_beginning _list_name )
+ list( REVERSE ${_list_name} )
+ list( REMOVE_DUPLICATES ${_list_name} )
+ list( REVERSE ${_list_name} )
+ endmacro()
+
+ if( HDF5_INCLUDE_DIRS )
+ _remove_duplicates_from_beginning( HDF5_INCLUDE_DIRS )
+ endif()
+ if( HDF5_LIBRARY_DIRS )
+ _remove_duplicates_from_beginning( HDF5_LIBRARY_DIRS )
+ endif()
+
+ # If the HDF5 include directory was found, open H5pubconf.h to determine if
+ # HDF5 was compiled with parallel IO support
+ set( HDF5_IS_PARALLEL FALSE )
+ foreach( _dir IN LISTS HDF5_INCLUDE_DIRS )
+ if( EXISTS "${_dir}/H5pubconf.h" )
+ file( STRINGS "${_dir}/H5pubconf.h"
+ HDF5_HAVE_PARALLEL_DEFINE
+ REGEX "HAVE_PARALLEL 1" )
+ if( HDF5_HAVE_PARALLEL_DEFINE )
+ set( HDF5_IS_PARALLEL TRUE )
+ endif()
+ endif()
+ endforeach()
+ set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL
+ "HDF5 library compiled with parallel IO support" )
+ mark_as_advanced( HDF5_IS_PARALLEL )
+
+ # For backwards compatibility we set HDF5_INCLUDE_DIR to the value of
+ # HDF5_INCLUDE_DIRS
+ if( HDF5_INCLUDE_DIRS )
+ set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" )
+ endif()
+
+endif()
+
+find_package_handle_standard_args( HDF5 DEFAULT_MSG
+ HDF5_LIBRARIES
+ HDF5_INCLUDE_DIRS
+)
+
diff --git a/Modules/FindHSPELL.cmake b/Modules/FindHSPELL.cmake
new file mode 100644
index 0000000000..2316533534
--- /dev/null
+++ b/Modules/FindHSPELL.cmake
@@ -0,0 +1,58 @@
+#.rst:
+# FindHSPELL
+# ----------
+#
+# Try to find Hspell
+#
+# Once done this will define
+#
+# ::
+#
+# HSPELL_FOUND - system has Hspell
+# HSPELL_INCLUDE_DIR - the Hspell include directory
+# HSPELL_LIBRARIES - The libraries needed to use Hspell
+# HSPELL_DEFINITIONS - Compiler switches required for using Hspell
+#
+#
+#
+# ::
+#
+# HSPELL_VERSION_STRING - The version of Hspell found (x.y)
+# HSPELL_MAJOR_VERSION - the major version of Hspell
+# HSPELL_MINOR_VERSION - The minor version of Hspell
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+find_path(HSPELL_INCLUDE_DIR hspell.h)
+
+find_library(HSPELL_LIBRARIES NAMES hspell)
+
+if (HSPELL_INCLUDE_DIR)
+ file(STRINGS "${HSPELL_INCLUDE_DIR}/hspell.h" HSPELL_H REGEX "#define HSPELL_VERSION_M(AJO|INO)R [0-9]+")
+ string(REGEX REPLACE ".*#define HSPELL_VERSION_MAJOR ([0-9]+).*" "\\1" HSPELL_VERSION_MAJOR "${HSPELL_H}")
+ string(REGEX REPLACE ".*#define HSPELL_VERSION_MINOR ([0-9]+).*" "\\1" HSPELL_VERSION_MINOR "${HSPELL_H}")
+ set(HSPELL_VERSION_STRING "${HSPELL_VERSION_MAJOR}.${HSPELL_VERSION_MINOR}")
+ unset(HSPELL_H)
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set HSPELL_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(HSPELL
+ REQUIRED_VARS HSPELL_LIBRARIES HSPELL_INCLUDE_DIR
+ VERSION_VAR HSPELL_VERSION_STRING)
+
+mark_as_advanced(HSPELL_INCLUDE_DIR HSPELL_LIBRARIES)
+
diff --git a/Modules/FindHTMLHelp.cmake b/Modules/FindHTMLHelp.cmake
new file mode 100644
index 0000000000..4e39a34ef8
--- /dev/null
+++ b/Modules/FindHTMLHelp.cmake
@@ -0,0 +1,61 @@
+#.rst:
+# FindHTMLHelp
+# ------------
+#
+# This module looks for Microsoft HTML Help Compiler
+#
+# It defines:
+#
+# ::
+#
+# HTML_HELP_COMPILER : full path to the Compiler (hhc.exe)
+# HTML_HELP_INCLUDE_PATH : include path to the API (htmlhelp.h)
+# HTML_HELP_LIBRARY : full path to the library (htmlhelp.lib)
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+if(WIN32)
+
+ find_program(HTML_HELP_COMPILER
+ hhc
+ "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]"
+ "$ENV{ProgramFiles}/HTML Help Workshop"
+ "C:/Program Files/HTML Help Workshop"
+ )
+
+ get_filename_component(HTML_HELP_COMPILER_PATH "${HTML_HELP_COMPILER}" PATH)
+
+ find_path(HTML_HELP_INCLUDE_PATH
+ htmlhelp.h
+ "${HTML_HELP_COMPILER_PATH}/include"
+ "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]/include"
+ "$ENV{ProgramFiles}/HTML Help Workshop/include"
+ "C:/Program Files/HTML Help Workshop/include"
+ )
+
+ find_library(HTML_HELP_LIBRARY
+ htmlhelp
+ "${HTML_HELP_COMPILER_PATH}/lib"
+ "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]/lib"
+ "$ENV{ProgramFiles}/HTML Help Workshop/lib"
+ "C:/Program Files/HTML Help Workshop/lib"
+ )
+
+ mark_as_advanced(
+ HTML_HELP_COMPILER
+ HTML_HELP_INCLUDE_PATH
+ HTML_HELP_LIBRARY
+ )
+
+endif()
diff --git a/Modules/FindHg.cmake b/Modules/FindHg.cmake
new file mode 100644
index 0000000000..c418afdd24
--- /dev/null
+++ b/Modules/FindHg.cmake
@@ -0,0 +1,96 @@
+#.rst:
+# FindHg
+# ------
+#
+# Extract information from a mercurial working copy.
+#
+# The module defines the following variables:
+#
+# ::
+#
+# HG_EXECUTABLE - path to mercurial command line client (hg)
+# HG_FOUND - true if the command line client was found
+# HG_VERSION_STRING - the version of mercurial found
+#
+# If the command line client executable is found the following macro is defined:
+#
+# ::
+#
+# HG_WC_INFO(<dir> <var-prefix>)
+#
+# Hg_WC_INFO extracts information of a mercurial working copy
+# at a given location. This macro defines the following variables:
+#
+# ::
+#
+# <var-prefix>_WC_CHANGESET - current changeset
+# <var-prefix>_WC_REVISION - current revision
+#
+# Example usage:
+#
+# ::
+#
+# find_package(Hg)
+# if(HG_FOUND)
+# message("hg found: ${HG_EXECUTABLE}")
+# HG_WC_INFO(${PROJECT_SOURCE_DIR} Project)
+# message("Current revision is ${Project_WC_REVISION}")
+# message("Current changeset is ${Project_WC_CHANGESET}")
+# endif()
+
+#=============================================================================
+# Copyright 2010-2012 Kitware, Inc.
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
+# Copyright 2014 Matthaeus G. Chajdas
+#
+# 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.)
+
+find_program(HG_EXECUTABLE
+ NAMES hg
+ PATHS
+ [HKEY_LOCAL_MACHINE\\Software\\TortoiseHG]
+ PATH_SUFFIXES Mercurial
+ DOC "hg command line client"
+ )
+mark_as_advanced(HG_EXECUTABLE)
+
+if(HG_EXECUTABLE)
+ execute_process(COMMAND ${HG_EXECUTABLE} --version
+ OUTPUT_VARIABLE hg_version
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if(hg_version MATCHES "^Mercurial Distributed SCM \\(version ([0-9][^)]*)\\)")
+ set(HG_VERSION_STRING "${CMAKE_MATCH_1}")
+ endif()
+ unset(hg_version)
+
+ macro(HG_WC_INFO dir prefix)
+ execute_process(COMMAND ${HG_EXECUTABLE} id -i -n
+ WORKING_DIRECTORY ${dir}
+ RESULT_VARIABLE hg_id_result
+ ERROR_VARIABLE hg_id_error
+ OUTPUT_VARIABLE ${prefix}_WC_DATA
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if(NOT ${hg_id_result} EQUAL 0)
+ message(SEND_ERROR "Command \"${HG_EXECUTBALE} id -n\" in directory ${dir} failed with output:\n${hg_id_error}")
+ endif()
+
+ string(REGEX REPLACE "([0-9a-f]+)\\+? [0-9]+\\+?" "\\1" ${prefix}_WC_CHANGESET ${${prefix}_WC_DATA})
+ string(REGEX REPLACE "[0-9a-f]+\\+? ([0-9]+)\\+?" "\\1" ${prefix}_WC_REVISION ${${prefix}_WC_DATA})
+ endmacro(HG_WC_INFO)
+endif()
+
+# Handle the QUIETLY and REQUIRED arguments and set HG_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(Hg
+ REQUIRED_VARS HG_EXECUTABLE
+ VERSION_VAR HG_VERSION_STRING)
diff --git a/Modules/FindIce.cmake b/Modules/FindIce.cmake
new file mode 100644
index 0000000000..55528b8ede
--- /dev/null
+++ b/Modules/FindIce.cmake
@@ -0,0 +1,393 @@
+#.rst:
+# FindIce
+# -------
+#
+# Find the ZeroC Internet Communication Engine (ICE) programs,
+# libraries and datafiles.
+#
+# This module supports multiple components.
+# Components can include any of: ``Freeze``, ``Glacier2``, ``Ice``,
+# ``IceBox``, ``IceDB``, ``IceGrid``, ``IcePatch``, ``IceSSL``,
+# ``IceStorm``, ``IceUtil``, ``IceXML``, or ``Slice``.
+#
+# This module reports information about the Ice installation in
+# several variables. General variables::
+#
+# Ice_VERSION - Ice release version
+# Ice_FOUND - true if the main programs and libraries were found
+# Ice_LIBRARIES - component libraries to be linked
+# Ice_INCLUDE_DIRS - the directories containing the Ice headers
+# Ice_SLICE_DIRS - the directories containing the Ice slice interface
+# definitions
+#
+# Ice programs are reported in::
+#
+# Ice_SLICE2CPP_EXECUTABLE - path to slice2cpp executable
+# Ice_SLICE2CS_EXECUTABLE - path to slice2cs executable
+# Ice_SLICE2FREEZEJ_EXECUTABLE - path to slice2freezej executable
+# Ice_SLICE2FREEZE_EXECUTABLE - path to slice2freeze executable
+# Ice_SLICE2HTML_EXECUTABLE - path to slice2html executable
+# Ice_SLICE2JAVA_EXECUTABLE - path to slice2java executable
+# Ice_SLICE2PHP_EXECUTABLE - path to slice2php executable
+# Ice_SLICE2PY_EXECUTABLE - path to slice2py executable
+# Ice_SLICE2RB_EXECUTABLE - path to slice2rb executable
+#
+# Ice component libraries are reported in::
+#
+# Ice_<C>_FOUND - ON if component was found
+# Ice_<C>_LIBRARIES - libraries for component
+#
+# Note that ``<C>`` is the uppercased name of the component.
+#
+# This module reads hints about search results from::
+#
+# Ice_HOME - the root of the Ice installation
+#
+# The environment variable :envvar:`ICE_HOME` may also be used; the
+# Ice_HOME variable takes precedence.
+#
+# The following cache variables may also be set::
+#
+# Ice_<P>_EXECUTABLE - the path to executable <P>
+# Ice_INCLUDE_DIR - the directory containing the Ice headers
+# Ice_SLICE_DIR - the directory containing the Ice slice interface
+# definitions
+# Ice_<C>_LIBRARY - the library for component <C>
+#
+# .. note::
+#
+# In most cases none of the above variables will require setting,
+# unless multiple Ice versions are available and a specific version
+# is required. On Windows, the most recent version of Ice will be
+# found through the registry. On Unix, the programs, headers and
+# libraries will usually be in standard locations, but Ice_SLICE_DIRS
+# might not be automatically detected (commonly known locations are
+# searched). All the other variables are defaulted using Ice_HOME,
+# if set. It's possible to set Ice_HOME and selectively specify
+# alternative locations for the other components; this might be
+# required for e.g. newer versions of Visual Studio if the
+# heuristics are not sufficient to identify the correct programs and
+# libraries for the specific Visual Studio version.
+#
+# Other variables one may set to control this module are::
+#
+# Ice_DEBUG - Set to ON to enable debug output from FindIce.
+
+# Written by Roger Leigh <rleigh@codelibre.net>
+
+#=============================================================================
+# Copyright 2014 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.)
+
+# The Ice checks are contained in a function due to the large number
+# of temporary variables needed.
+function(_Ice_FIND)
+ # Released versions of Ice, including generic short forms
+ set(ice_versions
+ 3
+ 3.5
+ 3.5.1
+ 3.5.0
+ 3.4
+ 3.4.2
+ 3.4.1
+ 3.4.0
+ 3.3
+ 3.3.1
+ 3.3.0)
+
+ # Set up search paths, taking compiler into account. Search Ice_HOME,
+ # with ICE_HOME in the environment as a fallback if unset.
+ if(Ice_HOME)
+ list(APPEND ice_roots "${Ice_HOME}")
+ else()
+ if(NOT "$ENV{ICE_HOME}" STREQUAL "")
+ file(TO_CMAKE_PATH "$ENV{ICE_HOME}" NATIVE_PATH)
+ list(APPEND ice_roots "${NATIVE_PATH}")
+ set(Ice_HOME "${NATIVE_PATH}"
+ CACHE PATH "Location of the Ice installation" FORCE)
+ endif()
+ endif()
+
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ # 64-bit path suffix
+ set(_x64 "/x64")
+ # 64-bit library directory
+ set(_lib64 "lib64")
+ endif()
+
+ if(MSVC_VERSION)
+ # VS 8.0
+ if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500)
+ set(vcver "vc80")
+ set(vcyear "2005")
+ # VS 9.0
+ elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600)
+ set(vcver "vc90")
+ set(vcyear "2008")
+ # VS 10.0
+ elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700)
+ set(vcver "vc100")
+ # VS 11.0
+ elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800)
+ set(vcver "vc110")
+ # VS 12.0
+ elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900)
+ set(vcver "vc120")
+ # VS 14.0
+ elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 2000)
+ set(vcver "vc140")
+ endif()
+ endif()
+
+ # For compatibility with ZeroC Windows builds.
+ if(vcver)
+ # Earlier Ice (3.3) builds don't use vcnnn subdirectories, but are harmless to check.
+ list(APPEND ice_binary_suffixes "bin/${vcver}${_x64}" "bin/${vcver}")
+ list(APPEND ice_library_suffixes "lib/${vcver}${_x64}" "lib/${vcver}")
+ endif()
+ # Generic 64-bit and 32-bit directories
+ list(APPEND ice_binary_suffixes "bin${_x64}" "bin")
+ list(APPEND ice_library_suffixes "${_lib64}" "lib${_x64}" "lib")
+ list(APPEND ice_include_suffixes "include")
+ list(APPEND ice_slice_suffixes "slice")
+
+ # On Windows, look in the registry for install locations. Different
+ # versions of Ice install support different compiler versions.
+ if(vcver)
+ foreach(ice_version ${ice_versions})
+ # Ice 3.3 releases use a Visual Studio year suffix and value is
+ # enclosed in double quotes, though only the leading quote is
+ # returned by get_filename_component.
+ unset(ice_location)
+ if(vcyear)
+ get_filename_component(ice_location
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ZeroC\\Ice ${ice_version} for Visual Studio ${vcyear};InstallDir]"
+ PATH)
+ if(ice_location AND NOT ("${ice_location}" STREQUAL "/registry" OR "${ice_location}" STREQUAL "/"))
+ string(REGEX REPLACE "^\"(.*)\"?$" "\\1" ice_location "${ice_location}")
+ get_filename_component(ice_location "${ice_location}" ABSOLUTE)
+ else()
+ unset(ice_location)
+ endif()
+ endif()
+ # Ice 3.4+ releases don't use a suffix
+ if(NOT ice_location OR "${ice_location}" STREQUAL "/registry")
+ get_filename_component(ice_location
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ZeroC\\Ice ${ice_version};InstallDir]"
+ ABSOLUTE)
+ endif()
+
+ if(ice_location AND NOT "${ice_location}" STREQUAL "/registry")
+ list(APPEND ice_roots "${ice_location}")
+ endif()
+ endforeach()
+ else()
+ foreach(ice_version ${ice_versions})
+ # Prefer 64-bit variants if present (and using a 64-bit compiler)
+ list(APPEND ice_roots "/opt/Ice-${ice_version}")
+ endforeach()
+ endif()
+
+ set(ice_programs
+ slice2cpp
+ slice2cs
+ slice2freezej
+ slice2freeze
+ slice2html
+ slice2java
+ slice2php
+ slice2py
+ slice2rb)
+
+ # Find all Ice programs
+ foreach(program ${ice_programs})
+ string(TOUPPER "${program}" program_upcase)
+ set(cache_var "Ice_${program_upcase}_EXECUTABLE")
+ set(program_var "Ice_${program_upcase}_EXECUTABLE")
+ find_program("${cache_var}" "${program}"
+ HINTS ${ice_roots}
+ PATH_SUFFIXES ${ice_binary_suffixes}
+ DOC "Ice ${program} executable")
+ mark_as_advanced(cache_var)
+ set("${program_var}" "${${cache_var}}" PARENT_SCOPE)
+ endforeach()
+
+ # Get version.
+ if(Ice_SLICE2CPP_EXECUTABLE)
+ # Execute in C locale for safety
+ set(_Ice_SAVED_LC_ALL "$ENV{LC_ALL}")
+ set(ENV{LC_ALL} C)
+
+ execute_process(COMMAND ${Ice_SLICE2CPP_EXECUTABLE} --version
+ ERROR_VARIABLE Ice_VERSION_SLICE2CPP_FULL
+ ERROR_STRIP_TRAILING_WHITESPACE)
+
+ # restore the previous LC_ALL
+ set(ENV{LC_ALL} ${_Ice_SAVED_LC_ALL})
+
+ # Make short version
+ string(REGEX REPLACE "^(.*)\\.[^.]*$" "\\1" Ice_VERSION_SLICE2CPP_SHORT "${Ice_VERSION_SLICE2CPP_FULL}")
+ set(Ice_VERSION "${Ice_VERSION_SLICE2CPP_FULL}" PARENT_SCOPE)
+ endif()
+
+ if(NOT Ice_FIND_QUIETLY)
+ message(STATUS "Ice version: ${Ice_VERSION_SLICE2CPP_FULL}")
+ endif()
+
+ # Find include directory
+ find_path(Ice_INCLUDE_DIR
+ NAMES "Ice/Ice.h"
+ HINTS ${ice_roots}
+ PATH_SUFFIXES ${ice_include_suffixes}
+ DOC "Ice include directory")
+ set(Ice_INCLUDE_DIR "${Ice_INCLUDE_DIR}" PARENT_SCOPE)
+
+ # In common use on Linux, MacOS X (homebrew) and FreeBSD; prefer
+ # version-specific dir
+ list(APPEND ice_slice_paths
+ /usr/local/share /usr/share)
+ list(APPEND ice_slice_suffixes
+ "Ice-${Ice_VERSION_SLICE2CPP_FULL}/slice"
+ "Ice-${Ice_VERSION_SLICE2CPP_SHORT}/slice"
+ Ice)
+
+ # Find slice directory
+ find_path(Ice_SLICE_DIR
+ NAMES "Ice/Connection.ice"
+ HINTS ${ice_roots}
+ ${ice_slice_paths}
+ PATH_SUFFIXES ${ice_slice_suffixes}
+ NO_DEFAULT_PATH
+ DOC "Ice slice directory")
+ set(Ice_SLICE_DIR "${Ice_SLICE_DIR}" PARENT_SCOPE)
+
+ # Find all Ice libraries
+ set(Ice_REQUIRED_LIBS_FOUND ON)
+ foreach(component ${Ice_FIND_COMPONENTS})
+ string(TOUPPER "${component}" component_upcase)
+ set(component_cache "Ice_${component_upcase}_LIBRARY")
+ set(component_found "${component_upcase}_FOUND")
+ find_library("${component_cache}" "${component}"
+ HINTS ${ice_roots}
+ PATH_SUFFIXES ${ice_library_suffixes}
+ DOC "Ice ${component} library")
+ mark_as_advanced("${component_cache}")
+ if("${component_cache}")
+ set("${component_found}" ON)
+ list(APPEND Ice_LIBRARY "${${component_cache}}")
+ endif()
+ mark_as_advanced("${component_found}")
+ set("${component_cache}" "${${component_cache}}" PARENT_SCOPE)
+ set("${component_found}" "${${component_found}}" PARENT_SCOPE)
+ if("${component_found}")
+ if ("Ice_FIND_REQUIRED_${component}")
+ list(APPEND Ice_LIBS_FOUND "${component} (required)")
+ else()
+ list(APPEND Ice_LIBS_FOUND "${component} (optional)")
+ endif()
+ else()
+ if ("Ice_FIND_REQUIRED_${component}")
+ set(Ice_REQUIRED_LIBS_FOUND OFF)
+ list(APPEND Ice_LIBS_NOTFOUND "${component} (required)")
+ else()
+ list(APPEND Ice_LIBS_NOTFOUND "${component} (optional)")
+ endif()
+ endif()
+ endforeach()
+ set(_Ice_REQUIRED_LIBS_FOUND "${Ice_REQUIRED_LIBS_FOUND}" PARENT_SCOPE)
+ set(Ice_LIBRARY "${Ice_LIBRARY}" PARENT_SCOPE)
+
+ if(NOT Ice_FIND_QUIETLY)
+ if(Ice_LIBS_FOUND)
+ message(STATUS "Found the following Ice libraries:")
+ foreach(found ${Ice_LIBS_FOUND})
+ message(STATUS " ${found}")
+ endforeach()
+ endif()
+ if(Ice_LIBS_NOTFOUND)
+ message(STATUS "The following Ice libraries were not found:")
+ foreach(notfound ${Ice_LIBS_NOTFOUND})
+ message(STATUS " ${notfound}")
+ endforeach()
+ endif()
+ endif()
+
+ if(Ice_DEBUG)
+ message(STATUS "--------FindIce.cmake search debug--------")
+ message(STATUS "ICE binary path search order: ${ice_roots}")
+ message(STATUS "ICE include path search order: ${ice_roots}")
+ message(STATUS "ICE slice path search order: ${ice_roots} ${ice_slice_paths}")
+ message(STATUS "ICE library path search order: ${ice_roots}")
+ message(STATUS "----------------")
+ endif()
+endfunction()
+
+_Ice_FIND()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ice
+ FOUND_VAR Ice_FOUND
+ REQUIRED_VARS Ice_SLICE2CPP_EXECUTABLE
+ Ice_INCLUDE_DIR
+ Ice_SLICE_DIR
+ Ice_LIBRARY
+ _Ice_REQUIRED_LIBS_FOUND
+ VERSION_VAR Ice_VERSION
+ FAIL_MESSAGE "Failed to find all Ice components")
+
+unset(_Ice_REQUIRED_LIBS_FOUND)
+
+if(Ice_FOUND)
+ set(Ice_INCLUDE_DIRS "${Ice_INCLUDE_DIR}")
+ set(Ice_SLICE_DIRS "${Ice_SLICE_DIR}")
+ set(Ice_LIBRARIES "${Ice_LIBRARY}")
+ foreach(_Ice_component ${Ice_FIND_COMPONENTS})
+ string(TOUPPER "${_Ice_component}" _Ice_component_upcase)
+ set(_Ice_component_cache "Ice_${_Ice_component_upcase}_LIBRARY")
+ set(_Ice_component_lib "Ice_${_Ice_component_upcase}_LIBRARIES")
+ set(_Ice_component_found "${_Ice_component_upcase}_FOUND")
+ if("${_Ice_component_found}")
+ set("${_Ice_component_lib}" "${${_Ice_component_cache}}")
+ endif()
+ unset(_Ice_component_upcase)
+ unset(_Ice_component_cache)
+ unset(_Ice_component_lib)
+ unset(_Ice_component_found)
+ endforeach()
+endif()
+
+if(Ice_DEBUG)
+ message(STATUS "--------FindIce.cmake results debug--------")
+ message(STATUS "Ice_VERSION number: ${Ice_VERSION}")
+ message(STATUS "Ice_HOME directory: ${Ice_HOME}")
+ message(STATUS "Ice_INCLUDE_DIR directory: ${Ice_INCLUDE_DIR}")
+ message(STATUS "Ice_SLICE_DIR directory: ${Ice_SLICE_DIR}")
+ message(STATUS "Ice_LIBRARIES: ${Ice_LIBRARIES}")
+ message(STATUS "slice2cpp executable: ${Ice_SLICE2CPP_EXECUTABLE}")
+ message(STATUS "slice2cs executable: ${Ice_SLICE2CS_EXECUTABLE}")
+ message(STATUS "slice2freezej executable: ${Ice_SLICE2FREEZEJ_EXECUTABLE}")
+ message(STATUS "slice2freeze executable: ${Ice_SLICE2FREEZE_EXECUTABLE}")
+ message(STATUS "slice2html executable: ${Ice_SLICE2HTML_EXECUTABLE}")
+ message(STATUS "slice2java executable: ${Ice_SLICE2JAVA_EXECUTABLE}")
+ message(STATUS "slice2php executable: ${Ice_SLICE2PHP_EXECUTABLE}")
+ message(STATUS "slice2py executable: ${Ice_SLICE2PY_EXECUTABLE}")
+ message(STATUS "slice2rb executable: ${Ice_SLICE2RB_EXECUTABLE}")
+ foreach(component ${Ice_FIND_COMPONENTS})
+ string(TOUPPER "${component}" component_upcase)
+ set(component_lib "Ice_${component_upcase}_LIBRARIES")
+ set(component_found "${component_upcase}_FOUND")
+ message(STATUS "${component} library found: ${${component_found}}")
+ message(STATUS "${component} library: ${${component_lib}}")
+ endforeach()
+ message(STATUS "----------------")
+endif()
diff --git a/Modules/FindIcotool.cmake b/Modules/FindIcotool.cmake
new file mode 100644
index 0000000000..a7c5a64ecc
--- /dev/null
+++ b/Modules/FindIcotool.cmake
@@ -0,0 +1,63 @@
+#.rst:
+# FindIcotool
+# -----------
+#
+# Find icotool
+#
+# This module looks for icotool. This module defines the following
+# values:
+#
+# ::
+#
+# ICOTOOL_EXECUTABLE: the full path to the icotool tool.
+# ICOTOOL_FOUND: True if icotool has been found.
+# ICOTOOL_VERSION_STRING: the version of icotool found.
+
+#=============================================================================
+# Copyright 2012 Aleksey Avdeev <solo@altlinux.ru>
+#
+# 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.)
+
+find_program(ICOTOOL_EXECUTABLE
+ icotool
+)
+
+if(ICOTOOL_EXECUTABLE)
+ execute_process(
+ COMMAND ${ICOTOOL_EXECUTABLE} --version
+ OUTPUT_VARIABLE _icotool_version
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if("${_icotool_version}" MATCHES "^icotool \\([^\\)]*\\) ([0-9\\.]+[^ \n]*)")
+ set( ICOTOOL_VERSION_STRING
+ "${CMAKE_MATCH_1}"
+ )
+ else()
+ set( ICOTOOL_VERSION_STRING
+ ""
+ )
+ endif()
+ unset(_icotool_version)
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set ICOTOOL_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(
+ Icotool
+ REQUIRED_VARS ICOTOOL_EXECUTABLE
+ VERSION_VAR ICOTOOL_VERSION_STRING
+)
+
+mark_as_advanced(
+ ICOTOOL_EXECUTABLE
+)
diff --git a/Modules/FindImageMagick.cmake b/Modules/FindImageMagick.cmake
new file mode 100644
index 0000000000..65458b7cf6
--- /dev/null
+++ b/Modules/FindImageMagick.cmake
@@ -0,0 +1,297 @@
+#.rst:
+# FindImageMagick
+# ---------------
+#
+# Find the ImageMagick binary suite.
+#
+# This module will search for a set of ImageMagick tools specified as
+# components in the FIND_PACKAGE call. Typical components include, but
+# are not limited to (future versions of ImageMagick might have
+# additional components not listed here):
+#
+# ::
+#
+# animate
+# compare
+# composite
+# conjure
+# convert
+# display
+# identify
+# import
+# mogrify
+# montage
+# stream
+#
+#
+#
+# If no component is specified in the FIND_PACKAGE call, then it only
+# searches for the ImageMagick executable directory. This code defines
+# the following variables:
+#
+# ::
+#
+# ImageMagick_FOUND - TRUE if all components are found.
+# ImageMagick_EXECUTABLE_DIR - Full path to executables directory.
+# ImageMagick_<component>_FOUND - TRUE if <component> is found.
+# ImageMagick_<component>_EXECUTABLE - Full path to <component> executable.
+# ImageMagick_VERSION_STRING - the version of ImageMagick found
+# (since CMake 2.8.8)
+#
+#
+#
+# ImageMagick_VERSION_STRING will not work for old versions like 5.2.3.
+#
+# There are also components for the following ImageMagick APIs:
+#
+# ::
+#
+# Magick++
+# MagickWand
+# MagickCore
+#
+#
+#
+# For these components the following variables are set:
+#
+# ::
+#
+# ImageMagick_FOUND - TRUE if all components are found.
+# ImageMagick_INCLUDE_DIRS - Full paths to all include dirs.
+# ImageMagick_LIBRARIES - Full paths to all libraries.
+# ImageMagick_<component>_FOUND - TRUE if <component> is found.
+# ImageMagick_<component>_INCLUDE_DIRS - Full path to <component> include dirs.
+# ImageMagick_<component>_LIBRARIES - Full path to <component> libraries.
+#
+#
+#
+# Example Usages:
+#
+# ::
+#
+# find_package(ImageMagick)
+# find_package(ImageMagick COMPONENTS convert)
+# find_package(ImageMagick COMPONENTS convert mogrify display)
+# find_package(ImageMagick COMPONENTS Magick++)
+# find_package(ImageMagick COMPONENTS Magick++ convert)
+#
+#
+#
+# Note that the standard FIND_PACKAGE features are supported (i.e.,
+# QUIET, REQUIRED, etc.).
+
+#=============================================================================
+# Copyright 2007-2009 Kitware, Inc.
+# Copyright 2007-2008 Miguel A. Figueroa-Villanueva <miguelf at ieee dot org>
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+find_package(PkgConfig QUIET)
+
+#---------------------------------------------------------------------
+# Helper functions
+#---------------------------------------------------------------------
+function(FIND_IMAGEMAGICK_API component header)
+ set(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
+
+ pkg_check_modules(PC_${component} QUIET ${component})
+
+ find_path(ImageMagick_${component}_INCLUDE_DIR
+ NAMES ${header}
+ HINTS
+ ${PC_${component}_INCLUDEDIR}
+ ${PC_${component}_INCLUDE_DIRS}
+ PATHS
+ ${ImageMagick_INCLUDE_DIRS}
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/include"
+ PATH_SUFFIXES
+ ImageMagick ImageMagick-6
+ DOC "Path to the ImageMagick arch-independent include dir."
+ )
+ find_path(ImageMagick_${component}_ARCH_INCLUDE_DIR
+ NAMES magick/magick-baseconfig.h
+ HINTS
+ ${PC_${component}_INCLUDEDIR}
+ ${PC_${component}_INCLUDE_DIRS}
+ PATHS
+ ${ImageMagick_INCLUDE_DIRS}
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/include"
+ PATH_SUFFIXES
+ ImageMagick ImageMagick-6
+ DOC "Path to the ImageMagick arch-specific include dir."
+ )
+ find_library(ImageMagick_${component}_LIBRARY
+ NAMES ${ARGN}
+ HINTS
+ ${PC_${component}_LIBDIR}
+ ${PC_${component}_LIB_DIRS}
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/lib"
+ DOC "Path to the ImageMagick Magick++ library."
+ )
+
+ # old version have only indep dir
+ if(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY)
+ set(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
+
+ # Construct per-component include directories.
+ set(ImageMagick_${component}_INCLUDE_DIRS
+ ${ImageMagick_${component}_INCLUDE_DIR}
+ )
+ if(ImageMagick_${component}_ARCH_INCLUDE_DIR)
+ list(APPEND ImageMagick_${component}_INCLUDE_DIRS
+ ${ImageMagick_${component}_ARCH_INCLUDE_DIR})
+ endif()
+ list(REMOVE_DUPLICATES ImageMagick_${component}_INCLUDE_DIRS)
+ set(ImageMagick_${component}_INCLUDE_DIRS
+ ${ImageMagick_${component}_INCLUDE_DIRS} PARENT_SCOPE)
+
+ # Add the per-component include directories to the full include dirs.
+ list(APPEND ImageMagick_INCLUDE_DIRS ${ImageMagick_${component}_INCLUDE_DIRS})
+ list(REMOVE_DUPLICATES ImageMagick_INCLUDE_DIRS)
+ set(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS} PARENT_SCOPE)
+
+ list(APPEND ImageMagick_LIBRARIES
+ ${ImageMagick_${component}_LIBRARY}
+ )
+ set(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES} PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(FIND_IMAGEMAGICK_EXE component)
+ set(_IMAGEMAGICK_EXECUTABLE
+ ${ImageMagick_EXECUTABLE_DIR}/${component}${CMAKE_EXECUTABLE_SUFFIX})
+ if(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
+ set(ImageMagick_${component}_EXECUTABLE
+ ${_IMAGEMAGICK_EXECUTABLE}
+ PARENT_SCOPE
+ )
+ set(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
+ else()
+ set(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
+ endif()
+endfunction()
+
+#---------------------------------------------------------------------
+# Start Actual Work
+#---------------------------------------------------------------------
+# Try to find a ImageMagick installation binary path.
+find_path(ImageMagick_EXECUTABLE_DIR
+ NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]"
+ DOC "Path to the ImageMagick binary directory."
+ NO_DEFAULT_PATH
+ )
+find_path(ImageMagick_EXECUTABLE_DIR
+ NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
+ )
+
+# Find each component. Search for all tools in same dir
+# <ImageMagick_EXECUTABLE_DIR>; otherwise they should be found
+# independently and not in a cohesive module such as this one.
+unset(ImageMagick_REQUIRED_VARS)
+unset(ImageMagick_DEFAULT_EXECUTABLES)
+foreach(component ${ImageMagick_FIND_COMPONENTS}
+ # DEPRECATED: forced components for backward compatibility
+ convert mogrify import montage composite
+ )
+ if(component STREQUAL "Magick++")
+ FIND_IMAGEMAGICK_API(Magick++ Magick++.h
+ Magick++ CORE_RL_Magick++_ Magick++-6.Q16 Magick++-Q16 Magick++-6.Q8 Magick++-Q8 Magick++-6.Q16HDRI Magick++-Q16HDRI Magick++-6.Q8HDRI Magick++-Q8HDRI
+ )
+ list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_Magick++_LIBRARY)
+ elseif(component STREQUAL "MagickWand")
+ FIND_IMAGEMAGICK_API(MagickWand wand/MagickWand.h
+ Wand MagickWand CORE_RL_wand_ MagickWand-6.Q16 MagickWand-Q16 MagickWand-6.Q8 MagickWand-Q8 MagickWand-6.Q16HDRI MagickWand-Q16HDRI MagickWand-6.Q8HDRI MagickWand-Q8HDRI
+ )
+ list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickWand_LIBRARY)
+ elseif(component STREQUAL "MagickCore")
+ FIND_IMAGEMAGICK_API(MagickCore magick/MagickCore.h
+ Magick MagickCore CORE_RL_magick_ MagickCore-6.Q16 MagickCore-Q16 MagickCore-6.Q8 MagickCore-Q8 MagickCore-6.Q16HDRI MagickCore-Q16HDRI MagickCore-6.Q8HDRI MagickCore-Q8HDRI
+ )
+ list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickCore_LIBRARY)
+ else()
+ if(ImageMagick_EXECUTABLE_DIR)
+ FIND_IMAGEMAGICK_EXE(${component})
+ endif()
+
+ if(ImageMagick_FIND_COMPONENTS)
+ list(FIND ImageMagick_FIND_COMPONENTS ${component} is_requested)
+ if(is_requested GREATER -1)
+ list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_${component}_EXECUTABLE)
+ endif()
+ elseif(ImageMagick_${component}_EXECUTABLE)
+ # if no components were requested explicitly put all (default) executables
+ # in the list
+ list(APPEND ImageMagick_DEFAULT_EXECUTABLES ImageMagick_${component}_EXECUTABLE)
+ endif()
+ endif()
+endforeach()
+
+if(NOT ImageMagick_FIND_COMPONENTS AND NOT ImageMagick_DEFAULT_EXECUTABLES)
+ # No components were requested, and none of the default components were
+ # found. Just insert mogrify into the list of the default components to
+ # find so FPHSA below has something to check
+ list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_mogrify_EXECUTABLE)
+elseif(ImageMagick_DEFAULT_EXECUTABLES)
+ list(APPEND ImageMagick_REQUIRED_VARS ${ImageMagick_DEFAULT_EXECUTABLES})
+endif()
+
+set(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS})
+set(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES})
+
+if(ImageMagick_mogrify_EXECUTABLE)
+ execute_process(COMMAND ${ImageMagick_mogrify_EXECUTABLE} -version
+ OUTPUT_VARIABLE imagemagick_version
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if(imagemagick_version MATCHES "^Version: ImageMagick ([-0-9\\.]+)")
+ set(ImageMagick_VERSION_STRING "${CMAKE_MATCH_1}")
+ endif()
+ unset(imagemagick_version)
+endif()
+
+#---------------------------------------------------------------------
+# Standard Package Output
+#---------------------------------------------------------------------
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ImageMagick
+ REQUIRED_VARS ${ImageMagick_REQUIRED_VARS}
+ VERSION_VAR ImageMagick_VERSION_STRING
+ )
+# Maintain consistency with all other variables.
+set(ImageMagick_FOUND ${IMAGEMAGICK_FOUND})
+
+#---------------------------------------------------------------------
+# DEPRECATED: Setting variables for backward compatibility.
+#---------------------------------------------------------------------
+set(IMAGEMAGICK_BINARY_PATH ${ImageMagick_EXECUTABLE_DIR}
+ CACHE PATH "Path to the ImageMagick binary directory.")
+set(IMAGEMAGICK_CONVERT_EXECUTABLE ${ImageMagick_convert_EXECUTABLE}
+ CACHE FILEPATH "Path to ImageMagick's convert executable.")
+set(IMAGEMAGICK_MOGRIFY_EXECUTABLE ${ImageMagick_mogrify_EXECUTABLE}
+ CACHE FILEPATH "Path to ImageMagick's mogrify executable.")
+set(IMAGEMAGICK_IMPORT_EXECUTABLE ${ImageMagick_import_EXECUTABLE}
+ CACHE FILEPATH "Path to ImageMagick's import executable.")
+set(IMAGEMAGICK_MONTAGE_EXECUTABLE ${ImageMagick_montage_EXECUTABLE}
+ CACHE FILEPATH "Path to ImageMagick's montage executable.")
+set(IMAGEMAGICK_COMPOSITE_EXECUTABLE ${ImageMagick_composite_EXECUTABLE}
+ CACHE FILEPATH "Path to ImageMagick's composite executable.")
+mark_as_advanced(
+ IMAGEMAGICK_BINARY_PATH
+ IMAGEMAGICK_CONVERT_EXECUTABLE
+ IMAGEMAGICK_MOGRIFY_EXECUTABLE
+ IMAGEMAGICK_IMPORT_EXECUTABLE
+ IMAGEMAGICK_MONTAGE_EXECUTABLE
+ IMAGEMAGICK_COMPOSITE_EXECUTABLE
+ )
diff --git a/Modules/FindJNI.cmake b/Modules/FindJNI.cmake
new file mode 100644
index 0000000000..3dcb0d0aaf
--- /dev/null
+++ b/Modules/FindJNI.cmake
@@ -0,0 +1,307 @@
+#.rst:
+# FindJNI
+# -------
+#
+# Find JNI java libraries.
+#
+# This module finds if Java is installed and determines where the
+# include files and libraries are. It also determines what the name of
+# the library is. The caller may set variable JAVA_HOME to specify a
+# Java installation prefix explicitly.
+#
+# This module sets the following result variables:
+#
+# ::
+#
+# JNI_INCLUDE_DIRS = the include dirs to use
+# JNI_LIBRARIES = the libraries to use
+# JNI_FOUND = TRUE if JNI headers and libraries were found.
+# JAVA_AWT_LIBRARY = the path to the jawt library
+# JAVA_JVM_LIBRARY = the path to the jvm library
+# JAVA_INCLUDE_PATH = the include path to jni.h
+# JAVA_INCLUDE_PATH2 = the include path to jni_md.h
+# JAVA_AWT_INCLUDE_PATH = the include path to jawt.h
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+# Expand {libarch} occurences to java_libarch subdirectory(-ies) and set ${_var}
+macro(java_append_library_directories _var)
+ # Determine java arch-specific library subdir
+ # Mostly based on openjdk/jdk/make/common/shared/Platform.gmk as of openjdk
+ # 1.6.0_18 + icedtea patches. However, it would be much better to base the
+ # guess on the first part of the GNU config.guess platform triplet.
+ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ set(_java_libarch "amd64" "i386")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
+ set(_java_libarch "i386")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha")
+ set(_java_libarch "alpha")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
+ # Subdir is "arm" for both big-endian (arm) and little-endian (armel).
+ set(_java_libarch "arm")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
+ # mips* machines are bi-endian mostly so processor does not tell
+ # endianess of the underlying system.
+ set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "mips" "mipsel" "mipseb")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
+ set(_java_libarch "ppc64" "ppc64le")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
+ set(_java_libarch "ppc64" "ppc")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
+ set(_java_libarch "ppc")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
+ # Both flavours can run on the same processor
+ set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(parisc|hppa)")
+ set(_java_libarch "parisc" "parisc64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390")
+ # s390 binaries can run on s390x machines
+ set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "s390" "s390x")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sh")
+ set(_java_libarch "sh")
+ else()
+ set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}")
+ endif()
+
+ # Append default list architectures if CMAKE_SYSTEM_PROCESSOR was empty or
+ # system is non-Linux (where the code above has not been well tested)
+ if(NOT _java_libarch OR NOT (CMAKE_SYSTEM_NAME MATCHES "Linux"))
+ list(APPEND _java_libarch "i386" "amd64" "ppc")
+ endif()
+
+ # Sometimes ${CMAKE_SYSTEM_PROCESSOR} is added to the list to prefer
+ # current value to a hardcoded list. Remove possible duplicates.
+ list(REMOVE_DUPLICATES _java_libarch)
+
+ foreach(_path ${ARGN})
+ if(_path MATCHES "{libarch}")
+ foreach(_libarch ${_java_libarch})
+ string(REPLACE "{libarch}" "${_libarch}" _newpath "${_path}")
+ list(APPEND ${_var} "${_newpath}")
+ endforeach()
+ else()
+ list(APPEND ${_var} "${_path}")
+ endif()
+ endforeach()
+endmacro()
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake)
+
+# Save CMAKE_FIND_FRAMEWORK
+if(DEFINED CMAKE_FIND_FRAMEWORK)
+ set(_JNI_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
+else()
+ unset(_JNI_CMAKE_FIND_FRAMEWORK)
+endif()
+
+if(_JAVA_HOME_EXPLICIT)
+ set(CMAKE_FIND_FRAMEWORK NEVER)
+endif()
+
+set(JAVA_AWT_LIBRARY_DIRECTORIES)
+if(_JAVA_HOME)
+ JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
+ ${_JAVA_HOME}/jre/lib/{libarch}
+ ${_JAVA_HOME}/jre/lib
+ ${_JAVA_HOME}/lib
+ ${_JAVA_HOME}
+ )
+endif()
+get_filename_component(java_install_version
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit;CurrentVersion]" NAME)
+
+list(APPEND JAVA_AWT_LIBRARY_DIRECTORIES
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/lib"
+ )
+JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
+ /usr/lib
+ /usr/local/lib
+ /usr/lib/jvm/java/lib
+ /usr/lib/java/jre/lib/{libarch}
+ /usr/lib/jvm/jre/lib/{libarch}
+ /usr/local/lib/java/jre/lib/{libarch}
+ /usr/local/share/java/jre/lib/{libarch}
+ /usr/lib/j2sdk1.4-sun/jre/lib/{libarch}
+ /usr/lib/j2sdk1.5-sun/jre/lib/{libarch}
+ /opt/sun-jdk-1.5.0.04/jre/lib/{libarch}
+ /usr/lib/jvm/java-6-sun/jre/lib/{libarch}
+ /usr/lib/jvm/java-1.5.0-sun/jre/lib/{libarch}
+ /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/{libarch} # can this one be removed according to #8821 ? Alex
+ /usr/lib/jvm/java-6-openjdk/jre/lib/{libarch}
+ /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/{libarch} # fedora
+ # Debian specific paths for default JVM
+ /usr/lib/jvm/default-java/jre/lib/{libarch}
+ /usr/lib/jvm/default-java/jre/lib
+ /usr/lib/jvm/default-java/lib
+ # OpenBSD specific paths for default JVM
+ /usr/local/jdk-1.7.0/jre/lib/{libarch}
+ /usr/local/jre-1.7.0/lib/{libarch}
+ /usr/local/jdk-1.6.0/jre/lib/{libarch}
+ /usr/local/jre-1.6.0/lib/{libarch}
+ )
+
+set(JAVA_JVM_LIBRARY_DIRECTORIES)
+foreach(dir ${JAVA_AWT_LIBRARY_DIRECTORIES})
+ list(APPEND JAVA_JVM_LIBRARY_DIRECTORIES
+ "${dir}"
+ "${dir}/client"
+ "${dir}/server"
+ )
+endforeach()
+
+set(JAVA_AWT_INCLUDE_DIRECTORIES)
+if(_JAVA_HOME)
+ list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES ${_JAVA_HOME}/include)
+endif()
+list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
+ /usr/include
+ /usr/local/include
+ /usr/lib/java/include
+ /usr/local/lib/java/include
+ /usr/lib/jvm/java/include
+ /usr/lib/jvm/java-6-sun/include
+ /usr/lib/jvm/java-1.5.0-sun/include
+ /usr/lib/jvm/java-6-sun-1.6.0.00/include # can this one be removed according to #8821 ? Alex
+ /usr/lib/jvm/java-6-openjdk/include
+ /usr/local/share/java/include
+ /usr/lib/j2sdk1.4-sun/include
+ /usr/lib/j2sdk1.5-sun/include
+ /opt/sun-jdk-1.5.0.04/include
+ # Debian specific path for default JVM
+ /usr/lib/jvm/default-java/include
+ # OpenBSD specific path for default JVM
+ /usr/local/jdk-1.7.0/include
+ /usr/local/jdk-1.6.0/include
+ )
+
+foreach(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
+ get_filename_component(jpath "${JAVA_PROG}" PATH)
+ foreach(JAVA_INC_PATH ../include ../java/include ../share/java/include)
+ if(EXISTS ${jpath}/${JAVA_INC_PATH})
+ list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES "${jpath}/${JAVA_INC_PATH}")
+ endif()
+ endforeach()
+ foreach(JAVA_LIB_PATH
+ ../lib ../jre/lib ../jre/lib/i386
+ ../java/lib ../java/jre/lib ../java/jre/lib/i386
+ ../share/java/lib ../share/java/jre/lib ../share/java/jre/lib/i386)
+ if(EXISTS ${jpath}/${JAVA_LIB_PATH})
+ list(APPEND JAVA_AWT_LIBRARY_DIRECTORIES "${jpath}/${JAVA_LIB_PATH}")
+ endif()
+ endforeach()
+endforeach()
+
+if(APPLE)
+ if(CMAKE_FIND_FRAMEWORK STREQUAL "ONLY")
+ set(_JNI_SEARCHES FRAMEWORK)
+ elseif(CMAKE_FIND_FRAMEWORK STREQUAL "NEVER")
+ set(_JNI_SEARCHES NORMAL)
+ elseif(CMAKE_FIND_FRAMEWORK STREQUAL "LAST")
+ set(_JNI_SEARCHES NORMAL FRAMEWORK)
+ else()
+ set(_JNI_SEARCHES FRAMEWORK NORMAL)
+ endif()
+ set(_JNI_FRAMEWORK_JVM NAMES JavaVM)
+ set(_JNI_FRAMEWORK_JAWT "${_JNI_FRAMEWORK_JVM}")
+else()
+ set(_JNI_SEARCHES NORMAL)
+endif()
+
+set(_JNI_NORMAL_JVM
+ NAMES jvm
+ PATHS ${JAVA_JVM_LIBRARY_DIRECTORIES}
+ )
+
+set(_JNI_NORMAL_JAWT
+ NAMES jawt
+ PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
+ )
+
+foreach(search ${_JNI_SEARCHES})
+ find_library(JAVA_JVM_LIBRARY ${_JNI_${search}_JVM})
+ find_library(JAVA_AWT_LIBRARY ${_JNI_${search}_JAWT})
+ if(JAVA_JVM_LIBRARY)
+ break()
+ endif()
+endforeach()
+unset(_JNI_SEARCHES)
+unset(_JNI_FRAMEWORK_JVM)
+unset(_JNI_FRAMEWORK_JAWT)
+unset(_JNI_NORMAL_JVM)
+unset(_JNI_NORMAL_JAWT)
+
+# Find headers matching the library.
+if("${JAVA_JVM_LIBRARY};${JAVA_AWT_LIBRARY};" MATCHES "(/JavaVM.framework|-framework JavaVM);")
+ set(CMAKE_FIND_FRAMEWORK ONLY)
+else()
+ set(CMAKE_FIND_FRAMEWORK NEVER)
+endif()
+
+# add in the include path
+find_path(JAVA_INCLUDE_PATH jni.h
+ ${JAVA_AWT_INCLUDE_DIRECTORIES}
+)
+
+find_path(JAVA_INCLUDE_PATH2 jni_md.h
+ ${JAVA_INCLUDE_PATH}
+ ${JAVA_INCLUDE_PATH}/darwin
+ ${JAVA_INCLUDE_PATH}/win32
+ ${JAVA_INCLUDE_PATH}/linux
+ ${JAVA_INCLUDE_PATH}/freebsd
+ ${JAVA_INCLUDE_PATH}/openbsd
+ ${JAVA_INCLUDE_PATH}/solaris
+ ${JAVA_INCLUDE_PATH}/hp-ux
+ ${JAVA_INCLUDE_PATH}/alpha
+)
+
+find_path(JAVA_AWT_INCLUDE_PATH jawt.h
+ ${JAVA_INCLUDE_PATH}
+)
+
+# Restore CMAKE_FIND_FRAMEWORK
+if(DEFINED _JNI_CMAKE_FIND_FRAMEWORK)
+ set(CMAKE_FIND_FRAMEWORK ${_JNI_CMAKE_FIND_FRAMEWORK})
+ unset(_JNI_CMAKE_FIND_FRAMEWORK)
+else()
+ unset(CMAKE_FIND_FRAMEWORK)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(JNI DEFAULT_MSG JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
+ JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
+
+mark_as_advanced(
+ JAVA_AWT_LIBRARY
+ JAVA_JVM_LIBRARY
+ JAVA_AWT_INCLUDE_PATH
+ JAVA_INCLUDE_PATH
+ JAVA_INCLUDE_PATH2
+)
+
+set(JNI_LIBRARIES
+ ${JAVA_AWT_LIBRARY}
+ ${JAVA_JVM_LIBRARY}
+)
+
+set(JNI_INCLUDE_DIRS
+ ${JAVA_INCLUDE_PATH}
+ ${JAVA_INCLUDE_PATH2}
+ ${JAVA_AWT_INCLUDE_PATH}
+)
+
diff --git a/Modules/FindJPEG.cmake b/Modules/FindJPEG.cmake
new file mode 100644
index 0000000000..86bb6e5054
--- /dev/null
+++ b/Modules/FindJPEG.cmake
@@ -0,0 +1,54 @@
+#.rst:
+# FindJPEG
+# --------
+#
+# Find JPEG
+#
+# Find the native JPEG includes and library This module defines
+#
+# ::
+#
+# JPEG_INCLUDE_DIR, where to find jpeglib.h, etc.
+# JPEG_LIBRARIES, the libraries needed to use JPEG.
+# JPEG_FOUND, If false, do not try to use JPEG.
+#
+# also defined, but not for general use are
+#
+# ::
+#
+# JPEG_LIBRARY, where to find the JPEG library.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+find_path(JPEG_INCLUDE_DIR jpeglib.h)
+
+set(JPEG_NAMES ${JPEG_NAMES} jpeg libjpeg)
+find_library(JPEG_LIBRARY NAMES ${JPEG_NAMES} )
+
+# handle the QUIETLY and REQUIRED arguments and set JPEG_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(JPEG DEFAULT_MSG JPEG_LIBRARY JPEG_INCLUDE_DIR)
+
+if(JPEG_FOUND)
+ set(JPEG_LIBRARIES ${JPEG_LIBRARY})
+endif()
+
+# Deprecated declarations.
+set (NATIVE_JPEG_INCLUDE_PATH ${JPEG_INCLUDE_DIR} )
+if(JPEG_LIBRARY)
+ get_filename_component (NATIVE_JPEG_LIB_PATH ${JPEG_LIBRARY} PATH)
+endif()
+
+mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR )
diff --git a/Modules/FindJasper.cmake b/Modules/FindJasper.cmake
new file mode 100644
index 0000000000..0f325f0391
--- /dev/null
+++ b/Modules/FindJasper.cmake
@@ -0,0 +1,60 @@
+#.rst:
+# FindJasper
+# ----------
+#
+# Try to find the Jasper JPEG2000 library
+#
+# Once done this will define
+#
+# ::
+#
+# JASPER_FOUND - system has Jasper
+# JASPER_INCLUDE_DIR - the Jasper include directory
+# JASPER_LIBRARIES - the libraries needed to use Jasper
+# JASPER_VERSION_STRING - the version of Jasper found (since CMake 2.8.8)
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+find_path(JASPER_INCLUDE_DIR jasper/jasper.h)
+
+if (NOT JASPER_LIBRARIES)
+ find_package(JPEG)
+
+ find_library(JASPER_LIBRARY_RELEASE NAMES jasper libjasper)
+ find_library(JASPER_LIBRARY_DEBUG NAMES jasperd)
+
+ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+ SELECT_LIBRARY_CONFIGURATIONS(JASPER)
+endif ()
+
+if (JASPER_INCLUDE_DIR AND EXISTS "${JASPER_INCLUDE_DIR}/jasper/jas_config.h")
+ file(STRINGS "${JASPER_INCLUDE_DIR}/jasper/jas_config.h" jasper_version_str REGEX "^#define[\t ]+JAS_VERSION[\t ]+\".*\".*")
+
+ string(REGEX REPLACE "^#define[\t ]+JAS_VERSION[\t ]+\"([^\"]+)\".*" "\\1" JASPER_VERSION_STRING "${jasper_version_str}")
+endif ()
+
+# handle the QUIETLY and REQUIRED arguments and set JASPER_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Jasper
+ REQUIRED_VARS JASPER_LIBRARIES JASPER_INCLUDE_DIR JPEG_LIBRARIES
+ VERSION_VAR JASPER_VERSION_STRING)
+
+if (JASPER_FOUND)
+ set(JASPER_LIBRARIES ${JASPER_LIBRARIES} ${JPEG_LIBRARIES} )
+endif ()
+
+mark_as_advanced(JASPER_INCLUDE_DIR)
diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake
new file mode 100644
index 0000000000..0bd7eb0739
--- /dev/null
+++ b/Modules/FindJava.cmake
@@ -0,0 +1,226 @@
+#.rst:
+# FindJava
+# --------
+#
+# Find Java
+#
+# This module finds if Java is installed and determines where the
+# include files and libraries are. The caller may set variable JAVA_HOME
+# to specify a Java installation prefix explicitly.
+#
+# This module sets the following result variables:
+#
+# ::
+#
+# Java_JAVA_EXECUTABLE = the full path to the Java runtime
+# Java_JAVAC_EXECUTABLE = the full path to the Java compiler
+# Java_JAVAH_EXECUTABLE = the full path to the Java header generator
+# Java_JAVADOC_EXECUTABLE = the full path to the Java documention generator
+# Java_JAR_EXECUTABLE = the full path to the Java archiver
+# Java_VERSION_STRING = Version of the package found (java version), eg. 1.6.0_12
+# Java_VERSION_MAJOR = The major version of the package found.
+# Java_VERSION_MINOR = The minor version of the package found.
+# Java_VERSION_PATCH = The patch version of the package found.
+# Java_VERSION_TWEAK = The tweak version of the package found (after '_')
+# Java_VERSION = This is set to: $major.$minor.$patch(.$tweak)
+#
+#
+#
+# The minimum required version of Java can be specified using the
+# standard CMake syntax, e.g. find_package(Java 1.5)
+#
+# NOTE: ${Java_VERSION} and ${Java_VERSION_STRING} are not guaranteed to
+# be identical. For example some java version may return:
+# Java_VERSION_STRING = 1.5.0_17 and Java_VERSION = 1.5.0.17
+#
+# another example is the Java OEM, with: Java_VERSION_STRING = 1.6.0-oem
+# and Java_VERSION = 1.6.0
+#
+# For these components the following variables are set:
+#
+# ::
+#
+# Java_FOUND - TRUE if all components are found.
+# Java_INCLUDE_DIRS - Full paths to all include dirs.
+# Java_LIBRARIES - Full paths to all libraries.
+# Java_<component>_FOUND - TRUE if <component> is found.
+#
+#
+#
+# Example Usages:
+#
+# ::
+#
+# find_package(Java)
+# find_package(Java COMPONENTS Runtime)
+# find_package(Java COMPONENTS Development)
+
+#=============================================================================
+# Copyright 2002-2009 Kitware, Inc.
+# Copyright 2009-2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
+#
+# 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake)
+
+# The HINTS option should only be used for values computed from the system.
+set(_JAVA_HINTS)
+if(_JAVA_HOME)
+ list(APPEND _JAVA_HINTS ${_JAVA_HOME}/bin)
+endif()
+list(APPEND _JAVA_HINTS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\2.0;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.9;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.8;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.7;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.6;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.5;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/bin"
+ )
+# Hard-coded guesses should still go in PATHS. This ensures that the user
+# environment can always override hard guesses.
+set(_JAVA_PATHS
+ /usr/lib/java/bin
+ /usr/share/java/bin
+ /usr/local/java/bin
+ /usr/local/java/share/bin
+ /usr/java/j2sdk1.4.2_04
+ /usr/lib/j2sdk1.4-sun/bin
+ /usr/java/j2sdk1.4.2_09/bin
+ /usr/lib/j2sdk1.5-sun/bin
+ /opt/sun-jdk-1.5.0.04/bin
+ /usr/local/jdk-1.7.0/bin
+ /usr/local/jdk-1.6.0/bin
+ )
+find_program(Java_JAVA_EXECUTABLE
+ NAMES java
+ HINTS ${_JAVA_HINTS}
+ PATHS ${_JAVA_PATHS}
+)
+
+if(Java_JAVA_EXECUTABLE)
+ execute_process(COMMAND ${Java_JAVA_EXECUTABLE} -version
+ RESULT_VARIABLE res
+ OUTPUT_VARIABLE var
+ ERROR_VARIABLE var # sun-java output to stderr
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_STRIP_TRAILING_WHITESPACE)
+ if( res )
+ if(${Java_FIND_REQUIRED})
+ message( FATAL_ERROR "Error executing java -version" )
+ else()
+ message( STATUS "Warning, could not run java -version")
+ endif()
+ else()
+ # extract major/minor version and patch level from "java -version" output
+ # Tested on linux using
+ # 1. Sun / Sun OEM
+ # 2. OpenJDK 1.6
+ # 3. GCJ 1.5
+ # 4. Kaffe 1.4.2
+ # 5. OpenJDK 1.7.x on OpenBSD
+ if(var MATCHES "java version \"([0-9]+\\.[0-9]+\\.[0-9_.]+.*)\"")
+ # This is most likely Sun / OpenJDK, or maybe GCJ-java compat layer
+ set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
+ elseif(var MATCHES "java full version \"kaffe-([0-9]+\\.[0-9]+\\.[0-9_]+)\"")
+ # Kaffe style
+ set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
+ elseif(var MATCHES "openjdk version \"([0-9]+\\.[0-9]+\\.[0-9_]+)\"")
+ # OpenJDK ver 1.7.x on OpenBSD
+ set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
+ else()
+ if(NOT Java_FIND_QUIETLY)
+ message(WARNING "regex not supported: ${var}. Please report")
+ endif()
+ endif()
+ string( REGEX REPLACE "([0-9]+).*" "\\1" Java_VERSION_MAJOR "${Java_VERSION_STRING}" )
+ string( REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_MINOR "${Java_VERSION_STRING}" )
+ string( REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_PATCH "${Java_VERSION_STRING}" )
+ # warning tweak version can be empty:
+ string( REGEX REPLACE "[0-9]+\\.[0-9]+\\.[0-9]+[_\\.]?([0-9]*).*$" "\\1" Java_VERSION_TWEAK "${Java_VERSION_STRING}" )
+ if( Java_VERSION_TWEAK STREQUAL "" ) # check case where tweak is not defined
+ set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH})
+ else()
+ set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH}.${Java_VERSION_TWEAK})
+ endif()
+ endif()
+
+endif()
+
+
+find_program(Java_JAR_EXECUTABLE
+ NAMES jar
+ HINTS ${_JAVA_HINTS}
+ PATHS ${_JAVA_PATHS}
+)
+
+find_program(Java_JAVAC_EXECUTABLE
+ NAMES javac
+ HINTS ${_JAVA_HINTS}
+ PATHS ${_JAVA_PATHS}
+)
+
+find_program(Java_JAVAH_EXECUTABLE
+ NAMES javah
+ HINTS ${_JAVA_HINTS}
+ PATHS ${_JAVA_PATHS}
+)
+
+find_program(Java_JAVADOC_EXECUTABLE
+ NAMES javadoc
+ HINTS ${_JAVA_HINTS}
+ PATHS ${_JAVA_PATHS}
+)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+if(Java_FIND_COMPONENTS)
+ foreach(component ${Java_FIND_COMPONENTS})
+ # User just want to execute some Java byte-compiled
+ if(component STREQUAL "Runtime")
+ find_package_handle_standard_args(Java
+ REQUIRED_VARS Java_JAVA_EXECUTABLE
+ VERSION_VAR Java_VERSION
+ )
+ elseif(component STREQUAL "Development")
+ find_package_handle_standard_args(Java
+ REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE
+ Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE
+ VERSION_VAR Java_VERSION
+ )
+ else()
+ message(FATAL_ERROR "Comp: ${component} is not handled")
+ endif()
+ set(Java_${component}_FOUND TRUE)
+ endforeach()
+else()
+ # Check for everything
+ find_package_handle_standard_args(Java
+ REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE
+ Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE
+ VERSION_VAR Java_VERSION
+ )
+endif()
+
+
+mark_as_advanced(
+ Java_JAVA_EXECUTABLE
+ Java_JAR_EXECUTABLE
+ Java_JAVAC_EXECUTABLE
+ Java_JAVAH_EXECUTABLE
+ Java_JAVADOC_EXECUTABLE
+ )
+
+# LEGACY
+set(JAVA_RUNTIME ${Java_JAVA_EXECUTABLE})
+set(JAVA_ARCHIVE ${Java_JAR_EXECUTABLE})
+set(JAVA_COMPILE ${Java_JAVAC_EXECUTABLE})
+
diff --git a/Modules/FindKDE3.cmake b/Modules/FindKDE3.cmake
new file mode 100644
index 0000000000..ea898a6508
--- /dev/null
+++ b/Modules/FindKDE3.cmake
@@ -0,0 +1,367 @@
+#.rst:
+# FindKDE3
+# --------
+#
+# Find the KDE3 include and library dirs, KDE preprocessors and define a some macros
+#
+#
+#
+# This module defines the following variables:
+#
+# ::
+#
+# KDE3_DEFINITIONS - compiler definitions required for compiling KDE software
+# KDE3_INCLUDE_DIR - the KDE include directory
+# KDE3_INCLUDE_DIRS - the KDE and the Qt include directory, for use with include_directories()
+# KDE3_LIB_DIR - the directory where the KDE libraries are installed, for use with link_directories()
+# QT_AND_KDECORE_LIBS - this contains both the Qt and the kdecore library
+# KDE3_DCOPIDL_EXECUTABLE - the dcopidl executable
+# KDE3_DCOPIDL2CPP_EXECUTABLE - the dcopidl2cpp executable
+# KDE3_KCFGC_EXECUTABLE - the kconfig_compiler executable
+# KDE3_FOUND - set to TRUE if all of the above has been found
+#
+#
+#
+# The following user adjustable options are provided:
+#
+# ::
+#
+# KDE3_BUILD_TESTS - enable this to build KDE testcases
+#
+#
+#
+#
+#
+# It also adds the following macros (from KDE3Macros.cmake) SRCS_VAR is
+# always the variable which contains the list of source files for your
+# application or library.
+#
+# KDE3_AUTOMOC(file1 ... fileN)
+#
+# ::
+#
+# Call this if you want to have automatic moc file handling.
+# This means if you include "foo.moc" in the source file foo.cpp
+# a moc file for the header foo.h will be created automatically.
+# You can set the property SKIP_AUTOMAKE using set_source_files_properties()
+# to exclude some files in the list from being processed.
+#
+#
+#
+# KDE3_ADD_MOC_FILES(SRCS_VAR file1 ... fileN )
+#
+# ::
+#
+# If you don't use the KDE3_AUTOMOC() macro, for the files
+# listed here moc files will be created (named "foo.moc.cpp")
+#
+#
+#
+# KDE3_ADD_DCOP_SKELS(SRCS_VAR header1.h ... headerN.h )
+#
+# ::
+#
+# Use this to generate DCOP skeletions from the listed headers.
+#
+#
+#
+# KDE3_ADD_DCOP_STUBS(SRCS_VAR header1.h ... headerN.h )
+#
+# ::
+#
+# Use this to generate DCOP stubs from the listed headers.
+#
+#
+#
+# KDE3_ADD_UI_FILES(SRCS_VAR file1.ui ... fileN.ui )
+#
+# ::
+#
+# Use this to add the Qt designer ui files to your application/library.
+#
+#
+#
+# KDE3_ADD_KCFG_FILES(SRCS_VAR file1.kcfgc ... fileN.kcfgc )
+#
+# ::
+#
+# Use this to add KDE kconfig compiler files to your application/library.
+#
+#
+#
+# KDE3_INSTALL_LIBTOOL_FILE(target)
+#
+# ::
+#
+# This will create and install a simple libtool file for the given target.
+#
+#
+#
+# KDE3_ADD_EXECUTABLE(name file1 ... fileN )
+#
+# ::
+#
+# Currently identical to add_executable(), may provide some advanced features in the future.
+#
+#
+#
+# KDE3_ADD_KPART(name [WITH_PREFIX] file1 ... fileN )
+#
+# ::
+#
+# Create a KDE plugin (KPart, kioslave, etc.) from the given source files.
+# If WITH_PREFIX is given, the resulting plugin will have the prefix "lib", otherwise it won't.
+# It creates and installs an appropriate libtool la-file.
+#
+#
+#
+# KDE3_ADD_KDEINIT_EXECUTABLE(name file1 ... fileN )
+#
+# ::
+#
+# Create a KDE application in the form of a module loadable via kdeinit.
+# A library named kdeinit_<name> will be created and a small executable which links to it.
+#
+#
+#
+# The option KDE3_ENABLE_FINAL to enable all-in-one compilation is no
+# longer supported.
+#
+#
+#
+# Author: Alexander Neundorf <neundorf@kde.org>
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+if(NOT UNIX AND KDE3_FIND_REQUIRED)
+ message(FATAL_ERROR "Compiling KDE3 applications and libraries under Windows is not supported")
+endif()
+
+# If Qt4 has already been found, fail.
+if(QT4_FOUND)
+ if(KDE3_FIND_REQUIRED)
+ message( FATAL_ERROR "KDE3/Qt3 and Qt4 cannot be used together in one project.")
+ else()
+ if(NOT KDE3_FIND_QUIETLY)
+ message( STATUS "KDE3/Qt3 and Qt4 cannot be used together in one project.")
+ endif()
+ return()
+ endif()
+endif()
+
+
+set(QT_MT_REQUIRED TRUE)
+#set(QT_MIN_VERSION "3.0.0")
+
+#this line includes FindQt.cmake, which searches the Qt library and headers
+if(KDE3_FIND_REQUIRED)
+ set(_REQ_STRING_KDE3 "REQUIRED")
+endif()
+
+find_package(Qt3 ${_REQ_STRING_KDE3})
+find_package(X11 ${_REQ_STRING_KDE3})
+
+
+#now try to find some kde stuff
+find_program(KDECONFIG_EXECUTABLE NAMES kde-config
+ HINTS
+ $ENV{KDEDIR}/bin
+ PATHS
+ /opt/kde3/bin
+ /opt/kde/bin
+ )
+
+set(KDE3PREFIX)
+if(KDECONFIG_EXECUTABLE)
+ execute_process(COMMAND ${KDECONFIG_EXECUTABLE} --version
+ OUTPUT_VARIABLE kde_config_version )
+
+ string(REGEX MATCH "KDE: .\\." kde_version "${kde_config_version}")
+ if ("${kde_version}" MATCHES "KDE: 3\\.")
+ execute_process(COMMAND ${KDECONFIG_EXECUTABLE} --prefix
+ OUTPUT_VARIABLE kdedir )
+ string(REPLACE "\n" "" KDE3PREFIX "${kdedir}")
+
+ endif ()
+endif()
+
+
+
+# at first the KDE include directory
+# kpassdlg.h comes from kdeui and doesn't exist in KDE4 anymore
+find_path(KDE3_INCLUDE_DIR kpassdlg.h
+ HINTS
+ $ENV{KDEDIR}/include
+ ${KDE3PREFIX}/include
+ PATHS
+ /opt/kde3/include
+ /opt/kde/include
+ /usr/include/kde
+ /usr/local/include/kde
+ )
+
+#now the KDE library directory
+find_library(KDE3_KDECORE_LIBRARY NAMES kdecore
+ HINTS
+ $ENV{KDEDIR}/lib
+ ${KDE3PREFIX}/lib
+ PATHS
+ /opt/kde3/lib
+ /opt/kde/lib
+)
+
+set(QT_AND_KDECORE_LIBS ${QT_LIBRARIES} ${KDE3_KDECORE_LIBRARY})
+
+get_filename_component(KDE3_LIB_DIR ${KDE3_KDECORE_LIBRARY} PATH )
+
+if(NOT KDE3_LIBTOOL_DIR)
+ if(KDE3_KDECORE_LIBRARY MATCHES lib64)
+ set(KDE3_LIBTOOL_DIR /lib64/kde3)
+ else()
+ set(KDE3_LIBTOOL_DIR /lib/kde3)
+ endif()
+endif()
+
+#now search for the dcop utilities
+find_program(KDE3_DCOPIDL_EXECUTABLE NAMES dcopidl
+ HINTS
+ $ENV{KDEDIR}/bin
+ ${KDE3PREFIX}/bin
+ PATHS
+ /opt/kde3/bin
+ /opt/kde/bin
+ )
+
+find_program(KDE3_DCOPIDL2CPP_EXECUTABLE NAMES dcopidl2cpp
+ HINTS
+ $ENV{KDEDIR}/bin
+ ${KDE3PREFIX}/bin
+ PATHS
+ /opt/kde3/bin
+ /opt/kde/bin
+ )
+
+find_program(KDE3_KCFGC_EXECUTABLE NAMES kconfig_compiler
+ HINTS
+ $ENV{KDEDIR}/bin
+ ${KDE3PREFIX}/bin
+ PATHS
+ /opt/kde3/bin
+ /opt/kde/bin
+ )
+
+
+#SET KDE3_FOUND
+if (KDE3_INCLUDE_DIR AND KDE3_LIB_DIR AND KDE3_DCOPIDL_EXECUTABLE AND KDE3_DCOPIDL2CPP_EXECUTABLE AND KDE3_KCFGC_EXECUTABLE)
+ set(KDE3_FOUND TRUE)
+else ()
+ set(KDE3_FOUND FALSE)
+endif ()
+
+# add some KDE specific stuff
+set(KDE3_DEFINITIONS -DQT_CLEAN_NAMESPACE -D_GNU_SOURCE)
+
+# set compiler flags only if KDE3 has actually been found
+if(KDE3_FOUND)
+ set(_KDE3_USE_FLAGS FALSE)
+ if(CMAKE_COMPILER_IS_GNUCXX)
+ set(_KDE3_USE_FLAGS TRUE) # use flags for gnu compiler
+ execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version
+ OUTPUT_VARIABLE out)
+ # gnu gcc 2.96 does not work with flags
+ # I guess 2.95 also doesn't then
+ if("${out}" MATCHES "2.9[56]")
+ set(_KDE3_USE_FLAGS FALSE)
+ endif()
+ endif()
+
+ #only on linux, but NOT e.g. on FreeBSD:
+ if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND _KDE3_USE_FLAGS)
+ set (KDE3_DEFINITIONS ${KDE3_DEFINITIONS} -D_XOPEN_SOURCE=500 -D_BSD_SOURCE)
+ set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long -ansi -Wundef -Wcast-align -Wconversion -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
+ set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wconversion -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -fno-exceptions -fno-check-new -fno-common")
+ endif()
+
+ # works on FreeBSD, NOT tested on NetBSD and OpenBSD
+ if (CMAKE_SYSTEM_NAME MATCHES BSD AND _KDE3_USE_FLAGS)
+ set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long -ansi -Wundef -Wcast-align -Wconversion -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
+ set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -Wundef -Wcast-align -Wconversion -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-exceptions -fno-check-new -fno-common")
+ endif ()
+
+ # if no special buildtype is selected, add -O2 as default optimization
+ if (NOT CMAKE_BUILD_TYPE AND _KDE3_USE_FLAGS)
+ set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
+ set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
+ endif ()
+
+#set(CMAKE_SHARED_LINKER_FLAGS "-avoid-version -module -Wl,--no-undefined -Wl,--allow-shlib-undefined")
+#set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--fatal-warnings -avoid-version -Wl,--no-undefined -lc")
+#set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings -avoid-version -Wl,--no-undefined -lc")
+endif()
+
+
+# KDE3Macros.cmake contains all the KDE specific macros
+include(${CMAKE_CURRENT_LIST_DIR}/KDE3Macros.cmake)
+
+
+macro (KDE3_PRINT_RESULTS)
+ if(KDE3_INCLUDE_DIR)
+ message(STATUS "Found KDE3 include dir: ${KDE3_INCLUDE_DIR}")
+ else()
+ message(STATUS "Didn't find KDE3 headers")
+ endif()
+
+ if(KDE3_LIB_DIR)
+ message(STATUS "Found KDE3 library dir: ${KDE3_LIB_DIR}")
+ else()
+ message(STATUS "Didn't find KDE3 core library")
+ endif()
+
+ if(KDE3_DCOPIDL_EXECUTABLE)
+ message(STATUS "Found KDE3 dcopidl preprocessor: ${KDE3_DCOPIDL_EXECUTABLE}")
+ else()
+ message(STATUS "Didn't find the KDE3 dcopidl preprocessor")
+ endif()
+
+ if(KDE3_DCOPIDL2CPP_EXECUTABLE)
+ message(STATUS "Found KDE3 dcopidl2cpp preprocessor: ${KDE3_DCOPIDL2CPP_EXECUTABLE}")
+ else()
+ message(STATUS "Didn't find the KDE3 dcopidl2cpp preprocessor")
+ endif()
+
+ if(KDE3_KCFGC_EXECUTABLE)
+ message(STATUS "Found KDE3 kconfig_compiler preprocessor: ${KDE3_KCFGC_EXECUTABLE}")
+ else()
+ message(STATUS "Didn't find the KDE3 kconfig_compiler preprocessor")
+ endif()
+
+endmacro ()
+
+
+if (KDE3_FIND_REQUIRED AND NOT KDE3_FOUND)
+ #bail out if something wasn't found
+ KDE3_PRINT_RESULTS()
+ message(FATAL_ERROR "Could NOT find everything required for compiling KDE 3 programs")
+
+endif ()
+
+
+if (NOT KDE3_FIND_QUIETLY)
+ KDE3_PRINT_RESULTS()
+endif ()
+
+#add the found Qt and KDE include directories to the current include path
+set(KDE3_INCLUDE_DIRS ${QT_INCLUDE_DIR} ${KDE3_INCLUDE_DIR})
+
diff --git a/Modules/FindKDE4.cmake b/Modules/FindKDE4.cmake
new file mode 100644
index 0000000000..3c2c309873
--- /dev/null
+++ b/Modules/FindKDE4.cmake
@@ -0,0 +1,113 @@
+#.rst:
+# FindKDE4
+# --------
+#
+#
+#
+# Find KDE4 and provide all necessary variables and macros to compile
+# software for it. It looks for KDE 4 in the following directories in
+# the given order:
+#
+# ::
+#
+# CMAKE_INSTALL_PREFIX
+# KDEDIRS
+# /opt/kde4
+#
+#
+#
+# Please look in FindKDE4Internal.cmake and KDE4Macros.cmake for more
+# information. They are installed with the KDE 4 libraries in
+# $KDEDIRS/share/apps/cmake/modules/.
+#
+# Author: Alexander Neundorf <neundorf@kde.org>
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# If Qt3 has already been found, fail.
+if(QT_QT_LIBRARY)
+ if(KDE4_FIND_REQUIRED)
+ message( FATAL_ERROR "KDE4/Qt4 and Qt3 cannot be used together in one project.")
+ else()
+ if(NOT KDE4_FIND_QUIETLY)
+ message( STATUS "KDE4/Qt4 and Qt3 cannot be used together in one project.")
+ endif()
+ return()
+ endif()
+endif()
+
+file(TO_CMAKE_PATH "$ENV{KDEDIRS}" _KDEDIRS)
+
+# when cross compiling, searching kde4-config in order to run it later on
+# doesn't make a lot of sense. We'll have to do something about this.
+# Searching always in the target environment ? Then we get at least the correct one,
+# still it can't be used to run it. Alex
+
+# For KDE4 kde-config has been renamed to kde4-config
+find_program(KDE4_KDECONFIG_EXECUTABLE NAMES kde4-config
+ # the suffix must be used since KDEDIRS can be a list of directories which don't have bin/ appended
+ PATH_SUFFIXES bin
+ HINTS
+ ${CMAKE_INSTALL_PREFIX}
+ ${_KDEDIRS}
+ /opt/kde4
+ ONLY_CMAKE_FIND_ROOT_PATH
+ )
+
+if (NOT KDE4_KDECONFIG_EXECUTABLE)
+ if (KDE4_FIND_REQUIRED)
+ message(FATAL_ERROR "ERROR: Could not find KDE4 kde4-config")
+ endif ()
+endif ()
+
+
+# when cross compiling, KDE4_DATA_DIR may be already preset
+if(NOT KDE4_DATA_DIR)
+ if(CMAKE_CROSSCOMPILING)
+ # when cross compiling, don't run kde4-config but use its location as install dir
+ get_filename_component(KDE4_DATA_DIR "${KDE4_KDECONFIG_EXECUTABLE}" PATH)
+ get_filename_component(KDE4_DATA_DIR "${KDE4_DATA_DIR}" PATH)
+ else()
+ # then ask kde4-config for the kde data dirs
+
+ if(KDE4_KDECONFIG_EXECUTABLE)
+ execute_process(COMMAND "${KDE4_KDECONFIG_EXECUTABLE}" --path data OUTPUT_VARIABLE _data_DIR ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+ file(TO_CMAKE_PATH "${_data_DIR}" _data_DIR)
+ # then check the data dirs for FindKDE4Internal.cmake
+ find_path(KDE4_DATA_DIR cmake/modules/FindKDE4Internal.cmake HINTS ${_data_DIR})
+ endif()
+ endif()
+endif()
+
+# if it has been found...
+if (KDE4_DATA_DIR)
+
+ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${KDE4_DATA_DIR}/cmake/modules)
+
+ if (KDE4_FIND_QUIETLY)
+ set(_quiet QUIET)
+ endif ()
+
+ if (KDE4_FIND_REQUIRED)
+ set(_req REQUIRED)
+ endif ()
+
+ # use FindKDE4Internal.cmake to do the rest
+ find_package(KDE4Internal ${_req} ${_quiet})
+else ()
+ if (KDE4_FIND_REQUIRED)
+ message(FATAL_ERROR "ERROR: cmake/modules/FindKDE4Internal.cmake not found in ${_data_DIR}")
+ endif ()
+endif ()
diff --git a/Modules/FindLAPACK.cmake b/Modules/FindLAPACK.cmake
new file mode 100644
index 0000000000..b11edc3341
--- /dev/null
+++ b/Modules/FindLAPACK.cmake
@@ -0,0 +1,355 @@
+#.rst:
+# FindLAPACK
+# ----------
+#
+# Find LAPACK library
+#
+# This module finds an installed fortran library that implements the
+# LAPACK linear-algebra interface (see http://www.netlib.org/lapack/).
+#
+# The approach follows that taken for the autoconf macro file,
+# acx_lapack.m4 (distributed at
+# http://ac-archive.sourceforge.net/ac-archive/acx_lapack.html).
+#
+# This module sets the following variables:
+#
+# ::
+#
+# LAPACK_FOUND - set to true if a library implementing the LAPACK interface
+# is found
+# LAPACK_LINKER_FLAGS - uncached list of required linker flags (excluding -l
+# and -L).
+# LAPACK_LIBRARIES - uncached list of libraries (using full path name) to
+# link against to use LAPACK
+# LAPACK95_LIBRARIES - uncached list of libraries (using full path name) to
+# link against to use LAPACK95
+# LAPACK95_FOUND - set to true if a library implementing the LAPACK f95
+# interface is found
+# BLA_STATIC if set on this determines what kind of linkage we do (static)
+# BLA_VENDOR if set checks only the specified vendor, if not set checks
+# all the possibilities
+# BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK
+#
+# ## List of vendors (BLA_VENDOR) valid in this module # Intel(mkl),
+# ACML,Apple, NAS, Generic
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+
+get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
+if (NOT _LANGUAGES_ MATCHES Fortran)
+include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
+else ()
+include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
+endif ()
+include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
+
+cmake_push_check_state()
+set(CMAKE_REQUIRED_QUIET ${LAPACK_FIND_QUIETLY})
+
+set(LAPACK_FOUND FALSE)
+set(LAPACK95_FOUND FALSE)
+
+# TODO: move this stuff to separate module
+
+macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas _threads)
+# This macro checks for the existence of the combination of fortran libraries
+# given by _list. If the combination is found, this macro checks (using the
+# Check_Fortran_Function_Exists macro) whether can link against that library
+# combination using the name of a routine given by _name using the linker
+# flags given by _flags. If the combination of libraries is found and passes
+# the link test, LIBRARIES is set to the list of complete library paths that
+# have been found. Otherwise, LIBRARIES is set to FALSE.
+
+# N.B. _prefix is the prefix applied to the names of all cached variables that
+# are generated internally and marked advanced by this macro.
+
+set(_libraries_work TRUE)
+set(${LIBRARIES})
+set(_combined_name)
+if (NOT _libdir)
+ if (WIN32)
+ set(_libdir ENV LIB)
+ elseif (APPLE)
+ set(_libdir ENV DYLD_LIBRARY_PATH)
+ else ()
+ set(_libdir ENV LD_LIBRARY_PATH)
+ endif ()
+endif ()
+foreach(_library ${_list})
+ set(_combined_name ${_combined_name}_${_library})
+
+ if(_libraries_work)
+ if (BLA_STATIC)
+ if (WIN32)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ endif ()
+ if (APPLE)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ else ()
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ endif ()
+ else ()
+ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ # for ubuntu's libblas3gf and liblapack3gf packages
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
+ endif ()
+ endif ()
+ find_library(${_prefix}_${_library}_LIBRARY
+ NAMES ${_library}
+ PATHS ${_libdir}
+ )
+ mark_as_advanced(${_prefix}_${_library}_LIBRARY)
+ set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
+ set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
+ endif()
+endforeach()
+
+if(_libraries_work)
+ # Test this combination of libraries.
+ if(UNIX AND BLA_STATIC)
+ set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group" ${${LIBRARIES}} ${_blas} "-Wl,--end-group" ${_threads})
+ else()
+ set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads})
+ endif()
+# message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
+ if (NOT _LANGUAGES_ MATCHES Fortran)
+ check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
+ else ()
+ check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
+ endif ()
+ set(CMAKE_REQUIRED_LIBRARIES)
+ mark_as_advanced(${_prefix}${_combined_name}_WORKS)
+ set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
+ #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
+endif()
+
+ if(_libraries_work)
+ set(${LIBRARIES} ${${LIBRARIES}} ${_blas} ${_threads})
+ else()
+ set(${LIBRARIES} FALSE)
+ endif()
+
+endmacro()
+
+
+set(LAPACK_LINKER_FLAGS)
+set(LAPACK_LIBRARIES)
+set(LAPACK95_LIBRARIES)
+
+
+if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
+ find_package(BLAS)
+else()
+ find_package(BLAS REQUIRED)
+endif()
+
+
+if(BLAS_FOUND)
+ set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
+ if (NOT $ENV{BLA_VENDOR} STREQUAL "")
+ set(BLA_VENDOR $ENV{BLA_VENDOR})
+ else ()
+ if(NOT BLA_VENDOR)
+ set(BLA_VENDOR "All")
+ endif()
+ endif ()
+
+if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
+ if(NOT LAPACK_LIBRARIES)
+ check_lapack_libraries(
+ LAPACK_LIBRARIES
+ LAPACK
+ cheev
+ ""
+ "goto2"
+ "${BLAS_LIBRARIES}"
+ ""
+ )
+ endif()
+endif ()
+
+
+#acml lapack
+ if (BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All")
+ if (BLAS_LIBRARIES MATCHES ".+acml.+")
+ set (LAPACK_LIBRARIES ${BLAS_LIBRARIES})
+ endif ()
+ endif ()
+
+# Apple LAPACK library?
+if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
+ if(NOT LAPACK_LIBRARIES)
+ check_lapack_libraries(
+ LAPACK_LIBRARIES
+ LAPACK
+ cheev
+ ""
+ "Accelerate"
+ "${BLAS_LIBRARIES}"
+ ""
+ )
+ endif()
+endif ()
+if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
+ if ( NOT LAPACK_LIBRARIES )
+ check_lapack_libraries(
+ LAPACK_LIBRARIES
+ LAPACK
+ cheev
+ ""
+ "vecLib"
+ "${BLAS_LIBRARIES}"
+ ""
+ )
+ endif ()
+endif ()
+# Generic LAPACK library?
+if (BLA_VENDOR STREQUAL "Generic" OR
+ BLA_VENDOR STREQUAL "ATLAS" OR
+ BLA_VENDOR STREQUAL "All")
+ if ( NOT LAPACK_LIBRARIES )
+ check_lapack_libraries(
+ LAPACK_LIBRARIES
+ LAPACK
+ cheev
+ ""
+ "lapack"
+ "${BLAS_LIBRARIES}"
+ ""
+ )
+ endif ()
+endif ()
+#intel lapack
+if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
+ if (NOT WIN32)
+ set(LM "-lm")
+ endif ()
+ if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
+ if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
+ find_PACKAGE(Threads)
+ else()
+ find_package(Threads REQUIRED)
+ endif()
+
+ set(LAPACK_SEARCH_LIBS "")
+
+ if (BLA_F95)
+ set(LAPACK_mkl_SEARCH_SYMBOL "CHEEV")
+ set(_LIBRARIES LAPACK95_LIBRARIES)
+ set(_BLAS_LIBRARIES ${BLAS95_LIBRARIES})
+
+ # old
+ list(APPEND LAPACK_SEARCH_LIBS
+ "mkl_lapack95")
+ # new >= 10.3
+ list(APPEND LAPACK_SEARCH_LIBS
+ "mkl_intel_c")
+ list(APPEND LAPACK_SEARCH_LIBS
+ "mkl_intel_lp64")
+ else()
+ set(LAPACK_mkl_SEARCH_SYMBOL "cheev")
+ set(_LIBRARIES LAPACK_LIBRARIES)
+ set(_BLAS_LIBRARIES ${BLAS_LIBRARIES})
+
+ # old
+ list(APPEND LAPACK_SEARCH_LIBS
+ "mkl_lapack")
+ # new >= 10.3
+ list(APPEND LAPACK_SEARCH_LIBS
+ "mkl_gf_lp64")
+ endif()
+
+ # First try empty lapack libs
+ if (NOT ${_LIBRARIES})
+ check_lapack_libraries(
+ ${_LIBRARIES}
+ BLAS
+ ${LAPACK_mkl_SEARCH_SYMBOL}
+ ""
+ ""
+ "${_BLAS_LIBRARIES}"
+ "${CMAKE_THREAD_LIBS_INIT};${LM}"
+ )
+ endif ()
+ # Then try the search libs
+ foreach (IT ${LAPACK_SEARCH_LIBS})
+ if (NOT ${_LIBRARIES})
+ check_lapack_libraries(
+ ${_LIBRARIES}
+ BLAS
+ ${LAPACK_mkl_SEARCH_SYMBOL}
+ ""
+ "${IT}"
+ "${_BLAS_LIBRARIES}"
+ "${CMAKE_THREAD_LIBS_INIT};${LM}"
+ )
+ endif ()
+ endforeach ()
+ endif ()
+endif()
+else()
+ message(STATUS "LAPACK requires BLAS")
+endif()
+
+if(BLA_F95)
+ if(LAPACK95_LIBRARIES)
+ set(LAPACK95_FOUND TRUE)
+ else()
+ set(LAPACK95_FOUND FALSE)
+ endif()
+ if(NOT LAPACK_FIND_QUIETLY)
+ if(LAPACK95_FOUND)
+ message(STATUS "A library with LAPACK95 API found.")
+ else()
+ if(LAPACK_FIND_REQUIRED)
+ message(FATAL_ERROR
+ "A required library with LAPACK95 API not found. Please specify library location."
+ )
+ else()
+ message(STATUS
+ "A library with LAPACK95 API not found. Please specify library location."
+ )
+ endif()
+ endif()
+ endif()
+ set(LAPACK_FOUND "${LAPACK95_FOUND}")
+ set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
+else()
+ if(LAPACK_LIBRARIES)
+ set(LAPACK_FOUND TRUE)
+ else()
+ set(LAPACK_FOUND FALSE)
+ endif()
+
+ if(NOT LAPACK_FIND_QUIETLY)
+ if(LAPACK_FOUND)
+ message(STATUS "A library with LAPACK API found.")
+ else()
+ if(LAPACK_FIND_REQUIRED)
+ message(FATAL_ERROR
+ "A required library with LAPACK API not found. Please specify library location."
+ )
+ else()
+ message(STATUS
+ "A library with LAPACK API not found. Please specify library location."
+ )
+ endif()
+ endif()
+ endif()
+endif()
+
+cmake_pop_check_state()
+set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
diff --git a/Modules/FindLATEX.cmake b/Modules/FindLATEX.cmake
new file mode 100644
index 0000000000..e353d384c9
--- /dev/null
+++ b/Modules/FindLATEX.cmake
@@ -0,0 +1,133 @@
+#.rst:
+# FindLATEX
+# ---------
+#
+# Find Latex
+#
+# This module finds if Latex is installed and determines where the
+# executables are. This code sets the following variables:
+#
+# ::
+#
+# LATEX_COMPILER: path to the LaTeX compiler
+# PDFLATEX_COMPILER: path to the PdfLaTeX compiler
+# BIBTEX_COMPILER: path to the BibTeX compiler
+# MAKEINDEX_COMPILER: path to the MakeIndex compiler
+# DVIPS_CONVERTER: path to the DVIPS converter
+# PS2PDF_CONVERTER: path to the PS2PDF converter
+# LATEX2HTML_CONVERTER: path to the LaTeX2Html converter
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+if (WIN32)
+
+ # Try to find the MikTex binary path (look for its package manager).
+
+ find_path(MIKTEX_BINARY_PATH mpm.exe
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MiK\\MiKTeX\\CurrentVersion\\MiKTeX;Install Root]/miktex/bin"
+ DOC
+ "Path to the MikTex binary directory."
+ )
+ mark_as_advanced(MIKTEX_BINARY_PATH)
+
+ # Try to find the GhostScript binary path (look for gswin32).
+
+ get_filename_component(GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_8_00
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\AFPL Ghostscript\\8.00;GS_DLL]" PATH
+ )
+
+ get_filename_component(GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_7_04
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\AFPL Ghostscript\\7.04;GS_DLL]" PATH
+ )
+
+ find_path(GHOSTSCRIPT_BINARY_PATH gswin32.exe
+ ${GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_8_00}
+ ${GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_7_04}
+ DOC "Path to the GhostScript binary directory."
+ )
+ mark_as_advanced(GHOSTSCRIPT_BINARY_PATH)
+
+ find_path(GHOSTSCRIPT_LIBRARY_PATH ps2pdf13.bat
+ "${GHOSTSCRIPT_BINARY_PATH}/../lib"
+ DOC "Path to the GhostScript library directory."
+ )
+ mark_as_advanced(GHOSTSCRIPT_LIBRARY_PATH)
+
+endif ()
+
+find_program(LATEX_COMPILER
+ NAMES latex
+ PATHS ${MIKTEX_BINARY_PATH}
+ /usr/bin
+)
+
+find_program(PDFLATEX_COMPILER
+ NAMES pdflatex
+ PATHS ${MIKTEX_BINARY_PATH}
+ /usr/bin
+)
+
+find_program(BIBTEX_COMPILER
+ NAMES bibtex
+ PATHS ${MIKTEX_BINARY_PATH}
+ /usr/bin
+)
+
+find_program(MAKEINDEX_COMPILER
+ NAMES makeindex
+ PATHS ${MIKTEX_BINARY_PATH}
+ /usr/bin
+)
+
+find_program(DVIPS_CONVERTER
+ NAMES dvips
+ PATHS ${MIKTEX_BINARY_PATH}
+ /usr/bin
+)
+
+find_program(DVIPDF_CONVERTER
+ NAMES dvipdfm dvipdft dvipdf
+ PATHS ${MIKTEX_BINARY_PATH}
+ /usr/bin
+)
+
+if (WIN32)
+ find_program(PS2PDF_CONVERTER
+ NAMES ps2pdf14.bat ps2pdf14 ps2pdf
+ PATHS ${GHOSTSCRIPT_LIBRARY_PATH}
+ ${MIKTEX_BINARY_PATH}
+ )
+else ()
+ find_program(PS2PDF_CONVERTER
+ NAMES ps2pdf14 ps2pdf
+ )
+endif ()
+
+find_program(LATEX2HTML_CONVERTER
+ NAMES latex2html
+ PATHS ${MIKTEX_BINARY_PATH}
+ /usr/bin
+)
+
+
+mark_as_advanced(
+ LATEX_COMPILER
+ PDFLATEX_COMPILER
+ BIBTEX_COMPILER
+ MAKEINDEX_COMPILER
+ DVIPS_CONVERTER
+ DVIPDF_CONVERTER
+ PS2PDF_CONVERTER
+ LATEX2HTML_CONVERTER
+)
diff --git a/Modules/FindLibArchive.cmake b/Modules/FindLibArchive.cmake
new file mode 100644
index 0000000000..471a4f1886
--- /dev/null
+++ b/Modules/FindLibArchive.cmake
@@ -0,0 +1,74 @@
+#.rst:
+# FindLibArchive
+# --------------
+#
+# Find libarchive library and headers
+#
+# The module defines the following variables:
+#
+# ::
+#
+# LibArchive_FOUND - true if libarchive was found
+# LibArchive_INCLUDE_DIRS - include search path
+# LibArchive_LIBRARIES - libraries to link
+# LibArchive_VERSION - libarchive 3-component version number
+
+#=============================================================================
+# Copyright 2010 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.)
+
+find_path(LibArchive_INCLUDE_DIR
+ NAMES archive.h
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/include"
+ )
+
+find_library(LibArchive_LIBRARY
+ NAMES archive libarchive
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/lib"
+ )
+
+mark_as_advanced(LibArchive_INCLUDE_DIR LibArchive_LIBRARY)
+
+# Extract the version number from the header.
+if(LibArchive_INCLUDE_DIR AND EXISTS "${LibArchive_INCLUDE_DIR}/archive.h")
+ # The version string appears in one of two known formats in the header:
+ # #define ARCHIVE_LIBRARY_VERSION "libarchive 2.4.12"
+ # #define ARCHIVE_VERSION_STRING "libarchive 2.8.4"
+ # Match either format.
+ set(_LibArchive_VERSION_REGEX "^#define[ \t]+ARCHIVE[_A-Z]+VERSION[_A-Z]*[ \t]+\"libarchive +([0-9]+)\\.([0-9]+)\\.([0-9]+)[^\"]*\".*$")
+ file(STRINGS "${LibArchive_INCLUDE_DIR}/archive.h" _LibArchive_VERSION_STRING LIMIT_COUNT 1 REGEX "${_LibArchive_VERSION_REGEX}")
+ if(_LibArchive_VERSION_STRING)
+ string(REGEX REPLACE "${_LibArchive_VERSION_REGEX}" "\\1.\\2.\\3" LibArchive_VERSION "${_LibArchive_VERSION_STRING}")
+ endif()
+ unset(_LibArchive_VERSION_REGEX)
+ unset(_LibArchive_VERSION_STRING)
+endif()
+
+# Handle the QUIETLY and REQUIRED arguments and set LIBARCHIVE_FOUND
+# to TRUE if all listed variables are TRUE.
+# (Use ${CMAKE_ROOT}/Modules instead of ${CMAKE_CURRENT_LIST_DIR} because CMake
+# itself includes this FindLibArchive when built with an older CMake that does
+# not provide it. The older CMake also does not have CMAKE_CURRENT_LIST_DIR.)
+include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(LibArchive
+ REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR
+ VERSION_VAR LibArchive_VERSION
+ )
+set(LibArchive_FOUND ${LIBARCHIVE_FOUND})
+unset(LIBARCHIVE_FOUND)
+
+if(LibArchive_FOUND)
+ set(LibArchive_INCLUDE_DIRS ${LibArchive_INCLUDE_DIR})
+ set(LibArchive_LIBRARIES ${LibArchive_LIBRARY})
+endif()
diff --git a/Modules/FindLibLZMA.cmake b/Modules/FindLibLZMA.cmake
new file mode 100644
index 0000000000..742b851cd1
--- /dev/null
+++ b/Modules/FindLibLZMA.cmake
@@ -0,0 +1,80 @@
+#.rst:
+# FindLibLZMA
+# -----------
+#
+# Find LibLZMA
+#
+# Find LibLZMA headers and library
+#
+# ::
+#
+# LIBLZMA_FOUND - True if liblzma is found.
+# LIBLZMA_INCLUDE_DIRS - Directory where liblzma headers are located.
+# LIBLZMA_LIBRARIES - Lzma libraries to link against.
+# LIBLZMA_HAS_AUTO_DECODER - True if lzma_auto_decoder() is found (required).
+# LIBLZMA_HAS_EASY_ENCODER - True if lzma_easy_encoder() is found (required).
+# LIBLZMA_HAS_LZMA_PRESET - True if lzma_lzma_preset() is found (required).
+# LIBLZMA_VERSION_MAJOR - The major version of lzma
+# LIBLZMA_VERSION_MINOR - The minor version of lzma
+# LIBLZMA_VERSION_PATCH - The patch version of lzma
+# LIBLZMA_VERSION_STRING - version number as a string (ex: "5.0.3")
+
+#=============================================================================
+# Copyright 2008 Per Øyvind Karlsen <peroyvind@mandriva.org>
+# Copyright 2009 Alexander Neundorf <neundorf@kde.org>
+# Copyright 2009 Helio Chissini de Castro <helio@kde.org>
+# Copyright 2012 Mario Bensi <mbensi@ipsquad.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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+
+find_path(LIBLZMA_INCLUDE_DIR lzma.h )
+find_library(LIBLZMA_LIBRARY lzma)
+
+if(LIBLZMA_INCLUDE_DIR AND EXISTS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h")
+ file(STRINGS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h" LIBLZMA_HEADER_CONTENTS REGEX "#define LZMA_VERSION_[A-Z]+ [0-9]+")
+
+ string(REGEX REPLACE ".*#define LZMA_VERSION_MAJOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MAJOR "${LIBLZMA_HEADER_CONTENTS}")
+ string(REGEX REPLACE ".*#define LZMA_VERSION_MINOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MINOR "${LIBLZMA_HEADER_CONTENTS}")
+ string(REGEX REPLACE ".*#define LZMA_VERSION_PATCH ([0-9]+).*" "\\1" LIBLZMA_VERSION_PATCH "${LIBLZMA_HEADER_CONTENTS}")
+
+ set(LIBLZMA_VERSION_STRING "${LIBLZMA_VERSION_MAJOR}.${LIBLZMA_VERSION_MINOR}.${LIBLZMA_VERSION_PATCH}")
+ unset(LIBLZMA_HEADER_CONTENTS)
+endif()
+
+# We're using new code known now as XZ, even library still been called LZMA
+# it can be found in http://tukaani.org/xz/
+# Avoid using old codebase
+if (LIBLZMA_LIBRARY)
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
+ set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
+ set(CMAKE_REQUIRED_QUIET ${LibLZMA_FIND_QUIETLY})
+ CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY} lzma_auto_decoder "" LIBLZMA_HAS_AUTO_DECODER)
+ CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY} lzma_easy_encoder "" LIBLZMA_HAS_EASY_ENCODER)
+ CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY} lzma_lzma_preset "" LIBLZMA_HAS_LZMA_PRESET)
+ set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
+endif ()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibLZMA REQUIRED_VARS LIBLZMA_INCLUDE_DIR
+ LIBLZMA_LIBRARY
+ LIBLZMA_HAS_AUTO_DECODER
+ LIBLZMA_HAS_EASY_ENCODER
+ LIBLZMA_HAS_LZMA_PRESET
+ VERSION_VAR LIBLZMA_VERSION_STRING
+ )
+
+if (LIBLZMA_FOUND)
+ set(LIBLZMA_LIBRARIES ${LIBLZMA_LIBRARY})
+ set(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIR})
+endif ()
+
+mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY )
diff --git a/Modules/FindLibXml2.cmake b/Modules/FindLibXml2.cmake
new file mode 100644
index 0000000000..73224286d9
--- /dev/null
+++ b/Modules/FindLibXml2.cmake
@@ -0,0 +1,73 @@
+#.rst:
+# FindLibXml2
+# -----------
+#
+# Try to find the LibXml2 xml processing library
+#
+# Once done this will define
+#
+# ::
+#
+# LIBXML2_FOUND - System has LibXml2
+# LIBXML2_INCLUDE_DIR - The LibXml2 include directory
+# LIBXML2_LIBRARIES - The libraries needed to use LibXml2
+# LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2
+# LIBXML2_XMLLINT_EXECUTABLE - The XML checking tool xmllint coming with LibXml2
+# LIBXML2_VERSION_STRING - the version of LibXml2 found (since CMake 2.8.8)
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# use pkg-config to get the directories and then use these values
+# in the find_path() and find_library() calls
+find_package(PkgConfig QUIET)
+PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0)
+set(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})
+
+find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
+ HINTS
+ ${PC_LIBXML_INCLUDEDIR}
+ ${PC_LIBXML_INCLUDE_DIRS}
+ PATH_SUFFIXES libxml2
+ )
+
+find_library(LIBXML2_LIBRARIES NAMES xml2 libxml2
+ HINTS
+ ${PC_LIBXML_LIBDIR}
+ ${PC_LIBXML_LIBRARY_DIRS}
+ )
+
+find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint)
+# for backwards compat. with KDE 4.0.x:
+set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
+
+if(PC_LIBXML_VERSION)
+ set(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION})
+elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h")
+ file(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str
+ REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"")
+
+ string(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
+ LIBXML2_VERSION_STRING "${libxml2_version_str}")
+ unset(libxml2_version_str)
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2
+ REQUIRED_VARS LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR
+ VERSION_VAR LIBXML2_VERSION_STRING)
+
+mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE)
diff --git a/Modules/FindLibXslt.cmake b/Modules/FindLibXslt.cmake
new file mode 100644
index 0000000000..bf2f821309
--- /dev/null
+++ b/Modules/FindLibXslt.cmake
@@ -0,0 +1,86 @@
+#.rst:
+# FindLibXslt
+# -----------
+#
+# Try to find the LibXslt library
+#
+# Once done this will define
+#
+# ::
+#
+# LIBXSLT_FOUND - system has LibXslt
+# LIBXSLT_INCLUDE_DIR - the LibXslt include directory
+# LIBXSLT_LIBRARIES - Link these to LibXslt
+# LIBXSLT_DEFINITIONS - Compiler switches required for using LibXslt
+# LIBXSLT_VERSION_STRING - version of LibXslt found (since CMake 2.8.8)
+#
+# Additionally, the following two variables are set (but not required
+# for using xslt):
+#
+# ::
+#
+# LIBXSLT_EXSLT_LIBRARIES - Link to these if you need to link against the exslt library
+# LIBXSLT_XSLTPROC_EXECUTABLE - Contains the full path to the xsltproc executable if found
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# use pkg-config to get the directories and then use these values
+# in the find_path() and find_library() calls
+find_package(PkgConfig QUIET)
+PKG_CHECK_MODULES(PC_LIBXSLT QUIET libxslt)
+set(LIBXSLT_DEFINITIONS ${PC_LIBXSLT_CFLAGS_OTHER})
+
+find_path(LIBXSLT_INCLUDE_DIR NAMES libxslt/xslt.h
+ HINTS
+ ${PC_LIBXSLT_INCLUDEDIR}
+ ${PC_LIBXSLT_INCLUDE_DIRS}
+ )
+
+find_library(LIBXSLT_LIBRARIES NAMES xslt libxslt
+ HINTS
+ ${PC_LIBXSLT_LIBDIR}
+ ${PC_LIBXSLT_LIBRARY_DIRS}
+ )
+
+find_library(LIBXSLT_EXSLT_LIBRARY NAMES exslt libexslt
+ HINTS
+ ${PC_LIBXSLT_LIBDIR}
+ ${PC_LIBXSLT_LIBRARY_DIRS}
+ )
+
+set(LIBXSLT_EXSLT_LIBRARIES ${LIBXSLT_EXSLT_LIBRARY} )
+
+find_program(LIBXSLT_XSLTPROC_EXECUTABLE xsltproc)
+
+if(PC_LIBXSLT_VERSION)
+ set(LIBXSLT_VERSION_STRING ${PC_LIBXSLT_VERSION})
+elseif(LIBXSLT_INCLUDE_DIR AND EXISTS "${LIBXSLT_INCLUDE_DIR}/libxslt/xsltconfig.h")
+ file(STRINGS "${LIBXSLT_INCLUDE_DIR}/libxslt/xsltconfig.h" libxslt_version_str
+ REGEX "^#define[\t ]+LIBXSLT_DOTTED_VERSION[\t ]+\".*\"")
+
+ string(REGEX REPLACE "^#define[\t ]+LIBXSLT_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
+ LIBXSLT_VERSION_STRING "${libxslt_version_str}")
+ unset(libxslt_version_str)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXslt
+ REQUIRED_VARS LIBXSLT_LIBRARIES LIBXSLT_INCLUDE_DIR
+ VERSION_VAR LIBXSLT_VERSION_STRING)
+
+mark_as_advanced(LIBXSLT_INCLUDE_DIR
+ LIBXSLT_LIBRARIES
+ LIBXSLT_EXSLT_LIBRARY
+ LIBXSLT_XSLTPROC_EXECUTABLE)
diff --git a/Modules/FindLua.cmake b/Modules/FindLua.cmake
new file mode 100644
index 0000000000..731f5f222c
--- /dev/null
+++ b/Modules/FindLua.cmake
@@ -0,0 +1,171 @@
+#.rst:
+# FindLua
+# -------
+#
+#
+#
+# Locate Lua library This module defines
+#
+# ::
+#
+# LUA_FOUND - if false, do not try to link to Lua
+# LUA_LIBRARIES - both lua and lualib
+# LUA_INCLUDE_DIR - where to find lua.h
+# LUA_VERSION_STRING - the version of Lua found
+# LUA_VERSION_MAJOR - the major version of Lua
+# LUA_VERSION_MINOR - the minor version of Lua
+# LUA_VERSION_PATCH - the patch version of Lua
+#
+#
+#
+# Note that the expected include convention is
+#
+# ::
+#
+# #include "lua.h"
+#
+# and not
+#
+# ::
+#
+# #include <lua/lua.h>
+#
+# This is because, the lua location is not standardized and may exist in
+# locations other than lua/
+
+#=============================================================================
+# Copyright 2007-2009 Kitware, Inc.
+# Copyright 2013 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+unset(_lua_include_subdirs)
+unset(_lua_library_names)
+
+# this is a function only to have all the variables inside go away automatically
+function(set_lua_version_vars)
+ set(LUA_VERSIONS5 5.3 5.2 5.1 5.0)
+
+ if (Lua_FIND_VERSION_EXACT)
+ if (Lua_FIND_VERSION_COUNT GREATER 1)
+ set(lua_append_versions ${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR})
+ endif ()
+ elseif (Lua_FIND_VERSION)
+ # once there is a different major version supported this should become a loop
+ if (NOT Lua_FIND_VERSION_MAJOR GREATER 5)
+ if (Lua_FIND_VERSION_COUNT EQUAL 1)
+ set(lua_append_versions ${LUA_VERSIONS5})
+ else ()
+ foreach (subver IN LISTS LUA_VERSIONS5)
+ if (NOT subver VERSION_LESS ${Lua_FIND_VERSION})
+ list(APPEND lua_append_versions ${subver})
+ endif ()
+ endforeach ()
+ endif ()
+ endif ()
+ else ()
+ # once there is a different major version supported this should become a loop
+ set(lua_append_versions ${LUA_VERSIONS5})
+ endif ()
+
+ foreach (ver IN LISTS lua_append_versions)
+ string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}")
+ list(APPEND _lua_include_subdirs
+ include/lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
+ include/lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+ include/lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+ )
+ list(APPEND _lua_library_names
+ lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
+ lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+ lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+ )
+ endforeach ()
+
+ set(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE)
+ set(_lua_library_names "${_lua_library_names}" PARENT_SCOPE)
+endfunction(set_lua_version_vars)
+
+set_lua_version_vars()
+
+find_path(LUA_INCLUDE_DIR lua.h
+ HINTS
+ ENV LUA_DIR
+ PATH_SUFFIXES ${_lua_include_subdirs} include/lua include
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+)
+unset(_lua_include_subdirs)
+
+find_library(LUA_LIBRARY
+ NAMES ${_lua_library_names} lua
+ HINTS
+ ENV LUA_DIR
+ PATH_SUFFIXES lib
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+)
+unset(_lua_library_names)
+
+if (LUA_LIBRARY)
+ # include the math library for Unix
+ if (UNIX AND NOT APPLE AND NOT BEOS)
+ find_library(LUA_MATH_LIBRARY m)
+ set(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}")
+ # For Windows and Mac, don't need to explicitly include the math library
+ else ()
+ set(LUA_LIBRARIES "${LUA_LIBRARY}")
+ endif ()
+endif ()
+
+if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
+ # At least 5.[012] have different ways to express the version
+ # so all of them need to be tested. Lua 5.2 defines LUA_VERSION
+ # and LUA_RELEASE as joined by the C preprocessor, so avoid those.
+ file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_strings
+ REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*")
+
+ string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};")
+ if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$")
+ string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};")
+ string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};")
+ set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
+ else ()
+ string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
+ if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$")
+ string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
+ endif ()
+ string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}")
+ string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}")
+ string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}")
+ endif ()
+
+ unset(lua_version_strings)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
+# all listed variables are TRUE
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
+ REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
+ VERSION_VAR LUA_VERSION_STRING)
+
+mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY)
diff --git a/Modules/FindLua50.cmake b/Modules/FindLua50.cmake
new file mode 100644
index 0000000000..666d90960a
--- /dev/null
+++ b/Modules/FindLua50.cmake
@@ -0,0 +1,108 @@
+#.rst:
+# FindLua50
+# ---------
+#
+#
+#
+# Locate Lua library This module defines
+#
+# ::
+#
+# LUA50_FOUND, if false, do not try to link to Lua
+# LUA_LIBRARIES, both lua and lualib
+# LUA_INCLUDE_DIR, where to find lua.h and lualib.h (and probably lauxlib.h)
+#
+#
+#
+# Note that the expected include convention is
+#
+# ::
+#
+# #include "lua.h"
+#
+# and not
+#
+# ::
+#
+# #include <lua/lua.h>
+#
+# This is because, the lua location is not standardized and may exist in
+# locations other than lua/
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+find_path(LUA_INCLUDE_DIR lua.h
+ HINTS
+ ENV LUA_DIR
+ PATH_SUFFIXES include/lua50 include/lua5.0 include/lua5 include/lua include
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+)
+
+find_library(LUA_LIBRARY_lua
+ NAMES lua50 lua5.0 lua-5.0 lua5 lua
+ HINTS
+ ENV LUA_DIR
+ PATH_SUFFIXES lib
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+)
+
+# In an OS X framework, lualib is usually included as part of the framework
+# (like GLU in OpenGL.framework)
+if(${LUA_LIBRARY_lua} MATCHES "framework")
+ set( LUA_LIBRARIES "${LUA_LIBRARY_lua}" CACHE STRING "Lua framework")
+else()
+ find_library(LUA_LIBRARY_lualib
+ NAMES lualib50 lualib5.0 lualib5 lualib
+ HINTS
+ ENV LUALIB_DIR
+ ENV LUA_DIR
+ PATH_SUFFIXES lib
+ PATHS
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ )
+ if(LUA_LIBRARY_lualib AND LUA_LIBRARY_lua)
+ # include the math library for Unix
+ if(UNIX AND NOT APPLE)
+ find_library(MATH_LIBRARY_FOR_LUA m)
+ set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua};${MATH_LIBRARY_FOR_LUA}" CACHE STRING "This is the concatentation of lua and lualib libraries")
+ # For Windows and Mac, don't need to explicitly include the math library
+ else()
+ set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua}" CACHE STRING "This is the concatentation of lua and lualib libraries")
+ endif()
+ endif()
+endif()
+
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
+# all listed variables are TRUE
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua50 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR)
+
+mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES)
+
diff --git a/Modules/FindLua51.cmake b/Modules/FindLua51.cmake
new file mode 100644
index 0000000000..5b9ff91a75
--- /dev/null
+++ b/Modules/FindLua51.cmake
@@ -0,0 +1,99 @@
+#.rst:
+# FindLua51
+# ---------
+#
+#
+#
+# Locate Lua library This module defines
+#
+# ::
+#
+# LUA51_FOUND, if false, do not try to link to Lua
+# LUA_LIBRARIES
+# LUA_INCLUDE_DIR, where to find lua.h
+# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
+#
+#
+#
+# Note that the expected include convention is
+#
+# ::
+#
+# #include "lua.h"
+#
+# and not
+#
+# ::
+#
+# #include <lua/lua.h>
+#
+# This is because, the lua location is not standardized and may exist in
+# locations other than lua/
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+find_path(LUA_INCLUDE_DIR lua.h
+ HINTS
+ ENV LUA_DIR
+ PATH_SUFFIXES include/lua51 include/lua5.1 include/lua-5.1 include/lua include
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+)
+
+find_library(LUA_LIBRARY
+ NAMES lua51 lua5.1 lua-5.1 lua
+ HINTS
+ ENV LUA_DIR
+ PATH_SUFFIXES lib
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+)
+
+if(LUA_LIBRARY)
+ # include the math library for Unix
+ if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
+ find_library(LUA_MATH_LIBRARY m)
+ set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
+ # For Windows and Mac, don't need to explicitly include the math library
+ else()
+ set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
+ endif()
+endif()
+
+if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
+ file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
+
+ string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
+ unset(lua_version_str)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
+# all listed variables are TRUE
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51
+ REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
+ VERSION_VAR LUA_VERSION_STRING)
+
+mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)
+
diff --git a/Modules/FindMFC.cmake b/Modules/FindMFC.cmake
new file mode 100644
index 0000000000..261ebdb4de
--- /dev/null
+++ b/Modules/FindMFC.cmake
@@ -0,0 +1,69 @@
+#.rst:
+# FindMFC
+# -------
+#
+# Find MFC on Windows
+#
+# Find the native MFC - i.e. decide if an application can link to the
+# MFC libraries.
+#
+# ::
+#
+# MFC_FOUND - Was MFC support found
+#
+# You don't need to include anything or link anything to use it.
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+# Assume no MFC support
+set(MFC_FOUND "NO")
+
+# Only attempt the try_compile call if it has a chance to succeed:
+set(MFC_ATTEMPT_TRY_COMPILE 0)
+if(WIN32 AND NOT UNIX AND NOT BORLAND AND NOT MINGW)
+ set(MFC_ATTEMPT_TRY_COMPILE 1)
+endif()
+
+if(MFC_ATTEMPT_TRY_COMPILE)
+ if("MFC_HAVE_MFC" MATCHES "^MFC_HAVE_MFC$")
+ set(CHECK_INCLUDE_FILE_VAR "afxwin.h")
+ configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx)
+ message(STATUS "Looking for MFC")
+ try_compile(MFC_HAVE_MFC
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
+ CMAKE_FLAGS
+ -DCMAKE_MFC_FLAG:STRING=2
+ -DCOMPILE_DEFINITIONS:STRING=-D_AFXDLL
+ OUTPUT_VARIABLE OUTPUT)
+ if(MFC_HAVE_MFC)
+ message(STATUS "Looking for MFC - found")
+ set(MFC_HAVE_MFC 1 CACHE INTERNAL "Have MFC?")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if MFC exists passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else()
+ message(STATUS "Looking for MFC - not found")
+ set(MFC_HAVE_MFC 0 CACHE INTERNAL "Have MFC?")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if MFC exists failed with the following output:\n"
+ "${OUTPUT}\n\n")
+ endif()
+ endif()
+
+ if(MFC_HAVE_MFC)
+ set(MFC_FOUND "YES")
+ endif()
+endif()
diff --git a/Modules/FindMPEG.cmake b/Modules/FindMPEG.cmake
new file mode 100644
index 0000000000..26ee8dd433
--- /dev/null
+++ b/Modules/FindMPEG.cmake
@@ -0,0 +1,56 @@
+#.rst:
+# FindMPEG
+# --------
+#
+# Find the native MPEG includes and library
+#
+# This module defines
+#
+# ::
+#
+# MPEG_INCLUDE_DIR, where to find MPEG.h, etc.
+# MPEG_LIBRARIES, the libraries required to use MPEG.
+# MPEG_FOUND, If false, do not try to use MPEG.
+#
+# also defined, but not for general use are
+#
+# ::
+#
+# MPEG_mpeg2_LIBRARY, where to find the MPEG library.
+# MPEG_vo_LIBRARY, where to find the vo library.
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+find_path(MPEG_INCLUDE_DIR mpeg2dec/include/video_out.h
+ /usr/local/livid
+)
+
+find_library(MPEG_mpeg2_LIBRARY mpeg2
+ /usr/local/livid/mpeg2dec/libmpeg2/.libs
+)
+
+find_library( MPEG_vo_LIBRARY vo
+ /usr/local/livid/mpeg2dec/libvo/.libs
+)
+
+# handle the QUIETLY and REQUIRED arguments and set MPEG2_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(MPEG DEFAULT_MSG MPEG_INCLUDE_DIR MPEG_mpeg2_LIBRARY MPEG_vo_LIBRARY)
+
+if(MPEG_FOUND)
+ set( MPEG_LIBRARIES ${MPEG_mpeg2_LIBRARY} ${MPEG_vo_LIBRARY} )
+endif()
+
+mark_as_advanced(MPEG_INCLUDE_DIR MPEG_mpeg2_LIBRARY MPEG_vo_LIBRARY)
diff --git a/Modules/FindMPEG2.cmake b/Modules/FindMPEG2.cmake
new file mode 100644
index 0000000000..f2f207610d
--- /dev/null
+++ b/Modules/FindMPEG2.cmake
@@ -0,0 +1,66 @@
+#.rst:
+# FindMPEG2
+# ---------
+#
+# Find the native MPEG2 includes and library
+#
+# This module defines
+#
+# ::
+#
+# MPEG2_INCLUDE_DIR, path to mpeg2dec/mpeg2.h, etc.
+# MPEG2_LIBRARIES, the libraries required to use MPEG2.
+# MPEG2_FOUND, If false, do not try to use MPEG2.
+#
+# also defined, but not for general use are
+#
+# ::
+#
+# MPEG2_mpeg2_LIBRARY, where to find the MPEG2 library.
+# MPEG2_vo_LIBRARY, where to find the vo library.
+
+#=============================================================================
+# Copyright 2003-2009 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.)
+
+find_path(MPEG2_INCLUDE_DIR
+ NAMES mpeg2.h mpeg2dec/mpeg2.h
+ PATHS /usr/local/livid
+)
+
+find_library(MPEG2_mpeg2_LIBRARY mpeg2
+ /usr/local/livid/mpeg2dec/libmpeg2/.libs
+)
+
+find_library( MPEG2_vo_LIBRARY vo
+ /usr/local/livid/mpeg2dec/libvo/.libs
+)
+
+
+# handle the QUIETLY and REQUIRED arguments and set MPEG2_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(MPEG2 DEFAULT_MSG MPEG2_mpeg2_LIBRARY MPEG2_INCLUDE_DIR)
+
+if(MPEG2_FOUND)
+ set( MPEG2_LIBRARIES ${MPEG2_mpeg2_LIBRARY}
+ ${MPEG2_vo_LIBRARY})
+
+ #some native mpeg2 installations will depend
+ #on libSDL, if found, add it in.
+ include(${CMAKE_CURRENT_LIST_DIR}/FindSDL.cmake)
+ if(SDL_FOUND)
+ set( MPEG2_LIBRARIES ${MPEG2_LIBRARIES} ${SDL_LIBRARY})
+ endif()
+endif()
+
+mark_as_advanced(MPEG2_INCLUDE_DIR MPEG2_mpeg2_LIBRARY MPEG2_vo_LIBRARY)
diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake
new file mode 100644
index 0000000000..3be5e3ceec
--- /dev/null
+++ b/Modules/FindMPI.cmake
@@ -0,0 +1,658 @@
+#.rst:
+# FindMPI
+# -------
+#
+# Find a Message Passing Interface (MPI) implementation
+#
+# The Message Passing Interface (MPI) is a library used to write
+# high-performance distributed-memory parallel applications, and is
+# typically deployed on a cluster. MPI is a standard interface (defined
+# by the MPI forum) for which many implementations are available. All
+# of them have somewhat different include paths, libraries to link
+# against, etc., and this module tries to smooth out those differences.
+#
+# === Variables ===
+#
+# This module will set the following variables per language in your
+# project, where <lang> is one of C, CXX, or Fortran:
+#
+# ::
+#
+# MPI_<lang>_FOUND TRUE if FindMPI found MPI flags for <lang>
+# MPI_<lang>_COMPILER MPI Compiler wrapper for <lang>
+# MPI_<lang>_COMPILE_FLAGS Compilation flags for MPI programs
+# MPI_<lang>_INCLUDE_PATH Include path(s) for MPI header
+# MPI_<lang>_LINK_FLAGS Linking flags for MPI programs
+# MPI_<lang>_LIBRARIES All libraries to link MPI programs against
+#
+# Additionally, FindMPI sets the following variables for running MPI
+# programs from the command line:
+#
+# ::
+#
+# MPIEXEC Executable for running MPI programs
+# MPIEXEC_NUMPROC_FLAG Flag to pass to MPIEXEC before giving
+# it the number of processors to run on
+# MPIEXEC_PREFLAGS Flags to pass to MPIEXEC directly
+# before the executable to run.
+# MPIEXEC_POSTFLAGS Flags to pass to MPIEXEC after other flags
+#
+# === Usage ===
+#
+# To use this module, simply call FindMPI from a CMakeLists.txt file, or
+# run find_package(MPI), then run CMake. If you are happy with the
+# auto- detected configuration for your language, then you're done. If
+# not, you have two options:
+#
+# ::
+#
+# 1. Set MPI_<lang>_COMPILER to the MPI wrapper (mpicc, etc.) of your
+# choice and reconfigure. FindMPI will attempt to determine all the
+# necessary variables using THAT compiler's compile and link flags.
+# 2. If this fails, or if your MPI implementation does not come with
+# a compiler wrapper, then set both MPI_<lang>_LIBRARIES and
+# MPI_<lang>_INCLUDE_PATH. You may also set any other variables
+# listed above, but these two are required. This will circumvent
+# autodetection entirely.
+#
+# When configuration is successful, MPI_<lang>_COMPILER will be set to
+# the compiler wrapper for <lang>, if it was found. MPI_<lang>_FOUND
+# and other variables above will be set if any MPI implementation was
+# found for <lang>, regardless of whether a compiler was found.
+#
+# When using MPIEXEC to execute MPI applications, you should typically
+# use all of the MPIEXEC flags as follows:
+#
+# ::
+#
+# ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} PROCS
+# ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS
+#
+# where PROCS is the number of processors on which to execute the
+# program, EXECUTABLE is the MPI program, and ARGS are the arguments to
+# pass to the MPI program.
+#
+# === Backward Compatibility ===
+#
+# For backward compatibility with older versions of FindMPI, these
+# variables are set, but deprecated:
+#
+# ::
+#
+# MPI_FOUND MPI_COMPILER MPI_LIBRARY
+# MPI_COMPILE_FLAGS MPI_INCLUDE_PATH MPI_EXTRA_LIBRARY
+# MPI_LINK_FLAGS MPI_LIBRARIES
+#
+# In new projects, please use the MPI_<lang>_XXX equivalents.
+
+#=============================================================================
+# Copyright 2001-2011 Kitware, Inc.
+# Copyright 2010-2011 Todd Gamblin tgamblin@llnl.gov
+# Copyright 2001-2009 Dave Partyka
+#
+# 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.)
+
+# include this to handle the QUIETLY and REQUIRED arguments
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/GetPrerequisites.cmake)
+
+#
+# This part detects MPI compilers, attempting to wade through the mess of compiler names in
+# a sensible way.
+#
+# The compilers are detected in this order:
+#
+# 1. Try to find the most generic available MPI compiler, as this is usually set up by
+# cluster admins. e.g., if plain old mpicc is available, we'll use it and assume it's
+# the right compiler.
+#
+# 2. If a generic mpicc is NOT found, then we attempt to find one that matches
+# CMAKE_<lang>_COMPILER_ID. e.g. if you are using XL compilers, we'll try to find mpixlc
+# and company, but not mpiicc. This hopefully prevents toolchain mismatches.
+#
+# If you want to force a particular MPI compiler other than what we autodetect (e.g. if you
+# want to compile regular stuff with GNU and parallel stuff with Intel), you can always set
+# your favorite MPI_<lang>_COMPILER explicitly and this stuff will be ignored.
+#
+
+# Start out with the generic MPI compiler names, as these are most commonly used.
+set(_MPI_C_COMPILER_NAMES mpicc mpcc mpicc_r mpcc_r)
+set(_MPI_CXX_COMPILER_NAMES mpicxx mpiCC mpcxx mpCC mpic++ mpc++
+ mpicxx_r mpiCC_r mpcxx_r mpCC_r mpic++_r mpc++_r)
+set(_MPI_Fortran_COMPILER_NAMES mpif95 mpif95_r mpf95 mpf95_r
+ mpif90 mpif90_r mpf90 mpf90_r
+ mpif77 mpif77_r mpf77 mpf77_r)
+
+# GNU compiler names
+set(_MPI_GNU_C_COMPILER_NAMES mpigcc mpgcc mpigcc_r mpgcc_r)
+set(_MPI_GNU_CXX_COMPILER_NAMES mpig++ mpg++ mpig++_r mpg++_r)
+set(_MPI_GNU_Fortran_COMPILER_NAMES mpigfortran mpgfortran mpigfortran_r mpgfortran_r
+ mpig77 mpig77_r mpg77 mpg77_r)
+
+# Intel MPI compiler names
+set(_MPI_Intel_C_COMPILER_NAMES mpiicc)
+set(_MPI_Intel_CXX_COMPILER_NAMES mpiicpc mpiicxx mpiic++ mpiiCC)
+set(_MPI_Intel_Fortran_COMPILER_NAMES mpiifort mpiif95 mpiif90 mpiif77)
+
+# PGI compiler names
+set(_MPI_PGI_C_COMPILER_NAMES mpipgcc mppgcc)
+set(_MPI_PGI_CXX_COMPILER_NAMES mpipgCC mppgCC)
+set(_MPI_PGI_Fortran_COMPILER_NAMES mpipgf95 mpipgf90 mppgf95 mppgf90 mpipgf77 mppgf77)
+
+# XLC MPI Compiler names
+set(_MPI_XL_C_COMPILER_NAMES mpxlc mpxlc_r mpixlc mpixlc_r)
+set(_MPI_XL_CXX_COMPILER_NAMES mpixlcxx mpixlC mpixlc++ mpxlcxx mpxlc++ mpixlc++ mpxlCC
+ mpixlcxx_r mpixlC_r mpixlc++_r mpxlcxx_r mpxlc++_r mpixlc++_r mpxlCC_r)
+set(_MPI_XL_Fortran_COMPILER_NAMES mpixlf95 mpixlf95_r mpxlf95 mpxlf95_r
+ mpixlf90 mpixlf90_r mpxlf90 mpxlf90_r
+ mpixlf77 mpixlf77_r mpxlf77 mpxlf77_r
+ mpixlf mpixlf_r mpxlf mpxlf_r)
+
+# append vendor-specific compilers to the list if we either don't know the compiler id,
+# or if we know it matches the regular compiler.
+foreach (lang C CXX Fortran)
+ foreach (id GNU Intel PGI XL)
+ if (NOT CMAKE_${lang}_COMPILER_ID OR "${CMAKE_${lang}_COMPILER_ID}" STREQUAL "${id}")
+ list(APPEND _MPI_${lang}_COMPILER_NAMES ${_MPI_${id}_${lang}_COMPILER_NAMES})
+ endif()
+ unset(_MPI_${id}_${lang}_COMPILER_NAMES) # clean up the namespace here
+ endforeach()
+endforeach()
+
+
+# Names to try for MPI exec
+set(_MPI_EXEC_NAMES mpiexec mpirun lamexec srun)
+
+# Grab the path to MPI from the registry if we're on windows.
+set(_MPI_PREFIX_PATH)
+if(WIN32)
+ list(APPEND _MPI_PREFIX_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MPICH\\SMPD;binary]/..")
+ list(APPEND _MPI_PREFIX_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MPICH2;Path]")
+ list(APPEND _MPI_PREFIX_PATH "$ENV{ProgramW6432}/MPICH2/")
+endif()
+
+# Build a list of prefixes to search for MPI.
+foreach(SystemPrefixDir ${CMAKE_SYSTEM_PREFIX_PATH})
+ foreach(MpiPackageDir ${_MPI_PREFIX_PATH})
+ if(EXISTS ${SystemPrefixDir}/${MpiPackageDir})
+ list(APPEND _MPI_PREFIX_PATH "${SystemPrefixDir}/${MpiPackageDir}")
+ endif()
+ endforeach()
+endforeach()
+
+
+#
+# interrogate_mpi_compiler(lang try_libs)
+#
+# Attempts to extract compiler and linker args from an MPI compiler. The arguments set
+# by this function are:
+#
+# MPI_<lang>_INCLUDE_PATH MPI_<lang>_LINK_FLAGS MPI_<lang>_FOUND
+# MPI_<lang>_COMPILE_FLAGS MPI_<lang>_LIBRARIES
+#
+# MPI_<lang>_COMPILER must be set beforehand to the absolute path to an MPI compiler for
+# <lang>. Additionally, MPI_<lang>_INCLUDE_PATH and MPI_<lang>_LIBRARIES may be set
+# to skip autodetection.
+#
+# If try_libs is TRUE, this will also attempt to find plain MPI libraries in the usual
+# way. In general, this is not as effective as interrogating the compilers, as it
+# ignores language-specific flags and libraries. However, some MPI implementations
+# (Windows implementations) do not have compiler wrappers, so this approach must be used.
+#
+function (interrogate_mpi_compiler lang try_libs)
+ # MPI_${lang}_NO_INTERROGATE will be set to a compiler name when the *regular* compiler was
+ # discovered to be the MPI compiler. This happens on machines like the Cray XE6 that use
+ # modules to set cc, CC, and ftn to the MPI compilers. If the user force-sets another MPI
+ # compiler, MPI_${lang}_COMPILER won't be equal to MPI_${lang}_NO_INTERROGATE, and we'll
+ # inspect that compiler anew. This allows users to set new compilers w/o rm'ing cache.
+ string(COMPARE NOTEQUAL "${MPI_${lang}_NO_INTERROGATE}" "${MPI_${lang}_COMPILER}" interrogate)
+
+ # If MPI is set already in the cache, don't bother with interrogating the compiler.
+ if (interrogate AND ((NOT MPI_${lang}_INCLUDE_PATH) OR (NOT MPI_${lang}_LIBRARIES)))
+ if (MPI_${lang}_COMPILER)
+ # Check whether the -showme:compile option works. This indicates that we have either OpenMPI
+ # or a newer version of LAM-MPI, and implies that -showme:link will also work.
+ execute_process(
+ COMMAND ${MPI_${lang}_COMPILER} -showme:compile
+ OUTPUT_VARIABLE MPI_COMPILE_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE MPI_COMPILE_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE MPI_COMPILER_RETURN)
+
+ if (MPI_COMPILER_RETURN EQUAL 0)
+ # If we appear to have -showme:compile, then we should
+ # also have -showme:link. Try it.
+ execute_process(
+ COMMAND ${MPI_${lang}_COMPILER} -showme:link
+ OUTPUT_VARIABLE MPI_LINK_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE MPI_LINK_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE MPI_COMPILER_RETURN)
+
+ if (MPI_COMPILER_RETURN EQUAL 0)
+ # We probably have -showme:incdirs and -showme:libdirs as well,
+ # so grab that while we're at it.
+ execute_process(
+ COMMAND ${MPI_${lang}_COMPILER} -showme:incdirs
+ OUTPUT_VARIABLE MPI_INCDIRS OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE MPI_INCDIRS ERROR_STRIP_TRAILING_WHITESPACE)
+
+ execute_process(
+ COMMAND ${MPI_${lang}_COMPILER} -showme:libdirs
+ OUTPUT_VARIABLE MPI_LIBDIRS OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE MPI_LIBDIRS ERROR_STRIP_TRAILING_WHITESPACE)
+
+ else()
+ # reset things here if something went wrong.
+ set(MPI_COMPILE_CMDLINE)
+ set(MPI_LINK_CMDLINE)
+ endif()
+ endif ()
+
+ # Older versions of LAM-MPI have "-showme". Try to find that.
+ if (NOT MPI_COMPILER_RETURN EQUAL 0)
+ execute_process(
+ COMMAND ${MPI_${lang}_COMPILER} -showme
+ OUTPUT_VARIABLE MPI_COMPILE_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE MPI_COMPILE_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE MPI_COMPILER_RETURN)
+ endif()
+
+ # MVAPICH uses -compile-info and -link-info. Try them.
+ if (NOT MPI_COMPILER_RETURN EQUAL 0)
+ execute_process(
+ COMMAND ${MPI_${lang}_COMPILER} -compile-info
+ OUTPUT_VARIABLE MPI_COMPILE_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE MPI_COMPILE_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE MPI_COMPILER_RETURN)
+
+ # If we have compile-info, also have link-info.
+ if (MPI_COMPILER_RETURN EQUAL 0)
+ execute_process(
+ COMMAND ${MPI_${lang}_COMPILER} -link-info
+ OUTPUT_VARIABLE MPI_LINK_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE MPI_LINK_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE MPI_COMPILER_RETURN)
+ endif()
+
+ # make sure we got compile and link. Reset vars if something's wrong.
+ if (NOT MPI_COMPILER_RETURN EQUAL 0)
+ set(MPI_COMPILE_CMDLINE)
+ set(MPI_LINK_CMDLINE)
+ endif()
+ endif()
+
+ # MPICH just uses "-show". Try it.
+ if (NOT MPI_COMPILER_RETURN EQUAL 0)
+ execute_process(
+ COMMAND ${MPI_${lang}_COMPILER} -show
+ OUTPUT_VARIABLE MPI_COMPILE_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE MPI_COMPILE_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE MPI_COMPILER_RETURN)
+ endif()
+
+ if (MPI_COMPILER_RETURN EQUAL 0)
+ # We have our command lines, but we might need to copy MPI_COMPILE_CMDLINE
+ # into MPI_LINK_CMDLINE, if we didn't find the link line.
+ if (NOT MPI_LINK_CMDLINE)
+ set(MPI_LINK_CMDLINE ${MPI_COMPILE_CMDLINE})
+ endif()
+ else()
+ message(STATUS "Unable to determine MPI from MPI driver ${MPI_${lang}_COMPILER}")
+ set(MPI_COMPILE_CMDLINE)
+ set(MPI_LINK_CMDLINE)
+ endif()
+
+ # Here, we're done with the interrogation part, and we'll try to extract args we care
+ # about from what we learned from the compiler wrapper scripts.
+
+ # If interrogation came back with something, extract our variable from the MPI command line
+ if (MPI_COMPILE_CMDLINE OR MPI_LINK_CMDLINE)
+ # Extract compile flags from the compile command line.
+ string(REGEX MATCHALL "(^| )-[Df]([^\" ]+|\"[^\"]+\")" MPI_ALL_COMPILE_FLAGS "${MPI_COMPILE_CMDLINE}")
+ set(MPI_COMPILE_FLAGS_WORK)
+
+ foreach(FLAG ${MPI_ALL_COMPILE_FLAGS})
+ if (MPI_COMPILE_FLAGS_WORK)
+ set(MPI_COMPILE_FLAGS_WORK "${MPI_COMPILE_FLAGS_WORK} ${FLAG}")
+ else()
+ set(MPI_COMPILE_FLAGS_WORK ${FLAG})
+ endif()
+ endforeach()
+
+ # Extract include paths from compile command line
+ string(REGEX MATCHALL "(^| )-I([^\" ]+|\"[^\"]+\")" MPI_ALL_INCLUDE_PATHS "${MPI_COMPILE_CMDLINE}")
+ foreach(IPATH ${MPI_ALL_INCLUDE_PATHS})
+ string(REGEX REPLACE "^ ?-I" "" IPATH ${IPATH})
+ string(REPLACE "//" "/" IPATH ${IPATH})
+ list(APPEND MPI_INCLUDE_PATH_WORK ${IPATH})
+ endforeach()
+
+ # try using showme:incdirs if extracting didn't work.
+ if (NOT MPI_INCLUDE_PATH_WORK)
+ set(MPI_INCLUDE_PATH_WORK ${MPI_INCDIRS})
+ separate_arguments(MPI_INCLUDE_PATH_WORK)
+ endif()
+
+ # If all else fails, just search for mpi.h in the normal include paths.
+ if (NOT MPI_INCLUDE_PATH_WORK)
+ set(MPI_HEADER_PATH "MPI_HEADER_PATH-NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
+ find_path(MPI_HEADER_PATH mpi.h
+ HINTS ${_MPI_BASE_DIR} ${_MPI_PREFIX_PATH}
+ PATH_SUFFIXES include)
+ set(MPI_INCLUDE_PATH_WORK ${MPI_HEADER_PATH})
+ endif()
+
+ # Extract linker paths from the link command line
+ string(REGEX MATCHALL "(^| |-Wl,)-L([^\" ]+|\"[^\"]+\")" MPI_ALL_LINK_PATHS "${MPI_LINK_CMDLINE}")
+ set(MPI_LINK_PATH)
+ foreach(LPATH ${MPI_ALL_LINK_PATHS})
+ string(REGEX REPLACE "^(| |-Wl,)-L" "" LPATH ${LPATH})
+ string(REPLACE "//" "/" LPATH ${LPATH})
+ list(APPEND MPI_LINK_PATH ${LPATH})
+ endforeach()
+
+ # try using showme:libdirs if extracting didn't work.
+ if (NOT MPI_LINK_PATH)
+ set(MPI_LINK_PATH ${MPI_LIBDIRS})
+ separate_arguments(MPI_LINK_PATH)
+ endif()
+
+ # Extract linker flags from the link command line
+ string(REGEX MATCHALL "(^| )-Wl,([^\" ]+|\"[^\"]+\")" MPI_ALL_LINK_FLAGS "${MPI_LINK_CMDLINE}")
+ set(MPI_LINK_FLAGS_WORK)
+ foreach(FLAG ${MPI_ALL_LINK_FLAGS})
+ if (MPI_LINK_FLAGS_WORK)
+ set(MPI_LINK_FLAGS_WORK "${MPI_LINK_FLAGS_WORK} ${FLAG}")
+ else()
+ set(MPI_LINK_FLAGS_WORK ${FLAG})
+ endif()
+ endforeach()
+
+ # Extract the set of libraries to link against from the link command
+ # line
+ string(REGEX MATCHALL "(^| )-l([^\" ]+|\"[^\"]+\")" MPI_LIBNAMES "${MPI_LINK_CMDLINE}")
+
+ # add the compiler implicit directories because some compilers
+ # such as the intel compiler have libraries that show up
+ # in the showme list that can only be found in the implicit
+ # link directories of the compiler.
+ if (DEFINED CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES)
+ set(MPI_LINK_PATH
+ "${MPI_LINK_PATH};${CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES}")
+ endif ()
+
+ # Determine full path names for all of the libraries that one needs
+ # to link against in an MPI program
+ foreach(LIB ${MPI_LIBNAMES})
+ string(REGEX REPLACE "^ ?-l" "" LIB ${LIB})
+ # MPI_LIB is cached by find_library, but we don't want that. Clear it first.
+ set(MPI_LIB "MPI_LIB-NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
+ find_library(MPI_LIB NAMES ${LIB} HINTS ${MPI_LINK_PATH})
+
+ if (MPI_LIB)
+ list(APPEND MPI_LIBRARIES_WORK ${MPI_LIB})
+ elseif (NOT MPI_FIND_QUIETLY)
+ message(WARNING "Unable to find MPI library ${LIB}")
+ endif()
+ endforeach()
+
+ # Sanity check MPI_LIBRARIES to make sure there are enough libraries
+ list(LENGTH MPI_LIBRARIES_WORK MPI_NUMLIBS)
+ list(LENGTH MPI_LIBNAMES MPI_NUMLIBS_EXPECTED)
+ if (NOT MPI_NUMLIBS EQUAL MPI_NUMLIBS_EXPECTED)
+ set(MPI_LIBRARIES_WORK "MPI_${lang}_LIBRARIES-NOTFOUND")
+ endif()
+ endif()
+
+ elseif(try_libs)
+ # If we didn't have an MPI compiler script to interrogate, attempt to find everything
+ # with plain old find functions. This is nasty because MPI implementations have LOTS of
+ # different library names, so this section isn't going to be very generic. We need to
+ # make sure it works for MS MPI, though, since there are no compiler wrappers for that.
+ find_path(MPI_HEADER_PATH mpi.h
+ HINTS ${_MPI_BASE_DIR} ${_MPI_PREFIX_PATH}
+ PATH_SUFFIXES include Inc)
+ set(MPI_INCLUDE_PATH_WORK ${MPI_HEADER_PATH})
+
+ # Decide between 32-bit and 64-bit libraries for Microsoft's MPI
+ if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ set(MS_MPI_ARCH_DIR amd64)
+ else()
+ set(MS_MPI_ARCH_DIR i386)
+ endif()
+
+ set(MPI_LIB "MPI_LIB-NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
+ find_library(MPI_LIB
+ NAMES mpi mpich mpich2 msmpi
+ HINTS ${_MPI_BASE_DIR} ${_MPI_PREFIX_PATH}
+ PATH_SUFFIXES lib lib/${MS_MPI_ARCH_DIR} Lib Lib/${MS_MPI_ARCH_DIR})
+ set(MPI_LIBRARIES_WORK ${MPI_LIB})
+
+ # Right now, we only know about the extra libs for C++.
+ # We could add Fortran here (as there is usually libfmpich, etc.), but
+ # this really only has to work with MS MPI on Windows.
+ # Assume that other MPI's are covered by the compiler wrappers.
+ if (${lang} STREQUAL CXX)
+ set(MPI_LIB "MPI_LIB-NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
+ find_library(MPI_LIB
+ NAMES mpi++ mpicxx cxx mpi_cxx
+ HINTS ${_MPI_BASE_DIR} ${_MPI_PREFIX_PATH}
+ PATH_SUFFIXES lib)
+ if (MPI_LIBRARIES_WORK AND MPI_LIB)
+ list(APPEND MPI_LIBRARIES_WORK ${MPI_LIB})
+ endif()
+ endif()
+
+ if (NOT MPI_LIBRARIES_WORK)
+ set(MPI_LIBRARIES_WORK "MPI_${lang}_LIBRARIES-NOTFOUND")
+ endif()
+ endif()
+
+ # If we found MPI, set up all of the appropriate cache entries
+ set(MPI_${lang}_COMPILE_FLAGS ${MPI_COMPILE_FLAGS_WORK} CACHE STRING "MPI ${lang} compilation flags" FORCE)
+ set(MPI_${lang}_INCLUDE_PATH ${MPI_INCLUDE_PATH_WORK} CACHE STRING "MPI ${lang} include path" FORCE)
+ set(MPI_${lang}_LINK_FLAGS ${MPI_LINK_FLAGS_WORK} CACHE STRING "MPI ${lang} linking flags" FORCE)
+ set(MPI_${lang}_LIBRARIES ${MPI_LIBRARIES_WORK} CACHE STRING "MPI ${lang} libraries to link against" FORCE)
+ mark_as_advanced(MPI_${lang}_COMPILE_FLAGS MPI_${lang}_INCLUDE_PATH MPI_${lang}_LINK_FLAGS MPI_${lang}_LIBRARIES)
+
+ # clear out our temporary lib/header detectionv variable here.
+ set(MPI_LIB "MPI_LIB-NOTFOUND" CACHE INTERNAL "Scratch variable for MPI lib detection" FORCE)
+ set(MPI_HEADER_PATH "MPI_HEADER_PATH-NOTFOUND" CACHE INTERNAL "Scratch variable for MPI header detection" FORCE)
+ endif()
+
+ # finally set a found variable for each MPI language
+ if (MPI_${lang}_INCLUDE_PATH AND MPI_${lang}_LIBRARIES)
+ set(MPI_${lang}_FOUND TRUE PARENT_SCOPE)
+ else()
+ set(MPI_${lang}_FOUND FALSE PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+# This function attempts to compile with the regular compiler, to see if MPI programs
+# work with it. This is a last ditch attempt after we've tried interrogating mpicc and
+# friends, and after we've tried to find generic libraries. Works on machines like
+# Cray XE6, where the modules environment changes what MPI version cc, CC, and ftn use.
+function(try_regular_compiler lang success)
+ set(scratch_directory ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY})
+ if (${lang} STREQUAL Fortran)
+ set(test_file ${scratch_directory}/cmake_mpi_test.f90)
+ file(WRITE ${test_file}
+ "program hello\n"
+ "include 'mpif.h'\n"
+ "integer ierror\n"
+ "call MPI_INIT(ierror)\n"
+ "call MPI_FINALIZE(ierror)\n"
+ "end\n")
+ else()
+ if (${lang} STREQUAL CXX)
+ set(test_file ${scratch_directory}/cmake_mpi_test.cpp)
+ else()
+ set(test_file ${scratch_directory}/cmake_mpi_test.c)
+ endif()
+ file(WRITE ${test_file}
+ "#include <mpi.h>\n"
+ "int main(int argc, char **argv) {\n"
+ " MPI_Init(&argc, &argv);\n"
+ " MPI_Finalize();\n"
+ "}\n")
+ endif()
+ try_compile(compiler_has_mpi ${scratch_directory} ${test_file})
+ if (compiler_has_mpi)
+ set(MPI_${lang}_NO_INTERROGATE ${CMAKE_${lang}_COMPILER} CACHE STRING "Whether to interrogate MPI ${lang} compiler" FORCE)
+ set(MPI_${lang}_COMPILER ${CMAKE_${lang}_COMPILER} CACHE STRING "MPI ${lang} compiler" FORCE)
+ set(MPI_${lang}_COMPILE_FLAGS "" CACHE STRING "MPI ${lang} compilation flags" FORCE)
+ set(MPI_${lang}_INCLUDE_PATH "" CACHE STRING "MPI ${lang} include path" FORCE)
+ set(MPI_${lang}_LINK_FLAGS "" CACHE STRING "MPI ${lang} linking flags" FORCE)
+ set(MPI_${lang}_LIBRARIES "" CACHE STRING "MPI ${lang} libraries to link against" FORCE)
+ endif()
+ set(${success} ${compiler_has_mpi} PARENT_SCOPE)
+ unset(compiler_has_mpi CACHE)
+endfunction()
+
+# End definitions, commence real work here.
+
+# Most mpi distros have some form of mpiexec which gives us something we can reliably look for.
+find_program(MPIEXEC
+ NAMES ${_MPI_EXEC_NAMES}
+ HINTS ${MPI_HOME} $ENV{MPI_HOME}
+ PATHS ${_MPI_PREFIX_PATH}
+ PATH_SUFFIXES bin
+ DOC "Executable for running MPI programs.")
+
+# call get_filename_component twice to remove mpiexec and the directory it exists in (typically bin).
+# This gives us a fairly reliable base directory to search for /bin /lib and /include from.
+get_filename_component(_MPI_BASE_DIR "${MPIEXEC}" PATH)
+get_filename_component(_MPI_BASE_DIR "${_MPI_BASE_DIR}" PATH)
+
+set(MPIEXEC_NUMPROC_FLAG "-np" CACHE STRING "Flag used by MPI to specify the number of processes for MPIEXEC; the next option will be the number of processes.")
+set(MPIEXEC_PREFLAGS "" CACHE STRING "These flags will be directly before the executable that is being run by MPIEXEC.")
+set(MPIEXEC_POSTFLAGS "" CACHE STRING "These flags will come after all flags given to MPIEXEC.")
+set(MPIEXEC_MAX_NUMPROCS "2" CACHE STRING "Maximum number of processors available to run MPI applications.")
+mark_as_advanced(MPIEXEC MPIEXEC_NUMPROC_FLAG MPIEXEC_PREFLAGS MPIEXEC_POSTFLAGS MPIEXEC_MAX_NUMPROCS)
+
+
+#=============================================================================
+# Backward compatibility input hacks. Propagate the FindMPI hints to C and
+# CXX if the respective new versions are not defined. Translate the old
+# MPI_LIBRARY and MPI_EXTRA_LIBRARY to respective MPI_${lang}_LIBRARIES.
+#
+# Once we find the new variables, we translate them back into their old
+# equivalents below.
+foreach (lang C CXX)
+ # Old input variables.
+ set(_MPI_OLD_INPUT_VARS COMPILER COMPILE_FLAGS INCLUDE_PATH LINK_FLAGS)
+
+ # Set new vars based on their old equivalents, if the new versions are not already set.
+ foreach (var ${_MPI_OLD_INPUT_VARS})
+ if (NOT MPI_${lang}_${var} AND MPI_${var})
+ set(MPI_${lang}_${var} "${MPI_${var}}")
+ endif()
+ endforeach()
+
+ # Special handling for MPI_LIBRARY and MPI_EXTRA_LIBRARY, which we nixed in the
+ # new FindMPI. These need to be merged into MPI_<lang>_LIBRARIES
+ if (NOT MPI_${lang}_LIBRARIES AND (MPI_LIBRARY OR MPI_EXTRA_LIBRARY))
+ set(MPI_${lang}_LIBRARIES ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY})
+ endif()
+endforeach()
+#=============================================================================
+
+
+# This loop finds the compilers and sends them off for interrogation.
+foreach (lang C CXX Fortran)
+ if (CMAKE_${lang}_COMPILER_WORKS)
+ # If the user supplies a compiler *name* instead of an absolute path, assume that we need to find THAT compiler.
+ if (MPI_${lang}_COMPILER)
+ is_file_executable(MPI_${lang}_COMPILER MPI_COMPILER_IS_EXECUTABLE)
+ if (NOT MPI_COMPILER_IS_EXECUTABLE)
+ # Get rid of our default list of names and just search for the name the user wants.
+ set(_MPI_${lang}_COMPILER_NAMES ${MPI_${lang}_COMPILER})
+ set(MPI_${lang}_COMPILER "MPI_${lang}_COMPILER-NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
+ # If the user specifies a compiler, we don't want to try to search libraries either.
+ set(try_libs FALSE)
+ endif()
+ else()
+ set(try_libs TRUE)
+ endif()
+
+ find_program(MPI_${lang}_COMPILER
+ NAMES ${_MPI_${lang}_COMPILER_NAMES}
+ HINTS ${_MPI_BASE_DIR}/bin
+ PATHS ${_MPI_PREFIX_PATH}
+ )
+ interrogate_mpi_compiler(${lang} ${try_libs})
+ mark_as_advanced(MPI_${lang}_COMPILER)
+
+ # last ditch try -- if nothing works so far, just try running the regular compiler and
+ # see if we can create an MPI executable.
+ set(regular_compiler_worked 0)
+ if (NOT MPI_${lang}_LIBRARIES OR NOT MPI_${lang}_INCLUDE_PATH)
+ try_regular_compiler(${lang} regular_compiler_worked)
+ endif()
+
+ set(MPI_${lang}_FIND_QUIETLY ${MPI_FIND_QUIETLY})
+ set(MPI_${lang}_FIND_REQUIRED ${MPI_FIND_REQUIRED})
+ set(MPI_${lang}_FIND_VERSION ${MPI_FIND_VERSION})
+ set(MPI_${lang}_FIND_VERSION_EXACT ${MPI_FIND_VERSION_EXACT})
+
+ if (regular_compiler_worked)
+ find_package_handle_standard_args(MPI_${lang} DEFAULT_MSG MPI_${lang}_COMPILER)
+ else()
+ find_package_handle_standard_args(MPI_${lang} DEFAULT_MSG MPI_${lang}_LIBRARIES MPI_${lang}_INCLUDE_PATH)
+ endif()
+ endif()
+endforeach()
+
+
+#=============================================================================
+# More backward compatibility stuff
+#
+# Bare MPI sans ${lang} vars are set to CXX then C, depending on what was found.
+# This mimics the behavior of the old language-oblivious FindMPI.
+set(_MPI_OLD_VARS FOUND COMPILER INCLUDE_PATH COMPILE_FLAGS LINK_FLAGS LIBRARIES)
+if (MPI_CXX_FOUND)
+ foreach (var ${_MPI_OLD_VARS})
+ set(MPI_${var} ${MPI_CXX_${var}})
+ endforeach()
+elseif (MPI_C_FOUND)
+ foreach (var ${_MPI_OLD_VARS})
+ set(MPI_${var} ${MPI_C_${var}})
+ endforeach()
+else()
+ # Note that we might still have found Fortran, but you'll need to use MPI_Fortran_FOUND
+ set(MPI_FOUND FALSE)
+endif()
+
+# Chop MPI_LIBRARIES into the old-style MPI_LIBRARY and MPI_EXTRA_LIBRARY, and set them in cache.
+if (MPI_LIBRARIES)
+ list(GET MPI_LIBRARIES 0 MPI_LIBRARY_WORK)
+ set(MPI_LIBRARY ${MPI_LIBRARY_WORK} CACHE FILEPATH "MPI library to link against" FORCE)
+else()
+ set(MPI_LIBRARY "MPI_LIBRARY-NOTFOUND" CACHE FILEPATH "MPI library to link against" FORCE)
+endif()
+
+list(LENGTH MPI_LIBRARIES MPI_NUMLIBS)
+if (MPI_NUMLIBS GREATER 1)
+ set(MPI_EXTRA_LIBRARY_WORK ${MPI_LIBRARIES})
+ list(REMOVE_AT MPI_EXTRA_LIBRARY_WORK 0)
+ set(MPI_EXTRA_LIBRARY ${MPI_EXTRA_LIBRARY_WORK} CACHE STRING "Extra MPI libraries to link against" FORCE)
+else()
+ set(MPI_EXTRA_LIBRARY "MPI_EXTRA_LIBRARY-NOTFOUND" CACHE STRING "Extra MPI libraries to link against" FORCE)
+endif()
+#=============================================================================
+
+# unset these vars to cleanup namespace
+unset(_MPI_OLD_VARS)
+unset(_MPI_PREFIX_PATH)
+unset(_MPI_BASE_DIR)
+foreach (lang C CXX Fortran)
+ unset(_MPI_${lang}_COMPILER_NAMES)
+endforeach()
diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake
new file mode 100644
index 0000000000..474556e720
--- /dev/null
+++ b/Modules/FindMatlab.cmake
@@ -0,0 +1,128 @@
+#.rst:
+# FindMatlab
+# ----------
+#
+# this module looks for Matlab
+#
+# Defines:
+#
+# ::
+#
+# MATLAB_INCLUDE_DIR: include path for mex.h, engine.h
+# MATLAB_LIBRARIES: required libraries: libmex, etc
+# MATLAB_MEX_LIBRARY: path to libmex.lib
+# MATLAB_MX_LIBRARY: path to libmx.lib
+# MATLAB_ENG_LIBRARY: path to libeng.lib
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+set(MATLAB_FOUND 0)
+if(WIN32)
+ if(${CMAKE_GENERATOR} MATCHES "Visual Studio 6")
+ set(MATLAB_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/lib/win32/microsoft/msvc60")
+ else()
+ if(${CMAKE_GENERATOR} MATCHES "Visual Studio 7")
+ # Assume people are generally using 7.1,
+ # if using 7.0 need to link to: ../extern/lib/win32/microsoft/msvc70
+ set(MATLAB_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/lib/win32/microsoft/msvc71")
+ else()
+ if(${CMAKE_GENERATOR} MATCHES "Borland")
+ # Same here, there are also: bcc50 and bcc51 directories
+ set(MATLAB_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/lib/win32/microsoft/bcc54")
+ else()
+ if(MATLAB_FIND_REQUIRED)
+ message(FATAL_ERROR "Generator not compatible: ${CMAKE_GENERATOR}")
+ endif()
+ endif()
+ endif()
+ endif()
+ find_library(MATLAB_MEX_LIBRARY
+ libmex
+ ${MATLAB_ROOT}
+ )
+ find_library(MATLAB_MX_LIBRARY
+ libmx
+ ${MATLAB_ROOT}
+ )
+ find_library(MATLAB_ENG_LIBRARY
+ libeng
+ ${MATLAB_ROOT}
+ )
+
+ find_path(MATLAB_INCLUDE_DIR
+ "mex.h"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/include"
+ )
+else()
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ # Regular x86
+ set(MATLAB_ROOT
+ /usr/local/matlab-7sp1/bin/glnx86/
+ /opt/matlab-7sp1/bin/glnx86/
+ $ENV{HOME}/matlab-7sp1/bin/glnx86/
+ $ENV{HOME}/redhat-matlab/bin/glnx86/
+ )
+ else()
+ # AMD64:
+ set(MATLAB_ROOT
+ /usr/local/matlab-7sp1/bin/glnxa64/
+ /opt/matlab-7sp1/bin/glnxa64/
+ $ENV{HOME}/matlab7_64/bin/glnxa64/
+ $ENV{HOME}/matlab-7sp1/bin/glnxa64/
+ $ENV{HOME}/redhat-matlab/bin/glnxa64/
+ )
+ endif()
+ find_library(MATLAB_MEX_LIBRARY
+ mex
+ ${MATLAB_ROOT}
+ )
+ find_library(MATLAB_MX_LIBRARY
+ mx
+ ${MATLAB_ROOT}
+ )
+ find_library(MATLAB_ENG_LIBRARY
+ eng
+ ${MATLAB_ROOT}
+ )
+ find_path(MATLAB_INCLUDE_DIR
+ "mex.h"
+ "/usr/local/matlab-7sp1/extern/include/"
+ "/opt/matlab-7sp1/extern/include/"
+ "$ENV{HOME}/matlab-7sp1/extern/include/"
+ "$ENV{HOME}/redhat-matlab/extern/include/"
+ )
+
+endif()
+
+# This is common to UNIX and Win32:
+set(MATLAB_LIBRARIES
+ ${MATLAB_MEX_LIBRARY}
+ ${MATLAB_MX_LIBRARY}
+ ${MATLAB_ENG_LIBRARY}
+)
+
+if(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES)
+ set(MATLAB_FOUND 1)
+endif()
+
+mark_as_advanced(
+ MATLAB_LIBRARIES
+ MATLAB_MEX_LIBRARY
+ MATLAB_MX_LIBRARY
+ MATLAB_ENG_LIBRARY
+ MATLAB_INCLUDE_DIR
+ MATLAB_FOUND
+ MATLAB_ROOT
+)
+
diff --git a/Modules/FindMotif.cmake b/Modules/FindMotif.cmake
new file mode 100644
index 0000000000..a08ece4444
--- /dev/null
+++ b/Modules/FindMotif.cmake
@@ -0,0 +1,52 @@
+#.rst:
+# FindMotif
+# ---------
+#
+# Try to find Motif (or lesstif)
+#
+# Once done this will define:
+#
+# ::
+#
+# MOTIF_FOUND - system has MOTIF
+# MOTIF_INCLUDE_DIR - include paths to use Motif
+# MOTIF_LIBRARIES - Link these to use Motif
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+set(MOTIF_FOUND 0)
+
+if(UNIX)
+ find_path(MOTIF_INCLUDE_DIR
+ Xm/Xm.h
+ /usr/openwin/include
+ )
+
+ find_library(MOTIF_LIBRARIES
+ Xm
+ /usr/openwin/lib
+ )
+
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set MOTIF_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Motif DEFAULT_MSG MOTIF_LIBRARIES MOTIF_INCLUDE_DIR)
+
+
+mark_as_advanced(
+ MOTIF_INCLUDE_DIR
+ MOTIF_LIBRARIES
+)
diff --git a/Modules/FindOpenAL.cmake b/Modules/FindOpenAL.cmake
new file mode 100644
index 0000000000..8150ff291d
--- /dev/null
+++ b/Modules/FindOpenAL.cmake
@@ -0,0 +1,103 @@
+#.rst:
+# FindOpenAL
+# ----------
+#
+#
+#
+# Locate OpenAL This module defines OPENAL_LIBRARY OPENAL_FOUND, if
+# false, do not try to link to OpenAL OPENAL_INCLUDE_DIR, where to find
+# the headers
+#
+# $OPENALDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OPENALDIR used in building OpenAL.
+#
+# Created by Eric Wing. This was influenced by the FindSDL.cmake
+# module.
+
+#=============================================================================
+# Copyright 2005-2009 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 makes the presumption that you are include al.h like
+# #include "al.h"
+# and not
+# #include <AL/al.h>
+# The reason for this is that the latter is not entirely portable.
+# Windows/Creative Labs does not by default put their headers in AL/ and
+# OS X uses the convention <OpenAL/al.h>.
+#
+# For Windows, Creative Labs seems to have added a registry key for their
+# OpenAL 1.1 installer. I have added that key to the list of search paths,
+# however, the key looks like it could be a little fragile depending on
+# if they decide to change the 1.00.0000 number for bug fix releases.
+# Also, they seem to have laid down groundwork for multiple library platforms
+# which puts the library in an extra subdirectory. Currently there is only
+# Win32 and I have hardcoded that here. This may need to be adjusted as
+# platforms are introduced.
+# The OpenAL 1.0 installer doesn't seem to have a useful key I can use.
+# I do not know if the Nvidia OpenAL SDK has a registry key.
+#
+# For OS X, remember that OpenAL was added by Apple in 10.4 (Tiger).
+# To support the framework, I originally wrote special framework detection
+# code in this module which I have now removed with CMake's introduction
+# of native support for frameworks.
+# In addition, OpenAL is open source, and it is possible to compile on Panther.
+# Furthermore, due to bugs in the initial OpenAL release, and the
+# transition to OpenAL 1.1, it is common to need to override the built-in
+# framework.
+# Per my request, CMake should search for frameworks first in
+# the following order:
+# ~/Library/Frameworks/OpenAL.framework/Headers
+# /Library/Frameworks/OpenAL.framework/Headers
+# /System/Library/Frameworks/OpenAL.framework/Headers
+#
+# On OS X, this will prefer the Framework version (if found) over others.
+# People will have to manually change the cache values of
+# OPENAL_LIBRARY to override this selection or set the CMake environment
+# CMAKE_INCLUDE_PATH to modify the search paths.
+
+find_path(OPENAL_INCLUDE_DIR al.h
+ HINTS
+ ENV OPENALDIR
+ PATH_SUFFIXES include/AL include/OpenAL include
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
+)
+
+find_library(OPENAL_LIBRARY
+ NAMES OpenAL al openal OpenAL32
+ HINTS
+ ENV OPENALDIR
+ PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
+)
+
+
+# handle the QUIETLY and REQUIRED arguments and set OPENAL_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenAL DEFAULT_MSG OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
+
+mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
diff --git a/Modules/FindOpenCL.cmake b/Modules/FindOpenCL.cmake
new file mode 100644
index 0000000000..4d3ed842c3
--- /dev/null
+++ b/Modules/FindOpenCL.cmake
@@ -0,0 +1,136 @@
+#.rst:
+# FindOpenCL
+# ----------
+#
+# Try to find OpenCL
+#
+# Once done this will define::
+#
+# OpenCL_FOUND - True if OpenCL was found
+# OpenCL_INCLUDE_DIRS - include directories for OpenCL
+# OpenCL_LIBRARIES - link against this library to use OpenCL
+# OpenCL_VERSION_STRING - Highest supported OpenCL version (eg. 1.2)
+# OpenCL_VERSION_MAJOR - The major version of the OpenCL implementation
+# OpenCL_VERSION_MINOR - The minor version of the OpenCL implementation
+#
+# The module will also define two cache variables::
+#
+# OpenCL_INCLUDE_DIR - the OpenCL include directory
+# OpenCL_LIBRARY - the path to the OpenCL library
+#
+
+#=============================================================================
+# Copyright 2014 Matthaeus G. Chajdas
+#
+# 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(_FIND_OPENCL_VERSION)
+ include(CheckSymbolExists)
+ include(CMakePushCheckState)
+ set(CMAKE_REQUIRED_QUIET ${OpenCL_FIND_QUIETLY})
+
+ CMAKE_PUSH_CHECK_STATE()
+ foreach(VERSION "2_0" "1_2" "1_1" "1_0")
+ set(CMAKE_REQUIRED_INCLUDES "${OpenCL_INCLUDE_DIR}")
+
+ if(APPLE)
+ CHECK_SYMBOL_EXISTS(
+ CL_VERSION_${VERSION}
+ "${OpenCL_INCLUDE_DIR}/OpenCL/cl.h"
+ OPENCL_VERSION_${VERSION})
+ else()
+ CHECK_SYMBOL_EXISTS(
+ CL_VERSION_${VERSION}
+ "${OpenCL_INCLUDE_DIR}/CL/cl.h"
+ OPENCL_VERSION_${VERSION})
+ endif()
+
+ if(OPENCL_VERSION_${VERSION})
+ string(REPLACE "_" "." VERSION "${VERSION}")
+ set(OpenCL_VERSION_STRING ${VERSION} PARENT_SCOPE)
+ string(REGEX MATCHALL "[0-9]+" version_components "${VERSION}")
+ list(GET version_components 0 major_version)
+ list(GET version_components 1 minor_version)
+ set(OpenCL_VERSION_MAJOR ${major_version} PARENT_SCOPE)
+ set(OpenCL_VERSION_MINOR ${minor_version} PARENT_SCOPE)
+ break()
+ endif()
+ endforeach()
+ CMAKE_POP_CHECK_STATE()
+endfunction()
+
+find_path(OpenCL_INCLUDE_DIR
+ NAMES
+ CL/cl.h OpenCL/cl.h
+ PATHS
+ ENV "PROGRAMFILES(X86)"
+ ENV AMDAPPSDKROOT
+ ENV INTELOCLSDKROOT
+ ENV NVSDKCOMPUTE_ROOT
+ ENV CUDA_PATH
+ ENV ATISTREAMSDKROOT
+ PATH_SUFFIXES
+ include
+ OpenCL/common/inc
+ "AMD APP/include")
+
+_FIND_OPENCL_VERSION()
+
+if(WIN32)
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ find_library(OpenCL_LIBRARY
+ NAMES OpenCL
+ PATHS
+ ENV "PROGRAMFILES(X86)"
+ ENV AMDAPPSDKROOT
+ ENV INTELOCLSDKROOT
+ ENV CUDA_PATH
+ ENV NVSDKCOMPUTE_ROOT
+ ENV ATISTREAMSDKROOT
+ PATH_SUFFIXES
+ "AMD APP/lib/x86"
+ lib/x86
+ lib/Win32
+ OpenCL/common/lib/Win32)
+ elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ find_library(OpenCL_LIBRARY
+ NAMES OpenCL
+ PATHS
+ ENV "PROGRAMFILES(X86)"
+ ENV AMDAPPSDKROOT
+ ENV INTELOCLSDKROOT
+ ENV CUDA_PATH
+ ENV NVSDKCOMPUTE_ROOT
+ ENV ATISTREAMSDKROOT
+ PATH_SUFFIXES
+ "AMD APP/lib/x86_64"
+ lib/x86_64
+ lib/x64
+ OpenCL/common/lib/x64)
+ endif()
+else()
+ find_library(OpenCL_LIBRARY
+ NAMES OpenCL)
+endif()
+
+set(OpenCL_LIBRARIES ${OpenCL_LIBRARY})
+set(OpenCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIR})
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(
+ OpenCL
+ FOUND_VAR OpenCL_FOUND
+ REQUIRED_VARS OpenCL_LIBRARY OpenCL_INCLUDE_DIR
+ VERSION_VAR OpenCL_VERSION_STRING)
+
+mark_as_advanced(
+ OpenCL_INCLUDE_DIR
+ OpenCL_LIBRARY)
diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake
new file mode 100644
index 0000000000..2b3bd1413e
--- /dev/null
+++ b/Modules/FindOpenGL.cmake
@@ -0,0 +1,229 @@
+#.rst:
+# FindOpenGL
+# ----------
+#
+# FindModule for OpenGL and GLU.
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the :prop_tgt:`IMPORTED` targets:
+#
+# ``OpenGL::GL``
+# Defined if the system has OpenGL.
+# ``OpenGL::GLU``
+# Defined if the system has GLU.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module sets the following variables:
+#
+# ``OPENGL_FOUND``
+# True, if the system has OpenGL.
+# ``OPENGL_XMESA_FOUND``
+# True, if the system has XMESA.
+# ``OPENGL_GLU_FOUND``
+# True, if the system has GLU.
+# ``OPENGL_INCLUDE_DIR``
+# Path to the OpenGL include directory.
+# ``OPENGL_LIBRARIES``
+# Paths to the OpenGL and GLU libraries.
+#
+# If you want to use just GL you can use these values:
+#
+# ``OPENGL_gl_LIBRARY``
+# Path to the OpenGL library.
+# ``OPENGL_glu_LIBRARY``
+# Path to the GLU library.
+#
+# OSX Specific
+# ^^^^^^^^^^^^
+#
+# On OSX default to using the framework version of OpenGL. People will
+# have to change the cache values of OPENGL_glu_LIBRARY and
+# OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX.
+
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
+
+if (CYGWIN)
+
+ find_path(OPENGL_INCLUDE_DIR GL/gl.h )
+ list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
+
+ find_library(OPENGL_gl_LIBRARY opengl32 )
+
+ find_library(OPENGL_glu_LIBRARY glu32 )
+
+elseif (WIN32)
+
+ if(BORLAND)
+ set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
+ set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
+ else()
+ set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
+ set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
+ endif()
+
+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")
+ list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
+
+else()
+ if (CMAKE_SYSTEM_NAME MATCHES "HP-UX")
+ # Handle HP-UX cases where we only want to find OpenGL in either hpux64
+ # or hpux32 depending on if we're doing a 64 bit build.
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set(_OPENGL_LIB_PATH
+ /opt/graphics/OpenGL/lib/hpux32/)
+ else()
+ set(_OPENGL_LIB_PATH
+ /opt/graphics/OpenGL/lib/hpux64/
+ /opt/graphics/OpenGL/lib/pa20_64)
+ endif()
+ elseif(CMAKE_SYSTEM_NAME STREQUAL Haiku)
+ set(_OPENGL_LIB_PATH
+ /boot/develop/lib/x86)
+ set(_OPENGL_INCLUDE_PATH
+ /boot/develop/headers/os/opengl)
+ endif()
+
+ # The first line below is to make sure that the proper headers
+ # are used on a Linux machine with the NVidia drivers installed.
+ # They replace Mesa with NVidia's own library but normally do not
+ # install headers and that causes the linking to
+ # fail since the compiler finds the Mesa headers but NVidia's library.
+ # Make sure the NVIDIA directory comes BEFORE the others.
+ # - Atanas Georgiev <atanas@cs.columbia.edu>
+
+ find_path(OPENGL_INCLUDE_DIR GL/gl.h
+ /usr/share/doc/NVIDIA_GLX-1.0/include
+ /usr/openwin/share/include
+ /opt/graphics/OpenGL/include /usr/X11R6/include
+ ${_OPENGL_INCLUDE_PATH}
+ )
+ list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
+
+ find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
+ /usr/share/doc/NVIDIA_GLX-1.0/include
+ /usr/openwin/share/include
+ /opt/graphics/OpenGL/include /usr/X11R6/include
+ )
+
+ find_library(OPENGL_gl_LIBRARY
+ NAMES GL MesaGL
+ PATHS /opt/graphics/OpenGL/lib
+ /usr/openwin/lib
+ /usr/shlib /usr/X11R6/lib
+ ${_OPENGL_LIB_PATH}
+ )
+
+ unset(_OPENGL_INCLUDE_PATH)
+ unset(_OPENGL_LIB_PATH)
+
+ # On Unix OpenGL most certainly always requires X11.
+ # Feel free to tighten up these conditions if you don't
+ # think this is always true.
+
+ if (OPENGL_gl_LIBRARY)
+ if(NOT X11_FOUND)
+ include(${CMAKE_CURRENT_LIST_DIR}/FindX11.cmake)
+ endif()
+ if (X11_FOUND)
+ set (OPENGL_LIBRARIES ${X11_LIBRARIES})
+ endif ()
+ endif ()
+
+ find_library(OPENGL_glu_LIBRARY
+ NAMES GLU MesaGLU
+ PATHS ${OPENGL_gl_LIBRARY}
+ /opt/graphics/OpenGL/lib
+ /usr/openwin/lib
+ /usr/shlib /usr/X11R6/lib
+ )
+
+endif ()
+
+if(OPENGL_gl_LIBRARY)
+
+ if(OPENGL_xmesa_INCLUDE_DIR)
+ set( OPENGL_XMESA_FOUND "YES" )
+ else()
+ set( OPENGL_XMESA_FOUND "NO" )
+ endif()
+
+ 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} )
+ else()
+ set( OPENGL_GLU_FOUND "NO" )
+ endif()
+
+ # This deprecated setting is for backward compatibility with CMake1.4
+ set (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
+
+endif()
+
+# This deprecated setting is for backward compatibility with CMake1.4
+set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
+
+# handle the QUIETLY and REQUIRED arguments and set OPENGL_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS})
+unset(_OpenGL_REQUIRED_VARS)
+
+# OpenGL:: targets
+if(OPENGL_FOUND)
+ if(NOT TARGET OpenGL::GL)
+ add_library(OpenGL::GL UNKNOWN IMPORTED)
+ set_target_properties(OpenGL::GL PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}")
+ if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$")
+ set_target_properties(OpenGL::GL PROPERTIES
+ IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}/${CMAKE_MATCH_1}")
+ else()
+ set_target_properties(OpenGL::GL PROPERTIES
+ IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}")
+ endif()
+ endif()
+
+ if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU)
+ add_library(OpenGL::GLU UNKNOWN IMPORTED)
+ set_target_properties(OpenGL::GLU PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
+ INTERFACE_LINK_LIBRARIES OpenGL::GL)
+ if(OPENGL_glu_LIBRARY MATCHES "/([^/]+)\\.framework$")
+ set_target_properties(OpenGL::GLU PROPERTIES
+ IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}/${CMAKE_MATCH_1}")
+ else()
+ set_target_properties(OpenGL::GLU PROPERTIES
+ IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}")
+ endif()
+ endif()
+endif()
+
+mark_as_advanced(
+ OPENGL_INCLUDE_DIR
+ OPENGL_xmesa_INCLUDE_DIR
+ OPENGL_glu_LIBRARY
+ OPENGL_gl_LIBRARY
+)
diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake
new file mode 100644
index 0000000000..801b4f8144
--- /dev/null
+++ b/Modules/FindOpenMP.cmake
@@ -0,0 +1,239 @@
+#.rst:
+# FindOpenMP
+# ----------
+#
+# Finds OpenMP support
+#
+# This module can be used to detect OpenMP support in a compiler. If
+# the compiler supports OpenMP, the flags required to compile with
+# OpenMP support are returned in variables for the different languages.
+# The variables may be empty if the compiler does not need a special
+# flag to support OpenMP.
+#
+# The following variables are set:
+#
+# ::
+#
+# OpenMP_C_FLAGS - flags to add to the C compiler for OpenMP support
+# OpenMP_CXX_FLAGS - flags to add to the CXX compiler for OpenMP support
+# OpenMP_Fortran_FLAGS - flags to add to the Fortran compiler for OpenMP support
+# OPENMP_FOUND - true if openmp is detected
+#
+#
+#
+# Supported compilers can be found at
+# http://openmp.org/wp/openmp-compilers/
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2008-2009 André Rigland Brodtkorb <Andre.Brodtkorb@ifi.uio.no>
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
+# Copyright 2014 Nicolas Bock <nicolasbock@gmail.com>
+#
+# 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.)
+
+set(_OPENMP_REQUIRED_VARS)
+set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
+set(CMAKE_REQUIRED_QUIET ${OpenMP_FIND_QUIETLY})
+
+function(_OPENMP_FLAG_CANDIDATES LANG)
+ set(OpenMP_FLAG_CANDIDATES
+ #Empty, if compiler automatically accepts openmp
+ " "
+ #GNU
+ "-fopenmp"
+ #Microsoft Visual Studio
+ "/openmp"
+ #Intel windows
+ "-Qopenmp"
+ #PathScale, Intel
+ "-openmp"
+ #Sun
+ "-xopenmp"
+ #HP
+ "+Oopenmp"
+ #IBM XL C/c++
+ "-qsmp"
+ #Portland Group, MIPSpro
+ "-mp"
+ )
+
+ set(OMP_FLAG_GNU "-fopenmp")
+ set(OMP_FLAG_HP "+Oopenmp")
+ if(WIN32)
+ set(OMP_FLAG_Intel "-Qopenmp")
+ elseif(CMAKE_${LANG}_COMPILER_ID STREQUAL "Intel" AND
+ "${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS "15.0.0.20140528")
+ set(OMP_FLAG_Intel "-openmp")
+ else()
+ set(OMP_FLAG_Intel "-qopenmp")
+ endif()
+ set(OMP_FLAG_MIPSpro "-mp")
+ set(OMP_FLAG_MSVC "/openmp")
+ set(OMP_FLAG_PathScale "-openmp")
+ set(OMP_FLAG_PGI "-mp")
+ set(OMP_FLAG_SunPro "-xopenmp")
+ set(OMP_FLAG_XL "-qsmp")
+ set(OMP_FLAG_Cray " ")
+
+ # Move the flag that matches the compiler to the head of the list,
+ # this is faster and doesn't clutter the output that much. If that
+ # flag doesn't work we will still try all.
+ if(OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID})
+ list(REMOVE_ITEM OpenMP_FLAG_CANDIDATES "${OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID}}")
+ list(INSERT OpenMP_FLAG_CANDIDATES 0 "${OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID}}")
+ endif()
+
+ set(OpenMP_${LANG}_FLAG_CANDIDATES "${OpenMP_FLAG_CANDIDATES}" PARENT_SCOPE)
+endfunction()
+
+# sample openmp source code to test
+set(OpenMP_C_TEST_SOURCE
+"
+#include <omp.h>
+int main() {
+#ifdef _OPENMP
+ return 0;
+#else
+ breaks_on_purpose
+#endif
+}
+")
+
+# same in Fortran
+set(OpenMP_Fortran_TEST_SOURCE
+ "
+program test
+use omp_lib
+integer :: n
+n = omp_get_num_threads()
+end program test
+ "
+ )
+
+# check c compiler
+if(CMAKE_C_COMPILER_LOADED)
+ # if these are set then do not try to find them again,
+ # by avoiding any try_compiles for the flags
+ if(OpenMP_C_FLAGS)
+ unset(OpenMP_C_FLAG_CANDIDATES)
+ else()
+ _OPENMP_FLAG_CANDIDATES("C")
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckCSourceCompiles.cmake)
+ endif()
+
+ foreach(FLAG IN LISTS OpenMP_C_FLAG_CANDIDATES)
+ set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
+ set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+ unset(OpenMP_FLAG_DETECTED CACHE)
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Try OpenMP C flag = [${FLAG}]")
+ endif()
+ check_c_source_compiles("${OpenMP_C_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
+ set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
+ if(OpenMP_FLAG_DETECTED)
+ set(OpenMP_C_FLAGS_INTERNAL "${FLAG}")
+ break()
+ endif()
+ endforeach()
+
+ set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS_INTERNAL}"
+ CACHE STRING "C compiler flags for OpenMP parallization")
+
+ list(APPEND _OPENMP_REQUIRED_VARS OpenMP_C_FLAGS)
+ unset(OpenMP_C_FLAG_CANDIDATES)
+endif()
+
+# check cxx compiler
+if(CMAKE_CXX_COMPILER_LOADED)
+ # if these are set then do not try to find them again,
+ # by avoiding any try_compiles for the flags
+ if(OpenMP_CXX_FLAGS)
+ unset(OpenMP_CXX_FLAG_CANDIDATES)
+ else()
+ _OPENMP_FLAG_CANDIDATES("CXX")
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckCXXSourceCompiles.cmake)
+
+ # use the same source for CXX as C for now
+ set(OpenMP_CXX_TEST_SOURCE ${OpenMP_C_TEST_SOURCE})
+ endif()
+
+ foreach(FLAG IN LISTS OpenMP_CXX_FLAG_CANDIDATES)
+ set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
+ set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+ unset(OpenMP_FLAG_DETECTED CACHE)
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Try OpenMP CXX flag = [${FLAG}]")
+ endif()
+ check_cxx_source_compiles("${OpenMP_CXX_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
+ set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
+ if(OpenMP_FLAG_DETECTED)
+ set(OpenMP_CXX_FLAGS_INTERNAL "${FLAG}")
+ break()
+ endif()
+ endforeach()
+
+ set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS_INTERNAL}"
+ CACHE STRING "C++ compiler flags for OpenMP parallization")
+
+ list(APPEND _OPENMP_REQUIRED_VARS OpenMP_CXX_FLAGS)
+ unset(OpenMP_CXX_FLAG_CANDIDATES)
+ unset(OpenMP_CXX_TEST_SOURCE)
+endif()
+
+# check Fortran compiler
+if(CMAKE_Fortran_COMPILER_LOADED)
+ # if these are set then do not try to find them again,
+ # by avoiding any try_compiles for the flags
+ if(OpenMP_Fortran_FLAGS)
+ unset(OpenMP_Fortran_FLAG_CANDIDATES)
+ else()
+ _OPENMP_FLAG_CANDIDATES("Fortran")
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranSourceCompiles.cmake)
+ endif()
+
+ foreach(FLAG IN LISTS OpenMP_Fortran_FLAG_CANDIDATES)
+ set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
+ set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+ unset(OpenMP_FLAG_DETECTED CACHE)
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Try OpenMP Fortran flag = [${FLAG}]")
+ endif()
+ check_fortran_source_compiles("${OpenMP_Fortran_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
+ set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
+ if(OpenMP_FLAG_DETECTED)
+ set(OpenMP_Fortran_FLAGS_INTERNAL "${FLAG}")
+ break()
+ endif()
+ endforeach()
+
+ set(OpenMP_Fortran_FLAGS "${OpenMP_Fortran_FLAGS_INTERNAL}"
+ CACHE STRING "Fortran compiler flags for OpenMP parallization")
+
+ list(APPEND _OPENMP_REQUIRED_VARS OpenMP_Fortran_FLAGS)
+ unset(OpenMP_Fortran_FLAG_CANDIDATES)
+ unset(OpenMP_Fortran_TEST_SOURCE)
+endif()
+
+set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
+
+if(_OPENMP_REQUIRED_VARS)
+ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+ find_package_handle_standard_args(OpenMP
+ REQUIRED_VARS ${_OPENMP_REQUIRED_VARS})
+
+ mark_as_advanced(${_OPENMP_REQUIRED_VARS})
+
+ unset(_OPENMP_REQUIRED_VARS)
+else()
+ message(SEND_ERROR "FindOpenMP requires C or CXX language to be enabled")
+endif()
diff --git a/Modules/FindOpenSSL.cmake b/Modules/FindOpenSSL.cmake
new file mode 100644
index 0000000000..340b41740e
--- /dev/null
+++ b/Modules/FindOpenSSL.cmake
@@ -0,0 +1,334 @@
+#.rst:
+# FindOpenSSL
+# -----------
+#
+# Try to find the OpenSSL encryption library
+#
+# Once done this will define
+#
+# ::
+#
+# OPENSSL_ROOT_DIR - Set this variable to the root installation of OpenSSL
+#
+#
+#
+# Read-Only variables:
+#
+# ::
+#
+# OPENSSL_FOUND - system has the OpenSSL library
+# OPENSSL_INCLUDE_DIR - the OpenSSL include directory
+# OPENSSL_LIBRARIES - The libraries needed to use OpenSSL
+# OPENSSL_VERSION - This is set to $major.$minor.$revision$path (eg. 0.9.8s)
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
+# Copyright 2009-2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
+#
+# 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.)
+
+if (UNIX)
+ find_package(PkgConfig QUIET)
+ pkg_check_modules(_OPENSSL QUIET openssl)
+endif ()
+
+if (WIN32)
+ # http://www.slproweb.com/products/Win32OpenSSL.html
+ set(_OPENSSL_ROOT_HINTS
+ ${OPENSSL_ROOT_DIR}
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]"
+ ENV OPENSSL_ROOT_DIR
+ )
+ file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
+ set(_OPENSSL_ROOT_PATHS
+ "${_programfiles}/OpenSSL"
+ "${_programfiles}/OpenSSL-Win32"
+ "${_programfiles}/OpenSSL-Win64"
+ "C:/OpenSSL/"
+ "C:/OpenSSL-Win32/"
+ "C:/OpenSSL-Win64/"
+ )
+ unset(_programfiles)
+else ()
+ set(_OPENSSL_ROOT_HINTS
+ ${OPENSSL_ROOT_DIR}
+ ENV OPENSSL_ROOT_DIR
+ )
+endif ()
+
+set(_OPENSSL_ROOT_HINTS_AND_PATHS
+ HINTS ${_OPENSSL_ROOT_HINTS}
+ PATHS ${_OPENSSL_ROOT_PATHS}
+ )
+
+find_path(OPENSSL_INCLUDE_DIR
+ NAMES
+ openssl/ssl.h
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ HINTS
+ ${_OPENSSL_INCLUDEDIR}
+ PATH_SUFFIXES
+ include
+)
+
+if(WIN32 AND NOT CYGWIN)
+ if(MSVC)
+ # /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
+ # 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
+ # * MT for static-release
+ # * MTd for static-debug
+
+ # Implementation details:
+ # We are using the libraries located in the VC subdir instead of the parent directory eventhough :
+ # libeay32MD.lib is identical to ../libeay32.lib, and
+ # ssleay32MD.lib is identical to ../ssleay32.lib
+ find_library(LIB_EAY_DEBUG
+ NAMES
+ libeay32MDd
+ libeay32d
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES
+ "lib"
+ "VC"
+ "lib/VC"
+ )
+
+ find_library(LIB_EAY_RELEASE
+ NAMES
+ libeay32MD
+ libeay32
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES
+ "lib"
+ "VC"
+ "lib/VC"
+ )
+
+ find_library(SSL_EAY_DEBUG
+ NAMES
+ ssleay32MDd
+ ssleay32d
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES
+ "lib"
+ "VC"
+ "lib/VC"
+ )
+
+ find_library(SSL_EAY_RELEASE
+ NAMES
+ ssleay32MD
+ ssleay32
+ ssl
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES
+ "lib"
+ "VC"
+ "lib/VC"
+ )
+
+ set(LIB_EAY_LIBRARY_DEBUG "${LIB_EAY_DEBUG}")
+ set(LIB_EAY_LIBRARY_RELEASE "${LIB_EAY_RELEASE}")
+ set(SSL_EAY_LIBRARY_DEBUG "${SSL_EAY_DEBUG}")
+ set(SSL_EAY_LIBRARY_RELEASE "${SSL_EAY_RELEASE}")
+
+ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+ select_library_configurations(LIB_EAY)
+ select_library_configurations(SSL_EAY)
+
+ mark_as_advanced(LIB_EAY_LIBRARY_DEBUG LIB_EAY_LIBRARY_RELEASE
+ SSL_EAY_LIBRARY_DEBUG SSL_EAY_LIBRARY_RELEASE)
+ 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()
+ find_library(LIB_EAY
+ NAMES
+ ${LIB_EAY_NAMES}
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES
+ "lib"
+ "lib/MinGW"
+ )
+
+ find_library(SSL_EAY
+ NAMES
+ ${SSL_EAY_NAMES}
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES
+ "lib"
+ "lib/MinGW"
+ )
+
+ mark_as_advanced(SSL_EAY LIB_EAY)
+ set( OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} )
+ unset(LIB_EAY_NAMES)
+ unset(SSL_EAY_NAMES)
+ else()
+ # Not sure what to pick for -say- intel, let's use the toplevel ones and hope someone report issues:
+ find_library(LIB_EAY
+ NAMES
+ libeay32
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ HINTS
+ ${_OPENSSL_LIBDIR}
+ PATH_SUFFIXES
+ lib
+ )
+
+ find_library(SSL_EAY
+ NAMES
+ ssleay32
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ HINTS
+ ${_OPENSSL_LIBDIR}
+ PATH_SUFFIXES
+ lib
+ )
+
+ mark_as_advanced(SSL_EAY LIB_EAY)
+ set( OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} )
+ endif()
+else()
+
+ find_library(OPENSSL_SSL_LIBRARY
+ NAMES
+ ssl
+ ssleay32
+ ssleay32MD
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ HINTS
+ ${_OPENSSL_LIBDIR}
+ PATH_SUFFIXES
+ lib
+ )
+
+ find_library(OPENSSL_CRYPTO_LIBRARY
+ NAMES
+ crypto
+ ${_OPENSSL_ROOT_HINTS_AND_PATHS}
+ HINTS
+ ${_OPENSSL_LIBDIR}
+ PATH_SUFFIXES
+ lib
+ )
+
+ mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY)
+
+ # compat defines
+ set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY})
+ set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
+
+ set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
+
+endif()
+
+function(from_hex HEX DEC)
+ string(TOUPPER "${HEX}" HEX)
+ set(_res 0)
+ string(LENGTH "${HEX}" _strlen)
+
+ while (_strlen GREATER 0)
+ math(EXPR _res "${_res} * 16")
+ string(SUBSTRING "${HEX}" 0 1 NIBBLE)
+ string(SUBSTRING "${HEX}" 1 -1 HEX)
+ if (NIBBLE STREQUAL "A")
+ math(EXPR _res "${_res} + 10")
+ elseif (NIBBLE STREQUAL "B")
+ math(EXPR _res "${_res} + 11")
+ elseif (NIBBLE STREQUAL "C")
+ math(EXPR _res "${_res} + 12")
+ elseif (NIBBLE STREQUAL "D")
+ math(EXPR _res "${_res} + 13")
+ elseif (NIBBLE STREQUAL "E")
+ math(EXPR _res "${_res} + 14")
+ elseif (NIBBLE STREQUAL "F")
+ math(EXPR _res "${_res} + 15")
+ else()
+ math(EXPR _res "${_res} + ${NIBBLE}")
+ endif()
+
+ string(LENGTH "${HEX}" _strlen)
+ endwhile()
+
+ set(${DEC} ${_res} PARENT_SCOPE)
+endfunction()
+
+if (OPENSSL_INCLUDE_DIR)
+ if (_OPENSSL_VERSION)
+ set(OPENSSL_VERSION "${_OPENSSL_VERSION}")
+ elseif(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])+.*")
+
+ # 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.
+ # Major, minor, and fix directly translate into the version numbers shown in
+ # the string. The patch field translates to the single character suffix that
+ # indicates the bug fix state, which 00 -> nothing, 01 -> a, 02 -> b and so
+ # on.
+
+ string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$"
+ "\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}")
+ list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR)
+ list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR)
+ from_hex("${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR)
+ list(GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX)
+ from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX)
+ list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH)
+
+ if (NOT OPENSSL_VERSION_PATCH STREQUAL "00")
+ from_hex("${OPENSSL_VERSION_PATCH}" _tmp)
+ # 96 is the ASCII code of 'a' minus 1
+ math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96")
+ unset(_tmp)
+ # Once anyone knows how OpenSSL would call the patch versions beyond 'z'
+ # this should be updated to handle that, too. This has not happened yet
+ # so it is simply ignored here for now.
+ string(ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING)
+ endif ()
+
+ set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}")
+ endif ()
+endif ()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+if (OPENSSL_VERSION)
+ find_package_handle_standard_args(OpenSSL
+ REQUIRED_VARS
+ OPENSSL_LIBRARIES
+ OPENSSL_INCLUDE_DIR
+ VERSION_VAR
+ OPENSSL_VERSION
+ FAIL_MESSAGE
+ "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR"
+ )
+else ()
+ find_package_handle_standard_args(OpenSSL "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR"
+ OPENSSL_LIBRARIES
+ OPENSSL_INCLUDE_DIR
+ )
+endif ()
+
+mark_as_advanced(OPENSSL_INCLUDE_DIR OPENSSL_LIBRARIES)
diff --git a/Modules/FindOpenSceneGraph.cmake b/Modules/FindOpenSceneGraph.cmake
new file mode 100644
index 0000000000..68adff746e
--- /dev/null
+++ b/Modules/FindOpenSceneGraph.cmake
@@ -0,0 +1,240 @@
+#.rst:
+# FindOpenSceneGraph
+# ------------------
+#
+# Find OpenSceneGraph
+#
+# This module searches for the OpenSceneGraph core "osg" library as well
+# as OpenThreads, and whatever additional COMPONENTS (nodekits) that you
+# specify.
+#
+# ::
+#
+# See http://www.openscenegraph.org
+#
+#
+#
+# NOTE: To use this module effectively you must either require CMake >=
+# 2.6.3 with cmake_minimum_required(VERSION 2.6.3) or download and place
+# FindOpenThreads.cmake, Findosg_functions.cmake, Findosg.cmake, and
+# Find<etc>.cmake files into your CMAKE_MODULE_PATH.
+#
+# ==================================
+#
+# This module accepts the following variables (note mixed case)
+#
+# ::
+#
+# OpenSceneGraph_DEBUG - Enable debugging output
+#
+#
+#
+# ::
+#
+# OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
+# automatically
+#
+#
+#
+# The following environment variables are also respected for finding the
+# OSG and it's various components. CMAKE_PREFIX_PATH can also be used
+# for this (see find_library() CMake documentation).
+#
+# ::
+#
+# <MODULE>_DIR (where MODULE is of the form "OSGVOLUME" and there is a FindosgVolume.cmake file)
+# OSG_DIR
+# OSGDIR
+# OSG_ROOT
+#
+#
+#
+# [CMake 2.8.10]: The CMake variable OSG_DIR can now be used as well to
+# influence detection, instead of needing to specify an environment
+# variable.
+#
+# This module defines the following output variables:
+#
+# ::
+#
+# OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
+#
+#
+#
+# ::
+#
+# OPENSCENEGRAPH_VERSION - The version of the OSG which was found
+#
+#
+#
+# ::
+#
+# OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
+#
+#
+#
+# ::
+#
+# OPENSCENEGRAPH_LIBRARIES - The OSG libraries
+#
+#
+#
+# ================================== Example Usage:
+#
+# ::
+#
+# find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil)
+# # libOpenThreads & libosg automatically searched
+# include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
+#
+#
+#
+# ::
+#
+# add_executable(foo foo.cc)
+# target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2009-2012 Philip Lowman <philip@yhbt.com>
+#
+# 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.)
+
+#
+# Naming convention:
+# Local variables of the form _osg_foo
+# Input variables of the form OpenSceneGraph_FOO
+# Output variables of the form OPENSCENEGRAPH_FOO
+#
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+
+set(_osg_modules_to_process)
+foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS})
+ list(APPEND _osg_modules_to_process ${_osg_component})
+endforeach()
+list(APPEND _osg_modules_to_process "osg" "OpenThreads")
+list(REMOVE_DUPLICATES _osg_modules_to_process)
+
+if(OpenSceneGraph_DEBUG)
+ message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Components = ${_osg_modules_to_process}")
+endif()
+
+#
+# First we need to find and parse osg/Version
+#
+OSG_FIND_PATH(OSG osg/Version)
+if(OpenSceneGraph_MARK_AS_ADVANCED)
+ OSG_MARK_AS_ADVANCED(OSG)
+endif()
+
+# Try to ascertain the version...
+if(OSG_INCLUDE_DIR)
+ if(OpenSceneGraph_DEBUG)
+ message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
+ endif()
+
+ set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version")
+ if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}")
+ set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version")
+ endif()
+
+ if(EXISTS "${_osg_Version_file}")
+ file(STRINGS "${_osg_Version_file}" _osg_Version_contents
+ REGEX "#define (OSG_VERSION_[A-Z]+|OPENSCENEGRAPH_[A-Z]+_VERSION)[ \t]+[0-9]+")
+ else()
+ set(_osg_Version_contents "unknown")
+ endif()
+
+ string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*"
+ _osg_old_defines "${_osg_Version_contents}")
+ string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*"
+ _osg_new_defines "${_osg_Version_contents}")
+ if(_osg_old_defines)
+ string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
+ "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
+ string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
+ "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
+ string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
+ "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
+ elseif(_osg_new_defines)
+ string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
+ "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
+ string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
+ "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
+ string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
+ "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
+ else()
+ message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Failed to parse version number, please report this as a bug")
+ endif()
+ unset(_osg_Version_contents)
+
+ set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
+ CACHE INTERNAL "The version of OSG which was detected")
+ if(OpenSceneGraph_DEBUG)
+ message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Detected version ${OPENSCENEGRAPH_VERSION}")
+ endif()
+endif()
+
+set(_osg_quiet)
+if(OpenSceneGraph_FIND_QUIETLY)
+ set(_osg_quiet "QUIET")
+endif()
+#
+# Here we call find_package() on all of the components
+#
+foreach(_osg_module ${_osg_modules_to_process})
+ if(OpenSceneGraph_DEBUG)
+ message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
+ endif()
+ find_package(${_osg_module} ${_osg_quiet})
+
+ string(TOUPPER ${_osg_module} _osg_module_UC)
+ # append to list if module was found OR is required
+ if( ${_osg_module_UC}_FOUND OR OpenSceneGraph_FIND_REQUIRED )
+ list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
+ list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
+ endif()
+
+ if(OpenSceneGraph_MARK_AS_ADVANCED)
+ OSG_MARK_AS_ADVANCED(${_osg_module})
+ endif()
+endforeach()
+
+if(OPENSCENEGRAPH_INCLUDE_DIR)
+ list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
+endif()
+
+#
+# Check each module to see if it's found
+#
+set(_osg_component_founds)
+if(OpenSceneGraph_FIND_REQUIRED)
+ foreach(_osg_module ${_osg_modules_to_process})
+ string(TOUPPER ${_osg_module} _osg_module_UC)
+ list(APPEND _osg_component_founds ${_osg_module_UC}_FOUND)
+ endforeach()
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph
+ REQUIRED_VARS OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR ${_osg_component_founds}
+ VERSION_VAR OPENSCENEGRAPH_VERSION)
+
+unset(_osg_component_founds)
+
+set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})
+
diff --git a/Modules/FindOpenThreads.cmake b/Modules/FindOpenThreads.cmake
new file mode 100644
index 0000000000..69bab3dd0c
--- /dev/null
+++ b/Modules/FindOpenThreads.cmake
@@ -0,0 +1,135 @@
+#.rst:
+# FindOpenThreads
+# ---------------
+#
+#
+#
+# OpenThreads is a C++ based threading library. Its largest userbase
+# seems to OpenSceneGraph so you might notice I accept OSGDIR as an
+# environment path. I consider this part of the Findosg* suite used to
+# find OpenSceneGraph components. Each component is separate and you
+# must opt in to each module.
+#
+# Locate OpenThreads This module defines OPENTHREADS_LIBRARY
+# OPENTHREADS_FOUND, if false, do not try to link to OpenThreads
+# OPENTHREADS_INCLUDE_DIR, where to find the headers
+#
+# $OPENTHREADS_DIR is an environment variable that would correspond to
+# the ./configure --prefix=$OPENTHREADS_DIR used in building osg.
+#
+# [CMake 2.8.10]: The CMake variables OPENTHREADS_DIR or OSG_DIR can now
+# be used as well to influence detection, instead of needing to specify
+# an environment variable.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 Kitware, Inc.
+# Copyright 2012 Philip Lowman <philip@yhbt.com>
+#
+# 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.)
+
+# Header files are presumed to be included like
+# #include <OpenThreads/Thread>
+
+# To make it easier for one-step automated configuration/builds,
+# we leverage environmental paths. This is preferable
+# to the -DVAR=value switches because it insulates the
+# users from changes we may make in this script.
+# It also offers a little more flexibility than setting
+# the CMAKE_*_PATH since we can target specific components.
+# However, the default CMake behavior will search system paths
+# before anything else. This is problematic in the cases
+# where you have an older (stable) version installed, but
+# are trying to build a newer version.
+# CMake doesn't offer a nice way to globally control this behavior
+# so we have to do a nasty "double FIND_" in this module.
+# The first FIND disables the CMAKE_ search paths and only checks
+# the environmental paths.
+# If nothing is found, then the second find will search the
+# standard install paths.
+# Explicit -DVAR=value arguments should still be able to override everything.
+
+find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
+ HINTS
+ ENV OPENTHREADS_INCLUDE_DIR
+ ENV OPENTHREADS_DIR
+ ENV OSG_INCLUDE_DIR
+ ENV OSG_DIR
+ ENV OSGDIR
+ ENV OpenThreads_ROOT
+ ENV OSG_ROOT
+ ${OPENTHREADS_DIR}
+ ${OSG_DIR}
+ PATHS
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+ /usr/freeware
+ PATH_SUFFIXES include
+)
+
+
+find_library(OPENTHREADS_LIBRARY
+ NAMES OpenThreads OpenThreadsWin32
+ HINTS
+ ENV OPENTHREADS_LIBRARY_DIR
+ ENV OPENTHREADS_DIR
+ ENV OSG_LIBRARY_DIR
+ ENV OSG_DIR
+ ENV OSGDIR
+ ENV OpenThreads_ROOT
+ ENV OSG_ROOT
+ ${OPENTHREADS_DIR}
+ ${OSG_DIR}
+ PATHS
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ /usr/freeware
+ PATH_SUFFIXES lib
+)
+
+find_library(OPENTHREADS_LIBRARY_DEBUG
+ NAMES OpenThreadsd OpenThreadsWin32d
+ HINTS
+ ENV OPENTHREADS_DEBUG_LIBRARY_DIR
+ ENV OPENTHREADS_LIBRARY_DIR
+ ENV OPENTHREADS_DIR
+ ENV OSG_LIBRARY_DIR
+ ENV OSG_DIR
+ ENV OSGDIR
+ ENV OpenThreads_ROOT
+ ENV OSG_ROOT
+ ${OPENTHREADS_DIR}
+ ${OSG_DIR}
+ PATHS
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ /usr/freeware
+ PATH_SUFFIXES lib
+)
+
+if(OPENTHREADS_LIBRARY_DEBUG)
+ set(OPENTHREADS_LIBRARIES
+ optimized ${OPENTHREADS_LIBRARY}
+ debug ${OPENTHREADS_LIBRARY_DEBUG})
+else()
+ set(OPENTHREADS_LIBRARIES ${OPENTHREADS_LIBRARY})
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenThreads DEFAULT_MSG
+ OPENTHREADS_LIBRARY OPENTHREADS_INCLUDE_DIR)
diff --git a/Modules/FindPHP4.cmake b/Modules/FindPHP4.cmake
new file mode 100644
index 0000000000..25fff8c73b
--- /dev/null
+++ b/Modules/FindPHP4.cmake
@@ -0,0 +1,91 @@
+#.rst:
+# FindPHP4
+# --------
+#
+# Find PHP4
+#
+# This module finds if PHP4 is installed and determines where the
+# include files and libraries are. It also determines what the name of
+# the library is. This code sets the following variables:
+#
+# ::
+#
+# PHP4_INCLUDE_PATH = path to where php.h can be found
+# PHP4_EXECUTABLE = full path to the php4 binary
+
+#=============================================================================
+# Copyright 2004-2009 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.)
+
+set(PHP4_POSSIBLE_INCLUDE_PATHS
+ /usr/include/php4
+ /usr/local/include/php4
+ /usr/include/php
+ /usr/local/include/php
+ /usr/local/apache/php
+ )
+
+set(PHP4_POSSIBLE_LIB_PATHS
+ /usr/lib
+ )
+
+find_path(PHP4_FOUND_INCLUDE_PATH main/php.h
+ ${PHP4_POSSIBLE_INCLUDE_PATHS})
+
+if(PHP4_FOUND_INCLUDE_PATH)
+ set(php4_paths "${PHP4_POSSIBLE_INCLUDE_PATHS}")
+ foreach(php4_path Zend main TSRM)
+ set(php4_paths ${php4_paths} "${PHP4_FOUND_INCLUDE_PATH}/${php4_path}")
+ endforeach()
+ set(PHP4_INCLUDE_PATH "${php4_paths}")
+endif()
+
+find_program(PHP4_EXECUTABLE NAMES php4 php )
+
+mark_as_advanced(
+ PHP4_EXECUTABLE
+ PHP4_FOUND_INCLUDE_PATH
+ )
+
+if(APPLE)
+# this is a hack for now
+ set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
+ "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -Wl,-flat_namespace")
+ foreach(symbol
+ __efree
+ __emalloc
+ __estrdup
+ __object_init_ex
+ __zend_get_parameters_array_ex
+ __zend_list_find
+ __zval_copy_ctor
+ _add_property_zval_ex
+ _alloc_globals
+ _compiler_globals
+ _convert_to_double
+ _convert_to_long
+ _zend_error
+ _zend_hash_find
+ _zend_register_internal_class_ex
+ _zend_register_list_destructors_ex
+ _zend_register_resource
+ _zend_rsrc_list_get_rsrc_type
+ _zend_wrong_param_count
+ _zval_used_for_init
+ )
+ set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
+ "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS},-U,${symbol}")
+ endforeach()
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PHP4 DEFAULT_MSG PHP4_EXECUTABLE PHP4_INCLUDE_PATH)
diff --git a/Modules/FindPNG.cmake b/Modules/FindPNG.cmake
new file mode 100644
index 0000000000..fa04bf0b4a
--- /dev/null
+++ b/Modules/FindPNG.cmake
@@ -0,0 +1,122 @@
+#.rst:
+# FindPNG
+# -------
+#
+# Find the native PNG includes and library
+#
+#
+#
+# This module searches libpng, the library for working with PNG images.
+#
+# It defines the following variables
+#
+# ::
+#
+# PNG_INCLUDE_DIRS, where to find png.h, etc.
+# PNG_LIBRARIES, the libraries to link against to use PNG.
+# PNG_DEFINITIONS - You should add_definitons(${PNG_DEFINITIONS}) before compiling code that includes png library files.
+# PNG_FOUND, If false, do not try to use PNG.
+# PNG_VERSION_STRING - the version of the PNG library found (since CMake 2.8.8)
+#
+# Also defined, but not for general use are
+#
+# ::
+#
+# 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.
+#
+# 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.
+#
+# 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.)
+
+if(PNG_FIND_QUIETLY)
+ set(_FIND_ZLIB_ARG QUIET)
+endif()
+find_package(ZLIB ${_FIND_ZLIB_ARG})
+
+if(ZLIB_FOUND)
+ find_path(PNG_PNG_INCLUDE_DIR png.h
+ /usr/local/include/libpng # OpenBSD
+ )
+
+ list(APPEND PNG_NAMES png libpng)
+ unset(PNG_NAMES_DEBUG)
+ set(_PNG_VERSION_SUFFIXES 17 16 15 14 12)
+ if (PNG_FIND_VERSION MATCHES "^([0-9]+)\\.([0-9]+)(\\..*)?$")
+ set(_PNG_VERSION_SUFFIX_MIN "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
+ if (PNG_FIND_VERSION_EXACT)
+ set(_PNG_VERSION_SUFFIXES ${_PNG_VERSION_SUFFIX_MIN})
+ else ()
+ string(REGEX REPLACE
+ "${_PNG_VERSION_SUFFIX_MIN}.*" "${_PNG_VERSION_SUFFIX_MIN}"
+ _PNG_VERSION_SUFFIXES "${_PNG_VERSION_SUFFIXES}")
+ endif ()
+ unset(_PNG_VERSION_SUFFIX_MIN)
+ endif ()
+ foreach(v IN LISTS _PNG_VERSION_SUFFIXES)
+ list(APPEND PNG_NAMES png${v} libpng${v})
+ list(APPEND PNG_NAMES_DEBUG png${v}d libpng${v}d)
+ endforeach()
+ unset(_PNG_VERSION_SUFFIXES)
+ # For compatiblity with versions prior to this multi-config search, honor
+ # any PNG_LIBRARY that is already specified and skip the search.
+ if(NOT PNG_LIBRARY)
+ find_library(PNG_LIBRARY_RELEASE NAMES ${PNG_NAMES})
+ find_library(PNG_LIBRARY_DEBUG NAMES ${PNG_NAMES_DEBUG})
+ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+ select_library_configurations(PNG)
+ mark_as_advanced(PNG_LIBRARY_RELEASE PNG_LIBRARY_DEBUG)
+ endif()
+ unset(PNG_NAMES)
+ unset(PNG_NAMES_DEBUG)
+
+ # Set by select_library_configurations(), but we want the one from
+ # find_package_handle_standard_args() below.
+ unset(PNG_FOUND)
+
+ if (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR)
+ # png.h includes zlib.h. Sigh.
+ set(PNG_INCLUDE_DIRS ${PNG_PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} )
+ set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIRS} ) # for backward compatiblity
+ set(PNG_LIBRARIES ${PNG_LIBRARY} ${ZLIB_LIBRARY})
+
+ if (CYGWIN)
+ if(BUILD_SHARED_LIBS)
+ # No need to define PNG_USE_DLL here, because it's default for Cygwin.
+ else()
+ set (PNG_DEFINITIONS -DPNG_STATIC)
+ endif()
+ endif ()
+
+ endif ()
+
+ if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
+ file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"")
+
+ string(REGEX REPLACE "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*" "\\1" PNG_VERSION_STRING "${png_version_str}")
+ unset(png_version_str)
+ endif ()
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(PNG
+ REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR
+ VERSION_VAR PNG_VERSION_STRING)
+
+mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY )
diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake
new file mode 100644
index 0000000000..23f3f0511b
--- /dev/null
+++ b/Modules/FindPackageHandleStandardArgs.cmake
@@ -0,0 +1,380 @@
+#.rst:
+# FindPackageHandleStandardArgs
+# -----------------------------
+#
+#
+#
+# FIND_PACKAGE_HANDLE_STANDARD_ARGS(<name> ... )
+#
+# This function is intended to be used in FindXXX.cmake modules files.
+# It handles the REQUIRED, QUIET and version-related arguments to
+# find_package(). It also sets the <packagename>_FOUND variable. The
+# package is considered found if all variables <var1>... listed contain
+# valid results, e.g. valid filepaths.
+#
+# There are two modes of this function. The first argument in both
+# modes is the name of the Find-module where it is called (in original
+# casing).
+#
+# The first simple mode looks like this:
+#
+# ::
+#
+# FIND_PACKAGE_HANDLE_STANDARD_ARGS(<name> (DEFAULT_MSG|"Custom failure message") <var1>...<varN> )
+#
+# If the variables <var1> to <varN> are all valid, then
+# <UPPERCASED_NAME>_FOUND will be set to TRUE. If DEFAULT_MSG is given
+# as second argument, then the function will generate itself useful
+# success and error messages. You can also supply a custom error
+# message for the failure case. This is not recommended.
+#
+# The second mode is more powerful and also supports version checking:
+#
+# ::
+#
+# FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME [FOUND_VAR <resultVar>]
+# [REQUIRED_VARS <var1>...<varN>]
+# [VERSION_VAR <versionvar>]
+# [HANDLE_COMPONENTS]
+# [CONFIG_MODE]
+# [FAIL_MESSAGE "Custom failure message"] )
+#
+#
+#
+# In this mode, the name of the result-variable can be set either to
+# either <UPPERCASED_NAME>_FOUND or <OriginalCase_Name>_FOUND using the
+# FOUND_VAR option. Other names for the result-variable are not
+# allowed. So for a Find-module named FindFooBar.cmake, the two
+# possible names are FooBar_FOUND and FOOBAR_FOUND. It is recommended
+# to use the original case version. If the FOUND_VAR option is not
+# used, the default is <UPPERCASED_NAME>_FOUND.
+#
+# As in the simple mode, if <var1> through <varN> are all valid,
+# <packagename>_FOUND will be set to TRUE. After REQUIRED_VARS the
+# variables which are required for this package are listed. Following
+# VERSION_VAR the name of the variable can be specified which holds the
+# version of the package which has been found. If this is done, this
+# version will be checked against the (potentially) specified required
+# version used in the find_package() call. The EXACT keyword is also
+# handled. The default messages include information about the required
+# version and the version which has been actually found, both if the
+# version is ok or not. If the package supports components, use the
+# HANDLE_COMPONENTS option to enable handling them. In this case,
+# find_package_handle_standard_args() will report which components have
+# been found and which are missing, and the <packagename>_FOUND variable
+# will be set to FALSE if any of the required components (i.e. not the
+# ones listed after OPTIONAL_COMPONENTS) are missing. Use the option
+# CONFIG_MODE if your FindXXX.cmake module is a wrapper for a
+# find_package(... NO_MODULE) call. In this case VERSION_VAR will be
+# set to <NAME>_VERSION and the macro will automatically check whether
+# the Config module was found. Via FAIL_MESSAGE a custom failure
+# message can be specified, if this is not used, the default message
+# will be displayed.
+#
+# Example for mode 1:
+#
+# ::
+#
+# find_package_handle_standard_args(LibXml2 DEFAULT_MSG LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR)
+#
+#
+#
+# LibXml2 is considered to be found, if both LIBXML2_LIBRARY and
+# LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to
+# TRUE. If it is not found and REQUIRED was used, it fails with
+# FATAL_ERROR, independent whether QUIET was used or not. If it is
+# found, success will be reported, including the content of <var1>. On
+# repeated Cmake runs, the same message won't be printed again.
+#
+# Example for mode 2:
+#
+# ::
+#
+# find_package_handle_standard_args(LibXslt FOUND_VAR LibXslt_FOUND
+# REQUIRED_VARS LibXslt_LIBRARIES LibXslt_INCLUDE_DIRS
+# VERSION_VAR LibXslt_VERSION_STRING)
+#
+# In this case, LibXslt is considered to be found if the variable(s)
+# listed after REQUIRED_VAR are all valid, i.e. LibXslt_LIBRARIES and
+# LibXslt_INCLUDE_DIRS in this case. The result will then be stored in
+# LibXslt_FOUND . Also the version of LibXslt will be checked by using
+# the version contained in LibXslt_VERSION_STRING. Since no
+# FAIL_MESSAGE is given, the default messages will be printed.
+#
+# Another example for mode 2:
+#
+# ::
+#
+# find_package(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4)
+# find_package_handle_standard_args(Automoc4 CONFIG_MODE)
+#
+# In this case, FindAutmoc4.cmake wraps a call to find_package(Automoc4
+# NO_MODULE) and adds an additional search directory for automoc4. Here
+# the result will be stored in AUTOMOC4_FOUND. The following
+# FIND_PACKAGE_HANDLE_STANDARD_ARGS() call produces a proper
+# success/error message.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
+
+# internal helper macro
+macro(_FPHSA_FAILURE_MESSAGE _msg)
+ if (${_NAME}_FIND_REQUIRED)
+ message(FATAL_ERROR "${_msg}")
+ else ()
+ if (NOT ${_NAME}_FIND_QUIETLY)
+ message(STATUS "${_msg}")
+ endif ()
+ endif ()
+endmacro()
+
+
+# internal helper macro to generate the failure message when used in CONFIG_MODE:
+macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE)
+ # <name>_CONFIG is set, but FOUND is false, this means that some other of the REQUIRED_VARS was not found:
+ if(${_NAME}_CONFIG)
+ _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: missing: ${MISSING_VARS} (found ${${_NAME}_CONFIG} ${VERSION_MSG})")
+ else()
+ # If _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version.
+ # List them all in the error message:
+ if(${_NAME}_CONSIDERED_CONFIGS)
+ set(configsText "")
+ list(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount)
+ math(EXPR configsCount "${configsCount} - 1")
+ foreach(currentConfigIndex RANGE ${configsCount})
+ list(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename)
+ list(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version)
+ set(configsText "${configsText} ${filename} (version ${version})\n")
+ endforeach()
+ if (${_NAME}_NOT_FOUND_MESSAGE)
+ set(configsText "${configsText} Reason given by package: ${${_NAME}_NOT_FOUND_MESSAGE}\n")
+ endif()
+ _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:\n${configsText}")
+
+ else()
+ # Simple case: No Config-file was found at all:
+ _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake ${VERSION_MSG}")
+ endif()
+ endif()
+endmacro()
+
+
+function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
+
+# set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in
+# new extended or in the "old" mode:
+ set(options CONFIG_MODE HANDLE_COMPONENTS)
+ set(oneValueArgs FAIL_MESSAGE VERSION_VAR FOUND_VAR)
+ set(multiValueArgs REQUIRED_VARS)
+ set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} )
+ list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX)
+
+ if(${INDEX} EQUAL -1)
+ set(FPHSA_FAIL_MESSAGE ${_FIRST_ARG})
+ set(FPHSA_REQUIRED_VARS ${ARGN})
+ set(FPHSA_VERSION_VAR)
+ else()
+
+ CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
+
+ if(FPHSA_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"")
+ endif()
+
+ if(NOT FPHSA_FAIL_MESSAGE)
+ set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG")
+ endif()
+ endif()
+
+# now that we collected all arguments, process them
+
+ if("x${FPHSA_FAIL_MESSAGE}" STREQUAL "xDEFAULT_MSG")
+ set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}")
+ endif()
+
+ # In config-mode, we rely on the variable <package>_CONFIG, which is set by find_package()
+ # when it successfully found the config-file, including version checking:
+ if(FPHSA_CONFIG_MODE)
+ list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG)
+ list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS)
+ set(FPHSA_VERSION_VAR ${_NAME}_VERSION)
+ endif()
+
+ if(NOT FPHSA_REQUIRED_VARS)
+ message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()")
+ endif()
+
+ list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR)
+
+ string(TOUPPER ${_NAME} _NAME_UPPER)
+ string(TOLOWER ${_NAME} _NAME_LOWER)
+
+ if(FPHSA_FOUND_VAR)
+ if(FPHSA_FOUND_VAR MATCHES "^${_NAME}_FOUND$" OR FPHSA_FOUND_VAR MATCHES "^${_NAME_UPPER}_FOUND$")
+ set(_FOUND_VAR ${FPHSA_FOUND_VAR})
+ else()
+ message(FATAL_ERROR "The argument for FOUND_VAR is \"${FPHSA_FOUND_VAR}\", but only \"${_NAME}_FOUND\" and \"${_NAME_UPPER}_FOUND\" are valid names.")
+ endif()
+ else()
+ set(_FOUND_VAR ${_NAME_UPPER}_FOUND)
+ endif()
+
+ # collect all variables which were not found, so they can be printed, so the
+ # user knows better what went wrong (#6375)
+ set(MISSING_VARS "")
+ set(DETAILS "")
+ # check if all passed variables are valid
+ unset(${_FOUND_VAR})
+ foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS})
+ if(NOT ${_CURRENT_VAR})
+ set(${_FOUND_VAR} FALSE)
+ set(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}")
+ else()
+ set(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]")
+ endif()
+ endforeach()
+ if(NOT "${${_FOUND_VAR}}" STREQUAL "FALSE")
+ set(${_FOUND_VAR} TRUE)
+ endif()
+
+ # component handling
+ unset(FOUND_COMPONENTS_MSG)
+ unset(MISSING_COMPONENTS_MSG)
+
+ if(FPHSA_HANDLE_COMPONENTS)
+ foreach(comp ${${_NAME}_FIND_COMPONENTS})
+ if(${_NAME}_${comp}_FOUND)
+
+ if(NOT DEFINED FOUND_COMPONENTS_MSG)
+ set(FOUND_COMPONENTS_MSG "found components: ")
+ endif()
+ set(FOUND_COMPONENTS_MSG "${FOUND_COMPONENTS_MSG} ${comp}")
+
+ else()
+
+ if(NOT DEFINED MISSING_COMPONENTS_MSG)
+ set(MISSING_COMPONENTS_MSG "missing components: ")
+ endif()
+ set(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}")
+
+ if(${_NAME}_FIND_REQUIRED_${comp})
+ set(${_FOUND_VAR} FALSE)
+ set(MISSING_VARS "${MISSING_VARS} ${comp}")
+ endif()
+
+ endif()
+ endforeach()
+ set(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}")
+ set(DETAILS "${DETAILS}[c${COMPONENT_MSG}]")
+ endif()
+
+ # version handling:
+ set(VERSION_MSG "")
+ set(VERSION_OK TRUE)
+ set(VERSION ${${FPHSA_VERSION_VAR}})
+
+ # check with DEFINED here as the requested or found version may be "0"
+ if (DEFINED ${_NAME}_FIND_VERSION)
+ if(DEFINED ${FPHSA_VERSION_VAR})
+
+ if(${_NAME}_FIND_VERSION_EXACT) # exact version required
+ # count the dots in the version string
+ string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${VERSION}")
+ # add one dot because there is one dot more than there are components
+ string(LENGTH "${_VERSION_DOTS}." _VERSION_DOTS)
+ if (_VERSION_DOTS GREATER ${_NAME}_FIND_VERSION_COUNT)
+ # Because of the C++ implementation of find_package() ${_NAME}_FIND_VERSION_COUNT
+ # is at most 4 here. Therefore a simple lookup table is used.
+ if (${_NAME}_FIND_VERSION_COUNT EQUAL 1)
+ set(_VERSION_REGEX "[^.]*")
+ elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 2)
+ set(_VERSION_REGEX "[^.]*\\.[^.]*")
+ elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 3)
+ set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*")
+ else ()
+ set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*")
+ endif ()
+ string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${VERSION}")
+ unset(_VERSION_REGEX)
+ if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _VERSION_HEAD)
+ set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
+ set(VERSION_OK FALSE)
+ else ()
+ set(VERSION_MSG "(found suitable exact version \"${VERSION}\")")
+ endif ()
+ unset(_VERSION_HEAD)
+ else ()
+ if (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
+ set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
+ set(VERSION_OK FALSE)
+ else ()
+ set(VERSION_MSG "(found suitable exact version \"${VERSION}\")")
+ endif ()
+ endif ()
+ unset(_VERSION_DOTS)
+
+ else() # minimum version specified:
+ if ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
+ set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"")
+ set(VERSION_OK FALSE)
+ else ()
+ set(VERSION_MSG "(found suitable version \"${VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")")
+ endif ()
+ endif()
+
+ else()
+
+ # if the package was not found, but a version was given, add that to the output:
+ if(${_NAME}_FIND_VERSION_EXACT)
+ set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")")
+ else()
+ set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")")
+ endif()
+
+ endif()
+ else ()
+ if(VERSION)
+ set(VERSION_MSG "(found version \"${VERSION}\")")
+ endif()
+ endif ()
+
+ if(VERSION_OK)
+ set(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]")
+ else()
+ set(${_FOUND_VAR} FALSE)
+ endif()
+
+
+ # print the result:
+ if (${_FOUND_VAR})
+ FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}")
+ else ()
+
+ if(FPHSA_CONFIG_MODE)
+ _FPHSA_HANDLE_FAILURE_CONFIG_MODE()
+ else()
+ if(NOT VERSION_OK)
+ _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})")
+ else()
+ _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}")
+ endif()
+ endif()
+
+ endif ()
+
+ set(${_FOUND_VAR} ${${_FOUND_VAR}} PARENT_SCOPE)
+
+endfunction()
diff --git a/Modules/FindPackageMessage.cmake b/Modules/FindPackageMessage.cmake
new file mode 100644
index 0000000000..a0349d3db9
--- /dev/null
+++ b/Modules/FindPackageMessage.cmake
@@ -0,0 +1,57 @@
+#.rst:
+# FindPackageMessage
+# ------------------
+#
+#
+#
+# FIND_PACKAGE_MESSAGE(<name> "message for user" "find result details")
+#
+# This macro is intended to be used in FindXXX.cmake modules files. It
+# will print a message once for each unique find result. This is useful
+# for telling the user where a package was found. The first argument
+# specifies the name (XXX) of the package. The second argument
+# specifies the message to display. The third argument lists details
+# about the find result so that if they change the message will be
+# displayed again. The macro also obeys the QUIET argument to the
+# find_package command.
+#
+# Example:
+#
+# ::
+#
+# if(X11_FOUND)
+# FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}"
+# "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
+# else()
+# ...
+# endif()
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+function(FIND_PACKAGE_MESSAGE pkg msg details)
+ # Avoid printing a message repeatedly for the same find result.
+ if(NOT ${pkg}_FIND_QUIETLY)
+ string(REPLACE "\n" "" details "${details}")
+ set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg})
+ if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}")
+ # The message has not yet been printed.
+ message(STATUS "${msg}")
+
+ # Save the find details in the cache to avoid printing the same
+ # message again.
+ set("${DETAILS_VAR}" "${details}"
+ CACHE INTERNAL "Details about finding ${pkg}")
+ endif()
+ endif()
+endfunction()
diff --git a/Modules/FindPerl.cmake b/Modules/FindPerl.cmake
new file mode 100644
index 0000000000..70284b6f75
--- /dev/null
+++ b/Modules/FindPerl.cmake
@@ -0,0 +1,90 @@
+#.rst:
+# FindPerl
+# --------
+#
+# Find perl
+#
+# this module looks for Perl
+#
+# ::
+#
+# PERL_EXECUTABLE - the full path to perl
+# PERL_FOUND - If false, don't attempt to use perl.
+# PERL_VERSION_STRING - version of perl found (since CMake 2.8.8)
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
+
+set(PERL_POSSIBLE_BIN_PATHS
+ ${CYGWIN_INSTALL_PATH}/bin
+ )
+
+if(WIN32)
+ get_filename_component(
+ ActivePerl_CurrentVersion
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl;CurrentVersion]"
+ NAME)
+ set(PERL_POSSIBLE_BIN_PATHS ${PERL_POSSIBLE_BIN_PATHS}
+ "C:/Perl/bin"
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl\\${ActivePerl_CurrentVersion}]/bin
+ )
+endif()
+
+find_program(PERL_EXECUTABLE
+ NAMES perl
+ PATHS ${PERL_POSSIBLE_BIN_PATHS}
+ )
+
+if(PERL_EXECUTABLE)
+ ### PERL_VERSION
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:version
+ OUTPUT_VARIABLE
+ PERL_VERSION_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_VERSION_RESULT_VARIABLE
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(NOT PERL_VERSION_RESULT_VARIABLE AND NOT PERL_VERSION_OUTPUT_VARIABLE MATCHES "^version='UNKNOWN'")
+ string(REGEX REPLACE "version='([^']+)'.*" "\\1" PERL_VERSION_STRING ${PERL_VERSION_OUTPUT_VARIABLE})
+ else()
+ execute_process(
+ COMMAND ${PERL_EXECUTABLE} -v
+ OUTPUT_VARIABLE PERL_VERSION_OUTPUT_VARIABLE
+ RESULT_VARIABLE PERL_VERSION_RESULT_VARIABLE
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl.*[ \\(]v([0-9\\._]+)[ \\)]")
+ set(PERL_VERSION_STRING "${CMAKE_MATCH_1}")
+ elseif(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl, version ([0-9\\._]+) +")
+ set(PERL_VERSION_STRING "${CMAKE_MATCH_1}")
+ endif()
+ endif()
+endif()
+
+# Deprecated settings for compatibility with CMake1.4
+set(PERL ${PERL_EXECUTABLE})
+
+# handle the QUIETLY and REQUIRED arguments and set PERL_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Perl
+ REQUIRED_VARS PERL_EXECUTABLE
+ VERSION_VAR PERL_VERSION_STRING)
+
+mark_as_advanced(PERL_EXECUTABLE)
diff --git a/Modules/FindPerlLibs.cmake b/Modules/FindPerlLibs.cmake
new file mode 100644
index 0000000000..54ccd249fc
--- /dev/null
+++ b/Modules/FindPerlLibs.cmake
@@ -0,0 +1,269 @@
+#.rst:
+# FindPerlLibs
+# ------------
+#
+# Find Perl libraries
+#
+# This module finds if PERL is installed and determines where the
+# include files and libraries are. It also determines what the name of
+# the library is. This code sets the following variables:
+#
+# ::
+#
+# PERLLIBS_FOUND = True if perl.h & libperl were found
+# PERL_INCLUDE_PATH = path to where perl.h is found
+# PERL_LIBRARY = path to libperl
+# PERL_EXECUTABLE = full path to the perl binary
+#
+#
+#
+# The minimum required version of Perl can be specified using the
+# standard syntax, e.g. find_package(PerlLibs 6.0)
+#
+# ::
+#
+# The following variables are also available if needed
+# (introduced after CMake 2.6.4)
+#
+#
+#
+# ::
+#
+# PERL_SITESEARCH = path to the sitesearch install dir
+# PERL_SITELIB = path to the sitelib install directory
+# PERL_VENDORARCH = path to the vendor arch install directory
+# PERL_VENDORLIB = path to the vendor lib install directory
+# PERL_ARCHLIB = path to the arch lib install directory
+# PERL_PRIVLIB = path to the priv lib install directory
+# PERL_EXTRA_C_FLAGS = Compilation flags used to build perl
+
+#=============================================================================
+# Copyright 2004-2009 Kitware, Inc.
+# Copyright 2008 Andreas Schneider <asn@cryptomilk.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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# find the perl executable
+include(${CMAKE_CURRENT_LIST_DIR}/FindPerl.cmake)
+
+if (PERL_EXECUTABLE)
+ ### PERL_PREFIX
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:prefix
+ OUTPUT_VARIABLE
+ PERL_PREFIX_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_PREFIX_RESULT_VARIABLE
+ )
+
+ if (NOT PERL_PREFIX_RESULT_VARIABLE)
+ string(REGEX REPLACE "prefix='([^']+)'.*" "\\1" PERL_PREFIX ${PERL_PREFIX_OUTPUT_VARIABLE})
+ endif ()
+
+ ### PERL_ARCHNAME
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:archname
+ OUTPUT_VARIABLE
+ PERL_ARCHNAME_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_ARCHNAME_RESULT_VARIABLE
+ )
+ if (NOT PERL_ARCHNAME_RESULT_VARIABLE)
+ string(REGEX REPLACE "archname='([^']+)'.*" "\\1" PERL_ARCHNAME ${PERL_ARCHNAME_OUTPUT_VARIABLE})
+ endif ()
+
+
+
+ ### PERL_EXTRA_C_FLAGS
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:cppflags
+ OUTPUT_VARIABLE
+ PERL_CPPFLAGS_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_CPPFLAGS_RESULT_VARIABLE
+ )
+ if (NOT PERL_CPPFLAGS_RESULT_VARIABLE)
+ string(REGEX REPLACE "cppflags='([^']+)'.*" "\\1" PERL_EXTRA_C_FLAGS ${PERL_CPPFLAGS_OUTPUT_VARIABLE})
+ endif ()
+
+ ### PERL_SITESEARCH
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:installsitesearch
+ OUTPUT_VARIABLE
+ PERL_SITESEARCH_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_SITESEARCH_RESULT_VARIABLE
+ )
+ if (NOT PERL_SITESEARCH_RESULT_VARIABLE)
+ string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITESEARCH ${PERL_SITESEARCH_OUTPUT_VARIABLE})
+ file(TO_CMAKE_PATH "${PERL_SITESEARCH}" PERL_SITESEARCH)
+ endif ()
+
+ ### PERL_SITELIB
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:installsitelib
+ OUTPUT_VARIABLE
+ PERL_SITELIB_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_SITELIB_RESULT_VARIABLE
+ )
+ if (NOT PERL_SITELIB_RESULT_VARIABLE)
+ string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITELIB ${PERL_SITELIB_OUTPUT_VARIABLE})
+ file(TO_CMAKE_PATH "${PERL_SITELIB}" PERL_SITELIB)
+ endif ()
+
+ ### PERL_VENDORARCH
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:installvendorarch
+ OUTPUT_VARIABLE
+ PERL_VENDORARCH_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_VENDORARCH_RESULT_VARIABLE
+ )
+ if (NOT PERL_VENDORARCH_RESULT_VARIABLE)
+ string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORARCH ${PERL_VENDORARCH_OUTPUT_VARIABLE})
+ file(TO_CMAKE_PATH "${PERL_VENDORARCH}" PERL_VENDORARCH)
+ endif ()
+
+ ### PERL_VENDORLIB
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:installvendorlib
+ OUTPUT_VARIABLE
+ PERL_VENDORLIB_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_VENDORLIB_RESULT_VARIABLE
+ )
+ if (NOT PERL_VENDORLIB_RESULT_VARIABLE)
+ string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORLIB ${PERL_VENDORLIB_OUTPUT_VARIABLE})
+ file(TO_CMAKE_PATH "${PERL_VENDORLIB}" PERL_VENDORLIB)
+ endif ()
+
+ macro(perl_adjust_darwin_lib_variable varname)
+ string( TOUPPER PERL_${varname} FINDPERL_VARNAME )
+ string( TOLOWER install${varname} PERL_VARNAME )
+
+ if (NOT PERL_MINUSV_OUTPUT_VARIABLE)
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V
+ OUTPUT_VARIABLE
+ PERL_MINUSV_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_MINUSV_RESULT_VARIABLE
+ )
+ endif()
+
+ if (NOT PERL_MINUSV_RESULT_VARIABLE)
+ string(REGEX MATCH "(${PERL_VARNAME}.*points? to the Updates directory)"
+ PERL_NEEDS_ADJUSTMENT ${PERL_MINUSV_OUTPUT_VARIABLE})
+
+ if (PERL_NEEDS_ADJUSTMENT)
+ string(REGEX REPLACE "(.*)/Updates/" "/System/\\1/" ${FINDPERL_VARNAME} ${${FINDPERL_VARNAME}})
+ endif ()
+
+ endif ()
+ endmacro()
+
+ ### PERL_ARCHLIB
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:installarchlib
+ OUTPUT_VARIABLE
+ PERL_ARCHLIB_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_ARCHLIB_RESULT_VARIABLE
+ )
+ if (NOT PERL_ARCHLIB_RESULT_VARIABLE)
+ string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_ARCHLIB ${PERL_ARCHLIB_OUTPUT_VARIABLE})
+ perl_adjust_darwin_lib_variable( ARCHLIB )
+ file(TO_CMAKE_PATH "${PERL_ARCHLIB}" PERL_ARCHLIB)
+ endif ()
+
+ ### PERL_PRIVLIB
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:installprivlib
+ OUTPUT_VARIABLE
+ PERL_PRIVLIB_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_PRIVLIB_RESULT_VARIABLE
+ )
+ if (NOT PERL_PRIVLIB_RESULT_VARIABLE)
+ string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_PRIVLIB ${PERL_PRIVLIB_OUTPUT_VARIABLE})
+ perl_adjust_darwin_lib_variable( PRIVLIB )
+ file(TO_CMAKE_PATH "${PERL_PRIVLIB}" PERL_PRIVLIB)
+ endif ()
+
+ ### PERL_POSSIBLE_LIBRARY_NAMES
+ execute_process(
+ COMMAND
+ ${PERL_EXECUTABLE} -V:libperl
+ OUTPUT_VARIABLE
+ PERL_LIBRARY_OUTPUT_VARIABLE
+ RESULT_VARIABLE
+ PERL_LIBRARY_RESULT_VARIABLE
+ )
+ if (NOT PERL_LIBRARY_RESULT_VARIABLE)
+ string(REGEX REPLACE "libperl='([^']+)'.*" "\\1" PERL_POSSIBLE_LIBRARY_NAMES ${PERL_LIBRARY_OUTPUT_VARIABLE})
+ else ()
+ set(PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING} perl)
+ endif ()
+
+ ### PERL_INCLUDE_PATH
+ find_path(PERL_INCLUDE_PATH
+ NAMES
+ perl.h
+ PATHS
+ ${PERL_ARCHLIB}/CORE
+ /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
+ /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
+ /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
+ /usr/lib/perl/${PERL_VERSION_STRING}/CORE
+ )
+
+ ### PERL_LIBRARY
+ find_library(PERL_LIBRARY
+ NAMES
+ ${PERL_POSSIBLE_LIBRARY_NAMES}
+ PATHS
+ ${PERL_ARCHLIB}/CORE
+ /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
+ /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
+ /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
+ /usr/lib/perl/${PERL_VERSION_STRING}/CORE
+ )
+
+endif ()
+
+# handle the QUIETLY and REQUIRED arguments and set PERLLIBS_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(PerlLibs REQUIRED_VARS PERL_LIBRARY PERL_INCLUDE_PATH
+ VERSION_VAR PERL_VERSION_STRING)
+
+# Introduced after CMake 2.6.4 to bring module into compliance
+set(PERL_INCLUDE_DIR ${PERL_INCLUDE_PATH})
+set(PERL_INCLUDE_DIRS ${PERL_INCLUDE_PATH})
+set(PERL_LIBRARIES ${PERL_LIBRARY})
+# For backward compatibility with CMake before 2.8.8
+set(PERL_VERSION ${PERL_VERSION_STRING})
+
+mark_as_advanced(
+ PERL_INCLUDE_PATH
+ PERL_LIBRARY
+)
diff --git a/Modules/FindPhysFS.cmake b/Modules/FindPhysFS.cmake
new file mode 100644
index 0000000000..ff584c7ffc
--- /dev/null
+++ b/Modules/FindPhysFS.cmake
@@ -0,0 +1,60 @@
+#.rst:
+# FindPhysFS
+# ----------
+#
+#
+#
+# Locate PhysFS library This module defines PHYSFS_LIBRARY, the name of
+# the library to link against PHYSFS_FOUND, if false, do not try to link
+# to PHYSFS PHYSFS_INCLUDE_DIR, where to find physfs.h
+#
+# $PHYSFSDIR is an environment variable that would correspond to the
+# ./configure --prefix=$PHYSFSDIR used in building PHYSFS.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+find_path(PHYSFS_INCLUDE_DIR physfs.h
+ HINTS
+ ENV PHYSFSDIR
+ PATH_SUFFIXES include/physfs include
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+)
+
+find_library(PHYSFS_LIBRARY
+ NAMES physfs
+ HINTS
+ ENV PHYSFSDIR
+ PATH_SUFFIXES lib
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+)
+
+# handle the QUIETLY and REQUIRED arguments and set PHYSFS_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PhysFS DEFAULT_MSG PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR)
+
diff --git a/Modules/FindPike.cmake b/Modules/FindPike.cmake
new file mode 100644
index 0000000000..2d6a03d453
--- /dev/null
+++ b/Modules/FindPike.cmake
@@ -0,0 +1,43 @@
+#.rst:
+# FindPike
+# --------
+#
+# Find Pike
+#
+# This module finds if PIKE is installed and determines where the
+# include files and libraries are. It also determines what the name of
+# the library is. This code sets the following variables:
+#
+# ::
+#
+# PIKE_INCLUDE_PATH = path to where program.h is found
+# PIKE_EXECUTABLE = full path to the pike binary
+
+#=============================================================================
+# Copyright 2004-2009 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.)
+
+file(GLOB PIKE_POSSIBLE_INCLUDE_PATHS
+ /usr/include/pike/*
+ /usr/local/include/pike/*)
+
+find_path(PIKE_INCLUDE_PATH program.h
+ ${PIKE_POSSIBLE_INCLUDE_PATHS})
+
+find_program(PIKE_EXECUTABLE
+ NAMES pike7.4
+ )
+
+mark_as_advanced(
+ PIKE_EXECUTABLE
+ PIKE_INCLUDE_PATH
+ )
diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake
new file mode 100644
index 0000000000..d728324a86
--- /dev/null
+++ b/Modules/FindPkgConfig.cmake
@@ -0,0 +1,577 @@
+#.rst:
+# FindPkgConfig
+# -------------
+#
+# A `pkg-config` module for CMake.
+#
+# Finds the ``pkg-config`` executable and add the
+# :command:`pkg_check_modules` and :command:`pkg_search_module`
+# commands.
+#
+# In order to find the ``pkg-config`` executable, it uses the
+# :variable:`PKG_CONFIG_EXECUTABLE` variable or the ``PKG_CONFIG``
+# environment variable first.
+
+#=============================================================================
+# Copyright 2006-2014 Kitware, Inc.
+# Copyright 2014 Christoph Grüninger <foss@grueninger.de>
+# Copyright 2006 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+#
+# 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.)
+
+### Common stuff ####
+set(PKG_CONFIG_VERSION 1)
+
+# find pkg-config, use PKG_CONFIG if set
+if((NOT PKG_CONFIG_EXECUTABLE) AND (NOT "$ENV{PKG_CONFIG}" STREQUAL ""))
+ set(PKG_CONFIG_EXECUTABLE "$ENV{PKG_CONFIG}" CACHE FILEPATH "pkg-config executable")
+endif()
+find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config DOC "pkg-config executable")
+mark_as_advanced(PKG_CONFIG_EXECUTABLE)
+
+if (PKG_CONFIG_EXECUTABLE)
+ execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --version
+ OUTPUT_VARIABLE PKG_CONFIG_VERSION_STRING
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+endif ()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(PkgConfig
+ REQUIRED_VARS PKG_CONFIG_EXECUTABLE
+ VERSION_VAR PKG_CONFIG_VERSION_STRING)
+
+# This is needed because the module name is "PkgConfig" but the name of
+# this variable has always been PKG_CONFIG_FOUND so this isn't automatically
+# handled by FPHSA.
+set(PKG_CONFIG_FOUND "${PKGCONFIG_FOUND}")
+
+# Unsets the given variables
+macro(_pkgconfig_unset var)
+ set(${var} "" CACHE INTERNAL "")
+endmacro()
+
+macro(_pkgconfig_set var value)
+ set(${var} ${value} CACHE INTERNAL "")
+endmacro()
+
+# Invokes pkgconfig, cleans up the result and sets variables
+macro(_pkgconfig_invoke _pkglist _prefix _varname _regexp)
+ set(_pkgconfig_invoke_result)
+
+ execute_process(
+ COMMAND ${PKG_CONFIG_EXECUTABLE} ${ARGN} ${_pkglist}
+ OUTPUT_VARIABLE _pkgconfig_invoke_result
+ RESULT_VARIABLE _pkgconfig_failed)
+
+ if (_pkgconfig_failed)
+ set(_pkgconfig_${_varname} "")
+ _pkgconfig_unset(${_prefix}_${_varname})
+ else()
+ string(REGEX REPLACE "[\r\n]" " " _pkgconfig_invoke_result "${_pkgconfig_invoke_result}")
+ string(REGEX REPLACE " +$" "" _pkgconfig_invoke_result "${_pkgconfig_invoke_result}")
+
+ if (NOT ${_regexp} STREQUAL "")
+ string(REGEX REPLACE "${_regexp}" " " _pkgconfig_invoke_result "${_pkgconfig_invoke_result}")
+ endif()
+
+ separate_arguments(_pkgconfig_invoke_result)
+
+ #message(STATUS " ${_varname} ... ${_pkgconfig_invoke_result}")
+ set(_pkgconfig_${_varname} ${_pkgconfig_invoke_result})
+ _pkgconfig_set(${_prefix}_${_varname} "${_pkgconfig_invoke_result}")
+ endif()
+endmacro()
+
+# Invokes pkgconfig two times; once without '--static' and once with
+# '--static'
+macro(_pkgconfig_invoke_dyn _pkglist _prefix _varname cleanup_regexp)
+ _pkgconfig_invoke("${_pkglist}" ${_prefix} ${_varname} "${cleanup_regexp}" ${ARGN})
+ _pkgconfig_invoke("${_pkglist}" ${_prefix} STATIC_${_varname} "${cleanup_regexp}" --static ${ARGN})
+endmacro()
+
+# Splits given arguments into options and a package list
+macro(_pkgconfig_parse_options _result _is_req _is_silent _no_cmake_path _no_cmake_environment_path)
+ set(${_is_req} 0)
+ set(${_is_silent} 0)
+ set(${_no_cmake_path} 0)
+ set(${_no_cmake_environment_path} 0)
+ if(DEFINED PKG_CONFIG_USE_CMAKE_PREFIX_PATH)
+ if(NOT PKG_CONFIG_USE_CMAKE_PREFIX_PATH)
+ set(${_no_cmake_path} 1)
+ set(${_no_cmake_environment_path} 1)
+ endif()
+ elseif(${CMAKE_MINIMUM_REQUIRED_VERSION} VERSION_LESS 3.1)
+ set(${_no_cmake_path} 1)
+ set(${_no_cmake_environment_path} 1)
+ endif()
+
+ foreach(_pkg ${ARGN})
+ if (_pkg STREQUAL "REQUIRED")
+ set(${_is_req} 1)
+ endif ()
+ if (_pkg STREQUAL "QUIET")
+ set(${_is_silent} 1)
+ endif ()
+ if (_pkg STREQUAL "NO_CMAKE_PATH")
+ set(${_no_cmake_path} 1)
+ endif()
+ if (_pkg STREQUAL "NO_CMAKE_ENVIRONMENT_PATH")
+ set(${_no_cmake_environment_path} 1)
+ endif()
+ endforeach()
+
+ set(${_result} ${ARGN})
+ list(REMOVE_ITEM ${_result} "REQUIRED")
+ list(REMOVE_ITEM ${_result} "QUIET")
+ list(REMOVE_ITEM ${_result} "NO_CMAKE_PATH")
+ list(REMOVE_ITEM ${_result} "NO_CMAKE_ENVIRONMENT_PATH")
+endmacro()
+
+# Add the content of a variable or an environment variable to a list of
+# paths
+# Usage:
+# - _pkgconfig_add_extra_path(_extra_paths VAR)
+# - _pkgconfig_add_extra_path(_extra_paths ENV VAR)
+function(_pkgconfig_add_extra_path _extra_paths_var _var)
+ set(_is_env 0)
+ if(_var STREQUAL "ENV")
+ set(_var ${ARGV2})
+ set(_is_env 1)
+ endif()
+ if(NOT _is_env)
+ if(NOT "${${_var}}" STREQUAL "")
+ list(APPEND ${_extra_paths_var} ${CMAKE_PREFIX_PATH})
+ endif()
+ else()
+ if(NOT "$ENV{${_var}}" STREQUAL "")
+ file(TO_CMAKE_PATH "$ENV{${_var}}" _path)
+ list(APPEND ${_extra_paths_var} ${_path})
+ unset(_path)
+ endif()
+ endif()
+ set(${_extra_paths_var} ${${_extra_paths_var}} PARENT_SCOPE)
+endfunction()
+
+###
+macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cmake_environment_path _prefix)
+ _pkgconfig_unset(${_prefix}_FOUND)
+ _pkgconfig_unset(${_prefix}_VERSION)
+ _pkgconfig_unset(${_prefix}_PREFIX)
+ _pkgconfig_unset(${_prefix}_INCLUDEDIR)
+ _pkgconfig_unset(${_prefix}_LIBDIR)
+ _pkgconfig_unset(${_prefix}_LIBS)
+ _pkgconfig_unset(${_prefix}_LIBS_L)
+ _pkgconfig_unset(${_prefix}_LIBS_PATHS)
+ _pkgconfig_unset(${_prefix}_LIBS_OTHER)
+ _pkgconfig_unset(${_prefix}_CFLAGS)
+ _pkgconfig_unset(${_prefix}_CFLAGS_I)
+ _pkgconfig_unset(${_prefix}_CFLAGS_OTHER)
+ _pkgconfig_unset(${_prefix}_STATIC_LIBDIR)
+ _pkgconfig_unset(${_prefix}_STATIC_LIBS)
+ _pkgconfig_unset(${_prefix}_STATIC_LIBS_L)
+ _pkgconfig_unset(${_prefix}_STATIC_LIBS_PATHS)
+ _pkgconfig_unset(${_prefix}_STATIC_LIBS_OTHER)
+ _pkgconfig_unset(${_prefix}_STATIC_CFLAGS)
+ _pkgconfig_unset(${_prefix}_STATIC_CFLAGS_I)
+ _pkgconfig_unset(${_prefix}_STATIC_CFLAGS_OTHER)
+
+ # create a better addressable variable of the modules and calculate its size
+ set(_pkg_check_modules_list ${ARGN})
+ list(LENGTH _pkg_check_modules_list _pkg_check_modules_cnt)
+
+ if(PKG_CONFIG_EXECUTABLE)
+ # give out status message telling checked module
+ if (NOT ${_is_silent})
+ if (_pkg_check_modules_cnt EQUAL 1)
+ message(STATUS "checking for module '${_pkg_check_modules_list}'")
+ else()
+ message(STATUS "checking for modules '${_pkg_check_modules_list}'")
+ endif()
+ endif()
+
+ set(_pkg_check_modules_packages)
+ set(_pkg_check_modules_failed)
+
+ set(_extra_paths)
+
+ if(NOT _no_cmake_path)
+ _pkgconfig_add_extra_path(_extra_paths CMAKE_PREFIX_PATH)
+ _pkgconfig_add_extra_path(_extra_paths CMAKE_FRAMEWORK_PATH)
+ _pkgconfig_add_extra_path(_extra_paths CMAKE_APPBUNDLE_PATH)
+ endif()
+
+ if(NOT _no_cmake_environment_path)
+ _pkgconfig_add_extra_path(_extra_paths ENV CMAKE_PREFIX_PATH)
+ _pkgconfig_add_extra_path(_extra_paths ENV CMAKE_FRAMEWORK_PATH)
+ _pkgconfig_add_extra_path(_extra_paths ENV CMAKE_APPBUNDLE_PATH)
+ endif()
+
+ 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})
+ if(NOT "${_pkgconfig_path}" STREQUAL "")
+ file(TO_CMAKE_PATH "${_pkgconfig_path}" _pkgconfig_path)
+ endif()
+
+ # Create a list of the possible pkgconfig subfolder (depending on
+ # the system
+ set(_lib_dirs)
+ if(NOT DEFINED CMAKE_SYSTEM_NAME
+ OR (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$"
+ AND NOT CMAKE_CROSSCOMPILING))
+ if(EXISTS "/etc/debian_version") # is this a debian system ?
+ if(CMAKE_LIBRARY_ARCHITECTURE)
+ list(APPEND _lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig")
+ endif()
+ else()
+ # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
+ get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
+ if(uselib64)
+ list(APPEND _lib_dirs "lib64/pkgconfig")
+ endif()
+ endif()
+ endif()
+ list(APPEND _lib_dirs "lib/pkgconfig")
+
+ # Check if directories exist and eventually append them to the
+ # pkgconfig path list
+ foreach(_prefix_dir ${_extra_paths})
+ foreach(_lib_dir ${_lib_dirs})
+ if(EXISTS "${_prefix_dir}/${_lib_dir}")
+ list(APPEND _pkgconfig_path "${_prefix_dir}/${_lib_dir}")
+ list(REMOVE_DUPLICATES _pkgconfig_path)
+ endif()
+ endforeach()
+ endforeach()
+
+ # Prepare and set the environment variable
+ if(NOT "${_pkgconfig_path}" STREQUAL "")
+ # remove empty values from the list
+ list(REMOVE_ITEM _pkgconfig_path "")
+ file(TO_NATIVE_PATH "${_pkgconfig_path}" _pkgconfig_path)
+ if(UNIX)
+ string(REPLACE ";" ":" _pkgconfig_path "${_pkgconfig_path}")
+ string(REPLACE "\\ " " " _pkgconfig_path "${_pkgconfig_path}")
+ endif()
+ set(ENV{PKG_CONFIG_PATH} ${_pkgconfig_path})
+ endif()
+
+ # Unset variables
+ unset(_lib_dirs)
+ unset(_pkgconfig_path)
+ endif()
+
+ # iterate through module list and check whether they exist and match the required version
+ foreach (_pkg_check_modules_pkg ${_pkg_check_modules_list})
+ set(_pkg_check_modules_exist_query)
+
+ # check whether version is given
+ if (_pkg_check_modules_pkg MATCHES "(.*[^><])(>=|=|<=)(.*)")
+ set(_pkg_check_modules_pkg_name "${CMAKE_MATCH_1}")
+ set(_pkg_check_modules_pkg_op "${CMAKE_MATCH_2}")
+ set(_pkg_check_modules_pkg_ver "${CMAKE_MATCH_3}")
+ else()
+ set(_pkg_check_modules_pkg_name "${_pkg_check_modules_pkg}")
+ set(_pkg_check_modules_pkg_op)
+ set(_pkg_check_modules_pkg_ver)
+ endif()
+
+ # handle the operands
+ if (_pkg_check_modules_pkg_op STREQUAL ">=")
+ list(APPEND _pkg_check_modules_exist_query --atleast-version)
+ endif()
+
+ if (_pkg_check_modules_pkg_op STREQUAL "=")
+ list(APPEND _pkg_check_modules_exist_query --exact-version)
+ endif()
+
+ if (_pkg_check_modules_pkg_op STREQUAL "<=")
+ list(APPEND _pkg_check_modules_exist_query --max-version)
+ endif()
+
+ # create the final query which is of the format:
+ # * --atleast-version <version> <pkg-name>
+ # * --exact-version <version> <pkg-name>
+ # * --max-version <version> <pkg-name>
+ # * --exists <pkg-name>
+ 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)
+ endif()
+
+ _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_VERSION)
+ _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_PREFIX)
+ _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_INCLUDEDIR)
+ _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_LIBDIR)
+
+ list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_name}")
+ list(APPEND _pkg_check_modules_packages "${_pkg_check_modules_pkg_name}")
+
+ # execute the query
+ execute_process(
+ COMMAND ${PKG_CONFIG_EXECUTABLE} ${_pkg_check_modules_exist_query}
+ RESULT_VARIABLE _pkgconfig_retval)
+
+ # evaluate result and tell failures
+ if (_pkgconfig_retval)
+ if(NOT ${_is_silent})
+ message(STATUS " package '${_pkg_check_modules_pkg}' not found")
+ endif()
+
+ set(_pkg_check_modules_failed 1)
+ endif()
+ endforeach()
+
+ if(_pkg_check_modules_failed)
+ # fail when requested
+ if (${_is_required})
+ message(FATAL_ERROR "A required package was not found")
+ endif ()
+ else()
+ # when we are here, we checked whether requested modules
+ # exist. Now, go through them and set variables
+
+ _pkgconfig_set(${_prefix}_FOUND 1)
+ list(LENGTH _pkg_check_modules_packages pkg_count)
+
+ # iterate through all modules again and set individual variables
+ foreach (_pkg_check_modules_pkg ${_pkg_check_modules_packages})
+ # handle case when there is only one package required
+ if (pkg_count EQUAL 1)
+ set(_pkg_check_prefix "${_prefix}")
+ else()
+ set(_pkg_check_prefix "${_prefix}_${_pkg_check_modules_pkg}")
+ endif()
+
+ _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" VERSION "" --modversion )
+ _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" PREFIX "" --variable=prefix )
+ _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" INCLUDEDIR "" --variable=includedir )
+ _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" LIBDIR "" --variable=libdir )
+
+ if (NOT ${_is_silent})
+ message(STATUS " found ${_pkg_check_modules_pkg}, version ${_pkgconfig_VERSION}")
+ endif ()
+ endforeach()
+
+ # set variables which are combined for multiple modules
+ _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARIES "(^| )-l" --libs-only-l )
+ _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARY_DIRS "(^| )-L" --libs-only-L )
+ _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS "" --libs )
+ _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS_OTHER "" --libs-only-other )
+
+ _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" INCLUDE_DIRS "(^| )-I" --cflags-only-I )
+ _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS "" --cflags )
+ _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS_OTHER "" --cflags-only-other )
+ endif()
+
+ if(NOT "${_extra_paths}" STREQUAL "")
+ # Restore the environment variable
+ set(ENV{PKG_CONFIG_PATH} ${_pkgconfig_path})
+ endif()
+
+ unset(_extra_paths)
+ unset(_pkgconfig_path_old)
+ else()
+ if (${_is_required})
+ message(SEND_ERROR "pkg-config tool not found")
+ endif ()
+ endif()
+endmacro()
+
+###
+### User visible macros start here
+###
+
+#[========================================[.rst:
+.. command:: pkg_check_modules
+
+ Checks for all the given modules. ::
+
+ pkg_check_modules(<PREFIX> [REQUIRED] [QUIET]
+ [NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH]
+ <MODULE> [<MODULE>]*)
+
+
+ When the ``REQUIRED`` argument was set, macros will fail with an error
+ when module(s) could not be found.
+
+ When the ``QUIET`` argument is set, no status messages will be printed.
+
+ By default, if :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` is 3.1 or
+ later, or if :variable:`PKG_CONFIG_USE_CMAKE_PREFIX_PATH` is set, the
+ :variable:`CMAKE_PREFIX_PATH`, :variable:`CMAKE_FRAMEWORK_PATH`, and
+ :variable:`CMAKE_APPBUNDLE_PATH` cache and environment variables will
+ be added to ``pkg-config`` search path.
+ The ``NO_CMAKE_PATH`` and ``NO_CMAKE_ENVIRONMENT_PATH`` arguments
+ disable this behavior for the cache variables and the environment
+ variables, respectively.
+
+ It sets the following variables: ::
+
+ PKG_CONFIG_FOUND ... if pkg-config executable was found
+ PKG_CONFIG_EXECUTABLE ... pathname of the pkg-config program
+ PKG_CONFIG_VERSION_STRING ... the version of the pkg-config program found
+ (since CMake 2.8.8)
+
+ For the following variables two sets of values exist; first one is the
+ common one and has the given PREFIX. The second set contains flags
+ which are given out when ``pkg-config`` was called with the ``--static``
+ option. ::
+
+ <XPREFIX>_FOUND ... set to 1 if module(s) exist
+ <XPREFIX>_LIBRARIES ... only the libraries (w/o the '-l')
+ <XPREFIX>_LIBRARY_DIRS ... the paths of the libraries (w/o the '-L')
+ <XPREFIX>_LDFLAGS ... all required linker flags
+ <XPREFIX>_LDFLAGS_OTHER ... all other linker flags
+ <XPREFIX>_INCLUDE_DIRS ... the '-I' preprocessor flags (w/o the '-I')
+ <XPREFIX>_CFLAGS ... all required cflags
+ <XPREFIX>_CFLAGS_OTHER ... the other compiler flags
+
+ ::
+
+ <XPREFIX> = <PREFIX> for common case
+ <XPREFIX> = <PREFIX>_STATIC for static linking
+
+ There are some special variables whose prefix depends on the count of
+ given modules. When there is only one module, <PREFIX> stays
+ unchanged. When there are multiple modules, the prefix will be
+ changed to <PREFIX>_<MODNAME>: ::
+
+ <XPREFIX>_VERSION ... version of the module
+ <XPREFIX>_PREFIX ... prefix-directory of the module
+ <XPREFIX>_INCLUDEDIR ... include-dir of the module
+ <XPREFIX>_LIBDIR ... lib-dir of the module
+
+ ::
+
+ <XPREFIX> = <PREFIX> when |MODULES| == 1, else
+ <XPREFIX> = <PREFIX>_<MODNAME>
+
+ A <MODULE> parameter can have the following formats: ::
+
+ {MODNAME} ... matches any version
+ {MODNAME}>={VERSION} ... at least version <VERSION> is required
+ {MODNAME}={VERSION} ... exactly version <VERSION> is required
+ {MODNAME}<={VERSION} ... modules must not be newer than <VERSION>
+
+ Examples
+
+ .. code-block:: cmake
+
+ pkg_check_modules (GLIB2 glib-2.0)
+
+ .. code-block:: cmake
+
+ pkg_check_modules (GLIB2 glib-2.0>=2.10)
+
+ Requires at least version 2.10 of glib2 and defines e.g.
+ ``GLIB2_VERSION=2.10.3``
+
+ .. code-block:: cmake
+
+ pkg_check_modules (FOO glib-2.0>=2.10 gtk+-2.0)
+
+ Requires both glib2 and gtk2, and defines e.g.
+ ``FOO_glib-2.0_VERSION=2.10.3`` and ``FOO_gtk+-2.0_VERSION=2.8.20``
+
+ .. code-block:: cmake
+
+ pkg_check_modules (XRENDER REQUIRED xrender)
+
+ Defines e.g.:
+ ``XRENDER_LIBRARIES=Xrender;X11`` and
+ ``XRENDER_STATIC_LIBRARIES=Xrender;X11;pthread;Xau;Xdmcp``
+#]========================================]
+macro(pkg_check_modules _prefix _module0)
+ # check cached value
+ if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION} OR NOT ${_prefix}_FOUND)
+ _pkgconfig_parse_options (_pkg_modules _pkg_is_required _pkg_is_silent _no_cmake_path _no_cmake_environment_path "${_module0}" ${ARGN})
+ _pkg_check_modules_internal("${_pkg_is_required}" "${_pkg_is_silent}" ${_no_cmake_path} ${_no_cmake_environment_path} "${_prefix}" ${_pkg_modules})
+
+ _pkgconfig_set(__pkg_config_checked_${_prefix} ${PKG_CONFIG_VERSION})
+ endif()
+endmacro()
+
+
+#[========================================[.rst:
+.. command:: pkg_search_module
+
+ Same as :command:`pkg_check_modules`, but instead it checks for given
+ modules and uses the first working one. ::
+
+ pkg_search_module(<PREFIX> [REQUIRED] [QUIET]
+ [NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH]
+ <MODULE> [<MODULE>]*)
+
+ Examples
+
+ .. code-block:: cmake
+
+ pkg_search_module (BAR libxml-2.0 libxml2 libxml>=2)
+#]========================================]
+macro(pkg_search_module _prefix _module0)
+ # check cached value
+ if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION} OR NOT ${_prefix}_FOUND)
+ set(_pkg_modules_found 0)
+ _pkgconfig_parse_options(_pkg_modules_alt _pkg_is_required _pkg_is_silent _no_cmake_path _no_cmake_environment_path "${_module0}" ${ARGN})
+
+ if (NOT ${_pkg_is_silent})
+ message(STATUS "checking for one of the modules '${_pkg_modules_alt}'")
+ endif ()
+
+ # iterate through all modules and stop at the first working one.
+ foreach(_pkg_alt ${_pkg_modules_alt})
+ if(NOT _pkg_modules_found)
+ _pkg_check_modules_internal(0 1 ${_no_cmake_path} ${_no_cmake_environment_path} "${_prefix}" "${_pkg_alt}")
+ endif()
+
+ if (${_prefix}_FOUND)
+ set(_pkg_modules_found 1)
+ endif()
+ endforeach()
+
+ if (NOT ${_prefix}_FOUND)
+ if(${_pkg_is_required})
+ message(SEND_ERROR "None of the required '${_pkg_modules_alt}' found")
+ endif()
+ endif()
+
+ _pkgconfig_set(__pkg_config_checked_${_prefix} ${PKG_CONFIG_VERSION})
+ endif()
+endmacro()
+
+
+#[========================================[.rst:
+.. variable:: PKG_CONFIG_EXECUTABLE
+
+ Path to the pkg-config executable.
+
+
+.. variable:: PKG_CONFIG_USE_CMAKE_PREFIX_PATH
+
+ Whether :command:`pkg_check_modules` and :command:`pkg_search_module`
+ should add the paths in :variable:`CMAKE_PREFIX_PATH`,
+ :variable:`CMAKE_FRAMEWORK_PATH`, and :variable:`CMAKE_APPBUNDLE_PATH`
+ cache and environment variables to ``pkg-config`` search path.
+
+ If this variable is not set, this behavior is enabled by default if
+ :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` is 3.1 or later, disabled
+ otherwise.
+#]========================================]
+
+
+### Local Variables:
+### mode: cmake
+### End:
diff --git a/Modules/FindPostgreSQL.cmake b/Modules/FindPostgreSQL.cmake
new file mode 100644
index 0000000000..97666c886c
--- /dev/null
+++ b/Modules/FindPostgreSQL.cmake
@@ -0,0 +1,186 @@
+#.rst:
+# FindPostgreSQL
+# --------------
+#
+# Find the PostgreSQL installation.
+#
+# In Windows, we make the assumption that, if the PostgreSQL files are
+# installed, the default directory will be C:\Program Files\PostgreSQL.
+#
+# This module defines
+#
+# ::
+#
+# PostgreSQL_LIBRARIES - the PostgreSQL libraries needed for linking
+# PostgreSQL_INCLUDE_DIRS - the directories of the PostgreSQL headers
+# PostgreSQL_VERSION_STRING - the version of PostgreSQL found (since CMake 2.8.8)
+
+#=============================================================================
+# Copyright 2004-2009 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.)
+
+# ----------------------------------------------------------------------------
+# History:
+# This module is derived from the module originally found in the VTK source tree.
+#
+# ----------------------------------------------------------------------------
+# Note:
+# PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the
+# version mumber of the implementation of PostgreSQL.
+# In Windows the default installation of PostgreSQL uses that as part of the path.
+# E.g C:\Program Files\PostgreSQL\8.4.
+# Currently, the following version numbers are known to this module:
+# "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
+#
+# To use this variable just do something like this:
+# set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4")
+# before calling find_package(PostgreSQL) in your CMakeLists.txt file.
+# This will mean that the versions you set here will be found first in the order
+# specified before the default ones are searched.
+#
+# ----------------------------------------------------------------------------
+# You may need to manually set:
+# PostgreSQL_INCLUDE_DIR - the path to where the PostgreSQL include files are.
+# PostgreSQL_LIBRARY_DIR - The path to where the PostgreSQL library files are.
+# If FindPostgreSQL.cmake cannot find the include files or the library files.
+#
+# ----------------------------------------------------------------------------
+# The following variables are set if PostgreSQL is found:
+# PostgreSQL_FOUND - Set to true when PostgreSQL is found.
+# PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL
+# PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries
+# PostgreSQL_LIBRARIES - The PostgreSQL libraries.
+#
+# ----------------------------------------------------------------------------
+# If you have installed PostgreSQL in a non-standard location.
+# (Please note that in the following comments, it is assumed that <Your Path>
+# points to the root directory of the include directory of PostgreSQL.)
+# Then you have three options.
+# 1) After CMake runs, set PostgreSQL_INCLUDE_DIR to <Your Path>/include and
+# PostgreSQL_LIBRARY_DIR to wherever the library pq (or libpq in windows) is
+# 2) Use CMAKE_INCLUDE_PATH to set a path to <Your Path>/PostgreSQL<-version>. This will allow find_path()
+# to locate PostgreSQL_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g. In your CMakeLists.txt file
+# set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include")
+# 3) Set an environment variable called ${PostgreSQL_ROOT} that points to the root of where you have
+# installed PostgreSQL, e.g. <Your Path>.
+#
+# ----------------------------------------------------------------------------
+
+set(PostgreSQL_INCLUDE_PATH_DESCRIPTION "top-level directory containing the PostgreSQL include directories. E.g /usr/local/include/PostgreSQL/8.4 or C:/Program Files/PostgreSQL/8.4/include")
+set(PostgreSQL_INCLUDE_DIR_MESSAGE "Set the PostgreSQL_INCLUDE_DIR cmake cache entry to the ${PostgreSQL_INCLUDE_PATH_DESCRIPTION}")
+set(PostgreSQL_LIBRARY_PATH_DESCRIPTION "top-level directory containing the PostgreSQL libraries.")
+set(PostgreSQL_LIBRARY_DIR_MESSAGE "Set the PostgreSQL_LIBRARY_DIR cmake cache entry to the ${PostgreSQL_LIBRARY_PATH_DESCRIPTION}")
+set(PostgreSQL_ROOT_DIR_MESSAGE "Set the PostgreSQL_ROOT system variable to where PostgreSQL is found on the machine E.g C:/Program Files/PostgreSQL/8.4")
+
+
+set(PostgreSQL_KNOWN_VERSIONS ${PostgreSQL_ADDITIONAL_VERSIONS}
+ "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0")
+
+# Define additional search paths for root directories.
+if ( WIN32 )
+ foreach (suffix ${PostgreSQL_KNOWN_VERSIONS} )
+ set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} "C:/Program Files/PostgreSQL/${suffix}" )
+ endforeach()
+endif()
+set( PostgreSQL_ROOT_DIRECTORIES
+ ENV PostgreSQL_ROOT
+ ${PostgreSQL_ROOT}
+ ${PostgreSQL_ADDITIONAL_SEARCH_PATHS}
+)
+
+#
+# Look for an installation.
+#
+find_path(PostgreSQL_INCLUDE_DIR
+ NAMES libpq-fe.h
+ PATHS
+ # Look in other places.
+ ${PostgreSQL_ROOT_DIRECTORIES}
+ PATH_SUFFIXES
+ pgsql
+ postgresql
+ include
+ # Help the user find it if we cannot.
+ DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
+)
+
+find_path(PostgreSQL_TYPE_INCLUDE_DIR
+ NAMES catalog/pg_type.h
+ PATHS
+ # Look in other places.
+ ${PostgreSQL_ROOT_DIRECTORIES}
+ PATH_SUFFIXES
+ postgresql
+ pgsql/server
+ postgresql/server
+ include/server
+ # Help the user find it if we cannot.
+ DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
+)
+
+# The PostgreSQL library.
+set (PostgreSQL_LIBRARY_TO_FIND pq)
+# Setting some more prefixes for the library
+set (PostgreSQL_LIB_PREFIX "")
+if ( WIN32 )
+ set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib")
+ set ( PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND})
+endif()
+
+find_library( PostgreSQL_LIBRARY
+ NAMES ${PostgreSQL_LIBRARY_TO_FIND}
+ PATHS
+ ${PostgreSQL_ROOT_DIRECTORIES}
+ PATH_SUFFIXES
+ lib
+)
+get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH)
+
+if (PostgreSQL_INCLUDE_DIR)
+ # Some platforms include multiple pg_config.hs for multi-lib configurations
+ # This is a temporary workaround. A better solution would be to compile
+ # a dummy c file and extract the value of the symbol.
+ file(GLOB _PG_CONFIG_HEADERS "${PostgreSQL_INCLUDE_DIR}/pg_config*.h")
+ foreach(_PG_CONFIG_HEADER ${_PG_CONFIG_HEADERS})
+ if(EXISTS "${_PG_CONFIG_HEADER}")
+ file(STRINGS "${_PG_CONFIG_HEADER}" pgsql_version_str
+ REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"")
+ if(pgsql_version_str)
+ string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*"
+ "\\1" PostgreSQL_VERSION_STRING "${pgsql_version_str}")
+ break()
+ endif()
+ endif()
+ endforeach()
+ unset(pgsql_version_str)
+endif()
+
+# Did we find anything?
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(PostgreSQL
+ REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR
+ VERSION_VAR PostgreSQL_VERSION_STRING)
+set( PostgreSQL_FOUND ${POSTGRESQL_FOUND})
+
+# Now try to get the include and library path.
+if(PostgreSQL_FOUND)
+
+ set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} )
+ set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
+ set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY_TO_FIND})
+
+ #message("Final PostgreSQL include dir: ${PostgreSQL_INCLUDE_DIRS}")
+ #message("Final PostgreSQL library dir: ${PostgreSQL_LIBRARY_DIRS}")
+ #message("Final PostgreSQL libraries: ${PostgreSQL_LIBRARIES}")
+endif()
+
+mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR PostgreSQL_LIBRARY )
diff --git a/Modules/FindProducer.cmake b/Modules/FindProducer.cmake
new file mode 100644
index 0000000000..aef84eac71
--- /dev/null
+++ b/Modules/FindProducer.cmake
@@ -0,0 +1,81 @@
+#.rst:
+# FindProducer
+# ------------
+#
+#
+#
+# Though Producer isn't directly part of OpenSceneGraph, its primary
+# user is OSG so I consider this part of the Findosg* suite used to find
+# OpenSceneGraph components. You'll notice that I accept OSGDIR as an
+# environment path.
+#
+# Each component is separate and you must opt in to each module. You
+# must also opt into OpenGL (and OpenThreads?) as these modules won't do
+# it for you. This is to allow you control over your own system piece
+# by piece in case you need to opt out of certain components or change
+# the Find behavior for a particular module (perhaps because the default
+# FindOpenGL.cmake module doesn't work with your system as an example).
+# If you want to use a more convenient module that includes everything,
+# use the FindOpenSceneGraph.cmake instead of the Findosg*.cmake
+# modules.
+#
+# Locate Producer This module defines PRODUCER_LIBRARY PRODUCER_FOUND,
+# if false, do not try to link to Producer PRODUCER_INCLUDE_DIR, where
+# to find the headers
+#
+# $PRODUCER_DIR is an environment variable that would correspond to the
+# ./configure --prefix=$PRODUCER_DIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <Producer/CameraGroup>
+
+# Try the user's environment request before anything else.
+find_path(PRODUCER_INCLUDE_DIR Producer/CameraGroup
+ HINTS
+ ENV PRODUCER_DIR
+ ENV OSG_DIR
+ ENV OSGDIR
+ PATH_SUFFIXES include
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /sw/include # Fink
+ /opt/local/include # DarwinPorts
+ /opt/csw/include # Blastwave
+ /opt/include
+ [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OpenThreads_ROOT]/include
+ [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include
+)
+
+find_library(PRODUCER_LIBRARY
+ NAMES Producer
+ HINTS
+ ENV PRODUCER_DIR
+ ENV OSG_DIR
+ ENV OSGDIR
+ PATH_SUFFIXES lib
+ PATHS
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Producer DEFAULT_MSG
+ PRODUCER_LIBRARY PRODUCER_INCLUDE_DIR)
diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
new file mode 100644
index 0000000000..72ca6ed202
--- /dev/null
+++ b/Modules/FindProtobuf.cmake
@@ -0,0 +1,296 @@
+#.rst:
+# FindProtobuf
+# ------------
+#
+#
+#
+# Locate and configure the Google Protocol Buffers library.
+#
+# The following variables can be set and are optional:
+#
+# ::
+#
+# PROTOBUF_SRC_ROOT_FOLDER - When compiling with MSVC, if this cache variable is set
+# the protobuf-default VS project build locations
+# (vsprojects/Debug & vsprojects/Release) will be searched
+# for libraries and binaries.
+#
+#
+#
+# ::
+#
+# PROTOBUF_IMPORT_DIRS - List of additional directories to be searched for
+# imported .proto files. (New in CMake 2.8.8)
+#
+#
+#
+# Defines the following variables:
+#
+# ::
+#
+# PROTOBUF_FOUND - Found the Google Protocol Buffers library (libprotobuf & header files)
+# PROTOBUF_INCLUDE_DIRS - Include directories for Google Protocol Buffers
+# PROTOBUF_LIBRARIES - The protobuf libraries
+#
+# [New in CMake 2.8.5]
+#
+# ::
+#
+# PROTOBUF_PROTOC_LIBRARIES - The protoc libraries
+# PROTOBUF_LITE_LIBRARIES - The protobuf-lite libraries
+#
+#
+#
+# The following cache variables are also available to set or use:
+#
+# ::
+#
+# PROTOBUF_LIBRARY - The protobuf library
+# PROTOBUF_PROTOC_LIBRARY - The protoc library
+# PROTOBUF_INCLUDE_DIR - The include directory for protocol buffers
+# PROTOBUF_PROTOC_EXECUTABLE - The protoc compiler
+#
+# [New in CMake 2.8.5]
+#
+# ::
+#
+# PROTOBUF_LIBRARY_DEBUG - The protobuf library (debug)
+# PROTOBUF_PROTOC_LIBRARY_DEBUG - The protoc library (debug)
+# PROTOBUF_LITE_LIBRARY - The protobuf lite library
+# PROTOBUF_LITE_LIBRARY_DEBUG - The protobuf lite library (debug)
+#
+#
+#
+# ::
+#
+# ====================================================================
+# Example:
+#
+#
+#
+# ::
+#
+# find_package(Protobuf REQUIRED)
+# include_directories(${PROTOBUF_INCLUDE_DIRS})
+#
+#
+#
+# ::
+#
+# include_directories(${CMAKE_CURRENT_BINARY_DIR})
+# PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS foo.proto)
+# add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS})
+# target_link_libraries(bar ${PROTOBUF_LIBRARIES})
+#
+#
+#
+# NOTE: You may need to link against pthreads, depending
+#
+# ::
+#
+# on the platform.
+#
+#
+#
+# NOTE: The PROTOBUF_GENERATE_CPP macro & add_executable() or
+# add_library()
+#
+# ::
+#
+# calls only work properly within the same directory.
+#
+#
+#
+# ::
+#
+# ====================================================================
+#
+#
+#
+# PROTOBUF_GENERATE_CPP (public function)
+#
+# ::
+#
+# SRCS = Variable to define with autogenerated
+# source files
+# HDRS = Variable to define with autogenerated
+# header files
+# ARGN = proto files
+#
+#
+#
+# ::
+#
+# ====================================================================
+
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2009-2011 Philip Lowman <philip@yhbt.com>
+# Copyright 2008 Esben Mose Hansen, Ange Optimization ApS
+#
+# 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(PROTOBUF_GENERATE_CPP SRCS HDRS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
+ return()
+ endif()
+
+ if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
+ # Create an include path for each file specified
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(ABS_PATH ${ABS_FIL} PATH)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ else()
+ set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
+ endif()
+
+ if(DEFINED PROTOBUF_IMPORT_DIRS)
+ foreach(DIR ${PROTOBUF_IMPORT_DIRS})
+ get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ endif()
+
+ set(${SRCS})
+ set(${HDRS})
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
+ list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
+
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
+ "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
+ COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
+ ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
+ DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
+ COMMENT "Running C++ protocol buffer compiler on ${FIL}"
+ VERBATIM )
+ endforeach()
+
+ set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
+ set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+ set(${HDRS} ${${HDRS}} PARENT_SCOPE)
+endfunction()
+
+# Internal function: search for normal library as well as a debug one
+# if the debug one is specified also include debug/optimized keywords
+# in *_LIBRARIES variable
+function(_protobuf_find_libraries name filename)
+ find_library(${name}_LIBRARY
+ NAMES ${filename}
+ PATHS ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/Release)
+ mark_as_advanced(${name}_LIBRARY)
+
+ find_library(${name}_LIBRARY_DEBUG
+ NAMES ${filename}
+ PATHS ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/Debug)
+ mark_as_advanced(${name}_LIBRARY_DEBUG)
+
+ if(NOT ${name}_LIBRARY_DEBUG)
+ # There is no debug library
+ set(${name}_LIBRARY_DEBUG ${${name}_LIBRARY} PARENT_SCOPE)
+ set(${name}_LIBRARIES ${${name}_LIBRARY} PARENT_SCOPE)
+ else()
+ # There IS a debug library
+ set(${name}_LIBRARIES
+ optimized ${${name}_LIBRARY}
+ debug ${${name}_LIBRARY_DEBUG}
+ PARENT_SCOPE
+ )
+ endif()
+endfunction()
+
+# Internal function: find threads library
+function(_protobuf_find_threads)
+ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
+ find_package(Threads)
+ if(Threads_FOUND)
+ list(APPEND PROTOBUF_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
+ set(PROTOBUF_LIBRARIES "${PROTOBUF_LIBRARIES}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+#
+# Main.
+#
+
+# By default have PROTOBUF_GENERATE_CPP macro pass -I to protoc
+# for each directory where a proto file is referenced.
+if(NOT DEFINED PROTOBUF_GENERATE_CPP_APPEND_PATH)
+ set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE)
+endif()
+
+
+# Google's provided vcproj files generate libraries with a "lib"
+# prefix on Windows
+if(MSVC)
+ set(PROTOBUF_ORIG_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
+ set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+
+ find_path(PROTOBUF_SRC_ROOT_FOLDER protobuf.pc.in)
+endif()
+
+# The Protobuf library
+_protobuf_find_libraries(PROTOBUF protobuf)
+#DOC "The Google Protocol Buffers RELEASE Library"
+
+_protobuf_find_libraries(PROTOBUF_LITE protobuf-lite)
+
+# The Protobuf Protoc Library
+_protobuf_find_libraries(PROTOBUF_PROTOC protoc)
+
+# Restore original find library prefixes
+if(MSVC)
+ set(CMAKE_FIND_LIBRARY_PREFIXES "${PROTOBUF_ORIG_FIND_LIBRARY_PREFIXES}")
+endif()
+
+if(UNIX)
+ _protobuf_find_threads()
+endif()
+
+# Find the include directory
+find_path(PROTOBUF_INCLUDE_DIR
+ google/protobuf/service.h
+ PATHS ${PROTOBUF_SRC_ROOT_FOLDER}/src
+)
+mark_as_advanced(PROTOBUF_INCLUDE_DIR)
+
+# Find the protoc Executable
+find_program(PROTOBUF_PROTOC_EXECUTABLE
+ NAMES protoc
+ DOC "The Google Protocol Buffers Compiler"
+ PATHS
+ ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/Release
+ ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/Debug
+)
+mark_as_advanced(PROTOBUF_PROTOC_EXECUTABLE)
+
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROTOBUF DEFAULT_MSG
+ PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR)
+
+if(PROTOBUF_FOUND)
+ set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIR})
+endif()
diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
new file mode 100644
index 0000000000..5e5c7b933e
--- /dev/null
+++ b/Modules/FindPythonInterp.cmake
@@ -0,0 +1,164 @@
+#.rst:
+# FindPythonInterp
+# ----------------
+#
+# Find python interpreter
+#
+# This module finds if Python interpreter is installed and determines
+# where the executables are. This code sets the following variables:
+#
+# ::
+#
+# PYTHONINTERP_FOUND - Was the Python executable found
+# PYTHON_EXECUTABLE - path to the Python interpreter
+#
+#
+#
+# ::
+#
+# PYTHON_VERSION_STRING - Python version found e.g. 2.5.2
+# PYTHON_VERSION_MAJOR - Python major version found e.g. 2
+# PYTHON_VERSION_MINOR - Python minor version found e.g. 5
+# PYTHON_VERSION_PATCH - Python patch version found e.g. 2
+#
+#
+#
+# The Python_ADDITIONAL_VERSIONS variable can be used to specify a list
+# of version numbers that should be taken into account when searching
+# 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.
+
+#=============================================================================
+# Copyright 2005-2010 Kitware, Inc.
+# Copyright 2011 Bjoern Ricks <bjoern.ricks@gmail.com>
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+unset(_Python_NAMES)
+
+set(_PYTHON1_VERSIONS 1.6 1.5)
+set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
+set(_PYTHON3_VERSIONS 3.4 3.3 3.2 3.1 3.0)
+
+if(PythonInterp_FIND_VERSION)
+ if(PythonInterp_FIND_VERSION_COUNT GREATER 1)
+ set(_PYTHON_FIND_MAJ_MIN "${PythonInterp_FIND_VERSION_MAJOR}.${PythonInterp_FIND_VERSION_MINOR}")
+ list(APPEND _Python_NAMES
+ python${_PYTHON_FIND_MAJ_MIN}
+ python${PythonInterp_FIND_VERSION_MAJOR})
+ unset(_PYTHON_FIND_OTHER_VERSIONS)
+ if(NOT PythonInterp_FIND_VERSION_EXACT)
+ foreach(_PYTHON_V ${_PYTHON${PythonInterp_FIND_VERSION_MAJOR}_VERSIONS})
+ if(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN)
+ list(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V})
+ endif()
+ endforeach()
+ endif()
+ unset(_PYTHON_FIND_MAJ_MIN)
+ else()
+ list(APPEND _Python_NAMES python${PythonInterp_FIND_VERSION_MAJOR})
+ set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonInterp_FIND_VERSION_MAJOR}_VERSIONS})
+ endif()
+else()
+ set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS})
+endif()
+find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES})
+
+# Set up the versions we know about, in the order we will search. Always add
+# the user supplied additional versions to the front.
+set(_Python_VERSIONS ${Python_ADDITIONAL_VERSIONS})
+# If FindPythonInterp has already found the major and minor version,
+# insert that version next to get consistent versions of the interpreter and
+# library.
+if(DEFINED PYTHONLIBS_VERSION_STRING)
+ string(REPLACE "." ";" _PYTHONLIBS_VERSION "${PYTHONLIBS_VERSION_STRING}")
+ list(GET _PYTHONLIBS_VERSION 0 _PYTHONLIBS_VERSION_MAJOR)
+ list(GET _PYTHONLIBS_VERSION 1 _PYTHONLIBS_VERSION_MINOR)
+ list(APPEND _Python_VERSIONS ${_PYTHONLIBS_VERSION_MAJOR}.${_PYTHONLIBS_VERSION_MINOR})
+endif()
+# Search for the current active python version first
+list(APPEND _Python_VERSIONS ";")
+list(APPEND _Python_VERSIONS ${_PYTHON_FIND_OTHER_VERSIONS})
+
+unset(_PYTHON_FIND_OTHER_VERSIONS)
+unset(_PYTHON1_VERSIONS)
+unset(_PYTHON2_VERSIONS)
+unset(_PYTHON3_VERSIONS)
+
+# Search for newest python version if python executable isn't found
+if(NOT PYTHON_EXECUTABLE)
+ foreach(_CURRENT_VERSION IN LISTS _Python_VERSIONS)
+ set(_Python_NAMES python${_CURRENT_VERSION})
+ if(WIN32)
+ list(APPEND _Python_NAMES python)
+ endif()
+ find_program(PYTHON_EXECUTABLE
+ NAMES ${_Python_NAMES}
+ PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]
+ )
+ endforeach()
+endif()
+
+# determine python version string
+if(PYTHON_EXECUTABLE)
+ execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
+ "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))"
+ OUTPUT_VARIABLE _VERSION
+ RESULT_VARIABLE _PYTHON_VERSION_RESULT
+ ERROR_QUIET)
+ if(NOT _PYTHON_VERSION_RESULT)
+ string(REPLACE ";" "." PYTHON_VERSION_STRING "${_VERSION}")
+ list(GET _VERSION 0 PYTHON_VERSION_MAJOR)
+ list(GET _VERSION 1 PYTHON_VERSION_MINOR)
+ list(GET _VERSION 2 PYTHON_VERSION_PATCH)
+ if(PYTHON_VERSION_PATCH EQUAL 0)
+ # it's called "Python 2.7", not "2.7.0"
+ string(REGEX REPLACE "\\.0$" "" PYTHON_VERSION_STRING "${PYTHON_VERSION_STRING}")
+ endif()
+ else()
+ # sys.version predates sys.version_info, so use that
+ execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)"
+ OUTPUT_VARIABLE _VERSION
+ RESULT_VARIABLE _PYTHON_VERSION_RESULT
+ ERROR_QUIET)
+ if(NOT _PYTHON_VERSION_RESULT)
+ string(REGEX REPLACE " .*" "" PYTHON_VERSION_STRING "${_VERSION}")
+ string(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" PYTHON_VERSION_MAJOR "${PYTHON_VERSION_STRING}")
+ string(REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" PYTHON_VERSION_MINOR "${PYTHON_VERSION_STRING}")
+ if(PYTHON_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.([0-9]+)")
+ set(PYTHON_VERSION_PATCH "${CMAKE_MATCH_1}")
+ else()
+ set(PYTHON_VERSION_PATCH "0")
+ endif()
+ else()
+ # sys.version was first documented for Python 1.5, so assume
+ # this is older.
+ set(PYTHON_VERSION_STRING "1.4")
+ set(PYTHON_VERSION_MAJOR "1")
+ set(PYTHON_VERSION_MAJOR "4")
+ set(PYTHON_VERSION_MAJOR "0")
+ endif()
+ endif()
+ unset(_PYTHON_VERSION_RESULT)
+ unset(_VERSION)
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonInterp REQUIRED_VARS PYTHON_EXECUTABLE VERSION_VAR PYTHON_VERSION_STRING)
+
+mark_as_advanced(PYTHON_EXECUTABLE)
diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake
new file mode 100644
index 0000000000..cc875ade7a
--- /dev/null
+++ b/Modules/FindPythonLibs.cmake
@@ -0,0 +1,294 @@
+#.rst:
+# FindPythonLibs
+# --------------
+#
+# Find python libraries
+#
+# This module finds if Python is installed and determines where the
+# include files and libraries are. It also determines what the name of
+# the library is. This code sets the following variables:
+#
+# ::
+#
+# PYTHONLIBS_FOUND - have the Python libs been found
+# PYTHON_LIBRARIES - path to the python library
+# PYTHON_INCLUDE_PATH - path to where Python.h is found (deprecated)
+# PYTHON_INCLUDE_DIRS - path to where Python.h is found
+# PYTHON_DEBUG_LIBRARIES - path to the debug library (deprecated)
+# PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8)
+#
+#
+#
+# The Python_ADDITIONAL_VERSIONS variable can be used to specify a list
+# of version numbers that should be taken into account when searching
+# for Python. You need to set this variable before calling
+# find_package(PythonLibs).
+#
+# If you'd like to specify the installation of Python to use, you should
+# modify the following cache variables:
+#
+# ::
+#
+# 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.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindFrameworks.cmake)
+# Search for the python framework on Apple.
+CMAKE_FIND_FRAMEWORKS(Python)
+
+set(_PYTHON1_VERSIONS 1.6 1.5)
+set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
+set(_PYTHON3_VERSIONS 3.4 3.3 3.2 3.1 3.0)
+
+if(PythonLibs_FIND_VERSION)
+ if(PythonLibs_FIND_VERSION_COUNT GREATER 1)
+ set(_PYTHON_FIND_MAJ_MIN "${PythonLibs_FIND_VERSION_MAJOR}.${PythonLibs_FIND_VERSION_MINOR}")
+ unset(_PYTHON_FIND_OTHER_VERSIONS)
+ if(PythonLibs_FIND_VERSION_EXACT)
+ if(_PYTHON_FIND_MAJ_MIN STREQUAL PythonLibs_FIND_VERSION)
+ set(_PYTHON_FIND_OTHER_VERSIONS "${PythonLibs_FIND_VERSION}")
+ else()
+ set(_PYTHON_FIND_OTHER_VERSIONS "${PythonLibs_FIND_VERSION}" "${_PYTHON_FIND_MAJ_MIN}")
+ endif()
+ else()
+ foreach(_PYTHON_V ${_PYTHON${PythonLibs_FIND_VERSION_MAJOR}_VERSIONS})
+ if(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN)
+ list(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V})
+ endif()
+ endforeach()
+ endif()
+ unset(_PYTHON_FIND_MAJ_MIN)
+ else()
+ set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonLibs_FIND_VERSION_MAJOR}_VERSIONS})
+ endif()
+else()
+ set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS})
+endif()
+
+# Set up the versions we know about, in the order we will search. Always add
+# the user supplied additional versions to the front.
+# If FindPythonInterp has already found the major and minor version,
+# insert that version between the user supplied versions and the stock
+# version list.
+set(_Python_VERSIONS ${Python_ADDITIONAL_VERSIONS})
+if(DEFINED PYTHON_VERSION_MAJOR AND DEFINED PYTHON_VERSION_MINOR)
+ list(APPEND _Python_VERSIONS ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
+endif()
+list(APPEND _Python_VERSIONS ${_PYTHON_FIND_OTHER_VERSIONS})
+
+unset(_PYTHON_FIND_OTHER_VERSIONS)
+unset(_PYTHON1_VERSIONS)
+unset(_PYTHON2_VERSIONS)
+unset(_PYTHON3_VERSIONS)
+
+foreach(_CURRENT_VERSION ${_Python_VERSIONS})
+ string(REPLACE "." "" _CURRENT_VERSION_NO_DOTS ${_CURRENT_VERSION})
+ if(WIN32)
+ find_library(PYTHON_DEBUG_LIBRARY
+ NAMES python${_CURRENT_VERSION_NO_DOTS}_d python
+ PATHS
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
+ )
+ endif()
+
+ find_library(PYTHON_LIBRARY
+ NAMES
+ python${_CURRENT_VERSION_NO_DOTS}
+ python${_CURRENT_VERSION}mu
+ python${_CURRENT_VERSION}m
+ python${_CURRENT_VERSION}u
+ python${_CURRENT_VERSION}
+ PATHS
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
+ # Avoid finding the .dll in the PATH. We want the .lib.
+ NO_SYSTEM_ENVIRONMENT_PATH
+ )
+ # Look for the static library in the Python config directory
+ find_library(PYTHON_LIBRARY
+ NAMES python${_CURRENT_VERSION_NO_DOTS} python${_CURRENT_VERSION}
+ # Avoid finding the .dll in the PATH. We want the .lib.
+ NO_SYSTEM_ENVIRONMENT_PATH
+ # This is where the static library is usually located
+ PATH_SUFFIXES python${_CURRENT_VERSION}/config
+ )
+
+ # For backward compatibility, honour value of PYTHON_INCLUDE_PATH, if
+ # PYTHON_INCLUDE_DIR is not set.
+ if(DEFINED PYTHON_INCLUDE_PATH AND NOT DEFINED PYTHON_INCLUDE_DIR)
+ set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_PATH}" CACHE PATH
+ "Path to where Python.h is found" FORCE)
+ endif()
+
+ set(PYTHON_FRAMEWORK_INCLUDES)
+ if(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR)
+ foreach(dir ${Python_FRAMEWORKS})
+ set(PYTHON_FRAMEWORK_INCLUDES ${PYTHON_FRAMEWORK_INCLUDES}
+ ${dir}/Versions/${_CURRENT_VERSION}/include/python${_CURRENT_VERSION})
+ endforeach()
+ endif()
+
+ find_path(PYTHON_INCLUDE_DIR
+ NAMES Python.h
+ PATHS
+ ${PYTHON_FRAMEWORK_INCLUDES}
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
+ PATH_SUFFIXES
+ python${_CURRENT_VERSION}mu
+ python${_CURRENT_VERSION}m
+ python${_CURRENT_VERSION}u
+ python${_CURRENT_VERSION}
+ )
+
+ # For backward compatibility, set PYTHON_INCLUDE_PATH.
+ set(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}")
+
+ if(PYTHON_INCLUDE_DIR AND EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h")
+ file(STRINGS "${PYTHON_INCLUDE_DIR}/patchlevel.h" python_version_str
+ REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"")
+ string(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
+ PYTHONLIBS_VERSION_STRING "${python_version_str}")
+ unset(python_version_str)
+ endif()
+
+ if(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR)
+ break()
+ endif()
+endforeach()
+
+mark_as_advanced(
+ PYTHON_DEBUG_LIBRARY
+ PYTHON_LIBRARY
+ PYTHON_INCLUDE_DIR
+)
+
+# We use PYTHON_INCLUDE_DIR, PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the
+# cache entries because they are meant to specify the location of a single
+# library. We now set the variables listed by the documentation for this
+# module.
+set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
+set(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
+
+# These variables have been historically named in this module different from
+# what SELECT_LIBRARY_CONFIGURATIONS() expects.
+set(PYTHON_LIBRARY_DEBUG "${PYTHON_DEBUG_LIBRARY}")
+set(PYTHON_LIBRARY_RELEASE "${PYTHON_LIBRARY}")
+include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+SELECT_LIBRARY_CONFIGURATIONS(PYTHON)
+# SELECT_LIBRARY_CONFIGURATIONS() sets ${PREFIX}_FOUND if it has a library.
+# Unset this, this prefix doesn't match the module prefix, they are different
+# for historical reasons.
+unset(PYTHON_FOUND)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs
+ REQUIRED_VARS PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS
+ VERSION_VAR PYTHONLIBS_VERSION_STRING)
+
+# PYTHON_ADD_MODULE(<name> src1 src2 ... srcN) is used to build modules for python.
+# PYTHON_WRITE_MODULES_HEADER(<filename>) writes a header file you can include
+# in your sources to initialize the static python modules
+function(PYTHON_ADD_MODULE _NAME )
+ get_property(_TARGET_SUPPORTS_SHARED_LIBS
+ GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
+ option(PYTHON_ENABLE_MODULE_${_NAME} "Add module ${_NAME}" TRUE)
+ option(PYTHON_MODULE_${_NAME}_BUILD_SHARED
+ "Add module ${_NAME} shared" ${_TARGET_SUPPORTS_SHARED_LIBS})
+
+ # Mark these options as advanced
+ mark_as_advanced(PYTHON_ENABLE_MODULE_${_NAME}
+ PYTHON_MODULE_${_NAME}_BUILD_SHARED)
+
+ if(PYTHON_ENABLE_MODULE_${_NAME})
+ if(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
+ set(PY_MODULE_TYPE MODULE)
+ else()
+ set(PY_MODULE_TYPE STATIC)
+ set_property(GLOBAL APPEND PROPERTY PY_STATIC_MODULES_LIST ${_NAME})
+ endif()
+
+ set_property(GLOBAL APPEND PROPERTY PY_MODULES_LIST ${_NAME})
+ add_library(${_NAME} ${PY_MODULE_TYPE} ${ARGN})
+# target_link_libraries(${_NAME} ${PYTHON_LIBRARIES})
+
+ if(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
+ set_target_properties(${_NAME} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}")
+ if(WIN32 AND NOT CYGWIN)
+ set_target_properties(${_NAME} PROPERTIES SUFFIX ".pyd")
+ endif()
+ endif()
+
+ endif()
+endfunction()
+
+function(PYTHON_WRITE_MODULES_HEADER _filename)
+
+ get_property(PY_STATIC_MODULES_LIST GLOBAL PROPERTY PY_STATIC_MODULES_LIST)
+
+ get_filename_component(_name "${_filename}" NAME)
+ string(REPLACE "." "_" _name "${_name}")
+ string(TOUPPER ${_name} _nameUpper)
+ set(_filename ${CMAKE_CURRENT_BINARY_DIR}/${_filename})
+
+ set(_filenameTmp "${_filename}.in")
+ file(WRITE ${_filenameTmp} "/*Created by cmake, do not edit, changes will be lost*/\n")
+ file(APPEND ${_filenameTmp}
+"#ifndef ${_nameUpper}
+#define ${_nameUpper}
+
+#include <Python.h>
+
+#ifdef __cplusplus
+extern \"C\" {
+#endif /* __cplusplus */
+
+")
+
+ foreach(_currentModule ${PY_STATIC_MODULES_LIST})
+ file(APPEND ${_filenameTmp} "extern void init${PYTHON_MODULE_PREFIX}${_currentModule}(void);\n\n")
+ endforeach()
+
+ file(APPEND ${_filenameTmp}
+"#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+")
+
+
+ foreach(_currentModule ${PY_STATIC_MODULES_LIST})
+ file(APPEND ${_filenameTmp} "int ${_name}_${_currentModule}(void) \n{\n static char name[]=\"${PYTHON_MODULE_PREFIX}${_currentModule}\"; return PyImport_AppendInittab(name, init${PYTHON_MODULE_PREFIX}${_currentModule});\n}\n\n")
+ endforeach()
+
+ file(APPEND ${_filenameTmp} "void ${_name}_LoadAllPythonModules(void)\n{\n")
+ foreach(_currentModule ${PY_STATIC_MODULES_LIST})
+ file(APPEND ${_filenameTmp} " ${_name}_${_currentModule}();\n")
+ endforeach()
+ file(APPEND ${_filenameTmp} "}\n\n")
+ file(APPEND ${_filenameTmp} "#ifndef EXCLUDE_LOAD_ALL_FUNCTION\nvoid CMakeLoadAllPythonModules(void)\n{\n ${_name}_LoadAllPythonModules();\n}\n#endif\n\n#endif\n")
+
+# with configure_file() cmake complains that you may not use a file created using file(WRITE) as input file for configure_file()
+ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_filenameTmp}" "${_filename}" OUTPUT_QUIET ERROR_QUIET)
+
+endfunction()
diff --git a/Modules/FindQt.cmake b/Modules/FindQt.cmake
new file mode 100644
index 0000000000..1bc0940e16
--- /dev/null
+++ b/Modules/FindQt.cmake
@@ -0,0 +1,188 @@
+#.rst:
+# FindQt
+# ------
+#
+# Searches for all installed versions of Qt.
+#
+# This should only be used if your project can work with multiple
+# versions of Qt. If not, you should just directly use FindQt4 or
+# FindQt3. If multiple versions of Qt are found on the machine, then
+# The user must set the option DESIRED_QT_VERSION to the version they
+# want to use. If only one version of qt is found on the machine, then
+# the DESIRED_QT_VERSION is set to that version and the matching FindQt3
+# or FindQt4 module is included. Once the user sets DESIRED_QT_VERSION,
+# then the FindQt3 or FindQt4 module is included.
+#
+# ::
+#
+# QT_REQUIRED if this is set to TRUE then if CMake can
+# not find Qt4 or Qt3 an error is raised
+# and a message is sent to the user.
+#
+#
+#
+# ::
+#
+# DESIRED_QT_VERSION OPTION is created
+# QT4_INSTALLED is set to TRUE if qt4 is found.
+# QT3_INSTALLED is set to TRUE if qt3 is found.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+# look for signs of qt3 installations
+file(GLOB GLOB_TEMP_VAR /usr/lib*/qt-3*/bin/qmake /usr/lib*/qt3*/bin/qmake)
+if(GLOB_TEMP_VAR)
+ set(QT3_INSTALLED TRUE)
+endif()
+set(GLOB_TEMP_VAR)
+
+file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-3*/bin/qmake)
+if(GLOB_TEMP_VAR)
+ set(QT3_INSTALLED TRUE)
+endif()
+set(GLOB_TEMP_VAR)
+
+file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt3/bin/qmake)
+if(GLOB_TEMP_VAR)
+ set(QT3_INSTALLED TRUE)
+endif()
+set(GLOB_TEMP_VAR)
+
+# look for qt4 installations
+file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
+if(GLOB_TEMP_VAR)
+ set(QT4_INSTALLED TRUE)
+endif()
+set(GLOB_TEMP_VAR)
+
+file(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
+if(GLOB_TEMP_VAR)
+ set(QT4_INSTALLED TRUE)
+endif()
+set(GLOB_TEMP_VAR)
+
+file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt4/bin/qmake)
+if(GLOB_TEMP_VAR)
+ set(QT4_INSTALLED TRUE)
+endif()
+set(GLOB_TEMP_VAR)
+
+if (Qt_FIND_VERSION)
+ set(DESIRED_QT_VERSION "${Qt_FIND_VERSION}")
+endif ()
+
+# now find qmake
+find_program(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin")
+if(QT_QMAKE_EXECUTABLE_FINDQT)
+ exec_program(${QT_QMAKE_EXECUTABLE_FINDQT} ARGS "-query QT_VERSION"
+ OUTPUT_VARIABLE QTVERSION)
+ if(QTVERSION MATCHES "4")
+ set(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt4 qmake program.")
+ set(QT4_INSTALLED TRUE)
+ endif()
+ if(QTVERSION MATCHES "Unknown")
+ set(QT3_INSTALLED TRUE)
+ endif()
+endif()
+
+if(QT_QMAKE_EXECUTABLE_FINDQT)
+ exec_program( ${QT_QMAKE_EXECUTABLE_FINDQT}
+ ARGS "-query QT_INSTALL_HEADERS"
+ OUTPUT_VARIABLE qt_headers )
+endif()
+
+find_file( QT4_QGLOBAL_H_FILE qglobal.h
+ "${QT_SEARCH_PATH}/Qt/include"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/include/Qt"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/include/Qt"
+ ${qt_headers}/Qt
+ $ENV{QTDIR}/include/Qt
+ /usr/local/qt/include/Qt
+ /usr/local/include/Qt
+ /usr/lib/qt/include/Qt
+ /usr/include/Qt
+ /usr/share/qt4/include/Qt
+ /usr/local/include/X11/qt4/Qt
+ C:/Progra~1/qt/include/Qt )
+
+if(QT4_QGLOBAL_H_FILE)
+ set(QT4_INSTALLED TRUE)
+endif()
+
+find_file( QT3_QGLOBAL_H_FILE qglobal.h
+ "${QT_SEARCH_PATH}/Qt/include"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
+ C:/Qt/3.3.3Educational/include
+ $ENV{QTDIR}/include
+ /usr/include/qt3/Qt
+ /usr/local/qt/include
+ /usr/local/include
+ /usr/lib/qt/include
+ /usr/include
+ /usr/share/qt3/include
+ /usr/local/include/X11/qt3
+ C:/Progra~1/qt/include
+ /usr/include/qt3 )
+
+if(QT3_QGLOBAL_H_FILE)
+ set(QT3_INSTALLED TRUE)
+endif()
+
+if(QT3_INSTALLED AND QT4_INSTALLED AND NOT DESIRED_QT_VERSION)
+ # force user to pick if we have both
+ set(DESIRED_QT_VERSION 0 CACHE STRING "Pick a version of Qt to use: 3 or 4")
+else()
+ # if only one found then pick that one
+ if(QT3_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 4)
+ set(DESIRED_QT_VERSION 3 CACHE STRING "Pick a version of Qt to use: 3 or 4")
+ endif()
+ if(QT4_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 3)
+ set(DESIRED_QT_VERSION 4 CACHE STRING "Pick a version of Qt to use: 3 or 4")
+ endif()
+endif()
+
+if(DESIRED_QT_VERSION EQUAL 3)
+ set(Qt3_FIND_REQUIRED ${Qt_FIND_REQUIRED})
+ set(Qt3_FIND_QUIETLY ${Qt_FIND_QUIETLY})
+ include(${CMAKE_CURRENT_LIST_DIR}/FindQt3.cmake)
+endif()
+if(DESIRED_QT_VERSION EQUAL 4)
+ set(Qt4_FIND_REQUIRED ${Qt_FIND_REQUIRED})
+ set(Qt4_FIND_QUIETLY ${Qt_FIND_QUIETLY})
+ include(${CMAKE_CURRENT_LIST_DIR}/FindQt4.cmake)
+endif()
+
+if(NOT QT3_INSTALLED AND NOT QT4_INSTALLED)
+ if(QT_REQUIRED)
+ message(SEND_ERROR "CMake was unable to find any Qt versions, put qmake in your path, or set QT_QMAKE_EXECUTABLE.")
+ endif()
+else()
+ if(NOT QT_FOUND AND NOT DESIRED_QT_VERSION)
+ if(QT_REQUIRED)
+ message(SEND_ERROR "Multiple versions of Qt found please set DESIRED_QT_VERSION")
+ else()
+ message("Multiple versions of Qt found please set DESIRED_QT_VERSION")
+ endif()
+ endif()
+ if(NOT QT_FOUND AND DESIRED_QT_VERSION)
+ if(QT_REQUIRED)
+ message(FATAL_ERROR "CMake was unable to find Qt version: ${DESIRED_QT_VERSION}. Set advanced values QT_QMAKE_EXECUTABLE and QT${DESIRED_QT_VERSION}_QGLOBAL_FILE, if those are set then QT_QT_LIBRARY or QT_LIBRARY_DIR.")
+ else()
+ message( "CMake was unable to find desired Qt version: ${DESIRED_QT_VERSION}. Set advanced values QT_QMAKE_EXECUTABLE and QT${DESIRED_QT_VERSION}_QGLOBAL_FILE.")
+ endif()
+ endif()
+endif()
+mark_as_advanced(QT3_QGLOBAL_H_FILE QT4_QGLOBAL_H_FILE QT_QMAKE_EXECUTABLE_FINDQT)
diff --git a/Modules/FindQt3.cmake b/Modules/FindQt3.cmake
new file mode 100644
index 0000000000..86997ba305
--- /dev/null
+++ b/Modules/FindQt3.cmake
@@ -0,0 +1,326 @@
+#.rst:
+# FindQt3
+# -------
+#
+# Locate Qt include paths and libraries
+#
+# This module defines:
+#
+# ::
+#
+# QT_INCLUDE_DIR - where to find qt.h, etc.
+# QT_LIBRARIES - the libraries to link against to use Qt.
+# QT_DEFINITIONS - definitions to use when
+# compiling code that uses Qt.
+# QT_FOUND - If false, don't try to use Qt.
+# QT_VERSION_STRING - the version of Qt found
+#
+#
+#
+# If you need the multithreaded version of Qt, set QT_MT_REQUIRED to
+# TRUE
+#
+# Also defined, but not for general use are:
+#
+# ::
+#
+# QT_MOC_EXECUTABLE, where to find the moc tool.
+# QT_UIC_EXECUTABLE, where to find the uic tool.
+# QT_QT_LIBRARY, where to find the Qt library.
+# QT_QTMAIN_LIBRARY, where to find the qtmain
+# library. This is only required by Qt3 on Windows.
+
+# These are around for backwards compatibility
+# they will be set
+# QT_WRAP_CPP, set true if QT_MOC_EXECUTABLE is found
+# QT_WRAP_UI set true if QT_UIC_EXECUTABLE is found
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+# If Qt4 has already been found, fail.
+if(QT4_FOUND)
+ if(Qt3_FIND_REQUIRED)
+ message( FATAL_ERROR "Qt3 and Qt4 cannot be used together in one project.")
+ else()
+ if(NOT Qt3_FIND_QUIETLY)
+ message( STATUS "Qt3 and Qt4 cannot be used together in one project.")
+ endif()
+ return()
+ endif()
+endif()
+
+
+file(GLOB GLOB_PATHS /usr/lib/qt-3*)
+foreach(GLOB_PATH ${GLOB_PATHS})
+ list(APPEND GLOB_PATHS_BIN "${GLOB_PATH}/bin")
+endforeach()
+find_path(QT_INCLUDE_DIR qt.h
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
+ $ENV{QTDIR}/include
+ ${GLOB_PATHS}
+ /usr/local/qt/include
+ /usr/lib/qt/include
+ /usr/lib/qt3/include
+ /usr/include/qt
+ /usr/share/qt3/include
+ C:/Progra~1/qt/include
+ /usr/include/qt3
+ /usr/local/include/X11/qt3
+ )
+
+# if qglobal.h is not in the qt_include_dir then set
+# QT_INCLUDE_DIR to NOTFOUND
+if(NOT EXISTS ${QT_INCLUDE_DIR}/qglobal.h)
+ set(QT_INCLUDE_DIR QT_INCLUDE_DIR-NOTFOUND CACHE PATH "path to Qt3 include directory" FORCE)
+endif()
+
+if(QT_INCLUDE_DIR)
+ #extract the version string from qglobal.h
+ file(STRINGS ${QT_INCLUDE_DIR}/qglobal.h QGLOBAL_H REGEX "#define[\t ]+QT_VERSION_STR[\t ]+\"[0-9]+.[0-9]+.[0-9]+[a-z]*\"")
+ string(REGEX REPLACE ".*\"([0-9]+.[0-9]+.[0-9]+[a-z]*)\".*" "\\1" qt_version_str "${QGLOBAL_H}")
+ unset(QGLOBAL_H)
+
+ # Under windows the qt library (MSVC) has the format qt-mtXYZ where XYZ is the
+ # version X.Y.Z, so we need to remove the dots from version
+ string(REGEX REPLACE "\\." "" qt_version_str_lib "${qt_version_str}")
+ set(QT_VERSION_STRING "${qt_version_str}")
+endif()
+
+file(GLOB GLOB_PATHS_LIB /usr/lib/qt-3*/lib/)
+if (QT_MT_REQUIRED)
+ find_library(QT_QT_LIBRARY
+ NAMES
+ qt-mt qt-mt${qt_version_str_lib} qt-mtnc${qt_version_str_lib}
+ qt-mtedu${qt_version_str_lib} qt-mt230nc qt-mtnc321 qt-mt3
+ PATHS
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
+ ENV QTDIR
+ ${GLOB_PATHS_LIB}
+ /usr/local/qt
+ /usr/lib/qt
+ /usr/lib/qt3
+ /usr/share/qt3
+ C:/Progra~1/qt
+ PATH_SUFFIXES
+ lib
+ )
+
+else ()
+ find_library(QT_QT_LIBRARY
+ NAMES
+ qt qt-${qt_version_str_lib} qt-edu${qt_version_str_lib}
+ qt-mt qt-mt${qt_version_str_lib} qt-mtnc${qt_version_str_lib}
+ qt-mtedu${qt_version_str_lib} qt-mt230nc qt-mtnc321 qt-mt3
+ PATHS
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
+ ENV QTDIR
+ ${GLOB_PATHS_LIB}
+ /usr/local/qt
+ /usr/lib/qt
+ /usr/lib/qt3
+ /usr/share/qt3
+ C:/Progra~1/qt/lib
+ PATH_SUFFIXES
+ lib
+ )
+endif ()
+
+
+find_library(QT_QASSISTANTCLIENT_LIBRARY
+ NAMES qassistantclient
+ PATHS
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
+ ENV QTDIR
+ ${GLOB_PATHS_LIB}
+ /usr/local/qt
+ /usr/lib/qt3
+ /usr/share/qt3
+ C:/Progra~1/qt
+ PATH_SUFFIXES
+ lib
+ )
+
+# Qt 3 should prefer QTDIR over the PATH
+find_program(QT_MOC_EXECUTABLE
+ NAMES moc-qt3 moc3 moc3-mt moc
+ HINTS
+ ENV QTDIR
+ PATHS
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
+ ${GLOB_PATHS_BIN}
+ /usr/local/lib/qt3
+ /usr/local/qt
+ /usr/lib/qt
+ /usr/lib/qt3
+ /usr/share/qt3
+ C:/Progra~1/qt
+ /usr/X11R6
+ PATH_SUFFIXES
+ bin
+ )
+
+if(QT_MOC_EXECUTABLE)
+ set ( QT_WRAP_CPP "YES")
+endif()
+
+# Qt 3 should prefer QTDIR over the PATH
+find_program(QT_UIC_EXECUTABLE
+ NAMES uic-qt3 uic3 uic3-mt uic
+ HINTS
+ ENV QTDIR
+ PATHS
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
+ ${GLOB_PATHS_BIN}
+ /usr/local/qt
+ /usr/lib/qt
+ /usr/lib/qt3
+ /usr/share/qt3
+ C:/Progra~1/qt
+ /usr/X11R6
+ PATH_SUFFIXES
+ bin
+ )
+
+if(QT_UIC_EXECUTABLE)
+ set ( QT_WRAP_UI "YES")
+endif()
+
+if (WIN32)
+ find_library(QT_QTMAIN_LIBRARY qtmain
+ HINTS
+ ENV QTDIR
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
+ PATHS
+ "$ENV{ProgramFiles}/qt"
+ "C:/Program Files/qt"
+ PATH_SUFFIXES
+ lib
+ DOC "This Library is only needed by and included with Qt3 on MSWindows. It should be NOTFOUND, undefined or IGNORE otherwise."
+ )
+endif ()
+
+#support old QT_MIN_VERSION if set, but not if version is supplied by find_package()
+if(NOT Qt3_FIND_VERSION AND QT_MIN_VERSION)
+ set(Qt3_FIND_VERSION ${QT_MIN_VERSION})
+endif()
+
+# if the include a library are found then we have it
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Qt3
+ REQUIRED_VARS QT_QT_LIBRARY QT_INCLUDE_DIR QT_MOC_EXECUTABLE
+ VERSION_VAR QT_VERSION_STRING)
+set(QT_FOUND ${QT3_FOUND} )
+
+if(QT_FOUND)
+ set( QT_LIBRARIES ${QT_LIBRARIES} ${QT_QT_LIBRARY} )
+ set( QT_DEFINITIONS "")
+
+ if (WIN32 AND NOT CYGWIN)
+ if (QT_QTMAIN_LIBRARY)
+ # for version 3
+ set (QT_DEFINITIONS -DQT_DLL -DQT_THREAD_SUPPORT -DNO_DEBUG)
+ set (QT_LIBRARIES imm32.lib ${QT_QT_LIBRARY} ${QT_QTMAIN_LIBRARY} )
+ set (QT_LIBRARIES ${QT_LIBRARIES} winmm wsock32)
+ else ()
+ # for version 2
+ set (QT_LIBRARIES imm32.lib ws2_32.lib ${QT_QT_LIBRARY} )
+ endif ()
+ else ()
+ set (QT_LIBRARIES ${QT_QT_LIBRARY} )
+
+ set (QT_DEFINITIONS -DQT_SHARED -DQT_NO_DEBUG)
+ if(QT_QT_LIBRARY MATCHES "qt-mt")
+ set (QT_DEFINITIONS ${QT_DEFINITIONS} -DQT_THREAD_SUPPORT -D_REENTRANT)
+ endif()
+
+ endif ()
+
+ if (QT_QASSISTANTCLIENT_LIBRARY)
+ set (QT_LIBRARIES ${QT_QASSISTANTCLIENT_LIBRARY} ${QT_LIBRARIES})
+ endif ()
+
+ # Backwards compatibility for CMake1.4 and 1.2
+ set (QT_MOC_EXE ${QT_MOC_EXECUTABLE} )
+ set (QT_UIC_EXE ${QT_UIC_EXECUTABLE} )
+ # for unix add X11 stuff
+ if(UNIX)
+ find_package(X11)
+ if (X11_FOUND)
+ set (QT_LIBRARIES ${QT_LIBRARIES} ${X11_LIBRARIES})
+ endif ()
+ if (CMAKE_DL_LIBS)
+ set (QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_DL_LIBS})
+ endif ()
+ endif()
+ if(QT_QT_LIBRARY MATCHES "qt-mt")
+ find_package(Threads)
+ set(QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+ endif()
+endif()
+
+if(QT_MOC_EXECUTABLE)
+ execute_process(COMMAND ${QT_MOC_EXECUTABLE} "-v"
+ OUTPUT_VARIABLE QTVERSION_MOC
+ ERROR_QUIET)
+endif()
+if(QT_UIC_EXECUTABLE)
+ execute_process(COMMAND ${QT_UIC_EXECUTABLE} "-version"
+ OUTPUT_VARIABLE QTVERSION_UIC
+ ERROR_QUIET)
+endif()
+
+set(_QT_UIC_VERSION_3 FALSE)
+if("${QTVERSION_UIC}" MATCHES " 3.")
+ set(_QT_UIC_VERSION_3 TRUE)
+endif()
+
+set(_QT_MOC_VERSION_3 FALSE)
+if("${QTVERSION_MOC}" MATCHES " 3.")
+ set(_QT_MOC_VERSION_3 TRUE)
+endif()
+
+set(QT_WRAP_CPP FALSE)
+if (QT_MOC_EXECUTABLE AND _QT_MOC_VERSION_3)
+ set ( QT_WRAP_CPP TRUE)
+endif ()
+
+set(QT_WRAP_UI FALSE)
+if (QT_UIC_EXECUTABLE AND _QT_UIC_VERSION_3)
+ set ( QT_WRAP_UI TRUE)
+endif ()
+
+mark_as_advanced(
+ QT_INCLUDE_DIR
+ QT_QT_LIBRARY
+ QT_QTMAIN_LIBRARY
+ QT_QASSISTANTCLIENT_LIBRARY
+ QT_UIC_EXECUTABLE
+ QT_MOC_EXECUTABLE
+ QT_WRAP_CPP
+ QT_WRAP_UI
+ )
diff --git a/Modules/FindQt4.cmake b/Modules/FindQt4.cmake
new file mode 100644
index 0000000000..06a891748f
--- /dev/null
+++ b/Modules/FindQt4.cmake
@@ -0,0 +1,1343 @@
+#.rst:
+# FindQt4
+# -------
+#
+# Finding and Using Qt4
+# ^^^^^^^^^^^^^^^^^^^^^
+#
+# This module can be used to find Qt4. The most important issue is that
+# the Qt4 qmake is available via the system path. This qmake is then
+# used to detect basically everything else. This module defines a
+# number of :prop_tgt:`IMPORTED` targets, macros and variables.
+#
+# Typical usage could be something like:
+#
+# .. code-block:: cmake
+#
+# set(CMAKE_AUTOMOC ON)
+# set(CMAKE_INCLUDE_CURRENT_DIR ON)
+# find_package(Qt4 4.4.3 REQUIRED QtGui QtXml)
+# add_executable(myexe main.cpp)
+# target_link_libraries(myexe Qt4::QtGui Qt4::QtXml)
+#
+# .. note::
+#
+# When using :prop_tgt:`IMPORTED` targets, the qtmain.lib static library is
+# automatically linked on Windows for :variable:`WIN32 <WIN32_EXECUTABLE>`
+# executables. To disable that globally, set the
+# ``QT4_NO_LINK_QTMAIN`` variable before finding Qt4. To disable that
+# for a particular executable, set the ``QT4_NO_LINK_QTMAIN`` target
+# property to ``TRUE`` on the executable.
+#
+# Qt Build Tools
+# ^^^^^^^^^^^^^^
+#
+# Qt relies on some bundled tools for code generation, such as ``moc`` for
+# meta-object code generation,``uic`` for widget layout and population,
+# and ``rcc`` for virtual filesystem content generation. These tools may be
+# automatically invoked by :manual:`cmake(1)` if the appropriate conditions
+# are met. See :manual:`cmake-qt(7)` for more.
+#
+# Qt Macros
+# ^^^^^^^^^
+#
+# In some cases it can be necessary or useful to invoke the Qt build tools in a
+# more-manual way. Several macros are available to add targets for such uses.
+#
+# ::
+#
+# macro QT4_WRAP_CPP(outfiles inputfile ... [TARGET tgt] OPTIONS ...)
+# create moc code from a list of files containing Qt class with
+# the Q_OBJECT declaration. Per-directory preprocessor definitions
+# are also added. If the <tgt> is specified, the
+# INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_COMPILE_DEFINITIONS from
+# the <tgt> are passed to moc. Options may be given to moc, such as
+# those found when executing "moc -help".
+#
+#
+# ::
+#
+# macro QT4_WRAP_UI(outfiles inputfile ... OPTIONS ...)
+# create code from a list of Qt designer ui files.
+# Options may be given to uic, such as those found
+# when executing "uic -help"
+#
+#
+# ::
+#
+# macro QT4_ADD_RESOURCES(outfiles inputfile ... OPTIONS ...)
+# create code from a list of Qt resource files.
+# Options may be given to rcc, such as those found
+# when executing "rcc -help"
+#
+#
+# ::
+#
+# macro QT4_GENERATE_MOC(inputfile outputfile [TARGET tgt])
+# creates a rule to run moc on infile and create outfile.
+# Use this if for some reason QT4_WRAP_CPP() isn't appropriate, e.g.
+# because you need a custom filename for the moc file or something
+# similar. If the <tgt> is specified, the
+# INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_COMPILE_DEFINITIONS from
+# the <tgt> are passed to moc.
+#
+#
+# ::
+#
+# macro QT4_ADD_DBUS_INTERFACE(outfiles interface basename)
+# Create the interface header and implementation files with the
+# given basename from the given interface xml file and add it to
+# the list of sources.
+#
+# You can pass additional parameters to the qdbusxml2cpp call by setting
+# properties on the input file:
+#
+# INCLUDE the given file will be included in the generate interface header
+#
+# CLASSNAME the generated class is named accordingly
+#
+# NO_NAMESPACE the generated class is not wrapped in a namespace
+#
+#
+# ::
+#
+# macro QT4_ADD_DBUS_INTERFACES(outfiles inputfile ... )
+# Create the interface header and implementation files
+# for all listed interface xml files.
+# The basename will be automatically determined from the name of the xml file.
+#
+# The source file properties described for QT4_ADD_DBUS_INTERFACE also apply here.
+#
+#
+# ::
+#
+# macro QT4_ADD_DBUS_ADAPTOR(outfiles xmlfile parentheader parentclassname [basename] [classname])
+# create a dbus adaptor (header and implementation file) from the xml file
+# describing the interface, and add it to the list of sources. The adaptor
+# forwards the calls to a parent class, defined in parentheader and named
+# parentclassname. The name of the generated files will be
+# <basename>adaptor.{cpp,h} where basename defaults to the basename of the xml file.
+# If <classname> is provided, then it will be used as the classname of the
+# adaptor itself.
+#
+#
+# ::
+#
+# macro QT4_GENERATE_DBUS_INTERFACE( header [interfacename] OPTIONS ...)
+# generate the xml interface file from the given header.
+# If the optional argument interfacename is omitted, the name of the
+# interface file is constructed from the basename of the header with
+# the suffix .xml appended.
+# Options may be given to qdbuscpp2xml, such as those found when executing "qdbuscpp2xml --help"
+#
+#
+# ::
+#
+# macro QT4_CREATE_TRANSLATION( qm_files directories ... sources ...
+# ts_files ... OPTIONS ...)
+# out: qm_files
+# in: directories sources ts_files
+# options: flags to pass to lupdate, such as -extensions to specify
+# extensions for a directory scan.
+# generates commands to create .ts (vie lupdate) and .qm
+# (via lrelease) - files from directories and/or sources. The ts files are
+# created and/or updated in the source tree (unless given with full paths).
+# The qm files are generated in the build tree.
+# Updating the translations can be done by adding the qm_files
+# to the source list of your library/executable, so they are
+# always updated, or by adding a custom target to control when
+# they get updated/generated.
+#
+#
+# ::
+#
+# macro QT4_ADD_TRANSLATION( qm_files ts_files ... )
+# out: qm_files
+# in: ts_files
+# generates commands to create .qm from .ts - files. The generated
+# filenames can be found in qm_files. The ts_files
+# must exist and are not updated in any way.
+#
+#
+# ::
+#
+# macro QT4_AUTOMOC(sourcefile1 sourcefile2 ... [TARGET tgt])
+# The qt4_automoc macro is obsolete. Use the CMAKE_AUTOMOC feature instead.
+# This macro is still experimental.
+# It can be used to have moc automatically handled.
+# So if you have the files foo.h and foo.cpp, and in foo.h a
+# a class uses the Q_OBJECT macro, moc has to run on it. If you don't
+# want to use QT4_WRAP_CPP() (which is reliable and mature), you can insert
+# #include "foo.moc"
+# in foo.cpp and then give foo.cpp as argument to QT4_AUTOMOC(). This will the
+# scan all listed files at cmake-time for such included moc files and if it finds
+# them cause a rule to be generated to run moc at build time on the
+# accompanying header file foo.h.
+# If a source file has the SKIP_AUTOMOC property set it will be ignored by this macro.
+# If the <tgt> is specified, the INTERFACE_INCLUDE_DIRECTORIES and
+# INTERFACE_COMPILE_DEFINITIONS from the <tgt> are passed to moc.
+#
+#
+# ::
+#
+# function QT4_USE_MODULES( target [link_type] modules...)
+# This function is obsolete. Use target_link_libraries with IMPORTED targets instead.
+# Make <target> use the <modules> from Qt. Using a Qt module means
+# to link to the library, add the relevant include directories for the module,
+# and add the relevant compiler defines for using the module.
+# Modules are roughly equivalent to components of Qt4, so usage would be
+# something like:
+# qt4_use_modules(myexe Core Gui Declarative)
+# to use QtCore, QtGui and QtDeclarative. The optional <link_type> argument can
+# be specified as either LINK_PUBLIC or LINK_PRIVATE to specify the same argument
+# to the target_link_libraries call.
+#
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# A particular Qt library may be used by using the corresponding
+# :prop_tgt:`IMPORTED` target with the :command:`target_link_libraries`
+# command:
+#
+# .. code-block:: cmake
+#
+# target_link_libraries(myexe Qt4::QtGui Qt4::QtXml)
+#
+# Using a target in this way causes :cmake(1)` to use the appropriate include
+# directories and compile definitions for the target when compiling ``myexe``.
+#
+# Targets are aware of their dependencies, so for example it is not necessary
+# to list ``Qt4::QtCore`` if another Qt library is listed, and it is not
+# necessary to list ``Qt4::QtGui`` if ``Qt4::QtDeclarative`` is listed.
+# Targets may be tested for existence in the usual way with the
+# :command:`if(TARGET)` command.
+#
+# The Qt toolkit may contain both debug and release libraries.
+# :manual:`cmake(1)` will choose the appropriate version based on the build
+# configuration.
+#
+# ``Qt4::QtCore``
+# The QtCore target
+# ``Qt4::QtGui``
+# The QtGui target
+# ``Qt4::Qt3Support``
+# The Qt3Support target
+# ``Qt4::QtAssistant``
+# The QtAssistant target
+# ``Qt4::QtAssistantClient``
+# The QtAssistantClient target
+# ``Qt4::QAxContainer``
+# The QAxContainer target (Windows only)
+# ``Qt4::QAxServer``
+# The QAxServer target (Windows only)
+# ``Qt4::QtDBus``
+# The QtDBus target
+# ``Qt4::QtDesigner``
+# The QtDesigner target
+# ``Qt4::QtDesignerComponents``
+# The QtDesignerComponents target
+# ``Qt4::QtHelp``
+# The QtHelp target
+# ``Qt4::QtMotif``
+# The QtMotif target
+# ``Qt4::QtMultimedia``
+# The QtMultimedia target
+# ``Qt4::QtNetwork``
+# The QtNetwork target
+# ``Qt4::QtNsPLugin``
+# The QtNsPLugin target
+# ``Qt4::QtOpenGL``
+# The QtOpenGL target
+# ``Qt4::QtScript``
+# The QtScript target
+# ``Qt4::QtScriptTools``
+# The QtScriptTools target
+# ``Qt4::QtSql``
+# The QtSql target
+# ``Qt4::QtSvg``
+# The QtSvg target
+# ``Qt4::QtTest``
+# The QtTest target
+# ``Qt4::QtUiTools``
+# The QtUiTools target
+# ``Qt4::QtWebKit``
+# The QtWebKit target
+# ``Qt4::QtXml``
+# The QtXml target
+# ``Qt4::QtXmlPatterns``
+# The QtXmlPatterns target
+# ``Qt4::phonon``
+# The phonon target
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# Below is a detailed list of variables that FindQt4.cmake sets.
+#
+# ``Qt4_FOUND``
+# If false, don't try to use Qt 4.
+# ``QT_FOUND``
+# If false, don't try to use Qt. This variable is for compatibility only.
+# ``QT4_FOUND``
+# If false, don't try to use Qt 4. This variable is for compatibility only.
+# ``QT_VERSION_MAJOR``
+# The major version of Qt found.
+# ``QT_VERSION_MINOR``
+# The minor version of Qt found.
+# ``QT_VERSION_PATCH``
+# The patch version of Qt found.
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+# Use find_package( Qt4 COMPONENTS ... ) to enable modules
+if( Qt4_FIND_COMPONENTS )
+ foreach( component ${Qt4_FIND_COMPONENTS} )
+ string( TOUPPER ${component} _COMPONENT )
+ set( QT_USE_${_COMPONENT} 1 )
+ endforeach()
+
+ # To make sure we don't use QtCore or QtGui when not in COMPONENTS
+ if(NOT QT_USE_QTCORE)
+ set( QT_DONT_USE_QTCORE 1 )
+ endif()
+
+ if(NOT QT_USE_QTGUI)
+ set( QT_DONT_USE_QTGUI 1 )
+ endif()
+
+endif()
+
+# If Qt3 has already been found, fail.
+if(QT_QT_LIBRARY)
+ if(Qt4_FIND_REQUIRED)
+ message( FATAL_ERROR "Qt3 and Qt4 cannot be used together in one project. If switching to Qt4, the CMakeCache.txt needs to be cleaned.")
+ else()
+ if(NOT Qt4_FIND_QUIETLY)
+ message( STATUS "Qt3 and Qt4 cannot be used together in one project. If switching to Qt4, the CMakeCache.txt needs to be cleaned.")
+ endif()
+ return()
+ endif()
+endif()
+
+
+include(${CMAKE_CURRENT_LIST_DIR}/CheckCXXSymbolExists.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/MacroAddFileDependencies.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
+
+set(QT_USE_FILE ${CMAKE_ROOT}/Modules/UseQt4.cmake)
+
+set( QT_DEFINITIONS "")
+
+# convenience macro for dealing with debug/release library names
+macro (_QT4_ADJUST_LIB_VARS _camelCaseBasename)
+
+ string(TOUPPER "${_camelCaseBasename}" basename)
+
+ # The name of the imported targets, i.e. the prefix "Qt4::" must not change,
+ # since it is stored in EXPORT-files as name of a required library. If the name would change
+ # here, this would lead to the imported Qt4-library targets not being resolved by cmake anymore.
+ if (QT_${basename}_LIBRARY_RELEASE OR QT_${basename}_LIBRARY_DEBUG)
+
+ if(NOT TARGET Qt4::${_camelCaseBasename})
+ add_library(Qt4::${_camelCaseBasename} UNKNOWN IMPORTED )
+
+ if (QT_${basename}_LIBRARY_RELEASE)
+ set_property(TARGET Qt4::${_camelCaseBasename} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+ if(QT_USE_FRAMEWORKS)
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_RELEASE "${QT_${basename}_LIBRARY_RELEASE}/${_camelCaseBasename}" )
+ else()
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_RELEASE "${QT_${basename}_LIBRARY_RELEASE}" )
+ endif()
+ endif ()
+
+ if (QT_${basename}_LIBRARY_DEBUG)
+ set_property(TARGET Qt4::${_camelCaseBasename} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+ if(QT_USE_FRAMEWORKS)
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_DEBUG "${QT_${basename}_LIBRARY_DEBUG}/${_camelCaseBasename}" )
+ else()
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_DEBUG "${QT_${basename}_LIBRARY_DEBUG}" )
+ endif()
+ endif ()
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES
+ "${QT_${basename}_INCLUDE_DIR}"
+ )
+ string(REGEX REPLACE "^QT" "" _stemname ${basename})
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY
+ INTERFACE_COMPILE_DEFINITIONS
+ "QT_${_stemname}_LIB"
+ )
+ endif()
+
+ # If QT_USE_IMPORTED_TARGETS is enabled, the QT_QTFOO_LIBRARY variables are set to point at these
+ # imported targets. This works better in general, and is also in almost all cases fully
+ # backward compatible. The only issue is when a project A which had this enabled then exports its
+ # libraries via export or export_library_dependencies(). In this case the libraries from project
+ # A will depend on the imported Qt targets, and the names of these imported targets will be stored
+ # in the dependency files on disk. This means when a project B then uses project A, these imported
+ # targets must be created again, otherwise e.g. "Qt4__QtCore" will be interpreted as name of a
+ # library file on disk, and not as a target, and linking will fail:
+ if(QT_USE_IMPORTED_TARGETS)
+ set(QT_${basename}_LIBRARY Qt4::${_camelCaseBasename} )
+ set(QT_${basename}_LIBRARIES Qt4::${_camelCaseBasename} )
+ else()
+
+ # if the release- as well as the debug-version of the library have been found:
+ if (QT_${basename}_LIBRARY_DEBUG AND QT_${basename}_LIBRARY_RELEASE)
+ # if the generator supports configuration types then set
+ # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
+ if (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
+ set(QT_${basename}_LIBRARY optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG})
+ else()
+ # if there are no configuration types and CMAKE_BUILD_TYPE has no value
+ # then just use the release libraries
+ set(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_RELEASE} )
+ endif()
+ set(QT_${basename}_LIBRARIES optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG})
+ endif ()
+
+ # if only the release version was found, set the debug variable also to the release version
+ if (QT_${basename}_LIBRARY_RELEASE AND NOT QT_${basename}_LIBRARY_DEBUG)
+ set(QT_${basename}_LIBRARY_DEBUG ${QT_${basename}_LIBRARY_RELEASE})
+ set(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_RELEASE})
+ set(QT_${basename}_LIBRARIES ${QT_${basename}_LIBRARY_RELEASE})
+ endif ()
+
+ # if only the debug version was found, set the release variable also to the debug version
+ if (QT_${basename}_LIBRARY_DEBUG AND NOT QT_${basename}_LIBRARY_RELEASE)
+ set(QT_${basename}_LIBRARY_RELEASE ${QT_${basename}_LIBRARY_DEBUG})
+ set(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_DEBUG})
+ set(QT_${basename}_LIBRARIES ${QT_${basename}_LIBRARY_DEBUG})
+ endif ()
+
+ # put the value in the cache:
+ set(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY} CACHE STRING "The Qt ${basename} library" FORCE)
+
+ endif()
+
+ set(QT_${basename}_FOUND 1)
+
+ else ()
+
+ set(QT_${basename}_LIBRARY "" CACHE STRING "The Qt ${basename} library" FORCE)
+
+ endif ()
+
+ if (QT_${basename}_INCLUDE_DIR)
+ #add the include directory to QT_INCLUDES
+ set(QT_INCLUDES "${QT_${basename}_INCLUDE_DIR}" ${QT_INCLUDES})
+ endif ()
+
+ # Make variables changeable to the advanced user
+ mark_as_advanced(QT_${basename}_LIBRARY QT_${basename}_LIBRARY_RELEASE QT_${basename}_LIBRARY_DEBUG QT_${basename}_INCLUDE_DIR)
+endmacro ()
+
+function(_QT4_QUERY_QMAKE VAR RESULT)
+ execute_process(COMMAND "${QT_QMAKE_EXECUTABLE}" -query ${VAR}
+ RESULT_VARIABLE return_code
+ OUTPUT_VARIABLE output
+ OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
+ if(NOT return_code)
+ file(TO_CMAKE_PATH "${output}" output)
+ set(${RESULT} ${output} PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(_QT4_GET_VERSION_COMPONENTS VERSION RESULT_MAJOR RESULT_MINOR RESULT_PATCH)
+ string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" QT_VERSION_MAJOR "${QTVERSION}")
+ string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" QT_VERSION_MINOR "${QTVERSION}")
+ string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" QT_VERSION_PATCH "${QTVERSION}")
+
+ set(${RESULT_MAJOR} ${QT_VERSION_MAJOR} PARENT_SCOPE)
+ set(${RESULT_MINOR} ${QT_VERSION_MINOR} PARENT_SCOPE)
+ set(${RESULT_PATCH} ${QT_VERSION_PATCH} PARENT_SCOPE)
+endfunction()
+
+function(_QT4_FIND_QMAKE QMAKE_NAMES QMAKE_RESULT VERSION_RESULT)
+ list(LENGTH QMAKE_NAMES QMAKE_NAMES_LEN)
+ if(${QMAKE_NAMES_LEN} EQUAL 0)
+ return()
+ endif()
+ list(GET QMAKE_NAMES 0 QMAKE_NAME)
+
+ get_filename_component(qt_install_version "[HKEY_CURRENT_USER\\Software\\trolltech\\Versions;DefaultQtVersion]" NAME)
+
+ find_program(QT_QMAKE_EXECUTABLE NAMES ${QMAKE_NAME}
+ PATHS
+ ENV QTDIR
+ "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\${qt_install_version};InstallDir]"
+ PATH_SUFFIXES bin
+ DOC "The qmake executable for the Qt installation to use"
+ )
+
+ set(major 0)
+ if (QT_QMAKE_EXECUTABLE)
+ _qt4_query_qmake(QT_VERSION QTVERSION)
+ _qt4_get_version_components("${QTVERSION}" major minor patch)
+ endif()
+
+ if (NOT QT_QMAKE_EXECUTABLE OR NOT "${major}" EQUAL 4)
+ set(curr_qmake "${QT_QMAKE_EXECUTABLE}")
+ set(curr_qt_version "${QTVERSION}")
+
+ set(QT_QMAKE_EXECUTABLE NOTFOUND CACHE FILEPATH "" FORCE)
+ list(REMOVE_AT QMAKE_NAMES 0)
+ _qt4_find_qmake("${QMAKE_NAMES}" QMAKE QTVERSION)
+
+ _qt4_get_version_components("${QTVERSION}" major minor patch)
+ if (NOT ${major} EQUAL 4)
+ # Restore possibly found qmake and it's version; these are used later
+ # in error message if incorrect version is found
+ set(QT_QMAKE_EXECUTABLE "${curr_qmake}" CACHE FILEPATH "" FORCE)
+ set(QTVERSION "${curr_qt_version}")
+ endif()
+
+ endif()
+
+
+ set(${QMAKE_RESULT} "${QT_QMAKE_EXECUTABLE}" PARENT_SCOPE)
+ set(${VERSION_RESULT} "${QTVERSION}" PARENT_SCOPE)
+endfunction()
+
+
+set(QT4_INSTALLED_VERSION_TOO_OLD FALSE)
+
+set(_QT4_QMAKE_NAMES qmake qmake4 qmake-qt4 qmake-mac)
+_qt4_find_qmake("${_QT4_QMAKE_NAMES}" QT_QMAKE_EXECUTABLE QTVERSION)
+
+if (QT_QMAKE_EXECUTABLE AND
+ QTVERSION VERSION_GREATER 3 AND QTVERSION VERSION_LESS 5)
+
+ if (Qt5Core_FOUND)
+ # Qt5CoreConfig sets QT_MOC_EXECUTABLE as a non-cache variable to the Qt 5
+ # path to moc. Unset that variable when Qt 4 and 5 are used together, so
+ # that when find_program looks for moc, it is not set to the Qt 5 version.
+ # If FindQt4 has already put the Qt 4 path in the cache, the unset()
+ # command 'unhides' the (correct) cache variable.
+ unset(QT_MOC_EXECUTABLE)
+ endif()
+ if (QT_QMAKE_EXECUTABLE_LAST)
+ string(COMPARE NOTEQUAL "${QT_QMAKE_EXECUTABLE_LAST}" "${QT_QMAKE_EXECUTABLE}" QT_QMAKE_CHANGED)
+ endif()
+ set(QT_QMAKE_EXECUTABLE_LAST "${QT_QMAKE_EXECUTABLE}" CACHE INTERNAL "" FORCE)
+
+ _qt4_get_version_components("${QTVERSION}" QT_VERSION_MAJOR QT_VERSION_MINOR QT_VERSION_PATCH)
+
+ # ask qmake for the mkspecs directory
+ # we do this first because QT_LIBINFIX might be set
+ if (NOT QT_MKSPECS_DIR OR QT_QMAKE_CHANGED)
+ _qt4_query_qmake(QMAKE_MKSPECS qt_mkspecs_dirs)
+ # do not replace : on windows as it might be a drive letter
+ # and windows should already use ; as a separator
+ if(NOT WIN32)
+ string(REPLACE ":" ";" qt_mkspecs_dirs "${qt_mkspecs_dirs}")
+ endif()
+ set(qt_cross_paths)
+ foreach(qt_cross_path ${CMAKE_FIND_ROOT_PATH})
+ set(qt_cross_paths ${qt_cross_paths} "${qt_cross_path}/mkspecs")
+ endforeach()
+ set(QT_MKSPECS_DIR NOTFOUND)
+ find_path(QT_MKSPECS_DIR NAMES qconfig.pri
+ HINTS ${qt_cross_paths} ${qt_mkspecs_dirs}
+ DOC "The location of the Qt mkspecs containing qconfig.pri"
+ NO_CMAKE_FIND_ROOT_PATH)
+ endif()
+
+ if(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri")
+ file(READ ${QT_MKSPECS_DIR}/qconfig.pri _qconfig_FILE_contents)
+ string(REGEX MATCH "QT_CONFIG[^\n]+" QT_QCONFIG "${_qconfig_FILE_contents}")
+ string(REGEX MATCH "CONFIG[^\n]+" QT_CONFIG "${_qconfig_FILE_contents}")
+ string(REGEX MATCH "EDITION[^\n]+" QT_EDITION "${_qconfig_FILE_contents}")
+ string(REGEX MATCH "QT_LIBINFIX[^\n]+" _qconfig_qt_libinfix "${_qconfig_FILE_contents}")
+ string(REGEX REPLACE "QT_LIBINFIX *= *([^\n]*)" "\\1" QT_LIBINFIX "${_qconfig_qt_libinfix}")
+ endif()
+ if("${QT_EDITION}" MATCHES "DesktopLight")
+ set(QT_EDITION_DESKTOPLIGHT 1)
+ endif()
+
+ # ask qmake for the library dir as a hint, then search for QtCore library and use that as a reference for finding the
+ # others and for setting QT_LIBRARY_DIR
+ if (NOT (QT_QTCORE_LIBRARY_RELEASE OR QT_QTCORE_LIBRARY_DEBUG) OR QT_QMAKE_CHANGED)
+ _qt4_query_qmake(QT_INSTALL_LIBS QT_LIBRARY_DIR_TMP)
+ set(QT_QTCORE_LIBRARY_RELEASE NOTFOUND)
+ set(QT_QTCORE_LIBRARY_DEBUG NOTFOUND)
+ find_library(QT_QTCORE_LIBRARY_RELEASE
+ NAMES QtCore${QT_LIBINFIX} QtCore${QT_LIBINFIX}4
+ HINTS ${QT_LIBRARY_DIR_TMP}
+ NO_DEFAULT_PATH
+ )
+ find_library(QT_QTCORE_LIBRARY_DEBUG
+ NAMES QtCore${QT_LIBINFIX}_debug QtCore${QT_LIBINFIX}d QtCore${QT_LIBINFIX}d4
+ HINTS ${QT_LIBRARY_DIR_TMP}
+ NO_DEFAULT_PATH
+ )
+
+ if(NOT QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTCORE_LIBRARY_DEBUG)
+ find_library(QT_QTCORE_LIBRARY_RELEASE
+ NAMES QtCore${QT_LIBINFIX} QtCore${QT_LIBINFIX}4
+ HINTS ${QT_LIBRARY_DIR_TMP}
+ )
+ find_library(QT_QTCORE_LIBRARY_DEBUG
+ NAMES QtCore${QT_LIBINFIX}_debug QtCore${QT_LIBINFIX}d QtCore${QT_LIBINFIX}d4
+ HINTS ${QT_LIBRARY_DIR_TMP}
+ )
+ endif()
+
+ # try dropping a hint if trying to use Visual Studio with Qt built by MinGW
+ if(NOT QT_QTCORE_LIBRARY_RELEASE AND MSVC)
+ if(EXISTS ${QT_LIBRARY_DIR_TMP}/libqtmain.a)
+ message( FATAL_ERROR "It appears you're trying to use Visual Studio with Qt built by MinGW. Those compilers do not produce code compatible with each other.")
+ endif()
+ endif()
+
+ endif ()
+
+ # set QT_LIBRARY_DIR based on location of QtCore found.
+ if(QT_QTCORE_LIBRARY_RELEASE)
+ get_filename_component(QT_LIBRARY_DIR_TMP "${QT_QTCORE_LIBRARY_RELEASE}" PATH)
+ set(QT_LIBRARY_DIR ${QT_LIBRARY_DIR_TMP} CACHE INTERNAL "Qt library dir" FORCE)
+ set(QT_QTCORE_FOUND 1)
+ elseif(QT_QTCORE_LIBRARY_DEBUG)
+ get_filename_component(QT_LIBRARY_DIR_TMP "${QT_QTCORE_LIBRARY_DEBUG}" PATH)
+ set(QT_LIBRARY_DIR ${QT_LIBRARY_DIR_TMP} CACHE INTERNAL "Qt library dir" FORCE)
+ set(QT_QTCORE_FOUND 1)
+ else()
+ if(NOT Qt4_FIND_QUIETLY)
+ message(WARNING
+ "${QT_QMAKE_EXECUTABLE} reported QT_INSTALL_LIBS as "
+ "\"${QT_LIBRARY_DIR_TMP}\" "
+ "but QtCore could not be found there. "
+ "Qt is NOT installed correctly for the target build environment.")
+ endif()
+ set(Qt4_FOUND FALSE)
+ if(Qt4_FIND_REQUIRED)
+ message( FATAL_ERROR "Could NOT find QtCore. Check ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log for more details.")
+ else()
+ return()
+ endif()
+ endif()
+
+ # ask qmake for the binary dir
+ if (NOT QT_BINARY_DIR OR QT_QMAKE_CHANGED)
+ _qt4_query_qmake(QT_INSTALL_BINS qt_bins)
+ set(QT_BINARY_DIR ${qt_bins} CACHE INTERNAL "" FORCE)
+ endif ()
+
+ if (APPLE)
+ set(CMAKE_FIND_FRAMEWORK_OLD ${CMAKE_FIND_FRAMEWORK})
+ if (EXISTS ${QT_LIBRARY_DIR}/QtCore.framework)
+ set(QT_USE_FRAMEWORKS ON CACHE INTERNAL "" FORCE)
+ set(CMAKE_FIND_FRAMEWORK FIRST)
+ else ()
+ set(QT_USE_FRAMEWORKS OFF CACHE INTERNAL "" FORCE)
+ set(CMAKE_FIND_FRAMEWORK LAST)
+ endif ()
+ endif ()
+
+ # ask qmake for the include dir
+ if (QT_LIBRARY_DIR AND (NOT QT_QTCORE_INCLUDE_DIR OR NOT QT_HEADERS_DIR OR QT_QMAKE_CHANGED))
+ _qt4_query_qmake(QT_INSTALL_HEADERS qt_headers)
+ set(QT_QTCORE_INCLUDE_DIR NOTFOUND)
+ find_path(QT_QTCORE_INCLUDE_DIR QtCore
+ HINTS ${qt_headers} ${QT_LIBRARY_DIR}
+ PATH_SUFFIXES QtCore qt4/QtCore
+ NO_DEFAULT_PATH
+ )
+ if(NOT QT_QTCORE_INCLUDE_DIR)
+ find_path(QT_QTCORE_INCLUDE_DIR QtCore
+ HINTS ${qt_headers} ${QT_LIBRARY_DIR}
+ PATH_SUFFIXES QtCore qt4/QtCore
+ )
+ endif()
+
+ # Set QT_HEADERS_DIR based on finding QtCore header
+ if(QT_QTCORE_INCLUDE_DIR)
+ if(QT_USE_FRAMEWORKS)
+ set(QT_HEADERS_DIR "${qt_headers}" CACHE INTERNAL "" FORCE)
+ else()
+ get_filename_component(qt_headers "${QT_QTCORE_INCLUDE_DIR}/../" ABSOLUTE)
+ set(QT_HEADERS_DIR "${qt_headers}" CACHE INTERNAL "" FORCE)
+ endif()
+ elseif()
+ message("Warning: QT_QMAKE_EXECUTABLE reported QT_INSTALL_HEADERS as ${qt_headers}")
+ message("Warning: But QtCore couldn't be found. Qt must NOT be installed correctly.")
+ endif()
+ endif()
+
+ if(APPLE)
+ set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_OLD})
+ endif()
+
+ # Set QT_INCLUDE_DIR based on QT_HEADERS_DIR
+ if(QT_HEADERS_DIR)
+ if(QT_USE_FRAMEWORKS)
+ # Qt/Mac frameworks has two include dirs.
+ # One is the framework include for which CMake will add a -F flag
+ # and the other is an include dir for non-framework Qt modules
+ set(QT_INCLUDE_DIR ${QT_HEADERS_DIR} ${QT_QTCORE_LIBRARY_RELEASE} )
+ else()
+ set(QT_INCLUDE_DIR ${QT_HEADERS_DIR})
+ endif()
+ endif()
+
+ # Set QT_INCLUDES
+ set( QT_INCLUDES ${QT_MKSPECS_DIR}/default ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR})
+
+
+ # ask qmake for the documentation directory
+ if (QT_LIBRARY_DIR AND NOT QT_DOC_DIR OR QT_QMAKE_CHANGED)
+ _qt4_query_qmake(QT_INSTALL_DOCS qt_doc_dir)
+ set(QT_DOC_DIR ${qt_doc_dir} CACHE PATH "The location of the Qt docs" FORCE)
+ endif ()
+
+
+ # ask qmake for the plugins directory
+ if (QT_LIBRARY_DIR AND NOT QT_PLUGINS_DIR OR QT_QMAKE_CHANGED)
+ _qt4_query_qmake(QT_INSTALL_PLUGINS qt_plugins_dir)
+ set(QT_PLUGINS_DIR NOTFOUND)
+ foreach(qt_cross_path ${CMAKE_FIND_ROOT_PATH})
+ set(qt_cross_paths ${qt_cross_paths} "${qt_cross_path}/plugins")
+ endforeach()
+ find_path(QT_PLUGINS_DIR NAMES accessible imageformats sqldrivers codecs designer
+ HINTS ${qt_cross_paths} ${qt_plugins_dir}
+ DOC "The location of the Qt plugins"
+ NO_CMAKE_FIND_ROOT_PATH)
+ endif ()
+
+ # ask qmake for the translations directory
+ if (QT_LIBRARY_DIR AND NOT QT_TRANSLATIONS_DIR OR QT_QMAKE_CHANGED)
+ _qt4_query_qmake(QT_INSTALL_TRANSLATIONS qt_translations_dir)
+ set(QT_TRANSLATIONS_DIR ${qt_translations_dir} CACHE PATH "The location of the Qt translations" FORCE)
+ endif ()
+
+ # ask qmake for the imports directory
+ if (QT_LIBRARY_DIR AND NOT QT_IMPORTS_DIR OR QT_QMAKE_CHANGED)
+ _qt4_query_qmake(QT_INSTALL_IMPORTS qt_imports_dir)
+ if(qt_imports_dir)
+ set(QT_IMPORTS_DIR NOTFOUND)
+ foreach(qt_cross_path ${CMAKE_FIND_ROOT_PATH})
+ set(qt_cross_paths ${qt_cross_paths} "${qt_cross_path}/imports")
+ endforeach()
+ find_path(QT_IMPORTS_DIR NAMES Qt
+ HINTS ${qt_cross_paths} ${qt_imports_dir}
+ DOC "The location of the Qt imports"
+ NO_CMAKE_FIND_ROOT_PATH
+ NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH
+ NO_CMAKE_SYSTEM_PATH)
+ mark_as_advanced(QT_IMPORTS_DIR)
+ endif()
+ endif ()
+
+ # Make variables changeable to the advanced user
+ mark_as_advanced( QT_LIBRARY_DIR QT_DOC_DIR QT_MKSPECS_DIR
+ QT_PLUGINS_DIR QT_TRANSLATIONS_DIR)
+
+
+
+
+ #############################################
+ #
+ # Find out what window system we're using
+ #
+ #############################################
+ cmake_push_check_state()
+ # Add QT_INCLUDE_DIR to CMAKE_REQUIRED_INCLUDES
+ set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${QT_INCLUDE_DIR}")
+ set(CMAKE_REQUIRED_QUIET ${Qt4_FIND_QUIETLY})
+ # Check for Window system symbols (note: only one should end up being set)
+ CHECK_CXX_SYMBOL_EXISTS(Q_WS_X11 "QtCore/qglobal.h" Q_WS_X11)
+ CHECK_CXX_SYMBOL_EXISTS(Q_WS_WIN "QtCore/qglobal.h" Q_WS_WIN)
+ CHECK_CXX_SYMBOL_EXISTS(Q_WS_QWS "QtCore/qglobal.h" Q_WS_QWS)
+ CHECK_CXX_SYMBOL_EXISTS(Q_WS_MAC "QtCore/qglobal.h" Q_WS_MAC)
+ if(Q_WS_MAC)
+ if(QT_QMAKE_CHANGED)
+ unset(QT_MAC_USE_COCOA CACHE)
+ endif()
+ CHECK_CXX_SYMBOL_EXISTS(QT_MAC_USE_COCOA "QtCore/qconfig.h" QT_MAC_USE_COCOA)
+ endif()
+
+ if (QT_QTCOPY_REQUIRED)
+ CHECK_CXX_SYMBOL_EXISTS(QT_IS_QTCOPY "QtCore/qglobal.h" QT_KDE_QT_COPY)
+ if (NOT QT_IS_QTCOPY)
+ message(FATAL_ERROR "qt-copy is required, but hasn't been found")
+ endif ()
+ endif ()
+
+ cmake_pop_check_state()
+ #
+ #############################################
+
+
+
+ ########################################
+ #
+ # Setting the INCLUDE-Variables
+ #
+ ########################################
+
+ set(QT_MODULES QtGui Qt3Support QtSvg QtScript QtTest QtUiTools
+ QtHelp QtWebKit QtXmlPatterns phonon QtNetwork QtMultimedia
+ QtNsPlugin QtOpenGL QtSql QtXml QtDesigner QtDBus QtScriptTools
+ QtDeclarative)
+
+ if(Q_WS_X11)
+ set(QT_MODULES ${QT_MODULES} QtMotif)
+ endif()
+
+ if(QT_QMAKE_CHANGED)
+ foreach(QT_MODULE ${QT_MODULES})
+ string(TOUPPER ${QT_MODULE} _upper_qt_module)
+ set(QT_${_upper_qt_module}_INCLUDE_DIR NOTFOUND)
+ set(QT_${_upper_qt_module}_LIBRARY_RELEASE NOTFOUND)
+ set(QT_${_upper_qt_module}_LIBRARY_DEBUG NOTFOUND)
+ endforeach()
+ set(QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR NOTFOUND)
+ set(QT_QTDESIGNERCOMPONENTS_LIBRARY_RELEASE NOTFOUND)
+ set(QT_QTDESIGNERCOMPONENTS_LIBRARY_DEBUG NOTFOUND)
+ set(QT_QTASSISTANTCLIENT_INCLUDE_DIR NOTFOUND)
+ set(QT_QTASSISTANTCLIENT_LIBRARY_RELEASE NOTFOUND)
+ set(QT_QTASSISTANTCLIENT_LIBRARY_DEBUG NOTFOUND)
+ set(QT_QTASSISTANT_INCLUDE_DIR NOTFOUND)
+ set(QT_QTASSISTANT_LIBRARY_RELEASE NOTFOUND)
+ set(QT_QTASSISTANT_LIBRARY_DEBUG NOTFOUND)
+ set(QT_QTCLUCENE_LIBRARY_RELEASE NOTFOUND)
+ set(QT_QTCLUCENE_LIBRARY_DEBUG NOTFOUND)
+ set(QT_QAXCONTAINER_INCLUDE_DIR NOTFOUND)
+ set(QT_QAXCONTAINER_LIBRARY_RELEASE NOTFOUND)
+ set(QT_QAXCONTAINER_LIBRARY_DEBUG NOTFOUND)
+ set(QT_QAXSERVER_INCLUDE_DIR NOTFOUND)
+ set(QT_QAXSERVER_LIBRARY_RELEASE NOTFOUND)
+ set(QT_QAXSERVER_LIBRARY_DEBUG NOTFOUND)
+ if(Q_WS_WIN)
+ set(QT_QTMAIN_LIBRARY_DEBUG NOTFOUND)
+ set(QT_QTMAIN_LIBRARY_RELEASE NOTFOUND)
+ endif()
+ endif()
+
+ foreach(QT_MODULE ${QT_MODULES})
+ string(TOUPPER ${QT_MODULE} _upper_qt_module)
+ find_path(QT_${_upper_qt_module}_INCLUDE_DIR ${QT_MODULE}
+ PATHS
+ ${QT_HEADERS_DIR}/${QT_MODULE}
+ ${QT_LIBRARY_DIR}/${QT_MODULE}.framework/Headers
+ NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ # phonon doesn't seem consistent, let's try phonondefs.h for some
+ # installations
+ if(${QT_MODULE} STREQUAL "phonon")
+ find_path(QT_${_upper_qt_module}_INCLUDE_DIR phonondefs.h
+ PATHS
+ ${QT_HEADERS_DIR}/${QT_MODULE}
+ ${QT_LIBRARY_DIR}/${QT_MODULE}.framework/Headers
+ NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ endif()
+ endforeach()
+
+ if(Q_WS_WIN)
+ set(QT_MODULES ${QT_MODULES} QAxContainer QAxServer)
+ # Set QT_AXCONTAINER_INCLUDE_DIR and QT_AXSERVER_INCLUDE_DIR
+ find_path(QT_QAXCONTAINER_INCLUDE_DIR ActiveQt
+ PATHS ${QT_HEADERS_DIR}/ActiveQt
+ NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ find_path(QT_QAXSERVER_INCLUDE_DIR ActiveQt
+ PATHS ${QT_HEADERS_DIR}/ActiveQt
+ NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ endif()
+
+ # Set QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR
+ find_path(QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR QDesignerComponents
+ PATHS
+ ${QT_HEADERS_DIR}/QtDesigner
+ ${QT_LIBRARY_DIR}/QtDesigner.framework/Headers
+ NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+
+ # Set QT_QTASSISTANT_INCLUDE_DIR
+ find_path(QT_QTASSISTANT_INCLUDE_DIR QtAssistant
+ PATHS
+ ${QT_HEADERS_DIR}/QtAssistant
+ ${QT_LIBRARY_DIR}/QtAssistant.framework/Headers
+ NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+
+ # Set QT_QTASSISTANTCLIENT_INCLUDE_DIR
+ find_path(QT_QTASSISTANTCLIENT_INCLUDE_DIR QAssistantClient
+ PATHS
+ ${QT_HEADERS_DIR}/QtAssistant
+ ${QT_LIBRARY_DIR}/QtAssistant.framework/Headers
+ NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+
+ ########################################
+ #
+ # Setting the LIBRARY-Variables
+ #
+ ########################################
+
+ # find the libraries
+ foreach(QT_MODULE ${QT_MODULES})
+ string(TOUPPER ${QT_MODULE} _upper_qt_module)
+ find_library(QT_${_upper_qt_module}_LIBRARY_RELEASE
+ NAMES ${QT_MODULE}${QT_LIBINFIX} ${QT_MODULE}${QT_LIBINFIX}4
+ PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ find_library(QT_${_upper_qt_module}_LIBRARY_DEBUG
+ NAMES ${QT_MODULE}${QT_LIBINFIX}_debug ${QT_MODULE}${QT_LIBINFIX}d ${QT_MODULE}${QT_LIBINFIX}d4
+ PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ if(QT_${_upper_qt_module}_LIBRARY_RELEASE MATCHES "/${QT_MODULE}\\.framework$")
+ if(NOT EXISTS "${QT_${_upper_qt_module}_LIBRARY_RELEASE}/${QT_MODULE}")
+ # Release framework library file does not exist... Force to NOTFOUND:
+ set(QT_${_upper_qt_module}_LIBRARY_RELEASE "QT_${_upper_qt_module}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library." FORCE)
+ endif()
+ endif()
+ if(QT_${_upper_qt_module}_LIBRARY_DEBUG MATCHES "/${QT_MODULE}\\.framework$")
+ if(NOT EXISTS "${QT_${_upper_qt_module}_LIBRARY_DEBUG}/${QT_MODULE}")
+ # Debug framework library file does not exist... Force to NOTFOUND:
+ set(QT_${_upper_qt_module}_LIBRARY_DEBUG "QT_${_upper_qt_module}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library." FORCE)
+ endif()
+ endif()
+ endforeach()
+
+ # QtUiTools is sometimes not in the same directory as the other found libraries
+ # e.g. on Mac, its never a framework like the others are
+ if(QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTUITOOLS_LIBRARY_RELEASE)
+ find_library(QT_QTUITOOLS_LIBRARY_RELEASE NAMES QtUiTools${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR})
+ endif()
+
+ # Set QT_QTDESIGNERCOMPONENTS_LIBRARY
+ find_library(QT_QTDESIGNERCOMPONENTS_LIBRARY_RELEASE NAMES QtDesignerComponents${QT_LIBINFIX} QtDesignerComponents${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+ find_library(QT_QTDESIGNERCOMPONENTS_LIBRARY_DEBUG NAMES QtDesignerComponents${QT_LIBINFIX}_debug QtDesignerComponents${QT_LIBINFIX}d QtDesignerComponents${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+
+ # Set QT_QTMAIN_LIBRARY
+ if(Q_WS_WIN)
+ find_library(QT_QTMAIN_LIBRARY_RELEASE NAMES qtmain${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+ find_library(QT_QTMAIN_LIBRARY_DEBUG NAMES qtmain${QT_LIBINFIX}d PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+ endif()
+
+ # Set QT_QTASSISTANTCLIENT_LIBRARY
+ find_library(QT_QTASSISTANTCLIENT_LIBRARY_RELEASE NAMES QtAssistantClient${QT_LIBINFIX} QtAssistantClient${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+ find_library(QT_QTASSISTANTCLIENT_LIBRARY_DEBUG NAMES QtAssistantClient${QT_LIBINFIX}_debug QtAssistantClient${QT_LIBINFIX}d QtAssistantClient${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+
+ # Set QT_QTASSISTANT_LIBRARY
+ find_library(QT_QTASSISTANT_LIBRARY_RELEASE NAMES QtAssistantClient${QT_LIBINFIX} QtAssistantClient${QT_LIBINFIX}4 QtAssistant${QT_LIBINFIX} QtAssistant${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+ find_library(QT_QTASSISTANT_LIBRARY_DEBUG NAMES QtAssistantClient${QT_LIBINFIX}_debug QtAssistantClient${QT_LIBINFIX}d QtAssistantClient${QT_LIBINFIX}d4 QtAssistant${QT_LIBINFIX}_debug QtAssistant${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+
+ # Set QT_QTHELP_LIBRARY
+ find_library(QT_QTCLUCENE_LIBRARY_RELEASE NAMES QtCLucene${QT_LIBINFIX} QtCLucene${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+ find_library(QT_QTCLUCENE_LIBRARY_DEBUG NAMES QtCLucene${QT_LIBINFIX}_debug QtCLucene${QT_LIBINFIX}d QtCLucene${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+ if(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTCLUCENE_LIBRARY_RELEASE)
+ find_library(QT_QTCLUCENE_LIBRARY_RELEASE NAMES QtCLucene${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR})
+ endif()
+
+
+ ############################################
+ #
+ # Check the existence of the libraries.
+ #
+ ############################################
+
+
+ macro(_qt4_add_target_depends_internal _QT_MODULE _PROPERTY)
+ if (TARGET Qt4::${_QT_MODULE})
+ foreach(_DEPEND ${ARGN})
+ set(_VALID_DEPENDS)
+ if (TARGET Qt4::Qt${_DEPEND})
+ list(APPEND _VALID_DEPENDS Qt4::Qt${_DEPEND})
+ endif()
+ if (_VALID_DEPENDS)
+ set_property(TARGET Qt4::${_QT_MODULE} APPEND PROPERTY
+ ${_PROPERTY}
+ "${_VALID_DEPENDS}"
+ )
+ endif()
+ set(_VALID_DEPENDS)
+ endforeach()
+ endif()
+ endmacro()
+
+ macro(_qt4_add_target_depends _QT_MODULE)
+ if (TARGET Qt4::${_QT_MODULE})
+ get_target_property(_configs Qt4::${_QT_MODULE} IMPORTED_CONFIGURATIONS)
+ _qt4_add_target_depends_internal(${_QT_MODULE} INTERFACE_LINK_LIBRARIES ${ARGN})
+ foreach(_config ${_configs})
+ _qt4_add_target_depends_internal(${_QT_MODULE} IMPORTED_LINK_INTERFACE_LIBRARIES_${_config} ${ARGN})
+ endforeach()
+ set(_configs)
+ endif()
+ endmacro()
+
+ macro(_qt4_add_target_private_depends _QT_MODULE)
+ if (TARGET Qt4::${_QT_MODULE})
+ get_target_property(_configs Qt4::${_QT_MODULE} IMPORTED_CONFIGURATIONS)
+ foreach(_config ${_configs})
+ _qt4_add_target_depends_internal(${_QT_MODULE} IMPORTED_LINK_DEPENDENT_LIBRARIES_${_config} ${ARGN})
+ endforeach()
+ set(_configs)
+ endif()
+ endmacro()
+
+
+ # Set QT_xyz_LIBRARY variable and add
+ # library include path to QT_INCLUDES
+ _QT4_ADJUST_LIB_VARS(QtCore)
+ set_property(TARGET Qt4::QtCore APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES
+ "${QT_MKSPECS_DIR}/default"
+ ${QT_INCLUDE_DIR}
+ )
+ set_property(TARGET Qt4::QtCore APPEND PROPERTY
+ INTERFACE_COMPILE_DEFINITIONS
+ $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG>
+ )
+ set_property(TARGET Qt4::QtCore PROPERTY
+ INTERFACE_QT_MAJOR_VERSION 4
+ )
+ set_property(TARGET Qt4::QtCore APPEND PROPERTY
+ COMPATIBLE_INTERFACE_STRING QT_MAJOR_VERSION
+ )
+
+ foreach(QT_MODULE ${QT_MODULES})
+ _QT4_ADJUST_LIB_VARS(${QT_MODULE})
+ _qt4_add_target_depends(${QT_MODULE} Core)
+ endforeach()
+
+ _QT4_ADJUST_LIB_VARS(QtAssistant)
+ _QT4_ADJUST_LIB_VARS(QtAssistantClient)
+ _QT4_ADJUST_LIB_VARS(QtCLucene)
+ _QT4_ADJUST_LIB_VARS(QtDesignerComponents)
+
+ # platform dependent libraries
+ if(Q_WS_WIN)
+ _QT4_ADJUST_LIB_VARS(qtmain)
+
+ _QT4_ADJUST_LIB_VARS(QAxServer)
+ if(QT_QAXSERVER_FOUND)
+ set_property(TARGET Qt4::QAxServer PROPERTY
+ INTERFACE_QT4_NO_LINK_QTMAIN ON
+ )
+ set_property(TARGET Qt4::QAxServer APPEND PROPERTY
+ COMPATIBLE_INTERFACE_BOOL QT4_NO_LINK_QTMAIN)
+ endif()
+
+ _QT4_ADJUST_LIB_VARS(QAxContainer)
+ endif()
+
+ # Only public dependencies are listed here.
+ # Eg, QtDBus links to QtXml, but users of QtDBus do not need to
+ # link to QtXml because QtDBus only uses it internally, not in public
+ # headers.
+ # Everything depends on QtCore, but that is covered above already
+ _qt4_add_target_depends(Qt3Support Sql Gui Network)
+ if (TARGET Qt4::Qt3Support)
+ # An additional define is required for QT3_SUPPORT
+ set_property(TARGET Qt4::Qt3Support APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS QT3_SUPPORT)
+ endif()
+ _qt4_add_target_depends(QtDeclarative Script Gui)
+ _qt4_add_target_depends(QtDesigner Gui)
+ _qt4_add_target_depends(QtHelp Gui)
+ _qt4_add_target_depends(QtMultimedia Gui)
+ _qt4_add_target_depends(QtOpenGL Gui)
+ _qt4_add_target_depends(QtSvg Gui)
+ _qt4_add_target_depends(QtWebKit Gui Network)
+
+ _qt4_add_target_private_depends(Qt3Support Xml)
+ if(QT_VERSION VERSION_GREATER 4.6)
+ _qt4_add_target_private_depends(QtSvg Xml)
+ endif()
+ _qt4_add_target_private_depends(QtDBus Xml)
+ _qt4_add_target_private_depends(QtUiTools Xml Gui)
+ _qt4_add_target_private_depends(QtHelp Sql Xml Network)
+ _qt4_add_target_private_depends(QtXmlPatterns Network)
+ _qt4_add_target_private_depends(QtScriptTools Gui)
+ _qt4_add_target_private_depends(QtWebKit XmlPatterns)
+ _qt4_add_target_private_depends(QtDeclarative XmlPatterns Svg Sql Gui)
+ _qt4_add_target_private_depends(QtMultimedia Gui)
+ _qt4_add_target_private_depends(QtOpenGL Gui)
+ if(QT_QAXSERVER_FOUND)
+ _qt4_add_target_private_depends(QAxServer Gui)
+ endif()
+ if(QT_QAXCONTAINER_FOUND)
+ _qt4_add_target_private_depends(QAxContainer Gui)
+ endif()
+ _qt4_add_target_private_depends(phonon Gui)
+ if(QT_QTDBUS_FOUND)
+ _qt4_add_target_private_depends(phonon DBus)
+ endif()
+
+ if (WIN32 AND NOT QT4_NO_LINK_QTMAIN)
+ set(_isExe $<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>)
+ set(_isWin32 $<BOOL:$<TARGET_PROPERTY:WIN32_EXECUTABLE>>)
+ set(_isNotExcluded $<NOT:$<BOOL:$<TARGET_PROPERTY:QT4_NO_LINK_QTMAIN>>>)
+ set(_isPolicyNEW $<TARGET_POLICY:CMP0020>)
+ get_target_property(_configs Qt4::QtCore IMPORTED_CONFIGURATIONS)
+ set_property(TARGET Qt4::QtCore APPEND PROPERTY
+ INTERFACE_LINK_LIBRARIES
+ $<$<AND:${_isExe},${_isWin32},${_isNotExcluded},${_isPolicyNEW}>:Qt4::qtmain>
+ )
+ foreach(_config ${_configs})
+ set_property(TARGET Qt4::QtCore APPEND PROPERTY
+ IMPORTED_LINK_INTERFACE_LIBRARIES_${_config}
+ $<$<AND:${_isExe},${_isWin32},${_isNotExcluded},${_isPolicyNEW}>:Qt4::qtmain>
+ )
+ endforeach()
+ unset(_configs)
+ unset(_isExe)
+ unset(_isWin32)
+ unset(_isNotExcluded)
+ unset(_isPolicyNEW)
+ endif()
+
+ #######################################
+ #
+ # Check the executables of Qt
+ # ( moc, uic, rcc )
+ #
+ #######################################
+
+
+ if(QT_QMAKE_CHANGED)
+ set(QT_UIC_EXECUTABLE NOTFOUND)
+ set(QT_MOC_EXECUTABLE NOTFOUND)
+ set(QT_UIC3_EXECUTABLE NOTFOUND)
+ set(QT_RCC_EXECUTABLE NOTFOUND)
+ set(QT_DBUSCPP2XML_EXECUTABLE NOTFOUND)
+ set(QT_DBUSXML2CPP_EXECUTABLE NOTFOUND)
+ set(QT_LUPDATE_EXECUTABLE NOTFOUND)
+ set(QT_LRELEASE_EXECUTABLE NOTFOUND)
+ set(QT_QCOLLECTIONGENERATOR_EXECUTABLE NOTFOUND)
+ set(QT_DESIGNER_EXECUTABLE NOTFOUND)
+ set(QT_LINGUIST_EXECUTABLE NOTFOUND)
+ endif()
+
+ macro(_find_qt4_program VAR NAME)
+ find_program(${VAR}
+ NAMES ${ARGN}
+ PATHS ${QT_BINARY_DIR}
+ NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ if (${VAR} AND NOT TARGET ${NAME})
+ add_executable(${NAME} IMPORTED)
+ set_property(TARGET ${NAME} PROPERTY IMPORTED_LOCATION ${${VAR}})
+ endif()
+ endmacro()
+
+ _find_qt4_program(QT_MOC_EXECUTABLE Qt4::moc moc-qt4 moc4 moc)
+ _find_qt4_program(QT_UIC_EXECUTABLE Qt4::uic uic-qt4 uic4 uic)
+ _find_qt4_program(QT_UIC3_EXECUTABLE Qt4::uic3 uic3)
+ _find_qt4_program(QT_RCC_EXECUTABLE Qt4::rcc rcc)
+ _find_qt4_program(QT_DBUSCPP2XML_EXECUTABLE Qt4::qdbuscpp2xml qdbuscpp2xml)
+ _find_qt4_program(QT_DBUSXML2CPP_EXECUTABLE Qt4::qdbusxml2cpp qdbusxml2cpp)
+ _find_qt4_program(QT_LUPDATE_EXECUTABLE Qt4::lupdate lupdate-qt4 lupdate4 lupdate)
+ _find_qt4_program(QT_LRELEASE_EXECUTABLE Qt4::lrelease lrelease-qt4 lrelease4 lrelease)
+ _find_qt4_program(QT_QCOLLECTIONGENERATOR_EXECUTABLE Qt4::qcollectiongenerator qcollectiongenerator-qt4 qcollectiongenerator)
+ _find_qt4_program(QT_DESIGNER_EXECUTABLE Qt4::designer designer-qt4 designer4 designer)
+ _find_qt4_program(QT_LINGUIST_EXECUTABLE Qt4::linguist linguist-qt4 linguist4 linguist)
+
+ if (NOT TARGET Qt4::qmake)
+ add_executable(Qt4::qmake IMPORTED)
+ set_property(TARGET Qt4::qmake PROPERTY IMPORTED_LOCATION ${QT_QMAKE_EXECUTABLE})
+ endif()
+
+ if (QT_MOC_EXECUTABLE)
+ set(QT_WRAP_CPP "YES")
+ endif ()
+
+ if (QT_UIC_EXECUTABLE)
+ set(QT_WRAP_UI "YES")
+ endif ()
+
+
+
+ mark_as_advanced( QT_UIC_EXECUTABLE QT_UIC3_EXECUTABLE QT_MOC_EXECUTABLE
+ QT_RCC_EXECUTABLE QT_DBUSXML2CPP_EXECUTABLE QT_DBUSCPP2XML_EXECUTABLE
+ QT_LUPDATE_EXECUTABLE QT_LRELEASE_EXECUTABLE QT_QCOLLECTIONGENERATOR_EXECUTABLE
+ QT_DESIGNER_EXECUTABLE QT_LINGUIST_EXECUTABLE)
+
+
+ # get the directory of the current file, used later on in the file
+ get_filename_component( _qt4_current_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+
+ ###############################################
+ #
+ # configuration/system dependent settings
+ #
+ ###############################################
+
+ include("${_qt4_current_dir}/Qt4ConfigDependentSettings.cmake")
+
+
+ #######################################
+ #
+ # Check the plugins of Qt
+ #
+ #######################################
+
+ set( QT_PLUGIN_TYPES accessible bearer codecs decorations designer gfxdrivers graphicssystems iconengines imageformats inputmethods mousedrivers phonon_backend script sqldrivers )
+
+ set( QT_ACCESSIBLE_PLUGINS qtaccessiblecompatwidgets qtaccessiblewidgets )
+ set( QT_BEARER_PLUGINS qcorewlanbearer qgenericbearer qnativewifibearer )
+ set( QT_CODECS_PLUGINS qcncodecs qjpcodecs qkrcodecs qtwcodecs )
+ set( QT_DECORATIONS_PLUGINS qdecorationdefault qdecorationwindows )
+ set( QT_DESIGNER_PLUGINS arthurplugin containerextension customwidgetplugin phononwidgets qdeclarativeview qt3supportwidgets qwebview taskmenuextension worldtimeclockplugin )
+ set( QT_GRAPHICSDRIVERS_PLUGINS qgfxtransformed qgfxvnc qscreenvfb )
+ set( QT_GRAPHICSSYSTEMS_PLUGINS qglgraphicssystem qtracegraphicssystem )
+ set( QT_ICONENGINES_PLUGINS qsvgicon )
+ set( QT_IMAGEFORMATS_PLUGINS qgif qjpeg qmng qico qsvg qtiff qtga )
+ set( QT_INPUTMETHODS_PLUGINS qimsw_multi )
+ set( QT_MOUSEDRIVERS_PLUGINS qwstslibmousehandler )
+ if(APPLE)
+ set( QT_PHONON_BACKEND_PLUGINS phonon_qt7 )
+ elseif(WIN32)
+ set( QT_PHONON_BACKEND_PLUGINS phonon_ds9 )
+ endif()
+ set( QT_SCRIPT_PLUGINS qtscriptdbus )
+ set( QT_SQLDRIVERS_PLUGINS qsqldb2 qsqlibase qsqlite qsqlite2 qsqlmysql qsqloci qsqlodbc qsqlpsql qsqltds )
+
+ set( QT_PHONON_PLUGINS ${QT_PHONON_BACKEND_PLUGINS} )
+ set( QT_QT3SUPPORT_PLUGINS qtaccessiblecompatwidgets )
+ set( QT_QTCORE_PLUGINS ${QT_BEARER_PLUGINS} ${QT_CODECS_PLUGINS} )
+ set( QT_QTGUI_PLUGINS qtaccessiblewidgets ${QT_IMAGEFORMATS_PLUGINS} ${QT_DECORATIONS_PLUGINS} ${QT_GRAPHICSDRIVERS_PLUGINS} ${QT_GRAPHICSSYSTEMS_PLUGINS} ${QT_INPUTMETHODS_PLUGINS} ${QT_MOUSEDRIVERS_PLUGINS} )
+ set( QT_QTSCRIPT_PLUGINS ${QT_SCRIPT_PLUGINS} )
+ set( QT_QTSQL_PLUGINS ${QT_SQLDRIVERS_PLUGINS} )
+ set( QT_QTSVG_PLUGINS qsvg qsvgicon )
+
+ if(QT_QMAKE_CHANGED)
+ foreach(QT_PLUGIN_TYPE ${QT_PLUGIN_TYPES})
+ string(TOUPPER ${QT_PLUGIN_TYPE} _upper_qt_plugin_type)
+ set(QT_${_upper_qt_plugin_type}_PLUGINS_DIR ${QT_PLUGINS_DIR}/${QT_PLUGIN_TYPE})
+ foreach(QT_PLUGIN ${QT_${_upper_qt_plugin_type}_PLUGINS})
+ string(TOUPPER ${QT_PLUGIN} _upper_qt_plugin)
+ unset(QT_${_upper_qt_plugin}_LIBRARY_RELEASE CACHE)
+ unset(QT_${_upper_qt_plugin}_LIBRARY_DEBUG CACHE)
+ unset(QT_${_upper_qt_plugin}_LIBRARY CACHE)
+ unset(QT_${_upper_qt_plugin}_PLUGIN_RELEASE CACHE)
+ unset(QT_${_upper_qt_plugin}_PLUGIN_DEBUG CACHE)
+ unset(QT_${_upper_qt_plugin}_PLUGIN CACHE)
+ endforeach()
+ endforeach()
+ endif()
+
+ # find_library works better than find_file but we need to set prefixes to only match plugins
+ foreach(QT_PLUGIN_TYPE ${QT_PLUGIN_TYPES})
+ string(TOUPPER ${QT_PLUGIN_TYPE} _upper_qt_plugin_type)
+ set(QT_${_upper_qt_plugin_type}_PLUGINS_DIR ${QT_PLUGINS_DIR}/${QT_PLUGIN_TYPE})
+ foreach(QT_PLUGIN ${QT_${_upper_qt_plugin_type}_PLUGINS})
+ string(TOUPPER ${QT_PLUGIN} _upper_qt_plugin)
+ if(QT_IS_STATIC)
+ find_library(QT_${_upper_qt_plugin}_LIBRARY_RELEASE
+ NAMES ${QT_PLUGIN}${QT_LIBINFIX} ${QT_PLUGIN}${QT_LIBINFIX}4
+ PATHS ${QT_${_upper_qt_plugin_type}_PLUGINS_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ find_library(QT_${_upper_qt_plugin}_LIBRARY_DEBUG
+ NAMES ${QT_PLUGIN}${QT_LIBINFIX}_debug ${QT_PLUGIN}${QT_LIBINFIX}d ${QT_PLUGIN}${QT_LIBINFIX}d4
+ PATHS ${QT_${_upper_qt_plugin_type}_PLUGINS_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ _QT4_ADJUST_LIB_VARS(${QT_PLUGIN})
+ else()
+ # find_library works easier/better than find_file but we need to set suffixes to only match plugins
+ set(CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_MODULE_SUFFIX} ${CMAKE_SHARED_LIBRARY_SUFFIX})
+ find_library(QT_${_upper_qt_plugin}_PLUGIN_RELEASE
+ NAMES ${QT_PLUGIN}${QT_LIBINFIX} ${QT_PLUGIN}${QT_LIBINFIX}4
+ PATHS ${QT_${_upper_qt_plugin_type}_PLUGINS_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ find_library(QT_${_upper_qt_plugin}_PLUGIN_DEBUG
+ NAMES ${QT_PLUGIN}${QT_LIBINFIX}_debug ${QT_PLUGIN}${QT_LIBINFIX}d ${QT_PLUGIN}${QT_LIBINFIX}d4
+ PATHS ${QT_${_upper_qt_plugin_type}_PLUGINS_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
+ )
+ mark_as_advanced(QT_${_upper_qt_plugin}_PLUGIN_RELEASE QT_${_upper_qt_plugin}_PLUGIN_DEBUG)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT})
+ endif()
+ endforeach()
+ endforeach()
+
+
+ ######################################
+ #
+ # Macros for building Qt files
+ #
+ ######################################
+
+ include("${_qt4_current_dir}/Qt4Macros.cmake")
+
+endif()
+
+#support old QT_MIN_VERSION if set, but not if version is supplied by find_package()
+if(NOT Qt4_FIND_VERSION AND QT_MIN_VERSION)
+ set(Qt4_FIND_VERSION ${QT_MIN_VERSION})
+endif()
+
+if( Qt4_FIND_COMPONENTS )
+
+ # if components specified in find_package(), make sure each of those pieces were found
+ set(_QT4_FOUND_REQUIRED_VARS QT_QMAKE_EXECUTABLE QT_MOC_EXECUTABLE QT_RCC_EXECUTABLE QT_INCLUDE_DIR QT_LIBRARY_DIR)
+ foreach( component ${Qt4_FIND_COMPONENTS} )
+ string( TOUPPER ${component} _COMPONENT )
+ if(${_COMPONENT} STREQUAL "QTMAIN")
+ if(Q_WS_WIN)
+ set(_QT4_FOUND_REQUIRED_VARS ${_QT4_FOUND_REQUIRED_VARS} QT_${_COMPONENT}_LIBRARY)
+ endif()
+ else()
+ set(_QT4_FOUND_REQUIRED_VARS ${_QT4_FOUND_REQUIRED_VARS} QT_${_COMPONENT}_INCLUDE_DIR QT_${_COMPONENT}_LIBRARY)
+ endif()
+ endforeach()
+
+ if(Qt4_FIND_COMPONENTS MATCHES QtGui)
+ set(_QT4_FOUND_REQUIRED_VARS ${_QT4_FOUND_REQUIRED_VARS} QT_UIC_EXECUTABLE)
+ endif()
+
+else()
+
+ # if no components specified, we'll make a default set of required variables to say Qt is found
+ set(_QT4_FOUND_REQUIRED_VARS QT_QMAKE_EXECUTABLE QT_MOC_EXECUTABLE QT_RCC_EXECUTABLE QT_UIC_EXECUTABLE QT_INCLUDE_DIR
+ QT_LIBRARY_DIR QT_QTCORE_LIBRARY)
+
+endif()
+
+if (NOT QT_VERSION_MAJOR EQUAL 4)
+ set(VERSION_MSG "Found unsuitable Qt version \"${QTVERSION}\" from ${QT_QMAKE_EXECUTABLE}")
+ set(QT4_FOUND FALSE)
+ if(Qt4_FIND_REQUIRED)
+ message( FATAL_ERROR "${VERSION_MSG}, this code requires Qt 4.x")
+ else()
+ if(NOT Qt4_FIND_QUIETLY)
+ message( STATUS "${VERSION_MSG}")
+ endif()
+ endif()
+else()
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Qt4 FOUND_VAR Qt4_FOUND
+ REQUIRED_VARS ${_QT4_FOUND_REQUIRED_VARS}
+ VERSION_VAR QTVERSION
+ )
+endif()
+
+#######################################
+#
+# compatibility settings
+#
+#######################################
+# Backwards compatibility for CMake1.4 and 1.2
+set (QT_MOC_EXE ${QT_MOC_EXECUTABLE} )
+set (QT_UIC_EXE ${QT_UIC_EXECUTABLE} )
+set( QT_QT_LIBRARY "")
+set(QT4_FOUND ${Qt4_FOUND})
+set(QT_FOUND ${Qt4_FOUND})
+
diff --git a/Modules/FindQuickTime.cmake b/Modules/FindQuickTime.cmake
new file mode 100644
index 0000000000..27792691b9
--- /dev/null
+++ b/Modules/FindQuickTime.cmake
@@ -0,0 +1,45 @@
+#.rst:
+# FindQuickTime
+# -------------
+#
+#
+#
+# Locate QuickTime This module defines QUICKTIME_LIBRARY
+# QUICKTIME_FOUND, if false, do not try to link to gdal
+# QUICKTIME_INCLUDE_DIR, where to find the headers
+#
+# $QUICKTIME_DIR is an environment variable that would correspond to the
+# ./configure --prefix=$QUICKTIME_DIR
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+find_path(QUICKTIME_INCLUDE_DIR QuickTime/QuickTime.h QuickTime.h
+ HINTS
+ ENV QUICKTIME_DIR
+ PATH_SUFFIXES
+ include
+)
+find_library(QUICKTIME_LIBRARY QuickTime
+ HINTS
+ ENV QUICKTIME_DIR
+ PATH_SUFFIXES
+ lib
+)
+
+# handle the QUIETLY and REQUIRED arguments and set QUICKTIME_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(QuickTime DEFAULT_MSG QUICKTIME_LIBRARY QUICKTIME_INCLUDE_DIR)
diff --git a/Modules/FindRTI.cmake b/Modules/FindRTI.cmake
new file mode 100644
index 0000000000..1aad0a80ab
--- /dev/null
+++ b/Modules/FindRTI.cmake
@@ -0,0 +1,112 @@
+#.rst:
+# FindRTI
+# -------
+#
+# Try to find M&S HLA RTI libraries
+#
+# This module finds if any HLA RTI is installed and locates the standard
+# RTI include files and libraries.
+#
+# RTI is a simulation infrastructure standardized by IEEE and SISO. It
+# has a well defined C++ API that assures that simulation applications
+# are independent on a particular RTI implementation.
+#
+# ::
+#
+# http://en.wikipedia.org/wiki/Run-Time_Infrastructure_(simulation)
+#
+#
+#
+# This code sets the following variables:
+#
+# ::
+#
+# RTI_INCLUDE_DIR = the directory where RTI includes file are found
+# RTI_LIBRARIES = The libraries to link against to use RTI
+# RTI_DEFINITIONS = -DRTI_USES_STD_FSTREAM
+# RTI_FOUND = Set to FALSE if any HLA RTI was not found
+#
+#
+#
+# Report problems to <certi-devel@nongnu.org>
+
+#=============================================================================
+# Copyright 2008-2009 Kitware, Inc.
+# Copyright 2008 Petr Gotthard <gotthard@honeywell.com>
+#
+# 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.)
+
+macro(RTI_MESSAGE_QUIETLY QUIET TYPE MSG)
+ if(NOT ${QUIET})
+ message(${TYPE} "${MSG}")
+ endif()
+endmacro()
+
+set(RTI_DEFINITIONS "-DRTI_USES_STD_FSTREAM")
+
+# Detect the CERTI installation, http://www.cert.fr/CERTI
+# Detect the MAK Technologies RTI installation, http://www.mak.com/products/rti.php
+# note: the following list is ordered to find the most recent version first
+set(RTI_POSSIBLE_DIRS
+ ENV CERTI_HOME
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MAK Technologies\\MAK RTI 3.2 MSVC++ 8.0;Location]"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MAK RTI 3.2-win32-msvc++8.0;InstallLocation]"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MAK Technologies\\MAK RTI 2.2;Location]"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MAK RTI 2.2;InstallLocation]")
+
+set(RTI_OLD_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
+# The MAK RTI has the "lib" prefix even on Windows.
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+
+find_library(RTI_LIBRARY
+ NAMES RTI RTI-NG
+ PATHS ${RTI_POSSIBLE_DIRS}
+ PATH_SUFFIXES lib
+ DOC "The RTI Library")
+
+if (RTI_LIBRARY)
+ set(RTI_LIBRARIES ${RTI_LIBRARY})
+ RTI_MESSAGE_QUIETLY(RTI_FIND_QUIETLY STATUS "RTI library found: ${RTI_LIBRARY}")
+else ()
+ RTI_MESSAGE_QUIETLY(RTI_FIND_QUIETLY STATUS "RTI library NOT found")
+endif ()
+
+find_library(RTI_FEDTIME_LIBRARY
+ NAMES FedTime
+ PATHS ${RTI_POSSIBLE_DIRS}
+ PATH_SUFFIXES lib
+ DOC "The FedTime Library")
+
+if (RTI_FEDTIME_LIBRARY)
+ set(RTI_LIBRARIES ${RTI_LIBRARIES} ${RTI_FEDTIME_LIBRARY})
+ RTI_MESSAGE_QUIETLY(RTI_FIND_QUIETLY STATUS "RTI FedTime found: ${RTI_FEDTIME_LIBRARY}")
+endif ()
+
+find_path(RTI_INCLUDE_DIR
+ NAMES RTI.hh
+ PATHS ${RTI_POSSIBLE_DIRS}
+ PATH_SUFFIXES include
+ DOC "The RTI Include Files")
+
+if (RTI_INCLUDE_DIR)
+ RTI_MESSAGE_QUIETLY(RTI_FIND_QUIETLY STATUS "RTI headers found: ${RTI_INCLUDE_DIR}")
+else ()
+ RTI_MESSAGE_QUIETLY(RTI_FIND_QUIETLY STATUS "RTI headers NOT found")
+endif ()
+
+# Set the modified system variables back to the original value.
+set(CMAKE_FIND_LIBRARY_PREFIXES "${RTI_OLD_FIND_LIBRARY_PREFIXES}")
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(RTI DEFAULT_MSG
+ RTI_LIBRARY RTI_INCLUDE_DIR)
+
+# $Id$
diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake
new file mode 100644
index 0000000000..aafdc09cf1
--- /dev/null
+++ b/Modules/FindRuby.cmake
@@ -0,0 +1,279 @@
+#.rst:
+# FindRuby
+# --------
+#
+# Find Ruby
+#
+# This module finds if Ruby is installed and determines where the
+# include files and libraries are. Ruby 1.8, 1.9, 2.0 and 2.1 are
+# supported.
+#
+# The minimum required version of Ruby can be specified using the
+# standard syntax, e.g. find_package(Ruby 1.8)
+#
+# It also determines what the name of the library is. This code sets
+# the following variables:
+#
+# ::
+#
+# RUBY_EXECUTABLE = full path to the ruby binary
+# RUBY_INCLUDE_DIRS = include dirs to be used when using the ruby library
+# RUBY_LIBRARY = full path to the ruby library
+# RUBY_VERSION = the version of ruby which was found, e.g. "1.8.7"
+# RUBY_FOUND = set to true if ruby ws found successfully
+#
+#
+#
+# ::
+#
+# RUBY_INCLUDE_PATH = same as RUBY_INCLUDE_DIRS, only provided for compatibility reasons, don't use it
+
+#=============================================================================
+# Copyright 2004-2009 Kitware, Inc.
+# Copyright 2008-2009 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'`
+# RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'`
+# RUBY_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'`
+# RUBY_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'`
+# RUBY_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'`
+
+# uncomment the following line to get debug output for this file
+# set(_RUBY_DEBUG_OUTPUT TRUE)
+
+# Determine the list of possible names of the ruby executable depending
+# on which version of ruby is required
+set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ruby)
+
+# if 1.9 is required, don't look for ruby18 and ruby1.8, default to version 1.8
+if(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
+ set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${RUBY_FIND_VERSION_MINOR}")
+ # we can't construct that if only major version is given
+ set(_RUBY_POSSIBLE_EXECUTABLE_NAMES
+ ruby${Ruby_FIND_VERSION_MAJOR}.${Ruby_FIND_VERSION_MINOR}
+ ruby${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR}
+ ${_RUBY_POSSIBLE_EXECUTABLE_NAMES})
+else()
+ set(Ruby_FIND_VERSION_SHORT_NODOT "18")
+endif()
+
+if(NOT Ruby_FIND_VERSION_EXACT)
+ list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.1 ruby21)
+ list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.0 ruby20)
+ list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby1.9 ruby19)
+
+ # if we want a version below 1.9, also look for ruby 1.8
+ if("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
+ list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby1.8 ruby18)
+ endif()
+
+ list(REMOVE_DUPLICATES _RUBY_POSSIBLE_EXECUTABLE_NAMES)
+endif()
+
+find_program(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES})
+
+if(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR)
+ function(_RUBY_CONFIG_VAR RBVAR OUTVAR)
+ execute_process(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']"
+ RESULT_VARIABLE _RUBY_SUCCESS
+ OUTPUT_VARIABLE _RUBY_OUTPUT
+ ERROR_QUIET)
+ if(_RUBY_SUCCESS OR NOT _RUBY_OUTPUT)
+ execute_process(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
+ RESULT_VARIABLE _RUBY_SUCCESS
+ OUTPUT_VARIABLE _RUBY_OUTPUT
+ ERROR_QUIET)
+ endif()
+ set(${OUTVAR} "${_RUBY_OUTPUT}" PARENT_SCOPE)
+ endfunction()
+
+
+ # query the ruby version
+ _RUBY_CONFIG_VAR("MAJOR" RUBY_VERSION_MAJOR)
+ _RUBY_CONFIG_VAR("MINOR" RUBY_VERSION_MINOR)
+ _RUBY_CONFIG_VAR("TEENY" RUBY_VERSION_PATCH)
+
+ # query the different directories
+ _RUBY_CONFIG_VAR("archdir" RUBY_ARCH_DIR)
+ _RUBY_CONFIG_VAR("arch" RUBY_ARCH)
+ _RUBY_CONFIG_VAR("rubyhdrdir" RUBY_HDR_DIR)
+ _RUBY_CONFIG_VAR("rubyarchhdrdir" RUBY_ARCHHDR_DIR)
+ _RUBY_CONFIG_VAR("libdir" RUBY_POSSIBLE_LIB_DIR)
+ _RUBY_CONFIG_VAR("rubylibdir" RUBY_RUBY_LIB_DIR)
+
+ # site_ruby
+ _RUBY_CONFIG_VAR("sitearchdir" RUBY_SITEARCH_DIR)
+ _RUBY_CONFIG_VAR("sitelibdir" RUBY_SITELIB_DIR)
+
+ # vendor_ruby available ?
+ execute_process(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'"
+ OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET)
+
+ if(RUBY_HAS_VENDOR_RUBY)
+ _RUBY_CONFIG_VAR("vendorlibdir" RUBY_VENDORLIB_DIR)
+ _RUBY_CONFIG_VAR("vendorarchdir" RUBY_VENDORARCH_DIR)
+ endif()
+
+ # save the results in the cache so we don't have to run ruby the next time again
+ set(RUBY_VERSION_MAJOR ${RUBY_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE)
+ set(RUBY_VERSION_MINOR ${RUBY_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE)
+ set(RUBY_VERSION_PATCH ${RUBY_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE)
+ set(RUBY_ARCH_DIR ${RUBY_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE)
+ set(RUBY_HDR_DIR ${RUBY_HDR_DIR} CACHE PATH "The Ruby header dir (1.9+)" FORCE)
+ set(RUBY_ARCHHDR_DIR ${RUBY_ARCHHDR_DIR} CACHE PATH "The Ruby arch header dir (2.0+)" FORCE)
+ set(RUBY_POSSIBLE_LIB_DIR ${RUBY_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE)
+ set(RUBY_RUBY_LIB_DIR ${RUBY_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE)
+ set(RUBY_SITEARCH_DIR ${RUBY_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE)
+ set(RUBY_SITELIB_DIR ${RUBY_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE)
+ set(RUBY_HAS_VENDOR_RUBY ${RUBY_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE)
+ set(RUBY_VENDORARCH_DIR ${RUBY_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE)
+ set(RUBY_VENDORLIB_DIR ${RUBY_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE)
+
+ mark_as_advanced(
+ RUBY_ARCH_DIR
+ RUBY_ARCH
+ RUBY_HDR_DIR
+ RUBY_ARCHHDR_DIR
+ RUBY_POSSIBLE_LIB_DIR
+ RUBY_RUBY_LIB_DIR
+ RUBY_SITEARCH_DIR
+ RUBY_SITELIB_DIR
+ RUBY_HAS_VENDOR_RUBY
+ RUBY_VENDORARCH_DIR
+ RUBY_VENDORLIB_DIR
+ RUBY_VERSION_MAJOR
+ RUBY_VERSION_MINOR
+ RUBY_VERSION_PATCH
+ )
+endif()
+
+# In case RUBY_EXECUTABLE could not be executed (e.g. cross compiling)
+# try to detect which version we found. This is not too good.
+if(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR)
+ # by default assume 1.8.0
+ set(RUBY_VERSION_MAJOR 1)
+ set(RUBY_VERSION_MINOR 8)
+ set(RUBY_VERSION_PATCH 0)
+ # check whether we found 1.9.x
+ if(${RUBY_EXECUTABLE} MATCHES "ruby1.?9")
+ set(RUBY_VERSION_MAJOR 1)
+ set(RUBY_VERSION_MINOR 9)
+ endif()
+ # check whether we found 2.0.x
+ if(${RUBY_EXECUTABLE} MATCHES "ruby2.?0")
+ set(RUBY_VERSION_MAJOR 2)
+ set(RUBY_VERSION_MINOR 0)
+ endif()
+ # check whether we found 2.1.x
+ if(${RUBY_EXECUTABLE} MATCHES "ruby2.?1")
+ set(RUBY_VERSION_MAJOR 2)
+ set(RUBY_VERSION_MINOR 1)
+ endif()
+endif()
+
+if(RUBY_VERSION_MAJOR)
+ set(RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}")
+ set(_RUBY_VERSION_SHORT "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}")
+ set(_RUBY_VERSION_SHORT_NODOT "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}")
+ set(_RUBY_NODOT_VERSION "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}${RUBY_VERSION_PATCH}")
+endif()
+
+find_path(RUBY_INCLUDE_DIR
+ NAMES ruby.h
+ HINTS
+ ${RUBY_HDR_DIR}
+ ${RUBY_ARCH_DIR}
+ /usr/lib/ruby/${_RUBY_VERSION_SHORT}/i586-linux-gnu/ )
+
+set(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIR} )
+
+# if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
+if( "${Ruby_FIND_VERSION_SHORT_NODOT}" GREATER 18 OR "${_RUBY_VERSION_SHORT_NODOT}" GREATER 18 OR RUBY_HDR_DIR)
+ find_path(RUBY_CONFIG_INCLUDE_DIR
+ NAMES ruby/config.h config.h
+ HINTS
+ ${RUBY_HDR_DIR}/${RUBY_ARCH}
+ ${RUBY_ARCH_DIR}
+ ${RUBY_ARCHHDR_DIR}
+ )
+
+ set(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR} )
+endif()
+
+
+# Determine the list of possible names for the ruby library
+set(_RUBY_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_RUBY_VERSION_SHORT} ruby${_RUBY_VERSION_SHORT_NODOT} ruby-${_RUBY_VERSION_SHORT} ruby-${RUBY_VERSION})
+
+if(WIN32)
+ set( _RUBY_MSVC_RUNTIME "" )
+ if( MSVC60 )
+ set( _RUBY_MSVC_RUNTIME "60" )
+ endif()
+ if( MSVC70 )
+ set( _RUBY_MSVC_RUNTIME "70" )
+ endif()
+ if( MSVC71 )
+ set( _RUBY_MSVC_RUNTIME "71" )
+ endif()
+ if( MSVC80 )
+ set( _RUBY_MSVC_RUNTIME "80" )
+ endif()
+ if( MSVC90 )
+ set( _RUBY_MSVC_RUNTIME "90" )
+ endif()
+
+ list(APPEND _RUBY_POSSIBLE_LIB_NAMES
+ "msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}"
+ "msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}-static"
+ "msvcrt-ruby${_RUBY_NODOT_VERSION}"
+ "msvcrt-ruby${_RUBY_NODOT_VERSION}-static" )
+endif()
+
+find_library(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR} )
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+set(_RUBY_REQUIRED_VARS RUBY_EXECUTABLE RUBY_INCLUDE_DIR RUBY_LIBRARY)
+if(_RUBY_VERSION_SHORT_NODOT GREATER 18)
+ list(APPEND _RUBY_REQUIRED_VARS RUBY_CONFIG_INCLUDE_DIR)
+endif()
+
+if(_RUBY_DEBUG_OUTPUT)
+ message(STATUS "--------FindRuby.cmake debug------------")
+ message(STATUS "_RUBY_POSSIBLE_EXECUTABLE_NAMES: ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}")
+ message(STATUS "_RUBY_POSSIBLE_LIB_NAMES: ${_RUBY_POSSIBLE_LIB_NAMES}")
+ message(STATUS "RUBY_ARCH_DIR: ${RUBY_ARCH_DIR}")
+ message(STATUS "RUBY_HDR_DIR: ${RUBY_HDR_DIR}")
+ message(STATUS "RUBY_POSSIBLE_LIB_DIR: ${RUBY_POSSIBLE_LIB_DIR}")
+ message(STATUS "Found RUBY_VERSION: \"${RUBY_VERSION}\" , short: \"${_RUBY_VERSION_SHORT}\", nodot: \"${_RUBY_VERSION_SHORT_NODOT}\"")
+ message(STATUS "_RUBY_REQUIRED_VARS: ${_RUBY_REQUIRED_VARS}")
+ message(STATUS "RUBY_EXECUTABLE: ${RUBY_EXECUTABLE}")
+ message(STATUS "RUBY_LIBRARY: ${RUBY_LIBRARY}")
+ message(STATUS "RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}")
+ message(STATUS "RUBY_CONFIG_INCLUDE_DIR: ${RUBY_CONFIG_INCLUDE_DIR}")
+ message(STATUS "--------------------")
+endif()
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby REQUIRED_VARS ${_RUBY_REQUIRED_VARS}
+ VERSION_VAR RUBY_VERSION )
+
+mark_as_advanced(
+ RUBY_EXECUTABLE
+ RUBY_LIBRARY
+ RUBY_INCLUDE_DIR
+ RUBY_CONFIG_INCLUDE_DIR
+ )
+
+# Set some variables for compatibility with previous version of this file
+set(RUBY_POSSIBLE_LIB_PATH ${RUBY_POSSIBLE_LIB_DIR})
+set(RUBY_RUBY_LIB_PATH ${RUBY_RUBY_LIB_DIR})
+set(RUBY_INCLUDE_PATH ${RUBY_INCLUDE_DIRS})
diff --git a/Modules/FindSDL.cmake b/Modules/FindSDL.cmake
new file mode 100644
index 0000000000..3905e5487c
--- /dev/null
+++ b/Modules/FindSDL.cmake
@@ -0,0 +1,201 @@
+#.rst:
+# FindSDL
+# -------
+#
+# Locate SDL library
+#
+# This module defines
+#
+# ::
+#
+# SDL_LIBRARY, the name of the library to link against
+# SDL_FOUND, if false, do not try to link to SDL
+# SDL_INCLUDE_DIR, where to find SDL.h
+# SDL_VERSION_STRING, human-readable string containing the version of SDL
+#
+#
+#
+# This module responds to the flag:
+#
+# ::
+#
+# SDL_BUILDING_LIBRARY
+# If this is defined, then no SDL_main will be linked in because
+# only applications need main().
+# Otherwise, it is assumed you are building an application and this
+# module will attempt to locate and set the proper link flags
+# as part of the returned SDL_LIBRARY variable.
+#
+#
+#
+# Don't forget to include SDLmain.h and SDLmain.m your project for the
+# OS X framework based version. (Other versions link to -lSDLmain which
+# this module will try to find on your behalf.) Also for OS X, this
+# module will automatically add the -framework Cocoa on your behalf.
+#
+#
+#
+# Additional Note: If you see an empty SDL_LIBRARY_TEMP in your
+# configuration and no SDL_LIBRARY, it means CMake did not find your SDL
+# library (SDL.dll, libsdl.so, SDL.framework, etc). Set
+# SDL_LIBRARY_TEMP to point to your SDL library, and configure again.
+# Similarly, if you see an empty SDLMAIN_LIBRARY, you should set this
+# value as appropriate. These values are used to generate the final
+# SDL_LIBRARY variable, but when these values are unset, SDL_LIBRARY
+# does not get created.
+#
+#
+#
+# $SDLDIR is an environment variable that would correspond to the
+# ./configure --prefix=$SDLDIR used in building SDL. l.e.galup 9-20-02
+#
+# Modified by Eric Wing. Added code to assist with automated building
+# by using environmental variables and providing a more
+# controlled/consistent search behavior. Added new modifications to
+# recognize OS X frameworks and additional Unix paths (FreeBSD, etc).
+# Also corrected the header search path to follow "proper" SDL
+# guidelines. Added a search for SDLmain which is needed by some
+# platforms. Added a search for threads which is needed by some
+# platforms. Added needed compile switches for MinGW.
+#
+# On OSX, this will prefer the Framework version (if found) over others.
+# People will have to manually change the cache values of SDL_LIBRARY to
+# override this selection or set the CMake environment
+# CMAKE_INCLUDE_PATH to modify the search paths.
+#
+# Note that the header path has changed from SDL/SDL.h to just SDL.h
+# This needed to change because "proper" SDL convention is #include
+# "SDL.h", not <SDL/SDL.h>. This is done for portability reasons
+# because not all systems place things in SDL/ (see FreeBSD).
+
+#=============================================================================
+# Copyright 2003-2009 Kitware, Inc.
+# Copyright 2012 Benjamin Eikel
+#
+# 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.)
+
+find_path(SDL_INCLUDE_DIR SDL.h
+ HINTS
+ ENV SDLDIR
+ PATH_SUFFIXES SDL SDL12 SDL11
+ # path suffixes to search inside ENV{SDLDIR}
+ include/SDL include/SDL12 include/SDL11 include
+)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+ set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+# SDL-1.1 is the name used by FreeBSD ports...
+# don't confuse it for the version number.
+find_library(SDL_LIBRARY_TEMP
+ NAMES SDL SDL-1.1
+ HINTS
+ ENV SDLDIR
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+)
+
+if(NOT SDL_BUILDING_LIBRARY)
+ if(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework")
+ # Non-OS X framework versions expect you to also dynamically link to
+ # SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms
+ # seem to provide SDLmain for compatibility even though they don't
+ # necessarily need it.
+ find_library(SDLMAIN_LIBRARY
+ NAMES SDLmain SDLmain-1.1
+ HINTS
+ ENV SDLDIR
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+ PATHS
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ )
+ endif()
+endif()
+
+# SDL may require threads on your system.
+# The Apple build may not need an explicit flag because one of the
+# frameworks may already provide it.
+# But for non-OSX systems, I will use the CMake Threads package.
+if(NOT APPLE)
+ find_package(Threads)
+endif()
+
+# MinGW needs an additional library, mwindows
+# It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows
+# (Actually on second look, I think it only needs one of the m* libraries.)
+if(MINGW)
+ set(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
+endif()
+
+if(SDL_LIBRARY_TEMP)
+ # For SDLmain
+ if(SDLMAIN_LIBRARY AND NOT SDL_BUILDING_LIBRARY)
+ list(FIND SDL_LIBRARY_TEMP "${SDLMAIN_LIBRARY}" _SDL_MAIN_INDEX)
+ if(_SDL_MAIN_INDEX EQUAL -1)
+ set(SDL_LIBRARY_TEMP "${SDLMAIN_LIBRARY}" ${SDL_LIBRARY_TEMP})
+ endif()
+ unset(_SDL_MAIN_INDEX)
+ endif()
+
+ # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa.
+ # CMake doesn't display the -framework Cocoa string in the UI even
+ # though it actually is there if I modify a pre-used variable.
+ # I think it has something to do with the CACHE STRING.
+ # So I use a temporary variable until the end so I can set the
+ # "real" variable in one-shot.
+ if(APPLE)
+ set(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa")
+ endif()
+
+ # For threads, as mentioned Apple doesn't need this.
+ # In fact, there seems to be a problem if I used the Threads package
+ # and try using this line, so I'm just skipping it entirely for OS X.
+ if(NOT APPLE)
+ set(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
+ endif()
+
+ # For MinGW library
+ if(MINGW)
+ set(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP})
+ endif()
+
+ # Set the final string here so the GUI reflects the final state.
+ set(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
+ # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
+ set(SDL_LIBRARY_TEMP "${SDL_LIBRARY_TEMP}" CACHE INTERNAL "")
+endif()
+
+if(SDL_INCLUDE_DIR AND EXISTS "${SDL_INCLUDE_DIR}/SDL_version.h")
+ file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" SDL_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" SDL_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" SDL_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MAJOR "${SDL_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MINOR "${SDL_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_VERSION_PATCH "${SDL_VERSION_PATCH_LINE}")
+ set(SDL_VERSION_STRING ${SDL_VERSION_MAJOR}.${SDL_VERSION_MINOR}.${SDL_VERSION_PATCH})
+ unset(SDL_VERSION_MAJOR_LINE)
+ unset(SDL_VERSION_MINOR_LINE)
+ unset(SDL_VERSION_PATCH_LINE)
+ unset(SDL_VERSION_MAJOR)
+ unset(SDL_VERSION_MINOR)
+ unset(SDL_VERSION_PATCH)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL
+ REQUIRED_VARS SDL_LIBRARY SDL_INCLUDE_DIR
+ VERSION_VAR SDL_VERSION_STRING)
diff --git a/Modules/FindSDL_image.cmake b/Modules/FindSDL_image.cmake
new file mode 100644
index 0000000000..fc2c043578
--- /dev/null
+++ b/Modules/FindSDL_image.cmake
@@ -0,0 +1,110 @@
+#.rst:
+# FindSDL_image
+# -------------
+#
+# Locate SDL_image library
+#
+# This module defines:
+#
+# ::
+#
+# SDL_IMAGE_LIBRARIES, the name of the library to link against
+# SDL_IMAGE_INCLUDE_DIRS, where to find the headers
+# SDL_IMAGE_FOUND, if false, do not try to link against
+# SDL_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image
+#
+#
+#
+# For backward compatiblity the following variables are also set:
+#
+# ::
+#
+# SDLIMAGE_LIBRARY (same value as SDL_IMAGE_LIBRARIES)
+# SDLIMAGE_INCLUDE_DIR (same value as SDL_IMAGE_INCLUDE_DIRS)
+# SDLIMAGE_FOUND (same value as SDL_IMAGE_FOUND)
+#
+#
+#
+# $SDLDIR is an environment variable that would correspond to the
+# ./configure --prefix=$SDLDIR used in building SDL.
+#
+# Created by Eric Wing. This was influenced by the FindSDL.cmake
+# module, but with modifications to recognize OS X frameworks and
+# additional Unix paths (FreeBSD, etc).
+
+#=============================================================================
+# Copyright 2005-2009 Kitware, Inc.
+# Copyright 2012 Benjamin Eikel
+#
+# 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.)
+
+if(NOT SDL_IMAGE_INCLUDE_DIR AND SDLIMAGE_INCLUDE_DIR)
+ set(SDL_IMAGE_INCLUDE_DIR ${SDLIMAGE_INCLUDE_DIR} CACHE PATH "directory cache
+entry initialized from old variable name")
+endif()
+find_path(SDL_IMAGE_INCLUDE_DIR SDL_image.h
+ HINTS
+ ENV SDLIMAGEDIR
+ ENV SDLDIR
+ PATH_SUFFIXES SDL
+ # path suffixes to search inside ENV{SDLDIR}
+ include/SDL include/SDL12 include/SDL11 include
+)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+ set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+if(NOT SDL_IMAGE_LIBRARY AND SDLIMAGE_LIBRARY)
+ set(SDL_IMAGE_LIBRARY ${SDLIMAGE_LIBRARY} CACHE FILEPATH "file cache entry
+initialized from old variable name")
+endif()
+find_library(SDL_IMAGE_LIBRARY
+ NAMES SDL_image
+ HINTS
+ ENV SDLIMAGEDIR
+ ENV SDLDIR
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+)
+
+if(SDL_IMAGE_INCLUDE_DIR AND EXISTS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h")
+ file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_MAJOR "${SDL_IMAGE_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_MINOR "${SDL_IMAGE_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_PATCH "${SDL_IMAGE_VERSION_PATCH_LINE}")
+ set(SDL_IMAGE_VERSION_STRING ${SDL_IMAGE_VERSION_MAJOR}.${SDL_IMAGE_VERSION_MINOR}.${SDL_IMAGE_VERSION_PATCH})
+ unset(SDL_IMAGE_VERSION_MAJOR_LINE)
+ unset(SDL_IMAGE_VERSION_MINOR_LINE)
+ unset(SDL_IMAGE_VERSION_PATCH_LINE)
+ unset(SDL_IMAGE_VERSION_MAJOR)
+ unset(SDL_IMAGE_VERSION_MINOR)
+ unset(SDL_IMAGE_VERSION_PATCH)
+endif()
+
+set(SDL_IMAGE_LIBRARIES ${SDL_IMAGE_LIBRARY})
+set(SDL_IMAGE_INCLUDE_DIRS ${SDL_IMAGE_INCLUDE_DIR})
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_image
+ REQUIRED_VARS SDL_IMAGE_LIBRARIES SDL_IMAGE_INCLUDE_DIRS
+ VERSION_VAR SDL_IMAGE_VERSION_STRING)
+
+# for backward compatiblity
+set(SDLIMAGE_LIBRARY ${SDL_IMAGE_LIBRARIES})
+set(SDLIMAGE_INCLUDE_DIR ${SDL_IMAGE_INCLUDE_DIRS})
+set(SDLIMAGE_FOUND ${SDL_IMAGE_FOUND})
+
+mark_as_advanced(SDL_IMAGE_LIBRARY SDL_IMAGE_INCLUDE_DIR)
diff --git a/Modules/FindSDL_mixer.cmake b/Modules/FindSDL_mixer.cmake
new file mode 100644
index 0000000000..176fee6917
--- /dev/null
+++ b/Modules/FindSDL_mixer.cmake
@@ -0,0 +1,110 @@
+#.rst:
+# FindSDL_mixer
+# -------------
+#
+# Locate SDL_mixer library
+#
+# This module defines:
+#
+# ::
+#
+# SDL_MIXER_LIBRARIES, the name of the library to link against
+# SDL_MIXER_INCLUDE_DIRS, where to find the headers
+# SDL_MIXER_FOUND, if false, do not try to link against
+# SDL_MIXER_VERSION_STRING - human-readable string containing the version of SDL_mixer
+#
+#
+#
+# For backward compatiblity the following variables are also set:
+#
+# ::
+#
+# SDLMIXER_LIBRARY (same value as SDL_MIXER_LIBRARIES)
+# SDLMIXER_INCLUDE_DIR (same value as SDL_MIXER_INCLUDE_DIRS)
+# SDLMIXER_FOUND (same value as SDL_MIXER_FOUND)
+#
+#
+#
+# $SDLDIR is an environment variable that would correspond to the
+# ./configure --prefix=$SDLDIR used in building SDL.
+#
+# Created by Eric Wing. This was influenced by the FindSDL.cmake
+# module, but with modifications to recognize OS X frameworks and
+# additional Unix paths (FreeBSD, etc).
+
+#=============================================================================
+# Copyright 2005-2009 Kitware, Inc.
+# Copyright 2012 Benjamin Eikel
+#
+# 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.)
+
+if(NOT SDL_MIXER_INCLUDE_DIR AND SDLMIXER_INCLUDE_DIR)
+ set(SDL_MIXER_INCLUDE_DIR ${SDLMIXER_INCLUDE_DIR} CACHE PATH "directory cache
+entry initialized from old variable name")
+endif()
+find_path(SDL_MIXER_INCLUDE_DIR SDL_mixer.h
+ HINTS
+ ENV SDLMIXERDIR
+ ENV SDLDIR
+ PATH_SUFFIXES SDL
+ # path suffixes to search inside ENV{SDLDIR}
+ include/SDL include/SDL12 include/SDL11 include
+)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+ set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+if(NOT SDL_MIXER_LIBRARY AND SDLMIXER_LIBRARY)
+ set(SDL_MIXER_LIBRARY ${SDLMIXER_LIBRARY} CACHE FILEPATH "file cache entry
+initialized from old variable name")
+endif()
+find_library(SDL_MIXER_LIBRARY
+ NAMES SDL_mixer
+ HINTS
+ ENV SDLMIXERDIR
+ ENV SDLDIR
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+)
+
+if(SDL_MIXER_INCLUDE_DIR AND EXISTS "${SDL_MIXER_INCLUDE_DIR}/SDL_mixer.h")
+ file(STRINGS "${SDL_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_MIXER_VERSION_MAJOR "${SDL_MIXER_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_MIXER_VERSION_MINOR "${SDL_MIXER_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_MIXER_VERSION_PATCH "${SDL_MIXER_VERSION_PATCH_LINE}")
+ set(SDL_MIXER_VERSION_STRING ${SDL_MIXER_VERSION_MAJOR}.${SDL_MIXER_VERSION_MINOR}.${SDL_MIXER_VERSION_PATCH})
+ unset(SDL_MIXER_VERSION_MAJOR_LINE)
+ unset(SDL_MIXER_VERSION_MINOR_LINE)
+ unset(SDL_MIXER_VERSION_PATCH_LINE)
+ unset(SDL_MIXER_VERSION_MAJOR)
+ unset(SDL_MIXER_VERSION_MINOR)
+ unset(SDL_MIXER_VERSION_PATCH)
+endif()
+
+set(SDL_MIXER_LIBRARIES ${SDL_MIXER_LIBRARY})
+set(SDL_MIXER_INCLUDE_DIRS ${SDL_MIXER_INCLUDE_DIR})
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_mixer
+ REQUIRED_VARS SDL_MIXER_LIBRARIES SDL_MIXER_INCLUDE_DIRS
+ VERSION_VAR SDL_MIXER_VERSION_STRING)
+
+# for backward compatiblity
+set(SDLMIXER_LIBRARY ${SDL_MIXER_LIBRARIES})
+set(SDLMIXER_INCLUDE_DIR ${SDL_MIXER_INCLUDE_DIRS})
+set(SDLMIXER_FOUND ${SDL_MIXER_FOUND})
+
+mark_as_advanced(SDL_MIXER_LIBRARY SDL_MIXER_INCLUDE_DIR)
diff --git a/Modules/FindSDL_net.cmake b/Modules/FindSDL_net.cmake
new file mode 100644
index 0000000000..ef23573e87
--- /dev/null
+++ b/Modules/FindSDL_net.cmake
@@ -0,0 +1,110 @@
+#.rst:
+# FindSDL_net
+# -----------
+#
+# Locate SDL_net library
+#
+# This module defines:
+#
+# ::
+#
+# SDL_NET_LIBRARIES, the name of the library to link against
+# SDL_NET_INCLUDE_DIRS, where to find the headers
+# SDL_NET_FOUND, if false, do not try to link against
+# SDL_NET_VERSION_STRING - human-readable string containing the version of SDL_net
+#
+#
+#
+# For backward compatiblity the following variables are also set:
+#
+# ::
+#
+# SDLNET_LIBRARY (same value as SDL_NET_LIBRARIES)
+# SDLNET_INCLUDE_DIR (same value as SDL_NET_INCLUDE_DIRS)
+# SDLNET_FOUND (same value as SDL_NET_FOUND)
+#
+#
+#
+# $SDLDIR is an environment variable that would correspond to the
+# ./configure --prefix=$SDLDIR used in building SDL.
+#
+# Created by Eric Wing. This was influenced by the FindSDL.cmake
+# module, but with modifications to recognize OS X frameworks and
+# additional Unix paths (FreeBSD, etc).
+
+#=============================================================================
+# Copyright 2005-2009 Kitware, Inc.
+# Copyright 2012 Benjamin Eikel
+#
+# 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.)
+
+if(NOT SDL_NET_INCLUDE_DIR AND SDLNET_INCLUDE_DIR)
+ set(SDL_NET_INCLUDE_DIR ${SDLNET_INCLUDE_DIR} CACHE PATH "directory cache
+entry initialized from old variable name")
+endif()
+find_path(SDL_NET_INCLUDE_DIR SDL_net.h
+ HINTS
+ ENV SDLNETDIR
+ ENV SDLDIR
+ PATH_SUFFIXES SDL
+ # path suffixes to search inside ENV{SDLDIR}
+ include/SDL include/SDL12 include/SDL11 include
+)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+ set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+if(NOT SDL_NET_LIBRARY AND SDLNET_LIBRARY)
+ set(SDL_NET_LIBRARY ${SDLNET_LIBRARY} CACHE FILEPATH "file cache entry
+initialized from old variable name")
+endif()
+find_library(SDL_NET_LIBRARY
+ NAMES SDL_net
+ HINTS
+ ENV SDLNETDIR
+ ENV SDLDIR
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+)
+
+if(SDL_NET_INCLUDE_DIR AND EXISTS "${SDL_NET_INCLUDE_DIR}/SDL_net.h")
+ file(STRINGS "${SDL_NET_INCLUDE_DIR}/SDL_net.h" SDL_NET_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_NET_INCLUDE_DIR}/SDL_net.h" SDL_NET_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_NET_INCLUDE_DIR}/SDL_net.h" SDL_NET_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_NET_VERSION_MAJOR "${SDL_NET_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_NET_VERSION_MINOR "${SDL_NET_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_NET_VERSION_PATCH "${SDL_NET_VERSION_PATCH_LINE}")
+ set(SDL_NET_VERSION_STRING ${SDL_NET_VERSION_MAJOR}.${SDL_NET_VERSION_MINOR}.${SDL_NET_VERSION_PATCH})
+ unset(SDL_NET_VERSION_MAJOR_LINE)
+ unset(SDL_NET_VERSION_MINOR_LINE)
+ unset(SDL_NET_VERSION_PATCH_LINE)
+ unset(SDL_NET_VERSION_MAJOR)
+ unset(SDL_NET_VERSION_MINOR)
+ unset(SDL_NET_VERSION_PATCH)
+endif()
+
+set(SDL_NET_LIBRARIES ${SDL_NET_LIBRARY})
+set(SDL_NET_INCLUDE_DIRS ${SDL_NET_INCLUDE_DIR})
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_net
+ REQUIRED_VARS SDL_NET_LIBRARIES SDL_NET_INCLUDE_DIRS
+ VERSION_VAR SDL_NET_VERSION_STRING)
+
+# for backward compatiblity
+set(SDLNET_LIBRARY ${SDL_NET_LIBRARIES})
+set(SDLNET_INCLUDE_DIR ${SDL_NET_INCLUDE_DIRS})
+set(SDLNET_FOUND ${SDL_NET_FOUND})
+
+mark_as_advanced(SDL_NET_LIBRARY SDL_NET_INCLUDE_DIR)
diff --git a/Modules/FindSDL_sound.cmake b/Modules/FindSDL_sound.cmake
new file mode 100644
index 0000000000..5fa40a5d32
--- /dev/null
+++ b/Modules/FindSDL_sound.cmake
@@ -0,0 +1,407 @@
+#.rst:
+# FindSDL_sound
+# -------------
+#
+# Locates the SDL_sound library
+#
+#
+#
+# This module depends on SDL being found and must be called AFTER
+# FindSDL.cmake is called.
+#
+# This module defines
+#
+# ::
+#
+# SDL_SOUND_INCLUDE_DIR, where to find SDL_sound.h
+# SDL_SOUND_FOUND, if false, do not try to link to SDL_sound
+# SDL_SOUND_LIBRARIES, this contains the list of libraries that you need
+# to link against. This is a read-only variable and is marked INTERNAL.
+# SDL_SOUND_EXTRAS, this is an optional variable for you to add your own
+# flags to SDL_SOUND_LIBRARIES. This is prepended to SDL_SOUND_LIBRARIES.
+# This is available mostly for cases this module failed to anticipate for
+# and you must add additional flags. This is marked as ADVANCED.
+# SDL_SOUND_VERSION_STRING, human-readable string containing the version of SDL_sound
+#
+#
+#
+# This module also defines (but you shouldn't need to use directly)
+#
+# ::
+#
+# SDL_SOUND_LIBRARY, the name of just the SDL_sound library you would link
+# against. Use SDL_SOUND_LIBRARIES for you link instructions and not this one.
+#
+# And might define the following as needed
+#
+# ::
+#
+# MIKMOD_LIBRARY
+# MODPLUG_LIBRARY
+# OGG_LIBRARY
+# VORBIS_LIBRARY
+# SMPEG_LIBRARY
+# FLAC_LIBRARY
+# SPEEX_LIBRARY
+#
+#
+#
+# Typically, you should not use these variables directly, and you should
+# use SDL_SOUND_LIBRARIES which contains SDL_SOUND_LIBRARY and the other
+# audio libraries (if needed) to successfully compile on your system.
+#
+# Created by Eric Wing. This module is a bit more complicated than the
+# other FindSDL* family modules. The reason is that SDL_sound can be
+# compiled in a large variety of different ways which are independent of
+# platform. SDL_sound may dynamically link against other 3rd party
+# libraries to get additional codec support, such as Ogg Vorbis, SMPEG,
+# ModPlug, MikMod, FLAC, Speex, and potentially others. Under some
+# circumstances which I don't fully understand, there seems to be a
+# requirement that dependent libraries of libraries you use must also be
+# explicitly linked against in order to successfully compile. SDL_sound
+# does not currently have any system in place to know how it was
+# compiled. So this CMake module does the hard work in trying to
+# discover which 3rd party libraries are required for building (if any).
+# This module uses a brute force approach to create a test program that
+# uses SDL_sound, and then tries to build it. If the build fails, it
+# parses the error output for known symbol names to figure out which
+# libraries are needed.
+#
+# Responds to the $SDLDIR and $SDLSOUNDDIR environmental variable that
+# would correspond to the ./configure --prefix=$SDLDIR used in building
+# SDL.
+#
+# On OSX, this will prefer the Framework version (if found) over others.
+# People will have to manually change the cache values of SDL_LIBRARY to
+# override this selectionor set the CMake environment CMAKE_INCLUDE_PATH
+# to modify the search paths.
+
+#=============================================================================
+# Copyright 2005-2009 Kitware, Inc.
+# Copyright 2012 Benjamin Eikel
+#
+# 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.)
+
+set(SDL_SOUND_EXTRAS "" CACHE STRING "SDL_sound extra flags")
+mark_as_advanced(SDL_SOUND_EXTRAS)
+
+# Find SDL_sound.h
+find_path(SDL_SOUND_INCLUDE_DIR SDL_sound.h
+ HINTS
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ PATH_SUFFIXES SDL
+ # path suffixes to search inside ENV{SDLDIR}
+ include/SDL include/SDL12 include/SDL11 include
+ )
+
+find_library(SDL_SOUND_LIBRARY
+ NAMES SDL_sound
+ HINTS
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ PATH_SUFFIXES lib VisualC/win32lib
+ )
+
+if(SDL_FOUND AND SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY)
+
+ # CMake is giving me problems using TRY_COMPILE with the CMAKE_FLAGS
+ # for the :STRING syntax if I have multiple values contained in a
+ # single variable. This is a problem for the SDL_LIBRARY variable
+ # because it does just that. When I feed this variable to the command,
+ # only the first value gets the appropriate modifier (e.g. -I) and
+ # the rest get dropped.
+ # To get multiple single variables to work, I must separate them with a "\;"
+ # I could go back and modify the FindSDL.cmake module, but that's kind of painful.
+ # The solution would be to try something like:
+ # set(SDL_TRY_COMPILE_LIBRARY_LIST "${SDL_TRY_COMPILE_LIBRARY_LIST}\;${CMAKE_THREAD_LIBS_INIT}")
+ # Instead, it was suggested on the mailing list to write a temporary CMakeLists.txt
+ # with a temporary test project and invoke that with TRY_COMPILE.
+ # See message thread "Figuring out dependencies for a library in order to build"
+ # 2005-07-16
+ # try_compile(
+ # MY_RESULT
+ # ${CMAKE_BINARY_DIR}
+ # ${PROJECT_SOURCE_DIR}/DetermineSoundLibs.c
+ # CMAKE_FLAGS
+ # -DINCLUDE_DIRECTORIES:STRING=${SDL_INCLUDE_DIR}\;${SDL_SOUND_INCLUDE_DIR}
+ # -DLINK_LIBRARIES:STRING=${SDL_SOUND_LIBRARY}\;${SDL_LIBRARY}
+ # OUTPUT_VARIABLE MY_OUTPUT
+ # )
+
+ # To minimize external dependencies, create a sdlsound test program
+ # which will be used to figure out if additional link dependencies are
+ # required for the link phase.
+ file(WRITE ${PROJECT_BINARY_DIR}/CMakeTmp/DetermineSoundLibs.c
+ "#include \"SDL_sound.h\"
+ #include \"SDL.h\"
+ int main(int argc, char* argv[])
+ {
+ Sound_AudioInfo desired;
+ Sound_Sample* sample;
+
+ SDL_Init(0);
+ Sound_Init();
+
+ /* This doesn't actually have to work, but Init() is a no-op
+ * for some of the decoders, so this should force more symbols
+ * to be pulled in.
+ */
+ sample = Sound_NewSampleFromFile(argv[1], &desired, 4096);
+
+ Sound_Quit();
+ SDL_Quit();
+ return 0;
+ }"
+ )
+
+ # Calling
+ # target_link_libraries(DetermineSoundLibs "${SDL_SOUND_LIBRARY} ${SDL_LIBRARY})
+ # causes problems when SDL_LIBRARY looks like
+ # /Library/Frameworks/SDL.framework;-framework Cocoa
+ # The ;-framework Cocoa seems to be confusing CMake once the OS X
+ # framework support was added. I was told that breaking up the list
+ # would fix the problem.
+ set(TMP_TRY_LIBS)
+ foreach(lib ${SDL_SOUND_LIBRARY} ${SDL_LIBRARY})
+ set(TMP_TRY_LIBS "${TMP_TRY_LIBS} \"${lib}\"")
+ endforeach()
+
+ # message("TMP_TRY_LIBS ${TMP_TRY_LIBS}")
+
+ # Write the CMakeLists.txt and test project
+ # Weird, this is still sketchy. If I don't quote the variables
+ # in the TARGET_LINK_LIBRARIES, I seem to loose everything
+ # in the SDL_LIBRARY string after the "-framework".
+ # But if I quote the stuff in INCLUDE_DIRECTORIES, it doesn't work.
+ file(WRITE ${PROJECT_BINARY_DIR}/CMakeTmp/CMakeLists.txt
+ "cmake_minimum_required(VERSION ${CMAKE_VERSION})
+ project(DetermineSoundLibs)
+ include_directories(${SDL_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
+ add_executable(DetermineSoundLibs DetermineSoundLibs.c)
+ target_link_libraries(DetermineSoundLibs ${TMP_TRY_LIBS})"
+ )
+
+ try_compile(
+ MY_RESULT
+ ${PROJECT_BINARY_DIR}/CMakeTmp
+ ${PROJECT_BINARY_DIR}/CMakeTmp
+ DetermineSoundLibs
+ OUTPUT_VARIABLE MY_OUTPUT
+ )
+
+ # message("${MY_RESULT}")
+ # message(${MY_OUTPUT})
+
+ if(NOT MY_RESULT)
+
+ # I expect that MPGLIB, VOC, WAV, AIFF, and SHN are compiled in statically.
+ # I think Timidity is also compiled in statically.
+ # I've never had to explcitly link against Quicktime, so I'll skip that for now.
+
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARY})
+
+ # Find MikMod
+ if("${MY_OUTPUT}" MATCHES "MikMod_")
+ find_library(MIKMOD_LIBRARY
+ NAMES libmikmod-coreaudio mikmod
+ PATHS
+ ENV MIKMODDIR
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES
+ lib
+ )
+ if(MIKMOD_LIBRARY)
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${MIKMOD_LIBRARY})
+ endif(MIKMOD_LIBRARY)
+ endif("${MY_OUTPUT}" MATCHES "MikMod_")
+
+ # Find ModPlug
+ if("${MY_OUTPUT}" MATCHES "MODPLUG_")
+ find_library(MODPLUG_LIBRARY
+ NAMES modplug
+ PATHS
+ ENV MODPLUGDIR
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES
+ lib
+ )
+ if(MODPLUG_LIBRARY)
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${MODPLUG_LIBRARY})
+ endif()
+ endif()
+
+
+ # Find Ogg and Vorbis
+ if("${MY_OUTPUT}" MATCHES "ov_")
+ find_library(VORBIS_LIBRARY
+ NAMES vorbis Vorbis VORBIS
+ PATHS
+ ENV VORBISDIR
+ ENV OGGDIR
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES
+ lib
+ )
+ if(VORBIS_LIBRARY)
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${VORBIS_LIBRARY})
+ endif()
+
+ find_library(OGG_LIBRARY
+ NAMES ogg Ogg OGG
+ PATHS
+ ENV OGGDIR
+ ENV VORBISDIR
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES
+ lib
+ )
+ if(OGG_LIBRARY)
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${OGG_LIBRARY})
+ endif()
+ endif()
+
+
+ # Find SMPEG
+ if("${MY_OUTPUT}" MATCHES "SMPEG_")
+ find_library(SMPEG_LIBRARY
+ NAMES smpeg SMPEG Smpeg SMpeg
+ PATHS
+ ENV SMPEGDIR
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES
+ lib
+ )
+ if(SMPEG_LIBRARY)
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${SMPEG_LIBRARY})
+ endif()
+ endif()
+
+
+ # Find FLAC
+ if("${MY_OUTPUT}" MATCHES "FLAC_")
+ find_library(FLAC_LIBRARY
+ NAMES flac FLAC
+ PATHS
+ ENV FLACDIR
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES
+ lib
+ )
+ if(FLAC_LIBRARY)
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${FLAC_LIBRARY})
+ endif()
+ endif()
+
+
+ # Hmmm...Speex seems to depend on Ogg. This might be a problem if
+ # the TRY_COMPILE attempt gets blocked at SPEEX before it can pull
+ # in the Ogg symbols. I'm not sure if I should duplicate the ogg stuff
+ # above for here or if two ogg entries will screw up things.
+ if("${MY_OUTPUT}" MATCHES "speex_")
+ find_library(SPEEX_LIBRARY
+ NAMES speex SPEEX
+ PATHS
+ ENV SPEEXDIR
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES
+ lib
+ )
+ if(SPEEX_LIBRARY)
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${SPEEX_LIBRARY})
+ endif()
+
+ # Find OGG (needed for Speex)
+ # We might have already found Ogg for Vorbis, so skip it if so.
+ if(NOT OGG_LIBRARY)
+ find_library(OGG_LIBRARY
+ NAMES ogg Ogg OGG
+ PATHS
+ ENV OGGDIR
+ ENV VORBISDIR
+ ENV SPEEXDIR
+ ENV SDLSOUNDDIR
+ ENV SDLDIR
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES lib
+ )
+ if(OGG_LIBRARY)
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${OGG_LIBRARY})
+ endif()
+ endif()
+ endif()
+
+ else()
+ set(SDL_SOUND_LIBRARIES "${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARY}" CACHE INTERNAL "SDL_sound and dependent libraries")
+ endif()
+
+ set(SDL_SOUND_LIBRARIES "${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARIES_TMP}" CACHE INTERNAL "SDL_sound and dependent libraries")
+ endif()
+
+if(SDL_SOUND_INCLUDE_DIR AND EXISTS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h")
+ file(STRINGS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h" SDL_SOUND_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SOUND_VER_MAJOR[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h" SDL_SOUND_VERSION_MINOR_LINE REGEX "^#define[ \t]+SOUND_VER_MINOR[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h" SDL_SOUND_VERSION_PATCH_LINE REGEX "^#define[ \t]+SOUND_VER_PATCH[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+SOUND_VER_MAJOR[ \t]+([0-9]+)$" "\\1" SDL_SOUND_VERSION_MAJOR "${SDL_SOUND_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SOUND_VER_MINOR[ \t]+([0-9]+)$" "\\1" SDL_SOUND_VERSION_MINOR "${SDL_SOUND_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SOUND_VER_PATCH[ \t]+([0-9]+)$" "\\1" SDL_SOUND_VERSION_PATCH "${SDL_SOUND_VERSION_PATCH_LINE}")
+ set(SDL_SOUND_VERSION_STRING ${SDL_SOUND_VERSION_MAJOR}.${SDL_SOUND_VERSION_MINOR}.${SDL_SOUND_VERSION_PATCH})
+ unset(SDL_SOUND_VERSION_MAJOR_LINE)
+ unset(SDL_SOUND_VERSION_MINOR_LINE)
+ unset(SDL_SOUND_VERSION_PATCH_LINE)
+ unset(SDL_SOUND_VERSION_MAJOR)
+ unset(SDL_SOUND_VERSION_MINOR)
+ unset(SDL_SOUND_VERSION_PATCH)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_sound
+ REQUIRED_VARS SDL_SOUND_LIBRARY SDL_SOUND_INCLUDE_DIR
+ VERSION_VAR SDL_SOUND_VERSION_STRING)
diff --git a/Modules/FindSDL_ttf.cmake b/Modules/FindSDL_ttf.cmake
new file mode 100644
index 0000000000..4b527fabee
--- /dev/null
+++ b/Modules/FindSDL_ttf.cmake
@@ -0,0 +1,110 @@
+#.rst:
+# FindSDL_ttf
+# -----------
+#
+# Locate SDL_ttf library
+#
+# This module defines:
+#
+# ::
+#
+# SDL_TTF_LIBRARIES, the name of the library to link against
+# SDL_TTF_INCLUDE_DIRS, where to find the headers
+# SDL_TTF_FOUND, if false, do not try to link against
+# SDL_TTF_VERSION_STRING - human-readable string containing the version of SDL_ttf
+#
+#
+#
+# For backward compatiblity the following variables are also set:
+#
+# ::
+#
+# SDLTTF_LIBRARY (same value as SDL_TTF_LIBRARIES)
+# SDLTTF_INCLUDE_DIR (same value as SDL_TTF_INCLUDE_DIRS)
+# SDLTTF_FOUND (same value as SDL_TTF_FOUND)
+#
+#
+#
+# $SDLDIR is an environment variable that would correspond to the
+# ./configure --prefix=$SDLDIR used in building SDL.
+#
+# Created by Eric Wing. This was influenced by the FindSDL.cmake
+# module, but with modifications to recognize OS X frameworks and
+# additional Unix paths (FreeBSD, etc).
+
+#=============================================================================
+# Copyright 2005-2009 Kitware, Inc.
+# Copyright 2012 Benjamin Eikel
+#
+# 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.)
+
+if(NOT SDL_TTF_INCLUDE_DIR AND SDLTTF_INCLUDE_DIR)
+ set(SDL_TTF_INCLUDE_DIR ${SDLTTF_INCLUDE_DIR} CACHE PATH "directory cache
+entry initialized from old variable name")
+endif()
+find_path(SDL_TTF_INCLUDE_DIR SDL_ttf.h
+ HINTS
+ ENV SDLTTFDIR
+ ENV SDLDIR
+ PATH_SUFFIXES SDL
+ # path suffixes to search inside ENV{SDLDIR}
+ include/SDL include/SDL12 include/SDL11 include
+)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+ set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+if(NOT SDL_TTF_LIBRARY AND SDLTTF_LIBRARY)
+ set(SDL_TTF_LIBRARY ${SDLTTF_LIBRARY} CACHE FILEPATH "file cache entry
+initialized from old variable name")
+endif()
+find_library(SDL_TTF_LIBRARY
+ NAMES SDL_ttf
+ HINTS
+ ENV SDLTTFDIR
+ ENV SDLDIR
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+)
+
+if(SDL_TTF_INCLUDE_DIR AND EXISTS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h")
+ file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_MAJOR "${SDL_TTF_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_MINOR "${SDL_TTF_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_PATCH "${SDL_TTF_VERSION_PATCH_LINE}")
+ set(SDL_TTF_VERSION_STRING ${SDL_TTF_VERSION_MAJOR}.${SDL_TTF_VERSION_MINOR}.${SDL_TTF_VERSION_PATCH})
+ unset(SDL_TTF_VERSION_MAJOR_LINE)
+ unset(SDL_TTF_VERSION_MINOR_LINE)
+ unset(SDL_TTF_VERSION_PATCH_LINE)
+ unset(SDL_TTF_VERSION_MAJOR)
+ unset(SDL_TTF_VERSION_MINOR)
+ unset(SDL_TTF_VERSION_PATCH)
+endif()
+
+set(SDL_TTF_LIBRARIES ${SDL_TTF_LIBRARY})
+set(SDL_TTF_INCLUDE_DIRS ${SDL_TTF_INCLUDE_DIR})
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_ttf
+ REQUIRED_VARS SDL_TTF_LIBRARIES SDL_TTF_INCLUDE_DIRS
+ VERSION_VAR SDL_TTF_VERSION_STRING)
+
+# for backward compatiblity
+set(SDLTTF_LIBRARY ${SDL_TTF_LIBRARIES})
+set(SDLTTF_INCLUDE_DIR ${SDL_TTF_INCLUDE_DIRS})
+set(SDLTTF_FOUND ${SDL_TTF_FOUND})
+
+mark_as_advanced(SDL_TTF_LIBRARY SDL_TTF_INCLUDE_DIR)
diff --git a/Modules/FindSWIG.cmake b/Modules/FindSWIG.cmake
new file mode 100644
index 0000000000..818d1f213d
--- /dev/null
+++ b/Modules/FindSWIG.cmake
@@ -0,0 +1,78 @@
+#.rst:
+# FindSWIG
+# --------
+#
+# Find SWIG
+#
+# This module finds an installed SWIG. It sets the following variables:
+#
+# ::
+#
+# SWIG_FOUND - set to true if SWIG is found
+# SWIG_DIR - the directory where swig is installed
+# SWIG_EXECUTABLE - the path to the swig executable
+# SWIG_VERSION - the version number of the swig executable
+#
+#
+#
+# The minimum required version of SWIG can be specified using the
+# standard syntax, e.g. find_package(SWIG 1.1)
+#
+# All information is collected from the SWIG_EXECUTABLE so the version
+# to be found can be changed from the command line by means of setting
+# SWIG_EXECUTABLE
+
+#=============================================================================
+# Copyright 2004-2009 Kitware, Inc.
+# Copyright 2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
+# Copyright 2014 Sylvain Joubert <joubert.sy@gmail.com>
+#
+# 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.)
+
+find_program(SWIG_EXECUTABLE NAMES swig3.0 swig2.0 swig)
+
+if(SWIG_EXECUTABLE)
+ execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
+ OUTPUT_VARIABLE SWIG_swiglib_output
+ ERROR_VARIABLE SWIG_swiglib_error
+ RESULT_VARIABLE SWIG_swiglib_result)
+
+ if(SWIG_swiglib_result)
+ if(SWIG_FIND_REQUIRED)
+ message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
+ else()
+ message(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
+ endif()
+ else()
+ string(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
+ find_path(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output} NO_CMAKE_FIND_ROOT_PATH)
+ if(SWIG_DIR)
+ set(SWIG_USE_FILE ${CMAKE_CURRENT_LIST_DIR}/UseSWIG.cmake)
+ execute_process(COMMAND ${SWIG_EXECUTABLE} -version
+ OUTPUT_VARIABLE SWIG_version_output
+ ERROR_VARIABLE SWIG_version_output
+ RESULT_VARIABLE SWIG_version_result)
+ if(SWIG_version_result)
+ message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
+ else()
+ string(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
+ SWIG_version_output "${SWIG_version_output}")
+ set(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
+ endif()
+ endif()
+ endif()
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWIG REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR
+ VERSION_VAR SWIG_VERSION )
+
+mark_as_advanced(SWIG_DIR SWIG_VERSION)
diff --git a/Modules/FindSelfPackers.cmake b/Modules/FindSelfPackers.cmake
new file mode 100644
index 0000000000..238be89a0a
--- /dev/null
+++ b/Modules/FindSelfPackers.cmake
@@ -0,0 +1,75 @@
+#.rst:
+# FindSelfPackers
+# ---------------
+#
+# Find upx
+#
+# This module looks for some executable packers (i.e. software that
+# compress executables or shared libs into on-the-fly self-extracting
+# executables or shared libs. Examples:
+#
+# ::
+#
+# UPX: http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
+
+find_program(SELF_PACKER_FOR_EXECUTABLE
+ upx
+ ${CYGWIN_INSTALL_PATH}/bin
+ /bin
+ /usr/bin
+ /usr/local/bin
+ /sbin
+)
+
+find_program(SELF_PACKER_FOR_SHARED_LIB
+ upx
+ ${CYGWIN_INSTALL_PATH}/bin
+ /bin
+ /usr/bin
+ /usr/local/bin
+ /sbin
+)
+
+mark_as_advanced(
+ SELF_PACKER_FOR_EXECUTABLE
+ SELF_PACKER_FOR_SHARED_LIB
+)
+
+#
+# Set flags
+#
+if (SELF_PACKER_FOR_EXECUTABLE MATCHES "upx")
+ set (SELF_PACKER_FOR_EXECUTABLE_FLAGS "-q" CACHE STRING
+ "Flags for the executable self-packer.")
+else ()
+ set (SELF_PACKER_FOR_EXECUTABLE_FLAGS "" CACHE STRING
+ "Flags for the executable self-packer.")
+endif ()
+
+if (SELF_PACKER_FOR_SHARED_LIB MATCHES "upx")
+ set (SELF_PACKER_FOR_SHARED_LIB_FLAGS "-q" CACHE STRING
+ "Flags for the shared lib self-packer.")
+else ()
+ set (SELF_PACKER_FOR_SHARED_LIB_FLAGS "" CACHE STRING
+ "Flags for the shared lib self-packer.")
+endif ()
+
+mark_as_advanced(
+ SELF_PACKER_FOR_EXECUTABLE_FLAGS
+ SELF_PACKER_FOR_SHARED_LIB_FLAGS
+)
diff --git a/Modules/FindSquish.cmake b/Modules/FindSquish.cmake
new file mode 100644
index 0000000000..2b7fd22612
--- /dev/null
+++ b/Modules/FindSquish.cmake
@@ -0,0 +1,306 @@
+#.rst:
+# FindSquish
+# ----------
+#
+# -- Typical Use
+#
+#
+#
+# This module can be used to find Squish. Currently Squish versions 3
+# and 4 are supported.
+#
+# ::
+#
+# SQUISH_FOUND If false, don't try to use Squish
+# SQUISH_VERSION The full version of Squish found
+# SQUISH_VERSION_MAJOR The major version of Squish found
+# SQUISH_VERSION_MINOR The minor version of Squish found
+# SQUISH_VERSION_PATCH The patch version of Squish found
+#
+#
+#
+# ::
+#
+# SQUISH_INSTALL_DIR The Squish installation directory (containing bin, lib, etc)
+# SQUISH_SERVER_EXECUTABLE The squishserver executable
+# SQUISH_CLIENT_EXECUTABLE The squishrunner executable
+#
+#
+#
+# ::
+#
+# SQUISH_INSTALL_DIR_FOUND Was the install directory found?
+# SQUISH_SERVER_EXECUTABLE_FOUND Was the server executable found?
+# SQUISH_CLIENT_EXECUTABLE_FOUND Was the client executable found?
+#
+#
+#
+# It provides the function squish_v4_add_test() for adding a squish test
+# to cmake using Squish 4.x:
+#
+# ::
+#
+# squish_v4_add_test(cmakeTestName AUT targetName SUITE suiteName TEST squishTestName
+# [SETTINGSGROUP group] [PRE_COMMAND command] [POST_COMMAND command] )
+#
+#
+#
+# The arguments have the following meaning:
+#
+# ::
+#
+# cmakeTestName: this will be used as the first argument for add_test()
+# AUT targetName: the name of the cmake target which will be used as AUT, i.e. the
+# executable which will be tested.
+# SUITE suiteName: this is either the full path to the squish suite, or just the
+# last directory of the suite, i.e. the suite name. In this case
+# the CMakeLists.txt which calls squish_add_test() must be located
+# in the parent directory of the suite directory.
+# TEST squishTestName: the name of the squish test, i.e. the name of the subdirectory
+# of the test inside the suite directory.
+# SETTINGSGROUP group: if specified, the given settings group will be used for executing the test.
+# If not specified, the groupname will be "CTest_<username>"
+# PRE_COMMAND command: if specified, the given command will be executed before starting the squish test.
+# POST_COMMAND command: same as PRE_COMMAND, but after the squish test has been executed.
+#
+#
+#
+# ::
+#
+# enable_testing()
+# find_package(Squish 4.0)
+# if (SQUISH_FOUND)
+# squish_v4_add_test(myTestName AUT myApp SUITE ${CMAKE_SOURCE_DIR}/tests/mySuite TEST someSquishTest SETTINGSGROUP myGroup )
+# endif ()
+#
+#
+#
+#
+#
+# For users of Squish version 3.x the macro squish_v3_add_test() is
+# provided:
+#
+# ::
+#
+# squish_v3_add_test(testName applicationUnderTest testCase envVars testWrapper)
+# Use this macro to add a test using Squish 3.x.
+#
+#
+#
+# ::
+#
+# enable_testing()
+# find_package(Squish)
+# if (SQUISH_FOUND)
+# squish_v3_add_test(myTestName myApplication testCase envVars testWrapper)
+# endif ()
+#
+#
+#
+# macro SQUISH_ADD_TEST(testName applicationUnderTest testCase envVars
+# testWrapper)
+#
+# ::
+#
+# This is deprecated. Use SQUISH_V3_ADD_TEST() if you are using Squish 3.x instead.
+
+
+#=============================================================================
+# Copyright 2008-2009 Kitware, Inc.
+# Copyright 2012 Alexander Neundorf
+#
+# 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.)
+
+
+include(CMakeParseArguments)
+
+set(SQUISH_INSTALL_DIR_STRING "Directory containing the bin, doc, and lib directories for Squish; this should be the root of the installation directory.")
+set(SQUISH_SERVER_EXECUTABLE_STRING "The squishserver executable program.")
+set(SQUISH_CLIENT_EXECUTABLE_STRING "The squishclient executable program.")
+
+# Search only if the location is not already known.
+if(NOT SQUISH_INSTALL_DIR)
+ # Get the system search path as a list.
+ file(TO_CMAKE_PATH "$ENV{PATH}" SQUISH_INSTALL_DIR_SEARCH2)
+
+ # Construct a set of paths relative to the system search path.
+ set(SQUISH_INSTALL_DIR_SEARCH "")
+ foreach(dir ${SQUISH_INSTALL_DIR_SEARCH2})
+ set(SQUISH_INSTALL_DIR_SEARCH ${SQUISH_INSTALL_DIR_SEARCH} "${dir}/../lib/fltk")
+ endforeach()
+ string(REPLACE "//" "/" SQUISH_INSTALL_DIR_SEARCH "${SQUISH_INSTALL_DIR_SEARCH}")
+
+ # Look for an installation
+ find_path(SQUISH_INSTALL_DIR bin/squishrunner
+ HINTS
+ # Look for an environment variable SQUISH_INSTALL_DIR.
+ ENV SQUISH_INSTALL_DIR
+
+ # Look in places relative to the system executable search path.
+ ${SQUISH_INSTALL_DIR_SEARCH}
+
+ # Look in standard UNIX install locations.
+ #/usr/local/squish
+
+ DOC "The ${SQUISH_INSTALL_DIR_STRING}"
+ )
+endif()
+
+# search for the executables
+if(SQUISH_INSTALL_DIR)
+ set(SQUISH_INSTALL_DIR_FOUND 1)
+
+ # find the client program
+ if(NOT SQUISH_CLIENT_EXECUTABLE)
+ find_program(SQUISH_CLIENT_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishrunner${CMAKE_EXECUTABLE_SUFFIX} DOC "The ${SQUISH_CLIENT_EXECUTABLE_STRING}")
+ endif()
+
+ # find the server program
+ if(NOT SQUISH_SERVER_EXECUTABLE)
+ find_program(SQUISH_SERVER_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishserver${CMAKE_EXECUTABLE_SUFFIX} DOC "The ${SQUISH_SERVER_EXECUTABLE_STRING}")
+ endif()
+
+else()
+ set(SQUISH_INSTALL_DIR_FOUND 0)
+endif()
+
+
+set(SQUISH_VERSION)
+set(SQUISH_VERSION_MAJOR )
+set(SQUISH_VERSION_MINOR )
+set(SQUISH_VERSION_PATCH )
+
+# record if executables are set
+if(SQUISH_CLIENT_EXECUTABLE)
+ set(SQUISH_CLIENT_EXECUTABLE_FOUND 1)
+ execute_process(COMMAND "${SQUISH_CLIENT_EXECUTABLE}" --version
+ OUTPUT_VARIABLE _squishVersionOutput
+ ERROR_QUIET )
+ if("${_squishVersionOutput}" MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
+ set(SQUISH_VERSION_MAJOR "${CMAKE_MATCH_1}")
+ set(SQUISH_VERSION_MINOR "${CMAKE_MATCH_2}")
+ set(SQUISH_VERSION_PATCH "${CMAKE_MATCH_3}")
+ set(SQUISH_VERSION "${SQUISH_VERSION_MAJOR}.${SQUISH_VERSION_MINOR}.${SQUISH_VERSION_PATCH}" )
+ endif()
+else()
+ set(SQUISH_CLIENT_EXECUTABLE_FOUND 0)
+endif()
+
+if(SQUISH_SERVER_EXECUTABLE)
+ set(SQUISH_SERVER_EXECUTABLE_FOUND 1)
+else()
+ set(SQUISH_SERVER_EXECUTABLE_FOUND 0)
+endif()
+
+# record if Squish was found
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(Squish REQUIRED_VARS SQUISH_INSTALL_DIR SQUISH_CLIENT_EXECUTABLE SQUISH_SERVER_EXECUTABLE
+ VERSION_VAR SQUISH_VERSION )
+
+
+set(_SQUISH_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+
+macro(SQUISH_V3_ADD_TEST testName testAUT testCase envVars testWraper)
+ if("${SQUISH_VERSION_MAJOR}" STREQUAL "4")
+ message(STATUS "Using squish_v3_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.")
+ endif()
+
+ add_test(${testName}
+ ${CMAKE_COMMAND} -V -VV
+ "-Dsquish_version:STRING=3"
+ "-Dsquish_aut:STRING=${testAUT}"
+ "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}"
+ "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}"
+ "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}"
+ "-Dsquish_test_case:STRING=${testCase}"
+ "-Dsquish_env_vars:STRING=${envVars}"
+ "-Dsquish_wrapper:STRING=${testWraper}"
+ "-Dsquish_module_dir:STRING=${_SQUISH_MODULE_DIR}"
+ -P "${_SQUISH_MODULE_DIR}/SquishTestScript.cmake"
+ )
+ set_tests_properties(${testName}
+ PROPERTIES FAIL_REGULAR_EXPRESSION "FAILED;ERROR;FATAL"
+ )
+endmacro()
+
+
+macro(SQUISH_ADD_TEST)
+ message(STATUS "Using squish_add_test() is deprecated, use squish_v3_add_test() instead.")
+ squish_v3_add_test(${ARGV})
+endmacro()
+
+
+function(SQUISH_V4_ADD_TEST testName)
+
+ if(NOT "${SQUISH_VERSION_MAJOR}" STREQUAL "4")
+ message(STATUS "Using squish_v4_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.")
+ endif()
+
+ set(oneValueArgs AUT SUITE TEST SETTINGSGROUP PRE_COMMAND POST_COMMAND)
+
+ cmake_parse_arguments(_SQUISH "" "${oneValueArgs}" "" ${ARGN} )
+
+ if(_SQUISH_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown keywords given to SQUISH_ADD_TEST(): \"${_SQUISH_UNPARSED_ARGUMENTS}\"")
+ endif()
+
+ if(NOT _SQUISH_AUT)
+ message(FATAL_ERROR "Required argument AUT not given for SQUISH_ADD_TEST()")
+ endif()
+
+ if(NOT _SQUISH_SUITE)
+ message(FATAL_ERROR "Required argument SUITE not given for SQUISH_ADD_TEST()")
+ endif()
+
+ if(NOT _SQUISH_TEST)
+ message(FATAL_ERROR "Required argument TEST not given for SQUISH_ADD_TEST()")
+ endif()
+
+ get_target_property(testAUTLocation ${_SQUISH_AUT} LOCATION)
+ get_filename_component(testAUTDir ${testAUTLocation} PATH)
+ get_filename_component(testAUTName ${testAUTLocation} NAME)
+
+ get_filename_component(absTestSuite "${_SQUISH_SUITE}" ABSOLUTE)
+ if(NOT EXISTS "${absTestSuite}")
+ message(FATAL_ERROR "Could not find squish test suite ${_SQUISH_SUITE} (checked ${absTestSuite})")
+ endif()
+
+ set(absTestCase "${absTestSuite}/${_SQUISH_TEST}")
+ if(NOT EXISTS "${absTestCase}")
+ message(FATAL_ERROR "Could not find squish testcase ${_SQUISH_TEST} (checked ${absTestCase})")
+ endif()
+
+ if(NOT _SQUISH_SETTINGSGROUP)
+ set(_SQUISH_SETTINGSGROUP "CTest_$ENV{LOGNAME}")
+ endif()
+
+ add_test(${testName}
+ ${CMAKE_COMMAND} -V -VV
+ "-Dsquish_version:STRING=4"
+ "-Dsquish_aut:STRING=${testAUTName}"
+ "-Dsquish_aut_dir:STRING=${testAUTDir}"
+ "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}"
+ "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}"
+ "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}"
+ "-Dsquish_test_suite:STRING=${absTestSuite}"
+ "-Dsquish_test_case:STRING=${_SQUISH_TEST}"
+ "-Dsquish_env_vars:STRING=${envVars}"
+ "-Dsquish_wrapper:STRING=${testWraper}"
+ "-Dsquish_module_dir:STRING=${_SQUISH_MODULE_DIR}"
+ "-Dsquish_settingsgroup:STRING=${_SQUISH_SETTINGSGROUP}"
+ "-Dsquish_pre_command:STRING=${_SQUISH_PRE_COMMAND}"
+ "-Dsquish_post_command:STRING=${_SQUISH_POST_COMMAND}"
+ -P "${_SQUISH_MODULE_DIR}/SquishTestScript.cmake"
+ )
+ set_tests_properties(${testName}
+ PROPERTIES FAIL_REGULAR_EXPRESSION "FAIL;FAILED;ERROR;FATAL"
+ )
+endfunction()
diff --git a/Modules/FindSubversion.cmake b/Modules/FindSubversion.cmake
new file mode 100644
index 0000000000..0d13318bd9
--- /dev/null
+++ b/Modules/FindSubversion.cmake
@@ -0,0 +1,158 @@
+#.rst:
+# FindSubversion
+# --------------
+#
+# Extract information from a subversion working copy
+#
+# The module defines the following variables:
+#
+# ::
+#
+# Subversion_SVN_EXECUTABLE - path to svn command line client
+# Subversion_VERSION_SVN - version of svn command line client
+# Subversion_FOUND - true if the command line client was found
+# SUBVERSION_FOUND - same as Subversion_FOUND, set for compatiblity reasons
+#
+#
+#
+# The minimum required version of Subversion can be specified using the
+# standard syntax, e.g. find_package(Subversion 1.4)
+#
+# If the command line client executable is found two macros are defined:
+#
+# ::
+#
+# Subversion_WC_INFO(<dir> <var-prefix>)
+# Subversion_WC_LOG(<dir> <var-prefix>)
+#
+# Subversion_WC_INFO extracts information of a subversion working copy
+# at a given location. This macro defines the following variables:
+#
+# ::
+#
+# <var-prefix>_WC_URL - url of the repository (at <dir>)
+# <var-prefix>_WC_ROOT - root url of the repository
+# <var-prefix>_WC_REVISION - current revision
+# <var-prefix>_WC_LAST_CHANGED_AUTHOR - author of last commit
+# <var-prefix>_WC_LAST_CHANGED_DATE - date of last commit
+# <var-prefix>_WC_LAST_CHANGED_REV - revision of last commit
+# <var-prefix>_WC_INFO - output of command `svn info <dir>'
+#
+# Subversion_WC_LOG retrieves the log message of the base revision of a
+# subversion working copy at a given location. This macro defines the
+# variable:
+#
+# ::
+#
+# <var-prefix>_LAST_CHANGED_LOG - last log of base revision
+#
+# Example usage:
+#
+# ::
+#
+# find_package(Subversion)
+# if(SUBVERSION_FOUND)
+# Subversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
+# message("Current revision is ${Project_WC_REVISION}")
+# Subversion_WC_LOG(${PROJECT_SOURCE_DIR} Project)
+# message("Last changed log is ${Project_LAST_CHANGED_LOG}")
+# endif()
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Tristan Carel
+#
+# 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.)
+
+find_program(Subversion_SVN_EXECUTABLE svn
+ PATHS
+ [HKEY_LOCAL_MACHINE\\Software\\TortoiseSVN;Directory]/bin
+ DOC "subversion command line client")
+mark_as_advanced(Subversion_SVN_EXECUTABLE)
+
+if(Subversion_SVN_EXECUTABLE)
+ # the subversion commands should be executed with the C locale, otherwise
+ # the message (which are parsed) may be translated, Alex
+ set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
+ set(ENV{LC_ALL} C)
+
+ execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} --version
+ OUTPUT_VARIABLE Subversion_VERSION_SVN
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ # restore the previous LC_ALL
+ set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
+
+ string(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
+ "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
+
+ macro(Subversion_WC_INFO dir prefix)
+ # the subversion commands should be executed with the C locale, otherwise
+ # the message (which are parsed) may be translated, Alex
+ set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
+ set(ENV{LC_ALL} C)
+
+ execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
+ OUTPUT_VARIABLE ${prefix}_WC_INFO
+ ERROR_VARIABLE Subversion_svn_info_error
+ RESULT_VARIABLE Subversion_svn_info_result
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(NOT ${Subversion_svn_info_result} EQUAL 0)
+ message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
+ else()
+
+ string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
+ "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
+ string(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*"
+ "\\2" ${prefix}_WC_ROOT "${${prefix}_WC_INFO}")
+ string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
+ "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
+ string(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
+ "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
+ string(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
+ "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
+ string(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
+ "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
+
+ endif()
+
+ # restore the previous LC_ALL
+ set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
+
+ endmacro()
+
+ macro(Subversion_WC_LOG dir prefix)
+ # This macro can block if the certificate is not signed:
+ # svn ask you to accept the certificate and wait for your answer
+ # This macro requires a svn server network access (Internet most of the time)
+ # and can also be slow since it access the svn server
+ execute_process(COMMAND
+ ${Subversion_SVN_EXECUTABLE} --non-interactive log -r BASE ${dir}
+ OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
+ ERROR_VARIABLE Subversion_svn_log_error
+ RESULT_VARIABLE Subversion_svn_log_result
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(NOT ${Subversion_svn_log_result} EQUAL 0)
+ message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
+ endif()
+ endmacro()
+
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE
+ VERSION_VAR Subversion_VERSION_SVN )
+
+# for compatibility
+set(Subversion_FOUND ${SUBVERSION_FOUND})
+set(Subversion_SVN_FOUND ${SUBVERSION_FOUND})
diff --git a/Modules/FindTCL.cmake b/Modules/FindTCL.cmake
new file mode 100644
index 0000000000..a83e277b0c
--- /dev/null
+++ b/Modules/FindTCL.cmake
@@ -0,0 +1,235 @@
+#.rst:
+# FindTCL
+# -------
+#
+# TK_INTERNAL_PATH was removed.
+#
+# This module finds if Tcl is installed and determines where the include
+# files and libraries are. It also determines what the name of the
+# library is. This code sets the following variables:
+#
+# ::
+#
+# TCL_FOUND = Tcl was found
+# TK_FOUND = Tk was found
+# TCLTK_FOUND = Tcl and Tk were found
+# TCL_LIBRARY = path to Tcl library (tcl tcl80)
+# TCL_INCLUDE_PATH = path to where tcl.h can be found
+# TCL_TCLSH = path to tclsh binary (tcl tcl80)
+# TK_LIBRARY = path to Tk library (tk tk80 etc)
+# TK_INCLUDE_PATH = path to where tk.h can be found
+# TK_WISH = full path to the wish executable
+#
+#
+#
+# In an effort to remove some clutter and clear up some issues for
+# people who are not necessarily Tcl/Tk gurus/developpers, some
+# variables were moved or removed. Changes compared to CMake 2.4 are:
+#
+# ::
+#
+# => they were only useful for people writing Tcl/Tk extensions.
+# => these libs are not packaged by default with Tcl/Tk distributions.
+# Even when Tcl/Tk is built from source, several flavors of debug libs
+# are created and there is no real reason to pick a single one
+# specifically (say, amongst tcl84g, tcl84gs, or tcl84sgx).
+# Let's leave that choice to the user by allowing him to assign
+# TCL_LIBRARY to any Tcl library, debug or not.
+# => this ended up being only a Win32 variable, and there is a lot of
+# confusion regarding the location of this file in an installed Tcl/Tk
+# tree anyway (see 8.5 for example). If you need the internal path at
+# this point it is safer you ask directly where the *source* tree is
+# and dig from there.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindFrameworks.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/FindTclsh.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/FindWish.cmake)
+
+if(TCLSH_VERSION_STRING)
+ set(TCL_TCLSH_VERSION "${TCLSH_VERSION_STRING}")
+else()
+ get_filename_component(TCL_TCLSH_PATH "${TCL_TCLSH}" PATH)
+ get_filename_component(TCL_TCLSH_PATH_PARENT "${TCL_TCLSH_PATH}" PATH)
+ string(REGEX REPLACE
+ "^.*tclsh([0-9]\\.*[0-9]).*$" "\\1" TCL_TCLSH_VERSION "${TCL_TCLSH}")
+endif()
+
+get_filename_component(TK_WISH_PATH "${TK_WISH}" PATH)
+get_filename_component(TK_WISH_PATH_PARENT "${TK_WISH_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*wish([0-9]\\.*[0-9]).*$" "\\1" TK_WISH_VERSION "${TK_WISH}")
+
+get_filename_component(TCL_INCLUDE_PATH_PARENT "${TCL_INCLUDE_PATH}" PATH)
+get_filename_component(TK_INCLUDE_PATH_PARENT "${TK_INCLUDE_PATH}" PATH)
+
+get_filename_component(TCL_LIBRARY_PATH "${TCL_LIBRARY}" PATH)
+get_filename_component(TCL_LIBRARY_PATH_PARENT "${TCL_LIBRARY_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tcl([0-9]\\.*[0-9]).*$" "\\1" TCL_LIBRARY_VERSION "${TCL_LIBRARY}")
+
+get_filename_component(TK_LIBRARY_PATH "${TK_LIBRARY}" PATH)
+get_filename_component(TK_LIBRARY_PATH_PARENT "${TK_LIBRARY_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tk([0-9]\\.*[0-9]).*$" "\\1" TK_LIBRARY_VERSION "${TK_LIBRARY}")
+
+set(TCLTK_POSSIBLE_LIB_PATHS
+ "${TCL_INCLUDE_PATH_PARENT}/lib"
+ "${TK_INCLUDE_PATH_PARENT}/lib"
+ "${TCL_LIBRARY_PATH}"
+ "${TK_LIBRARY_PATH}"
+ "${TCL_TCLSH_PATH_PARENT}/lib"
+ "${TK_WISH_PATH_PARENT}/lib"
+ /usr/local/lib/tcl/tcl8.5
+ /usr/local/lib/tcl/tk8.5
+ /usr/local/lib/tcl/tcl8.4
+ /usr/local/lib/tcl/tk8.4
+ )
+
+if(WIN32)
+ get_filename_component(
+ ActiveTcl_CurrentVersion
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl;CurrentVersion]"
+ NAME)
+ set(TCLTK_POSSIBLE_LIB_PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl\\${ActiveTcl_CurrentVersion}]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.6;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.5;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/lib"
+ "$ENV{ProgramFiles}/Tcl/Lib"
+ "C:/Program Files/Tcl/lib"
+ "C:/Tcl/lib"
+ )
+endif()
+
+find_library(TCL_LIBRARY
+ NAMES
+ tcl
+ tcl${TCL_LIBRARY_VERSION} tcl${TCL_TCLSH_VERSION} tcl${TK_WISH_VERSION}
+ tcl86 tcl8.6
+ tcl85 tcl8.5
+ tcl84 tcl8.4
+ tcl83 tcl8.3
+ tcl82 tcl8.2
+ tcl80 tcl8.0
+ PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+ )
+
+find_library(TK_LIBRARY
+ NAMES
+ tk
+ tk${TK_LIBRARY_VERSION} tk${TCL_TCLSH_VERSION} tk${TK_WISH_VERSION}
+ tk86 tk8.6
+ tk85 tk8.5
+ tk84 tk8.4
+ tk83 tk8.3
+ tk82 tk8.2
+ tk80 tk8.0
+ PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+ )
+
+CMAKE_FIND_FRAMEWORKS(Tcl)
+CMAKE_FIND_FRAMEWORKS(Tk)
+
+set(TCL_FRAMEWORK_INCLUDES)
+if(Tcl_FRAMEWORKS)
+ if(NOT TCL_INCLUDE_PATH)
+ foreach(dir ${Tcl_FRAMEWORKS})
+ set(TCL_FRAMEWORK_INCLUDES ${TCL_FRAMEWORK_INCLUDES} ${dir}/Headers)
+ endforeach()
+ endif()
+endif()
+
+set(TK_FRAMEWORK_INCLUDES)
+if(Tk_FRAMEWORKS)
+ if(NOT TK_INCLUDE_PATH)
+ foreach(dir ${Tk_FRAMEWORKS})
+ set(TK_FRAMEWORK_INCLUDES ${TK_FRAMEWORK_INCLUDES}
+ ${dir}/Headers ${dir}/PrivateHeaders)
+ endforeach()
+ endif()
+endif()
+
+set(TCLTK_POSSIBLE_INCLUDE_PATHS
+ "${TCL_LIBRARY_PATH_PARENT}/include"
+ "${TK_LIBRARY_PATH_PARENT}/include"
+ "${TCL_INCLUDE_PATH}"
+ "${TK_INCLUDE_PATH}"
+ ${TCL_FRAMEWORK_INCLUDES}
+ ${TK_FRAMEWORK_INCLUDES}
+ "${TCL_TCLSH_PATH_PARENT}/include"
+ "${TK_WISH_PATH_PARENT}/include"
+ /usr/include/tcl${TK_LIBRARY_VERSION}
+ /usr/include/tcl${TCL_LIBRARY_VERSION}
+ /usr/include/tcl8.6
+ /usr/include/tcl8.5
+ /usr/include/tcl8.4
+ /usr/include/tcl8.3
+ /usr/include/tcl8.2
+ /usr/include/tcl8.0
+ /usr/local/include/tcl8.6
+ /usr/local/include/tk8.6
+ /usr/local/include/tcl8.5
+ /usr/local/include/tk8.5
+ /usr/local/include/tcl8.4
+ /usr/local/include/tk8.4
+ )
+
+if(WIN32)
+ set(TCLTK_POSSIBLE_INCLUDE_PATHS ${TCLTK_POSSIBLE_INCLUDE_PATHS}
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl\\${ActiveTcl_CurrentVersion}]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.6;Root]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.5;Root]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/include"
+ "$ENV{ProgramFiles}/Tcl/include"
+ "C:/Program Files/Tcl/include"
+ "C:/Tcl/include"
+ )
+endif()
+
+find_path(TCL_INCLUDE_PATH
+ NAMES tcl.h
+ HINTS ${TCLTK_POSSIBLE_INCLUDE_PATHS}
+ )
+
+find_path(TK_INCLUDE_PATH
+ NAMES tk.h
+ HINTS ${TCLTK_POSSIBLE_INCLUDE_PATHS}
+ )
+
+# handle the QUIETLY and REQUIRED arguments and set TCL_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(TCL DEFAULT_MSG TCL_LIBRARY TCL_INCLUDE_PATH)
+set(TCLTK_FIND_REQUIRED ${TCL_FIND_REQUIRED})
+set(TCLTK_FIND_QUIETLY ${TCL_FIND_QUIETLY})
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(TCLTK DEFAULT_MSG TCL_LIBRARY TCL_INCLUDE_PATH TK_LIBRARY TK_INCLUDE_PATH)
+set(TK_FIND_REQUIRED ${TCL_FIND_REQUIRED})
+set(TK_FIND_QUIETLY ${TCL_FIND_QUIETLY})
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(TK DEFAULT_MSG TK_LIBRARY TK_INCLUDE_PATH)
+
+mark_as_advanced(
+ TCL_INCLUDE_PATH
+ TK_INCLUDE_PATH
+ TCL_LIBRARY
+ TK_LIBRARY
+ )
diff --git a/Modules/FindTIFF.cmake b/Modules/FindTIFF.cmake
new file mode 100644
index 0000000000..a67d24d0a0
--- /dev/null
+++ b/Modules/FindTIFF.cmake
@@ -0,0 +1,59 @@
+#.rst:
+# FindTIFF
+# --------
+#
+# Find TIFF library
+#
+# Find the native TIFF includes and library This module defines
+#
+# ::
+#
+# 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.
+#
+# also defined, but not for general use are
+#
+# ::
+#
+# TIFF_LIBRARY, where to find the TIFF library.
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+find_path(TIFF_INCLUDE_DIR tiff.h)
+
+set(TIFF_NAMES ${TIFF_NAMES} tiff libtiff tiff3 libtiff3)
+find_library(TIFF_LIBRARY NAMES ${TIFF_NAMES} )
+
+if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h")
+ file(STRINGS "${TIFF_INCLUDE_DIR}/tiffvers.h" tiff_version_str
+ REGEX "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version .*")
+
+ string(REGEX REPLACE "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version +([^ \\n]*).*"
+ "\\1" TIFF_VERSION_STRING "${tiff_version_str}")
+ unset(tiff_version_str)
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set TIFF_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF
+ REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIR
+ VERSION_VAR TIFF_VERSION_STRING)
+
+if(TIFF_FOUND)
+ set( TIFF_LIBRARIES ${TIFF_LIBRARY} )
+endif()
+
+mark_as_advanced(TIFF_INCLUDE_DIR TIFF_LIBRARY)
diff --git a/Modules/FindTclStub.cmake b/Modules/FindTclStub.cmake
new file mode 100644
index 0000000000..3c24f9721e
--- /dev/null
+++ b/Modules/FindTclStub.cmake
@@ -0,0 +1,150 @@
+#.rst:
+# FindTclStub
+# -----------
+#
+# TCL_STUB_LIBRARY_DEBUG and TK_STUB_LIBRARY_DEBUG were removed.
+#
+# This module finds Tcl stub libraries. It first finds Tcl include
+# files and libraries by calling FindTCL.cmake. How to Use the Tcl
+# Stubs Library:
+#
+# ::
+#
+# http://tcl.activestate.com/doc/howto/stubs.html
+#
+# Using Stub Libraries:
+#
+# ::
+#
+# http://safari.oreilly.com/0130385603/ch48lev1sec3
+#
+# This code sets the following variables:
+#
+# ::
+#
+# TCL_STUB_LIBRARY = path to Tcl stub library
+# TK_STUB_LIBRARY = path to Tk stub library
+# TTK_STUB_LIBRARY = path to ttk stub library
+#
+#
+#
+# In an effort to remove some clutter and clear up some issues for
+# people who are not necessarily Tcl/Tk gurus/developpers, some
+# variables were moved or removed. Changes compared to CMake 2.4 are:
+#
+# ::
+#
+# => these libs are not packaged by default with Tcl/Tk distributions.
+# Even when Tcl/Tk is built from source, several flavors of debug libs
+# are created and there is no real reason to pick a single one
+# specifically (say, amongst tclstub84g, tclstub84gs, or tclstub84sgx).
+# Let's leave that choice to the user by allowing him to assign
+# TCL_STUB_LIBRARY to any Tcl library, debug or not.
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindTCL.cmake)
+
+get_filename_component(TCL_TCLSH_PATH "${TCL_TCLSH}" PATH)
+get_filename_component(TCL_TCLSH_PATH_PARENT "${TCL_TCLSH_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tclsh([0-9]\\.*[0-9]).*$" "\\1" TCL_TCLSH_VERSION "${TCL_TCLSH}")
+
+get_filename_component(TK_WISH_PATH "${TK_WISH}" PATH)
+get_filename_component(TK_WISH_PATH_PARENT "${TK_WISH_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*wish([0-9]\\.*[0-9]).*$" "\\1" TK_WISH_VERSION "${TK_WISH}")
+
+get_filename_component(TCL_INCLUDE_PATH_PARENT "${TCL_INCLUDE_PATH}" PATH)
+get_filename_component(TK_INCLUDE_PATH_PARENT "${TK_INCLUDE_PATH}" PATH)
+
+get_filename_component(TCL_LIBRARY_PATH "${TCL_LIBRARY}" PATH)
+get_filename_component(TCL_LIBRARY_PATH_PARENT "${TCL_LIBRARY_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tcl([0-9]\\.*[0-9]).*$" "\\1" TCL_LIBRARY_VERSION "${TCL_LIBRARY}")
+
+get_filename_component(TK_LIBRARY_PATH "${TK_LIBRARY}" PATH)
+get_filename_component(TK_LIBRARY_PATH_PARENT "${TK_LIBRARY_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tk([0-9]\\.*[0-9]).*$" "\\1" TK_LIBRARY_VERSION "${TK_LIBRARY}")
+
+set(TCLTK_POSSIBLE_LIB_PATHS
+ "${TCL_INCLUDE_PATH_PARENT}/lib"
+ "${TK_INCLUDE_PATH_PARENT}/lib"
+ "${TCL_LIBRARY_PATH}"
+ "${TK_LIBRARY_PATH}"
+ "${TCL_TCLSH_PATH_PARENT}/lib"
+ "${TK_WISH_PATH_PARENT}/lib"
+)
+
+if(WIN32)
+ get_filename_component(
+ ActiveTcl_CurrentVersion
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl;CurrentVersion]"
+ NAME)
+ set(TCLTK_POSSIBLE_LIB_PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl\\${ActiveTcl_CurrentVersion}]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.6;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.5;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/lib"
+ "$ENV{ProgramFiles}/Tcl/Lib"
+ "C:/Program Files/Tcl/lib"
+ "C:/Tcl/lib"
+ )
+endif()
+
+find_library(TCL_STUB_LIBRARY
+ NAMES
+ tclstub
+ tclstub${TK_LIBRARY_VERSION} tclstub${TCL_TCLSH_VERSION} tclstub${TK_WISH_VERSION}
+ tclstub86 tclstub8.6
+ tclstub85 tclstub8.5
+ tclstub84 tclstub8.4
+ tclstub83 tclstub8.3
+ tclstub82 tclstub8.2
+ tclstub80 tclstub8.0
+ PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+)
+
+find_library(TK_STUB_LIBRARY
+ NAMES
+ tkstub
+ tkstub${TCL_LIBRARY_VERSION} tkstub${TCL_TCLSH_VERSION} tkstub${TK_WISH_VERSION}
+ tkstub86 tkstub8.6
+ tkstub85 tkstub8.5
+ tkstub84 tkstub8.4
+ tkstub83 tkstub8.3
+ tkstub82 tkstub8.2
+ tkstub80 tkstub8.0
+ PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+)
+
+find_library(TTK_STUB_LIBRARY
+ NAMES
+ ttkstub
+ ttkstub${TCL_LIBRARY_VERSION} ttkstub${TCL_TCLSH_VERSION} ttkstub${TK_WISH_VERSION}
+ ttkstub88 ttkstub8.8
+ ttkstub87 ttkstub8.7
+ ttkstub86 ttkstub8.6
+ ttkstub85 ttkstub8.5
+ PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+)
+
+mark_as_advanced(
+ TCL_STUB_LIBRARY
+ TK_STUB_LIBRARY
+ )
diff --git a/Modules/FindTclsh.cmake b/Modules/FindTclsh.cmake
new file mode 100644
index 0000000000..2fd5332aa7
--- /dev/null
+++ b/Modules/FindTclsh.cmake
@@ -0,0 +1,109 @@
+#.rst:
+# FindTclsh
+# ---------
+#
+# Find tclsh
+#
+# This module finds if TCL is installed and determines where the include
+# files and libraries are. It also determines what the name of the
+# library is. This code sets the following variables:
+#
+# ::
+#
+# TCLSH_FOUND = TRUE if tclsh has been found
+# TCL_TCLSH = the path to the tclsh executable
+#
+# In cygwin, look for the cygwin version first. Don't look for it later
+# to avoid finding the cygwin version on a Win32 build.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+if(CYGWIN)
+ find_program(TCL_TCLSH NAMES cygtclsh83 cygtclsh80)
+endif()
+
+get_filename_component(TK_WISH_PATH "${TK_WISH}" PATH)
+get_filename_component(TK_WISH_PATH_PARENT "${TK_WISH_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*wish([0-9]\\.*[0-9]).*$" "\\1" TK_WISH_VERSION "${TK_WISH}")
+
+get_filename_component(TCL_INCLUDE_PATH_PARENT "${TCL_INCLUDE_PATH}" PATH)
+get_filename_component(TK_INCLUDE_PATH_PARENT "${TK_INCLUDE_PATH}" PATH)
+
+get_filename_component(TCL_LIBRARY_PATH "${TCL_LIBRARY}" PATH)
+get_filename_component(TCL_LIBRARY_PATH_PARENT "${TCL_LIBRARY_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tcl([0-9]\\.*[0-9]).*$" "\\1" TCL_LIBRARY_VERSION "${TCL_LIBRARY}")
+
+get_filename_component(TK_LIBRARY_PATH "${TK_LIBRARY}" PATH)
+get_filename_component(TK_LIBRARY_PATH_PARENT "${TK_LIBRARY_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tk([0-9]\\.*[0-9]).*$" "\\1" TK_LIBRARY_VERSION "${TK_LIBRARY}")
+
+set(TCLTK_POSSIBLE_BIN_PATHS
+ "${TCL_INCLUDE_PATH_PARENT}/bin"
+ "${TK_INCLUDE_PATH_PARENT}/bin"
+ "${TCL_LIBRARY_PATH_PARENT}/bin"
+ "${TK_LIBRARY_PATH_PARENT}/bin"
+ "${TK_WISH_PATH_PARENT}/bin"
+ )
+
+if(WIN32)
+ get_filename_component(
+ ActiveTcl_CurrentVersion
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl;CurrentVersion]"
+ NAME)
+ set(TCLTK_POSSIBLE_BIN_PATHS ${TCLTK_POSSIBLE_BIN_PATHS}
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl\\${ActiveTcl_CurrentVersion}]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.6;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.5;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/bin"
+ )
+endif()
+
+set(TCL_TCLSH_NAMES
+ tclsh
+ tclsh${TCL_LIBRARY_VERSION} tclsh${TK_LIBRARY_VERSION} tclsh${TK_WISH_VERSION}
+ tclsh86 tclsh8.6
+ tclsh85 tclsh8.5
+ tclsh84 tclsh8.4
+ tclsh83 tclsh8.3
+ tclsh82 tclsh8.2
+ tclsh80 tclsh8.0
+ )
+
+find_program(TCL_TCLSH
+ NAMES ${TCL_TCLSH_NAMES}
+ HINTS ${TCLTK_POSSIBLE_BIN_PATHS}
+ )
+
+if(TCL_TCLSH)
+ execute_process(COMMAND "${CMAKE_COMMAND}" -E echo puts "\$tcl_version"
+ COMMAND "${TCL_TCLSH}"
+ OUTPUT_VARIABLE TCLSH_VERSION_STRING
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set TIFF_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Tclsh
+ REQUIRED_VARS TCL_TCLSH
+ VERSION_VAR TCLSH_VERSION_STRING)
+
+mark_as_advanced(TCL_TCLSH)
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake
new file mode 100644
index 0000000000..a0bc4d133e
--- /dev/null
+++ b/Modules/FindThreads.cmake
@@ -0,0 +1,216 @@
+#.rst:
+# FindThreads
+# -----------
+#
+# This module determines the thread library of the system.
+#
+# The following variables are set
+#
+# ::
+#
+# CMAKE_THREAD_LIBS_INIT - the thread library
+# CMAKE_USE_SPROC_INIT - are we using sproc?
+# CMAKE_USE_WIN32_THREADS_INIT - using WIN32 threads?
+# CMAKE_USE_PTHREADS_INIT - are we using pthreads
+# CMAKE_HP_PTHREADS_INIT - are we using hp pthreads
+#
+# The following import target is created
+#
+# ::
+#
+# Threads::Threads
+#
+# For systems with multiple thread libraries, caller can set
+#
+# ::
+#
+# CMAKE_THREAD_PREFER_PTHREAD
+#
+# If the use of the -pthread compiler and linker flag is prefered then the
+# caller can set
+#
+# ::
+#
+# THREADS_PREFER_PTHREAD_FLAG
+#
+# Please note that the compiler flag can only be used with the imported
+# target. Use of both the imported target as well as this switch is highly
+# recommended for new code.
+
+#=============================================================================
+# Copyright 2002-2009 Kitware, Inc.
+# Copyright 2011-2014 Rolf Eike Beer <eike@sf-mail.de>
+#
+# 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.)
+
+include (CheckIncludeFiles)
+include (CheckLibraryExists)
+include (CheckSymbolExists)
+set(Threads_FOUND FALSE)
+set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
+set(CMAKE_REQUIRED_QUIET ${Threads_FIND_QUIETLY})
+
+# Do we have sproc?
+if(CMAKE_SYSTEM_NAME MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD)
+ CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H)
+endif()
+
+# Internal helper macro.
+# Do NOT even think about using it outside of this file!
+macro(_check_threads_lib LIBNAME FUNCNAME VARNAME)
+ if(NOT Threads_FOUND)
+ CHECK_LIBRARY_EXISTS(${LIBNAME} ${FUNCNAME} "" ${VARNAME})
+ if(${VARNAME})
+ set(CMAKE_THREAD_LIBS_INIT "-l${LIBNAME}")
+ set(CMAKE_HAVE_THREADS_LIBRARY 1)
+ set(Threads_FOUND TRUE)
+ endif()
+ endif ()
+endmacro()
+
+# Internal helper macro.
+# Do NOT even think about using it outside of this file!
+macro(_check_pthreads_flag)
+ if(NOT Threads_FOUND)
+ # If we did not found -lpthread, -lpthread, or -lthread, look for -pthread
+ if(NOT DEFINED THREADS_HAVE_PTHREAD_ARG)
+ message(STATUS "Check if compiler accepts -pthread")
+ try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_CURRENT_LIST_DIR}/CheckForPthreads.c
+ CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread
+ COMPILE_OUTPUT_VARIABLE OUTPUT)
+
+ if(THREADS_HAVE_PTHREAD_ARG)
+ if(THREADS_PTHREAD_ARG STREQUAL "2")
+ set(Threads_FOUND TRUE)
+ message(STATUS "Check if compiler accepts -pthread - yes")
+ else()
+ message(STATUS "Check if compiler accepts -pthread - no")
+ file(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n")
+ endif()
+ else()
+ message(STATUS "Check if compiler accepts -pthread - no")
+ file(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n")
+ endif()
+
+ endif()
+
+ if(THREADS_HAVE_PTHREAD_ARG)
+ set(Threads_FOUND TRUE)
+ set(CMAKE_THREAD_LIBS_INIT "-pthread")
+ endif()
+ endif()
+endmacro()
+
+if(CMAKE_HAVE_SPROC_H AND NOT CMAKE_THREAD_PREFER_PTHREAD)
+ # We have sproc
+ set(CMAKE_USE_SPROC_INIT 1)
+else()
+ # Do we have pthreads?
+ CHECK_INCLUDE_FILES("pthread.h" CMAKE_HAVE_PTHREAD_H)
+ if(CMAKE_HAVE_PTHREAD_H)
+
+ #
+ # We have pthread.h
+ # Let's check for the library now.
+ #
+ set(CMAKE_HAVE_THREADS_LIBRARY)
+ if(NOT THREADS_HAVE_PTHREAD_ARG)
+ # Check if pthread functions are in normal C library
+ CHECK_SYMBOL_EXISTS(pthread_create pthread.h CMAKE_HAVE_LIBC_CREATE)
+ if(CMAKE_HAVE_LIBC_CREATE)
+ set(CMAKE_THREAD_LIBS_INIT "")
+ set(CMAKE_HAVE_THREADS_LIBRARY 1)
+ set(Threads_FOUND TRUE)
+ else()
+
+ # Check for -pthread first if enabled. This is the recommended
+ # way, but not backwards compatible as one must also pass -pthread
+ # as compiler flag then.
+ if (THREADS_PREFER_PTHREAD_FLAG)
+ _check_pthreads_flag()
+ endif ()
+
+ _check_threads_lib(pthreads pthread_create CMAKE_HAVE_PTHREADS_CREATE)
+ _check_threads_lib(pthread pthread_create CMAKE_HAVE_PTHREAD_CREATE)
+ if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
+ # On sun also check for -lthread
+ _check_threads_lib(thread thr_create CMAKE_HAVE_THR_CREATE)
+ endif()
+ endif()
+ endif()
+
+ _check_pthreads_flag()
+ endif()
+endif()
+
+if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_CREATE)
+ set(CMAKE_USE_PTHREADS_INIT 1)
+ set(Threads_FOUND TRUE)
+endif()
+
+if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set(CMAKE_USE_WIN32_THREADS_INIT 1)
+ set(Threads_FOUND TRUE)
+endif()
+
+if(CMAKE_USE_PTHREADS_INIT)
+ if(CMAKE_SYSTEM_NAME MATCHES "HP-UX")
+ # Use libcma if it exists and can be used. It provides more
+ # symbols than the plain pthread library. CMA threads
+ # have actually been deprecated:
+ # http://docs.hp.com/en/B3920-90091/ch12s03.html#d0e11395
+ # http://docs.hp.com/en/947/d8.html
+ # but we need to maintain compatibility here.
+ # The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads
+ # are available.
+ CHECK_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA)
+ if(CMAKE_HAVE_HP_CMA)
+ set(CMAKE_THREAD_LIBS_INIT "-lcma")
+ set(CMAKE_HP_PTHREADS_INIT 1)
+ set(Threads_FOUND TRUE)
+ endif()
+ set(CMAKE_USE_PTHREADS_INIT 1)
+ endif()
+
+ if(CMAKE_SYSTEM MATCHES "OSF1-V")
+ set(CMAKE_USE_PTHREADS_INIT 0)
+ set(CMAKE_THREAD_LIBS_INIT )
+ endif()
+
+ if(CMAKE_SYSTEM MATCHES "CYGWIN_NT")
+ set(CMAKE_USE_PTHREADS_INIT 1)
+ set(Threads_FOUND TRUE)
+ set(CMAKE_THREAD_LIBS_INIT )
+ set(CMAKE_USE_WIN32_THREADS_INIT 0)
+ endif()
+endif()
+
+set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG Threads_FOUND)
+
+if(THREADS_FOUND AND NOT TARGET Threads::Threads)
+ add_library(Threads::Threads INTERFACE IMPORTED)
+
+ if(THREADS_HAVE_PTHREAD_ARG)
+ set_property(TARGET Threads::Threads PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread")
+ endif()
+
+ if(CMAKE_THREAD_LIBS_INIT)
+ set_property(TARGET Threads::Threads PROPERTY INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
+ endif()
+endif()
diff --git a/Modules/FindUnixCommands.cmake b/Modules/FindUnixCommands.cmake
new file mode 100644
index 0000000000..d4e5dcdf72
--- /dev/null
+++ b/Modules/FindUnixCommands.cmake
@@ -0,0 +1,97 @@
+#.rst:
+# FindUnixCommands
+# ----------------
+#
+# Find unix commands from cygwin
+#
+# This module looks for some usual Unix commands.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
+
+find_program(BASH
+ bash
+ ${CYGWIN_INSTALL_PATH}/bin
+ /bin
+ /usr/bin
+ /usr/local/bin
+ /sbin
+)
+mark_as_advanced(
+ BASH
+)
+
+find_program(CP
+ cp
+ ${CYGWIN_INSTALL_PATH}/bin
+ /bin
+ /usr/bin
+ /usr/local/bin
+ /sbin
+)
+mark_as_advanced(
+ CP
+)
+
+find_program(GZIP
+ gzip
+ ${CYGWIN_INSTALL_PATH}/bin
+ /bin
+ /usr/bin
+ /usr/local/bin
+ /sbin
+)
+mark_as_advanced(
+ GZIP
+)
+
+find_program(MV
+ mv
+ ${CYGWIN_INSTALL_PATH}/bin
+ /bin
+ /usr/bin
+ /usr/local/bin
+ /sbin
+)
+mark_as_advanced(
+ MV
+)
+
+find_program(RM
+ rm
+ ${CYGWIN_INSTALL_PATH}/bin
+ /bin
+ /usr/bin
+ /usr/local/bin
+ /sbin
+)
+mark_as_advanced(
+ RM
+)
+
+find_program(TAR
+ NAMES
+ tar
+ gtar
+ PATH
+ ${CYGWIN_INSTALL_PATH}/bin
+ /bin
+ /usr/bin
+ /usr/local/bin
+ /sbin
+)
+mark_as_advanced(
+ TAR
+)
diff --git a/Modules/FindWget.cmake b/Modules/FindWget.cmake
new file mode 100644
index 0000000000..b303b407d9
--- /dev/null
+++ b/Modules/FindWget.cmake
@@ -0,0 +1,43 @@
+#.rst:
+# FindWget
+# --------
+#
+# Find wget
+#
+# This module looks for wget. This module defines the following values:
+#
+# ::
+#
+# WGET_EXECUTABLE: the full path to the wget tool.
+# WGET_FOUND: True if wget has been found.
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
+
+find_program(WGET_EXECUTABLE
+ wget
+ ${CYGWIN_INSTALL_PATH}/bin
+)
+
+# handle the QUIETLY and REQUIRED arguments and set WGET_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Wget DEFAULT_MSG WGET_EXECUTABLE)
+
+mark_as_advanced( WGET_EXECUTABLE )
+
+# WGET option is deprecated.
+# use WGET_EXECUTABLE instead.
+set (WGET ${WGET_EXECUTABLE} )
diff --git a/Modules/FindWish.cmake b/Modules/FindWish.cmake
new file mode 100644
index 0000000000..df301b4127
--- /dev/null
+++ b/Modules/FindWish.cmake
@@ -0,0 +1,94 @@
+#.rst:
+# FindWish
+# --------
+#
+# Find wish installation
+#
+# This module finds if TCL is installed and determines where the include
+# files and libraries are. It also determines what the name of the
+# library is. This code sets the following variables:
+#
+# ::
+#
+# TK_WISH = the path to the wish executable
+#
+#
+#
+# if UNIX is defined, then it will look for the cygwin version first
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+if(UNIX)
+ find_program(TK_WISH cygwish80 )
+endif()
+
+get_filename_component(TCL_TCLSH_PATH "${TCL_TCLSH}" PATH)
+get_filename_component(TCL_TCLSH_PATH_PARENT "${TCL_TCLSH_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tclsh([0-9]\\.*[0-9]).*$" "\\1" TCL_TCLSH_VERSION "${TCL_TCLSH}")
+
+get_filename_component(TCL_INCLUDE_PATH_PARENT "${TCL_INCLUDE_PATH}" PATH)
+get_filename_component(TK_INCLUDE_PATH_PARENT "${TK_INCLUDE_PATH}" PATH)
+
+get_filename_component(TCL_LIBRARY_PATH "${TCL_LIBRARY}" PATH)
+get_filename_component(TCL_LIBRARY_PATH_PARENT "${TCL_LIBRARY_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tcl([0-9]\\.*[0-9]).*$" "\\1" TCL_LIBRARY_VERSION "${TCL_LIBRARY}")
+
+get_filename_component(TK_LIBRARY_PATH "${TK_LIBRARY}" PATH)
+get_filename_component(TK_LIBRARY_PATH_PARENT "${TK_LIBRARY_PATH}" PATH)
+string(REGEX REPLACE
+ "^.*tk([0-9]\\.*[0-9]).*$" "\\1" TK_LIBRARY_VERSION "${TK_LIBRARY}")
+
+set(TCLTK_POSSIBLE_BIN_PATHS
+ "${TCL_INCLUDE_PATH_PARENT}/bin"
+ "${TK_INCLUDE_PATH_PARENT}/bin"
+ "${TCL_LIBRARY_PATH_PARENT}/bin"
+ "${TK_LIBRARY_PATH_PARENT}/bin"
+ "${TCL_TCLSH_PATH_PARENT}/bin"
+ )
+
+if(WIN32)
+ get_filename_component(
+ ActiveTcl_CurrentVersion
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl;CurrentVersion]"
+ NAME)
+ set(TCLTK_POSSIBLE_BIN_PATHS ${TCLTK_POSSIBLE_BIN_PATHS}
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl\\${ActiveTcl_CurrentVersion}]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.6;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.5;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/bin"
+ )
+endif()
+
+set(TK_WISH_NAMES
+ wish
+ wish${TCL_LIBRARY_VERSION} wish${TK_LIBRARY_VERSION} wish${TCL_TCLSH_VERSION}
+ wish86 wish8.6
+ wish85 wish8.5
+ wish84 wish8.4
+ wish83 wish8.3
+ wish82 wish8.2
+ wish80 wish8.0
+ )
+
+find_program(TK_WISH
+ NAMES ${TK_WISH_NAMES}
+ HINTS ${TCLTK_POSSIBLE_BIN_PATHS}
+ )
+
+mark_as_advanced(TK_WISH)
diff --git a/Modules/FindX11.cmake b/Modules/FindX11.cmake
new file mode 100644
index 0000000000..90c1499c32
--- /dev/null
+++ b/Modules/FindX11.cmake
@@ -0,0 +1,512 @@
+#.rst:
+# FindX11
+# -------
+#
+# Find X11 installation
+#
+# Try to find X11 on UNIX systems. The following values are defined
+#
+# ::
+#
+# X11_FOUND - True if X11 is available
+# X11_INCLUDE_DIR - include directories to use X11
+# X11_LIBRARIES - link against these to use X11
+#
+# and also the following more fine grained variables:
+#
+# ::
+#
+# X11_ICE_INCLUDE_PATH, X11_ICE_LIB, X11_ICE_FOUND
+# X11_SM_INCLUDE_PATH, X11_SM_LIB, X11_SM_FOUND
+# X11_X11_INCLUDE_PATH, X11_X11_LIB
+# X11_Xaccessrules_INCLUDE_PATH, X11_Xaccess_FOUND
+# X11_Xaccessstr_INCLUDE_PATH, X11_Xaccess_FOUND
+# X11_Xau_INCLUDE_PATH, X11_Xau_LIB, X11_Xau_FOUND
+# X11_Xcomposite_INCLUDE_PATH, X11_Xcomposite_LIB, X11_Xcomposite_FOUND
+# X11_Xcursor_INCLUDE_PATH, X11_Xcursor_LIB, X11_Xcursor_FOUND
+# X11_Xdamage_INCLUDE_PATH, X11_Xdamage_LIB, X11_Xdamage_FOUND
+# X11_Xdmcp_INCLUDE_PATH, X11_Xdmcp_LIB, X11_Xdmcp_FOUND
+# X11_Xext_LIB, X11_Xext_FOUND
+# X11_dpms_INCLUDE_PATH, (in X11_Xext_LIB), X11_dpms_FOUND
+# X11_XShm_INCLUDE_PATH, (in X11_Xext_LIB), X11_XShm_FOUND
+# X11_Xshape_INCLUDE_PATH, (in X11_Xext_LIB), X11_Xshape_FOUND
+# X11_xf86misc_INCLUDE_PATH, X11_Xxf86misc_LIB, X11_xf86misc_FOUND
+# X11_xf86vmode_INCLUDE_PATH, X11_Xxf86vm_LIB X11_xf86vmode_FOUND
+# X11_Xfixes_INCLUDE_PATH, X11_Xfixes_LIB, X11_Xfixes_FOUND
+# X11_Xft_INCLUDE_PATH, X11_Xft_LIB, X11_Xft_FOUND
+# X11_Xi_INCLUDE_PATH, X11_Xi_LIB, X11_Xi_FOUND
+# X11_Xinerama_INCLUDE_PATH, X11_Xinerama_LIB, X11_Xinerama_FOUND
+# X11_Xinput_INCLUDE_PATH, X11_Xinput_LIB, X11_Xinput_FOUND
+# X11_Xkb_INCLUDE_PATH, X11_Xkb_FOUND
+# X11_Xkblib_INCLUDE_PATH, X11_Xkb_FOUND
+# X11_Xkbfile_INCLUDE_PATH, X11_Xkbfile_LIB, X11_Xkbfile_FOUND
+# X11_Xmu_INCLUDE_PATH, X11_Xmu_LIB, X11_Xmu_FOUND
+# X11_Xpm_INCLUDE_PATH, X11_Xpm_LIB, X11_Xpm_FOUND
+# X11_XTest_INCLUDE_PATH, X11_XTest_LIB, X11_XTest_FOUND
+# X11_Xrandr_INCLUDE_PATH, X11_Xrandr_LIB, X11_Xrandr_FOUND
+# X11_Xrender_INCLUDE_PATH, X11_Xrender_LIB, X11_Xrender_FOUND
+# X11_Xscreensaver_INCLUDE_PATH, X11_Xscreensaver_LIB, X11_Xscreensaver_FOUND
+# X11_Xt_INCLUDE_PATH, X11_Xt_LIB, X11_Xt_FOUND
+# X11_Xutil_INCLUDE_PATH, X11_Xutil_FOUND
+# X11_Xv_INCLUDE_PATH, X11_Xv_LIB, X11_Xv_FOUND
+# X11_XSync_INCLUDE_PATH, (in X11_Xext_LIB), X11_XSync_FOUND
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+if (UNIX)
+ set(X11_FOUND 0)
+ # X11 is never a framework and some header files may be
+ # found in tcl on the mac
+ set(CMAKE_FIND_FRAMEWORK_SAVE ${CMAKE_FIND_FRAMEWORK})
+ set(CMAKE_FIND_FRAMEWORK NEVER)
+ set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
+ set(CMAKE_REQUIRED_QUIET ${X11_FIND_QUIETLY})
+ set(X11_INC_SEARCH_PATH
+ /usr/pkg/xorg/include
+ /usr/X11R6/include
+ /usr/X11R7/include
+ /usr/include/X11
+ /usr/openwin/include
+ /usr/openwin/share/include
+ /opt/graphics/OpenGL/include
+ /opt/X11/include
+ )
+
+ set(X11_LIB_SEARCH_PATH
+ /usr/pkg/xorg/lib
+ /usr/X11R6/lib
+ /usr/X11R7/lib
+ /usr/openwin/lib
+ /opt/X11/lib
+ )
+
+ find_path(X11_X11_INCLUDE_PATH X11/X.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xlib_INCLUDE_PATH X11/Xlib.h ${X11_INC_SEARCH_PATH})
+
+ # Look for includes; keep the list sorted by name of the cmake *_INCLUDE_PATH
+ # variable (which doesn't need to match the include file name).
+
+ # Solaris lacks XKBrules.h, so we should skip kxkbd there.
+ find_path(X11_ICE_INCLUDE_PATH X11/ICE/ICE.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_SM_INCLUDE_PATH X11/SM/SM.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xaccessrules_INCLUDE_PATH X11/extensions/XKBrules.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xaccessstr_INCLUDE_PATH X11/extensions/XKBstr.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xau_INCLUDE_PATH X11/Xauth.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xcomposite_INCLUDE_PATH X11/extensions/Xcomposite.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xcursor_INCLUDE_PATH X11/Xcursor/Xcursor.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xdamage_INCLUDE_PATH X11/extensions/Xdamage.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xdmcp_INCLUDE_PATH X11/Xdmcp.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_dpms_INCLUDE_PATH X11/extensions/dpms.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_xf86misc_INCLUDE_PATH X11/extensions/xf86misc.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_xf86vmode_INCLUDE_PATH X11/extensions/xf86vmode.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xfixes_INCLUDE_PATH X11/extensions/Xfixes.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xft_INCLUDE_PATH X11/Xft/Xft.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xi_INCLUDE_PATH X11/extensions/XInput.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xinerama_INCLUDE_PATH X11/extensions/Xinerama.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xinput_INCLUDE_PATH X11/extensions/XInput.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xkb_INCLUDE_PATH X11/extensions/XKB.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xkblib_INCLUDE_PATH X11/XKBlib.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xkbfile_INCLUDE_PATH X11/extensions/XKBfile.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xmu_INCLUDE_PATH X11/Xmu/Xmu.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xpm_INCLUDE_PATH X11/xpm.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_XTest_INCLUDE_PATH X11/extensions/XTest.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_XShm_INCLUDE_PATH X11/extensions/XShm.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xrandr_INCLUDE_PATH X11/extensions/Xrandr.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xrender_INCLUDE_PATH X11/extensions/Xrender.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_XRes_INCLUDE_PATH X11/extensions/XRes.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xscreensaver_INCLUDE_PATH X11/extensions/scrnsaver.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xshape_INCLUDE_PATH X11/extensions/shape.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xutil_INCLUDE_PATH X11/Xutil.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xt_INCLUDE_PATH X11/Intrinsic.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xv_INCLUDE_PATH X11/extensions/Xvlib.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_XSync_INCLUDE_PATH X11/extensions/sync.h ${X11_INC_SEARCH_PATH})
+
+
+ find_library(X11_X11_LIB X11 ${X11_LIB_SEARCH_PATH})
+
+ # Find additional X libraries. Keep list sorted by library name.
+ find_library(X11_ICE_LIB ICE ${X11_LIB_SEARCH_PATH})
+ find_library(X11_SM_LIB SM ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xau_LIB Xau ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xcomposite_LIB Xcomposite ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xcursor_LIB Xcursor ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xdamage_LIB Xdamage ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xdmcp_LIB Xdmcp ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xext_LIB Xext ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xfixes_LIB Xfixes ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xft_LIB Xft ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xi_LIB Xi ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xinerama_LIB Xinerama ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xinput_LIB Xi ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xkbfile_LIB xkbfile ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xmu_LIB Xmu ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xpm_LIB Xpm ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xrandr_LIB Xrandr ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xrender_LIB Xrender ${X11_LIB_SEARCH_PATH})
+ find_library(X11_XRes_LIB XRes ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xscreensaver_LIB Xss ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xt_LIB Xt ${X11_LIB_SEARCH_PATH})
+ find_library(X11_XTest_LIB Xtst ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xv_LIB Xv ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xxf86misc_LIB Xxf86misc ${X11_LIB_SEARCH_PATH})
+ find_library(X11_Xxf86vm_LIB Xxf86vm ${X11_LIB_SEARCH_PATH})
+
+ set(X11_LIBRARY_DIR "")
+ if(X11_X11_LIB)
+ get_filename_component(X11_LIBRARY_DIR ${X11_X11_LIB} PATH)
+ endif()
+
+ set(X11_INCLUDE_DIR) # start with empty list
+ if(X11_X11_INCLUDE_PATH)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_X11_INCLUDE_PATH})
+ endif()
+
+ if(X11_Xlib_INCLUDE_PATH)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xlib_INCLUDE_PATH})
+ endif()
+
+ if(X11_Xutil_INCLUDE_PATH)
+ set(X11_Xutil_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xutil_INCLUDE_PATH})
+ endif()
+
+ if(X11_Xshape_INCLUDE_PATH)
+ set(X11_Xshape_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xshape_INCLUDE_PATH})
+ endif()
+
+ set(X11_LIBRARIES) # start with empty list
+ if(X11_X11_LIB)
+ set(X11_LIBRARIES ${X11_LIBRARIES} ${X11_X11_LIB})
+ endif()
+
+ if(X11_Xext_LIB)
+ set(X11_Xext_FOUND TRUE)
+ set(X11_LIBRARIES ${X11_LIBRARIES} ${X11_Xext_LIB})
+ endif()
+
+ if(X11_Xt_LIB AND X11_Xt_INCLUDE_PATH)
+ set(X11_Xt_FOUND TRUE)
+ endif()
+
+ if(X11_Xft_LIB AND X11_Xft_INCLUDE_PATH)
+ set(X11_Xft_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xft_INCLUDE_PATH})
+ endif()
+
+ if(X11_Xv_LIB AND X11_Xv_INCLUDE_PATH)
+ set(X11_Xv_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xv_INCLUDE_PATH})
+ endif()
+
+ if (X11_Xau_LIB AND X11_Xau_INCLUDE_PATH)
+ set(X11_Xau_FOUND TRUE)
+ endif ()
+
+ if (X11_Xdmcp_INCLUDE_PATH AND X11_Xdmcp_LIB)
+ set(X11_Xdmcp_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xdmcp_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xaccessrules_INCLUDE_PATH AND X11_Xaccessstr_INCLUDE_PATH)
+ set(X11_Xaccess_FOUND TRUE)
+ set(X11_Xaccess_INCLUDE_PATH ${X11_Xaccessstr_INCLUDE_PATH})
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xaccess_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xpm_INCLUDE_PATH AND X11_Xpm_LIB)
+ set(X11_Xpm_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xpm_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xcomposite_INCLUDE_PATH AND X11_Xcomposite_LIB)
+ set(X11_Xcomposite_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xcomposite_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xdamage_INCLUDE_PATH AND X11_Xdamage_LIB)
+ set(X11_Xdamage_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xdamage_INCLUDE_PATH})
+ endif ()
+
+ if (X11_XShm_INCLUDE_PATH)
+ set(X11_XShm_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_XShm_INCLUDE_PATH})
+ endif ()
+
+ if (X11_XTest_INCLUDE_PATH AND X11_XTest_LIB)
+ set(X11_XTest_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_XTest_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xi_INCLUDE_PATH AND X11_Xi_LIB)
+ set(X11_Xi_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xi_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xinerama_INCLUDE_PATH AND X11_Xinerama_LIB)
+ set(X11_Xinerama_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xinerama_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xfixes_INCLUDE_PATH AND X11_Xfixes_LIB)
+ set(X11_Xfixes_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xfixes_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xrender_INCLUDE_PATH AND X11_Xrender_LIB)
+ set(X11_Xrender_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xrender_INCLUDE_PATH})
+ endif ()
+
+ if (X11_XRes_INCLUDE_PATH AND X11_XRes_LIB)
+ set(X11_XRes_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_XRes_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xrandr_INCLUDE_PATH AND X11_Xrandr_LIB)
+ set(X11_Xrandr_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xrandr_INCLUDE_PATH})
+ endif ()
+
+ if (X11_xf86misc_INCLUDE_PATH AND X11_Xxf86misc_LIB)
+ set(X11_xf86misc_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_xf86misc_INCLUDE_PATH})
+ endif ()
+
+ if (X11_xf86vmode_INCLUDE_PATH AND X11_Xxf86vm_LIB)
+ set(X11_xf86vmode_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_xf86vmode_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xcursor_INCLUDE_PATH AND X11_Xcursor_LIB)
+ set(X11_Xcursor_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xcursor_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xscreensaver_INCLUDE_PATH AND X11_Xscreensaver_LIB)
+ set(X11_Xscreensaver_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xscreensaver_INCLUDE_PATH})
+ endif ()
+
+ if (X11_dpms_INCLUDE_PATH)
+ set(X11_dpms_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_dpms_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xkb_INCLUDE_PATH AND X11_Xkblib_INCLUDE_PATH AND X11_Xlib_INCLUDE_PATH)
+ set(X11_Xkb_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xkb_INCLUDE_PATH} )
+ endif ()
+
+ if (X11_Xkbfile_INCLUDE_PATH AND X11_Xkbfile_LIB AND X11_Xlib_INCLUDE_PATH)
+ set(X11_Xkbfile_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xkbfile_INCLUDE_PATH} )
+ endif ()
+
+ if (X11_Xmu_INCLUDE_PATH AND X11_Xmu_LIB)
+ set(X11_Xmu_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xmu_INCLUDE_PATH})
+ endif ()
+
+ if (X11_Xinput_INCLUDE_PATH AND X11_Xinput_LIB)
+ set(X11_Xinput_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xinput_INCLUDE_PATH})
+ endif ()
+
+ if (X11_XSync_INCLUDE_PATH)
+ set(X11_XSync_FOUND TRUE)
+ set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_XSync_INCLUDE_PATH})
+ endif ()
+
+ if(X11_ICE_LIB AND X11_ICE_INCLUDE_PATH)
+ set(X11_ICE_FOUND TRUE)
+ endif()
+
+ if(X11_SM_LIB AND X11_SM_INCLUDE_PATH)
+ set(X11_SM_FOUND TRUE)
+ endif()
+
+ # Most of the X11 headers will be in the same directories, avoid
+ # creating a huge list of duplicates.
+ if (X11_INCLUDE_DIR)
+ list(REMOVE_DUPLICATES X11_INCLUDE_DIR)
+ endif ()
+
+ # Deprecated variable for backwards compatibility with CMake 1.4
+ if (X11_X11_INCLUDE_PATH AND X11_LIBRARIES)
+ set(X11_FOUND 1)
+ endif ()
+
+ if(X11_FOUND)
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
+
+ # Translated from an autoconf-generated configure script.
+ # See libs.m4 in autoconf's m4 directory.
+ if($ENV{ISC} MATCHES "^yes$")
+ set(X11_X_EXTRA_LIBS -lnsl_s -linet)
+ else()
+ set(X11_X_EXTRA_LIBS "")
+
+ # See if XOpenDisplay in X11 works by itself.
+ CHECK_LIBRARY_EXISTS("${X11_LIBRARIES}" "XOpenDisplay" "${X11_LIBRARY_DIR}" X11_LIB_X11_SOLO)
+ if(NOT X11_LIB_X11_SOLO)
+ # Find library needed for dnet_ntoa.
+ CHECK_LIBRARY_EXISTS("dnet" "dnet_ntoa" "" X11_LIB_DNET_HAS_DNET_NTOA)
+ if (X11_LIB_DNET_HAS_DNET_NTOA)
+ set (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -ldnet)
+ else ()
+ CHECK_LIBRARY_EXISTS("dnet_stub" "dnet_ntoa" "" X11_LIB_DNET_STUB_HAS_DNET_NTOA)
+ if (X11_LIB_DNET_STUB_HAS_DNET_NTOA)
+ set (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -ldnet_stub)
+ endif ()
+ endif ()
+ endif()
+
+ # Find library needed for gethostbyname.
+ CHECK_FUNCTION_EXISTS("gethostbyname" CMAKE_HAVE_GETHOSTBYNAME)
+ if(NOT CMAKE_HAVE_GETHOSTBYNAME)
+ CHECK_LIBRARY_EXISTS("nsl" "gethostbyname" "" CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
+ if (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
+ set (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lnsl)
+ else ()
+ CHECK_LIBRARY_EXISTS("bsd" "gethostbyname" "" CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
+ if (CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
+ set (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lbsd)
+ endif ()
+ endif ()
+ endif()
+
+ # Find library needed for connect.
+ CHECK_FUNCTION_EXISTS("connect" CMAKE_HAVE_CONNECT)
+ if(NOT CMAKE_HAVE_CONNECT)
+ CHECK_LIBRARY_EXISTS("socket" "connect" "" CMAKE_LIB_SOCKET_HAS_CONNECT)
+ if (CMAKE_LIB_SOCKET_HAS_CONNECT)
+ set (X11_X_EXTRA_LIBS -lsocket ${X11_X_EXTRA_LIBS})
+ endif ()
+ endif()
+
+ # Find library needed for remove.
+ CHECK_FUNCTION_EXISTS("remove" CMAKE_HAVE_REMOVE)
+ if(NOT CMAKE_HAVE_REMOVE)
+ CHECK_LIBRARY_EXISTS("posix" "remove" "" CMAKE_LIB_POSIX_HAS_REMOVE)
+ if (CMAKE_LIB_POSIX_HAS_REMOVE)
+ set (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lposix)
+ endif ()
+ endif()
+
+ # Find library needed for shmat.
+ CHECK_FUNCTION_EXISTS("shmat" CMAKE_HAVE_SHMAT)
+ if(NOT CMAKE_HAVE_SHMAT)
+ CHECK_LIBRARY_EXISTS("ipc" "shmat" "" CMAKE_LIB_IPS_HAS_SHMAT)
+ if (CMAKE_LIB_IPS_HAS_SHMAT)
+ set (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lipc)
+ endif ()
+ endif()
+ endif()
+
+ if (X11_ICE_FOUND)
+ CHECK_LIBRARY_EXISTS("ICE" "IceConnectionNumber" "${X11_LIBRARY_DIR}"
+ CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
+ if(CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
+ set (X11_X_PRE_LIBS ${X11_ICE_LIB})
+ if(X11_SM_LIB)
+ set (X11_X_PRE_LIBS ${X11_SM_LIB} ${X11_X_PRE_LIBS})
+ endif()
+ endif()
+ endif ()
+
+ # Build the final list of libraries.
+ set(X11_LIBRARIES ${X11_X_PRE_LIBS} ${X11_LIBRARIES} ${X11_X_EXTRA_LIBS})
+
+ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake)
+ FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}"
+ "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
+ else ()
+ if (X11_FIND_REQUIRED)
+ message(FATAL_ERROR "Could not find X11")
+ endif ()
+ endif ()
+
+ mark_as_advanced(
+ X11_X11_INCLUDE_PATH
+ X11_X11_LIB
+ X11_Xext_LIB
+ X11_Xau_LIB
+ X11_Xau_INCLUDE_PATH
+ X11_Xlib_INCLUDE_PATH
+ X11_Xutil_INCLUDE_PATH
+ X11_Xcomposite_INCLUDE_PATH
+ X11_Xcomposite_LIB
+ X11_Xaccess_INCLUDE_PATH
+ X11_Xfixes_LIB
+ X11_Xfixes_INCLUDE_PATH
+ X11_Xrandr_LIB
+ X11_Xrandr_INCLUDE_PATH
+ X11_Xdamage_LIB
+ X11_Xdamage_INCLUDE_PATH
+ X11_Xrender_LIB
+ X11_Xrender_INCLUDE_PATH
+ X11_XRes_LIB
+ X11_XRes_INCLUDE_PATH
+ X11_Xxf86misc_LIB
+ X11_xf86misc_INCLUDE_PATH
+ X11_Xxf86vm_LIB
+ X11_xf86vmode_INCLUDE_PATH
+ X11_Xi_LIB
+ X11_Xi_INCLUDE_PATH
+ X11_Xinerama_LIB
+ X11_Xinerama_INCLUDE_PATH
+ X11_XTest_LIB
+ X11_XTest_INCLUDE_PATH
+ X11_Xcursor_LIB
+ X11_Xcursor_INCLUDE_PATH
+ X11_dpms_INCLUDE_PATH
+ X11_Xt_LIB
+ X11_Xt_INCLUDE_PATH
+ X11_Xdmcp_LIB
+ X11_LIBRARIES
+ X11_Xaccessrules_INCLUDE_PATH
+ X11_Xaccessstr_INCLUDE_PATH
+ X11_Xdmcp_INCLUDE_PATH
+ X11_Xkb_INCLUDE_PATH
+ X11_Xkblib_INCLUDE_PATH
+ X11_Xkbfile_INCLUDE_PATH
+ X11_Xkbfile_LIB
+ X11_Xmu_INCLUDE_PATH
+ X11_Xmu_LIB
+ X11_Xscreensaver_INCLUDE_PATH
+ X11_Xscreensaver_LIB
+ X11_Xpm_INCLUDE_PATH
+ X11_Xpm_LIB
+ X11_Xinput_LIB
+ X11_Xinput_INCLUDE_PATH
+ X11_Xft_LIB
+ X11_Xft_INCLUDE_PATH
+ X11_Xshape_INCLUDE_PATH
+ X11_Xv_LIB
+ X11_Xv_INCLUDE_PATH
+ X11_XShm_INCLUDE_PATH
+ X11_ICE_LIB
+ X11_ICE_INCLUDE_PATH
+ X11_SM_LIB
+ X11_SM_INCLUDE_PATH
+ X11_XSync_INCLUDE_PATH
+ )
+ set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_SAVE})
+ set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
+endif ()
+
+# X11_FIND_REQUIRED_<component> could be checked too
diff --git a/Modules/FindXMLRPC.cmake b/Modules/FindXMLRPC.cmake
new file mode 100644
index 0000000000..14917547d0
--- /dev/null
+++ b/Modules/FindXMLRPC.cmake
@@ -0,0 +1,159 @@
+#.rst:
+# FindXMLRPC
+# ----------
+#
+# Find xmlrpc
+#
+# Find the native XMLRPC headers and libraries.
+#
+# ::
+#
+# XMLRPC_INCLUDE_DIRS - where to find xmlrpc.h, etc.
+# XMLRPC_LIBRARIES - List of libraries when using xmlrpc.
+# XMLRPC_FOUND - True if xmlrpc found.
+#
+# XMLRPC modules may be specified as components for this find module.
+# Modules may be listed by running "xmlrpc-c-config". Modules include:
+#
+# ::
+#
+# c++ C++ wrapper code
+# libwww-client libwww-based client
+# cgi-server CGI-based server
+# abyss-server ABYSS-based server
+#
+# Typical usage:
+#
+# ::
+#
+# find_package(XMLRPC REQUIRED libwww-client)
+
+#=============================================================================
+# Copyright 2001-2009 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.)
+
+# First find the config script from which to obtain other values.
+find_program(XMLRPC_C_CONFIG NAMES xmlrpc-c-config)
+
+# Check whether we found anything.
+if(XMLRPC_C_CONFIG)
+ set(XMLRPC_FOUND 1)
+else()
+ set(XMLRPC_FOUND 0)
+endif()
+
+# Lookup the include directories needed for the components requested.
+if(XMLRPC_FOUND)
+ # Use the newer EXECUTE_PROCESS command if it is available.
+ if(COMMAND EXECUTE_PROCESS)
+ execute_process(
+ COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --cflags
+ OUTPUT_VARIABLE XMLRPC_C_CONFIG_CFLAGS
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
+ )
+ else()
+ exec_program(${XMLRPC_C_CONFIG} ARGS "${XMLRPC_FIND_COMPONENTS} --cflags"
+ OUTPUT_VARIABLE XMLRPC_C_CONFIG_CFLAGS
+ RETURN_VALUE XMLRPC_C_CONFIG_RESULT
+ )
+ endif()
+
+ # Parse the include flags.
+ if("${XMLRPC_C_CONFIG_RESULT}" STREQUAL "0")
+ # Convert the compile flags to a CMake list.
+ string(REGEX REPLACE " +" ";"
+ XMLRPC_C_CONFIG_CFLAGS "${XMLRPC_C_CONFIG_CFLAGS}")
+
+ # Look for -I options.
+ set(XMLRPC_INCLUDE_DIRS)
+ foreach(flag ${XMLRPC_C_CONFIG_CFLAGS})
+ if("${flag}" MATCHES "^-I(.+)")
+ file(TO_CMAKE_PATH "${CMAKE_MATCH_1}" DIR)
+ list(APPEND XMLRPC_INCLUDE_DIRS "${DIR}")
+ endif()
+ endforeach()
+ else()
+ message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
+ set(XMLRPC_FOUND 0)
+ endif()
+endif()
+
+# Lookup the libraries needed for the components requested.
+if(XMLRPC_FOUND)
+ # Use the newer EXECUTE_PROCESS command if it is available.
+ if(COMMAND EXECUTE_PROCESS)
+ execute_process(
+ COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --libs
+ OUTPUT_VARIABLE XMLRPC_C_CONFIG_LIBS
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
+ )
+ else()
+ exec_program(${XMLRPC_C_CONFIG} ARGS "${XMLRPC_FIND_COMPONENTS} --libs"
+ OUTPUT_VARIABLE XMLRPC_C_CONFIG_LIBS
+ RETURN_VALUE XMLRPC_C_CONFIG_RESULT
+ )
+ endif()
+
+ # Parse the library names and directories.
+ if("${XMLRPC_C_CONFIG_RESULT}" STREQUAL "0")
+ string(REGEX REPLACE " +" ";"
+ XMLRPC_C_CONFIG_LIBS "${XMLRPC_C_CONFIG_LIBS}")
+
+ # Look for -L flags for directories and -l flags for library names.
+ set(XMLRPC_LIBRARY_DIRS)
+ set(XMLRPC_LIBRARY_NAMES)
+ foreach(flag ${XMLRPC_C_CONFIG_LIBS})
+ if("${flag}" MATCHES "^-L(.+)")
+ file(TO_CMAKE_PATH "${CMAKE_MATCH_1}" DIR)
+ list(APPEND XMLRPC_LIBRARY_DIRS "${DIR}")
+ elseif("${flag}" MATCHES "^-l(.+)")
+ list(APPEND XMLRPC_LIBRARY_NAMES "${CMAKE_MATCH_1}")
+ endif()
+ endforeach()
+
+ # Search for each library needed using the directories given.
+ foreach(name ${XMLRPC_LIBRARY_NAMES})
+ # Look for this library.
+ find_library(XMLRPC_${name}_LIBRARY
+ NAMES ${name}
+ HINTS ${XMLRPC_LIBRARY_DIRS}
+ )
+ mark_as_advanced(XMLRPC_${name}_LIBRARY)
+
+ # If any library is not found then the whole package is not found.
+ if(NOT XMLRPC_${name}_LIBRARY)
+ set(XMLRPC_FOUND 0)
+ endif()
+
+ # Build an ordered list of all the libraries needed.
+ set(XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES} "${XMLRPC_${name}_LIBRARY}")
+ endforeach()
+ else()
+ message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
+ set(XMLRPC_FOUND 0)
+ endif()
+endif()
+
+# Report the results.
+if(NOT XMLRPC_FOUND)
+ set(XMLRPC_DIR_MESSAGE
+ "XMLRPC was not found. Make sure the entries XMLRPC_* are set.")
+ if(NOT XMLRPC_FIND_QUIETLY)
+ message(STATUS "${XMLRPC_DIR_MESSAGE}")
+ else()
+ if(XMLRPC_FIND_REQUIRED)
+ message(FATAL_ERROR "${XMLRPC_DIR_MESSAGE}")
+ endif()
+ endif()
+endif()
diff --git a/Modules/FindXerces.cmake b/Modules/FindXerces.cmake
new file mode 100644
index 0000000000..6c6007a1ea
--- /dev/null
+++ b/Modules/FindXerces.cmake
@@ -0,0 +1,85 @@
+#.rst:
+# FindXerces
+# ----------
+#
+# Find the Apache Xerces-C++ validating XML parser headers and libraries.
+#
+# This module reports information about the Xerces installation in
+# several variables. General variables::
+#
+# Xerces_FOUND - true if the Xerces headers and libraries were found
+# Xerces_VERSION - Xerces release version
+# Xerces_INCLUDE_DIRS - the directory containing the Xerces headers
+# Xerces_LIBRARIES - Xerces libraries to be linked
+#
+# The following cache variables may also be set::
+#
+# Xerces_INCLUDE_DIR - the directory containing the Xerces headers
+# Xerces_LIBRARY - the Xerces library
+
+# Written by Roger Leigh <rleigh@codelibre.net>
+
+#=============================================================================
+# Copyright 2014 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(_Xerces_GET_VERSION version_hdr)
+ file(STRINGS ${version_hdr} _contents REGEX "^[ \t]*#define XERCES_VERSION_.*")
+ if(_contents)
+ string(REGEX REPLACE ".*#define XERCES_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" Xerces_MAJOR "${_contents}")
+ string(REGEX REPLACE ".*#define XERCES_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" Xerces_MINOR "${_contents}")
+ string(REGEX REPLACE ".*#define XERCES_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" Xerces_PATCH "${_contents}")
+
+ if(NOT Xerces_MAJOR MATCHES "^[0-9]+$")
+ message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MAJOR!")
+ endif()
+ if(NOT Xerces_MINOR MATCHES "^[0-9]+$")
+ message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MINOR!")
+ endif()
+ if(NOT Xerces_PATCH MATCHES "^[0-9]+$")
+ message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_REVISION!")
+ endif()
+
+ set(Xerces_VERSION "${Xerces_MAJOR}.${Xerces_MINOR}.${Xerces_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(Xerces_INCLUDE_DIR
+ NAMES "xercesc/util/PlatformUtils.hpp"
+ DOC "Xerces-C++ include directory")
+mark_as_advanced(Xerces_INCLUDE_DIR)
+
+# Find all Xerces libraries
+find_library(Xerces_LIBRARY "xerces-c"
+ DOC "Xerces-C++ libraries")
+mark_as_advanced(Xerces_LIBRARY)
+
+if(Xerces_INCLUDE_DIR)
+ _Xerces_GET_VERSION("${Xerces_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Xerces
+ FOUND_VAR Xerces_FOUND
+ REQUIRED_VARS Xerces_LIBRARY
+ Xerces_INCLUDE_DIR
+ Xerces_VERSION
+ VERSION_VAR Xerces_VERSION
+ FAIL_MESSAGE "Failed to find Xerces")
+
+if(Xerces_FOUND)
+ set(Xerces_INCLUDE_DIRS "${Xerces_INCLUDE_DIR}")
+ set(Xerces_LIBRARIES "${Xerces_LIBRARY}")
+endif()
diff --git a/Modules/FindZLIB.cmake b/Modules/FindZLIB.cmake
new file mode 100644
index 0000000000..d4a27d5a17
--- /dev/null
+++ b/Modules/FindZLIB.cmake
@@ -0,0 +1,123 @@
+#.rst:
+# FindZLIB
+# --------
+#
+# Find the native ZLIB includes and library.
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines :prop_tgt:`IMPORTED` target ``ZLIB::ZLIB``, if
+# ZLIB has been found.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following variables:
+#
+# ::
+#
+# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc.
+# ZLIB_LIBRARIES - List of libraries when using zlib.
+# ZLIB_FOUND - True if zlib found.
+#
+# ::
+#
+# ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
+# ZLIB_VERSION_MAJOR - The major version of zlib
+# ZLIB_VERSION_MINOR - The minor version of zlib
+# ZLIB_VERSION_PATCH - The patch version of zlib
+# ZLIB_VERSION_TWEAK - The tweak version of zlib
+#
+# Backward Compatibility
+# ^^^^^^^^^^^^^^^^^^^^^^
+#
+# The following variable are provided for backward compatibility
+#
+# ::
+#
+# ZLIB_MAJOR_VERSION - The major version of zlib
+# ZLIB_MINOR_VERSION - The minor version of zlib
+# ZLIB_PATCH_VERSION - The patch version of zlib
+#
+# Hints
+# ^^^^^
+#
+# A user may set ``ZLIB_ROOT`` to a zlib installation root to tell this
+# module where to look.
+
+#=============================================================================
+# Copyright 2001-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+set(_ZLIB_SEARCHES)
+
+# Search ZLIB_ROOT first if it is set.
+if(ZLIB_ROOT)
+ set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH)
+ list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT)
+endif()
+
+# Normal search.
+set(_ZLIB_SEARCH_NORMAL
+ PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]"
+ "$ENV{PROGRAMFILES}/zlib"
+ )
+list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
+
+set(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1)
+
+# Try each search configuration.
+foreach(search ${_ZLIB_SEARCHES})
+ find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include)
+ find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib)
+endforeach()
+
+mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
+
+if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
+ file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
+
+ string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
+ string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
+ string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
+ set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
+
+ # only append a TWEAK version if it exists:
+ set(ZLIB_VERSION_TWEAK "")
+ if( "${ZLIB_H}" MATCHES "ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+)")
+ set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
+ set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}")
+ endif()
+
+ set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
+ set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
+ set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if
+# all listed variables are TRUE
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR
+ VERSION_VAR ZLIB_VERSION_STRING)
+
+if(ZLIB_FOUND)
+ set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
+ set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
+
+ if(NOT TARGET ZLIB::ZLIB)
+ add_library(ZLIB::ZLIB UNKNOWN IMPORTED)
+ set_target_properties(ZLIB::ZLIB PROPERTIES
+ IMPORTED_LOCATION "${ZLIB_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}")
+ endif()
+endif()
diff --git a/Modules/Findosg.cmake b/Modules/Findosg.cmake
new file mode 100644
index 0000000000..5ab2846fc8
--- /dev/null
+++ b/Modules/Findosg.cmake
@@ -0,0 +1,60 @@
+#.rst:
+# Findosg
+# -------
+#
+#
+#
+#
+#
+# NOTE: It is highly recommended that you use the new
+# FindOpenSceneGraph.cmake introduced in CMake 2.6.3 and not use this
+# Find module directly.
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osg This module defines
+#
+# OSG_FOUND - Was the Osg found? OSG_INCLUDE_DIR - Where to find the
+# headers OSG_LIBRARIES - The libraries to link against for the OSG (use
+# this)
+#
+# OSG_LIBRARY - The OSG library OSG_LIBRARY_DEBUG - The OSG debug
+# library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgUtil/SceneView>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSG osg/PositionAttitudeTransform)
+OSG_FIND_LIBRARY(OSG osg)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osg DEFAULT_MSG OSG_LIBRARY OSG_INCLUDE_DIR)
diff --git a/Modules/FindosgAnimation.cmake b/Modules/FindosgAnimation.cmake
new file mode 100644
index 0000000000..403e68e767
--- /dev/null
+++ b/Modules/FindosgAnimation.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgAnimation
+# ----------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgAnimation This module defines
+#
+# OSGANIMATION_FOUND - Was osgAnimation found? OSGANIMATION_INCLUDE_DIR
+# - Where to find the headers OSGANIMATION_LIBRARIES - The libraries to
+# link against for the OSG (use this)
+#
+# OSGANIMATION_LIBRARY - The OSG library OSGANIMATION_LIBRARY_DEBUG -
+# The OSG debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgAnimation/Animation>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGANIMATION osgAnimation/Animation)
+OSG_FIND_LIBRARY(OSGANIMATION osgAnimation)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgAnimation DEFAULT_MSG
+ OSGANIMATION_LIBRARY OSGANIMATION_INCLUDE_DIR)
diff --git a/Modules/FindosgDB.cmake b/Modules/FindosgDB.cmake
new file mode 100644
index 0000000000..0e5bdef828
--- /dev/null
+++ b/Modules/FindosgDB.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgDB
+# ---------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgDB This module defines
+#
+# OSGDB_FOUND - Was osgDB found? OSGDB_INCLUDE_DIR - Where to find the
+# headers OSGDB_LIBRARIES - The libraries to link against for the osgDB
+# (use this)
+#
+# OSGDB_LIBRARY - The osgDB library OSGDB_LIBRARY_DEBUG - The osgDB
+# debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgDB/DatabasePager>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGDB osgDB/DatabasePager)
+OSG_FIND_LIBRARY(OSGDB osgDB)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgDB DEFAULT_MSG
+ OSGDB_LIBRARY OSGDB_INCLUDE_DIR)
diff --git a/Modules/FindosgFX.cmake b/Modules/FindosgFX.cmake
new file mode 100644
index 0000000000..7b2cb76c1c
--- /dev/null
+++ b/Modules/FindosgFX.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgFX
+# ---------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgFX This module defines
+#
+# OSGFX_FOUND - Was osgFX found? OSGFX_INCLUDE_DIR - Where to find the
+# headers OSGFX_LIBRARIES - The libraries to link against for the osgFX
+# (use this)
+#
+# OSGFX_LIBRARY - The osgFX library OSGFX_LIBRARY_DEBUG - The osgFX
+# debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgFX/BumpMapping>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGFX osgFX/BumpMapping)
+OSG_FIND_LIBRARY(OSGFX osgFX)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgFX DEFAULT_MSG
+ OSGFX_LIBRARY OSGFX_INCLUDE_DIR)
diff --git a/Modules/FindosgGA.cmake b/Modules/FindosgGA.cmake
new file mode 100644
index 0000000000..2e80ff2fa1
--- /dev/null
+++ b/Modules/FindosgGA.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgGA
+# ---------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgGA This module defines
+#
+# OSGGA_FOUND - Was osgGA found? OSGGA_INCLUDE_DIR - Where to find the
+# headers OSGGA_LIBRARIES - The libraries to link against for the osgGA
+# (use this)
+#
+# OSGGA_LIBRARY - The osgGA library OSGGA_LIBRARY_DEBUG - The osgGA
+# debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgGA/FlightManipulator>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGGA osgGA/FlightManipulator)
+OSG_FIND_LIBRARY(OSGGA osgGA)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgGA DEFAULT_MSG
+ OSGGA_LIBRARY OSGGA_INCLUDE_DIR)
diff --git a/Modules/FindosgIntrospection.cmake b/Modules/FindosgIntrospection.cmake
new file mode 100644
index 0000000000..1b52a6a240
--- /dev/null
+++ b/Modules/FindosgIntrospection.cmake
@@ -0,0 +1,56 @@
+#.rst:
+# FindosgIntrospection
+# --------------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgINTROSPECTION This module defines
+#
+# OSGINTROSPECTION_FOUND - Was osgIntrospection found?
+# OSGINTROSPECTION_INCLUDE_DIR - Where to find the headers
+# OSGINTROSPECTION_LIBRARIES - The libraries to link for
+# osgIntrospection (use this)
+#
+# OSGINTROSPECTION_LIBRARY - The osgIntrospection library
+# OSGINTROSPECTION_LIBRARY_DEBUG - The osgIntrospection debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgIntrospection/Reflection>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGINTROSPECTION osgIntrospection/Reflection)
+OSG_FIND_LIBRARY(OSGINTROSPECTION osgIntrospection)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgIntrospection DEFAULT_MSG
+ OSGINTROSPECTION_LIBRARY OSGINTROSPECTION_INCLUDE_DIR)
diff --git a/Modules/FindosgManipulator.cmake b/Modules/FindosgManipulator.cmake
new file mode 100644
index 0000000000..6f5408241d
--- /dev/null
+++ b/Modules/FindosgManipulator.cmake
@@ -0,0 +1,56 @@
+#.rst:
+# FindosgManipulator
+# ------------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgManipulator This module defines
+#
+# OSGMANIPULATOR_FOUND - Was osgManipulator found?
+# OSGMANIPULATOR_INCLUDE_DIR - Where to find the headers
+# OSGMANIPULATOR_LIBRARIES - The libraries to link for osgManipulator
+# (use this)
+#
+# OSGMANIPULATOR_LIBRARY - The osgManipulator library
+# OSGMANIPULATOR_LIBRARY_DEBUG - The osgManipulator debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgManipulator/TrackballDragger>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGMANIPULATOR osgManipulator/TrackballDragger)
+OSG_FIND_LIBRARY(OSGMANIPULATOR osgManipulator)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgManipulator DEFAULT_MSG
+ OSGMANIPULATOR_LIBRARY OSGMANIPULATOR_INCLUDE_DIR)
diff --git a/Modules/FindosgParticle.cmake b/Modules/FindosgParticle.cmake
new file mode 100644
index 0000000000..82e9a13649
--- /dev/null
+++ b/Modules/FindosgParticle.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgParticle
+# ---------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgParticle This module defines
+#
+# OSGPARTICLE_FOUND - Was osgParticle found? OSGPARTICLE_INCLUDE_DIR -
+# Where to find the headers OSGPARTICLE_LIBRARIES - The libraries to
+# link for osgParticle (use this)
+#
+# OSGPARTICLE_LIBRARY - The osgParticle library
+# OSGPARTICLE_LIBRARY_DEBUG - The osgParticle debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgParticle/FireEffect>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGPARTICLE osgParticle/FireEffect)
+OSG_FIND_LIBRARY(OSGPARTICLE osgParticle)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgParticle DEFAULT_MSG
+ OSGPARTICLE_LIBRARY OSGPARTICLE_INCLUDE_DIR)
diff --git a/Modules/FindosgPresentation.cmake b/Modules/FindosgPresentation.cmake
new file mode 100644
index 0000000000..1cd57b3012
--- /dev/null
+++ b/Modules/FindosgPresentation.cmake
@@ -0,0 +1,57 @@
+#.rst:
+# FindosgPresentation
+# -------------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgPresentation This module defines
+#
+# OSGPRESENTATION_FOUND - Was osgPresentation found?
+# OSGPRESENTATION_INCLUDE_DIR - Where to find the headers
+# OSGPRESENTATION_LIBRARIES - The libraries to link for osgPresentation
+# (use this)
+#
+# OSGPRESENTATION_LIBRARY - The osgPresentation library
+# OSGPRESENTATION_LIBRARY_DEBUG - The osgPresentation debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing. Modified to work with osgPresentation by Robert
+# Osfield, January 2012.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgPresentation/SlideEventHandler>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGPRESENTATION osgPresentation/SlideEventHandler)
+OSG_FIND_LIBRARY(OSGPRESENTATION osgPresentation)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgPresentation DEFAULT_MSG
+ OSGPRESENTATION_LIBRARY OSGPRESENTATION_INCLUDE_DIR)
diff --git a/Modules/FindosgProducer.cmake b/Modules/FindosgProducer.cmake
new file mode 100644
index 0000000000..ad4902b867
--- /dev/null
+++ b/Modules/FindosgProducer.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgProducer
+# ---------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgProducer This module defines
+#
+# OSGPRODUCER_FOUND - Was osgProducer found? OSGPRODUCER_INCLUDE_DIR -
+# Where to find the headers OSGPRODUCER_LIBRARIES - The libraries to
+# link for osgProducer (use this)
+#
+# OSGPRODUCER_LIBRARY - The osgProducer library
+# OSGPRODUCER_LIBRARY_DEBUG - The osgProducer debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgProducer/OsgSceneHandler>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGPRODUCER osgProducer/OsgSceneHandler)
+OSG_FIND_LIBRARY(OSGPRODUCER osgProducer)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgProducer DEFAULT_MSG
+ OSGPRODUCER_LIBRARY OSGPRODUCER_INCLUDE_DIR)
diff --git a/Modules/FindosgQt.cmake b/Modules/FindosgQt.cmake
new file mode 100644
index 0000000000..b5c1718c81
--- /dev/null
+++ b/Modules/FindosgQt.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgQt
+# ---------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgQt This module defines
+#
+# OSGQT_FOUND - Was osgQt found? OSGQT_INCLUDE_DIR - Where to find the
+# headers OSGQT_LIBRARIES - The libraries to link for osgQt (use this)
+#
+# OSGQT_LIBRARY - The osgQt library OSGQT_LIBRARY_DEBUG - The osgQt
+# debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing. Modified to work with osgQt by Robert Osfield,
+# January 2012.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgQt/GraphicsWindowQt>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGQT osgQt/GraphicsWindowQt)
+OSG_FIND_LIBRARY(OSGQT osgQt)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgQt DEFAULT_MSG
+ OSGQT_LIBRARY OSGQT_INCLUDE_DIR)
diff --git a/Modules/FindosgShadow.cmake b/Modules/FindosgShadow.cmake
new file mode 100644
index 0000000000..b0d22e7af4
--- /dev/null
+++ b/Modules/FindosgShadow.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgShadow
+# -------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgShadow This module defines
+#
+# OSGSHADOW_FOUND - Was osgShadow found? OSGSHADOW_INCLUDE_DIR - Where
+# to find the headers OSGSHADOW_LIBRARIES - The libraries to link for
+# osgShadow (use this)
+#
+# OSGSHADOW_LIBRARY - The osgShadow library OSGSHADOW_LIBRARY_DEBUG -
+# The osgShadow debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgShadow/ShadowTexture>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGSHADOW osgShadow/ShadowTexture)
+OSG_FIND_LIBRARY(OSGSHADOW osgShadow)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgShadow DEFAULT_MSG
+ OSGSHADOW_LIBRARY OSGSHADOW_INCLUDE_DIR)
diff --git a/Modules/FindosgSim.cmake b/Modules/FindosgSim.cmake
new file mode 100644
index 0000000000..ce088dc6d2
--- /dev/null
+++ b/Modules/FindosgSim.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgSim
+# ----------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgSim This module defines
+#
+# OSGSIM_FOUND - Was osgSim found? OSGSIM_INCLUDE_DIR - Where to find
+# the headers OSGSIM_LIBRARIES - The libraries to link for osgSim (use
+# this)
+#
+# OSGSIM_LIBRARY - The osgSim library OSGSIM_LIBRARY_DEBUG - The osgSim
+# debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgSim/ImpostorSprite>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGSIM osgSim/ImpostorSprite)
+OSG_FIND_LIBRARY(OSGSIM osgSim)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgSim DEFAULT_MSG
+ OSGSIM_LIBRARY OSGSIM_INCLUDE_DIR)
diff --git a/Modules/FindosgTerrain.cmake b/Modules/FindosgTerrain.cmake
new file mode 100644
index 0000000000..bfde773ef6
--- /dev/null
+++ b/Modules/FindosgTerrain.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgTerrain
+# --------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgTerrain This module defines
+#
+# OSGTERRAIN_FOUND - Was osgTerrain found? OSGTERRAIN_INCLUDE_DIR -
+# Where to find the headers OSGTERRAIN_LIBRARIES - The libraries to link
+# for osgTerrain (use this)
+#
+# OSGTERRAIN_LIBRARY - The osgTerrain library OSGTERRAIN_LIBRARY_DEBUG -
+# The osgTerrain debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgTerrain/Terrain>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGTERRAIN osgTerrain/Terrain)
+OSG_FIND_LIBRARY(OSGTERRAIN osgTerrain)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgTerrain DEFAULT_MSG
+ OSGTERRAIN_LIBRARY OSGTERRAIN_INCLUDE_DIR)
diff --git a/Modules/FindosgText.cmake b/Modules/FindosgText.cmake
new file mode 100644
index 0000000000..32cd115c19
--- /dev/null
+++ b/Modules/FindosgText.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgText
+# -----------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgText This module defines
+#
+# OSGTEXT_FOUND - Was osgText found? OSGTEXT_INCLUDE_DIR - Where to find
+# the headers OSGTEXT_LIBRARIES - The libraries to link for osgText (use
+# this)
+#
+# OSGTEXT_LIBRARY - The osgText library OSGTEXT_LIBRARY_DEBUG - The
+# osgText debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgText/Text>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGTEXT osgText/Text)
+OSG_FIND_LIBRARY(OSGTEXT osgText)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgText DEFAULT_MSG
+ OSGTEXT_LIBRARY OSGTEXT_INCLUDE_DIR)
diff --git a/Modules/FindosgUtil.cmake b/Modules/FindosgUtil.cmake
new file mode 100644
index 0000000000..97974255c8
--- /dev/null
+++ b/Modules/FindosgUtil.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgUtil
+# -----------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgUtil This module defines
+#
+# OSGUTIL_FOUND - Was osgUtil found? OSGUTIL_INCLUDE_DIR - Where to find
+# the headers OSGUTIL_LIBRARIES - The libraries to link for osgUtil (use
+# this)
+#
+# OSGUTIL_LIBRARY - The osgUtil library OSGUTIL_LIBRARY_DEBUG - The
+# osgUtil debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgUtil/SceneView>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGUTIL osgUtil/SceneView)
+OSG_FIND_LIBRARY(OSGUTIL osgUtil)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgUtil DEFAULT_MSG
+ OSGUTIL_LIBRARY OSGUTIL_INCLUDE_DIR)
diff --git a/Modules/FindosgViewer.cmake b/Modules/FindosgViewer.cmake
new file mode 100644
index 0000000000..b3555302d5
--- /dev/null
+++ b/Modules/FindosgViewer.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgViewer
+# -------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgViewer This module defines
+#
+# OSGVIEWER_FOUND - Was osgViewer found? OSGVIEWER_INCLUDE_DIR - Where
+# to find the headers OSGVIEWER_LIBRARIES - The libraries to link for
+# osgViewer (use this)
+#
+# OSGVIEWER_LIBRARY - The osgViewer library OSGVIEWER_LIBRARY_DEBUG -
+# The osgViewer debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgViewer/Viewer>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGVIEWER osgViewer/Viewer)
+OSG_FIND_LIBRARY(OSGVIEWER osgViewer)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgViewer DEFAULT_MSG
+ OSGVIEWER_LIBRARY OSGVIEWER_INCLUDE_DIR)
diff --git a/Modules/FindosgVolume.cmake b/Modules/FindosgVolume.cmake
new file mode 100644
index 0000000000..8d3ad6c5d1
--- /dev/null
+++ b/Modules/FindosgVolume.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindosgVolume
+# -------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgVolume This module defines
+#
+# OSGVOLUME_FOUND - Was osgVolume found? OSGVOLUME_INCLUDE_DIR - Where
+# to find the headers OSGVOLUME_LIBRARIES - The libraries to link for
+# osgVolume (use this)
+#
+# OSGVOLUME_LIBRARY - The osgVolume library OSGVOLUME_LIBRARY_DEBUG -
+# The osgVolume debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# Created by Eric Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgVolume/Volume>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGVOLUME osgVolume/Volume)
+OSG_FIND_LIBRARY(OSGVOLUME osgVolume)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgVolume DEFAULT_MSG
+ OSGVOLUME_LIBRARY OSGVOLUME_INCLUDE_DIR)
diff --git a/Modules/FindosgWidget.cmake b/Modules/FindosgWidget.cmake
new file mode 100644
index 0000000000..ec3c3bca9d
--- /dev/null
+++ b/Modules/FindosgWidget.cmake
@@ -0,0 +1,56 @@
+#.rst:
+# FindosgWidget
+# -------------
+#
+#
+#
+# This is part of the Findosg* suite used to find OpenSceneGraph
+# components. Each component is separate and you must opt in to each
+# module. You must also opt into OpenGL and OpenThreads (and Producer
+# if needed) as these modules won't do it for you. This is to allow you
+# control over your own system piece by piece in case you need to opt
+# out of certain components or change the Find behavior for a particular
+# module (perhaps because the default FindOpenGL.cmake module doesn't
+# work with your system as an example). If you want to use a more
+# convenient module that includes everything, use the
+# FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules.
+#
+# Locate osgWidget This module defines
+#
+# OSGWIDGET_FOUND - Was osgWidget found? OSGWIDGET_INCLUDE_DIR - Where
+# to find the headers OSGWIDGET_LIBRARIES - The libraries to link for
+# osgWidget (use this)
+#
+# OSGWIDGET_LIBRARY - The osgWidget library OSGWIDGET_LIBRARY_DEBUG -
+# The osgWidget debug library
+#
+# $OSGDIR is an environment variable that would correspond to the
+# ./configure --prefix=$OSGDIR used in building osg.
+#
+# FindosgWidget.cmake tweaked from Findosg* suite as created by Eric
+# Wing.
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+# Header files are presumed to be included like
+# #include <osg/PositionAttitudeTransform>
+# #include <osgWidget/Widget>
+
+include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
+OSG_FIND_PATH (OSGWIDGET osgWidget/Widget)
+OSG_FIND_LIBRARY(OSGWIDGET osgWidget)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgWidget DEFAULT_MSG
+ OSGWIDGET_LIBRARY OSGWIDGET_INCLUDE_DIR)
diff --git a/Modules/Findosg_functions.cmake b/Modules/Findosg_functions.cmake
new file mode 100644
index 0000000000..d10fae92fd
--- /dev/null
+++ b/Modules/Findosg_functions.cmake
@@ -0,0 +1,118 @@
+#.rst:
+# Findosg_functions
+# -----------------
+#
+#
+#
+#
+#
+# This CMake file contains two macros to assist with searching for OSG
+# libraries and nodekits. Please see FindOpenSceneGraph.cmake for full
+# documentation.
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2009-2012 Philip Lowman <philip@yhbt.com>
+#
+# 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.)
+
+#
+# OSG_FIND_PATH
+#
+function(OSG_FIND_PATH module header)
+ string(TOUPPER ${module} module_uc)
+
+ # Try the user's environment request before anything else.
+ find_path(${module_uc}_INCLUDE_DIR ${header}
+ HINTS
+ ENV ${module_uc}_DIR
+ ENV OSG_DIR
+ ENV OSGDIR
+ ENV OSG_ROOT
+ ${${module_uc}_DIR}
+ ${OSG_DIR}
+ PATH_SUFFIXES include
+ PATHS
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+ /usr/freeware
+ )
+endfunction()
+
+
+#
+# OSG_FIND_LIBRARY
+#
+function(OSG_FIND_LIBRARY module library)
+ string(TOUPPER ${module} module_uc)
+
+ find_library(${module_uc}_LIBRARY
+ NAMES ${library}
+ HINTS
+ ENV ${module_uc}_DIR
+ ENV OSG_DIR
+ ENV OSGDIR
+ ENV OSG_ROOT
+ ${${module_uc}_DIR}
+ ${OSG_DIR}
+ PATH_SUFFIXES lib
+ PATHS
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+ /usr/freeware
+ )
+
+ find_library(${module_uc}_LIBRARY_DEBUG
+ NAMES ${library}d
+ HINTS
+ ENV ${module_uc}_DIR
+ ENV OSG_DIR
+ ENV OSGDIR
+ ENV OSG_ROOT
+ ${${module_uc}_DIR}
+ ${OSG_DIR}
+ PATH_SUFFIXES lib
+ PATHS
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+ /usr/freeware
+ )
+
+ if(NOT ${module_uc}_LIBRARY_DEBUG)
+ # They don't have a debug library
+ set(${module_uc}_LIBRARY_DEBUG ${${module_uc}_LIBRARY} PARENT_SCOPE)
+ set(${module_uc}_LIBRARIES ${${module_uc}_LIBRARY} PARENT_SCOPE)
+ else()
+ # They really have a FOO_LIBRARY_DEBUG
+ set(${module_uc}_LIBRARIES
+ optimized ${${module_uc}_LIBRARY}
+ debug ${${module_uc}_LIBRARY_DEBUG}
+ PARENT_SCOPE
+ )
+ endif()
+endfunction()
+
+#
+# OSG_MARK_AS_ADVANCED
+# Just a convenience function for calling MARK_AS_ADVANCED
+#
+function(OSG_MARK_AS_ADVANCED _module)
+ string(TOUPPER ${_module} _module_UC)
+ mark_as_advanced(${_module_UC}_INCLUDE_DIR)
+ mark_as_advanced(${_module_UC}_LIBRARY)
+ mark_as_advanced(${_module_UC}_LIBRARY_DEBUG)
+endfunction()
diff --git a/Modules/FindwxWidgets.cmake b/Modules/FindwxWidgets.cmake
new file mode 100644
index 0000000000..7ef06a88f5
--- /dev/null
+++ b/Modules/FindwxWidgets.cmake
@@ -0,0 +1,1082 @@
+#.rst:
+# FindwxWidgets
+# -------------
+#
+# Find a wxWidgets (a.k.a., wxWindows) installation.
+#
+# This module finds if wxWidgets is installed and selects a default
+# configuration to use. wxWidgets is a modular library. To specify the
+# modules that you will use, you need to name them as components to the
+# package:
+#
+# find_package(wxWidgets COMPONENTS core base ...)
+#
+# There are two search branches: a windows style and a unix style. For
+# windows, the following variables are searched for and set to defaults
+# in case of multiple choices. Change them if the defaults are not
+# desired (i.e., these are the only variables you should change to
+# select a configuration):
+#
+# ::
+#
+# wxWidgets_ROOT_DIR - Base wxWidgets directory
+# (e.g., C:/wxWidgets-2.6.3).
+# wxWidgets_LIB_DIR - Path to wxWidgets libraries
+# (e.g., C:/wxWidgets-2.6.3/lib/vc_lib).
+# wxWidgets_CONFIGURATION - Configuration to use
+# (e.g., msw, mswd, mswu, mswunivud, etc.)
+# wxWidgets_EXCLUDE_COMMON_LIBRARIES
+# - Set to TRUE to exclude linking of
+# commonly required libs (e.g., png tiff
+# jpeg zlib regex expat).
+#
+#
+#
+# For unix style it uses the wx-config utility. You can select between
+# debug/release, unicode/ansi, universal/non-universal, and
+# static/shared in the QtDialog or ccmake interfaces by turning ON/OFF
+# the following variables:
+#
+# ::
+#
+# wxWidgets_USE_DEBUG
+# wxWidgets_USE_UNICODE
+# wxWidgets_USE_UNIVERSAL
+# wxWidgets_USE_STATIC
+#
+#
+#
+# There is also a wxWidgets_CONFIG_OPTIONS variable for all other
+# options that need to be passed to the wx-config utility. For example,
+# to use the base toolkit found in the /usr/local path, set the variable
+# (before calling the FIND_PACKAGE command) as such:
+#
+# ::
+#
+# set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr)
+#
+#
+#
+# The following are set after the configuration is done for both windows
+# and unix style:
+#
+# ::
+#
+# wxWidgets_FOUND - Set to TRUE if wxWidgets was found.
+# wxWidgets_INCLUDE_DIRS - Include directories for WIN32
+# i.e., where to find "wx/wx.h" and
+# "wx/setup.h"; possibly empty for unices.
+# wxWidgets_LIBRARIES - Path to the wxWidgets libraries.
+# wxWidgets_LIBRARY_DIRS - compile time link dirs, useful for
+# rpath on UNIX. Typically an empty string
+# in WIN32 environment.
+# wxWidgets_DEFINITIONS - Contains defines required to compile/link
+# against WX, e.g. WXUSINGDLL
+# wxWidgets_DEFINITIONS_DEBUG- Contains defines required to compile/link
+# against WX debug builds, e.g. __WXDEBUG__
+# wxWidgets_CXX_FLAGS - Include dirs and compiler flags for
+# unices, empty on WIN32. Essentially
+# "`wx-config --cxxflags`".
+# wxWidgets_USE_FILE - Convenience include file.
+#
+#
+#
+# Sample usage:
+#
+# ::
+#
+# # Note that for MinGW users the order of libs is important!
+# find_package(wxWidgets COMPONENTS net gl core base)
+# if(wxWidgets_FOUND)
+# include(${wxWidgets_USE_FILE})
+# # and for each of your dependent executable/library targets:
+# target_link_libraries(<YourTarget> ${wxWidgets_LIBRARIES})
+# endif()
+#
+#
+#
+# If wxWidgets is required (i.e., not an optional part):
+#
+# ::
+#
+# find_package(wxWidgets REQUIRED net gl core base)
+# include(${wxWidgets_USE_FILE})
+# # and for each of your dependent executable/library targets:
+# target_link_libraries(<YourTarget> ${wxWidgets_LIBRARIES})
+
+#=============================================================================
+# Copyright 2004-2009 Kitware, Inc.
+# Copyright 2007-2009 Miguel A. Figueroa-Villanueva <miguelf at ieee dot 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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+#
+# FIXME: check this and provide a correct sample usage...
+# Remember to connect back to the upper text.
+# Sample usage with monolithic wx build:
+#
+# find_package(wxWidgets COMPONENTS mono)
+# ...
+
+# NOTES
+#
+# This module has been tested on the WIN32 platform with wxWidgets
+# 2.6.2, 2.6.3, and 2.5.3. However, it has been designed to
+# easily extend support to all possible builds, e.g., static/shared,
+# debug/release, unicode, universal, multilib/monolithic, etc..
+#
+# If you want to use the module and your build type is not supported
+# out-of-the-box, please contact me to exchange information on how
+# your system is setup and I'll try to add support for it.
+#
+# AUTHOR
+#
+# Miguel A. Figueroa-Villanueva (miguelf at ieee dot org).
+# Jan Woetzel (jw at mip.informatik.uni-kiel.de).
+#
+# Based on previous works of:
+# Jan Woetzel (FindwxWindows.cmake),
+# Jorgen Bodde and Jerry Fath (FindwxWin.cmake).
+
+# TODO/ideas
+#
+# (1) Option/Setting to use all available wx libs
+# In contrast to expert developer who lists the
+# minimal set of required libs in wxWidgets_USE_LIBS
+# there is the newbie user:
+# - who just wants to link against WX with more 'magic'
+# - doesn't know the internal structure of WX or how it was built,
+# in particular if it is monolithic or not
+# - want to link against all available WX libs
+# Basically, the intent here is to mimic what wx-config would do by
+# default (i.e., `wx-config --libs`).
+#
+# Possible solution:
+# Add a reserved keyword "std" that initializes to what wx-config
+# would default to. If the user has not set the wxWidgets_USE_LIBS,
+# default to "std" instead of "base core" as it is now. To implement
+# "std" will basically boil down to a FOR_EACH lib-FOUND, but maybe
+# checking whether a minimal set was found.
+
+
+# FIXME: This and all the DBG_MSG calls should be removed after the
+# module stabilizes.
+#
+# Helper macro to control the debugging output globally. There are
+# two versions for controlling how verbose your output should be.
+macro(DBG_MSG _MSG)
+# message(STATUS
+# "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
+endmacro()
+macro(DBG_MSG_V _MSG)
+# message(STATUS
+# "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
+endmacro()
+
+# Clear return values in case the module is loaded more than once.
+set(wxWidgets_FOUND FALSE)
+set(wxWidgets_INCLUDE_DIRS "")
+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:
+# http://www.cmake.org/pipermail/cmake/2008-April/021115.html
+# http://www.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.
+#
+# If wxWidgets_USE_LIBS is set:
+# - if using <components>, then override wxWidgets_USE_LIBS
+# - else set wxWidgets_FIND_COMPONENTS to wxWidgets_USE_LIBS
+if(wxWidgets_USE_LIBS AND NOT wxWidgets_FIND_COMPONENTS)
+ set(wxWidgets_FIND_COMPONENTS ${wxWidgets_USE_LIBS})
+endif()
+DBG_MSG("wxWidgets_FIND_COMPONENTS : ${wxWidgets_FIND_COMPONENTS}")
+
+# Add the convenience use file if available.
+#
+# Get dir of this file which may reside in:
+# - CMAKE_MAKE_ROOT/Modules on CMake installation
+# - CMAKE_MODULE_PATH if user prefers his own specialized version
+set(wxWidgets_USE_FILE "")
+get_filename_component(
+ wxWidgets_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
+# Prefer an existing customized version, but the user might override
+# the FindwxWidgets module and not the UsewxWidgets one.
+if(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
+ set(wxWidgets_USE_FILE
+ "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
+else()
+ set(wxWidgets_USE_FILE UsewxWidgets)
+endif()
+
+#=====================================================================
+# Determine whether unix or win32 paths should be used
+#=====================================================================
+if(WIN32 AND NOT CYGWIN AND NOT MSYS AND NOT CMAKE_CROSSCOMPILING)
+ set(wxWidgets_FIND_STYLE "win32")
+else()
+ set(wxWidgets_FIND_STYLE "unix")
+endif()
+
+#=====================================================================
+# WIN32_FIND_STYLE
+#=====================================================================
+if(wxWidgets_FIND_STYLE STREQUAL "win32")
+ # Useful common wx libs needed by almost all components.
+ set(wxWidgets_COMMON_LIBRARIES png tiff jpeg zlib regex expat)
+
+ # DEPRECATED: Use find_package(wxWidgets COMPONENTS mono) instead.
+ if(NOT wxWidgets_FIND_COMPONENTS)
+ if(wxWidgets_USE_MONOLITHIC)
+ set(wxWidgets_FIND_COMPONENTS mono)
+ else()
+ set(wxWidgets_FIND_COMPONENTS core base) # this is default
+ endif()
+ endif()
+
+ # Add the common (usually required libs) unless
+ # wxWidgets_EXCLUDE_COMMON_LIBRARIES has been set.
+ if(NOT wxWidgets_EXCLUDE_COMMON_LIBRARIES)
+ list(APPEND wxWidgets_FIND_COMPONENTS
+ ${wxWidgets_COMMON_LIBRARIES})
+ endif()
+
+ #-------------------------------------------------------------------
+ # WIN32: Helper MACROS
+ #-------------------------------------------------------------------
+ #
+ # Get filename components for a configuration. For example,
+ # if _CONFIGURATION = mswunivud, then _UNV=univ, _UCD=u _DBG=d
+ # if _CONFIGURATION = mswu, then _UNV="", _UCD=u _DBG=""
+ #
+ macro(WX_GET_NAME_COMPONENTS _CONFIGURATION _UNV _UCD _DBG)
+ string(REGEX MATCH "univ" ${_UNV} "${_CONFIGURATION}")
+ string(REGEX REPLACE "msw.*(u)[d]*$" "u" ${_UCD} "${_CONFIGURATION}")
+ if(${_UCD} STREQUAL ${_CONFIGURATION})
+ set(${_UCD} "")
+ endif()
+ string(REGEX MATCH "d$" ${_DBG} "${_CONFIGURATION}")
+ endmacro()
+
+ #
+ # Find libraries associated to a configuration.
+ #
+ macro(WX_FIND_LIBS _UNV _UCD _DBG)
+ DBG_MSG_V("m_unv = ${_UNV}")
+ DBG_MSG_V("m_ucd = ${_UCD}")
+ DBG_MSG_V("m_dbg = ${_DBG}")
+
+ # FIXME: What if both regex libs are available. regex should be
+ # found outside the loop and only wx${LIB}${_UCD}${_DBG}.
+ # Find wxWidgets common libraries.
+ foreach(LIB ${wxWidgets_COMMON_LIBRARIES} scintilla)
+ find_library(WX_${LIB}${_DBG}
+ NAMES
+ wx${LIB}${_UCD}${_DBG} # for regex
+ wx${LIB}${_DBG}
+ PATHS ${WX_LIB_DIR}
+ NO_DEFAULT_PATH
+ )
+ mark_as_advanced(WX_${LIB}${_DBG})
+ endforeach()
+
+ # Find wxWidgets multilib base libraries.
+ find_library(WX_base${_DBG}
+ NAMES
+ wxbase30${_UCD}${_DBG}
+ wxbase29${_UCD}${_DBG}
+ wxbase28${_UCD}${_DBG}
+ wxbase27${_UCD}${_DBG}
+ wxbase26${_UCD}${_DBG}
+ wxbase25${_UCD}${_DBG}
+ PATHS ${WX_LIB_DIR}
+ NO_DEFAULT_PATH
+ )
+ mark_as_advanced(WX_base${_DBG})
+ foreach(LIB net odbc xml)
+ find_library(WX_${LIB}${_DBG}
+ NAMES
+ wxbase30${_UCD}${_DBG}_${LIB}
+ wxbase29${_UCD}${_DBG}_${LIB}
+ wxbase28${_UCD}${_DBG}_${LIB}
+ wxbase27${_UCD}${_DBG}_${LIB}
+ wxbase26${_UCD}${_DBG}_${LIB}
+ wxbase25${_UCD}${_DBG}_${LIB}
+ PATHS ${WX_LIB_DIR}
+ NO_DEFAULT_PATH
+ )
+ mark_as_advanced(WX_${LIB}${_DBG})
+ endforeach()
+
+ # Find wxWidgets monolithic library.
+ find_library(WX_mono${_DBG}
+ NAMES
+ wxmsw${_UNV}30${_UCD}${_DBG}
+ wxmsw${_UNV}29${_UCD}${_DBG}
+ wxmsw${_UNV}28${_UCD}${_DBG}
+ wxmsw${_UNV}27${_UCD}${_DBG}
+ wxmsw${_UNV}26${_UCD}${_DBG}
+ wxmsw${_UNV}25${_UCD}${_DBG}
+ PATHS ${WX_LIB_DIR}
+ NO_DEFAULT_PATH
+ )
+ mark_as_advanced(WX_mono${_DBG})
+
+ # Find wxWidgets multilib libraries.
+ foreach(LIB core adv aui html media xrc dbgrid gl qa richtext
+ stc ribbon propgrid webview)
+ find_library(WX_${LIB}${_DBG}
+ NAMES
+ wxmsw${_UNV}30${_UCD}${_DBG}_${LIB}
+ wxmsw${_UNV}29${_UCD}${_DBG}_${LIB}
+ wxmsw${_UNV}28${_UCD}${_DBG}_${LIB}
+ wxmsw${_UNV}27${_UCD}${_DBG}_${LIB}
+ wxmsw${_UNV}26${_UCD}${_DBG}_${LIB}
+ wxmsw${_UNV}25${_UCD}${_DBG}_${LIB}
+ PATHS ${WX_LIB_DIR}
+ NO_DEFAULT_PATH
+ )
+ mark_as_advanced(WX_${LIB}${_DBG})
+ endforeach()
+ endmacro()
+
+ #
+ # Clear all library paths, so that FIND_LIBRARY refinds them.
+ #
+ # Clear a lib, reset its found flag, and mark as advanced.
+ macro(WX_CLEAR_LIB _LIB)
+ set(${_LIB} "${_LIB}-NOTFOUND" CACHE FILEPATH "Cleared." FORCE)
+ set(${_LIB}_FOUND FALSE)
+ mark_as_advanced(${_LIB})
+ endmacro()
+ # Clear all debug or release library paths (arguments are "d" or "").
+ macro(WX_CLEAR_ALL_LIBS _DBG)
+ # Clear wxWidgets common libraries.
+ foreach(LIB ${wxWidgets_COMMON_LIBRARIES} scintilla)
+ WX_CLEAR_LIB(WX_${LIB}${_DBG})
+ endforeach()
+
+ # Clear wxWidgets multilib base libraries.
+ WX_CLEAR_LIB(WX_base${_DBG})
+ foreach(LIB net odbc xml)
+ WX_CLEAR_LIB(WX_${LIB}${_DBG})
+ endforeach()
+
+ # Clear wxWidgets monolithic library.
+ WX_CLEAR_LIB(WX_mono${_DBG})
+
+ # Clear wxWidgets multilib libraries.
+ foreach(LIB core adv aui html media xrc dbgrid gl qa richtext
+ stc ribbon propgrid)
+ WX_CLEAR_LIB(WX_${LIB}${_DBG})
+ endforeach()
+ endmacro()
+ # Clear all wxWidgets debug libraries.
+ macro(WX_CLEAR_ALL_DBG_LIBS)
+ WX_CLEAR_ALL_LIBS("d")
+ endmacro()
+ # Clear all wxWidgets release libraries.
+ macro(WX_CLEAR_ALL_REL_LIBS)
+ WX_CLEAR_ALL_LIBS("")
+ endmacro()
+
+ #
+ # Set the wxWidgets_LIBRARIES variable.
+ # Also, Sets output variable wxWidgets_FOUND to FALSE if it fails.
+ #
+ macro(WX_SET_LIBRARIES _LIBS _DBG)
+ DBG_MSG_V("Looking for ${${_LIBS}}")
+ if(WX_USE_REL_AND_DBG)
+ foreach(LIB ${${_LIBS}})
+ DBG_MSG_V("Searching for ${LIB} and ${LIB}d")
+ DBG_MSG_V("WX_${LIB} : ${WX_${LIB}}")
+ DBG_MSG_V("WX_${LIB}d : ${WX_${LIB}d}")
+ if(WX_${LIB} AND WX_${LIB}d)
+ DBG_MSG_V("Found ${LIB} and ${LIB}d")
+ list(APPEND wxWidgets_LIBRARIES
+ debug ${WX_${LIB}d} optimized ${WX_${LIB}}
+ )
+ else()
+ DBG_MSG_V("- not found due to missing WX_${LIB}=${WX_${LIB}} or WX_${LIB}d=${WX_${LIB}d}")
+ set(wxWidgets_FOUND FALSE)
+ endif()
+ endforeach()
+ else()
+ foreach(LIB ${${_LIBS}})
+ DBG_MSG_V("Searching for ${LIB}${_DBG}")
+ DBG_MSG_V("WX_${LIB}${_DBG} : ${WX_${LIB}${_DBG}}")
+ if(WX_${LIB}${_DBG})
+ DBG_MSG_V("Found ${LIB}${_DBG}")
+ list(APPEND wxWidgets_LIBRARIES ${WX_${LIB}${_DBG}})
+ else()
+ DBG_MSG_V(
+ "- not found due to missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
+ set(wxWidgets_FOUND FALSE)
+ endif()
+ endforeach()
+ endif()
+
+ DBG_MSG_V("OpenGL")
+ list(FIND ${_LIBS} gl WX_USE_GL)
+ if(NOT WX_USE_GL EQUAL -1)
+ DBG_MSG_V("- is required.")
+ list(APPEND wxWidgets_LIBRARIES opengl32 glu32)
+ endif()
+
+ list(APPEND wxWidgets_LIBRARIES winmm comctl32 rpcrt4 wsock32)
+ endmacro()
+
+ #-------------------------------------------------------------------
+ # WIN32: Start actual work.
+ #-------------------------------------------------------------------
+
+ # Look for an installation tree.
+ find_path(wxWidgets_ROOT_DIR
+ NAMES include/wx/wx.h
+ PATHS
+ ENV wxWidgets_ROOT_DIR
+ ENV WXWIN
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\wxWidgets_is1;Inno Setup: App Path]" # WX 2.6.x
+ C:/
+ D:/
+ ENV ProgramFiles
+ PATH_SUFFIXES
+ wxWidgets-3.0.0
+ wxWidgets-2.9.5
+ wxWidgets-2.9.4
+ wxWidgets-2.9.3
+ wxWidgets-2.9.2
+ wxWidgets-2.9.1
+ wxWidgets-2.9.0
+ wxWidgets-2.8.9
+ wxWidgets-2.8.8
+ wxWidgets-2.8.7
+ wxWidgets-2.8.6
+ wxWidgets-2.8.5
+ wxWidgets-2.8.4
+ wxWidgets-2.8.3
+ wxWidgets-2.8.2
+ wxWidgets-2.8.1
+ wxWidgets-2.8.0
+ wxWidgets-2.7.4
+ wxWidgets-2.7.3
+ wxWidgets-2.7.2
+ wxWidgets-2.7.1
+ wxWidgets-2.7.0
+ wxWidgets-2.7.0-1
+ wxWidgets-2.6.4
+ wxWidgets-2.6.3
+ wxWidgets-2.6.2
+ wxWidgets-2.6.1
+ wxWidgets-2.5.4
+ wxWidgets-2.5.3
+ wxWidgets-2.5.2
+ wxWidgets-2.5.1
+ wxWidgets
+ DOC "wxWidgets base/installation directory"
+ )
+
+ # If wxWidgets_ROOT_DIR changed, clear lib dir.
+ if(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
+ set(WX_ROOT_DIR ${wxWidgets_ROOT_DIR}
+ CACHE INTERNAL "wxWidgets_ROOT_DIR")
+ set(wxWidgets_LIB_DIR "wxWidgets_LIB_DIR-NOTFOUND"
+ CACHE PATH "Cleared." FORCE)
+ endif()
+
+ if(WX_ROOT_DIR)
+ # Select one default tree inside the already determined wx tree.
+ # Prefer static/shared order usually consistent with build
+ # settings.
+ if(MINGW)
+ set(WX_LIB_DIR_PREFIX gcc)
+ elseif(CMAKE_CL_64)
+ set(WX_LIB_DIR_PREFIX vc_x64)
+ else()
+ set(WX_LIB_DIR_PREFIX vc)
+ endif()
+ if(BUILD_SHARED_LIBS)
+ find_path(wxWidgets_LIB_DIR
+ NAMES
+ msw/wx/setup.h
+ mswd/wx/setup.h
+ mswu/wx/setup.h
+ mswud/wx/setup.h
+ mswuniv/wx/setup.h
+ mswunivd/wx/setup.h
+ mswunivu/wx/setup.h
+ mswunivud/wx/setup.h
+ PATHS
+ ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll # prefer shared
+ ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib
+ DOC "Path to wxWidgets libraries"
+ NO_DEFAULT_PATH
+ )
+ else()
+ find_path(wxWidgets_LIB_DIR
+ NAMES
+ msw/wx/setup.h
+ mswd/wx/setup.h
+ mswu/wx/setup.h
+ mswud/wx/setup.h
+ mswuniv/wx/setup.h
+ mswunivd/wx/setup.h
+ mswunivu/wx/setup.h
+ mswunivud/wx/setup.h
+ PATHS
+ ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib # prefer static
+ ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll
+ DOC "Path to wxWidgets libraries"
+ NO_DEFAULT_PATH
+ )
+ endif()
+
+ # If wxWidgets_LIB_DIR changed, clear all libraries.
+ if(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
+ set(WX_LIB_DIR ${wxWidgets_LIB_DIR} CACHE INTERNAL "wxWidgets_LIB_DIR")
+ WX_CLEAR_ALL_DBG_LIBS()
+ WX_CLEAR_ALL_REL_LIBS()
+ endif()
+
+ if(WX_LIB_DIR)
+ # If building shared libs, define WXUSINGDLL to use dllimport.
+ if(WX_LIB_DIR MATCHES "[dD][lL][lL]")
+ set(wxWidgets_DEFINITIONS WXUSINGDLL)
+ DBG_MSG_V("detected SHARED/DLL tree WX_LIB_DIR=${WX_LIB_DIR}")
+ endif()
+
+ # Search for available configuration types.
+ foreach(CFG mswunivud mswunivd mswud mswd mswunivu mswuniv mswu msw)
+ set(WX_${CFG}_FOUND FALSE)
+ if(EXISTS ${WX_LIB_DIR}/${CFG})
+ list(APPEND WX_CONFIGURATION_LIST ${CFG})
+ set(WX_${CFG}_FOUND TRUE)
+ set(WX_CONFIGURATION ${CFG})
+ endif()
+ endforeach()
+ DBG_MSG_V("WX_CONFIGURATION_LIST=${WX_CONFIGURATION_LIST}")
+
+ if(WX_CONFIGURATION)
+ set(wxWidgets_FOUND TRUE)
+
+ # If the selected configuration wasn't found force the default
+ # one. Otherwise, use it but still force a refresh for
+ # updating the doc string with the current list of available
+ # configurations.
+ if(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
+ set(wxWidgets_CONFIGURATION ${WX_CONFIGURATION} CACHE STRING
+ "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
+ else()
+ set(wxWidgets_CONFIGURATION ${wxWidgets_CONFIGURATION} CACHE STRING
+ "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
+ endif()
+
+ # If release config selected, and both release/debug exist.
+ if(WX_${wxWidgets_CONFIGURATION}d_FOUND)
+ option(wxWidgets_USE_REL_AND_DBG
+ "Use release and debug configurations?" TRUE)
+ set(WX_USE_REL_AND_DBG ${wxWidgets_USE_REL_AND_DBG})
+ else()
+ # If the option exists (already in cache), force it false.
+ if(wxWidgets_USE_REL_AND_DBG)
+ set(wxWidgets_USE_REL_AND_DBG FALSE CACHE BOOL
+ "No ${wxWidgets_CONFIGURATION}d found." FORCE)
+ endif()
+ set(WX_USE_REL_AND_DBG FALSE)
+ endif()
+
+ # Get configuration parameters from the name.
+ WX_GET_NAME_COMPONENTS(${wxWidgets_CONFIGURATION} UNV UCD DBG)
+
+ # Set wxWidgets lib setup include directory.
+ if(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
+ set(wxWidgets_INCLUDE_DIRS
+ ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION})
+ else()
+ DBG_MSG("wxWidgets_FOUND FALSE because ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h does not exists.")
+ set(wxWidgets_FOUND FALSE)
+ endif()
+
+ # Set wxWidgets main include directory.
+ if(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
+ list(APPEND wxWidgets_INCLUDE_DIRS ${WX_ROOT_DIR}/include)
+ else()
+ DBG_MSG("wxWidgets_FOUND FALSE because WX_ROOT_DIR=${WX_ROOT_DIR} has no ${WX_ROOT_DIR}/include/wx/wx.h")
+ set(wxWidgets_FOUND FALSE)
+ endif()
+
+ # Find wxWidgets libraries.
+ WX_FIND_LIBS("${UNV}" "${UCD}" "${DBG}")
+ if(WX_USE_REL_AND_DBG)
+ WX_FIND_LIBS("${UNV}" "${UCD}" "d")
+ endif()
+
+ # Settings for requested libs (i.e., include dir, libraries, etc.).
+ WX_SET_LIBRARIES(wxWidgets_FIND_COMPONENTS "${DBG}")
+
+ # Add necessary definitions for unicode builds
+ if("${UCD}" STREQUAL "u")
+ list(APPEND wxWidgets_DEFINITIONS UNICODE _UNICODE)
+ endif()
+
+ # Add necessary definitions for debug builds
+ set(wxWidgets_DEFINITIONS_DEBUG _DEBUG __WXDEBUG__)
+
+ endif()
+ endif()
+ endif()
+
+#=====================================================================
+# UNIX_FIND_STYLE
+#=====================================================================
+else()
+ if(wxWidgets_FIND_STYLE STREQUAL "unix")
+ #-----------------------------------------------------------------
+ # UNIX: Helper MACROS
+ #-----------------------------------------------------------------
+ #
+ # Set the default values based on "wx-config --selected-config".
+ #
+ macro(WX_CONFIG_SELECT_GET_DEFAULT)
+ execute_process(
+ COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
+ ${wxWidgets_CONFIG_OPTIONS} --selected-config
+ OUTPUT_VARIABLE _wx_selected_config
+ RESULT_VARIABLE _wx_result
+ ERROR_QUIET
+ )
+ if(_wx_result EQUAL 0)
+ foreach(_opt_name debug static unicode universal)
+ string(TOUPPER ${_opt_name} _upper_opt_name)
+ if(_wx_selected_config MATCHES "${_opt_name}")
+ set(wxWidgets_DEFAULT_${_upper_opt_name} ON)
+ else()
+ set(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
+ endif()
+ endforeach()
+ else()
+ foreach(_upper_opt_name DEBUG STATIC UNICODE UNIVERSAL)
+ set(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
+ endforeach()
+ endif()
+ endmacro()
+
+ #
+ # Query a boolean configuration option to determine if the system
+ # has both builds available. If so, provide the selection option
+ # to the user.
+ #
+ macro(WX_CONFIG_SELECT_QUERY_BOOL _OPT_NAME _OPT_HELP)
+ execute_process(
+ COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
+ ${wxWidgets_CONFIG_OPTIONS} --${_OPT_NAME}=yes
+ RESULT_VARIABLE _wx_result_yes
+ OUTPUT_QUIET
+ ERROR_QUIET
+ )
+ execute_process(
+ COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
+ ${wxWidgets_CONFIG_OPTIONS} --${_OPT_NAME}=no
+ RESULT_VARIABLE _wx_result_no
+ OUTPUT_QUIET
+ ERROR_QUIET
+ )
+ string(TOUPPER ${_OPT_NAME} _UPPER_OPT_NAME)
+ if(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
+ option(wxWidgets_USE_${_UPPER_OPT_NAME}
+ ${_OPT_HELP} ${wxWidgets_DEFAULT_${_UPPER_OPT_NAME}})
+ else()
+ # If option exists (already in cache), force to available one.
+ if(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
+ if(_wx_result_yes EQUAL 0)
+ set(wxWidgets_USE_${_UPPER_OPT_NAME} ON CACHE BOOL ${_OPT_HELP} FORCE)
+ else()
+ set(wxWidgets_USE_${_UPPER_OPT_NAME} OFF CACHE BOOL ${_OPT_HELP} FORCE)
+ endif()
+ endif()
+ endif()
+ endmacro()
+
+ #
+ # Set wxWidgets_SELECT_OPTIONS to wx-config options for selecting
+ # among multiple builds.
+ #
+ macro(WX_CONFIG_SELECT_SET_OPTIONS)
+ set(wxWidgets_SELECT_OPTIONS ${wxWidgets_CONFIG_OPTIONS})
+ foreach(_opt_name debug static unicode universal)
+ string(TOUPPER ${_opt_name} _upper_opt_name)
+ if(DEFINED wxWidgets_USE_${_upper_opt_name})
+ if(wxWidgets_USE_${_upper_opt_name})
+ list(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=yes)
+ else()
+ list(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=no)
+ endif()
+ endif()
+ endforeach()
+ endmacro()
+
+ #-----------------------------------------------------------------
+ # UNIX: Start actual work.
+ #-----------------------------------------------------------------
+ # Support cross-compiling, only search in the target platform.
+ find_program(wxWidgets_CONFIG_EXECUTABLE wx-config
+ DOC "Location of wxWidgets library configuration provider binary (wx-config)."
+ ONLY_CMAKE_FIND_ROOT_PATH
+ )
+
+ if(wxWidgets_CONFIG_EXECUTABLE)
+ set(wxWidgets_FOUND TRUE)
+
+ # get defaults based on "wx-config --selected-config"
+ WX_CONFIG_SELECT_GET_DEFAULT()
+
+ # for each option: if both builds are available, provide option
+ WX_CONFIG_SELECT_QUERY_BOOL(debug "Use debug build?")
+ WX_CONFIG_SELECT_QUERY_BOOL(unicode "Use unicode build?")
+ WX_CONFIG_SELECT_QUERY_BOOL(universal "Use universal build?")
+ WX_CONFIG_SELECT_QUERY_BOOL(static "Link libraries statically?")
+
+ # process selection to set wxWidgets_SELECT_OPTIONS
+ WX_CONFIG_SELECT_SET_OPTIONS()
+ DBG_MSG("wxWidgets_SELECT_OPTIONS=${wxWidgets_SELECT_OPTIONS}")
+
+ # run the wx-config program to get cxxflags
+ execute_process(
+ COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
+ ${wxWidgets_SELECT_OPTIONS} --cxxflags
+ OUTPUT_VARIABLE wxWidgets_CXX_FLAGS
+ RESULT_VARIABLE RET
+ ERROR_QUIET
+ )
+ if(RET EQUAL 0)
+ string(STRIP "${wxWidgets_CXX_FLAGS}" wxWidgets_CXX_FLAGS)
+ separate_arguments(wxWidgets_CXX_FLAGS)
+
+ DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
+
+ # parse definitions from cxxflags;
+ # drop -D* from CXXFLAGS and the -D prefix
+ string(REGEX MATCHALL "-D[^;]+"
+ wxWidgets_DEFINITIONS "${wxWidgets_CXX_FLAGS}")
+ string(REGEX REPLACE "-D[^;]+(;|$)" ""
+ wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
+ string(REGEX REPLACE ";$" ""
+ wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
+ string(REPLACE "-D" ""
+ wxWidgets_DEFINITIONS "${wxWidgets_DEFINITIONS}")
+
+ # parse include dirs from cxxflags; drop -I prefix
+ string(REGEX MATCHALL "-I[^;]+"
+ wxWidgets_INCLUDE_DIRS "${wxWidgets_CXX_FLAGS}")
+ string(REGEX REPLACE "-I[^;]+;" ""
+ wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
+ string(REPLACE "-I" ""
+ wxWidgets_INCLUDE_DIRS "${wxWidgets_INCLUDE_DIRS}")
+
+ DBG_MSG_V("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
+ DBG_MSG_V("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
+ DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
+
+ else()
+ set(wxWidgets_FOUND FALSE)
+ DBG_MSG_V(
+ "${wxWidgets_CONFIG_EXECUTABLE} --cxxflags FAILED with RET=${RET}")
+ endif()
+
+ # run the wx-config program to get the libs
+ # - NOTE: wx-config doesn't verify that the libs requested exist
+ # it just produces the names. Maybe a TRY_COMPILE would
+ # be useful here...
+ string(REPLACE ";" ","
+ wxWidgets_FIND_COMPONENTS "${wxWidgets_FIND_COMPONENTS}")
+ execute_process(
+ COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
+ ${wxWidgets_SELECT_OPTIONS} --libs ${wxWidgets_FIND_COMPONENTS}
+ OUTPUT_VARIABLE wxWidgets_LIBRARIES
+ RESULT_VARIABLE RET
+ ERROR_QUIET
+ )
+ if(RET EQUAL 0)
+ string(STRIP "${wxWidgets_LIBRARIES}" wxWidgets_LIBRARIES)
+ separate_arguments(wxWidgets_LIBRARIES)
+ string(REPLACE "-framework;" "-framework "
+ wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
+ string(REPLACE "-arch;" "-arch "
+ wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
+ string(REPLACE "-isysroot;" "-isysroot "
+ wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
+
+ # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
+ string(REGEX MATCHALL "-L[^;]+"
+ wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARIES}")
+ string(REPLACE "-L" ""
+ wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARY_DIRS}")
+
+ DBG_MSG_V("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
+ DBG_MSG_V("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}")
+
+ else()
+ set(wxWidgets_FOUND FALSE)
+ DBG_MSG("${wxWidgets_CONFIG_EXECUTABLE} --libs ${wxWidgets_FIND_COMPONENTS} FAILED with RET=${RET}")
+ endif()
+ endif()
+
+#=====================================================================
+# Neither UNIX_FIND_STYLE, nor WIN32_FIND_STYLE
+#=====================================================================
+ else()
+ if(NOT wxWidgets_FIND_QUIETLY)
+ message(STATUS
+ "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): \n"
+ " Platform unknown/unsupported. It's neither WIN32 nor UNIX "
+ "find style."
+ )
+ endif()
+ endif()
+endif()
+
+# Debug output:
+DBG_MSG("wxWidgets_FOUND : ${wxWidgets_FOUND}")
+DBG_MSG("wxWidgets_INCLUDE_DIRS : ${wxWidgets_INCLUDE_DIRS}")
+DBG_MSG("wxWidgets_LIBRARY_DIRS : ${wxWidgets_LIBRARY_DIRS}")
+DBG_MSG("wxWidgets_LIBRARIES : ${wxWidgets_LIBRARIES}")
+DBG_MSG("wxWidgets_CXX_FLAGS : ${wxWidgets_CXX_FLAGS}")
+DBG_MSG("wxWidgets_USE_FILE : ${wxWidgets_USE_FILE}")
+
+#=====================================================================
+#=====================================================================
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(wxWidgets DEFAULT_MSG wxWidgets_FOUND)
+# Maintain consistency with all other variables.
+set(wxWidgets_FOUND ${WXWIDGETS_FOUND})
+
+#=====================================================================
+# Macros for use in wxWidgets apps.
+# - This module will not fail to find wxWidgets based on the code
+# below. Hence, it's required to check for validity of:
+#
+# wxWidgets_wxrc_EXECUTABLE
+#=====================================================================
+
+# Resource file compiler.
+find_program(wxWidgets_wxrc_EXECUTABLE wxrc
+ ${wxWidgets_ROOT_DIR}/utils/wxrc/vc_msw
+ DOC "Location of wxWidgets resource file compiler binary (wxrc)"
+ )
+
+#
+# WX_SPLIT_ARGUMENTS_ON(<keyword> <left> <right> <arg1> <arg2> ...)
+#
+# Sets <left> and <right> to contain arguments to the left and right,
+# respectively, of <keyword>.
+#
+# Example usage:
+# function(WXWIDGETS_ADD_RESOURCES outfiles)
+# WX_SPLIT_ARGUMENTS_ON(OPTIONS wxrc_files wxrc_options ${ARGN})
+# ...
+# endfunction()
+#
+# WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o file.C)
+#
+# NOTE: This is a generic piece of code that should be renamed to
+# SPLIT_ARGUMENTS_ON and put in a file serving the same purpose as
+# FindPackageStandardArgs.cmake. At the time of this writing
+# FindQt4.cmake has a QT4_EXTRACT_OPTIONS, which I basically copied
+# here a bit more generalized. So, there are already two find modules
+# using this approach.
+#
+function(WX_SPLIT_ARGUMENTS_ON _keyword _leftvar _rightvar)
+ # FIXME: Document that the input variables will be cleared.
+ #list(APPEND ${_leftvar} "")
+ #list(APPEND ${_rightvar} "")
+ set(${_leftvar} "")
+ set(${_rightvar} "")
+
+ set(_doing_right FALSE)
+ foreach(element ${ARGN})
+ if("${element}" STREQUAL "${_keyword}")
+ set(_doing_right TRUE)
+ else()
+ if(_doing_right)
+ list(APPEND ${_rightvar} "${element}")
+ else()
+ list(APPEND ${_leftvar} "${element}")
+ endif()
+ endif()
+ endforeach()
+
+ set(${_leftvar} ${${_leftvar}} PARENT_SCOPE)
+ set(${_rightvar} ${${_rightvar}} PARENT_SCOPE)
+endfunction()
+
+#
+# WX_GET_DEPENDENCIES_FROM_XML(
+# <depends>
+# <match_pattern>
+# <clean_pattern>
+# <xml_contents>
+# <depends_path>
+# )
+#
+# FIXME: Add documentation here...
+#
+function(WX_GET_DEPENDENCIES_FROM_XML
+ _depends
+ _match_patt
+ _clean_patt
+ _xml_contents
+ _depends_path
+ )
+
+ string(REGEX MATCHALL
+ ${_match_patt}
+ dep_file_list
+ "${${_xml_contents}}"
+ )
+ foreach(dep_file ${dep_file_list})
+ string(REGEX REPLACE ${_clean_patt} "" dep_file "${dep_file}")
+
+ # make the file have an absolute path
+ if(NOT IS_ABSOLUTE "${dep_file}")
+ set(dep_file "${${_depends_path}}/${dep_file}")
+ endif()
+
+ # append file to dependency list
+ list(APPEND ${_depends} "${dep_file}")
+ endforeach()
+
+ set(${_depends} ${${_depends}} PARENT_SCOPE)
+endfunction()
+
+#
+# WXWIDGETS_ADD_RESOURCES(<sources> <xrc_files>
+# OPTIONS <options> [NO_CPP_CODE])
+#
+# Adds a custom command for resource file compilation of the
+# <xrc_files> and appends the output files to <sources>.
+#
+# Example usages:
+# WXWIDGETS_ADD_RESOURCES(sources xrc/main_frame.xrc)
+# WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o altname.cxx)
+#
+function(WXWIDGETS_ADD_RESOURCES _outfiles)
+ WX_SPLIT_ARGUMENTS_ON(OPTIONS rc_file_list rc_options ${ARGN})
+
+ # Parse files for dependencies.
+ set(rc_file_list_abs "")
+ set(rc_depends "")
+ foreach(rc_file ${rc_file_list})
+ get_filename_component(depends_path ${rc_file} PATH)
+
+ get_filename_component(rc_file_abs ${rc_file} ABSOLUTE)
+ list(APPEND rc_file_list_abs "${rc_file_abs}")
+
+ # All files have absolute paths or paths relative to the location
+ # of the rc file.
+ file(READ "${rc_file_abs}" rc_file_contents)
+
+ # get bitmap/bitmap2 files
+ WX_GET_DEPENDENCIES_FROM_XML(
+ rc_depends
+ "<bitmap[^<]+"
+ "^<bitmap[^>]*>"
+ rc_file_contents
+ depends_path
+ )
+
+ # get url files
+ WX_GET_DEPENDENCIES_FROM_XML(
+ rc_depends
+ "<url[^<]+"
+ "^<url[^>]*>"
+ rc_file_contents
+ depends_path
+ )
+
+ # get wxIcon files
+ WX_GET_DEPENDENCIES_FROM_XML(
+ rc_depends
+ "<object[^>]*class=\"wxIcon\"[^<]+"
+ "^<object[^>]*>"
+ rc_file_contents
+ depends_path
+ )
+ endforeach()
+
+ #
+ # Parse options.
+ #
+ # If NO_CPP_CODE option specified, then produce .xrs file rather
+ # than a .cpp file (i.e., don't add the default --cpp-code option).
+ list(FIND rc_options NO_CPP_CODE index)
+ if(index EQUAL -1)
+ list(APPEND rc_options --cpp-code)
+ # wxrc's default output filename for cpp code.
+ set(outfile resource.cpp)
+ else()
+ list(REMOVE_AT rc_options ${index})
+ # wxrc's default output filename for xrs file.
+ set(outfile resource.xrs)
+ endif()
+
+ # Get output name for use in ADD_CUSTOM_COMMAND.
+ # - short option scanning
+ list(FIND rc_options -o index)
+ if(NOT index EQUAL -1)
+ math(EXPR filename_index "${index} + 1")
+ list(GET rc_options ${filename_index} outfile)
+ #list(REMOVE_AT rc_options ${index} ${filename_index})
+ endif()
+ # - long option scanning
+ string(REGEX MATCH "--output=[^;]*" outfile_opt "${rc_options}")
+ if(outfile_opt)
+ string(REPLACE "--output=" "" outfile "${outfile_opt}")
+ endif()
+ #string(REGEX REPLACE "--output=[^;]*;?" "" rc_options "${rc_options}")
+ #string(REGEX REPLACE ";$" "" rc_options "${rc_options}")
+
+ if(NOT IS_ABSOLUTE "${outfile}")
+ set(outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
+ endif()
+ add_custom_command(
+ OUTPUT "${outfile}"
+ COMMAND ${wxWidgets_wxrc_EXECUTABLE} ${rc_options} ${rc_file_list_abs}
+ DEPENDS ${rc_file_list_abs} ${rc_depends}
+ )
+
+ # Add generated header to output file list.
+ list(FIND rc_options -e short_index)
+ list(FIND rc_options --extra-cpp-code long_index)
+ if(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
+ get_filename_component(outfile_ext ${outfile} EXT)
+ string(REPLACE "${outfile_ext}" ".h" outfile_header "${outfile}")
+ list(APPEND ${_outfiles} "${outfile_header}")
+ set_source_files_properties(
+ "${outfile_header}" PROPERTIES GENERATED TRUE
+ )
+ endif()
+
+ # Add generated file to output file list.
+ list(APPEND ${_outfiles} "${outfile}")
+
+ set(${_outfiles} ${${_outfiles}} PARENT_SCOPE)
+endfunction()
diff --git a/Modules/FindwxWindows.cmake b/Modules/FindwxWindows.cmake
new file mode 100644
index 0000000000..6e441c3a46
--- /dev/null
+++ b/Modules/FindwxWindows.cmake
@@ -0,0 +1,737 @@
+#.rst:
+# FindwxWindows
+# -------------
+#
+# Find wxWindows (wxWidgets) installation
+#
+# This module finds if wxWindows/wxWidgets is installed and determines
+# where the include files and libraries are. It also determines what
+# the name of the library is. Please note this file is DEPRECATED and
+# replaced by FindwxWidgets.cmake. This code sets the following
+# variables:
+#
+# ::
+#
+# WXWINDOWS_FOUND = system has WxWindows
+# WXWINDOWS_LIBRARIES = path to the wxWindows libraries
+# on Unix/Linux with additional
+# linker flags from
+# "wx-config --libs"
+# CMAKE_WXWINDOWS_CXX_FLAGS = Compiler flags for wxWindows,
+# essentially "`wx-config --cxxflags`"
+# on Linux
+# WXWINDOWS_INCLUDE_DIR = where to find "wx/wx.h" and "wx/setup.h"
+# WXWINDOWS_LINK_DIRECTORIES = link directories, useful for rpath on
+# Unix
+# WXWINDOWS_DEFINITIONS = extra defines
+#
+#
+#
+# OPTIONS If you need OpenGL support please
+#
+# ::
+#
+# set(WXWINDOWS_USE_GL 1)
+#
+# in your CMakeLists.txt *before* you include this file.
+#
+# ::
+#
+# HAVE_ISYSTEM - true required to replace -I by -isystem on g++
+#
+#
+#
+# For convenience include Use_wxWindows.cmake in your project's
+# CMakeLists.txt using
+# include(${CMAKE_CURRENT_LIST_DIR}/Use_wxWindows.cmake).
+#
+# USAGE
+#
+# ::
+#
+# set(WXWINDOWS_USE_GL 1)
+# find_package(wxWindows)
+#
+#
+#
+# NOTES wxWidgets 2.6.x is supported for monolithic builds e.g.
+# compiled in wx/build/msw dir as:
+#
+# ::
+#
+# nmake -f makefile.vc BUILD=debug SHARED=0 USE_OPENGL=1 MONOLITHIC=1
+#
+#
+#
+# DEPRECATED
+#
+# ::
+#
+# CMAKE_WX_CAN_COMPILE
+# WXWINDOWS_LIBRARY
+# CMAKE_WX_CXX_FLAGS
+# WXWINDOWS_INCLUDE_PATH
+#
+#
+#
+# AUTHOR Jan Woetzel <http://www.mip.informatik.uni-kiel.de/~jw>
+# (07/2003-01/2006)
+
+#=============================================================================
+# Copyright 2000-2009 Kitware, Inc.
+# Copyright 2003-2006 Jan Woetzel
+#
+# 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.)
+
+# ------------------------------------------------------------------
+#
+# -removed OPTION for CMAKE_WXWINDOWS_USE_GL. Force the developer to SET it before calling this.
+# -major update for wx 2.6.2 and monolithic build option. (10/2005)
+#
+# STATUS
+# tested with:
+# cmake 1.6.7, Linux (Suse 7.3), wxWindows 2.4.0, gcc 2.95
+# cmake 1.6.7, Linux (Suse 8.2), wxWindows 2.4.0, gcc 3.3
+# cmake 1.6.7, Linux (Suse 8.2), wxWindows 2.4.1-patch1, gcc 3.3
+# cmake 1.6.7, MS Windows XP home, wxWindows 2.4.1, MS Visual Studio .net 7 2002 (static build)
+# cmake 2.0.5 on Windows XP and Suse Linux 9.2
+# cmake 2.0.6 on Windows XP and Suse Linux 9.2, wxWidgets 2.6.2 MONOLITHIC build
+# cmake 2.2.2 on Windows XP, MS Visual Studio .net 2003 7.1 wxWidgets 2.6.2 MONOLITHIC build
+#
+# TODO
+# -OPTION for unicode builds
+# -further testing of DLL linking under MS WIN32
+# -better support for non-monolithic builds
+#
+
+
+if(WIN32)
+ set(WIN32_STYLE_FIND 1)
+endif()
+if(MINGW)
+ set(WIN32_STYLE_FIND 0)
+ set(UNIX_STYLE_FIND 1)
+endif()
+if(UNIX)
+ set(UNIX_STYLE_FIND 1)
+endif()
+
+
+if(WIN32_STYLE_FIND)
+
+ ## ######################################################################
+ ##
+ ## Windows specific:
+ ##
+ ## candidates for root/base directory of wxwindows
+ ## should have subdirs include and lib containing include/wx/wx.h
+ ## fix the root dir to avoid mixing of headers/libs from different
+ ## versions/builds:
+
+ ## WX supports monolithic and multiple smaller libs (since 2.5.x), we prefer monolithic for now.
+ ## monolithic = WX is built as a single big library
+ ## e.g. compile on WIN32 as "nmake -f makefile.vc MONOLITHIC=1 BUILD=debug SHARED=0 USE_OPENGL=1" (JW)
+ option(WXWINDOWS_USE_MONOLITHIC "Use monolithic build of WX??" ON)
+ mark_as_advanced(WXWINDOWS_USE_MONOLITHIC)
+
+ ## GL libs used?
+ option(WXWINDOWS_USE_GL "Use Wx with GL support(glcanvas)?" ON)
+ mark_as_advanced(WXWINDOWS_USE_GL)
+
+
+ ## avoid mixing of headers and libs between multiple installed WX versions,
+ ## select just one tree here:
+ find_path(WXWINDOWS_ROOT_DIR include/wx/wx.h
+ HINTS
+ ENV WXWIN
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\wxWidgets_is1;Inno Setup: App Path]" ## WX 2.6.x
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\wxWindows_is1;Inno Setup: App Path]" ## WX 2.4.x
+ PATHS
+ C:/wxWidgets-2.6.2
+ D:/wxWidgets-2.6.2
+ C:/wxWidgets-2.6.1
+ D:/wxWidgets-2.6.1
+ C:/wxWindows-2.4.2
+ D:/wxWindows-2.4.2
+ )
+ # message("DBG found WXWINDOWS_ROOT_DIR: ${WXWINDOWS_ROOT_DIR}")
+
+
+ ## find libs for combination of static/shared with release/debug
+ ## be careful if you add something here,
+ ## avoid mixing of headers and libs of different wx versions,
+ ## there may be multiple WX versions installed.
+ set (WXWINDOWS_POSSIBLE_LIB_PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib"
+ )
+
+ ## monolithic?
+ if (WXWINDOWS_USE_MONOLITHIC)
+
+ find_library(WXWINDOWS_STATIC_LIBRARY
+ NAMES wx wxmsw wxmsw26
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static release build library" )
+
+ find_library(WXWINDOWS_STATIC_DEBUG_LIBRARY
+ NAMES wxd wxmswd wxmsw26d
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static debug build library" )
+
+ find_library(WXWINDOWS_SHARED_LIBRARY
+ NAMES wxmsw26 wxmsw262 wxmsw24 wxmsw242 wxmsw241 wxmsw240 wx23_2 wx22_9
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_dll"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows shared release build library" )
+
+ find_library(WXWINDOWS_SHARED_DEBUG_LIBRARY
+ NAMES wxmsw26d wxmsw262d wxmsw24d wxmsw241d wxmsw240d wx23_2d wx22_9d
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_dll"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows shared debug build library " )
+
+
+ ##
+ ## required for WXWINDOWS_USE_GL
+ ## gl lib is always build separate:
+ ##
+ find_library(WXWINDOWS_STATIC_LIBRARY_GL
+ NAMES wx_gl wxmsw_gl wxmsw26_gl
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static release build GL library" )
+
+ find_library(WXWINDOWS_STATIC_DEBUG_LIBRARY_GL
+ NAMES wxd_gl wxmswd_gl wxmsw26d_gl
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static debug build GL library" )
+
+
+ find_library(WXWINDOWS_STATIC_DEBUG_LIBRARY_PNG
+ NAMES wxpngd
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static debug png library" )
+
+ find_library(WXWINDOWS_STATIC_LIBRARY_PNG
+ NAMES wxpng
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static png library" )
+
+ find_library(WXWINDOWS_STATIC_DEBUG_LIBRARY_TIFF
+ NAMES wxtiffd
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static debug tiff library" )
+
+ find_library(WXWINDOWS_STATIC_LIBRARY_TIFF
+ NAMES wxtiff
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static tiff library" )
+
+ find_library(WXWINDOWS_STATIC_DEBUG_LIBRARY_JPEG
+ NAMES wxjpegd wxjpgd
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static debug jpeg library" )
+
+ find_library(WXWINDOWS_STATIC_LIBRARY_JPEG
+ NAMES wxjpeg wxjpg
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static jpeg library" )
+
+ find_library(WXWINDOWS_STATIC_DEBUG_LIBRARY_ZLIB
+ NAMES wxzlibd
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static debug zlib library" )
+
+ find_library(WXWINDOWS_STATIC_LIBRARY_ZLIB
+ NAMES wxzlib
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static zib library" )
+
+ find_library(WXWINDOWS_STATIC_DEBUG_LIBRARY_REGEX
+ NAMES wxregexd
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static debug regex library" )
+
+ find_library(WXWINDOWS_STATIC_LIBRARY_REGEX
+ NAMES wxregex
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_lib"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows static regex library" )
+
+
+
+ ## untested:
+ find_library(WXWINDOWS_SHARED_LIBRARY_GL
+ NAMES wx_gl wxmsw_gl wxmsw26_gl
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_dll"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows shared release build GL library" )
+
+ find_library(WXWINDOWS_SHARED_DEBUG_LIBRARY_GL
+ NAMES wxd_gl wxmswd_gl wxmsw26d_gl
+ PATHS
+ "${WXWINDOWS_ROOT_DIR}/lib/vc_dll"
+ ${WXWINDOWS_POSSIBLE_LIB_PATHS}
+ DOC "wxWindows shared debug build GL library" )
+
+
+ else ()
+ ## WX is built as multiple small pieces libraries instead of monolithic
+
+ ## DEPECATED (jw) replaced by more general WXWINDOWS_USE_MONOLITHIC ON/OFF
+ # option(WXWINDOWS_SEPARATE_LIBS_BUILD "Is wxWindows build with separate libs?" OFF)
+
+ ## HACK: This is very dirty.
+ ## because the libs of a particular version are explicitly listed
+ ## and NOT searched/verified.
+ ## TODO: Really search for each lib, then decide for
+ ## monolithic x debug x shared x GL (=16 combinations) for at least 18 libs
+ ## --> about 288 combinations
+ ## thus we need a different approach so solve this correctly ...
+
+ message(STATUS "Warning: You are trying to use wxWidgets without monolithic build (WXWINDOWS_SEPARATE_LIBS_BUILD). This is a HACK, libraries are not verified! (JW).")
+
+ set(WXWINDOWS_STATIC_LIBS ${WXWINDOWS_STATIC_LIBS}
+ wxbase26
+ wxbase26_net
+ wxbase26_odbc
+ wxbase26_xml
+ wxmsw26_adv
+ wxmsw26_core
+ wxmsw26_dbgrid
+ wxmsw26_gl
+ wxmsw26_html
+ wxmsw26_media
+ wxmsw26_qa
+ wxmsw26_xrc
+ wxexpat
+ wxjpeg
+ wxpng
+ wxregex
+ wxtiff
+ wxzlib
+ comctl32
+ rpcrt4
+ wsock32
+ )
+ ## HACK: feed in to optimized / debug libraries if both were FOUND.
+ set(WXWINDOWS_STATIC_DEBUG_LIBS ${WXWINDOWS_STATIC_DEBUG_LIBS}
+ wxbase26d
+ wxbase26d_net
+ wxbase26d_odbc
+ wxbase26d_xml
+ wxmsw26d_adv
+ wxmsw26d_core
+ wxmsw26d_dbgrid
+ wxmsw26d_gl
+ wxmsw26d_html
+ wxmsw26d_media
+ wxmsw26d_qa
+ wxmsw26d_xrc
+ wxexpatd
+ wxjpegd
+ wxpngd
+ wxregexd
+ wxtiffd
+ wxzlibd
+ comctl32
+ rpcrt4
+ wsock32
+ )
+ endif ()
+
+
+ ##
+ ## now we should have found all WX libs available on the system.
+ ## let the user decide which of the available onse to use.
+ ##
+
+ ## if there is at least one shared lib available
+ ## let user choose whether to use shared or static wxwindows libs
+ if(WXWINDOWS_SHARED_LIBRARY OR WXWINDOWS_SHARED_DEBUG_LIBRARY)
+ ## default value OFF because wxWindows MSVS default build is static
+ option(WXWINDOWS_USE_SHARED_LIBS
+ "Use shared versions (dll) of wxWindows libraries?" OFF)
+ mark_as_advanced(WXWINDOWS_USE_SHARED_LIBS)
+ endif()
+
+ ## add system libraries wxwindows always seems to depend on
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ comctl32
+ rpcrt4
+ wsock32
+ )
+
+ if (NOT WXWINDOWS_USE_SHARED_LIBS)
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ ## these ones dont seem required, in particular ctl3d32 is not neccesary (Jan Woetzel 07/2003)
+ # ctl3d32
+ debug ${WXWINDOWS_STATIC_DEBUG_LIBRARY_ZLIB} optimized ${WXWINDOWS_STATIC_LIBRARY_ZLIB}
+ debug ${WXWINDOWS_STATIC_DEBUG_LIBRARY_REGEX} optimized ${WXWINDOWS_STATIC_LIBRARY_REGEX}
+ debug ${WXWINDOWS_STATIC_DEBUG_LIBRARY_PNG} optimized ${WXWINDOWS_STATIC_LIBRARY_PNG}
+ debug ${WXWINDOWS_STATIC_DEBUG_LIBRARY_JPEG} optimized ${WXWINDOWS_STATIC_LIBRARY_JPEG}
+ debug ${WXWINDOWS_STATIC_DEBUG_LIBRARY_TIFF} optimized ${WXWINDOWS_STATIC_LIBRARY_TIFF}
+ )
+ endif ()
+
+ ## opengl/glu: TODO/FIXME: better use FindOpenGL.cmake here
+ ## assume release versions of glu an dopengl, here.
+ if (WXWINDOWS_USE_GL)
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ opengl32
+ glu32 )
+ endif ()
+
+ ##
+ ## select between use of shared or static wxWindows lib then set libs to use
+ ## for debug and optimized build. so the user can switch between debug and
+ ## release build e.g. within MS Visual Studio without running cmake with a
+ ## different build directory again.
+ ##
+ ## then add the build specific include dir for wx/setup.h
+ ##
+
+ if(WXWINDOWS_USE_SHARED_LIBS)
+ ##message("DBG wxWindows use shared lib selected.")
+ ## assume that both builds use the same setup(.h) for simplicity
+
+ ## shared: both wx (debug and release) found?
+ ## assume that both builds use the same setup(.h) for simplicity
+ if(WXWINDOWS_SHARED_DEBUG_LIBRARY AND WXWINDOWS_SHARED_LIBRARY)
+ ##message("DBG wx shared: debug and optimized found.")
+ find_path(WXWINDOWS_INCLUDE_DIR_SETUPH wx/setup.h
+ ${WXWINDOWS_ROOT_DIR}/lib/mswdlld
+ ${WXWINDOWS_ROOT_DIR}/lib/mswdll
+ ${WXWINDOWS_ROOT_DIR}/lib/vc_dll/mswd
+ ${WXWINDOWS_ROOT_DIR}/lib/vc_dll/msw )
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ debug ${WXWINDOWS_SHARED_DEBUG_LIBRARY}
+ optimized ${WXWINDOWS_SHARED_LIBRARY} )
+ if (WXWINDOWS_USE_GL)
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ debug ${WXWINDOWS_SHARED_DEBUG_LIBRARY_GL}
+ optimized ${WXWINDOWS_SHARED_LIBRARY_GL} )
+ endif ()
+ endif()
+
+ ## shared: only debug wx lib found?
+ if(WXWINDOWS_SHARED_DEBUG_LIBRARY)
+ if(NOT WXWINDOWS_SHARED_LIBRARY)
+ ##message("DBG wx shared: debug (but no optimized) found.")
+ find_path(WXWINDOWS_INCLUDE_DIR_SETUPH wx/setup.h
+ ${WXWINDOWS_ROOT_DIR}/lib/mswdlld
+ ${WXWINDOWS_ROOT_DIR}/lib/vc_dll/mswd )
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ ${WXWINDOWS_SHARED_DEBUG_LIBRARY} )
+ if (WXWINDOWS_USE_GL)
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ ${WXWINDOWS_SHARED_DEBUG_LIBRARY_GL} )
+ endif ()
+ endif()
+ endif()
+
+ ## shared: only release wx lib found?
+ if(NOT WXWINDOWS_SHARED_DEBUG_LIBRARY)
+ if(WXWINDOWS_SHARED_LIBRARY)
+ ##message("DBG wx shared: optimized (but no debug) found.")
+ find_path(WXWINDOWS_INCLUDE_DIR_SETUPH wx/setup.h
+ ${WXWINDOWS_ROOT_DIR}/lib/mswdll
+ ${WXWINDOWS_ROOT_DIR}/lib/vc_dll/msw )
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ ${WXWINDOWS_SHARED_DEBUG_LIBRARY} )
+ if (WXWINDOWS_USE_GL)
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ ${WXWINDOWS_SHARED_DEBUG_LIBRARY_GL} )
+ endif ()
+ endif()
+ endif()
+
+ ## shared: none found?
+ if(NOT WXWINDOWS_SHARED_DEBUG_LIBRARY)
+ if(NOT WXWINDOWS_SHARED_LIBRARY)
+ message(STATUS
+ "No shared wxWindows lib found, but WXWINDOWS_USE_SHARED_LIBS=${WXWINDOWS_USE_SHARED_LIBS}.")
+ endif()
+ endif()
+
+ #########################################################################################
+ else()
+
+ ##jw: DEPRECATED if(NOT WXWINDOWS_SEPARATE_LIBS_BUILD)
+
+ ## static: both wx (debug and release) found?
+ ## assume that both builds use the same setup(.h) for simplicity
+ if(WXWINDOWS_STATIC_DEBUG_LIBRARY AND WXWINDOWS_STATIC_LIBRARY)
+ ##message("DBG wx static: debug and optimized found.")
+ find_path(WXWINDOWS_INCLUDE_DIR_SETUPH wx/setup.h
+ ${WXWINDOWS_ROOT_DIR}/lib/mswd
+ ${WXWINDOWS_ROOT_DIR}/lib/msw
+ ${WXWINDOWS_ROOT_DIR}/lib/vc_lib/mswd
+ ${WXWINDOWS_ROOT_DIR}/lib/vc_lib/msw )
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ debug ${WXWINDOWS_STATIC_DEBUG_LIBRARY}
+ optimized ${WXWINDOWS_STATIC_LIBRARY} )
+ if (WXWINDOWS_USE_GL)
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ debug ${WXWINDOWS_STATIC_DEBUG_LIBRARY_GL}
+ optimized ${WXWINDOWS_STATIC_LIBRARY_GL} )
+ endif ()
+ endif()
+
+ ## static: only debug wx lib found?
+ if(WXWINDOWS_STATIC_DEBUG_LIBRARY)
+ if(NOT WXWINDOWS_STATIC_LIBRARY)
+ ##message("DBG wx static: debug (but no optimized) found.")
+ find_path(WXWINDOWS_INCLUDE_DIR_SETUPH wx/setup.h
+ ${WXWINDOWS_ROOT_DIR}/lib/mswd
+ ${WXWINDOWS_ROOT_DIR}/lib/vc_lib/mswd )
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ ${WXWINDOWS_STATIC_DEBUG_LIBRARY} )
+ if (WXWINDOWS_USE_GL)
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ ${WXWINDOWS_STATIC_DEBUG_LIBRARY_GL} )
+ endif ()
+ endif()
+ endif()
+
+ ## static: only release wx lib found?
+ if(NOT WXWINDOWS_STATIC_DEBUG_LIBRARY)
+ if(WXWINDOWS_STATIC_LIBRARY)
+ ##message("DBG wx static: optimized (but no debug) found.")
+ find_path(WXWINDOWS_INCLUDE_DIR_SETUPH wx/setup.h
+ ${WXWINDOWS_ROOT_DIR}/lib/msw
+ ${WXWINDOWS_ROOT_DIR}/lib/vc_lib/msw )
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ ${WXWINDOWS_STATIC_LIBRARY} )
+ if (WXWINDOWS_USE_GL)
+ set(WXWINDOWS_LIBRARIES ${WXWINDOWS_LIBRARIES}
+ ${WXWINDOWS_STATIC_LIBRARY_GL} )
+ endif ()
+ endif()
+ endif()
+
+ ## static: none found?
+ if(NOT WXWINDOWS_STATIC_DEBUG_LIBRARY AND NOT WXWINDOWS_SEPARATE_LIBS_BUILD)
+ if(NOT WXWINDOWS_STATIC_LIBRARY)
+ message(STATUS
+ "No static wxWindows lib found, but WXWINDOWS_USE_SHARED_LIBS=${WXWINDOWS_USE_SHARED_LIBS}.")
+ endif()
+ endif()
+ endif()
+
+
+ ## not neccessary in wxWindows 2.4.1 and 2.6.2
+ ## but it may fix a previous bug, see
+ ## http://lists.wxwindows.org/cgi-bin/ezmlm-cgi?8:mss:37574:200305:mpdioeneabobmgjenoap
+ option(WXWINDOWS_SET_DEFINITIONS "Set additional defines for wxWindows" OFF)
+ mark_as_advanced(WXWINDOWS_SET_DEFINITIONS)
+ if (WXWINDOWS_SET_DEFINITIONS)
+ set(WXWINDOWS_DEFINITIONS "-DWINVER=0x400")
+ else ()
+ # clear:
+ set(WXWINDOWS_DEFINITIONS "")
+ endif ()
+
+
+
+ ## Find the include directories for wxwindows
+ ## the first, build specific for wx/setup.h was determined before.
+ ## add inc dir for general for "wx/wx.h"
+ find_path(WXWINDOWS_INCLUDE_DIR wx/wx.h
+ "${WXWINDOWS_ROOT_DIR}/include" )
+ ## append the build specific include dir for wx/setup.h:
+ if (WXWINDOWS_INCLUDE_DIR_SETUPH)
+ set(WXWINDOWS_INCLUDE_DIR ${WXWINDOWS_INCLUDE_DIR} ${WXWINDOWS_INCLUDE_DIR_SETUPH} )
+ endif ()
+
+
+
+ mark_as_advanced(
+ WXWINDOWS_ROOT_DIR
+ WXWINDOWS_INCLUDE_DIR
+ WXWINDOWS_INCLUDE_DIR_SETUPH
+ WXWINDOWS_STATIC_LIBRARY
+ WXWINDOWS_STATIC_LIBRARY_GL
+ WXWINDOWS_STATIC_DEBUG_LIBRARY
+ WXWINDOWS_STATIC_DEBUG_LIBRARY_GL
+ WXWINDOWS_STATIC_LIBRARY_ZLIB
+ WXWINDOWS_STATIC_DEBUG_LIBRARY_ZLIB
+ WXWINDOWS_STATIC_LIBRARY_REGEX
+ WXWINDOWS_STATIC_DEBUG_LIBRARY_REGEX
+ WXWINDOWS_STATIC_LIBRARY_PNG
+ WXWINDOWS_STATIC_DEBUG_LIBRARY_PNG
+ WXWINDOWS_STATIC_LIBRARY_JPEG
+ WXWINDOWS_STATIC_DEBUG_LIBRARY_JPEG
+ WXWINDOWS_STATIC_DEBUG_LIBRARY_TIFF
+ WXWINDOWS_STATIC_LIBRARY_TIFF
+ WXWINDOWS_SHARED_LIBRARY
+ WXWINDOWS_SHARED_DEBUG_LIBRARY
+ WXWINDOWS_SHARED_LIBRARY_GL
+ WXWINDOWS_SHARED_DEBUG_LIBRARY_GL
+ )
+
+
+else()
+
+ if (UNIX_STYLE_FIND)
+ ## ######################################################################
+ ##
+ ## UNIX/Linux specific:
+ ##
+ ## use backquoted wx-config to query and set flags and libs:
+ ## 06/2003 Jan Woetzel
+ ##
+
+ option(WXWINDOWS_USE_SHARED_LIBS "Use shared versions (.so) of wxWindows libraries" ON)
+ mark_as_advanced(WXWINDOWS_USE_SHARED_LIBS)
+
+ # JW removed option and force the develper th SET it.
+ # option(WXWINDOWS_USE_GL "use wxWindows with GL support (use additional
+ # --gl-libs for wx-config)?" OFF)
+
+ # wx-config should be in your path anyhow, usually no need to set WXWIN or
+ # search in ../wx or ../../wx
+ find_program(CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE wx-config
+ HINTS
+ ENV WXWIN
+ $ENV{WXWIN}/bin
+ PATHS
+ ../wx/bin
+ ../../wx/bin )
+
+ # check whether wx-config was found:
+ if(CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE)
+
+ # use shared/static wx lib?
+ # remember: always link shared to use systems GL etc. libs (no static
+ # linking, just link *against* static .a libs)
+ if(WXWINDOWS_USE_SHARED_LIBS)
+ set(WX_CONFIG_ARGS_LIBS "--libs")
+ else()
+ set(WX_CONFIG_ARGS_LIBS "--static --libs")
+ endif()
+
+ # do we need additionial wx GL stuff like GLCanvas ?
+ if(WXWINDOWS_USE_GL)
+ set(WX_CONFIG_ARGS_LIBS "${WX_CONFIG_ARGS_LIBS} --gl-libs" )
+ endif()
+ ##message("DBG: WX_CONFIG_ARGS_LIBS=${WX_CONFIG_ARGS_LIBS}===")
+
+ # set CXXFLAGS to be fed into CMAKE_CXX_FLAGS by the user:
+ if (HAVE_ISYSTEM) # does the compiler support -isystem ?
+ if (NOT APPLE) # -isystem seem sto be unsuppored on Mac
+ if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX )
+ if (CMAKE_CXX_COMPILER MATCHES g\\+\\+)
+ set(CMAKE_WXWINDOWS_CXX_FLAGS "`${CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE} --cxxflags|sed -e s/-I/-isystem/g`")
+ else()
+ set(CMAKE_WXWINDOWS_CXX_FLAGS "`${CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE} --cxxflags`")
+ endif()
+ endif()
+ endif ()
+ endif ()
+ ##message("DBG: for compilation:
+ ##CMAKE_WXWINDOWS_CXX_FLAGS=${CMAKE_WXWINDOWS_CXX_FLAGS}===")
+
+ # keep the back-quoted string for clarity
+ set(WXWINDOWS_LIBRARIES "`${CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE} ${WX_CONFIG_ARGS_LIBS}`")
+ ##message("DBG2: for linking:
+ ##WXWINDOWS_LIBRARIES=${WXWINDOWS_LIBRARIES}===")
+
+ # evaluate wx-config output to separate linker flags and linkdirs for
+ # rpath:
+ exec_program(${CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE}
+ ARGS ${WX_CONFIG_ARGS_LIBS}
+ OUTPUT_VARIABLE WX_CONFIG_LIBS )
+
+ ## extract linkdirs (-L) for rpath
+ ## use regular expression to match wildcard equivalent "-L*<endchar>"
+ ## with <endchar> is a space or a semicolon
+ string(REGEX MATCHALL "[-][L]([^ ;])+" WXWINDOWS_LINK_DIRECTORIES_WITH_PREFIX "${WX_CONFIG_LIBS}" )
+ # message("DBG WXWINDOWS_LINK_DIRECTORIES_WITH_PREFIX=${WXWINDOWS_LINK_DIRECTORIES_WITH_PREFIX}")
+
+ ## remove prefix -L because we need the pure directory for LINK_DIRECTORIES
+ ## replace -L by ; because the separator seems to be lost otherwise (bug or
+ ## feature?)
+ if(WXWINDOWS_LINK_DIRECTORIES_WITH_PREFIX)
+ string(REGEX REPLACE "[-][L]" ";" WXWINDOWS_LINK_DIRECTORIES ${WXWINDOWS_LINK_DIRECTORIES_WITH_PREFIX} )
+ # message("DBG WXWINDOWS_LINK_DIRECTORIES=${WXWINDOWS_LINK_DIRECTORIES}")
+ endif()
+
+
+ ## replace space separated string by semicolon separated vector to make it
+ ## work with LINK_DIRECTORIES
+ separate_arguments(WXWINDOWS_LINK_DIRECTORIES)
+
+ mark_as_advanced(
+ CMAKE_WXWINDOWS_CXX_FLAGS
+ WXWINDOWS_INCLUDE_DIR
+ WXWINDOWS_LIBRARIES
+ CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE
+ )
+
+
+ ## we really need wx-config...
+ else()
+ message(STATUS "Cannot find wx-config anywhere on the system. Please put the file into your path or specify it in CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE.")
+ mark_as_advanced(CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE)
+ endif()
+
+
+
+ else()
+ message(STATUS "FindwxWindows.cmake: Platform unknown/unsupported by FindwxWindows.cmake. It's neither WIN32 nor UNIX")
+ endif()
+endif()
+
+
+if(WXWINDOWS_LIBRARIES)
+ if(WXWINDOWS_INCLUDE_DIR OR CMAKE_WXWINDOWS_CXX_FLAGS)
+ ## found all we need.
+ set(WXWINDOWS_FOUND 1)
+
+ ## set deprecated variables for backward compatibility:
+ set(CMAKE_WX_CAN_COMPILE ${WXWINDOWS_FOUND})
+ set(WXWINDOWS_LIBRARY ${WXWINDOWS_LIBRARIES})
+ set(WXWINDOWS_INCLUDE_PATH ${WXWINDOWS_INCLUDE_DIR})
+ set(WXWINDOWS_LINK_DIRECTORIES ${WXWINDOWS_LINK_DIRECTORIES})
+ set(CMAKE_WX_CXX_FLAGS ${CMAKE_WXWINDOWS_CXX_FLAGS})
+
+ endif()
+endif()
diff --git a/Modules/FortranCInterface.cmake b/Modules/FortranCInterface.cmake
new file mode 100644
index 0000000000..27f8a82151
--- /dev/null
+++ b/Modules/FortranCInterface.cmake
@@ -0,0 +1,341 @@
+#.rst:
+# FortranCInterface
+# -----------------
+#
+# Fortran/C Interface Detection
+#
+# This module automatically detects the API by which C and Fortran
+# languages interact. Variables indicate if the mangling is found:
+#
+# ::
+#
+# FortranCInterface_GLOBAL_FOUND = Global subroutines and functions
+# FortranCInterface_MODULE_FOUND = Module subroutines and functions
+# (declared by "MODULE PROCEDURE")
+#
+# A function is provided to generate a C header file containing macros
+# to mangle symbol names:
+#
+# ::
+#
+# FortranCInterface_HEADER(<file>
+# [MACRO_NAMESPACE <macro-ns>]
+# [SYMBOL_NAMESPACE <ns>]
+# [SYMBOLS [<module>:]<function> ...])
+#
+# It generates in <file> definitions of the following macros:
+#
+# ::
+#
+# #define FortranCInterface_GLOBAL (name,NAME) ...
+# #define FortranCInterface_GLOBAL_(name,NAME) ...
+# #define FortranCInterface_MODULE (mod,name, MOD,NAME) ...
+# #define FortranCInterface_MODULE_(mod,name, MOD,NAME) ...
+#
+# These macros mangle four categories of Fortran symbols, respectively:
+#
+# ::
+#
+# - Global symbols without '_': call mysub()
+# - Global symbols with '_' : call my_sub()
+# - Module symbols without '_': use mymod; call mysub()
+# - Module symbols with '_' : use mymod; call my_sub()
+#
+# If mangling for a category is not known, its macro is left undefined.
+# All macros require raw names in both lower case and upper case. The
+# MACRO_NAMESPACE option replaces the default "FortranCInterface_"
+# prefix with a given namespace "<macro-ns>".
+#
+# The SYMBOLS option lists symbols to mangle automatically with C
+# preprocessor definitions:
+#
+# ::
+#
+# <function> ==> #define <ns><function> ...
+# <module>:<function> ==> #define <ns><module>_<function> ...
+#
+# If the mangling for some symbol is not known then no preprocessor
+# definition is created, and a warning is displayed. The
+# SYMBOL_NAMESPACE option prefixes all preprocessor definitions
+# generated by the SYMBOLS option with a given namespace "<ns>".
+#
+# Example usage:
+#
+# ::
+#
+# include(FortranCInterface)
+# FortranCInterface_HEADER(FC.h MACRO_NAMESPACE "FC_")
+#
+# This creates a "FC.h" header that defines mangling macros FC_GLOBAL(),
+# FC_GLOBAL_(), FC_MODULE(), and FC_MODULE_().
+#
+# Example usage:
+#
+# ::
+#
+# include(FortranCInterface)
+# FortranCInterface_HEADER(FCMangle.h
+# MACRO_NAMESPACE "FC_"
+# SYMBOL_NAMESPACE "FC_"
+# SYMBOLS mysub mymod:my_sub)
+#
+# This creates a "FCMangle.h" header that defines the same FC_*()
+# mangling macros as the previous example plus preprocessor symbols
+# FC_mysub and FC_mymod_my_sub.
+#
+# Another function is provided to verify that the Fortran and C/C++
+# compilers work together:
+#
+# ::
+#
+# FortranCInterface_VERIFY([CXX] [QUIET])
+#
+# It tests whether a simple test executable using Fortran and C (and C++
+# when the CXX option is given) compiles and links successfully. The
+# result is stored in the cache entry FortranCInterface_VERIFIED_C (or
+# FortranCInterface_VERIFIED_CXX if CXX is given) as a boolean. If the
+# check fails and QUIET is not given the function terminates with a
+# FATAL_ERROR message describing the problem. The purpose of this check
+# is to stop a build early for incompatible compiler combinations. The
+# test is built in the Release configuration.
+#
+# FortranCInterface is aware of possible GLOBAL and MODULE manglings for
+# many Fortran compilers, but it also provides an interface to specify
+# new possible manglings. Set the variables
+#
+# ::
+#
+# FortranCInterface_GLOBAL_SYMBOLS
+# FortranCInterface_MODULE_SYMBOLS
+#
+# before including FortranCInterface to specify manglings of the symbols
+# "MySub", "My_Sub", "MyModule:MySub", and "My_Module:My_Sub". For
+# example, the code:
+#
+# ::
+#
+# set(FortranCInterface_GLOBAL_SYMBOLS mysub_ my_sub__ MYSUB_)
+# # ^^^^^ ^^^^^^ ^^^^^
+# set(FortranCInterface_MODULE_SYMBOLS
+# __mymodule_MOD_mysub __my_module_MOD_my_sub)
+# # ^^^^^^^^ ^^^^^ ^^^^^^^^^ ^^^^^^
+# include(FortranCInterface)
+#
+# tells FortranCInterface to try given GLOBAL and MODULE manglings.
+# (The carets point at raw symbol names for clarity in this example but
+# are not needed.)
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+#-----------------------------------------------------------------------------
+# Execute at most once in a project.
+if(FortranCInterface_SOURCE_DIR)
+ return()
+endif()
+
+# Use CMake 2.8.0 behavior for this module regardless of including context.
+cmake_policy(PUSH)
+cmake_policy(VERSION 2.8.0)
+
+#-----------------------------------------------------------------------------
+# Verify that C and Fortran are available.
+foreach(lang C Fortran)
+ if(NOT CMAKE_${lang}_COMPILER_LOADED)
+ message(FATAL_ERROR
+ "FortranCInterface requires the ${lang} language to be enabled.")
+ endif()
+endforeach()
+
+#-----------------------------------------------------------------------------
+set(FortranCInterface_SOURCE_DIR ${CMAKE_ROOT}/Modules/FortranCInterface)
+
+# MinGW's make tool does not always like () in the path
+if("${CMAKE_GENERATOR}" MATCHES "MinGW" AND
+ "${FortranCInterface_SOURCE_DIR}" MATCHES "[()]")
+ file(COPY ${FortranCInterface_SOURCE_DIR}/
+ DESTINATION ${CMAKE_BINARY_DIR}/CMakeFiles/FortranCInterfaceMinGW)
+ set(FortranCInterface_SOURCE_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/FortranCInterfaceMinGW)
+endif()
+
+# Create the interface detection project if it does not exist.
+if(NOT FortranCInterface_BINARY_DIR)
+ set(FortranCInterface_BINARY_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/FortranCInterface)
+ include(${FortranCInterface_SOURCE_DIR}/Detect.cmake)
+endif()
+
+# Load the detection results.
+include(${FortranCInterface_BINARY_DIR}/Output.cmake)
+
+#-----------------------------------------------------------------------------
+function(FortranCInterface_HEADER file)
+ # Parse arguments.
+ if(IS_ABSOLUTE "${file}")
+ set(FILE "${file}")
+ else()
+ set(FILE "${CMAKE_CURRENT_BINARY_DIR}/${file}")
+ endif()
+ set(MACRO_NAMESPACE "FortranCInterface_")
+ set(SYMBOL_NAMESPACE)
+ set(SYMBOLS)
+ set(doing)
+ foreach(arg ${ARGN})
+ if("x${arg}" MATCHES "^x(SYMBOLS|SYMBOL_NAMESPACE|MACRO_NAMESPACE)$")
+ set(doing "${arg}")
+ elseif("x${doing}" MATCHES "^x(SYMBOLS)$")
+ list(APPEND "${doing}" "${arg}")
+ elseif("x${doing}" MATCHES "^x(SYMBOL_NAMESPACE|MACRO_NAMESPACE)$")
+ set("${doing}" "${arg}")
+ set(doing)
+ else()
+ message(AUTHOR_WARNING "Unknown argument: \"${arg}\"")
+ endif()
+ endforeach()
+
+ # Generate macro definitions.
+ set(HEADER_CONTENT)
+ set(_desc_GLOBAL "/* Mangling for Fortran global symbols without underscores. */")
+ set(_desc_GLOBAL_ "/* Mangling for Fortran global symbols with underscores. */")
+ set(_desc_MODULE "/* Mangling for Fortran module symbols without underscores. */")
+ set(_desc_MODULE_ "/* Mangling for Fortran module symbols with underscores. */")
+ foreach(macro GLOBAL GLOBAL_ MODULE MODULE_)
+ if(FortranCInterface_${macro}_MACRO)
+ set(HEADER_CONTENT "${HEADER_CONTENT}
+${_desc_${macro}}
+#define ${MACRO_NAMESPACE}${macro}${FortranCInterface_${macro}_MACRO}
+")
+ endif()
+ endforeach()
+
+ # Generate symbol mangling definitions.
+ if(SYMBOLS)
+ set(HEADER_CONTENT "${HEADER_CONTENT}
+/*--------------------------------------------------------------------------*/
+/* Mangle some symbols automatically. */
+")
+ endif()
+ foreach(f ${SYMBOLS})
+ if("${f}" MATCHES ":")
+ # Module symbol name. Parse "<module>:<function>" syntax.
+ string(REPLACE ":" ";" pieces "${f}")
+ list(GET pieces 0 module)
+ list(GET pieces 1 function)
+ string(TOUPPER "${module}" m_upper)
+ string(TOLOWER "${module}" m_lower)
+ string(TOUPPER "${function}" f_upper)
+ string(TOLOWER "${function}" f_lower)
+ if("${function}" MATCHES "_")
+ set(form "_")
+ else()
+ set(form "")
+ endif()
+ if(FortranCInterface_MODULE${form}_MACRO)
+ set(HEADER_CONTENT "${HEADER_CONTENT}#define ${SYMBOL_NAMESPACE}${module}_${function} ${MACRO_NAMESPACE}MODULE${form}(${m_lower},${f_lower}, ${m_upper},${f_upper})\n")
+ else()
+ message(AUTHOR_WARNING "No FortranCInterface mangling known for ${f}")
+ endif()
+ else()
+ # Global symbol name.
+ if("${f}" MATCHES "_")
+ set(form "_")
+ else()
+ set(form "")
+ endif()
+ string(TOUPPER "${f}" f_upper)
+ string(TOLOWER "${f}" f_lower)
+ if(FortranCInterface_GLOBAL${form}_MACRO)
+ set(HEADER_CONTENT "${HEADER_CONTENT}#define ${SYMBOL_NAMESPACE}${f} ${MACRO_NAMESPACE}GLOBAL${form}(${f_lower}, ${f_upper})\n")
+ else()
+ message(AUTHOR_WARNING "No FortranCInterface mangling known for ${f}")
+ endif()
+ endif()
+ endforeach()
+
+ # Store the content.
+ configure_file(${FortranCInterface_SOURCE_DIR}/Macro.h.in ${FILE} @ONLY)
+endfunction()
+
+function(FortranCInterface_VERIFY)
+ # Check arguments.
+
+ set(lang C)
+ set(quiet 0)
+ set(verify_cxx 0)
+ foreach(arg ${ARGN})
+ if("${arg}" STREQUAL "QUIET")
+ set(quiet 1)
+ elseif("${arg}" STREQUAL "CXX")
+ set(lang CXX)
+ set(verify_cxx 1)
+ else()
+ message(FATAL_ERROR
+ "FortranCInterface_VERIFY - called with unknown argument:\n ${arg}")
+ endif()
+ endforeach()
+
+ if(NOT CMAKE_${lang}_COMPILER_LOADED)
+ message(FATAL_ERROR
+ "FortranCInterface_VERIFY(${lang}) requires ${lang} to be enabled.")
+ endif()
+
+ # Build the verification project if not yet built.
+ if(NOT DEFINED FortranCInterface_VERIFIED_${lang})
+ set(_desc "Verifying Fortran/${lang} Compiler Compatibility")
+ message(STATUS "${_desc}")
+
+ # Build a sample project which reports symbols.
+ set(CMAKE_TRY_COMPILE_CONFIGURATION Release)
+ try_compile(FortranCInterface_VERIFY_${lang}_COMPILED
+ ${FortranCInterface_BINARY_DIR}/Verify${lang}
+ ${FortranCInterface_SOURCE_DIR}/Verify
+ VerifyFortranC
+ CMAKE_FLAGS -DVERIFY_CXX=${verify_cxx}
+ -DCMAKE_VERBOSE_MAKEFILE=ON
+ "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
+ "-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}"
+ "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}"
+ "-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}"
+ "-DCMAKE_CXX_FLAGS_RELEASE:STRING=${CMAKE_CXX_FLAGS_RELEASE}"
+ "-DCMAKE_Fortran_FLAGS_RELEASE:STRING=${CMAKE_Fortran_FLAGS_RELEASE}"
+ OUTPUT_VARIABLE _output)
+ file(WRITE "${FortranCInterface_BINARY_DIR}/Verify${lang}/output.txt" "${_output}")
+
+ # Report results.
+ if(FortranCInterface_VERIFY_${lang}_COMPILED)
+ message(STATUS "${_desc} - Success")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "${_desc} passed with the following output:\n${_output}\n\n")
+ set(FortranCInterface_VERIFIED_${lang} 1 CACHE INTERNAL "Fortran/${lang} compatibility")
+ else()
+ message(STATUS "${_desc} - Failed")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "${_desc} failed with the following output:\n${_output}\n\n")
+ set(FortranCInterface_VERIFIED_${lang} 0 CACHE INTERNAL "Fortran/${lang} compatibility")
+ endif()
+ unset(FortranCInterface_VERIFY_${lang}_COMPILED CACHE)
+ endif()
+
+ # Error if compilers are incompatible.
+ if(NOT FortranCInterface_VERIFIED_${lang} AND NOT quiet)
+ file(READ "${FortranCInterface_BINARY_DIR}/Verify${lang}/output.txt" _output)
+ string(REPLACE "\n" "\n " _output "${_output}")
+ message(FATAL_ERROR
+ "The Fortran compiler:\n ${CMAKE_Fortran_COMPILER}\n"
+ "and the ${lang} compiler:\n ${CMAKE_${lang}_COMPILER}\n"
+ "failed to compile a simple test project using both languages. "
+ "The output was:\n ${_output}")
+ endif()
+endfunction()
+
+# Restore including context policies.
+cmake_policy(POP)
diff --git a/Modules/FortranCInterface/CMakeLists.txt b/Modules/FortranCInterface/CMakeLists.txt
new file mode 100644
index 0000000000..b6232ed74f
--- /dev/null
+++ b/Modules/FortranCInterface/CMakeLists.txt
@@ -0,0 +1,108 @@
+#=============================================================================
+# Copyright 2009 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.
+#=============================================================================
+
+cmake_minimum_required(VERSION ${CMAKE_VERSION})
+project(FortranCInterface C Fortran)
+include(${FortranCInterface_BINARY_DIR}/Input.cmake OPTIONAL)
+
+# Check if the C compiler supports '$' in identifiers.
+include(CheckCSourceCompiles)
+check_c_source_compiles("
+extern int dollar$(void);
+int main() { return 0; }
+" C_SUPPORTS_DOLLAR)
+
+# List manglings of global symbol names to try.
+set(global_symbols
+ my_sub # VisualAge
+ my_sub_ # GNU, Intel, HP, SunPro, MIPSpro
+ my_sub__ # GNU g77
+ MY_SUB # Intel on Windows
+ mysub # VisualAge
+ mysub_ # GNU, Intel, HP, SunPro, MIPSpro
+ MYSUB # Intel on Windows
+ ${FortranCInterface_GLOBAL_SYMBOLS}
+ )
+list(REMOVE_DUPLICATES global_symbols)
+
+# List manglings of module symbol names to try.
+set(module_symbols
+ __my_module_MOD_my_sub # GNU 4.3
+ __my_module_NMOD_my_sub # VisualAge
+ __my_module__my_sub # GNU 4.2
+ __mymodule_MOD_mysub # GNU 4.3
+ __mymodule_NMOD_mysub # VisualAge
+ __mymodule__mysub # GNU 4.2
+ my_module$my_sub # HP
+ my_module_mp_my_sub_ # Intel
+ MY_MODULE_mp_MY_SUB # Intel on Windows
+ my_module_my_sub_ # PGI
+ my_module_MP_my_sub # NAG
+ mymodule$mysub # HP
+ mymodule_mp_mysub_ # Intel
+ MYMODULE_mp_MYSUB # Intel on Windows
+ mymodule_mysub_ # PGI
+ mymodule_MP_mysub # NAG
+ ${FortranCInterface_MODULE_SYMBOLS}
+ )
+list(REMOVE_DUPLICATES module_symbols)
+
+# Note that some compiler manglings cannot be invoked from C:
+# MIPSpro uses "MY_SUB.in.MY_MODULE"
+# SunPro uses "my_module.my_sub_"
+# PathScale uses "MY_SUB.in.MY_MODULE"
+
+# Add module symbols only with Fortran90.
+if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
+ set(myfort_modules mymodule.f90 my_module.f90)
+ set(call_mod call_mod.f90)
+ set_property(SOURCE main.F PROPERTY COMPILE_DEFINITIONS CALL_MOD)
+else()
+ set(module_symbols)
+endif()
+
+# Generate C symbol sources.
+set(symbol_sources)
+if(NOT "${CMAKE_Fortran_COMPILER_ID}" MATCHES "^(PathScale|Cray)$")
+ # Provide mymodule_ and my_module_ init symbols because:
+ # - PGI Fortran uses module init symbols
+ # but not for:
+ # - PathScale Fortran uses module init symbols but module symbols
+ # use '.in.' so we cannot provide them anyway.
+ # - Cray Fortran >= 7.3.2 uses module init symbols but module symbols
+ # use 'mysub$mymodule_' so we cannot provide them anyway.
+ list(APPEND symbol_sources mymodule_.c my_module_.c)
+endif()
+foreach(symbol IN LISTS global_symbols module_symbols)
+ # Skip symbols with '$' if C cannot handle them.
+ if(C_SUPPORTS_DOLLAR OR NOT "${symbol}" MATCHES "\\$")
+ if("${symbol}" MATCHES "SUB")
+ set(upper "-UPPER")
+ else()
+ set(upper)
+ endif()
+ string(REPLACE "$" "S" name "${symbol}")
+ set(source ${CMAKE_CURRENT_BINARY_DIR}/symbols/${name}${upper}.c)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/symbol.c.in ${source} @ONLY)
+ list(APPEND symbol_sources ${source})
+ endif()
+endforeach()
+
+# Provide symbols through Fortran.
+add_library(myfort STATIC mysub.f my_sub.f ${myfort_modules})
+
+# Provide symbols through C but fall back to Fortran.
+add_library(symbols STATIC ${symbol_sources})
+target_link_libraries(symbols myfort)
+
+# Require symbols through Fortran.
+add_executable(FortranCInterface main.F call_sub.f ${call_mod})
+target_link_libraries(FortranCInterface symbols)
diff --git a/Modules/FortranCInterface/Detect.cmake b/Modules/FortranCInterface/Detect.cmake
new file mode 100644
index 0000000000..bee7dae351
--- /dev/null
+++ b/Modules/FortranCInterface/Detect.cmake
@@ -0,0 +1,182 @@
+#=============================================================================
+# Copyright 2009 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.
+#=============================================================================
+
+configure_file(${FortranCInterface_SOURCE_DIR}/Input.cmake.in
+ ${FortranCInterface_BINARY_DIR}/Input.cmake @ONLY)
+
+# Detect the Fortran/C interface on the first run or when the
+# configuration changes.
+if(${FortranCInterface_BINARY_DIR}/Input.cmake
+ IS_NEWER_THAN ${FortranCInterface_BINARY_DIR}/Output.cmake
+ OR ${FortranCInterface_SOURCE_DIR}/Output.cmake.in
+ IS_NEWER_THAN ${FortranCInterface_BINARY_DIR}/Output.cmake
+ OR ${FortranCInterface_SOURCE_DIR}/CMakeLists.txt
+ IS_NEWER_THAN ${FortranCInterface_BINARY_DIR}/Output.cmake
+ OR ${CMAKE_CURRENT_LIST_FILE}
+ IS_NEWER_THAN ${FortranCInterface_BINARY_DIR}/Output.cmake
+ )
+ message(STATUS "Detecting Fortran/C Interface")
+else()
+ return()
+endif()
+
+# Invalidate verification results.
+unset(FortranCInterface_VERIFIED_C CACHE)
+unset(FortranCInterface_VERIFIED_CXX CACHE)
+
+set(_result)
+
+# Build a sample project which reports symbols.
+try_compile(FortranCInterface_COMPILED
+ ${FortranCInterface_BINARY_DIR}
+ ${FortranCInterface_SOURCE_DIR}
+ FortranCInterface
+ CMAKE_FLAGS
+ "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
+ "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}"
+ OUTPUT_VARIABLE FortranCInterface_OUTPUT)
+set(FortranCInterface_COMPILED ${FortranCInterface_COMPILED})
+unset(FortranCInterface_COMPILED CACHE)
+
+# Locate the sample project executable.
+if(FortranCInterface_COMPILED)
+ find_program(FortranCInterface_EXE
+ NAMES FortranCInterface${CMAKE_EXECUTABLE_SUFFIX}
+ PATHS ${FortranCInterface_BINARY_DIR} ${FortranCInterface_BINARY_DIR}/Debug
+ NO_DEFAULT_PATH
+ )
+ set(FortranCInterface_EXE ${FortranCInterface_EXE})
+ unset(FortranCInterface_EXE CACHE)
+else()
+ set(_result "Failed to compile")
+ set(FortranCInterface_EXE)
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Fortran/C interface test project failed with the following output:\n"
+ "${FortranCInterface_OUTPUT}\n")
+endif()
+
+# Load symbols from INFO:symbol[] strings in the executable.
+set(FortranCInterface_SYMBOLS)
+if(FortranCInterface_EXE)
+ file(STRINGS "${FortranCInterface_EXE}" _info_strings
+ LIMIT_COUNT 8 REGEX "INFO:[A-Za-z0-9_]+\\[[^]]*\\]")
+ foreach(info ${_info_strings})
+ if("${info}" MATCHES "INFO:symbol\\[([^]]*)\\]")
+ list(APPEND FortranCInterface_SYMBOLS ${CMAKE_MATCH_1})
+ endif()
+ endforeach()
+elseif(NOT _result)
+ set(_result "Failed to load sample executable")
+endif()
+
+set(_case_mysub "LOWER")
+set(_case_my_sub "LOWER")
+set(_case_MYSUB "UPPER")
+set(_case_MY_SUB "UPPER")
+set(_global_regex "^(_*)(mysub|MYSUB)([_$]*)$")
+set(_global__regex "^(_*)(my_sub|MY_SUB)([_$]*)$")
+set(_module_regex "^(_*)(mymodule|MYMODULE)([A-Za-z_$]*)(mysub|MYSUB)([_$]*)$")
+set(_module__regex "^(_*)(my_module|MY_MODULE)([A-Za-z_$]*)(my_sub|MY_SUB)([_$]*)$")
+
+# Parse the symbol names.
+foreach(symbol ${FortranCInterface_SYMBOLS})
+ foreach(form "" "_")
+ # Look for global symbols.
+ string(REGEX REPLACE "${_global_${form}regex}"
+ "\\1;\\2;\\3" pieces "${symbol}")
+ list(LENGTH pieces len)
+ if(len EQUAL 3)
+ set(FortranCInterface_GLOBAL_${form}SYMBOL "${symbol}")
+ list(GET pieces 0 FortranCInterface_GLOBAL_${form}PREFIX)
+ list(GET pieces 1 name)
+ list(GET pieces 2 FortranCInterface_GLOBAL_${form}SUFFIX)
+ set(FortranCInterface_GLOBAL_${form}CASE "${_case_${name}}")
+ endif()
+
+ # Look for module symbols.
+ string(REGEX REPLACE "${_module_${form}regex}"
+ "\\1;\\2;\\3;\\4;\\5" pieces "${symbol}")
+ list(LENGTH pieces len)
+ if(len EQUAL 5)
+ set(FortranCInterface_MODULE_${form}SYMBOL "${symbol}")
+ list(GET pieces 0 FortranCInterface_MODULE_${form}PREFIX)
+ list(GET pieces 1 module)
+ list(GET pieces 2 FortranCInterface_MODULE_${form}MIDDLE)
+ list(GET pieces 3 name)
+ list(GET pieces 4 FortranCInterface_MODULE_${form}SUFFIX)
+ set(FortranCInterface_MODULE_${form}CASE "${_case_${name}}")
+ endif()
+ endforeach()
+endforeach()
+
+# Construct mangling macro definitions.
+set(_name_LOWER "name")
+set(_name_UPPER "NAME")
+foreach(form "" "_")
+ if(FortranCInterface_GLOBAL_${form}SYMBOL)
+ if(FortranCInterface_GLOBAL_${form}PREFIX)
+ set(_prefix "${FortranCInterface_GLOBAL_${form}PREFIX}##")
+ else()
+ set(_prefix "")
+ endif()
+ if(FortranCInterface_GLOBAL_${form}SUFFIX)
+ set(_suffix "##${FortranCInterface_GLOBAL_${form}SUFFIX}")
+ else()
+ set(_suffix "")
+ endif()
+ set(_name "${_name_${FortranCInterface_GLOBAL_${form}CASE}}")
+ set(FortranCInterface_GLOBAL${form}_MACRO
+ "(name,NAME) ${_prefix}${_name}${_suffix}")
+ endif()
+ if(FortranCInterface_MODULE_${form}SYMBOL)
+ if(FortranCInterface_MODULE_${form}PREFIX)
+ set(_prefix "${FortranCInterface_MODULE_${form}PREFIX}##")
+ else()
+ set(_prefix "")
+ endif()
+ if(FortranCInterface_MODULE_${form}SUFFIX)
+ set(_suffix "##${FortranCInterface_MODULE_${form}SUFFIX}")
+ else()
+ set(_suffix "")
+ endif()
+ set(_name "${_name_${FortranCInterface_MODULE_${form}CASE}}")
+ set(_middle "##${FortranCInterface_MODULE_${form}MIDDLE}##")
+ set(FortranCInterface_MODULE${form}_MACRO
+ "(mod_name,name, mod_NAME,NAME) ${_prefix}mod_${_name}${_middle}${_name}${_suffix}")
+ endif()
+endforeach()
+
+# Summarize what is available.
+foreach(scope GLOBAL MODULE)
+ if(FortranCInterface_${scope}_SYMBOL AND
+ FortranCInterface_${scope}__SYMBOL)
+ set(FortranCInterface_${scope}_FOUND 1)
+ else()
+ set(FortranCInterface_${scope}_FOUND 0)
+ endif()
+endforeach()
+
+# Record the detection results.
+configure_file(${FortranCInterface_SOURCE_DIR}/Output.cmake.in
+ ${FortranCInterface_BINARY_DIR}/Output.cmake @ONLY)
+file(APPEND ${FortranCInterface_BINARY_DIR}/Output.cmake "\n")
+
+# Report the results.
+if(FortranCInterface_GLOBAL_FOUND)
+ if(FortranCInterface_MODULE_FOUND)
+ set(_result "Found GLOBAL and MODULE mangling")
+ else()
+ set(_result "Found GLOBAL but not MODULE mangling")
+ endif()
+elseif(NOT _result)
+ set(_result "Failed to recognize symbols")
+endif()
+message(STATUS "Detecting Fortran/C Interface - ${_result}")
diff --git a/Modules/FortranCInterface/Input.cmake.in b/Modules/FortranCInterface/Input.cmake.in
new file mode 100644
index 0000000000..f261e3b45b
--- /dev/null
+++ b/Modules/FortranCInterface/Input.cmake.in
@@ -0,0 +1,3 @@
+set(CMAKE_Fortran_COMPILER_ID "@CMAKE_Fortran_COMPILER_ID@")
+set(FortranCInterface_GLOBAL_SYMBOLS "@FortranCInterface_GLOBAL_SYMBOLS@")
+set(FortranCInterface_MODULE_SYMBOLS "@FortranCInterface_MODULE_SYMBOLS@")
diff --git a/Modules/FortranCInterface/Macro.h.in b/Modules/FortranCInterface/Macro.h.in
new file mode 100644
index 0000000000..d015a62392
--- /dev/null
+++ b/Modules/FortranCInterface/Macro.h.in
@@ -0,0 +1,4 @@
+#ifndef @MACRO_NAMESPACE@HEADER_INCLUDED
+#define @MACRO_NAMESPACE@HEADER_INCLUDED
+@HEADER_CONTENT@
+#endif
diff --git a/Modules/FortranCInterface/Output.cmake.in b/Modules/FortranCInterface/Output.cmake.in
new file mode 100644
index 0000000000..bce410e760
--- /dev/null
+++ b/Modules/FortranCInterface/Output.cmake.in
@@ -0,0 +1,33 @@
+# Global symbol without underscore.
+set(FortranCInterface_GLOBAL_SYMBOL "@FortranCInterface_GLOBAL_SYMBOL@")
+set(FortranCInterface_GLOBAL_PREFIX "@FortranCInterface_GLOBAL_PREFIX@")
+set(FortranCInterface_GLOBAL_SUFFIX "@FortranCInterface_GLOBAL_SUFFIX@")
+set(FortranCInterface_GLOBAL_CASE "@FortranCInterface_GLOBAL_CASE@")
+set(FortranCInterface_GLOBAL_MACRO "@FortranCInterface_GLOBAL_MACRO@")
+
+# Global symbol with underscore.
+set(FortranCInterface_GLOBAL__SYMBOL "@FortranCInterface_GLOBAL__SYMBOL@")
+set(FortranCInterface_GLOBAL__PREFIX "@FortranCInterface_GLOBAL__PREFIX@")
+set(FortranCInterface_GLOBAL__SUFFIX "@FortranCInterface_GLOBAL__SUFFIX@")
+set(FortranCInterface_GLOBAL__CASE "@FortranCInterface_GLOBAL__CASE@")
+set(FortranCInterface_GLOBAL__MACRO "@FortranCInterface_GLOBAL__MACRO@")
+
+# Module symbol without underscore.
+set(FortranCInterface_MODULE_SYMBOL "@FortranCInterface_MODULE_SYMBOL@")
+set(FortranCInterface_MODULE_PREFIX "@FortranCInterface_MODULE_PREFIX@")
+set(FortranCInterface_MODULE_MIDDLE "@FortranCInterface_MODULE_MIDDLE@")
+set(FortranCInterface_MODULE_SUFFIX "@FortranCInterface_MODULE_SUFFIX@")
+set(FortranCInterface_MODULE_CASE "@FortranCInterface_MODULE_CASE@")
+set(FortranCInterface_MODULE_MACRO "@FortranCInterface_MODULE_MACRO@")
+
+# Module symbol with underscore.
+set(FortranCInterface_MODULE__SYMBOL "@FortranCInterface_MODULE__SYMBOL@")
+set(FortranCInterface_MODULE__PREFIX "@FortranCInterface_MODULE__PREFIX@")
+set(FortranCInterface_MODULE__MIDDLE "@FortranCInterface_MODULE__MIDDLE@")
+set(FortranCInterface_MODULE__SUFFIX "@FortranCInterface_MODULE__SUFFIX@")
+set(FortranCInterface_MODULE__CASE "@FortranCInterface_MODULE__CASE@")
+set(FortranCInterface_MODULE__MACRO "@FortranCInterface_MODULE__MACRO@")
+
+# Summarize what was found.
+set(FortranCInterface_GLOBAL_FOUND @FortranCInterface_GLOBAL_FOUND@)
+set(FortranCInterface_MODULE_FOUND @FortranCInterface_MODULE_FOUND@)
diff --git a/Modules/FortranCInterface/Verify/CMakeLists.txt b/Modules/FortranCInterface/Verify/CMakeLists.txt
new file mode 100644
index 0000000000..cde3c53123
--- /dev/null
+++ b/Modules/FortranCInterface/Verify/CMakeLists.txt
@@ -0,0 +1,34 @@
+#=============================================================================
+# Copyright 2009 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.
+#=============================================================================
+
+cmake_minimum_required(VERSION ${CMAKE_VERSION})
+project(VerifyFortranC C Fortran)
+
+option(VERIFY_CXX "Whether to verify C++ and Fortran" OFF)
+if(VERIFY_CXX)
+ enable_language(CXX)
+ set(VerifyCXX VerifyCXX.cxx)
+ add_definitions(-DVERIFY_CXX)
+endif()
+
+include(FortranCInterface)
+
+FortranCInterface_HEADER(VerifyFortran.h SYMBOLS VerifyFortran)
+include_directories(${VerifyFortranC_BINARY_DIR})
+
+add_library(VerifyFortran STATIC VerifyFortran.f)
+add_executable(VerifyFortranC main.c VerifyC.c ${VerifyCXX})
+target_link_libraries(VerifyFortranC VerifyFortran)
+
+if(NOT VERIFY_CXX)
+ # The entry point (main) is defined in C; link with the C compiler.
+ set_property(TARGET VerifyFortranC PROPERTY LINKER_LANGUAGE C)
+endif()
diff --git a/Modules/FortranCInterface/Verify/VerifyC.c b/Modules/FortranCInterface/Verify/VerifyC.c
new file mode 100644
index 0000000000..7f847ef01f
--- /dev/null
+++ b/Modules/FortranCInterface/Verify/VerifyC.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+void VerifyC(void)
+{
+ printf("VerifyC\n");
+}
diff --git a/Modules/FortranCInterface/Verify/VerifyCXX.cxx b/Modules/FortranCInterface/Verify/VerifyCXX.cxx
new file mode 100644
index 0000000000..689fac53d9
--- /dev/null
+++ b/Modules/FortranCInterface/Verify/VerifyCXX.cxx
@@ -0,0 +1,4 @@
+extern "C" void VerifyCXX(void)
+{
+ delete new int;
+}
diff --git a/Modules/FortranCInterface/Verify/VerifyFortran.f b/Modules/FortranCInterface/Verify/VerifyFortran.f
new file mode 100644
index 0000000000..a17e48d1bd
--- /dev/null
+++ b/Modules/FortranCInterface/Verify/VerifyFortran.f
@@ -0,0 +1,3 @@
+ subroutine VerifyFortran
+ print *, 'VerifyFortran'
+ end
diff --git a/Modules/FortranCInterface/Verify/main.c b/Modules/FortranCInterface/Verify/main.c
new file mode 100644
index 0000000000..582ef1d909
--- /dev/null
+++ b/Modules/FortranCInterface/Verify/main.c
@@ -0,0 +1,16 @@
+extern void VerifyC(void);
+#ifdef VERIFY_CXX
+extern void VerifyCXX(void);
+#endif
+#include "VerifyFortran.h"
+extern void VerifyFortran(void);
+
+int main(void)
+{
+ VerifyC();
+#ifdef VERIFY_CXX
+ VerifyCXX();
+#endif
+ VerifyFortran();
+ return 0;
+}
diff --git a/Modules/FortranCInterface/call_mod.f90 b/Modules/FortranCInterface/call_mod.f90
new file mode 100644
index 0000000000..9b6af640e3
--- /dev/null
+++ b/Modules/FortranCInterface/call_mod.f90
@@ -0,0 +1,6 @@
+subroutine call_mod
+ use mymodule
+ use my_module
+ call mysub()
+ call my_sub()
+end subroutine call_mod
diff --git a/Modules/FortranCInterface/call_sub.f b/Modules/FortranCInterface/call_sub.f
new file mode 100644
index 0000000000..ce3d50b14f
--- /dev/null
+++ b/Modules/FortranCInterface/call_sub.f
@@ -0,0 +1,4 @@
+ subroutine call_sub
+ call mysub()
+ call my_sub()
+ end
diff --git a/Modules/FortranCInterface/main.F b/Modules/FortranCInterface/main.F
new file mode 100644
index 0000000000..84991b0ee3
--- /dev/null
+++ b/Modules/FortranCInterface/main.F
@@ -0,0 +1,6 @@
+ program main
+ call call_sub()
+#ifdef CALL_MOD
+ call call_mod()
+#endif
+ end
diff --git a/Modules/FortranCInterface/my_module.f90 b/Modules/FortranCInterface/my_module.f90
new file mode 100644
index 0000000000..82713b43e0
--- /dev/null
+++ b/Modules/FortranCInterface/my_module.f90
@@ -0,0 +1,8 @@
+module my_module
+ interface my_interface
+ module procedure my_sub
+ end interface
+contains
+ subroutine my_sub
+ end subroutine my_sub
+end module my_module
diff --git a/Modules/FortranCInterface/my_module_.c b/Modules/FortranCInterface/my_module_.c
new file mode 100644
index 0000000000..6510ae9774
--- /dev/null
+++ b/Modules/FortranCInterface/my_module_.c
@@ -0,0 +1 @@
+void my_module_(void) {}
diff --git a/Modules/FortranCInterface/my_sub.f b/Modules/FortranCInterface/my_sub.f
new file mode 100644
index 0000000000..247ba06784
--- /dev/null
+++ b/Modules/FortranCInterface/my_sub.f
@@ -0,0 +1,2 @@
+ subroutine my_sub
+ end
diff --git a/Modules/FortranCInterface/mymodule.f90 b/Modules/FortranCInterface/mymodule.f90
new file mode 100644
index 0000000000..ef6281a3f3
--- /dev/null
+++ b/Modules/FortranCInterface/mymodule.f90
@@ -0,0 +1,8 @@
+module mymodule
+ interface myinterface
+ module procedure mysub
+ end interface
+contains
+ subroutine mysub
+ end subroutine mysub
+end module mymodule
diff --git a/Modules/FortranCInterface/mymodule_.c b/Modules/FortranCInterface/mymodule_.c
new file mode 100644
index 0000000000..52706058e4
--- /dev/null
+++ b/Modules/FortranCInterface/mymodule_.c
@@ -0,0 +1 @@
+void mymodule_(void) {}
diff --git a/Modules/FortranCInterface/mysub.f b/Modules/FortranCInterface/mysub.f
new file mode 100644
index 0000000000..1c27ff4525
--- /dev/null
+++ b/Modules/FortranCInterface/mysub.f
@@ -0,0 +1,2 @@
+ subroutine mysub
+ end
diff --git a/Modules/FortranCInterface/symbol.c.in b/Modules/FortranCInterface/symbol.c.in
new file mode 100644
index 0000000000..369fa45973
--- /dev/null
+++ b/Modules/FortranCInterface/symbol.c.in
@@ -0,0 +1,4 @@
+const char* @symbol@(void)
+{
+ return "INFO:symbol[@symbol@]";
+}
diff --git a/Modules/GNUInstallDirs.cmake b/Modules/GNUInstallDirs.cmake
new file mode 100644
index 0000000000..10956aac0e
--- /dev/null
+++ b/Modules/GNUInstallDirs.cmake
@@ -0,0 +1,271 @@
+#.rst:
+# GNUInstallDirs
+# --------------
+#
+# Define GNU standard installation directories
+#
+# Provides install directory variables as defined for GNU software:
+#
+# ::
+#
+# http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
+#
+# Inclusion of this module defines the following variables:
+#
+# ::
+#
+# CMAKE_INSTALL_<dir> - destination for files of a given type
+# CMAKE_INSTALL_FULL_<dir> - corresponding absolute path
+#
+# where <dir> is one of:
+#
+# ::
+#
+# BINDIR - user executables (bin)
+# SBINDIR - system admin executables (sbin)
+# LIBEXECDIR - program executables (libexec)
+# SYSCONFDIR - read-only single-machine data (etc)
+# SHAREDSTATEDIR - modifiable architecture-independent data (com)
+# LOCALSTATEDIR - modifiable single-machine data (var)
+# LIBDIR - object code libraries (lib or lib64 or lib/<multiarch-tuple> on Debian)
+# INCLUDEDIR - C header files (include)
+# OLDINCLUDEDIR - C header files for non-gcc (/usr/include)
+# DATAROOTDIR - read-only architecture-independent data root (share)
+# DATADIR - read-only architecture-independent data (DATAROOTDIR)
+# INFODIR - info documentation (DATAROOTDIR/info)
+# LOCALEDIR - locale-dependent data (DATAROOTDIR/locale)
+# MANDIR - man documentation (DATAROOTDIR/man)
+# DOCDIR - documentation root (DATAROOTDIR/doc/PROJECT_NAME)
+#
+# Each CMAKE_INSTALL_<dir> value may be passed to the DESTINATION
+# options of install() commands for the corresponding file type. If the
+# includer does not define a value the above-shown default will be used
+# and the value will appear in the cache for editing by the user. Each
+# CMAKE_INSTALL_FULL_<dir> value contains an absolute path constructed
+# from the corresponding destination by prepending (if necessary) the
+# value of CMAKE_INSTALL_PREFIX.
+
+#=============================================================================
+# Copyright 2011 Nikita Krupen'ko <krnekit@gmail.com>
+# Copyright 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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# Installation directories
+#
+if(NOT DEFINED CMAKE_INSTALL_BINDIR)
+ set(CMAKE_INSTALL_BINDIR "bin" CACHE PATH "user executables (bin)")
+endif()
+
+if(NOT DEFINED CMAKE_INSTALL_SBINDIR)
+ set(CMAKE_INSTALL_SBINDIR "sbin" CACHE PATH "system admin executables (sbin)")
+endif()
+
+if(NOT DEFINED CMAKE_INSTALL_LIBEXECDIR)
+ set(CMAKE_INSTALL_LIBEXECDIR "libexec" CACHE PATH "program executables (libexec)")
+endif()
+
+if(NOT DEFINED CMAKE_INSTALL_SYSCONFDIR)
+ set(CMAKE_INSTALL_SYSCONFDIR "etc" CACHE PATH "read-only single-machine data (etc)")
+endif()
+
+if(NOT DEFINED CMAKE_INSTALL_SHAREDSTATEDIR)
+ set(CMAKE_INSTALL_SHAREDSTATEDIR "com" CACHE PATH "modifiable architecture-independent data (com)")
+endif()
+
+if(NOT DEFINED CMAKE_INSTALL_LOCALSTATEDIR)
+ set(CMAKE_INSTALL_LOCALSTATEDIR "var" CACHE PATH "modifiable single-machine data (var)")
+endif()
+
+# We check if the variable was manually set and not cached, in order to
+# allow projects to set the values as normal variables before including
+# GNUInstallDirs to avoid having the entries cached or user-editable. It
+# replaces the "if(NOT DEFINED CMAKE_INSTALL_XXX)" checks in all the
+# other cases.
+# If CMAKE_INSTALL_LIBDIR is defined, if _libdir_set is false, then the
+# variable is a normal one, otherwise it is a cache one.
+get_property(_libdir_set CACHE CMAKE_INSTALL_LIBDIR PROPERTY TYPE SET)
+if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set
+ AND DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
+ AND NOT "${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}"))
+ # If CMAKE_INSTALL_LIBDIR is not defined, it is always executed.
+ # Otherwise:
+ # * if _libdir_set is false it is not executed (meaning that it is
+ # not a cache variable)
+ # * if _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX is not defined it is
+ # not executed
+ # * if _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX and
+ # CMAKE_INSTALL_PREFIX are the same string it is not executed.
+ # _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX is updated after the
+ # execution, of this part of code, therefore at the next inclusion
+ # of the file, CMAKE_INSTALL_LIBDIR is defined, and the 2 strings
+ # are equal, meaning that the if is not executed the code the
+ # second time.
+
+ set(_LIBDIR_DEFAULT "lib")
+ # Override this default 'lib' with 'lib64' iff:
+ # - we are on Linux system but NOT cross-compiling
+ # - we are NOT on debian
+ # - we are on a 64 bits system
+ # reason is: amd64 ABI: http://www.x86-64.org/documentation/abi.pdf
+ # For Debian with multiarch, use 'lib/${CMAKE_LIBRARY_ARCHITECTURE}' if
+ # CMAKE_LIBRARY_ARCHITECTURE is set (which contains e.g. "i386-linux-gnu"
+ # and CMAKE_INSTALL_PREFIX is "/usr"
+ # See http://wiki.debian.org/Multiarch
+ if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX)
+ set(__LAST_LIBDIR_DEFAULT "lib")
+ # __LAST_LIBDIR_DEFAULT is the default value that we compute from
+ # _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX, not a cache entry for
+ # the value that was last used as the default.
+ # This value is used to figure out whether the user changed the
+ # CMAKE_INSTALL_LIBDIR value manually, or if the value was the
+ # default one. When CMAKE_INSTALL_PREFIX changes, the value is
+ # updated to the new default, unless the user explicitly changed it.
+ endif()
+ if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$"
+ AND NOT CMAKE_CROSSCOMPILING)
+ if (EXISTS "/etc/debian_version") # is this a debian system ?
+ if(CMAKE_LIBRARY_ARCHITECTURE)
+ if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
+ set(_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
+ endif()
+ if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
+ AND "${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
+ set(__LAST_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
+ endif()
+ endif()
+ else() # not debian, rely on CMAKE_SIZEOF_VOID_P:
+ if(NOT DEFINED CMAKE_SIZEOF_VOID_P)
+ message(AUTHOR_WARNING
+ "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. "
+ "Please enable at least one language before including GNUInstallDirs.")
+ else()
+ if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
+ set(_LIBDIR_DEFAULT "lib64")
+ if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX)
+ set(__LAST_LIBDIR_DEFAULT "lib64")
+ endif()
+ endif()
+ endif()
+ endif()
+ endif()
+ if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
+ set(CMAKE_INSTALL_LIBDIR "${_LIBDIR_DEFAULT}" CACHE PATH "object code libraries (${_LIBDIR_DEFAULT})")
+ elseif(DEFINED __LAST_LIBDIR_DEFAULT
+ AND "${__LAST_LIBDIR_DEFAULT}" STREQUAL "${CMAKE_INSTALL_LIBDIR}")
+ set_property(CACHE CMAKE_INSTALL_LIBDIR PROPERTY VALUE "${_LIBDIR_DEFAULT}")
+ endif()
+endif()
+# Save for next run
+set(_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "CMAKE_INSTALL_PREFIX during last run")
+unset(_libdir_set)
+unset(__LAST_LIBDIR_DEFAULT)
+
+
+if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
+ set(CMAKE_INSTALL_INCLUDEDIR "include" CACHE PATH "C header files (include)")
+endif()
+
+if(NOT DEFINED CMAKE_INSTALL_OLDINCLUDEDIR)
+ set(CMAKE_INSTALL_OLDINCLUDEDIR "/usr/include" CACHE PATH "C header files for non-gcc (/usr/include)")
+endif()
+
+if(NOT DEFINED CMAKE_INSTALL_DATAROOTDIR)
+ set(CMAKE_INSTALL_DATAROOTDIR "share" CACHE PATH "read-only architecture-independent data root (share)")
+endif()
+
+#-----------------------------------------------------------------------------
+# Values whose defaults are relative to DATAROOTDIR. Store empty values in
+# the cache and store the defaults in local variables if the cache values are
+# not set explicitly. This auto-updates the defaults as DATAROOTDIR changes.
+
+if(NOT CMAKE_INSTALL_DATADIR)
+ set(CMAKE_INSTALL_DATADIR "" CACHE PATH "read-only architecture-independent data (DATAROOTDIR)")
+ set(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_DATAROOTDIR}")
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+ if(NOT CMAKE_INSTALL_INFODIR)
+ set(CMAKE_INSTALL_INFODIR "" CACHE PATH "info documentation (info)")
+ set(CMAKE_INSTALL_INFODIR "info")
+ endif()
+
+ if(NOT CMAKE_INSTALL_MANDIR)
+ set(CMAKE_INSTALL_MANDIR "" CACHE PATH "man documentation (man)")
+ set(CMAKE_INSTALL_MANDIR "man")
+ endif()
+else()
+ if(NOT CMAKE_INSTALL_INFODIR)
+ set(CMAKE_INSTALL_INFODIR "" CACHE PATH "info documentation (DATAROOTDIR/info)")
+ set(CMAKE_INSTALL_INFODIR "${CMAKE_INSTALL_DATAROOTDIR}/info")
+ endif()
+
+ if(NOT CMAKE_INSTALL_MANDIR)
+ set(CMAKE_INSTALL_MANDIR "" CACHE PATH "man documentation (DATAROOTDIR/man)")
+ set(CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_DATAROOTDIR}/man")
+ endif()
+endif()
+
+if(NOT CMAKE_INSTALL_LOCALEDIR)
+ set(CMAKE_INSTALL_LOCALEDIR "" CACHE PATH "locale-dependent data (DATAROOTDIR/locale)")
+ set(CMAKE_INSTALL_LOCALEDIR "${CMAKE_INSTALL_DATAROOTDIR}/locale")
+endif()
+
+if(NOT CMAKE_INSTALL_DOCDIR)
+ set(CMAKE_INSTALL_DOCDIR "" CACHE PATH "documentation root (DATAROOTDIR/doc/PROJECT_NAME)")
+ set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}")
+endif()
+
+#-----------------------------------------------------------------------------
+
+mark_as_advanced(
+ CMAKE_INSTALL_BINDIR
+ CMAKE_INSTALL_SBINDIR
+ CMAKE_INSTALL_LIBEXECDIR
+ CMAKE_INSTALL_SYSCONFDIR
+ CMAKE_INSTALL_SHAREDSTATEDIR
+ CMAKE_INSTALL_LOCALSTATEDIR
+ CMAKE_INSTALL_LIBDIR
+ CMAKE_INSTALL_INCLUDEDIR
+ CMAKE_INSTALL_OLDINCLUDEDIR
+ CMAKE_INSTALL_DATAROOTDIR
+ CMAKE_INSTALL_DATADIR
+ CMAKE_INSTALL_INFODIR
+ CMAKE_INSTALL_LOCALEDIR
+ CMAKE_INSTALL_MANDIR
+ CMAKE_INSTALL_DOCDIR
+ )
+
+# Result directories
+#
+foreach(dir
+ BINDIR
+ SBINDIR
+ LIBEXECDIR
+ SYSCONFDIR
+ SHAREDSTATEDIR
+ LOCALSTATEDIR
+ LIBDIR
+ INCLUDEDIR
+ OLDINCLUDEDIR
+ DATAROOTDIR
+ DATADIR
+ INFODIR
+ LOCALEDIR
+ MANDIR
+ DOCDIR
+ )
+ if(NOT IS_ABSOLUTE ${CMAKE_INSTALL_${dir}})
+ set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${dir}}")
+ else()
+ set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_${dir}}")
+ endif()
+endforeach()
diff --git a/Modules/GenerateExportHeader.cmake b/Modules/GenerateExportHeader.cmake
new file mode 100644
index 0000000000..0c6256cf7f
--- /dev/null
+++ b/Modules/GenerateExportHeader.cmake
@@ -0,0 +1,403 @@
+#.rst:
+# GenerateExportHeader
+# --------------------
+#
+# Function for generation of export macros for libraries
+#
+# This module provides the function GENERATE_EXPORT_HEADER().
+#
+# The ``GENERATE_EXPORT_HEADER`` function can be used to generate a file
+# suitable for preprocessor inclusion which contains EXPORT macros to be
+# used in library classes::
+#
+# GENERATE_EXPORT_HEADER( LIBRARY_TARGET
+# [BASE_NAME <base_name>]
+# [EXPORT_MACRO_NAME <export_macro_name>]
+# [EXPORT_FILE_NAME <export_file_name>]
+# [DEPRECATED_MACRO_NAME <deprecated_macro_name>]
+# [NO_EXPORT_MACRO_NAME <no_export_macro_name>]
+# [STATIC_DEFINE <static_define>]
+# [NO_DEPRECATED_MACRO_NAME <no_deprecated_macro_name>]
+# [DEFINE_NO_DEPRECATED]
+# [PREFIX_NAME <prefix_name>]
+# )
+#
+#
+# The target properties :prop_tgt:`CXX_VISIBILITY_PRESET <<LANG>_VISIBILITY_PRESET>`
+# and :prop_tgt:`VISIBILITY_INLINES_HIDDEN` can be used to add the appropriate
+# compile flags for targets. See the documentation of those target properties,
+# and the convenience variables
+# :variable:`CMAKE_CXX_VISIBILITY_PRESET <CMAKE_<LANG>_VISIBILITY_PRESET>` and
+# :variable:`CMAKE_VISIBILITY_INLINES_HIDDEN`.
+#
+# By default ``GENERATE_EXPORT_HEADER()`` generates macro names in a file
+# name determined by the name of the library. This means that in the
+# simplest case, users of ``GenerateExportHeader`` will be equivalent to:
+#
+# .. code-block:: cmake
+#
+# set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+# set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
+# add_library(somelib someclass.cpp)
+# generate_export_header(somelib)
+# install(TARGETS somelib DESTINATION ${LIBRARY_INSTALL_DIR})
+# install(FILES
+# someclass.h
+# ${PROJECT_BINARY_DIR}/somelib_export.h DESTINATION ${INCLUDE_INSTALL_DIR}
+# )
+#
+#
+# And in the ABI header files:
+#
+# .. code-block:: c++
+#
+# #include "somelib_export.h"
+# class SOMELIB_EXPORT SomeClass {
+# ...
+# };
+#
+#
+# The CMake fragment will generate a file in the
+# ``${CMAKE_CURRENT_BINARY_DIR}`` called ``somelib_export.h`` containing the
+# macros ``SOMELIB_EXPORT``, ``SOMELIB_NO_EXPORT``, ``SOMELIB_DEPRECATED``,
+# ``SOMELIB_DEPRECATED_EXPORT`` and ``SOMELIB_DEPRECATED_NO_EXPORT``. The
+# resulting file should be installed with other headers in the library.
+#
+# The ``BASE_NAME`` argument can be used to override the file name and the
+# names used for the macros:
+#
+# .. code-block:: cmake
+#
+# add_library(somelib someclass.cpp)
+# generate_export_header(somelib
+# BASE_NAME other_name
+# )
+#
+#
+# Generates a file called ``other_name_export.h`` containing the macros
+# ``OTHER_NAME_EXPORT``, ``OTHER_NAME_NO_EXPORT`` and ``OTHER_NAME_DEPRECATED``
+# etc.
+#
+# The ``BASE_NAME`` may be overridden by specifiying other options in the
+# function. For example:
+#
+# .. code-block:: cmake
+#
+# add_library(somelib someclass.cpp)
+# generate_export_header(somelib
+# EXPORT_MACRO_NAME OTHER_NAME_EXPORT
+# )
+#
+#
+# creates the macro ``OTHER_NAME_EXPORT`` instead of ``SOMELIB_EXPORT``, but
+# other macros and the generated file name is as default:
+#
+# .. code-block:: cmake
+#
+# add_library(somelib someclass.cpp)
+# generate_export_header(somelib
+# DEPRECATED_MACRO_NAME KDE_DEPRECATED
+# )
+#
+#
+# creates the macro ``KDE_DEPRECATED`` instead of ``SOMELIB_DEPRECATED``.
+#
+# If ``LIBRARY_TARGET`` is a static library, macros are defined without
+# values.
+#
+# If the same sources are used to create both a shared and a static
+# library, the uppercased symbol ``${BASE_NAME}_STATIC_DEFINE`` should be
+# used when building the static library:
+#
+# .. code-block:: cmake
+#
+# add_library(shared_variant SHARED ${lib_SRCS})
+# add_library(static_variant ${lib_SRCS})
+# generate_export_header(shared_variant BASE_NAME libshared_and_static)
+# set_target_properties(static_variant PROPERTIES
+# COMPILE_FLAGS -DLIBSHARED_AND_STATIC_STATIC_DEFINE)
+#
+# This will cause the export macros to expand to nothing when building
+# the static library.
+#
+# If ``DEFINE_NO_DEPRECATED`` is specified, then a macro
+# ``${BASE_NAME}_NO_DEPRECATED`` will be defined This macro can be used to
+# remove deprecated code from preprocessor output:
+#
+# .. code-block:: cmake
+#
+# option(EXCLUDE_DEPRECATED "Exclude deprecated parts of the library" FALSE)
+# if (EXCLUDE_DEPRECATED)
+# set(NO_BUILD_DEPRECATED DEFINE_NO_DEPRECATED)
+# endif()
+# generate_export_header(somelib ${NO_BUILD_DEPRECATED})
+#
+#
+# And then in somelib:
+#
+# .. code-block:: c++
+#
+# class SOMELIB_EXPORT SomeClass
+# {
+# public:
+# #ifndef SOMELIB_NO_DEPRECATED
+# SOMELIB_DEPRECATED void oldMethod();
+# #endif
+# };
+#
+# .. code-block:: c++
+#
+# #ifndef SOMELIB_NO_DEPRECATED
+# void SomeClass::oldMethod() { }
+# #endif
+#
+#
+# If ``PREFIX_NAME`` is specified, the argument will be used as a prefix to
+# all generated macros.
+#
+# For example:
+#
+# .. code-block:: cmake
+#
+# generate_export_header(somelib PREFIX_NAME VTK_)
+#
+# Generates the macros ``VTK_SOMELIB_EXPORT`` etc.
+#
+# ::
+#
+# ADD_COMPILER_EXPORT_FLAGS( [<output_variable>] )
+#
+# The ``ADD_COMPILER_EXPORT_FLAGS`` function adds ``-fvisibility=hidden`` to
+# :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>` if supported, and is a no-op
+# on Windows which does not need extra compiler flags for exporting support.
+# You may optionally pass a single argument to ``ADD_COMPILER_EXPORT_FLAGS``
+# that will be populated with the ``CXX_FLAGS`` required to enable visibility
+# support for the compiler/architecture in use.
+#
+# This function is deprecated. Set the target properties
+# :prop_tgt:`CXX_VISIBILITY_PRESET <<LANG>_VISIBILITY_PRESET>` and
+# :prop_tgt:`VISIBILITY_INLINES_HIDDEN` instead.
+
+#=============================================================================
+# Copyright 2011 Stephen Kelly <steveire@gmail.com>
+#
+# 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.)
+
+include(CMakeParseArguments)
+include(CheckCXXCompilerFlag)
+
+# TODO: Install this macro separately?
+macro(_check_cxx_compiler_attribute _ATTRIBUTE _RESULT)
+ check_cxx_source_compiles("${_ATTRIBUTE} int somefunc() { return 0; }
+ int main() { return somefunc();}" ${_RESULT}
+ )
+endmacro()
+
+macro(_test_compiler_hidden_visibility)
+
+ if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.2")
+ set(GCC_TOO_OLD TRUE)
+ elseif(CMAKE_COMPILER_IS_GNUC AND CMAKE_C_COMPILER_VERSION VERSION_LESS "4.2")
+ set(GCC_TOO_OLD TRUE)
+ elseif(CMAKE_CXX_COMPILER_ID MATCHES Intel AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "12.0")
+ set(_INTEL_TOO_OLD TRUE)
+ endif()
+
+ # Exclude XL here because it misinterprets -fvisibility=hidden even though
+ # the check_cxx_compiler_flag passes
+ if(NOT GCC_TOO_OLD
+ AND NOT _INTEL_TOO_OLD
+ AND NOT WIN32
+ AND NOT CYGWIN
+ AND NOT CMAKE_CXX_COMPILER_ID MATCHES XL
+ AND NOT CMAKE_CXX_COMPILER_ID MATCHES PGI
+ AND NOT CMAKE_CXX_COMPILER_ID MATCHES Watcom)
+ check_cxx_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
+ check_cxx_compiler_flag(-fvisibility-inlines-hidden
+ COMPILER_HAS_HIDDEN_INLINE_VISIBILITY)
+ option(USE_COMPILER_HIDDEN_VISIBILITY
+ "Use HIDDEN visibility support if available." ON)
+ mark_as_advanced(USE_COMPILER_HIDDEN_VISIBILITY)
+ endif()
+endmacro()
+
+macro(_test_compiler_has_deprecated)
+ if(CMAKE_CXX_COMPILER_ID MATCHES Borland
+ OR CMAKE_CXX_COMPILER_ID MATCHES HP
+ OR GCC_TOO_OLD
+ OR CMAKE_CXX_COMPILER_ID MATCHES PGI
+ OR CMAKE_CXX_COMPILER_ID MATCHES Watcom)
+ set(COMPILER_HAS_DEPRECATED "" CACHE INTERNAL
+ "Compiler support for a deprecated attribute")
+ else()
+ _check_cxx_compiler_attribute("__attribute__((__deprecated__))"
+ COMPILER_HAS_DEPRECATED_ATTR)
+ if(COMPILER_HAS_DEPRECATED_ATTR)
+ set(COMPILER_HAS_DEPRECATED "${COMPILER_HAS_DEPRECATED_ATTR}"
+ CACHE INTERNAL "Compiler support for a deprecated attribute")
+ else()
+ _check_cxx_compiler_attribute("__declspec(deprecated)"
+ COMPILER_HAS_DEPRECATED)
+ endif()
+ endif()
+endmacro()
+
+get_filename_component(_GENERATE_EXPORT_HEADER_MODULE_DIR
+ "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+macro(_DO_SET_MACRO_VALUES TARGET_LIBRARY)
+ set(DEFINE_DEPRECATED)
+ set(DEFINE_EXPORT)
+ set(DEFINE_IMPORT)
+ set(DEFINE_NO_EXPORT)
+
+ if (COMPILER_HAS_DEPRECATED_ATTR)
+ set(DEFINE_DEPRECATED "__attribute__ ((__deprecated__))")
+ elseif(COMPILER_HAS_DEPRECATED)
+ set(DEFINE_DEPRECATED "__declspec(deprecated)")
+ endif()
+
+ get_property(type TARGET ${TARGET_LIBRARY} PROPERTY TYPE)
+
+ if(NOT ${type} STREQUAL "STATIC_LIBRARY")
+ if(WIN32)
+ set(DEFINE_EXPORT "__declspec(dllexport)")
+ set(DEFINE_IMPORT "__declspec(dllimport)")
+ elseif(COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
+ set(DEFINE_EXPORT "__attribute__((visibility(\"default\")))")
+ set(DEFINE_IMPORT "__attribute__((visibility(\"default\")))")
+ set(DEFINE_NO_EXPORT "__attribute__((visibility(\"hidden\")))")
+ endif()
+ endif()
+endmacro()
+
+macro(_DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY)
+ # Option overrides
+ set(options DEFINE_NO_DEPRECATED)
+ set(oneValueArgs PREFIX_NAME BASE_NAME EXPORT_MACRO_NAME EXPORT_FILE_NAME
+ DEPRECATED_MACRO_NAME NO_EXPORT_MACRO_NAME STATIC_DEFINE
+ NO_DEPRECATED_MACRO_NAME)
+ set(multiValueArgs)
+
+ cmake_parse_arguments(_GEH "${options}" "${oneValueArgs}" "${multiValueArgs}"
+ ${ARGN})
+
+ set(BASE_NAME "${TARGET_LIBRARY}")
+
+ if(_GEH_BASE_NAME)
+ set(BASE_NAME ${_GEH_BASE_NAME})
+ endif()
+
+ string(TOUPPER ${BASE_NAME} BASE_NAME_UPPER)
+ string(TOLOWER ${BASE_NAME} BASE_NAME_LOWER)
+
+ # Default options
+ set(EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_EXPORT")
+ set(NO_EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_NO_EXPORT")
+ set(EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${BASE_NAME_LOWER}_export.h")
+ set(DEPRECATED_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_DEPRECATED")
+ set(STATIC_DEFINE "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_STATIC_DEFINE")
+ set(NO_DEPRECATED_MACRO_NAME
+ "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_NO_DEPRECATED")
+
+ if(_GEH_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown keywords given to GENERATE_EXPORT_HEADER(): \"${_GEH_UNPARSED_ARGUMENTS}\"")
+ endif()
+
+ if(_GEH_EXPORT_MACRO_NAME)
+ set(EXPORT_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_EXPORT_MACRO_NAME})
+ endif()
+ string(MAKE_C_IDENTIFIER ${EXPORT_MACRO_NAME} EXPORT_MACRO_NAME)
+ if(_GEH_EXPORT_FILE_NAME)
+ if(IS_ABSOLUTE ${_GEH_EXPORT_FILE_NAME})
+ set(EXPORT_FILE_NAME ${_GEH_EXPORT_FILE_NAME})
+ else()
+ set(EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${_GEH_EXPORT_FILE_NAME}")
+ endif()
+ endif()
+ if(_GEH_DEPRECATED_MACRO_NAME)
+ set(DEPRECATED_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_DEPRECATED_MACRO_NAME})
+ endif()
+ string(MAKE_C_IDENTIFIER ${DEPRECATED_MACRO_NAME} DEPRECATED_MACRO_NAME)
+ if(_GEH_NO_EXPORT_MACRO_NAME)
+ set(NO_EXPORT_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_NO_EXPORT_MACRO_NAME})
+ endif()
+ string(MAKE_C_IDENTIFIER ${NO_EXPORT_MACRO_NAME} NO_EXPORT_MACRO_NAME)
+ if(_GEH_STATIC_DEFINE)
+ set(STATIC_DEFINE ${_GEH_PREFIX_NAME}${_GEH_STATIC_DEFINE})
+ endif()
+ string(MAKE_C_IDENTIFIER ${STATIC_DEFINE} STATIC_DEFINE)
+
+ if(_GEH_DEFINE_NO_DEPRECATED)
+ set(DEFINE_NO_DEPRECATED TRUE)
+ endif()
+
+ if(_GEH_NO_DEPRECATED_MACRO_NAME)
+ set(NO_DEPRECATED_MACRO_NAME
+ ${_GEH_PREFIX_NAME}${_GEH_NO_DEPRECATED_MACRO_NAME})
+ endif()
+ string(MAKE_C_IDENTIFIER ${NO_DEPRECATED_MACRO_NAME} NO_DEPRECATED_MACRO_NAME)
+
+ set(INCLUDE_GUARD_NAME "${EXPORT_MACRO_NAME}_H")
+
+ get_target_property(EXPORT_IMPORT_CONDITION ${TARGET_LIBRARY} DEFINE_SYMBOL)
+
+ if(NOT EXPORT_IMPORT_CONDITION)
+ set(EXPORT_IMPORT_CONDITION ${TARGET_LIBRARY}_EXPORTS)
+ endif()
+ string(MAKE_C_IDENTIFIER ${EXPORT_IMPORT_CONDITION} EXPORT_IMPORT_CONDITION)
+
+ configure_file("${_GENERATE_EXPORT_HEADER_MODULE_DIR}/exportheader.cmake.in"
+ "${EXPORT_FILE_NAME}" @ONLY)
+endmacro()
+
+function(GENERATE_EXPORT_HEADER TARGET_LIBRARY)
+ get_property(type TARGET ${TARGET_LIBRARY} PROPERTY TYPE)
+ if(NOT ${type} STREQUAL "STATIC_LIBRARY"
+ AND NOT ${type} STREQUAL "SHARED_LIBRARY"
+ AND NOT ${type} STREQUAL "OBJECT_LIBRARY"
+ AND NOT ${type} STREQUAL "MODULE_LIBRARY")
+ message(WARNING "This macro can only be used with libraries")
+ return()
+ endif()
+ _test_compiler_hidden_visibility()
+ _test_compiler_has_deprecated()
+ _do_set_macro_values(${TARGET_LIBRARY})
+ _do_generate_export_header(${TARGET_LIBRARY} ${ARGN})
+endfunction()
+
+function(add_compiler_export_flags)
+ if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.12)
+ message(DEPRECATION "The add_compiler_export_flags function is obsolete. Use the CXX_VISIBILITY_PRESET and VISIBILITY_INLINES_HIDDEN target properties instead.")
+ endif()
+
+ _test_compiler_hidden_visibility()
+ _test_compiler_has_deprecated()
+
+ if(NOT (USE_COMPILER_HIDDEN_VISIBILITY AND COMPILER_HAS_HIDDEN_VISIBILITY))
+ # Just return if there are no flags to add.
+ return()
+ endif()
+
+ set (EXTRA_FLAGS "-fvisibility=hidden")
+
+ if(COMPILER_HAS_HIDDEN_INLINE_VISIBILITY)
+ set (EXTRA_FLAGS "${EXTRA_FLAGS} -fvisibility-inlines-hidden")
+ endif()
+
+ # Either return the extra flags needed in the supplied argument, or to the
+ # CMAKE_CXX_FLAGS if no argument is supplied.
+ if(ARGV0)
+ set(${ARGV0} "${EXTRA_FLAGS}" PARENT_SCOPE)
+ else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS}" PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake
new file mode 100644
index 0000000000..99635175d6
--- /dev/null
+++ b/Modules/GetPrerequisites.cmake
@@ -0,0 +1,955 @@
+#.rst:
+# GetPrerequisites
+# ----------------
+#
+# Functions to analyze and list executable file prerequisites.
+#
+# This module provides functions to list the .dll, .dylib or .so files
+# that an executable or shared library file depends on. (Its
+# prerequisites.)
+#
+# It uses various tools to obtain the list of required shared library
+# files:
+#
+# ::
+#
+# dumpbin (Windows)
+# objdump (MinGW on Windows)
+# ldd (Linux/Unix)
+# otool (Mac OSX)
+#
+# The following functions are provided by this module:
+#
+# ::
+#
+# get_prerequisites
+# list_prerequisites
+# list_prerequisites_by_glob
+# gp_append_unique
+# is_file_executable
+# gp_item_default_embedded_path
+# (projects can override with gp_item_default_embedded_path_override)
+# gp_resolve_item
+# (projects can override with gp_resolve_item_override)
+# gp_resolved_file_type
+# (projects can override with gp_resolved_file_type_override)
+# gp_file_type
+#
+# Requires CMake 2.6 or greater because it uses function, break, return
+# and PARENT_SCOPE.
+#
+# ::
+#
+# GET_PREREQUISITES(<target> <prerequisites_var> <exclude_system> <recurse>
+# <exepath> <dirs> [<rpaths>])
+#
+# Get the list of shared library files required by <target>. The list
+# in the variable named <prerequisites_var> should be empty on first
+# entry to this function. On exit, <prerequisites_var> will contain the
+# list of required shared library files.
+#
+# <target> is the full path to an executable file. <prerequisites_var>
+# is the name of a CMake variable to contain the results.
+# <exclude_system> must be 0 or 1 indicating whether to include or
+# exclude "system" prerequisites. If <recurse> is set to 1 all
+# prerequisites will be found recursively, if set to 0 only direct
+# prerequisites are listed. <exepath> is the path to the top level
+# executable used for @executable_path replacment on the Mac. <dirs> is
+# a list of paths where libraries might be found: these paths are
+# searched first when a target without any path info is given. Then
+# standard system locations are also searched: PATH, Framework
+# locations, /usr/lib...
+#
+# ::
+#
+# LIST_PREREQUISITES(<target> [<recurse> [<exclude_system> [<verbose>]]])
+#
+# Print a message listing the prerequisites of <target>.
+#
+# <target> is the name of a shared library or executable target or the
+# full path to a shared library or executable file. If <recurse> is set
+# to 1 all prerequisites will be found recursively, if set to 0 only
+# direct prerequisites are listed. <exclude_system> must be 0 or 1
+# indicating whether to include or exclude "system" prerequisites. With
+# <verbose> set to 0 only the full path names of the prerequisites are
+# printed, set to 1 extra informatin will be displayed.
+#
+# ::
+#
+# LIST_PREREQUISITES_BY_GLOB(<glob_arg> <glob_exp>)
+#
+# Print the prerequisites of shared library and executable files
+# matching a globbing pattern. <glob_arg> is GLOB or GLOB_RECURSE and
+# <glob_exp> is a globbing expression used with "file(GLOB" or
+# "file(GLOB_RECURSE" to retrieve a list of matching files. If a
+# matching file is executable, its prerequisites are listed.
+#
+# Any additional (optional) arguments provided are passed along as the
+# optional arguments to the list_prerequisites calls.
+#
+# ::
+#
+# GP_APPEND_UNIQUE(<list_var> <value>)
+#
+# Append <value> to the list variable <list_var> only if the value is
+# not already in the list.
+#
+# ::
+#
+# IS_FILE_EXECUTABLE(<file> <result_var>)
+#
+# Return 1 in <result_var> if <file> is a binary executable, 0
+# otherwise.
+#
+# ::
+#
+# GP_ITEM_DEFAULT_EMBEDDED_PATH(<item> <default_embedded_path_var>)
+#
+# Return the path that others should refer to the item by when the item
+# is embedded inside a bundle.
+#
+# Override on a per-project basis by providing a project-specific
+# gp_item_default_embedded_path_override function.
+#
+# ::
+#
+# GP_RESOLVE_ITEM(<context> <item> <exepath> <dirs> <resolved_item_var>
+# [<rpaths>])
+#
+# Resolve an item into an existing full path file.
+#
+# Override on a per-project basis by providing a project-specific
+# gp_resolve_item_override function.
+#
+# ::
+#
+# GP_RESOLVED_FILE_TYPE(<original_file> <file> <exepath> <dirs> <type_var>
+# [<rpaths>])
+#
+# Return the type of <file> with respect to <original_file>. String
+# describing type of prerequisite is returned in variable named
+# <type_var>.
+#
+# Use <exepath> and <dirs> if necessary to resolve non-absolute <file>
+# values -- but only for non-embedded items.
+#
+# Possible types are:
+#
+# ::
+#
+# system
+# local
+# embedded
+# other
+#
+# Override on a per-project basis by providing a project-specific
+# gp_resolved_file_type_override function.
+#
+# ::
+#
+# GP_FILE_TYPE(<original_file> <file> <type_var>)
+#
+# Return the type of <file> with respect to <original_file>. String
+# describing type of prerequisite is returned in variable named
+# <type_var>.
+#
+# Possible types are:
+#
+# ::
+#
+# system
+# local
+# embedded
+# other
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+function(gp_append_unique list_var value)
+ set(contains 0)
+
+ foreach(item ${${list_var}})
+ if("${item}" STREQUAL "${value}")
+ set(contains 1)
+ break()
+ endif()
+ endforeach()
+
+ if(NOT contains)
+ set(${list_var} ${${list_var}} "${value}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+function(is_file_executable file result_var)
+ #
+ # A file is not executable until proven otherwise:
+ #
+ set(${result_var} 0 PARENT_SCOPE)
+
+ get_filename_component(file_full "${file}" ABSOLUTE)
+ string(TOLOWER "${file_full}" file_full_lower)
+
+ # If file name ends in .exe on Windows, *assume* executable:
+ #
+ if(WIN32 AND NOT UNIX)
+ if("${file_full_lower}" MATCHES "\\.exe$")
+ set(${result_var} 1 PARENT_SCOPE)
+ return()
+ endif()
+
+ # A clause could be added here that uses output or return value of dumpbin
+ # to determine ${result_var}. In 99%+? practical cases, the exe name
+ # match will be sufficient...
+ #
+ endif()
+
+ # Use the information returned from the Unix shell command "file" to
+ # determine if ${file_full} should be considered an executable file...
+ #
+ # If the file command's output contains "executable" and does *not* contain
+ # "text" then it is likely an executable suitable for prerequisite analysis
+ # via the get_prerequisites macro.
+ #
+ if(UNIX)
+ if(NOT file_cmd)
+ find_program(file_cmd "file")
+ mark_as_advanced(file_cmd)
+ endif()
+
+ if(file_cmd)
+ execute_process(COMMAND "${file_cmd}" "${file_full}"
+ OUTPUT_VARIABLE file_ov
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ # Replace the name of the file in the output with a placeholder token
+ # (the string " _file_full_ ") so that just in case the path name of
+ # the file contains the word "text" or "executable" we are not fooled
+ # into thinking "the wrong thing" because the file name matches the
+ # other 'file' command output we are looking for...
+ #
+ string(REPLACE "${file_full}" " _file_full_ " file_ov "${file_ov}")
+ string(TOLOWER "${file_ov}" file_ov)
+
+ #message(STATUS "file_ov='${file_ov}'")
+ if("${file_ov}" MATCHES "executable")
+ #message(STATUS "executable!")
+ if("${file_ov}" MATCHES "text")
+ #message(STATUS "but text, so *not* a binary executable!")
+ else()
+ set(${result_var} 1 PARENT_SCOPE)
+ return()
+ endif()
+ endif()
+
+ # Also detect position independent executables on Linux,
+ # where "file" gives "shared object ... (uses shared libraries)"
+ if("${file_ov}" MATCHES "shared object.*\(uses shared libs\)")
+ set(${result_var} 1 PARENT_SCOPE)
+ return()
+ endif()
+
+ else()
+ message(STATUS "warning: No 'file' command, skipping execute_process...")
+ endif()
+ endif()
+endfunction()
+
+
+function(gp_item_default_embedded_path item default_embedded_path_var)
+
+ # On Windows and Linux, "embed" prerequisites in the same directory
+ # as the executable by default:
+ #
+ set(path "@executable_path")
+ set(overridden 0)
+
+ # On the Mac, relative to the executable depending on the type
+ # of the thing we are embedding:
+ #
+ if(APPLE)
+ #
+ # The assumption here is that all executables in the bundle will be
+ # in same-level-directories inside the bundle. The parent directory
+ # of an executable inside the bundle should be MacOS or a sibling of
+ # MacOS and all embedded paths returned from here will begin with
+ # "@executable_path/../" and will work from all executables in all
+ # such same-level-directories inside the bundle.
+ #
+
+ # By default, embed things right next to the main bundle executable:
+ #
+ set(path "@executable_path/../../Contents/MacOS")
+
+ # Embed .dylibs right next to the main bundle executable:
+ #
+ if(item MATCHES "\\.dylib$")
+ set(path "@executable_path/../MacOS")
+ set(overridden 1)
+ endif()
+
+ # Embed frameworks in the embedded "Frameworks" directory (sibling of MacOS):
+ #
+ if(NOT overridden)
+ if(item MATCHES "[^/]+\\.framework/")
+ set(path "@executable_path/../Frameworks")
+ set(overridden 1)
+ endif()
+ endif()
+ endif()
+
+ # Provide a hook so that projects can override the default embedded location
+ # of any given library by whatever logic they choose:
+ #
+ if(COMMAND gp_item_default_embedded_path_override)
+ gp_item_default_embedded_path_override("${item}" path)
+ endif()
+
+ set(${default_embedded_path_var} "${path}" PARENT_SCOPE)
+endfunction()
+
+
+function(gp_resolve_item context item exepath dirs resolved_item_var)
+ set(resolved 0)
+ set(resolved_item "${item}")
+ set(rpaths "${ARGV5}")
+
+ # Is it already resolved?
+ #
+ if(IS_ABSOLUTE "${resolved_item}" AND EXISTS "${resolved_item}")
+ set(resolved 1)
+ endif()
+
+ if(NOT resolved)
+ if(item MATCHES "^@executable_path")
+ #
+ # @executable_path references are assumed relative to exepath
+ #
+ string(REPLACE "@executable_path" "${exepath}" ri "${item}")
+ get_filename_component(ri "${ri}" ABSOLUTE)
+
+ if(EXISTS "${ri}")
+ #message(STATUS "info: embedded item exists (${ri})")
+ set(resolved 1)
+ set(resolved_item "${ri}")
+ else()
+ message(STATUS "warning: embedded item does not exist '${ri}'")
+ endif()
+ endif()
+ endif()
+
+ if(NOT resolved)
+ if(item MATCHES "^@loader_path")
+ #
+ # @loader_path references are assumed relative to the
+ # PATH of the given "context" (presumably another library)
+ #
+ get_filename_component(contextpath "${context}" PATH)
+ string(REPLACE "@loader_path" "${contextpath}" ri "${item}")
+ get_filename_component(ri "${ri}" ABSOLUTE)
+
+ if(EXISTS "${ri}")
+ #message(STATUS "info: embedded item exists (${ri})")
+ set(resolved 1)
+ set(resolved_item "${ri}")
+ else()
+ message(STATUS "warning: embedded item does not exist '${ri}'")
+ endif()
+ endif()
+ endif()
+
+ if(NOT resolved)
+ if(item MATCHES "^@rpath")
+ #
+ # @rpath references are relative to the paths built into the binaries with -rpath
+ # We handle this case like we do for other Unixes
+ #
+ string(REPLACE "@rpath/" "" norpath_item "${item}")
+
+ set(ri "ri-NOTFOUND")
+ find_file(ri "${norpath_item}" ${exepath} ${dirs} ${rpaths} NO_DEFAULT_PATH)
+ if(ri)
+ #message(STATUS "info: 'find_file' in exepath/dirs/rpaths (${ri})")
+ set(resolved 1)
+ set(resolved_item "${ri}")
+ set(ri "ri-NOTFOUND")
+ endif()
+
+ endif()
+ endif()
+
+ if(NOT resolved)
+ set(ri "ri-NOTFOUND")
+ find_file(ri "${item}" ${exepath} ${dirs} NO_DEFAULT_PATH)
+ find_file(ri "${item}" ${exepath} ${dirs} /usr/lib)
+ if(ri)
+ #message(STATUS "info: 'find_file' in exepath/dirs (${ri})")
+ set(resolved 1)
+ set(resolved_item "${ri}")
+ set(ri "ri-NOTFOUND")
+ endif()
+ endif()
+
+ if(NOT resolved)
+ if(item MATCHES "[^/]+\\.framework/")
+ set(fw "fw-NOTFOUND")
+ find_file(fw "${item}"
+ "~/Library/Frameworks"
+ "/Library/Frameworks"
+ "/System/Library/Frameworks"
+ )
+ if(fw)
+ #message(STATUS "info: 'find_file' found framework (${fw})")
+ set(resolved 1)
+ set(resolved_item "${fw}")
+ set(fw "fw-NOTFOUND")
+ endif()
+ endif()
+ endif()
+
+ # Using find_program on Windows will find dll files that are in the PATH.
+ # (Converting simple file names into full path names if found.)
+ #
+ if(WIN32 AND NOT UNIX)
+ if(NOT resolved)
+ set(ri "ri-NOTFOUND")
+ find_program(ri "${item}" PATHS "${exepath};${dirs}" NO_DEFAULT_PATH)
+ find_program(ri "${item}" PATHS "${exepath};${dirs}")
+ if(ri)
+ #message(STATUS "info: 'find_program' in exepath/dirs (${ri})")
+ set(resolved 1)
+ set(resolved_item "${ri}")
+ set(ri "ri-NOTFOUND")
+ endif()
+ endif()
+ endif()
+
+ # Provide a hook so that projects can override item resolution
+ # by whatever logic they choose:
+ #
+ if(COMMAND gp_resolve_item_override)
+ gp_resolve_item_override("${context}" "${item}" "${exepath}" "${dirs}" resolved_item resolved)
+ endif()
+
+ if(NOT resolved)
+ message(STATUS "
+warning: cannot resolve item '${item}'
+
+ possible problems:
+ need more directories?
+ need to use InstallRequiredSystemLibraries?
+ run in install tree instead of build tree?
+")
+# message(STATUS "
+#******************************************************************************
+#warning: cannot resolve item '${item}'
+#
+# possible problems:
+# need more directories?
+# need to use InstallRequiredSystemLibraries?
+# run in install tree instead of build tree?
+#
+# context='${context}'
+# item='${item}'
+# exepath='${exepath}'
+# dirs='${dirs}'
+# resolved_item_var='${resolved_item_var}'
+#******************************************************************************
+#")
+ endif()
+
+ set(${resolved_item_var} "${resolved_item}" PARENT_SCOPE)
+endfunction()
+
+
+function(gp_resolved_file_type original_file file exepath dirs type_var)
+ set(rpaths "${ARGV5}")
+ #message(STATUS "**")
+
+ if(NOT IS_ABSOLUTE "${original_file}")
+ message(STATUS "warning: gp_resolved_file_type expects absolute full path for first arg original_file")
+ endif()
+
+ set(is_embedded 0)
+ set(is_local 0)
+ set(is_system 0)
+
+ set(resolved_file "${file}")
+
+ if("${file}" MATCHES "^@(executable|loader)_path")
+ set(is_embedded 1)
+ endif()
+
+ if(NOT is_embedded)
+ if(NOT IS_ABSOLUTE "${file}")
+ gp_resolve_item("${original_file}" "${file}" "${exepath}" "${dirs}" resolved_file "${rpaths}")
+ endif()
+
+ string(TOLOWER "${original_file}" original_lower)
+ string(TOLOWER "${resolved_file}" lower)
+
+ if(UNIX)
+ if(resolved_file MATCHES "^(/lib/|/lib32/|/lib64/|/usr/lib/|/usr/lib32/|/usr/lib64/|/usr/X11R6/|/usr/bin/)")
+ set(is_system 1)
+ endif()
+ endif()
+
+ if(APPLE)
+ if(resolved_file MATCHES "^(/System/Library/|/usr/lib/)")
+ set(is_system 1)
+ endif()
+ endif()
+
+ if(WIN32)
+ string(TOLOWER "$ENV{SystemRoot}" sysroot)
+ file(TO_CMAKE_PATH "${sysroot}" sysroot)
+
+ string(TOLOWER "$ENV{windir}" windir)
+ file(TO_CMAKE_PATH "${windir}" windir)
+
+ if(lower MATCHES "^(${sysroot}/sys(tem|wow)|${windir}/sys(tem|wow)|(.*/)*msvc[^/]+dll)")
+ set(is_system 1)
+ endif()
+
+ if(UNIX)
+ # if cygwin, we can get the properly formed windows paths from cygpath
+ find_program(CYGPATH_EXECUTABLE cygpath)
+
+ if(CYGPATH_EXECUTABLE)
+ execute_process(COMMAND ${CYGPATH_EXECUTABLE} -W
+ OUTPUT_VARIABLE env_windir
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND ${CYGPATH_EXECUTABLE} -S
+ OUTPUT_VARIABLE env_sysdir
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(TOLOWER "${env_windir}" windir)
+ string(TOLOWER "${env_sysdir}" sysroot)
+
+ if(lower MATCHES "^(${sysroot}/sys(tem|wow)|${windir}/sys(tem|wow)|(.*/)*msvc[^/]+dll)")
+ set(is_system 1)
+ endif()
+ endif()
+ endif()
+ endif()
+
+ if(NOT is_system)
+ get_filename_component(original_path "${original_lower}" PATH)
+ get_filename_component(path "${lower}" PATH)
+ if("${original_path}" STREQUAL "${path}")
+ set(is_local 1)
+ else()
+ string(LENGTH "${original_path}/" original_length)
+ string(LENGTH "${lower}" path_length)
+ if(${path_length} GREATER ${original_length})
+ string(SUBSTRING "${lower}" 0 ${original_length} path)
+ if("${original_path}/" STREQUAL "${path}")
+ set(is_embedded 1)
+ endif()
+ endif()
+ endif()
+ endif()
+ endif()
+
+ # Return type string based on computed booleans:
+ #
+ set(type "other")
+
+ if(is_system)
+ set(type "system")
+ elseif(is_embedded)
+ set(type "embedded")
+ elseif(is_local)
+ set(type "local")
+ endif()
+
+ #message(STATUS "gp_resolved_file_type: '${file}' '${resolved_file}'")
+ #message(STATUS " type: '${type}'")
+
+ if(NOT is_embedded)
+ if(NOT IS_ABSOLUTE "${resolved_file}")
+ if(lower MATCHES "^msvc[^/]+dll" AND is_system)
+ message(STATUS "info: non-absolute msvc file '${file}' returning type '${type}'")
+ else()
+ message(STATUS "warning: gp_resolved_file_type non-absolute file '${file}' returning type '${type}' -- possibly incorrect")
+ endif()
+ endif()
+ endif()
+
+ # Provide a hook so that projects can override the decision on whether a
+ # library belongs to the system or not by whatever logic they choose:
+ #
+ if(COMMAND gp_resolved_file_type_override)
+ gp_resolved_file_type_override("${resolved_file}" type)
+ endif()
+
+ set(${type_var} "${type}" PARENT_SCOPE)
+
+ #message(STATUS "**")
+endfunction()
+
+
+function(gp_file_type original_file file type_var)
+ if(NOT IS_ABSOLUTE "${original_file}")
+ message(STATUS "warning: gp_file_type expects absolute full path for first arg original_file")
+ endif()
+
+ get_filename_component(exepath "${original_file}" PATH)
+
+ set(type "")
+ gp_resolved_file_type("${original_file}" "${file}" "${exepath}" "" type)
+
+ set(${type_var} "${type}" PARENT_SCOPE)
+endfunction()
+
+
+function(get_prerequisites target prerequisites_var exclude_system recurse exepath dirs)
+ set(verbose 0)
+ set(eol_char "E")
+ set(rpaths "${ARGV6}")
+
+ if(NOT IS_ABSOLUTE "${target}")
+ message("warning: target '${target}' is not absolute...")
+ endif()
+
+ if(NOT EXISTS "${target}")
+ message("warning: target '${target}' does not exist...")
+ endif()
+
+ set(gp_cmd_paths ${gp_cmd_paths}
+ "C:/Program Files/Microsoft Visual Studio 9.0/VC/bin"
+ "C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin"
+ "C:/Program Files/Microsoft Visual Studio 8/VC/BIN"
+ "C:/Program Files (x86)/Microsoft Visual Studio 8/VC/BIN"
+ "C:/Program Files/Microsoft Visual Studio .NET 2003/VC7/BIN"
+ "C:/Program Files (x86)/Microsoft Visual Studio .NET 2003/VC7/BIN"
+ "/usr/local/bin"
+ "/usr/bin"
+ )
+
+ # <setup-gp_tool-vars>
+ #
+ # Try to choose the right tool by default. Caller can set gp_tool prior to
+ # calling this function to force using a different tool.
+ #
+ if("${gp_tool}" STREQUAL "")
+ set(gp_tool "ldd")
+
+ if(APPLE)
+ set(gp_tool "otool")
+ endif()
+
+ if(WIN32 AND NOT UNIX) # This is how to check for cygwin, har!
+ find_program(gp_dumpbin "dumpbin" PATHS ${gp_cmd_paths})
+ if(gp_dumpbin)
+ set(gp_tool "dumpbin")
+ else() # Try harder. Maybe we're on MinGW
+ set(gp_tool "objdump")
+ endif()
+ endif()
+ endif()
+
+ find_program(gp_cmd ${gp_tool} PATHS ${gp_cmd_paths})
+
+ if(NOT gp_cmd)
+ message(STATUS "warning: could not find '${gp_tool}' - cannot analyze prerequisites...")
+ return()
+ endif()
+
+ set(gp_tool_known 0)
+
+ if("${gp_tool}" STREQUAL "ldd")
+ set(gp_cmd_args "")
+ set(gp_regex "^[\t ]*[^\t ]+ => ([^\t\(]+) .*${eol_char}$")
+ set(gp_regex_error "not found${eol_char}$")
+ set(gp_regex_fallback "^[\t ]*([^\t ]+) => ([^\t ]+).*${eol_char}$")
+ set(gp_regex_cmp_count 1)
+ set(gp_tool_known 1)
+ endif()
+
+ if("${gp_tool}" STREQUAL "otool")
+ set(gp_cmd_args "-L")
+ set(gp_regex "^\t([^\t]+) \\(compatibility version ([0-9]+.[0-9]+.[0-9]+), current version ([0-9]+.[0-9]+.[0-9]+)\\)${eol_char}$")
+ set(gp_regex_error "")
+ set(gp_regex_fallback "")
+ set(gp_regex_cmp_count 3)
+ set(gp_tool_known 1)
+ endif()
+
+ if("${gp_tool}" STREQUAL "dumpbin")
+ set(gp_cmd_args "/dependents")
+ set(gp_regex "^ ([^ ].*[Dd][Ll][Ll])${eol_char}$")
+ set(gp_regex_error "")
+ set(gp_regex_fallback "")
+ set(gp_regex_cmp_count 1)
+ set(gp_tool_known 1)
+ endif()
+
+ if("${gp_tool}" STREQUAL "objdump")
+ set(gp_cmd_args "-p")
+ set(gp_regex "^\t*DLL Name: (.*\\.[Dd][Ll][Ll])${eol_char}$")
+ set(gp_regex_error "")
+ set(gp_regex_fallback "")
+ set(gp_regex_cmp_count 1)
+ set(gp_tool_known 1)
+ endif()
+
+ if(NOT gp_tool_known)
+ message(STATUS "warning: gp_tool='${gp_tool}' is an unknown tool...")
+ message(STATUS "CMake function get_prerequisites needs more code to handle '${gp_tool}'")
+ message(STATUS "Valid gp_tool values are dumpbin, ldd, objdump and otool.")
+ return()
+ endif()
+
+
+ if("${gp_tool}" STREQUAL "dumpbin")
+ # When running dumpbin, it also needs the "Common7/IDE" directory in the
+ # PATH. It will already be in the PATH if being run from a Visual Studio
+ # command prompt. Add it to the PATH here in case we are running from a
+ # different command prompt.
+ #
+ get_filename_component(gp_cmd_dir "${gp_cmd}" PATH)
+ get_filename_component(gp_cmd_dlls_dir "${gp_cmd_dir}/../../Common7/IDE" ABSOLUTE)
+ # Use cmake paths as a user may have a PATH element ending with a backslash.
+ # This will escape the list delimiter and create havoc!
+ if(EXISTS "${gp_cmd_dlls_dir}")
+ # only add to the path if it is not already in the path
+ set(gp_found_cmd_dlls_dir 0)
+ file(TO_CMAKE_PATH "$ENV{PATH}" env_path)
+ foreach(gp_env_path_element ${env_path})
+ if("${gp_env_path_element}" STREQUAL "${gp_cmd_dlls_dir}")
+ set(gp_found_cmd_dlls_dir 1)
+ endif()
+ endforeach()
+
+ if(NOT gp_found_cmd_dlls_dir)
+ file(TO_NATIVE_PATH "${gp_cmd_dlls_dir}" gp_cmd_dlls_dir)
+ set(ENV{PATH} "$ENV{PATH};${gp_cmd_dlls_dir}")
+ endif()
+ endif()
+ endif()
+ #
+ # </setup-gp_tool-vars>
+
+ if("${gp_tool}" STREQUAL "ldd")
+ set(old_ld_env "$ENV{LD_LIBRARY_PATH}")
+ set(new_ld_env "${exepath}")
+ foreach(dir ${dirs})
+ set(new_ld_env "${new_ld_env}:${dir}")
+ endforeach()
+ set(ENV{LD_LIBRARY_PATH} "${new_ld_env}:$ENV{LD_LIBRARY_PATH}")
+ endif()
+
+
+ # Track new prerequisites at each new level of recursion. Start with an
+ # empty list at each level:
+ #
+ set(unseen_prereqs)
+
+ # Run gp_cmd on the target:
+ #
+ execute_process(
+ COMMAND ${gp_cmd} ${gp_cmd_args} ${target}
+ OUTPUT_VARIABLE gp_cmd_ov
+ )
+
+ if("${gp_tool}" STREQUAL "ldd")
+ set(ENV{LD_LIBRARY_PATH} "${old_ld_env}")
+ endif()
+
+ if(verbose)
+ message(STATUS "<RawOutput cmd='${gp_cmd} ${gp_cmd_args} ${target}'>")
+ message(STATUS "gp_cmd_ov='${gp_cmd_ov}'")
+ message(STATUS "</RawOutput>")
+ endif()
+
+ get_filename_component(target_dir "${target}" PATH)
+
+ # Convert to a list of lines:
+ #
+ string(REPLACE ";" "\\;" candidates "${gp_cmd_ov}")
+ string(REPLACE "\n" "${eol_char};" candidates "${candidates}")
+
+ # check for install id and remove it from list, since otool -L can include a
+ # reference to itself
+ set(gp_install_id)
+ if("${gp_tool}" STREQUAL "otool")
+ execute_process(
+ COMMAND otool -D ${target}
+ OUTPUT_VARIABLE gp_install_id_ov
+ )
+ # second line is install name
+ string(REGEX REPLACE ".*:\n" "" gp_install_id "${gp_install_id_ov}")
+ if(gp_install_id)
+ # trim
+ string(REGEX MATCH "[^\n ].*[^\n ]" gp_install_id "${gp_install_id}")
+ #message("INSTALL ID is \"${gp_install_id}\"")
+ endif()
+ endif()
+
+ # Analyze each line for file names that match the regular expression:
+ #
+ foreach(candidate ${candidates})
+ if("${candidate}" MATCHES "${gp_regex}")
+
+ # Extract information from each candidate:
+ if(gp_regex_error AND "${candidate}" MATCHES "${gp_regex_error}")
+ string(REGEX REPLACE "${gp_regex_fallback}" "\\1" raw_item "${candidate}")
+ else()
+ string(REGEX REPLACE "${gp_regex}" "\\1" raw_item "${candidate}")
+ endif()
+
+ if(gp_regex_cmp_count GREATER 1)
+ string(REGEX REPLACE "${gp_regex}" "\\2" raw_compat_version "${candidate}")
+ string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\1" compat_major_version "${raw_compat_version}")
+ string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\2" compat_minor_version "${raw_compat_version}")
+ string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\3" compat_patch_version "${raw_compat_version}")
+ endif()
+
+ if(gp_regex_cmp_count GREATER 2)
+ string(REGEX REPLACE "${gp_regex}" "\\3" raw_current_version "${candidate}")
+ string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\1" current_major_version "${raw_current_version}")
+ string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\2" current_minor_version "${raw_current_version}")
+ string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\3" current_patch_version "${raw_current_version}")
+ endif()
+
+ # Use the raw_item as the list entries returned by this function. Use the
+ # gp_resolve_item function to resolve it to an actual full path file if
+ # necessary.
+ #
+ set(item "${raw_item}")
+
+ # Add each item unless it is excluded:
+ #
+ set(add_item 1)
+
+ if("${item}" STREQUAL "${gp_install_id}")
+ set(add_item 0)
+ endif()
+
+ if(add_item AND ${exclude_system})
+ set(type "")
+ gp_resolved_file_type("${target}" "${item}" "${exepath}" "${dirs}" type "${rpaths}")
+
+ if("${type}" STREQUAL "system")
+ set(add_item 0)
+ endif()
+ endif()
+
+ if(add_item)
+ list(LENGTH ${prerequisites_var} list_length_before_append)
+ gp_append_unique(${prerequisites_var} "${item}")
+ list(LENGTH ${prerequisites_var} list_length_after_append)
+
+ if(${recurse})
+ # If item was really added, this is the first time we have seen it.
+ # Add it to unseen_prereqs so that we can recursively add *its*
+ # prerequisites...
+ #
+ # But first: resolve its name to an absolute full path name such
+ # that the analysis tools can simply accept it as input.
+ #
+ if(NOT list_length_before_append EQUAL list_length_after_append)
+ gp_resolve_item("${target}" "${item}" "${exepath}" "${dirs}" resolved_item "${rpaths}")
+ set(unseen_prereqs ${unseen_prereqs} "${resolved_item}")
+ endif()
+ endif()
+ endif()
+ else()
+ if(verbose)
+ message(STATUS "ignoring non-matching line: '${candidate}'")
+ endif()
+ endif()
+ endforeach()
+
+ list(LENGTH ${prerequisites_var} prerequisites_var_length)
+ if(prerequisites_var_length GREATER 0)
+ list(SORT ${prerequisites_var})
+ endif()
+ if(${recurse})
+ set(more_inputs ${unseen_prereqs})
+ foreach(input ${more_inputs})
+ get_prerequisites("${input}" ${prerequisites_var} ${exclude_system} ${recurse} "${exepath}" "${dirs}" "${rpaths}")
+ endforeach()
+ endif()
+
+ set(${prerequisites_var} ${${prerequisites_var}} PARENT_SCOPE)
+endfunction()
+
+
+function(list_prerequisites target)
+ if("${ARGV1}" STREQUAL "")
+ set(all 1)
+ else()
+ set(all "${ARGV1}")
+ endif()
+
+ if("${ARGV2}" STREQUAL "")
+ set(exclude_system 0)
+ else()
+ set(exclude_system "${ARGV2}")
+ endif()
+
+ if("${ARGV3}" STREQUAL "")
+ set(verbose 0)
+ else()
+ set(verbose "${ARGV3}")
+ endif()
+
+ set(count 0)
+ set(count_str "")
+ set(print_count "${verbose}")
+ set(print_prerequisite_type "${verbose}")
+ set(print_target "${verbose}")
+ set(type_str "")
+
+ get_filename_component(exepath "${target}" PATH)
+
+ set(prereqs "")
+ get_prerequisites("${target}" prereqs ${exclude_system} ${all} "${exepath}" "")
+
+ if(print_target)
+ message(STATUS "File '${target}' depends on:")
+ endif()
+
+ foreach(d ${prereqs})
+ math(EXPR count "${count} + 1")
+
+ if(print_count)
+ set(count_str "${count}. ")
+ endif()
+
+ if(print_prerequisite_type)
+ gp_file_type("${target}" "${d}" type)
+ set(type_str " (${type})")
+ endif()
+
+ message(STATUS "${count_str}${d}${type_str}")
+ endforeach()
+endfunction()
+
+
+function(list_prerequisites_by_glob glob_arg glob_exp)
+ message(STATUS "=============================================================================")
+ message(STATUS "List prerequisites of executables matching ${glob_arg} '${glob_exp}'")
+ message(STATUS "")
+ file(${glob_arg} file_list ${glob_exp})
+ foreach(f ${file_list})
+ is_file_executable("${f}" is_f_executable)
+ if(is_f_executable)
+ message(STATUS "=============================================================================")
+ list_prerequisites("${f}" ${ARGN})
+ message(STATUS "")
+ endif()
+ endforeach()
+endfunction()
diff --git a/Modules/ITKCompatibility.cmake b/Modules/ITKCompatibility.cmake
new file mode 100644
index 0000000000..ca2d69bfb3
--- /dev/null
+++ b/Modules/ITKCompatibility.cmake
@@ -0,0 +1,17 @@
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+# work around an old bug in ITK prior to verison 3.0
+set(TIFF_RIGHT_VERSION 1)
+
diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake
new file mode 100644
index 0000000000..5afb517d6f
--- /dev/null
+++ b/Modules/InstallRequiredSystemLibraries.cmake
@@ -0,0 +1,483 @@
+#.rst:
+# InstallRequiredSystemLibraries
+# ------------------------------
+#
+#
+#
+# By including this file, all library files listed in the variable
+# CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS will be installed with
+# install(PROGRAMS ...) into bin for WIN32 and lib for non-WIN32. If
+# CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP is set to TRUE before including
+# this file, then the INSTALL command is not called. The user can use
+# the variable CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS to use a custom install
+# command and install them however they want. If it is the MSVC
+# compiler, then the microsoft run time libraries will be found and
+# automatically added to the CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS, and
+# installed. If CMAKE_INSTALL_DEBUG_LIBRARIES is set and it is the MSVC
+# compiler, then the debug libraries are installed when available. If
+# CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY is set then only the debug
+# libraries are installed when both debug and release are available. If
+# CMAKE_INSTALL_MFC_LIBRARIES is set then the MFC run time libraries are
+# installed as well as the CRT run time libraries. If
+# CMAKE_INSTALL_OPENMP_LIBRARIES is set then the OpenMP run time libraries
+# are installed as well. If
+# CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION is set then the libraries are
+# installed to that directory rather than the default. If
+# CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS is NOT set, then this
+# file warns about required files that do not exist. You can set this
+# variable to ON before including this file to avoid the warning. For
+# example, the Visual Studio Express editions do not include the
+# redistributable files, so if you include this file on a machine with
+# only VS Express installed, you'll get the warning.
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+if(MSVC)
+ file(TO_CMAKE_PATH "$ENV{SYSTEMROOT}" SYSTEMROOT)
+
+ if(CMAKE_CL_64)
+ if(MSVC_VERSION GREATER 1599)
+ # VS 10 and later:
+ set(CMAKE_MSVC_ARCH x64)
+ else()
+ # VS 9 and earlier:
+ set(CMAKE_MSVC_ARCH amd64)
+ endif()
+ else()
+ set(CMAKE_MSVC_ARCH x86)
+ endif()
+
+ get_filename_component(devenv_dir "${CMAKE_MAKE_PROGRAM}" PATH)
+ get_filename_component(base_dir "${devenv_dir}/../.." ABSOLUTE)
+
+ if(MSVC70)
+ set(__install__libs
+ "${SYSTEMROOT}/system32/msvcp70.dll"
+ "${SYSTEMROOT}/system32/msvcr70.dll"
+ )
+ endif()
+
+ if(MSVC71)
+ set(__install__libs
+ "${SYSTEMROOT}/system32/msvcp71.dll"
+ "${SYSTEMROOT}/system32/msvcr71.dll"
+ )
+ endif()
+
+ if(MSVC80)
+ # Find the runtime library redistribution directory.
+ get_filename_component(msvc_install_dir
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0;InstallDir]" ABSOLUTE)
+ find_path(MSVC80_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC80.CRT/Microsoft.VC80.CRT.manifest
+ PATHS
+ "${msvc_install_dir}/../../VC/redist"
+ "${base_dir}/VC/redist"
+ )
+ mark_as_advanced(MSVC80_REDIST_DIR)
+ set(MSVC80_CRT_DIR "${MSVC80_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC80.CRT")
+
+ # Install the manifest that allows DLLs to be loaded from the
+ # directory containing the executable.
+ if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
+ set(__install__libs
+ "${MSVC80_CRT_DIR}/Microsoft.VC80.CRT.manifest"
+ "${MSVC80_CRT_DIR}/msvcm80.dll"
+ "${MSVC80_CRT_DIR}/msvcp80.dll"
+ "${MSVC80_CRT_DIR}/msvcr80.dll"
+ )
+ else()
+ set(__install__libs)
+ endif()
+
+ if(CMAKE_INSTALL_DEBUG_LIBRARIES)
+ set(MSVC80_CRT_DIR
+ "${MSVC80_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC80.DebugCRT")
+ set(__install__libs ${__install__libs}
+ "${MSVC80_CRT_DIR}/Microsoft.VC80.DebugCRT.manifest"
+ "${MSVC80_CRT_DIR}/msvcm80d.dll"
+ "${MSVC80_CRT_DIR}/msvcp80d.dll"
+ "${MSVC80_CRT_DIR}/msvcr80d.dll"
+ )
+ endif()
+ endif()
+
+ if(MSVC90)
+ # Find the runtime library redistribution directory.
+ get_filename_component(msvc_install_dir
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0;InstallDir]" ABSOLUTE)
+ get_filename_component(msvc_express_install_dir
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\9.0;InstallDir]" ABSOLUTE)
+ find_path(MSVC90_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest
+ PATHS
+ "${msvc_install_dir}/../../VC/redist"
+ "${msvc_express_install_dir}/../../VC/redist"
+ "${base_dir}/VC/redist"
+ )
+ mark_as_advanced(MSVC90_REDIST_DIR)
+ set(MSVC90_CRT_DIR "${MSVC90_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC90.CRT")
+
+ # Install the manifest that allows DLLs to be loaded from the
+ # directory containing the executable.
+ if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
+ set(__install__libs
+ "${MSVC90_CRT_DIR}/Microsoft.VC90.CRT.manifest"
+ "${MSVC90_CRT_DIR}/msvcm90.dll"
+ "${MSVC90_CRT_DIR}/msvcp90.dll"
+ "${MSVC90_CRT_DIR}/msvcr90.dll"
+ )
+ else()
+ set(__install__libs)
+ endif()
+
+ if(CMAKE_INSTALL_DEBUG_LIBRARIES)
+ set(MSVC90_CRT_DIR
+ "${MSVC90_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC90.DebugCRT")
+ set(__install__libs ${__install__libs}
+ "${MSVC90_CRT_DIR}/Microsoft.VC90.DebugCRT.manifest"
+ "${MSVC90_CRT_DIR}/msvcm90d.dll"
+ "${MSVC90_CRT_DIR}/msvcp90d.dll"
+ "${MSVC90_CRT_DIR}/msvcr90d.dll"
+ )
+ endif()
+ endif()
+
+ macro(MSVCRT_FILES_FOR_VERSION version)
+ set(v "${version}")
+
+ # Find the runtime library redistribution directory.
+ get_filename_component(msvc_install_dir
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\${v}.0;InstallDir]" ABSOLUTE)
+ find_path(MSVC${v}_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.CRT
+ PATHS
+ "${msvc_install_dir}/../../VC/redist"
+ "${base_dir}/VC/redist"
+ "$ENV{ProgramFiles}/Microsoft Visual Studio ${v}.0/VC/redist"
+ set(programfilesx86 "ProgramFiles(x86)")
+ "$ENV{${programfilesx86}}/Microsoft Visual Studio ${v}.0/VC/redist"
+ )
+ mark_as_advanced(MSVC${v}_REDIST_DIR)
+ set(MSVC${v}_CRT_DIR "${MSVC${v}_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.CRT")
+
+ if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
+ set(__install__libs
+ "${MSVC${v}_CRT_DIR}/msvcp${v}0.dll"
+ "${MSVC${v}_CRT_DIR}/msvcr${v}0.dll"
+ )
+ else()
+ set(__install__libs)
+ endif()
+
+ if(CMAKE_INSTALL_DEBUG_LIBRARIES)
+ set(MSVC${v}_CRT_DIR
+ "${MSVC${v}_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.DebugCRT")
+ set(__install__libs ${__install__libs}
+ "${MSVC${v}_CRT_DIR}/msvcp${v}0d.dll"
+ "${MSVC${v}_CRT_DIR}/msvcr${v}0d.dll"
+ )
+ endif()
+ endmacro()
+
+ if(MSVC10)
+ MSVCRT_FILES_FOR_VERSION(10)
+ endif()
+
+ if(MSVC11)
+ MSVCRT_FILES_FOR_VERSION(11)
+ endif()
+
+ if(MSVC12)
+ MSVCRT_FILES_FOR_VERSION(12)
+ endif()
+
+ if(MSVC14)
+ MSVCRT_FILES_FOR_VERSION(14)
+ endif()
+
+ if(CMAKE_INSTALL_MFC_LIBRARIES)
+ if(MSVC70)
+ set(__install__libs ${__install__libs}
+ "${SYSTEMROOT}/system32/mfc70.dll"
+ )
+ endif()
+
+ if(MSVC71)
+ set(__install__libs ${__install__libs}
+ "${SYSTEMROOT}/system32/mfc71.dll"
+ )
+ endif()
+
+ if(MSVC80)
+ if(CMAKE_INSTALL_DEBUG_LIBRARIES)
+ set(MSVC80_MFC_DIR
+ "${MSVC80_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC80.DebugMFC")
+ set(__install__libs ${__install__libs}
+ "${MSVC80_MFC_DIR}/Microsoft.VC80.DebugMFC.manifest"
+ "${MSVC80_MFC_DIR}/mfc80d.dll"
+ "${MSVC80_MFC_DIR}/mfc80ud.dll"
+ "${MSVC80_MFC_DIR}/mfcm80d.dll"
+ "${MSVC80_MFC_DIR}/mfcm80ud.dll"
+ )
+ endif()
+
+ set(MSVC80_MFC_DIR "${MSVC80_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC80.MFC")
+ # Install the manifest that allows DLLs to be loaded from the
+ # directory containing the executable.
+ if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
+ set(__install__libs ${__install__libs}
+ "${MSVC80_MFC_DIR}/Microsoft.VC80.MFC.manifest"
+ "${MSVC80_MFC_DIR}/mfc80.dll"
+ "${MSVC80_MFC_DIR}/mfc80u.dll"
+ "${MSVC80_MFC_DIR}/mfcm80.dll"
+ "${MSVC80_MFC_DIR}/mfcm80u.dll"
+ )
+ endif()
+
+ # include the language dll's for vs8 as well as the actuall dll's
+ set(MSVC80_MFCLOC_DIR "${MSVC80_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC80.MFCLOC")
+ # Install the manifest that allows DLLs to be loaded from the
+ # directory containing the executable.
+ set(__install__libs ${__install__libs}
+ "${MSVC80_MFCLOC_DIR}/Microsoft.VC80.MFCLOC.manifest"
+ "${MSVC80_MFCLOC_DIR}/mfc80chs.dll"
+ "${MSVC80_MFCLOC_DIR}/mfc80cht.dll"
+ "${MSVC80_MFCLOC_DIR}/mfc80enu.dll"
+ "${MSVC80_MFCLOC_DIR}/mfc80esp.dll"
+ "${MSVC80_MFCLOC_DIR}/mfc80deu.dll"
+ "${MSVC80_MFCLOC_DIR}/mfc80fra.dll"
+ "${MSVC80_MFCLOC_DIR}/mfc80ita.dll"
+ "${MSVC80_MFCLOC_DIR}/mfc80jpn.dll"
+ "${MSVC80_MFCLOC_DIR}/mfc80kor.dll"
+ )
+ endif()
+
+ if(MSVC90)
+ if(CMAKE_INSTALL_DEBUG_LIBRARIES)
+ set(MSVC90_MFC_DIR
+ "${MSVC90_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC90.DebugMFC")
+ set(__install__libs ${__install__libs}
+ "${MSVC90_MFC_DIR}/Microsoft.VC90.DebugMFC.manifest"
+ "${MSVC90_MFC_DIR}/mfc90d.dll"
+ "${MSVC90_MFC_DIR}/mfc90ud.dll"
+ "${MSVC90_MFC_DIR}/mfcm90d.dll"
+ "${MSVC90_MFC_DIR}/mfcm90ud.dll"
+ )
+ endif()
+
+ set(MSVC90_MFC_DIR "${MSVC90_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC90.MFC")
+ # Install the manifest that allows DLLs to be loaded from the
+ # directory containing the executable.
+ if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
+ set(__install__libs ${__install__libs}
+ "${MSVC90_MFC_DIR}/Microsoft.VC90.MFC.manifest"
+ "${MSVC90_MFC_DIR}/mfc90.dll"
+ "${MSVC90_MFC_DIR}/mfc90u.dll"
+ "${MSVC90_MFC_DIR}/mfcm90.dll"
+ "${MSVC90_MFC_DIR}/mfcm90u.dll"
+ )
+ endif()
+
+ # include the language dll's for vs9 as well as the actuall dll's
+ set(MSVC90_MFCLOC_DIR "${MSVC90_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC90.MFCLOC")
+ # Install the manifest that allows DLLs to be loaded from the
+ # directory containing the executable.
+ set(__install__libs ${__install__libs}
+ "${MSVC90_MFCLOC_DIR}/Microsoft.VC90.MFCLOC.manifest"
+ "${MSVC90_MFCLOC_DIR}/mfc90chs.dll"
+ "${MSVC90_MFCLOC_DIR}/mfc90cht.dll"
+ "${MSVC90_MFCLOC_DIR}/mfc90enu.dll"
+ "${MSVC90_MFCLOC_DIR}/mfc90esp.dll"
+ "${MSVC90_MFCLOC_DIR}/mfc90deu.dll"
+ "${MSVC90_MFCLOC_DIR}/mfc90fra.dll"
+ "${MSVC90_MFCLOC_DIR}/mfc90ita.dll"
+ "${MSVC90_MFCLOC_DIR}/mfc90jpn.dll"
+ "${MSVC90_MFCLOC_DIR}/mfc90kor.dll"
+ )
+ endif()
+
+ macro(MFC_FILES_FOR_VERSION version)
+ set(v "${version}")
+
+ # Multi-Byte Character Set versions of MFC are available as optional
+ # addon since Visual Studio 12. So for version 12 or higher, check
+ # whether they are available and exclude them if they are not.
+ if("${v}" LESS 12 OR EXISTS "${MSVC${v}_MFC_DIR}/mfc${v}0d.dll")
+ set(mbcs ON)
+ else()
+ set(mbcs OFF)
+ endif()
+
+ if(CMAKE_INSTALL_DEBUG_LIBRARIES)
+ set(MSVC${v}_MFC_DIR
+ "${MSVC${v}_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.DebugMFC")
+ set(__install__libs ${__install__libs}
+ "${MSVC${v}_MFC_DIR}/mfc${v}0ud.dll"
+ "${MSVC${v}_MFC_DIR}/mfcm${v}0ud.dll"
+ )
+ if(mbcs)
+ set(__install__libs ${__install__libs}
+ "${MSVC${v}_MFC_DIR}/mfc${v}0d.dll"
+ "${MSVC${v}_MFC_DIR}/mfcm${v}0d.dll"
+ )
+ endif()
+ endif()
+
+ set(MSVC${v}_MFC_DIR "${MSVC${v}_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.MFC")
+ if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
+ set(__install__libs ${__install__libs}
+ "${MSVC${v}_MFC_DIR}/mfc${v}0u.dll"
+ "${MSVC${v}_MFC_DIR}/mfcm${v}0u.dll"
+ )
+ if(mbcs)
+ set(__install__libs ${__install__libs}
+ "${MSVC${v}_MFC_DIR}/mfc${v}0.dll"
+ "${MSVC${v}_MFC_DIR}/mfcm${v}0.dll"
+ )
+ endif()
+ endif()
+
+ # include the language dll's as well as the actuall dll's
+ set(MSVC${v}_MFCLOC_DIR "${MSVC${v}_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.MFCLOC")
+ set(__install__libs ${__install__libs}
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0chs.dll"
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0cht.dll"
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0deu.dll"
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0enu.dll"
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0esn.dll"
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0fra.dll"
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0ita.dll"
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0jpn.dll"
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0kor.dll"
+ "${MSVC${v}_MFCLOC_DIR}/mfc${v}0rus.dll"
+ )
+ endmacro()
+
+ if(MSVC10)
+ MFC_FILES_FOR_VERSION(10)
+ endif()
+
+ if(MSVC11)
+ MFC_FILES_FOR_VERSION(11)
+ endif()
+
+ if(MSVC12)
+ MFC_FILES_FOR_VERSION(12)
+ endif()
+
+ if(MSVC14)
+ MFC_FILES_FOR_VERSION(14)
+ endif()
+ endif()
+
+ # MSVC 8 was the first version with OpenMP
+ # Furthermore, there is no debug version of this
+ if(CMAKE_INSTALL_OPENMP_LIBRARIES)
+ macro(OPENMP_FILES_FOR_VERSION version_a version_b)
+ set(va "${version_a}")
+ set(vb "${version_b}")
+ set(MSVC${va}_OPENMP_DIR "${MSVC${va}_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vb}.OPENMP")
+
+ if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
+ set(__install__libs ${__install__libs}
+ "${MSVC${va}_OPENMP_DIR}/vcomp${vb}.dll")
+ endif()
+ endmacro()
+
+ if(MSVC80)
+ OPENMP_FILES_FOR_VERSION(80 80)
+ endif()
+ if(MSVC90)
+ OPENMP_FILES_FOR_VERSION(90 90)
+ endif()
+ if(MSVC10)
+ OPENMP_FILES_FOR_VERSION(10 100)
+ endif()
+ if(MSVC11)
+ OPENMP_FILES_FOR_VERSION(11 110)
+ endif()
+ if(MSVC12)
+ OPENMP_FILES_FOR_VERSION(12 120)
+ endif()
+ if(MSVC14)
+ OPENMP_FILES_FOR_VERSION(14 140)
+ endif()
+ endif()
+
+ foreach(lib
+ ${__install__libs}
+ )
+ if(EXISTS ${lib})
+ set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS
+ ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} ${lib})
+ else()
+ if(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
+ message(WARNING "system runtime library file does not exist: '${lib}'")
+ # This warning indicates an incomplete Visual Studio installation
+ # or a bug somewhere above here in this file.
+ # If you would like to avoid this warning, fix the real problem, or
+ # set CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS before including
+ # this file.
+ endif()
+ endif()
+ endforeach()
+endif()
+
+if(WATCOM)
+ get_filename_component( CompilerPath ${CMAKE_C_COMPILER} PATH )
+ if(CMAKE_C_COMPILER_VERSION)
+ set(_compiler_version ${CMAKE_C_COMPILER_VERSION})
+ else()
+ set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION})
+ endif()
+ string(REGEX MATCHALL "[0-9]+" _watcom_version_list "${_compiler_version}")
+ list(GET _watcom_version_list 0 _watcom_major)
+ list(GET _watcom_version_list 1 _watcom_minor)
+ set( __install__libs
+ ${CompilerPath}/clbr${_watcom_major}${_watcom_minor}.dll
+ ${CompilerPath}/mt7r${_watcom_major}${_watcom_minor}.dll
+ ${CompilerPath}/plbr${_watcom_major}${_watcom_minor}.dll )
+ foreach(lib
+ ${__install__libs}
+ )
+ if(EXISTS ${lib})
+ set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS
+ ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} ${lib})
+ else()
+ if(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
+ message(WARNING "system runtime library file does not exist: '${lib}'")
+ # This warning indicates an incomplete Watcom installation
+ # or a bug somewhere above here in this file.
+ # If you would like to avoid this warning, fix the real problem, or
+ # set CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS before including
+ # this file.
+ endif()
+ endif()
+ endforeach()
+endif()
+
+
+# Include system runtime libraries in the installation if any are
+# specified by CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS.
+if(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
+ if(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP)
+ if(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION)
+ if(WIN32)
+ set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION bin)
+ else()
+ set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION lib)
+ endif()
+ endif()
+ install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
+ DESTINATION ${CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION})
+ endif()
+endif()
diff --git a/Modules/IntelVSImplicitPath/CMakeLists.txt b/Modules/IntelVSImplicitPath/CMakeLists.txt
new file mode 100644
index 0000000000..d115704474
--- /dev/null
+++ b/Modules/IntelVSImplicitPath/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION ${CMAKE_VERSION})
+project(IntelFortranImplicit Fortran)
+add_custom_command(
+ OUTPUT output.cmake
+ COMMAND ${CMAKE_COMMAND} -P ${IntelFortranImplicit_SOURCE_DIR}/detect.cmake
+ )
+add_library(FortranLib hello.f output.cmake)
diff --git a/Modules/IntelVSImplicitPath/detect.cmake b/Modules/IntelVSImplicitPath/detect.cmake
new file mode 100644
index 0000000000..20753bef49
--- /dev/null
+++ b/Modules/IntelVSImplicitPath/detect.cmake
@@ -0,0 +1,9 @@
+# look at each path and try to find ifconsol.lib
+set(LIB "$ENV{LIB}")
+foreach(dir ${LIB})
+ file(TO_CMAKE_PATH "${dir}" dir)
+ if(EXISTS "${dir}/ifconsol.lib")
+ file(WRITE output.cmake "list(APPEND implicit_dirs \"${dir}\")\n")
+ break()
+ endif()
+endforeach()
diff --git a/Modules/IntelVSImplicitPath/hello.f b/Modules/IntelVSImplicitPath/hello.f
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Modules/IntelVSImplicitPath/hello.f
diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake
new file mode 100644
index 0000000000..abd9a2636c
--- /dev/null
+++ b/Modules/Internal/FeatureTesting.cmake
@@ -0,0 +1,60 @@
+
+macro(record_compiler_features lang compile_flags feature_list)
+ include("${CMAKE_ROOT}/Modules/Compiler/${CMAKE_${lang}_COMPILER_ID}-${lang}-FeatureTests.cmake" OPTIONAL)
+
+ string(TOLOWER ${lang} lang_lc)
+ file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin")
+ file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" "
+ const char features[] = {\"\"\n")
+
+ get_property(known_features GLOBAL PROPERTY CMAKE_${lang}_KNOWN_FEATURES)
+
+ foreach(feature ${known_features})
+ if (_cmake_feature_test_${feature})
+ if (${_cmake_feature_test_${feature}} STREQUAL 1)
+ set(_feature_condition "\"1\" ")
+ else()
+ set(_feature_condition "#if ${_cmake_feature_test_${feature}}\n\"1\"\n#else\n\"0\"\n#endif\n")
+ endif()
+ file(APPEND "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" "\"${lang}_FEATURE:\"\n${_feature_condition}\"${feature}\\n\"\n")
+ endif()
+ endforeach()
+ file(APPEND "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}"
+ "\n};\n\nint main(int argc, char** argv) { (void)argv; return features[argc]; }\n")
+
+ try_compile(CMAKE_${lang}_FEATURE_TEST
+ ${CMAKE_BINARY_DIR} "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}"
+ COMPILE_DEFINITIONS "${compile_flags}"
+ OUTPUT_VARIABLE _output
+ COPY_FILE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin"
+ COPY_FILE_ERROR _copy_error
+ )
+ if(CMAKE_${lang}_FEATURE_TEST AND NOT _copy_error)
+ set(_result 0)
+ else()
+ set(_result 255)
+ endif()
+ unset(CMAKE_${lang}_FEATURE_TEST CACHE)
+
+ if (_result EQUAL 0)
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "\n\nDetecting ${lang} [${compile_flags}] compiler features compiled with the following output:\n${_output}\n\n")
+ if(EXISTS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin")
+ file(STRINGS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin"
+ features REGEX "${lang}_FEATURE:.*")
+ foreach(info ${features})
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ " Feature record: ${info}\n")
+ string(REPLACE "${lang}_FEATURE:" "" info ${info})
+ string(SUBSTRING ${info} 0 1 has_feature)
+ if(has_feature)
+ string(REGEX REPLACE "^1" "" feature ${info})
+ list(APPEND ${feature_list} ${feature})
+ endif()
+ endforeach()
+ endif()
+ else()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Detecting ${lang} [${compile_flags}] compiler features failed to compile with the following output:\n${_output}\n${_copy_error}\n\n")
+ endif()
+endmacro()
diff --git a/Modules/KDE3Macros.cmake b/Modules/KDE3Macros.cmake
new file mode 100644
index 0000000000..07864f5d87
--- /dev/null
+++ b/Modules/KDE3Macros.cmake
@@ -0,0 +1,410 @@
+#
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# See FindKDE3.cmake for documentation.
+#
+# this file contains the following macros:
+# KDE3_ADD_DCOP_SKELS
+# KDE3_ADD_DCOP_STUBS
+# KDE3_ADD_MOC_FILES
+# KDE3_ADD_UI_FILES
+# KDE3_ADD_KCFG_FILES
+# KDE3_AUTOMOC
+# KDE3_INSTALL_LIBTOOL_FILE
+# KDE3_CREATE_FINAL_FILE
+# KDE3_ADD_KPART
+# KDE3_ADD_KDEINIT_EXECUTABLE
+# KDE3_ADD_EXECUTABLE
+
+
+#neundorf@kde.org
+
+include(AddFileDependencies)
+
+#create the kidl and skeletion file for dcop stuff
+#usage: KDE_ADD_COP_SKELS(foo_SRCS ${dcop_headers})
+macro(KDE3_ADD_DCOP_SKELS _sources)
+ foreach (_current_FILE ${ARGN})
+
+ get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
+ get_filename_component(_basename ${_tmp_FILE} NAME_WE)
+
+ set(_skel ${CMAKE_CURRENT_BINARY_DIR}/${_basename}_skel.cpp)
+ set(_kidl ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.kidl)
+
+ if (NOT HAVE_${_basename}_KIDL_RULE)
+ set(HAVE_${_basename}_KIDL_RULE ON)
+
+ add_custom_command(OUTPUT ${_kidl}
+ COMMAND ${KDE3_DCOPIDL_EXECUTABLE}
+ ARGS ${_tmp_FILE} > ${_kidl}
+ DEPENDS ${_tmp_FILE}
+ )
+
+ endif ()
+
+ if (NOT HAVE_${_basename}_SKEL_RULE)
+ set(HAVE_${_basename}_SKEL_RULE ON)
+
+ add_custom_command(OUTPUT ${_skel}
+ COMMAND ${KDE3_DCOPIDL2CPP_EXECUTABLE}
+ ARGS --c++-suffix cpp --no-signals --no-stub ${_kidl}
+ DEPENDS ${_kidl}
+ )
+
+ endif ()
+
+ set(${_sources} ${${_sources}} ${_skel})
+
+ endforeach ()
+
+endmacro()
+
+
+macro(KDE3_ADD_DCOP_STUBS _sources)
+ foreach (_current_FILE ${ARGN})
+
+ get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
+
+ get_filename_component(_basename ${_tmp_FILE} NAME_WE)
+
+ set(_stub_CPP ${CMAKE_CURRENT_BINARY_DIR}/${_basename}_stub.cpp)
+ set(_kidl ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.kidl)
+
+ if (NOT HAVE_${_basename}_KIDL_RULE)
+ set(HAVE_${_basename}_KIDL_RULE ON)
+
+
+ add_custom_command(OUTPUT ${_kidl}
+ COMMAND ${KDE3_DCOPIDL_EXECUTABLE}
+ ARGS ${_tmp_FILE} > ${_kidl}
+ DEPENDS ${_tmp_FILE}
+ )
+
+ endif ()
+
+
+ if (NOT HAVE_${_basename}_STUB_RULE)
+ set(HAVE_${_basename}_STUB_RULE ON)
+
+ add_custom_command(OUTPUT ${_stub_CPP}
+ COMMAND ${KDE3_DCOPIDL2CPP_EXECUTABLE}
+ ARGS --c++-suffix cpp --no-signals --no-skel ${_kidl}
+ DEPENDS ${_kidl}
+ )
+
+ endif ()
+
+ set(${_sources} ${${_sources}} ${_stub_CPP})
+
+ endforeach ()
+
+endmacro()
+
+
+macro(KDE3_ADD_KCFG_FILES _sources)
+ foreach (_current_FILE ${ARGN})
+
+ get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
+
+ get_filename_component(_basename ${_tmp_FILE} NAME_WE)
+
+ file(READ ${_tmp_FILE} _contents)
+ string(REGEX REPLACE "^(.*\n)?File=([^\n]+)\n.*$" "\\2" _kcfg_FILE "${_contents}")
+
+ set(_src_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp)
+ set(_header_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h)
+
+ add_custom_command(OUTPUT ${_src_FILE}
+ COMMAND ${KDE3_KCFGC_EXECUTABLE}
+ ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${_kcfg_FILE} ${_tmp_FILE}
+ DEPENDS ${_tmp_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${_kcfg_FILE} )
+
+ set(${_sources} ${${_sources}} ${_src_FILE})
+
+ endforeach ()
+
+endmacro()
+
+
+#create the moc files and add them to the list of sources
+#usage: KDE_ADD_MOC_FILES(foo_SRCS ${moc_headers})
+macro(KDE3_ADD_MOC_FILES _sources)
+ foreach (_current_FILE ${ARGN})
+
+ get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
+
+ get_filename_component(_basename ${_tmp_FILE} NAME_WE)
+ set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc.cpp)
+
+ add_custom_command(OUTPUT ${_moc}
+ COMMAND ${QT_MOC_EXECUTABLE}
+ ARGS ${_tmp_FILE} -o ${_moc}
+ DEPENDS ${_tmp_FILE}
+ )
+
+ set(${_sources} ${${_sources}} ${_moc})
+
+ endforeach ()
+endmacro()
+
+
+get_filename_component( KDE3_MODULE_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
+
+#create the implementation files from the ui files and add them to the list of sources
+#usage: KDE_ADD_UI_FILES(foo_SRCS ${ui_files})
+macro(KDE3_ADD_UI_FILES _sources )
+ foreach (_current_FILE ${ARGN})
+
+ get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
+
+ get_filename_component(_basename ${_tmp_FILE} NAME_WE)
+ set(_header ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h)
+ set(_src ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp)
+ set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc.cpp)
+
+ add_custom_command(OUTPUT ${_header}
+ COMMAND ${QT_UIC_EXECUTABLE}
+ ARGS -L ${KDE3_LIB_DIR}/kde3/plugins/designer -nounload -o ${_header} ${CMAKE_CURRENT_SOURCE_DIR}/${_current_FILE}
+ DEPENDS ${_tmp_FILE}
+ )
+
+ add_custom_command(OUTPUT ${_src}
+ COMMAND ${CMAKE_COMMAND}
+ ARGS
+ -DKDE_UIC_PLUGIN_DIR:FILEPATH=${KDE3_LIB_DIR}/kde3/plugins/designer
+ -DKDE_UIC_EXECUTABLE:FILEPATH=${QT_UIC_EXECUTABLE}
+ -DKDE_UIC_FILE:FILEPATH=${_tmp_FILE}
+ -DKDE_UIC_CPP_FILE:FILEPATH=${_src}
+ -DKDE_UIC_H_FILE:FILEPATH=${_header}
+ -P ${KDE3_MODULE_DIR}/kde3uic.cmake
+ DEPENDS ${_header}
+ )
+
+ add_custom_command(OUTPUT ${_moc}
+ COMMAND ${QT_MOC_EXECUTABLE}
+ ARGS ${_header} -o ${_moc}
+ DEPENDS ${_header}
+ )
+
+ set(${_sources} ${${_sources}} ${_src} ${_moc} )
+
+ endforeach ()
+endmacro()
+
+
+macro(KDE3_AUTOMOC)
+ set(_matching_FILES )
+ foreach (_current_FILE ${ARGN})
+
+ get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
+
+ # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
+ # here. this is required to make bouic work correctly:
+ # we need to add generated .cpp files to the sources (to compile them),
+ # but we cannot let automoc handle them, as the .cpp files don't exist yet when
+ # cmake is run for the very first time on them -> however the .cpp files might
+ # exist at a later run. at that time we need to skip them, so that we don't add two
+ # different rules for the same moc file
+ get_source_file_property(_skip ${_abs_FILE} SKIP_AUTOMOC)
+
+ if (EXISTS ${_abs_FILE} AND NOT _skip)
+
+ file(STRINGS ${_abs_FILE} _match REGEX "#include +[^ ]+\\.moc[\">]")
+
+ get_filename_component(_abs_PATH ${_abs_FILE} PATH)
+
+ foreach (_current_MOC_INC IN LISTS _match)
+ string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
+
+ get_filename_component(_basename ${_current_MOC} NAME_WE)
+# set(_header ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.h)
+ set(_header ${_abs_PATH}/${_basename}.h)
+ set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
+
+ add_custom_command(OUTPUT ${_moc}
+ COMMAND ${QT_MOC_EXECUTABLE}
+ ARGS ${_header} -o ${_moc}
+ DEPENDS ${_header}
+ )
+
+ ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
+
+ endforeach ()
+ unset(_match)
+ unset(_header)
+ unset(_moc)
+ endif ()
+ endforeach ()
+endmacro()
+
+# only used internally by KDE3_INSTALL_ICONS
+macro (_KDE3_ADD_ICON_INSTALL_RULE _install_SCRIPT _install_PATH _group _orig_NAME _install_NAME)
+
+ # if the string doesn't match the pattern, the result is the full string, so all three have the same content
+ if (NOT ${_group} STREQUAL ${_install_NAME} )
+ set(_icon_GROUP "actions")
+
+ if (${_group} STREQUAL "mime")
+ set(_icon_GROUP "mimetypes")
+ endif ()
+
+ if (${_group} STREQUAL "filesys")
+ set(_icon_GROUP "filesystems")
+ endif ()
+
+ if (${_group} STREQUAL "device")
+ set(_icon_GROUP "devices")
+ endif ()
+
+ if (${_group} STREQUAL "app")
+ set(_icon_GROUP "apps")
+ endif ()
+
+ if (${_group} STREQUAL "action")
+ set(_icon_GROUP "actions")
+ endif ()
+
+# message(STATUS "icon: ${_current_ICON} size: ${_size} group: ${_group} name: ${_name}" )
+ install(FILES ${_orig_NAME} DESTINATION ${_install_PATH}/${_icon_GROUP}/ RENAME ${_install_NAME} )
+ endif ()
+
+endmacro ()
+
+
+macro (KDE3_INSTALL_ICONS _theme )
+ set(_defaultpath "${CMAKE_INSTALL_PREFIX}/share/icons")
+ # first the png icons
+ file(GLOB _icons *.png)
+ foreach (_current_ICON ${_icons} )
+ string(REGEX REPLACE "^.*/[a-zA-Z]+([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" "\\1" _size "${_current_ICON}")
+ string(REGEX REPLACE "^.*/[a-zA-Z]+([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" "\\2" _group "${_current_ICON}")
+ string(REGEX REPLACE "^.*/[a-zA-Z]+([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" "\\3" _name "${_current_ICON}")
+ _KDE3_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
+ ${_defaultpath}/${_theme}/${_size}x${_size}
+ ${_group} ${_current_ICON} ${_name})
+ endforeach ()
+
+ # and now the svg icons
+ file(GLOB _icons *.svgz)
+ foreach (_current_ICON ${_icons} )
+ string(REGEX REPLACE "^.*/crsc\\-([a-z]+)\\-(.+\\.svgz)$" "\\1" _group "${_current_ICON}")
+ string(REGEX REPLACE "^.*/crsc\\-([a-z]+)\\-(.+\\.svgz)$" "\\2" _name "${_current_ICON}")
+ _KDE3_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
+ ${_defaultpath}/${_theme}/scalable
+ ${_group} ${_current_ICON} ${_name})
+ endforeach ()
+
+endmacro ()
+
+macro(KDE3_INSTALL_LIBTOOL_FILE _target)
+ get_target_property(_target_location ${_target} LOCATION)
+
+ get_filename_component(_laname ${_target_location} NAME_WE)
+ get_filename_component(_soname ${_target_location} NAME)
+ set(_laname ${CMAKE_CURRENT_BINARY_DIR}/${_laname}.la)
+
+ file(WRITE ${_laname} "# ${_laname} - a libtool library file, generated by cmake \n")
+ file(APPEND ${_laname} "# The name that we can dlopen(3).\n")
+ file(APPEND ${_laname} "dlname='${_soname}'\n")
+ file(APPEND ${_laname} "# Names of this library\n")
+ if(CYGWIN)
+ file(APPEND ${_laname} "library_names='${_soname}'\n")
+ else()
+ file(APPEND ${_laname} "library_names='${_soname} ${_soname} ${_soname}'\n")
+ endif()
+ file(APPEND ${_laname} "# The name of the static archive\n")
+ file(APPEND ${_laname} "old_library=''\n")
+ file(APPEND ${_laname} "# Libraries that this one depends upon.\n")
+ file(APPEND ${_laname} "dependency_libs=''\n")
+# file(APPEND ${_laname} "dependency_libs='${${_target}_LIB_DEPENDS}'\n")
+ file(APPEND ${_laname} "# Version information.\ncurrent=0\nage=0\nrevision=0\n")
+ file(APPEND ${_laname} "# Is this an already installed library?\ninstalled=yes\n")
+ file(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\nshouldnotlink=yes\n")
+ file(APPEND ${_laname} "# Files to dlopen/dlpreopen\ndlopen=''\ndlpreopen=''\n")
+ file(APPEND ${_laname} "# Directory that this library needs to be installed in:\n")
+ file(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}/lib/kde3'\n")
+
+ install_files(${KDE3_LIBTOOL_DIR} FILES ${_laname})
+endmacro()
+
+
+macro(KDE3_CREATE_FINAL_FILE _filename)
+ file(WRITE ${_filename} "//autogenerated file\n")
+ foreach (_current_FILE ${ARGN})
+ file(APPEND ${_filename} "#include \"${_current_FILE}\"\n")
+ endforeach ()
+
+endmacro()
+
+
+# option(KDE3_ENABLE_FINAL "Enable final all-in-one compilation")
+option(KDE3_BUILD_TESTS "Build the tests")
+
+
+macro(KDE3_ADD_KPART _target_NAME _with_PREFIX)
+#is the first argument is "WITH_PREFIX" then keep the standard "lib" prefix, otherwise SET the prefix empty
+ if (${_with_PREFIX} STREQUAL "WITH_PREFIX")
+ set(_first_SRC)
+ else ()
+ set(_first_SRC ${_with_PREFIX})
+ endif ()
+
+# if (KDE3_ENABLE_FINAL)
+# KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${_first_SRC} ${ARGN})
+# add_library(${_target_NAME} MODULE ${_target_NAME}_final.cpp)
+# else ()
+ add_library(${_target_NAME} MODULE ${_first_SRC} ${ARGN})
+# endif ()
+
+ if(_first_SRC)
+ set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
+ endif()
+
+ KDE3_INSTALL_LIBTOOL_FILE(${_target_NAME})
+
+endmacro()
+
+
+macro(KDE3_ADD_KDEINIT_EXECUTABLE _target_NAME )
+
+# if (KDE3_ENABLE_FINAL)
+# KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${ARGN})
+# add_library(kdeinit_${_target_NAME} SHARED ${_target_NAME}_final.cpp)
+# else ()
+ add_library(kdeinit_${_target_NAME} SHARED ${ARGN} )
+# endif ()
+
+ configure_file(${KDE3_MODULE_DIR}/kde3init_dummy.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_dummy.cpp)
+
+ add_executable( ${_target_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_dummy.cpp )
+ target_link_libraries( ${_target_NAME} kdeinit_${_target_NAME} )
+
+endmacro()
+
+
+macro(KDE3_ADD_EXECUTABLE _target_NAME )
+
+# if (KDE3_ENABLE_FINAL)
+# KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${ARGN})
+# add_executable(${_target_NAME} ${_target_NAME}_final.cpp)
+# else ()
+ add_executable(${_target_NAME} ${ARGN} )
+# endif ()
+
+endmacro()
+
+
diff --git a/Modules/MacOSXBundleInfo.plist.in b/Modules/MacOSXBundleInfo.plist.in
new file mode 100644
index 0000000000..a466dc7c4e
--- /dev/null
+++ b/Modules/MacOSXBundleInfo.plist.in
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
+ <key>CFBundleGetInfoString</key>
+ <string>${MACOSX_BUNDLE_INFO_STRING}</string>
+ <key>CFBundleIconFile</key>
+ <string>${MACOSX_BUNDLE_ICON_FILE}</string>
+ <key>CFBundleIdentifier</key>
+ <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleLongVersionString</key>
+ <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
+ <key>CFBundleName</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
+ <key>CSResourcesFileMapped</key>
+ <true/>
+ <key>LSRequiresCarbon</key>
+ <true/>
+ <key>NSHumanReadableCopyright</key>
+ <string>${MACOSX_BUNDLE_COPYRIGHT}</string>
+</dict>
+</plist>
diff --git a/Modules/MacOSXFrameworkInfo.plist.in b/Modules/MacOSXFrameworkInfo.plist.in
new file mode 100644
index 0000000000..18eaef2f7d
--- /dev/null
+++ b/Modules/MacOSXFrameworkInfo.plist.in
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${MACOSX_FRAMEWORK_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string>${MACOSX_FRAMEWORK_ICON_FILE}</string>
+ <key>CFBundleIdentifier</key>
+ <string>${MACOSX_FRAMEWORK_IDENTIFIER}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>${MACOSX_FRAMEWORK_BUNDLE_VERSION}</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${MACOSX_FRAMEWORK_SHORT_VERSION_STRING}</string>
+ <key>CSResourcesFileMapped</key>
+ <true/>
+</dict>
+</plist>
diff --git a/Modules/MacroAddFileDependencies.cmake b/Modules/MacroAddFileDependencies.cmake
new file mode 100644
index 0000000000..38df1d3a9a
--- /dev/null
+++ b/Modules/MacroAddFileDependencies.cmake
@@ -0,0 +1,39 @@
+#.rst:
+# MacroAddFileDependencies
+# ------------------------
+#
+# MACRO_ADD_FILE_DEPENDENCIES(<_file> depend_files...)
+#
+# Using the macro MACRO_ADD_FILE_DEPENDENCIES() is discouraged. There
+# are usually better ways to specify the correct dependencies.
+#
+# MACRO_ADD_FILE_DEPENDENCIES(<_file> depend_files...) is just a
+# convenience wrapper around the OBJECT_DEPENDS source file property.
+# You can just use set_property(SOURCE <file> APPEND PROPERTY
+# OBJECT_DEPENDS depend_files) instead.
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+macro (MACRO_ADD_FILE_DEPENDENCIES _file)
+
+ get_source_file_property(_deps ${_file} OBJECT_DEPENDS)
+ if (_deps)
+ set(_deps ${_deps} ${ARGN})
+ else ()
+ set(_deps ${ARGN})
+ endif ()
+
+ set_source_files_properties(${_file} PROPERTIES OBJECT_DEPENDS "${_deps}")
+
+endmacro ()
diff --git a/Modules/NSIS.InstallOptions.ini.in b/Modules/NSIS.InstallOptions.ini.in
new file mode 100644
index 0000000000..d92d77959c
--- /dev/null
+++ b/Modules/NSIS.InstallOptions.ini.in
@@ -0,0 +1,46 @@
+[Settings]
+NumFields=5
+
+[Field 1]
+Type=label
+Text=By default @CPACK_PACKAGE_INSTALL_DIRECTORY@ does not add its directory to the system PATH.
+Left=0
+Right=-1
+Top=0
+Bottom=20
+
+[Field 2]
+Type=radiobutton
+Text=Do not add @CPACK_PACKAGE_NAME@ to the system PATH
+Left=0
+Right=-1
+Top=30
+Bottom=40
+State=1
+
+[Field 3]
+Type=radiobutton
+Text=Add @CPACK_PACKAGE_NAME@ to the system PATH for all users
+Left=0
+Right=-1
+Top=40
+Bottom=50
+State=0
+
+[Field 4]
+Type=radiobutton
+Text=Add @CPACK_PACKAGE_NAME@ to the system PATH for current user
+Left=0
+Right=-1
+Top=50
+Bottom=60
+State=0
+
+[Field 5]
+Type=CheckBox
+Text=Create @CPACK_PACKAGE_NAME@ Desktop Icon
+Left=0
+Right=-1
+Top=80
+Bottom=90
+State=0
diff --git a/Modules/NSIS.template.in b/Modules/NSIS.template.in
new file mode 100644
index 0000000000..76310af31a
--- /dev/null
+++ b/Modules/NSIS.template.in
@@ -0,0 +1,977 @@
+; CPack install script designed for a nmake build
+
+;--------------------------------
+; You must define these values
+
+ !define VERSION "@CPACK_PACKAGE_VERSION@"
+ !define PATCH "@CPACK_PACKAGE_VERSION_PATCH@"
+ !define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@"
+
+;--------------------------------
+;Variables
+
+ Var MUI_TEMP
+ Var STARTMENU_FOLDER
+ Var SV_ALLUSERS
+ Var START_MENU
+ Var DO_NOT_ADD_TO_PATH
+ Var ADD_TO_PATH_ALL_USERS
+ Var ADD_TO_PATH_CURRENT_USER
+ Var INSTALL_DESKTOP
+ Var IS_DEFAULT_INSTALLDIR
+;--------------------------------
+;Include Modern UI
+
+ !include "MUI.nsh"
+
+ ;Default installation folder
+ InstallDir "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
+
+;--------------------------------
+;General
+
+ ;Name and file
+ Name "@CPACK_NSIS_PACKAGE_NAME@"
+ OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@"
+
+ ;Set compression
+ SetCompressor @CPACK_NSIS_COMPRESSOR@
+
+ ;Require administrator access
+ RequestExecutionLevel admin
+
+@CPACK_NSIS_DEFINES@
+
+ !include Sections.nsh
+
+;--- Component support macros: ---
+; The code for the add/remove functionality is from:
+; http://nsis.sourceforge.net/Add/Remove_Functionality
+; It has been modified slightly and extended to provide
+; inter-component dependencies.
+Var AR_SecFlags
+Var AR_RegFlags
+@CPACK_NSIS_SECTION_SELECTED_VARS@
+
+; Loads the "selected" flag for the section named SecName into the
+; variable VarName.
+!macro LoadSectionSelectedIntoVar SecName VarName
+ SectionGetFlags ${${SecName}} $${VarName}
+ IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits
+!macroend
+
+; Loads the value of a variable... can we get around this?
+!macro LoadVar VarName
+ IntOp $R0 0 + $${VarName}
+!macroend
+
+; Sets the value of a variable
+!macro StoreVar VarName IntValue
+ IntOp $${VarName} 0 + ${IntValue}
+!macroend
+
+!macro InitSection SecName
+ ; This macro reads component installed flag from the registry and
+ ;changes checked state of the section on the components page.
+ ;Input: section index constant name specified in Section command.
+
+ ClearErrors
+ ;Reading component status from registry
+ ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" "Installed"
+ IfErrors "default_${SecName}"
+ ;Status will stay default if registry value not found
+ ;(component was never installed)
+ IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits
+ SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags
+ IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off
+ IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit
+
+ ; Note whether this component was installed before
+ !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags
+ IntOp $R0 $AR_RegFlags & $AR_RegFlags
+
+ ;Writing modified flags
+ SectionSetFlags ${${SecName}} $AR_SecFlags
+
+ "default_${SecName}:"
+ !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
+!macroend
+
+!macro FinishSection SecName
+ ; This macro reads section flag set by user and removes the section
+ ;if it is not selected.
+ ;Then it writes component installed flag to registry
+ ;Input: section index constant name specified in Section command.
+
+ SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags
+ ;Checking lowest bit:
+ IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED}
+ IntCmp $AR_SecFlags 1 "leave_${SecName}"
+ ;Section is not selected:
+ ;Calling Section uninstall macro and writing zero installed flag
+ !insertmacro "Remove_${${SecName}}"
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
+ "Installed" 0
+ Goto "exit_${SecName}"
+
+ "leave_${SecName}:"
+ ;Section is selected:
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
+ "Installed" 1
+
+ "exit_${SecName}:"
+!macroend
+
+!macro RemoveSection_CPack SecName
+ ; This macro is used to call section's Remove_... macro
+ ;from the uninstaller.
+ ;Input: section index constant name specified in Section command.
+
+ !insertmacro "Remove_${${SecName}}"
+!macroend
+
+; Determine whether the selection of SecName changed
+!macro MaybeSelectionChanged SecName
+ !insertmacro LoadVar ${SecName}_selected
+ SectionGetFlags ${${SecName}} $R1
+ IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits
+
+ ; See if the status has changed:
+ IntCmp $R0 $R1 "${SecName}_unchanged"
+ !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
+
+ IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected"
+ !insertmacro "Deselect_required_by_${SecName}"
+ goto "${SecName}_unchanged"
+
+ "${SecName}_was_selected:"
+ !insertmacro "Select_${SecName}_depends"
+
+ "${SecName}_unchanged:"
+!macroend
+;--- End of Add/Remove macros ---
+
+;--------------------------------
+;Interface Settings
+
+ !define MUI_HEADERIMAGE
+ !define MUI_ABORTWARNING
+
+;--------------------------------
+; path functions
+
+!verbose 3
+!include "WinMessages.NSH"
+!verbose 4
+
+;----------------------------------------
+; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
+;----------------------------------------
+!verbose 3
+!include "WinMessages.NSH"
+!verbose 4
+;====================================================
+; get_NT_environment
+; Returns: the selected environment
+; Output : head of the stack
+;====================================================
+!macro select_NT_profile UN
+Function ${UN}select_NT_profile
+ StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
+ DetailPrint "Selected environment for all users"
+ Push "all"
+ Return
+ environment_single:
+ DetailPrint "Selected environment for current user only."
+ Push "current"
+ Return
+FunctionEnd
+!macroend
+!insertmacro select_NT_profile ""
+!insertmacro select_NT_profile "un."
+;----------------------------------------------------
+!define NT_current_env 'HKCU "Environment"'
+!define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
+
+!ifndef WriteEnvStr_RegKey
+ !ifdef ALL_USERS
+ !define WriteEnvStr_RegKey \
+ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
+ !else
+ !define WriteEnvStr_RegKey 'HKCU "Environment"'
+ !endif
+!endif
+
+; AddToPath - Adds the given dir to the search path.
+; Input - head of the stack
+; Note - Win9x systems requires reboot
+
+Function AddToPath
+ Exch $0
+ Push $1
+ Push $2
+ Push $3
+
+ # don't add if the path doesn't exist
+ IfFileExists "$0\*.*" "" AddToPath_done
+
+ ReadEnvStr $1 PATH
+ ; if the path is too long for a NSIS variable NSIS will return a 0
+ ; length string. If we find that, then warn and skip any path
+ ; modification as it will trash the existing path.
+ StrLen $2 $1
+ IntCmp $2 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
+ CheckPathLength_ShowPathWarning:
+ Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long installer unable to modify PATH!"
+ Goto AddToPath_done
+ CheckPathLength_Done:
+ Push "$1;"
+ Push "$0;"
+ Call StrStr
+ Pop $2
+ StrCmp $2 "" "" AddToPath_done
+ Push "$1;"
+ Push "$0\;"
+ Call StrStr
+ Pop $2
+ StrCmp $2 "" "" AddToPath_done
+ GetFullPathName /SHORT $3 $0
+ Push "$1;"
+ Push "$3;"
+ Call StrStr
+ Pop $2
+ StrCmp $2 "" "" AddToPath_done
+ Push "$1;"
+ Push "$3\;"
+ Call StrStr
+ Pop $2
+ StrCmp $2 "" "" AddToPath_done
+
+ Call IsNT
+ Pop $1
+ StrCmp $1 1 AddToPath_NT
+ ; Not on NT
+ StrCpy $1 $WINDIR 2
+ FileOpen $1 "$1\autoexec.bat" a
+ FileSeek $1 -1 END
+ FileReadByte $1 $2
+ IntCmp $2 26 0 +2 +2 # DOS EOF
+ FileSeek $1 -1 END # write over EOF
+ FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
+ FileClose $1
+ SetRebootFlag true
+ Goto AddToPath_done
+
+ AddToPath_NT:
+ StrCmp $ADD_TO_PATH_ALL_USERS "1" ReadAllKey
+ ReadRegStr $1 ${NT_current_env} "PATH"
+ Goto DoTrim
+ ReadAllKey:
+ ReadRegStr $1 ${NT_all_env} "PATH"
+ DoTrim:
+ StrCmp $1 "" AddToPath_NTdoIt
+ Push $1
+ Call Trim
+ Pop $1
+ StrCpy $0 "$1;$0"
+ AddToPath_NTdoIt:
+ StrCmp $ADD_TO_PATH_ALL_USERS "1" WriteAllKey
+ WriteRegExpandStr ${NT_current_env} "PATH" $0
+ Goto DoSend
+ WriteAllKey:
+ WriteRegExpandStr ${NT_all_env} "PATH" $0
+ DoSend:
+ SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+
+ AddToPath_done:
+ Pop $3
+ Pop $2
+ Pop $1
+ Pop $0
+FunctionEnd
+
+
+; RemoveFromPath - Remove a given dir from the path
+; Input: head of the stack
+
+Function un.RemoveFromPath
+ Exch $0
+ Push $1
+ Push $2
+ Push $3
+ Push $4
+ Push $5
+ Push $6
+
+ IntFmt $6 "%c" 26 # DOS EOF
+
+ Call un.IsNT
+ Pop $1
+ StrCmp $1 1 unRemoveFromPath_NT
+ ; Not on NT
+ StrCpy $1 $WINDIR 2
+ FileOpen $1 "$1\autoexec.bat" r
+ GetTempFileName $4
+ FileOpen $2 $4 w
+ GetFullPathName /SHORT $0 $0
+ StrCpy $0 "SET PATH=%PATH%;$0"
+ Goto unRemoveFromPath_dosLoop
+
+ unRemoveFromPath_dosLoop:
+ FileRead $1 $3
+ StrCpy $5 $3 1 -1 # read last char
+ StrCmp $5 $6 0 +2 # if DOS EOF
+ StrCpy $3 $3 -1 # remove DOS EOF so we can compare
+ StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
+ StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
+ StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
+ StrCmp $3 "" unRemoveFromPath_dosLoopEnd
+ FileWrite $2 $3
+ Goto unRemoveFromPath_dosLoop
+ unRemoveFromPath_dosLoopRemoveLine:
+ SetRebootFlag true
+ Goto unRemoveFromPath_dosLoop
+
+ unRemoveFromPath_dosLoopEnd:
+ FileClose $2
+ FileClose $1
+ StrCpy $1 $WINDIR 2
+ Delete "$1\autoexec.bat"
+ CopyFiles /SILENT $4 "$1\autoexec.bat"
+ Delete $4
+ Goto unRemoveFromPath_done
+
+ unRemoveFromPath_NT:
+ StrCmp $ADD_TO_PATH_ALL_USERS "1" unReadAllKey
+ ReadRegStr $1 ${NT_current_env} "PATH"
+ Goto unDoTrim
+ unReadAllKey:
+ ReadRegStr $1 ${NT_all_env} "PATH"
+ unDoTrim:
+ StrCpy $5 $1 1 -1 # copy last char
+ StrCmp $5 ";" +2 # if last char != ;
+ StrCpy $1 "$1;" # append ;
+ Push $1
+ Push "$0;"
+ Call un.StrStr ; Find `$0;` in $1
+ Pop $2 ; pos of our dir
+ StrCmp $2 "" unRemoveFromPath_done
+ ; else, it is in path
+ # $0 - path to add
+ # $1 - path var
+ StrLen $3 "$0;"
+ StrLen $4 $2
+ StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
+ StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
+ StrCpy $3 $5$6
+
+ StrCpy $5 $3 1 -1 # copy last char
+ StrCmp $5 ";" 0 +2 # if last char == ;
+ StrCpy $3 $3 -1 # remove last char
+
+ StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey
+ WriteRegExpandStr ${NT_current_env} "PATH" $3
+ Goto unDoSend
+ unWriteAllKey:
+ WriteRegExpandStr ${NT_all_env} "PATH" $3
+ unDoSend:
+ SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+
+ unRemoveFromPath_done:
+ Pop $6
+ Pop $5
+ Pop $4
+ Pop $3
+ Pop $2
+ Pop $1
+ Pop $0
+FunctionEnd
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Uninstall sutff
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+###########################################
+# Utility Functions #
+###########################################
+
+;====================================================
+; IsNT - Returns 1 if the current system is NT, 0
+; otherwise.
+; Output: head of the stack
+;====================================================
+; IsNT
+; no input
+; output, top of the stack = 1 if NT or 0 if not
+;
+; Usage:
+; Call IsNT
+; Pop $R0
+; ($R0 at this point is 1 or 0)
+
+!macro IsNT un
+Function ${un}IsNT
+ Push $0
+ ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
+ StrCmp $0 "" 0 IsNT_yes
+ ; we are not NT.
+ Pop $0
+ Push 0
+ Return
+
+ IsNT_yes:
+ ; NT!!!
+ Pop $0
+ Push 1
+FunctionEnd
+!macroend
+!insertmacro IsNT ""
+!insertmacro IsNT "un."
+
+; StrStr
+; input, top of stack = string to search for
+; top of stack-1 = string to search in
+; output, top of stack (replaces with the portion of the string remaining)
+; modifies no other variables.
+;
+; Usage:
+; Push "this is a long ass string"
+; Push "ass"
+; Call StrStr
+; Pop $R0
+; ($R0 at this point is "ass string")
+
+!macro StrStr un
+Function ${un}StrStr
+Exch $R1 ; st=haystack,old$R1, $R1=needle
+ Exch ; st=old$R1,haystack
+ Exch $R2 ; st=old$R1,old$R2, $R2=haystack
+ Push $R3
+ Push $R4
+ Push $R5
+ StrLen $R3 $R1
+ StrCpy $R4 0
+ ; $R1=needle
+ ; $R2=haystack
+ ; $R3=len(needle)
+ ; $R4=cnt
+ ; $R5=tmp
+ loop:
+ StrCpy $R5 $R2 $R3 $R4
+ StrCmp $R5 $R1 done
+ StrCmp $R5 "" done
+ IntOp $R4 $R4 + 1
+ Goto loop
+done:
+ StrCpy $R1 $R2 "" $R4
+ Pop $R5
+ Pop $R4
+ Pop $R3
+ Pop $R2
+ Exch $R1
+FunctionEnd
+!macroend
+!insertmacro StrStr ""
+!insertmacro StrStr "un."
+
+Function Trim ; Added by Pelaca
+ Exch $R1
+ Push $R2
+Loop:
+ StrCpy $R2 "$R1" 1 -1
+ StrCmp "$R2" " " RTrim
+ StrCmp "$R2" "$\n" RTrim
+ StrCmp "$R2" "$\r" RTrim
+ StrCmp "$R2" ";" RTrim
+ GoTo Done
+RTrim:
+ StrCpy $R1 "$R1" -1
+ Goto Loop
+Done:
+ Pop $R2
+ Exch $R1
+FunctionEnd
+
+Function ConditionalAddToRegisty
+ Pop $0
+ Pop $1
+ StrCmp "$0" "" ConditionalAddToRegisty_EmptyString
+ WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" \
+ "$1" "$0"
+ ;MessageBox MB_OK "Set Registry: '$1' to '$0'"
+ DetailPrint "Set install registry entry: '$1' to '$0'"
+ ConditionalAddToRegisty_EmptyString:
+FunctionEnd
+
+;--------------------------------
+
+!ifdef CPACK_USES_DOWNLOAD
+Function DownloadFile
+ IfFileExists $INSTDIR\* +2
+ CreateDirectory $INSTDIR
+ Pop $0
+
+ ; Skip if already downloaded
+ IfFileExists $INSTDIR\$0 0 +2
+ Return
+
+ StrCpy $1 "@CPACK_DOWNLOAD_SITE@"
+
+ try_again:
+ NSISdl::download "$1/$0" "$INSTDIR\$0"
+
+ Pop $1
+ StrCmp $1 "success" success
+ StrCmp $1 "Cancelled" cancel
+ MessageBox MB_OK "Download failed: $1"
+ cancel:
+ Return
+ success:
+FunctionEnd
+!endif
+
+;--------------------------------
+; Installation types
+@CPACK_NSIS_INSTALLATION_TYPES@
+
+;--------------------------------
+; Component sections
+@CPACK_NSIS_COMPONENT_SECTIONS@
+
+;--------------------------------
+; Define some macro setting for the gui
+@CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
+@CPACK_NSIS_INSTALLER_ICON_CODE@
+@CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@
+@CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE@
+
+;--------------------------------
+;Pages
+ !insertmacro MUI_PAGE_WELCOME
+
+ !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
+ Page custom InstallOptionsPage
+ !insertmacro MUI_PAGE_DIRECTORY
+
+ ;Start Menu Folder Page Configuration
+ !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
+ !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
+ !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
+ !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
+
+ @CPACK_NSIS_PAGE_COMPONENTS@
+
+ !insertmacro MUI_PAGE_INSTFILES
+ !insertmacro MUI_PAGE_FINISH
+
+ !insertmacro MUI_UNPAGE_CONFIRM
+ !insertmacro MUI_UNPAGE_INSTFILES
+
+;--------------------------------
+;Languages
+
+ !insertmacro MUI_LANGUAGE "English" ;first language is the default language
+ !insertmacro MUI_LANGUAGE "Albanian"
+ !insertmacro MUI_LANGUAGE "Arabic"
+ !insertmacro MUI_LANGUAGE "Basque"
+ !insertmacro MUI_LANGUAGE "Belarusian"
+ !insertmacro MUI_LANGUAGE "Bosnian"
+ !insertmacro MUI_LANGUAGE "Breton"
+ !insertmacro MUI_LANGUAGE "Bulgarian"
+ !insertmacro MUI_LANGUAGE "Croatian"
+ !insertmacro MUI_LANGUAGE "Czech"
+ !insertmacro MUI_LANGUAGE "Danish"
+ !insertmacro MUI_LANGUAGE "Dutch"
+ !insertmacro MUI_LANGUAGE "Estonian"
+ !insertmacro MUI_LANGUAGE "Farsi"
+ !insertmacro MUI_LANGUAGE "Finnish"
+ !insertmacro MUI_LANGUAGE "French"
+ !insertmacro MUI_LANGUAGE "German"
+ !insertmacro MUI_LANGUAGE "Greek"
+ !insertmacro MUI_LANGUAGE "Hebrew"
+ !insertmacro MUI_LANGUAGE "Hungarian"
+ !insertmacro MUI_LANGUAGE "Icelandic"
+ !insertmacro MUI_LANGUAGE "Indonesian"
+ !insertmacro MUI_LANGUAGE "Irish"
+ !insertmacro MUI_LANGUAGE "Italian"
+ !insertmacro MUI_LANGUAGE "Japanese"
+ !insertmacro MUI_LANGUAGE "Korean"
+ !insertmacro MUI_LANGUAGE "Kurdish"
+ !insertmacro MUI_LANGUAGE "Latvian"
+ !insertmacro MUI_LANGUAGE "Lithuanian"
+ !insertmacro MUI_LANGUAGE "Luxembourgish"
+ !insertmacro MUI_LANGUAGE "Macedonian"
+ !insertmacro MUI_LANGUAGE "Malay"
+ !insertmacro MUI_LANGUAGE "Mongolian"
+ !insertmacro MUI_LANGUAGE "Norwegian"
+ !insertmacro MUI_LANGUAGE "Polish"
+ !insertmacro MUI_LANGUAGE "Portuguese"
+ !insertmacro MUI_LANGUAGE "PortugueseBR"
+ !insertmacro MUI_LANGUAGE "Romanian"
+ !insertmacro MUI_LANGUAGE "Russian"
+ !insertmacro MUI_LANGUAGE "Serbian"
+ !insertmacro MUI_LANGUAGE "SerbianLatin"
+ !insertmacro MUI_LANGUAGE "SimpChinese"
+ !insertmacro MUI_LANGUAGE "Slovak"
+ !insertmacro MUI_LANGUAGE "Slovenian"
+ !insertmacro MUI_LANGUAGE "Spanish"
+ !insertmacro MUI_LANGUAGE "Swedish"
+ !insertmacro MUI_LANGUAGE "Thai"
+ !insertmacro MUI_LANGUAGE "TradChinese"
+ !insertmacro MUI_LANGUAGE "Turkish"
+ !insertmacro MUI_LANGUAGE "Ukrainian"
+ !insertmacro MUI_LANGUAGE "Welsh"
+
+
+;--------------------------------
+;Reserve Files
+
+ ;These files should be inserted before other files in the data block
+ ;Keep these lines before any File command
+ ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
+
+ ReserveFile "NSIS.InstallOptions.ini"
+ !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
+
+;--------------------------------
+;Installer Sections
+
+Section "-Core installation"
+ ;Use the entire tree produced by the INSTALL target. Keep the
+ ;list of directories here in sync with the RMDir commands below.
+ SetOutPath "$INSTDIR"
+ @CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@
+ @CPACK_NSIS_FULL_INSTALL@
+
+ ;Store installation folder
+ WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
+
+ ;Create uninstaller
+ WriteUninstaller "$INSTDIR\Uninstall.exe"
+ Push "DisplayName"
+ Push "@CPACK_NSIS_DISPLAY_NAME@"
+ Call ConditionalAddToRegisty
+ Push "DisplayVersion"
+ Push "@CPACK_PACKAGE_VERSION@"
+ Call ConditionalAddToRegisty
+ Push "Publisher"
+ Push "@CPACK_PACKAGE_VENDOR@"
+ Call ConditionalAddToRegisty
+ Push "UninstallString"
+ Push "$INSTDIR\Uninstall.exe"
+ Call ConditionalAddToRegisty
+ Push "NoRepair"
+ Push "1"
+ Call ConditionalAddToRegisty
+
+ !ifdef CPACK_NSIS_ADD_REMOVE
+ ;Create add/remove functionality
+ Push "ModifyPath"
+ Push "$INSTDIR\AddRemove.exe"
+ Call ConditionalAddToRegisty
+ !else
+ Push "NoModify"
+ Push "1"
+ Call ConditionalAddToRegisty
+ !endif
+
+ ; Optional registration
+ Push "DisplayIcon"
+ Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
+ Call ConditionalAddToRegisty
+ Push "HelpLink"
+ Push "@CPACK_NSIS_HELP_LINK@"
+ Call ConditionalAddToRegisty
+ Push "URLInfoAbout"
+ Push "@CPACK_NSIS_URL_INFO_ABOUT@"
+ Call ConditionalAddToRegisty
+ Push "Contact"
+ Push "@CPACK_NSIS_CONTACT@"
+ Call ConditionalAddToRegisty
+ !insertmacro MUI_INSTALLOPTIONS_READ $INSTALL_DESKTOP "NSIS.InstallOptions.ini" "Field 5" "State"
+ !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
+
+ ;Create shortcuts
+ CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
+@CPACK_NSIS_CREATE_ICONS@
+@CPACK_NSIS_CREATE_ICONS_EXTRA@
+ CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
+
+ ;Read a value from an InstallOptions INI file
+ !insertmacro MUI_INSTALLOPTIONS_READ $DO_NOT_ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 2" "State"
+ !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 3" "State"
+ !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_CURRENT_USER "NSIS.InstallOptions.ini" "Field 4" "State"
+
+ ; Write special uninstall registry entries
+ Push "StartMenu"
+ Push "$STARTMENU_FOLDER"
+ Call ConditionalAddToRegisty
+ Push "DoNotAddToPath"
+ Push "$DO_NOT_ADD_TO_PATH"
+ Call ConditionalAddToRegisty
+ Push "AddToPathAllUsers"
+ Push "$ADD_TO_PATH_ALL_USERS"
+ Call ConditionalAddToRegisty
+ Push "AddToPathCurrentUser"
+ Push "$ADD_TO_PATH_CURRENT_USER"
+ Call ConditionalAddToRegisty
+ Push "InstallToDesktop"
+ Push "$INSTALL_DESKTOP"
+ Call ConditionalAddToRegisty
+
+ !insertmacro MUI_STARTMENU_WRITE_END
+
+@CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
+
+SectionEnd
+
+Section "-Add to path"
+ Push $INSTDIR\bin
+ StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 doNotAddToPath
+ StrCmp $DO_NOT_ADD_TO_PATH "1" doNotAddToPath 0
+ Call AddToPath
+ doNotAddToPath:
+SectionEnd
+
+;--------------------------------
+; Create custom pages
+Function InstallOptionsPage
+ !insertmacro MUI_HEADER_TEXT "Install Options" "Choose options for installing @CPACK_NSIS_PACKAGE_NAME@"
+ !insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini"
+
+FunctionEnd
+
+;--------------------------------
+; determine admin versus local install
+Function un.onInit
+
+ ClearErrors
+ UserInfo::GetName
+ IfErrors noLM
+ Pop $0
+ UserInfo::GetAccountType
+ Pop $1
+ StrCmp $1 "Admin" 0 +3
+ SetShellVarContext all
+ ;MessageBox MB_OK 'User "$0" is in the Admin group'
+ Goto done
+ StrCmp $1 "Power" 0 +3
+ SetShellVarContext all
+ ;MessageBox MB_OK 'User "$0" is in the Power Users group'
+ Goto done
+
+ noLM:
+ ;Get installation folder from registry if available
+
+ done:
+
+FunctionEnd
+
+;--- Add/Remove callback functions: ---
+!macro SectionList MacroName
+ ;This macro used to perform operation on multiple sections.
+ ;List all of your components in following manner here.
+@CPACK_NSIS_COMPONENT_SECTION_LIST@
+!macroend
+
+Section -FinishComponents
+ ;Removes unselected components and writes component status to registry
+ !insertmacro SectionList "FinishSection"
+
+!ifdef CPACK_NSIS_ADD_REMOVE
+ ; Get the name of the installer executable
+ System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
+ StrCpy $R3 $R0
+
+ ; Strip off the last 13 characters, to see if we have AddRemove.exe
+ StrLen $R1 $R0
+ IntOp $R1 $R0 - 13
+ StrCpy $R2 $R0 13 $R1
+ StrCmp $R2 "AddRemove.exe" addremove_installed
+
+ ; We're not running AddRemove.exe, so install it
+ CopyFiles $R3 $INSTDIR\AddRemove.exe
+
+ addremove_installed:
+!endif
+SectionEnd
+;--- End of Add/Remove callback functions ---
+
+;--------------------------------
+; Component dependencies
+Function .onSelChange
+ !insertmacro SectionList MaybeSelectionChanged
+FunctionEnd
+
+;--------------------------------
+;Uninstaller Section
+
+Section "Uninstall"
+ ReadRegStr $START_MENU SHCTX \
+ "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "StartMenu"
+ ;MessageBox MB_OK "Start menu is in: $START_MENU"
+ ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \
+ "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "DoNotAddToPath"
+ ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \
+ "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathAllUsers"
+ ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \
+ "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathCurrentUser"
+ ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS"
+ ReadRegStr $INSTALL_DESKTOP SHCTX \
+ "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "InstallToDesktop"
+ ;MessageBox MB_OK "Install to desktop: $INSTALL_DESKTOP "
+
+@CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
+
+ ;Remove files we installed.
+ ;Keep the list of directories here in sync with the File commands above.
+@CPACK_NSIS_DELETE_FILES@
+@CPACK_NSIS_DELETE_DIRECTORIES@
+
+!ifdef CPACK_NSIS_ADD_REMOVE
+ ;Remove the add/remove program
+ Delete "$INSTDIR\AddRemove.exe"
+!endif
+
+ ;Remove the uninstaller itself.
+ Delete "$INSTDIR\Uninstall.exe"
+ DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
+
+ ;Remove the installation directory if it is empty.
+ RMDir "$INSTDIR"
+
+ ; Remove the registry entries.
+ DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
+
+ ; Removes all optional components
+ !insertmacro SectionList "RemoveSection_CPack"
+
+ !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
+
+ Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
+@CPACK_NSIS_DELETE_ICONS@
+@CPACK_NSIS_DELETE_ICONS_EXTRA@
+
+ ;Delete empty start menu parent diretories
+ StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
+
+ startMenuDeleteLoop:
+ ClearErrors
+ RMDir $MUI_TEMP
+ GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
+
+ IfErrors startMenuDeleteLoopDone
+
+ StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
+ startMenuDeleteLoopDone:
+
+ ; If the user changed the shortcut, then untinstall may not work. This should
+ ; try to fix it.
+ StrCpy $MUI_TEMP "$START_MENU"
+ Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
+@CPACK_NSIS_DELETE_ICONS_EXTRA@
+
+ ;Delete empty start menu parent diretories
+ StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
+
+ secondStartMenuDeleteLoop:
+ ClearErrors
+ RMDir $MUI_TEMP
+ GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
+
+ IfErrors secondStartMenuDeleteLoopDone
+
+ StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop
+ secondStartMenuDeleteLoopDone:
+
+ DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
+
+ Push $INSTDIR\bin
+ StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0
+ Call un.RemoveFromPath
+ doNotRemoveFromPath:
+SectionEnd
+
+;--------------------------------
+; determine admin versus local install
+; Is install for "AllUsers" or "JustMe"?
+; Default to "JustMe" - set to "AllUsers" if admin or on Win9x
+; This function is used for the very first "custom page" of the installer.
+; This custom page does not show up visibly, but it executes prior to the
+; first visible page and sets up $INSTDIR properly...
+; Choose different default installation folder based on SV_ALLUSERS...
+; "Program Files" for AllUsers, "My Documents" for JustMe...
+
+Function .onInit
+ StrCmp "@CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL@" "ON" 0 inst
+
+ ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "UninstallString"
+ StrCmp $0 "" inst
+
+ MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION \
+ "@CPACK_NSIS_PACKAGE_NAME@ is already installed. $\n$\nDo you want to uninstall the old version before installing the new one?" \
+ IDYES uninst IDNO inst
+ Abort
+
+;Run the uninstaller
+uninst:
+ ClearErrors
+ StrLen $2 "\Uninstall.exe"
+ StrCpy $3 $0 -$2 # remove "\Uninstall.exe" from UninstallString to get path
+ ExecWait '$0 _?=$3' ;Do not copy the uninstaller to a temp file
+
+ IfErrors uninst_failed inst
+uninst_failed:
+ MessageBox MB_OK|MB_ICONSTOP "Uninstall failed."
+ Abort
+
+
+inst:
+ ; Reads components status for registry
+ !insertmacro SectionList "InitSection"
+
+ ; check to see if /D has been used to change
+ ; the install directory by comparing it to the
+ ; install directory that is expected to be the
+ ; default
+ StrCpy $IS_DEFAULT_INSTALLDIR 0
+ StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2
+ StrCpy $IS_DEFAULT_INSTALLDIR 1
+
+ StrCpy $SV_ALLUSERS "JustMe"
+ ; if default install dir then change the default
+ ; if it is installed for JustMe
+ StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
+ StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
+
+ ClearErrors
+ UserInfo::GetName
+ IfErrors noLM
+ Pop $0
+ UserInfo::GetAccountType
+ Pop $1
+ StrCmp $1 "Admin" 0 +4
+ SetShellVarContext all
+ ;MessageBox MB_OK 'User "$0" is in the Admin group'
+ StrCpy $SV_ALLUSERS "AllUsers"
+ Goto done
+ StrCmp $1 "Power" 0 +4
+ SetShellVarContext all
+ ;MessageBox MB_OK 'User "$0" is in the Power Users group'
+ StrCpy $SV_ALLUSERS "AllUsers"
+ Goto done
+
+ noLM:
+ StrCpy $SV_ALLUSERS "AllUsers"
+ ;Get installation folder from registry if available
+
+ done:
+ StrCmp $SV_ALLUSERS "AllUsers" 0 +3
+ StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
+ StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
+
+ StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
+ !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
+
+ noOptionsPage:
+FunctionEnd
diff --git a/Modules/Platform/AIX-GNU-ASM.cmake b/Modules/Platform/AIX-GNU-ASM.cmake
new file mode 100644
index 0000000000..c256df6f92
--- /dev/null
+++ b/Modules/Platform/AIX-GNU-ASM.cmake
@@ -0,0 +1,2 @@
+include(Platform/AIX-GNU)
+__aix_compiler_gnu(ASM)
diff --git a/Modules/Platform/AIX-GNU-C.cmake b/Modules/Platform/AIX-GNU-C.cmake
new file mode 100644
index 0000000000..f49d528b32
--- /dev/null
+++ b/Modules/Platform/AIX-GNU-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/AIX-GNU)
+__aix_compiler_gnu(C)
diff --git a/Modules/Platform/AIX-GNU-CXX.cmake b/Modules/Platform/AIX-GNU-CXX.cmake
new file mode 100644
index 0000000000..ec8e83fa17
--- /dev/null
+++ b/Modules/Platform/AIX-GNU-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/AIX-GNU)
+__aix_compiler_gnu(CXX)
diff --git a/Modules/Platform/AIX-GNU-Fortran.cmake b/Modules/Platform/AIX-GNU-Fortran.cmake
new file mode 100644
index 0000000000..07772a716c
--- /dev/null
+++ b/Modules/Platform/AIX-GNU-Fortran.cmake
@@ -0,0 +1,2 @@
+include(Platform/AIX-GNU)
+__aix_compiler_gnu(Fortran)
diff --git a/Modules/Platform/AIX-GNU.cmake b/Modules/Platform/AIX-GNU.cmake
new file mode 100644
index 0000000000..e5d9434b57
--- /dev/null
+++ b/Modules/Platform/AIX-GNU.cmake
@@ -0,0 +1,27 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__AIX_COMPILER_GNU)
+ return()
+endif()
+set(__AIX_COMPILER_GNU 1)
+
+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_${lang}_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH 1)
+endmacro()
diff --git a/Modules/Platform/AIX-VisualAge-C.cmake b/Modules/Platform/AIX-VisualAge-C.cmake
new file mode 100644
index 0000000000..67b3171dc4
--- /dev/null
+++ b/Modules/Platform/AIX-VisualAge-C.cmake
@@ -0,0 +1 @@
+include(Platform/AIX-XL-C)
diff --git a/Modules/Platform/AIX-VisualAge-CXX.cmake b/Modules/Platform/AIX-VisualAge-CXX.cmake
new file mode 100644
index 0000000000..7894d244fa
--- /dev/null
+++ b/Modules/Platform/AIX-VisualAge-CXX.cmake
@@ -0,0 +1 @@
+include(Platform/AIX-XL-CXX)
diff --git a/Modules/Platform/AIX-VisualAge-Fortran.cmake b/Modules/Platform/AIX-VisualAge-Fortran.cmake
new file mode 100644
index 0000000000..19e59d6663
--- /dev/null
+++ b/Modules/Platform/AIX-VisualAge-Fortran.cmake
@@ -0,0 +1 @@
+include(Platform/AIX-XL-Fortran)
diff --git a/Modules/Platform/AIX-XL-ASM.cmake b/Modules/Platform/AIX-XL-ASM.cmake
new file mode 100644
index 0000000000..ea0944ba4c
--- /dev/null
+++ b/Modules/Platform/AIX-XL-ASM.cmake
@@ -0,0 +1,2 @@
+include(Platform/AIX-XL)
+__aix_compiler_xl(ASM)
diff --git a/Modules/Platform/AIX-XL-C.cmake b/Modules/Platform/AIX-XL-C.cmake
new file mode 100644
index 0000000000..5e437fafd0
--- /dev/null
+++ b/Modules/Platform/AIX-XL-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/AIX-XL)
+__aix_compiler_xl(C)
diff --git a/Modules/Platform/AIX-XL-CXX.cmake b/Modules/Platform/AIX-XL-CXX.cmake
new file mode 100644
index 0000000000..ef38a5f230
--- /dev/null
+++ b/Modules/Platform/AIX-XL-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/AIX-XL)
+__aix_compiler_xl(CXX)
diff --git a/Modules/Platform/AIX-XL-Fortran.cmake b/Modules/Platform/AIX-XL-Fortran.cmake
new file mode 100644
index 0000000000..6d4f6559f0
--- /dev/null
+++ b/Modules/Platform/AIX-XL-Fortran.cmake
@@ -0,0 +1,2 @@
+include(Platform/AIX-XL)
+__aix_compiler_xl(Fortran)
diff --git a/Modules/Platform/AIX-XL.cmake b/Modules/Platform/AIX-XL.cmake
new file mode 100644
index 0000000000..abf385569b
--- /dev/null
+++ b/Modules/Platform/AIX-XL.cmake
@@ -0,0 +1,28 @@
+
+#=============================================================================
+# Copyright 2002-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# This module is shared by multiple languages; use include blocker.
+if(__AIX_COMPILER_XL)
+ return()
+endif()
+set(__AIX_COMPILER_XL 1)
+
+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_${lang}_FLAGS " ")
+ set(CMAKE_SHARED_MODULE_${lang}_FLAGS " ")
+endmacro()
diff --git a/Modules/Platform/AIX.cmake b/Modules/Platform/AIX.cmake
new file mode 100644
index 0000000000..58c6483190
--- /dev/null
+++ b/Modules/Platform/AIX.cmake
@@ -0,0 +1,29 @@
+set(CMAKE_SHARED_LIBRARY_PREFIX "lib") # lib
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") # .so
+set(CMAKE_DL_LIBS "-lld")
+
+# RPATH support on AIX is called libpath. By default the runtime
+# libpath is paths specified by -L followed by /usr/lib and /lib. In
+# order to prevent the -L paths from being used we must force use of
+# -Wl,-blibpath:/usr/lib:/lib whether RPATH support is on or not.
+# When our own RPATH is to be added it may be inserted before the
+# "always" paths.
+set(CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH /usr/lib /lib)
+
+# Files named "libfoo.a" may actually be shared libraries.
+set_property(GLOBAL PROPERTY TARGET_ARCHIVES_MAY_BE_SHARED_LIBS 1)
+
+# since .a can be a static or shared library on AIX, we can not do this.
+# at some point if we wanted it, we would have to figure out if a .a is
+# static or shared, then we could add this back:
+
+# Initialize C link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+#foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+# set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-bstatic")
+# set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-bdynamic")
+#endforeach()
+
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/Android.cmake b/Modules/Platform/Android.cmake
new file mode 100644
index 0000000000..1bdad0403a
--- /dev/null
+++ b/Modules/Platform/Android.cmake
@@ -0,0 +1,15 @@
+include(Platform/Linux)
+
+# Android has soname, but binary names must end in ".so" so we cannot append
+# a version number. Also we cannot portably represent symlinks on the host.
+set(CMAKE_PLATFORM_NO_VERSIONED_SONAME 1)
+
+# Android reportedly ignores RPATH, and we cannot predict the install
+# location anyway.
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "")
+
+# Nsight Tegra Visual Studio Edition takes care of
+# prefixing library names with '-l'.
+if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
+ set(CMAKE_LINK_LIBRARY_FLAG "")
+endif()
diff --git a/Modules/Platform/BSDOS.cmake b/Modules/Platform/BSDOS.cmake
new file mode 100644
index 0000000000..47852f8e13
--- /dev/null
+++ b/Modules/Platform/BSDOS.cmake
@@ -0,0 +1,2 @@
+include(Platform/UnixPaths)
+
diff --git a/Modules/Platform/BeOS.cmake b/Modules/Platform/BeOS.cmake
new file mode 100644
index 0000000000..ef811bd9c3
--- /dev/null
+++ b/Modules/Platform/BeOS.cmake
@@ -0,0 +1,12 @@
+set(BEOS 1)
+
+set(CMAKE_DL_LIBS root be)
+set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
+set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-nostart")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/BlueGeneL.cmake b/Modules/Platform/BlueGeneL.cmake
new file mode 100644
index 0000000000..082e46cae2
--- /dev/null
+++ b/Modules/Platform/BlueGeneL.cmake
@@ -0,0 +1,40 @@
+#the compute nodes on BlueGene/L don't support shared libs
+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
+
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "") # -pic
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "") # -shared
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "") # -rpath
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "") # : or empty
+
+set(CMAKE_LINK_LIBRARY_SUFFIX "")
+set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+set(CMAKE_SHARED_LIBRARY_PREFIX "lib") # lib
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".a") # .a
+set(CMAKE_EXECUTABLE_SUFFIX "") # .exe
+set(CMAKE_DL_LIBS "" )
+
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+
+
+include(Platform/UnixPaths)
+
+if(CMAKE_COMPILER_IS_GNUCC)
+ set(CMAKE_C_LINK_EXECUTABLE
+ "<CMAKE_C_COMPILER> -Wl,-relax <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lgcc,-lc -lnss_files -lnss_dns -lresolv")
+else()
+ # when using IBM xlc we probably don't want to link to -lgcc
+ set(CMAKE_C_LINK_EXECUTABLE
+ "<CMAKE_C_COMPILER> -Wl,-relax <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lc -lnss_files -lnss_dns -lresolv")
+endif()
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_CXX_LINK_EXECUTABLE
+ "<CMAKE_CXX_COMPILER> -Wl,-relax <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lstdc++,-lgcc,-lc -lnss_files -lnss_dns -lresolv")
+else()
+ # when using the IBM xlC we probably don't want to link to -lgcc
+ set(CMAKE_CXX_LINK_EXECUTABLE
+ "<CMAKE_CXX_COMPILER> -Wl,-relax <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lstdc++,-lc -lnss_files -lnss_dns -lresolv")
+endif()
diff --git a/Modules/Platform/BlueGeneP-base.cmake b/Modules/Platform/BlueGeneP-base.cmake
new file mode 100644
index 0000000000..c0241e19dd
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-base.cmake
@@ -0,0 +1,125 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+#
+# BlueGeneP base platform file.
+#
+# NOTE: Do not set your platform to "BlueGeneP-base". This file is included
+# by the real platform files. Use one of these two platforms instead:
+#
+# BlueGeneP-dynamic For dynamically linked builds
+# BlueGeneP-static For statically linked builds
+#
+# This platform file tries its best to adhere to the behavior of the MPI
+# compiler wrappers included with the latest BG/P drivers.
+#
+
+
+#
+# For BGP builds, we're cross compiling, but we don't want to re-root things
+# (e.g. with CMAKE_FIND_ROOT_PATH) because users may have libraries anywhere on
+# the shared filesystems, and this may lie outside the root. Instead, we set the
+# system directories so that the various system BGP CNK library locations are
+# searched first. This is not the clearest thing in the world, given IBM's driver
+# layout, but this should cover all the standard ones.
+#
+set(CMAKE_SYSTEM_LIBRARY_PATH
+ /bgsys/drivers/ppcfloor/comm/default/lib # default comm layer (used by mpi compiler wrappers)
+ /bgsys/drivers/ppcfloor/comm/sys/lib # DCMF, other lower-level comm libraries
+ /bgsys/drivers/ppcfloor/runtime/SPI # other low-level stuff
+ /bgsys/drivers/ppcfloor/gnu-linux/lib # CNK python installation directory
+ /bgsys/drivers/ppcfloor/gnu-linux/powerpc-bgp-linux/lib # CNK Linux image -- standard runtime libs, pthread, etc.
+)
+
+#
+# This adds directories that find commands should specifically ignore for cross compiles.
+# Most of these directories are the includeand lib directories for the frontend on BG/P systems.
+# Not ignoring these can cause things like FindX11 to find a frontend PPC version mistakenly.
+# We use this on BG instead of re-rooting because backend libraries are typically strewn about
+# the filesystem, and we can't re-root ALL backend libraries to a single place.
+#
+set(CMAKE_SYSTEM_IGNORE_PATH
+ /lib /lib64 /include
+ /usr/lib /usr/lib64 /usr/include
+ /usr/local/lib /usr/local/lib64 /usr/local/include
+ /usr/X11/lib /usr/X11/lib64 /usr/X11/include
+ /usr/lib/X11 /usr/lib64/X11 /usr/include/X11
+ /usr/X11R6/lib /usr/X11R6/lib64 /usr/X11R6/include
+ /usr/X11R7/lib /usr/X11R7/lib64 /usr/X11R7/include
+)
+
+#
+# Indicate that this is a unix-like system
+#
+set(UNIX 1)
+
+#
+# Library prefixes, suffixes, extra libs.
+#
+set(CMAKE_LINK_LIBRARY_SUFFIX "")
+set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # lib
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") # .a
+
+set(CMAKE_SHARED_LIBRARY_PREFIX "lib") # lib
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") # .so
+set(CMAKE_EXECUTABLE_SUFFIX "") # .exe
+set(CMAKE_DL_LIBS "dl")
+
+#
+# This macro needs to be called for dynamic library support. Unfortunately on BGP,
+# We can't support both static and dynamic links in the same platform file. The
+# dynamic link platform file needs to call this explicitly to set up dynamic linking.
+#
+macro(__BlueGeneP_set_dynamic_flags compiler_id lang)
+ if (${compiler_id} STREQUAL XL)
+ # Flags for XL compilers if we explicitly detected XL
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-qpic")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-qpie")
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-qpic")
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-qmkshrobj -qnostaticlink")
+ set(BGP_${lang}_DYNAMIC_EXE_FLAGS "-qnostaticlink -qnostaticlink=libgcc")
+ else()
+ # Assume flags for GNU compilers (if the ID is GNU *or* anything else).
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
+ set(BGP_${lang}_DYNAMIC_EXE_FLAGS "-dynamic")
+ endif()
+
+ # Both toolchains use the GNU linker on BG/P, so these options are shared.
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-rpath,")
+ set(CMAKE_SHARED_LIBRARY_RPATH_LINK_${lang}_FLAG "-Wl,-rpath-link,")
+ set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,-soname,")
+ set(CMAKE_EXE_EXPORTS_${lang}_FLAG "-Wl,--export-dynamic")
+ set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "") # +s, flag for exe link to use shared lib
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":") # : or empty
+
+ set(BGP_${lang}_DEFAULT_EXE_FLAGS
+ "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+ set(CMAKE_${lang}_LINK_EXECUTABLE
+ "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGP_${lang}_DYNAMIC_EXE_FLAGS} ${BGP_${lang}_DEFAULT_EXE_FLAGS}")
+endmacro()
+
+#
+# This macro needs to be called for static builds. Right now it just adds -Wl,-relax
+# to the link line.
+#
+macro(__BlueGeneP_set_static_flags compiler_id lang)
+ set(BGP_${lang}_DEFAULT_EXE_FLAGS
+ "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+ set(CMAKE_${lang}_LINK_EXECUTABLE
+ "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGP_${lang}_DEFAULT_EXE_FLAGS}")
+endmacro()
diff --git a/Modules/Platform/BlueGeneP-dynamic-GNU-C.cmake b/Modules/Platform/BlueGeneP-dynamic-GNU-C.cmake
new file mode 100644
index 0000000000..bd4696b6bc
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-dynamic-GNU-C.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_dynamic_flags(GNU C)
diff --git a/Modules/Platform/BlueGeneP-dynamic-GNU-CXX.cmake b/Modules/Platform/BlueGeneP-dynamic-GNU-CXX.cmake
new file mode 100644
index 0000000000..9c995dc7bd
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-dynamic-GNU-CXX.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_dynamic_flags(GNU CXX)
diff --git a/Modules/Platform/BlueGeneP-dynamic-GNU-Fortran.cmake b/Modules/Platform/BlueGeneP-dynamic-GNU-Fortran.cmake
new file mode 100644
index 0000000000..19d6be8ec1
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-dynamic-GNU-Fortran.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_dynamic_flags(GNU Fortran)
diff --git a/Modules/Platform/BlueGeneP-dynamic-XL-C.cmake b/Modules/Platform/BlueGeneP-dynamic-XL-C.cmake
new file mode 100644
index 0000000000..2dbbbc0ec8
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-dynamic-XL-C.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_dynamic_flags(XL C)
diff --git a/Modules/Platform/BlueGeneP-dynamic-XL-CXX.cmake b/Modules/Platform/BlueGeneP-dynamic-XL-CXX.cmake
new file mode 100644
index 0000000000..2bc51272b6
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-dynamic-XL-CXX.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_dynamic_flags(XL CXX)
diff --git a/Modules/Platform/BlueGeneP-dynamic-XL-Fortran.cmake b/Modules/Platform/BlueGeneP-dynamic-XL-Fortran.cmake
new file mode 100644
index 0000000000..59da63da6e
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-dynamic-XL-Fortran.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_dynamic_flags(XL Fortran)
diff --git a/Modules/Platform/BlueGeneP-dynamic.cmake b/Modules/Platform/BlueGeneP-dynamic.cmake
new file mode 100644
index 0000000000..8f96f2f138
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-dynamic.cmake
@@ -0,0 +1,19 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+include(Platform/BlueGeneP-base)
+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
diff --git a/Modules/Platform/BlueGeneP-static-GNU-C.cmake b/Modules/Platform/BlueGeneP-static-GNU-C.cmake
new file mode 100644
index 0000000000..412a7a3e54
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-static-GNU-C.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_static_flags(GNU C)
diff --git a/Modules/Platform/BlueGeneP-static-GNU-CXX.cmake b/Modules/Platform/BlueGeneP-static-GNU-CXX.cmake
new file mode 100644
index 0000000000..418f0d8d51
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-static-GNU-CXX.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_static_flags(GNU CXX)
diff --git a/Modules/Platform/BlueGeneP-static-GNU-Fortran.cmake b/Modules/Platform/BlueGeneP-static-GNU-Fortran.cmake
new file mode 100644
index 0000000000..119195b30e
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-static-GNU-Fortran.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_static_flags(GNU Fortran)
diff --git a/Modules/Platform/BlueGeneP-static-XL-C.cmake b/Modules/Platform/BlueGeneP-static-XL-C.cmake
new file mode 100644
index 0000000000..1f20959327
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-static-XL-C.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_static_flags(XL C)
diff --git a/Modules/Platform/BlueGeneP-static-XL-CXX.cmake b/Modules/Platform/BlueGeneP-static-XL-CXX.cmake
new file mode 100644
index 0000000000..f027a533fa
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-static-XL-CXX.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_static_flags(XL CXX)
diff --git a/Modules/Platform/BlueGeneP-static-XL-Fortran.cmake b/Modules/Platform/BlueGeneP-static-XL-Fortran.cmake
new file mode 100644
index 0000000000..778d4bd91d
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-static-XL-Fortran.cmake
@@ -0,0 +1,16 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+__BlueGeneP_set_static_flags(XL Fortran)
diff --git a/Modules/Platform/BlueGeneP-static.cmake b/Modules/Platform/BlueGeneP-static.cmake
new file mode 100644
index 0000000000..c4f5f21a63
--- /dev/null
+++ b/Modules/Platform/BlueGeneP-static.cmake
@@ -0,0 +1,19 @@
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
+#
+# 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.)
+
+include(Platform/BlueGeneP-base)
+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
diff --git a/Modules/Platform/CYGWIN-CXX.cmake b/Modules/Platform/CYGWIN-CXX.cmake
new file mode 100644
index 0000000000..bf37f79030
--- /dev/null
+++ b/Modules/Platform/CYGWIN-CXX.cmake
@@ -0,0 +1,7 @@
+if(NOT CMAKE_CXX_COMPILER_NAMES)
+ set(CMAKE_CXX_COMPILER_NAMES c++)
+endif()
+
+# Exclude C++ compilers differing from C compiler only by case
+# because this platform may have a case-insensitive filesystem.
+set(CMAKE_CXX_COMPILER_EXCLUDE CC aCC xlC)
diff --git a/Modules/Platform/CYGWIN-GNU-C.cmake b/Modules/Platform/CYGWIN-GNU-C.cmake
new file mode 100644
index 0000000000..9eb0ecf299
--- /dev/null
+++ b/Modules/Platform/CYGWIN-GNU-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/CYGWIN-GNU)
+__cygwin_compiler_gnu(C)
diff --git a/Modules/Platform/CYGWIN-GNU-CXX.cmake b/Modules/Platform/CYGWIN-GNU-CXX.cmake
new file mode 100644
index 0000000000..2603dcd49c
--- /dev/null
+++ b/Modules/Platform/CYGWIN-GNU-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/CYGWIN-GNU)
+__cygwin_compiler_gnu(CXX)
diff --git a/Modules/Platform/CYGWIN-GNU-Fortran.cmake b/Modules/Platform/CYGWIN-GNU-Fortran.cmake
new file mode 100644
index 0000000000..d3b49b6f95
--- /dev/null
+++ b/Modules/Platform/CYGWIN-GNU-Fortran.cmake
@@ -0,0 +1,2 @@
+include(Platform/CYGWIN-GNU)
+__cygwin_compiler_gnu(Fortran)
diff --git a/Modules/Platform/CYGWIN-GNU.cmake b/Modules/Platform/CYGWIN-GNU.cmake
new file mode 100644
index 0000000000..fe25ab214d
--- /dev/null
+++ b/Modules/Platform/CYGWIN-GNU.cmake
@@ -0,0 +1,56 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__CYGWIN_COMPILER_GNU)
+ return()
+endif()
+set(__CYGWIN_COMPILER_GNU 1)
+
+# TODO: Is -Wl,--enable-auto-import now always default?
+set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--enable-auto-import")
+set(CMAKE_CREATE_WIN32_EXE "-mwindows")
+
+set(CMAKE_GNULD_IMAGE_VERSION
+ "-Wl,--major-image-version,<TARGET_VERSION_MAJOR>,--minor-image-version,<TARGET_VERSION_MINOR>")
+set(CMAKE_GENERATOR_RC windres)
+enable_language(RC)
+macro(__cygwin_compiler_gnu lang)
+ # Binary link rules.
+ set(CMAKE_${lang}_CREATE_SHARED_MODULE
+ "<CMAKE_${lang}_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_MODULE_${lang}_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS> -o <TARGET> ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>")
+ set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
+ "<CMAKE_${lang}_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>")
+ set(CMAKE_${lang}_LINK_EXECUTABLE
+ "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>")
+
+ # No -fPIC on cygwin
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
+
+ # Initialize C link type selection flags. These flags are used when
+ # building a shared library, shared module, or executable that links
+ # to other libraries to select whether to use the static or shared
+ # versions of the libraries.
+ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_${lang}_FLAGS "-Wl,-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_${lang}_FLAGS "-Wl,-Bdynamic")
+ endforeach()
+
+ set(CMAKE_EXE_EXPORTS_${lang}_FLAG "-Wl,--export-all-symbols")
+ # TODO: Is -Wl,--enable-auto-import now always default?
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS} -Wl,--enable-auto-import")
+ set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS}")
+endmacro()
diff --git a/Modules/Platform/CYGWIN-windres.cmake b/Modules/Platform/CYGWIN-windres.cmake
new file mode 100644
index 0000000000..01d6be3dfd
--- /dev/null
+++ b/Modules/Platform/CYGWIN-windres.cmake
@@ -0,0 +1 @@
+set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <FLAGS> <DEFINES> <SOURCE> <OBJECT>")
diff --git a/Modules/Platform/CYGWIN.cmake b/Modules/Platform/CYGWIN.cmake
new file mode 100644
index 0000000000..22816e77aa
--- /dev/null
+++ b/Modules/Platform/CYGWIN.cmake
@@ -0,0 +1,64 @@
+if("${CMAKE_MINIMUM_REQUIRED_VERSION}" VERSION_LESS "2.8.3.20101214")
+ set(__USE_CMAKE_LEGACY_CYGWIN_WIN32 1)
+endif()
+if(NOT DEFINED WIN32)
+ set(WIN32 0)
+ if(DEFINED __USE_CMAKE_LEGACY_CYGWIN_WIN32)
+ if(NOT DEFINED CMAKE_LEGACY_CYGWIN_WIN32
+ AND DEFINED ENV{CMAKE_LEGACY_CYGWIN_WIN32})
+ set(CMAKE_LEGACY_CYGWIN_WIN32 $ENV{CMAKE_LEGACY_CYGWIN_WIN32})
+ endif()
+ if(CMAKE_LEGACY_CYGWIN_WIN32)
+ message(STATUS "Defining WIN32 under Cygwin due to CMAKE_LEGACY_CYGWIN_WIN32")
+ set(WIN32 1)
+ elseif("x${CMAKE_LEGACY_CYGWIN_WIN32}" STREQUAL "x")
+ message(WARNING "CMake no longer defines WIN32 on Cygwin!"
+ "\n"
+ "(1) If you are just trying to build this project, ignore this warning "
+ "or quiet it by setting CMAKE_LEGACY_CYGWIN_WIN32=0 in your environment or "
+ "in the CMake cache. "
+ "If later configuration or build errors occur then this project may "
+ "have been written under the assumption that Cygwin is WIN32. "
+ "In that case, set CMAKE_LEGACY_CYGWIN_WIN32=1 instead."
+ "\n"
+ "(2) If you are developing this project, add the line\n"
+ " set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required\n"
+ "at the top of your top-level CMakeLists.txt file or set the minimum "
+ "required version of CMake to 2.8.4 or higher. "
+ "Then teach your project to build on Cygwin without WIN32.")
+ endif()
+ elseif(DEFINED CMAKE_LEGACY_CYGWIN_WIN32)
+ message(AUTHOR_WARNING "CMAKE_LEGACY_CYGWIN_WIN32 ignored because\n"
+ " cmake_minimum_required(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})\n"
+ "is at least 2.8.4.")
+ endif()
+endif()
+if(DEFINED __USE_CMAKE_LEGACY_CYGWIN_WIN32)
+ # Pass WIN32 legacy setting to scripts.
+ if(WIN32)
+ set(ENV{CMAKE_LEGACY_CYGWIN_WIN32} 1)
+ else()
+ set(ENV{CMAKE_LEGACY_CYGWIN_WIN32} 0)
+ endif()
+ unset(__USE_CMAKE_LEGACY_CYGWIN_WIN32)
+endif()
+
+set(CYGWIN 1)
+
+set(CMAKE_SHARED_LIBRARY_PREFIX "cyg")
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
+set(CMAKE_SHARED_MODULE_PREFIX "cyg")
+set(CMAKE_SHARED_MODULE_SUFFIX ".dll")
+set(CMAKE_IMPORT_LIBRARY_PREFIX "lib")
+set(CMAKE_IMPORT_LIBRARY_SUFFIX ".dll.a")
+set(CMAKE_EXECUTABLE_SUFFIX ".exe") # .exe
+# Modules have a different default prefix that shared libs.
+set(CMAKE_MODULE_EXISTS 1)
+
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".a")
+
+# Shared libraries on cygwin can be named with their version number.
+set(CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION 1)
+
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/Catamount.cmake b/Modules/Platform/Catamount.cmake
new file mode 100644
index 0000000000..7e9e02171c
--- /dev/null
+++ b/Modules/Platform/Catamount.cmake
@@ -0,0 +1,26 @@
+#Catamount, which runs on the compute nodes of Cray machines, e.g. RedStorm, doesn't support shared libs
+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
+
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "") # -pic
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "") # -shared
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "") # -rpath
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "") # : or empty
+
+set(CMAKE_LINK_LIBRARY_SUFFIX "")
+set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+set(CMAKE_SHARED_LIBRARY_PREFIX "lib") # lib
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".a") # .a
+set(CMAKE_EXECUTABLE_SUFFIX "") # .exe
+set(CMAKE_DL_LIBS "" )
+
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+
+include(Platform/UnixPaths)
+
+set(CMAKE_CXX_LINK_SHARED_LIBRARY)
+set(CMAKE_CXX_LINK_MODULE_LIBRARY)
+set(CMAKE_C_LINK_SHARED_LIBRARY)
+set(CMAKE_C_LINK_MODULE_LIBRARY)
diff --git a/Modules/Platform/Darwin-Absoft-Fortran.cmake b/Modules/Platform/Darwin-Absoft-Fortran.cmake
new file mode 100644
index 0000000000..dc62b0dce3
--- /dev/null
+++ b/Modules/Platform/Darwin-Absoft-Fortran.cmake
@@ -0,0 +1,18 @@
+#=============================================================================
+# Copyright 2011 Kitware, Inc.
+# Copyright 2013 OpenGamma Ltd. <graham@opengamma.com>
+#
+# 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.)
+
+set(CMAKE_Fortran_VERBOSE_FLAG "-X -v") # Runs gcc under the hood.
+
+set(CMAKE_Fortran_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
+set(CMAKE_Fortran_OSX_CURRENT_VERSION_FLAG "-current_version ")
diff --git a/Modules/Platform/Darwin-AppleClang-C.cmake b/Modules/Platform/Darwin-AppleClang-C.cmake
new file mode 100644
index 0000000000..98971bbca3
--- /dev/null
+++ b/Modules/Platform/Darwin-AppleClang-C.cmake
@@ -0,0 +1 @@
+include(Platform/Darwin-Clang-C)
diff --git a/Modules/Platform/Darwin-AppleClang-CXX.cmake b/Modules/Platform/Darwin-AppleClang-CXX.cmake
new file mode 100644
index 0000000000..4e9e7c12e7
--- /dev/null
+++ b/Modules/Platform/Darwin-AppleClang-CXX.cmake
@@ -0,0 +1 @@
+include(Platform/Darwin-Clang-CXX)
diff --git a/Modules/Platform/Darwin-CXX.cmake b/Modules/Platform/Darwin-CXX.cmake
new file mode 100644
index 0000000000..bf37f79030
--- /dev/null
+++ b/Modules/Platform/Darwin-CXX.cmake
@@ -0,0 +1,7 @@
+if(NOT CMAKE_CXX_COMPILER_NAMES)
+ set(CMAKE_CXX_COMPILER_NAMES c++)
+endif()
+
+# Exclude C++ compilers differing from C compiler only by case
+# because this platform may have a case-insensitive filesystem.
+set(CMAKE_CXX_COMPILER_EXCLUDE CC aCC xlC)
diff --git a/Modules/Platform/Darwin-Clang-C.cmake b/Modules/Platform/Darwin-Clang-C.cmake
new file mode 100644
index 0000000000..0a1502ea9b
--- /dev/null
+++ b/Modules/Platform/Darwin-Clang-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/Darwin-Clang)
+__darwin_compiler_clang(C)
diff --git a/Modules/Platform/Darwin-Clang-CXX.cmake b/Modules/Platform/Darwin-Clang-CXX.cmake
new file mode 100644
index 0000000000..f8e8d888e7
--- /dev/null
+++ b/Modules/Platform/Darwin-Clang-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/Darwin-Clang)
+__darwin_compiler_clang(CXX)
diff --git a/Modules/Platform/Darwin-Clang.cmake b/Modules/Platform/Darwin-Clang.cmake
new file mode 100644
index 0000000000..4cded47a16
--- /dev/null
+++ b/Modules/Platform/Darwin-Clang.cmake
@@ -0,0 +1,30 @@
+
+#=============================================================================
+# Copyright 2002-2012 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 module is shared by multiple languages; use include blocker.
+if(__DARWIN_COMPILER_CLANG)
+ return()
+endif()
+set(__DARWIN_COMPILER_CLANG 1)
+
+macro(__darwin_compiler_clang lang)
+ set(CMAKE_${lang}_VERBOSE_FLAG "-v -Wl,-v") # also tell linker to print verbose output
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names")
+ set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "-bundle -Wl,-headerpad_max_install_names")
+ set(CMAKE_${lang}_SYSROOT_FLAG "-isysroot")
+ set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=")
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.1)
+ set(CMAKE_${lang}_SYSTEM_FRAMEWORK_SEARCH_FLAG "-iframework ")
+ endif()
+endmacro()
diff --git a/Modules/Platform/Darwin-GNU-C.cmake b/Modules/Platform/Darwin-GNU-C.cmake
new file mode 100644
index 0000000000..efdfd0014a
--- /dev/null
+++ b/Modules/Platform/Darwin-GNU-C.cmake
@@ -0,0 +1,4 @@
+include(Platform/Darwin-GNU)
+__darwin_compiler_gnu(C)
+cmake_gnu_set_sysroot_flag(C)
+cmake_gnu_set_osx_deployment_target_flag(C)
diff --git a/Modules/Platform/Darwin-GNU-CXX.cmake b/Modules/Platform/Darwin-GNU-CXX.cmake
new file mode 100644
index 0000000000..e3c2ea7c57
--- /dev/null
+++ b/Modules/Platform/Darwin-GNU-CXX.cmake
@@ -0,0 +1,4 @@
+include(Platform/Darwin-GNU)
+__darwin_compiler_gnu(CXX)
+cmake_gnu_set_sysroot_flag(CXX)
+cmake_gnu_set_osx_deployment_target_flag(CXX)
diff --git a/Modules/Platform/Darwin-GNU-Fortran.cmake b/Modules/Platform/Darwin-GNU-Fortran.cmake
new file mode 100644
index 0000000000..f4b509a13e
--- /dev/null
+++ b/Modules/Platform/Darwin-GNU-Fortran.cmake
@@ -0,0 +1,19 @@
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2013 OpenGamma Ltd. <graham@opengamma.com>
+#
+# 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.)
+
+include(Platform/Darwin-GNU)
+__darwin_compiler_gnu(Fortran)
+
+set(CMAKE_Fortran_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
+set(CMAKE_Fortran_OSX_CURRENT_VERSION_FLAG "-current_version ")
diff --git a/Modules/Platform/Darwin-GNU.cmake b/Modules/Platform/Darwin-GNU.cmake
new file mode 100644
index 0000000000..87d1d2394d
--- /dev/null
+++ b/Modules/Platform/Darwin-GNU.cmake
@@ -0,0 +1,70 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__DARWIN_COMPILER_GNU)
+ return()
+endif()
+set(__DARWIN_COMPILER_GNU 1)
+
+macro(__darwin_compiler_gnu lang)
+ set(CMAKE_${lang}_VERBOSE_FLAG "-v -Wl,-v") # also tell linker to print verbose output
+ # GNU does not have -shared on OS X
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names")
+ set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "-bundle -Wl,-headerpad_max_install_names")
+
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.3)
+ set(CMAKE_${lang}_SYSTEM_FRAMEWORK_SEARCH_FLAG "-iframework ")
+ endif()
+endmacro()
+
+macro(cmake_gnu_set_sysroot_flag lang)
+ if(NOT DEFINED CMAKE_${lang}_SYSROOT_FLAG)
+ set(_doc "${lang} compiler has -isysroot")
+ message(STATUS "Checking whether ${_doc}")
+ execute_process(
+ COMMAND ${CMAKE_${lang}_COMPILER} "-v" "--help"
+ OUTPUT_VARIABLE _gcc_help
+ ERROR_VARIABLE _gcc_help
+ )
+ if("${_gcc_help}" MATCHES "isysroot")
+ message(STATUS "Checking whether ${_doc} - yes")
+ set(CMAKE_${lang}_SYSROOT_FLAG "-isysroot")
+ else()
+ message(STATUS "Checking whether ${_doc} - no")
+ set(CMAKE_${lang}_SYSROOT_FLAG "")
+ endif()
+ set(CMAKE_${lang}_SYSROOT_FLAG_CODE "set(CMAKE_${lang}_SYSROOT_FLAG \"${CMAKE_${lang}_SYSROOT_FLAG}\")")
+ endif()
+endmacro()
+
+macro(cmake_gnu_set_osx_deployment_target_flag lang)
+ if(NOT DEFINED CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG)
+ set(_doc "${lang} compiler supports OSX deployment target flag")
+ message(STATUS "Checking whether ${_doc}")
+ execute_process(
+ COMMAND ${CMAKE_${lang}_COMPILER} "-v" "--help"
+ OUTPUT_VARIABLE _gcc_help
+ ERROR_VARIABLE _gcc_help
+ )
+ if("${_gcc_help}" MATCHES "macosx-version-min")
+ message(STATUS "Checking whether ${_doc} - yes")
+ set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=")
+ else()
+ message(STATUS "Checking whether ${_doc} - no")
+ set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "")
+ endif()
+ set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG_CODE "set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG \"${CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG}\")")
+ endif()
+endmacro()
diff --git a/Modules/Platform/Darwin-Initialize.cmake b/Modules/Platform/Darwin-Initialize.cmake
new file mode 100644
index 0000000000..62fb985678
--- /dev/null
+++ b/Modules/Platform/Darwin-Initialize.cmake
@@ -0,0 +1,151 @@
+# Ask xcode-select where to find /Developer or fall back to ancient location.
+execute_process(COMMAND xcode-select -print-path
+ OUTPUT_VARIABLE _stdout
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE _stderr
+ RESULT_VARIABLE _failed)
+if(NOT _failed AND IS_DIRECTORY ${_stdout})
+ set(OSX_DEVELOPER_ROOT ${_stdout})
+elseif(IS_DIRECTORY "/Developer")
+ set(OSX_DEVELOPER_ROOT "/Developer")
+else()
+ set(OSX_DEVELOPER_ROOT "")
+endif()
+
+execute_process(COMMAND sw_vers -productVersion
+ OUTPUT_VARIABLE CURRENT_OSX_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+# Save CMAKE_OSX_ARCHITECTURES from the environment.
+set(CMAKE_OSX_ARCHITECTURES "$ENV{CMAKE_OSX_ARCHITECTURES}" CACHE STRING
+ "Build architectures for OSX")
+
+#----------------------------------------------------------------------------
+# _CURRENT_OSX_VERSION - as a two-component string: 10.5, 10.6, ...
+#
+string(REGEX REPLACE "^([0-9]+\\.[0-9]+).*$" "\\1"
+ _CURRENT_OSX_VERSION "${CURRENT_OSX_VERSION}")
+
+#----------------------------------------------------------------------------
+# CMAKE_OSX_DEPLOYMENT_TARGET
+
+# Set cache variable - end user may change this during ccmake or cmake-gui configure.
+if(_CURRENT_OSX_VERSION VERSION_GREATER 10.3)
+ set(CMAKE_OSX_DEPLOYMENT_TARGET "$ENV{MACOSX_DEPLOYMENT_TARGET}" CACHE STRING
+ "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value.")
+endif()
+
+#----------------------------------------------------------------------------
+# CMAKE_OSX_SYSROOT
+
+if(CMAKE_OSX_SYSROOT)
+ # Use the existing value without further computation to choose a default.
+ set(_CMAKE_OSX_SYSROOT_DEFAULT "${CMAKE_OSX_SYSROOT}")
+elseif(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND
+ (NOT "x$ENV{SDKROOT}" MATCHES "/" OR IS_DIRECTORY "$ENV{SDKROOT}"))
+ # Use the value of SDKROOT from the environment.
+ set(_CMAKE_OSX_SYSROOT_DEFAULT "$ENV{SDKROOT}")
+elseif("${CMAKE_GENERATOR}" MATCHES Xcode
+ OR CMAKE_OSX_DEPLOYMENT_TARGET
+ OR CMAKE_OSX_ARCHITECTURES MATCHES "[^;]"
+ OR NOT EXISTS "/usr/include/sys/types.h")
+ # Find installed SDKs in either Xcode-4.3+ or pre-4.3 SDKs directory.
+ set(_CMAKE_OSX_SDKS_DIR "")
+ if(OSX_DEVELOPER_ROOT)
+ foreach(d Platforms/MacOSX.platform/Developer/SDKs SDKs)
+ file(GLOB _CMAKE_OSX_SDKS ${OSX_DEVELOPER_ROOT}/${d}/*)
+ if(_CMAKE_OSX_SDKS)
+ set(_CMAKE_OSX_SDKS_DIR ${OSX_DEVELOPER_ROOT}/${d})
+ break()
+ endif()
+ endforeach()
+ endif()
+
+ if(_CMAKE_OSX_SDKS_DIR)
+ # Select SDK for current OSX version accounting for the known
+ # specially named SDKs.
+ set(_CMAKE_OSX_SDKS_VER_SUFFIX_10.4 "u")
+ set(_CMAKE_OSX_SDKS_VER_SUFFIX_10.3 ".9")
+
+ # find the latest SDK
+ set(_CMAKE_OSX_LATEST_SDK_VERSION "0.0")
+ file(GLOB _CMAKE_OSX_SDKS RELATIVE "${_CMAKE_OSX_SDKS_DIR}" "${_CMAKE_OSX_SDKS_DIR}/MacOSX*.sdk")
+ foreach(_SDK ${_CMAKE_OSX_SDKS})
+ if(_SDK MATCHES "MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk" AND CMAKE_MATCH_1 VERSION_GREATER ${_CMAKE_OSX_LATEST_SDK_VERSION})
+ set(_CMAKE_OSX_LATEST_SDK_VERSION "${CMAKE_MATCH_1}")
+ endif()
+ endforeach()
+
+ # pick an SDK that works
+ set(_CMAKE_OSX_SYSROOT_DEFAULT)
+ foreach(ver ${CMAKE_OSX_DEPLOYMENT_TARGET}
+ ${_CURRENT_OSX_VERSION}
+ ${_CMAKE_OSX_LATEST_SDK_VERSION})
+ set(_CMAKE_OSX_DEPLOYMENT_TARGET ${ver})
+ set(_CMAKE_OSX_SDKS_VER ${_CMAKE_OSX_DEPLOYMENT_TARGET}${_CMAKE_OSX_SDKS_VER_SUFFIX_${_CMAKE_OSX_DEPLOYMENT_TARGET}})
+ set(_CMAKE_OSX_SYSROOT_CHECK "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CMAKE_OSX_SDKS_VER}.sdk")
+ if(IS_DIRECTORY "${_CMAKE_OSX_SYSROOT_CHECK}")
+ set(_CMAKE_OSX_SYSROOT_DEFAULT "${_CMAKE_OSX_SYSROOT_CHECK}")
+ break()
+ endif()
+ endforeach()
+
+ if(CMAKE_OSX_DEPLOYMENT_TARGET AND
+ NOT CMAKE_OSX_DEPLOYMENT_TARGET VERSION_EQUAL ${_CMAKE_OSX_DEPLOYMENT_TARGET})
+ set(_CMAKE_OSX_SDKS_VER ${CMAKE_OSX_DEPLOYMENT_TARGET}${_CMAKE_OSX_SDKS_VER_SUFFIX_${CMAKE_OSX_DEPLOYMENT_TARGET}})
+ set(_CMAKE_OSX_SYSROOT_CHECK "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CMAKE_OSX_SDKS_VER}.sdk")
+ message(WARNING
+ "CMAKE_OSX_DEPLOYMENT_TARGET is '${CMAKE_OSX_DEPLOYMENT_TARGET}' "
+ "but the matching SDK does not exist at:\n \"${_CMAKE_OSX_SYSROOT_CHECK}\"\n"
+ "Instead using SDK:\n \"${_CMAKE_OSX_SYSROOT_DEFAULT}\"."
+ )
+ endif()
+ else()
+ # Assume developer files are in root (such as Xcode 4.5 command-line tools).
+ set(_CMAKE_OSX_SYSROOT_DEFAULT "")
+ endif()
+endif()
+
+# Set cache variable - end user may change this during ccmake or cmake-gui configure.
+# Choose the type based on the current value.
+set(_CMAKE_OSX_SYSROOT_TYPE STRING)
+foreach(v CMAKE_OSX_SYSROOT _CMAKE_OSX_SYSROOT_DEFAULT)
+ if("x${${v}}" MATCHES "/")
+ set(_CMAKE_OSX_SYSROOT_TYPE PATH)
+ break()
+ endif()
+endforeach()
+set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_DEFAULT}" CACHE ${_CMAKE_OSX_SYSROOT_TYPE}
+ "The product will be built against the headers and libraries located inside the indicated SDK.")
+
+# Transform the cached value to something we can use.
+set(_CMAKE_OSX_SYSROOT_ORIG "${CMAKE_OSX_SYSROOT}")
+set(_CMAKE_OSX_SYSROOT_PATH "")
+if(CMAKE_OSX_SYSROOT)
+ if("x${CMAKE_OSX_SYSROOT}" MATCHES "/")
+ # This is a path to the SDK. Make sure it exists.
+ if(NOT IS_DIRECTORY "${CMAKE_OSX_SYSROOT}")
+ message(WARNING "Ignoring CMAKE_OSX_SYSROOT value:\n ${CMAKE_OSX_SYSROOT}\n"
+ "because the directory does not exist.")
+ set(CMAKE_OSX_SYSROOT "")
+ set(_CMAKE_OSX_SYSROOT_ORIG "")
+ endif()
+ set(_CMAKE_OSX_SYSROOT_PATH "${CMAKE_OSX_SYSROOT}")
+ else()
+ # Transform the sdk name into a path.
+ execute_process(
+ COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version Path
+ OUTPUT_VARIABLE _stdout
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE _stderr
+ RESULT_VARIABLE _failed
+ )
+ if(NOT _failed AND IS_DIRECTORY "${_stdout}")
+ set(_CMAKE_OSX_SYSROOT_PATH "${_stdout}")
+ # For non-Xcode generators use the path.
+ if(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode")
+ set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_PATH}")
+ endif()
+ endif()
+ endif()
+endif()
diff --git a/Modules/Platform/Darwin-Intel-C.cmake b/Modules/Platform/Darwin-Intel-C.cmake
new file mode 100644
index 0000000000..81c630f4ad
--- /dev/null
+++ b/Modules/Platform/Darwin-Intel-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/Darwin-Intel)
+__darwin_compiler_intel(C)
diff --git a/Modules/Platform/Darwin-Intel-CXX.cmake b/Modules/Platform/Darwin-Intel-CXX.cmake
new file mode 100644
index 0000000000..90ae53be32
--- /dev/null
+++ b/Modules/Platform/Darwin-Intel-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/Darwin-Intel)
+__darwin_compiler_intel(CXX)
diff --git a/Modules/Platform/Darwin-Intel-Fortran.cmake b/Modules/Platform/Darwin-Intel-Fortran.cmake
new file mode 100644
index 0000000000..a604bb69f5
--- /dev/null
+++ b/Modules/Platform/Darwin-Intel-Fortran.cmake
@@ -0,0 +1,18 @@
+#=============================================================================
+# Copyright 2013 OpenGamma Ltd. <graham@opengamma.com>
+#
+# 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.)
+
+include(Platform/Darwin-Intel)
+__darwin_compiler_intel(Fortran)
+
+set(CMAKE_Fortran_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
+set(CMAKE_Fortran_OSX_CURRENT_VERSION_FLAG "-current_version ")
diff --git a/Modules/Platform/Darwin-Intel.cmake b/Modules/Platform/Darwin-Intel.cmake
new file mode 100644
index 0000000000..42f115412f
--- /dev/null
+++ b/Modules/Platform/Darwin-Intel.cmake
@@ -0,0 +1,29 @@
+
+#=============================================================================
+# Copyright 2002-2014 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 module is shared by multiple languages; use include blocker.
+if(__DARWIN_COMPILER_INTEL)
+ return()
+endif()
+set(__DARWIN_COMPILER_INTEL 1)
+
+macro(__darwin_compiler_intel lang)
+ set(CMAKE_${lang}_VERBOSE_FLAG "-v -Wl,-v") # also tell linker to print verbose output
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names")
+ set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "-bundle -Wl,-headerpad_max_install_names")
+
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 12.0)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
+ endif()
+endmacro()
diff --git a/Modules/Platform/Darwin-NAG-Fortran.cmake b/Modules/Platform/Darwin-NAG-Fortran.cmake
new file mode 100644
index 0000000000..4c28e625ca
--- /dev/null
+++ b/Modules/Platform/Darwin-NAG-Fortran.cmake
@@ -0,0 +1,26 @@
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+# Copyright 2013 OpenGamma Ltd. <graham@opengamma.com>
+#
+# 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.)
+
+set(CMAKE_Fortran_VERBOSE_FLAG "-Wl,-v") # Runs gcc under the hood.
+
+# Need -fpp explicitly on case-insensitive filesystem.
+set(CMAKE_Fortran_COMPILE_OBJECT
+ "<CMAKE_Fortran_COMPILER> -fpp -o <OBJECT> <DEFINES> <FLAGS> -c <SOURCE>")
+
+set(CMAKE_Fortran_OSX_COMPATIBILITY_VERSION_FLAG "-Wl,-compatibility_version -Wl,")
+set(CMAKE_Fortran_OSX_CURRENT_VERSION_FLAG "-Wl,-current_version -Wl,")
+set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-Wl,-shared")
+set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-Wl,-install_name -Wl,")
+set(CMAKE_Fortran_CREATE_SHARED_LIBRARY
+ "<CMAKE_Fortran_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG><TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
diff --git a/Modules/Platform/Darwin-VisualAge-C.cmake b/Modules/Platform/Darwin-VisualAge-C.cmake
new file mode 100644
index 0000000000..859914f867
--- /dev/null
+++ b/Modules/Platform/Darwin-VisualAge-C.cmake
@@ -0,0 +1 @@
+include(Platform/Darwin-XL-C)
diff --git a/Modules/Platform/Darwin-VisualAge-CXX.cmake b/Modules/Platform/Darwin-VisualAge-CXX.cmake
new file mode 100644
index 0000000000..46c1005df9
--- /dev/null
+++ b/Modules/Platform/Darwin-VisualAge-CXX.cmake
@@ -0,0 +1 @@
+include(Platform/Darwin-XL-CXX)
diff --git a/Modules/Platform/Darwin-XL-C.cmake b/Modules/Platform/Darwin-XL-C.cmake
new file mode 100644
index 0000000000..42e94a9d6b
--- /dev/null
+++ b/Modules/Platform/Darwin-XL-C.cmake
@@ -0,0 +1,5 @@
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-qmkshrobj")
+set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle")
+
+# Enable shared library versioning.
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-install_name")
diff --git a/Modules/Platform/Darwin-XL-CXX.cmake b/Modules/Platform/Darwin-XL-CXX.cmake
new file mode 100644
index 0000000000..65c76f8b72
--- /dev/null
+++ b/Modules/Platform/Darwin-XL-CXX.cmake
@@ -0,0 +1,5 @@
+set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-qmkshrobj")
+set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS "-bundle")
+
+# Enable shared library versioning.
+set(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-Wl,-install_name")
diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake
new file mode 100644
index 0000000000..e5c5f36d2d
--- /dev/null
+++ b/Modules/Platform/Darwin.cmake
@@ -0,0 +1,226 @@
+set(APPLE 1)
+
+# Darwin versions:
+# 6.x == Mac OSX 10.2 (Jaguar)
+# 7.x == Mac OSX 10.3 (Panther)
+# 8.x == Mac OSX 10.4 (Tiger)
+# 9.x == Mac OSX 10.5 (Leopard)
+# 10.x == Mac OSX 10.6 (Snow Leopard)
+# 11.x == Mac OSX 10.7 (Lion)
+# 12.x == Mac OSX 10.8 (Mountain Lion)
+string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}")
+string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}")
+
+# Do not use the "-Wl,-search_paths_first" flag with the OSX 10.2 compiler.
+# Done this way because it is too early to do a TRY_COMPILE.
+if(NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST)
+ set(HAVE_FLAG_SEARCH_PATHS_FIRST 0)
+ if("${DARWIN_MAJOR_VERSION}" GREATER 6)
+ set(HAVE_FLAG_SEARCH_PATHS_FIRST 1)
+ endif()
+endif()
+# More desirable, but does not work:
+ #include(CheckCXXCompilerFlag)
+ #CHECK_CXX_COMPILER_FLAG("-Wl,-search_paths_first" HAVE_FLAG_SEARCH_PATHS_FIRST)
+
+set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
+set(CMAKE_SHARED_MODULE_PREFIX "lib")
+set(CMAKE_SHARED_MODULE_SUFFIX ".so")
+set(CMAKE_MODULE_EXISTS 1)
+set(CMAKE_DL_LIBS "")
+
+# Enable rpath support for 10.5 and greater where it is known to work.
+if("${DARWIN_MAJOR_VERSION}" GREATER 8)
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
+endif()
+
+set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
+set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
+set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
+set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
+
+set(CMAKE_C_LINK_FLAGS "-Wl,-headerpad_max_install_names")
+set(CMAKE_CXX_LINK_FLAGS "-Wl,-headerpad_max_install_names")
+
+if(HAVE_FLAG_SEARCH_PATHS_FIRST)
+ set(CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
+ set(CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
+endif()
+
+set(CMAKE_PLATFORM_HAS_INSTALLNAME 1)
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names")
+set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -Wl,-headerpad_max_install_names")
+set(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
+set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
+
+# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
+# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
+# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
+# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
+if(NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
+ find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
+ mark_as_advanced(CMAKE_INSTALL_NAME_TOOL)
+endif()
+
+# Make sure the combination of SDK and Deployment Target are allowed
+if(CMAKE_OSX_DEPLOYMENT_TARGET)
+ if("${_CMAKE_OSX_SYSROOT_PATH}" MATCHES "/MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk")
+ set(_sdk_ver "${CMAKE_MATCH_1}")
+ elseif("${_CMAKE_OSX_SYSROOT_ORIG}" MATCHES "^macosx([0-9]+\\.[0-9]+)$")
+ set(_sdk_ver "${CMAKE_MATCH_1}")
+ elseif("${_CMAKE_OSX_SYSROOT_ORIG}" STREQUAL "/")
+ set(_sdk_ver "${_CURRENT_OSX_VERSION}")
+ else()
+ message(FATAL_ERROR
+ "CMAKE_OSX_DEPLOYMENT_TARGET is '${CMAKE_OSX_DEPLOYMENT_TARGET}' "
+ "but CMAKE_OSX_SYSROOT:\n \"${_CMAKE_OSX_SYSROOT_ORIG}\"\n"
+ "is not set to a MacOSX SDK with a recognized version. "
+ "Either set CMAKE_OSX_SYSROOT to a valid SDK or set "
+ "CMAKE_OSX_DEPLOYMENT_TARGET to empty.")
+ endif()
+ if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER "${_sdk_ver}")
+ message(FATAL_ERROR
+ "CMAKE_OSX_DEPLOYMENT_TARGET (${CMAKE_OSX_DEPLOYMENT_TARGET}) "
+ "is greater than CMAKE_OSX_SYSROOT SDK:\n ${_CMAKE_OSX_SYSROOT_ORIG}\n"
+ "Please set CMAKE_OSX_DEPLOYMENT_TARGET to ${_sdk_ver} or lower.")
+ endif()
+endif()
+
+# Enable shared library versioning.
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name")
+
+# Xcode does not support -isystem yet.
+if(XCODE)
+ set(CMAKE_INCLUDE_SYSTEM_FLAG_C)
+ set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
+endif()
+
+if("${_CURRENT_OSX_VERSION}" VERSION_LESS "10.5")
+ # Need to list dependent shared libraries on link line. When building
+ # with -isysroot (for universal binaries), the linker always looks for
+ # dependent libraries under the sysroot. Listing them on the link
+ # line works around the problem.
+ set(CMAKE_LINK_DEPENDENT_LIBRARY_FILES 1)
+endif()
+
+set(CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
+set(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
+set(CMAKE_C_CREATE_SHARED_LIBRARY
+ "<CMAKE_C_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
+set(CMAKE_CXX_CREATE_SHARED_LIBRARY
+ "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
+set(CMAKE_Fortran_CREATE_SHARED_LIBRARY
+ "<CMAKE_Fortran_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
+
+set(CMAKE_CXX_CREATE_SHARED_MODULE
+ "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+
+set(CMAKE_C_CREATE_SHARED_MODULE
+ "<CMAKE_C_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_MODULE_CREATE_C_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+
+set(CMAKE_Fortran_CREATE_SHARED_MODULE
+ "<CMAKE_Fortran_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+
+set(CMAKE_C_CREATE_MACOSX_FRAMEWORK
+ "<CMAKE_C_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
+set(CMAKE_CXX_CREATE_MACOSX_FRAMEWORK
+ "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
+
+# Set default framework search path flag for languages known to use a
+# preprocessor that may find headers in frameworks.
+set(CMAKE_C_FRAMEWORK_SEARCH_FLAG -F)
+set(CMAKE_CXX_FRAMEWORK_SEARCH_FLAG -F)
+set(CMAKE_Fortran_FRAMEWORK_SEARCH_FLAG -F)
+
+# default to searching for frameworks first
+if(NOT DEFINED CMAKE_FIND_FRAMEWORK)
+ set(CMAKE_FIND_FRAMEWORK FIRST)
+endif()
+
+# Older OS X linkers do not report their framework search path
+# with -v but "man ld" documents the following locations.
+set(CMAKE_PLATFORM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ ${_CMAKE_OSX_SYSROOT_PATH}/Library/Frameworks
+ ${_CMAKE_OSX_SYSROOT_PATH}/System/Library/Frameworks
+ )
+if(_CMAKE_OSX_SYSROOT_PATH)
+ # Treat some paths as implicit so we do not override the SDK versions.
+ list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ /System/Library/Frameworks)
+endif()
+if("${_CURRENT_OSX_VERSION}" VERSION_LESS "10.5")
+ # Older OS X tools had more implicit paths.
+ list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ ${_CMAKE_OSX_SYSROOT_PATH}/Network/Library/Frameworks)
+endif()
+
+# set up the default search directories for frameworks
+set(CMAKE_SYSTEM_FRAMEWORK_PATH
+ ~/Library/Frameworks
+ )
+if(_CMAKE_OSX_SYSROOT_PATH)
+ list(APPEND CMAKE_SYSTEM_FRAMEWORK_PATH
+ ${_CMAKE_OSX_SYSROOT_PATH}/Library/Frameworks
+ ${_CMAKE_OSX_SYSROOT_PATH}/Network/Library/Frameworks
+ ${_CMAKE_OSX_SYSROOT_PATH}/System/Library/Frameworks
+ )
+endif()
+list(APPEND CMAKE_SYSTEM_FRAMEWORK_PATH
+ /Library/Frameworks
+ /Network/Library/Frameworks
+ /System/Library/Frameworks)
+
+# Warn about known system mis-configuration case.
+if(CMAKE_OSX_SYSROOT)
+ get_property(_IN_TC GLOBAL PROPERTY IN_TRY_COMPILE)
+ if(NOT _IN_TC AND
+ NOT IS_SYMLINK "${CMAKE_OSX_SYSROOT}/Library/Frameworks"
+ AND IS_SYMLINK "${CMAKE_OSX_SYSROOT}/Library/Frameworks/Frameworks")
+ message(WARNING "The SDK Library/Frameworks path\n"
+ " ${CMAKE_OSX_SYSROOT}/Library/Frameworks\n"
+ "is not set up correctly on this system. "
+ "This is known to occur when installing Xcode 3.2.6:\n"
+ " http://bugs.python.org/issue14018\n"
+ "The problem may cause build errors that report missing system frameworks. "
+ "Fix your SDK symlinks to resolve this issue and avoid this warning."
+ )
+ endif()
+endif()
+
+# default to searching for application bundles first
+if(NOT DEFINED CMAKE_FIND_APPBUNDLE)
+ set(CMAKE_FIND_APPBUNDLE FIRST)
+endif()
+# set up the default search directories for application bundles
+set(_apps_paths)
+foreach(_path
+ "~/Applications"
+ "/Applications"
+ "${OSX_DEVELOPER_ROOT}/../Applications" # Xcode 4.3+
+ "${OSX_DEVELOPER_ROOT}/Applications" # pre-4.3
+ )
+ get_filename_component(_apps "${_path}" ABSOLUTE)
+ if(EXISTS "${_apps}")
+ list(APPEND _apps_paths "${_apps}")
+ endif()
+endforeach()
+if(_apps_paths)
+ list(REMOVE_DUPLICATES _apps_paths)
+endif()
+set(CMAKE_SYSTEM_APPBUNDLE_PATH
+ ${_apps_paths})
+unset(_apps_paths)
+
+include(Platform/UnixPaths)
+if(_CMAKE_OSX_SYSROOT_PATH AND EXISTS ${_CMAKE_OSX_SYSROOT_PATH}/usr/include)
+ list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${_CMAKE_OSX_SYSROOT_PATH}/usr)
+ foreach(lang C CXX)
+ list(APPEND CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES ${_CMAKE_OSX_SYSROOT_PATH}/usr/include)
+ endforeach()
+endif()
+list(APPEND CMAKE_SYSTEM_PREFIX_PATH
+ /sw # Fink
+ /opt/local # MacPorts
+ )
diff --git a/Modules/Platform/DragonFly.cmake b/Modules/Platform/DragonFly.cmake
new file mode 100644
index 0000000000..c22677b9d4
--- /dev/null
+++ b/Modules/Platform/DragonFly.cmake
@@ -0,0 +1,5 @@
+# DragonFly BSD was forked from FreeBSD and is still very close to it
+# http://www.dragonflybsd.org
+# see http://archive.netbsd.se/?ml=dfbsd-users&a=2007-07&m=4678361
+
+include(Platform/FreeBSD)
diff --git a/Modules/Platform/FreeBSD.cmake b/Modules/Platform/FreeBSD.cmake
new file mode 100644
index 0000000000..ce4d3ce490
--- /dev/null
+++ b/Modules/Platform/FreeBSD.cmake
@@ -0,0 +1,26 @@
+set(CMAKE_DL_LIBS "")
+set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
+set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") # -pic
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") # -rpath
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":") # : or empty
+set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
+
+# Shared libraries with no builtin soname may not be linked safely by
+# specifying the file path.
+set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME 1)
+
+# Initialize C link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
+endforeach()
+
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/GNU.cmake b/Modules/Platform/GNU.cmake
new file mode 100644
index 0000000000..e8c3b657b6
--- /dev/null
+++ b/Modules/Platform/GNU.cmake
@@ -0,0 +1,13 @@
+# GCC is the default compiler on GNU/Hurd.
+set(CMAKE_DL_LIBS "dl")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
+set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
+
+set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-gnu[a-z0-9_]*")
+
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/GNUtoMS_lib.bat.in b/Modules/Platform/GNUtoMS_lib.bat.in
new file mode 100644
index 0000000000..2da920ab00
--- /dev/null
+++ b/Modules/Platform/GNUtoMS_lib.bat.in
@@ -0,0 +1,3 @@
+@echo off
+call "@CMAKE_GNUtoMS_BAT@"
+lib /machine:"@CMAKE_GNUtoMS_ARCH@" %*
diff --git a/Modules/Platform/GNUtoMS_lib.cmake b/Modules/Platform/GNUtoMS_lib.cmake
new file mode 100644
index 0000000000..ca9b0f8da9
--- /dev/null
+++ b/Modules/Platform/GNUtoMS_lib.cmake
@@ -0,0 +1,10 @@
+# Usage: cmake -Dlib=lib.bat -Ddef=out.def -Ddll=out.dll -Dimp=out.dll.a -P GNUtoMS_lib.cmake
+get_filename_component(name ${dll} NAME) # .dll file name
+string(REGEX REPLACE "\\.dll\\.a$" ".lib" out "${imp}") # .dll.a -> .lib
+execute_process(
+ COMMAND ${lib} /def:${def} /name:${name} /out:${out}
+ RESULT_VARIABLE res
+ )
+if(res)
+ message(FATAL_ERROR "lib failed: ${res}")
+endif()
diff --git a/Modules/Platform/Generic-ADSP-ASM.cmake b/Modules/Platform/Generic-ADSP-ASM.cmake
new file mode 100644
index 0000000000..63a1388ce1
--- /dev/null
+++ b/Modules/Platform/Generic-ADSP-ASM.cmake
@@ -0,0 +1,7 @@
+include(Platform/Generic-ADSP-Common)
+
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS asm)
+set(CMAKE_ASM_OUTPUT_EXTENSION ".doj" )
+set(CMAKE_ASM_COMPILE_OBJECT
+ "<CMAKE_ASM_COMPILER> <FLAGS> -proc ${ADSP_PROCESSOR} -si-revision ${ADSP_PROCESSOR_SILICIUM_REVISION} -o <OBJECT> <SOURCE>")
+
diff --git a/Modules/Platform/Generic-ADSP-C.cmake b/Modules/Platform/Generic-ADSP-C.cmake
new file mode 100644
index 0000000000..4b9ed9d073
--- /dev/null
+++ b/Modules/Platform/Generic-ADSP-C.cmake
@@ -0,0 +1,20 @@
+
+include(Platform/Generic-ADSP-Common)
+
+
+set(CMAKE_C_OUTPUT_EXTENSION ".doj")
+
+set(CMAKE_C_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_C_FLAGS_MINSIZEREL_INIT "")
+set(CMAKE_C_FLAGS_RELEASE_INIT "")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "")
+
+set(CMAKE_C_CREATE_STATIC_LIBRARY
+ "<CMAKE_C_COMPILER> -build-lib -proc ${ADSP_PROCESSOR} -si-revision ${ADSP_PROCESSOR_SILICIUM_REVISION} -o <TARGET> <CMAKE_C_LINK_FLAGS> <OBJECTS>")
+
+set(CMAKE_C_LINK_EXECUTABLE
+ "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+
+set(CMAKE_C_CREATE_SHARED_LIBRARY)
+set(CMAKE_C_CREATE_MODULE_LIBRARY)
+
diff --git a/Modules/Platform/Generic-ADSP-CXX.cmake b/Modules/Platform/Generic-ADSP-CXX.cmake
new file mode 100644
index 0000000000..9673aef408
--- /dev/null
+++ b/Modules/Platform/Generic-ADSP-CXX.cmake
@@ -0,0 +1,18 @@
+include(Platform/Generic-ADSP-Common)
+
+set(CMAKE_CXX_OUTPUT_EXTENSION ".doj")
+
+set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "")
+set(CMAKE_CXX_FLAGS_RELEASE_INIT "")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "")
+
+set(CMAKE_CXX_CREATE_STATIC_LIBRARY
+ "<CMAKE_CXX_COMPILER> -build-lib -proc ${ADSP_PROCESSOR} -si-revision ${ADSP_PROCESSOR_SILICIUM_REVISION} -o <TARGET> <CMAKE_CXX_LINK_FLAGS> <OBJECTS>")
+
+set(CMAKE_CXX_LINK_EXECUTABLE
+ "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+
+set(CMAKE_CXX_CREATE_SHARED_LIBRARY)
+set(CMAKE_CXX_CREATE_MODULE_LIBRARY)
+
diff --git a/Modules/Platform/Generic-ADSP-Common.cmake b/Modules/Platform/Generic-ADSP-Common.cmake
new file mode 100644
index 0000000000..026f83c489
--- /dev/null
+++ b/Modules/Platform/Generic-ADSP-Common.cmake
@@ -0,0 +1,120 @@
+# support for the Analog Devices toolchain for their DSPs
+# Raphael Cotty" <raphael.cotty (AT) googlemail.com>
+#
+# it supports three architectures:
+# Blackfin
+# TS (TigerShark)
+# 21k (Sharc 21xxx)
+
+if(NOT ADSP)
+
+ set(ADSP TRUE)
+
+ set(CMAKE_STATIC_LIBRARY_SUFFIX ".dlb")
+ set(CMAKE_SHARED_LIBRARY_SUFFIX "")
+ set(CMAKE_EXECUTABLE_SUFFIX ".dxe")
+
+ # if ADSP_PROCESSOR has not been set, but CMAKE_SYSTEM_PROCESSOR has,
+ # assume that this is the processor name to use for the compiler
+ if(CMAKE_SYSTEM_PROCESSOR AND NOT ADSP_PROCESSOR)
+ set(ADSP_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR})
+ endif()
+
+ # if ADSP_PROCESSOR_SILICIUM_REVISION has not been set, use "none"
+ if(NOT ADSP_PROCESSOR_SILICIUM_REVISION)
+ set(ADSP_PROCESSOR_SILICIUM_REVISION "none")
+ endif()
+
+ # this file is included from the C and CXX files, so handle both here
+
+ get_filename_component(_ADSP_DIR "${CMAKE_C_COMPILER}" PATH)
+ if(NOT _ADSP_DIR)
+ get_filename_component(_ADSP_DIR "${CMAKE_CXX_COMPILER}" PATH)
+ endif()
+ if(NOT _ADSP_DIR)
+ get_filename_component(_ADSP_DIR "${CMAKE_ASM_COMPILER}" PATH)
+ endif()
+
+ # detect architecture
+
+ if(CMAKE_C_COMPILER MATCHES ccblkfn OR CMAKE_CXX_COMPILER MATCHES ccblkfn OR CMAKE_ASM_COMPILER MATCHES easmBLKFN)
+ if(NOT ADSP_PROCESSOR)
+ set(ADSP_PROCESSOR "ADSP-BF561")
+ endif()
+ set(ADSP_BLACKFIN TRUE)
+ set(_ADSP_FAMILY_DIR "${_ADSP_DIR}/Blackfin")
+ endif()
+
+ if(CMAKE_C_COMPILER MATCHES ccts OR CMAKE_CXX_COMPILER MATCHES ccts OR CMAKE_ASM_COMPILER MATCHES easmTS)
+ if(NOT ADSP_PROCESSOR)
+ set(ADSP_PROCESSOR "ADSP-TS101")
+ endif()
+ set(ADSP_TS TRUE)
+ set(_ADSP_FAMILY_DIR "${_ADSP_DIR}/TS")
+ endif()
+
+ if(CMAKE_C_COMPILER MATCHES cc21k OR CMAKE_CXX_COMPILER MATCHES cc21k OR CMAKE_ASM_COMPILER MATCHES easm21k)
+ if(NOT ADSP_PROCESSOR)
+ set(ADSP_PROCESSOR "ADSP-21060")
+ endif()
+ set(ADSP_21K TRUE)
+
+ set(_ADSP_FAMILY_DIR "${_ADSP_DIR}/21k") # default if nothing matches
+ if (ADSP_PROCESSOR MATCHES "210..$")
+ set(_ADSP_FAMILY_DIR "${_ADSP_DIR}/21k")
+ endif()
+
+ if (ADSP_PROCESSOR MATCHES "211..$")
+ set(_ADSP_FAMILY_DIR "${_ADSP_DIR}/211k")
+ endif()
+
+ if (ADSP_PROCESSOR MATCHES "212..$")
+ set(_ADSP_FAMILY_DIR "${_ADSP_DIR}/212k")
+ endif()
+
+ if (ADSP_PROCESSOR MATCHES "213..$")
+ set(_ADSP_FAMILY_DIR "${_ADSP_DIR}/213k")
+ endif()
+
+ set(_ADSP_FAMILY_DIR "${_ADSP_DIR}/21k")
+ endif()
+
+
+ link_directories("${_ADSP_FAMILY_DIR}/lib")
+
+ # vdk support
+ find_program( ADSP_VDKGEN_EXECUTABLE vdkgen "${_ADSP_FAMILY_DIR}/vdk" )
+
+ macro(ADSP_GENERATE_VDK VDK_GENERATED_HEADER VDK_GENERATED_SOURCE VDK_KERNEL_SUPPORT_FILE)
+ add_custom_command(
+ OUTPUT ${VDK_GENERATED_HEADER} ${VDK_GENERATED_SOURCE}
+ COMMAND ${ADSP_VDKGEN_EXECUTABLE} ${VDK_KERNEL_SUPPORT_FILE} -proc ${ADSP_PROCESSOR} -si-revision ${ADSP_PROCESSOR_SILICIUM_REVISION} -MM
+ DEPENDS ${VDK_KERNEL_SUPPORT_FILE}
+ )
+ endmacro()
+
+ # loader support
+ find_program( ADSP_ELFLOADER_EXECUTABLE elfloader "${_ADSP_FAMILY_DIR}" )
+
+ # BOOT_MODE: prom, flash, spi, spislave, UART, TWI, FIFO
+ # FORMAT: hex, ASCII, binary, include
+ # WIDTH: 8, 16
+ macro(ADSP_CREATE_LOADER_FILE TARGET_NAME BOOT_MODE FORMAT WIDTH)
+ add_custom_command(
+ TARGET ${TARGET_NAME}
+ POST_BUILD
+ COMMAND ${ADSP_ELFLOADER_EXECUTABLE} ${EXECUTABLE_OUTPUT_PATH}/${TARGET_NAME}.dxe -proc ${ADSP_PROCESSOR} -si-revision ${ADSP_PROCESSOR_SILICIUM_REVISION} -b ${BOOT_MODE} -f ${FORMAT} -width ${WIDTH} -o ${EXECUTABLE_OUTPUT_PATH}/${TARGET_NAME}.ldr
+ COMMENT "Building the loader file"
+ )
+ endmacro()
+
+ macro(ADSP_CREATE_LOADER_FILE_INIT TARGET_NAME BOOT_MODE FORMAT WIDTH INITIALIZATION_FILE)
+ add_custom_command(
+ TARGET ${TARGET_NAME}
+ POST_BUILD
+ COMMAND ${ADSP_ELFLOADER_EXECUTABLE} ${EXECUTABLE_OUTPUT_PATH}/${TARGET_NAME}.dxe -proc ${ADSP_PROCESSOR} -si-revision ${ADSP_PROCESSOR_SILICIUM_REVISION} -b ${BOOT_MODE} -f ${FORMAT} -width ${WIDTH} -o ${EXECUTABLE_OUTPUT_PATH}/${TARGET_NAME}.ldr -init ${INITIALIZATION_FILE}
+ COMMENT "Building the loader file"
+ )
+ endmacro()
+
+endif()
diff --git a/Modules/Platform/Generic-SDCC-C.cmake b/Modules/Platform/Generic-SDCC-C.cmake
new file mode 100644
index 0000000000..588bf32d91
--- /dev/null
+++ b/Modules/Platform/Generic-SDCC-C.cmake
@@ -0,0 +1,54 @@
+
+# This file implements basic support for sdcc (http://sdcc.sourceforge.net/)
+# a free C compiler for 8 and 16 bit microcontrollers.
+# To use it either a toolchain file is required or cmake has to be run like this:
+# cmake -DCMAKE_C_COMPILER=sdcc -DCMAKE_SYSTEM_NAME=Generic <dir...>
+# Since sdcc doesn't support C++, C++ support should be disabled in the
+# CMakeLists.txt using the project() command:
+# project(my_project C)
+
+set(CMAKE_STATIC_LIBRARY_PREFIX "")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
+set(CMAKE_SHARED_LIBRARY_PREFIX "") # lib
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".lib") # .so
+set(CMAKE_IMPORT_LIBRARY_PREFIX )
+set(CMAKE_IMPORT_LIBRARY_SUFFIX )
+set(CMAKE_EXECUTABLE_SUFFIX ".ihx") # intel hex file
+set(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
+set(CMAKE_DL_LIBS "")
+
+set(CMAKE_C_OUTPUT_EXTENSION ".rel")
+
+# find sdcclib as CMAKE_AR
+# since cmake may already have searched for "ar", sdcclib has to
+# be searched with a different variable name (SDCCLIB_EXECUTABLE)
+# and must then be forced into the cache
+get_filename_component(SDCC_LOCATION "${CMAKE_C_COMPILER}" PATH)
+find_program(SDCCLIB_EXECUTABLE sdcclib PATHS "${SDCC_LOCATION}" NO_DEFAULT_PATH)
+find_program(SDCCLIB_EXECUTABLE sdcclib)
+set(CMAKE_AR "${SDCCLIB_EXECUTABLE}" CACHE FILEPATH "The sdcc librarian" FORCE)
+
+# CMAKE_C_FLAGS_INIT and CMAKE_EXE_LINKER_FLAGS_INIT should be set in a CMAKE_SYSTEM_PROCESSOR file
+if(NOT DEFINED CMAKE_C_FLAGS_INIT)
+ set(CMAKE_C_FLAGS_INIT "-mmcs51 --model-small")
+endif()
+
+if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
+ set (CMAKE_EXE_LINKER_FLAGS_INIT --model-small)
+endif()
+
+# compile a C file into an object file
+set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+
+# link object files to an executable
+set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> --out-fmt-ihx -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")
+
+# needs sdcc 2.7.0 + sddclib from cvs
+set(CMAKE_C_CREATE_STATIC_LIBRARY
+ "\"${CMAKE_COMMAND}\" -E remove <TARGET>"
+ "<CMAKE_AR> -a <TARGET> <LINK_FLAGS> <OBJECTS> ")
+
+# not supported by sdcc
+set(CMAKE_C_CREATE_SHARED_LIBRARY "")
+set(CMAKE_C_CREATE_MODULE_LIBRARY "")
+
diff --git a/Modules/Platform/Generic.cmake b/Modules/Platform/Generic.cmake
new file mode 100644
index 0000000000..fcb2699d63
--- /dev/null
+++ b/Modules/Platform/Generic.cmake
@@ -0,0 +1,17 @@
+# This is a platform definition file for platforms without
+# operating system, typically embedded platforms.
+# It is used when CMAKE_SYSTEM_NAME is set to "Generic"
+#
+# It is intentionally empty, since nothing is known
+# about the platform. So everything has to be specified
+# in the system/compiler files ${CMAKE_SYSTEM_NAME}-<compiler_basename>.cmake
+# and/or ${CMAKE_SYSTEM_NAME}-<compiler_basename>-${CMAKE_SYSTEM_PROCESSOR}.cmake
+
+# (embedded) targets without operating system usually don't support shared libraries
+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
+
+# To help the find_xxx() commands, set at least the following so CMAKE_FIND_ROOT_PATH
+# works at least for some simple cases:
+set(CMAKE_SYSTEM_INCLUDE_PATH /include )
+set(CMAKE_SYSTEM_LIBRARY_PATH /lib )
+set(CMAKE_SYSTEM_PROGRAM_PATH /bin )
diff --git a/Modules/Platform/HP-UX-GNU-C.cmake b/Modules/Platform/HP-UX-GNU-C.cmake
new file mode 100644
index 0000000000..5f9ac42005
--- /dev/null
+++ b/Modules/Platform/HP-UX-GNU-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/HP-UX-GNU)
+__hpux_compiler_gnu(C)
diff --git a/Modules/Platform/HP-UX-GNU-CXX.cmake b/Modules/Platform/HP-UX-GNU-CXX.cmake
new file mode 100644
index 0000000000..689bed0880
--- /dev/null
+++ b/Modules/Platform/HP-UX-GNU-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/HP-UX-GNU)
+__hpux_compiler_gnu(CXX)
diff --git a/Modules/Platform/HP-UX-GNU-Fortran.cmake b/Modules/Platform/HP-UX-GNU-Fortran.cmake
new file mode 100644
index 0000000000..ee0181fe4c
--- /dev/null
+++ b/Modules/Platform/HP-UX-GNU-Fortran.cmake
@@ -0,0 +1,2 @@
+include(Platform/HP-UX-GNU)
+__hpux_compiler_gnu(Fortran)
diff --git a/Modules/Platform/HP-UX-GNU.cmake b/Modules/Platform/HP-UX-GNU.cmake
new file mode 100644
index 0000000000..eb909fe990
--- /dev/null
+++ b/Modules/Platform/HP-UX-GNU.cmake
@@ -0,0 +1,27 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__HPUX_COMPILER_GNU)
+ return()
+endif()
+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_RUNTIME_${lang}_FLAG "-Wl,+b")
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":")
+ set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,+h")
+endmacro()
diff --git a/Modules/Platform/HP-UX-HP-ASM.cmake b/Modules/Platform/HP-UX-HP-ASM.cmake
new file mode 100644
index 0000000000..05c69e41bc
--- /dev/null
+++ b/Modules/Platform/HP-UX-HP-ASM.cmake
@@ -0,0 +1,2 @@
+include(Platform/HP-UX-HP)
+__hpux_compiler_hp(ASM)
diff --git a/Modules/Platform/HP-UX-HP-C.cmake b/Modules/Platform/HP-UX-HP-C.cmake
new file mode 100644
index 0000000000..1000935900
--- /dev/null
+++ b/Modules/Platform/HP-UX-HP-C.cmake
@@ -0,0 +1,6 @@
+include(Platform/HP-UX-HP)
+__hpux_compiler_hp(C)
+
+set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> -Aa -Ae <FLAGS> -o <OBJECT> -c <SOURCE>")
diff --git a/Modules/Platform/HP-UX-HP-CXX.cmake b/Modules/Platform/HP-UX-HP-CXX.cmake
new file mode 100644
index 0000000000..dfa1e4e45f
--- /dev/null
+++ b/Modules/Platform/HP-UX-HP-CXX.cmake
@@ -0,0 +1,14 @@
+include(Platform/HP-UX-HP)
+__hpux_compiler_hp(CXX)
+
+set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE
+ "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -S <SOURCE>"
+ "mv `basename \"<SOURCE>\" | sed 's/\\.[^./]*$$//'`.s <ASSEMBLY_SOURCE>"
+ "rm -f `basename \"<SOURCE>\" | sed 's/\\.[^./]*$$//'`.o"
+ )
+
+set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "+O3 -DNDEBUG")
+set(CMAKE_CXX_FLAGS_RELEASE_INIT "+O2 -DNDEBUG")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-g")
diff --git a/Modules/Platform/HP-UX-HP-Fortran.cmake b/Modules/Platform/HP-UX-HP-Fortran.cmake
new file mode 100644
index 0000000000..30acab8077
--- /dev/null
+++ b/Modules/Platform/HP-UX-HP-Fortran.cmake
@@ -0,0 +1,2 @@
+include(Platform/HP-UX-HP)
+__hpux_compiler_hp(Fortran)
diff --git a/Modules/Platform/HP-UX-HP.cmake b/Modules/Platform/HP-UX-HP.cmake
new file mode 100644
index 0000000000..871ea13234
--- /dev/null
+++ b/Modules/Platform/HP-UX-HP.cmake
@@ -0,0 +1,31 @@
+
+#=============================================================================
+# Copyright 2002-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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# This module is shared by multiple languages; use include blocker.
+if(__HPUX_COMPILER_HP)
+ return()
+endif()
+set(__HPUX_COMPILER_HP 1)
+
+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_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 "")
+endmacro()
diff --git a/Modules/Platform/HP-UX.cmake b/Modules/Platform/HP-UX.cmake
new file mode 100644
index 0000000000..65cc7310de
--- /dev/null
+++ b/Modules/Platform/HP-UX.cmake
@@ -0,0 +1,50 @@
+set(CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH /usr/lib)
+
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".sl") # .so
+set(CMAKE_DL_LIBS "dld")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".sl" ".so" ".a")
+set(CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES ".so")
+
+# The HP linker needs to find transitive shared library dependencies
+# in the -L path. Therefore the runtime path must be added to the
+# link line with -L flags.
+set(CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH 1)
+set(CMAKE_LINK_DEPENDENT_LIBRARY_DIRS 1)
+
+# Shared libraries with no builtin soname may not be linked safely by
+# specifying the file path.
+set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME 1)
+
+# set flags for gcc support
+include(Platform/UnixPaths)
+
+# Look in both 32-bit and 64-bit implict link directories, but tell
+# CMake not to pass the paths to the linker. The linker will find the
+# library for the proper architecture. In the future we should detect
+# which path will be used by the linker. Since the pointer type size
+# CMAKE_SIZEOF_VOID_P is not set until after this file executes, we
+# would need to append to CMAKE_SYSTEM_LIBRARY_PATH at a later point
+# (after CMakeTest(LANG)Compiler.cmake runs for at least one language).
+list(APPEND CMAKE_SYSTEM_LIBRARY_PATH /usr/lib/hpux32)
+list(APPEND CMAKE_SYSTEM_LIBRARY_PATH /usr/lib/hpux64)
+list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
+ /usr/lib/hpux32 /usr/lib/hpux64)
+
+# Initialize C and CXX link type selection flags. These flags are
+# used when building a shared library, shared module, or executable
+# that links to other libraries to select whether to use the static or
+# shared versions of the libraries. Note that C modules and shared
+# libs are built using ld directly so we leave off the "-Wl," portion.
+foreach(type SHARED_LIBRARY SHARED_MODULE)
+ set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-a archive")
+ set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-a default")
+endforeach()
+foreach(type EXE)
+ set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-a,archive")
+ set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-a,default")
+endforeach()
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_CXX_FLAGS "-Wl,-a,archive")
+ set(CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS "-Wl,-a,default")
+endforeach()
+
diff --git a/Modules/Platform/Haiku.cmake b/Modules/Platform/Haiku.cmake
new file mode 100644
index 0000000000..dfc2664d33
--- /dev/null
+++ b/Modules/Platform/Haiku.cmake
@@ -0,0 +1,130 @@
+# process only once
+if(HAIKU)
+ return()
+endif()
+
+set(HAIKU 1)
+set(UNIX 1)
+
+set(CMAKE_DL_LIBS "")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
+set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
+
+# Determine, if the C or C++ compiler is configured for a secondary
+# architecture. If so, that will change the search paths we set below. We check
+# whether the compiler's library search paths contain a
+# "/boot/system/develop/lib/<subdir>/", which we assume to be the secondary
+# architecture specific subdirectory and extract the name of the architecture
+# accordingly.
+
+# First of all, find a C or C++ compiler we can run. The "arg1" is necessary
+# here for compilers such as "distcc gcc-x86" or "ccache gcc-x86"
+# TODO See CMakeDetermineCompilerId.cmake for some more things we may want to do.
+if(CMAKE_C_COMPILER)
+ set(__HAIKU_COMPILER ${CMAKE_C_COMPILER})
+ string (STRIP "${CMAKE_C_COMPILER_ARG1}" __HAIKU_COMPILER_FLAGS)
+else()
+ set(__HAIKU_COMPILER ${CMAKE_CXX_COMPILER})
+ string (STRIP "${CMAKE_CXX_COMPILER_ARG1}" __HAIKU_COMPILER_FLAGS)
+endif()
+
+
+execute_process(
+ COMMAND ${__HAIKU_COMPILER} ${__HAIKU_COMPILER_FLAGS} -print-search-dirs
+ OUTPUT_VARIABLE _HAIKU_SEARCH_DIRS
+ RESULT_VARIABLE _HAIKU_SEARCH_DIRS_FOUND
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+string(REGEX MATCH "libraries: =?([^\n]*:)?/boot/system/develop/lib/([^/]*)/?(:?\n+)" _dummy "${_HAIKU_SEARCH_DIRS}\n")
+set(CMAKE_HAIKU_SECONDARY_ARCH "${CMAKE_MATCH_2}")
+
+if(NOT CMAKE_HAIKU_SECONDARY_ARCH)
+ set(CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR "")
+ unset(CMAKE_HAIKU_SECONDARY_ARCH)
+else()
+ set(CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR "/${CMAKE_HAIKU_SECONDARY_ARCH}")
+
+ # Override CMAKE_*LIBRARY_ARCHITECTURE. This will cause FIND_LIBRARY to search
+ # the libraries in the correct subdirectory first. It still isn't completely
+ # correct, since the parent directories shouldn't be searched at all. The
+ # primary architecture library might still be found, if there isn't one
+ # installed for the secondary architecture or it is installed in a less
+ # specific location.
+ set(CMAKE_LIBRARY_ARCHITECTURE ${CMAKE_HAIKU_SECONDARY_ARCH})
+ set(CMAKE_C_LIBRARY_ARCHITECTURE ${CMAKE_HAIKU_SECONDARY_ARCH})
+ set(CMAKE_CXX_LIBRARY_ARCHITECTURE ${CMAKE_HAIKU_SECONDARY_ARCH})
+endif()
+
+list(APPEND CMAKE_SYSTEM_PREFIX_PATH
+ /boot/system/non-packaged
+ /boot/system
+ )
+
+LIST(APPEND CMAKE_HAIKU_COMMON_INCLUDE_DIRECTORIES
+ /boot/system/non-packaged/develop/headers${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+ /boot/system/develop/headers/os
+ /boot/system/develop/headers/os/app
+ /boot/system/develop/headers/os/device
+ /boot/system/develop/headers/os/drivers
+ /boot/system/develop/headers/os/game
+ /boot/system/develop/headers/os/interface
+ /boot/system/develop/headers/os/kernel
+ /boot/system/develop/headers/os/locale
+ /boot/system/develop/headers/os/mail
+ /boot/system/develop/headers/os/media
+ /boot/system/develop/headers/os/midi
+ /boot/system/develop/headers/os/midi2
+ /boot/system/develop/headers/os/net
+ /boot/system/develop/headers/os/opengl
+ /boot/system/develop/headers/os/storage
+ /boot/system/develop/headers/os/support
+ /boot/system/develop/headers/os/translation
+ /boot/system/develop/headers/os/add-ons/graphics
+ /boot/system/develop/headers/os/add-ons/input_server
+ /boot/system/develop/headers/os/add-ons/screen_saver
+ /boot/system/develop/headers/os/add-ons/tracker
+ /boot/system/develop/headers/os/be_apps/Deskbar
+ /boot/system/develop/headers/os/be_apps/NetPositive
+ /boot/system/develop/headers/os/be_apps/Tracker
+ /boot/system/develop/headers/3rdparty
+ /boot/system/develop/headers/bsd
+ /boot/system/develop/headers/glibc
+ /boot/system/develop/headers/gnu
+ /boot/system/develop/headers/posix
+ /boot/system/develop/headers${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+ )
+IF (CMAKE_HAIKU_SECONDARY_ARCH)
+ LIST(APPEND CMAKE_HAIKU_COMMON_INCLUDE_DIRECTORIES
+ /boot/system/develop/headers
+ )
+ENDIF (CMAKE_HAIKU_SECONDARY_ARCH)
+
+LIST(APPEND CMAKE_HAIKU_C_INCLUDE_DIRECTORIES
+ ${CMAKE_HAIKU_COMMON_INCLUDE_DIRECTORIES}
+ )
+
+LIST(APPEND CMAKE_HAIKU_CXX_INCLUDE_DIRECTORIES
+ ${CMAKE_HAIKU_COMMON_INCLUDE_DIRECTORIES})
+
+LIST(APPEND CMAKE_SYSTEM_INCLUDE_PATH ${CMAKE_HAIKU_C_INCLUDE_DIRECTORIES})
+
+LIST(APPEND CMAKE_HAIKU_DEVELOP_LIB_DIRECTORIES
+ /boot/system/non-packaged/develop/lib${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+ /boot/system/develop/lib${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+ )
+
+LIST(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
+ ${CMAKE_HAIKU_DEVELOP_LIB_DIRECTORIES}
+ )
+
+LIST(APPEND CMAKE_SYSTEM_LIBRARY_PATH ${CMAKE_HAIKU_DEVELOP_LIB_DIRECTORIES})
+
+if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+ set(CMAKE_INSTALL_PREFIX "/boot/system" CACHE PATH
+ "Install path prefix, prepended onto install directories." FORCE)
+endif()
diff --git a/Modules/Platform/IRIX.cmake b/Modules/Platform/IRIX.cmake
new file mode 100644
index 0000000000..03e98ccfd7
--- /dev/null
+++ b/Modules/Platform/IRIX.cmake
@@ -0,0 +1,45 @@
+set(CMAKE_DL_LIBS "")
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared -rdata_shared")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") # -rpath
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "") # : or empty
+if(NOT CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_CXX_CREATE_STATIC_LIBRARY
+ "<CMAKE_CXX_COMPILER> -ar -o <TARGET> <OBJECTS>")
+ set (CMAKE_CXX_FLAGS_INIT "")
+ set (CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
+ set (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-O3 -DNDEBUG")
+ set (CMAKE_CXX_FLAGS_RELEASE_INIT "-O2 -DNDEBUG")
+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2")
+ set (CMAKE_C_FLAGS_INIT "")
+endif()
+# set flags for gcc support
+include(Platform/UnixPaths)
+
+if(NOT CMAKE_COMPILER_IS_GNUCC)
+ set (CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+ set (CMAKE_C_CREATE_ASSEMBLY_SOURCE
+ "<CMAKE_C_COMPILER> <FLAGS> -S <SOURCE>"
+ "mv `basename \"<SOURCE>\" | sed 's/\\.[^./]*$$//'`.s <ASSEMBLY_SOURCE>"
+ )
+endif()
+
+if(NOT CMAKE_COMPILER_IS_GNUCXX)
+ set (CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+ set (CMAKE_CXX_CREATE_ASSEMBLY_SOURCE
+ "<CMAKE_CXX_COMPILER> <FLAGS> -S <SOURCE>"
+ "mv `basename \"<SOURCE>\" | sed 's/\\.[^./]*$$//'`.s <ASSEMBLY_SOURCE>"
+ )
+endif()
+
+# Initialize C link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
+endforeach()
+
+# The IRIX linker needs to find transitive shared library dependencies
+# in the -L path.
+set(CMAKE_LINK_DEPENDENT_LIBRARY_DIRS 1)
diff --git a/Modules/Platform/IRIX64.cmake b/Modules/Platform/IRIX64.cmake
new file mode 100644
index 0000000000..5acbd81fa0
--- /dev/null
+++ b/Modules/Platform/IRIX64.cmake
@@ -0,0 +1,73 @@
+set(CMAKE_DL_LIBS "")
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared -rdata_shared")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") # -rpath
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "") # : or empty
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+if(NOT CMAKE_COMPILER_IS_GNUCC)
+ # Set default flags init.
+ set(CMAKE_C_FLAGS_INIT "")
+ set(CMAKE_CXX_FLAGS_INIT "")
+ set(CMAKE_Fortran_FLAGS_INIT "")
+ set(CMAKE_EXE_LINKER_FLAGS_INIT "")
+ set(CMAKE_SHARED_LINKER_FLAGS_INIT "")
+ set(CMAKE_MODULE_LINKER_FLAGS_INIT "")
+
+ # If no -o32, -n32, or -64 flag is given, set a reasonable default.
+ if("$ENV{CFLAGS} $ENV{CXXFLAGS} $ENV{LDFLAGS}" MATCHES "-([no]32|64)")
+ else()
+ # Check if this is a 64-bit CMake.
+ if(CMAKE_FILE_SELF MATCHES "^CMAKE_FILE_SELF$")
+ exec_program(file ARGS ${CMAKE_COMMAND} OUTPUT_VARIABLE CMAKE_FILE_SELF)
+ set(CMAKE_FILE_SELF "${CMAKE_FILE_SELF}" CACHE INTERNAL
+ "Output of file command on ${CMAKE_COMMAND}.")
+ endif()
+
+ # Set initial flags to match cmake executable.
+ if(CMAKE_FILE_SELF MATCHES " 64-bit ")
+ set(CMAKE_C_FLAGS_INIT "-64")
+ set(CMAKE_CXX_FLAGS_INIT "-64")
+ set(CMAKE_Fortran_FLAGS_INIT "-64")
+ set(CMAKE_EXE_LINKER_FLAGS_INIT "-64")
+ set(CMAKE_SHARED_LINKER_FLAGS_INIT "-64")
+ set(CMAKE_MODULE_LINKER_FLAGS_INIT "-64")
+ endif()
+ endif()
+
+ # Set remaining defaults.
+ set(CMAKE_CXX_CREATE_STATIC_LIBRARY
+ "<CMAKE_CXX_COMPILER> -ar -o <TARGET> <OBJECTS>")
+ set (CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
+ set (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-O3 -DNDEBUG")
+ set (CMAKE_CXX_FLAGS_RELEASE_INIT "-O2 -DNDEBUG")
+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2")
+endif()
+include(Platform/UnixPaths)
+
+if(NOT CMAKE_COMPILER_IS_GNUCC)
+ set (CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+ set (CMAKE_C_CREATE_ASSEMBLY_SOURCE
+ "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -S <SOURCE>"
+ "mv `basename \"<SOURCE>\" | sed 's/\\.[^./]*$$//'`.s <ASSEMBLY_SOURCE>"
+ )
+endif()
+
+if(NOT CMAKE_COMPILER_IS_GNUCXX)
+ set (CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+ set (CMAKE_CXX_CREATE_ASSEMBLY_SOURCE
+ "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -S <SOURCE>"
+ "mv `basename \"<SOURCE>\" | sed 's/\\.[^./]*$$//'`.s <ASSEMBLY_SOURCE>"
+ )
+endif()
+
+# Initialize C link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
+endforeach()
+
+# The IRIX linker needs to find transitive shared library dependencies
+# in the -L path.
+set(CMAKE_LINK_DEPENDENT_LIBRARY_DIRS 1)
diff --git a/Modules/Platform/Linux-Absoft-Fortran.cmake b/Modules/Platform/Linux-Absoft-Fortran.cmake
new file mode 100644
index 0000000000..beb41a3b83
--- /dev/null
+++ b/Modules/Platform/Linux-Absoft-Fortran.cmake
@@ -0,0 +1 @@
+set(CMAKE_Fortran_VERBOSE_FLAG "-X -v") # Runs gcc under the hood.
diff --git a/Modules/Platform/Linux-CXX.cmake b/Modules/Platform/Linux-CXX.cmake
new file mode 100644
index 0000000000..b594daeb0b
--- /dev/null
+++ b/Modules/Platform/Linux-CXX.cmake
@@ -0,0 +1,3 @@
+if(NOT CMAKE_CXX_COMPILER_NAMES)
+ set(CMAKE_CXX_COMPILER_NAMES c++)
+endif()
diff --git a/Modules/Platform/Linux-Clang-C.cmake b/Modules/Platform/Linux-Clang-C.cmake
new file mode 100644
index 0000000000..2a77d27104
--- /dev/null
+++ b/Modules/Platform/Linux-Clang-C.cmake
@@ -0,0 +1 @@
+include(Platform/Linux-GNU-C)
diff --git a/Modules/Platform/Linux-Clang-CXX.cmake b/Modules/Platform/Linux-Clang-CXX.cmake
new file mode 100644
index 0000000000..9d9a4df66b
--- /dev/null
+++ b/Modules/Platform/Linux-Clang-CXX.cmake
@@ -0,0 +1 @@
+include(Platform/Linux-GNU-CXX)
diff --git a/Modules/Platform/Linux-GNU-C.cmake b/Modules/Platform/Linux-GNU-C.cmake
new file mode 100644
index 0000000000..84dd492691
--- /dev/null
+++ b/Modules/Platform/Linux-GNU-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-GNU)
+__linux_compiler_gnu(C)
diff --git a/Modules/Platform/Linux-GNU-CXX.cmake b/Modules/Platform/Linux-GNU-CXX.cmake
new file mode 100644
index 0000000000..4162335311
--- /dev/null
+++ b/Modules/Platform/Linux-GNU-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-GNU)
+__linux_compiler_gnu(CXX)
diff --git a/Modules/Platform/Linux-GNU-Fortran.cmake b/Modules/Platform/Linux-GNU-Fortran.cmake
new file mode 100644
index 0000000000..68e95404b8
--- /dev/null
+++ b/Modules/Platform/Linux-GNU-Fortran.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-GNU)
+__linux_compiler_gnu(Fortran)
diff --git a/Modules/Platform/Linux-GNU.cmake b/Modules/Platform/Linux-GNU.cmake
new file mode 100644
index 0000000000..0e254c6eaf
--- /dev/null
+++ b/Modules/Platform/Linux-GNU.cmake
@@ -0,0 +1,25 @@
+
+#=============================================================================
+# Copyright 2010 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 module is shared by multiple languages; use include blocker.
+if(__LINUX_COMPILER_GNU)
+ return()
+endif()
+set(__LINUX_COMPILER_GNU 1)
+
+macro(__linux_compiler_gnu lang)
+ # We pass this for historical reasons. Projects may have
+ # executables that use dlopen but do not set ENABLE_EXPORTS.
+ set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")
+endmacro()
diff --git a/Modules/Platform/Linux-Intel-C.cmake b/Modules/Platform/Linux-Intel-C.cmake
new file mode 100644
index 0000000000..449493a788
--- /dev/null
+++ b/Modules/Platform/Linux-Intel-C.cmake
@@ -0,0 +1,3 @@
+include(Platform/Linux-Intel)
+__linux_compiler_intel(C)
+set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
diff --git a/Modules/Platform/Linux-Intel-CXX.cmake b/Modules/Platform/Linux-Intel-CXX.cmake
new file mode 100644
index 0000000000..142b6cf5c6
--- /dev/null
+++ b/Modules/Platform/Linux-Intel-CXX.cmake
@@ -0,0 +1,3 @@
+include(Platform/Linux-Intel)
+__linux_compiler_intel(CXX)
+set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
diff --git a/Modules/Platform/Linux-Intel-Fortran.cmake b/Modules/Platform/Linux-Intel-Fortran.cmake
new file mode 100644
index 0000000000..0c9523c8c8
--- /dev/null
+++ b/Modules/Platform/Linux-Intel-Fortran.cmake
@@ -0,0 +1,4 @@
+include(Platform/Linux-Intel)
+__linux_compiler_intel(Fortran)
+set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS} -nofor_main")
+set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "")
diff --git a/Modules/Platform/Linux-Intel.cmake b/Modules/Platform/Linux-Intel.cmake
new file mode 100644
index 0000000000..20fddb4229
--- /dev/null
+++ b/Modules/Platform/Linux-Intel.cmake
@@ -0,0 +1,54 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__LINUX_COMPILER_INTEL)
+ return()
+endif()
+set(__LINUX_COMPILER_INTEL 1)
+
+if(NOT XIAR)
+ set(_intel_xiar_hints)
+ foreach(lang C CXX Fortran)
+ if(IS_ABSOLUTE "${CMAKE_${lang}_COMPILER}")
+ get_filename_component(_hint "${CMAKE_${lang}_COMPILER}" PATH)
+ list(APPEND _intel_xiar_hints ${_hint})
+ endif()
+ endforeach()
+ find_program(XIAR NAMES xiar HINTS ${_intel_xiar_hints})
+ mark_as_advanced(XIAR)
+endif()
+
+macro(__linux_compiler_intel lang)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
+
+ # We pass this for historical reasons. Projects may have
+ # executables that use dlopen but do not set ENABLE_EXPORTS.
+ set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")
+
+ if(XIAR)
+ # INTERPROCEDURAL_OPTIMIZATION
+ set(CMAKE_${lang}_COMPILE_OPTIONS_IPO -ipo)
+ set(CMAKE_${lang}_CREATE_STATIC_LIBRARY_IPO
+ "${XIAR} cr <TARGET> <LINK_FLAGS> <OBJECTS> "
+ "${XIAR} -s <TARGET> ")
+ endif()
+
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 12.0)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
+ endif()
+endmacro()
diff --git a/Modules/Platform/Linux-NAG-Fortran.cmake b/Modules/Platform/Linux-NAG-Fortran.cmake
new file mode 100644
index 0000000000..353bae6ddd
--- /dev/null
+++ b/Modules/Platform/Linux-NAG-Fortran.cmake
@@ -0,0 +1,10 @@
+set(CMAKE_Fortran_VERBOSE_FLAG "-Wl,-v") # Runs gcc under the hood.
+
+# Need one "-Wl," level to send flag through to gcc.
+# Use "-Xlinker" to get through gcc to real linker.
+set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-Wl,-shared")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG "-Wl,-Xlinker,-rpath,-Xlinker,")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ":")
+set(CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG "-Wl,-Xlinker,-rpath-link,-Xlinker,")
+set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-Wl,-Xlinker,-soname,-Xlinker,")
+set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "-Wl,-rdynamic")
diff --git a/Modules/Platform/Linux-PGI-C.cmake b/Modules/Platform/Linux-PGI-C.cmake
new file mode 100644
index 0000000000..edf4f3f0e2
--- /dev/null
+++ b/Modules/Platform/Linux-PGI-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-PGI)
+__linux_compiler_pgi(C)
diff --git a/Modules/Platform/Linux-PGI-CXX.cmake b/Modules/Platform/Linux-PGI-CXX.cmake
new file mode 100644
index 0000000000..d425f886e5
--- /dev/null
+++ b/Modules/Platform/Linux-PGI-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-PGI)
+__linux_compiler_pgi(CXX)
diff --git a/Modules/Platform/Linux-PGI-Fortran.cmake b/Modules/Platform/Linux-PGI-Fortran.cmake
new file mode 100644
index 0000000000..e8731a3843
--- /dev/null
+++ b/Modules/Platform/Linux-PGI-Fortran.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-PGI)
+__linux_compiler_pgi(Fortran)
diff --git a/Modules/Platform/Linux-PGI.cmake b/Modules/Platform/Linux-PGI.cmake
new file mode 100644
index 0000000000..3cbb35c72e
--- /dev/null
+++ b/Modules/Platform/Linux-PGI.cmake
@@ -0,0 +1,27 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__LINUX_COMPILER_PGI)
+ return()
+endif()
+set(__LINUX_COMPILER_PGI 1)
+
+macro(__linux_compiler_pgi lang)
+ # Shared library compile and link flags.
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
+endmacro()
diff --git a/Modules/Platform/Linux-PathScale-C.cmake b/Modules/Platform/Linux-PathScale-C.cmake
new file mode 100644
index 0000000000..009f398fea
--- /dev/null
+++ b/Modules/Platform/Linux-PathScale-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-PathScale)
+__linux_compiler_pathscale(C)
diff --git a/Modules/Platform/Linux-PathScale-CXX.cmake b/Modules/Platform/Linux-PathScale-CXX.cmake
new file mode 100644
index 0000000000..b6a5771aab
--- /dev/null
+++ b/Modules/Platform/Linux-PathScale-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-PathScale)
+__linux_compiler_pathscale(CXX)
diff --git a/Modules/Platform/Linux-PathScale-Fortran.cmake b/Modules/Platform/Linux-PathScale-Fortran.cmake
new file mode 100644
index 0000000000..5662d3d88a
--- /dev/null
+++ b/Modules/Platform/Linux-PathScale-Fortran.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-PathScale)
+__linux_compiler_pathscale(Fortran)
diff --git a/Modules/Platform/Linux-PathScale.cmake b/Modules/Platform/Linux-PathScale.cmake
new file mode 100644
index 0000000000..d230ab2250
--- /dev/null
+++ b/Modules/Platform/Linux-PathScale.cmake
@@ -0,0 +1,27 @@
+
+#=============================================================================
+# Copyright 2002-2010 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 module is shared by multiple languages; use include blocker.
+if(__LINUX_COMPILER_PATHSCALE)
+ return()
+endif()
+set(__LINUX_COMPILER_PATHSCALE 1)
+
+macro(__linux_compiler_pathscale lang)
+ # Shared library compile and link flags.
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
+ set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
+endmacro()
diff --git a/Modules/Platform/Linux-SunPro-CXX.cmake b/Modules/Platform/Linux-SunPro-CXX.cmake
new file mode 100644
index 0000000000..a07f1ec84b
--- /dev/null
+++ b/Modules/Platform/Linux-SunPro-CXX.cmake
@@ -0,0 +1,9 @@
+# Sun C++ 5.9 does not support -Wl, but Sun C++ 5.11 does not work without it.
+# Query the compiler flags to detect whether to use -Wl.
+execute_process(COMMAND ${CMAKE_CXX_COMPILER} -flags OUTPUT_VARIABLE _cxx_flags ERROR_VARIABLE _cxx_error)
+if("${_cxx_flags}" MATCHES "\n-W[^\n]*component")
+ set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG "-Wl,-rpath-link,")
+else()
+ set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG "-rpath-link ")
+endif()
+set(CMAKE_EXE_EXPORTS_CXX_FLAG "--export-dynamic")
diff --git a/Modules/Platform/Linux-TinyCC-C.cmake b/Modules/Platform/Linux-TinyCC-C.cmake
new file mode 100644
index 0000000000..f78e708f97
--- /dev/null
+++ b/Modules/Platform/Linux-TinyCC-C.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "")
+set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-soname ")
diff --git a/Modules/Platform/Linux-VisualAge-C.cmake b/Modules/Platform/Linux-VisualAge-C.cmake
new file mode 100644
index 0000000000..0622b63c3d
--- /dev/null
+++ b/Modules/Platform/Linux-VisualAge-C.cmake
@@ -0,0 +1 @@
+include(Platform/Linux-XL-C)
diff --git a/Modules/Platform/Linux-VisualAge-CXX.cmake b/Modules/Platform/Linux-VisualAge-CXX.cmake
new file mode 100644
index 0000000000..b878ba02ca
--- /dev/null
+++ b/Modules/Platform/Linux-VisualAge-CXX.cmake
@@ -0,0 +1 @@
+include(Platform/Linux-XL-CXX)
diff --git a/Modules/Platform/Linux-VisualAge-Fortran.cmake b/Modules/Platform/Linux-VisualAge-Fortran.cmake
new file mode 100644
index 0000000000..1939a8a2f0
--- /dev/null
+++ b/Modules/Platform/Linux-VisualAge-Fortran.cmake
@@ -0,0 +1 @@
+include(Platform/Linux-XL-Fortran)
diff --git a/Modules/Platform/Linux-XL-C.cmake b/Modules/Platform/Linux-XL-C.cmake
new file mode 100644
index 0000000000..f1c584ce51
--- /dev/null
+++ b/Modules/Platform/Linux-XL-C.cmake
@@ -0,0 +1 @@
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-qmkshrobj")
diff --git a/Modules/Platform/Linux-XL-CXX.cmake b/Modules/Platform/Linux-XL-CXX.cmake
new file mode 100644
index 0000000000..abd3fa497e
--- /dev/null
+++ b/Modules/Platform/Linux-XL-CXX.cmake
@@ -0,0 +1 @@
+set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-qmkshrobj")
diff --git a/Modules/Platform/Linux-XL-Fortran.cmake b/Modules/Platform/Linux-XL-Fortran.cmake
new file mode 100644
index 0000000000..cdd1f702b0
--- /dev/null
+++ b/Modules/Platform/Linux-XL-Fortran.cmake
@@ -0,0 +1 @@
+set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-qmkshrobj")
diff --git a/Modules/Platform/Linux-como.cmake b/Modules/Platform/Linux-como.cmake
new file mode 100644
index 0000000000..d1550d201c
--- /dev/null
+++ b/Modules/Platform/Linux-como.cmake
@@ -0,0 +1,17 @@
+# create a shared C++ library
+set(CMAKE_CXX_CREATE_SHARED_LIBRARY
+ "<CMAKE_CXX_COMPILER> --prelink_objects <OBJECTS>"
+ "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+
+# create a C++ static library
+set(CMAKE_CXX_CREATE_STATIC_LIBRARY
+ "<CMAKE_CXX_COMPILER> --prelink_objects <OBJECTS>"
+ "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
+ "<CMAKE_RANLIB> <TARGET> ")
+
+set(CMAKE_CXX_LINK_EXECUTABLE
+ "<CMAKE_CXX_COMPILER> --prelink_objects <OBJECTS>"
+ "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "")
diff --git a/Modules/Platform/Linux.cmake b/Modules/Platform/Linux.cmake
new file mode 100644
index 0000000000..fe8e0039fc
--- /dev/null
+++ b/Modules/Platform/Linux.cmake
@@ -0,0 +1,57 @@
+set(CMAKE_DL_LIBS "dl")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
+set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
+
+# Shared libraries with no builtin soname may not be linked safely by
+# specifying the file path.
+set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME 1)
+
+# Initialize C link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
+endforeach()
+
+# Debian policy requires that shared libraries be installed without
+# executable permission. Fedora policy requires that shared libraries
+# be installed with the executable permission. Since the native tools
+# create shared libraries with execute permission in the first place a
+# reasonable policy seems to be to install with execute permission by
+# default. In order to support debian packages we provide an option
+# here. The option default is based on the current distribution, but
+# packagers can set it explicitly on the command line.
+if(DEFINED CMAKE_INSTALL_SO_NO_EXE)
+ # Store the decision variable in the cache. This preserves any
+ # setting the user provides on the command line.
+ set(CMAKE_INSTALL_SO_NO_EXE "${CMAKE_INSTALL_SO_NO_EXE}" CACHE INTERNAL
+ "Install .so files without execute permission.")
+else()
+ # Store the decision variable as an internal cache entry to avoid
+ # checking the platform every time. This option is advanced enough
+ # that only package maintainers should need to adjust it. They are
+ # capable of providing a setting on the command line.
+ if(EXISTS "/etc/debian_version")
+ set(CMAKE_INSTALL_SO_NO_EXE 1 CACHE INTERNAL
+ "Install .so files without execute permission.")
+ else()
+ set(CMAKE_INSTALL_SO_NO_EXE 0 CACHE INTERNAL
+ "Install .so files without execute permission.")
+ endif()
+endif()
+
+# Match multiarch library directory names.
+set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_]*")
+
+include(Platform/UnixPaths)
+
+# Debian has lib64 paths only for compatibility so they should not be
+# searched.
+if(EXISTS "/etc/debian_version")
+ set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
+endif()
diff --git a/Modules/Platform/MP-RAS.cmake b/Modules/Platform/MP-RAS.cmake
new file mode 100644
index 0000000000..fe8d81a1b5
--- /dev/null
+++ b/Modules/Platform/MP-RAS.cmake
@@ -0,0 +1,14 @@
+if(CMAKE_SYSTEM MATCHES "MP-RAS-02*.")
+ set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+ set(CMAKE_C_COMPILE_OPTIONS_PIE -K PIE)
+ set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
+else()
+ set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+ set(CMAKE_C_COMPILE_OPTIONS_PIE -K PIE)
+ set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
+ set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-Bexport")
+endif()
+
+include(Platform/UnixPaths)
+
+
diff --git a/Modules/Platform/MirBSD.cmake b/Modules/Platform/MirBSD.cmake
new file mode 100644
index 0000000000..7637f9bc77
--- /dev/null
+++ b/Modules/Platform/MirBSD.cmake
@@ -0,0 +1 @@
+include(Platform/OpenBSD)
diff --git a/Modules/Platform/NetBSD.cmake b/Modules/Platform/NetBSD.cmake
new file mode 100644
index 0000000000..1004eb3104
--- /dev/null
+++ b/Modules/Platform/NetBSD.cmake
@@ -0,0 +1,13 @@
+set(CMAKE_DL_LIBS "")
+set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
+set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") # -pic
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") # -rpath
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":") # : or empty
+set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
+
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/OSF1.cmake b/Modules/Platform/OSF1.cmake
new file mode 100644
index 0000000000..f2ad6129c0
--- /dev/null
+++ b/Modules/Platform/OSF1.cmake
@@ -0,0 +1,47 @@
+set(CMAKE_DL_LIBS "")
+
+if(CMAKE_SYSTEM MATCHES "OSF1-1.[012]")
+endif()
+if(CMAKE_SYSTEM MATCHES "OSF1-1")
+ # OSF/1 1.3 from OSF using ELF, and derivatives, including AD2
+ set(CMAKE_C_COMPILE_OPTIONS_PIC "-fpic")
+ set(CMAKE_C_COMPILE_OPTIONS_PIE "-fpie")
+ set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fpic") # -pic
+ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-fpic") # -pic
+endif()
+
+
+
+if(CMAKE_SYSTEM MATCHES "OSF1-V")
+ set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared -Wl,-expect_unresolved,\\*") # -shared
+ if(CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-Wl,-rpath,")
+ else()
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-rpath ")
+ endif()
+ if(CMAKE_COMPILER_IS_GNUCC)
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
+ else()
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-rpath ")
+ endif()
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
+endif()
+
+set(CMAKE_MAKE_INCLUDE_FROM_ROOT 1) # include $(CMAKE_BINARY_DIR)/...
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ # include the gcc flags
+else ()
+ # use default OSF compiler flags
+ set (CMAKE_C_FLAGS_INIT "")
+ set (CMAKE_C_FLAGS_DEBUG_INIT "-g")
+ set (CMAKE_C_FLAGS_MINSIZEREL_INIT "-O2 -DNDEBUG")
+ set (CMAKE_C_FLAGS_RELEASE_INIT "-O2 -DNDEBUG")
+ set (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2")
+ set (CMAKE_CXX_FLAGS_INIT "")
+ set (CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
+ set (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-O2 -DNDEBUG")
+ set (CMAKE_CXX_FLAGS_RELEASE_INIT "-O2 -DNDEBUG")
+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2")
+endif()
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/OpenBSD.cmake b/Modules/Platform/OpenBSD.cmake
new file mode 100644
index 0000000000..7ac6c7e842
--- /dev/null
+++ b/Modules/Platform/OpenBSD.cmake
@@ -0,0 +1,38 @@
+include(Platform/NetBSD)
+
+# On OpenBSD, the compile time linker does not share it's configuration with
+# the runtime linker. This will extract the library search paths from the
+# system's ld.so.hints file which will allow CMake to set the appropriate
+# -rpath-link flags
+if(NOT CMAKE_PLATFORM_RUNTIME_PATH)
+ execute_process(COMMAND /sbin/ldconfig -r
+ OUTPUT_VARIABLE LDCONFIG_HINTS
+ ERROR_QUIET)
+ string(REGEX REPLACE ".*search\\ directories:\\ ([^\n]*).*" "\\1"
+ LDCONFIG_HINTS "${LDCONFIG_HINTS}")
+ string(REPLACE ":" ";"
+ CMAKE_PLATFORM_RUNTIME_PATH
+ "${LDCONFIG_HINTS}")
+endif()
+
+set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_OPENBSD_VERSIONING 1)
+
+# OpenBSD has no multilib
+set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
+
+# OpenBSD policy requires that shared libraries be installed without
+# executable permission.
+set(CMAKE_INSTALL_SO_NO_EXE 1)
+
+if($ENV{LOCALBASE})
+ set(OPENBSD_LOCALBASE $ENV{LOCALBASE})
+else()
+ set(OPENBSD_LOCALBASE /usr/local)
+endif()
+if($ENV{X11BASE})
+ set(OPENBSD_X11BASE $ENV{X11BASE})
+else()
+ set(OPENBSD_X11BASE /usr/X11R6)
+endif()
+
+list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${OPENBSD_LOCALBASE})
diff --git a/Modules/Platform/OpenVMS.cmake b/Modules/Platform/OpenVMS.cmake
new file mode 100644
index 0000000000..b10da23884
--- /dev/null
+++ b/Modules/Platform/OpenVMS.cmake
@@ -0,0 +1,8 @@
+include(Platform/UnixPaths)
+
+set(CMAKE_C_CREATE_STATIC_LIBRARY
+ "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>"
+ "<CMAKE_RANLIB> <TARGET>"
+ )
+set(CMAKE_CXX_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY})
+set(CMAKE_EXECUTABLE_SUFFIX ".exe") # .exe
diff --git a/Modules/Platform/QNX.cmake b/Modules/Platform/QNX.cmake
new file mode 100644
index 0000000000..ebc4609a37
--- /dev/null
+++ b/Modules/Platform/QNX.cmake
@@ -0,0 +1,19 @@
+set(QNXNTO 1)
+
+include(Platform/GNU)
+unset(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
+
+set(CMAKE_DL_LIBS "")
+
+# Shared libraries with no builtin soname may not be linked safely by
+# specifying the file path.
+set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME 1)
+
+# Initialize C link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
+endforeach()
diff --git a/Modules/Platform/RISCos.cmake b/Modules/Platform/RISCos.cmake
new file mode 100644
index 0000000000..570cd7b5b6
--- /dev/null
+++ b/Modules/Platform/RISCos.cmake
@@ -0,0 +1,6 @@
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-G 0")
+set(CMAKE_SHARED_LIBRARY_SUFFIX "..o")
+set(CMAKE_DL_LIBS "")
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-D,08000000")
+
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/SCO_SV.cmake b/Modules/Platform/SCO_SV.cmake
new file mode 100644
index 0000000000..ddd960083d
--- /dev/null
+++ b/Modules/Platform/SCO_SV.cmake
@@ -0,0 +1,2 @@
+set(CMAKE_DL_LIBS "")
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/SINIX.cmake b/Modules/Platform/SINIX.cmake
new file mode 100644
index 0000000000..c37a113d38
--- /dev/null
+++ b/Modules/Platform/SINIX.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+set(CMAKE_C_COMPILE_OPTIONS_PIE "")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/SunOS-GNU-C.cmake b/Modules/Platform/SunOS-GNU-C.cmake
new file mode 100644
index 0000000000..6a96c00eea
--- /dev/null
+++ b/Modules/Platform/SunOS-GNU-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/SunOS-GNU)
+__sunos_compiler_gnu(C)
diff --git a/Modules/Platform/SunOS-GNU-CXX.cmake b/Modules/Platform/SunOS-GNU-CXX.cmake
new file mode 100644
index 0000000000..6b9f6fa862
--- /dev/null
+++ b/Modules/Platform/SunOS-GNU-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/SunOS-GNU)
+__sunos_compiler_gnu(CXX)
diff --git a/Modules/Platform/SunOS-GNU-Fortran.cmake b/Modules/Platform/SunOS-GNU-Fortran.cmake
new file mode 100644
index 0000000000..c6b1888361
--- /dev/null
+++ b/Modules/Platform/SunOS-GNU-Fortran.cmake
@@ -0,0 +1,2 @@
+include(Platform/SunOS-GNU)
+__sunos_compiler_gnu(Fortran)
diff --git a/Modules/Platform/SunOS-GNU.cmake b/Modules/Platform/SunOS-GNU.cmake
new file mode 100644
index 0000000000..7169056de4
--- /dev/null
+++ b/Modules/Platform/SunOS-GNU.cmake
@@ -0,0 +1,34 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__SUNOS_COMPILER_GNU)
+ return()
+endif()
+set(__SUNOS_COMPILER_GNU 1)
+
+macro(__sunos_compiler_gnu lang)
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-R")
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":")
+ set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,-h")
+
+ # Initialize C link type selection flags. These flags are used when
+ # building a shared library, shared module, or executable that links
+ # to other libraries to select whether to use the static or shared
+ # versions of the libraries.
+ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_${lang}_FLAGS "-Wl,-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_${lang}_FLAGS "-Wl,-Bdynamic")
+ endforeach()
+endmacro()
diff --git a/Modules/Platform/SunOS.cmake b/Modules/Platform/SunOS.cmake
new file mode 100644
index 0000000000..aaa79c449e
--- /dev/null
+++ b/Modules/Platform/SunOS.cmake
@@ -0,0 +1,32 @@
+if(CMAKE_SYSTEM MATCHES "SunOS-4")
+ set(CMAKE_C_COMPILE_OPTIONS_PIC "-PIC")
+ set(CMAKE_C_COMPILE_OPTIONS_PIE "-PIE")
+ set(CMAKE_SHARED_LIBRARY_C_FLAGS "-PIC")
+ set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared -Wl,-r")
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-R")
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
+endif()
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ if(CMAKE_COMPILER_IS_GNUCC)
+ set(CMAKE_CXX_CREATE_SHARED_LIBRARY
+ "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+ else()
+ # Take default rule from CMakeDefaultMakeRuleVariables.cmake.
+ endif()
+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)
+
+# Shared libraries with no builtin soname may not be linked safely by
+# specifying the file path.
+set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME 1)
diff --git a/Modules/Platform/Tru64.cmake b/Modules/Platform/Tru64.cmake
new file mode 100644
index 0000000000..47852f8e13
--- /dev/null
+++ b/Modules/Platform/Tru64.cmake
@@ -0,0 +1,2 @@
+include(Platform/UnixPaths)
+
diff --git a/Modules/Platform/ULTRIX.cmake b/Modules/Platform/ULTRIX.cmake
new file mode 100644
index 0000000000..9db4c7c20f
--- /dev/null
+++ b/Modules/Platform/ULTRIX.cmake
@@ -0,0 +1,5 @@
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-G 0")
+set(CMAKE_SHARED_LIBRARY_SUFFIX "..o")
+set(CMAKE_DL_LIBS "")
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-D,08000000")
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/UNIX_SV.cmake b/Modules/Platform/UNIX_SV.cmake
new file mode 100644
index 0000000000..1ec96aea26
--- /dev/null
+++ b/Modules/Platform/UNIX_SV.cmake
@@ -0,0 +1,5 @@
+set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+set(CMAKE_C_COMPILE_OPTIONS_PIE "")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-Bexport")
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/UnixPaths.cmake b/Modules/Platform/UnixPaths.cmake
new file mode 100644
index 0000000000..20ee1d1114
--- /dev/null
+++ b/Modules/Platform/UnixPaths.cmake
@@ -0,0 +1,97 @@
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+# Block multiple inclusion because "CMakeCInformation.cmake" includes
+# "Platform/${CMAKE_SYSTEM_NAME}" even though the generic module
+# "CMakeSystemSpecificInformation.cmake" already included it.
+# The extra inclusion is a work-around documented next to the include()
+# call, so this can be removed when the work-around is removed.
+if(__UNIX_PATHS_INCLUDED)
+ return()
+endif()
+set(__UNIX_PATHS_INCLUDED 1)
+
+set(UNIX 1)
+
+# also add 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)
+
+# List common installation prefixes. These will be used for all
+# search types.
+list(APPEND CMAKE_SYSTEM_PREFIX_PATH
+ # Standard
+ /usr/local /usr /
+
+ # 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 common include file locations not under the common prefixes.
+list(APPEND CMAKE_SYSTEM_INCLUDE_PATH
+ # Windows API on Cygwin
+ /usr/include/w32api
+
+ # X11
+ /usr/X11R6/include /usr/include/X11
+
+ # Other
+ /usr/pkg/include
+ /opt/csw/include /opt/include
+ /usr/openwin/include
+ )
+
+list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
+ # Windows API on Cygwin
+ /usr/lib/w32api
+
+ # X11
+ /usr/X11R6/lib /usr/lib/X11
+
+ # Other
+ /usr/pkg/lib
+ /opt/csw/lib /opt/lib
+ /usr/openwin/lib
+ )
+
+list(APPEND CMAKE_SYSTEM_PROGRAM_PATH
+ /usr/pkg/bin
+ )
+
+list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
+ /lib /lib32 /lib64 /usr/lib /usr/lib32 /usr/lib64
+ )
+
+list(APPEND CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES
+ /usr/include
+ )
+list(APPEND CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
+ /usr/include
+ )
+
+# Enable use of lib64 search path variants by default.
+set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
diff --git a/Modules/Platform/UnixWare.cmake b/Modules/Platform/UnixWare.cmake
new file mode 100644
index 0000000000..e649bd2a48
--- /dev/null
+++ b/Modules/Platform/UnixWare.cmake
@@ -0,0 +1,5 @@
+set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
+set(CMAKE_C_COMPILE_OPTIONS_PIE "")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-Wl,-Bexport")
+include(Platform/UnixPaths)
diff --git a/Modules/Platform/Windows-Borland-C.cmake b/Modules/Platform/Windows-Borland-C.cmake
new file mode 100644
index 0000000000..e2f76aacba
--- /dev/null
+++ b/Modules/Platform/Windows-Borland-C.cmake
@@ -0,0 +1 @@
+include(Platform/Windows-Embarcadero-C)
diff --git a/Modules/Platform/Windows-Borland-CXX.cmake b/Modules/Platform/Windows-Borland-CXX.cmake
new file mode 100644
index 0000000000..809490f95b
--- /dev/null
+++ b/Modules/Platform/Windows-Borland-CXX.cmake
@@ -0,0 +1 @@
+include(Platform/Windows-Embarcadero-CXX)
diff --git a/Modules/Platform/Windows-CXX.cmake b/Modules/Platform/Windows-CXX.cmake
new file mode 100644
index 0000000000..bf37f79030
--- /dev/null
+++ b/Modules/Platform/Windows-CXX.cmake
@@ -0,0 +1,7 @@
+if(NOT CMAKE_CXX_COMPILER_NAMES)
+ set(CMAKE_CXX_COMPILER_NAMES c++)
+endif()
+
+# Exclude C++ compilers differing from C compiler only by case
+# because this platform may have a case-insensitive filesystem.
+set(CMAKE_CXX_COMPILER_EXCLUDE CC aCC xlC)
diff --git a/Modules/Platform/Windows-Clang-C.cmake b/Modules/Platform/Windows-Clang-C.cmake
new file mode 100644
index 0000000000..d00710579f
--- /dev/null
+++ b/Modules/Platform/Windows-Clang-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/Windows-Clang)
+__windows_compiler_clang(C)
diff --git a/Modules/Platform/Windows-Clang-CXX.cmake b/Modules/Platform/Windows-Clang-CXX.cmake
new file mode 100644
index 0000000000..2c3688a368
--- /dev/null
+++ b/Modules/Platform/Windows-Clang-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/Windows-Clang)
+__windows_compiler_clang(CXX)
diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake
new file mode 100644
index 0000000000..4c936fe2e7
--- /dev/null
+++ b/Modules/Platform/Windows-Clang.cmake
@@ -0,0 +1,32 @@
+
+#=============================================================================
+# Copyright 2001-2013 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 module is shared by multiple languages; use include blocker.
+if(__WINDOWS_CLANG)
+ return()
+endif()
+set(__WINDOWS_CLANG 1)
+
+if(CMAKE_C_SIMULATE_ID STREQUAL "MSVC"
+ OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
+ include(Platform/Windows-MSVC)
+ macro(__windows_compiler_clang lang)
+ __windows_compiler_msvc(${lang})
+ endmacro()
+else()
+ include(Platform/Windows-GNU)
+ macro(__windows_compiler_clang lang)
+ __windows_compiler_gnu(${lang})
+ endmacro()
+endif()
diff --git a/Modules/Platform/Windows-Embarcadero-C.cmake b/Modules/Platform/Windows-Embarcadero-C.cmake
new file mode 100644
index 0000000000..607fd4ebe2
--- /dev/null
+++ b/Modules/Platform/Windows-Embarcadero-C.cmake
@@ -0,0 +1,3 @@
+set(_lang C)
+include(Platform/Windows-Embarcadero)
+__embarcadero_language(C)
diff --git a/Modules/Platform/Windows-Embarcadero-CXX.cmake b/Modules/Platform/Windows-Embarcadero-CXX.cmake
new file mode 100644
index 0000000000..279a4def41
--- /dev/null
+++ b/Modules/Platform/Windows-Embarcadero-CXX.cmake
@@ -0,0 +1,3 @@
+set(_lang CXX)
+include(Platform/Windows-Embarcadero)
+__embarcadero_language(CXX)
diff --git a/Modules/Platform/Windows-Embarcadero.cmake b/Modules/Platform/Windows-Embarcadero.cmake
new file mode 100644
index 0000000000..26b3c0cab9
--- /dev/null
+++ b/Modules/Platform/Windows-Embarcadero.cmake
@@ -0,0 +1,131 @@
+
+#=============================================================================
+# Copyright 2002-2012 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 module is shared by multiple languages; use include blocker.
+if(__WINDOWS_EMBARCADERO)
+ return()
+endif()
+set(__WINDOWS_EMBARCADERO 1)
+
+set(BORLAND 1)
+
+if("${CMAKE_${_lang}_COMPILER_VERSION}" VERSION_LESS 6.30)
+ # Borland target type flags (bcc32 -h -t):
+ set(_tW "-tW") # -tW GUI App (implies -U__CONSOLE__)
+ set(_tC "-tWC") # -tWC Console App (implies -D__CONSOLE__=1)
+ set(_tD "-tWD") # -tWD Build a DLL (implies -D__DLL__=1 -D_DLL=1)
+ set(_tM "-tWM") # -tWM Enable threads (implies -D__MT__=1 -D_MT=1)
+ set(_tR "-tWR -tW-") # -tWR Use DLL runtime (implies -D_RTLDLL, and '-tW' too!!)
+ # Notes:
+ # - The flags affect linking so we pass them to the linker.
+ # - The flags affect preprocessing so we pass them to the compiler.
+ # - Since '-tWR' implies '-tW' we use '-tWR -tW-' instead.
+ # - Since '-tW-' disables '-tWD' we use '-tWR -tW- -tWD' for DLLs.
+else()
+ set(EMBARCADERO 1)
+ set(_tC "-tC") # Target is a console application
+ set(_tD "-tD") # Target is a shared library
+ set(_tM "-tM") # Target is multi-threaded
+ set(_tR "-tR") # Target uses the dynamic RTL
+ set(_tW "-tW") # Target is a Windows application
+endif()
+set(_COMPILE_C "-c")
+set(_COMPILE_CXX "-P -c")
+
+set(CMAKE_LIBRARY_PATH_FLAG "-L")
+set(CMAKE_LINK_LIBRARY_FLAG "")
+
+set(CMAKE_FIND_LIBRARY_SUFFIXES "-bcc.lib" ".lib")
+
+# uncomment these out to debug makefiles
+#set(CMAKE_START_TEMP_FILE "")
+#set(CMAKE_END_TEMP_FILE "")
+#set(CMAKE_VERBOSE_MAKEFILE 1)
+
+# Borland cannot handle + in the file name, so mangle object file name
+set (CMAKE_MANGLE_OBJECT_FILE_NAMES "ON")
+
+# extra flags for a win32 exe
+set(CMAKE_CREATE_WIN32_EXE "${_tW}" )
+# extra flags for a console app
+set(CMAKE_CREATE_CONSOLE_EXE "${_tC}" )
+
+set (CMAKE_BUILD_TYPE Debug CACHE STRING
+ "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel.")
+
+set (CMAKE_EXE_LINKER_FLAGS_INIT "${_tM} -lS:1048576 -lSc:4098 -lH:1048576 -lHc:8192 ")
+set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "-v")
+set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "-v")
+set (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT})
+set (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
+set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT})
+
+
+macro(__embarcadero_language lang)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_DLL "${_tD}") # Note: This variable is a ';' separated list
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "${_tD}") # ... while this is a space separated string.
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
+
+ # compile a source file into an object file
+ # place <DEFINES> outside the response file because Borland refuses
+ # to parse quotes from the response file.
+ set(CMAKE_${lang}_COMPILE_OBJECT
+ "<CMAKE_${lang}_COMPILER> ${_tR} <DEFINES> -DWIN32 -o<OBJECT> <FLAGS> ${_COMPILE_${lang}} <SOURCE>"
+ )
+
+ set(CMAKE_${lang}_LINK_EXECUTABLE
+ "<CMAKE_${lang}_COMPILER> ${_tR} -e<TARGET> <LINK_FLAGS> <FLAGS> ${CMAKE_START_TEMP_FILE} <LINK_LIBRARIES> <OBJECTS>${CMAKE_END_TEMP_FILE}"
+ # "implib -c -w <TARGET_IMPLIB> <TARGET>"
+ )
+
+ # place <DEFINES> outside the response file because Borland refuses
+ # to parse quotes from the response file.
+ set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE
+ "cpp32 <DEFINES> -DWIN32 <FLAGS> -o<PREPROCESSED_SOURCE> ${_COMPILE_${lang}} <SOURCE>"
+ )
+ # Borland >= 5.6 allows -P option for cpp32, <= 5.5 does not
+
+ # Create a module library.
+ set(CMAKE_${lang}_CREATE_SHARED_MODULE
+ "<CMAKE_${lang}_COMPILER> ${_tR} ${_tD} ${CMAKE_START_TEMP_FILE}-e<TARGET> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS>${CMAKE_END_TEMP_FILE}"
+ )
+
+ # Create an import library for another target.
+ set(CMAKE_${lang}_CREATE_IMPORT_LIBRARY
+ "implib -c -w <TARGET_IMPLIB> <TARGET>"
+ )
+
+ # Create a shared library.
+ # First create a module and then its import library.
+ set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
+ ${CMAKE_${lang}_CREATE_SHARED_MODULE}
+ ${CMAKE_${lang}_CREATE_IMPORT_LIBRARY}
+ )
+
+ # create a static library
+ set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
+ "tlib ${CMAKE_START_TEMP_FILE}/p512 <LINK_FLAGS> /a <TARGET_QUOTED> <OBJECTS>${CMAKE_END_TEMP_FILE}"
+ )
+
+ # Initial configuration flags.
+ set(CMAKE_${lang}_FLAGS_INIT "${_tM}")
+ set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-Od -v")
+ set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-O1 -DNDEBUG")
+ set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-O2 -DNDEBUG")
+ set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-Od")
+ set(CMAKE_${lang}_STANDARD_LIBRARIES_INIT "import32.lib")
+endmacro()
diff --git a/Modules/Platform/Windows-G95-Fortran.cmake b/Modules/Platform/Windows-G95-Fortran.cmake
new file mode 100644
index 0000000000..af08008252
--- /dev/null
+++ b/Modules/Platform/Windows-G95-Fortran.cmake
@@ -0,0 +1 @@
+include(Platform/Windows-GNU-Fortran)
diff --git a/Modules/Platform/Windows-GNU-C-ABI.cmake b/Modules/Platform/Windows-GNU-C-ABI.cmake
new file mode 100644
index 0000000000..1189263fad
--- /dev/null
+++ b/Modules/Platform/Windows-GNU-C-ABI.cmake
@@ -0,0 +1 @@
+__windows_compiler_gnu_abi(C)
diff --git a/Modules/Platform/Windows-GNU-C.cmake b/Modules/Platform/Windows-GNU-C.cmake
new file mode 100644
index 0000000000..ecf89dc1b7
--- /dev/null
+++ b/Modules/Platform/Windows-GNU-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/Windows-GNU)
+__windows_compiler_gnu(C)
diff --git a/Modules/Platform/Windows-GNU-CXX-ABI.cmake b/Modules/Platform/Windows-GNU-CXX-ABI.cmake
new file mode 100644
index 0000000000..f3c701c3c0
--- /dev/null
+++ b/Modules/Platform/Windows-GNU-CXX-ABI.cmake
@@ -0,0 +1 @@
+__windows_compiler_gnu_abi(CXX)
diff --git a/Modules/Platform/Windows-GNU-CXX.cmake b/Modules/Platform/Windows-GNU-CXX.cmake
new file mode 100644
index 0000000000..23e6552292
--- /dev/null
+++ b/Modules/Platform/Windows-GNU-CXX.cmake
@@ -0,0 +1,2 @@
+include(Platform/Windows-GNU)
+__windows_compiler_gnu(CXX)
diff --git a/Modules/Platform/Windows-GNU-Fortran-ABI.cmake b/Modules/Platform/Windows-GNU-Fortran-ABI.cmake
new file mode 100644
index 0000000000..179280b4d8
--- /dev/null
+++ b/Modules/Platform/Windows-GNU-Fortran-ABI.cmake
@@ -0,0 +1 @@
+__windows_compiler_gnu_abi(Fortran)
diff --git a/Modules/Platform/Windows-GNU-Fortran.cmake b/Modules/Platform/Windows-GNU-Fortran.cmake
new file mode 100644
index 0000000000..b81b79679d
--- /dev/null
+++ b/Modules/Platform/Windows-GNU-Fortran.cmake
@@ -0,0 +1,5 @@
+include(Platform/Windows-GNU)
+__windows_compiler_gnu(Fortran)
+
+# gfortran on 64-bit MinGW defines __SIZEOF_POINTER__
+set(CMAKE_Fortran_SIZEOF_DATA_PTR_DEFAULT 4)
diff --git a/Modules/Platform/Windows-GNU.cmake b/Modules/Platform/Windows-GNU.cmake
new file mode 100644
index 0000000000..ffc56573fd
--- /dev/null
+++ b/Modules/Platform/Windows-GNU.cmake
@@ -0,0 +1,196 @@
+
+#=============================================================================
+# Copyright 2002-2009 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 module is shared by multiple languages; use include blocker.
+if(__WINDOWS_GNU)
+ return()
+endif()
+set(__WINDOWS_GNU 1)
+
+set(CMAKE_IMPORT_LIBRARY_PREFIX "lib")
+set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
+set(CMAKE_SHARED_MODULE_PREFIX "lib")
+set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+
+set(CMAKE_EXECUTABLE_SUFFIX ".exe")
+set(CMAKE_IMPORT_LIBRARY_SUFFIX ".dll.a")
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
+set(CMAKE_SHARED_MODULE_SUFFIX ".dll")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+
+if(MSYS OR MINGW)
+ set(CMAKE_EXTRA_LINK_EXTENSIONS ".lib") # MinGW can also link to a MS .lib
+endif()
+
+if(MINGW)
+ set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ".dll.a" ".a" ".lib")
+ set(CMAKE_C_STANDARD_LIBRARIES_INIT "-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32")
+ set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")
+endif()
+
+set(CMAKE_DL_LIBS "")
+set(CMAKE_LIBRARY_PATH_FLAG "-L")
+set(CMAKE_LINK_LIBRARY_FLAG "-l")
+set(CMAKE_LINK_DEF_FILE_FLAG "") # Empty string: passing the file is enough
+set(CMAKE_LINK_LIBRARY_SUFFIX "")
+set(CMAKE_CREATE_WIN32_EXE "-mwindows")
+
+set(CMAKE_GNULD_IMAGE_VERSION
+ "-Wl,--major-image-version,<TARGET_VERSION_MAJOR>,--minor-image-version,<TARGET_VERSION_MINOR>")
+
+# Check if GNU ld is too old to support @FILE syntax.
+set(__WINDOWS_GNU_LD_RESPONSE 1)
+execute_process(COMMAND ld -v OUTPUT_VARIABLE _help ERROR_VARIABLE _help)
+if("${_help}" MATCHES "GNU ld .* 2\\.1[1-6]")
+ set(__WINDOWS_GNU_LD_RESPONSE 0)
+endif()
+
+if(NOT CMAKE_GENERATOR_RC AND CMAKE_GENERATOR MATCHES "Unix Makefiles")
+ set(CMAKE_GENERATOR_RC windres)
+endif()
+
+enable_language(RC)
+
+macro(__windows_compiler_gnu lang)
+
+ if(MSYS OR MINGW)
+ # Create archiving rules to support large object file lists for static libraries.
+ set(CMAKE_${lang}_ARCHIVE_CREATE "<CMAKE_AR> cq <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_${lang}_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
+
+ # Initialize C link type selection flags. These flags are used when
+ # building a shared library, shared module, or executable that links
+ # to other libraries to select whether to use the static or shared
+ # versions of the libraries.
+ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_${lang}_FLAGS "-Wl,-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_${lang}_FLAGS "-Wl,-Bdynamic")
+ endforeach()
+ endif()
+
+ # No -fPIC on Windows
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
+
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS ${__WINDOWS_GNU_LD_RESPONSE})
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES ${__WINDOWS_GNU_LD_RESPONSE})
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
+
+ # We prefer "@" for response files but it is not supported by gcc 3.
+ execute_process(COMMAND ${CMAKE_${lang}_COMPILER} --version OUTPUT_VARIABLE _ver ERROR_VARIABLE _ver)
+ if("${_ver}" MATCHES "\\(GCC\\) 3\\.")
+ if("${lang}" STREQUAL "Fortran")
+ # The GNU Fortran compiler reports an error:
+ # no input files; unwilling to write output files
+ # when the response file is passed with "-Wl,@".
+ set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 0)
+ else()
+ # Use "-Wl,@" to pass the response file to the linker.
+ set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-Wl,@")
+ endif()
+ # The GNU 3.x compilers do not support response files (only linkers).
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 0)
+ # Link libraries are generated only for the front-end.
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
+ else()
+ # Use "@" to pass the response file to the front-end.
+ set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "@")
+ endif()
+
+ # Binary link rules.
+ set(CMAKE_${lang}_CREATE_SHARED_MODULE
+ "<CMAKE_${lang}_COMPILER> <CMAKE_SHARED_MODULE_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS> -o <TARGET> ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>")
+ set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
+ "<CMAKE_${lang}_COMPILER> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>")
+ set(CMAKE_${lang}_LINK_EXECUTABLE
+ "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>")
+
+ list(APPEND CMAKE_${lang}_ABI_FILES "Platform/Windows-GNU-${lang}-ABI")
+
+ # Support very long lists of object files.
+ # TODO: check for which gcc versions this is still needed, not needed for gcc >= 4.4.
+ # Ninja generator doesn't support this work around.
+ if("${CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG}" STREQUAL "@" AND NOT CMAKE_GENERATOR MATCHES "Ninja")
+ foreach(rule CREATE_SHARED_MODULE CREATE_SHARED_LIBRARY LINK_EXECUTABLE)
+ # The gcc/collect2/ld toolchain does not use response files
+ # internally so we cannot pass long object lists. Instead pass
+ # the object file list in a response file to the archiver to put
+ # them in a temporary archive. Hand the archive to the linker.
+ string(REPLACE "<OBJECTS>" "-Wl,--whole-archive <OBJECT_DIR>/objects.a -Wl,--no-whole-archive"
+ CMAKE_${lang}_${rule} "${CMAKE_${lang}_${rule}}")
+ set(CMAKE_${lang}_${rule}
+ "<CMAKE_COMMAND> -E remove -f <OBJECT_DIR>/objects.a"
+ "<CMAKE_AR> cr <OBJECT_DIR>/objects.a <OBJECTS>"
+ "${CMAKE_${lang}_${rule}}"
+ )
+ endforeach()
+ endif()
+endmacro()
+
+macro(__windows_compiler_gnu_abi lang)
+ if(CMAKE_NO_GNUtoMS)
+ set(CMAKE_GNUtoMS 0)
+ else()
+ option(CMAKE_GNUtoMS "Convert GNU import libraries to MS format (requires Visual Studio)" OFF)
+ endif()
+
+ if(CMAKE_GNUtoMS AND NOT CMAKE_GNUtoMS_LIB)
+ # Find MS development environment setup script for this architecture.
+ if("${CMAKE_SIZEOF_VOID_P}" EQUAL 4)
+ find_program(CMAKE_GNUtoMS_VCVARS NAMES vcvars32.bat
+ DOC "Visual Studio vcvars32.bat"
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\12.0\\Setup\\VC;ProductDir]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0\\Setup\\VC;ProductDir]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0\\Setup\\VC;ProductDir]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\Setup\\VC;ProductDir]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup\\VC;ProductDir]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.1\\Setup\\VC;ProductDir]/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++;ProductDir]/bin"
+ )
+ set(CMAKE_GNUtoMS_ARCH x86)
+ elseif("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ find_program(CMAKE_GNUtoMS_VCVARS NAMES vcvars64.bat vcvarsamd64.bat
+ DOC "Visual Studio vcvarsamd64.bat"
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\12.0\\Setup\\VC;ProductDir]/bin/amd64"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0\\Setup\\VC;ProductDir]/bin/amd64"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0\\Setup\\VC;ProductDir]/bin/amd64"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\Setup\\VC;ProductDir]/bin/amd64"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup\\VC;ProductDir]/bin/amd64"
+ )
+ set(CMAKE_GNUtoMS_ARCH amd64)
+ endif()
+ set_property(CACHE CMAKE_GNUtoMS_VCVARS PROPERTY ADVANCED 1)
+ if(CMAKE_GNUtoMS_VCVARS)
+ # Create helper script to run lib.exe from MS environment.
+ string(REPLACE "/" "\\" CMAKE_GNUtoMS_BAT "${CMAKE_GNUtoMS_VCVARS}")
+ set(CMAKE_GNUtoMS_LIB ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeGNUtoMS_lib.bat)
+ configure_file(${CMAKE_ROOT}/Modules/Platform/GNUtoMS_lib.bat.in ${CMAKE_GNUtoMS_LIB})
+ else()
+ message(WARNING "Disabling CMAKE_GNUtoMS option because CMAKE_GNUtoMS_VCVARS is not set.")
+ set(CMAKE_GNUtoMS 0)
+ endif()
+ endif()
+
+ if(CMAKE_GNUtoMS)
+ # Teach CMake how to create a MS import library at link time.
+ set(CMAKE_${lang}_GNUtoMS_RULE " -Wl,--output-def,<TARGET_NAME>.def"
+ "<CMAKE_COMMAND> -Dlib=\"${CMAKE_GNUtoMS_LIB}\" -Ddef=<TARGET_NAME>.def -Ddll=<TARGET> -Dimp=<TARGET_IMPLIB> -P \"${CMAKE_ROOT}/Modules/Platform/GNUtoMS_lib.cmake\""
+ )
+ endif()
+endmacro()
diff --git a/Modules/Platform/Windows-Intel-ASM.cmake b/Modules/Platform/Windows-Intel-ASM.cmake
new file mode 100644
index 0000000000..31d08c7adc
--- /dev/null
+++ b/Modules/Platform/Windows-Intel-ASM.cmake
@@ -0,0 +1,2 @@
+include(Platform/Windows-Intel)
+__windows_compiler_intel(ASM)
diff --git a/Modules/Platform/Windows-Intel-C.cmake b/Modules/Platform/Windows-Intel-C.cmake
new file mode 100644
index 0000000000..767fec541a
--- /dev/null
+++ b/Modules/Platform/Windows-Intel-C.cmake
@@ -0,0 +1,2 @@
+include(Platform/Windows-Intel)
+__windows_compiler_intel(C)
diff --git a/Modules/Platform/Windows-Intel-CXX.cmake b/Modules/Platform/Windows-Intel-CXX.cmake
new file mode 100644
index 0000000000..84cd303ec6
--- /dev/null
+++ b/Modules/Platform/Windows-Intel-CXX.cmake
@@ -0,0 +1,3 @@
+include(Platform/Windows-Intel)
+set(_COMPILE_CXX " /TP")
+__windows_compiler_intel(CXX)
diff --git a/Modules/Platform/Windows-Intel-Fortran.cmake b/Modules/Platform/Windows-Intel-Fortran.cmake
new file mode 100644
index 0000000000..40523ffe56
--- /dev/null
+++ b/Modules/Platform/Windows-Intel-Fortran.cmake
@@ -0,0 +1,11 @@
+include(Platform/Windows-Intel)
+set(CMAKE_BUILD_TYPE_INIT Debug)
+set(_COMPILE_Fortran " /fpp")
+set(CMAKE_Fortran_MODDIR_FLAG "-module:")
+set(CMAKE_Fortran_STANDARD_LIBRARIES_INIT "user32.lib")
+__windows_compiler_intel(Fortran)
+set (CMAKE_Fortran_FLAGS_INIT "/W1 /nologo /fpp /libs:dll /threads")
+set (CMAKE_Fortran_FLAGS_DEBUG_INIT "/debug:full /dbglibs")
+set (CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "/O1 /D NDEBUG")
+set (CMAKE_Fortran_FLAGS_RELEASE_INIT "/O2 /D NDEBUG")
+set (CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "/O2 /debug:full /D NDEBUG")
diff --git a/Modules/Platform/Windows-Intel.cmake b/Modules/Platform/Windows-Intel.cmake
new file mode 100644
index 0000000000..34e6b377b6
--- /dev/null
+++ b/Modules/Platform/Windows-Intel.cmake
@@ -0,0 +1,28 @@
+
+#=============================================================================
+# Copyright 2002-2010 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 module is shared by multiple languages; use include blocker.
+if(__WINDOWS_INTEL)
+ return()
+endif()
+set(__WINDOWS_INTEL 1)
+
+include(Platform/Windows-MSVC)
+macro(__windows_compiler_intel lang)
+ __windows_compiler_msvc(${lang})
+ string(REPLACE "<CMAKE_LINKER> /lib" "lib" CMAKE_${lang}_CREATE_STATIC_LIBRARY "${CMAKE_${lang}_CREATE_STATIC_LIBRARY}")
+ foreach(rule CREATE_SHARED_LIBRARY CREATE_SHARED_MODULE LINK_EXECUTABLE)
+ string(REPLACE "<CMAKE_LINKER>" "xilink" CMAKE_${lang}_${rule} "${CMAKE_${lang}_${rule}}")
+ endforeach()
+endmacro()
diff --git a/Modules/Platform/Windows-MSVC-C.cmake b/Modules/Platform/Windows-MSVC-C.cmake
new file mode 100644
index 0000000000..cbe1586e1e
--- /dev/null
+++ b/Modules/Platform/Windows-MSVC-C.cmake
@@ -0,0 +1,5 @@
+include(Platform/Windows-MSVC)
+if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 18.0)
+ set(_FS_C " /FS")
+endif()
+__windows_compiler_msvc(C)
diff --git a/Modules/Platform/Windows-MSVC-CXX.cmake b/Modules/Platform/Windows-MSVC-CXX.cmake
new file mode 100644
index 0000000000..0e85005322
--- /dev/null
+++ b/Modules/Platform/Windows-MSVC-CXX.cmake
@@ -0,0 +1,6 @@
+include(Platform/Windows-MSVC)
+set(_COMPILE_CXX " /TP")
+if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
+ set(_FS_CXX " /FS")
+endif()
+__windows_compiler_msvc(CXX)
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
new file mode 100644
index 0000000000..a72f9469ee
--- /dev/null
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -0,0 +1,277 @@
+
+#=============================================================================
+# Copyright 2001-2012 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 module is shared by multiple languages; use include blocker.
+if(__WINDOWS_MSVC)
+ return()
+endif()
+set(__WINDOWS_MSVC 1)
+
+set(CMAKE_LIBRARY_PATH_FLAG "-LIBPATH:")
+set(CMAKE_LINK_LIBRARY_FLAG "")
+set(MSVC 1)
+
+# hack: if a new cmake (which uses CMAKE_LINKER) runs on an old build tree
+# (where link was hardcoded) and where CMAKE_LINKER isn't in the cache
+# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
+# hardcode CMAKE_LINKER here to link, so it behaves as it did before, Alex
+if(NOT DEFINED CMAKE_LINKER)
+ set(CMAKE_LINKER link)
+endif()
+
+if(CMAKE_VERBOSE_MAKEFILE)
+ set(CMAKE_CL_NOLOGO)
+else()
+ set(CMAKE_CL_NOLOGO "/nologo")
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "WindowsCE")
+ set(CMAKE_CREATE_WIN32_EXE "/entry:WinMainCRTStartup")
+ set(CMAKE_CREATE_CONSOLE_EXE "/entry:mainACRTStartup")
+ set(_PLATFORM_LINK_FLAGS " /subsystem:windowsce")
+else()
+ set(CMAKE_CREATE_WIN32_EXE "/subsystem:windows")
+ set(CMAKE_CREATE_CONSOLE_EXE "/subsystem:console")
+ set(_PLATFORM_LINK_FLAGS "")
+endif()
+
+if(CMAKE_GENERATOR MATCHES "Visual Studio 6")
+ set (CMAKE_NO_BUILD_TYPE 1)
+endif()
+if(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio")
+ set (CMAKE_NO_BUILD_TYPE 1)
+endif()
+
+# make sure to enable languages after setting configuration types
+enable_language(RC)
+set(CMAKE_COMPILE_RESOURCE "rc <FLAGS> /fo<OBJECT> <SOURCE>")
+
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
+ set(MSVC_IDE 1)
+else()
+ set(MSVC_IDE 0)
+endif()
+
+if(NOT MSVC_VERSION)
+ if(CMAKE_C_SIMULATE_VERSION)
+ set(_compiler_version ${CMAKE_C_SIMULATE_VERSION})
+ elseif(CMAKE_CXX_SIMULATE_VERSION)
+ set(_compiler_version ${CMAKE_CXX_SIMULATE_VERSION})
+ elseif(CMAKE_Fortran_SIMULATE_VERSION)
+ set(_compiler_version ${CMAKE_Fortran_SIMULATE_VERSION})
+ elseif(CMAKE_C_COMPILER_VERSION)
+ set(_compiler_version ${CMAKE_C_COMPILER_VERSION})
+ else()
+ set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION})
+ endif()
+ if("${_compiler_version}" MATCHES "^([0-9]+)\\.([0-9]+)")
+ math(EXPR MSVC_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
+ else()
+ message(FATAL_ERROR "MSVC compiler version not detected properly: ${_compiler_version}")
+ endif()
+
+ set(MSVC10)
+ set(MSVC11)
+ set(MSVC12)
+ set(MSVC14)
+ set(MSVC60)
+ set(MSVC70)
+ set(MSVC71)
+ set(MSVC80)
+ set(MSVC90)
+ set(CMAKE_COMPILER_2005)
+ set(CMAKE_COMPILER_SUPPORTS_PDBTYPE)
+ if(NOT "${_compiler_version}" VERSION_LESS 19)
+ set(MSVC14 1)
+ elseif(NOT "${_compiler_version}" VERSION_LESS 18)
+ set(MSVC12 1)
+ elseif(NOT "${_compiler_version}" VERSION_LESS 17)
+ set(MSVC11 1)
+ elseif(NOT "${_compiler_version}" VERSION_LESS 16)
+ set(MSVC10 1)
+ elseif(NOT "${_compiler_version}" VERSION_LESS 15)
+ set(MSVC90 1)
+ elseif(NOT "${_compiler_version}" VERSION_LESS 14)
+ set(MSVC80 1)
+ set(CMAKE_COMPILER_2005 1)
+ elseif(NOT "${_compiler_version}" VERSION_LESS 13.10)
+ set(MSVC71 1)
+ elseif(NOT "${_compiler_version}" VERSION_LESS 13)
+ set(MSVC70 1)
+ else()
+ set(MSVC60 1)
+ set(CMAKE_COMPILER_SUPPORTS_PDBTYPE 1)
+ endif()
+endif()
+
+if(MSVC_C_ARCHITECTURE_ID MATCHES 64 OR MSVC_CXX_ARCHITECTURE_ID MATCHES 64)
+ set(CMAKE_CL_64 1)
+else()
+ set(CMAKE_CL_64 0)
+endif()
+if(CMAKE_FORCE_WIN64 OR CMAKE_FORCE_IA64)
+ set(CMAKE_CL_64 1)
+endif()
+
+if("${MSVC_VERSION}" GREATER 1599)
+ set(MSVC_INCREMENTAL_DEFAULT ON)
+endif()
+
+# default to Debug builds
+set(CMAKE_BUILD_TYPE_INIT Debug)
+
+if(WINCE)
+ foreach(lang C CXX)
+ set(_MSVC_${lang}_ARCHITECTURE_FAMILY "${MSVC_${lang}_ARCHITECTURE_ID}")
+ if(_MSVC_${lang}_ARCHITECTURE_FAMILY STREQUAL "THUMB")
+ set(_MSVC_${lang}_ARCHITECTURE_FAMILY "ARM")
+ elseif(_MSVC_${lang}_ARCHITECTURE_FAMILY MATCHES "^SH")
+ set(_MSVC_${lang}_ARCHITECTURE_FAMILY "SHx")
+ endif()
+ string(TOUPPER "${_MSVC_${lang}_ARCHITECTURE_FAMILY}" _MSVC_${lang}_ARCHITECTURE_FAMILY_UPPER)
+ endforeach()
+
+ if("${CMAKE_SYSTEM_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)")
+ math(EXPR _CE_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
+ elseif("${CMAKE_SYSTEM_VERSION}" STREQUAL "")
+ set(_CE_VERSION "500")
+ else()
+ message(FATAL_ERROR "Invalid Windows CE version: ${CMAKE_SYSTEM_VERSION}")
+ endif()
+
+ set(_PLATFORM_DEFINES "/D_WIN32_WCE=0x${_CE_VERSION} /DUNDER_CE")
+ set(_PLATFORM_DEFINES_C " /D${_MSVC_C_ARCHITECTURE_FAMILY} /D_${_MSVC_C_ARCHITECTURE_FAMILY_UPPER}_")
+ set(_PLATFORM_DEFINES_CXX " /D${_MSVC_CXX_ARCHITECTURE_FAMILY} /D_${_MSVC_CXX_ARCHITECTURE_FAMILY_UPPER}_")
+
+ set(_RTC1 "")
+ set(_FLAGS_CXX " /GR /EHsc")
+ set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib")
+ set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib")
+
+ if (MSVC_VERSION LESS 1600)
+ set(CMAKE_C_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT} corelibc.lib")
+ endif ()
+elseif(WINDOWS_PHONE OR WINDOWS_STORE)
+ set(_PLATFORM_DEFINES "/DWIN32")
+ set(_FLAGS_C " /DUNICODE /D_UNICODE")
+ set(_FLAGS_CXX " /DUNICODE /D_UNICODE /GR /EHsc")
+ if(WINDOWS_PHONE)
+ set(CMAKE_C_STANDARD_LIBRARIES_INIT "WindowsPhoneCore.lib RuntimeObject.lib PhoneAppModelHost.lib")
+ elseif(MSVC_C_ARCHITECTURE_ID STREQUAL ARM OR MSVC_CXX_ARCHITECTURE_ID STREQUAL ARM)
+ set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib")
+ else()
+ set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib")
+ endif()
+else()
+ set(_PLATFORM_DEFINES "/DWIN32")
+
+ if(MSVC_C_ARCHITECTURE_ID STREQUAL ARM OR MSVC_CXX_ARCHITECTURE_ID STREQUAL ARM)
+ set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib")
+ elseif(MSVC_VERSION GREATER 1310)
+ set(_RTC1 "/RTC1")
+ set(_FLAGS_CXX " /GR /EHsc")
+ set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib")
+ else()
+ set(_RTC1 "/GZ")
+ set(_FLAGS_CXX " /GR /GX")
+ set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib")
+ endif()
+
+ if(MSVC_VERSION LESS 1310)
+ set(_FLAGS_C " /Zm1000${_FLAGS_C}")
+ set(_FLAGS_CXX " /Zm1000${_FLAGS_CXX}")
+ endif()
+endif()
+
+set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")
+
+# executable linker flags
+set (CMAKE_LINK_DEF_FILE_FLAG "/DEF:")
+# set the machine type
+if(MSVC_C_ARCHITECTURE_ID)
+ set(_MACHINE_ARCH_FLAG "/machine:${MSVC_C_ARCHITECTURE_ID}")
+elseif(MSVC_CXX_ARCHITECTURE_ID)
+ set(_MACHINE_ARCH_FLAG "/machine:${MSVC_CXX_ARCHITECTURE_ID}")
+elseif(MSVC_Fortran_ARCHITECTURE_ID)
+ set(_MACHINE_ARCH_FLAG "/machine:${MSVC_Fortran_ARCHITECTURE_ID}")
+endif()
+set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} ${_MACHINE_ARCH_FLAG}")
+unset(_MACHINE_ARCH_FLAG)
+
+# add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype
+# on versions that support it
+set( MSVC_INCREMENTAL_YES_FLAG "")
+if(NOT WINDOWS_PHONE AND NOT WINDOWS_STORE)
+ if(NOT MSVC_INCREMENTAL_DEFAULT)
+ set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:YES")
+ else()
+ set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL" )
+ endif()
+endif()
+
+if (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
+ set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}")
+ set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}")
+else ()
+ set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}")
+ set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}")
+endif ()
+# for release and minsize release default to no incremental linking
+set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT "/INCREMENTAL:NO")
+set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO")
+
+# copy the EXE_LINKER flags to SHARED and MODULE linker flags
+# shared linker flags
+set (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT})
+set (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
+set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
+set (CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT})
+set (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT})
+# module linker flags
+set (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT})
+
+macro(__windows_compiler_msvc lang)
+ if(NOT MSVC_VERSION LESS 1400)
+ # for 2005 make sure the manifest is put in the dll with mt
+ set(_CMAKE_VS_LINK_DLL "<CMAKE_COMMAND> -E vs_link_dll ")
+ set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe ")
+ endif()
+ set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
+ "${_CMAKE_VS_LINK_DLL}<CMAKE_LINKER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /dll /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR>${_PLATFORM_LINK_FLAGS} <LINK_FLAGS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")
+
+ set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY})
+ set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_LINKER> /lib ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ")
+
+ set(CMAKE_${lang}_COMPILE_OBJECT
+ "<CMAKE_${lang}_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> /Fo<OBJECT> /Fd<TARGET_COMPILE_PDB>${_FS_${lang}} -c <SOURCE>${CMAKE_END_TEMP_FILE}")
+ set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE
+ "<CMAKE_${lang}_COMPILER> > <PREPROCESSED_SOURCE> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> -E <SOURCE>${CMAKE_END_TEMP_FILE}")
+ set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE
+ "<CMAKE_${lang}_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> /FoNUL /FAs /Fa<ASSEMBLY_SOURCE> /c <SOURCE>${CMAKE_END_TEMP_FILE}")
+
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
+ set(CMAKE_${lang}_LINK_EXECUTABLE
+ "${_CMAKE_VS_LINK_EXE}<CMAKE_LINKER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR>${_PLATFORM_LINK_FLAGS} <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
+
+ set(CMAKE_${lang}_FLAGS_INIT "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} /D_WINDOWS /W3${_FLAGS_${lang}}")
+ set(CMAKE_${lang}_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od ${_RTC1}")
+ set(CMAKE_${lang}_FLAGS_RELEASE_INIT "/MD /O2 /Ob2 /D NDEBUG")
+ 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)
+endmacro()
diff --git a/Modules/Platform/Windows-NMcl.cmake b/Modules/Platform/Windows-NMcl.cmake
new file mode 100644
index 0000000000..7add0b060a
--- /dev/null
+++ b/Modules/Platform/Windows-NMcl.cmake
@@ -0,0 +1,4 @@
+# this is for the numega compiler which is really a front
+# end for visual studio, but adds memory checking code.
+
+include(Platform/Windows-cl)
diff --git a/Modules/Platform/Windows-df.cmake b/Modules/Platform/Windows-df.cmake
new file mode 100644
index 0000000000..211cc9d934
--- /dev/null
+++ b/Modules/Platform/Windows-df.cmake
@@ -0,0 +1,68 @@
+# compiler support for fortran CVF compiler on windows
+
+set(CMAKE_WINDOWS_OBJECT_PATH 1)
+set(CMAKE_LIBRARY_PATH_FLAG "-LIBPATH:")
+set(CMAKE_LINK_LIBRARY_FLAG "")
+set(WIN32 1)
+if(CMAKE_VERBOSE_MAKEFILE)
+ set(CMAKE_CL_NOLOGO)
+else()
+ set(CMAKE_CL_NOLOGO "/nologo")
+endif()
+
+set(CMAKE_Fortran_MODDIR_FLAG "-module:")
+
+set(CMAKE_Fortran_CREATE_SHARED_LIBRARY
+ "link ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} /out:<TARGET> /dll <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")
+
+set(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
+
+# create a C++ static library
+set(CMAKE_Fortran_CREATE_STATIC_LIBRARY "lib ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ")
+
+# compile a C++ file into an object file
+set(CMAKE_Fortran_COMPILE_OBJECT
+ "<CMAKE_Fortran_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} /object:<OBJECT> <FLAGS> /compile_only <SOURCE>${CMAKE_END_TEMP_FILE}")
+
+set(CMAKE_COMPILE_RESOURCE "rc <FLAGS> /fo<OBJECT> <SOURCE>")
+
+set(CMAKE_Fortran_LINK_EXECUTABLE
+ "<CMAKE_Fortran_COMPILER> ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} <FLAGS> /exe:<TARGET> <OBJECTS> /link <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
+
+set(CMAKE_CREATE_WIN32_EXE /winapp)
+set(CMAKE_CREATE_CONSOLE_EXE )
+
+if(CMAKE_GENERATOR MATCHES "Visual Studio 6")
+ set (CMAKE_NO_BUILD_TYPE 1)
+endif()
+if(CMAKE_GENERATOR MATCHES "Visual Studio 7" OR CMAKE_GENERATOR MATCHES "Visual Studio 8")
+ set (CMAKE_NO_BUILD_TYPE 1)
+endif()
+# does the compiler support pdbtype and is it the newer compiler
+
+set(CMAKE_BUILD_TYPE_INIT Debug)
+set (CMAKE_Fortran_FLAGS_INIT "")
+set (CMAKE_Fortran_FLAGS_DEBUG_INIT "/debug:full")
+set (CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "/Optimize:2 /Define:NDEBUG")
+set (CMAKE_Fortran_FLAGS_RELEASE_INIT "/Optimize:1 /Define:NDEBUG")
+set (CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "/Optimize:1 /debug:full /Define:NDEBUG")
+
+set (CMAKE_Fortran_STANDARD_LIBRARIES_INIT "user32.lib")
+
+# executable linker flags
+set (CMAKE_LINK_DEF_FILE_FLAG "/DEF:")
+set (CMAKE_EXE_LINKER_FLAGS_INIT " /INCREMENTAL:YES")
+if (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
+ set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept")
+ set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept")
+else ()
+ set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug")
+ set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug")
+endif ()
+
+set (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT})
+set (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
+set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT})
+set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT})
diff --git a/Modules/Platform/Windows-wcl386.cmake b/Modules/Platform/Windows-wcl386.cmake
new file mode 100644
index 0000000000..ac410de1ba
--- /dev/null
+++ b/Modules/Platform/Windows-wcl386.cmake
@@ -0,0 +1,119 @@
+set(CMAKE_LIBRARY_PATH_FLAG "libpath ")
+set(CMAKE_LINK_LIBRARY_FLAG "library ")
+set(CMAKE_LINK_LIBRARY_FILE_FLAG "library")
+
+if(CMAKE_VERBOSE_MAKEFILE)
+ set(CMAKE_WCL_QUIET)
+ set(CMAKE_WLINK_QUIET)
+ set(CMAKE_LIB_QUIET)
+else()
+ set(CMAKE_WCL_QUIET "-zq")
+ set(CMAKE_WLINK_QUIET "option quiet")
+ set(CMAKE_LIB_QUIET "-q")
+endif()
+
+set(CMAKE_EXE_LINKER_FLAGS_INIT)
+set(CMAKE_CREATE_WIN32_EXE "system nt_win" )
+set(CMAKE_CREATE_CONSOLE_EXE "system nt" )
+set(CMAKE_SHARED_LINKER_FLAGS_INIT "system nt_dll")
+set(CMAKE_MODULE_LINKER_FLAGS_INIT "system nt_dll")
+foreach(type SHARED MODULE EXE)
+ set(CMAKE_${type}_LINKER_FLAGS_DEBUG_INIT "debug all opt map, symfile")
+ set(CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO_INIT "debug all opt map, symfile")
+endforeach()
+
+set(CMAKE_C_COMPILE_OPTIONS_DLL "-bd") # Note: This variable is a ';' separated list
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-bd") # ... while this is a space separated string.
+
+set(CMAKE_RC_COMPILER "rc" )
+
+set(CMAKE_BUILD_TYPE_INIT Debug)
+
+# single/multi-threaded /-bm
+# static/DLL run-time libraries /-br
+# default is setup for multi-threaded + DLL run-time libraries
+set (CMAKE_C_FLAGS_INIT "-bt=nt -w3 -dWIN32 -br -bm")
+set (CMAKE_CXX_FLAGS_INIT "-bt=nt -xs -w3 -dWIN32 -br -bm")
+foreach(lang C CXX)
+ set (CMAKE_${lang}_FLAGS_DEBUG_INIT "-d2")
+ set (CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-s -os -d0 -dNDEBUG")
+ set (CMAKE_${lang}_FLAGS_RELEASE_INIT "-s -ot -d0 -dNDEBUG")
+ set (CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-s -ot -d1 -dNDEBUG")
+endforeach()
+
+foreach(type CREATE_SHARED_LIBRARY CREATE_SHARED_MODULE LINK_EXECUTABLE)
+ set(CMAKE_C_${type}_USE_WATCOM_QUOTE 1)
+ set(CMAKE_CXX_${type}_USE_WATCOM_QUOTE 1)
+endforeach()
+
+set(CMAKE_C_CREATE_IMPORT_LIBRARY
+ "wlib -c -q -n -b <TARGET_IMPLIB> +<TARGET_QUOTED>")
+set(CMAKE_CXX_CREATE_IMPORT_LIBRARY ${CMAKE_C_CREATE_IMPORT_LIBRARY})
+
+set(CMAKE_C_LINK_EXECUTABLE
+ "wlink ${CMAKE_START_TEMP_FILE} ${CMAKE_WLINK_QUIET} name <TARGET> <LINK_FLAGS> file {<OBJECTS>} <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")
+
+
+set(CMAKE_CXX_LINK_EXECUTABLE ${CMAKE_C_LINK_EXECUTABLE})
+
+# compile a C++ file into an object file
+set(CMAKE_CXX_COMPILE_OBJECT
+ "<CMAKE_CXX_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_WCL_QUIET} <FLAGS> -d+ <DEFINES> -fo<OBJECT> -c -cc++ <SOURCE>${CMAKE_END_TEMP_FILE}")
+
+# compile a C file into an object file
+set(CMAKE_C_COMPILE_OBJECT
+ "<CMAKE_C_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_WCL_QUIET} <FLAGS> -d+ <DEFINES> -fo<OBJECT> -c -cc <SOURCE>${CMAKE_END_TEMP_FILE}")
+
+# preprocess a C source file
+set(CMAKE_C_CREATE_PREPROCESSED_SOURCE
+ "<CMAKE_C_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_WCL_QUIET} <FLAGS> -d+ <DEFINES> -fo<PREPROCESSED_SOURCE> -pl -cc <SOURCE>${CMAKE_END_TEMP_FILE}")
+
+# preprocess a C++ source file
+set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE
+ "<CMAKE_CXX_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_WCL_QUIET} <FLAGS> -d+ <DEFINES> -fo<PREPROCESSED_SOURCE> -pl -cc++ <SOURCE>${CMAKE_END_TEMP_FILE}")
+
+set(CMAKE_CXX_CREATE_SHARED_LIBRARY
+ "wlink ${CMAKE_START_TEMP_FILE} ${CMAKE_WLINK_QUIET} name <TARGET> <LINK_FLAGS> option implib=<TARGET_IMPLIB> file {<OBJECTS>} <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")
+string(REPLACE " option implib=<TARGET_IMPLIB>" ""
+ CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
+
+# create a C shared library
+set(CMAKE_C_CREATE_SHARED_LIBRARY ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
+
+# create a C shared module
+set(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_MODULE})
+
+# create a C++ static library
+set(CMAKE_CXX_CREATE_STATIC_LIBRARY "wlib ${CMAKE_LIB_QUIET} -c -n -b <TARGET_QUOTED> <LINK_FLAGS> <OBJECTS> ")
+
+# create a C static library
+set(CMAKE_C_CREATE_STATIC_LIBRARY ${CMAKE_CXX_CREATE_STATIC_LIBRARY})
+
+if(NOT _CMAKE_WATCOM_VERSION)
+ set(_CMAKE_WATCOM_VERSION 1)
+ if(CMAKE_C_COMPILER_VERSION)
+ set(_compiler_version ${CMAKE_C_COMPILER_VERSION})
+ set(_compiler_id ${CMAKE_C_COMPILER_ID})
+ else()
+ set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION})
+ set(_compiler_id ${CMAKE_CXX_COMPILER_ID})
+ endif()
+ set(WATCOM16)
+ set(WATCOM17)
+ set(WATCOM18)
+ set(WATCOM19)
+ if("${_compiler_id}" STREQUAL "OpenWatcom")
+ if("${_compiler_version}" VERSION_LESS 1.7)
+ set(WATCOM16 1)
+ endif()
+ if("${_compiler_version}" VERSION_EQUAL 1.7)
+ set(WATCOM17 1)
+ endif()
+ if("${_compiler_version}" VERSION_EQUAL 1.8)
+ set(WATCOM18 1)
+ endif()
+ if("${_compiler_version}" VERSION_EQUAL 1.9)
+ set(WATCOM19 1)
+ endif()
+ endif()
+endif()
diff --git a/Modules/Platform/Windows-windres.cmake b/Modules/Platform/Windows-windres.cmake
new file mode 100644
index 0000000000..01d6be3dfd
--- /dev/null
+++ b/Modules/Platform/Windows-windres.cmake
@@ -0,0 +1 @@
+set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <FLAGS> <DEFINES> <SOURCE> <OBJECT>")
diff --git a/Modules/Platform/Windows.cmake b/Modules/Platform/Windows.cmake
new file mode 100644
index 0000000000..9a937a7e8f
--- /dev/null
+++ b/Modules/Platform/Windows.cmake
@@ -0,0 +1,44 @@
+set(WIN32 1)
+
+if(CMAKE_SYSTEM_NAME STREQUAL "WindowsCE")
+ set(WINCE 1)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone")
+ set(WINDOWS_PHONE 1)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
+ set(WINDOWS_STORE 1)
+endif()
+
+set(CMAKE_STATIC_LIBRARY_PREFIX "")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
+set(CMAKE_SHARED_LIBRARY_PREFIX "") # lib
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") # .so
+set(CMAKE_IMPORT_LIBRARY_PREFIX "")
+set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib")
+set(CMAKE_EXECUTABLE_SUFFIX ".exe") # .exe
+set(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
+set(CMAKE_DL_LIBS "")
+
+set(CMAKE_FIND_LIBRARY_PREFIXES "")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
+
+# for borland make long command lines are redirected to a file
+# with the following syntax, see Windows-bcc32.cmake for use
+if(CMAKE_GENERATOR MATCHES "Borland")
+ set(CMAKE_START_TEMP_FILE "@&&|\n")
+ set(CMAKE_END_TEMP_FILE "\n|")
+endif()
+
+# for nmake make long command lines are redirected to a file
+# with the following syntax, see Windows-bcc32.cmake for use
+if(CMAKE_GENERATOR MATCHES "NMake")
+ set(CMAKE_START_TEMP_FILE "@<<\n")
+ set(CMAKE_END_TEMP_FILE "\n<<")
+endif()
+
+include(Platform/WindowsPaths)
+
+# uncomment these out to debug nmake and borland makefiles
+#set(CMAKE_START_TEMP_FILE "")
+#set(CMAKE_END_TEMP_FILE "")
+#set(CMAKE_VERBOSE_MAKEFILE 1)
+
diff --git a/Modules/Platform/WindowsCE-MSVC-C.cmake b/Modules/Platform/WindowsCE-MSVC-C.cmake
new file mode 100644
index 0000000000..ce8060bed5
--- /dev/null
+++ b/Modules/Platform/WindowsCE-MSVC-C.cmake
@@ -0,0 +1 @@
+include(Platform/Windows-MSVC-C)
diff --git a/Modules/Platform/WindowsCE-MSVC-CXX.cmake b/Modules/Platform/WindowsCE-MSVC-CXX.cmake
new file mode 100644
index 0000000000..281eadc104
--- /dev/null
+++ b/Modules/Platform/WindowsCE-MSVC-CXX.cmake
@@ -0,0 +1 @@
+include(Platform/Windows-MSVC-CXX)
diff --git a/Modules/Platform/WindowsCE.cmake b/Modules/Platform/WindowsCE.cmake
new file mode 100644
index 0000000000..65b2eaed4d
--- /dev/null
+++ b/Modules/Platform/WindowsCE.cmake
@@ -0,0 +1 @@
+include(Platform/Windows)
diff --git a/Modules/Platform/WindowsPaths.cmake b/Modules/Platform/WindowsPaths.cmake
new file mode 100644
index 0000000000..658de3bf5e
--- /dev/null
+++ b/Modules/Platform/WindowsPaths.cmake
@@ -0,0 +1,116 @@
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+# Block multiple inclusion because "CMakeCInformation.cmake" includes
+# "Platform/${CMAKE_SYSTEM_NAME}" even though the generic module
+# "CMakeSystemSpecificInformation.cmake" already included it.
+# The extra inclusion is a work-around documented next to the include()
+# call, so this can be removed when the work-around is removed.
+if(__WINDOWS_PATHS_INCLUDED)
+ return()
+endif()
+set(__WINDOWS_PATHS_INCLUDED 1)
+
+# Add the program-files folder(s) to the list of installation
+# prefixes.
+#
+# 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>
+#
+# Windows 32-bit Binary:
+# 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}")
+ 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)")
+ endif()
+ endif()
+endif()
+
+# Add the CMake install location.
+get_filename_component(_CMAKE_INSTALL_DIR "${CMAKE_ROOT}" PATH)
+get_filename_component(_CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" PATH)
+list(APPEND CMAKE_SYSTEM_PREFIX_PATH "${_CMAKE_INSTALL_DIR}")
+
+if (NOT CMAKE_FIND_NO_INSTALL_PREFIX)
+ # Add other locations.
+ 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()
+
+if(CMAKE_CROSSCOMPILING AND NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
+ # MinGW (useful when cross compiling from linux with CMAKE_FIND_ROOT_PATH set)
+ list(APPEND CMAKE_SYSTEM_PREFIX_PATH /)
+endif()
+
+list(APPEND CMAKE_SYSTEM_INCLUDE_PATH
+ )
+
+# mingw can also link against dlls which can also be in /bin, so list this too
+if (NOT CMAKE_FIND_NO_INSTALL_PREFIX)
+ list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
+ "${CMAKE_INSTALL_PREFIX}/bin"
+ )
+ if (CMAKE_STAGING_PREFIX)
+ list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
+ "${CMAKE_STAGING_PREFIX}/bin"
+ )
+ endif()
+endif()
+list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
+ "${_CMAKE_INSTALL_DIR}/bin"
+ /bin
+ )
+
+list(APPEND CMAKE_SYSTEM_PROGRAM_PATH
+ )
diff --git a/Modules/Platform/WindowsPhone-MSVC-C.cmake b/Modules/Platform/WindowsPhone-MSVC-C.cmake
new file mode 100644
index 0000000000..ce8060bed5
--- /dev/null
+++ b/Modules/Platform/WindowsPhone-MSVC-C.cmake
@@ -0,0 +1 @@
+include(Platform/Windows-MSVC-C)
diff --git a/Modules/Platform/WindowsPhone-MSVC-CXX.cmake b/Modules/Platform/WindowsPhone-MSVC-CXX.cmake
new file mode 100644
index 0000000000..281eadc104
--- /dev/null
+++ b/Modules/Platform/WindowsPhone-MSVC-CXX.cmake
@@ -0,0 +1 @@
+include(Platform/Windows-MSVC-CXX)
diff --git a/Modules/Platform/WindowsPhone.cmake b/Modules/Platform/WindowsPhone.cmake
new file mode 100644
index 0000000000..65b2eaed4d
--- /dev/null
+++ b/Modules/Platform/WindowsPhone.cmake
@@ -0,0 +1 @@
+include(Platform/Windows)
diff --git a/Modules/Platform/WindowsStore-MSVC-C.cmake b/Modules/Platform/WindowsStore-MSVC-C.cmake
new file mode 100644
index 0000000000..ce8060bed5
--- /dev/null
+++ b/Modules/Platform/WindowsStore-MSVC-C.cmake
@@ -0,0 +1 @@
+include(Platform/Windows-MSVC-C)
diff --git a/Modules/Platform/WindowsStore-MSVC-CXX.cmake b/Modules/Platform/WindowsStore-MSVC-CXX.cmake
new file mode 100644
index 0000000000..281eadc104
--- /dev/null
+++ b/Modules/Platform/WindowsStore-MSVC-CXX.cmake
@@ -0,0 +1 @@
+include(Platform/Windows-MSVC-CXX)
diff --git a/Modules/Platform/WindowsStore.cmake b/Modules/Platform/WindowsStore.cmake
new file mode 100644
index 0000000000..65b2eaed4d
--- /dev/null
+++ b/Modules/Platform/WindowsStore.cmake
@@ -0,0 +1 @@
+include(Platform/Windows)
diff --git a/Modules/Platform/Xenix.cmake b/Modules/Platform/Xenix.cmake
new file mode 100644
index 0000000000..47852f8e13
--- /dev/null
+++ b/Modules/Platform/Xenix.cmake
@@ -0,0 +1,2 @@
+include(Platform/UnixPaths)
+
diff --git a/Modules/Platform/eCos.cmake b/Modules/Platform/eCos.cmake
new file mode 100644
index 0000000000..a203826926
--- /dev/null
+++ b/Modules/Platform/eCos.cmake
@@ -0,0 +1,65 @@
+# support for eCos http://ecos.sourceware.org
+
+# Guard against multiple inclusion, which e.g. leads to multiple calls to add_definition() #12987
+if(__ECOS_CMAKE_INCLUDED)
+ return()
+endif()
+set(__ECOS_CMAKE_INCLUDED TRUE)
+
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "") # -pic
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "") # -shared
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "") # -rpath
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "") # : or empty
+
+set(CMAKE_LINK_LIBRARY_SUFFIX "")
+set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+set(CMAKE_SHARED_LIBRARY_PREFIX "lib") # lib
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".a") # .a
+set(CMAKE_EXECUTABLE_SUFFIX ".elf") # same suffix as if built using UseEcos.cmake
+set(CMAKE_DL_LIBS "" )
+
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+
+
+include(Platform/UnixPaths)
+
+# eCos can be built only with gcc
+get_property(_IN_TC GLOBAL PROPERTY IN_TRY_COMPILE)
+if(CMAKE_C_COMPILER AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "GNU" AND NOT _IN_TC)
+ message(FATAL_ERROR "GNU gcc is required for eCos")
+endif()
+if(CMAKE_CXX_COMPILER AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" AND NOT _IN_TC)
+ message(FATAL_ERROR "GNU g++ is required for eCos")
+endif()
+
+# find eCos system files
+find_path(ECOS_SYSTEM_CONFIG_HEADER_PATH NAMES pkgconf/system.h)
+find_library(ECOS_SYSTEM_TARGET_LIBRARY NAMES libtarget.a)
+
+if(NOT ECOS_SYSTEM_CONFIG_HEADER_PATH)
+ message(FATAL_ERROR "Could not find eCos pkgconf/system.h. Build eCos first and set up CMAKE_FIND_ROOT_PATH correctly.")
+endif()
+
+if(NOT ECOS_SYSTEM_TARGET_LIBRARY)
+ message(FATAL_ERROR "Could not find eCos \"libtarget.a\". Build eCos first and set up CMAKE_FIND_ROOT_PATH correctly.")
+endif()
+
+get_filename_component(ECOS_LIBTARGET_DIRECTORY "${ECOS_SYSTEM_TARGET_LIBRARY}" PATH)
+include_directories(${ECOS_SYSTEM_CONFIG_HEADER_PATH})
+add_definitions(-D__ECOS__=1 -D__ECOS=1)
+
+# special link commands for eCos executables
+set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostdlib -nostartfiles -L${ECOS_LIBTARGET_DIRECTORY} -Ttarget.ld <LINK_LIBRARIES>")
+set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostdlib -nostartfiles -L${ECOS_LIBTARGET_DIRECTORY} -Ttarget.ld <LINK_LIBRARIES>")
+
+# eCos doesn't support shared libs
+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
+
+set(CMAKE_CXX_LINK_SHARED_LIBRARY )
+set(CMAKE_CXX_LINK_MODULE_LIBRARY )
+set(CMAKE_C_LINK_SHARED_LIBRARY )
+set(CMAKE_C_LINK_MODULE_LIBRARY )
+
diff --git a/Modules/Platform/gas.cmake b/Modules/Platform/gas.cmake
new file mode 100644
index 0000000000..7d2bc84549
--- /dev/null
+++ b/Modules/Platform/gas.cmake
@@ -0,0 +1,19 @@
+if(UNIX)
+ set(CMAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION .o)
+else()
+ set(CMAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION .obj)
+endif()
+
+set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <FLAGS> -o <OBJECT> <SOURCE>")
+
+set(CMAKE_ASM${ASM_DIALECT}_CREATE_STATIC_LIBRARY
+ "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
+ "<CMAKE_RANLIB> <TARGET> ")
+
+set(CMAKE_ASM${ASM_DIALECT}_LINK_EXECUTABLE
+ "<CMAKE_LINKER> <FLAGS> <CMAKE_ASM${ASM_DIALECT}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+
+# to be done
+set(CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_LIBRARY)
+set(CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_MODULE)
+
diff --git a/Modules/Platform/kFreeBSD.cmake b/Modules/Platform/kFreeBSD.cmake
new file mode 100644
index 0000000000..c1db2594d4
--- /dev/null
+++ b/Modules/Platform/kFreeBSD.cmake
@@ -0,0 +1,4 @@
+# kFreeBSD looks just like Linux.
+include(Platform/Linux)
+
+set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-kfreebsd-gnu[a-z0-9_]*")
diff --git a/Modules/Platform/syllable.cmake b/Modules/Platform/syllable.cmake
new file mode 100644
index 0000000000..69c108db08
--- /dev/null
+++ b/Modules/Platform/syllable.cmake
@@ -0,0 +1,33 @@
+# this is the platform file for the Syllable OS (http://www.syllable.org)
+# Syllable is a free OS (GPL), which is mostly POSIX conform
+# the linker accepts the rpath related arguments, but this is later on
+# ignored by the runtime linker
+# shared libs are found exclusively via the environment variable DLL_PATH,
+# which may contain also dirs containing the special variable @bindir@
+# by default @bindir@/lib is part of DLL_PATH
+# in order to run the cmake tests successfully it is required that also
+# @bindir@/. and @bindir@/../lib are in DLL_PATH
+
+
+set(CMAKE_DL_LIBS "dl")
+set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
+set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") # -pic
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+#set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
+
+# Initialize C link type selection flags. These flags are used when
+# building a shared library, shared module, or executable that links
+# to other libraries to select whether to use the static or shared
+# versions of the libraries.
+foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+ set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-Bstatic")
+ set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
+endforeach()
+
+include(Platform/UnixPaths)
+
+# these are Syllable specific:
+list(APPEND CMAKE_SYSTEM_PREFIX_PATH /usr/indexes)
diff --git a/Modules/ProcessorCount.cmake b/Modules/ProcessorCount.cmake
new file mode 100644
index 0000000000..8f21adf987
--- /dev/null
+++ b/Modules/ProcessorCount.cmake
@@ -0,0 +1,231 @@
+#.rst:
+# ProcessorCount
+# --------------
+#
+# ProcessorCount(var)
+#
+# Determine the number of processors/cores and save value in ${var}
+#
+# Sets the variable named ${var} to the number of physical cores
+# available on the machine if the information can be determined.
+# Otherwise it is set to 0. Currently this functionality is implemented
+# for AIX, cygwin, FreeBSD, HPUX, IRIX, Linux, Mac OS X, QNX, Sun and
+# Windows.
+#
+# This function is guaranteed to return a positive integer (>=1) if it
+# succeeds. It returns 0 if there's a problem determining the processor
+# count.
+#
+# Example use, in a ctest -S dashboard script:
+#
+# ::
+#
+# include(ProcessorCount)
+# ProcessorCount(N)
+# if(NOT N EQUAL 0)
+# set(CTEST_BUILD_FLAGS -j${N})
+# set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
+# endif()
+#
+#
+#
+# This function is intended to offer an approximation of the value of
+# the number of compute cores available on the current machine, such
+# that you may use that value for parallel building and parallel
+# testing. It is meant to help utilize as much of the machine as seems
+# reasonable. Of course, knowledge of what else might be running on the
+# machine simultaneously should be used when deciding whether to request
+# a machine's full capacity all for yourself.
+
+# A more reliable way might be to compile a small C program that uses the CPUID
+# instruction, but that again requires compiler support or compiling assembler
+# code.
+
+#=============================================================================
+# 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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+function(ProcessorCount var)
+ # Unknown:
+ set(count 0)
+
+ if(WIN32)
+ # Windows:
+ set(count "$ENV{NUMBER_OF_PROCESSORS}")
+ #message("ProcessorCount: WIN32, trying environment variable")
+ endif()
+
+ if(NOT count)
+ # Mac, FreeBSD, OpenBSD (systems with sysctl):
+ find_program(ProcessorCount_cmd_sysctl sysctl
+ PATHS /usr/sbin /sbin)
+ mark_as_advanced(ProcessorCount_cmd_sysctl)
+ if(ProcessorCount_cmd_sysctl)
+ execute_process(COMMAND ${ProcessorCount_cmd_sysctl} -n hw.ncpu
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE count)
+ #message("ProcessorCount: trying sysctl '${ProcessorCount_cmd_sysctl}'")
+ endif()
+ endif()
+
+ if(NOT count)
+ # Linux (systems with getconf):
+ find_program(ProcessorCount_cmd_getconf getconf)
+ mark_as_advanced(ProcessorCount_cmd_getconf)
+ if(ProcessorCount_cmd_getconf)
+ execute_process(COMMAND ${ProcessorCount_cmd_getconf} _NPROCESSORS_ONLN
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE count)
+ #message("ProcessorCount: trying getconf '${ProcessorCount_cmd_getconf}'")
+ endif()
+ endif()
+
+ if(NOT count)
+ # HPUX (systems with machinfo):
+ find_program(ProcessorCount_cmd_machinfo machinfo
+ PATHS /usr/contrib/bin)
+ mark_as_advanced(ProcessorCount_cmd_machinfo)
+ if(ProcessorCount_cmd_machinfo)
+ execute_process(COMMAND ${ProcessorCount_cmd_machinfo}
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE machinfo_output)
+ string(REGEX MATCHALL "Number of CPUs = ([0-9]+)" procs "${machinfo_output}")
+ set(count "${CMAKE_MATCH_1}")
+ if(NOT count)
+ string(REGEX MATCHALL "([0-9]+) logical processors" procs "${machinfo_output}")
+ set(count "${CMAKE_MATCH_1}")
+ endif()
+ #message("ProcessorCount: trying machinfo '${ProcessorCount_cmd_machinfo}'")
+ else()
+ find_program(ProcessorCount_cmd_mpsched mpsched)
+ mark_as_advanced(ProcessorCount_cmd_mpsched)
+ if(ProcessorCount_cmd_mpsched)
+ execute_process(COMMAND ${ProcessorCount_cmd_mpsched} -s
+ OUTPUT_QUIET
+ ERROR_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE mpsched_output)
+ string(REGEX MATCHALL "Processor Count *: *([0-9]+)" procs "${mpsched_output}")
+ set(count "${CMAKE_MATCH_1}")
+ #message("ProcessorCount: trying mpsched -s '${ProcessorCount_cmd_mpsched}'")
+ endif()
+ endif()
+ endif()
+
+ if(NOT count)
+ # IRIX (systems with hinv):
+ find_program(ProcessorCount_cmd_hinv hinv
+ PATHS /sbin)
+ mark_as_advanced(ProcessorCount_cmd_hinv)
+ if(ProcessorCount_cmd_hinv)
+ execute_process(COMMAND ${ProcessorCount_cmd_hinv}
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE hinv_output)
+ string(REGEX MATCHALL "([0-9]+) .* Processors" procs "${hinv_output}")
+ set(count "${CMAKE_MATCH_1}")
+ #message("ProcessorCount: trying hinv '${ProcessorCount_cmd_hinv}'")
+ endif()
+ endif()
+
+ if(NOT count)
+ # AIX (systems with lsconf):
+ find_program(ProcessorCount_cmd_lsconf lsconf
+ PATHS /usr/sbin)
+ mark_as_advanced(ProcessorCount_cmd_lsconf)
+ if(ProcessorCount_cmd_lsconf)
+ execute_process(COMMAND ${ProcessorCount_cmd_lsconf}
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE lsconf_output)
+ string(REGEX MATCHALL "Number Of Processors: ([0-9]+)" procs "${lsconf_output}")
+ set(count "${CMAKE_MATCH_1}")
+ #message("ProcessorCount: trying lsconf '${ProcessorCount_cmd_lsconf}'")
+ endif()
+ endif()
+
+ if(NOT count)
+ # QNX (systems with pidin):
+ find_program(ProcessorCount_cmd_pidin pidin)
+ mark_as_advanced(ProcessorCount_cmd_pidin)
+ if(ProcessorCount_cmd_pidin)
+ execute_process(COMMAND ${ProcessorCount_cmd_pidin} info
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE pidin_output)
+ string(REGEX MATCHALL "Processor[0-9]+: " procs "${pidin_output}")
+ list(LENGTH procs count)
+ #message("ProcessorCount: trying pidin '${ProcessorCount_cmd_pidin}'")
+ endif()
+ endif()
+
+ if(NOT count)
+ # Sun (systems where uname -X emits "NumCPU" in its output):
+ find_program(ProcessorCount_cmd_uname uname)
+ mark_as_advanced(ProcessorCount_cmd_uname)
+ if(ProcessorCount_cmd_uname)
+ execute_process(COMMAND ${ProcessorCount_cmd_uname} -X
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE uname_X_output)
+ string(REGEX MATCHALL "NumCPU = ([0-9]+)" procs "${uname_X_output}")
+ set(count "${CMAKE_MATCH_1}")
+ #message("ProcessorCount: trying uname -X '${ProcessorCount_cmd_uname}'")
+ endif()
+ endif()
+
+ # Execute this code when all previously attempted methods return empty
+ # output:
+ #
+ if(NOT count)
+ # Systems with /proc/cpuinfo:
+ set(cpuinfo_file /proc/cpuinfo)
+ if(EXISTS "${cpuinfo_file}")
+ file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$")
+ list(LENGTH procs count)
+ #message("ProcessorCount: trying cpuinfo '${cpuinfo_file}'")
+ endif()
+ endif()
+
+ if(NOT count)
+ # Haiku
+ find_program(ProcessorCount_cmd_sysinfo sysinfo)
+ if(ProcessorCount_cmd_sysinfo)
+ execute_process(COMMAND ${ProcessorCount_cmd_sysinfo}
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE sysinfo_X_output)
+ string(REGEX MATCHALL "\nCPU #[0-9]+:" procs "\n${sysinfo_X_output}")
+ list(LENGTH procs count)
+ #message("ProcessorCount: trying sysinfo '${ProcessorCount_cmd_sysinfo}'")
+ endif()
+ endif()
+
+ # Since cygwin builds of CMake do not define WIN32 anymore, but they still
+ # run on Windows, and will still have this env var defined:
+ #
+ if(NOT count)
+ set(count "$ENV{NUMBER_OF_PROCESSORS}")
+ #message("ProcessorCount: last fallback, trying environment variable")
+ endif()
+
+ # Ensure an integer return (avoid inadvertently returning an empty string
+ # or an error string)... If it's not a decimal integer, return 0:
+ #
+ if(NOT count MATCHES "^[0-9]+$")
+ set(count 0)
+ endif()
+
+ set(${var} ${count} PARENT_SCOPE)
+endfunction()
diff --git a/Modules/Qt4ConfigDependentSettings.cmake b/Modules/Qt4ConfigDependentSettings.cmake
new file mode 100644
index 0000000000..03fb8449a2
--- /dev/null
+++ b/Modules/Qt4ConfigDependentSettings.cmake
@@ -0,0 +1,301 @@
+#.rst:
+# Qt4ConfigDependentSettings
+# --------------------------
+#
+#
+#
+# This file is included by FindQt4.cmake, don't include it directly.
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+
+###############################################
+#
+# configuration/system dependent settings
+#
+###############################################
+
+# find dependencies for some Qt modules
+# when doing builds against a static Qt, they are required
+# when doing builds against a shared Qt, they are not required
+# if a user needs the dependencies, and they couldn't be found, they can set
+# the variables themselves.
+
+set(QT_QTGUI_LIB_DEPENDENCIES "")
+set(QT_QTCORE_LIB_DEPENDENCIES "")
+set(QT_QTNETWORK_LIB_DEPENDENCIES "")
+set(QT_QTOPENGL_LIB_DEPENDENCIES "")
+set(QT_QTDBUS_LIB_DEPENDENCIES "")
+set(QT_QTHELP_LIB_DEPENDENCIES ${QT_QTCLUCENE_LIBRARY})
+
+
+if(Q_WS_WIN)
+ # On Windows, qconfig.pri has "shared" for shared library builds
+ if(NOT QT_CONFIG MATCHES "shared")
+ set(QT_IS_STATIC 1)
+ endif()
+else()
+ # On other platforms, check file extension to know if its static
+ if(QT_QTCORE_LIBRARY_RELEASE)
+ get_filename_component(qtcore_lib_ext "${QT_QTCORE_LIBRARY_RELEASE}" EXT)
+ if("${qtcore_lib_ext}" STREQUAL "${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ set(QT_IS_STATIC 1)
+ endif()
+ endif()
+ if(QT_QTCORE_LIBRARY_DEBUG)
+ get_filename_component(qtcore_lib_ext "${QT_QTCORE_LIBRARY_DEBUG}" EXT)
+ if(${qtcore_lib_ext} STREQUAL ${CMAKE_STATIC_LIBRARY_SUFFIX})
+ set(QT_IS_STATIC 1)
+ endif()
+ endif()
+endif()
+
+# build using shared Qt needs -DQT_DLL on Windows
+if(Q_WS_WIN AND NOT QT_IS_STATIC)
+ set(QT_DEFINITIONS ${QT_DEFINITIONS} -DQT_DLL)
+endif()
+
+if(NOT QT_IS_STATIC)
+ return()
+endif()
+
+# QtOpenGL dependencies
+find_package(OpenGL)
+set (QT_QTOPENGL_LIB_DEPENDENCIES ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY})
+
+
+## system png
+if(QT_QCONFIG MATCHES "system-png")
+ find_package(PNG)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${PNG_LIBRARY})
+endif()
+
+## system jpeg
+if(QT_QCONFIG MATCHES "system-jpeg")
+ find_package(JPEG)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${JPEG_LIBRARIES})
+endif()
+
+## system tiff
+if(QT_QCONFIG MATCHES "system-tiff")
+ find_package(TIFF)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${TIFF_LIBRARIES})
+endif()
+
+## system mng
+if(QT_QCONFIG MATCHES "system-mng")
+ find_library(MNG_LIBRARY NAMES mng)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${MNG_LIBRARY})
+endif()
+
+# for X11, get X11 library directory
+if(Q_WS_X11)
+ find_package(X11)
+endif()
+
+
+## X11 SM
+if(QT_QCONFIG MATCHES "x11sm")
+ if(X11_SM_LIB AND X11_ICE_LIB)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${X11_SM_LIB} ${X11_ICE_LIB})
+ endif()
+endif()
+
+
+## Xi
+if(QT_QCONFIG MATCHES "tablet")
+ if(X11_Xi_LIB)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${X11_Xi_LIB})
+ endif()
+endif()
+
+
+## Xrender
+if(QT_QCONFIG MATCHES "xrender")
+ if(X11_Xrender_LIB)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${X11_Xrender_LIB})
+ endif()
+endif()
+
+
+## Xrandr
+if(QT_QCONFIG MATCHES "xrandr")
+ if(X11_Xrandr_LIB)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${X11_Xrandr_LIB})
+ endif()
+endif()
+
+
+## Xcursor
+if(QT_QCONFIG MATCHES "xcursor")
+ if(X11_Xcursor_LIB)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${X11_Xcursor_LIB})
+ endif()
+endif()
+
+
+## Xinerama
+if(QT_QCONFIG MATCHES "xinerama")
+ if(X11_Xinerama_LIB)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${X11_Xinerama_LIB})
+ endif()
+endif()
+
+
+## Xfixes
+if(QT_QCONFIG MATCHES "xfixes")
+ if(X11_Xfixes_LIB)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${X11_Xfixes_LIB})
+ endif()
+endif()
+
+
+## fontconfig
+if(QT_QCONFIG MATCHES "fontconfig")
+ find_library(QT_FONTCONFIG_LIBRARY NAMES fontconfig)
+ mark_as_advanced(QT_FONTCONFIG_LIBRARY)
+ if(QT_FONTCONFIG_LIBRARY)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_FONTCONFIG_LIBRARY})
+ endif()
+endif()
+
+
+## system-freetype
+if(QT_QCONFIG MATCHES "system-freetype")
+ find_package(Freetype)
+ if(FREETYPE_LIBRARIES)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${FREETYPE_LIBRARIES})
+ endif()
+endif()
+
+
+## system-zlib
+if(QT_QCONFIG MATCHES "system-zlib")
+ find_package(ZLIB)
+ set(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ${ZLIB_LIBRARIES})
+endif()
+
+
+## openssl
+if(NOT Q_WS_WIN)
+ set(_QT_NEED_OPENSSL 0)
+ if(QT_VERSION_MINOR LESS 4 AND QT_QCONFIG MATCHES "openssl")
+ set(_QT_NEED_OPENSSL 1)
+ endif()
+ if(QT_VERSION_MINOR GREATER 3 AND QT_QCONFIG MATCHES "openssl-linked")
+ set(_QT_NEED_OPENSSL 1)
+ endif()
+ if(_QT_NEED_OPENSSL)
+ find_package(OpenSSL)
+ if(OPENSSL_LIBRARIES)
+ set(QT_QTNETWORK_LIB_DEPENDENCIES ${QT_QTNETWORK_LIB_DEPENDENCIES} ${OPENSSL_LIBRARIES})
+ endif()
+ endif()
+endif()
+
+
+## dbus
+if(QT_QCONFIG MATCHES "dbus")
+
+ find_library(QT_DBUS_LIBRARY NAMES dbus-1 )
+ if(QT_DBUS_LIBRARY)
+ set(QT_QTDBUS_LIB_DEPENDENCIES ${QT_QTDBUS_LIB_DEPENDENCIES} ${QT_DBUS_LIBRARY})
+ endif()
+ mark_as_advanced(QT_DBUS_LIBRARY)
+
+endif()
+
+
+## glib
+if(QT_QCONFIG MATCHES "glib")
+
+ # Qt 4.2.0+ uses glib-2.0
+ find_library(QT_GLIB_LIBRARY NAMES glib-2.0 )
+ find_library(QT_GTHREAD_LIBRARY NAMES gthread-2.0 )
+ mark_as_advanced(QT_GLIB_LIBRARY)
+ mark_as_advanced(QT_GTHREAD_LIBRARY)
+
+ if(QT_GLIB_LIBRARY AND QT_GTHREAD_LIBRARY)
+ set(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES}
+ ${QT_GTHREAD_LIBRARY} ${QT_GLIB_LIBRARY})
+ endif()
+
+
+ # Qt 4.5+ also links to gobject-2.0
+ if(QT_VERSION_MINOR GREATER 4)
+ find_library(QT_GOBJECT_LIBRARY NAMES gobject-2.0 PATHS ${_glib_query_output} )
+ mark_as_advanced(QT_GOBJECT_LIBRARY)
+
+ if(QT_GOBJECT_LIBRARY)
+ set(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES}
+ ${QT_GOBJECT_LIBRARY})
+ endif()
+ endif()
+
+endif()
+
+
+## clock-monotonic, just see if we need to link with rt
+if(QT_QCONFIG MATCHES "clock-monotonic")
+ set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
+ set(CMAKE_REQUIRED_LIBRARIES rt)
+ CHECK_SYMBOL_EXISTS(_POSIX_TIMERS "unistd.h;time.h" QT_POSIX_TIMERS)
+ set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
+ if(QT_POSIX_TIMERS)
+ find_library(QT_RT_LIBRARY NAMES rt)
+ mark_as_advanced(QT_RT_LIBRARY)
+ if(QT_RT_LIBRARY)
+ set(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ${QT_RT_LIBRARY})
+ endif()
+ endif()
+endif()
+
+
+if(Q_WS_X11)
+ # X11 libraries Qt always depends on
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${X11_Xext_LIB} ${X11_X11_LIB})
+
+ set(CMAKE_THREAD_PREFER_PTHREAD 1)
+ find_package(Threads)
+ if(CMAKE_USE_PTHREADS_INIT)
+ set(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ${CMAKE_THREAD_LIBS_INIT})
+ endif()
+
+ set (QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ${CMAKE_DL_LIBS})
+
+endif()
+
+
+if(Q_WS_WIN)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} imm32 winmm)
+ set(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ws2_32)
+endif()
+
+
+if(Q_WS_MAC)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} "-framework Carbon")
+
+ # Qt 4.0, 4.1, 4.2 use QuickTime
+ if(QT_VERSION_MINOR LESS 3)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} "-framework QuickTime")
+ endif()
+
+ # Qt 4.2+ use AppKit
+ if(QT_VERSION_MINOR GREATER 1)
+ set(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} "-framework AppKit")
+ endif()
+
+ set(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} "-framework ApplicationServices")
+endif()
+
diff --git a/Modules/Qt4Macros.cmake b/Modules/Qt4Macros.cmake
new file mode 100644
index 0000000000..8c4daac6ba
--- /dev/null
+++ b/Modules/Qt4Macros.cmake
@@ -0,0 +1,509 @@
+#.rst:
+# Qt4Macros
+# ---------
+#
+#
+#
+# This file is included by FindQt4.cmake, don't include it directly.
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+
+######################################
+#
+# Macros for building Qt files
+#
+######################################
+
+
+macro (QT4_EXTRACT_OPTIONS _qt4_files _qt4_options _qt4_target)
+ set(${_qt4_files})
+ set(${_qt4_options})
+ set(_QT4_DOING_OPTIONS FALSE)
+ set(_QT4_DOING_TARGET FALSE)
+ foreach(_currentArg ${ARGN})
+ if ("x${_currentArg}" STREQUAL "xOPTIONS")
+ set(_QT4_DOING_OPTIONS TRUE)
+ elseif ("x${_currentArg}" STREQUAL "xTARGET")
+ set(_QT4_DOING_TARGET TRUE)
+ else ()
+ if(_QT4_DOING_TARGET)
+ set(${_qt4_target} "${_currentArg}")
+ elseif(_QT4_DOING_OPTIONS)
+ list(APPEND ${_qt4_options} "${_currentArg}")
+ else()
+ list(APPEND ${_qt4_files} "${_currentArg}")
+ endif()
+ endif ()
+ endforeach()
+endmacro ()
+
+
+# macro used to create the names of output files preserving relative dirs
+macro (QT4_MAKE_OUTPUT_FILE infile prefix ext outfile )
+ string(LENGTH ${CMAKE_CURRENT_BINARY_DIR} _binlength)
+ string(LENGTH ${infile} _infileLength)
+ set(_checkinfile ${CMAKE_CURRENT_SOURCE_DIR})
+ if(_infileLength GREATER _binlength)
+ string(SUBSTRING "${infile}" 0 ${_binlength} _checkinfile)
+ if(_checkinfile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
+ file(RELATIVE_PATH rel ${CMAKE_CURRENT_BINARY_DIR} ${infile})
+ else()
+ file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile})
+ endif()
+ else()
+ file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile})
+ endif()
+ if(WIN32 AND rel MATCHES "^([a-zA-Z]):(.*)$") # absolute path
+ set(rel "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}")
+ endif()
+ set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${rel}")
+ string(REPLACE ".." "__" _outfile ${_outfile})
+ get_filename_component(outpath ${_outfile} PATH)
+ get_filename_component(_outfile ${_outfile} NAME_WE)
+ file(MAKE_DIRECTORY ${outpath})
+ set(${outfile} ${outpath}/${prefix}${_outfile}.${ext})
+endmacro ()
+
+
+macro (QT4_GET_MOC_FLAGS _moc_flags)
+ set(${_moc_flags})
+ get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)
+
+ foreach(_current ${_inc_DIRS})
+ if("${_current}" MATCHES "\\.framework/?$")
+ string(REGEX REPLACE "/[^/]+\\.framework" "" framework_path "${_current}")
+ set(${_moc_flags} ${${_moc_flags}} "-F${framework_path}")
+ else()
+ set(${_moc_flags} ${${_moc_flags}} "-I${_current}")
+ endif()
+ endforeach()
+
+ get_directory_property(_defines COMPILE_DEFINITIONS)
+ foreach(_current ${_defines})
+ set(${_moc_flags} ${${_moc_flags}} "-D${_current}")
+ endforeach()
+
+ if(Q_WS_WIN)
+ set(${_moc_flags} ${${_moc_flags}} -DWIN32)
+ endif()
+
+endmacro()
+
+
+# helper macro to set up a moc rule
+function (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options moc_target)
+ # For Windows, create a parameters file to work around command line length limit
+ # Pass the parameters in a file. Set the working directory to
+ # be that containing the parameters file and reference it by
+ # just the file name. This is necessary because the moc tool on
+ # MinGW builds does not seem to handle spaces in the path to the
+ # file given with the @ syntax.
+ get_filename_component(_moc_outfile_name "${outfile}" NAME)
+ get_filename_component(_moc_outfile_dir "${outfile}" PATH)
+ if(_moc_outfile_dir)
+ set(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir})
+ endif()
+ set (_moc_parameters_file ${outfile}_parameters)
+ set (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}")
+ string (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}")
+
+ if(moc_target)
+ set (_moc_parameters_file ${_moc_parameters_file}$<$<BOOL:$<CONFIGURATION>>:_$<CONFIGURATION>>)
+ set(targetincludes "$<TARGET_PROPERTY:${moc_target},INCLUDE_DIRECTORIES>")
+ set(targetdefines "$<TARGET_PROPERTY:${moc_target},COMPILE_DEFINITIONS>")
+
+ set(targetincludes "$<$<BOOL:${targetincludes}>:-I$<JOIN:${targetincludes},\n-I>\n>")
+ set(targetdefines "$<$<BOOL:${targetdefines}>:-D$<JOIN:${targetdefines},\n-D>\n>")
+
+ file (GENERATE
+ OUTPUT ${_moc_parameters_file}
+ CONTENT "${targetdefines}${targetincludes}${_moc_parameters}\n"
+ )
+
+ set(targetincludes)
+ set(targetdefines)
+ else()
+ set(CMAKE_CONFIGURABLE_FILE_CONTENT "${_moc_parameters}")
+ configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
+ "${_moc_parameters_file}" @ONLY)
+ endif()
+
+ set(_moc_extra_parameters_file @${_moc_parameters_file})
+ add_custom_command(OUTPUT ${outfile}
+ COMMAND Qt4::moc ${_moc_extra_parameters_file}
+ DEPENDS ${infile} ${_moc_parameters_file}
+ ${_moc_working_dir}
+ VERBATIM)
+endfunction ()
+
+
+macro (QT4_GENERATE_MOC infile outfile )
+# get include dirs and flags
+ QT4_GET_MOC_FLAGS(moc_flags)
+ get_filename_component(abs_infile ${infile} ABSOLUTE)
+ set(_outfile "${outfile}")
+ if(NOT IS_ABSOLUTE "${outfile}")
+ set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
+ endif()
+
+ if ("x${ARGV2}" STREQUAL "xTARGET")
+ set(moc_target ${ARGV3})
+ endif()
+ QT4_CREATE_MOC_COMMAND(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}")
+ set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file
+endmacro ()
+
+
+# QT4_WRAP_CPP(outfiles inputfile ... )
+
+macro (QT4_WRAP_CPP outfiles )
+ # get include dirs
+ QT4_GET_MOC_FLAGS(moc_flags)
+ QT4_EXTRACT_OPTIONS(moc_files moc_options moc_target ${ARGN})
+
+ foreach (it ${moc_files})
+ get_filename_component(it ${it} ABSOLUTE)
+ QT4_MAKE_OUTPUT_FILE(${it} moc_ cxx outfile)
+ QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags}" "${moc_options}" "${moc_target}")
+ set(${outfiles} ${${outfiles}} ${outfile})
+ endforeach()
+
+endmacro ()
+
+
+# QT4_WRAP_UI(outfiles inputfile ... )
+
+macro (QT4_WRAP_UI outfiles )
+ QT4_EXTRACT_OPTIONS(ui_files ui_options ui_target ${ARGN})
+
+ foreach (it ${ui_files})
+ get_filename_component(outfile ${it} NAME_WE)
+ get_filename_component(infile ${it} ABSOLUTE)
+ set(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.h)
+ add_custom_command(OUTPUT ${outfile}
+ COMMAND Qt4::uic
+ ARGS ${ui_options} -o ${outfile} ${infile}
+ MAIN_DEPENDENCY ${infile} VERBATIM)
+ set(${outfiles} ${${outfiles}} ${outfile})
+ endforeach ()
+
+endmacro ()
+
+
+# QT4_ADD_RESOURCES(outfiles inputfile ... )
+
+macro (QT4_ADD_RESOURCES outfiles )
+ QT4_EXTRACT_OPTIONS(rcc_files rcc_options rcc_target ${ARGN})
+
+ foreach (it ${rcc_files})
+ get_filename_component(outfilename ${it} NAME_WE)
+ get_filename_component(infile ${it} ABSOLUTE)
+ get_filename_component(rc_path ${infile} PATH)
+ set(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cxx)
+
+ set(_RC_DEPENDS)
+ if(EXISTS "${infile}")
+ # parse file for dependencies
+ # all files are absolute paths or relative to the location of the qrc file
+ file(READ "${infile}" _RC_FILE_CONTENTS)
+ string(REGEX MATCHALL "<file[^<]+" _RC_FILES "${_RC_FILE_CONTENTS}")
+ foreach(_RC_FILE ${_RC_FILES})
+ string(REGEX REPLACE "^<file[^>]*>" "" _RC_FILE "${_RC_FILE}")
+ if(NOT IS_ABSOLUTE "${_RC_FILE}")
+ set(_RC_FILE "${rc_path}/${_RC_FILE}")
+ endif()
+ set(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}")
+ endforeach()
+ unset(_RC_FILES)
+ unset(_RC_FILE_CONTENTS)
+ # Since this cmake macro is doing the dependency scanning for these files,
+ # let's make a configured file and add it as a dependency so cmake is run
+ # again when dependencies need to be recomputed.
+ QT4_MAKE_OUTPUT_FILE("${infile}" "" "qrc.depends" out_depends)
+ configure_file("${infile}" "${out_depends}" COPY_ONLY)
+ else()
+ # The .qrc file does not exist (yet). Let's add a dependency and hope
+ # that it will be generated later
+ set(out_depends)
+ endif()
+
+ add_custom_command(OUTPUT ${outfile}
+ COMMAND Qt4::rcc
+ ARGS ${rcc_options} -name ${outfilename} -o ${outfile} ${infile}
+ MAIN_DEPENDENCY ${infile}
+ DEPENDS ${_RC_DEPENDS} "${out_depends}" VERBATIM)
+ set(${outfiles} ${${outfiles}} ${outfile})
+ endforeach ()
+
+endmacro ()
+
+
+macro(QT4_ADD_DBUS_INTERFACE _sources _interface _basename)
+ get_filename_component(_infile ${_interface} ABSOLUTE)
+ set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
+ set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
+ set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
+
+ get_source_file_property(_nonamespace ${_interface} NO_NAMESPACE)
+ if(_nonamespace)
+ set(_params -N -m)
+ else()
+ set(_params -m)
+ endif()
+
+ get_source_file_property(_classname ${_interface} CLASSNAME)
+ if(_classname)
+ set(_params ${_params} -c ${_classname})
+ endif()
+
+ get_source_file_property(_include ${_interface} INCLUDE)
+ if(_include)
+ set(_params ${_params} -i ${_include})
+ endif()
+
+ add_custom_command(OUTPUT "${_impl}" "${_header}"
+ COMMAND Qt4::qdbusxml2cpp ${_params} -p ${_basename} ${_infile}
+ DEPENDS ${_infile} VERBATIM)
+
+ set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
+
+ QT4_GENERATE_MOC("${_header}" "${_moc}")
+
+ list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
+ MACRO_ADD_FILE_DEPENDENCIES("${_impl}" "${_moc}")
+
+endmacro()
+
+
+macro(QT4_ADD_DBUS_INTERFACES _sources)
+ foreach (_current_FILE ${ARGN})
+ get_filename_component(_infile ${_current_FILE} ABSOLUTE)
+ get_filename_component(_basename ${_current_FILE} NAME)
+ # get the part before the ".xml" suffix
+ string(TOLOWER ${_basename} _basename)
+ string(REGEX REPLACE "(.*\\.)?([^\\.]+)\\.xml" "\\2" _basename ${_basename})
+ QT4_ADD_DBUS_INTERFACE(${_sources} ${_infile} ${_basename}interface)
+ endforeach ()
+endmacro()
+
+
+macro(QT4_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options )
+ QT4_EXTRACT_OPTIONS(_customName _qt4_dbus_options _qt4_dbus_target ${ARGN})
+
+ get_filename_component(_in_file ${_header} ABSOLUTE)
+ get_filename_component(_basename ${_header} NAME_WE)
+
+ if (_customName)
+ if (IS_ABSOLUTE ${_customName})
+ get_filename_component(_containingDir ${_customName} PATH)
+ if (NOT EXISTS ${_containingDir})
+ file(MAKE_DIRECTORY "${_containingDir}")
+ endif()
+ set(_target ${_customName})
+ else()
+ set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName})
+ endif()
+ else ()
+ set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml)
+ endif ()
+
+ add_custom_command(OUTPUT ${_target}
+ COMMAND Qt4::qdbuscpp2xml ${_qt4_dbus_options} ${_in_file} -o ${_target}
+ DEPENDS ${_in_file} VERBATIM
+ )
+endmacro()
+
+
+macro(QT4_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName)
+ get_filename_component(_infile ${_xml_file} ABSOLUTE)
+
+ set(_optionalBasename "${ARGV4}")
+ if (_optionalBasename)
+ set(_basename ${_optionalBasename} )
+ else ()
+ string(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile})
+ string(TOLOWER ${_basename} _basename)
+ endif ()
+
+ set(_optionalClassName "${ARGV5}")
+ set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
+ set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
+ set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
+
+ if(_optionalClassName)
+ add_custom_command(OUTPUT "${_impl}" "${_header}"
+ COMMAND Qt4::qdbusxml2cpp -m -a ${_basename} -c ${_optionalClassName} -i ${_include} -l ${_parentClass} ${_infile}
+ DEPENDS ${_infile} VERBATIM
+ )
+ else()
+ add_custom_command(OUTPUT "${_impl}" "${_header}"
+ COMMAND Qt4::qdbusxml2cpp -m -a ${_basename} -i ${_include} -l ${_parentClass} ${_infile}
+ DEPENDS ${_infile} VERBATIM
+ )
+ endif()
+
+ QT4_GENERATE_MOC("${_header}" "${_moc}")
+ set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
+ MACRO_ADD_FILE_DEPENDENCIES("${_impl}" "${_moc}")
+
+ list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
+endmacro()
+
+
+macro(QT4_AUTOMOC)
+ if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.11)
+ message(DEPRECATION "The qt4_automoc macro is obsolete. Use the CMAKE_AUTOMOC feature instead.")
+ endif()
+ QT4_GET_MOC_FLAGS(_moc_INCS)
+
+ set(_matching_FILES )
+ foreach (_current_FILE ${ARGN})
+
+ get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
+ # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
+ # This is required to make uic work correctly:
+ # we need to add generated .cpp files to the sources (to compile them),
+ # but we cannot let automoc handle them, as the .cpp files don't exist yet when
+ # cmake is run for the very first time on them -> however the .cpp files might
+ # exist at a later run. at that time we need to skip them, so that we don't add two
+ # different rules for the same moc file
+ get_source_file_property(_skip ${_abs_FILE} SKIP_AUTOMOC)
+
+ if ( NOT _skip AND EXISTS ${_abs_FILE} )
+
+ file(READ ${_abs_FILE} _contents)
+
+ get_filename_component(_abs_PATH ${_abs_FILE} PATH)
+
+ string(REGEX MATCHALL "# *include +[^ ]+\\.moc[\">]" _match "${_contents}")
+ if(_match)
+ foreach (_current_MOC_INC ${_match})
+ string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
+
+ get_filename_component(_basename ${_current_MOC} NAME_WE)
+ if(EXISTS ${_abs_PATH}/${_basename}.hpp)
+ set(_header ${_abs_PATH}/${_basename}.hpp)
+ else()
+ set(_header ${_abs_PATH}/${_basename}.h)
+ endif()
+ set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
+ QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "" "")
+ MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
+ endforeach ()
+ endif()
+ endif ()
+ endforeach ()
+endmacro()
+
+
+macro(QT4_CREATE_TRANSLATION _qm_files)
+ QT4_EXTRACT_OPTIONS(_lupdate_files _lupdate_options _lupdate_target ${ARGN})
+ set(_my_sources)
+ set(_my_dirs)
+ set(_my_tsfiles)
+ set(_ts_pro)
+ foreach (_file ${_lupdate_files})
+ get_filename_component(_ext ${_file} EXT)
+ get_filename_component(_abs_FILE ${_file} ABSOLUTE)
+ if(_ext MATCHES "ts")
+ list(APPEND _my_tsfiles ${_abs_FILE})
+ else()
+ if(NOT _ext)
+ list(APPEND _my_dirs ${_abs_FILE})
+ else()
+ list(APPEND _my_sources ${_abs_FILE})
+ endif()
+ endif()
+ endforeach()
+ foreach(_ts_file ${_my_tsfiles})
+ if(_my_sources)
+ # make a .pro file to call lupdate on, so we don't make our commands too
+ # long for some systems
+ get_filename_component(_ts_name ${_ts_file} NAME_WE)
+ set(_ts_pro ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_ts_name}_lupdate.pro)
+ set(_pro_srcs)
+ foreach(_pro_src ${_my_sources})
+ set(_pro_srcs "${_pro_srcs} \\\n \"${_pro_src}\"")
+ endforeach()
+ set(_pro_includes)
+ get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)
+ list(REMOVE_DUPLICATES _inc_DIRS)
+ foreach(_pro_include ${_inc_DIRS})
+ get_filename_component(_abs_include "${_pro_include}" ABSOLUTE)
+ set(_pro_includes "${_pro_includes} \\\n \"${_abs_include}\"")
+ endforeach()
+ file(WRITE ${_ts_pro} "SOURCES =${_pro_srcs}\nINCLUDEPATH =${_pro_includes}\n")
+ endif()
+ add_custom_command(OUTPUT ${_ts_file}
+ COMMAND Qt4::lupdate
+ ARGS ${_lupdate_options} ${_ts_pro} ${_my_dirs} -ts ${_ts_file}
+ DEPENDS ${_my_sources} ${_ts_pro} VERBATIM)
+ endforeach()
+ QT4_ADD_TRANSLATION(${_qm_files} ${_my_tsfiles})
+endmacro()
+
+
+macro(QT4_ADD_TRANSLATION _qm_files)
+ foreach (_current_FILE ${ARGN})
+ get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
+ get_filename_component(qm ${_abs_FILE} NAME_WE)
+ get_source_file_property(output_location ${_abs_FILE} OUTPUT_LOCATION)
+ if(output_location)
+ file(MAKE_DIRECTORY "${output_location}")
+ set(qm "${output_location}/${qm}.qm")
+ else()
+ set(qm "${CMAKE_CURRENT_BINARY_DIR}/${qm}.qm")
+ endif()
+
+ add_custom_command(OUTPUT ${qm}
+ COMMAND Qt4::lrelease
+ ARGS ${_abs_FILE} -qm ${qm}
+ DEPENDS ${_abs_FILE} VERBATIM
+ )
+ set(${_qm_files} ${${_qm_files}} ${qm})
+ endforeach ()
+endmacro()
+
+function(qt4_use_modules _target _link_type)
+ if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.11)
+ message(DEPRECATION "The qt4_use_modules function is obsolete. Use target_link_libraries with IMPORTED targets instead.")
+ endif()
+ if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE")
+ set(modules ${ARGN})
+ set(link_type ${_link_type})
+ else()
+ set(modules ${_link_type} ${ARGN})
+ endif()
+ foreach(_module ${modules})
+ string(TOUPPER ${_module} _ucmodule)
+ set(_targetPrefix QT_QT${_ucmodule})
+ if (_ucmodule STREQUAL QAXCONTAINER OR _ucmodule STREQUAL QAXSERVER)
+ if (NOT QT_Q${_ucmodule}_FOUND)
+ message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
+ endif()
+ set(_targetPrefix QT_Q${_ucmodule})
+ else()
+ if (NOT QT_QT${_ucmodule}_FOUND)
+ message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
+ endif()
+ if ("${_ucmodule}" STREQUAL "MAIN")
+ message(FATAL_ERROR "Can not use \"${_module}\" module with qt4_use_modules.")
+ endif()
+ endif()
+ target_link_libraries(${_target} ${link_type} ${${_targetPrefix}_LIBRARIES})
+ set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${${_targetPrefix}_INCLUDE_DIR} ${QT_HEADERS_DIR} ${QT_MKSPECS_DIR}/default)
+ set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS ${${_targetPrefix}_COMPILE_DEFINITIONS})
+ endforeach()
+endfunction()
diff --git a/Modules/RepositoryInfo.txt.in b/Modules/RepositoryInfo.txt.in
new file mode 100644
index 0000000000..df8e32272d
--- /dev/null
+++ b/Modules/RepositoryInfo.txt.in
@@ -0,0 +1,3 @@
+repository='@repository@'
+module='@module@'
+tag='@tag@'
diff --git a/Modules/SelectLibraryConfigurations.cmake b/Modules/SelectLibraryConfigurations.cmake
new file mode 100644
index 0000000000..d7108562b1
--- /dev/null
+++ b/Modules/SelectLibraryConfigurations.cmake
@@ -0,0 +1,81 @@
+#.rst:
+# SelectLibraryConfigurations
+# ---------------------------
+#
+#
+#
+# select_library_configurations( basename )
+#
+# This macro takes a library base name as an argument, and will choose
+# good values for basename_LIBRARY, basename_LIBRARIES,
+# basename_LIBRARY_DEBUG, and basename_LIBRARY_RELEASE depending on what
+# has been found and set. If only basename_LIBRARY_RELEASE is defined,
+# basename_LIBRARY will be set to the release value, and
+# basename_LIBRARY_DEBUG will be set to basename_LIBRARY_DEBUG-NOTFOUND.
+# If only basename_LIBRARY_DEBUG is defined, then basename_LIBRARY will
+# take the debug value, and basename_LIBRARY_RELEASE will be set to
+# basename_LIBRARY_RELEASE-NOTFOUND.
+#
+# If the generator supports configuration types, then basename_LIBRARY
+# and basename_LIBRARIES will be set with debug and optimized flags
+# specifying the library to be used for the given configuration. If no
+# build type has been set or the generator in use does not support
+# configuration types, then basename_LIBRARY and basename_LIBRARIES will
+# take only the release value, or the debug value if the release one is
+# not set.
+
+#=============================================================================
+# Copyright 2009 Will Dicharry <wdicharry@stellarscience.com>
+# Copyright 2005-2009 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 macro was adapted from the FindQt4 CMake module and is maintained by Will
+# Dicharry <wdicharry@stellarscience.com>.
+
+macro( select_library_configurations basename )
+ if(NOT ${basename}_LIBRARY_RELEASE)
+ set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.")
+ endif()
+ if(NOT ${basename}_LIBRARY_DEBUG)
+ set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.")
+ endif()
+
+ if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND
+ NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND
+ ( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) )
+ # if the generator supports configuration types or CMAKE_BUILD_TYPE
+ # is set, then set optimized and debug options.
+ set( ${basename}_LIBRARY "" )
+ foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
+ list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
+ endforeach()
+ foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG )
+ list( APPEND ${basename}_LIBRARY debug "${_libname}" )
+ endforeach()
+ elseif( ${basename}_LIBRARY_RELEASE )
+ set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
+ elseif( ${basename}_LIBRARY_DEBUG )
+ set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} )
+ else()
+ set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND")
+ endif()
+
+ set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" )
+
+ if( ${basename}_LIBRARY )
+ set( ${basename}_FOUND TRUE )
+ endif()
+
+ mark_as_advanced( ${basename}_LIBRARY_RELEASE
+ ${basename}_LIBRARY_DEBUG
+ )
+endmacro()
diff --git a/Modules/Squish4RunTestCase.bat b/Modules/Squish4RunTestCase.bat
new file mode 100755
index 0000000000..ad1cc8c3b1
--- /dev/null
+++ b/Modules/Squish4RunTestCase.bat
@@ -0,0 +1,24 @@
+set SQUISHSERVER=%1
+set SQUISHRUNNER=%2
+set TESTSUITE=%3
+set TESTCASE=%4
+set AUT=%5
+set AUTDIR=%6
+set SETTINGSGROUP=%7
+
+%SQUISHSERVER% --stop
+
+echo "Adding AUT... %SQUISHSERVER% --config addAUT %AUT% %AUTDIR%"
+%SQUISHSERVER% --config addAUT "%AUT%" "%AUTDIR%"
+
+echo "Starting the squish server... %SQUISHSERVER%"
+start /B %SQUISHSERVER%
+
+echo "Running the test case...%SQUISHRUNNER% --testsuite %TESTSUITE% --testcase %TESTCASE%"
+%SQUISHRUNNER% --testsuite "%TESTSUITE%" --testcase "%TESTCASE%"
+set returnValue=%ERRORLEVEL%
+
+echo "Stopping the squish server... %SQUISHSERVER% --stop"
+%SQUISHSERVER% --stop
+
+exit /B %returnValue%
diff --git a/Modules/Squish4RunTestCase.sh b/Modules/Squish4RunTestCase.sh
new file mode 100755
index 0000000000..abd5debd2e
--- /dev/null
+++ b/Modules/Squish4RunTestCase.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+SQUISHSERVER=$1
+SQUISHRUNNER=$2
+TESTSUITE=$3
+TESTCASE=$4
+AUT=$5
+AUTDIR=$6
+SETTINGSGROUP=$7
+
+$SQUISHSERVER --stop > /dev/null 2>&1
+
+echo "Adding AUT... $SQUISHSERVER --settingsGroup $SETTINGSGROUP --config addAUT $AUT $AUTDIR"
+$SQUISHSERVER --settingsGroup "$SETTINGSGROUP" --config addAUT "$AUT" "$AUTDIR" || exit -1
+# sleep 1
+
+echo "Starting the squish server... $SQUISHSERVER --daemon"
+$SQUISHSERVER --daemon || exit -1
+# sleep 2
+
+echo "Running the test case...$SQUISHRUNNER --settingsGroup $SETTINGSGROUP --testsuite $TESTSUITE --testcase $TESTCASE"
+$SQUISHRUNNER --settingsGroup "$SETTINGSGROUP" --testsuite "$TESTSUITE" --testcase "$TESTCASE"
+returnValue=$?
+
+echo "Stopping the squish server... $SQUISHSERVER --stop"
+$SQUISHSERVER --stop
+
+exit $returnValue
diff --git a/Modules/SquishRunTestCase.bat b/Modules/SquishRunTestCase.bat
new file mode 100755
index 0000000000..5c5d388b03
--- /dev/null
+++ b/Modules/SquishRunTestCase.bat
@@ -0,0 +1,11 @@
+echo 'Starting the squish server...'
+start %1
+
+echo 'Running the test case...'
+%2 --testcase %3 --wrapper %4 --aut %5
+set result=%ERRORLEVEL%
+
+echo 'Stopping the squish server...'
+%1 --stop
+
+exit \b %result%
diff --git a/Modules/SquishRunTestCase.sh b/Modules/SquishRunTestCase.sh
new file mode 100755
index 0000000000..409b46a3ed
--- /dev/null
+++ b/Modules/SquishRunTestCase.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+echo "Starting the squish server...$1 --daemon"
+$1 --daemon
+
+echo "Running the test case...$2 --testcase $3 --wrapper $4 --aut $5"
+$2 --testcase $3 --wrapper $4 --aut $5
+returnValue=$?
+
+echo "Stopping the squish server...$1 --stop"
+$1 --stop
+
+exit $returnValue
diff --git a/Modules/SquishTestScript.cmake b/Modules/SquishTestScript.cmake
new file mode 100644
index 0000000000..d6487499e3
--- /dev/null
+++ b/Modules/SquishTestScript.cmake
@@ -0,0 +1,95 @@
+#.rst:
+# SquishTestScript
+# ----------------
+#
+#
+#
+#
+#
+# This script launches a GUI test using Squish. You should not call the
+# script directly; instead, you should access it via the SQUISH_ADD_TEST
+# macro that is defined in FindSquish.cmake.
+#
+# This script starts the Squish server, launches the test on the client,
+# and finally stops the squish server. If any of these steps fail
+# (including if the tests do not pass) then a fatal error is raised.
+
+#=============================================================================
+# Copyright 2008-2009 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.)
+
+# print out the variable that we are using
+message(STATUS "squish_aut='${squish_aut}'")
+message(STATUS "squish_aut_dir='${squish_aut_dir}'")
+
+message(STATUS "squish_version='${squish_version}'")
+message(STATUS "squish_server_executable='${squish_server_executable}'")
+message(STATUS "squish_client_executable='${squish_client_executable}'")
+message(STATUS "squish_libqtdir ='${squish_libqtdir}'")
+message(STATUS "squish_test_suite='${squish_test_suite}'")
+message(STATUS "squish_test_case='${squish_test_case}'")
+message(STATUS "squish_wrapper='${squish_wrapper}'")
+message(STATUS "squish_env_vars='${squish_env_vars}'")
+message(STATUS "squish_module_dir='${squish_module_dir}'")
+message(STATUS "squish_settingsgroup='${squish_settingsgroup}'")
+message(STATUS "squish_pre_command='${squish_pre_command}'")
+message(STATUS "squish_post_command='${squish_post_command}'")
+
+# parse enviornment variables
+foreach(i ${squish_env_vars})
+ message(STATUS "parsing env var key/value pair ${i}")
+ string(REGEX MATCH "([^=]*)=(.*)" squish_env_name ${i})
+ message(STATUS "key=${CMAKE_MATCH_1}")
+ message(STATUS "value=${CMAKE_MATCH_2}")
+ set ( ENV{${CMAKE_MATCH_1}} ${CMAKE_MATCH_2} )
+endforeach()
+
+if (QT4_INSTALLED)
+ # record Qt lib directory
+ set ( ENV{${SQUISH_LIBQTDIR}} ${squish_libqtdir} )
+endif ()
+
+if(squish_pre_command)
+ message(STATUS "Executing pre command: ${squish_pre_command}")
+ execute_process(COMMAND "${squish_pre_command}")
+endif()
+
+# run the test
+if("${squish_version}" STREQUAL "4")
+ if (WIN32)
+ execute_process(COMMAND ${squish_module_dir}/Squish4RunTestCase.bat ${squish_server_executable} ${squish_client_executable} ${squish_test_suite} ${squish_test_case} ${squish_aut} ${squish_aut_dir} ${squish_settingsgroup}
+ RESULT_VARIABLE test_rv )
+ elseif(UNIX)
+ execute_process(COMMAND ${squish_module_dir}/Squish4RunTestCase.sh ${squish_server_executable} ${squish_client_executable} ${squish_test_suite} ${squish_test_case} ${squish_aut} ${squish_aut_dir} ${squish_settingsgroup}
+ RESULT_VARIABLE test_rv )
+ endif ()
+
+else()
+
+ if (WIN32)
+ execute_process(COMMAND ${squish_module_dir}/SquishRunTestCase.bat ${squish_server_executable} ${squish_client_executable} ${squish_test_case} ${squish_wrapper} ${squish_aut}
+ RESULT_VARIABLE test_rv )
+ elseif(UNIX)
+ execute_process(COMMAND ${squish_module_dir}/SquishRunTestCase.sh ${squish_server_executable} ${squish_client_executable} ${squish_test_case} ${squish_wrapper} ${squish_aut}
+ RESULT_VARIABLE test_rv )
+ endif ()
+endif()
+
+if(squish_post_command)
+ message(STATUS "Executing post command: ${squish_post_command}")
+ execute_process(COMMAND "${squish_post_command}")
+endif()
+
+# check for an error with running the test
+if(NOT "${test_rv}" STREQUAL "0")
+ message(FATAL_ERROR "Error running Squish test")
+endif()
diff --git a/Modules/SystemInformation.cmake b/Modules/SystemInformation.cmake
new file mode 100644
index 0000000000..fa85071067
--- /dev/null
+++ b/Modules/SystemInformation.cmake
@@ -0,0 +1,103 @@
+
+#=============================================================================
+# Copyright 2007-2010 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.)
+
+cmake_minimum_required(VERSION ${CMAKE_VERSION})
+project(DumpInformation)
+
+# first get the standard information for th platform
+include_directories("This does not exists")
+get_directory_property(incl INCLUDE_DIRECTORIES)
+set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${DumpInformation_BINARY_DIR};${DumpInformation_SOURCE_DIR}")
+
+configure_file("${CMAKE_ROOT}/Modules/SystemInformation.in" "${RESULT_FILE}")
+
+
+file(APPEND "${RESULT_FILE}"
+ "\n=================================================================\n")
+file(APPEND "${RESULT_FILE}"
+ "=== VARIABLES\n")
+file(APPEND "${RESULT_FILE}"
+ "=================================================================\n")
+get_cmake_property(res VARIABLES)
+foreach(var ${res})
+ file(APPEND "${RESULT_FILE}" "${var} \"${${var}}\"\n")
+endforeach()
+
+file(APPEND "${RESULT_FILE}"
+ "\n=================================================================\n")
+file(APPEND "${RESULT_FILE}"
+ "=== COMMANDS\n")
+file(APPEND "${RESULT_FILE}"
+ "=================================================================\n")
+get_cmake_property(res COMMANDS)
+foreach(var ${res})
+ file(APPEND "${RESULT_FILE}" "${var}\n")
+endforeach()
+
+file(APPEND "${RESULT_FILE}"
+ "\n=================================================================\n")
+file(APPEND "${RESULT_FILE}"
+ "=== MACROS\n")
+file(APPEND "${RESULT_FILE}"
+ "=================================================================\n")
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AllMacros.txt "")
+get_cmake_property(res MACROS)
+foreach(var ${res})
+ file(APPEND "${RESULT_FILE}" "${var}\n")
+endforeach()
+
+file(APPEND "${RESULT_FILE}"
+ "\n=================================================================\n")
+file(APPEND "${RESULT_FILE}"
+ "=== OTHER\n")
+file(APPEND "${RESULT_FILE}"
+ "=================================================================\n")
+get_directory_property(res INCLUDE_DIRECTORIES)
+foreach(var ${res})
+ file(APPEND "${RESULT_FILE}" "INCLUDE_DIRECTORY: ${var}\n")
+endforeach()
+
+get_directory_property(res LINK_DIRECTORIES)
+foreach(var ${res})
+ file(APPEND "${RESULT_FILE}" "LINK_DIRECTORIES: ${var}\n")
+endforeach()
+
+get_directory_property(res INCLUDE_REGULAR_EXPRESSION)
+file(APPEND "${RESULT_FILE}" "INCLUDE_REGULAR_EXPRESSION: ${res}\n")
+
+# include other files if they are present, such as when run from within the
+# binary tree
+macro(DUMP_FILE THE_FILE)
+ if (EXISTS "${THE_FILE}")
+ file(APPEND "${RESULT_FILE}"
+ "\n=================================================================\n")
+ file(APPEND "${RESULT_FILE}"
+ "=== ${THE_FILE}\n")
+ file(APPEND "${RESULT_FILE}"
+ "=================================================================\n")
+
+ file(READ "${THE_FILE}" FILE_CONTENTS LIMIT 50000)
+ file(APPEND "${RESULT_FILE}" "${FILE_CONTENTS}")
+ endif ()
+endmacro()
+
+DUMP_FILE("../CMakeCache.txt")
+DUMP_FILE("../CMakeFiles/CMakeOutput.log")
+DUMP_FILE("../CMakeFiles/CMakeError.log")
+DUMP_FILE("../CMakeFiles/CMakeSystem.cmake")
+
+foreach (EXTRA_FILE ${EXTRA_DUMP_FILES})
+ DUMP_FILE("${EXTRA_FILE}")
+endforeach ()
+
diff --git a/Modules/SystemInformation.in b/Modules/SystemInformation.in
new file mode 100644
index 0000000000..f2aef5055e
--- /dev/null
+++ b/Modules/SystemInformation.in
@@ -0,0 +1,88 @@
+Avoid ctest truncation of output: CTEST_FULL_OUTPUT
+========================================================
+=== MAIN VARIABLES
+========================================================
+CMAKE_STATIC_LIBRARY_PREFIX == "${CMAKE_STATIC_LIBRARY_PREFIX}"
+CMAKE_STATIC_LIBRARY_SUFFIX == "${CMAKE_STATIC_LIBRARY_SUFFIX}"
+CMAKE_SHARED_LIBRARY_PREFIX == "${CMAKE_SHARED_LIBRARY_PREFIX}"
+CMAKE_SHARED_LIBRARY_SUFFIX == "${CMAKE_SHARED_LIBRARY_SUFFIX}"
+CMAKE_SHARED_MODULE_PREFIX == "${CMAKE_SHARED_MODULE_PREFIX}"
+CMAKE_SHARED_MODULE_SUFFIX == "${CMAKE_SHARED_MODULE_SUFFIX}"
+
+
+CMAKE_DL_LIBS == "${CMAKE_DL_LIBS}"
+CMAKE_LIBRARY_PATH_FLAG == "${CMAKE_LIBRARY_PATH_FLAG}"
+CMAKE_LINK_LIBRARY_FLAG == "${CMAKE_LINK_LIBRARY_FLAG}"
+CMAKE_SKIP_RPATH == "${CMAKE_SKIP_RPATH}"
+CMAKE_SYSTEM_INFO_FILE == "${CMAKE_SYSTEM_INFO_FILE}"
+CMAKE_SYSTEM_NAME == "${CMAKE_SYSTEM_NAME}"
+CMAKE_SYSTEM == "${CMAKE_SYSTEM}"
+CMAKE_CXX_COMPILER == "${CMAKE_CXX_COMPILER}"
+CMAKE_C_COMPILER == "${CMAKE_C_COMPILER}"
+CMAKE_COMPILER_IS_GNUCC == "${CMAKE_COMPILER_IS_GNUCC}"
+CMAKE_COMPILER_IS_GNUCXX == "${CMAKE_COMPILER_IS_GNUCXX}"
+
+// C shared library flag
+CMAKE_SHARED_LIBRARY_C_FLAGS == "${CMAKE_SHARED_LIBRARY_C_FLAGS}"
+CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS == "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}"
+CMAKE_SHARED_LIBRARY_LINK_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_FLAGS}"
+CMAKE_SHARED_LIBRARY_RUNTIME_FLAG == "${CMAKE_SHARED_LIBRARY_RUNTIME_FLAG}"
+CMAKE_SHARED_LIBRARY_RUNTIME_FLAG_SEP == "${CMAKE_SHARED_LIBRARY_RUNTIME_FLAG_SEP}"
+CMAKE_SHARED_LIBRARY_LINK_STATIC_C_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_STATIC_C_FLAGS}"
+CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_C_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_C_FLAGS}"
+
+// C shared module flags
+CMAKE_SHARED_MODULE_C_FLAGS == "${CMAKE_SHARED_MODULE_C_FLAGS}"
+CMAKE_SHARED_MODULE_CREATE_C_FLAGS == "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS}"
+CMAKE_SHARED_MODULE_LINK_STATIC_C_FLAGS == "${CMAKE_SHARED_MODULE_LINK_STATIC_C_FLAGS}"
+CMAKE_SHARED_MODULE_LINK_DYNAMIC_C_FLAGS == "${CMAKE_SHARED_MODULE_LINK_DYNAMIC_C_FLAGS}"
+
+// C exe flags
+CMAKE_EXE_LINK_STATIC_C_FLAGS == "${CMAKE_EXE_LINK_STATIC_C_FLAGS}"
+CMAKE_EXE_LINK_DYNAMIC_C_FLAGS == "${CMAKE_EXE_LINK_DYNAMIC_C_FLAGS}"
+
+// CXX shared library flags
+CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}"
+CMAKE_SHARED_LIBRARY_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
+CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}"
+CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG == "${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG}"
+CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP == "${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP}"
+CMAKE_SHARED_LIBRARY_LINK_STATIC_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_STATIC_CXX_FLAGS}"
+CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_CXX_FLAGS}"
+
+// CXX shared module flags
+CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS == "${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS}"
+CMAKE_SHARED_MODULE_CXX_FLAGS == "${CMAKE_SHARED_MODULE_CXX_FLAGS}"
+CMAKE_SHARED_MODULE_LINK_STATIC_CXX_FLAGS == "${CMAKE_SHARED_MODULE_LINK_STATIC_CXX_FLAGS}"
+CMAKE_SHARED_MODULE_LINK_DYNAMIC_CXX_FLAGS == "${CMAKE_SHARED_MODULE_LINK_DYNAMIC_CXX_FLAGS}"
+
+// CXX exe flags
+CMAKE_EXE_LINK_STATIC_CXX_FLAGS == "${CMAKE_EXE_LINK_STATIC_CXX_FLAGS}"
+CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS == "${CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS}"
+
+CMAKE_USER_MAKE_RULES_OVERRIDE == "${CMAKE_USER_MAKE_RULES_OVERRIDE}"
+CMAKE_VERBOSE_MAKEFILE == "${CMAKE_VERBOSE_MAKEFILE}"
+CMAKE_BUILD_TYPE == "${CMAKE_BUILD_TYPE}"
+CMAKE_CXX_FLAGS == "${CMAKE_CXX_FLAGS}"
+CMAKE_CXX_FLAGS_DEBUG == "${CMAKE_CXX_FLAGS_DEBUG}"
+CMAKE_CXX_FLAGS_MINSIZEREL == "${CMAKE_CXX_FLAGS_MINSIZEREL}"
+CMAKE_CXX_FLAGS_RELEASE == "${CMAKE_CXX_FLAGS_RELEASE}"
+CMAKE_CXX_FLAGS_RELWITHDEBINFO == "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
+
+CMAKE_C_FLAGS == "${CMAKE_C_FLAGS}"
+CMAKE_C_FLAGS_DEBUG == "${CMAKE_C_FLAGS_DEBUG}"
+CMAKE_C_FLAGS_MINSIZEREL == "${CMAKE_C_FLAGS_MINSIZEREL}"
+CMAKE_C_FLAGS_RELEASE == "${CMAKE_C_FLAGS_RELEASE}"
+CMAKE_C_FLAGS_RELWITHDEBINFO == "${CMAKE_C_FLAGS_RELWITHDEBINFO}"
+
+// build rules
+CMAKE_CXX_CREATE_SHARED_LIBRARY == "${CMAKE_CXX_CREATE_SHARED_LIBRARY}"
+CMAKE_CXX_CREATE_SHARED_MODULE == "${CMAKE_CXX_CREATE_SHARED_MODULE}"
+CMAKE_C_CREATE_SHARED_LIBRARY == "${CMAKE_C_CREATE_SHARED_LIBRARY}"
+CMAKE_C_CREATE_SHARED_MODULE == "${CMAKE_C_CREATE_SHARED_MODULE}"
+CMAKE_CXX_CREATE_STATIC_LIBRARY == "${CMAKE_CXX_CREATE_STATIC_LIBRARY}"
+CMAKE_C_CREATE_STATIC_LIBRARY == "${CMAKE_C_CREATE_STATIC_LIBRARY}"
+CMAKE_CXX_COMPILE_OBJECT == "${CMAKE_CXX_COMPILE_OBJECT}"
+CMAKE_C_COMPILE_OBJECT == "${CMAKE_C_COMPILE_OBJECT}"
+CMAKE_C_LINK_EXECUTABLE == "${CMAKE_C_LINK_EXECUTABLE}"
+CMAKE_CXX_LINK_EXECUTABLE == "${CMAKE_CXX_LINK_EXECUTABLE}"
diff --git a/Modules/TestBigEndian.cmake b/Modules/TestBigEndian.cmake
new file mode 100644
index 0000000000..fcb41abe1c
--- /dev/null
+++ b/Modules/TestBigEndian.cmake
@@ -0,0 +1,119 @@
+#.rst:
+# TestBigEndian
+# -------------
+#
+# Define macro to determine endian type
+#
+# Check if the system is big endian or little endian
+#
+# ::
+#
+# TEST_BIG_ENDIAN(VARIABLE)
+# VARIABLE - variable to store the result to
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+macro(TEST_BIG_ENDIAN VARIABLE)
+ if(NOT DEFINED HAVE_${VARIABLE})
+ message(STATUS "Check if the system is big endian")
+ message(STATUS "Searching 16 bit integer")
+
+ include(CheckTypeSize)
+
+ CHECK_TYPE_SIZE("unsigned short" CMAKE_SIZEOF_UNSIGNED_SHORT)
+ if(CMAKE_SIZEOF_UNSIGNED_SHORT EQUAL 2)
+ message(STATUS "Using unsigned short")
+ set(CMAKE_16BIT_TYPE "unsigned short")
+ else()
+ CHECK_TYPE_SIZE("unsigned int" CMAKE_SIZEOF_UNSIGNED_INT)
+ if(CMAKE_SIZEOF_UNSIGNED_INT)
+ message(STATUS "Using unsigned int")
+ set(CMAKE_16BIT_TYPE "unsigned int")
+
+ else()
+
+ CHECK_TYPE_SIZE("unsigned long" CMAKE_SIZEOF_UNSIGNED_LONG)
+ if(CMAKE_SIZEOF_UNSIGNED_LONG)
+ message(STATUS "Using unsigned long")
+ set(CMAKE_16BIT_TYPE "unsigned long")
+ else()
+ message(FATAL_ERROR "no suitable type found")
+ endif()
+
+ endif()
+
+ endif()
+
+
+ configure_file("${CMAKE_ROOT}/Modules/TestEndianess.c.in"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c"
+ @ONLY)
+
+ file(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c"
+ TEST_ENDIANESS_FILE_CONTENT)
+
+ try_compile(HAVE_${VARIABLE}
+ "${CMAKE_BINARY_DIR}"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c"
+ OUTPUT_VARIABLE OUTPUT
+ COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" )
+
+ if(HAVE_${VARIABLE})
+
+ file(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin"
+ CMAKE_TEST_ENDIANESS_STRINGS_LE LIMIT_COUNT 1 REGEX "THIS IS LITTLE ENDIAN")
+
+ file(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin"
+ CMAKE_TEST_ENDIANESS_STRINGS_BE LIMIT_COUNT 1 REGEX "THIS IS BIG ENDIAN")
+
+ # on mac, if there are universal binaries built both will be true
+ # return the result depending on the machine on which cmake runs
+ if(CMAKE_TEST_ENDIANESS_STRINGS_BE AND CMAKE_TEST_ENDIANESS_STRINGS_LE)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
+ set(CMAKE_TEST_ENDIANESS_STRINGS_BE TRUE)
+ set(CMAKE_TEST_ENDIANESS_STRINGS_LE FALSE)
+ else()
+ set(CMAKE_TEST_ENDIANESS_STRINGS_BE FALSE)
+ set(CMAKE_TEST_ENDIANESS_STRINGS_LE TRUE)
+ endif()
+ message(STATUS "TEST_BIG_ENDIAN found different results, consider setting CMAKE_OSX_ARCHITECTURES or CMAKE_TRY_COMPILE_OSX_ARCHITECTURES to one or no architecture !")
+ endif()
+
+ if(CMAKE_TEST_ENDIANESS_STRINGS_LE)
+ set(${VARIABLE} 0 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE)
+ message(STATUS "Check if the system is big endian - little endian")
+ endif()
+
+ if(CMAKE_TEST_ENDIANESS_STRINGS_BE)
+ set(${VARIABLE} 1 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE)
+ message(STATUS "Check if the system is big endian - big endian")
+ endif()
+
+ if(NOT CMAKE_TEST_ENDIANESS_STRINGS_BE AND NOT CMAKE_TEST_ENDIANESS_STRINGS_LE)
+ message(SEND_ERROR "TEST_BIG_ENDIAN found no result!")
+ endif()
+
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the system is big endian passed with the following output:\n${OUTPUT}\nTestEndianess.c:\n${TEST_ENDIANESS_FILE_CONTENT}\n\n")
+
+ else()
+ message(STATUS "Check if the system is big endian - failed")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the system is big endian failed with the following output:\n${OUTPUT}\nTestEndianess.c:\n${TEST_ENDIANESS_FILE_CONTENT}\n\n")
+ set(${VARIABLE})
+ endif()
+ endif()
+endmacro()
+
+
diff --git a/Modules/TestCXXAcceptsFlag.cmake b/Modules/TestCXXAcceptsFlag.cmake
new file mode 100644
index 0000000000..c814187d5b
--- /dev/null
+++ b/Modules/TestCXXAcceptsFlag.cmake
@@ -0,0 +1,51 @@
+#.rst:
+# TestCXXAcceptsFlag
+# ------------------
+#
+# Deprecated. See :module:`CheckCXXCompilerFlag`.
+#
+# Check if the CXX compiler accepts a flag.
+#
+# .. code-block:: cmake
+#
+# CHECK_CXX_ACCEPTS_FLAG(<flags> <variable>)
+#
+# ``<flags>``
+# the flags to try
+# ``<variable>``
+# variable to store the result
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+macro(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE)
+ if(NOT DEFINED ${VARIABLE})
+ message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS}")
+ try_compile(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
+ OUTPUT_VARIABLE OUTPUT)
+ if(${VARIABLE})
+ message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - yes")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
+ "the following output:\n${OUTPUT}\n\n")
+ else()
+ message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - no")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the CXX compiler accepts the flag ${FLAGS} failed with "
+ "the following output:\n${OUTPUT}\n\n")
+ endif()
+ endif()
+endmacro()
diff --git a/Modules/TestEndianess.c.in b/Modules/TestEndianess.c.in
new file mode 100644
index 0000000000..c924f7858a
--- /dev/null
+++ b/Modules/TestEndianess.c.in
@@ -0,0 +1,23 @@
+/* A 16 bit integer is required. */
+typedef @CMAKE_16BIT_TYPE@ cmakeint16;
+
+/* On a little endian machine, these 16bit ints will give "THIS IS LITTLE ENDIAN."
+ On a big endian machine the characters will be exchanged pairwise. */
+const cmakeint16 info_little[] = {0x4854, 0x5349, 0x4920, 0x2053, 0x494c, 0x5454, 0x454c, 0x4520, 0x444e, 0x4149, 0x2e4e, 0x0000};
+
+/* on a big endian machine, these 16bit ints will give "THIS IS BIG ENDIAN."
+ On a little endian machine the characters will be exchanged pairwise. */
+const cmakeint16 info_big[] = {0x5448, 0x4953, 0x2049, 0x5320, 0x4249, 0x4720, 0x454e, 0x4449, 0x414e, 0x2e2e, 0x0000};
+
+#ifdef __CLASSIC_C__
+int main(argc, argv) int argc; char *argv[];
+#else
+int main(int argc, char *argv[])
+#endif
+{
+ int require = 0;
+ require += info_little[argc];
+ require += info_big[argc];
+ (void)argv;
+ return require;
+}
diff --git a/Modules/TestForANSIForScope.cmake b/Modules/TestForANSIForScope.cmake
new file mode 100644
index 0000000000..78fff9f74d
--- /dev/null
+++ b/Modules/TestForANSIForScope.cmake
@@ -0,0 +1,52 @@
+#.rst:
+# TestForANSIForScope
+# -------------------
+#
+# Check for ANSI for scope support
+#
+# Check if the compiler restricts the scope of variables declared in a
+# for-init-statement to the loop body.
+#
+# ::
+#
+# CMAKE_NO_ANSI_FOR_SCOPE - holds result
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+if(NOT DEFINED CMAKE_ANSI_FOR_SCOPE)
+ message(STATUS "Check for ANSI scope")
+ try_compile(CMAKE_ANSI_FOR_SCOPE ${CMAKE_BINARY_DIR}
+ ${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx
+ OUTPUT_VARIABLE OUTPUT)
+ if (CMAKE_ANSI_FOR_SCOPE)
+ message(STATUS "Check for ANSI scope - found")
+ set (CMAKE_NO_ANSI_FOR_SCOPE 0 CACHE INTERNAL
+ "Does the compiler support ansi for scope.")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the CXX compiler understands ansi for scopes passed with "
+ "the following output:\n${OUTPUT}\n\n")
+ else ()
+ message(STATUS "Check for ANSI scope - not found")
+ set (CMAKE_NO_ANSI_FOR_SCOPE 1 CACHE INTERNAL
+ "Does the compiler support ansi for scope.")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the CXX compiler understands ansi for scopes failed with "
+ "the following output:\n${OUTPUT}\n\n")
+ endif ()
+endif()
+
+
+
+
+
diff --git a/Modules/TestForANSIStreamHeaders.cmake b/Modules/TestForANSIStreamHeaders.cmake
new file mode 100644
index 0000000000..c13000b707
--- /dev/null
+++ b/Modules/TestForANSIStreamHeaders.cmake
@@ -0,0 +1,42 @@
+#.rst:
+# TestForANSIStreamHeaders
+# ------------------------
+#
+# Test for compiler support of ANSI stream headers iostream, etc.
+#
+# check if the compiler supports the standard ANSI iostream header
+# (without the .h)
+#
+# ::
+#
+# CMAKE_NO_ANSI_STREAM_HEADERS - defined by the results
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CheckIncludeFileCXX.cmake)
+
+if(NOT CMAKE_NO_ANSI_STREAM_HEADERS)
+ CHECK_INCLUDE_FILE_CXX(iostream CMAKE_ANSI_STREAM_HEADERS)
+ if (CMAKE_ANSI_STREAM_HEADERS)
+ set (CMAKE_NO_ANSI_STREAM_HEADERS 0 CACHE INTERNAL
+ "Does the compiler support headers like iostream.")
+ else ()
+ set (CMAKE_NO_ANSI_STREAM_HEADERS 1 CACHE INTERNAL
+ "Does the compiler support headers like iostream.")
+ endif ()
+
+ mark_as_advanced(CMAKE_NO_ANSI_STREAM_HEADERS)
+endif()
+
+
diff --git a/Modules/TestForANSIStreamHeaders.cxx b/Modules/TestForANSIStreamHeaders.cxx
new file mode 100644
index 0000000000..cfb768608f
--- /dev/null
+++ b/Modules/TestForANSIStreamHeaders.cxx
@@ -0,0 +1,6 @@
+#include <iostream>
+
+int main(int,char *[])
+{
+ return 0;
+}
diff --git a/Modules/TestForAnsiForScope.cxx b/Modules/TestForAnsiForScope.cxx
new file mode 100644
index 0000000000..e8807ab4aa
--- /dev/null
+++ b/Modules/TestForAnsiForScope.cxx
@@ -0,0 +1,7 @@
+int main(int, char*[])
+{
+ int i;
+ for(int i=0; i < 1; ++i);
+ (void)i;
+ return 0;
+}
diff --git a/Modules/TestForSSTREAM.cmake b/Modules/TestForSSTREAM.cmake
new file mode 100644
index 0000000000..fe18ea2a78
--- /dev/null
+++ b/Modules/TestForSSTREAM.cmake
@@ -0,0 +1,50 @@
+#.rst:
+# TestForSSTREAM
+# --------------
+#
+# Test for compiler support of ANSI sstream header
+#
+# check if the compiler supports the standard ANSI sstream header
+#
+# ::
+#
+# CMAKE_NO_ANSI_STRING_STREAM - defined by the results
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+if(NOT DEFINED CMAKE_HAS_ANSI_STRING_STREAM)
+ message(STATUS "Check for sstream")
+ try_compile(CMAKE_HAS_ANSI_STRING_STREAM ${CMAKE_BINARY_DIR}
+ ${CMAKE_ROOT}/Modules/TestForSSTREAM.cxx
+ OUTPUT_VARIABLE OUTPUT)
+ if (CMAKE_HAS_ANSI_STRING_STREAM)
+ message(STATUS "Check for sstream - found")
+ set (CMAKE_NO_ANSI_STRING_STREAM 0 CACHE INTERNAL
+ "Does the compiler support sstream")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the CXX compiler has sstream passed with "
+ "the following output:\n${OUTPUT}\n\n")
+ else ()
+ message(STATUS "Check for sstream - not found")
+ set (CMAKE_NO_ANSI_STRING_STREAM 1 CACHE INTERNAL
+ "Does the compiler support sstream")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the CXX compiler has sstream failed with "
+ "the following output:\n${OUTPUT}\n\n")
+ endif ()
+endif()
+
+
+
+
diff --git a/Modules/TestForSSTREAM.cxx b/Modules/TestForSSTREAM.cxx
new file mode 100644
index 0000000000..1c939da239
--- /dev/null
+++ b/Modules/TestForSSTREAM.cxx
@@ -0,0 +1,11 @@
+#include <sstream>
+int main(int, char*[])
+{
+ std::ostringstream os;
+ os << "12345";
+ if(os.str().size() == 5)
+ {
+ return 0;
+ }
+ return -1;
+}
diff --git a/Modules/TestForSTDNamespace.cmake b/Modules/TestForSTDNamespace.cmake
new file mode 100644
index 0000000000..0d907744a4
--- /dev/null
+++ b/Modules/TestForSTDNamespace.cmake
@@ -0,0 +1,50 @@
+#.rst:
+# TestForSTDNamespace
+# -------------------
+#
+# Test for std:: namespace support
+#
+# check if the compiler supports std:: on stl classes
+#
+# ::
+#
+# CMAKE_NO_STD_NAMESPACE - defined by the results
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+if(NOT DEFINED CMAKE_STD_NAMESPACE)
+ message(STATUS "Check for STD namespace")
+ try_compile(CMAKE_STD_NAMESPACE ${CMAKE_BINARY_DIR}
+ ${CMAKE_ROOT}/Modules/TestForSTDNamespace.cxx
+ OUTPUT_VARIABLE OUTPUT)
+ if (CMAKE_STD_NAMESPACE)
+ message(STATUS "Check for STD namespace - found")
+ set (CMAKE_NO_STD_NAMESPACE 0 CACHE INTERNAL
+ "Does the compiler support std::.")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the CXX compiler has std namespace passed with "
+ "the following output:\n${OUTPUT}\n\n")
+ else ()
+ message(STATUS "Check for STD namespace - not found")
+ set (CMAKE_NO_STD_NAMESPACE 1 CACHE INTERNAL
+ "Does the compiler support std::.")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the CXX compiler has std namespace failed with "
+ "the following output:\n${OUTPUT}\n\n")
+ endif ()
+endif()
+
+
+
+
diff --git a/Modules/TestForSTDNamespace.cxx b/Modules/TestForSTDNamespace.cxx
new file mode 100644
index 0000000000..b537d44a93
--- /dev/null
+++ b/Modules/TestForSTDNamespace.cxx
@@ -0,0 +1,6 @@
+#include <list>
+int main(int, char*[])
+{
+ std::list<int>();
+ return 0;
+}
diff --git a/Modules/UseEcos.cmake b/Modules/UseEcos.cmake
new file mode 100644
index 0000000000..3bd92ca230
--- /dev/null
+++ b/Modules/UseEcos.cmake
@@ -0,0 +1,245 @@
+#.rst:
+# UseEcos
+# -------
+#
+# This module defines variables and macros required to build eCos application.
+#
+# This file contains the following macros:
+# ECOS_ADD_INCLUDE_DIRECTORIES() - add the eCos include dirs
+# ECOS_ADD_EXECUTABLE(name source1 ... sourceN ) - create an eCos
+# executable ECOS_ADJUST_DIRECTORY(VAR source1 ... sourceN ) - adjusts
+# the path of the source files and puts the result into VAR
+#
+# Macros for selecting the toolchain: ECOS_USE_ARM_ELF_TOOLS() - enable
+# the ARM ELF toolchain for the directory where it is called
+# ECOS_USE_I386_ELF_TOOLS() - enable the i386 ELF toolchain for the
+# directory where it is called ECOS_USE_PPC_EABI_TOOLS() - enable the
+# PowerPC toolchain for the directory where it is called
+#
+# It contains the following variables: ECOS_DEFINITIONS
+# ECOSCONFIG_EXECUTABLE ECOS_CONFIG_FILE - defaults to ecos.ecc, if your
+# eCos configuration file has a different name, adjust this variable for
+# internal use only:
+#
+# ::
+#
+# ECOS_ADD_TARGET_LIB
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+# first check that ecosconfig is available
+find_program(ECOSCONFIG_EXECUTABLE NAMES ecosconfig)
+if(NOT ECOSCONFIG_EXECUTABLE)
+ message(SEND_ERROR "ecosconfig was not found. Either include it in the system path or set it manually using ccmake.")
+else()
+ message(STATUS "Found ecosconfig: ${ECOSCONFIG_EXECUTABLE}")
+endif()
+
+# check that ECOS_REPOSITORY is set correctly
+if (NOT EXISTS $ENV{ECOS_REPOSITORY}/ecos.db)
+ message(SEND_ERROR "The environment variable ECOS_REPOSITORY is not set correctly. Set it to the directory which contains the file ecos.db")
+else ()
+ message(STATUS "ECOS_REPOSITORY is set to $ENV{ECOS_REPOSITORY}")
+endif ()
+
+# check that tclsh (coming with TCL) is available, otherwise ecosconfig doesn't work
+find_package(Tclsh)
+if (NOT TCL_TCLSH)
+ message(SEND_ERROR "The TCL tclsh was not found. Please install TCL, it is required for building eCos applications.")
+else ()
+ message(STATUS "tlcsh found: ${TCL_TCLSH}")
+endif ()
+
+#add the globale include-diretories
+#usage: ECOS_ADD_INCLUDE_DIRECTORIES()
+macro(ECOS_ADD_INCLUDE_DIRECTORIES)
+#check for ProjectSources.txt one level higher
+ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../ProjectSources.txt)
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
+ else ()
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
+ endif ()
+
+#the ecos include directory
+ include_directories(${CMAKE_CURRENT_BINARY_DIR}/ecos/install/include/)
+
+endmacro()
+
+
+#we want to compile for the xscale processor, in this case the following macro has to be called
+#usage: ECOS_USE_ARM_ELF_TOOLS()
+macro (ECOS_USE_ARM_ELF_TOOLS)
+ set(CMAKE_CXX_COMPILER "arm-elf-c++")
+ set(CMAKE_COMPILER_IS_GNUCXX 1)
+ set(CMAKE_C_COMPILER "arm-elf-gcc")
+ set(CMAKE_AR "arm-elf-ar")
+ set(CMAKE_RANLIB "arm-elf-ranlib")
+#for linking
+ set(ECOS_LD_MCPU "-mcpu=xscale")
+#for compiling
+ add_definitions(-mcpu=xscale -mapcs-frame)
+#for the obj-tools
+ set(ECOS_ARCH_PREFIX "arm-elf-")
+endmacro ()
+
+#usage: ECOS_USE_PPC_EABI_TOOLS()
+macro (ECOS_USE_PPC_EABI_TOOLS)
+ set(CMAKE_CXX_COMPILER "powerpc-eabi-c++")
+ set(CMAKE_COMPILER_IS_GNUCXX 1)
+ set(CMAKE_C_COMPILER "powerpc-eabi-gcc")
+ set(CMAKE_AR "powerpc-eabi-ar")
+ set(CMAKE_RANLIB "powerpc-eabi-ranlib")
+#for linking
+ set(ECOS_LD_MCPU "")
+#for compiling
+ add_definitions()
+#for the obj-tools
+ set(ECOS_ARCH_PREFIX "powerpc-eabi-")
+endmacro ()
+
+#usage: ECOS_USE_I386_ELF_TOOLS()
+macro (ECOS_USE_I386_ELF_TOOLS)
+ set(CMAKE_CXX_COMPILER "i386-elf-c++")
+ set(CMAKE_COMPILER_IS_GNUCXX 1)
+ set(CMAKE_C_COMPILER "i386-elf-gcc")
+ set(CMAKE_AR "i386-elf-ar")
+ set(CMAKE_RANLIB "i386-elf-ranlib")
+#for linking
+ set(ECOS_LD_MCPU "")
+#for compiling
+ add_definitions()
+#for the obj-tools
+ set(ECOS_ARCH_PREFIX "i386-elf-")
+endmacro ()
+
+
+#since the actual sources are located one level upwards
+#a "../" has to be prepended in front of every source file
+#call the following macro to achieve this, the first parameter
+#is the name of the new list of source files with adjusted paths,
+#followed by all source files
+#usage: ECOS_ADJUST_DIRECTORY(adjusted_SRCS ${my_srcs})
+macro(ECOS_ADJUST_DIRECTORY _target_FILES )
+ foreach (_current_FILE ${ARGN})
+ get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
+ if (NOT ${_abs_FILE} STREQUAL ${_current_FILE})
+ get_filename_component(_abs_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../${_current_FILE} ABSOLUTE)
+ endif ()
+ list(APPEND ${_target_FILES} ${_abs_FILE})
+ endforeach ()
+endmacro()
+
+# the default ecos config file name
+# maybe in future also out-of-source builds may be possible
+set(ECOS_CONFIG_FILE ecos.ecc)
+
+#creates the dependency from all source files on the ecos target.ld,
+#adds the command for compiling ecos
+macro(ECOS_ADD_TARGET_LIB)
+# when building out-of-source, create the ecos/ subdir
+ if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/ecos)
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ecos)
+ endif()
+
+#sources depend on target.ld
+ set_source_files_properties(
+ ${ARGN}
+ PROPERTIES
+ OBJECT_DEPENDS
+ ${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld
+ )
+
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld
+ COMMAND sh -c \"make -C ${CMAKE_CURRENT_BINARY_DIR}/ecos || exit -1\; if [ -e ${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld ] \; then touch ${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld\; fi\"
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ecos/makefile
+ )
+
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ecos/makefile
+ COMMAND sh -c \" cd ${CMAKE_CURRENT_BINARY_DIR}/ecos\; ${ECOSCONFIG_EXECUTABLE} --config=${CMAKE_CURRENT_SOURCE_DIR}/ecos/${ECOS_CONFIG_FILE} tree || exit -1\;\"
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ecos/${ECOS_CONFIG_FILE}
+ )
+
+ add_custom_target( ecos make -C ${CMAKE_CURRENT_BINARY_DIR}/ecos/ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ecos/makefile )
+endmacro()
+
+# get the directory of the current file, used later on in the file
+get_filename_component( ECOS_CMAKE_MODULE_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
+
+#macro for creating an executable ecos application
+#the first parameter is the name of the executable,
+#the second is the list of all source files (where the path
+#has been adjusted beforehand by calling ECOS_ADJUST_DIRECTORY()
+#usage: ECOS_ADD_EXECUTABLE(my_app ${adjusted_SRCS})
+macro(ECOS_ADD_EXECUTABLE _exe_NAME )
+ #definitions, valid for all ecos projects
+ #the optimization and "-g" for debugging has to be enabled
+ #in the project-specific CMakeLists.txt
+ add_definitions(-D__ECOS__=1 -D__ECOS=1)
+ set(ECOS_DEFINITIONS -Wall -Wno-long-long -pipe -fno-builtin)
+
+#the executable depends on ecos target.ld
+ ECOS_ADD_TARGET_LIB(${ARGN})
+
+# when using nmake makefiles, the custom buildtype supresses the default cl.exe flags
+# and the rules for creating objects are adjusted for gcc
+ set(CMAKE_BUILD_TYPE CUSTOM_ECOS_BUILD)
+ set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <FLAGS> -o <OBJECT> -c <SOURCE>")
+ set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <FLAGS> -o <OBJECT> -c <SOURCE>")
+# special link commands for ecos-executables
+ set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <OBJECTS> -o <TARGET> ${_ecos_EXTRA_LIBS} -nostdlib -nostartfiles -L${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib -Ttarget.ld ${ECOS_LD_MCPU}")
+ set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <OBJECTS> -o <TARGET> ${_ecos_EXTRA_LIBS} -nostdlib -nostartfiles -L${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib -Ttarget.ld ${ECOS_LD_MCPU}")
+# some strict compiler flags
+ set (CMAKE_C_FLAGS "-Wstrict-prototypes")
+ set (CMAKE_CXX_FLAGS "-Woverloaded-virtual -fno-rtti -Wctor-dtor-privacy -fno-strict-aliasing -fno-exceptions")
+
+ add_executable(${_exe_NAME} ${ARGN})
+ set_target_properties(${_exe_NAME} PROPERTIES SUFFIX ".elf")
+
+#create a binary file
+ add_custom_command(
+ TARGET ${_exe_NAME}
+ POST_BUILD
+ COMMAND ${ECOS_ARCH_PREFIX}objcopy
+ ARGS -O binary ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.bin
+ )
+
+#and an srec file
+ add_custom_command(
+ TARGET ${_exe_NAME}
+ POST_BUILD
+ COMMAND ${ECOS_ARCH_PREFIX}objcopy
+ ARGS -O srec ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.srec
+ )
+
+#add the created files to the clean-files
+ set_directory_properties(
+ PROPERTIES
+ ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.bin;${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.srec;${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst;"
+ )
+
+ add_custom_target(ecosclean ${CMAKE_COMMAND} -DECOS_DIR=${CMAKE_CURRENT_BINARY_DIR}/ecos/ -P ${ECOS_CMAKE_MODULE_DIR}/ecos_clean.cmake )
+ add_custom_target(normalclean ${CMAKE_MAKE_PROGRAM} clean WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ add_dependencies (ecosclean normalclean)
+
+
+ add_custom_target( listing
+ COMMAND echo -e \"\\n--- Symbols sorted by address ---\\n\" > ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
+ COMMAND ${ECOS_ARCH_PREFIX}nm -S -C -n ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
+ COMMAND echo -e \"\\n--- Symbols sorted by size ---\\n\" >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
+ COMMAND ${ECOS_ARCH_PREFIX}nm -S -C -r --size-sort ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
+ COMMAND echo -e \"\\n--- Full assembly listing ---\\n\" >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
+ COMMAND ${ECOS_ARCH_PREFIX}objdump -S -x -d -C ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst )
+
+endmacro()
+
diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake
new file mode 100644
index 0000000000..127012fda3
--- /dev/null
+++ b/Modules/UseJava.cmake
@@ -0,0 +1,1075 @@
+#.rst:
+# UseJava
+# -------
+#
+# Use Module for Java
+#
+# This file provides functions for Java. It is assumed that
+# FindJava.cmake has already been loaded. See FindJava.cmake for
+# information on how to load Java into your CMake project.
+#
+# ::
+#
+# add_jar(target_name
+# [SOURCES] source1 [source2 ...] [resource1 ...]
+# [INCLUDE_JARS jar1 [jar2 ...]]
+# [ENTRY_POINT entry]
+# [VERSION version]
+# [OUTPUT_NAME name]
+# [OUTPUT_DIR dir]
+# )
+#
+# This command creates a <target_name>.jar. It compiles the given
+# source files (source) and adds the given resource files (resource) to
+# the jar file. If only resource files are given then just a jar file
+# is created. The list of include jars are added to the classpath when
+# compiling the java sources and also to the dependencies of the target.
+# INCLUDE_JARS also accepts other target names created by add_jar. For
+# backwards compatibility, jar files listed as sources are ignored (as
+# they have been since the first version of this module).
+#
+# The default OUTPUT_DIR can also be changed by setting the variable
+# CMAKE_JAVA_TARGET_OUTPUT_DIR.
+#
+# Additional instructions:
+#
+# ::
+#
+# To add compile flags to the target you can set these flags with
+# the following variable:
+#
+#
+#
+# ::
+#
+# set(CMAKE_JAVA_COMPILE_FLAGS -nowarn)
+#
+#
+#
+# ::
+#
+# To add a path or a jar file to the class path you can do this
+# with the CMAKE_JAVA_INCLUDE_PATH variable.
+#
+#
+#
+# ::
+#
+# set(CMAKE_JAVA_INCLUDE_PATH /usr/share/java/shibboleet.jar)
+#
+#
+#
+# ::
+#
+# To use a different output name for the target you can set it with:
+#
+#
+#
+# ::
+#
+# add_jar(foobar foobar.java OUTPUT_NAME shibboleet.jar)
+#
+#
+#
+# ::
+#
+# To use a different output directory than CMAKE_CURRENT_BINARY_DIR
+# you can set it with:
+#
+#
+#
+# ::
+#
+# add_jar(foobar foobar.java OUTPUT_DIR ${PROJECT_BINARY_DIR}/bin)
+#
+#
+#
+# ::
+#
+# To define an entry point in your jar you can set it with the ENTRY_POINT
+# named argument:
+#
+#
+#
+# ::
+#
+# add_jar(example ENTRY_POINT com/examples/MyProject/Main)
+#
+#
+#
+# ::
+#
+# To define a custom manifest for the jar, you can set it with the manifest
+# named argument:
+#
+#
+#
+# ::
+#
+# add_jar(example MANIFEST /path/to/manifest)
+#
+#
+#
+# ::
+#
+# To add a VERSION to the target output name you can set it using
+# the VERSION named argument to add_jar. This will create a jar file with the
+# name shibboleet-1.0.0.jar and will create a symlink shibboleet.jar
+# pointing to the jar with the version information.
+#
+#
+#
+# ::
+#
+# add_jar(shibboleet shibbotleet.java VERSION 1.2.0)
+#
+#
+#
+# ::
+#
+# If the target is a JNI library, utilize the following commands to
+# create a JNI symbolic link:
+#
+#
+#
+# ::
+#
+# set(CMAKE_JNI_TARGET TRUE)
+# add_jar(shibboleet shibbotleet.java VERSION 1.2.0)
+# install_jar(shibboleet ${LIB_INSTALL_DIR}/shibboleet)
+# install_jni_symlink(shibboleet ${JAVA_LIB_INSTALL_DIR})
+#
+#
+#
+# ::
+#
+# If a single target needs to produce more than one jar from its
+# java source code, to prevent the accumulation of duplicate class
+# files in subsequent jars, set/reset CMAKE_JAR_CLASSES_PREFIX prior
+# to calling the add_jar() function:
+#
+#
+#
+# ::
+#
+# set(CMAKE_JAR_CLASSES_PREFIX com/redhat/foo)
+# add_jar(foo foo.java)
+#
+#
+#
+# ::
+#
+# set(CMAKE_JAR_CLASSES_PREFIX com/redhat/bar)
+# add_jar(bar bar.java)
+#
+#
+#
+# Target Properties:
+#
+# ::
+#
+# The add_jar() functions sets some target properties. You can get these
+# properties with the
+# get_property(TARGET <target_name> PROPERTY <propery_name>)
+# command.
+#
+#
+#
+# ::
+#
+# INSTALL_FILES The files which should be installed. This is used by
+# install_jar().
+# JNI_SYMLINK The JNI symlink which should be installed.
+# 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
+# example to use them with javah.
+#
+# ::
+#
+# find_jar(<VAR>
+# name | NAMES name1 [name2 ...]
+# [PATHS path1 [path2 ... ENV var]]
+# [VERSIONS version1 [version2]]
+# [DOC "cache documentation string"]
+# )
+#
+# This command is used to find a full path to the named jar. A cache
+# entry named by <VAR> is created to stor the result of this command.
+# If the full path to a jar is found the result is stored in the
+# variable and the search will not repeated unless the variable is
+# cleared. If nothing is found, the result will be <VAR>-NOTFOUND, and
+# the search will be attempted again next time find_jar is invoked with
+# the same variable. The name of the full path to a file that is
+# searched for is specified by the names listed after NAMES argument.
+# Additional search locations can be specified after the PATHS argument.
+# If you require special a version of a jar file you can specify it with
+# the VERSIONS argument. The argument after DOC will be used for the
+# documentation string in the cache.
+#
+# ::
+#
+# install_jar(TARGET_NAME DESTINATION)
+#
+# This command installs the TARGET_NAME files to the given DESTINATION.
+# It should be called in the same scope as add_jar() or it will fail.
+#
+# ::
+#
+# install_jni_symlink(TARGET_NAME DESTINATION)
+#
+# This command installs the TARGET_NAME JNI symlinks to the given
+# DESTINATION. It should be called in the same scope as add_jar() or it
+# will fail.
+#
+# ::
+#
+# create_javadoc(<VAR>
+# PACKAGES pkg1 [pkg2 ...]
+# [SOURCEPATH <sourcepath>]
+# [CLASSPATH <classpath>]
+# [INSTALLPATH <install path>]
+# [DOCTITLE "the documentation title"]
+# [WINDOWTITLE "the title of the document"]
+# [AUTHOR TRUE|FALSE]
+# [USE TRUE|FALSE]
+# [VERSION TRUE|FALSE]
+# )
+#
+# Create java documentation based on files or packages. For more
+# details please read the javadoc manpage.
+#
+# There are two main signatures for create_javadoc. The first signature
+# works with package names on a path with source files:
+#
+# ::
+#
+# Example:
+# create_javadoc(my_example_doc
+# PACKAGES com.exmaple.foo com.example.bar
+# SOURCEPATH "${CMAKE_CURRENT_SOURCE_DIR}"
+# CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
+# WINDOWTITLE "My example"
+# DOCTITLE "<h1>My example</h1>"
+# AUTHOR TRUE
+# USE TRUE
+# VERSION TRUE
+# )
+#
+#
+#
+# The second signature for create_javadoc works on a given list of
+# files.
+#
+# ::
+#
+# create_javadoc(<VAR>
+# FILES file1 [file2 ...]
+# [CLASSPATH <classpath>]
+# [INSTALLPATH <install path>]
+# [DOCTITLE "the documentation title"]
+# [WINDOWTITLE "the title of the document"]
+# [AUTHOR TRUE|FALSE]
+# [USE TRUE|FALSE]
+# [VERSION TRUE|FALSE]
+# )
+#
+#
+#
+# Example:
+#
+# ::
+#
+# create_javadoc(my_example_doc
+# FILES ${example_SRCS}
+# CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
+# WINDOWTITLE "My example"
+# DOCTITLE "<h1>My example</h1>"
+# AUTHOR TRUE
+# USE TRUE
+# VERSION TRUE
+# )
+#
+#
+#
+# Both signatures share most of the options. These options are the same
+# as what you can find in the javadoc manpage. Please look at the
+# manpage for CLASSPATH, DOCTITLE, WINDOWTITLE, AUTHOR, USE and VERSION.
+#
+# The documentation will be by default installed to
+#
+# ::
+#
+# ${CMAKE_INSTALL_PREFIX}/share/javadoc/<VAR>
+#
+#
+#
+# if you don't set the INSTALLPATH.
+
+#=============================================================================
+# Copyright 2013 OpenGamma Ltd. <graham@opengamma.com>
+# Copyright 2010-2011 Andreas schneider <asn@redhat.com>
+# Copyright 2010-2013 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
+
+function (__java_copy_file src dest comment)
+ add_custom_command(
+ OUTPUT ${dest}
+ COMMAND cmake -E copy_if_different
+ ARGS ${src}
+ ${dest}
+ DEPENDS ${src}
+ COMMENT ${comment})
+endfunction ()
+
+# define helper scripts
+set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake)
+set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake)
+
+function(add_jar _TARGET_NAME)
+
+ # In CMake < 2.8.12, add_jar used variables which were set prior to calling
+ # add_jar for customizing the behavior of add_jar. In order to be backwards
+ # compatible, check if any of those variables are set, and use them to
+ # initialize values of the named arguments. (Giving the corresponding named
+ # argument will override the value set here.)
+ #
+ # New features should use named arguments only.
+ if(DEFINED CMAKE_JAVA_TARGET_VERSION)
+ set(_add_jar_VERSION "${CMAKE_JAVA_TARGET_VERSION}")
+ endif()
+ if(DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR)
+ set(_add_jar_OUTPUT_DIR "${CMAKE_JAVA_TARGET_OUTPUT_DIR}")
+ endif()
+ if(DEFINED CMAKE_JAVA_TARGET_OUTPUT_NAME)
+ set(_add_jar_OUTPUT_NAME "${CMAKE_JAVA_TARGET_OUTPUT_NAME}")
+ # reset
+ set(CMAKE_JAVA_TARGET_OUTPUT_NAME)
+ endif()
+ if(DEFINED CMAKE_JAVA_JAR_ENTRY_POINT)
+ set(_add_jar_ENTRY_POINT "${CMAKE_JAVA_JAR_ENTRY_POINT}")
+ endif()
+
+ cmake_parse_arguments(_add_jar
+ ""
+ "VERSION;OUTPUT_DIR;OUTPUT_NAME;ENTRY_POINT;MANIFEST"
+ "SOURCES;INCLUDE_JARS"
+ ${ARGN}
+ )
+
+ set(_JAVA_SOURCE_FILES ${_add_jar_SOURCES} ${_add_jar_UNPARSED_ARGUMENTS})
+
+ if (NOT DEFINED _add_jar_OUTPUT_DIR)
+ set(_add_jar_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
+ endif()
+
+ if (_add_jar_ENTRY_POINT)
+ set(_ENTRY_POINT_OPTION e)
+ set(_ENTRY_POINT_VALUE ${_add_jar_ENTRY_POINT})
+ endif ()
+
+ if (_add_jar_MANIFEST)
+ set(_MANIFEST_OPTION m)
+ set(_MANIFEST_VALUE ${_add_jar_MANIFEST})
+ endif ()
+
+ if (LIBRARY_OUTPUT_PATH)
+ set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH})
+ else ()
+ set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${_add_jar_OUTPUT_DIR})
+ endif ()
+
+ set(CMAKE_JAVA_INCLUDE_PATH
+ ${CMAKE_JAVA_INCLUDE_PATH}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_JAVA_OBJECT_OUTPUT_PATH}
+ ${CMAKE_JAVA_LIBRARY_OUTPUT_PATH}
+ )
+
+ if (WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
+ set(CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
+ else ()
+ set(CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
+ endif()
+
+ foreach (JAVA_INCLUDE_DIR ${CMAKE_JAVA_INCLUDE_PATH})
+ set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${JAVA_INCLUDE_DIR}")
+ endforeach()
+
+ set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${_add_jar_OUTPUT_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir")
+
+ set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar")
+ if (_add_jar_OUTPUT_NAME AND _add_jar_VERSION)
+ set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}-${_add_jar_VERSION}.jar")
+ set(_JAVA_TARGET_OUTPUT_LINK "${_add_jar_OUTPUT_NAME}.jar")
+ elseif (_add_jar_VERSION)
+ set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}-${_add_jar_VERSION}.jar")
+ set(_JAVA_TARGET_OUTPUT_LINK "${_TARGET_NAME}.jar")
+ elseif (_add_jar_OUTPUT_NAME)
+ set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}.jar")
+ endif ()
+
+ set(_JAVA_CLASS_FILES)
+ set(_JAVA_COMPILE_FILES)
+ set(_JAVA_DEPENDS)
+ set(_JAVA_COMPILE_DEPENDS)
+ set(_JAVA_RESOURCE_FILES)
+ set(_JAVA_RESOURCE_FILES_RELATIVE)
+ foreach(_JAVA_SOURCE_FILE ${_JAVA_SOURCE_FILES})
+ get_filename_component(_JAVA_EXT ${_JAVA_SOURCE_FILE} EXT)
+ get_filename_component(_JAVA_FILE ${_JAVA_SOURCE_FILE} NAME_WE)
+ get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH)
+ get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE)
+
+ if (_JAVA_EXT MATCHES ".java")
+ file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${_add_jar_OUTPUT_DIR} ${_JAVA_FULL})
+ file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL})
+ string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN)
+ string(LENGTH ${_JAVA_REL_SOURCE_PATH} _SRC_LEN)
+ if (${_BIN_LEN} LESS ${_SRC_LEN})
+ set(_JAVA_REL_PATH ${_JAVA_REL_BINARY_PATH})
+ else ()
+ set(_JAVA_REL_PATH ${_JAVA_REL_SOURCE_PATH})
+ endif ()
+ get_filename_component(_JAVA_REL_PATH ${_JAVA_REL_PATH} PATH)
+
+ list(APPEND _JAVA_COMPILE_FILES ${_JAVA_SOURCE_FILE})
+ set(_JAVA_CLASS_FILE "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_REL_PATH}/${_JAVA_FILE}.class")
+ set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES} ${_JAVA_CLASS_FILE})
+
+ elseif (_JAVA_EXT MATCHES ".jar"
+ OR _JAVA_EXT MATCHES ".war"
+ OR _JAVA_EXT MATCHES ".ear"
+ OR _JAVA_EXT MATCHES ".sar")
+ # Ignored for backward compatibility
+
+ elseif (_JAVA_EXT STREQUAL "")
+ list(APPEND CMAKE_JAVA_INCLUDE_PATH ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}} ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}_CLASSPATH})
+ list(APPEND _JAVA_DEPENDS ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}})
+
+ else ()
+ __java_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/${_JAVA_SOURCE_FILE}
+ ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE}
+ "Copying ${_JAVA_SOURCE_FILE} to the build directory")
+ list(APPEND _JAVA_RESOURCE_FILES ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE})
+ list(APPEND _JAVA_RESOURCE_FILES_RELATIVE ${_JAVA_SOURCE_FILE})
+ endif ()
+ endforeach()
+
+ foreach(_JAVA_INCLUDE_JAR ${_add_jar_INCLUDE_JARS})
+ if (TARGET ${_JAVA_INCLUDE_JAR})
+ get_target_property(_JAVA_JAR_PATH ${_JAVA_INCLUDE_JAR} JAR_FILE)
+ if (_JAVA_JAR_PATH)
+ set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_JAR_PATH}")
+ list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_JAR_PATH})
+ list(APPEND _JAVA_DEPENDS ${_JAVA_INCLUDE_JAR})
+ list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_INCLUDE_JAR})
+ else ()
+ message(SEND_ERROR "add_jar: INCLUDE_JARS target ${_JAVA_INCLUDE_JAR} is not a jar")
+ endif ()
+ else ()
+ set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_INCLUDE_JAR}")
+ list(APPEND CMAKE_JAVA_INCLUDE_PATH "${_JAVA_INCLUDE_JAR}")
+ list(APPEND _JAVA_DEPENDS "${_JAVA_INCLUDE_JAR}")
+ list(APPEND _JAVA_COMPILE_DEPENDS "${_JAVA_INCLUDE_JAR}")
+ endif ()
+ endforeach()
+
+ # create an empty java_class_filelist
+ if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist)
+ file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
+ endif()
+
+ if (_JAVA_COMPILE_FILES)
+ # Create the list of files to compile.
+ set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources)
+ string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"")
+ file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING})
+
+ # Compile the java files and create a list of class files
+ add_custom_command(
+ # NOTE: this command generates an artificial dependency file
+ OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
+ COMMAND ${Java_JAVAC_EXECUTABLE}
+ ${CMAKE_JAVA_COMPILE_FLAGS}
+ -classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}"
+ -d ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
+ @${_JAVA_SOURCES_FILE}
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
+ DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_DEPENDS}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMENT "Building Java objects for ${_TARGET_NAME}.jar"
+ )
+ add_custom_command(
+ OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
+ COMMAND ${CMAKE_COMMAND}
+ -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH}
+ -DCMAKE_JAR_CLASSES_PREFIX="${CMAKE_JAR_CLASSES_PREFIX}"
+ -P ${_JAVA_CLASS_FILELIST_SCRIPT}
+ DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+ endif ()
+
+ # create the jar file
+ set(_JAVA_JAR_OUTPUT_PATH
+ ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_NAME})
+ if (CMAKE_JNI_TARGET)
+ add_custom_command(
+ OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
+ COMMAND ${Java_JAR_EXECUTABLE}
+ -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
+ ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
+ COMMAND ${CMAKE_COMMAND}
+ -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
+ -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
+ -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
+ -P ${_JAVA_SYMLINK_SCRIPT}
+ COMMAND ${CMAKE_COMMAND}
+ -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
+ -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_JAR_OUTPUT_PATH}
+ -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
+ -P ${_JAVA_SYMLINK_SCRIPT}
+ DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
+ WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
+ COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
+ )
+ else ()
+ add_custom_command(
+ OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
+ COMMAND ${Java_JAR_EXECUTABLE}
+ -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
+ ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
+ COMMAND ${CMAKE_COMMAND}
+ -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
+ -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
+ -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
+ -P ${_JAVA_SYMLINK_SCRIPT}
+ WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
+ DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
+ COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
+ )
+ endif ()
+
+ # Add the target and make sure we have the latest resource files.
+ add_custom_target(${_TARGET_NAME} ALL DEPENDS ${_JAVA_JAR_OUTPUT_PATH})
+
+ set_property(
+ TARGET
+ ${_TARGET_NAME}
+ PROPERTY
+ INSTALL_FILES
+ ${_JAVA_JAR_OUTPUT_PATH}
+ )
+
+ if (_JAVA_TARGET_OUTPUT_LINK)
+ set_property(
+ TARGET
+ ${_TARGET_NAME}
+ PROPERTY
+ INSTALL_FILES
+ ${_JAVA_JAR_OUTPUT_PATH}
+ ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
+ )
+
+ if (CMAKE_JNI_TARGET)
+ set_property(
+ TARGET
+ ${_TARGET_NAME}
+ PROPERTY
+ JNI_SYMLINK
+ ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
+ )
+ endif ()
+ endif ()
+
+ set_property(
+ TARGET
+ ${_TARGET_NAME}
+ PROPERTY
+ JAR_FILE
+ ${_JAVA_JAR_OUTPUT_PATH}
+ )
+
+ set_property(
+ TARGET
+ ${_TARGET_NAME}
+ PROPERTY
+ CLASSDIR
+ ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
+ )
+
+endfunction()
+
+function(INSTALL_JAR _TARGET_NAME _DESTINATION)
+ get_property(__FILES
+ TARGET
+ ${_TARGET_NAME}
+ PROPERTY
+ INSTALL_FILES
+ )
+
+ if (__FILES)
+ install(
+ FILES
+ ${__FILES}
+ DESTINATION
+ ${_DESTINATION}
+ )
+ else ()
+ message(SEND_ERROR "The target ${_TARGET_NAME} is not known in this scope.")
+ endif ()
+endfunction()
+
+function(INSTALL_JNI_SYMLINK _TARGET_NAME _DESTINATION)
+ get_property(__SYMLINK
+ TARGET
+ ${_TARGET_NAME}
+ PROPERTY
+ JNI_SYMLINK
+ )
+
+ if (__SYMLINK)
+ install(
+ FILES
+ ${__SYMLINK}
+ DESTINATION
+ ${_DESTINATION}
+ )
+ else ()
+ message(SEND_ERROR "The target ${_TARGET_NAME} is not known in this scope.")
+ endif ()
+endfunction()
+
+function (find_jar VARIABLE)
+ set(_jar_names)
+ set(_jar_files)
+ set(_jar_versions)
+ set(_jar_paths
+ /usr/share/java/
+ /usr/local/share/java/
+ ${Java_JAR_PATHS})
+ set(_jar_doc "NOTSET")
+
+ set(_state "name")
+
+ foreach (arg ${ARGN})
+ if (${_state} STREQUAL "name")
+ if (${arg} STREQUAL "VERSIONS")
+ set(_state "versions")
+ elseif (${arg} STREQUAL "NAMES")
+ set(_state "names")
+ elseif (${arg} STREQUAL "PATHS")
+ set(_state "paths")
+ elseif (${arg} STREQUAL "DOC")
+ set(_state "doc")
+ else ()
+ set(_jar_names ${arg})
+ if (_jar_doc STREQUAL "NOTSET")
+ set(_jar_doc "Finding ${arg} jar")
+ endif ()
+ endif ()
+ elseif (${_state} STREQUAL "versions")
+ if (${arg} STREQUAL "NAMES")
+ set(_state "names")
+ elseif (${arg} STREQUAL "PATHS")
+ set(_state "paths")
+ elseif (${arg} STREQUAL "DOC")
+ set(_state "doc")
+ else ()
+ set(_jar_versions ${_jar_versions} ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "names")
+ if (${arg} STREQUAL "VERSIONS")
+ set(_state "versions")
+ elseif (${arg} STREQUAL "PATHS")
+ set(_state "paths")
+ elseif (${arg} STREQUAL "DOC")
+ set(_state "doc")
+ else ()
+ set(_jar_names ${_jar_names} ${arg})
+ if (_jar_doc STREQUAL "NOTSET")
+ set(_jar_doc "Finding ${arg} jar")
+ endif ()
+ endif ()
+ elseif (${_state} STREQUAL "paths")
+ if (${arg} STREQUAL "VERSIONS")
+ set(_state "versions")
+ elseif (${arg} STREQUAL "NAMES")
+ set(_state "names")
+ elseif (${arg} STREQUAL "DOC")
+ set(_state "doc")
+ else ()
+ set(_jar_paths ${_jar_paths} ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "doc")
+ if (${arg} STREQUAL "VERSIONS")
+ set(_state "versions")
+ elseif (${arg} STREQUAL "NAMES")
+ set(_state "names")
+ elseif (${arg} STREQUAL "PATHS")
+ set(_state "paths")
+ else ()
+ set(_jar_doc ${arg})
+ endif ()
+ endif ()
+ endforeach ()
+
+ if (NOT _jar_names)
+ message(FATAL_ERROR "find_jar: No name to search for given")
+ endif ()
+
+ foreach (jar_name ${_jar_names})
+ foreach (version ${_jar_versions})
+ set(_jar_files ${_jar_files} ${jar_name}-${version}.jar)
+ endforeach ()
+ set(_jar_files ${_jar_files} ${jar_name}.jar)
+ endforeach ()
+
+ find_file(${VARIABLE}
+ NAMES ${_jar_files}
+ PATHS ${_jar_paths}
+ DOC ${_jar_doc}
+ NO_DEFAULT_PATH)
+endfunction ()
+
+function(create_javadoc _target)
+ set(_javadoc_packages)
+ set(_javadoc_files)
+ set(_javadoc_sourcepath)
+ set(_javadoc_classpath)
+ set(_javadoc_installpath "${CMAKE_INSTALL_PREFIX}/share/javadoc")
+ set(_javadoc_doctitle)
+ set(_javadoc_windowtitle)
+ set(_javadoc_author FALSE)
+ set(_javadoc_version FALSE)
+ set(_javadoc_use FALSE)
+
+ set(_state "package")
+
+ foreach (arg ${ARGN})
+ if (${_state} STREQUAL "package")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "CLASSPATH")
+ set(_state "classpath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ set(_javadoc_packages ${arg})
+ set(_state "packages")
+ endif ()
+ elseif (${_state} STREQUAL "packages")
+ if (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "CLASSPATH")
+ set(_state "classpath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ list(APPEND _javadoc_packages ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "files")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "CLASSPATH")
+ set(_state "classpath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ list(APPEND _javadoc_files ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "sourcepath")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "CLASSPATH")
+ set(_state "classpath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ list(APPEND _javadoc_sourcepath ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "classpath")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ list(APPEND _javadoc_classpath ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "installpath")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ set(_javadoc_installpath ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "doctitle")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "CLASSPATH")
+ set(_state "classpath")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ set(_javadoc_doctitle ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "windowtitle")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "CLASSPATH")
+ set(_state "classpath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ set(_javadoc_windowtitle ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "author")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "CLASSPATH")
+ set(_state "classpath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ set(_javadoc_author ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "use")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "CLASSPATH")
+ set(_state "classpath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ set(_javadoc_use ${arg})
+ endif ()
+ elseif (${_state} STREQUAL "version")
+ if (${arg} STREQUAL "PACKAGES")
+ set(_state "packages")
+ elseif (${arg} STREQUAL "FILES")
+ set(_state "files")
+ elseif (${arg} STREQUAL "SOURCEPATH")
+ set(_state "sourcepath")
+ elseif (${arg} STREQUAL "CLASSPATH")
+ set(_state "classpath")
+ elseif (${arg} STREQUAL "INSTALLPATH")
+ set(_state "installpath")
+ elseif (${arg} STREQUAL "DOCTITLE")
+ set(_state "doctitle")
+ elseif (${arg} STREQUAL "WINDOWTITLE")
+ set(_state "windowtitle")
+ elseif (${arg} STREQUAL "AUTHOR")
+ set(_state "author")
+ elseif (${arg} STREQUAL "USE")
+ set(_state "use")
+ elseif (${arg} STREQUAL "VERSION")
+ set(_state "version")
+ else ()
+ set(_javadoc_version ${arg})
+ endif ()
+ endif ()
+ endforeach ()
+
+ set(_javadoc_builddir ${CMAKE_CURRENT_BINARY_DIR}/javadoc/${_target})
+ set(_javadoc_options -d ${_javadoc_builddir})
+
+ if (_javadoc_sourcepath)
+ set(_start TRUE)
+ foreach(_path ${_javadoc_sourcepath})
+ if (_start)
+ set(_sourcepath ${_path})
+ set(_start FALSE)
+ else ()
+ set(_sourcepath ${_sourcepath}:${_path})
+ endif ()
+ endforeach()
+ set(_javadoc_options ${_javadoc_options} -sourcepath ${_sourcepath})
+ endif ()
+
+ if (_javadoc_classpath)
+ set(_start TRUE)
+ foreach(_path ${_javadoc_classpath})
+ if (_start)
+ set(_classpath ${_path})
+ set(_start FALSE)
+ else ()
+ set(_classpath ${_classpath}:${_path})
+ endif ()
+ endforeach()
+ set(_javadoc_options ${_javadoc_options} -classpath "${_classpath}")
+ endif ()
+
+ if (_javadoc_doctitle)
+ set(_javadoc_options ${_javadoc_options} -doctitle '${_javadoc_doctitle}')
+ endif ()
+
+ if (_javadoc_windowtitle)
+ set(_javadoc_options ${_javadoc_options} -windowtitle '${_javadoc_windowtitle}')
+ endif ()
+
+ if (_javadoc_author)
+ set(_javadoc_options ${_javadoc_options} -author)
+ endif ()
+
+ if (_javadoc_use)
+ set(_javadoc_options ${_javadoc_options} -use)
+ endif ()
+
+ if (_javadoc_version)
+ set(_javadoc_options ${_javadoc_options} -version)
+ endif ()
+
+ add_custom_target(${_target}_javadoc ALL
+ COMMAND ${Java_JAVADOC_EXECUTABLE} ${_javadoc_options}
+ ${_javadoc_files}
+ ${_javadoc_packages}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+
+ install(
+ DIRECTORY ${_javadoc_builddir}
+ DESTINATION ${_javadoc_installpath}
+ )
+endfunction()
diff --git a/Modules/UseJavaClassFilelist.cmake b/Modules/UseJavaClassFilelist.cmake
new file mode 100644
index 0000000000..e8e6f014cf
--- /dev/null
+++ b/Modules/UseJavaClassFilelist.cmake
@@ -0,0 +1,58 @@
+#.rst:
+# UseJavaClassFilelist
+# --------------------
+#
+#
+#
+#
+#
+# This script create a list of compiled Java class files to be added to
+# a jar file. This avoids including cmake files which get created in
+# the binary directory.
+
+#=============================================================================
+# Copyright 2010-2011 Andreas schneider <asn@redhat.com>
+#
+# 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.)
+
+if (CMAKE_JAVA_CLASS_OUTPUT_PATH)
+ if (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}")
+
+ set(_JAVA_GLOBBED_FILES)
+ if (CMAKE_JAR_CLASSES_PREFIX)
+ foreach(JAR_CLASS_PREFIX ${CMAKE_JAR_CLASSES_PREFIX})
+ message(STATUS "JAR_CLASS_PREFIX: ${JAR_CLASS_PREFIX}")
+
+ file(GLOB_RECURSE _JAVA_GLOBBED_TMP_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${JAR_CLASS_PREFIX}/*.class")
+ if (_JAVA_GLOBBED_TMP_FILES)
+ list(APPEND _JAVA_GLOBBED_FILES ${_JAVA_GLOBBED_TMP_FILES})
+ endif ()
+ endforeach()
+ else()
+ file(GLOB_RECURSE _JAVA_GLOBBED_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/*.class")
+ endif ()
+
+ set(_JAVA_CLASS_FILES)
+ # file(GLOB_RECURSE foo RELATIVE) is broken so we need this.
+ foreach(_JAVA_GLOBBED_FILE ${_JAVA_GLOBBED_FILES})
+ file(RELATIVE_PATH _JAVA_CLASS_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH} ${_JAVA_GLOBBED_FILE})
+ set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES}${_JAVA_CLASS_FILE}\n)
+ endforeach()
+
+ # write to file
+ file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist ${_JAVA_CLASS_FILES})
+
+ else ()
+ message(SEND_ERROR "FATAL: Java class output path doesn't exist")
+ endif ()
+else ()
+ message(SEND_ERROR "FATAL: Can't find CMAKE_JAVA_CLASS_OUTPUT_PATH")
+endif ()
diff --git a/Modules/UseJavaSymlinks.cmake b/Modules/UseJavaSymlinks.cmake
new file mode 100644
index 0000000000..90ffdd5357
--- /dev/null
+++ b/Modules/UseJavaSymlinks.cmake
@@ -0,0 +1,38 @@
+#.rst:
+# UseJavaSymlinks
+# ---------------
+#
+#
+#
+#
+#
+# Helper script for UseJava.cmake
+
+#=============================================================================
+# Copyright 2010-2011 Andreas schneider <asn@redhat.com>
+#
+# 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.)
+
+if (UNIX AND _JAVA_TARGET_OUTPUT_LINK)
+ if (_JAVA_TARGET_OUTPUT_NAME)
+ find_program(LN_EXECUTABLE
+ NAMES
+ ln
+ )
+
+ execute_process(
+ COMMAND ${LN_EXECUTABLE} -sf "${_JAVA_TARGET_OUTPUT_NAME}" "${_JAVA_TARGET_OUTPUT_LINK}"
+ WORKING_DIRECTORY ${_JAVA_TARGET_DIR}
+ )
+ else ()
+ message(SEND_ERROR "FATAL: Can't find _JAVA_TARGET_OUTPUT_NAME")
+ endif ()
+endif ()
diff --git a/Modules/UsePkgConfig.cmake b/Modules/UsePkgConfig.cmake
new file mode 100644
index 0000000000..6a38502ca6
--- /dev/null
+++ b/Modules/UsePkgConfig.cmake
@@ -0,0 +1,84 @@
+#.rst:
+# UsePkgConfig
+# ------------
+#
+# Obsolete pkg-config module for CMake, use FindPkgConfig instead.
+#
+#
+#
+# This module defines the following macro:
+#
+# PKGCONFIG(package includedir libdir linkflags cflags)
+#
+# Calling PKGCONFIG will fill the desired information into the 4 given
+# arguments, e.g. PKGCONFIG(libart-2.0 LIBART_INCLUDE_DIR
+# LIBART_LINK_DIR LIBART_LINK_FLAGS LIBART_CFLAGS) if pkg-config was NOT
+# found or the specified software package doesn't exist, the variable
+# will be empty when the function returns, otherwise they will contain
+# the respective information
+
+#=============================================================================
+# Copyright 2006-2009 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.)
+
+find_program(PKGCONFIG_EXECUTABLE NAMES pkg-config )
+
+macro(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
+ message(STATUS
+ "WARNING: you are using the obsolete 'PKGCONFIG' macro, use FindPkgConfig")
+# reset the variables at the beginning
+ set(${_include_DIR})
+ set(${_link_DIR})
+ set(${_link_FLAGS})
+ set(${_cflags})
+
+ # if pkg-config has been found
+ if(PKGCONFIG_EXECUTABLE)
+
+ exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
+
+ # and if the package of interest also exists for pkg-config, then get the information
+ if(NOT _return_VALUE)
+
+ exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir
+ OUTPUT_VARIABLE ${_include_DIR} )
+ string(REGEX REPLACE "[\r\n]" " " ${_include_DIR} "${${_include_DIR}}")
+
+
+ exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir
+ OUTPUT_VARIABLE ${_link_DIR} )
+ string(REGEX REPLACE "[\r\n]" " " ${_link_DIR} "${${_link_DIR}}")
+
+ exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs
+ OUTPUT_VARIABLE ${_link_FLAGS} )
+ string(REGEX REPLACE "[\r\n]" " " ${_link_FLAGS} "${${_link_FLAGS}}")
+
+ exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags
+ OUTPUT_VARIABLE ${_cflags} )
+ string(REGEX REPLACE "[\r\n]" " " ${_cflags} "${${_cflags}}")
+
+ else()
+
+ message(STATUS "PKGCONFIG() indicates that ${_package} is not installed (install the package which contains ${_package}.pc if you want to support this feature)")
+
+ endif()
+
+ # if pkg-config has NOT been found, INFORM the user
+ else()
+
+ message(STATUS "WARNING: PKGCONFIG() indicates that the tool pkg-config has not been found on your system. You should install it.")
+
+ endif()
+
+endmacro()
+
+mark_as_advanced(PKGCONFIG_EXECUTABLE)
diff --git a/Modules/UseQt4.cmake b/Modules/UseQt4.cmake
new file mode 100644
index 0000000000..cba22af8cd
--- /dev/null
+++ b/Modules/UseQt4.cmake
@@ -0,0 +1,117 @@
+#.rst:
+# UseQt4
+# ------
+#
+# Use Module for QT4
+#
+# Sets up C and C++ to use Qt 4. It is assumed that FindQt.cmake has
+# already been loaded. See FindQt.cmake for information on how to load
+# Qt 4 into your CMake project.
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+add_definitions(${QT_DEFINITIONS})
+set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG>)
+
+if(QT_INCLUDE_DIRS_NO_SYSTEM)
+ include_directories(${QT_INCLUDE_DIR})
+else(QT_INCLUDE_DIRS_NO_SYSTEM)
+ include_directories(SYSTEM ${QT_INCLUDE_DIR})
+endif(QT_INCLUDE_DIRS_NO_SYSTEM)
+
+set(QT_LIBRARIES "")
+set(QT_LIBRARIES_PLUGINS "")
+
+if (QT_USE_QTMAIN)
+ if (Q_WS_WIN)
+ set(QT_LIBRARIES ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY})
+ endif ()
+endif ()
+
+if(QT_DONT_USE_QTGUI)
+ set(QT_USE_QTGUI 0)
+else()
+ set(QT_USE_QTGUI 1)
+endif()
+
+if(QT_DONT_USE_QTCORE)
+ set(QT_USE_QTCORE 0)
+else()
+ set(QT_USE_QTCORE 1)
+endif()
+
+if (QT_USE_QT3SUPPORT)
+ add_definitions(-DQT3_SUPPORT)
+endif ()
+
+# list dependent modules, so dependent libraries are added
+set(QT_QT3SUPPORT_MODULE_DEPENDS QTGUI QTSQL QTXML QTNETWORK QTCORE)
+set(QT_QTSVG_MODULE_DEPENDS QTGUI QTCORE)
+set(QT_QTUITOOLS_MODULE_DEPENDS QTGUI QTXML QTCORE)
+set(QT_QTHELP_MODULE_DEPENDS QTGUI QTSQL QTXML QTNETWORK QTCORE)
+if(QT_QTDBUS_FOUND)
+ set(QT_PHONON_MODULE_DEPENDS QTGUI QTDBUS QTCORE)
+else()
+ set(QT_PHONON_MODULE_DEPENDS QTGUI QTCORE)
+endif()
+set(QT_QTDBUS_MODULE_DEPENDS QTXML QTCORE)
+set(QT_QTXMLPATTERNS_MODULE_DEPENDS QTNETWORK QTCORE)
+set(QT_QAXCONTAINER_MODULE_DEPENDS QTGUI QTCORE)
+set(QT_QAXSERVER_MODULE_DEPENDS QTGUI QTCORE)
+set(QT_QTSCRIPTTOOLS_MODULE_DEPENDS QTGUI QTCORE)
+set(QT_QTWEBKIT_MODULE_DEPENDS QTXMLPATTERNS QTGUI QTCORE)
+set(QT_QTDECLARATIVE_MODULE_DEPENDS QTSCRIPT QTSVG QTSQL QTXMLPATTERNS QTGUI QTCORE)
+set(QT_QTMULTIMEDIA_MODULE_DEPENDS QTGUI QTCORE)
+set(QT_QTOPENGL_MODULE_DEPENDS QTGUI QTCORE)
+set(QT_QTSCRIPT_MODULE_DEPENDS QTCORE)
+set(QT_QTGUI_MODULE_DEPENDS QTCORE)
+set(QT_QTTEST_MODULE_DEPENDS QTCORE)
+set(QT_QTXML_MODULE_DEPENDS QTCORE)
+set(QT_QTSQL_MODULE_DEPENDS QTCORE)
+set(QT_QTNETWORK_MODULE_DEPENDS QTCORE)
+
+# Qt modules (in order of dependence)
+foreach(module QT3SUPPORT QTOPENGL QTASSISTANT QTDESIGNER QTMOTIF QTNSPLUGIN
+ QAXSERVER QAXCONTAINER QTDECLARATIVE QTSCRIPT QTSVG QTUITOOLS QTHELP
+ QTWEBKIT PHONON QTSCRIPTTOOLS QTMULTIMEDIA QTXMLPATTERNS QTGUI QTTEST
+ QTDBUS QTXML QTSQL QTNETWORK QTCORE)
+
+ if (QT_USE_${module} OR QT_USE_${module}_DEPENDS)
+ if (QT_${module}_FOUND)
+ if(QT_USE_${module})
+ string(REPLACE "QT" "" qt_module_def "${module}")
+ add_definitions(-DQT_${qt_module_def}_LIB)
+ if(QT_INCLUDE_DIRS_NO_SYSTEM)
+ include_directories(${QT_${module}_INCLUDE_DIR})
+ else(QT_INCLUDE_DIRS_NO_SYSTEM)
+ include_directories(SYSTEM ${QT_${module}_INCLUDE_DIR})
+ endif(QT_INCLUDE_DIRS_NO_SYSTEM)
+ endif()
+ if(QT_USE_${module} OR QT_IS_STATIC)
+ set(QT_LIBRARIES ${QT_LIBRARIES} ${QT_${module}_LIBRARY})
+ endif()
+ set(QT_LIBRARIES_PLUGINS ${QT_LIBRARIES_PLUGINS} ${QT_${module}_PLUGINS})
+ if(QT_IS_STATIC)
+ set(QT_LIBRARIES ${QT_LIBRARIES} ${QT_${module}_LIB_DEPENDENCIES})
+ endif()
+ foreach(depend_module ${QT_${module}_MODULE_DEPENDS})
+ set(QT_USE_${depend_module}_DEPENDS 1)
+ endforeach()
+ else ()
+ message("Qt ${module} library not found.")
+ endif ()
+ endif ()
+
+endforeach()
+
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake
new file mode 100644
index 0000000000..31ab48d5b7
--- /dev/null
+++ b/Modules/UseSWIG.cmake
@@ -0,0 +1,299 @@
+#.rst:
+# UseSWIG
+# -------
+#
+# Defines the following macros for use with SWIG:
+#
+# ::
+#
+# SWIG_ADD_MODULE(name language [ files ])
+# - Define swig module with given name and specified language
+# SWIG_LINK_LIBRARIES(name [ libraries ])
+# - Link libraries to swig module
+#
+# Source files properties on module files can be set before the invocation
+# of the SWIG_ADD_MODULE macro to specify special behavior of SWIG.
+#
+# The source file property CPLUSPLUS calls SWIG in c++ mode, e.g.::
+#
+# set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON)
+# swig_add_module(mymod python mymod.i)
+#
+# The source file property SWIG_FLAGS adds custom flags to the SWIG executable.
+#
+# The source-file property SWIG_MODULE_NAME have to be provided to specify the actual
+# import name of the module in the target language if it cannot be scanned automatically
+# from source or different from the module file basename.::
+#
+# set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname)
+#
+# To get the name of the swig module target library, use: ${SWIG_MODULE_${name}_REAL_NAME}.
+#
+# Also some variables can be set to specify special behavior of SWIG.
+#
+# CMAKE_SWIG_FLAGS can be used to add special flags to all swig calls.
+#
+# Another special variable is CMAKE_SWIG_OUTDIR, it allows one to specify
+# where to write all the swig generated module (swig -outdir option)
+#
+# The name-specific variable SWIG_MODULE_<name>_EXTRA_DEPS may be used to specify extra
+# dependencies for the generated modules.
+#
+# If the source file generated by swig need some special flag you can use::
+#
+# set_source_files_properties( ${swig_generated_file_fullname}
+# PROPERTIES COMPILE_FLAGS "-bla")
+
+#=============================================================================
+# Copyright 2004-2009 Kitware, Inc.
+# Copyright 2009 Mathieu Malaterre <mathieu.malaterre@gmail.com>
+#
+# 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.)
+
+set(SWIG_CXX_EXTENSION "cxx")
+set(SWIG_EXTRA_LIBRARIES "")
+
+set(SWIG_PYTHON_EXTRA_FILE_EXTENSION "py")
+
+#
+# For given swig module initialize variables associated with it
+#
+macro(SWIG_MODULE_INITIALIZE name language)
+ string(TOUPPER "${language}" swig_uppercase_language)
+ string(TOLOWER "${language}" swig_lowercase_language)
+ set(SWIG_MODULE_${name}_LANGUAGE "${swig_uppercase_language}")
+ set(SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG "${swig_lowercase_language}")
+
+ set(SWIG_MODULE_${name}_REAL_NAME "${name}")
+ if (";${CMAKE_SWIG_FLAGS};" MATCHES ";-noproxy;")
+ set (SWIG_MODULE_${name}_NOPROXY TRUE)
+ endif ()
+ if("${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "UNKNOWN")
+ message(FATAL_ERROR "SWIG Error: Language \"${language}\" not found")
+ elseif("${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "PYTHON" AND NOT SWIG_MODULE_${name}_NOPROXY)
+ # swig will produce a module.py containing an 'import _modulename' statement,
+ # which implies having a corresponding _modulename.so (*NIX), _modulename.pyd (Win32),
+ # unless the -noproxy flag is used
+ set(SWIG_MODULE_${name}_REAL_NAME "_${name}")
+ elseif("${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "PERL")
+ set(SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow")
+ elseif("${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "CSHARP")
+ # This makes sure that the name used in the generated DllImport
+ # matches the library name created by CMake
+ set(SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport;${name}")
+ endif()
+endmacro()
+
+#
+# For a given language, input file, and output file, determine extra files that
+# will be generated. This is internal swig macro.
+#
+
+macro(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
+ set(${outfiles} "")
+ get_source_file_property(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename
+ ${infile} SWIG_MODULE_NAME)
+ if(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename STREQUAL "NOTFOUND")
+
+ # try to get module name from "%module foo" syntax
+ if ( EXISTS ${infile} )
+ file ( STRINGS ${infile} _MODULE_NAME REGEX "[ ]*%module[ ]*[a-zA-Z0-9_]+.*" )
+ endif ()
+ if ( _MODULE_NAME )
+ string ( REGEX REPLACE "[ ]*%module[ ]*([a-zA-Z0-9_]+).*" "\\1" _MODULE_NAME "${_MODULE_NAME}" )
+ set(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename "${_MODULE_NAME}")
+
+ else ()
+ # try to get module name from "%module (options=...) foo" syntax
+ if ( EXISTS ${infile} )
+ file ( STRINGS ${infile} _MODULE_NAME REGEX "[ ]*%module[ ]*\\(.*\\)[ ]*[a-zA-Z0-9_]+.*" )
+ endif ()
+ if ( _MODULE_NAME )
+ string ( REGEX REPLACE "[ ]*%module[ ]*\\(.*\\)[ ]*([a-zA-Z0-9_]+).*" "\\1" _MODULE_NAME "${_MODULE_NAME}" )
+ set(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename "${_MODULE_NAME}")
+
+ else ()
+ # fallback to file basename
+ get_filename_component(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename ${infile} NAME_WE)
+ endif ()
+ endif ()
+
+ endif()
+ foreach(it ${SWIG_${language}_EXTRA_FILE_EXTENSION})
+ set(${outfiles} ${${outfiles}}
+ "${generatedpath}/${SWIG_GET_EXTRA_OUTPUT_FILES_module_basename}.${it}")
+ endforeach()
+endmacro()
+
+#
+# Take swig (*.i) file and add proper custom commands for it
+#
+macro(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
+ set(swig_full_infile ${infile})
+ get_filename_component(swig_source_file_name_we "${infile}" NAME_WE)
+ get_source_file_property(swig_source_file_generated ${infile} GENERATED)
+ get_source_file_property(swig_source_file_cplusplus ${infile} CPLUSPLUS)
+ get_source_file_property(swig_source_file_flags ${infile} SWIG_FLAGS)
+ if("${swig_source_file_flags}" STREQUAL "NOTFOUND")
+ set(swig_source_file_flags "")
+ endif()
+ get_filename_component(swig_source_file_fullname "${infile}" ABSOLUTE)
+
+ # If CMAKE_SWIG_OUTDIR was specified then pass it to -outdir
+ if(CMAKE_SWIG_OUTDIR)
+ set(swig_outdir ${CMAKE_SWIG_OUTDIR})
+ else()
+ set(swig_outdir ${CMAKE_CURRENT_BINARY_DIR})
+ endif()
+ SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE}
+ swig_extra_generated_files
+ "${swig_outdir}"
+ "${infile}")
+ set(swig_generated_file_fullname
+ "${swig_outdir}/${swig_source_file_name_we}")
+ # add the language into the name of the file (i.e. TCL_wrap)
+ # this allows for the same .i file to be wrapped into different languages
+ set(swig_generated_file_fullname
+ "${swig_generated_file_fullname}${SWIG_MODULE_${name}_LANGUAGE}_wrap")
+
+ if(swig_source_file_cplusplus)
+ set(swig_generated_file_fullname
+ "${swig_generated_file_fullname}.${SWIG_CXX_EXTENSION}")
+ else()
+ set(swig_generated_file_fullname
+ "${swig_generated_file_fullname}.c")
+ endif()
+
+ #message("Full path to source file: ${swig_source_file_fullname}")
+ #message("Full path to the output file: ${swig_generated_file_fullname}")
+ get_directory_property(cmake_include_directories INCLUDE_DIRECTORIES)
+ list(REMOVE_DUPLICATES cmake_include_directories)
+ set(swig_include_dirs)
+ foreach(it ${cmake_include_directories})
+ set(swig_include_dirs ${swig_include_dirs} "-I${it}")
+ endforeach()
+
+ set(swig_special_flags)
+ # default is c, so add c++ flag if it is c++
+ if(swig_source_file_cplusplus)
+ set(swig_special_flags ${swig_special_flags} "-c++")
+ endif()
+ set(swig_extra_flags)
+ if(SWIG_MODULE_${name}_EXTRA_FLAGS)
+ set(swig_extra_flags ${swig_extra_flags} ${SWIG_MODULE_${name}_EXTRA_FLAGS})
+ endif()
+ add_custom_command(
+ OUTPUT "${swig_generated_file_fullname}" ${swig_extra_generated_files}
+ # Let's create the ${swig_outdir} at execution time, in case dir contains $(OutDir)
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${swig_outdir}
+ COMMAND "${SWIG_EXECUTABLE}"
+ ARGS "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
+ ${swig_source_file_flags}
+ ${CMAKE_SWIG_FLAGS}
+ -outdir ${swig_outdir}
+ ${swig_special_flags}
+ ${swig_extra_flags}
+ ${swig_include_dirs}
+ -o "${swig_generated_file_fullname}"
+ "${swig_source_file_fullname}"
+ MAIN_DEPENDENCY "${swig_source_file_fullname}"
+ DEPENDS ${SWIG_MODULE_${name}_EXTRA_DEPS}
+ COMMENT "Swig source")
+ set_source_files_properties("${swig_generated_file_fullname}" ${swig_extra_generated_files}
+ PROPERTIES GENERATED 1)
+ set(${outfiles} "${swig_generated_file_fullname}" ${swig_extra_generated_files})
+endmacro()
+
+#
+# Create Swig module
+#
+macro(SWIG_ADD_MODULE name language)
+ SWIG_MODULE_INITIALIZE(${name} ${language})
+ set(swig_dot_i_sources)
+ set(swig_other_sources)
+ foreach(it ${ARGN})
+ if(${it} MATCHES "\\.i$")
+ set(swig_dot_i_sources ${swig_dot_i_sources} "${it}")
+ else()
+ set(swig_other_sources ${swig_other_sources} "${it}")
+ endif()
+ endforeach()
+
+ set(swig_generated_sources)
+ foreach(it ${swig_dot_i_sources})
+ SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source ${it})
+ set(swig_generated_sources ${swig_generated_sources} "${swig_generated_source}")
+ endforeach()
+ get_directory_property(swig_extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
+ set_directory_properties(PROPERTIES
+ ADDITIONAL_MAKE_CLEAN_FILES "${swig_extra_clean_files};${swig_generated_sources}")
+ add_library(${SWIG_MODULE_${name}_REAL_NAME}
+ MODULE
+ ${swig_generated_sources}
+ ${swig_other_sources})
+ set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES NO_SONAME ON)
+ string(TOLOWER "${language}" swig_lowercase_language)
+ if ("${swig_lowercase_language}" STREQUAL "octave")
+ set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
+ set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".oct")
+ elseif ("${swig_lowercase_language}" STREQUAL "go")
+ set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
+ elseif ("${swig_lowercase_language}" STREQUAL "java")
+ if (APPLE)
+ # In java you want:
+ # System.loadLibrary("LIBRARY");
+ # then JNI will look for a library whose name is platform dependent, namely
+ # MacOS : libLIBRARY.jnilib
+ # Windows: LIBRARY.dll
+ # Linux : libLIBRARY.so
+ set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".jnilib")
+ endif ()
+ elseif ("${swig_lowercase_language}" STREQUAL "lua")
+ set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
+ elseif ("${swig_lowercase_language}" STREQUAL "python")
+ # this is only needed for the python case where a _modulename.so is generated
+ set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
+ # Python extension modules on Windows must have the extension ".pyd"
+ # instead of ".dll" as of Python 2.5. Older python versions do support
+ # this suffix.
+ # http://docs.python.org/whatsnew/ports.html#SECTION0001510000000000000000
+ # <quote>
+ # Windows: .dll is no longer supported as a filename extension for extension modules.
+ # .pyd is now the only filename extension that will be searched for.
+ # </quote>
+ if(WIN32 AND NOT CYGWIN)
+ set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".pyd")
+ endif()
+ elseif ("${swig_lowercase_language}" STREQUAL "ruby")
+ # In ruby you want:
+ # require 'LIBRARY'
+ # then ruby will look for a library whose name is platform dependent, namely
+ # MacOS : LIBRARY.bundle
+ # Windows: LIBRARY.dll
+ # Linux : LIBRARY.so
+ set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
+ if (APPLE)
+ set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".bundle")
+ endif ()
+ endif ()
+endmacro()
+
+#
+# Like TARGET_LINK_LIBRARIES but for swig modules
+#
+macro(SWIG_LINK_LIBRARIES name)
+ if(SWIG_MODULE_${name}_REAL_NAME)
+ target_link_libraries(${SWIG_MODULE_${name}_REAL_NAME} ${ARGN})
+ else()
+ message(SEND_ERROR "Cannot find Swig library \"${name}\".")
+ endif()
+endmacro()
+
diff --git a/Modules/UseVTK40.cmake b/Modules/UseVTK40.cmake
new file mode 100644
index 0000000000..d6bdaaa52b
--- /dev/null
+++ b/Modules/UseVTK40.cmake
@@ -0,0 +1,29 @@
+#
+
+#=============================================================================
+# Copyright 2002-2009 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 is an implementation detail for using VTK 4.0 with the
+# FindVTK.cmake module. Do not include directly by name. This should
+# be included only when FindVTK.cmake sets the VTK_USE_FILE variable
+# to point here.
+
+# Add compiler flags needed to use VTK.
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VTK_REQUIRED_C_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VTK_REQUIRED_CXX_FLAGS}")
+
+# Add include directories needed to use VTK.
+include_directories(${VTK_INCLUDE_DIRS})
+
+# Add link directories needed to use VTK.
+link_directories(${VTK_LIBRARY_DIRS})
diff --git a/Modules/UseVTKBuildSettings40.cmake b/Modules/UseVTKBuildSettings40.cmake
new file mode 100644
index 0000000000..474f67c9c3
--- /dev/null
+++ b/Modules/UseVTKBuildSettings40.cmake
@@ -0,0 +1,38 @@
+#
+
+#=============================================================================
+# Copyright 2002-2009 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.)
+
+# Implementation detail for FindVTK.cmake to let it provide a
+# VTK_BUILD_SETTINGS_FILE for VTK 4.0.
+
+set(CMAKE_BUILD_SETTING_CMAKE_MAJOR_VERSION "${VTK40_CMAKE_MAJOR_VERSION}")
+set(CMAKE_BUILD_SETTING_CMAKE_MINOR_VERSION "${VTK40_CMAKE_MINOR_VERSION}")
+set(CMAKE_BUILD_SETTING_PROJECT_NAME "VTK")
+
+set(CMAKE_BUILD_SETTING_C_COMPILER "${VTK40_CMAKE_C_COMPILER}")
+set(CMAKE_BUILD_SETTING_C_FLAGS "${VTK40_CMAKE_C_FLAGS}")
+set(CMAKE_BUILD_SETTING_C_FLAGS_DEBUG "${VTK40_CMAKE_C_FLAGS_DEBUG}")
+set(CMAKE_BUILD_SETTING_C_FLAGS_RELEASE "${VTK40_CMAKE_C_FLAGS_RELEASE}")
+set(CMAKE_BUILD_SETTING_C_FLAGS_MINSIZEREL "${VTK40_CMAKE_C_FLAGS_MINSIZEREL}")
+set(CMAKE_BUILD_SETTING_C_FLAGS_RELWITHDEBINFO "${VTK40_CMAKE_C_FLAGS_RELWITHDEBINFO}")
+
+set(CMAKE_BUILD_SETTING_CXX_COMPILER "${VTK40_CMAKE_CXX_COMPILER}")
+set(CMAKE_BUILD_SETTING_CXX_FLAGS "${VTK40_CMAKE_CXX_FLAGS}")
+set(CMAKE_BUILD_SETTING_CXX_FLAGS_DEBUG "${VTK40_CMAKE_CXX_FLAGS_DEBUG}")
+set(CMAKE_BUILD_SETTING_CXX_FLAGS_RELEASE "${VTK40_CMAKE_CXX_FLAGS_RELEASE}")
+set(CMAKE_BUILD_SETTING_CXX_FLAGS_MINSIZEREL "${VTK40_CMAKE_CXX_FLAGS_MINSIZEREL}")
+set(CMAKE_BUILD_SETTING_CXX_FLAGS_RELWITHDEBINFO "${VTK40_CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
+
+set(CMAKE_BUILD_SETTING_BUILD_TYPE "${VTK40_CMAKE_BUILD_TYPE}")
+set(CMAKE_BUILD_SETTING_BUILD_TOOL "${VTK40_CMAKE_BUILD_TOOL}")
diff --git a/Modules/UseVTKConfig40.cmake b/Modules/UseVTKConfig40.cmake
new file mode 100644
index 0000000000..c5022e4f82
--- /dev/null
+++ b/Modules/UseVTKConfig40.cmake
@@ -0,0 +1,409 @@
+#
+
+#=============================================================================
+# Copyright 2002-2009 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 is an implementation detail for using VTK 4.0 with the
+# FindVTK.cmake module. Do not include directly.
+
+# Hard-code the version number since it isn't provided by VTK 4.0.
+set(VTK_MAJOR_VERSION 4)
+set(VTK_MINOR_VERSION 0)
+set(VTK_BUILD_VERSION 2)
+
+# Provide a new UseVTK file that doesn't do a full LOAD_CACHE.
+set(VTK_USE_FILE ${CMAKE_ROOT}/Modules/UseVTK40.cmake)
+
+# Provide a build settings file.
+set(VTK_BUILD_SETTINGS_FILE ${CMAKE_ROOT}/Modules/UseVTKBuildSettings40.cmake)
+
+# There are no CMake extensions for VTK 4.0.
+set(VTK_CMAKE_EXTENSIONS_DIR "")
+
+# grep "VTK40_" UseVTKConfig40.cmake |sed 's/.*VTK40_\([A-Za-z0-9_]*\).*/ \1/'
+load_cache(${VTK_DIR} READ_WITH_PREFIX VTK40_
+ BUILD_SHARED_LIBS
+ CMAKE_BUILD_TOOL
+ CMAKE_BUILD_TYPE
+ CMAKE_CACHE_MAJOR_VERSION
+ CMAKE_CACHE_MINOR_VERSION
+ CMAKE_CXX_COMPILER
+ CMAKE_CXX_FLAGS
+ CMAKE_CXX_FLAGS_DEBUG
+ CMAKE_CXX_FLAGS_MINSIZEREL
+ CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_RELWITHDEBINFO
+ CMAKE_C_COMPILER
+ CMAKE_C_FLAGS
+ CMAKE_C_FLAGS_DEBUG
+ CMAKE_C_FLAGS_MINSIZEREL
+ CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_INSTALL_PREFIX
+ CMAKE_Xutil_INCLUDE_PATH
+ EXECUTABLE_OUTPUT_PATH
+ JAVA_INCLUDE_PATH2
+ LIBRARY_OUTPUT_PATH
+ MPIRUN
+ MPI_INCLUDE_PATH
+ MPI_POSTFLAGS
+ MPI_PREFLAGS
+ OPENGL_INCLUDE_DIR
+ OSMESA_INCLUDE_PATH
+ PYTHON_INCLUDE_PATH
+ TCL_INCLUDE_PATH
+ VLI_INCLUDE_PATH_FOR_VG500
+ VLI_INCLUDE_PATH_FOR_VP1000
+ VTK_BINARY_DIR
+ VTK_DEBUG_LEAKS
+ VTK_HAVE_VG500
+ VTK_HAVE_VP1000
+ VTK_MANGLE_MESA
+ VTK_OPENGL_HAS_OSMESA
+ VTK_PARSE_JAVA_EXE
+ VTK_SOURCE_DIR
+ VTK_USE_64BIT_IDS
+ VTK_USE_ANSI_STDLIB
+ VTK_USE_HYBRID
+ VTK_USE_MATROX_IMAGING
+ VTK_USE_MPI
+ VTK_USE_PARALLEL
+ VTK_USE_PATENTED
+ VTK_USE_RENDERING
+ VTK_USE_VIDEO_FOR_WINDOWS
+ VTK_USE_VOLUMEPRO
+ VTK_USE_X
+ VTK_WRAP_JAVA
+ VTK_WRAP_JAVA_EXE
+ VTK_WRAP_PYTHON
+ VTK_WRAP_PYTHON_EXE
+ VTK_WRAP_TCL
+ VTK_WRAP_TCL_EXE
+ vtkCommonJava_LIB_DEPENDS
+ vtkCommonPython_LIB_DEPENDS
+ vtkCommonTCL_LIB_DEPENDS
+ vtkCommon_LIB_DEPENDS
+ vtkFilteringJava_LIB_DEPENDS
+ vtkFilteringPython_LIB_DEPENDS
+ vtkFilteringTCL_LIB_DEPENDS
+ vtkFiltering_LIB_DEPENDS
+ vtkGraphicsJava_LIB_DEPENDS
+ vtkGraphicsPython_LIB_DEPENDS
+ vtkGraphicsTCL_LIB_DEPENDS
+ vtkGraphics_LIB_DEPENDS
+ vtkHybridJava_LIB_DEPENDS
+ vtkHybridPython_LIB_DEPENDS
+ vtkHybridTCL_LIB_DEPENDS
+ vtkHybrid_LIB_DEPENDS
+ vtkIOJava_LIB_DEPENDS
+ vtkIOPython_LIB_DEPENDS
+ vtkIOTCL_LIB_DEPENDS
+ vtkIO_LIB_DEPENDS
+ vtkImagingJava_LIB_DEPENDS
+ vtkImagingPython_LIB_DEPENDS
+ vtkImagingTCL_LIB_DEPENDS
+ vtkImaging_LIB_DEPENDS
+ vtkParallelJava_LIB_DEPENDS
+ vtkParallelPython_LIB_DEPENDS
+ vtkParallelTCL_LIB_DEPENDS
+ vtkParallel_LIB_DEPENDS
+ vtkPatentedJava_LIB_DEPENDS
+ vtkPatentedPython_LIB_DEPENDS
+ vtkPatentedTCL_LIB_DEPENDS
+ vtkPatented_LIB_DEPENDS
+ vtkRenderingJava_LIB_DEPENDS
+ vtkRenderingPythonTkWidgets_LIB_DEPENDS
+ vtkRenderingPython_LIB_DEPENDS
+ vtkRenderingTCL_LIB_DEPENDS
+ vtkRendering_LIB_DEPENDS
+ vtkjpeg_LIB_DEPENDS
+ vtkpng_LIB_DEPENDS
+ vtkzlib_LIB_DEPENDS
+)
+
+# Copy needed settings from the VTK 4.0 cache.
+set(VTK_BUILD_SHARED ${VTK40_BUILD_SHARED_LIBS})
+set(VTK_DEBUG_LEAKS ${VTK40_VTK_DEBUG_LEAKS})
+set(VTK_HAVE_VG500 ${VTK40_VTK_HAVE_VG500})
+set(VTK_HAVE_VP1000 ${VTK40_VTK_HAVE_VP1000})
+set(VTK_USE_MANGLED_MESA ${VTK40_VTK_MANGLE_MESA})
+set(VTK_MPIRUN_EXE ${VTK40_MPIRUN})
+set(VTK_MPI_POSTFLAGS ${VTK40_MPI_POSTFLAGS})
+set(VTK_MPI_PREFLAGS ${VTK40_MPI_PREFLAGS})
+set(VTK_OPENGL_HAS_OSMESA ${VTK40_VTK_OPENGL_HAS_OSMESA})
+set(VTK_USE_64BIT_IDS ${VTK40_VTK_USE_64BIT_IDS})
+set(VTK_USE_ANSI_STDLIB ${VTK40_VTK_USE_ANSI_STDLIB})
+set(VTK_USE_HYBRID ${VTK40_VTK_USE_HYBRID})
+set(VTK_USE_MATROX_IMAGING ${VTK40_VTK_USE_MATROX_IMAGING})
+set(VTK_USE_MPI ${VTK40_VTK_USE_MPI})
+set(VTK_USE_PARALLEL ${VTK40_VTK_USE_PARALLEL})
+set(VTK_USE_PATENTED ${VTK40_VTK_USE_PATENTED})
+set(VTK_USE_RENDERING ${VTK40_VTK_USE_RENDERING})
+set(VTK_USE_VIDEO_FOR_WINDOWS ${VTK40_VTK_USE_VIDEO_FOR_WINDOWS})
+set(VTK_USE_VOLUMEPRO ${VTK40_VTK_USE_VOLUMEPRO})
+set(VTK_USE_X ${VTK40_VTK_USE_X})
+set(VTK_WRAP_JAVA ${VTK40_VTK_WRAP_JAVA})
+set(VTK_WRAP_PYTHON ${VTK40_VTK_WRAP_PYTHON})
+set(VTK_WRAP_TCL ${VTK40_VTK_WRAP_TCL})
+
+# Create the list of available kits.
+set(VTK_KITS COMMON FILTERING GRAPHICS IMAGING IO)
+if(VTK_USE_RENDERING)
+ set(VTK_KITS ${VTK_KITS} RENDERING)
+endif()
+if(VTK_USE_HYBRID)
+ set(VTK_KITS ${VTK_KITS} HYBRID)
+endif()
+if(VTK_USE_PARALLEL)
+ set(VTK_KITS ${VTK_KITS} PARALLEL)
+endif()
+if(VTK_USE_PATENTED)
+ set(VTK_KITS ${VTK_KITS} PATENTED)
+endif()
+
+# Create the list of available languages.
+set(VTK_LANGUAGES "")
+if(VTK_WRAP_TCL)
+ set(VTK_LANGUAGES ${VTK_LANGUAGES} TCL)
+endif()
+if(VTK_WRAP_PYTHON)
+ set(VTK_LANGUAGES ${VTK_LANGUAGES} PYTHON)
+endif()
+if(VTK_WRAP_JAVA)
+ set(VTK_LANGUAGES ${VTK_LANGUAGES} JAVA)
+endif()
+
+# Include directories for other projects installed on the system and
+# used by VTK.
+set(VTK_INCLUDE_DIRS_SYS "")
+if(VTK_USE_RENDERING)
+ set(VTK_INCLUDE_DIRS_SYS ${VTK_INCLUDE_DIRS_SYS}
+ ${VTK40_OPENGL_INCLUDE_PATH} ${VTK40_OPENGL_INCLUDE_DIR})
+ if(VTK_USE_X)
+ set(VTK_INCLUDE_DIRS_SYS ${VTK_INCLUDE_DIRS_SYS}
+ ${VTK40_CMAKE_Xlib_INCLUDE_PATH} ${VTK40_CMAKE_Xutil_INCLUDE_PATH})
+ endif()
+endif()
+
+if(VTK_OPENGL_HAS_OSMESA)
+ set(VTK_INCLUDE_DIRS_SYS ${VTK_INCLUDE_DIRS_SYS}
+ ${VTK40_OSMESA_INCLUDE_PATH})
+endif()
+
+if(VTK_USE_MPI)
+ set(VTK_INCLUDE_DIRS_SYS ${VTK_INCLUDE_DIRS_SYS} ${VTK40_MPI_INCLUDE_PATH})
+endif()
+
+if(VTK_WRAP_TCL)
+ set(VTK_INCLUDE_DIRS_SYS ${VTK_INCLUDE_DIRS_SYS} ${VTK40_TCL_INCLUDE_PATH})
+endif()
+
+if(VTK_WRAP_PYTHON)
+ set(VTK_INCLUDE_DIRS_SYS ${VTK_INCLUDE_DIRS_SYS} ${VTK40_PYTHON_INCLUDE_PATH})
+endif()
+
+if(VTK_WRAP_JAVA)
+ set(VTK_INCLUDE_DIRS_SYS ${VTK_INCLUDE_DIRS_SYS}
+ ${VTK40_JAVA_INCLUDE_PATH} ${VTK40_JAVA_INCLUDE_PATH2})
+endif()
+
+if(VTK_HAVE_VG500)
+ set(VTK_INCLUDE_DIRS_SYS ${VTK_INCLUDE_DIRS_SYS}
+ ${VTK40_VLI_INCLUDE_PATH_FOR_VG500})
+endif()
+
+if(VTK_HAVE_VP1000)
+ set(VTK_INCLUDE_DIRS_SYS ${VTK_INCLUDE_DIRS_SYS}
+ ${VTK40_VLI_INCLUDE_PATH_FOR_VP1000})
+endif()
+
+# See if this is a build tree or install tree.
+if(EXISTS ${VTK_DIR}/Common)
+ # This is a VTK 4.0 build tree.
+
+ set(VTK_LIBRARY_DIRS ${VTK40_LIBRARY_OUTPUT_PATH})
+
+ # Determine the include directories needed.
+ set(VTK_INCLUDE_DIRS ${VTK40_VTK_BINARY_DIR})
+ if(VTK_USE_PARALLEL)
+ set(VTK_INCLUDE_DIRS ${VTK_INCLUDE_DIRS} ${VTK40_VTK_SOURCE_DIR}/Parallel)
+ endif()
+ if(VTK_USE_HYBRID)
+ set(VTK_INCLUDE_DIRS ${VTK_INCLUDE_DIRS} ${VTK40_VTK_SOURCE_DIR}/Hybrid)
+ endif()
+ if(VTK_USE_PATENTED)
+ set(VTK_INCLUDE_DIRS ${VTK_INCLUDE_DIRS} ${VTK40_VTK_SOURCE_DIR}/Patented)
+ endif()
+ if(VTK_USE_RENDERING)
+ set(VTK_INCLUDE_DIRS ${VTK_INCLUDE_DIRS} ${VTK40_VTK_SOURCE_DIR}/Rendering)
+ endif()
+
+ # These directories are always needed.
+ set(VTK_INCLUDE_DIRS ${VTK_INCLUDE_DIRS}
+ ${VTK40_VTK_SOURCE_DIR}/IO
+ ${VTK40_VTK_SOURCE_DIR}/Imaging
+ ${VTK40_VTK_SOURCE_DIR}/Graphics
+ ${VTK40_VTK_SOURCE_DIR}/Filtering
+ ${VTK40_VTK_SOURCE_DIR}/Common)
+
+ # Give access to a few utilities.
+ set(VTK_INCLUDE_DIRS ${VTK_INCLUDE_DIRS}
+ ${VTK40_VTK_BINARY_DIR}/Utilities/png
+ ${VTK40_VTK_SOURCE_DIR}/Utilities/png
+ ${VTK40_VTK_BINARY_DIR}/Utilities/zlib
+ ${VTK40_VTK_SOURCE_DIR}/Utilities/zlib)
+
+ # Executable locations.
+ if(VTK_WRAP_TCL)
+ set(VTK_TCL_EXE ${VTK40_EXECUTABLE_OUTPUT_PATH}/vtk)
+ set(VTK_WRAP_TCL_EXE ${VTK40_VTK_WRAP_TCL_EXE})
+ set(VTK_TCL_HOME ${VTK40_VTK_SOURCE_DIR}/Wrapping/Tcl)
+ endif()
+ if(VTK_WRAP_PYTHON)
+ set(VTK_WRAP_PYTHON_EXE ${VTK40_VTK_WRAP_PYTHON_EXE})
+ endif()
+ if(VTK_WRAP_JAVA)
+ set(VTK_PARSE_JAVA_EXE ${VTK40_VTK_PARSE_JAVA_EXE})
+ set(VTK_WRAP_JAVA_EXE ${VTK40_VTK_WRAP_JAVA_EXE})
+ endif()
+
+else()
+ # This is a VTK 4.0 install tree.
+
+ set(VTK_INCLUDE_DIRS ${VTK_DIR})
+ set(VTK_LIBRARY_DIRS ${VTK40_CMAKE_INSTALL_PREFIX}/lib/vtk)
+
+ # Executable locations.
+ if(VTK_WRAP_TCL)
+ set(VTK_TCL_EXE ${VTK40_CMAKE_INSTALL_PREFIX}/bin/vtk)
+ set(VTK_WRAP_TCL_EXE ${VTK40_CMAKE_INSTALL_PREFIX}/bin/vtkWrapTcl)
+ set(VTK_TCL_HOME ${VTK40_CMAKE_INSTALL_PREFIX}/lib/vtk/tcl)
+ endif()
+ if(VTK_WRAP_PYTHON)
+ set(VTK_WRAP_PYTHON_EXE ${VTK40_CMAKE_INSTALL_PREFIX}/bin/vtkWrapPython)
+ endif()
+ if(VTK_WRAP_JAVA)
+ set(VTK_PARSE_JAVA_EXE ${VTK40_CMAKE_INSTALL_PREFIX}/bin/vtkParseJava)
+ set(VTK_WRAP_JAVA_EXE ${VTK40_CMAKE_INSTALL_PREFIX}/bin/vtkWrapJava)
+ endif()
+endif()
+
+# Add the system include directories last.
+set(VTK_INCLUDE_DIRS ${VTK_INCLUDE_DIRS} ${VTK_INCLUDE_DIRS_SYS})
+
+# Find the required C and C++ compiler flags.
+if(CMAKE_COMPILER_IS_GNUCXX)
+ if(WIN32)
+ # The platform is gcc on cygwin.
+ set(VTK_REQUIRED_CXX_FLAGS "${VTK_REQUIRED_CXX_FLAGS} -mwin32")
+ set(VTK_REQUIRED_C_FLAGS "${VTK_REQUIRED_C_FLAGS} -mwin32")
+ endif()
+else()
+ if(CMAKE_ANSI_CFLAGS)
+ set(VTK_REQUIRED_C_FLAGS "${VTK_REQUIRED_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
+ endif()
+ if(CMAKE_SYSTEM MATCHES "OSF1-V")
+ set(VTK_REQUIRED_CXX_FLAGS
+ "${VTK_REQUIRED_CXX_FLAGS} -timplicit_local -no_implicit_include")
+ endif()
+endif()
+
+if(VTK_USE_X)
+ if(CMAKE_X_CFLAGS)
+ set(VTK_REQUIRED_C_FLAGS "${VTK_REQUIRED_C_FLAGS} ${CMAKE_X_CFLAGS}")
+ set(VTK_REQUIRED_CXX_FLAGS "${VTK_REQUIRED_CXX_FLAGS} ${CMAKE_X_CFLAGS}")
+ endif()
+endif()
+
+# Copy library dependencies.
+set(vtkCommonJava_LIB_DEPENDS "${VTK40_vtkCommonJava_LIB_DEPENDS}")
+set(vtkCommonPython_LIB_DEPENDS "${VTK40_vtkCommonPython_LIB_DEPENDS}")
+set(vtkCommonTCL_LIB_DEPENDS "${VTK40_vtkCommonTCL_LIB_DEPENDS}")
+set(vtkCommon_LIB_DEPENDS "${VTK40_vtkCommon_LIB_DEPENDS}")
+set(vtkFilteringJava_LIB_DEPENDS "${VTK40_vtkFilteringJava_LIB_DEPENDS}")
+set(vtkFilteringPython_LIB_DEPENDS "${VTK40_vtkFilteringPython_LIB_DEPENDS}")
+set(vtkFilteringTCL_LIB_DEPENDS "${VTK40_vtkFilteringTCL_LIB_DEPENDS}")
+set(vtkFiltering_LIB_DEPENDS "${VTK40_vtkFiltering_LIB_DEPENDS}")
+set(vtkGraphicsJava_LIB_DEPENDS "${VTK40_vtkGraphicsJava_LIB_DEPENDS}")
+set(vtkGraphicsPython_LIB_DEPENDS "${VTK40_vtkGraphicsPython_LIB_DEPENDS}")
+set(vtkGraphicsTCL_LIB_DEPENDS "${VTK40_vtkGraphicsTCL_LIB_DEPENDS}")
+set(vtkGraphics_LIB_DEPENDS "${VTK40_vtkGraphics_LIB_DEPENDS}")
+set(vtkHybridJava_LIB_DEPENDS "${VTK40_vtkHybridJava_LIB_DEPENDS}")
+set(vtkHybridPython_LIB_DEPENDS "${VTK40_vtkHybridPython_LIB_DEPENDS}")
+set(vtkHybridTCL_LIB_DEPENDS "${VTK40_vtkHybridTCL_LIB_DEPENDS}")
+set(vtkHybrid_LIB_DEPENDS "${VTK40_vtkHybrid_LIB_DEPENDS}")
+set(vtkIOJava_LIB_DEPENDS "${VTK40_vtkIOJava_LIB_DEPENDS}")
+set(vtkIOPython_LIB_DEPENDS "${VTK40_vtkIOPython_LIB_DEPENDS}")
+set(vtkIOTCL_LIB_DEPENDS "${VTK40_vtkIOTCL_LIB_DEPENDS}")
+set(vtkIO_LIB_DEPENDS "${VTK40_vtkIO_LIB_DEPENDS}")
+set(vtkImagingJava_LIB_DEPENDS "${VTK40_vtkImagingJava_LIB_DEPENDS}")
+set(vtkImagingPython_LIB_DEPENDS "${VTK40_vtkImagingPython_LIB_DEPENDS}")
+set(vtkImagingTCL_LIB_DEPENDS "${VTK40_vtkImagingTCL_LIB_DEPENDS}")
+set(vtkImaging_LIB_DEPENDS "${VTK40_vtkImaging_LIB_DEPENDS}")
+set(vtkParallelJava_LIB_DEPENDS "${VTK40_vtkParallelJava_LIB_DEPENDS}")
+set(vtkParallelPython_LIB_DEPENDS "${VTK40_vtkParallelPython_LIB_DEPENDS}")
+set(vtkParallelTCL_LIB_DEPENDS "${VTK40_vtkParallelTCL_LIB_DEPENDS}")
+set(vtkParallel_LIB_DEPENDS "${VTK40_vtkParallel_LIB_DEPENDS}")
+set(vtkPatentedJava_LIB_DEPENDS "${VTK40_vtkPatentedJava_LIB_DEPENDS}")
+set(vtkPatentedPython_LIB_DEPENDS "${VTK40_vtkPatentedPython_LIB_DEPENDS}")
+set(vtkPatentedTCL_LIB_DEPENDS "${VTK40_vtkPatentedTCL_LIB_DEPENDS}")
+set(vtkPatented_LIB_DEPENDS "${VTK40_vtkPatented_LIB_DEPENDS}")
+set(vtkRenderingJava_LIB_DEPENDS "${VTK40_vtkRenderingJava_LIB_DEPENDS}")
+set(vtkRenderingPythonTkWidgets_LIB_DEPENDS "${VTK40_vtkRenderingPythonTkWidgets_LIB_DEPENDS}")
+set(vtkRenderingPython_LIB_DEPENDS "${VTK40_vtkRenderingPython_LIB_DEPENDS}")
+set(vtkRenderingTCL_LIB_DEPENDS "${VTK40_vtkRenderingTCL_LIB_DEPENDS}")
+set(vtkRendering_LIB_DEPENDS "${VTK40_vtkRendering_LIB_DEPENDS}")
+set(vtkjpeg_LIB_DEPENDS "${VTK40_vtkjpeg_LIB_DEPENDS}")
+set(vtkpng_LIB_DEPENDS "${VTK40_vtkpng_LIB_DEPENDS}")
+set(vtkzlib_LIB_DEPENDS "${VTK40_vtkzlib_LIB_DEPENDS}")
+
+# List of VTK configuration variables set above.
+# grep "^[ ]*set(VTK" UseVTKConfig40.cmake |sed 's/[ ]*set(\([^ ]*\) .*/ \1/'
+set(VTK_SETTINGS
+ VTK_BUILD_SHARED
+ VTK_BUILD_VERSION
+ VTK_DEBUG_LEAKS
+ VTK_HAVE_VG500
+ VTK_HAVE_VP1000
+ VTK_INCLUDE_DIRS
+ VTK_KITS
+ VTK_LANGUAGES
+ VTK_LIBRARY_DIRS
+ VTK_MAJOR_VERSION
+ VTK_MANGLE_MESA
+ VTK_MINOR_VERSION
+ VTK_MPIRUN_EXE
+ VTK_MPI_POSTFLAGS
+ VTK_MPI_PREFLAGS
+ VTK_OPENGL_HAS_OSMESA
+ VTK_PARSE_JAVA_EXE
+ VTK_TCL_EXE
+ VTK_TCL_HOME
+ VTK_USE_64BIT_IDS
+ VTK_USE_ANSI_STDLIB
+ VTK_USE_HYBRID
+ VTK_USE_MATROX_IMAGING
+ VTK_USE_MPI
+ VTK_USE_PARALLEL
+ VTK_USE_PATENTED
+ VTK_USE_RENDERING
+ VTK_USE_VIDEO_FOR_WINDOWS
+ VTK_USE_VOLUMEPRO
+ VTK_USE_X
+ VTK_WRAP_JAVA
+ VTK_WRAP_JAVA_EXE
+ VTK_WRAP_PYTHON
+ VTK_WRAP_PYTHON_EXE
+ VTK_WRAP_TCL
+ VTK_WRAP_TCL_EXE
+)
diff --git a/Modules/Use_wxWindows.cmake b/Modules/Use_wxWindows.cmake
new file mode 100644
index 0000000000..d3025ac12a
--- /dev/null
+++ b/Modules/Use_wxWindows.cmake
@@ -0,0 +1,79 @@
+#.rst:
+# Use_wxWindows
+# -------------
+#
+#
+#
+#
+# This convenience include finds if wxWindows is installed and set the
+# appropriate libs, incdirs, flags etc. author Jan Woetzel <jw -at-
+# mip.informatik.uni-kiel.de> (07/2003)
+#
+# USAGE:
+#
+# ::
+#
+# just include Use_wxWindows.cmake
+# in your projects CMakeLists.txt
+#
+# include( ${CMAKE_MODULE_PATH}/Use_wxWindows.cmake)
+#
+# ::
+#
+# if you are sure you need GL then
+#
+# set(WXWINDOWS_USE_GL 1)
+#
+# ::
+#
+# *before* you include this file.
+
+#=============================================================================
+# Copyright 2003-2009 Kitware, Inc.
+# Copyright 2003 Jan Woetzel
+#
+# 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.)
+
+# -----------------------------------------------------
+# 16.Feb.2004: changed INCLUDE to FIND_PACKAGE to read from users own non-system CMAKE_MODULE_PATH (Jan Woetzel JW)
+# 07/2006: rewrite as FindwxWidgets.cmake, kept for backward compatibility JW
+
+message(STATUS "Use_wxWindows.cmake is DEPRECATED. \n"
+"Please use find_package(wxWidgets) and include(${wxWidgets_USE_FILE}) instead. (JW)")
+
+
+# ------------------------
+
+find_package( wxWindows )
+
+if(WXWINDOWS_FOUND)
+
+#message("DBG Use_wxWindows.cmake: WXWINDOWS_INCLUDE_DIR=${WXWINDOWS_INCLUDE_DIR} WXWINDOWS_LINK_DIRECTORIES=${WXWINDOWS_LINK_DIRECTORIES} WXWINDOWS_LIBRARIES=${WXWINDOWS_LIBRARIES} CMAKE_WXWINDOWS_CXX_FLAGS=${CMAKE_WXWINDOWS_CXX_FLAGS} WXWINDOWS_DEFINITIONS=${WXWINDOWS_DEFINITIONS}")
+
+ if(WXWINDOWS_INCLUDE_DIR)
+ include_directories(${WXWINDOWS_INCLUDE_DIR})
+ endif()
+ if(WXWINDOWS_LINK_DIRECTORIES)
+ link_directories(${WXWINDOWS_LINK_DIRECTORIES})
+ endif()
+ if(WXWINDOWS_LIBRARIES)
+ link_libraries(${WXWINDOWS_LIBRARIES})
+ endif()
+ if (CMAKE_WXWINDOWS_CXX_FLAGS)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_WXWINDOWS_CXX_FLAGS}")
+ endif()
+ if(WXWINDOWS_DEFINITIONS)
+ add_definitions(${WXWINDOWS_DEFINITIONS})
+ endif()
+else()
+ message(SEND_ERROR "wxWindows not found by Use_wxWindows.cmake")
+endif()
+
diff --git a/Modules/UsewxWidgets.cmake b/Modules/UsewxWidgets.cmake
new file mode 100644
index 0000000000..b3633a6c2f
--- /dev/null
+++ b/Modules/UsewxWidgets.cmake
@@ -0,0 +1,111 @@
+#.rst:
+# UsewxWidgets
+# ------------
+#
+# Convenience include for using wxWidgets library.
+#
+# Determines if wxWidgets was FOUND and sets the appropriate libs,
+# incdirs, flags, etc. INCLUDE_DIRECTORIES and LINK_DIRECTORIES are
+# called.
+#
+# USAGE
+#
+# ::
+#
+# # Note that for MinGW users the order of libs is important!
+# find_package(wxWidgets REQUIRED net gl core base)
+# include(${wxWidgets_USE_FILE})
+# # and for each of your dependent executable/library targets:
+# target_link_libraries(<YourTarget> ${wxWidgets_LIBRARIES})
+#
+#
+#
+# DEPRECATED
+#
+# ::
+#
+# LINK_LIBRARIES is not called in favor of adding dependencies per target.
+#
+#
+#
+# AUTHOR
+#
+# ::
+#
+# Jan Woetzel <jw -at- mip.informatik.uni-kiel.de>
+
+#=============================================================================
+# Copyright 2004-2009 Kitware, Inc.
+# Copyright 2006 Jan Woetzel
+#
+# 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.)
+
+# debug message and logging.
+# comment these out for distribution
+if (NOT LOGFILE )
+ # set(LOGFILE "${PROJECT_BINARY_DIR}/CMakeOutput.log")
+endif ()
+macro(MSG _MSG)
+ # file(APPEND ${LOGFILE} "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}\n")
+ # message(STATUS "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
+endmacro()
+
+
+MSG("wxWidgets_FOUND=${wxWidgets_FOUND}")
+if (wxWidgets_FOUND)
+ if (wxWidgets_INCLUDE_DIRS)
+ if(wxWidgets_INCLUDE_DIRS_NO_SYSTEM)
+ include_directories(${wxWidgets_INCLUDE_DIRS})
+ else()
+ include_directories(SYSTEM ${wxWidgets_INCLUDE_DIRS})
+ endif()
+ MSG("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
+ endif()
+
+ if (wxWidgets_LIBRARY_DIRS)
+ link_directories(${wxWidgets_LIBRARY_DIRS})
+ MSG("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}")
+ endif()
+
+ if (wxWidgets_DEFINITIONS)
+ set_property(DIRECTORY APPEND
+ PROPERTY COMPILE_DEFINITIONS ${wxWidgets_DEFINITIONS})
+ MSG("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
+ endif()
+
+ if (wxWidgets_DEFINITIONS_DEBUG)
+ set_property(DIRECTORY APPEND
+ PROPERTY COMPILE_DEFINITIONS_DEBUG ${wxWidgets_DEFINITIONS_DEBUG})
+ MSG("wxWidgets_DEFINITIONS_DEBUG=${wxWidgets_DEFINITIONS_DEBUG}")
+ endif()
+
+ if (wxWidgets_CXX_FLAGS)
+ # Flags are expected to be a string here, not a list.
+ string(REPLACE ";" " " wxWidgets_CXX_FLAGS_str "${wxWidgets_CXX_FLAGS}")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${wxWidgets_CXX_FLAGS_str}")
+ MSG("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS_str}")
+ unset(wxWidgets_CXX_FLAGS_str)
+ endif()
+
+ # DEPRECATED JW
+ # just for backward compatibility: add deps to all targets
+ # library projects better use advanced find_package(wxWidgets) directly.
+ #if(wxWidgets_LIBRARIES)
+ # link_libraries(${wxWidgets_LIBRARIES})
+ # # BUG: str too long: MSG("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
+ # if(LOGFILE)
+ # file(APPEND ${LOGFILE} "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${wxWidgets_LIBRARIES}\n")
+ # endif()
+ #endif()
+
+else ()
+ message("wxWidgets requested but not found.")
+endif()
diff --git a/Modules/VTKCompatibility.cmake b/Modules/VTKCompatibility.cmake
new file mode 100644
index 0000000000..b33bf2e16d
--- /dev/null
+++ b/Modules/VTKCompatibility.cmake
@@ -0,0 +1,52 @@
+
+#=============================================================================
+# Copyright 2005-2009 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.)
+
+if(APPLE)
+ set(CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY}")
+ set(CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE}")
+ string( REGEX REPLACE "CMAKE_C_COMPILER"
+ CMAKE_CXX_COMPILER CMAKE_CXX_CREATE_SHARED_MODULE
+ "${CMAKE_CXX_CREATE_SHARED_MODULE}")
+ string( REGEX REPLACE "CMAKE_C_COMPILER"
+ CMAKE_CXX_COMPILER CMAKE_CXX_CREATE_SHARED_LIBRARY
+ "${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
+endif()
+
+set(VTKFTGL_BINARY_DIR "${VTK_BINARY_DIR}/Utilities/ftgl"
+ CACHE INTERNAL "")
+set(VTKFREETYPE_BINARY_DIR "${VTK_BINARY_DIR}/Utilities/freetype"
+ CACHE INTERNAL "")
+set(VTKFTGL_SOURCE_DIR "${VTK_SOURCE_DIR}/Utilities/ftgl"
+ CACHE INTERNAL "")
+set(VTKFREETYPE_SOURCE_DIR "${VTK_SOURCE_DIR}/Utilities/freetype"
+ CACHE INTERNAL "")
+
+set(VTK_GLEXT_FILE "${VTK_SOURCE_DIR}/Utilities/ParseOGLExt/headers/glext.h"
+ CACHE FILEPATH
+ "Location of the OpenGL extensions header file (glext.h).")
+set(VTK_GLXEXT_FILE
+ "${VTK_SOURCE_DIR}/Utilities/ParseOGLExt/headers/glxext.h" CACHE FILEPATH
+ "Location of the GLX extensions header file (glxext.h).")
+set(VTK_WGLEXT_FILE "${VTK_SOURCE_DIR}/Utilities/ParseOGLExt/headers/wglext.h"
+ CACHE FILEPATH
+ "Location of the WGL extensions header file (wglext.h).")
+
+# work around an old bug in VTK
+set(TIFF_RIGHT_VERSION 1)
+
+# for very old VTK (versions prior to 4.2)
+macro(SOURCE_FILES)
+ message (FATAL_ERROR "You are trying to build a very old version of VTK (prior to VTK 4.2). To do this you need to use CMake 2.0 as it was the last version of CMake to support VTK 4.0.")
+endmacro()
+
diff --git a/Modules/WIX.template.in b/Modules/WIX.template.in
new file mode 100644
index 0000000000..bbb7c88318
--- /dev/null
+++ b/Modules/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"/>
+
+ <Media Id="1" Cabinet="media1.cab" EmbedCab="yes"/>
+
+ <MajorUpgrade
+ Schedule="afterInstallInitialize"
+ AllowSameVersionUpgrades="yes"
+ DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit."/>
+
+ <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"?>
+ </Product>
+</Wix>
diff --git a/Modules/WriteBasicConfigVersionFile.cmake b/Modules/WriteBasicConfigVersionFile.cmake
new file mode 100644
index 0000000000..7d28e95bf7
--- /dev/null
+++ b/Modules/WriteBasicConfigVersionFile.cmake
@@ -0,0 +1,58 @@
+#.rst:
+# WriteBasicConfigVersionFile
+# ---------------------------
+#
+#
+#
+# ::
+#
+# WRITE_BASIC_CONFIG_VERSION_FILE( filename [VERSION major.minor.patch] COMPATIBILITY (AnyNewerVersion|SameMajorVersion) )
+#
+#
+#
+# Deprecated, see WRITE_BASIC_PACKAGE_VERSION_FILE(), it is identical.
+
+#=============================================================================
+# Copyright 2008-2011 Alexander Neundorf, <neundorf@kde.org>
+# Copyright 2004-2009 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.)
+
+include(CMakeParseArguments)
+
+function(WRITE_BASIC_CONFIG_VERSION_FILE _filename)
+
+ set(options )
+ set(oneValueArgs VERSION COMPATIBILITY )
+ set(multiValueArgs )
+
+ cmake_parse_arguments(CVF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if(CVF_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown keywords given to WRITE_BASIC_CONFIG_VERSION_FILE(): \"${CVF_UNPARSED_ARGUMENTS}\"")
+ endif()
+
+ set(versionTemplateFile "${CMAKE_ROOT}/Modules/BasicConfigVersion-${CVF_COMPATIBILITY}.cmake.in")
+ if(NOT EXISTS "${versionTemplateFile}")
+ message(FATAL_ERROR "Bad COMPATIBILITY value used for WRITE_BASIC_CONFIG_VERSION_FILE(): \"${CVF_COMPATIBILITY}\"")
+ endif()
+
+ if("${CVF_VERSION}" STREQUAL "")
+ if ("${PROJECT_VERSION}" STREQUAL "")
+ message(FATAL_ERROR "No VERSION specified for WRITE_BASIC_CONFIG_VERSION_FILE()")
+ else()
+ set(CVF_VERSION "${PROJECT_VERSION}")
+ endif()
+ endif()
+
+ configure_file("${versionTemplateFile}" "${_filename}" @ONLY)
+
+endfunction()
diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake
new file mode 100644
index 0000000000..86137e2d68
--- /dev/null
+++ b/Modules/WriteCompilerDetectionHeader.cmake
@@ -0,0 +1,535 @@
+#.rst:
+# WriteCompilerDetectionHeader
+# ----------------------------
+#
+# This module provides the function write_compiler_detection_header().
+#
+# The ``WRITE_COMPILER_DETECTION_HEADER`` function can be used to generate
+# a file suitable for preprocessor inclusion which contains macros to be
+# used in source code::
+#
+# write_compiler_detection_header(
+# FILE <file>
+# PREFIX <prefix>
+# COMPILERS <compiler> [...]
+# FEATURES <feature> [...]
+# [VERSION <version>]
+# [PROLOG <prolog>]
+# [EPILOG <epilog>]
+# )
+#
+# The ``write_compiler_detection_header`` function generates the
+# file ``<file>`` with macros which all have the prefix ``<prefix>``.
+#
+# ``VERSION`` may be used to specify the API version to be generated.
+# Future versions of CMake may introduce alternative APIs. A given
+# API is selected by any ``<version>`` value greater than or equal
+# to the version of CMake that introduced the given API and less
+# than the version of CMake that introduced its succeeding API.
+# The value of the :variable:`CMAKE_MINIMUM_REQUIRED_VERSION`
+# variable is used if no explicit version is specified.
+# (As of CMake version |release| there is only one API version.)
+#
+# ``PROLOG`` may be specified as text content to write at the start of the
+# header. ``EPILOG`` may be specified as text content to write at the end
+# of the header
+#
+# At least one ``<compiler>`` and one ``<feature>`` must be listed. Compilers
+# which are known to CMake, but not specified are detected and a preprocessor
+# ``#error`` is generated for them. A preprocessor macro matching
+# ``<PREFIX>_COMPILER_IS_<compiler>`` is generated for each compiler
+# known to CMake to contain the value ``0`` or ``1``.
+#
+# Possible compiler identifiers are documented with the
+# :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
+# Available features in this version of CMake are listed in the
+# :prop_gbl:`CMAKE_C_KNOWN_FEATURES` and
+# :prop_gbl:`CMAKE_CXX_KNOWN_FEATURES` global properties.
+#
+# See the :manual:`cmake-compile-features(7)` manual for information on
+# compile features.
+#
+# Feature Test Macros
+# ===================
+#
+# For each compiler, a preprocessor macro is generated matching
+# ``<PREFIX>_COMPILER_IS_<compiler>`` which has the content either ``0``
+# or ``1``, depending on the compiler in use. Preprocessor macros for
+# compiler version components are generated matching
+# ``<PREFIX>_COMPILER_VERSION_MAJOR`` ``<PREFIX>_COMPILER_VERSION_MINOR``
+# and ``<PREFIX>_COMPILER_VERSION_PATCH`` containing decimal values
+# for the corresponding compiler version components, if defined.
+#
+# A preprocessor test is generated based on the compiler version
+# denoting whether each feature is enabled. A preprocessor macro
+# matching ``<PREFIX>_COMPILER_<FEATURE>``, where ``<FEATURE>`` is the
+# upper-case ``<feature>`` name, is generated to contain the value
+# ``0`` or ``1`` depending on whether the compiler in use supports the
+# feature:
+#
+# .. code-block:: cmake
+#
+# write_compiler_detection_header(
+# FILE climbingstats_compiler_detection.h
+# PREFIX ClimbingStats
+# COMPILERS GNU Clang MSVC
+# FEATURES cxx_variadic_templates
+# )
+#
+# .. code-block:: c++
+#
+# #if ClimbingStats_COMPILER_CXX_VARIADIC_TEMPLATES
+# template<typename... T>
+# void someInterface(T t...) { /* ... */ }
+# #else
+# // Compatibility versions
+# template<typename T1>
+# void someInterface(T1 t1) { /* ... */ }
+# template<typename T1, typename T2>
+# void someInterface(T1 t1, T2 t2) { /* ... */ }
+# template<typename T1, typename T2, typename T3>
+# void someInterface(T1 t1, T2 t2, T3 t3) { /* ... */ }
+# #endif
+#
+# Symbol Macros
+# =============
+#
+# Some additional symbol-defines are created for particular features for
+# use as symbols which may be conditionally defined empty:
+#
+# .. code-block:: c++
+#
+# class MyClass ClimbingStats_FINAL
+# {
+# ClimbingStats_CONSTEXPR int someInterface() { return 42; }
+# };
+#
+# The ``ClimbingStats_FINAL`` macro will expand to ``final`` if the
+# compiler (and its flags) support the ``cxx_final`` feature, and the
+# ``ClimbingStats_CONSTEXPR`` macro will expand to ``constexpr``
+# if ``cxx_constexpr`` is supported.
+#
+# The following features generate corresponding symbol defines:
+#
+# ========================== =================================== =================
+# Feature Define Symbol
+# ========================== =================================== =================
+# ``c_restrict`` ``<PREFIX>_RESTRICT`` ``restrict``
+# ``cxx_constexpr`` ``<PREFIX>_CONSTEXPR`` ``constexpr``
+# ``cxx_deleted_functions`` ``<PREFIX>_DELETED_FUNCTION`` ``= delete``
+# ``cxx_extern_templates`` ``<PREFIX>_EXTERN_TEMPLATE`` ``extern``
+# ``cxx_final`` ``<PREFIX>_FINAL`` ``final``
+# ``cxx_noexcept`` ``<PREFIX>_NOEXCEPT`` ``noexcept``
+# ``cxx_noexcept`` ``<PREFIX>_NOEXCEPT_EXPR(X)`` ``noexcept(X)``
+# ``cxx_override`` ``<PREFIX>_OVERRIDE`` ``override``
+# ========================== =================================== =================
+#
+# Compatibility Implementation Macros
+# ===================================
+#
+# Some features are suitable for wrapping in a macro with a backward
+# compatibility implementation if the compiler does not support the feature.
+#
+# When the ``cxx_static_assert`` feature is not provided by the compiler,
+# a compatibility implementation is available via the
+# ``<PREFIX>_STATIC_ASSERT(COND)`` and
+# ``<PREFIX>_STATIC_ASSERT_MSG(COND, MSG)`` function-like macros. The macros
+# expand to ``static_assert`` where that compiler feature is available, and
+# to a compatibility implementation otherwise. In the first form, the
+# condition is stringified in the message field of ``static_assert``. In
+# the second form, the message ``MSG`` is passed to the message field of
+# ``static_assert``, or ignored if using the backward compatibility
+# implementation.
+#
+# The ``cxx_attribute_deprecated`` feature provides a macro definition
+# ``<PREFIX>_DEPRECATED``, which expands to either the standard
+# ``[[deprecated]]`` attribute or a compiler-specific decorator such
+# as ``__attribute__((__deprecated__))`` used by GNU compilers.
+#
+# The ``cxx_alignas`` feature provides a macro definition
+# ``<PREFIX>_ALIGNAS`` which expands to either the standard ``alignas``
+# decorator or a compiler-specific decorator such as
+# ``__attribute__ ((__aligned__))`` used by GNU compilers.
+#
+# The ``cxx_alignof`` feature provides a macro definition
+# ``<PREFIX>_ALIGNOF`` which expands to either the standard ``alignof``
+# decorator or a compiler-specific decorator such as ``__alignof__``
+# used by GNU compilers.
+#
+# ============================= ================================ =====================
+# Feature Define Symbol
+# ============================= ================================ =====================
+# ``cxx_alignas`` ``<PREFIX>_ALIGNAS`` ``alignas``
+# ``cxx_alignof`` ``<PREFIX>_ALIGNOF`` ``alignof``
+# ``cxx_nullptr`` ``<PREFIX>_NULLPTR`` ``nullptr``
+# ``cxx_static_assert`` ``<PREFIX>_STATIC_ASSERT`` ``static_assert``
+# ``cxx_static_assert`` ``<PREFIX>_STATIC_ASSERT_MSG`` ``static_assert``
+# ``cxx_attribute_deprecated`` ``<PREFIX>_DEPRECATED`` ``[[deprecated]]``
+# ``cxx_attribute_deprecated`` ``<PREFIX>_DEPRECATED_MSG`` ``[[deprecated]]``
+# ============================= ================================ =====================
+#
+# A use-case which arises with such deprecation macros is the deprecation
+# of an entire library. In that case, all public API in the library may
+# be decorated with the ``<PREFIX>_DEPRECATED`` macro. This results in
+# very noisy build output when building the library itself, so the macro
+# may be may be defined to empty in that case when building the deprecated
+# library:
+#
+# .. code-block:: cmake
+#
+# add_library(compat_support ${srcs})
+# target_compile_definitions(compat_support
+# PRIVATE
+# CompatSupport_DEPRECATED=
+# )
+
+#=============================================================================
+# Copyright 2014 Stephen Kelly <steveire@gmail.com>
+#
+# 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.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeCompilerIdDetection.cmake)
+
+function(_load_compiler_variables CompilerId lang)
+ include("${CMAKE_ROOT}/Modules/Compiler/${CompilerId}-${lang}-FeatureTests.cmake" OPTIONAL)
+ set(_cmake_oldestSupported_${CompilerId} ${_cmake_oldestSupported} PARENT_SCOPE)
+ foreach(feature ${ARGN})
+ set(_cmake_feature_test_${CompilerId}_${feature} ${_cmake_feature_test_${feature}} PARENT_SCOPE)
+ endforeach()
+ include("${CMAKE_ROOT}/Modules/Compiler/${CompilerId}-DetermineCompiler.cmake" OPTIONAL)
+ set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE)
+endfunction()
+
+function(write_compiler_detection_header
+ file_keyword file_arg
+ prefix_keyword prefix_arg
+ )
+ if (NOT file_keyword STREQUAL FILE)
+ message(FATAL_ERROR "write_compiler_detection_header: FILE parameter missing.")
+ endif()
+ if (NOT prefix_keyword STREQUAL PREFIX)
+ message(FATAL_ERROR "write_compiler_detection_header: PREFIX parameter missing.")
+ endif()
+ set(options)
+ set(oneValueArgs VERSION EPILOG PROLOG)
+ set(multiValueArgs COMPILERS FEATURES)
+ cmake_parse_arguments(_WCD "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if (NOT _WCD_COMPILERS)
+ message(FATAL_ERROR "Invalid arguments. write_compiler_detection_header requires at least one compiler.")
+ endif()
+ if (NOT _WCD_FEATURES)
+ message(FATAL_ERROR "Invalid arguments. write_compiler_detection_header requires at least one feature.")
+ endif()
+
+ if(_WCD_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unparsed arguments: ${_WCD_UNPARSED_ARGUMENTS}")
+ endif()
+
+ if (prefix_arg STREQUAL "")
+ message(FATAL_ERROR "A prefix must be specified")
+ endif()
+ string(MAKE_C_IDENTIFIER ${prefix_arg} cleaned_prefix)
+ if (NOT prefix_arg STREQUAL cleaned_prefix)
+ message(FATAL_ERROR "The prefix must be a valid C identifier.")
+ endif()
+
+ if(NOT _WCD_VERSION)
+ set(_WCD_VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
+ endif()
+ set(_min_version 3.1.0) # Version which introduced this function
+ if (_WCD_VERSION VERSION_LESS _min_version)
+ set(err "VERSION compatibility for write_compiler_detection_header is set to ${_WCD_VERSION}, which is too low.")
+ set(err "${err} It must be set to at least ${_min_version}. ")
+ set(err "${err} Either set the VERSION parameter to the write_compiler_detection_header function, or update")
+ set(err "${err} your minimum required CMake version with the cmake_minimum_required command.")
+ message(FATAL_ERROR "${err}")
+ endif()
+
+ set(compilers
+ GNU
+ Clang
+ )
+
+ set(_hex_compilers ADSP Borland Embarcadero SunPro)
+
+ foreach(_comp ${_WCD_COMPILERS})
+ list(FIND compilers ${_comp} idx)
+ if (idx EQUAL -1)
+ message(FATAL_ERROR "Unsupported compiler ${_comp}.")
+ endif()
+ if (NOT _need_hex_conversion)
+ list(FIND _hex_compilers ${_comp} idx)
+ if (NOT idx EQUAL -1)
+ set(_need_hex_conversion TRUE)
+ endif()
+ endif()
+ endforeach()
+
+ set(file_content "
+// This is a generated file. Do not edit!
+
+#ifndef ${prefix_arg}_COMPILER_DETECTION_H
+#define ${prefix_arg}_COMPILER_DETECTION_H
+")
+
+ if (_WCD_PROLOG)
+ set(file_content "${file_content}\n${_WCD_PROLOG}\n")
+ endif()
+
+ if (_need_hex_conversion)
+ set(file_content "${file_content}
+#define ${prefix_arg}_DEC(X) (X)
+#define ${prefix_arg}_HEX(X) ( \\
+ ((X)>>28 & 0xF) * 10000000 + \\
+ ((X)>>24 & 0xF) * 1000000 + \\
+ ((X)>>20 & 0xF) * 100000 + \\
+ ((X)>>16 & 0xF) * 10000 + \\
+ ((X)>>12 & 0xF) * 1000 + \\
+ ((X)>>8 & 0xF) * 100 + \\
+ ((X)>>4 & 0xF) * 10 + \\
+ ((X) & 0xF) \\
+ )\n")
+ endif()
+
+ foreach(feature ${_WCD_FEATURES})
+ if (feature MATCHES "^cxx_")
+ list(APPEND _langs CXX)
+ list(APPEND CXX_features ${feature})
+ elseif (feature MATCHES "^c_")
+ list(APPEND _langs C)
+ list(APPEND C_features ${feature})
+ else()
+ message(FATAL_ERROR "Unsupported feature ${feature}.")
+ endif()
+ endforeach()
+ list(REMOVE_DUPLICATES _langs)
+
+ foreach(_lang ${_langs})
+
+ get_property(known_features GLOBAL PROPERTY CMAKE_${_lang}_KNOWN_FEATURES)
+ foreach(feature ${${_lang}_features})
+ list(FIND known_features ${feature} idx)
+ if (idx EQUAL -1)
+ message(FATAL_ERROR "Unsupported feature ${feature}.")
+ endif()
+ endforeach()
+
+ if(_lang STREQUAL CXX)
+ set(file_content "${file_content}\n#ifdef __cplusplus\n")
+ else()
+ set(file_content "${file_content}\n#ifndef __cplusplus\n")
+ endif()
+
+ compiler_id_detection(ID_CONTENT ${_lang} PREFIX ${prefix_arg}_
+ ID_DEFINE
+ )
+
+ set(file_content "${file_content}${ID_CONTENT}\n")
+
+ set(pp_if "if")
+ foreach(compiler ${_WCD_COMPILERS})
+ _load_compiler_variables(${compiler} ${_lang} ${${_lang}_features})
+ set(file_content "${file_content}\n# ${pp_if} ${prefix_arg}_COMPILER_IS_${compiler}\n")
+ set(file_content "${file_content}
+# if !(${_cmake_oldestSupported_${compiler}})
+# error Unsupported compiler version
+# endif\n")
+
+ set(PREFIX ${prefix_arg}_)
+ if (_need_hex_conversion)
+ set(MACRO_DEC ${prefix_arg}_DEC)
+ set(MACRO_HEX ${prefix_arg}_HEX)
+ else()
+ set(MACRO_DEC)
+ set(MACRO_HEX)
+ endif()
+ string(CONFIGURE "${_compiler_id_version_compute_${compiler}}" VERSION_BLOCK @ONLY)
+ set(file_content "${file_content}${VERSION_BLOCK}\n")
+ set(PREFIX)
+ set(MACRO_DEC)
+ set(MACRO_HEX)
+
+ set(pp_if "elif")
+ foreach(feature ${${_lang}_features})
+ string(TOUPPER ${feature} feature_upper)
+ set(feature_PP "COMPILER_${feature_upper}")
+ set(_define_item "\n# define ${prefix_arg}_${feature_PP} 0\n")
+ if (_cmake_feature_test_${compiler}_${feature} STREQUAL "1")
+ set(_define_item "\n# define ${prefix_arg}_${feature_PP} 1\n")
+ elseif (_cmake_feature_test_${compiler}_${feature})
+ set(_define_item "\n# define ${prefix_arg}_${feature_PP} 0\n")
+ set(_define_item "\n# if ${_cmake_feature_test_${compiler}_${feature}}\n# define ${prefix_arg}_${feature_PP} 1\n# else${_define_item}# endif\n")
+ endif()
+ set(file_content "${file_content}${_define_item}")
+ endforeach()
+ endforeach()
+ if(pp_if STREQUAL "elif")
+ set(file_content "${file_content}
+# else
+# error Unsupported compiler
+# endif\n")
+ endif()
+ foreach(feature ${${_lang}_features})
+ string(TOUPPER ${feature} feature_upper)
+ set(feature_PP "COMPILER_${feature_upper}")
+ set(def_name ${prefix_arg}_${feature_PP})
+ if (feature STREQUAL c_restrict)
+ set(def_value "${prefix_arg}_RESTRICT")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} restrict
+# else
+# define ${def_value}
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_constexpr)
+ set(def_value "${prefix_arg}_CONSTEXPR")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} constexpr
+# else
+# define ${def_value}
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_final)
+ set(def_value "${prefix_arg}_FINAL")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} final
+# else
+# define ${def_value}
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_override)
+ set(def_value "${prefix_arg}_OVERRIDE")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} override
+# else
+# define ${def_value}
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_static_assert)
+ set(def_value "${prefix_arg}_STATIC_ASSERT(X)")
+ set(def_value_msg "${prefix_arg}_STATIC_ASSERT_MSG(X, MSG)")
+ set(static_assert_struct "template<bool> struct ${prefix_arg}StaticAssert;\ntemplate<> struct ${prefix_arg}StaticAssert<true>{};\n")
+ set(def_standard "# define ${def_value} static_assert(X, #X)\n# define ${def_value_msg} static_assert(X, MSG)")
+ set(def_alternative "${static_assert_struct}# define ${def_value} sizeof(${prefix_arg}StaticAssert<X>)\n# define ${def_value_msg} sizeof(${prefix_arg}StaticAssert<X>)")
+ set(file_content "${file_content}# if ${def_name}\n${def_standard}\n# else\n${def_alternative}\n# endif\n\n")
+ endif()
+ if (feature STREQUAL cxx_alignas)
+ set(def_value "${prefix_arg}_ALIGNAS(X)")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} alignas(X)
+# elif ${prefix_arg}_COMPILER_IS_GNU || ${prefix_arg}_COMPILER_IS_Clang
+# define ${def_value} __attribute__ ((__aligned__(X)))
+# else
+# define ${def_value}
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_alignof)
+ set(def_value "${prefix_arg}_ALIGNOF(X)")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} alignof(X)
+# elif ${prefix_arg}_COMPILER_IS_GNU || ${prefix_arg}_COMPILER_IS_Clang
+# define ${def_value} __alignof__(X)
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_deleted_functions)
+ set(def_value "${prefix_arg}_DELETED_FUNCTION")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} = delete
+# else
+# define ${def_value}
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_extern_templates)
+ set(def_value "${prefix_arg}_EXTERN_TEMPLATE")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} extern
+# else
+# define ${def_value}
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_noexcept)
+ set(def_value "${prefix_arg}_NOEXCEPT")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} noexcept
+# define ${def_value}_EXPR(X) noexcept(X)
+# else
+# define ${def_value}
+# define ${def_value}_EXPR(X)
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_nullptr)
+ set(def_value "${prefix_arg}_NULLPTR")
+ set(file_content "${file_content}
+# if ${def_name}
+# define ${def_value} nullptr
+# else
+# define ${def_value} static_cast<void*>(0)
+# endif
+\n")
+ endif()
+ if (feature STREQUAL cxx_attribute_deprecated)
+ set(def_name ${prefix_arg}_${feature_PP})
+ set(def_value "${prefix_arg}_DEPRECATED")
+ set(file_content "${file_content}
+# ifndef ${def_value}
+# if ${def_name}
+# define ${def_value} [[deprecated]]
+# define ${def_value}_MSG(MSG) [[deprecated(MSG)]]
+# elif ${prefix_arg}_COMPILER_IS_GNU || ${prefix_arg}_COMPILER_IS_Clang
+# define ${def_value} __attribute__((__deprecated__))
+# define ${def_value}_MSG(MSG) __attribute__((__deprecated__(MSG)))
+# elif ${prefix_arg}_COMPILER_IS_MSVC
+# define ${def_value} __declspec(deprecated)
+# define ${def_value}_MSG(MSG) __declspec(deprecated(MSG))
+# else
+# define ${def_value}
+# define ${def_value}_MSG(MSG)
+# endif
+# endif
+\n")
+ endif()
+ endforeach()
+
+ set(file_content "${file_content}#endif\n")
+
+ endforeach()
+
+ if (_WCD_EPILOG)
+ set(file_content "${file_content}\n${_WCD_EPILOG}\n")
+ endif()
+ set(file_content "${file_content}\n#endif")
+
+ set(CMAKE_CONFIGURABLE_FILE_CONTENT ${file_content})
+ configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
+ "${file_arg}"
+ @ONLY
+ )
+endfunction()
diff --git a/Modules/ecos_clean.cmake b/Modules/ecos_clean.cmake
new file mode 100644
index 0000000000..37a1f93c2f
--- /dev/null
+++ b/Modules/ecos_clean.cmake
@@ -0,0 +1,26 @@
+
+#=============================================================================
+# Copyright 2007-2009 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.)
+
+file(GLOB _files ${ECOS_DIR}/*)
+
+# remove all directories, which consist of lower-case letters only
+# this skips e.g. CVS/ and .subversion/
+foreach(_entry ${_files})
+ if(IS_DIRECTORY ${_entry})
+ get_filename_component(dir ${_entry} NAME)
+ if(${dir} MATCHES "^[a-z]+$")
+ file(REMOVE_RECURSE ${_entry})
+ endif()
+ endif()
+endforeach()
diff --git a/Modules/exportheader.cmake.in b/Modules/exportheader.cmake.in
new file mode 100644
index 0000000000..118de16d69
--- /dev/null
+++ b/Modules/exportheader.cmake.in
@@ -0,0 +1,41 @@
+
+#ifndef @INCLUDE_GUARD_NAME@
+#define @INCLUDE_GUARD_NAME@
+
+#ifdef @STATIC_DEFINE@
+# define @EXPORT_MACRO_NAME@
+# define @NO_EXPORT_MACRO_NAME@
+#else
+# ifndef @EXPORT_MACRO_NAME@
+# ifdef @EXPORT_IMPORT_CONDITION@
+ /* We are building this library */
+# define @EXPORT_MACRO_NAME@ @DEFINE_EXPORT@
+# else
+ /* We are using this library */
+# define @EXPORT_MACRO_NAME@ @DEFINE_IMPORT@
+# endif
+# endif
+
+# ifndef @NO_EXPORT_MACRO_NAME@
+# define @NO_EXPORT_MACRO_NAME@ @DEFINE_NO_EXPORT@
+# endif
+#endif
+
+#ifndef @DEPRECATED_MACRO_NAME@
+# define @DEPRECATED_MACRO_NAME@ @DEFINE_DEPRECATED@
+#endif
+
+#ifndef @DEPRECATED_MACRO_NAME@_EXPORT
+# define @DEPRECATED_MACRO_NAME@_EXPORT @EXPORT_MACRO_NAME@ @DEPRECATED_MACRO_NAME@
+#endif
+
+#ifndef @DEPRECATED_MACRO_NAME@_NO_EXPORT
+# define @DEPRECATED_MACRO_NAME@_NO_EXPORT @NO_EXPORT_MACRO_NAME@ @DEPRECATED_MACRO_NAME@
+#endif
+
+#cmakedefine01 DEFINE_NO_DEPRECATED
+#if DEFINE_NO_DEPRECATED
+# define @NO_DEPRECATED_MACRO_NAME@
+#endif
+
+#endif
diff --git a/Modules/kde3init_dummy.cpp.in b/Modules/kde3init_dummy.cpp.in
new file mode 100644
index 0000000000..7135c73a1b
--- /dev/null
+++ b/Modules/kde3init_dummy.cpp.in
@@ -0,0 +1,6 @@
+
+/* used by KDE3Macros.cmake */
+
+extern "C" int kdemain(int argc, char* argv[]);
+extern "C" int kdeinitmain(int argc, char* argv[]) { return kdemain(argc,argv); }
+int main(int argc, char* argv[]) { return kdemain(argc,argv); }
diff --git a/Modules/kde3uic.cmake b/Modules/kde3uic.cmake
new file mode 100644
index 0000000000..4ad364b50f
--- /dev/null
+++ b/Modules/kde3uic.cmake
@@ -0,0 +1,33 @@
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Alexander Neundorf <neundorf@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.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# used internally by KDE3Macros.cmake
+# neundorf@kde.org
+
+
+execute_process(COMMAND ${KDE_UIC_EXECUTABLE}
+ -L ${KDE_UIC_PLUGIN_DIR} -nounload -tr tr2i18n
+ -impl ${KDE_UIC_H_FILE}
+ ${KDE_UIC_FILE}
+ OUTPUT_VARIABLE _uic_CONTENTS
+ ERROR_QUIET
+ )
+
+string(REGEX REPLACE "tr2i18n\\(\"\"\\)" "QString::null" _uic_CONTENTS "${_uic_CONTENTS}" )
+string(REGEX REPLACE "tr2i18n\\(\"\", \"\"\\)" "QString::null" _uic_CONTENTS "${_uic_CONTENTS}" )
+
+file(WRITE ${KDE_UIC_CPP_FILE} "#include <kdialog.h>\n#include <klocale.h>\n\n")
+file(APPEND ${KDE_UIC_CPP_FILE} "${_uic_CONTENTS}")
+
diff --git a/Modules/readme.txt b/Modules/readme.txt
new file mode 100644
index 0000000000..b40f3d0097
--- /dev/null
+++ b/Modules/readme.txt
@@ -0,0 +1,4 @@
+See the "Find Modules" section of the cmake-developer(7) manual page.
+
+For more information about how to contribute modules to CMake, see this page:
+http://www.cmake.org/Wiki/CMake:Module_Maintainers
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000000..e8524f81a3
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,99 @@
+CMake
+*****
+
+Introduction
+============
+
+CMake is a cross-platform, open-source build system generator.
+For full documentation visit the `CMake Home Page`_ and the
+`CMake Documentation Page`_.
+
+.. _`CMake Home Page`: http://www.cmake.org
+.. _`CMake Documentation Page`: http://www.cmake.org/cmake/help/documentation.html
+
+CMake is maintained and supported by `Kitware`_ and developed in
+collaboration with a productive community of contributors.
+
+.. _`Kitware`: http://www.kitware.com/cmake
+
+License
+=======
+
+CMake is distributed under the OSI-approved BSD 3-clause License.
+See `Copyright.txt`_ for details.
+
+.. _`Copyright.txt`: Copyright.txt
+
+Building CMake
+==============
+
+Supported Platforms
+-------------------
+
+MS Windows, Mac OS X, Linux, FreeBSD, Solaris, HP-UX, IRIX, BeOS, QNX
+
+Other UNIX-like operating systems may work too out of the box, if not
+it should not be a major problem to port CMake to this platform.
+Subscribe and post to the `CMake Users List`_ to ask if others have
+had experience with the platform.
+
+.. _`CMake Users List`: http://www.cmake.org/mailman/listinfo/cmake
+
+Building CMake from Scratch
+---------------------------
+
+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.
+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
+within the CMake source directory or any other build directory of your
+choice. Once this has finished successfully, run ``make`` and
+``make install``. In summary::
+
+ $ ./bootstrap && make && make install
+
+Windows
+^^^^^^^
+
+You need to download and install a binary release of CMake in order to build
+CMake. You can get these releases from the `CMake Download Page`_ . Then
+proceed with the instructions below.
+
+.. _`CMake Download Page`: http://www.cmake.org/cmake/resources/software.html
+
+Building CMake with CMake
+-------------------------
+
+You can build CMake as any other project with a CMake-based build system:
+run the installed CMake on the sources of this CMake with your preferred
+options and generators. Then build it and install it.
+For instructions how to do this, see documentation on `Running CMake`_.
+
+.. _`Running CMake`: http://www.cmake.org/cmake/help/runningcmake.html
+
+Reporting Bugs
+==============
+
+If you have found a bug:
+
+1. If you have a patch, please read the `CONTRIBUTING.rst`_ document.
+
+2. Otherwise, please join the the `CMake Users List`_ and ask about
+ the expected and observed behaviors to determine if it is really
+ a bug.
+
+3. Finally, if the issue is not resolved by the above steps, open
+ an entry in the `CMake Issue Tracker`_.
+
+.. _`CMake Issue Tracker`: http://www.cmake.org/Bug
+
+Contributing
+============
+
+See `CONTRIBUTING.rst`_ for instructions to contribute.
+
+.. _`CONTRIBUTING.rst`: CONTRIBUTING.rst
diff --git a/Source/.cvsignore b/Source/.cvsignore
new file mode 100644
index 0000000000..31e286c6de
--- /dev/null
+++ b/Source/.cvsignore
@@ -0,0 +1,5 @@
+ccommand___Win32_Debug
+Debug
+cmake___Win32_Debug
+ctest___Win32_Debug
+CMakeSetup.map
diff --git a/Source/.gitattributes b/Source/.gitattributes
new file mode 100644
index 0000000000..cf4dabd86b
--- /dev/null
+++ b/Source/.gitattributes
@@ -0,0 +1,2 @@
+# Preserve upstream indentation style.
+cm_sha2.* whitespace=indent-with-non-tab
diff --git a/Source/CMakeInstallDestinations.cmake b/Source/CMakeInstallDestinations.cmake
new file mode 100644
index 0000000000..99c86ca77b
--- /dev/null
+++ b/Source/CMakeInstallDestinations.cmake
@@ -0,0 +1,38 @@
+# Keep formatting here consistent with bootstrap script expectations.
+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
+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
+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
+endif()
+
+set(CMAKE_DATA_DIR_DESC "data")
+set(CMAKE_DOC_DIR_DESC "docs")
+set(CMAKE_MAN_DIR_DESC "man pages")
+
+foreach(v
+ CMAKE_DATA_DIR
+ CMAKE_DOC_DIR
+ CMAKE_MAN_DIR
+ )
+ # Populate the cache with empty values so we know when the user sets them.
+ set(${v} "" CACHE STRING "")
+ set_property(CACHE ${v} PROPERTY HELPSTRING
+ "Location under install prefix for ${${v}_DESC} (default \"${${v}_DEFAULT}\")"
+ )
+ set_property(CACHE ${v} PROPERTY ADVANCED 1)
+
+ # Use the default when the user did not set this variable.
+ if(NOT ${v})
+ set(${v} "${${v}_DEFAULT}")
+ endif()
+ # Remove leading slash to treat as relative to install prefix.
+ string(REGEX REPLACE "^/" "" ${v} "${${v}}")
+endforeach()
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
new file mode 100644
index 0000000000..f9405b364f
--- /dev/null
+++ b/Source/CMakeLists.txt
@@ -0,0 +1,674 @@
+#=============================================================================
+# 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(CheckIncludeFile)
+# Check if we can build support for ELF parsing.
+if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
+ CHECK_INCLUDE_FILES("stdint.h;elf_abi.h" HAVE_ELF_H)
+else()
+ CHECK_INCLUDE_FILE("elf.h" HAVE_ELF_H)
+endif()
+if(HAVE_ELF_H)
+ set(CMAKE_USE_ELF_PARSER 1)
+elseif(HAIKU)
+ # On Haiku, we need to include elf32.h from the private headers
+ set(CMake_HAIKU_INCLUDE_DIRS
+ /boot/system/develop/headers/private/system
+ /boot/system/develop/headers/private/system/arch/x86
+ )
+
+ set(CMAKE_REQUIRED_INCLUDES ${CMake_HAIKU_INCLUDE_DIRS})
+ CHECK_INCLUDE_FILE("elf32.h" HAVE_ELF32_H)
+ unset(CMAKE_REQUIRED_INCLUDES)
+
+ if(HAVE_ELF32_H)
+ set(CMAKE_USE_ELF_PARSER 1)
+ else()
+ unset(CMake_HAIKU_INCLUDE_DIRS)
+ set(CMAKE_USE_ELF_PARSER)
+ endif()
+else()
+ set(CMAKE_USE_ELF_PARSER)
+endif()
+
+set(EXECUTABLE_OUTPUT_PATH ${CMake_BIN_DIR})
+
+# ensure Unicode friendly APIs are used on Windows
+if(WIN32)
+ add_definitions(-DUNICODE -D_UNICODE)
+endif()
+
+# configure the .h file
+configure_file(
+ "${CMake_SOURCE_DIR}/Source/cmConfigure.cmake.h.in"
+ "${CMake_BINARY_DIR}/Source/cmConfigure.h"
+ )
+configure_file(
+ "${CMake_SOURCE_DIR}/Source/cmVersionConfig.h.in"
+ "${CMake_BINARY_DIR}/Source/cmVersionConfig.h"
+ )
+configure_file(
+ "${CMake_SOURCE_DIR}/Source/CPack/cmCPackConfigure.h.in"
+ "${CMake_BINARY_DIR}/Source/CPack/cmCPackConfigure.h"
+ )
+
+# Tell CMake executable in the build tree where to find the source tree.
+configure_file(
+ "${CMake_SOURCE_DIR}/Source/CMakeSourceDir.txt.in"
+ "${CMake_BINARY_DIR}/CMakeFiles/CMakeSourceDir.txt" @ONLY
+ )
+
+# add the include path to find the .h
+include_directories(
+ "${CMake_BINARY_DIR}/Source"
+ "${CMake_SOURCE_DIR}/Source"
+ ${CMAKE_ZLIB_INCLUDES}
+ ${CMAKE_EXPAT_INCLUDES}
+ ${CMAKE_TAR_INCLUDES}
+ ${CMAKE_COMPRESS_INCLUDES}
+ ${CMake_HAIKU_INCLUDE_DIRS}
+ )
+
+# let cmake know it is supposed to use it
+add_definitions(-DCMAKE_BUILD_WITH_CMAKE)
+
+option(CMAKE_REGENERATE_YACCLEX
+ "Regenerate YACC and LEXX files" OFF)
+mark_as_advanced(CMAKE_REGENERATE_YACCLEX)
+if(CMAKE_REGENERATE_YACCLEX)
+ set(parsersLexers cmDependsFortran cmCommandArgument cmExpr)
+ find_program(YACC_EXECUTABLE
+ NAMES yacc bison
+ PATHS /usr/bin
+ DOC "Yacc or Bison executable")
+ find_program(FLEX_EXECUTABLE
+ NAMES flex
+ PATHS /usr/bin
+ DOC "Flex executable")
+ mark_as_advanced(YACC_EXECUTABLE FLEX_EXECUTABLE)
+ if(YACC_EXECUTABLE)
+ set(BISON_FLAGS)
+ if(YACC_EXECUTABLE MATCHES "bison")
+ set(BISON_FLAGS "--yacc")
+ endif()
+ set(yacc_files)
+ foreach(name ${parsersLexers})
+ set(src "${CMAKE_CURRENT_SOURCE_DIR}/${name}Parser.y")
+ set(dst "${CMAKE_CURRENT_BINARY_DIR}/${name}Parser.cxx")
+ set(hdr "${CMAKE_CURRENT_BINARY_DIR}/${name}ParserTokens.h")
+ add_custom_command(
+ OUTPUT "${dst}"
+ DEPENDS "${src}"
+ COMMAND
+ ${YACC_EXECUTABLE}
+ --name-prefix=${name}_yy --defines=${hdr} -o${dst} ${src}
+ )
+ set(yacc_files ${yacc_files} "${dst}")
+ endforeach()
+ add_custom_target(RerunYacc DEPENDS ${yacc_files})
+ endif()
+ if(FLEX_EXECUTABLE)
+ set(lex_files)
+ foreach(name ${parsersLexers})
+ set(src "${CMAKE_CURRENT_SOURCE_DIR}/${name}Lexer.in.l")
+ set(dst "${CMAKE_CURRENT_BINARY_DIR}/${name}Lexer.cxx")
+ set(hdr "${CMAKE_CURRENT_BINARY_DIR}/${name}Lexer.h")
+ add_custom_command(
+ OUTPUT "${dst}"
+ DEPENDS "${src}"
+ COMMAND
+ ${FLEX_EXECUTABLE}
+ --prefix=${name}_yy --header-file=${hdr} -o${dst} ${src}
+ )
+ set(lex_files ${lex_files} "${dst}")
+ endforeach()
+ add_custom_target(RerunLex DEPENDS ${lex_files})
+ endif()
+
+endif()
+
+# Check if we can build the ELF parser.
+if(CMAKE_USE_ELF_PARSER)
+ set(ELF_SRCS cmELF.h cmELF.cxx)
+endif()
+
+#
+# Sources for CMakeLib
+#
+set(SRCS
+ cmStandardIncludes.cxx
+ cmArchiveWrite.cxx
+ cmBootstrapCommands1.cxx
+ cmBootstrapCommands2.cxx
+ cmCacheManager.cxx
+ cmCacheManager.h
+ "${CMAKE_CURRENT_BINARY_DIR}/cmCommands.cxx"
+ cmCommands.h
+ cmCommandArgumentLexer.cxx
+ cmCommandArgumentParser.cxx
+ cmCommandArgumentParserHelper.cxx
+ cmComputeComponentGraph.cxx
+ cmComputeComponentGraph.h
+ cmComputeLinkDepends.cxx
+ cmComputeLinkDepends.h
+ cmComputeLinkInformation.cxx
+ cmComputeLinkInformation.h
+ cmComputeTargetDepends.h
+ cmComputeTargetDepends.cxx
+ cmCPackPropertiesGenerator.h
+ cmCPackPropertiesGenerator.cxx
+ cmCryptoHash.cxx
+ cmCryptoHash.h
+ cmCustomCommand.cxx
+ cmCustomCommand.h
+ cmCustomCommandGenerator.cxx
+ cmCustomCommandGenerator.h
+ cmDefinitions.cxx
+ cmDefinitions.h
+ cmDepends.cxx
+ cmDepends.h
+ cmDependsC.cxx
+ cmDependsC.h
+ cmDependsFortran.cxx
+ cmDependsFortran.h
+ cmDependsFortranLexer.cxx
+ cmDependsFortranParser.cxx
+ cmDependsFortranParser.h
+ cmDependsJava.cxx
+ cmDependsJava.h
+ cmDependsJavaLexer.cxx
+ cmDependsJavaParser.cxx
+ cmDependsJavaParserHelper.cxx
+ cmDependsJavaParserHelper.h
+ cmDocumentation.cxx
+ cmDocumentationFormatter.cxx
+ cmDocumentationSection.cxx
+ cmDynamicLoader.cxx
+ cmDynamicLoader.h
+ ${ELF_SRCS}
+ cmExprLexer.cxx
+ cmExprParser.cxx
+ cmExprParserHelper.cxx
+ cmExportBuildFileGenerator.h
+ cmExportBuildFileGenerator.cxx
+ cmExportFileGenerator.h
+ cmExportFileGenerator.cxx
+ cmExportInstallFileGenerator.h
+ cmExportInstallFileGenerator.cxx
+ cmExportTryCompileFileGenerator.h
+ cmExportTryCompileFileGenerator.cxx
+ cmExportSet.h
+ cmExportSet.cxx
+ cmExportSetMap.h
+ cmExportSetMap.cxx
+ cmExtraCodeBlocksGenerator.cxx
+ cmExtraCodeBlocksGenerator.h
+ cmExtraCodeLiteGenerator.cxx
+ cmExtraCodeLiteGenerator.h
+ cmExtraEclipseCDT4Generator.cxx
+ cmExtraEclipseCDT4Generator.h
+ cmExtraKateGenerator.cxx
+ cmExtraKateGenerator.h
+ cmExtraSublimeTextGenerator.cxx
+ cmExtraSublimeTextGenerator.h
+ cmFileTimeComparison.cxx
+ cmFileTimeComparison.h
+ cmGeneratedFileStream.cxx
+ cmGeneratorExpressionDAGChecker.cxx
+ cmGeneratorExpressionDAGChecker.h
+ cmGeneratorExpressionEvaluator.cxx
+ cmGeneratorExpressionEvaluator.h
+ cmGeneratorExpressionLexer.cxx
+ cmGeneratorExpressionLexer.h
+ cmGeneratorExpressionParser.cxx
+ cmGeneratorExpressionParser.h
+ cmGeneratorExpression.cxx
+ cmGeneratorExpression.h
+ cmGeneratorTarget.cxx
+ cmGeneratorTarget.h
+ cmGlobalGenerator.cxx
+ cmGlobalGenerator.h
+ cmGlobalGeneratorFactory.h
+ cmGlobalUnixMakefileGenerator3.cxx
+ cmGlobalUnixMakefileGenerator3.h
+ cmGraphAdjacencyList.h
+ cmGraphVizWriter.cxx
+ cmGraphVizWriter.h
+ cmInstallGenerator.h
+ cmInstallGenerator.cxx
+ cmInstallExportGenerator.cxx
+ cmInstalledFile.h
+ cmInstalledFile.cxx
+ cmInstallFilesGenerator.h
+ cmInstallFilesGenerator.cxx
+ cmInstallScriptGenerator.h
+ cmInstallScriptGenerator.cxx
+ cmInstallTargetGenerator.h
+ cmInstallTargetGenerator.cxx
+ cmInstallDirectoryGenerator.h
+ cmInstallDirectoryGenerator.cxx
+ cmListFileCache.cxx
+ cmListFileCache.h
+ cmListFileLexer.c
+ cmLocalGenerator.cxx
+ cmLocalGenerator.h
+ cmLocalUnixMakefileGenerator3.cxx
+ cmMakeDepend.cxx
+ cmMakeDepend.h
+ cmMakefile.cxx
+ cmMakefile.h
+ cmMakefileTargetGenerator.cxx
+ cmMakefileExecutableTargetGenerator.cxx
+ cmMakefileLibraryTargetGenerator.cxx
+ cmMakefileUtilityTargetGenerator.cxx
+ cmOSXBundleGenerator.cxx
+ cmOSXBundleGenerator.h
+ cmNewLineStyle.h
+ cmNewLineStyle.cxx
+ cmOrderDirectories.cxx
+ cmOrderDirectories.h
+ cmPolicies.h
+ cmPolicies.cxx
+ cmProcessTools.cxx
+ cmProcessTools.h
+ cmProperty.cxx
+ cmProperty.h
+ cmPropertyDefinition.cxx
+ cmPropertyDefinition.h
+ cmPropertyDefinitionMap.cxx
+ cmPropertyDefinitionMap.h
+ cmPropertyMap.cxx
+ cmPropertyMap.h
+ cmQtAutoGenerators.cxx
+ cmQtAutoGenerators.h
+ cmRST.cxx
+ cmRST.h
+ cmScriptGenerator.h
+ cmScriptGenerator.cxx
+ cmSourceFile.cxx
+ cmSourceFile.h
+ cmSourceFileLocation.cxx
+ cmSourceFileLocation.h
+ cmSourceGroup.cxx
+ cmSourceGroup.h
+ cmSystemTools.cxx
+ cmSystemTools.h
+ cmTarget.cxx
+ cmTarget.h
+ cmTargetExport.h
+ cmTest.cxx
+ cmTest.h
+ cmTestGenerator.cxx
+ cmTestGenerator.h
+ cmUuid.cxx
+ cmVariableWatch.cxx
+ cmVariableWatch.h
+ cmVersion.cxx
+ cmVersion.h
+ cmXMLParser.cxx
+ cmXMLParser.h
+ cmXMLSafe.cxx
+ cmXMLSafe.h
+ cmake.cxx
+ cmake.h
+
+ cm_sha2.h
+ cm_sha2.c
+ cm_utf8.h
+ cm_utf8.c
+ )
+
+set(COMMAND_INCLUDES "#include \"cmTargetPropCommandBase.cxx\"\n")
+list(APPEND SRCS cmTargetPropCommandBase.cxx)
+set_property(SOURCE cmTargetPropCommandBase.cxx PROPERTY HEADER_FILE_ONLY ON)
+set(NEW_COMMANDS "")
+foreach(command_file
+ cmAddCompileOptionsCommand
+ cmAuxSourceDirectoryCommand
+ cmBuildNameCommand
+ cmCMakeHostSystemInformationCommand
+ cmElseIfCommand
+ cmExportCommand
+ cmExportLibraryDependenciesCommand
+ cmFLTKWrapUICommand
+ cmIncludeExternalMSProjectCommand
+ cmInstallProgramsCommand
+ cmLinkLibrariesCommand
+ cmLoadCacheCommand
+ cmOutputRequiredFilesCommand
+ cmQTWrapCPPCommand
+ cmQTWrapUICommand
+ cmRemoveCommand
+ cmRemoveDefinitionsCommand
+ cmSourceGroupCommand
+ cmSubdirDependsCommand
+ cmTargetCompileDefinitionsCommand
+ cmTargetCompileFeaturesCommand
+ cmTargetCompileOptionsCommand
+ cmTargetIncludeDirectoriesCommand
+ cmTargetSourcesCommand
+ cmUseMangledMesaCommand
+ cmUtilitySourceCommand
+ cmVariableRequiresCommand
+ cmVariableWatchCommand
+ cmWriteFileCommand
+ # This one must be last because it includes windows.h and
+ # windows.h #defines GetCurrentDirectory which is a member
+ # of cmMakefile
+ cmLoadCommandCommand
+ )
+ set(COMMAND_INCLUDES "${COMMAND_INCLUDES}#include \"${command_file}.cxx\"\n")
+ set(NEW_COMMANDS "${NEW_COMMANDS}commands.push_back(new ${command_file});\n")
+ list(APPEND SRCS ${command_file}.cxx)
+ set_property(SOURCE ${command_file}.cxx PROPERTY HEADER_FILE_ONLY ON)
+endforeach()
+configure_file(cmCommands.cxx.in ${CMAKE_CURRENT_BINARY_DIR}/cmCommands.cxx @ONLY)
+
+# Kdevelop only works on UNIX and not windows
+if(UNIX)
+ set(SRCS ${SRCS} cmGlobalKdevelopGenerator.cxx)
+endif()
+
+# Xcode only works on Apple
+if(APPLE)
+ set(SRCS ${SRCS}
+ cmXCodeObject.cxx
+ cmXCode21Object.cxx
+ cmGlobalXCodeGenerator.cxx
+ cmGlobalXCodeGenerator.h
+ cmLocalXCodeGenerator.cxx
+ cmLocalXCodeGenerator.h)
+endif()
+
+
+if (WIN32)
+ set(SRCS ${SRCS}
+ cmCallVisualStudioMacro.cxx
+ cmCallVisualStudioMacro.h
+ )
+
+ if(NOT UNIX)
+ set(SRCS ${SRCS}
+ cmGlobalBorlandMakefileGenerator.cxx
+ cmGlobalBorlandMakefileGenerator.h
+ cmGlobalMSYSMakefileGenerator.cxx
+ cmGlobalMinGWMakefileGenerator.cxx
+ cmGlobalNMakeMakefileGenerator.cxx
+ cmGlobalNMakeMakefileGenerator.h
+ cmGlobalJOMMakefileGenerator.cxx
+ cmGlobalJOMMakefileGenerator.h
+ cmGlobalVisualStudio6Generator.cxx
+ cmGlobalVisualStudio6Generator.h
+ cmGlobalVisualStudio71Generator.cxx
+ cmGlobalVisualStudio71Generator.h
+ cmGlobalVisualStudio7Generator.cxx
+ cmGlobalVisualStudio7Generator.h
+ cmGlobalVisualStudio8Generator.cxx
+ cmGlobalVisualStudio8Generator.h
+ cmGlobalVisualStudio9Generator.cxx
+ cmGlobalVisualStudio9Generator.h
+ cmVisualStudioGeneratorOptions.h
+ cmVisualStudioGeneratorOptions.cxx
+ cmVisualStudio10TargetGenerator.h
+ cmVisualStudio10TargetGenerator.cxx
+ cmLocalVisualStudio10Generator.cxx
+ cmLocalVisualStudio10Generator.h
+ cmGlobalVisualStudio10Generator.h
+ cmGlobalVisualStudio10Generator.cxx
+ cmGlobalVisualStudio11Generator.h
+ cmGlobalVisualStudio11Generator.cxx
+ cmGlobalVisualStudio12Generator.h
+ cmGlobalVisualStudio12Generator.cxx
+ cmGlobalVisualStudio14Generator.h
+ cmGlobalVisualStudio14Generator.cxx
+ cmGlobalVisualStudioGenerator.cxx
+ cmGlobalVisualStudioGenerator.h
+ cmIDEFlagTable.h
+ cmIDEOptions.cxx
+ cmIDEOptions.h
+ cmLocalVisualStudio6Generator.cxx
+ cmLocalVisualStudio6Generator.h
+ cmLocalVisualStudio7Generator.cxx
+ cmLocalVisualStudio7Generator.h
+ cmLocalVisualStudioGenerator.cxx
+ cmLocalVisualStudioGenerator.h
+ cmVisualStudioSlnData.h
+ cmVisualStudioSlnData.cxx
+ cmVisualStudioSlnParser.h
+ cmVisualStudioSlnParser.cxx
+ cmVisualStudioWCEPlatformParser.h
+ cmVisualStudioWCEPlatformParser.cxx
+ )
+ endif()
+endif ()
+
+# Watcom support
+if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ set_property(SOURCE cmake.cxx APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_USE_WMAKE)
+ list(APPEND SRCS
+ cmGlobalWatcomWMakeGenerator.cxx
+ cmGlobalWatcomWMakeGenerator.h
+ )
+endif()
+
+# Ninja support
+set(SRCS ${SRCS}
+ cmGlobalNinjaGenerator.cxx
+ cmGlobalNinjaGenerator.h
+ cmNinjaTypes.h
+ cmLocalNinjaGenerator.cxx
+ cmLocalNinjaGenerator.h
+ cmNinjaTargetGenerator.cxx
+ cmNinjaTargetGenerator.h
+ cmNinjaNormalTargetGenerator.cxx
+ cmNinjaNormalTargetGenerator.h
+ cmNinjaUtilityTargetGenerator.cxx
+ cmNinjaUtilityTargetGenerator.h
+ )
+if(WIN32 AND NOT CYGWIN AND NOT BORLAND)
+ set_source_files_properties(cmcldeps.cxx PROPERTIES COMPILE_DEFINITIONS _WIN32_WINNT=0x0501)
+ add_executable(cmcldeps cmcldeps.cxx)
+ target_link_libraries(cmcldeps CMakeLib)
+ install(TARGETS cmcldeps DESTINATION bin)
+endif()
+
+# create a library used by the command line and the GUI
+add_library(CMakeLib ${SRCS})
+target_link_libraries(CMakeLib cmsys
+ ${CMAKE_EXPAT_LIBRARIES} ${CMAKE_ZLIB_LIBRARIES}
+ ${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES}
+ ${CMAKE_CURL_LIBRARIES} )
+
+# On Apple we need CoreFoundation
+if(APPLE)
+ target_link_libraries(CMakeLib "-framework CoreFoundation")
+endif()
+
+# On some platforms we need the rpcrt4 library for the VS 7 generators.
+if(CMAKE_BUILD_ON_VISUAL_STUDIO OR MINGW)
+ target_link_libraries(CMakeLib rpcrt4)
+endif()
+
+#
+# CTestLib
+#
+include_directories(
+ "${CMake_SOURCE_DIR}/Source/CTest"
+ ${CMAKE_XMLRPC_INCLUDES}
+ ${CMAKE_CURL_INCLUDES}
+ )
+#
+# Sources for CTestLib
+#
+set(CTEST_SRCS cmCTest.cxx
+ CTest/cmProcess.cxx
+ CTest/cmCTestBatchTestHandler.cxx
+ CTest/cmCTestBuildAndTestHandler.cxx
+ CTest/cmCTestBuildCommand.cxx
+ CTest/cmCTestBuildHandler.cxx
+ CTest/cmCTestConfigureCommand.cxx
+ CTest/cmCTestConfigureHandler.cxx
+ CTest/cmCTestCoverageCommand.cxx
+ CTest/cmCTestCoverageHandler.cxx
+ CTest/cmParseMumpsCoverage.cxx
+ CTest/cmParseCacheCoverage.cxx
+ CTest/cmParseGTMCoverage.cxx
+ CTest/cmParseJacocoCoverage.cxx
+ CTest/cmParsePHPCoverage.cxx
+ CTest/cmParseCoberturaCoverage.cxx
+ CTest/cmCTestEmptyBinaryDirectoryCommand.cxx
+ CTest/cmCTestGenericHandler.cxx
+ CTest/cmCTestHandlerCommand.cxx
+ CTest/cmCTestLaunch.cxx
+ CTest/cmCTestMemCheckCommand.cxx
+ CTest/cmCTestMemCheckHandler.cxx
+ CTest/cmCTestMultiProcessHandler.cxx
+ CTest/cmCTestReadCustomFilesCommand.cxx
+ CTest/cmCTestRunScriptCommand.cxx
+ CTest/cmCTestRunTest.cxx
+ CTest/cmCTestScriptHandler.cxx
+ CTest/cmCTestSleepCommand.cxx
+ CTest/cmCTestStartCommand.cxx
+ CTest/cmCTestSubmitCommand.cxx
+ CTest/cmCTestSubmitHandler.cxx
+ CTest/cmCTestTestCommand.cxx
+ CTest/cmCTestTestHandler.cxx
+ CTest/cmCTestUpdateCommand.cxx
+ CTest/cmCTestUpdateHandler.cxx
+ CTest/cmCTestUploadCommand.cxx
+ CTest/cmCTestUploadHandler.cxx
+
+ CTest/cmCTestVC.cxx
+ CTest/cmCTestVC.h
+ CTest/cmCTestGlobalVC.cxx
+ CTest/cmCTestGlobalVC.h
+ CTest/cmCTestCVS.cxx
+ CTest/cmCTestCVS.h
+ CTest/cmCTestSVN.cxx
+ CTest/cmCTestSVN.h
+ CTest/cmCTestBZR.cxx
+ CTest/cmCTestBZR.h
+ CTest/cmCTestGIT.cxx
+ CTest/cmCTestGIT.h
+ CTest/cmCTestHG.cxx
+ CTest/cmCTestHG.h
+ CTest/cmCTestP4.cxx
+ CTest/cmCTestP4.h
+ )
+
+# Build CTestLib
+add_library(CTestLib ${CTEST_SRCS})
+target_link_libraries(CTestLib CMakeLib ${CMAKE_CURL_LIBRARIES} ${CMAKE_XMLRPC_LIBRARIES})
+
+#
+# Sources for CPack
+#
+set(CPACK_SRCS
+ CPack/cmCPackArchiveGenerator.cxx
+ CPack/cmCPackComponentGroup.cxx
+ CPack/cmCPackGeneratorFactory.cxx
+ CPack/cmCPackGenerator.cxx
+ CPack/cmCPackLog.cxx
+ CPack/cmCPackNSISGenerator.cxx
+ CPack/IFW/cmCPackIFWPackage.cxx
+ CPack/IFW/cmCPackIFWInstaller.cxx
+ CPack/IFW/cmCPackIFWGenerator.cxx
+ CPack/cmCPackSTGZGenerator.cxx
+ CPack/cmCPackTGZGenerator.cxx
+ CPack/cmCPackTXZGenerator.cxx
+ CPack/cmCPackTarBZip2Generator.cxx
+ CPack/cmCPackTarCompressGenerator.cxx
+ CPack/cmCPackZIPGenerator.cxx
+ CPack/cmCPack7zGenerator.cxx
+ )
+
+if(CYGWIN)
+ set(CPACK_SRCS ${CPACK_SRCS}
+ CPack/cmCPackCygwinBinaryGenerator.cxx
+ CPack/cmCPackCygwinSourceGenerator.cxx
+ )
+endif()
+
+if(UNIX)
+ set(CPACK_SRCS ${CPACK_SRCS}
+ CPack/cmCPackDebGenerator.cxx
+ CPack/cmCPackRPMGenerator.cxx
+ )
+endif()
+
+if(WIN32)
+ set(CPACK_SRCS ${CPACK_SRCS}
+ CPack/WiX/cmCPackWIXGenerator.cxx
+ CPack/WiX/cmWIXAccessControlList.cxx
+ CPack/WiX/cmWIXDirectoriesSourceWriter.cxx
+ CPack/WiX/cmWIXFeaturesSourceWriter.cxx
+ CPack/WiX/cmWIXFilesSourceWriter.cxx
+ CPack/WiX/cmWIXPatch.cxx
+ CPack/WiX/cmWIXPatchParser.cxx
+ CPack/WiX/cmWIXRichTextFormatWriter.cxx
+ CPack/WiX/cmWIXSourceWriter.cxx
+ )
+endif()
+
+if(APPLE)
+ set(CPACK_SRCS ${CPACK_SRCS}
+ CPack/cmCPackBundleGenerator.cxx
+ CPack/cmCPackDragNDropGenerator.cxx
+ CPack/cmCPackOSXX11Generator.cxx
+ CPack/cmCPackPackageMakerGenerator.cxx
+ )
+endif()
+
+# Build CPackLib
+add_library(CPackLib ${CPACK_SRCS})
+target_link_libraries(CPackLib CMakeLib)
+
+if(APPLE)
+ add_executable(cmakexbuild cmakexbuild.cxx)
+ target_link_libraries(cmakexbuild CMakeLib)
+ add_executable(OSXScriptLauncher
+ CPack/OSXScriptLauncher.cxx)
+ target_link_libraries(OSXScriptLauncher cmsys)
+ target_link_libraries(OSXScriptLauncher "-framework CoreFoundation")
+endif()
+
+# Build CMake executable
+add_executable(cmake cmakemain.cxx cmcmd.cxx cmcmd.h)
+target_link_libraries(cmake CMakeLib)
+
+# Build CTest executable
+add_executable(ctest ctest.cxx)
+target_link_libraries(ctest CTestLib)
+
+# Build CPack executable
+add_executable(cpack CPack/cpack.cxx)
+target_link_libraries(cpack CPackLib)
+
+# Curses GUI
+if(BUILD_CursesDialog)
+ include(${CMake_SOURCE_DIR}/Source/CursesDialog/CMakeLists.txt)
+endif()
+
+# Qt GUI
+option(BUILD_QtDialog "Build Qt dialog for CMake" FALSE)
+if(BUILD_QtDialog)
+ add_subdirectory(QtDialog)
+endif()
+
+include (${CMake_BINARY_DIR}/Source/LocalUserOptions.cmake OPTIONAL)
+include (${CMake_SOURCE_DIR}/Source/LocalUserOptions.cmake OPTIONAL)
+
+install(TARGETS cmake ctest cpack DESTINATION bin)
+if(APPLE)
+ install(TARGETS cmakexbuild DESTINATION bin)
+endif()
+
+install(FILES cmCPluginAPI.h DESTINATION ${CMAKE_DATA_DIR}/include)
diff --git a/Source/CMakeSourceDir.txt.in b/Source/CMakeSourceDir.txt.in
new file mode 100644
index 0000000000..5e6a988c08
--- /dev/null
+++ b/Source/CMakeSourceDir.txt.in
@@ -0,0 +1 @@
+@CMake_SOURCE_DIR@
diff --git a/Source/CMakeVersion.bash b/Source/CMakeVersion.bash
new file mode 100755
index 0000000000..853b0ca288
--- /dev/null
+++ b/Source/CMakeVersion.bash
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+# Update the version component if it looks like a date or -f is given.
+if test "x$1" = "x-f"; then shift ; n='*' ; else n='\{8\}' ; fi
+if test "$#" -gt 0; then echo 1>&2 "usage: CMakeVersion.bash [-f]"; exit 1; fi
+sed -i -e '
+s/\(^set(CMake_VERSION_PATCH\) [0-9]'"$n"'\(.*\)/\1 '"$(date +%Y%m%d)"'\2/
+' "${BASH_SOURCE%/*}/CMakeVersion.cmake"
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
new file mode 100644
index 0000000000..b30e3ef55d
--- /dev/null
+++ b/Source/CMakeVersion.cmake
@@ -0,0 +1,5 @@
+# CMake version number components.
+set(CMake_VERSION_MAJOR 3)
+set(CMake_VERSION_MINOR 1)
+set(CMake_VERSION_PATCH 20141014)
+#set(CMake_VERSION_RC 1)
diff --git a/Source/CMakeVersionCompute.cmake b/Source/CMakeVersionCompute.cmake
new file mode 100644
index 0000000000..496d6cf1a4
--- /dev/null
+++ b/Source/CMakeVersionCompute.cmake
@@ -0,0 +1,20 @@
+# Load version number components.
+include(${CMake_SOURCE_DIR}/Source/CMakeVersion.cmake)
+
+# Releases define a small patch level.
+if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000)
+ set(CMake_VERSION_IS_RELEASE 1)
+ set(CMake_VERSION_SOURCE "")
+else()
+ set(CMake_VERSION_IS_RELEASE 0)
+ include(${CMake_SOURCE_DIR}/Source/CMakeVersionSource.cmake)
+endif()
+
+# Compute the full version string.
+set(CMake_VERSION ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH})
+if(CMake_VERSION_RC)
+ set(CMake_VERSION ${CMake_VERSION}-rc${CMake_VERSION_RC})
+endif()
+if(CMake_VERSION_SOURCE)
+ set(CMake_VERSION ${CMake_VERSION}-${CMake_VERSION_SOURCE})
+endif()
diff --git a/Source/CMakeVersionSource.cmake b/Source/CMakeVersionSource.cmake
new file mode 100644
index 0000000000..888f557fb1
--- /dev/null
+++ b/Source/CMakeVersionSource.cmake
@@ -0,0 +1,37 @@
+# Try to identify the current development source version.
+set(CMake_VERSION_SOURCE "")
+if(EXISTS ${CMake_SOURCE_DIR}/.git/HEAD)
+ find_program(GIT_EXECUTABLE NAMES git git.cmd)
+ mark_as_advanced(GIT_EXECUTABLE)
+ if(GIT_EXECUTABLE)
+ execute_process(
+ COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=4 HEAD
+ OUTPUT_VARIABLE head
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ WORKING_DIRECTORY ${CMake_SOURCE_DIR}
+ )
+ if(head)
+ set(CMake_VERSION_SOURCE "g${head}")
+ execute_process(
+ COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
+ WORKING_DIRECTORY ${CMake_SOURCE_DIR}
+ )
+ execute_process(
+ COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
+ OUTPUT_VARIABLE dirty
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ WORKING_DIRECTORY ${CMake_SOURCE_DIR}
+ )
+ if(dirty)
+ set(CMake_VERSION_SOURCE "${CMake_VERSION_SOURCE}-dirty")
+ endif()
+ endif()
+ endif()
+elseif(EXISTS ${CMake_SOURCE_DIR}/CVS/Repository)
+ file(READ ${CMake_SOURCE_DIR}/CVS/Repository repo)
+ set(branch "")
+ if("${repo}" MATCHES "\\.git/([^\r\n]*)")
+ set(branch "${CMAKE_MATCH_1}")
+ endif()
+ set(CMake_VERSION_SOURCE "cvs${branch}")
+endif()
diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx
new file mode 100644
index 0000000000..7f06e2d8a7
--- /dev/null
+++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx
@@ -0,0 +1,552 @@
+/*============================================================================
+ 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 "cmCPackIFWGenerator.h"
+
+#include "cmCPackIFWPackage.h"
+#include "cmCPackIFWInstaller.h"
+
+#include <CPack/cmCPackLog.h>
+#include <CPack/cmCPackComponentGroup.h>
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/Directory.hxx>
+#include <cmsys/RegularExpression.hxx>
+
+#include <cmGlobalGenerator.h>
+#include <cmLocalGenerator.h>
+#include <cmSystemTools.h>
+#include <cmMakefile.h>
+#include <cmGeneratedFileStream.h>
+#include <cmXMLSafe.h>
+
+//----------------------------------------------------------------------------
+cmCPackIFWGenerator::cmCPackIFWGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+cmCPackIFWGenerator::~cmCPackIFWGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+int cmCPackIFWGenerator::PackageFiles()
+{
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Configuration" << std::endl);
+
+ // Installer configuragion
+ Installer.GenerateInstallerFile();
+
+ // Packages configuration
+ Installer.GeneratePackageFiles();
+
+ std::string ifwTLD = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ std::string ifwTmpFile = ifwTLD;
+ ifwTmpFile += "/IFWOutput.log";
+
+ // Run repogen
+ if (!Installer.Repositories.empty())
+ {
+ std::string ifwCmd = RepoGen;
+ ifwCmd += " -c " + this->toplevel + "/config/config.xml";
+ ifwCmd += " -p " + this->toplevel + "/packages";
+
+ if(!PkgsDirsVector.empty())
+ {
+ for(std::vector<std::string>::iterator it = PkgsDirsVector.begin();
+ it != PkgsDirsVector.end(); ++it)
+ {
+ ifwCmd += " -p " + *it;
+ }
+ }
+
+ if (!OnlineOnly && !DownloadedPackages.empty())
+ {
+ ifwCmd += " -i ";
+ std::set<cmCPackIFWPackage*>::iterator it
+ = DownloadedPackages.begin();
+ ifwCmd += (*it)->Name;
+ ++it;
+ while(it != DownloadedPackages.end())
+ {
+ ifwCmd += "," + (*it)->Name;
+ ++it;
+ }
+ }
+ ifwCmd += " " + this->toplevel + "/repository";
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << ifwCmd
+ << std::endl);
+ std::string output;
+ int retVal = 1;
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Generate repository" << std::endl);
+ bool res = cmSystemTools::RunSingleCommand(
+ ifwCmd.c_str(), &output, &retVal, 0, this->GeneratorVerbose, 0);
+ if ( !res || retVal )
+ {
+ cmGeneratedFileStream ofs(ifwTmpFile.c_str());
+ ofs << "# Run command: " << ifwCmd << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running IFW command: "
+ << ifwCmd << std::endl
+ << "Please check " << ifwTmpFile << " for errors"
+ << std::endl);
+ return 0;
+ }
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- repository: " << this->toplevel
+ << "/repository generated" << std::endl);
+ }
+
+ // Run binary creator
+ {
+ std::string ifwCmd = BinCreator;
+ ifwCmd += " -c " + this->toplevel + "/config/config.xml";
+ ifwCmd += " -p " + this->toplevel + "/packages";
+
+ if(!PkgsDirsVector.empty())
+ {
+ for(std::vector<std::string>::iterator it = PkgsDirsVector.begin();
+ it != PkgsDirsVector.end(); ++it)
+ {
+ ifwCmd += " -p " + *it;
+ }
+ }
+
+ if (OnlineOnly)
+ {
+ ifwCmd += " --online-only";
+ }
+ else if (!DownloadedPackages.empty() && !Installer.Repositories.empty())
+ {
+ ifwCmd += " -e ";
+ std::set<cmCPackIFWPackage*>::iterator it
+ = DownloadedPackages.begin();
+ ifwCmd += (*it)->Name;
+ ++it;
+ while(it != DownloadedPackages.end())
+ {
+ ifwCmd += "," + (*it)->Name;
+ ++it;
+ }
+ }
+ else if (!DependentPackages.empty())
+ {
+ ifwCmd += " -i ";
+ // Binary
+ std::set<cmCPackIFWPackage*>::iterator bit = BinaryPackages.begin();
+ while(bit != BinaryPackages.end())
+ {
+ ifwCmd += (*bit)->Name + ",";
+ ++bit;
+ }
+ // Depend
+ DependenceMap::iterator it = DependentPackages.begin();
+ ifwCmd += it->second.Name;
+ ++it;
+ while(it != DependentPackages.end())
+ {
+ ifwCmd += "," + it->second.Name;
+ ++it;
+ }
+ }
+ // TODO: set correct name for multipackages
+ if (this->packageFileNames.size() > 0)
+ {
+ ifwCmd += " " + packageFileNames[0];
+ }
+ else
+ {
+ ifwCmd += " installer";
+ }
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << ifwCmd
+ << std::endl);
+ std::string output;
+ int retVal = 1;
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Generate package" << std::endl);
+ bool res = cmSystemTools::RunSingleCommand(
+ ifwCmd.c_str(), &output, &retVal, 0, this->GeneratorVerbose, 0);
+ if ( !res || retVal )
+ {
+ cmGeneratedFileStream ofs(ifwTmpFile.c_str());
+ ofs << "# Run command: " << ifwCmd << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running IFW command: "
+ << ifwCmd << std::endl
+ << "Please check " << ifwTmpFile << " for errors"
+ << std::endl);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+const char *cmCPackIFWGenerator::GetPackagingInstallPrefix()
+{
+ const char *defPrefix = cmCPackGenerator::GetPackagingInstallPrefix();
+
+ std::string tmpPref = defPrefix ? defPrefix : "";
+
+ if(this->Components.empty())
+ {
+ tmpPref += "packages/" + GetRootPackageName() + "/data";
+ }
+
+ this->SetOption("CPACK_IFW_PACKAGING_INSTALL_PREFIX", tmpPref.c_str());
+
+ return this->GetOption("CPACK_IFW_PACKAGING_INSTALL_PREFIX");
+}
+
+//----------------------------------------------------------------------------
+const char *cmCPackIFWGenerator::GetOutputExtension()
+{
+ const char *suffix = this->GetOption("CMAKE_EXECUTABLE_SUFFIX");
+ return suffix ? suffix : cmCPackGenerator::GetOutputExtension();
+}
+
+//----------------------------------------------------------------------------
+int cmCPackIFWGenerator::InitializeInternal()
+{
+ // Search Qt Installer Framework tools
+
+ const std::string BinCreatorOpt = "CPACK_IFW_BINARYCREATOR_EXECUTABLE";
+ const std::string RepoGenOpt = "CPACK_IFW_REPOGEN_EXECUTABLE";
+
+ if(!this->IsSet(BinCreatorOpt) ||
+ !this->IsSet(RepoGenOpt))
+ {
+ this->ReadListFile("CPackIFW.cmake");
+ }
+
+ // Look 'binarycreator' executable (needs)
+
+ const char *BinCreatorStr = this->GetOption(BinCreatorOpt);
+ if(!BinCreatorStr || cmSystemTools::IsNOTFOUND(BinCreatorStr))
+ {
+ BinCreator = "";
+ }
+ else
+ {
+ BinCreator = BinCreatorStr;
+ }
+
+ if (BinCreator.empty())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find QtIFW compiler \"binarycreator\": "
+ "likely it is not installed, or not in your PATH"
+ << std::endl);
+ return 0;
+ }
+
+ // Look 'repogen' executable (optional)
+
+ const char *RepoGenStr = this->GetOption(RepoGenOpt);
+ if(!RepoGenStr || cmSystemTools::IsNOTFOUND(RepoGenStr))
+ {
+ RepoGen = "";
+ }
+ else
+ {
+ RepoGen = RepoGenStr;
+ }
+
+ // Variables that Change Behavior
+
+ // Resolve duplicate names
+ ResolveDuplicateNames = this->IsOn("CPACK_IFW_RESOLVE_DUPLICATE_NAMES");
+
+ // Additional packages dirs
+ PkgsDirsVector.clear();
+ if(const char* dirs = this->GetOption("CPACK_IFW_PACKAGES_DIRECTORIES"))
+ {
+ cmSystemTools::ExpandListArgument(dirs,
+ PkgsDirsVector);
+ }
+
+ // Installer
+ Installer.Generator = this;
+ Installer.ConfigureFromOptions();
+
+ if (const char* ifwDownloadAll =
+ this->GetOption("CPACK_IFW_DOWNLOAD_ALL"))
+ {
+ OnlineOnly = cmSystemTools::IsOn(ifwDownloadAll);
+ }
+ else if (const char* cpackDownloadAll =
+ this->GetOption("CPACK_DOWNLOAD_ALL"))
+ {
+ OnlineOnly = cmSystemTools::IsOn(cpackDownloadAll);
+ }
+ else
+ {
+ OnlineOnly = false;
+ }
+
+ if (!Installer.Repositories.empty() && RepoGen.empty()) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find QtIFW repository generator \"repogen\": "
+ "likely it is not installed, or not in your PATH"
+ << std::endl);
+ return 0;
+ }
+
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmCPackIFWGenerator::GetComponentInstallDirNameSuffix(
+ const std::string& componentName)
+{
+ const std::string prefix = "packages/";
+ const std::string suffix = "/data";
+
+ if (componentPackageMethod == ONE_PACKAGE) {
+ return std::string(prefix + GetRootPackageName() + suffix);
+ }
+
+ return prefix
+ + GetComponentPackageName(&Components[componentName])
+ + suffix;
+}
+
+//----------------------------------------------------------------------------
+cmCPackComponent*
+cmCPackIFWGenerator::GetComponent(const std::string &projectName,
+ const std::string &componentName)
+{
+ ComponentsMap::iterator cit = Components.find(componentName);
+ if ( cit != Components.end() ) return &(cit->second);
+
+ cmCPackComponent* component
+ = cmCPackGenerator::GetComponent(projectName, componentName);
+ if(!component) return component;
+
+ std::string name = GetComponentPackageName(component);
+ PackagesMap::iterator pit = Packages.find(name);
+ if(pit != Packages.end()) return component;
+
+ cmCPackIFWPackage *package = &Packages[name];
+ package->Name = name;
+ package->Generator = this;
+ if(package->ConfigureFromComponent(component))
+ {
+ package->Installer = &Installer;
+ Installer.Packages.insert(
+ std::pair<std::string, cmCPackIFWPackage*>(
+ name, package));
+ ComponentPackages.insert(
+ std::pair<cmCPackComponent*, cmCPackIFWPackage*>(
+ component, package));
+ if(component->IsDownloaded)
+ {
+ DownloadedPackages.insert(package);
+ }
+ else
+ {
+ BinaryPackages.insert(package);
+ }
+ }
+ else
+ {
+ Packages.erase(name);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot configure package \"" << name <<
+ "\" for component \"" << component->Name << "\""
+ << std::endl);
+ }
+
+ return component;
+}
+
+//----------------------------------------------------------------------------
+cmCPackComponentGroup*
+cmCPackIFWGenerator::GetComponentGroup(const std::string &projectName,
+ const std::string &groupName)
+{
+ cmCPackComponentGroup* group
+ = cmCPackGenerator::GetComponentGroup(projectName, groupName);
+ if(!group) return group;
+
+ std::string name = GetGroupPackageName(group);
+ PackagesMap::iterator pit = Packages.find(name);
+ if(pit != Packages.end()) return group;
+
+ cmCPackIFWPackage *package = &Packages[name];
+ package->Name = name;
+ package->Generator = this;
+ if(package->ConfigureFromGroup(group))
+ {
+ package->Installer = &Installer;
+ Installer.Packages.insert(
+ std::pair<std::string, cmCPackIFWPackage*>(
+ name, package));
+ GroupPackages.insert(
+ std::pair<cmCPackComponentGroup*, cmCPackIFWPackage*>(
+ group, package));
+ BinaryPackages.insert(package);
+ }
+ else
+ {
+ Packages.erase(name);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot configure package \"" << name <<
+ "\" for component group \"" << group->Name << "\""
+ << std::endl);
+ }
+ return group;
+}
+
+//----------------------------------------------------------------------------
+enum cmCPackGenerator::CPackSetDestdirSupport
+cmCPackIFWGenerator::SupportsSetDestdir() const
+{
+ return cmCPackGenerator::SETDESTDIR_SHOULD_NOT_BE_USED;
+}
+
+//----------------------------------------------------------------------------
+bool cmCPackIFWGenerator::SupportsAbsoluteDestination() const
+{
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmCPackIFWGenerator::SupportsComponentInstallation() const
+{
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmCPackIFWGenerator::IsOnePackage() const
+{
+ return componentPackageMethod == ONE_PACKAGE;
+}
+
+//----------------------------------------------------------------------------
+std::string cmCPackIFWGenerator::GetRootPackageName()
+{
+ // Default value
+ std::string name = "root";
+ if (const char* optIFW_PACKAGE_GROUP =
+ this->GetOption("CPACK_IFW_PACKAGE_GROUP"))
+ {
+ // Configure from root group
+ cmCPackIFWPackage package;
+ package.Generator = this;
+ package.ConfigureFromGroup(optIFW_PACKAGE_GROUP);
+ name = package.Name;
+ }
+ else if (const char* optIFW_PACKAGE_NAME =
+ this->GetOption("CPACK_IFW_PACKAGE_NAME"))
+ {
+ // Configure from root package name
+ name = optIFW_PACKAGE_NAME;
+ }
+ else if (const char* optPACKAGE_NAME =
+ this->GetOption("CPACK_PACKAGE_NAME"))
+ {
+ // Configure from package name
+ name = optPACKAGE_NAME;
+ }
+ return name;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmCPackIFWGenerator::GetGroupPackageName(cmCPackComponentGroup *group) const
+{
+ std::string name;
+ if (!group) return name;
+ if (cmCPackIFWPackage* package = GetGroupPackage(group))
+ {
+ return package->Name;
+ }
+ const char* option = GetOption(
+ "CPACK_IFW_COMPONENT_GROUP_"
+ + cmsys::SystemTools::UpperCase(group->Name)
+ + "_NAME");
+ name = option ? option : group->Name;
+ if(group->ParentGroup)
+ {
+ cmCPackIFWPackage* package = GetGroupPackage(group->ParentGroup);
+ bool dot = !ResolveDuplicateNames;
+ if(dot && name.substr(0, package->Name.size()) == package->Name)
+ {
+ dot = false;
+ }
+ if(dot)
+ {
+ name = package->Name + "." + name;
+ }
+ }
+ return name;
+}
+
+//----------------------------------------------------------------------------
+std::string cmCPackIFWGenerator::GetComponentPackageName(
+ cmCPackComponent *component) const
+{
+ std::string name;
+ if (!component) return name;
+ if (cmCPackIFWPackage* package = GetComponentPackage(component))
+ {
+ return package->Name;
+ }
+ std::string prefix = "CPACK_IFW_COMPONENT_"
+ + cmsys::SystemTools::UpperCase(component->Name)
+ + "_";
+ const char* option = GetOption(prefix + "NAME");
+ name = option ? option : component->Name;
+ if(component->Group)
+ {
+ cmCPackIFWPackage* package = GetGroupPackage(component->Group);
+ if((componentPackageMethod == ONE_PACKAGE_PER_GROUP)
+ || IsOn(prefix + "COMMON"))
+ {
+ return package->Name;
+ }
+ bool dot = !ResolveDuplicateNames;
+ if(dot && name.substr(0, package->Name.size()) == package->Name)
+ {
+ dot = false;
+ }
+ if(dot)
+ {
+ name = package->Name + "." + name;
+ }
+ }
+ return name;
+}
+
+//----------------------------------------------------------------------------
+cmCPackIFWPackage* cmCPackIFWGenerator::GetGroupPackage(
+ cmCPackComponentGroup *group) const
+{
+ std::map<cmCPackComponentGroup*, cmCPackIFWPackage*>::const_iterator pit
+ = GroupPackages.find(group);
+ return pit != GroupPackages.end() ? pit->second : 0;
+}
+
+//----------------------------------------------------------------------------
+cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage(
+ cmCPackComponent *component) const
+{
+ std::map<cmCPackComponent*, cmCPackIFWPackage*>::const_iterator pit
+ = ComponentPackages.find(component);
+ return pit != ComponentPackages.end() ? pit->second : 0;
+}
diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.h b/Source/CPack/IFW/cmCPackIFWGenerator.h
new file mode 100644
index 0000000000..1d4d67bf17
--- /dev/null
+++ b/Source/CPack/IFW/cmCPackIFWGenerator.h
@@ -0,0 +1,135 @@
+/*============================================================================
+ 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 cmCPackIFWGenerator_h
+#define cmCPackIFWGenerator_h
+
+#include <CPack/cmCPackGenerator.h>
+
+#include "cmCPackIFWPackage.h"
+#include "cmCPackIFWInstaller.h"
+
+/** \class cmCPackIFWGenerator
+ * \brief A generator for Qt Installer Framework tools
+ *
+ * http://qt-project.org/doc/qtinstallerframework/index.html
+ */
+class cmCPackIFWGenerator : public cmCPackGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackIFWGenerator, cmCPackGenerator);
+
+ typedef std::map<std::string, cmCPackIFWPackage> PackagesMap;
+ typedef std::map<std::string, cmCPackComponent> ComponentsMap;
+ typedef std::map<std::string, cmCPackComponentGroup> ComponentGoupsMap;
+ typedef std::map<std::string, cmCPackIFWPackage::DependenceStruct>
+ DependenceMap;
+
+ /**
+ * Construct IFW generator
+ */
+ cmCPackIFWGenerator();
+
+ /**
+ * Destruct IFW generator
+ */
+ virtual ~cmCPackIFWGenerator();
+
+protected: // cmCPackGenerator reimplementation
+
+ /**
+ * @brief Initialize generator
+ * @return 0 on failure
+ */
+ virtual int InitializeInternal();
+ virtual int PackageFiles();
+ virtual const char* GetPackagingInstallPrefix();
+
+ /**
+ * @brief Extension of binary installer
+ * @return Executable suffix or value from default implementation
+ */
+ virtual const char* GetOutputExtension();
+
+ virtual std::string GetComponentInstallDirNameSuffix(
+ const std::string& componentName);
+
+ /**
+ * @brief Get Component
+ * @param projectName Project name
+ * @param componentName Component name
+ *
+ * This method calls the base implementation.
+ *
+ * @return Pointer to component
+ */
+ virtual cmCPackComponent* GetComponent(
+ const std::string& projectName,
+ const std::string& componentName);
+
+ /**
+ * @brief Get group of component
+ * @param projectName Project name
+ * @param groupName Component group name
+ *
+ * This method calls the base implementation.
+ *
+ * @return Pointer to component group
+ */
+ virtual cmCPackComponentGroup* GetComponentGroup(
+ const std::string& projectName,
+ const std::string& groupName);
+
+ enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const;
+ virtual bool SupportsAbsoluteDestination() const;
+ virtual bool SupportsComponentInstallation() const;
+
+protected: // Methods
+
+ bool IsOnePackage() const;
+
+ std::string GetRootPackageName();
+
+ std::string GetGroupPackageName(cmCPackComponentGroup *group) const;
+ std::string GetComponentPackageName(cmCPackComponent *component) const;
+
+ cmCPackIFWPackage* GetGroupPackage(cmCPackComponentGroup *group) const;
+ cmCPackIFWPackage* GetComponentPackage(cmCPackComponent *component) const;
+
+protected: // Data
+
+ friend class cmCPackIFWPackage;
+ friend class cmCPackIFWInstaller;
+
+ // Installer
+ cmCPackIFWInstaller Installer;
+ // Collection of packages
+ PackagesMap Packages;
+ // Collection of binary packages
+ std::set<cmCPackIFWPackage*> BinaryPackages;
+ // Collection of downloaded packages
+ std::set<cmCPackIFWPackage*> DownloadedPackages;
+ // Dependent packages
+ DependenceMap DependentPackages;
+ std::map<cmCPackComponent*, cmCPackIFWPackage*> ComponentPackages;
+ std::map<cmCPackComponentGroup*, cmCPackIFWPackage*> GroupPackages;
+
+private:
+ std::string RepoGen;
+ std::string BinCreator;
+
+ bool OnlineOnly;
+ bool ResolveDuplicateNames;
+ std::vector<std::string> PkgsDirsVector;
+};
+
+#endif
diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.cxx b/Source/CPack/IFW/cmCPackIFWInstaller.cxx
new file mode 100644
index 0000000000..0644ecbd39
--- /dev/null
+++ b/Source/CPack/IFW/cmCPackIFWInstaller.cxx
@@ -0,0 +1,406 @@
+/*============================================================================
+ 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 "cmCPackIFWInstaller.h"
+
+#include "cmCPackIFWGenerator.h"
+
+#include <CPack/cmCPackLog.h>
+
+#include <cmGeneratedFileStream.h>
+#include <cmXMLSafe.h>
+
+#ifdef cmCPackLogger
+# undef cmCPackLogger
+#endif
+#define cmCPackLogger(logType, msg) \
+ do { \
+ cmOStringStream cmCPackLog_msg; \
+ cmCPackLog_msg << msg; \
+ if(Generator) { \
+ Generator->Logger->Log(logType, __FILE__, __LINE__, \
+ cmCPackLog_msg.str().c_str()); \
+ } \
+ } while ( 0 )
+
+//----------------------------------------------------------------------------
+cmCPackIFWInstaller::cmCPackIFWInstaller() :
+ Generator(0)
+{
+}
+
+//----------------------------------------------------------------------------
+const char *cmCPackIFWInstaller::GetOption(const std::string &op) const
+{
+ return Generator ? Generator->GetOption(op) : 0;
+}
+
+//----------------------------------------------------------------------------
+bool cmCPackIFWInstaller::IsOn(const std::string &op) const
+{
+ return Generator ? Generator->IsOn(op) : false;
+}
+
+//----------------------------------------------------------------------------
+void cmCPackIFWInstaller::ConfigureFromOptions()
+{
+ // Name;
+ if (const char* optIFW_PACKAGE_NAME =
+ this->GetOption("CPACK_IFW_PACKAGE_NAME"))
+ {
+ Name = optIFW_PACKAGE_NAME;
+ }
+ else if (const char* optPACKAGE_NAME =
+ this->GetOption("CPACK_PACKAGE_NAME"))
+ {
+ Name = optPACKAGE_NAME;
+ }
+ else
+ {
+ Name = "Your package";
+ }
+
+ // Title;
+ if (const char* optIFW_PACKAGE_TITLE =
+ GetOption("CPACK_IFW_PACKAGE_TITLE"))
+ {
+ Title = optIFW_PACKAGE_TITLE;
+ }
+ else if (const char* optPACKAGE_DESCRIPTION_SUMMARY =
+ GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY"))
+ {
+ Title = optPACKAGE_DESCRIPTION_SUMMARY;
+ }
+ else
+ {
+ Title = "Your package description";
+ }
+
+ // Version;
+ if (const char* option = GetOption("CPACK_PACKAGE_VERSION"))
+ {
+ Version = option;
+ }
+ else
+ {
+ Version = "1.0.0";
+ }
+
+ // Publisher
+ if(const char* optIFW_PACKAGE_PUBLISHER =
+ GetOption("CPACK_IFW_PACKAGE_PUBLISHER"))
+ {
+ Publisher = optIFW_PACKAGE_PUBLISHER;
+ }
+ else if(const char* optPACKAGE_VENDOR = GetOption("CPACK_PACKAGE_VENDOR"))
+ {
+ Publisher = optPACKAGE_VENDOR;
+ }
+
+ // ProductUrl
+ if(const char* option = GetOption("CPACK_IFW_PRODUCT_URL"))
+ {
+ ProductUrl = option;
+ }
+
+ // ApplicationIcon
+ if(const char* option = GetOption("CPACK_IFW_PACKAGE_ICON"))
+ {
+ if(cmSystemTools::FileExists(option))
+ {
+ InstallerApplicationIcon = option;
+ }
+ else
+ {
+ // TODO: implement warning
+ }
+ }
+
+ // WindowIcon
+ if(const char* option = GetOption("CPACK_IFW_PACKAGE_WINDOW_ICON"))
+ {
+ if(cmSystemTools::FileExists(option))
+ {
+ InstallerWindowIcon = option;
+ }
+ else
+ {
+ // TODO: implement warning
+ }
+ }
+
+ // Logo
+ if(const char* option = GetOption("CPACK_IFW_PACKAGE_LOGO"))
+ {
+ if(cmSystemTools::FileExists(option))
+ {
+ Logo = option;
+ }
+ else
+ {
+ // TODO: implement warning
+ }
+ }
+
+ // Default target directory for installation
+ if (const char* optIFW_TARGET_DIRECTORY =
+ GetOption("CPACK_IFW_TARGET_DIRECTORY"))
+ {
+ TargetDir = optIFW_TARGET_DIRECTORY;
+ }
+ else if (const char *optPACKAGE_INSTALL_DIRECTORY =
+ GetOption("CPACK_PACKAGE_INSTALL_DIRECTORY"))
+ {
+ TargetDir = "@ApplicationsDir@/";
+ TargetDir += optPACKAGE_INSTALL_DIRECTORY;
+ }
+ else
+ {
+ TargetDir = "@RootDir@/usr/local";
+ }
+
+ // Default target directory for installation with administrator rights
+ if (const char* option = GetOption("CPACK_IFW_ADMIN_TARGET_DIRECTORY"))
+ {
+ AdminTargetDir = option;
+ }
+
+ // Repositories
+ Repositories.clear();
+ RepositoryStruct Repo;
+ if (const char *site = this->GetOption("CPACK_DOWNLOAD_SITE"))
+ {
+ Repo.Url = site;
+ Repositories.push_back(Repo);
+ }
+ if(const char *RepoAllStr = this->GetOption("CPACK_IFW_REPOSITORIES_ALL"))
+ {
+ std::vector<std::string> RepoAllVector;
+ cmSystemTools::ExpandListArgument(RepoAllStr,
+ RepoAllVector);
+ for(std::vector<std::string>::iterator
+ rit = RepoAllVector.begin(); rit != RepoAllVector.end(); ++rit)
+ {
+ std::string prefix = "CPACK_IFW_REPOSITORY_"
+ + cmsys::SystemTools::UpperCase(*rit)
+ + "_";
+ // Url
+ if (const char* url = GetOption(prefix + "URL"))
+ {
+ Repo.Url = url;
+ }
+ else
+ {
+ Repo.Url = "";
+ }
+ // Enabled
+ if (IsOn(prefix + "DISABLED"))
+ {
+ Repo.Enabled = "0";
+ }
+ else
+ {
+ Repo.Enabled = "";
+ }
+ // Username
+ if (const char* username = GetOption(prefix + "USERNAME"))
+ {
+ Repo.Username = username;
+ }
+ else
+ {
+ Repo.Username = "";
+ }
+ // Password
+ if (const char* password = GetOption(prefix + "PASSWORD"))
+ {
+ Repo.Password = password;
+ }
+ else
+ {
+ Repo.Password = "";
+ }
+ // DisplayName
+ if (const char* displayName = GetOption(prefix + "DISPLAY_NAME"))
+ {
+ Repo.DisplayName = displayName;
+ }
+ else
+ {
+ Repo.DisplayName = "";
+ }
+
+ if(!Repo.Url.empty())
+ {
+ Repositories.push_back(Repo);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCPackIFWInstaller::GenerateInstallerFile()
+{
+ // Lazy directory initialization
+ if(Directory.empty() && Generator)
+ {
+ Directory = Generator->toplevel;
+ }
+
+ // Output stream
+ cmGeneratedFileStream xout((Directory + "/config/config.xml").data());
+
+ xout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
+ xout << "<Installer>" << std::endl;
+
+ xout << " <Name>" << cmXMLSafe(Name).str() << "</Name>" << std::endl;
+
+ xout << " <Version>" << Version << "</Version>" << std::endl;
+
+ xout << " <Title>" << cmXMLSafe(Title).str() << "</Title>"
+ << std::endl;
+
+ if(!Publisher.empty())
+ {
+ xout << " <Publisher>" << cmXMLSafe(Publisher).str()
+ << "</Publisher>" << std::endl;
+ }
+
+ if(!ProductUrl.empty())
+ {
+ xout << " <ProductUrl>" << ProductUrl << "</ProductUrl>" << std::endl;
+ }
+
+ // ApplicationIcon
+ if(!InstallerApplicationIcon.empty())
+ {
+ std::string name =
+ cmSystemTools::GetFilenameName(InstallerApplicationIcon);
+ std::string path = Directory + "/config/" + name;
+ name = cmSystemTools::GetFilenameWithoutExtension(name);
+ cmsys::SystemTools::CopyFileIfDifferent(
+ InstallerApplicationIcon.data(), path.data());
+ xout << " <InstallerApplicationIcon>" << name
+ << "</InstallerApplicationIcon>" << std::endl;
+ }
+
+ // WindowIcon
+ if(!InstallerWindowIcon.empty())
+ {
+ std::string name = cmSystemTools::GetFilenameName(InstallerWindowIcon);
+ std::string path = Directory + "/config/" + name;
+ cmsys::SystemTools::CopyFileIfDifferent(
+ InstallerWindowIcon.data(), path.data());
+ xout << " <InstallerWindowIcon>" << name
+ << "</InstallerWindowIcon>" << std::endl;
+ }
+
+ // Logo
+ if(!Logo.empty())
+ {
+ std::string name = cmSystemTools::GetFilenameName(Logo);
+ std::string path = Directory + "/config/" + name;
+ cmsys::SystemTools::CopyFileIfDifferent(Logo.data(), path.data());
+ xout << " <Logo>" << name << "</Logo>" << std::endl;
+ }
+
+ if(!TargetDir.empty())
+ {
+ xout << " <TargetDir>" << TargetDir << "</TargetDir>" << std::endl;
+ }
+
+ if(!AdminTargetDir.empty())
+ {
+ xout << " <AdminTargetDir>" << AdminTargetDir
+ << "</AdminTargetDir>" << std::endl;
+ }
+
+ // Remote repositories
+ if (!Repositories.empty())
+ {
+ xout << " <RemoteRepositories>" << std::endl;
+ for(std::vector<RepositoryStruct>::iterator
+ rit = Repositories.begin(); rit != Repositories.end(); ++rit)
+ {
+ xout << " <Repository>" << std::endl;
+ // Url
+ xout << " <Url>" << rit->Url
+ << "</Url>" << std::endl;
+ // Enabled
+ if(!rit->Enabled.empty())
+ {
+ xout << " <Enabled>" << rit->Enabled
+ << "</Enabled>" << std::endl;
+ }
+ // Username
+ if(!rit->Username.empty())
+ {
+ xout << " <Username>" << rit->Username
+ << "</Username>" << std::endl;
+ }
+ // Password
+ if(!rit->Password.empty())
+ {
+ xout << " <Password>" << rit->Password
+ << "</Password>" << std::endl;
+ }
+ // DisplayName
+ if(!rit->DisplayName.empty())
+ {
+ xout << " <DisplayName>" << rit->DisplayName
+ << "</DisplayName>" << std::endl;
+ }
+ xout << " </Repository>" << std::endl;
+ }
+ xout << " </RemoteRepositories>" << std::endl;
+ }
+
+ // CPack IFW default policy
+ xout << " <!-- CPack IFW default policy -->" << std::endl;
+ xout << " <AllowNonAsciiCharacters>true</AllowNonAsciiCharacters>"
+ << std::endl;
+ xout << " <AllowSpaceInPath>true</AllowSpaceInPath>" << std::endl;
+
+ xout << "</Installer>" << std::endl;
+}
+
+//----------------------------------------------------------------------------
+void cmCPackIFWInstaller::GeneratePackageFiles()
+{
+ if (Packages.empty() || Generator->IsOnePackage())
+ {
+ // Generate default package
+ cmCPackIFWPackage package;
+ package.Generator = Generator;
+ package.Installer = this;
+ // Check package group
+ if (const char* option = GetOption("CPACK_IFW_PACKAGE_GROUP"))
+ {
+ package.ConfigureFromGroup(option);
+ package.ForcedInstallation = "true";
+ }
+ else
+ {
+ package.ConfigureFromOptions();
+ }
+ package.GeneratePackageFile();
+ return;
+ }
+
+ // Generate packages meta information
+ for(PackagesMap::iterator pit = Packages.begin();
+ pit != Packages.end(); ++pit)
+ {
+ cmCPackIFWPackage* package = pit->second;
+ package->GeneratePackageFile();
+ }
+}
diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.h b/Source/CPack/IFW/cmCPackIFWInstaller.h
new file mode 100644
index 0000000000..5824d334a8
--- /dev/null
+++ b/Source/CPack/IFW/cmCPackIFWInstaller.h
@@ -0,0 +1,95 @@
+/*============================================================================
+ 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 cmCPackIFWInstaller_h
+#define cmCPackIFWInstaller_h
+
+#include <cmStandardIncludes.h>
+
+class cmCPackIFWPackage;
+class cmCPackIFWGenerator;
+
+/** \class cmCPackIFWInstaller
+ * \brief A binary installer to be created CPack IFW generator
+ */
+class cmCPackIFWInstaller
+{
+public: // Types
+
+ typedef std::map<std::string, cmCPackIFWPackage*> PackagesMap;
+
+ struct RepositoryStruct
+ {
+ std::string Url;
+ std::string Enabled;
+ std::string Username;
+ std::string Password;
+ std::string DisplayName;
+ };
+
+public: // Constructor
+
+ /**
+ * Construct installer
+ */
+ cmCPackIFWInstaller();
+
+public: // Configuration
+
+ /// Name of the product being installed
+ std::string Name;
+
+ /// Version number of the product being installed
+ std::string Version;
+
+ /// Name of the installer as displayed on the title bar
+ std::string Title;
+
+ /// Publisher of the software (as shown in the Windows Control Panel)
+ std::string Publisher;
+
+ /// URL to a page that contains product information on your web site
+ std::string ProductUrl;
+
+ /// Filename for a custom installer icon
+ std::string InstallerApplicationIcon;
+
+ /// Filename for a custom window icon
+ std::string InstallerWindowIcon;
+
+ /// Filename for a logo
+ std::string Logo;
+
+ /// Default target directory for installation
+ std::string TargetDir;
+
+ /// Default target directory for installation with administrator rights
+ std::string AdminTargetDir;
+
+public: // Internal implementation
+
+ const char* GetOption(const std::string& op) const;
+ bool IsOn(const std::string& op) const;
+
+ void ConfigureFromOptions();
+
+ void GenerateInstallerFile();
+
+ void GeneratePackageFiles();
+
+ cmCPackIFWGenerator* Generator;
+ PackagesMap Packages;
+ std::vector<RepositoryStruct> Repositories;
+ std::string Directory;
+};
+
+#endif // cmCPackIFWInstaller_h
diff --git a/Source/CPack/IFW/cmCPackIFWPackage.cxx b/Source/CPack/IFW/cmCPackIFWPackage.cxx
new file mode 100644
index 0000000000..3c45639ef6
--- /dev/null
+++ b/Source/CPack/IFW/cmCPackIFWPackage.cxx
@@ -0,0 +1,540 @@
+/*============================================================================
+ 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 "cmCPackIFWPackage.h"
+
+#include "cmCPackIFWGenerator.h"
+
+#include <CPack/cmCPackLog.h>
+
+#include <cmGeneratedFileStream.h>
+#include <cmTimestamp.h>
+
+//----------------------------------------------------------------- Logger ---
+#ifdef cmCPackLogger
+# undef cmCPackLogger
+#endif
+#define cmCPackLogger(logType, msg) \
+ do { \
+ cmOStringStream cmCPackLog_msg; \
+ cmCPackLog_msg << msg; \
+ if(Generator) { \
+ Generator->Logger->Log(logType, __FILE__, __LINE__, \
+ cmCPackLog_msg.str().c_str()); \
+ } \
+ } while ( 0 )
+
+//---------------------------------------------------------- CompareStruct ---
+cmCPackIFWPackage::CompareStruct::CompareStruct() :
+ Type(CompareNone)
+{
+}
+
+//------------------------------------------------------- DependenceStruct ---
+cmCPackIFWPackage::DependenceStruct::DependenceStruct()
+{
+}
+
+//----------------------------------------------------------------------------
+cmCPackIFWPackage::DependenceStruct::DependenceStruct(
+ const std::string &dependence)
+{
+ // Search compare section
+ size_t pos = std::string::npos;
+ if((pos = dependence.find("<=")) != std::string::npos)
+ {
+ Compare.Type = CompareLessOrEqual;
+ Compare.Value = dependence.substr(pos + 2);
+ }
+ else if((pos = dependence.find(">=")) != std::string::npos)
+ {
+ Compare.Type = CompareGreaterOrEqual;
+ Compare.Value = dependence.substr(pos + 2);
+ }
+ else if((pos = dependence.find("<")) != std::string::npos)
+ {
+ Compare.Type = CompareLess;
+ Compare.Value = dependence.substr(pos + 1);
+ }
+ else if((pos = dependence.find("=")) != std::string::npos)
+ {
+ Compare.Type = CompareEqual;
+ Compare.Value = dependence.substr(pos + 1);
+ }
+ else if((pos = dependence.find(">")) != std::string::npos)
+ {
+ Compare.Type = CompareGreater;
+ Compare.Value = dependence.substr(pos + 1);
+ }
+ Name = pos == std::string::npos ? dependence : dependence.substr(0, pos);
+}
+
+//----------------------------------------------------------------------------
+std::string cmCPackIFWPackage::DependenceStruct::NameWithCompare() const
+{
+ if (Compare.Type == CompareNone) return Name;
+
+ std::string result = Name;
+
+ if (Compare.Type == CompareLessOrEqual)
+ {
+ result += "<=";
+ }
+ else if (Compare.Type == CompareGreaterOrEqual)
+ {
+ result += ">=";
+ }
+ else if (Compare.Type == CompareLess)
+ {
+ result += "<";
+ }
+ else if (Compare.Type == CompareEqual)
+ {
+ result += "=";
+ }
+ else if (Compare.Type == CompareGreater)
+ {
+ result += ">";
+ }
+
+ result += Compare.Value;
+
+ return result;
+}
+
+//------------------------------------------------------ cmCPackIFWPackage ---
+cmCPackIFWPackage::cmCPackIFWPackage() :
+ Generator(0),
+ Installer(0)
+{
+}
+
+//----------------------------------------------------------------------------
+const char *cmCPackIFWPackage::GetOption(const std::string &op) const
+{
+ const char *option = Generator ? Generator->GetOption(op) : 0;
+ return option && *option ? option : 0;
+}
+
+//----------------------------------------------------------------------------
+bool cmCPackIFWPackage::IsOn(const std::string &op) const
+{
+ return Generator ? Generator->IsOn(op) : false;
+}
+
+//----------------------------------------------------------------------------
+std::string cmCPackIFWPackage::GetComponentName(cmCPackComponent *component)
+{
+ if (!component) return "";
+ const char* option = GetOption(
+ "CPACK_IFW_COMPONENT_"
+ + cmsys::SystemTools::UpperCase(component->Name)
+ + "_NAME");
+ return option ? option : component->Name;
+}
+
+//----------------------------------------------------------------------------
+void cmCPackIFWPackage::DefaultConfiguration()
+{
+ DisplayName = "";
+ Description = "";
+ Version = "";
+ ReleaseDate = "";
+ Script = "";
+ Licenses.clear();
+ SortingPriority = "";
+ Default = "";
+ Virtual = "";
+ ForcedInstallation = "";
+}
+
+//----------------------------------------------------------------------------
+// Defaul configuration (all in one package)
+int cmCPackIFWPackage::ConfigureFromOptions()
+{
+ // Restore defaul configuration
+ DefaultConfiguration();
+
+ // Name
+ Name = Generator->GetRootPackageName();
+
+ // Display name
+ if (const char *option = this->GetOption("CPACK_PACKAGE_NAME"))
+ {
+ DisplayName = option;
+ }
+ else
+ {
+ DisplayName = "Your package";
+ }
+
+ // Description
+ if (const char* option =
+ this->GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY"))
+ {
+ Description = option;
+ }
+ else
+ {
+ Description = "Your package description";
+ }
+
+ // Version
+ if(const char* option = GetOption("CPACK_PACKAGE_VERSION"))
+ {
+ Version = option;
+ }
+ else
+ {
+ Version = "1.0.0";
+ }
+
+ ForcedInstallation = "true";
+
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent *component)
+{
+ if(!component) return 0;
+
+ // Restore defaul configuration
+ DefaultConfiguration();
+
+ std::string prefix = "CPACK_IFW_COMPONENT_"
+ + cmsys::SystemTools::UpperCase(component->Name)
+ + "_";
+
+ // Display name
+ DisplayName = component->DisplayName;
+
+ // Description
+ Description = component->Description;
+
+ // Version
+ if(const char* optVERSION = GetOption(prefix + "VERSION"))
+ {
+ Version = optVERSION;
+ }
+ else if(const char* optPACKAGE_VERSION =
+ GetOption("CPACK_PACKAGE_VERSION"))
+ {
+ Version = optPACKAGE_VERSION;
+ }
+ else
+ {
+ Version = "1.0.0";
+ }
+
+ // Script
+ if (const char* option = GetOption(prefix + "SCRIPT"))
+ {
+ Script = option;
+ }
+
+ // CMake dependencies
+ if (!component->Dependencies.empty())
+ {
+ std::vector<cmCPackComponent*>::iterator dit;
+ for(dit = component->Dependencies.begin();
+ dit != component->Dependencies.end();
+ ++dit)
+ {
+ Dependencies.insert(Generator->ComponentPackages[*dit]);
+ }
+ }
+
+ // QtIFW dependencies
+ if(const char* option = this->GetOption(prefix + "DEPENDS"))
+ {
+ std::vector<std::string> deps;
+ cmSystemTools::ExpandListArgument(option,
+ deps);
+ for(std::vector<std::string>::iterator
+ dit = deps.begin(); dit != deps.end(); ++dit)
+ {
+ DependenceStruct dep(*dit);
+ if (!Generator->Packages.count(dep.Name))
+ {
+ bool hasDep = Generator->DependentPackages.count(dep.Name) > 0;
+ DependenceStruct &depRef =
+ Generator->DependentPackages[dep.Name];
+ if(!hasDep)
+ {
+ depRef = dep;
+ }
+ AlienDependencies.insert(&depRef);
+ }
+ }
+ }
+
+ // Licenses
+ if (const char* option = this->GetOption(prefix + "LICENSES"))
+ {
+ Licenses.clear();
+ cmSystemTools::ExpandListArgument( option, Licenses );
+ if ( Licenses.size() % 2 != 0 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_WARNING, prefix << "LICENSES"
+ << " should contain pairs of <display_name> and <file_path>."
+ << std::endl);
+ Licenses.clear();
+ }
+ }
+
+ // Priority
+ if(const char* option = this->GetOption(prefix + "PRIORITY"))
+ {
+ SortingPriority = option;
+ }
+
+ // Default
+ Default = component->IsDisabledByDefault ? "false" : "true";
+
+ // Virtual
+ Virtual = component->IsHidden ? "true" : "";
+
+ // ForcedInstallation
+ ForcedInstallation = component->IsRequired ? "true" : "false";
+
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+int
+cmCPackIFWPackage::ConfigureFromGroup(cmCPackComponentGroup *group)
+{
+ if(!group) return 0;
+
+ // Restore defaul configuration
+ DefaultConfiguration();
+
+ std::string prefix = "CPACK_IFW_COMPONENT_GROUP_"
+ + cmsys::SystemTools::UpperCase(group->Name)
+ + "_";
+
+ DisplayName = group->DisplayName;
+ Description = group->Description;
+
+ // Version
+ if(const char* optVERSION = GetOption(prefix + "VERSION"))
+ {
+ Version = optVERSION;
+ }
+ else if(const char* optPACKAGE_VERSION =
+ GetOption("CPACK_PACKAGE_VERSION"))
+ {
+ Version = optPACKAGE_VERSION;
+ }
+ else
+ {
+ Version = "1.0.0";
+ }
+
+ // Script
+ if (const char* option = GetOption(prefix + "SCRIPT"))
+ {
+ Script = option;
+ }
+
+ // Licenses
+ if (const char* option = this->GetOption(prefix + "LICENSES"))
+ {
+ Licenses.clear();
+ cmSystemTools::ExpandListArgument( option, Licenses );
+ if ( Licenses.size() % 2 != 0 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_WARNING, prefix << "LICENSES"
+ << " should contain pairs of <display_name> and <file_path>."
+ << std::endl);
+ Licenses.clear();
+ }
+ }
+
+ // Priority
+ if(const char* option = this->GetOption(prefix + "PRIORITY"))
+ {
+ SortingPriority = option;
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+int cmCPackIFWPackage::ConfigureFromGroup(const std::string &groupName)
+{
+ // Group configuration
+
+ cmCPackComponentGroup group;
+ std::string prefix = "CPACK_COMPONENT_GROUP_"
+ + cmsys::SystemTools::UpperCase(groupName)
+ + "_";
+
+ if (const char *option = GetOption(prefix + "DISPLAY_NAME"))
+ {
+ group.DisplayName = option;
+ }
+ else
+ {
+ group.DisplayName = group.Name;
+ }
+
+ if (const char* option = GetOption(prefix + "DESCRIPTION"))
+ {
+ group.Description = option;
+ }
+ group.IsBold = IsOn(prefix + "BOLD_TITLE");
+ group.IsExpandedByDefault = IsOn(prefix + "EXPANDED");
+
+ // Package configuration
+
+ group.Name = groupName;
+
+ if(Generator)
+ {
+ Name = Generator->GetGroupPackageName(&group);
+ }
+ else
+ {
+ Name = group.Name;
+ }
+
+ return ConfigureFromGroup(&group);
+}
+
+//----------------------------------------------------------------------------
+void cmCPackIFWPackage::GeneratePackageFile()
+{
+ // Lazy directory initialization
+ if (Directory.empty())
+ {
+ if(Installer)
+ {
+ Directory = Installer->Directory + "/packages/" + Name;
+ }
+ else if (Generator)
+ {
+ Directory = Generator->toplevel + "/packages/" + Name;
+ }
+ }
+
+ // Output stream
+ cmGeneratedFileStream xout((Directory + "/meta/package.xml").data());
+
+ xout << "<?xml version=\"1.0\"?>" << std::endl;
+ xout << "<Package>" << std::endl;
+
+ xout << " <DisplayName>" << DisplayName
+ << "</DisplayName>" << std::endl;
+
+ xout << " <Description>" << Description
+ << "</Description>" << std::endl;
+
+ xout << " <Name>" << Name << "</Name>" << std::endl;
+
+ xout << " <Version>" << Version
+ << "</Version>" << std::endl;
+
+ xout << " <ReleaseDate>";
+ if(ReleaseDate.empty())
+ {
+ xout << cmTimestamp().CurrentTime("%Y-%m-%d", true);
+ }
+ else
+ {
+ xout << ReleaseDate;
+ }
+ xout << "</ReleaseDate>" << std::endl;
+
+ // Script (copy to meta dir)
+ if(!Script.empty())
+ {
+ std::string name = cmSystemTools::GetFilenameName(Script);
+ std::string path = Directory + "/meta/" + name;
+ cmsys::SystemTools::CopyFileIfDifferent(Script.data(), path.data());
+ xout << " <Script>" << name << "</Script>" << std::endl;
+ }
+
+ // Dependencies
+ std::set<DependenceStruct> compDepSet;
+ for(std::set<DependenceStruct*>::iterator ait = AlienDependencies.begin();
+ ait != AlienDependencies.end(); ++ait)
+ {
+ compDepSet.insert(*(*ait));
+ }
+ for(std::set<cmCPackIFWPackage*>::iterator it = Dependencies.begin();
+ it != Dependencies.end(); ++it)
+ {
+ compDepSet.insert(DependenceStruct((*it)->Name));
+ }
+ // Write dependencies
+ if (!compDepSet.empty())
+ {
+ xout << " <Dependencies>";
+ std::set<DependenceStruct>::iterator it = compDepSet.begin();
+ xout << it->NameWithCompare();
+ ++it;
+ while(it != compDepSet.end())
+ {
+ xout << "," << it->NameWithCompare();
+ ++it;
+ }
+ xout << "</Dependencies>" << std::endl;
+ }
+
+ // Licenses (copy to meta dir)
+ std::vector<std::string> licenses = Licenses;
+ for(size_t i = 1; i < licenses.size(); i += 2)
+ {
+ std::string name = cmSystemTools::GetFilenameName(licenses[i]);
+ std::string path = Directory + "/meta/" + name;
+ cmsys::SystemTools::CopyFileIfDifferent(licenses[i].data(), path.data());
+ licenses[i] = name;
+ }
+ if(!licenses.empty())
+ {
+ xout << " <Licenses>" << std::endl;
+ for(size_t i = 0; i < licenses.size(); i += 2)
+ {
+ xout << " <License "
+ << "name=\"" << licenses[i] << "\" "
+ << "file=\"" << licenses[i + 1] << "\" "
+ << "/>" <<std::endl;
+ }
+ xout << " </Licenses>" << std::endl;
+ }
+
+ if (!ForcedInstallation.empty())
+ {
+ xout << " <ForcedInstallation>" << ForcedInstallation
+ << "</ForcedInstallation>" << std::endl;
+ }
+
+ if (!Virtual.empty())
+ {
+ xout << " <Virtual>" << Virtual << "</Virtual>" << std::endl;
+ }
+ else if (!Default.empty())
+ {
+ xout << " <Default>" << Default << "</Default>" << std::endl;
+ }
+
+ // Priority
+ if(!SortingPriority.empty())
+ {
+ xout << " <SortingPriority>" << SortingPriority
+ << "</SortingPriority>" << std::endl;
+ }
+
+ xout << "</Package>" << std::endl;
+}
diff --git a/Source/CPack/IFW/cmCPackIFWPackage.h b/Source/CPack/IFW/cmCPackIFWPackage.h
new file mode 100644
index 0000000000..9fc9bd0006
--- /dev/null
+++ b/Source/CPack/IFW/cmCPackIFWPackage.h
@@ -0,0 +1,133 @@
+/*============================================================================
+ 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 cmCPackIFWPackage_h
+#define cmCPackIFWPackage_h
+
+#include <cmStandardIncludes.h>
+
+class cmCPackComponent;
+class cmCPackComponentGroup;
+class cmCPackIFWInstaller;
+class cmCPackIFWGenerator;
+
+/** \class cmCPackIFWPackage
+ * \brief A single component to be installed by CPack IFW generator
+ */
+class cmCPackIFWPackage
+{
+public: // Types
+ enum CompareTypes
+ {
+ CompareNone = 0x0,
+ CompareEqual = 0x1,
+ CompareLess = 0x2,
+ CompareLessOrEqual = 0x3,
+ CompareGreater = 0x4,
+ CompareGreaterOrEqual = 0x5
+ };
+
+ struct CompareStruct
+ {
+ CompareStruct();
+
+ unsigned int Type;
+ std::string Value;
+ };
+
+ struct DependenceStruct
+ {
+ DependenceStruct();
+ DependenceStruct(const std::string &dependence);
+
+ std::string Name;
+ CompareStruct Compare;
+
+ std::string NameWithCompare() const;
+
+ bool operator < (const DependenceStruct &other) const
+ {
+ return Name < other.Name;
+ }
+ };
+
+public: // [Con|De]structor
+
+ /**
+ * Construct package
+ */
+ cmCPackIFWPackage();
+
+public: // Configuration
+
+ /// Human-readable name of the component
+ std::string DisplayName;
+
+ /// Human-readable description of the component
+ std::string Description;
+
+ /// Version number of the component
+ std::string Version;
+
+ /// Date when this component version was released
+ std::string ReleaseDate;
+
+ /// Domain-like identification for this component
+ std::string Name;
+
+ /// File name of a script being loaded
+ std::string Script;
+
+ /// List of license agreements to be accepted by the installing user
+ std::vector<std::string> Licenses;
+
+ /// Priority of the component in the tree
+ std::string SortingPriority;
+
+ /// Set to true to preselect the component in the installer
+ std::string Default;
+
+ /// Set to true to hide the component from the installer
+ std::string Virtual;
+
+ /// Determines that the package must always be installed
+ std::string ForcedInstallation;
+
+public: // Internal implementation
+
+ const char* GetOption(const std::string& op) const;
+ bool IsOn(const std::string& op) const;
+
+ std::string GetComponentName(cmCPackComponent *component);
+
+ void DefaultConfiguration();
+
+ int ConfigureFromOptions();
+ int ConfigureFromComponent(cmCPackComponent *component);
+ int ConfigureFromGroup(cmCPackComponentGroup *group);
+ int ConfigureFromGroup(const std::string &groupName);
+
+ void GeneratePackageFile();
+
+ // Pointer to generator
+ cmCPackIFWGenerator* Generator;
+ // Pointer to installer
+ cmCPackIFWInstaller* Installer;
+ // Collection of dependencies
+ std::set<cmCPackIFWPackage*> Dependencies;
+ // Collection of unresolved dependencies
+ std::set<DependenceStruct*> AlienDependencies;
+ // Patch to package directory
+ std::string Directory;
+};
+
+#endif // cmCPackIFWPackage_h
diff --git a/Source/CPack/OSXLauncherScript.scpt b/Source/CPack/OSXLauncherScript.scpt
new file mode 100644
index 0000000000..342cf8c01b
--- /dev/null
+++ b/Source/CPack/OSXLauncherScript.scpt
Binary files differ
diff --git a/Source/CPack/OSXScriptLauncher.cxx b/Source/CPack/OSXScriptLauncher.cxx
new file mode 100644
index 0000000000..d9d623692e
--- /dev/null
+++ b/Source/CPack/OSXScriptLauncher.cxx
@@ -0,0 +1,147 @@
+/*============================================================================
+ 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 <cmsys/SystemTools.hxx>
+#include <cmsys/Process.h>
+#include <cmsys/ios/iostream>
+#include <cmsys/FStream.hxx>
+
+#include <CoreFoundation/CoreFoundation.h>
+
+// For the PATH_MAX constant
+#include <sys/syslimits.h>
+
+#define DebugError(x) \
+ ofs << x << cmsys_ios::endl; \
+ cmsys_ios::cout << x << cmsys_ios::endl
+
+int main(int argc, char* argv[])
+{
+ //if ( cmsys::SystemTools::FileExists(
+ cmsys_stl::string cwd = cmsys::SystemTools::GetCurrentWorkingDirectory();
+ cmsys::ofstream ofs("/tmp/output.txt");
+
+ CFStringRef fileName;
+ CFBundleRef appBundle;
+ CFURLRef scriptFileURL;
+ UInt8 *path;
+
+ //get CF URL for script
+ if (! (appBundle = CFBundleGetMainBundle()))
+ {
+ DebugError("Cannot get main bundle");
+ return 1;
+ }
+ fileName = CFSTR("RuntimeScript");
+ if (! (scriptFileURL = CFBundleCopyResourceURL(appBundle, fileName, NULL,
+ NULL)))
+ {
+ DebugError("CFBundleCopyResourceURL failed");
+ return 1;
+ }
+
+ //create path string
+ if (! (path = new UInt8[PATH_MAX]))
+ {
+ return 1;
+ }
+
+ //get the file system path of the url as a cstring
+ //in an encoding suitable for posix apis
+ if ( CFURLGetFileSystemRepresentation(scriptFileURL, true, path,
+ PATH_MAX) == false)
+ {
+ DebugError("CFURLGetFileSystemRepresentation failed");
+ return 1;
+ }
+
+ //dispose of the CF variable
+ CFRelease(scriptFileURL);
+
+ cmsys_stl::string fullScriptPath = reinterpret_cast<char*>(path);
+ delete [] path;
+
+
+ if (! cmsys::SystemTools::FileExists(fullScriptPath.c_str()))
+ {
+ return 1;
+ }
+
+ cmsys_stl::string scriptDirectory = cmsys::SystemTools::GetFilenamePath(
+ fullScriptPath);
+ ofs << fullScriptPath.c_str() << cmsys_ios::endl;
+ cmsys_stl::vector<const char*> args;
+ args.push_back(fullScriptPath.c_str());
+ int cc;
+ for ( cc = 1; cc < argc; ++ cc )
+ {
+ args.push_back(argv[cc]);
+ }
+ args.push_back(0);
+
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetCommand(cp, &*args.begin());
+ cmsysProcess_SetWorkingDirectory(cp, scriptDirectory.c_str());
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+ cmsysProcess_SetTimeout(cp, 0);
+ cmsysProcess_Execute(cp);
+
+ std::vector<char> tempOutput;
+ char* data;
+ int length;
+ while(cmsysProcess_WaitForData(cp, &data, &length, 0))
+ {
+ // 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')
+ {
+ data[i] = ' ';
+ }
+ }
+ cmsys_ios::cout.write(data, length);
+ }
+
+ cmsysProcess_WaitForExit(cp, 0);
+
+ bool result = true;
+ if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
+ {
+ if ( cmsysProcess_GetExitValue(cp) != 0 )
+ {
+ result = false;
+ }
+ }
+ else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception)
+ {
+ const char* exception_str = cmsysProcess_GetExceptionString(cp);
+ std::cerr << exception_str << std::endl;
+ result = false;
+ }
+ else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
+ {
+ const char* error_str = cmsysProcess_GetErrorString(cp);
+ std::cerr << error_str << std::endl;
+ result = false;
+ }
+ else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired)
+ {
+ const char* error_str = "Process terminated due to timeout\n";
+ std::cerr << error_str << std::endl;
+ result = false;
+ }
+
+ cmsysProcess_Delete(cp);
+
+ return 0;
+}
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
new file mode 100644
index 0000000000..7e0002711e
--- /dev/null
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
@@ -0,0 +1,1175 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2014 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 "cmCPackWIXGenerator.h"
+
+#include <cmSystemTools.h>
+#include <cmGeneratedFileStream.h>
+#include <cmCryptoHash.h>
+#include <cmInstalledFile.h>
+#include <CPack/cmCPackLog.h>
+#include <CPack/cmCPackComponentGroup.h>
+
+#include "cmWIXSourceWriter.h"
+#include "cmWIXDirectoriesSourceWriter.h"
+#include "cmWIXFeaturesSourceWriter.h"
+#include "cmWIXFilesSourceWriter.h"
+#include "cmWIXRichTextFormatWriter.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Directory.hxx>
+#include <cmsys/Encoding.hxx>
+#include <cmsys/FStream.hxx>
+
+#include <rpc.h> // for GUID generation
+
+cmCPackWIXGenerator::cmCPackWIXGenerator():
+ HasDesktopShortcuts(false),
+ Patch(0)
+{
+
+}
+
+cmCPackWIXGenerator::~cmCPackWIXGenerator()
+{
+ if(this->Patch)
+ {
+ delete this->Patch;
+ }
+}
+
+int cmCPackWIXGenerator::InitializeInternal()
+{
+ componentPackageMethod = ONE_PACKAGE;
+ this->Patch = new cmWIXPatch(this->Logger);
+
+ return this->Superclass::InitializeInternal();
+}
+
+bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command)
+{
+ std::string logFileName = this->CPackTopLevel + "/wix.log";
+
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Running WiX command: " << command << std::endl);
+
+ std::string output;
+
+ int returnValue = 0;
+ bool status = cmSystemTools::RunSingleCommand(command.c_str(), &output,
+ &returnValue, 0, cmSystemTools::OUTPUT_NONE);
+
+ cmsys::ofstream logFile(logFileName.c_str(), std::ios::app);
+ logFile << command << std::endl;
+ logFile << output;
+ logFile.close();
+
+ if(!status || returnValue)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running WiX candle. "
+ "Please check '" << logFileName << "' for errors." << std::endl);
+
+ return false;
+ }
+
+ return true;
+}
+
+bool cmCPackWIXGenerator::RunCandleCommand(
+ std::string const& sourceFile, std::string const& objectFile)
+{
+ std::string executable;
+ if(!RequireOption("CPACK_WIX_CANDLE_EXECUTABLE", executable))
+ {
+ return false;
+ }
+
+ std::stringstream command;
+ command << QuotePath(executable);
+ command << " -nologo";
+ command << " -arch " << GetArchitecture();
+ command << " -out " << QuotePath(objectFile);
+
+ for(extension_set_t::const_iterator i = CandleExtensions.begin();
+ i != CandleExtensions.end(); ++i)
+ {
+ command << " -ext " << QuotePath(*i);
+ }
+
+ AddCustomFlags("CPACK_WIX_CANDLE_EXTRA_FLAGS", command);
+
+ command << " " << QuotePath(sourceFile);
+
+ return RunWiXCommand(command.str());
+}
+
+bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles)
+{
+ std::string executable;
+ if(!RequireOption("CPACK_WIX_LIGHT_EXECUTABLE", executable))
+ {
+ return false;
+ }
+
+ std::stringstream command;
+ command << QuotePath(executable);
+ command << " -nologo";
+ command << " -out " << QuotePath(packageFileNames.at(0));
+
+ for(extension_set_t::const_iterator i = this->LightExtensions.begin();
+ i != this->LightExtensions.end(); ++i)
+ {
+ command << " -ext " << QuotePath(*i);
+ }
+
+ const char* const cultures = GetOption("CPACK_WIX_CULTURES");
+ if(cultures)
+ {
+ command << " -cultures:" << cultures;
+ }
+
+ AddCustomFlags("CPACK_WIX_LIGHT_EXTRA_FLAGS", command);
+
+ command << " " << objectFiles;
+
+ return RunWiXCommand(command.str());
+}
+
+int cmCPackWIXGenerator::PackageFiles()
+{
+ if(!PackageFilesImpl() || cmSystemTools::GetErrorOccuredFlag())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Fatal WiX Generator Error" << std::endl);
+ return false;
+ }
+
+ return true;
+}
+
+bool cmCPackWIXGenerator::InitializeWiXConfiguration()
+{
+ if(!ReadListFile("CPackWIX.cmake"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while executing CPackWIX.cmake" << std::endl);
+ return false;
+ }
+
+ if(GetOption("CPACK_WIX_PRODUCT_GUID") == 0)
+ {
+ std::string guid = GenerateGUID();
+ SetOption("CPACK_WIX_PRODUCT_GUID", guid.c_str());
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "CPACK_WIX_PRODUCT_GUID implicitly set to " << guid << " . "
+ << std::endl);
+ }
+
+ if(GetOption("CPACK_WIX_UPGRADE_GUID") == 0)
+ {
+ std::string guid = GenerateGUID();
+ SetOption("CPACK_WIX_UPGRADE_GUID", guid.c_str());
+
+ cmCPackLogger(cmCPackLog::LOG_WARNING,
+ "CPACK_WIX_UPGRADE_GUID implicitly set to " << guid << " . "
+ "Please refer to the documentation on how and why "
+ "you might want to set this explicitly." << std::endl);
+ }
+
+ if(!RequireOption("CPACK_TOPLEVEL_DIRECTORY", this->CPackTopLevel))
+ {
+ return false;
+ }
+
+ if(GetOption("CPACK_WIX_LICENSE_RTF") == 0)
+ {
+ std::string licenseFilename = this->CPackTopLevel + "/License.rtf";
+ SetOption("CPACK_WIX_LICENSE_RTF", licenseFilename.c_str());
+
+ if(!CreateLicenseFile())
+ {
+ return false;
+ }
+ }
+
+ if(GetOption("CPACK_PACKAGE_VENDOR") == 0)
+ {
+ std::string defaultVendor = "Humanity";
+ SetOption("CPACK_PACKAGE_VENDOR", defaultVendor.c_str());
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "CPACK_PACKAGE_VENDOR implicitly set to " << defaultVendor << " . "
+ << std::endl);
+ }
+
+ if(GetOption("CPACK_WIX_UI_REF") == 0)
+ {
+ std::string defaultRef = "WixUI_InstallDir";
+
+ if(this->Components.size())
+ {
+ defaultRef = "WixUI_FeatureTree";
+ }
+
+ SetOption("CPACK_WIX_UI_REF", defaultRef.c_str());
+ }
+
+ const char* packageContact = GetOption("CPACK_PACKAGE_CONTACT");
+ if(packageContact != 0 &&
+ GetOption("CPACK_WIX_PROPERTY_ARPCONTACT") == 0)
+ {
+ SetOption("CPACK_WIX_PROPERTY_ARPCONTACT", packageContact);
+ }
+
+ CollectExtensions("CPACK_WIX_EXTENSIONS", this->CandleExtensions);
+ CollectExtensions("CPACK_WIX_CANDLE_EXTENSIONS", this->CandleExtensions);
+
+ this->LightExtensions.insert("WixUIExtension");
+ CollectExtensions("CPACK_WIX_EXTENSIONS", this->LightExtensions);
+ CollectExtensions("CPACK_WIX_LIGHT_EXTENSIONS", this->LightExtensions);
+
+ const char* patchFilePath = GetOption("CPACK_WIX_PATCH_FILE");
+ if(patchFilePath)
+ {
+ this->Patch->LoadFragments(patchFilePath);
+ }
+
+ return true;
+}
+
+bool cmCPackWIXGenerator::PackageFilesImpl()
+{
+ if(!InitializeWiXConfiguration())
+ {
+ return false;
+ }
+
+ CreateWiXVariablesIncludeFile();
+ CreateWiXPropertiesIncludeFile();
+
+ if(!CreateWiXSourceFiles())
+ {
+ return false;
+ }
+
+ AppendUserSuppliedExtraSources();
+
+ std::stringstream objectFiles;
+ for(size_t i = 0; i < this->WixSources.size(); ++i)
+ {
+ std::string const& sourceFilename = this->WixSources[i];
+
+ std::string objectFilename =
+ cmSystemTools::GetFilenameWithoutExtension(sourceFilename) + ".wixobj";
+
+ if(!RunCandleCommand(sourceFilename, objectFilename))
+ {
+ return false;
+ }
+
+ objectFiles << " " << QuotePath(objectFilename);
+ }
+
+ AppendUserSuppliedExtraObjects(objectFiles);
+
+ return RunLightCommand(objectFiles.str());
+}
+
+void cmCPackWIXGenerator::AppendUserSuppliedExtraSources()
+{
+ const char *cpackWixExtraSources = GetOption("CPACK_WIX_EXTRA_SOURCES");
+ if(!cpackWixExtraSources) return;
+
+ cmSystemTools::ExpandListArgument(cpackWixExtraSources, this->WixSources);
+}
+
+void cmCPackWIXGenerator::AppendUserSuppliedExtraObjects(std::ostream& stream)
+{
+ const char *cpackWixExtraObjects = GetOption("CPACK_WIX_EXTRA_OBJECTS");
+ if(!cpackWixExtraObjects) return;
+
+ std::vector<std::string> expandedExtraObjects;
+
+ cmSystemTools::ExpandListArgument(
+ cpackWixExtraObjects, expandedExtraObjects);
+
+ for(size_t i = 0; i < expandedExtraObjects.size(); ++i)
+ {
+ stream << " " << QuotePath(expandedExtraObjects[i]);
+ }
+}
+
+void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile()
+{
+ std::string includeFilename =
+ this->CPackTopLevel + "/cpack_variables.wxi";
+
+ cmWIXSourceWriter includeFile(
+ this->Logger, includeFilename, true);
+
+ CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_GUID");
+ CopyDefinition(includeFile, "CPACK_WIX_UPGRADE_GUID");
+ CopyDefinition(includeFile, "CPACK_PACKAGE_VENDOR");
+ CopyDefinition(includeFile, "CPACK_PACKAGE_NAME");
+ CopyDefinition(includeFile, "CPACK_PACKAGE_VERSION");
+ CopyDefinition(includeFile, "CPACK_WIX_LICENSE_RTF");
+ CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_ICON");
+ CopyDefinition(includeFile, "CPACK_WIX_UI_BANNER");
+ CopyDefinition(includeFile, "CPACK_WIX_UI_DIALOG");
+ SetOptionIfNotSet("CPACK_WIX_PROGRAM_MENU_FOLDER",
+ GetOption("CPACK_PACKAGE_NAME"));
+ CopyDefinition(includeFile, "CPACK_WIX_PROGRAM_MENU_FOLDER");
+ CopyDefinition(includeFile, "CPACK_WIX_UI_REF");
+}
+
+void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile()
+{
+ std::string includeFilename =
+ this->CPackTopLevel + "/properties.wxi";
+
+ cmWIXSourceWriter includeFile(
+ this->Logger, includeFilename, true);
+
+ std::string prefix = "CPACK_WIX_PROPERTY_";
+ std::vector<std::string> options = GetOptions();
+
+ for(size_t i = 0; i < options.size(); ++i)
+ {
+ std::string const& name = options[i];
+
+ if(name.length() > prefix.length() &&
+ name.substr(0, prefix.length()) == prefix)
+ {
+ std::string id = name.substr(prefix.length());
+ std::string value = GetOption(name.c_str());
+
+ includeFile.BeginElement("Property");
+ includeFile.AddAttribute("Id", id);
+ includeFile.AddAttribute("Value", value);
+ includeFile.EndElement("Property");
+ }
+ }
+
+ if(GetOption("CPACK_WIX_PROPERTY_ARPINSTALLLOCATION") == 0)
+ {
+ includeFile.BeginElement("Property");
+ includeFile.AddAttribute("Id", "INSTALL_ROOT");
+ includeFile.AddAttribute("Secure", "yes");
+
+ includeFile.BeginElement("RegistrySearch");
+ includeFile.AddAttribute("Id", "FindInstallLocation");
+ includeFile.AddAttribute("Root", "HKLM");
+ includeFile.AddAttribute("Key", "Software\\Microsoft\\Windows\\"
+ "CurrentVersion\\Uninstall\\[WIX_UPGRADE_DETECTED]");
+ includeFile.AddAttribute("Name", "InstallLocation");
+ includeFile.AddAttribute("Type", "raw");
+ includeFile.EndElement("RegistrySearch");
+ includeFile.EndElement("Property");
+
+ includeFile.BeginElement("SetProperty");
+ includeFile.AddAttribute("Id", "ARPINSTALLLOCATION");
+ includeFile.AddAttribute("Value", "[INSTALL_ROOT]");
+ includeFile.AddAttribute("After", "CostFinalize");
+ includeFile.EndElement("SetProperty");
+ }
+}
+
+void cmCPackWIXGenerator::CopyDefinition(
+ cmWIXSourceWriter &source, std::string const& name)
+{
+ const char* value = GetOption(name.c_str());
+ if(value)
+ {
+ AddDefinition(source, name, value);
+ }
+}
+
+void cmCPackWIXGenerator::AddDefinition(cmWIXSourceWriter& source,
+ std::string const& name, std::string const& value)
+{
+ std::stringstream tmp;
+ tmp << name << "=\"" << value << '"';
+
+ source.AddProcessingInstruction("define",
+ cmWIXSourceWriter::WindowsCodepageToUtf8(tmp.str()));
+}
+
+bool cmCPackWIXGenerator::CreateWiXSourceFiles()
+{
+ std::string directoryDefinitionsFilename =
+ this->CPackTopLevel + "/directories.wxs";
+
+ this->WixSources.push_back(directoryDefinitionsFilename);
+
+ cmWIXDirectoriesSourceWriter directoryDefinitions(
+ this->Logger, directoryDefinitionsFilename);
+ directoryDefinitions.BeginElement("Fragment");
+
+ std::string installRoot;
+ if(!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY", installRoot))
+ {
+ return false;
+ }
+
+ directoryDefinitions.BeginElement("Directory");
+ directoryDefinitions.AddAttribute("Id", "TARGETDIR");
+ directoryDefinitions.AddAttribute("Name", "SourceDir");
+
+ size_t installRootSize =
+ directoryDefinitions.BeginInstallationPrefixDirectory(
+ GetProgramFilesFolderId(), installRoot);
+
+ std::string fileDefinitionsFilename =
+ this->CPackTopLevel + "/files.wxs";
+
+ this->WixSources.push_back(fileDefinitionsFilename);
+
+ cmWIXFilesSourceWriter fileDefinitions(
+ this->Logger, fileDefinitionsFilename);
+
+ fileDefinitions.BeginElement("Fragment");
+
+ std::string featureDefinitionsFilename =
+ this->CPackTopLevel +"/features.wxs";
+
+ this->WixSources.push_back(featureDefinitionsFilename);
+
+ cmWIXFeaturesSourceWriter featureDefinitions(
+ this->Logger, featureDefinitionsFilename);
+
+ featureDefinitions.BeginElement("Fragment");
+
+ featureDefinitions.BeginElement("Feature");
+ featureDefinitions.AddAttribute("Id", "ProductFeature");
+ featureDefinitions.AddAttribute("Display", "expand");
+ featureDefinitions.AddAttribute("ConfigurableDirectory", "INSTALL_ROOT");
+
+ std::string cpackPackageName;
+ if(!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName))
+ {
+ return false;
+ }
+
+ featureDefinitions.AddAttribute("Title", cpackPackageName);
+ featureDefinitions.AddAttribute("Level", "1");
+
+ const char* package = GetOption("CPACK_WIX_CMAKE_PACKAGE_REGISTRY");
+ if(package)
+ {
+ featureDefinitions.CreateCMakePackageRegistryEntry(
+ package, GetOption("CPACK_WIX_UPGRADE_GUID"));
+ }
+
+ if(!CreateFeatureHierarchy(featureDefinitions))
+ {
+ return false;
+ }
+
+ featureDefinitions.EndElement("Feature");
+
+ bool hasShortcuts = false;
+
+ shortcut_map_t globalShortcuts;
+ if(Components.empty())
+ {
+ AddComponentsToFeature(toplevel, "ProductFeature",
+ directoryDefinitions, fileDefinitions, featureDefinitions,
+ globalShortcuts);
+ if(globalShortcuts.size())
+ {
+ hasShortcuts = true;
+ }
+ }
+ else
+ {
+ for(std::map<std::string, cmCPackComponent>::const_iterator
+ i = this->Components.begin(); i != this->Components.end(); ++i)
+ {
+ cmCPackComponent const& component = i->second;
+
+ std::string componentPath = toplevel;
+ componentPath += "/";
+ componentPath += component.Name;
+
+ std::string componentFeatureId = "CM_C_" + component.Name;
+
+ shortcut_map_t featureShortcuts;
+ AddComponentsToFeature(componentPath, componentFeatureId,
+ directoryDefinitions, fileDefinitions,
+ featureDefinitions, featureShortcuts);
+ if(featureShortcuts.size())
+ {
+ hasShortcuts = true;
+ }
+
+ if(featureShortcuts.size())
+ {
+ if(!CreateStartMenuShortcuts(component.Name, componentFeatureId,
+ featureShortcuts, fileDefinitions, featureDefinitions))
+ {
+ return false;
+ }
+ }
+ }
+ }
+
+ if(hasShortcuts)
+ {
+ if(!CreateStartMenuShortcuts(std::string(), "ProductFeature",
+ globalShortcuts, fileDefinitions, featureDefinitions))
+ {
+ return false;
+ }
+ }
+
+ featureDefinitions.EndElement("Fragment");
+ fileDefinitions.EndElement("Fragment");
+
+ directoryDefinitions.EndInstallationPrefixDirectory(
+ installRootSize);
+
+ if(hasShortcuts)
+ {
+ directoryDefinitions.EmitStartMenuFolder(
+ GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"));
+ }
+
+ if(this->HasDesktopShortcuts)
+ {
+ directoryDefinitions.EmitDesktopFolder();
+ }
+
+ directoryDefinitions.EndElement("Directory");
+ directoryDefinitions.EndElement("Fragment");
+
+ if(!GenerateMainSourceFileFromTemplate())
+ {
+ return false;
+ }
+
+ return this->Patch->CheckForUnappliedFragments();
+}
+
+std::string cmCPackWIXGenerator::GetProgramFilesFolderId() const
+{
+ if(GetArchitecture() == "x86")
+ {
+ return "ProgramFilesFolder";
+ }
+ else
+ {
+ return "ProgramFiles64Folder";
+ }
+}
+
+bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate()
+{
+ std::string wixTemplate = FindTemplate("WIX.template.in");
+ if(GetOption("CPACK_WIX_TEMPLATE") != 0)
+ {
+ wixTemplate = GetOption("CPACK_WIX_TEMPLATE");
+ }
+
+ if(wixTemplate.empty())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Could not find CPack WiX template file WIX.template.in" << std::endl);
+ return false;
+ }
+
+ std::string mainSourceFilePath = this->CPackTopLevel + "/main.wxs";
+
+ if(!ConfigureFile(wixTemplate.c_str(), mainSourceFilePath .c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Failed creating '" << mainSourceFilePath <<
+ "'' from template." << std::endl);
+
+ return false;
+ }
+
+ this->WixSources.push_back(mainSourceFilePath);
+
+ return true;
+}
+
+bool cmCPackWIXGenerator::CreateFeatureHierarchy(
+ cmWIXFeaturesSourceWriter& featureDefinitions)
+{
+ for(std::map<std::string, cmCPackComponentGroup>::const_iterator
+ i = ComponentGroups.begin(); i != ComponentGroups.end(); ++i)
+ {
+ cmCPackComponentGroup const& group = i->second;
+ if(group.ParentGroup == 0)
+ {
+ featureDefinitions.EmitFeatureForComponentGroup(group);
+ }
+ }
+
+ for(std::map<std::string, cmCPackComponent>::const_iterator
+ i = this->Components.begin(); i != this->Components.end(); ++i)
+ {
+ cmCPackComponent const& component = i->second;
+
+ if(!component.Group)
+ {
+ featureDefinitions.EmitFeatureForComponent(component);
+ }
+ }
+
+ return true;
+}
+
+bool cmCPackWIXGenerator::AddComponentsToFeature(
+ std::string const& rootPath,
+ std::string const& featureId,
+ cmWIXDirectoriesSourceWriter& directoryDefinitions,
+ cmWIXFilesSourceWriter& fileDefinitions,
+ cmWIXFeaturesSourceWriter& featureDefinitions,
+ shortcut_map_t& shortcutMap)
+{
+ featureDefinitions.BeginElement("FeatureRef");
+ featureDefinitions.AddAttribute("Id", featureId);
+
+ std::vector<std::string> cpackPackageExecutablesList;
+ const char *cpackPackageExecutables = GetOption("CPACK_PACKAGE_EXECUTABLES");
+ if(cpackPackageExecutables)
+ {
+ cmSystemTools::ExpandListArgument(cpackPackageExecutables,
+ cpackPackageExecutablesList);
+ if(cpackPackageExecutablesList.size() % 2 != 0 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and "
+ "<text label>." << std::endl);
+ return false;
+ }
+ }
+
+ std::vector<std::string> cpackPackageDesktopLinksList;
+ const char *cpackPackageDesktopLinks =
+ GetOption("CPACK_CREATE_DESKTOP_LINKS");
+ if(cpackPackageDesktopLinks)
+ {
+ cmSystemTools::ExpandListArgument(cpackPackageDesktopLinks,
+ cpackPackageDesktopLinksList);
+ }
+
+ AddDirectoryAndFileDefinitons(
+ rootPath, "INSTALL_ROOT",
+ directoryDefinitions, fileDefinitions, featureDefinitions,
+ cpackPackageExecutablesList, cpackPackageDesktopLinksList,
+ shortcutMap);
+
+ featureDefinitions.EndElement("FeatureRef");
+
+ return true;
+}
+
+bool cmCPackWIXGenerator::CreateStartMenuShortcuts(
+ std::string const& cpackComponentName,
+ std::string const& featureId,
+ shortcut_map_t& shortcutMap,
+ cmWIXFilesSourceWriter& fileDefinitions,
+ cmWIXFeaturesSourceWriter& featureDefinitions)
+{
+ bool thisHasDesktopShortcuts = false;
+
+ featureDefinitions.BeginElement("FeatureRef");
+ featureDefinitions.AddAttribute("Id", featureId);
+
+ std::string cpackVendor;
+ if(!RequireOption("CPACK_PACKAGE_VENDOR", cpackVendor))
+ {
+ return false;
+ }
+
+ std::string cpackPackageName;
+ if(!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName))
+ {
+ return false;
+ }
+
+ std::string idSuffix;
+ if(!cpackComponentName.empty())
+ {
+ idSuffix += "_";
+ idSuffix += cpackComponentName;
+ }
+
+ std::string componentId = "CM_SHORTCUT" + idSuffix;
+
+ fileDefinitions.BeginElement("DirectoryRef");
+ fileDefinitions.AddAttribute("Id", "PROGRAM_MENU_FOLDER");
+
+ fileDefinitions.BeginElement("Component");
+ fileDefinitions.AddAttribute("Id", componentId);
+ fileDefinitions.AddAttribute("Guid", "*");
+
+ for(shortcut_map_t::const_iterator
+ i = shortcutMap.begin(); i != shortcutMap.end(); ++i)
+ {
+ std::string const& id = i->first;
+ cmWIXShortcut const& shortcut = i->second;
+
+ fileDefinitions.EmitShortcut(id, shortcut, false);
+
+ if(shortcut.desktop)
+ {
+ thisHasDesktopShortcuts = true;
+ }
+ }
+
+ if(cpackComponentName.empty())
+ {
+ fileDefinitions.EmitUninstallShortcut(cpackPackageName);
+ }
+
+ fileDefinitions.EmitRemoveFolder(
+ "CM_REMOVE_PROGRAM_MENU_FOLDER" + idSuffix);
+
+ std::string registryKey =
+ std::string("Software\\") + cpackVendor + "\\" + cpackPackageName;
+
+ fileDefinitions.EmitStartMenuShortcutRegistryValue(
+ registryKey, cpackComponentName);
+
+ fileDefinitions.EndElement("Component");
+ fileDefinitions.EndElement("DirectoryRef");
+
+ featureDefinitions.EmitComponentRef(componentId);
+
+ if(thisHasDesktopShortcuts)
+ {
+ this->HasDesktopShortcuts = true;
+ componentId = "CM_DESKTOP_SHORTCUT" + idSuffix;
+
+ fileDefinitions.BeginElement("DirectoryRef");
+ fileDefinitions.AddAttribute("Id", "DesktopFolder");
+ fileDefinitions.BeginElement("Component");
+ fileDefinitions.AddAttribute("Id", componentId);
+ fileDefinitions.AddAttribute("Guid", "*");
+
+ for(shortcut_map_t::const_iterator
+ i = shortcutMap.begin(); i != shortcutMap.end(); ++i)
+ {
+ std::string const& id = i->first;
+ cmWIXShortcut const& shortcut = i->second;
+
+ if (!shortcut.desktop)
+ continue;
+
+ fileDefinitions.EmitShortcut(id, shortcut, true);
+ }
+
+ fileDefinitions.EmitDesktopShortcutRegistryValue(
+ registryKey, cpackComponentName);
+
+ fileDefinitions.EndElement("Component");
+ fileDefinitions.EndElement("DirectoryRef");
+
+ featureDefinitions.EmitComponentRef(componentId);
+ }
+
+ featureDefinitions.EndElement("FeatureRef");
+
+ return true;
+}
+
+bool cmCPackWIXGenerator::CreateLicenseFile()
+{
+ std::string licenseSourceFilename;
+ if(!RequireOption("CPACK_RESOURCE_FILE_LICENSE", licenseSourceFilename))
+ {
+ return false;
+ }
+
+ std::string licenseDestinationFilename;
+ if(!RequireOption("CPACK_WIX_LICENSE_RTF", licenseDestinationFilename))
+ {
+ return false;
+ }
+
+ std::string extension = GetRightmostExtension(licenseSourceFilename);
+
+ if(extension == ".rtf")
+ {
+ cmSystemTools::CopyAFile(
+ licenseSourceFilename.c_str(),
+ licenseDestinationFilename.c_str());
+ }
+ else if(extension == ".txt")
+ {
+ cmWIXRichTextFormatWriter rtfWriter(licenseDestinationFilename);
+
+ cmsys::ifstream licenseSource(licenseSourceFilename.c_str());
+
+ std::string line;
+ while(std::getline(licenseSource, line))
+ {
+ rtfWriter.AddText(line);
+ rtfWriter.AddText("\n");
+ }
+ }
+ else
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "unsupported WiX License file extension '" <<
+ extension << "'" << std::endl);
+
+ return false;
+ }
+
+ return true;
+}
+
+void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
+ std::string const& topdir,
+ std::string const& directoryId,
+ cmWIXDirectoriesSourceWriter& directoryDefinitions,
+ cmWIXFilesSourceWriter& fileDefinitions,
+ cmWIXFeaturesSourceWriter& featureDefinitions,
+ const std::vector<std::string>& packageExecutables,
+ const std::vector<std::string>& desktopExecutables,
+ shortcut_map_t& shortcutMap)
+{
+ cmsys::Directory dir;
+ dir.Load(topdir.c_str());
+
+ std::string relativeDirectoryPath =
+ cmSystemTools::RelativePath(toplevel.c_str(), topdir.c_str());
+
+ if(relativeDirectoryPath.empty())
+ {
+ relativeDirectoryPath = ".";
+ }
+
+ cmInstalledFile const* directoryInstalledFile =
+ this->GetInstalledFile(relativeDirectoryPath);
+
+ bool emptyDirectory = dir.GetNumberOfFiles() == 2;
+ bool createDirectory = false;
+
+ if(emptyDirectory)
+ {
+ createDirectory = true;
+ }
+
+ if(directoryInstalledFile)
+ {
+ if(directoryInstalledFile->HasProperty("CPACK_WIX_ACL"))
+ {
+ createDirectory = true;
+ }
+ }
+
+ if(createDirectory)
+ {
+ std::string componentId = fileDefinitions.EmitComponentCreateFolder(
+ directoryId, GenerateGUID(), directoryInstalledFile);
+ featureDefinitions.EmitComponentRef(componentId);
+ }
+
+ if(emptyDirectory)
+ {
+ return;
+ }
+
+ for(size_t i = 0; i < dir.GetNumberOfFiles(); ++i)
+ {
+ std::string fileName = dir.GetFile(static_cast<unsigned long>(i));
+
+ if(fileName == "." || fileName == "..")
+ {
+ continue;
+ }
+
+ std::string fullPath = topdir + "/" + fileName;
+
+ std::string relativePath = cmSystemTools::RelativePath(
+ toplevel.c_str(), fullPath.c_str());
+
+ std::string id = PathToId(relativePath);
+
+ if(cmSystemTools::FileIsDirectory(fullPath.c_str()))
+ {
+ std::string subDirectoryId = std::string("CM_D") + id;
+
+ directoryDefinitions.BeginElement("Directory");
+ directoryDefinitions.AddAttribute("Id", subDirectoryId);
+ directoryDefinitions.AddAttribute("Name", fileName);
+
+ AddDirectoryAndFileDefinitons(
+ fullPath, subDirectoryId,
+ directoryDefinitions,
+ fileDefinitions,
+ featureDefinitions,
+ packageExecutables,
+ desktopExecutables,
+ shortcutMap);
+
+ this->Patch->ApplyFragment(subDirectoryId, directoryDefinitions);
+ directoryDefinitions.EndElement("Directory");
+ }
+ else
+ {
+ cmInstalledFile const* installedFile =
+ this->GetInstalledFile(relativePath);
+
+ std::string componentId = fileDefinitions.EmitComponentFile(
+ directoryId, id, fullPath, *(this->Patch), installedFile);
+
+ featureDefinitions.EmitComponentRef(componentId);
+
+ for(size_t j = 0; j < packageExecutables.size(); ++j)
+ {
+ std::string const& executableName = packageExecutables[j++];
+ std::string const& textLabel = packageExecutables[j];
+
+ if(cmSystemTools::LowerCase(fileName) ==
+ cmSystemTools::LowerCase(executableName) + ".exe")
+ {
+ cmWIXShortcut &shortcut = shortcutMap[id];
+ shortcut.textLabel= textLabel;
+ shortcut.workingDirectoryId = directoryId;
+
+ if(desktopExecutables.size() &&
+ std::find(desktopExecutables.begin(),
+ desktopExecutables.end(),
+ executableName)
+ != desktopExecutables.end())
+ {
+ shortcut.desktop = true;
+ }
+ }
+ }
+ }
+ }
+}
+
+bool cmCPackWIXGenerator::RequireOption(
+ std::string const& name, std::string &value) const
+{
+ const char* tmp = GetOption(name.c_str());
+ if(tmp)
+ {
+ value = tmp;
+
+ return true;
+ }
+ else
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Required variable " << name << " not set" << std::endl);
+
+ return false;
+ }
+}
+
+std::string cmCPackWIXGenerator::GetArchitecture() const
+{
+ std::string void_p_size;
+ RequireOption("CPACK_WIX_SIZEOF_VOID_P", void_p_size);
+
+ if(void_p_size == "8")
+ {
+ return "x64";
+ }
+ else
+ {
+ return "x86";
+ }
+}
+
+std::string cmCPackWIXGenerator::GenerateGUID()
+{
+ UUID guid;
+ UuidCreate(&guid);
+
+ unsigned short *tmp = 0;
+ UuidToStringW(&guid, &tmp);
+
+ std::string result =
+ cmsys::Encoding::ToNarrow(reinterpret_cast<wchar_t*>(tmp));
+ RpcStringFreeW(&tmp);
+
+ return cmSystemTools::UpperCase(result);
+}
+
+std::string cmCPackWIXGenerator::QuotePath(std::string const& path)
+{
+ return std::string("\"") + path + '"';
+}
+
+std::string cmCPackWIXGenerator::GetRightmostExtension(
+ std::string const& filename)
+{
+ std::string extension;
+
+ std::string::size_type i = filename.rfind(".");
+ if(i != std::string::npos)
+ {
+ extension = filename.substr(i);
+ }
+
+ return cmSystemTools::LowerCase(extension);
+}
+
+std::string cmCPackWIXGenerator::PathToId(std::string const& path)
+{
+ id_map_t::const_iterator i = PathToIdMap.find(path);
+ if(i != PathToIdMap.end()) return i->second;
+
+ std::string id = CreateNewIdForPath(path);
+ return id;
+}
+
+std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path)
+{
+ std::vector<std::string> components;
+ cmSystemTools::SplitPath(path.c_str(), components, false);
+
+ size_t replacementCount = 0;
+
+ std::string identifier;
+ std::string currentComponent;
+
+ for(size_t i = 1; i < components.size(); ++i)
+ {
+ if(i != 1) identifier += '.';
+
+ currentComponent = NormalizeComponentForId(
+ components[i], replacementCount);
+
+ identifier += currentComponent;
+ }
+
+ std::string idPrefix = "P";
+ size_t replacementPercent = replacementCount * 100 / identifier.size();
+ if(replacementPercent > 33 || identifier.size() > 60)
+ {
+ identifier = CreateHashedId(path, currentComponent);
+ idPrefix = "H";
+ }
+
+ std::stringstream result;
+ result << idPrefix << "_" << identifier;
+
+ size_t ambiguityCount = ++IdAmbiguityCounter[identifier];
+
+ if(ambiguityCount > 999)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while trying to generate a unique Id for '" <<
+ path << "'" << std::endl);
+
+ return std::string();
+ }
+ else if(ambiguityCount > 1)
+ {
+ result << "_" << ambiguityCount;
+ }
+
+ std::string resultString = result.str();
+
+ PathToIdMap[path] = resultString;
+
+ return resultString;
+}
+
+std::string cmCPackWIXGenerator::CreateHashedId(
+ std::string const& path, std::string const& normalizedFilename)
+{
+ cmsys::auto_ptr<cmCryptoHash> sha1 = cmCryptoHash::New("SHA1");
+ std::string hash = sha1->HashString(path.c_str());
+
+ std::string identifier;
+ identifier += hash.substr(0, 7) + "_";
+
+ const size_t maxFileNameLength = 52;
+ if(normalizedFilename.length() > maxFileNameLength)
+ {
+ identifier += normalizedFilename.substr(0, maxFileNameLength - 3);
+ identifier += "...";
+ }
+ else
+ {
+ identifier += normalizedFilename;
+ }
+
+ return identifier;
+}
+
+std::string cmCPackWIXGenerator::NormalizeComponentForId(
+ std::string const& component, size_t& replacementCount)
+{
+ std::string result;
+ result.resize(component.size());
+
+ for(size_t i = 0; i < component.size(); ++i)
+ {
+ char c = component[i];
+ if(IsLegalIdCharacter(c))
+ {
+ result[i] = c;
+ }
+ else
+ {
+ result[i] = '_';
+ ++ replacementCount;
+ }
+ }
+
+ return result;
+}
+
+bool cmCPackWIXGenerator::IsLegalIdCharacter(char c)
+{
+ return (c >= '0' && c <= '9') ||
+ (c >= 'a' && c <= 'z') ||
+ (c >= 'A' && c <= 'Z') ||
+ c == '_' || c == '.';
+}
+
+void cmCPackWIXGenerator::CollectExtensions(
+ std::string const& variableName, extension_set_t& extensions)
+{
+ const char *variableContent = GetOption(variableName.c_str());
+ if(!variableContent) return;
+
+ std::vector<std::string> list;
+ cmSystemTools::ExpandListArgument(variableContent, list);
+
+ for(std::vector<std::string>::const_iterator i = list.begin();
+ i != list.end(); ++i)
+ {
+ extensions.insert(*i);
+ }
+}
+
+void cmCPackWIXGenerator::AddCustomFlags(
+ std::string const& variableName, std::ostream& stream)
+{
+ const char *variableContent = GetOption(variableName.c_str());
+ if(!variableContent) return;
+
+ std::vector<std::string> list;
+ cmSystemTools::ExpandListArgument(variableContent, list);
+
+ for(std::vector<std::string>::const_iterator i = list.begin();
+ i != list.end(); ++i)
+ {
+ stream << " " << QuotePath(*i);
+ }
+}
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h
new file mode 100644
index 0000000000..8705d404ba
--- /dev/null
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.h
@@ -0,0 +1,173 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 cmCPackWIXGenerator_h
+#define cmCPackWIXGenerator_h
+
+#include "cmWIXPatch.h"
+#include "cmWIXShortcut.h"
+
+#include <CPack/cmCPackGenerator.h>
+
+#include <string>
+#include <map>
+
+class cmWIXSourceWriter;
+class cmWIXDirectoriesSourceWriter;
+class cmWIXFilesSourceWriter;
+class cmWIXFeaturesSourceWriter;
+
+/** \class cmCPackWIXGenerator
+ * \brief A generator for WIX files
+ */
+class cmCPackWIXGenerator : public cmCPackGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackWIXGenerator, cmCPackGenerator);
+
+ cmCPackWIXGenerator();
+ ~cmCPackWIXGenerator();
+
+protected:
+ virtual int InitializeInternal();
+
+ virtual int PackageFiles();
+
+ virtual const char* GetOutputExtension()
+ {
+ return ".msi";
+ }
+
+ virtual enum CPackSetDestdirSupport SupportsSetDestdir() const
+ {
+ return SETDESTDIR_UNSUPPORTED;
+ }
+
+ virtual bool SupportsAbsoluteDestination() const
+ {
+ return false;
+ }
+
+ virtual bool SupportsComponentInstallation() const
+ {
+ return true;
+ }
+
+private:
+ typedef std::map<std::string, std::string> id_map_t;
+ typedef std::map<std::string, size_t> ambiguity_map_t;
+ typedef std::map<std::string, cmWIXShortcut> shortcut_map_t;
+ typedef std::set<std::string> extension_set_t;
+
+ bool InitializeWiXConfiguration();
+
+ bool PackageFilesImpl();
+
+ void CreateWiXVariablesIncludeFile();
+
+ void CreateWiXPropertiesIncludeFile();
+
+ void CopyDefinition(
+ cmWIXSourceWriter &source, std::string const& name);
+
+ void AddDefinition(cmWIXSourceWriter& source,
+ std::string const& name, std::string const& value);
+
+ bool CreateWiXSourceFiles();
+
+ std::string GetProgramFilesFolderId() const;
+
+ bool GenerateMainSourceFileFromTemplate();
+
+ bool CreateFeatureHierarchy(
+ cmWIXFeaturesSourceWriter& featureDefinitions);
+
+ bool AddComponentsToFeature(
+ std::string const& rootPath,
+ std::string const& featureId,
+ cmWIXDirectoriesSourceWriter& directoryDefinitions,
+ cmWIXFilesSourceWriter& fileDefinitions,
+ cmWIXFeaturesSourceWriter& featureDefinitions,
+ shortcut_map_t& shortcutMap);
+
+ bool CreateStartMenuShortcuts(
+ std::string const& cpackComponentName,
+ std::string const& featureId,
+ shortcut_map_t& shortcutMap,
+ cmWIXFilesSourceWriter& fileDefinitions,
+ cmWIXFeaturesSourceWriter& featureDefinitions);
+
+ void AppendUserSuppliedExtraSources();
+
+ void AppendUserSuppliedExtraObjects(std::ostream& stream);
+
+ bool CreateLicenseFile();
+
+ bool RunWiXCommand(std::string const& command);
+
+ bool RunCandleCommand(
+ std::string const& sourceFile, std::string const& objectFile);
+
+ bool RunLightCommand(std::string const& objectFiles);
+
+ void AddDirectoryAndFileDefinitons(std::string const& topdir,
+ std::string const& directoryId,
+ cmWIXDirectoriesSourceWriter& directoryDefinitions,
+ cmWIXFilesSourceWriter& fileDefinitions,
+ cmWIXFeaturesSourceWriter& featureDefinitions,
+ const std::vector<std::string>& pkgExecutables,
+ const std::vector<std::string>& desktopExecutables,
+ shortcut_map_t& shortcutMap);
+
+ bool RequireOption(std::string const& name, std::string& value) const;
+
+ std::string GetArchitecture() const;
+
+ static std::string GenerateGUID();
+
+ static std::string QuotePath(std::string const& path);
+
+ static std::string GetRightmostExtension(std::string const& filename);
+
+ std::string PathToId(std::string const& path);
+
+ std::string CreateNewIdForPath(std::string const& path);
+
+ static std::string CreateHashedId(
+ std::string const& path, std::string const& normalizedFilename);
+
+ std::string NormalizeComponentForId(
+ std::string const& component, size_t& replacementCount);
+
+ static bool IsLegalIdCharacter(char c);
+
+ void CollectExtensions(
+ std::string const& variableName, extension_set_t& extensions);
+
+ void AddCustomFlags(
+ std::string const& variableName, std::ostream& stream);
+
+ std::vector<std::string> WixSources;
+ id_map_t PathToIdMap;
+ ambiguity_map_t IdAmbiguityCounter;
+
+ extension_set_t CandleExtensions;
+ extension_set_t LightExtensions;
+
+ bool HasDesktopShortcuts;
+
+ std::string CPackTopLevel;
+
+ cmWIXPatch* Patch;
+};
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXAccessControlList.cxx b/Source/CPack/WiX/cmWIXAccessControlList.cxx
new file mode 100644
index 0000000000..aeec968611
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXAccessControlList.cxx
@@ -0,0 +1,149 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 "cmWIXAccessControlList.h"
+
+#include <CPack/cmCPackGenerator.h>
+
+#include <cmSystemTools.h>
+
+cmWIXAccessControlList::cmWIXAccessControlList(
+ cmCPackLog *logger,
+ cmInstalledFile const& installedFile,
+ cmWIXSourceWriter &sourceWriter):
+ Logger(logger),
+ InstalledFile(installedFile),
+ SourceWriter(sourceWriter)
+{
+
+}
+
+bool cmWIXAccessControlList::Apply()
+{
+ std::vector<std::string> entries;
+ this->InstalledFile.GetPropertyAsList("CPACK_WIX_ACL", entries);
+
+ for(size_t i = 0; i < entries.size(); ++i)
+ {
+ this->CreatePermissionElement(entries[i]);
+ }
+
+ return true;
+}
+
+void cmWIXAccessControlList::CreatePermissionElement(
+ std::string const& entry)
+{
+ std::string::size_type pos = entry.find('=');
+ if(pos == std::string::npos)
+ {
+ this->ReportError(entry, "Did not find mandatory '='");
+ return;
+ }
+
+ std::string user_and_domain = entry.substr(0, pos);
+ std::string permission_string = entry.substr(pos + 1);
+
+ pos = user_and_domain.find('@');
+ std::string user;
+ std::string domain;
+ if(pos != std::string::npos)
+ {
+ user = user_and_domain.substr(0, pos);
+ domain = user_and_domain.substr(pos + 1);
+ }
+ else
+ {
+ user = user_and_domain;
+ }
+
+ std::vector<std::string> permissions =
+ cmSystemTools::tokenize(permission_string, ",");
+
+ this->SourceWriter.BeginElement("Permission");
+ this->SourceWriter.AddAttribute("User", user);
+ if(domain.size())
+ {
+ this->SourceWriter.AddAttribute("Domain", domain);
+ }
+ for(size_t i = 0; i < permissions.size(); ++i)
+ {
+ this->EmitBooleanAttribute(entry,
+ cmSystemTools::TrimWhitespace(permissions[i]));
+ }
+ this->SourceWriter.EndElement("Permission");
+}
+
+void cmWIXAccessControlList::ReportError(
+ std::string const& entry,
+ std::string const& message)
+{
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Failed processing ACL entry '" << entry <<
+ "': " << message << std::endl);
+}
+
+bool cmWIXAccessControlList::IsBooleanAttribute(std::string const& name)
+{
+ static const char* validAttributes[] =
+ {
+ "Append",
+ "ChangePermission",
+ "CreateChild",
+ "CreateFile",
+ "CreateLink",
+ "CreateSubkeys",
+ "Delete",
+ "DeleteChild",
+ "EnumerateSubkeys",
+ "Execute",
+ "FileAllRights",
+ "GenericAll",
+ "GenericExecute",
+ "GenericRead",
+ "GenericWrite",
+ "Notify",
+ "Read",
+ "ReadAttributes",
+ "ReadExtendedAttributes",
+ "ReadPermission",
+ "SpecificRightsAll",
+ "Synchronize",
+ "TakeOwnership",
+ "Traverse",
+ "Write",
+ "WriteAttributes",
+ "WriteExtendedAttributes",
+ 0
+ };
+
+ size_t i = 0;
+ while(validAttributes[i])
+ {
+ if(name == validAttributes[i++]) return true;
+ }
+
+ return false;
+}
+
+void cmWIXAccessControlList::EmitBooleanAttribute(
+ std::string const& entry, std::string const& name)
+{
+ if(!this->IsBooleanAttribute(name))
+ {
+ std::stringstream message;
+ message << "Unknown boolean attribute '" << name << "'";
+ this->ReportError(entry, message.str());
+ }
+
+ this->SourceWriter.AddAttribute(name, "yes");
+}
diff --git a/Source/CPack/WiX/cmWIXAccessControlList.h b/Source/CPack/WiX/cmWIXAccessControlList.h
new file mode 100644
index 0000000000..20902f768a
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXAccessControlList.h
@@ -0,0 +1,46 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmWIXAccessControlList_h
+#define cmWIXAccessControlList_h
+
+#include <cmInstalledFile.h>
+#include <CPack/cmCPackLog.h>
+
+#include "cmWIXSourceWriter.h"
+
+class cmWIXAccessControlList
+{
+public:
+ cmWIXAccessControlList(
+ cmCPackLog *logger,
+ cmInstalledFile const& installedFile,
+ cmWIXSourceWriter &sourceWriter);
+
+ bool Apply();
+
+private:
+ void CreatePermissionElement(std::string const& entry);
+
+ void ReportError(std::string const& entry, std::string const& message);
+
+ bool IsBooleanAttribute(std::string const& name);
+
+ void EmitBooleanAttribute(
+ std::string const& entry, std::string const& name);
+
+ cmCPackLog* Logger;
+ cmInstalledFile const& InstalledFile;
+ cmWIXSourceWriter &SourceWriter;
+};
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx
new file mode 100644
index 0000000000..a93f89bae8
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx
@@ -0,0 +1,87 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 "cmWIXDirectoriesSourceWriter.h"
+
+cmWIXDirectoriesSourceWriter::cmWIXDirectoriesSourceWriter(cmCPackLog* logger,
+ std::string const& filename):
+ cmWIXSourceWriter(logger, filename)
+{
+
+}
+
+void cmWIXDirectoriesSourceWriter::EmitStartMenuFolder(
+ std::string const& startMenuFolder)
+{
+ BeginElement("Directory");
+ AddAttribute("Id", "ProgramMenuFolder");
+
+ BeginElement("Directory");
+ AddAttribute("Id", "PROGRAM_MENU_FOLDER");
+ AddAttribute("Name", startMenuFolder);
+ EndElement("Directory");
+
+ EndElement("Directory");
+}
+
+void cmWIXDirectoriesSourceWriter::EmitDesktopFolder()
+{
+ BeginElement("Directory");
+ AddAttribute("Id", "DesktopFolder");
+ AddAttribute("Name", "Desktop");
+ EndElement("Directory");
+}
+
+size_t cmWIXDirectoriesSourceWriter::BeginInstallationPrefixDirectory(
+ std::string const& programFilesFolderId,
+ std::string const& installRootString)
+{
+ BeginElement("Directory");
+ AddAttribute("Id", programFilesFolderId);
+
+ std::vector<std::string> installRoot;
+
+ cmSystemTools::SplitPath(installRootString.c_str(), installRoot);
+
+ if(!installRoot.empty() && installRoot.back().empty())
+ {
+ installRoot.pop_back();
+ }
+
+ for(size_t i = 1; i < installRoot.size(); ++i)
+ {
+ BeginElement("Directory");
+
+ if(i == installRoot.size() - 1)
+ {
+ AddAttribute("Id", "INSTALL_ROOT");
+ }
+ else
+ {
+ std::stringstream tmp;
+ tmp << "INSTALL_PREFIX_" << i;
+ AddAttribute("Id", tmp.str());
+ }
+
+ AddAttribute("Name", installRoot[i]);
+ }
+
+ return installRoot.size();
+}
+
+void cmWIXDirectoriesSourceWriter::EndInstallationPrefixDirectory(size_t size)
+{
+ for(size_t i = 0; i < size; ++i)
+ {
+ EndElement("Directory");
+ }
+}
diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h
new file mode 100644
index 0000000000..f51fdb4bbd
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h
@@ -0,0 +1,42 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmWIXDirectoriesSourceWriter_h
+#define cmWIXDirectoriesSourceWriter_h
+
+#include "cmWIXSourceWriter.h"
+
+#include <CPack/cmCPackGenerator.h>
+
+#include <string>
+
+/** \class cmWIXDirectoriesSourceWriter
+ * \brief Helper class to generate directories.wxs
+ */
+class cmWIXDirectoriesSourceWriter : public cmWIXSourceWriter
+{
+public:
+ cmWIXDirectoriesSourceWriter(cmCPackLog* logger,
+ std::string const& filename);
+
+ void EmitStartMenuFolder(std::string const& startMenuFolder);
+
+ void EmitDesktopFolder();
+
+ size_t BeginInstallationPrefixDirectory(
+ std::string const& programFilesFolderId,
+ std::string const& installRootString);
+
+ void EndInstallationPrefixDirectory(size_t size);
+};
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
new file mode 100644
index 0000000000..0bcfc389ff
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
@@ -0,0 +1,102 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 "cmWIXFeaturesSourceWriter.h"
+
+cmWIXFeaturesSourceWriter::cmWIXFeaturesSourceWriter(cmCPackLog* logger,
+ std::string const& filename):
+ cmWIXSourceWriter(logger, filename)
+{
+
+}
+
+void cmWIXFeaturesSourceWriter::CreateCMakePackageRegistryEntry(
+ std::string const& package,
+ std::string const& upgradeGuid)
+{
+ BeginElement("Component");
+ AddAttribute("Id", "CM_PACKAGE_REGISTRY");
+ AddAttribute("Directory", "TARGETDIR");
+ AddAttribute("Guid", "*");
+
+ std::string registryKey =
+ std::string("Software\\Kitware\\CMake\\Packages\\") + package;
+
+ BeginElement("RegistryValue");
+ AddAttribute("Root", "HKLM");
+ AddAttribute("Key", registryKey);
+ AddAttribute("Name", upgradeGuid);
+ AddAttribute("Type", "string");
+ AddAttribute("Value", "[INSTALL_ROOT]");
+ AddAttribute("KeyPath", "yes");
+ EndElement("RegistryValue");
+
+ EndElement("Component");
+}
+
+void cmWIXFeaturesSourceWriter::EmitFeatureForComponentGroup(
+ cmCPackComponentGroup const& group)
+{
+ BeginElement("Feature");
+ AddAttribute("Id", "CM_G_" + group.Name);
+
+ if(group.IsExpandedByDefault)
+ {
+ AddAttribute("Display", "expand");
+ }
+
+ AddAttributeUnlessEmpty("Title", group.DisplayName);
+ AddAttributeUnlessEmpty("Description", group.Description);
+
+ for(std::vector<cmCPackComponentGroup*>::const_iterator
+ i = group.Subgroups.begin(); i != group.Subgroups.end(); ++i)
+ {
+ EmitFeatureForComponentGroup(**i);
+ }
+
+ for(std::vector<cmCPackComponent*>::const_iterator
+ i = group.Components.begin(); i != group.Components.end(); ++i)
+ {
+ EmitFeatureForComponent(**i);
+ }
+
+ EndElement("Feature");
+}
+
+void cmWIXFeaturesSourceWriter::EmitFeatureForComponent(
+ cmCPackComponent const& component)
+{
+ BeginElement("Feature");
+ AddAttribute("Id", "CM_C_" + component.Name);
+
+ AddAttributeUnlessEmpty("Title", component.DisplayName);
+ AddAttributeUnlessEmpty("Description", component.Description);
+
+ if(component.IsRequired)
+ {
+ AddAttribute("Absent", "disallow");
+ }
+
+ if(component.IsHidden)
+ {
+ AddAttribute("Display", "hidden");
+ }
+
+ EndElement("Feature");
+}
+
+void cmWIXFeaturesSourceWriter::EmitComponentRef(std::string const& id)
+{
+ BeginElement("ComponentRef");
+ AddAttribute("Id", id);
+ EndElement("ComponentRef");
+}
diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h
new file mode 100644
index 0000000000..7670417550
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h
@@ -0,0 +1,39 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmWIXFeaturesSourceWriter_h
+#define cmWIXFeaturesSourceWriter_h
+
+#include "cmWIXSourceWriter.h"
+#include <CPack/cmCPackGenerator.h>
+
+/** \class cmWIXFeaturesSourceWriter
+ * \brief Helper class to generate features.wxs
+ */
+class cmWIXFeaturesSourceWriter : public cmWIXSourceWriter
+{
+public:
+ cmWIXFeaturesSourceWriter(cmCPackLog* logger,
+ std::string const& filename);
+
+ void CreateCMakePackageRegistryEntry(
+ std::string const& package,
+ std::string const& upgradeGuid);
+
+ void EmitFeatureForComponentGroup(const cmCPackComponentGroup& group);
+
+ void EmitFeatureForComponent(const cmCPackComponent& component);
+
+ void EmitComponentRef(std::string const& id);
+};
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
new file mode 100644
index 0000000000..1adb06ade2
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
@@ -0,0 +1,201 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 "cmWIXFilesSourceWriter.h"
+#include "cmWIXAccessControlList.h"
+
+#include <cmInstalledFile.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger,
+ std::string const& filename):
+ cmWIXSourceWriter(logger, filename)
+{
+
+}
+
+void cmWIXFilesSourceWriter::EmitShortcut(
+ std::string const& id,
+ cmWIXShortcut const& shortcut,
+ bool desktop)
+{
+ std::string shortcutId;
+
+ if(desktop)
+ {
+ shortcutId = "CM_DS";
+ }
+ else
+ {
+ shortcutId = "CM_S";
+ }
+
+ shortcutId += id;
+
+ std::string fileId = std::string("CM_F") + id;
+
+ BeginElement("Shortcut");
+ AddAttribute("Id", shortcutId);
+ AddAttribute("Name", shortcut.textLabel);
+ std::string target = "[#" + fileId + "]";
+ AddAttribute("Target", target);
+ AddAttribute("WorkingDirectory", shortcut.workingDirectoryId);
+ EndElement("Shortcut");
+}
+
+void cmWIXFilesSourceWriter::EmitRemoveFolder(std::string const& id)
+{
+ BeginElement("RemoveFolder");
+ AddAttribute("Id", id);
+ AddAttribute("On", "uninstall");
+ EndElement("RemoveFolder");
+}
+
+void cmWIXFilesSourceWriter::EmitStartMenuShortcutRegistryValue(
+ std::string const& registryKey,
+ std::string const& cpackComponentName)
+{
+ EmitInstallRegistryValue(registryKey, cpackComponentName, std::string());
+}
+
+void cmWIXFilesSourceWriter::EmitDesktopShortcutRegistryValue(
+ std::string const& registryKey,
+ std::string const& cpackComponentName)
+{
+ EmitInstallRegistryValue(registryKey, cpackComponentName, "_desktop");
+}
+
+void cmWIXFilesSourceWriter::EmitInstallRegistryValue(
+ std::string const& registryKey,
+ std::string const& cpackComponentName,
+ std::string const& suffix)
+{
+ std::string valueName;
+ if(!cpackComponentName.empty())
+ {
+ valueName = cpackComponentName + "_";
+ }
+
+ valueName += "installed";
+ valueName += suffix;
+
+ BeginElement("RegistryValue");
+ AddAttribute("Root", "HKCU");
+ AddAttribute("Key", registryKey);
+ AddAttribute("Name", valueName);
+ AddAttribute("Type", "integer");
+ AddAttribute("Value", "1");
+ AddAttribute("KeyPath", "yes");
+ EndElement("RegistryValue");
+}
+
+void cmWIXFilesSourceWriter::EmitUninstallShortcut(
+ std::string const& packageName)
+{
+ BeginElement("Shortcut");
+ AddAttribute("Id", "UNINSTALL");
+ AddAttribute("Name", "Uninstall " + packageName);
+ AddAttribute("Description", "Uninstalls " + packageName);
+ AddAttribute("Target", "[SystemFolder]msiexec.exe");
+ AddAttribute("Arguments", "/x [ProductCode]");
+ EndElement("Shortcut");
+}
+
+std::string cmWIXFilesSourceWriter::EmitComponentCreateFolder(
+ std::string const& directoryId,
+ std::string const& guid,
+ cmInstalledFile const* installedFile)
+{
+ std::string componentId =
+ std::string("CM_C_EMPTY_") + directoryId;
+
+ BeginElement("DirectoryRef");
+ AddAttribute("Id", directoryId);
+
+ BeginElement("Component");
+ AddAttribute("Id", componentId);
+ AddAttribute("Guid", guid);
+
+ BeginElement("CreateFolder");
+
+ if(installedFile)
+ {
+ cmWIXAccessControlList acl(Logger, *installedFile, *this);
+ acl.Apply();
+ }
+
+ EndElement("CreateFolder");
+ EndElement("Component");
+ EndElement("DirectoryRef");
+
+ return componentId;
+}
+
+std::string cmWIXFilesSourceWriter::EmitComponentFile(
+ std::string const& directoryId,
+ std::string const& id,
+ std::string const& filePath,
+ cmWIXPatch &patch,
+ cmInstalledFile const* installedFile)
+{
+ std::string componentId = std::string("CM_C") + id;
+ std::string fileId = std::string("CM_F") + id;
+
+ BeginElement("DirectoryRef");
+ AddAttribute("Id", directoryId);
+
+ BeginElement("Component");
+ AddAttribute("Id", componentId);
+ AddAttribute("Guid", "*");
+
+ if(installedFile)
+ {
+ if(installedFile->GetPropertyAsBool("CPACK_NEVER_OVERWRITE"))
+ {
+ AddAttribute("NeverOverwrite", "yes");
+ }
+ if(installedFile->GetPropertyAsBool("CPACK_PERMANENT"))
+ {
+ AddAttribute("Permanent", "yes");
+ }
+ }
+
+ BeginElement("File");
+ AddAttribute("Id", fileId);
+ AddAttribute("Source", filePath);
+ AddAttribute("KeyPath", "yes");
+
+ mode_t fileMode = 0;
+ cmSystemTools::GetPermissions(filePath.c_str(), fileMode);
+
+ if(!(fileMode & S_IWRITE))
+ {
+ AddAttribute("ReadOnly", "yes");
+ }
+
+ if(installedFile)
+ {
+ cmWIXAccessControlList acl(Logger, *installedFile, *this);
+ acl.Apply();
+ }
+
+ patch.ApplyFragment(fileId, *this);
+ EndElement("File");
+
+ patch.ApplyFragment(componentId, *this);
+ EndElement("Component");
+ EndElement("DirectoryRef");
+
+ return componentId;
+}
diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.h b/Source/CPack/WiX/cmWIXFilesSourceWriter.h
new file mode 100644
index 0000000000..b0a4af8f8e
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.h
@@ -0,0 +1,68 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmWIXFilesSourceWriter_h
+#define cmWIXFilesSourceWriter_h
+
+#include "cmWIXSourceWriter.h"
+#include "cmWIXShortcut.h"
+#include "cmWIXPatch.h"
+
+#include <CPack/cmCPackGenerator.h>
+
+/** \class cmWIXFilesSourceWriter
+ * \brief Helper class to generate files.wxs
+ */
+class cmWIXFilesSourceWriter : public cmWIXSourceWriter
+{
+public:
+ cmWIXFilesSourceWriter(cmCPackLog* logger,
+ std::string const& filename);
+
+ void EmitShortcut(
+ std::string const& id,
+ cmWIXShortcut const& shortcut,
+ bool desktop);
+
+ void EmitRemoveFolder(std::string const& id);
+
+ void EmitStartMenuShortcutRegistryValue(
+ std::string const& registryKey,
+ std::string const& cpackComponentName);
+
+ void EmitDesktopShortcutRegistryValue(
+ std::string const& registryKey,
+ std::string const& cpackComponentName);
+
+ void EmitUninstallShortcut(std::string const& packageName);
+
+ std::string EmitComponentCreateFolder(
+ std::string const& directoryId,
+ std::string const& guid,
+ cmInstalledFile const* installedFile);
+
+ std::string EmitComponentFile(
+ std::string const& directoryId,
+ std::string const& id,
+ std::string const& filePath,
+ cmWIXPatch &patch,
+ cmInstalledFile const* installedFile);
+
+private:
+ void EmitInstallRegistryValue(
+ std::string const& registryKey,
+ std::string const& cpackComponentName,
+ std::string const& suffix);
+};
+
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXPatch.cxx b/Source/CPack/WiX/cmWIXPatch.cxx
new file mode 100644
index 0000000000..b5202e0c01
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXPatch.cxx
@@ -0,0 +1,91 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 "cmWIXPatch.h"
+
+#include <CPack/cmCPackGenerator.h>
+
+cmWIXPatch::cmWIXPatch(cmCPackLog* logger):
+ Logger(logger)
+{
+
+}
+
+void cmWIXPatch::LoadFragments(std::string const& patchFilePath)
+{
+ cmWIXPatchParser parser(Fragments, Logger);
+ parser.ParseFile(patchFilePath.c_str());
+}
+
+void cmWIXPatch::ApplyFragment(
+ std::string const& id, cmWIXSourceWriter& writer)
+{
+ cmWIXPatchParser::fragment_map_t::iterator i = Fragments.find(id);
+ if(i == Fragments.end()) return;
+
+ const cmWIXPatchElement& fragment = i->second;
+ for(cmWIXPatchElement::child_list_t::const_iterator
+ j = fragment.children.begin(); j != fragment.children.end(); ++j)
+ {
+ ApplyElement(**j, writer);
+ }
+
+ Fragments.erase(i);
+}
+
+void cmWIXPatch::ApplyElement(
+ const cmWIXPatchElement& element, cmWIXSourceWriter& writer)
+{
+ writer.BeginElement(element.name);
+
+ for(cmWIXPatchElement::attributes_t::const_iterator
+ i = element.attributes.begin(); i != element.attributes.end(); ++i)
+ {
+ 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);
+ }
+
+ writer.EndElement(element.name);
+}
+
+
+bool cmWIXPatch::CheckForUnappliedFragments()
+{
+ std::string fragmentList;
+ for(cmWIXPatchParser::fragment_map_t::const_iterator
+ i = Fragments.begin(); i != Fragments.end(); ++i)
+ {
+ if(!fragmentList.empty())
+ {
+ fragmentList += ", ";
+ }
+
+ fragmentList += "'";
+ fragmentList += i->first;
+ fragmentList += "'";
+ }
+
+ if(fragmentList.size())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Some XML patch fragments did not have matching IDs: " <<
+ fragmentList << std::endl);
+ return false;
+ }
+
+ return true;
+}
diff --git a/Source/CPack/WiX/cmWIXPatch.h b/Source/CPack/WiX/cmWIXPatch.h
new file mode 100644
index 0000000000..7b7b2f1700
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXPatch.h
@@ -0,0 +1,45 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmWIXPatch_h
+#define cmWIXPatch_h
+
+#include "cmWIXSourceWriter.h"
+#include "cmWIXPatchParser.h"
+
+#include <string>
+
+/** \class cmWIXPatch
+ * \brief Class that maintains and applies patch fragments
+ */
+class cmWIXPatch
+{
+public:
+ cmWIXPatch(cmCPackLog* logger);
+
+ void LoadFragments(std::string const& patchFilePath);
+
+ void ApplyFragment(std::string const& id, cmWIXSourceWriter& writer);
+
+ bool CheckForUnappliedFragments();
+
+private:
+ void ApplyElement(const cmWIXPatchElement& element,
+ cmWIXSourceWriter& writer);
+
+ cmCPackLog* Logger;
+
+ cmWIXPatchParser::fragment_map_t Fragments;
+};
+
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXPatchParser.cxx b/Source/CPack/WiX/cmWIXPatchParser.cxx
new file mode 100644
index 0000000000..ef67b23ec5
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXPatchParser.cxx
@@ -0,0 +1,143 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 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 "cmWIXPatchParser.h"
+
+#include <CPack/cmCPackGenerator.h>
+
+#include <cm_expat.h>
+
+cmWIXPatchElement::~cmWIXPatchElement()
+{
+ for(child_list_t::iterator i = children.begin(); i != children.end(); ++i)
+ {
+ delete *i;
+ }
+}
+
+cmWIXPatchParser::cmWIXPatchParser(
+ fragment_map_t& fragments, cmCPackLog* logger):
+ Logger(logger),
+ State(BEGIN_DOCUMENT),
+ Valid(true),
+ Fragments(fragments)
+{
+
+}
+
+void cmWIXPatchParser::StartElement(const std::string& name, const char **atts)
+{
+ if(State == BEGIN_DOCUMENT)
+ {
+ if(name == "CPackWiXPatch")
+ {
+ State = BEGIN_FRAGMENTS;
+ }
+ else
+ {
+ ReportValidationError("Expected root element 'CPackWiXPatch'");
+ }
+ }
+ else if(State == BEGIN_FRAGMENTS)
+ {
+ if(name == "CPackWiXFragment")
+ {
+ State = INSIDE_FRAGMENT;
+ StartFragment(atts);
+ }
+ else
+ {
+ ReportValidationError("Expected 'CPackWixFragment' element");
+ }
+ }
+ else if(State == INSIDE_FRAGMENT)
+ {
+ cmWIXPatchElement &parent = *ElementStack.back();
+
+ parent.children.resize(parent.children.size() + 1);
+ cmWIXPatchElement*& currentElement = parent.children.back();
+ currentElement = new cmWIXPatchElement;
+ currentElement->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;
+ }
+
+ ElementStack.push_back(currentElement);
+ }
+}
+
+void cmWIXPatchParser::StartFragment(const char **attributes)
+{
+ for(size_t i = 0; attributes[i]; i += 2)
+ {
+ std::string key = attributes[i];
+ std::string value = attributes[i+1];
+
+ if(key == "Id")
+ {
+ if(Fragments.find(value) != Fragments.end())
+ {
+ std::stringstream tmp;
+ tmp << "Invalid reuse of 'CPackWixFragment' 'Id': " << value;
+ ReportValidationError(tmp.str());
+ }
+
+ ElementStack.push_back(&Fragments[value]);
+ }
+ else
+ {
+ ReportValidationError(
+ "The only allowed 'CPackWixFragment' attribute is 'Id'");
+ }
+ }
+}
+
+void cmWIXPatchParser::EndElement(const std::string& name)
+{
+ if(State == INSIDE_FRAGMENT)
+ {
+ if(name == "CPackWiXFragment")
+ {
+ State = BEGIN_FRAGMENTS;
+ ElementStack.clear();
+ }
+ else
+ {
+ ElementStack.pop_back();
+ }
+ }
+}
+
+void cmWIXPatchParser::ReportError(int line, int column, const char* msg)
+{
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while processing XML patch file at " << line << ":" << column <<
+ ": "<< msg << std::endl);
+ Valid = false;
+}
+
+void cmWIXPatchParser::ReportValidationError(std::string const& message)
+{
+ ReportError(XML_GetCurrentLineNumber(Parser),
+ XML_GetCurrentColumnNumber(Parser),
+ message.c_str());
+}
+
+bool cmWIXPatchParser::IsValid() const
+{
+ return Valid;
+}
diff --git a/Source/CPack/WiX/cmWIXPatchParser.h b/Source/CPack/WiX/cmWIXPatchParser.h
new file mode 100644
index 0000000000..acfb4c071a
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXPatchParser.h
@@ -0,0 +1,75 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 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 cmCPackWIXPatchParser_h
+#define cmCPackWIXPatchParser_h
+
+#include <cmXMLParser.h>
+
+#include <CPack/cmCPackLog.h>
+
+#include <map>
+#include <list>
+
+struct cmWIXPatchElement
+{
+ ~cmWIXPatchElement();
+
+ typedef std::list<cmWIXPatchElement*> child_list_t;
+ typedef std::map<std::string, std::string> attributes_t;
+
+ std::string name;
+ child_list_t children;
+ attributes_t attributes;
+};
+
+/** \class cmWIXPatchParser
+ * \brief Helper class that parses XML patch files (CPACK_WIX_PATCH_FILE)
+ */
+class cmWIXPatchParser : public cmXMLParser
+{
+public:
+ typedef std::map<std::string, cmWIXPatchElement> fragment_map_t;
+
+ cmWIXPatchParser(fragment_map_t& Fragments, cmCPackLog* logger);
+
+private:
+ virtual void StartElement(const std::string& name, const char **atts);
+
+ void StartFragment(const char **attributes);
+
+ virtual void EndElement(const std::string& name);
+ virtual void ReportError(int line, int column, const char* msg);
+
+ void ReportValidationError(std::string const& message);
+
+ bool IsValid() const;
+
+ cmCPackLog* Logger;
+
+ enum ParserState
+ {
+ BEGIN_DOCUMENT,
+ BEGIN_FRAGMENTS,
+ INSIDE_FRAGMENT
+ };
+
+ ParserState State;
+
+ bool Valid;
+
+ fragment_map_t& Fragments;
+
+ std::list<cmWIXPatchElement*> ElementStack;
+};
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx
new file mode 100644
index 0000000000..f27caa941d
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx
@@ -0,0 +1,228 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 "cmWIXRichTextFormatWriter.h"
+
+#include <cmVersion.h>
+
+cmWIXRichTextFormatWriter::cmWIXRichTextFormatWriter(
+ std::string const& filename):
+ File(filename.c_str(), std::ios::binary)
+{
+ StartGroup();
+ WriteHeader();
+ WriteDocumentPrefix();
+}
+
+cmWIXRichTextFormatWriter::~cmWIXRichTextFormatWriter()
+{
+ EndGroup();
+
+ /* I haven't seen this in the RTF spec but
+ * wordpad terminates its RTF like this */
+ File << "\r\n";
+ File.put(0);
+}
+
+void cmWIXRichTextFormatWriter::AddText(std::string const& text)
+{
+ typedef unsigned char rtf_byte_t;
+
+ for(size_t i = 0; i < text.size(); ++i)
+ {
+ rtf_byte_t c = rtf_byte_t(text[i]);
+
+ switch(c)
+ {
+ case '\\':
+ File << "\\\\";
+ break;
+ case '{':
+ File << "\\{";
+ break;
+ case '}':
+ File << "\\}";
+ break;
+ case '\n':
+ File << "\\par\r\n";
+ break;
+ case '\r':
+ continue;
+ default:
+ {
+ if(c <= 0x7F)
+ {
+ File << c;
+ }
+ else
+ {
+ if(c <= 0xC0)
+ {
+ EmitInvalidCodepoint(c);
+ }
+ else if(c < 0xE0 && i+1 < text.size())
+ {
+ EmitUnicodeCodepoint(
+ (text[i+1] & 0x3F) |
+ ((c & 0x1F) << 6)
+ );
+ i+= 1;
+ }
+ else if(c < 0xF0 && i+2 < text.size())
+ {
+ EmitUnicodeCodepoint(
+ (text[i+2] & 0x3F) |
+ ((text[i+1] & 0x3F) << 6) |
+ ((c & 0xF) << 12)
+ );
+ i += 2;
+ }
+ else if(c < 0xF8 && i+3 < text.size())
+ {
+ EmitUnicodeCodepoint(
+ (text[i+3] & 0x3F) |
+ ((text[i+2] & 0x3F) << 6) |
+ ((text[i+1] & 0x3F) << 12) |
+ ((c & 0x7) << 18)
+ );
+ i += 3;
+ }
+ else
+ {
+ EmitInvalidCodepoint(c);
+ }
+ }
+ }
+ break;
+ }
+ }
+}
+
+void cmWIXRichTextFormatWriter::WriteHeader()
+{
+ ControlWord("rtf1");
+ ControlWord("ansi");
+ ControlWord("ansicpg1252");
+ ControlWord("deff0");
+ ControlWord("deflang1031");
+
+ WriteFontTable();
+ WriteColorTable();
+ WriteGenerator();
+}
+
+void cmWIXRichTextFormatWriter::WriteFontTable()
+{
+ StartGroup();
+ ControlWord("fonttbl");
+
+ StartGroup();
+ ControlWord("f0");
+ ControlWord("fswiss");
+ ControlWord("fcharset0 Arial;");
+ EndGroup();
+
+ EndGroup();
+}
+
+void cmWIXRichTextFormatWriter::WriteColorTable()
+{
+ StartGroup();
+ ControlWord("colortbl ;");
+ ControlWord("red255");
+ ControlWord("green0");
+ ControlWord("blue0;");
+ ControlWord("red0");
+ ControlWord("green255");
+ ControlWord("blue0;");
+ ControlWord("red0");
+ ControlWord("green0");
+ ControlWord("blue255;");
+ EndGroup();
+}
+
+void cmWIXRichTextFormatWriter::WriteGenerator()
+{
+ StartGroup();
+ NewControlWord("generator");
+ File << " CPack WiX Generator (" << cmVersion::GetCMakeVersion() << ");";
+ EndGroup();
+}
+
+void cmWIXRichTextFormatWriter::WriteDocumentPrefix()
+{
+ ControlWord("viewkind4");
+ ControlWord("uc1");
+ ControlWord("pard");
+ ControlWord("f0");
+ ControlWord("fs20");
+}
+
+void cmWIXRichTextFormatWriter::ControlWord(std::string const& keyword)
+{
+ File << "\\" << keyword;
+}
+
+void cmWIXRichTextFormatWriter::NewControlWord(std::string const& keyword)
+{
+ File << "\\*\\" << keyword;
+}
+
+void cmWIXRichTextFormatWriter::StartGroup()
+{
+ File.put('{');
+}
+
+void cmWIXRichTextFormatWriter::EndGroup()
+{
+ File.put('}');
+}
+
+void cmWIXRichTextFormatWriter::EmitUnicodeCodepoint(int c)
+{
+ // Do not emit byte order mark (BOM)
+ if(c == 0xFEFF)
+ {
+ return;
+ }
+ else if(c <= 0xFFFF)
+ {
+ EmitUnicodeSurrogate(c);
+ }
+ else
+ {
+ c -= 0x10000;
+ EmitUnicodeSurrogate(((c >> 10) & 0x3FF) + 0xD800);
+ EmitUnicodeSurrogate((c & 0x3FF) + 0xDC00);
+ }
+}
+
+void cmWIXRichTextFormatWriter::EmitUnicodeSurrogate(int c)
+{
+ ControlWord("u");
+ if(c <= 32767)
+ {
+ File << c;
+ }
+ else
+ {
+ File << (c - 65536);
+ }
+ File << "?";
+}
+
+void cmWIXRichTextFormatWriter::EmitInvalidCodepoint(int c)
+{
+ ControlWord("cf1 ");
+ File << "[INVALID-BYTE-" << int(c) << "]";
+ ControlWord("cf0 ");
+}
diff --git a/Source/CPack/WiX/cmWIXRichTextFormatWriter.h b/Source/CPack/WiX/cmWIXRichTextFormatWriter.h
new file mode 100644
index 0000000000..f6327fbd5d
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXRichTextFormatWriter.h
@@ -0,0 +1,52 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 cmWIXRichTextFormatWriter_h
+#define cmWIXRichTextFormatWriter_h
+
+#include <cmsys/FStream.hxx>
+
+/** \class cmWIXRichtTextFormatWriter
+ * \brief Helper class to generate Rich Text Format (RTF) documents
+ * from plain text (e.g. for license and welcome text)
+ */
+class cmWIXRichTextFormatWriter
+{
+public:
+ cmWIXRichTextFormatWriter(std::string const& filename);
+ ~cmWIXRichTextFormatWriter();
+
+ void AddText(std::string const& text);
+
+private:
+ void WriteHeader();
+ void WriteFontTable();
+ void WriteColorTable();
+ void WriteGenerator();
+
+ void WriteDocumentPrefix();
+
+ void ControlWord(std::string const& keyword);
+ void NewControlWord(std::string const& keyword);
+
+ void StartGroup();
+ void EndGroup();
+
+ void EmitUnicodeCodepoint(int c);
+ void EmitUnicodeSurrogate(int c);
+
+ void EmitInvalidCodepoint(int c);
+
+ cmsys::ofstream File;
+};
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXShortcut.h b/Source/CPack/WiX/cmWIXShortcut.h
new file mode 100644
index 0000000000..93095e03fe
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXShortcut.h
@@ -0,0 +1,29 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmWIXFilesShortcut_h
+#define cmWIXFilesShortcut_h
+
+#include <string>
+
+struct cmWIXShortcut
+{
+ cmWIXShortcut()
+ :desktop(false)
+ {}
+
+ std::string textLabel;
+ std::string workingDirectoryId;
+ bool desktop;
+};
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx
new file mode 100644
index 0000000000..aad19daf11
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx
@@ -0,0 +1,217 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 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 "cmWIXSourceWriter.h"
+
+#include <CPack/cmCPackGenerator.h>
+
+#include <windows.h>
+
+cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger,
+ std::string const& filename,
+ bool isIncludeFile):
+ Logger(logger),
+ File(filename.c_str()),
+ State(DEFAULT),
+ SourceFilename(filename)
+{
+ WriteXMLDeclaration();
+
+ if(isIncludeFile)
+ {
+ BeginElement("Include");
+ }
+ else
+ {
+ BeginElement("Wix");
+ }
+
+ AddAttribute("xmlns", "http://schemas.microsoft.com/wix/2006/wi");
+}
+
+cmWIXSourceWriter::~cmWIXSourceWriter()
+{
+ if(Elements.size() > 1)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ Elements.size() - 1 << " WiX elements were still open when closing '" <<
+ SourceFilename << "'" << std::endl);
+ return;
+ }
+
+ EndElement(Elements.back());
+}
+
+void cmWIXSourceWriter::BeginElement(std::string const& name)
+{
+ if(State == BEGIN)
+ {
+ File << ">";
+ }
+
+ File << "\n";
+ Indent(Elements.size());
+ File << "<" << name;
+
+ Elements.push_back(name);
+ State = BEGIN;
+}
+
+void cmWIXSourceWriter::EndElement(std::string const& name)
+{
+ if(Elements.empty())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "can not end WiX element with no open elements in '" <<
+ SourceFilename << "'" << std::endl);
+ return;
+ }
+
+ if(Elements.back() != name)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "WiX element <" << Elements.back() <<
+ "> can not be closed by </" << name << "> in '" <<
+ SourceFilename << "'" << std::endl);
+ return;
+ }
+
+ if(State == DEFAULT)
+ {
+ File << "\n";
+ Indent(Elements.size()-1);
+ File << "</" << Elements.back() << ">";
+ }
+ else
+ {
+ File << "/>";
+ }
+
+ Elements.pop_back();
+ State = DEFAULT;
+}
+
+void cmWIXSourceWriter::AddProcessingInstruction(
+ std::string const& target, std::string const& content)
+{
+ if(State == BEGIN)
+ {
+ File << ">";
+ }
+
+ File << "\n";
+ Indent(Elements.size());
+ File << "<?" << target << " " << content << "?>";
+
+ State = DEFAULT;
+}
+
+void cmWIXSourceWriter::AddAttribute(
+ std::string const& key, std::string const& value)
+{
+ std::string utf8 = WindowsCodepageToUtf8(value);
+
+ File << " " << key << "=\"" << EscapeAttributeValue(utf8) << '"';
+}
+
+void cmWIXSourceWriter::AddAttributeUnlessEmpty(
+ std::string const& key, std::string const& value)
+{
+ if(value.size())
+ {
+ AddAttribute(key, value);
+ }
+}
+
+std::string cmWIXSourceWriter::WindowsCodepageToUtf8(std::string const& value)
+{
+ if(value.empty())
+ {
+ return std::string();
+ }
+
+ int characterCount = MultiByteToWideChar(
+ CP_ACP, 0, value.c_str(), static_cast<int>(value.size()), 0, 0);
+
+ if(characterCount == 0)
+ {
+ return std::string();
+ }
+
+ std::vector<wchar_t> utf16(characterCount);
+
+ MultiByteToWideChar(
+ CP_ACP, 0, value.c_str(), static_cast<int>(value.size()),
+ &utf16[0], static_cast<int>(utf16.size()));
+
+ int utf8ByteCount = WideCharToMultiByte(
+ CP_UTF8, 0, &utf16[0], static_cast<int>(utf16.size()), 0, 0, 0, 0);
+
+ if(utf8ByteCount == 0)
+ {
+ return std::string();
+ }
+
+ std::vector<char> utf8(utf8ByteCount);
+
+ WideCharToMultiByte(CP_UTF8, 0, &utf16[0], static_cast<int>(utf16.size()),
+ &utf8[0], static_cast<int>(utf8.size()), 0, 0);
+
+ return std::string(&utf8[0], utf8.size());
+}
+
+
+void cmWIXSourceWriter::WriteXMLDeclaration()
+{
+ File << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
+}
+
+void cmWIXSourceWriter::Indent(size_t count)
+{
+ for(size_t i = 0; i < count; ++i)
+ {
+ File << " ";
+ }
+}
+
+std::string cmWIXSourceWriter::EscapeAttributeValue(
+ std::string const& value)
+{
+ std::string result;
+ result.reserve(value.size());
+
+ char c = 0;
+ for(size_t i = 0 ; i < value.size(); ++i)
+ {
+ c = value[i];
+ switch(c)
+ {
+ case '<':
+ result += "&lt;";
+ break;
+ case '>':
+ result += "&gt;";
+ break;
+ case '&':
+ result +="&amp;";
+ break;
+ case '"':
+ result += "&quot;";
+ break;
+ default:
+ result += c;
+ break;
+ }
+ }
+
+ return result;
+}
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.h b/Source/CPack/WiX/cmWIXSourceWriter.h
new file mode 100644
index 0000000000..3957d9663b
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXSourceWriter.h
@@ -0,0 +1,73 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 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 cmWIXSourceWriter_h
+#define cmWIXSourceWriter_h
+
+#include <vector>
+#include <string>
+#include <cmsys/FStream.hxx>
+
+#include <CPack/cmCPackLog.h>
+
+/** \class cmWIXSourceWriter
+ * \brief Helper class to generate XML WiX source files
+ */
+class cmWIXSourceWriter
+{
+public:
+ cmWIXSourceWriter(cmCPackLog* logger,
+ std::string const& filename, bool isIncludeFile = false);
+
+ ~cmWIXSourceWriter();
+
+ void BeginElement(std::string const& name);
+
+ void EndElement(std::string const& name);
+
+ void AddProcessingInstruction(
+ std::string const& target, std::string const& content);
+
+ void AddAttribute(
+ std::string const& key, std::string const& value);
+
+ void AddAttributeUnlessEmpty(
+ std::string const& key, std::string const& value);
+
+ static std::string WindowsCodepageToUtf8(std::string const& value);
+
+protected:
+ cmCPackLog* Logger;
+
+private:
+ enum State
+ {
+ DEFAULT,
+ BEGIN
+ };
+
+ void WriteXMLDeclaration();
+
+ void Indent(size_t count);
+
+ static std::string EscapeAttributeValue(std::string const& value);
+
+ cmsys::ofstream File;
+
+ State State;
+
+ std::vector<std::string> Elements;
+
+ std::string SourceFilename;
+};
+
+#endif
diff --git a/Source/CPack/bills-comments.txt b/Source/CPack/bills-comments.txt
new file mode 100644
index 0000000000..c3b4ee8e71
--- /dev/null
+++ b/Source/CPack/bills-comments.txt
@@ -0,0 +1,68 @@
+cpack.cxx
+
+cmCPackGenerators -- creates cmCPackGenericGenerator's via NewGenerator
+ - a cmCPackGenericGenerator factory
+
+
+cmCPackGenericGenerator::Initialize
+ this->InitializeInternal
+ CPACK_INCLUDE_TOPLEVEL_DIRECTORY = 0 turns off
+
+
+// binary package run
+cmCPackGenericGenerator::ProcessGenerator // DoPackage
+ cmCPackGenericGenerator::PrepareNames -- sets a bunch of CPACK_vars
+ cmCPackGenericGenerator::InstallProject
+ run preinstall (make preinstall/fast)
+ call ReadListFile(cmake_install.cmake)
+ glob recurse in install directory to get list of files
+ this->CompressFiles with the list of files
+
+
+// source package run
+cmCPackGenericGenerator::ProcessGenerator // DoPackage
+ cmCPackGenericGenerator::PrepareNames -- sets a bunch of CPACK_vars
+ cmCPackGenericGenerator::InstallProject -->
+ if set CPACK_INSTALLED_DIRECTORIES
+ glob the files in that directory
+ copy those files to the tmp install directory _CPack something
+ glob recurse in install directory to get list of files
+ this->CompressFiles with the list of files
+
+
+cmCPackGenericGenerator::InstallProject is used for both source and binary
+packages. It is controled based on values set in CPACK_ variables.
+
+
+InstallProject
+ 1. CPACK_INSTALL_COMMANDS - a list of commands used to install the package
+
+ 2. CPACK_INSTALLED_DIRECTORIES - copy this directory to CPACK_TEMPORARY_DIRECTORY
+
+ 3. CPACK_INSTALL_CMAKE_PROJECTS - a cmake install script
+ - run make preinstall
+ - run cmake_install.cmake
+ - set CMAKE_INSTALL_PREFIX to the temp directory
+ - CPACK_BUILD_CONFIG check this and set the BUILD_TYPE to it
+ - ReadListFile on the install script cmake_install.cmake
+ - run strip on the executables and libraries if CPACK_STRIP_FILES is TRUE
+
+Recommendations:
+
+rename cmCPackGenerators to cmCPackGeneratorFactory
+
+rename cmCPackGenericGenerator --> cmCPackGenerator
+
+rename cmCPackGenericGenerator::ProcessGenerator -> cmCPackGenerator::DoPackage
+
+
+break up cmCPackGenerator::InstallProject so it calls the following:
+
+// run user provided install commands
+ cmCPackGenerator::RunInstallCommands();
+// copy entire directories that need no processing like source trees
+ cmCPackGenerator::CopyPreInstalledDirectories();
+// run the cmake install scripts if provided
+ cmCPackGenerator::RunCMakeInstallScripts()
+
+-
diff --git a/Source/CPack/cmCPack7zGenerator.cxx b/Source/CPack/cmCPack7zGenerator.cxx
new file mode 100644
index 0000000000..ce31ad4554
--- /dev/null
+++ b/Source/CPack/cmCPack7zGenerator.cxx
@@ -0,0 +1,25 @@
+/*============================================================================
+ 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 "cmCPack7zGenerator.h"
+
+//----------------------------------------------------------------------
+cmCPack7zGenerator::cmCPack7zGenerator()
+ :cmCPackArchiveGenerator(cmArchiveWrite::CompressNone,
+ cmArchiveWrite::Type7Zip)
+{
+}
+
+//----------------------------------------------------------------------
+cmCPack7zGenerator::~cmCPack7zGenerator()
+{
+}
diff --git a/Source/CPack/cmCPack7zGenerator.h b/Source/CPack/cmCPack7zGenerator.h
new file mode 100644
index 0000000000..f5a323f1e4
--- /dev/null
+++ b/Source/CPack/cmCPack7zGenerator.h
@@ -0,0 +1,36 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPack7zGenerator_h
+#define cmCPack7zGenerator_h
+
+#include "cmCPackArchiveGenerator.h"
+
+/** \class cmCPack7zGenerator
+ * \brief A generator for 7z files
+ */
+class cmCPack7zGenerator : public cmCPackArchiveGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPack7zGenerator, cmCPackArchiveGenerator);
+
+ /**
+ * Construct generator
+ */
+ cmCPack7zGenerator();
+ virtual ~cmCPack7zGenerator();
+
+protected:
+ virtual const char* GetOutputExtension() { return ".7z"; }
+};
+
+#endif
diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx
new file mode 100644
index 0000000000..6e7b8d7c89
--- /dev/null
+++ b/Source/CPack/cmCPackArchiveGenerator.cxx
@@ -0,0 +1,314 @@
+/*============================================================================
+ 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 "cmCPackArchiveGenerator.h"
+
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackLog.h"
+#include <errno.h>
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Directory.hxx>
+#include <cm_libarchive.h>
+
+//----------------------------------------------------------------------
+cmCPackArchiveGenerator::cmCPackArchiveGenerator(cmArchiveWrite::Compress t,
+ cmArchiveWrite::Type at)
+{
+ this->Compress = t;
+ this->Archive = at;
+}
+
+//----------------------------------------------------------------------
+cmCPackArchiveGenerator::~cmCPackArchiveGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackArchiveGenerator::InitializeInternal()
+{
+ this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
+ return this->Superclass::InitializeInternal();
+}
+//----------------------------------------------------------------------
+int cmCPackArchiveGenerator::addOneComponentToArchive(cmArchiveWrite& archive,
+ cmCPackComponent* component)
+{
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, " - packaging component: "
+ << component->Name
+ << std::endl);
+ // Add the files of this component to the archive
+ std::string localToplevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
+ localToplevel += "/"+ component->Name;
+ std::string dir = cmSystemTools::GetCurrentWorkingDirectory();
+ // Change to local toplevel
+ cmSystemTools::ChangeDirectory(localToplevel.c_str());
+ std::string filePrefix;
+ if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY"))
+ {
+ filePrefix = this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ filePrefix += "/";
+ }
+ std::vector<std::string>::const_iterator fileIt;
+ for (fileIt = component->Files.begin(); fileIt != component->Files.end();
+ ++fileIt )
+ {
+ std::string rp = filePrefix + *fileIt;
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,"Adding file: "
+ << rp << std::endl);
+ archive.Add(rp);
+ if (!archive)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "ERROR while packaging files: "
+ << archive.GetError()
+ << std::endl);
+ return 0;
+ }
+ }
+ // Go back to previous dir
+ cmSystemTools::ChangeDirectory(dir.c_str());
+ return 1;
+}
+
+/*
+ * The macro will open/create a file 'filename'
+ * an declare and open the associated
+ * cmArchiveWrite 'archive' object.
+ */
+#define DECLARE_AND_OPEN_ARCHIVE(filename,archive) \
+cmGeneratedFileStream gf; \
+gf.Open(filename.c_str(), false, true); \
+if (!GenerateHeader(&gf)) \
+ { \
+ cmCPackLogger(cmCPackLog::LOG_ERROR, \
+ "Problem to generate Header for archive < " \
+ << filename \
+ << ">." << std::endl); \
+ return 0; \
+ } \
+cmArchiveWrite archive(gf,this->Compress, this->Archive); \
+if (!archive) \
+ { \
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem to create archive < " \
+ << filename \
+ << ">. ERROR =" \
+ << archive.GetError() \
+ << std::endl); \
+ return 0; \
+ }
+
+//----------------------------------------------------------------------
+int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup)
+{
+ packageFileNames.clear();
+ // The default behavior is to have one package by component group
+ // unless CPACK_COMPONENTS_IGNORE_GROUP is specified.
+ if (!ignoreGroup)
+ {
+ std::map<std::string, cmCPackComponentGroup>::iterator compGIt;
+ for (compGIt=this->ComponentGroups.begin();
+ compGIt!=this->ComponentGroups.end(); ++compGIt)
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
+ << compGIt->first
+ << std::endl);
+ // Begin the archive for this group
+ std::string packageFileName= std::string(toplevel);
+ packageFileName += "/"+
+ GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
+ compGIt->first,
+ true)
+ + this->GetOutputExtension();
+ // open a block in order to automatically close archive
+ // at the end of the block
+ {
+ DECLARE_AND_OPEN_ARCHIVE(packageFileName,archive);
+ // now iterate over the component of this group
+ std::vector<cmCPackComponent*>::iterator compIt;
+ for (compIt=(compGIt->second).Components.begin();
+ compIt!=(compGIt->second).Components.end();
+ ++compIt)
+ {
+ // Add the files of this component to the archive
+ addOneComponentToArchive(archive,*compIt);
+ }
+ }
+ // add the generated package to package file names list
+ packageFileNames.push_back(packageFileName);
+ }
+ // Handle Orphan components (components not belonging to any groups)
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt=this->Components.begin();
+ compIt!=this->Components.end(); ++compIt )
+ {
+ // Does the component belong to a group?
+ if (compIt->second.Group==NULL)
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Component <"
+ << compIt->second.Name
+ << "> does not belong to any group, package it separately."
+ << std::endl);
+ std::string localToplevel(
+ this->GetOption("CPACK_TEMPORARY_DIRECTORY")
+ );
+ std::string packageFileName = std::string(toplevel);
+
+ localToplevel += "/"+ compIt->first;
+ packageFileName += "/"+
+ GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
+ compIt->first,
+ false)
+ + this->GetOutputExtension();
+ {
+ DECLARE_AND_OPEN_ARCHIVE(packageFileName,archive);
+ // Add the files of this component to the archive
+ addOneComponentToArchive(archive,&(compIt->second));
+ }
+ // add the generated package to package file names list
+ packageFileNames.push_back(packageFileName);
+ }
+ }
+ }
+ // CPACK_COMPONENTS_IGNORE_GROUPS is set
+ // We build 1 package per component
+ else
+ {
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt=this->Components.begin();
+ compIt!=this->Components.end(); ++compIt )
+ {
+ std::string localToplevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
+ std::string packageFileName = std::string(toplevel);
+
+ localToplevel += "/"+ compIt->first;
+ packageFileName += "/"+
+ GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
+ compIt->first,
+ false)
+ + this->GetOutputExtension();
+ {
+ DECLARE_AND_OPEN_ARCHIVE(packageFileName,archive);
+ // Add the files of this component to the archive
+ addOneComponentToArchive(archive,&(compIt->second));
+ }
+ // add the generated package to package file names list
+ packageFileNames.push_back(packageFileName);
+ }
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackArchiveGenerator::PackageComponentsAllInOne()
+{
+ // reset the package file names
+ packageFileNames.clear();
+ packageFileNames.push_back(std::string(toplevel));
+ packageFileNames[0] += "/"
+ +std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
+ + this->GetOutputExtension();
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Packaging all groups in one package..."
+ "(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE is set)"
+ << std::endl);
+ DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0],archive);
+
+ // The ALL COMPONENTS in ONE package case
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt=this->Components.begin();compIt!=this->Components.end();
+ ++compIt )
+ {
+ // Add the files of this component to the archive
+ addOneComponentToArchive(archive,&(compIt->second));
+ }
+
+ // archive goes out of scope so it will finalized and closed.
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackArchiveGenerator::PackageFiles()
+{
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: "
+ << toplevel << std::endl);
+
+ if (WantsComponentInstallation()) {
+ // CASE 1 : COMPONENT ALL-IN-ONE package
+ // If ALL COMPONENTS in ONE package has been requested
+ // then the package file is unique and should be open here.
+ if (componentPackageMethod == ONE_PACKAGE)
+ {
+ return PackageComponentsAllInOne();
+ }
+ // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one)
+ // There will be 1 package for each component group
+ // however one may require to ignore component group and
+ // in this case you'll get 1 package for each component.
+ else
+ {
+ return PackageComponents(componentPackageMethod ==
+ ONE_PACKAGE_PER_COMPONENT);
+ }
+ }
+
+ // CASE 3 : NON COMPONENT package.
+ DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0],archive);
+ std::vector<std::string>::const_iterator fileIt;
+ std::string dir = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(toplevel.c_str());
+ for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
+ {
+ // Get the relative path to the file
+ std::string rp = cmSystemTools::RelativePath(toplevel.c_str(),
+ fileIt->c_str());
+ archive.Add(rp);
+ if(!archive)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem while adding file< "
+ << *fileIt
+ << "> to archive <"
+ << packageFileNames[0] << "> .ERROR ="
+ << archive.GetError()
+ << std::endl);
+ return 0;
+ }
+ }
+ cmSystemTools::ChangeDirectory(dir.c_str());
+ // The destructor of cmArchiveWrite will close and finish the write
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackArchiveGenerator::GenerateHeader(std::ostream*)
+{
+ return 1;
+}
+
+bool cmCPackArchiveGenerator::SupportsComponentInstallation() const {
+ // The Component installation support should only
+ // be activated if explicitly requested by the user
+ // (for backward compatibility reason)
+ if (IsOn("CPACK_ARCHIVE_COMPONENT_INSTALL"))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
diff --git a/Source/CPack/cmCPackArchiveGenerator.h b/Source/CPack/cmCPackArchiveGenerator.h
new file mode 100644
index 0000000000..6411b1ebf2
--- /dev/null
+++ b/Source/CPack/cmCPackArchiveGenerator.h
@@ -0,0 +1,74 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackArchiveGenerator_h
+#define cmCPackArchiveGenerator_h
+
+#include "cmArchiveWrite.h"
+#include "cmCPackGenerator.h"
+
+
+/** \class cmCPackArchiveGenerator
+ * \brief A generator base for libarchive generation.
+ * The generator itself uses the libarchive wrapper
+ * \ref cmArchiveWrite.
+ *
+ */
+class cmCPackArchiveGenerator : public cmCPackGenerator
+ {
+public:
+ cmTypeMacro(cmCPackArchiveGenerator, cmCPackGenerator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackArchiveGenerator(cmArchiveWrite::Compress, cmArchiveWrite::Type);
+ virtual ~cmCPackArchiveGenerator();
+ // Used to add a header to the archive
+ virtual int GenerateHeader(std::ostream* os);
+ // component support
+ virtual bool SupportsComponentInstallation() const;
+protected:
+ virtual int InitializeInternal();
+ /**
+ * Add the files belonging to the specified component
+ * to the provided (already opened) archive.
+ * @param[in,out] archive the archive object
+ * @param[in] component the component whose file will be added to archive
+ */
+ int addOneComponentToArchive(cmArchiveWrite& archive,
+ cmCPackComponent* component);
+
+ /**
+ * The main package file method.
+ * If component install was required this
+ * method will call either PackageComponents or
+ * PackageComponentsAllInOne.
+ */
+ int PackageFiles();
+ /**
+ * The method used to package files when component
+ * install is used. This will create one
+ * archive for each component group.
+ */
+ int PackageComponents(bool ignoreGroup);
+ /**
+ * Special case of component install where all
+ * components will be put in a single installer.
+ */
+ int PackageComponentsAllInOne();
+ virtual const char* GetOutputExtension() = 0;
+ cmArchiveWrite::Compress Compress;
+ cmArchiveWrite::Type Archive;
+ };
+
+#endif
diff --git a/Source/CPack/cmCPackBundleGenerator.cxx b/Source/CPack/cmCPackBundleGenerator.cxx
new file mode 100644
index 0000000000..6c994f13fd
--- /dev/null
+++ b/Source/CPack/cmCPackBundleGenerator.cxx
@@ -0,0 +1,174 @@
+/*============================================================================
+ 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 "cmCPackBundleGenerator.h"
+#include "cmCPackLog.h"
+#include "cmSystemTools.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+//----------------------------------------------------------------------
+cmCPackBundleGenerator::cmCPackBundleGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackBundleGenerator::~cmCPackBundleGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackBundleGenerator::InitializeInternal()
+{
+ const char* name = this->GetOption("CPACK_BUNDLE_NAME");
+ if(0 == name)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_BUNDLE_NAME must be set to use the Bundle generator."
+ << std::endl);
+
+ return 0;
+ }
+
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+const char* cmCPackBundleGenerator::GetPackagingInstallPrefix()
+{
+ this->InstallPrefix = "/";
+ this->InstallPrefix += this->GetOption("CPACK_BUNDLE_NAME");
+ this->InstallPrefix += ".app/Contents/Resources";
+
+ return this->InstallPrefix.c_str();
+}
+
+//----------------------------------------------------------------------
+int cmCPackBundleGenerator::PackageFiles()
+{
+
+ // Get required arguments ...
+ const std::string cpack_bundle_name = this->GetOption("CPACK_BUNDLE_NAME")
+ ? this->GetOption("CPACK_BUNDLE_NAME") : "";
+ if(cpack_bundle_name.empty())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_BUNDLE_NAME must be set."
+ << std::endl);
+
+ return 0;
+ }
+
+ const std::string cpack_bundle_plist = this->GetOption("CPACK_BUNDLE_PLIST")
+ ? this->GetOption("CPACK_BUNDLE_PLIST") : "";
+ if(cpack_bundle_plist.empty())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_BUNDLE_PLIST must be set."
+ << std::endl);
+
+ return 0;
+ }
+
+ const std::string cpack_bundle_icon = this->GetOption("CPACK_BUNDLE_ICON")
+ ? this->GetOption("CPACK_BUNDLE_ICON") : "";
+ if(cpack_bundle_icon.empty())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_BUNDLE_ICON must be set."
+ << std::endl);
+
+ return 0;
+ }
+
+ // Get optional arguments ...
+ const std::string cpack_bundle_startup_command =
+ this->GetOption("CPACK_BUNDLE_STARTUP_COMMAND")
+ ? this->GetOption("CPACK_BUNDLE_STARTUP_COMMAND") : "";
+
+ // The staging directory contains everything that will end-up inside the
+ // final disk image ...
+ cmOStringStream staging;
+ staging << toplevel;
+
+ cmOStringStream contents;
+ contents << staging.str() << "/" << cpack_bundle_name
+ << ".app/" << "Contents";
+
+ cmOStringStream application;
+ application << contents.str() << "/" << "MacOS";
+
+ cmOStringStream resources;
+ resources << contents.str() << "/" << "Resources";
+
+ // Install a required, user-provided bundle metadata file ...
+ cmOStringStream plist_source;
+ plist_source << cpack_bundle_plist;
+
+ cmOStringStream plist_target;
+ plist_target << contents.str() << "/" << "Info.plist";
+
+ if(!this->CopyFile(plist_source, plist_target))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error copying plist. Check the value of CPACK_BUNDLE_PLIST."
+ << std::endl);
+
+ return 0;
+ }
+
+ // Install a user-provided bundle icon ...
+ cmOStringStream icon_source;
+ icon_source << cpack_bundle_icon;
+
+ cmOStringStream icon_target;
+ icon_target << resources.str() << "/" << cpack_bundle_name << ".icns";
+
+ if(!this->CopyFile(icon_source, icon_target))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error copying bundle icon. Check the value of CPACK_BUNDLE_ICON."
+ << std::endl);
+
+ return 0;
+ }
+
+ // Optionally a user-provided startup command (could be an
+ // executable or a script) ...
+ if(!cpack_bundle_startup_command.empty())
+ {
+ cmOStringStream command_source;
+ command_source << cpack_bundle_startup_command;
+
+ cmOStringStream command_target;
+ command_target << application.str() << "/" << cpack_bundle_name;
+
+ if(!this->CopyFile(command_source, command_target))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error copying startup command. "
+ " Check the value of CPACK_BUNDLE_STARTUP_COMMAND."
+ << std::endl);
+
+ return 0;
+ }
+
+ cmSystemTools::SetPermissions(command_target.str().c_str(), 0777);
+ }
+
+ return this->CreateDMG(toplevel, packageFileNames[0]);
+}
+
+bool cmCPackBundleGenerator::SupportsComponentInstallation() const
+{
+ return false;
+}
diff --git a/Source/CPack/cmCPackBundleGenerator.h b/Source/CPack/cmCPackBundleGenerator.h
new file mode 100644
index 0000000000..ed0187dd47
--- /dev/null
+++ b/Source/CPack/cmCPackBundleGenerator.h
@@ -0,0 +1,40 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackBundleGenerator_h
+#define cmCPackBundleGenerator_h
+
+#include "cmCPackDragNDropGenerator.h"
+
+/** \class cmCPackBundleGenerator
+ * \brief A generator for OSX bundles
+ *
+ * Based on Gimp.app
+ */
+class cmCPackBundleGenerator : public cmCPackDragNDropGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackBundleGenerator, cmCPackDragNDropGenerator);
+
+ cmCPackBundleGenerator();
+ virtual ~cmCPackBundleGenerator();
+
+protected:
+ virtual int InitializeInternal();
+ virtual const char* GetPackagingInstallPrefix();
+ int PackageFiles();
+ bool SupportsComponentInstallation() const;
+
+ std::string InstallPrefix;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackComponentGroup.cxx b/Source/CPack/cmCPackComponentGroup.cxx
new file mode 100644
index 0000000000..77f11cbf29
--- /dev/null
+++ b/Source/CPack/cmCPackComponentGroup.cxx
@@ -0,0 +1,45 @@
+/*============================================================================
+ 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 "cmCPackComponentGroup.h"
+#include "cmSystemTools.h"
+#include <vector>
+#include <string>
+
+//----------------------------------------------------------------------
+unsigned long cmCPackComponent::GetInstalledSize(
+ const std::string& installDir) const
+{
+ if (this->TotalSize != 0)
+ {
+ return this->TotalSize;
+ }
+
+ std::vector<std::string>::const_iterator fileIt;
+ for (fileIt = this->Files.begin(); fileIt != this->Files.end(); ++fileIt)
+ {
+ std::string path = installDir;
+ path += '/';
+ path += *fileIt;
+ this->TotalSize += cmSystemTools::FileLength(path.c_str());
+ }
+
+ return this->TotalSize;
+}
+
+//----------------------------------------------------------------------
+unsigned long
+cmCPackComponent::GetInstalledSizeInKbytes(const std::string& installDir) const
+{
+ unsigned long result = (GetInstalledSize(installDir) + 512) / 1024;
+ return result? result : 1;
+}
diff --git a/Source/CPack/cmCPackComponentGroup.h b/Source/CPack/cmCPackComponentGroup.h
new file mode 100644
index 0000000000..0679638a6a
--- /dev/null
+++ b/Source/CPack/cmCPackComponentGroup.h
@@ -0,0 +1,140 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackComponentGroup_h
+#define cmCPackComponentGroup_h
+
+#include "cmStandardIncludes.h"
+
+class cmCPackComponentGroup;
+
+/** \class cmCPackInstallationType
+ * \brief A certain type of installation, which encompasses a
+ * set of components.
+ */
+class cmCPackInstallationType
+{
+public:
+ /// The name of the installation type (used to reference this
+ /// installation type).
+ std::string Name;
+
+ /// The name of the installation type as displayed to the user.
+ std::string DisplayName;
+
+ /// The index number of the installation type. This is an arbitrary
+ /// numbering from 1 to the number of installation types.
+ unsigned Index;
+};
+
+/** \class cmCPackComponent
+ * \brief A single component to be installed by CPack.
+ */
+class cmCPackComponent
+{
+public:
+ cmCPackComponent() : Group(0), IsRequired(true), IsHidden(false),
+ IsDisabledByDefault(false), IsDownloaded(false),
+ TotalSize(0) { }
+
+ /// The name of the component (used to reference the component).
+ std::string Name;
+
+ /// The name of the component as displayed to the user.
+ std::string DisplayName;
+
+ /// The component group that contains this component (if any).
+ cmCPackComponentGroup *Group;
+
+ /// Whether this component group must always be installed.
+ bool IsRequired : 1;
+
+ /// Whether this component group is hidden. A hidden component group
+ /// is always installed. However, it may still be shown to the user.
+ bool IsHidden : 1;
+
+ /// Whether this component defaults to "disabled".
+ bool IsDisabledByDefault : 1;
+
+ /// Whether this component should be downloaded on-the-fly. If false,
+ /// the component will be a part of the installation package.
+ bool IsDownloaded : 1;
+
+ /// A description of this component.
+ std::string Description;
+
+ /// The installation types that this component is a part of.
+ std::vector<cmCPackInstallationType *> InstallationTypes;
+
+ /// If IsDownloaded is true, the name of the archive file that
+ /// contains the files that are part of this component.
+ std::string ArchiveFile;
+
+ /// The components that this component depends on.
+ std::vector<cmCPackComponent *> Dependencies;
+
+ /// The components that depend on this component.
+ std::vector<cmCPackComponent *> ReverseDependencies;
+
+ /// The list of installed files that are part of this component.
+ std::vector<std::string> Files;
+
+ /// The list of installed directories that are part of this component.
+ std::vector<std::string> Directories;
+
+ /// Get the total installed size of all of the files in this
+ /// component, in bytes. installDir is the directory into which the
+ /// component was installed.
+ unsigned long GetInstalledSize(const std::string& installDir) const;
+
+ /// Identical to GetInstalledSize, but returns the result in
+ /// kilobytes.
+ unsigned long GetInstalledSizeInKbytes(const std::string& installDir) const;
+
+ private:
+ mutable unsigned long TotalSize;
+};
+
+/** \class cmCPackComponentGroup
+ * \brief A component group to be installed by CPack.
+ */
+class cmCPackComponentGroup
+{
+public:
+ cmCPackComponentGroup() : ParentGroup(0) { }
+
+ /// The name of the group (used to reference the group).
+ std::string Name;
+
+ /// The name of the component as displayed to the user.
+ std::string DisplayName;
+
+ /// The description of this component group.
+ std::string Description;
+
+ /// Whether the name of the component will be shown in bold.
+ bool IsBold : 1;
+
+ /// Whether the section should be expanded by default
+ bool IsExpandedByDefault : 1;
+
+ /// The components within this group.
+ std::vector<cmCPackComponent*> Components;
+
+ /// The parent group of this component group (if any).
+ cmCPackComponentGroup *ParentGroup;
+
+ /// The subgroups of this group.
+ std::vector<cmCPackComponentGroup*> Subgroups;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackConfigure.h.in b/Source/CPack/cmCPackConfigure.h.in
new file mode 100644
index 0000000000..3d7702e1a7
--- /dev/null
+++ b/Source/CPack/cmCPackConfigure.h.in
@@ -0,0 +1,11 @@
+/*============================================================================
+ 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.
+============================================================================*/
diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx
new file mode 100644
index 0000000000..6605f16e02
--- /dev/null
+++ b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx
@@ -0,0 +1,92 @@
+/*============================================================================
+ 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 "cmCPackCygwinBinaryGenerator.h"
+
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackLog.h"
+
+#include <cmsys/SystemTools.hxx>
+
+//----------------------------------------------------------------------
+cmCPackCygwinBinaryGenerator::cmCPackCygwinBinaryGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackCygwinBinaryGenerator::~cmCPackCygwinBinaryGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackCygwinBinaryGenerator::InitializeInternal()
+{
+ this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
+ this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+int cmCPackCygwinBinaryGenerator::PackageFiles()
+{
+ std::string packageName = this->GetOption("CPACK_PACKAGE_NAME");
+ packageName += "-";
+ packageName += this->GetOption("CPACK_PACKAGE_VERSION");
+ packageName = cmsys::SystemTools::LowerCase(packageName);
+ std::string manifest = "/usr/share/doc/";
+ manifest += packageName;
+ manifest += "/MANIFEST";
+ std::string manifestFile
+ = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ // Create a MANIFEST file that contains all of the files in
+ // the tar file
+ std::string tempdir = manifestFile;
+ manifestFile += manifest;
+ // create an extra scope to force the stream
+ // to create the file before the super class is called
+ {
+ cmGeneratedFileStream ofs(manifestFile.c_str());
+ for(std::vector<std::string>::const_iterator i = files.begin();
+ i != files.end(); ++i)
+ {
+ // remove the temp dir and replace with /usr
+ ofs << (*i).substr(tempdir.size()) << "\n";
+ }
+ ofs << manifest << "\n";
+ }
+ // add the manifest file to the list of all files
+ files.push_back(manifestFile);
+
+ // create the bzip2 tar file
+ return this->Superclass::PackageFiles();
+}
+
+const char* cmCPackCygwinBinaryGenerator::GetOutputExtension()
+{
+ this->OutputExtension = "-";
+ const char* patchNumber =this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
+ if(!patchNumber)
+ {
+ patchNumber = "1";
+ cmCPackLogger(cmCPackLog::LOG_WARNING,
+ "CPACK_CYGWIN_PATCH_NUMBER not specified using 1"
+ << std::endl);
+ }
+ this->OutputExtension += patchNumber;
+ this->OutputExtension += ".tar.bz2";
+ return this->OutputExtension.c_str();
+}
diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.h b/Source/CPack/cmCPackCygwinBinaryGenerator.h
new file mode 100644
index 0000000000..38f6df17d9
--- /dev/null
+++ b/Source/CPack/cmCPackCygwinBinaryGenerator.h
@@ -0,0 +1,38 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackCygwinBinaryGenerator_h
+#define cmCPackCygwinBinaryGenerator_h
+
+#include "cmCPackTarBZip2Generator.h"
+
+/** \class cmCPackCygwinBinaryGenerator
+ * \brief A generator for TarBZip2 files
+ */
+class cmCPackCygwinBinaryGenerator : public cmCPackTarBZip2Generator
+{
+public:
+ cmCPackTypeMacro(cmCPackCygwinBinaryGenerator, cmCPackTarBZip2Generator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackCygwinBinaryGenerator();
+ virtual ~cmCPackCygwinBinaryGenerator();
+protected:
+ virtual int InitializeInternal();
+ int PackageFiles();
+ virtual const char* GetOutputExtension();
+ std::string OutputExtension;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.cxx b/Source/CPack/cmCPackCygwinSourceGenerator.cxx
new file mode 100644
index 0000000000..f1e8539b97
--- /dev/null
+++ b/Source/CPack/cmCPackCygwinSourceGenerator.cxx
@@ -0,0 +1,182 @@
+/*============================================================================
+ 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 "cmCPackCygwinSourceGenerator.h"
+
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackLog.h"
+
+#include <cmsys/SystemTools.hxx>
+
+// Includes needed for implementation of RenameFile. This is not in
+// system tools because it is not implemented robustly enough to move
+// files across directories.
+#ifdef _WIN32
+# include <windows.h>
+# include <sys/stat.h>
+#endif
+
+//----------------------------------------------------------------------
+cmCPackCygwinSourceGenerator::cmCPackCygwinSourceGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackCygwinSourceGenerator::~cmCPackCygwinSourceGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackCygwinSourceGenerator::InitializeInternal()
+{
+ this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+int cmCPackCygwinSourceGenerator::PackageFiles()
+{
+ // Create a tar file of the sources
+ std::string packageDirFileName
+ = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ packageDirFileName += ".tar.bz2";
+ packageFileNames[0] = packageDirFileName;
+ std::string output;
+ // skip one parent up to the cmCPackTarBZip2Generator
+ // to create tar.bz2 file with the list of source
+ // files
+ this->Compress = cmArchiveWrite::CompressBZip2;
+ if ( !this->cmCPackTarBZip2Generator::PackageFiles() )
+ {
+ return 0;
+ }
+ // Now create a tar file that contains the above .tar.bz2 file
+ // and the CPACK_CYGWIN_PATCH_FILE and CPACK_TOPLEVEL_DIRECTORY
+ // files
+ std::string compressOutFile = packageDirFileName;
+ // at this point compressOutFile is the full path to
+ // _CPack_Package/.../package-2.5.0.tar.bz2
+ // we want to create a tar _CPack_Package/.../package-2.5.0-1-src.tar.bz2
+ // with these
+ // _CPack_Package/.../package-2.5.0-1.patch
+ // _CPack_Package/.../package-2.5.0-1.sh
+ // _CPack_Package/.../package-2.5.0.tar.bz2
+ // the -1 is CPACK_CYGWIN_PATCH_NUMBER
+
+ // first copy the patch file and the .sh file
+ // to the toplevel cpack temp dir
+
+ // copy the patch file into place
+ if(!this->GetOption("CPACK_CYGWIN_PATCH_FILE"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "No patch file specified for cygwin sources.");
+ return 0;
+ }
+ if(!cmSystemTools::CopyFileAlways(
+ this->GetOption("CPACK_CYGWIN_PATCH_FILE"),
+ this->GetOption("CPACK_TOPLEVEL_DIRECTORY")))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "problem copying: ["
+ << this->GetOption("CPACK_CYGWIN_PATCH_FILE") << "]\nto\n["
+ << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
+ return 0;
+ }
+ if(!this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "No build script specified for cygwin sources.");
+ return 0;
+ }
+ // copy the build script into place
+ if(!cmSystemTools::CopyFileAlways(
+ this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"),
+ this->GetOption("CPACK_TOPLEVEL_DIRECTORY")))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "problem copying: "
+ << this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT") << "\nto\n"
+ << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
+ return 0;
+ }
+ std::string outerTarFile
+ = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ outerTarFile += "-";
+ const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
+ if(!patch)
+ {
+ cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER"
+ << " not specified, defaulting to 1\n");
+ patch = "1";
+ }
+ outerTarFile += patch;
+ outerTarFile += "-src.tar.bz2";
+ std::string tmpDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ std::string buildScript = tmpDir;
+ buildScript += "/";
+ buildScript += cmSystemTools::GetFilenameName(
+ this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"));
+ std::string patchFile = tmpDir;
+ patchFile += "/";
+ patchFile += cmSystemTools::GetFilenameName(
+ this->GetOption("CPACK_CYGWIN_PATCH_FILE"));
+
+ std::string file = cmSystemTools::GetFilenameName(compressOutFile);
+ std::string sourceTar = cmSystemTools::GetFilenamePath(compressOutFile);
+ sourceTar += "/";
+ sourceTar += file;
+ /* reset list of file to be packaged */
+ files.clear();
+ // a source release in cygwin should have the build script used
+ // to build the package, the patch file that is different from the
+ // regular upstream version of the sources, and a bziped tar file
+ // of the original sources
+ files.push_back(buildScript);
+ files.push_back(patchFile);
+ files.push_back(sourceTar);
+ /* update the name of the produced package */
+ packageFileNames[0] = outerTarFile;
+ /* update the toplevel dir */
+ toplevel = tmpDir;
+ if ( !this->cmCPackTarBZip2Generator::PackageFiles() )
+ {
+ return 0;
+ }
+ return 1;
+}
+
+const char* cmCPackCygwinSourceGenerator::GetPackagingInstallPrefix()
+{
+ this->InstallPrefix = "/";
+ this->InstallPrefix += this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ return this->InstallPrefix.c_str();
+}
+
+const char* cmCPackCygwinSourceGenerator::GetOutputExtension()
+{
+ this->OutputExtension = "-";
+ const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
+ if(!patch)
+ {
+ cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER"
+ << " not specified, defaulting to 1\n");
+ patch = "1";
+ }
+ this->OutputExtension += patch;
+ this->OutputExtension += "-src.tar.bz2";
+ return this->OutputExtension.c_str();
+}
+
diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.h b/Source/CPack/cmCPackCygwinSourceGenerator.h
new file mode 100644
index 0000000000..9d98a9b951
--- /dev/null
+++ b/Source/CPack/cmCPackCygwinSourceGenerator.h
@@ -0,0 +1,40 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackCygwinSourceGenerator_h
+#define cmCPackCygwinSourceGenerator_h
+
+#include "cmCPackTarBZip2Generator.h"
+
+/** \class cmCPackCygwinSourceGenerator
+ * \brief A generator for cygwin source files
+ */
+class cmCPackCygwinSourceGenerator : public cmCPackTarBZip2Generator
+{
+public:
+ cmCPackTypeMacro(cmCPackCygwinSourceGenerator, cmCPackTarBZip2Generator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackCygwinSourceGenerator();
+ virtual ~cmCPackCygwinSourceGenerator();
+protected:
+ const char* GetPackagingInstallPrefix();
+ virtual int InitializeInternal();
+ int PackageFiles();
+ virtual const char* GetOutputExtension();
+ std::string InstallPrefix;
+ std::string OutputExtension;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx
new file mode 100644
index 0000000000..936942b9b0
--- /dev/null
+++ b/Source/CPack/cmCPackDebGenerator.cxx
@@ -0,0 +1,869 @@
+/*============================================================================
+ 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 "cmCPackDebGenerator.h"
+
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackLog.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Glob.hxx>
+
+#include <limits.h> // USHRT_MAX
+
+// NOTE:
+// A debian package .deb is simply an 'ar' archive. The only subtle difference
+// is that debian uses the BSD ar style archive whereas most Linux distro have
+// a GNU ar.
+// See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=161593 for more info
+// Therefore we provide our own implementation of a BSD-ar:
+static int ar_append(const char*archive,const std::vector<std::string>& files);
+
+//----------------------------------------------------------------------
+cmCPackDebGenerator::cmCPackDebGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackDebGenerator::~cmCPackDebGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackDebGenerator::InitializeInternal()
+{
+ this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
+ if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR")))
+ {
+ this->SetOption("CPACK_SET_DESTDIR", "I_ON");
+ }
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+int cmCPackDebGenerator::PackageOnePack(std::string initialTopLevel,
+ std::string packageName)
+ {
+ int retval = 1;
+ // Begin the archive for this pack
+ std::string localToplevel(initialTopLevel);
+ std::string packageFileName(
+ cmSystemTools::GetParentDirectory(toplevel.c_str())
+ );
+ std::string outputFileName(
+ std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
+ +"-"+packageName + this->GetOutputExtension()
+ );
+
+ localToplevel += "/"+ packageName;
+ /* replace the TEMP DIRECTORY with the component one */
+ this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
+ packageFileName += "/"+ outputFileName;
+ /* replace proposed CPACK_OUTPUT_FILE_NAME */
+ this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
+ /* replace the TEMPORARY package file name */
+ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
+ packageFileName.c_str());
+ // Tell CPackDeb.cmake the name of the component GROUP.
+ this->SetOption("CPACK_DEB_PACKAGE_COMPONENT",packageName.c_str());
+ // Tell CPackDeb.cmake the path where the component is.
+ std::string component_path = "/";
+ component_path += packageName;
+ this->SetOption("CPACK_DEB_PACKAGE_COMPONENT_PART_PATH",
+ component_path.c_str());
+ if (!this->ReadListFile("CPackDeb.cmake"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while execution CPackDeb.cmake" << std::endl);
+ retval = 0;
+ return retval;
+ }
+
+ cmsys::Glob gl;
+ std::string findExpr(this->GetOption("WDIR"));
+ findExpr += "/*";
+ gl.RecurseOn();
+ if ( !gl.FindFiles(findExpr) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find any files in the installed directory" << std::endl);
+ return 0;
+ }
+ packageFiles = gl.GetFiles();
+
+ int res = createDeb();
+ if (res != 1)
+ {
+ retval = 0;
+ }
+ // add the generated package to package file names list
+ packageFileNames.push_back(packageFileName);
+ return retval;
+}
+
+//----------------------------------------------------------------------
+int cmCPackDebGenerator::PackageComponents(bool ignoreGroup)
+{
+ int retval = 1;
+ /* Reset package file name list it will be populated during the
+ * component packaging run*/
+ packageFileNames.clear();
+ std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
+
+ // The default behavior is to have one package by component group
+ // unless CPACK_COMPONENTS_IGNORE_GROUP is specified.
+ if (!ignoreGroup)
+ {
+ std::map<std::string, cmCPackComponentGroup>::iterator compGIt;
+ for (compGIt=this->ComponentGroups.begin();
+ compGIt!=this->ComponentGroups.end(); ++compGIt)
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
+ << compGIt->first
+ << std::endl);
+ // Begin the archive for this group
+ retval &= PackageOnePack(initialTopLevel,compGIt->first);
+ }
+ // Handle Orphan components (components not belonging to any groups)
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt=this->Components.begin();
+ compIt!=this->Components.end(); ++compIt )
+ {
+ // Does the component belong to a group?
+ if (compIt->second.Group==NULL)
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Component <"
+ << compIt->second.Name
+ << "> does not belong to any group, package it separately."
+ << std::endl);
+ // Begin the archive for this orphan component
+ retval &= PackageOnePack(initialTopLevel,compIt->first);
+ }
+ }
+ }
+ // CPACK_COMPONENTS_IGNORE_GROUPS is set
+ // We build 1 package per component
+ else
+ {
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt=this->Components.begin();
+ compIt!=this->Components.end(); ++compIt )
+ {
+ retval &= PackageOnePack(initialTopLevel,compIt->first);
+ }
+ }
+ return retval;
+}
+
+//----------------------------------------------------------------------
+int cmCPackDebGenerator::PackageComponentsAllInOne()
+{
+ int retval = 1;
+ std::string compInstDirName;
+ /* Reset package file name list it will be populated during the
+ * component packaging run*/
+ packageFileNames.clear();
+ std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
+
+ compInstDirName = "ALL_COMPONENTS_IN_ONE";
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Packaging all groups in one package..."
+ "(CPACK_COMPONENTS_ALL_[GROUPS_]IN_ONE_PACKAGE is set)"
+ << std::endl);
+
+ // The ALL GROUPS in ONE package case
+ std::string localToplevel(initialTopLevel);
+ std::string packageFileName(
+ cmSystemTools::GetParentDirectory(toplevel.c_str())
+ );
+ std::string outputFileName(
+ std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
+ + this->GetOutputExtension()
+ );
+ // all GROUP in one vs all COMPONENT in one
+ localToplevel += "/"+compInstDirName;
+
+ /* replace the TEMP DIRECTORY with the component one */
+ this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
+ packageFileName += "/"+ outputFileName;
+ /* replace proposed CPACK_OUTPUT_FILE_NAME */
+ this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
+ /* replace the TEMPORARY package file name */
+ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
+ packageFileName.c_str());
+ // Tell CPackDeb.cmake the path where the component is.
+ std::string component_path = "/";
+ component_path += compInstDirName;
+ this->SetOption("CPACK_DEB_PACKAGE_COMPONENT_PART_PATH",
+ component_path.c_str());
+ if (!this->ReadListFile("CPackDeb.cmake"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while execution CPackDeb.cmake" << std::endl);
+ retval = 0;
+ return retval;
+ }
+
+ cmsys::Glob gl;
+ std::string findExpr(this->GetOption("WDIR"));
+ findExpr += "/*";
+ gl.RecurseOn();
+ if ( !gl.FindFiles(findExpr) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find any files in the installed directory" << std::endl);
+ return 0;
+ }
+ packageFiles = gl.GetFiles();
+
+ int res = createDeb();
+ if (res != 1)
+ {
+ retval = 0;
+ }
+ // add the generated package to package file names list
+ packageFileNames.push_back(packageFileName);
+ return retval;
+}
+
+//----------------------------------------------------------------------
+int cmCPackDebGenerator::PackageFiles()
+{
+ int retval = -1;
+
+ /* Are we in the component packaging case */
+ if (WantsComponentInstallation()) {
+ // CASE 1 : COMPONENT ALL-IN-ONE package
+ // If ALL GROUPS or ALL COMPONENTS in ONE package has been requested
+ // then the package file is unique and should be open here.
+ if (componentPackageMethod == ONE_PACKAGE)
+ {
+ return PackageComponentsAllInOne();
+ }
+ // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one)
+ // There will be 1 package for each component group
+ // however one may require to ignore component group and
+ // in this case you'll get 1 package for each component.
+ else
+ {
+ return PackageComponents(componentPackageMethod ==
+ ONE_PACKAGE_PER_COMPONENT);
+ }
+ }
+ // CASE 3 : NON COMPONENT package.
+ else
+ {
+ if (!this->ReadListFile("CPackDeb.cmake"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while execution CPackDeb.cmake" << std::endl);
+ retval = 0;
+ }
+ else
+ {
+ packageFiles = files;
+ return createDeb();
+ }
+ }
+ return retval;
+}
+
+int cmCPackDebGenerator::createDeb()
+{
+ const char* cmakeExecutable = this->GetOption("CMAKE_COMMAND");
+
+ // debian-binary file
+ std::string dbfilename;
+ dbfilename += this->GetOption("WDIR");
+ dbfilename += "/debian-binary";
+ { // the scope is needed for cmGeneratedFileStream
+ cmGeneratedFileStream out(dbfilename.c_str());
+ out << "2.0";
+ out << std::endl; // required for valid debian package
+ }
+
+ // control file
+ std::string ctlfilename;
+ ctlfilename = this->GetOption("WDIR");
+ ctlfilename += "/control";
+
+ // debian policy enforce lower case for package name
+ // mandatory entries:
+ std::string debian_pkg_name = cmsys::SystemTools::LowerCase(
+ this->GetOption("CPACK_DEBIAN_PACKAGE_NAME") );
+ const char* debian_pkg_version =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_VERSION");
+ const char* debian_pkg_section =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_SECTION");
+ const char* debian_pkg_priority =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_PRIORITY");
+ const char* debian_pkg_arch =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_ARCHITECTURE");
+ const char* maintainer = this->GetOption("CPACK_DEBIAN_PACKAGE_MAINTAINER");
+ const char* desc = this->GetOption("CPACK_DEBIAN_PACKAGE_DESCRIPTION");
+
+ // optional entries
+ const char* debian_pkg_dep = this->GetOption("CPACK_DEBIAN_PACKAGE_DEPENDS");
+ const char* debian_pkg_rec =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_RECOMMENDS");
+ const char* debian_pkg_sug =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_SUGGESTS");
+ const char* debian_pkg_url =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_HOMEPAGE");
+ const char* debian_pkg_predep =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_PREDEPENDS");
+ const char* debian_pkg_enhances =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_ENHANCES");
+ const char* debian_pkg_breaks =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_BREAKS");
+ const char* debian_pkg_conflicts =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_CONFLICTS");
+ const char* debian_pkg_provides =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_PROVIDES");
+ const char* debian_pkg_replaces =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_REPLACES");
+
+ { // the scope is needed for cmGeneratedFileStream
+ cmGeneratedFileStream out(ctlfilename.c_str());
+ out << "Package: " << debian_pkg_name << "\n";
+ out << "Version: " << debian_pkg_version << "\n";
+ out << "Section: " << debian_pkg_section << "\n";
+ out << "Priority: " << debian_pkg_priority << "\n";
+ out << "Architecture: " << debian_pkg_arch << "\n";
+ if(debian_pkg_dep && *debian_pkg_dep)
+ {
+ out << "Depends: " << debian_pkg_dep << "\n";
+ }
+ if(debian_pkg_rec && *debian_pkg_rec)
+ {
+ out << "Recommends: " << debian_pkg_rec << "\n";
+ }
+ if(debian_pkg_sug && *debian_pkg_sug)
+ {
+ out << "Suggests: " << debian_pkg_sug << "\n";
+ }
+ if(debian_pkg_url && *debian_pkg_url)
+ {
+ out << "Homepage: " << debian_pkg_url << "\n";
+ }
+ if (debian_pkg_predep && *debian_pkg_predep)
+ {
+ out << "Pre-Depends: " << debian_pkg_predep << "\n";
+ }
+ if (debian_pkg_enhances && *debian_pkg_enhances)
+ {
+ out << "Enhances: " << debian_pkg_enhances << "\n";
+ }
+ if (debian_pkg_breaks && *debian_pkg_breaks)
+ {
+ out << "Breaks: " << debian_pkg_breaks << "\n";
+ }
+ if (debian_pkg_conflicts && *debian_pkg_conflicts)
+ {
+ out << "Conflicts: " << debian_pkg_conflicts << "\n";
+ }
+ if (debian_pkg_provides && *debian_pkg_provides)
+ {
+ out << "Provides: " << debian_pkg_provides << "\n";
+ }
+ if (debian_pkg_replaces && *debian_pkg_replaces)
+ {
+ out << "Replaces: " << debian_pkg_replaces << "\n";
+ }
+ unsigned long totalSize = 0;
+ {
+ std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ dirName += '/';
+ for (std::vector<std::string>::const_iterator fileIt =
+ packageFiles.begin();
+ fileIt != packageFiles.end(); ++ fileIt )
+ {
+ totalSize += cmSystemTools::FileLength(fileIt->c_str());
+ }
+ }
+ out << "Installed-Size: " << (totalSize + 1023) / 1024 << "\n";
+ out << "Maintainer: " << maintainer << "\n";
+ out << "Description: " << desc << "\n";
+ out << std::endl;
+ }
+
+ std::string cmd;
+ if (NULL != this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE")) {
+ cmd += this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE");
+ }
+
+ const char* debian_compression_type =
+ this->GetOption("CPACK_DEBIAN_COMPRESSION_TYPE");
+ if(!debian_compression_type)
+ {
+ debian_compression_type = "gzip";
+ }
+
+ std::string cmake_tar = " ", compression_modifier = "a", compression_suffix;
+ if(!strcmp(debian_compression_type, "lzma")) {
+ compression_suffix = ".lzma";
+ } else if(!strcmp(debian_compression_type, "xz")) {
+ compression_suffix = ".xz";
+ } else if(!strcmp(debian_compression_type, "bzip2")) {
+ compression_suffix = ".bz2";
+ compression_modifier = "j";
+ cmake_tar += "\"" + std::string(cmakeExecutable) + "\" -E ";
+ } else if(!strcmp(debian_compression_type, "gzip")) {
+ compression_suffix = ".gz";
+ compression_modifier = "z";
+ cmake_tar += "\"" + std::string(cmakeExecutable) + "\" -E ";
+ } else if(!strcmp(debian_compression_type, "none")) {
+ compression_suffix = "";
+ compression_modifier = "";
+ cmake_tar += "\"" + std::string(cmakeExecutable) + "\" -E ";
+ } else {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error unrecognized compression type: "
+ << debian_compression_type << std::endl);
+ }
+
+ cmd += cmake_tar + "tar c" + compression_modifier + "f data.tar"
+ + compression_suffix;
+
+ // now add all directories which have to be compressed
+ // collect all top level install dirs for that
+ // e.g. /opt/bin/foo, /usr/bin/bar and /usr/bin/baz would give /usr and /opt
+ size_t topLevelLength = std::string(this->GetOption("WDIR")).length();
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "WDIR: \"" << this->GetOption("WDIR")
+ << "\", length = " << topLevelLength
+ << std::endl);
+ std::set<std::string> installDirs;
+ for (std::vector<std::string>::const_iterator fileIt =
+ packageFiles.begin();
+ fileIt != packageFiles.end(); ++ fileIt )
+ {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "FILEIT: \"" << *fileIt << "\""
+ << std::endl);
+ std::string::size_type slashPos = fileIt->find('/', topLevelLength+1);
+ std::string relativeDir = fileIt->substr(topLevelLength,
+ slashPos - topLevelLength);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "RELATIVEDIR: \"" << relativeDir
+ << "\"" << std::endl);
+ if (installDirs.find(relativeDir) == installDirs.end())
+ {
+ installDirs.insert(relativeDir);
+ cmd += " .";
+ cmd += relativeDir;
+ }
+ }
+
+ std::string output;
+ int retval = -1;
+ int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
+ &retval, this->GetOption("WDIR"), this->GeneratorVerbose, 0);
+
+ if ( !res || retval )
+ {
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/Deb.log";
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << cmd << std::endl
+ << "# Working directory: " << toplevel << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running tar command: "
+ << cmd << std::endl
+ << "Please check " << tmpFile << " for errors" << std::endl);
+ return 0;
+ }
+
+ std::string md5filename;
+ md5filename = this->GetOption("WDIR");
+ md5filename += "/md5sums";
+
+ { // the scope is needed for cmGeneratedFileStream
+ cmGeneratedFileStream out(md5filename.c_str());
+ std::vector<std::string>::const_iterator fileIt;
+// std::string topLevelWithTrailingSlash = toplevel;
+ std::string topLevelWithTrailingSlash =
+ this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ topLevelWithTrailingSlash += '/';
+ for ( fileIt = packageFiles.begin();
+ fileIt != packageFiles.end(); ++ fileIt )
+ {
+ cmd = "\"";
+ cmd += cmakeExecutable;
+ cmd += "\" -E md5sum \"";
+ cmd += *fileIt;
+ cmd += "\"";
+ //std::string output;
+ //int retVal = -1;
+ res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
+ &retval, toplevel.c_str(), this->GeneratorVerbose, 0);
+ // debian md5sums entries are like this:
+ // 014f3604694729f3bf19263bac599765 usr/bin/ccmake
+ // thus strip the full path (with the trailing slash)
+ cmSystemTools::ReplaceString(output,
+ topLevelWithTrailingSlash.c_str(), "");
+ out << output;
+ }
+ // each line contains a eol.
+ // Do not end the md5sum file with yet another (invalid)
+ }
+
+ cmd = "";
+ if (NULL != this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE"))
+ {
+ cmd = this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE");
+ }
+ cmd += cmake_tar + "tar czf control.tar.gz ./control ./md5sums";
+ const char* controlExtra =
+ this->GetOption("CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA");
+ if( controlExtra )
+ {
+ std::vector<std::string> controlExtraList;
+ cmSystemTools::ExpandListArgument(controlExtra, controlExtraList);
+ for(std::vector<std::string>::iterator i =
+ controlExtraList.begin(); i != controlExtraList.end(); ++i)
+ {
+ std::string filenamename =
+ cmsys::SystemTools::GetFilenameName(*i);
+ std::string localcopy = this->GetOption("WDIR");
+ localcopy += "/";
+ localcopy += filenamename;
+ // if we can copy the file, it means it does exist, let's add it:
+ if( cmsys::SystemTools::CopyFileIfDifferent(
+ i->c_str(), localcopy.c_str()) )
+ {
+ // debian is picky and need relative to ./ path in the tar.*
+ cmd += " ./";
+ cmd += filenamename;
+ }
+ }
+ }
+ res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
+ &retval, this->GetOption("WDIR"), this->GeneratorVerbose, 0);
+
+ if ( !res || retval )
+ {
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/Deb.log";
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << cmd << std::endl
+ << "# Working directory: " << toplevel << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running tar command: "
+ << cmd << std::endl
+ << "Please check " << tmpFile << " for errors" << std::endl);
+ return 0;
+ }
+
+ // ar -r your-package-name.deb debian-binary control.tar.* data.tar.*
+ // since debian packages require BSD ar (most Linux distros and even
+ // FreeBSD and NetBSD ship GNU ar) we use a copy of OpenBSD ar here.
+ std::vector<std::string> arFiles;
+ std::string topLevelString = this->GetOption("WDIR");
+ topLevelString += "/";
+ arFiles.push_back(topLevelString + "debian-binary");
+ arFiles.push_back(topLevelString + "control.tar.gz");
+ arFiles.push_back(topLevelString + "data.tar" + compression_suffix);
+ std::string outputFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ outputFileName += "/";
+ outputFileName += this->GetOption("CPACK_OUTPUT_FILE_NAME");
+ res = ar_append(outputFileName.c_str(), arFiles);
+ if ( res!=0 )
+ {
+ std::string tmpFile = this->GetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME");
+ tmpFile += "/Deb.log";
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Problem creating archive using: " << res << std::endl;
+ return 0;
+ }
+ return 1;
+}
+
+bool cmCPackDebGenerator::SupportsComponentInstallation() const
+ {
+ if (IsOn("CPACK_DEB_COMPONENT_INSTALL"))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+std::string cmCPackDebGenerator::GetComponentInstallDirNameSuffix(
+ const std::string& componentName)
+ {
+ if (componentPackageMethod == ONE_PACKAGE_PER_COMPONENT) {
+ return componentName;
+ }
+
+ if (componentPackageMethod == ONE_PACKAGE) {
+ return std::string("ALL_COMPONENTS_IN_ONE");
+ }
+ // We have to find the name of the COMPONENT GROUP
+ // the current COMPONENT belongs to.
+ std::string groupVar = "CPACK_COMPONENT_" +
+ cmSystemTools::UpperCase(componentName) + "_GROUP";
+ if (NULL != GetOption(groupVar))
+ {
+ return std::string(GetOption(groupVar));
+ }
+ else
+ {
+ return componentName;
+ }
+ }
+
+
+// The following code is taken from OpenBSD ar:
+// http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ar/
+// It has been slightly modified:
+// -return error codes instead exit() in functions
+// -use the stdio file I/O functions instead the file descriptor based ones
+// -merged into one cxx file
+// -no additional options supported
+// The coding style hasn't been modified.
+
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Hugh Smith at The University of Guelph.
+ *
+ * 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.
+ * 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define ARMAG "!<arch>\n" /* ar "magic number" */
+#define SARMAG 8 /* strlen(ARMAG); */
+
+#define AR_EFMT1 "#1/" /* extended format #1 */
+#define ARFMAG "`\n"
+
+/* Header format strings. */
+#define HDR1 "%s%-13d%-12ld%-6u%-6u%-8o%-10lld%2s"
+#define HDR2 "%-16.16s%-12ld%-6u%-6u%-8o%-10lld%2s"
+
+struct ar_hdr {
+ char ar_name[16]; /* name */
+ char ar_date[12]; /* modification time */
+ char ar_uid[6]; /* user id */
+ char ar_gid[6]; /* group id */
+ char ar_mode[8]; /* octal file permissions */
+ char ar_size[10]; /* size in bytes */
+ char ar_fmag[2]; /* consistency check */
+};
+
+/* Set up file copy. */
+#define SETCF(from, fromname, to, toname, pad) { \
+ cf.rFile = from; \
+ cf.rname = fromname; \
+ cf.wFile = to; \
+ cf.wname = toname; \
+ cf.flags = pad; \
+}
+
+/* File copy structure. */
+typedef struct {
+ FILE* rFile; /* read file descriptor */
+ const char *rname; /* read name */
+ FILE* wFile; /* write file descriptor */
+ const char *wname; /* write name */
+#define NOPAD 0x00 /* don't pad */
+#define WPAD 0x02 /* pad on writes */
+ unsigned int flags; /* pad flags */
+} CF;
+
+/* misc.c */
+
+static const char * ar_rname(const char *path)
+{
+ const char *ind = strrchr(path, '/');
+ return (ind ) ? ind + 1 : path;
+}
+
+/* archive.c */
+
+typedef struct ar_hdr HDR;
+static char ar_hb[sizeof(HDR) + 1]; /* real header */
+
+static size_t ar_already_written;
+
+/* copy_ar --
+ * Copy size bytes from one file to another - taking care to handle the
+ * extra byte (for odd size files) when reading archives and writing an
+ * extra byte if necessary when adding files to archive. The length of
+ * the object is the long name plus the object itself; the variable
+ * already_written gets set if a long name was written.
+ *
+ * The padding is really unnecessary, and is almost certainly a remnant
+ * of early archive formats where the header included binary data which
+ * a PDP-11 required to start on an even byte boundary. (Or, perhaps,
+ * because 16-bit word addressed copies were faster?) Anyhow, it should
+ * have been ripped out long ago.
+ */
+static int copy_ar(CF *cfp, off_t size)
+{
+ static char pad = '\n';
+ off_t sz = size;
+ size_t nr, nw;
+ char buf[8*1024];
+
+ if (sz == 0)
+ return 0;
+
+ FILE* from = cfp->rFile;
+ FILE* to = cfp->wFile;
+ while (sz &&
+ (nr = fread(buf, 1, sz < static_cast<off_t>(sizeof(buf))
+ ? static_cast<size_t>(sz) : sizeof(buf), from ))
+ > 0) {
+ sz -= nr;
+ for (size_t off = 0; off < nr; nr -= off, off += nw)
+ if ((nw = fwrite(buf + off, 1, nr, to)) < nr)
+ return -1;
+ }
+ if (sz)
+ return -2;
+
+ if (cfp->flags & WPAD && (size + ar_already_written) & 1
+ && fwrite(&pad, 1, 1, to) != 1)
+ return -4;
+
+ return 0;
+}
+
+/* put_arobj -- Write an archive member to a file. */
+static int put_arobj(CF *cfp, struct stat *sb)
+{
+ int result = 0;
+ struct ar_hdr *hdr;
+
+ /* If passed an sb structure, reading a file from disk. Get stat(2)
+ * information, build a name and construct a header. (Files are named
+ * by their last component in the archive.) */
+ const char* name = ar_rname(cfp->rname);
+ (void)stat(cfp->rname, sb);
+
+ /* If not truncating names and the name is too long or contains
+ * a space, use extended format 1. */
+ size_t lname = strlen(name);
+ uid_t uid = sb->st_uid;
+ gid_t gid = sb->st_gid;
+ if (uid > USHRT_MAX) {
+ uid = USHRT_MAX;
+ }
+ if (gid > USHRT_MAX) {
+ gid = USHRT_MAX;
+ }
+ if (lname > sizeof(hdr->ar_name) || strchr(name, ' '))
+ (void)sprintf(ar_hb, HDR1, AR_EFMT1, (int)lname,
+ (long int)sb->st_mtime, (unsigned)uid, (unsigned)gid,
+ sb->st_mode, (long long)sb->st_size + lname, ARFMAG);
+ else {
+ lname = 0;
+ (void)sprintf(ar_hb, HDR2, name,
+ (long int)sb->st_mtime, (unsigned)uid, (unsigned)gid,
+ sb->st_mode, (long long)sb->st_size, ARFMAG);
+ }
+ off_t size = sb->st_size;
+
+ if (fwrite(ar_hb, 1, sizeof(HDR), cfp->wFile) != sizeof(HDR))
+ return -1;
+
+ if (lname) {
+ if (fwrite(name, 1, lname, cfp->wFile) != lname)
+ return -2;
+ ar_already_written = lname;
+ }
+ result = copy_ar(cfp, size);
+ ar_already_written = 0;
+ return result;
+}
+
+/* append.c */
+
+/* append --
+ * Append files to the archive - modifies original archive or creates
+ * a new archive if named archive does not exist.
+ */
+static int ar_append(const char* archive,const std::vector<std::string>& files)
+{
+ int eval = 0;
+ FILE* aFile = cmSystemTools::Fopen(archive, "wb+");
+ if (aFile!=NULL) {
+ fwrite(ARMAG, SARMAG, 1, aFile);
+ if (fseek(aFile, 0, SEEK_END) != -1) {
+ CF cf;
+ struct stat sb;
+ /* Read from disk, write to an archive; pad on write. */
+ SETCF(NULL, 0, aFile, archive, WPAD);
+ for(std::vector<std::string>::const_iterator fileIt = files.begin();
+ fileIt!=files.end(); ++fileIt) {
+ const char* filename = fileIt->c_str();
+ FILE* file = cmSystemTools::Fopen(filename, "rb");
+ if (file == NULL) {
+ eval = -1;
+ continue;
+ }
+ cf.rFile = file;
+ cf.rname = filename;
+ int result = put_arobj(&cf, &sb);
+ (void)fclose(file);
+ if (result!=0) {
+ eval = -2;
+ break;
+ }
+ }
+ }
+ else {
+ eval = -3;
+ }
+ fclose(aFile);
+ }
+ else {
+ eval = -4;
+ }
+ return eval;
+}
diff --git a/Source/CPack/cmCPackDebGenerator.h b/Source/CPack/cmCPackDebGenerator.h
new file mode 100644
index 0000000000..d678cfacf3
--- /dev/null
+++ b/Source/CPack/cmCPackDebGenerator.h
@@ -0,0 +1,77 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackDebGenerator_h
+#define cmCPackDebGenerator_h
+
+
+#include "cmCPackGenerator.h"
+
+/** \class cmCPackDebGenerator
+ * \brief A generator for Debian packages
+ *
+ */
+class cmCPackDebGenerator : public cmCPackGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackDebGenerator, cmCPackGenerator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackDebGenerator();
+ virtual ~cmCPackDebGenerator();
+
+ static bool CanGenerate()
+ {
+#ifdef __APPLE__
+ // on MacOS enable CPackDeb iff dpkg is found
+ std::vector<std::string> locations;
+ locations.push_back("/sw/bin"); // Fink
+ locations.push_back("/opt/local/bin"); // MacPorts
+ return cmSystemTools::FindProgram("dpkg",locations) != "" ? true : false;
+#else
+ // legacy behavior on other systems
+ return true;
+#endif
+ }
+
+protected:
+ virtual int InitializeInternal();
+ /**
+ * This method factors out the work done in component packaging case.
+ */
+ int PackageOnePack(std::string initialToplevel, std::string packageName);
+ /**
+ * The method used to package files when component
+ * install is used. This will create one
+ * archive for each component group.
+ */
+ int PackageComponents(bool ignoreGroup);
+ /**
+ * Special case of component install where all
+ * components will be put in a single installer.
+ */
+ int PackageComponentsAllInOne();
+ virtual int PackageFiles();
+ virtual const char* GetOutputExtension() { return ".deb"; }
+ virtual bool SupportsComponentInstallation() const;
+ virtual std::string GetComponentInstallDirNameSuffix(
+ const std::string& componentName);
+
+private:
+ int createDeb();
+ std::vector<std::string> packageFiles;
+
+};
+
+#endif
diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx
new file mode 100644
index 0000000000..9f0a77eeff
--- /dev/null
+++ b/Source/CPack/cmCPackDragNDropGenerator.cxx
@@ -0,0 +1,609 @@
+/*============================================================================
+ 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 "cmCPackDragNDropGenerator.h"
+#include "cmCPackLog.h"
+#include "cmSystemTools.h"
+#include "cmGeneratedFileStream.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/FStream.hxx>
+
+static const char* SLAHeader =
+"data 'LPic' (5000) {\n"
+" $\"0002 0011 0003 0001 0000 0000 0002 0000\"\n"
+" $\"0008 0003 0000 0001 0004 0000 0004 0005\"\n"
+" $\"0000 000E 0006 0001 0005 0007 0000 0007\"\n"
+" $\"0008 0000 0047 0009 0000 0034 000A 0001\"\n"
+" $\"0035 000B 0001 0020 000C 0000 0011 000D\"\n"
+" $\"0000 005B 0004 0000 0033 000F 0001 000C\"\n"
+" $\"0010 0000 000B 000E 0000\"\n"
+"};\n"
+"\n";
+
+static const char* SLASTREnglish =
+"resource 'STR#' (5002, \"English\") {\n"
+" {\n"
+" \"English\",\n"
+" \"Agree\",\n"
+" \"Disagree\",\n"
+" \"Print\",\n"
+" \"Save...\",\n"
+" \"You agree to the License Agreement terms when you click \"\n"
+" \"the \\\"Agree\\\" button.\",\n"
+" \"Software License Agreement\",\n"
+" \"This text cannot be saved. This disk may be full or locked, "
+"or the \"\n"
+" \"file may be locked.\",\n"
+" \"Unable to print. Make sure you have selected a printer.\"\n"
+" }\n"
+"};\n"
+"\n";
+
+//----------------------------------------------------------------------
+cmCPackDragNDropGenerator::cmCPackDragNDropGenerator()
+{
+ // default to one package file for components
+ this->componentPackageMethod = ONE_PACKAGE;
+}
+
+//----------------------------------------------------------------------
+cmCPackDragNDropGenerator::~cmCPackDragNDropGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackDragNDropGenerator::InitializeInternal()
+{
+ // Starting with Xcode 4.3, look in "/Applications/Xcode.app" first:
+ //
+ std::vector<std::string> paths;
+ paths.push_back("/Applications/Xcode.app/Contents/Developer/Tools");
+ paths.push_back("/Developer/Tools");
+
+ const std::string hdiutil_path = cmSystemTools::FindProgram("hdiutil",
+ std::vector<std::string>(), false);
+ if(hdiutil_path.empty())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot locate hdiutil command"
+ << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_COMMAND_HDIUTIL", hdiutil_path.c_str());
+
+ const std::string setfile_path = cmSystemTools::FindProgram("SetFile",
+ paths, false);
+ if(setfile_path.empty())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot locate SetFile command"
+ << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_COMMAND_SETFILE", setfile_path.c_str());
+
+ const std::string rez_path = cmSystemTools::FindProgram("Rez",
+ paths, false);
+ if(rez_path.empty())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot locate Rez command"
+ << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_COMMAND_REZ", rez_path.c_str());
+
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+const char* cmCPackDragNDropGenerator::GetOutputExtension()
+{
+ return ".dmg";
+}
+
+//----------------------------------------------------------------------
+int cmCPackDragNDropGenerator::PackageFiles()
+{
+ // gather which directories to make dmg files for
+ // multiple directories occur if packaging components or groups separately
+
+ // monolith
+ if(this->Components.empty())
+ {
+ return this->CreateDMG(toplevel, packageFileNames[0]);
+ }
+
+ // component install
+ std::vector<std::string> package_files;
+
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt=this->Components.begin();
+ compIt!=this->Components.end(); ++compIt )
+ {
+ std::string name = GetComponentInstallDirNameSuffix(compIt->first);
+ package_files.push_back(name);
+ }
+ std::sort(package_files.begin(), package_files.end());
+ package_files.erase(std::unique(package_files.begin(),
+ package_files.end()),
+ package_files.end());
+
+
+ // loop to create dmg files
+ packageFileNames.clear();
+ for(size_t i=0; i<package_files.size(); i++)
+ {
+ std::string full_package_name = std::string(toplevel) + std::string("/");
+ if(package_files[i] == "ALL_IN_ONE")
+ {
+ full_package_name += this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ }
+ else
+ {
+ full_package_name += package_files[i];
+ }
+ full_package_name += std::string(GetOutputExtension());
+ packageFileNames.push_back(full_package_name);
+
+ std::string src_dir = toplevel;
+ src_dir += "/";
+ src_dir += package_files[i];
+
+ if(0 == this->CreateDMG(src_dir, full_package_name))
+ {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackDragNDropGenerator::CopyFile(cmOStringStream& source,
+ cmOStringStream& target)
+{
+ if(!cmSystemTools::CopyFileIfDifferent(
+ source.str().c_str(),
+ target.str().c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error copying "
+ << source.str()
+ << " to "
+ << target.str()
+ << std::endl);
+
+ return false;
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackDragNDropGenerator::RunCommand(cmOStringStream& command,
+ std::string* output)
+{
+ int exit_code = 1;
+
+ bool result = cmSystemTools::RunSingleCommand(
+ command.str().c_str(),
+ output,
+ &exit_code,
+ 0,
+ this->GeneratorVerbose,
+ 0);
+
+ if(!result || exit_code)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error executing: "
+ << command.str()
+ << std::endl);
+
+ return false;
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------
+int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
+ const std::string& output_file)
+{
+ // Get optional arguments ...
+ const std::string cpack_package_icon = this->GetOption("CPACK_PACKAGE_ICON")
+ ? this->GetOption("CPACK_PACKAGE_ICON") : "";
+
+ const std::string cpack_dmg_volume_name =
+ this->GetOption("CPACK_DMG_VOLUME_NAME")
+ ? this->GetOption("CPACK_DMG_VOLUME_NAME")
+ : this->GetOption("CPACK_PACKAGE_FILE_NAME");
+
+ const std::string cpack_dmg_format =
+ this->GetOption("CPACK_DMG_FORMAT")
+ ? this->GetOption("CPACK_DMG_FORMAT") : "UDZO";
+
+ // Get optional arguments ...
+ std::string cpack_license_file =
+ this->GetOption("CPACK_RESOURCE_FILE_LICENSE") ?
+ this->GetOption("CPACK_RESOURCE_FILE_LICENSE") : "";
+
+ const std::string cpack_dmg_background_image =
+ this->GetOption("CPACK_DMG_BACKGROUND_IMAGE")
+ ? this->GetOption("CPACK_DMG_BACKGROUND_IMAGE") : "";
+
+ const std::string cpack_dmg_ds_store =
+ this->GetOption("CPACK_DMG_DS_STORE")
+ ? this->GetOption("CPACK_DMG_DS_STORE") : "";
+
+ // 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 = "";
+ }
+
+ // The staging directory contains everything that will end-up inside the
+ // final disk image ...
+ cmOStringStream staging;
+ staging << src_dir;
+
+ // Add a symlink to /Applications so users can drag-and-drop the bundle
+ // into it
+ cmOStringStream application_link;
+ application_link << staging.str() << "/Applications";
+ cmSystemTools::CreateSymlink("/Applications",
+ application_link.str().c_str());
+
+ // Optionally add a custom volume icon ...
+ if(!cpack_package_icon.empty())
+ {
+ cmOStringStream package_icon_source;
+ package_icon_source << cpack_package_icon;
+
+ cmOStringStream package_icon_destination;
+ package_icon_destination << staging.str() << "/.VolumeIcon.icns";
+
+ if(!this->CopyFile(package_icon_source, package_icon_destination))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error copying disk volume icon. "
+ "Check the value of CPACK_PACKAGE_ICON."
+ << std::endl);
+
+ return 0;
+ }
+ }
+
+ // Optionally add a custom .DS_Store file
+ // (e.g. for setting background/layout) ...
+ if(!cpack_dmg_ds_store.empty())
+ {
+ cmOStringStream package_settings_source;
+ package_settings_source << cpack_dmg_ds_store;
+
+ cmOStringStream package_settings_destination;
+ package_settings_destination << staging.str() << "/.DS_Store";
+
+ if(!this->CopyFile(package_settings_source, package_settings_destination))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error copying disk volume settings file. "
+ "Check the value of CPACK_DMG_DS_STORE."
+ << std::endl);
+
+ return 0;
+ }
+ }
+
+ // Optionally add a custom background image ...
+ if(!cpack_dmg_background_image.empty())
+ {
+ cmOStringStream package_background_source;
+ package_background_source << cpack_dmg_background_image;
+
+ cmOStringStream package_background_destination;
+ package_background_destination << staging.str() << "/background.png";
+
+ if(!this->CopyFile(package_background_source,
+ package_background_destination))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error copying disk volume background image. "
+ "Check the value of CPACK_DMG_BACKGROUND_IMAGE."
+ << std::endl);
+
+ return 0;
+ }
+
+ cmOStringStream 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 << "\"";
+
+ if(!this->RunCommand(temp_background_hiding_command))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error setting attributes on disk volume background image."
+ << std::endl);
+
+ return 0;
+ }
+ }
+
+ // Create a temporary read-write disk image ...
+ std::string temp_image = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ temp_image += "/temp.dmg";
+
+ cmOStringStream temp_image_command;
+ temp_image_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
+ temp_image_command << " create";
+ temp_image_command << " -ov";
+ temp_image_command << " -srcfolder \"" << staging.str() << "\"";
+ temp_image_command << " -volname \""
+ << cpack_dmg_volume_name << "\"";
+ temp_image_command << " -format UDRW";
+ temp_image_command << " \"" << temp_image << "\"";
+
+ if(!this->RunCommand(temp_image_command))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error generating temporary disk image."
+ << std::endl);
+
+ return 0;
+ }
+
+ // Optionally set the custom icon flag for the image ...
+ if(!cpack_package_icon.empty())
+ {
+ cmOStringStream temp_mount;
+
+ cmOStringStream attach_command;
+ attach_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
+ attach_command << " attach";
+ attach_command << " \"" << temp_image << "\"";
+
+ std::string attach_output;
+ if(!this->RunCommand(attach_command, &attach_output))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error attaching temporary disk image."
+ << std::endl);
+
+ return 0;
+ }
+
+ cmsys::RegularExpression mountpoint_regex(".*(/Volumes/[^\n]+)\n.*");
+ mountpoint_regex.find(attach_output.c_str());
+ temp_mount << mountpoint_regex.match(1);
+
+ cmOStringStream 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);
+
+ return 0;
+ }
+
+ cmOStringStream detach_command;
+ detach_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
+ detach_command << " detach";
+ detach_command << " \"" << temp_mount.str() << "\"";
+
+ if(!this->RunCommand(detach_command))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error detaching temporary disk image."
+ << std::endl);
+
+ return 0;
+ }
+ }
+
+ if(!cpack_license_file.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::string line;
+ std::getline(ifs, line);
+ // escape quotes
+ std::string::size_type pos = line.find('\"');
+ while(pos != std::string::npos)
+ {
+ line.replace(pos, 1, "\\\"");
+ pos = line.find('\"', pos+2);
+ }
+ // 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)
+ {
+ 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));
+ }
+
+ for(size_t i=0; i<lines.size(); i++)
+ {
+ osf << " \"" << lines[i] << "\"\n";
+ }
+ osf << " \"\\n\"\n";
+ }
+ osf << "};\n";
+ osf << "\n";
+ osf << SLASTREnglish;
+ ifs.close();
+ osf.close();
+ }
+
+ // convert to UDCO
+ std::string temp_udco = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ temp_udco += "/temp-udco.dmg";
+
+ cmOStringStream udco_image_command;
+ udco_image_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
+ udco_image_command << " convert \"" << temp_image << "\"";
+ 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,
+ "Error converting to UDCO dmg for adding SLA." << std::endl
+ << error
+ << std::endl);
+ return 0;
+ }
+
+ // unflatten dmg
+ cmOStringStream unflatten_command;
+ unflatten_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
+ unflatten_command << " unflatten ";
+ unflatten_command << "\"" << temp_udco << "\"";
+
+ if(!this->RunCommand(unflatten_command, &error))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error unflattening dmg for adding SLA." << std::endl
+ << error
+ << std::endl);
+ return 0;
+ }
+
+ // Rez the SLA
+ cmOStringStream embed_sla_command;
+ embed_sla_command << this->GetOption("CPACK_COMMAND_REZ");
+ const char* sysroot = this->GetOption("CPACK_OSX_SYSROOT");
+ if(sysroot && sysroot[0] != '\0')
+ {
+ embed_sla_command << " -isysroot \"" << sysroot << "\"";
+ }
+ embed_sla_command << " \"" << sla_r << "\"";
+ embed_sla_command << " -a -o ";
+ embed_sla_command << "\"" << temp_udco << "\"";
+
+ if(!this->RunCommand(embed_sla_command, &error))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error adding SLA." << std::endl
+ << error
+ << std::endl);
+ return 0;
+ }
+
+ // flatten dmg
+ cmOStringStream flatten_command;
+ flatten_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
+ flatten_command << " flatten ";
+ flatten_command << "\"" << temp_udco << "\"";
+
+ if(!this->RunCommand(flatten_command, &error))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error flattening dmg for adding SLA." << std::endl
+ << error
+ << std::endl);
+ return 0;
+ }
+
+ temp_image = temp_udco;
+ }
+
+
+ // Create the final compressed read-only disk image ...
+ cmOStringStream final_image_command;
+ final_image_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
+ final_image_command << " convert \"" << temp_image << "\"";
+ final_image_command << " -format ";
+ final_image_command << cpack_dmg_format;
+ final_image_command << " -imagekey";
+ final_image_command << " zlib-level=9";
+ final_image_command << " -o \"" << output_file << "\"";
+
+ if(!this->RunCommand(final_image_command))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error compressing disk image."
+ << std::endl);
+
+ return 0;
+ }
+
+ return 1;
+}
+
+bool cmCPackDragNDropGenerator::SupportsComponentInstallation() const
+{
+ return true;
+}
+
+std::string
+cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix(
+ const std::string& componentName)
+{
+ // we want to group components together that go in the same dmg package
+ std::string package_file_name = this->GetOption("CPACK_PACKAGE_FILE_NAME");
+
+ // we have 3 mutually exclusive modes to work in
+ // 1. all components in one package
+ // 2. each group goes in its own package with left over
+ // components in their own package
+ // 3. ignore groups - if grouping is defined, it is ignored
+ // and each component goes in its own package
+
+ if(this->componentPackageMethod == ONE_PACKAGE)
+ {
+ return "ALL_IN_ONE";
+ }
+
+ if(this->componentPackageMethod == ONE_PACKAGE_PER_GROUP)
+ {
+ // We have to find the name of the COMPONENT GROUP
+ // the current COMPONENT belongs to.
+ std::string groupVar = "CPACK_COMPONENT_" +
+ cmSystemTools::UpperCase(componentName) + "_GROUP";
+ const char* _groupName = GetOption(groupVar.c_str());
+ if (_groupName)
+ {
+ std::string groupName = _groupName;
+
+ groupName = GetComponentPackageFileName(package_file_name,
+ groupName, true);
+ return groupName;
+ }
+ }
+
+ return GetComponentPackageFileName(package_file_name, componentName, false);
+}
diff --git a/Source/CPack/cmCPackDragNDropGenerator.h b/Source/CPack/cmCPackDragNDropGenerator.h
new file mode 100644
index 0000000000..808c618868
--- /dev/null
+++ b/Source/CPack/cmCPackDragNDropGenerator.h
@@ -0,0 +1,47 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackDragNDropGenerator_h
+#define cmCPackDragNDropGenerator_h
+
+#include "cmCPackGenerator.h"
+
+/** \class cmCPackDragNDropGenerator
+ * \brief A generator for OSX drag-n-drop installs
+ */
+class cmCPackDragNDropGenerator : public cmCPackGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackDragNDropGenerator, cmCPackGenerator);
+
+ cmCPackDragNDropGenerator();
+ virtual ~cmCPackDragNDropGenerator();
+
+protected:
+ virtual int InitializeInternal();
+ virtual const char* GetOutputExtension();
+ int PackageFiles();
+ bool SupportsComponentInstallation() const;
+
+
+ bool CopyFile(cmOStringStream& source, cmOStringStream& target);
+ bool RunCommand(cmOStringStream& command, std::string* output = 0);
+
+ std::string
+ GetComponentInstallDirNameSuffix(const std::string& componentName);
+
+ int CreateDMG(const std::string& src_dir, const std::string& output_file);
+
+ std::string InstallPrefix;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
new file mode 100644
index 0000000000..1461bb18ea
--- /dev/null
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -0,0 +1,1667 @@
+/*============================================================================
+ 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 "cmCPackGenerator.h"
+
+#include "cmMakefile.h"
+#include "cmCPackLog.h"
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackComponentGroup.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+#include <algorithm>
+
+#if defined(__HAIKU__)
+#include <FindDirectory.h>
+#include <StorageDefs.h>
+#endif
+
+//----------------------------------------------------------------------
+cmCPackGenerator::cmCPackGenerator()
+{
+ this->GeneratorVerbose = cmSystemTools::OUTPUT_NONE;
+ this->MakefileMap = 0;
+ this->Logger = 0;
+ this->componentPackageMethod = ONE_PACKAGE_PER_GROUP;
+}
+
+//----------------------------------------------------------------------
+cmCPackGenerator::~cmCPackGenerator()
+{
+ this->MakefileMap = 0;
+}
+
+//----------------------------------------------------------------------
+void cmCPackGeneratorProgress(const char *msg, float prog, void* ptr)
+{
+ cmCPackGenerator* self = static_cast<cmCPackGenerator*>(ptr);
+ self->DisplayVerboseOutput(msg, prog);
+}
+
+//----------------------------------------------------------------------
+void cmCPackGenerator::DisplayVerboseOutput(const char* msg,
+ float progress)
+{
+ (void)progress;
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl);
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::PrepareNames()
+{
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Create temp directory." << std::endl);
+
+ // checks CPACK_SET_DESTDIR support
+ if (IsOn("CPACK_SET_DESTDIR"))
+ {
+ if (SETDESTDIR_UNSUPPORTED==SupportsSetDestdir())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_SET_DESTDIR is set to ON but the '"
+ << Name << "' generator does NOT support it."
+ << std::endl);
+ return 0;
+ }
+ else if (SETDESTDIR_SHOULD_NOT_BE_USED==SupportsSetDestdir())
+ {
+ cmCPackLogger(cmCPackLog::LOG_WARNING,
+ "CPACK_SET_DESTDIR is set to ON but it is "
+ << "usually a bad idea to do that with '"
+ << Name << "' generator. Use at your own risk."
+ << std::endl);
+ }
+ }
+
+ std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
+ tempDirectory += "/_CPack_Packages/";
+ const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG");
+ if ( toplevelTag )
+ {
+ tempDirectory += toplevelTag;
+ tempDirectory += "/";
+ }
+ tempDirectory += this->GetOption("CPACK_GENERATOR");
+ std::string topDirectory = tempDirectory;
+ const char* pfname = this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ if(!pfname)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_PACKAGE_FILE_NAME not specified" << std::endl);
+ return 0;
+ }
+ std::string outName = pfname;
+ tempDirectory += "/" + outName;
+ if(!this->GetOutputExtension())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "No output extension specified" << std::endl);
+ return 0;
+ }
+ outName += this->GetOutputExtension();
+ const char* pdir = this->GetOption("CPACK_PACKAGE_DIRECTORY");
+ if(!pdir)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_PACKAGE_DIRECTORY not specified" << std::endl);
+ return 0;
+ }
+
+ std::string destFile = pdir;
+ this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PREFIX", destFile.c_str());
+ destFile += "/" + outName;
+ std::string outFile = topDirectory + "/" + outName;
+ this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
+ this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
+ this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str());
+ this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
+ this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
+ outFile.c_str());
+ this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
+ this->SetOptionIfNotSet("CPACK_NATIVE_INSTALL_DIRECTORY",
+ cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
+ this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY",
+ tempDirectory.c_str());
+
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl);
+ const char* descFileName
+ = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE");
+ if ( descFileName )
+ {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Look for: " << descFileName << std::endl);
+ if ( !cmSystemTools::FileExists(descFileName) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find description file name: ["
+ << descFileName << "]" << std::endl);
+ return 0;
+ }
+ cmsys::ifstream ifs(descFileName);
+ if ( !ifs )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot open description file name: " << descFileName << std::endl);
+ return 0;
+ }
+ cmOStringStream ostr;
+ std::string line;
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Read description file: " << descFileName << std::endl);
+ while ( ifs && cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ ostr << cmXMLSafe(line) << std::endl;
+ }
+ this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
+ }
+ if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Project description not specified. Please specify "
+ "CPACK_PACKAGE_DESCRIPTION or CPACK_PACKAGE_DESCRIPTION_FILE."
+ << std::endl);
+ return 0;
+ }
+
+ this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1");
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::InstallProject()
+{
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
+ this->CleanTemporaryDirectory();
+
+ std::string bareTempInstallDirectory
+ = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
+ std::string tempInstallDirectoryStr = bareTempInstallDirectory;
+ bool setDestDir = cmSystemTools::IsOn(this->GetOption("CPACK_SET_DESTDIR"))
+ | cmSystemTools::IsInternallyOn(
+ this->GetOption("CPACK_SET_DESTDIR"));
+ if (!setDestDir)
+ {
+ tempInstallDirectoryStr += this->GetPackagingInstallPrefix();
+ }
+
+ const char* tempInstallDirectory = tempInstallDirectoryStr.c_str();
+ int res = 1;
+ if ( !cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem creating temporary directory: "
+ << (tempInstallDirectory ? tempInstallDirectory : "(NULL)")
+ << std::endl);
+ return 0;
+ }
+
+ if ( setDestDir )
+ {
+ std::string destDir = "DESTDIR=";
+ destDir += tempInstallDirectory;
+ cmSystemTools::PutEnv(destDir.c_str());
+ }
+ else
+ {
+ // Make sure there is no destdir
+ cmSystemTools::PutEnv("DESTDIR=");
+ }
+
+ // If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them
+ // as listed
+ if ( !this->InstallProjectViaInstallCommands(
+ setDestDir, tempInstallDirectory) )
+ {
+ return 0;
+ }
+
+ // If the CPackConfig file sets CPACK_INSTALL_SCRIPT then run them
+ // as listed
+ if ( !this->InstallProjectViaInstallScript(
+ setDestDir, tempInstallDirectory) )
+ {
+ return 0;
+ }
+
+ // If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES
+ // then glob it and copy it to CPACK_TEMPORARY_DIRECTORY
+ // This is used in Source packaging
+ if ( !this->InstallProjectViaInstalledDirectories(
+ setDestDir, tempInstallDirectory) )
+ {
+ return 0;
+ }
+
+
+ // If the project is a CMAKE project then run pre-install
+ // and then read the cmake_install script to run it
+ if ( !this->InstallProjectViaInstallCMakeProjects(
+ setDestDir, bareTempInstallDirectory) )
+ {
+ return 0;
+ }
+
+ if ( setDestDir )
+ {
+ cmSystemTools::PutEnv("DESTDIR=");
+ }
+
+ return res;
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::InstallProjectViaInstallCommands(
+ bool setDestDir, const std::string& tempInstallDirectory)
+{
+ (void) setDestDir;
+ const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
+ if ( installCommands && *installCommands )
+ {
+ std::string tempInstallDirectoryEnv = "CMAKE_INSTALL_PREFIX=";
+ tempInstallDirectoryEnv += tempInstallDirectory;
+ cmSystemTools::PutEnv(tempInstallDirectoryEnv.c_str());
+ std::vector<std::string> installCommandsVector;
+ cmSystemTools::ExpandListArgument(installCommands,installCommandsVector);
+ std::vector<std::string>::iterator it;
+ for ( it = installCommandsVector.begin();
+ it != installCommandsVector.end();
+ ++it )
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << *it
+ << std::endl);
+ std::string output;
+ int retVal = 1;
+ bool resB = cmSystemTools::RunSingleCommand(it->c_str(), &output,
+ &retVal, 0, this->GeneratorVerbose, 0);
+ if ( !resB || retVal )
+ {
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/InstallOutput.log";
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << *it << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running install command: " << *it << std::endl
+ << "Please check " << tmpFile << " for errors"
+ << std::endl);
+ return 0;
+ }
+ }
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::InstallProjectViaInstalledDirectories(
+ bool setDestDir, const std::string& tempInstallDirectory)
+{
+ (void)setDestDir;
+ (void)tempInstallDirectory;
+ std::vector<cmsys::RegularExpression> ignoreFilesRegex;
+ const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
+ if ( cpackIgnoreFiles )
+ {
+ std::vector<std::string> ignoreFilesRegexString;
+ cmSystemTools::ExpandListArgument(cpackIgnoreFiles,
+ ignoreFilesRegexString);
+ std::vector<std::string>::iterator it;
+ for ( it = ignoreFilesRegexString.begin();
+ it != ignoreFilesRegexString.end();
+ ++it )
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Create ignore files regex for: " << *it << std::endl);
+ ignoreFilesRegex.push_back(it->c_str());
+ }
+ }
+ const char* installDirectories
+ = this->GetOption("CPACK_INSTALLED_DIRECTORIES");
+ if ( installDirectories && *installDirectories )
+ {
+ std::vector<std::string> installDirectoriesVector;
+ cmSystemTools::ExpandListArgument(installDirectories,
+ installDirectoriesVector);
+ if ( installDirectoriesVector.size() % 2 != 0 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and "
+ "<subdirectory>. The <subdirectory> can be '.' to be installed in "
+ "the toplevel directory of installation." << std::endl);
+ return 0;
+ }
+ std::vector<std::string>::iterator it;
+ const std::string& tempDir = tempInstallDirectory;
+ for ( it = installDirectoriesVector.begin();
+ it != installDirectoriesVector.end();
+ ++it )
+ {
+ std::list<std::pair<std::string,std::string> > symlinkedFiles;
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
+ cmsys::Glob gl;
+ std::string top = *it;
+ it ++;
+ std::string subdir = *it;
+ std::string findExpr = top;
+ findExpr += "/*";
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Install directory: " << top << std::endl);
+ gl.RecurseOn();
+ if ( !gl.FindFiles(findExpr) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find any files in the installed directory" << std::endl);
+ return 0;
+ }
+ files = gl.GetFiles();
+ std::vector<std::string>::iterator gfit;
+ std::vector<cmsys::RegularExpression>::iterator regIt;
+ for ( gfit = files.begin(); gfit != files.end(); ++ gfit )
+ {
+ bool skip = false;
+ std::string &inFile = *gfit;
+ for ( regIt= ignoreFilesRegex.begin();
+ regIt!= ignoreFilesRegex.end();
+ ++ regIt)
+ {
+ if ( regIt->find(inFile.c_str()) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Ignore file: "
+ << inFile << std::endl);
+ skip = true;
+ }
+ }
+ if ( skip )
+ {
+ continue;
+ }
+ std::string filePath = tempDir;
+ filePath += "/" + subdir + "/"
+ + cmSystemTools::RelativePath(top.c_str(), gfit->c_str());
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: "
+ << inFile << " -> " << filePath << std::endl);
+ /* If the file is a symlink we will have to re-create it */
+ if ( cmSystemTools::FileIsSymlink(inFile.c_str()))
+ {
+ std::string targetFile;
+ std::string inFileRelative =
+ cmSystemTools::RelativePath(top.c_str(),inFile.c_str());
+ cmSystemTools::ReadSymlink(inFile.c_str(),targetFile);
+ symlinkedFiles.push_back(std::pair<std::string,
+ std::string>(targetFile,inFileRelative));
+ }
+ /* If it is not a symlink then do a plain copy */
+ else if (!(
+ cmSystemTools::CopyFileIfDifferent(inFile.c_str(),filePath.c_str())
+ &&
+ cmSystemTools::CopyFileTime(inFile.c_str(),filePath.c_str())
+ ) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: "
+ << inFile << " -> " << filePath << std::endl);
+ return 0;
+ }
+ }
+ /* rebuild symlinks in the installed tree */
+ if (symlinkedFiles.size()>0)
+ {
+ std::list< std::pair<std::string,std::string> >::iterator symlinkedIt;
+ std::string curDir = cmSystemTools::GetCurrentWorkingDirectory();
+ std::string goToDir = tempDir;
+ goToDir += "/"+subdir;
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Change dir to: " << goToDir <<std::endl);
+ cmSystemTools::ChangeDirectory(goToDir.c_str());
+ for (symlinkedIt=symlinkedFiles.begin();
+ symlinkedIt != symlinkedFiles.end();
+ ++symlinkedIt)
+ {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Will create a symlink: "
+ << symlinkedIt->second << "--> "
+ << symlinkedIt->first << std::endl);
+ if (!cmSystemTools::CreateSymlink((symlinkedIt->first).c_str(),
+ (symlinkedIt->second).c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create symlink: "
+ << symlinkedIt->second << "--> "
+ << symlinkedIt->first << std::endl);
+ return 0;
+ }
+ }
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Going back to: "
+ << curDir <<std::endl);
+ cmSystemTools::ChangeDirectory(curDir.c_str());
+ }
+ }
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::InstallProjectViaInstallScript(
+ bool setDestDir, const std::string& tempInstallDirectory)
+{
+ const char* cmakeScripts
+ = this->GetOption("CPACK_INSTALL_SCRIPT");
+ if ( cmakeScripts && *cmakeScripts )
+ {
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Install scripts: " << cmakeScripts << std::endl);
+ std::vector<std::string> cmakeScriptsVector;
+ cmSystemTools::ExpandListArgument(cmakeScripts,
+ cmakeScriptsVector);
+ std::vector<std::string>::iterator it;
+ for ( it = cmakeScriptsVector.begin();
+ it != cmakeScriptsVector.end();
+ ++it )
+ {
+ std::string installScript = *it;
+
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Install script: " << installScript << std::endl);
+
+ if ( setDestDir )
+ {
+ // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
+ // underneath the tempInstallDirectory. The value of the project's
+ // CMAKE_INSTALL_PREFIX is sent in here as the value of the
+ // CPACK_INSTALL_PREFIX variable.
+
+ std::string dir;
+ if (this->GetOption("CPACK_INSTALL_PREFIX"))
+ {
+ dir += this->GetOption("CPACK_INSTALL_PREFIX");
+ }
+ this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str());
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)"
+ << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" << std::endl);
+ }
+ else
+ {
+ this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str());
+
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Using non-DESTDIR install... (this->SetOption)" << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
+ << "'" << std::endl);
+ }
+
+ this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
+ tempInstallDirectory.c_str());
+ this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
+ tempInstallDirectory.c_str());
+ int res = this->MakefileMap->ReadListFile(0, installScript.c_str());
+ if ( cmSystemTools::GetErrorOccuredFlag() || !res )
+ {
+ return 0;
+ }
+ }
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
+ bool setDestDir, const std::string& baseTempInstallDirectory)
+{
+ const char* cmakeProjects
+ = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
+ const char* cmakeGenerator
+ = this->GetOption("CPACK_CMAKE_GENERATOR");
+ std::string absoluteDestFiles;
+ if ( cmakeProjects && *cmakeProjects )
+ {
+ if ( !cmakeGenerator )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_INSTALL_CMAKE_PROJECTS is specified, but "
+ "CPACK_CMAKE_GENERATOR is not. CPACK_CMAKE_GENERATOR "
+ "is required to install the project."
+ << std::endl);
+ return 0;
+ }
+ std::vector<std::string> cmakeProjectsVector;
+ cmSystemTools::ExpandListArgument(cmakeProjects,
+ cmakeProjectsVector);
+ std::vector<std::string>::iterator it;
+ for ( it = cmakeProjectsVector.begin();
+ it != cmakeProjectsVector.end();
+ ++it )
+ {
+ if ( it+1 == cmakeProjectsVector.end() ||
+ it+2 == cmakeProjectsVector.end() ||
+ it+3 == cmakeProjectsVector.end() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Not enough items on list: CPACK_INSTALL_CMAKE_PROJECTS. "
+ "CPACK_INSTALL_CMAKE_PROJECTS should hold quadruplet of install "
+ "directory, install project name, install component, and install "
+ "subdirectory."
+ << std::endl);
+ return 0;
+ }
+ std::string installDirectory = *it;
+ ++it;
+ std::string installProjectName = *it;
+ ++it;
+ std::string installComponent = *it;
+ ++it;
+ std::string installSubDirectory = *it;
+ std::string installFile = installDirectory + "/cmake_install.cmake";
+
+ std::vector<std::string> componentsVector;
+
+ bool componentInstall = false;
+ /*
+ * We do a component install iff
+ * - the CPack generator support component
+ * - the user did not request Monolithic install
+ * (this works at CPack time too)
+ */
+ if (this->SupportsComponentInstallation() &
+ !(this->IsOn("CPACK_MONOLITHIC_INSTALL")))
+ {
+ // Determine the installation types for this project (if provided).
+ std::string installTypesVar = "CPACK_"
+ + cmSystemTools::UpperCase(installComponent) + "_INSTALL_TYPES";
+ const char *installTypes = this->GetOption(installTypesVar);
+ if (installTypes && *installTypes)
+ {
+ std::vector<std::string> installTypesVector;
+ cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
+ std::vector<std::string>::iterator installTypeIt;
+ for (installTypeIt = installTypesVector.begin();
+ installTypeIt != installTypesVector.end();
+ ++installTypeIt)
+ {
+ this->GetInstallationType(installProjectName,
+ *installTypeIt);
+ }
+ }
+
+ // Determine the set of components that will be used in this project
+ std::string componentsVar
+ = "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent);
+ const char *components = this->GetOption(componentsVar);
+ if (components && *components)
+ {
+ cmSystemTools::ExpandListArgument(components, componentsVector);
+ std::vector<std::string>::iterator compIt;
+ for (compIt = componentsVector.begin();
+ compIt != componentsVector.end();
+ ++compIt)
+ {
+ GetComponent(installProjectName, *compIt);
+ }
+ componentInstall = true;
+ }
+ }
+ if (componentsVector.empty())
+ {
+ componentsVector.push_back(installComponent);
+ }
+
+ const char* buildConfigCstr = this->GetOption("CPACK_BUILD_CONFIG");
+ std::string buildConfig = buildConfigCstr ? buildConfigCstr : "";
+ cmGlobalGenerator* globalGenerator
+ = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
+ cmakeGenerator);
+ // set the global flag for unix style paths on cmSystemTools as
+ // soon as the generator is set. This allows gmake to be used
+ // on windows.
+ cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
+
+ // Does this generator require pre-install?
+ if ( globalGenerator->GetPreinstallTargetName() )
+ {
+ globalGenerator->FindMakeProgram(this->MakefileMap);
+ std::string cmakeMakeProgram
+ = this->MakefileMap->GetSafeDefinition("CMAKE_MAKE_PROGRAM");
+ std::vector<std::string> buildCommand;
+ globalGenerator->GenerateBuildCommand(buildCommand, cmakeMakeProgram,
+ installProjectName, installDirectory,
+ globalGenerator->GetPreinstallTargetName(),
+ buildConfig, false);
+ std::string buildCommandStr =
+ cmSystemTools::PrintSingleCommand(buildCommand);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Install command: " << buildCommandStr << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Run preinstall target for: " << installProjectName << std::endl);
+ std::string output;
+ int retVal = 1;
+ bool resB =
+ cmSystemTools::RunSingleCommand(buildCommand,
+ &output,
+ &retVal,
+ installDirectory.c_str(),
+ this->GeneratorVerbose, 0);
+ if ( !resB || retVal )
+ {
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/PreinstallOutput.log";
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << buildCommandStr << std::endl
+ << "# Directory: " << installDirectory << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running install command: " << buildCommandStr
+ << std::endl
+ << "Please check " << tmpFile << " for errors"
+ << std::endl);
+ return 0;
+ }
+ }
+ delete globalGenerator;
+
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Install project: " << installProjectName << std::endl);
+
+ // Run the installation for each component
+ std::vector<std::string>::iterator componentIt;
+ for (componentIt = componentsVector.begin();
+ componentIt != componentsVector.end();
+ ++componentIt)
+ {
+ std::string tempInstallDirectory = baseTempInstallDirectory;
+ installComponent = *componentIt;
+ if (componentInstall)
+ {
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Install component: " << installComponent
+ << std::endl);
+ }
+
+ cmake cm;
+ cm.AddCMakePaths();
+ cm.SetProgressCallback(cmCPackGeneratorProgress, this);
+ cmGlobalGenerator gg;
+ gg.SetCMakeInstance(&cm);
+ cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
+ cmMakefile *mf = lg->GetMakefile();
+ std::string realInstallDirectory = tempInstallDirectory;
+ if ( !installSubDirectory.empty() && installSubDirectory != "/" )
+ {
+ realInstallDirectory += installSubDirectory;
+ }
+ if (componentInstall)
+ {
+ tempInstallDirectory += "/";
+ // Some CPack generators would rather chose
+ // the local installation directory suffix.
+ // Some (e.g. RPM) use
+ // one install directory for each component **GROUP**
+ // instead of the default
+ // one install directory for each component.
+ tempInstallDirectory +=
+ GetComponentInstallDirNameSuffix(installComponent);
+ if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY"))
+ {
+ tempInstallDirectory += "/";
+ tempInstallDirectory += this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ }
+ }
+
+ if (!setDestDir)
+ {
+ tempInstallDirectory += this->GetPackagingInstallPrefix();
+ }
+
+ if ( setDestDir )
+ {
+ // For DESTDIR based packaging, use the *project*
+ // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
+ // value of the project's CMAKE_INSTALL_PREFIX is sent in here as
+ // the value of the CPACK_INSTALL_PREFIX variable.
+ //
+ // If DESTDIR has been 'internally set ON' this means that
+ // the underlying CPack specific generator did ask for that
+ // In this case we may override CPACK_INSTALL_PREFIX with
+ // CPACK_PACKAGING_INSTALL_PREFIX
+ // I know this is tricky and awkward but it's the price for
+ // CPACK_SET_DESTDIR backward compatibility.
+ if (cmSystemTools::IsInternallyOn(
+ this->GetOption("CPACK_SET_DESTDIR")))
+ {
+ this->SetOption("CPACK_INSTALL_PREFIX",
+ this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX"));
+ }
+ std::string dir;
+ if (this->GetOption("CPACK_INSTALL_PREFIX"))
+ {
+ dir += this->GetOption("CPACK_INSTALL_PREFIX");
+ }
+ mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
+
+ cmCPackLogger(
+ cmCPackLog::LOG_DEBUG,
+ "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)"
+ << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
+ << std::endl);
+
+ // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
+ // exists:
+ //
+ if (cmSystemTools::StringStartsWith(dir.c_str(), "/"))
+ {
+ dir = tempInstallDirectory + dir;
+ }
+ else
+ {
+ dir = tempInstallDirectory + "/" + dir;
+ }
+ /*
+ * We must re-set DESTDIR for each component
+ * We must not add the CPACK_INSTALL_PREFIX part because
+ * it will be added using the override of CMAKE_INSTALL_PREFIX
+ * The main reason for this awkward trick is that
+ * are using DESTDIR for 2 different reasons:
+ * - Because it was asked by the CPack Generator or the user
+ * using CPACK_SET_DESTDIR
+ * - Because it was already used for component install
+ * in order to put things in subdirs...
+ */
+ cmSystemTools::PutEnv(
+ (std::string("DESTDIR=")+tempInstallDirectory).c_str()
+ );
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Creating directory: '" << dir << "'" << std::endl);
+
+ if ( !cmsys::SystemTools::MakeDirectory(dir.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem creating temporary directory: "
+ << dir << std::endl);
+ return 0;
+ }
+ }
+ else
+ {
+ mf->AddDefinition("CMAKE_INSTALL_PREFIX",
+ tempInstallDirectory.c_str());
+
+ if ( !cmsys::SystemTools::MakeDirectory(
+ tempInstallDirectory.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem creating temporary directory: "
+ << tempInstallDirectory << std::endl);
+ return 0;
+ }
+
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Using non-DESTDIR install... (mf->AddDefinition)"
+ << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Setting CMAKE_INSTALL_PREFIX to '"
+ << tempInstallDirectory
+ << "'" << std::endl);
+ }
+
+ if (!buildConfig.empty())
+ {
+ mf->AddDefinition("BUILD_TYPE", buildConfig.c_str());
+ }
+ std::string installComponentLowerCase
+ = cmSystemTools::LowerCase(installComponent);
+ if ( installComponentLowerCase != "all" )
+ {
+ mf->AddDefinition("CMAKE_INSTALL_COMPONENT",
+ installComponent.c_str());
+ }
+
+ // strip on TRUE, ON, 1, one or several file names, but not on
+ // FALSE, OFF, 0 and an empty string
+ if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES")))
+ {
+ mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
+ }
+ // Remember the list of files before installation
+ // of the current component (if we are in component install)
+ const char* InstallPrefix = tempInstallDirectory.c_str();
+ std::vector<std::string> filesBefore;
+ std::string findExpr(InstallPrefix);
+ if (componentInstall)
+ {
+ cmsys::Glob glB;
+ findExpr += "/*";
+ glB.RecurseOn();
+ glB.FindFiles(findExpr);
+ filesBefore = glB.GetFiles();
+ std::sort(filesBefore.begin(),filesBefore.end());
+ }
+
+ // If CPack was asked to warn on ABSOLUTE INSTALL DESTINATION
+ // then forward request to cmake_install.cmake script
+ if (this->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION"))
+ {
+ mf->AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION",
+ "1");
+ }
+ // If current CPack generator does support
+ // ABSOLUTE INSTALL DESTINATION or CPack has been asked for
+ // then ask cmake_install.cmake script to error out
+ // as soon as it occurs (before installing file)
+ if (!SupportsAbsoluteDestination() ||
+ this->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION"))
+ {
+ mf->AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION",
+ "1");
+ }
+ // do installation
+ int res = mf->ReadListFile(0, installFile.c_str());
+ // forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES
+ // to CPack (may be used by generators like CPack RPM or DEB)
+ // in order to transparently handle ABSOLUTE PATH
+ if (mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES"))
+ {
+ mf->AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES",
+ mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES"));
+ }
+
+ // Now rebuild the list of files after installation
+ // of the current component (if we are in component install)
+ if (componentInstall)
+ {
+ cmsys::Glob glA;
+ glA.RecurseOn();
+ glA.FindFiles(findExpr);
+ std::vector<std::string> filesAfter = glA.GetFiles();
+ std::sort(filesAfter.begin(),filesAfter.end());
+ std::vector<std::string>::iterator diff;
+ std::vector<std::string> result(filesAfter.size());
+ diff = std::set_difference (
+ filesAfter.begin(),filesAfter.end(),
+ filesBefore.begin(),filesBefore.end(),
+ result.begin());
+
+ std::vector<std::string>::iterator fit;
+ std::string localFileName;
+ // Populate the File field of each component
+ for (fit=result.begin();fit!=diff;++fit)
+ {
+ localFileName =
+ cmSystemTools::RelativePath(InstallPrefix, fit->c_str());
+ localFileName =
+ localFileName.substr(localFileName.find_first_not_of('/'),
+ std::string::npos);
+ Components[installComponent].Files.push_back(localFileName);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file <"
+ <<localFileName<<"> to component <"
+ <<installComponent<<">"<<std::endl);
+ }
+ }
+
+ if (NULL !=mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
+ if (absoluteDestFiles.length()>0) {
+ absoluteDestFiles +=";";
+ }
+ absoluteDestFiles +=
+ mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES");
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Got some ABSOLUTE DESTINATION FILES: "
+ << absoluteDestFiles << std::endl);
+ // define component specific var
+ if (componentInstall)
+ {
+ std::string absoluteDestFileComponent =
+ std::string("CPACK_ABSOLUTE_DESTINATION_FILES")
+ + "_" + GetComponentInstallDirNameSuffix(installComponent);
+ if (NULL != this->GetOption(absoluteDestFileComponent))
+ {
+ std::string absoluteDestFilesListComponent =
+ this->GetOption(absoluteDestFileComponent);
+ absoluteDestFilesListComponent +=";";
+ absoluteDestFilesListComponent +=
+ mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES");
+ this->SetOption(absoluteDestFileComponent,
+ absoluteDestFilesListComponent.c_str());
+ }
+ else
+ {
+ this->SetOption(absoluteDestFileComponent,
+ mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"));
+ }
+ }
+ }
+ if ( cmSystemTools::GetErrorOccuredFlag() || !res )
+ {
+ return 0;
+ }
+ }
+ }
+ }
+ this->SetOption("CPACK_ABSOLUTE_DESTINATION_FILES",
+ absoluteDestFiles.c_str());
+ return 1;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackGenerator::ReadListFile(const char* moduleName)
+{
+ bool retval;
+ std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
+ retval = this->MakefileMap->ReadListFile(0, fullPath.c_str());
+ // include FATAL_ERROR and ERROR in the return status
+ retval = retval && (! cmSystemTools::GetErrorOccuredFlag());
+ return retval;
+}
+
+//----------------------------------------------------------------------
+void cmCPackGenerator::SetOptionIfNotSet(const std::string& op,
+ const char* value)
+{
+ const char* def = this->MakefileMap->GetDefinition(op);
+ if ( def && *def )
+ {
+ return;
+ }
+ this->SetOption(op, value);
+}
+
+//----------------------------------------------------------------------
+void cmCPackGenerator::SetOption(const std::string& op, const char* value)
+{
+ if ( !value )
+ {
+ this->MakefileMap->RemoveDefinition(op);
+ return;
+ }
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
+ << "::SetOption(" << op << ", " << value << ")" << std::endl);
+ this->MakefileMap->AddDefinition(op, value);
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::DoPackage()
+{
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "Create package using " << this->Name << std::endl);
+
+ // Prepare CPack internal name and check
+ // values for many CPACK_xxx vars
+ if ( !this->PrepareNames() )
+ {
+ return 0;
+ }
+
+ // Digest Component grouping specification
+ if ( !this->PrepareGroupingKind() )
+ {
+ return 0;
+ }
+
+ if ( cmSystemTools::IsOn(
+ this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY")) )
+ {
+ const char* toplevelDirectory
+ = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ if ( cmSystemTools::FileExists(toplevelDirectory) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Remove toplevel directory: "
+ << toplevelDirectory << std::endl);
+ if ( !cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem removing toplevel directory: "
+ << toplevelDirectory
+ << std::endl);
+ return 0;
+ }
+ }
+ }
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "About to install project " << std::endl);
+
+ if ( !this->InstallProject() )
+ {
+ return 0;
+ }
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Done install project " << std::endl);
+
+
+ const char* tempPackageFileName = this->GetOption(
+ "CPACK_TEMPORARY_PACKAGE_FILE_NAME");
+ const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
+ cmsys::Glob gl;
+ std::string findExpr = tempDirectory;
+ findExpr += "/*";
+ gl.RecurseOn();
+ gl.SetRecurseThroughSymlinks(false);
+ if ( !gl.FindFiles(findExpr) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find any files in the packaging tree" << std::endl);
+ return 0;
+ }
+
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package" << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Package files to: "
+ << (tempPackageFileName ? tempPackageFileName : "(NULL)") << std::endl);
+ if ( cmSystemTools::FileExists(tempPackageFileName) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove old package file"
+ << std::endl);
+ cmSystemTools::RemoveFile(tempPackageFileName);
+ }
+ if ( cmSystemTools::IsOn(this->GetOption(
+ "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
+ {
+ tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ }
+
+ // The files to be installed
+ files = gl.GetFiles();
+
+ packageFileNames.clear();
+ /* Put at least one file name into the list of
+ * wanted packageFileNames. The specific generator
+ * may update this during PackageFiles.
+ * (either putting several names or updating the provided one)
+ */
+ packageFileNames.push_back(tempPackageFileName ? tempPackageFileName : "");
+ toplevel = tempDirectory;
+ if ( !this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag())
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory"
+ << std::endl);
+ return 0;
+ }
+
+ /*
+ * Copy the generated packages to final destination
+ * - there may be several of them
+ * - the initially provided name may have changed
+ * (because the specific generator did 'normalize' it)
+ */
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copying final package(s) ["
+ <<packageFileNames.size()
+ <<"]:"<<std::endl);
+ std::vector<std::string>::iterator it;
+ /* now copy package one by one */
+ for (it=packageFileNames.begin();it!=packageFileNames.end();++it)
+ {
+ std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
+ tempPackageFileName = it->c_str();
+ tmpPF += "/"+cmSystemTools::GetFilenameName(*it);
+ const char* packageFileName = tmpPF.c_str();
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy final package(s): "
+ << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
+ << " to "
+ << (packageFileName ? packageFileName : "(NULL)")
+ << std::endl);
+ if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
+ packageFileName) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: "
+ << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
+ << " to "
+ << (packageFileName ? packageFileName : "(NULL)")
+ << std::endl);
+ return 0;
+ }
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- package: "
+ << packageFileName
+ << " generated." << std::endl);
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::Initialize(const std::string& name, cmMakefile* mf)
+{
+ this->MakefileMap = mf;
+ this->Name = name;
+ // set the running generator name
+ this->SetOption("CPACK_GENERATOR", this->Name.c_str());
+ // Load the project specific config file
+ const char* config =
+ this->GetOption("CPACK_PROJECT_CONFIG_FILE");
+ if(config)
+ {
+ mf->ReadListFile(config);
+ }
+ int result = this->InitializeInternal();
+ if (cmSystemTools::GetErrorOccuredFlag())
+ {
+ return 0;
+ }
+
+ // If a generator subclass did not already set this option in its
+ // InitializeInternal implementation, and the project did not already set
+ // it, the default value should be:
+ this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
+
+ return result;
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::InitializeInternal()
+{
+ return 1;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackGenerator::IsSet(const std::string& name) const
+{
+ return this->MakefileMap->IsSet(name);
+}
+
+//----------------------------------------------------------------------
+bool cmCPackGenerator::IsOn(const std::string& name) const
+{
+ return cmSystemTools::IsOn(GetOption(name));
+}
+
+//----------------------------------------------------------------------
+const char* cmCPackGenerator::GetOption(const std::string& op) const
+{
+ const char* ret = this->MakefileMap->GetDefinition(op);
+ if(!ret)
+ {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Warning, GetOption return NULL for: "
+ << op
+ << std::endl);
+ }
+ return ret;
+}
+
+//----------------------------------------------------------------------
+std::vector<std::string> cmCPackGenerator::GetOptions() const
+{
+ return this->MakefileMap->GetDefinitions();
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::PackageFiles()
+{
+ return 0;
+}
+
+//----------------------------------------------------------------------
+const char* cmCPackGenerator::GetInstallPath()
+{
+ if ( !this->InstallPath.empty() )
+ {
+ return this->InstallPath.c_str();
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
+ const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
+ if ( prgfiles )
+ {
+ this->InstallPath = prgfiles;
+ }
+ else if ( sysDrive )
+ {
+ this->InstallPath = sysDrive;
+ this->InstallPath += "/Program Files";
+ }
+ else
+ {
+ this->InstallPath = "c:/Program Files";
+ }
+ this->InstallPath += "/";
+ this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
+ this->InstallPath += "-";
+ this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
+#elif defined(__HAIKU__)
+ char dir[B_PATH_NAME_LENGTH];
+ if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir)) == B_OK)
+ {
+ this->InstallPath = dir;
+ }
+ else
+ {
+ this->InstallPath = "/boot/system";
+ }
+#else
+ this->InstallPath = "/usr/local/";
+#endif
+ return this->InstallPath.c_str();
+}
+
+//----------------------------------------------------------------------
+const char* cmCPackGenerator::GetPackagingInstallPrefix()
+{
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
+ << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl);
+
+ return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
+}
+
+//----------------------------------------------------------------------
+std::string cmCPackGenerator::FindTemplate(const char* name)
+{
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
+ << (name ? name : "(NULL)") << std::endl);
+ std::string ffile = this->MakefileMap->GetModulesFile(name);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
+ << ffile << std::endl);
+ return ffile;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackGenerator::ConfigureString(const std::string& inString,
+ std::string& outString)
+{
+ this->MakefileMap->ConfigureString(inString,
+ outString, true, false);
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackGenerator::ConfigureFile(const char* inName,
+ const char* outName, bool copyOnly /* = false */)
+{
+ return this->MakefileMap->ConfigureFile(inName, outName,
+ copyOnly, true, false) == 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::CleanTemporaryDirectory()
+{
+ std::string tempInstallDirectoryWithPostfix
+ = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
+ const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
+ if(cmsys::SystemTools::FileExists(tempInstallDirectory))
+ {
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Clean temporary : "
+ << tempInstallDirectory << std::endl);
+ if(!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem removing temporary directory: " <<
+ tempInstallDirectory
+ << std::endl);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+cmInstalledFile const* cmCPackGenerator::GetInstalledFile(
+ std::string const& name) const
+{
+ cmake const* cm = this->MakefileMap->GetCMakeInstance();
+ return cm->GetInstalledFile(name);
+}
+
+//----------------------------------------------------------------------
+int cmCPackGenerator::PrepareGroupingKind()
+{
+ // find a component package method specified by the user
+ ComponentPackageMethod method = UNKNOWN_COMPONENT_PACKAGE_METHOD;
+
+ if(this->GetOption("CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE"))
+ {
+ method = ONE_PACKAGE;
+ }
+
+ if(this->GetOption("CPACK_COMPONENTS_IGNORE_GROUPS"))
+ {
+ method = ONE_PACKAGE_PER_COMPONENT;
+ }
+
+ if(this->GetOption("CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP"))
+ {
+ method = ONE_PACKAGE_PER_GROUP;
+ }
+
+ std::string groupingType;
+
+ // Second way to specify grouping
+ if (NULL != this->GetOption("CPACK_COMPONENTS_GROUPING")) {
+ groupingType = this->GetOption("CPACK_COMPONENTS_GROUPING");
+ }
+
+ if (groupingType.length()>0)
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
+ << this->Name << "]"
+ << " requested component grouping = "<< groupingType <<std::endl);
+ if (groupingType == "ALL_COMPONENTS_IN_ONE")
+ {
+ method = ONE_PACKAGE;
+ }
+ else if (groupingType == "IGNORE")
+ {
+ method = ONE_PACKAGE_PER_COMPONENT;
+ }
+ else if (groupingType == "ONE_PER_GROUP")
+ {
+ method = ONE_PACKAGE_PER_GROUP;
+ }
+ else
+ {
+ cmCPackLogger(cmCPackLog::LOG_WARNING, "["
+ << this->Name << "]"
+ << " requested component grouping type <"<< groupingType
+ << "> UNKNOWN not in (ALL_COMPONENTS_IN_ONE,IGNORE,ONE_PER_GROUP)"
+ << std::endl);
+ }
+ }
+
+ // Some components were defined but NO group
+ // fallback to default if not group based
+ if(method == ONE_PACKAGE_PER_GROUP &&
+ this->ComponentGroups.empty() && !this->Components.empty())
+ {
+ if(componentPackageMethod == ONE_PACKAGE)
+ {
+ method = ONE_PACKAGE;
+ }
+ else
+ {
+ method = ONE_PACKAGE_PER_COMPONENT;
+ }
+ cmCPackLogger(cmCPackLog::LOG_WARNING, "["
+ << this->Name << "]"
+ << " One package per component group requested, "
+ << "but NO component groups exist: Ignoring component group."
+ << std::endl);
+ }
+
+ // if user specified packaging method, override the default packaging method
+ if(method != UNKNOWN_COMPONENT_PACKAGE_METHOD)
+ {
+ componentPackageMethod = method;
+ }
+
+ const char* method_names[] =
+ {
+ "ALL_COMPONENTS_IN_ONE",
+ "IGNORE_GROUPS",
+ "ONE_PER_GROUP"
+ };
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
+ << this->Name << "]"
+ << " requested component grouping = "
+ << method_names[componentPackageMethod]
+ << std::endl);
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+std::string cmCPackGenerator::GetComponentInstallDirNameSuffix(
+ const std::string& componentName) {
+ return componentName;
+}
+//----------------------------------------------------------------------
+std::string cmCPackGenerator::GetComponentPackageFileName(
+ const std::string& initialPackageFileName,
+ const std::string& groupOrComponentName,
+ bool isGroupName) {
+
+ /*
+ * the default behavior is to use the
+ * component [group] name as a suffix
+ */
+ std::string suffix="-"+groupOrComponentName;
+ /* check if we should use DISPLAY name */
+ std::string dispNameVar = "CPACK_"+Name+"_USE_DISPLAY_NAME_IN_FILENAME";
+ if (IsOn(dispNameVar))
+ {
+ /* the component Group case */
+ if (isGroupName)
+ {
+ std::string groupDispVar = "CPACK_COMPONENT_GROUP_"
+ + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
+ const char* groupDispName = GetOption(groupDispVar);
+ if (groupDispName)
+ {
+ suffix = "-"+std::string(groupDispName);
+ }
+ }
+ /* the [single] component case */
+ else
+ {
+ std::string dispVar = "CPACK_COMPONENT_"
+ + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
+ const char* dispName = GetOption(dispVar);
+ if(dispName)
+ {
+ suffix = "-"+std::string(dispName);
+ }
+ }
+ }
+ return initialPackageFileName + suffix;
+}
+
+//----------------------------------------------------------------------
+enum cmCPackGenerator::CPackSetDestdirSupport
+cmCPackGenerator::SupportsSetDestdir() const
+{
+ return cmCPackGenerator::SETDESTDIR_SUPPORTED;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackGenerator::SupportsAbsoluteDestination() const
+{
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackGenerator::SupportsComponentInstallation() const
+{
+ return false;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackGenerator::WantsComponentInstallation() const
+{
+ return (!IsOn("CPACK_MONOLITHIC_INSTALL") & SupportsComponentInstallation());
+}
+
+//----------------------------------------------------------------------
+cmCPackInstallationType*
+cmCPackGenerator::GetInstallationType(const std::string& projectName,
+ const std::string& name)
+{
+ (void) projectName;
+ bool hasInstallationType = this->InstallationTypes.count(name) != 0;
+ cmCPackInstallationType *installType = &this->InstallationTypes[name];
+ if (!hasInstallationType)
+ {
+ // Define the installation type
+ std::string macroPrefix = "CPACK_INSTALL_TYPE_"
+ + cmsys::SystemTools::UpperCase(name);
+ installType->Name = name;
+
+ const char* displayName
+ = this->GetOption(macroPrefix + "_DISPLAY_NAME");
+ if (displayName && *displayName)
+ {
+ installType->DisplayName = displayName;
+ }
+ else
+ {
+ installType->DisplayName = installType->Name;
+ }
+
+ installType->Index = static_cast<unsigned>(
+ this->InstallationTypes.size());
+ }
+ return installType;
+}
+
+//----------------------------------------------------------------------
+cmCPackComponent*
+cmCPackGenerator::GetComponent(const std::string& projectName,
+ const std::string& name)
+{
+ bool hasComponent = this->Components.count(name) != 0;
+ cmCPackComponent *component = &this->Components[name];
+ if (!hasComponent)
+ {
+ // Define the component
+ std::string macroPrefix = "CPACK_COMPONENT_"
+ + cmsys::SystemTools::UpperCase(name);
+ component->Name = name;
+ const char* displayName
+ = this->GetOption(macroPrefix + "_DISPLAY_NAME");
+ if (displayName && *displayName)
+ {
+ component->DisplayName = displayName;
+ }
+ else
+ {
+ component->DisplayName = component->Name;
+ }
+ component->IsHidden
+ = this->IsOn(macroPrefix + "_HIDDEN");
+ component->IsRequired
+ = this->IsOn(macroPrefix + "_REQUIRED");
+ component->IsDisabledByDefault
+ = this->IsOn(macroPrefix + "_DISABLED");
+ component->IsDownloaded
+ = this->IsOn(macroPrefix + "_DOWNLOADED")
+ || cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
+
+ const char* archiveFile = this->GetOption(macroPrefix +
+ "_ARCHIVE_FILE");
+ if (archiveFile && *archiveFile)
+ {
+ component->ArchiveFile = archiveFile;
+ }
+
+ const char* groupName = this->GetOption(macroPrefix + "_GROUP");
+ if (groupName && *groupName)
+ {
+ component->Group = GetComponentGroup(projectName, groupName);
+ component->Group->Components.push_back(component);
+ }
+ else
+ {
+ component->Group = 0;
+ }
+
+ const char* description
+ = this->GetOption(macroPrefix + "_DESCRIPTION");
+ if (description && *description)
+ {
+ component->Description = description;
+ }
+
+ // Determine the installation types.
+ const char *installTypes
+ = this->GetOption(macroPrefix + "_INSTALL_TYPES");
+ if (installTypes && *installTypes)
+ {
+ std::vector<std::string> installTypesVector;
+ cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
+ std::vector<std::string>::iterator installTypesIt;
+ for (installTypesIt = installTypesVector.begin();
+ installTypesIt != installTypesVector.end();
+ ++installTypesIt)
+ {
+ component->InstallationTypes.push_back(
+ this->GetInstallationType(projectName, *installTypesIt));
+ }
+ }
+
+ // Determine the component dependencies.
+ const char *depends = this->GetOption(macroPrefix + "_DEPENDS");
+ if (depends && *depends)
+ {
+ std::vector<std::string> dependsVector;
+ cmSystemTools::ExpandListArgument(depends, dependsVector);
+ std::vector<std::string>::iterator dependIt;
+ for (dependIt = dependsVector.begin();
+ dependIt != dependsVector.end();
+ ++dependIt)
+ {
+ cmCPackComponent *child = GetComponent(projectName,
+ *dependIt);
+ component->Dependencies.push_back(child);
+ child->ReverseDependencies.push_back(component);
+ }
+ }
+ }
+ return component;
+}
+
+//----------------------------------------------------------------------
+cmCPackComponentGroup*
+cmCPackGenerator::GetComponentGroup(const std::string& projectName,
+ const std::string& name)
+{
+ (void) projectName;
+ std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
+ + cmsys::SystemTools::UpperCase(name);
+ bool hasGroup = this->ComponentGroups.count(name) != 0;
+ cmCPackComponentGroup *group = &this->ComponentGroups[name];
+ if (!hasGroup)
+ {
+ // Define the group
+ group->Name = name;
+ const char* displayName
+ = this->GetOption(macroPrefix + "_DISPLAY_NAME");
+ if (displayName && *displayName)
+ {
+ group->DisplayName = displayName;
+ }
+ else
+ {
+ group->DisplayName = group->Name;
+ }
+
+ const char* description
+ = this->GetOption(macroPrefix + "_DESCRIPTION");
+ if (description && *description)
+ {
+ group->Description = description;
+ }
+ group->IsBold
+ = this->IsOn(macroPrefix + "_BOLD_TITLE");
+ group->IsExpandedByDefault
+ = this->IsOn(macroPrefix + "_EXPANDED");
+ const char* parentGroupName
+ = this->GetOption(macroPrefix + "_PARENT_GROUP");
+ if (parentGroupName && *parentGroupName)
+ {
+ group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
+ group->ParentGroup->Subgroups.push_back(group);
+ }
+ else
+ {
+ group->ParentGroup = 0;
+ }
+ }
+ return group;
+}
diff --git a/Source/CPack/cmCPackGenerator.h b/Source/CPack/cmCPackGenerator.h
new file mode 100644
index 0000000000..ed89b53a84
--- /dev/null
+++ b/Source/CPack/cmCPackGenerator.h
@@ -0,0 +1,330 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackGenerator_h
+#define cmCPackGenerator_h
+
+#include "cmObject.h"
+#include "cmSystemTools.h"
+#include <map>
+#include <vector>
+
+#include "cmCPackComponentGroup.h" // cmCPackComponent and friends
+ // Forward declarations are insufficient since we use them in
+ // std::map data members below...
+
+#define cmCPackTypeMacro(klass, superclass) \
+ cmTypeMacro(klass, superclass); \
+ static cmCPackGenerator* CreateGenerator() { return new klass; } \
+ class cmCPackTypeMacro_UseTrailingSemicolon
+
+#define cmCPackLogger(logType, msg) \
+ do { \
+ cmOStringStream cmCPackLog_msg; \
+ cmCPackLog_msg << msg; \
+ this->Logger->Log(logType, __FILE__, __LINE__,\
+ cmCPackLog_msg.str().c_str());\
+ } while ( 0 )
+
+#ifdef cerr
+# undef cerr
+#endif
+#define cerr no_cerr_use_cmCPack_Log
+
+#ifdef cout
+# undef cout
+#endif
+#define cout no_cout_use_cmCPack_Log
+
+class cmMakefile;
+class cmCPackLog;
+class cmInstalledFile;
+
+/** \class cmCPackGenerator
+ * \brief A superclass of all CPack Generators
+ *
+ */
+class cmCPackGenerator : public cmObject
+{
+public:
+ cmTypeMacro(cmCPackGenerator, cmObject);
+ /**
+ * If verbose then more information is printed out
+ */
+ void SetVerbose(bool val)
+ { this->GeneratorVerbose = val ?
+ cmSystemTools::OUTPUT_MERGE : cmSystemTools::OUTPUT_NONE; }
+
+ /**
+ * Returns true if the generator may work on this system.
+ * Rational:
+ * Some CPack generator may run on some host and may not on others
+ * (with the same system) because some tools are missing. If the tool
+ * is missing then CPack won't activate (in the CPackGeneratorFactory)
+ * this particular generator.
+ */
+ static bool CanGenerate() { return true; }
+
+ /**
+ * Do the actual whole package processing.
+ * Subclass may redefine it but its usually enough
+ * to redefine @ref PackageFiles, because in fact
+ * this method do call:
+ * - PrepareName
+ * - clean-up temp dirs
+ * - InstallProject (with the appropriate method)
+ * - prepare list of files and/or components to be package
+ * - PackageFiles
+ * - Copy produced packages at the expected place
+ * @return 0 if error.
+ */
+ virtual int DoPackage();
+
+ /**
+ * Initialize generator
+ */
+ int Initialize(const std::string& name, cmMakefile* mf);
+
+ /**
+ * Construct generator
+ */
+ cmCPackGenerator();
+ virtual ~cmCPackGenerator();
+
+ //! Set and get the options
+ void SetOption(const std::string& op, const char* value);
+ void SetOptionIfNotSet(const std::string& op, const char* value);
+ const char* GetOption(const std::string& op) const;
+ std::vector<std::string> GetOptions() const;
+ bool IsSet(const std::string& name) const;
+ bool IsOn(const std::string& name) const;
+
+ //! Set the logger
+ void SetLogger(cmCPackLog* log) { this->Logger = log; }
+
+ //! Display verbose information via logger
+ void DisplayVerboseOutput(const char* msg, float progress);
+
+ bool ReadListFile(const char* moduleName);
+
+protected:
+ /**
+ * Prepare common used names by inspecting
+ * several CPACK_xxx var values.
+ */
+ int PrepareNames();
+
+ /**
+ * Install the project using appropriate method.
+ */
+ int InstallProject();
+
+ int CleanTemporaryDirectory();
+
+ cmInstalledFile const* GetInstalledFile(std::string const& name) const;
+
+ virtual const char* GetOutputExtension() { return ".cpack"; }
+ virtual const char* GetOutputPostfix() { return 0; }
+
+ /**
+ * Prepare requested grouping kind from CPACK_xxx vars
+ * CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE
+ * CPACK_COMPONENTS_IGNORE_GROUPS
+ * or
+ * CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP
+ * @return 1 on success 0 on failure.
+ */
+ virtual int PrepareGroupingKind();
+
+ /**
+ * Some CPack generators may prefer to have
+ * CPack install all components belonging to the same
+ * [component] group to be install in the same directory.
+ * The default behavior is to install each component in
+ * a separate directory.
+ * @param[in] componentName the name of the component to be installed
+ * @return the name suffix the generator wants for the specified component
+ * default is "componentName"
+ */
+ virtual std::string GetComponentInstallDirNameSuffix(
+ const std::string& componentName);
+
+ /**
+ * CPack specific generator may mangle CPACK_PACKAGE_FILE_NAME
+ * with CPACK_COMPONENT_xxxx_<NAME>_DISPLAY_NAME if
+ * CPACK_<GEN>_USE_DISPLAY_NAME_IN_FILENAME is ON.
+ * @param[in] initialPackageFileName the initial package name to be mangled
+ * @param[in] groupOrComponentName the name of the group/component
+ * @param[in] isGroupName true if previous name refers to a group,
+ * false otherwise
+ */
+ virtual std::string GetComponentPackageFileName(
+ const std::string& initialPackageFileName,
+ const std::string& groupOrComponentName,
+ bool isGroupName);
+
+ /**
+ * Package the list of files and/or components which
+ * has been prepared by the beginning of DoPackage.
+ * @pre the @ref toplevel has been filled-in
+ * @pre the list of file @ref files has been populated
+ * @pre packageFileNames contains at least 1 entry
+ * @post packageFileNames may have been updated and contains
+ * the list of packages generated by the specific generator.
+ */
+ virtual int PackageFiles();
+ virtual const char* GetInstallPath();
+ virtual const char* GetPackagingInstallPrefix();
+
+ virtual std::string FindTemplate(const char* name);
+ virtual bool ConfigureFile(const char* inName, const char* outName,
+ bool copyOnly = false);
+ virtual bool ConfigureString(const std::string& input, std::string& output);
+ virtual int InitializeInternal();
+
+
+ //! Run install commands if specified
+ virtual int InstallProjectViaInstallCommands(
+ bool setDestDir, const std::string& tempInstallDirectory);
+ virtual int InstallProjectViaInstallScript(
+ bool setDestDir, const std::string& tempInstallDirectory);
+ virtual int InstallProjectViaInstalledDirectories(
+ bool setDestDir, const std::string& tempInstallDirectory);
+ virtual int InstallProjectViaInstallCMakeProjects(
+ bool setDestDir, const std::string& tempInstallDirectory);
+
+ /**
+ * The various level of support of
+ * CPACK_SET_DESTDIR used by the generator.
+ */
+ enum CPackSetDestdirSupport {
+ /* the generator works with or without it */
+ SETDESTDIR_SUPPORTED,
+ /* the generator works best if automatically handled */
+ SETDESTDIR_INTERNALLY_SUPPORTED,
+ /* no official support, use at your own risk */
+ SETDESTDIR_SHOULD_NOT_BE_USED,
+ /* officially NOT supported */
+ SETDESTDIR_UNSUPPORTED
+ };
+
+ /**
+ * Does the CPack generator support CPACK_SET_DESTDIR?
+ * The default legacy value is 'SETDESTDIR_SUPPORTED' generator
+ * have to override it in order change this.
+ * @return CPackSetDestdirSupport
+ */
+ virtual enum CPackSetDestdirSupport SupportsSetDestdir() const;
+
+ /**
+ * Does the CPack generator support absolute path
+ * in INSTALL DESTINATION?
+ * The default legacy value is 'true' generator
+ * have to override it in order change this.
+ * @return true if supported false otherwise
+ */
+ virtual bool SupportsAbsoluteDestination() const;
+
+ /**
+ * Does the CPack generator support component installation?.
+ * Some Generators requires the user to set
+ * CPACK_<GENNAME>_COMPONENT_INSTALL in order to make this
+ * method return true.
+ * @return true if supported, false otherwise
+ */
+ virtual bool SupportsComponentInstallation() const;
+ /**
+ * Does the currently running generator want a component installation.
+ * The generator may support component installation but he may
+ * be requiring monolithic install using CPACK_MONOLITHIC_INSTALL.
+ * @return true if component installation is supported and wanted.
+ */
+ virtual bool WantsComponentInstallation() const;
+ virtual cmCPackInstallationType* GetInstallationType(
+ const std::string& projectName,
+ const std::string& name);
+ virtual cmCPackComponent* GetComponent(const std::string& projectName,
+ const std::string& name);
+ virtual cmCPackComponentGroup* GetComponentGroup(
+ const std::string& projectName,
+ const std::string& name);
+
+ cmSystemTools::OutputOption GeneratorVerbose;
+ std::string Name;
+
+ std::string InstallPath;
+
+ /**
+ * The list of package file names.
+ * At beginning of DoPackage the (generic) generator will populate
+ * the list of desired package file names then it will
+ * call the redefined method PackageFiles which is may
+ * either use this set of names (usually on entry there should be
+ * only a single name) or update the vector with the list
+ * of created package file names.
+ */
+ std::vector<std::string> packageFileNames;
+
+ /**
+ * The directory where all the files to be packaged reside.
+ * If the installer support components there will be one
+ * sub-directory for each component. In those directories
+ * one will find the file belonging to the specified component.
+ */
+ std::string toplevel;
+
+ /**
+ * The complete list of files to be packaged.
+ * This list will be populated by DoPackage before
+ * PackageFiles is called.
+ */
+ std::vector<std::string> files;
+
+ std::map<std::string, cmCPackInstallationType> InstallationTypes;
+ /**
+ * The set of components.
+ * If component installation is supported then this map
+ * contains the component specified in CPACK_COMPONENTS_ALL
+ */
+ std::map<std::string, cmCPackComponent> Components;
+ std::map<std::string, cmCPackComponentGroup> ComponentGroups;
+
+ /**
+ * If components are enabled, this enum represents the different
+ * ways of mapping components to package files.
+ */
+ enum ComponentPackageMethod
+ {
+ /* one package for all components */
+ ONE_PACKAGE,
+ /* one package for each component */
+ ONE_PACKAGE_PER_COMPONENT,
+ /* one package for each group,
+ * with left over components in their own package */
+ ONE_PACKAGE_PER_GROUP,
+ UNKNOWN_COMPONENT_PACKAGE_METHOD
+ };
+
+ /**
+ * The component package method
+ * The default is ONE_PACKAGE_PER_GROUP,
+ * and generators may override the default
+ * before PrepareGroupingKind() is called.
+ */
+ ComponentPackageMethod componentPackageMethod;
+
+ cmCPackLog* Logger;
+private:
+ cmMakefile* MakefileMap;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx
new file mode 100644
index 0000000000..c8737f40b2
--- /dev/null
+++ b/Source/CPack/cmCPackGeneratorFactory.cxx
@@ -0,0 +1,211 @@
+/*============================================================================
+ 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 "cmCPackGeneratorFactory.h"
+
+#include "cmCPackGenerator.h"
+#include "cmCPackTGZGenerator.h"
+#include "cmCPackTXZGenerator.h"
+#include "cmCPackTarBZip2Generator.h"
+#include "cmCPackTarCompressGenerator.h"
+#include "cmCPackZIPGenerator.h"
+#include "cmCPack7zGenerator.h"
+#include "cmCPackSTGZGenerator.h"
+#include "cmCPackNSISGenerator.h"
+#include "IFW/cmCPackIFWGenerator.h"
+
+#ifdef __APPLE__
+# include "cmCPackDragNDropGenerator.h"
+# include "cmCPackBundleGenerator.h"
+# include "cmCPackPackageMakerGenerator.h"
+# include "cmCPackOSXX11Generator.h"
+#endif
+
+#ifdef __CYGWIN__
+# include "cmCPackCygwinBinaryGenerator.h"
+# include "cmCPackCygwinSourceGenerator.h"
+#endif
+
+#if !defined(_WIN32) \
+ && !defined(__QNXNTO__) && !defined(__BEOS__) && !defined(__HAIKU__)
+# include "cmCPackDebGenerator.h"
+# include "cmCPackRPMGenerator.h"
+#endif
+
+#ifdef _WIN32
+# include "WiX/cmCPackWIXGenerator.h"
+#endif
+
+#include "cmCPackLog.h"
+
+#if defined(__BORLANDC__)
+# pragma warn -8008 /* condition is always true */
+#endif
+
+//----------------------------------------------------------------------
+cmCPackGeneratorFactory::cmCPackGeneratorFactory()
+{
+ if (cmCPackTGZGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("TGZ", "Tar GZip compression",
+ cmCPackTGZGenerator::CreateGenerator);
+ }
+ if (cmCPackTXZGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("TXZ", "Tar XZ compression",
+ cmCPackTXZGenerator::CreateGenerator);
+ }
+ if (cmCPackSTGZGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("STGZ", "Self extracting Tar GZip compression",
+ cmCPackSTGZGenerator::CreateGenerator);
+ }
+ if (cmCPackNSISGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("NSIS", "Null Soft Installer",
+ cmCPackNSISGenerator::CreateGenerator);
+ this->RegisterGenerator("NSIS64", "Null Soft Installer (64-bit)",
+ cmCPackNSISGenerator::CreateGenerator64);
+ }
+ if (cmCPackIFWGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("IFW", "Qt Installer Framework",
+ cmCPackIFWGenerator::CreateGenerator);
+ }
+#ifdef __CYGWIN__
+ if (cmCPackCygwinBinaryGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("CygwinBinary", "Cygwin Binary Installer",
+ cmCPackCygwinBinaryGenerator::CreateGenerator);
+ }
+ if (cmCPackCygwinSourceGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("CygwinSource", "Cygwin Source Installer",
+ cmCPackCygwinSourceGenerator::CreateGenerator);
+ }
+#endif
+
+ if (cmCPackZIPGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("ZIP", "ZIP file format",
+ cmCPackZIPGenerator::CreateGenerator);
+ }
+ if (cmCPack7zGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("7Z", "7-Zip file format",
+ cmCPack7zGenerator::CreateGenerator);
+ }
+#ifdef _WIN32
+ if (cmCPackWIXGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("WIX", "MSI file format via WiX tools",
+ cmCPackWIXGenerator::CreateGenerator);
+ }
+#endif
+ if (cmCPackTarBZip2Generator::CanGenerate())
+ {
+ this->RegisterGenerator("TBZ2", "Tar BZip2 compression",
+ cmCPackTarBZip2Generator::CreateGenerator);
+ }
+ if (cmCPackTarCompressGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("TZ", "Tar Compress compression",
+ cmCPackTarCompressGenerator::CreateGenerator);
+ }
+#ifdef __APPLE__
+ if (cmCPackDragNDropGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("DragNDrop", "Mac OSX Drag And Drop",
+ cmCPackDragNDropGenerator::CreateGenerator);
+ }
+ if (cmCPackBundleGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("Bundle", "Mac OSX bundle",
+ cmCPackBundleGenerator::CreateGenerator);
+ }
+ if (cmCPackPackageMakerGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("PackageMaker", "Mac OSX Package Maker installer",
+ cmCPackPackageMakerGenerator::CreateGenerator);
+ }
+ if (cmCPackOSXX11Generator::CanGenerate())
+ {
+ this->RegisterGenerator("OSXX11", "Mac OSX X11 bundle",
+ cmCPackOSXX11Generator::CreateGenerator);
+ }
+#endif
+#if !defined(_WIN32) \
+ && !defined(__QNXNTO__) && !defined(__BEOS__) && !defined(__HAIKU__)
+ if (cmCPackDebGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("DEB", "Debian packages",
+ cmCPackDebGenerator::CreateGenerator);
+ }
+ if (cmCPackRPMGenerator::CanGenerate())
+ {
+ this->RegisterGenerator("RPM", "RPM packages",
+ cmCPackRPMGenerator::CreateGenerator);
+ }
+#endif
+}
+
+//----------------------------------------------------------------------
+cmCPackGeneratorFactory::~cmCPackGeneratorFactory()
+{
+ std::vector<cmCPackGenerator*>::iterator it;
+ for ( it = this->Generators.begin(); it != this->Generators.end(); ++ it )
+ {
+ delete *it;
+ }
+}
+
+//----------------------------------------------------------------------
+cmCPackGenerator* cmCPackGeneratorFactory::NewGenerator(
+ const std::string& name)
+{
+ cmCPackGenerator* gen = this->NewGeneratorInternal(name);
+ if ( !gen )
+ {
+ return 0;
+ }
+ this->Generators.push_back(gen);
+ gen->SetLogger(this->Logger);
+ return gen;
+}
+
+//----------------------------------------------------------------------
+cmCPackGenerator* cmCPackGeneratorFactory::NewGeneratorInternal(
+ const std::string& name)
+{
+ cmCPackGeneratorFactory::t_GeneratorCreatorsMap::iterator it
+ = this->GeneratorCreators.find(name);
+ if ( it == this->GeneratorCreators.end() )
+ {
+ return 0;
+ }
+ return (it->second)();
+}
+
+//----------------------------------------------------------------------
+void cmCPackGeneratorFactory::RegisterGenerator(const std::string& name,
+ const char* generatorDescription,
+ CreateGeneratorCall* createGenerator)
+{
+ if ( !createGenerator )
+ {
+ cmCPack_Log(this->Logger, cmCPackLog::LOG_ERROR,
+ "Cannot register generator" << std::endl);
+ return;
+ }
+ this->GeneratorCreators[name] = createGenerator;
+ this->GeneratorDescriptions[name] = generatorDescription;
+}
diff --git a/Source/CPack/cmCPackGeneratorFactory.h b/Source/CPack/cmCPackGeneratorFactory.h
new file mode 100644
index 0000000000..010777f259
--- /dev/null
+++ b/Source/CPack/cmCPackGeneratorFactory.h
@@ -0,0 +1,59 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackGeneratorFactory_h
+#define cmCPackGeneratorFactory_h
+
+#include "cmObject.h"
+
+class cmCPackLog;
+class cmCPackGenerator;
+
+/** \class cmCPackGeneratorFactory
+ * \brief A container for CPack generators
+ *
+ */
+class cmCPackGeneratorFactory : public cmObject
+{
+public:
+ cmTypeMacro(cmCPackGeneratorFactory, cmObject);
+
+ cmCPackGeneratorFactory();
+ ~cmCPackGeneratorFactory();
+
+ //! Get the generator
+ cmCPackGenerator* NewGenerator(const std::string& name);
+ void DeleteGenerator(cmCPackGenerator* gen);
+
+ typedef cmCPackGenerator* CreateGeneratorCall();
+
+ void RegisterGenerator(const std::string& name,
+ const char* generatorDescription,
+ CreateGeneratorCall* createGenerator);
+
+ void SetLogger(cmCPackLog* logger) { this->Logger = logger; }
+
+ typedef std::map<std::string, std::string> DescriptionsMap;
+ const DescriptionsMap& GetGeneratorsList() const
+ { return this->GeneratorDescriptions; }
+
+private:
+ cmCPackGenerator* NewGeneratorInternal(const std::string& name);
+ std::vector<cmCPackGenerator*> Generators;
+
+ typedef std::map<std::string, CreateGeneratorCall*> t_GeneratorCreatorsMap;
+ t_GeneratorCreatorsMap GeneratorCreators;
+ DescriptionsMap GeneratorDescriptions;
+ cmCPackLog* Logger;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackLog.cxx b/Source/CPack/cmCPackLog.cxx
new file mode 100644
index 0000000000..7befca0e1f
--- /dev/null
+++ b/Source/CPack/cmCPackLog.cxx
@@ -0,0 +1,225 @@
+/*============================================================================
+ 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 "cmCPackLog.h"
+
+#include "cmGeneratedFileStream.h"
+#include "cmSystemTools.h"
+
+//----------------------------------------------------------------------
+cmCPackLog::cmCPackLog()
+{
+ this->Verbose = false;
+ this->Debug = false;
+ this->Quiet = false;
+ this->NewLine = true;
+
+ this->LastTag = cmCPackLog::NOTAG;
+#undef cerr
+#undef cout
+ this->DefaultOutput = &std::cout;
+ this->DefaultError = &std::cerr;
+
+ this->LogOutput = 0;
+ this->LogOutputCleanup = false;
+}
+
+//----------------------------------------------------------------------
+cmCPackLog::~cmCPackLog()
+{
+ this->SetLogOutputStream(0);
+}
+
+//----------------------------------------------------------------------
+void cmCPackLog::SetLogOutputStream(std::ostream* os)
+{
+ if ( this->LogOutputCleanup && this->LogOutput )
+ {
+ delete this->LogOutput;
+ }
+ this->LogOutputCleanup = false;
+ this->LogOutput = os;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackLog::SetLogOutputFile(const char* fname)
+{
+ cmGeneratedFileStream *cg = 0;
+ if ( fname )
+ {
+ cg = new cmGeneratedFileStream(fname);
+ }
+ if ( cg && !*cg )
+ {
+ delete cg;
+ cg = 0;
+ }
+ this->SetLogOutputStream(cg);
+ if ( !cg )
+ {
+ return false;
+ }
+ this->LogOutputCleanup = true;
+ return true;
+}
+
+//----------------------------------------------------------------------
+void cmCPackLog::Log(int tag, const char* file, int line,
+ const char* msg, size_t length)
+{
+ // By default no logging
+ bool display = false;
+
+ // Display file and line number if debug
+ bool useFileAndLine = this->Debug;
+
+ bool output = false;
+ bool debug = false;
+ bool warning = false;
+ bool error = false;
+ bool verbose = false;
+
+ // When writing in file, add list of tags whenever tag changes.
+ std::string tagString;
+ bool needTagString = false;
+ if ( this->LogOutput && this->LastTag != tag )
+ {
+ needTagString = true;
+ }
+
+ if ( tag & LOG_OUTPUT )
+ {
+ output = true;
+ display = true;
+ if ( needTagString )
+ {
+ if ( tagString.size() > 0 ) { tagString += ","; }
+ tagString = "VERBOSE";
+ }
+ }
+ if ( tag & LOG_WARNING )
+ {
+ warning = true;
+ display = true;
+ if ( needTagString )
+ {
+ if ( tagString.size() > 0 ) { tagString += ","; }
+ tagString = "WARNING";
+ }
+ }
+ if ( tag & LOG_ERROR )
+ {
+ error = true;
+ display = true;
+ if ( needTagString )
+ {
+ if ( tagString.size() > 0 ) { tagString += ","; }
+ tagString = "ERROR";
+ }
+ }
+ if ( tag & LOG_DEBUG && this->Debug )
+ {
+ debug = true;
+ display = true;
+ if ( needTagString )
+ {
+ if ( tagString.size() > 0 ) { tagString += ","; }
+ tagString = "DEBUG";
+ }
+ useFileAndLine = true;
+ }
+ if ( tag & LOG_VERBOSE && this->Verbose )
+ {
+ verbose = true;
+ display = true;
+ if ( needTagString )
+ {
+ if ( tagString.size() > 0 ) { tagString += ","; }
+ tagString = "VERBOSE";
+ }
+ }
+ if ( this->Quiet )
+ {
+ display = false;
+ }
+ if ( this->LogOutput )
+ {
+ if ( needTagString )
+ {
+ *this->LogOutput << "[" << file << ":" << line << " "
+ << tagString << "] ";
+ }
+ this->LogOutput->write(msg, length);
+ }
+ this->LastTag = tag;
+ if ( !display )
+ {
+ return;
+ }
+ if ( this->NewLine )
+ {
+ if ( error && !this->ErrorPrefix.empty() )
+ {
+ *this->DefaultError << this->ErrorPrefix;
+ }
+ else if ( warning && !this->WarningPrefix.empty() )
+ {
+ *this->DefaultError << this->WarningPrefix;
+ }
+ else if ( output && !this->OutputPrefix.empty() )
+ {
+ *this->DefaultOutput << this->OutputPrefix;
+ }
+ else if ( verbose && !this->VerbosePrefix.empty() )
+ {
+ *this->DefaultOutput << this->VerbosePrefix;
+ }
+ else if ( debug && !this->DebugPrefix.empty() )
+ {
+ *this->DefaultOutput << this->DebugPrefix;
+ }
+ else if ( !this->Prefix.empty() )
+ {
+ *this->DefaultOutput << this->Prefix;
+ }
+ if ( useFileAndLine )
+ {
+ if ( error || warning )
+ {
+ *this->DefaultError << file << ":" << line << " ";
+ }
+ else
+ {
+ *this->DefaultOutput << file << ":" << line << " ";
+ }
+ }
+ }
+ if ( error || warning )
+ {
+ this->DefaultError->write(msg, length);
+ this->DefaultError->flush();
+ }
+ else
+ {
+ this->DefaultOutput->write(msg, length);
+ this->DefaultOutput->flush();
+ }
+ if ( msg[length-1] == '\n' || length > 2 )
+ {
+ this->NewLine = true;
+ }
+
+ if ( error )
+ {
+ cmSystemTools::SetErrorOccured();
+ }
+}
diff --git a/Source/CPack/cmCPackLog.h b/Source/CPack/cmCPackLog.h
new file mode 100644
index 0000000000..812f1de27b
--- /dev/null
+++ b/Source/CPack/cmCPackLog.h
@@ -0,0 +1,155 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackLog_h
+#define cmCPackLog_h
+
+#include "cmObject.h"
+
+#define cmCPack_Log(ctSelf, logType, msg) \
+ do { \
+ cmOStringStream cmCPackLog_msg; \
+ cmCPackLog_msg << msg; \
+ (ctSelf)->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str());\
+ } while ( 0 )
+
+#ifdef cerr
+# undef cerr
+#endif
+#define cerr no_cerr_use_cmCPack_Log
+
+#ifdef cout
+# undef cout
+#endif
+#define cout no_cout_use_cmCPack_Log
+
+
+/** \class cmCPackLog
+ * \brief A container for CPack generators
+ *
+ */
+class cmCPackLog : public cmObject
+{
+public:
+ cmTypeMacro(cmCPackLog, cmObject);
+
+ cmCPackLog();
+ ~cmCPackLog();
+
+ enum __log_tags {
+ NOTAG = 0,
+ LOG_OUTPUT = 0x1,
+ LOG_VERBOSE = 0x2,
+ LOG_DEBUG = 0x4,
+ LOG_WARNING = 0x8,
+ LOG_ERROR = 0x10
+ };
+
+ //! Various signatures for logging.
+ void Log(const char* file, int line, const char* msg)
+ {
+ this->Log(LOG_OUTPUT, file, line, msg);
+ }
+ void Log(const char* file, int line, const char* msg, size_t length)
+ {
+ this->Log(LOG_OUTPUT, file, line, msg, length);
+ }
+ void Log(int tag, const char* file, int line, const char* msg)
+ {
+ this->Log(tag, file, line, msg, strlen(msg));
+ }
+ void Log(int tag, const char* file, int line, const char* msg,
+ size_t length);
+
+ //! Set Verbose
+ void VerboseOn() { this->SetVerbose(true); }
+ void VerboseOff() { this->SetVerbose(true); }
+ void SetVerbose(bool verb) { this->Verbose = verb; }
+ bool GetVerbose() { return this->Verbose; }
+
+ //! Set Debug
+ void DebugOn() { this->SetDebug(true); }
+ void DebugOff() { this->SetDebug(true); }
+ void SetDebug(bool verb) { this->Debug = verb; }
+ bool GetDebug() { return this->Debug; }
+
+ //! Set Quiet
+ void QuietOn() { this->SetQuiet(true); }
+ void QuietOff() { this->SetQuiet(true); }
+ void SetQuiet(bool verb) { this->Quiet = verb; }
+ bool GetQuiet() { return this->Quiet; }
+
+ //! Set the output stream
+ void SetOutputStream(std::ostream* os) { this->DefaultOutput = os; }
+
+ //! Set the error stream
+ void SetErrorStream(std::ostream* os) { this->DefaultError = os; }
+
+ //! Set the log output stream
+ void SetLogOutputStream(std::ostream* os);
+
+ //! Set the log output file. The cmCPackLog will try to create file. If it
+ // cannot, it will report an error.
+ bool SetLogOutputFile(const char* fname);
+
+ //! Set the various prefixes for the logging. SetPrefix sets the generic
+ // prefix that overwrittes missing ones.
+ void SetPrefix(std::string pfx) { this->Prefix = pfx; }
+ void SetOutputPrefix(std::string pfx) { this->OutputPrefix = pfx; }
+ void SetVerbosePrefix(std::string pfx) { this->VerbosePrefix = pfx; }
+ void SetDebugPrefix(std::string pfx) { this->DebugPrefix = pfx; }
+ void SetWarningPrefix(std::string pfx) { this->WarningPrefix = pfx; }
+ void SetErrorPrefix(std::string pfx) { this->ErrorPrefix = pfx; }
+
+private:
+ bool Verbose;
+ bool Debug;
+ bool Quiet;
+
+ bool NewLine;
+
+ int LastTag;
+
+ std::string Prefix;
+ std::string OutputPrefix;
+ std::string VerbosePrefix;
+ std::string DebugPrefix;
+ std::string WarningPrefix;
+ std::string ErrorPrefix;
+
+ std::ostream *DefaultOutput;
+ std::ostream *DefaultError;
+
+ std::string LogOutputFileName;
+ std::ostream *LogOutput;
+ // Do we need to cleanup log output stream
+ bool LogOutputCleanup;
+};
+
+class cmCPackLogWrite
+{
+public:
+ cmCPackLogWrite(const char* data, size_t length)
+ : Data(data), Length(length) {}
+
+ const char* Data;
+ size_t Length;
+};
+
+inline std::ostream& operator<< (std::ostream& os, const cmCPackLogWrite& c)
+{
+ os.write(c.Data, c.Length);
+ os.flush();
+ return os;
+}
+
+#endif
diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx
new file mode 100644
index 0000000000..a5eee6ba87
--- /dev/null
+++ b/Source/CPack/cmCPackNSISGenerator.cxx
@@ -0,0 +1,1044 @@
+/*============================================================================
+ 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 "cmCPackNSISGenerator.h"
+
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackLog.h"
+#include "cmCPackComponentGroup.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/Directory.hxx>
+#include <cmsys/RegularExpression.hxx>
+
+/* NSIS uses different command line syntax on Windows and others */
+#ifdef _WIN32
+# define NSIS_OPT "/"
+#else
+# define NSIS_OPT "-"
+#endif
+
+//----------------------------------------------------------------------
+cmCPackNSISGenerator::cmCPackNSISGenerator(bool nsis64)
+{
+ Nsis64 = nsis64;
+}
+
+//----------------------------------------------------------------------
+cmCPackNSISGenerator::~cmCPackNSISGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackNSISGenerator::PackageFiles()
+{
+ // TODO: Fix nsis to force out file name
+
+ std::string nsisInFileName = this->FindTemplate("NSIS.template.in");
+ if ( nsisInFileName.size() == 0 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPack error: Could not find NSIS installer template file."
+ << std::endl);
+ return false;
+ }
+ std::string nsisInInstallOptions
+ = this->FindTemplate("NSIS.InstallOptions.ini.in");
+ if ( nsisInInstallOptions.size() == 0 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPack error: Could not find NSIS installer options file."
+ << std::endl);
+ return false;
+ }
+
+ std::string nsisFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ std::string tmpFile = nsisFileName;
+ tmpFile += "/NSISOutput.log";
+ std::string nsisInstallOptions = nsisFileName + "/NSIS.InstallOptions.ini";
+ nsisFileName += "/project.nsi";
+ cmOStringStream str;
+ std::vector<std::string>::const_iterator it;
+ for ( it = files.begin(); it != files.end(); ++ it )
+ {
+ std::string fileN = cmSystemTools::RelativePath(toplevel.c_str(),
+ it->c_str());
+ if (!this->Components.empty())
+ {
+ // Strip off the component part of the path.
+ fileN = fileN.substr(fileN.find('/')+1, std::string::npos);
+ }
+ cmSystemTools::ReplaceString(fileN, "/", "\\");
+ str << " Delete \"$INSTDIR\\" << fileN << "\"" << std::endl;
+ }
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Files: "
+ << str.str() << std::endl);
+ this->SetOptionIfNotSet("CPACK_NSIS_DELETE_FILES", str.str().c_str());
+ std::vector<std::string> dirs;
+ this->GetListOfSubdirectories(toplevel.c_str(), dirs);
+ std::vector<std::string>::const_iterator sit;
+ cmOStringStream dstr;
+ for ( sit = dirs.begin(); sit != dirs.end(); ++ sit )
+ {
+ std::string componentName;
+ std::string fileN = cmSystemTools::RelativePath(toplevel.c_str(),
+ sit->c_str());
+ if ( fileN.empty() )
+ {
+ continue;
+ }
+ if (!Components.empty())
+ {
+ // If this is a component installation, strip off the component
+ // part of the path.
+ std::string::size_type slash = fileN.find('/');
+ if (slash != std::string::npos)
+ {
+ // If this is a component installation, determine which component it
+ // is.
+ componentName = fileN.substr(0, slash);
+
+ // Strip off the component part of the path.
+ fileN = fileN.substr(slash+1, std::string::npos);
+ }
+ }
+ cmSystemTools::ReplaceString(fileN, "/", "\\");
+ dstr << " RMDir \"$INSTDIR\\" << fileN << "\"" << std::endl;
+ if (!componentName.empty())
+ {
+ this->Components[componentName].Directories.push_back(fileN);
+ }
+ }
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Dirs: "
+ << dstr.str() << std::endl);
+ this->SetOptionIfNotSet("CPACK_NSIS_DELETE_DIRECTORIES",
+ dstr.str().c_str());
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << nsisInFileName
+ << " to " << nsisFileName << std::endl);
+ if(this->IsSet("CPACK_NSIS_MUI_ICON")
+ || this->IsSet("CPACK_NSIS_MUI_UNIICON"))
+ {
+ std::string installerIconCode;
+ if(this->IsSet("CPACK_NSIS_MUI_ICON"))
+ {
+ installerIconCode += "!define MUI_ICON \"";
+ installerIconCode += this->GetOption("CPACK_NSIS_MUI_ICON");
+ installerIconCode += "\"\n";
+ }
+ if(this->IsSet("CPACK_NSIS_MUI_UNIICON"))
+ {
+ installerIconCode += "!define MUI_UNICON \"";
+ installerIconCode += this->GetOption("CPACK_NSIS_MUI_UNIICON");
+ installerIconCode += "\"\n";
+ }
+ this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_ICON_CODE",
+ installerIconCode.c_str());
+ }
+ if(this->IsSet("CPACK_PACKAGE_ICON"))
+ {
+ std::string installerIconCode = "!define MUI_HEADERIMAGE_BITMAP \"";
+ installerIconCode += this->GetOption("CPACK_PACKAGE_ICON");
+ installerIconCode += "\"\n";
+ this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_ICON_CODE",
+ installerIconCode.c_str());
+ }
+
+ if(this->IsSet("CPACK_NSIS_MUI_FINISHPAGE_RUN"))
+ {
+ std::string installerRunCode = "!define MUI_FINISHPAGE_RUN \"$INSTDIR\\";
+ installerRunCode += this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY");
+ installerRunCode += "\\";
+ installerRunCode += this->GetOption("CPACK_NSIS_MUI_FINISHPAGE_RUN");
+ installerRunCode += "\"\n";
+ this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE",
+ installerRunCode.c_str());
+ }
+
+ // Setup all of the component sections
+ if (this->Components.empty())
+ {
+ this->SetOptionIfNotSet("CPACK_NSIS_INSTALLATION_TYPES", "");
+ this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC", "");
+ this->SetOptionIfNotSet("CPACK_NSIS_PAGE_COMPONENTS", "");
+ this->SetOptionIfNotSet("CPACK_NSIS_FULL_INSTALL",
+ "File /r \"${INST_DIR}\\*.*\"");
+ this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTIONS", "");
+ this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTION_LIST", "");
+ this->SetOptionIfNotSet("CPACK_NSIS_SECTION_SELECTED_VARS", "");
+ }
+ else
+ {
+ std::string componentCode;
+ std::string sectionList;
+ std::string selectedVarsList;
+ std::string componentDescriptions;
+ std::string groupDescriptions;
+ std::string installTypesCode;
+ std::string defines;
+ cmOStringStream macrosOut;
+ bool anyDownloadedComponents = false;
+
+ // Create installation types. The order is significant, so we first fill
+ // in a vector based on the indices, and print them in that order.
+ std::vector<cmCPackInstallationType *>
+ installTypes(this->InstallationTypes.size());
+ std::map<std::string, cmCPackInstallationType>::iterator installTypeIt;
+ for (installTypeIt = this->InstallationTypes.begin();
+ installTypeIt != this->InstallationTypes.end();
+ ++installTypeIt)
+ {
+ installTypes[installTypeIt->second.Index-1] = &installTypeIt->second;
+ }
+ std::vector<cmCPackInstallationType *>::iterator installTypeIt2;
+ for (installTypeIt2 = installTypes.begin();
+ installTypeIt2 != installTypes.end();
+ ++installTypeIt2)
+ {
+ installTypesCode += "InstType \"";
+ installTypesCode += (*installTypeIt2)->DisplayName;
+ installTypesCode += "\"\n";
+ }
+
+ // Create installation groups first
+ std::map<std::string, cmCPackComponentGroup>::iterator groupIt;
+ for (groupIt = this->ComponentGroups.begin();
+ groupIt != this->ComponentGroups.end();
+ ++groupIt)
+ {
+ if (groupIt->second.ParentGroup == 0)
+ {
+ componentCode +=
+ this->CreateComponentGroupDescription(&groupIt->second, macrosOut);
+ }
+
+ // Add the group description, if any.
+ if (!groupIt->second.Description.empty())
+ {
+ groupDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${"
+ + groupIt->first + "} \""
+ + this->TranslateNewlines(groupIt->second.Description) + "\"\n";
+ }
+ }
+
+ // Create the remaining components, which aren't associated with groups.
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt = this->Components.begin();
+ compIt != this->Components.end();
+ ++compIt)
+ {
+ if (compIt->second.Files.empty())
+ {
+ // NSIS cannot cope with components that have no files.
+ continue;
+ }
+
+ anyDownloadedComponents =
+ anyDownloadedComponents || compIt->second.IsDownloaded;
+
+ if (!compIt->second.Group)
+ {
+ componentCode
+ += this->CreateComponentDescription(&compIt->second, macrosOut);
+ }
+
+ // Add this component to the various section lists.
+ sectionList += " !insertmacro \"${MacroName}\" \"";
+ sectionList += compIt->first;
+ sectionList += "\"\n";
+ selectedVarsList += "Var " + compIt->first + "_selected\n";
+ selectedVarsList += "Var " + compIt->first + "_was_installed\n";
+
+ // Add the component description, if any.
+ if (!compIt->second.Description.empty())
+ {
+ componentDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${"
+ + compIt->first + "} \""
+ + this->TranslateNewlines(compIt->second.Description) + "\"\n";
+ }
+ }
+
+ componentCode += macrosOut.str();
+
+ if (componentDescriptions.empty() && groupDescriptions.empty())
+ {
+ // Turn off the "Description" box
+ this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC",
+ "!define MUI_COMPONENTSPAGE_NODESC");
+ }
+ else
+ {
+ componentDescriptions =
+ "!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN\n"
+ + componentDescriptions
+ + groupDescriptions
+ + "!insertmacro MUI_FUNCTION_DESCRIPTION_END\n";
+ this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC",
+ componentDescriptions.c_str());
+ }
+
+ if (anyDownloadedComponents)
+ {
+ defines += "!define CPACK_USES_DOWNLOAD\n";
+ if (cmSystemTools::IsOn(this->GetOption("CPACK_ADD_REMOVE")))
+ {
+ defines += "!define CPACK_NSIS_ADD_REMOVE\n";
+ }
+ }
+
+ this->SetOptionIfNotSet("CPACK_NSIS_INSTALLATION_TYPES",
+ installTypesCode.c_str());
+ this->SetOptionIfNotSet("CPACK_NSIS_PAGE_COMPONENTS",
+ "!insertmacro MUI_PAGE_COMPONENTS");
+ this->SetOptionIfNotSet("CPACK_NSIS_FULL_INSTALL", "");
+ this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTIONS",
+ componentCode.c_str());
+ this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTION_LIST",
+ sectionList.c_str());
+ this->SetOptionIfNotSet("CPACK_NSIS_SECTION_SELECTED_VARS",
+ selectedVarsList.c_str());
+ this->SetOption("CPACK_NSIS_DEFINES", defines.c_str());
+ }
+
+ this->ConfigureFile(nsisInInstallOptions.c_str(),
+ nsisInstallOptions.c_str());
+ this->ConfigureFile(nsisInFileName.c_str(), nsisFileName.c_str());
+ std::string nsisCmd = "\"";
+ nsisCmd += this->GetOption("CPACK_INSTALLER_PROGRAM");
+ nsisCmd += "\" \"" + nsisFileName + "\"";
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << nsisCmd
+ << std::endl);
+ std::string output;
+ int retVal = 1;
+ bool res = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output,
+ &retVal, 0, this->GeneratorVerbose, 0);
+ if ( !res || retVal )
+ {
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << nsisCmd << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running NSIS command: "
+ << nsisCmd << std::endl
+ << "Please check " << tmpFile << " for errors" << std::endl);
+ return 0;
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackNSISGenerator::InitializeInternal()
+{
+ if ( cmSystemTools::IsOn(this->GetOption(
+ "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_WARNING,
+ "NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY set. "
+ "This option will be reset to 0 (for this generator only)."
+ << std::endl);
+ this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", 0);
+ }
+
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackNSISGenerator::Initialize()"
+ << std::endl);
+ std::vector<std::string> path;
+ std::string nsisPath;
+ bool gotRegValue = false;
+
+#ifdef _WIN32
+ if (Nsis64)
+ {
+ if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath,
+ cmsys::SystemTools::KeyWOW64_64) )
+ {
+ gotRegValue = true;
+ }
+ if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath,
+ cmsys::SystemTools::KeyWOW64_64) )
+ {
+ gotRegValue = true;
+ }
+ }
+ if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath,
+ cmsys::SystemTools::KeyWOW64_32) )
+ {
+ gotRegValue = true;
+ }
+ if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath) )
+ {
+ gotRegValue = true;
+ }
+ if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath,
+ cmsys::SystemTools::KeyWOW64_32) )
+ {
+ gotRegValue = true;
+ }
+ if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath) )
+ {
+ gotRegValue = true;
+ }
+
+ if (gotRegValue)
+ {
+ path.push_back(nsisPath);
+ }
+#endif
+
+ nsisPath = cmSystemTools::FindProgram("makensis", path, false);
+
+ if ( nsisPath.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find NSIS compiler makensis: likely it is not installed, "
+ "or not in your PATH"
+ << std::endl);
+
+ if (!gotRegValue)
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Could not read NSIS registry value. This is usually caused by "
+ "NSIS not being installed. Please install NSIS from "
+ "http://nsis.sourceforge.net"
+ << std::endl);
+ }
+
+ return 0;
+ }
+
+ std::string nsisCmd = "\"" + nsisPath + "\" " NSIS_OPT "VERSION";
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Test NSIS version: "
+ << nsisCmd << std::endl);
+ std::string output;
+ int retVal = 1;
+ bool resS = cmSystemTools::RunSingleCommand(nsisCmd.c_str(),
+ &output, &retVal, 0, this->GeneratorVerbose, 0);
+ cmsys::RegularExpression versionRex("v([0-9]+.[0-9]+)");
+ cmsys::RegularExpression versionRexCVS("v(.*)\\.cvs");
+ if ( !resS || retVal ||
+ (!versionRex.find(output) && !versionRexCVS.find(output))
+ )
+ {
+ const char* topDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ std::string tmpFile = topDir ? topDir : ".";
+ tmpFile += "/NSISOutput.log";
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << nsisCmd << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem checking NSIS version with command: "
+ << nsisCmd << std::endl
+ << "Please check " << tmpFile << " for errors" << std::endl);
+ return 0;
+ }
+ if ( versionRex.find(output))
+ {
+ double nsisVersion = atof(versionRex.match(1).c_str());
+ double minNSISVersion = 2.09;
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "NSIS Version: "
+ << nsisVersion << std::endl);
+ if ( nsisVersion < minNSISVersion )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPack requires NSIS Version 2.09 or greater. "
+ "NSIS found on the system was: "
+ << nsisVersion << std::endl);
+ return 0;
+ }
+ }
+ if ( versionRexCVS.find(output))
+ {
+ // No version check for NSIS cvs build
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "NSIS Version: CVS "
+ << versionRexCVS.match(1) << std::endl);
+ }
+ this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", nsisPath.c_str());
+ this->SetOptionIfNotSet("CPACK_NSIS_EXECUTABLES_DIRECTORY", "bin");
+ const char* cpackPackageExecutables
+ = this->GetOption("CPACK_PACKAGE_EXECUTABLES");
+ const char* cpackPackageDeskTopLinks
+ = this->GetOption("CPACK_CREATE_DESKTOP_LINKS");
+ const char* cpackNsisExecutablesDirectory
+ = this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY");
+ std::vector<std::string> cpackPackageDesktopLinksVector;
+ if(cpackPackageDeskTopLinks)
+ {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: "
+ << cpackPackageDeskTopLinks << std::endl);
+
+ cmSystemTools::
+ ExpandListArgument(cpackPackageDeskTopLinks,
+ cpackPackageDesktopLinksVector);
+ for(std::vector<std::string>::iterator i =
+ cpackPackageDesktopLinksVector.begin(); i !=
+ cpackPackageDesktopLinksVector.end(); ++i)
+ {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: "
+ << *i << std::endl);
+ }
+ }
+ else
+ {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: "
+ << "not set" << std::endl);
+ }
+
+ cmOStringStream str;
+ cmOStringStream deleteStr;
+
+ if ( cpackPackageExecutables )
+ {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackPackageExecutables: "
+ << cpackPackageExecutables << "." << std::endl);
+ std::vector<std::string> cpackPackageExecutablesVector;
+ cmSystemTools::ExpandListArgument(cpackPackageExecutables,
+ cpackPackageExecutablesVector);
+ if ( cpackPackageExecutablesVector.size() % 2 != 0 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and "
+ "<icon name>." << std::endl);
+ return 0;
+ }
+ std::vector<std::string>::iterator it;
+ for ( it = cpackPackageExecutablesVector.begin();
+ it != cpackPackageExecutablesVector.end();
+ ++it )
+ {
+ std::string execName = *it;
+ ++ it;
+ std::string linkName = *it;
+ str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\"
+ << linkName << ".lnk\" \"$INSTDIR\\"
+ << cpackNsisExecutablesDirectory << "\\" << execName << ".exe\""
+ << std::endl;
+ deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
+ << ".lnk\"" << std::endl;
+ // see if CPACK_CREATE_DESKTOP_LINK_ExeName is on
+ // if so add a desktop link
+ if(cpackPackageDesktopLinksVector.size() &&
+ std::find(cpackPackageDesktopLinksVector.begin(),
+ cpackPackageDesktopLinksVector.end(),
+ execName)
+ != cpackPackageDesktopLinksVector.end())
+ {
+ str << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
+ str << " CreateShortCut \"$DESKTOP\\"
+ << linkName << ".lnk\" \"$INSTDIR\\"
+ << cpackNsisExecutablesDirectory << "\\" << execName << ".exe\""
+ << std::endl;
+ deleteStr << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
+ deleteStr << " Delete \"$DESKTOP\\" << linkName
+ << ".lnk\"" << std::endl;
+ }
+ }
+ }
+
+ this->CreateMenuLinks(str, deleteStr);
+ this->SetOptionIfNotSet("CPACK_NSIS_CREATE_ICONS", str.str().c_str());
+ this->SetOptionIfNotSet("CPACK_NSIS_DELETE_ICONS",
+ deleteStr.str().c_str());
+
+ this->SetOptionIfNotSet("CPACK_NSIS_COMPRESSOR", "lzma");
+
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+void cmCPackNSISGenerator::CreateMenuLinks( cmOStringStream& str,
+ cmOStringStream& deleteStr)
+{
+ const char* cpackMenuLinks
+ = this->GetOption("CPACK_NSIS_MENU_LINKS");
+ if(!cpackMenuLinks)
+ {
+ return;
+ }
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackMenuLinks: "
+ << cpackMenuLinks << "." << std::endl);
+ std::vector<std::string> cpackMenuLinksVector;
+ cmSystemTools::ExpandListArgument(cpackMenuLinks,
+ cpackMenuLinksVector);
+ if ( cpackMenuLinksVector.size() % 2 != 0 )
+ {
+ cmCPackLogger(
+ cmCPackLog::LOG_ERROR,
+ "CPACK_NSIS_MENU_LINKS should contain pairs of <shortcut target> and "
+ "<shortcut label>." << std::endl);
+ return;
+ }
+
+ static cmsys::RegularExpression
+ urlRegex("^(mailto:|(ftps?|https?|news)://).*$");
+
+ std::vector<std::string>::iterator it;
+ for ( it = cpackMenuLinksVector.begin();
+ it != cpackMenuLinksVector.end();
+ ++it )
+ {
+ std::string sourceName = *it;
+ const bool url = urlRegex.find(sourceName);
+
+ // Convert / to \ in filenames, but not in urls:
+ //
+ if(!url)
+ {
+ cmSystemTools::ReplaceString(sourceName, "/", "\\");
+ }
+
+ ++ it;
+ std::string linkName = *it;
+ if(!url)
+ {
+ str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\"
+ << linkName << ".lnk\" \"$INSTDIR\\" << sourceName << "\""
+ << std::endl;
+ deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
+ << ".lnk\"" << std::endl;
+ }
+ else
+ {
+ str << " WriteINIStr \"$SMPROGRAMS\\$STARTMENU_FOLDER\\"
+ << linkName << ".url\" \"InternetShortcut\" \"URL\" \""
+ << sourceName << "\""
+ << std::endl;
+ deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
+ << ".url\"" << std::endl;
+ }
+ // see if CPACK_CREATE_DESKTOP_LINK_ExeName is on
+ // if so add a desktop link
+ std::string desktop = "CPACK_CREATE_DESKTOP_LINK_";
+ desktop += linkName;
+ if(this->IsSet(desktop))
+ {
+ str << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
+ str << " CreateShortCut \"$DESKTOP\\"
+ << linkName << ".lnk\" \"$INSTDIR\\" << sourceName << "\""
+ << std::endl;
+ deleteStr << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
+ deleteStr << " Delete \"$DESKTOP\\" << linkName
+ << ".lnk\"" << std::endl;
+ }
+ }
+}
+
+//----------------------------------------------------------------------
+bool cmCPackNSISGenerator::GetListOfSubdirectories(const char* topdir,
+ std::vector<std::string>& dirs)
+{
+ cmsys::Directory dir;
+ dir.Load(topdir);
+ size_t fileNum;
+ for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum)
+ {
+ if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") &&
+ strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".."))
+ {
+ cmsys_stl::string fullPath = topdir;
+ fullPath += "/";
+ fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
+ if(cmsys::SystemTools::FileIsDirectory(fullPath.c_str()) &&
+ !cmsys::SystemTools::FileIsSymlink(fullPath.c_str()))
+ {
+ if (!this->GetListOfSubdirectories(fullPath.c_str(), dirs))
+ {
+ return false;
+ }
+ }
+ }
+ }
+ dirs.push_back(topdir);
+ return true;
+}
+
+//----------------------------------------------------------------------
+enum cmCPackGenerator::CPackSetDestdirSupport
+cmCPackNSISGenerator::SupportsSetDestdir() const
+{
+ return cmCPackGenerator::SETDESTDIR_SHOULD_NOT_BE_USED;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackNSISGenerator::SupportsAbsoluteDestination() const
+{
+ return false;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackNSISGenerator::SupportsComponentInstallation() const
+{
+ return true;
+}
+
+//----------------------------------------------------------------------
+std::string
+cmCPackNSISGenerator::
+CreateComponentDescription(cmCPackComponent *component,
+ cmOStringStream& macrosOut)
+{
+ // Basic description of the component
+ std::string componentCode = "Section ";
+ if (component->IsDisabledByDefault)
+ {
+ componentCode += "/o ";
+ }
+ componentCode += "\"";
+ if (component->IsHidden)
+ {
+ componentCode += "-";
+ }
+ componentCode += component->DisplayName + "\" " + component->Name + "\n";
+ if (component->IsRequired)
+ {
+ componentCode += " SectionIn RO\n";
+ }
+ else if (!component->InstallationTypes.empty())
+ {
+ cmOStringStream out;
+ std::vector<cmCPackInstallationType *>::iterator installTypeIter;
+ for (installTypeIter = component->InstallationTypes.begin();
+ installTypeIter != component->InstallationTypes.end();
+ ++installTypeIter)
+ {
+ out << " " << (*installTypeIter)->Index;
+ }
+ componentCode += " SectionIn" + out.str() + "\n";
+ }
+ componentCode += " SetOutPath \"$INSTDIR\"\n";
+
+ // Create the actual installation commands
+ if (component->IsDownloaded)
+ {
+ if (component->ArchiveFile.empty())
+ {
+ // Compute the name of the archive.
+ std::string packagesDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ packagesDir += ".dummy";
+ cmOStringStream out;
+ out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir)
+ << "-" << component->Name << ".zip";
+ component->ArchiveFile = out.str();
+ }
+
+ // Create the directory for the upload area
+ const char* userUploadDirectory =
+ this->GetOption("CPACK_UPLOAD_DIRECTORY");
+ std::string uploadDirectory;
+ if (userUploadDirectory && *userUploadDirectory)
+ {
+ uploadDirectory = userUploadDirectory;
+ }
+ else
+ {
+ uploadDirectory= this->GetOption("CPACK_PACKAGE_DIRECTORY");
+ uploadDirectory += "/CPackUploads";
+ }
+ if(!cmSystemTools::FileExists(uploadDirectory.c_str()))
+ {
+ if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Unable to create NSIS upload directory " << uploadDirectory
+ << std::endl);
+ return "";
+ }
+ }
+
+ // Remove the old archive, if one exists
+ std::string archiveFile = uploadDirectory + '/' + component->ArchiveFile;
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Building downloaded component archive: "
+ << archiveFile << std::endl);
+ if (cmSystemTools::FileExists(archiveFile.c_str(), true))
+ {
+ if (!cmSystemTools::RemoveFile(archiveFile.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Unable to remove archive file " << archiveFile
+ << std::endl);
+ return "";
+ }
+ }
+
+ // Find a ZIP program
+ if (!this->IsSet("ZIP_EXECUTABLE"))
+ {
+ this->ReadListFile("CPackZIP.cmake");
+
+ if (!this->IsSet("ZIP_EXECUTABLE"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Unable to find ZIP program"
+ << std::endl);
+ return "";
+ }
+ }
+
+ // The directory where this component's files reside
+ std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ dirName += '/';
+ dirName += component->Name;
+ dirName += '/';
+
+ // Build the list of files to go into this archive, and determine the
+ // size of the installed component.
+ std::string zipListFileName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ zipListFileName += "/winZip.filelist";
+ bool needQuotesInFile
+ = cmSystemTools::IsOn(this->GetOption("CPACK_ZIP_NEED_QUOTES"));
+ unsigned long totalSize = 0;
+ { // the scope is needed for cmGeneratedFileStream
+ cmGeneratedFileStream out(zipListFileName.c_str());
+ std::vector<std::string>::iterator fileIt;
+ for (fileIt = component->Files.begin();
+ fileIt != component->Files.end();
+ ++fileIt)
+ {
+ if ( needQuotesInFile )
+ {
+ out << "\"";
+ }
+ out << *fileIt;
+ if ( needQuotesInFile )
+ {
+ out << "\"";
+ }
+ out << std::endl;
+
+ totalSize += cmSystemTools::FileLength((dirName + *fileIt).c_str());
+ }
+ }
+
+ // Build the archive in the upload area
+ std::string cmd = this->GetOption("CPACK_ZIP_COMMAND");
+ cmsys::SystemTools::ReplaceString(cmd, "<ARCHIVE>", archiveFile.c_str());
+ cmsys::SystemTools::ReplaceString(cmd, "<FILELIST>",
+ zipListFileName.c_str());
+ std::string output;
+ int retVal = -1;
+ int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &retVal,
+ dirName.c_str(),
+ cmSystemTools::OUTPUT_NONE, 0);
+ if ( !res || retVal )
+ {
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/CompressZip.log";
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << cmd << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running zip command: "
+ << cmd << std::endl
+ << "Please check " << tmpFile << " for errors" << std::endl);
+ return "";
+ }
+
+ // Create the NSIS code to download this file on-the-fly.
+ unsigned long totalSizeInKbytes = (totalSize + 512) / 1024;
+ if (totalSizeInKbytes == 0)
+ {
+ totalSizeInKbytes = 1;
+ }
+ cmOStringStream out;
+ out << " AddSize " << totalSizeInKbytes << "\n"
+ << " Push \"" << component->ArchiveFile << "\"\n"
+ << " Call DownloadFile\n"
+ << " ZipDLL::extractall \"$INSTDIR\\"
+ << component->ArchiveFile << "\" \"$INSTDIR\"\n"
+ << " Pop $2 ; error message\n"
+ " StrCmp $2 \"success\" +2 0\n"
+ " MessageBox MB_OK \"Failed to unzip $2\"\n"
+ " Delete $INSTDIR\\$0\n";
+ componentCode += out.str();
+ }
+ else
+ {
+ componentCode += " File /r \"${INST_DIR}\\" +
+ component->Name + "\\*.*\"\n";
+ }
+ componentCode += "SectionEnd\n";
+
+ // Macro used to remove the component
+ macrosOut << "!macro Remove_${" << component->Name << "}\n";
+ macrosOut << " IntCmp $" << component->Name << "_was_installed 0 noremove_"
+ << component->Name << "\n";
+ std::vector<std::string>::iterator pathIt;
+ std::string path;
+ for (pathIt = component->Files.begin();
+ pathIt != component->Files.end();
+ ++pathIt)
+ {
+ path = *pathIt;
+ cmSystemTools::ReplaceString(path, "/", "\\");
+ macrosOut << " Delete \"$INSTDIR\\"
+ << path
+ << "\"\n";
+ }
+ for (pathIt = component->Directories.begin();
+ pathIt != component->Directories.end();
+ ++pathIt)
+ {
+ path = *pathIt;
+ cmSystemTools::ReplaceString(path, "/", "\\");
+ macrosOut << " RMDir \"$INSTDIR\\"
+ << path
+ << "\"\n";
+ }
+ macrosOut << " noremove_" << component->Name << ":\n";
+ macrosOut << "!macroend\n";
+
+ // Macro used to select each of the components that this component
+ // depends on.
+ std::set<cmCPackComponent *> visited;
+ macrosOut << "!macro Select_" << component->Name << "_depends\n";
+ macrosOut << CreateSelectionDependenciesDescription(component, visited);
+ macrosOut << "!macroend\n";
+
+ // Macro used to deselect each of the components that depend on this
+ // component.
+ visited.clear();
+ macrosOut << "!macro Deselect_required_by_" << component->Name << "\n";
+ macrosOut << CreateDeselectionDependenciesDescription(component, visited);
+ macrosOut << "!macroend\n";
+ return componentCode;
+}
+
+//----------------------------------------------------------------------
+std::string cmCPackNSISGenerator::CreateSelectionDependenciesDescription
+ (cmCPackComponent *component,
+ std::set<cmCPackComponent *>& visited)
+{
+ // Don't visit a component twice
+ if (visited.count(component))
+ {
+ return std::string();
+ }
+ visited.insert(component);
+
+ cmOStringStream out;
+ std::vector<cmCPackComponent *>::iterator dependIt;
+ for (dependIt = component->Dependencies.begin();
+ dependIt != component->Dependencies.end();
+ ++dependIt)
+ {
+ // Write NSIS code to select this dependency
+ out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n";
+ out << " IntOp $0 $0 | ${SF_SELECTED}\n";
+ out << " SectionSetFlags ${" << (*dependIt)->Name << "} $0\n";
+ out << " IntOp $" << (*dependIt)->Name
+ << "_selected 0 + ${SF_SELECTED}\n";
+ // Recurse
+ out << CreateSelectionDependenciesDescription(*dependIt, visited).c_str();
+ }
+
+ return out.str();
+}
+
+
+//----------------------------------------------------------------------
+std::string cmCPackNSISGenerator::CreateDeselectionDependenciesDescription
+ (cmCPackComponent *component,
+ std::set<cmCPackComponent *>& visited)
+{
+ // Don't visit a component twice
+ if (visited.count(component))
+ {
+ return std::string();
+ }
+ visited.insert(component);
+
+ cmOStringStream out;
+ std::vector<cmCPackComponent *>::iterator dependIt;
+ for (dependIt = component->ReverseDependencies.begin();
+ dependIt != component->ReverseDependencies.end();
+ ++dependIt)
+ {
+ // Write NSIS code to deselect this dependency
+ out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n";
+ out << " IntOp $1 ${SF_SELECTED} ~\n";
+ out << " IntOp $0 $0 & $1\n";
+ out << " SectionSetFlags ${" << (*dependIt)->Name << "} $0\n";
+ out << " IntOp $" << (*dependIt)->Name << "_selected 0 + 0\n";
+
+ // Recurse
+ out <<
+ CreateDeselectionDependenciesDescription(*dependIt, visited).c_str();
+ }
+
+ return out.str();
+}
+
+//----------------------------------------------------------------------
+std::string
+cmCPackNSISGenerator::
+CreateComponentGroupDescription(cmCPackComponentGroup *group,
+ cmOStringStream& macrosOut)
+{
+ if (group->Components.empty() && group->Subgroups.empty())
+ {
+ // Silently skip empty groups. NSIS doesn't support them.
+ return std::string();
+ }
+
+ std::string code = "SectionGroup ";
+ if (group->IsExpandedByDefault)
+ {
+ code += "/e ";
+ }
+ if (group->IsBold)
+ {
+ code += "\"!" + group->DisplayName + "\" " + group->Name + "\n";
+ }
+ else
+ {
+ code += "\"" + group->DisplayName + "\" " + group->Name + "\n";
+ }
+
+ std::vector<cmCPackComponentGroup*>::iterator groupIt;
+ for (groupIt = group->Subgroups.begin(); groupIt != group->Subgroups.end();
+ ++groupIt)
+ {
+ code += this->CreateComponentGroupDescription(*groupIt, macrosOut);
+ }
+
+ std::vector<cmCPackComponent*>::iterator comp;
+ for (comp = group->Components.begin();
+ comp != group->Components.end();
+ ++comp)
+ {
+ if ((*comp)->Files.empty())
+ {
+ continue;
+ }
+
+ code += this->CreateComponentDescription(*comp, macrosOut);
+ }
+ code += "SectionGroupEnd\n";
+ return code;
+}
+
+std::string cmCPackNSISGenerator::TranslateNewlines(std::string str)
+{
+ cmSystemTools::ReplaceString(str, "\n", "$\\r$\\n");
+ return str;
+}
diff --git a/Source/CPack/cmCPackNSISGenerator.h b/Source/CPack/cmCPackNSISGenerator.h
new file mode 100644
index 0000000000..e46fbdab7b
--- /dev/null
+++ b/Source/CPack/cmCPackNSISGenerator.h
@@ -0,0 +1,87 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackNSISGenerator_h
+#define cmCPackNSISGenerator_h
+
+
+#include "cmCPackGenerator.h"
+#include <set>
+
+/** \class cmCPackNSISGenerator
+ * \brief A generator for NSIS files
+ *
+ * http://people.freebsd.org/~kientzle/libarchive/
+ */
+class cmCPackNSISGenerator : public cmCPackGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackNSISGenerator, cmCPackGenerator);
+
+ static cmCPackGenerator* CreateGenerator64()
+ { return new cmCPackNSISGenerator(true); }
+
+ /**
+ * Construct generator
+ */
+ cmCPackNSISGenerator(bool nsis64 = false);
+ virtual ~cmCPackNSISGenerator();
+
+protected:
+ virtual int InitializeInternal();
+ void CreateMenuLinks( cmOStringStream& str,
+ cmOStringStream& deleteStr);
+ int PackageFiles();
+ virtual const char* GetOutputExtension() { return ".exe"; }
+ virtual const char* GetOutputPostfix() { return "win32"; }
+
+ bool GetListOfSubdirectories(const char* dir,
+ std::vector<std::string>& dirs);
+
+ enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const;
+ virtual bool SupportsAbsoluteDestination() const;
+ virtual bool SupportsComponentInstallation() const;
+
+ /// Produce a string that contains the NSIS code to describe a
+ /// particular component. Any added macros will be emitted via
+ /// macrosOut.
+ std::string
+ CreateComponentDescription(cmCPackComponent *component,
+ cmOStringStream& macrosOut);
+
+ /// Produce NSIS code that selects all of the components that this component
+ /// depends on, recursively.
+ std::string CreateSelectionDependenciesDescription
+ (cmCPackComponent *component,
+ std::set<cmCPackComponent *>& visited);
+
+ /// Produce NSIS code that de-selects all of the components that are
+ /// dependent on this component, recursively.
+ std::string CreateDeselectionDependenciesDescription
+ (cmCPackComponent *component,
+ std::set<cmCPackComponent *>& visited);
+
+ /// Produce a string that contains the NSIS code to describe a
+ /// particular component group, including its components. Any
+ /// added macros will be emitted via macrosOut.
+ std::string
+ CreateComponentGroupDescription(cmCPackComponentGroup *group,
+ cmOStringStream& macrosOut);
+
+ /// Translations any newlines found in the string into \\r\\n, so that the
+ /// resulting string can be used within NSIS.
+ static std::string TranslateNewlines(std::string str);
+
+ bool Nsis64;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx
new file mode 100644
index 0000000000..28c7f1dc07
--- /dev/null
+++ b/Source/CPack/cmCPackOSXX11Generator.cxx
@@ -0,0 +1,311 @@
+/*============================================================================
+ 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 "cmCPackOSXX11Generator.h"
+
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackLog.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Glob.hxx>
+#include <sys/stat.h>
+
+//----------------------------------------------------------------------
+cmCPackOSXX11Generator::cmCPackOSXX11Generator()
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackOSXX11Generator::~cmCPackOSXX11Generator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackOSXX11Generator::PackageFiles()
+{
+ // TODO: Use toplevel ?
+ // It is used! Is this an obsolete comment?
+
+ const char* cpackPackageExecutables
+ = this->GetOption("CPACK_PACKAGE_EXECUTABLES");
+ if ( cpackPackageExecutables )
+ {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackPackageExecutables: "
+ << cpackPackageExecutables << "." << std::endl);
+ cmOStringStream str;
+ cmOStringStream deleteStr;
+ std::vector<std::string> cpackPackageExecutablesVector;
+ cmSystemTools::ExpandListArgument(cpackPackageExecutables,
+ cpackPackageExecutablesVector);
+ if ( cpackPackageExecutablesVector.size() % 2 != 0 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and "
+ "<icon name>." << std::endl);
+ return 0;
+ }
+ std::vector<std::string>::iterator it;
+ for ( it = cpackPackageExecutablesVector.begin();
+ it != cpackPackageExecutablesVector.end();
+ ++it )
+ {
+ std::string cpackExecutableName = *it;
+ ++ it;
+ this->SetOptionIfNotSet("CPACK_EXECUTABLE_NAME",
+ cpackExecutableName.c_str());
+ }
+ }
+
+ // Disk image directories
+ std::string diskImageDirectory = toplevel;
+ std::string diskImageBackgroundImageDir
+ = diskImageDirectory + "/.background";
+
+
+ // App bundle directories
+ std::string packageDirFileName = toplevel;
+ packageDirFileName += "/";
+ packageDirFileName += this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ packageDirFileName += ".app";
+ std::string contentsDirectory = packageDirFileName + "/Contents";
+ std::string resourcesDirectory = contentsDirectory + "/Resources";
+ std::string appDirectory = contentsDirectory + "/MacOS";
+ std::string scriptDirectory = resourcesDirectory + "/Scripts";
+ std::string resourceFileName = this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ resourceFileName += ".rsrc";
+
+ const char* dir = resourcesDirectory.c_str();
+ const char* appdir = appDirectory.c_str();
+ const char* scrDir = scriptDirectory.c_str();
+ const char* contDir = contentsDirectory.c_str();
+ const char* rsrcFile = resourceFileName.c_str();
+ const char* iconFile = this->GetOption("CPACK_PACKAGE_ICON");
+ if ( iconFile )
+ {
+ std::string iconFileName = cmsys::SystemTools::GetFilenameName(
+ iconFile);
+ if ( !cmSystemTools::FileExists(iconFile) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find icon file: "
+ << iconFile << ". Please check CPACK_PACKAGE_ICON setting."
+ << std::endl);
+ return 0;
+ }
+ std::string destFileName = resourcesDirectory + "/" + iconFileName;
+ this->ConfigureFile(iconFile, destFileName.c_str(), true);
+ this->SetOptionIfNotSet("CPACK_APPLE_GUI_ICON", iconFileName.c_str());
+ }
+
+ std::string applicationsLinkName = diskImageDirectory + "/Applications";
+ cmSystemTools::CreateSymlink("/Applications", applicationsLinkName.c_str());
+
+ if (
+ !this->CopyResourcePlistFile("VolumeIcon.icns",
+ diskImageDirectory.c_str(),
+ ".VolumeIcon.icns", true ) ||
+ !this->CopyResourcePlistFile("DS_Store", diskImageDirectory.c_str(),
+ ".DS_Store", true ) ||
+ !this->CopyResourcePlistFile("background.png",
+ diskImageBackgroundImageDir.c_str(), "background.png", true ) ||
+ !this->CopyResourcePlistFile("RuntimeScript", dir) ||
+ !this->CopyResourcePlistFile("OSXX11.Info.plist", contDir,
+ "Info.plist" ) ||
+ !this->CopyResourcePlistFile("OSXX11.main.scpt", scrDir,
+ "main.scpt", true ) ||
+ !this->CopyResourcePlistFile("OSXScriptLauncher.rsrc", dir,
+ rsrcFile, true) ||
+ !this->CopyResourcePlistFile("OSXScriptLauncher", appdir,
+ this->GetOption("CPACK_PACKAGE_FILE_NAME"), true)
+ )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files"
+ << std::endl);
+ return 0;
+ }
+
+ // Two of the files need to have execute permission, so ensure they do:
+ std::string runTimeScript = dir;
+ runTimeScript += "/";
+ runTimeScript += "RuntimeScript";
+
+ std::string appScriptName = appdir;
+ appScriptName += "/";
+ appScriptName += this->GetOption("CPACK_PACKAGE_FILE_NAME");
+
+ mode_t mode;
+ if (cmsys::SystemTools::GetPermissions(runTimeScript.c_str(), mode))
+ {
+ mode |= (S_IXUSR | S_IXGRP | S_IXOTH);
+ cmsys::SystemTools::SetPermissions(runTimeScript.c_str(), mode);
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Setting: " << runTimeScript
+ << " to permission: " << mode << std::endl);
+ }
+
+ if (cmsys::SystemTools::GetPermissions(appScriptName.c_str(), mode))
+ {
+ mode |= (S_IXUSR | S_IXGRP | S_IXOTH);
+ cmsys::SystemTools::SetPermissions(appScriptName.c_str(), mode);
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Setting: " << appScriptName
+ << " to permission: " << mode << std::endl);
+ }
+
+ std::string output;
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/hdiutilOutput.log";
+ cmOStringStream dmgCmd;
+ dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE")
+ << "\" create -ov -format UDZO -srcfolder \""
+ << diskImageDirectory.c_str()
+ << "\" \"" << packageFileNames[0] << "\"";
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Compress disk image using command: "
+ << dmgCmd.str().c_str() << std::endl);
+ // since we get random dashboard failures with this one
+ // try running it more than once
+ int retVal = 1;
+ int numTries = 10;
+ bool res = false;
+ while(numTries > 0)
+ {
+ res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output,
+ &retVal, 0,
+ this->GeneratorVerbose, 0);
+ if ( res && !retVal )
+ {
+ numTries = -1;
+ break;
+ }
+ cmSystemTools::Delay(500);
+ numTries--;
+ }
+ if ( !res || retVal )
+ {
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
+ << "# Output:" << std::endl
+ << output.c_str() << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: "
+ << dmgCmd.str().c_str() << std::endl
+ << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
+ return 0;
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackOSXX11Generator::InitializeInternal()
+{
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "cmCPackOSXX11Generator::Initialize()" << std::endl);
+ std::vector<std::string> path;
+ std::string pkgPath = cmSystemTools::FindProgram("hdiutil", path, false);
+ if ( pkgPath.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler"
+ << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE",
+ pkgPath.c_str());
+
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+/*
+bool cmCPackOSXX11Generator::CopyCreateResourceFile(const std::string& name)
+{
+ std::string uname = cmSystemTools::UpperCase(name);
+ std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
+ const char* inFileName = this->GetOption(cpackVar.c_str());
+ if ( !inFileName )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack option: " << cpackVar.c_str()
+ << " not specified. It should point to "
+ << (name ? name : "(NULL)")
+ << ".rtf, " << name
+ << ".html, or " << name << ".txt file" << std::endl);
+ return false;
+ }
+ if ( !cmSystemTools::FileExists(inFileName) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find "
+ << (name ? name : "(NULL)")
+ << " resource file: " << inFileName << std::endl);
+ return false;
+ }
+ std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName);
+ if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Bad file extension specified: "
+ << ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed."
+ << std::endl);
+ return false;
+ }
+
+ std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ destFileName += "/Resources/";
+ destFileName += name + ext;
+
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
+ << (inFileName ? inFileName : "(NULL)")
+ << " to " << destFileName.c_str() << std::endl);
+ this->ConfigureFile(inFileName, destFileName.c_str());
+ return true;
+}
+*/
+
+//----------------------------------------------------------------------
+bool cmCPackOSXX11Generator::CopyResourcePlistFile(const std::string& name,
+ const std::string& dir, const char* outputFileName /* = 0 */,
+ bool copyOnly /* = false */)
+{
+ std::string inFName = "CPack.";
+ inFName += name;
+ inFName += ".in";
+ std::string inFileName = this->FindTemplate(inFName.c_str());
+ if ( inFileName.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: "
+ << inFName << std::endl);
+ return false;
+ }
+
+ if ( !outputFileName )
+ {
+ outputFileName = name.c_str();
+ }
+
+ std::string destFileName = dir;
+ destFileName += "/";
+ destFileName += outputFileName;
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
+ << inFileName.c_str() << " to " << destFileName.c_str() << std::endl);
+ this->ConfigureFile(inFileName.c_str(), destFileName.c_str(), copyOnly);
+ return true;
+}
+
+//----------------------------------------------------------------------
+const char* cmCPackOSXX11Generator::GetPackagingInstallPrefix()
+{
+ this->InstallPrefix = "/";
+ this->InstallPrefix += this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ this->InstallPrefix += ".app/Contents/Resources";
+ return this->InstallPrefix.c_str();
+}
diff --git a/Source/CPack/cmCPackOSXX11Generator.h b/Source/CPack/cmCPackOSXX11Generator.h
new file mode 100644
index 0000000000..9d0a6d1888
--- /dev/null
+++ b/Source/CPack/cmCPackOSXX11Generator.h
@@ -0,0 +1,47 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackOSXX11Generator_h
+#define cmCPackOSXX11Generator_h
+
+#include "cmCPackGenerator.h"
+
+/** \class cmCPackOSXX11Generator
+ * \brief A generator for OSX X11 modules
+ *
+ * Based on Gimp.app
+ */
+class cmCPackOSXX11Generator : public cmCPackGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackOSXX11Generator, cmCPackGenerator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackOSXX11Generator();
+ virtual ~cmCPackOSXX11Generator();
+
+protected:
+ virtual int InitializeInternal();
+ int PackageFiles();
+ virtual const char* GetPackagingInstallPrefix();
+ virtual const char* GetOutputExtension() { return ".dmg"; }
+
+ //bool CopyCreateResourceFile(const std::string& name,
+ // const std::string& dir);
+ bool CopyResourcePlistFile(const std::string& name, const std::string& dir,
+ const char* outputFileName = 0, bool copyOnly = false);
+ std::string InstallPrefix;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx
new file mode 100644
index 0000000000..d736948a28
--- /dev/null
+++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx
@@ -0,0 +1,1041 @@
+/*============================================================================
+ 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 "cmCPackPackageMakerGenerator.h"
+
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackComponentGroup.h"
+#include "cmCPackLog.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+
+//----------------------------------------------------------------------
+cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
+{
+ this->PackageMakerVersion = 0.0;
+ this->PackageCompatibilityVersion = 10.4;
+}
+
+//----------------------------------------------------------------------
+cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+bool cmCPackPackageMakerGenerator::SupportsComponentInstallation() const
+{
+ return this->PackageCompatibilityVersion >= 10.4;
+}
+
+//----------------------------------------------------------------------
+int cmCPackPackageMakerGenerator::CopyInstallScript(const std::string& resdir,
+ const std::string& script,
+ const std::string& name)
+{
+ std::string dst = resdir;
+ dst += "/";
+ dst += name;
+ cmSystemTools::CopyFileAlways(script.c_str(), dst.c_str());
+ cmSystemTools::SetPermissions(dst.c_str(),0777);
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "copy script : " << script << "\ninto " << dst.c_str() <<
+ std::endl);
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackPackageMakerGenerator::PackageFiles()
+{
+ // TODO: Use toplevel
+ // It is used! Is this an obsolete comment?
+
+ std::string resDir; // Where this package's resources will go.
+ std::string packageDirFileName
+ = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ if (this->Components.empty())
+ {
+ packageDirFileName += ".pkg";
+ resDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ resDir += "/Resources";
+ }
+ else
+ {
+ packageDirFileName += ".mpkg";
+ if ( !cmsys::SystemTools::MakeDirectory(packageDirFileName.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "unable to create package directory "
+ << packageDirFileName << std::endl);
+ return 0;
+ }
+
+ resDir = packageDirFileName;
+ resDir += "/Contents";
+ if ( !cmsys::SystemTools::MakeDirectory(resDir.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "unable to create package subdirectory " << resDir
+ << std::endl);
+ return 0;
+ }
+
+ resDir += "/Resources";
+ if ( !cmsys::SystemTools::MakeDirectory(resDir.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "unable to create package subdirectory " << resDir
+ << std::endl);
+ return 0;
+ }
+
+ resDir += "/en.lproj";
+ }
+
+ const char* preflight = this->GetOption("CPACK_PREFLIGHT_SCRIPT");
+ const char* postflight = this->GetOption("CPACK_POSTFLIGHT_SCRIPT");
+ const char* postupgrade = this->GetOption("CPACK_POSTUPGRADE_SCRIPT");
+
+ if(this->Components.empty())
+ {
+ // Create directory structure
+ std::string preflightDirName = resDir + "/PreFlight";
+ std::string postflightDirName = resDir + "/PostFlight";
+ // if preflight or postflight scripts not there create directories
+ // of the same name, I think this makes it work
+ if(!preflight)
+ {
+ if ( !cmsys::SystemTools::MakeDirectory(preflightDirName.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem creating installer directory: "
+ << preflightDirName.c_str() << std::endl);
+ return 0;
+ }
+ }
+ if(!postflight)
+ {
+ if ( !cmsys::SystemTools::MakeDirectory(postflightDirName.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem creating installer directory: "
+ << postflightDirName.c_str() << std::endl);
+ return 0;
+ }
+ }
+ // if preflight, postflight, or postupgrade are set
+ // then copy them into the resource directory and make
+ // them executable
+ if(preflight)
+ {
+ this->CopyInstallScript(resDir.c_str(),
+ preflight,
+ "preflight");
+ }
+ if(postflight)
+ {
+ this->CopyInstallScript(resDir.c_str(),
+ postflight,
+ "postflight");
+ }
+ if(postupgrade)
+ {
+ this->CopyInstallScript(resDir.c_str(),
+ postupgrade,
+ "postupgrade");
+ }
+ }
+ else if(postflight)
+ {
+ // create a postflight component to house the script
+ this->PostFlightComponent.Name = "PostFlight";
+ this->PostFlightComponent.DisplayName = "PostFlight";
+ this->PostFlightComponent.Description = "PostFlight";
+ this->PostFlightComponent.IsHidden = true;
+
+ // empty directory for pkg contents
+ std::string packageDir = toplevel + "/" + PostFlightComponent.Name;
+ if (!cmsys::SystemTools::MakeDirectory(packageDir.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem creating component packages directory: "
+ << packageDir.c_str() << std::endl);
+ return 0;
+ }
+
+ // create package
+ std::string packageFileDir = packageDirFileName + "/Contents/Packages/";
+ if (!cmsys::SystemTools::MakeDirectory(packageFileDir.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem creating component PostFlight Packages directory: "
+ << packageFileDir.c_str() << std::endl);
+ return 0;
+ }
+ std::string packageFile = packageFileDir +
+ this->GetPackageName(PostFlightComponent);
+ if (!this->GenerateComponentPackage(packageFile.c_str(),
+ packageDir.c_str(),
+ PostFlightComponent))
+ {
+ return 0;
+ }
+
+ // copy postflight script into resource directory of .pkg
+ std::string resourceDir = packageFile + "/Contents/Resources";
+ this->CopyInstallScript(resourceDir.c_str(),
+ postflight,
+ "postflight");
+ }
+
+ if (!this->Components.empty())
+ {
+ // Create the directory where component packages will be built.
+ std::string basePackageDir = packageDirFileName;
+ basePackageDir += "/Contents/Packages";
+ if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem creating component packages directory: "
+ << basePackageDir.c_str() << std::endl);
+ return 0;
+ }
+
+ // Create the directory where downloaded component packages will
+ // be placed.
+ const char* userUploadDirectory =
+ this->GetOption("CPACK_UPLOAD_DIRECTORY");
+ std::string uploadDirectory;
+ if (userUploadDirectory && *userUploadDirectory)
+ {
+ uploadDirectory = userUploadDirectory;
+ }
+ else
+ {
+ uploadDirectory= this->GetOption("CPACK_PACKAGE_DIRECTORY");
+ uploadDirectory += "/CPackUploads";
+ }
+
+ // Create packages for each component
+ bool warnedAboutDownloadCompatibility = false;
+
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt = this->Components.begin(); compIt != this->Components.end();
+ ++compIt)
+ {
+ std::string packageFile;
+ if (compIt->second.IsDownloaded)
+ {
+ if (this->PackageCompatibilityVersion >= 10.5 &&
+ this->PackageMakerVersion >= 3.0)
+ {
+ // Build this package within the upload directory.
+ packageFile = uploadDirectory;
+
+ if(!cmSystemTools::FileExists(uploadDirectory.c_str()))
+ {
+ if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str()))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Unable to create package upload directory "
+ << uploadDirectory << std::endl);
+ return 0;
+ }
+ }
+ }
+ else if (!warnedAboutDownloadCompatibility)
+ {
+ if (this->PackageCompatibilityVersion < 10.5)
+ {
+ cmCPackLogger(
+ cmCPackLog::LOG_WARNING,
+ "CPack warning: please set CPACK_OSX_PACKAGE_VERSION to 10.5 "
+ "or greater enable downloaded packages. CPack will build a "
+ "non-downloaded package."
+ << std::endl);
+ }
+
+ if (this->PackageMakerVersion < 3)
+ {
+ cmCPackLogger(cmCPackLog::LOG_WARNING,
+ "CPack warning: unable to build downloaded "
+ "packages with PackageMaker versions prior "
+ "to 3.0. CPack will build a non-downloaded package."
+ << std::endl);
+ }
+
+ warnedAboutDownloadCompatibility = true;
+ }
+ }
+
+ if (packageFile.empty())
+ {
+ // Build this package within the overall distribution
+ // metapackage.
+ packageFile = basePackageDir;
+
+ // We're not downloading this component, even if the user
+ // requested it.
+ compIt->second.IsDownloaded = false;
+ }
+
+ packageFile += '/';
+ packageFile += GetPackageName(compIt->second);
+
+ std::string packageDir = toplevel;
+ packageDir += '/';
+ packageDir += compIt->first;
+ if (!this->GenerateComponentPackage(packageFile.c_str(),
+ packageDir.c_str(),
+ compIt->second))
+ {
+ return 0;
+ }
+ }
+ }
+ this->SetOption("CPACK_MODULE_VERSION_SUFFIX", "");
+
+ // Copy or create all of the resource files we need.
+ if ( !this->CopyCreateResourceFile("License", resDir.c_str())
+ || !this->CopyCreateResourceFile("ReadMe", resDir.c_str())
+ || !this->CopyCreateResourceFile("Welcome", resDir.c_str())
+ || !this->CopyResourcePlistFile("Info.plist")
+ || !this->CopyResourcePlistFile("Description.plist") )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files"
+ << std::endl);
+ return 0;
+ }
+
+ if (this->Components.empty())
+ {
+ // Use PackageMaker to build the package.
+ cmOStringStream pkgCmd;
+ pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
+ << "\" -build -p \"" << packageDirFileName << "\"";
+ if (this->Components.empty())
+ {
+ pkgCmd << " -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ }
+ else
+ {
+ pkgCmd << " -mi \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
+ << "/packages/";
+ }
+ pkgCmd << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
+ << "/Resources\" -i \""
+ << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
+ << "/Info.plist\" -d \""
+ << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
+ << "/Description.plist\"";
+ if ( this->PackageMakerVersion > 2.0 )
+ {
+ pkgCmd << " -v";
+ }
+ if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str()))
+ return 0;
+ }
+ else
+ {
+ // We have built the package in place. Generate the
+ // distribution.dist file to describe it for the installer.
+ WriteDistributionFile(packageDirFileName.c_str());
+ }
+
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/hdiutilOutput.log";
+ cmOStringStream dmgCmd;
+ dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE")
+ << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName
+ << "\" \"" << packageFileNames[0] << "\"";
+ std::string output;
+ int retVal = 1;
+ int numTries = 10;
+ bool res = false;
+ while(numTries > 0)
+ {
+ res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output,
+ &retVal, 0, this->GeneratorVerbose,
+ 0);
+ if ( res && !retVal )
+ {
+ numTries = -1;
+ break;
+ }
+ cmSystemTools::Delay(500);
+ numTries--;
+ }
+ if ( !res || retVal )
+ {
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
+ << "# Output:" << std::endl
+ << output.c_str() << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: "
+ << dmgCmd.str().c_str() << std::endl
+ << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
+ return 0;
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackPackageMakerGenerator::InitializeInternal()
+{
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "cmCPackPackageMakerGenerator::Initialize()" << std::endl);
+ this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
+
+ // Starting with Xcode 4.3, PackageMaker is a separate app, and you
+ // can put it anywhere you want. So... use a variable for its location.
+ // People who put it in unexpected places can use the variable to tell
+ // us where it is.
+ //
+ // Use the following locations, in "most recent installation" order,
+ // to search for the PackageMaker app. Assume people who copy it into
+ // the new Xcode 4.3 app in "/Applications" will copy it into the nested
+ // Applications folder inside the Xcode bundle itself. Or directly in
+ // the "/Applications" directory.
+ //
+ // If found, save result in the CPACK_INSTALLER_PROGRAM variable.
+
+ std::vector<std::string> paths;
+ paths.push_back(
+ "/Applications/Xcode.app/Contents/Applications"
+ "/PackageMaker.app/Contents/MacOS");
+ paths.push_back(
+ "/Applications/Utilities"
+ "/PackageMaker.app/Contents/MacOS");
+ paths.push_back(
+ "/Applications"
+ "/PackageMaker.app/Contents/MacOS");
+ paths.push_back(
+ "/Developer/Applications/Utilities"
+ "/PackageMaker.app/Contents/MacOS");
+ paths.push_back(
+ "/Developer/Applications"
+ "/PackageMaker.app/Contents/MacOS");
+
+ std::string pkgPath;
+ const char *inst_program = this->GetOption("CPACK_INSTALLER_PROGRAM");
+ if (inst_program && *inst_program)
+ {
+ pkgPath = inst_program;
+ }
+ else
+ {
+ pkgPath = cmSystemTools::FindProgram("PackageMaker", paths, false);
+ if ( pkgPath.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler"
+ << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
+ }
+
+ // Get path to the real PackageMaker, not a symlink:
+ pkgPath = cmSystemTools::GetRealPath(pkgPath.c_str());
+ // Up from there to find the version.plist file in the "Contents" dir:
+ std::string contents_dir;
+ contents_dir = cmSystemTools::GetFilenamePath(pkgPath);
+ contents_dir = cmSystemTools::GetFilenamePath(contents_dir);
+
+ std::string versionFile = contents_dir + "/version.plist";
+
+ if ( !cmSystemTools::FileExists(versionFile.c_str()) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find PackageMaker compiler version file: "
+ << versionFile.c_str()
+ << std::endl);
+ return 0;
+ }
+
+ cmsys::ifstream ifs(versionFile.c_str());
+ if ( !ifs )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot open PackageMaker compiler version file" << std::endl);
+ return 0;
+ }
+
+ // Check the PackageMaker version
+ cmsys::RegularExpression rexKey("<key>CFBundleShortVersionString</key>");
+ cmsys::RegularExpression rexVersion("<string>([0-9]+.[0-9.]+)</string>");
+ std::string line;
+ bool foundKey = false;
+ while ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ if ( rexKey.find(line) )
+ {
+ foundKey = true;
+ break;
+ }
+ }
+ if ( !foundKey )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find CFBundleShortVersionString in the PackageMaker compiler "
+ "version file" << std::endl);
+ return 0;
+ }
+ if ( !cmSystemTools::GetLineFromStream(ifs, line) ||
+ !rexVersion.find(line) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem reading the PackageMaker compiler version file: "
+ << versionFile.c_str() << std::endl);
+ return 0;
+ }
+ this->PackageMakerVersion = atof(rexVersion.match(1).c_str());
+ if ( this->PackageMakerVersion < 1.0 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Require PackageMaker 1.0 or higher"
+ << std::endl);
+ return 0;
+ }
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "PackageMaker version is: "
+ << this->PackageMakerVersion << std::endl);
+
+ // Determine the package compatibility version. If it wasn't
+ // specified by the user, we define it based on which features the
+ // user requested.
+ const char *packageCompat = this->GetOption("CPACK_OSX_PACKAGE_VERSION");
+ if (packageCompat && *packageCompat)
+ {
+ this->PackageCompatibilityVersion = atof(packageCompat);
+ }
+ else if (this->GetOption("CPACK_DOWNLOAD_SITE"))
+ {
+ this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.5");
+ this->PackageCompatibilityVersion = 10.5;
+ }
+ else if (this->GetOption("CPACK_COMPONENTS_ALL"))
+ {
+ this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.4");
+ this->PackageCompatibilityVersion = 10.4;
+ }
+ else
+ {
+ this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.3");
+ this->PackageCompatibilityVersion = 10.3;
+ }
+
+ std::vector<std::string> no_paths;
+ pkgPath = cmSystemTools::FindProgram("hdiutil", no_paths, false);
+ if ( pkgPath.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler"
+ << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE",
+ pkgPath.c_str());
+
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(
+ const std::string& name,
+ const std::string& dirName)
+{
+ std::string uname = cmSystemTools::UpperCase(name);
+ std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
+ const char* inFileName = this->GetOption(cpackVar.c_str());
+ if ( !inFileName )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack option: " << cpackVar.c_str()
+ << " not specified. It should point to "
+ << (!name.empty() ? name : "<empty>")
+ << ".rtf, " << name
+ << ".html, or " << name << ".txt file" << std::endl);
+ return false;
+ }
+ if ( !cmSystemTools::FileExists(inFileName) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find "
+ << (!name.empty() ? name : "<empty>")
+ << " resource file: " << inFileName << std::endl);
+ return false;
+ }
+ std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName);
+ if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Bad file extension specified: "
+ << ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed."
+ << std::endl);
+ return false;
+ }
+
+ std::string destFileName = dirName;
+ destFileName += '/';
+ destFileName += name + ext;
+
+ // Set this so that distribution.dist gets the right name (without
+ // the path).
+ this->SetOption(("CPACK_RESOURCE_FILE_" + uname + "_NOPATH").c_str(),
+ (name + ext).c_str());
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
+ << (inFileName ? inFileName : "(NULL)")
+ << " to " << destFileName.c_str() << std::endl);
+ this->ConfigureFile(inFileName, destFileName.c_str());
+ return true;
+}
+
+bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(
+ const std::string& name,
+ const char* outName)
+{
+ if (!outName)
+ {
+ outName = name.c_str();
+ }
+
+ std::string inFName = "CPack.";
+ inFName += name;
+ inFName += ".in";
+ std::string inFileName = this->FindTemplate(inFName.c_str());
+ if ( inFileName.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: "
+ << inFName << std::endl);
+ return false;
+ }
+
+ std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ destFileName += "/";
+ destFileName += outName;
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
+ << inFileName.c_str() << " to " << destFileName.c_str() << std::endl);
+ this->ConfigureFile(inFileName.c_str(), destFileName.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCPackPackageMakerGenerator::RunPackageMaker(const char *command,
+ const char *packageFile)
+{
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/PackageMakerOutput.log";
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl);
+ std::string output;
+ int retVal = 1;
+ bool res = cmSystemTools::RunSingleCommand(command, &output, &retVal, 0,
+ this->GeneratorVerbose, 0);
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker"
+ << std::endl);
+ if ( !res || retVal )
+ {
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << command << std::endl
+ << "# Output:" << std::endl
+ << output.c_str() << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running PackageMaker command: " << command
+ << std::endl << "Please check " << tmpFile.c_str() << " for errors"
+ << std::endl);
+ return false;
+ }
+ // sometimes the command finishes but the directory is not yet
+ // created, so try 10 times to see if it shows up
+ int tries = 10;
+ while(tries > 0 &&
+ !cmSystemTools::FileExists(packageFile))
+ {
+ cmSystemTools::Delay(500);
+ tries--;
+ }
+ if(!cmSystemTools::FileExists(packageFile))
+ {
+ cmCPackLogger(
+ cmCPackLog::LOG_ERROR,
+ "Problem running PackageMaker command: " << command
+ << std::endl << "Package not created: " << packageFile
+ << std::endl);
+ return false;
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------
+std::string
+cmCPackPackageMakerGenerator::GetPackageName(const cmCPackComponent& component)
+{
+ if (component.ArchiveFile.empty())
+ {
+ std::string packagesDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ packagesDir += ".dummy";
+ cmOStringStream out;
+ out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir)
+ << "-" << component.Name << ".pkg";
+ return out.str();
+ }
+ else
+ {
+ return component.ArchiveFile + ".pkg";
+ }
+}
+
+//----------------------------------------------------------------------
+bool
+cmCPackPackageMakerGenerator::
+GenerateComponentPackage(const char *packageFile,
+ const char *packageDir,
+ const cmCPackComponent& component)
+{
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Building component package: " <<
+ packageFile << std::endl);
+
+ // The command that will be used to run PackageMaker
+ cmOStringStream pkgCmd;
+
+ if (this->PackageCompatibilityVersion < 10.5 ||
+ this->PackageMakerVersion < 3.0)
+ {
+ // Create Description.plist and Info.plist files for normal Mac OS
+ // X packages, which work on Mac OS X 10.3 and newer.
+ std::string descriptionFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ descriptionFile += '/' + component.Name + "-Description.plist";
+ cmsys::ofstream out(descriptionFile.c_str());
+ out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl
+ << "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\""
+ << "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" << std::endl
+ << "<plist version=\"1.4\">" << std::endl
+ << "<dict>" << std::endl
+ << " <key>IFPkgDescriptionTitle</key>" << std::endl
+ << " <string>" << component.DisplayName << "</string>" << std::endl
+ << " <key>IFPkgDescriptionVersion</key>" << std::endl
+ << " <string>" << this->GetOption("CPACK_PACKAGE_VERSION")
+ << "</string>" << std::endl
+ << " <key>IFPkgDescriptionDescription</key>" << std::endl
+ << " <string>" + this->EscapeForXML(component.Description)
+ << "</string>" << std::endl
+ << "</dict>" << std::endl
+ << "</plist>" << std::endl;
+ out.close();
+
+ // Create the Info.plist file for this component
+ std::string moduleVersionSuffix = ".";
+ moduleVersionSuffix += component.Name;
+ this->SetOption("CPACK_MODULE_VERSION_SUFFIX",
+ moduleVersionSuffix.c_str());
+ std::string infoFileName = component.Name;
+ infoFileName += "-Info.plist";
+ if (!this->CopyResourcePlistFile("Info.plist", infoFileName.c_str()))
+ {
+ return false;
+ }
+
+ pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
+ << "\" -build -p \"" << packageFile << "\""
+ << " -f \"" << packageDir << "\""
+ << " -i \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
+ << "/" << infoFileName << "\""
+ << " -d \"" << descriptionFile << "\"";
+ }
+ else
+ {
+ // Create a "flat" package on Mac OS X 10.5 and newer. Flat
+ // packages are stored in a single file, rather than a directory
+ // like normal packages, and can be downloaded by the installer
+ // on-the-fly in Mac OS X 10.5 or newer. Thus, we need to create
+ // flat packages when the packages will be downloaded on the fly.
+ std::string pkgId = "com.";
+ pkgId += this->GetOption("CPACK_PACKAGE_VENDOR");
+ pkgId += '.';
+ pkgId += this->GetOption("CPACK_PACKAGE_NAME");
+ pkgId += '.';
+ pkgId += component.Name;
+
+ pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
+ << "\" --root \"" << packageDir << "\""
+ << " --id " << pkgId
+ << " --target " << this->GetOption("CPACK_OSX_PACKAGE_VERSION")
+ << " --out \"" << packageFile << "\"";
+ }
+
+ // Run PackageMaker
+ return RunPackageMaker(pkgCmd.str().c_str(), packageFile);
+}
+
+//----------------------------------------------------------------------
+void
+cmCPackPackageMakerGenerator::
+WriteDistributionFile(const char* metapackageFile)
+{
+ std::string distributionTemplate
+ = this->FindTemplate("CPack.distribution.dist.in");
+ if ( distributionTemplate.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: "
+ << distributionTemplate << std::endl);
+ return;
+ }
+
+ std::string distributionFile = metapackageFile;
+ distributionFile += "/Contents/distribution.dist";
+
+ // Create the choice outline, which provides a tree-based view of
+ // the components in their groups.
+ cmOStringStream choiceOut;
+ choiceOut << "<choices-outline>" << std::endl;
+
+ // Emit the outline for the groups
+ std::map<std::string, cmCPackComponentGroup>::iterator groupIt;
+ for (groupIt = this->ComponentGroups.begin();
+ groupIt != this->ComponentGroups.end();
+ ++groupIt)
+ {
+ if (groupIt->second.ParentGroup == 0)
+ {
+ CreateChoiceOutline(groupIt->second, choiceOut);
+ }
+ }
+
+ // Emit the outline for the non-grouped components
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt = this->Components.begin(); compIt != this->Components.end();
+ ++compIt)
+ {
+ if (!compIt->second.Group)
+ {
+ choiceOut << "<line choice=\"" << compIt->first << "Choice\"></line>"
+ << std::endl;
+ }
+ }
+ if(!this->PostFlightComponent.Name.empty())
+ {
+ choiceOut << "<line choice=\"" << PostFlightComponent.Name
+ << "Choice\"></line>" << std::endl;
+ }
+ choiceOut << "</choices-outline>" << std::endl;
+
+ // Create the actual choices
+ for (groupIt = this->ComponentGroups.begin();
+ groupIt != this->ComponentGroups.end();
+ ++groupIt)
+ {
+ CreateChoice(groupIt->second, choiceOut);
+ }
+ for (compIt = this->Components.begin(); compIt != this->Components.end();
+ ++compIt)
+ {
+ CreateChoice(compIt->second, choiceOut);
+ }
+
+ if(!this->PostFlightComponent.Name.empty())
+ {
+ CreateChoice(PostFlightComponent, choiceOut);
+ }
+
+ this->SetOption("CPACK_PACKAGEMAKER_CHOICES", choiceOut.str().c_str());
+
+ // Create the distribution.dist file in the metapackage to turn it
+ // into a distribution package.
+ this->ConfigureFile(distributionTemplate.c_str(),
+ distributionFile.c_str());
+}
+
+//----------------------------------------------------------------------
+void
+cmCPackPackageMakerGenerator::
+CreateChoiceOutline(const cmCPackComponentGroup& group, cmOStringStream& out)
+{
+ out << "<line choice=\"" << group.Name << "Choice\">" << std::endl;
+ std::vector<cmCPackComponentGroup*>::const_iterator groupIt;
+ for (groupIt = group.Subgroups.begin(); groupIt != group.Subgroups.end();
+ ++groupIt)
+ {
+ CreateChoiceOutline(**groupIt, out);
+ }
+
+ std::vector<cmCPackComponent*>::const_iterator compIt;
+ for (compIt = group.Components.begin(); compIt != group.Components.end();
+ ++compIt)
+ {
+ out << " <line choice=\"" << (*compIt)->Name << "Choice\"></line>"
+ << std::endl;
+ }
+ out << "</line>" << std::endl;
+}
+
+//----------------------------------------------------------------------
+void
+cmCPackPackageMakerGenerator::CreateChoice(const cmCPackComponentGroup& group,
+ cmOStringStream& out)
+{
+ out << "<choice id=\"" << group.Name << "Choice\" "
+ << "title=\"" << group.DisplayName << "\" "
+ << "start_selected=\"true\" "
+ << "start_enabled=\"true\" "
+ << "start_visible=\"true\" ";
+ if (!group.Description.empty())
+ {
+ out << "description=\"" << EscapeForXML(group.Description)
+ << "\"";
+ }
+ out << "></choice>" << std::endl;
+}
+
+//----------------------------------------------------------------------
+void
+cmCPackPackageMakerGenerator::CreateChoice(const cmCPackComponent& component,
+ cmOStringStream& out)
+{
+ std::string packageId = "com.";
+ packageId += this->GetOption("CPACK_PACKAGE_VENDOR");
+ packageId += '.';
+ packageId += this->GetOption("CPACK_PACKAGE_NAME");
+ packageId += '.';
+ packageId += component.Name;
+
+ out << "<choice id=\"" << component.Name << "Choice\" "
+ << "title=\"" << component.DisplayName << "\" "
+ << "start_selected=\""
+ << (component.IsDisabledByDefault &&
+ !component.IsRequired? "false" : "true")
+ << "\" "
+ << "start_enabled=\""
+ << (component.IsRequired? "false" : "true")
+ << "\" "
+ << "start_visible=\"" << (component.IsHidden? "false" : "true") << "\" ";
+ if (!component.Description.empty())
+ {
+ out << "description=\"" << EscapeForXML(component.Description)
+ << "\" ";
+ }
+ if (!component.Dependencies.empty() ||
+ !component.ReverseDependencies.empty())
+ {
+ // The "selected" expression is evaluated each time any choice is
+ // selected, for all choices *except* the one that the user
+ // selected. A component is marked selected if it has been
+ // selected (my.choice.selected in Javascript) and all of the
+ // components it depends on have been selected (transitively) or
+ // if any of the components that depend on it have been selected
+ // (transitively). Assume that we have components A, B, C, D, and
+ // E, where each component depends on the previous component (B
+ // depends on A, C depends on B, D depends on C, and E depends on
+ // D). The expression we build for the component C will be
+ // my.choice.selected && B && A || D || E
+ // This way, selecting C will automatically select everything it depends
+ // on (B and A), while selecting something that depends on C--either D
+ // or E--will automatically cause C to get selected.
+ out << "selected=\"my.choice.selected";
+ std::set<const cmCPackComponent *> visited;
+ AddDependencyAttributes(component, visited, out);
+ visited.clear();
+ AddReverseDependencyAttributes(component, visited, out);
+ out << "\"";
+ }
+ out << ">" << std::endl;
+ out << " <pkg-ref id=\"" << packageId << "\"></pkg-ref>" << std::endl;
+ out << "</choice>" << std::endl;
+
+ // Create a description of the package associated with this
+ // component.
+ std::string relativePackageLocation = "Contents/Packages/";
+ relativePackageLocation += this->GetPackageName(component);
+
+ // Determine the installed size of the package.
+ std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ dirName += '/';
+ dirName += component.Name;
+ unsigned long installedSize
+ = component.GetInstalledSizeInKbytes(dirName.c_str());
+
+ out << "<pkg-ref id=\"" << packageId << "\" "
+ << "version=\"" << this->GetOption("CPACK_PACKAGE_VERSION") << "\" "
+ << "installKBytes=\"" << installedSize << "\" "
+ << "auth=\"Admin\" onConclusion=\"None\">";
+ if (component.IsDownloaded)
+ {
+ out << this->GetOption("CPACK_DOWNLOAD_SITE")
+ << this->GetPackageName(component);
+ }
+ else
+ {
+ out << "file:./" << relativePackageLocation;
+ }
+ out << "</pkg-ref>" << std::endl;
+}
+
+//----------------------------------------------------------------------
+void
+cmCPackPackageMakerGenerator::
+AddDependencyAttributes(const cmCPackComponent& component,
+ std::set<const cmCPackComponent *>& visited,
+ cmOStringStream& out)
+{
+ if (visited.find(&component) != visited.end())
+ {
+ return;
+ }
+ visited.insert(&component);
+
+ std::vector<cmCPackComponent *>::const_iterator dependIt;
+ for (dependIt = component.Dependencies.begin();
+ dependIt != component.Dependencies.end();
+ ++dependIt)
+ {
+ out << " &amp;&amp; choices['" <<
+ (*dependIt)->Name << "Choice'].selected";
+ AddDependencyAttributes(**dependIt, visited, out);
+ }
+}
+
+//----------------------------------------------------------------------
+void
+cmCPackPackageMakerGenerator::
+AddReverseDependencyAttributes(const cmCPackComponent& component,
+ std::set<const cmCPackComponent *>& visited,
+ cmOStringStream& out)
+{
+ if (visited.find(&component) != visited.end())
+ {
+ return;
+ }
+ visited.insert(&component);
+
+ std::vector<cmCPackComponent *>::const_iterator dependIt;
+ for (dependIt = component.ReverseDependencies.begin();
+ dependIt != component.ReverseDependencies.end();
+ ++dependIt)
+ {
+ out << " || choices['" << (*dependIt)->Name << "Choice'].selected";
+ AddReverseDependencyAttributes(**dependIt, visited, out);
+ }
+}
+
+//----------------------------------------------------------------------
+std::string cmCPackPackageMakerGenerator::EscapeForXML(std::string str)
+{
+ cmSystemTools::ReplaceString(str, "&", "&amp;");
+ cmSystemTools::ReplaceString(str, "<", "&lt;");
+ cmSystemTools::ReplaceString(str, ">", "&gt;");
+ cmSystemTools::ReplaceString(str, "\"", "&quot;");
+ return str;
+}
diff --git a/Source/CPack/cmCPackPackageMakerGenerator.h b/Source/CPack/cmCPackPackageMakerGenerator.h
new file mode 100644
index 0000000000..e350a609df
--- /dev/null
+++ b/Source/CPack/cmCPackPackageMakerGenerator.h
@@ -0,0 +1,123 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackPackageMakerGenerator_h
+#define cmCPackPackageMakerGenerator_h
+
+
+#include "cmCPackGenerator.h"
+
+class cmCPackComponent;
+
+/** \class cmCPackPackageMakerGenerator
+ * \brief A generator for PackageMaker files
+ *
+ * http://developer.apple.com/documentation/Darwin
+ * /Reference/ManPages/man1/packagemaker.1.html
+ */
+class cmCPackPackageMakerGenerator : public cmCPackGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackPackageMakerGenerator, cmCPackGenerator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackPackageMakerGenerator();
+ virtual ~cmCPackPackageMakerGenerator();
+
+ virtual bool SupportsComponentInstallation() const;
+
+protected:
+ int CopyInstallScript(const std::string& resdir,
+ const std::string& script,
+ const std::string& name);
+ virtual int InitializeInternal();
+ int PackageFiles();
+ virtual const char* GetOutputExtension() { return ".dmg"; }
+ virtual const char* GetOutputPostfix() { return "darwin"; }
+
+ // Copies or creates the resource file with the given name to the
+ // package or package staging directory dirName. The variable
+ // CPACK_RESOURCE_FILE_${NAME} (where ${NAME} is the uppercased
+ // version of name) specifies the input file to use for this file,
+ // which will be configured via ConfigureFile.
+ bool CopyCreateResourceFile(const std::string& name,
+ const std::string& dirName);
+ bool CopyResourcePlistFile(const std::string& name, const char* outName = 0);
+
+ // Run PackageMaker with the given command line, which will (if
+ // successful) produce the given package file. Returns true if
+ // PackageMaker succeeds, false otherwise.
+ bool RunPackageMaker(const char *command, const char *packageFile);
+
+ // Retrieve the name of package file that will be generated for this
+ // component. The name is just the file name with extension, and
+ // does not include the subdirectory.
+ std::string GetPackageName(const cmCPackComponent& component);
+
+ // Generate a package in the file packageFile for the given
+ // component. All of the files within this component are stored in
+ // the directory packageDir. Returns true if successful, false
+ // otherwise.
+ bool GenerateComponentPackage(const char *packageFile,
+ const char *packageDir,
+ const cmCPackComponent& component);
+
+ // Writes a distribution.dist file, which turns a metapackage into a
+ // full-fledged distribution. This file is used to describe
+ // inter-component dependencies. metapackageFile is the name of the
+ // metapackage for the distribution. Only valid for a
+ // component-based install.
+ void WriteDistributionFile(const char* metapackageFile);
+
+ // Subroutine of WriteDistributionFile that writes out the
+ // dependency attributes for inter-component dependencies.
+ void AddDependencyAttributes(const cmCPackComponent& component,
+ std::set<const cmCPackComponent *>& visited,
+ cmOStringStream& out);
+
+ // Subroutine of WriteDistributionFile that writes out the
+ // reverse dependency attributes for inter-component dependencies.
+ void
+ AddReverseDependencyAttributes(const cmCPackComponent& component,
+ std::set<const cmCPackComponent *>& visited,
+ cmOStringStream& out);
+
+ // Generates XML that encodes the hierarchy of component groups and
+ // their components in a form that can be used by distribution
+ // metapackages.
+ void CreateChoiceOutline(const cmCPackComponentGroup& group,
+ cmOStringStream& out);
+
+ /// Create the "choice" XML element to describe a component group
+ /// for the installer GUI.
+ void CreateChoice(const cmCPackComponentGroup& group,
+ cmOStringStream& out);
+
+ /// Create the "choice" XML element to describe a component for the
+ /// installer GUI.
+ void CreateChoice(const cmCPackComponent& component,
+ cmOStringStream& out);
+
+ // Escape the given string to make it usable as an XML attribute
+ // value.
+ std::string EscapeForXML(std::string str);
+
+ // The PostFlight component when creating a metapackage
+ cmCPackComponent PostFlightComponent;
+
+ double PackageMakerVersion;
+ double PackageCompatibilityVersion;
+};
+
+#endif
diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx
new file mode 100644
index 0000000000..c6171dc4e0
--- /dev/null
+++ b/Source/CPack/cmCPackRPMGenerator.cxx
@@ -0,0 +1,283 @@
+/*============================================================================
+ 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 "cmCPackRPMGenerator.h"
+#include "cmCPackLog.h"
+#include "cmSystemTools.h"
+
+//----------------------------------------------------------------------
+cmCPackRPMGenerator::cmCPackRPMGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackRPMGenerator::~cmCPackRPMGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackRPMGenerator::InitializeInternal()
+{
+ this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
+ if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR")))
+ {
+ this->SetOption("CPACK_SET_DESTDIR", "I_ON");
+ }
+ /* Replace space in CPACK_PACKAGE_NAME in order to avoid
+ * rpmbuild scream on unwanted space in filename issue
+ * Moreover RPM file do not usually embed space in filename
+ */
+ if (this->GetOption("CPACK_PACKAGE_NAME")) {
+ std::string packageName=this->GetOption("CPACK_PACKAGE_NAME");
+ cmSystemTools::ReplaceString(packageName," ","-");
+ this->SetOption("CPACK_PACKAGE_NAME",packageName.c_str());
+ }
+ /* same for CPACK_PACKAGE_FILE_NAME */
+ if (this->GetOption("CPACK_PACKAGE_FILE_NAME")) {
+ std::string packageName=this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ cmSystemTools::ReplaceString(packageName," ","-");
+ this->SetOption("CPACK_PACKAGE_FILE_NAME",packageName.c_str());
+ }
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+int cmCPackRPMGenerator::PackageOnePack(std::string initialToplevel,
+ std::string packageName)
+{
+ int retval = 1;
+ // Begin the archive for this pack
+ std::string localToplevel(initialToplevel);
+ std::string packageFileName(
+ cmSystemTools::GetParentDirectory(toplevel.c_str())
+ );
+ std::string outputFileName(
+ GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
+ packageName,
+ true)
+ + this->GetOutputExtension()
+ );
+
+ localToplevel += "/"+ packageName;
+ /* replace the TEMP DIRECTORY with the component one */
+ this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
+ packageFileName += "/"+ outputFileName;
+ /* replace proposed CPACK_OUTPUT_FILE_NAME */
+ this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
+ /* replace the TEMPORARY package file name */
+ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
+ packageFileName.c_str());
+ // Tell CPackRPM.cmake the name of the component NAME.
+ this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",packageName.c_str());
+ // Tell CPackRPM.cmake the path where the component is.
+ std::string component_path = "/";
+ component_path += packageName;
+ this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH",
+ component_path.c_str());
+ if (!this->ReadListFile("CPackRPM.cmake"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while execution CPackRPM.cmake" << std::endl);
+ retval = 0;
+ }
+ // add the generated package to package file names list
+ packageFileNames.push_back(packageFileName);
+ return retval;
+}
+
+//----------------------------------------------------------------------
+int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
+{
+ int retval = 1;
+ /* Reset package file name list it will be populated during the
+ * component packaging run*/
+ packageFileNames.clear();
+ std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
+
+ // The default behavior is to have one package by component group
+ // unless CPACK_COMPONENTS_IGNORE_GROUP is specified.
+ if (!ignoreGroup)
+ {
+ std::map<std::string, cmCPackComponentGroup>::iterator compGIt;
+ for (compGIt=this->ComponentGroups.begin();
+ compGIt!=this->ComponentGroups.end(); ++compGIt)
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
+ << compGIt->first
+ << std::endl);
+ retval &= PackageOnePack(initialTopLevel,compGIt->first);
+ }
+ // Handle Orphan components (components not belonging to any groups)
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt=this->Components.begin();
+ compIt!=this->Components.end(); ++compIt )
+ {
+ // Does the component belong to a group?
+ if (compIt->second.Group==NULL)
+ {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Component <"
+ << compIt->second.Name
+ << "> does not belong to any group, package it separately."
+ << std::endl);
+ retval &= PackageOnePack(initialTopLevel,compIt->first);
+ }
+ }
+ }
+ // CPACK_COMPONENTS_IGNORE_GROUPS is set
+ // We build 1 package per component
+ else
+ {
+ std::map<std::string, cmCPackComponent>::iterator compIt;
+ for (compIt=this->Components.begin();
+ compIt!=this->Components.end(); ++compIt )
+ {
+ retval &= PackageOnePack(initialTopLevel,compIt->first);
+ }
+ }
+ return retval;
+}
+
+//----------------------------------------------------------------------
+int cmCPackRPMGenerator::PackageComponentsAllInOne()
+{
+ int retval = 1;
+ std::string compInstDirName;
+ /* Reset package file name list it will be populated during the
+ * component packaging run*/
+ packageFileNames.clear();
+ std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
+
+ compInstDirName = "ALL_COMPONENTS_IN_ONE";
+
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Packaging all groups in one package..."
+ "(CPACK_COMPONENTS_ALL_[GROUPS_]IN_ONE_PACKAGE is set)"
+ << std::endl);
+
+ // The ALL GROUPS in ONE package case
+ std::string localToplevel(initialTopLevel);
+ std::string packageFileName(
+ cmSystemTools::GetParentDirectory(toplevel.c_str())
+ );
+ std::string outputFileName(
+ std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
+ + this->GetOutputExtension()
+ );
+ // all GROUP in one vs all COMPONENT in one
+ localToplevel += "/"+compInstDirName;
+
+ /* replace the TEMP DIRECTORY with the component one */
+ this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
+ packageFileName += "/"+ outputFileName;
+ /* replace proposed CPACK_OUTPUT_FILE_NAME */
+ this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
+ /* replace the TEMPORARY package file name */
+ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
+ packageFileName.c_str());
+ // Tell CPackRPM.cmake the path where the component is.
+ std::string component_path = "/";
+ component_path += compInstDirName;
+ this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH",
+ component_path.c_str());
+ if (!this->ReadListFile("CPackRPM.cmake"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while execution CPackRPM.cmake" << std::endl);
+ retval = 0;
+ }
+ // add the generated package to package file names list
+ packageFileNames.push_back(packageFileName);
+
+ return retval;
+}
+
+//----------------------------------------------------------------------
+int cmCPackRPMGenerator::PackageFiles()
+{
+ int retval = 1;
+
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: "
+ << toplevel << std::endl);
+
+ /* Are we in the component packaging case */
+ if (WantsComponentInstallation()) {
+ // CASE 1 : COMPONENT ALL-IN-ONE package
+ // If ALL COMPONENTS in ONE package has been requested
+ // then the package file is unique and should be open here.
+ if (componentPackageMethod == ONE_PACKAGE)
+ {
+ return PackageComponentsAllInOne();
+ }
+ // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one)
+ // There will be 1 package for each component group
+ // however one may require to ignore component group and
+ // in this case you'll get 1 package for each component.
+ else
+ {
+ return PackageComponents(componentPackageMethod ==
+ ONE_PACKAGE_PER_COMPONENT);
+ }
+ }
+ // CASE 3 : NON COMPONENT package.
+ else
+ {
+ if (!this->ReadListFile("CPackRPM.cmake"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while execution CPackRPM.cmake" << std::endl);
+ retval = 0;
+ }
+ }
+
+ if (!this->IsSet("RPMBUILD_EXECUTABLE"))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find rpmbuild" << std::endl);
+ retval = 0;
+ }
+ return retval;
+}
+
+bool cmCPackRPMGenerator::SupportsComponentInstallation() const
+ {
+ if (IsOn("CPACK_RPM_COMPONENT_INSTALL"))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix(
+ const std::string& componentName)
+ {
+ if (componentPackageMethod == ONE_PACKAGE_PER_COMPONENT) {
+ return componentName;
+ }
+
+ if (componentPackageMethod == ONE_PACKAGE) {
+ return std::string("ALL_COMPONENTS_IN_ONE");
+ }
+ // We have to find the name of the COMPONENT GROUP
+ // the current COMPONENT belongs to.
+ std::string groupVar = "CPACK_COMPONENT_" +
+ cmSystemTools::UpperCase(componentName) + "_GROUP";
+ if (NULL != GetOption(groupVar))
+ {
+ return std::string(GetOption(groupVar));
+ }
+ else
+ {
+ return componentName;
+ }
+ }
diff --git a/Source/CPack/cmCPackRPMGenerator.h b/Source/CPack/cmCPackRPMGenerator.h
new file mode 100644
index 0000000000..a7722bc58f
--- /dev/null
+++ b/Source/CPack/cmCPackRPMGenerator.h
@@ -0,0 +1,77 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackRPMGenerator_h
+#define cmCPackRPMGenerator_h
+
+
+#include "cmCPackGenerator.h"
+
+/** \class cmCPackRPMGenerator
+ * \brief A generator for RPM packages
+ * The idea of the CPack RPM generator is to use
+ * as minimal C++ code as possible.
+ * Ideally the C++ part of the CPack RPM generator
+ * will only 'execute' (aka ->ReadListFile) several
+ * CMake macros files.
+ */
+class cmCPackRPMGenerator : public cmCPackGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackRPMGenerator, cmCPackGenerator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackRPMGenerator();
+ virtual ~cmCPackRPMGenerator();
+
+ static bool CanGenerate()
+ {
+#ifdef __APPLE__
+ // on MacOS enable CPackRPM iff rpmbuild is found
+ std::vector<std::string> locations;
+ locations.push_back("/sw/bin"); // Fink
+ locations.push_back("/opt/local/bin"); // MacPorts
+ return cmSystemTools::FindProgram("rpmbuild") != "" ? true : false;
+#else
+ // legacy behavior on other systems
+ return true;
+#endif
+ }
+
+protected:
+ virtual int InitializeInternal();
+ virtual int PackageFiles();
+ /**
+ * This method factors out the work done in component packaging case.
+ */
+ int PackageOnePack(std::string initialToplevel, std::string packageName);
+ /**
+ * The method used to package files when component
+ * install is used. This will create one
+ * archive for each component group.
+ */
+ int PackageComponents(bool ignoreGroup);
+ /**
+ * Special case of component install where all
+ * components will be put in a single installer.
+ */
+ int PackageComponentsAllInOne();
+ virtual const char* GetOutputExtension() { return ".rpm"; }
+ virtual bool SupportsComponentInstallation() const;
+ virtual std::string GetComponentInstallDirNameSuffix(
+ const std::string& componentName);
+
+};
+
+#endif
diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx
new file mode 100644
index 0000000000..6c1d201896
--- /dev/null
+++ b/Source/CPack/cmCPackSTGZGenerator.cxx
@@ -0,0 +1,139 @@
+/*============================================================================
+ 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 "cmCPackSTGZGenerator.h"
+
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmCPackLog.h"
+
+#include <cmsys/ios/sstream>
+#include <cmsys/FStream.hxx>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+//----------------------------------------------------------------------
+cmCPackSTGZGenerator::cmCPackSTGZGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackSTGZGenerator::~cmCPackSTGZGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackSTGZGenerator::InitializeInternal()
+{
+ this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
+
+ std::string inFile = this->FindTemplate("CPack.STGZ_Header.sh.in");
+ if ( inFile.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find template file: "
+ << inFile << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str());
+ this->SetOptionIfNotSet("CPACK_AT_SIGN", "@");
+
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+int cmCPackSTGZGenerator::PackageFiles()
+{
+ bool retval = true;
+ if ( !this->Superclass::PackageFiles() )
+ {
+ return 0;
+ }
+
+ /* TGZ generator (our Superclass) may
+ * have generated several packages (component packaging)
+ * so we must iterate over generated packages.
+ */
+ for (std::vector<std::string>::iterator it=packageFileNames.begin();
+ it != packageFileNames.end(); ++it)
+ {
+ retval &= cmSystemTools::SetPermissions((*it).c_str(),
+#if defined( _MSC_VER ) || defined( __MINGW32__ )
+ S_IREAD | S_IWRITE | S_IEXEC
+#elif defined( __BORLANDC__ )
+ S_IRUSR | S_IWUSR | S_IXUSR
+#else
+ S_IRUSR | S_IWUSR | S_IXUSR |
+ S_IRGRP | S_IWGRP | S_IXGRP |
+ S_IROTH | S_IWOTH | S_IXOTH
+#endif
+ );
+ }
+ return retval;
+}
+
+//----------------------------------------------------------------------
+int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
+{
+ cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl);
+ cmsys_ios::ostringstream str;
+ int counter = 0;
+
+ std::string inLicFile = this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
+ std::string line;
+ cmsys::ifstream ilfs(inLicFile.c_str());
+ std::string licenseText;
+ while ( cmSystemTools::GetLineFromStream(ilfs, line) )
+ {
+ licenseText += line + "\n";
+ }
+ this->SetOptionIfNotSet("CPACK_RESOURCE_FILE_LICENSE_CONTENT",
+ licenseText.c_str());
+
+ const char headerLengthTag[] = "###CPACK_HEADER_LENGTH###";
+
+ // Create the header
+ std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE");
+ cmsys::ifstream ifs(inFile.c_str());
+ std::string packageHeaderText;
+ while ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ packageHeaderText += line + "\n";
+ }
+
+ // Configure in the values
+ std::string res;
+ this->ConfigureString(packageHeaderText, res);
+
+ // Count the lines
+ const char* ptr = res.c_str();
+ while ( *ptr )
+ {
+ if ( *ptr == '\n' )
+ {
+ counter ++;
+ }
+ ++ptr;
+ }
+ counter ++;
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Number of lines: " << counter << std::endl);
+ char buffer[1024];
+ sprintf(buffer, "%d", counter);
+ cmSystemTools::ReplaceString(res, headerLengthTag, buffer);
+
+ // Write in file
+ *os << res;
+ return this->Superclass::GenerateHeader(os);
+}
diff --git a/Source/CPack/cmCPackSTGZGenerator.h b/Source/CPack/cmCPackSTGZGenerator.h
new file mode 100644
index 0000000000..ccceec8062
--- /dev/null
+++ b/Source/CPack/cmCPackSTGZGenerator.h
@@ -0,0 +1,41 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackSTGZGenerator_h
+#define cmCPackSTGZGenerator_h
+
+
+#include "cmCPackTGZGenerator.h"
+
+/** \class cmCPackSTGZGenerator
+ * \brief A generator for Self extractable TGZ files
+ *
+ */
+class cmCPackSTGZGenerator : public cmCPackTGZGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackSTGZGenerator, cmCPackTGZGenerator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackSTGZGenerator();
+ virtual ~cmCPackSTGZGenerator();
+
+protected:
+ int PackageFiles();
+ virtual int InitializeInternal();
+ int GenerateHeader(std::ostream* os);
+ virtual const char* GetOutputExtension() { return ".sh"; }
+};
+
+#endif
diff --git a/Source/CPack/cmCPackTGZGenerator.cxx b/Source/CPack/cmCPackTGZGenerator.cxx
new file mode 100644
index 0000000000..509c7f80a5
--- /dev/null
+++ b/Source/CPack/cmCPackTGZGenerator.cxx
@@ -0,0 +1,26 @@
+/*============================================================================
+ 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 "cmCPackTGZGenerator.h"
+
+//----------------------------------------------------------------------
+cmCPackTGZGenerator::cmCPackTGZGenerator()
+ :cmCPackArchiveGenerator(cmArchiveWrite::CompressGZip,
+ cmArchiveWrite::TypeTAR)
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackTGZGenerator::~cmCPackTGZGenerator()
+{
+}
+
diff --git a/Source/CPack/cmCPackTGZGenerator.h b/Source/CPack/cmCPackTGZGenerator.h
new file mode 100644
index 0000000000..3a9fc6b41c
--- /dev/null
+++ b/Source/CPack/cmCPackTGZGenerator.h
@@ -0,0 +1,35 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackTGZGenerator_h
+#define cmCPackTGZGenerator_h
+
+#include "cmCPackArchiveGenerator.h"
+
+/** \class cmCPackTGZGenerator
+ * \brief A generator for TGZ files
+ *
+ */
+class cmCPackTGZGenerator : public cmCPackArchiveGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackTGZGenerator, cmCPackArchiveGenerator);
+ /**
+ * Construct generator
+ */
+ cmCPackTGZGenerator();
+ virtual ~cmCPackTGZGenerator();
+protected:
+ virtual const char* GetOutputExtension() { return ".tar.gz"; }
+};
+
+#endif
diff --git a/Source/CPack/cmCPackTXZGenerator.cxx b/Source/CPack/cmCPackTXZGenerator.cxx
new file mode 100644
index 0000000000..ecfc177af4
--- /dev/null
+++ b/Source/CPack/cmCPackTXZGenerator.cxx
@@ -0,0 +1,25 @@
+/*============================================================================
+ 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 "cmCPackTXZGenerator.h"
+
+//----------------------------------------------------------------------
+cmCPackTXZGenerator::cmCPackTXZGenerator()
+ :cmCPackArchiveGenerator(cmArchiveWrite::CompressXZ,
+ cmArchiveWrite::TypeTAR)
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackTXZGenerator::~cmCPackTXZGenerator()
+{
+}
diff --git a/Source/CPack/cmCPackTXZGenerator.h b/Source/CPack/cmCPackTXZGenerator.h
new file mode 100644
index 0000000000..bf8152fccd
--- /dev/null
+++ b/Source/CPack/cmCPackTXZGenerator.h
@@ -0,0 +1,35 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackTXZGenerator_h
+#define cmCPackTXZGenerator_h
+
+#include "cmCPackArchiveGenerator.h"
+
+/** \class cmCPackTXZGenerator
+ * \brief A generator for TXZ files
+ *
+ */
+class cmCPackTXZGenerator : public cmCPackArchiveGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackTXZGenerator, cmCPackArchiveGenerator);
+ /**
+ * Construct generator
+ */
+ cmCPackTXZGenerator();
+ virtual ~cmCPackTXZGenerator();
+protected:
+ virtual const char* GetOutputExtension() { return ".tar.xz"; }
+};
+
+#endif
diff --git a/Source/CPack/cmCPackTarBZip2Generator.cxx b/Source/CPack/cmCPackTarBZip2Generator.cxx
new file mode 100644
index 0000000000..ae73c37952
--- /dev/null
+++ b/Source/CPack/cmCPackTarBZip2Generator.cxx
@@ -0,0 +1,25 @@
+/*============================================================================
+ 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 "cmCPackTarBZip2Generator.h"
+//----------------------------------------------------------------------
+cmCPackTarBZip2Generator::cmCPackTarBZip2Generator()
+ :cmCPackArchiveGenerator(cmArchiveWrite::CompressBZip2,
+ cmArchiveWrite::TypeTAR)
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackTarBZip2Generator::~cmCPackTarBZip2Generator()
+{
+}
+
diff --git a/Source/CPack/cmCPackTarBZip2Generator.h b/Source/CPack/cmCPackTarBZip2Generator.h
new file mode 100644
index 0000000000..74c244e5af
--- /dev/null
+++ b/Source/CPack/cmCPackTarBZip2Generator.h
@@ -0,0 +1,34 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackTarBZip2Generator_h
+#define cmCPackTarBZip2Generator_h
+
+#include "cmCPackArchiveGenerator.h"
+
+/** \class cmCPackTarBZip2Generator
+ * \brief A generator for TarBZip2 files
+ */
+class cmCPackTarBZip2Generator : public cmCPackArchiveGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackTarBZip2Generator, cmCPackArchiveGenerator);
+ /**
+ * Construct generator
+ */
+ cmCPackTarBZip2Generator();
+ virtual ~cmCPackTarBZip2Generator();
+protected:
+ virtual const char* GetOutputExtension() { return ".tar.bz2"; }
+};
+
+#endif
diff --git a/Source/CPack/cmCPackTarCompressGenerator.cxx b/Source/CPack/cmCPackTarCompressGenerator.cxx
new file mode 100644
index 0000000000..df294084c1
--- /dev/null
+++ b/Source/CPack/cmCPackTarCompressGenerator.cxx
@@ -0,0 +1,26 @@
+/*============================================================================
+ 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 "cmCPackTarCompressGenerator.h"
+
+//----------------------------------------------------------------------
+cmCPackTarCompressGenerator::cmCPackTarCompressGenerator()
+ :cmCPackArchiveGenerator(cmArchiveWrite::CompressCompress,
+ cmArchiveWrite::TypeTAR)
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackTarCompressGenerator::~cmCPackTarCompressGenerator()
+{
+}
+
diff --git a/Source/CPack/cmCPackTarCompressGenerator.h b/Source/CPack/cmCPackTarCompressGenerator.h
new file mode 100644
index 0000000000..7ff9a0ade5
--- /dev/null
+++ b/Source/CPack/cmCPackTarCompressGenerator.h
@@ -0,0 +1,35 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackTarCompressGenerator_h
+#define cmCPackTarCompressGenerator_h
+
+#include "cmCPackTGZGenerator.h"
+
+/** \class cmCPackTarCompressGenerator
+ * \brief A generator for TarCompress files
+ */
+class cmCPackTarCompressGenerator : public cmCPackArchiveGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackTarCompressGenerator, cmCPackArchiveGenerator);
+ /**
+ * Construct generator
+ */
+ cmCPackTarCompressGenerator();
+ virtual ~cmCPackTarCompressGenerator();
+
+protected:
+ virtual const char* GetOutputExtension() { return ".tar.Z"; }
+};
+
+#endif
diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx
new file mode 100644
index 0000000000..e6e4e77d05
--- /dev/null
+++ b/Source/CPack/cmCPackZIPGenerator.cxx
@@ -0,0 +1,26 @@
+/*============================================================================
+ 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 "cmCPackZIPGenerator.h"
+
+//----------------------------------------------------------------------
+cmCPackZIPGenerator::cmCPackZIPGenerator()
+ :cmCPackArchiveGenerator(cmArchiveWrite::CompressNone,
+ cmArchiveWrite::TypeZIP)
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackZIPGenerator::~cmCPackZIPGenerator()
+{
+}
+
diff --git a/Source/CPack/cmCPackZIPGenerator.h b/Source/CPack/cmCPackZIPGenerator.h
new file mode 100644
index 0000000000..70e1a5fa84
--- /dev/null
+++ b/Source/CPack/cmCPackZIPGenerator.h
@@ -0,0 +1,36 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCPackZIPGenerator_h
+#define cmCPackZIPGenerator_h
+
+#include "cmCPackArchiveGenerator.h"
+
+/** \class cmCPackZIPGenerator
+ * \brief A generator for ZIP files
+ */
+class cmCPackZIPGenerator : public cmCPackArchiveGenerator
+{
+public:
+ cmCPackTypeMacro(cmCPackZIPGenerator, cmCPackArchiveGenerator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackZIPGenerator();
+ virtual ~cmCPackZIPGenerator();
+
+protected:
+ virtual const char* GetOutputExtension() { return ".zip"; }
+};
+
+#endif
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx
new file mode 100644
index 0000000000..c57028ddd3
--- /dev/null
+++ b/Source/CPack/cpack.cxx
@@ -0,0 +1,486 @@
+/*============================================================================
+ 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 "cmSystemTools.h"
+
+// Need these for documentation support.
+#include "cmake.h"
+#include "cmDocumentation.h"
+#include "cmCPackGeneratorFactory.h"
+#include "cmCPackGenerator.h"
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+
+#include "cmCPackLog.h"
+
+#include <cmsys/CommandLineArguments.hxx>
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Encoding.hxx>
+#include <locale.h>
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationName[][2] =
+{
+ {0,
+ " cpack - Packaging driver provided by CMake."},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationUsage[][2] =
+{
+ {0,
+ " cpack -G <generator> [options]"},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationOptions[][2] =
+{
+ {"-G <generator>", "Use the specified generator to generate package."},
+ {"-C <Configuration>", "Specify the project configuration"},
+ {"-D <var>=<value>", "Set a CPack variable."},
+ {"--config <config file>", "Specify the config file."},
+ {"--verbose,-V","enable verbose output"},
+ {"--debug","enable debug output (for CPack developers)"},
+ {"-P <package name>","override/define CPACK_PACKAGE_NAME"},
+ {"-R <package version>","override/define CPACK_PACKAGE_VERSION"},
+ {"-B <package directory>","override/define CPACK_PACKAGE_DIRECTORY"},
+ {"--vendor <vendor name>","override/define CPACK_PACKAGE_VENDOR"},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+int cpackUnknownArgument(const char*, void*)
+{
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+struct cpackDefinitions
+{
+ typedef std::map<std::string, std::string> MapType;
+ MapType Map;
+ cmCPackLog *Log;
+};
+
+//----------------------------------------------------------------------------
+int cpackDefinitionArgument(const char* argument, const char* cValue,
+ void* call_data)
+{
+ (void)argument;
+ cpackDefinitions* def = static_cast<cpackDefinitions*>(call_data);
+ std::string value = cValue;
+ size_t pos = value.find_first_of("=");
+ if ( pos == std::string::npos )
+ {
+ cmCPack_Log(def->Log, cmCPackLog::LOG_ERROR,
+ "Please specify CPack definitions as: KEY=VALUE" << std::endl);
+ return 0;
+ }
+ std::string key = value.substr(0, pos);
+ value = value.c_str() + pos + 1;
+ def->Map[key] = value;
+ cmCPack_Log(def->Log, cmCPackLog::LOG_DEBUG, "Set CPack variable: "
+ << key << " to \"" << value << "\"" << std::endl);
+ return 1;
+}
+
+
+//----------------------------------------------------------------------------
+// this is CPack.
+int main (int argc, char const* const* argv)
+{
+ setlocale(LC_CTYPE, "");
+ cmsys::Encoding::CommandLineArguments args =
+ cmsys::Encoding::CommandLineArguments::Main(argc, argv);
+ argc = args.argc();
+ argv = args.argv();
+
+ cmSystemTools::FindCMakeResources(argv[0]);
+ cmCPackLog log;
+
+ log.SetErrorPrefix("CPack Error: ");
+ log.SetWarningPrefix("CPack Warning: ");
+ log.SetOutputPrefix("CPack: ");
+ log.SetVerbosePrefix("CPack Verbose: ");
+
+ cmSystemTools::EnableMSVCDebugHook();
+
+ if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Current working directory cannot be established." << std::endl);
+ return 1;
+ }
+
+ std::string generator;
+ bool help = false;
+ bool helpVersion = false;
+ bool verbose = false;
+ bool debug = false;
+ std::string helpFull;
+ std::string helpMAN;
+ std::string helpHTML;
+
+ std::string cpackProjectName;
+ std::string cpackProjectDirectory;
+ std::string cpackBuildConfig;
+ std::string cpackProjectVersion;
+ std::string cpackProjectPatch;
+ std::string cpackProjectVendor;
+ std::string cpackConfigFile;
+
+ cpackDefinitions definitions;
+ definitions.Log = &log;
+
+ cpackConfigFile = "";
+
+ cmsys::CommandLineArguments arg;
+ arg.Initialize(argc, argv);
+ typedef cmsys::CommandLineArguments argT;
+ // Help arguments
+ arg.AddArgument("--help", argT::NO_ARGUMENT, &help, "CPack help");
+ arg.AddArgument("--help-full", argT::SPACE_ARGUMENT, &helpFull,
+ "CPack help");
+ arg.AddArgument("--help-html", argT::SPACE_ARGUMENT, &helpHTML,
+ "CPack help");
+ arg.AddArgument("--help-man", argT::SPACE_ARGUMENT, &helpMAN, "CPack help");
+ arg.AddArgument("--version", argT::NO_ARGUMENT, &helpVersion, "CPack help");
+
+ arg.AddArgument("-V", argT::NO_ARGUMENT, &verbose, "CPack verbose");
+ arg.AddArgument("--verbose", argT::NO_ARGUMENT, &verbose, "-V");
+ arg.AddArgument("--debug", argT::NO_ARGUMENT, &debug, "-V");
+ arg.AddArgument("--config", argT::SPACE_ARGUMENT, &cpackConfigFile,
+ "CPack configuration file");
+ arg.AddArgument("-C", argT::SPACE_ARGUMENT, &cpackBuildConfig,
+ "CPack build configuration");
+ arg.AddArgument("-G", argT::SPACE_ARGUMENT,
+ &generator, "CPack generator");
+ arg.AddArgument("-P", argT::SPACE_ARGUMENT,
+ &cpackProjectName, "CPack project name");
+ arg.AddArgument("-R", argT::SPACE_ARGUMENT,
+ &cpackProjectVersion, "CPack project version");
+ arg.AddArgument("-B", argT::SPACE_ARGUMENT,
+ &cpackProjectDirectory, "CPack project directory");
+ arg.AddArgument("--patch", argT::SPACE_ARGUMENT,
+ &cpackProjectPatch, "CPack project patch");
+ arg.AddArgument("--vendor", argT::SPACE_ARGUMENT,
+ &cpackProjectVendor, "CPack project vendor");
+ arg.AddCallback("-D", argT::SPACE_ARGUMENT,
+ cpackDefinitionArgument, &definitions, "CPack Definitions");
+ arg.SetUnknownArgumentCallback(cpackUnknownArgument);
+
+ // Parse command line
+ int parsed = arg.Parse();
+
+ // Setup logging
+ if ( verbose )
+ {
+ log.SetVerbose(verbose);
+ cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Verbose" << std::endl);
+ }
+ if ( debug )
+ {
+ log.SetDebug(debug);
+ cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Debug" << std::endl);
+ }
+
+ cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
+ "Read CPack config file: " << cpackConfigFile << std::endl);
+
+ cmake cminst;
+ cminst.RemoveUnscriptableCommands();
+ cmGlobalGenerator cmgg;
+ cmgg.SetCMakeInstance(&cminst);
+ cmsys::auto_ptr<cmLocalGenerator> cmlg(cmgg.CreateLocalGenerator());
+ cmMakefile* globalMF = cmlg->GetMakefile();
+
+ bool cpackConfigFileSpecified = true;
+ if ( cpackConfigFile.empty() )
+ {
+ cpackConfigFile = cmSystemTools::GetCurrentWorkingDirectory();
+ cpackConfigFile += "/CPackConfig.cmake";
+ cpackConfigFileSpecified = false;
+ }
+
+ cmCPackGeneratorFactory generators;
+ generators.SetLogger(&log);
+ cmCPackGenerator* cpackGenerator = 0;
+
+ cmDocumentation doc;
+ doc.addCPackStandardDocSections();
+ /* Were we invoked to display doc or to do some work ?
+ * Unlike cmake launching cpack with zero argument
+ * should launch cpack using "cpackConfigFile" if it exists
+ * in the current directory.
+ */
+ if((doc.CheckOptions(argc, argv,"-G")) && !(argc==1))
+ {
+ help = true;
+ }
+ else
+ {
+ help = false;
+ }
+
+ // This part is used for cpack documentation lookup as well.
+ cminst.AddCMakePaths();
+
+ if ( parsed && !help )
+ {
+ // find out which system cpack is running on, so it can setup the search
+ // paths, so FIND_XXX() commands can be used in scripts
+ std::string systemFile =
+ globalMF->GetModulesFile("CMakeDetermineSystem.cmake");
+ if (!globalMF->ReadListFile(0, systemFile.c_str()))
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Error reading CMakeDetermineSystem.cmake" << std::endl);
+ return 1;
+ }
+
+ systemFile =
+ globalMF->GetModulesFile("CMakeSystemSpecificInformation.cmake");
+ if (!globalMF->ReadListFile(0, systemFile.c_str()))
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Error reading CMakeSystemSpecificInformation.cmake" << std::endl);
+ return 1;
+ }
+
+ if ( !cpackBuildConfig.empty() )
+ {
+ globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
+ }
+
+ if ( cmSystemTools::FileExists(cpackConfigFile.c_str()) )
+ {
+ cpackConfigFile =
+ cmSystemTools::CollapseFullPath(cpackConfigFile.c_str());
+ cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
+ "Read CPack configuration file: " << cpackConfigFile
+ << std::endl);
+ if ( !globalMF->ReadListFile(0, cpackConfigFile.c_str()) )
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Problem reading CPack config file: \""
+ << cpackConfigFile << "\"" << std::endl);
+ return 1;
+ }
+ }
+ else if ( cpackConfigFileSpecified )
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Cannot find CPack config file: \"" <<
+ cpackConfigFile << "\"" << std::endl);
+ return 1;
+ }
+
+ if ( !generator.empty() )
+ {
+ globalMF->AddDefinition("CPACK_GENERATOR", generator.c_str());
+ }
+ if ( !cpackProjectName.empty() )
+ {
+ globalMF->AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str());
+ }
+ if ( !cpackProjectVersion.empty() )
+ {
+ globalMF->AddDefinition("CPACK_PACKAGE_VERSION",
+ cpackProjectVersion.c_str());
+ }
+ if ( !cpackProjectVendor.empty() )
+ {
+ globalMF->AddDefinition("CPACK_PACKAGE_VENDOR",
+ cpackProjectVendor.c_str());
+ }
+ // if this is not empty it has been set on the command line
+ // go for it. Command line override values set in config file.
+ if ( !cpackProjectDirectory.empty() )
+ {
+ globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY",
+ cpackProjectDirectory.c_str());
+ }
+ // The value has not been set on the command line
+ else
+ {
+ // get a default value (current working directory)
+ cpackProjectDirectory = cmsys::SystemTools::GetCurrentWorkingDirectory();
+ // use default value iff no value has been provided by the config file
+ if (!globalMF->IsSet("CPACK_PACKAGE_DIRECTORY"))
+ {
+ globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY",
+ cpackProjectDirectory.c_str());
+ }
+ }
+ cpackDefinitions::MapType::iterator cdit;
+ for ( cdit = definitions.Map.begin();
+ cdit != definitions.Map.end();
+ ++cdit )
+ {
+ globalMF->AddDefinition(cdit->first, cdit->second.c_str());
+ }
+
+ const char* cpackModulesPath =
+ globalMF->GetDefinition("CPACK_MODULE_PATH");
+ if ( cpackModulesPath )
+ {
+ globalMF->AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath);
+ }
+ const char* genList = globalMF->GetDefinition("CPACK_GENERATOR");
+ if ( !genList )
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "CPack generator not specified" << std::endl);
+ }
+ else
+ {
+ std::vector<std::string> generatorsVector;
+ cmSystemTools::ExpandListArgument(genList,
+ generatorsVector);
+ std::vector<std::string>::iterator it;
+ for ( it = generatorsVector.begin();
+ it != generatorsVector.end();
+ ++it )
+ {
+ const char* gen = it->c_str();
+ cmMakefile newMF(*globalMF);
+ cmMakefile* mf = &newMF;
+ cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
+ "Specified generator: " << gen << std::endl);
+ if ( parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME") )
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "CPack project name not specified" << std::endl);
+ parsed = 0;
+ }
+ if (parsed &&
+ !(mf->GetDefinition("CPACK_PACKAGE_VERSION") ||
+ (mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR") &&
+ mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR") &&
+ mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"))))
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "CPack project version not specified" << std::endl
+ << "Specify CPACK_PACKAGE_VERSION, or "
+ "CPACK_PACKAGE_VERSION_MAJOR, "
+ "CPACK_PACKAGE_VERSION_MINOR, and CPACK_PACKAGE_VERSION_PATCH."
+ << std::endl);
+ parsed = 0;
+ }
+ if ( parsed )
+ {
+ cpackGenerator = generators.NewGenerator(gen);
+ if ( !cpackGenerator )
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Cannot initialize CPack generator: "
+ << gen << std::endl);
+ parsed = 0;
+ }
+ if ( parsed && !cpackGenerator->Initialize(gen, mf) )
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Cannot initialize the generator " << gen << std::endl);
+ parsed = 0;
+ }
+
+ if ( !mf->GetDefinition("CPACK_INSTALL_COMMANDS") &&
+ !mf->GetDefinition("CPACK_INSTALLED_DIRECTORIES") &&
+ !mf->GetDefinition("CPACK_INSTALL_CMAKE_PROJECTS") )
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Please specify build tree of the project that uses CMake "
+ "using CPACK_INSTALL_CMAKE_PROJECTS, specify "
+ "CPACK_INSTALL_COMMANDS, or specify "
+ "CPACK_INSTALLED_DIRECTORIES."
+ << std::endl);
+ parsed = 0;
+ }
+ if ( parsed )
+ {
+ const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME");
+ cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: "
+ << cpackGenerator->GetNameOfClass() << std::endl);
+ cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: "
+ << projName << std::endl);
+
+ const char* projVersion =
+ mf->GetDefinition("CPACK_PACKAGE_VERSION");
+ if ( !projVersion )
+ {
+ const char* projVersionMajor
+ = mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR");
+ const char* projVersionMinor
+ = mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR");
+ const char* projVersionPatch
+ = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH");
+ cmOStringStream ostr;
+ ostr << projVersionMajor << "." << projVersionMinor << "."
+ << projVersionPatch;
+ mf->AddDefinition("CPACK_PACKAGE_VERSION",
+ ostr.str().c_str());
+ }
+
+ int res = cpackGenerator->DoPackage();
+ if ( !res )
+ {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Error when generating package: " << projName << std::endl);
+ return 1;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* In this case we are building the documentation object
+ * instance in order to create appropriate structure
+ * in order to satisfy the appropriate --help-xxx request
+ */
+ if ( help )
+ {
+ // Construct and print requested documentation.
+
+ doc.SetName("cpack");
+ doc.SetSection("Name",cmDocumentationName);
+ doc.SetSection("Usage",cmDocumentationUsage);
+ doc.PrependSection("Options",cmDocumentationOptions);
+
+ std::vector<cmDocumentationEntry> v;
+ cmCPackGeneratorFactory::DescriptionsMap::const_iterator generatorIt;
+ for( generatorIt = generators.GetGeneratorsList().begin();
+ generatorIt != generators.GetGeneratorsList().end();
+ ++ generatorIt )
+ {
+ cmDocumentationEntry e;
+ e.Name = generatorIt->first.c_str();
+ e.Brief = generatorIt->second.c_str();
+ v.push_back(e);
+ }
+ doc.SetSection("Generators",v);
+
+#undef cout
+ return doc.PrintRequestedDocumentation(std::cout)? 0:1;
+#define cout no_cout_use_cmCPack_Log
+ }
+
+ if (cmSystemTools::GetErrorOccuredFlag())
+ {
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/Source/CPack/cygwin.readme b/Source/CPack/cygwin.readme
new file mode 100644
index 0000000000..c0cd4b9136
--- /dev/null
+++ b/Source/CPack/cygwin.readme
@@ -0,0 +1,69 @@
+http://cygwin.com/setup.html
+
+
+Need to produce two tar files:
+
+Source-
+
+- create subdirs
+- copy src
+- duplicate src
+- configure files into duplicate src
+ CPack.cygwin-readme.in
+ CPack.cygwin-install.sh.in
+ CPack.setup.hint.in
+- diff duplicate src and orig src
+- write diff into toplevel
+- create tar file call super class
+
+cmake-2.2.3-1
+
+
+1. a source release
+cmake-2.2.3-2-src.tar.bz2
+
+cmake-2.2.3-2.patch has cmake-2.2.3/CYGWIN-PATCHES/cmake.README cmake-2.2.3/CYGWIN-PATCHES/setup.hint
+cmake-2.2.3-2.sh -> script to create cygwin release
+cmake-2.2.3.tar.bz2 -> unmodified cmake sources for 2.2.3
+
+
+
+
+
+2 a binary release
+cmake-2.2.3-2.tar.bz2
+
+normal binary release with use as the root of the tree:
+
+Here is the bootstrap command used:
+
+ ${SOURCE_DIR}/bootstrap --prefix=/usr --datadir=/share/cmake-${VER} \
+ --docdir=/share/doc/cmake-${VER} --mandir=/share/man
+
+CMAKE_DOC_DIR /share/doc/${PKG}-${VER}
+CMAKE_MAN_DIR /share/man
+CMAKE_DATA_DIR /share/${PKG}-${VER}
+
+Here is the directory stucture:
+
+usr/bin/cmake.exe
+usr/share/doc/cmake-2.2.3/MANIFEST ***
+usr/share/doc/Cygwin/cmake-2.2.3-2.README ****
+usr/share/cmake-2.2.3/Modules
+
+
+
+usr/bin
+usr/share/cmake-2.2.3/include
+usr/share/cmake-2.2.3/Modules/Platform
+usr/share/cmake-2.2.3/Modules
+usr/share/cmake-2.2.3/Templates
+usr/share/cmake-2.2.3
+usr/share/doc/cmake-2.2.3
+usr/share/doc/Cygwin
+usr/share/doc
+usr/share/man/man1
+usr/share/man
+usr/share
+usr
+
diff --git a/Source/CTest/cmCTestBZR.cxx b/Source/CTest/cmCTestBZR.cxx
new file mode 100644
index 0000000000..3014a9322f
--- /dev/null
+++ b/Source/CTest/cmCTestBZR.cxx
@@ -0,0 +1,523 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestBZR.h"
+
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include "cmXMLParser.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+#include <cm_expat.h>
+
+//----------------------------------------------------------------------------
+extern "C"
+int cmBZRXMLParserUnknownEncodingHandler(void*,
+ const XML_Char *name,
+ XML_Encoding *info)
+{
+ static const int latin1[]=
+ {
+ 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
+ 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
+ 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
+ 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
+ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
+ 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
+ 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
+ 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
+ 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
+ 0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008D, 0x017D, 0x008F,
+ 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x009D, 0x017E, 0x0178,
+ 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
+ 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
+ 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
+ 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
+ 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
+ 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
+ 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
+ 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
+ };
+
+ // The BZR xml output plugin can use some encodings that are not
+ // recognized by expat. This will lead to an error, e.g. "Error
+ // parsing bzr log xml: unknown encoding", the following is a
+ // workaround for these unknown encodings.
+ if(name == std::string("ascii") || name == std::string("cp1252") ||
+ name == std::string("ANSI_X3.4-1968"))
+ {
+ for(unsigned int i=0;i<256;++i) info->map[i] = latin1[i];
+ return 1;
+ }
+
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+cmCTestBZR::cmCTestBZR(cmCTest* ct, std::ostream& log):
+ cmCTestGlobalVC(ct, log)
+{
+ this->PriorRev = this->Unknown;
+ // Even though it is specified in the documention, with bzr 1.13
+ // BZR_PROGRESS_BAR has no effect. In the future this bug might be fixed.
+ // Since it doesn't hurt, we specify this environment variable.
+ cmSystemTools::PutEnv("BZR_PROGRESS_BAR=none");
+}
+
+//----------------------------------------------------------------------------
+cmCTestBZR::~cmCTestBZR()
+{
+}
+
+//----------------------------------------------------------------------------
+class cmCTestBZR::InfoParser: public cmCTestVC::LineParser
+{
+public:
+ InfoParser(cmCTestBZR* bzr, const char* prefix):
+ BZR(bzr), CheckOutFound(false)
+ {
+ this->SetLog(&bzr->Log, prefix);
+ this->RegexCheckOut.compile("checkout of branch: *([^\t\r\n]+)$");
+ this->RegexParent.compile("parent branch: *([^\t\r\n]+)$");
+ }
+private:
+ cmCTestBZR* BZR;
+ bool CheckOutFound;
+ cmsys::RegularExpression RegexCheckOut;
+ cmsys::RegularExpression RegexParent;
+ virtual bool ProcessLine()
+ {
+ if(this->RegexCheckOut.find(this->Line))
+ {
+ this->BZR->URL = this->RegexCheckOut.match(1);
+ CheckOutFound = true;
+ }
+ else if(!CheckOutFound && this->RegexParent.find(this->Line))
+ {
+ this->BZR->URL = this->RegexParent.match(1);
+ }
+ return true;
+ }
+};
+
+//----------------------------------------------------------------------------
+class cmCTestBZR::RevnoParser: public cmCTestVC::LineParser
+{
+public:
+ RevnoParser(cmCTestBZR* bzr, const char* prefix, std::string& rev):
+ Rev(rev)
+ {
+ this->SetLog(&bzr->Log, prefix);
+ this->RegexRevno.compile("^([0-9]+)$");
+ }
+private:
+ std::string& Rev;
+ cmsys::RegularExpression RegexRevno;
+ virtual bool ProcessLine()
+ {
+ if(this->RegexRevno.find(this->Line))
+ {
+ this->Rev = this->RegexRevno.match(1);
+ }
+ return true;
+ }
+};
+
+//----------------------------------------------------------------------------
+std::string cmCTestBZR::LoadInfo()
+{
+ // Run "bzr info" to get the repository info from the work tree.
+ const char* bzr = this->CommandLineTool.c_str();
+ const char* bzr_info[] = {bzr, "info", 0};
+ InfoParser iout(this, "info-out> ");
+ OutputLogger ierr(this->Log, "info-err> ");
+ this->RunChild(bzr_info, &iout, &ierr);
+
+ // Run "bzr revno" to get the repository revision number from the work tree.
+ const char* bzr_revno[] = {bzr, "revno", 0};
+ std::string rev;
+ RevnoParser rout(this, "revno-out> ", rev);
+ OutputLogger rerr(this->Log, "revno-err> ");
+ this->RunChild(bzr_revno, &rout, &rerr);
+
+ return rev;
+}
+
+void cmCTestBZR::NoteOldRevision()
+{
+ this->OldRevision = this->LoadInfo();
+ this->Log << "Revision before update: " << this->OldRevision << "\n";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
+ << this->OldRevision << "\n");
+ this->PriorRev.Rev = this->OldRevision;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestBZR::NoteNewRevision()
+{
+ this->NewRevision = this->LoadInfo();
+ this->Log << "Revision after update: " << this->NewRevision << "\n";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
+ << this->NewRevision << "\n");
+ this->Log << "URL = " << this->URL << "\n";
+}
+
+//----------------------------------------------------------------------------
+class cmCTestBZR::LogParser: public cmCTestVC::OutputLogger,
+ private cmXMLParser
+{
+public:
+ LogParser(cmCTestBZR* bzr, const char* prefix):
+ OutputLogger(bzr->Log, prefix), BZR(bzr),
+ EmailRegex("(.*) <([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+)>")
+ { this->InitializeParser(); }
+ ~LogParser() { this->CleanupParser(); }
+
+ virtual int InitializeParser()
+ {
+ int res = cmXMLParser::InitializeParser();
+ if (res)
+ {
+ XML_SetUnknownEncodingHandler(static_cast<XML_Parser>(this->Parser),
+ cmBZRXMLParserUnknownEncodingHandler, 0);
+ }
+ return res;
+ }
+private:
+ cmCTestBZR* BZR;
+
+ typedef cmCTestBZR::Revision Revision;
+ typedef cmCTestBZR::Change Change;
+ Revision Rev;
+ std::vector<Change> Changes;
+ Change CurChange;
+ std::vector<char> CData;
+
+ cmsys::RegularExpression EmailRegex;
+
+ virtual bool ProcessChunk(const char* data, int length)
+ {
+ this->OutputLogger::ProcessChunk(data, length);
+ this->ParseChunk(data, length);
+ return true;
+ }
+
+ virtual void StartElement(const std::string& name, const char**)
+ {
+ this->CData.clear();
+ if(name == "log")
+ {
+ this->Rev = Revision();
+ this->Changes.clear();
+ }
+ // affected-files can contain blocks of
+ // modified, unknown, renamed, kind-changed, removed, conflicts, added
+ else if(name == "modified"
+ || name == "renamed"
+ || name == "kind-changed")
+ {
+ this->CurChange = Change();
+ this->CurChange.Action = 'M';
+ }
+ else if(name == "added")
+ {
+ this->CurChange = Change();
+ this->CurChange = 'A';
+ }
+ else if(name == "removed")
+ {
+ this->CurChange = Change();
+ this->CurChange = 'D';
+ }
+ else if(name == "unknown"
+ || name == "conflicts")
+ {
+ // Should not happen here
+ this->CurChange = Change();
+ }
+ }
+
+ virtual void CharacterDataHandler(const char* data, int length)
+ {
+ this->CData.insert(this->CData.end(), data, data+length);
+ }
+
+ virtual void EndElement(const std::string& name)
+ {
+ if(name == "log")
+ {
+ this->BZR->DoRevision(this->Rev, this->Changes);
+ }
+ else if(!this->CData.empty() &&
+ (name == "file" || name == "directory"))
+ {
+ this->CurChange.Path.assign(&this->CData[0], this->CData.size());
+ cmSystemTools::ConvertToUnixSlashes(this->CurChange.Path);
+ this->Changes.push_back(this->CurChange);
+ }
+ else if(!this->CData.empty() && name == "symlink")
+ {
+ // symlinks have an arobase at the end in the log
+ this->CurChange.Path.assign(&this->CData[0], this->CData.size()-1);
+ cmSystemTools::ConvertToUnixSlashes(this->CurChange.Path);
+ this->Changes.push_back(this->CurChange);
+ }
+ else if(!this->CData.empty() && name == "committer")
+ {
+ this->Rev.Author.assign(&this->CData[0], this->CData.size());
+ if(this->EmailRegex.find(this->Rev.Author))
+ {
+ this->Rev.Author = this->EmailRegex.match(1);
+ this->Rev.EMail = this->EmailRegex.match(2);
+ }
+ }
+ else if(!this->CData.empty() && name == "timestamp")
+ {
+ this->Rev.Date.assign(&this->CData[0], this->CData.size());
+ }
+ else if(!this->CData.empty() && name == "message")
+ {
+ this->Rev.Log.assign(&this->CData[0], this->CData.size());
+ }
+ else if(!this->CData.empty() && name == "revno")
+ {
+ this->Rev.Rev.assign(&this->CData[0], this->CData.size());
+ }
+ this->CData.clear();
+ }
+
+ virtual void ReportError(int, int, const char* msg)
+ {
+ this->BZR->Log << "Error parsing bzr log xml: " << msg << "\n";
+ }
+};
+
+//----------------------------------------------------------------------------
+class cmCTestBZR::UpdateParser: public cmCTestVC::LineParser
+{
+public:
+ UpdateParser(cmCTestBZR* bzr, const char* prefix): BZR(bzr)
+ {
+ this->SetLog(&bzr->Log, prefix);
+ this->RegexUpdate.compile("^([-+R?XCP ])([NDKM ])([* ]) +(.+)$");
+ }
+private:
+ cmCTestBZR* BZR;
+ cmsys::RegularExpression RegexUpdate;
+
+ virtual bool ProcessChunk(const char* first, int length)
+ {
+ bool last_is_new_line = (*first == '\r' || *first == '\n');
+
+ const char* const last = first + length;
+ for(const char* c = first; c != last; ++c)
+ {
+ if(*c == '\r' || *c == '\n')
+ {
+ if(!last_is_new_line)
+ {
+ // Log this line.
+ if(this->Log && this->Prefix)
+ {
+ *this->Log << this->Prefix << this->Line << "\n";
+ }
+
+ // Hand this line to the subclass implementation.
+ if(!this->ProcessLine())
+ {
+ this->Line = "";
+ return false;
+ }
+
+ this->Line = "";
+ last_is_new_line = true;
+ }
+ }
+ else
+ {
+ // Append this character to the line under construction.
+ this->Line.append(1, *c);
+ last_is_new_line = false;
+ }
+ }
+ return true;
+ }
+
+ bool ProcessLine()
+ {
+ if(this->RegexUpdate.find(this->Line))
+ {
+ this->DoPath(this->RegexUpdate.match(1)[0],
+ this->RegexUpdate.match(2)[0],
+ this->RegexUpdate.match(3)[0],
+ this->RegexUpdate.match(4));
+ }
+ return true;
+ }
+
+ void DoPath(char c0, char c1, char c2, std::string path)
+ {
+ if(path.empty()) return;
+ cmSystemTools::ConvertToUnixSlashes(path);
+
+ const std::string dir = cmSystemTools::GetFilenamePath(path);
+ const std::string name = cmSystemTools::GetFilenameName(path);
+
+ if ( c0=='C' )
+ {
+ this->BZR->Dirs[dir][name].Status = PathConflicting;
+ return;
+ }
+
+ if ( c1=='M' || c1=='K' || c1=='N' || c1=='D' || c2 =='*' )
+ {
+ this->BZR->Dirs[dir][name].Status = PathUpdated;
+ return;
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+bool cmCTestBZR::UpdateImpl()
+{
+ // Get user-specified update options.
+ std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
+ if(opts.empty())
+ {
+ opts = this->CTest->GetCTestConfiguration("BZRUpdateOptions");
+ }
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
+
+ // TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY)
+
+ // Use "bzr pull" to update the working tree.
+ std::vector<char const*> bzr_update;
+ bzr_update.push_back(this->CommandLineTool.c_str());
+ bzr_update.push_back("pull");
+
+ for(std::vector<std::string>::const_iterator ai = args.begin();
+ ai != args.end(); ++ai)
+ {
+ bzr_update.push_back(ai->c_str());
+ }
+
+ bzr_update.push_back(this->URL.c_str());
+
+ bzr_update.push_back(0);
+
+ // For some reason bzr uses stderr to display the update status.
+ OutputLogger out(this->Log, "pull-out> ");
+ UpdateParser err(this, "pull-err> ");
+ return this->RunUpdateCommand(&bzr_update[0], &out, &err);
+}
+
+//----------------------------------------------------------------------------
+void cmCTestBZR::LoadRevisions()
+{
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Gathering version information (one . per revision):\n"
+ " " << std::flush);
+
+ // We are interested in every revision included in the update.
+ this->Revisions.clear();
+ std::string revs;
+ if(atoi(this->OldRevision.c_str()) <= atoi(this->NewRevision.c_str()))
+ {
+ // DoRevision takes care of discarding the information about OldRevision
+ revs = this->OldRevision + ".." + this->NewRevision;
+ }
+ else
+ {
+ return;
+ }
+
+ // Run "bzr log" to get all global revisions of interest.
+ const char* bzr = this->CommandLineTool.c_str();
+ const char* bzr_log[] = {bzr, "log", "-v", "-r", revs.c_str(), "--xml",
+ this->URL.c_str(), 0};
+ {
+ LogParser out(this, "log-out> ");
+ OutputLogger err(this->Log, "log-err> ");
+ this->RunChild(bzr_log, &out, &err);
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
+}
+
+//----------------------------------------------------------------------------
+class cmCTestBZR::StatusParser: public cmCTestVC::LineParser
+{
+public:
+ StatusParser(cmCTestBZR* bzr, const char* prefix): BZR(bzr)
+ {
+ this->SetLog(&bzr->Log, prefix);
+ this->RegexStatus.compile("^([-+R?XCP ])([NDKM ])([* ]) +(.+)$");
+ }
+private:
+ cmCTestBZR* BZR;
+ cmsys::RegularExpression RegexStatus;
+ bool ProcessLine()
+ {
+ if(this->RegexStatus.find(this->Line))
+ {
+ this->DoPath(this->RegexStatus.match(1)[0],
+ this->RegexStatus.match(2)[0],
+ this->RegexStatus.match(3)[0],
+ this->RegexStatus.match(4));
+ }
+ return true;
+ }
+
+ void DoPath(char c0, char c1, char c2, std::string path)
+ {
+ if(path.empty()) return;
+ cmSystemTools::ConvertToUnixSlashes(path);
+
+ if ( c0=='C' )
+ {
+ this->BZR->DoModification(PathConflicting, path);
+ return;
+ }
+
+ if ( c0 == '+' || c0 == 'R' || c0 == 'P'
+ || c1=='M' || c1=='K' || c1=='N' || c1=='D'
+ || c2 =='*' )
+ {
+ this->BZR->DoModification(PathModified, path);
+ return;
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmCTestBZR::LoadModifications()
+{
+ // Run "bzr status" which reports local modifications.
+ const char* bzr = this->CommandLineTool.c_str();
+ const char* bzr_status[] = {bzr, "status", "-SV", 0};
+ StatusParser out(this, "status-out> ");
+ OutputLogger err(this->Log, "status-err> ");
+ this->RunChild(bzr_status, &out, &err);
+}
diff --git a/Source/CTest/cmCTestBZR.h b/Source/CTest/cmCTestBZR.h
new file mode 100644
index 0000000000..df688e1eea
--- /dev/null
+++ b/Source/CTest/cmCTestBZR.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestBZR_h
+#define cmCTestBZR_h
+
+#include "cmCTestGlobalVC.h"
+
+/** \class cmCTestBZR
+ * \brief Interaction with bzr command-line tool
+ *
+ */
+class cmCTestBZR: public cmCTestGlobalVC
+{
+public:
+ /** Construct with a CTest instance and update log stream. */
+ cmCTestBZR(cmCTest* ctest, std::ostream& log);
+
+ virtual ~cmCTestBZR();
+
+private:
+ // Implement cmCTestVC internal API.
+ virtual void NoteOldRevision();
+ virtual void NoteNewRevision();
+ virtual bool UpdateImpl();
+
+ // URL of repository directory checked out in the working tree.
+ std::string URL;
+
+ std::string LoadInfo();
+ void LoadModifications();
+ void LoadRevisions();
+
+ // Parsing helper classes.
+ class InfoParser;
+ class RevnoParser;
+ class LogParser;
+ class UpdateParser;
+ class StatusParser;
+ friend class InfoParser;
+ friend class RevnoParser;
+ friend class LogParser;
+ friend class UpdateParser;
+ friend class StatusParser;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestBatchTestHandler.cxx b/Source/CTest/cmCTestBatchTestHandler.cxx
new file mode 100644
index 0000000000..7f966aa65d
--- /dev/null
+++ b/Source/CTest/cmCTestBatchTestHandler.cxx
@@ -0,0 +1,143 @@
+/*============================================================================
+ 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 "cmCTestBatchTestHandler.h"
+#include "cmProcess.h"
+#include "cmStandardIncludes.h"
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include <stdlib.h>
+
+cmCTestBatchTestHandler::~cmCTestBatchTestHandler()
+{
+}
+
+//---------------------------------------------------------
+void cmCTestBatchTestHandler::RunTests()
+{
+ this->WriteBatchScript();
+ this->SubmitBatchScript();
+}
+
+//---------------------------------------------------------
+void cmCTestBatchTestHandler::WriteBatchScript()
+{
+ this->Script = this->CTest->GetBinaryDir()
+ + "/Testing/CTestBatch.txt";
+ cmsys::ofstream fout;
+ fout.open(this->Script.c_str());
+ fout << "#!/bin/sh\n";
+
+ for(TestMap::iterator i = this->Tests.begin(); i != this->Tests.end(); ++i)
+ {
+ this->WriteSrunArgs(i->first, fout);
+ this->WriteTestCommand(i->first, fout);
+ fout << "\n";
+ }
+ fout.flush();
+ fout.close();
+}
+
+//---------------------------------------------------------
+void cmCTestBatchTestHandler::WriteSrunArgs(int test, cmsys::ofstream& fout)
+{
+ cmCTestTestHandler::cmCTestTestProperties* properties =
+ this->Properties[test];
+
+ fout << "srun ";
+ //fout << "--jobid=" << test << " ";
+ fout << "-J=" << properties->Name << " ";
+
+ //Write dependency information
+ /*if(this->Tests[test].size() > 0)
+ {
+ fout << "-P=afterany";
+ for(TestSet::iterator i = this->Tests[test].begin();
+ i != this->Tests[test].end(); ++i)
+ {
+ fout << ":" << *i;
+ }
+ fout << " ";
+ }*/
+ if(properties->RunSerial)
+ {
+ fout << "--exclusive ";
+ }
+ if(properties->Processors > 1)
+ {
+ fout << "-n" << properties->Processors << " ";
+ }
+}
+
+//---------------------------------------------------------
+void cmCTestBatchTestHandler::WriteTestCommand(int test, cmsys::ofstream& fout)
+{
+ std::vector<std::string> args = this->Properties[test]->Args;
+ std::vector<std::string> processArgs;
+ std::string command;
+
+ command = this->TestHandler->FindTheExecutable(args[1].c_str());
+ command = cmSystemTools::ConvertToOutputPath(command.c_str());
+
+ //Prepends memcheck args to our command string if this is a memcheck
+ this->TestHandler->GenerateTestCommand(processArgs, test);
+ processArgs.push_back(command);
+
+ for(std::vector<std::string>::iterator arg = processArgs.begin();
+ arg != processArgs.end(); ++arg)
+ {
+ fout << *arg << " ";
+ }
+
+ std::vector<std::string>::iterator i = args.begin();
+ ++i; //the test name
+ ++i; //the executable (command)
+ if(args.size() > 2)
+ {
+ fout << "'";
+ }
+ while(i != args.end())
+ {
+ fout << "\"" << *i << "\""; //args to the test executable
+ ++i;
+
+ if(i == args.end() && args.size() > 2)
+ {
+ fout << "'";
+ }
+ fout << " ";
+ }
+ //TODO ZACH build TestResult.FullCommandLine
+ //this->TestResult.FullCommandLine = this->TestCommand;
+}
+
+//---------------------------------------------------------
+void cmCTestBatchTestHandler::SubmitBatchScript()
+{
+ cmProcess sbatch;
+ std::vector<std::string> args;
+ args.push_back(this->Script);
+ args.push_back("-o");
+ args.push_back(this->CTest->GetBinaryDir()
+ + "/Testing/CTestBatch.txt");
+
+ sbatch.SetCommand("sbatch");
+ sbatch.SetCommandArguments(args);
+ /*if(sbatch.StartProcess())
+ {
+ //success condition
+ }
+ else
+ {
+ //fail condition
+ }*/
+}
diff --git a/Source/CTest/cmCTestBatchTestHandler.h b/Source/CTest/cmCTestBatchTestHandler.h
new file mode 100644
index 0000000000..e0c6e48d52
--- /dev/null
+++ b/Source/CTest/cmCTestBatchTestHandler.h
@@ -0,0 +1,42 @@
+/*============================================================================
+ 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 cmCTestBatchTestHandler_h
+#define cmCTestBatchTestHandler_h
+
+#include <cmStandardIncludes.h>
+#include <cmCTestTestHandler.h>
+#include <cmCTestMultiProcessHandler.h>
+#include <cmCTestRunTest.h>
+#include <cmsys/FStream.hxx>
+
+/** \class cmCTestBatchTestHandler
+ * \brief run parallel ctest
+ *
+ * cmCTestBatchTestHandler
+ */
+class cmCTestBatchTestHandler : public cmCTestMultiProcessHandler
+{
+public:
+ ~cmCTestBatchTestHandler();
+ virtual void RunTests();
+protected:
+ void WriteBatchScript();
+ void WriteSrunArgs(int test, cmsys::ofstream& fout);
+ void WriteTestCommand(int test, cmsys::ofstream& fout);
+
+ void SubmitBatchScript();
+
+ std::string Script;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx
new file mode 100644
index 0000000000..41db042a84
--- /dev/null
+++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx
@@ -0,0 +1,555 @@
+/*============================================================================
+ 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 "cmCTestBuildAndTestHandler.h"
+
+#include "cmSystemTools.h"
+#include "cmCTest.h"
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include <cmsys/Process.h>
+#include "cmCTestTestHandler.h"
+#include "cmCacheManager.h"
+
+//----------------------------------------------------------------------
+cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
+{
+ this->BuildTwoConfig = false;
+ this->BuildNoClean = false;
+ this->BuildNoCMake = false;
+ this->Timeout = 0;
+}
+
+//----------------------------------------------------------------------
+void cmCTestBuildAndTestHandler::Initialize()
+{
+ this->BuildTargets.erase(
+ this->BuildTargets.begin(), this->BuildTargets.end());
+ this->Superclass::Initialize();
+}
+
+//----------------------------------------------------------------------
+const char* cmCTestBuildAndTestHandler::GetOutput()
+{
+ return this->Output.c_str();
+}
+//----------------------------------------------------------------------
+int cmCTestBuildAndTestHandler::ProcessHandler()
+{
+ this->Output = "";
+ std::string output;
+ cmSystemTools::ResetErrorOccuredFlag();
+ int retv = this->RunCMakeAndTest(&this->Output);
+ cmSystemTools::ResetErrorOccuredFlag();
+ return retv;
+}
+
+//----------------------------------------------------------------------
+int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
+ cmOStringStream &out, std::string &cmakeOutString, std::string &cwd,
+ cmake *cm)
+{
+ unsigned int k;
+ std::vector<std::string> args;
+ args.push_back(cmSystemTools::GetCMakeCommand());
+ args.push_back(this->SourceDir);
+ if(this->BuildGenerator.size())
+ {
+ std::string generator = "-G";
+ generator += this->BuildGenerator;
+ args.push_back(generator);
+ }
+ if(!this->BuildGeneratorPlatform.empty())
+ {
+ std::string platform = "-A";
+ platform += this->BuildGeneratorPlatform;
+ args.push_back(platform);
+ }
+ if(this->BuildGeneratorToolset.size())
+ {
+ std::string toolset = "-T";
+ toolset += this->BuildGeneratorToolset;
+ args.push_back(toolset);
+ }
+
+ const char* config = 0;
+ if ( this->CTest->GetConfigType().size() > 0 )
+ {
+ config = this->CTest->GetConfigType().c_str();
+ }
+#ifdef CMAKE_INTDIR
+ if(!config)
+ {
+ config = CMAKE_INTDIR;
+ }
+#endif
+
+ if ( config )
+ {
+ std::string btype
+ = "-DCMAKE_BUILD_TYPE:STRING=" + std::string(config);
+ args.push_back(btype);
+ }
+
+ for(k=0; k < this->BuildOptions.size(); ++k)
+ {
+ args.push_back(this->BuildOptions[k]);
+ }
+ if (cm->Run(args) != 0)
+ {
+ out << "Error: cmake execution failed\n";
+ out << cmakeOutString << "\n";
+ // return to the original directory
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ if(outstring)
+ {
+ *outstring = out.str();
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, out.str() << std::endl);
+ }
+ return 1;
+ }
+ // do another config?
+ if(this->BuildTwoConfig)
+ {
+ if (cm->Run(args) != 0)
+ {
+ out << "Error: cmake execution failed\n";
+ out << cmakeOutString << "\n";
+ // return to the original directory
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ if(outstring)
+ {
+ *outstring = out.str();
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, out.str() << std::endl);
+ }
+ return 1;
+ }
+ }
+ out << "======== CMake output ======\n";
+ out << cmakeOutString;
+ out << "======== End CMake output ======\n";
+ return 0;
+}
+
+//----------------------------------------------------------------------
+void CMakeMessageCallback(const char* m, const char*, bool&, void* s)
+{
+ std::string* out = (std::string*)s;
+ *out += m;
+ *out += "\n";
+}
+
+void CMakeProgressCallback(const char*msg, float , void * s)
+{
+ std::string* out = (std::string*)s;
+ *out += msg;
+ *out += "\n";
+}
+
+//----------------------------------------------------------------------
+void CMakeOutputCallback(const char* m, size_t len, void* s)
+{
+ std::string* out = (std::string*)s;
+ out->append(m, len);
+}
+
+//----------------------------------------------------------------------
+class cmCTestBuildAndTestCaptureRAII
+{
+ cmake& CM;
+public:
+ cmCTestBuildAndTestCaptureRAII(cmake& cm, std::string& s): CM(cm)
+ {
+ cmSystemTools::SetMessageCallback(CMakeMessageCallback, &s);
+ cmSystemTools::SetStdoutCallback(CMakeOutputCallback, &s);
+ cmSystemTools::SetStderrCallback(CMakeOutputCallback, &s);
+ this->CM.SetProgressCallback(CMakeProgressCallback, &s);
+ }
+ ~cmCTestBuildAndTestCaptureRAII()
+ {
+ this->CM.SetProgressCallback(0, 0);
+ cmSystemTools::SetStderrCallback(0, 0);
+ cmSystemTools::SetStdoutCallback(0, 0);
+ cmSystemTools::SetMessageCallback(0, 0);
+ }
+};
+
+//----------------------------------------------------------------------
+int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
+{
+ // if the generator and make program are not specified then it is an error
+ if (!this->BuildGenerator.size())
+ {
+ if(outstring)
+ {
+ *outstring =
+ "--build-and-test requires that the generator "
+ "be provided using the --build-generator "
+ "command line option. ";
+ }
+ return 1;
+ }
+
+ cmake cm;
+ std::string cmakeOutString;
+ cmCTestBuildAndTestCaptureRAII captureRAII(cm, cmakeOutString);
+ static_cast<void>(captureRAII);
+ cmOStringStream out;
+
+ if ( this->CTest->GetConfigType().size() == 0 &&
+ this->ConfigSample.size())
+ {
+ // use the config sample to set the ConfigType
+ std::string fullPath;
+ std::string resultingConfig;
+ std::vector<std::string> extraPaths;
+ std::vector<std::string> failed;
+ fullPath =
+ cmCTestTestHandler::FindExecutable(this->CTest,
+ this->ConfigSample.c_str(),
+ resultingConfig,
+ extraPaths,
+ failed);
+ if (fullPath.size() && resultingConfig.size())
+ {
+ this->CTest->SetConfigType(resultingConfig.c_str());
+ }
+ out << "Using config sample with results: "
+ << fullPath << " and " << resultingConfig << std::endl;
+ }
+
+ // we need to honor the timeout specified, the timeout include cmake, build
+ // and test time
+ double clock_start = cmSystemTools::GetTime();
+
+ // make sure the binary dir is there
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ out << "Internal cmake changing into directory: "
+ << this->BinaryDir << std::endl;
+ if (!cmSystemTools::FileIsDirectory(this->BinaryDir.c_str()))
+ {
+ cmSystemTools::MakeDirectory(this->BinaryDir.c_str());
+ }
+ cmSystemTools::ChangeDirectory(this->BinaryDir.c_str());
+
+ if(this->BuildNoCMake)
+ {
+ // Make the generator available for the Build call below.
+ cm.SetGlobalGenerator(cm.CreateGlobalGenerator(
+ this->BuildGenerator));
+ cm.SetGeneratorPlatform(this->BuildGeneratorPlatform);
+ cm.SetGeneratorToolset(this->BuildGeneratorToolset);
+
+ // Load the cache to make CMAKE_MAKE_PROGRAM available.
+ cm.GetCacheManager()->LoadCache(this->BinaryDir);
+ }
+ else
+ {
+ // do the cmake step, no timeout here since it is not a sub process
+ if (this->RunCMake(outstring,out,cmakeOutString,cwd,&cm))
+ {
+ return 1;
+ }
+ }
+
+ // do the build
+ std::vector<std::string>::iterator tarIt;
+ if ( this->BuildTargets.size() == 0 )
+ {
+ this->BuildTargets.push_back("");
+ }
+ for ( tarIt = this->BuildTargets.begin();
+ tarIt != this->BuildTargets.end(); ++ tarIt )
+ {
+ double remainingTime = 0;
+ if (this->Timeout > 0)
+ {
+ remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start;
+ if (remainingTime <= 0)
+ {
+ if(outstring)
+ {
+ *outstring = "--build-and-test timeout exceeded. ";
+ }
+ return 1;
+ }
+ }
+ std::string output;
+ const char* config = 0;
+ if ( this->CTest->GetConfigType().size() > 0 )
+ {
+ config = this->CTest->GetConfigType().c_str();
+ }
+#ifdef CMAKE_INTDIR
+ if(!config)
+ {
+ config = CMAKE_INTDIR;
+ }
+#endif
+ if(!config)
+ {
+ config = "Debug";
+ }
+ int retVal = cm.GetGlobalGenerator()->Build(
+ this->SourceDir, this->BinaryDir,
+ this->BuildProject, *tarIt,
+ output, this->BuildMakeProgram,
+ config,
+ !this->BuildNoClean,
+ false, remainingTime);
+ out << output;
+ // if the build failed then return
+ if (retVal)
+ {
+ if(outstring)
+ {
+ *outstring = out.str();
+ }
+ return 1;
+ }
+ }
+ if(outstring)
+ {
+ *outstring = out.str();
+ }
+
+ // if no test was specified then we are done
+ if (!this->TestCommand.size())
+ {
+ return 0;
+ }
+
+ // now run the compiled test if we can find it
+ // store the final location in fullPath
+ std::string fullPath;
+ std::string resultingConfig;
+ std::vector<std::string> extraPaths;
+ // if this->ExecutableDirectory is set try that as well
+ if (this->ExecutableDirectory.size())
+ {
+ std::string tempPath = this->ExecutableDirectory;
+ tempPath += "/";
+ tempPath += this->TestCommand;
+ extraPaths.push_back(tempPath);
+ }
+ std::vector<std::string> failed;
+ fullPath =
+ cmCTestTestHandler::FindExecutable(this->CTest,
+ this->TestCommand.c_str(),
+ resultingConfig,
+ extraPaths,
+ failed);
+
+ if(!cmSystemTools::FileExists(fullPath.c_str()))
+ {
+ out << "Could not find path to executable, perhaps it was not built: "
+ << this->TestCommand << "\n";
+ out << "tried to find it in these places:\n";
+ out << fullPath.c_str() << "\n";
+ for(unsigned int i=0; i < failed.size(); ++i)
+ {
+ out << failed[i] << "\n";
+ }
+ if(outstring)
+ {
+ *outstring = out.str();
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, out.str());
+ }
+ // return to the original directory
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ return 1;
+ }
+
+ std::vector<const char*> testCommand;
+ testCommand.push_back(fullPath.c_str());
+ for(size_t k=0; k < this->TestCommandArgs.size(); ++k)
+ {
+ testCommand.push_back(this->TestCommandArgs[k].c_str());
+ }
+ testCommand.push_back(0);
+ std::string outs;
+ int retval = 0;
+ // run the test from the this->BuildRunDir if set
+ if(this->BuildRunDir.size())
+ {
+ out << "Run test in directory: " << this->BuildRunDir << "\n";
+ cmSystemTools::ChangeDirectory(this->BuildRunDir.c_str());
+ }
+ out << "Running test command: \"" << fullPath << "\"";
+ for(size_t k=0; k < this->TestCommandArgs.size(); ++k)
+ {
+ out << " \"" << this->TestCommandArgs[k] << "\"";
+ }
+ out << "\n";
+
+ // how much time is remaining
+ double remainingTime = 0;
+ if (this->Timeout > 0)
+ {
+ remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start;
+ if (remainingTime <= 0)
+ {
+ if(outstring)
+ {
+ *outstring = "--build-and-test timeout exceeded. ";
+ }
+ return 1;
+ }
+ }
+
+ int runTestRes = this->CTest->RunTest(testCommand, &outs, &retval, 0,
+ remainingTime, 0);
+
+ if(runTestRes != cmsysProcess_State_Exited || retval != 0)
+ {
+ out << "Test command failed: " << testCommand[0] << "\n";
+ retval = 1;
+ }
+
+ out << outs << "\n";
+ if(outstring)
+ {
+ *outstring = out.str();
+ }
+ else
+ {
+ cmCTestLog(this->CTest, OUTPUT, out.str() << std::endl);
+ }
+ return retval;
+}
+
+//----------------------------------------------------------------------
+int cmCTestBuildAndTestHandler::ProcessCommandLineArguments(
+ const std::string& currentArg, size_t& idx,
+ const std::vector<std::string>& allArgs)
+{
+ // --build-and-test options
+ if(currentArg.find("--build-and-test",0) == 0 && idx < allArgs.size() - 1)
+ {
+ if(idx+2 < allArgs.size())
+ {
+ idx++;
+ this->SourceDir = allArgs[idx];
+ idx++;
+ this->BinaryDir = allArgs[idx];
+ // dir must exist before CollapseFullPath is called
+ cmSystemTools::MakeDirectory(this->BinaryDir.c_str());
+ this->BinaryDir
+ = cmSystemTools::CollapseFullPath(this->BinaryDir.c_str());
+ this->SourceDir
+ = cmSystemTools::CollapseFullPath(this->SourceDir.c_str());
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "--build-and-test must have source and binary dir" << std::endl);
+ return 0;
+ }
+ }
+ if(currentArg.find("--build-target",0) == 0 && idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->BuildTargets.push_back(allArgs[idx]);
+ }
+ if(currentArg.find("--build-nocmake",0) == 0)
+ {
+ this->BuildNoCMake = true;
+ }
+ if(currentArg.find("--build-run-dir",0) == 0 && idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->BuildRunDir = allArgs[idx];
+ }
+ if(currentArg.find("--build-two-config",0) == 0)
+ {
+ this->BuildTwoConfig = true;
+ }
+ if(currentArg.find("--build-exe-dir",0) == 0 && idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->ExecutableDirectory = allArgs[idx];
+ }
+ if(currentArg.find("--test-timeout",0) == 0 && idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->Timeout = atof(allArgs[idx].c_str());
+ }
+ if(currentArg == "--build-generator" && idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->BuildGenerator = allArgs[idx];
+ }
+ if(currentArg == "--build-generator-platform" &&
+ idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->BuildGeneratorPlatform = allArgs[idx];
+ }
+ if(currentArg == "--build-generator-toolset" &&
+ idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->BuildGeneratorToolset = allArgs[idx];
+ }
+ if(currentArg.find("--build-project",0) == 0 && idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->BuildProject = allArgs[idx];
+ }
+ if(currentArg.find("--build-makeprogram",0) == 0 &&
+ idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->BuildMakeProgram = allArgs[idx];
+ }
+ if(currentArg.find("--build-config-sample",0) == 0 &&
+ idx < allArgs.size() - 1)
+ {
+ idx++;
+ this->ConfigSample = allArgs[idx];
+ }
+ if(currentArg.find("--build-noclean",0) == 0)
+ {
+ this->BuildNoClean = true;
+ }
+ if(currentArg.find("--build-options",0) == 0)
+ {
+ while(idx+1 < allArgs.size() &&
+ allArgs[idx+1] != "--build-target" &&
+ allArgs[idx+1] != "--test-command")
+ {
+ ++idx;
+ this->BuildOptions.push_back(allArgs[idx]);
+ }
+ }
+ if(currentArg.find("--test-command",0) == 0 && idx < allArgs.size() - 1)
+ {
+ ++idx;
+ this->TestCommand = allArgs[idx];
+ while(idx+1 < allArgs.size())
+ {
+ ++idx;
+ this->TestCommandArgs.push_back(allArgs[idx]);
+ }
+ }
+ return 1;
+}
+
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.h b/Source/CTest/cmCTestBuildAndTestHandler.h
new file mode 100644
index 0000000000..5a7b9168fa
--- /dev/null
+++ b/Source/CTest/cmCTestBuildAndTestHandler.h
@@ -0,0 +1,80 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestBuildAndTestHandler_h
+#define cmCTestBuildAndTestHandler_h
+
+
+#include "cmCTestGenericHandler.h"
+#include "cmListFileCache.h"
+
+class cmake;
+
+/** \class cmCTestBuildAndTestHandler
+ * \brief A class that handles ctest -S invocations
+ *
+ */
+class cmCTestBuildAndTestHandler : public cmCTestGenericHandler
+{
+public:
+ cmTypeMacro(cmCTestBuildAndTestHandler, cmCTestGenericHandler);
+
+ /*
+ * The main entry point for this class
+ */
+ int ProcessHandler();
+
+ //! Set all the build and test arguments
+ virtual int ProcessCommandLineArguments(
+ const std::string& currentArg, size_t& idx,
+ const std::vector<std::string>& allArgs);
+
+ /*
+ * Get the output variable
+ */
+ const char* GetOutput();
+
+ cmCTestBuildAndTestHandler();
+
+ virtual void Initialize();
+
+protected:
+ ///! Run CMake and build a test and then run it as a single test.
+ int RunCMakeAndTest(std::string* output);
+ int RunCMake(std::string* outstring, cmOStringStream &out,
+ std::string &cmakeOutString,
+ std::string &cwd, cmake *cm);
+
+ std::string Output;
+
+ std::string BuildGenerator;
+ std::string BuildGeneratorPlatform;
+ std::string BuildGeneratorToolset;
+ std::vector<std::string> BuildOptions;
+ bool BuildTwoConfig;
+ std::string BuildMakeProgram;
+ std::string ConfigSample;
+ std::string SourceDir;
+ std::string BinaryDir;
+ std::string BuildProject;
+ std::string TestCommand;
+ bool BuildNoClean;
+ std::string BuildRunDir;
+ std::string ExecutableDirectory;
+ std::vector<std::string> TestCommandArgs;
+ std::vector<std::string> BuildTargets;
+ bool BuildNoCMake;
+ double Timeout;
+};
+
+#endif
+
diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx
new file mode 100644
index 0000000000..a5a593a081
--- /dev/null
+++ b/Source/CTest/cmCTestBuildCommand.cxx
@@ -0,0 +1,198 @@
+/*============================================================================
+ 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 "cmCTestBuildCommand.h"
+
+#include "cmCTest.h"
+#include "cmCTestGenericHandler.h"
+#include "cmCTestBuildHandler.h"
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+
+
+//----------------------------------------------------------------------------
+cmCTestBuildCommand::cmCTestBuildCommand()
+{
+ this->GlobalGenerator = 0;
+ this->Arguments[ctb_NUMBER_ERRORS] = "NUMBER_ERRORS";
+ this->Arguments[ctb_NUMBER_WARNINGS] = "NUMBER_WARNINGS";
+ this->Arguments[ctb_TARGET] = "TARGET";
+ this->Arguments[ctb_CONFIGURATION] = "CONFIGURATION";
+ this->Arguments[ctb_FLAGS] = "FLAGS";
+ this->Arguments[ctb_PROJECT_NAME] = "PROJECT_NAME";
+ this->Arguments[ctb_LAST] = 0;
+ this->Last = ctb_LAST;
+}
+
+//----------------------------------------------------------------------------
+cmCTestBuildCommand::~cmCTestBuildCommand()
+{
+ if ( this->GlobalGenerator )
+ {
+ delete this->GlobalGenerator;
+ this->GlobalGenerator = 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
+{
+ cmCTestGenericHandler* handler
+ = this->CTest->GetInitializedHandler("build");
+ if ( !handler )
+ {
+ this->SetError("internal CTest error. Cannot instantiate build handler");
+ return 0;
+ }
+ this->Handler = (cmCTestBuildHandler*)handler;
+
+ const char* ctestBuildCommand
+ = this->Makefile->GetDefinition("CTEST_BUILD_COMMAND");
+ if ( ctestBuildCommand && *ctestBuildCommand )
+ {
+ this->CTest->SetCTestConfiguration("MakeCommand", ctestBuildCommand);
+ }
+ else
+ {
+ const char* cmakeGeneratorName
+ = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
+ const char* cmakeProjectName
+ = (this->Values[ctb_PROJECT_NAME] && *this->Values[ctb_PROJECT_NAME])
+ ? this->Values[ctb_PROJECT_NAME]
+ : this->Makefile->GetDefinition("CTEST_PROJECT_NAME");
+
+ // Build configuration is determined by: CONFIGURATION argument,
+ // or CTEST_BUILD_CONFIGURATION script variable, or
+ // CTEST_CONFIGURATION_TYPE script variable, or ctest -C command
+ // line argument... in that order.
+ //
+ const char* ctestBuildConfiguration
+ = this->Makefile->GetDefinition("CTEST_BUILD_CONFIGURATION");
+ const char* cmakeBuildConfiguration
+ = (this->Values[ctb_CONFIGURATION] && *this->Values[ctb_CONFIGURATION])
+ ? this->Values[ctb_CONFIGURATION]
+ : ((ctestBuildConfiguration && *ctestBuildConfiguration)
+ ? ctestBuildConfiguration
+ : this->CTest->GetConfigType().c_str());
+
+ const char* cmakeBuildAdditionalFlags
+ = (this->Values[ctb_FLAGS] && *this->Values[ctb_FLAGS])
+ ? this->Values[ctb_FLAGS]
+ : this->Makefile->GetDefinition("CTEST_BUILD_FLAGS");
+ const char* cmakeBuildTarget
+ = (this->Values[ctb_TARGET] && *this->Values[ctb_TARGET])
+ ? this->Values[ctb_TARGET]
+ : this->Makefile->GetDefinition("CTEST_BUILD_TARGET");
+
+ if ( cmakeGeneratorName && *cmakeGeneratorName &&
+ cmakeProjectName && *cmakeProjectName )
+ {
+ if ( !cmakeBuildConfiguration )
+ {
+ cmakeBuildConfiguration = "Release";
+ }
+ if ( this->GlobalGenerator )
+ {
+ if ( this->GlobalGenerator->GetName() != cmakeGeneratorName )
+ {
+ delete this->GlobalGenerator;
+ this->GlobalGenerator = 0;
+ }
+ }
+ if ( !this->GlobalGenerator )
+ {
+ this->GlobalGenerator =
+ this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
+ cmakeGeneratorName);
+ if(!this->GlobalGenerator)
+ {
+ std::string e = "could not create generator named \"";
+ e += cmakeGeneratorName;
+ e += "\"";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e);
+ cmSystemTools::SetFatalErrorOccured();
+ return 0;
+ }
+ }
+ if(strlen(cmakeBuildConfiguration) == 0)
+ {
+ const char* config = 0;
+#ifdef CMAKE_INTDIR
+ config = CMAKE_INTDIR;
+#endif
+ if(!config)
+ {
+ config = "Debug";
+ }
+ cmakeBuildConfiguration = config;
+ }
+
+ std::string dir = this->CTest->GetCTestConfiguration("BuildDirectory");
+ std::string buildCommand
+ = this->GlobalGenerator->
+ GenerateCMakeBuildCommand(cmakeBuildTarget ? cmakeBuildTarget : "",
+ cmakeBuildConfiguration,
+ cmakeBuildAdditionalFlags ? cmakeBuildAdditionalFlags : "", true);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "SetMakeCommand:"
+ << buildCommand << "\n");
+ this->CTest->SetCTestConfiguration("MakeCommand", buildCommand.c_str());
+ }
+ else
+ {
+ cmOStringStream ostr;
+ ostr << "has no project to build. If this is a "
+ "\"built with CMake\" project, verify that CTEST_CMAKE_GENERATOR "
+ "and CTEST_PROJECT_NAME are set."
+ "\n"
+ "CTEST_PROJECT_NAME is usually set in CTestConfig.cmake. Verify "
+ "that CTestConfig.cmake exists, or CTEST_PROJECT_NAME "
+ "is set in the script, or PROJECT_NAME is passed as an argument "
+ "to ctest_build."
+ "\n"
+ "Alternatively, set CTEST_BUILD_COMMAND to build the project "
+ "with a custom command line.";
+ this->SetError(ostr.str());
+ return 0;
+ }
+ }
+
+ if(const char* useLaunchers =
+ this->Makefile->GetDefinition("CTEST_USE_LAUNCHERS"))
+ {
+ this->CTest->SetCTestConfiguration("UseLaunchers", useLaunchers);
+ }
+
+ return handler;
+}
+
+
+bool cmCTestBuildCommand::InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status)
+{
+ bool ret = cmCTestHandlerCommand::InitialPass(args, status);
+ if ( this->Values[ctb_NUMBER_ERRORS] && *this->Values[ctb_NUMBER_ERRORS])
+ {
+ cmOStringStream str;
+ str << this->Handler->GetTotalErrors();
+ this->Makefile->AddDefinition(
+ this->Values[ctb_NUMBER_ERRORS], str.str().c_str());
+ }
+ if ( this->Values[ctb_NUMBER_WARNINGS]
+ && *this->Values[ctb_NUMBER_WARNINGS])
+ {
+ cmOStringStream str;
+ str << this->Handler->GetTotalWarnings();
+ this->Makefile->AddDefinition(
+ this->Values[ctb_NUMBER_WARNINGS], str.str().c_str());
+ }
+ return ret;
+}
diff --git a/Source/CTest/cmCTestBuildCommand.h b/Source/CTest/cmCTestBuildCommand.h
new file mode 100644
index 0000000000..2632ebc472
--- /dev/null
+++ b/Source/CTest/cmCTestBuildCommand.h
@@ -0,0 +1,72 @@
+/*============================================================================
+ 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 cmCTestBuildCommand_h
+#define cmCTestBuildCommand_h
+
+#include "cmCTestHandlerCommand.h"
+
+class cmGlobalGenerator;
+class cmCTestBuildHandler;
+
+/** \class cmCTestBuild
+ * \brief Run a ctest script
+ *
+ * cmCTestBuildCommand defineds the command to build the project.
+ */
+class cmCTestBuildCommand : public cmCTestHandlerCommand
+{
+public:
+
+ cmCTestBuildCommand();
+ ~cmCTestBuildCommand();
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestBuildCommand* ni = new cmCTestBuildCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_build";}
+
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ cmTypeMacro(cmCTestBuildCommand, cmCTestHandlerCommand);
+
+ cmGlobalGenerator* GlobalGenerator;
+
+protected:
+ cmCTestBuildHandler* Handler;
+ enum {
+ ctb_BUILD = ct_LAST,
+ ctb_NUMBER_ERRORS,
+ ctb_NUMBER_WARNINGS,
+ ctb_TARGET,
+ ctb_CONFIGURATION,
+ ctb_FLAGS,
+ ctb_PROJECT_NAME,
+ ctb_LAST
+ };
+
+ cmCTestGenericHandler* InitializeHandler();
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx
new file mode 100644
index 0000000000..2ec1365419
--- /dev/null
+++ b/Source/CTest/cmCTestBuildHandler.cxx
@@ -0,0 +1,1316 @@
+/*============================================================================
+ 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 "cmCTestBuildHandler.h"
+
+#include "cmCTest.h"
+#include "cmake.h"
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmXMLSafe.h"
+#include "cmFileTimeComparison.h"
+
+//#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Process.h>
+#include <cmsys/Directory.hxx>
+#include <cmsys/FStream.hxx>
+
+// used for sleep
+#ifdef _WIN32
+#include "windows.h"
+#endif
+
+#include <stdlib.h>
+#include <time.h>
+#include <math.h>
+#include <float.h>
+
+#if defined(__BORLANDC__)
+# pragma warn -8060 /* possibly incorrect assignment */
+#endif
+
+static const char* cmCTestErrorMatches[] = {
+ "^[Bb]us [Ee]rror",
+ "^[Ss]egmentation [Vv]iolation",
+ "^[Ss]egmentation [Ff]ault",
+ ":.*[Pp]ermission [Dd]enied",
+ "([^ :]+):([0-9]+): ([^ \\t])",
+ "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
+ "^Error ([0-9]+):",
+ "^Fatal",
+ "^Error: ",
+ "^Error ",
+ "[0-9] ERROR: ",
+ "^\"[^\"]+\", line [0-9]+: [^Ww]",
+ "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
+ "^ld([^:])*:([ \\t])*ERROR([^:])*:",
+ "^ild:([ \\t])*\\(undefined symbol\\)",
+ "([^ :]+) : (error|fatal error|catastrophic error)",
+ "([^:]+): (Error:|error|undefined reference|multiply defined)",
+ "([^:]+)\\(([^\\)]+)\\) ?: (error|fatal error|catastrophic error)",
+ "^fatal error C[0-9]+:",
+ ": syntax error ",
+ "^collect2: ld returned 1 exit status",
+ "ld terminated with signal",
+ "Unsatisfied symbol",
+ "^Unresolved:",
+ "Undefined symbol",
+ "^Undefined[ \\t]+first referenced",
+ "^CMake Error.*:",
+ ":[ \\t]cannot find",
+ ":[ \\t]can't find",
+ ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
+ ": \\*\\*\\* No targets specified and no makefile found",
+ ": Invalid loader fixup for symbol",
+ ": Invalid fixups exist",
+ ": Can't find library for",
+ ": internal link edit command failed",
+ ": Unrecognized option \\`.*\\'",
+ "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^WI]\\)",
+ "ld: 0706-006 Cannot find or open library file: -l ",
+ "ild: \\(argument error\\) can't find library argument ::",
+ "^could not be found and will not be loaded.",
+ "s:616 string too big",
+ "make: Fatal error: ",
+ "ld: 0711-993 Error occurred while writing to the output file:",
+ "ld: fatal: ",
+ "final link failed:",
+ "make: \\*\\*\\*.*Error",
+ "make\\[.*\\]: \\*\\*\\*.*Error",
+ "\\*\\*\\* Error code",
+ "nternal error:",
+ "Makefile:[0-9]+: \\*\\*\\* .* Stop\\.",
+ ": No such file or directory",
+ ": Invalid argument",
+ "^The project cannot be built\\.",
+ "^\\[ERROR\\]",
+ "^Command .* failed with exit code",
+ 0
+};
+
+static const char* cmCTestErrorExceptions[] = {
+ "instantiated from ",
+ "candidates are:",
+ ": warning",
+ ": \\(Warning\\)",
+ ": note",
+ "makefile:",
+ "Makefile:",
+ ":[ \\t]+Where:",
+ "([^ :]+):([0-9]+): Warning",
+ "------ Build started: .* ------",
+ 0
+};
+
+static const char* cmCTestWarningMatches[] = {
+ "([^ :]+):([0-9]+): warning:",
+ "([^ :]+):([0-9]+): note:",
+ "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
+ "^ld([^:])*:([ \\t])*WARNING([^:])*:",
+ "([^:]+): warning ([0-9]+):",
+ "^\"[^\"]+\", line [0-9]+: [Ww](arning|arnung)",
+ "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
+ "^(Warning|Warnung) ([0-9]+):",
+ "^(Warning|Warnung)[ :]",
+ "WARNING: ",
+ "([^ :]+) : warning",
+ "([^:]+): warning",
+ "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([WI]\\)",
+ "^cxx: Warning:",
+ ".*file: .* has no symbols",
+ "([^ :]+):([0-9]+): (Warning|Warnung)",
+ "\\([0-9]*\\): remark #[0-9]*",
+ "\".*\", line [0-9]+: remark\\([0-9]*\\):",
+ "cc-[0-9]* CC: REMARK File = .*, Line = [0-9]*",
+ "^CMake Warning.*:",
+ "^\\[WARNING\\]",
+ 0
+};
+
+static const char* cmCTestWarningExceptions[] = {
+ "/usr/.*/X11/Xlib\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
+ "/usr/.*/X11/Xutil\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
+ "/usr/.*/X11/XResource\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
+ "WARNING 84 :",
+ "WARNING 47 :",
+ "makefile:",
+ "Makefile:",
+ "warning: Clock skew detected. Your build may be incomplete.",
+ "/usr/openwin/include/GL/[^:]+:",
+ "bind_at_load",
+ "XrmQGetResource",
+ "IceFlush",
+ "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
+ "ld32: WARNING 85: definition of dataKey in",
+ "cc: warning 422: Unknown option \"\\+b",
+ "_with_warning_C",
+ 0
+};
+
+struct cmCTestBuildCompileErrorWarningRex
+{
+ const char* RegularExpressionString;
+ int FileIndex;
+ int LineIndex;
+};
+
+static cmCTestBuildCompileErrorWarningRex
+cmCTestWarningErrorFileLine[] = {
+ { "^Warning W[0-9]+ ([a-zA-Z.\\:/0-9_+ ~-]+) ([0-9]+):", 1, 2 },
+ { "^([a-zA-Z./0-9_+ ~-]+):([0-9]+):", 1, 2 },
+ { "^([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
+ { "^[0-9]+>([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
+ { "^([a-zA-Z./0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
+ { "\"([a-zA-Z./0-9_+ ~-]+)\", line ([0-9]+)", 1, 2 },
+ { "File = ([a-zA-Z./0-9_+ ~-]+), Line = ([0-9]+)", 1, 2 },
+ { 0, 0, 0 }
+};
+
+//----------------------------------------------------------------------
+cmCTestBuildHandler::cmCTestBuildHandler()
+{
+ this->MaxPreContext = 10;
+ this->MaxPostContext = 10;
+
+ this->MaxErrors = 50;
+ this->MaxWarnings = 50;
+
+ this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
+
+ this->UseCTestLaunch = false;
+}
+
+//----------------------------------------------------------------------
+void cmCTestBuildHandler::Initialize()
+{
+ this->Superclass::Initialize();
+ this->StartBuild = "";
+ this->EndBuild = "";
+ this->CustomErrorMatches.clear();
+ this->CustomErrorExceptions.clear();
+ this->CustomWarningMatches.clear();
+ this->CustomWarningExceptions.clear();
+ this->ReallyCustomWarningMatches.clear();
+ this->ReallyCustomWarningExceptions.clear();
+ this->ErrorWarningFileLineRegex.clear();
+
+ this->ErrorMatchRegex.clear();
+ this->ErrorExceptionRegex.clear();
+ this->WarningMatchRegex.clear();
+ this->WarningExceptionRegex.clear();
+ this->BuildProcessingQueue.clear();
+ this->BuildProcessingErrorQueue.clear();
+ this->BuildOutputLogSize = 0;
+ this->CurrentProcessingLine.clear();
+
+ this->SimplifySourceDir = "";
+ this->SimplifyBuildDir = "";
+ this->OutputLineCounter = 0;
+ this->ErrorsAndWarnings.clear();
+ this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
+ this->PostContextCount = 0;
+ this->MaxPreContext = 10;
+ this->MaxPostContext = 10;
+ this->PreContext.clear();
+
+ this->TotalErrors = 0;
+ this->TotalWarnings = 0;
+ this->LastTickChar = 0;
+
+ this->ErrorQuotaReached = false;
+ this->WarningQuotaReached = false;
+
+ this->MaxErrors = 50;
+ this->MaxWarnings = 50;
+
+ this->UseCTestLaunch = false;
+}
+
+//----------------------------------------------------------------------
+void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile *mf)
+{
+ this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH",
+ this->CustomErrorMatches);
+ this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION",
+ this->CustomErrorExceptions);
+ this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH",
+ this->CustomWarningMatches);
+ this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION",
+ this->CustomWarningExceptions);
+ this->CTest->PopulateCustomInteger(mf,
+ "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS",
+ this->MaxErrors);
+ this->CTest->PopulateCustomInteger(mf,
+ "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS",
+ this->MaxWarnings);
+
+ int n = -1;
+ this->CTest->PopulateCustomInteger(mf, "CTEST_CUSTOM_ERROR_PRE_CONTEXT", n);
+ if (n != -1)
+ {
+ this->MaxPreContext = static_cast<size_t>(n);
+ }
+
+ n = -1;
+ this->CTest->PopulateCustomInteger(mf, "CTEST_CUSTOM_ERROR_POST_CONTEXT", n);
+ if (n != -1)
+ {
+ this->MaxPostContext = static_cast<size_t>(n);
+ }
+
+ // Record the user-specified custom warning rules.
+ if(const char* customWarningMatchers =
+ mf->GetDefinition("CTEST_CUSTOM_WARNING_MATCH"))
+ {
+ cmSystemTools::ExpandListArgument(customWarningMatchers,
+ this->ReallyCustomWarningMatches);
+ }
+ if(const char* customWarningExceptions =
+ mf->GetDefinition("CTEST_CUSTOM_WARNING_EXCEPTION"))
+ {
+ cmSystemTools::ExpandListArgument(customWarningExceptions,
+ this->ReallyCustomWarningExceptions);
+ }
+}
+
+//----------------------------------------------------------------------
+std::string cmCTestBuildHandler::GetMakeCommand()
+{
+ std::string makeCommand
+ = this->CTest->GetCTestConfiguration("MakeCommand");
+ cmCTestLog(this->CTest,
+ HANDLER_VERBOSE_OUTPUT, "MakeCommand:" << makeCommand <<
+ "\n");
+
+ std::string configType = this->CTest->GetConfigType();
+ if (configType == "")
+ {
+ configType
+ = this->CTest->GetCTestConfiguration("DefaultCTestConfigurationType");
+ }
+ if (configType == "")
+ {
+ configType = "Release";
+ }
+
+ cmSystemTools::ReplaceString(makeCommand,
+ "${CTEST_CONFIGURATION_TYPE}", configType.c_str());
+
+ return makeCommand;
+}
+
+//----------------------------------------------------------------------
+//clearly it would be nice if this were broken up into a few smaller
+//functions and commented...
+int cmCTestBuildHandler::ProcessHandler()
+{
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Build project" << std::endl);
+
+ // do we have time for this
+ if (this->CTest->GetRemainingTimeAllowed() < 120)
+ {
+ return 0;
+ }
+
+ int entry;
+ for ( entry = 0;
+ cmCTestWarningErrorFileLine[entry].RegularExpressionString;
+ ++ entry )
+ {
+ cmCTestBuildHandler::cmCTestCompileErrorWarningRex r;
+ if ( r.RegularExpression.compile(
+ cmCTestWarningErrorFileLine[entry].RegularExpressionString) )
+ {
+ r.FileIndex = cmCTestWarningErrorFileLine[entry].FileIndex;
+ r.LineIndex = cmCTestWarningErrorFileLine[entry].LineIndex;
+ this->ErrorWarningFileLineRegex.push_back(r);
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Problem Compiling regular expression: "
+ << cmCTestWarningErrorFileLine[entry].RegularExpressionString
+ << std::endl);
+ }
+ }
+
+ // Determine build command and build directory
+ std::string makeCommand = this->GetMakeCommand();
+ if ( makeCommand.size() == 0 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find MakeCommand key in the DartConfiguration.tcl"
+ << std::endl);
+ return -1;
+ }
+
+ const std::string &buildDirectory
+ = this->CTest->GetCTestConfiguration("BuildDirectory");
+ if ( buildDirectory.size() == 0 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find BuildDirectory key in the DartConfiguration.tcl"
+ << std::endl);
+ return -1;
+ }
+
+ std::string const& useLaunchers =
+ this->CTest->GetCTestConfiguration("UseLaunchers");
+ this->UseCTestLaunch = cmSystemTools::IsOn(useLaunchers.c_str());
+
+ // Create a last build log
+ cmGeneratedFileStream ofs;
+ double elapsed_time_start = cmSystemTools::GetTime();
+ if ( !this->StartLogFile("Build", ofs) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build log file"
+ << std::endl);
+ }
+
+ // Create lists of regular expression strings for errors, error exceptions,
+ // warnings and warning exceptions.
+ std::vector<std::string>::size_type cc;
+ for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
+ {
+ this->CustomErrorMatches.push_back(cmCTestErrorMatches[cc]);
+ }
+ for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
+ {
+ this->CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
+ }
+ for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
+ {
+ this->CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
+ }
+
+ for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
+ {
+ this->CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
+ }
+
+ // Pre-compile regular expressions objects for all regular expressions
+ std::vector<std::string>::iterator it;
+
+#define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \
+ regexes.clear(); \
+ cmCTestLog(this->CTest, DEBUG, this << "Add " #regexes \
+ << std::endl); \
+ for ( it = strings.begin(); it != strings.end(); ++it ) \
+ { \
+ cmCTestLog(this->CTest, DEBUG, "Add " #strings ": " \
+ << *it << std::endl); \
+ regexes.push_back(it->c_str()); \
+ }
+ cmCTestBuildHandlerPopulateRegexVector(
+ this->CustomErrorMatches, this->ErrorMatchRegex);
+ cmCTestBuildHandlerPopulateRegexVector(
+ this->CustomErrorExceptions, this->ErrorExceptionRegex);
+ cmCTestBuildHandlerPopulateRegexVector(
+ this->CustomWarningMatches, this->WarningMatchRegex);
+ cmCTestBuildHandlerPopulateRegexVector(
+ this->CustomWarningExceptions, this->WarningExceptionRegex);
+
+
+ // Determine source and binary tree substitutions to simplify the output.
+ this->SimplifySourceDir = "";
+ this->SimplifyBuildDir = "";
+ if ( this->CTest->GetCTestConfiguration("SourceDirectory").size() > 20 )
+ {
+ std::string srcdir
+ = this->CTest->GetCTestConfiguration("SourceDirectory") + "/";
+ std::string srcdirrep;
+ for ( cc = srcdir.size()-2; cc > 0; cc -- )
+ {
+ if ( srcdir[cc] == '/' )
+ {
+ srcdirrep = srcdir.c_str() + cc;
+ srcdirrep = "/..." + srcdirrep;
+ srcdir = srcdir.substr(0, cc+1);
+ break;
+ }
+ }
+ this->SimplifySourceDir = srcdir;
+ }
+ if ( this->CTest->GetCTestConfiguration("BuildDirectory").size() > 20 )
+ {
+ std::string bindir
+ = this->CTest->GetCTestConfiguration("BuildDirectory") + "/";
+ std::string bindirrep;
+ for ( cc = bindir.size()-2; cc > 0; cc -- )
+ {
+ if ( bindir[cc] == '/' )
+ {
+ bindirrep = bindir.c_str() + cc;
+ bindirrep = "/..." + bindirrep;
+ bindir = bindir.substr(0, cc+1);
+ break;
+ }
+ }
+ this->SimplifyBuildDir = bindir;
+ }
+
+
+ // Ok, let's do the build
+
+ // Remember start build time
+ this->StartBuild = this->CTest->CurrentTime();
+ this->StartBuildTime = cmSystemTools::GetTime();
+ int retVal = 0;
+ int res = cmsysProcess_State_Exited;
+ if ( !this->CTest->GetShowOnly() )
+ {
+ res = this->RunMakeCommand(makeCommand.c_str(), &retVal,
+ buildDirectory.c_str(), 0, ofs);
+ }
+ else
+ {
+ cmCTestLog(this->CTest, DEBUG, "Build with command: " << makeCommand
+ << std::endl);
+ }
+
+ // Remember end build time and calculate elapsed time
+ this->EndBuild = this->CTest->CurrentTime();
+ this->EndBuildTime = cmSystemTools::GetTime();
+ double elapsed_build_time = cmSystemTools::GetTime() - elapsed_time_start;
+
+ // Cleanups strings in the errors and warnings list.
+ t_ErrorsAndWarningsVector::iterator evit;
+ if ( !this->SimplifySourceDir.empty() )
+ {
+ for ( evit = this->ErrorsAndWarnings.begin();
+ evit != this->ErrorsAndWarnings.end();
+ ++ evit )
+ {
+ cmSystemTools::ReplaceString(
+ evit->Text, this->SimplifySourceDir.c_str(), "/.../");
+ cmSystemTools::ReplaceString(
+ evit->PreContext, this->SimplifySourceDir.c_str(), "/.../");
+ cmSystemTools::ReplaceString(
+ evit->PostContext, this->SimplifySourceDir.c_str(), "/.../");
+ }
+ }
+
+ if ( !this->SimplifyBuildDir.empty() )
+ {
+ for ( evit = this->ErrorsAndWarnings.begin();
+ evit != this->ErrorsAndWarnings.end();
+ ++ evit )
+ {
+ cmSystemTools::ReplaceString(
+ evit->Text, this->SimplifyBuildDir.c_str(), "/.../");
+ cmSystemTools::ReplaceString(
+ evit->PreContext, this->SimplifyBuildDir.c_str(), "/.../");
+ cmSystemTools::ReplaceString(
+ evit->PostContext, this->SimplifyBuildDir.c_str(), "/.../");
+ }
+ }
+
+ // Generate XML output
+ cmGeneratedFileStream xofs;
+ if(!this->StartResultingXML(cmCTest::PartBuild, "Build", xofs))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build XML file"
+ << std::endl);
+ return -1;
+ }
+ this->GenerateXMLHeader(xofs);
+ if(this->UseCTestLaunch)
+ {
+ this->GenerateXMLLaunched(xofs);
+ }
+ else
+ {
+ this->GenerateXMLLogScraped(xofs);
+ }
+ this->GenerateXMLFooter(xofs, elapsed_build_time);
+
+ if (res != cmsysProcess_State_Exited || retVal || this->TotalErrors > 0)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Error(s) when building project"
+ << std::endl);
+ }
+
+ // Display message about number of errors and warnings
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << this->TotalErrors
+ << (this->TotalErrors >= this->MaxErrors ? " or more" : "")
+ << " Compiler errors" << std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << this->TotalWarnings
+ << (this->TotalWarnings >= this->MaxWarnings ? " or more" : "")
+ << " Compiler warnings" << std::endl);
+
+ return retVal;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestBuildHandler::GenerateXMLHeader(std::ostream& os)
+{
+ this->CTest->StartXML(os, this->AppendXML);
+ os << "<Build>\n"
+ << "\t<StartDateTime>" << this->StartBuild << "</StartDateTime>\n"
+ << "\t<StartBuildTime>" <<
+ static_cast<unsigned int>(this->StartBuildTime)
+ << "</StartBuildTime>\n"
+ << "<BuildCommand>"
+ << cmXMLSafe(this->GetMakeCommand())
+ << "</BuildCommand>" << std::endl;
+}
+
+//----------------------------------------------------------------------------
+class cmCTestBuildHandler::FragmentCompare
+{
+public:
+ FragmentCompare(cmFileTimeComparison* ftc): FTC(ftc) {}
+ FragmentCompare(): FTC(0) {}
+ bool operator()(std::string const& l, std::string const& r)
+ {
+ // Order files by modification time. Use lexicographic order
+ // among files with the same time.
+ int result;
+ if(this->FTC->FileTimeCompare(l.c_str(), r.c_str(), &result) &&
+ result != 0)
+ {
+ return result < 0;
+ }
+ else
+ {
+ return l < r;
+ }
+ }
+private:
+ cmFileTimeComparison* FTC;
+};
+
+//----------------------------------------------------------------------------
+void cmCTestBuildHandler::GenerateXMLLaunched(std::ostream& os)
+{
+ if(this->CTestLaunchDir.empty())
+ {
+ return;
+ }
+
+ // Sort XML fragments in chronological order.
+ cmFileTimeComparison ftc;
+ FragmentCompare fragmentCompare(&ftc);
+ typedef std::set<std::string, FragmentCompare> Fragments;
+ Fragments fragments(fragmentCompare);
+
+ // only report the first 50 warnings and first 50 errors
+ int numErrorsAllowed = this->MaxErrors;
+ int numWarningsAllowed = this->MaxWarnings;
+ // Identify fragments on disk.
+ cmsys::Directory launchDir;
+ launchDir.Load(this->CTestLaunchDir.c_str());
+ unsigned long n = launchDir.GetNumberOfFiles();
+ for(unsigned long i=0; i < n; ++i)
+ {
+ const char* fname = launchDir.GetFile(i);
+ if(this->IsLaunchedErrorFile(fname) && numErrorsAllowed)
+ {
+ numErrorsAllowed--;
+ fragments.insert(this->CTestLaunchDir + "/" + fname);
+ ++this->TotalErrors;
+ }
+ else if(this->IsLaunchedWarningFile(fname) && numWarningsAllowed)
+ {
+ numWarningsAllowed--;
+ fragments.insert(this->CTestLaunchDir + "/" + fname);
+ ++this->TotalWarnings;
+ }
+ }
+
+ // Copy the fragments into the final XML file.
+ for(Fragments::const_iterator fi = fragments.begin();
+ fi != fragments.end(); ++fi)
+ {
+ this->GenerateXMLLaunchedFragment(os, fi->c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os)
+{
+ std::vector<cmCTestBuildErrorWarning>& ew = this->ErrorsAndWarnings;
+ std::vector<cmCTestBuildErrorWarning>::iterator it;
+
+ // only report the first 50 warnings and first 50 errors
+ int numErrorsAllowed = this->MaxErrors;
+ int numWarningsAllowed = this->MaxWarnings;
+ std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
+ // make sure the source dir is in the correct case on windows
+ // via a call to collapse full path.
+ srcdir = cmSystemTools::CollapseFullPath(srcdir.c_str());
+ srcdir += "/";
+ for ( it = ew.begin();
+ it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++ )
+ {
+ cmCTestBuildErrorWarning *cm = &(*it);
+ if ((cm->Error && numErrorsAllowed) ||
+ (!cm->Error && numWarningsAllowed))
+ {
+ if (cm->Error)
+ {
+ numErrorsAllowed--;
+ }
+ else
+ {
+ numWarningsAllowed--;
+ }
+ os << "\t<" << (cm->Error ? "Error" : "Warning") << ">\n"
+ << "\t\t<BuildLogLine>" << cm->LogLine << "</BuildLogLine>\n"
+ << "\t\t<Text>" << cmXMLSafe(cm->Text).Quotes(false)
+ << "\n</Text>" << std::endl;
+ std::vector<cmCTestCompileErrorWarningRex>::iterator rit;
+ for ( rit = this->ErrorWarningFileLineRegex.begin();
+ rit != this->ErrorWarningFileLineRegex.end(); ++ rit )
+ {
+ cmsys::RegularExpression* re = &rit->RegularExpression;
+ if ( re->find(cm->Text.c_str() ) )
+ {
+ cm->SourceFile = re->match(rit->FileIndex);
+ // At this point we need to make this->SourceFile relative to
+ // the source root of the project, so cvs links will work
+ cmSystemTools::ConvertToUnixSlashes(cm->SourceFile);
+ if(cm->SourceFile.find("/.../") != cm->SourceFile.npos)
+ {
+ cmSystemTools::ReplaceString(cm->SourceFile, "/.../", "");
+ std::string::size_type p = cm->SourceFile.find("/");
+ if(p != cm->SourceFile.npos)
+ {
+ cm->SourceFile = cm->SourceFile.substr(
+ p+1, cm->SourceFile.size()-p);
+ }
+ }
+ else
+ {
+ // make sure it is a full path with the correct case
+ cm->SourceFile = cmSystemTools::CollapseFullPath(
+ cm->SourceFile.c_str());
+ cmSystemTools::ReplaceString(
+ cm->SourceFile, srcdir.c_str(), "");
+ }
+ cm->LineNumber = atoi(re->match(rit->LineIndex).c_str());
+ break;
+ }
+ }
+ if ( !cm->SourceFile.empty() && cm->LineNumber >= 0 )
+ {
+ if ( cm->SourceFile.size() > 0 )
+ {
+ os << "\t\t<SourceFile>" << cm->SourceFile << "</SourceFile>"
+ << std::endl;
+ }
+ if ( cm->SourceFileTail.size() > 0 )
+ {
+ os << "\t\t<SourceFileTail>" << cm->SourceFileTail
+ << "</SourceFileTail>" << std::endl;
+ }
+ if ( cm->LineNumber >= 0 )
+ {
+ os << "\t\t<SourceLineNumber>" << cm->LineNumber
+ << "</SourceLineNumber>" << std::endl;
+ }
+ }
+ os << "\t\t<PreContext>" << cmXMLSafe(cm->PreContext).Quotes(false)
+ << "</PreContext>\n"
+ << "\t\t<PostContext>" << cmXMLSafe(cm->PostContext).Quotes(false);
+ // is this the last warning or error, if so notify
+ if ((cm->Error && !numErrorsAllowed) ||
+ (!cm->Error && !numWarningsAllowed))
+ {
+ os << "\nThe maximum number of reported warnings or errors has been "
+ "reached!!!\n";
+ }
+ os << "</PostContext>\n"
+ << "\t\t<RepeatCount>0</RepeatCount>\n"
+ << "</" << (cm->Error ? "Error" : "Warning") << ">\n\n"
+ << std::endl;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestBuildHandler::GenerateXMLFooter(std::ostream& os,
+ double elapsed_build_time)
+{
+ os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
+ << "\t<EndDateTime>" << this->EndBuild << "</EndDateTime>\n"
+ << "\t<EndBuildTime>" << static_cast<unsigned int>(this->EndBuildTime)
+ << "</EndBuildTime>\n"
+ << "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time/6)/10.0
+ << "</ElapsedMinutes>"
+ << "</Build>" << std::endl;
+ this->CTest->EndXML(os);
+}
+
+//----------------------------------------------------------------------------
+void cmCTestBuildHandler::GenerateXMLLaunchedFragment(std::ostream& os,
+ const char* fname)
+{
+ cmsys::ifstream fin(fname, std::ios::in | std::ios::binary);
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ os << line << "\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestBuildHandler::IsLaunchedErrorFile(const char* fname)
+{
+ // error-{hash}.xml
+ return (cmHasLiteralPrefix(fname, "error-") &&
+ strcmp(fname+strlen(fname)-4, ".xml") == 0);
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestBuildHandler::IsLaunchedWarningFile(const char* fname)
+{
+ // warning-{hash}.xml
+ return (cmHasLiteralPrefix(fname, "warning-") &&
+ strcmp(fname+strlen(fname)-4, ".xml") == 0);
+}
+
+//######################################################################
+//######################################################################
+//######################################################################
+//######################################################################
+
+//----------------------------------------------------------------------------
+class cmCTestBuildHandler::LaunchHelper
+{
+public:
+ LaunchHelper(cmCTestBuildHandler* handler);
+ ~LaunchHelper();
+private:
+ cmCTestBuildHandler* Handler;
+ cmCTest* CTest;
+
+ void WriteLauncherConfig();
+ void WriteScrapeMatchers(const char* purpose,
+ std::vector<std::string> const& matchers);
+};
+
+//----------------------------------------------------------------------------
+cmCTestBuildHandler::LaunchHelper::LaunchHelper(cmCTestBuildHandler* handler):
+ Handler(handler), CTest(handler->CTest)
+{
+ std::string tag = this->CTest->GetCurrentTag();
+ if(tag.empty())
+ {
+ // This is not for a dashboard submission, so there is no XML.
+ // Skip enabling the launchers.
+ this->Handler->UseCTestLaunch = false;
+ }
+ else
+ {
+ // Compute a directory in which to store launcher fragments.
+ std::string& launchDir = this->Handler->CTestLaunchDir;
+ launchDir = this->CTest->GetBinaryDir();
+ launchDir += "/Testing/";
+ launchDir += tag;
+ launchDir += "/Build";
+
+ // Clean out any existing launcher fragments.
+ cmSystemTools::RemoveADirectory(launchDir.c_str());
+
+ if(this->Handler->UseCTestLaunch)
+ {
+ // Enable launcher fragments.
+ cmSystemTools::MakeDirectory(launchDir.c_str());
+ this->WriteLauncherConfig();
+ std::string launchEnv = "CTEST_LAUNCH_LOGS=";
+ launchEnv += launchDir;
+ cmSystemTools::PutEnv(launchEnv.c_str());
+ }
+ }
+
+ // If not using launchers, make sure they passthru.
+ if(!this->Handler->UseCTestLaunch)
+ {
+ cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
+ }
+}
+
+//----------------------------------------------------------------------------
+cmCTestBuildHandler::LaunchHelper::~LaunchHelper()
+{
+ if(this->Handler->UseCTestLaunch)
+ {
+ cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestBuildHandler::LaunchHelper::WriteLauncherConfig()
+{
+ this->WriteScrapeMatchers("Warning",
+ this->Handler->ReallyCustomWarningMatches);
+ this->WriteScrapeMatchers("WarningSuppress",
+ this->Handler->ReallyCustomWarningExceptions);
+
+ // Give some testing configuration information to the launcher.
+ std::string fname = this->Handler->CTestLaunchDir;
+ fname += "/CTestLaunchConfig.cmake";
+ cmGeneratedFileStream fout(fname.c_str());
+ std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
+ fout << "set(CTEST_SOURCE_DIRECTORY \"" << srcdir << "\")\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmCTestBuildHandler::LaunchHelper
+::WriteScrapeMatchers(const char* purpose,
+ std::vector<std::string> const& matchers)
+{
+ if(matchers.empty())
+ {
+ return;
+ }
+ std::string fname = this->Handler->CTestLaunchDir;
+ fname += "/Custom";
+ fname += purpose;
+ fname += ".txt";
+ cmGeneratedFileStream fout(fname.c_str());
+ for(std::vector<std::string>::const_iterator mi = matchers.begin();
+ mi != matchers.end(); ++mi)
+ {
+ fout << *mi << "\n";
+ }
+}
+
+//----------------------------------------------------------------------
+int cmCTestBuildHandler::RunMakeCommand(const char* command,
+ int* retVal, const char* dir, int timeout, std::ostream& ofs)
+{
+ // First generate the command and arguments
+ std::vector<std::string> args = cmSystemTools::ParseArguments(command);
+
+ if(args.size() < 1)
+ {
+ return false;
+ }
+
+ std::vector<const char*> argv;
+ for(std::vector<std::string>::const_iterator a = args.begin();
+ a != args.end(); ++a)
+ {
+ argv.push_back(a->c_str());
+ }
+ argv.push_back(0);
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command:");
+ std::vector<const char*>::iterator ait;
+ for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
+
+ // Optionally use make rule launchers to record errors and warnings.
+ LaunchHelper launchHelper(this);
+ static_cast<void>(launchHelper);
+
+ // Now create process object
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetWorkingDirectory(cp, dir);
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+ cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_Execute(cp);
+
+ // Initialize tick's
+ std::string::size_type tick = 0;
+ const std::string::size_type tick_len = 1024;
+
+ char* data;
+ int length;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Each symbol represents " << tick_len << " bytes of output."
+ << std::endl
+ << (this->UseCTestLaunch? "" :
+ " '!' represents an error and '*' a warning.\n")
+ << " " << std::flush);
+
+ // Initialize building structures
+ this->BuildProcessingQueue.clear();
+ this->OutputLineCounter = 0;
+ this->ErrorsAndWarnings.clear();
+ this->TotalErrors = 0;
+ this->TotalWarnings = 0;
+ this->BuildOutputLogSize = 0;
+ this->LastTickChar = '.';
+ this->WarningQuotaReached = false;
+ this->ErrorQuotaReached = false;
+
+ // For every chunk of data
+ int res;
+ while((res = cmsysProcess_WaitForData(cp, &data, &length, 0)))
+ {
+ // Replace '\0' with '\n', since '\0' does not really make sense. This is
+ // for Visual Studio output
+ for(int cc =0; cc < length; ++cc)
+ {
+ if(data[cc] == 0)
+ {
+ data[cc] = '\n';
+ }
+ }
+
+ // Process the chunk of data
+ if ( res == cmsysProcess_Pipe_STDERR )
+ {
+ this->ProcessBuffer(data, length, tick, tick_len, ofs,
+ &this->BuildProcessingErrorQueue);
+ }
+ else
+ {
+ this->ProcessBuffer(data, length, tick, tick_len, ofs,
+ &this->BuildProcessingQueue);
+ }
+ }
+
+ this->ProcessBuffer(0, 0, tick, tick_len, ofs, &this->BuildProcessingQueue);
+ this->ProcessBuffer(0, 0, tick, tick_len, ofs,
+ &this->BuildProcessingErrorQueue);
+ cmCTestLog(this->CTest, OUTPUT, " Size of output: "
+ << ((this->BuildOutputLogSize + 512) / 1024) << "K" << std::endl);
+
+ // Properly handle output of the build command
+ cmsysProcess_WaitForExit(cp, 0);
+ int result = cmsysProcess_GetState(cp);
+
+ if(result == cmsysProcess_State_Exited)
+ {
+ if (retVal)
+ {
+ *retVal = cmsysProcess_GetExitValue(cp);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Command exited with the value: " << *retVal << std::endl);
+ // if a non zero return value
+ if (*retVal)
+ {
+ // If there was an error running command, report that on the
+ // dashboard.
+ cmCTestBuildErrorWarning errorwarning;
+ errorwarning.LogLine = 1;
+ errorwarning.Text
+ = "*** WARNING non-zero return value in ctest from: ";
+ errorwarning.Text += argv[0];
+ errorwarning.PreContext = "";
+ errorwarning.PostContext = "";
+ errorwarning.Error = false;
+ this->ErrorsAndWarnings.push_back(errorwarning);
+ this->TotalWarnings ++;
+ }
+ }
+ }
+ else if(result == cmsysProcess_State_Exception)
+ {
+ if (retVal)
+ {
+ *retVal = cmsysProcess_GetExitException(cp);
+ cmCTestLog(this->CTest, WARNING, "There was an exception: " << *retVal
+ << std::endl);
+ }
+ }
+ else if(result == cmsysProcess_State_Expired)
+ {
+ cmCTestLog(this->CTest, WARNING, "There was a timeout" << std::endl);
+ }
+ else if(result == cmsysProcess_State_Error)
+ {
+ // If there was an error running command, report that on the dashboard.
+ cmCTestBuildErrorWarning errorwarning;
+ errorwarning.LogLine = 1;
+ errorwarning.Text = "*** ERROR executing: ";
+ errorwarning.Text += cmsysProcess_GetErrorString(cp);
+ errorwarning.PreContext = "";
+ errorwarning.PostContext = "";
+ errorwarning.Error = true;
+ this->ErrorsAndWarnings.push_back(errorwarning);
+ this->TotalErrors ++;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "There was an error: "
+ << cmsysProcess_GetErrorString(cp) << std::endl);
+ }
+
+ cmsysProcess_Delete(cp);
+ return result;
+}
+
+//######################################################################
+//######################################################################
+//######################################################################
+//######################################################################
+
+//----------------------------------------------------------------------
+void cmCTestBuildHandler::ProcessBuffer(const char* data, int length,
+ size_t& tick, size_t tick_len, std::ostream& ofs,
+ t_BuildProcessingQueueType* queue)
+{
+ const std::string::size_type tick_line_len = 50;
+ const char* ptr;
+ for ( ptr = data; ptr < data+length; ptr ++ )
+ {
+ queue->push_back(*ptr);
+ }
+ this->BuildOutputLogSize += length;
+
+ // until there are any lines left in the buffer
+ while ( 1 )
+ {
+ // Find the end of line
+ t_BuildProcessingQueueType::iterator it;
+ for ( it = queue->begin();
+ it != queue->end();
+ ++ it )
+ {
+ if ( *it == '\n' )
+ {
+ break;
+ }
+ }
+
+ // Once certain number of errors or warnings reached, ignore future errors
+ // or warnings.
+ if ( this->TotalWarnings >= this->MaxWarnings )
+ {
+ this->WarningQuotaReached = true;
+ }
+ if ( this->TotalErrors >= this->MaxErrors )
+ {
+ this->ErrorQuotaReached = true;
+ }
+
+ // If the end of line was found
+ if ( it != queue->end() )
+ {
+ // Create a contiguous array for the line
+ this->CurrentProcessingLine.clear();
+ t_BuildProcessingQueueType::iterator cit;
+ for ( cit = queue->begin(); cit != it; ++cit )
+ {
+ this->CurrentProcessingLine.push_back(*cit);
+ }
+ this->CurrentProcessingLine.push_back(0);
+ const char* line = &*this->CurrentProcessingLine.begin();
+
+ // Process the line
+ int lineType = this->ProcessSingleLine(line);
+
+ // Erase the line from the queue
+ queue->erase(queue->begin(), it+1);
+
+ // Depending on the line type, produce error or warning, or nothing
+ cmCTestBuildErrorWarning errorwarning;
+ bool found = false;
+ switch ( lineType )
+ {
+ case b_WARNING_LINE:
+ this->LastTickChar = '*';
+ errorwarning.Error = false;
+ found = true;
+ this->TotalWarnings ++;
+ break;
+ case b_ERROR_LINE:
+ this->LastTickChar = '!';
+ errorwarning.Error = true;
+ found = true;
+ this->TotalErrors ++;
+ break;
+ }
+ if ( found )
+ {
+ // This is an error or warning, so generate report
+ errorwarning.LogLine = static_cast<int>(this->OutputLineCounter+1);
+ errorwarning.Text = line;
+ errorwarning.PreContext = "";
+ errorwarning.PostContext = "";
+
+ // Copy pre-context to report
+ std::deque<std::string>::iterator pcit;
+ for ( pcit = this->PreContext.begin();
+ pcit != this->PreContext.end();
+ ++pcit )
+ {
+ errorwarning.PreContext += *pcit + "\n";
+ }
+ this->PreContext.clear();
+
+ // Store report
+ this->ErrorsAndWarnings.push_back(errorwarning);
+ this->LastErrorOrWarning = this->ErrorsAndWarnings.end()-1;
+ this->PostContextCount = 0;
+ }
+ else
+ {
+ // This is not an error or warning.
+ // So, figure out if this is a post-context line
+ if ( this->ErrorsAndWarnings.size() &&
+ this->LastErrorOrWarning != this->ErrorsAndWarnings.end() &&
+ this->PostContextCount < this->MaxPostContext )
+ {
+ this->PostContextCount ++;
+ this->LastErrorOrWarning->PostContext += line;
+ if ( this->PostContextCount < this->MaxPostContext )
+ {
+ this->LastErrorOrWarning->PostContext += "\n";
+ }
+ }
+ else
+ {
+ // Otherwise store pre-context for the next error
+ this->PreContext.push_back(line);
+ if ( this->PreContext.size() > this->MaxPreContext )
+ {
+ this->PreContext.erase(this->PreContext.begin(),
+ this->PreContext.end()-this->MaxPreContext);
+ }
+ }
+ }
+ this->OutputLineCounter ++;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ // Now that the buffer is processed, display missing ticks
+ int tickDisplayed = false;
+ while ( this->BuildOutputLogSize > (tick * tick_len) )
+ {
+ tick ++;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, this->LastTickChar);
+ tickDisplayed = true;
+ if ( tick % tick_line_len == 0 && tick > 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Size: "
+ << ((this->BuildOutputLogSize + 512) / 1024) << "K" << std::endl
+ << " ");
+ }
+ }
+ if ( tickDisplayed )
+ {
+ this->LastTickChar = '.';
+ }
+
+ // And if this is verbose output, display the content of the chunk
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ cmCTestLogWrite(data, length));
+
+ // Always store the chunk to the file
+ ofs << cmCTestLogWrite(data, length);
+}
+
+//----------------------------------------------------------------------
+int cmCTestBuildHandler::ProcessSingleLine(const char* data)
+{
+ if(this->UseCTestLaunch)
+ {
+ // No log scraping when using launchers.
+ return b_REGULAR_LINE;
+ }
+
+ cmCTestLog(this->CTest, DEBUG, "Line: [" << data << "]" << std::endl);
+
+ std::vector<cmsys::RegularExpression>::iterator it;
+
+ int warningLine = 0;
+ int errorLine = 0;
+
+ // Check for regular expressions
+
+ if ( !this->ErrorQuotaReached )
+ {
+ // Errors
+ int wrxCnt = 0;
+ for ( it = this->ErrorMatchRegex.begin();
+ it != this->ErrorMatchRegex.end();
+ ++ it )
+ {
+ if ( it->find(data) )
+ {
+ errorLine = 1;
+ cmCTestLog(this->CTest, DEBUG, " Error Line: " << data
+ << " (matches: " << this->CustomErrorMatches[wrxCnt] << ")"
+ << std::endl);
+ break;
+ }
+ wrxCnt ++;
+ }
+ // Error exceptions
+ wrxCnt = 0;
+ for ( it = this->ErrorExceptionRegex.begin();
+ it != this->ErrorExceptionRegex.end();
+ ++ it )
+ {
+ if ( it->find(data) )
+ {
+ errorLine = 0;
+ cmCTestLog(this->CTest, DEBUG, " Not an error Line: " << data
+ << " (matches: " << this->CustomErrorExceptions[wrxCnt] << ")"
+ << std::endl);
+ break;
+ }
+ wrxCnt ++;
+ }
+ }
+ if ( !this->WarningQuotaReached )
+ {
+ // Warnings
+ int wrxCnt = 0;
+ for ( it = this->WarningMatchRegex.begin();
+ it != this->WarningMatchRegex.end();
+ ++ it )
+ {
+ if ( it->find(data) )
+ {
+ warningLine = 1;
+ cmCTestLog(this->CTest, DEBUG,
+ " Warning Line: " << data
+ << " (matches: " << this->CustomWarningMatches[wrxCnt] << ")"
+ << std::endl);
+ break;
+ }
+ wrxCnt ++;
+ }
+
+ wrxCnt = 0;
+ // Warning exceptions
+ for ( it = this->WarningExceptionRegex.begin();
+ it != this->WarningExceptionRegex.end();
+ ++ it )
+ {
+ if ( it->find(data) )
+ {
+ warningLine = 0;
+ cmCTestLog(this->CTest, DEBUG, " Not a warning Line: " << data
+ << " (matches: " << this->CustomWarningExceptions[wrxCnt] << ")"
+ << std::endl);
+ break;
+ }
+ wrxCnt ++;
+ }
+ }
+ if ( errorLine )
+ {
+ return b_ERROR_LINE;
+ }
+ if ( warningLine )
+ {
+ return b_WARNING_LINE;
+ }
+ return b_REGULAR_LINE;
+}
+
diff --git a/Source/CTest/cmCTestBuildHandler.h b/Source/CTest/cmCTestBuildHandler.h
new file mode 100644
index 0000000000..09346f9498
--- /dev/null
+++ b/Source/CTest/cmCTestBuildHandler.h
@@ -0,0 +1,152 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestBuildHandler_h
+#define cmCTestBuildHandler_h
+
+
+#include "cmCTestGenericHandler.h"
+#include "cmListFileCache.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+class cmMakefile;
+
+/** \class cmCTestBuildHandler
+ * \brief A class that handles ctest -S invocations
+ *
+ */
+class cmCTestBuildHandler : public cmCTestGenericHandler
+{
+public:
+ cmTypeMacro(cmCTestBuildHandler, cmCTestGenericHandler);
+
+ /*
+ * The main entry point for this class
+ */
+ int ProcessHandler();
+
+ cmCTestBuildHandler();
+
+ void PopulateCustomVectors(cmMakefile *mf);
+
+ /**
+ * Initialize handler
+ */
+ virtual void Initialize();
+
+ int GetTotalErrors() { return this->TotalErrors;}
+ int GetTotalWarnings() { return this->TotalWarnings;}
+
+private:
+ std::string GetMakeCommand();
+
+ //! Run command specialized for make and configure. Returns process status
+ // and retVal is return value or exception.
+ int RunMakeCommand(const char* command,
+ int* retVal, const char* dir, int timeout,
+ std::ostream& ofs);
+
+ enum {
+ b_REGULAR_LINE,
+ b_WARNING_LINE,
+ b_ERROR_LINE
+ };
+
+ class cmCTestCompileErrorWarningRex
+ {
+ public:
+ cmCTestCompileErrorWarningRex() {}
+ int FileIndex;
+ int LineIndex;
+ cmsys::RegularExpression RegularExpression;
+ };
+
+ struct cmCTestBuildErrorWarning
+ {
+ bool Error;
+ int LogLine;
+ std::string Text;
+ std::string SourceFile;
+ std::string SourceFileTail;
+ int LineNumber;
+ std::string PreContext;
+ std::string PostContext;
+ };
+
+ // generate the XML output
+ void GenerateXMLHeader(std::ostream& os);
+ void GenerateXMLLaunched(std::ostream& os);
+ void GenerateXMLLogScraped(std::ostream& os);
+ void GenerateXMLFooter(std::ostream& os, double elapsed_build_time);
+ void GenerateXMLLaunchedFragment(std::ostream& os, const char* fname);
+ bool IsLaunchedErrorFile(const char* fname);
+ bool IsLaunchedWarningFile(const char* fname);
+
+ std::string StartBuild;
+ std::string EndBuild;
+ double StartBuildTime;
+ double EndBuildTime;
+
+ std::vector<std::string> CustomErrorMatches;
+ std::vector<std::string> CustomErrorExceptions;
+ std::vector<std::string> CustomWarningMatches;
+ std::vector<std::string> CustomWarningExceptions;
+ std::vector<std::string> ReallyCustomWarningMatches;
+ std::vector<std::string> ReallyCustomWarningExceptions;
+ std::vector<cmCTestCompileErrorWarningRex> ErrorWarningFileLineRegex;
+
+ std::vector<cmsys::RegularExpression> ErrorMatchRegex;
+ std::vector<cmsys::RegularExpression> ErrorExceptionRegex;
+ std::vector<cmsys::RegularExpression> WarningMatchRegex;
+ std::vector<cmsys::RegularExpression> WarningExceptionRegex;
+
+ typedef std::deque<char> t_BuildProcessingQueueType;
+
+ void ProcessBuffer(const char* data, int length, size_t& tick,
+ size_t tick_len, std::ostream& ofs, t_BuildProcessingQueueType* queue);
+ int ProcessSingleLine(const char* data);
+
+ t_BuildProcessingQueueType BuildProcessingQueue;
+ t_BuildProcessingQueueType BuildProcessingErrorQueue;
+ size_t BuildOutputLogSize;
+ std::vector<char> CurrentProcessingLine;
+
+ std::string SimplifySourceDir;
+ std::string SimplifyBuildDir;
+ size_t OutputLineCounter;
+ typedef std::vector<cmCTestBuildErrorWarning> t_ErrorsAndWarningsVector;
+ t_ErrorsAndWarningsVector ErrorsAndWarnings;
+ t_ErrorsAndWarningsVector::iterator LastErrorOrWarning;
+ size_t PostContextCount;
+ size_t MaxPreContext;
+ size_t MaxPostContext;
+ std::deque<std::string> PreContext;
+
+ int TotalErrors;
+ int TotalWarnings;
+ char LastTickChar;
+
+ bool ErrorQuotaReached;
+ bool WarningQuotaReached;
+
+ int MaxErrors;
+ int MaxWarnings;
+
+ bool UseCTestLaunch;
+ std::string CTestLaunchDir;
+ class LaunchHelper;
+ friend class LaunchHelper;
+ class FragmentCompare;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx
new file mode 100644
index 0000000000..ab363d0164
--- /dev/null
+++ b/Source/CTest/cmCTestCVS.cxx
@@ -0,0 +1,320 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestCVS.h"
+
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/FStream.hxx>
+
+//----------------------------------------------------------------------------
+cmCTestCVS::cmCTestCVS(cmCTest* ct, std::ostream& log): cmCTestVC(ct, log)
+{
+}
+
+//----------------------------------------------------------------------------
+cmCTestCVS::~cmCTestCVS()
+{
+}
+
+//----------------------------------------------------------------------------
+class cmCTestCVS::UpdateParser: public cmCTestVC::LineParser
+{
+public:
+ UpdateParser(cmCTestCVS* cvs, const char* prefix): CVS(cvs)
+ {
+ this->SetLog(&cvs->Log, prefix);
+ // See "man cvs", section "update output".
+ this->RegexFileUpdated.compile("^([UP]) *(.*)");
+ this->RegexFileModified.compile("^([MRA]) *(.*)");
+ this->RegexFileConflicting.compile("^([C]) *(.*)");
+ this->RegexFileRemoved1.compile(
+ "cvs[^ ]* update: `?([^']*)'? is no longer in the repository");
+ this->RegexFileRemoved2.compile(
+ "cvs[^ ]* update: "
+ "warning: `?([^']*)'? is not \\(any longer\\) pertinent");
+ }
+private:
+ cmCTestCVS* CVS;
+ cmsys::RegularExpression RegexFileUpdated;
+ cmsys::RegularExpression RegexFileModified;
+ cmsys::RegularExpression RegexFileConflicting;
+ cmsys::RegularExpression RegexFileRemoved1;
+ cmsys::RegularExpression RegexFileRemoved2;
+
+ virtual bool ProcessLine()
+ {
+ if(this->RegexFileUpdated.find(this->Line))
+ {
+ this->DoFile(PathUpdated, this->RegexFileUpdated.match(2));
+ }
+ else if(this->RegexFileModified.find(this->Line))
+ {
+ this->DoFile(PathModified, this->RegexFileModified.match(2));
+ }
+ else if(this->RegexFileConflicting.find(this->Line))
+ {
+ this->DoFile(PathConflicting, this->RegexFileConflicting.match(2));
+ }
+ else if(this->RegexFileRemoved1.find(this->Line))
+ {
+ this->DoFile(PathUpdated, this->RegexFileRemoved1.match(1));
+ }
+ else if(this->RegexFileRemoved2.find(this->Line))
+ {
+ this->DoFile(PathUpdated, this->RegexFileRemoved2.match(1));
+ }
+ return true;
+ }
+
+ void DoFile(PathStatus status, std::string const& file)
+ {
+ std::string dir = cmSystemTools::GetFilenamePath(file);
+ std::string name = cmSystemTools::GetFilenameName(file);
+ this->CVS->Dirs[dir][name] = status;
+ }
+};
+
+//----------------------------------------------------------------------------
+bool cmCTestCVS::UpdateImpl()
+{
+ // Get user-specified update options.
+ std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
+ if(opts.empty())
+ {
+ opts = this->CTest->GetCTestConfiguration("CVSUpdateOptions");
+ if(opts.empty())
+ {
+ opts = "-dP";
+ }
+ }
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
+
+ // Specify the start time for nightly testing.
+ if(this->CTest->GetTestModel() == cmCTest::NIGHTLY)
+ {
+ args.push_back("-D" + this->GetNightlyTime() + " UTC");
+ }
+
+ // Run "cvs update" to update the work tree.
+ std::vector<char const*> cvs_update;
+ cvs_update.push_back(this->CommandLineTool.c_str());
+ cvs_update.push_back("-z3");
+ cvs_update.push_back("update");
+ for(std::vector<std::string>::const_iterator ai = args.begin();
+ ai != args.end(); ++ai)
+ {
+ cvs_update.push_back(ai->c_str());
+ }
+ cvs_update.push_back(0);
+
+ UpdateParser out(this, "up-out> ");
+ UpdateParser err(this, "up-err> ");
+ return this->RunUpdateCommand(&cvs_update[0], &out, &err);
+}
+
+//----------------------------------------------------------------------------
+class cmCTestCVS::LogParser: public cmCTestVC::LineParser
+{
+public:
+ typedef cmCTestCVS::Revision Revision;
+ LogParser(cmCTestCVS* cvs, const char* prefix, std::vector<Revision>& revs):
+ CVS(cvs), Revisions(revs), Section(SectionHeader)
+ {
+ this->SetLog(&cvs->Log, prefix),
+ this->RegexRevision.compile("^revision +([^ ]*) *$");
+ this->RegexBranches.compile("^branches: .*$");
+ this->RegexPerson.compile("^date: +([^;]+); +author: +([^;]+);");
+ }
+private:
+ cmCTestCVS* CVS;
+ std::vector<Revision>& Revisions;
+ cmsys::RegularExpression RegexRevision;
+ cmsys::RegularExpression RegexBranches;
+ cmsys::RegularExpression RegexPerson;
+ enum SectionType { SectionHeader, SectionRevisions, SectionEnd };
+ SectionType Section;
+ Revision Rev;
+
+ virtual bool ProcessLine()
+ {
+ if(this->Line == ("======================================="
+ "======================================"))
+ {
+ // This line ends the revision list.
+ if(this->Section == SectionRevisions)
+ {
+ this->FinishRevision();
+ }
+ this->Section = SectionEnd;
+ }
+ else if(this->Line == "----------------------------")
+ {
+ // This line divides revisions from the header and each other.
+ if(this->Section == SectionHeader)
+ {
+ this->Section = SectionRevisions;
+ }
+ else if(this->Section == SectionRevisions)
+ {
+ this->FinishRevision();
+ }
+ }
+ else if(this->Section == SectionRevisions)
+ {
+ if(!this->Rev.Log.empty())
+ {
+ // Continue the existing log.
+ this->Rev.Log += this->Line;
+ this->Rev.Log += "\n";
+ }
+ else if(this->Rev.Rev.empty() && this->RegexRevision.find(this->Line))
+ {
+ this->Rev.Rev = this->RegexRevision.match(1);
+ }
+ else if(this->Rev.Date.empty() && this->RegexPerson.find(this->Line))
+ {
+ this->Rev.Date = this->RegexPerson.match(1);
+ this->Rev.Author = this->RegexPerson.match(2);
+ }
+ else if(!this->RegexBranches.find(this->Line))
+ {
+ // Start the log.
+ this->Rev.Log += this->Line;
+ this->Rev.Log += "\n";
+ }
+ }
+ return this->Section != SectionEnd;
+ }
+
+ void FinishRevision()
+ {
+ if(!this->Rev.Rev.empty())
+ {
+ // Record this revision.
+ this->CVS->Log << "Found revision " << this->Rev.Rev << "\n"
+ << " author = " << this->Rev.Author << "\n"
+ << " date = " << this->Rev.Date << "\n";
+ this->Revisions.push_back(this->Rev);
+
+ // We only need two revisions.
+ if(this->Revisions.size() >= 2)
+ {
+ this->Section = SectionEnd;
+ }
+ }
+ this->Rev = Revision();
+ }
+};
+
+//----------------------------------------------------------------------------
+std::string cmCTestCVS::ComputeBranchFlag(std::string const& dir)
+{
+ // Compute the tag file location for this directory.
+ std::string tagFile = this->SourceDirectory;
+ if(!dir.empty())
+ {
+ tagFile += "/";
+ tagFile += dir;
+ }
+ tagFile += "/CVS/Tag";
+
+ // Lookup the branch in the tag file, if any.
+ std::string tagLine;
+ cmsys::ifstream tagStream(tagFile.c_str());
+ if(tagStream && cmSystemTools::GetLineFromStream(tagStream, tagLine) &&
+ tagLine.size() > 1 && tagLine[0] == 'T')
+ {
+ // Use the branch specified in the tag file.
+ std::string flag = "-r";
+ flag += tagLine.substr(1);
+ return flag;
+ }
+ else
+ {
+ // Use the default branch.
+ return "-b";
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestCVS::LoadRevisions(std::string const& file,
+ const char* branchFlag,
+ std::vector<Revision>& revisions)
+{
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
+
+ // Run "cvs log" to get revisions of this file on this branch.
+ const char* cvs = this->CommandLineTool.c_str();
+ const char* cvs_log[] =
+ {cvs, "log", "-N", branchFlag, file.c_str(), 0};
+
+ LogParser out(this, "log-out> ", revisions);
+ OutputLogger err(this->Log, "log-err> ");
+ this->RunChild(cvs_log, &out, &err);
+}
+
+//----------------------------------------------------------------------------
+void cmCTestCVS::WriteXMLDirectory(std::ostream& xml,
+ std::string const& path,
+ Directory const& dir)
+{
+ const char* slash = path.empty()? "":"/";
+ xml << "\t<Directory>\n"
+ << "\t\t<Name>" << cmXMLSafe(path) << "</Name>\n";
+
+ // Lookup the branch checked out in the working tree.
+ std::string branchFlag = this->ComputeBranchFlag(path);
+
+ // Load revisions and write an entry for each file in this directory.
+ std::vector<Revision> revisions;
+ for(Directory::const_iterator fi = dir.begin(); fi != dir.end(); ++fi)
+ {
+ std::string full = path + slash + fi->first;
+
+ // Load two real or unknown revisions.
+ revisions.clear();
+ if(fi->second != PathUpdated)
+ {
+ // For local modifications the current rev is unknown and the
+ // prior rev is the latest from cvs.
+ revisions.push_back(this->Unknown);
+ }
+ this->LoadRevisions(full, branchFlag.c_str(), revisions);
+ revisions.resize(2, this->Unknown);
+
+ // Write the entry for this file with these revisions.
+ File f(fi->second, &revisions[0], &revisions[1]);
+ this->WriteXMLEntry(xml, path, fi->first, full, f);
+ }
+ xml << "\t</Directory>\n";
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestCVS::WriteXMLUpdates(std::ostream& xml)
+{
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Gathering version information (one . per updated file):\n"
+ " " << std::flush);
+
+ for(std::map<std::string, Directory>::const_iterator
+ di = this->Dirs.begin(); di != this->Dirs.end(); ++di)
+ {
+ this->WriteXMLDirectory(xml, di->first, di->second);
+ }
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
+
+ return true;
+}
diff --git a/Source/CTest/cmCTestCVS.h b/Source/CTest/cmCTestCVS.h
new file mode 100644
index 0000000000..64e1747d1f
--- /dev/null
+++ b/Source/CTest/cmCTestCVS.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestCVS_h
+#define cmCTestCVS_h
+
+#include "cmCTestVC.h"
+
+/** \class cmCTestCVS
+ * \brief Interaction with cvs command-line tool
+ *
+ */
+class cmCTestCVS: public cmCTestVC
+{
+public:
+ /** Construct with a CTest instance and update log stream. */
+ cmCTestCVS(cmCTest* ctest, std::ostream& log);
+
+ virtual ~cmCTestCVS();
+
+private:
+ // Implement cmCTestVC internal API.
+ virtual bool UpdateImpl();
+ virtual bool WriteXMLUpdates(std::ostream& xml);
+
+ // Update status for files in each directory.
+ class Directory: public std::map<std::string, PathStatus> {};
+ std::map<std::string, Directory> Dirs;
+
+ std::string ComputeBranchFlag(std::string const& dir);
+ void LoadRevisions(std::string const& file, const char* branchFlag,
+ std::vector<Revision>& revisions);
+ void WriteXMLDirectory(std::ostream& xml, std::string const& path,
+ Directory const& dir);
+
+ // Parsing helper classes.
+ class UpdateParser;
+ class LogParser;
+ friend class UpdateParser;
+ friend class LogParser;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestCommand.h b/Source/CTest/cmCTestCommand.h
new file mode 100644
index 0000000000..e2ebba8fdc
--- /dev/null
+++ b/Source/CTest/cmCTestCommand.h
@@ -0,0 +1,40 @@
+/*============================================================================
+ 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 cmCTestCommand_h
+#define cmCTestCommand_h
+
+#include "cmCommand.h"
+
+class cmCTest;
+class cmCTestScriptHandler;
+
+/** \class cmCTestCommand
+ * \brief A superclass for all commands added to the CTestScriptHandler
+ *
+ * cmCTestCommand is the superclass for all commands that will be added to
+ * the ctest script handlers parser.
+ *
+ */
+class cmCTestCommand : public cmCommand
+{
+public:
+
+ cmCTestCommand() {this->CTest = 0; this->CTestScriptHandler = 0;}
+
+ cmCTest *CTest;
+ cmCTestScriptHandler *CTestScriptHandler;
+
+ cmTypeMacro(cmCTestCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestConfigureCommand.cxx b/Source/CTest/cmCTestConfigureCommand.cxx
new file mode 100644
index 0000000000..ef62fd3728
--- /dev/null
+++ b/Source/CTest/cmCTestConfigureCommand.cxx
@@ -0,0 +1,164 @@
+/*============================================================================
+ 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 "cmCTestConfigureCommand.h"
+
+#include "cmGlobalGenerator.h"
+#include "cmCTest.h"
+#include "cmCTestGenericHandler.h"
+
+cmCTestConfigureCommand::cmCTestConfigureCommand()
+{
+ this->Arguments[ctc_OPTIONS] = "OPTIONS";
+ this->Arguments[ctc_LAST] = 0;
+ this->Last = ctc_LAST;
+}
+
+cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
+{
+ std::vector<std::string> options;
+
+ if (this->Values[ctc_OPTIONS])
+ {
+ cmSystemTools::ExpandListArgument(this->Values[ctc_OPTIONS], options);
+ }
+
+ if ( this->CTest->GetCTestConfiguration("BuildDirectory").empty() )
+ {
+ this->SetError("Build directory not specified. Either use BUILD "
+ "argument to CTEST_CONFIGURE command or set CTEST_BINARY_DIRECTORY "
+ "variable");
+ return 0;
+ }
+
+ const char* ctestConfigureCommand
+ = this->Makefile->GetDefinition("CTEST_CONFIGURE_COMMAND");
+
+ if ( ctestConfigureCommand && *ctestConfigureCommand )
+ {
+ this->CTest->SetCTestConfiguration("ConfigureCommand",
+ ctestConfigureCommand);
+ }
+ else
+ {
+ const char* cmakeGeneratorName
+ = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
+ if ( cmakeGeneratorName && *cmakeGeneratorName )
+ {
+ const std::string& source_dir
+ = this->CTest->GetCTestConfiguration("SourceDirectory");
+ if ( source_dir.empty() )
+ {
+ this->SetError("Source directory not specified. Either use SOURCE "
+ "argument to CTEST_CONFIGURE command or set CTEST_SOURCE_DIRECTORY "
+ "variable");
+ return 0;
+ }
+
+ const std::string cmakelists_file = source_dir + "/CMakeLists.txt";
+ if ( !cmSystemTools::FileExists(cmakelists_file.c_str()) )
+ {
+ cmOStringStream e;
+ e << "CMakeLists.txt file does not exist ["
+ << cmakelists_file << "]";
+ this->SetError(e.str());
+ return 0;
+ }
+
+ bool multiConfig = false;
+ bool cmakeBuildTypeInOptions = false;
+
+ cmGlobalGenerator *gg =
+ this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
+ cmakeGeneratorName);
+ if(gg)
+ {
+ multiConfig = gg->IsMultiConfig();
+ delete gg;
+ }
+
+ std::string cmakeConfigureCommand = "\"";
+ cmakeConfigureCommand += cmSystemTools::GetCMakeCommand();
+ cmakeConfigureCommand += "\"";
+
+ std::vector<std::string>::const_iterator it;
+ std::string option;
+ for (it= options.begin(); it!=options.end(); ++it)
+ {
+ option = *it;
+
+ cmakeConfigureCommand += " \"";
+ cmakeConfigureCommand += option;
+ cmakeConfigureCommand += "\"";
+
+ if ((0 != strstr(option.c_str(), "CMAKE_BUILD_TYPE=")) ||
+ (0 != strstr(option.c_str(), "CMAKE_BUILD_TYPE:STRING=")))
+ {
+ cmakeBuildTypeInOptions = true;
+ }
+ }
+
+ if (!multiConfig && !cmakeBuildTypeInOptions &&
+ !this->CTest->GetConfigType().empty())
+ {
+ cmakeConfigureCommand += " \"-DCMAKE_BUILD_TYPE:STRING=";
+ cmakeConfigureCommand += this->CTest->GetConfigType();
+ cmakeConfigureCommand += "\"";
+ }
+
+ cmakeConfigureCommand += " \"-G";
+ cmakeConfigureCommand += cmakeGeneratorName;
+ cmakeConfigureCommand += "\"";
+
+ const char* cmakeGeneratorPlatform =
+ this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR_PLATFORM");
+ if(cmakeGeneratorPlatform && *cmakeGeneratorPlatform)
+ {
+ cmakeConfigureCommand += " \"-A";
+ cmakeConfigureCommand += cmakeGeneratorPlatform;
+ cmakeConfigureCommand += "\"";
+ }
+
+ const char* cmakeGeneratorToolset =
+ this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR_TOOLSET");
+ if(cmakeGeneratorToolset && *cmakeGeneratorToolset)
+ {
+ cmakeConfigureCommand += " \"-T";
+ cmakeConfigureCommand += cmakeGeneratorToolset;
+ cmakeConfigureCommand += "\"";
+ }
+
+ cmakeConfigureCommand += " \"";
+ cmakeConfigureCommand += source_dir;
+ cmakeConfigureCommand += "\"";
+
+ this->CTest->SetCTestConfiguration("ConfigureCommand",
+ cmakeConfigureCommand.c_str());
+ }
+ else
+ {
+ this->SetError("Configure command is not specified. If this is a "
+ "\"built with CMake\" project, set CTEST_CMAKE_GENERATOR. If not, "
+ "set CTEST_CONFIGURE_COMMAND.");
+ return 0;
+ }
+ }
+
+ cmCTestGenericHandler* handler
+ = this->CTest->GetInitializedHandler("configure");
+ if ( !handler )
+ {
+ this->SetError(
+ "internal CTest error. Cannot instantiate configure handler");
+ return 0;
+ }
+ return handler;
+}
diff --git a/Source/CTest/cmCTestConfigureCommand.h b/Source/CTest/cmCTestConfigureCommand.h
new file mode 100644
index 0000000000..7941d4e3c9
--- /dev/null
+++ b/Source/CTest/cmCTestConfigureCommand.h
@@ -0,0 +1,56 @@
+/*============================================================================
+ 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 cmCTestConfigureCommand_h
+#define cmCTestConfigureCommand_h
+
+#include "cmCTestHandlerCommand.h"
+
+/** \class cmCTestConfigure
+ * \brief Run a ctest script
+ *
+ * cmCTestConfigureCommand defineds the command to configures the project.
+ */
+class cmCTestConfigureCommand : public cmCTestHandlerCommand
+{
+public:
+ cmCTestConfigureCommand();
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestConfigureCommand* ni = new cmCTestConfigureCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_configure";}
+
+ cmTypeMacro(cmCTestConfigureCommand, cmCTestHandlerCommand);
+
+protected:
+ cmCTestGenericHandler* InitializeHandler();
+
+ enum {
+ ctc_FIRST = ct_LAST,
+ ctc_OPTIONS,
+ ctc_LAST
+ };
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestConfigureHandler.cxx b/Source/CTest/cmCTestConfigureHandler.cxx
new file mode 100644
index 0000000000..c492bf0c31
--- /dev/null
+++ b/Source/CTest/cmCTestConfigureHandler.cxx
@@ -0,0 +1,132 @@
+/*============================================================================
+ 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 "cmCTestConfigureHandler.h"
+
+#include "cmCTest.h"
+#include "cmGeneratedFileStream.h"
+#include "cmake.h"
+#include "cmXMLSafe.h"
+#include <cmsys/Process.h>
+
+
+//----------------------------------------------------------------------
+cmCTestConfigureHandler::cmCTestConfigureHandler()
+{
+}
+
+//----------------------------------------------------------------------
+void cmCTestConfigureHandler::Initialize()
+{
+ this->Superclass::Initialize();
+}
+
+//----------------------------------------------------------------------
+//clearly it would be nice if this were broken up into a few smaller
+//functions and commented...
+int cmCTestConfigureHandler::ProcessHandler()
+{
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Configure project" << std::endl);
+ std::string cCommand
+ = this->CTest->GetCTestConfiguration("ConfigureCommand");
+ if ( cCommand.size() == 0 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
+ << std::endl);
+ return -1;
+ }
+
+ std::string buildDirectory
+ = this->CTest->GetCTestConfiguration("BuildDirectory");
+ if ( buildDirectory.size() == 0 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find BuildDirectory key in the DartConfiguration.tcl"
+ << std::endl);
+ return -1;
+ }
+
+ double elapsed_time_start = cmSystemTools::GetTime();
+ std::string output;
+ int retVal = 0;
+ int res = 0;
+ if ( !this->CTest->GetShowOnly() )
+ {
+ cmGeneratedFileStream os;
+ if(!this->StartResultingXML(cmCTest::PartConfigure, "Configure", os))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open configure file"
+ << std::endl);
+ return 1;
+ }
+ std::string start_time = this->CTest->CurrentTime();
+ unsigned int start_time_time = static_cast<unsigned int>(
+ cmSystemTools::GetTime());
+
+ cmGeneratedFileStream ofs;
+ this->StartLogFile("Configure", ofs);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Configure with command: "
+ << cCommand << std::endl);
+ res = this->CTest->RunMakeCommand(cCommand.c_str(), output,
+ &retVal, buildDirectory.c_str(),
+ 0, ofs);
+
+ if ( ofs )
+ {
+ ofs.close();
+ }
+
+ if ( os )
+ {
+ this->CTest->StartXML(os, this->AppendXML);
+ os << "<Configure>\n"
+ << "\t<StartDateTime>" << start_time << "</StartDateTime>"
+ << std::endl
+ << "\t<StartConfigureTime>" << start_time_time
+ << "</StartConfigureTime>\n";
+
+ if ( res == cmsysProcess_State_Exited && retVal )
+ {
+ os << retVal;
+ }
+ os << "<ConfigureCommand>" << cCommand << "</ConfigureCommand>"
+ << std::endl;
+ cmCTestLog(this->CTest, DEBUG, "End" << std::endl);
+ os << "<Log>" << cmXMLSafe(output) << "</Log>" << std::endl;
+ std::string end_time = this->CTest->CurrentTime();
+ os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
+ << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
+ << "\t<EndConfigureTime>" <<
+ static_cast<unsigned int>(cmSystemTools::GetTime())
+ << "</EndConfigureTime>\n"
+ << "<ElapsedMinutes>"
+ << static_cast<int>(
+ (cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
+ << "</ElapsedMinutes>"
+ << "</Configure>" << std::endl;
+ this->CTest->EndXML(os);
+ }
+ }
+ else
+ {
+ cmCTestLog(this->CTest, DEBUG, "Configure with command: " << cCommand
+ << std::endl);
+ }
+ if (! res || retVal )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error(s) when configuring the project" << std::endl);
+ return -1;
+ }
+ return 0;
+}
diff --git a/Source/CTest/cmCTestConfigureHandler.h b/Source/CTest/cmCTestConfigureHandler.h
new file mode 100644
index 0000000000..d880bd7df6
--- /dev/null
+++ b/Source/CTest/cmCTestConfigureHandler.h
@@ -0,0 +1,39 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestConfigureHandler_h
+#define cmCTestConfigureHandler_h
+
+
+#include "cmCTestGenericHandler.h"
+#include "cmListFileCache.h"
+
+/** \class cmCTestConfigureHandler
+ * \brief A class that handles ctest -S invocations
+ *
+ */
+class cmCTestConfigureHandler : public cmCTestGenericHandler
+{
+public:
+ cmTypeMacro(cmCTestConfigureHandler, cmCTestGenericHandler);
+
+ /*
+ * The main entry point for this class
+ */
+ int ProcessHandler();
+
+ cmCTestConfigureHandler();
+
+ void Initialize();
+};
+
+#endif
diff --git a/Source/CTest/cmCTestCoverageCommand.cxx b/Source/CTest/cmCTestCoverageCommand.cxx
new file mode 100644
index 0000000000..41f016bb95
--- /dev/null
+++ b/Source/CTest/cmCTestCoverageCommand.cxx
@@ -0,0 +1,74 @@
+/*============================================================================
+ 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 "cmCTestCoverageCommand.h"
+
+#include "cmCTest.h"
+#include "cmCTestCoverageHandler.h"
+
+//----------------------------------------------------------------------------
+cmCTestCoverageCommand::cmCTestCoverageCommand()
+{
+ this->LabelsMentioned = false;
+}
+
+//----------------------------------------------------------------------------
+cmCTestGenericHandler* cmCTestCoverageCommand::InitializeHandler()
+{
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "CoverageCommand", "CTEST_COVERAGE_COMMAND");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "CoverageExtraFlags", "CTEST_COVERAGE_EXTRA_FLAGS");
+ cmCTestCoverageHandler* handler = static_cast<cmCTestCoverageHandler*>(
+ this->CTest->GetInitializedHandler("coverage"));
+ if ( !handler )
+ {
+ this->SetError("internal CTest error. Cannot instantiate test handler");
+ return 0;
+ }
+
+ // If a LABELS option was given, select only files with the labels.
+ if(this->LabelsMentioned)
+ {
+ handler->SetLabelFilter(this->Labels);
+ }
+
+ return handler;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestCoverageCommand::CheckArgumentKeyword(std::string const& arg)
+{
+ // Look for arguments specific to this command.
+ if(arg == "LABELS")
+ {
+ this->ArgumentDoing = ArgumentDoingLabels;
+ this->LabelsMentioned = true;
+ return true;
+ }
+
+ // Look for other arguments.
+ return this->Superclass::CheckArgumentKeyword(arg);
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestCoverageCommand::CheckArgumentValue(std::string const& arg)
+{
+ // Handle states specific to this command.
+ if(this->ArgumentDoing == ArgumentDoingLabels)
+ {
+ this->Labels.insert(arg);
+ return true;
+ }
+
+ // Look for other arguments.
+ return this->Superclass::CheckArgumentValue(arg);
+}
diff --git a/Source/CTest/cmCTestCoverageCommand.h b/Source/CTest/cmCTestCoverageCommand.h
new file mode 100644
index 0000000000..5762e07318
--- /dev/null
+++ b/Source/CTest/cmCTestCoverageCommand.h
@@ -0,0 +1,64 @@
+/*============================================================================
+ 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 cmCTestCoverageCommand_h
+#define cmCTestCoverageCommand_h
+
+#include "cmCTestHandlerCommand.h"
+
+/** \class cmCTestCoverage
+ * \brief Run a ctest script
+ *
+ * cmCTestCoverageCommand defineds the command to test the project.
+ */
+class cmCTestCoverageCommand : public cmCTestHandlerCommand
+{
+public:
+
+ cmCTestCoverageCommand();
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestCoverageCommand* ni = new cmCTestCoverageCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_coverage";}
+
+ cmTypeMacro(cmCTestCoverageCommand, cmCTestHandlerCommand);
+
+protected:
+ cmCTestGenericHandler* InitializeHandler();
+
+ virtual bool CheckArgumentKeyword(std::string const& arg);
+ virtual bool CheckArgumentValue(std::string const& arg);
+
+ enum
+ {
+ ArgumentDoingLabels = Superclass::ArgumentDoingLast1,
+ ArgumentDoingLast2
+ };
+
+ bool LabelsMentioned;
+ std::set<std::string> Labels;
+};
+
+
+#endif
+
diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx
new file mode 100644
index 0000000000..76f65840a2
--- /dev/null
+++ b/Source/CTest/cmCTestCoverageHandler.cxx
@@ -0,0 +1,2538 @@
+/*============================================================================
+ 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 "cmCTestCoverageHandler.h"
+#include "cmParsePHPCoverage.h"
+#include "cmParseCoberturaCoverage.h"
+#include "cmParseGTMCoverage.h"
+#include "cmParseCacheCoverage.h"
+#include "cmParseJacocoCoverage.h"
+#include "cmCTest.h"
+#include "cmake.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include "cmGeneratedFileStream.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/Process.h>
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/stl/iterator>
+#include <cmsys/stl/algorithm>
+#include <cmsys/FStream.hxx>
+
+#include <stdlib.h>
+#include <math.h>
+#include <float.h>
+
+#define SAFEDIV(x,y) (((y)!=0)?((x)/(y)):(0))
+
+class cmCTestRunProcess
+{
+public:
+ cmCTestRunProcess()
+ {
+ this->Process = cmsysProcess_New();
+ this->PipeState = -1;
+ this->TimeOut = -1;
+ }
+ ~cmCTestRunProcess()
+ {
+ if(!(this->PipeState == -1)
+ && !(this->PipeState == cmsysProcess_Pipe_None )
+ && !(this->PipeState == cmsysProcess_Pipe_Timeout))
+ {
+ this->WaitForExit();
+ }
+ cmsysProcess_Delete(this->Process);
+ }
+ void SetCommand(const char* command)
+ {
+ this->CommandLineStrings.clear();
+ this->CommandLineStrings.push_back(command);;
+ }
+ void AddArgument(const char* arg)
+ {
+ if(arg)
+ {
+ this->CommandLineStrings.push_back(arg);
+ }
+ }
+ void SetWorkingDirectory(const char* dir)
+ {
+ this->WorkingDirectory = dir;
+ }
+ void SetTimeout(double t)
+ {
+ this->TimeOut = t;
+ }
+ bool StartProcess()
+ {
+ std::vector<const char*> args;
+ for(std::vector<std::string>::iterator i =
+ this->CommandLineStrings.begin();
+ i != this->CommandLineStrings.end(); ++i)
+ {
+ args.push_back(i->c_str());
+ }
+ args.push_back(0); // null terminate
+ cmsysProcess_SetCommand(this->Process, &*args.begin());
+ if(this->WorkingDirectory.size())
+ {
+ cmsysProcess_SetWorkingDirectory(this->Process,
+ this->WorkingDirectory.c_str());
+ }
+
+ cmsysProcess_SetOption(this->Process,
+ cmsysProcess_Option_HideWindow, 1);
+ if(this->TimeOut != -1)
+ {
+ cmsysProcess_SetTimeout(this->Process, this->TimeOut);
+ }
+ cmsysProcess_Execute(this->Process);
+ this->PipeState = cmsysProcess_GetState(this->Process);
+ // if the process is running or exited return true
+ if(this->PipeState == cmsysProcess_State_Executing
+ || this->PipeState == cmsysProcess_State_Exited)
+ {
+ return true;
+ }
+ return false;
+ }
+ void SetStdoutFile(const char* fname)
+ {
+ cmsysProcess_SetPipeFile(this->Process, cmsysProcess_Pipe_STDOUT, fname);
+ }
+ void SetStderrFile(const char* fname)
+ {
+ cmsysProcess_SetPipeFile(this->Process, cmsysProcess_Pipe_STDERR, fname);
+ }
+ int WaitForExit(double* timeout =0)
+ {
+ this->PipeState = cmsysProcess_WaitForExit(this->Process,
+ timeout);
+ return this->PipeState;
+ }
+ int GetProcessState() { return this->PipeState;}
+private:
+ int PipeState;
+ cmsysProcess* Process;
+ std::vector<std::string> CommandLineStrings;
+ std::string WorkingDirectory;
+ double TimeOut;
+};
+
+
+//----------------------------------------------------------------------
+
+//----------------------------------------------------------------------
+cmCTestCoverageHandler::cmCTestCoverageHandler()
+{
+}
+
+//----------------------------------------------------------------------
+void cmCTestCoverageHandler::Initialize()
+{
+ this->Superclass::Initialize();
+ this->CustomCoverageExclude.clear();
+ this->SourceLabels.clear();
+ this->TargetDirs.clear();
+ this->LabelIdMap.clear();
+ this->Labels.clear();
+ this->LabelFilter.clear();
+}
+
+//----------------------------------------------------------------------------
+void cmCTestCoverageHandler::CleanCoverageLogFiles(std::ostream& log)
+{
+ std::string logGlob = this->CTest->GetCTestConfiguration("BuildDirectory");
+ logGlob += "/Testing/";
+ logGlob += this->CTest->GetCurrentTag();
+ logGlob += "/CoverageLog*";
+ cmsys::Glob gl;
+ gl.FindFiles(logGlob);
+ std::vector<std::string> const& files = gl.GetFiles();
+ for(std::vector<std::string>::const_iterator fi = files.begin();
+ fi != files.end(); ++fi)
+ {
+ log << "Removing old coverage log: " << *fi << "\n";
+ cmSystemTools::RemoveFile(fi->c_str());
+ }
+}
+
+//----------------------------------------------------------------------
+bool cmCTestCoverageHandler::StartCoverageLogFile(
+ cmGeneratedFileStream& covLogFile, int logFileCount)
+{
+ char covLogFilename[1024];
+ sprintf(covLogFilename, "CoverageLog-%d", logFileCount);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Open file: "
+ << covLogFilename << std::endl);
+ if(!this->StartResultingXML(cmCTest::PartCoverage,
+ covLogFilename, covLogFile))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open log file: "
+ << covLogFilename << std::endl);
+ return false;
+ }
+ std::string local_start_time = this->CTest->CurrentTime();
+ this->CTest->StartXML(covLogFile, this->AppendXML);
+ covLogFile << "<CoverageLog>" << std::endl
+ << "\t<StartDateTime>" << local_start_time << "</StartDateTime>"
+ << "\t<StartTime>"
+ << static_cast<unsigned int>(cmSystemTools::GetTime())
+ << "</StartTime>"
+ << std::endl;
+ return true;
+}
+
+//----------------------------------------------------------------------
+void cmCTestCoverageHandler::EndCoverageLogFile(cmGeneratedFileStream& ostr,
+ int logFileCount)
+{
+ std::string local_end_time = this->CTest->CurrentTime();
+ ostr << "\t<EndDateTime>" << local_end_time << "</EndDateTime>" << std::endl
+ << "\t<EndTime>" <<
+ static_cast<unsigned int>(cmSystemTools::GetTime())
+ << "</EndTime>" << std::endl
+ << "</CoverageLog>" << std::endl;
+ this->CTest->EndXML(ostr);
+ char covLogFilename[1024];
+ sprintf(covLogFilename, "CoverageLog-%d.xml", logFileCount);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Close file: "
+ << covLogFilename << std::endl);
+ ostr.Close();
+}
+
+//----------------------------------------------------------------------
+bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file,
+ const char* srcDir,
+ const char* binDir)
+{
+ if(this->IsFilteredOut(file))
+ {
+ return false;
+ }
+
+ std::vector<cmsys::RegularExpression>::iterator sit;
+ for ( sit = this->CustomCoverageExcludeRegex.begin();
+ sit != this->CustomCoverageExcludeRegex.end(); ++ sit )
+ {
+ if ( sit->find(file) )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " File " << file
+ << " is excluded in CTestCustom.ctest" << std::endl;);
+ return false;
+ }
+ }
+
+ std::string fSrcDir = cmSystemTools::CollapseFullPath(srcDir);
+ std::string fBinDir = cmSystemTools::CollapseFullPath(binDir);
+ std::string fFile = cmSystemTools::CollapseFullPath(file);
+ bool sourceSubDir = cmSystemTools::IsSubDirectory(fFile.c_str(),
+ fSrcDir.c_str());
+ bool buildSubDir = cmSystemTools::IsSubDirectory(fFile.c_str(),
+ fBinDir.c_str());
+ // Always check parent directory of the file.
+ std::string fileDir = cmSystemTools::GetFilenamePath(fFile);
+ std::string checkDir;
+
+ // We also need to check the binary/source directory pair.
+ if ( sourceSubDir && buildSubDir )
+ {
+ if ( fSrcDir.size() > fBinDir.size() )
+ {
+ checkDir = fSrcDir;
+ }
+ else
+ {
+ checkDir = fBinDir;
+ }
+ }
+ else if ( sourceSubDir )
+ {
+ checkDir = fSrcDir;
+ }
+ else if ( buildSubDir )
+ {
+ checkDir = fBinDir;
+ }
+ std::string ndc
+ = cmSystemTools::FileExistsInParentDirectories(".NoDartCoverage",
+ fFile.c_str(), checkDir.c_str());
+ if ( ndc.size() )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Found: " << ndc
+ << " so skip coverage of " << file << std::endl);
+ return false;
+ }
+
+ // By now checkDir should be set to parent directory of the file.
+ // Get the relative path to the file an apply it to the opposite directory.
+ // If it is the same as fileDir, then ignore, otherwise check.
+ std::string relPath;
+ if(checkDir.size() )
+ {
+ relPath = cmSystemTools::RelativePath(checkDir.c_str(),
+ fFile.c_str());
+ }
+ else
+ {
+ relPath = fFile;
+ }
+ if ( checkDir == fSrcDir )
+ {
+ checkDir = fBinDir;
+ }
+ else
+ {
+ checkDir = fSrcDir;
+ }
+ fFile = checkDir + "/" + relPath;
+ fFile = cmSystemTools::GetFilenamePath(fFile);
+
+ if ( fileDir == fFile )
+ {
+ // This is in-source build, so we trust the previous check.
+ return true;
+ }
+
+ ndc = cmSystemTools::FileExistsInParentDirectories(".NoDartCoverage",
+ fFile.c_str(), checkDir.c_str());
+ if ( ndc.size() )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Found: " << ndc
+ << " so skip coverage of: " << file << std::endl);
+ return false;
+ }
+ // Ok, nothing in source tree, nothing in binary tree
+ return true;
+}
+
+//----------------------------------------------------------------------
+//clearly it would be nice if this were broken up into a few smaller
+//functions and commented...
+int cmCTestCoverageHandler::ProcessHandler()
+{
+ this->CTest->ClearSubmitFiles(cmCTest::PartCoverage);
+ int error = 0;
+ // do we have time for this
+ if (this->CTest->GetRemainingTimeAllowed() < 120)
+ {
+ return error;
+ }
+
+ std::string coverage_start_time = this->CTest->CurrentTime();
+ unsigned int coverage_start_time_time = static_cast<unsigned int>(
+ cmSystemTools::GetTime());
+ std::string sourceDir
+ = this->CTest->GetCTestConfiguration("SourceDirectory");
+ std::string binaryDir
+ = this->CTest->GetCTestConfiguration("BuildDirectory");
+
+ this->LoadLabels();
+
+ cmGeneratedFileStream ofs;
+ double elapsed_time_start = cmSystemTools::GetTime();
+ if ( !this->StartLogFile("Coverage", ofs) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot create LastCoverage.log file" << std::endl);
+ }
+
+ ofs << "Performing coverage: " << elapsed_time_start << std::endl;
+ this->CleanCoverageLogFiles(ofs);
+
+ cmSystemTools::ConvertToUnixSlashes(sourceDir);
+ cmSystemTools::ConvertToUnixSlashes(binaryDir);
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Performing coverage" << std::endl);
+
+ cmCTestCoverageHandlerContainer cont;
+ cont.Error = error;
+ cont.SourceDir = sourceDir;
+ cont.BinaryDir = binaryDir;
+ cont.OFS = &ofs;
+
+ // setup the regex exclude stuff
+ this->CustomCoverageExcludeRegex.clear();
+ std::vector<std::string>::iterator rexIt;
+ for ( rexIt = this->CustomCoverageExclude.begin();
+ rexIt != this->CustomCoverageExclude.end();
+ ++ rexIt )
+ {
+ this->CustomCoverageExcludeRegex.push_back(
+ cmsys::RegularExpression(rexIt->c_str()));
+ }
+
+ if(this->HandleBullseyeCoverage(&cont))
+ {
+ return cont.Error;
+ }
+ int file_count = 0;
+ file_count += this->HandleGCovCoverage(&cont);
+ error = cont.Error;
+ if ( file_count < 0 )
+ {
+ return error;
+ }
+ file_count += this->HandleLCovCoverage(&cont);
+ error = cont.Error;
+ if ( file_count < 0 )
+ {
+ return error;
+ }
+ file_count += this->HandleTracePyCoverage(&cont);
+ error = cont.Error;
+ if ( file_count < 0 )
+ {
+ return error;
+ }
+ file_count += this->HandlePHPCoverage(&cont);
+ error = cont.Error;
+ if ( file_count < 0 )
+ {
+ return error;
+ }
+ file_count += this->HandleCoberturaCoverage(&cont);
+ error = cont.Error;
+ if ( file_count < 0 )
+ {
+ return error;
+ }
+
+ file_count += this->HandleMumpsCoverage(&cont);
+ error = cont.Error;
+ if ( file_count < 0 )
+ {
+ return error;
+ }
+
+ file_count += this->HandleJacocoCoverage(&cont);
+ error = cont.Error;
+ if ( file_count < 0 )
+ {
+ return error;
+ }
+
+ std::set<std::string> uncovered = this->FindUncoveredFiles(&cont);
+
+ if ( file_count == 0 )
+ {
+ cmCTestLog(this->CTest, WARNING,
+ " Cannot find any coverage files. Ignoring Coverage request."
+ << std::endl);
+ return error;
+ }
+ cmGeneratedFileStream covSumFile;
+ cmGeneratedFileStream covLogFile;
+
+ if(!this->StartResultingXML(cmCTest::PartCoverage, "Coverage", covSumFile))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot open coverage summary file." << std::endl);
+ return -1;
+ }
+
+ this->CTest->StartXML(covSumFile, this->AppendXML);
+ // Produce output xml files
+
+ covSumFile << "<Coverage>" << std::endl
+ << "\t<StartDateTime>" << coverage_start_time << "</StartDateTime>"
+ << std::endl
+ << "\t<StartTime>" << coverage_start_time_time << "</StartTime>"
+ << std::endl;
+ int logFileCount = 0;
+ if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
+ {
+ return -1;
+ }
+ cmCTestCoverageHandlerContainer::TotalCoverageMap::iterator fileIterator;
+ int cnt = 0;
+ long total_tested = 0;
+ long total_untested = 0;
+ //std::string fullSourceDir = sourceDir + "/";
+ //std::string fullBinaryDir = binaryDir + "/";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Accumulating results (each . represents one file):" << std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+
+ std::vector<std::string> errorsWhileAccumulating;
+
+ file_count = 0;
+ for ( fileIterator = cont.TotalCoverage.begin();
+ fileIterator != cont.TotalCoverage.end();
+ ++fileIterator )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
+ file_count ++;
+ if ( file_count % 50 == 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " processed: " << file_count
+ << " out of "
+ << cont.TotalCoverage.size() << std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+ }
+
+ const std::string fullFileName = fileIterator->first;
+ bool shouldIDoCoverage
+ = this->ShouldIDoCoverage(fullFileName.c_str(),
+ sourceDir.c_str(), binaryDir.c_str());
+ if ( !shouldIDoCoverage )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ ".NoDartCoverage found, so skip coverage check for: "
+ << fullFileName
+ << std::endl);
+ continue;
+ }
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Process file: " << fullFileName << std::endl);
+
+ if ( !cmSystemTools::FileExists(fullFileName.c_str()) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find file: "
+ << fullFileName << std::endl);
+ continue;
+ }
+
+ if ( ++cnt % 100 == 0 )
+ {
+ this->EndCoverageLogFile(covLogFile, logFileCount);
+ logFileCount ++;
+ if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
+ {
+ return -1;
+ }
+ }
+
+ const std::string fileName
+ = cmSystemTools::GetFilenameName(fullFileName);
+ std::string shortFileName =
+ this->CTest->GetShortPathToFile(fullFileName.c_str());
+ const cmCTestCoverageHandlerContainer::SingleFileCoverageVector& fcov
+ = fileIterator->second;
+ covLogFile << "\t<File Name=\"" << cmXMLSafe(fileName)
+ << "\" FullPath=\"" << cmXMLSafe(shortFileName) << "\">\n"
+ << "\t\t<Report>" << std::endl;
+
+ cmsys::ifstream ifs(fullFileName.c_str());
+ if ( !ifs)
+ {
+ cmOStringStream ostr;
+ ostr << "Cannot open source file: " << fullFileName;
+ errorsWhileAccumulating.push_back(ostr.str());
+ error ++;
+ continue;
+ }
+
+ int tested = 0;
+ int untested = 0;
+
+ cmCTestCoverageHandlerContainer::SingleFileCoverageVector::size_type cc;
+ std::string line;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Actually performing coverage for: " << fullFileName << std::endl);
+ for ( cc= 0; cc < fcov.size(); cc ++ )
+ {
+ if ( !cmSystemTools::GetLineFromStream(ifs, line) &&
+ cc != fcov.size() -1 )
+ {
+ cmOStringStream ostr;
+ ostr << "Problem reading source file: " << fullFileName
+ << " line:" << cc << " out total: " << fcov.size()-1;
+ errorsWhileAccumulating.push_back(ostr.str());
+ error ++;
+ break;
+ }
+ covLogFile << "\t\t<Line Number=\"" << cc << "\" Count=\"" << fcov[cc]
+ << "\">"
+ << cmXMLSafe(line) << "</Line>" << std::endl;
+ if ( fcov[cc] == 0 )
+ {
+ untested ++;
+ }
+ else if ( fcov[cc] > 0 )
+ {
+ tested ++;
+ }
+ }
+ if ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ cmOStringStream ostr;
+ ostr << "Looks like there are more lines in the file: " << line;
+ errorsWhileAccumulating.push_back(ostr.str());
+ }
+ float cper = 0;
+ float cmet = 0;
+ if ( tested + untested > 0 )
+ {
+ cper = (100 * SAFEDIV(static_cast<float>(tested),
+ static_cast<float>(tested + untested)));
+ cmet = ( SAFEDIV(static_cast<float>(tested + 10),
+ static_cast<float>(tested + untested + 10)));
+ }
+ total_tested += tested;
+ total_untested += untested;
+ covLogFile << "\t\t</Report>" << std::endl
+ << "\t</File>" << std::endl;
+ covSumFile << "\t<File Name=\"" << cmXMLSafe(fileName)
+ << "\" FullPath=\"" << cmXMLSafe(
+ this->CTest->GetShortPathToFile(fullFileName.c_str()))
+ << "\" Covered=\"" << (tested+untested > 0 ? "true":"false") << "\">\n"
+ << "\t\t<LOCTested>" << tested << "</LOCTested>\n"
+ << "\t\t<LOCUnTested>" << untested << "</LOCUnTested>\n"
+ << "\t\t<PercentCoverage>";
+ covSumFile.setf(std::ios::fixed, std::ios::floatfield);
+ covSumFile.precision(2);
+ covSumFile << (cper) << "</PercentCoverage>\n"
+ << "\t\t<CoverageMetric>";
+ covSumFile.setf(std::ios::fixed, std::ios::floatfield);
+ covSumFile.precision(2);
+ covSumFile << (cmet) << "</CoverageMetric>\n";
+ this->WriteXMLLabels(covSumFile, shortFileName);
+ covSumFile << "\t</File>" << std::endl;
+ }
+
+ //Handle all the files in the extra coverage globs that have no cov data
+ for(std::set<std::string>::iterator i = uncovered.begin();
+ i != uncovered.end(); ++i)
+ {
+ std::string fileName = cmSystemTools::GetFilenameName(*i);
+ std::string fullPath = cont.SourceDir + "/" + *i;
+
+ covLogFile << "\t<File Name=\"" << cmXMLSafe(fileName)
+ << "\" FullPath=\"" << cmXMLSafe(*i) << "\">\n"
+ << "\t\t<Report>" << std::endl;
+
+ cmsys::ifstream ifs(fullPath.c_str());
+ if (!ifs)
+ {
+ cmOStringStream ostr;
+ ostr << "Cannot open source file: " << fullPath;
+ errorsWhileAccumulating.push_back(ostr.str());
+ error ++;
+ continue;
+ }
+ int untested = 0;
+ std::string line;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Actually performing coverage for: " << *i << std::endl);
+ while (cmSystemTools::GetLineFromStream(ifs, line))
+ {
+ covLogFile << "\t\t<Line Number=\"" << untested << "\" Count=\"0\">"
+ << cmXMLSafe(line) << "</Line>" << std::endl;
+ untested ++;
+ }
+ covLogFile << "\t\t</Report>\n\t</File>" << std::endl;
+
+ total_untested += untested;
+ covSumFile << "\t<File Name=\"" << cmXMLSafe(fileName)
+ << "\" FullPath=\"" << cmXMLSafe(i->c_str())
+ << "\" Covered=\"true\">\n"
+ << "\t\t<LOCTested>0</LOCTested>\n"
+ << "\t\t<LOCUnTested>" << untested << "</LOCUnTested>\n"
+ << "\t\t<PercentCoverage>0</PercentCoverage>\n"
+ << "\t\t<CoverageMetric>0</CoverageMetric>\n";
+ this->WriteXMLLabels(covSumFile, *i);
+ covSumFile << "\t</File>" << std::endl;
+ }
+
+ this->EndCoverageLogFile(covLogFile, logFileCount);
+
+ if ( errorsWhileAccumulating.size() > 0 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error(s) while accumulating results:" << std::endl);
+ std::vector<std::string>::iterator erIt;
+ for ( erIt = errorsWhileAccumulating.begin();
+ erIt != errorsWhileAccumulating.end();
+ ++ erIt )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " " << *erIt << std::endl);
+ }
+ }
+
+ long total_lines = total_tested + total_untested;
+ float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
+ static_cast<float>(total_lines));
+ if ( total_lines == 0 )
+ {
+ percent_coverage = 0;
+ }
+
+ std::string end_time = this->CTest->CurrentTime();
+
+ covSumFile << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
+ << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
+ << "\t<LOC>" << total_lines << "</LOC>\n"
+ << "\t<PercentCoverage>";
+ covSumFile.setf(std::ios::fixed, std::ios::floatfield);
+ covSumFile.precision(2);
+ covSumFile << (percent_coverage)<< "</PercentCoverage>\n"
+ << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
+ << "\t<EndTime>" <<
+ static_cast<unsigned int>(cmSystemTools::GetTime())
+ << "</EndTime>\n";
+ covSumFile << "<ElapsedMinutes>" <<
+ static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
+ << "</ElapsedMinutes>"
+ << "</Coverage>" << std::endl;
+ this->CTest->EndXML(covSumFile);
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "" << std::endl
+ << "\tCovered LOC: "
+ << total_tested << std::endl
+ << "\tNot covered LOC: " << total_untested << std::endl
+ << "\tTotal LOC: " << total_lines << std::endl
+ << "\tPercentage Coverage: "
+ << std::setiosflags(std::ios::fixed)
+ << std::setprecision(2)
+ << (percent_coverage) << "%" << std::endl);
+
+ ofs << "\tCovered LOC: " << total_tested << std::endl
+ << "\tNot covered LOC: " << total_untested << std::endl
+ << "\tTotal LOC: " << total_lines << std::endl
+ << "\tPercentage Coverage: "
+ << std::setiosflags(std::ios::fixed)
+ << std::setprecision(2)
+ << (percent_coverage) << "%" << std::endl;
+
+
+ if ( error )
+ {
+ return -1;
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------
+void cmCTestCoverageHandler::PopulateCustomVectors(cmMakefile *mf)
+{
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Add coverage exclude regular expressions." << std::endl);
+ this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_COVERAGE_EXCLUDE",
+ this->CustomCoverageExclude);
+ this->CTest->PopulateCustomVector(mf, "CTEST_EXTRA_COVERAGE_GLOB",
+ this->ExtraCoverageGlobs);
+ std::vector<std::string>::iterator it;
+ for ( it = this->CustomCoverageExclude.begin();
+ it != this->CustomCoverageExclude.end();
+ ++ it )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Add coverage exclude: "
+ << *it << std::endl);
+ }
+ for ( it = this->ExtraCoverageGlobs.begin();
+ it != this->ExtraCoverageGlobs.end(); ++it)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Add coverage glob: "
+ << *it << std::endl);
+ }
+}
+
+//----------------------------------------------------------------------
+// Fix for issue #4971 where the case of the drive letter component of
+// the filenames might be different when analyzing gcov output.
+//
+// Compare file names: fnc(fn1) == fnc(fn2) // fnc == file name compare
+//
+#ifdef _WIN32
+#define fnc(s) cmSystemTools::LowerCase(s)
+#else
+#define fnc(s) s
+#endif
+
+//----------------------------------------------------------------------
+bool IsFileInDir(const std::string &infile, const std::string &indir)
+{
+ std::string file = cmSystemTools::CollapseFullPath(infile.c_str());
+ std::string dir = cmSystemTools::CollapseFullPath(indir.c_str());
+
+ if (
+ file.size() > dir.size() &&
+ (fnc(file.substr(0, dir.size())) == fnc(dir)) &&
+ file[dir.size()] == '/'
+ )
+ {
+ return true;
+ }
+
+ return false;
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::HandlePHPCoverage(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ cmParsePHPCoverage cov(*cont, this->CTest);
+ std::string coverageDir = this->CTest->GetBinaryDir() + "/xdebugCoverage";
+ if(cmSystemTools::FileIsDirectory(coverageDir.c_str()))
+ {
+ cov.ReadPHPCoverageDirectory(coverageDir.c_str());
+ }
+ return static_cast<int>(cont->TotalCoverage.size());
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::HandleCoberturaCoverage(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ cmParseCoberturaCoverage cov(*cont, this->CTest);
+
+ // Assume the coverage.xml is in the source directory
+ std::string coverageXMLFile = this->CTest->GetBinaryDir() + "/coverage.xml";
+
+ if(cmSystemTools::FileExists(coverageXMLFile.c_str()))
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Parsing Cobertura XML file: " << coverageXMLFile
+ << std::endl);
+ cov.ReadCoverageXML(coverageXMLFile.c_str());
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Cannot find Cobertura XML file: " << coverageXMLFile
+ << std::endl);
+ }
+ return static_cast<int>(cont->TotalCoverage.size());
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::HandleMumpsCoverage(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ // try gtm coverage
+ cmParseGTMCoverage cov(*cont, this->CTest);
+ std::string coverageFile = this->CTest->GetBinaryDir() +
+ "/gtm_coverage.mcov";
+ if(cmSystemTools::FileExists(coverageFile.c_str()))
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Parsing Cache Coverage: " << coverageFile
+ << std::endl);
+ cov.ReadCoverageFile(coverageFile.c_str());
+ return static_cast<int>(cont->TotalCoverage.size());
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Cannot find foobar GTM coverage file: " << coverageFile
+ << std::endl);
+ }
+ cmParseCacheCoverage ccov(*cont, this->CTest);
+ coverageFile = this->CTest->GetBinaryDir() +
+ "/cache_coverage.cmcov";
+ if(cmSystemTools::FileExists(coverageFile.c_str()))
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Parsing Cache Coverage: " << coverageFile
+ << std::endl);
+ ccov.ReadCoverageFile(coverageFile.c_str());
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Cannot find Cache coverage file: " << coverageFile
+ << std::endl);
+ }
+ return static_cast<int>(cont->TotalCoverage.size());
+}
+
+struct cmCTestCoverageHandlerLocale
+{
+ cmCTestCoverageHandlerLocale()
+ {
+ if(const char* l = cmSystemTools::GetEnv("LC_ALL"))
+ {
+ lc_all = l;
+ }
+ if(lc_all != "C")
+ {
+ cmSystemTools::PutEnv("LC_ALL=C");
+ }
+ }
+ ~cmCTestCoverageHandlerLocale()
+ {
+ if(!lc_all.empty())
+ {
+ cmSystemTools::PutEnv(("LC_ALL=" + lc_all).c_str());
+ }
+ else
+ {
+ cmSystemTools::UnsetEnv("LC_ALL");
+ }
+ }
+ std::string lc_all;
+};
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::HandleJacocoCoverage(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ cmParseJacocoCoverage cov =
+ cmParseJacocoCoverage(*cont, this->CTest);
+ cmsys::Glob g;
+ std::vector<std::string> files;
+ g.SetRecurse(true);
+
+ std::string SourceDir
+ = this->CTest->GetCTestConfiguration("SourceDirectory");
+ std::string coverageFile = SourceDir+ "/*jacoco.xml";
+
+ g.FindFiles(coverageFile);
+ files=g.GetFiles();
+ if (files.size() > 0)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Found Jacoco Files, Performing Coverage" << std::endl);
+ cov.LoadCoverageData(files);
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Cannot find Jacoco coverage files: " << coverageFile
+ << std::endl);
+ }
+ return static_cast<int>(cont->TotalCoverage.size());
+}
+
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::HandleGCovCoverage(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ std::string gcovCommand
+ = this->CTest->GetCTestConfiguration("CoverageCommand");
+ if (gcovCommand.empty())
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Could not find gcov." << std::endl);
+ return 0;
+ }
+ std::string gcovExtraFlags
+ = this->CTest->GetCTestConfiguration("CoverageExtraFlags");
+
+ // Immediately skip to next coverage option since codecov is only for Intel
+ // compiler
+ if ( gcovCommand == "codecov" )
+ {
+ return 0;
+ }
+
+ // Style 1
+ std::string st1gcovOutputRex1
+ = "[0-9]+\\.[0-9]+% of [0-9]+ (source |)lines executed in file (.*)$";
+ std::string st1gcovOutputRex2 = "^Creating (.*\\.gcov)\\.";
+ cmsys::RegularExpression st1re1(st1gcovOutputRex1.c_str());
+ cmsys::RegularExpression st1re2(st1gcovOutputRex2.c_str());
+
+
+ // Style 2
+ std::string st2gcovOutputRex1 = "^File *[`'](.*)'$";
+ std::string st2gcovOutputRex2
+ = "Lines executed: *[0-9]+\\.[0-9]+% of [0-9]+$";
+ std::string st2gcovOutputRex3 = "^(.*)reating [`'](.*\\.gcov)'";
+ std::string st2gcovOutputRex4 = "^(.*):unexpected EOF *$";
+ std::string st2gcovOutputRex5 = "^(.*):cannot open source file*$";
+ std::string st2gcovOutputRex6
+ = "^(.*):source file is newer than graph file `(.*)'$";
+ cmsys::RegularExpression st2re1(st2gcovOutputRex1.c_str());
+ cmsys::RegularExpression st2re2(st2gcovOutputRex2.c_str());
+ cmsys::RegularExpression st2re3(st2gcovOutputRex3.c_str());
+ cmsys::RegularExpression st2re4(st2gcovOutputRex4.c_str());
+ cmsys::RegularExpression st2re5(st2gcovOutputRex5.c_str());
+ cmsys::RegularExpression st2re6(st2gcovOutputRex6.c_str());
+
+ std::vector<std::string> files;
+ this->FindGCovFiles(files);
+ std::vector<std::string>::iterator it;
+
+ if ( files.size() == 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Cannot find any GCov coverage files."
+ << std::endl);
+ // No coverage files is a valid thing, so the exit code is 0
+ return 0;
+ }
+
+ std::string testingDir = this->CTest->GetBinaryDir() + "/Testing";
+ std::string tempDir = testingDir + "/CoverageInfo";
+ std::string currentDirectory = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::MakeDirectory(tempDir.c_str());
+ cmSystemTools::ChangeDirectory(tempDir.c_str());
+
+ int gcovStyle = 0;
+
+ std::set<std::string> missingFiles;
+
+ std::string actualSourceFile = "";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Processing coverage (each . represents one file):" << std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+ int file_count = 0;
+
+ // make sure output from gcov is in English!
+ cmCTestCoverageHandlerLocale locale_C;
+ static_cast<void>(locale_C);
+
+ // files is a list of *.da and *.gcda files with coverage data in them.
+ // These are binary files that you give as input to gcov so that it will
+ // give us text output we can analyze to summarize coverage.
+ //
+ for ( it = files.begin(); it != files.end(); ++ it )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
+
+ // Call gcov to get coverage data for this *.gcda file:
+ //
+ std::string fileDir = cmSystemTools::GetFilenamePath(*it);
+ std::string command = "\"" + gcovCommand + "\" " +
+ gcovExtraFlags + " " +
+ "-o \"" + fileDir + "\" " +
+ "\"" + *it + "\"";
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, command.c_str()
+ << std::endl);
+
+ std::string output = "";
+ std::string errors = "";
+ int retVal = 0;
+ *cont->OFS << "* Run coverage for: " << fileDir << std::endl;
+ *cont->OFS << " Command: " << command << std::endl;
+ int res = this->CTest->RunCommand(command.c_str(), &output, &errors,
+ &retVal, tempDir.c_str(), 0 /*this->TimeOut*/);
+
+ *cont->OFS << " Output: " << output << std::endl;
+ *cont->OFS << " Errors: " << errors << std::endl;
+ if ( ! res )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Problem running coverage on file: " << *it << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Command produced error: " << errors << std::endl);
+ cont->Error ++;
+ continue;
+ }
+ if ( retVal != 0 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Coverage command returned: "
+ << retVal << " while processing: " << *it << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Command produced error: " << cont->Error << std::endl);
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "--------------------------------------------------------------"
+ << std::endl
+ << output << std::endl
+ << "--------------------------------------------------------------"
+ << std::endl);
+
+ std::vector<std::string> lines;
+ std::vector<std::string>::iterator line;
+
+ cmSystemTools::Split(output.c_str(), lines);
+
+ for ( line = lines.begin(); line != lines.end(); ++line)
+ {
+ std::string sourceFile;
+ std::string gcovFile;
+
+ cmCTestLog(this->CTest, DEBUG, "Line: [" << *line << "]"
+ << std::endl);
+
+ if ( line->size() == 0 )
+ {
+ // Ignore empty line; probably style 2
+ }
+ else if ( st1re1.find(line->c_str()) )
+ {
+ if ( gcovStyle == 0 )
+ {
+ gcovStyle = 1;
+ }
+ if ( gcovStyle != 1 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e1"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
+
+ actualSourceFile = "";
+ sourceFile = st1re1.match(2);
+ }
+ else if ( st1re2.find(line->c_str() ) )
+ {
+ if ( gcovStyle == 0 )
+ {
+ gcovStyle = 1;
+ }
+ if ( gcovStyle != 1 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e2"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
+
+ gcovFile = st1re2.match(1);
+ }
+ else if ( st2re1.find(line->c_str() ) )
+ {
+ if ( gcovStyle == 0 )
+ {
+ gcovStyle = 2;
+ }
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e3"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
+
+ actualSourceFile = "";
+ sourceFile = st2re1.match(1);
+ }
+ else if ( st2re2.find(line->c_str() ) )
+ {
+ if ( gcovStyle == 0 )
+ {
+ gcovStyle = 2;
+ }
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e4"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
+ }
+ else if ( st2re3.find(line->c_str() ) )
+ {
+ if ( gcovStyle == 0 )
+ {
+ gcovStyle = 2;
+ }
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e5"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
+
+ gcovFile = st2re3.match(2);
+ }
+ else if ( st2re4.find(line->c_str() ) )
+ {
+ if ( gcovStyle == 0 )
+ {
+ gcovStyle = 2;
+ }
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e6"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
+
+ cmCTestLog(this->CTest, WARNING, "Warning: " << st2re4.match(1)
+ << " had unexpected EOF" << std::endl);
+ }
+ else if ( st2re5.find(line->c_str() ) )
+ {
+ if ( gcovStyle == 0 )
+ {
+ gcovStyle = 2;
+ }
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e7"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
+
+ cmCTestLog(this->CTest, WARNING, "Warning: Cannot open file: "
+ << st2re5.match(1) << std::endl);
+ }
+ else if ( st2re6.find(line->c_str() ) )
+ {
+ if ( gcovStyle == 0 )
+ {
+ gcovStyle = 2;
+ }
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e8"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
+
+ cmCTestLog(this->CTest, WARNING, "Warning: File: " << st2re6.match(1)
+ << " is newer than " << st2re6.match(2) << std::endl);
+ }
+ else
+ {
+ // gcov 4.7 can have output lines saying "No executable lines" and
+ // "Removing 'filename.gcov'"... Don't log those as "errors."
+ if(*line != "No executable lines" &&
+ !cmSystemTools::StringStartsWith(line->c_str(), "Removing "))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unknown gcov output line: [" << *line << "]"
+ << std::endl);
+ cont->Error ++;
+ //abort();
+ }
+ }
+
+
+ // If the last line of gcov output gave us a valid value for gcovFile,
+ // and we have an actualSourceFile, then insert a (or add to existing)
+ // SingleFileCoverageVector for actualSourceFile:
+ //
+ if ( !gcovFile.empty() && !actualSourceFile.empty() )
+ {
+ cmCTestCoverageHandlerContainer::SingleFileCoverageVector& vec
+ = cont->TotalCoverage[actualSourceFile];
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " in gcovFile: "
+ << gcovFile << std::endl);
+
+ cmsys::ifstream ifile(gcovFile.c_str());
+ if ( ! ifile )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open file: "
+ << gcovFile << std::endl);
+ }
+ else
+ {
+ long cnt = -1;
+ std::string nl;
+ while ( cmSystemTools::GetLineFromStream(ifile, nl) )
+ {
+ cnt ++;
+
+ //TODO: Handle gcov 3.0 non-coverage lines
+
+ // Skip empty lines
+ if ( !nl.size() )
+ {
+ continue;
+ }
+
+ // Skip unused lines
+ if ( nl.size() < 12 )
+ {
+ continue;
+ }
+
+ // Read the coverage count from the beginning of the gcov output
+ // line
+ std::string prefix = nl.substr(0, 12);
+ int cov = atoi(prefix.c_str());
+
+ // Read the line number starting at the 10th character of the gcov
+ // output line
+ std::string lineNumber = nl.substr(10, 5);
+
+ int lineIdx = atoi(lineNumber.c_str())-1;
+ if ( lineIdx >= 0 )
+ {
+ while ( vec.size() <= static_cast<size_t>(lineIdx) )
+ {
+ vec.push_back(-1);
+ }
+
+ // Initially all entries are -1 (not used). If we get coverage
+ // information, increment it to 0 first.
+ if ( vec[lineIdx] < 0 )
+ {
+ if ( cov > 0 || prefix.find("#") != prefix.npos )
+ {
+ vec[lineIdx] = 0;
+ }
+ }
+
+ vec[lineIdx] += cov;
+ }
+ }
+ }
+
+ actualSourceFile = "";
+ }
+
+
+ if ( !sourceFile.empty() && actualSourceFile.empty() )
+ {
+ gcovFile = "";
+
+ // Is it in the source dir or the binary dir?
+ //
+ if ( IsFileInDir(sourceFile, cont->SourceDir) )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " produced s: "
+ << sourceFile << std::endl);
+ *cont->OFS << " produced in source dir: " << sourceFile
+ << std::endl;
+ actualSourceFile
+ = cmSystemTools::CollapseFullPath(sourceFile.c_str());
+ }
+ else if ( IsFileInDir(sourceFile, cont->BinaryDir) )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " produced b: "
+ << sourceFile << std::endl);
+ *cont->OFS << " produced in binary dir: " << sourceFile
+ << std::endl;
+ actualSourceFile
+ = cmSystemTools::CollapseFullPath(sourceFile.c_str());
+ }
+
+ if ( actualSourceFile.empty() )
+ {
+ if ( missingFiles.find(sourceFile) == missingFiles.end() )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Something went wrong" << std::endl);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Cannot find file: ["
+ << sourceFile << "]" << std::endl);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " in source dir: ["
+ << cont->SourceDir << "]"
+ << std::endl);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " or binary dir: ["
+ << cont->BinaryDir.size() << "]"
+ << std::endl);
+ *cont->OFS << " Something went wrong. Cannot find file: "
+ << sourceFile
+ << " in source dir: " << cont->SourceDir
+ << " or binary dir: " << cont->BinaryDir << std::endl;
+
+ missingFiles.insert(sourceFile);
+ }
+ }
+ }
+ }
+
+ file_count++;
+
+ if ( file_count % 50 == 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " processed: " << file_count
+ << " out of " << files.size() << std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+ }
+ }
+
+ cmSystemTools::ChangeDirectory(currentDirectory.c_str());
+ return file_count;
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::HandleLCovCoverage(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ std::string lcovCommand
+ = this->CTest->GetCTestConfiguration("CoverageCommand");
+ std::string lcovExtraFlags
+ = this->CTest->GetCTestConfiguration("CoverageExtraFlags");
+ if ( lcovCommand != "codecov" )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Not a valid Intel Coverage command."
+ << std::endl);
+ return 0;
+ }
+ // There is only percentage completed output from LCOV
+ std::string st2lcovOutputRex3 = "[0-9]+%";
+ cmsys::RegularExpression st2re3(st2lcovOutputRex3.c_str());
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " This is coverage command: " << lcovCommand
+ << std::endl);
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " These are coverage command flags: " << lcovExtraFlags
+ << std::endl);
+
+ std::vector<std::string> files;
+ this->FindLCovFiles(files);
+ std::vector<std::string>::iterator it;
+
+ if ( files.size() == 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Cannot find any LCov coverage files."
+ << std::endl);
+ // No coverage files is a valid thing, so the exit code is 0
+ return 0;
+ }
+ std::string testingDir = this->CTest->GetBinaryDir();
+ std::string tempDir = testingDir;
+ std::string currentDirectory = cmSystemTools::GetCurrentWorkingDirectory();
+
+ std::set<std::string> missingFiles;
+
+ std::string actualSourceFile = "";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Processing coverage (each . represents one file):" << std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+ int file_count = 0;
+
+ // make sure output from lcov is in English!
+ cmCTestCoverageHandlerLocale locale_C;
+ static_cast<void>(locale_C);
+
+ // In intel compiler we have to call codecov only once in each executable
+ // directory. It collects all *.dyn files to generate .dpi file.
+ for ( it = files.begin(); it != files.end(); ++ it )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
+ std::string fileDir = cmSystemTools::GetFilenamePath(it->c_str());
+ cmSystemTools::ChangeDirectory(fileDir.c_str());
+ std::string command = "\"" + lcovCommand + "\" " +
+ lcovExtraFlags + " ";
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Current coverage dir: "
+ << fileDir.c_str() << std::endl);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, command.c_str()
+ << std::endl);
+
+ std::string output = "";
+ std::string errors = "";
+ int retVal = 0;
+ *cont->OFS << "* Run coverage for: " << fileDir.c_str() << std::endl;
+ *cont->OFS << " Command: " << command.c_str() << std::endl;
+ int res = this->CTest->RunCommand(command.c_str(), &output, &errors,
+ &retVal, fileDir.c_str(), 0 /*this->TimeOut*/);
+
+ *cont->OFS << " Output: " << output.c_str() << std::endl;
+ *cont->OFS << " Errors: " << errors.c_str() << std::endl;
+ if ( ! res )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Problem running coverage on file: " << it->c_str() << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Command produced error: " << errors << std::endl);
+ cont->Error ++;
+ continue;
+ }
+ if ( retVal != 0 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Coverage command returned: "
+ << retVal << " while processing: " << it->c_str() << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Command produced error: " << cont->Error << std::endl);
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "--------------------------------------------------------------"
+ << std::endl
+ << output << std::endl
+ << "--------------------------------------------------------------"
+ << std::endl);
+
+ std::vector<std::string> lines;
+ std::vector<std::string>::iterator line;
+
+ cmSystemTools::Split(output.c_str(), lines);
+
+ for ( line = lines.begin(); line != lines.end(); ++line)
+ {
+ std::string sourceFile;
+ std::string lcovFile;
+
+ if ( line->size() == 0 )
+ {
+ // Ignore empty line
+ }
+ // Look for LCOV files in binary directory
+ // Intel Compiler creates a CodeCoverage dir for each subfolder and
+ // each subfolder has LCOV files
+ cmsys::Glob gl;
+ gl.RecurseOn();
+ gl.RecurseThroughSymlinksOff();
+ std::string dir;
+ std::vector<std::string> lcovFiles;
+ dir = this->CTest->GetBinaryDir();
+ std::string daGlob;
+ daGlob = dir;
+ daGlob += "/*.LCOV";
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " looking for LCOV files in: " << daGlob << std::endl);
+ gl.FindFiles(daGlob);
+ // Keep a list of all LCOV files
+ lcovFiles.insert(lcovFiles.end(), gl.GetFiles().begin(),
+ gl.GetFiles().end());
+
+ for(std::vector<std::string>::iterator a = lcovFiles.begin();
+ a != lcovFiles.end(); ++a)
+ {
+ lcovFile = *a;
+ cmsys::ifstream srcead(lcovFile.c_str());
+ if ( ! srcead )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open file: "
+ << lcovFile << std::endl);
+ }
+ std::string srcname;
+
+ int success = cmSystemTools::GetLineFromStream(srcead, srcname);
+ if ( !success )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error while parsing lcov file '" << lcovFile << "':"
+ << " No source file name found!" << std::endl);
+ return 0;
+ }
+ srcname = srcname.substr(18);
+ // We can directly read found LCOV files to determine the source
+ // files
+ sourceFile = srcname;
+ actualSourceFile = srcname;
+
+ for(std::vector<std::string>::iterator t = lcovFiles.begin();
+ t != lcovFiles.end(); ++t)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Found LCOV File: "
+ << *t << std::endl);
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "SourceFile: "
+ << sourceFile << std::endl);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "lCovFile: "
+ << lcovFile << std::endl);
+
+ // If we have some LCOV files to process
+ if ( !lcovFile.empty() && !actualSourceFile.empty() )
+ {
+ cmCTestCoverageHandlerContainer::SingleFileCoverageVector& vec
+ = cont->TotalCoverage[actualSourceFile];
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " in lcovFile: "
+ << lcovFile << std::endl);
+
+ cmsys::ifstream ifile(lcovFile.c_str());
+ if ( ! ifile )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open file: "
+ << lcovFile << std::endl);
+ }
+ else
+ {
+ long cnt = -1;
+ std::string nl;
+
+ // Skip the first line
+ cmSystemTools::GetLineFromStream(ifile, nl);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "File is ready, start reading." << std::endl);
+ while ( cmSystemTools::GetLineFromStream(ifile, nl) )
+ {
+ cnt ++;
+
+ // Skip empty lines
+ if ( !nl.size() )
+ {
+ continue;
+ }
+
+ // Skip unused lines
+ if ( nl.size() < 12 )
+ {
+ continue;
+ }
+
+ // Read the coverage count from the beginning of the lcov
+ // output line
+ std::string prefix = nl.substr(0, 17);
+ int cov = atoi(prefix.c_str());
+
+ // Read the line number starting at the 17th character of the
+ // lcov output line
+ std::string lineNumber = nl.substr(17, 7);
+
+ int lineIdx = atoi(lineNumber.c_str())-1;
+ if ( lineIdx >= 0 )
+ {
+ while ( vec.size() <= static_cast<size_t>(lineIdx) )
+ {
+ vec.push_back(-1);
+ }
+
+ // Initially all entries are -1 (not used). If we get coverage
+ // information, increment it to 0 first.
+ if ( vec[lineIdx] < 0 )
+ {
+ if ( cov > 0 || prefix.find("#") != prefix.npos )
+ {
+ vec[lineIdx] = 0;
+ }
+ }
+
+ vec[lineIdx] += cov;
+ }
+ }
+ }
+
+ actualSourceFile = "";
+ }
+ }
+ }
+
+ file_count++;
+
+ if ( file_count % 50 == 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " processed: " << file_count
+ << " out of " << files.size() << std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+ }
+ }
+
+ cmSystemTools::ChangeDirectory(currentDirectory.c_str());
+ return file_count;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestCoverageHandler::FindGCovFiles(std::vector<std::string>& files)
+{
+ cmsys::Glob gl;
+ gl.RecurseOn();
+ gl.RecurseThroughSymlinksOff();
+
+ for(LabelMapType::const_iterator lmi = this->TargetDirs.begin();
+ lmi != this->TargetDirs.end(); ++lmi)
+ {
+ // Skip targets containing no interesting labels.
+ if(!this->IntersectsFilter(lmi->second))
+ {
+ continue;
+ }
+
+ // Coverage files appear next to their object files in the target
+ // support directory.
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " globbing for coverage in: " << lmi->first << std::endl);
+ std::string daGlob = lmi->first;
+ daGlob += "/*.da";
+ gl.FindFiles(daGlob);
+ files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
+ daGlob = lmi->first;
+ daGlob += "/*.gcda";
+ gl.FindFiles(daGlob);
+ files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files)
+{
+ cmsys::Glob gl;
+ gl.RecurseOff(); // No need of recurse if -prof_dir${BUILD_DIR} flag is
+ // used while compiling.
+ gl.RecurseThroughSymlinksOff();
+ std::string prevBinaryDir;
+ cmSystemTools::ChangeDirectory(
+ this->CTest->GetCTestConfiguration("BuildDirectory").c_str());
+
+ // Run profmerge to merge all *.dyn files into dpi files
+ cmSystemTools::RunSingleCommand("profmerge");
+
+ prevBinaryDir = cmSystemTools::GetCurrentWorkingDirectory().c_str();
+
+ // DPI file should appear in build directory
+ std::string daGlob;
+ daGlob = prevBinaryDir;
+ daGlob += "/*.dpi";
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " looking for dpi files in: " << daGlob << std::endl);
+ gl.FindFiles(daGlob);
+ files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Now searching in: " << daGlob << std::endl);
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::HandleTracePyCoverage(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ cmsys::Glob gl;
+ gl.RecurseOn();
+ gl.RecurseThroughSymlinksOff();
+ std::string daGlob = cont->BinaryDir + "/*.cover";
+ gl.FindFiles(daGlob);
+ std::vector<std::string> files = gl.GetFiles();
+
+ if ( files.size() == 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Cannot find any Python Trace.py coverage files."
+ << std::endl);
+ // No coverage files is a valid thing, so the exit code is 0
+ return 0;
+ }
+
+ std::string testingDir = this->CTest->GetBinaryDir() + "/Testing";
+ std::string tempDir = testingDir + "/CoverageInfo";
+ std::string currentDirectory = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::MakeDirectory(tempDir.c_str());
+ cmSystemTools::ChangeDirectory(tempDir.c_str());
+
+ cmSystemTools::ChangeDirectory(currentDirectory.c_str());
+
+ std::vector<std::string>::iterator fileIt;
+ int file_count = 0;
+ for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
+ {
+ std::string fileName = this->FindFile(cont, *fileIt);
+ if ( fileName.empty() )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find source Python file corresponding to: "
+ << *fileIt << std::endl);
+ continue;
+ }
+
+ std::string actualSourceFile
+ = cmSystemTools::CollapseFullPath(fileName.c_str());
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Check coverage for file: " << actualSourceFile
+ << std::endl);
+ cmCTestCoverageHandlerContainer::SingleFileCoverageVector* vec
+ = &cont->TotalCoverage[actualSourceFile];
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " in file: " << *fileIt << std::endl);
+ cmsys::ifstream ifile(fileIt->c_str());
+ if ( ! ifile )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open file: "
+ << *fileIt << std::endl);
+ }
+ else
+ {
+ long cnt = -1;
+ std::string nl;
+ while ( cmSystemTools::GetLineFromStream(ifile, nl) )
+ {
+ cnt ++;
+
+ // Skip empty lines
+ if ( !nl.size() )
+ {
+ continue;
+ }
+
+ // Skip unused lines
+ if ( nl.size() < 12 )
+ {
+ continue;
+ }
+
+ // Read the coverage count from the beginning of the Trace.py output
+ // line
+ std::string prefix = nl.substr(0, 6);
+ if ( prefix[5] != ' ' && prefix[5] != ':' )
+ {
+ // This is a hack. We should really do something more elaborate
+ prefix = nl.substr(0, 7);
+ if ( prefix[6] != ' ' && prefix[6] != ':' )
+ {
+ prefix = nl.substr(0, 8);
+ if ( prefix[7] != ' ' && prefix[7] != ':' )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Currently the limit is maximum coverage of 999999"
+ << std::endl);
+ }
+ }
+ }
+ int cov = atoi(prefix.c_str());
+ if ( prefix[prefix.size()-1] != ':' )
+ {
+ // This line does not have ':' so no coverage here. That said,
+ // Trace.py does not handle not covered lines versus comments etc.
+ // So, this will be set to 0.
+ cov = 0;
+ }
+ cmCTestLog(this->CTest, DEBUG, "Prefix: " << prefix
+ << " cov: " << cov
+ << std::endl);
+ // Read the line number starting at the 10th character of the gcov
+ // output line
+ long lineIdx = cnt;
+ if ( lineIdx >= 0 )
+ {
+ while ( vec->size() <=
+ static_cast<size_t>(lineIdx) )
+ {
+ vec->push_back(-1);
+ }
+ // Initially all entries are -1 (not used). If we get coverage
+ // information, increment it to 0 first.
+ if ( (*vec)[lineIdx] < 0 )
+ {
+ if ( cov >= 0 )
+ {
+ (*vec)[lineIdx] = 0;
+ }
+ }
+ (*vec)[lineIdx] += cov;
+ }
+ }
+ }
+ ++ file_count;
+ }
+ cmSystemTools::ChangeDirectory(currentDirectory.c_str());
+ return file_count;
+}
+
+//----------------------------------------------------------------------
+std::string cmCTestCoverageHandler::FindFile(
+ cmCTestCoverageHandlerContainer* cont,
+ std::string fileName)
+{
+ std::string fileNameNoE
+ = cmSystemTools::GetFilenameWithoutLastExtension(fileName);
+ // First check in source and binary directory
+ std::string fullName = cont->SourceDir + "/" + fileNameNoE + ".py";
+ if ( cmSystemTools::FileExists(fullName.c_str()) )
+ {
+ return fullName;
+ }
+ fullName = cont->BinaryDir + "/" + fileNameNoE + ".py";
+ if ( cmSystemTools::FileExists(fullName.c_str()) )
+ {
+ return fullName;
+ }
+ return "";
+}
+
+// This is a header put on each marked up source file
+namespace
+{
+ const char* bullseyeHelp[] =
+ {" Coverage produced by bullseye covbr tool: ",
+ " www.bullseye.com/help/ref_covbr.html",
+ " * An arrow --> indicates incomplete coverage.",
+ " * An X indicates a function that was invoked, a switch label that ",
+ " was exercised, a try-block that finished, or an exception handler ",
+ " that was invoked.",
+ " * A T or F indicates a boolean decision that evaluated true or false,",
+ " respectively.",
+ " * A t or f indicates a boolean condition within a decision if the ",
+ " condition evaluated true or false, respectively.",
+ " * A k indicates a constant decision or condition.",
+ " * The slash / means this probe is excluded from summary results. ",
+ 0};
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::RunBullseyeCoverageBranch(
+ cmCTestCoverageHandlerContainer* cont,
+ std::set<std::string>& coveredFileNames,
+ std::vector<std::string>& files,
+ std::vector<std::string>& filesFullPath)
+{
+ if(files.size() != filesFullPath.size())
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Files and full path files not the same size?:\n");
+ return 0;
+ }
+ // create the output stream for the CoverageLog-N.xml file
+ cmGeneratedFileStream covLogFile;
+ int logFileCount = 0;
+ if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
+ {
+ return -1;
+ }
+ // for each file run covbr on that file to get the coverage
+ // information for that file
+ std::string outputFile;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "run covbr: "
+ << std::endl);
+
+ if(!this->RunBullseyeCommand(cont, "covbr", 0, outputFile))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "error running covbr for." << "\n");
+ return -1;
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "covbr output in " << outputFile
+ << std::endl);
+ // open the output file
+ cmsys::ifstream fin(outputFile.c_str());
+ if(!fin)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot open coverage file: " <<
+ outputFile << std::endl);
+ return 0;
+ }
+ std::map<std::string, std::string> fileMap;
+ std::vector<std::string>::iterator fp = filesFullPath.begin();
+ for(std::vector<std::string>::iterator f = files.begin();
+ f != files.end(); ++f, ++fp)
+ {
+ fileMap[*f] = *fp;
+ }
+
+ int count =0; // keep count of the number of files
+ // Now parse each line from the bullseye cov log file
+ std::string lineIn;
+ bool valid = false; // are we in a valid output file
+ int line = 0; // line of the current file
+ std::string file;
+ while(cmSystemTools::GetLineFromStream(fin, lineIn))
+ {
+ bool startFile = false;
+ if(lineIn.size() > 1 && lineIn[lineIn.size()-1] == ':')
+ {
+ file = lineIn.substr(0, lineIn.size()-1);
+ if(coveredFileNames.find(file) != coveredFileNames.end())
+ {
+ startFile = true;
+ }
+ }
+ if(startFile)
+ {
+ // if we are in a valid file close it because a new one started
+ if(valid)
+ {
+ covLogFile << "\t\t</Report>" << std::endl
+ << "\t</File>" << std::endl;
+ }
+ // only allow 100 files in each log file
+ if ( count != 0 && count % 100 == 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "start a new log file: "
+ << count
+ << std::endl);
+ this->EndCoverageLogFile(covLogFile, logFileCount);
+ logFileCount ++;
+ if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
+ {
+ return -1;
+ }
+ count++; // move on one
+ }
+ std::map<std::string, std::string>::iterator
+ i = fileMap.find(file);
+ // if the file should be covered write out the header for that file
+ if(i != fileMap.end())
+ {
+ // we have a new file so count it in the output
+ count++;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Produce coverage for file: "
+ << file << " " << count
+ << std::endl);
+ // start the file output
+ covLogFile << "\t<File Name=\""
+ << cmXMLSafe(i->first)
+ << "\" FullPath=\"" << cmXMLSafe(
+ this->CTest->GetShortPathToFile(
+ i->second.c_str())) << "\">" << std::endl
+ << "\t\t<Report>" << std::endl;
+ // write the bullseye header
+ line =0;
+ for(int k =0; bullseyeHelp[k] != 0; ++k)
+ {
+ covLogFile << "\t\t<Line Number=\"" << line << "\" Count=\"-1\">"
+ << cmXMLSafe(bullseyeHelp[k])
+ << "</Line>" << std::endl;
+ line++;
+ }
+ valid = true; // we are in a valid file section
+ }
+ else
+ {
+ // this is not a file that we want coverage for
+ valid = false;
+ }
+ }
+ // we are not at a start file, and we are in a valid file output the line
+ else if(valid)
+ {
+ covLogFile << "\t\t<Line Number=\"" << line << "\" Count=\"-1\">"
+ << cmXMLSafe(lineIn)
+ << "</Line>" << std::endl;
+ line++;
+ }
+ }
+ // if we ran out of lines a valid file then close that file
+ if(valid)
+ {
+ covLogFile << "\t\t</Report>" << std::endl
+ << "\t</File>" << std::endl;
+ }
+ this->EndCoverageLogFile(covLogFile, logFileCount);
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::RunBullseyeCommand(
+ cmCTestCoverageHandlerContainer* cont,
+ const char* cmd,
+ const char* arg,
+ std::string& outputFile)
+{
+ std::string program = cmSystemTools::FindProgram(cmd);
+ if(program.size() == 0)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find :" << cmd << "\n");
+ return 0;
+ }
+ if(arg)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Run : " << program << " " << arg << "\n");
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Run : " << program << "\n");
+ }
+ // create a process object and start it
+ cmCTestRunProcess runCoverageSrc;
+ runCoverageSrc.SetCommand(program.c_str());
+ runCoverageSrc.AddArgument(arg);
+ std::string stdoutFile = cont->BinaryDir + "/Testing/Temporary/";
+ stdoutFile += this->GetCTestInstance()->GetCurrentTag();
+ stdoutFile += "-";
+ stdoutFile += cmd;
+ std::string stderrFile = stdoutFile;
+ stdoutFile += ".stdout";
+ stderrFile += ".stderr";
+ runCoverageSrc.SetStdoutFile(stdoutFile.c_str());
+ runCoverageSrc.SetStderrFile(stderrFile.c_str());
+ if(!runCoverageSrc.StartProcess())
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Could not run : "
+ << program << " " << arg << "\n"
+ << "kwsys process state : "
+ << runCoverageSrc.GetProcessState());
+ return 0;
+ }
+ // since we set the output file names wait for it to end
+ runCoverageSrc.WaitForExit();
+ outputFile = stdoutFile;
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::RunBullseyeSourceSummary(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ // Run the covsrc command and create a temp outputfile
+ std::string outputFile;
+ if(!this->RunBullseyeCommand(cont, "covsrc", "-c", outputFile))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "error running covsrc:\n");
+ return 0;
+ }
+
+ std::ostream& tmpLog = *cont->OFS;
+ // copen the Coverage.xml file in the Testing directory
+ cmGeneratedFileStream covSumFile;
+ if(!this->StartResultingXML(cmCTest::PartCoverage, "Coverage", covSumFile))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot open coverage summary file." << std::endl);
+ return 0;
+ }
+ this->CTest->StartXML(covSumFile, this->AppendXML);
+ double elapsed_time_start = cmSystemTools::GetTime();
+ std::string coverage_start_time = this->CTest->CurrentTime();
+ covSumFile << "<Coverage>" << std::endl
+ << "\t<StartDateTime>"
+ << coverage_start_time << "</StartDateTime>"
+ << std::endl
+ << "\t<StartTime>"
+ << static_cast<unsigned int>(cmSystemTools::GetTime())
+ << "</StartTime>"
+ << std::endl;
+ std::string stdline;
+ std::string errline;
+ // expected output:
+ // first line is:
+ // "Source","Function Coverage","out of","%","C/D Coverage","out of","%"
+ // after that data follows in that format
+ std::string sourceFile;
+ int functionsCalled = 0;
+ int totalFunctions = 0;
+ int percentFunction = 0;
+ int branchCovered = 0;
+ int totalBranches = 0;
+ int percentBranch = 0;
+ double total_tested = 0;
+ double total_untested = 0;
+ double total_functions = 0;
+ double percent_coverage =0;
+ double number_files = 0;
+ std::vector<std::string> coveredFiles;
+ std::vector<std::string> coveredFilesFullPath;
+ // Read and parse the summary output file
+ cmsys::ifstream fin(outputFile.c_str());
+ if(!fin)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot open coverage summary file: " <<
+ outputFile << std::endl);
+ return 0;
+ }
+ std::set<std::string> coveredFileNames;
+ while(cmSystemTools::GetLineFromStream(fin, stdline))
+ {
+ // if we have a line of output from stdout
+ if(stdline.size())
+ {
+ // parse the comma separated output
+ this->ParseBullsEyeCovsrcLine(stdline,
+ sourceFile,
+ functionsCalled,
+ totalFunctions,
+ percentFunction,
+ branchCovered,
+ totalBranches,
+ percentBranch);
+ // The first line is the header
+ if(sourceFile == "Source" || sourceFile == "Total")
+ {
+ continue;
+ }
+ std::string file = sourceFile;
+ coveredFileNames.insert(file);
+ if(!cmSystemTools::FileIsFullPath(sourceFile.c_str()))
+ {
+ // file will be relative to the binary dir
+ file = cont->BinaryDir;
+ file += "/";
+ file += sourceFile;
+ }
+ file = cmSystemTools::CollapseFullPath(file.c_str());
+ bool shouldIDoCoverage
+ = this->ShouldIDoCoverage(file.c_str(),
+ cont->SourceDir.c_str(),
+ cont->BinaryDir.c_str());
+ if ( !shouldIDoCoverage )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ ".NoDartCoverage found, so skip coverage check for: "
+ << file
+ << std::endl);
+ continue;
+ }
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Doing coverage for: "
+ << file
+ << std::endl);
+
+ coveredFiles.push_back(sourceFile);
+ coveredFilesFullPath.push_back(file);
+
+ number_files++;
+ total_functions += totalFunctions;
+ total_tested += functionsCalled;
+ total_untested += (totalFunctions - functionsCalled);
+
+ std::string fileName = cmSystemTools::GetFilenameName(file);
+ std::string shortFileName =
+ this->CTest->GetShortPathToFile(file.c_str());
+
+ float cper = static_cast<float>(percentBranch + percentFunction);
+ if(totalBranches > 0)
+ {
+ cper /= 2.0f;
+ }
+ percent_coverage += cper;
+ float cmet = static_cast<float>(percentFunction + percentBranch);
+ if(totalBranches > 0)
+ {
+ cmet /= 2.0f;
+ }
+ cmet /= 100.0f;
+ tmpLog << stdline << "\n";
+ tmpLog << fileName << "\n";
+ tmpLog << "functionsCalled: " << functionsCalled/100 << "\n";
+ tmpLog << "totalFunctions: " << totalFunctions/100 << "\n";
+ tmpLog << "percentFunction: " << percentFunction << "\n";
+ tmpLog << "branchCovered: " << branchCovered << "\n";
+ tmpLog << "totalBranches: " << totalBranches << "\n";
+ tmpLog << "percentBranch: " << percentBranch << "\n";
+ tmpLog << "percentCoverage: " << percent_coverage << "\n";
+ tmpLog << "coverage metric: " << cmet << "\n";
+ covSumFile << "\t<File Name=\"" << cmXMLSafe(sourceFile)
+ << "\" FullPath=\"" << cmXMLSafe(shortFileName)
+ << "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
+ << "\t\t<BranchesTested>"
+ << branchCovered
+ << "</BranchesTested>\n"
+ << "\t\t<BranchesUnTested>"
+ << totalBranches - branchCovered
+ << "</BranchesUnTested>\n"
+ << "\t\t<FunctionsTested>"
+ << functionsCalled
+ << "</FunctionsTested>\n"
+ << "\t\t<FunctionsUnTested>"
+ << totalFunctions - functionsCalled
+ << "</FunctionsUnTested>\n"
+ // Hack for conversion of function to loc assume a function
+ // has 100 lines of code
+ << "\t\t<LOCTested>" << functionsCalled *100
+ << "</LOCTested>\n"
+ << "\t\t<LOCUnTested>"
+ << (totalFunctions - functionsCalled)*100
+ << "</LOCUnTested>\n"
+ << "\t\t<PercentCoverage>";
+ covSumFile.setf(std::ios::fixed, std::ios::floatfield);
+ covSumFile.precision(2);
+ covSumFile << (cper) << "</PercentCoverage>\n"
+ << "\t\t<CoverageMetric>";
+ covSumFile.setf(std::ios::fixed, std::ios::floatfield);
+ covSumFile.precision(2);
+ covSumFile << (cmet) << "</CoverageMetric>\n";
+ this->WriteXMLLabels(covSumFile, shortFileName);
+ covSumFile << "\t</File>" << std::endl;
+ }
+ }
+ std::string end_time = this->CTest->CurrentTime();
+ covSumFile << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
+ << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
+ << "\t<LOC>" << total_functions << "</LOC>\n"
+ << "\t<PercentCoverage>";
+ covSumFile.setf(std::ios::fixed, std::ios::floatfield);
+ covSumFile.precision(2);
+ covSumFile
+ << SAFEDIV(percent_coverage,number_files)<< "</PercentCoverage>\n"
+ << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
+ << "\t<EndTime>" << static_cast<unsigned int>(cmSystemTools::GetTime())
+ << "</EndTime>\n";
+ covSumFile
+ << "<ElapsedMinutes>" <<
+ static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
+ << "</ElapsedMinutes>"
+ << "</Coverage>" << std::endl;
+ this->CTest->EndXML(covSumFile);
+
+ // Now create the coverage information for each file
+ return this->RunBullseyeCoverageBranch(cont,
+ coveredFileNames,
+ coveredFiles,
+ coveredFilesFullPath);
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::HandleBullseyeCoverage(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ const char* covfile = cmSystemTools::GetEnv("COVFILE");
+ if(!covfile || strlen(covfile) == 0)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " COVFILE environment variable not found, not running "
+ " bullseye\n");
+ return 0;
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " run covsrc with COVFILE=["
+ << covfile
+ << "]" << std::endl);
+ if(!this->RunBullseyeSourceSummary(cont))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error running bullseye summary.\n");
+ return 0;
+ }
+ cmCTestLog(this->CTest, DEBUG, "HandleBullseyeCoverage return 1 "
+ << std::endl);
+ return 1;
+}
+
+bool cmCTestCoverageHandler::GetNextInt(std::string const& inputLine,
+ std::string::size_type& pos,
+ int& value)
+{
+ std::string::size_type start = pos;
+ pos = inputLine.find(',', start);
+ value = atoi(inputLine.substr(start, pos).c_str());
+ if(pos == inputLine.npos)
+ {
+ return true;
+ }
+ pos++;
+ return true;
+}
+
+bool cmCTestCoverageHandler::ParseBullsEyeCovsrcLine(
+ std::string const& inputLine,
+ std::string& sourceFile,
+ int& functionsCalled,
+ int& totalFunctions,
+ int& percentFunction,
+ int& branchCovered,
+ int& totalBranches,
+ int& percentBranch)
+{
+ // find the first comma
+ std::string::size_type pos = inputLine.find(',');
+ if(pos == inputLine.npos)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Error parsing string : "
+ << inputLine << "\n");
+ return false;
+ }
+ // the source file has "" around it so extract out the file name
+ sourceFile = inputLine.substr(1,pos-2);
+ pos++;
+ if(!this->GetNextInt(inputLine, pos, functionsCalled))
+ {
+ return false;
+ }
+ if(!this->GetNextInt(inputLine, pos, totalFunctions))
+ {
+ return false;
+ }
+ if(!this->GetNextInt(inputLine, pos, percentFunction))
+ {
+ return false;
+ }
+ if(!this->GetNextInt(inputLine, pos, branchCovered))
+ {
+ return false;
+ }
+ if(!this->GetNextInt(inputLine, pos, totalBranches))
+ {
+ return false;
+ }
+ if(!this->GetNextInt(inputLine, pos, percentBranch))
+ {
+ return false;
+ }
+ // should be at the end now
+ if(pos != inputLine.npos)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Error parsing input : "
+ << inputLine << " last pos not npos = " << pos <<
+ "\n");
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+int cmCTestCoverageHandler::GetLabelId(std::string const& label)
+{
+ LabelIdMapType::iterator i = this->LabelIdMap.find(label);
+ if(i == this->LabelIdMap.end())
+ {
+ int n = int(this->Labels.size());
+ this->Labels.push_back(label);
+ LabelIdMapType::value_type entry(label, n);
+ i = this->LabelIdMap.insert(entry).first;
+ }
+ return i->second;
+}
+
+//----------------------------------------------------------------------
+void cmCTestCoverageHandler::LoadLabels()
+{
+ std::string fileList = this->CTest->GetBinaryDir();
+ fileList += cmake::GetCMakeFilesDirectory();
+ fileList += "/TargetDirectories.txt";
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " target directory list [" << fileList << "]\n");
+ cmsys::ifstream finList(fileList.c_str());
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(finList, line))
+ {
+ this->LoadLabels(line.c_str());
+ }
+}
+
+//----------------------------------------------------------------------
+void cmCTestCoverageHandler::LoadLabels(const char* dir)
+{
+ LabelSet& dirLabels = this->TargetDirs[dir];
+ std::string fname = dir;
+ fname += "/Labels.txt";
+ cmsys::ifstream fin(fname.c_str());
+ if(!fin)
+ {
+ return;
+ }
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " loading labels from [" << fname << "]\n");
+ bool inTarget = true;
+ std::string source;
+ std::string line;
+ std::vector<int> targetLabels;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ if(line.empty() || line[0] == '#')
+ {
+ // Ignore blank and comment lines.
+ continue;
+ }
+ else if(line[0] == ' ')
+ {
+ // Label lines appear indented by one space.
+ std::string label = line.substr(1);
+ int id = this->GetLabelId(label);
+ dirLabels.insert(id);
+ if(inTarget)
+ {
+ targetLabels.push_back(id);
+ }
+ else
+ {
+ this->SourceLabels[source].insert(id);
+ }
+ }
+ else
+ {
+ // Non-indented lines specify a source file name. The first one
+ // is the end of the target-wide labels.
+ inTarget = false;
+
+ source = this->CTest->GetShortPathToFile(line.c_str());
+
+ // Label the source with the target labels.
+ LabelSet& labelSet = this->SourceLabels[source];
+ for(std::vector<int>::const_iterator li = targetLabels.begin();
+ li != targetLabels.end(); ++li)
+ {
+ labelSet.insert(*li);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------
+void cmCTestCoverageHandler::WriteXMLLabels(std::ostream& os,
+ std::string const& source)
+{
+ LabelMapType::const_iterator li = this->SourceLabels.find(source);
+ if(li != this->SourceLabels.end() && !li->second.empty())
+ {
+ os << "\t\t<Labels>\n";
+ for(LabelSet::const_iterator lsi = li->second.begin();
+ lsi != li->second.end(); ++lsi)
+ {
+ os << "\t\t\t<Label>" << cmXMLSafe(this->Labels[*lsi]) << "</Label>\n";
+ }
+ os << "\t\t</Labels>\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmCTestCoverageHandler::SetLabelFilter(std::set<std::string> const& labels)
+{
+ this->LabelFilter.clear();
+ for(std::set<std::string>::const_iterator li = labels.begin();
+ li != labels.end(); ++li)
+ {
+ this->LabelFilter.insert(this->GetLabelId(*li));
+ }
+}
+
+//----------------------------------------------------------------------
+bool cmCTestCoverageHandler::IntersectsFilter(LabelSet const& labels)
+{
+ // If there is no label filter then nothing is filtered out.
+ if(this->LabelFilter.empty())
+ {
+ return true;
+ }
+
+ std::vector<int> ids;
+ cmsys_stl::set_intersection
+ (labels.begin(), labels.end(),
+ this->LabelFilter.begin(), this->LabelFilter.end(),
+ cmsys_stl::back_inserter(ids));
+ return !ids.empty();
+}
+
+//----------------------------------------------------------------------
+bool cmCTestCoverageHandler::IsFilteredOut(std::string const& source)
+{
+ // If there is no label filter then nothing is filtered out.
+ if(this->LabelFilter.empty())
+ {
+ return false;
+ }
+
+ // The source is filtered out if it does not have any labels in
+ // common with the filter set.
+ std::string shortSrc = this->CTest->GetShortPathToFile(source.c_str());
+ LabelMapType::const_iterator li = this->SourceLabels.find(shortSrc);
+ if(li != this->SourceLabels.end())
+ {
+ return !this->IntersectsFilter(li->second);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+std::set<std::string> cmCTestCoverageHandler::FindUncoveredFiles(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ std::set<std::string> extraMatches;
+
+ for(std::vector<std::string>::iterator i = this->ExtraCoverageGlobs.begin();
+ i != this->ExtraCoverageGlobs.end(); ++i)
+ {
+ cmsys::Glob gl;
+ gl.RecurseOn();
+ gl.RecurseThroughSymlinksOff();
+ std::string glob = cont->SourceDir + "/" + *i;
+ gl.FindFiles(glob);
+ std::vector<std::string> files = gl.GetFiles();
+ for(std::vector<std::string>::iterator f = files.begin();
+ f != files.end(); ++f)
+ {
+ if(this->ShouldIDoCoverage(f->c_str(),
+ cont->SourceDir.c_str(), cont->BinaryDir.c_str()))
+ {
+ extraMatches.insert(this->CTest->GetShortPathToFile(
+ f->c_str()));
+ }
+ }
+ }
+
+ if(extraMatches.size())
+ {
+ for(cmCTestCoverageHandlerContainer::TotalCoverageMap::iterator i =
+ cont->TotalCoverage.begin(); i != cont->TotalCoverage.end(); ++i)
+ {
+ std::string shortPath = this->CTest->GetShortPathToFile(
+ i->first.c_str());
+ extraMatches.erase(shortPath);
+ }
+ }
+ return extraMatches;
+}
diff --git a/Source/CTest/cmCTestCoverageHandler.h b/Source/CTest/cmCTestCoverageHandler.h
new file mode 100644
index 0000000000..d0f274c81c
--- /dev/null
+++ b/Source/CTest/cmCTestCoverageHandler.h
@@ -0,0 +1,150 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestCoverageHandler_h
+#define cmCTestCoverageHandler_h
+
+
+#include "cmCTestGenericHandler.h"
+#include "cmListFileCache.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+class cmGeneratedFileStream;
+class cmCTestCoverageHandlerContainer
+{
+public:
+ int Error;
+ std::string SourceDir;
+ std::string BinaryDir;
+ typedef std::vector<int> SingleFileCoverageVector;
+ typedef std::map<std::string, SingleFileCoverageVector> TotalCoverageMap;
+ TotalCoverageMap TotalCoverage;
+ std::ostream* OFS;
+};
+/** \class cmCTestCoverageHandler
+ * \brief A class that handles coverage computaiton for ctest
+ *
+ */
+class cmCTestCoverageHandler : public cmCTestGenericHandler
+{
+public:
+ cmTypeMacro(cmCTestCoverageHandler, cmCTestGenericHandler);
+
+ /*
+ * The main entry point for this class
+ */
+ int ProcessHandler();
+
+ cmCTestCoverageHandler();
+
+ virtual void Initialize();
+
+ /**
+ * This method is called when reading CTest custom file
+ */
+ void PopulateCustomVectors(cmMakefile *mf);
+
+ /** Report coverage only for sources with these labels. */
+ void SetLabelFilter(std::set<std::string> const& labels);
+
+private:
+ bool ShouldIDoCoverage(const char* file, const char* srcDir,
+ const char* binDir);
+ void CleanCoverageLogFiles(std::ostream& log);
+ bool StartCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
+ void EndCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
+
+ //! Handle coverage using GCC's GCov
+ int HandleGCovCoverage(cmCTestCoverageHandlerContainer* cont);
+ void FindGCovFiles(std::vector<std::string>& files);
+
+ //! Handle coverage using Intel's LCov
+ int HandleLCovCoverage(cmCTestCoverageHandlerContainer* cont);
+ void FindLCovFiles(std::vector<std::string>& files);
+
+ //! Handle coverage using xdebug php coverage
+ int HandlePHPCoverage(cmCTestCoverageHandlerContainer* cont);
+
+ //! Handle coverage for Python with coverage.py
+ int HandleCoberturaCoverage(cmCTestCoverageHandlerContainer* cont);
+
+ //! Handle coverage for mumps
+ int HandleMumpsCoverage(cmCTestCoverageHandlerContainer* cont);
+
+ //! Handle coverage for Jacoco
+ int HandleJacocoCoverage(cmCTestCoverageHandlerContainer* cont);
+
+//! Handle coverage using Bullseye
+ int HandleBullseyeCoverage(cmCTestCoverageHandlerContainer* cont);
+ int RunBullseyeSourceSummary(cmCTestCoverageHandlerContainer* cont);
+ int RunBullseyeCoverageBranch(cmCTestCoverageHandlerContainer* cont,
+ std::set<std::string>& coveredFileNames,
+ std::vector<std::string>& files,
+ std::vector<std::string>& filesFullPath);
+
+ int RunBullseyeCommand(
+ cmCTestCoverageHandlerContainer* cont,
+ const char* cmd,
+ const char* arg,
+ std::string& outputFile);
+ bool ParseBullsEyeCovsrcLine(
+ std::string const& inputLine,
+ std::string& sourceFile,
+ int& functionsCalled,
+ int& totalFunctions,
+ int& percentFunction,
+ int& branchCovered,
+ int& totalBranches,
+ int& percentBranch);
+ bool GetNextInt(std::string const& inputLine,
+ std::string::size_type& pos,
+ int& value);
+ //! Handle Python coverage using Python's Trace.py
+ int HandleTracePyCoverage(cmCTestCoverageHandlerContainer* cont);
+
+ // Find the source file based on the source and build tree. This is used for
+ // Trace.py mode, since that one does not tell us where the source file is.
+ std::string FindFile(cmCTestCoverageHandlerContainer* cont,
+ std::string fileName);
+
+ std::set<std::string> FindUncoveredFiles(
+ cmCTestCoverageHandlerContainer* cont);
+ std::vector<std::string> CustomCoverageExclude;
+ std::vector<cmsys::RegularExpression> CustomCoverageExcludeRegex;
+ std::vector<std::string> ExtraCoverageGlobs;
+
+
+ // Map from source file to label ids.
+ class LabelSet: public std::set<int> {};
+ typedef std::map<std::string, LabelSet> LabelMapType;
+ LabelMapType SourceLabels;
+ LabelMapType TargetDirs;
+
+ // Map from label name to label id.
+ typedef std::map<std::string, int> LabelIdMapType;
+ LabelIdMapType LabelIdMap;
+ std::vector<std::string> Labels;
+ int GetLabelId(std::string const& label);
+
+ // Label reading and writing methods.
+ void LoadLabels();
+ void LoadLabels(const char* dir);
+ void WriteXMLLabels(std::ostream& os, std::string const& source);
+
+ // Label-based filtering.
+ std::set<int> LabelFilter;
+ bool IntersectsFilter(LabelSet const& labels);
+ bool IsFilteredOut(std::string const& source);
+};
+
+#endif
diff --git a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.cxx b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.cxx
new file mode 100644
index 0000000000..5ddef01a75
--- /dev/null
+++ b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.cxx
@@ -0,0 +1,36 @@
+/*============================================================================
+ 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 "cmCTestEmptyBinaryDirectoryCommand.h"
+
+#include "cmCTestScriptHandler.h"
+
+bool cmCTestEmptyBinaryDirectoryCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() != 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ if ( !cmCTestScriptHandler::EmptyBinaryDirectory(args[0].c_str()) )
+ {
+ cmOStringStream ostr;
+ ostr << "problem removing the binary directory: " << args[0];
+ this->SetError(ostr.str());
+ return false;
+ }
+
+ return true;
+}
+
+
diff --git a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h
new file mode 100644
index 0000000000..d182d17947
--- /dev/null
+++ b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 cmCTestEmptyBinaryDirectoryCommand_h
+#define cmCTestEmptyBinaryDirectoryCommand_h
+
+#include "cmCTestCommand.h"
+
+/** \class cmCTestEmptyBinaryDirectory
+ * \brief Run a ctest script
+ *
+ * cmLibrarysCommand defines a list of executable (i.e., test)
+ * programs to create.
+ */
+class cmCTestEmptyBinaryDirectoryCommand : public cmCTestCommand
+{
+public:
+
+ cmCTestEmptyBinaryDirectoryCommand() {}
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestEmptyBinaryDirectoryCommand* ni
+ = new cmCTestEmptyBinaryDirectoryCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_empty_binary_directory";}
+
+ cmTypeMacro(cmCTestEmptyBinaryDirectoryCommand, cmCTestCommand);
+
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx
new file mode 100644
index 0000000000..aaa01b2d00
--- /dev/null
+++ b/Source/CTest/cmCTestGIT.cxx
@@ -0,0 +1,653 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestGIT.h"
+
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/ios/sstream>
+#include <cmsys/Process.h>
+#include <cmsys/FStream.hxx>
+
+#include <sys/types.h>
+#include <time.h>
+#include <ctype.h>
+
+//----------------------------------------------------------------------------
+static unsigned int cmCTestGITVersion(unsigned int epic, unsigned int major,
+ unsigned int minor, unsigned int fix)
+{
+ // 1.6.5.0 maps to 10605000
+ return fix + minor*1000 + major*100000 + epic*10000000;
+}
+
+//----------------------------------------------------------------------------
+cmCTestGIT::cmCTestGIT(cmCTest* ct, std::ostream& log):
+ cmCTestGlobalVC(ct, log)
+{
+ this->PriorRev = this->Unknown;
+ this->CurrentGitVersion = 0;
+}
+
+//----------------------------------------------------------------------------
+cmCTestGIT::~cmCTestGIT()
+{
+}
+
+//----------------------------------------------------------------------------
+class cmCTestGIT::OneLineParser: public cmCTestVC::LineParser
+{
+public:
+ OneLineParser(cmCTestGIT* git, const char* prefix,
+ std::string& l): Line1(l)
+ {
+ this->SetLog(&git->Log, prefix);
+ }
+private:
+ std::string& Line1;
+ virtual bool ProcessLine()
+ {
+ // Only the first line is of interest.
+ this->Line1 = this->Line;
+ return false;
+ }
+};
+
+//----------------------------------------------------------------------------
+std::string cmCTestGIT::GetWorkingRevision()
+{
+ // Run plumbing "git rev-list" to get work tree revision.
+ const char* git = this->CommandLineTool.c_str();
+ const char* git_rev_list[] = {git, "rev-list", "-n", "1", "HEAD", "--", 0};
+ std::string rev;
+ OneLineParser out(this, "rl-out> ", rev);
+ OutputLogger err(this->Log, "rl-err> ");
+ this->RunChild(git_rev_list, &out, &err);
+ return rev;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestGIT::NoteOldRevision()
+{
+ this->OldRevision = this->GetWorkingRevision();
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
+ << this->OldRevision << "\n");
+ this->PriorRev.Rev = this->OldRevision;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestGIT::NoteNewRevision()
+{
+ this->NewRevision = this->GetWorkingRevision();
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
+ << this->NewRevision << "\n");
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTestGIT::FindGitDir()
+{
+ std::string git_dir;
+
+ // Run "git rev-parse --git-dir" to locate the real .git directory.
+ const char* git = this->CommandLineTool.c_str();
+ char const* git_rev_parse[] = {git, "rev-parse", "--git-dir", 0};
+ std::string git_dir_line;
+ OneLineParser rev_parse_out(this, "rev-parse-out> ", git_dir_line);
+ OutputLogger rev_parse_err(this->Log, "rev-parse-err> ");
+ if(this->RunChild(git_rev_parse, &rev_parse_out, &rev_parse_err))
+ {
+ git_dir = git_dir_line;
+ }
+ if(git_dir.empty())
+ {
+ git_dir = ".git";
+ }
+
+ // Git reports a relative path only when the .git directory is in
+ // the current directory.
+ if(git_dir[0] == '.')
+ {
+ git_dir = this->SourceDirectory + "/" + git_dir;
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ else if(git_dir[0] == '/')
+ {
+ // Cygwin Git reports a full path that Cygwin understands, but we
+ // are a Windows application. Run "cygpath" to get Windows path.
+ std::string cygpath_exe = cmSystemTools::GetFilenamePath(git);
+ cygpath_exe += "/cygpath.exe";
+ if(cmSystemTools::FileExists(cygpath_exe.c_str()))
+ {
+ char const* cygpath[] = {cygpath_exe.c_str(), "-w", git_dir.c_str(), 0};
+ OneLineParser cygpath_out(this, "cygpath-out> ", git_dir_line);
+ OutputLogger cygpath_err(this->Log, "cygpath-err> ");
+ if(this->RunChild(cygpath, &cygpath_out, &cygpath_err))
+ {
+ git_dir = git_dir_line;
+ }
+ }
+ }
+#endif
+ return git_dir;
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTestGIT::FindTopDir()
+{
+ std::string top_dir = this->SourceDirectory;
+
+ // Run "git rev-parse --show-cdup" to locate the top of the tree.
+ const char* git = this->CommandLineTool.c_str();
+ char const* git_rev_parse[] = {git, "rev-parse", "--show-cdup", 0};
+ std::string cdup;
+ OneLineParser rev_parse_out(this, "rev-parse-out> ", cdup);
+ OutputLogger rev_parse_err(this->Log, "rev-parse-err> ");
+ if(this->RunChild(git_rev_parse, &rev_parse_out, &rev_parse_err) &&
+ !cdup.empty())
+ {
+ top_dir += "/";
+ top_dir += cdup;
+ top_dir = cmSystemTools::CollapseFullPath(top_dir.c_str());
+ }
+ return top_dir;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestGIT::UpdateByFetchAndReset()
+{
+ const char* git = this->CommandLineTool.c_str();
+
+ // Use "git fetch" to get remote commits.
+ std::vector<char const*> git_fetch;
+ git_fetch.push_back(git);
+ git_fetch.push_back("fetch");
+
+ // Add user-specified update options.
+ std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
+ if(opts.empty())
+ {
+ opts = this->CTest->GetCTestConfiguration("GITUpdateOptions");
+ }
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
+ for(std::vector<std::string>::const_iterator ai = args.begin();
+ ai != args.end(); ++ai)
+ {
+ git_fetch.push_back(ai->c_str());
+ }
+
+ // Sentinel argument.
+ git_fetch.push_back(0);
+
+ // Fetch upstream refs.
+ OutputLogger fetch_out(this->Log, "fetch-out> ");
+ OutputLogger fetch_err(this->Log, "fetch-err> ");
+ if(!this->RunUpdateCommand(&git_fetch[0], &fetch_out, &fetch_err))
+ {
+ return false;
+ }
+
+ // Identify the merge head that would be used by "git pull".
+ std::string sha1;
+ {
+ std::string fetch_head = this->FindGitDir() + "/FETCH_HEAD";
+ cmsys::ifstream fin(fetch_head.c_str(), std::ios::in | std::ios::binary);
+ if(!fin)
+ {
+ this->Log << "Unable to open " << fetch_head << "\n";
+ return false;
+ }
+ std::string line;
+ while(sha1.empty() && cmSystemTools::GetLineFromStream(fin, line))
+ {
+ this->Log << "FETCH_HEAD> " << line << "\n";
+ if(line.find("\tnot-for-merge\t") == line.npos)
+ {
+ std::string::size_type pos = line.find('\t');
+ if(pos != line.npos)
+ {
+ sha1 = line.substr(0, pos);
+ }
+ }
+ }
+ if(sha1.empty())
+ {
+ this->Log << "FETCH_HEAD has no upstream branch candidate!\n";
+ return false;
+ }
+ }
+
+ // Reset the local branch to point at that tracked from upstream.
+ char const* git_reset[] = {git, "reset", "--hard", sha1.c_str(), 0};
+ OutputLogger reset_out(this->Log, "reset-out> ");
+ OutputLogger reset_err(this->Log, "reset-err> ");
+ return this->RunChild(&git_reset[0], &reset_out, &reset_err);
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestGIT::UpdateByCustom(std::string const& custom)
+{
+ std::vector<std::string> git_custom_command;
+ cmSystemTools::ExpandListArgument(custom, git_custom_command, true);
+ std::vector<char const*> git_custom;
+ for(std::vector<std::string>::const_iterator
+ i = git_custom_command.begin(); i != git_custom_command.end(); ++i)
+ {
+ git_custom.push_back(i->c_str());
+ }
+ git_custom.push_back(0);
+
+ OutputLogger custom_out(this->Log, "custom-out> ");
+ OutputLogger custom_err(this->Log, "custom-err> ");
+ return this->RunUpdateCommand(&git_custom[0], &custom_out, &custom_err);
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestGIT::UpdateInternal()
+{
+ std::string custom = this->CTest->GetCTestConfiguration("GITUpdateCustom");
+ if(!custom.empty())
+ {
+ return this->UpdateByCustom(custom);
+ }
+ return this->UpdateByFetchAndReset();
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestGIT::UpdateImpl()
+{
+ if(!this->UpdateInternal())
+ {
+ return false;
+ }
+
+ std::string top_dir = this->FindTopDir();
+ const char* git = this->CommandLineTool.c_str();
+ const char* recursive = "--recursive";
+
+ // Git < 1.6.5.0 did not support --recursive
+ if(this->GetGitVersion() < cmCTestGITVersion(1,6,5,0))
+ {
+ recursive = 0;
+ // No need to require >= 1.6.5.0 if there are no submodules.
+ if(cmSystemTools::FileExists((top_dir + "/.gitmodules").c_str()))
+ {
+ this->Log << "Git < 1.6.5.0 cannot update submodules recursively\n";
+ }
+ }
+
+ char const* git_submodule[] = {git, "submodule", "update", recursive, 0};
+ OutputLogger submodule_out(this->Log, "submodule-out> ");
+ OutputLogger submodule_err(this->Log, "submodule-err> ");
+ return this->RunChild(git_submodule, &submodule_out, &submodule_err,
+ top_dir.c_str());
+}
+
+//----------------------------------------------------------------------------
+unsigned int cmCTestGIT::GetGitVersion()
+{
+ if(!this->CurrentGitVersion)
+ {
+ const char* git = this->CommandLineTool.c_str();
+ char const* git_version[] = {git, "--version", 0};
+ std::string version;
+ OneLineParser version_out(this, "version-out> ", version);
+ OutputLogger version_err(this->Log, "version-err> ");
+ unsigned int v[4] = {0,0,0,0};
+ if(this->RunChild(git_version, &version_out, &version_err) &&
+ sscanf(version.c_str(), "git version %u.%u.%u.%u",
+ &v[0], &v[1], &v[2], &v[3]) >= 3)
+ {
+ this->CurrentGitVersion = cmCTestGITVersion(v[0], v[1], v[2], v[3]);
+ }
+ }
+ return this->CurrentGitVersion;
+}
+
+//----------------------------------------------------------------------------
+/* Diff format:
+
+ :src-mode dst-mode src-sha1 dst-sha1 status\0
+ src-path\0
+ [dst-path\0]
+
+ The format is repeated for every file changed. The [dst-path\0]
+ line appears only for lines with status 'C' or 'R'. See 'git help
+ diff-tree' for details.
+*/
+class cmCTestGIT::DiffParser: public cmCTestVC::LineParser
+{
+public:
+ DiffParser(cmCTestGIT* git, const char* prefix):
+ LineParser('\0', false), GIT(git), DiffField(DiffFieldNone)
+ {
+ this->SetLog(&git->Log, prefix);
+ }
+
+ typedef cmCTestGIT::Change Change;
+ std::vector<Change> Changes;
+protected:
+ cmCTestGIT* GIT;
+ enum DiffFieldType { DiffFieldNone, DiffFieldChange,
+ DiffFieldSrc, DiffFieldDst };
+ DiffFieldType DiffField;
+ Change CurChange;
+
+ void DiffReset()
+ {
+ this->DiffField = DiffFieldNone;
+ this->Changes.clear();
+ }
+
+ virtual bool ProcessLine()
+ {
+ if(this->Line[0] == ':')
+ {
+ this->DiffField = DiffFieldChange;
+ this->CurChange = Change();
+ }
+ if(this->DiffField == DiffFieldChange)
+ {
+ // :src-mode dst-mode src-sha1 dst-sha1 status
+ if(this->Line[0] != ':')
+ {
+ this->DiffField = DiffFieldNone;
+ return true;
+ }
+ const char* src_mode_first = this->Line.c_str()+1;
+ const char* src_mode_last = this->ConsumeField(src_mode_first);
+ const char* dst_mode_first = this->ConsumeSpace(src_mode_last);
+ const char* dst_mode_last = this->ConsumeField(dst_mode_first);
+ const char* src_sha1_first = this->ConsumeSpace(dst_mode_last);
+ const char* src_sha1_last = this->ConsumeField(src_sha1_first);
+ const char* dst_sha1_first = this->ConsumeSpace(src_sha1_last);
+ const char* dst_sha1_last = this->ConsumeField(dst_sha1_first);
+ const char* status_first = this->ConsumeSpace(dst_sha1_last);
+ const char* status_last = this->ConsumeField(status_first);
+ if(status_first != status_last)
+ {
+ this->CurChange.Action = *status_first;
+ this->DiffField = DiffFieldSrc;
+ }
+ else
+ {
+ this->DiffField = DiffFieldNone;
+ }
+ }
+ else if(this->DiffField == DiffFieldSrc)
+ {
+ // src-path
+ if(this->CurChange.Action == 'C')
+ {
+ // Convert copy to addition of destination.
+ this->CurChange.Action = 'A';
+ this->DiffField = DiffFieldDst;
+ }
+ else if(this->CurChange.Action == 'R')
+ {
+ // Convert rename to deletion of source and addition of destination.
+ this->CurChange.Action = 'D';
+ this->CurChange.Path = this->Line;
+ this->Changes.push_back(this->CurChange);
+
+ this->CurChange = Change('A');
+ this->DiffField = DiffFieldDst;
+ }
+ else
+ {
+ this->CurChange.Path = this->Line;
+ this->Changes.push_back(this->CurChange);
+ this->DiffField = this->DiffFieldNone;
+ }
+ }
+ else if(this->DiffField == DiffFieldDst)
+ {
+ // dst-path
+ this->CurChange.Path = this->Line;
+ this->Changes.push_back(this->CurChange);
+ this->DiffField = this->DiffFieldNone;
+ }
+ return true;
+ }
+
+ const char* ConsumeSpace(const char* c)
+ {
+ while(*c && isspace(*c)) { ++c; }
+ return c;
+ }
+ const char* ConsumeField(const char* c)
+ {
+ while(*c && !isspace(*c)) { ++c; }
+ return c;
+ }
+};
+
+//----------------------------------------------------------------------------
+/* Commit format:
+
+ commit ...\n
+ tree ...\n
+ parent ...\n
+ author ...\n
+ committer ...\n
+ \n
+ Log message indented by (4) spaces\n
+ (even blank lines have the spaces)\n
+ [[
+ \n
+ [Diff format]
+ OR
+ \0
+ ]]
+
+ The header may have more fields. See 'git help diff-tree'.
+*/
+class cmCTestGIT::CommitParser: public cmCTestGIT::DiffParser
+{
+public:
+ CommitParser(cmCTestGIT* git, const char* prefix):
+ DiffParser(git, prefix), Section(SectionHeader)
+ {
+ this->Separator = SectionSep[this->Section];
+ }
+
+private:
+ typedef cmCTestGIT::Revision Revision;
+ enum SectionType { SectionHeader, SectionBody, SectionDiff, SectionCount };
+ static char const SectionSep[SectionCount];
+ SectionType Section;
+ Revision Rev;
+
+ struct Person
+ {
+ std::string Name;
+ std::string EMail;
+ unsigned long Time;
+ long TimeZone;
+ Person(): Name(), EMail(), Time(0), TimeZone(0) {}
+ };
+
+ void ParsePerson(const char* str, Person& person)
+ {
+ // Person Name <person@domain.com> 1234567890 +0000
+ const char* c = str;
+ while(*c && isspace(*c)) { ++c; }
+
+ const char* name_first = c;
+ while(*c && *c != '<') { ++c; }
+ const char* name_last = c;
+ while(name_last != name_first && isspace(*(name_last-1))) { --name_last; }
+ person.Name.assign(name_first, name_last-name_first);
+
+ const char* email_first = *c? ++c : c;
+ while(*c && *c != '>') { ++c; }
+ const char* email_last = *c? c++ : c;
+ person.EMail.assign(email_first, email_last-email_first);
+
+ person.Time = strtoul(c, (char**)&c, 10);
+ person.TimeZone = strtol(c, (char**)&c, 10);
+ }
+
+ virtual bool ProcessLine()
+ {
+ if(this->Line.empty())
+ {
+ if(this->Section == SectionBody && this->LineEnd == '\0')
+ {
+ // Skip SectionDiff
+ this->NextSection();
+ }
+ this->NextSection();
+ }
+ else
+ {
+ switch(this->Section)
+ {
+ case SectionHeader: this->DoHeaderLine(); break;
+ case SectionBody: this->DoBodyLine(); break;
+ case SectionDiff: this->DiffParser::ProcessLine(); break;
+ case SectionCount: break; // never happens
+ }
+ }
+ return true;
+ }
+
+ void NextSection()
+ {
+ this->Section = SectionType((this->Section+1) % SectionCount);
+ this->Separator = SectionSep[this->Section];
+ if(this->Section == SectionHeader)
+ {
+ this->GIT->DoRevision(this->Rev, this->Changes);
+ this->Rev = Revision();
+ this->DiffReset();
+ }
+ }
+
+ void DoHeaderLine()
+ {
+ // Look for header fields that we need.
+ if(cmHasLiteralPrefix(this->Line.c_str(), "commit "))
+ {
+ this->Rev.Rev = this->Line.c_str()+7;
+ }
+ else if(cmHasLiteralPrefix(this->Line.c_str(), "author "))
+ {
+ Person author;
+ this->ParsePerson(this->Line.c_str()+7, author);
+ this->Rev.Author = author.Name;
+ this->Rev.EMail = author.EMail;
+ this->Rev.Date = this->FormatDateTime(author);
+ }
+ else if(cmHasLiteralPrefix(this->Line.c_str(), "committer "))
+ {
+ Person committer;
+ this->ParsePerson(this->Line.c_str()+10, committer);
+ this->Rev.Committer = committer.Name;
+ this->Rev.CommitterEMail = committer.EMail;
+ this->Rev.CommitDate = this->FormatDateTime(committer);
+ }
+ }
+
+ void DoBodyLine()
+ {
+ // Commit log lines are indented by 4 spaces.
+ if(this->Line.size() >= 4)
+ {
+ this->Rev.Log += this->Line.substr(4);
+ }
+ this->Rev.Log += "\n";
+ }
+
+ std::string FormatDateTime(Person const& person)
+ {
+ // Convert the time to a human-readable format that is also easy
+ // to machine-parse: "CCYY-MM-DD hh:mm:ss".
+ time_t seconds = static_cast<time_t>(person.Time);
+ struct tm* t = gmtime(&seconds);
+ char dt[1024];
+ sprintf(dt, "%04d-%02d-%02d %02d:%02d:%02d",
+ t->tm_year+1900, t->tm_mon+1, t->tm_mday,
+ t->tm_hour, t->tm_min, t->tm_sec);
+ std::string out = dt;
+
+ // Add the time-zone field "+zone" or "-zone".
+ char tz[32];
+ if(person.TimeZone >= 0)
+ {
+ sprintf(tz, " +%04ld", person.TimeZone);
+ }
+ else
+ {
+ sprintf(tz, " -%04ld", -person.TimeZone);
+ }
+ out += tz;
+ return out;
+ }
+};
+
+char const cmCTestGIT::CommitParser::SectionSep[SectionCount] =
+{'\n', '\n', '\0'};
+
+//----------------------------------------------------------------------------
+void cmCTestGIT::LoadRevisions()
+{
+ // Use 'git rev-list ... | git diff-tree ...' to get revisions.
+ std::string range = this->OldRevision + ".." + this->NewRevision;
+ const char* git = this->CommandLineTool.c_str();
+ const char* git_rev_list[] =
+ {git, "rev-list", "--reverse", range.c_str(), "--", 0};
+ const char* git_diff_tree[] =
+ {git, "diff-tree", "--stdin", "--always", "-z", "-r", "--pretty=raw",
+ "--encoding=utf-8", 0};
+ this->Log << this->ComputeCommandLine(git_rev_list) << " | "
+ << this->ComputeCommandLine(git_diff_tree) << "\n";
+
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_AddCommand(cp, git_rev_list);
+ cmsysProcess_AddCommand(cp, git_diff_tree);
+ cmsysProcess_SetWorkingDirectory(cp, this->SourceDirectory.c_str());
+
+ CommitParser out(this, "dt-out> ");
+ OutputLogger err(this->Log, "dt-err> ");
+ this->RunProcess(cp, &out, &err);
+
+ // Send one extra zero-byte to terminate the last record.
+ out.Process("", 1);
+
+ cmsysProcess_Delete(cp);
+}
+
+//----------------------------------------------------------------------------
+void cmCTestGIT::LoadModifications()
+{
+ const char* git = this->CommandLineTool.c_str();
+
+ // Use 'git update-index' to refresh the index w.r.t. the work tree.
+ const char* git_update_index[] = {git, "update-index", "--refresh", 0};
+ OutputLogger ui_out(this->Log, "ui-out> ");
+ OutputLogger ui_err(this->Log, "ui-err> ");
+ this->RunChild(git_update_index, &ui_out, &ui_err);
+
+ // Use 'git diff-index' to get modified files.
+ const char* git_diff_index[] = {git, "diff-index", "-z", "HEAD", "--", 0};
+ DiffParser out(this, "di-out> ");
+ OutputLogger err(this->Log, "di-err> ");
+ this->RunChild(git_diff_index, &out, &err);
+
+ for(std::vector<Change>::const_iterator ci = out.Changes.begin();
+ ci != out.Changes.end(); ++ci)
+ {
+ this->DoModification(PathModified, ci->Path);
+ }
+}
diff --git a/Source/CTest/cmCTestGIT.h b/Source/CTest/cmCTestGIT.h
new file mode 100644
index 0000000000..f4fae8f9db
--- /dev/null
+++ b/Source/CTest/cmCTestGIT.h
@@ -0,0 +1,57 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestGIT_h
+#define cmCTestGIT_h
+
+#include "cmCTestGlobalVC.h"
+
+/** \class cmCTestGIT
+ * \brief Interaction with git command-line tool
+ *
+ */
+class cmCTestGIT: public cmCTestGlobalVC
+{
+public:
+ /** Construct with a CTest instance and update log stream. */
+ cmCTestGIT(cmCTest* ctest, std::ostream& log);
+
+ virtual ~cmCTestGIT();
+
+private:
+ unsigned int CurrentGitVersion;
+ unsigned int GetGitVersion();
+ std::string GetWorkingRevision();
+ virtual void NoteOldRevision();
+ virtual void NoteNewRevision();
+ virtual bool UpdateImpl();
+
+ std::string FindGitDir();
+ std::string FindTopDir();
+
+ bool UpdateByFetchAndReset();
+ bool UpdateByCustom(std::string const& custom);
+ bool UpdateInternal();
+
+ void LoadRevisions();
+ void LoadModifications();
+
+public: // needed by older Sun compilers
+ // Parsing helper classes.
+ class OneLineParser;
+ class DiffParser;
+ class CommitParser;
+ friend class OneLineParser;
+ friend class DiffParser;
+ friend class CommitParser;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestGenericHandler.cxx b/Source/CTest/cmCTestGenericHandler.cxx
new file mode 100644
index 0000000000..2df2229e73
--- /dev/null
+++ b/Source/CTest/cmCTestGenericHandler.cxx
@@ -0,0 +1,163 @@
+/*============================================================================
+ 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 "cmCTestGenericHandler.h"
+#include "cmSystemTools.h"
+
+#include "cmCTest.h"
+
+//----------------------------------------------------------------------
+cmCTestGenericHandler::cmCTestGenericHandler()
+{
+ this->HandlerVerbose = cmSystemTools::OUTPUT_NONE;
+ this->CTest = 0;
+ this->SubmitIndex = 0;
+ this->AppendXML = false;
+}
+
+//----------------------------------------------------------------------
+cmCTestGenericHandler::~cmCTestGenericHandler()
+{
+}
+
+//----------------------------------------------------------------------
+void cmCTestGenericHandler::SetOption(const std::string& op, const char* value)
+{
+ if ( !value )
+ {
+ cmCTestGenericHandler::t_StringToString::iterator remit
+ = this->Options.find(op);
+ if ( remit != this->Options.end() )
+ {
+ this->Options.erase(remit);
+ }
+ return;
+ }
+
+ this->Options[op] = value;
+}
+
+//----------------------------------------------------------------------
+void cmCTestGenericHandler::SetPersistentOption(const std::string& op,
+ const char* value)
+{
+ this->SetOption(op, value);
+ if ( !value )
+ {
+ cmCTestGenericHandler::t_StringToString::iterator remit
+ = this->PersistentOptions.find(op);
+ if ( remit != this->PersistentOptions.end() )
+ {
+ this->PersistentOptions.erase(remit);
+ }
+ return;
+ }
+
+ this->PersistentOptions[op] = value;
+}
+
+//----------------------------------------------------------------------
+void cmCTestGenericHandler::Initialize()
+{
+ this->AppendXML = false;
+ this->Options.clear();
+ t_StringToString::iterator it;
+ for ( it = this->PersistentOptions.begin();
+ it != this->PersistentOptions.end();
+ ++ it )
+ {
+ this->Options[it->first] = it->second.c_str();
+ }
+}
+
+//----------------------------------------------------------------------
+const char* cmCTestGenericHandler::GetOption(const std::string& op)
+{
+ cmCTestGenericHandler::t_StringToString::iterator remit
+ = this->Options.find(op);
+ if ( remit == this->Options.end() )
+ {
+ return 0;
+ }
+ return remit->second.c_str();
+}
+
+//----------------------------------------------------------------------
+bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part,
+ const char* name,
+ cmGeneratedFileStream& xofs)
+{
+ if ( !name )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot create resulting XML file without providing the name"
+ << std::endl;);
+ return false;
+ }
+ cmOStringStream ostr;
+ ostr << name;
+ if ( this->SubmitIndex > 0 )
+ {
+ ostr << "_" << this->SubmitIndex;
+ }
+ ostr << ".xml";
+ if(this->CTest->GetCurrentTag().empty())
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Current Tag empty, this may mean NightlyStartTime / "
+ "CTEST_NIGHTLY_START_TIME was not set correctly. Or "
+ "maybe you forgot to call ctest_start() before calling "
+ "ctest_configure()." << std::endl);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+ if( !this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(),
+ ostr.str(), xofs, true) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot create resulting XML file: " << ostr.str()
+ << std::endl);
+ return false;
+ }
+ this->CTest->AddSubmitFile(part, ostr.str().c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCTestGenericHandler::StartLogFile(const char* name,
+ cmGeneratedFileStream& xofs)
+{
+ if ( !name )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot create log file without providing the name" << std::endl;);
+ return false;
+ }
+ cmOStringStream ostr;
+ ostr << "Last" << name;
+ if ( this->SubmitIndex > 0 )
+ {
+ ostr << "_" << this->SubmitIndex;
+ }
+ if ( !this->CTest->GetCurrentTag().empty() )
+ {
+ ostr << "_" << this->CTest->GetCurrentTag();
+ }
+ ostr << ".log";
+ if( !this->CTest->OpenOutputFile("Temporary", ostr.str(), xofs) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create log file: "
+ << ostr.str() << std::endl);
+ return false;
+ }
+ return true;
+}
diff --git a/Source/CTest/cmCTestGenericHandler.h b/Source/CTest/cmCTestGenericHandler.h
new file mode 100644
index 0000000000..2788cba57a
--- /dev/null
+++ b/Source/CTest/cmCTestGenericHandler.h
@@ -0,0 +1,107 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestGenericHandler_h
+#define cmCTestGenericHandler_h
+
+
+#include "cmObject.h"
+#include "cmCTest.h"
+#include "cmSystemTools.h" //OutputOption
+
+class cmMakefile;
+class cmCTestCommand;
+class cmGeneratedFileStream;
+
+/** \class cmCTestGenericHandler
+ * \brief A superclass of all CTest Handlers
+ *
+ */
+class cmCTestGenericHandler : public cmObject
+{
+public:
+ /**
+ * If verbose then more informaiton is printed out
+ */
+ void SetVerbose(bool val)
+ { this->HandlerVerbose = val ?
+ cmSystemTools::OUTPUT_MERGE : cmSystemTools::OUTPUT_NONE; }
+
+ /**
+ * Populate internals from CTest custom scripts
+ */
+ virtual void PopulateCustomVectors(cmMakefile *) {}
+
+ /**
+ * Do the actual processing. Subclass has to override it.
+ * Return < 0 if error.
+ */
+ virtual int ProcessHandler() = 0;
+
+ /**
+ * Process command line arguments that are applicable for the handler
+ */
+ virtual int ProcessCommandLineArguments(
+ const std::string& /*currentArg*/, size_t& /*idx*/,
+ const std::vector<std::string>& /*allArgs*/) { return 1; }
+
+ /**
+ * Initialize handler
+ */
+ virtual void Initialize();
+
+ /**
+ * Set the CTest instance
+ */
+ void SetCTestInstance(cmCTest* ctest) { this->CTest = ctest; }
+ cmCTest* GetCTestInstance() { return this->CTest; }
+
+ /**
+ * Construct handler
+ */
+ cmCTestGenericHandler();
+ virtual ~cmCTestGenericHandler();
+
+ typedef std::map<std::string,std::string> t_StringToString;
+
+
+ void SetPersistentOption(const std::string& op, const char* value);
+ void SetOption(const std::string& op, const char* value);
+ const char* GetOption(const std::string& op);
+
+ void SetCommand(cmCTestCommand* command)
+ {
+ this->Command = command;
+ }
+
+ void SetSubmitIndex(int idx) { this->SubmitIndex = idx; }
+ int GetSubmitIndex() { return this->SubmitIndex; }
+
+ void SetAppendXML(bool b) { this->AppendXML = b; }
+
+protected:
+ bool StartResultingXML(cmCTest::Part part,
+ const char* name, cmGeneratedFileStream& xofs);
+ bool StartLogFile(const char* name, cmGeneratedFileStream& xofs);
+
+ bool AppendXML;
+ cmSystemTools::OutputOption HandlerVerbose;
+ cmCTest *CTest;
+ t_StringToString Options;
+ t_StringToString PersistentOptions;
+
+ cmCTestCommand* Command;
+ int SubmitIndex;
+};
+
+#endif
+
diff --git a/Source/CTest/cmCTestGlobalVC.cxx b/Source/CTest/cmCTestGlobalVC.cxx
new file mode 100644
index 0000000000..5f570b5d31
--- /dev/null
+++ b/Source/CTest/cmCTestGlobalVC.cxx
@@ -0,0 +1,142 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestGlobalVC.h"
+
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+//----------------------------------------------------------------------------
+cmCTestGlobalVC::cmCTestGlobalVC(cmCTest* ct, std::ostream& log):
+ cmCTestVC(ct, log)
+{
+ this->PriorRev = this->Unknown;
+}
+
+//----------------------------------------------------------------------------
+cmCTestGlobalVC::~cmCTestGlobalVC()
+{
+}
+
+//----------------------------------------------------------------------------
+const char* cmCTestGlobalVC::LocalPath(std::string const& path)
+{
+ return path.c_str();
+}
+
+//----------------------------------------------------------------------------
+void cmCTestGlobalVC::DoRevision(Revision const& revision,
+ std::vector<Change> const& changes)
+{
+ // Ignore changes in the old revision.
+ if(revision.Rev == this->OldRevision)
+ {
+ this->PriorRev = revision;
+ return;
+ }
+
+ // Indicate we found a revision.
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
+
+ // Store the revision.
+ this->Revisions.push_back(revision);
+
+ // Report this revision.
+ Revision const& rev = this->Revisions.back();
+ this->Log << "Found revision " << rev.Rev << "\n"
+ << " author = " << rev.Author << "\n"
+ << " date = " << rev.Date << "\n";
+
+ // Update information about revisions of the changed files.
+ for(std::vector<Change>::const_iterator ci = changes.begin();
+ ci != changes.end(); ++ci)
+ {
+ if(const char* local = this->LocalPath(ci->Path))
+ {
+ std::string dir = cmSystemTools::GetFilenamePath(local);
+ std::string name = cmSystemTools::GetFilenameName(local);
+ File& file = this->Dirs[dir][name];
+ file.PriorRev = file.Rev? file.Rev : &this->PriorRev;
+ file.Rev = &rev;
+ this->Log << " " << ci->Action << " " << local << " " << "\n";
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestGlobalVC::DoModification(PathStatus status,
+ std::string const& path)
+{
+ std::string dir = cmSystemTools::GetFilenamePath(path);
+ std::string name = cmSystemTools::GetFilenameName(path);
+ File& file = this->Dirs[dir][name];
+ file.Status = status;
+ // For local modifications the current rev is unknown and the
+ // prior rev is the latest from svn.
+ if(!file.Rev && !file.PriorRev)
+ {
+ file.PriorRev = &this->PriorRev;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestGlobalVC::WriteXMLDirectory(std::ostream& xml,
+ std::string const& path,
+ Directory const& dir)
+{
+ const char* slash = path.empty()? "":"/";
+ xml << "\t<Directory>\n"
+ << "\t\t<Name>" << cmXMLSafe(path) << "</Name>\n";
+ for(Directory::const_iterator fi = dir.begin(); fi != dir.end(); ++fi)
+ {
+ std::string full = path + slash + fi->first;
+ this->WriteXMLEntry(xml, path, fi->first, full, fi->second);
+ }
+ xml << "\t</Directory>\n";
+}
+
+//----------------------------------------------------------------------------
+void cmCTestGlobalVC::WriteXMLGlobal(std::ostream& xml)
+{
+ if(!this->NewRevision.empty())
+ {
+ xml << "\t<Revision>" << this->NewRevision << "</Revision>\n";
+ }
+ if(!this->OldRevision.empty() && this->OldRevision != this->NewRevision)
+ {
+ xml << "\t<PriorRevision>" << this->OldRevision << "</PriorRevision>\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestGlobalVC::WriteXMLUpdates(std::ostream& xml)
+{
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Gathering version information (one . per revision):\n"
+ " " << std::flush);
+ this->LoadRevisions();
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
+
+ this->LoadModifications();
+
+ this->WriteXMLGlobal(xml);
+
+ for(std::map<std::string, Directory>::const_iterator
+ di = this->Dirs.begin(); di != this->Dirs.end(); ++di)
+ {
+ this->WriteXMLDirectory(xml, di->first, di->second);
+ }
+
+ return true;
+}
diff --git a/Source/CTest/cmCTestGlobalVC.h b/Source/CTest/cmCTestGlobalVC.h
new file mode 100644
index 0000000000..cb0d165608
--- /dev/null
+++ b/Source/CTest/cmCTestGlobalVC.h
@@ -0,0 +1,68 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestGlobalVC_h
+#define cmCTestGlobalVC_h
+
+#include "cmCTestVC.h"
+
+/** \class cmCTestGlobalVC
+ * \brief Base class for handling globally-versioned trees
+ *
+ */
+class cmCTestGlobalVC: public cmCTestVC
+{
+public:
+ /** Construct with a CTest instance and update log stream. */
+ cmCTestGlobalVC(cmCTest* ctest, std::ostream& log);
+
+ virtual ~cmCTestGlobalVC();
+
+protected:
+ // Implement cmCTestVC internal API.
+ virtual bool WriteXMLUpdates(std::ostream& xml);
+
+ /** Represent a vcs-reported action for one path in a revision. */
+ struct Change
+ {
+ char Action;
+ std::string Path;
+ Change(char a = '?'): Action(a) {}
+ };
+
+ // Update status for files in each directory.
+ class Directory: public std::map<std::string, File> {};
+ std::map<std::string, Directory> Dirs;
+
+ // Old and new repository revisions.
+ std::string OldRevision;
+ std::string NewRevision;
+
+ // Information known about old revision.
+ Revision PriorRev;
+
+ // Information about revisions from a svn log.
+ std::list<Revision> Revisions;
+
+ virtual const char* LocalPath(std::string const& path);
+
+ virtual void DoRevision(Revision const& revision,
+ std::vector<Change> const& changes);
+ virtual void DoModification(PathStatus status, std::string const& path);
+ virtual void LoadModifications() = 0;
+ virtual void LoadRevisions() = 0;
+
+ virtual void WriteXMLGlobal(std::ostream& xml);
+ void WriteXMLDirectory(std::ostream& xml, std::string const& path,
+ Directory const& dir);
+};
+
+#endif
diff --git a/Source/CTest/cmCTestHG.cxx b/Source/CTest/cmCTestHG.cxx
new file mode 100644
index 0000000000..0f79d68a0b
--- /dev/null
+++ b/Source/CTest/cmCTestHG.cxx
@@ -0,0 +1,338 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestHG.h"
+
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include "cmXMLParser.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+//----------------------------------------------------------------------------
+cmCTestHG::cmCTestHG(cmCTest* ct, std::ostream& log):
+ cmCTestGlobalVC(ct, log)
+{
+ this->PriorRev = this->Unknown;
+}
+
+//----------------------------------------------------------------------------
+cmCTestHG::~cmCTestHG()
+{
+}
+
+//----------------------------------------------------------------------------
+class cmCTestHG::IdentifyParser: public cmCTestVC::LineParser
+{
+public:
+ IdentifyParser(cmCTestHG* hg, const char* prefix,
+ std::string& rev): Rev(rev)
+ {
+ this->SetLog(&hg->Log, prefix);
+ this->RegexIdentify.compile("^([0-9a-f]+)");
+ }
+private:
+ std::string& Rev;
+ cmsys::RegularExpression RegexIdentify;
+
+ bool ProcessLine()
+ {
+ if(this->RegexIdentify.find(this->Line))
+ {
+ this->Rev = this->RegexIdentify.match(1);
+ return false;
+ }
+ return true;
+ }
+};
+
+//----------------------------------------------------------------------------
+class cmCTestHG::StatusParser: public cmCTestVC::LineParser
+{
+public:
+ StatusParser(cmCTestHG* hg, const char* prefix): HG(hg)
+ {
+ this->SetLog(&hg->Log, prefix);
+ this->RegexStatus.compile("([MARC!?I]) (.*)");
+ }
+
+private:
+ cmCTestHG* HG;
+ cmsys::RegularExpression RegexStatus;
+
+ bool ProcessLine()
+ {
+ if(this->RegexStatus.find(this->Line))
+ {
+ this->DoPath(this->RegexStatus.match(1)[0],
+ this->RegexStatus.match(2));
+ }
+ return true;
+ }
+
+ void DoPath(char status, std::string const& path)
+ {
+ if(path.empty()) return;
+
+ // See "hg help status". Note that there is no 'conflict' status.
+ switch(status)
+ {
+ case 'M': case 'A': case '!': case 'R':
+ this->HG->DoModification(PathModified, path);
+ break;
+ case 'I': case '?': case 'C': case ' ': default:
+ break;
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+std::string cmCTestHG::GetWorkingRevision()
+{
+ // Run plumbing "hg identify" to get work tree revision.
+ const char* hg = this->CommandLineTool.c_str();
+ const char* hg_identify[] = {hg, "identify","-i", 0};
+ std::string rev;
+ IdentifyParser out(this, "rev-out> ", rev);
+ OutputLogger err(this->Log, "rev-err> ");
+ this->RunChild(hg_identify, &out, &err);
+ return rev;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestHG::NoteOldRevision()
+{
+ this->OldRevision = this->GetWorkingRevision();
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
+ << this->OldRevision << "\n");
+ this->PriorRev.Rev = this->OldRevision;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestHG::NoteNewRevision()
+{
+ this->NewRevision = this->GetWorkingRevision();
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
+ << this->NewRevision << "\n");
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestHG::UpdateImpl()
+{
+ // Use "hg pull" followed by "hg update" to update the working tree.
+ {
+ const char* hg = this->CommandLineTool.c_str();
+ const char* hg_pull[] = {hg, "pull","-v", 0};
+ OutputLogger out(this->Log, "pull-out> ");
+ OutputLogger err(this->Log, "pull-err> ");
+ this->RunChild(&hg_pull[0], &out, &err);
+ }
+
+ // TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY)
+
+ std::vector<char const*> hg_update;
+ hg_update.push_back(this->CommandLineTool.c_str());
+ hg_update.push_back("update");
+ hg_update.push_back("-v");
+
+ // Add user-specified update options.
+ std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
+ if(opts.empty())
+ {
+ opts = this->CTest->GetCTestConfiguration("HGUpdateOptions");
+ }
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
+ for(std::vector<std::string>::const_iterator ai = args.begin();
+ ai != args.end(); ++ai)
+ {
+ hg_update.push_back(ai->c_str());
+ }
+
+ // Sentinel argument.
+ hg_update.push_back(0);
+
+ OutputLogger out(this->Log, "update-out> ");
+ OutputLogger err(this->Log, "update-err> ");
+ return this->RunUpdateCommand(&hg_update[0], &out, &err);
+}
+
+//----------------------------------------------------------------------------
+class cmCTestHG::LogParser: public cmCTestVC::OutputLogger,
+ private cmXMLParser
+{
+public:
+ LogParser(cmCTestHG* hg, const char* prefix):
+ OutputLogger(hg->Log, prefix), HG(hg) { this->InitializeParser(); }
+ ~LogParser() { this->CleanupParser(); }
+private:
+ cmCTestHG* HG;
+
+ typedef cmCTestHG::Revision Revision;
+ typedef cmCTestHG::Change Change;
+ Revision Rev;
+ std::vector<Change> Changes;
+ Change CurChange;
+ std::vector<char> CData;
+
+ virtual bool ProcessChunk(const char* data, int length)
+ {
+ this->OutputLogger::ProcessChunk(data, length);
+ this->ParseChunk(data, length);
+ return true;
+ }
+
+ virtual void StartElement(const std::string& name, const char** atts)
+ {
+ this->CData.clear();
+ if(name == "logentry")
+ {
+ this->Rev = Revision();
+ if(const char* rev = this->FindAttribute(atts, "revision"))
+ {
+ this->Rev.Rev = rev;
+ }
+ this->Changes.clear();
+ }
+ }
+
+ virtual void CharacterDataHandler(const char* data, int length)
+ {
+ this->CData.insert(this->CData.end(), data, data+length);
+ }
+
+ virtual void EndElement(const std::string& name)
+ {
+ if(name == "logentry")
+ {
+ this->HG->DoRevision(this->Rev, this->Changes);
+ }
+ else if(!this->CData.empty() && name == "author")
+ {
+ this->Rev.Author.assign(&this->CData[0], this->CData.size());
+ }
+ else if(!this->CData.empty() && name == "email")
+ {
+ this->Rev.EMail.assign(&this->CData[0], this->CData.size());
+ }
+ else if(!this->CData.empty() && name == "date")
+ {
+ this->Rev.Date.assign(&this->CData[0], this->CData.size());
+ }
+ else if(!this->CData.empty() && name == "msg")
+ {
+ this->Rev.Log.assign(&this->CData[0], this->CData.size());
+ }
+ else if(!this->CData.empty() && name == "files")
+ {
+ std::vector<std::string> paths = this->SplitCData();
+ for(unsigned int i = 0; i < paths.size(); ++i)
+ {
+ // Updated by default, will be modified using file_adds and
+ // file_dels.
+ this->CurChange = Change('U');
+ this->CurChange.Path = paths[i];
+ this->Changes.push_back(this->CurChange);
+ }
+ }
+ else if(!this->CData.empty() && name == "file_adds")
+ {
+ std::string added_paths(this->CData.begin(), this->CData.end());
+ for(unsigned int i = 0; i < this->Changes.size(); ++i)
+ {
+ if(added_paths.find(this->Changes[i].Path) != std::string::npos)
+ {
+ this->Changes[i].Action = 'A';
+ }
+ }
+ }
+ else if(!this->CData.empty() && name == "file_dels")
+ {
+ std::string added_paths(this->CData.begin(), this->CData.end());
+ for(unsigned int i = 0; i < this->Changes.size(); ++i)
+ {
+ if(added_paths.find(this->Changes[i].Path) != std::string::npos)
+ {
+ this->Changes[i].Action = 'D';
+ }
+ }
+ }
+ this->CData.clear();
+ }
+
+ std::vector<std::string> SplitCData()
+ {
+ std::vector<std::string> output;
+ std::string currPath;
+ for(unsigned int i=0; i < this->CData.size(); ++i)
+ {
+ if(this->CData[i] != ' ')
+ {
+ currPath += this->CData[i];
+ }
+ else
+ {
+ output.push_back(currPath);
+ currPath = "";
+ }
+ }
+ output.push_back(currPath);
+ return output;
+ }
+
+ virtual void ReportError(int, int, const char* msg)
+ {
+ this->HG->Log << "Error parsing hg log xml: " << msg << "\n";
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmCTestHG::LoadRevisions()
+{
+ // Use 'hg log' to get revisions in a xml format.
+ //
+ // TODO: This should use plumbing or python code to be more precise.
+ // The "list of strings" templates like {files} will not work when
+ // the project has spaces in the path. Also, they may not have
+ // proper XML escapes.
+ std::string range = this->OldRevision + ":" + this->NewRevision;
+ const char* hg = this->CommandLineTool.c_str();
+ const char* hgXMLTemplate =
+ "<logentry\n"
+ " revision=\"{node|short}\">\n"
+ " <author>{author|person}</author>\n"
+ " <email>{author|email}</email>\n"
+ " <date>{date|isodate}</date>\n"
+ " <msg>{desc}</msg>\n"
+ " <files>{files}</files>\n"
+ " <file_adds>{file_adds}</file_adds>\n"
+ " <file_dels>{file_dels}</file_dels>\n"
+ "</logentry>\n";
+ const char* hg_log[] = {hg, "log","--removed", "-r", range.c_str(),
+ "--template", hgXMLTemplate, 0};
+
+ LogParser out(this, "log-out> ");
+ out.Process("<?xml version=\"1.0\"?>\n"
+ "<log>\n");
+ OutputLogger err(this->Log, "log-err> ");
+ this->RunChild(hg_log, &out, &err);
+ out.Process("</log>\n");
+}
+
+//----------------------------------------------------------------------------
+void cmCTestHG::LoadModifications()
+{
+ // Use 'hg status' to get modified files.
+ const char* hg = this->CommandLineTool.c_str();
+ const char* hg_status[] = {hg, "status", 0};
+ StatusParser out(this, "status-out> ");
+ OutputLogger err(this->Log, "status-err> ");
+ this->RunChild(hg_status, &out, &err);
+}
diff --git a/Source/CTest/cmCTestHG.h b/Source/CTest/cmCTestHG.h
new file mode 100644
index 0000000000..1eaf9337e8
--- /dev/null
+++ b/Source/CTest/cmCTestHG.h
@@ -0,0 +1,47 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestHG_h
+#define cmCTestHG_h
+
+#include "cmCTestGlobalVC.h"
+
+/** \class cmCTestHG
+ * \brief Interaction with Mercurial command-line tool
+ *
+ */
+class cmCTestHG: public cmCTestGlobalVC
+{
+public:
+ /** Construct with a CTest instance and update log stream. */
+ cmCTestHG(cmCTest* ctest, std::ostream& log);
+
+ virtual ~cmCTestHG();
+
+private:
+ std::string GetWorkingRevision();
+ virtual void NoteOldRevision();
+ virtual void NoteNewRevision();
+ virtual bool UpdateImpl();
+
+ void LoadRevisions();
+ void LoadModifications();
+
+ // Parsing helper classes.
+ class IdentifyParser;
+ class StatusParser;
+ class LogParser;
+ friend class IdentifyParser;
+ friend class StatusParser;
+ friend class LogParser;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx
new file mode 100644
index 0000000000..0e29160dde
--- /dev/null
+++ b/Source/CTest/cmCTestHandlerCommand.cxx
@@ -0,0 +1,198 @@
+/*============================================================================
+ 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 "cmCTestHandlerCommand.h"
+
+#include "cmCTest.h"
+#include "cmCTestGenericHandler.h"
+
+cmCTestHandlerCommand::cmCTestHandlerCommand()
+{
+ const size_t INIT_SIZE = 100;
+ size_t cc;
+ this->Arguments.reserve(INIT_SIZE);
+ for ( cc = 0; cc < INIT_SIZE; ++ cc )
+ {
+ this->Arguments.push_back(0);
+ }
+ this->Arguments[ct_RETURN_VALUE] = "RETURN_VALUE";
+ this->Arguments[ct_SOURCE] = "SOURCE";
+ this->Arguments[ct_BUILD] = "BUILD";
+ this->Arguments[ct_SUBMIT_INDEX] = "SUBMIT_INDEX";
+ this->Last = ct_LAST;
+ this->AppendXML = false;
+}
+
+bool cmCTestHandlerCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ // Allocate space for argument values.
+ this->Values.clear();
+ this->Values.resize(this->Last, 0);
+
+ // Process input arguments.
+ this->ArgumentDoing = ArgumentDoingNone;
+ for(unsigned int i=0; i < args.size(); ++i)
+ {
+ // Check this argument.
+ if(!this->CheckArgumentKeyword(args[i]) &&
+ !this->CheckArgumentValue(args[i]))
+ {
+ cmOStringStream e;
+ e << "called with unknown argument \"" << args[i] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Quit if an argument is invalid.
+ if(this->ArgumentDoing == ArgumentDoingError)
+ {
+ return false;
+ }
+ }
+
+ // Set the config type of this ctest to the current value of the
+ // CTEST_CONFIGURATION_TYPE script variable if it is defined.
+ // The current script value trumps the -C argument on the command
+ // line.
+ const char* ctestConfigType =
+ this->Makefile->GetDefinition("CTEST_CONFIGURATION_TYPE");
+ if (ctestConfigType)
+ {
+ this->CTest->SetConfigType(ctestConfigType);
+ }
+
+ if ( this->Values[ct_BUILD] )
+ {
+ this->CTest->SetCTestConfiguration("BuildDirectory",
+ cmSystemTools::CollapseFullPath(
+ this->Values[ct_BUILD]).c_str());
+ }
+ else
+ {
+ const char* bdir =
+ this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
+ if(bdir)
+ {
+ this->
+ CTest->SetCTestConfiguration("BuildDirectory",
+ cmSystemTools::CollapseFullPath(bdir).c_str());
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "CTEST_BINARY_DIRECTORY not set" << std::endl;);
+ }
+ }
+ if ( this->Values[ct_SOURCE] )
+ {
+ cmCTestLog(this->CTest, DEBUG,
+ "Set source directory to: " << this->Values[ct_SOURCE] << std::endl);
+ this->CTest->SetCTestConfiguration("SourceDirectory",
+ cmSystemTools::CollapseFullPath(
+ this->Values[ct_SOURCE]).c_str());
+ }
+ else
+ {
+ this->CTest->SetCTestConfiguration("SourceDirectory",
+ cmSystemTools::CollapseFullPath(
+ this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
+ }
+
+ cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
+ cmCTestGenericHandler* handler = this->InitializeHandler();
+ if ( !handler )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot instantiate test handler " << this->GetName()
+ << std::endl);
+ return false;
+ }
+
+ handler->SetAppendXML(this->AppendXML);
+
+ handler->PopulateCustomVectors(this->Makefile);
+ if ( this->Values[ct_SUBMIT_INDEX] )
+ {
+ if(!this->CTest->GetDropSiteCDash() && this->CTest->GetDartVersion() <= 1)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Dart before version 2.0 does not support collecting submissions."
+ << std::endl
+ << "Please upgrade the server to Dart 2 or higher, or do not use "
+ "SUBMIT_INDEX." << std::endl);
+ }
+ else
+ {
+ handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
+ }
+ }
+ std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(
+ this->CTest->GetCTestConfiguration("BuildDirectory").c_str());
+ int res = handler->ProcessHandler();
+ if ( this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE])
+ {
+ cmOStringStream str;
+ str << res;
+ this->Makefile->AddDefinition(
+ this->Values[ct_RETURN_VALUE], str.str().c_str());
+ }
+ cmSystemTools::ChangeDirectory(current_dir.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestHandlerCommand::CheckArgumentKeyword(std::string const& arg)
+{
+ // Look for non-value arguments common to all commands.
+ if(arg == "APPEND")
+ {
+ this->ArgumentDoing = ArgumentDoingNone;
+ this->AppendXML = true;
+ return true;
+ }
+
+ // Check for a keyword in our argument/value table.
+ for(unsigned int k=0; k < this->Arguments.size(); ++k)
+ {
+ if(this->Arguments[k] && arg == this->Arguments[k])
+ {
+ this->ArgumentDoing = ArgumentDoingKeyword;
+ this->ArgumentIndex = k;
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg)
+{
+ if(this->ArgumentDoing == ArgumentDoingKeyword)
+ {
+ this->ArgumentDoing = ArgumentDoingNone;
+ unsigned int k = this->ArgumentIndex;
+ if(this->Values[k])
+ {
+ cmOStringStream e;
+ e << "Called with more than one value for " << this->Arguments[k];
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->ArgumentDoing = ArgumentDoingError;
+ return true;
+ }
+ this->Values[k] = arg.c_str();
+ cmCTestLog(this->CTest, DEBUG, "Set " << this->Arguments[k]
+ << " to " << arg << "\n");
+ return true;
+ }
+ return false;
+}
diff --git a/Source/CTest/cmCTestHandlerCommand.h b/Source/CTest/cmCTestHandlerCommand.h
new file mode 100644
index 0000000000..8ef2b8028a
--- /dev/null
+++ b/Source/CTest/cmCTestHandlerCommand.h
@@ -0,0 +1,77 @@
+/*============================================================================
+ 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 cmCTestHandlerCommand_h
+#define cmCTestHandlerCommand_h
+
+#include "cmCTestCommand.h"
+
+class cmCTestGenericHandler;
+
+/** \class cmCTestHandler
+ * \brief Run a ctest script
+ *
+ * cmCTestHandlerCommand defineds the command to test the project.
+ */
+class cmCTestHandlerCommand : public cmCTestCommand
+{
+public:
+ cmCTestHandlerCommand();
+
+ /**
+ * 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);
+
+ cmTypeMacro(cmCTestHandlerCommand, cmCTestCommand);
+
+ enum
+ {
+ ct_NONE,
+ ct_RETURN_VALUE,
+ ct_BUILD,
+ ct_SOURCE,
+ ct_SUBMIT_INDEX,
+ ct_LAST
+ };
+
+protected:
+ virtual cmCTestGenericHandler* InitializeHandler() = 0;
+
+ // Command argument handling.
+ virtual bool CheckArgumentKeyword(std::string const& arg);
+ virtual bool CheckArgumentValue(std::string const& arg);
+ enum
+ {
+ ArgumentDoingNone,
+ ArgumentDoingError,
+ ArgumentDoingKeyword,
+ ArgumentDoingLast1
+ };
+ int ArgumentDoing;
+ unsigned int ArgumentIndex;
+
+ bool AppendXML;
+
+ std::string ReturnVariable;
+ std::vector<const char*> Arguments;
+ std::vector<const char*> Values;
+ size_t Last;
+};
+
+#define CTEST_COMMAND_APPEND_OPTION_DOCS \
+ "The APPEND option marks results for append to those previously " \
+ "submitted to a dashboard server since the last ctest_start. " \
+ "Append semantics are defined by the dashboard server in use."
+
+#endif
diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx
new file mode 100644
index 0000000000..10a5199ebb
--- /dev/null
+++ b/Source/CTest/cmCTestLaunch.cxx
@@ -0,0 +1,752 @@
+/*============================================================================
+ 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 "cmCTestLaunch.h"
+
+#include "cmGeneratedFileStream.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+#include "cmake.h"
+
+#include <cmsys/MD5.h>
+#include <cmsys/Process.h>
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/FStream.hxx>
+
+//----------------------------------------------------------------------------
+cmCTestLaunch::cmCTestLaunch(int argc, const char* const* argv)
+{
+ this->Passthru = true;
+ this->Process = 0;
+ this->ExitCode = 1;
+ this->CWD = cmSystemTools::GetCurrentWorkingDirectory();
+
+ if(!this->ParseArguments(argc, argv))
+ {
+ return;
+ }
+
+ this->ComputeFileNames();
+
+ this->ScrapeRulesLoaded = false;
+ this->HaveOut = false;
+ this->HaveErr = false;
+ this->Process = cmsysProcess_New();
+}
+
+//----------------------------------------------------------------------------
+cmCTestLaunch::~cmCTestLaunch()
+{
+ cmsysProcess_Delete(this->Process);
+ if(!this->Passthru)
+ {
+ cmSystemTools::RemoveFile(this->LogOut.c_str());
+ cmSystemTools::RemoveFile(this->LogErr.c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestLaunch::ParseArguments(int argc, const char* const* argv)
+{
+ // Launcher options occur first and are separated from the real
+ // command line by a '--' option.
+ enum Doing { DoingNone,
+ DoingOutput,
+ DoingSource,
+ DoingLanguage,
+ DoingTargetName,
+ DoingTargetType,
+ DoingBuildDir,
+ DoingCount,
+ DoingFilterPrefix };
+ Doing doing = DoingNone;
+ int arg0 = 0;
+ for(int i=1; !arg0 && i < argc; ++i)
+ {
+ const char* arg = argv[i];
+ if(strcmp(arg, "--") == 0)
+ {
+ arg0 = i+1;
+ }
+ else if(strcmp(arg, "--output") == 0)
+ {
+ doing = DoingOutput;
+ }
+ else if(strcmp(arg, "--source") == 0)
+ {
+ doing = DoingSource;
+ }
+ else if(strcmp(arg, "--language") == 0)
+ {
+ doing = DoingLanguage;
+ }
+ else if(strcmp(arg, "--target-name") == 0)
+ {
+ doing = DoingTargetName;
+ }
+ else if(strcmp(arg, "--target-type") == 0)
+ {
+ doing = DoingTargetType;
+ }
+ else if(strcmp(arg, "--build-dir") == 0)
+ {
+ doing = DoingBuildDir;
+ }
+ else if(strcmp(arg, "--filter-prefix") == 0)
+ {
+ doing = DoingFilterPrefix;
+ }
+ else if(doing == DoingOutput)
+ {
+ this->OptionOutput = arg;
+ doing = DoingNone;
+ }
+ else if(doing == DoingSource)
+ {
+ this->OptionSource = arg;
+ doing = DoingNone;
+ }
+ else if(doing == DoingLanguage)
+ {
+ this->OptionLanguage = arg;
+ if(this->OptionLanguage == "CXX")
+ {
+ this->OptionLanguage = "C++";
+ }
+ doing = DoingNone;
+ }
+ else if(doing == DoingTargetName)
+ {
+ this->OptionTargetName = arg;
+ doing = DoingNone;
+ }
+ else if(doing == DoingTargetType)
+ {
+ this->OptionTargetType = arg;
+ doing = DoingNone;
+ }
+ else if(doing == DoingBuildDir)
+ {
+ this->OptionBuildDir = arg;
+ doing = DoingNone;
+ }
+ else if(doing == DoingFilterPrefix)
+ {
+ this->OptionFilterPrefix = arg;
+ doing = DoingNone;
+ }
+ }
+
+ // Extract the real command line.
+ if(arg0)
+ {
+ this->RealArgC = argc - arg0;
+ this->RealArgV = argv + arg0;
+ for(int i=0; i < this->RealArgC; ++i)
+ {
+ this->HandleRealArg(this->RealArgV[i]);
+ }
+ return true;
+ }
+ else
+ {
+ this->RealArgC = 0;
+ this->RealArgV = 0;
+ std::cerr << "No launch/command separator ('--') found!\n";
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::HandleRealArg(const char* arg)
+{
+#ifdef _WIN32
+ // Expand response file arguments.
+ if(arg[0] == '@' && cmSystemTools::FileExists(arg+1))
+ {
+ cmsys::ifstream fin(arg+1);
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ cmSystemTools::ParseWindowsCommandLine(line.c_str(), this->RealArgs);
+ }
+ return;
+ }
+#endif
+ this->RealArgs.push_back(arg);
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::ComputeFileNames()
+{
+ // We just passthru the behavior of the real command unless the
+ // CTEST_LAUNCH_LOGS environment variable is set.
+ const char* d = getenv("CTEST_LAUNCH_LOGS");
+ if(!(d && *d))
+ {
+ return;
+ }
+ this->Passthru = false;
+
+ // The environment variable specifies the directory into which we
+ // generate build logs.
+ this->LogDir = d;
+ cmSystemTools::ConvertToUnixSlashes(this->LogDir);
+ this->LogDir += "/";
+
+ // We hash the input command working dir and command line to obtain
+ // a repeatable and (probably) unique name for log files.
+ char hash[32];
+ cmsysMD5* md5 = cmsysMD5_New();
+ cmsysMD5_Initialize(md5);
+ cmsysMD5_Append(md5, (unsigned char const*)(this->CWD.c_str()), -1);
+ for(std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
+ ai != this->RealArgs.end(); ++ai)
+ {
+ cmsysMD5_Append(md5, (unsigned char const*)ai->c_str(), -1);
+ }
+ cmsysMD5_FinalizeHex(md5, hash);
+ cmsysMD5_Delete(md5);
+ this->LogHash.assign(hash, 32);
+
+ // We store stdout and stderr in temporary log files.
+ this->LogOut = this->LogDir;
+ this->LogOut += "launch-";
+ this->LogOut += this->LogHash;
+ this->LogOut += "-out.txt";
+ this->LogErr = this->LogDir;
+ this->LogErr += "launch-";
+ this->LogErr += this->LogHash;
+ this->LogErr += "-err.txt";
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::RunChild()
+{
+ // Ignore noopt make rules
+ if(this->RealArgs.empty() || this->RealArgs[0] == ":")
+ {
+ this->ExitCode = 0;
+ return;
+ }
+
+ // Prepare to run the real command.
+ cmsysProcess* cp = this->Process;
+ cmsysProcess_SetCommand(cp, this->RealArgV);
+
+ cmsys::ofstream fout;
+ cmsys::ofstream ferr;
+ if(this->Passthru)
+ {
+ // In passthru mode we just share the output pipes.
+ cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
+ cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
+ }
+ else
+ {
+ // In full mode we record the child output pipes to log files.
+ fout.open(this->LogOut.c_str(),
+ std::ios::out | std::ios::binary);
+ ferr.open(this->LogErr.c_str(),
+ std::ios::out | std::ios::binary);
+ }
+
+ // Run the real command.
+ cmsysProcess_Execute(cp);
+
+ // Record child stdout and stderr if necessary.
+ if(!this->Passthru)
+ {
+ char* data = 0;
+ int length = 0;
+ while(int p = cmsysProcess_WaitForData(cp, &data, &length, 0))
+ {
+ if(p == cmsysProcess_Pipe_STDOUT)
+ {
+ fout.write(data, length);
+ std::cout.write(data, length);
+ this->HaveOut = true;
+ }
+ else if(p == cmsysProcess_Pipe_STDERR)
+ {
+ ferr.write(data, length);
+ std::cerr.write(data, length);
+ this->HaveErr = true;
+ }
+ }
+ }
+
+ // Wait for the real command to finish.
+ cmsysProcess_WaitForExit(cp, 0);
+ this->ExitCode = cmsysProcess_GetExitValue(cp);
+}
+
+//----------------------------------------------------------------------------
+int cmCTestLaunch::Run()
+{
+ if(!this->Process)
+ {
+ std::cerr << "Could not allocate cmsysProcess instance!\n";
+ return -1;
+ }
+
+ this->RunChild();
+
+ if(this->CheckResults())
+ {
+ return this->ExitCode;
+ }
+
+ this->LoadConfig();
+ this->WriteXML();
+
+ return this->ExitCode;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::LoadLabels()
+{
+ if(this->OptionBuildDir.empty() || this->OptionTargetName.empty())
+ {
+ return;
+ }
+
+ // Labels are listed in per-target files.
+ std::string fname = this->OptionBuildDir;
+ fname += cmake::GetCMakeFilesDirectory();
+ fname += "/";
+ fname += this->OptionTargetName;
+ fname += ".dir/Labels.txt";
+
+ // We are interested in per-target labels for this source file.
+ std::string source = this->OptionSource;
+ cmSystemTools::ConvertToUnixSlashes(source);
+
+ // Load the labels file.
+ cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
+ if(!fin) { return; }
+ bool inTarget = true;
+ bool inSource = false;
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ if(line.empty() || line[0] == '#')
+ {
+ // Ignore blank and comment lines.
+ continue;
+ }
+ else if(line[0] == ' ')
+ {
+ // Label lines appear indented by one space.
+ if(inTarget || inSource)
+ {
+ this->Labels.insert(line.c_str()+1);
+ }
+ }
+ else if(!this->OptionSource.empty() && !inSource)
+ {
+ // Non-indented lines specify a source file name. The first one
+ // is the end of the target-wide labels. Use labels following a
+ // matching source.
+ inTarget = false;
+ inSource = this->SourceMatches(line, source);
+ }
+ else
+ {
+ return;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestLaunch::SourceMatches(std::string const& lhs,
+ std::string const& rhs)
+{
+ // TODO: Case sensitivity, UseRelativePaths, etc. Note that both
+ // paths in the comparison get generated by CMake. This is done for
+ // every source in the target, so it should be efficient (cannot use
+ // cmSystemTools::IsSameFile).
+ return lhs == rhs;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestLaunch::IsError() const
+{
+ return this->ExitCode != 0;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::WriteXML()
+{
+ // Name the xml file.
+ std::string logXML = this->LogDir;
+ logXML += this->IsError()? "error-" : "warning-";
+ logXML += this->LogHash;
+ logXML += ".xml";
+
+ // Use cmGeneratedFileStream to atomically create the report file.
+ cmGeneratedFileStream fxml(logXML.c_str());
+ fxml << "\t<Failure type=\""
+ << (this->IsError()? "Error" : "Warning") << "\">\n";
+ this->WriteXMLAction(fxml);
+ this->WriteXMLCommand(fxml);
+ this->WriteXMLResult(fxml);
+ this->WriteXMLLabels(fxml);
+ fxml << "\t</Failure>\n";
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::WriteXMLAction(std::ostream& fxml)
+{
+ fxml << "\t\t<!-- Meta-information about the build action -->\n";
+ fxml << "\t\t<Action>\n";
+
+ // TargetName
+ if(!this->OptionTargetName.empty())
+ {
+ fxml << "\t\t\t<TargetName>"
+ << cmXMLSafe(this->OptionTargetName)
+ << "</TargetName>\n";
+ }
+
+ // Language
+ if(!this->OptionLanguage.empty())
+ {
+ fxml << "\t\t\t<Language>"
+ << cmXMLSafe(this->OptionLanguage)
+ << "</Language>\n";
+ }
+
+ // SourceFile
+ if(!this->OptionSource.empty())
+ {
+ std::string source = this->OptionSource;
+ cmSystemTools::ConvertToUnixSlashes(source);
+
+ // If file is in source tree use its relative location.
+ if(cmSystemTools::FileIsFullPath(this->SourceDir.c_str()) &&
+ cmSystemTools::FileIsFullPath(source.c_str()) &&
+ cmSystemTools::IsSubDirectory(source.c_str(),
+ this->SourceDir.c_str()))
+ {
+ source = cmSystemTools::RelativePath(this->SourceDir.c_str(),
+ source.c_str());
+ }
+
+ fxml << "\t\t\t<SourceFile>"
+ << cmXMLSafe(source)
+ << "</SourceFile>\n";
+ }
+
+ // OutputFile
+ if(!this->OptionOutput.empty())
+ {
+ fxml << "\t\t\t<OutputFile>"
+ << cmXMLSafe(this->OptionOutput)
+ << "</OutputFile>\n";
+ }
+
+ // OutputType
+ const char* outputType = 0;
+ if(!this->OptionTargetType.empty())
+ {
+ if(this->OptionTargetType == "EXECUTABLE")
+ {
+ outputType = "executable";
+ }
+ else if(this->OptionTargetType == "SHARED_LIBRARY")
+ {
+ outputType = "shared library";
+ }
+ else if(this->OptionTargetType == "MODULE_LIBRARY")
+ {
+ outputType = "module library";
+ }
+ else if(this->OptionTargetType == "STATIC_LIBRARY")
+ {
+ outputType = "static library";
+ }
+ }
+ else if(!this->OptionSource.empty())
+ {
+ outputType = "object file";
+ }
+ if(outputType)
+ {
+ fxml << "\t\t\t<OutputType>"
+ << cmXMLSafe(outputType)
+ << "</OutputType>\n";
+ }
+
+ fxml << "\t\t</Action>\n";
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::WriteXMLCommand(std::ostream& fxml)
+{
+ fxml << "\n";
+ fxml << "\t\t<!-- Details of command -->\n";
+ fxml << "\t\t<Command>\n";
+ if(!this->CWD.empty())
+ {
+ fxml << "\t\t\t<WorkingDirectory>"
+ << cmXMLSafe(this->CWD)
+ << "</WorkingDirectory>\n";
+ }
+ for(std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
+ ai != this->RealArgs.end(); ++ai)
+ {
+ fxml << "\t\t\t<Argument>"
+ << cmXMLSafe(ai->c_str())
+ << "</Argument>\n";
+ }
+ fxml << "\t\t</Command>\n";
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::WriteXMLResult(std::ostream& fxml)
+{
+ fxml << "\n";
+ fxml << "\t\t<!-- Result of command -->\n";
+ fxml << "\t\t<Result>\n";
+
+ // StdOut
+ fxml << "\t\t\t<StdOut>";
+ this->DumpFileToXML(fxml, this->LogOut);
+ fxml << "</StdOut>\n";
+
+ // StdErr
+ fxml << "\t\t\t<StdErr>";
+ this->DumpFileToXML(fxml, this->LogErr);
+ fxml << "</StdErr>\n";
+
+ // ExitCondition
+ fxml << "\t\t\t<ExitCondition>";
+ cmsysProcess* cp = this->Process;
+ switch (cmsysProcess_GetState(cp))
+ {
+ case cmsysProcess_State_Starting:
+ fxml << "No process has been executed"; break;
+ case cmsysProcess_State_Executing:
+ fxml << "The process is still executing"; break;
+ case cmsysProcess_State_Disowned:
+ fxml << "Disowned"; break;
+ case cmsysProcess_State_Killed:
+ fxml << "Killed by parent"; break;
+
+ case cmsysProcess_State_Expired:
+ fxml << "Killed when timeout expired"; break;
+ case cmsysProcess_State_Exited:
+ fxml << this->ExitCode; break;
+ case cmsysProcess_State_Exception:
+ fxml << "Terminated abnormally: "
+ << cmXMLSafe(cmsysProcess_GetExceptionString(cp)); break;
+ case cmsysProcess_State_Error:
+ fxml << "Error administrating child process: "
+ << cmXMLSafe(cmsysProcess_GetErrorString(cp)); break;
+ };
+ fxml << "</ExitCondition>\n";
+
+ fxml << "\t\t</Result>\n";
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::WriteXMLLabels(std::ostream& fxml)
+{
+ this->LoadLabels();
+ if(!this->Labels.empty())
+ {
+ fxml << "\n";
+ fxml << "\t\t<!-- Interested parties -->\n";
+ fxml << "\t\t<Labels>\n";
+ for(std::set<std::string>::const_iterator li = this->Labels.begin();
+ li != this->Labels.end(); ++li)
+ {
+ fxml << "\t\t\t<Label>" << cmXMLSafe(*li) << "</Label>\n";
+ }
+ fxml << "\t\t</Labels>\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::DumpFileToXML(std::ostream& fxml,
+ std::string const& fname)
+{
+ cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
+
+ std::string line;
+ const char* sep = "";
+
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ if(MatchesFilterPrefix(line))
+ {
+ continue;
+ }
+
+ fxml << sep << cmXMLSafe(line).Quotes(false);
+ sep = "\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestLaunch::CheckResults()
+{
+ // Skip XML in passthru mode.
+ if(this->Passthru)
+ {
+ return true;
+ }
+
+ // We always report failure for error conditions.
+ if(this->IsError())
+ {
+ return false;
+ }
+
+ // Scrape the output logs to look for warnings.
+ if((this->HaveErr && this->ScrapeLog(this->LogErr)) ||
+ (this->HaveOut && this->ScrapeLog(this->LogOut)))
+ {
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestLaunch::LoadScrapeRules()
+{
+ if(this->ScrapeRulesLoaded)
+ {
+ return;
+ }
+ this->ScrapeRulesLoaded = true;
+
+ // Common compiler warning formats. These are much simpler than the
+ // full log-scraping expressions because we do not need to extract
+ // file and line information.
+ this->RegexWarning.push_back("(^|[ :])[Ww][Aa][Rr][Nn][Ii][Nn][Gg]");
+ this->RegexWarning.push_back("(^|[ :])[Rr][Ee][Mm][Aa][Rr][Kk]");
+ this->RegexWarning.push_back("(^|[ :])[Nn][Oo][Tt][Ee]");
+
+ // Load custom match rules given to us by CTest.
+ this->LoadScrapeRules("Warning", this->RegexWarning);
+ this->LoadScrapeRules("WarningSuppress", this->RegexWarningSuppress);
+}
+
+//----------------------------------------------------------------------------
+void
+cmCTestLaunch
+::LoadScrapeRules(const char* purpose,
+ std::vector<cmsys::RegularExpression>& regexps)
+{
+ std::string fname = this->LogDir;
+ fname += "Custom";
+ fname += purpose;
+ fname += ".txt";
+ cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
+ std::string line;
+ cmsys::RegularExpression rex;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ if(rex.compile(line.c_str()))
+ {
+ regexps.push_back(rex);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestLaunch::ScrapeLog(std::string const& fname)
+{
+ this->LoadScrapeRules();
+
+ // Look for log file lines matching warning expressions but not
+ // suppression expressions.
+ cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ if(MatchesFilterPrefix(line))
+ {
+ continue;
+ }
+
+ if(this->Match(line, this->RegexWarning) &&
+ !this->Match(line, this->RegexWarningSuppress))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestLaunch::Match(std::string const& line,
+ std::vector<cmsys::RegularExpression>& regexps)
+{
+ for(std::vector<cmsys::RegularExpression>::iterator ri = regexps.begin();
+ ri != regexps.end(); ++ri)
+ {
+ if(ri->find(line.c_str()))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestLaunch::MatchesFilterPrefix(std::string const& line) const
+{
+ if(this->OptionFilterPrefix.size() && cmSystemTools::StringStartsWith(
+ line.c_str(), this->OptionFilterPrefix.c_str()))
+ {
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+int cmCTestLaunch::Main(int argc, const char* const argv[])
+{
+ if(argc == 2)
+ {
+ std::cerr << "ctest --launch: this mode is for internal CTest use only"
+ << std::endl;
+ return 1;
+ }
+ cmCTestLaunch self(argc, argv);
+ return self.Run();
+}
+
+//----------------------------------------------------------------------------
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include <cmsys/auto_ptr.hxx>
+void cmCTestLaunch::LoadConfig()
+{
+ cmake cm;
+ cmGlobalGenerator gg;
+ gg.SetCMakeInstance(&cm);
+ cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
+ cmMakefile* mf = lg->GetMakefile();
+ std::string fname = this->LogDir;
+ fname += "CTestLaunchConfig.cmake";
+ if(cmSystemTools::FileExists(fname.c_str()) &&
+ mf->ReadListFile(0, fname.c_str()))
+ {
+ this->SourceDir = mf->GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
+ cmSystemTools::ConvertToUnixSlashes(this->SourceDir);
+ }
+}
diff --git a/Source/CTest/cmCTestLaunch.h b/Source/CTest/cmCTestLaunch.h
new file mode 100644
index 0000000000..bc90d28cf6
--- /dev/null
+++ b/Source/CTest/cmCTestLaunch.h
@@ -0,0 +1,106 @@
+/*============================================================================
+ 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 cmCTestLaunch_h
+#define cmCTestLaunch_h
+
+#include "cmStandardIncludes.h"
+#include <cmsys/RegularExpression.hxx>
+
+/** \class cmCTestLaunch
+ * \brief Launcher for make rules to report results for ctest
+ *
+ * This implements the 'ctest --launch' tool.
+ */
+class cmCTestLaunch
+{
+public:
+ /** Entry point from ctest executable main(). */
+ static int Main(int argc, const char* const argv[]);
+private:
+ // Initialize the launcher from its command line.
+ cmCTestLaunch(int argc, const char* const* argv);
+ ~cmCTestLaunch();
+
+ // Run the real command.
+ int Run();
+ void RunChild();
+
+ // Methods to check the result of the real command.
+ bool IsError() const;
+ bool CheckResults();
+
+ // Launcher options specified before the real command.
+ std::string OptionOutput;
+ std::string OptionSource;
+ std::string OptionLanguage;
+ std::string OptionTargetName;
+ std::string OptionTargetType;
+ std::string OptionBuildDir;
+ std::string OptionFilterPrefix;
+ bool ParseArguments(int argc, const char* const* argv);
+
+ // The real command line appearing after launcher arguments.
+ int RealArgC;
+ const char* const* RealArgV;
+ std::string CWD;
+
+ // The real command line after response file expansion.
+ std::vector<std::string> RealArgs;
+ void HandleRealArg(const char* arg);
+
+ // A hash of the real command line is unique and unlikely to collide.
+ std::string LogHash;
+ void ComputeFileNames();
+
+ bool Passthru;
+ struct cmsysProcess_s* Process;
+ int ExitCode;
+
+ // Temporary log files for stdout and stderr of real command.
+ std::string LogDir;
+ std::string LogOut;
+ std::string LogErr;
+ bool HaveOut;
+ bool HaveErr;
+
+ // Labels associated with the build rule.
+ std::set<std::string> Labels;
+ void LoadLabels();
+ bool SourceMatches(std::string const& lhs,
+ std::string const& rhs);
+
+ // Regular expressions to match warnings and their exceptions.
+ bool ScrapeRulesLoaded;
+ std::vector<cmsys::RegularExpression> RegexWarning;
+ std::vector<cmsys::RegularExpression> RegexWarningSuppress;
+ void LoadScrapeRules();
+ void LoadScrapeRules(const char* purpose,
+ std::vector<cmsys::RegularExpression>& regexps);
+ bool ScrapeLog(std::string const& fname);
+ bool Match(std::string const& line,
+ std::vector<cmsys::RegularExpression>& regexps);
+ bool MatchesFilterPrefix(std::string const& line) const;
+
+ // Methods to generate the xml fragment.
+ void WriteXML();
+ void WriteXMLAction(std::ostream& fxml);
+ void WriteXMLCommand(std::ostream& fxml);
+ void WriteXMLResult(std::ostream& fxml);
+ void WriteXMLLabels(std::ostream& fxml);
+ void DumpFileToXML(std::ostream& fxml, std::string const& fname);
+
+ // Configuration
+ void LoadConfig();
+ std::string SourceDir;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestMemCheckCommand.cxx b/Source/CTest/cmCTestMemCheckCommand.cxx
new file mode 100644
index 0000000000..f1440668b3
--- /dev/null
+++ b/Source/CTest/cmCTestMemCheckCommand.cxx
@@ -0,0 +1,36 @@
+/*============================================================================
+ 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 "cmCTestMemCheckCommand.h"
+
+#include "cmCTest.h"
+#include "cmCTestGenericHandler.h"
+
+
+cmCTestGenericHandler* cmCTestMemCheckCommand::InitializeActualHandler()
+{
+ cmCTestGenericHandler* handler
+ = this->CTest->GetInitializedHandler("memcheck");
+
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "MemoryCheckType", "CTEST_MEMORYCHECK_TYPE");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "MemoryCheckSanitizerOptions", "CTEST_MEMORYCHECK_SANITIZER_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "MemoryCheckCommand", "CTEST_MEMORYCHECK_COMMAND");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "MemoryCheckCommandOptions", "CTEST_MEMORYCHECK_COMMAND_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "MemoryCheckSuppressionFile", "CTEST_MEMORYCHECK_SUPPRESSIONS_FILE");
+
+ return handler;
+}
+
diff --git a/Source/CTest/cmCTestMemCheckCommand.h b/Source/CTest/cmCTestMemCheckCommand.h
new file mode 100644
index 0000000000..e239d46421
--- /dev/null
+++ b/Source/CTest/cmCTestMemCheckCommand.h
@@ -0,0 +1,54 @@
+/*============================================================================
+ 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 cmCTestMemCheckCommand_h
+#define cmCTestMemCheckCommand_h
+
+#include "cmCTestTestCommand.h"
+
+class cmCTestGenericHandler;
+
+/** \class cmCTestMemCheck
+ * \brief Run a ctest script
+ *
+ * cmCTestMemCheckCommand defineds the command to test the project.
+ */
+class cmCTestMemCheckCommand : public cmCTestTestCommand
+{
+public:
+
+ cmCTestMemCheckCommand() {}
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestMemCheckCommand* ni = new cmCTestMemCheckCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_memcheck";}
+
+ cmTypeMacro(cmCTestMemCheckCommand, cmCTestTestCommand);
+
+protected:
+ cmCTestGenericHandler* InitializeActualHandler();
+};
+
+
+#endif
+
diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx
new file mode 100644
index 0000000000..4835010e1a
--- /dev/null
+++ b/Source/CTest/cmCTestMemCheckHandler.cxx
@@ -0,0 +1,1300 @@
+/*============================================================================
+ 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 "cmCTestMemCheckHandler.h"
+#include "cmXMLParser.h"
+#include "cmCTest.h"
+#include "cmake.h"
+#include "cmGeneratedFileStream.h"
+#include <cmsys/Process.h>
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Base64.h>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+#include "cmMakefile.h"
+#include "cmXMLSafe.h"
+
+#include <stdlib.h>
+#include <math.h>
+#include <float.h>
+
+struct CatToErrorType
+{
+ const char* ErrorCategory;
+ int ErrorCode;
+};
+
+
+static CatToErrorType cmCTestMemCheckBoundsChecker[] = {
+ // Error tags
+ {"Write Overrun", cmCTestMemCheckHandler::ABW},
+ {"Read Overrun", cmCTestMemCheckHandler::ABR},
+ {"Memory Overrun", cmCTestMemCheckHandler::ABW},
+ {"Allocation Conflict", cmCTestMemCheckHandler::FMM},
+ {"Bad Pointer Use", cmCTestMemCheckHandler::FMW},
+ {"Dangling Pointer", cmCTestMemCheckHandler::FMR},
+ {0,0}
+};
+
+static void xmlReportError(int line, const char* msg, void* data)
+{
+ cmCTest* ctest = (cmCTest*)data;
+ cmCTestLog(ctest, ERROR_MESSAGE,
+ "Error parsing XML in stream at line "
+ << line << ": " << msg << std::endl);
+}
+
+// parse the xml file containing the results of last BoundsChecker run
+class cmBoundsCheckerParser : public cmXMLParser
+{
+public:
+ cmBoundsCheckerParser(cmCTest* c)
+ {
+ this->CTest = c;
+ this->SetErrorCallback(xmlReportError, (void*)c);
+ }
+ void StartElement(const std::string& name, const char** atts)
+ {
+ if(name == "MemoryLeak" ||
+ name == "ResourceLeak")
+ {
+ this->Errors.push_back(cmCTestMemCheckHandler::MLK);
+ }
+ else if(name == "Error" ||
+ name == "Dangling Pointer")
+ {
+ this->ParseError(atts);
+ }
+ // Create the log
+ cmOStringStream ostr;
+ ostr << name << ":\n";
+ int i = 0;
+ for(; atts[i] != 0; i+=2)
+ {
+ ostr << " " << cmXMLSafe(atts[i])
+ << " - " << cmXMLSafe(atts[i+1]) << "\n";
+ }
+ ostr << "\n";
+ this->Log += ostr.str();
+ }
+ void EndElement(const std::string& )
+ {
+ }
+
+ const char* GetAttribute(const char* name, const char** atts)
+ {
+ int i = 0;
+ for(; atts[i] != 0; ++i)
+ {
+ if(strcmp(name, atts[i]) == 0)
+ {
+ return atts[i+1];
+ }
+ }
+ return 0;
+ }
+ void ParseError(const char** atts)
+ {
+ CatToErrorType* ptr = cmCTestMemCheckBoundsChecker;
+ const char* cat = this->GetAttribute("ErrorCategory", atts);
+ if(!cat)
+ {
+ this->Errors.push_back(cmCTestMemCheckHandler::ABW); // do not know
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "No Category found in Bounds checker XML\n" );
+ return;
+ }
+ while(ptr->ErrorCategory && cat)
+ {
+ if(strcmp(ptr->ErrorCategory, cat) == 0)
+ {
+ this->Errors.push_back(ptr->ErrorCode);
+ return; // found it we are done
+ }
+ ptr++;
+ }
+ if(ptr->ErrorCategory)
+ {
+ this->Errors.push_back(cmCTestMemCheckHandler::ABW); // do not know
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Found unknown Bounds Checker error "
+ << ptr->ErrorCategory << std::endl);
+ }
+ }
+ cmCTest* CTest;
+ std::vector<int> Errors;
+ std::string Log;
+};
+
+#define BOUNDS_CHECKER_MARKER \
+"******######*****Begin BOUNDS CHECKER XML******######******"
+
+
+
+//----------------------------------------------------------------------
+cmCTestMemCheckHandler::cmCTestMemCheckHandler()
+{
+ this->MemCheck = true;
+ this->CustomMaximumPassedTestOutputSize = 0;
+ this->CustomMaximumFailedTestOutputSize = 0;
+ this->LogWithPID = false;
+}
+
+//----------------------------------------------------------------------
+void cmCTestMemCheckHandler::Initialize()
+{
+ this->Superclass::Initialize();
+ this->LogWithPID = false;
+ this->CustomMaximumPassedTestOutputSize = 0;
+ this->CustomMaximumFailedTestOutputSize = 0;
+ this->MemoryTester = "";
+ this->MemoryTesterDynamicOptions.clear();
+ this->MemoryTesterOptions.clear();
+ this->MemoryTesterStyle = UNKNOWN;
+ this->MemoryTesterOutputFile = "";
+}
+
+//----------------------------------------------------------------------
+int cmCTestMemCheckHandler::PreProcessHandler()
+{
+ if ( !this->InitializeMemoryChecking() )
+ {
+ return 0;
+ }
+
+ if ( !this->ExecuteCommands(this->CustomPreMemCheck) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Problem executing pre-memcheck command(s)." << std::endl);
+ return 0;
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCTestMemCheckHandler::PostProcessHandler()
+{
+ if ( !this->ExecuteCommands(this->CustomPostMemCheck) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Problem executing post-memcheck command(s)." << std::endl);
+ return 0;
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+void cmCTestMemCheckHandler::GenerateTestCommand(
+ std::vector<std::string>& args, int test)
+{
+ std::vector<std::string>::size_type pp;
+ std::string index;
+ cmOStringStream stream;
+ std::string memcheckcommand
+ = cmSystemTools::ConvertToOutputPath(this->MemoryTester.c_str());
+ stream << test;
+ index = stream.str();
+ for ( pp = 0; pp < this->MemoryTesterDynamicOptions.size(); pp ++ )
+ {
+ std::string arg = this->MemoryTesterDynamicOptions[pp];
+ std::string::size_type pos = arg.find("??");
+ if (pos != std::string::npos)
+ {
+ arg.replace(pos, 2, index);
+ }
+ args.push_back(arg);
+ memcheckcommand += " \"";
+ memcheckcommand += arg;
+ memcheckcommand += "\"";
+ }
+ // Create a copy of the memory tester environment variable.
+ // This is used for memory testing programs that pass options
+ // via environment varaibles.
+ std::string memTesterEnvironmentVariable =
+ this->MemoryTesterEnvironmentVariable;
+ for ( pp = 0; pp < this->MemoryTesterOptions.size(); pp ++ )
+ {
+ if(memTesterEnvironmentVariable.size())
+ {
+ // If we are using env to pass options, append all the options to
+ // this string with space separation.
+ memTesterEnvironmentVariable += " " + this->MemoryTesterOptions[pp];
+ }
+ // for regular options just add them to args and memcheckcommand
+ // which is just used for display
+ else
+ {
+ args.push_back(this->MemoryTesterOptions[pp]);
+ memcheckcommand += " \"";
+ memcheckcommand += this->MemoryTesterOptions[pp];
+ memcheckcommand += "\"";
+ }
+ }
+ // if this is an env option type, then add the env string as a single
+ // argument.
+ if(memTesterEnvironmentVariable.size())
+ {
+ std::string::size_type pos = memTesterEnvironmentVariable.find("??");
+ if (pos != std::string::npos)
+ {
+ memTesterEnvironmentVariable.replace(pos, 2, index);
+ }
+ memcheckcommand += " " + memTesterEnvironmentVariable;
+ args.push_back(memTesterEnvironmentVariable);
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Memory check command: "
+ << memcheckcommand << std::endl);
+}
+
+//----------------------------------------------------------------------
+void cmCTestMemCheckHandler::InitializeResultsVectors()
+{
+ // fill these members
+// cmsys::vector<std::string> ResultStrings;
+// cmsys::vector<std::string> ResultStringsLong;
+// cmsys::vector<int> GlobalResults;
+ this->ResultStringsLong.clear();
+ this->ResultStrings.clear();
+ this->GlobalResults.clear();
+ // If we are working with style checkers that dynamically fill
+ // the results strings then return.
+ if(this->MemoryTesterStyle > cmCTestMemCheckHandler::BOUNDS_CHECKER)
+ {
+ return;
+ }
+
+ // define the standard set of errors
+ //----------------------------------------------------------------------
+ static const char* cmCTestMemCheckResultStrings[] = {
+ "ABR",
+ "ABW",
+ "ABWL",
+ "COR",
+ "EXU",
+ "FFM",
+ "FIM",
+ "FMM",
+ "FMR",
+ "FMW",
+ "FUM",
+ "IPR",
+ "IPW",
+ "MAF",
+ "MLK",
+ "MPK",
+ "NPR",
+ "ODS",
+ "PAR",
+ "PLK",
+ "UMC",
+ "UMR",
+ 0
+ };
+//----------------------------------------------------------------------
+ static const char* cmCTestMemCheckResultLongStrings[] = {
+ "Threading Problem",
+ "ABW",
+ "ABWL",
+ "COR",
+ "EXU",
+ "FFM",
+ "FIM",
+ "Mismatched deallocation",
+ "FMR",
+ "FMW",
+ "FUM",
+ "IPR",
+ "IPW",
+ "MAF",
+ "Memory Leak",
+ "Potential Memory Leak",
+ "NPR",
+ "ODS",
+ "Invalid syscall param",
+ "PLK",
+ "Uninitialized Memory Conditional",
+ "Uninitialized Memory Read",
+ 0
+ };
+ this->GlobalResults.clear();
+ for(int i =0; cmCTestMemCheckResultStrings[i] != 0; ++i)
+ {
+ this->ResultStrings.push_back(cmCTestMemCheckResultStrings[i]);
+ this->ResultStringsLong.push_back(cmCTestMemCheckResultLongStrings[i]);
+ this->GlobalResults.push_back(0);
+ }
+}
+
+//----------------------------------------------------------------------
+void cmCTestMemCheckHandler::PopulateCustomVectors(cmMakefile *mf)
+{
+ this->cmCTestTestHandler::PopulateCustomVectors(mf);
+ this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_MEMCHECK",
+ this->CustomPreMemCheck);
+ this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_MEMCHECK",
+ this->CustomPostMemCheck);
+
+ this->CTest->PopulateCustomVector(mf,
+ "CTEST_CUSTOM_MEMCHECK_IGNORE",
+ this->CustomTestsIgnore);
+ std::string cmake = cmSystemTools::GetCMakeCommand();
+ this->CTest->SetCTestConfiguration("CMakeCommand", cmake.c_str());
+}
+
+//----------------------------------------------------------------------
+void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os)
+{
+ if ( !this->CTest->GetProduceXML() )
+ {
+ return;
+ }
+ this->CTest->StartXML(os, this->AppendXML);
+ os << "<DynamicAnalysis Checker=\"";
+ switch ( this->MemoryTesterStyle )
+ {
+ case cmCTestMemCheckHandler::VALGRIND:
+ os << "Valgrind";
+ break;
+ case cmCTestMemCheckHandler::PURIFY:
+ os << "Purify";
+ break;
+ case cmCTestMemCheckHandler::BOUNDS_CHECKER:
+ os << "BoundsChecker";
+ break;
+ case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
+ os << "AddressSanitizer";
+ break;
+ case cmCTestMemCheckHandler::THREAD_SANITIZER:
+ os << "ThreadSanitizer";
+ break;
+ case cmCTestMemCheckHandler::MEMORY_SANITIZER:
+ os << "MemorySanitizer";
+ break;
+ case cmCTestMemCheckHandler::UB_SANITIZER:
+ os << "UndefinedBehaviorSanitizer";
+ break;
+ default:
+ os << "Unknown";
+ }
+ os << "\">" << std::endl;
+
+ os << "\t<StartDateTime>" << this->StartTest << "</StartDateTime>\n"
+ << "\t<StartTestTime>" << this->StartTestTime << "</StartTestTime>\n"
+ << "\t<TestList>\n";
+ cmCTestMemCheckHandler::TestResultsVector::size_type cc;
+ for ( cc = 0; cc < this->TestResults.size(); cc ++ )
+ {
+ cmCTestTestResult *result = &this->TestResults[cc];
+ std::string testPath = result->Path + "/" + result->Name;
+ os << "\t\t<Test>" << cmXMLSafe(
+ this->CTest->GetShortPathToFile(testPath.c_str()))
+ << "</Test>" << std::endl;
+ }
+ os << "\t</TestList>\n";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ "-- Processing memory checking output: ");
+ size_t total = this->TestResults.size();
+ size_t step = total / 10;
+ size_t current = 0;
+ for ( cc = 0; cc < this->TestResults.size(); cc ++ )
+ {
+ cmCTestTestResult *result = &this->TestResults[cc];
+ std::string memcheckstr;
+ std::vector<int> memcheckresults(this->ResultStrings.size(), 0);
+ bool res = this->ProcessMemCheckOutput(result->Output, memcheckstr,
+ memcheckresults);
+ if ( res && result->Status == cmCTestMemCheckHandler::COMPLETED )
+ {
+ continue;
+ }
+ this->CleanTestOutput(memcheckstr,
+ static_cast<size_t>(this->CustomMaximumFailedTestOutputSize));
+ this->WriteTestResultHeader(os, result);
+ os << "\t\t<Results>" << std::endl;
+ for(std::vector<int>::size_type kk = 0;
+ kk < memcheckresults.size(); ++kk)
+ {
+ if ( memcheckresults[kk] )
+ {
+ os << "\t\t\t<Defect type=\"" << this->ResultStringsLong[kk]
+ << "\">"
+ << memcheckresults[kk]
+ << "</Defect>" << std::endl;
+ }
+ this->GlobalResults[kk] += memcheckresults[kk];
+ }
+
+ std::string logTag;
+ if(this->CTest->ShouldCompressMemCheckOutput())
+ {
+ this->CTest->CompressString(memcheckstr);
+ logTag = "\t<Log compression=\"gzip\" encoding=\"base64\">\n";
+ }
+ else
+ {
+ logTag = "\t<Log>\n";
+ }
+
+ os
+ << "\t\t</Results>\n"
+ << logTag << cmXMLSafe(memcheckstr) << std::endl
+ << "\t</Log>\n";
+ this->WriteTestResultFooter(os, result);
+ if ( current < cc )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "#" << std::flush);
+ current += step;
+ }
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Memory checking results:"
+ << std::endl);
+ os << "\t<DefectList>" << std::endl;
+ for ( cc = 0; cc < this->GlobalResults.size(); cc ++ )
+ {
+ if ( this->GlobalResults[cc] )
+ {
+#ifdef cerr
+# undef cerr
+#endif
+ std::cerr.width(35);
+#define cerr no_cerr
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ this->ResultStringsLong[cc] << " - "
+ << this->GlobalResults[cc] << std::endl);
+ os << "\t\t<Defect Type=\"" << this->ResultStringsLong[cc]
+ << "\"/>" << std::endl;
+ }
+ }
+ os << "\t</DefectList>" << std::endl;
+
+ os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>" << std::endl;
+ os << "\t<EndTestTime>" << this->EndTestTime
+ << "</EndTestTime>" << std::endl;
+ os << "<ElapsedMinutes>"
+ << static_cast<int>(this->ElapsedTestingTime/6)/10.0
+ << "</ElapsedMinutes>\n";
+
+ os << "</DynamicAnalysis>" << std::endl;
+ this->CTest->EndXML(os);
+}
+
+//----------------------------------------------------------------------
+bool cmCTestMemCheckHandler::InitializeMemoryChecking()
+{
+ this->MemoryTesterEnvironmentVariable = "";
+ this->MemoryTester = "";
+ // Setup the command
+ if ( cmSystemTools::FileExists(this->CTest->GetCTestConfiguration(
+ "MemoryCheckCommand").c_str()) )
+ {
+ this->MemoryTester
+ = this->CTest->GetCTestConfiguration("MemoryCheckCommand").c_str();
+ std::string testerName =
+ cmSystemTools::GetFilenameName(this->MemoryTester);
+ // determine the checker type
+ if ( testerName.find("valgrind") != std::string::npos ||
+ this->CTest->GetCTestConfiguration("MemoryCheckType")
+ == "Valgrind")
+ {
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
+ }
+ else if ( testerName.find("purify") != std::string::npos )
+ {
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
+ }
+ else if ( testerName.find("BC") != std::string::npos )
+ {
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
+ }
+ else
+ {
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::UNKNOWN;
+ }
+ }
+ else if ( cmSystemTools::FileExists(this->CTest->GetCTestConfiguration(
+ "PurifyCommand").c_str()) )
+ {
+ this->MemoryTester
+ = this->CTest->GetCTestConfiguration("PurifyCommand").c_str();
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
+ }
+ else if ( cmSystemTools::FileExists(this->CTest->GetCTestConfiguration(
+ "ValgrindCommand").c_str()) )
+ {
+ this->MemoryTester
+ = this->CTest->GetCTestConfiguration("ValgrindCommand").c_str();
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
+ }
+ else if ( cmSystemTools::FileExists(this->CTest->GetCTestConfiguration(
+ "BoundsCheckerCommand").c_str()) )
+ {
+ this->MemoryTester
+ = this->CTest->GetCTestConfiguration("BoundsCheckerCommand").c_str();
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
+ }
+ if ( this->CTest->GetCTestConfiguration("MemoryCheckType")
+ == "AddressSanitizer")
+ {
+ this->MemoryTester
+ = this->CTest->GetCTestConfiguration("CMakeCommand").c_str();
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::ADDRESS_SANITIZER;
+ this->LogWithPID = true; // even if we give the log file the pid is added
+ }
+ if ( this->CTest->GetCTestConfiguration("MemoryCheckType")
+ == "ThreadSanitizer")
+ {
+ this->MemoryTester
+ = this->CTest->GetCTestConfiguration("CMakeCommand").c_str();
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::THREAD_SANITIZER;
+ this->LogWithPID = true; // even if we give the log file the pid is added
+ }
+ if ( this->CTest->GetCTestConfiguration("MemoryCheckType")
+ == "MemorySanitizer")
+ {
+ this->MemoryTester
+ = this->CTest->GetCTestConfiguration("CMakeCommand").c_str();
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::MEMORY_SANITIZER;
+ this->LogWithPID = true; // even if we give the log file the pid is added
+ }
+ if ( this->CTest->GetCTestConfiguration("MemoryCheckType")
+ == "UndefinedBehaviorSanitizer")
+ {
+ this->MemoryTester
+ = this->CTest->GetCTestConfiguration("CMakeCommand").c_str();
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::UB_SANITIZER;
+ this->LogWithPID = true; // even if we give the log file the pid is added
+ }
+ // Check the MemoryCheckType
+ if(this->MemoryTesterStyle == cmCTestMemCheckHandler::UNKNOWN)
+ {
+ std::string checkType =
+ this->CTest->GetCTestConfiguration("MemoryCheckType");
+ if(checkType == "Purify")
+ {
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
+ }
+ else if(checkType == "BoundsChecker")
+ {
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
+ }
+ else if(checkType == "Valgrind")
+ {
+ this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
+ }
+ }
+ if(this->MemoryTester.size() == 0 )
+ {
+ cmCTestLog(this->CTest, WARNING,
+ "Memory checker (MemoryCheckCommand) "
+ "not set, or cannot find the specified program."
+ << std::endl);
+ return false;
+ }
+
+ // Setup the options
+ std::string memoryTesterOptions;
+ if ( this->CTest->GetCTestConfiguration(
+ "MemoryCheckCommandOptions").size() )
+ {
+ memoryTesterOptions = this->CTest->GetCTestConfiguration(
+ "MemoryCheckCommandOptions");
+ }
+ else if ( this->CTest->GetCTestConfiguration(
+ "ValgrindCommandOptions").size() )
+ {
+ memoryTesterOptions = this->CTest->GetCTestConfiguration(
+ "ValgrindCommandOptions");
+ }
+ this->MemoryTesterOptions
+ = cmSystemTools::ParseArguments(memoryTesterOptions.c_str());
+
+ this->MemoryTesterOutputFile
+ = this->CTest->GetBinaryDir()
+ + "/Testing/Temporary/MemoryChecker.??.log";
+
+ switch ( this->MemoryTesterStyle )
+ {
+ case cmCTestMemCheckHandler::VALGRIND:
+ {
+ if ( this->MemoryTesterOptions.empty() )
+ {
+ this->MemoryTesterOptions.push_back("-q");
+ this->MemoryTesterOptions.push_back("--tool=memcheck");
+ this->MemoryTesterOptions.push_back("--leak-check=yes");
+ this->MemoryTesterOptions.push_back("--show-reachable=yes");
+ this->MemoryTesterOptions.push_back("--num-callers=50");
+ }
+ if ( this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile").size() )
+ {
+ if ( !cmSystemTools::FileExists(this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile").c_str()) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find memory checker suppression file: "
+ << this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile") << std::endl);
+ return false;
+ }
+ std::string suppressions = "--suppressions="
+ + this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
+ this->MemoryTesterOptions.push_back(suppressions);
+ }
+ std::string outputFile = "--log-file="
+ + this->MemoryTesterOutputFile;
+ this->MemoryTesterDynamicOptions.push_back(outputFile);
+ break;
+ }
+ case cmCTestMemCheckHandler::PURIFY:
+ {
+ std::string outputFile;
+#ifdef _WIN32
+ if( this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile").size() )
+ {
+ if( !cmSystemTools::FileExists(this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile").c_str()) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find memory checker suppression file: "
+ << this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile").c_str() << std::endl);
+ return false;
+ }
+ std::string filterFiles = "/FilterFiles="
+ + this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
+ this->MemoryTesterOptions.push_back(filterFiles);
+ }
+ outputFile = "/SAVETEXTDATA=";
+#else
+ outputFile = "-log-file=";
+#endif
+ outputFile += this->MemoryTesterOutputFile;
+ this->MemoryTesterDynamicOptions.push_back(outputFile);
+ break;
+ }
+ case cmCTestMemCheckHandler::BOUNDS_CHECKER:
+ {
+ this->BoundsCheckerXMLFile = this->MemoryTesterOutputFile;
+ std::string dpbdFile = this->CTest->GetBinaryDir()
+ + "/Testing/Temporary/MemoryChecker.??.DPbd";
+ this->BoundsCheckerDPBDFile = dpbdFile;
+ this->MemoryTesterDynamicOptions.push_back("/B");
+ this->MemoryTesterDynamicOptions.push_back(dpbdFile);
+ this->MemoryTesterDynamicOptions.push_back("/X");
+ this->MemoryTesterDynamicOptions.push_back(this->MemoryTesterOutputFile);
+ this->MemoryTesterOptions.push_back("/M");
+ break;
+ }
+ // these are almost the same but the env var used is different
+ case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
+ case cmCTestMemCheckHandler::THREAD_SANITIZER:
+ case cmCTestMemCheckHandler::MEMORY_SANITIZER:
+ case cmCTestMemCheckHandler::UB_SANITIZER:
+ {
+ // To pass arguments to ThreadSanitizer the environment variable
+ // TSAN_OPTIONS is used. This is done with the cmake -E env command.
+ // The MemoryTesterDynamicOptions is setup with the -E env
+ // Then the MemoryTesterEnvironmentVariable gets the
+ // TSAN_OPTIONS string with the log_path in it.
+ this->MemoryTesterDynamicOptions.push_back("-E");
+ this->MemoryTesterDynamicOptions.push_back("env");
+ std::string envVar;
+ std::string extraOptions =
+ this->CTest->GetCTestConfiguration("MemoryCheckSanitizerOptions");
+ if(this->MemoryTesterStyle == cmCTestMemCheckHandler::ADDRESS_SANITIZER)
+ {
+ envVar = "ASAN_OPTIONS";
+ extraOptions += " detect_leaks=1";
+ }
+ else if(this->MemoryTesterStyle ==
+ cmCTestMemCheckHandler::THREAD_SANITIZER)
+ {
+ envVar = "TSAN_OPTIONS";
+ }
+ else if(this->MemoryTesterStyle ==
+ cmCTestMemCheckHandler::MEMORY_SANITIZER)
+ {
+ envVar = "MSAN_OPTIONS";
+ }
+ else if(this->MemoryTesterStyle == cmCTestMemCheckHandler::UB_SANITIZER)
+ {
+ envVar = "UBSAN_OPTIONS";
+ }
+ std::string outputFile = envVar + "=log_path=\""
+ + this->MemoryTesterOutputFile + "\" ";
+ this->MemoryTesterEnvironmentVariable = outputFile + extraOptions;
+ break;
+ }
+ default:
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Do not understand memory checker: " << this->MemoryTester
+ << std::endl);
+ return false;
+ }
+
+ this->InitializeResultsVectors();
+ // std::vector<std::string>::size_type cc;
+ // for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
+ // {
+ // this->MemoryTesterGlobalResults[cc] = 0;
+ // }
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCTestMemCheckHandler::
+ProcessMemCheckOutput(const std::string& str,
+ std::string& log, std::vector<int>& results)
+{
+ if ( this->MemoryTesterStyle == cmCTestMemCheckHandler::VALGRIND )
+ {
+ return this->ProcessMemCheckValgrindOutput(str, log, results);
+ }
+ else if ( this->MemoryTesterStyle == cmCTestMemCheckHandler::PURIFY )
+ {
+ return this->ProcessMemCheckPurifyOutput(str, log, results);
+ }
+ else if ( this->MemoryTesterStyle ==
+ cmCTestMemCheckHandler::ADDRESS_SANITIZER ||
+ this->MemoryTesterStyle ==
+ cmCTestMemCheckHandler::THREAD_SANITIZER ||
+ this->MemoryTesterStyle ==
+ cmCTestMemCheckHandler::MEMORY_SANITIZER ||
+ this->MemoryTesterStyle ==
+ cmCTestMemCheckHandler::UB_SANITIZER)
+ {
+ return this->ProcessMemCheckSanitizerOutput(str, log, results);
+ }
+ else if ( this->MemoryTesterStyle ==
+ cmCTestMemCheckHandler::BOUNDS_CHECKER )
+ {
+ return this->ProcessMemCheckBoundsCheckerOutput(str, log, results);
+ }
+ else
+ {
+ log.append("\nMemory checking style used was: ");
+ log.append("None that I know");
+ log = str;
+ }
+ return true;
+}
+
+std::vector<int>::size_type cmCTestMemCheckHandler::FindOrAddWarning(
+ const std::string& warning)
+{
+ for(std::vector<std::string>::size_type i =0;
+ i < this->ResultStrings.size(); ++i)
+ {
+ if(this->ResultStrings[i] == warning)
+ {
+ return i;
+ }
+ }
+ this->GlobalResults.push_back(0); // this must stay the same size
+ this->ResultStrings.push_back(warning);
+ this->ResultStringsLong.push_back(warning);
+ return this->ResultStrings.size()-1;
+}
+//----------------------------------------------------------------------
+bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput(
+ const std::string& str, std::string& log,
+ std::vector<int>& result)
+{
+ std::string regex;
+ switch ( this->MemoryTesterStyle )
+ {
+ case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
+ regex = "ERROR: AddressSanitizer: (.*) on.*";
+ break;
+ case cmCTestMemCheckHandler::THREAD_SANITIZER:
+ regex = "WARNING: ThreadSanitizer: (.*) \\(pid=.*\\)";
+ break;
+ case cmCTestMemCheckHandler::MEMORY_SANITIZER:
+ regex = "WARNING: MemorySanitizer: (.*)";
+ break;
+ case cmCTestMemCheckHandler::UB_SANITIZER:
+ regex = "runtime error: (.*)";
+ break;
+ default:
+ break;
+ }
+ cmsys::RegularExpression sanitizerWarning(regex);
+ cmsys::RegularExpression leakWarning("(Direct|Indirect) leak of .*");
+ int defects = 0;
+ std::vector<std::string> lines;
+ cmSystemTools::Split(str.c_str(), lines);
+ cmOStringStream ostr;
+ log = "";
+ for( std::vector<std::string>::iterator i = lines.begin();
+ i != lines.end(); ++i)
+ {
+ std::string resultFound;
+ if(leakWarning.find(*i))
+ {
+ resultFound = leakWarning.match(1)+" leak";
+ }
+ else if (sanitizerWarning.find(*i))
+ {
+ resultFound = sanitizerWarning.match(1);
+ }
+ if(resultFound.size())
+ {
+ std::vector<int>::size_type idx = this->FindOrAddWarning(resultFound);
+ if(result.size() == 0 || idx > result.size()-1)
+ {
+ result.push_back(1);
+ }
+ else
+ {
+ result[idx]++;
+ }
+ defects++;
+ ostr << "<b>" << this->ResultStrings[idx] << "</b> ";
+ }
+ ostr << cmXMLSafe(*i) << std::endl;
+ }
+ log = ostr.str();
+ if(defects)
+ {
+ return false;
+ }
+ return true;
+}
+//----------------------------------------------------------------------
+bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput(
+ const std::string& str, std::string& log,
+ std::vector<int>& results)
+{
+ std::vector<std::string> lines;
+ cmSystemTools::Split(str.c_str(), lines);
+ cmOStringStream ostr;
+ log = "";
+
+ cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
+
+ int defects = 0;
+
+ for( std::vector<std::string>::iterator i = lines.begin();
+ i != lines.end(); ++i)
+ {
+ std::vector<int>::size_type failure = this->ResultStrings.size();
+ if ( pfW.find(*i) )
+ {
+ std::vector<int>::size_type cc;
+ for ( cc = 0; cc < this->ResultStrings.size(); cc ++ )
+ {
+ if ( pfW.match(1) == this->ResultStrings[cc] )
+ {
+ failure = cc;
+ break;
+ }
+ }
+ if ( cc == this->ResultStrings.size() )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown Purify memory fault: "
+ << pfW.match(1) << std::endl);
+ ostr << "*** Unknown Purify memory fault: " << pfW.match(1)
+ << std::endl;
+ }
+ }
+ if ( failure != this->ResultStrings.size() )
+ {
+ ostr << "<b>" << this->ResultStrings[failure] << "</b> ";
+ results[failure] ++;
+ defects ++;
+ }
+ ostr << cmXMLSafe(*i) << std::endl;
+ }
+
+ log = ostr.str();
+ if ( defects )
+ {
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
+ const std::string& str, std::string& log,
+ std::vector<int>& results)
+{
+ std::vector<std::string> lines;
+ cmSystemTools::Split(str.c_str(), lines);
+ bool unlimitedOutput = false;
+ if(str.find("CTEST_FULL_OUTPUT") != str.npos ||
+ this->CustomMaximumFailedTestOutputSize == 0)
+ {
+ unlimitedOutput = true;
+ }
+
+ std::string::size_type cc;
+
+ cmOStringStream ostr;
+ log = "";
+
+ int defects = 0;
+
+ cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
+
+ cmsys::RegularExpression vgFIM(
+ "== .*Invalid free\\(\\) / delete / delete\\[\\]");
+ cmsys::RegularExpression vgFMM(
+ "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
+ cmsys::RegularExpression vgMLK1(
+ "== .*[0-9,]+ bytes in [0-9,]+ blocks are definitely lost"
+ " in loss record [0-9,]+ of [0-9,]+");
+ cmsys::RegularExpression vgMLK2(
+ "== .*[0-9,]+ \\([0-9,]+ direct, [0-9,]+ indirect\\)"
+ " bytes in [0-9,]+ blocks are definitely lost"
+ " in loss record [0-9,]+ of [0-9,]+");
+ cmsys::RegularExpression vgPAR(
+ "== .*Syscall param .* (contains|points to) unaddressable byte\\(s\\)");
+ cmsys::RegularExpression vgMPK1(
+ "== .*[0-9,]+ bytes in [0-9,]+ blocks are possibly lost in"
+ " loss record [0-9,]+ of [0-9,]+");
+ cmsys::RegularExpression vgMPK2(
+ "== .*[0-9,]+ bytes in [0-9,]+ blocks are still reachable"
+ " in loss record [0-9,]+ of [0-9,]+");
+ cmsys::RegularExpression vgUMC(
+ "== .*Conditional jump or move depends on uninitialised value\\(s\\)");
+ cmsys::RegularExpression vgUMR1(
+ "== .*Use of uninitialised value of size [0-9,]+");
+ cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9,]+");
+ cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
+ cmsys::RegularExpression vgUMR4("== .*Syscall param .* contains "
+ "uninitialised or unaddressable byte\\(s\\)");
+ cmsys::RegularExpression vgUMR5("== .*Syscall param .* uninitialised");
+ cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9,]+");
+ cmsys::RegularExpression vgABR("== .*pthread_mutex_unlock: mutex is "
+ "locked by a different thread");
+ std::vector<std::string::size_type> nonValGrindOutput;
+ double sttime = cmSystemTools::GetTime();
+ cmCTestLog(this->CTest, DEBUG, "Start test: " << lines.size() << std::endl);
+ std::string::size_type totalOutputSize = 0;
+ for ( cc = 0; cc < lines.size(); cc ++ )
+ {
+ cmCTestLog(this->CTest, DEBUG, "test line "
+ << lines[cc] << std::endl);
+
+ if ( valgrindLine.find(lines[cc]) )
+ {
+ cmCTestLog(this->CTest, DEBUG, "valgrind line "
+ << lines[cc] << std::endl);
+ int failure = cmCTestMemCheckHandler::NO_MEMORY_FAULT;
+ if ( vgFIM.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::FIM;
+ }
+ else if ( vgFMM.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::FMM;
+ }
+ else if ( vgMLK1.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::MLK;
+ }
+ else if ( vgMLK2.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::MLK;
+ }
+ else if ( vgPAR.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::PAR;
+ }
+ else if ( vgMPK1.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::MPK;
+ }
+ else if ( vgMPK2.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::MPK;
+ }
+ else if ( vgUMC.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::UMC;
+ }
+ else if ( vgUMR1.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::UMR;
+ }
+ else if ( vgUMR2.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::UMR;
+ }
+ else if ( vgUMR3.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::UMR;
+ }
+ else if ( vgUMR4.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::UMR;
+ }
+ else if ( vgUMR5.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::UMR;
+ }
+ else if ( vgIPW.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::IPW;
+ }
+ else if ( vgABR.find(lines[cc]) )
+ {
+ failure = cmCTestMemCheckHandler::ABR;
+ }
+
+ if ( failure != cmCTestMemCheckHandler::NO_MEMORY_FAULT )
+ {
+ ostr << "<b>" << this->ResultStrings[failure] << "</b> ";
+ results[failure] ++;
+ defects ++;
+ }
+ totalOutputSize += lines[cc].size();
+ ostr << cmXMLSafe(lines[cc]) << std::endl;
+ }
+ else
+ {
+ nonValGrindOutput.push_back(cc);
+ }
+ }
+ // Now put all all the non valgrind output into the test output
+ // This should be last in case it gets truncated by the output
+ // limiting code
+ for(std::vector<std::string::size_type>::iterator i =
+ nonValGrindOutput.begin(); i != nonValGrindOutput.end(); ++i)
+ {
+ totalOutputSize += lines[*i].size();
+ cmCTestLog(this->CTest, DEBUG, "before xml safe "
+ << lines[*i] << std::endl);
+ cmCTestLog(this->CTest, DEBUG, "after xml safe "
+ << cmXMLSafe(lines[*i]) << std::endl);
+ ostr << cmXMLSafe(lines[*i]) << std::endl;
+ if(!unlimitedOutput && totalOutputSize >
+ static_cast<size_t>(this->CustomMaximumFailedTestOutputSize))
+ {
+ ostr << "....\n";
+ ostr << "Test Output for this test has been truncated see testing"
+ " machine logs for full output,\n";
+ ostr << "or put CTEST_FULL_OUTPUT in the output of "
+ "this test program.\n";
+ break; // stop the copy of output if we are full
+ }
+ }
+ cmCTestLog(this->CTest, DEBUG, "End test (elapsed: "
+ << (cmSystemTools::GetTime() - sttime) << std::endl);
+ log = ostr.str();
+ if ( defects )
+ {
+ return false;
+ }
+ return true;
+}
+
+
+
+//----------------------------------------------------------------------
+bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput(
+ const std::string& str, std::string& log,
+ std::vector<int>& results)
+{
+ log = "";
+ double sttime = cmSystemTools::GetTime();
+ std::vector<std::string> lines;
+ cmSystemTools::Split(str.c_str(), lines);
+ cmCTestLog(this->CTest, DEBUG, "Start test: " << lines.size() << std::endl);
+ std::vector<std::string>::size_type cc;
+ for ( cc = 0; cc < lines.size(); cc ++ )
+ {
+ if(lines[cc] == BOUNDS_CHECKER_MARKER)
+ {
+ break;
+ }
+ }
+ cmBoundsCheckerParser parser(this->CTest);
+ parser.InitializeParser();
+ if(cc < lines.size())
+ {
+ for(cc++; cc < lines.size(); ++cc)
+ {
+ std::string& theLine = lines[cc];
+ // check for command line arguments that are not escaped
+ // correctly by BC
+ if(theLine.find("TargetArgs=") != theLine.npos)
+ {
+ // skip this because BC gets it wrong and we can't parse it
+ }
+ else if(!parser.ParseChunk(theLine.c_str(), theLine.size()))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error in ParseChunk: " << theLine
+ << std::endl);
+ }
+ }
+ }
+ int defects = 0;
+ for(cc =0; cc < parser.Errors.size(); ++cc)
+ {
+ results[parser.Errors[cc]]++;
+ defects++;
+ }
+ cmCTestLog(this->CTest, DEBUG, "End test (elapsed: "
+ << (cmSystemTools::GetTime() - sttime) << std::endl);
+ if(defects)
+ {
+ // only put the output of Bounds Checker if there were
+ // errors or leaks detected
+ log = parser.Log;
+ return false;
+ }
+ return true;
+}
+
+// PostProcessTest memcheck results
+void
+cmCTestMemCheckHandler::PostProcessTest(cmCTestTestResult& res,
+ int test)
+{
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "PostProcessTest memcheck results for : "
+ << res.Name << std::endl);
+ if(this->MemoryTesterStyle
+ == cmCTestMemCheckHandler::BOUNDS_CHECKER)
+ {
+ this->PostProcessBoundsCheckerTest(res, test);
+ }
+ else
+ {
+ std::vector<std::string> files;
+ this->TestOutputFileNames(test, files);
+ for(std::vector<std::string>::iterator i = files.begin();
+ i != files.end(); ++i)
+ {
+ this->AppendMemTesterOutput(res, *i);
+ }
+ }
+}
+
+
+// This method puts the bounds checker output file into the output
+// for the test
+void
+cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res,
+ int test)
+{
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "PostProcessBoundsCheckerTest for : "
+ << res.Name << std::endl);
+ std::vector<std::string> files;
+ this->TestOutputFileNames(test, files);
+ if ( files.size() == 0 )
+ {
+ return;
+ }
+ std::string ofile = files[0];
+ // put a scope around this to close ifs so the file can be removed
+ {
+ cmsys::ifstream ifs(ofile.c_str());
+ if ( !ifs )
+ {
+ std::string log = "Cannot read memory tester output file: " + ofile;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
+ return;
+ }
+ res.Output += BOUNDS_CHECKER_MARKER;
+ res.Output += "\n";
+ std::string line;
+ while ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ res.Output += line;
+ res.Output += "\n";
+ }
+ }
+ cmSystemTools::Delay(1000);
+ cmSystemTools::RemoveFile(this->BoundsCheckerDPBDFile.c_str());
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Remove: "
+ << this->BoundsCheckerDPBDFile << std::endl);
+ cmSystemTools::RemoveFile(this->BoundsCheckerXMLFile.c_str());
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Remove: "
+ << this->BoundsCheckerXMLFile << std::endl);
+}
+
+void
+cmCTestMemCheckHandler::AppendMemTesterOutput(cmCTestTestResult& res,
+ std::string const& ofile)
+{
+ if ( ofile.empty() )
+ {
+ return;
+ }
+ // put ifs in scope so file can be deleted if needed
+ {
+ cmsys::ifstream ifs(ofile.c_str());
+ if ( !ifs )
+ {
+ std::string log = "Cannot read memory tester output file: " + ofile;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
+ return;
+ }
+ std::string line;
+ while ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ res.Output += line;
+ res.Output += "\n";
+ }
+ }
+ if(this->LogWithPID)
+ {
+ cmSystemTools::RemoveFile(ofile.c_str());
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Remove: "<< ofile <<"\n");
+ }
+}
+
+void cmCTestMemCheckHandler::TestOutputFileNames(int test,
+ std::vector<std::string>&
+ files)
+{
+ std::string index;
+ cmOStringStream stream;
+ stream << test;
+ index = stream.str();
+ std::string ofile = this->MemoryTesterOutputFile;
+ std::string::size_type pos = ofile.find("??");
+ ofile.replace(pos, 2, index);
+ if(this->LogWithPID)
+ {
+ ofile += ".*";
+ cmsys::Glob g;
+ g.FindFiles(ofile);
+ if(g.GetFiles().size() == 0)
+ {
+ std::string log = "Cannot find memory tester output file: "
+ + ofile;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
+ ofile = "";
+ }
+ else
+ {
+ files = g.GetFiles();
+ return;
+ }
+ }
+ else if ( !cmSystemTools::FileExists(ofile.c_str()) )
+ {
+ std::string log = "Cannot find memory tester output file: "
+ + ofile;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
+ ofile = "";
+ }
+ files.push_back(ofile);
+}
diff --git a/Source/CTest/cmCTestMemCheckHandler.h b/Source/CTest/cmCTestMemCheckHandler.h
new file mode 100644
index 0000000000..69fdd9f8c8
--- /dev/null
+++ b/Source/CTest/cmCTestMemCheckHandler.h
@@ -0,0 +1,157 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestMemCheckHandler_h
+#define cmCTestMemCheckHandler_h
+
+
+#include "cmCTestTestHandler.h"
+#include "cmStandardIncludes.h"
+#include "cmListFileCache.h"
+#include <vector>
+#include <string>
+
+class cmMakefile;
+
+/** \class cmCTestMemCheckHandler
+ * \brief A class that handles ctest -S invocations
+ *
+ */
+class cmCTestMemCheckHandler : public cmCTestTestHandler
+{
+ friend class cmCTestRunTest;
+public:
+ cmTypeMacro(cmCTestMemCheckHandler, cmCTestTestHandler);
+
+ void PopulateCustomVectors(cmMakefile *mf);
+
+ cmCTestMemCheckHandler();
+
+ void Initialize();
+protected:
+ virtual int PreProcessHandler();
+ virtual int PostProcessHandler();
+ virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
+
+private:
+
+ enum { // Memory checkers
+ UNKNOWN = 0,
+ VALGRIND,
+ PURIFY,
+ BOUNDS_CHECKER,
+ // checkers after here do not use the standard error list
+ ADDRESS_SANITIZER,
+ THREAD_SANITIZER,
+ MEMORY_SANITIZER,
+ UB_SANITIZER
+ };
+public:
+ enum { // Memory faults
+ ABR = 0,
+ ABW,
+ ABWL,
+ COR,
+ EXU,
+ FFM,
+ FIM,
+ FMM,
+ FMR,
+ FMW,
+ FUM,
+ IPR,
+ IPW,
+ MAF,
+ MLK,
+ MPK,
+ NPR,
+ ODS,
+ PAR,
+ PLK,
+ UMC,
+ UMR,
+ NO_MEMORY_FAULT
+ };
+private:
+ enum { // Program statuses
+ NOT_RUN = 0,
+ TIMEOUT,
+ SEGFAULT,
+ ILLEGAL,
+ INTERRUPT,
+ NUMERICAL,
+ OTHER_FAULT,
+ FAILED,
+ BAD_COMMAND,
+ COMPLETED
+ };
+ std::string BoundsCheckerDPBDFile;
+ std::string BoundsCheckerXMLFile;
+ std::string MemoryTester;
+ std::vector<std::string> MemoryTesterDynamicOptions;
+ std::vector<std::string> MemoryTesterOptions;
+ int MemoryTesterStyle;
+ std::string MemoryTesterOutputFile;
+ std::string MemoryTesterEnvironmentVariable;
+ // these are used to store the types of errors that can show up
+ std::vector<std::string> ResultStrings;
+ std::vector<std::string> ResultStringsLong;
+ std::vector<int> GlobalResults;
+ bool LogWithPID; // does log file add pid
+
+ std::vector<int>::size_type FindOrAddWarning(const std::string& warning);
+ // initialize the ResultStrings and ResultStringsLong for
+ // this type of checker
+ void InitializeResultsVectors();
+
+ ///! Initialize memory checking subsystem.
+ bool InitializeMemoryChecking();
+
+ /**
+ * Generate the Dart compatible output
+ */
+ void GenerateDartOutput(std::ostream& os);
+
+ std::vector<std::string> CustomPreMemCheck;
+ std::vector<std::string> CustomPostMemCheck;
+
+ //! Parse Valgrind/Purify/Bounds Checker result out of the output
+ //string. After running, log holds the output and results hold the
+ //different memmory errors.
+ bool ProcessMemCheckOutput(const std::string& str,
+ std::string& log, std::vector<int>& results);
+ bool ProcessMemCheckValgrindOutput(const std::string& str,
+ std::string& log,
+ std::vector<int>& results);
+ bool ProcessMemCheckPurifyOutput(const std::string& str,
+ std::string& log,
+ std::vector<int>& results);
+ bool ProcessMemCheckSanitizerOutput(const std::string& str,
+ std::string& log,
+ std::vector<int>& results);
+ bool ProcessMemCheckBoundsCheckerOutput(const std::string& str,
+ std::string& log,
+ std::vector<int>& results);
+
+ void PostProcessTest(cmCTestTestResult& res, int test);
+ void PostProcessBoundsCheckerTest(cmCTestTestResult& res, int test);
+
+ ///! append MemoryTesterOutputFile to the test log
+ void AppendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res,
+ std::string const& filename);
+
+ ///! generate the output filename for the given test index
+ void TestOutputFileNames(int test, std::vector<std::string>& files);
+};
+
+#endif
+
diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx
new file mode 100644
index 0000000000..7ba434cc96
--- /dev/null
+++ b/Source/CTest/cmCTestMultiProcessHandler.cxx
@@ -0,0 +1,809 @@
+/*============================================================================
+ 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 "cmCTestMultiProcessHandler.h"
+#include "cmProcess.h"
+#include "cmStandardIncludes.h"
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include <stdlib.h>
+#include <stack>
+#include <float.h>
+#include <cmsys/FStream.hxx>
+
+class TestComparator
+{
+public:
+ TestComparator(cmCTestMultiProcessHandler* handler) : Handler(handler) {}
+ ~TestComparator() {}
+
+ // Sorts tests in descending order of cost
+ bool operator() (int index1, int index2) const
+ {
+ return Handler->Properties[index1]->Cost >
+ Handler->Properties[index2]->Cost;
+ }
+
+private:
+ cmCTestMultiProcessHandler* Handler;
+};
+
+cmCTestMultiProcessHandler::cmCTestMultiProcessHandler()
+{
+ this->ParallelLevel = 1;
+ this->Completed = 0;
+ this->RunningCount = 0;
+ this->StopTimePassed = false;
+ this->HasCycles = false;
+}
+
+cmCTestMultiProcessHandler::~cmCTestMultiProcessHandler()
+{
+}
+
+ // Set the tests
+void
+cmCTestMultiProcessHandler::SetTests(TestMap& tests,
+ PropertiesMap& properties)
+{
+ this->Tests = tests;
+ this->Properties = properties;
+ this->Total = this->Tests.size();
+ // set test run map to false for all
+ for(TestMap::iterator i = this->Tests.begin();
+ i != this->Tests.end(); ++i)
+ {
+ this->TestRunningMap[i->first] = false;
+ this->TestFinishMap[i->first] = false;
+ }
+ if(!this->CTest->GetShowOnly())
+ {
+ this->ReadCostData();
+ this->HasCycles = !this->CheckCycles();
+ if(this->HasCycles)
+ {
+ return;
+ }
+ this->CreateTestCostList();
+ }
+}
+
+ // Set the max number of tests that can be run at the same time.
+void cmCTestMultiProcessHandler::SetParallelLevel(size_t level)
+{
+ this->ParallelLevel = level < 1 ? 1 : level;
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::RunTests()
+{
+ this->CheckResume();
+ if(this->HasCycles)
+ {
+ return;
+ }
+ this->TestHandler->SetMaxIndex(this->FindMaxIndex());
+ this->StartNextTests();
+ while(this->Tests.size() != 0)
+ {
+ if(this->StopTimePassed)
+ {
+ return;
+ }
+ this->CheckOutput();
+ this->StartNextTests();
+ }
+ // let all running tests finish
+ while(this->CheckOutput())
+ {
+ }
+ this->MarkFinished();
+ this->UpdateCostData();
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::StartTestProcess(int test)
+{
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "test " << test << "\n");
+ this->TestRunningMap[test] = true; // mark the test as running
+ // now remove the test itself
+ this->EraseTest(test);
+ this->RunningCount += GetProcessorsUsed(test);
+
+ cmCTestRunTest* testRun = new cmCTestRunTest(this->TestHandler);
+ testRun->SetIndex(test);
+ testRun->SetTestProperties(this->Properties[test]);
+
+ std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(this->Properties[test]->Directory.c_str());
+
+ // Lock the resources we'll be using
+ this->LockResources(test);
+
+ if(testRun->StartTest(this->Total))
+ {
+ this->RunningTests.insert(testRun);
+ }
+ else if(testRun->IsStopTimePassed())
+ {
+ this->StopTimePassed = true;
+ delete testRun;
+ return;
+ }
+ else
+ {
+
+ for(TestMap::iterator j = this->Tests.begin();
+ j != this->Tests.end(); ++j)
+ {
+ j->second.erase(test);
+ }
+
+ this->UnlockResources(test);
+ this->Completed++;
+ this->TestFinishMap[test] = true;
+ this->TestRunningMap[test] = false;
+ this->RunningCount -= GetProcessorsUsed(test);
+ testRun->EndTest(this->Completed, this->Total, false);
+ this->Failed->push_back(this->Properties[test]->Name);
+ delete testRun;
+ }
+ cmSystemTools::ChangeDirectory(current_dir.c_str());
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::LockResources(int index)
+{
+ for(std::set<std::string>::iterator i =
+ this->Properties[index]->LockedResources.begin();
+ i != this->Properties[index]->LockedResources.end(); ++i)
+ {
+ this->LockedResources.insert(*i);
+ }
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::UnlockResources(int index)
+{
+ for(std::set<std::string>::iterator i =
+ this->Properties[index]->LockedResources.begin();
+ i != this->Properties[index]->LockedResources.end(); ++i)
+ {
+ this->LockedResources.erase(*i);
+ }
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::EraseTest(int test)
+{
+ this->Tests.erase(test);
+ this->SortedTests.erase(
+ std::find(this->SortedTests.begin(), this->SortedTests.end(), test));
+}
+
+//---------------------------------------------------------
+inline size_t cmCTestMultiProcessHandler::GetProcessorsUsed(int test)
+{
+ size_t processors =
+ static_cast<int>(this->Properties[test]->Processors);
+ //If this is set to run serially, it must run alone.
+ //Also, if processors setting is set higher than the -j
+ //setting, we default to using all of the process slots.
+ if(this->Properties[test]->RunSerial
+ || processors > this->ParallelLevel)
+ {
+ processors = this->ParallelLevel;
+ }
+ return processors;
+}
+
+//---------------------------------------------------------
+bool cmCTestMultiProcessHandler::StartTest(int test)
+{
+ //Check for locked resources
+ for(std::set<std::string>::iterator i =
+ this->Properties[test]->LockedResources.begin();
+ i != this->Properties[test]->LockedResources.end(); ++i)
+ {
+ if(this->LockedResources.find(*i) != this->LockedResources.end())
+ {
+ return false;
+ }
+ }
+
+ // if there are no depends left then run this test
+ if(this->Tests[test].empty())
+ {
+ this->StartTestProcess(test);
+ return true;
+ }
+ // This test was not able to start because it is waiting
+ // on depends to run
+ return false;
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::StartNextTests()
+{
+ size_t numToStart = 0;
+ if(this->RunningCount < this->ParallelLevel)
+ {
+ numToStart = this->ParallelLevel - this->RunningCount;
+ }
+
+ if(numToStart == 0)
+ {
+ return;
+ }
+
+ TestList copy = this->SortedTests;
+ for(TestList::iterator test = copy.begin(); test != copy.end(); ++test)
+ {
+ size_t processors = GetProcessorsUsed(*test);
+
+ if(processors <= numToStart && this->StartTest(*test))
+ {
+ if(this->StopTimePassed)
+ {
+ return;
+ }
+ numToStart -= processors;
+ }
+ else if(numToStart == 0)
+ {
+ return;
+ }
+ }
+}
+
+//---------------------------------------------------------
+bool cmCTestMultiProcessHandler::CheckOutput()
+{
+ // no more output we are done
+ if(this->RunningTests.size() == 0)
+ {
+ return false;
+ }
+ std::vector<cmCTestRunTest*> finished;
+ std::string out, err;
+ for(std::set<cmCTestRunTest*>::const_iterator i = this->RunningTests.begin();
+ i != this->RunningTests.end(); ++i)
+ {
+ cmCTestRunTest* p = *i;
+ if(!p->CheckOutput())
+ {
+ finished.push_back(p);
+ }
+ }
+ for( std::vector<cmCTestRunTest*>::iterator i = finished.begin();
+ i != finished.end(); ++i)
+ {
+ this->Completed++;
+ cmCTestRunTest* p = *i;
+ int test = p->GetIndex();
+
+ if(p->EndTest(this->Completed, this->Total, true))
+ {
+ this->Passed->push_back(p->GetTestProperties()->Name);
+ }
+ else
+ {
+ this->Failed->push_back(p->GetTestProperties()->Name);
+ }
+ for(TestMap::iterator j = this->Tests.begin();
+ j != this->Tests.end(); ++j)
+ {
+ j->second.erase(test);
+ }
+ this->TestFinishMap[test] = true;
+ this->TestRunningMap[test] = false;
+ this->RunningTests.erase(p);
+ this->WriteCheckpoint(test);
+ this->UnlockResources(test);
+ this->RunningCount -= GetProcessorsUsed(test);
+ delete p;
+ }
+ return true;
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::UpdateCostData()
+{
+ std::string fname = this->CTest->GetCostDataFile();
+ std::string tmpout = fname + ".tmp";
+ cmsys::ofstream fout;
+ fout.open(tmpout.c_str());
+
+ PropertiesMap temp = this->Properties;
+
+ if(cmSystemTools::FileExists(fname.c_str()))
+ {
+ cmsys::ifstream fin;
+ fin.open(fname.c_str());
+
+ std::string line;
+ while(std::getline(fin, line))
+ {
+ if(line == "---") break;
+ std::vector<cmsys::String> parts =
+ cmSystemTools::SplitString(line.c_str(), ' ');
+ //Format: <name> <previous_runs> <avg_cost>
+ if(parts.size() < 3) break;
+
+ std::string name = parts[0];
+ int prev = atoi(parts[1].c_str());
+ float cost = static_cast<float>(atof(parts[2].c_str()));
+
+ int index = this->SearchByName(name);
+ if(index == -1)
+ {
+ // This test is not in memory. We just rewrite the entry
+ fout << name << " " << prev << " " << cost << "\n";
+ }
+ else
+ {
+ // Update with our new average cost
+ fout << name << " " << this->Properties[index]->PreviousRuns << " "
+ << this->Properties[index]->Cost << "\n";
+ temp.erase(index);
+ }
+ }
+ fin.close();
+ cmSystemTools::RemoveFile(fname.c_str());
+ }
+
+ // Add all tests not previously listed in the file
+ for(PropertiesMap::iterator i = temp.begin(); i != temp.end(); ++i)
+ {
+ fout << i->second->Name << " " << i->second->PreviousRuns << " "
+ << i->second->Cost << "\n";
+ }
+
+ // Write list of failed tests
+ fout << "---\n";
+ for(std::vector<std::string>::iterator i = this->Failed->begin();
+ i != this->Failed->end(); ++i)
+ {
+ fout << i->c_str() << "\n";
+ }
+ fout.close();
+ cmSystemTools::RenameFile(tmpout.c_str(), fname.c_str());
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::ReadCostData()
+{
+ std::string fname = this->CTest->GetCostDataFile();
+
+ if(cmSystemTools::FileExists(fname.c_str(), true))
+ {
+ cmsys::ifstream fin;
+ fin.open(fname.c_str());
+ std::string line;
+ while(std::getline(fin, line))
+ {
+ if(line == "---") break;
+
+ std::vector<cmsys::String> parts =
+ cmSystemTools::SplitString(line.c_str(), ' ');
+
+ // Probably an older version of the file, will be fixed next run
+ if(parts.size() < 3)
+ {
+ fin.close();
+ return;
+ }
+
+ std::string name = parts[0];
+ int prev = atoi(parts[1].c_str());
+ float cost = static_cast<float>(atof(parts[2].c_str()));
+
+ int index = this->SearchByName(name);
+ if(index == -1) continue;
+
+ this->Properties[index]->PreviousRuns = prev;
+ // When not running in parallel mode, don't use cost data
+ if(this->ParallelLevel > 1 &&
+ this->Properties[index] &&
+ this->Properties[index]->Cost == 0)
+ {
+ this->Properties[index]->Cost = cost;
+ }
+ }
+ // Next part of the file is the failed tests
+ while(std::getline(fin, line))
+ {
+ if(line != "")
+ {
+ this->LastTestsFailed.push_back(line);
+ }
+ }
+ fin.close();
+ }
+}
+
+//---------------------------------------------------------
+int cmCTestMultiProcessHandler::SearchByName(std::string name)
+{
+ int index = -1;
+
+ for(PropertiesMap::iterator i = this->Properties.begin();
+ i != this->Properties.end(); ++i)
+ {
+ if(i->second->Name == name)
+ {
+ index = i->first;
+ }
+ }
+ return index;
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::CreateTestCostList()
+{
+ if(this->ParallelLevel > 1)
+ {
+ CreateParallelTestCostList();
+ }
+ else
+ {
+ CreateSerialTestCostList();
+ }
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::CreateParallelTestCostList()
+{
+ TestSet alreadySortedTests;
+
+ std::list<TestSet> priorityStack;
+ priorityStack.push_back(TestSet());
+ TestSet &topLevel = priorityStack.back();
+
+ // In parallel test runs add previously failed tests to the front
+ // of the cost list and queue other tests for further sorting
+ for(TestMap::const_iterator i = this->Tests.begin();
+ i != this->Tests.end(); ++i)
+ {
+ if(std::find(this->LastTestsFailed.begin(), this->LastTestsFailed.end(),
+ this->Properties[i->first]->Name) != this->LastTestsFailed.end())
+ {
+ //If the test failed last time, it should be run first.
+ this->SortedTests.push_back(i->first);
+ alreadySortedTests.insert(i->first);
+ }
+ else
+ {
+ topLevel.insert(i->first);
+ }
+ }
+
+ // In parallel test runs repeatedly move dependencies of the tests on
+ // the current dependency level to the next level until no
+ // further dependencies exist.
+ while(priorityStack.back().size())
+ {
+ TestSet &previousSet = priorityStack.back();
+ priorityStack.push_back(TestSet());
+ TestSet &currentSet = priorityStack.back();
+
+ for(TestSet::const_iterator i = previousSet.begin();
+ i != previousSet.end(); ++i)
+ {
+ TestSet const& dependencies = this->Tests[*i];
+ for(TestSet::const_iterator j = dependencies.begin();
+ j != dependencies.end(); ++j)
+ {
+ currentSet.insert(*j);
+ }
+ }
+
+ for(TestSet::const_iterator i = currentSet.begin();
+ i != currentSet.end(); ++i)
+ {
+ previousSet.erase(*i);
+ }
+ }
+
+ // Remove the empty dependency level
+ priorityStack.pop_back();
+
+ // Reverse iterate over the different dependency levels (deepest first).
+ // Sort tests within each level by COST and append them to the cost list.
+ for(std::list<TestSet>::reverse_iterator i = priorityStack.rbegin();
+ i != priorityStack.rend(); ++i)
+ {
+ TestSet const& currentSet = *i;
+ TestComparator comp(this);
+
+ TestList sortedCopy;
+
+ for(TestSet::const_iterator j = currentSet.begin();
+ j != currentSet.end(); ++j)
+ {
+ sortedCopy.push_back(*j);
+ }
+
+ std::stable_sort(sortedCopy.begin(), sortedCopy.end(), comp);
+
+ for(TestList::const_iterator j = sortedCopy.begin();
+ j != sortedCopy.end(); ++j)
+ {
+ if(alreadySortedTests.find(*j) == alreadySortedTests.end())
+ {
+ this->SortedTests.push_back(*j);
+ alreadySortedTests.insert(*j);
+ }
+ }
+ }
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::GetAllTestDependencies(
+ int test, TestList& dependencies)
+{
+ TestSet const& dependencySet = this->Tests[test];
+ for(TestSet::const_iterator i = dependencySet.begin();
+ i != dependencySet.end(); ++i)
+ {
+ GetAllTestDependencies(*i, dependencies);
+ dependencies.push_back(*i);
+ }
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::CreateSerialTestCostList()
+{
+ TestList presortedList;
+
+ for(TestMap::iterator i = this->Tests.begin();
+ i != this->Tests.end(); ++i)
+ {
+ presortedList.push_back(i->first);
+ }
+
+ TestComparator comp(this);
+ std::stable_sort(presortedList.begin(), presortedList.end(), comp);
+
+ TestSet alreadySortedTests;
+
+ for(TestList::const_iterator i = presortedList.begin();
+ i != presortedList.end(); ++i)
+ {
+ int test = *i;
+
+ if(alreadySortedTests.find(test) != alreadySortedTests.end())
+ {
+ continue;
+ }
+
+ TestList dependencies;
+ GetAllTestDependencies(test, dependencies);
+
+ for(TestList::const_iterator j = dependencies.begin();
+ j != dependencies.end(); ++j)
+ {
+ int testDependency = *j;
+
+ if(alreadySortedTests.find(testDependency) == alreadySortedTests.end())
+ {
+ alreadySortedTests.insert(testDependency);
+ this->SortedTests.push_back(testDependency);
+ }
+ }
+
+ alreadySortedTests.insert(test);
+ this->SortedTests.push_back(test);
+ }
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::WriteCheckpoint(int index)
+{
+ std::string fname = this->CTest->GetBinaryDir()
+ + "/Testing/Temporary/CTestCheckpoint.txt";
+ cmsys::ofstream fout;
+ fout.open(fname.c_str(), std::ios::app);
+ fout << index << "\n";
+ fout.close();
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::MarkFinished()
+{
+ std::string fname = this->CTest->GetBinaryDir()
+ + "/Testing/Temporary/CTestCheckpoint.txt";
+ cmSystemTools::RemoveFile(fname.c_str());
+}
+
+//---------------------------------------------------------
+//For ShowOnly mode
+void cmCTestMultiProcessHandler::PrintTestList()
+{
+ this->TestHandler->SetMaxIndex(this->FindMaxIndex());
+ int count = 0;
+
+ for (PropertiesMap::iterator it = this->Properties.begin();
+ it != this->Properties.end(); ++it)
+ {
+ count++;
+ cmCTestTestHandler::cmCTestTestProperties& p = *it->second;
+
+ //push working dir
+ std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(p.Directory.c_str());
+
+ cmCTestRunTest testRun(this->TestHandler);
+ testRun.SetIndex(p.Index);
+ testRun.SetTestProperties(&p);
+ testRun.ComputeArguments(); //logs the command in verbose mode
+
+ if(p.Labels.size()) //print the labels
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Labels:");
+ }
+ for(std::vector<std::string>::iterator label = p.Labels.begin();
+ label != p.Labels.end(); ++label)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " " << *label);
+ }
+ if(p.Labels.size()) //print the labels
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
+ }
+
+ if (this->TestHandler->MemCheck)
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Memory Check");
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Test");
+ }
+ cmOStringStream indexStr;
+ indexStr << " #" << p.Index << ":";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
+ << indexStr.str());
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, p.Name.c_str() << std::endl);
+ //pop working dir
+ cmSystemTools::ChangeDirectory(current_dir.c_str());
+ }
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl << "Total Tests: "
+ << this->Total << std::endl);
+}
+
+void cmCTestMultiProcessHandler::PrintLabels()
+{
+ std::set<std::string> allLabels;
+ for (PropertiesMap::iterator it = this->Properties.begin();
+ it != this->Properties.end(); ++it)
+ {
+ cmCTestTestHandler::cmCTestTestProperties& p = *it->second;
+ allLabels.insert(p.Labels.begin(), p.Labels.end());
+ }
+
+ if(allLabels.size())
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "All Labels:" << std::endl);
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "No Labels Exist" << std::endl);
+ }
+ for(std::set<std::string>::iterator label = allLabels.begin();
+ label != allLabels.end(); ++label)
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << *label << std::endl);
+ }
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::CheckResume()
+{
+ std::string fname = this->CTest->GetBinaryDir()
+ + "/Testing/Temporary/CTestCheckpoint.txt";
+ if(this->CTest->GetFailover())
+ {
+ if(cmSystemTools::FileExists(fname.c_str(), true))
+ {
+ *this->TestHandler->LogFile << "Resuming previously interrupted test set"
+ << std::endl
+ << "----------------------------------------------------------"
+ << std::endl;
+
+ cmsys::ifstream fin;
+ fin.open(fname.c_str());
+ std::string line;
+ while(std::getline(fin, line))
+ {
+ int index = atoi(line.c_str());
+ this->RemoveTest(index);
+ }
+ fin.close();
+ }
+ }
+ else if(cmSystemTools::FileExists(fname.c_str(), true))
+ {
+ cmSystemTools::RemoveFile(fname.c_str());
+ }
+}
+
+//---------------------------------------------------------
+void cmCTestMultiProcessHandler::RemoveTest(int index)
+{
+ this->EraseTest(index);
+ this->Properties.erase(index);
+ this->TestRunningMap[index] = false;
+ this->TestFinishMap[index] = true;
+ this->Completed++;
+}
+
+//---------------------------------------------------------
+int cmCTestMultiProcessHandler::FindMaxIndex()
+{
+ int max = 0;
+ cmCTestMultiProcessHandler::TestMap::iterator i = this->Tests.begin();
+ for(; i != this->Tests.end(); ++i)
+ {
+ if(i->first > max)
+ {
+ max = i->first;
+ }
+ }
+ return max;
+}
+
+//Returns true if no cycles exist in the dependency graph
+bool cmCTestMultiProcessHandler::CheckCycles()
+{
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Checking test dependency graph..." << std::endl);
+ for(TestMap::iterator it = this->Tests.begin();
+ it != this->Tests.end(); ++it)
+ {
+ //DFS from each element to itself
+ int root = it->first;
+ std::set<int> visited;
+ std::stack<int> s;
+ s.push(root);
+ while(!s.empty())
+ {
+ int test = s.top();
+ s.pop();
+ if(visited.insert(test).second)
+ {
+ for(TestSet::iterator d = this->Tests[test].begin();
+ d != this->Tests[test].end(); ++d)
+ {
+ if(*d == root)
+ {
+ //cycle exists
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error: a cycle exists in the test dependency graph "
+ "for the test \"" << this->Properties[root]->Name <<
+ "\".\nPlease fix the cycle and run ctest again.\n");
+ return false;
+ }
+ else
+ {
+ s.push(*d);
+ }
+ }
+ }
+ }
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Checking test dependency graph end" << std::endl);
+ return true;
+}
diff --git a/Source/CTest/cmCTestMultiProcessHandler.h b/Source/CTest/cmCTestMultiProcessHandler.h
new file mode 100644
index 0000000000..605de31346
--- /dev/null
+++ b/Source/CTest/cmCTestMultiProcessHandler.h
@@ -0,0 +1,123 @@
+/*============================================================================
+ 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 cmCTestMultiProcessHandler_h
+#define cmCTestMultiProcessHandler_h
+
+#include <cmStandardIncludes.h>
+#include <cmCTestTestHandler.h>
+#include <cmCTestRunTest.h>
+
+/** \class cmCTestMultiProcessHandler
+ * \brief run parallel ctest
+ *
+ * cmCTestMultiProcessHandler
+ */
+class cmCTestMultiProcessHandler
+{
+ friend class TestComparator;
+public:
+ struct TestSet : public std::set<int> {};
+ struct TestMap : public std::map<int, TestSet> {};
+ struct TestList : public std::vector<int> {};
+ struct PropertiesMap : public
+ std::map<int, cmCTestTestHandler::cmCTestTestProperties*> {};
+
+ cmCTestMultiProcessHandler();
+ virtual ~cmCTestMultiProcessHandler();
+ // Set the tests
+ void SetTests(TestMap& tests, PropertiesMap& properties);
+ // Set the max number of tests that can be run at the same time.
+ void SetParallelLevel(size_t);
+ virtual void RunTests();
+ void PrintTestList();
+ void PrintLabels();
+
+ void SetPassFailVectors(std::vector<std::string>* passed,
+ std::vector<std::string>* failed)
+ {
+ this->Passed = passed;
+ this->Failed = failed;
+ }
+ void SetTestResults(std::vector<cmCTestTestHandler::cmCTestTestResult>* r)
+ { this->TestResults = r; }
+
+ void SetCTest(cmCTest* ctest) { this->CTest = ctest;}
+
+ void SetTestHandler(cmCTestTestHandler * handler)
+ { this->TestHandler = handler; }
+
+ cmCTestTestHandler * GetTestHandler()
+ { return this->TestHandler; }
+protected:
+ // Start the next test or tests as many as are allowed by
+ // ParallelLevel
+ void StartNextTests();
+ void StartTestProcess(int test);
+ bool StartTest(int test);
+ // Mark the checkpoint for the given test
+ void WriteCheckpoint(int index);
+
+ void UpdateCostData();
+ void ReadCostData();
+ // Return index of a test based on its name
+ int SearchByName(std::string name);
+
+ void CreateTestCostList();
+
+ void GetAllTestDependencies(int test, TestList& dependencies);
+ void CreateSerialTestCostList();
+
+ void CreateParallelTestCostList();
+
+ // Removes the checkpoint file
+ void MarkFinished();
+ void EraseTest(int index);
+ // Return true if there are still tests running
+ // check all running processes for output and exit case
+ bool CheckOutput();
+ void RemoveTest(int index);
+ //Check if we need to resume an interrupted test set
+ void CheckResume();
+ //Check if there are any circular dependencies
+ bool CheckCycles();
+ int FindMaxIndex();
+ inline size_t GetProcessorsUsed(int index);
+
+ void LockResources(int index);
+ void UnlockResources(int index);
+ // map from test number to set of depend tests
+ TestMap Tests;
+ TestList SortedTests;
+ //Total number of tests we'll be running
+ size_t Total;
+ //Number of tests that are complete
+ size_t Completed;
+ size_t RunningCount;
+ bool StopTimePassed;
+ //list of test properties (indices concurrent to the test map)
+ PropertiesMap Properties;
+ std::map<int, bool> TestRunningMap;
+ std::map<int, bool> TestFinishMap;
+ std::map<int, std::string> TestOutput;
+ std::vector<std::string>* Passed;
+ std::vector<std::string>* Failed;
+ std::vector<std::string> LastTestsFailed;
+ std::set<std::string> LockedResources;
+ std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults;
+ size_t ParallelLevel; // max number of process that can be run at once
+ std::set<cmCTestRunTest*> RunningTests; // current running tests
+ cmCTestTestHandler * TestHandler;
+ cmCTest* CTest;
+ bool HasCycles;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx
new file mode 100644
index 0000000000..0bb1a99608
--- /dev/null
+++ b/Source/CTest/cmCTestP4.cxx
@@ -0,0 +1,568 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 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 "cmCTestP4.h"
+
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/ios/sstream>
+#include <cmsys/Process.h>
+
+#include <sys/types.h>
+#include <time.h>
+#include <ctype.h>
+
+//----------------------------------------------------------------------------
+cmCTestP4::cmCTestP4(cmCTest* ct, std::ostream& log):
+ cmCTestGlobalVC(ct, log)
+{
+ this->PriorRev = this->Unknown;
+}
+
+//----------------------------------------------------------------------------
+cmCTestP4::~cmCTestP4()
+{
+}
+
+//----------------------------------------------------------------------------
+class cmCTestP4::IdentifyParser: public cmCTestVC::LineParser
+{
+public:
+ IdentifyParser(cmCTestP4* p4, const char* prefix,
+ std::string& rev): Rev(rev)
+ {
+ this->SetLog(&p4->Log, prefix);
+ this->RegexIdentify.compile("^Change ([0-9]+) on");
+ }
+private:
+ std::string& Rev;
+ cmsys::RegularExpression RegexIdentify;
+
+ bool ProcessLine()
+ {
+ if(this->RegexIdentify.find(this->Line))
+ {
+ this->Rev = this->RegexIdentify.match(1);
+ return false;
+ }
+ return true;
+ }
+};
+
+//----------------------------------------------------------------------------
+class cmCTestP4::ChangesParser: public cmCTestVC::LineParser
+{
+public:
+ ChangesParser(cmCTestP4* p4, const char* prefix) : P4(p4)
+ {
+ this->SetLog(&P4->Log, prefix);
+ this->RegexIdentify.compile("^Change ([0-9]+) on");
+ }
+private:
+ cmsys::RegularExpression RegexIdentify;
+ cmCTestP4* P4;
+
+ bool ProcessLine()
+ {
+ if(this->RegexIdentify.find(this->Line))
+ {
+ P4->ChangeLists.push_back(this->RegexIdentify.match(1));
+ }
+ return true;
+ }
+};
+
+//----------------------------------------------------------------------------
+class cmCTestP4::UserParser: public cmCTestVC::LineParser
+{
+public:
+ UserParser(cmCTestP4* p4, const char* prefix) : P4(p4)
+ {
+ this->SetLog(&P4->Log, prefix);
+ this->RegexUser.compile("^(.+) <(.*)> \\((.*)\\) accessed (.*)$");
+ }
+private:
+ cmsys::RegularExpression RegexUser;
+ cmCTestP4* P4;
+
+ bool ProcessLine()
+ {
+ if(this->RegexUser.find(this->Line))
+ {
+ User NewUser;
+
+ NewUser.UserName = this->RegexUser.match(1);
+ NewUser.EMail = this->RegexUser.match(2);
+ NewUser.Name = this->RegexUser.match(3);
+ NewUser.AccessTime = this->RegexUser.match(4);
+ P4->Users[this->RegexUser.match(1)] = NewUser;
+
+ return false;
+ }
+ return true;
+ }
+};
+
+//----------------------------------------------------------------------------
+/* Diff format:
+==== //depot/file#rev - /absolute/path/to/file ====
+(diff data)
+==== //depot/file2#rev - /absolute/path/to/file2 ====
+(diff data)
+==== //depot/file3#rev - /absolute/path/to/file3 ====
+==== //depot/file4#rev - /absolute/path/to/file4 ====
+(diff data)
+*/
+class cmCTestP4::DiffParser: public cmCTestVC::LineParser
+{
+public:
+ DiffParser(cmCTestP4* p4, const char* prefix)
+ : P4(p4), AlreadyNotified(false)
+ {
+ this->SetLog(&P4->Log, prefix);
+ this->RegexDiff.compile("^==== (.*)#[0-9]+ - (.*)");
+ }
+private:
+ cmCTestP4* P4;
+ bool AlreadyNotified;
+ std::string CurrentPath;
+ cmsys::RegularExpression RegexDiff;
+
+ bool ProcessLine()
+ {
+ if(!this->Line.empty() && this->Line[0] == '='
+ && this->RegexDiff.find(this->Line))
+ {
+ CurrentPath = this->RegexDiff.match(1);
+ AlreadyNotified = false;
+ }
+ else
+ {
+ if(!AlreadyNotified)
+ {
+ P4->DoModification(PathModified, CurrentPath);
+ AlreadyNotified = true;
+ }
+ }
+ return true;
+ }
+};
+
+//----------------------------------------------------------------------------
+cmCTestP4::User cmCTestP4::GetUserData(const std::string& username)
+{
+ std::map<std::string, cmCTestP4::User>::const_iterator it =
+ Users.find(username);
+
+ if(it == Users.end())
+ {
+ std::vector<char const*> p4_users;
+ SetP4Options(p4_users);
+ p4_users.push_back("users");
+ p4_users.push_back("-m");
+ p4_users.push_back("1");
+ p4_users.push_back(username.c_str());
+ p4_users.push_back(0);
+
+ UserParser out(this, "users-out> ");
+ OutputLogger err(this->Log, "users-err> ");
+ RunChild(&p4_users[0], &out, &err);
+
+ // The user should now be added to the map. Search again.
+ it = Users.find(username);
+ if(it == Users.end())
+ {
+ return cmCTestP4::User();
+ }
+ }
+
+ return it->second;
+}
+
+//----------------------------------------------------------------------------
+/* Commit format:
+
+Change 1111111 by user@client on 2013/09/26 11:50:36
+
+ text
+ text
+
+Affected files ...
+
+... //path/to/file#rev edit
+... //path/to/file#rev add
+... //path/to/file#rev delete
+... //path/to/file#rev integrate
+*/
+class cmCTestP4::DescribeParser: public cmCTestVC::LineParser
+{
+public:
+ DescribeParser(cmCTestP4* p4, const char* prefix):
+ LineParser('\n', false), P4(p4), Section(SectionHeader)
+ {
+ this->SetLog(&P4->Log, prefix);
+ this->RegexHeader.compile("^Change ([0-9]+) by (.+)@(.+) on (.*)$");
+ this->RegexDiff.compile("^\\.\\.\\. (.*)#[0-9]+ ([^ ]+)$");
+ }
+private:
+ cmsys::RegularExpression RegexHeader;
+ cmsys::RegularExpression RegexDiff;
+ cmCTestP4* P4;
+
+ typedef cmCTestP4::Revision Revision;
+ typedef cmCTestP4::Change Change;
+ std::vector<Change> Changes;
+ enum SectionType { SectionHeader, SectionBody, SectionDiffHeader,
+ SectionDiff, SectionCount };
+ SectionType Section;
+ Revision Rev;
+
+ virtual bool ProcessLine()
+ {
+ if(this->Line.empty())
+ {
+ this->NextSection();
+ }
+ else
+ {
+ switch(this->Section)
+ {
+ case SectionHeader: this->DoHeaderLine(); break;
+ case SectionBody: this->DoBodyLine(); break;
+ case SectionDiffHeader: break; // nothing to do
+ case SectionDiff: this->DoDiffLine(); break;
+ case SectionCount: break; // never happens
+ }
+ }
+ return true;
+ }
+
+ void NextSection()
+ {
+ if(this->Section == SectionDiff)
+ {
+ this->P4->DoRevision(this->Rev, this->Changes);
+ this->Rev = Revision();
+ }
+
+ this->Section = SectionType((this->Section+1) % SectionCount);
+ }
+
+ void DoHeaderLine()
+ {
+ if(this->RegexHeader.find(this->Line))
+ {
+ this->Rev.Rev = this->RegexHeader.match(1);
+ this->Rev.Date = this->RegexHeader.match(4);
+
+ cmCTestP4::User user = P4->GetUserData(this->RegexHeader.match(2));
+ this->Rev.Author = user.Name;
+ this->Rev.EMail = user.EMail;
+
+ this->Rev.Committer = this->Rev.Author;
+ this->Rev.CommitterEMail = this->Rev.EMail;
+ this->Rev.CommitDate = this->Rev.Date;
+ }
+ }
+
+ void DoBodyLine()
+ {
+ if(this->Line[0] == '\t')
+ {
+ this->Rev.Log += this->Line.substr(1);
+ }
+ this->Rev.Log += "\n";
+ }
+
+ void DoDiffLine()
+ {
+ if(this->RegexDiff.find(this->Line))
+ {
+ Change change;
+ std::string Path = this->RegexDiff.match(1);
+ if(Path.length() > 2 && Path[0] == '/' && Path[1] == '/')
+ {
+ size_t found = Path.find('/', 2);
+ if(found != std::string::npos)
+ {
+ Path = Path.substr(found + 1);
+ }
+ }
+
+ change.Path = Path;
+ std::string action = this->RegexDiff.match(2);
+
+ if(action == "add")
+ {
+ change.Action = 'A';
+ }
+ else if(action == "delete")
+ {
+ change.Action = 'D';
+ }
+ else if(action == "edit" || action == "integrate")
+ {
+ change.Action = 'M';
+ }
+
+ Changes.push_back(change);
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmCTestP4::SetP4Options(std::vector<char const*> &CommandOptions)
+{
+ if(P4Options.size() == 0)
+ {
+ const char* p4 = this->CommandLineTool.c_str();
+ P4Options.push_back(p4);
+
+ //The CTEST_P4_CLIENT variable sets the P4 client used when issuing
+ //Perforce commands, if it's different from the default one.
+ std::string client = this->CTest->GetCTestConfiguration("P4Client");
+ if(!client.empty())
+ {
+ P4Options.push_back("-c");
+ P4Options.push_back(client);
+ }
+
+ //Set the message language to be English, in case the P4 admin
+ //has localized them
+ P4Options.push_back("-L");
+ P4Options.push_back("en");
+
+ //The CTEST_P4_OPTIONS variable adds additional Perforce command line
+ //options before the main command
+ std::string opts = this->CTest->GetCTestConfiguration("P4Options");
+ std::vector<std::string> args =
+ cmSystemTools::ParseArguments(opts.c_str());
+
+ for(std::vector<std::string>::const_iterator ai = args.begin();
+ ai != args.end(); ++ai)
+ {
+ P4Options.push_back(*ai);
+ }
+ }
+
+ CommandOptions.clear();
+ for(std::vector<std::string>::iterator i = P4Options.begin();
+ i != P4Options.end(); ++i)
+ {
+ CommandOptions.push_back(i->c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTestP4::GetWorkingRevision()
+{
+ std::vector<char const*> p4_identify;
+ SetP4Options(p4_identify);
+
+ p4_identify.push_back("changes");
+ p4_identify.push_back("-m");
+ p4_identify.push_back("1");
+ p4_identify.push_back("-t");
+
+ std::string source = this->SourceDirectory + "/...#have";
+ p4_identify.push_back(source.c_str());
+ p4_identify.push_back(0);
+
+ std::string rev;
+ IdentifyParser out(this, "p4_changes-out> ", rev);
+ OutputLogger err(this->Log, "p4_changes-err> ");
+
+ bool result = RunChild(&p4_identify[0], &out, &err);
+
+ // If there was a problem contacting the server return "<unknown>"
+ if(!result)
+ {
+ return "<unknown>";
+ }
+
+ if(rev.empty())
+ {
+ return "0";
+ }
+ else
+ {
+ return rev;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestP4::NoteOldRevision()
+{
+ this->OldRevision = this->GetWorkingRevision();
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
+ << this->OldRevision << "\n");
+ this->PriorRev.Rev = this->OldRevision;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestP4::NoteNewRevision()
+{
+ this->NewRevision = this->GetWorkingRevision();
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
+ << this->NewRevision << "\n");
+}
+
+//----------------------------------------------------------------------------
+void cmCTestP4::LoadRevisions()
+{
+ std::vector<char const*> p4_changes;
+ SetP4Options(p4_changes);
+
+ // Use 'p4 changes ...@old,new' to get a list of changelists
+ std::string range = this->SourceDirectory + "/...";
+
+ // If any revision is unknown it means we couldn't contact the server.
+ // Do not process updates
+ if(this->OldRevision == "<unknown>" || this->NewRevision == "<unknown>")
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " At least one of the revisions "
+ << "is unknown. No repository changes will be reported.\n");
+ return;
+ }
+
+ range.append("@").append(this->OldRevision)
+ .append(",").append(this->NewRevision);
+
+ p4_changes.push_back("changes");
+ p4_changes.push_back(range.c_str());
+ p4_changes.push_back(0);
+
+ ChangesParser out(this, "p4_changes-out> ");
+ OutputLogger err(this->Log, "p4_changes-err> ");
+
+ ChangeLists.clear();
+ this->RunChild(&p4_changes[0], &out, &err);
+
+ if(ChangeLists.size() == 0)
+ return;
+
+ //p4 describe -s ...@1111111,2222222
+ std::vector<char const*> p4_describe;
+ for(std::vector<std::string>::reverse_iterator i = ChangeLists.rbegin();
+ i != ChangeLists.rend(); ++i)
+ {
+ SetP4Options(p4_describe);
+ p4_describe.push_back("describe");
+ p4_describe.push_back("-s");
+ p4_describe.push_back(i->c_str());
+ p4_describe.push_back(0);
+
+ DescribeParser outDescribe(this, "p4_describe-out> ");
+ OutputLogger errDescribe(this->Log, "p4_describe-err> ");
+ this->RunChild(&p4_describe[0], &outDescribe, &errDescribe);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestP4::LoadModifications()
+{
+ std::vector<char const*> p4_diff;
+ SetP4Options(p4_diff);
+
+ p4_diff.push_back("diff");
+
+ //Ideally we would use -Od but not all clients support it
+ p4_diff.push_back("-dn");
+ std::string source = this->SourceDirectory + "/...";
+ p4_diff.push_back(source.c_str());
+ p4_diff.push_back(0);
+
+ DiffParser out(this, "p4_diff-out> ");
+ OutputLogger err(this->Log, "p4_diff-err> ");
+ this->RunChild(&p4_diff[0], &out, &err);
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestP4::UpdateCustom(const std::string& custom)
+{
+ std::vector<std::string> p4_custom_command;
+ cmSystemTools::ExpandListArgument(custom, p4_custom_command, true);
+
+ std::vector<char const*> p4_custom;
+ for(std::vector<std::string>::const_iterator
+ i = p4_custom_command.begin(); i != p4_custom_command.end(); ++i)
+ {
+ p4_custom.push_back(i->c_str());
+ }
+ p4_custom.push_back(0);
+
+ OutputLogger custom_out(this->Log, "p4_customsync-out> ");
+ OutputLogger custom_err(this->Log, "p4_customsync-err> ");
+
+ return this->RunUpdateCommand(&p4_custom[0], &custom_out, &custom_err);
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestP4::UpdateImpl()
+{
+ std::string custom = this->CTest->GetCTestConfiguration("P4UpdateCustom");
+ if(!custom.empty())
+ {
+ return this->UpdateCustom(custom);
+ }
+
+ // If we couldn't get a revision number before updating, abort.
+ if(this->OldRevision == "<unknown>")
+ {
+ this->UpdateCommandLine = "Unknown current revision";
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Unknown current revision\n");
+ return false;
+ }
+
+ std::vector<char const*> p4_sync;
+ SetP4Options(p4_sync);
+
+ p4_sync.push_back("sync");
+
+ // Get user-specified update options.
+ std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
+ if(opts.empty())
+ {
+ opts = this->CTest->GetCTestConfiguration("P4UpdateOptions");
+ }
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
+ for(std::vector<std::string>::const_iterator ai = args.begin();
+ ai != args.end(); ++ai)
+ {
+ p4_sync.push_back(ai->c_str());
+ }
+
+ std::string source = this->SourceDirectory + "/...";
+
+ // Specify the start time for nightly testing.
+ if(this->CTest->GetTestModel() == cmCTest::NIGHTLY)
+ {
+ std::string date = this->GetNightlyTime();
+ //CTest reports the date as YYYY-MM-DD, Perforce needs it as YYYY/MM/DD
+ std::replace(date.begin(), date.end(), '-', '/');
+
+ //Revision specification: /...@"YYYY/MM/DD HH:MM:SS"
+ source.append("@\"").append(date).append("\"");
+ }
+
+ p4_sync.push_back(source.c_str());
+ p4_sync.push_back(0);
+
+ OutputLogger out(this->Log, "p4_sync-out> ");
+ OutputLogger err(this->Log, "p4_sync-err> ");
+
+ return this->RunUpdateCommand(&p4_sync[0], &out, &err);
+}
diff --git a/Source/CTest/cmCTestP4.h b/Source/CTest/cmCTestP4.h
new file mode 100644
index 0000000000..7a53475fd8
--- /dev/null
+++ b/Source/CTest/cmCTestP4.h
@@ -0,0 +1,71 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 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 cmCTestP4_h
+#define cmCTestP4_h
+
+#include "cmCTestGlobalVC.h"
+#include <vector>
+#include <map>
+
+/** \class cmCTestP4
+ * \brief Interaction with the Perforce command-line tool
+ *
+ */
+class cmCTestP4: public cmCTestGlobalVC
+{
+public:
+ /** Construct with a CTest instance and update log stream. */
+ cmCTestP4(cmCTest* ctest, std::ostream& log);
+
+ virtual ~cmCTestP4();
+
+private:
+ std::vector<std::string> ChangeLists;
+
+ struct User
+ {
+ std::string UserName;
+ std::string Name;
+ std::string EMail;
+ std::string AccessTime;
+
+ User(): UserName(), Name(), EMail(), AccessTime() {}
+ };
+ std::map<std::string, User> Users;
+ std::vector<std::string> P4Options;
+
+ User GetUserData(const std::string& username);
+ void SetP4Options(std::vector<char const*> &options);
+
+ std::string GetWorkingRevision();
+ virtual void NoteOldRevision();
+ virtual void NoteNewRevision();
+ virtual bool UpdateImpl();
+ bool UpdateCustom(const std::string& custom);
+
+ void LoadRevisions();
+ void LoadModifications();
+
+ // Parsing helper classes.
+ class IdentifyParser;
+ class ChangesParser;
+ class UserParser;
+ class DescribeParser;
+ class DiffParser;
+ friend class IdentifyParser;
+ friend class ChangesParser;
+ friend class UserParser;
+ friend class DescribeParser;
+ friend class DiffParser;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestReadCustomFilesCommand.cxx b/Source/CTest/cmCTestReadCustomFilesCommand.cxx
new file mode 100644
index 0000000000..3b9d5527a8
--- /dev/null
+++ b/Source/CTest/cmCTestReadCustomFilesCommand.cxx
@@ -0,0 +1,34 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestReadCustomFilesCommand.h"
+#include "cmCTest.h"
+
+bool cmCTestReadCustomFilesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if (args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::vector<std::string>::const_iterator dit;
+ for ( dit = args.begin(); dit != args.end(); ++ dit )
+ {
+ this->CTest->ReadCustomConfigurationFileTree(dit->c_str(),
+ this->Makefile);
+ }
+
+ return true;
+}
+
+
diff --git a/Source/CTest/cmCTestReadCustomFilesCommand.h b/Source/CTest/cmCTestReadCustomFilesCommand.h
new file mode 100644
index 0000000000..c95694ae57
--- /dev/null
+++ b/Source/CTest/cmCTestReadCustomFilesCommand.h
@@ -0,0 +1,56 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestReadCustomFilesCommand_h
+#define cmCTestReadCustomFilesCommand_h
+
+#include "cmCTestCommand.h"
+
+/** \class cmCTestReadCustomFiles
+ * \brief Run a ctest script
+ *
+ * cmLibrarysCommand defines a list of executable (i.e., test)
+ * programs to create.
+ */
+class cmCTestReadCustomFilesCommand : public cmCTestCommand
+{
+public:
+
+ cmCTestReadCustomFilesCommand() {}
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestReadCustomFilesCommand* ni = new cmCTestReadCustomFilesCommand;
+ ni->CTest = this->CTest;
+ return ni;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_read_custom_files";}
+
+ cmTypeMacro(cmCTestReadCustomFilesCommand, cmCTestCommand);
+
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestRunScriptCommand.cxx b/Source/CTest/cmCTestRunScriptCommand.cxx
new file mode 100644
index 0000000000..bdf9b9cae9
--- /dev/null
+++ b/Source/CTest/cmCTestRunScriptCommand.cxx
@@ -0,0 +1,65 @@
+/*============================================================================
+ 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 "cmCTestRunScriptCommand.h"
+
+#include "cmCTestScriptHandler.h"
+
+bool cmCTestRunScriptCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->CTestScriptHandler->RunCurrentScript();
+ return true;
+ }
+
+ bool np = false;
+ unsigned int i = 0;
+ if (args[i] == "NEW_PROCESS")
+ {
+ np = true;
+ i++;
+ }
+ int start = i;
+ // run each script
+ std::string returnVariable;
+ for (i = start; i < args.size(); ++i)
+ {
+ if(args[i] == "RETURN_VALUE")
+ {
+ ++i;
+ if(i < args.size())
+ {
+ returnVariable = args[i];
+ }
+ }
+ }
+ for (i = start; i < args.size(); ++i)
+ {
+ if(args[i] == "RETURN_VALUE")
+ {
+ ++i;
+ }
+ else
+ {
+ int ret;
+ cmCTestScriptHandler::RunScript(this->CTest, args[i].c_str(), !np,
+ &ret);
+ cmOStringStream str;
+ str << ret;
+ this->Makefile->AddDefinition(returnVariable, str.str().c_str());
+ }
+ }
+ return true;
+}
+
+
diff --git a/Source/CTest/cmCTestRunScriptCommand.h b/Source/CTest/cmCTestRunScriptCommand.h
new file mode 100644
index 0000000000..0998e5c621
--- /dev/null
+++ b/Source/CTest/cmCTestRunScriptCommand.h
@@ -0,0 +1,56 @@
+/*============================================================================
+ 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 cmCTestRunScriptCommand_h
+#define cmCTestRunScriptCommand_h
+
+#include "cmCTestCommand.h"
+
+/** \class cmCTestRunScript
+ * \brief Run a ctest script
+ *
+ * cmLibrarysCommand defines a list of executable (i.e., test)
+ * programs to create.
+ */
+class cmCTestRunScriptCommand : public cmCTestCommand
+{
+public:
+
+ cmCTestRunScriptCommand() {}
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestRunScriptCommand* ni = new cmCTestRunScriptCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_run_script";}
+
+ cmTypeMacro(cmCTestRunScriptCommand, cmCTestCommand);
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx
new file mode 100644
index 0000000000..bdd8c0247f
--- /dev/null
+++ b/Source/CTest/cmCTestRunTest.cxx
@@ -0,0 +1,736 @@
+/*============================================================================
+ 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 "cmCTestRunTest.h"
+#include "cmCTestMemCheckHandler.h"
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include "cm_curl.h"
+
+#include <cm_zlib.h>
+#include <cmsys/Base64.h>
+
+cmCTestRunTest::cmCTestRunTest(cmCTestTestHandler* handler)
+{
+ this->CTest = handler->CTest;
+ this->TestHandler = handler;
+ this->TestProcess = 0;
+ this->TestResult.ExecutionTime =0;
+ this->TestResult.ReturnValue = 0;
+ this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
+ this->TestResult.TestCount = 0;
+ this->TestResult.Properties = 0;
+ this->ProcessOutput = "";
+ this->CompressedOutput = "";
+ this->CompressionRatio = 2;
+ this->StopTimePassed = false;
+}
+
+cmCTestRunTest::~cmCTestRunTest()
+{
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestRunTest::CheckOutput()
+{
+ // Read lines for up to 0.1 seconds of total time.
+ double timeout = 0.1;
+ double timeEnd = cmSystemTools::GetTime() + timeout;
+ std::string line;
+ while((timeout = timeEnd - cmSystemTools::GetTime(), timeout > 0))
+ {
+ int p = this->TestProcess->GetNextOutputLine(line, timeout);
+ if(p == cmsysProcess_Pipe_None)
+ {
+ // Process has terminated and all output read.
+ return false;
+ }
+ else if(p == cmsysProcess_Pipe_STDOUT ||
+ p == cmsysProcess_Pipe_STDERR)
+ {
+ // Store this line of output.
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ this->GetIndex() << ": " << line << std::endl);
+ this->ProcessOutput += line;
+ this->ProcessOutput += "\n";
+ }
+ else // if(p == cmsysProcess_Pipe_Timeout)
+ {
+ break;
+ }
+ }
+ return true;
+}
+
+//---------------------------------------------------------
+// Streamed compression of test output. The compressed data
+// is appended to this->CompressedOutput
+void cmCTestRunTest::CompressOutput()
+{
+ int ret;
+ z_stream strm;
+
+ unsigned char* in =
+ reinterpret_cast<unsigned char*>(
+ const_cast<char*>(this->ProcessOutput.c_str()));
+ //zlib makes the guarantee that this is the maximum output size
+ int outSize = static_cast<int>(
+ static_cast<double>(this->ProcessOutput.size()) * 1.001 + 13.0);
+ unsigned char* out = new unsigned char[outSize];
+
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ ret = deflateInit(&strm, -1); //default compression level
+ if (ret != Z_OK)
+ {
+ delete[] out;
+ return;
+ }
+
+ strm.avail_in = static_cast<uInt>(this->ProcessOutput.size());
+ strm.next_in = in;
+ strm.avail_out = outSize;
+ strm.next_out = out;
+ ret = deflate(&strm, Z_FINISH);
+
+ if(ret == Z_STREAM_ERROR || ret != Z_STREAM_END)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Error during output "
+ "compression. Sending uncompressed output." << std::endl);
+ delete[] out;
+ return;
+ }
+
+ (void)deflateEnd(&strm);
+
+ unsigned char *encoded_buffer
+ = new unsigned char[static_cast<int>(outSize * 1.5)];
+
+ unsigned long rlen
+ = cmsysBase64_Encode(out, strm.total_out, encoded_buffer, 1);
+
+ for(unsigned long i = 0; i < rlen; i++)
+ {
+ this->CompressedOutput += encoded_buffer[i];
+ }
+
+ if(strm.total_in)
+ {
+ this->CompressionRatio = static_cast<double>(strm.total_out) /
+ static_cast<double>(strm.total_in);
+ }
+
+ delete [] encoded_buffer;
+ delete [] out;
+}
+
+//---------------------------------------------------------
+bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
+{
+ if ((!this->TestHandler->MemCheck &&
+ this->CTest->ShouldCompressTestOutput()) ||
+ (this->TestHandler->MemCheck &&
+ this->CTest->ShouldCompressMemCheckOutput()))
+ {
+ this->CompressOutput();
+ }
+
+ this->WriteLogOutputTop(completed, total);
+ std::string reason;
+ bool passed = true;
+ int res = started ? this->TestProcess->GetProcessStatus()
+ : cmsysProcess_State_Error;
+ int retVal = this->TestProcess->GetExitValue();
+ std::vector<std::pair<cmsys::RegularExpression,
+ std::string> >::iterator passIt;
+ bool forceFail = false;
+ bool outputTestErrorsToConsole = false;
+ if ( this->TestProperties->RequiredRegularExpressions.size() > 0 )
+ {
+ bool found = false;
+ for ( passIt = this->TestProperties->RequiredRegularExpressions.begin();
+ passIt != this->TestProperties->RequiredRegularExpressions.end();
+ ++ passIt )
+ {
+ if ( passIt->first.find(this->ProcessOutput.c_str()) )
+ {
+ found = true;
+ reason = "Required regular expression found.";
+ break;
+ }
+ }
+ if ( !found )
+ {
+ reason = "Required regular expression not found.";
+ forceFail = true;
+ }
+ reason += "Regex=[";
+ for ( passIt = this->TestProperties->RequiredRegularExpressions.begin();
+ passIt != this->TestProperties->RequiredRegularExpressions.end();
+ ++ passIt )
+ {
+ reason += passIt->second;
+ reason += "\n";
+ }
+ reason += "]";
+ }
+ if ( this->TestProperties->ErrorRegularExpressions.size() > 0 )
+ {
+ for ( passIt = this->TestProperties->ErrorRegularExpressions.begin();
+ passIt != this->TestProperties->ErrorRegularExpressions.end();
+ ++ passIt )
+ {
+ if ( passIt->first.find(this->ProcessOutput.c_str()) )
+ {
+ reason = "Error regular expression found in output.";
+ reason += " Regex=[";
+ reason += passIt->second;
+ reason += "]";
+ forceFail = true;
+ break;
+ }
+ }
+ }
+ if (res == cmsysProcess_State_Exited)
+ {
+ bool success =
+ !forceFail && (retVal == 0 ||
+ this->TestProperties->RequiredRegularExpressions.size());
+ if(this->TestProperties->SkipReturnCode >= 0
+ && this->TestProperties->SkipReturnCode == retVal)
+ {
+ this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Skipped ");
+ }
+ else if((success && !this->TestProperties->WillFail)
+ || (!success && this->TestProperties->WillFail))
+ {
+ this->TestResult.Status = cmCTestTestHandler::COMPLETED;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed " );
+ }
+ else
+ {
+ this->TestResult.Status = cmCTestTestHandler::FAILED;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed " << reason );
+ outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
+ }
+ }
+ else if ( res == cmsysProcess_State_Expired )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout ");
+ this->TestResult.Status = cmCTestTestHandler::TIMEOUT;
+ outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
+ }
+ else if ( res == cmsysProcess_State_Exception )
+ {
+ outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: ");
+ switch(this->TestProcess->GetExitException())
+ {
+ case cmsysProcess_Exception_Fault:
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
+ this->TestResult.Status = cmCTestTestHandler::SEGFAULT;
+ break;
+ case cmsysProcess_Exception_Illegal:
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
+ this->TestResult.Status = cmCTestTestHandler::ILLEGAL;
+ break;
+ case cmsysProcess_Exception_Interrupt:
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
+ this->TestResult.Status = cmCTestTestHandler::INTERRUPT;
+ break;
+ case cmsysProcess_Exception_Numerical:
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
+ this->TestResult.Status = cmCTestTestHandler::NUMERICAL;
+ break;
+ default:
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other");
+ this->TestResult.Status = cmCTestTestHandler::OTHER_FAULT;
+ }
+ }
+ else //cmsysProcess_State_Error
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Not Run ");
+ }
+
+ passed = this->TestResult.Status == cmCTestTestHandler::COMPLETED;
+ char buf[1024];
+ sprintf(buf, "%6.2f sec", this->TestProcess->GetTotalTime());
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, buf << "\n" );
+
+ if ( outputTestErrorsToConsole )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, this->ProcessOutput << std::endl );
+ }
+
+ if ( this->TestHandler->LogFile )
+ {
+ *this->TestHandler->LogFile << "Test time = " << buf << std::endl;
+ }
+
+ // Set the working directory to the tests directory
+ std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(this->TestProperties->Directory.c_str());
+
+ this->DartProcessing();
+
+ // restore working directory
+ cmSystemTools::ChangeDirectory(oldpath.c_str());
+
+
+ // if this is doing MemCheck then all the output needs to be put into
+ // Output since that is what is parsed by cmCTestMemCheckHandler
+ if(!this->TestHandler->MemCheck && started)
+ {
+ this->TestHandler->CleanTestOutput(this->ProcessOutput,
+ static_cast<size_t>
+ (this->TestResult.Status == cmCTestTestHandler::COMPLETED ?
+ this->TestHandler->CustomMaximumPassedTestOutputSize :
+ this->TestHandler->CustomMaximumFailedTestOutputSize));
+ }
+ this->TestResult.Reason = reason;
+ if (this->TestHandler->LogFile)
+ {
+ bool pass = true;
+ const char* reasonType = "Test Pass Reason";
+ if(this->TestResult.Status != cmCTestTestHandler::COMPLETED &&
+ this->TestResult.Status != cmCTestTestHandler::NOT_RUN)
+ {
+ reasonType = "Test Fail Reason";
+ pass = false;
+ }
+ double ttime = this->TestProcess->GetTotalTime();
+ int hours = static_cast<int>(ttime / (60 * 60));
+ int minutes = static_cast<int>(ttime / 60) % 60;
+ int seconds = static_cast<int>(ttime) % 60;
+ char buffer[100];
+ sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
+ *this->TestHandler->LogFile
+ << "----------------------------------------------------------"
+ << std::endl;
+ if(this->TestResult.Reason.size())
+ {
+ *this->TestHandler->LogFile << reasonType << ":\n"
+ << this->TestResult.Reason << "\n";
+ }
+ else
+ {
+ if(pass)
+ {
+ *this->TestHandler->LogFile << "Test Passed.\n";
+ }
+ else
+ {
+ *this->TestHandler->LogFile << "Test Failed.\n";
+ }
+ }
+ *this->TestHandler->LogFile << "\"" << this->TestProperties->Name
+ << "\" end time: " << this->CTest->CurrentTime() << std::endl
+ << "\"" << this->TestProperties->Name << "\" time elapsed: "
+ << buffer << std::endl
+ << "----------------------------------------------------------"
+ << std::endl << std::endl;
+ }
+ // if the test actually started and ran
+ // record the results in TestResult
+ if(started)
+ {
+ bool compress = !this->TestHandler->MemCheck &&
+ this->CompressionRatio < 1 &&
+ this->CTest->ShouldCompressTestOutput();
+ this->TestResult.Output = compress ? this->CompressedOutput
+ : this->ProcessOutput;
+ this->TestResult.CompressOutput = compress;
+ this->TestResult.ReturnValue = this->TestProcess->GetExitValue();
+ this->TestResult.CompletionStatus = "Completed";
+ this->TestResult.ExecutionTime = this->TestProcess->GetTotalTime();
+ this->MemCheckPostProcess();
+ this->ComputeWeightedCost();
+ }
+ // Always push the current TestResult onto the
+ // TestHandler vector
+ this->TestHandler->TestResults.push_back(this->TestResult);
+ delete this->TestProcess;
+ return passed;
+}
+
+//----------------------------------------------------------------------
+void cmCTestRunTest::ComputeWeightedCost()
+{
+ double prev = static_cast<double>(this->TestProperties->PreviousRuns);
+ double avgcost = static_cast<double>(this->TestProperties->Cost);
+ double current = this->TestResult.ExecutionTime;
+
+ if(this->TestResult.Status == cmCTestTestHandler::COMPLETED)
+ {
+ this->TestProperties->Cost =
+ static_cast<float>(((prev * avgcost) + current) / (prev + 1.0));
+ this->TestProperties->PreviousRuns++;
+ }
+}
+
+//----------------------------------------------------------------------
+void cmCTestRunTest::MemCheckPostProcess()
+{
+ if(!this->TestHandler->MemCheck)
+ {
+ return;
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index
+ << ": process test output now: "
+ << this->TestProperties->Name << " "
+ << this->TestResult.Name << std::endl);
+ cmCTestMemCheckHandler * handler = static_cast<cmCTestMemCheckHandler*>
+ (this->TestHandler);
+ handler->PostProcessTest(this->TestResult, this->Index);
+}
+
+//----------------------------------------------------------------------
+// Starts the execution of a test. Returns once it has started
+bool cmCTestRunTest::StartTest(size_t total)
+{
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(2*getNumWidth(total) + 8)
+ << "Start "
+ << std::setw(getNumWidth(this->TestHandler->GetMaxIndex()))
+ << this->TestProperties->Index << ": "
+ << this->TestProperties->Name << std::endl);
+ this->ComputeArguments();
+ std::vector<std::string>& args = this->TestProperties->Args;
+ this->TestResult.Properties = this->TestProperties;
+ this->TestResult.ExecutionTime = 0;
+ this->TestResult.CompressOutput = false;
+ this->TestResult.ReturnValue = -1;
+ this->TestResult.CompletionStatus = "Failed to start";
+ this->TestResult.Status = cmCTestTestHandler::BAD_COMMAND;
+ this->TestResult.TestCount = this->TestProperties->Index;
+ this->TestResult.Name = this->TestProperties->Name;
+ this->TestResult.Path = this->TestProperties->Directory.c_str();
+
+ if(args.size() >= 2 && args[1] == "NOT_AVAILABLE")
+ {
+ this->TestProcess = new cmProcess;
+ std::string msg;
+ if(this->CTest->GetConfigType().empty())
+ {
+ msg = "Test not available without configuration.";
+ msg += " (Missing \"-C <config>\"?)";
+ }
+ else
+ {
+ msg = "Test not available in configuration \"";
+ msg += this->CTest->GetConfigType();
+ msg += "\".";
+ }
+ *this->TestHandler->LogFile << msg << std::endl;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, msg << std::endl);
+ this->TestResult.Output = msg;
+ this->TestResult.FullCommandLine = "";
+ this->TestResult.CompletionStatus = "Not Run";
+ this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
+ return false;
+ }
+
+ // Check if all required files exist
+ for(std::vector<std::string>::iterator i =
+ this->TestProperties->RequiredFiles.begin();
+ i != this->TestProperties->RequiredFiles.end(); ++i)
+ {
+ std::string file = *i;
+
+ if(!cmSystemTools::FileExists(file.c_str()))
+ {
+ //Required file was not found
+ this->TestProcess = new cmProcess;
+ *this->TestHandler->LogFile << "Unable to find required file: "
+ << file << std::endl;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find required file: "
+ << file << std::endl);
+ this->TestResult.Output = "Unable to find required file: " + file;
+ this->TestResult.FullCommandLine = "";
+ this->TestResult.CompletionStatus = "Not Run";
+ this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
+ return false;
+ }
+ }
+ // log and return if we did not find the executable
+ if (this->ActualCommand == "")
+ {
+ // if the command was not found create a TestResult object
+ // that has that information
+ this->TestProcess = new cmProcess;
+ *this->TestHandler->LogFile << "Unable to find executable: "
+ << args[1] << std::endl;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find executable: "
+ << args[1] << std::endl);
+ this->TestResult.Output = "Unable to find executable: " + args[1];
+ this->TestResult.FullCommandLine = "";
+ this->TestResult.CompletionStatus = "Not Run";
+ this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
+ return false;
+ }
+ this->StartTime = this->CTest->CurrentTime();
+
+ double timeout = this->ResolveTimeout();
+
+ if(this->StopTimePassed)
+ {
+ return false;
+ }
+ return this->ForkProcess(timeout, this->TestProperties->ExplicitTimeout,
+ &this->TestProperties->Environment);
+}
+
+//----------------------------------------------------------------------
+void cmCTestRunTest::ComputeArguments()
+{
+ std::vector<std::string>::const_iterator j =
+ this->TestProperties->Args.begin();
+ ++j; // skip test name
+
+ // find the test executable
+ if(this->TestHandler->MemCheck)
+ {
+ cmCTestMemCheckHandler * handler = static_cast<cmCTestMemCheckHandler*>
+ (this->TestHandler);
+ this->ActualCommand = handler->MemoryTester.c_str();
+ this->TestProperties->Args[1] = this->TestHandler->FindTheExecutable(
+ this->TestProperties->Args[1].c_str());
+ }
+ else
+ {
+ this->ActualCommand =
+ this->TestHandler->FindTheExecutable(
+ this->TestProperties->Args[1].c_str());
+ ++j; //skip the executable (it will be actualCommand)
+ }
+ std::string testCommand
+ = cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str());
+
+ //Prepends memcheck args to our command string
+ this->TestHandler->GenerateTestCommand(this->Arguments, this->Index);
+ for(std::vector<std::string>::iterator i = this->Arguments.begin();
+ i != this->Arguments.end(); ++i)
+ {
+ testCommand += " \"";
+ testCommand += *i;
+ testCommand += "\"";
+ }
+
+ for(;j != this->TestProperties->Args.end(); ++j)
+ {
+ testCommand += " \"";
+ testCommand += *j;
+ testCommand += "\"";
+ this->Arguments.push_back(*j);
+ }
+ this->TestResult.FullCommandLine = testCommand;
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
+ << this->Index << ": "
+ << (this->TestHandler->MemCheck?"MemCheck":"Test")
+ << " command: " << testCommand
+ << std::endl);
+}
+
+//----------------------------------------------------------------------
+void cmCTestRunTest::DartProcessing()
+{
+ if (!this->ProcessOutput.empty() &&
+ this->ProcessOutput.find("<DartMeasurement") != this->ProcessOutput.npos)
+ {
+ if (this->TestHandler->DartStuff.find(this->ProcessOutput.c_str()))
+ {
+ std::string dartString = this->TestHandler->DartStuff.match(1);
+ // keep searching and replacing until none are left
+ while (this->TestHandler->DartStuff1.find(this->ProcessOutput.c_str()))
+ {
+ // replace the exact match for the string
+ cmSystemTools::ReplaceString(this->ProcessOutput,
+ this->TestHandler->DartStuff1.match(1).c_str(), "");
+ }
+ this->TestResult.RegressionImages
+ = this->TestHandler->GenerateRegressionImages(dartString);
+ }
+ }
+}
+
+//----------------------------------------------------------------------
+double cmCTestRunTest::ResolveTimeout()
+{
+ double timeout = this->TestProperties->Timeout;
+
+ if(this->CTest->GetStopTime() == "")
+ {
+ return timeout;
+ }
+ struct tm* lctime;
+ time_t current_time = time(0);
+ lctime = gmtime(&current_time);
+ int gm_hour = lctime->tm_hour;
+ time_t gm_time = mktime(lctime);
+ lctime = localtime(&current_time);
+ int local_hour = lctime->tm_hour;
+
+ int tzone_offset = local_hour - gm_hour;
+ if(gm_time > current_time && gm_hour < local_hour)
+ {
+ // this means gm_time is on the next day
+ tzone_offset -= 24;
+ }
+ else if(gm_time < current_time && gm_hour > local_hour)
+ {
+ // this means gm_time is on the previous day
+ tzone_offset += 24;
+ }
+
+ tzone_offset *= 100;
+ char buf[1024];
+ // add todays year day and month to the time in str because
+ // curl_getdate no longer assumes the day is today
+ sprintf(buf, "%d%02d%02d %s %+05i",
+ lctime->tm_year + 1900,
+ lctime->tm_mon + 1,
+ lctime->tm_mday,
+ this->CTest->GetStopTime().c_str(),
+ tzone_offset);
+
+ time_t stop_time = curl_getdate(buf, &current_time);
+ if(stop_time == -1)
+ {
+ return timeout;
+ }
+
+ //the stop time refers to the next day
+ if(this->CTest->NextDayStopTime)
+ {
+ stop_time += 24*60*60;
+ }
+ int stop_timeout = static_cast<int>(stop_time - current_time) % (24*60*60);
+ this->CTest->LastStopTimeout = stop_timeout;
+
+ if(stop_timeout <= 0 || stop_timeout > this->CTest->LastStopTimeout)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "The stop time has been passed. "
+ "Stopping all tests." << std::endl);
+ this->StopTimePassed = true;
+ return 0;
+ }
+ return timeout == 0 ? stop_timeout :
+ (timeout < stop_timeout ? timeout : stop_timeout);
+}
+
+//----------------------------------------------------------------------
+bool cmCTestRunTest::ForkProcess(double testTimeOut, bool explicitTimeout,
+ std::vector<std::string>* environment)
+{
+ this->TestProcess = new cmProcess;
+ this->TestProcess->SetId(this->Index);
+ this->TestProcess->SetWorkingDirectory(
+ this->TestProperties->Directory.c_str());
+ this->TestProcess->SetCommand(this->ActualCommand.c_str());
+ this->TestProcess->SetCommandArguments(this->Arguments);
+
+ // determine how much time we have
+ double timeout = this->CTest->GetRemainingTimeAllowed() - 120;
+ if (this->CTest->GetTimeOut() > 0 && this->CTest->GetTimeOut() < timeout)
+ {
+ timeout = this->CTest->GetTimeOut();
+ }
+ if (testTimeOut > 0
+ && testTimeOut < this->CTest->GetRemainingTimeAllowed())
+ {
+ timeout = testTimeOut;
+ }
+ // always have at least 1 second if we got to here
+ if (timeout <= 0)
+ {
+ timeout = 1;
+ }
+ // handle timeout explicitly set to 0
+ if (testTimeOut == 0 && explicitTimeout)
+ {
+ timeout = 0;
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index << ": "
+ << "Test timeout computed to be: " << timeout << "\n");
+
+ this->TestProcess->SetTimeout(timeout);
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmSystemTools::SaveRestoreEnvironment sre;
+#endif
+
+ if (environment && environment->size()>0)
+ {
+ cmSystemTools::AppendEnv(*environment);
+ }
+
+ return this->TestProcess->StartProcess();
+}
+
+void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
+{
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
+ << completed << "/");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
+ << total << " ");
+
+ if ( this->TestHandler->MemCheck )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "MemCheck");
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Test");
+ }
+
+ cmOStringStream indexStr;
+ indexStr << " #" << this->Index << ":";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
+ << indexStr.str());
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+ const int maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
+ std::string outname = this->TestProperties->Name + " ";
+ outname.resize(maxTestNameWidth + 4, '.');
+
+ *this->TestHandler->LogFile << this->TestProperties->Index << "/"
+ << this->TestHandler->TotalNumberOfTests << " Testing: "
+ << this->TestProperties->Name << std::endl;
+ *this->TestHandler->LogFile << this->TestProperties->Index << "/"
+ << this->TestHandler->TotalNumberOfTests
+ << " Test: " << this->TestProperties->Name << std::endl;
+ *this->TestHandler->LogFile << "Command: \"" << this->ActualCommand << "\"";
+
+ for (std::vector<std::string>::iterator i = this->Arguments.begin();
+ i != this->Arguments.end(); ++i)
+ {
+ *this->TestHandler->LogFile
+ << " \"" << *i << "\"";
+ }
+ *this->TestHandler->LogFile << std::endl
+ << "Directory: " << this->TestProperties->Directory << std::endl
+ << "\"" << this->TestProperties->Name << "\" start time: "
+ << this->StartTime << std::endl;
+
+ *this->TestHandler->LogFile
+ << "Output:" << std::endl
+ << "----------------------------------------------------------"
+ << std::endl;
+ *this->TestHandler->LogFile
+ << this->ProcessOutput << "<end of output>" << std::endl;
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str());
+ cmCTestLog(this->CTest, DEBUG, "Testing "
+ << this->TestProperties->Name << " ... ");
+}
diff --git a/Source/CTest/cmCTestRunTest.h b/Source/CTest/cmCTestRunTest.h
new file mode 100644
index 0000000000..476f3e1263
--- /dev/null
+++ b/Source/CTest/cmCTestRunTest.h
@@ -0,0 +1,112 @@
+/*============================================================================
+ 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 cmCTestRunTest_h
+#define cmCTestRunTest_h
+
+#include <cmStandardIncludes.h>
+#include <cmCTestTestHandler.h>
+#include <cmProcess.h>
+
+/** \class cmRunTest
+ * \brief represents a single test to be run
+ *
+ * cmRunTest contains the information related to running a single test
+ */
+class cmCTestRunTest
+{
+public:
+ cmCTestRunTest(cmCTestTestHandler* handler);
+ ~cmCTestRunTest();
+
+ void SetTestProperties(cmCTestTestHandler::cmCTestTestProperties * prop)
+ { this->TestProperties = prop; }
+
+ cmCTestTestHandler::cmCTestTestProperties * GetTestProperties()
+ { return this->TestProperties; }
+
+ void SetIndex(int i) { this->Index = i; }
+
+ int GetIndex() { return this->Index; }
+
+ std::string GetProcessOutput() { return this->ProcessOutput; }
+
+ bool IsStopTimePassed() { return this->StopTimePassed; }
+
+ cmCTestTestHandler::cmCTestTestResult GetTestResults()
+ { return this->TestResult; }
+
+ // Read and store output. Returns true if it must be called again.
+ bool CheckOutput();
+
+ // Compresses the output, writing to CompressedOutput
+ void CompressOutput();
+
+ //launch the test process, return whether it started correctly
+ bool StartTest(size_t total);
+ //capture and report the test results
+ bool EndTest(size_t completed, size_t total, bool started);
+ //Called by ctest -N to log the command string
+ void ComputeArguments();
+
+ void ComputeWeightedCost();
+private:
+ void DartProcessing();
+ void ExeNotFound(std::string exe);
+ // Figures out a final timeout which is min(STOP_TIME, NOW+TIMEOUT)
+ double ResolveTimeout();
+ bool ForkProcess(double testTimeOut, bool explicitTimeout,
+ std::vector<std::string>* environment);
+ void WriteLogOutputTop(size_t completed, size_t total);
+ //Run post processing of the process output for MemCheck
+ void MemCheckPostProcess();
+
+ cmCTestTestHandler::cmCTestTestProperties * TestProperties;
+ //Pointer back to the "parent"; the handler that invoked this test run
+ cmCTestTestHandler * TestHandler;
+ cmCTest * CTest;
+ cmProcess * TestProcess;
+ //If the executable to run is ctest, don't create a new process;
+ //just instantiate a new cmTest. (Can be disabled for a single test
+ //if this option is set to false.)
+ //bool OptimizeForCTest;
+
+ bool UsePrefixCommand;
+ std::string PrefixCommand;
+
+ std::string ProcessOutput;
+ std::string CompressedOutput;
+ double CompressionRatio;
+ //The test results
+ cmCTestTestHandler::cmCTestTestResult TestResult;
+ int Index;
+ std::string StartTime;
+ std::string ActualCommand;
+ std::vector<std::string> Arguments;
+ bool StopTimePassed;
+};
+
+inline int getNumWidth(size_t n)
+{
+ int numWidth = 1;
+ if(n >= 10)
+ {
+ numWidth = 2;
+ }
+ if(n >= 100)
+ {
+ numWidth = 3;
+ }
+ return numWidth;
+}
+
+#endif
+
diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx
new file mode 100644
index 0000000000..86dc2f2fd9
--- /dev/null
+++ b/Source/CTest/cmCTestSVN.cxx
@@ -0,0 +1,619 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestSVN.h"
+
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include "cmXMLParser.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+struct cmCTestSVN::Revision: public cmCTestVC::Revision
+{
+ cmCTestSVN::SVNInfo* SVNInfo;
+};
+
+//----------------------------------------------------------------------------
+cmCTestSVN::cmCTestSVN(cmCTest* ct, std::ostream& log):
+ cmCTestGlobalVC(ct, log)
+{
+ this->PriorRev = this->Unknown;
+}
+
+//----------------------------------------------------------------------------
+cmCTestSVN::~cmCTestSVN()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::CleanupImpl()
+{
+ std::vector<const char*> svn_cleanup;
+ svn_cleanup.push_back("cleanup");
+ OutputLogger out(this->Log, "cleanup-out> ");
+ OutputLogger err(this->Log, "cleanup-err> ");
+ this->RunSVNCommand(svn_cleanup, &out, &err);
+}
+
+//----------------------------------------------------------------------------
+class cmCTestSVN::InfoParser: public cmCTestVC::LineParser
+{
+public:
+ InfoParser(cmCTestSVN* svn,
+ const char* prefix,
+ std::string& rev,
+ SVNInfo& svninfo):
+ Rev(rev), SVNRepo(svninfo)
+ {
+ this->SetLog(&svn->Log, prefix);
+ this->RegexRev.compile("^Revision: ([0-9]+)");
+ this->RegexURL.compile("^URL: +([^ ]+) *$");
+ this->RegexRoot.compile("^Repository Root: +([^ ]+) *$");
+ }
+private:
+ std::string& Rev;
+ cmCTestSVN::SVNInfo& SVNRepo;
+ cmsys::RegularExpression RegexRev;
+ cmsys::RegularExpression RegexURL;
+ cmsys::RegularExpression RegexRoot;
+ virtual bool ProcessLine()
+ {
+ if(this->RegexRev.find(this->Line))
+ {
+ this->Rev = this->RegexRev.match(1);
+ }
+ else if(this->RegexURL.find(this->Line))
+ {
+ this->SVNRepo.URL = this->RegexURL.match(1);
+ }
+ else if(this->RegexRoot.find(this->Line))
+ {
+ this->SVNRepo.Root = this->RegexRoot.match(1);
+ }
+ return true;
+ }
+};
+
+//----------------------------------------------------------------------------
+static bool cmCTestSVNPathStarts(std::string const& p1, std::string const& p2)
+{
+ // Does path p1 start with path p2?
+ if(p1.size() == p2.size())
+ {
+ return p1 == p2;
+ }
+ else if(p1.size() > p2.size() && p1[p2.size()] == '/')
+ {
+ return strncmp(p1.c_str(), p2.c_str(), p2.size()) == 0;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTestSVN::LoadInfo(SVNInfo& svninfo)
+{
+ // Run "svn info" to get the repository info from the work tree.
+ std::vector<const char*> svn_info;
+ svn_info.push_back("info");
+ svn_info.push_back(svninfo.LocalPath.c_str());
+ std::string rev;
+ InfoParser out(this, "info-out> ", rev, svninfo);
+ OutputLogger err(this->Log, "info-err> ");
+ this->RunSVNCommand(svn_info, &out, &err);
+ return rev;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::NoteOldRevision()
+{
+ // Info for root repository
+ this->Repositories.push_back( SVNInfo("") );
+ this->RootInfo = &(this->Repositories.back());
+ // Info for the external repositories
+ this->LoadExternals();
+
+ // Get info for all the repositories
+ std::list<SVNInfo>::iterator itbeg = this->Repositories.begin();
+ std::list<SVNInfo>::iterator itend = this->Repositories.end();
+ for( ; itbeg != itend ; itbeg++)
+ {
+ SVNInfo& svninfo = *itbeg;
+ svninfo.OldRevision = this->LoadInfo(svninfo);
+ this->Log << "Revision for repository '" << svninfo.LocalPath
+ << "' before update: " << svninfo.OldRevision << "\n";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Old revision of external repository '"
+ << svninfo.LocalPath << "' is: "
+ << svninfo.OldRevision << "\n");
+ }
+
+ // Set the global old revision to the one of the root
+ this->OldRevision = this->RootInfo->OldRevision;
+ this->PriorRev.Rev = this->OldRevision;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::NoteNewRevision()
+{
+ // Get info for the external repositories
+ std::list<SVNInfo>::iterator itbeg = this->Repositories.begin();
+ std::list<SVNInfo>::iterator itend = this->Repositories.end();
+ for( ; itbeg != itend ; itbeg++)
+ {
+ SVNInfo& svninfo = *itbeg;
+ svninfo.NewRevision = this->LoadInfo(svninfo);
+ this->Log << "Revision for repository '" << svninfo.LocalPath
+ << "' after update: " << svninfo.NewRevision << "\n";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " New revision of external repository '"
+ << svninfo.LocalPath << "' is: "
+ << svninfo.NewRevision << "\n");
+
+ // svninfo.Root = ""; // uncomment to test GuessBase
+ this->Log << "Repository '" << svninfo.LocalPath
+ << "' URL = " << svninfo.URL << "\n";
+ this->Log << "Repository '" << svninfo.LocalPath
+ << "' Root = " << svninfo.Root << "\n";
+
+ // Compute the base path the working tree has checked out under
+ // the repository root.
+ if(!svninfo.Root.empty()
+ && cmCTestSVNPathStarts(svninfo.URL, svninfo.Root))
+ {
+ svninfo.Base = cmCTest::DecodeURL(
+ svninfo.URL.substr(svninfo.Root.size()));
+ svninfo.Base += "/";
+ }
+ this->Log << "Repository '" << svninfo.LocalPath
+ << "' Base = " << svninfo.Base << "\n";
+
+ }
+
+ // Set the global new revision to the one of the root
+ this->NewRevision = this->RootInfo->NewRevision;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::GuessBase(SVNInfo& svninfo,
+ std::vector<Change> const& changes)
+{
+ // Subversion did not give us a good repository root so we need to
+ // guess the base path from the URL and the paths in a revision with
+ // changes under it.
+
+ // Consider each possible URL suffix from longest to shortest.
+ for(std::string::size_type slash = svninfo.URL.find('/');
+ svninfo.Base.empty() && slash != std::string::npos;
+ slash = svninfo.URL.find('/', slash+1))
+ {
+ // If the URL suffix is a prefix of at least one path then it is the base.
+ std::string base = cmCTest::DecodeURL(svninfo.URL.substr(slash));
+ for(std::vector<Change>::const_iterator ci = changes.begin();
+ svninfo.Base.empty() && ci != changes.end(); ++ci)
+ {
+ if(cmCTestSVNPathStarts(ci->Path, base))
+ {
+ svninfo.Base = base;
+ }
+ }
+ }
+
+ // We always append a slash so that we know paths beginning in the
+ // base lie under its path. If no base was found then the working
+ // tree must be a checkout of the entire repo and this will match
+ // the leading slash in all paths.
+ svninfo.Base += "/";
+
+ this->Log << "Guessed Base = " << svninfo.Base << "\n";
+}
+
+//----------------------------------------------------------------------------
+class cmCTestSVN::UpdateParser: public cmCTestVC::LineParser
+{
+public:
+ UpdateParser(cmCTestSVN* svn, const char* prefix): SVN(svn)
+ {
+ this->SetLog(&svn->Log, prefix);
+ this->RegexUpdate.compile("^([ADUCGE ])([ADUCGE ])[B ] +(.+)$");
+ }
+private:
+ cmCTestSVN* SVN;
+ cmsys::RegularExpression RegexUpdate;
+
+ bool ProcessLine()
+ {
+ if(this->RegexUpdate.find(this->Line))
+ {
+ this->DoPath(this->RegexUpdate.match(1)[0],
+ this->RegexUpdate.match(2)[0],
+ this->RegexUpdate.match(3));
+ }
+ return true;
+ }
+
+ void DoPath(char path_status, char prop_status, std::string const& path)
+ {
+ char status = (path_status != ' ')? path_status : prop_status;
+ std::string dir = cmSystemTools::GetFilenamePath(path);
+ std::string name = cmSystemTools::GetFilenameName(path);
+ // See "svn help update".
+ switch(status)
+ {
+ case 'G':
+ this->SVN->Dirs[dir][name].Status = PathModified;
+ break;
+ case 'C':
+ this->SVN->Dirs[dir][name].Status = PathConflicting;
+ break;
+ case 'A': case 'D': case 'U':
+ this->SVN->Dirs[dir][name].Status = PathUpdated;
+ break;
+ case 'E': // TODO?
+ case '?': case ' ': default:
+ break;
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+bool cmCTestSVN::UpdateImpl()
+{
+ // Get user-specified update options.
+ std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
+ if(opts.empty())
+ {
+ opts = this->CTest->GetCTestConfiguration("SVNUpdateOptions");
+ }
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
+
+ // Specify the start time for nightly testing.
+ if(this->CTest->GetTestModel() == cmCTest::NIGHTLY)
+ {
+ args.push_back("-r{" + this->GetNightlyTime() + " +0000}");
+ }
+
+ std::vector<char const*> svn_update;
+ svn_update.push_back("update");
+ for(std::vector<std::string>::const_iterator ai = args.begin();
+ ai != args.end(); ++ai)
+ {
+ svn_update.push_back(ai->c_str());
+ }
+
+ UpdateParser out(this, "up-out> ");
+ OutputLogger err(this->Log, "up-err> ");
+ return this->RunSVNCommand(svn_update, &out, &err);
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestSVN::RunSVNCommand(std::vector<char const*> const& parameters,
+ OutputParser* out, OutputParser* err)
+{
+ if(parameters.empty()) return false;
+
+ std::vector<char const*> args;
+ args.push_back(this->CommandLineTool.c_str());
+
+ args.insert(args.end(), parameters.begin(), parameters.end());
+
+ args.push_back("--non-interactive");
+
+ std::string userOptions =
+ this->CTest->GetCTestConfiguration("SVNOptions");
+
+ std::vector<std::string> parsedUserOptions =
+ cmSystemTools::ParseArguments(userOptions.c_str());
+ for(std::vector<std::string>::iterator i = parsedUserOptions.begin();
+ i != parsedUserOptions.end(); ++i)
+ {
+ args.push_back(i->c_str());
+ }
+
+ args.push_back(0);
+
+ if(strcmp(parameters[0], "update") == 0)
+ {
+ return RunUpdateCommand(&args[0], out, err);
+ }
+ else
+ {
+ return RunChild(&args[0], out, err);
+ }
+}
+
+//----------------------------------------------------------------------------
+class cmCTestSVN::LogParser: public cmCTestVC::OutputLogger,
+ private cmXMLParser
+{
+public:
+ LogParser(cmCTestSVN* svn, const char* prefix, SVNInfo& svninfo):
+ OutputLogger(svn->Log, prefix), SVN(svn), SVNRepo(svninfo)
+ { this->InitializeParser(); }
+ ~LogParser() { this->CleanupParser(); }
+private:
+ cmCTestSVN* SVN;
+ cmCTestSVN::SVNInfo& SVNRepo;
+
+ typedef cmCTestSVN::Revision Revision;
+ typedef cmCTestSVN::Change Change;
+ Revision Rev;
+ std::vector<Change> Changes;
+ Change CurChange;
+ std::vector<char> CData;
+
+ virtual bool ProcessChunk(const char* data, int length)
+ {
+ this->OutputLogger::ProcessChunk(data, length);
+ this->ParseChunk(data, length);
+ return true;
+ }
+
+ virtual void StartElement(const std::string& name, const char** atts)
+ {
+ this->CData.clear();
+ if(name == "logentry")
+ {
+ this->Rev = Revision();
+ this->Rev.SVNInfo = &SVNRepo;
+ if(const char* rev = this->FindAttribute(atts, "revision"))
+ {
+ this->Rev.Rev = rev;
+ }
+ this->Changes.clear();
+ }
+ else if(name == "path")
+ {
+ this->CurChange = Change();
+ if(const char* action = this->FindAttribute(atts, "action"))
+ {
+ this->CurChange.Action = action[0];
+ }
+ }
+ }
+
+ virtual void CharacterDataHandler(const char* data, int length)
+ {
+ this->CData.insert(this->CData.end(), data, data+length);
+ }
+
+ virtual void EndElement(const std::string& name)
+ {
+ if(name == "logentry")
+ {
+ this->SVN->DoRevisionSVN(this->Rev, this->Changes);
+ }
+ else if(!this->CData.empty() && name == "path")
+ {
+ std::string orig_path(&this->CData[0], this->CData.size());
+ std::string new_path = SVNRepo.BuildLocalPath( orig_path );
+ this->CurChange.Path.assign(new_path);
+ this->Changes.push_back(this->CurChange);
+ }
+ else if(!this->CData.empty() && name == "author")
+ {
+ this->Rev.Author.assign(&this->CData[0], this->CData.size());
+ }
+ else if(!this->CData.empty() && name == "date")
+ {
+ this->Rev.Date.assign(&this->CData[0], this->CData.size());
+ }
+ else if(!this->CData.empty() && name == "msg")
+ {
+ this->Rev.Log.assign(&this->CData[0], this->CData.size());
+ }
+ this->CData.clear();
+ }
+
+ virtual void ReportError(int, int, const char* msg)
+ {
+ this->SVN->Log << "Error parsing svn log xml: " << msg << "\n";
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::LoadRevisions()
+{
+ // Get revisions for all the external repositories
+ std::list<SVNInfo>::iterator itbeg = this->Repositories.begin();
+ std::list<SVNInfo>::iterator itend = this->Repositories.end();
+ for( ; itbeg != itend ; itbeg++)
+ {
+ SVNInfo& svninfo = *itbeg;
+ LoadRevisions(svninfo);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::LoadRevisions(SVNInfo &svninfo)
+{
+ // We are interested in every revision included in the update.
+ std::string revs;
+ if(atoi(svninfo.OldRevision.c_str()) < atoi(svninfo.NewRevision.c_str()))
+ {
+ revs = "-r" + svninfo.OldRevision + ":" + svninfo.NewRevision;
+ }
+ else
+ {
+ revs = "-r" + svninfo.NewRevision;
+ }
+
+ // Run "svn log" to get all global revisions of interest.
+ std::vector<const char*> svn_log;
+ svn_log.push_back("log");
+ svn_log.push_back("--xml");
+ svn_log.push_back("-v");
+ svn_log.push_back(revs.c_str());
+ svn_log.push_back(svninfo.LocalPath.c_str());
+ LogParser out(this, "log-out> ", svninfo);
+ OutputLogger err(this->Log, "log-err> ");
+ this->RunSVNCommand(svn_log, &out, &err);
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::DoRevisionSVN(Revision const& revision,
+ std::vector<Change> const& changes)
+{
+ // Guess the base checkout path from the changes if necessary.
+ if(this->RootInfo->Base.empty() && !changes.empty())
+ {
+ this->GuessBase(*this->RootInfo, changes);
+ }
+
+ // Ignore changes in the old revision for external repositories
+ if(revision.Rev == revision.SVNInfo->OldRevision
+ && revision.SVNInfo->LocalPath != "")
+ {
+ return;
+ }
+
+ this->cmCTestGlobalVC::DoRevision(revision, changes);
+}
+
+//----------------------------------------------------------------------------
+class cmCTestSVN::StatusParser: public cmCTestVC::LineParser
+{
+public:
+ StatusParser(cmCTestSVN* svn, const char* prefix): SVN(svn)
+ {
+ this->SetLog(&svn->Log, prefix);
+ this->RegexStatus.compile("^([ACDIMRX?!~ ])([CM ])[ L]... +(.+)$");
+ }
+private:
+ cmCTestSVN* SVN;
+ cmsys::RegularExpression RegexStatus;
+ bool ProcessLine()
+ {
+ if(this->RegexStatus.find(this->Line))
+ {
+ this->DoPath(this->RegexStatus.match(1)[0],
+ this->RegexStatus.match(2)[0],
+ this->RegexStatus.match(3));
+ }
+ return true;
+ }
+
+ void DoPath(char path_status, char prop_status, std::string const& path)
+ {
+ char status = (path_status != ' ')? path_status : prop_status;
+ // See "svn help status".
+ switch(status)
+ {
+ case 'M': case '!': case 'A': case 'D': case 'R':
+ this->SVN->DoModification(PathModified, path);
+ break;
+ case 'C': case '~':
+ this->SVN->DoModification(PathConflicting, path);
+ break;
+ case 'X': case 'I': case '?': case ' ': default:
+ break;
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::LoadModifications()
+{
+ // Run "svn status" which reports local modifications.
+ std::vector<const char*> svn_status;
+ svn_status.push_back("status");
+ StatusParser out(this, "status-out> ");
+ OutputLogger err(this->Log, "status-err> ");
+ this->RunSVNCommand(svn_status, &out, &err);
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::WriteXMLGlobal(std::ostream& xml)
+{
+ this->cmCTestGlobalVC::WriteXMLGlobal(xml);
+
+ xml << "\t<SVNPath>" << this->RootInfo->Base << "</SVNPath>\n";
+}
+
+//----------------------------------------------------------------------------
+class cmCTestSVN::ExternalParser: public cmCTestVC::LineParser
+{
+public:
+ ExternalParser(cmCTestSVN* svn, const char* prefix): SVN(svn)
+ {
+ this->SetLog(&svn->Log, prefix);
+ this->RegexExternal.compile("^X..... +(.+)$");
+ }
+private:
+ cmCTestSVN* SVN;
+ cmsys::RegularExpression RegexExternal;
+ bool ProcessLine()
+ {
+ if(this->RegexExternal.find(this->Line))
+ {
+ this->DoPath(this->RegexExternal.match(1));
+ }
+ return true;
+ }
+
+ void DoPath(std::string const& path)
+ {
+ // Get local path relative to the source directory
+ std::string local_path;
+ if(path.size() > this->SVN->SourceDirectory.size() &&
+ strncmp(path.c_str(), this->SVN->SourceDirectory.c_str(),
+ this->SVN->SourceDirectory.size()) == 0)
+ {
+ local_path = path.c_str() + this->SVN->SourceDirectory.size() + 1;
+ }
+ else
+ {
+ local_path = path;
+ }
+ this->SVN->Repositories.push_back( SVNInfo(local_path.c_str()) );
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::LoadExternals()
+{
+ // Run "svn status" to get the list of external repositories
+ std::vector<const char*> svn_status;
+ svn_status.push_back("status");
+ ExternalParser out(this, "external-out> ");
+ OutputLogger err(this->Log, "external-err> ");
+ this->RunSVNCommand(svn_status, &out, &err);
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTestSVN::SVNInfo::BuildLocalPath(std::string const& path) const
+{
+ std::string local_path;
+
+ // Add local path prefix if not empty
+ if (!this->LocalPath.empty())
+ {
+ local_path += this->LocalPath;
+ local_path += "/";
+ }
+
+ // Add path with base prefix removed
+ if(path.size() > this->Base.size() &&
+ strncmp(path.c_str(), this->Base.c_str(), this->Base.size()) == 0)
+ {
+ local_path += (path.c_str() + this->Base.size());
+ }
+ else
+ {
+ local_path += path;
+ }
+
+ return local_path;
+}
diff --git a/Source/CTest/cmCTestSVN.h b/Source/CTest/cmCTestSVN.h
new file mode 100644
index 0000000000..c6548e3fbc
--- /dev/null
+++ b/Source/CTest/cmCTestSVN.h
@@ -0,0 +1,100 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestSVN_h
+#define cmCTestSVN_h
+
+#include "cmCTestGlobalVC.h"
+
+/** \class cmCTestSVN
+ * \brief Interaction with subversion command-line tool
+ *
+ */
+class cmCTestSVN: public cmCTestGlobalVC
+{
+public:
+ /** Construct with a CTest instance and update log stream. */
+ cmCTestSVN(cmCTest* ctest, std::ostream& log);
+
+ virtual ~cmCTestSVN();
+
+private:
+ // Implement cmCTestVC internal API.
+ virtual void CleanupImpl();
+ virtual void NoteOldRevision();
+ virtual void NoteNewRevision();
+ virtual bool UpdateImpl();
+
+ bool RunSVNCommand(std::vector<char const*> const& parameters,
+ OutputParser* out, OutputParser* err);
+
+ // Information about an SVN repository (root repository or external)
+ struct SVNInfo {
+
+ SVNInfo(const char* path) : LocalPath(path) {}
+ // Remove base from the filename
+ std::string BuildLocalPath(std::string const& path) const;
+
+ // LocalPath relative to the main source directory.
+ std::string LocalPath;
+
+ // URL of repository directory checked out in the working tree.
+ std::string URL;
+
+ // URL of repository root directory.
+ std::string Root;
+
+ // Directory under repository root checked out in working tree.
+ std::string Base;
+
+ // Old and new repository revisions.
+ std::string OldRevision;
+ std::string NewRevision;
+
+ };
+
+ // Extended revision structure to include info about external it refers to.
+ struct Revision;
+ friend struct Revision;
+
+ // Info of all the repositories (root, externals and nested ones).
+ std::list<SVNInfo> Repositories;
+
+ // Pointer to the infos of the root repository.
+ SVNInfo* RootInfo;
+
+ std::string LoadInfo(SVNInfo& svninfo);
+ void LoadExternals();
+ void LoadModifications();
+ void LoadRevisions();
+ void LoadRevisions(SVNInfo& svninfo);
+
+ void GuessBase(SVNInfo &svninfo, std::vector<Change> const& changes);
+
+ void DoRevisionSVN(Revision const& revision,
+ std::vector<Change> const& changes);
+
+ void WriteXMLGlobal(std::ostream& xml);
+
+ // Parsing helper classes.
+ class InfoParser;
+ class LogParser;
+ class StatusParser;
+ class UpdateParser;
+ class ExternalParser;
+ friend class InfoParser;
+ friend class LogParser;
+ friend class StatusParser;
+ friend class UpdateParser;
+ friend class ExternalParser;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx
new file mode 100644
index 0000000000..f050148d13
--- /dev/null
+++ b/Source/CTest/cmCTestScriptHandler.cxx
@@ -0,0 +1,1157 @@
+/*============================================================================
+ 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 "cmCTestScriptHandler.h"
+
+#include "cmCTest.h"
+#include "cmake.h"
+#include "cmFunctionBlocker.h"
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmGeneratedFileStream.h"
+
+//#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Process.h>
+#include <cmsys/Directory.hxx>
+
+// used for sleep
+#ifdef _WIN32
+#include "windows.h"
+#endif
+
+#include <stdlib.h>
+#include <time.h>
+#include <math.h>
+#include <float.h>
+
+// needed for sleep
+#if !defined(_WIN32)
+# include <unistd.h>
+#endif
+
+#include "cmCTestBuildCommand.h"
+#include "cmCTestConfigureCommand.h"
+#include "cmCTestCoverageCommand.h"
+#include "cmCTestEmptyBinaryDirectoryCommand.h"
+#include "cmCTestMemCheckCommand.h"
+#include "cmCTestReadCustomFilesCommand.h"
+#include "cmCTestRunScriptCommand.h"
+#include "cmCTestSleepCommand.h"
+#include "cmCTestStartCommand.h"
+#include "cmCTestSubmitCommand.h"
+#include "cmCTestTestCommand.h"
+#include "cmCTestUpdateCommand.h"
+#include "cmCTestUploadCommand.h"
+
+#define CTEST_INITIAL_CMAKE_OUTPUT_FILE_NAME "CTestInitialCMakeOutput.log"
+
+// used to keep elapsed time up to date
+class cmCTestScriptFunctionBlocker : public cmFunctionBlocker
+{
+public:
+ cmCTestScriptFunctionBlocker() {}
+ virtual ~cmCTestScriptFunctionBlocker() {}
+ virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
+ cmMakefile &mf,
+ cmExecutionStatus &);
+ //virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf);
+ //virtual void ScopeEnded(cmMakefile &mf);
+
+ cmCTestScriptHandler* CTestScriptHandler;
+};
+
+// simply update the time and don't block anything
+bool cmCTestScriptFunctionBlocker::
+IsFunctionBlocked(const cmListFileFunction& , cmMakefile &,
+ cmExecutionStatus &)
+{
+ this->CTestScriptHandler->UpdateElapsedTime();
+ return false;
+}
+
+//----------------------------------------------------------------------
+cmCTestScriptHandler::cmCTestScriptHandler()
+{
+ this->Backup = false;
+ this->EmptyBinDir = false;
+ this->EmptyBinDirOnce = false;
+ this->Makefile = 0;
+ this->LocalGenerator = 0;
+ this->CMake = 0;
+ this->GlobalGenerator = 0;
+
+ this->ScriptStartTime = 0;
+
+ // the *60 is becuase the settings are in minutes but GetTime is seconds
+ this->MinimumInterval = 30*60;
+ this->ContinuousDuration = -1;
+}
+
+//----------------------------------------------------------------------
+void cmCTestScriptHandler::Initialize()
+{
+ this->Superclass::Initialize();
+ this->Backup = false;
+ this->EmptyBinDir = false;
+ this->EmptyBinDirOnce = false;
+
+ this->SourceDir = "";
+ this->BinaryDir = "";
+ this->BackupSourceDir = "";
+ this->BackupBinaryDir = "";
+ this->CTestRoot = "";
+ this->CVSCheckOut = "";
+ this->CTestCmd = "";
+ this->UpdateCmd = "";
+ this->CTestEnv = "";
+ this->InitialCache = "";
+ this->CMakeCmd = "";
+ this->CMOutFile = "";
+ this->ExtraUpdates.clear();
+
+ this->MinimumInterval = 20*60;
+ this->ContinuousDuration = -1;
+
+ // what time in seconds did this script start running
+ this->ScriptStartTime = 0;
+
+ this->Makefile = 0;
+ if (this->LocalGenerator)
+ {
+ delete this->LocalGenerator;
+ }
+ this->LocalGenerator = 0;
+ if (this->GlobalGenerator)
+ {
+ delete this->GlobalGenerator;
+ }
+ this->GlobalGenerator = 0;
+ if (this->CMake)
+ {
+ delete this->CMake;
+ }
+}
+
+//----------------------------------------------------------------------
+cmCTestScriptHandler::~cmCTestScriptHandler()
+{
+ // local generator owns the makefile
+ this->Makefile = 0;
+ if (this->LocalGenerator)
+ {
+ delete this->LocalGenerator;
+ }
+ this->LocalGenerator = 0;
+ if (this->GlobalGenerator)
+ {
+ delete this->GlobalGenerator;
+ }
+ this->GlobalGenerator = 0;
+ if (this->CMake)
+ {
+ delete this->CMake;
+ }
+}
+
+
+//----------------------------------------------------------------------
+// just adds an argument to the vector
+void cmCTestScriptHandler::AddConfigurationScript(const char *script,
+ bool pscope)
+{
+ this->ConfigurationScripts.push_back(script);
+ this->ScriptProcessScope.push_back(pscope);
+}
+
+
+//----------------------------------------------------------------------
+// the generic entry point for handling scripts, this routine will run all
+// the scripts provides a -S arguments
+int cmCTestScriptHandler::ProcessHandler()
+{
+ int res = 0;
+ for (size_t i=0; i < this->ConfigurationScripts.size(); ++i)
+ {
+ // for each script run it
+ res += this->RunConfigurationScript
+ (cmSystemTools::CollapseFullPath(this->ConfigurationScripts[i].c_str()),
+ this->ScriptProcessScope[i]);
+ }
+ if ( res )
+ {
+ return -1;
+ }
+ return 0;
+}
+
+void cmCTestScriptHandler::UpdateElapsedTime()
+{
+ if (this->LocalGenerator)
+ {
+ // 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);
+ }
+}
+
+//----------------------------------------------------------------------
+void cmCTestScriptHandler::AddCTestCommand(cmCTestCommand* command)
+{
+ cmCTestCommand* newCom = command;
+ newCom->CTest = this->CTest;
+ newCom->CTestScriptHandler = this;
+ this->CMake->AddCommand(newCom);
+}
+
+int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
+{
+ // execute the script passing in the arguments to the script as well as the
+ // arguments from this invocation of cmake
+ std::vector<const char*> argv;
+ argv.push_back(cmSystemTools::GetCTestCommand().c_str());
+ argv.push_back("-SR");
+ argv.push_back(total_script_arg.c_str());
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Executable for CTest is: " <<
+ cmSystemTools::GetCTestCommand() << "\n");
+
+ // now pass through all the other arguments
+ std::vector<std::string> &initArgs =
+ this->CTest->GetInitialCommandLineArguments();
+ //*** need to make sure this does not have the current script ***
+ for(size_t i=1; i < initArgs.size(); ++i)
+ {
+ argv.push_back(initArgs[i].c_str());
+ }
+ argv.push_back(0);
+
+ // Now create process object
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetCommand(cp, &*argv.begin());
+ //cmsysProcess_SetWorkingDirectory(cp, dir);
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+ //cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_Execute(cp);
+
+ std::vector<char> out;
+ std::vector<char> err;
+ std::string line;
+ int pipe = cmSystemTools::WaitForLine(cp, line, 100.0, out, err);
+ while(pipe != cmsysProcess_Pipe_None)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Output: "
+ << line << "\n");
+ if(pipe == cmsysProcess_Pipe_STDERR)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, line << "\n");
+ }
+ else if(pipe == cmsysProcess_Pipe_STDOUT)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, line << "\n");
+ }
+ pipe = cmSystemTools::WaitForLine(cp, line, 100, out, err);
+ }
+
+ // Properly handle output of the build command
+ cmsysProcess_WaitForExit(cp, 0);
+ int result = cmsysProcess_GetState(cp);
+ int retVal = 0;
+ bool failed = false;
+ if(result == cmsysProcess_State_Exited)
+ {
+ retVal = cmsysProcess_GetExitValue(cp);
+ }
+ else if(result == cmsysProcess_State_Exception)
+ {
+ retVal = cmsysProcess_GetExitException(cp);
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "\tThere was an exception: "
+ << cmsysProcess_GetExceptionString(cp) << " " <<
+ retVal << std::endl);
+ failed = true;
+ }
+ else if(result == cmsysProcess_State_Expired)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "\tThere was a timeout"
+ << std::endl);
+ failed = true;
+ }
+ else if(result == cmsysProcess_State_Error)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "\tError executing ctest: "
+ << cmsysProcess_GetErrorString(cp) << std::endl);
+ failed = true;
+ }
+ cmsysProcess_Delete(cp);
+ if(failed)
+ {
+ cmOStringStream message;
+ message << "Error running command: [";
+ message << result << "] ";
+ for(std::vector<const char*>::iterator i = argv.begin();
+ i != argv.end(); ++i)
+ {
+ if(*i)
+ {
+ message << *i << " ";
+ }
+ }
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ message.str() << argv[0] << std::endl);
+ return -1;
+ }
+ return retVal;
+}
+
+static void ctestScriptProgressCallback(const char *m, float, void* cd)
+{
+ cmCTest* ctest = static_cast<cmCTest*>(cd);
+ if(m && *m)
+ {
+ cmCTestLog(ctest, HANDLER_OUTPUT, "-- " << m << std::endl);
+ }
+}
+
+void cmCTestScriptHandler::CreateCMake()
+{
+ // create a cmake instance to read the configuration script
+ if (this->CMake)
+ {
+ delete this->CMake;
+ delete this->GlobalGenerator;
+ delete this->LocalGenerator;
+ }
+ this->CMake = new cmake;
+ this->CMake->AddCMakePaths();
+ this->GlobalGenerator = new cmGlobalGenerator;
+ this->GlobalGenerator->SetCMakeInstance(this->CMake);
+
+ this->LocalGenerator = this->GlobalGenerator->CreateLocalGenerator();
+ this->Makefile = this->LocalGenerator->GetMakefile();
+
+ this->CMake->SetProgressCallback(ctestScriptProgressCallback, this->CTest);
+
+ // Set CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_BINARY_DIR.
+ // Also, some commands need Makefile->GetCurrentDirectory().
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ this->Makefile->SetStartDirectory(cwd);
+ this->Makefile->SetStartOutputDirectory(cwd);
+
+ // remove all cmake commands which are not scriptable, since they can't be
+ // used in ctest scripts
+ this->CMake->RemoveUnscriptableCommands();
+
+ // add any ctest specific commands, probably should have common superclass
+ // for ctest commands to clean this up. If a couple more commands are
+ // created with the same format lets do that - ken
+ this->AddCTestCommand(new cmCTestBuildCommand);
+ this->AddCTestCommand(new cmCTestConfigureCommand);
+ this->AddCTestCommand(new cmCTestCoverageCommand);
+ this->AddCTestCommand(new cmCTestEmptyBinaryDirectoryCommand);
+ this->AddCTestCommand(new cmCTestMemCheckCommand);
+ this->AddCTestCommand(new cmCTestReadCustomFilesCommand);
+ this->AddCTestCommand(new cmCTestRunScriptCommand);
+ this->AddCTestCommand(new cmCTestSleepCommand);
+ this->AddCTestCommand(new cmCTestStartCommand);
+ this->AddCTestCommand(new cmCTestSubmitCommand);
+ this->AddCTestCommand(new cmCTestTestCommand);
+ this->AddCTestCommand(new cmCTestUpdateCommand);
+ this->AddCTestCommand(new cmCTestUploadCommand);
+}
+
+//----------------------------------------------------------------------
+// this sets up some variables for the script to use, creates the required
+// cmake instance and generators, and then reads in the script
+int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
+{
+ // Reset the error flag so that the script is read in no matter what
+ cmSystemTools::ResetErrorOccuredFlag();
+
+ // if the argument has a , in it then it needs to be broken into the fist
+ // argument (which is the script) and the second argument which will be
+ // passed into the scripts as S_ARG
+ std::string script = total_script_arg;
+ std::string script_arg;
+ if (total_script_arg.find(",") != std::string::npos)
+ {
+ script = total_script_arg.substr(0,total_script_arg.find(","));
+ script_arg = total_script_arg.substr(total_script_arg.find(",")+1);
+ }
+ // make sure the file exists
+ if (!cmSystemTools::FileExists(script.c_str()))
+ {
+ cmSystemTools::Error("Cannot find file: ", script.c_str());
+ return 1;
+ }
+
+ // read in the list file to fill the cache
+ // create a cmake instance to read the configuration script
+ this->CreateCMake();
+
+ // set a variable with the path to the current script
+ this->Makefile->AddDefinition("CTEST_SCRIPT_DIRECTORY",
+ cmSystemTools::GetFilenamePath(script).c_str());
+ this->Makefile->AddDefinition("CTEST_SCRIPT_NAME",
+ cmSystemTools::GetFilenameName(script).c_str());
+ this->Makefile->AddDefinition("CTEST_EXECUTABLE_NAME",
+ cmSystemTools::GetCTestCommand().c_str());
+ this->Makefile->AddDefinition("CMAKE_EXECUTABLE_NAME",
+ cmSystemTools::GetCMakeCommand().c_str());
+ this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", true);
+ this->UpdateElapsedTime();
+
+ // add the script arg if defined
+ if (script_arg.size())
+ {
+ this->Makefile->AddDefinition("CTEST_SCRIPT_ARG", script_arg.c_str());
+ }
+
+ // always add a function blocker to update the elapsed time
+ cmCTestScriptFunctionBlocker *f = new cmCTestScriptFunctionBlocker();
+ f->CTestScriptHandler = this;
+ this->Makefile->AddFunctionBlocker(f);
+
+
+ /* Execute CTestScriptMode.cmake, which loads CMakeDetermineSystem and
+ CMakeSystemSpecificInformation, so
+ that variables like CMAKE_SYSTEM and also the search paths for libraries,
+ header and executables are set correctly and can be used. Makes new-style
+ ctest scripting easier. */
+ std::string systemFile =
+ this->Makefile->GetModulesFile("CTestScriptMode.cmake");
+ if (!this->Makefile->ReadListFile(0, systemFile.c_str()) ||
+ cmSystemTools::GetErrorOccuredFlag())
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in read:"
+ << systemFile << "\n");
+ return 2;
+ }
+
+ // Add definitions of variables passed in on the command line:
+ const std::map<std::string, std::string> &defs =
+ this->CTest->GetDefinitions();
+ for (std::map<std::string, std::string>::const_iterator it = defs.begin();
+ it != defs.end(); ++it)
+ {
+ this->Makefile->AddDefinition(it->first, it->second.c_str());
+ }
+
+ // finally read in the script
+ if (!this->Makefile->ReadListFile(0, script.c_str()) ||
+ cmSystemTools::GetErrorOccuredFlag())
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in read script: "
+ << script
+ << std::endl);
+ // Reset the error flag so that it can run more than
+ // one script with an error when you
+ // use ctest_run_script
+ cmSystemTools::ResetErrorOccuredFlag();
+ return 2;
+ }
+
+ return 0;
+}
+
+
+//----------------------------------------------------------------------
+// extract variabels from the script to set ivars
+int cmCTestScriptHandler::ExtractVariables()
+{
+ // Temporary variables
+ const char* minInterval;
+ const char* contDuration;
+
+ this->SourceDir
+ = this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
+ this->BinaryDir
+ = this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
+
+ // add in translations for src and bin
+ cmSystemTools::AddKeepPath(this->SourceDir.c_str());
+ cmSystemTools::AddKeepPath(this->BinaryDir.c_str());
+
+ this->CTestCmd
+ = this->Makefile->GetSafeDefinition("CTEST_COMMAND");
+ this->CVSCheckOut
+ = this->Makefile->GetSafeDefinition("CTEST_CVS_CHECKOUT");
+ this->CTestRoot
+ = this->Makefile->GetSafeDefinition("CTEST_DASHBOARD_ROOT");
+ this->UpdateCmd
+ = this->Makefile->GetSafeDefinition("CTEST_UPDATE_COMMAND");
+ if ( this->UpdateCmd.empty() )
+ {
+ this->UpdateCmd
+ = this->Makefile->GetSafeDefinition("CTEST_CVS_COMMAND");
+ }
+ this->CTestEnv
+ = this->Makefile->GetSafeDefinition("CTEST_ENVIRONMENT");
+ this->InitialCache
+ = this->Makefile->GetSafeDefinition("CTEST_INITIAL_CACHE");
+ this->CMakeCmd
+ = this->Makefile->GetSafeDefinition("CTEST_CMAKE_COMMAND");
+ this->CMOutFile
+ = this->Makefile->GetSafeDefinition("CTEST_CMAKE_OUTPUT_FILE_NAME");
+
+ this->Backup
+ = this->Makefile->IsOn("CTEST_BACKUP_AND_RESTORE");
+ this->EmptyBinDir
+ = this->Makefile->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY");
+ this->EmptyBinDirOnce
+ = this->Makefile->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY_ONCE");
+
+ minInterval
+ = this->Makefile->GetDefinition("CTEST_CONTINUOUS_MINIMUM_INTERVAL");
+ contDuration
+ = this->Makefile->GetDefinition("CTEST_CONTINUOUS_DURATION");
+
+ char updateVar[40];
+ int i;
+ for (i = 1; i < 10; ++i)
+ {
+ sprintf(updateVar,"CTEST_EXTRA_UPDATES_%i",i);
+ const char *updateVal = this->Makefile->GetDefinition(updateVar);
+ if ( updateVal )
+ {
+ if ( this->UpdateCmd.empty() )
+ {
+ cmSystemTools::Error(updateVar,
+ " specified without specifying CTEST_CVS_COMMAND.");
+ return 12;
+ }
+ this->ExtraUpdates.push_back(updateVal);
+ }
+ }
+
+ // in order to backup and restore we also must have the cvs root
+ if (this->Backup && this->CVSCheckOut.empty())
+ {
+ cmSystemTools::Error(
+ "Backup was requested without specifying CTEST_CVS_CHECKOUT.");
+ return 3;
+ }
+
+ // make sure the required info is here
+ if (this->SourceDir.empty() ||
+ this->BinaryDir.empty() ||
+ this->CTestCmd.empty())
+ {
+ std::string msg = "CTEST_SOURCE_DIRECTORY = ";
+ msg += (!this->SourceDir.empty()) ? this->SourceDir.c_str() : "(Null)";
+ msg += "\nCTEST_BINARY_DIRECTORY = ";
+ msg += (!this->BinaryDir.empty()) ? this->BinaryDir.c_str() : "(Null)";
+ msg += "\nCTEST_COMMAND = ";
+ msg += (!this->CTestCmd.empty()) ? this->CTestCmd.c_str() : "(Null)";
+ cmSystemTools::Error(
+ "Some required settings in the configuration file were missing:\n",
+ msg.c_str());
+ return 4;
+ }
+
+ // if the dashboard root isn't specified then we can compute it from the
+ // this->SourceDir
+ if (this->CTestRoot.empty() )
+ {
+ this->CTestRoot = cmSystemTools::GetFilenamePath(this->SourceDir).c_str();
+ }
+
+ // the script may override the minimum continuous interval
+ if (minInterval)
+ {
+ this->MinimumInterval = 60 * atof(minInterval);
+ }
+ if (contDuration)
+ {
+ this->ContinuousDuration = 60.0 * atof(contDuration);
+ }
+
+
+ this->UpdateElapsedTime();
+
+ return 0;
+}
+
+//----------------------------------------------------------------------
+void cmCTestScriptHandler::SleepInSeconds(unsigned int secondsToWait)
+{
+#if defined(_WIN32)
+ Sleep(1000*secondsToWait);
+#else
+ sleep(secondsToWait);
+#endif
+}
+
+//----------------------------------------------------------------------
+// run a specific script
+int cmCTestScriptHandler::RunConfigurationScript
+(const std::string& total_script_arg, bool pscope)
+{
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmSystemTools::SaveRestoreEnvironment sre;
+#endif
+
+ int result;
+
+ this->ScriptStartTime =
+ cmSystemTools::GetTime();
+
+ // read in the script
+ if (pscope)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Reading Script: " << total_script_arg << std::endl);
+ result = this->ReadInScript(total_script_arg);
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Executing Script: " << total_script_arg << std::endl);
+ result = this->ExecuteScript(total_script_arg);
+ }
+ if (result)
+ {
+ return result;
+ }
+
+ // only run the curent script if we should
+ if (this->Makefile && this->Makefile->IsOn("CTEST_RUN_CURRENT_SCRIPT"))
+ {
+ return this->RunCurrentScript();
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------
+int cmCTestScriptHandler::RunCurrentScript()
+{
+ int result;
+
+ // do not run twice
+ this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", false);
+
+ // no popup widows
+ cmSystemTools::SetRunCommandHideConsole(true);
+
+ // extract the vars from the cache and store in ivars
+ result = this->ExtractVariables();
+ if (result)
+ {
+ return result;
+ }
+
+ // set any environment variables
+ if (!this->CTestEnv.empty())
+ {
+ std::vector<std::string> envArgs;
+ cmSystemTools::ExpandListArgument(this->CTestEnv,envArgs);
+ cmSystemTools::AppendEnv(envArgs);
+ }
+
+ // now that we have done most of the error checking finally run the
+ // dashboard, we may be asked to repeatedly run this dashboard, such as
+ // for a continuous, do we ned to run it more than once?
+ if ( this->ContinuousDuration >= 0 )
+ {
+ this->UpdateElapsedTime();
+ double ending_time = cmSystemTools::GetTime() + this->ContinuousDuration;
+ if (this->EmptyBinDirOnce)
+ {
+ this->EmptyBinDir = true;
+ }
+ do
+ {
+ double interval = cmSystemTools::GetTime();
+ result = this->RunConfigurationDashboard();
+ interval = cmSystemTools::GetTime() - interval;
+ if (interval < this->MinimumInterval)
+ {
+ this->SleepInSeconds(
+ static_cast<unsigned int>(this->MinimumInterval - interval));
+ }
+ if (this->EmptyBinDirOnce)
+ {
+ this->EmptyBinDir = false;
+ }
+ }
+ while (cmSystemTools::GetTime() < ending_time);
+ }
+ // otherwise just run it once
+ else
+ {
+ result = this->RunConfigurationDashboard();
+ }
+
+ return result;
+}
+
+//----------------------------------------------------------------------
+int cmCTestScriptHandler::CheckOutSourceDir()
+{
+ std::string command;
+ std::string output;
+ int retVal;
+ bool res;
+
+ if (!cmSystemTools::FileExists(this->SourceDir.c_str()) &&
+ !this->CVSCheckOut.empty())
+ {
+ // we must now checkout the src dir
+ output = "";
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Run cvs: " << this->CVSCheckOut << std::endl);
+ res = cmSystemTools::RunSingleCommand(this->CVSCheckOut.c_str(), &output,
+ &retVal, this->CTestRoot.c_str(), this->HandlerVerbose,
+ 0 /*this->TimeOut*/);
+ if (!res || retVal != 0)
+ {
+ cmSystemTools::Error("Unable to perform cvs checkout:\n",
+ output.c_str());
+ return 6;
+ }
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------
+int cmCTestScriptHandler::BackupDirectories()
+{
+ int retVal;
+
+ // compute the backup names
+ this->BackupSourceDir = this->SourceDir;
+ this->BackupSourceDir += "_CMakeBackup";
+ this->BackupBinaryDir = this->BinaryDir;
+ this->BackupBinaryDir += "_CMakeBackup";
+
+ // backup the binary and src directories if requested
+ if (this->Backup)
+ {
+ // if for some reason those directories exist then first delete them
+ if (cmSystemTools::FileExists(this->BackupSourceDir.c_str()))
+ {
+ cmSystemTools::RemoveADirectory(this->BackupSourceDir.c_str());
+ }
+ if (cmSystemTools::FileExists(this->BackupBinaryDir.c_str()))
+ {
+ cmSystemTools::RemoveADirectory(this->BackupBinaryDir.c_str());
+ }
+
+ // first rename the src and binary directories
+ rename(this->SourceDir.c_str(), this->BackupSourceDir.c_str());
+ rename(this->BinaryDir.c_str(), this->BackupBinaryDir.c_str());
+
+ // we must now checkout the src dir
+ retVal = this->CheckOutSourceDir();
+ if (retVal)
+ {
+ this->RestoreBackupDirectories();
+ return retVal;
+ }
+ }
+
+ return 0;
+}
+
+
+//----------------------------------------------------------------------
+int cmCTestScriptHandler::PerformExtraUpdates()
+{
+ std::string command;
+ std::string output;
+ int retVal;
+ bool res;
+
+ // do an initial cvs update as required
+ command = this->UpdateCmd;
+ std::vector<std::string>::iterator it;
+ for (it = this->ExtraUpdates.begin();
+ it != this->ExtraUpdates.end();
+ ++ it )
+ {
+ std::vector<std::string> cvsArgs;
+ cmSystemTools::ExpandListArgument(*it,cvsArgs);
+ if (cvsArgs.size() == 2)
+ {
+ std::string fullCommand = command;
+ fullCommand += " update ";
+ fullCommand += cvsArgs[1];
+ output = "";
+ retVal = 0;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run Update: "
+ << fullCommand << std::endl);
+ res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output,
+ &retVal, cvsArgs[0].c_str(),
+ this->HandlerVerbose, 0 /*this->TimeOut*/);
+ if (!res || retVal != 0)
+ {
+ cmSystemTools::Error("Unable to perform extra updates:\n",
+ it->c_str(), "\nWith output:\n",
+ output.c_str());
+ return 0;
+ }
+ }
+ }
+ return 0;
+}
+
+
+//----------------------------------------------------------------------
+// run a single dashboard entry
+int cmCTestScriptHandler::RunConfigurationDashboard()
+{
+ // local variables
+ std::string command;
+ std::string output;
+ int retVal;
+ bool res;
+
+ // make sure the src directory is there, if it isn't then we might be able
+ // to check it out from cvs
+ retVal = this->CheckOutSourceDir();
+ if (retVal)
+ {
+ return retVal;
+ }
+
+ // backup the dirs if requested
+ retVal = this->BackupDirectories();
+ if (retVal)
+ {
+ return retVal;
+ }
+
+ // clear the binary directory?
+ if (this->EmptyBinDir)
+ {
+ if ( !cmCTestScriptHandler::EmptyBinaryDirectory(
+ this->BinaryDir.c_str()) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Problem removing the binary directory" << std::endl);
+ }
+ }
+
+ // make sure the binary directory exists if it isn't the srcdir
+ if (!cmSystemTools::FileExists(this->BinaryDir.c_str()) &&
+ this->SourceDir != this->BinaryDir)
+ {
+ if (!cmSystemTools::MakeDirectory(this->BinaryDir.c_str()))
+ {
+ cmSystemTools::Error("Unable to create the binary directory:\n",
+ this->BinaryDir.c_str());
+ this->RestoreBackupDirectories();
+ return 7;
+ }
+ }
+
+ // if the binary directory and the source directory are the same,
+ // and we are starting with an empty binary directory, then that means
+ // we must check out the source tree
+ if (this->EmptyBinDir && this->SourceDir == this->BinaryDir)
+ {
+ // make sure we have the required info
+ if (this->CVSCheckOut.empty())
+ {
+ cmSystemTools::Error("You have specified the source and binary "
+ "directories to be the same (an in source build). You have also "
+ "specified that the binary directory is to be erased. This means "
+ "that the source will have to be checked out from CVS. But you have "
+ "not specified CTEST_CVS_CHECKOUT");
+ return 8;
+ }
+
+ // we must now checkout the src dir
+ retVal = this->CheckOutSourceDir();
+ if (retVal)
+ {
+ this->RestoreBackupDirectories();
+ return retVal;
+ }
+ }
+
+ // backup the dirs if requested
+ retVal = this->PerformExtraUpdates();
+ if (retVal)
+ {
+ return retVal;
+ }
+
+ // put the initial cache into the bin dir
+ if (!this->InitialCache.empty())
+ {
+ if (!this->WriteInitialCache(this->BinaryDir.c_str(),
+ this->InitialCache.c_str()))
+ {
+ this->RestoreBackupDirectories();
+ return 9;
+ }
+ }
+
+ // do an initial cmake to setup the DartConfig file
+ int cmakeFailed = 0;
+ std::string cmakeFailedOuput;
+ if (!this->CMakeCmd.empty())
+ {
+ command = this->CMakeCmd;
+ command += " \"";
+ command += this->SourceDir;
+ output = "";
+ command += "\"";
+ retVal = 0;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run cmake command: "
+ << command << std::endl);
+ res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
+ &retVal, this->BinaryDir.c_str(),
+ this->HandlerVerbose, 0 /*this->TimeOut*/);
+
+ if ( !this->CMOutFile.empty() )
+ {
+ std::string cmakeOutputFile = this->CMOutFile;
+ if ( !cmSystemTools::FileIsFullPath(cmakeOutputFile.c_str()) )
+ {
+ cmakeOutputFile = this->BinaryDir + "/" + cmakeOutputFile;
+ }
+
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Write CMake output to file: " << cmakeOutputFile
+ << std::endl);
+ cmGeneratedFileStream fout(cmakeOutputFile.c_str());
+ if ( fout )
+ {
+ fout << output.c_str();
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot open CMake output file: "
+ << cmakeOutputFile << " for writing" << std::endl);
+ }
+ }
+ if (!res || retVal != 0)
+ {
+ // even if this fails continue to the next step
+ cmakeFailed = 1;
+ cmakeFailedOuput = output;
+ }
+ }
+
+ // run ctest, it may be more than one command in here
+ std::vector<std::string> ctestCommands;
+ cmSystemTools::ExpandListArgument(this->CTestCmd,ctestCommands);
+ // for each variable/argument do a putenv
+ for (unsigned i = 0; i < ctestCommands.size(); ++i)
+ {
+ command = ctestCommands[i];
+ output = "";
+ retVal = 0;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run ctest command: "
+ << command << std::endl);
+ res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
+ &retVal, this->BinaryDir.c_str(), this->HandlerVerbose,
+ 0 /*this->TimeOut*/);
+
+ // did something critical fail in ctest
+ if (!res || cmakeFailed ||
+ retVal & cmCTest::BUILD_ERRORS)
+ {
+ this->RestoreBackupDirectories();
+ if (cmakeFailed)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unable to run cmake:" << std::endl
+ << cmakeFailedOuput << std::endl);
+ return 10;
+ }
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unable to run ctest:" << std::endl
+ << "command: " << command << std::endl
+ << "output: " << output << std::endl);
+ if (!res)
+ {
+ return 11;
+ }
+ return retVal * 100;
+ }
+ }
+
+ // if all was succesful, delete the backup dirs to free up disk space
+ if (this->Backup)
+ {
+ cmSystemTools::RemoveADirectory(this->BackupSourceDir.c_str());
+ cmSystemTools::RemoveADirectory(this->BackupBinaryDir.c_str());
+ }
+
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+bool cmCTestScriptHandler::WriteInitialCache(const char* directory,
+ const char* text)
+{
+ std::string cacheFile = directory;
+ cacheFile += "/CMakeCache.txt";
+ cmGeneratedFileStream fout(cacheFile.c_str());
+ if(!fout)
+ {
+ return false;
+ }
+
+ if (text!=0)
+ {
+ fout.write(text, strlen(text));
+ }
+
+ // Make sure the operating system has finished writing the file
+ // before closing it. This will ensure the file is finished before
+ // the check below.
+ fout.flush();
+ fout.close();
+ return true;
+}
+
+//-------------------------------------------------------------------------
+void cmCTestScriptHandler::RestoreBackupDirectories()
+{
+ // if we backed up the dirs and the build failed, then restore
+ // the backed up dirs
+ if (this->Backup)
+ {
+ // if for some reason those directories exist then first delete them
+ if (cmSystemTools::FileExists(this->SourceDir.c_str()))
+ {
+ cmSystemTools::RemoveADirectory(this->SourceDir.c_str());
+ }
+ if (cmSystemTools::FileExists(this->BinaryDir.c_str()))
+ {
+ cmSystemTools::RemoveADirectory(this->BinaryDir.c_str());
+ }
+ // rename the src and binary directories
+ rename(this->BackupSourceDir.c_str(), this->SourceDir.c_str());
+ rename(this->BackupBinaryDir.c_str(), this->BinaryDir.c_str());
+ }
+}
+
+bool cmCTestScriptHandler::RunScript(cmCTest* ctest, const char *sname,
+ bool InProcess, int* returnValue)
+{
+ cmCTestScriptHandler* sh = new cmCTestScriptHandler();
+ sh->SetCTestInstance(ctest);
+ sh->AddConfigurationScript(sname,InProcess);
+ int res = sh->ProcessHandler();
+ if(returnValue)
+ {
+ *returnValue = res;
+ }
+ delete sh;
+ return true;
+}
+
+bool cmCTestScriptHandler::EmptyBinaryDirectory(const char *sname)
+{
+ // try to avoid deleting root
+ if (!sname || strlen(sname) < 2)
+ {
+ return false;
+ }
+
+ // consider non existing target directory a success
+ if(!cmSystemTools::FileExists(sname))
+ {
+ return true;
+ }
+
+ // try to avoid deleting directories that we shouldn't
+ std::string check = sname;
+ check += "/CMakeCache.txt";
+
+ if(!cmSystemTools::FileExists(check.c_str()))
+ {
+ return false;
+ }
+
+ for(int i = 0; i < 5; ++i)
+ {
+ if(TryToRemoveBinaryDirectoryOnce(sname))
+ {
+ return true;
+ }
+ cmSystemTools::Delay(100);
+ }
+
+ return false;
+}
+
+//-------------------------------------------------------------------------
+bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce(
+ const std::string& directoryPath)
+{
+ cmsys::Directory directory;
+ directory.Load(directoryPath.c_str());
+
+ for(unsigned long i = 0; i < directory.GetNumberOfFiles(); ++i)
+ {
+ std::string path = directory.GetFile(i);
+
+ if(path == "." || path == ".." || path == "CMakeCache.txt")
+ {
+ continue;
+ }
+
+ std::string fullPath = directoryPath + std::string("/") + path;
+
+ bool isDirectory = cmSystemTools::FileIsDirectory(fullPath.c_str()) &&
+ !cmSystemTools::FileIsSymlink(fullPath.c_str());
+
+ if(isDirectory)
+ {
+ if(!cmSystemTools::RemoveADirectory(fullPath.c_str()))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if(!cmSystemTools::RemoveFile(fullPath.c_str()))
+ {
+ return false;
+ }
+ }
+ }
+
+ return cmSystemTools::RemoveADirectory(directoryPath.c_str());
+}
+
+//-------------------------------------------------------------------------
+double cmCTestScriptHandler::GetRemainingTimeAllowed()
+{
+ if (!this->Makefile)
+ {
+ return 1.0e7;
+ }
+
+ const char *timelimitS
+ = this->Makefile->GetDefinition("CTEST_TIME_LIMIT");
+
+ if (!timelimitS)
+ {
+ return 1.0e7;
+ }
+
+ double timelimit = atof(timelimitS);
+
+ return timelimit - cmSystemTools::GetTime() + this->ScriptStartTime;
+}
diff --git a/Source/CTest/cmCTestScriptHandler.h b/Source/CTest/cmCTestScriptHandler.h
new file mode 100644
index 0000000000..42c2f209bd
--- /dev/null
+++ b/Source/CTest/cmCTestScriptHandler.h
@@ -0,0 +1,174 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestScriptHandler_h
+#define cmCTestScriptHandler_h
+
+
+#include "cmCTestGenericHandler.h"
+#include "cmListFileCache.h"
+
+class cmMakefile;
+class cmLocalGenerator;
+class cmGlobalGenerator;
+class cmake;
+class cmCTestCommand;
+
+/** \class cmCTestScriptHandler
+ * \brief A class that handles ctest -S invocations
+ *
+ * CTest script is controlled using several variables that script has to
+ * specify and some optional ones. Required ones are:
+ * CTEST_SOURCE_DIRECTORY - Source directory of the project
+ * CTEST_BINARY_DIRECTORY - Binary directory of the project
+ * CTEST_COMMAND - Testing commands
+ *
+ * Optional variables are:
+ * CTEST_BACKUP_AND_RESTORE
+ * CTEST_CMAKE_COMMAND
+ * CTEST_CMAKE_OUTPUT_FILE_NAME
+ * CTEST_CONTINUOUS_DURATION
+ * CTEST_CONTINUOUS_MINIMUM_INTERVAL
+ * CTEST_CVS_CHECKOUT
+ * CTEST_CVS_COMMAND
+ * CTEST_UPDATE_COMMAND
+ * CTEST_DASHBOARD_ROOT
+ * CTEST_ENVIRONMENT
+ * CTEST_INITIAL_CACHE
+ * CTEST_START_WITH_EMPTY_BINARY_DIRECTORY
+ * CTEST_START_WITH_EMPTY_BINARY_DIRECTORY_ONCE
+ *
+ * In addition the following variables can be used. The number can be 1-10.
+ * CTEST_EXTRA_UPDATES_1
+ * CTEST_EXTRA_UPDATES_2
+ * ...
+ * CTEST_EXTRA_UPDATES_10
+ *
+ * CTest script can use the following arguments CTest provides:
+ * CTEST_SCRIPT_ARG
+ * CTEST_SCRIPT_DIRECTORY
+ * CTEST_SCRIPT_NAME
+ *
+ */
+class cmCTestScriptHandler : public cmCTestGenericHandler
+{
+public:
+ cmTypeMacro(cmCTestScriptHandler, cmCTestGenericHandler);
+
+ /**
+ * Add a script to run, and if is should run in the current process
+ */
+ void AddConfigurationScript(const char *, bool pscope);
+
+ /**
+ * Run a dashboard using a specified confiuration script
+ */
+ int ProcessHandler();
+
+ /*
+ * Run a script
+ */
+ static bool RunScript(cmCTest* ctest, const char *script, bool InProcess,
+ int* returnValue);
+ int RunCurrentScript();
+
+ /*
+ * Empty Binary Directory
+ */
+ static bool EmptyBinaryDirectory(const char *dir);
+
+ /*
+ * Write an initial CMakeCache.txt from the given contents.
+ */
+ static bool WriteInitialCache(const char* directory, const char* text);
+
+ /*
+ * Some elapsed time handling functions
+ */
+ static void SleepInSeconds(unsigned int secondsToWait);
+ void UpdateElapsedTime();
+
+ /**
+ * Return the time remaianing that the script is allowed to run in
+ * seconds if the user has set the variable CTEST_TIME_LIMIT. If that has
+ * not been set it returns 1e7 seconds
+ */
+ double GetRemainingTimeAllowed();
+
+ cmCTestScriptHandler();
+ ~cmCTestScriptHandler();
+
+ void Initialize();
+
+ void CreateCMake();
+ cmake* GetCMake() { return this->CMake;}
+private:
+ // reads in a script
+ int ReadInScript(const std::string& total_script_arg);
+ int ExecuteScript(const std::string& total_script_arg);
+
+ // extract vars from the script to set ivars
+ int ExtractVariables();
+
+ // perform a CVS checkout of the source dir
+ int CheckOutSourceDir();
+
+ // perform any extra cvs updates that were requested
+ int PerformExtraUpdates();
+
+ // backup and restore dirs
+ int BackupDirectories();
+ void RestoreBackupDirectories();
+
+ int RunConfigurationScript(const std::string& script, bool pscope);
+ int RunConfigurationDashboard();
+
+ // Add ctest command
+ void AddCTestCommand(cmCTestCommand* command);
+
+ // Try to remove the binary directory once
+ static bool TryToRemoveBinaryDirectoryOnce(const std::string& directoryPath);
+
+ std::vector<std::string> ConfigurationScripts;
+ std::vector<bool> ScriptProcessScope;
+
+ bool Backup;
+ bool EmptyBinDir;
+ bool EmptyBinDirOnce;
+
+ std::string SourceDir;
+ std::string BinaryDir;
+ std::string BackupSourceDir;
+ std::string BackupBinaryDir;
+ std::string CTestRoot;
+ std::string CVSCheckOut;
+ std::string CTestCmd;
+ std::string UpdateCmd;
+ std::string CTestEnv;
+ std::string InitialCache;
+ std::string CMakeCmd;
+ std::string CMOutFile;
+ std::vector<std::string> ExtraUpdates;
+
+ double MinimumInterval;
+ double ContinuousDuration;
+
+ // what time in seconds did this script start running
+ double ScriptStartTime;
+
+ cmMakefile *Makefile;
+ cmLocalGenerator *LocalGenerator;
+ cmGlobalGenerator *GlobalGenerator;
+ cmake *CMake;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestSleepCommand.cxx b/Source/CTest/cmCTestSleepCommand.cxx
new file mode 100644
index 0000000000..7e8755066a
--- /dev/null
+++ b/Source/CTest/cmCTestSleepCommand.cxx
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 "cmCTestSleepCommand.h"
+
+#include "cmCTestScriptHandler.h"
+#include <stdlib.h> // required for atoi
+
+bool cmCTestSleepCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if (args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // sleep for specified seconds
+ unsigned int time1 = atoi(args[0].c_str());
+ if(args.size() == 1 )
+ {
+ cmCTestScriptHandler::SleepInSeconds(time1);
+ // update the elapsed time since it could have slept for a while
+ this->CTestScriptHandler->UpdateElapsedTime();
+ return true;
+ }
+
+ // sleep up to a duration
+ if(args.size() == 3 )
+ {
+ unsigned int duration = atoi(args[1].c_str());
+ unsigned int time2 = atoi(args[2].c_str());
+ if (time1 + duration > time2)
+ {
+ duration = (time1 + duration - time2);
+ cmCTestScriptHandler::SleepInSeconds(duration);
+ // update the elapsed time since it could have slept for a while
+ this->CTestScriptHandler->UpdateElapsedTime();
+ }
+ return true;
+ }
+
+ this->SetError("called with incorrect number of arguments");
+ return false;
+}
+
+
diff --git a/Source/CTest/cmCTestSleepCommand.h b/Source/CTest/cmCTestSleepCommand.h
new file mode 100644
index 0000000000..740a7e12aa
--- /dev/null
+++ b/Source/CTest/cmCTestSleepCommand.h
@@ -0,0 +1,57 @@
+/*============================================================================
+ 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 cmCTestSleepCommand_h
+#define cmCTestSleepCommand_h
+
+#include "cmCTestCommand.h"
+
+/** \class cmCTestSleep
+ * \brief Run a ctest script
+ *
+ * cmLibrarysCommand defines a list of executable (i.e., test)
+ * programs to create.
+ */
+class cmCTestSleepCommand : public cmCTestCommand
+{
+public:
+
+ cmCTestSleepCommand() {}
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestSleepCommand* ni = new cmCTestSleepCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_sleep";}
+
+ cmTypeMacro(cmCTestSleepCommand, cmCTestCommand);
+
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestStartCommand.cxx b/Source/CTest/cmCTestStartCommand.cxx
new file mode 100644
index 0000000000..da46f4ab86
--- /dev/null
+++ b/Source/CTest/cmCTestStartCommand.cxx
@@ -0,0 +1,170 @@
+/*============================================================================
+ 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 "cmCTestStartCommand.h"
+
+#include "cmCTest.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmCTestVC.h"
+#include "cmGeneratedFileStream.h"
+
+cmCTestStartCommand::cmCTestStartCommand()
+{
+ this->CreateNewTag = true;
+}
+
+bool cmCTestStartCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if (args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ size_t cnt = 0;
+ const char* smodel = args[cnt].c_str();
+ const char* src_dir = 0;
+ const char* bld_dir = 0;
+
+ cnt++;
+
+ this->CTest->SetSpecificTrack(0);
+ if ( cnt < args.size() -1 )
+ {
+ if ( args[cnt] == "TRACK" )
+ {
+ cnt ++;
+ this->CTest->SetSpecificTrack(args[cnt].c_str());
+ cnt ++;
+ }
+ }
+
+ if (cnt < args.size())
+ {
+ if (args[cnt] == "APPEND")
+ {
+ cnt ++;
+ this->CreateNewTag = false;
+ }
+ }
+
+ if ( cnt < args.size() )
+ {
+ src_dir = args[cnt].c_str();
+ cnt ++;
+ if ( cnt < args.size() )
+ {
+ bld_dir = args[cnt].c_str();
+ }
+ }
+ if ( !src_dir )
+ {
+ src_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
+ }
+ if ( !bld_dir)
+ {
+ bld_dir = this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY");
+ }
+ if ( !src_dir )
+ {
+ this->SetError("source directory not specified. Specify source directory "
+ "as an argument or set CTEST_SOURCE_DIRECTORY");
+ return false;
+ }
+ if ( !bld_dir)
+ {
+ this->SetError("binary directory not specified. Specify binary directory "
+ "as an argument or set CTEST_BINARY_DIRECTORY");
+ return false;
+ }
+
+ cmSystemTools::AddKeepPath(src_dir);
+ cmSystemTools::AddKeepPath(bld_dir);
+
+ this->CTest->EmptyCTestConfiguration();
+
+ std::string sourceDir = cmSystemTools::CollapseFullPath(src_dir);
+ std::string binaryDir = cmSystemTools::CollapseFullPath(bld_dir);
+ this->CTest->SetCTestConfiguration("SourceDirectory", sourceDir.c_str());
+ this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir.c_str());
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Run dashboard with model "
+ << smodel << std::endl
+ << " Source directory: " << src_dir << std::endl
+ << " Build directory: " << bld_dir << std::endl);
+ const char* track = this->CTest->GetSpecificTrack();
+ if ( track )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Track: " << track << std::endl);
+ }
+
+ // Log startup actions.
+ std::string startLogFile = binaryDir + "/Testing/Temporary/LastStart.log";
+ cmGeneratedFileStream ofs(startLogFile.c_str());
+ if(!ofs)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot create log file: LastStart.log" << std::endl);
+ return false;
+ }
+
+ // Make sure the source directory exists.
+ if(!this->InitialCheckout(ofs, sourceDir))
+ {
+ return false;
+ }
+ if(!cmSystemTools::FileIsDirectory(sourceDir.c_str()))
+ {
+ cmOStringStream e;
+ e << "given source path\n"
+ << " " << sourceDir << "\n"
+ << "which is not an existing directory. "
+ << "Set CTEST_CHECKOUT_COMMAND to a command line to create it.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", "OFF");
+ this->CTest->SetSuppressUpdatingCTestConfiguration(true);
+ int model = this->CTest->GetTestModelFromString(smodel);
+ this->CTest->SetTestModel(model);
+ this->CTest->SetProduceXML(true);
+
+ return this->CTest->InitializeFromCommand(this);
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestStartCommand::InitialCheckout(
+ std::ostream& ofs, std::string const& sourceDir)
+{
+ // Use the user-provided command to create the source tree.
+ const char* initialCheckoutCommand
+ = this->Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
+ if(!initialCheckoutCommand)
+ {
+ initialCheckoutCommand =
+ this->Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
+ }
+ if(initialCheckoutCommand)
+ {
+ // Use a generic VC object to run and log the command.
+ cmCTestVC vc(this->CTest, ofs);
+ vc.SetSourceDirectory(sourceDir);
+ if(!vc.InitialCheckout(initialCheckoutCommand))
+ {
+ return false;
+ }
+ }
+ return true;
+}
diff --git a/Source/CTest/cmCTestStartCommand.h b/Source/CTest/cmCTestStartCommand.h
new file mode 100644
index 0000000000..3b8843f35c
--- /dev/null
+++ b/Source/CTest/cmCTestStartCommand.h
@@ -0,0 +1,68 @@
+/*============================================================================
+ 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 cmCTestStartCommand_h
+#define cmCTestStartCommand_h
+
+#include "cmCTestCommand.h"
+
+/** \class cmCTestStart
+ * \brief Run a ctest script
+ *
+ * cmCTestStartCommand defineds the command to start the nightly testing.
+ */
+class cmCTestStartCommand : public cmCTestCommand
+{
+public:
+
+ cmCTestStartCommand();
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestStartCommand* ni = new cmCTestStartCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ ni->CreateNewTag = this->CreateNewTag;
+ return ni;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * Will this invocation of ctest_start create a new TAG file?
+ */
+ bool ShouldCreateNewTag()
+ {
+ return this->CreateNewTag;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_start";}
+
+ cmTypeMacro(cmCTestStartCommand, cmCTestCommand);
+
+private:
+ bool InitialCheckout(std::ostream& ofs, std::string const& sourceDir);
+ bool CreateNewTag;
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestSubmitCommand.cxx b/Source/CTest/cmCTestSubmitCommand.cxx
new file mode 100644
index 0000000000..07a994de64
--- /dev/null
+++ b/Source/CTest/cmCTestSubmitCommand.cxx
@@ -0,0 +1,255 @@
+/*============================================================================
+ 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 "cmCTestSubmitCommand.h"
+
+#include "cmCTest.h"
+#include "cmCTestGenericHandler.h"
+#include "cmCTestSubmitHandler.h"
+
+cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
+{
+ const char* ctestDropMethod
+ = this->Makefile->GetDefinition("CTEST_DROP_METHOD");
+ const char* ctestDropSite
+ = this->Makefile->GetDefinition("CTEST_DROP_SITE");
+ const char* ctestDropLocation
+ = this->Makefile->GetDefinition("CTEST_DROP_LOCATION");
+ const char* ctestTriggerSite
+ = this->Makefile->GetDefinition("CTEST_TRIGGER_SITE");
+ bool ctestDropSiteCDash
+ = this->Makefile->IsOn("CTEST_DROP_SITE_CDASH");
+
+ if ( !ctestDropMethod )
+ {
+ ctestDropMethod = "http";
+ }
+
+ if ( !ctestDropSite )
+ {
+ // error: CDash requires CTEST_DROP_SITE definition
+ // in CTestConfig.cmake
+ }
+ if ( !ctestDropLocation )
+ {
+ // error: CDash requires CTEST_DROP_LOCATION definition
+ // in CTestConfig.cmake
+ }
+
+ this->CTest->SetCTestConfiguration("DropMethod", ctestDropMethod);
+ this->CTest->SetCTestConfiguration("DropSite", ctestDropSite);
+ this->CTest->SetCTestConfiguration("DropLocation", ctestDropLocation);
+
+ this->CTest->SetCTestConfiguration("IsCDash",
+ ctestDropSiteCDash ? "TRUE" : "FALSE");
+
+ // Only propagate TriggerSite for non-CDash projects:
+ //
+ if ( !ctestDropSiteCDash )
+ {
+ this->CTest->SetCTestConfiguration("TriggerSite", ctestTriggerSite);
+ }
+
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "CurlOptions", "CTEST_CURL_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "DropSiteUser", "CTEST_DROP_SITE_USER");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "DropSitePassword", "CTEST_DROP_SITE_PASSWORD");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "ScpCommand", "CTEST_SCP_COMMAND");
+
+ const char* notesFilesVariable
+ = this->Makefile->GetDefinition("CTEST_NOTES_FILES");
+ if (notesFilesVariable)
+ {
+ std::vector<std::string> notesFiles;
+ cmCTest::VectorOfStrings newNotesFiles;
+ cmSystemTools::ExpandListArgument(notesFilesVariable,notesFiles);
+ std::vector<std::string>::iterator it;
+ for ( it = notesFiles.begin();
+ it != notesFiles.end();
+ ++ it )
+ {
+ newNotesFiles.push_back(*it);
+ }
+ this->CTest->GenerateNotesFile(newNotesFiles);
+ }
+
+ const char* extraFilesVariable
+ = this->Makefile->GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
+ if (extraFilesVariable)
+ {
+ std::vector<std::string> extraFiles;
+ cmCTest::VectorOfStrings newExtraFiles;
+ cmSystemTools::ExpandListArgument(extraFilesVariable,extraFiles);
+ std::vector<std::string>::iterator it;
+ for ( it = extraFiles.begin();
+ it != extraFiles.end();
+ ++ it )
+ {
+ newExtraFiles.push_back(*it);
+ }
+ if ( !this->CTest->SubmitExtraFiles(newExtraFiles))
+ {
+ this->SetError("problem submitting extra files.");
+ return 0;
+ }
+ }
+
+ cmCTestGenericHandler* handler
+ = this->CTest->GetInitializedHandler("submit");
+ if ( !handler )
+ {
+ this->SetError("internal CTest error. Cannot instantiate submit handler");
+ return 0;
+ }
+
+ // If no FILES or PARTS given, *all* PARTS are submitted by default.
+ //
+ // If FILES are given, but not PARTS, only the FILES are submitted
+ // and *no* PARTS are submitted.
+ // (This is why we select the empty "noParts" set in the
+ // FilesMentioned block below...)
+ //
+ // If PARTS are given, only the selected PARTS are submitted.
+ //
+ // If both PARTS and FILES are given, only the selected PARTS *and*
+ // all the given FILES are submitted.
+
+ // If given explicit FILES to submit, pass them to the handler.
+ //
+ if(this->FilesMentioned)
+ {
+ // Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
+ // were also explicitly mentioned, they will be selected below...
+ // But FILES with no PARTS mentioned should just submit the FILES
+ // without any of the default parts.
+ //
+ std::set<cmCTest::Part> noParts;
+ static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(noParts);
+
+ static_cast<cmCTestSubmitHandler*>(handler)->SelectFiles(this->Files);
+ }
+
+ // If a PARTS option was given, select only the named parts for submission.
+ //
+ if(this->PartsMentioned)
+ {
+ static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(this->Parts);
+ }
+
+ static_cast<cmCTestSubmitHandler*>(handler)->SetOption("RetryDelay",
+ this->RetryDelay.c_str());
+ static_cast<cmCTestSubmitHandler*>(handler)->SetOption("RetryCount",
+ this->RetryCount.c_str());
+ static_cast<cmCTestSubmitHandler*>(handler)->SetOption("InternalTest",
+ this->InternalTest ? "ON" : "OFF");
+
+ return handler;
+}
+
+
+//----------------------------------------------------------------------------
+bool cmCTestSubmitCommand::CheckArgumentKeyword(std::string const& arg)
+{
+ // Look for arguments specific to this command.
+ if(arg == "PARTS")
+ {
+ this->ArgumentDoing = ArgumentDoingParts;
+ this->PartsMentioned = true;
+ return true;
+ }
+
+ if(arg == "FILES")
+ {
+ this->ArgumentDoing = ArgumentDoingFiles;
+ this->FilesMentioned = true;
+ return true;
+ }
+
+ if(arg == "RETRY_COUNT")
+ {
+ this->ArgumentDoing = ArgumentDoingRetryCount;
+ return true;
+ }
+
+ if(arg == "RETRY_DELAY")
+ {
+ this->ArgumentDoing = ArgumentDoingRetryDelay;
+ return true;
+ }
+
+ if(arg == "INTERNAL_TEST_CHECKSUM")
+ {
+ this->InternalTest = true;
+ return true;
+ }
+
+ // Look for other arguments.
+ return this->Superclass::CheckArgumentKeyword(arg);
+}
+
+
+//----------------------------------------------------------------------------
+bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg)
+{
+ // Handle states specific to this command.
+ if(this->ArgumentDoing == ArgumentDoingParts)
+ {
+ cmCTest::Part p = this->CTest->GetPartFromName(arg.c_str());
+ if(p != cmCTest::PartCount)
+ {
+ this->Parts.insert(p);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "Part name \"" << arg << "\" is invalid.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->ArgumentDoing = ArgumentDoingError;
+ }
+ return true;
+ }
+
+ if(this->ArgumentDoing == ArgumentDoingFiles)
+ {
+ std::string filename(arg);
+ if(cmSystemTools::FileExists(filename.c_str()))
+ {
+ this->Files.insert(filename);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "File \"" << filename << "\" does not exist. Cannot submit "
+ << "a non-existent file.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->ArgumentDoing = ArgumentDoingError;
+ }
+ return true;
+ }
+
+ if(this->ArgumentDoing == ArgumentDoingRetryCount)
+ {
+ this->RetryCount = arg;
+ return true;
+ }
+
+ if(this->ArgumentDoing == ArgumentDoingRetryDelay)
+ {
+ this->RetryDelay = arg;
+ return true;
+ }
+
+ // Look for other arguments.
+ return this->Superclass::CheckArgumentValue(arg);
+}
diff --git a/Source/CTest/cmCTestSubmitCommand.h b/Source/CTest/cmCTestSubmitCommand.h
new file mode 100644
index 0000000000..3673fbdec2
--- /dev/null
+++ b/Source/CTest/cmCTestSubmitCommand.h
@@ -0,0 +1,80 @@
+/*============================================================================
+ 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 cmCTestSubmitCommand_h
+#define cmCTestSubmitCommand_h
+
+#include "cmCTestHandlerCommand.h"
+#include "cmCTest.h"
+
+/** \class cmCTestSubmit
+ * \brief Run a ctest script
+ *
+ * cmCTestSubmitCommand defineds the command to submit the test results for
+ * the project.
+ */
+class cmCTestSubmitCommand : public cmCTestHandlerCommand
+{
+public:
+
+ cmCTestSubmitCommand()
+ {
+ this->PartsMentioned = false;
+ this->FilesMentioned = false;
+ this->InternalTest = false;
+ this->RetryCount = "";
+ this->RetryDelay = "";
+ }
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestSubmitCommand* ni = new cmCTestSubmitCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_submit";}
+
+ cmTypeMacro(cmCTestSubmitCommand, cmCTestHandlerCommand);
+
+protected:
+ cmCTestGenericHandler* InitializeHandler();
+
+ virtual bool CheckArgumentKeyword(std::string const& arg);
+ virtual bool CheckArgumentValue(std::string const& arg);
+
+ enum
+ {
+ ArgumentDoingParts = Superclass::ArgumentDoingLast1,
+ ArgumentDoingFiles,
+ ArgumentDoingRetryDelay,
+ ArgumentDoingRetryCount,
+ ArgumentDoingLast2
+ };
+
+ bool PartsMentioned;
+ std::set<cmCTest::Part> Parts;
+ bool FilesMentioned;
+ bool InternalTest;
+ cmCTest::SetOfStrings Files;
+ std::string RetryCount;
+ std::string RetryDelay;
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx
new file mode 100644
index 0000000000..06fcb75260
--- /dev/null
+++ b/Source/CTest/cmCTestSubmitHandler.cxx
@@ -0,0 +1,1511 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestSubmitHandler.h"
+
+#include "cmSystemTools.h"
+#include "cmVersion.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCTest.h"
+#include "cmXMLParser.h"
+
+#include <cmsys/Process.h>
+#include <cmsys/Base64.h>
+
+// For XML-RPC submission
+#include "cm_xmlrpc.h"
+
+// For curl submission
+#include "cm_curl.h"
+
+#include <sys/stat.h>
+
+#define SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT 120
+
+typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
+
+//----------------------------------------------------------------------------
+class cmCTestSubmitHandler::ResponseParser: public cmXMLParser
+{
+public:
+ ResponseParser() { this->Status = STATUS_OK; }
+ ~ResponseParser() {}
+
+public:
+
+ enum StatusType
+ {
+ STATUS_OK,
+ STATUS_WARNING,
+ STATUS_ERROR
+ };
+
+ StatusType Status;
+ std::string CDashVersion;
+ std::string Filename;
+ std::string MD5;
+ std::string Message;
+
+private:
+
+ std::vector<char> CurrentValue;
+
+ std::string GetCurrentValue()
+ {
+ std::string val;
+ if(this->CurrentValue.size())
+ {
+ val.assign(&this->CurrentValue[0], this->CurrentValue.size());
+ }
+ return val;
+ }
+
+ virtual void StartElement(const std::string& name, const char** atts)
+ {
+ this->CurrentValue.clear();
+ if(name == "cdash")
+ {
+ this->CDashVersion = this->FindAttribute(atts, "version");
+ }
+ }
+
+ virtual void CharacterDataHandler(const char* data, int length)
+ {
+ this->CurrentValue.insert(this->CurrentValue.end(), data, data+length);
+ }
+
+ virtual void EndElement(const std::string& name)
+ {
+ if(name == "status")
+ {
+ std::string status = cmSystemTools::UpperCase(this->GetCurrentValue());
+ if(status == "OK" || status == "SUCCESS")
+ {
+ this->Status = STATUS_OK;
+ }
+ else if(status == "WARNING")
+ {
+ this->Status = STATUS_WARNING;
+ }
+ else
+ {
+ this->Status = STATUS_ERROR;
+ }
+ }
+ else if(name == "filename")
+ {
+ this->Filename = this->GetCurrentValue();
+ }
+ else if(name == "md5")
+ {
+ this->MD5 = this->GetCurrentValue();
+ }
+ else if(name == "message")
+ {
+ this->Message = this->GetCurrentValue();
+ }
+ }
+};
+
+
+static size_t
+cmCTestSubmitHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
+ void *data)
+{
+ int realsize = (int)(size * nmemb);
+
+ cmCTestSubmitHandlerVectorOfChar *vec
+ = static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
+ const char* chPtr = static_cast<char*>(ptr);
+ vec->insert(vec->end(), chPtr, chPtr + realsize);
+
+ return realsize;
+}
+
+static size_t
+cmCTestSubmitHandlerCurlDebugCallback(CURL *, curl_infotype, char *chPtr,
+ size_t size, void *data)
+{
+ cmCTestSubmitHandlerVectorOfChar *vec
+ = static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
+ vec->insert(vec->end(), chPtr, chPtr + size);
+
+ return size;
+}
+
+//----------------------------------------------------------------------------
+cmCTestSubmitHandler::cmCTestSubmitHandler() : HTTPProxy(), FTPProxy()
+{
+ this->Initialize();
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSubmitHandler::Initialize()
+{
+ // We submit all available parts by default.
+ for(cmCTest::Part p = cmCTest::PartStart;
+ p != cmCTest::PartCount; p = cmCTest::Part(p+1))
+ {
+ this->SubmitPart[p] = true;
+ }
+ this->CDash = false;
+ this->HasWarnings = false;
+ this->HasErrors = false;
+ this->Superclass::Initialize();
+ this->HTTPProxy = "";
+ this->HTTPProxyType = 0;
+ this->HTTPProxyAuth = "";
+ this->FTPProxy = "";
+ this->FTPProxyType = 0;
+ this->LogFile = 0;
+ this->Files.clear();
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestSubmitHandler::SubmitUsingFTP(const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url)
+{
+ CURL *curl;
+ CURLcode res;
+ FILE* ftpfile;
+ char error_buffer[1024];
+
+ /* In windows, this will init the winsock stuff */
+ ::curl_global_init(CURL_GLOBAL_ALL);
+
+ cmCTest::SetOfStrings::const_iterator file;
+ for ( file = files.begin(); file != files.end(); ++file )
+ {
+ /* get a curl handle */
+ curl = curl_easy_init();
+ if(curl)
+ {
+ // Using proxy
+ if ( this->FTPProxyType > 0 )
+ {
+ curl_easy_setopt(curl, CURLOPT_PROXY, this->FTPProxy.c_str());
+ switch (this->FTPProxyType)
+ {
+ case 2:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+ break;
+ case 3:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+ break;
+ default:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+ }
+ }
+
+ // enable uploading
+ ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
+
+ // if there is little to no activity for too long stop submitting
+ ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
+ ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
+ SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
+
+ ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
+
+ std::string local_file = *file;
+ if ( !cmSystemTools::FileExists(local_file.c_str()) )
+ {
+ local_file = localprefix + "/" + *file;
+ }
+ std::string upload_as
+ = url + "/" + remoteprefix + cmSystemTools::GetFilenameName(*file);
+
+
+ if ( !cmSystemTools::FileExists(local_file.c_str()) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Cannot find file: "
+ << local_file << std::endl);
+ ::curl_easy_cleanup(curl);
+ ::curl_global_cleanup();
+ return false;
+ }
+ unsigned long filelen = cmSystemTools::FileLength(local_file.c_str());
+
+ ftpfile = cmsys::SystemTools::Fopen(local_file.c_str(), "rb");
+ *this->LogFile << "\tUpload file: " << local_file << " to "
+ << upload_as << std::endl;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Upload file: "
+ << local_file << " to "
+ << upload_as << std::endl);
+
+ ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+
+ // specify target
+ ::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
+
+ // now specify which file to upload
+ ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
+
+ // and give the size of the upload (optional)
+ ::curl_easy_setopt(curl, CURLOPT_INFILESIZE,
+ static_cast<long>(filelen));
+
+ // and give curl the buffer for errors
+ ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
+
+ // specify handler for output
+ ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
+ cmCTestSubmitHandlerWriteMemoryCallback);
+ ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
+ cmCTestSubmitHandlerCurlDebugCallback);
+
+ /* we pass our 'chunk' struct to the callback function */
+ cmCTestSubmitHandlerVectorOfChar chunk;
+ cmCTestSubmitHandlerVectorOfChar chunkDebug;
+ ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);
+ ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
+
+ // Now run off and do what you've been told!
+ res = ::curl_easy_perform(curl);
+
+ if ( chunk.size() > 0 )
+ {
+ cmCTestLog(this->CTest, DEBUG, "CURL output: ["
+ << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
+ << std::endl);
+ }
+ if ( chunkDebug.size() > 0 )
+ {
+ cmCTestLog(this->CTest, DEBUG, "CURL debug output: ["
+ << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
+ << std::endl);
+ }
+
+ fclose(ftpfile);
+ if ( res )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Error when uploading file: "
+ << local_file << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Error message was: "
+ << error_buffer << std::endl);
+ *this->LogFile << " Error when uploading file: "
+ << local_file
+ << std::endl
+ << " Error message was: "
+ << error_buffer << std::endl
+ << " Curl output was: ";
+ // avoid dereference of empty vector
+ if(chunk.size())
+ {
+ *this->LogFile << cmCTestLogWrite(&*chunk.begin(), chunk.size());
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
+ << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
+ << std::endl);
+ }
+ *this->LogFile << std::endl;
+ ::curl_easy_cleanup(curl);
+ ::curl_global_cleanup();
+ return false;
+ }
+ // always cleanup
+ ::curl_easy_cleanup(curl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Uploaded: " + local_file
+ << std::endl);
+ }
+ }
+ ::curl_global_cleanup();
+ return true;
+}
+
+//----------------------------------------------------------------------------
+// Uploading files is simpler
+bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url)
+{
+ CURL *curl;
+ CURLcode res;
+ FILE* ftpfile;
+ char error_buffer[1024];
+
+ /* In windows, this will init the winsock stuff */
+ ::curl_global_init(CURL_GLOBAL_ALL);
+ std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
+ std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
+ std::vector<std::string> args;
+ cmSystemTools::ExpandListArgument(curlopt, args);
+ bool verifyPeerOff = false;
+ bool verifyHostOff = false;
+ for( std::vector<std::string>::iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ if(*i == "CURLOPT_SSL_VERIFYPEER_OFF")
+ {
+ verifyPeerOff = true;
+ }
+ if(*i == "CURLOPT_SSL_VERIFYHOST_OFF")
+ {
+ verifyHostOff = true;
+ }
+ }
+ std::string::size_type kk;
+ cmCTest::SetOfStrings::const_iterator file;
+ for ( file = files.begin(); file != files.end(); ++file )
+ {
+ /* get a curl handle */
+ curl = curl_easy_init();
+ if(curl)
+ {
+ if(verifyPeerOff)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Set CURLOPT_SSL_VERIFYPEER to off\n");
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
+ }
+ if(verifyHostOff)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Set CURLOPT_SSL_VERIFYHOST to off\n");
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
+ }
+
+ // Using proxy
+ if ( this->HTTPProxyType > 0 )
+ {
+ curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
+ switch (this->HTTPProxyType)
+ {
+ case 2:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+ break;
+ case 3:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+ break;
+ default:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+ if (this->HTTPProxyAuth.size() > 0)
+ {
+ curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
+ this->HTTPProxyAuth.c_str());
+ }
+ }
+ }
+ if(this->CTest->ShouldUseHTTP10())
+ {
+ curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+ }
+ // enable HTTP ERROR parsing
+ curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+ /* enable uploading */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
+
+ // if there is little to no activity for too long stop submitting
+ ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
+ ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
+ SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
+
+ /* HTTP PUT please */
+ ::curl_easy_setopt(curl, CURLOPT_PUT, 1);
+ ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+
+ std::string local_file = *file;
+ if ( !cmSystemTools::FileExists(local_file.c_str()) )
+ {
+ local_file = localprefix + "/" + *file;
+ }
+ std::string remote_file
+ = remoteprefix + cmSystemTools::GetFilenameName(*file);
+
+ *this->LogFile << "\tUpload file: " << local_file << " to "
+ << remote_file << std::endl;
+
+ std::string ofile = "";
+ for ( kk = 0; kk < remote_file.size(); kk ++ )
+ {
+ char c = remote_file[kk];
+ char hexCh[4] = { 0, 0, 0, 0 };
+ hexCh[0] = c;
+ switch ( c )
+ {
+ case '+':
+ case '?':
+ case '/':
+ case '\\':
+ case '&':
+ case ' ':
+ case '=':
+ case '%':
+ sprintf(hexCh, "%%%02X", (int)c);
+ ofile.append(hexCh);
+ break;
+ default:
+ ofile.append(hexCh);
+ }
+ }
+ std::string upload_as
+ = url + ((url.find("?",0) == std::string::npos) ? "?" : "&")
+ + "FileName=" + ofile;
+
+ upload_as += "&MD5=";
+
+ if(cmSystemTools::IsOn(this->GetOption("InternalTest")))
+ {
+ upload_as += "bad_md5sum";
+ }
+ else
+ {
+ char md5[33];
+ cmSystemTools::ComputeFileMD5(local_file, md5);
+ md5[32] = 0;
+ upload_as += md5;
+ }
+
+ if( !cmSystemTools::FileExists(local_file.c_str()) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Cannot find file: "
+ << local_file << std::endl);
+ ::curl_easy_cleanup(curl);
+ ::curl_global_cleanup();
+ return false;
+ }
+ unsigned long filelen = cmSystemTools::FileLength(local_file.c_str());
+
+ ftpfile = cmsys::SystemTools::Fopen(local_file.c_str(), "rb");
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Upload file: "
+ << local_file << " to "
+ << upload_as << " Size: " << filelen << std::endl);
+
+ // specify target
+ ::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
+
+ // now specify which file to upload
+ ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
+
+ // and give the size of the upload (optional)
+ ::curl_easy_setopt(curl, CURLOPT_INFILESIZE,
+ static_cast<long>(filelen));
+
+ // and give curl the buffer for errors
+ ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
+
+ // specify handler for output
+ ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
+ cmCTestSubmitHandlerWriteMemoryCallback);
+ ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
+ cmCTestSubmitHandlerCurlDebugCallback);
+
+ /* we pass our 'chunk' struct to the callback function */
+ cmCTestSubmitHandlerVectorOfChar chunk;
+ cmCTestSubmitHandlerVectorOfChar chunkDebug;
+ ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);
+ ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
+
+ // Now run off and do what you've been told!
+ res = ::curl_easy_perform(curl);
+
+ if(cmSystemTools::IsOn(this->GetOption("InternalTest")) &&
+ cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
+ this->CTest->GetCDashVersion().c_str(), "1.7"))
+ {
+ // mock failure output for internal test case
+ std::string mock_output = "<cdash version=\"1.7.0\">\n"
+ " <status>ERROR</status>\n"
+ " <message>Checksum failed for file.</message>\n"
+ "</cdash>\n";
+ chunk.clear();
+ chunk.assign(mock_output.begin(), mock_output.end());
+ }
+
+ if ( chunk.size() > 0 )
+ {
+ cmCTestLog(this->CTest, DEBUG, "CURL output: ["
+ << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
+ << std::endl);
+ this->ParseResponse(chunk);
+ }
+ if ( chunkDebug.size() > 0 )
+ {
+ cmCTestLog(this->CTest, DEBUG, "CURL debug output: ["
+ << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
+ << std::endl);
+ }
+
+ // If curl failed for any reason, or checksum fails, wait and retry
+ //
+ if(res != CURLE_OK || this->HasErrors)
+ {
+ std::string retryDelay = this->GetOption("RetryDelay") == NULL ?
+ "" : this->GetOption("RetryDelay");
+ std::string retryCount = this->GetOption("RetryCount") == NULL ?
+ "" : this->GetOption("RetryCount");
+
+ int delay = retryDelay == "" ? atoi(this->CTest->GetCTestConfiguration(
+ "CTestSubmitRetryDelay").c_str()) : atoi(retryDelay.c_str());
+ int count = retryCount == "" ? atoi(this->CTest->GetCTestConfiguration(
+ "CTestSubmitRetryCount").c_str()) : atoi(retryCount.c_str());
+
+ for(int i = 0; i < count; i++)
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Submit failed, waiting " << delay << " seconds...\n");
+
+ double stop = cmSystemTools::GetTime() + delay;
+ while(cmSystemTools::GetTime() < stop)
+ {
+ cmSystemTools::Delay(100);
+ }
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Retry submission: Attempt " << (i + 1) << " of "
+ << count << std::endl);
+
+ ::fclose(ftpfile);
+ ftpfile = cmsys::SystemTools::Fopen(local_file.c_str(), "rb");
+ ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
+
+ chunk.clear();
+ chunkDebug.clear();
+ this->HasErrors = false;
+
+ res = ::curl_easy_perform(curl);
+
+ if ( chunk.size() > 0 )
+ {
+ cmCTestLog(this->CTest, DEBUG, "CURL output: ["
+ << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
+ << std::endl);
+ this->ParseResponse(chunk);
+ }
+
+ if(res == CURLE_OK && !this->HasErrors)
+ {
+ break;
+ }
+ }
+ }
+
+ fclose(ftpfile);
+ if ( res )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Error when uploading file: "
+ << local_file << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Error message was: "
+ << error_buffer << std::endl);
+ *this->LogFile << " Error when uploading file: "
+ << local_file
+ << std::endl
+ << " Error message was: " << error_buffer
+ << std::endl;
+ // avoid deref of begin for zero size array
+ if(chunk.size())
+ {
+ *this->LogFile << " Curl output was: "
+ << cmCTestLogWrite(&*chunk.begin(), chunk.size())
+ << std::endl;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
+ << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
+ << std::endl);
+ }
+ ::curl_easy_cleanup(curl);
+ ::curl_global_cleanup();
+ return false;
+ }
+ // always cleanup
+ ::curl_easy_cleanup(curl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Uploaded: " + local_file
+ << std::endl);
+ }
+ }
+ ::curl_global_cleanup();
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSubmitHandler
+::ParseResponse(cmCTestSubmitHandlerVectorOfChar chunk)
+{
+ std::string output = "";
+ output.append(chunk.begin(), chunk.end());
+
+ if(output.find("<cdash") != output.npos)
+ {
+ ResponseParser parser;
+ parser.Parse(output.c_str());
+
+ if(parser.Status != ResponseParser::STATUS_OK)
+ {
+ this->HasErrors = true;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submission failed: " <<
+ parser.Message << std::endl);
+ return;
+ }
+ }
+ output = cmSystemTools::UpperCase(output);
+ if(output.find("WARNING") != std::string::npos)
+ {
+ this->HasWarnings = true;
+ }
+ if(output.find("ERROR") != std::string::npos)
+ {
+ this->HasErrors = true;
+ }
+
+ if(this->HasWarnings || this->HasErrors)
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Server Response:\n" <<
+ cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestSubmitHandler::TriggerUsingHTTP(
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url)
+{
+ CURL *curl;
+ char error_buffer[1024];
+ /* In windows, this will init the winsock stuff */
+ ::curl_global_init(CURL_GLOBAL_ALL);
+
+ cmCTest::SetOfStrings::const_iterator file;
+ for ( file = files.begin(); file != files.end(); ++file )
+ {
+ /* get a curl handle */
+ curl = curl_easy_init();
+ if(curl)
+ {
+ // Using proxy
+ if ( this->HTTPProxyType > 0 )
+ {
+ curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
+ switch (this->HTTPProxyType)
+ {
+ case 2:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+ break;
+ case 3:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+ break;
+ default:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+ if (this->HTTPProxyAuth.size() > 0)
+ {
+ curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
+ this->HTTPProxyAuth.c_str());
+ }
+ }
+ }
+
+ ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+
+ // and give curl the buffer for errors
+ ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
+
+ // specify handler for output
+ ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
+ cmCTestSubmitHandlerWriteMemoryCallback);
+ ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
+ cmCTestSubmitHandlerCurlDebugCallback);
+
+ /* we pass our 'chunk' struct to the callback function */
+ cmCTestSubmitHandlerVectorOfChar chunk;
+ cmCTestSubmitHandlerVectorOfChar chunkDebug;
+ ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);
+ ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
+
+ std::string rfile
+ = remoteprefix + cmSystemTools::GetFilenameName(*file);
+ std::string ofile = "";
+ std::string::iterator kk;
+ for ( kk = rfile.begin(); kk < rfile.end(); ++ kk)
+ {
+ char c = *kk;
+ char hexCh[4] = { 0, 0, 0, 0 };
+ hexCh[0] = c;
+ switch ( c )
+ {
+ case '+':
+ case '?':
+ case '/':
+ case '\\':
+ case '&':
+ case ' ':
+ case '=':
+ case '%':
+ sprintf(hexCh, "%%%02X", (int)c);
+ ofile.append(hexCh);
+ break;
+ default:
+ ofile.append(hexCh);
+ }
+ }
+ std::string turl
+ = url + ((url.find("?",0) == std::string::npos) ? "?" : "&")
+ + "xmlfile=" + ofile;
+ *this->LogFile << "Trigger url: " << turl << std::endl;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Trigger url: "
+ << turl << std::endl);
+ curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
+ curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
+ if ( curl_easy_perform(curl) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Error when triggering: "
+ << turl << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Error message was: "
+ << error_buffer << std::endl);
+ *this->LogFile << "\tTriggering failed with error: " << error_buffer
+ << std::endl
+ << " Error message was: " << error_buffer
+ << std::endl;
+ if(chunk.size())
+ {
+ *this->LogFile
+ << " Curl output was: "
+ << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << std::endl;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
+ << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
+ << std::endl);
+ }
+ ::curl_easy_cleanup(curl);
+ ::curl_global_cleanup();
+ return false;
+ }
+
+ if ( chunk.size() > 0 )
+ {
+ cmCTestLog(this->CTest, DEBUG, "CURL output: ["
+ << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
+ << std::endl);
+ }
+ if ( chunkDebug.size() > 0 )
+ {
+ cmCTestLog(this->CTest, DEBUG, "CURL debug output: ["
+ << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size())
+ << "]" << std::endl);
+ }
+
+ // always cleanup
+ ::curl_easy_cleanup(curl);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
+ }
+ }
+ ::curl_global_cleanup();
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Dart server triggered..."
+ << std::endl);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestSubmitHandler::SubmitUsingSCP(
+ const std::string& scp_command,
+ const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url)
+{
+ if ( !scp_command.size() || !localprefix.size() ||
+ !files.size() || !remoteprefix.size() || !url.size() )
+ {
+ return 0;
+ }
+ std::vector<const char*> argv;
+ argv.push_back(scp_command.c_str()); // Scp command
+ argv.push_back(scp_command.c_str()); // Dummy string for file
+ argv.push_back(scp_command.c_str()); // Dummy string for remote url
+ argv.push_back(0);
+
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+ //cmsysProcess_SetTimeout(cp, timeout);
+
+ int problems = 0;
+
+ cmCTest::SetOfStrings::const_iterator file;
+ for ( file = files.begin(); file != files.end(); ++file )
+ {
+ int retVal;
+
+ std::string lfname = localprefix;
+ cmSystemTools::ConvertToUnixSlashes(lfname);
+ lfname += "/" + *file;
+ lfname = cmSystemTools::ConvertToOutputPath(lfname.c_str());
+ argv[1] = lfname.c_str();
+ std::string rfname = url + "/" + remoteprefix + *file;
+ argv[2] = rfname.c_str();
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Execute \"" << argv[0]
+ << "\" \"" << argv[1] << "\" \""
+ << argv[2] << "\"" << std::endl);
+ *this->LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
+ << argv[2] << "\"" << std::endl;
+
+ cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_Execute(cp);
+ char* data;
+ int length;
+
+ while(cmsysProcess_WaitForData(cp, &data, &length, 0))
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ cmCTestLogWrite(data, length));
+ }
+
+ cmsysProcess_WaitForExit(cp, 0);
+
+ int result = cmsysProcess_GetState(cp);
+
+ if(result == cmsysProcess_State_Exited)
+ {
+ retVal = cmsysProcess_GetExitValue(cp);
+ if ( retVal != 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "\tSCP returned: "
+ << retVal << std::endl);
+ *this->LogFile << "\tSCP returned: " << retVal << std::endl;
+ problems ++;
+ }
+ }
+ else if(result == cmsysProcess_State_Exception)
+ {
+ retVal = cmsysProcess_GetExitException(cp);
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "\tThere was an exception: "
+ << retVal << std::endl);
+ *this->LogFile << "\tThere was an exception: " << retVal << std::endl;
+ problems ++;
+ }
+ else if(result == cmsysProcess_State_Expired)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "\tThere was a timeout"
+ << std::endl);
+ *this->LogFile << "\tThere was a timeout" << std::endl;
+ problems ++;
+ }
+ else if(result == cmsysProcess_State_Error)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "\tError executing SCP: "
+ << cmsysProcess_GetErrorString(cp) << std::endl);
+ *this->LogFile << "\tError executing SCP: "
+ << cmsysProcess_GetErrorString(cp) << std::endl;
+ problems ++;
+ }
+ }
+ cmsysProcess_Delete(cp);
+ if ( problems )
+ {
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestSubmitHandler::SubmitUsingCP(
+ const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& destination)
+{
+ if ( !localprefix.size() ||
+ !files.size() || !remoteprefix.size() || !destination.size() )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Missing arguments for submit via cp:\n"
+ << "\tlocalprefix: " << localprefix << "\n"
+ << "\tNumber of files: " << files.size() << "\n"
+ << "\tremoteprefix: " << remoteprefix << "\n"
+ << "\tdestination: " << destination << std::endl);
+ return 0;
+ }
+ cmCTest::SetOfStrings::const_iterator file;
+ bool problems = false;
+ for ( file = files.begin(); file != files.end(); ++file )
+ {
+ std::string lfname = localprefix;
+ cmSystemTools::ConvertToUnixSlashes(lfname);
+ lfname += "/" + *file;
+ std::string rfname = destination + "/" + remoteprefix + *file;
+ cmSystemTools::CopyFileAlways(lfname.c_str(), rfname.c_str());
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Copy file: "
+ << lfname << " to "
+ << rfname << std::endl);
+ }
+ std::string tagDoneFile = destination + "/" + remoteprefix + "DONE";
+ cmSystemTools::Touch(tagDoneFile.c_str(), true);
+ if ( problems )
+ {
+ return false;
+ }
+ return true;
+}
+
+
+//----------------------------------------------------------------------------
+#if defined(CTEST_USE_XMLRPC)
+bool cmCTestSubmitHandler::SubmitUsingXMLRPC(const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url)
+{
+ xmlrpc_env env;
+ char ctestString[] = "CTest";
+ std::string ctestVersionString = cmVersion::GetCMakeVersion();
+ char* ctestVersion = const_cast<char*>(ctestVersionString.c_str());
+
+ std::string realURL = url + "/" + remoteprefix + "/Command/";
+
+ /* Start up our XML-RPC client library. */
+ xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, ctestString, ctestVersion);
+
+ /* Initialize our error-handling environment. */
+ xmlrpc_env_init(&env);
+
+ /* Call the famous server at UserLand. */
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submitting to: "
+ << realURL.c_str() << " (" << remoteprefix.c_str() << ")" << std::endl);
+ cmCTest::SetOfStrings::const_iterator file;
+ for ( file = files.begin(); file != files.end(); ++file )
+ {
+ xmlrpc_value *result;
+
+ std::string local_file = *file;
+ if ( !cmSystemTools::FileExists(local_file.c_str()) )
+ {
+ local_file = localprefix + "/" + *file;
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submit file: "
+ << local_file.c_str() << std::endl);
+ struct stat st;
+ if ( ::stat(local_file.c_str(), &st) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Cannot find file: "
+ << local_file.c_str() << std::endl);
+ return false;
+ }
+
+ // off_t can be bigger than size_t. fread takes size_t.
+ // make sure the file is not too big.
+ if(static_cast<off_t>(static_cast<size_t>(st.st_size)) !=
+ static_cast<off_t>(st.st_size))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " File too big: "
+ << local_file.c_str() << std::endl);
+ return false;
+ }
+ size_t fileSize = static_cast<size_t>(st.st_size);
+ FILE* fp = cmsys::SystemTools::Fopen(local_file.c_str(), "rb");
+ if ( !fp )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Cannot open file: "
+ << local_file.c_str() << std::endl);
+ return false;
+ }
+
+ unsigned char *fileBuffer = new unsigned char[fileSize];
+ if ( fread(fileBuffer, 1, fileSize, fp) != fileSize )
+ {
+ delete [] fileBuffer;
+ fclose(fp);
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Cannot read file: "
+ << local_file.c_str() << std::endl);
+ return false;
+ }
+ fclose(fp);
+
+ char remoteCommand[] = "Submit.put";
+ char* pRealURL = const_cast<char*>(realURL.c_str());
+ result = xmlrpc_client_call(&env, pRealURL, remoteCommand,
+ "(6)", fileBuffer, (xmlrpc_int32)fileSize );
+
+ delete [] fileBuffer;
+
+ if ( env.fault_occurred )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Submission problem: "
+ << env.fault_string << " (" << env.fault_code << ")" << std::endl);
+ xmlrpc_env_clean(&env);
+ xmlrpc_client_cleanup();
+ return false;
+ }
+
+ /* Dispose of our result value. */
+ xmlrpc_DECREF(result);
+ }
+
+ /* Clean up our error-handling environment. */
+ xmlrpc_env_clean(&env);
+
+ /* Shutdown our XML-RPC client library. */
+ xmlrpc_client_cleanup();
+ return true;
+}
+#else
+bool cmCTestSubmitHandler::SubmitUsingXMLRPC(std::string const&,
+ std::set<std::string> const&,
+ std::string const&,
+ std::string const&)
+{
+ return false;
+}
+#endif
+
+//----------------------------------------------------------------------------
+int cmCTestSubmitHandler::ProcessHandler()
+{
+ std::string iscdash = this->CTest->GetCTestConfiguration("IsCDash");
+ // cdash does not need to trigger so just return true
+ if(iscdash.size())
+ {
+ this->CDash = true;
+ }
+
+ const std::string &buildDirectory
+ = this->CTest->GetCTestConfiguration("BuildDirectory");
+ if ( buildDirectory.size() == 0 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find BuildDirectory key in the DartConfiguration.tcl"
+ << std::endl);
+ return -1;
+ }
+
+ if ( getenv("HTTP_PROXY") )
+ {
+ this->HTTPProxyType = 1;
+ this->HTTPProxy = getenv("HTTP_PROXY");
+ if ( getenv("HTTP_PROXY_PORT") )
+ {
+ this->HTTPProxy += ":";
+ this->HTTPProxy += getenv("HTTP_PROXY_PORT");
+ }
+ if ( getenv("HTTP_PROXY_TYPE") )
+ {
+ std::string type = getenv("HTTP_PROXY_TYPE");
+ // HTTP/SOCKS4/SOCKS5
+ if ( type == "HTTP" )
+ {
+ this->HTTPProxyType = 1;
+ }
+ else if ( type == "SOCKS4" )
+ {
+ this->HTTPProxyType = 2;
+ }
+ else if ( type == "SOCKS5" )
+ {
+ this->HTTPProxyType = 3;
+ }
+ }
+ if ( getenv("HTTP_PROXY_USER") )
+ {
+ this->HTTPProxyAuth = getenv("HTTP_PROXY_USER");
+ }
+ if ( getenv("HTTP_PROXY_PASSWD") )
+ {
+ this->HTTPProxyAuth += ":";
+ this->HTTPProxyAuth += getenv("HTTP_PROXY_PASSWD");
+ }
+ }
+
+ if ( getenv("FTP_PROXY") )
+ {
+ this->FTPProxyType = 1;
+ this->FTPProxy = getenv("FTP_PROXY");
+ if ( getenv("FTP_PROXY_PORT") )
+ {
+ this->FTPProxy += ":";
+ this->FTPProxy += getenv("FTP_PROXY_PORT");
+ }
+ if ( getenv("FTP_PROXY_TYPE") )
+ {
+ std::string type = getenv("FTP_PROXY_TYPE");
+ // HTTP/SOCKS4/SOCKS5
+ if ( type == "HTTP" )
+ {
+ this->FTPProxyType = 1;
+ }
+ else if ( type == "SOCKS4" )
+ {
+ this->FTPProxyType = 2;
+ }
+ else if ( type == "SOCKS5" )
+ {
+ this->FTPProxyType = 3;
+ }
+ }
+ }
+
+ if ( this->HTTPProxy.size() > 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Use HTTP Proxy: "
+ << this->HTTPProxy << std::endl);
+ }
+ if ( this->FTPProxy.size() > 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Use FTP Proxy: "
+ << this->FTPProxy << std::endl);
+ }
+ cmGeneratedFileStream ofs;
+ this->StartLogFile("Submit", ofs);
+
+ cmCTest::SetOfStrings files;
+ std::string prefix = this->GetSubmitResultsPrefix();
+
+ if (!this->Files.empty())
+ {
+ // Submit the explicitly selected files:
+ //
+ cmCTest::SetOfStrings::const_iterator it;
+ for (it = this->Files.begin(); it != this->Files.end(); ++it)
+ {
+ files.insert(*it);
+ }
+ }
+
+ // Add to the list of files to submit from any selected, existing parts:
+ //
+
+ // TODO:
+ // Check if test is enabled
+
+ this->CTest->AddIfExists(cmCTest::PartUpdate, "Update.xml");
+ this->CTest->AddIfExists(cmCTest::PartConfigure, "Configure.xml");
+ this->CTest->AddIfExists(cmCTest::PartBuild, "Build.xml");
+ this->CTest->AddIfExists(cmCTest::PartTest, "Test.xml");
+ if(this->CTest->AddIfExists(cmCTest::PartCoverage, "Coverage.xml"))
+ {
+ std::vector<std::string> gfiles;
+ std::string gpath
+ = buildDirectory + "/Testing/" + this->CTest->GetCurrentTag();
+ std::string::size_type glen = gpath.size() + 1;
+ gpath = gpath + "/CoverageLog*";
+ cmCTestLog(this->CTest, DEBUG, "Globbing for: " << gpath
+ << std::endl);
+ if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
+ {
+ size_t cc;
+ for ( cc = 0; cc < gfiles.size(); cc ++ )
+ {
+ gfiles[cc] = gfiles[cc].substr(glen);
+ cmCTestLog(this->CTest, DEBUG, "Glob file: " << gfiles[cc]
+ << std::endl);
+ this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfiles[cc].c_str());
+ }
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing" << std::endl);
+ }
+ }
+ this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml");
+ this->CTest->AddIfExists(cmCTest::PartMemCheck, "Purify.xml");
+ this->CTest->AddIfExists(cmCTest::PartNotes, "Notes.xml");
+ this->CTest->AddIfExists(cmCTest::PartUpload, "Upload.xml");
+
+ // Query parts for files to submit.
+ for(cmCTest::Part p = cmCTest::PartStart;
+ p != cmCTest::PartCount; p = cmCTest::Part(p+1))
+ {
+ // Skip parts we are not submitting.
+ if(!this->SubmitPart[p])
+ {
+ continue;
+ }
+
+ // Submit files from this part.
+ std::vector<std::string> const& pfiles = this->CTest->GetSubmitFiles(p);
+ for(std::vector<std::string>::const_iterator pi = pfiles.begin();
+ pi != pfiles.end(); ++pi)
+ {
+ files.insert(*pi);
+ }
+ }
+
+ if ( ofs )
+ {
+ ofs << "Upload files:" << std::endl;
+ int cnt = 0;
+ cmCTest::SetOfStrings::iterator it;
+ for ( it = files.begin(); it != files.end(); ++ it )
+ {
+ ofs << cnt << "\t" << *it << std::endl;
+ cnt ++;
+ }
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "Submit files (using "
+ << this->CTest->GetCTestConfiguration("DropMethod") << ")"
+ << std::endl);
+ const char* specificTrack = this->CTest->GetSpecificTrack();
+ if ( specificTrack )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Send to track: "
+ << specificTrack << std::endl);
+ }
+ this->SetLogFile(&ofs);
+
+ std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
+
+ if ( dropMethod == "" || dropMethod == "ftp" )
+ {
+ ofs << "Using drop method: FTP" << std::endl;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Using FTP submit method"
+ << std::endl
+ << " Drop site: ftp://");
+ std::string url = "ftp://";
+ url += cmCTest::MakeURLSafe(
+ this->CTest->GetCTestConfiguration("DropSiteUser")) + ":" +
+ cmCTest::MakeURLSafe(this->CTest->GetCTestConfiguration(
+ "DropSitePassword")) + "@" +
+ this->CTest->GetCTestConfiguration("DropSite") +
+ cmCTest::MakeURLSafe(
+ this->CTest->GetCTestConfiguration("DropLocation"));
+ if ( this->CTest->GetCTestConfiguration("DropSiteUser").size() > 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ this->CTest->GetCTestConfiguration(
+ "DropSiteUser").c_str());
+ if ( this->CTest->GetCTestConfiguration("DropSitePassword").size() > 0 )
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, ":******");
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "@");
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ this->CTest->GetCTestConfiguration("DropSite")
+ << this->CTest->GetCTestConfiguration("DropLocation") << std::endl);
+ if ( !this->SubmitUsingFTP(buildDirectory + "/Testing/"
+ + this->CTest->GetCurrentTag(),
+ files, prefix, url) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Problems when submitting via FTP"
+ << std::endl);
+ ofs << " Problems when submitting via FTP" << std::endl;
+ return -1;
+ }
+ if(!this->CDash)
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
+ << std::endl
+ << " Trigger site: "
+ << this->CTest->GetCTestConfiguration("TriggerSite")
+ << std::endl);
+ if ( !this->
+ TriggerUsingHTTP(files, prefix,
+ this->CTest->GetCTestConfiguration("TriggerSite")))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Problems when triggering via HTTP" << std::endl);
+ ofs << " Problems when triggering via HTTP" << std::endl;
+ return -1;
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submission successful"
+ << std::endl);
+ ofs << " Submission successful" << std::endl;
+ return 0;
+ }
+ }
+ else if ( dropMethod == "http" || dropMethod == "https" )
+ {
+ std::string url = dropMethod;
+ url += "://";
+ ofs << "Using drop method: " << dropMethod << std::endl;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Using HTTP submit method"
+ << std::endl
+ << " Drop site:" << url);
+ if ( this->CTest->GetCTestConfiguration("DropSiteUser").size() > 0 )
+ {
+ url += this->CTest->GetCTestConfiguration("DropSiteUser");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ this->CTest->GetCTestConfiguration("DropSiteUser").c_str());
+ if ( this->CTest->GetCTestConfiguration("DropSitePassword").size() > 0 )
+ {
+ url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, ":******");
+ }
+ url += "@";
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "@");
+ }
+ url += this->CTest->GetCTestConfiguration("DropSite") +
+ this->CTest->GetCTestConfiguration("DropLocation");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ this->CTest->GetCTestConfiguration("DropSite")
+ << this->CTest->GetCTestConfiguration("DropLocation") << std::endl);
+ if ( !this->SubmitUsingHTTP(buildDirectory + "/Testing/" +
+ this->CTest->GetCurrentTag(), files, prefix, url) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Problems when submitting via HTTP" << std::endl);
+ ofs << " Problems when submitting via HTTP" << std::endl;
+ return -1;
+ }
+ if(!this->CDash)
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
+ << std::endl
+ << " Trigger site: "
+ << this->CTest->GetCTestConfiguration("TriggerSite")
+ << std::endl);
+ if ( !this->
+ TriggerUsingHTTP(files, prefix,
+ this->CTest->GetCTestConfiguration("TriggerSite")))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Problems when triggering via HTTP" << std::endl);
+ ofs << " Problems when triggering via HTTP" << std::endl;
+ return -1;
+ }
+ }
+ if(this->HasErrors)
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Errors occurred during "
+ "submission." << std::endl);
+ ofs << " Errors occurred during submission. " << std::endl;
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submission successful" <<
+ (this->HasWarnings ? ", with warnings." : "") << std::endl);
+ ofs << " Submission successful" <<
+ (this->HasWarnings ? ", with warnings." : "") << std::endl;
+ }
+
+ return 0;
+ }
+ else if ( dropMethod == "xmlrpc" )
+ {
+#if defined(CTEST_USE_XMLRPC)
+ ofs << "Using drop method: XML-RPC" << std::endl;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Using XML-RPC submit method"
+ << std::endl);
+ std::string url = this->CTest->GetCTestConfiguration("DropSite");
+ prefix = this->CTest->GetCTestConfiguration("DropLocation");
+ if ( !this->SubmitUsingXMLRPC(buildDirectory + "/Testing/" +
+ this->CTest->GetCurrentTag(), files, prefix, url) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Problems when submitting via XML-RPC" << std::endl);
+ ofs << " Problems when submitting via XML-RPC" << std::endl;
+ return -1;
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submission successful"
+ << std::endl);
+ ofs << " Submission successful" << std::endl;
+ return 0;
+#else
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Submission method \"xmlrpc\" not compiled into CTest!"
+ << std::endl);
+ return -1;
+#endif
+ }
+ else if ( dropMethod == "scp" )
+ {
+ std::string url;
+ std::string oldWorkingDirectory;
+ if ( this->CTest->GetCTestConfiguration("DropSiteUser").size() > 0 )
+ {
+ url += this->CTest->GetCTestConfiguration("DropSiteUser") + "@";
+ }
+ url += this->CTest->GetCTestConfiguration("DropSite") + ":" +
+ this->CTest->GetCTestConfiguration("DropLocation");
+
+ // change to the build directory so that we can uses a relative path
+ // on windows since scp dosn't support "c:" a drive in the path
+ oldWorkingDirectory = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(buildDirectory.c_str());
+
+ if ( !this->SubmitUsingSCP(
+ this->CTest->GetCTestConfiguration("ScpCommand"),
+ "Testing/"+this->CTest->GetCurrentTag(), files, prefix, url) )
+ {
+ cmSystemTools::ChangeDirectory(oldWorkingDirectory.c_str());
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Problems when submitting via SCP"
+ << std::endl);
+ ofs << " Problems when submitting via SCP" << std::endl;
+ return -1;
+ }
+ cmSystemTools::ChangeDirectory(oldWorkingDirectory.c_str());
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submission successful"
+ << std::endl);
+ ofs << " Submission successful" << std::endl;
+ return 0;
+ }
+ else if ( dropMethod == "cp" )
+ {
+ std::string location
+ = this->CTest->GetCTestConfiguration("DropLocation");
+
+
+ // change to the build directory so that we can uses a relative path
+ // on windows since scp dosn't support "c:" a drive in the path
+ std::string
+ oldWorkingDirectory = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(buildDirectory.c_str());
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Change directory: "
+ << buildDirectory << std::endl);
+
+ if ( !this->SubmitUsingCP(
+ "Testing/"+this->CTest->GetCurrentTag(),
+ files,
+ prefix,
+ location) )
+ {
+ cmSystemTools::ChangeDirectory(oldWorkingDirectory.c_str());
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " Problems when submitting via CP"
+ << std::endl);
+ ofs << " Problems when submitting via cp" << std::endl;
+ return -1;
+ }
+ cmSystemTools::ChangeDirectory(oldWorkingDirectory.c_str());
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submission successful"
+ << std::endl);
+ ofs << " Submission successful" << std::endl;
+ return 0;
+ }
+
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Unknown submission method: \""
+ << dropMethod << "\"" << std::endl);
+ return -1;
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTestSubmitHandler::GetSubmitResultsPrefix()
+{
+ std::string buildname = cmCTest::SafeBuildIdField(
+ this->CTest->GetCTestConfiguration("BuildName"));
+ std::string name = this->CTest->GetCTestConfiguration("Site") +
+ "___" + buildname +
+ "___" + this->CTest->GetCurrentTag() + "-" +
+ this->CTest->GetTestModelString() + "___XML___";
+ return name;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSubmitHandler::SelectParts(std::set<cmCTest::Part> const& parts)
+{
+ // Check whether each part is selected.
+ for(cmCTest::Part p = cmCTest::PartStart;
+ p != cmCTest::PartCount; p = cmCTest::Part(p+1))
+ {
+ this->SubmitPart[p] =
+ (std::set<cmCTest::Part>::const_iterator(parts.find(p)) != parts.end());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCTestSubmitHandler::SelectFiles(cmCTest::SetOfStrings const& files)
+{
+ cmCTest::SetOfStrings::const_iterator it;
+ for (it = files.begin(); it != files.end(); ++it)
+ {
+ this->Files.insert(*it);
+ }
+}
diff --git a/Source/CTest/cmCTestSubmitHandler.h b/Source/CTest/cmCTestSubmitHandler.h
new file mode 100644
index 0000000000..accabd1c5a
--- /dev/null
+++ b/Source/CTest/cmCTestSubmitHandler.h
@@ -0,0 +1,98 @@
+/*============================================================================
+ 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 cmCTestSubmitHandler_h
+#define cmCTestSubmitHandler_h
+
+#include "cmCTestGenericHandler.h"
+
+/** \class cmCTestSubmitHandler
+ * \brief Helper class for CTest
+ *
+ * Submit testing results
+ *
+ */
+class cmCTestSubmitHandler : public cmCTestGenericHandler
+{
+public:
+ cmTypeMacro(cmCTestSubmitHandler, cmCTestGenericHandler);
+
+ cmCTestSubmitHandler();
+ ~cmCTestSubmitHandler() { this->LogFile = 0; }
+
+ /*
+ * The main entry point for this class
+ */
+ int ProcessHandler();
+
+ void Initialize();
+
+ /** Specify a set of parts (by name) to submit. */
+ void SelectParts(std::set<cmCTest::Part> const& parts);
+
+ /** Specify a set of files to submit. */
+ void SelectFiles(cmCTest::SetOfStrings const& files);
+
+private:
+ void SetLogFile(std::ostream* ost) { this->LogFile = ost; }
+
+ /**
+ * Submit file using various ways
+ */
+ bool SubmitUsingFTP(const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url);
+ bool SubmitUsingHTTP(const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url);
+ bool SubmitUsingSCP(const std::string& scp_command,
+ const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url);
+
+ bool SubmitUsingCP( const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url);
+
+ bool TriggerUsingHTTP(const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url);
+
+ bool SubmitUsingXMLRPC(const std::string& localprefix,
+ const std::set<std::string>& files,
+ const std::string& remoteprefix,
+ const std::string& url);
+
+ typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
+
+ void ParseResponse(cmCTestSubmitHandlerVectorOfChar chunk);
+
+ std::string GetSubmitResultsPrefix();
+
+ class ResponseParser;
+ std::string HTTPProxy;
+ int HTTPProxyType;
+ std::string HTTPProxyAuth;
+ std::string FTPProxy;
+ int FTPProxyType;
+ std::ostream* LogFile;
+ bool SubmitPart[cmCTest::PartCount];
+ bool CDash;
+ bool HasWarnings;
+ bool HasErrors;
+ cmCTest::SetOfStrings Files;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestTestCommand.cxx b/Source/CTest/cmCTestTestCommand.cxx
new file mode 100644
index 0000000000..231f035fbb
--- /dev/null
+++ b/Source/CTest/cmCTestTestCommand.cxx
@@ -0,0 +1,112 @@
+/*============================================================================
+ 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 "cmCTestTestCommand.h"
+
+#include "cmCTest.h"
+#include "cmCTestGenericHandler.h"
+
+cmCTestTestCommand::cmCTestTestCommand()
+{
+ this->Arguments[ctt_START] = "START";
+ this->Arguments[ctt_END] = "END";
+ this->Arguments[ctt_STRIDE] = "STRIDE";
+ this->Arguments[ctt_EXCLUDE] = "EXCLUDE";
+ this->Arguments[ctt_INCLUDE] = "INCLUDE";
+ this->Arguments[ctt_EXCLUDE_LABEL] = "EXCLUDE_LABEL";
+ this->Arguments[ctt_INCLUDE_LABEL] = "INCLUDE_LABEL";
+ this->Arguments[ctt_PARALLEL_LEVEL] = "PARALLEL_LEVEL";
+ this->Arguments[ctt_SCHEDULE_RANDOM] = "SCHEDULE_RANDOM";
+ this->Arguments[ctt_STOP_TIME] = "STOP_TIME";
+ this->Arguments[ctt_LAST] = 0;
+ this->Last = ctt_LAST;
+}
+
+cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
+{
+ const char* ctestTimeout =
+ this->Makefile->GetDefinition("CTEST_TEST_TIMEOUT");
+
+ double timeout = this->CTest->GetTimeOut();
+ if ( ctestTimeout )
+ {
+ timeout = atof(ctestTimeout);
+ }
+ else
+ {
+ if ( timeout <= 0 )
+ {
+ // By default use timeout of 10 minutes
+ timeout = 600;
+ }
+ }
+ this->CTest->SetTimeOut(timeout);
+ cmCTestGenericHandler* handler = this->InitializeActualHandler();
+ if ( this->Values[ctt_START] || this->Values[ctt_END] ||
+ this->Values[ctt_STRIDE] )
+ {
+ cmOStringStream testsToRunString;
+ if ( this->Values[ctt_START] )
+ {
+ testsToRunString << this->Values[ctt_START];
+ }
+ testsToRunString << ",";
+ if ( this->Values[ctt_END] )
+ {
+ testsToRunString << this->Values[ctt_END];
+ }
+ testsToRunString << ",";
+ if ( this->Values[ctt_STRIDE] )
+ {
+ testsToRunString << this->Values[ctt_STRIDE];
+ }
+ handler->SetOption("TestsToRunInformation",
+ testsToRunString.str().c_str());
+ }
+ if(this->Values[ctt_EXCLUDE])
+ {
+ handler->SetOption("ExcludeRegularExpression", this->Values[ctt_EXCLUDE]);
+ }
+ if(this->Values[ctt_INCLUDE])
+ {
+ handler->SetOption("IncludeRegularExpression", this->Values[ctt_INCLUDE]);
+ }
+ if(this->Values[ctt_EXCLUDE_LABEL])
+ {
+ handler->SetOption("ExcludeLabelRegularExpression",
+ this->Values[ctt_EXCLUDE_LABEL]);
+ }
+ if(this->Values[ctt_INCLUDE_LABEL])
+ {
+ handler->SetOption("LabelRegularExpression",
+ this->Values[ctt_INCLUDE_LABEL]);
+ }
+ if(this->Values[ctt_PARALLEL_LEVEL])
+ {
+ handler->SetOption("ParallelLevel",
+ this->Values[ctt_PARALLEL_LEVEL]);
+ }
+ if(this->Values[ctt_SCHEDULE_RANDOM])
+ {
+ handler->SetOption("ScheduleRandom",
+ this->Values[ctt_SCHEDULE_RANDOM]);
+ }
+ if(this->Values[ctt_STOP_TIME])
+ {
+ this->CTest->SetStopTime(this->Values[ctt_STOP_TIME]);
+ }
+ return handler;
+}
+
+cmCTestGenericHandler* cmCTestTestCommand::InitializeActualHandler()
+{
+ return this->CTest->GetInitializedHandler("test");
+}
diff --git a/Source/CTest/cmCTestTestCommand.h b/Source/CTest/cmCTestTestCommand.h
new file mode 100644
index 0000000000..a1e5f368fe
--- /dev/null
+++ b/Source/CTest/cmCTestTestCommand.h
@@ -0,0 +1,68 @@
+/*============================================================================
+ 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 cmCTestTestCommand_h
+#define cmCTestTestCommand_h
+
+#include "cmCTestHandlerCommand.h"
+
+/** \class cmCTestTest
+ * \brief Run a ctest script
+ *
+ * cmCTestTestCommand defineds the command to test the project.
+ */
+class cmCTestTestCommand : public cmCTestHandlerCommand
+{
+public:
+
+ cmCTestTestCommand();
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestTestCommand* ni = new cmCTestTestCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_test";}
+
+ cmTypeMacro(cmCTestTestCommand, cmCTestHandlerCommand);
+
+protected:
+ virtual cmCTestGenericHandler* InitializeActualHandler();
+ cmCTestGenericHandler* InitializeHandler();
+
+ enum {
+ ctt_BUILD = ct_LAST,
+ ctt_RETURN_VALUE,
+ ctt_START,
+ ctt_END,
+ ctt_STRIDE,
+ ctt_EXCLUDE,
+ ctt_INCLUDE,
+ ctt_EXCLUDE_LABEL,
+ ctt_INCLUDE_LABEL,
+ ctt_PARALLEL_LEVEL,
+ ctt_SCHEDULE_RANDOM,
+ ctt_STOP_TIME,
+ ctt_LAST
+ };
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
new file mode 100644
index 0000000000..f21d1661d5
--- /dev/null
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -0,0 +1,2391 @@
+/*============================================================================
+ 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 "cmCTestTestHandler.h"
+#include "cmCTestMultiProcessHandler.h"
+#include "cmCTestBatchTestHandler.h"
+#include "cmCTest.h"
+#include "cmCTestRunTest.h"
+#include "cmake.h"
+#include "cmGeneratedFileStream.h"
+#include <cmsys/Process.h>
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Base64.h>
+#include <cmsys/Directory.hxx>
+#include <cmsys/FStream.hxx>
+#include "cmMakefile.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmCommand.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+#include "cm_utf8.h"
+
+#include <stdlib.h>
+#include <math.h>
+#include <float.h>
+
+#include <set>
+
+//----------------------------------------------------------------------
+class cmCTestSubdirCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
+ c->TestHandler = this->TestHandler;
+ return c;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "subdirs";}
+
+ cmTypeMacro(cmCTestSubdirCommand, cmCommand);
+
+ cmCTestTestHandler* TestHandler;
+};
+
+//----------------------------------------------------------------------
+bool cmCTestSubdirCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ std::vector<std::string>::const_iterator it;
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ for ( it = args.begin(); it != args.end(); ++ it )
+ {
+ std::string fname;
+
+ if(cmSystemTools::FileIsFullPath(it->c_str()))
+ {
+ fname = *it;
+ }
+ else
+ {
+ fname = cwd;
+ fname += "/";
+ fname += *it;
+ }
+
+ if ( !cmSystemTools::FileIsDirectory(fname.c_str()) )
+ {
+ // No subdirectory? So what...
+ continue;
+ }
+ cmSystemTools::ChangeDirectory(fname.c_str());
+ const char* testFilename;
+ if( cmSystemTools::FileExists("CTestTestfile.cmake") )
+ {
+ // does the CTestTestfile.cmake exist ?
+ testFilename = "CTestTestfile.cmake";
+ }
+ else if( cmSystemTools::FileExists("DartTestfile.txt") )
+ {
+ // does the DartTestfile.txt exist ?
+ testFilename = "DartTestfile.txt";
+ }
+ else
+ {
+ // No CTestTestfile? Who cares...
+ continue;
+ }
+ fname += "/";
+ fname += testFilename;
+ bool readit =
+ this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
+ fname.c_str());
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ if(!readit)
+ {
+ std::string m = "Could not find include file: ";
+ m += fname;
+ this->SetError(m);
+ return false;
+ }
+ }
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------
+class cmCTestAddSubdirectoryCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestAddSubdirectoryCommand* c = new cmCTestAddSubdirectoryCommand;
+ c->TestHandler = this->TestHandler;
+ return c;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "add_subdirectory";}
+
+ cmTypeMacro(cmCTestAddSubdirectoryCommand, cmCommand);
+
+ cmCTestTestHandler* TestHandler;
+};
+
+//----------------------------------------------------------------------
+bool cmCTestAddSubdirectoryCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ std::string fname = cwd;
+ fname += "/";
+ fname += args[1];
+
+ if ( !cmSystemTools::FileExists(fname.c_str()) )
+ {
+ // No subdirectory? So what...
+ return true;
+ }
+ cmSystemTools::ChangeDirectory(fname.c_str());
+ const char* testFilename;
+ if( cmSystemTools::FileExists("CTestTestfile.cmake") )
+ {
+ // does the CTestTestfile.cmake exist ?
+ testFilename = "CTestTestfile.cmake";
+ }
+ else if( cmSystemTools::FileExists("DartTestfile.txt") )
+ {
+ // does the DartTestfile.txt exist ?
+ testFilename = "DartTestfile.txt";
+ }
+ else
+ {
+ // No CTestTestfile? Who cares...
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ return true;
+ }
+ fname += "/";
+ fname += testFilename;
+ bool readit =
+ this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
+ fname.c_str());
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ if(!readit)
+ {
+ std::string m = "Could not find include file: ";
+ m += fname;
+ this->SetError(m);
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+class cmCTestAddTestCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestAddTestCommand* c = new cmCTestAddTestCommand;
+ c->TestHandler = this->TestHandler;
+ return c;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "add_test";}
+
+ cmTypeMacro(cmCTestAddTestCommand, cmCommand);
+
+ cmCTestTestHandler* TestHandler;
+};
+
+//----------------------------------------------------------------------
+bool cmCTestAddTestCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if ( args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ return this->TestHandler->AddTest(args);
+}
+
+//----------------------------------------------------------------------
+class cmCTestSetTestsPropertiesCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestSetTestsPropertiesCommand* c
+ = new cmCTestSetTestsPropertiesCommand;
+ c->TestHandler = this->TestHandler;
+ return c;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "set_tests_properties";}
+
+ cmTypeMacro(cmCTestSetTestsPropertiesCommand, cmCommand);
+
+ cmCTestTestHandler* TestHandler;
+};
+
+//----------------------------------------------------------------------
+bool cmCTestSetTestsPropertiesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ return this->TestHandler->SetTestsProperties(args);
+}
+
+//----------------------------------------------------------------------
+// get the next number in a string with numbers separated by ,
+// pos is the start of the search and pos2 is the end of the search
+// pos becomes pos2 after a call to GetNextNumber.
+// -1 is returned at the end of the list.
+inline int GetNextNumber(std::string const& in,
+ int& val,
+ std::string::size_type& pos,
+ std::string::size_type& pos2)
+{
+ pos2 = in.find(',', pos);
+ if(pos2 != in.npos)
+ {
+ if(pos2-pos == 0)
+ {
+ val = -1;
+ }
+ else
+ {
+ val = atoi(in.substr(pos, pos2-pos).c_str());
+ }
+ pos = pos2+1;
+ return 1;
+ }
+ else
+ {
+ if(in.size()-pos == 0)
+ {
+ val = -1;
+ }
+ else
+ {
+ val = atoi(in.substr(pos, in.size()-pos).c_str());
+ }
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------
+// get the next number in a string with numbers separated by ,
+// pos is the start of the search and pos2 is the end of the search
+// pos becomes pos2 after a call to GetNextNumber.
+// -1 is returned at the end of the list.
+inline int GetNextRealNumber(std::string const& in,
+ double& val,
+ std::string::size_type& pos,
+ std::string::size_type& pos2)
+{
+ pos2 = in.find(',', pos);
+ if(pos2 != in.npos)
+ {
+ if(pos2-pos == 0)
+ {
+ val = -1;
+ }
+ else
+ {
+ val = atof(in.substr(pos, pos2-pos).c_str());
+ }
+ pos = pos2+1;
+ return 1;
+ }
+ else
+ {
+ if(in.size()-pos == 0)
+ {
+ val = -1;
+ }
+ else
+ {
+ val = atof(in.substr(pos, in.size()-pos).c_str());
+ }
+ return 0;
+ }
+}
+
+
+//----------------------------------------------------------------------
+cmCTestTestHandler::cmCTestTestHandler()
+{
+ this->UseUnion = false;
+
+ this->UseIncludeLabelRegExpFlag = false;
+ this->UseExcludeLabelRegExpFlag = false;
+ this->UseIncludeRegExpFlag = false;
+ this->UseExcludeRegExpFlag = false;
+ this->UseExcludeRegExpFirst = false;
+
+ this->CustomMaximumPassedTestOutputSize = 1 * 1024;
+ this->CustomMaximumFailedTestOutputSize = 300 * 1024;
+
+ this->MemCheck = false;
+
+ this->LogFile = 0;
+
+ // regex to detect <DartMeasurement>...</DartMeasurement>
+ this->DartStuff.compile(
+ "(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
+ // regex to detect each individual <DartMeasurement>...</DartMeasurement>
+ this->DartStuff1.compile(
+ "(<DartMeasurement[^<]*</DartMeasurement[a-zA-Z]*>)");
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::Initialize()
+{
+ this->Superclass::Initialize();
+
+ this->ElapsedTestingTime = -1;
+
+ this->TestResults.clear();
+
+ this->CustomTestsIgnore.clear();
+ this->StartTest = "";
+ this->EndTest = "";
+
+ this->CustomPreTest.clear();
+ this->CustomPostTest.clear();
+ this->CustomMaximumPassedTestOutputSize = 1 * 1024;
+ this->CustomMaximumFailedTestOutputSize = 300 * 1024;
+
+ this->TestsToRun.clear();
+
+ this->UseIncludeLabelRegExpFlag = false;
+ this->UseExcludeLabelRegExpFlag = false;
+ this->UseIncludeRegExpFlag = false;
+ this->UseExcludeRegExpFlag = false;
+ this->UseExcludeRegExpFirst = false;
+ this->IncludeLabelRegularExpression = "";
+ this->ExcludeLabelRegularExpression = "";
+ this->IncludeRegExp = "";
+ this->ExcludeRegExp = "";
+
+ TestsToRunString = "";
+ this->UseUnion = false;
+ this->TestList.clear();
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf)
+{
+ this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
+ this->CustomPreTest);
+ this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
+ this->CustomPostTest);
+ this->CTest->PopulateCustomVector(mf,
+ "CTEST_CUSTOM_TESTS_IGNORE",
+ this->CustomTestsIgnore);
+ this->CTest->PopulateCustomInteger(mf,
+ "CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE",
+ this->CustomMaximumPassedTestOutputSize);
+ this->CTest->PopulateCustomInteger(mf,
+ "CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE",
+ this->CustomMaximumFailedTestOutputSize);
+}
+
+//----------------------------------------------------------------------
+int cmCTestTestHandler::PreProcessHandler()
+{
+ if ( !this->ExecuteCommands(this->CustomPreTest) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Problem executing pre-test command(s)." << std::endl);
+ return 0;
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCTestTestHandler::PostProcessHandler()
+{
+ if ( !this->ExecuteCommands(this->CustomPostTest) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Problem executing post-test command(s)." << std::endl);
+ return 0;
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------
+//clearly it would be nice if this were broken up into a few smaller
+//functions and commented...
+int cmCTestTestHandler::ProcessHandler()
+{
+ // Update internal data structure from generic one
+ this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
+ this->SetUseUnion(cmSystemTools::IsOn(this->GetOption("UseUnion")));
+ if(cmSystemTools::IsOn(this->GetOption("ScheduleRandom")))
+ {
+ this->CTest->SetScheduleType("Random");
+ }
+ if(this->GetOption("ParallelLevel"))
+ {
+ this->CTest->SetParallelLevel(atoi(this->GetOption("ParallelLevel")));
+ }
+
+ const char* val;
+ val = this->GetOption("LabelRegularExpression");
+ if ( val )
+ {
+ this->UseIncludeLabelRegExpFlag = true;
+ this->IncludeLabelRegExp = val;
+ }
+ val = this->GetOption("ExcludeLabelRegularExpression");
+ if ( val )
+ {
+ this->UseExcludeLabelRegExpFlag = true;
+ this->ExcludeLabelRegExp = val;
+ }
+ val = this->GetOption("IncludeRegularExpression");
+ if ( val )
+ {
+ this->UseIncludeRegExp();
+ this->SetIncludeRegExp(val);
+ }
+ val = this->GetOption("ExcludeRegularExpression");
+ if ( val )
+ {
+ this->UseExcludeRegExp();
+ this->SetExcludeRegExp(val);
+ }
+ this->SetRerunFailed(cmSystemTools::IsOn(this->GetOption("RerunFailed")));
+
+ this->TestResults.clear();
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ (this->MemCheck ? "Memory check" : "Test")
+ << " project " << cmSystemTools::GetCurrentWorkingDirectory()
+ << std::endl);
+ if ( ! this->PreProcessHandler() )
+ {
+ return -1;
+ }
+
+ cmGeneratedFileStream mLogFile;
+ this->StartLogFile((this->MemCheck ? "DynamicAnalysis" : "Test"), mLogFile);
+ this->LogFile = &mLogFile;
+
+ std::vector<std::string> passed;
+ std::vector<std::string> failed;
+ int total;
+
+ //start the real time clock
+ double clock_start, clock_finish;
+ clock_start = cmSystemTools::GetTime();
+
+ this->ProcessDirectory(passed, failed);
+
+ clock_finish = cmSystemTools::GetTime();
+
+ total = int(passed.size()) + int(failed.size());
+
+ if (total == 0)
+ {
+ if ( !this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels() )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "No tests were found!!!"
+ << std::endl);
+ }
+ }
+ else
+ {
+ if (this->HandlerVerbose && passed.size() &&
+ (this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag))
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
+ << "The following tests passed:" << std::endl);
+ for(std::vector<std::string>::iterator j = passed.begin();
+ j != passed.end(); ++j)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "\t" << *j
+ << std::endl);
+ }
+ }
+
+ float percent = float(passed.size()) * 100.0f / float(total);
+ if ( failed.size() > 0 && percent > 99)
+ {
+ percent = 99;
+ }
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
+ << static_cast<int>(percent + .5) << "% tests passed, "
+ << failed.size() << " tests failed out of "
+ << total << std::endl);
+ if(this->CTest->GetLabelSummary())
+ {
+ this->PrintLabelSummary();
+ }
+ char realBuf[1024];
+ sprintf(realBuf, "%6.2f sec", (double)(clock_finish - clock_start));
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nTotal Test time (real) = "
+ << realBuf << "\n" );
+
+ if (failed.size())
+ {
+ cmGeneratedFileStream ofs;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
+ << "The following tests FAILED:" << std::endl);
+ this->StartLogFile("TestsFailed", ofs);
+
+ typedef std::set<cmCTestTestHandler::cmCTestTestResult,
+ cmCTestTestResultLess> SetOfTests;
+ SetOfTests resultsSet(this->TestResults.begin(),
+ this->TestResults.end());
+
+ for(SetOfTests::iterator ftit = resultsSet.begin();
+ ftit != resultsSet.end(); ++ftit)
+ {
+ if ( ftit->Status != cmCTestTestHandler::COMPLETED )
+ {
+ ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" << std::setw(3)
+ << ftit->TestCount << " - "
+ << ftit->Name << " ("
+ << this->GetTestStatus(ftit->Status) << ")"
+ << std::endl);
+ }
+ }
+ }
+ }
+
+ if ( this->CTest->GetProduceXML() )
+ {
+ cmGeneratedFileStream xmlfile;
+ if( !this->StartResultingXML(
+ (this->MemCheck ? cmCTest::PartMemCheck : cmCTest::PartTest),
+ (this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create "
+ << (this->MemCheck ? "memory check" : "testing")
+ << " XML file" << std::endl);
+ this->LogFile = 0;
+ return 1;
+ }
+ this->GenerateDartOutput(xmlfile);
+ }
+
+ if ( ! this->PostProcessHandler() )
+ {
+ this->LogFile = 0;
+ return -1;
+ }
+
+ if ( !failed.empty() )
+ {
+ this->LogFile = 0;
+ return -1;
+ }
+ this->LogFile = 0;
+ return 0;
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::PrintLabelSummary()
+{
+ cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin();
+ cmCTestTestHandler::TestResultsVector::iterator ri =
+ this->TestResults.begin();
+ std::map<std::string, double> labelTimes;
+ std::set<std::string> labels;
+ // initialize maps
+ std::string::size_type maxlen = 0;
+ for(; it != this->TestList.end(); ++it)
+ {
+ cmCTestTestProperties& p = *it;
+ if(p.Labels.size() != 0)
+ {
+ for(std::vector<std::string>::iterator l = p.Labels.begin();
+ l != p.Labels.end(); ++l)
+ {
+ if((*l).size() > maxlen)
+ {
+ maxlen = (*l).size();
+ }
+ labels.insert(*l);
+ labelTimes[*l] = 0;
+ }
+ }
+ }
+ ri = this->TestResults.begin();
+ // fill maps
+ for(; ri != this->TestResults.end(); ++ri)
+ {
+ cmCTestTestResult &result = *ri;
+ cmCTestTestProperties& p = *result.Properties;
+ if(p.Labels.size() != 0)
+ {
+ for(std::vector<std::string>::iterator l = p.Labels.begin();
+ l != p.Labels.end(); ++l)
+ {
+ labelTimes[*l] += result.ExecutionTime;
+ }
+ }
+ }
+ // now print times
+ if(labels.size())
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nLabel Time Summary:");
+ }
+ for(std::set<std::string>::const_iterator i = labels.begin();
+ i != labels.end(); ++i)
+ {
+ std::string label = *i;
+ label.resize(maxlen +3, ' ');
+ char buf[1024];
+ sprintf(buf, "%6.2f sec", labelTimes[*i]);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "\n"
+ << label << " = " << buf );
+ if ( this->LogFile )
+ {
+ *this->LogFile << "\n" << *i << " = "
+ << buf << "\n";
+ }
+ }
+ if(labels.size())
+ {
+ if(this->LogFile)
+ {
+ *this->LogFile << "\n";
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "\n");
+ }
+
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it)
+{
+ // if not using Labels to filter then return
+ if (!this->UseIncludeLabelRegExpFlag )
+ {
+ return;
+ }
+ // if there are no labels and we are filtering by labels
+ // then exclude the test as it does not have the label
+ if(it.Labels.size() == 0 )
+ {
+ it.IsInBasedOnREOptions = false;
+ return;
+ }
+ // check to see if the label regular expression matches
+ bool found = false; // assume it does not match
+ // loop over all labels and look for match
+ for(std::vector<std::string>::iterator l = it.Labels.begin();
+ l != it.Labels.end(); ++l)
+ {
+ if(this->IncludeLabelRegularExpression.find(*l))
+ {
+ found = true;
+ }
+ }
+ // if no match was found, exclude the test
+ if(!found)
+ {
+ it.IsInBasedOnREOptions = false;
+ }
+}
+
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::CheckLabelFilterExclude(cmCTestTestProperties& it)
+{
+ // if not using Labels to filter then return
+ if (!this->UseExcludeLabelRegExpFlag )
+ {
+ return;
+ }
+ // if there are no labels and we are excluding by labels
+ // then do nothing as a no label can not be a match
+ if(it.Labels.size() == 0 )
+ {
+ return;
+ }
+ // check to see if the label regular expression matches
+ bool found = false; // assume it does not match
+ // loop over all labels and look for match
+ for(std::vector<std::string>::iterator l = it.Labels.begin();
+ l != it.Labels.end(); ++l)
+ {
+ if(this->ExcludeLabelRegularExpression.find(*l))
+ {
+ found = true;
+ }
+ }
+ // if match was found, exclude the test
+ if(found)
+ {
+ it.IsInBasedOnREOptions = false;
+ }
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::CheckLabelFilter(cmCTestTestProperties& it)
+{
+ this->CheckLabelFilterInclude(it);
+ this->CheckLabelFilterExclude(it);
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::ComputeTestList()
+{
+ this->TestList.clear(); // clear list of test
+ this->GetListOfTests();
+
+ if (this->RerunFailed)
+ {
+ this->ComputeTestListForRerunFailed();
+ return;
+ }
+
+ cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
+ // how many tests are in based on RegExp?
+ int inREcnt = 0;
+ cmCTestTestHandler::ListOfTests::iterator it;
+ for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
+ {
+ this->CheckLabelFilter(*it);
+ if (it->IsInBasedOnREOptions)
+ {
+ inREcnt ++;
+ }
+ }
+ // expand the test list based on the union flag
+ if (this->UseUnion)
+ {
+ this->ExpandTestsToRunInformation((int)tmsize);
+ }
+ else
+ {
+ this->ExpandTestsToRunInformation(inREcnt);
+ }
+ // Now create a final list of tests to run
+ int cnt = 0;
+ inREcnt = 0;
+ std::string last_directory = "";
+ ListOfTests finalList;
+ for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
+ {
+ cnt ++;
+ if (it->IsInBasedOnREOptions)
+ {
+ inREcnt++;
+ }
+
+ if (this->UseUnion)
+ {
+ // if it is not in the list and not in the regexp then skip
+ if ((this->TestsToRun.size() &&
+ std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt)
+ == this->TestsToRun.end()) && !it->IsInBasedOnREOptions)
+ {
+ continue;
+ }
+ }
+ else
+ {
+ // is this test in the list of tests to run? If not then skip it
+ if ((this->TestsToRun.size() &&
+ std::find(this->TestsToRun.begin(),
+ this->TestsToRun.end(), inREcnt)
+ == this->TestsToRun.end()) || !it->IsInBasedOnREOptions)
+ {
+ continue;
+ }
+ }
+ it->Index = cnt; // save the index into the test list for this test
+ finalList.push_back(*it);
+ }
+ // Save the total number of tests before exclusions
+ this->TotalNumberOfTests = this->TestList.size();
+ // Set the TestList to the final list of all test
+ this->TestList = finalList;
+
+ this->UpdateMaxTestNameWidth();
+}
+
+void cmCTestTestHandler::ComputeTestListForRerunFailed()
+{
+ this->ExpandTestsToRunInformationForRerunFailed();
+
+ cmCTestTestHandler::ListOfTests::iterator it;
+ ListOfTests finalList;
+ int cnt = 0;
+ for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
+ {
+ cnt ++;
+
+ // if this test is not in our list of tests to run, then skip it.
+ if ((this->TestsToRun.size() &&
+ std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt)
+ == this->TestsToRun.end()))
+ {
+ continue;
+ }
+
+ it->Index = cnt;
+ finalList.push_back(*it);
+ }
+
+ // Save the total number of tests before exclusions
+ this->TotalNumberOfTests = this->TestList.size();
+
+ // Set the TestList to the list of failed tests to rerun
+ this->TestList = finalList;
+
+ this->UpdateMaxTestNameWidth();
+}
+
+void cmCTestTestHandler::UpdateMaxTestNameWidth()
+{
+ std::string::size_type max = this->CTest->GetMaxTestNameWidth();
+ for ( cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin();
+ it != this->TestList.end(); it ++ )
+ {
+ cmCTestTestProperties& p = *it;
+ if(max < p.Name.size())
+ {
+ max = p.Name.size();
+ }
+ }
+ if(static_cast<std::string::size_type>(this->CTest->GetMaxTestNameWidth())
+ != max)
+ {
+ this->CTest->SetMaxTestNameWidth(static_cast<int>(max));
+ }
+}
+
+bool cmCTestTestHandler::GetValue(const char* tag,
+ int& value,
+ std::istream& fin)
+{
+ std::string line;
+ bool ret = true;
+ cmSystemTools::GetLineFromStream(fin, line);
+ if(line == tag)
+ {
+ fin >> value;
+ ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: "
+ << tag << " found [" << line << "]" << std::endl);
+ ret = false;
+ }
+ return ret;
+}
+
+bool cmCTestTestHandler::GetValue(const char* tag,
+ double& value,
+ std::istream& fin)
+{
+ std::string line;
+ cmSystemTools::GetLineFromStream(fin, line);
+ bool ret = true;
+ if(line == tag)
+ {
+ fin >> value;
+ ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: "
+ << tag << " found [" << line << "]" << std::endl);
+ ret = false;
+ }
+ return ret;
+}
+
+bool cmCTestTestHandler::GetValue(const char* tag,
+ bool& value,
+ std::istream& fin)
+{
+ std::string line;
+ cmSystemTools::GetLineFromStream(fin, line);
+ bool ret = true;
+ if(line == tag)
+ {
+#ifdef __HAIKU__
+ int tmp = 0;
+ fin >> tmp;
+ value = false;
+ if(tmp)
+ {
+ value = true;
+ }
+#else
+ fin >> value;
+#endif
+ ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: "
+ << tag << " found [" << line << "]" << std::endl);
+ ret = false;
+ }
+ return ret;
+}
+
+bool cmCTestTestHandler::GetValue(const char* tag,
+ size_t& value,
+ std::istream& fin)
+{
+ std::string line;
+ cmSystemTools::GetLineFromStream(fin, line);
+ bool ret = true;
+ if(line == tag)
+ {
+ fin >> value;
+ ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: "
+ << tag << " found [" << line << "]" << std::endl);
+ ret = false;
+ }
+ return ret;
+}
+
+bool cmCTestTestHandler::GetValue(const char* tag,
+ std::string& value,
+ std::istream& fin)
+{
+ std::string line;
+ cmSystemTools::GetLineFromStream(fin, line);
+ bool ret = true;
+ if(line == tag)
+ {
+ ret = cmSystemTools::GetLineFromStream(fin, value);
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: "
+ << tag << " found [" << line << "]" << std::endl);
+ ret = false;
+ }
+ return ret;
+}
+
+//---------------------------------------------------------------------
+void cmCTestTestHandler::ProcessDirectory(std::vector<std::string> &passed,
+ std::vector<std::string> &failed)
+{
+ this->ComputeTestList();
+ this->StartTest = this->CTest->CurrentTime();
+ this->StartTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
+ double elapsed_time_start = cmSystemTools::GetTime();
+
+ cmCTestMultiProcessHandler* parallel = this->CTest->GetBatchJobs() ?
+ new cmCTestBatchTestHandler : new cmCTestMultiProcessHandler;
+ parallel->SetCTest(this->CTest);
+ parallel->SetParallelLevel(this->CTest->GetParallelLevel());
+ parallel->SetTestHandler(this);
+
+ *this->LogFile << "Start testing: "
+ << this->CTest->CurrentTime() << std::endl
+ << "----------------------------------------------------------"
+ << std::endl;
+
+ cmCTestMultiProcessHandler::TestMap tests;
+ cmCTestMultiProcessHandler::PropertiesMap properties;
+
+ bool randomSchedule = this->CTest->GetScheduleType() == "Random";
+ if(randomSchedule)
+ {
+ srand((unsigned)time(0));
+ }
+
+ for (ListOfTests::iterator it = this->TestList.begin();
+ it != this->TestList.end(); ++it)
+ {
+ cmCTestTestProperties& p = *it;
+ cmCTestMultiProcessHandler::TestSet depends;
+
+ if(randomSchedule)
+ {
+ p.Cost = static_cast<float>(rand());
+ }
+
+ if(p.Timeout == 0 && this->CTest->GetGlobalTimeout() != 0)
+ {
+ p.Timeout = this->CTest->GetGlobalTimeout();
+ }
+
+ if(p.Depends.size())
+ {
+ for(std::vector<std::string>::iterator i = p.Depends.begin();
+ i != p.Depends.end(); ++i)
+ {
+ for(ListOfTests::iterator it2 = this->TestList.begin();
+ it2 != this->TestList.end(); ++it2)
+ {
+ if(it2->Name == *i)
+ {
+ depends.insert(it2->Index);
+ break; // break out of test loop as name can only match 1
+ }
+ }
+ }
+ }
+ tests[it->Index] = depends;
+ properties[it->Index] = &*it;
+ }
+ parallel->SetTests(tests, properties);
+ parallel->SetPassFailVectors(&passed, &failed);
+ this->TestResults.clear();
+ parallel->SetTestResults(&this->TestResults);
+
+ if(this->CTest->ShouldPrintLabels())
+ {
+ parallel->PrintLabels();
+ }
+ else if(this->CTest->GetShowOnly())
+ {
+ parallel->PrintTestList();
+ }
+ else
+ {
+ parallel->RunTests();
+ }
+ delete parallel;
+ this->EndTest = this->CTest->CurrentTime();
+ this->EndTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
+ this->ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
+ *this->LogFile << "End testing: "
+ << this->CTest->CurrentTime() << std::endl;
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::GenerateTestCommand(std::vector<std::string>&, int)
+{
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
+{
+ if ( !this->CTest->GetProduceXML() )
+ {
+ return;
+ }
+
+ this->CTest->StartXML(os, this->AppendXML);
+ os << "<Testing>\n"
+ << "\t<StartDateTime>" << this->StartTest << "</StartDateTime>\n"
+ << "\t<StartTestTime>" << this->StartTestTime << "</StartTestTime>\n"
+ << "\t<TestList>\n";
+ cmCTestTestHandler::TestResultsVector::size_type cc;
+ for ( cc = 0; cc < this->TestResults.size(); cc ++ )
+ {
+ cmCTestTestResult *result = &this->TestResults[cc];
+ std::string testPath = result->Path + "/" + result->Name;
+ os << "\t\t<Test>" << cmXMLSafe(
+ this->CTest->GetShortPathToFile(testPath.c_str()))
+ << "</Test>" << std::endl;
+ }
+ os << "\t</TestList>\n";
+ for ( cc = 0; cc < this->TestResults.size(); cc ++ )
+ {
+ cmCTestTestResult *result = &this->TestResults[cc];
+ this->WriteTestResultHeader(os, result);
+ os << "\t\t<Results>" << std::endl;
+ if ( result->Status != cmCTestTestHandler::NOT_RUN )
+ {
+ if ( result->Status != cmCTestTestHandler::COMPLETED ||
+ result->ReturnValue )
+ {
+ os << "\t\t\t<NamedMeasurement type=\"text/string\" "
+ "name=\"Exit Code\"><Value>"
+ << cmXMLSafe(this->GetTestStatus(result->Status))
+ << "</Value>"
+ "</NamedMeasurement>\n"
+ << "\t\t\t<NamedMeasurement type=\"text/string\" "
+ "name=\"Exit Value\"><Value>"
+ << result->ReturnValue
+ << "</Value></NamedMeasurement>"
+ << std::endl;
+ }
+ os << result->RegressionImages;
+ os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
+ << "name=\"Execution Time\"><Value>"
+ << result->ExecutionTime
+ << "</Value></NamedMeasurement>\n";
+ if(result->Reason.size())
+ {
+ const char* reasonType = "Pass Reason";
+ if(result->Status != cmCTestTestHandler::COMPLETED &&
+ result->Status != cmCTestTestHandler::NOT_RUN)
+ {
+ reasonType = "Fail Reason";
+ }
+ os << "\t\t\t<NamedMeasurement type=\"text/string\" "
+ << "name=\"" << reasonType << "\"><Value>"
+ << cmXMLSafe(result->Reason)
+ << "</Value></NamedMeasurement>\n";
+ }
+ os
+ << "\t\t\t<NamedMeasurement type=\"text/string\" "
+ << "name=\"Completion Status\"><Value>"
+ << cmXMLSafe(result->CompletionStatus)
+ << "</Value></NamedMeasurement>\n";
+ }
+ os
+ << "\t\t\t<NamedMeasurement type=\"text/string\" "
+ << "name=\"Command Line\"><Value>"
+ << cmXMLSafe(result->FullCommandLine)
+ << "</Value></NamedMeasurement>\n";
+ std::map<std::string,std::string>::iterator measureIt;
+ for ( measureIt = result->Properties->Measurements.begin();
+ measureIt != result->Properties->Measurements.end();
+ ++ measureIt )
+ {
+ os
+ << "\t\t\t<NamedMeasurement type=\"text/string\" "
+ << "name=\"" << measureIt->first << "\"><Value>"
+ << cmXMLSafe(measureIt->second)
+ << "</Value></NamedMeasurement>\n";
+ }
+ os
+ << "\t\t\t<Measurement>\n"
+ << "\t\t\t\t<Value"
+ << (result->CompressOutput ?
+ " encoding=\"base64\" compression=\"gzip\">"
+ : ">");
+ os << cmXMLSafe(result->Output);
+ os
+ << "</Value>\n"
+ << "\t\t\t</Measurement>\n"
+ << "\t\t</Results>\n";
+
+ this->AttachFiles(os, result);
+ this->WriteTestResultFooter(os, result);
+ }
+
+ os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>\n"
+ << "\t<EndTestTime>" << this->EndTestTime << "</EndTestTime>\n"
+ << "<ElapsedMinutes>"
+ << static_cast<int>(this->ElapsedTestingTime/6)/10.0
+ << "</ElapsedMinutes>"
+ << "</Testing>" << std::endl;
+ this->CTest->EndXML(os);
+}
+
+//----------------------------------------------------------------------------
+void cmCTestTestHandler::WriteTestResultHeader(std::ostream& os,
+ cmCTestTestResult* result)
+{
+ os << "\t<Test Status=\"";
+ if ( result->Status == cmCTestTestHandler::COMPLETED )
+ {
+ os << "passed";
+ }
+ else if ( result->Status == cmCTestTestHandler::NOT_RUN )
+ {
+ os << "notrun";
+ }
+ else
+ {
+ os << "failed";
+ }
+ std::string testPath = result->Path + "/" + result->Name;
+ os << "\">\n"
+ << "\t\t<Name>" << cmXMLSafe(result->Name) << "</Name>\n"
+ << "\t\t<Path>" << cmXMLSafe(
+ this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
+ << "\t\t<FullName>" << cmXMLSafe(
+ this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
+ << "\t\t<FullCommandLine>"
+ << cmXMLSafe(result->FullCommandLine)
+ << "</FullCommandLine>\n";
+}
+
+//----------------------------------------------------------------------------
+void cmCTestTestHandler::WriteTestResultFooter(std::ostream& os,
+ cmCTestTestResult* result)
+{
+ if(!result->Properties->Labels.empty())
+ {
+ os << "\t\t<Labels>\n";
+ std::vector<std::string> const& labels = result->Properties->Labels;
+ for(std::vector<std::string>::const_iterator li = labels.begin();
+ li != labels.end(); ++li)
+ {
+ os << "\t\t\t<Label>" << cmXMLSafe(*li) << "</Label>\n";
+ }
+ os << "\t\t</Labels>\n";
+ }
+
+ os
+ << "\t</Test>" << std::endl;
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::AttachFiles(std::ostream& os,
+ cmCTestTestResult* result)
+{
+ if(result->Status != cmCTestTestHandler::COMPLETED
+ && result->Properties->AttachOnFail.size())
+ {
+ result->Properties->AttachedFiles.insert(
+ result->Properties->AttachedFiles.end(),
+ result->Properties->AttachOnFail.begin(),
+ result->Properties->AttachOnFail.end());
+ }
+ for(std::vector<std::string>::const_iterator file =
+ result->Properties->AttachedFiles.begin();
+ file != result->Properties->AttachedFiles.end(); ++file)
+ {
+ std::string base64 = this->CTest->Base64GzipEncodeFile(*file);
+ std::string fname = cmSystemTools::GetFilenameName(*file);
+ os << "\t\t<NamedMeasurement name=\"Attached File\" encoding=\"base64\" "
+ "compression=\"tar/gzip\" filename=\"" << fname << "\" type=\"file\">"
+ "\n\t\t\t<Value>\n\t\t\t"
+ << base64
+ << "\n\t\t\t</Value>\n\t\t</NamedMeasurement>\n";
+ }
+}
+
+//----------------------------------------------------------------------
+int cmCTestTestHandler::ExecuteCommands(std::vector<std::string>& vec)
+{
+ std::vector<std::string>::iterator it;
+ for ( it = vec.begin(); it != vec.end(); ++it )
+ {
+ int retVal = 0;
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it
+ << std::endl);
+ if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0,
+ cmSystemTools::OUTPUT_MERGE
+ /*this->Verbose*/) || retVal != 0 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem running command: "
+ << *it << std::endl);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+
+//----------------------------------------------------------------------
+// Find the appropriate executable to run for a test
+std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
+{
+ std::string resConfig;
+ std::vector<std::string> extraPaths;
+ std::vector<std::string> failedPaths;
+ if(strcmp(exe, "NOT_AVAILABLE") == 0)
+ {
+ return exe;
+ }
+ return cmCTestTestHandler::FindExecutable(this->CTest,
+ exe, resConfig,
+ extraPaths,
+ failedPaths);
+}
+
+// add additional configurations to the search path
+void cmCTestTestHandler
+::AddConfigurations(cmCTest *ctest,
+ std::vector<std::string> &attempted,
+ std::vector<std::string> &attemptedConfigs,
+ std::string filepath,
+ std::string &filename)
+{
+ std::string tempPath;
+
+ if (filepath.size() &&
+ filepath[filepath.size()-1] != '/')
+ {
+ filepath += "/";
+ }
+ tempPath = filepath + filename;
+ attempted.push_back(tempPath);
+ attemptedConfigs.push_back("");
+
+ if(ctest->GetConfigType().size())
+ {
+ tempPath = filepath;
+ tempPath += ctest->GetConfigType();
+ tempPath += "/";
+ tempPath += filename;
+ attempted.push_back(tempPath);
+ attemptedConfigs.push_back(ctest->GetConfigType());
+ // If the file is an OSX bundle then the configtype
+ // will be at the start of the path
+ tempPath = ctest->GetConfigType();
+ tempPath += "/";
+ tempPath += filepath;
+ tempPath += filename;
+ attempted.push_back(tempPath);
+ attemptedConfigs.push_back(ctest->GetConfigType());
+ }
+ else
+ {
+ // no config specified - try some options...
+ tempPath = filepath;
+ tempPath += "Release/";
+ tempPath += filename;
+ attempted.push_back(tempPath);
+ attemptedConfigs.push_back("Release");
+ tempPath = filepath;
+ tempPath += "Debug/";
+ tempPath += filename;
+ attempted.push_back(tempPath);
+ attemptedConfigs.push_back("Debug");
+ tempPath = filepath;
+ tempPath += "MinSizeRel/";
+ tempPath += filename;
+ attempted.push_back(tempPath);
+ attemptedConfigs.push_back("MinSizeRel");
+ tempPath = filepath;
+ tempPath += "RelWithDebInfo/";
+ tempPath += filename;
+ attempted.push_back(tempPath);
+ attemptedConfigs.push_back("RelWithDebInfo");
+ tempPath = filepath;
+ tempPath += "Deployment/";
+ tempPath += filename;
+ attempted.push_back(tempPath);
+ attemptedConfigs.push_back("Deployment");
+ tempPath = filepath;
+ tempPath += "Development/";
+ tempPath += filename;
+ attempted.push_back(tempPath);
+ attemptedConfigs.push_back("Deployment");
+ }
+}
+
+
+//----------------------------------------------------------------------
+// Find the appropriate executable to run for a test
+std::string cmCTestTestHandler
+::FindExecutable(cmCTest *ctest,
+ const char *testCommand,
+ std::string &resultingConfig,
+ std::vector<std::string> &extraPaths,
+ std::vector<std::string> &failed)
+{
+ // now run the compiled test if we can find it
+ std::vector<std::string> attempted;
+ std::vector<std::string> attemptedConfigs;
+ std::string tempPath;
+ std::string filepath =
+ cmSystemTools::GetFilenamePath(testCommand);
+ std::string filename =
+ cmSystemTools::GetFilenameName(testCommand);
+
+ cmCTestTestHandler::AddConfigurations(ctest, attempted,
+ attemptedConfigs,
+ filepath,filename);
+
+ // even if a fullpath was specified also try it relative to the current
+ // directory
+ if (filepath.size() && filepath[0] == '/')
+ {
+ std::string localfilepath = filepath.substr(1,filepath.size()-1);
+ cmCTestTestHandler::AddConfigurations(ctest, attempted,
+ attemptedConfigs,
+ localfilepath,filename);
+ }
+
+
+ // if extraPaths are provided and we were not passed a full path, try them,
+ // try any extra paths
+ if (filepath.size() == 0)
+ {
+ for (unsigned int i = 0; i < extraPaths.size(); ++i)
+ {
+ std::string filepathExtra =
+ cmSystemTools::GetFilenamePath(extraPaths[i]);
+ std::string filenameExtra =
+ cmSystemTools::GetFilenameName(extraPaths[i]);
+ cmCTestTestHandler::AddConfigurations(ctest,attempted,
+ attemptedConfigs,
+ filepathExtra,
+ filenameExtra);
+ }
+ }
+
+ // store the final location in fullPath
+ std::string fullPath;
+
+ // now look in the paths we specified above
+ for(unsigned int ai=0;
+ ai < attempted.size() && fullPath.size() == 0; ++ai)
+ {
+ // first check without exe extension
+ if(cmSystemTools::FileExists(attempted[ai].c_str())
+ && !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
+ {
+ fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
+ resultingConfig = attemptedConfigs[ai];
+ }
+ // then try with the exe extension
+ else
+ {
+ failed.push_back(attempted[ai]);
+ tempPath = attempted[ai];
+ tempPath += cmSystemTools::GetExecutableExtension();
+ if(cmSystemTools::FileExists(tempPath.c_str())
+ && !cmSystemTools::FileIsDirectory(tempPath.c_str()))
+ {
+ fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
+ resultingConfig = attemptedConfigs[ai];
+ }
+ else
+ {
+ failed.push_back(tempPath);
+ }
+ }
+ }
+
+ // if everything else failed, check the users path, but only if a full path
+ // wasn't specified
+ if (fullPath.size() == 0 && filepath.size() == 0)
+ {
+ std::string path = cmSystemTools::FindProgram(filename.c_str());
+ if (path != "")
+ {
+ resultingConfig = "";
+ return path;
+ }
+ }
+ if(fullPath.size() == 0)
+ {
+ cmCTestLog(ctest, HANDLER_OUTPUT,
+ "Could not find executable " << testCommand << "\n"
+ << "Looked in the following places:\n");
+ for(std::vector<std::string>::iterator i = failed.begin();
+ i != failed.end(); ++i)
+ {
+ cmCTestLog(ctest, HANDLER_OUTPUT,
+ i->c_str() << "\n");
+ }
+ }
+
+ return fullPath;
+}
+
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::GetListOfTests()
+{
+ if ( !this->IncludeLabelRegExp.empty() )
+ {
+ this->IncludeLabelRegularExpression.
+ compile(this->IncludeLabelRegExp.c_str());
+ }
+ if ( !this->ExcludeLabelRegExp.empty() )
+ {
+ this->ExcludeLabelRegularExpression.
+ compile(this->ExcludeLabelRegExp.c_str());
+ }
+ if ( !this->IncludeRegExp.empty() )
+ {
+ this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
+ }
+ if ( !this->ExcludeRegExp.empty() )
+ {
+ this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Constructing a list of tests" << std::endl);
+ cmake cm;
+ cmGlobalGenerator gg;
+ gg.SetCMakeInstance(&cm);
+ cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
+ cmMakefile *mf = lg->GetMakefile();
+ mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
+ this->CTest->GetConfigType().c_str());
+
+ // Add handler for ADD_TEST
+ cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
+ newCom1->TestHandler = this;
+ cm.AddCommand(newCom1);
+
+ // Add handler for SUBDIRS
+ cmCTestSubdirCommand* newCom2 =
+ new cmCTestSubdirCommand;
+ newCom2->TestHandler = this;
+ cm.AddCommand(newCom2);
+
+ // Add handler for ADD_SUBDIRECTORY
+ cmCTestAddSubdirectoryCommand* newCom3 =
+ new cmCTestAddSubdirectoryCommand;
+ newCom3->TestHandler = this;
+ cm.AddCommand(newCom3);
+
+ // Add handler for SET_SOURCE_FILES_PROPERTIES
+ cmCTestSetTestsPropertiesCommand* newCom4
+ = new cmCTestSetTestsPropertiesCommand;
+ newCom4->TestHandler = this;
+ cm.AddCommand(newCom4);
+
+ const char* testFilename;
+ if( cmSystemTools::FileExists("CTestTestfile.cmake") )
+ {
+ // does the CTestTestfile.cmake exist ?
+ testFilename = "CTestTestfile.cmake";
+ }
+ else if( cmSystemTools::FileExists("DartTestfile.txt") )
+ {
+ // does the DartTestfile.txt exist ?
+ testFilename = "DartTestfile.txt";
+ }
+ else
+ {
+ return;
+ }
+
+ if ( !mf->ReadListFile(0, testFilename) )
+ {
+ return;
+ }
+ if ( cmSystemTools::GetErrorOccuredFlag() )
+ {
+ return;
+ }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Done constructing a list of tests" << std::endl);
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::UseIncludeRegExp()
+{
+ this->UseIncludeRegExpFlag = true;
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::UseExcludeRegExp()
+{
+ this->UseExcludeRegExpFlag = true;
+ this->UseExcludeRegExpFirst = this->UseIncludeRegExpFlag ? false : true;
+}
+
+//----------------------------------------------------------------------
+const char* cmCTestTestHandler::GetTestStatus(int status)
+{
+ static const char statuses[][100] = {
+ "Not Run",
+ "Timeout",
+ "SEGFAULT",
+ "ILLEGAL",
+ "INTERRUPT",
+ "NUMERICAL",
+ "OTHER_FAULT",
+ "Failed",
+ "BAD_COMMAND",
+ "Completed"
+ };
+
+ if ( status < cmCTestTestHandler::NOT_RUN ||
+ status > cmCTestTestHandler::COMPLETED )
+ {
+ return "No Status";
+ }
+ return statuses[status];
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
+{
+ if (this->TestsToRunString.empty())
+ {
+ return;
+ }
+
+ int start;
+ int end = -1;
+ double stride = -1;
+ std::string::size_type pos = 0;
+ std::string::size_type pos2;
+ // read start
+ if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
+ {
+ // read end
+ if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
+ {
+ // read stride
+ if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
+ {
+ int val =0;
+ // now read specific numbers
+ while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
+ {
+ this->TestsToRun.push_back(val);
+ }
+ this->TestsToRun.push_back(val);
+ }
+ }
+ }
+
+ // if start is not specified then we assume we start at 1
+ if(start == -1)
+ {
+ start = 1;
+ }
+
+ // if end isnot specified then we assume we end with the last test
+ if(end == -1)
+ {
+ end = static_cast<int>(numTests);
+ }
+
+ // if the stride wasn't specified then it defaults to 1
+ if(stride == -1)
+ {
+ stride = 1;
+ }
+
+ // if we have a range then add it
+ if(end != -1 && start != -1 && stride > 0)
+ {
+ int i = 0;
+ while (i*stride + start <= end)
+ {
+ this->TestsToRun.push_back(static_cast<int>(i*stride+start));
+ ++i;
+ }
+ }
+
+ // sort the array
+ std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
+ std::less<int>());
+ // remove duplicates
+ std::vector<int>::iterator new_end =
+ std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
+ this->TestsToRun.erase(new_end, this->TestsToRun.end());
+}
+
+void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
+{
+
+ std::string dirName = this->CTest->GetBinaryDir() + "/Testing/Temporary";
+
+ cmsys::Directory directory;
+ if (directory.Load(dirName.c_str()) == 0)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to read the contents of "
+ << dirName << std::endl);
+ return;
+ }
+
+ int numFiles = static_cast<int>
+ (cmsys::Directory::GetNumberOfFilesInDirectory(dirName.c_str()));
+ std::string pattern = "LastTestsFailed";
+ std::string logName = "";
+
+ for (int i = 0; i < numFiles; ++i)
+ {
+ std::string fileName = directory.GetFile(i);
+ // bcc crashes if we attempt a normal substring comparison,
+ // hence the following workaround
+ std::string fileNameSubstring = fileName.substr(0, pattern.length());
+ if (fileNameSubstring.compare(pattern) != 0)
+ {
+ continue;
+ }
+ if (logName == "")
+ {
+ logName = fileName;
+ }
+ else
+ {
+ // if multiple matching logs were found we use the most recently
+ // modified one.
+ int res;
+ cmSystemTools::FileTimeCompare(logName.c_str(), fileName.c_str(), &res);
+ if (res == -1)
+ {
+ logName = fileName;
+ }
+ }
+ }
+
+ std::string lastTestsFailedLog = this->CTest->GetBinaryDir()
+ + "/Testing/Temporary/" + logName;
+
+ if ( !cmSystemTools::FileExists(lastTestsFailedLog.c_str()) )
+ {
+ if ( !this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels() )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, lastTestsFailedLog
+ << " does not exist!" << std::endl);
+ }
+ return;
+ }
+
+ // parse the list of tests to rerun from LastTestsFailed.log
+ cmsys::ifstream ifs(lastTestsFailedLog.c_str());
+ if ( ifs )
+ {
+ std::string line;
+ std::string::size_type pos;
+ while ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ pos = line.find(':', 0);
+ if (pos == line.npos)
+ {
+ continue;
+ }
+
+ int val = atoi(line.substr(0, pos).c_str());
+ this->TestsToRun.push_back(val);
+ }
+ ifs.close();
+ }
+ else if ( !this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels() )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem reading file: "
+ << lastTestsFailedLog <<
+ " while generating list of previously failed tests." << std::endl);
+ }
+}
+
+//----------------------------------------------------------------------
+// Just for convenience
+#define SPACE_REGEX "[ \t\r\n]"
+//----------------------------------------------------------------------
+std::string cmCTestTestHandler::GenerateRegressionImages(
+ const std::string& xml)
+{
+ cmsys::RegularExpression twoattributes(
+ "<DartMeasurement"
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*>([^<]*)</DartMeasurement>");
+ cmsys::RegularExpression threeattributes(
+ "<DartMeasurement"
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*>([^<]*)</DartMeasurement>");
+ cmsys::RegularExpression fourattributes(
+ "<DartMeasurement"
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*>([^<]*)</DartMeasurement>");
+ cmsys::RegularExpression cdatastart(
+ "<DartMeasurement"
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*>"
+ SPACE_REGEX "*<!\\[CDATA\\[");
+ cmsys::RegularExpression cdataend(
+ "]]>"
+ SPACE_REGEX "*</DartMeasurement>");
+ cmsys::RegularExpression measurementfile(
+ "<DartMeasurementFile"
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
+ SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
+
+ cmOStringStream ostr;
+ bool done = false;
+ std::string cxml = xml;
+ while ( ! done )
+ {
+ if ( twoattributes.find(cxml) )
+ {
+ ostr
+ << "\t\t\t<NamedMeasurement"
+ << " " << twoattributes.match(1) << "=\""
+ << twoattributes.match(2) << "\""
+ << " " << twoattributes.match(3) << "=\""
+ << twoattributes.match(4) << "\""
+ << "><Value>" << twoattributes.match(5)
+ << "</Value></NamedMeasurement>"
+ << std::endl;
+ cxml.erase(twoattributes.start(),
+ twoattributes.end() - twoattributes.start());
+ }
+ else if ( threeattributes.find(cxml) )
+ {
+ ostr
+ << "\t\t\t<NamedMeasurement"
+ << " " << threeattributes.match(1) << "=\""
+ << threeattributes.match(2) << "\""
+ << " " << threeattributes.match(3) << "=\""
+ << threeattributes.match(4) << "\""
+ << " " << threeattributes.match(5) << "=\""
+ << threeattributes.match(6) << "\""
+ << "><Value>" << threeattributes.match(7)
+ << "</Value></NamedMeasurement>"
+ << std::endl;
+ cxml.erase(threeattributes.start(),
+ threeattributes.end() - threeattributes.start());
+ }
+ else if ( fourattributes.find(cxml) )
+ {
+ ostr
+ << "\t\t\t<NamedMeasurement"
+ << " " << fourattributes.match(1) << "=\""
+ << fourattributes.match(2) << "\""
+ << " " << fourattributes.match(3) << "=\""
+ << fourattributes.match(4) << "\""
+ << " " << fourattributes.match(5) << "=\""
+ << fourattributes.match(6) << "\""
+ << " " << fourattributes.match(7) << "=\""
+ << fourattributes.match(8) << "\""
+ << "><Value>" << fourattributes.match(9)
+ << "</Value></NamedMeasurement>"
+ << std::endl;
+ cxml.erase(fourattributes.start(),
+ fourattributes.end() - fourattributes.start());
+ }
+ else if ( cdatastart.find(cxml) && cdataend.find(cxml) )
+ {
+ ostr
+ << "\t\t\t<NamedMeasurement"
+ << " " << cdatastart.match(1) << "=\""
+ << cdatastart.match(2) << "\""
+ << " " << cdatastart.match(3) << "=\""
+ << cdatastart.match(4) << "\""
+ << "><Value><![CDATA["
+ << cxml.substr(cdatastart.end(), cdataend.start() - cdatastart.end())
+ << "]]></Value></NamedMeasurement>"
+ << std::endl;
+ cxml.erase(cdatastart.start(),
+ cdataend.end() - cdatastart.start());
+ }
+ else if ( measurementfile.find(cxml) )
+ {
+ const std::string& filename =
+ cmCTest::CleanString(measurementfile.match(5));
+ if ( cmSystemTools::FileExists(filename.c_str()) )
+ {
+ long len = cmSystemTools::FileLength(filename.c_str());
+ if ( len == 0 )
+ {
+ std::string k1 = measurementfile.match(1);
+ std::string v1 = measurementfile.match(2);
+ std::string k2 = measurementfile.match(3);
+ std::string v2 = measurementfile.match(4);
+ if ( cmSystemTools::LowerCase(k1) == "type" )
+ {
+ v1 = "text/string";
+ }
+ if ( cmSystemTools::LowerCase(k2) == "type" )
+ {
+ v2 = "text/string";
+ }
+
+ ostr
+ << "\t\t\t<NamedMeasurement"
+ << " " << k1 << "=\"" << v1 << "\""
+ << " " << k2 << "=\"" << v2 << "\""
+ << " encoding=\"none\""
+ << "><Value>Image " << filename
+ << " is empty</Value></NamedMeasurement>";
+ }
+ else
+ {
+ cmsys::ifstream ifs(filename.c_str(), std::ios::in
+#ifdef _WIN32
+ | std::ios::binary
+#endif
+ );
+ unsigned char *file_buffer = new unsigned char [ len + 1 ];
+ ifs.read(reinterpret_cast<char*>(file_buffer), len);
+ unsigned char *encoded_buffer
+ = new unsigned char [ static_cast<int>(
+ static_cast<double>(len) * 1.5 + 5.0) ];
+
+ unsigned long rlen
+ = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
+ unsigned long cc;
+
+ ostr
+ << "\t\t\t<NamedMeasurement"
+ << " " << measurementfile.match(1) << "=\""
+ << measurementfile.match(2) << "\""
+ << " " << measurementfile.match(3) << "=\""
+ << measurementfile.match(4) << "\""
+ << " encoding=\"base64\""
+ << ">" << std::endl << "\t\t\t\t<Value>";
+ for ( cc = 0; cc < rlen; cc ++ )
+ {
+ ostr << encoded_buffer[cc];
+ if ( cc % 60 == 0 && cc )
+ {
+ ostr << std::endl;
+ }
+ }
+ ostr
+ << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
+ << std::endl;
+ delete [] file_buffer;
+ delete [] encoded_buffer;
+ }
+ }
+ else
+ {
+ int idx = 4;
+ if ( measurementfile.match(1) == "name" )
+ {
+ idx = 2;
+ }
+ ostr
+ << "\t\t\t<NamedMeasurement"
+ << " name=\"" << measurementfile.match(idx) << "\""
+ << " text=\"text/string\""
+ << "><Value>File " << filename
+ << " not found</Value></NamedMeasurement>"
+ << std::endl;
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "File \"" << filename
+ << "\" not found." << std::endl);
+ }
+ cxml.erase(measurementfile.start(),
+ measurementfile.end() - measurementfile.start());
+ }
+ else
+ {
+ done = true;
+ }
+ }
+ return ostr.str();
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
+{
+ this->IncludeRegExp = arg;
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
+{
+ this->ExcludeRegExp = arg;
+}
+
+//----------------------------------------------------------------------
+void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
+{
+ if ( !in )
+ {
+ return;
+ }
+ this->TestsToRunString = in;
+ // if the argument is a file, then read it and use the contents as the
+ // string
+ if(cmSystemTools::FileExists(in))
+ {
+ cmsys::ifstream fin(in);
+ unsigned long filelen = cmSystemTools::FileLength(in);
+ char* buff = new char[filelen+1];
+ fin.getline(buff, filelen);
+ buff[fin.gcount()] = 0;
+ this->TestsToRunString = buff;
+ delete [] buff;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length)
+{
+ if(!length || length >= output.size() ||
+ output.find("CTEST_FULL_OUTPUT") != output.npos)
+ {
+ return true;
+ }
+
+ // Truncate at given length but do not break in the middle of a multi-byte
+ // UTF-8 encoding.
+ char const* const begin = output.c_str();
+ char const* const end = begin + output.size();
+ char const* const truncate = begin + length;
+ char const* current = begin;
+ while(current < truncate)
+ {
+ unsigned int ch;
+ if(const char* next = cm_utf8_decode_character(current, end, &ch))
+ {
+ if(next > truncate)
+ {
+ break;
+ }
+ current = next;
+ }
+ else // Bad byte will be handled by cmXMLSafe.
+ {
+ ++current;
+ }
+ }
+ output = output.substr(0, current - begin);
+
+ // Append truncation message.
+ cmOStringStream msg;
+ msg << "...\n"
+ "The rest of the test output was removed since it exceeds the threshold "
+ "of " << length << " bytes.\n";
+ output += msg.str();
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCTestTestHandler::SetTestsProperties(
+ const std::vector<std::string>& args)
+{
+ std::vector<std::string>::const_iterator it;
+ std::vector<std::string> tests;
+ bool found = false;
+ for ( it = args.begin(); it != args.end(); ++ it )
+ {
+ if ( *it == "PROPERTIES" )
+ {
+ found = true;
+ break;
+ }
+ tests.push_back(*it);
+ }
+ if ( !found )
+ {
+ return false;
+ }
+ ++ it; // skip PROPERTIES
+ for ( ; it != args.end(); ++ it )
+ {
+ std::string key = *it;
+ ++ it;
+ if ( it == args.end() )
+ {
+ break;
+ }
+ std::string val = *it;
+ std::vector<std::string>::const_iterator tit;
+ for ( tit = tests.begin(); tit != tests.end(); ++ tit )
+ {
+ cmCTestTestHandler::ListOfTests::iterator rtit;
+ for ( rtit = this->TestList.begin();
+ rtit != this->TestList.end();
+ ++ rtit )
+ {
+ if ( *tit == rtit->Name )
+ {
+ if ( key == "WILL_FAIL" )
+ {
+ rtit->WillFail = cmSystemTools::IsOn(val.c_str());
+ }
+ if ( key == "ATTACHED_FILES" )
+ {
+ std::vector<std::string> lval;
+ cmSystemTools::ExpandListArgument(val, lval);
+
+ for(std::vector<std::string>::iterator f = lval.begin();
+ f != lval.end(); ++f)
+ {
+ rtit->AttachedFiles.push_back(*f);
+ }
+ }
+ if ( key == "ATTACHED_FILES_ON_FAIL" )
+ {
+ std::vector<std::string> lval;
+ cmSystemTools::ExpandListArgument(val, lval);
+
+ for(std::vector<std::string>::iterator f = lval.begin();
+ f != lval.end(); ++f)
+ {
+ rtit->AttachOnFail.push_back(*f);
+ }
+ }
+ if ( key == "RESOURCE_LOCK" )
+ {
+ std::vector<std::string> lval;
+ cmSystemTools::ExpandListArgument(val, lval);
+
+ for(std::vector<std::string>::iterator f = lval.begin();
+ f != lval.end(); ++f)
+ {
+ rtit->LockedResources.insert(*f);
+ }
+ }
+ if ( key == "TIMEOUT" )
+ {
+ rtit->Timeout = atof(val.c_str());
+ rtit->ExplicitTimeout = true;
+ }
+ if ( key == "COST" )
+ {
+ rtit->Cost = static_cast<float>(atof(val.c_str()));
+ }
+ if ( key == "REQUIRED_FILES" )
+ {
+ std::vector<std::string> lval;
+ cmSystemTools::ExpandListArgument(val, lval);
+
+ for(std::vector<std::string>::iterator f = lval.begin();
+ f != lval.end(); ++f)
+ {
+ rtit->RequiredFiles.push_back(*f);
+ }
+ }
+ if ( key == "RUN_SERIAL" )
+ {
+ rtit->RunSerial = cmSystemTools::IsOn(val.c_str());
+ }
+ if ( key == "FAIL_REGULAR_EXPRESSION" )
+ {
+ std::vector<std::string> lval;
+ cmSystemTools::ExpandListArgument(val, lval);
+ std::vector<std::string>::iterator crit;
+ for ( crit = lval.begin(); crit != lval.end(); ++ crit )
+ {
+ rtit->ErrorRegularExpressions.push_back(
+ std::pair<cmsys::RegularExpression, std::string>(
+ cmsys::RegularExpression(crit->c_str()),
+ std::string(*crit)));
+ }
+ }
+ if ( key == "PROCESSORS" )
+ {
+ rtit->Processors = atoi(val.c_str());
+ if(rtit->Processors < 1)
+ {
+ rtit->Processors = 1;
+ }
+ }
+ if ( key == "SKIP_RETURN_CODE" )
+ {
+ rtit->SkipReturnCode = atoi(val.c_str());
+ if(rtit->SkipReturnCode < 0 || rtit->SkipReturnCode > 255)
+ {
+ rtit->SkipReturnCode = -1;
+ }
+ }
+ if ( key == "DEPENDS" )
+ {
+ std::vector<std::string> lval;
+ cmSystemTools::ExpandListArgument(val, lval);
+ std::vector<std::string>::iterator crit;
+ for ( crit = lval.begin(); crit != lval.end(); ++ crit )
+ {
+ rtit->Depends.push_back(*crit);
+ }
+ }
+ if ( key == "ENVIRONMENT" )
+ {
+ std::vector<std::string> lval;
+ cmSystemTools::ExpandListArgument(val, lval);
+ std::vector<std::string>::iterator crit;
+ for ( crit = lval.begin(); crit != lval.end(); ++ crit )
+ {
+ rtit->Environment.push_back(*crit);
+ }
+ }
+ if ( key == "LABELS" )
+ {
+ std::vector<std::string> lval;
+ cmSystemTools::ExpandListArgument(val, lval);
+ std::vector<std::string>::iterator crit;
+ for ( crit = lval.begin(); crit != lval.end(); ++ crit )
+ {
+ rtit->Labels.push_back(*crit);
+ }
+ }
+ if ( key == "MEASUREMENT" )
+ {
+ size_t pos = val.find_first_of("=");
+ if ( pos != val.npos )
+ {
+ std::string mKey = val.substr(0, pos);
+ const char* mVal = val.c_str() + pos + 1;
+ rtit->Measurements[mKey] = mVal;
+ }
+ else
+ {
+ rtit->Measurements[val] = "1";
+ }
+ }
+ if ( key == "PASS_REGULAR_EXPRESSION" )
+ {
+ std::vector<std::string> lval;
+ cmSystemTools::ExpandListArgument(val, lval);
+ std::vector<std::string>::iterator crit;
+ for ( crit = lval.begin(); crit != lval.end(); ++ crit )
+ {
+ rtit->RequiredRegularExpressions.push_back(
+ std::pair<cmsys::RegularExpression, std::string>(
+ cmsys::RegularExpression(crit->c_str()),
+ std::string(*crit)));
+ }
+ }
+ if ( key == "WORKING_DIRECTORY" )
+ {
+ rtit->Directory = val;
+ }
+ }
+ }
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
+{
+ const std::string& testname = args[0];
+ cmCTestLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl);
+
+ if (this->UseExcludeRegExpFlag &&
+ this->UseExcludeRegExpFirst &&
+ this->ExcludeTestsRegularExpression.find(testname.c_str()))
+ {
+ return true;
+ }
+ if ( this->MemCheck )
+ {
+ std::vector<std::string>::iterator it;
+ bool found = false;
+ for ( it = this->CustomTestsIgnore.begin();
+ it != this->CustomTestsIgnore.end(); ++ it )
+ {
+ if ( *it == testname )
+ {
+ found = true;
+ break;
+ }
+ }
+ if ( found )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: "
+ << *it << std::endl);
+ return true;
+ }
+ }
+ else
+ {
+ std::vector<std::string>::iterator it;
+ bool found = false;
+ for ( it = this->CustomTestsIgnore.begin();
+ it != this->CustomTestsIgnore.end(); ++ it )
+ {
+ if ( *it == testname )
+ {
+ found = true;
+ break;
+ }
+ }
+ if ( found )
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: "
+ << *it << std::endl);
+ return true;
+ }
+ }
+
+ cmCTestTestProperties test;
+ test.Name = testname;
+ test.Args = args;
+ test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
+ cmCTestLog(this->CTest, DEBUG, "Set test directory: "
+ << test.Directory << std::endl);
+
+ test.IsInBasedOnREOptions = true;
+ test.WillFail = false;
+ test.RunSerial = false;
+ test.Timeout = 0;
+ test.ExplicitTimeout = false;
+ test.Cost = 0;
+ test.Processors = 1;
+ test.SkipReturnCode = -1;
+ test.PreviousRuns = 0;
+ if (this->UseIncludeRegExpFlag &&
+ !this->IncludeTestsRegularExpression.find(testname.c_str()))
+ {
+ test.IsInBasedOnREOptions = false;
+ }
+ else if (this->UseExcludeRegExpFlag &&
+ !this->UseExcludeRegExpFirst &&
+ this->ExcludeTestsRegularExpression.find(testname.c_str()))
+ {
+ test.IsInBasedOnREOptions = false;
+ }
+ this->TestList.push_back(test);
+ return true;
+}
+
diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h
new file mode 100644
index 0000000000..fe43bb893e
--- /dev/null
+++ b/Source/CTest/cmCTestTestHandler.h
@@ -0,0 +1,290 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestTestHandler_h
+#define cmCTestTestHandler_h
+
+
+#include "cmCTestGenericHandler.h"
+#include <cmsys/RegularExpression.hxx>
+
+class cmMakefile;
+
+/** \class cmCTestTestHandler
+ * \brief A class that handles ctest -S invocations
+ *
+ */
+class cmCTestTestHandler : public cmCTestGenericHandler
+{
+ friend class cmCTestRunTest;
+ friend class cmCTestMultiProcessHandler;
+ friend class cmCTestBatchTestHandler;
+public:
+ cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
+
+ /**
+ * The main entry point for this class
+ */
+ int ProcessHandler();
+
+ /**
+ * When both -R and -I are used should te resulting test list be the
+ * intersection or the union of the lists. By default it is the
+ * intersection.
+ */
+ void SetUseUnion(bool val) { this->UseUnion = val; }
+
+ /**
+ * Set whether or not CTest should only execute the tests that failed
+ * on the previous run. By default this is false.
+ */
+ void SetRerunFailed(bool val) { this->RerunFailed = val; }
+
+ /**
+ * This method is called when reading CTest custom file
+ */
+ void PopulateCustomVectors(cmMakefile *mf);
+
+ ///! Control the use of the regular expresisons, call these methods to turn
+ ///them on
+ void UseIncludeRegExp();
+ void UseExcludeRegExp();
+ void SetIncludeRegExp(const char *);
+ void SetExcludeRegExp(const char *);
+
+ void SetMaxIndex(int n) {this->MaxIndex = n;}
+ int GetMaxIndex() {return this->MaxIndex;}
+
+ ///! pass the -I argument down
+ void SetTestsToRunInformation(const char*);
+
+ cmCTestTestHandler();
+
+ /*
+ * Add the test to the list of tests to be executed
+ */
+ bool AddTest(const std::vector<std::string>& args);
+
+ /*
+ * Set tests properties
+ */
+ bool SetTestsProperties(const std::vector<std::string>& args);
+
+ void Initialize();
+
+ // NOTE: This struct is Saved/Restored
+ // in cmCTestTestHandler, if you add to this class
+ // then you must add the new members to that code or
+ // ctest -j N will break for that feature
+ struct cmCTestTestProperties
+ {
+ std::string Name;
+ std::string Directory;
+ std::vector<std::string> Args;
+ std::vector<std::string> RequiredFiles;
+ std::vector<std::string> Depends;
+ std::vector<std::string> AttachedFiles;
+ std::vector<std::string> AttachOnFail;
+ std::vector<std::pair<cmsys::RegularExpression,
+ std::string> > ErrorRegularExpressions;
+ std::vector<std::pair<cmsys::RegularExpression,
+ std::string> > RequiredRegularExpressions;
+ std::map<std::string, std::string> Measurements;
+ bool IsInBasedOnREOptions;
+ bool WillFail;
+ float Cost;
+ int PreviousRuns;
+ bool RunSerial;
+ double Timeout;
+ bool ExplicitTimeout;
+ int Index;
+ //Requested number of process slots
+ int Processors;
+ // return code of test which will mark test as "not run"
+ int SkipReturnCode;
+ std::vector<std::string> Environment;
+ std::vector<std::string> Labels;
+ std::set<std::string> LockedResources;
+ };
+
+ struct cmCTestTestResult
+ {
+ std::string Name;
+ std::string Path;
+ std::string Reason;
+ std::string FullCommandLine;
+ double ExecutionTime;
+ int ReturnValue;
+ int Status;
+ bool CompressOutput;
+ std::string CompletionStatus;
+ std::string Output;
+ std::string RegressionImages;
+ int TestCount;
+ cmCTestTestProperties* Properties;
+ };
+
+ struct cmCTestTestResultLess
+ {
+ bool operator() (const cmCTestTestResult &lhs,
+ const cmCTestTestResult &rhs) const
+ {
+ return lhs.TestCount < rhs.TestCount;
+ }
+ };
+
+ // add configurations to a search path for an executable
+ static void AddConfigurations(cmCTest *ctest,
+ std::vector<std::string> &attempted,
+ std::vector<std::string> &attemptedConfigs,
+ std::string filepath,
+ std::string &filename);
+
+ // full signature static method to find an executable
+ static std::string FindExecutable(cmCTest *ctest,
+ const char *testCommand,
+ std::string &resultingConfig,
+ std::vector<std::string> &extraPaths,
+ std::vector<std::string> &failed);
+
+ typedef std::vector<cmCTestTestProperties> ListOfTests;
+protected:
+ // compute a final test list
+ virtual int PreProcessHandler();
+ virtual int PostProcessHandler();
+ virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
+ int ExecuteCommands(std::vector<std::string>& vec);
+
+ void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
+ void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
+ // Write attached test files into the xml
+ void AttachFiles(std::ostream& os, cmCTestTestResult* result);
+
+ //! Clean test output to specified length
+ bool CleanTestOutput(std::string& output, size_t length);
+
+ double ElapsedTestingTime;
+
+ typedef std::vector<cmCTestTestResult> TestResultsVector;
+ TestResultsVector TestResults;
+
+ std::vector<std::string> CustomTestsIgnore;
+ std::string StartTest;
+ std::string EndTest;
+ unsigned int StartTestTime;
+ unsigned int EndTestTime;
+ bool MemCheck;
+ int CustomMaximumPassedTestOutputSize;
+ int CustomMaximumFailedTestOutputSize;
+ int MaxIndex;
+public:
+ enum { // Program statuses
+ NOT_RUN = 0,
+ TIMEOUT,
+ SEGFAULT,
+ ILLEGAL,
+ INTERRUPT,
+ NUMERICAL,
+ OTHER_FAULT,
+ FAILED,
+ BAD_COMMAND,
+ COMPLETED
+ };
+
+private:
+ /**
+ * Generate the Dart compatible output
+ */
+ virtual void GenerateDartOutput(std::ostream& os);
+
+ void PrintLabelSummary();
+ /**
+ * Run the tests for a directory and any subdirectories
+ */
+ void ProcessDirectory(std::vector<std::string> &passed,
+ std::vector<std::string> &failed);
+
+ /**
+ * Get the list of tests in directory and subdirectories.
+ */
+ void GetListOfTests();
+ // compute the lists of tests that will actually run
+ // based on union regex and -I stuff
+ void ComputeTestList();
+
+ // compute the lists of tests that will actually run
+ // based on LastTestFailed.log
+ void ComputeTestListForRerunFailed();
+
+ void UpdateMaxTestNameWidth();
+
+ bool GetValue(const char* tag,
+ std::string& value,
+ std::istream& fin);
+ bool GetValue(const char* tag,
+ int& value,
+ std::istream& fin);
+ bool GetValue(const char* tag,
+ size_t& value,
+ std::istream& fin);
+ bool GetValue(const char* tag,
+ bool& value,
+ std::istream& fin);
+ bool GetValue(const char* tag,
+ double& value,
+ std::istream& fin);
+ /**
+ * Find the executable for a test
+ */
+ std::string FindTheExecutable(const char *exe);
+
+ const char* GetTestStatus(int status);
+ void ExpandTestsToRunInformation(size_t numPossibleTests);
+ void ExpandTestsToRunInformationForRerunFailed();
+
+ std::vector<std::string> CustomPreTest;
+ std::vector<std::string> CustomPostTest;
+
+ std::vector<int> TestsToRun;
+
+ bool UseIncludeLabelRegExpFlag;
+ bool UseExcludeLabelRegExpFlag;
+ bool UseIncludeRegExpFlag;
+ bool UseExcludeRegExpFlag;
+ bool UseExcludeRegExpFirst;
+ std::string IncludeLabelRegExp;
+ std::string ExcludeLabelRegExp;
+ std::string IncludeRegExp;
+ std::string ExcludeRegExp;
+ cmsys::RegularExpression IncludeLabelRegularExpression;
+ cmsys::RegularExpression ExcludeLabelRegularExpression;
+ cmsys::RegularExpression IncludeTestsRegularExpression;
+ cmsys::RegularExpression ExcludeTestsRegularExpression;
+
+ std::string GenerateRegressionImages(const std::string& xml);
+ cmsys::RegularExpression DartStuff1;
+ void CheckLabelFilter(cmCTestTestProperties& it);
+ void CheckLabelFilterExclude(cmCTestTestProperties& it);
+ void CheckLabelFilterInclude(cmCTestTestProperties& it);
+
+ std::string TestsToRunString;
+ bool UseUnion;
+ ListOfTests TestList;
+ size_t TotalNumberOfTests;
+ cmsys::RegularExpression DartStuff;
+
+ std::ostream* LogFile;
+
+ bool RerunFailed;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestUpdateCommand.cxx b/Source/CTest/cmCTestUpdateCommand.cxx
new file mode 100644
index 0000000000..f87466d9c3
--- /dev/null
+++ b/Source/CTest/cmCTestUpdateCommand.cxx
@@ -0,0 +1,90 @@
+/*============================================================================
+ 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 "cmCTestUpdateCommand.h"
+
+#include "cmCTest.h"
+#include "cmCTestGenericHandler.h"
+
+cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
+{
+ if ( this->Values[ct_SOURCE] )
+ {
+ this->CTest->SetCTestConfiguration("SourceDirectory",
+ cmSystemTools::CollapseFullPath(
+ this->Values[ct_SOURCE]).c_str());
+ }
+ else
+ {
+ this->CTest->SetCTestConfiguration("SourceDirectory",
+ cmSystemTools::CollapseFullPath(
+ this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
+ }
+ std::string source_dir
+ = this->CTest->GetCTestConfiguration("SourceDirectory");
+
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "UpdateCommand", "CTEST_UPDATE_COMMAND");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "UpdateOptions", "CTEST_UPDATE_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "CVSCommand", "CTEST_CVS_COMMAND");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "CVSUpdateOptions", "CTEST_CVS_UPDATE_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "SVNCommand", "CTEST_SVN_COMMAND");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "SVNUpdateOptions", "CTEST_SVN_UPDATE_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "SVNOptions", "CTEST_SVN_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "BZRCommand", "CTEST_BZR_COMMAND");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "BZRUpdateOptions", "CTEST_BZR_UPDATE_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "GITCommand", "CTEST_GIT_COMMAND");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "GITUpdateOptions", "CTEST_GIT_UPDATE_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "GITUpdateCustom", "CTEST_GIT_UPDATE_CUSTOM");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "UpdateVersionOnly", "CTEST_UPDATE_VERSION_ONLY");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "HGCommand", "CTEST_HG_COMMAND");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "HGUpdateOptions", "CTEST_HG_UPDATE_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "P4Command", "CTEST_P4_COMMAND");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "P4UpdateOptions", "CTEST_P4_UPDATE_OPTIONS");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "P4Client", "CTEST_P4_CLIENT");
+ this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
+ "P4Options", "CTEST_P4_OPTIONS");
+
+ cmCTestGenericHandler* handler
+ = this->CTest->GetInitializedHandler("update");
+ if ( !handler )
+ {
+ this->SetError("internal CTest error. Cannot instantiate update handler");
+ return 0;
+ }
+ handler->SetCommand(this);
+ if ( source_dir.empty() )
+ {
+ this->SetError("source directory not specified. Please use SOURCE tag");
+ return 0;
+ }
+ handler->SetOption("SourceDirectory", source_dir.c_str());
+ return handler;
+}
+
+
diff --git a/Source/CTest/cmCTestUpdateCommand.h b/Source/CTest/cmCTestUpdateCommand.h
new file mode 100644
index 0000000000..fb80333b7f
--- /dev/null
+++ b/Source/CTest/cmCTestUpdateCommand.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmCTestUpdateCommand_h
+#define cmCTestUpdateCommand_h
+
+#include "cmCTestHandlerCommand.h"
+
+/** \class cmCTestUpdate
+ * \brief Run a ctest script
+ *
+ * cmCTestUpdateCommand defineds the command to updates the repository.
+ */
+class cmCTestUpdateCommand : public cmCTestHandlerCommand
+{
+public:
+
+ cmCTestUpdateCommand() {}
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestUpdateCommand* ni = new cmCTestUpdateCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_update";}
+
+ cmTypeMacro(cmCTestUpdateCommand, cmCTestHandlerCommand);
+
+protected:
+ cmCTestGenericHandler* InitializeHandler();
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx
new file mode 100644
index 0000000000..68f5fe133e
--- /dev/null
+++ b/Source/CTest/cmCTestUpdateHandler.cxx
@@ -0,0 +1,429 @@
+/*============================================================================
+ 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 "cmCTestUpdateHandler.h"
+
+#include "cmCTest.h"
+#include "cmake.h"
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmVersion.h"
+#include "cmGeneratedFileStream.h"
+#include "cmXMLParser.h"
+#include "cmXMLSafe.h"
+
+#include "cmCTestVC.h"
+#include "cmCTestCVS.h"
+#include "cmCTestSVN.h"
+#include "cmCTestBZR.h"
+#include "cmCTestGIT.h"
+#include "cmCTestHG.h"
+#include "cmCTestP4.h"
+
+#include <cmsys/auto_ptr.hxx>
+
+//#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Process.h>
+
+// used for sleep
+#ifdef _WIN32
+#include "windows.h"
+#endif
+
+#include <stdlib.h>
+#include <math.h>
+#include <float.h>
+
+//----------------------------------------------------------------------
+static const char* cmCTestUpdateHandlerUpdateStrings[] =
+{
+ "Unknown",
+ "CVS",
+ "SVN",
+ "BZR",
+ "GIT",
+ "HG",
+ "P4"
+};
+
+static const char* cmCTestUpdateHandlerUpdateToString(int type)
+{
+ if ( type < cmCTestUpdateHandler::e_UNKNOWN ||
+ type >= cmCTestUpdateHandler::e_LAST )
+ {
+ return cmCTestUpdateHandlerUpdateStrings[cmCTestUpdateHandler::e_UNKNOWN];
+ }
+ return cmCTestUpdateHandlerUpdateStrings[type];
+}
+
+class cmCTestUpdateHandlerLocale
+{
+public:
+ cmCTestUpdateHandlerLocale();
+ ~cmCTestUpdateHandlerLocale();
+private:
+ std::string saveLCMessages;
+};
+
+cmCTestUpdateHandlerLocale::cmCTestUpdateHandlerLocale()
+{
+ const char* lcmess = cmSystemTools::GetEnv("LC_MESSAGES");
+ if(lcmess)
+ {
+ saveLCMessages = lcmess;
+ }
+ // if LC_MESSAGES is not set to C, then
+ // set it, so that svn/cvs info will be in english ascii
+ if(! (lcmess && strcmp(lcmess, "C") == 0))
+ {
+ cmSystemTools::PutEnv("LC_MESSAGES=C");
+ }
+}
+
+cmCTestUpdateHandlerLocale::~cmCTestUpdateHandlerLocale()
+{
+ // restore the value of LC_MESSAGES after running the version control
+ // commands
+ if(saveLCMessages.size())
+ {
+ std::string put = "LC_MESSAGES=";
+ put += saveLCMessages;
+ cmSystemTools::PutEnv(put.c_str());
+ }
+ else
+ {
+ cmSystemTools::UnsetEnv("LC_MESSAGES");
+ }
+}
+
+//----------------------------------------------------------------------
+cmCTestUpdateHandler::cmCTestUpdateHandler()
+{
+}
+
+//----------------------------------------------------------------------
+void cmCTestUpdateHandler::Initialize()
+{
+ this->Superclass::Initialize();
+ this->UpdateCommand = "";
+ this->UpdateType = e_CVS;
+}
+
+//----------------------------------------------------------------------
+int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
+{
+ cmCTestLog(this->CTest, DEBUG, "Determine update type from command: " << cmd
+ << " and type: " << type << std::endl);
+ if ( type && *type )
+ {
+ cmCTestLog(this->CTest, DEBUG, "Type specified: " << type << std::endl);
+ std::string stype = cmSystemTools::LowerCase(type);
+ if ( stype.find("cvs") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_CVS;
+ }
+ if ( stype.find("svn") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_SVN;
+ }
+ if ( stype.find("bzr") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_BZR;
+ }
+ if ( stype.find("git") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_GIT;
+ }
+ if ( stype.find("hg") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_HG;
+ }
+ if ( stype.find("p4") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_P4;
+ }
+ }
+ else
+ {
+ cmCTestLog(this->CTest, DEBUG, "Type not specified, check command: "
+ << cmd << std::endl);
+ std::string stype = cmSystemTools::LowerCase(cmd);
+ if ( stype.find("cvs") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_CVS;
+ }
+ if ( stype.find("svn") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_SVN;
+ }
+ if ( stype.find("bzr") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_BZR;
+ }
+ if ( stype.find("git") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_GIT;
+ }
+ if ( stype.find("hg") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_HG;
+ }
+ if ( stype.find("p4") != std::string::npos )
+ {
+ return cmCTestUpdateHandler::e_P4;
+ }
+ }
+ return cmCTestUpdateHandler::e_UNKNOWN;
+}
+
+//----------------------------------------------------------------------
+//clearly it would be nice if this were broken up into a few smaller
+//functions and commented...
+int cmCTestUpdateHandler::ProcessHandler()
+{
+ // Make sure VCS tool messages are in English so we can parse them.
+ cmCTestUpdateHandlerLocale fixLocale;
+ static_cast<void>(fixLocale);
+
+ // Get source dir
+ const char* sourceDirectory = this->GetOption("SourceDirectory");
+ if ( !sourceDirectory )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find SourceDirectory key in the DartConfiguration.tcl"
+ << std::endl);
+ return -1;
+ }
+
+ cmGeneratedFileStream ofs;
+ if ( !this->CTest->GetShowOnly() )
+ {
+ this->StartLogFile("Update", ofs);
+ }
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Updating the repository: "
+ << sourceDirectory << std::endl);
+
+ if(!this->SelectVCS())
+ {
+ return -1;
+ }
+
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, " Use "
+ << cmCTestUpdateHandlerUpdateToString(this->UpdateType)
+ << " repository type"
+ << std::endl;);
+
+ // Create an object to interact with the VCS tool.
+ cmsys::auto_ptr<cmCTestVC> vc;
+ switch (this->UpdateType)
+ {
+ case e_CVS: vc.reset(new cmCTestCVS(this->CTest, ofs)); break;
+ case e_SVN: vc.reset(new cmCTestSVN(this->CTest, ofs)); break;
+ case e_BZR: vc.reset(new cmCTestBZR(this->CTest, ofs)); break;
+ case e_GIT: vc.reset(new cmCTestGIT(this->CTest, ofs)); break;
+ case e_HG: vc.reset(new cmCTestHG(this->CTest, ofs)); break;
+ case e_P4: vc.reset(new cmCTestP4(this->CTest, ofs)); break;
+ default: vc.reset(new cmCTestVC(this->CTest, ofs)); break;
+ }
+ vc->SetCommandLineTool(this->UpdateCommand);
+ vc->SetSourceDirectory(sourceDirectory);
+
+ // Cleanup the working tree.
+ vc->Cleanup();
+
+ //
+ // Now update repository and remember what files were updated
+ //
+ cmGeneratedFileStream os;
+ if(!this->StartResultingXML(cmCTest::PartUpdate, "Update", os))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open log file"
+ << std::endl);
+ return -1;
+ }
+ std::string start_time = this->CTest->CurrentTime();
+ unsigned int start_time_time =
+ static_cast<unsigned int>(cmSystemTools::GetTime());
+ double elapsed_time_start = cmSystemTools::GetTime();
+
+ bool updated = vc->Update();
+ std::string buildname = cmCTest::SafeBuildIdField(
+ this->CTest->GetCTestConfiguration("BuildName"));
+ os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ << "<Update mode=\"Client\" Generator=\"ctest-"
+ << cmVersion::GetCMakeVersion() << "\">\n"
+ << "\t<Site>" << this->CTest->GetCTestConfiguration("Site") << "</Site>\n"
+ << "\t<BuildName>" << buildname
+ << "</BuildName>\n"
+ << "\t<BuildStamp>" << this->CTest->GetCurrentTag() << "-"
+ << this->CTest->GetTestModelString() << "</BuildStamp>" << std::endl;
+ os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
+ << "\t<StartTime>" << start_time_time << "</StartTime>\n"
+ << "\t<UpdateCommand>"
+ << cmXMLSafe(vc->GetUpdateCommandLine()).Quotes(false)
+ << "</UpdateCommand>\n"
+ << "\t<UpdateType>" << cmXMLSafe(
+ cmCTestUpdateHandlerUpdateToString(this->UpdateType))
+ << "</UpdateType>\n";
+
+ vc->WriteXML(os);
+
+ int localModifications = 0;
+ int numUpdated = vc->GetPathCount(cmCTestVC::PathUpdated);
+ if(numUpdated)
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Found " << numUpdated << " updated files\n");
+ }
+ if(int numModified = vc->GetPathCount(cmCTestVC::PathModified))
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Found " << numModified << " locally modified files\n");
+ localModifications += numModified;
+ }
+ if(int numConflicting = vc->GetPathCount(cmCTestVC::PathConflicting))
+ {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Found " << numConflicting << " conflicting files\n");
+ localModifications += numConflicting;
+ }
+
+ cmCTestLog(this->CTest, DEBUG, "End" << std::endl);
+ std::string end_time = this->CTest->CurrentTime();
+ os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
+ << "\t<EndTime>" << static_cast<unsigned int>(cmSystemTools::GetTime())
+ << "</EndTime>\n"
+ << "<ElapsedMinutes>" <<
+ static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
+ << "</ElapsedMinutes>\n"
+ << "\t<UpdateReturnStatus>";
+ if(localModifications)
+ {
+ os << "Update error: There are modified or conflicting files in the "
+ "repository";
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ " There are modified or conflicting files in the repository"
+ << std::endl);
+ }
+ if(!updated)
+ {
+ os << "Update command failed:\n" << vc->GetUpdateCommandLine();
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " Update command failed: "
+ << vc->GetUpdateCommandLine() << "\n");
+ }
+ os << "</UpdateReturnStatus>" << std::endl;
+ os << "</Update>" << std::endl;
+ return numUpdated;
+}
+
+//----------------------------------------------------------------------
+int cmCTestUpdateHandler::DetectVCS(const char* dir)
+{
+ std::string sourceDirectory = dir;
+ cmCTestLog(this->CTest, DEBUG, "Check directory: "
+ << sourceDirectory << std::endl);
+ sourceDirectory += "/.svn";
+ if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
+ {
+ return cmCTestUpdateHandler::e_SVN;
+ }
+ sourceDirectory = dir;
+ sourceDirectory += "/CVS";
+ if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
+ {
+ return cmCTestUpdateHandler::e_CVS;
+ }
+ sourceDirectory = dir;
+ sourceDirectory += "/.bzr";
+ if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
+ {
+ return cmCTestUpdateHandler::e_BZR;
+ }
+ sourceDirectory = dir;
+ sourceDirectory += "/.git";
+ if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
+ {
+ return cmCTestUpdateHandler::e_GIT;
+ }
+ sourceDirectory = dir;
+ sourceDirectory += "/.hg";
+ if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
+ {
+ return cmCTestUpdateHandler::e_HG;
+ }
+ sourceDirectory = dir;
+ sourceDirectory += "/.p4";
+ if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
+ {
+ return cmCTestUpdateHandler::e_P4;
+ }
+ sourceDirectory = dir;
+ sourceDirectory += "/.p4config";
+ if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
+ {
+ return cmCTestUpdateHandler::e_P4;
+ }
+ return cmCTestUpdateHandler::e_UNKNOWN;
+}
+
+//----------------------------------------------------------------------
+bool cmCTestUpdateHandler::SelectVCS()
+{
+ // Get update command
+ this->UpdateCommand = this->CTest->GetCTestConfiguration("UpdateCommand");
+
+ // Detect the VCS managing the source tree.
+ this->UpdateType = this->DetectVCS(this->GetOption("SourceDirectory"));
+ if (this->UpdateType == e_UNKNOWN)
+ {
+ // The source tree does not have a recognized VCS. Check the
+ // configuration value or command name.
+ this->UpdateType = this->DetermineType(this->UpdateCommand.c_str(),
+ this->CTest->GetCTestConfiguration("UpdateType").c_str());
+ }
+
+ // If no update command was specified, lookup one for this VCS tool.
+ if (this->UpdateCommand.empty())
+ {
+ const char* key = 0;
+ switch (this->UpdateType)
+ {
+ case e_CVS: key = "CVSCommand"; break;
+ case e_SVN: key = "SVNCommand"; break;
+ case e_BZR: key = "BZRCommand"; break;
+ case e_GIT: key = "GITCommand"; break;
+ case e_HG: key = "HGCommand"; break;
+ case e_P4: key = "P4Command"; break;
+ default: break;
+ }
+ if (key)
+ {
+ this->UpdateCommand = this->CTest->GetCTestConfiguration(key);
+ }
+ if (this->UpdateCommand.empty())
+ {
+ cmOStringStream e;
+ e << "Cannot find UpdateCommand ";
+ if (key)
+ {
+ e << "or " << key;
+ }
+ e << " configuration key.";
+ cmCTestLog(this->CTest, ERROR_MESSAGE, e.str() << std::endl);
+ return false;
+ }
+ }
+
+ return true;
+}
diff --git a/Source/CTest/cmCTestUpdateHandler.h b/Source/CTest/cmCTestUpdateHandler.h
new file mode 100644
index 0000000000..954c024f11
--- /dev/null
+++ b/Source/CTest/cmCTestUpdateHandler.h
@@ -0,0 +1,77 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestUpdateHandler_h
+#define cmCTestUpdateHandler_h
+
+
+#include "cmCTestGenericHandler.h"
+#include "cmListFileCache.h"
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 1375 /* base class destructor not virtual */
+#endif
+
+/** \class cmCTestUpdateHandler
+ * \brief A class that handles ctest -S invocations
+ *
+ */
+class cmCTestUpdateHandler : public cmCTestGenericHandler
+{
+public:
+ cmTypeMacro(cmCTestUpdateHandler, cmCTestGenericHandler);
+
+ /*
+ * The main entry point for this class
+ */
+ int ProcessHandler();
+
+ cmCTestUpdateHandler();
+
+ enum {
+ e_UNKNOWN = 0,
+ e_CVS,
+ e_SVN,
+ e_BZR,
+ e_GIT,
+ e_HG,
+ e_P4,
+ e_LAST
+ };
+
+ /**
+ * Initialize handler
+ */
+ virtual void Initialize();
+
+private:
+ // Some structures needed for update
+ struct StringPair :
+ public std::pair<std::string, std::string>{};
+ struct UpdateFiles : public std::vector<StringPair>{};
+
+ // Determine the type of version control
+ int DetermineType(const char* cmd, const char* type);
+
+ // The VCS command to update the working tree.
+ std::string UpdateCommand;
+ int UpdateType;
+
+ int DetectVCS(const char* dir);
+ bool SelectVCS();
+};
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma reset woff 1375 /* base class destructor not virtual */
+#endif
+
+#endif
diff --git a/Source/CTest/cmCTestUploadCommand.cxx b/Source/CTest/cmCTestUploadCommand.cxx
new file mode 100644
index 0000000000..f7de29471f
--- /dev/null
+++ b/Source/CTest/cmCTestUploadCommand.cxx
@@ -0,0 +1,69 @@
+/*============================================================================
+ 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 "cmCTestUploadCommand.h"
+
+#include "cmCTest.h"
+#include "cmCTestGenericHandler.h"
+#include "cmCTestUploadHandler.h"
+
+cmCTestGenericHandler* cmCTestUploadCommand::InitializeHandler()
+{
+ cmCTestGenericHandler* handler
+ = this->CTest->GetInitializedHandler("upload");
+ if ( !handler )
+ {
+ this->SetError("internal CTest error. Cannot instantiate upload handler");
+ return 0;
+ }
+ static_cast<cmCTestUploadHandler*>(handler)->SetFiles(this->Files);
+
+ return handler;
+}
+
+
+//----------------------------------------------------------------------------
+bool cmCTestUploadCommand::CheckArgumentKeyword(std::string const& arg)
+{
+ if(arg == "FILES")
+ {
+ this->ArgumentDoing = ArgumentDoingFiles;
+ return true;
+ }
+ return false;
+}
+
+
+//----------------------------------------------------------------------------
+bool cmCTestUploadCommand::CheckArgumentValue(std::string const& arg)
+{
+ if(this->ArgumentDoing == ArgumentDoingFiles)
+ {
+ std::string filename(arg);
+ if(cmSystemTools::FileExists(filename.c_str()))
+ {
+ this->Files.insert(filename);
+ return true;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "File \"" << filename << "\" does not exist. Cannot submit "
+ << "a non-existent file.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->ArgumentDoing = ArgumentDoingError;
+ return false;
+ }
+ }
+
+ // Look for other arguments.
+ return this->Superclass::CheckArgumentValue(arg);
+}
diff --git a/Source/CTest/cmCTestUploadCommand.h b/Source/CTest/cmCTestUploadCommand.h
new file mode 100644
index 0000000000..4a07608d25
--- /dev/null
+++ b/Source/CTest/cmCTestUploadCommand.h
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 cmCTestUploadCommand_h
+#define cmCTestUploadCommand_h
+
+#include "cmCTestHandlerCommand.h"
+#include "cmCTest.h"
+
+/** \class cmCTestUpload
+ * \brief Run a ctest script
+ *
+ * cmCTestUploadCommand defines the command to upload result files for
+ * the project.
+ */
+class cmCTestUploadCommand : public cmCTestHandlerCommand
+{
+public:
+
+ cmCTestUploadCommand()
+ {
+ }
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmCTestUploadCommand* ni = new cmCTestUploadCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "ctest_upload";}
+
+ cmTypeMacro(cmCTestUploadCommand, cmCTestHandlerCommand);
+
+protected:
+ cmCTestGenericHandler* InitializeHandler();
+
+ virtual bool CheckArgumentKeyword(std::string const& arg);
+ virtual bool CheckArgumentValue(std::string const& arg);
+
+ enum
+ {
+ ArgumentDoingFiles = Superclass::ArgumentDoingLast1,
+ ArgumentDoingLast2
+ };
+
+ cmCTest::SetOfStrings Files;
+};
+
+
+#endif
diff --git a/Source/CTest/cmCTestUploadHandler.cxx b/Source/CTest/cmCTestUploadHandler.cxx
new file mode 100644
index 0000000000..e33c3871aa
--- /dev/null
+++ b/Source/CTest/cmCTestUploadHandler.cxx
@@ -0,0 +1,78 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestUploadHandler.h"
+
+#include "cmGeneratedFileStream.h"
+#include "cmVersion.h"
+#include "cmXMLSafe.h"
+
+//----------------------------------------------------------------------------
+cmCTestUploadHandler::cmCTestUploadHandler()
+{
+ this->Initialize();
+}
+
+//----------------------------------------------------------------------------
+void cmCTestUploadHandler::Initialize()
+{
+ this->Superclass::Initialize();
+ this->Files.clear();
+}
+
+void cmCTestUploadHandler::SetFiles(const cmCTest::SetOfStrings& files)
+{
+ this->Files = files;
+}
+
+//----------------------------------------------------------------------------
+int cmCTestUploadHandler::ProcessHandler()
+{
+ cmGeneratedFileStream ofs;
+ if ( !this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(),
+ "Upload.xml", ofs))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot open Upload.xml file" << std::endl);
+ return -1;
+ }
+ std::string buildname = cmCTest::SafeBuildIdField(
+ this->CTest->GetCTestConfiguration("BuildName"));
+ cmCTest::SetOfStrings::const_iterator it;
+ ofs << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ << "<?xml-stylesheet type=\"text/xsl\" "
+ "href=\"Dart/Source/Server/XSL/Build.xsl "
+ "<file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
+ << "<Site BuildName=\""
+ << buildname
+ << "\" BuildStamp=\""
+ << this->CTest->GetCurrentTag() << "-"
+ << this->CTest->GetTestModelString() << "\" Name=\""
+ << this->CTest->GetCTestConfiguration("Site") << "\" Generator=\"ctest"
+ << cmVersion::GetCMakeVersion()
+ << "\">\n";
+ this->CTest->AddSiteProperties(ofs);
+ ofs << "<Upload>\n";
+
+ for ( it = this->Files.begin(); it != this->Files.end(); it ++ )
+ {
+ cmCTestLog(this->CTest, OUTPUT,
+ "\tUpload file: " << *it << std::endl);
+ ofs << "<File filename=\"" << cmXMLSafe(*it) << "\">\n"
+ << "<Content encoding=\"base64\">\n";
+ ofs << this->CTest->Base64EncodeFile(*it);
+ ofs << "\n</Content>\n"
+ << "</File>\n";
+ }
+ ofs << "</Upload>\n"
+ << "</Site>\n";
+ return 0;
+}
diff --git a/Source/CTest/cmCTestUploadHandler.h b/Source/CTest/cmCTestUploadHandler.h
new file mode 100644
index 0000000000..23ed35a256
--- /dev/null
+++ b/Source/CTest/cmCTestUploadHandler.h
@@ -0,0 +1,45 @@
+/*============================================================================
+ 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 cmCTestUploadHandler_h
+#define cmCTestUploadHandler_h
+
+#include "cmCTestGenericHandler.h"
+
+/** \class cmCTestUploadHandler
+ * \brief Helper class for CTest
+ *
+ * Submit arbitrary files
+ *
+ */
+class cmCTestUploadHandler : public cmCTestGenericHandler
+{
+public:
+ cmTypeMacro(cmCTestUploadHandler, cmCTestGenericHandler);
+
+ cmCTestUploadHandler();
+ ~cmCTestUploadHandler() {}
+
+ /*
+ * The main entry point for this class
+ */
+ int ProcessHandler();
+
+ void Initialize();
+
+ /** Specify a set of files to submit. */
+ void SetFiles(cmCTest::SetOfStrings const& files);
+
+private:
+ cmCTest::SetOfStrings Files;
+};
+
+#endif
diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx
new file mode 100644
index 0000000000..15f796f0ab
--- /dev/null
+++ b/Source/CTest/cmCTestVC.cxx
@@ -0,0 +1,248 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 "cmCTestVC.h"
+
+#include "cmCTest.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/Process.h>
+
+//----------------------------------------------------------------------------
+cmCTestVC::cmCTestVC(cmCTest* ct, std::ostream& log): CTest(ct), Log(log)
+{
+ this->PathCount[PathUpdated] = 0;
+ this->PathCount[PathModified] = 0;
+ this->PathCount[PathConflicting] = 0;
+ this->Unknown.Date = "Unknown";
+ this->Unknown.Author = "Unknown";
+ this->Unknown.Rev = "Unknown";
+}
+
+//----------------------------------------------------------------------------
+cmCTestVC::~cmCTestVC()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmCTestVC::SetCommandLineTool(std::string const& tool)
+{
+ this->CommandLineTool = tool;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestVC::SetSourceDirectory(std::string const& dir)
+{
+ this->SourceDirectory = dir;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestVC::InitialCheckout(const char* command)
+{
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " First perform the initial checkout: " << command << "\n");
+
+ // Make the parent directory in which to perform the checkout.
+ std::string parent = cmSystemTools::GetFilenamePath(this->SourceDirectory);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Perform checkout in directory: " << parent << "\n");
+ if(!cmSystemTools::MakeDirectory(parent.c_str()))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot create directory: " << parent << std::endl);
+ return false;
+ }
+
+ // Construct the initial checkout command line.
+ std::vector<std::string> args = cmSystemTools::ParseArguments(command);
+ std::vector<char const*> vc_co;
+ for(std::vector<std::string>::const_iterator ai = args.begin();
+ ai != args.end(); ++ai)
+ {
+ vc_co.push_back(ai->c_str());
+ }
+ vc_co.push_back(0);
+
+ // Run the initial checkout command and log its output.
+ this->Log << "--- Begin Initial Checkout ---\n";
+ OutputLogger out(this->Log, "co-out> ");
+ OutputLogger err(this->Log, "co-err> ");
+ bool result = this->RunChild(&vc_co[0], &out, &err, parent.c_str());
+ this->Log << "--- End Initial Checkout ---\n";
+ if(!result)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Initial checkout failed!" << std::endl);
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestVC::RunChild(char const* const* cmd, OutputParser* out,
+ OutputParser* err, const char* workDir)
+{
+ this->Log << this->ComputeCommandLine(cmd) << "\n";
+
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetCommand(cp, cmd);
+ workDir = workDir? workDir : this->SourceDirectory.c_str();
+ cmsysProcess_SetWorkingDirectory(cp, workDir);
+ this->RunProcess(cp, out, err);
+ int result = cmsysProcess_GetExitValue(cp);
+ cmsysProcess_Delete(cp);
+ return result == 0;
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTestVC::ComputeCommandLine(char const* const* cmd)
+{
+ cmOStringStream line;
+ const char* sep = "";
+ for(const char* const* arg = cmd; *arg; ++arg)
+ {
+ line << sep << "\"" << *arg << "\"";
+ sep = " ";
+ }
+ return line.str();
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestVC::RunUpdateCommand(char const* const* cmd,
+ OutputParser* out, OutputParser* err)
+{
+ // Report the command line.
+ this->UpdateCommandLine = this->ComputeCommandLine(cmd);
+ if(this->CTest->GetShowOnly())
+ {
+ this->Log << this->UpdateCommandLine << "\n";
+ return true;
+ }
+
+ // Run the command.
+ return this->RunChild(cmd, out, err);
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTestVC::GetNightlyTime()
+{
+ // Get the nightly start time corresponding to the current dau.
+ struct tm* t = this->CTest->GetNightlyTime(
+ this->CTest->GetCTestConfiguration("NightlyStartTime"),
+ this->CTest->GetTomorrowTag());
+ char current_time[1024];
+ sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d",
+ t->tm_year + 1900,
+ t->tm_mon + 1,
+ t->tm_mday,
+ t->tm_hour,
+ t->tm_min,
+ t->tm_sec);
+ return std::string(current_time);
+}
+
+//----------------------------------------------------------------------------
+void cmCTestVC::Cleanup()
+{
+ this->Log << "--- Begin Cleanup ---\n";
+ this->CleanupImpl();
+ this->Log << "--- End Cleanup ---\n";
+}
+
+//----------------------------------------------------------------------------
+void cmCTestVC::CleanupImpl()
+{
+ // We do no cleanup by default.
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestVC::Update()
+{
+ bool result = true;
+ // if update version only is on then do not actually update,
+ // just note the current version and finish
+ if(!cmSystemTools::IsOn(
+ this->CTest->GetCTestConfiguration("UpdateVersionOnly").c_str()))
+ {
+ this->NoteOldRevision();
+ this->Log << "--- Begin Update ---\n";
+ result = this->UpdateImpl();
+ this->Log << "--- End Update ---\n";
+ }
+ this->NoteNewRevision();
+ return result;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestVC::NoteOldRevision()
+{
+ // We do nothing by default.
+}
+
+//----------------------------------------------------------------------------
+void cmCTestVC::NoteNewRevision()
+{
+ // We do nothing by default.
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestVC::UpdateImpl()
+{
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "* Unknown VCS tool, not updating!" << std::endl);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestVC::WriteXML(std::ostream& xml)
+{
+ this->Log << "--- Begin Revisions ---\n";
+ bool result = this->WriteXMLUpdates(xml);
+ this->Log << "--- End Revisions ---\n";
+ return result;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTestVC::WriteXMLUpdates(std::ostream&)
+{
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "* CTest cannot extract updates for this VCS tool.\n");
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmCTestVC::WriteXMLEntry(std::ostream& xml,
+ std::string const& path,
+ std::string const& name,
+ std::string const& full,
+ File const& f)
+{
+ static const char* desc[3] = { "Updated", "Modified", "Conflicting"};
+ Revision const& rev = f.Rev? *f.Rev : this->Unknown;
+ std::string prior = f.PriorRev? f.PriorRev->Rev : std::string("Unknown");
+ xml << "\t\t<" << desc[f.Status] << ">\n"
+ << "\t\t\t<File>" << cmXMLSafe(name) << "</File>\n"
+ << "\t\t\t<Directory>" << cmXMLSafe(path) << "</Directory>\n"
+ << "\t\t\t<FullName>" << cmXMLSafe(full) << "</FullName>\n"
+ << "\t\t\t<CheckinDate>" << cmXMLSafe(rev.Date) << "</CheckinDate>\n"
+ << "\t\t\t<Author>" << cmXMLSafe(rev.Author) << "</Author>\n"
+ << "\t\t\t<Email>" << cmXMLSafe(rev.EMail) << "</Email>\n"
+ << "\t\t\t<Committer>" << cmXMLSafe(rev.Committer) << "</Committer>\n"
+ << "\t\t\t<CommitterEmail>" << cmXMLSafe(rev.CommitterEMail)
+ << "</CommitterEmail>\n"
+ << "\t\t\t<CommitDate>" << cmXMLSafe(rev.CommitDate)
+ << "</CommitDate>\n"
+ << "\t\t\t<Log>" << cmXMLSafe(rev.Log) << "</Log>\n"
+ << "\t\t\t<Revision>" << cmXMLSafe(rev.Rev) << "</Revision>\n"
+ << "\t\t\t<PriorRevision>" << cmXMLSafe(prior) << "</PriorRevision>\n"
+ << "\t\t</" << desc[f.Status] << ">\n";
+ ++this->PathCount[f.Status];
+}
diff --git a/Source/CTest/cmCTestVC.h b/Source/CTest/cmCTestVC.h
new file mode 100644
index 0000000000..9dd06515d9
--- /dev/null
+++ b/Source/CTest/cmCTestVC.h
@@ -0,0 +1,137 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmCTestVC_h
+#define cmCTestVC_h
+
+#include "cmProcessTools.h"
+
+class cmCTest;
+
+/** \class cmCTestVC
+ * \brief Base class for version control system handlers
+ *
+ */
+class cmCTestVC: public cmProcessTools
+{
+public:
+ /** Construct with a CTest instance and update log stream. */
+ cmCTestVC(cmCTest* ctest, std::ostream& log);
+
+ virtual ~cmCTestVC();
+
+ /** Command line tool to invoke. */
+ void SetCommandLineTool(std::string const& tool);
+
+ /** Top-level source directory. */
+ void SetSourceDirectory(std::string const& dir);
+
+ /** Get the date/time specification for the current nightly start time. */
+ std::string GetNightlyTime();
+
+ /** Prepare the work tree. */
+ bool InitialCheckout(const char* command);
+
+ /** Perform cleanup operations on the work tree. */
+ void Cleanup();
+
+ /** Update the working tree to the new revision. */
+ bool Update();
+
+ /** Get the command line used by the Update method. */
+ std::string const& GetUpdateCommandLine() const
+ { return this->UpdateCommandLine; }
+
+ /** Write Update.xml entries for the updates found. */
+ bool WriteXML(std::ostream& xml);
+
+ /** Enumerate non-trivial working tree states during update. */
+ enum PathStatus { PathUpdated, PathModified, PathConflicting };
+
+ /** Get the number of working tree paths in each state after update. */
+ int GetPathCount(PathStatus s) const { return this->PathCount[s]; }
+
+protected:
+ // Internal API to be implemented by subclasses.
+ virtual void CleanupImpl();
+ virtual void NoteOldRevision();
+ virtual bool UpdateImpl();
+ virtual void NoteNewRevision();
+ virtual bool WriteXMLUpdates(std::ostream& xml);
+
+#if defined(__SUNPRO_CC) && __SUNPRO_CC <= 0x510
+public: // Sun CC 5.1 needs help to allow cmCTestSVN::Revision to see this
+#endif
+ /** Basic information about one revision of a tree or file. */
+ struct Revision
+ {
+ std::string Rev;
+ std::string Date;
+ std::string Author;
+ std::string EMail;
+ std::string Committer;
+ std::string CommitterEMail;
+ std::string CommitDate;
+ std::string Log;
+ };
+
+protected:
+ struct File;
+ friend struct File;
+
+ /** Represent change to one file. */
+ struct File
+ {
+ PathStatus Status;
+ Revision const* Rev;
+ Revision const* PriorRev;
+ File(): Status(PathUpdated), Rev(0), PriorRev(0) {}
+ File(PathStatus status, Revision const* rev, Revision const* priorRev):
+ Status(status), Rev(rev), PriorRev(priorRev) {}
+ };
+
+ /** Convert a list of arguments to a human-readable command line. */
+ static std::string ComputeCommandLine(char const* const* cmd);
+
+ /** Run a command line and send output to given parsers. */
+ bool RunChild(char const* const* cmd, OutputParser* out,
+ OutputParser* err, const char* workDir = 0);
+
+ /** Run VC update command line and send output to given parsers. */
+ bool RunUpdateCommand(char const* const* cmd,
+ OutputParser* out, OutputParser* err = 0);
+
+ /** Write xml element for one file. */
+ void WriteXMLEntry(std::ostream& xml, std::string const& path,
+ std::string const& name, std::string const& full,
+ File const& f);
+
+ // Instance of cmCTest running the script.
+ cmCTest* CTest;
+
+ // A stream to which we write log information.
+ std::ostream& Log;
+
+ // Basic information about the working tree.
+ std::string CommandLineTool;
+ std::string SourceDirectory;
+
+ // Record update command info.
+ std::string UpdateCommandLine;
+
+ // Placeholder for unknown revisions.
+ Revision Unknown;
+
+ // Count paths reported with each PathStatus value.
+ int PathCount[3];
+};
+
+#endif
diff --git a/Source/CTest/cmParseCacheCoverage.cxx b/Source/CTest/cmParseCacheCoverage.cxx
new file mode 100644
index 0000000000..d17f169ea7
--- /dev/null
+++ b/Source/CTest/cmParseCacheCoverage.cxx
@@ -0,0 +1,233 @@
+#include "cmStandardIncludes.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "cmSystemTools.h"
+#include "cmParseCacheCoverage.h"
+#include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+
+
+cmParseCacheCoverage::cmParseCacheCoverage(
+ cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest)
+ :cmParseMumpsCoverage(cont, ctest)
+{
+}
+
+
+bool cmParseCacheCoverage::LoadCoverageData(const char* d)
+{
+ // load all the .mcov files in the specified directory
+ cmsys::Directory dir;
+ if(!dir.Load(d))
+ {
+ return false;
+ }
+ size_t numf;
+ unsigned int i;
+ numf = dir.GetNumberOfFiles();
+ for (i = 0; i < numf; i++)
+ {
+ std::string file = dir.GetFile(i);
+ if(file != "." && file != ".."
+ && !cmSystemTools::FileIsDirectory(file.c_str()))
+ {
+ std::string path = d;
+ path += "/";
+ path += file;
+ if(cmSystemTools::GetFilenameLastExtension(path) == ".cmcov")
+ {
+ if(!this->ReadCMCovFile(path.c_str()))
+ {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+
+// not currently used, but leave it in case we want it in the future
+void cmParseCacheCoverage::RemoveUnCoveredFiles()
+{
+ // loop over the coverage data computed and remove all files
+ // that only have -1 or 0 for the lines.
+ cmCTestCoverageHandlerContainer::TotalCoverageMap::iterator ci =
+ this->Coverage.TotalCoverage.begin();
+ while(ci != this->Coverage.TotalCoverage.end())
+ {
+ cmCTestCoverageHandlerContainer::SingleFileCoverageVector& v =
+ ci->second;
+ bool nothing = true;
+ for(cmCTestCoverageHandlerContainer::SingleFileCoverageVector::iterator i=
+ v.begin(); i != v.end(); ++i)
+ {
+ if(*i > 0)
+ {
+ nothing = false;
+ break;
+ }
+ }
+ if(nothing)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "No coverage found in: " << ci->first
+ << std::endl);
+ this->Coverage.TotalCoverage.erase(ci++);
+ }
+ else
+ {
+ ++ci;
+ }
+ }
+}
+
+bool cmParseCacheCoverage::SplitString(std::vector<std::string>& args,
+ std::string const& line)
+{
+ std::string::size_type pos1 = 0;
+ std::string::size_type pos2 = line.find(',', 0);
+ if(pos2 == std::string::npos)
+ {
+ return false;
+ }
+ std::string arg;
+ while(pos2 != std::string::npos)
+ {
+ arg = line.substr(pos1, pos2-pos1);
+ args.push_back(arg);
+ pos1 = pos2+1;
+ pos2 = line.find(',',pos1);
+ }
+ arg = line.substr(pos1);
+ args.push_back(arg);
+ return true;
+}
+
+bool cmParseCacheCoverage::ReadCMCovFile(const char* file)
+{
+ cmsys::ifstream in(file);
+ if(!in)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Can not open : "
+ << file << "\n");
+ return false;
+ }
+ std::string line;
+ std::vector<std::string> separateLine;
+ if(!cmSystemTools::GetLineFromStream(in, line))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Empty file : "
+ << file << " referenced in this line of cmcov data:\n"
+ "[" << line << "]\n");
+ return false;
+ }
+ separateLine.clear();
+ this->SplitString(separateLine, line);
+ if(separateLine.size() !=4 || separateLine[0] != "Routine"
+ || separateLine[1] != "Line" || separateLine[2] != "RtnLine"
+ || separateLine[3] != "Code")
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Bad first line of cmcov file : "
+ << file << " line:\n"
+ "[" << line << "]\n");
+ }
+ std::string routine;
+ std::string filepath;
+ while(cmSystemTools::GetLineFromStream(in, line))
+ {
+ // clear out line argument vector
+ separateLine.clear();
+ // parse the comma separated line
+ this->SplitString(separateLine, line);
+ // might have more because code could have a quoted , in it
+ // but we only care about the first 3 args anyway
+ if(separateLine.size() < 4)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Bad line of cmcov file expected at least 4 found: "
+ << separateLine.size() << " "
+ << file << " line:\n"
+ "[" << line << "]\n");
+ for(std::string::size_type i = 0; i < separateLine.size(); ++i)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,""
+ << separateLine[1] << " ");
+ }
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "\n");
+ return false;
+ }
+ // if we do not have a routine yet, then it should be
+ // the first argument in the vector
+ if(routine.size() == 0)
+ {
+ routine = separateLine[0];
+ // Find the full path to the file
+ if(!this->FindMumpsFile(routine, filepath))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Could not find mumps file for routine: "
+ << routine << "\n");
+ filepath = "";
+ continue; // move to next line
+ }
+ }
+ // if we have a routine name, check for end of routine
+ else
+ {
+ // Totals in arg 0 marks the end of a routine
+ if(separateLine[0].substr(0, 6) == "Totals")
+ {
+ routine = ""; // at the end of this routine
+ filepath = "";
+ continue; // move to next line
+ }
+ }
+ // if the file path was not found for the routine
+ // move to next line. We should have already warned
+ // after the call to FindMumpsFile that we did not find
+ // it, so don't report again to cut down on output
+ if(filepath.size() == 0)
+ {
+ continue;
+ }
+ // now we are ready to set the coverage from the line of data
+ cmCTestCoverageHandlerContainer::SingleFileCoverageVector&
+ coverageVector = this->Coverage.TotalCoverage[filepath];
+ std::string::size_type linenumber = atoi(separateLine[1].c_str()) -1;
+ int count = atoi(separateLine[2].c_str());
+ if(linenumber > coverageVector.size())
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Parse error line is greater than number of lines in file: "
+ << linenumber << " " << filepath << "\n");
+ continue; // skip setting count to avoid crash
+ }
+ // now add to count for linenumber
+ // for some reason the cache coverage adds extra lines to the
+ // end of the file in some cases. Since they do not exist, we will
+ // mark them as non executable
+ while(linenumber >= coverageVector.size())
+ {
+ coverageVector.push_back(-1);
+ }
+ // Accounts for lines that were previously marked
+ // as non-executable code (-1). if the parser comes back with
+ // a non-zero count, increase the count by 1 to push the line
+ // into the executable code set in addition to the count found.
+ if(coverageVector[linenumber] == -1 &&
+ count > 0)
+ {
+ coverageVector[linenumber] += count+1;
+ }
+ else
+ {
+ coverageVector[linenumber] += count;
+ }
+ }
+ return true;
+}
diff --git a/Source/CTest/cmParseCacheCoverage.h b/Source/CTest/cmParseCacheCoverage.h
new file mode 100644
index 0000000000..114eb92d30
--- /dev/null
+++ b/Source/CTest/cmParseCacheCoverage.h
@@ -0,0 +1,42 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmParseCacheCoverage_h
+#define cmParseCacheCoverage_h
+
+#include "cmParseMumpsCoverage.h"
+
+/** \class cmParseCacheCoverage
+ * \brief Parse Cache coverage information
+ *
+ * This class is used to parse Cache coverage information for
+ * mumps.
+ */
+class cmParseCacheCoverage : public cmParseMumpsCoverage
+{
+public:
+ cmParseCacheCoverage(cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest);
+protected:
+ // implement virtual from parent
+ bool LoadCoverageData(const char* dir);
+ // remove files with no coverage
+ void RemoveUnCoveredFiles();
+ // Read a single mcov file
+ bool ReadCMCovFile(const char* f);
+ // split a string based on ,
+ bool SplitString(std::vector<std::string>& args,
+ std::string const& line);
+};
+
+
+#endif
diff --git a/Source/CTest/cmParseCoberturaCoverage.cxx b/Source/CTest/cmParseCoberturaCoverage.cxx
new file mode 100644
index 0000000000..0742be172b
--- /dev/null
+++ b/Source/CTest/cmParseCoberturaCoverage.cxx
@@ -0,0 +1,169 @@
+#include "cmStandardIncludes.h"
+#include "cmSystemTools.h"
+#include "cmXMLParser.h"
+#include "cmParseCoberturaCoverage.h"
+#include <cmsys/Directory.hxx>
+#include <cmsys/FStream.hxx>
+
+//----------------------------------------------------------------------------
+class cmParseCoberturaCoverage::XMLParser: public cmXMLParser
+{
+public:
+ XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont)
+ : CTest(ctest), Coverage(cont)
+ {
+ this->InSources = false;
+ this->InSource = false;
+ this->FilePaths.push_back(this->Coverage.SourceDir);
+ this->CurFileName = "";
+ }
+
+ virtual ~XMLParser()
+ {
+ }
+
+protected:
+
+
+ virtual void EndElement(const std::string& name)
+ {
+ if(name == "source")
+ {
+ this->InSource=false;
+ }
+ else if (name == "sources")
+ {
+ this->InSources=false;
+ }
+ }
+
+ virtual void CharacterDataHandler(const char* data, int length)
+ {
+ std::string tmp;
+ tmp.insert(0,data,length);
+ if (this->InSources && this->InSource)
+ {
+ this->FilePaths.push_back(tmp);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Adding Source: "
+ << tmp << std::endl);
+ }
+ }
+
+ virtual void StartElement(const std::string& name, const char** atts)
+ {
+ std::string FoundSource;
+ std::string finalpath = "";
+ if(name == "source")
+ {
+ this->InSource = true;
+ }
+ else if(name == "sources")
+ {
+ this->InSources = true;
+ }
+ else if(name == "class")
+ {
+ int tagCount = 0;
+ while(true)
+ {
+ if(strcmp(atts[tagCount], "filename") == 0)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Reading file: "
+ << atts[tagCount+1]<< std::endl);
+ std::string filename = atts[tagCount+1];
+ this->CurFileName = "";
+ for(size_t i=0;i < FilePaths.size();i++)
+ {
+ finalpath = FilePaths[i] + "/" + filename;
+ if(cmSystemTools::FileExists(finalpath.c_str()))
+ {
+ this->CurFileName = finalpath;
+ break;
+ }
+ }
+ cmsys::ifstream fin(this->CurFileName.c_str());
+ if(this->CurFileName == "" || !fin )
+ {
+ this->CurFileName = this->Coverage.BinaryDir + "/" +
+ atts[tagCount+1];
+ fin.open(this->CurFileName.c_str());
+ if (!fin)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Python Coverage: Error opening " << this->CurFileName
+ << std::endl);
+ this->Coverage.Error++;
+ break;
+ }
+ }
+ std::string line;
+ FileLinesType& curFileLines =
+ this->Coverage.TotalCoverage[this->CurFileName];
+ curFileLines.push_back(-1);
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ curFileLines.push_back(-1);
+ }
+
+ break;
+ }
+ ++tagCount;
+ }
+ }
+ else if(name == "line")
+ {
+ int tagCount = 0;
+ int curNumber = -1;
+ int curHits = -1;
+ while(true)
+ {
+ if(strcmp(atts[tagCount], "hits") == 0)
+ {
+ curHits = atoi(atts[tagCount+1]);
+ }
+ else if(strcmp(atts[tagCount], "number") == 0)
+ {
+ curNumber = atoi(atts[tagCount+1]);
+ }
+
+ if(curHits > -1 && curNumber > 0)
+ {
+ FileLinesType& curFileLines =
+ this->Coverage.TotalCoverage[this->CurFileName];
+ {
+ curFileLines[curNumber-1] = curHits;
+ }
+ break;
+ }
+ ++tagCount;
+ }
+ }
+ }
+
+private:
+
+ bool InSources;
+ bool InSource;
+ std::vector<std::string> FilePaths;
+ typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector
+ FileLinesType;
+ cmCTest* CTest;
+ cmCTestCoverageHandlerContainer& Coverage;
+ std::string CurFileName;
+
+};
+
+
+cmParseCoberturaCoverage::cmParseCoberturaCoverage(
+ cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest)
+ :Coverage(cont), CTest(ctest)
+{
+}
+
+bool cmParseCoberturaCoverage::ReadCoverageXML(const char* xmlFile)
+{
+ cmParseCoberturaCoverage::XMLParser parser(this->CTest, this->Coverage);
+ parser.ParseFile(xmlFile);
+ return true;
+}
diff --git a/Source/CTest/cmParseCoberturaCoverage.h b/Source/CTest/cmParseCoberturaCoverage.h
new file mode 100644
index 0000000000..ff5954dd1a
--- /dev/null
+++ b/Source/CTest/cmParseCoberturaCoverage.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmParseCoberturaCoverage_h
+#define cmParseCoberturaCoverage_h
+
+#include "cmStandardIncludes.h"
+#include "cmCTestCoverageHandler.h"
+
+/** \class cmParsePythonCoverage
+ * \brief Parse coverage.py Python coverage information
+ *
+ * This class is used to parse the output of the coverage.py tool that
+ * is currently maintained by Ned Batchelder. That tool has a command
+ * that produces xml output in the format typically output by the common
+ * Java-based Cobertura coverage application. This helper class parses
+ * that XML file to fill the coverage-handler container.
+ */
+class cmParseCoberturaCoverage
+{
+public:
+
+ //! Create the coverage parser by passing in the coverage handler
+ //! container and the cmCTest object
+ cmParseCoberturaCoverage(cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest);
+
+ bool inSources;
+ bool inSource;
+ std::vector<std::string> filepaths;
+ //! Read the XML produced by running `coverage xml`
+ bool ReadCoverageXML(const char* xmlFile);
+
+private:
+
+ class XMLParser;
+ cmCTestCoverageHandlerContainer& Coverage;
+ cmCTest* CTest;
+ std::string CurFileName;
+};
+
+#endif
diff --git a/Source/CTest/cmParseGTMCoverage.cxx b/Source/CTest/cmParseGTMCoverage.cxx
new file mode 100644
index 0000000000..be10c2eaa3
--- /dev/null
+++ b/Source/CTest/cmParseGTMCoverage.cxx
@@ -0,0 +1,289 @@
+#include "cmStandardIncludes.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "cmSystemTools.h"
+#include "cmParseGTMCoverage.h"
+#include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+
+
+cmParseGTMCoverage::cmParseGTMCoverage(cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest)
+ :cmParseMumpsCoverage(cont, ctest)
+{
+}
+
+
+bool cmParseGTMCoverage::LoadCoverageData(const char* d)
+{
+ // load all the .mcov files in the specified directory
+ cmsys::Directory dir;
+ if(!dir.Load(d))
+ {
+ return false;
+ }
+ size_t numf;
+ unsigned int i;
+ numf = dir.GetNumberOfFiles();
+ for (i = 0; i < numf; i++)
+ {
+ std::string file = dir.GetFile(i);
+ if(file != "." && file != ".."
+ && !cmSystemTools::FileIsDirectory(file.c_str()))
+ {
+ std::string path = d;
+ path += "/";
+ path += file;
+ if(cmSystemTools::GetFilenameLastExtension(path) == ".mcov")
+ {
+ if(!this->ReadMCovFile(path.c_str()))
+ {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+
+bool cmParseGTMCoverage::ReadMCovFile(const char* file)
+{
+ cmsys::ifstream in(file);
+ if(!in)
+ {
+ return false;
+ }
+ std::string line;
+ std::string lastfunction;
+ std::string lastroutine;
+ std::string lastpath;
+ int lastoffset = 0;
+ while( cmSystemTools::GetLineFromStream(in, line))
+ {
+ // only look at lines that have coverage data
+ if(line.find("^ZZCOVERAGE") == line.npos)
+ {
+ continue;
+ }
+ std::string filepath;
+ std::string function;
+ std::string routine;
+ int linenumber = 0;
+ int count = 0;
+ this->ParseMCOVLine(line, routine, function, linenumber, count);
+ // skip this one
+ if(routine == "RSEL")
+ {
+ continue;
+ }
+ // no need to search the file if we just did it
+ if(function == lastfunction && lastroutine == routine)
+ {
+ if(lastpath.size())
+ {
+ this->Coverage.TotalCoverage[lastpath][lastoffset + linenumber]
+ += count;
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Can not find mumps file : "
+ << lastroutine <<
+ " referenced in this line of mcov data:\n"
+ "[" << line << "]\n");
+ }
+ continue;
+ }
+ // Find the full path to the file
+ bool found = this->FindMumpsFile(routine, filepath);
+ if(found)
+ {
+ int lineoffset = 0;
+ if(this->FindFunctionInMumpsFile(filepath,
+ function,
+ lineoffset))
+ {
+ cmCTestCoverageHandlerContainer::SingleFileCoverageVector&
+ coverageVector = this->Coverage.TotalCoverage[filepath];
+ // This section accounts for lines that were previously marked
+ // as non-executable code (-1), if the parser comes back with
+ // a non-zero count, increase the count by 1 to push the line
+ // into the executable code set in addtion to the count found.
+ if(coverageVector[lineoffset + linenumber] == -1 &&
+ count > 0)
+ {
+ coverageVector[lineoffset + linenumber] += count+1;
+ }
+ else
+ {
+ coverageVector[lineoffset + linenumber] += count;
+ }
+ lastoffset = lineoffset;
+ }
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Can not find mumps file : "
+ << routine << " referenced in this line of mcov data:\n"
+ "[" << line << "]\n");
+ }
+ lastfunction = function;
+ lastroutine = routine;
+ lastpath = filepath;
+ }
+ return true;
+}
+
+bool cmParseGTMCoverage::FindFunctionInMumpsFile(std::string const& filepath,
+ std::string const& function,
+ int& lineoffset)
+{
+ cmsys::ifstream in(filepath.c_str());
+ if(!in)
+ {
+ return false;
+ }
+ std::string line;
+ int linenum = 0;
+ while( cmSystemTools::GetLineFromStream(in, line))
+ {
+ std::string::size_type pos = line.find(function.c_str());
+ if(pos == 0)
+ {
+ char nextchar = line[function.size()];
+ if(nextchar == ' ' || nextchar == '('|| nextchar == '\t')
+ {
+ lineoffset = linenum;
+ return true;
+ }
+ }
+ if(pos == 1)
+ {
+ char prevchar = line[0];
+ char nextchar = line[function.size()+1];
+ if(prevchar == '%' && (nextchar == ' ' || nextchar == '('))
+ {
+ lineoffset = linenum;
+ return true;
+ }
+ }
+ linenum++; // move to next line count
+ }
+ lineoffset = 0;
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Could not find entry point : "
+ << function << " in " << filepath << "\n");
+ return false;
+}
+
+bool cmParseGTMCoverage::ParseMCOVLine(std::string const& line,
+ std::string& routine,
+ std::string& function,
+ int& linenumber,
+ int& count)
+{
+ // this method parses lines from the .mcov file
+ // each line has ^COVERAGE(...) in it, and there
+ // are several varients of coverage lines:
+ //
+ // ^COVERAGE("DIC11","PR1",0)="2:0:0:0"
+ // ( file , entry, line ) = "number_executed:timing_info"
+ // ^COVERAGE("%RSEL","SRC")="1:0:0:0"
+ // ( file , entry ) = "number_executed:timing_info"
+ // ^COVERAGE("%RSEL","init",8,"FOR_LOOP",1)=1
+ // ( file , entry, line, IGNORE ) =number_executed
+ std::vector<std::string> args;
+ std::string::size_type pos = line.find('(', 0);
+ // if no ( is found, then return line has no coverage
+ if(pos == std::string::npos)
+ {
+ return false;
+ }
+ std::string arg;
+ bool done = false;
+ // separate out all of the comma separated arguments found
+ // in the COVERAGE(...) line
+ while(line[pos] && !done)
+ {
+ // save the char we are looking at
+ char cur = line[pos];
+ // , or ) means end of argument
+ if(cur == ',' || cur == ')')
+ {
+ // save the argument into the argument vector
+ args.push_back(arg);
+ // start on a new argument
+ arg = "";
+ // if we are at the end of the ), then finish while loop
+ if(cur == ')')
+ {
+ done = true;
+ }
+ }
+ else
+ {
+ // all chars except ", (, and % get stored in the arg string
+ if(cur != '\"' && cur != '(' && cur != '%')
+ {
+ arg.append(1, line[pos]);
+ }
+ }
+ // move to next char
+ pos++;
+ }
+ // now parse the right hand side of the =
+ pos = line.find('=');
+ // no = found, this is an error
+ if(pos == line.npos)
+ {
+ return false;
+ }
+ pos++; // move past =
+
+ // if the next positing is not a ", then this is a
+ // COVERAGE(..)=count line and turn the rest of the string
+ // past the = into an integer and set it to count
+ if(line[pos] != '\"')
+ {
+ count = atoi(line.substr(pos).c_str());
+ }
+ else
+ {
+ // this means line[pos] is a ", and we have a
+ // COVERAGE(...)="1:0:0:0" type of line
+ pos++; // move past "
+ // find the first : past the "
+ std::string::size_type pos2 = line.find(':', pos);
+ // turn the string between the " and the first : into an integer
+ // and set it to count
+ count = atoi(line.substr(pos, pos2-pos).c_str());
+ }
+ // less then two arguments is an error
+ if(args.size() < 2)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error parsing mcov line: [" << line << "]\n");
+ return false;
+ }
+ routine = args[0]; // the routine is the first argument
+ function = args[1]; // the function in the routine is the second
+ // in the two argument only format
+ // ^COVERAGE("%RSEL","SRC"), the line offset is 0
+ if(args.size() == 2)
+ {
+ // To avoid double counting of line 0 of each entry point,
+ // Don't count the lines that do not give an explicit line
+ // number.
+ routine="";
+ function="";
+ }
+ else
+ {
+ // this is the format for this line
+ // ^COVERAGE("%RSEL","SRC",count)
+ linenumber = atoi(args[2].c_str());
+ }
+ return true;
+}
diff --git a/Source/CTest/cmParseGTMCoverage.h b/Source/CTest/cmParseGTMCoverage.h
new file mode 100644
index 0000000000..c6d7ef919e
--- /dev/null
+++ b/Source/CTest/cmParseGTMCoverage.h
@@ -0,0 +1,49 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmParseGTMCoverage_h
+#define cmParseGTMCoverage_h
+
+#include "cmParseMumpsCoverage.h"
+
+/** \class cmParseGTMCoverage
+ * \brief Parse GTM coverage information
+ *
+ * This class is used to parse GTM coverage information for
+ * mumps.
+ */
+class cmParseGTMCoverage : public cmParseMumpsCoverage
+{
+public:
+ cmParseGTMCoverage(cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest);
+protected:
+ // implement virtual from parent
+ bool LoadCoverageData(const char* dir);
+ // Read a single mcov file
+ bool ReadMCovFile(const char* f);
+ // find out what line in a mumps file (filepath) the given entry point
+ // or function is. lineoffset is set by this method.
+ bool FindFunctionInMumpsFile(std::string const& filepath,
+ std::string const& function,
+ int& lineoffset);
+ // parse a line from a .mcov file, and fill in the
+ // routine, function, linenumber and coverage count
+ bool ParseMCOVLine(std::string const& line,
+ std::string& routine,
+ std::string& function,
+ int& linenumber,
+ int& count);
+};
+
+
+#endif
diff --git a/Source/CTest/cmParseJacocoCoverage.cxx b/Source/CTest/cmParseJacocoCoverage.cxx
new file mode 100644
index 0000000000..f270adbbea
--- /dev/null
+++ b/Source/CTest/cmParseJacocoCoverage.cxx
@@ -0,0 +1,170 @@
+#include "cmStandardIncludes.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "cmSystemTools.h"
+#include "cmXMLParser.h"
+#include "cmParseJacocoCoverage.h"
+#include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+
+
+class cmParseJacocoCoverage::XMLParser: public cmXMLParser
+{
+ public:
+ XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont)
+ : CTest(ctest), Coverage(cont)
+ {
+ this->PackageName = "";
+ this->ModuleName = "";
+ this->FileName = "";
+ this->CurFileName = "";
+ this->FilePaths.push_back(this->Coverage.SourceDir);
+ }
+
+ virtual ~XMLParser()
+ {
+ }
+
+ protected:
+
+ virtual void EndElement(const std::string&)
+ {
+ }
+
+ virtual void StartElement(const std::string& name,
+ const char** atts)
+ {
+ if(name == "package")
+ {
+ this->PackageName = atts[1];
+ std::string FilePath = this->Coverage.SourceDir +
+ "/" + this->ModuleName + "/src/main/java/" +
+ this->PackageName;
+ this->FilePaths.push_back(FilePath);
+ FilePath = this->Coverage.SourceDir +
+ "/src/main/java/" + this->PackageName;
+ this->FilePaths.push_back(FilePath);
+ }
+ else if(name == "sourcefile")
+ {
+ this->FileName = atts[1];
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Reading file: "
+ << this->FileName << std::endl);
+ for(size_t i=0;i < FilePaths.size();i++)
+ {
+ std::string finalpath = FilePaths[i] + "/" + this->FileName;
+ if(cmSystemTools::FileExists(finalpath.c_str()))
+ {
+ this->CurFileName = finalpath;
+ break;
+ }
+ }
+ cmsys::ifstream fin(this->CurFileName.c_str());
+ if(this->CurFileName == "" || !fin )
+ {
+ this->CurFileName = this->Coverage.BinaryDir + "/" +
+ this->FileName;
+ fin.open(this->CurFileName.c_str());
+ if (!fin)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Jacoco Coverage: Error opening " << this->CurFileName
+ << std::endl);
+ this->Coverage.Error++;
+ }
+ }
+ std::string line;
+ FileLinesType& curFileLines =
+ this->Coverage.TotalCoverage[this->CurFileName];
+ curFileLines.push_back(-1);
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ curFileLines.push_back(-1);
+ }
+ }
+ else if(name == "report")
+ {
+ this->ModuleName=atts[1];
+ }
+ else if(name == "line")
+ {
+ int tagCount = 0;
+ int nr = -1;
+ int ci = -1;
+ while(true)
+ {
+ if(strcmp(atts[tagCount],"ci") == 0)
+ {
+ ci = atoi(atts[tagCount+1]);
+ }
+ else if (strcmp(atts[tagCount],"nr") == 0)
+ {
+ nr = atoi(atts[tagCount+1]);
+ }
+ if (ci > -1 && nr > 0)
+ {
+ FileLinesType& curFileLines=
+ this->Coverage.TotalCoverage[this->CurFileName];
+ if(curFileLines.size() > 0)
+ {
+ curFileLines[nr-1] = ci;
+ }
+ break;
+ }
+ ++tagCount;
+ }
+ }
+ }
+
+ private:
+ std::string PackageName;
+ std::string FileName;
+ std::string ModuleName;
+ std::string CurFileName;
+ std::vector<std::string> FilePaths;
+ typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector
+ FileLinesType;
+ cmCTest* CTest;
+ cmCTestCoverageHandlerContainer& Coverage;
+};
+
+cmParseJacocoCoverage::cmParseJacocoCoverage(
+ cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest)
+ :Coverage(cont), CTest(ctest)
+ {
+ }
+
+bool cmParseJacocoCoverage::LoadCoverageData(
+ const std::vector<std::string> files)
+{
+ // load all the jacoco.xml files in the source directory
+ cmsys::Directory dir;
+ size_t i;
+ std::string path;
+ size_t numf = files.size();
+ for (i = 0; i < numf; i++)
+ {
+ path = files[i];
+
+ cmCTestLog(this->CTest,HANDLER_VERBOSE_OUTPUT,
+ "Reading XML File " << path << std::endl);
+ if(cmSystemTools::GetFilenameLastExtension(path) == ".xml")
+ {
+ if(!this->ReadJacocoXML(path.c_str()))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool cmParseJacocoCoverage::ReadJacocoXML(const char* file)
+{
+ cmParseJacocoCoverage::XMLParser
+ parser(this->CTest, this->Coverage);
+ parser.ParseFile(file);
+ return true;
+}
diff --git a/Source/CTest/cmParseJacocoCoverage.h b/Source/CTest/cmParseJacocoCoverage.h
new file mode 100644
index 0000000000..dad05a32e4
--- /dev/null
+++ b/Source/CTest/cmParseJacocoCoverage.h
@@ -0,0 +1,59 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmParseJacocoCoverage_h
+#define cmParseJacocoCoverage_h
+
+#include "cmStandardIncludes.h"
+#include "cmCTestCoverageHandler.h"
+
+
+/** \class cmParseJacocoCoverage
+ * \brief Parse JaCoCO coverage information
+ *
+ * This class is used to parse coverage information for
+ * java using the JaCoCo tool:
+ *
+ * http://www.eclemma.org/jacoco/trunk/index.html
+ */
+class cmParseJacocoCoverage
+{
+public:
+ cmParseJacocoCoverage(cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest);
+ bool LoadCoverageData(const std::vector<std::string> files);
+
+ std::string PackageName;
+ std::string FileName;
+ std::string ModuleName;
+ std::string CurFileName;
+private:
+ // implement virtual from parent
+ // remove files with no coverage
+ void RemoveUnCoveredFiles();
+ // Read a single mcov file
+ bool ReadJacocoXML(const char* f);
+ // split a string based on ,
+ bool SplitString(std::vector<std::string>& args,
+ std::string const& line);
+ bool FindJavaFile(std::string const& routine,
+ std::string& filepath);
+ void InitializeJavaFile(std::string& file);
+ bool LoadSource(std::string d);
+
+ class XMLParser;
+ std::map<std::string, std::string> RoutineToDirectory;
+ cmCTestCoverageHandlerContainer& Coverage;
+ cmCTest* CTest;
+};
+
+#endif
diff --git a/Source/CTest/cmParseMumpsCoverage.cxx b/Source/CTest/cmParseMumpsCoverage.cxx
new file mode 100644
index 0000000000..225e704d90
--- /dev/null
+++ b/Source/CTest/cmParseMumpsCoverage.cxx
@@ -0,0 +1,168 @@
+#include "cmStandardIncludes.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "cmSystemTools.h"
+#include "cmParseGTMCoverage.h"
+#include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+
+
+cmParseMumpsCoverage::cmParseMumpsCoverage(
+ cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest)
+ :Coverage(cont), CTest(ctest)
+{
+}
+
+cmParseMumpsCoverage::~cmParseMumpsCoverage()
+{
+}
+
+bool cmParseMumpsCoverage::ReadCoverageFile(const char* file)
+{
+ // Read the gtm_coverage.mcov file, that has two lines of data:
+ // packages:/full/path/to/Vista/Packages
+ // coverage_dir:/full/path/to/dir/with/*.mcov
+ cmsys::ifstream in(file);
+ if(!in)
+ {
+ return false;
+ }
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(in, line))
+ {
+ std::string::size_type pos = line.find(':', 0);
+ std::string packages;
+ if(pos != std::string::npos)
+ {
+ std::string type = line.substr(0, pos);
+ std::string path = line.substr(pos+1);
+ if(type == "packages")
+ {
+ this->LoadPackages(path.c_str());
+ }
+ else if(type == "coverage_dir")
+ {
+ this->LoadCoverageData(path.c_str());
+ }
+ else
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Parse Error in Mumps coverage file :\n"
+ << file <<
+ "\ntype: [" << type << "]\npath:[" << path << "]\n"
+ "input line: [" << line << "]\n");
+ }
+ }
+ }
+ return true;
+}
+
+void cmParseMumpsCoverage::InitializeMumpsFile(std::string& file)
+{
+ // initialize the coverage information for a given mumps file
+ cmsys::ifstream in(file.c_str());
+ if(!in)
+ {
+ return;
+ }
+ std::string line;
+ cmCTestCoverageHandlerContainer::SingleFileCoverageVector&
+ coverageVector = this->Coverage.TotalCoverage[file];
+ if(!cmSystemTools::GetLineFromStream(in, line))
+ {
+ return;
+ }
+ // first line of a .m file can never be run
+ coverageVector.push_back(-1);
+ while( cmSystemTools::GetLineFromStream(in, line) )
+ {
+ // putting in a 0 for a line means it is executable code
+ // putting in a -1 for a line means it is not executable code
+ int val = -1; // assume line is not executable
+ bool found = false;
+ std::string::size_type i = 0;
+ // (1) Search for the first whitespace or semicolon character on a line.
+ //This will skip over labels if the line starts with one, or will simply
+ //be the first character on the line for non-label lines.
+ for(; i < line.size(); ++i)
+ {
+ if(line[i] == ' ' || line[i] == '\t' || line[i] == ';')
+ {
+ found = true;
+ break;
+ }
+ }
+ if(found)
+ {
+ // (2) If the first character found above is whitespace or a period
+ // then continue the search for the first following non-whitespace
+ // character.
+ if(line[i] == ' ' || line[i] == '\t')
+ {
+ while(i < line.size() && (line[i] == ' ' || line[i] == '\t'
+ || line[i] == '.'))
+ {
+ i++;
+ }
+ }
+ // (3) If the character found is not a semicolon then the line counts for
+ // coverage.
+ if(i < line.size() && line[i] != ';')
+ {
+ val = 0;
+ }
+ }
+ coverageVector.push_back(val);
+ }
+}
+
+bool cmParseMumpsCoverage::LoadPackages(const char* d)
+{
+ cmsys::Glob glob;
+ glob.RecurseOn();
+ std::string pat = d;
+ pat += "/*.m";
+ glob.FindFiles(pat);
+ std::vector<std::string>& files = glob.GetFiles();
+ std::vector<std::string>::iterator fileIt;
+ for ( fileIt = files.begin(); fileIt != files.end();
+ ++ fileIt )
+ {
+ std::string name = cmSystemTools::GetFilenameName(*fileIt);
+ this->RoutineToDirectory[name.substr(0, name.size()-2)] = *fileIt;
+ // initialze each file, this is left out until CDash is fixed
+ // to handle large numbers of files
+ this->InitializeMumpsFile(*fileIt);
+ }
+ return true;
+}
+
+bool cmParseMumpsCoverage::FindMumpsFile(std::string const& routine,
+ std::string& filepath)
+{
+ std::map<std::string, std::string>::iterator i =
+ this->RoutineToDirectory.find(routine);
+ if(i != this->RoutineToDirectory.end())
+ {
+ filepath = i->second;
+ return true;
+ }
+ else
+ {
+ // try some alternate names
+ const char* tryname[] = {"GUX", "GTM", "ONT", 0};
+ for(int k=0; tryname[k] != 0; k++)
+ {
+ std::string routine2 = routine + tryname[k];
+ i = this->RoutineToDirectory.find(routine2);
+ if(i != this->RoutineToDirectory.end())
+ {
+ filepath = i->second;
+ return true;
+ }
+ }
+ }
+ return false;
+}
diff --git a/Source/CTest/cmParseMumpsCoverage.h b/Source/CTest/cmParseMumpsCoverage.h
new file mode 100644
index 0000000000..bc71891688
--- /dev/null
+++ b/Source/CTest/cmParseMumpsCoverage.h
@@ -0,0 +1,52 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmParseMumpsCoverage_h
+#define cmParseMumpsCoverage_h
+
+#include "cmStandardIncludes.h"
+#include "cmCTestCoverageHandler.h"
+
+/** \class cmParseMumpsCoverage
+ * \brief Parse Mumps coverage information
+ *
+ * This class is used as the base class for Mumps coverage
+ * parsing.
+ */
+class cmParseMumpsCoverage
+{
+public:
+ cmParseMumpsCoverage(cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest);
+ virtual ~cmParseMumpsCoverage();
+ // This is the toplevel coverage file locating the coverage files
+ // and the mumps source code package tree.
+ bool ReadCoverageFile(const char* file);
+protected:
+ // sub classes will use this to
+ // load all coverage files found in the given directory
+ virtual bool LoadCoverageData(const char* d) = 0;
+ // search the package directory for mumps files and fill
+ // in the RoutineToDirectory map
+ bool LoadPackages(const char* dir);
+ // initialize the coverage information for a single mumps file
+ void InitializeMumpsFile(std::string& file);
+ // Find mumps file for routine
+ bool FindMumpsFile(std::string const& routine,
+ std::string& filepath);
+protected:
+ std::map<std::string, std::string> RoutineToDirectory;
+ cmCTestCoverageHandlerContainer& Coverage;
+ cmCTest* CTest;
+};
+
+#endif
diff --git a/Source/CTest/cmParsePHPCoverage.cxx b/Source/CTest/cmParsePHPCoverage.cxx
new file mode 100644
index 0000000000..3b7f968f68
--- /dev/null
+++ b/Source/CTest/cmParsePHPCoverage.cxx
@@ -0,0 +1,254 @@
+#include "cmStandardIncludes.h"
+#include "cmSystemTools.h"
+#include "cmParsePHPCoverage.h"
+#include <cmsys/Directory.hxx>
+#include <cmsys/FStream.hxx>
+
+/*
+ To setup coverage for php.
+
+ - edit php.ini to add auto prepend and append php files from phpunit
+ auto_prepend_file =
+ auto_append_file =
+ - run the tests
+ - run this program on all the files in c:/tmp
+
+*/
+
+cmParsePHPCoverage::cmParsePHPCoverage(cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest)
+ :Coverage(cont), CTest(ctest)
+{
+}
+
+bool cmParsePHPCoverage::ReadUntil(std::istream& in, char until)
+{
+ char c = 0;
+ while(in.get(c) && c != until)
+ {
+ }
+ if(c != until)
+ {
+ return false;
+ }
+ return true;
+}
+bool cmParsePHPCoverage::ReadCoverageArray(std::istream& in,
+ std::string const& fileName)
+{
+ cmCTestCoverageHandlerContainer::SingleFileCoverageVector& coverageVector
+ = this->Coverage.TotalCoverage[fileName];
+
+ char c;
+ char buf[4];
+ in.read(buf, 3);
+ buf[3] = 0;
+ if(strcmp(buf, ";a:") != 0)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "failed to read start of coverage array, found : "
+ << buf << "\n");
+ return false;
+ }
+ int size = 0;
+ if(!this->ReadInt(in, size))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "failed to read size ");
+ return false;
+ }
+ if(!in.get(c) && c == '{')
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "failed to read open {\n");
+ return false;
+ }
+ for(int i =0; i < size; i++)
+ {
+ this->ReadUntil(in, ':');
+ int line = 0;
+ this->ReadInt(in, line);
+ // ok xdebug may have a bug here
+ // it seems to be 1 based but often times
+ // seems to have a 0'th line.
+ line--;
+ if(line < 0)
+ {
+ line = 0;
+ }
+ this->ReadUntil(in, ':');
+ int value = 0;
+ this->ReadInt(in, value);
+ // make sure the vector is the right size and is
+ // initialized with -1 for each line
+ while(coverageVector.size() <= static_cast<size_t>(line) )
+ {
+ coverageVector.push_back(-1);
+ }
+ // if value is less than 0, set it to zero
+ // TODO figure out the difference between
+ // -1 and -2 in xdebug coverage?? For now
+ // assume less than 0 is just not covered
+ // CDash expects -1 for non executable code (like comments)
+ // and 0 for uncovered code, and a positive value
+ // for number of times a line was executed
+ if(value < 0)
+ {
+ value = 0;
+ }
+ // if unset then set it to value
+ if(coverageVector[line] == -1)
+ {
+ coverageVector[line] = value;
+ }
+ // otherwise increment by value
+ else
+ {
+ coverageVector[line] += value;
+ }
+ }
+ return true;
+}
+
+bool cmParsePHPCoverage::ReadInt(std::istream& in, int& v)
+{
+ std::string s;
+ char c = 0;
+ while(in.get(c) && c != ':' && c != ';')
+ {
+ s += c;
+ }
+ v = atoi(s.c_str());
+ return true;
+}
+
+bool cmParsePHPCoverage::ReadArraySize(std::istream& in, int& size)
+{
+ char c = 0;
+ in.get(c);
+ if(c != 'a')
+ {
+ return false;
+ }
+ if(in.get(c) && c == ':')
+ {
+ if(this->ReadInt(in, size))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool cmParsePHPCoverage::ReadFileInformation(std::istream& in)
+{
+ char buf[4];
+ in.read(buf, 2);
+ buf[2] = 0;
+ if(strcmp(buf, "s:") != 0)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "failed to read start of file info found: [" << buf << "]\n");
+ return false;
+ }
+ char c;
+ int size = 0;
+ if(this->ReadInt(in, size))
+ {
+ size++; // add one for null termination
+ char* s = new char[size+1];
+ // read open quote
+ if(in.get(c) && c != '"')
+ {
+ delete[] s;
+ return false;
+ }
+ // read the string data
+ in.read(s, size-1);
+ s[size-1] = 0;
+ std::string fileName = s;
+ delete [] s;
+ // read close quote
+ if(in.get(c) && c != '"')
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "failed to read close quote\n"
+ << "read [" << c << "]\n");
+ return false;
+ }
+ if(!this->ReadCoverageArray(in, fileName) )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "failed to read coverage array for file: "
+ << fileName << "\n");
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
+
+bool cmParsePHPCoverage::ReadPHPData(const char* file)
+{
+ cmsys::ifstream in(file);
+ if(!in)
+ {
+ return false;
+ }
+ int size = 0;
+ this->ReadArraySize(in, size);
+ char c = 0;
+ in.get(c);
+ if(c != '{')
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "failed to read open array\n");
+ return false;
+ }
+ for(int i =0; i < size; i++)
+ {
+ if(!this->ReadFileInformation(in))
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Failed to read file #" << i << "\n");
+ return false;
+ }
+ in.get(c);
+ if(c != '}')
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "failed to read close array\n");
+ return false;
+ }
+ }
+ return true;
+}
+
+bool cmParsePHPCoverage::ReadPHPCoverageDirectory(const char* d)
+{
+ cmsys::Directory dir;
+ if(!dir.Load(d))
+ {
+ return false;
+ }
+ size_t numf;
+ unsigned int i;
+ numf = dir.GetNumberOfFiles();
+ for (i = 0; i < numf; i++)
+ {
+ std::string file = dir.GetFile(i);
+ if(file != "." && file != ".."
+ && !cmSystemTools::FileIsDirectory(file.c_str()))
+ {
+ std::string path = d;
+ path += "/";
+ path += file;
+ if(!this->ReadPHPData(path.c_str()))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+}
diff --git a/Source/CTest/cmParsePHPCoverage.h b/Source/CTest/cmParsePHPCoverage.h
new file mode 100644
index 0000000000..92a76347f1
--- /dev/null
+++ b/Source/CTest/cmParsePHPCoverage.h
@@ -0,0 +1,45 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 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 cmParsePHPCoverage_h
+#define cmParsePHPCoverage_h
+
+#include "cmStandardIncludes.h"
+#include "cmCTestCoverageHandler.h"
+
+/** \class cmParsePHPCoverage
+ * \brief Parse xdebug PHP coverage information
+ *
+ * This class is used to parse php coverage information produced
+ * by xdebug. The data is stored as a php dump of the array
+ * return by xdebug coverage. It is an array of arrays.
+ */
+class cmParsePHPCoverage
+{
+public:
+ cmParsePHPCoverage(cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest);
+ bool ReadPHPCoverageDirectory(const char* dir);
+ void PrintCoverage();
+private:
+ bool ReadPHPData(const char* file);
+ bool ReadArraySize(std::istream& in, int& size);
+ bool ReadFileInformation(std::istream& in);
+ bool ReadInt(std::istream& in, int& v);
+ bool ReadCoverageArray(std::istream& in, std::string const&);
+ bool ReadUntil(std::istream& in, char until);
+ cmCTestCoverageHandlerContainer& Coverage;
+ cmCTest* CTest;
+};
+
+
+#endif
diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx
new file mode 100644
index 0000000000..167b992c9b
--- /dev/null
+++ b/Source/CTest/cmProcess.cxx
@@ -0,0 +1,280 @@
+/*============================================================================
+ 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 <cmProcess.h>
+#include <cmSystemTools.h>
+
+cmProcess::cmProcess()
+{
+ this->Process = 0;
+ this->Timeout = 0;
+ this->TotalTime = 0;
+ this->ExitValue = 0;
+ this->Id = 0;
+ this->StartTime = 0;
+}
+
+cmProcess::~cmProcess()
+{
+ cmsysProcess_Delete(this->Process);
+}
+void cmProcess::SetCommand(const char* command)
+{
+ this->Command = command;
+}
+
+void cmProcess::SetCommandArguments(std::vector<std::string> const& args)
+{
+ this->Arguments = args;
+}
+
+bool cmProcess::StartProcess()
+{
+ if(this->Command.size() == 0)
+ {
+ return false;
+ }
+ this->StartTime = cmSystemTools::GetTime();
+ this->ProcessArgs.clear();
+ // put the command as arg0
+ this->ProcessArgs.push_back(this->Command.c_str());
+ // now put the command arguments in
+ for(std::vector<std::string>::iterator i = this->Arguments.begin();
+ i != this->Arguments.end(); ++i)
+ {
+ this->ProcessArgs.push_back(i->c_str());
+ }
+ this->ProcessArgs.push_back(0); // null terminate the list
+ this->Process = cmsysProcess_New();
+ cmsysProcess_SetCommand(this->Process, &*this->ProcessArgs.begin());
+ if(this->WorkingDirectory.size())
+ {
+ cmsysProcess_SetWorkingDirectory(this->Process,
+ this->WorkingDirectory.c_str());
+ }
+ cmsysProcess_SetTimeout(this->Process, this->Timeout);
+ cmsysProcess_Execute(this->Process);
+ return (cmsysProcess_GetState(this->Process)
+ == cmsysProcess_State_Executing);
+}
+
+//----------------------------------------------------------------------------
+bool cmProcess::Buffer::GetLine(std::string& line)
+{
+ // Scan for the next newline.
+ for(size_type sz = this->size(); this->Last != sz; ++this->Last)
+ {
+ if((*this)[this->Last] == '\n' || (*this)[this->Last] == '\0')
+ {
+ // Extract the range first..last as a line.
+ const char* text = &*this->begin() + this->First;
+ size_type length = this->Last - this->First;
+ while(length && text[length-1] == '\r')
+ {
+ length --;
+ }
+ line.assign(text, length);
+
+ // Start a new range for the next line.
+ ++this->Last;
+ this->First = Last;
+
+ // Return the line extracted.
+ return true;
+ }
+ }
+
+ // Available data have been exhausted without a newline.
+ if(this->First != 0)
+ {
+ // Move the partial line to the beginning of the buffer.
+ this->erase(this->begin(), this->begin() + this->First);
+ this->First = 0;
+ this->Last = this->size();
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmProcess::Buffer::GetLast(std::string& line)
+{
+ // Return the partial last line, if any.
+ if(!this->empty())
+ {
+ line.assign(&*this->begin(), this->size());
+ this->First = this->Last = 0;
+ this->clear();
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+int cmProcess::GetNextOutputLine(std::string& line, double timeout)
+{
+ for(;;)
+ {
+ // Look for lines already buffered.
+ if(this->StdOut.GetLine(line))
+ {
+ return cmsysProcess_Pipe_STDOUT;
+ }
+ else if(this->StdErr.GetLine(line))
+ {
+ return cmsysProcess_Pipe_STDERR;
+ }
+
+ // Check for more data from the process.
+ char* data;
+ int length;
+ int p = cmsysProcess_WaitForData(this->Process, &data, &length, &timeout);
+ if(p == cmsysProcess_Pipe_Timeout)
+ {
+ return cmsysProcess_Pipe_Timeout;
+ }
+ else if(p == cmsysProcess_Pipe_STDOUT)
+ {
+ this->StdOut.insert(this->StdOut.end(), data, data+length);
+ }
+ else if(p == cmsysProcess_Pipe_STDERR)
+ {
+ this->StdErr.insert(this->StdErr.end(), data, data+length);
+ }
+ else // p == cmsysProcess_Pipe_None
+ {
+ // The process will provide no more data.
+ break;
+ }
+ }
+
+ // Look for partial last lines.
+ if(this->StdOut.GetLast(line))
+ {
+ return cmsysProcess_Pipe_STDOUT;
+ }
+ else if(this->StdErr.GetLast(line))
+ {
+ return cmsysProcess_Pipe_STDERR;
+ }
+
+ // No more data. Wait for process exit.
+ if(!cmsysProcess_WaitForExit(this->Process, &timeout))
+ {
+ return cmsysProcess_Pipe_Timeout;
+ }
+
+ // Record exit information.
+ this->ExitValue = cmsysProcess_GetExitValue(this->Process);
+ this->TotalTime = cmSystemTools::GetTime() - this->StartTime;
+ // Because of a processor clock scew the runtime may become slightly
+ // negative. If someone changed the system clock while the process was
+ // running this may be even more. Make sure not to report a negative
+ // duration here.
+ if (this->TotalTime <= 0.0)
+ {
+ this->TotalTime = 0.0;
+ }
+ // std::cerr << "Time to run: " << this->TotalTime << "\n";
+ return cmsysProcess_Pipe_None;
+}
+
+// return the process status
+int cmProcess::GetProcessStatus()
+{
+ if(!this->Process)
+ {
+ return cmsysProcess_State_Exited;
+ }
+ return cmsysProcess_GetState(this->Process);
+}
+
+int cmProcess::ReportStatus()
+{
+ int result = 1;
+ switch(cmsysProcess_GetState(this->Process))
+ {
+ case cmsysProcess_State_Starting:
+ {
+ std::cerr << "cmProcess: Never started "
+ << this->Command << " process.\n";
+ } break;
+ case cmsysProcess_State_Error:
+ {
+ std::cerr << "cmProcess: Error executing " << this->Command
+ << " process: "
+ << cmsysProcess_GetErrorString(this->Process)
+ << "\n";
+ } break;
+ case cmsysProcess_State_Exception:
+ {
+ std::cerr << "cmProcess: " << this->Command
+ << " process exited with an exception: ";
+ switch(cmsysProcess_GetExitException(this->Process))
+ {
+ case cmsysProcess_Exception_None:
+ {
+ std::cerr << "None";
+ } break;
+ case cmsysProcess_Exception_Fault:
+ {
+ std::cerr << "Segmentation fault";
+ } break;
+ case cmsysProcess_Exception_Illegal:
+ {
+ std::cerr << "Illegal instruction";
+ } break;
+ case cmsysProcess_Exception_Interrupt:
+ {
+ std::cerr << "Interrupted by user";
+ } break;
+ case cmsysProcess_Exception_Numerical:
+ {
+ std::cerr << "Numerical exception";
+ } break;
+ case cmsysProcess_Exception_Other:
+ {
+ std::cerr << "Unknown";
+ } break;
+ }
+ std::cerr << "\n";
+ } break;
+ case cmsysProcess_State_Executing:
+ {
+ std::cerr << "cmProcess: Never terminated " <<
+ this->Command << " process.\n";
+ } break;
+ case cmsysProcess_State_Exited:
+ {
+ result = cmsysProcess_GetExitValue(this->Process);
+ std::cerr << "cmProcess: " << this->Command
+ << " process exited with code "
+ << result << "\n";
+ } break;
+ case cmsysProcess_State_Expired:
+ {
+ std::cerr << "cmProcess: killed " << this->Command
+ << " process due to timeout.\n";
+ } break;
+ case cmsysProcess_State_Killed:
+ {
+ std::cerr << "cmProcess: killed " << this->Command << " process.\n";
+ } break;
+ }
+ return result;
+
+}
+
+
+int cmProcess::GetExitException()
+{
+ return cmsysProcess_GetExitException(this->Process);
+}
diff --git a/Source/CTest/cmProcess.h b/Source/CTest/cmProcess.h
new file mode 100644
index 0000000000..1479df05f9
--- /dev/null
+++ b/Source/CTest/cmProcess.h
@@ -0,0 +1,82 @@
+/*============================================================================
+ 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 cmProcess_h
+#define cmProcess_h
+
+
+#include "cmStandardIncludes.h"
+#include <cmsys/Process.h>
+
+
+/** \class cmProcess
+ * \brief run a process with c++
+ *
+ * cmProcess wraps the kwsys process stuff in a c++ class.
+ */
+class cmProcess
+{
+public:
+ cmProcess();
+ ~cmProcess();
+ const char* GetCommand() { return this->Command.c_str();}
+ void SetCommand(const char* command);
+ void SetCommandArguments(std::vector<std::string> const& arg);
+ void SetWorkingDirectory(const char* dir) { this->WorkingDirectory = dir;}
+ void SetTimeout(double t) { this->Timeout = t;}
+ // Return true if the process starts
+ bool StartProcess();
+
+ // return the process status
+ int GetProcessStatus();
+ // Report the status of the program
+ int ReportStatus();
+ int GetId() { return this->Id; }
+ void SetId(int id) { this->Id = id;}
+ int GetExitValue() { return this->ExitValue;}
+ double GetTotalTime() { return this->TotalTime;}
+ int GetExitException();
+ /**
+ * Read one line of output but block for no more than timeout.
+ * Returns:
+ * cmsysProcess_Pipe_None = Process terminated and all output read
+ * cmsysProcess_Pipe_STDOUT = Line came from stdout
+ * cmsysProcess_Pipe_STDOUT = Line came from stderr
+ * cmsysProcess_Pipe_Timeout = Timeout expired while waiting
+ */
+ int GetNextOutputLine(std::string& line, double timeout);
+private:
+ double Timeout;
+ double StartTime;
+ double TotalTime;
+ cmsysProcess* Process;
+ class Buffer: public std::vector<char>
+ {
+ // Half-open index range of partial line already scanned.
+ size_type First;
+ size_type Last;
+ public:
+ Buffer(): First(0), Last(0) {}
+ bool GetLine(std::string& line);
+ bool GetLast(std::string& line);
+ };
+ Buffer StdErr;
+ Buffer StdOut;
+ std::string Command;
+ std::string WorkingDirectory;
+ std::vector<std::string> Arguments;
+ std::vector<const char*> ProcessArgs;
+ std::string Output;
+ int Id;
+ int ExitValue;
+};
+
+#endif
diff --git a/Source/CursesDialog/.NoDartCoverage b/Source/CursesDialog/.NoDartCoverage
new file mode 100644
index 0000000000..3c99729386
--- /dev/null
+++ b/Source/CursesDialog/.NoDartCoverage
@@ -0,0 +1 @@
+# do not do coverage in this directory
diff --git a/Source/CursesDialog/CMakeLists.txt b/Source/CursesDialog/CMakeLists.txt
new file mode 100644
index 0000000000..548f5a5fe6
--- /dev/null
+++ b/Source/CursesDialog/CMakeLists.txt
@@ -0,0 +1,38 @@
+#=============================================================================
+# 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.
+#=============================================================================
+
+set( CURSES_SRCS
+ CursesDialog/cmCursesOptionsWidget
+ CursesDialog/cmCursesBoolWidget
+ CursesDialog/cmCursesCacheEntryComposite
+ CursesDialog/cmCursesDummyWidget
+ CursesDialog/cmCursesFilePathWidget
+ CursesDialog/cmCursesForm
+ CursesDialog/cmCursesLabelWidget
+ CursesDialog/cmCursesLongMessageForm
+ CursesDialog/cmCursesMainForm
+ CursesDialog/cmCursesPathWidget
+ CursesDialog/cmCursesStringWidget
+ CursesDialog/cmCursesWidget
+ CursesDialog/ccmake
+ )
+
+include_directories(${CMake_SOURCE_DIR}/Source/CursesDialog/form
+ ${CMake_BINARY_DIR}/Source/CursesDialog/form)
+include_directories(${CURSES_INCLUDE_PATH})
+
+
+add_executable(ccmake ${CURSES_SRCS} )
+target_link_libraries(ccmake CMakeLib)
+target_link_libraries(ccmake cmForm)
+
+install(TARGETS ccmake DESTINATION bin)
diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx
new file mode 100644
index 0000000000..28f3d9b787
--- /dev/null
+++ b/Source/CursesDialog/ccmake.cxx
@@ -0,0 +1,216 @@
+/*============================================================================
+ 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 "../cmCacheManager.h"
+#include "../cmSystemTools.h"
+#include "../cmake.h"
+#include "../cmDocumentation.h"
+
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <locale.h>
+
+#include "cmCursesMainForm.h"
+#include "cmCursesStandardIncludes.h"
+#include <cmsys/Encoding.hxx>
+
+#include <form.h>
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationName[][2] =
+{
+ {0,
+ " ccmake - Curses Interface for CMake."},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationUsage[][2] =
+{
+ {0,
+ " ccmake <path-to-source>\n"
+ " ccmake <path-to-existing-build>"},
+ {0,
+ "Specify a source directory to (re-)generate a build system for "
+ "it in the current working directory. Specify an existing build "
+ "directory to re-generate its build system."},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationUsageNote[][2] =
+{
+ {0,
+ "Run 'ccmake --help' for more information."},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationOptions[][2] =
+{
+ CMAKE_STANDARD_OPTIONS_TABLE,
+ {0,0}
+};
+
+cmCursesForm* cmCursesForm::CurrentForm=0;
+
+extern "C"
+{
+
+void onsig(int)
+{
+ if (cmCursesForm::CurrentForm)
+ {
+ endwin();
+ initscr(); /* Initialization */
+ noecho(); /* Echo off */
+ cbreak(); /* nl- or cr not needed */
+ keypad(stdscr,TRUE); /* Use key symbols as
+ KEY_DOWN*/
+ refresh();
+ int x,y;
+ getmaxyx(stdscr, y, x);
+ cmCursesForm::CurrentForm->Render(1,1,x,y);
+ cmCursesForm::CurrentForm->UpdateStatusBar();
+ }
+ signal(SIGWINCH, onsig);
+}
+
+}
+
+void CMakeMessageHandler(const char* message, const char* title, bool&,
+ void* clientData)
+{
+ cmCursesForm* self = static_cast<cmCursesForm*>( clientData );
+ self->AddError(message, title);
+}
+
+int main(int argc, char const* const* argv)
+{
+ setlocale(LC_CTYPE, "");
+
+ cmsys::Encoding::CommandLineArguments encoding_args =
+ cmsys::Encoding::CommandLineArguments::Main(argc, argv);
+ argc = encoding_args.argc();
+ argv = encoding_args.argv();
+
+ cmSystemTools::FindCMakeResources(argv[0]);
+ cmDocumentation doc;
+ doc.addCMakeStandardDocSections();
+ if(doc.CheckOptions(argc, argv))
+ {
+ cmake hcm;
+ hcm.AddCMakePaths();
+ std::vector<cmDocumentationEntry> generators;
+ hcm.GetGeneratorDocumentation(generators);
+ doc.SetName("ccmake");
+ doc.SetSection("Name",cmDocumentationName);
+ doc.SetSection("Usage",cmDocumentationUsage);
+ if ( argc == 1 )
+ {
+ doc.AppendSection("Usage",cmDocumentationUsageNote);
+ }
+ doc.SetSection("Generators",generators);
+ doc.PrependSection("Options",cmDocumentationOptions);
+ return doc.PrintRequestedDocumentation(std::cout)? 0:1;
+ }
+
+ bool debug = false;
+ unsigned int i;
+ int j;
+ std::vector<std::string> args;
+ for(j =0; j < argc; ++j)
+ {
+ if(strcmp(argv[j], "-debug") == 0)
+ {
+ debug = true;
+ }
+ else
+ {
+ args.push_back(argv[j]);
+ }
+ }
+
+ std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
+ for(i=1; i < args.size(); ++i)
+ {
+ std::string arg = args[i];
+ if(arg.find("-B",0) == 0)
+ {
+ cacheDir = arg.substr(2);
+ }
+ }
+
+ cmSystemTools::DisableRunCommandOutput();
+
+ if (debug)
+ {
+ cmCursesForm::DebugStart();
+ }
+
+ initscr(); /* Initialization */
+ noecho(); /* Echo off */
+ cbreak(); /* nl- or cr not needed */
+ keypad(stdscr,TRUE); /* Use key symbols as
+ KEY_DOWN*/
+
+ signal(SIGWINCH, onsig);
+
+ int x,y;
+ getmaxyx(stdscr, y, x);
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ endwin();
+ std::cerr << "Window is too small. A size of at least "
+ << cmCursesMainForm::MIN_WIDTH << " x "
+ << cmCursesMainForm::MIN_HEIGHT
+ << " is required to run ccmake." << std::endl;
+ return 1;
+ }
+
+
+ cmCursesMainForm* myform;
+
+ myform = new cmCursesMainForm(args, x);
+ if(myform->LoadCache(cacheDir.c_str()))
+ {
+ curses_clear();
+ touchwin(stdscr);
+ endwin();
+ delete myform;
+ std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
+ return 1;
+ }
+
+ cmSystemTools::SetMessageCallback(CMakeMessageHandler, myform);
+
+ cmCursesForm::CurrentForm = myform;
+
+ myform->InitializeUI();
+ if ( myform->Configure(1) == 0 )
+ {
+ myform->Render(1, 1, x, y);
+ myform->HandleInput();
+ }
+
+ // Need to clean-up better
+ curses_clear();
+ touchwin(stdscr);
+ endwin();
+ delete cmCursesForm::CurrentForm;
+ cmCursesForm::CurrentForm = 0;
+
+ std::cout << std::endl << std::endl;
+
+ return 0;
+
+}
diff --git a/Source/CursesDialog/cmCursesBoolWidget.cxx b/Source/CursesDialog/cmCursesBoolWidget.cxx
new file mode 100644
index 0000000000..fd15b99441
--- /dev/null
+++ b/Source/CursesDialog/cmCursesBoolWidget.cxx
@@ -0,0 +1,74 @@
+/*============================================================================
+ 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 "cmCursesBoolWidget.h"
+#include "cmCursesMainForm.h"
+
+cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
+ int left, int top) :
+ cmCursesWidget(width, height, left, top)
+{
+ this->Type = cmCacheManager::BOOL;
+ set_field_fore(this->Field, A_NORMAL);
+ set_field_back(this->Field, A_STANDOUT);
+ field_opts_off(this->Field, O_STATIC);
+ this->SetValueAsBool(false);
+}
+
+bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* w)
+{
+
+ // 10 == enter
+ if (key == 10 || key == KEY_ENTER)
+ {
+ if (this->GetValueAsBool())
+ {
+ this->SetValueAsBool(false);
+ }
+ else
+ {
+ this->SetValueAsBool(true);
+ }
+
+ touchwin(w);
+ wrefresh(w);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+
+}
+
+void cmCursesBoolWidget::SetValueAsBool(bool value)
+{
+ if (value)
+ {
+ this->SetValue("ON");
+ }
+ else
+ {
+ this->SetValue("OFF");
+ }
+}
+
+bool cmCursesBoolWidget::GetValueAsBool()
+{
+ if (this->Value == "ON")
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
diff --git a/Source/CursesDialog/cmCursesBoolWidget.h b/Source/CursesDialog/cmCursesBoolWidget.h
new file mode 100644
index 0000000000..d2a25ca12b
--- /dev/null
+++ b/Source/CursesDialog/cmCursesBoolWidget.h
@@ -0,0 +1,40 @@
+/*============================================================================
+ 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 __cmCursesBoolWidget_h
+#define __cmCursesBoolWidget_h
+
+#include "cmCursesWidget.h"
+class cmCursesMainForm;
+
+class cmCursesBoolWidget : public cmCursesWidget
+{
+public:
+ cmCursesBoolWidget(int width, int height, int left, int top);
+
+ // Description:
+ // Handle user input. Called by the container of this widget
+ // when this widget has focus. Returns true if the input was
+ // handled.
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
+
+ // Description:
+ // Set/Get the value (on/off).
+ void SetValueAsBool(bool value);
+ bool GetValueAsBool();
+
+protected:
+ cmCursesBoolWidget(const cmCursesBoolWidget& from);
+ void operator=(const cmCursesBoolWidget&);
+
+};
+
+#endif // __cmCursesBoolWidget_h
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
new file mode 100644
index 0000000000..682f95f9ee
--- /dev/null
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
@@ -0,0 +1,124 @@
+/*============================================================================
+ 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 "cmCursesCacheEntryComposite.h"
+#include "cmCursesOptionsWidget.h"
+#include "cmCursesStringWidget.h"
+#include "cmCursesLabelWidget.h"
+#include "cmCursesBoolWidget.h"
+#include "cmCursesPathWidget.h"
+#include "cmCursesFilePathWidget.h"
+#include "cmCursesDummyWidget.h"
+#include "../cmSystemTools.h"
+
+cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
+ const std::string& key,
+ int labelwidth,
+ int entrywidth) :
+ Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
+{
+ this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
+ this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
+ this->Entry = 0;
+ this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
+}
+
+cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
+ const std::string& key, const cmCacheManager::CacheIterator& it, bool isNew,
+ int labelwidth, int entrywidth)
+ : Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
+{
+ this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
+ if (isNew)
+ {
+ this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
+ }
+ else
+ {
+ this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
+ }
+
+ this->Entry = 0;
+ switch ( it.GetType() )
+ {
+ case cmCacheManager::BOOL:
+ this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
+ if (cmSystemTools::IsOn(it.GetValue().c_str()))
+ {
+ static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
+ }
+ else
+ {
+ static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
+ }
+ break;
+ case cmCacheManager::PATH:
+ this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
+ static_cast<cmCursesPathWidget*>(this->Entry)->SetString(
+ it.GetValue());
+ break;
+ case cmCacheManager::FILEPATH:
+ this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
+ static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(
+ it.GetValue());
+ break;
+ case cmCacheManager::STRING:
+ if(it.PropertyExists("STRINGS"))
+ {
+ cmCursesOptionsWidget* ow =
+ new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
+ this->Entry = ow;
+ std::vector<std::string> options;
+ cmSystemTools::ExpandListArgument(
+ std::string(it.GetProperty("STRINGS")), options);
+ for(std::vector<std::string>::iterator
+ si = options.begin(); si != options.end(); ++si)
+ {
+ ow->AddOption(*si);
+ }
+ ow->SetOption(it.GetValue());
+ }
+ else
+ {
+ this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
+ static_cast<cmCursesStringWidget*>(this->Entry)->SetString(
+ it.GetValue());
+ }
+ break;
+ case cmCacheManager::UNINITIALIZED:
+ cmSystemTools::Error("Found an undefined variable: ",
+ it.GetName().c_str());
+ break;
+ default:
+ // TODO : put warning message here
+ break;
+ }
+
+}
+
+cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
+{
+ delete this->Label;
+ delete this->IsNewLabel;
+ delete this->Entry;
+}
+
+const char* cmCursesCacheEntryComposite::GetValue()
+{
+ if (this->Label)
+ {
+ return this->Label->GetValue();
+ }
+ else
+ {
+ return 0;
+ }
+}
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.h b/Source/CursesDialog/cmCursesCacheEntryComposite.h
new file mode 100644
index 0000000000..98107cc70e
--- /dev/null
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.h
@@ -0,0 +1,43 @@
+/*============================================================================
+ 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 __cmCursesCacheEntryComposite_h
+#define __cmCursesCacheEntryComposite_h
+
+#include "../cmCacheManager.h"
+#include "cmCursesLabelWidget.h"
+
+class cmCursesCacheEntryComposite
+{
+public:
+ cmCursesCacheEntryComposite(const std::string& key, int labelwidth,
+ int entrywidth);
+ cmCursesCacheEntryComposite(const std::string& key,
+ const cmCacheManager::CacheIterator& it,
+ bool isNew, int labelwidth, int entrywidth);
+ ~cmCursesCacheEntryComposite();
+ const char* GetValue();
+
+ friend class cmCursesMainForm;
+
+protected:
+ cmCursesCacheEntryComposite(const cmCursesCacheEntryComposite& from);
+ void operator=(const cmCursesCacheEntryComposite&);
+
+ cmCursesLabelWidget* Label;
+ cmCursesLabelWidget* IsNewLabel;
+ cmCursesWidget* Entry;
+ std::string Key;
+ int LabelWidth;
+ int EntryWidth;
+};
+
+#endif // __cmCursesCacheEntryComposite_h
diff --git a/Source/CursesDialog/cmCursesDummyWidget.cxx b/Source/CursesDialog/cmCursesDummyWidget.cxx
new file mode 100644
index 0000000000..60086a51bf
--- /dev/null
+++ b/Source/CursesDialog/cmCursesDummyWidget.cxx
@@ -0,0 +1,26 @@
+/*============================================================================
+ 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 "cmCursesDummyWidget.h"
+
+cmCursesDummyWidget::cmCursesDummyWidget(int width, int height,
+ int left, int top) :
+ cmCursesWidget(width, height, left, top)
+{
+ this->Type = cmCacheManager::INTERNAL;
+}
+
+
+bool cmCursesDummyWidget::HandleInput(int&, cmCursesMainForm*, WINDOW* )
+{
+ return false;
+}
+
diff --git a/Source/CursesDialog/cmCursesDummyWidget.h b/Source/CursesDialog/cmCursesDummyWidget.h
new file mode 100644
index 0000000000..9ac13652d6
--- /dev/null
+++ b/Source/CursesDialog/cmCursesDummyWidget.h
@@ -0,0 +1,36 @@
+/*============================================================================
+ 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 __cmCursesDummyWidget_h
+#define __cmCursesDummyWidget_h
+
+#include "cmCursesWidget.h"
+
+class cmCursesMainForm;
+
+class cmCursesDummyWidget : public cmCursesWidget
+{
+public:
+ cmCursesDummyWidget(int width, int height, int left, int top);
+
+ // Description:
+ // Handle user input. Called by the container of this widget
+ // when this widget has focus. Returns true if the input was
+ // handled.
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
+
+protected:
+ cmCursesDummyWidget(const cmCursesDummyWidget& from);
+ void operator=(const cmCursesDummyWidget&);
+
+};
+
+#endif // __cmCursesDummyWidget_h
diff --git a/Source/CursesDialog/cmCursesFilePathWidget.cxx b/Source/CursesDialog/cmCursesFilePathWidget.cxx
new file mode 100644
index 0000000000..01db014bbd
--- /dev/null
+++ b/Source/CursesDialog/cmCursesFilePathWidget.cxx
@@ -0,0 +1,20 @@
+/*============================================================================
+ 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 "cmCursesFilePathWidget.h"
+
+cmCursesFilePathWidget::cmCursesFilePathWidget(int width, int height,
+ int left, int top) :
+ cmCursesPathWidget(width, height, left, top)
+{
+ this->Type = cmCacheManager::FILEPATH;
+}
+
diff --git a/Source/CursesDialog/cmCursesFilePathWidget.h b/Source/CursesDialog/cmCursesFilePathWidget.h
new file mode 100644
index 0000000000..9d2972ee7d
--- /dev/null
+++ b/Source/CursesDialog/cmCursesFilePathWidget.h
@@ -0,0 +1,28 @@
+/*============================================================================
+ 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 __cmCursesFilePathWidget_h
+#define __cmCursesFilePathWidget_h
+
+#include "cmCursesPathWidget.h"
+
+class cmCursesFilePathWidget : public cmCursesPathWidget
+{
+public:
+ cmCursesFilePathWidget(int width, int height, int left, int top);
+
+protected:
+ cmCursesFilePathWidget(const cmCursesFilePathWidget& from);
+ void operator=(const cmCursesFilePathWidget&);
+
+};
+
+#endif // __cmCursesFilePathWidget_h
diff --git a/Source/CursesDialog/cmCursesForm.cxx b/Source/CursesDialog/cmCursesForm.cxx
new file mode 100644
index 0000000000..d1b470c312
--- /dev/null
+++ b/Source/CursesDialog/cmCursesForm.cxx
@@ -0,0 +1,57 @@
+/*============================================================================
+ 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 "cmCursesForm.h"
+
+cmsys::ofstream cmCursesForm::DebugFile;
+bool cmCursesForm::Debug = false;
+
+cmCursesForm::cmCursesForm()
+{
+ this->Form = 0;
+}
+
+cmCursesForm::~cmCursesForm()
+{
+ if (this->Form)
+ {
+ unpost_form(this->Form);
+ free_form(this->Form);
+ this->Form = 0;
+ }
+}
+
+void cmCursesForm::DebugStart()
+{
+ cmCursesForm::Debug = true;
+ cmCursesForm::DebugFile.open("ccmakelog.txt");
+}
+
+void cmCursesForm::DebugEnd()
+{
+ if (!cmCursesForm::Debug)
+ {
+ return;
+ }
+
+ cmCursesForm::Debug = false;
+ cmCursesForm::DebugFile.close();
+}
+
+void cmCursesForm::LogMessage(const char* msg)
+{
+ if (!cmCursesForm::Debug)
+ {
+ return;
+ }
+
+ cmCursesForm::DebugFile << msg << std::endl;
+}
diff --git a/Source/CursesDialog/cmCursesForm.h b/Source/CursesDialog/cmCursesForm.h
new file mode 100644
index 0000000000..f9317b9fba
--- /dev/null
+++ b/Source/CursesDialog/cmCursesForm.h
@@ -0,0 +1,76 @@
+/*============================================================================
+ 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 __cmCursesForm_h
+#define __cmCursesForm_h
+
+#include "../cmStandardIncludes.h"
+#include "cmCursesStandardIncludes.h"
+#include <cmsys/FStream.hxx>
+
+class cmCursesForm
+{
+public:
+ cmCursesForm();
+ virtual ~cmCursesForm();
+
+ // Description:
+ // Handle user input.
+ virtual void HandleInput() = 0;
+
+ // Description:
+ // Display form.
+ virtual void Render(int left, int top, int width, int height) = 0;
+
+ // Description:
+ // This method should normally called only by the form.
+ // The only exception is during a resize.
+ virtual void UpdateStatusBar() = 0;
+
+ // Description:
+ // During a CMake run, an error handle should add errors
+ // to be displayed afterwards.
+ virtual void AddError(const char*, const char*) {}
+
+ // Description:
+ // Turn debugging on. This will create ccmakelog.txt.
+ static void DebugStart();
+
+ // Description:
+ // Turn debugging off. This will close ccmakelog.txt.
+ static void DebugEnd();
+
+ // Description:
+ // Write a debugging message.
+ static void LogMessage(const char* msg);
+
+ // Description:
+ // Return the FORM. Should be only used by low-level methods.
+ FORM* GetForm()
+ {
+ return this->Form;
+ }
+
+ static cmCursesForm* CurrentForm;
+
+
+protected:
+
+ static cmsys::ofstream DebugFile;
+ static bool Debug;
+
+ cmCursesForm(const cmCursesForm& form);
+ void operator=(const cmCursesForm&);
+
+ FORM* Form;
+};
+
+#endif // __cmCursesForm_h
diff --git a/Source/CursesDialog/cmCursesLabelWidget.cxx b/Source/CursesDialog/cmCursesLabelWidget.cxx
new file mode 100644
index 0000000000..b50eb644dc
--- /dev/null
+++ b/Source/CursesDialog/cmCursesLabelWidget.cxx
@@ -0,0 +1,33 @@
+/*============================================================================
+ 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 "cmCursesLabelWidget.h"
+
+cmCursesLabelWidget::cmCursesLabelWidget(int width, int height,
+ int left, int top,
+ const std::string& name) :
+ cmCursesWidget(width, height, left, top)
+{
+ field_opts_off(this->Field, O_EDIT);
+ field_opts_off(this->Field, O_ACTIVE);
+ field_opts_off(this->Field, O_STATIC);
+ this->SetValue(name);
+}
+
+cmCursesLabelWidget::~cmCursesLabelWidget()
+{
+}
+
+bool cmCursesLabelWidget::HandleInput(int&, cmCursesMainForm*, WINDOW* )
+{
+ // Static text. No input is handled here.
+ return false;
+}
diff --git a/Source/CursesDialog/cmCursesLabelWidget.h b/Source/CursesDialog/cmCursesLabelWidget.h
new file mode 100644
index 0000000000..cc32d11eaa
--- /dev/null
+++ b/Source/CursesDialog/cmCursesLabelWidget.h
@@ -0,0 +1,38 @@
+/*============================================================================
+ 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 __cmCursesLabelWidget_h
+#define __cmCursesLabelWidget_h
+
+#include "cmCursesWidget.h"
+#include "cmCursesStandardIncludes.h"
+
+class cmCursesMainForm;
+
+class cmCursesLabelWidget : public cmCursesWidget
+{
+public:
+ cmCursesLabelWidget(int width, int height, int left, int top,
+ const std::string& name);
+ virtual ~cmCursesLabelWidget();
+
+ // Description:
+ // Handle user input. Called by the container of this widget
+ // when this widget has focus. Returns true if the input was
+ // handled
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
+
+protected:
+ cmCursesLabelWidget(const cmCursesLabelWidget& from);
+ void operator=(const cmCursesLabelWidget&);
+};
+
+#endif // __cmCursesLabelWidget_h
diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx
new file mode 100644
index 0000000000..057f8f3d86
--- /dev/null
+++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx
@@ -0,0 +1,207 @@
+/*============================================================================
+ 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 "../cmCacheManager.h"
+#include "../cmSystemTools.h"
+#include "../cmake.h"
+#include "../cmVersion.h"
+#include "cmCursesLongMessageForm.h"
+#include "cmCursesMainForm.h"
+
+inline int ctrl(int z)
+{
+ return (z&037);
+}
+
+cmCursesLongMessageForm::cmCursesLongMessageForm(std::vector<std::string>
+ const& messages, const char*
+ title)
+{
+ // Append all messages into on big string
+ std::vector<std::string>::const_iterator it;
+ for(it=messages.begin(); it != messages.end(); it++)
+ {
+ this->Messages += (*it);
+ // Add one blank line after each message
+ this->Messages += "\n\n";
+ }
+ this->Title = title;
+ this->Fields[0] = 0;
+ this->Fields[1] = 0;
+}
+
+cmCursesLongMessageForm::~cmCursesLongMessageForm()
+{
+ if (this->Fields[0])
+ {
+ free_field(this->Fields[0]);
+ }
+}
+
+
+void cmCursesLongMessageForm::UpdateStatusBar()
+{
+ int x,y;
+ getmaxyx(stdscr, y, x);
+
+ char bar[cmCursesMainForm::MAX_WIDTH];
+ size_t size = strlen(this->Title.c_str());
+ if ( size >= cmCursesMainForm::MAX_WIDTH )
+ {
+ size = cmCursesMainForm::MAX_WIDTH-1;
+ }
+ strncpy(bar, this->Title.c_str(), size);
+ for(size_t i=size-1; i<cmCursesMainForm::MAX_WIDTH; i++) bar[i] = ' ';
+
+ int width;
+ if (x < cmCursesMainForm::MAX_WIDTH )
+ {
+ width = x;
+ }
+ else
+ {
+ width = cmCursesMainForm::MAX_WIDTH-1;
+ }
+
+ bar[width] = '\0';
+
+ char version[cmCursesMainForm::MAX_WIDTH];
+ char vertmp[128];
+ sprintf(vertmp,"CMake Version %s", cmVersion::GetCMakeVersion());
+ size_t sideSpace = (width-strlen(vertmp));
+ for(size_t i=0; i<sideSpace; i++) { version[i] = ' '; }
+ sprintf(version+sideSpace, "%s", vertmp);
+ version[width] = '\0';
+
+ curses_move(y-4,0);
+ attron(A_STANDOUT);
+ printw(bar);
+ attroff(A_STANDOUT);
+ curses_move(y-3,0);
+ printw(version);
+ pos_form_cursor(this->Form);
+}
+
+void cmCursesLongMessageForm::PrintKeys()
+{
+ int x,y;
+ getmaxyx(stdscr, y, x);
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ return;
+ }
+ char firstLine[512];
+ sprintf(firstLine, "Press [e] to exit help");
+
+ curses_move(y-2,0);
+ printw(firstLine);
+ pos_form_cursor(this->Form);
+
+}
+
+void cmCursesLongMessageForm::Render(int, int, int, int)
+{
+ int x,y;
+ getmaxyx(stdscr, y, x);
+
+ if (this->Form)
+ {
+ unpost_form(this->Form);
+ free_form(this->Form);
+ this->Form = 0;
+ }
+
+ const char* msg = this->Messages.c_str();
+
+ curses_clear();
+
+ if (this->Fields[0])
+ {
+ free_field(this->Fields[0]);
+ this->Fields[0] = 0;
+ }
+
+ this->Fields[0] = new_field(y-6, x-2, 1, 1, 0, 0);
+
+ field_opts_off(this->Fields[0], O_STATIC);
+
+ this->Form = new_form(this->Fields);
+ post_form(this->Form);
+
+ int i=0;
+ form_driver(this->Form, REQ_BEG_FIELD);
+ while(msg[i] != '\0' && i < 60000)
+ {
+ if (msg[i] == '\n' && msg[i+1] != '\0')
+ {
+ form_driver(this->Form, REQ_NEW_LINE);
+ }
+ else
+ {
+ form_driver(this->Form, msg[i]);
+ }
+ i++;
+ }
+ form_driver(this->Form, REQ_BEG_FIELD);
+
+ this->UpdateStatusBar();
+ this->PrintKeys();
+ touchwin(stdscr);
+ refresh();
+
+}
+
+void cmCursesLongMessageForm::HandleInput()
+{
+ if (!this->Form)
+ {
+ return;
+ }
+
+ char debugMessage[128];
+
+ for(;;)
+ {
+ int key = getch();
+
+ sprintf(debugMessage, "Message widget handling input, key: %d", key);
+ cmCursesForm::LogMessage(debugMessage);
+
+ // quit
+ if ( key == 'o' || key == 'e' )
+ {
+ break;
+ }
+ else if ( key == KEY_DOWN || key == ctrl('n') )
+ {
+ form_driver(this->Form, REQ_SCR_FLINE);
+ }
+ else if ( key == KEY_UP || key == ctrl('p') )
+ {
+ form_driver(this->Form, REQ_SCR_BLINE);
+ }
+ else if ( key == KEY_NPAGE || key == ctrl('d') )
+ {
+ form_driver(this->Form, REQ_SCR_FPAGE);
+ }
+ else if ( key == KEY_PPAGE || key == ctrl('u') )
+ {
+ form_driver(this->Form, REQ_SCR_BPAGE);
+ }
+
+ this->UpdateStatusBar();
+ this->PrintKeys();
+ touchwin(stdscr);
+ wrefresh(stdscr);
+ }
+
+}
diff --git a/Source/CursesDialog/cmCursesLongMessageForm.h b/Source/CursesDialog/cmCursesLongMessageForm.h
new file mode 100644
index 0000000000..1e86974f2a
--- /dev/null
+++ b/Source/CursesDialog/cmCursesLongMessageForm.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 __cmCursesLongMessageForm_h
+#define __cmCursesLongMessageForm_h
+
+#include "../cmStandardIncludes.h"
+#include "cmCursesForm.h"
+#include "cmCursesStandardIncludes.h"
+
+class cmCursesCacheEntryComposite;
+
+class cmCursesLongMessageForm : public cmCursesForm
+{
+public:
+ cmCursesLongMessageForm(std::vector<std::string> const& messages,
+ const char* title);
+ virtual ~cmCursesLongMessageForm();
+
+ // Description:
+ // Handle user input.
+ virtual void HandleInput();
+
+ // Description:
+ // Display form. Use a window of size width x height, starting
+ // at top, left.
+ virtual void Render(int left, int top, int width, int height);
+
+ // Description:
+ // This method should normally called only by the form.
+ // The only exception is during a resize.
+ void PrintKeys();
+
+ // Description:
+ // This method should normally called only by the form.
+ // The only exception is during a resize.
+ virtual void UpdateStatusBar();
+
+protected:
+ cmCursesLongMessageForm(const cmCursesLongMessageForm& from);
+ void operator=(const cmCursesLongMessageForm&);
+
+ std::string Messages;
+ std::string Title;
+
+ FIELD* Fields[2];
+
+};
+
+#endif // __cmCursesLongMessageForm_h
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx
new file mode 100644
index 0000000000..0734927147
--- /dev/null
+++ b/Source/CursesDialog/cmCursesMainForm.cxx
@@ -0,0 +1,1303 @@
+/*============================================================================
+ 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 "../cmCacheManager.h"
+#include "../cmSystemTools.h"
+#include "../cmVersion.h"
+#include "../cmake.h"
+#include "cmCursesMainForm.h"
+#include "cmCursesStringWidget.h"
+#include "cmCursesLabelWidget.h"
+#include "cmCursesBoolWidget.h"
+#include "cmCursesPathWidget.h"
+#include "cmCursesFilePathWidget.h"
+#include "cmCursesDummyWidget.h"
+#include "cmCursesCacheEntryComposite.h"
+#include "cmCursesLongMessageForm.h"
+
+
+inline int ctrl(int z)
+{
+ return (z&037);
+}
+
+cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args,
+ int initWidth) :
+ Args(args), InitialWidth(initWidth)
+{
+ this->NumberOfPages = 0;
+ this->Fields = 0;
+ this->Entries = 0;
+ this->AdvancedMode = false;
+ this->NumberOfVisibleEntries = 0;
+ this->OkToGenerate = false;
+ this->HelpMessage.push_back("Welcome to ccmake, curses based user interface for CMake.");
+ this->HelpMessage.push_back("");
+ this->HelpMessage.push_back(s_ConstHelpMessage);
+ this->CMakeInstance = new cmake;
+ this->CMakeInstance->SetCMakeEditCommand(
+ cmSystemTools::GetCMakeCursesCommand());
+
+ // create the arguments for the cmake object
+ std::string whereCMake = cmSystemTools::GetProgramPath(this->Args[0].c_str());
+ whereCMake += "/cmake";
+ this->Args[0] = whereCMake;
+ this->CMakeInstance->SetArgs(this->Args);
+ this->SearchString = "";
+ this->OldSearchString = "";
+ this->SearchMode = false;
+}
+
+cmCursesMainForm::~cmCursesMainForm()
+{
+ if (this->Form)
+ {
+ unpost_form(this->Form);
+ free_form(this->Form);
+ this->Form = 0;
+ }
+ delete[] this->Fields;
+
+ // Clean-up composites
+ if (this->Entries)
+ {
+ std::vector<cmCursesCacheEntryComposite*>::iterator it;
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
+ {
+ delete *it;
+ }
+ }
+ delete this->Entries;
+ if (this->CMakeInstance)
+ {
+ delete this->CMakeInstance;
+ this->CMakeInstance = 0;
+ }
+}
+
+// See if a cache entry is in the list of entries in the ui.
+bool cmCursesMainForm::LookForCacheEntry(const std::string& key)
+{
+ if (!this->Entries)
+ {
+ return false;
+ }
+
+ std::vector<cmCursesCacheEntryComposite*>::iterator it;
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
+ {
+ if (key == (*it)->Key)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// Create new cmCursesCacheEntryComposite entries from the cache
+void cmCursesMainForm::InitializeUI()
+{
+ // Create a vector of cmCursesCacheEntryComposite's
+ // which contain labels, entries and new entry markers
+ std::vector<cmCursesCacheEntryComposite*>* newEntries =
+ new std::vector<cmCursesCacheEntryComposite*>;
+ newEntries->reserve(this->CMakeInstance->GetCacheManager()->GetSize());
+
+ // Count non-internal and non-static entries
+ int count=0;
+ for(cmCacheManager::CacheIterator i =
+ this->CMakeInstance->GetCacheManager()->NewIterator();
+ !i.IsAtEnd(); i.Next())
+ {
+ if ( i.GetType() != cmCacheManager::INTERNAL &&
+ i.GetType() != cmCacheManager::STATIC &&
+ i.GetType() != cmCacheManager::UNINITIALIZED)
+ {
+ ++count;
+ }
+ }
+
+ int entrywidth = this->InitialWidth - 35;
+
+ cmCursesCacheEntryComposite* comp;
+ if ( count == 0 )
+ {
+ // If cache is empty, display a label saying so and a
+ // dummy entry widget (does not respond to input)
+ comp = new cmCursesCacheEntryComposite("EMPTY CACHE", 30, 30);
+ comp->Entry = new cmCursesDummyWidget(1, 1, 1, 1);
+ newEntries->push_back(comp);
+ }
+ else
+ {
+ // Create the composites.
+
+ // First add entries which are new
+ for(cmCacheManager::CacheIterator i =
+ this->CMakeInstance->GetCacheManager()->NewIterator();
+ !i.IsAtEnd(); i.Next())
+ {
+ std::string key = i.GetName();
+ if ( i.GetType() == cmCacheManager::INTERNAL ||
+ i.GetType() == cmCacheManager::STATIC ||
+ i.GetType() == cmCacheManager::UNINITIALIZED )
+ {
+ continue;
+ }
+
+ if (!this->LookForCacheEntry(key))
+ {
+ newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
+ true, 30,
+ entrywidth));
+ this->OkToGenerate = false;
+ }
+ }
+
+ // then add entries which are old
+ for(cmCacheManager::CacheIterator i =
+ this->CMakeInstance->GetCacheManager()->NewIterator();
+ !i.IsAtEnd(); i.Next())
+ {
+ std::string key = i.GetName();
+ if ( i.GetType() == cmCacheManager::INTERNAL ||
+ i.GetType() == cmCacheManager::STATIC ||
+ i.GetType() == cmCacheManager::UNINITIALIZED )
+ {
+ continue;
+ }
+
+ if (this->LookForCacheEntry(key))
+ {
+ newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
+ false, 30,
+ entrywidth));
+ }
+ }
+ }
+
+ // Clean old entries
+ if (this->Entries)
+ {
+ // Have to call delete on each pointer
+ std::vector<cmCursesCacheEntryComposite*>::iterator it;
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
+ {
+ delete *it;
+ }
+ }
+ delete this->Entries;
+ this->Entries = newEntries;
+
+ // Compute fields from composites
+ this->RePost();
+}
+
+
+void cmCursesMainForm::RePost()
+{
+ // Create the fields to be passed to the form.
+ if (this->Form)
+ {
+ unpost_form(this->Form);
+ free_form(this->Form);
+ this->Form = 0;
+ }
+ delete[] this->Fields;
+ if (this->AdvancedMode)
+ {
+ this->NumberOfVisibleEntries = this->Entries->size();
+ }
+ else
+ {
+ // If normal mode, count only non-advanced entries
+ this->NumberOfVisibleEntries = 0;
+ std::vector<cmCursesCacheEntryComposite*>::iterator it;
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
+ {
+ cmCacheManager::CacheIterator mit =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
+ if (mit.IsAtEnd() ||
+ (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
+ {
+ continue;
+ }
+ this->NumberOfVisibleEntries++;
+ }
+ }
+ // there is always one even if it is the dummy one
+ if(this->NumberOfVisibleEntries == 0)
+ {
+ this->NumberOfVisibleEntries = 1;
+ }
+ // Assign the fields: 3 for each entry: label, new entry marker
+ // ('*' or ' ') and entry widget
+ this->Fields = new FIELD*[3*this->NumberOfVisibleEntries+1];
+ size_t cc;
+ for ( cc = 0; cc < 3 * this->NumberOfVisibleEntries+1; cc ++ )
+ {
+ this->Fields[cc] = 0;
+ }
+
+ // Assign fields
+ int j=0;
+ std::vector<cmCursesCacheEntryComposite*>::iterator it;
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
+ {
+ cmCacheManager::CacheIterator mit =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
+ if (mit.IsAtEnd() ||
+ (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
+ {
+ continue;
+ }
+ this->Fields[3*j] = (*it)->Label->Field;
+ this->Fields[3*j+1] = (*it)->IsNewLabel->Field;
+ this->Fields[3*j+2] = (*it)->Entry->Field;
+ j++;
+ }
+ // if no cache entries there should still be one dummy field
+ if(j == 0)
+ {
+ it = this->Entries->begin();
+ this->Fields[0] = (*it)->Label->Field;
+ this->Fields[1] = (*it)->IsNewLabel->Field;
+ this->Fields[2] = (*it)->Entry->Field;
+ this->NumberOfVisibleEntries = 1;
+ }
+ // Has to be null terminated.
+ this->Fields[3*this->NumberOfVisibleEntries] = 0;
+}
+
+void cmCursesMainForm::Render(int left, int top, int width, int height)
+{
+
+ if (this->Form)
+ {
+ FIELD* currentField = current_field(this->Form);
+ cmCursesWidget* cw = reinterpret_cast<cmCursesWidget*>
+ (field_userptr(currentField));
+ // If in edit mode, get out of it
+ if ( cw->GetType() == cmCacheManager::STRING ||
+ cw->GetType() == cmCacheManager::PATH ||
+ cw->GetType() == cmCacheManager::FILEPATH )
+ {
+ cmCursesStringWidget* sw = static_cast<cmCursesStringWidget*>(cw);
+ sw->SetInEdit(false);
+ }
+ // Delete the previous form
+ unpost_form(this->Form);
+ free_form(this->Form);
+ this->Form = 0;
+ }
+
+ // Wrong window size
+ if ( width < cmCursesMainForm::MIN_WIDTH ||
+ width < this->InitialWidth ||
+ height < cmCursesMainForm::MIN_HEIGHT )
+ {
+ return;
+ }
+
+ // Leave room for toolbar
+ height -= 7;
+
+ if (this->AdvancedMode)
+ {
+ this->NumberOfVisibleEntries = this->Entries->size();
+ }
+ else
+ {
+ // If normal, display only non-advanced entries
+ this->NumberOfVisibleEntries = 0;
+ std::vector<cmCursesCacheEntryComposite*>::iterator it;
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
+ {
+ cmCacheManager::CacheIterator mit =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
+ if (mit.IsAtEnd() ||
+ (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
+ {
+ continue;
+ }
+ this->NumberOfVisibleEntries++;
+ }
+ }
+
+ // Re-adjust the fields according to their place
+ this->NumberOfPages = 1;
+ if (height > 0)
+ {
+ bool isNewPage;
+ int i=0;
+ std::vector<cmCursesCacheEntryComposite*>::iterator it;
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
+ {
+ cmCacheManager::CacheIterator mit =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
+ if (mit.IsAtEnd() ||
+ (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
+ {
+ continue;
+ }
+ int row = (i % height) + 1;
+ int page = (i / height) + 1;
+ isNewPage = ( page > 1 ) && ( row == 1 );
+
+ if (isNewPage)
+ {
+ this->NumberOfPages++;
+ }
+ (*it)->Label->Move(left, top+row-1, isNewPage);
+ (*it)->IsNewLabel->Move(left+32, top+row-1, false);
+ (*it)->Entry->Move(left+33, top+row-1, false);
+ (*it)->Entry->SetPage(this->NumberOfPages);
+ i++;
+ }
+ }
+
+ // Post the form
+ this->Form = new_form(this->Fields);
+ post_form(this->Form);
+ // Update toolbar
+ this->UpdateStatusBar();
+ this->PrintKeys();
+
+ touchwin(stdscr);
+ refresh();
+}
+
+void cmCursesMainForm::PrintKeys(int process /* = 0 */)
+{
+ int x,y;
+ getmaxyx(stdscr, y, x);
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ x < this->InitialWidth ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ return;
+ }
+
+ // Give the current widget (if it exists), a chance to print keys
+ cmCursesWidget* cw = 0;
+ if (this->Form)
+ {
+ FIELD* currentField = current_field(this->Form);
+ cw = reinterpret_cast<cmCursesWidget*>(field_userptr(currentField));
+ }
+
+ if (cw)
+ {
+ cw->PrintKeys();
+ }
+
+// {
+// }
+// else
+// {
+ char firstLine[512]="";
+ char secondLine[512]="";
+ char thirdLine[512]="";
+ if (process)
+ {
+ const char* clearLine =
+ " ";
+ strcpy(firstLine, clearLine);
+ strcpy(secondLine, clearLine);
+ strcpy(thirdLine, clearLine);
+ }
+ else
+ {
+ if (this->OkToGenerate)
+ {
+ sprintf(firstLine,
+ "Press [c] to configure Press [g] to generate and exit");
+ }
+ else
+ {
+ sprintf(firstLine, "Press [c] to configure ");
+ }
+ {
+ const char* toggleKeyInstruction =
+ "Press [t] to toggle advanced mode (Currently %s)";
+ sprintf(thirdLine,
+ toggleKeyInstruction,
+ this->AdvancedMode ? "On" : "Off");
+ }
+ sprintf(secondLine,
+ "Press [h] for help "
+ "Press [q] to quit without generating");
+ }
+
+ curses_move(y-4,0);
+ char fmt[512] = "Press [enter] to edit option";
+ if ( process )
+ {
+ strcpy(fmt, " ");
+ }
+ printw(fmt);
+ curses_move(y-3,0);
+ printw(firstLine);
+ curses_move(y-2,0);
+ printw(secondLine);
+ curses_move(y-1,0);
+ printw(thirdLine);
+
+ if (cw)
+ {
+ sprintf(firstLine, "Page %d of %d", cw->GetPage(), this->NumberOfPages);
+ curses_move(0,65-static_cast<unsigned int>(strlen(firstLine))-1);
+ printw(firstLine);
+ }
+// }
+
+ pos_form_cursor(this->Form);
+
+}
+
+// Print the key of the current entry and the CMake version
+// on the status bar. Designed for a width of 80 chars.
+void cmCursesMainForm::UpdateStatusBar(const char* message)
+{
+ int x,y;
+ getmaxyx(stdscr, y, x);
+ // If window size is too small, display error and return
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ x < this->InitialWidth ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ curses_clear();
+ curses_move(0,0);
+ char fmt[] = "Window is too small. A size of at least %dx%d is required.";
+ printw(fmt,
+ (cmCursesMainForm::MIN_WIDTH < this->InitialWidth ?
+ this->InitialWidth : cmCursesMainForm::MIN_WIDTH),
+ cmCursesMainForm::MIN_HEIGHT);
+ touchwin(stdscr);
+ wrefresh(stdscr);
+ return;
+ }
+
+ // Get the key of the current entry
+ FIELD* cur = current_field(this->Form);
+ int findex = field_index(cur);
+ cmCursesWidget* lbl = 0;
+ if ( findex >= 0 )
+ {
+ lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(this->Fields[findex-2]));
+ }
+ char help[128] = "";
+ const char* curField = "";
+ if ( lbl )
+ {
+ curField = lbl->GetValue();
+
+ // Get the help string of the current entry
+ // and add it to the help string
+ cmCacheManager::CacheIterator it =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
+ if (!it.IsAtEnd())
+ {
+ const char* hs = it.GetProperty("HELPSTRING");
+ if ( hs )
+ {
+ strncpy(help, hs, 127);
+ help[127] = '\0';
+ }
+ else
+ {
+ help[0] = 0;
+ }
+ }
+ else
+ {
+ sprintf(help," ");
+ }
+ }
+
+ // Join the key, help string and pad with spaces
+ // (or truncate) as necessary
+ char bar[cmCursesMainForm::MAX_WIDTH];
+ size_t i, curFieldLen = strlen(curField);
+ size_t helpLen = strlen(help);
+
+ size_t width;
+ if (x < cmCursesMainForm::MAX_WIDTH )
+ {
+ width = x;
+ }
+ else
+ {
+ width = cmCursesMainForm::MAX_WIDTH;
+ }
+
+ if ( message )
+ {
+ curField = message;
+ curFieldLen = strlen(message);
+ if ( curFieldLen < width )
+ {
+ strcpy(bar, curField);
+ for(i=curFieldLen; i < width; ++i)
+ {
+ bar[i] = ' ';
+ }
+ }
+ else
+ {
+ strncpy(bar, curField, width);
+ }
+ }
+ else
+ {
+ if (curFieldLen >= width)
+ {
+ strncpy(bar, curField, width);
+ }
+ else
+ {
+ strcpy(bar, curField);
+ bar[curFieldLen] = ':';
+ bar[curFieldLen+1] = ' ';
+ if (curFieldLen + helpLen + 2 >= width)
+ {
+ strncpy(bar+curFieldLen+2, help, width
+ - curFieldLen - 2);
+ }
+ else
+ {
+ strcpy(bar+curFieldLen+2, help);
+ for(i=curFieldLen+helpLen+2; i < width; ++i)
+ {
+ bar[i] = ' ';
+ }
+ }
+ }
+ }
+
+
+ bar[width] = '\0';
+
+
+ // Display CMake version info on the next line
+ // We want to display this on the right
+ char version[cmCursesMainForm::MAX_WIDTH];
+ char vertmp[128];
+ sprintf(vertmp,"CMake Version %s", cmVersion::GetCMakeVersion());
+ size_t sideSpace = (width-strlen(vertmp));
+ for(i=0; i<sideSpace; i++) { version[i] = ' '; }
+ sprintf(version+sideSpace, "%s", vertmp);
+ version[width] = '\0';
+
+ // Now print both lines
+ curses_move(y-5,0);
+ attron(A_STANDOUT);
+ char format[] = "%s";
+ printw(format, bar);
+ attroff(A_STANDOUT);
+ curses_move(y-4,0);
+ printw(version);
+ pos_form_cursor(this->Form);
+}
+
+void cmCursesMainForm::UpdateProgress(const char *msg, float prog, void* vp)
+{
+ cmCursesMainForm* cm = static_cast<cmCursesMainForm*>(vp);
+ if ( !cm )
+ {
+ return;
+ }
+ char tmp[1024];
+ const char *cmsg = tmp;
+ if ( prog >= 0 )
+ {
+ sprintf(tmp, "%s %i%%",msg,(int)(100*prog));
+ }
+ else
+ {
+ cmsg = msg;
+ }
+ cm->UpdateStatusBar(cmsg);
+ cm->PrintKeys(1);
+ curses_move(1,1);
+ touchwin(stdscr);
+ refresh();
+}
+
+int cmCursesMainForm::Configure(int noconfigure)
+{
+ int xi,yi;
+ getmaxyx(stdscr, yi, xi);
+
+ curses_move(1,1);
+ this->UpdateStatusBar("Configuring, please wait...");
+ this->PrintKeys(1);
+ touchwin(stdscr);
+ refresh();
+ this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this);
+
+ // always save the current gui values to disk
+ this->FillCacheManagerFromUI();
+ this->CMakeInstance->GetCacheManager()->SaveCache(
+ this->CMakeInstance->GetHomeOutputDirectory());
+ this->LoadCache(0);
+
+ // Get rid of previous errors
+ this->Errors = std::vector<std::string>();
+
+ // run the generate process
+ this->OkToGenerate = true;
+ int retVal;
+ if ( noconfigure )
+ {
+ retVal = this->CMakeInstance->DoPreConfigureChecks();
+ this->OkToGenerate = false;
+ if ( retVal > 0 )
+ {
+ retVal = 0;
+ }
+ }
+ else
+ {
+ retVal = this->CMakeInstance->Configure();
+ }
+ this->CMakeInstance->SetProgressCallback(0, 0);
+
+ keypad(stdscr,TRUE); /* Use key symbols as
+ KEY_DOWN*/
+
+ if( retVal != 0 || !this->Errors.empty())
+ {
+ // see if there was an error
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ this->OkToGenerate = false;
+ }
+ int xx,yy;
+ getmaxyx(stdscr, yy, xx);
+ cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(
+ this->Errors,
+ cmSystemTools::GetErrorOccuredFlag()
+ ? "Errors occurred during the last pass." :
+ "CMake produced the following output.");
+ // reset error condition
+ cmSystemTools::ResetErrorOccuredFlag();
+ CurrentForm = msgs;
+ msgs->Render(1,1,xx,yy);
+ msgs->HandleInput();
+ // If they typed the wrong source directory, we report
+ // an error and exit
+ if ( retVal == -2 )
+ {
+ return retVal;
+ }
+ CurrentForm = this;
+ this->Render(1,1,xx,yy);
+ }
+
+ this->InitializeUI();
+ this->Render(1, 1, xi, yi);
+
+ return 0;
+}
+
+int cmCursesMainForm::Generate()
+{
+ int xi,yi;
+ getmaxyx(stdscr, yi, xi);
+
+ curses_move(1,1);
+ this->UpdateStatusBar("Generating, please wait...");
+ this->PrintKeys(1);
+ touchwin(stdscr);
+ refresh();
+ this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this);
+
+ // Get rid of previous errors
+ this->Errors = std::vector<std::string>();
+
+ // run the generate process
+ int retVal = this->CMakeInstance->Generate();
+
+ this->CMakeInstance->SetProgressCallback(0, 0);
+ keypad(stdscr,TRUE); /* Use key symbols as
+ KEY_DOWN*/
+
+ if( retVal != 0 || !this->Errors.empty())
+ {
+ // see if there was an error
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ this->OkToGenerate = false;
+ }
+ // reset error condition
+ cmSystemTools::ResetErrorOccuredFlag();
+ int xx,yy;
+ getmaxyx(stdscr, yy, xx);
+ const char* title = "Messages during last pass.";
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ title = "Errors occurred during the last pass.";
+ }
+ cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(this->Errors,
+ title);
+ CurrentForm = msgs;
+ msgs->Render(1,1,xx,yy);
+ msgs->HandleInput();
+ // If they typed the wrong source directory, we report
+ // an error and exit
+ if ( retVal == -2 )
+ {
+ return retVal;
+ }
+ CurrentForm = this;
+ this->Render(1,1,xx,yy);
+ }
+
+ this->InitializeUI();
+ this->Render(1, 1, xi, yi);
+
+ return 0;
+}
+
+void cmCursesMainForm::AddError(const char* message, const char*)
+{
+ this->Errors.push_back(message);
+}
+
+void cmCursesMainForm::RemoveEntry(const char* value)
+{
+ if (!value)
+ {
+ return;
+ }
+
+ std::vector<cmCursesCacheEntryComposite*>::iterator it;
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
+ {
+ const char* val = (*it)->GetValue();
+ if ( val && !strcmp(value, val) )
+ {
+ this->CMakeInstance->UnwatchUnusedCli(value);
+ this->Entries->erase(it);
+ break;
+ }
+ }
+}
+
+// copy from the list box to the cache manager
+void cmCursesMainForm::FillCacheManagerFromUI()
+{
+ size_t size = this->Entries->size();
+ for(size_t i=0; i < size; i++)
+ {
+ cmCacheManager::CacheIterator it =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator(
+ (*this->Entries)[i]->Key.c_str());
+ if (!it.IsAtEnd())
+ {
+ std::string oldValue = it.GetValue();
+ std::string newValue = (*this->Entries)[i]->Entry->GetValue();
+ std::string fixedOldValue;
+ std::string fixedNewValue;
+ this->FixValue(it.GetType(), oldValue, fixedOldValue);
+ this->FixValue(it.GetType(), newValue, fixedNewValue);
+
+ if(!(fixedOldValue == fixedNewValue))
+ {
+ // The user has changed the value. Mark it as modified.
+ it.SetProperty("MODIFIED", true);
+ it.SetValue(fixedNewValue.c_str());
+ }
+ }
+ }
+}
+
+void cmCursesMainForm::FixValue(cmCacheManager::CacheEntryType type,
+ const std::string& in, std::string& out) const
+{
+ out = in.substr(0,in.find_last_not_of(" ")+1);
+ if(type == cmCacheManager::PATH || type == cmCacheManager::FILEPATH)
+ {
+ cmSystemTools::ConvertToUnixSlashes(out);
+ }
+ if(type == cmCacheManager::BOOL)
+ {
+ if(cmSystemTools::IsOff(out.c_str()))
+ {
+ out = "OFF";
+ }
+ else
+ {
+ out = "ON";
+ }
+ }
+}
+
+#include <unistd.h>
+
+void cmCursesMainForm::HandleInput()
+{
+ int x=0,y=0;
+
+ if (!this->Form)
+ {
+ return;
+ }
+
+ FIELD* currentField;
+ cmCursesWidget* currentWidget;
+
+ char debugMessage[128];
+
+ for(;;)
+ {
+ this->UpdateStatusBar();
+ this->PrintKeys();
+ if ( this->SearchMode )
+ {
+ std::string searchstr = "Search: " + this->SearchString;
+ this->UpdateStatusBar( searchstr.c_str() );
+ this->PrintKeys(1);
+ curses_move(y-5,static_cast<unsigned int>(searchstr.size()));
+ //curses_move(1,1);
+ touchwin(stdscr);
+ refresh();
+ }
+ int key = getch();
+
+ getmaxyx(stdscr, y, x);
+ // If window too small, handle 'q' only
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ // quit
+ if ( key == 'q' )
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ currentField = current_field(this->Form);
+ currentWidget = reinterpret_cast<cmCursesWidget*>(field_userptr(
+ currentField));
+
+ bool widgetHandled=false;
+
+ if ( this->SearchMode )
+ {
+ if ( key == 10 || key == KEY_ENTER )
+ {
+ this->SearchMode = false;
+ if ( this->SearchString.size() > 0 )
+ {
+ this->JumpToCacheEntry(this->SearchString.c_str());
+ this->OldSearchString = this->SearchString;
+ }
+ this->SearchString = "";
+ }
+ /*
+ else if ( key == KEY_ESCAPE )
+ {
+ this->SearchMode = false;
+ }
+ */
+ else if ((key >= 'a' && key <= 'z') ||
+ (key >= 'A' && key <= 'Z') ||
+ (key >= '0' && key <= '9') ||
+ (key == '_' ))
+ {
+ if ( this->SearchString.size() < static_cast<std::string::size_type>(x-10) )
+ {
+ this->SearchString += static_cast<char>(key);
+ }
+ }
+ else if ( key == ctrl('h') || key == KEY_BACKSPACE || key == KEY_DC )
+ {
+ if ( this->SearchString.size() > 0 )
+ {
+ this->SearchString.resize(this->SearchString.size()-1);
+ }
+ }
+ }
+ else if (currentWidget && !this->SearchMode)
+ {
+ // Ask the current widget if it wants to handle input
+ widgetHandled = currentWidget->HandleInput(key, this, stdscr);
+ if (widgetHandled)
+ {
+ this->OkToGenerate = false;
+ this->UpdateStatusBar();
+ this->PrintKeys();
+ }
+ }
+ if ((!currentWidget || !widgetHandled) && !this->SearchMode)
+ {
+ // If the current widget does not want to handle input,
+ // we handle it.
+ sprintf(debugMessage, "Main form handling input, key: %d", key);
+ cmCursesForm::LogMessage(debugMessage);
+ // quit
+ if ( key == 'q' )
+ {
+ break;
+ }
+ // if not end of page, next field otherwise next page
+ // each entry consists of fields: label, isnew, value
+ // therefore, the label field for the prev. entry is index-5
+ // and the label field for the next entry is index+1
+ // (index always corresponds to the value field)
+ else if ( key == KEY_DOWN || key == ctrl('n') )
+ {
+ FIELD* cur = current_field(this->Form);
+ size_t findex = field_index(cur);
+ if ( findex == 3*this->NumberOfVisibleEntries-1 )
+ {
+ continue;
+ }
+ if (new_page(this->Fields[findex+1]))
+ {
+ form_driver(this->Form, REQ_NEXT_PAGE);
+ }
+ else
+ {
+ form_driver(this->Form, REQ_NEXT_FIELD);
+ }
+ }
+ // if not beginning of page, previous field, otherwise previous page
+ // each entry consists of fields: label, isnew, value
+ // therefore, the label field for the prev. entry is index-5
+ // and the label field for the next entry is index+1
+ // (index always corresponds to the value field)
+ else if ( key == KEY_UP || key == ctrl('p') )
+ {
+ FIELD* cur = current_field(this->Form);
+ int findex = field_index(cur);
+ if ( findex == 2 )
+ {
+ continue;
+ }
+ if ( new_page(this->Fields[findex-2]) )
+ {
+ form_driver(this->Form, REQ_PREV_PAGE);
+ set_current_field(this->Form, this->Fields[findex-3]);
+ }
+ else
+ {
+ form_driver(this->Form, REQ_PREV_FIELD);
+ }
+ }
+ // pg down
+ else if ( key == KEY_NPAGE || key == ctrl('d') )
+ {
+ form_driver(this->Form, REQ_NEXT_PAGE);
+ }
+ // pg up
+ else if ( key == KEY_PPAGE || key == ctrl('u') )
+ {
+ form_driver(this->Form, REQ_PREV_PAGE);
+ }
+ // configure
+ else if ( key == 'c' )
+ {
+ this->Configure();
+ }
+ // display help
+ else if ( key == 'h' )
+ {
+ getmaxyx(stdscr, y, x);
+
+ FIELD* cur = current_field(this->Form);
+ int findex = field_index(cur);
+ cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
+ this->Fields[findex-2]));
+ const char* curField = lbl->GetValue();
+ const char* helpString=0;
+ cmCacheManager::CacheIterator it =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
+ if (!it.IsAtEnd())
+ {
+ helpString = it.GetProperty("HELPSTRING");
+ }
+ if (helpString)
+ {
+ char* message = new char[strlen(curField)+strlen(helpString)
+ +strlen("Current option is: \n Help string for this option is: \n")+10];
+ sprintf(message,"Current option is: %s\nHelp string for this option is: %s\n", curField, helpString);
+ this->HelpMessage[1] = message;
+ delete[] message;
+ }
+ else
+ {
+ this->HelpMessage[1] = "";
+ }
+
+ cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(this->HelpMessage,
+ "Help.");
+ CurrentForm = msgs;
+ msgs->Render(1,1,x,y);
+ msgs->HandleInput();
+ CurrentForm = this;
+ this->Render(1,1,x,y);
+ set_current_field(this->Form, cur);
+ }
+ // display last errors
+ else if ( key == 'l' )
+ {
+ getmaxyx(stdscr, y, x);
+ cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(this->Errors,
+ "Errors occurred during the last pass.");
+ CurrentForm = msgs;
+ msgs->Render(1,1,x,y);
+ msgs->HandleInput();
+ CurrentForm = this;
+ this->Render(1,1,x,y);
+ }
+ else if ( key == '/' )
+ {
+ this->SearchMode = true;
+ this->UpdateStatusBar("Search");
+ this->PrintKeys(1);
+ touchwin(stdscr);
+ refresh();
+ }
+ else if ( key == 'n' )
+ {
+ if ( this->OldSearchString.size() > 0 )
+ {
+ this->JumpToCacheEntry(this->OldSearchString.c_str());
+ }
+ }
+ // switch advanced on/off
+ else if ( key == 't' )
+ {
+ if (this->AdvancedMode)
+ {
+ this->AdvancedMode = false;
+ }
+ else
+ {
+ this->AdvancedMode = true;
+ }
+ getmaxyx(stdscr, y, x);
+ this->RePost();
+ this->Render(1, 1, x, y);
+ }
+ // generate and exit
+ else if ( key == 'g' )
+ {
+ if ( this->OkToGenerate )
+ {
+ this->Generate();
+ break;
+ }
+ }
+ // delete cache entry
+ else if ( key == 'd' && this->NumberOfVisibleEntries )
+ {
+ this->OkToGenerate = false;
+ FIELD* cur = current_field(this->Form);
+ size_t findex = field_index(cur);
+
+ // make the next or prev. current field after deletion
+ // each entry consists of fields: label, isnew, value
+ // therefore, the label field for the prev. entry is findex-5
+ // and the label field for the next entry is findex+1
+ // (findex always corresponds to the value field)
+ FIELD* nextCur;
+ if ( findex == 2 )
+ {
+ nextCur=0;
+ }
+ else if ( findex == 3*this->NumberOfVisibleEntries-1 )
+ {
+ nextCur = this->Fields[findex-5];
+ }
+ else
+ {
+ nextCur = this->Fields[findex+1];
+ }
+
+ // Get the label widget
+ // each entry consists of fields: label, isnew, value
+ // therefore, the label field for the is findex-2
+ // (findex always corresponds to the value field)
+ cmCursesWidget* lbl
+ = reinterpret_cast<cmCursesWidget*>(
+ field_userptr(this->Fields[findex-2]));
+ if ( lbl )
+ {
+ this->CMakeInstance->GetCacheManager()->RemoveCacheEntry(lbl->GetValue());
+
+ std::string nextVal;
+ if (nextCur)
+ {
+ nextVal = (reinterpret_cast<cmCursesWidget*>(field_userptr(nextCur))->GetValue());
+ }
+
+ getmaxyx(stdscr, y, x);
+ this->RemoveEntry(lbl->GetValue());
+ this->RePost();
+ this->Render(1, 1, x, y);
+
+ if (nextCur)
+ {
+ // make the next or prev. current field after deletion
+ nextCur = 0;
+ std::vector<cmCursesCacheEntryComposite*>::iterator it;
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
+ {
+ if (nextVal == (*it)->Key)
+ {
+ nextCur = (*it)->Entry->Field;
+ }
+ }
+
+ if (nextCur)
+ {
+ set_current_field(this->Form, nextCur);
+ }
+ }
+ }
+ }
+ }
+
+ touchwin(stdscr);
+ wrefresh(stdscr);
+ }
+}
+
+int cmCursesMainForm::LoadCache(const char *)
+
+{
+ int r = this->CMakeInstance->LoadCache();
+ if(r < 0)
+ {
+ return r;
+ }
+ this->CMakeInstance->SetCacheArgs(this->Args);
+ this->CMakeInstance->PreLoadCMakeFiles();
+ return r;
+}
+
+void cmCursesMainForm::JumpToCacheEntry(const char* astr)
+{
+ std::string str;
+ if ( astr )
+ {
+ str = cmSystemTools::LowerCase(astr);
+ }
+
+ if(str.empty())
+ {
+ return;
+ }
+ FIELD* cur = current_field(this->Form);
+ int start_index = field_index(cur);
+ int findex = start_index;
+ for(;;)
+ {
+ if ( str.size() > 0 )
+ {
+ cmCursesWidget* lbl = 0;
+ if ( findex >= 0 )
+ {
+ lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(this->Fields[findex-2]));
+ }
+ if ( lbl )
+ {
+ const char* curField = lbl->GetValue();
+ if ( curField )
+ {
+ std::string cfld = cmSystemTools::LowerCase(curField);
+ if ( cfld.find(str) != cfld.npos && findex != start_index )
+ {
+ break;
+ }
+ }
+ }
+ }
+ if ( size_t(findex) >= 3* this->NumberOfVisibleEntries-1 )
+ {
+ set_current_field(this->Form, this->Fields[2]);
+ }
+ else if (new_page(this->Fields[findex+1]))
+ {
+ form_driver(this->Form, REQ_NEXT_PAGE);
+ }
+ else
+ {
+ form_driver(this->Form, REQ_NEXT_FIELD);
+ }
+ /*
+ char buffer[1024];
+ sprintf(buffer, "Line: %d != %d / %d\n", findex, idx, this->NumberOfVisibleEntries);
+ touchwin(stdscr);
+ refresh();
+ this->UpdateStatusBar( buffer );
+ usleep(100000);
+ */
+ cur = current_field(this->Form);
+ findex = field_index(cur);
+ if ( findex == start_index )
+ {
+ break;
+ }
+ }
+}
+
+
+const char* cmCursesMainForm::s_ConstHelpMessage =
+"CMake is used to configure and generate build files for software projects. "
+"The basic steps for configuring a project with ccmake are as follows:\n\n"
+"1. Run ccmake in the directory where you want the object and executable files to be placed (build directory). If the source directory is not the same as this build directory, you have to specify it as an argument on the command line.\n\n"
+"2. When ccmake is run, it will read the configuration files and display the current build options. "
+"If you have run CMake before and have updated the configuration files since then, any new entries will be displayed on top and will be marked with a *. "
+"On the other hand, the first time you run ccmake, all build options will be new and will be marked as such. "
+"At this point, you can modify any options (see keys below) you want to change. "
+"When you are satisfied with your changes, press 'c' to have CMake process the configuration files. "
+"Please note that changing some options may cause new ones to appear. These will be shown on top and will be marked with *. "
+"Repeat this procedure until you are satisfied with all the options and there are no new entries. "
+"At this point, a new command will appear: G)enerate and Exit. You can now hit 'g' to have CMake generate all the build files (i.e. makefiles or project files) and exit. "
+"At any point during the process, you can exit ccmake with 'q'. However, this will not generate/change any build files.\n\n"
+"ccmake KEYS:\n\n"
+"Navigation: "
+"You can use the arrow keys and page up, down to navigate the options. Alternatively, you can use the following keys: \n"
+" C-n : next option\n"
+" C-p : previous options\n"
+" C-d : down one page\n"
+" C-u : up one page\n\n"
+"Editing options: "
+"To change an option press enter or return. If the current options is a boolean, this will toggle it's value. "
+"Otherwise, ccmake will enter edit mode. In this mode you can edit an option using arrow keys and backspace. Alternatively, you can use the following keys:\n"
+" C-b : back one character\n"
+" C-f : forward one character\n"
+" C-a : go to the beginning of the field\n"
+" C-e : go to the end of the field\n"
+" C-d : delete previous character\n"
+" C-k : kill the rest of the field\n"
+" Esc : Restore field (discard last changes)\n"
+" Enter : Leave edit mode\n"
+"You can also delete an option by pressing 'd'\n\n"
+"Commands:\n"
+" q : quit ccmake without generating build files\n"
+" h : help, shows this screen\n"
+" c : process the configuration files with the current options\n"
+" g : generate build files and exit, only available when there are no "
+"new options and no errors have been detected during last configuration.\n"
+" l : shows last errors\n"
+" t : toggles advanced mode. In normal mode, only the most important options are shown. In advanced mode, all options are shown. We recommend using normal mode unless you are an expert.\n"
+" / : search for a variable name.\n";
diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h
new file mode 100644
index 0000000000..fba9bc50d1
--- /dev/null
+++ b/Source/CursesDialog/cmCursesMainForm.h
@@ -0,0 +1,164 @@
+/*============================================================================
+ 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 __cmCursesMainForm_h
+#define __cmCursesMainForm_h
+
+#include "../cmStandardIncludes.h"
+#include "cmCursesForm.h"
+#include "cmCursesStandardIncludes.h"
+
+class cmCursesCacheEntryComposite;
+class cmCursesWidget;
+class cmake;
+
+/** \class cmCursesMainForm
+ * \brief The main page of ccmake
+ *
+ * cmCursesMainForm is the main page of ccmake.
+ */
+class cmCursesMainForm : public cmCursesForm
+{
+public:
+ cmCursesMainForm(std::vector<std::string> const& args, int initwidth);
+ virtual ~cmCursesMainForm();
+
+ /**
+ * Set the widgets which represent the cache entries.
+ */
+ void InitializeUI();
+
+ /**
+ * Handle user input.
+ */
+ virtual void HandleInput();
+
+ /**
+ * Display form. Use a window of size width x height, starting
+ * at top, left.
+ */
+ virtual void Render(int left, int top, int width, int height);
+
+ /**
+ * Returns true if an entry with the given key is in the
+ * list of current composites.
+ */
+ bool LookForCacheEntry(const std::string& key);
+
+ enum {
+ MIN_WIDTH = 65,
+ MIN_HEIGHT = 6,
+ IDEAL_WIDTH = 80,
+ MAX_WIDTH = 512
+ };
+
+ /**
+ * This method should normally be called only by the form. The only
+ * exception is during a resize. The optional argument specifies the
+ * string to be displayed in the status bar.
+ */
+ virtual void UpdateStatusBar() { this->UpdateStatusBar(0); }
+ virtual void UpdateStatusBar(const char* message);
+
+ /**
+ * Display current commands and their keys on the toolbar. This
+ * method should normally called only by the form. The only
+ * exception is during a resize. If the optional argument process is
+ * specified and is either 1 (configure) or 2 (generate), then keys
+ * will be displayed accordingly.
+ */
+ void PrintKeys(int process = 0);
+
+ /**
+ * During a CMake run, an error handle should add errors
+ * to be displayed afterwards.
+ */
+ virtual void AddError(const char* message, const char* title);
+
+ /**
+ * Used to do a configure. If argument is specified, it does only the check
+ * and not configure.
+ */
+ int Configure(int noconfigure=0);
+
+ /**
+ * Used to generate
+ */
+ int Generate();
+
+ /**
+ * Used by main program
+ */
+ int LoadCache(const char *dir);
+
+ /**
+ * Progress callback
+ */
+ static void UpdateProgressOld(const char *msg, float prog, void*);
+ static void UpdateProgress(const char *msg, float prog, void*);
+
+protected:
+ cmCursesMainForm(const cmCursesMainForm& from);
+ void operator=(const cmCursesMainForm&);
+
+ // Copy the cache values from the user interface to the actual
+ // cache.
+ void FillCacheManagerFromUI();
+ // Fix formatting of values to a consistent form.
+ void FixValue(cmCacheManager::CacheEntryType type,
+ const std::string& in, std::string& out) const;
+ // Re-post the existing fields. Used to toggle between
+ // normal and advanced modes. Render() should be called
+ // afterwards.
+ void RePost();
+ // Remove an entry from the interface and the cache.
+ void RemoveEntry(const char* value);
+
+ // Jump to the cache entry whose name matches the string.
+ void JumpToCacheEntry(const char* str);
+
+ // Copies of cache entries stored in the user interface
+ std::vector<cmCursesCacheEntryComposite*>* Entries;
+ // Errors produced during last run of cmake
+ std::vector<std::string> Errors;
+ // Command line argumens to be passed to cmake each time
+ // it is run
+ std::vector<std::string> Args;
+ // Message displayed when user presses 'h'
+ // It is: Welcome + info about current entry + common help
+ std::vector<std::string> HelpMessage;
+
+ // Common help
+ static const char* s_ConstHelpMessage;
+
+ // Fields displayed. Includes labels, new entry markers, entries
+ FIELD** Fields;
+ // Where is source of current project
+ std::string WhereSource;
+ // Where is cmake executable
+ std::string WhereCMake;
+ // Number of entries shown (depends on mode -normal or advanced-)
+ size_t NumberOfVisibleEntries;
+ bool AdvancedMode;
+ // Did the iteration converge (no new entries) ?
+ bool OkToGenerate;
+ // Number of pages displayed
+ int NumberOfPages;
+
+ int InitialWidth;
+ cmake *CMakeInstance;
+
+ std::string SearchString;
+ std::string OldSearchString;
+ bool SearchMode;
+};
+
+#endif // __cmCursesMainForm_h
diff --git a/Source/CursesDialog/cmCursesOptionsWidget.cxx b/Source/CursesDialog/cmCursesOptionsWidget.cxx
new file mode 100644
index 0000000000..2f4b59e5b2
--- /dev/null
+++ b/Source/CursesDialog/cmCursesOptionsWidget.cxx
@@ -0,0 +1,105 @@
+/*============================================================================
+ 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 "cmCursesOptionsWidget.h"
+#include "cmCursesMainForm.h"
+
+inline int ctrl(int z)
+{
+ return (z&037);
+}
+
+cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height,
+ int left, int top) :
+ cmCursesWidget(width, height, left, top)
+{
+ this->Type = cmCacheManager::BOOL; // this is a bit of a hack
+ // there is no option type, and string type causes ccmake to cast
+ // the widget into a string widget at some point. BOOL is safe for
+ // now.
+ set_field_fore(this->Field, A_NORMAL);
+ set_field_back(this->Field, A_STANDOUT);
+ field_opts_off(this->Field, O_STATIC);
+}
+
+bool cmCursesOptionsWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* w)
+{
+
+ // 10 == enter
+ if (key == 10 || key == KEY_ENTER)
+ {
+ this->NextOption();
+ touchwin(w);
+ wrefresh(w);
+ return true;
+ }
+ else if (key == KEY_LEFT || key == ctrl('b'))
+ {
+ touchwin(w);
+ wrefresh(w);
+ this->PreviousOption();
+ return true;
+ }
+ else if (key == KEY_RIGHT || key == ctrl('f'))
+ {
+ this->NextOption();
+ touchwin(w);
+ wrefresh(w);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void cmCursesOptionsWidget::AddOption(std::string const & option )
+{
+ this->Options.push_back(option);
+}
+
+void cmCursesOptionsWidget::NextOption()
+{
+ this->CurrentOption++;
+ if(this->CurrentOption > this->Options.size()-1)
+ {
+ this->CurrentOption = 0;
+ }
+ this->SetValue(this->Options[this->CurrentOption]);
+}
+void cmCursesOptionsWidget::PreviousOption()
+{
+ if(this->CurrentOption == 0)
+ {
+ this->CurrentOption = this->Options.size()-1;
+ }
+ else
+ {
+ this->CurrentOption--;
+ }
+ this->SetValue(this->Options[this->CurrentOption]);
+}
+
+void cmCursesOptionsWidget::SetOption(const std::string& value)
+{
+ this->CurrentOption = 0; // default to 0 index
+ this->SetValue(value);
+ int index = 0;
+ for(std::vector<std::string>::iterator i = this->Options.begin();
+ i != this->Options.end(); ++i)
+ {
+ if(*i == value)
+ {
+ this->CurrentOption = index;
+ }
+ index++;
+ }
+}
diff --git a/Source/CursesDialog/cmCursesOptionsWidget.h b/Source/CursesDialog/cmCursesOptionsWidget.h
new file mode 100644
index 0000000000..5cee489b02
--- /dev/null
+++ b/Source/CursesDialog/cmCursesOptionsWidget.h
@@ -0,0 +1,39 @@
+/*============================================================================
+ 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 __cmCursesOptionsWidget_h
+#define __cmCursesOptionsWidget_h
+
+#include "cmCursesWidget.h"
+class cmCursesMainForm;
+
+class cmCursesOptionsWidget : public cmCursesWidget
+{
+public:
+ cmCursesOptionsWidget(int width, int height, int left, int top);
+
+ // Description:
+ // Handle user input. Called by the container of this widget
+ // when this widget has focus. Returns true if the input was
+ // handled.
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
+ void SetOption(const std::string&);
+ void AddOption(std::string const &);
+ void NextOption();
+ void PreviousOption();
+protected:
+ cmCursesOptionsWidget(const cmCursesOptionsWidget& from);
+ void operator=(const cmCursesOptionsWidget&);
+ std::vector<std::string> Options;
+ std::vector<std::string>::size_type CurrentOption;
+};
+
+#endif // __cmCursesOptionsWidget_h
diff --git a/Source/CursesDialog/cmCursesPathWidget.cxx b/Source/CursesDialog/cmCursesPathWidget.cxx
new file mode 100644
index 0000000000..cd93bc3c10
--- /dev/null
+++ b/Source/CursesDialog/cmCursesPathWidget.cxx
@@ -0,0 +1,94 @@
+/*============================================================================
+ 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 "cmCursesPathWidget.h"
+
+#include "cmCursesMainForm.h"
+#include "cmSystemTools.h"
+
+cmCursesPathWidget::cmCursesPathWidget(int width, int height,
+ int left, int top) :
+ cmCursesStringWidget(width, height, left, top)
+{
+ this->Type = cmCacheManager::PATH;
+ this->Cycle = false;
+ this->CurrentIndex = 0;
+}
+
+void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w)
+{
+ this->Cycle = false;
+ this->CurrentIndex = 0;
+ this->LastGlob = "";
+ this->cmCursesStringWidget::OnType(key, fm, w);
+}
+
+void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
+{
+ if ( !this->GetString() )
+ {
+ return;
+ }
+ FORM* form = fm->GetForm();
+ form_driver(form, REQ_NEXT_FIELD);
+ form_driver(form, REQ_PREV_FIELD);
+ std::string cstr = this->GetString();
+ cstr = cstr.substr(0, cstr.find_last_not_of(" \t\n\r")+1);
+ if ( this->LastString != cstr )
+ {
+ this->Cycle = false;
+ this->CurrentIndex = 0;
+ this->LastGlob = "";
+ }
+ std::string glob;
+ if ( this->Cycle )
+ {
+ glob = this->LastGlob;
+ }
+ else
+ {
+ glob = cstr + "*";
+ }
+ std::vector<std::string> dirs;
+
+ cmSystemTools::SimpleGlob(glob, dirs, (this->Type == cmCacheManager::PATH?-1:0));
+ if ( this->CurrentIndex < dirs.size() )
+ {
+ cstr = dirs[this->CurrentIndex];
+ }
+ if ( cstr[cstr.size()-1] == '*' )
+ {
+ cstr = cstr.substr(0, cstr.size()-1);
+ }
+
+ if ( cmSystemTools::FileIsDirectory(cstr.c_str()) )
+ {
+ cstr += "/";
+ }
+
+ this->SetString(cstr);
+ touchwin(w);
+ wrefresh(w);
+ form_driver(form, REQ_END_FIELD);
+ this->LastGlob = glob;
+ this->LastString = cstr;
+ this->Cycle = true;
+ this->CurrentIndex ++;
+ if ( this->CurrentIndex >= dirs.size() )
+ {
+ this->CurrentIndex = 0;
+ }
+}
+
+void cmCursesPathWidget::OnReturn(cmCursesMainForm* fm, WINDOW* w)
+{
+ this->cmCursesStringWidget::OnReturn(fm, w);
+}
diff --git a/Source/CursesDialog/cmCursesPathWidget.h b/Source/CursesDialog/cmCursesPathWidget.h
new file mode 100644
index 0000000000..45c22a3920
--- /dev/null
+++ b/Source/CursesDialog/cmCursesPathWidget.h
@@ -0,0 +1,40 @@
+/*============================================================================
+ 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 __cmCursesPathWidget_h
+#define __cmCursesPathWidget_h
+
+#include "cmCursesStringWidget.h"
+
+class cmCursesPathWidget : public cmCursesStringWidget
+{
+public:
+ cmCursesPathWidget(int width, int height, int left, int top);
+
+ /**
+ * This method is called when different keys are pressed. The
+ * subclass can have a special implementation handler for this.
+ */
+ virtual void OnTab(cmCursesMainForm* fm, WINDOW* w);
+ virtual void OnReturn(cmCursesMainForm* fm, WINDOW* w);
+ virtual void OnType(int& key, cmCursesMainForm* fm, WINDOW* w);
+
+protected:
+ cmCursesPathWidget(const cmCursesPathWidget& from);
+ void operator=(const cmCursesPathWidget&);
+
+ std::string LastString;
+ std::string LastGlob;
+ bool Cycle;
+ std::string::size_type CurrentIndex;
+};
+
+#endif // __cmCursesPathWidget_h
diff --git a/Source/CursesDialog/cmCursesStandardIncludes.h b/Source/CursesDialog/cmCursesStandardIncludes.h
new file mode 100644
index 0000000000..b157a289b5
--- /dev/null
+++ b/Source/CursesDialog/cmCursesStandardIncludes.h
@@ -0,0 +1,83 @@
+/*============================================================================
+ 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 cmCursesStandardIncludes_h
+#define cmCursesStandardIncludes_h
+#if defined(__sun__) && defined(__GNUC__)
+ #define _MSE_INT_H
+#endif
+
+#include <cmFormConfigure.h>
+
+#if defined(__hpux)
+# define _BOOL_DEFINED
+# include <sys/time.h>
+# define _XOPEN_SOURCE_EXTENDED
+# include <curses.h>
+# include <form.h>
+# undef _XOPEN_SOURCE_EXTENDED
+#else
+/* figure out which curses.h to include */
+# if defined(CURSES_HAVE_NCURSES_H)
+# include <ncurses.h>
+# elif defined(CURSES_HAVE_NCURSES_NCURSES_H)
+# include <ncurses/ncurses.h>
+# elif defined(CURSES_HAVE_NCURSES_CURSES_H)
+# include <ncurses/curses.h>
+# else
+# include <curses.h>
+# endif
+
+# include <form.h>
+#endif
+
+// This is a hack to prevent warnings about these functions being
+// declared but not referenced.
+#if defined(__sgi) && !defined(__GNUC__)
+class cmCursesStandardIncludesHack
+{
+public:
+ enum
+ {
+ Ref1 = sizeof(cfgetospeed(0)),
+ Ref2 = sizeof(cfgetispeed(0)),
+ Ref3 = sizeof(tcgetattr(0, 0)),
+ Ref4 = sizeof(tcsetattr(0, 0, 0)),
+ Ref5 = sizeof(cfsetospeed(0,0)),
+ Ref6 = sizeof(cfsetispeed(0,0))
+ };
+};
+#endif
+
+#ifndef getmaxyx
+ #define getmaxyx(w,y,x) ((y) = getmaxy(w), (x) = getmaxx(w))
+#endif
+
+
+// on some machines move erase and clear conflict with stl
+// so remove them from the namespace
+inline void curses_move(unsigned int x, unsigned int y)
+{
+ move(x,y);
+}
+
+inline void curses_clear()
+{
+ erase();
+ clearok(stdscr, TRUE);
+}
+
+#undef move
+#undef erase
+#undef clear
+
+
+#endif // cmCursesStandardIncludes_h
diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx
new file mode 100644
index 0000000000..d25022d59e
--- /dev/null
+++ b/Source/CursesDialog/cmCursesStringWidget.cxx
@@ -0,0 +1,249 @@
+/*============================================================================
+ 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 "cmCursesStringWidget.h"
+#include "cmCursesMainForm.h"
+
+inline int ctrl(int z)
+{
+ return (z&037);
+}
+
+cmCursesStringWidget::cmCursesStringWidget(int width, int height,
+ int left, int top) :
+ cmCursesWidget(width, height, left, top)
+{
+ this->InEdit = false;
+ this->Type = cmCacheManager::STRING;
+ set_field_fore(this->Field, A_NORMAL);
+ set_field_back(this->Field, A_STANDOUT);
+ field_opts_off(this->Field, O_STATIC);
+}
+
+void cmCursesStringWidget::OnTab(cmCursesMainForm*, WINDOW*)
+{
+ //FORM* form = fm->GetForm();
+}
+
+void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW*)
+{
+ FORM* form = fm->GetForm();
+ if (this->InEdit)
+ {
+ cmCursesForm::LogMessage("String widget leaving edit.");
+ this->InEdit = false;
+ fm->PrintKeys();
+ delete[] this->OriginalString;
+ // trick to force forms to update the field buffer
+ form_driver(form, REQ_NEXT_FIELD);
+ form_driver(form, REQ_PREV_FIELD);
+ this->Done = true;
+ }
+ else
+ {
+ cmCursesForm::LogMessage("String widget entering edit.");
+ this->InEdit = true;
+ fm->PrintKeys();
+ char* buf = field_buffer(this->Field, 0);
+ this->OriginalString = new char[strlen(buf)+1];
+ strcpy(this->OriginalString, buf);
+ }
+}
+
+void cmCursesStringWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW*)
+{
+ form_driver(fm->GetForm(), key);
+}
+
+bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
+ WINDOW* w)
+{
+ int x,y;
+
+ FORM* form = fm->GetForm();
+ // 10 == enter
+ if (!this->InEdit && ( key != 10 && key != KEY_ENTER ) )
+ {
+ return false;
+ }
+
+ this->OriginalString=0;
+ this->Done = false;
+
+ char debugMessage[128];
+
+ // <Enter> is used to change edit mode (like <Esc> in vi).
+ while(!this->Done)
+ {
+ sprintf(debugMessage, "String widget handling input, key: %d", key);
+ cmCursesForm::LogMessage(debugMessage);
+
+ fm->PrintKeys();
+
+ getmaxyx(stdscr, y, x);
+ // If window too small, handle 'q' only
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ // quit
+ if ( key == 'q' )
+ {
+ return false;
+ }
+ else
+ {
+ key=getch();
+ continue;
+ }
+ }
+
+ // If resize occured during edit, move out of edit mode
+ if (!this->InEdit && ( key != 10 && key != KEY_ENTER ) )
+ {
+ return false;
+ }
+ // 10 == enter
+ if (key == 10 || key == KEY_ENTER)
+ {
+ this->OnReturn(fm, w);
+ }
+ else if ( key == KEY_DOWN || key == ctrl('n') ||
+ key == KEY_UP || key == ctrl('p') ||
+ key == KEY_NPAGE || key == ctrl('d') ||
+ key == KEY_PPAGE || key == ctrl('u'))
+ {
+ this->InEdit = false;
+ delete[] this->OriginalString;
+ // trick to force forms to update the field buffer
+ form_driver(form, REQ_NEXT_FIELD);
+ form_driver(form, REQ_PREV_FIELD);
+ return false;
+ }
+ // esc
+ else if (key == 27)
+ {
+ if (this->InEdit)
+ {
+ this->InEdit = false;
+ fm->PrintKeys();
+ this->SetString(this->OriginalString);
+ delete[] this->OriginalString;
+ touchwin(w);
+ wrefresh(w);
+ return true;
+ }
+ }
+ else if ( key == 9 )
+ {
+ this->OnTab(fm, w);
+ }
+ else if ( key == KEY_LEFT || key == ctrl('b') )
+ {
+ form_driver(form, REQ_PREV_CHAR);
+ }
+ else if ( key == KEY_RIGHT || key == ctrl('f') )
+ {
+ form_driver(form, REQ_NEXT_CHAR);
+ }
+ else if ( key == ctrl('k') )
+ {
+ form_driver(form, REQ_CLR_EOL);
+ }
+ else if ( key == ctrl('a') || key == KEY_HOME )
+ {
+ form_driver(form, REQ_BEG_FIELD);
+ }
+ else if ( key == ctrl('e') || key == KEY_END )
+ {
+ form_driver(form, REQ_END_FIELD);
+ }
+ else if ( key == 127 ||
+ key == KEY_BACKSPACE )
+ {
+ if ( form->curcol > 0 )
+ {
+ form_driver(form, REQ_DEL_PREV);
+ }
+ }
+ else if ( key == ctrl('d') ||key == KEY_DC )
+ {
+ if ( form->curcol >= 0 )
+ {
+ form_driver(form, REQ_DEL_CHAR);
+ }
+ }
+ else
+ {
+ this->OnType(key, fm, w);
+ }
+ if ( !this->Done )
+ {
+ touchwin(w);
+ wrefresh(w);
+
+ key=getch();
+ }
+ }
+ return true;
+}
+
+void cmCursesStringWidget::SetString(const std::string& value)
+{
+ this->SetValue(value);
+}
+
+const char* cmCursesStringWidget::GetString()
+{
+ return this->GetValue();
+}
+
+const char* cmCursesStringWidget::GetValue()
+{
+ return field_buffer(this->Field, 0);
+}
+
+bool cmCursesStringWidget::PrintKeys()
+{
+ int x,y;
+ getmaxyx(stdscr, y, x);
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ return false;
+ }
+ if (this->InEdit)
+ {
+ char firstLine[512];
+ // Clean the toolbar
+ for(int i=0; i<512; i++)
+ {
+ firstLine[i] = ' ';
+ }
+ firstLine[511] = '\0';
+ curses_move(y-4,0);
+ printw(firstLine);
+ curses_move(y-3,0);
+ printw(firstLine);
+ curses_move(y-2,0);
+ printw(firstLine);
+ curses_move(y-1,0);
+ printw(firstLine);
+
+ sprintf(firstLine, "Editing option, press [enter] to leave edit.");
+ curses_move(y-3,0);
+ printw(firstLine);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
diff --git a/Source/CursesDialog/cmCursesStringWidget.h b/Source/CursesDialog/cmCursesStringWidget.h
new file mode 100644
index 0000000000..dd8c02a32b
--- /dev/null
+++ b/Source/CursesDialog/cmCursesStringWidget.h
@@ -0,0 +1,76 @@
+/*============================================================================
+ 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 __cmCursesStringWidget_h
+#define __cmCursesStringWidget_h
+
+#include "cmCursesWidget.h"
+
+class cmCursesMainForm;
+
+/** \class cmCursesStringWidget
+ * \brief A simple entry widget.
+ *
+ * cmCursesStringWdiget is a simple text entry widget.
+ */
+
+class cmCursesStringWidget : public cmCursesWidget
+{
+public:
+ cmCursesStringWidget(int width, int height, int left, int top);
+
+ /**
+ * Handle user input. Called by the container of this widget
+ * when this widget has focus. Returns true if the input was
+ * handled.
+ */
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
+
+ /**
+ * Set/Get the string.
+ */
+ void SetString(const std::string& value);
+ const char* GetString();
+ virtual const char* GetValue();
+
+ /**
+ * Set/Get InEdit flag. Can be used to tell the widget to leave
+ * edit mode (in case of a resize for example).
+ */
+ void SetInEdit(bool inedit) { this->InEdit = inedit; }
+ bool GetInEdit() { return this->InEdit; }
+
+ /**
+ * This method is called when different keys are pressed. The
+ * subclass can have a special implementation handler for this.
+ */
+ virtual void OnTab(cmCursesMainForm* fm, WINDOW* w);
+ virtual void OnReturn(cmCursesMainForm* fm, WINDOW* w);
+ virtual void OnType(int& key, cmCursesMainForm* fm, WINDOW* w);
+
+ /**
+ * If there are any, print the widget specific commands
+ * in the toolbar and return true. Otherwise, return false
+ * and the parent widget will print.
+ */
+ virtual bool PrintKeys();
+
+protected:
+ cmCursesStringWidget(const cmCursesStringWidget& from);
+ void operator=(const cmCursesStringWidget&);
+
+ // true if the widget is in edit mode
+ bool InEdit;
+ char* OriginalString;
+ bool Done;
+};
+
+#endif // __cmCursesStringWidget_h
diff --git a/Source/CursesDialog/cmCursesWidget.cxx b/Source/CursesDialog/cmCursesWidget.cxx
new file mode 100644
index 0000000000..e5363f4890
--- /dev/null
+++ b/Source/CursesDialog/cmCursesWidget.cxx
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 "cmCursesWidget.h"
+
+cmCursesWidget::cmCursesWidget(int width, int height, int left, int top)
+{
+ this->Field = new_field(height, width, top, left, 0, 0);
+ set_field_userptr(this->Field, reinterpret_cast<char*>(this));
+ field_opts_off(this->Field, O_AUTOSKIP);
+ this->Page = 0;
+}
+
+cmCursesWidget::~cmCursesWidget()
+{
+ if (this->Field)
+ {
+ free_field(this->Field);
+ this->Field = 0;
+ }
+}
+
+void cmCursesWidget::Move(int x, int y, bool isNewPage)
+{
+ if (!this->Field)
+ {
+ return;
+ }
+
+ move_field(this->Field, y, x);
+ if (isNewPage)
+ {
+ set_new_page(this->Field, TRUE);
+ }
+ else
+ {
+ set_new_page(this->Field, FALSE);
+ }
+}
+
+void cmCursesWidget::SetValue(const std::string& value)
+{
+ this->Value = value;
+ set_field_buffer(this->Field, 0, value.c_str());
+}
+
+const char* cmCursesWidget::GetValue()
+{
+ return this->Value.c_str();
+}
diff --git a/Source/CursesDialog/cmCursesWidget.h b/Source/CursesDialog/cmCursesWidget.h
new file mode 100644
index 0000000000..d91a0cb5f9
--- /dev/null
+++ b/Source/CursesDialog/cmCursesWidget.h
@@ -0,0 +1,87 @@
+/*============================================================================
+ 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 __cmCursesWidget_h
+#define __cmCursesWidget_h
+
+#include "../cmCacheManager.h"
+#include "cmCursesStandardIncludes.h"
+
+class cmCursesMainForm;
+
+class cmCursesWidget
+{
+public:
+ cmCursesWidget(int width, int height, int left, int top);
+ virtual ~cmCursesWidget();
+
+ /**
+ * Handle user input. Called by the container of this widget
+ * when this widget has focus. Returns true if the input was
+ * handled
+ */
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) = 0;
+
+ /**
+ * Change the position of the widget. Set isNewPage to true
+ * if this widget marks the beginning of a new page.
+ */
+ virtual void Move(int x, int y, bool isNewPage);
+
+ /**
+ * Set/Get the value (setting the value also changes the contents
+ * of the field buffer).
+ */
+ virtual void SetValue(const std::string& value);
+ virtual const char* GetValue();
+
+ /**
+ * Get the type of the widget (STRING, PATH etc...)
+ */
+ cmCacheManager::CacheEntryType GetType()
+ { return this->Type; }
+
+ /**
+ * If there are any, print the widget specific commands
+ * in the toolbar and return true. Otherwise, return false
+ * and the parent widget will print.
+ */
+ virtual bool PrintKeys()
+ {
+ return false;
+ }
+
+ /**
+ * Set/Get the page this widget is in.
+ */
+ void SetPage(int page)
+ {
+ this->Page = page;
+ }
+ int GetPage()
+ {
+ return this->Page;
+ }
+
+ friend class cmCursesMainForm;
+
+protected:
+ cmCursesWidget(const cmCursesWidget& from);
+ void operator=(const cmCursesWidget&);
+
+ cmCacheManager::CacheEntryType Type;
+ std::string Value;
+ FIELD* Field;
+ // The page in the main form this widget is in
+ int Page;
+};
+
+#endif // __cmCursesWidget_h
diff --git a/Source/CursesDialog/form/.NoDartCoverage b/Source/CursesDialog/form/.NoDartCoverage
new file mode 100644
index 0000000000..3c99729386
--- /dev/null
+++ b/Source/CursesDialog/form/.NoDartCoverage
@@ -0,0 +1 @@
+# do not do coverage in this directory
diff --git a/Source/CursesDialog/form/CMakeLists.txt b/Source/CursesDialog/form/CMakeLists.txt
new file mode 100644
index 0000000000..4e07fa0ff7
--- /dev/null
+++ b/Source/CursesDialog/form/CMakeLists.txt
@@ -0,0 +1,66 @@
+#=============================================================================
+# 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.
+#=============================================================================
+project(CMAKE_FORM)
+
+include_regular_expression("^.*$")
+include_directories(${CURSES_INCLUDE_PATH} "${CMAKE_CURRENT_BINARY_DIR}")
+
+configure_file(cmFormConfigure.h.in "${CMAKE_CURRENT_BINARY_DIR}/cmFormConfigure.h")
+
+set( FORM_SRCS
+ fld_arg.c
+ fld_attr.c
+ fld_current.c
+ fld_def.c
+ fld_dup.c
+ fld_ftchoice.c
+ fld_ftlink.c
+ fld_info.c
+ fld_just.c
+ fld_link.c
+ fld_max.c
+ fld_move.c
+ fld_newftyp.c
+ fld_opts.c
+ fld_pad.c
+ fld_page.c
+ fld_stat.c
+ fld_type.c
+ fld_user.c
+ frm_cursor.c
+ frm_data.c
+ frm_def.c
+ frm_driver.c
+ frm_hook.c
+ frm_opts.c
+ frm_page.c
+ frm_post.c
+ frm_req_name.c
+ frm_scale.c
+ frm_sub.c
+ frm_user.c
+ frm_win.c
+ fty_alnum.c
+ fty_alpha.c
+ fty_enum.c
+ fty_int.c
+ fty_ipv4.c
+ fty_num.c
+ fty_regex.c
+ )
+
+include_directories(${CMAKE_FORM_SOURCE_DIR})
+add_library(cmForm ${FORM_SRCS} )
+target_link_libraries(cmForm ${CURSES_LIBRARY})
+if(CURSES_EXTRA_LIBRARY)
+ target_link_libraries(cmForm ${CURSES_EXTRA_LIBRARY})
+endif()
diff --git a/Source/CursesDialog/form/READ.ME b/Source/CursesDialog/form/READ.ME
new file mode 100644
index 0000000000..dd91693f6b
--- /dev/null
+++ b/Source/CursesDialog/form/READ.ME
@@ -0,0 +1,15 @@
+This is a clone of the form library that is available with typical
+System V curses implementations (ETI).
+
+It is modelled after the documentation that comes for this library with
+a 386 based SVR4 implementation (ESIX).
+
+The development environment was and is an ELF based Linux system.
+
+For things that still need doing, see the TO-DO file in the top-level
+directory.
+
+Juergen Pfeifer
+
+eMail: juergen.pfeifer@gmx.net
+
diff --git a/Source/CursesDialog/form/cmFormConfigure.h.in b/Source/CursesDialog/form/cmFormConfigure.h.in
new file mode 100644
index 0000000000..a43169d038
--- /dev/null
+++ b/Source/CursesDialog/form/cmFormConfigure.h.in
@@ -0,0 +1,21 @@
+/*============================================================================
+ 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 CMFORMCONFIGURE_H
+#define CMFORMCONFIGURE_H
+
+#cmakedefine CURSES_HAVE_CURSES_H
+#cmakedefine CURSES_HAVE_NCURSES_H
+#cmakedefine CURSES_HAVE_NCURSES_NCURSES_H
+#cmakedefine CURSES_HAVE_NCURSES_CURSES_H
+
+#endif
diff --git a/Source/CursesDialog/form/eti.h b/Source/CursesDialog/form/eti.h
new file mode 100644
index 0000000000..cc1c8308a9
--- /dev/null
+++ b/Source/CursesDialog/form/eti.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#ifndef _ETI_ERRNO_H_
+#define _ETI_ERRNO_H_
+
+#define E_OK (0)
+#define E_SYSTEM_ERROR (-1)
+#define E_BAD_ARGUMENT (-2)
+#define E_POSTED (-3)
+#define E_CONNECTED (-4)
+#define E_BAD_STATE (-5)
+#define E_NO_ROOM (-6)
+#define E_NOT_POSTED (-7)
+#define E_UNKNOWN_COMMAND (-8)
+#define E_NO_MATCH (-9)
+#define E_NOT_SELECTABLE (-10)
+#define E_NOT_CONNECTED (-11)
+#define E_REQUEST_DENIED (-12)
+#define E_INVALID_FIELD (-13)
+#define E_CURRENT (-14)
+
+#endif
diff --git a/Source/CursesDialog/form/fld_arg.c b/Source/CursesDialog/form/fld_arg.c
new file mode 100644
index 0000000000..91ad79f1a4
--- /dev/null
+++ b/Source/CursesDialog/form/fld_arg.c
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_fieldtype_arg(
+| FIELDTYPE *typ,
+| void * (* const make_arg)(va_list *),
+| void * (* const copy_arg)(const void *),
+| void (* const free_arg)(void *) )
+|
+| Description : Connects to the type additional arguments necessary
+| for a set_field_type call. The various function pointer
+| arguments are:
+| make_arg : allocates a structure for the field
+| specific parameters.
+| copy_arg : duplicate the structure created by
+| make_arg
+| free_arg : Release the memory allocated by make_arg
+| or copy_arg
+|
+| At least make_arg must be non-NULL.
+| You may pass NULL for copy_arg and free_arg if your
+| make_arg function doesn't allocate memory and your
+| arg fits into the storage for a (void*).
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid argument
++--------------------------------------------------------------------------*/
+int set_fieldtype_arg(FIELDTYPE * typ,
+ void * (* const make_arg)(va_list *),
+ void * (* const copy_arg)(const void *),
+ void (* const free_arg)(void *))
+{
+ if ( !typ || !make_arg )
+ RETURN(E_BAD_ARGUMENT);
+
+ typ->status |= _HAS_ARGS;
+ typ->makearg = make_arg;
+ typ->copyarg = copy_arg;
+ typ->freearg = free_arg;
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : void *field_arg(const FIELD *field)
+|
+| Description : Retrieve pointer to the fields argument structure.
+|
+| Return Values : Pointer to structure or NULL if none is defined.
++--------------------------------------------------------------------------*/
+void *field_arg(const FIELD * field)
+{
+ return Normalize_Field(field)->arg;
+}
+
+/* fld_arg.c ends here */
diff --git a/Source/CursesDialog/form/fld_attr.c b/Source/CursesDialog/form/fld_attr.c
new file mode 100644
index 0000000000..86195882b3
--- /dev/null
+++ b/Source/CursesDialog/form/fld_attr.c
@@ -0,0 +1,116 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+#if defined(__hpux)
+ #define _XOPEN_SOURCE_EXTENDED
+#endif
+ #include "form.priv.h"
+#if defined(__hpux)
+ #undef _XOPEN_SOURCE_EXTENDED
+#endif
+MODULE_ID("$Id$")
+
+/*----------------------------------------------------------------------------
+ Field-Attribute manipulation routines
+ --------------------------------------------------------------------------*/
+/* "Template" macro to generate a function to set a fields attribute */
+#define GEN_FIELD_ATTR_SET_FCT( name ) \
+int set_field_ ## name (FIELD * field, chtype attr)\
+{\
+ int res = E_BAD_ARGUMENT;\
+ if ( attr==A_NORMAL || ((attr & A_ATTRIBUTES)==attr) )\
+ {\
+ Normalize_Field( field );\
+ if ((field -> name) != attr)\
+ {\
+ field -> name = attr;\
+ res = _nc_Synchronize_Attributes( field );\
+ }\
+ else\
+ res = E_OK;\
+ }\
+ RETURN(res);\
+}
+
+/* "Template" macro to generate a function to get a fields attribute */
+#define GEN_FIELD_ATTR_GET_FCT( name ) \
+chtype field_ ## name (const FIELD * field)\
+{\
+ return ( A_ATTRIBUTES & (Normalize_Field( field ) -> name) );\
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_fore(FIELD *field, chtype attr)
+|
+| Description : Sets the foreground of the field used to display the
+| field contents.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid attributes
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+GEN_FIELD_ATTR_SET_FCT( fore )
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : chtype field_fore(const FIELD *)
+|
+| Description : Retrieve fields foreground attribute
+|
+| Return Values : The foreground attribute
++--------------------------------------------------------------------------*/
+GEN_FIELD_ATTR_GET_FCT( fore )
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_back(FIELD *field, chtype attr)
+|
+| Description : Sets the background of the field used to display the
+| fields extend.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid attributes
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+GEN_FIELD_ATTR_SET_FCT( back )
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : chtype field_back(const
+|
+| Description : Retrieve fields background attribute
+|
+| Return Values : The background attribute
++--------------------------------------------------------------------------*/
+GEN_FIELD_ATTR_GET_FCT( back )
+
+/* fld_attr.c ends here */
diff --git a/Source/CursesDialog/form/fld_current.c b/Source/CursesDialog/form/fld_current.c
new file mode 100644
index 0000000000..d4b1254f74
--- /dev/null
+++ b/Source/CursesDialog/form/fld_current.c
@@ -0,0 +1,124 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_current_field(FORM * form,FIELD * field)
+|
+| Description : Set the current field of the form to the specified one.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid form or field pointer
+| E_REQUEST_DENIED - field not selectable
+| E_BAD_STATE - called from a hook routine
+| E_INVALID_FIELD - current field can't be left
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+int set_current_field(FORM * form, FIELD * field)
+{
+ int err = E_OK;
+
+ if ( !form || !field )
+ RETURN(E_BAD_ARGUMENT);
+
+ if ( (form != field->form) || Field_Is_Not_Selectable(field) )
+ RETURN(E_REQUEST_DENIED);
+
+ if (!(form->status & _POSTED))
+ {
+ form->current = field;
+ form->curpage = field->page;
+ }
+ else
+ {
+ if (form->status & _IN_DRIVER)
+ err = E_BAD_STATE;
+ else
+ {
+ if (form->current != field)
+ {
+ if (!_nc_Internal_Validation(form))
+ err = E_INVALID_FIELD;
+ else
+ {
+ Call_Hook(form,fieldterm);
+ if (field->page != form->curpage)
+ {
+ Call_Hook(form,formterm);
+ err = _nc_Set_Form_Page(form,field->page,field);
+ Call_Hook(form,forminit);
+ }
+ else
+ {
+ err = _nc_Set_Current_Field(form,field);
+ }
+ Call_Hook(form,fieldinit);
+ _nc_Refresh_Current_Field(form);
+ }
+ }
+ }
+ }
+ RETURN(err);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FIELD *current_field(const FORM * form)
+|
+| Description : Return the current field.
+|
+| Return Values : Pointer to the current field.
++--------------------------------------------------------------------------*/
+FIELD *current_field(const FORM * form)
+{
+ return Normalize_Form(form)->current;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int field_index(const FIELD * field)
+|
+| Description : Return the index of the field in the field-array of
+| the form.
+|
+| Return Values : >= 0 : field index
+| -1 : fieldpointer invalid or field not connected
++--------------------------------------------------------------------------*/
+int field_index(const FIELD * field)
+{
+ return ( (field && field->form) ? field->index : -1 );
+}
+
+/* fld_current.c ends here */
diff --git a/Source/CursesDialog/form/fld_def.c b/Source/CursesDialog/form/fld_def.c
new file mode 100644
index 0000000000..4a49a25586
--- /dev/null
+++ b/Source/CursesDialog/form/fld_def.c
@@ -0,0 +1,346 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/* this can't be readonly */
+static FIELD default_field = {
+ 0, /* status */
+ 0, /* rows */
+ 0, /* cols */
+ 0, /* frow */
+ 0, /* fcol */
+ 0, /* drows */
+ 0, /* dcols */
+ 0, /* maxgrow*/
+ 0, /* nrow */
+ 0, /* nbuf */
+ NO_JUSTIFICATION, /* just */
+ 0, /* page */
+ 0, /* index */
+ (int)' ', /* pad */
+ A_NORMAL, /* fore */
+ A_NORMAL, /* back */
+ ALL_FIELD_OPTS, /* opts */
+ (FIELD *)0, /* snext */
+ (FIELD *)0, /* sprev */
+ (FIELD *)0, /* link */
+ (FORM *)0, /* form */
+ (FIELDTYPE *)0, /* type */
+ (char *)0, /* arg */
+ (char *)0, /* buf */
+ (char *)0 /* usrptr */
+};
+
+FIELD *_nc_Default_Field = &default_field;
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : TypeArgument *_nc_Make_Argument(
+| const FIELDTYPE *typ,
+| va_list *ap,
+| int *err )
+|
+| Description : Create an argument structure for the specified type.
+| Use the type-dependant argument list to construct
+| it.
+|
+| Return Values : Pointer to argument structure. Maybe NULL.
+| In case of an error in *err an errorcounter is increased.
++--------------------------------------------------------------------------*/
+TypeArgument*
+_nc_Make_Argument(const FIELDTYPE *typ, va_list *ap, int *err)
+{
+ TypeArgument *res = (TypeArgument *)0;
+ TypeArgument *p;
+
+ if (typ && (typ->status & _HAS_ARGS))
+ {
+ assert(err && ap);
+ if (typ->status & _LINKED_TYPE)
+ {
+ p = (TypeArgument *)malloc(sizeof(TypeArgument));
+ if (p)
+ {
+ p->left = _nc_Make_Argument(typ->left ,ap,err);
+ p->right = _nc_Make_Argument(typ->right,ap,err);
+ return p;
+ }
+ else
+ *err += 1;
+ } else
+ {
+ assert(typ->makearg != 0);
+ if ( !(res=(TypeArgument *)typ->makearg(ap)) )
+ *err += 1;
+ }
+ }
+ return res;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : TypeArgument *_nc_Copy_Argument(const FIELDTYPE *typ,
+| const TypeArgument *argp,
+| int *err )
+|
+| Description : Create a copy of an argument structure for the specified
+| type.
+|
+| Return Values : Pointer to argument structure. Maybe NULL.
+| In case of an error in *err an errorcounter is increased.
++--------------------------------------------------------------------------*/
+TypeArgument*
+_nc_Copy_Argument(const FIELDTYPE *typ,
+ const TypeArgument *argp, int *err)
+{
+ TypeArgument *res = (TypeArgument *)0;
+ TypeArgument *p;
+
+ if ( typ && (typ->status & _HAS_ARGS) )
+ {
+ assert(err && argp);
+ if (typ->status & _LINKED_TYPE)
+ {
+ p = (TypeArgument *)malloc(sizeof(TypeArgument));
+ if (p)
+ {
+ p->left = _nc_Copy_Argument(typ,argp->left ,err);
+ p->right = _nc_Copy_Argument(typ,argp->right,err);
+ return p;
+ }
+ *err += 1;
+ }
+ else
+ {
+ if (typ->copyarg)
+ {
+ if (!(res = (TypeArgument *)(typ->copyarg((const void *)argp))))
+ *err += 1;
+ }
+ else
+ res = (TypeArgument *)argp;
+ }
+ }
+ return res;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : void _nc_Free_Argument(const FIELDTYPE *typ,
+| TypeArgument * argp )
+|
+| Description : Release memory associated with the argument structure
+| for the given fieldtype.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+void
+_nc_Free_Argument(const FIELDTYPE * typ, TypeArgument * argp)
+{
+ if (!typ || !(typ->status & _HAS_ARGS))
+ return;
+
+ if (typ->status & _LINKED_TYPE)
+ {
+ assert(argp != 0);
+ _nc_Free_Argument(typ->left ,argp->left );
+ _nc_Free_Argument(typ->right,argp->right);
+ free(argp);
+ }
+ else
+ {
+ if (typ->freearg)
+ typ->freearg((void *)argp);
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : bool _nc_Copy_Type( FIELD *dst, FIELD const *src )
+|
+| Description : Copy argument structure of field src to field dst
+|
+| Return Values : TRUE - copy worked
+| FALSE - error occured
++--------------------------------------------------------------------------*/
+bool
+_nc_Copy_Type(FIELD *dst, FIELD const *src)
+{
+ int err = 0;
+
+ assert(dst && src);
+
+ dst->type = src->type;
+ dst->arg = (void *)_nc_Copy_Argument(src->type,(TypeArgument *)(src->arg),&err);
+
+ if (err)
+ {
+ _nc_Free_Argument(dst->type,(TypeArgument *)(dst->arg));
+ dst->type = (FIELDTYPE *)0;
+ dst->arg = (void *)0;
+ return FALSE;
+ }
+ else
+ {
+ if (dst->type)
+ dst->type->ref++;
+ return TRUE;
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : void _nc_Free_Type( FIELD *field )
+|
+| Description : Release Argument structure for this field
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+void
+_nc_Free_Type(FIELD *field)
+{
+ assert(field != 0);
+ if (field->type)
+ field->type->ref--;
+ _nc_Free_Argument(field->type,(TypeArgument *)(field->arg));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FIELD *new_field( int rows, int cols,
+| int frow, int fcol,
+| int nrow, int nbuf )
+|
+| Description : Create a new field with this many 'rows' and 'cols',
+| starting at 'frow/fcol' in the subwindow of the form.
+| Allocate 'nrow' off-screen rows and 'nbuf' additional
+| buffers. If an error occurs, errno is set to
+|
+| E_BAD_ARGUMENT - invalid argument
+| E_SYSTEM_ERROR - system error
+|
+| Return Values : Pointer to the new field or NULL if failure.
++--------------------------------------------------------------------------*/
+FIELD *new_field(int rows, int cols, int frow, int fcol, int nrow, int nbuf)
+{
+ FIELD *New_Field = (FIELD *)0;
+ int err = E_BAD_ARGUMENT;
+
+ if (rows>0 &&
+ cols>0 &&
+ frow>=0 &&
+ fcol>=0 &&
+ nrow>=0 &&
+ nbuf>=0 &&
+ ((err = E_SYSTEM_ERROR) != 0) && /* trick: this resets the default error */
+ (New_Field=(FIELD *)malloc(sizeof(FIELD))) )
+ {
+ *New_Field = default_field;
+ New_Field->rows = rows;
+ New_Field->cols = cols;
+ New_Field->drows = rows + nrow;
+ New_Field->dcols = cols;
+ New_Field->frow = frow;
+ New_Field->fcol = fcol;
+ New_Field->nrow = nrow;
+ New_Field->nbuf = nbuf;
+ New_Field->link = New_Field;
+
+ if (_nc_Copy_Type(New_Field,&default_field))
+ {
+ size_t len;
+
+ len = Total_Buffer_Size(New_Field);
+ if ((New_Field->buf = (char *)malloc(len)))
+ {
+ /* Prefill buffers with blanks and insert terminating zeroes
+ between buffers */
+ int i;
+
+ memset(New_Field->buf,' ',len);
+ for(i=0;i<=New_Field->nbuf;i++)
+ {
+ New_Field->buf[(New_Field->drows*New_Field->cols+1)*(i+1)-1]
+ = '\0';
+ }
+ return New_Field;
+ }
+ }
+ }
+
+ if (New_Field)
+ free_field(New_Field);
+
+ SET_ERROR( err );
+ return (FIELD *)0;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int free_field( FIELD *field )
+|
+| Description : Frees the storage allocated for the field.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid field pointer
+| E_CONNECTED - field is connected
++--------------------------------------------------------------------------*/
+int free_field(FIELD * field)
+{
+ if (!field)
+ RETURN(E_BAD_ARGUMENT);
+
+ if (field->form)
+ RETURN(E_CONNECTED);
+
+ if (field == field->link)
+ {
+ if (field->buf)
+ free(field->buf);
+ }
+ else
+ {
+ FIELD *f;
+
+ for(f=field;f->link != field;f = f->link)
+ {}
+ f->link = field->link;
+ }
+ _nc_Free_Type(field);
+ free(field);
+ RETURN(E_OK);
+}
+
+/* fld_def.c ends here */
diff --git a/Source/CursesDialog/form/fld_dup.c b/Source/CursesDialog/form/fld_dup.c
new file mode 100644
index 0000000000..1c5301d55a
--- /dev/null
+++ b/Source/CursesDialog/form/fld_dup.c
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FIELD *dup_field(FIELD *field, int frow, int fcol)
+|
+| Description : Duplicates the field at the specified position. All
+| field attributes and the buffers are copied.
+| If an error occurs, errno is set to
+|
+| E_BAD_ARGUMENT - invalid argument
+| E_SYSTEM_ERROR - system error
+|
+| Return Values : Pointer to the new field or NULL if failure
++--------------------------------------------------------------------------*/
+FIELD *dup_field(FIELD * field, int frow, int fcol)
+{
+ FIELD *New_Field = (FIELD *)0;
+ int err = E_BAD_ARGUMENT;
+
+ if (field && (frow>=0) && (fcol>=0) &&
+ ((err=E_SYSTEM_ERROR) != 0) && /* trick : this resets the default error */
+ (New_Field=(FIELD *)malloc(sizeof(FIELD))) )
+ {
+ *New_Field = *_nc_Default_Field;
+ New_Field->frow = frow;
+ New_Field->fcol = fcol;
+ New_Field->link = New_Field;
+ New_Field->rows = field->rows;
+ New_Field->cols = field->cols;
+ New_Field->nrow = field->nrow;
+ New_Field->drows = field->drows;
+ New_Field->dcols = field->dcols;
+ New_Field->maxgrow = field->maxgrow;
+ New_Field->nbuf = field->nbuf;
+ New_Field->just = field->just;
+ New_Field->fore = field->fore;
+ New_Field->back = field->back;
+ New_Field->pad = field->pad;
+ New_Field->opts = field->opts;
+ New_Field->usrptr = field->usrptr;
+
+ if (_nc_Copy_Type(New_Field,field))
+ {
+ size_t len;
+
+ len = Total_Buffer_Size(New_Field);
+ if ( (New_Field->buf=(char *)malloc(len)) )
+ {
+ memcpy(New_Field->buf,field->buf,len);
+ return New_Field;
+ }
+ }
+ }
+
+ if (New_Field)
+ free_field(New_Field);
+
+ SET_ERROR(err);
+ return (FIELD *)0;
+}
+
+/* fld_dup.c ends here */
diff --git a/Source/CursesDialog/form/fld_ftchoice.c b/Source/CursesDialog/form/fld_ftchoice.c
new file mode 100644
index 0000000000..bb37073fb8
--- /dev/null
+++ b/Source/CursesDialog/form/fld_ftchoice.c
@@ -0,0 +1,62 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_fieldtype_choice(
+| FIELDTYPE *typ,
+| bool (* const next_choice)(FIELD *,const void *),
+| bool (* const prev_choice)(FIELD *,const void *))
+|
+| Description : Define implementation of enumeration requests.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid arguments
++--------------------------------------------------------------------------*/
+int set_fieldtype_choice(FIELDTYPE * typ,
+ bool (* const next_choice) (FIELD *,const void *),
+ bool (* const prev_choice) (FIELD *,const void *))
+{
+ if ( !typ || !next_choice || !prev_choice )
+ RETURN(E_BAD_ARGUMENT);
+
+ typ->status |= _HAS_CHOICE;
+ typ->next = next_choice;
+ typ->prev = prev_choice;
+ RETURN(E_OK);
+}
+
+/* fld_ftchoice.c ends here */
diff --git a/Source/CursesDialog/form/fld_ftlink.c b/Source/CursesDialog/form/fld_ftlink.c
new file mode 100644
index 0000000000..1cb80d1184
--- /dev/null
+++ b/Source/CursesDialog/form/fld_ftlink.c
@@ -0,0 +1,83 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FIELDTYPE *link_fieldtype(
+| FIELDTYPE *type1,
+| FIELDTYPE *type2)
+|
+| Description : Create a new fieldtype built from the two given types.
+| They are connected by an logical 'OR'.
+| If an error occurs, errno is set to
+| E_BAD_ARGUMENT - invalid arguments
+| E_SYSTEM_ERROR - system error (no memory)
+|
+| Return Values : Fieldtype pointer or NULL if error occured.
++--------------------------------------------------------------------------*/
+FIELDTYPE *link_fieldtype(FIELDTYPE * type1, FIELDTYPE * type2)
+{
+ FIELDTYPE *nftyp = (FIELDTYPE *)0;
+
+ if ( type1 && type2 )
+ {
+ nftyp = (FIELDTYPE *)malloc(sizeof(FIELDTYPE));
+ if (nftyp)
+ {
+ *nftyp = *_nc_Default_FieldType;
+ nftyp->status |= _LINKED_TYPE;
+ if ((type1->status & _HAS_ARGS) || (type2->status & _HAS_ARGS) )
+ nftyp->status |= _HAS_ARGS;
+ if ((type1->status & _HAS_CHOICE) || (type2->status & _HAS_CHOICE) )
+ nftyp->status |= _HAS_CHOICE;
+ nftyp->left = type1;
+ nftyp->right = type2;
+ type1->ref++;
+ type2->ref++;
+ }
+ else
+ {
+ SET_ERROR( E_SYSTEM_ERROR );
+ }
+ }
+ else
+ {
+ SET_ERROR( E_BAD_ARGUMENT );
+ }
+ return nftyp;
+}
+
+/* fld_ftlink.c ends here */
diff --git a/Source/CursesDialog/form/fld_info.c b/Source/CursesDialog/form/fld_info.c
new file mode 100644
index 0000000000..1ba92c8334
--- /dev/null
+++ b/Source/CursesDialog/form/fld_info.c
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int field_info(const FIELD *field,
+| int *rows, int *cols,
+| int *frow, int *fcol,
+| int *nrow, int *nbuf)
+|
+| Description : Retrieve infos about the fields creation parameters.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid field pointer
++--------------------------------------------------------------------------*/
+int field_info(const FIELD *field,
+ int *rows, int *cols,
+ int *frow, int *fcol,
+ int *nrow, int *nbuf)
+{
+ if (!field)
+ RETURN(E_BAD_ARGUMENT);
+
+ if (rows) *rows = field->rows;
+ if (cols) *cols = field->cols;
+ if (frow) *frow = field->frow;
+ if (fcol) *fcol = field->fcol;
+ if (nrow) *nrow = field->nrow;
+ if (nbuf) *nbuf = field->nbuf;
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int dynamic_field_info(const FIELD *field,
+| int *drows, int *dcols,
+| int *maxgrow)
+|
+| Description : Retrieve information about a dynamic fields current
+| dynamic parameters.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid argument
++--------------------------------------------------------------------------*/
+int dynamic_field_info(const FIELD *field,
+ int *drows, int *dcols, int *maxgrow)
+{
+ if (!field)
+ RETURN(E_BAD_ARGUMENT);
+
+ if (drows) *drows = field->drows;
+ if (dcols) *dcols = field->dcols;
+ if (maxgrow) *maxgrow = field->maxgrow;
+
+ RETURN(E_OK);
+}
+
+/* fld_info.c ends here */
diff --git a/Source/CursesDialog/form/fld_just.c b/Source/CursesDialog/form/fld_just.c
new file mode 100644
index 0000000000..7015654509
--- /dev/null
+++ b/Source/CursesDialog/form/fld_just.c
@@ -0,0 +1,81 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_just(FIELD *field, int just)
+|
+| Description : Set the fields type of justification.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - one of the arguments was incorrect
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+int set_field_just(FIELD * field, int just)
+{
+ int res = E_BAD_ARGUMENT;
+
+ if ((just==NO_JUSTIFICATION) ||
+ (just==JUSTIFY_LEFT) ||
+ (just==JUSTIFY_CENTER) ||
+ (just==JUSTIFY_RIGHT) )
+ {
+ Normalize_Field( field );
+ if (field->just != just)
+ {
+ field->just = just;
+ res = _nc_Synchronize_Attributes( field );
+ }
+ else
+ res = E_OK;
+ }
+ RETURN(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int field_just( const FIELD *field )
+|
+| Description : Retrieve the fields type of justification
+|
+| Return Values : The justification type.
++--------------------------------------------------------------------------*/
+int field_just(const FIELD * field)
+{
+ return Normalize_Field( field )->just;
+}
+
+/* fld_just.c ends here */
diff --git a/Source/CursesDialog/form/fld_link.c b/Source/CursesDialog/form/fld_link.c
new file mode 100644
index 0000000000..164f51bc42
--- /dev/null
+++ b/Source/CursesDialog/form/fld_link.c
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FIELD *link_field(FIELD *field, int frow, int fcol)
+|
+| Description : Duplicates the field at the specified position. The
+| new field shares its buffers with the original one,
+| the attributes are independent.
+| If an error occurs, errno is set to
+|
+| E_BAD_ARGUMENT - invalid argument
+| E_SYSTEM_ERROR - system error
+|
+| Return Values : Pointer to the new field or NULL if failure
++--------------------------------------------------------------------------*/
+FIELD *link_field(FIELD * field, int frow, int fcol)
+{
+ FIELD *New_Field = (FIELD *)0;
+ int err = E_BAD_ARGUMENT;
+
+ if (field && (frow>=0) && (fcol>=0) &&
+ ((err=E_SYSTEM_ERROR) != 0) && /* trick: this resets the default error */
+ (New_Field = (FIELD *)malloc(sizeof(FIELD))) )
+ {
+ *New_Field = *_nc_Default_Field;
+ New_Field->frow = frow;
+ New_Field->fcol = fcol;
+ New_Field->link = field->link;
+ field->link = New_Field;
+ New_Field->buf = field->buf;
+ New_Field->rows = field->rows;
+ New_Field->cols = field->cols;
+ New_Field->nrow = field->nrow;
+ New_Field->nbuf = field->nbuf;
+ New_Field->drows = field->drows;
+ New_Field->dcols = field->dcols;
+ New_Field->maxgrow= field->maxgrow;
+ New_Field->just = field->just;
+ New_Field->fore = field->fore;
+ New_Field->back = field->back;
+ New_Field->pad = field->pad;
+ New_Field->opts = field->opts;
+ New_Field->usrptr = field->usrptr;
+ if (_nc_Copy_Type(New_Field,field))
+ return New_Field;
+ }
+
+ if (New_Field)
+ free_field(New_Field);
+
+ SET_ERROR( err );
+ return (FIELD *)0;
+}
+
+/* fld_link.c ends here */
diff --git a/Source/CursesDialog/form/fld_max.c b/Source/CursesDialog/form/fld_max.c
new file mode 100644
index 0000000000..cca8dc5587
--- /dev/null
+++ b/Source/CursesDialog/form/fld_max.c
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_max_field(FIELD *field, int maxgrow)
+|
+| Description : Set the maximum growth for a dynamic field. If maxgrow=0
+| the field may grow to any possible size.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid argument
++--------------------------------------------------------------------------*/
+int set_max_field(FIELD *field, int maxgrow)
+{
+ if (!field || (maxgrow<0))
+ RETURN(E_BAD_ARGUMENT);
+ else
+ {
+ bool single_line_field = Single_Line_Field(field);
+
+ if (maxgrow>0)
+ {
+ if (( single_line_field && (maxgrow < field->dcols)) ||
+ (!single_line_field && (maxgrow < field->drows)))
+ RETURN(E_BAD_ARGUMENT);
+ }
+ field->maxgrow = maxgrow;
+ field->status &= ~_MAY_GROW;
+ if (!(field->opts & O_STATIC))
+ {
+ if ((maxgrow==0) ||
+ ( single_line_field && (field->dcols < maxgrow)) ||
+ (!single_line_field && (field->drows < maxgrow)))
+ field->status |= _MAY_GROW;
+ }
+ }
+ RETURN(E_OK);
+}
+
+/* fld_max.c ends here */
diff --git a/Source/CursesDialog/form/fld_move.c b/Source/CursesDialog/form/fld_move.c
new file mode 100644
index 0000000000..22934779cc
--- /dev/null
+++ b/Source/CursesDialog/form/fld_move.c
@@ -0,0 +1,62 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int move_field(FIELD *field,int frow, int fcol)
+|
+| Description : Moves the disconnected field to the new location in
+| the forms subwindow.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid argument passed
+| E_CONNECTED - field is connected
++--------------------------------------------------------------------------*/
+int move_field(FIELD *field, int frow, int fcol)
+{
+ if ( !field || (frow<0) || (fcol<0) )
+ RETURN(E_BAD_ARGUMENT);
+
+ if (field->form)
+ RETURN(E_CONNECTED);
+
+ field->frow = frow;
+ field->fcol = fcol;
+ RETURN(E_OK);
+}
+
+/* fld_move.c ends here */
+
diff --git a/Source/CursesDialog/form/fld_newftyp.c b/Source/CursesDialog/form/fld_newftyp.c
new file mode 100644
index 0000000000..b45ebd8791
--- /dev/null
+++ b/Source/CursesDialog/form/fld_newftyp.c
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+static FIELDTYPE const default_fieldtype = {
+ 0, /* status */
+ 0L, /* reference count */
+ (FIELDTYPE *)0, /* pointer to left operand */
+ (FIELDTYPE *)0, /* pointer to right operand */
+ NULL, /* makearg function */
+ NULL, /* copyarg function */
+ NULL, /* freearg function */
+ NULL, /* field validation function */
+ NULL, /* Character check function */
+ NULL, /* enumerate next function */
+ NULL /* enumerate previous function */
+};
+
+const FIELDTYPE* _nc_Default_FieldType = &default_fieldtype;
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FIELDTYPE *new_fieldtype(
+| bool (* const field_check)(FIELD *,const void *),
+| bool (* const char_check) (int, const void *) )
+|
+| Description : Create a new fieldtype. The application programmer must
+| write a field_check and a char_check function and give
+| them as input to this call.
+| If an error occurs, errno is set to
+| E_BAD_ARGUMENT - invalid arguments
+| E_SYSTEM_ERROR - system error (no memory)
+|
+| Return Values : Fieldtype pointer or NULL if error occured
++--------------------------------------------------------------------------*/
+FIELDTYPE *new_fieldtype(
+ bool (* const field_check)(FIELD *,const void *),
+ bool (* const char_check) (int,const void *) )
+{
+ FIELDTYPE *nftyp = (FIELDTYPE *)0;
+
+ if ( (field_check) || (char_check) )
+ {
+ nftyp = (FIELDTYPE *)malloc(sizeof(FIELDTYPE));
+ if (nftyp)
+ {
+ *nftyp = default_fieldtype;
+ nftyp->fcheck = field_check;
+ nftyp->ccheck = char_check;
+ }
+ else
+ {
+ SET_ERROR( E_SYSTEM_ERROR );
+ }
+ }
+ else
+ {
+ SET_ERROR( E_BAD_ARGUMENT );
+ }
+ return nftyp;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int free_fieldtype(FIELDTYPE *typ)
+|
+| Description : Release the memory associated with this fieldtype.
+|
+| Return Values : E_OK - success
+| E_CONNECTED - there are fields referencing the type
+| E_BAD_ARGUMENT - invalid fieldtype pointer
++--------------------------------------------------------------------------*/
+int free_fieldtype(FIELDTYPE *typ)
+{
+ if (!typ)
+ RETURN(E_BAD_ARGUMENT);
+
+ if (typ->ref!=0)
+ RETURN(E_CONNECTED);
+
+ if (typ->status & _RESIDENT)
+ RETURN(E_CONNECTED);
+
+ if (typ->status & _LINKED_TYPE)
+ {
+ if (typ->left ) typ->left->ref--;
+ if (typ->right) typ->right->ref--;
+ }
+ free(typ);
+ RETURN(E_OK);
+}
+
+/* fld_newftyp.c ends here */
diff --git a/Source/CursesDialog/form/fld_opts.c b/Source/CursesDialog/form/fld_opts.c
new file mode 100644
index 0000000000..234634bc67
--- /dev/null
+++ b/Source/CursesDialog/form/fld_opts.c
@@ -0,0 +1,124 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*----------------------------------------------------------------------------
+ Field-Options manipulation routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_opts(FIELD *field, Field_Options opts)
+|
+| Description : Turns on the named options for this field and turns
+| off all the remaining options.
+|
+| Return Values : E_OK - success
+| E_CURRENT - the field is the current field
+| E_BAD_ARGUMENT - invalid options
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+int set_field_opts(FIELD * field, Field_Options opts)
+{
+ int res = E_BAD_ARGUMENT;
+ opts &= ALL_FIELD_OPTS;
+ if (!(opts & ~ALL_FIELD_OPTS))
+ res = _nc_Synchronize_Options( Normalize_Field(field), opts );
+ RETURN(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : Field_Options field_opts(const FIELD *field)
+|
+| Description : Retrieve the fields options.
+|
+| Return Values : The options.
++--------------------------------------------------------------------------*/
+Field_Options field_opts(const FIELD * field)
+{
+ return ALL_FIELD_OPTS & Normalize_Field( field )->opts;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int field_opts_on(FIELD *field, Field_Options opts)
+|
+| Description : Turns on the named options for this field and all the
+| remaining options are unchanged.
+|
+| Return Values : E_OK - success
+| E_CURRENT - the field is the current field
+| E_BAD_ARGUMENT - invalid options
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+int field_opts_on(FIELD * field, Field_Options opts)
+{
+ int res = E_BAD_ARGUMENT;
+
+ opts &= ALL_FIELD_OPTS;
+ if (!(opts & ~ALL_FIELD_OPTS))
+ {
+ Normalize_Field( field );
+ res = _nc_Synchronize_Options( field, field->opts | opts );
+ }
+ RETURN(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int field_opts_off(FIELD *field, Field_Options opts)
+|
+| Description : Turns off the named options for this field and all the
+| remaining options are unchanged.
+|
+| Return Values : E_OK - success
+| E_CURRENT - the field is the current field
+| E_BAD_ARGUMENT - invalid options
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+int field_opts_off(FIELD * field, Field_Options opts)
+{
+ int res = E_BAD_ARGUMENT;
+
+ opts &= ALL_FIELD_OPTS;
+ if (!(opts & ~ALL_FIELD_OPTS))
+ {
+ Normalize_Field( field );
+ res = _nc_Synchronize_Options( field, field->opts & ~opts );
+ }
+ RETURN(res);
+}
+
+/* fld_opts.c ends here */
diff --git a/Source/CursesDialog/form/fld_pad.c b/Source/CursesDialog/form/fld_pad.c
new file mode 100644
index 0000000000..45983409d2
--- /dev/null
+++ b/Source/CursesDialog/form/fld_pad.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_pad(FIELD *field, int ch)
+|
+| Description : Set the pad character used to fill the field. This must
+| be a printable character.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid field pointer or pad character
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+int set_field_pad(FIELD * field, int ch)
+{
+ int res = E_BAD_ARGUMENT;
+
+ Normalize_Field( field );
+ if (isprint((unsigned char)ch))
+ {
+ if (field->pad != ch)
+ {
+ field->pad = ch;
+ res = _nc_Synchronize_Attributes( field );
+ }
+ else
+ res = E_OK;
+ }
+ RETURN(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int field_pad(const FIELD *field)
+|
+| Description : Retrieve the fields pad character.
+|
+| Return Values : The pad character.
++--------------------------------------------------------------------------*/
+int field_pad(const FIELD * field)
+{
+ return Normalize_Field( field )->pad;
+}
+
+/* fld_pad.c ends here */
diff --git a/Source/CursesDialog/form/fld_page.c b/Source/CursesDialog/form/fld_page.c
new file mode 100644
index 0000000000..408e71201f
--- /dev/null
+++ b/Source/CursesDialog/form/fld_page.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_new_page(FIELD *field, bool new_page_flag)
+|
+| Description : Marks the field as the beginning of a new page of
+| the form.
+|
+| Return Values : E_OK - success
+| E_CONNECTED - field is connected
++--------------------------------------------------------------------------*/
+int set_new_page(FIELD * field, bool new_page_flag)
+{
+ Normalize_Field(field);
+ if (field->form)
+ RETURN(E_CONNECTED);
+
+ if (new_page_flag)
+ field->status |= _NEWPAGE;
+ else
+ field->status &= ~_NEWPAGE;
+
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : bool new_page(const FIELD *field)
+|
+| Description : Retrieve the info whether or not the field starts a
+| new page on the form.
+|
+| Return Values : TRUE - field starts a new page
+| FALSE - field doesn't start a new page
++--------------------------------------------------------------------------*/
+bool new_page(const FIELD * field)
+{
+ return (Normalize_Field(field)->status & _NEWPAGE) ? TRUE : FALSE;
+}
+
+/* fld_page.c ends here */
diff --git a/Source/CursesDialog/form/fld_stat.c b/Source/CursesDialog/form/fld_stat.c
new file mode 100644
index 0000000000..ee6831bbe5
--- /dev/null
+++ b/Source/CursesDialog/form/fld_stat.c
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_status(FIELD *field, bool status)
+|
+| Description : Set or clear the 'changed' indication flag for that
+| fields primary buffer.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+int set_field_status(FIELD * field, bool status)
+{
+ Normalize_Field( field );
+
+ if (status)
+ field->status |= _CHANGED;
+ else
+ field->status &= ~_CHANGED;
+
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : bool field_status(const FIELD *field)
+|
+| Description : Retrieve the value of the 'changed' indication flag
+| for that fields primary buffer.
+|
+| Return Values : TRUE - buffer has been changed
+| FALSE - buffer has not been changed
++--------------------------------------------------------------------------*/
+bool field_status(const FIELD * field)
+{
+ return ((Normalize_Field(field)->status & _CHANGED) ? TRUE : FALSE);
+}
+
+/* fld_stat.c ends here */
diff --git a/Source/CursesDialog/form/fld_type.c b/Source/CursesDialog/form/fld_type.c
new file mode 100644
index 0000000000..6c9def2c99
--- /dev/null
+++ b/Source/CursesDialog/form/fld_type.c
@@ -0,0 +1,51 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FIELDTYPE *field_type(const FIELD *field)
+|
+| Description : Retrieve the associated fieldtype for this field.
+|
+| Return Values : Pointer to fieldtype of NULL if none is defined.
++--------------------------------------------------------------------------*/
+FIELDTYPE *field_type(const FIELD * field)
+{
+ return Normalize_Field(field)->type;
+}
+
+/* fld_type.c ends here */
diff --git a/Source/CursesDialog/form/fld_user.c b/Source/CursesDialog/form/fld_user.c
new file mode 100644
index 0000000000..3287b5b179
--- /dev/null
+++ b/Source/CursesDialog/form/fld_user.c
@@ -0,0 +1,67 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_userptr(FIELD *field, void *usrptr)
+|
+| Description : Set the pointer that is reserved in any field to store
+| application relevant information
+|
+| Return Values : E_OK - on success
++--------------------------------------------------------------------------*/
+int set_field_userptr(FIELD * field, void *usrptr)
+{
+ Normalize_Field( field )->usrptr = usrptr;
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : void *field_userptr(const FIELD *field)
+|
+| Description : Return the pointer that is reserved in any field to
+| store application relevant information.
+|
+| Return Values : Value of pointer. If no such pointer has been set,
+| NULL is returned
++--------------------------------------------------------------------------*/
+void *field_userptr(const FIELD *field)
+{
+ return Normalize_Field( field )->usrptr;
+}
+
+/* fld_user.c ends here */
diff --git a/Source/CursesDialog/form/form.h b/Source/CursesDialog/form/form.h
new file mode 100644
index 0000000000..94f05af8a2
--- /dev/null
+++ b/Source/CursesDialog/form/form.h
@@ -0,0 +1,401 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#ifndef FORM_H
+#define FORM_H
+
+#if defined(__sun__) && defined(__GNUC__)
+ #define _MSE_INT_H
+#endif
+
+#include <cmFormConfigure.h>
+
+/* figure out which curses.h to include */
+# if defined(CURSES_HAVE_NCURSES_H)
+# include <ncurses.h>
+# elif defined(CURSES_HAVE_NCURSES_NCURSES_H)
+# include <ncurses/ncurses.h>
+# elif defined(CURSES_HAVE_NCURSES_CURSES_H)
+# include <ncurses/curses.h>
+# else
+# include <curses.h>
+# endif
+
+#include <eti.h>
+#include <stdarg.h>
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+typedef int Form_Options;
+typedef int Field_Options;
+
+ /**********
+ * _PAGE *
+ **********/
+
+typedef struct {
+ short pmin; /* index of first field on page */
+ short pmax; /* index of last field on page */
+ short smin; /* index of top leftmost field on page */
+ short smax; /* index of bottom rightmost field on page */
+} _PAGE;
+
+ /**********
+ * FIELD *
+ **********/
+
+typedef struct fieldnode {
+ unsigned short status; /* flags */
+ short rows; /* size in rows */
+ short cols; /* size in cols */
+ short frow; /* first row */
+ short fcol; /* first col */
+ int drows; /* dynamic rows */
+ int dcols; /* dynamic cols */
+ int maxgrow; /* maximum field growth */
+ int nrow; /* offscreen rows */
+ short nbuf; /* additional buffers */
+ short just; /* justification */
+ short page; /* page on form */
+ short index; /* into form -> field */
+ int pad; /* pad character */
+ chtype fore; /* foreground attribute */
+ chtype back; /* background attribute */
+ Field_Options opts; /* options */
+ struct fieldnode * snext; /* sorted order pointer */
+ struct fieldnode * sprev; /* sorted order pointer */
+ struct fieldnode * link; /* linked field chain */
+ struct formnode * form; /* containing form */
+ struct typenode * type; /* field type */
+ void * arg; /* argument for type */
+ char * buf; /* field buffers */
+ void * usrptr; /* user pointer */
+} FIELD;
+
+ /**************
+ * FIELDTYPE *
+ **************/
+
+typedef struct typenode {
+ unsigned short status; /* flags */
+ long ref; /* reference count */
+ struct typenode * left; /* ptr to operand for | */
+ struct typenode * right; /* ptr to operand for | */
+
+ void* (*makearg)(va_list *); /* make fieldtype arg */
+ void* (*copyarg)(const void *); /* copy fieldtype arg */
+ void (*freearg)(void *); /* free fieldtype arg */
+
+ bool (*fcheck)(FIELD *,const void *); /* field validation */
+ bool (*ccheck)(int,const void *); /* character validation */
+
+ bool (*next)(FIELD *,const void *); /* enumerate next value */
+ bool (*prev)(FIELD *,const void *); /* enumerate prev value */
+
+} FIELDTYPE;
+
+ /*********
+ * FORM *
+ *********/
+
+typedef struct formnode {
+ unsigned short status; /* flags */
+ short rows; /* size in rows */
+ short cols; /* size in cols */
+ int currow; /* current row in field window*/
+ int curcol; /* current col in field window*/
+ int toprow; /* in scrollable field window */
+ int begincol; /* in horiz. scrollable field */
+ short maxfield; /* number of fields */
+ short maxpage; /* number of pages */
+ short curpage; /* index into page */
+ Form_Options opts; /* options */
+ WINDOW * win; /* window */
+ WINDOW * sub; /* subwindow */
+ WINDOW * w; /* window for current field */
+ FIELD ** field; /* field [maxfield] */
+ FIELD * current; /* current field */
+ _PAGE * page; /* page [maxpage] */
+ void * usrptr; /* user pointer */
+
+ void (*forminit)(struct formnode *);
+ void (*formterm)(struct formnode *);
+ void (*fieldinit)(struct formnode *);
+ void (*fieldterm)(struct formnode *);
+
+} FORM;
+
+typedef void (*Form_Hook)(FORM *);
+
+ /***************************
+ * miscellaneous #defines *
+ ***************************/
+
+/* field justification */
+#define NO_JUSTIFICATION (0)
+#define JUSTIFY_LEFT (1)
+#define JUSTIFY_CENTER (2)
+#define JUSTIFY_RIGHT (3)
+
+/* field options */
+#define O_VISIBLE (0x0001)
+#define O_ACTIVE (0x0002)
+#define O_PUBLIC (0x0004)
+#define O_EDIT (0x0008)
+#define O_WRAP (0x0010)
+#define O_BLANK (0x0020)
+#define O_AUTOSKIP (0x0040)
+#define O_NULLOK (0x0080)
+#define O_PASSOK (0x0100)
+#define O_STATIC (0x0200)
+
+/* form options */
+#define O_NL_OVERLOAD (0x0001)
+#define O_BS_OVERLOAD (0x0002)
+
+/* form driver commands */
+#define REQ_NEXT_PAGE (KEY_MAX + 1) /* move to next page */
+#define REQ_PREV_PAGE (KEY_MAX + 2) /* move to previous page */
+#define REQ_FIRST_PAGE (KEY_MAX + 3) /* move to first page */
+#define REQ_LAST_PAGE (KEY_MAX + 4) /* move to last page */
+
+#define REQ_NEXT_FIELD (KEY_MAX + 5) /* move to next field */
+#define REQ_PREV_FIELD (KEY_MAX + 6) /* move to previous field */
+#define REQ_FIRST_FIELD (KEY_MAX + 7) /* move to first field */
+#define REQ_LAST_FIELD (KEY_MAX + 8) /* move to last field */
+#define REQ_SNEXT_FIELD (KEY_MAX + 9) /* move to sorted next field */
+#define REQ_SPREV_FIELD (KEY_MAX + 10) /* move to sorted prev field */
+#define REQ_SFIRST_FIELD (KEY_MAX + 11) /* move to sorted first field */
+#define REQ_SLAST_FIELD (KEY_MAX + 12) /* move to sorted last field */
+#define REQ_LEFT_FIELD (KEY_MAX + 13) /* move to left to field */
+#define REQ_RIGHT_FIELD (KEY_MAX + 14) /* move to right to field */
+#define REQ_UP_FIELD (KEY_MAX + 15) /* move to up to field */
+#define REQ_DOWN_FIELD (KEY_MAX + 16) /* move to down to field */
+
+#define REQ_NEXT_CHAR (KEY_MAX + 17) /* move to next char in field */
+#define REQ_PREV_CHAR (KEY_MAX + 18) /* move to prev char in field */
+#define REQ_NEXT_LINE (KEY_MAX + 19) /* move to next line in field */
+#define REQ_PREV_LINE (KEY_MAX + 20) /* move to prev line in field */
+#define REQ_NEXT_WORD (KEY_MAX + 21) /* move to next word in field */
+#define REQ_PREV_WORD (KEY_MAX + 22) /* move to prev word in field */
+#define REQ_BEG_FIELD (KEY_MAX + 23) /* move to first char in field */
+#define REQ_END_FIELD (KEY_MAX + 24) /* move after last char in fld */
+#define REQ_BEG_LINE (KEY_MAX + 25) /* move to beginning of line */
+#define REQ_END_LINE (KEY_MAX + 26) /* move after last char in line */
+#define REQ_LEFT_CHAR (KEY_MAX + 27) /* move left in field */
+#define REQ_RIGHT_CHAR (KEY_MAX + 28) /* move right in field */
+#define REQ_UP_CHAR (KEY_MAX + 29) /* move up in field */
+#define REQ_DOWN_CHAR (KEY_MAX + 30) /* move down in field */
+
+#define REQ_NEW_LINE (KEY_MAX + 31) /* insert/overlay new line */
+#define REQ_INS_CHAR (KEY_MAX + 32) /* insert blank char at cursor */
+#define REQ_INS_LINE (KEY_MAX + 33) /* insert blank line at cursor */
+#define REQ_DEL_CHAR (KEY_MAX + 34) /* delete char at cursor */
+#define REQ_DEL_PREV (KEY_MAX + 35) /* delete char before cursor */
+#define REQ_DEL_LINE (KEY_MAX + 36) /* delete line at cursor */
+#define REQ_DEL_WORD (KEY_MAX + 37) /* delete line at cursor */
+#define REQ_CLR_EOL (KEY_MAX + 38) /* clear to end of line */
+#define REQ_CLR_EOF (KEY_MAX + 39) /* clear to end of field */
+#define REQ_CLR_FIELD (KEY_MAX + 40) /* clear entire field */
+#define REQ_OVL_MODE (KEY_MAX + 41) /* begin overlay mode */
+#define REQ_INS_MODE (KEY_MAX + 42) /* begin insert mode */
+#define REQ_SCR_FLINE (KEY_MAX + 43) /* scroll field forward a line */
+#define REQ_SCR_BLINE (KEY_MAX + 44) /* scroll field backward a line */
+#define REQ_SCR_FPAGE (KEY_MAX + 45) /* scroll field forward a page */
+#define REQ_SCR_BPAGE (KEY_MAX + 46) /* scroll field backward a page */
+#define REQ_SCR_FHPAGE (KEY_MAX + 47) /* scroll field forward half page */
+#define REQ_SCR_BHPAGE (KEY_MAX + 48) /* scroll field backward half page */
+#define REQ_SCR_FCHAR (KEY_MAX + 49) /* horizontal scroll char */
+#define REQ_SCR_BCHAR (KEY_MAX + 50) /* horizontal scroll char */
+#define REQ_SCR_HFLINE (KEY_MAX + 51) /* horizontal scroll line */
+#define REQ_SCR_HBLINE (KEY_MAX + 52) /* horizontal scroll line */
+#define REQ_SCR_HFHALF (KEY_MAX + 53) /* horizontal scroll half line */
+#define REQ_SCR_HBHALF (KEY_MAX + 54) /* horizontal scroll half line */
+
+#define REQ_VALIDATION (KEY_MAX + 55) /* validate field */
+#define REQ_NEXT_CHOICE (KEY_MAX + 56) /* display next field choice */
+#define REQ_PREV_CHOICE (KEY_MAX + 57) /* display prev field choice */
+
+#define MIN_FORM_COMMAND (KEY_MAX + 1) /* used by form_driver */
+#define MAX_FORM_COMMAND (KEY_MAX + 57) /* used by form_driver */
+
+#if defined(MAX_COMMAND)
+# if (MAX_FORM_COMMAND > MAX_COMMAND)
+# error Something is wrong -- MAX_FORM_COMMAND is greater than MAX_COMMAND
+# elif (MAX_COMMAND != (KEY_MAX + 128))
+# error Something is wrong -- MAX_COMMAND is already inconsistently defined.
+# endif
+#else
+# define MAX_COMMAND (KEY_MAX + 128)
+#endif
+
+ /*************************
+ * standard field types *
+ *************************/
+extern FIELDTYPE *TYPE_ALPHA,
+ *TYPE_ALNUM,
+ *TYPE_ENUM,
+ *TYPE_INTEGER,
+ *TYPE_NUMERIC,
+ *TYPE_REGEXP;
+
+ /************************************
+ * built-in additional field types *
+ * They are not defined in SVr4 *
+ ************************************/
+extern FIELDTYPE *TYPE_IPV4; /* Internet IP Version 4 address */
+
+ /***********************
+ * Default objects *
+ ***********************/
+extern FORM *_nc_Default_Form;
+extern FIELD *_nc_Default_Field;
+
+
+ /***********************
+ * FIELDTYPE routines *
+ ***********************/
+extern FIELDTYPE
+ *new_fieldtype(
+ bool (* const field_check)(FIELD *,const void *),
+ bool (* const char_check)(int,const void *)),
+ *link_fieldtype(FIELDTYPE *,FIELDTYPE *);
+
+extern int free_fieldtype(FIELDTYPE *),
+ set_fieldtype_choice (FIELDTYPE *,
+ bool (* const next_choice)(FIELD *,const void *),
+ bool (* const prev_choice)(FIELD *,const void *));
+
+ /*******************
+ * FIELD routines *
+ *******************/
+extern FIELD *new_field(int,int,int,int,int,int),
+ *dup_field(FIELD *,int,int),
+ *link_field(FIELD *,int,int);
+
+extern int free_field(FIELD *),
+ field_info(const FIELD *,int *,int *,int *,int *,int *,int *),
+ dynamic_field_info(const FIELD *,int *,int *,int *),
+ set_max_field( FIELD *,int),
+ move_field(FIELD *,int,int),
+ set_field_type(FIELD *,FIELDTYPE *,...),
+ set_new_page(FIELD *,bool),
+ set_field_just(FIELD *,int),
+ field_just(const FIELD *),
+ set_field_fore(FIELD *,chtype),
+ set_field_back(FIELD *,chtype),
+ set_field_pad(FIELD *,int),
+ field_pad(const FIELD *),
+ set_field_buffer(FIELD *,int,const char *),
+ set_field_status(FIELD *,bool),
+ set_field_userptr(FIELD *, void *),
+ set_field_opts(FIELD *,Field_Options),
+ field_opts_on(FIELD *,Field_Options),
+ field_opts_off(FIELD *,Field_Options);
+
+extern chtype field_fore(const FIELD *),
+ field_back(const FIELD *);
+
+extern bool new_page(const FIELD *),
+ field_status(const FIELD *);
+
+extern void *field_arg(const FIELD *);
+
+extern void *field_userptr(const FIELD *);
+
+extern FIELDTYPE
+ *field_type(const FIELD *);
+
+extern char* field_buffer(const FIELD *,int);
+
+extern Field_Options
+ field_opts(const FIELD *);
+
+ /******************
+ * FORM routines *
+ ******************/
+extern FORM *new_form(FIELD **);
+
+extern FIELD **form_fields(const FORM *),
+ *current_field(const FORM *);
+
+extern WINDOW *form_win(const FORM *),
+ *form_sub(const FORM *);
+
+extern Form_Hook
+ form_init(const FORM *),
+ form_term(const FORM *),
+ field_init(const FORM *),
+ field_term(const FORM *);
+
+extern int free_form(FORM *),
+ set_form_fields(FORM *,FIELD **),
+ field_count(const FORM *),
+ set_form_win(FORM *,WINDOW *),
+ set_form_sub(FORM *,WINDOW *),
+ set_current_field(FORM *,FIELD *),
+ field_index(const FIELD *),
+ set_form_page(FORM *,int),
+ form_page(const FORM *),
+ scale_form(const FORM *,int *,int *),
+ set_form_init(FORM *,Form_Hook),
+ set_form_term(FORM *,Form_Hook),
+ set_field_init(FORM *,Form_Hook),
+ set_field_term(FORM *,Form_Hook),
+ post_form(FORM *),
+ unpost_form(FORM *),
+ pos_form_cursor(FORM *),
+ form_driver(FORM *,int),
+ set_form_userptr(FORM *,void *),
+ set_form_opts(FORM *,Form_Options),
+ form_opts_on(FORM *,Form_Options),
+ form_opts_off(FORM *,Form_Options),
+ form_request_by_name(const char *);
+
+extern const char
+ *form_request_name(int);
+
+extern void *form_userptr(const FORM *);
+
+extern Form_Options
+ form_opts(const FORM *);
+
+extern bool data_ahead(const FORM *),
+ data_behind(const FORM *);
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* FORM_H */
diff --git a/Source/CursesDialog/form/form.priv.h b/Source/CursesDialog/form/form.priv.h
new file mode 100644
index 0000000000..3691f2fd0c
--- /dev/null
+++ b/Source/CursesDialog/form/form.priv.h
@@ -0,0 +1,134 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "mf_common.h"
+#include "form.h"
+
+/* get around odd bug on aCC and itanium */
+#if defined(__hpux) && defined(__ia64)
+#define getmaxx __getmaxx
+#define getmaxy __getmaxy
+#endif
+
+/* form status values */
+#define _OVLMODE (0x04) /* Form is in overlay mode */
+#define _WINDOW_MODIFIED (0x10) /* Current field window has been modified */
+#define _FCHECK_REQUIRED (0x20) /* Current field needs validation */
+
+/* field status values */
+#define _CHANGED (0x01) /* Field has been changed */
+#define _NEWTOP (0x02) /* Vertical scrolling occured */
+#define _NEWPAGE (0x04) /* field begins new page of form */
+#define _MAY_GROW (0x08) /* dynamic field may still grow */
+
+/* fieldtype status values */
+#define _LINKED_TYPE (0x01) /* Type is a linked type */
+#define _HAS_ARGS (0x02) /* Type has arguments */
+#define _HAS_CHOICE (0x04) /* Type has choice methods */
+#define _RESIDENT (0x08) /* Type is builtin */
+
+/* This are the field options required to be a selectable field in field
+ navigation requests */
+#define O_SELECTABLE (O_ACTIVE | O_VISIBLE)
+
+/* If form is NULL replace form argument by default-form */
+#define Normalize_Form(form) ((form)=(form)?(form):_nc_Default_Form)
+
+/* If field is NULL replace field argument by default-field */
+#define Normalize_Field(field) ((field)=(field)?(field):_nc_Default_Field)
+
+/* Retrieve forms window */
+#define Get_Form_Window(form) \
+ ((form)->sub?(form)->sub:((form)->win?(form)->win:stdscr))
+
+/* Calculate the size for a single buffer for this field */
+#define Buffer_Length(field) ((field)->drows * (field)->dcols)
+
+/* Calculate the total size of all buffers for this field */
+#define Total_Buffer_Size(field) \
+ ( (Buffer_Length(field) + 1) * (1+(field)->nbuf) )
+
+/* Logic to determine whether or not a field is single lined */
+#define Single_Line_Field(field) \
+ (((field)->rows + (field)->nrow) == 1)
+
+/* Logic to determine whether or not a field is selectable */
+#define Field_Is_Selectable(f) (((f)->opts & O_SELECTABLE)==O_SELECTABLE)
+#define Field_Is_Not_Selectable(f) (((f)->opts & O_SELECTABLE)!=O_SELECTABLE)
+
+typedef struct typearg {
+ struct typearg *left;
+ struct typearg *right;
+} TypeArgument;
+
+/* This is a dummy request code (normally invalid) to be used internally
+ with the form_driver() routine to position to the first active field
+ on the form
+*/
+#define FIRST_ACTIVE_MAGIC (-291056)
+
+#define ALL_FORM_OPTS ( \
+ O_NL_OVERLOAD |\
+ O_BS_OVERLOAD )
+
+#define ALL_FIELD_OPTS ( \
+ O_VISIBLE |\
+ O_ACTIVE |\
+ O_PUBLIC |\
+ O_EDIT |\
+ O_WRAP |\
+ O_BLANK |\
+ O_AUTOSKIP|\
+ O_NULLOK |\
+ O_PASSOK |\
+ O_STATIC )
+
+
+#define C_BLANK ' '
+#define is_blank(c) ((c)==C_BLANK)
+
+extern const FIELDTYPE* _nc_Default_FieldType;
+
+extern TypeArgument* _nc_Make_Argument(const FIELDTYPE*,va_list*,int*);
+extern TypeArgument *_nc_Copy_Argument(const FIELDTYPE*,const TypeArgument*, int*);
+extern void _nc_Free_Argument(const FIELDTYPE*,TypeArgument*);
+extern bool _nc_Copy_Type(FIELD*, FIELD const *);
+extern void _nc_Free_Type(FIELD *);
+
+extern int _nc_Synchronize_Attributes(FIELD*);
+extern int _nc_Synchronize_Options(FIELD*,Field_Options);
+extern int _nc_Set_Form_Page(FORM*,int,FIELD*);
+extern int _nc_Refresh_Current_Field(FORM*);
+extern FIELD* _nc_First_Active_Field(FORM*);
+extern bool _nc_Internal_Validation(FORM*);
+extern int _nc_Set_Current_Field(FORM*,FIELD*);
+extern int _nc_Position_Form_Cursor(FORM*);
diff --git a/Source/CursesDialog/form/frm_cursor.c b/Source/CursesDialog/form/frm_cursor.c
new file mode 100644
index 0000000000..6c311fe608
--- /dev/null
+++ b/Source/CursesDialog/form/frm_cursor.c
@@ -0,0 +1,66 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int pos_form_cursor(FORM * form)
+|
+| Description : Moves the form window cursor to the location required
+| by the form driver to resume form processing. This may
+| be needed after the application calls a curses library
+| I/O routine that modifies the cursor position.
+|
+| Return Values : E_OK - Success
+| E_SYSTEM_ERROR - System error.
+| E_BAD_ARGUMENT - Invalid form pointer
+| E_NOT_POSTED - Form is not posted
++--------------------------------------------------------------------------*/
+int pos_form_cursor(FORM * form)
+{
+ int res;
+
+ if (!form)
+ res = E_BAD_ARGUMENT;
+ else
+ {
+ if (!(form->status & _POSTED))
+ res = E_NOT_POSTED;
+ else
+ res = _nc_Position_Form_Cursor(form);
+ }
+ RETURN(res);
+}
+
+/* frm_cursor.c ends here */
diff --git a/Source/CursesDialog/form/frm_data.c b/Source/CursesDialog/form/frm_data.c
new file mode 100644
index 0000000000..fb62ab82ad
--- /dev/null
+++ b/Source/CursesDialog/form/frm_data.c
@@ -0,0 +1,183 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+extern int winnstr(WINDOW *, char *, int);
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : bool data_behind(const FORM *form)
+|
+| Description : Check for off-screen data behind. This is nearly trivial
+| becose the begin of a field is fixed.
+|
+| Return Values : TRUE - there are off-screen data behind
+| FALSE - there are no off-screen data behind
++--------------------------------------------------------------------------*/
+bool data_behind(const FORM *form)
+{
+ bool result = FALSE;
+
+ if (form && (form->status & _POSTED) && form->current)
+ {
+ FIELD *field;
+
+ field = form->current;
+ if (!Single_Line_Field(field))
+ {
+ result = (form->toprow==0) ? FALSE : TRUE;
+ }
+ else
+ {
+ result = (form->begincol==0) ? FALSE : TRUE;
+ }
+ }
+ return(result);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static char * After_Last_Non_Pad_Position(
+| char *buffer,
+| int len,
+| int pad)
+|
+| Description : Find the last position in the buffer that doesn't
+| contain a padding character.
+|
+| Return Values : The pointer to this position
++--------------------------------------------------------------------------*/
+INLINE
+static char * After_Last_Non_Pad_Position(char *buffer, int len, int pad)
+{
+ char *end = buffer + len;
+
+ assert(buffer && len>=0);
+ while ( (buffer < end) && (*(end-1)==pad) )
+ end--;
+
+ return end;
+}
+
+#define SMALL_BUFFER_SIZE (80)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : bool data_ahead(const FORM *form)
+|
+| Description : Check for off-screen data ahead. This is more difficult
+| because a dynamic field has a variable end.
+|
+| Return Values : TRUE - there are off-screen data ahead
+| FALSE - there are no off-screen data ahead
++--------------------------------------------------------------------------*/
+bool data_ahead(const FORM *form)
+{
+ bool result = FALSE;
+
+ if (form && (form->status & _POSTED) && form->current)
+ {
+ static char buffer[SMALL_BUFFER_SIZE + 1];
+ FIELD *field;
+ bool large_buffer;
+ bool cursor_moved = FALSE;
+ char *bp;
+ char *found_content;
+ int pos;
+
+ field = form->current;
+ assert(form->w != 0);
+
+ large_buffer = (field->cols > SMALL_BUFFER_SIZE);
+ if (large_buffer)
+ bp = (char *)malloc((size_t)(field->cols) + 1);
+ else
+ bp = buffer;
+
+ assert(bp != 0);
+
+ if (Single_Line_Field(field))
+ {
+ int check_len;
+
+ pos = form->begincol + field->cols;
+ while (pos < field->dcols)
+ {
+ check_len = field->dcols - pos;
+ if ( check_len >= field->cols )
+ check_len = field->cols;
+ cursor_moved = TRUE;
+ wmove(form->w,0,pos);
+ winnstr(form->w,bp,check_len);
+ found_content =
+ After_Last_Non_Pad_Position(bp,check_len,field->pad);
+ if (found_content==bp)
+ pos += field->cols;
+ else
+ {
+ result = TRUE;
+ break;
+ }
+ }
+ }
+ else
+ {
+ pos = form->toprow + field->rows;
+ while (pos < field->drows)
+ {
+ cursor_moved = TRUE;
+ wmove(form->w,pos,0);
+ pos++;
+ winnstr(form->w,bp,field->cols);
+ found_content =
+ After_Last_Non_Pad_Position(bp,field->cols,field->pad);
+ if (found_content!=bp)
+ {
+ result = TRUE;
+ break;
+ }
+ }
+ }
+
+ if (large_buffer)
+ free(bp);
+
+ if (cursor_moved)
+ wmove(form->w,form->currow,form->curcol);
+ }
+ return(result);
+}
+
+/* frm_data.c ends here */
diff --git a/Source/CursesDialog/form/frm_def.c b/Source/CursesDialog/form/frm_def.c
new file mode 100644
index 0000000000..0b28f5f0e3
--- /dev/null
+++ b/Source/CursesDialog/form/frm_def.c
@@ -0,0 +1,376 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/* this can't be readonly */
+static FORM default_form = {
+ 0, /* status */
+ 0, /* rows */
+ 0, /* cols */
+ 0, /* currow */
+ 0, /* curcol */
+ 0, /* toprow */
+ 0, /* begincol */
+ -1, /* maxfield */
+ -1, /* maxpage */
+ -1, /* curpage */
+ ALL_FORM_OPTS, /* opts */
+ (WINDOW *)0, /* win */
+ (WINDOW *)0, /* sub */
+ (WINDOW *)0, /* w */
+ (FIELD **)0, /* field */
+ (FIELD *)0, /* current */
+ (_PAGE *)0, /* page */
+ (char *)0, /* usrptr */
+ NULL, /* forminit */
+ NULL, /* formterm */
+ NULL, /* fieldinit */
+ NULL /* fieldterm */
+};
+
+FORM *_nc_Default_Form = &default_form;
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static FIELD *Insert_Field_By_Position(
+| FIELD *new_field,
+| FIELD *head )
+|
+| Description : Insert new_field into sorted fieldlist with head "head"
+| and return new head of sorted fieldlist. Sorting
+| criteria is (row,column). This is a circular list.
+|
+| Return Values : New head of sorted fieldlist
++--------------------------------------------------------------------------*/
+static FIELD *Insert_Field_By_Position(FIELD *newfield, FIELD *head)
+{
+ FIELD *current, *newhead;
+
+ assert(newfield != 0);
+
+ if (!head)
+ { /* empty list is trivial */
+ newhead = newfield->snext = newfield->sprev = newfield;
+ }
+ else
+ {
+ newhead = current = head;
+ while((current->frow < newfield->frow) ||
+ ((current->frow==newfield->frow) &&
+ (current->fcol < newfield->fcol)) )
+ {
+ current = current->snext;
+ if (current==head)
+ { /* We cycled through. Reset head to indicate that */
+ head = (FIELD *)0;
+ break;
+ }
+ }
+ /* we leave the loop with current pointing to the field after newfield*/
+ newfield->snext = current;
+ newfield->sprev = current->sprev;
+ newfield->snext->sprev = newfield;
+ newfield->sprev->snext = newfield;
+ if (current==head)
+ newhead = newfield;
+ }
+ return(newhead);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Disconnect_Fields(FORM *form)
+|
+| Description : Break association between form and array of fields.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Disconnect_Fields( FORM * form )
+{
+ if (form->field)
+ {
+ FIELD **fields;
+
+ for(fields=form->field;*fields;fields++)
+ {
+ if (form == (*fields)->form)
+ (*fields)->form = (FORM *)0;
+ }
+
+ form->rows = form->cols = 0;
+ form->maxfield = form->maxpage = -1;
+ form->field = (FIELD **)0;
+ if (form->page)
+ free(form->page);
+ form->page = (_PAGE *)0;
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Connect_Fields(FORM *form, FIELD **fields)
+|
+| Description : Set association between form and array of fields.
+|
+| Return Values : E_OK - no error
+| E_CONNECTED - a field is already connected
+| E_BAD_ARGUMENT - Invalid form pointer or field array
+| E_SYSTEM_ERROR - not enough memory
++--------------------------------------------------------------------------*/
+static int Connect_Fields(FORM * form, FIELD ** fields)
+{
+ int field_cnt, j;
+ int page_nr;
+ int maximum_row_in_field, maximum_col_in_field;
+ _PAGE *pg;
+
+ assert(form != 0);
+
+ form->field = fields;
+ form->maxfield = 0;
+ form->maxpage = 0;
+
+ if (!fields)
+ RETURN(E_OK);
+
+ page_nr = 0;
+ /* store formpointer in fields and count pages */
+ for(field_cnt=0;fields[field_cnt];field_cnt++)
+ {
+ if (fields[field_cnt]->form)
+ RETURN(E_CONNECTED);
+ if ( field_cnt==0 ||
+ (fields[field_cnt]->status & _NEWPAGE))
+ page_nr++;
+ fields[field_cnt]->form = form;
+ }
+ if (field_cnt==0)
+ RETURN(E_BAD_ARGUMENT);
+
+ /* allocate page structures */
+ if ( (pg = (_PAGE *)malloc(page_nr * sizeof(_PAGE))) != (_PAGE *)0 )
+ {
+ form->page = pg;
+ }
+ else
+ RETURN(E_SYSTEM_ERROR);
+
+ /* Cycle through fields and calculate page boundaries as well as
+ size of the form */
+ for(j=0;j<field_cnt;j++)
+ {
+ if (j==0)
+ pg->pmin = j;
+ else
+ {
+ if (fields[j]->status & _NEWPAGE)
+ {
+ pg->pmax = j-1;
+ pg++;
+ pg->pmin = j;
+ }
+ }
+
+ maximum_row_in_field = fields[j]->frow + fields[j]->rows;
+ maximum_col_in_field = fields[j]->fcol + fields[j]->cols;
+
+ if (form->rows < maximum_row_in_field)
+ form->rows = maximum_row_in_field;
+ if (form->cols < maximum_col_in_field)
+ form->cols = maximum_col_in_field;
+ }
+
+ pg->pmax = field_cnt-1;
+ form->maxfield = field_cnt;
+ form->maxpage = page_nr;
+
+ /* Sort fields on form pages */
+ for(page_nr = 0;page_nr < form->maxpage; page_nr++)
+ {
+ FIELD *fld = (FIELD *)0;
+ for(j = form->page[page_nr].pmin;j <= form->page[page_nr].pmax;j++)
+ {
+ fields[j]->index = j;
+ fields[j]->page = page_nr;
+ fld = Insert_Field_By_Position(fields[j],fld);
+ }
+ form->page[page_nr].smin = fld->index;
+ form->page[page_nr].smax = fld->sprev->index;
+ }
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Associate_Fields(FORM *form, FIELD **fields)
+|
+| Description : Set association between form and array of fields.
+| If there are fields, position to first active field.
+|
+| Return Values : E_OK - success
+| any other - error occured
++--------------------------------------------------------------------------*/
+INLINE static int Associate_Fields(FORM *form, FIELD **fields)
+{
+ int res = Connect_Fields(form,fields);
+ if (res == E_OK)
+ {
+ if (form->maxpage>0)
+ {
+ form->curpage = 0;
+ form_driver(form,FIRST_ACTIVE_MAGIC);
+ }
+ else
+ {
+ form->curpage = -1;
+ form->current = (FIELD *)0;
+ }
+ }
+ return(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FORM *new_form( FIELD **fields )
+|
+| Description : Create new form with given array of fields.
+|
+| Return Values : Pointer to form. NULL if error occured.
++--------------------------------------------------------------------------*/
+FORM *new_form(FIELD ** fields)
+{
+ int err = E_SYSTEM_ERROR;
+
+ FORM *form = (FORM *)malloc(sizeof(FORM));
+
+ if (form)
+ {
+ *form = *_nc_Default_Form;
+ if ((err=Associate_Fields(form,fields))!=E_OK)
+ {
+ free_form(form);
+ form = (FORM *)0;
+ }
+ }
+
+ if (!form)
+ SET_ERROR(err);
+
+ return(form);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int free_form( FORM *form )
+|
+| Description : Release internal memory associated with form.
+|
+| Return Values : E_OK - no error
+| E_BAD_ARGUMENT - invalid form pointer
+| E_POSTED - form is posted
++--------------------------------------------------------------------------*/
+int free_form(FORM * form)
+{
+ if ( !form )
+ RETURN(E_BAD_ARGUMENT);
+
+ if ( form->status & _POSTED)
+ RETURN(E_POSTED);
+
+ Disconnect_Fields( form );
+ if (form->page)
+ free(form->page);
+ free(form);
+
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_form_fields( FORM *form, FIELD **fields )
+|
+| Description : Set a new association of an array of fields to a form
+|
+| Return Values : E_OK - no error
+| E_BAD_ARGUMENT - invalid form pointer
+| E_POSTED - form is posted
++--------------------------------------------------------------------------*/
+int set_form_fields(FORM * form, FIELD ** fields)
+{
+ FIELD **old;
+ int res;
+
+ if ( !form )
+ RETURN(E_BAD_ARGUMENT);
+
+ if ( form->status & _POSTED )
+ RETURN(E_POSTED);
+
+ old = form->field;
+ Disconnect_Fields( form );
+
+ if( (res = Associate_Fields( form, fields )) != E_OK )
+ Connect_Fields( form, old );
+
+ RETURN(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FIELD **form_fields( const FORM *form )
+|
+| Description : Retrieve array of fields
+|
+| Return Values : Pointer to field array
++--------------------------------------------------------------------------*/
+FIELD **form_fields(const FORM * form)
+{
+ return (Normalize_Form( form )->field);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int field_count( const FORM *form )
+|
+| Description : Retrieve number of fields
+|
+| Return Values : Number of fields, -1 if none are defined
++--------------------------------------------------------------------------*/
+int field_count(const FORM * form)
+{
+ return (Normalize_Form( form )->maxfield);
+}
+
+/* frm_def.c ends here */
diff --git a/Source/CursesDialog/form/frm_driver.c b/Source/CursesDialog/form/frm_driver.c
new file mode 100644
index 0000000000..b9611bf104
--- /dev/null
+++ b/Source/CursesDialog/form/frm_driver.c
@@ -0,0 +1,3898 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+#if defined(__hpux)
+ #define _XOPEN_SOURCE_EXTENDED
+#endif
+#include "form.priv.h"
+#if defined(__hpux)
+ #undef _XOPEN_SOURCE_EXTENDED
+#endif
+
+/* AIX seems to define this */
+#undef lines
+#undef columns
+
+MODULE_ID("$Id$")
+
+/* These declarations are missing from curses.h on some platforms. */
+extern int winnstr(WINDOW *, char *, int);
+#if defined(__DECCXX_VER) || (defined(__GNUC__) && defined(__osf__))
+extern int waddnstr(WINDOW *,const char *const,int);
+extern void wbkgdset(WINDOW *,chtype);
+#ifndef untouchwin
+extern int untouchwin(WINDOW *);
+#endif
+extern void wcursyncup(WINDOW *);
+extern int copywin(const WINDOW*,WINDOW*,int,int,int,int,int,int,int);
+extern bool is_linetouched(WINDOW *,int);
+extern void wsyncup(WINDOW *);
+extern WINDOW *derwin(WINDOW *,int,int,int,int);
+extern int winsnstr(WINDOW *, const char *,int);
+extern int winsdelln(WINDOW *,int);
+#endif
+
+/*----------------------------------------------------------------------------
+ This is the core module of the form library. It contains the majority
+ of the driver routines as well as the form_driver function.
+
+ Essentially this module is nearly the whole library. This is because
+ all the functions in this module depends on some others in the module,
+ so it makes no sense to split them into separate files because they
+ will always be linked together. The only acceptable concern is turnaround
+ time for this module, but now we have all Pentiums or Riscs, so what!
+
+ The driver routines are grouped into nine generic categories:
+
+ a) Page Navigation ( all functions prefixed by PN_ )
+ The current page of the form is left and some new page is
+ entered.
+ b) Inter-Field Navigation ( all functions prefixed by FN_ )
+ The current field of the form is left and some new field is
+ entered.
+ c) Intra-Field Navigation ( all functions prefixed by IFN_ )
+ The current position in the current field is changed.
+ d) Vertical Scrolling ( all functions prefixed by VSC_ )
+ Esseantially this is a specialization of Intra-Field navigation.
+ It has to check for a multi-line field.
+ e) Horizontal Scrolling ( all functions prefixed by HSC_ )
+ Esseantially this is a specialization of Intra-Field navigation.
+ It has to check for a single-line field.
+ f) Field Editing ( all functions prefixed by FE_ )
+ The content of the current field is changed
+ g) Edit Mode requests ( all functions prefixed by EM_ )
+ Switching between insert and overlay mode
+ h) Field-Validation requests ( all functions prefixed by FV_ )
+ Perform verifications of the field.
+ i) Choice requests ( all functions prefixed by CR_ )
+ Requests to enumerate possible field values
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Some remarks on the placements of assert() macros :
+ I use them only on "strategic" places, i.e. top level entries where
+ I want to make sure that things are set correctly. Throughout subordinate
+ routines I omit them mostly.
+ --------------------------------------------------------------------------*/
+
+/*
+Some options that may effect compatibility in behavior to SVr4 forms,
+but they are here to allow a more intuitive and user friendly behaviour of
+our form implementation. This doesn't affect the API, so we feel it is
+uncritical.
+
+The initial implementation tries to stay very close with the behaviour
+of the original SVr4 implementation, although in some areas it is quite
+clear that this isn't the most appropriate way. As far as possible this
+sources will allow you to build a forms lib that behaves quite similar
+to SVr4, but now and in the future we will give you better options.
+Perhaps at some time we will make this configurable at runtime.
+*/
+
+/* Implement a more user-friendly previous/next word behaviour */
+#define FRIENDLY_PREV_NEXT_WORD (1)
+/* Fix the wrong behaviour for forms with all fields inactive */
+#define FIX_FORM_INACTIVE_BUG (1)
+/* Allow dynamic field growth also when navigating past the end */
+#define GROW_IF_NAVIGATE (1)
+
+/*----------------------------------------------------------------------------
+ Forward references to some internally used static functions
+ --------------------------------------------------------------------------*/
+static int Inter_Field_Navigation ( int (* const fct) (FORM *), FORM * form );
+static int FN_Next_Field (FORM * form);
+static int FN_Previous_Field (FORM * form);
+static int FE_New_Line(FORM *);
+static int FE_Delete_Previous(FORM *);
+
+/*----------------------------------------------------------------------------
+ Macro Definitions.
+
+ Some Remarks on that: I use the convention to use UPPERCASE for constants
+ defined by Macros. If I provide a macro as a kind of inline routine to
+ provide some logic, I use my Upper_Lower case style.
+ --------------------------------------------------------------------------*/
+
+/* Calculate the position of a single row in a field buffer */
+#define Position_Of_Row_In_Buffer(field,row) ((row)*(field)->dcols)
+
+/* Calculate start address for the fields buffer# N */
+#define Address_Of_Nth_Buffer(field,N) \
+ ((field)->buf + (N)*(1+Buffer_Length(field)))
+
+/* Calculate the start address of the row in the fields specified buffer# N */
+#define Address_Of_Row_In_Nth_Buffer(field,N,row) \
+ (Address_Of_Nth_Buffer(field,N) + Position_Of_Row_In_Buffer(field,row))
+
+/* Calculate the start address of the row in the fields primary buffer */
+#define Address_Of_Row_In_Buffer(field,row) \
+ Address_Of_Row_In_Nth_Buffer(field,0,row)
+
+/* Calculate the start address of the row in the forms current field
+ buffer# N */
+#define Address_Of_Current_Row_In_Nth_Buffer(form,N) \
+ Address_Of_Row_In_Nth_Buffer((form)->current,N,(form)->currow)
+
+/* Calculate the start address of the row in the forms current field
+ primary buffer */
+#define Address_Of_Current_Row_In_Buffer(form) \
+ Address_Of_Current_Row_In_Nth_Buffer(form,0)
+
+/* Calculate the address of the cursor in the forms current field
+ primary buffer */
+#define Address_Of_Current_Position_In_Nth_Buffer(form,N) \
+ (Address_Of_Current_Row_In_Nth_Buffer(form,N) + (form)->curcol)
+
+/* Calculate the address of the cursor in the forms current field
+ buffer# N */
+#define Address_Of_Current_Position_In_Buffer(form) \
+ Address_Of_Current_Position_In_Nth_Buffer(form,0)
+
+/* Logic to decide whether or not a field is actually a field with
+ vertical or horizontal scrolling */
+#define Is_Scroll_Field(field) \
+ (((field)->drows > (field)->rows) || \
+ ((field)->dcols > (field)->cols))
+
+/* Logic to decide whether or not a field needs to have an individual window
+ instead of a derived window because it contains invisible parts.
+ This is true for non-public fields and for scrollable fields. */
+#define Has_Invisible_Parts(field) \
+ (!((field)->opts & O_PUBLIC) || \
+ Is_Scroll_Field(field))
+
+/* Logic to decide whether or not a field needs justification */
+#define Justification_Allowed(field) \
+ (((field)->just != NO_JUSTIFICATION) && \
+ (Single_Line_Field(field)) && \
+ (((field)->dcols == (field)->cols) && \
+ ((field)->opts & O_STATIC)) )
+
+/* Logic to determine whether or not a dynamic field may still grow */
+#define Growable(field) ((field)->status & _MAY_GROW)
+
+/* Macro to set the attributes for a fields window */
+#define Set_Field_Window_Attributes(field,win) \
+( wbkgdset((win),(chtype)((field)->pad | (field)->back)), \
+ wattrset((win),(field)->fore) )
+
+/* Logic to decide whether or not a field really appears on the form */
+#define Field_Really_Appears(field) \
+ ((field->form) &&\
+ (field->form->status & _POSTED) &&\
+ (field->opts & O_VISIBLE) &&\
+ (field->page == field->form->curpage))
+
+/* Logic to determine whether or not we are on the first position in the
+ current field */
+#define First_Position_In_Current_Field(form) \
+ (((form)->currow==0) && ((form)->curcol==0))
+
+
+#define Minimum(a,b) (((a)<=(b)) ? (a) : (b))
+#define Maximum(a,b) (((a)>=(b)) ? (a) : (b))
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static char *Get_Start_Of_Data(char * buf, int blen)
+|
+| Description : Return pointer to first non-blank position in buffer.
+| If buffer is empty return pointer to buffer itself.
+|
+| Return Values : Pointer to first non-blank position in buffer
++--------------------------------------------------------------------------*/
+INLINE static char *Get_Start_Of_Data(char * buf, int blen)
+{
+ char *p = buf;
+ char *end = &buf[blen];
+
+ assert(buf && blen>=0);
+ while( (p < end) && is_blank(*p) )
+ p++;
+ return( (p==end) ? buf : p );
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static char *After_End_Of_Data(char * buf, int blen)
+|
+| Description : Return pointer after last non-blank position in buffer.
+| If buffer is empty, return pointer to buffer itself.
+|
+| Return Values : Pointer to position after last non-blank position in
+| buffer.
++--------------------------------------------------------------------------*/
+INLINE static char *After_End_Of_Data(char * buf,int blen)
+{
+ char *p = &buf[blen];
+
+ assert(buf && blen>=0);
+ while( (p>buf) && is_blank(p[-1]) )
+ p--;
+ return( p );
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static char *Get_First_Whitespace_Character(
+| char * buf, int blen)
+|
+| Description : Position to the first whitespace character.
+|
+| Return Values : Pointer to first whitespace character in buffer.
++--------------------------------------------------------------------------*/
+INLINE static char *Get_First_Whitespace_Character(char * buf, int blen)
+{
+ char *p = buf;
+ char *end = &p[blen];
+
+ assert(buf && blen>=0);
+ while( (p < end) && !is_blank(*p))
+ p++;
+ return( (p==end) ? buf : p );
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static char *After_Last_Whitespace_Character(
+| char * buf, int blen)
+|
+| Description : Get the position after the last whitespace character.
+|
+| Return Values : Pointer to position after last whitespace character in
+| buffer.
++--------------------------------------------------------------------------*/
+INLINE static char *After_Last_Whitespace_Character(char * buf, int blen)
+{
+ char *p = &buf[blen];
+
+ assert(buf && blen>=0);
+ while( (p>buf) && !is_blank(p[-1]) )
+ p--;
+ return( p );
+}
+
+/* Set this to 1 to use the div_t version. This is a good idea if your
+ compiler has an intrinsic div() support. Unfortunately GNU-C has it
+ not yet.
+ N.B.: This only works if form->curcol follows immediately form->currow
+ and both are of type int.
+*/
+#define USE_DIV_T (0)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Adjust_Cursor_Position(
+| FORM * form, const char * pos)
+|
+| Description : Set current row and column of the form to values
+| corresponding to the buffer position.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+INLINE static void Adjust_Cursor_Position(FORM * form, const char * pos)
+{
+ FIELD *field;
+ int idx;
+
+ field = form->current;
+ assert( pos >= field->buf && field->dcols > 0);
+ idx = (int)( pos - field->buf );
+#if USE_DIV_T
+ *((div_t *)&(form->currow)) = div(idx,field->dcols);
+#else
+ form->currow = idx / field->dcols;
+ form->curcol = idx - field->cols * form->currow;
+#endif
+ if ( field->drows < form->currow )
+ form->currow = 0;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Buffer_To_Window(
+| const FIELD * field,
+| WINDOW * win)
+|
+| Description : Copy the buffer to the window. If its a multiline
+| field, the buffer is split to the lines of the
+| window without any editing.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Buffer_To_Window(const FIELD * field, WINDOW * win)
+{
+ int width, height;
+ int len;
+ int row;
+ char *pBuffer;
+
+ assert(win && field);
+
+#if defined(__LSB_VERSION__)
+ getmaxyx(win, height, width);
+#else
+ width = getmaxx(win);
+ height = getmaxy(win);
+#endif
+
+ for(row=0, pBuffer=field->buf;
+ row < height;
+ row++, pBuffer += width )
+ {
+ if ((len = (int)( After_End_Of_Data( pBuffer, width ) - pBuffer )) > 0)
+ {
+ wmove( win, row, 0 );
+ waddnstr( win, pBuffer, len );
+ }
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Window_To_Buffer(
+| WINDOW * win,
+| FIELD * field)
+|
+| Description : Copy the content of the window into the buffer.
+| The multiple lines of a window are simply
+| concatenated into the buffer. Pad characters in
+| the window will be replaced by blanks in the buffer.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Window_To_Buffer(WINDOW * win, FIELD * field)
+{
+ int pad;
+ int len = 0;
+ char *p;
+ int row, height;
+
+ assert(win && field && field->buf );
+
+ pad = field->pad;
+ p = field->buf;
+#if defined(__LSB_VERSION__)
+ { int width; getmaxyx(win, height, width); }
+#else
+ height = getmaxy(win);
+#endif
+
+ for(row=0; (row < height) && (row < field->drows); row++ )
+ {
+ wmove( win, row, 0 );
+ len += winnstr( win, p+len, field->dcols );
+ }
+ p[len] = '\0';
+
+ /* replace visual padding character by blanks in buffer */
+ if (pad != C_BLANK)
+ {
+ int i;
+ for(i=0; i<len; i++, p++)
+ {
+ if (*p==pad)
+ *p = C_BLANK;
+ }
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Synchronize_Buffer(FORM * form)
+|
+| Description : If there was a change, copy the content of the
+| window into the buffer, so the buffer is synchronized
+| with the windows content. We have to indicate that the
+| buffer needs validation due to the change.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+INLINE static void Synchronize_Buffer(FORM * form)
+{
+ if (form->status & _WINDOW_MODIFIED)
+ {
+ form->status &= ~_WINDOW_MODIFIED;
+ form->status |= _FCHECK_REQUIRED;
+ Window_To_Buffer(form->w,form->current);
+ wmove(form->w,form->currow,form->curcol);
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Field_Grown( FIELD *field, int amount)
+|
+| Description : This function is called for growable dynamic fields
+| only. It has to increase the buffers and to allocate
+| a new window for this field.
+| This function has the side effect to set a new
+| field-buffer pointer, the dcols and drows values
+| as well as a new current Window for the field.
+|
+| Return Values : TRUE - field successfully increased
+| FALSE - there was some error
++--------------------------------------------------------------------------*/
+static bool Field_Grown(FIELD * field, int amount)
+{
+ bool result = FALSE;
+
+ if (field && Growable(field))
+ {
+ bool single_line_field = Single_Line_Field(field);
+ int old_buflen = Buffer_Length(field);
+ int new_buflen;
+ int old_dcols = field->dcols;
+ int old_drows = field->drows;
+ char *oldbuf = field->buf;
+ char *newbuf;
+
+ int growth;
+ FORM *form = field->form;
+ bool need_visual_update = ((form != (FORM *)0) &&
+ (form->status & _POSTED) &&
+ (form->current==field));
+
+ if (need_visual_update)
+ Synchronize_Buffer(form);
+
+ if (single_line_field)
+ {
+ growth = field->cols * amount;
+ if (field->maxgrow)
+ growth = Minimum(field->maxgrow - field->dcols,growth);
+ field->dcols += growth;
+ if (field->dcols == field->maxgrow)
+ field->status &= ~_MAY_GROW;
+ }
+ else
+ {
+ growth = (field->rows + field->nrow) * amount;
+ if (field->maxgrow)
+ growth = Minimum(field->maxgrow - field->drows,growth);
+ field->drows += growth;
+ if (field->drows == field->maxgrow)
+ field->status &= ~_MAY_GROW;
+ }
+ /* drows, dcols changed, so we get really the new buffer length */
+ new_buflen = Buffer_Length(field);
+ newbuf=(char *)malloc((size_t)Total_Buffer_Size(field));
+ if (!newbuf)
+ { /* restore to previous state */
+ field->dcols = old_dcols;
+ field->drows = old_drows;
+ if (( single_line_field && (field->dcols!=field->maxgrow)) ||
+ (!single_line_field && (field->drows!=field->maxgrow)))
+ field->status |= _MAY_GROW;
+ return FALSE;
+ }
+ else
+ { /* Copy all the buffers. This is the reason why we can't
+ just use realloc().
+ */
+ int i;
+ char *old_bp;
+ char *new_bp;
+
+ field->buf = newbuf;
+ for(i=0;i<=field->nbuf;i++)
+ {
+ new_bp = Address_Of_Nth_Buffer(field,i);
+ old_bp = oldbuf + i*(1+old_buflen);
+ memcpy(new_bp,old_bp,(size_t)old_buflen);
+ if (new_buflen > old_buflen)
+ memset(new_bp + old_buflen,C_BLANK,
+ (size_t)(new_buflen - old_buflen));
+ *(new_bp + new_buflen) = '\0';
+ }
+
+ if (need_visual_update)
+ {
+ WINDOW *new_window = newpad(field->drows,field->dcols);
+ if (!new_window)
+ { /* restore old state */
+ field->dcols = old_dcols;
+ field->drows = old_drows;
+ field->buf = oldbuf;
+ if (( single_line_field &&
+ (field->dcols!=field->maxgrow)) ||
+ (!single_line_field &&
+ (field->drows!=field->maxgrow)))
+ field->status |= _MAY_GROW;
+ free( newbuf );
+ return FALSE;
+ }
+ assert(form!=(FORM *)0);
+ delwin(form->w);
+ form->w = new_window;
+ Set_Field_Window_Attributes(field,form->w);
+ werase(form->w);
+ Buffer_To_Window(field,form->w);
+ untouchwin(form->w);
+ wmove(form->w,form->currow,form->curcol);
+ }
+
+ free(oldbuf);
+ /* reflect changes in linked fields */
+ if (field != field->link)
+ {
+ FIELD *linked_field;
+ for(linked_field = field->link;
+ linked_field!= field;
+ linked_field = linked_field->link)
+ {
+ linked_field->buf = field->buf;
+ linked_field->drows = field->drows;
+ linked_field->dcols = field->dcols;
+ }
+ }
+ result = TRUE;
+ }
+ }
+ return(result);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int _nc_Position_Form_Cursor(FORM * form)
+|
+| Description : Position the cursor in the window for the current
+| field to be in sync. with the currow and curcol
+| values.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid form pointer
+| E_SYSTEM_ERROR - form has no current field or
+| field-window
++--------------------------------------------------------------------------*/
+int
+_nc_Position_Form_Cursor(FORM * form)
+{
+ FIELD *field;
+ WINDOW *formwin;
+
+ if (!form)
+ return(E_BAD_ARGUMENT);
+
+ if (!form->w || !form->current)
+ return(E_SYSTEM_ERROR);
+
+ field = form->current;
+ formwin = Get_Form_Window(form);
+
+ wmove( form->w, form->currow, form->curcol );
+ if ( Has_Invisible_Parts(field) )
+ {
+ /* in this case fieldwin isn't derived from formwin, so we have
+ to move the cursor in formwin by hand... */
+ wmove(formwin,
+ field->frow + form->currow - form->toprow,
+ field->fcol + form->curcol - form->begincol);
+ wcursyncup(formwin);
+ }
+ else
+ wcursyncup(form->w);
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int _nc_Refresh_Current_Field(FORM * form)
+|
+| Description : Propagate the changes in the fields window to the
+| window of the form.
+|
+| Return Values : E_OK - on success
+| E_BAD_ARGUMENT - invalid form pointer
+| E_SYSTEM_ERROR - general error
++--------------------------------------------------------------------------*/
+int
+_nc_Refresh_Current_Field(FORM * form)
+{
+ WINDOW *formwin;
+ FIELD *field;
+
+ if (!form)
+ RETURN(E_BAD_ARGUMENT);
+
+ if (!form->w || !form->current)
+ RETURN(E_SYSTEM_ERROR);
+
+ field = form->current;
+ formwin = Get_Form_Window(form);
+
+ if (field->opts & O_PUBLIC)
+ {
+ if (Is_Scroll_Field(field))
+ {
+ /* Again, in this case the fieldwin isn't derived from formwin,
+ so we have to perform a copy operation. */
+ if (Single_Line_Field(field))
+ { /* horizontal scrolling */
+ if (form->curcol < form->begincol)
+ form->begincol = form->curcol;
+ else
+ {
+ if (form->curcol >= (form->begincol + field->cols))
+ form->begincol = form->curcol - field->cols + 1;
+ }
+ copywin(form->w,
+ formwin,
+ 0,
+ form->begincol,
+ field->frow,
+ field->fcol,
+ field->frow,
+ field->cols + field->fcol - 1,
+ 0);
+ }
+ else
+ { /* A multiline, i.e. vertical scrolling field */
+ int row_after_bottom,first_modified_row,first_unmodified_row;
+
+ if (field->drows > field->rows)
+ {
+ row_after_bottom = form->toprow + field->rows;
+ if (form->currow < form->toprow)
+ {
+ form->toprow = form->currow;
+ field->status |= _NEWTOP;
+ }
+ if (form->currow >= row_after_bottom)
+ {
+ form->toprow = form->currow - field->rows + 1;
+ field->status |= _NEWTOP;
+ }
+ if (field->status & _NEWTOP)
+ { /* means we have to copy whole range */
+ first_modified_row = form->toprow;
+ first_unmodified_row = first_modified_row + field->rows;
+ field->status &= ~_NEWTOP;
+ }
+ else
+ { /* we try to optimize : finding the range of touched
+ lines */
+ first_modified_row = form->toprow;
+ while(first_modified_row < row_after_bottom)
+ {
+ if (is_linetouched(form->w,first_modified_row))
+ break;
+ first_modified_row++;
+ }
+ first_unmodified_row = first_modified_row;
+ while(first_unmodified_row < row_after_bottom)
+ {
+ if (!is_linetouched(form->w,first_unmodified_row))
+ break;
+ first_unmodified_row++;
+ }
+ }
+ }
+ else
+ {
+ first_modified_row = form->toprow;
+ first_unmodified_row = first_modified_row + field->rows;
+ }
+ if (first_unmodified_row != first_modified_row)
+ copywin(form->w,
+ formwin,
+ first_modified_row,
+ 0,
+ field->frow + first_modified_row - form->toprow,
+ field->fcol,
+ field->frow + first_unmodified_row - form->toprow - 1,
+ field->cols + field->fcol - 1,
+ 0);
+ }
+ wsyncup(formwin);
+ }
+ else
+ { /* if the field-window is simply a derived window, i.e. contains
+ no invisible parts, the whole thing is trivial
+ */
+ wsyncup(form->w);
+ }
+ }
+ untouchwin(form->w);
+ return _nc_Position_Form_Cursor(form);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Perform_Justification(
+| FIELD * field,
+| WINDOW * win)
+|
+| Description : Output field with requested justification
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Perform_Justification(FIELD * field, WINDOW * win)
+{
+ char *bp;
+ int len;
+ int col = 0;
+
+ bp = Get_Start_Of_Data(field->buf,Buffer_Length(field));
+ len = (int)(After_End_Of_Data(field->buf,Buffer_Length(field)) - bp);
+
+ if (len>0)
+ {
+ assert(win && (field->drows == 1) && (field->dcols == field->cols));
+
+ switch(field->just)
+ {
+ case JUSTIFY_LEFT:
+ break;
+ case JUSTIFY_CENTER:
+ col = (field->cols - len)/2;
+ break;
+ case JUSTIFY_RIGHT:
+ col = field->cols - len;
+ break;
+ default:
+ break;
+ }
+
+ wmove(win,0,col);
+ waddnstr(win,bp,len);
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Undo_Justification(
+| FIELD * field,
+| WINDOW * win)
+|
+| Description : Display field without any justification, i.e.
+| left justified
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Undo_Justification(FIELD * field, WINDOW * win)
+{
+ char *bp;
+ int len;
+
+ bp = Get_Start_Of_Data(field->buf,Buffer_Length(field));
+ len = (int)(After_End_Of_Data(field->buf,Buffer_Length(field))-bp);
+
+ if (len>0)
+ {
+ assert(win != 0);
+ wmove(win,0,0);
+ waddnstr(win,bp,len);
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_Char(
+| FIELDTYPE * typ,
+| int ch,
+| TypeArgument *argp)
+|
+| Description : Perform a single character check for character ch
+| according to the fieldtype instance.
+|
+| Return Values : TRUE - Character is valid
+| FALSE - Character is invalid
++--------------------------------------------------------------------------*/
+static bool Check_Char(FIELDTYPE * typ, int ch, TypeArgument *argp)
+{
+ if (typ)
+ {
+ if (typ->status & _LINKED_TYPE)
+ {
+ assert(argp != 0);
+ return(
+ Check_Char(typ->left ,ch,argp->left ) ||
+ Check_Char(typ->right,ch,argp->right) );
+ }
+ else
+ {
+ if (typ->ccheck)
+ return typ->ccheck(ch,(void *)argp);
+ }
+ }
+ return (isprint((unsigned char)ch) ? TRUE : FALSE);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Display_Or_Erase_Field(
+| FIELD * field,
+| bool bEraseFlag)
+|
+| Description : Create a subwindow for the field and display the
+| buffer contents (apply justification if required)
+| or simply erase the field.
+|
+| Return Values : E_OK - on success
+| E_SYSTEM_ERROR - some error (typical no memory)
++--------------------------------------------------------------------------*/
+static int Display_Or_Erase_Field(FIELD * field, bool bEraseFlag)
+{
+ WINDOW *win;
+ WINDOW *fwin;
+
+ if (!field)
+ return E_SYSTEM_ERROR;
+
+ fwin = Get_Form_Window(field->form);
+ win = derwin(fwin,
+ field->rows,field->cols,field->frow,field->fcol);
+
+ if (!win)
+ return E_SYSTEM_ERROR;
+ else
+ {
+ if (field->opts & O_VISIBLE)
+ Set_Field_Window_Attributes(field,win);
+ else
+ {
+#if defined(__LSB_VERSION__)
+ /* getattrs() would be handy, but it is not part of LSB 4.0 */
+ attr_t fwinAttrs;
+ short fwinPair;
+ wattr_get(fwin, &fwinAttrs, &fwinPair, 0);
+ wattr_set(win, fwinAttrs, fwinPair, 0);
+#else
+ wattrset(win,getattrs(fwin));
+#endif
+ }
+ werase(win);
+ }
+
+ if (!bEraseFlag)
+ {
+ if (field->opts & O_PUBLIC)
+ {
+ if (Justification_Allowed(field))
+ Perform_Justification(field,win);
+ else
+ Buffer_To_Window(field,win);
+ }
+ field->status &= ~_NEWTOP;
+ }
+ wsyncup(win);
+ delwin(win);
+ return E_OK;
+}
+
+/* Macros to preset the bEraseFlag */
+#define Display_Field(field) Display_Or_Erase_Field(field,FALSE)
+#define Erase_Field(field) Display_Or_Erase_Field(field,TRUE)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Synchronize_Field(FIELD * field)
+|
+| Description : Synchronize the windows content with the value in
+| the buffer.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid field pointer
+| E_SYSTEM_ERROR - some severe basic error
++--------------------------------------------------------------------------*/
+static int Synchronize_Field(FIELD * field)
+{
+ FORM *form;
+ int res = E_OK;
+
+ if (!field)
+ return(E_BAD_ARGUMENT);
+
+ if (((form=field->form) != (FORM *)0)
+ && Field_Really_Appears(field))
+ {
+ if (field == form->current)
+ {
+ form->currow = form->curcol = form->toprow = form->begincol = 0;
+ werase(form->w);
+
+ if ( (field->opts & O_PUBLIC) && Justification_Allowed(field) )
+ Undo_Justification( field, form->w );
+ else
+ Buffer_To_Window( field, form->w );
+
+ field->status |= _NEWTOP;
+ res = _nc_Refresh_Current_Field( form );
+ }
+ else
+ res = Display_Field( field );
+ }
+ field->status |= _CHANGED;
+ return(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Synchronize_Linked_Fields(FIELD * field)
+|
+| Description : Propagate the Synchronize_Field function to all linked
+| fields. The first error that occurs in the sequence
+| of updates is the returnvalue.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid field pointer
+| E_SYSTEM_ERROR - some severe basic error
++--------------------------------------------------------------------------*/
+static int Synchronize_Linked_Fields(FIELD * field)
+{
+ FIELD *linked_field;
+ int res = E_OK;
+ int syncres;
+
+ if (!field)
+ return(E_BAD_ARGUMENT);
+
+ if (!field->link)
+ return(E_SYSTEM_ERROR);
+
+ for(linked_field = field->link;
+ linked_field!= field;
+ linked_field = linked_field->link )
+ {
+ if (((syncres=Synchronize_Field(linked_field)) != E_OK) &&
+ (res==E_OK))
+ res = syncres;
+ }
+ return(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int _nc_Synchronize_Attributes(FIELD * field)
+|
+| Description : If a fields visual attributes have changed, this
+| routine is called to propagate those changes to the
+| screen.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid field pointer
+| E_SYSTEM_ERROR - some severe basic error
++--------------------------------------------------------------------------*/
+int _nc_Synchronize_Attributes(FIELD * field)
+{
+ FORM *form;
+ int res = E_OK;
+ WINDOW *formwin;
+
+ if (!field)
+ return(E_BAD_ARGUMENT);
+
+ if (((form=field->form) != (FORM *)0)
+ && Field_Really_Appears(field))
+ {
+ if (form->current==field)
+ {
+ Synchronize_Buffer(form);
+ Set_Field_Window_Attributes(field,form->w);
+ werase(form->w);
+ if (field->opts & O_PUBLIC)
+ {
+ if (Justification_Allowed(field))
+ Undo_Justification(field,form->w);
+ else
+ Buffer_To_Window(field,form->w);
+ }
+ else
+ {
+ formwin = Get_Form_Window(form);
+ copywin(form->w,formwin,
+ 0,0,
+ field->frow,field->fcol,
+ field->rows-1,field->cols-1,0);
+ wsyncup(formwin);
+ Buffer_To_Window(field,form->w);
+ field->status |= _NEWTOP; /* fake refresh to paint all */
+ _nc_Refresh_Current_Field(form);
+ }
+ }
+ else
+ {
+ res = Display_Field(field);
+ }
+ }
+ return(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int _nc_Synchronize_Options(FIELD * field,
+| Field_Options newopts)
+|
+| Description : If a fields options have changed, this routine is
+| called to propagate these changes to the screen and
+| to really change the behaviour of the field.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid field pointer
+| E_SYSTEM_ERROR - some severe basic error
++--------------------------------------------------------------------------*/
+int
+_nc_Synchronize_Options(FIELD *field, Field_Options newopts)
+{
+ Field_Options oldopts;
+ Field_Options changed_opts;
+ FORM *form;
+ int res = E_OK;
+
+ if (!field)
+ return(E_BAD_ARGUMENT);
+
+ oldopts = field->opts;
+ changed_opts = oldopts ^ newopts;
+ field->opts = newopts;
+ form = field->form;
+
+ if (form)
+ {
+ if (form->current == field)
+ {
+ field->opts = oldopts;
+ return(E_CURRENT);
+ }
+
+ if (form->status & _POSTED)
+ {
+ if (form->curpage == field->page)
+ {
+ if (changed_opts & O_VISIBLE)
+ {
+ if (newopts & O_VISIBLE)
+ res = Display_Field(field);
+ else
+ res = Erase_Field(field);
+ }
+ else
+ {
+ if ((changed_opts & O_PUBLIC) &&
+ (newopts & O_VISIBLE))
+ res = Display_Field(field);
+ }
+ }
+ }
+ }
+
+ if (changed_opts & O_STATIC)
+ {
+ bool single_line_field = Single_Line_Field(field);
+ int res2 = E_OK;
+
+ if (newopts & O_STATIC)
+ { /* the field becomes now static */
+ field->status &= ~_MAY_GROW;
+ /* if actually we have no hidden columns, justification may
+ occur again */
+ if (single_line_field &&
+ (field->cols == field->dcols) &&
+ (field->just != NO_JUSTIFICATION) &&
+ Field_Really_Appears(field))
+ {
+ res2 = Display_Field(field);
+ }
+ }
+ else
+ { /* field is no longer static */
+ if ((field->maxgrow==0) ||
+ ( single_line_field && (field->dcols < field->maxgrow)) ||
+ (!single_line_field && (field->drows < field->maxgrow)))
+ {
+ field->status |= _MAY_GROW;
+ /* a field with justification now changes its behaviour,
+ so we must redisplay it */
+ if (single_line_field &&
+ (field->just != NO_JUSTIFICATION) &&
+ Field_Really_Appears(field))
+ {
+ res2 = Display_Field(field);
+ }
+ }
+ }
+ if (res2 != E_OK)
+ res = res2;
+ }
+
+ return(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int _nc_Set_Current_Field(FORM * form,
+| FIELD * newfield)
+|
+| Description : Make the newfield the new current field.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid form or field pointer
+| E_SYSTEM_ERROR - some severe basic error
++--------------------------------------------------------------------------*/
+int
+_nc_Set_Current_Field(FORM *form, FIELD *newfield)
+{
+ FIELD *field;
+ WINDOW *new_window;
+
+ if (!form || !newfield || !form->current || (newfield->form!=form))
+ return(E_BAD_ARGUMENT);
+
+ if ( (form->status & _IN_DRIVER) )
+ return(E_BAD_STATE);
+
+ if (!(form->field))
+ return(E_NOT_CONNECTED);
+
+ field = form->current;
+
+ if ((field!=newfield) ||
+ !(form->status & _POSTED))
+ {
+ if ((form->w) &&
+ (field->opts & O_VISIBLE) &&
+ (field->form->curpage == field->page))
+ {
+ _nc_Refresh_Current_Field(form);
+ if (field->opts & O_PUBLIC)
+ {
+ if (field->drows > field->rows)
+ {
+ if (form->toprow==0)
+ field->status &= ~_NEWTOP;
+ else
+ field->status |= _NEWTOP;
+ }
+ else
+ {
+ if (Justification_Allowed(field))
+ {
+ Window_To_Buffer(form->w,field);
+ werase(form->w);
+ Perform_Justification(field,form->w);
+ wsyncup(form->w);
+ }
+ }
+ }
+ delwin(form->w);
+ }
+
+ field = newfield;
+
+ if (Has_Invisible_Parts(field))
+ new_window = newpad(field->drows,field->dcols);
+ else
+ new_window = derwin(Get_Form_Window(form),
+ field->rows,field->cols,field->frow,field->fcol);
+
+ if (!new_window)
+ return(E_SYSTEM_ERROR);
+
+ form->current = field;
+ form->w = new_window;
+ form->status &= ~_WINDOW_MODIFIED;
+ Set_Field_Window_Attributes(field,form->w);
+
+ if (Has_Invisible_Parts(field))
+ {
+ werase(form->w);
+ Buffer_To_Window(field,form->w);
+ }
+ else
+ {
+ if (Justification_Allowed(field))
+ {
+ werase(form->w);
+ Undo_Justification(field,form->w);
+ wsyncup(form->w);
+ }
+ }
+
+ untouchwin(form->w);
+ }
+
+ form->currow = form->curcol = form->toprow = form->begincol = 0;
+ return(E_OK);
+}
+
+/*----------------------------------------------------------------------------
+ Intra-Field Navigation routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Next_Character(FORM * form)
+|
+| Description : Move to the next character in the field. In a multiline
+| field this wraps at the end of the line.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - at the rightmost position
++--------------------------------------------------------------------------*/
+static int IFN_Next_Character(FORM * form)
+{
+ FIELD *field = form->current;
+
+ if ((++(form->curcol))==field->dcols)
+ {
+ if ((++(form->currow))==field->drows)
+ {
+#if GROW_IF_NAVIGATE
+ if (!Single_Line_Field(field) && Field_Grown(field,1)) {
+ form->curcol = 0;
+ return(E_OK);
+ }
+#endif
+ form->currow--;
+#if GROW_IF_NAVIGATE
+ if (Single_Line_Field(field) && Field_Grown(field,1))
+ return(E_OK);
+#endif
+ form->curcol--;
+ return(E_REQUEST_DENIED);
+ }
+ form->curcol = 0;
+ }
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Previous_Character(FORM * form)
+|
+| Description : Move to the previous character in the field. In a
+| multiline field this wraps and the beginning of the
+| line.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - at the leftmost position
++--------------------------------------------------------------------------*/
+static int IFN_Previous_Character(FORM * form)
+{
+ if ((--(form->curcol))<0)
+ {
+ if ((--(form->currow))<0)
+ {
+ form->currow++;
+ form->curcol++;
+ return(E_REQUEST_DENIED);
+ }
+ form->curcol = form->current->dcols - 1;
+ }
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Next_Line(FORM * form)
+|
+| Description : Move to the beginning of the next line in the field
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - at the last line
++--------------------------------------------------------------------------*/
+static int IFN_Next_Line(FORM * form)
+{
+ FIELD *field = form->current;
+
+ if ((++(form->currow))==field->drows)
+ {
+#if GROW_IF_NAVIGATE
+ if (!Single_Line_Field(field) && Field_Grown(field,1))
+ return(E_OK);
+#endif
+ form->currow--;
+ return(E_REQUEST_DENIED);
+ }
+ form->curcol = 0;
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Previous_Line(FORM * form)
+|
+| Description : Move to the beginning of the previous line in the field
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - at the first line
++--------------------------------------------------------------------------*/
+static int IFN_Previous_Line(FORM * form)
+{
+ if ( (--(form->currow)) < 0 )
+ {
+ form->currow++;
+ return(E_REQUEST_DENIED);
+ }
+ form->curcol = 0;
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Next_Word(FORM * form)
+|
+| Description : Move to the beginning of the next word in the field.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - there is no next word
++--------------------------------------------------------------------------*/
+static int IFN_Next_Word(FORM * form)
+{
+ FIELD *field = form->current;
+ char *bp = Address_Of_Current_Position_In_Buffer(form);
+ char *s;
+ char *t;
+
+ /* We really need access to the data, so we have to synchronize */
+ Synchronize_Buffer(form);
+
+ /* Go to the first whitespace after the current position (including
+ current position). This is then the startpoint to look for the
+ next non-blank data */
+ s = Get_First_Whitespace_Character(bp,Buffer_Length(field) -
+ (int)(bp - field->buf));
+
+ /* Find the start of the next word */
+ t = Get_Start_Of_Data(s,Buffer_Length(field) -
+ (int)(s - field->buf));
+#if !FRIENDLY_PREV_NEXT_WORD
+ if (s==t)
+ return(E_REQUEST_DENIED);
+ else
+#endif
+ {
+ Adjust_Cursor_Position(form,t);
+ return(E_OK);
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Previous_Word(FORM * form)
+|
+| Description : Move to the beginning of the previous word in the field.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - there is no previous word
++--------------------------------------------------------------------------*/
+static int IFN_Previous_Word(FORM * form)
+{
+ FIELD *field = form->current;
+ char *bp = Address_Of_Current_Position_In_Buffer(form);
+ char *s;
+ char *t;
+ bool again = FALSE;
+
+ /* We really need access to the data, so we have to synchronize */
+ Synchronize_Buffer(form);
+
+ s = After_End_Of_Data(field->buf,(int)(bp-field->buf));
+ /* s points now right after the last non-blank in the buffer before bp.
+ If bp was in a word, s equals bp. In this case we must find the last
+ whitespace in the buffer before bp and repeat the game to really find
+ the previous word! */
+ if (s==bp)
+ again = TRUE;
+
+ /* And next call now goes backward to look for the last whitespace
+ before that, pointing right after this, so it points to the begin
+ of the previous word.
+ */
+ t = After_Last_Whitespace_Character(field->buf,(int)(s - field->buf));
+#if !FRIENDLY_PREV_NEXT_WORD
+ if (s==t)
+ return(E_REQUEST_DENIED);
+#endif
+ if (again)
+ { /* and do it again, replacing bp by t */
+ s = After_End_Of_Data(field->buf,(int)(t - field->buf));
+ t = After_Last_Whitespace_Character(field->buf,(int)(s - field->buf));
+#if !FRIENDLY_PREV_NEXT_WORD
+ if (s==t)
+ return(E_REQUEST_DENIED);
+#endif
+ }
+ Adjust_Cursor_Position(form,t);
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Beginning_Of_Field(FORM * form)
+|
+| Description : Place the cursor at the first non-pad character in
+| the field.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int IFN_Beginning_Of_Field(FORM * form)
+{
+ FIELD *field = form->current;
+
+ Synchronize_Buffer(form);
+ Adjust_Cursor_Position(form,
+ Get_Start_Of_Data(field->buf,Buffer_Length(field)));
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_End_Of_Field(FORM * form)
+|
+| Description : Place the cursor after the last non-pad character in
+| the field. If the field occupies the last position in
+| the buffer, the cursos is positioned on the last
+| character.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int IFN_End_Of_Field(FORM * form)
+{
+ FIELD *field = form->current;
+ char *pos;
+
+ Synchronize_Buffer(form);
+ pos = After_End_Of_Data(field->buf,Buffer_Length(field));
+ if (pos==(field->buf + Buffer_Length(field)))
+ pos--;
+ Adjust_Cursor_Position(form,pos);
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Beginning_Of_Line(FORM * form)
+|
+| Description : Place the cursor on the first non-pad character in
+| the current line of the field.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int IFN_Beginning_Of_Line(FORM * form)
+{
+ FIELD *field = form->current;
+
+ Synchronize_Buffer(form);
+ Adjust_Cursor_Position(form,
+ Get_Start_Of_Data(Address_Of_Current_Row_In_Buffer(form),
+ field->dcols));
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_End_Of_Line(FORM * form)
+|
+| Description : Place the cursor after the last non-pad character in the
+| current line of the field. If the field occupies the
+| last column in the line, the cursor is positioned on the
+| last character of the line.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int IFN_End_Of_Line(FORM * form)
+{
+ FIELD *field = form->current;
+ char *pos;
+ char *bp;
+
+ Synchronize_Buffer(form);
+ bp = Address_Of_Current_Row_In_Buffer(form);
+ pos = After_End_Of_Data(bp,field->dcols);
+ if (pos == (bp + field->dcols))
+ pos--;
+ Adjust_Cursor_Position(form,pos);
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Left_Character(FORM * form)
+|
+| Description : Move one character to the left in the current line.
+| This doesn't cycle.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - already in first column
++--------------------------------------------------------------------------*/
+static int IFN_Left_Character(FORM * form)
+{
+ if ( (--(form->curcol)) < 0 )
+ {
+ form->curcol++;
+ return(E_REQUEST_DENIED);
+ }
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Right_Character(FORM * form)
+|
+| Description : Move one character to the right in the current line.
+| This doesn't cycle.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - already in last column
++--------------------------------------------------------------------------*/
+static int IFN_Right_Character(FORM * form)
+{
+ if ( (++(form->curcol)) == form->current->dcols )
+ {
+#if GROW_IF_NAVIGATE
+ FIELD *field = form->current;
+ if (Single_Line_Field(field) && Field_Grown(field,1))
+ return(E_OK);
+#endif
+ --(form->curcol);
+ return(E_REQUEST_DENIED);
+ }
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Up_Character(FORM * form)
+|
+| Description : Move one line up. This doesn't cycle through the lines
+| of the field.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - already in last column
++--------------------------------------------------------------------------*/
+static int IFN_Up_Character(FORM * form)
+{
+ if ( (--(form->currow)) < 0 )
+ {
+ form->currow++;
+ return(E_REQUEST_DENIED);
+ }
+ return(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int IFN_Down_Character(FORM * form)
+|
+| Description : Move one line down. This doesn't cycle through the
+| lines of the field.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - already in last column
++--------------------------------------------------------------------------*/
+static int IFN_Down_Character(FORM * form)
+{
+ FIELD *field = form->current;
+
+ if ( (++(form->currow)) == field->drows )
+ {
+#if GROW_IF_NAVIGATE
+ if (!Single_Line_Field(field) && Field_Grown(field,1))
+ return(E_OK);
+#endif
+ --(form->currow);
+ return(E_REQUEST_DENIED);
+ }
+ return(E_OK);
+}
+/*----------------------------------------------------------------------------
+ END of Intra-Field Navigation routines
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Vertical scrolling helper routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int VSC_Generic(FORM *form, int lines)
+|
+| Description : Scroll multi-line field forward (lines>0) or
+| backward (lines<0) this many lines.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - can't scroll
++--------------------------------------------------------------------------*/
+static int VSC_Generic(FORM *form, int lines)
+{
+ FIELD *field = form->current;
+ int res = E_REQUEST_DENIED;
+ int rows_to_go = (lines > 0 ? lines : -lines);
+
+ if (lines > 0)
+ {
+ if ( (rows_to_go + form->toprow) > (field->drows - field->rows) )
+ rows_to_go = (field->drows - field->rows - form->toprow);
+
+ if (rows_to_go > 0)
+ {
+ form->currow += rows_to_go;
+ form->toprow += rows_to_go;
+ res = E_OK;
+ }
+ }
+ else
+ {
+ if (rows_to_go > form->toprow)
+ rows_to_go = form->toprow;
+
+ if (rows_to_go > 0)
+ {
+ form->currow -= rows_to_go;
+ form->toprow -= rows_to_go;
+ res = E_OK;
+ }
+ }
+ return(res);
+}
+/*----------------------------------------------------------------------------
+ End of Vertical scrolling helper routines
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Vertical scrolling routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Vertical_Scrolling(
+| int (* const fct) (FORM *),
+| FORM * form)
+|
+| Description : Performs the generic vertical scrolling routines.
+| This has to check for a multi-line field and to set
+| the _NEWTOP flag if scrolling really occured.
+|
+| Return Values : Propagated error code from low-level driver calls
++--------------------------------------------------------------------------*/
+static int Vertical_Scrolling(int (* const fct) (FORM *), FORM * form)
+{
+ int res = E_REQUEST_DENIED;
+
+ if (!Single_Line_Field(form->current))
+ {
+ res = fct(form);
+ if (res == E_OK)
+ form->current->status |= _NEWTOP;
+ }
+ return(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int VSC_Scroll_Line_Forward(FORM * form)
+|
+| Description : Scroll multi-line field forward a line
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data ahead
++--------------------------------------------------------------------------*/
+static int VSC_Scroll_Line_Forward(FORM * form)
+{
+ return VSC_Generic(form,1);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int VSC_Scroll_Line_Backward(FORM * form)
+|
+| Description : Scroll multi-line field backward a line
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data behind
++--------------------------------------------------------------------------*/
+static int VSC_Scroll_Line_Backward(FORM * form)
+{
+ return VSC_Generic(form,-1);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int VSC_Scroll_Page_Forward(FORM * form)
+|
+| Description : Scroll a multi-line field forward a page
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data ahead
++--------------------------------------------------------------------------*/
+static int VSC_Scroll_Page_Forward(FORM * form)
+{
+ return VSC_Generic(form,form->current->rows);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int VSC_Scroll_Half_Page_Forward(FORM * form)
+|
+| Description : Scroll a multi-line field forward half a page
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data ahead
++--------------------------------------------------------------------------*/
+static int VSC_Scroll_Half_Page_Forward(FORM * form)
+{
+ return VSC_Generic(form,(form->current->rows + 1)/2);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int VSC_Scroll_Page_Backward(FORM * form)
+|
+| Description : Scroll a multi-line field backward a page
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data behind
++--------------------------------------------------------------------------*/
+static int VSC_Scroll_Page_Backward(FORM * form)
+{
+ return VSC_Generic(form, -(form->current->rows));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int VSC_Scroll_Half_Page_Backward(FORM * form)
+|
+| Description : Scroll a multi-line field backward half a page
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data behind
++--------------------------------------------------------------------------*/
+static int VSC_Scroll_Half_Page_Backward(FORM * form)
+{
+ return VSC_Generic(form, -((form->current->rows + 1)/2));
+}
+/*----------------------------------------------------------------------------
+ End of Vertical scrolling routines
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Horizontal scrolling helper routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int HSC_Generic(FORM *form, int columns)
+|
+| Description : Scroll single-line field forward (columns>0) or
+| backward (columns<0) this many columns.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - can't scroll
++--------------------------------------------------------------------------*/
+static int HSC_Generic(FORM *form, int columns)
+{
+ FIELD *field = form->current;
+ int res = E_REQUEST_DENIED;
+ int cols_to_go = (columns > 0 ? columns : -columns);
+
+ if (columns > 0)
+ {
+ if ((cols_to_go + form->begincol) > (field->dcols - field->cols))
+ cols_to_go = field->dcols - field->cols - form->begincol;
+
+ if (cols_to_go > 0)
+ {
+ form->curcol += cols_to_go;
+ form->begincol += cols_to_go;
+ res = E_OK;
+ }
+ }
+ else
+ {
+ if ( cols_to_go > form->begincol )
+ cols_to_go = form->begincol;
+
+ if (cols_to_go > 0)
+ {
+ form->curcol -= cols_to_go;
+ form->begincol -= cols_to_go;
+ res = E_OK;
+ }
+ }
+ return(res);
+}
+/*----------------------------------------------------------------------------
+ End of Horizontal scrolling helper routines
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Horizontal scrolling routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Horizontal_Scrolling(
+| int (* const fct) (FORM *),
+| FORM * form)
+|
+| Description : Performs the generic horizontal scrolling routines.
+| This has to check for a single-line field.
+|
+| Return Values : Propagated error code from low-level driver calls
++--------------------------------------------------------------------------*/
+static int Horizontal_Scrolling(int (* const fct) (FORM *), FORM * form)
+{
+ if (Single_Line_Field(form->current))
+ return fct(form);
+ else
+ return(E_REQUEST_DENIED);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int HSC_Scroll_Char_Forward(FORM * form)
+|
+| Description : Scroll single-line field forward a character
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data ahead
++--------------------------------------------------------------------------*/
+static int HSC_Scroll_Char_Forward(FORM *form)
+{
+ return HSC_Generic(form,1);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int HSC_Scroll_Char_Backward(FORM * form)
+|
+| Description : Scroll single-line field backward a character
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data behind
++--------------------------------------------------------------------------*/
+static int HSC_Scroll_Char_Backward(FORM *form)
+{
+ return HSC_Generic(form,-1);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int HSC_Horizontal_Line_Forward(FORM* form)
+|
+| Description : Scroll single-line field forward a line
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data ahead
++--------------------------------------------------------------------------*/
+static int HSC_Horizontal_Line_Forward(FORM * form)
+{
+ return HSC_Generic(form,form->current->cols);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int HSC_Horizontal_Half_Line_Forward(FORM* form)
+|
+| Description : Scroll single-line field forward half a line
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data ahead
++--------------------------------------------------------------------------*/
+static int HSC_Horizontal_Half_Line_Forward(FORM * form)
+{
+ return HSC_Generic(form,(form->current->cols + 1)/2);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int HSC_Horizontal_Line_Backward(FORM* form)
+|
+| Description : Scroll single-line field backward a line
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data behind
++--------------------------------------------------------------------------*/
+static int HSC_Horizontal_Line_Backward(FORM * form)
+{
+ return HSC_Generic(form,-(form->current->cols));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int HSC_Horizontal_Half_Line_Backward(FORM* form)
+|
+| Description : Scroll single-line field backward half a line
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - no data behind
++--------------------------------------------------------------------------*/
+static int HSC_Horizontal_Half_Line_Backward(FORM * form)
+{
+ return HSC_Generic(form,-((form->current->cols + 1)/2));
+}
+
+/*----------------------------------------------------------------------------
+ End of Horizontal scrolling routines
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Helper routines for Field Editing
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Is_There_Room_For_A_Line(FORM * form)
+|
+| Description : Check whether or not there is enough room in the
+| buffer to enter a whole line.
+|
+| Return Values : TRUE - there is enough space
+| FALSE - there is not enough space
++--------------------------------------------------------------------------*/
+INLINE static bool Is_There_Room_For_A_Line(FORM * form)
+{
+ FIELD *field = form->current;
+ char *begin_of_last_line, *s;
+
+ Synchronize_Buffer(form);
+ begin_of_last_line = Address_Of_Row_In_Buffer(field,(field->drows-1));
+ s = After_End_Of_Data(begin_of_last_line,field->dcols);
+ return ((s==begin_of_last_line) ? TRUE : FALSE);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
+|
+| Description : Checks whether or not there is room for a new character
+| in the current line.
+|
+| Return Values : TRUE - there is room
+| FALSE - there is not enough room (line full)
++--------------------------------------------------------------------------*/
+INLINE static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
+{
+ int last_char_in_line;
+
+ wmove(form->w,form->currow,form->current->dcols-1);
+ last_char_in_line = (int)(winch(form->w) & A_CHARTEXT);
+ wmove(form->w,form->currow,form->curcol);
+ return (((last_char_in_line == form->current->pad) ||
+ is_blank(last_char_in_line)) ? TRUE : FALSE);
+}
+
+#define There_Is_No_Room_For_A_Char_In_Line(f) \
+ !Is_There_Room_For_A_Char_In_Line(f)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Insert_String(
+| FORM * form,
+| int row,
+| char *txt,
+| int len )
+|
+| Description : Insert the 'len' characters beginning at pointer 'txt'
+| into the 'row' of the 'form'. The insertion occurs
+| on the beginning of the row, all other characters are
+| moved to the right. After the text a pad character will
+| be inserted to separate the text from the rest. If
+| necessary the insertion moves characters on the next
+| line to make place for the requested insertion string.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED -
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+static int Insert_String(FORM *form, int row, char *txt, int len)
+{
+ FIELD *field = form->current;
+ char *bp = Address_Of_Row_In_Buffer(field,row);
+ int datalen = (int)(After_End_Of_Data(bp,field->dcols) - bp);
+ int freelen = field->dcols - datalen;
+ int requiredlen = len+1;
+ char *split;
+ int result = E_REQUEST_DENIED;
+ char *Space;
+
+ Space = (char*)malloc(2*sizeof(char));
+ strcpy(Space, " ");
+
+ if (freelen >= requiredlen)
+ {
+ wmove(form->w,row,0);
+ winsnstr(form->w,txt,len);
+ wmove(form->w,row,len);
+ winsnstr(form->w,Space,1);
+ free(Space);
+ return E_OK;
+ }
+ else
+ { /* we have to move characters on the next line. If we are on the
+ last line this may work, if the field is growable */
+ if ((row == (field->drows - 1)) && Growable(field))
+ {
+ if (!Field_Grown(field,1))
+ {
+ free(Space);
+ return(E_SYSTEM_ERROR);
+ }
+ /* !!!Side-Effect : might be changed due to growth!!! */
+ bp = Address_Of_Row_In_Buffer(field,row);
+ }
+
+ if (row < (field->drows - 1))
+ {
+ split = After_Last_Whitespace_Character(bp,
+ (int)(Get_Start_Of_Data(bp + field->dcols - requiredlen ,
+ requiredlen) - bp));
+ /* split points now to the first character of the portion of the
+ line that must be moved to the next line */
+ datalen = (int)(split-bp); /* + freelen has to stay on this line */
+ freelen = field->dcols - (datalen + freelen); /* for the next line */
+
+ if ((result=Insert_String(form,row+1,split,freelen))==E_OK)
+ {
+ wmove(form->w,row,datalen);
+ wclrtoeol(form->w);
+ wmove(form->w,row,0);
+ winsnstr(form->w,txt,len);
+ wmove(form->w,row,len);
+ winsnstr(form->w,Space,1);
+ free(Space);
+ return E_OK;
+ }
+ }
+ free(Space);
+ return(result);
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Wrapping_Not_Necessary_Or_Wrapping_Ok(
+| FORM * form)
+|
+| Description : If a character has been entered into a field, it may
+| be that wrapping has to occur. This routine checks
+| whether or not wrapping is required and if so, performs
+| the wrapping.
+|
+| Return Values : E_OK - no wrapping required or wrapping
+| was successful
+| E_REQUEST_DENIED -
+| E_SYSTEM_ERROR - some system error
++--------------------------------------------------------------------------*/
+static int Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM * form)
+{
+ FIELD *field = form->current;
+ int result = E_REQUEST_DENIED;
+ bool Last_Row = ((field->drows - 1) == form->currow);
+
+ if ( (field->opts & O_WRAP) && /* wrapping wanted */
+ (!Single_Line_Field(field)) && /* must be multi-line */
+ (There_Is_No_Room_For_A_Char_In_Line(form)) && /* line is full */
+ (!Last_Row || Growable(field)) ) /* there are more lines*/
+ {
+ char *bp;
+ char *split;
+ int chars_to_be_wrapped;
+ int chars_to_remain_on_line;
+ if (Last_Row)
+ { /* the above logic already ensures, that in this case the field
+ is growable */
+ if (!Field_Grown(field,1))
+ return E_SYSTEM_ERROR;
+ }
+ bp = Address_Of_Current_Row_In_Buffer(form);
+ Window_To_Buffer(form->w,field);
+ split = After_Last_Whitespace_Character(bp,field->dcols);
+ /* split points to the first character of the sequence to be brought
+ on the next line */
+ chars_to_remain_on_line = (int)(split - bp);
+ chars_to_be_wrapped = field->dcols - chars_to_remain_on_line;
+ if (chars_to_remain_on_line > 0)
+ {
+ if ((result=Insert_String(form,form->currow+1,split,
+ chars_to_be_wrapped)) == E_OK)
+ {
+ wmove(form->w,form->currow,chars_to_remain_on_line);
+ wclrtoeol(form->w);
+ if (form->curcol >= chars_to_remain_on_line)
+ {
+ form->currow++;
+ form->curcol -= chars_to_remain_on_line;
+ }
+ return E_OK;
+ }
+ }
+ else
+ return E_OK;
+ if (result!=E_OK)
+ {
+ wmove(form->w,form->currow,form->curcol);
+ wdelch(form->w);
+ Window_To_Buffer(form->w,field);
+ result = E_REQUEST_DENIED;
+ }
+ }
+ else
+ result = E_OK; /* wrapping was not necessary */
+ return(result);
+}
+
+/*----------------------------------------------------------------------------
+ Field Editing routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Field_Editing(
+| int (* const fct) (FORM *),
+| FORM * form)
+|
+| Description : Generic routine for field editing requests. The driver
+| routines are only called for editable fields, the
+| _WINDOW_MODIFIED flag is set if editing occured.
+| This is somewhat special due to the overload semantics
+| of the NEW_LINE and DEL_PREV requests.
+|
+| Return Values : Error code from low level drivers.
++--------------------------------------------------------------------------*/
+static int Field_Editing(int (* const fct) (FORM *), FORM * form)
+{
+ int res = E_REQUEST_DENIED;
+
+ /* We have to deal here with the specific case of the overloaded
+ behaviour of New_Line and Delete_Previous requests.
+ They may end up in navigational requests if we are on the first
+ character in a field. But navigation is also allowed on non-
+ editable fields.
+ */
+ if ((fct==FE_Delete_Previous) &&
+ (form->opts & O_BS_OVERLOAD) &&
+ First_Position_In_Current_Field(form) )
+ {
+ res = Inter_Field_Navigation(FN_Previous_Field,form);
+ }
+ else
+ {
+ if (fct==FE_New_Line)
+ {
+ if ((form->opts & O_NL_OVERLOAD) &&
+ First_Position_In_Current_Field(form))
+ {
+ res = Inter_Field_Navigation(FN_Next_Field,form);
+ }
+ else
+ /* FE_New_Line deals itself with the _WINDOW_MODIFIED flag */
+ res = fct(form);
+ }
+ else
+ {
+ /* From now on, everything must be editable */
+ if (form->current->opts & O_EDIT)
+ {
+ res = fct(form);
+ if (res==E_OK)
+ form->status |= _WINDOW_MODIFIED;
+ }
+ }
+ }
+ return res;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_New_Line(FORM * form)
+|
+| Description : Perform a new line request. This is rather complex
+| compared to other routines in this code due to the
+| rather difficult to understand description in the
+| manuals.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - new line not allowed
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+static int FE_New_Line(FORM * form)
+{
+ FIELD *field = form->current;
+ char *bp, *t;
+ bool Last_Row = ((field->drows - 1)==form->currow);
+
+ if (form->status & _OVLMODE)
+ {
+ if (Last_Row &&
+ (!(Growable(field) && !Single_Line_Field(field))))
+ {
+ if (!(form->opts & O_NL_OVERLOAD))
+ return(E_REQUEST_DENIED);
+ wclrtoeol(form->w);
+ /* we have to set this here, although it is also
+ handled in the generic routine. The reason is,
+ that FN_Next_Field may fail, but the form is
+ definitively changed */
+ form->status |= _WINDOW_MODIFIED;
+ return Inter_Field_Navigation(FN_Next_Field,form);
+ }
+ else
+ {
+ if (Last_Row && !Field_Grown(field,1))
+ { /* N.B.: due to the logic in the 'if', LastRow==TRUE
+ means here that the field is growable and not
+ a single-line field */
+ return(E_SYSTEM_ERROR);
+ }
+ wclrtoeol(form->w);
+ form->currow++;
+ form->curcol = 0;
+ form->status |= _WINDOW_MODIFIED;
+ return(E_OK);
+ }
+ }
+ else
+ { /* Insert Mode */
+ if (Last_Row &&
+ !(Growable(field) && !Single_Line_Field(field)))
+ {
+ if (!(form->opts & O_NL_OVERLOAD))
+ return(E_REQUEST_DENIED);
+ return Inter_Field_Navigation(FN_Next_Field,form);
+ }
+ else
+ {
+ bool May_Do_It = !Last_Row && Is_There_Room_For_A_Line(form);
+
+ if (!(May_Do_It || Growable(field)))
+ return(E_REQUEST_DENIED);
+ if (!May_Do_It && !Field_Grown(field,1))
+ return(E_SYSTEM_ERROR);
+
+ bp= Address_Of_Current_Position_In_Buffer(form);
+ t = After_End_Of_Data(bp,field->dcols - form->curcol);
+ wclrtoeol(form->w);
+ form->currow++;
+ form->curcol=0;
+ wmove(form->w,form->currow,form->curcol);
+ winsertln(form->w);
+ waddnstr(form->w,bp,(int)(t-bp));
+ form->status |= _WINDOW_MODIFIED;
+ return E_OK;
+ }
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_Insert_Character(FORM * form)
+|
+| Description : Insert blank character at the cursor position
+|
+| Return Values : E_OK
+| E_REQUEST_DENIED
++--------------------------------------------------------------------------*/
+static int FE_Insert_Character(FORM * form)
+{
+ FIELD *field = form->current;
+ int result = E_REQUEST_DENIED;
+
+ if (Check_Char(field->type,(int)C_BLANK,(TypeArgument *)(field->arg)))
+ {
+ bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
+
+ if (There_Is_Room ||
+ ((Single_Line_Field(field) && Growable(field))))
+ {
+ if (!There_Is_Room && !Field_Grown(field,1))
+ result = E_SYSTEM_ERROR;
+ else
+ {
+ winsch(form->w,(chtype)C_BLANK);
+ result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form);
+ }
+ }
+ }
+ return result;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_Insert_Line(FORM * form)
+|
+| Description : Insert a blank line at the cursor position
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - line can not be inserted
++--------------------------------------------------------------------------*/
+static int FE_Insert_Line(FORM * form)
+{
+ FIELD *field = form->current;
+ int result = E_REQUEST_DENIED;
+
+ if (Check_Char(field->type,(int)C_BLANK,(TypeArgument *)(field->arg)))
+ {
+ bool Maybe_Done = (form->currow!=(field->drows-1)) &&
+ Is_There_Room_For_A_Line(form);
+
+ if (!Single_Line_Field(field) &&
+ (Maybe_Done || Growable(field)))
+ {
+ if (!Maybe_Done && !Field_Grown(field,1))
+ result = E_SYSTEM_ERROR;
+ else
+ {
+ form->curcol = 0;
+ winsertln(form->w);
+ result = E_OK;
+ }
+ }
+ }
+ return result;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_Delete_Character(FORM * form)
+|
+| Description : Delete character at the cursor position
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int FE_Delete_Character(FORM * form)
+{
+ wdelch(form->w);
+ return E_OK;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_Delete_Previous(FORM * form)
+|
+| Description : Delete character before cursor. Again this is a rather
+| difficult piece compared to others due to the overloading
+| semantics of backspace.
+| N.B.: The case of overloaded BS on first field position
+| is already handled in the generic routine.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - Character can't be deleted
++--------------------------------------------------------------------------*/
+static int FE_Delete_Previous(FORM * form)
+{
+ FIELD *field = form->current;
+
+ if (First_Position_In_Current_Field(form))
+ return E_REQUEST_DENIED;
+
+ if ( (--(form->curcol))<0 )
+ {
+ char *this_line, *prev_line, *prev_end, *this_end;
+
+ form->curcol++;
+ if (form->status & _OVLMODE)
+ return E_REQUEST_DENIED;
+
+ prev_line = Address_Of_Row_In_Buffer(field,(form->currow-1));
+ this_line = Address_Of_Row_In_Buffer(field,(form->currow));
+ Synchronize_Buffer(form);
+ prev_end = After_End_Of_Data(prev_line,field->dcols);
+ this_end = After_End_Of_Data(this_line,field->dcols);
+ if ((int)(this_end-this_line) >
+ (field->cols-(int)(prev_end-prev_line)))
+ return E_REQUEST_DENIED;
+ wdeleteln(form->w);
+ Adjust_Cursor_Position(form,prev_end);
+ wmove(form->w,form->currow,form->curcol);
+ waddnstr(form->w,this_line,(int)(this_end-this_line));
+ }
+ else
+ {
+ wmove(form->w,form->currow,form->curcol);
+ wdelch(form->w);
+ }
+ return E_OK;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_Delete_Line(FORM * form)
+|
+| Description : Delete line at cursor position.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int FE_Delete_Line(FORM * form)
+{
+ form->curcol = 0;
+ wdeleteln(form->w);
+ return E_OK;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_Delete_Word(FORM * form)
+|
+| Description : Delete word at cursor position
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - failure
++--------------------------------------------------------------------------*/
+static int FE_Delete_Word(FORM * form)
+{
+ FIELD *field = form->current;
+ char *bp = Address_Of_Current_Row_In_Buffer(form);
+ char *ep = bp + field->dcols;
+ char *cp = bp + form->curcol;
+ char *s;
+
+ Synchronize_Buffer(form);
+ if (is_blank(*cp))
+ return E_REQUEST_DENIED; /* not in word */
+
+ /* move cursor to begin of word and erase to end of screen-line */
+ Adjust_Cursor_Position(form,
+ After_Last_Whitespace_Character(bp,form->curcol));
+ wmove(form->w,form->currow,form->curcol);
+ wclrtoeol(form->w);
+
+ /* skip over word in buffer */
+ s = Get_First_Whitespace_Character(cp,(int)(ep-cp));
+ /* to begin of next word */
+ s = Get_Start_Of_Data(s,(int)(ep - s));
+ if ( (s!=cp) && !is_blank(*s))
+ {
+ /* copy remaining line to window */
+ waddnstr(form->w,s,(int)(s - After_End_Of_Data(s,(int)(ep - s))));
+ }
+ return E_OK;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_Clear_To_End_Of_Line(FORM * form)
+|
+| Description : Clear to end of current line.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int FE_Clear_To_End_Of_Line(FORM * form)
+{
+ wclrtoeol(form->w);
+ return E_OK;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_Clear_To_End_Of_Form(FORM * form)
+|
+| Description : Clear to end of form.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int FE_Clear_To_End_Of_Form(FORM * form)
+{
+ wclrtobot(form->w);
+ return E_OK;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FE_Clear_Field(FORM * form)
+|
+| Description : Clear entire field.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int FE_Clear_Field(FORM * form)
+{
+ form->currow = form->curcol = 0;
+ werase(form->w);
+ return E_OK;
+}
+/*----------------------------------------------------------------------------
+ END of Field Editing routines
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Edit Mode routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int EM_Overlay_Mode(FORM * form)
+|
+| Description : Switch to overlay mode.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int EM_Overlay_Mode(FORM * form)
+{
+ form->status |= _OVLMODE;
+ return E_OK;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int EM_Insert_Mode(FORM * form)
+|
+| Description : Switch to insert mode
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+static int EM_Insert_Mode(FORM * form)
+{
+ form->status &= ~_OVLMODE;
+ return E_OK;
+}
+
+/*----------------------------------------------------------------------------
+ END of Edit Mode routines
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Helper routines for Choice Requests
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Next_Choice(
+| FIELDTYPE * typ,
+| FIELD * field,
+| TypeArgument *argp)
+|
+| Description : Get the next field choice. For linked types this is
+| done recursively.
+|
+| Return Values : TRUE - next choice successfully retrieved
+| FALSE - couldn't retrieve next choice
++--------------------------------------------------------------------------*/
+static bool Next_Choice(FIELDTYPE * typ, FIELD *field, TypeArgument *argp)
+{
+ if (!typ || !(typ->status & _HAS_CHOICE))
+ return FALSE;
+
+ if (typ->status & _LINKED_TYPE)
+ {
+ assert(argp != 0);
+ return(
+ Next_Choice(typ->left ,field,argp->left) ||
+ Next_Choice(typ->right,field,argp->right) );
+ }
+ else
+ {
+ assert(typ->next != 0);
+ return typ->next(field,(void *)argp);
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Previous_Choice(
+| FIELDTYPE * typ,
+| FIELD * field,
+| TypeArgument *argp)
+|
+| Description : Get the previous field choice. For linked types this
+| is done recursively.
+|
+| Return Values : TRUE - previous choice successfully retrieved
+| FALSE - couldn't retrieve previous choice
++--------------------------------------------------------------------------*/
+static bool Previous_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
+{
+ if (!typ || !(typ->status & _HAS_CHOICE))
+ return FALSE;
+
+ if (typ->status & _LINKED_TYPE)
+ {
+ assert(argp != 0);
+ return(
+ Previous_Choice(typ->left ,field,argp->left) ||
+ Previous_Choice(typ->right,field,argp->right));
+ }
+ else
+ {
+ assert(typ->prev != 0);
+ return typ->prev(field,(void *)argp);
+ }
+}
+/*----------------------------------------------------------------------------
+ End of Helper routines for Choice Requests
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Routines for Choice Requests
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int CR_Next_Choice(FORM * form)
+|
+| Description : Get the next field choice.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - next choice couldn't be retrieved
++--------------------------------------------------------------------------*/
+static int CR_Next_Choice(FORM * form)
+{
+ FIELD *field = form->current;
+ Synchronize_Buffer(form);
+ return ((Next_Choice(field->type,field,(TypeArgument *)(field->arg))) ?
+ E_OK : E_REQUEST_DENIED);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int CR_Previous_Choice(FORM * form)
+|
+| Description : Get the previous field choice.
+|
+| Return Values : E_OK - success
+| E_REQUEST_DENIED - prev. choice couldn't be retrieved
++--------------------------------------------------------------------------*/
+static int CR_Previous_Choice(FORM * form)
+{
+ FIELD *field = form->current;
+ Synchronize_Buffer(form);
+ return ((Previous_Choice(field->type,field,(TypeArgument *)(field->arg))) ?
+ E_OK : E_REQUEST_DENIED);
+}
+/*----------------------------------------------------------------------------
+ End of Routines for Choice Requests
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Helper routines for Field Validations.
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_Field(
+| FIELDTYPE * typ,
+| FIELD * field,
+| TypeArgument * argp)
+|
+| Description : Check the field according to its fieldtype and its
+| actual arguments. For linked fieldtypes this is done
+| recursively.
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid.
++--------------------------------------------------------------------------*/
+static bool Check_Field(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
+{
+ if (typ)
+ {
+ if (field->opts & O_NULLOK)
+ {
+ char *bp = field->buf;
+ assert(bp != 0);
+ while(is_blank(*bp))
+ { bp++; }
+ if (*bp == '\0')
+ return TRUE;
+ }
+
+ if (typ->status & _LINKED_TYPE)
+ {
+ assert(argp != 0);
+ return(
+ Check_Field(typ->left ,field,argp->left ) ||
+ Check_Field(typ->right,field,argp->right) );
+ }
+ else
+ {
+ if (typ->fcheck)
+ return typ->fcheck(field,(void *)argp);
+ }
+ }
+ return TRUE;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : bool _nc_Internal_Validation(FORM * form )
+|
+| Description : Validate the current field of the form.
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid
++--------------------------------------------------------------------------*/
+bool
+_nc_Internal_Validation(FORM *form)
+{
+ FIELD *field;
+
+ field = form->current;
+
+ Synchronize_Buffer(form);
+ if ((form->status & _FCHECK_REQUIRED) ||
+ (!(field->opts & O_PASSOK)))
+ {
+ if (!Check_Field(field->type,field,(TypeArgument *)(field->arg)))
+ return FALSE;
+ form->status &= ~_FCHECK_REQUIRED;
+ field->status |= _CHANGED;
+ Synchronize_Linked_Fields(field);
+ }
+ return TRUE;
+}
+/*----------------------------------------------------------------------------
+ End of Helper routines for Field Validations.
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Routines for Field Validation.
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FV_Validation(FORM * form)
+|
+| Description : Validate the current field of the form.
+|
+| Return Values : E_OK - field valid
+| E_INVALID_FIELD - field not valid
++--------------------------------------------------------------------------*/
+static int FV_Validation(FORM * form)
+{
+ if (_nc_Internal_Validation(form))
+ return E_OK;
+ else
+ return E_INVALID_FIELD;
+}
+/*----------------------------------------------------------------------------
+ End of routines for Field Validation.
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Helper routines for Inter-Field Navigation
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static FIELD *Next_Field_On_Page(FIELD * field)
+|
+| Description : Get the next field after the given field on the current
+| page. The order of fields is the one defined by the
+| fields array. Only visible and active fields are
+| counted.
+|
+| Return Values : Pointer to the next field.
++--------------------------------------------------------------------------*/
+INLINE static FIELD *Next_Field_On_Page(FIELD * field)
+{
+ FORM *form = field->form;
+ FIELD **field_on_page = &form->field[field->index];
+ FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
+ FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
+
+ do
+ {
+ field_on_page =
+ (field_on_page==last_on_page) ? first_on_page : field_on_page + 1;
+ if (Field_Is_Selectable(*field_on_page))
+ break;
+ } while(field!=(*field_on_page));
+ return(*field_on_page);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : FIELD* _nc_First_Active_Field(FORM * form)
+|
+| Description : Get the first active field on the current page,
+| if there are such. If there are none, get the first
+| visible field on the page. If there are also none,
+| we return the first field on page and hope the best.
+|
+| Return Values : Pointer to calculated field.
++--------------------------------------------------------------------------*/
+FIELD*
+_nc_First_Active_Field(FORM * form)
+{
+ FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
+ FIELD *proposed = Next_Field_On_Page(*last_on_page);
+
+ if (proposed == *last_on_page)
+ { /* there might be the special situation, where there is no
+ active and visible field on the current page. We then select
+ the first visible field on this readonly page
+ */
+ if (Field_Is_Not_Selectable(proposed))
+ {
+ FIELD **field = &form->field[proposed->index];
+ FIELD **first = &form->field[form->page[form->curpage].pmin];
+
+ do
+ {
+ field = (field==last_on_page) ? first : field + 1;
+ if (((*field)->opts & O_VISIBLE))
+ break;
+ } while(proposed!=(*field));
+
+ proposed = *field;
+
+ if ((proposed == *last_on_page) && !(proposed->opts&O_VISIBLE))
+ { /* This means, there is also no visible field on the page.
+ So we propose the first one and hope the very best...
+ Some very clever user has designed a readonly and invisible
+ page on this form.
+ */
+ proposed = *first;
+ }
+ }
+ }
+ return(proposed);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static FIELD *Previous_Field_On_Page(FIELD * field)
+|
+| Description : Get the previous field before the given field on the
+| current page. The order of fields is the one defined by
+| the fields array. Only visible and active fields are
+| counted.
+|
+| Return Values : Pointer to the previous field.
++--------------------------------------------------------------------------*/
+INLINE static FIELD *Previous_Field_On_Page(FIELD * field)
+{
+ FORM *form = field->form;
+ FIELD **field_on_page = &form->field[field->index];
+ FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
+ FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
+
+ do
+ {
+ field_on_page =
+ (field_on_page==first_on_page) ? last_on_page : field_on_page - 1;
+ if (Field_Is_Selectable(*field_on_page))
+ break;
+ } while(field!=(*field_on_page));
+
+ return (*field_on_page);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static FIELD *Sorted_Next_Field(FIELD * field)
+|
+| Description : Get the next field after the given field on the current
+| page. The order of fields is the one defined by the
+| (row,column) geometry, rows are major.
+|
+| Return Values : Pointer to the next field.
++--------------------------------------------------------------------------*/
+INLINE static FIELD *Sorted_Next_Field(FIELD * field)
+{
+ FIELD *field_on_page = field;
+
+ do
+ {
+ field_on_page = field_on_page->snext;
+ if (Field_Is_Selectable(field_on_page))
+ break;
+ } while(field_on_page!=field);
+
+ return (field_on_page);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static FIELD *Sorted_Previous_Field(FIELD * field)
+|
+| Description : Get the previous field before the given field on the
+| current page. The order of fields is the one defined
+| by the (row,column) geometry, rows are major.
+|
+| Return Values : Pointer to the previous field.
++--------------------------------------------------------------------------*/
+INLINE static FIELD *Sorted_Previous_Field(FIELD * field)
+{
+ FIELD *field_on_page = field;
+
+ do
+ {
+ field_on_page = field_on_page->sprev;
+ if (Field_Is_Selectable(field_on_page))
+ break;
+ } while(field_on_page!=field);
+
+ return (field_on_page);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static FIELD *Left_Neighbour_Field(FIELD * field)
+|
+| Description : Get the left neighbour of the field on the same line
+| and the same page. Cycles through the line.
+|
+| Return Values : Pointer to left neighbour field.
++--------------------------------------------------------------------------*/
+INLINE static FIELD *Left_Neighbour_Field(FIELD * field)
+{
+ FIELD *field_on_page = field;
+
+ /* For a field that has really a left neighbour, the while clause
+ immediately fails and the loop is left, positioned at the right
+ neighbour. Otherwise we cycle backwards through the sorted fieldlist
+ until we enter the same line (from the right end).
+ */
+ do
+ {
+ field_on_page = Sorted_Previous_Field(field_on_page);
+ } while(field_on_page->frow != field->frow);
+
+ return (field_on_page);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static FIELD *Right_Neighbour_Field(FIELD * field)
+|
+| Description : Get the right neighbour of the field on the same line
+| and the same page.
+|
+| Return Values : Pointer to right neighbour field.
++--------------------------------------------------------------------------*/
+INLINE static FIELD *Right_Neighbour_Field(FIELD * field)
+{
+ FIELD *field_on_page = field;
+
+ /* See the comments on Left_Neighbour_Field to understand how it works */
+ do
+ {
+ field_on_page = Sorted_Next_Field(field_on_page);
+ } while(field_on_page->frow != field->frow);
+
+ return (field_on_page);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static FIELD *Upper_Neighbour_Field(FIELD * field)
+|
+| Description : Because of the row-major nature of sorting the fields,
+| its more difficult to define whats the upper neighbour
+| field really means. We define that it must be on a
+| 'previous' line (cyclic order!) and is the rightmost
+| field laying on the left side of the given field. If
+| this set is empty, we take the first field on the line.
+|
+| Return Values : Pointer to the upper neighbour field.
++--------------------------------------------------------------------------*/
+static FIELD *Upper_Neighbour_Field(FIELD * field)
+{
+ FIELD *field_on_page = field;
+ int frow = field->frow;
+ int fcol = field->fcol;
+
+ /* Walk back to the 'previous' line. The second term in the while clause
+ just guarantees that we stop if we cycled through the line because
+ there might be no 'previous' line if the page has just one line.
+ */
+ do
+ {
+ field_on_page = Sorted_Previous_Field(field_on_page);
+ } while(field_on_page->frow==frow && field_on_page->fcol!=fcol);
+
+ if (field_on_page->frow!=frow)
+ { /* We really found a 'previous' line. We are positioned at the
+ rightmost field on this line */
+ frow = field_on_page->frow;
+
+ /* We walk to the left as long as we are really right of the
+ field. */
+ while(field_on_page->frow==frow && field_on_page->fcol>fcol)
+ field_on_page = Sorted_Previous_Field(field_on_page);
+
+ /* If we wrapped, just go to the right which is the first field on
+ the row */
+ if (field_on_page->frow!=frow)
+ field_on_page = Sorted_Next_Field(field_on_page);
+ }
+
+ return (field_on_page);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static FIELD *Down_Neighbour_Field(FIELD * field)
+|
+| Description : Because of the row-major nature of sorting the fields,
+| its more difficult to define whats the down neighbour
+| field really means. We define that it must be on a
+| 'next' line (cyclic order!) and is the leftmost
+| field laying on the right side of the given field. If
+| this set is empty, we take the last field on the line.
+|
+| Return Values : Pointer to the upper neighbour field.
++--------------------------------------------------------------------------*/
+static FIELD *Down_Neighbour_Field(FIELD * field)
+{
+ FIELD *field_on_page = field;
+ int frow = field->frow;
+ int fcol = field->fcol;
+
+ /* Walk forward to the 'next' line. The second term in the while clause
+ just guarantees that we stop if we cycled through the line because
+ there might be no 'next' line if the page has just one line.
+ */
+ do
+ {
+ field_on_page = Sorted_Next_Field(field_on_page);
+ } while(field_on_page->frow==frow && field_on_page->fcol!=fcol);
+
+ if (field_on_page->frow!=frow)
+ { /* We really found a 'next' line. We are positioned at the rightmost
+ field on this line */
+ frow = field_on_page->frow;
+
+ /* We walk to the right as long as we are really left of the
+ field. */
+ while(field_on_page->frow==frow && field_on_page->fcol<fcol)
+ field_on_page = Sorted_Next_Field(field_on_page);
+
+ /* If we wrapped, just go to the left which is the last field on
+ the row */
+ if (field_on_page->frow!=frow)
+ field_on_page = Sorted_Previous_Field(field_on_page);
+ }
+
+ return(field_on_page);
+}
+
+/*----------------------------------------------------------------------------
+ Inter-Field Navigation routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Inter_Field_Navigation(
+| int (* const fct) (FORM *),
+| FORM * form)
+|
+| Description : Generic behaviour for changing the current field, the
+| field is left and a new field is entered. So the field
+| must be validated and the field init/term hooks must
+| be called.
+|
+| Return Values : E_OK - success
+| E_INVALID_FIELD - field is invalid
+| some other - error from subordinate call
++--------------------------------------------------------------------------*/
+static int Inter_Field_Navigation(int (* const fct) (FORM *),FORM *form)
+{
+ int res;
+
+ if (!_nc_Internal_Validation(form))
+ res = E_INVALID_FIELD;
+ else
+ {
+ Call_Hook(form,fieldterm);
+ res = fct(form);
+ Call_Hook(form,fieldinit);
+ }
+ return res;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Next_Field(FORM * form)
+|
+| Description : Move to the next field on the current page of the form
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Next_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Next_Field_On_Page(form->current));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Previous_Field(FORM * form)
+|
+| Description : Move to the previous field on the current page of the
+| form
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Previous_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Previous_Field_On_Page(form->current));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_First_Field(FORM * form)
+|
+| Description : Move to the first field on the current page of the form
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_First_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Next_Field_On_Page(form->field[form->page[form->curpage].pmax]));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Last_Field(FORM * form)
+|
+| Description : Move to the last field on the current page of the form
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Last_Field(FORM * form)
+{
+ return
+ _nc_Set_Current_Field(form,
+ Previous_Field_On_Page(form->field[form->page[form->curpage].pmin]));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Sorted_Next_Field(FORM * form)
+|
+| Description : Move to the sorted next field on the current page
+| of the form.
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Sorted_Next_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Sorted_Next_Field(form->current));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Sorted_Previous_Field(FORM * form)
+|
+| Description : Move to the sorted previous field on the current page
+| of the form.
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Sorted_Previous_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Sorted_Previous_Field(form->current));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Sorted_First_Field(FORM * form)
+|
+| Description : Move to the sorted first field on the current page
+| of the form.
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Sorted_First_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Sorted_Next_Field(form->field[form->page[form->curpage].smax]));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Sorted_Last_Field(FORM * form)
+|
+| Description : Move to the sorted last field on the current page
+| of the form.
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Sorted_Last_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Sorted_Previous_Field(form->field[form->page[form->curpage].smin]));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Left_Field(FORM * form)
+|
+| Description : Get the field on the left of the current field on the
+| same line and the same page. Cycles through the line.
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Left_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Left_Neighbour_Field(form->current));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Right_Field(FORM * form)
+|
+| Description : Get the field on the right of the current field on the
+| same line and the same page. Cycles through the line.
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Right_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Right_Neighbour_Field(form->current));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Up_Field(FORM * form)
+|
+| Description : Get the upper neighbour of the current field. This
+| cycles through the page. See the comments of the
+| Upper_Neighbour_Field function to understand how
+| 'upper' is defined.
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Up_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Upper_Neighbour_Field(form->current));
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int FN_Down_Field(FORM * form)
+|
+| Description : Get the down neighbour of the current field. This
+| cycles through the page. See the comments of the
+| Down_Neighbour_Field function to understand how
+| 'down' is defined.
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int FN_Down_Field(FORM * form)
+{
+ return _nc_Set_Current_Field(form,
+ Down_Neighbour_Field(form->current));
+}
+/*----------------------------------------------------------------------------
+ END of Field Navigation routines
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Helper routines for Page Navigation
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int _nc_Set_Form_Page(FORM * form,
+| int page,
+| FIELD * field)
+|
+| Description : Make the given page nr. the current page and make
+| the given field the current field on the page. If
+| for the field NULL is given, make the first field on
+| the page the current field. The routine acts only
+| if the requested page is not the current page.
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+int
+_nc_Set_Form_Page(FORM * form, int page, FIELD * field)
+{
+ int res = E_OK;
+
+ if ((form->curpage!=page))
+ {
+ FIELD *last_field, *field_on_page;
+
+ werase(Get_Form_Window(form));
+ form->curpage = page;
+ last_field = field_on_page = form->field[form->page[page].smin];
+ do
+ {
+ if (field_on_page->opts & O_VISIBLE)
+ if ((res=Display_Field(field_on_page))!=E_OK)
+ return(res);
+ field_on_page = field_on_page->snext;
+ } while(field_on_page != last_field);
+
+ if (field)
+ res = _nc_Set_Current_Field(form,field);
+ else
+ /* N.B.: we don't encapsulate this by Inter_Field_Navigation(),
+ because this is already executed in a page navigation
+ context that contains field navigation
+ */
+ res = FN_First_Field(form);
+ }
+ return(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Next_Page_Number(const FORM * form)
+|
+| Description : Calculate the page number following the current page
+| number. This cycles if the highest page number is
+| reached.
+|
+| Return Values : The next page number
++--------------------------------------------------------------------------*/
+INLINE static int Next_Page_Number(const FORM * form)
+{
+ return (form->curpage + 1) % form->maxpage;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Previous_Page_Number(const FORM * form)
+|
+| Description : Calculate the page number before the current page
+| number. This cycles if the first page number is
+| reached.
+|
+| Return Values : The previous page number
++--------------------------------------------------------------------------*/
+INLINE static int Previous_Page_Number(const FORM * form)
+{
+ return (form->curpage!=0 ? form->curpage - 1 : form->maxpage - 1);
+}
+
+/*----------------------------------------------------------------------------
+ Page Navigation routines
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Page_Navigation(
+| int (* const fct) (FORM *),
+| FORM * form)
+|
+| Description : Generic behaviour for changing a page. This means
+| that the field is left and a new field is entered.
+| So the field must be validated and the field init/term
+| hooks must be called. Because also the page is changed,
+| the forms init/term hooks must be called also.
+|
+| Return Values : E_OK - success
+| E_INVALID_FIELD - field is invalid
+| some other - error from subordinate call
++--------------------------------------------------------------------------*/
+static int Page_Navigation(int (* const fct) (FORM *), FORM * form)
+{
+ int res;
+
+ if (!_nc_Internal_Validation(form))
+ res = E_INVALID_FIELD;
+ else
+ {
+ Call_Hook(form,fieldterm);
+ Call_Hook(form,formterm);
+ res = fct(form);
+ Call_Hook(form,forminit);
+ Call_Hook(form,fieldinit);
+ }
+ return res;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int PN_Next_Page(FORM * form)
+|
+| Description : Move to the next page of the form
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int PN_Next_Page(FORM * form)
+{
+ return _nc_Set_Form_Page(form,Next_Page_Number(form),(FIELD *)0);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int PN_Previous_Page(FORM * form)
+|
+| Description : Move to the previous page of the form
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int PN_Previous_Page(FORM * form)
+{
+ return _nc_Set_Form_Page(form,Previous_Page_Number(form),(FIELD *)0);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int PN_First_Page(FORM * form)
+|
+| Description : Move to the first page of the form
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int PN_First_Page(FORM * form)
+{
+ return _nc_Set_Form_Page(form,0,(FIELD *)0);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int PN_Last_Page(FORM * form)
+|
+| Description : Move to the last page of the form
+|
+| Return Values : E_OK - success
+| != E_OK - error from subordinate call
++--------------------------------------------------------------------------*/
+static int PN_Last_Page(FORM * form)
+{
+ return _nc_Set_Form_Page(form,form->maxpage-1,(FIELD *)0);
+}
+/*----------------------------------------------------------------------------
+ END of Field Navigation routines
+ --------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Helper routines for the core form driver.
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Data_Entry(FORM * form,int c)
+|
+| Description : Enter character c into at the current position of the
+| current field of the form.
+|
+| Return Values : E_OK -
+| E_REQUEST_DENIED -
+| E_SYSTEM_ERROR -
++--------------------------------------------------------------------------*/
+static int Data_Entry(FORM * form, int c)
+{
+ FIELD *field = form->current;
+ int result = E_REQUEST_DENIED;
+
+ if ( (field->opts & O_EDIT)
+#if FIX_FORM_INACTIVE_BUG
+ && (field->opts & O_ACTIVE)
+#endif
+ )
+ {
+ if ( (field->opts & O_BLANK) &&
+ First_Position_In_Current_Field(form) &&
+ !(form->status & _FCHECK_REQUIRED) &&
+ !(form->status & _WINDOW_MODIFIED) )
+ werase(form->w);
+
+ if (form->status & _OVLMODE)
+ {
+ waddch(form->w,(chtype)c);
+ }
+ else /* no _OVLMODE */
+ {
+ bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
+
+ if (!(There_Is_Room ||
+ ((Single_Line_Field(field) && Growable(field)))))
+ return E_REQUEST_DENIED;
+
+ if (!There_Is_Room && !Field_Grown(field,1))
+ return E_SYSTEM_ERROR;
+
+ winsch(form->w,(chtype)c);
+ }
+
+ if ((result=Wrapping_Not_Necessary_Or_Wrapping_Ok(form))==E_OK)
+ {
+ bool End_Of_Field= (((field->drows-1)==form->currow) &&
+ ((field->dcols-1)==form->curcol));
+ form->status |= _WINDOW_MODIFIED;
+ if (End_Of_Field && !Growable(field) && (field->opts & O_AUTOSKIP))
+ result = Inter_Field_Navigation(FN_Next_Field,form);
+ else
+ {
+ if (End_Of_Field && Growable(field) && !Field_Grown(field,1))
+ result = E_SYSTEM_ERROR;
+ else
+ {
+ IFN_Next_Character(form);
+ result = E_OK;
+ }
+ }
+ }
+ }
+ return result;
+}
+
+/* Structure to describe the binding of a request code to a function.
+ The member keycode codes the request value as well as the generic
+ routine to use for the request. The code for the generic routine
+ is coded in the upper 16 Bits while the request code is coded in
+ the lower 16 bits.
+
+ In terms of C++ you might think of a request as a class with a
+ virtual method "perform". The different types of request are
+ derived from this base class and overload (or not) the base class
+ implementation of perform.
+*/
+typedef struct {
+ int keycode; /* must be at least 32 bit: hi:mode, lo: key */
+ int (*cmd)(FORM *); /* low level driver routine for this key */
+} Binding_Info;
+
+/* You may see this is the class-id of the request type class */
+#define ID_PN (0x00000000) /* Page navigation */
+#define ID_FN (0x00010000) /* Inter-Field navigation */
+#define ID_IFN (0x00020000) /* Intra-Field navigation */
+#define ID_VSC (0x00030000) /* Vertical Scrolling */
+#define ID_HSC (0x00040000) /* Horizontal Scrolling */
+#define ID_FE (0x00050000) /* Field Editing */
+#define ID_EM (0x00060000) /* Edit Mode */
+#define ID_FV (0x00070000) /* Field Validation */
+#define ID_CH (0x00080000) /* Choice */
+#define ID_Mask (0xffff0000)
+#define Key_Mask (0x0000ffff)
+#define ID_Shft (16)
+
+/* This array holds all the Binding Infos */
+static const Binding_Info bindings[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
+{
+ { REQ_NEXT_PAGE |ID_PN ,PN_Next_Page},
+ { REQ_PREV_PAGE |ID_PN ,PN_Previous_Page},
+ { REQ_FIRST_PAGE |ID_PN ,PN_First_Page},
+ { REQ_LAST_PAGE |ID_PN ,PN_Last_Page},
+
+ { REQ_NEXT_FIELD |ID_FN ,FN_Next_Field},
+ { REQ_PREV_FIELD |ID_FN ,FN_Previous_Field},
+ { REQ_FIRST_FIELD |ID_FN ,FN_First_Field},
+ { REQ_LAST_FIELD |ID_FN ,FN_Last_Field},
+ { REQ_SNEXT_FIELD |ID_FN ,FN_Sorted_Next_Field},
+ { REQ_SPREV_FIELD |ID_FN ,FN_Sorted_Previous_Field},
+ { REQ_SFIRST_FIELD |ID_FN ,FN_Sorted_First_Field},
+ { REQ_SLAST_FIELD |ID_FN ,FN_Sorted_Last_Field},
+ { REQ_LEFT_FIELD |ID_FN ,FN_Left_Field},
+ { REQ_RIGHT_FIELD |ID_FN ,FN_Right_Field},
+ { REQ_UP_FIELD |ID_FN ,FN_Up_Field},
+ { REQ_DOWN_FIELD |ID_FN ,FN_Down_Field},
+
+ { REQ_NEXT_CHAR |ID_IFN ,IFN_Next_Character},
+ { REQ_PREV_CHAR |ID_IFN ,IFN_Previous_Character},
+ { REQ_NEXT_LINE |ID_IFN ,IFN_Next_Line},
+ { REQ_PREV_LINE |ID_IFN ,IFN_Previous_Line},
+ { REQ_NEXT_WORD |ID_IFN ,IFN_Next_Word},
+ { REQ_PREV_WORD |ID_IFN ,IFN_Previous_Word},
+ { REQ_BEG_FIELD |ID_IFN ,IFN_Beginning_Of_Field},
+ { REQ_END_FIELD |ID_IFN ,IFN_End_Of_Field},
+ { REQ_BEG_LINE |ID_IFN ,IFN_Beginning_Of_Line},
+ { REQ_END_LINE |ID_IFN ,IFN_End_Of_Line},
+ { REQ_LEFT_CHAR |ID_IFN ,IFN_Left_Character},
+ { REQ_RIGHT_CHAR |ID_IFN ,IFN_Right_Character},
+ { REQ_UP_CHAR |ID_IFN ,IFN_Up_Character},
+ { REQ_DOWN_CHAR |ID_IFN ,IFN_Down_Character},
+
+ { REQ_NEW_LINE |ID_FE ,FE_New_Line},
+ { REQ_INS_CHAR |ID_FE ,FE_Insert_Character},
+ { REQ_INS_LINE |ID_FE ,FE_Insert_Line},
+ { REQ_DEL_CHAR |ID_FE ,FE_Delete_Character},
+ { REQ_DEL_PREV |ID_FE ,FE_Delete_Previous},
+ { REQ_DEL_LINE |ID_FE ,FE_Delete_Line},
+ { REQ_DEL_WORD |ID_FE ,FE_Delete_Word},
+ { REQ_CLR_EOL |ID_FE ,FE_Clear_To_End_Of_Line},
+ { REQ_CLR_EOF |ID_FE ,FE_Clear_To_End_Of_Form},
+ { REQ_CLR_FIELD |ID_FE ,FE_Clear_Field},
+
+ { REQ_OVL_MODE |ID_EM ,EM_Overlay_Mode},
+ { REQ_INS_MODE |ID_EM ,EM_Insert_Mode},
+
+ { REQ_SCR_FLINE |ID_VSC ,VSC_Scroll_Line_Forward},
+ { REQ_SCR_BLINE |ID_VSC ,VSC_Scroll_Line_Backward},
+ { REQ_SCR_FPAGE |ID_VSC ,VSC_Scroll_Page_Forward},
+ { REQ_SCR_BPAGE |ID_VSC ,VSC_Scroll_Page_Backward},
+ { REQ_SCR_FHPAGE |ID_VSC ,VSC_Scroll_Half_Page_Forward},
+ { REQ_SCR_BHPAGE |ID_VSC ,VSC_Scroll_Half_Page_Backward},
+
+ { REQ_SCR_FCHAR |ID_HSC ,HSC_Scroll_Char_Forward},
+ { REQ_SCR_BCHAR |ID_HSC ,HSC_Scroll_Char_Backward},
+ { REQ_SCR_HFLINE |ID_HSC ,HSC_Horizontal_Line_Forward},
+ { REQ_SCR_HBLINE |ID_HSC ,HSC_Horizontal_Line_Backward},
+ { REQ_SCR_HFHALF |ID_HSC ,HSC_Horizontal_Half_Line_Forward},
+ { REQ_SCR_HBHALF |ID_HSC ,HSC_Horizontal_Half_Line_Backward},
+
+ { REQ_VALIDATION |ID_FV ,FV_Validation},
+
+ { REQ_NEXT_CHOICE |ID_CH ,CR_Next_Choice},
+ { REQ_PREV_CHOICE |ID_CH ,CR_Previous_Choice}
+};
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int form_driver(FORM * form,int c)
+|
+| Description : This is the workhorse of the forms system. It checks
+| to determine whether the character c is a request or
+| data. If it is a request, the form driver executes
+| the request and returns the result. If it is data
+| (printable character), it enters the data into the
+| current position in the current field. If it is not
+| recognized, the form driver assumes it is an application
+| defined command and returns E_UNKNOWN_COMMAND.
+| Application defined command should be defined relative
+| to MAX_FORM_COMMAND, the maximum value of a request.
+|
+| Return Values : E_OK - success
+| E_SYSTEM_ERROR - system error
+| E_BAD_ARGUMENT - an argument is incorrect
+| E_NOT_POSTED - form is not posted
+| E_INVALID_FIELD - field contents are invalid
+| E_BAD_STATE - called from inside a hook routine
+| E_REQUEST_DENIED - request failed
+| E_UNKNOWN_COMMAND - command not known
++--------------------------------------------------------------------------*/
+int form_driver(FORM * form, int c)
+{
+ const Binding_Info* BI = (Binding_Info *)0;
+ int res = E_UNKNOWN_COMMAND;
+
+ if (!form)
+ RETURN(E_BAD_ARGUMENT);
+
+ if (!(form->field))
+ RETURN(E_NOT_CONNECTED);
+
+ assert(form->page != 0);
+
+ if (c==FIRST_ACTIVE_MAGIC)
+ {
+ form->current = _nc_First_Active_Field(form);
+ return E_OK;
+ }
+
+ assert(form->current &&
+ form->current->buf &&
+ (form->current->form == form)
+ );
+
+ if ( form->status & _IN_DRIVER )
+ RETURN(E_BAD_STATE);
+
+ if ( !( form->status & _POSTED ) )
+ RETURN(E_NOT_POSTED);
+
+ if ((c>=MIN_FORM_COMMAND && c<=MAX_FORM_COMMAND) &&
+ ((bindings[c-MIN_FORM_COMMAND].keycode & Key_Mask) == c))
+ BI = &(bindings[c-MIN_FORM_COMMAND]);
+
+ if (BI)
+ {
+ typedef int (*Generic_Method)(int (* const)(FORM *),FORM *);
+ static const Generic_Method Generic_Methods[] =
+ {
+ Page_Navigation, /* overloaded to call field&form hooks */
+ Inter_Field_Navigation, /* overloaded to call field hooks */
+ NULL, /* Intra-Field is generic */
+ Vertical_Scrolling, /* Overloaded to check multi-line */
+ Horizontal_Scrolling, /* Overloaded to check single-line */
+ Field_Editing, /* Overloaded to mark modification */
+ NULL, /* Edit Mode is generic */
+ NULL, /* Field Validation is generic */
+ NULL /* Choice Request is generic */
+ };
+ size_t nMethods = (sizeof(Generic_Methods)/sizeof(Generic_Methods[0]));
+ size_t method = ((BI->keycode & ID_Mask) >> ID_Shft) & 0xffff;
+
+ if ( (method >= nMethods) || !(BI->cmd) )
+ res = E_SYSTEM_ERROR;
+ else
+ {
+ Generic_Method fct = Generic_Methods[method];
+ if (fct)
+ res = fct(BI->cmd,form);
+ else
+ res = (BI->cmd)(form);
+ }
+ }
+ else
+ {
+ if (!(c & (~(int)MAX_REGULAR_CHARACTER)) &&
+ isprint((unsigned char)c) &&
+ Check_Char(form->current->type,c,
+ (TypeArgument *)(form->current->arg)))
+ res = Data_Entry(form,c);
+ }
+ _nc_Refresh_Current_Field(form);
+ RETURN(res);
+}
+
+/*----------------------------------------------------------------------------
+ Field-Buffer manipulation routines.
+ The effects of setting a buffer is tightly coupled to the core of the form
+ driver logic. This is especially true in the case of growable fields.
+ So I don't separate this into an own module.
+ --------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_buffer(FIELD *field,
+| int buffer, char *value)
+|
+| Description : Set the given buffer of the field to the given value.
+| Buffer 0 stores the displayed content of the field.
+| For dynamic fields this may grow the fieldbuffers if
+| the length of the value exceeds the current buffer
+| length. For buffer 0 only printable values are allowed.
+| For static fields, the value needs not to be zero ter-
+| minated. It is copied up to the length of the buffer.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid argument
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+int set_field_buffer(FIELD * field, int buffer, const char * value)
+{
+ char *s, *p;
+ int res = E_OK;
+ unsigned int len;
+
+ if ( !field || !value || ((buffer < 0)||(buffer > field->nbuf)) )
+ RETURN(E_BAD_ARGUMENT);
+
+ len = Buffer_Length(field);
+
+ if (buffer==0)
+ {
+ const char *v;
+ unsigned int i = 0;
+
+ for(v=value; *v && (i<len); v++,i++)
+ {
+ if (!isprint((unsigned char)*v))
+ RETURN(E_BAD_ARGUMENT);
+ }
+ }
+
+ if (Growable(field))
+ {
+ /* for a growable field we must assume zero terminated strings, because
+ somehow we have to detect the length of what should be copied.
+ */
+ unsigned int vlen = strlen(value);
+ if (vlen > len)
+ {
+ if (!Field_Grown(field,
+ (int)(1 + (vlen-len)/((field->rows+field->nrow)*field->cols))))
+ RETURN(E_SYSTEM_ERROR);
+
+ /* in this case we also have to check, whether or not the remaining
+ characters in value are also printable for buffer 0. */
+ if (buffer==0)
+ {
+ unsigned int i;
+
+ for(i=len; i<vlen; i++)
+ if (!isprint((int)(value[i])))
+ RETURN(E_BAD_ARGUMENT);
+ }
+ len = vlen;
+ }
+ }
+
+ p = Address_Of_Nth_Buffer(field,buffer);
+
+#if HAVE_MEMCCPY
+ s = memccpy(p,value,0,len);
+#else
+ for(s=(char *)value; *s && (s < (value+len)); s++)
+ p[s-value] = *s;
+ if (s < (value+len))
+ {
+ int off = s-value;
+ p[off] = *s++;
+ s = p + (s-value);
+ }
+ else
+ s=(char *)0;
+#endif
+
+ if (s)
+ { /* this means, value was null terminated and not greater than the
+ buffer. We have to pad with blanks. Please note that due to memccpy
+ logic s points after the terminating null. */
+ s--; /* now we point to the terminator. */
+ assert(len >= (unsigned int)(s-p));
+ if (len > (unsigned int)(s-p))
+ memset(s,C_BLANK,len-(unsigned int)(s-p));
+ }
+
+ if (buffer==0)
+ {
+ int syncres;
+ if (((syncres=Synchronize_Field( field ))!=E_OK) &&
+ (res==E_OK))
+ res = syncres;
+ if (((syncres=Synchronize_Linked_Fields(field ))!=E_OK) &&
+ (res==E_OK))
+ res = syncres;
+ }
+ RETURN(res);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : char *field_buffer(const FIELD *field,int buffer)
+|
+| Description : Return the address of the buffer for the field.
+|
+| Return Values : Pointer to buffer or NULL if arguments were invalid.
++--------------------------------------------------------------------------*/
+char *field_buffer(const FIELD * field, int buffer)
+{
+ if (field && (buffer >= 0) && (buffer <= field->nbuf))
+ return Address_Of_Nth_Buffer(field,buffer);
+ else
+ return (char *)0;
+}
+
+/* frm_driver.c ends here */
diff --git a/Source/CursesDialog/form/frm_hook.c b/Source/CursesDialog/form/frm_hook.c
new file mode 100644
index 0000000000..eb654c4f3f
--- /dev/null
+++ b/Source/CursesDialog/form/frm_hook.c
@@ -0,0 +1,140 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/* "Template" macro to generate function to set application specific hook */
+#define GEN_HOOK_SET_FUNCTION( typ, name ) \
+int set_ ## typ ## _ ## name (FORM *form, Form_Hook func)\
+{\
+ (Normalize_Form( form ) -> typ ## name) = func ;\
+ RETURN(E_OK);\
+}
+
+/* "Template" macro to generate function to get application specific hook */
+#define GEN_HOOK_GET_FUNCTION( typ, name ) \
+Form_Hook typ ## _ ## name ( const FORM *form )\
+{\
+ return ( Normalize_Form( form ) -> typ ## name );\
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_init(FORM *form, Form_Hook f)
+|
+| Description : Assigns an application defined initialization function
+| to be called when the form is posted and just after
+| the current field changes.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+GEN_HOOK_SET_FUNCTION(field,init)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : Form_Hook field_init(const FORM *form)
+|
+| Description : Retrieve field initialization routine address.
+|
+| Return Values : The address or NULL if no hook defined.
++--------------------------------------------------------------------------*/
+GEN_HOOK_GET_FUNCTION(field,init)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_field_term(FORM *form, Form_Hook f)
+|
+| Description : Assigns an application defined finalization function
+| to be called when the form is unposted and just before
+| the current field changes.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+GEN_HOOK_SET_FUNCTION(field,term)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : Form_Hook field_term(const FORM *form)
+|
+| Description : Retrieve field finalization routine address.
+|
+| Return Values : The address or NULL if no hook defined.
++--------------------------------------------------------------------------*/
+GEN_HOOK_GET_FUNCTION(field,term)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_form_init(FORM *form, Form_Hook f)
+|
+| Description : Assigns an application defined initialization function
+| to be called when the form is posted and just after
+| a page change.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+GEN_HOOK_SET_FUNCTION(form,init)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : Form_Hook form_init(const FORM *form)
+|
+| Description : Retrieve form initialization routine address.
+|
+| Return Values : The address or NULL if no hook defined.
++--------------------------------------------------------------------------*/
+GEN_HOOK_GET_FUNCTION(form,init)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_form_term(FORM *form, Form_Hook f)
+|
+| Description : Assigns an application defined finalization function
+| to be called when the form is unposted and just before
+| a page change.
+|
+| Return Values : E_OK - success
++--------------------------------------------------------------------------*/
+GEN_HOOK_SET_FUNCTION(form,term)
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : Form_Hook form_term(const FORM *form)
+|
+| Description : Retrieve form finalization routine address.
+|
+| Return Values : The address or NULL if no hook defined.
++--------------------------------------------------------------------------*/
+GEN_HOOK_GET_FUNCTION(form,term)
+
+/* frm_hook.c ends here */
diff --git a/Source/CursesDialog/form/frm_opts.c b/Source/CursesDialog/form/frm_opts.c
new file mode 100644
index 0000000000..7bbeaa1353
--- /dev/null
+++ b/Source/CursesDialog/form/frm_opts.c
@@ -0,0 +1,116 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_form_opts(FORM *form, Form_Options opts)
+|
+| Description : Turns on the named options and turns off all the
+| remaining options for that form.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid options
++--------------------------------------------------------------------------*/
+int set_form_opts(FORM * form, Form_Options opts)
+{
+ opts &= ALL_FORM_OPTS;
+ if (opts & ~ALL_FORM_OPTS)
+ RETURN(E_BAD_ARGUMENT);
+ else
+ {
+ Normalize_Form( form )->opts = opts;
+ RETURN(E_OK);
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : Form_Options form_opts(const FORM *)
+|
+| Description : Retrieves the current form options.
+|
+| Return Values : The option flags.
++--------------------------------------------------------------------------*/
+Form_Options form_opts(const FORM * form)
+{
+ return (Normalize_Form(form)->opts & ALL_FORM_OPTS);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int form_opts_on(FORM *form, Form_Options opts)
+|
+| Description : Turns on the named options; no other options are
+| changed.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid options
++--------------------------------------------------------------------------*/
+int form_opts_on(FORM * form, Form_Options opts)
+{
+ opts &= ALL_FORM_OPTS;
+ if (opts & ~ALL_FORM_OPTS)
+ RETURN(E_BAD_ARGUMENT);
+ else
+ {
+ Normalize_Form( form )->opts |= opts;
+ RETURN(E_OK);
+ }
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int form_opts_off(FORM *form, Form_Options opts)
+|
+| Description : Turns off the named options; no other options are
+| changed.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid options
++--------------------------------------------------------------------------*/
+int form_opts_off(FORM * form, Form_Options opts)
+{
+ opts &= ALL_FORM_OPTS;
+ if (opts & ~ALL_FORM_OPTS)
+ RETURN(E_BAD_ARGUMENT);
+ else
+ {
+ Normalize_Form(form)->opts &= ~opts;
+ RETURN(E_OK);
+ }
+}
+
+/* frm_opts.c ends here */
diff --git a/Source/CursesDialog/form/frm_page.c b/Source/CursesDialog/form/frm_page.c
new file mode 100644
index 0000000000..842cbce7b0
--- /dev/null
+++ b/Source/CursesDialog/form/frm_page.c
@@ -0,0 +1,100 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_form_page(FORM * form,int page)
+|
+| Description : Set the page number of the form.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid form pointer or page number
+| E_BAD_STATE - called from a hook routine
+| E_INVALID_FIELD - current field can't be left
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+int set_form_page(FORM * form, int page)
+{
+ int err = E_OK;
+
+ if ( !form || (page<0) || (page>=form->maxpage) )
+ RETURN(E_BAD_ARGUMENT);
+
+ if (!(form->status & _POSTED))
+ {
+ form->curpage = page;
+ form->current = _nc_First_Active_Field(form);
+ }
+ else
+ {
+ if (form->status & _IN_DRIVER)
+ err = E_BAD_STATE;
+ else
+ {
+ if (form->curpage != page)
+ {
+ if (!_nc_Internal_Validation(form))
+ err = E_INVALID_FIELD;
+ else
+ {
+ Call_Hook(form,fieldterm);
+ Call_Hook(form,formterm);
+ err = _nc_Set_Form_Page(form,page,(FIELD *)0);
+ Call_Hook(form,forminit);
+ Call_Hook(form,fieldinit);
+ _nc_Refresh_Current_Field(form);
+ }
+ }
+ }
+ }
+ RETURN(err);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int form_page(const FORM * form)
+|
+| Description : Return the current page of the form.
+|
+| Return Values : >= 0 : current page number
+| -1 : invalid form pointer
++--------------------------------------------------------------------------*/
+int form_page(const FORM * form)
+{
+ return Normalize_Form(form)->curpage;
+}
+
+/* frm_page.c ends here */
diff --git a/Source/CursesDialog/form/frm_post.c b/Source/CursesDialog/form/frm_post.c
new file mode 100644
index 0000000000..3c63de70e5
--- /dev/null
+++ b/Source/CursesDialog/form/frm_post.c
@@ -0,0 +1,124 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int post_form(FORM * form)
+|
+| Description : Writes the form into its associated subwindow.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid form pointer
+| E_POSTED - form already posted
+| E_NOT_CONNECTED - no fields connected to form
+| E_NO_ROOM - form doesn't fit into subwindow
+| E_SYSTEM_ERROR - system error
++--------------------------------------------------------------------------*/
+int post_form(FORM * form)
+{
+ WINDOW *formwin;
+ int err;
+ int page;
+ int height, width;
+
+ if (!form)
+ RETURN(E_BAD_ARGUMENT);
+
+ if (form->status & _POSTED)
+ RETURN(E_POSTED);
+
+ if (!(form->field))
+ RETURN(E_NOT_CONNECTED);
+
+ formwin = Get_Form_Window(form);
+#if defined(__LSB_VERSION__)
+ getmaxyx(formwin, height, width);
+#else
+ width = getmaxx(formwin);
+ height = getmaxy(formwin);
+#endif
+ if ((form->cols > width) || (form->rows > height))
+ RETURN(E_NO_ROOM);
+
+ /* reset form->curpage to an invald value. This forces Set_Form_Page
+ to do the page initialization which is required by post_form.
+ */
+ page = form->curpage;
+ form->curpage = -1;
+ if ((err = _nc_Set_Form_Page(form,page,form->current))!=E_OK)
+ RETURN(err);
+
+ form->status |= _POSTED;
+
+ Call_Hook(form,forminit);
+ Call_Hook(form,fieldinit);
+
+ _nc_Refresh_Current_Field(form);
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int unpost_form(FORM * form)
+|
+| Description : Erase form from its associated subwindow.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid form pointer
+| E_NOT_POSTED - form isn't posted
+| E_BAD_STATE - called from a hook routine
++--------------------------------------------------------------------------*/
+int unpost_form(FORM * form)
+{
+ if (!form)
+ RETURN(E_BAD_ARGUMENT);
+
+ if (!(form->status & _POSTED))
+ RETURN(E_NOT_POSTED);
+
+ if (form->status & _IN_DRIVER)
+ RETURN(E_BAD_STATE);
+
+ Call_Hook(form,fieldterm);
+ Call_Hook(form,formterm);
+
+ werase(Get_Form_Window(form));
+ delwin(form->w);
+ form->w = (WINDOW *)0;
+ form->status &= ~_POSTED;
+ RETURN(E_OK);
+}
+
+/* frm_post.c ends here */
diff --git a/Source/CursesDialog/form/frm_req_name.c b/Source/CursesDialog/form/frm_req_name.c
new file mode 100644
index 0000000000..b108dabe4d
--- /dev/null
+++ b/Source/CursesDialog/form/frm_req_name.c
@@ -0,0 +1,169 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+/***************************************************************************
+* Module form_request_name *
+* Routines to handle external names of menu requests *
+***************************************************************************/
+
+#if defined(__hpux)
+ #define _XOPEN_SOURCE_EXTENDED
+#endif
+#include "form.priv.h"
+#if defined(__hpux)
+ #undef _XOPEN_SOURCE_EXTENDED
+#endif
+
+MODULE_ID("$Id$")
+
+static const char *request_names[ MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1 ] = {
+ "NEXT_PAGE" ,
+ "PREV_PAGE" ,
+ "FIRST_PAGE" ,
+ "LAST_PAGE" ,
+
+ "NEXT_FIELD" ,
+ "PREV_FIELD" ,
+ "FIRST_FIELD" ,
+ "LAST_FIELD" ,
+ "SNEXT_FIELD" ,
+ "SPREV_FIELD" ,
+ "SFIRST_FIELD" ,
+ "SLAST_FIELD" ,
+ "LEFT_FIELD" ,
+ "RIGHT_FIELD" ,
+ "UP_FIELD" ,
+ "DOWN_FIELD" ,
+
+ "NEXT_CHAR" ,
+ "PREV_CHAR" ,
+ "NEXT_LINE" ,
+ "PREV_LINE" ,
+ "NEXT_WORD" ,
+ "PREV_WORD" ,
+ "BEG_FIELD" ,
+ "END_FIELD" ,
+ "BEG_LINE" ,
+ "END_LINE" ,
+ "LEFT_CHAR" ,
+ "RIGHT_CHAR" ,
+ "UP_CHAR" ,
+ "DOWN_CHAR" ,
+
+ "NEW_LINE" ,
+ "INS_CHAR" ,
+ "INS_LINE" ,
+ "DEL_CHAR" ,
+ "DEL_PREV" ,
+ "DEL_LINE" ,
+ "DEL_WORD" ,
+ "CLR_EOL" ,
+ "CLR_EOF" ,
+ "CLR_FIELD" ,
+ "OVL_MODE" ,
+ "INS_MODE" ,
+ "SCR_FLINE" ,
+ "SCR_BLINE" ,
+ "SCR_FPAGE" ,
+ "SCR_BPAGE" ,
+ "SCR_FHPAGE" ,
+ "SCR_BHPAGE" ,
+ "SCR_FCHAR" ,
+ "SCR_BCHAR" ,
+ "SCR_HFLINE" ,
+ "SCR_HBLINE" ,
+ "SCR_HFHALF" ,
+ "SCR_HBHALF" ,
+
+ "VALIDATION" ,
+ "NEXT_CHOICE" ,
+ "PREV_CHOICE"
+};
+#define A_SIZE (sizeof(request_names)/sizeof(request_names[0]))
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : const char * form_request_name (int request);
+|
+| Description : Get the external name of a form request.
+|
+| Return Values : Pointer to name - on success
+| NULL - on invalid request code
++--------------------------------------------------------------------------*/
+const char *form_request_name( int request )
+{
+ if ( (request < MIN_FORM_COMMAND) || (request > MAX_FORM_COMMAND) )
+ {
+ SET_ERROR (E_BAD_ARGUMENT);
+ return (const char *)0;
+ }
+ else
+ return request_names[ request - MIN_FORM_COMMAND ];
+}
+
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int form_request_by_name (const char *str);
+|
+| Description : Search for a request with this name.
+|
+| Return Values : Request Id - on success
+| E_NO_MATCH - request not found
++--------------------------------------------------------------------------*/
+int form_request_by_name( const char *str )
+{
+ /* because the table is so small, it doesn't really hurt
+ to run sequentially through it.
+ */
+ unsigned int i = 0;
+ char buf[16];
+
+ if (str)
+ {
+ strncpy(buf,str,sizeof(buf));
+ while( (i<sizeof(buf)) && (buf[i] != '\0') )
+ {
+ buf[i] = toupper((int)(buf[i]));
+ i++;
+ }
+
+ for (i=0; i < A_SIZE; i++)
+ {
+ if (strncmp(request_names[i],buf,sizeof(buf))==0)
+ return MIN_FORM_COMMAND + i;
+ }
+ }
+ RETURN(E_NO_MATCH);
+}
+
+/* frm_req_name.c ends here */
diff --git a/Source/CursesDialog/form/frm_scale.c b/Source/CursesDialog/form/frm_scale.c
new file mode 100644
index 0000000000..028e9e2e8e
--- /dev/null
+++ b/Source/CursesDialog/form/frm_scale.c
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int scale_form( const FORM *form, int *rows, int *cols )
+|
+| Description : Retrieve size of form
+|
+| Return Values : E_OK - no error
+| E_BAD_ARGUMENT - invalid form pointer
+| E_NOT_CONNECTED - no fields connected to form
++--------------------------------------------------------------------------*/
+int scale_form(const FORM * form, int * rows, int * cols)
+{
+ if ( !form )
+ RETURN(E_BAD_ARGUMENT);
+
+ if ( !(form->field) )
+ RETURN(E_NOT_CONNECTED);
+
+ if (rows)
+ *rows = form->rows;
+ if (cols)
+ *cols = form->cols;
+
+ RETURN(E_OK);
+}
+
+/* frm_scale.c ends here */
diff --git a/Source/CursesDialog/form/frm_sub.c b/Source/CursesDialog/form/frm_sub.c
new file mode 100644
index 0000000000..62dc613b01
--- /dev/null
+++ b/Source/CursesDialog/form/frm_sub.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_form_sub(FORM *form, WINDOW *win)
+|
+| Description : Set the subwindow of the form to win.
+|
+| Return Values : E_OK - success
+| E_POSTED - form is posted
++--------------------------------------------------------------------------*/
+int set_form_sub(FORM * form, WINDOW * win)
+{
+ if (form && (form->status & _POSTED))
+ RETURN(E_POSTED);
+
+ Normalize_Form( form )->sub = win;
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : WINDOW *form_sub(const FORM *)
+|
+| Description : Retrieve the window of the form.
+|
+| Return Values : The pointer to the Subwindow.
++--------------------------------------------------------------------------*/
+WINDOW *form_sub(const FORM * form)
+{
+ const FORM* f = Normalize_Form( form );
+ return Get_Form_Window(f);
+}
+
+/* frm_sub.c ends here */
diff --git a/Source/CursesDialog/form/frm_user.c b/Source/CursesDialog/form/frm_user.c
new file mode 100644
index 0000000000..f38bbbb8d9
--- /dev/null
+++ b/Source/CursesDialog/form/frm_user.c
@@ -0,0 +1,67 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_form_userptr(FORM *form, void *usrptr)
+|
+| Description : Set the pointer that is reserved in any form to store
+| application relevant information
+|
+| Return Values : E_OK - on success
++--------------------------------------------------------------------------*/
+int set_form_userptr(FORM * form, void *usrptr)
+{
+ Normalize_Form(form)->usrptr = usrptr;
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : void *form_userptr(const FORM *form)
+|
+| Description : Return the pointer that is reserved in any form to
+| store application relevant information.
+|
+| Return Values : Value of pointer. If no such pointer has been set,
+| NULL is returned
++--------------------------------------------------------------------------*/
+void *form_userptr(const FORM * form)
+{
+ return Normalize_Form(form)->usrptr;
+}
+
+/* frm_user.c ends here */
diff --git a/Source/CursesDialog/form/frm_win.c b/Source/CursesDialog/form/frm_win.c
new file mode 100644
index 0000000000..82d716f7f1
--- /dev/null
+++ b/Source/CursesDialog/form/frm_win.c
@@ -0,0 +1,70 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int set_form_win(FORM *form,WINDOW *win)
+|
+| Description : Set the window of the form to win.
+|
+| Return Values : E_OK - success
+| E_POSTED - form is posted
++--------------------------------------------------------------------------*/
+int set_form_win(FORM * form, WINDOW * win)
+{
+ if (form && (form->status & _POSTED))
+ RETURN(E_POSTED);
+
+ Normalize_Form( form )->win = win;
+ RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : WINDOW *form_win(const FORM *)
+|
+| Description : Retrieve the window of the form.
+|
+| Return Values : The pointer to the Window or stdscr if there is none.
++--------------------------------------------------------------------------*/
+WINDOW *form_win(const FORM * form)
+{
+ const FORM* f = Normalize_Form( form );
+ return (f->win ? f->win : stdscr);
+}
+
+/* frm_win.c ends here */
+
diff --git a/Source/CursesDialog/form/fty_alnum.c b/Source/CursesDialog/form/fty_alnum.c
new file mode 100644
index 0000000000..6f3cfd4fc1
--- /dev/null
+++ b/Source/CursesDialog/form/fty_alnum.c
@@ -0,0 +1,138 @@
+
+/*
+ * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
+ * You may freely copy it for use as a template for your own field types.
+ * If you develop a field type that might be of general use, please send
+ * it back to the ncurses maintainers for inclusion in the next version.
+ */
+/***************************************************************************
+* *
+* Author : Juergen Pfeifer, juergen.pfeifer@gmx.net *
+* *
+***************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+typedef struct {
+ int width;
+} alnumARG;
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Make_AlphaNumeric_Type(va_list *ap)
+|
+| Description : Allocate structure for alphanumeric type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error
++--------------------------------------------------------------------------*/
+static void *Make_AlphaNumeric_Type(va_list * ap)
+{
+ alnumARG *argp = (alnumARG *)malloc(sizeof(alnumARG));
+
+ if (argp)
+ argp->width = va_arg(*ap,int);
+
+ return ((void *)argp);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Copy_AlphaNumericType(const void *argp)
+|
+| Description : Copy structure for alphanumeric type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error.
++--------------------------------------------------------------------------*/
+static void *Copy_AlphaNumeric_Type(const void *argp)
+{
+ const alnumARG *ap = (const alnumARG *)argp;
+ alnumARG *result = (alnumARG *)malloc(sizeof(alnumARG));
+
+ if (result)
+ *result = *ap;
+
+ return ((void *)result);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Free_AlphaNumeric_Type(void *argp)
+|
+| Description : Free structure for alphanumeric type argument.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Free_AlphaNumeric_Type(void * argp)
+{
+ if (argp)
+ free(argp);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_AlphaNumeric_Field(
+| FIELD *field,
+| const void *argp)
+|
+| Description : Validate buffer content to be a valid alphanumeric value
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid
++--------------------------------------------------------------------------*/
+static bool Check_AlphaNumeric_Field(FIELD * field, const void * argp)
+{
+ int width = ((const alnumARG *)argp)->width;
+ unsigned char *bp = (unsigned char *)field_buffer(field,0);
+ int l = -1;
+ unsigned char *s;
+
+ while(*bp && *bp==' ')
+ bp++;
+ if (*bp)
+ {
+ s = bp;
+ while(*bp && isalnum(*bp))
+ bp++;
+ l = (int)(bp-s);
+ while(*bp && *bp==' ')
+ bp++;
+ }
+ return ((*bp || (l < width)) ? FALSE : TRUE);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_AlphaNumeric_Character(
+| int c,
+| const void *argp )
+|
+| Description : Check a character for the alphanumeric type.
+|
+| Return Values : TRUE - character is valid
+| FALSE - character is invalid
++--------------------------------------------------------------------------*/
+static bool Check_AlphaNumeric_Character(int c, const void * argp)
+{
+ argp=0; /* Silence unused parameter warning. */
+ return (isalnum(c) ? TRUE : FALSE);
+}
+
+static FIELDTYPE typeALNUM = {
+ _HAS_ARGS | _RESIDENT,
+ 1, /* this is mutable, so we can't be const */
+ (FIELDTYPE *)0,
+ (FIELDTYPE *)0,
+ Make_AlphaNumeric_Type,
+ Copy_AlphaNumeric_Type,
+ Free_AlphaNumeric_Type,
+ Check_AlphaNumeric_Field,
+ Check_AlphaNumeric_Character,
+ NULL,
+ NULL
+};
+
+FIELDTYPE* TYPE_ALNUM = &typeALNUM;
+
+/* fty_alnum.c ends here */
diff --git a/Source/CursesDialog/form/fty_alpha.c b/Source/CursesDialog/form/fty_alpha.c
new file mode 100644
index 0000000000..e4e9ceb1c1
--- /dev/null
+++ b/Source/CursesDialog/form/fty_alpha.c
@@ -0,0 +1,139 @@
+
+/*
+ * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
+ * You may freely copy it for use as a template for your own field types.
+ * If you develop a field type that might be of general use, please send
+ * it back to the ncurses maintainers for inclusion in the next version.
+ */
+/***************************************************************************
+* *
+* Author : Juergen Pfeifer, juergen.pfeifer@gmx.net *
+* *
+***************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+typedef struct {
+ int width;
+} alphaARG;
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Make_Alpha_Type(va_list *ap)
+|
+| Description : Allocate structure for alpha type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error
++--------------------------------------------------------------------------*/
+static void *Make_Alpha_Type(va_list * ap)
+{
+ alphaARG *argp = (alphaARG *)malloc(sizeof(alphaARG));
+ if (argp)
+ {
+ argp->width = va_arg(*ap,int);
+ }
+ return ((void *)argp);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Copy_Alpha_Type(const void * argp)
+|
+| Description : Copy structure for alpha type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error.
++--------------------------------------------------------------------------*/
+static void *Copy_Alpha_Type(const void * argp)
+{
+ const alphaARG *ap = (const alphaARG *)argp;
+ alphaARG *result = (alphaARG *)malloc(sizeof(alphaARG));
+
+ if (result)
+ {
+ *result = *ap;
+ }
+ return ((void *)result);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Free_Alpha_Type( void * argp )
+|
+| Description : Free structure for alpha type argument.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Free_Alpha_Type(void * argp)
+{
+ if (argp)
+ free(argp);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_Alpha_Field(
+| FIELD * field,
+| const void * argp)
+|
+| Description : Validate buffer content to be a valid alpha value
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid
++--------------------------------------------------------------------------*/
+static bool Check_Alpha_Field(FIELD * field, const void * argp)
+{
+ int width = ((const alphaARG *)argp)->width;
+ unsigned char *bp = (unsigned char *)field_buffer(field,0);
+ int l = -1;
+ unsigned char *s;
+
+ while(*bp && *bp==' ')
+ bp++;
+ if (*bp)
+ {
+ s = bp;
+ while(*bp && isalpha(*bp))
+ bp++;
+ l = (int)(bp-s);
+ while(*bp && *bp==' ')
+ bp++;
+ }
+ return ((*bp || (l < width)) ? FALSE : TRUE);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_Alpha_Character(
+| int c,
+| const void * argp)
+|
+| Description : Check a character for the alpha type.
+|
+| Return Values : TRUE - character is valid
+| FALSE - character is invalid
++--------------------------------------------------------------------------*/
+static bool Check_Alpha_Character(int c, const void * argp)
+{
+ argp=0; /* Silence unused parameter warning. */
+ return (isalpha(c) ? TRUE : FALSE);
+}
+
+static FIELDTYPE typeALPHA = {
+ _HAS_ARGS | _RESIDENT,
+ 1, /* this is mutable, so we can't be const */
+ (FIELDTYPE *)0,
+ (FIELDTYPE *)0,
+ Make_Alpha_Type,
+ Copy_Alpha_Type,
+ Free_Alpha_Type,
+ Check_Alpha_Field,
+ Check_Alpha_Character,
+ NULL,
+ NULL
+};
+
+FIELDTYPE* TYPE_ALPHA = &typeALPHA;
+
+/* fty_alpha.c ends here */
diff --git a/Source/CursesDialog/form/fty_enum.c b/Source/CursesDialog/form/fty_enum.c
new file mode 100644
index 0000000000..59058a98ce
--- /dev/null
+++ b/Source/CursesDialog/form/fty_enum.c
@@ -0,0 +1,295 @@
+
+/*
+ * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
+ * You may freely copy it for use as a template for your own field types.
+ * If you develop a field type that might be of general use, please send
+ * it back to the ncurses maintainers for inclusion in the next version.
+ */
+/***************************************************************************
+* *
+* Author : Juergen Pfeifer, juergen.pfeifer@gmx.net *
+* *
+***************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+typedef struct {
+ char **kwds;
+ int count;
+ bool checkcase;
+ bool checkunique;
+} enumARG;
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Make_Enum_Type( va_list * ap )
+|
+| Description : Allocate structure for enumeration type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error
++--------------------------------------------------------------------------*/
+static void *Make_Enum_Type(va_list * ap)
+{
+ enumARG *argp = (enumARG *)malloc(sizeof(enumARG));
+
+ if (argp)
+ {
+ int cnt = 0;
+ char **kp = (char **)0;
+ int ccase, cunique;
+
+ argp->kwds = va_arg(*ap,char **);
+ ccase = va_arg(*ap,int);
+ cunique = va_arg(*ap,int);
+ argp->checkcase = ccase ? TRUE : FALSE;
+ argp->checkunique = cunique ? TRUE : FALSE;
+
+ kp = argp->kwds;
+ while( kp && (*kp++) ) cnt++;
+ argp->count = cnt;
+ }
+ return (void *)argp;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Copy_Enum_Type( const void * argp )
+|
+| Description : Copy structure for enumeration type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error.
++--------------------------------------------------------------------------*/
+static void *Copy_Enum_Type(const void * argp)
+{
+ enumARG *result = (enumARG *)0;
+
+ if (argp)
+ {
+ const enumARG *ap = (const enumARG *)argp;
+
+ result = (enumARG *)malloc(sizeof(enumARG));
+ if (result)
+ *result = *ap;
+ }
+ return (void *)result;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Free_Enum_Type( void * argp )
+|
+| Description : Free structure for enumeration type argument.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Free_Enum_Type(void * argp)
+{
+ if (argp)
+ free(argp);
+}
+
+#define SKIP_SPACE(x) while(((*(x))!='\0') && (is_blank(*(x)))) (x)++
+#define NOMATCH 0
+#define PARTIAL 1
+#define EXACT 2
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static int Compare(const unsigned char * s,
+| const unsigned char * buf,
+| bool ccase )
+|
+| Description : Check whether or not the text in 'buf' matches the
+| text in 's', at least partial.
+|
+| Return Values : NOMATCH - buffer doesn't match
+| PARTIAL - buffer matches partially
+| EXACT - buffer matches exactly
++--------------------------------------------------------------------------*/
+static int Compare(const unsigned char *s, const unsigned char *buf,
+ bool ccase)
+{
+ SKIP_SPACE(buf); /* Skip leading spaces in both texts */
+ SKIP_SPACE(s);
+
+ if (*buf=='\0')
+ {
+ return (((*s)!='\0') ? NOMATCH : EXACT);
+ }
+ else
+ {
+ if (ccase)
+ {
+ while(*s++ == *buf)
+ {
+ if (*buf++=='\0') return EXACT;
+ }
+ }
+ else
+ {
+ while(toupper(*s++)==toupper(*buf))
+ {
+ if (*buf++=='\0') return EXACT;
+ }
+ }
+ }
+ /* At this location buf points to the first character where it no longer
+ matches with s. So if only blanks are following, we have a partial
+ match otherwise there is no match */
+ SKIP_SPACE(buf);
+ if (*buf)
+ return NOMATCH;
+
+ /* If it happens that the reference buffer is at its end, the partial
+ match is actually an exact match. */
+ return ((s[-1]!='\0') ? PARTIAL : EXACT);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_Enum_Field(
+| FIELD * field,
+| const void * argp)
+|
+| Description : Validate buffer content to be a valid enumeration value
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid
++--------------------------------------------------------------------------*/
+static bool Check_Enum_Field(FIELD * field, const void * argp)
+{
+ char **kwds = ((const enumARG *)argp)->kwds;
+ bool ccase = ((const enumARG *)argp)->checkcase;
+ bool unique = ((const enumARG *)argp)->checkunique;
+ unsigned char *bp = (unsigned char *)field_buffer(field,0);
+ char *s, *t, *p;
+ int res;
+
+ while( kwds && (s=(*kwds++)) )
+ {
+ if ((res=Compare((unsigned char *)s,bp,ccase))!=NOMATCH)
+ {
+ p=t=s; /* t is at least a partial match */
+ if ((unique && res!=EXACT))
+ {
+ while( kwds && (p = *kwds++) )
+ {
+ if ((res=Compare((unsigned char *)p,bp,ccase))!=NOMATCH)
+ {
+ if (res==EXACT)
+ {
+ t = p;
+ break;
+ }
+ else
+ t = (char *)0;
+ }
+ }
+ }
+ if (t)
+ {
+ set_field_buffer(field,0,t);
+ return TRUE;
+ }
+ if (!p)
+ break;
+ }
+ }
+ return FALSE;
+}
+
+static const char *dummy[] = { (char *)0 };
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Next_Enum(FIELD * field,
+| const void * argp)
+|
+| Description : Check for the next enumeration value
+|
+| Return Values : TRUE - next value found and loaded
+| FALSE - no next value loaded
++--------------------------------------------------------------------------*/
+static bool Next_Enum(FIELD * field, const void * argp)
+{
+ const enumARG *args = (const enumARG *)argp;
+ char **kwds = args->kwds;
+ bool ccase = args->checkcase;
+ int cnt = args->count;
+ unsigned char *bp = (unsigned char *)field_buffer(field,0);
+
+ if (kwds) {
+ while(cnt--)
+ {
+ if (Compare((unsigned char *)(*kwds++),bp,ccase)==EXACT)
+ break;
+ }
+ if (cnt<=0)
+ kwds = args->kwds;
+ if ((cnt>=0) || (Compare((const unsigned char *)dummy,bp,ccase)==EXACT))
+ {
+ set_field_buffer(field,0,*kwds);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Previous_Enum(
+| FIELD * field,
+| const void * argp)
+|
+| Description : Check for the previous enumeration value
+|
+| Return Values : TRUE - previous value found and loaded
+| FALSE - no previous value loaded
++--------------------------------------------------------------------------*/
+static bool Previous_Enum(FIELD * field, const void * argp)
+{
+ const enumARG *args = (const enumARG *)argp;
+ int cnt = args->count;
+ char **kwds = &args->kwds[cnt-1];
+ bool ccase = args->checkcase;
+ unsigned char *bp = (unsigned char *)field_buffer(field,0);
+
+ if (kwds) {
+ while(cnt--)
+ {
+ if (Compare((unsigned char *)(*kwds--),bp,ccase)==EXACT)
+ break;
+ }
+
+ if (cnt<=0)
+ kwds = &args->kwds[args->count-1];
+
+ if ((cnt>=0) || (Compare((const unsigned char *)dummy,bp,ccase)==EXACT))
+ {
+ set_field_buffer(field,0,*kwds);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+
+static FIELDTYPE typeENUM = {
+ _HAS_ARGS | _HAS_CHOICE | _RESIDENT,
+ 1, /* this is mutable, so we can't be const */
+ (FIELDTYPE *)0,
+ (FIELDTYPE *)0,
+ Make_Enum_Type,
+ Copy_Enum_Type,
+ Free_Enum_Type,
+ Check_Enum_Field,
+ NULL,
+ Next_Enum,
+ Previous_Enum
+};
+
+FIELDTYPE* TYPE_ENUM = &typeENUM;
+
+/* fty_enum.c ends here */
diff --git a/Source/CursesDialog/form/fty_int.c b/Source/CursesDialog/form/fty_int.c
new file mode 100644
index 0000000000..7107fcc3f5
--- /dev/null
+++ b/Source/CursesDialog/form/fty_int.c
@@ -0,0 +1,161 @@
+
+/*
+ * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
+ * You may freely copy it for use as a template for your own field types.
+ * If you develop a field type that might be of general use, please send
+ * it back to the ncurses maintainers for inclusion in the next version.
+ */
+/***************************************************************************
+* *
+* Author : Juergen Pfeifer, juergen.pfeifer@gmx.net *
+* *
+***************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+typedef struct {
+ int precision;
+ long low;
+ long high;
+} integerARG;
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Make_Integer_Type( va_list * ap )
+|
+| Description : Allocate structure for integer type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error
++--------------------------------------------------------------------------*/
+static void *Make_Integer_Type(va_list * ap)
+{
+ integerARG *argp = (integerARG *)malloc(sizeof(integerARG));
+
+ if (argp)
+ {
+ argp->precision = va_arg(*ap,int);
+ argp->low = va_arg(*ap,long);
+ argp->high = va_arg(*ap,long);
+ }
+ return (void *)argp;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Copy_Integer_Type(const void * argp)
+|
+| Description : Copy structure for integer type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error.
++--------------------------------------------------------------------------*/
+static void *Copy_Integer_Type(const void * argp)
+{
+ const integerARG *ap = (const integerARG *)argp;
+ integerARG *result = (integerARG *)0;
+
+ if (argp)
+ {
+ result = (integerARG *)malloc(sizeof(integerARG));
+ if (result)
+ *result = *ap;
+ }
+ return (void *)result;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Free_Integer_Type(void * argp)
+|
+| Description : Free structure for integer type argument.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Free_Integer_Type(void * argp)
+{
+ if (argp)
+ free(argp);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_Integer_Field(
+| FIELD * field,
+| const void * argp)
+|
+| Description : Validate buffer content to be a valid integer value
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid
++--------------------------------------------------------------------------*/
+static bool Check_Integer_Field(FIELD * field, const void * argp)
+{
+ const integerARG *argi = (const integerARG *)argp;
+ long low = argi->low;
+ long high = argi->high;
+ int prec = argi->precision;
+ unsigned char *bp = (unsigned char *)field_buffer(field,0);
+ char *s = (char *)bp;
+ long val;
+ char buf[100];
+
+ while( *bp && *bp==' ') bp++;
+ if (*bp)
+ {
+ if (*bp=='-') bp++;
+ while (*bp)
+ {
+ if (!isdigit(*bp)) break;
+ bp++;
+ }
+ while(*bp && *bp==' ') bp++;
+ if (*bp=='\0')
+ {
+ val = atol(s);
+ if (low<high)
+ {
+ if (val<low || val>high) return FALSE;
+ }
+ sprintf(buf,"%.*ld",(prec>0?prec:0),val);
+ set_field_buffer(field,0,buf);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_Integer_Character(
+| int c,
+| const void * argp)
+|
+| Description : Check a character for the integer type.
+|
+| Return Values : TRUE - character is valid
+| FALSE - character is invalid
++--------------------------------------------------------------------------*/
+static bool Check_Integer_Character(int c, const void * argp)
+{
+ argp=0; /* Silence unused parameter warning. */
+ return ((isdigit(c) || (c=='-')) ? TRUE : FALSE);
+}
+
+static FIELDTYPE typeINTEGER = {
+ _HAS_ARGS | _RESIDENT,
+ 1, /* this is mutable, so we can't be const */
+ (FIELDTYPE *)0,
+ (FIELDTYPE *)0,
+ Make_Integer_Type,
+ Copy_Integer_Type,
+ Free_Integer_Type,
+ Check_Integer_Field,
+ Check_Integer_Character,
+ NULL,
+ NULL
+};
+
+FIELDTYPE* TYPE_INTEGER = &typeINTEGER;
+
+/* fty_int.c ends here */
diff --git a/Source/CursesDialog/form/fty_ipv4.c b/Source/CursesDialog/form/fty_ipv4.c
new file mode 100644
index 0000000000..c855af6557
--- /dev/null
+++ b/Source/CursesDialog/form/fty_ipv4.c
@@ -0,0 +1,84 @@
+
+/*
+ * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
+ * You may freely copy it for use as a template for your own field types.
+ * If you develop a field type that might be of general use, please send
+ * it back to the ncurses maintainers for inclusion in the next version.
+ */
+/***************************************************************************
+* *
+* Author : Per Foreby, perf@efd.lth.se *
+* *
+***************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_IPV4_Field(
+| FIELD * field,
+| const void * argp)
+|
+| Description : Validate buffer content to be a valid IP number (Ver. 4)
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid
++--------------------------------------------------------------------------*/
+static bool Check_IPV4_Field(FIELD * field, const void * argp)
+{
+ char *bp = field_buffer(field,0);
+ int num = 0, len;
+ unsigned int d1=256, d2=256, d3=256, d4=256;
+
+ argp=0; /* Silence unused parameter warning. */
+
+ if(isdigit((int)(*bp))) /* Must start with digit */
+ {
+ num = sscanf(bp, "%u.%u.%u.%u%n", &d1, &d2, &d3, &d4, &len);
+ if (num == 4)
+ {
+ bp += len; /* Make bp point to what sscanf() left */
+ while (*bp && isspace((int)(*bp)))
+ bp++; /* Allow trailing whitespace */
+ }
+ }
+ return ((num != 4 || *bp || d1 > 255 || d2 > 255
+ || d3 > 255 || d4 > 255) ? FALSE : TRUE);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_IPV4_Character(
+| int c,
+| const void *argp )
+|
+| Description : Check a character for unsigned type or period.
+|
+| Return Values : TRUE - character is valid
+| FALSE - character is invalid
++--------------------------------------------------------------------------*/
+static bool Check_IPV4_Character(int c, const void * argp)
+{
+ argp=0; /* Silence unused parameter warning. */
+ return ((isdigit(c) || (c=='.')) ? TRUE : FALSE);
+}
+
+static FIELDTYPE typeIPV4 = {
+ _RESIDENT,
+ 1, /* this is mutable, so we can't be const */
+ (FIELDTYPE *)0,
+ (FIELDTYPE *)0,
+ NULL,
+ NULL,
+ NULL,
+ Check_IPV4_Field,
+ Check_IPV4_Character,
+ NULL,
+ NULL
+};
+
+FIELDTYPE* TYPE_IPV4 = &typeIPV4;
+
+/* fty_ipv4.c ends here */
diff --git a/Source/CursesDialog/form/fty_num.c b/Source/CursesDialog/form/fty_num.c
new file mode 100644
index 0000000000..78095995fa
--- /dev/null
+++ b/Source/CursesDialog/form/fty_num.c
@@ -0,0 +1,192 @@
+
+/*
+ * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
+ * You may freely copy it for use as a template for your own field types.
+ * If you develop a field type that might be of general use, please send
+ * it back to the ncurses maintainers for inclusion in the next version.
+ */
+/***************************************************************************
+* *
+* Author : Juergen Pfeifer, juergen.pfeifer@gmx.net *
+* *
+***************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+typedef struct {
+ int precision;
+ double low;
+ double high;
+ struct lconv* L;
+} numericARG;
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Make_Numeric_Type(va_list * ap)
+|
+| Description : Allocate structure for numeric type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error
++--------------------------------------------------------------------------*/
+static void *Make_Numeric_Type(va_list * ap)
+{
+ numericARG *argn = (numericARG *)malloc(sizeof(numericARG));
+
+ if (argn)
+ {
+ argn->precision = va_arg(*ap,int);
+ argn->low = va_arg(*ap,double);
+ argn->high = va_arg(*ap,double);
+#if HAVE_LOCALE_H
+ argn->L = localeconv();
+#else
+ argn->L = NULL;
+#endif
+ }
+ return (void *)argn;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Copy_Numeric_Type(const void * argp)
+|
+| Description : Copy structure for numeric type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error.
++--------------------------------------------------------------------------*/
+static void *Copy_Numeric_Type(const void * argp)
+{
+ const numericARG *ap = (const numericARG *)argp;
+ numericARG *result = (numericARG *)0;
+
+ if (argp)
+ {
+ result = (numericARG *)malloc(sizeof(numericARG));
+ if (result)
+ *result = *ap;
+ }
+ return (void *)result;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Free_Numeric_Type(void * argp)
+|
+| Description : Free structure for numeric type argument.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Free_Numeric_Type(void * argp)
+{
+ if (argp)
+ free(argp);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_Numeric_Field(FIELD * field,
+| const void * argp)
+|
+| Description : Validate buffer content to be a valid numeric value
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid
++--------------------------------------------------------------------------*/
+static bool Check_Numeric_Field(FIELD * field, const void * argp)
+{
+ const numericARG *argn = (const numericARG *)argp;
+ double low = argn->low;
+ double high = argn->high;
+ int prec = argn->precision;
+ unsigned char *bp = (unsigned char *)field_buffer(field,0);
+ char *s = (char *)bp;
+ double val = 0.0;
+ char buf[64];
+
+ while(*bp && *bp==' ') bp++;
+ if (*bp)
+ {
+ if (*bp=='-' || *bp=='+')
+ bp++;
+ while(*bp)
+ {
+ if (!isdigit(*bp)) break;
+ bp++;
+ }
+ if (*bp==(
+#if HAVE_LOCALE_H
+ (L && L->decimal_point) ? *(L->decimal_point) :
+#endif
+ '.'))
+ {
+ bp++;
+ while(*bp)
+ {
+ if (!isdigit(*bp)) break;
+ bp++;
+ }
+ }
+ while(*bp && *bp==' ') bp++;
+ if (*bp=='\0')
+ {
+ val = atof(s);
+ if (low<high)
+ {
+ if (val<low || val>high) return FALSE;
+ }
+ sprintf(buf,"%.*f",(prec>0?prec:0),val);
+ set_field_buffer(field,0,buf);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_Numeric_Character(
+| int c,
+| const void * argp)
+|
+| Description : Check a character for the numeric type.
+|
+| Return Values : TRUE - character is valid
+| FALSE - character is invalid
++--------------------------------------------------------------------------*/
+static bool Check_Numeric_Character(int c, const void * argp)
+{
+ argp=0; /* Silence unused parameter warning. */
+ return (isdigit(c) ||
+ c == '+' ||
+ c == '-' ||
+ c == (
+#if HAVE_LOCALE_H
+ (L && L->decimal_point) ? *(L->decimal_point) :
+#endif
+ '.')
+ ) ? TRUE : FALSE;
+}
+
+static FIELDTYPE typeNUMERIC = {
+ _HAS_ARGS | _RESIDENT,
+ 1, /* this is mutable, so we can't be const */
+ (FIELDTYPE *)0,
+ (FIELDTYPE *)0,
+ Make_Numeric_Type,
+ Copy_Numeric_Type,
+ Free_Numeric_Type,
+ Check_Numeric_Field,
+ Check_Numeric_Character,
+ NULL,
+ NULL
+};
+
+FIELDTYPE* TYPE_NUMERIC = &typeNUMERIC;
+
+/* fty_num.c ends here */
diff --git a/Source/CursesDialog/form/fty_regex.c b/Source/CursesDialog/form/fty_regex.c
new file mode 100644
index 0000000000..f90e0c108d
--- /dev/null
+++ b/Source/CursesDialog/form/fty_regex.c
@@ -0,0 +1,264 @@
+
+/*
+ * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
+ * You may freely copy it for use as a template for your own field types.
+ * If you develop a field type that might be of general use, please send
+ * it back to the ncurses maintainers for inclusion in the next version.
+ */
+/***************************************************************************
+* *
+* Author : Juergen Pfeifer, juergen.pfeifer@gmx.net *
+* *
+***************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+#if HAVE_REGEX_H_FUNCS /* We prefer POSIX regex */
+#include <regex.h>
+
+typedef struct
+{
+ regex_t *pRegExp;
+ unsigned long *refCount;
+} RegExp_Arg;
+
+#elif HAVE_REGEXP_H_FUNCS | HAVE_REGEXPR_H_FUNCS
+#undef RETURN
+static int reg_errno;
+
+static char *RegEx_Init(char *instring)
+{
+ reg_errno = 0;
+ return instring;
+}
+
+static char *RegEx_Error(int code)
+{
+ reg_errno = code;
+ return 0;
+}
+
+#define INIT char *sp = RegEx_Init(instring);
+#define GETC() (*sp++)
+#define PEEKC() (*sp)
+#define UNGETC(c) (--sp)
+#define RETURN(c) return(c)
+#define ERROR(c) return RegEx_Error(c)
+
+#if HAVE_REGEXP_H_FUNCS
+#include <regexp.h>
+#else
+#include <regexpr.h>
+#endif
+
+typedef struct
+{
+ char *compiled_expression;
+ unsigned long *refCount;
+} RegExp_Arg;
+
+/* Maximum Length we allow for a compiled regular expression */
+#define MAX_RX_LEN (2048)
+#define RX_INCREMENT (256)
+
+#endif
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Make_RegularExpression_Type(va_list * ap)
+|
+| Description : Allocate structure for regex type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error
++--------------------------------------------------------------------------*/
+static void *Make_RegularExpression_Type(va_list * ap)
+{
+#if HAVE_REGEX_H_FUNCS
+ char *rx = va_arg(*ap,char *);
+ RegExp_Arg *preg;
+
+ preg = (RegExp_Arg*)malloc(sizeof(RegExp_Arg));
+ if (preg)
+ {
+ if (((preg->pRegExp = (regex_t*)malloc(sizeof(regex_t))) != (regex_t*)0)
+ && !regcomp(preg->pRegExp,rx,
+ (REG_EXTENDED | REG_NOSUB | REG_NEWLINE) ))
+ {
+ preg->refCount = (unsigned long *)malloc(sizeof(unsigned long));
+ *(preg->refCount) = 1;
+ }
+ else
+ {
+ if (preg->pRegExp)
+ free(preg->pRegExp);
+ free(preg);
+ preg = (RegExp_Arg*)0;
+ }
+ }
+ return((void *)preg);
+#elif HAVE_REGEXP_H_FUNCS | HAVE_REGEXPR_H_FUNCS
+ char *rx = va_arg(*ap,char *);
+ RegExp_Arg *pArg;
+
+ pArg = (RegExp_Arg *)malloc(sizeof(RegExp_Arg));
+
+ if (pArg)
+ {
+ int blen = RX_INCREMENT;
+ pArg->compiled_expression = NULL;
+ pArg->refCount = (unsigned long *)malloc(sizeof(unsigned long));
+ *(pArg->refCount) = 1;
+
+ do {
+ char *buf = (char *)malloc(blen);
+ if (buf)
+ {
+#if HAVE_REGEXP_H_FUNCS
+ char *last_pos = compile (rx, buf, &buf[blen], '\0');
+#else /* HAVE_REGEXPR_H_FUNCS */
+ char *last_pos = compile (rx, buf, &buf[blen]);
+#endif
+ if (reg_errno)
+ {
+ free(buf);
+ if (reg_errno==50)
+ blen += RX_INCREMENT;
+ else
+ {
+ free(pArg);
+ pArg = NULL;
+ break;
+ }
+ }
+ else
+ {
+ pArg->compiled_expression = buf;
+ break;
+ }
+ }
+ } while( blen <= MAX_RX_LEN );
+ }
+ if (pArg && !pArg->compiled_expression)
+ {
+ free(pArg);
+ pArg = NULL;
+ }
+ return (void *)pArg;
+#else
+ ap=0; /* Silence unused parameter warning. */
+ return 0;
+#endif
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void *Copy_RegularExpression_Type(
+| const void * argp)
+|
+| Description : Copy structure for regex type argument.
+|
+| Return Values : Pointer to argument structure or NULL on error.
++--------------------------------------------------------------------------*/
+static void *Copy_RegularExpression_Type(const void * argp)
+{
+#if (HAVE_REGEX_H_FUNCS | HAVE_REGEXP_H_FUNCS | HAVE_REGEXPR_H_FUNCS)
+ const RegExp_Arg *ap = (const RegExp_Arg *)argp;
+ const RegExp_Arg *result = (const RegExp_Arg *)0;
+
+ if (ap)
+ {
+ *(ap->refCount) += 1;
+ result = ap;
+ }
+ return (void *)result;
+#else
+ argp=0; /* Silence unused parameter warning. */
+ return 0;
+#endif
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Free_RegularExpression_Type(void * argp)
+|
+| Description : Free structure for regex type argument.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void Free_RegularExpression_Type(void * argp)
+{
+#if HAVE_REGEX_H_FUNCS | HAVE_REGEXP_H_FUNCS | HAVE_REGEXPR_H_FUNCS
+ RegExp_Arg *ap = (RegExp_Arg *)argp;
+ if (ap)
+ {
+ if (--(*(ap->refCount)) == 0)
+ {
+#if HAVE_REGEX_H_FUNCS
+ if (ap->pRegExp)
+ {
+ free(ap->refCount);
+ regfree(ap->pRegExp);
+ }
+#elif HAVE_REGEXP_H_FUNCS | HAVE_REGEXPR_H_FUNCS
+ if (ap->compiled_expression)
+ {
+ free(ap->refCount);
+ free(ap->compiled_expression);
+ }
+#endif
+ free(ap);
+ }
+ }
+#else
+ argp=0; /* Silence unused parameter warning. */
+#endif
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_RegularExpression_Field(
+| FIELD * field,
+| const void * argp)
+|
+| Description : Validate buffer content to be a valid regular expression
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid
++--------------------------------------------------------------------------*/
+static bool Check_RegularExpression_Field(FIELD * field, const void * argp)
+{
+ bool match = FALSE;
+#if HAVE_REGEX_H_FUNCS
+ const RegExp_Arg *ap = (const RegExp_Arg*)argp;
+ if (ap && ap->pRegExp)
+ match = (regexec(ap->pRegExp,field_buffer(field,0),0,NULL,0) ? FALSE:TRUE);
+#elif HAVE_REGEXP_H_FUNCS | HAVE_REGEXPR_H_FUNCS
+ RegExp_Arg *ap = (RegExp_Arg *)argp;
+ if (ap && ap->compiled_expression)
+ match = (step(field_buffer(field,0),ap->compiled_expression) ? TRUE:FALSE);
+#else
+ argp=0; /* Silence unused parameter warning. */
+ field=0; /* Silence unused parameter warning. */
+#endif
+ return match;
+}
+
+static FIELDTYPE typeREGEXP = {
+ _HAS_ARGS | _RESIDENT,
+ 1, /* this is mutable, so we can't be const */
+ (FIELDTYPE *)0,
+ (FIELDTYPE *)0,
+ Make_RegularExpression_Type,
+ Copy_RegularExpression_Type,
+ Free_RegularExpression_Type,
+ Check_RegularExpression_Field,
+ NULL,
+ NULL,
+ NULL
+};
+
+FIELDTYPE* TYPE_REGEXP = &typeREGEXP;
+
+/* fty_regex.c ends here */
diff --git a/Source/CursesDialog/form/llib-lform b/Source/CursesDialog/form/llib-lform
new file mode 100644
index 0000000000..ac2ba436d6
--- /dev/null
+++ b/Source/CursesDialog/form/llib-lform
@@ -0,0 +1,694 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./fld_arg.c */
+
+#include "form.priv.h"
+
+#undef set_fieldtype_arg
+int set_fieldtype_arg(
+ FIELDTYPE *typ,
+ void *(*const make_arg)(
+ va_list *p1),
+ void *(*const copy_arg)(
+ const void *p1),
+ void (*const free_arg)(
+ void *p1))
+ { return(*(int *)0); }
+
+#undef field_arg
+void *field_arg(
+ const FIELD *field)
+ { return(*(void **)0); }
+
+/* ./fld_attr.c */
+
+#undef set_field_fore
+int set_field_fore(
+ FIELD *field,
+ chtype attr)
+ { return(*(int *)0); }
+
+#undef field_fore
+chtype field_fore(
+ const FIELD *field)
+ { return(*(chtype *)0); }
+
+#undef set_field_back
+int set_field_back(
+ FIELD *field,
+ chtype attr)
+ { return(*(int *)0); }
+
+#undef field_back
+chtype field_back(
+ const FIELD *field)
+ { return(*(chtype *)0); }
+
+/* ./fld_current.c */
+
+#undef set_current_field
+int set_current_field(
+ FORM *form,
+ FIELD *field)
+ { return(*(int *)0); }
+
+#undef current_field
+FIELD *current_field(
+ const FORM *form)
+ { return(*(FIELD **)0); }
+
+#undef field_index
+int field_index(
+ const FIELD *field)
+ { return(*(int *)0); }
+
+/* ./fld_def.c */
+
+#undef _nc_Default_Field
+FIELD *_nc_Default_Field;
+
+#undef _nc_Make_Argument
+TypeArgument *_nc_Make_Argument(
+ const FIELDTYPE *typ,
+ va_list *ap,
+ int *err)
+ { return(*(TypeArgument **)0); }
+
+#undef _nc_Copy_Argument
+TypeArgument *_nc_Copy_Argument(
+ const FIELDTYPE *typ,
+ const TypeArgument *argp,
+ int *err)
+ { return(*(TypeArgument **)0); }
+
+#undef _nc_Free_Argument
+void _nc_Free_Argument(
+ const FIELDTYPE *typ,
+ TypeArgument *argp)
+ { /* void */ }
+
+#undef _nc_Copy_Type
+bool _nc_Copy_Type(
+ FIELD *dst,
+ FIELD const *src)
+ { return(*(bool *)0); }
+
+#undef _nc_Free_Type
+void _nc_Free_Type(
+ FIELD *field)
+ { /* void */ }
+
+#undef new_field
+FIELD *new_field(
+ int rows,
+ int cols,
+ int frow,
+ int fcol,
+ int nrow,
+ int nbuf)
+ { return(*(FIELD **)0); }
+
+#undef free_field
+int free_field(
+ FIELD *field)
+ { return(*(int *)0); }
+
+/* ./fld_dup.c */
+
+#undef dup_field
+FIELD *dup_field(
+ FIELD *field,
+ int frow,
+ int fcol)
+ { return(*(FIELD **)0); }
+
+/* ./fld_ftchoice.c */
+
+#undef set_fieldtype_choice
+int set_fieldtype_choice(
+ FIELDTYPE *typ,
+ bool (*const next_choice)(
+ FIELD *p1,
+ const void *p2),
+ bool (*const prev_choice)(
+ FIELD *p1,
+ const void *p2))
+ { return(*(int *)0); }
+
+/* ./fld_ftlink.c */
+
+#undef link_fieldtype
+FIELDTYPE *link_fieldtype(
+ FIELDTYPE *type1,
+ FIELDTYPE *type2)
+ { return(*(FIELDTYPE **)0); }
+
+/* ./fld_info.c */
+
+#undef field_info
+int field_info(
+ const FIELD *field,
+ int *rows,
+ int *cols,
+ int *frow,
+ int *fcol,
+ int *nrow,
+ int *nbuf)
+ { return(*(int *)0); }
+
+#undef dynamic_field_info
+int dynamic_field_info(
+ const FIELD *field,
+ int *drows,
+ int *dcols,
+ int *maxgrow)
+ { return(*(int *)0); }
+
+/* ./fld_just.c */
+
+#undef set_field_just
+int set_field_just(
+ FIELD *field,
+ int just)
+ { return(*(int *)0); }
+
+#undef field_just
+int field_just(
+ const FIELD *field)
+ { return(*(int *)0); }
+
+/* ./fld_link.c */
+
+#undef link_field
+FIELD *link_field(
+ FIELD *field,
+ int frow,
+ int fcol)
+ { return(*(FIELD **)0); }
+
+/* ./fld_max.c */
+
+#undef set_max_field
+int set_max_field(
+ FIELD *field,
+ int maxgrow)
+ { return(*(int *)0); }
+
+/* ./fld_move.c */
+
+#undef move_field
+int move_field(
+ FIELD *field,
+ int frow,
+ int fcol)
+ { return(*(int *)0); }
+
+/* ./fld_newftyp.c */
+
+#undef _nc_Default_FieldType
+const FIELDTYPE *_nc_Default_FieldType = {0};
+
+#undef new_fieldtype
+FIELDTYPE *new_fieldtype(
+ bool (*const field_check)(
+ FIELD *p1,
+ const void *p2),
+ bool (*const char_check)(
+ int p1,
+ const void *p2))
+ { return(*(FIELDTYPE **)0); }
+
+#undef free_fieldtype
+int free_fieldtype(
+ FIELDTYPE *typ)
+ { return(*(int *)0); }
+
+/* ./fld_opts.c */
+
+#undef set_field_opts
+int set_field_opts(
+ FIELD *field,
+ Field_Options opts)
+ { return(*(int *)0); }
+
+#undef field_opts
+Field_Options field_opts(
+ const FIELD *field)
+ { return(*(Field_Options *)0); }
+
+#undef field_opts_on
+int field_opts_on(
+ FIELD *field,
+ Field_Options opts)
+ { return(*(int *)0); }
+
+#undef field_opts_off
+int field_opts_off(
+ FIELD *field,
+ Field_Options opts)
+ { return(*(int *)0); }
+
+/* ./fld_pad.c */
+
+#undef set_field_pad
+int set_field_pad(
+ FIELD *field,
+ int ch)
+ { return(*(int *)0); }
+
+#undef field_pad
+int field_pad(
+ const FIELD *field)
+ { return(*(int *)0); }
+
+/* ./fld_page.c */
+
+#undef set_new_page
+int set_new_page(
+ FIELD *field,
+ bool new_page_flag)
+ { return(*(int *)0); }
+
+#undef new_page
+bool new_page(
+ const FIELD *field)
+ { return(*(bool *)0); }
+
+/* ./fld_stat.c */
+
+#undef set_field_status
+int set_field_status(
+ FIELD *field,
+ bool status)
+ { return(*(int *)0); }
+
+#undef field_status
+bool field_status(
+ const FIELD *field)
+ { return(*(bool *)0); }
+
+/* ./fld_type.c */
+
+#undef set_field_type
+int set_field_type(
+ FIELD *field,
+ FIELDTYPE *type,
+ ...)
+ { return(*(int *)0); }
+
+#undef field_type
+FIELDTYPE *field_type(
+ const FIELD *field)
+ { return(*(FIELDTYPE **)0); }
+
+/* ./fld_user.c */
+
+#undef set_field_userptr
+int set_field_userptr(
+ FIELD *field,
+ void *usrptr)
+ { return(*(int *)0); }
+
+#undef field_userptr
+void *field_userptr(
+ const FIELD *field)
+ { return(*(void **)0); }
+
+/* ./frm_cursor.c */
+
+#undef pos_form_cursor
+int pos_form_cursor(
+ FORM *form)
+ { return(*(int *)0); }
+
+/* ./frm_data.c */
+
+#undef data_behind
+bool data_behind(
+ const FORM *form)
+ { return(*(bool *)0); }
+
+#undef data_ahead
+bool data_ahead(
+ const FORM *form)
+ { return(*(bool *)0); }
+
+/* ./frm_def.c */
+
+#undef _nc_Default_Form
+FORM *_nc_Default_Form;
+
+#undef new_form
+FORM *new_form(
+ FIELD **fields)
+ { return(*(FORM **)0); }
+
+#undef free_form
+int free_form(
+ FORM *form)
+ { return(*(int *)0); }
+
+#undef set_form_fields
+int set_form_fields(
+ FORM *form,
+ FIELD **fields)
+ { return(*(int *)0); }
+
+#undef form_fields
+FIELD **form_fields(
+ const FORM *form)
+ { return(*(FIELD ***)0); }
+
+#undef field_count
+int field_count(
+ const FORM *form)
+ { return(*(int *)0); }
+
+/* ./frm_driver.c */
+
+#undef _nc_Position_Form_Cursor
+int _nc_Position_Form_Cursor(
+ FORM *form)
+ { return(*(int *)0); }
+
+#undef _nc_Refresh_Current_Field
+int _nc_Refresh_Current_Field(
+ FORM *form)
+ { return(*(int *)0); }
+
+#undef _nc_Synchronize_Attributes
+int _nc_Synchronize_Attributes(
+ FIELD *field)
+ { return(*(int *)0); }
+
+#undef _nc_Synchronize_Options
+int _nc_Synchronize_Options(
+ FIELD *field,
+ Field_Options newopts)
+ { return(*(int *)0); }
+
+#undef _nc_Set_Current_Field
+int _nc_Set_Current_Field(
+ FORM *form,
+ FIELD *newfield)
+ { return(*(int *)0); }
+
+#undef _nc_Internal_Validation
+bool _nc_Internal_Validation(
+ FORM *form)
+ { return(*(bool *)0); }
+
+#undef _nc_First_Active_Field
+FIELD *_nc_First_Active_Field(
+ FORM *form)
+ { return(*(FIELD **)0); }
+
+#undef _nc_Set_Form_Page
+int _nc_Set_Form_Page(
+ FORM *form,
+ int page,
+ FIELD *field)
+ { return(*(int *)0); }
+
+typedef struct {
+ int keycode;
+ int (*cmd)(FORM *);
+} Binding_Info;
+
+#undef form_driver
+int form_driver(
+ FORM *form,
+ int c)
+ { return(*(int *)0); }
+
+#undef set_field_buffer
+int set_field_buffer(
+ FIELD *field,
+ int buffer,
+ const char *value)
+ { return(*(int *)0); }
+
+#undef field_buffer
+char *field_buffer(
+ const FIELD *field,
+ int buffer)
+ { return(*(char **)0); }
+
+/* ./frm_hook.c */
+
+#undef set_field_init
+int set_field_init(
+ FORM *form,
+ Form_Hook func)
+ { return(*(int *)0); }
+
+#undef field_init
+Form_Hook field_init(
+ const FORM *form)
+ { return(*(Form_Hook *)0); }
+
+#undef set_field_term
+int set_field_term(
+ FORM *form,
+ Form_Hook func)
+ { return(*(int *)0); }
+
+#undef field_term
+Form_Hook field_term(
+ const FORM *form)
+ { return(*(Form_Hook *)0); }
+
+#undef set_form_init
+int set_form_init(
+ FORM *form,
+ Form_Hook func)
+ { return(*(int *)0); }
+
+#undef form_init
+Form_Hook form_init(
+ const FORM *form)
+ { return(*(Form_Hook *)0); }
+
+#undef set_form_term
+int set_form_term(
+ FORM *form,
+ Form_Hook func)
+ { return(*(int *)0); }
+
+#undef form_term
+Form_Hook form_term(
+ const FORM *form)
+ { return(*(Form_Hook *)0); }
+
+/* ./frm_opts.c */
+
+#undef set_form_opts
+int set_form_opts(
+ FORM *form,
+ Form_Options opts)
+ { return(*(int *)0); }
+
+#undef form_opts
+Form_Options form_opts(
+ const FORM *form)
+ { return(*(Form_Options *)0); }
+
+#undef form_opts_on
+int form_opts_on(
+ FORM *form,
+ Form_Options opts)
+ { return(*(int *)0); }
+
+#undef form_opts_off
+int form_opts_off(
+ FORM *form,
+ Form_Options opts)
+ { return(*(int *)0); }
+
+/* ./frm_page.c */
+
+#undef set_form_page
+int set_form_page(
+ FORM *form,
+ int page)
+ { return(*(int *)0); }
+
+#undef form_page
+int form_page(
+ const FORM *form)
+ { return(*(int *)0); }
+
+/* ./frm_post.c */
+
+#undef post_form
+int post_form(
+ FORM *form)
+ { return(*(int *)0); }
+
+#undef unpost_form
+int unpost_form(
+ FORM *form)
+ { return(*(int *)0); }
+
+/* ./frm_req_name.c */
+
+#undef form_request_name
+const char *form_request_name(
+ int request)
+ { return(*(const char **)0); }
+
+#undef form_request_by_name
+int form_request_by_name(
+ const char *str)
+ { return(*(int *)0); }
+
+/* ./frm_scale.c */
+
+#undef scale_form
+int scale_form(
+ const FORM *form,
+ int *rows,
+ int *cols)
+ { return(*(int *)0); }
+
+/* ./frm_sub.c */
+
+#undef set_form_sub
+int set_form_sub(
+ FORM *form,
+ WINDOW *win)
+ { return(*(int *)0); }
+
+#undef form_sub
+WINDOW *form_sub(
+ const FORM *form)
+ { return(*(WINDOW **)0); }
+
+/* ./frm_user.c */
+
+#undef set_form_userptr
+int set_form_userptr(
+ FORM *form,
+ void *usrptr)
+ { return(*(int *)0); }
+
+#undef form_userptr
+void *form_userptr(
+ const FORM *form)
+ { return(*(void **)0); }
+
+/* ./frm_win.c */
+
+#undef set_form_win
+int set_form_win(
+ FORM *form,
+ WINDOW *win)
+ { return(*(int *)0); }
+
+#undef form_win
+WINDOW *form_win(
+ const FORM *form)
+ { return(*(WINDOW **)0); }
+
+/* ./fty_alnum.c */
+
+typedef struct {
+ int width;
+} alnumARG;
+
+#undef TYPE_ALNUM
+FIELDTYPE *TYPE_ALNUM;
+
+/* ./fty_alpha.c */
+
+typedef struct {
+ int width;
+} alphaARG;
+
+#undef TYPE_ALPHA
+FIELDTYPE *TYPE_ALPHA;
+
+/* ./fty_enum.c */
+
+typedef struct {
+ char **kwds;
+ int count;
+ bool checkcase;
+ bool checkunique;
+} enumARG;
+
+#undef TYPE_ENUM
+FIELDTYPE *TYPE_ENUM;
+
+/* ./fty_int.c */
+
+typedef struct {
+ int precision;
+ long low;
+ long high;
+} integerARG;
+
+#undef TYPE_INTEGER
+FIELDTYPE *TYPE_INTEGER;
+
+/* ./fty_ipv4.c */
+#undef TYPE_IPV4
+FIELDTYPE *TYPE_IPV4;
+
+/* ./fty_num.c */
+
+#include <locale.h>
+
+typedef struct {
+ int precision;
+ double low;
+ double high;
+ struct lconv* L;
+} numericARG;
+
+#undef TYPE_NUMERIC
+FIELDTYPE *TYPE_NUMERIC;
+
+/* ./fty_regex.c */
+
+#include <regex.h>
+
+typedef struct
+{
+ regex_t *pRegExp;
+ unsigned long *refCount;
+} RegExp_Arg;
+
+#undef TYPE_REGEXP
+FIELDTYPE *TYPE_REGEXP;
diff --git a/Source/CursesDialog/form/mf_common.h b/Source/CursesDialog/form/mf_common.h
new file mode 100644
index 0000000000..6b1e8feee2
--- /dev/null
+++ b/Source/CursesDialog/form/mf_common.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
+ ****************************************************************************/
+
+/* Common internal header for menu and form library */
+
+#if HAVE_CONFIG_H
+# include <ncurses_cfg.h>
+#endif
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+
+#if DECL_ERRNO
+extern int errno;
+#endif
+
+/* in case of debug version we ignore the suppression of assertions */
+#ifdef TRACE
+# ifdef NDEBUG
+# undef NDEBUG
+# endif
+#endif
+
+#include <nc_alloc.h>
+
+#if USE_RCS_IDS
+#define MODULE_ID(id) static const char Ident[] = id;
+#else
+#define MODULE_ID(id) /*nothing*/
+#endif
+
+
+/* Maximum regular 8-bit character code */
+#define MAX_REGULAR_CHARACTER (0xff)
+
+#define SET_ERROR(code) (errno=(code))
+#define GET_ERROR() (errno)
+#define RETURN(code) return( SET_ERROR(code) )
+
+/* The few common values in the status fields for menus and forms */
+#define _POSTED (0x01) /* menu or form is posted */
+#define _IN_DRIVER (0x02) /* menu or form is processing hook routine */
+
+/* Call object hook */
+#define Call_Hook( object, handler ) \
+ if ( (object) && ((object)->handler) )\
+ {\
+ (object)->status |= _IN_DRIVER;\
+ (object)->handler(object);\
+ (object)->status &= ~_IN_DRIVER;\
+ }
+
+#define INLINE
+
+#ifndef TRACE
+# if CC_HAS_INLINE_FUNCS
+# undef INLINE
+# define INLINE inline
+# endif
+#endif
diff --git a/Source/CursesDialog/form/nc_alloc.h b/Source/CursesDialog/form/nc_alloc.h
new file mode 100644
index 0000000000..f49ea93e87
--- /dev/null
+++ b/Source/CursesDialog/form/nc_alloc.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 *
+ ****************************************************************************/
+/* $Id$ */
+
+#ifndef NC_ALLOC_included
+#define NC_ALLOC_included 1
+
+#if HAVE_LIBDMALLOC
+#include <dmalloc.h> /* Gray Watson's library */
+#else
+#undef HAVE_LIBDMALLOC
+#define HAVE_LIBDMALLOC 0
+#endif
+
+#if HAVE_LIBDBMALLOC
+#include <dbmalloc.h> /* Conor Cahill's library */
+#else
+#undef HAVE_LIBDBMALLOC
+#define HAVE_LIBDBMALLOC 0
+#endif
+
+#ifndef NO_LEAKS
+#define NO_LEAKS 0
+#endif
+
+#if HAVE_LIBDBMALLOC || HAVE_LIBDMALLOC || NO_LEAKS
+#define HAVE_NC_FREEALL 1
+struct termtype;
+extern void _nc_free_and_exit(int) GCC_NORETURN;
+extern void _nc_free_tparm(void);
+extern void _nc_leaks_dump_entry(void);
+#define ExitProgram(code) _nc_free_and_exit(code)
+#endif
+
+#ifndef HAVE_NC_FREEALL
+#define HAVE_NC_FREEALL 0
+#endif
+
+#ifndef ExitProgram
+#define ExitProgram(code) return code
+#endif
+
+/* doalloc.c */
+extern void *_nc_doalloc(void *, size_t);
+#if !HAVE_STRDUP
+/* #define strdup _nc_strdup */
+extern char *_nc_strdup(const char *);
+#endif
+
+#define typeMalloc(type,elts) (type *)malloc((elts)*sizeof(type))
+#define typeCalloc(type,elts) (type *)calloc((elts),sizeof(type))
+#define typeRealloc(type,elts,ptr) (type *)_nc_doalloc(ptr, (elts)*sizeof(type))
+
+#endif /* NC_ALLOC_included */
diff --git a/Source/QtDialog/AddCacheEntry.cxx b/Source/QtDialog/AddCacheEntry.cxx
new file mode 100644
index 0000000000..3881045bdd
--- /dev/null
+++ b/Source/QtDialog/AddCacheEntry.cxx
@@ -0,0 +1,113 @@
+/*============================================================================
+ 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 "AddCacheEntry.h"
+#include <QMetaProperty>
+#include <QCompleter>
+
+static const int NumTypes = 4;
+static const int DefaultTypeIndex = 0;
+static const QByteArray TypeStrings[NumTypes] =
+ { "BOOL", "PATH", "FILEPATH", "STRING" };
+static const QCMakeProperty::PropertyType Types[NumTypes] =
+ { QCMakeProperty::BOOL, QCMakeProperty::PATH,
+ QCMakeProperty::FILEPATH, QCMakeProperty::STRING};
+
+AddCacheEntry::AddCacheEntry(QWidget* p, const QStringList& varNames,
+ const QStringList& varTypes)
+ : QWidget(p), VarNames(varNames), VarTypes(varTypes)
+{
+ this->setupUi(this);
+ for(int i=0; i<NumTypes; i++)
+ {
+ this->Type->addItem(TypeStrings[i]);
+ }
+ QWidget* cb = new QCheckBox();
+ QWidget* path = new QCMakePathEditor();
+ QWidget* filepath = new QCMakeFilePathEditor();
+ QWidget* string = new QLineEdit();
+ this->StackedWidget->addWidget(cb);
+ this->StackedWidget->addWidget(path);
+ this->StackedWidget->addWidget(filepath);
+ this->StackedWidget->addWidget(string);
+ this->setTabOrder(this->Name, this->Type);
+ this->setTabOrder(this->Type, cb);
+ this->setTabOrder(cb, path);
+ this->setTabOrder(path, filepath);
+ this->setTabOrder(filepath, string);
+ this->setTabOrder(string, this->Description);
+ QCompleter *completer = new QCompleter(this->VarNames, this);
+ this->Name->setCompleter(completer);
+ connect(completer, SIGNAL(activated(const QString&)),
+ this, SLOT(onCompletionActivated(const QString&)));
+}
+
+QString AddCacheEntry::name() const
+{
+ return this->Name->text();
+}
+
+QVariant AddCacheEntry::value() const
+{
+ QWidget* w = this->StackedWidget->currentWidget();
+ if(qobject_cast<QLineEdit*>(w))
+ {
+ return static_cast<QLineEdit*>(w)->text();
+ }
+ else if(qobject_cast<QCheckBox*>(w))
+ {
+ return static_cast<QCheckBox*>(w)->isChecked();
+ }
+ return QVariant();
+}
+
+QString AddCacheEntry::description() const
+{
+ return this->Description->text();
+}
+
+QCMakeProperty::PropertyType AddCacheEntry::type() const
+{
+ int idx = this->Type->currentIndex();
+ if(idx >= 0 && idx < NumTypes)
+ {
+ return Types[idx];
+ }
+ return Types[DefaultTypeIndex];
+}
+
+QString AddCacheEntry::typeString() const
+{
+ int idx = this->Type->currentIndex();
+ if(idx >= 0 && idx < NumTypes)
+ {
+ return TypeStrings[idx];
+ }
+ return TypeStrings[DefaultTypeIndex];
+}
+
+void AddCacheEntry::onCompletionActivated(const QString &text)
+{
+ int idx = this->VarNames.indexOf(text);
+ if (idx != -1)
+ {
+ QString vartype = this->VarTypes[idx];
+ for (int i = 0; i < NumTypes; i++)
+ {
+ if (TypeStrings[i] == vartype)
+ {
+ this->Type->setCurrentIndex(i);
+ break;
+ }
+ }
+ }
+}
diff --git a/Source/QtDialog/AddCacheEntry.h b/Source/QtDialog/AddCacheEntry.h
new file mode 100644
index 0000000000..38c3a7444c
--- /dev/null
+++ b/Source/QtDialog/AddCacheEntry.h
@@ -0,0 +1,45 @@
+/*============================================================================
+ 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 AddCacheEntry_h
+#define AddCacheEntry_h
+
+#include <QWidget>
+#include <QCheckBox>
+#include <QStringList>
+
+#include "QCMake.h"
+#include "ui_AddCacheEntry.h"
+
+class AddCacheEntry : public QWidget, public Ui::AddCacheEntry
+{
+ Q_OBJECT
+public:
+ AddCacheEntry(QWidget* p, const QStringList& varNames,
+ const QStringList& varTypes);
+
+ QString name() const;
+ QVariant value() const;
+ QString description() const;
+ QCMakeProperty::PropertyType type() const;
+ QString typeString() const;
+
+private slots:
+ void onCompletionActivated(const QString &text);
+
+private:
+ const QStringList& VarNames;
+ const QStringList& VarTypes;
+};
+
+#endif
+
diff --git a/Source/QtDialog/AddCacheEntry.ui b/Source/QtDialog/AddCacheEntry.ui
new file mode 100644
index 0000000000..a81587473d
--- /dev/null
+++ b/Source/QtDialog/AddCacheEntry.ui
@@ -0,0 +1,97 @@
+<ui version="4.0" >
+ <class>AddCacheEntry</class>
+ <widget class="QWidget" name="AddCacheEntry" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>380</width>
+ <height>158</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Name:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="Name" />
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Type:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QComboBox" name="Type" >
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_5" >
+ <property name="text" >
+ <string>Value:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QStackedWidget" name="StackedWidget" >
+ <property name="currentIndex" >
+ <number>0</number>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Description:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QLineEdit" name="Description" />
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QCMakePathEditor</class>
+ <extends>QLineEdit</extends>
+ <header>QCMakeWidgets.h</header>
+ </customwidget>
+ <customwidget>
+ <class>QCMakeFilePathEditor</class>
+ <extends>QLineEdit</extends>
+ <header>QCMakeWidgets.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>Type</sender>
+ <signal>currentIndexChanged(int)</signal>
+ <receiver>StackedWidget</receiver>
+ <slot>setCurrentIndex(int)</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>229</x>
+ <y>34</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>287</x>
+ <y>65</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/Source/QtDialog/CMake.desktop b/Source/QtDialog/CMake.desktop
new file mode 100644
index 0000000000..7be495f993
--- /dev/null
+++ b/Source/QtDialog/CMake.desktop
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Version=1.0
+Name=CMake
+Comment=Cross-platform buildsystem
+Exec=cmake-gui %f
+Icon=CMakeSetup32
+Terminal=false
+X-MultipleArgs=false
+Type=Application
+Categories=Development;
+StartupNotify=true
+MimeType=application/x-cmakecache;
diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt
new file mode 100644
index 0000000000..03c2fb42b8
--- /dev/null
+++ b/Source/QtDialog/CMakeLists.txt
@@ -0,0 +1,203 @@
+#=============================================================================
+# 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.
+#=============================================================================
+
+project(QtDialog)
+if(POLICY CMP0020)
+ cmake_policy(SET CMP0020 NEW) # Drop when CMake >= 2.8.11 required
+endif()
+find_package(Qt5Widgets QUIET)
+if (Qt5Widgets_FOUND)
+ include_directories(${Qt5Widgets_INCLUDE_DIRS})
+ add_definitions(${Qt5Widgets_DEFINITONS})
+ macro(qt4_wrap_ui)
+ qt5_wrap_ui(${ARGN})
+ endmacro()
+ macro(qt4_wrap_cpp)
+ qt5_wrap_cpp(${ARGN})
+ endmacro()
+ macro(qt4_add_resources)
+ qt5_add_resources(${ARGN})
+ endmacro()
+ set(CMake_QT_LIBRARIES ${Qt5Widgets_LIBRARIES})
+ set(QT_QTMAIN_LIBRARY ${Qt5Core_QTMAIN_LIBRARIES})
+
+ # Remove this when the minimum version of Qt is 4.6.
+ add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
+
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
+
+ # We need to install Cocoa platform plugin and add qt.conf for Qt5 on Mac.
+ # FIXME: This should be part of Qt5 CMake scripts, but unfortunatelly
+ # Qt5 Mac support is missing there.
+ if(APPLE)
+ macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
+ get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
+ if(EXISTS "${_qt_plugin_path}")
+ get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
+ get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
+ get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
+ set(_qt_plugin_dest "${CMAKE_INSTALL_PREFIX}/PlugIns/${_qt_plugin_type}")
+ install(FILES "${_qt_plugin_path}"
+ DESTINATION "${_qt_plugin_dest}")
+ set(${_qt_plugins_var}
+ "${${_qt_plugins_var}};${_qt_plugin_dest}/${_qt_plugin_file}")
+ else()
+ message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found")
+ endif()
+ endmacro()
+ install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
+ "[Paths]\nPlugins = PlugIns\n")
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
+ DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources")
+ endif()
+
+ if(WIN32 AND TARGET Qt5::Core)
+ get_property(_Qt5_Core_LOCATION TARGET Qt5::Core PROPERTY LOCATION)
+ get_filename_component(Qt_BIN_DIR "${_Qt5_Core_LOCATION}" PATH)
+ endif()
+else()
+ set(QT_MIN_VERSION "4.4.0")
+ find_package(Qt4 REQUIRED)
+ if(NOT QT4_FOUND)
+ message(SEND_ERROR "Failed to find Qt 4.4 or greater.")
+ return()
+ endif()
+
+ include(${QT_USE_FILE})
+
+ set(CMake_QT_LIBRARIES ${QT_LIBRARIES})
+
+ if(WIN32 AND EXISTS "${QT_QMAKE_EXECUTABLE}")
+ get_filename_component(_Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH)
+ if(EXISTS "${_Qt_BIN_DIR}/QtCore4.dll")
+ set(Qt_BIN_DIR ${_Qt_BIN_DIR})
+ endif()
+ endif()
+endif()
+
+set(SRCS
+ AddCacheEntry.cxx
+ AddCacheEntry.h
+ CMakeSetup.cxx
+ CMakeSetupDialog.cxx
+ CMakeSetupDialog.h
+ FirstConfigure.cxx
+ FirstConfigure.h
+ QCMake.cxx
+ QCMake.h
+ QCMakeCacheView.cxx
+ QCMakeCacheView.h
+ QCMakeWidgets.cxx
+ QCMakeWidgets.h
+ QMacInstallDialog.cxx
+ QMacInstallDialog.h
+ )
+QT4_WRAP_UI(UI_SRCS
+ CMakeSetupDialog.ui
+ Compilers.ui
+ CrossCompiler.ui
+ AddCacheEntry.ui
+ MacInstallDialog.ui
+ )
+QT4_WRAP_CPP(MOC_SRCS
+ AddCacheEntry.h
+ Compilers.h
+ CMakeSetupDialog.h
+ FirstConfigure.h
+ QCMake.h
+ QCMakeCacheView.h
+ QCMakeWidgets.h
+ QMacInstallDialog.h
+ )
+QT4_ADD_RESOURCES(RC_SRCS CMakeSetup.qrc)
+
+set(SRCS ${SRCS} ${UI_SRCS} ${MOC_SRCS} ${RC_SRCS})
+if(WIN32)
+ set(SRCS ${SRCS} CMakeSetup.rc)
+endif()
+if(APPLE)
+ set(SRCS ${SRCS} CMakeSetup.icns)
+ set(MACOSX_BUNDLE_ICON_FILE CMakeSetup.icns)
+ set_source_files_properties(CMakeSetup.icns PROPERTIES
+ MACOSX_PACKAGE_LOCATION Resources)
+endif()
+
+if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
+ install(FILES ${CMake_SOURCE_DIR}/Licenses/LGPLv2.1.txt
+ DESTINATION ${CMAKE_DATA_DIR}/Licenses)
+ set_property(SOURCE CMakeSetupDialog.cxx
+ PROPERTY COMPILE_DEFINITIONS CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
+endif()
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS})
+target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${CMake_QT_LIBRARIES})
+if(Qt_BIN_DIR)
+ set_property(TARGET cmake-gui PROPERTY Qt_BIN_DIR ${Qt_BIN_DIR})
+endif()
+
+if(APPLE)
+ file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
+ LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
+
+ set_target_properties(cmake-gui PROPERTIES
+ OUTPUT_NAME CMake
+ MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
+ MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_BUNDLE_VERSION}"
+ # TBD: MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_BUNDLE_VERSION}"
+ MACOSX_BUNDLE_COPYRIGHT "${copyright_line}"
+ )
+
+ # Create a symlink in the build tree to provide a "cmake-gui" next
+ # to the "cmake" executable that refers to the application bundle.
+ add_custom_command(TARGET cmake-gui POST_BUILD
+ COMMAND ln -sf CMake.app/Contents/MacOS/CMake
+ $<TARGET_FILE_DIR:cmake>/cmake-gui
+ )
+endif()
+set(CMAKE_INSTALL_DESTINATION_ARGS
+ BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}")
+
+install(TARGETS cmake-gui RUNTIME DESTINATION bin ${CMAKE_INSTALL_DESTINATION_ARGS})
+
+if(UNIX)
+ # install a desktop file so CMake appears in the application start menu
+ # with an icon
+ install(FILES CMake.desktop DESTINATION share/applications )
+ install(FILES CMakeSetup32.png DESTINATION share/pixmaps )
+ install(FILES cmakecache.xml DESTINATION share/mime/packages )
+endif()
+
+if(APPLE)
+ install(CODE "execute_process(COMMAND ln -s \"../MacOS/CMake\" cmake-gui
+ WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)")
+endif()
+
+if(APPLE OR WIN32)
+ # install rules for including 3rd party libs such as Qt
+ # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
+ set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
+ if(APPLE)
+ set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/CMake")
+ endif()
+ install(CODE "
+ include(\"${CMake_SOURCE_DIR}/Modules/BundleUtilities.cmake\")
+ set(BU_CHMOD_BUNDLE_ITEMS ON)
+ fixup_bundle(\"${fixup_exe}\" \"${QT_PLUGINS}\" \"${QT_LIBRARY_DIR};${QT_BINARY_DIR}\")
+ ")
+endif()
+
+set(CMAKE_PACKAGE_QTGUI TRUE)
+configure_file("${QtDialog_SOURCE_DIR}/QtDialogCPack.cmake.in"
+ "${QtDialog_BINARY_DIR}/QtDialogCPack.cmake" @ONLY)
diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx
new file mode 100644
index 0000000000..82fa3a3a97
--- /dev/null
+++ b/Source/QtDialog/CMakeSetup.cxx
@@ -0,0 +1,189 @@
+/*============================================================================
+ 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 "QCMake.h" // include to disable MS warnings
+#include <QApplication>
+#include <QDir>
+#include <QTranslator>
+#include <QLocale>
+#include <QTextCodec>
+#include "QMacInstallDialog.h"
+#include "CMakeSetupDialog.h"
+#include "cmDocumentation.h"
+#include "cmake.h"
+#include "cmVersion.h"
+#include <cmsys/CommandLineArguments.hxx>
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Encoding.hxx>
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationName[][2] =
+{
+ {0,
+ " cmake-gui - CMake GUI."},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationUsage[][2] =
+{
+ {0,
+ " cmake-gui [options]\n"
+ " cmake-gui [options] <path-to-source>\n"
+ " cmake-gui [options] <path-to-existing-build>"},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationOptions[][2] =
+{
+ {0,0}
+};
+
+int main(int argc, char** argv)
+{
+ cmsys::Encoding::CommandLineArguments encoding_args =
+ cmsys::Encoding::CommandLineArguments::Main(argc, argv);
+ int argc2 = encoding_args.argc();
+ char const* const* argv2 = encoding_args.argv();
+
+ cmSystemTools::FindCMakeResources(argv2[0]);
+ // check docs first so that X is not need to get docs
+ // do docs, if args were given
+ cmDocumentation doc;
+ doc.addCMakeStandardDocSections();
+ if(argc2 >1 && doc.CheckOptions(argc2, argv2))
+ {
+ // Construct and print requested documentation.
+ cmake hcm;
+ hcm.AddCMakePaths();
+
+ std::vector<cmDocumentationEntry> generators;
+ hcm.GetGeneratorDocumentation(generators);
+ doc.SetName("cmake");
+ doc.SetSection("Name",cmDocumentationName);
+ doc.SetSection("Usage",cmDocumentationUsage);
+ doc.AppendSection("Generators",generators);
+ doc.PrependSection("Options",cmDocumentationOptions);
+
+ return (doc.PrintRequestedDocumentation(std::cout)? 0:1);
+ }
+
+ QApplication app(argc, argv);
+
+#if defined(CMAKE_ENCODING_UTF8)
+ QTextCodec* utf8_codec = QTextCodec::codecForName("UTF-8");
+ QTextCodec::setCodecForLocale(utf8_codec);
+#endif
+
+ // clean out standard Qt paths for plugins, which we don't use anyway
+ // when creating Mac bundles, it potentially causes problems
+ foreach(QString p, QApplication::libraryPaths())
+ {
+ QApplication::removeLibraryPath(p);
+ }
+
+ // if arg for install
+ for(int i =0; i < argc2; i++)
+ {
+ if(strcmp(argv2[i], "--mac-install") == 0)
+ {
+ QMacInstallDialog setupdialog(0);
+ setupdialog.exec();
+ return 0;
+ }
+ }
+ // tell the cmake library where cmake is
+ QDir cmExecDir(QApplication::applicationDirPath());
+#if defined(Q_OS_MAC)
+ cmExecDir.cd("../../../");
+#endif
+
+ // pick up translation files if they exists in the data directory
+ QDir translationsDir = cmExecDir;
+ translationsDir.cd(QString::fromLocal8Bit(".." CMAKE_DATA_DIR));
+ translationsDir.cd("i18n");
+ QTranslator translator;
+ QString transfile = QString("cmake_%1").arg(QLocale::system().name());
+ translator.load(transfile, translationsDir.path());
+ app.installTranslator(&translator);
+
+ // app setup
+ app.setApplicationName("CMakeSetup");
+ app.setOrganizationName("Kitware");
+ QIcon appIcon;
+ appIcon.addFile(":/Icons/CMakeSetup32.png");
+ appIcon.addFile(":/Icons/CMakeSetup128.png");
+ app.setWindowIcon(appIcon);
+
+ CMakeSetupDialog dialog;
+ dialog.show();
+
+ cmsys::CommandLineArguments arg;
+ arg.Initialize(argc2, argv2);
+ std::string binaryDirectory;
+ std::string sourceDirectory;
+ typedef cmsys::CommandLineArguments argT;
+ arg.AddArgument("-B", argT::CONCAT_ARGUMENT,
+ &binaryDirectory, "Binary Directory");
+ arg.AddArgument("-H", argT::CONCAT_ARGUMENT,
+ &sourceDirectory, "Source Directory");
+ // do not complain about unknown options
+ arg.StoreUnusedArguments(true);
+ arg.Parse();
+ if(!sourceDirectory.empty() && !binaryDirectory.empty())
+ {
+ dialog.setSourceDirectory(QString::fromLocal8Bit(sourceDirectory.c_str()));
+ dialog.setBinaryDirectory(QString::fromLocal8Bit(binaryDirectory.c_str()));
+ }
+ else
+ {
+ QStringList args = app.arguments();
+ if(args.count() == 2)
+ {
+ cmsys_stl::string filePath = cmSystemTools::CollapseFullPath(args[1].toLocal8Bit().data());
+
+ // check if argument is a directory containing CMakeCache.txt
+ cmsys_stl::string buildFilePath =
+ cmSystemTools::CollapseFullPath("CMakeCache.txt", filePath.c_str());
+
+ // check if argument is a CMakeCache.txt file
+ if(cmSystemTools::GetFilenameName(filePath) == "CMakeCache.txt" &&
+ cmSystemTools::FileExists(filePath.c_str()))
+ {
+ buildFilePath = filePath;
+ }
+
+ // check if argument is a directory containing CMakeLists.txt
+ cmsys_stl::string srcFilePath =
+ cmSystemTools::CollapseFullPath("CMakeLists.txt", filePath.c_str());
+
+ if(cmSystemTools::FileExists(buildFilePath.c_str()))
+ {
+ dialog.setBinaryDirectory(
+ QString::fromLocal8Bit(
+ cmSystemTools::GetFilenamePath(buildFilePath).c_str()
+ )
+ );
+ }
+ else if(cmSystemTools::FileExists(srcFilePath.c_str()))
+ {
+ dialog.setSourceDirectory(QString::fromLocal8Bit(filePath.c_str()));
+ dialog.setBinaryDirectory(
+ QString::fromLocal8Bit(cmSystemTools::CollapseFullPath(".").c_str())
+ );
+ }
+ }
+ }
+
+ return app.exec();
+}
+
diff --git a/Source/QtDialog/CMakeSetup.icns b/Source/QtDialog/CMakeSetup.icns
new file mode 100644
index 0000000000..4a50c04169
--- /dev/null
+++ b/Source/QtDialog/CMakeSetup.icns
Binary files differ
diff --git a/Source/QtDialog/CMakeSetup.ico b/Source/QtDialog/CMakeSetup.ico
new file mode 100644
index 0000000000..e13bb156f4
--- /dev/null
+++ b/Source/QtDialog/CMakeSetup.ico
Binary files differ
diff --git a/Source/QtDialog/CMakeSetup.qrc b/Source/QtDialog/CMakeSetup.qrc
new file mode 100644
index 0000000000..eaac192236
--- /dev/null
+++ b/Source/QtDialog/CMakeSetup.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/Icons" >
+ <file>CMakeSetup128.png</file>
+ <file>CMakeSetup32.png</file>
+ <file>Delete16.png</file>
+ <file>Plus16.png</file>
+ </qresource>
+</RCC>
diff --git a/Source/QtDialog/CMakeSetup.rc b/Source/QtDialog/CMakeSetup.rc
new file mode 100644
index 0000000000..fcc887ddb3
--- /dev/null
+++ b/Source/QtDialog/CMakeSetup.rc
@@ -0,0 +1 @@
+IDI_ICON1 ICON DISCARDABLE "CMakeSetup.ico"
diff --git a/Source/QtDialog/CMakeSetup128.png b/Source/QtDialog/CMakeSetup128.png
new file mode 100644
index 0000000000..12f1d9a9a1
--- /dev/null
+++ b/Source/QtDialog/CMakeSetup128.png
Binary files differ
diff --git a/Source/QtDialog/CMakeSetup32.png b/Source/QtDialog/CMakeSetup32.png
new file mode 100644
index 0000000000..7bbcee413c
--- /dev/null
+++ b/Source/QtDialog/CMakeSetup32.png
Binary files differ
diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx
new file mode 100644
index 0000000000..0574681d3c
--- /dev/null
+++ b/Source/QtDialog/CMakeSetupDialog.cxx
@@ -0,0 +1,1331 @@
+/*============================================================================
+ 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 "CMakeSetupDialog.h"
+#include <QFileDialog>
+#include <QProgressBar>
+#include <QMessageBox>
+#include <QStatusBar>
+#include <QToolButton>
+#include <QDialogButtonBox>
+#include <QCloseEvent>
+#include <QCoreApplication>
+#include <QSettings>
+#include <QMenu>
+#include <QMenuBar>
+#include <QDragEnterEvent>
+#include <QMimeData>
+#include <QUrl>
+#include <QShortcut>
+#include <QKeySequence>
+#include <QMacInstallDialog.h>
+#include <QInputDialog>
+
+#include "QCMake.h"
+#include "QCMakeCacheView.h"
+#include "AddCacheEntry.h"
+#include "FirstConfigure.h"
+#include "cmSystemTools.h"
+#include "cmVersion.h"
+
+QCMakeThread::QCMakeThread(QObject* p)
+ : QThread(p), CMakeInstance(NULL)
+{
+}
+
+QCMake* QCMakeThread::cmakeInstance() const
+{
+ return this->CMakeInstance;
+}
+
+void QCMakeThread::run()
+{
+ this->CMakeInstance = new QCMake;
+ // emit that this cmake thread is ready for use
+ emit this->cmakeInitialized();
+ this->exec();
+ delete this->CMakeInstance;
+ this->CMakeInstance = NULL;
+}
+
+CMakeSetupDialog::CMakeSetupDialog()
+ : ExitAfterGenerate(true), CacheModified(false), ConfigureNeeded(true), CurrentState(Interrupting)
+{
+ QString title = QString(tr("CMake %1"));
+ title = title.arg(cmVersion::GetCMakeVersion());
+ this->setWindowTitle(title);
+
+ // create the GUI
+ QSettings settings;
+ settings.beginGroup("Settings/StartPath");
+ restoreGeometry(settings.value("geometry").toByteArray());
+ restoreState(settings.value("windowState").toByteArray());
+
+ this->AddVariableNames = settings.value("AddVariableNames",
+ QStringList("CMAKE_INSTALL_PREFIX")).toStringList();
+ this->AddVariableTypes = settings.value("AddVariableTypes",
+ QStringList("PATH")).toStringList();
+
+ QWidget* cont = new QWidget(this);
+ this->setupUi(cont);
+ this->Splitter->setStretchFactor(0, 3);
+ this->Splitter->setStretchFactor(1, 1);
+ this->setCentralWidget(cont);
+ this->ProgressBar->reset();
+ this->RemoveEntry->setEnabled(false);
+ this->AddEntry->setEnabled(false);
+
+ QByteArray p = settings.value("SplitterSizes").toByteArray();
+ this->Splitter->restoreState(p);
+
+ bool groupView = settings.value("GroupView", false).toBool();
+ this->setGroupedView(groupView);
+ this->groupedCheck->setCheckState(groupView ? Qt::Checked : Qt::Unchecked);
+
+ bool advancedView = settings.value("AdvancedView", false).toBool();
+ this->setAdvancedView(advancedView);
+ this->advancedCheck->setCheckState(advancedView?Qt::Checked : Qt::Unchecked);
+
+ QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
+ this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
+ QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)),
+ this, SLOT(doReloadCache()));
+ this->DeleteCacheAction = FileMenu->addAction(tr("&Delete Cache"));
+ QObject::connect(this->DeleteCacheAction, SIGNAL(triggered(bool)),
+ this, SLOT(doDeleteCache()));
+ this->ExitAction = FileMenu->addAction(tr("E&xit"));
+ this->ExitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
+ QObject::connect(this->ExitAction, SIGNAL(triggered(bool)),
+ this, SLOT(close()));
+
+ QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
+ this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
+ // prevent merging with Preferences menu item on Mac OS X
+ this->ConfigureAction->setMenuRole(QAction::NoRole);
+ QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)),
+ this, SLOT(doConfigure()));
+ this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
+ QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)),
+ this, SLOT(doGenerate()));
+ QAction* showChangesAction = ToolsMenu->addAction(tr("&Show My Changes"));
+ QObject::connect(showChangesAction, SIGNAL(triggered(bool)),
+ this, SLOT(showUserChanges()));
+#if defined(Q_WS_MAC)
+ this->InstallForCommandLineAction
+ = ToolsMenu->addAction(tr("&Install For Command Line Use"));
+ QObject::connect(this->InstallForCommandLineAction, SIGNAL(triggered(bool)),
+ this, SLOT(doInstallForCommandLine()));
+#endif
+ ToolsMenu->addSeparator();
+ ToolsMenu->addAction(tr("&Find in Output..."),
+ this, SLOT(doOutputFindDialog()),
+ QKeySequence::Find);
+ ToolsMenu->addAction(tr("Find Next"),
+ this, SLOT(doOutputFindNext()),
+ QKeySequence::FindNext);
+ ToolsMenu->addAction(tr("Find Previous"),
+ this, SLOT(doOutputFindPrev()),
+ QKeySequence::FindPrevious);
+ ToolsMenu->addAction(tr("Goto Next Error"),
+ this, SLOT(doOutputErrorNext()),
+ QKeySequence(Qt::Key_F8)); // in Visual Studio
+ new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Period),
+ 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);
+ this->WarnUninitializedAction =
+ OptionsMenu->addAction(tr("&Warn Uninitialized (--warn-uninitialized)"));
+ this->WarnUninitializedAction->setCheckable(true);
+ this->WarnUnusedAction =
+ OptionsMenu->addAction(tr("&Warn Unused (--warn-unused-vars)"));
+ this->WarnUnusedAction->setCheckable(true);
+
+ QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output"));
+ debugAction->setCheckable(true);
+ QObject::connect(debugAction, SIGNAL(toggled(bool)),
+ this, SLOT(setDebugOutput(bool)));
+
+ OptionsMenu->addSeparator();
+ QAction* expandAction = OptionsMenu->addAction(tr("&Expand Grouped Entries"));
+ QObject::connect(expandAction, SIGNAL(triggered(bool)),
+ this->CacheValues, SLOT(expandAll()));
+ QAction* collapseAction = OptionsMenu->addAction(tr("&Collapse Grouped Entries"));
+ QObject::connect(collapseAction, SIGNAL(triggered(bool)),
+ this->CacheValues, SLOT(collapseAll()));
+
+ QMenu* HelpMenu = this->menuBar()->addMenu(tr("&Help"));
+ QAction* a = HelpMenu->addAction(tr("About"));
+ QObject::connect(a, SIGNAL(triggered(bool)),
+ this, SLOT(doAbout()));
+ a = HelpMenu->addAction(tr("Help"));
+ QObject::connect(a, SIGNAL(triggered(bool)),
+ this, SLOT(doHelp()));
+
+ this->setAcceptDrops(true);
+
+ // get the saved binary directories
+ QStringList buildPaths = this->loadBuildPaths();
+ this->BinaryDirectory->addItems(buildPaths);
+
+ this->BinaryDirectory->setCompleter(new QCMakeFileCompleter(this, true));
+ this->SourceDirectory->setCompleter(new QCMakeFileCompleter(this, true));
+
+ // fixed pitch font in output window
+ QFont outputFont("Courier");
+ this->Output->setFont(outputFont);
+ this->ErrorFormat.setForeground(QBrush(Qt::red));
+
+ this->Output->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(this->Output, SIGNAL(customContextMenuRequested(const QPoint&)),
+ this, SLOT(doOutputContextMenu(const QPoint &)));
+
+ // start the cmake worker thread
+ this->CMakeThread = new QCMakeThread(this);
+ QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()),
+ this, SLOT(initialize()), Qt::QueuedConnection);
+ this->CMakeThread->start();
+
+ this->enterState(ReadyConfigure);
+
+ ProgressOffset = 0.0;
+ ProgressFactor = 1.0;
+}
+
+void CMakeSetupDialog::initialize()
+{
+ // now the cmake worker thread is running, lets make our connections to it
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ SIGNAL(propertiesChanged(const QCMakePropertyList&)),
+ this->CacheValues->cacheModel(),
+ SLOT(setProperties(const QCMakePropertyList&)));
+
+ QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)),
+ this, SLOT(doConfigure()));
+
+ QObject::connect(this->CMakeThread->cmakeInstance(), SIGNAL(configureDone(int)),
+ this, SLOT(exitLoop(int)));
+ QObject::connect(this->CMakeThread->cmakeInstance(), SIGNAL(generateDone(int)),
+ this, SLOT(exitLoop(int)));
+
+ QObject::connect(this->GenerateButton, SIGNAL(clicked(bool)),
+ this, SLOT(doGenerate()));
+
+ QObject::connect(this->BrowseSourceDirectoryButton, SIGNAL(clicked(bool)),
+ this, SLOT(doSourceBrowse()));
+ QObject::connect(this->BrowseBinaryDirectoryButton, SIGNAL(clicked(bool)),
+ this, SLOT(doBinaryBrowse()));
+
+ QObject::connect(this->BinaryDirectory, SIGNAL(editTextChanged(QString)),
+ this, SLOT(onBinaryDirectoryChanged(QString)));
+ QObject::connect(this->SourceDirectory, SIGNAL(textChanged(QString)),
+ this, SLOT(onSourceDirectoryChanged(QString)));
+
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ SIGNAL(sourceDirChanged(QString)),
+ this, SLOT(updateSourceDirectory(QString)));
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ SIGNAL(binaryDirChanged(QString)),
+ this, SLOT(updateBinaryDirectory(QString)));
+
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ SIGNAL(progressChanged(QString, float)),
+ this, SLOT(showProgress(QString,float)));
+
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ SIGNAL(errorMessage(QString)),
+ this, SLOT(error(QString)));
+
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ SIGNAL(outputMessage(QString)),
+ this, SLOT(message(QString)));
+
+ QObject::connect(this->groupedCheck, SIGNAL(toggled(bool)),
+ this, SLOT(setGroupedView(bool)));
+ QObject::connect(this->advancedCheck, SIGNAL(toggled(bool)),
+ this, SLOT(setAdvancedView(bool)));
+ QObject::connect(this->Search, SIGNAL(textChanged(QString)),
+ this, SLOT(setSearchFilter(QString)));
+
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ SIGNAL(generatorChanged(QString)),
+ this, SLOT(updateGeneratorLabel(QString)));
+ this->updateGeneratorLabel(QString());
+
+ QObject::connect(this->CacheValues->cacheModel(),
+ SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+ this, SLOT(setCacheModified()));
+
+ QObject::connect(this->CacheValues->selectionModel(),
+ SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
+ this, SLOT(selectionChanged()));
+ QObject::connect(this->RemoveEntry, SIGNAL(clicked(bool)),
+ this, SLOT(removeSelectedCacheEntries()));
+ 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)));
+ QObject::connect(this->WarnUnusedAction, SIGNAL(triggered(bool)),
+ this->CMakeThread->cmakeInstance(),
+ SLOT(setWarnUnusedMode(bool)));
+
+ if(!this->SourceDirectory->text().isEmpty() ||
+ !this->BinaryDirectory->lineEdit()->text().isEmpty())
+ {
+ this->onSourceDirectoryChanged(this->SourceDirectory->text());
+ this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
+ }
+ else
+ {
+ this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
+ }
+}
+
+CMakeSetupDialog::~CMakeSetupDialog()
+{
+ QSettings settings;
+ settings.beginGroup("Settings/StartPath");
+ settings.setValue("windowState", QVariant(saveState()));
+ settings.setValue("geometry", QVariant(saveGeometry()));
+ settings.setValue("SplitterSizes", this->Splitter->saveState());
+
+ // wait for thread to stop
+ this->CMakeThread->quit();
+ this->CMakeThread->wait();
+}
+
+bool CMakeSetupDialog::prepareConfigure()
+{
+ // make sure build directory exists
+ QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
+ QDir dir(bindir);
+ if(!dir.exists())
+ {
+ QString msg = tr("Build directory does not exist, "
+ "should I create it?\n\n"
+ "Directory: ");
+ msg += bindir;
+ QString title = tr("Create Directory");
+ QMessageBox::StandardButton btn;
+ btn = QMessageBox::information(this, title, msg,
+ QMessageBox::Yes | QMessageBox::No);
+ if(btn == QMessageBox::No)
+ {
+ return false;
+ }
+ if(!dir.mkpath("."))
+ {
+ QMessageBox::information(this, tr("Create Directory Failed"),
+ QString(tr("Failed to create directory %1")).arg(dir.path()),
+ QMessageBox::Ok);
+
+ return false;
+ }
+ }
+
+ // if no generator, prompt for it and other setup stuff
+ if(this->CMakeThread->cmakeInstance()->generator().isEmpty())
+ {
+ if(!this->setupFirstConfigure())
+ {
+ return false;
+ }
+ }
+
+ // remember path
+ this->addBinaryPath(dir.absolutePath());
+
+ return true;
+}
+
+void CMakeSetupDialog::exitLoop(int err)
+{
+ this->LocalLoop.exit(err);
+}
+
+void CMakeSetupDialog::doConfigure()
+{
+ if(this->CurrentState == Configuring)
+ {
+ // stop configure
+ doInterrupt();
+ return;
+ }
+
+ if(!prepareConfigure())
+ {
+ return;
+ }
+
+ this->enterState(Configuring);
+
+ bool ret = doConfigureInternal();
+
+ if(ret)
+ {
+ this->ConfigureNeeded = false;
+ }
+
+ if(ret && !this->CacheValues->cacheModel()->newPropertyCount())
+ {
+ this->enterState(ReadyGenerate);
+ }
+ else
+ {
+ this->enterState(ReadyConfigure);
+ this->CacheValues->scrollToTop();
+ }
+ this->ProgressBar->reset();
+}
+
+bool CMakeSetupDialog::doConfigureInternal()
+{
+ this->Output->clear();
+ this->CacheValues->selectionModel()->clear();
+
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
+ "setProperties", Qt::QueuedConnection,
+ Q_ARG(QCMakePropertyList,
+ this->CacheValues->cacheModel()->properties()));
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
+ "configure", Qt::QueuedConnection);
+
+ int err = this->LocalLoop.exec();
+
+ if(err != 0)
+ {
+ QMessageBox::critical(this, tr("Error"),
+ tr("Error in configuration process, project files may be invalid"),
+ QMessageBox::Ok);
+ }
+
+ return 0 == err;
+}
+
+void CMakeSetupDialog::doInstallForCommandLine()
+{
+ QMacInstallDialog setupdialog(0);
+ setupdialog.exec();
+}
+
+bool CMakeSetupDialog::doGenerateInternal()
+{
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
+ "generate", Qt::QueuedConnection);
+
+ int err = this->LocalLoop.exec();
+
+ if(err != 0)
+ {
+ QMessageBox::critical(this, tr("Error"),
+ tr("Error in generation process, project files may be invalid"),
+ QMessageBox::Ok);
+ }
+
+ return 0 == err;
+}
+
+void CMakeSetupDialog::doGenerate()
+{
+ if(this->CurrentState == Generating)
+ {
+ // stop generate
+ doInterrupt();
+ return;
+ }
+
+ // see if we need to configure
+ // we'll need to configure if:
+ // the configure step hasn't been done yet
+ // generate was the last step done
+ if(this->ConfigureNeeded)
+ {
+ if(!prepareConfigure())
+ {
+ return;
+ }
+ }
+
+ this->enterState(Generating);
+
+ bool config_passed = true;
+ if(this->ConfigureNeeded)
+ {
+ this->CacheValues->cacheModel()->setShowNewProperties(false);
+ this->ProgressFactor = 0.5;
+ config_passed = doConfigureInternal();
+ this->ProgressOffset = 0.5;
+ }
+
+ if(config_passed)
+ {
+ doGenerateInternal();
+ }
+
+ this->ProgressOffset = 0.0;
+ this->ProgressFactor = 1.0;
+ this->CacheValues->cacheModel()->setShowNewProperties(true);
+
+ this->enterState(ReadyConfigure);
+ this->ProgressBar->reset();
+
+ this->ConfigureNeeded = true;
+}
+
+void CMakeSetupDialog::closeEvent(QCloseEvent* e)
+{
+ // prompt for close if there are unsaved changes, and we're not busy
+ if(this->CacheModified)
+ {
+ QString msg = tr("You have changed options but not rebuilt, "
+ "are you sure you want to exit?");
+ QString title = tr("Confirm Exit");
+ QMessageBox::StandardButton btn;
+ btn = QMessageBox::critical(this, title, msg,
+ QMessageBox::Yes | QMessageBox::No);
+ if(btn == QMessageBox::No)
+ {
+ e->ignore();
+ }
+ }
+
+ // don't close if we're busy, unless the user really wants to
+ if(this->CurrentState == Configuring)
+ {
+ QString msg = tr("You are in the middle of a Configure.\n"
+ "If you Exit now the configure information will be lost.\n"
+ "Are you sure you want to Exit?");
+ QString title = tr("Confirm Exit");
+ QMessageBox::StandardButton btn;
+ btn = QMessageBox::critical(this, title, msg,
+ QMessageBox::Yes | QMessageBox::No);
+ if(btn == QMessageBox::No)
+ {
+ e->ignore();
+ }
+ else
+ {
+ this->doInterrupt();
+ }
+ }
+
+ // let the generate finish
+ if(this->CurrentState == Generating)
+ {
+ e->ignore();
+ }
+}
+
+void CMakeSetupDialog::doHelp()
+{
+ QString msg = tr("CMake is used to configure and generate build files for "
+ "software projects. The basic steps for configuring a project are as "
+ "follows:\r\n\r\n1. Select the source directory for the project. This should "
+ "contain the CMakeLists.txt files for the project.\r\n\r\n2. Select the build "
+ "directory for the project. This is the directory where the project will be "
+ "built. It can be the same or a different directory than the source "
+ "directory. For easy clean up, a separate build directory is recommended. "
+ "CMake will create the directory if it does not exist.\r\n\r\n3. Once the "
+ "source and binary directories are selected, it is time to press the "
+ "Configure button. This will cause CMake to read all of the input files and "
+ "discover all the variables used by the project. The first time a variable "
+ "is displayed it will be in Red. Users should inspect red variables making "
+ "sure the values are correct. For some projects the Configure process can "
+ "be iterative, so continue to press the Configure button until there are no "
+ "longer red entries.\r\n\r\n4. Once there are no longer red entries, you "
+ "should click the Generate button. This will write the build files to the build "
+ "directory.");
+
+ QDialog dialog;
+ QFontMetrics met(this->font());
+ int msgWidth = met.width(msg);
+ dialog.setMinimumSize(msgWidth/15,20);
+ dialog.setWindowTitle(tr("Help"));
+ QVBoxLayout* l = new QVBoxLayout(&dialog);
+ QLabel* lab = new QLabel(&dialog);
+ lab->setText(msg);
+ lab->setWordWrap(true);
+ QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
+ Qt::Horizontal, &dialog);
+ QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
+ l->addWidget(lab);
+ l->addWidget(btns);
+ dialog.exec();
+}
+
+void CMakeSetupDialog::doInterrupt()
+{
+ this->enterState(Interrupting);
+ this->CMakeThread->cmakeInstance()->interrupt();
+}
+
+void CMakeSetupDialog::doSourceBrowse()
+{
+ QString dir = QFileDialog::getExistingDirectory(this,
+ tr("Enter Path to Source"), this->SourceDirectory->text(),
+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+ if(!dir.isEmpty())
+ {
+ this->setSourceDirectory(dir);
+ }
+}
+
+void CMakeSetupDialog::updateSourceDirectory(const QString& dir)
+{
+ if(this->SourceDirectory->text() != dir)
+ {
+ this->SourceDirectory->blockSignals(true);
+ this->SourceDirectory->setText(dir);
+ this->SourceDirectory->blockSignals(false);
+ }
+}
+
+void CMakeSetupDialog::updateBinaryDirectory(const QString& dir)
+{
+ if(this->BinaryDirectory->currentText() != dir)
+ {
+ this->BinaryDirectory->blockSignals(true);
+ this->BinaryDirectory->setEditText(dir);
+ this->BinaryDirectory->blockSignals(false);
+ }
+}
+
+void CMakeSetupDialog::doBinaryBrowse()
+{
+ QString dir = QFileDialog::getExistingDirectory(this,
+ tr("Enter Path to Build"), this->BinaryDirectory->currentText(),
+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+ if(!dir.isEmpty() && dir != this->BinaryDirectory->currentText())
+ {
+ this->setBinaryDirectory(dir);
+ }
+}
+
+void CMakeSetupDialog::setBinaryDirectory(const QString& dir)
+{
+ this->BinaryDirectory->setEditText(dir);
+}
+
+void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
+{
+ this->Output->clear();
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
+ "setSourceDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
+}
+
+void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
+{
+ QString title = QString(tr("CMake %1 - %2"));
+ title = title.arg(cmVersion::GetCMakeVersion());
+ title = title.arg(dir);
+ this->setWindowTitle(title);
+
+ this->CacheModified = false;
+ this->CacheValues->cacheModel()->clear();
+ qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())->clearChanges();
+ this->Output->clear();
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
+ "setBinaryDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
+}
+
+void CMakeSetupDialog::setSourceDirectory(const QString& dir)
+{
+ this->SourceDirectory->setText(dir);
+}
+
+void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
+{
+ percent = (percent * ProgressFactor) + ProgressOffset;
+ this->ProgressBar->setValue(qRound(percent * 100));
+}
+
+void CMakeSetupDialog::error(const QString& msg)
+{
+ this->Output->setCurrentCharFormat(this->ErrorFormat);
+ //QTextEdit will terminate the msg with a ParagraphSeparator, but it also replaces
+ //all newlines with ParagraphSeparators. By replacing the newlines by ourself, one
+ //error msg will be one paragraph.
+ QString paragraph(msg);
+ paragraph.replace(QLatin1Char('\n'), QChar::LineSeparator);
+ this->Output->append(paragraph);
+
+}
+
+void CMakeSetupDialog::message(const QString& msg)
+{
+ this->Output->setCurrentCharFormat(this->MessageFormat);
+ this->Output->append(msg);
+}
+
+void CMakeSetupDialog::setEnabledState(bool enabled)
+{
+ // disable parts of the GUI during configure/generate
+ this->CacheValues->cacheModel()->setEditEnabled(enabled);
+ this->SourceDirectory->setEnabled(enabled);
+ this->BrowseSourceDirectoryButton->setEnabled(enabled);
+ this->BinaryDirectory->setEnabled(enabled);
+ this->BrowseBinaryDirectoryButton->setEnabled(enabled);
+ this->ReloadCacheAction->setEnabled(enabled);
+ this->DeleteCacheAction->setEnabled(enabled);
+ this->ExitAction->setEnabled(enabled);
+ this->ConfigureAction->setEnabled(enabled);
+ this->AddEntry->setEnabled(enabled);
+ this->RemoveEntry->setEnabled(false); // let selection re-enable it
+}
+
+bool CMakeSetupDialog::setupFirstConfigure()
+{
+ FirstConfigure dialog;
+
+ // initialize dialog and restore saved settings
+
+ // add generators
+ dialog.setGenerators(this->CMakeThread->cmakeInstance()->availableGenerators());
+
+ // restore from settings
+ dialog.loadFromSettings();
+
+ if(dialog.exec() == QDialog::Accepted)
+ {
+ dialog.saveToSettings();
+ this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator());
+
+ QCMakeCacheModel* m = this->CacheValues->cacheModel();
+
+ if(dialog.compilerSetup())
+ {
+ QString fortranCompiler = dialog.getFortranCompiler();
+ if(!fortranCompiler.isEmpty())
+ {
+ m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
+ "Fortran compiler.", fortranCompiler, false);
+ }
+ QString cxxCompiler = dialog.getCXXCompiler();
+ if(!cxxCompiler.isEmpty())
+ {
+ m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
+ "CXX compiler.", cxxCompiler, false);
+ }
+
+ QString cCompiler = dialog.getCCompiler();
+ if(!cCompiler.isEmpty())
+ {
+ m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
+ "C compiler.", cCompiler, false);
+ }
+ }
+ else if(dialog.crossCompilerSetup())
+ {
+ QString fortranCompiler = dialog.getFortranCompiler();
+ if(!fortranCompiler.isEmpty())
+ {
+ m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
+ "Fortran compiler.", fortranCompiler, false);
+ }
+
+ QString mode = dialog.getCrossIncludeMode();
+ m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE",
+ tr("CMake Find Include Mode"), mode, false);
+ mode = dialog.getCrossLibraryMode();
+ m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
+ tr("CMake Find Library Mode"), mode, false);
+ mode = dialog.getCrossProgramMode();
+ m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
+ tr("CMake Find Program Mode"), mode, false);
+
+ QString rootPath = dialog.getCrossRoot();
+ m->insertProperty(QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH",
+ tr("CMake Find Root Path"), rootPath, false);
+
+ QString systemName = dialog.getSystemName();
+ m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME",
+ tr("CMake System Name"), systemName, false);
+ QString systemVersion = dialog.getSystemVersion();
+ m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_VERSION",
+ tr("CMake System Version"), systemVersion, false);
+ QString cxxCompiler = dialog.getCXXCompiler();
+ m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
+ tr("CXX compiler."), cxxCompiler, false);
+ QString cCompiler = dialog.getCCompiler();
+ m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
+ tr("C compiler."), cCompiler, false);
+ }
+ else if(dialog.crossCompilerToolChainFile())
+ {
+ QString toolchainFile = dialog.getCrossCompilerToolChainFile();
+ m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE",
+ tr("Cross Compile ToolChain File"), toolchainFile, false);
+ }
+ return true;
+ }
+
+ return false;
+}
+
+void CMakeSetupDialog::updateGeneratorLabel(const QString& gen)
+{
+ QString str = tr("Current Generator: ");
+ if(gen.isEmpty())
+ {
+ str += tr("None");
+ }
+ else
+ {
+ str += gen;
+ }
+ this->Generator->setText(str);
+}
+
+void CMakeSetupDialog::doReloadCache()
+{
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
+ "reloadCache", Qt::QueuedConnection);
+}
+
+void CMakeSetupDialog::doDeleteCache()
+{
+ QString title = tr("Delete Cache");
+ QString msg = tr("Are you sure you want to delete the cache?");
+ QMessageBox::StandardButton btn;
+ btn = QMessageBox::information(this, title, msg,
+ QMessageBox::Yes | QMessageBox::No);
+ if(btn == QMessageBox::No)
+ {
+ return;
+ }
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
+ "deleteCache", Qt::QueuedConnection);
+}
+
+void CMakeSetupDialog::doAbout()
+{
+ QString msg = tr(
+ "CMake %1 (cmake.org).\n"
+ "CMake suite maintained and supported by Kitware (kitware.com/cmake).\n"
+ "Distributed under terms of the BSD 3-Clause License.\n"
+ "\n"
+ "CMake GUI maintained by csimsoft,\n"
+ "built using Qt %2 (qt-project.org).\n"
+#ifdef CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL
+ "\n"
+ "The Qt Toolkit is Copyright (C) Digia Plc and/or its subsidiary(-ies).\n"
+ "Qt is licensed under terms of the GNU LGPLv2.1, available at:\n"
+ " \"%3\""
+#endif
+ );
+ msg = msg.arg(cmVersion::GetCMakeVersion());
+ msg = msg.arg(qVersion());
+#ifdef CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL
+ std::string lgpl = cmSystemTools::GetCMakeRoot()+"/Licenses/LGPLv2.1.txt";
+ msg = msg.arg(lgpl.c_str());
+#endif
+
+ QDialog dialog;
+ dialog.setWindowTitle(tr("About"));
+ QVBoxLayout* l = new QVBoxLayout(&dialog);
+ QLabel* lab = new QLabel(&dialog);
+ l->addWidget(lab);
+ lab->setText(msg);
+ lab->setWordWrap(true);
+ QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
+ Qt::Horizontal, &dialog);
+ QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
+ l->addWidget(btns);
+ dialog.exec();
+}
+
+void CMakeSetupDialog::setExitAfterGenerate(bool b)
+{
+ this->ExitAfterGenerate = b;
+}
+
+void CMakeSetupDialog::addBinaryPath(const QString& path)
+{
+ QString cleanpath = QDir::cleanPath(path);
+
+ // update UI
+ this->BinaryDirectory->blockSignals(true);
+ int idx = this->BinaryDirectory->findText(cleanpath);
+ if(idx != -1)
+ {
+ this->BinaryDirectory->removeItem(idx);
+ }
+ this->BinaryDirectory->insertItem(0, cleanpath);
+ this->BinaryDirectory->setCurrentIndex(0);
+ this->BinaryDirectory->blockSignals(false);
+
+ // save to registry
+ QStringList buildPaths = this->loadBuildPaths();
+ buildPaths.removeAll(cleanpath);
+ buildPaths.prepend(cleanpath);
+ this->saveBuildPaths(buildPaths);
+}
+
+void CMakeSetupDialog::dragEnterEvent(QDragEnterEvent* e)
+{
+ if(!(this->CurrentState == ReadyConfigure ||
+ this->CurrentState == ReadyGenerate))
+ {
+ e->ignore();
+ return;
+ }
+
+ const QMimeData* dat = e->mimeData();
+ QList<QUrl> urls = dat->urls();
+ QString file = urls.count() ? urls[0].toLocalFile() : QString();
+ if(!file.isEmpty() &&
+ (file.endsWith("CMakeCache.txt", Qt::CaseInsensitive) ||
+ file.endsWith("CMakeLists.txt", Qt::CaseInsensitive) ) )
+ {
+ e->accept();
+ }
+ else
+ {
+ e->ignore();
+ }
+}
+
+void CMakeSetupDialog::dropEvent(QDropEvent* e)
+{
+ if(!(this->CurrentState == ReadyConfigure ||
+ this->CurrentState == ReadyGenerate))
+ {
+ return;
+ }
+
+ const QMimeData* dat = e->mimeData();
+ QList<QUrl> urls = dat->urls();
+ QString file = urls.count() ? urls[0].toLocalFile() : QString();
+ if(file.endsWith("CMakeCache.txt", Qt::CaseInsensitive))
+ {
+ QFileInfo info(file);
+ if(this->CMakeThread->cmakeInstance()->binaryDirectory() != info.absolutePath())
+ {
+ this->setBinaryDirectory(info.absolutePath());
+ }
+ }
+ else if(file.endsWith("CMakeLists.txt", Qt::CaseInsensitive))
+ {
+ QFileInfo info(file);
+ if(this->CMakeThread->cmakeInstance()->binaryDirectory() != info.absolutePath())
+ {
+ this->setSourceDirectory(info.absolutePath());
+ this->setBinaryDirectory(info.absolutePath());
+ }
+ }
+}
+
+QStringList CMakeSetupDialog::loadBuildPaths()
+{
+ QSettings settings;
+ settings.beginGroup("Settings/StartPath");
+
+ QStringList buildPaths;
+ for(int i=0; i<10; i++)
+ {
+ QString p = settings.value(QString("WhereBuild%1").arg(i)).toString();
+ if(!p.isEmpty())
+ {
+ buildPaths.append(p);
+ }
+ }
+ return buildPaths;
+}
+
+void CMakeSetupDialog::saveBuildPaths(const QStringList& paths)
+{
+ QSettings settings;
+ settings.beginGroup("Settings/StartPath");
+
+ int num = paths.count();
+ if(num > 10)
+ {
+ num = 10;
+ }
+
+ for(int i=0; i<num; i++)
+ {
+ settings.setValue(QString("WhereBuild%1").arg(i), paths[i]);
+ }
+}
+
+void CMakeSetupDialog::setCacheModified()
+{
+ this->CacheModified = true;
+ this->ConfigureNeeded = true;
+ this->enterState(ReadyConfigure);
+}
+
+void CMakeSetupDialog::removeSelectedCacheEntries()
+{
+ QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
+ QList<QPersistentModelIndex> pidxs;
+ foreach(QModelIndex i, idxs)
+ {
+ pidxs.append(i);
+ }
+ foreach(QPersistentModelIndex pi, pidxs)
+ {
+ this->CacheValues->model()->removeRow(pi.row(), pi.parent());
+ }
+}
+
+void CMakeSetupDialog::selectionChanged()
+{
+ QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
+ if(idxs.count() &&
+ (this->CurrentState == ReadyConfigure ||
+ this->CurrentState == ReadyGenerate) )
+ {
+ this->RemoveEntry->setEnabled(true);
+ }
+ else
+ {
+ this->RemoveEntry->setEnabled(false);
+ }
+}
+
+void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
+{
+ if(s == this->CurrentState)
+ {
+ return;
+ }
+
+ this->CurrentState = s;
+
+ if(s == Interrupting)
+ {
+ this->ConfigureButton->setEnabled(false);
+ this->GenerateButton->setEnabled(false);
+ }
+ else if(s == Configuring)
+ {
+ this->setEnabledState(false);
+ this->GenerateButton->setEnabled(false);
+ this->GenerateAction->setEnabled(false);
+ this->ConfigureButton->setText(tr("&Stop"));
+ }
+ else if(s == Generating)
+ {
+ this->CacheModified = false;
+ this->setEnabledState(false);
+ this->ConfigureButton->setEnabled(false);
+ this->GenerateAction->setEnabled(false);
+ this->GenerateButton->setText(tr("&Stop"));
+ }
+ else if(s == ReadyConfigure)
+ {
+ this->setEnabledState(true);
+ this->GenerateButton->setEnabled(true);
+ this->GenerateAction->setEnabled(true);
+ this->ConfigureButton->setEnabled(true);
+ this->ConfigureButton->setText(tr("&Configure"));
+ this->GenerateButton->setText(tr("&Generate"));
+ }
+ else if(s == ReadyGenerate)
+ {
+ this->setEnabledState(true);
+ this->GenerateButton->setEnabled(true);
+ this->GenerateAction->setEnabled(true);
+ this->ConfigureButton->setEnabled(true);
+ this->ConfigureButton->setText(tr("&Configure"));
+ this->GenerateButton->setText(tr("&Generate"));
+ }
+}
+
+void CMakeSetupDialog::addCacheEntry()
+{
+ QDialog dialog(this);
+ dialog.resize(400, 200);
+ dialog.setWindowTitle(tr("Add Cache Entry"));
+ QVBoxLayout* l = new QVBoxLayout(&dialog);
+ AddCacheEntry* w = new AddCacheEntry(&dialog, this->AddVariableNames,
+ this->AddVariableTypes);
+ QDialogButtonBox* btns = new QDialogButtonBox(
+ QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ Qt::Horizontal, &dialog);
+ QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
+ QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(reject()));
+ l->addWidget(w);
+ l->addStretch();
+ l->addWidget(btns);
+ if(QDialog::Accepted == dialog.exec())
+ {
+ QCMakeCacheModel* m = this->CacheValues->cacheModel();
+ m->insertProperty(w->type(), w->name(), w->description(), w->value(), false);
+
+ // only add variable names to the completion which are new
+ if (!this->AddVariableNames.contains(w->name()))
+ {
+ this->AddVariableNames << w->name();
+ this->AddVariableTypes << w->typeString();
+ // limit to at most 100 completion items
+ if (this->AddVariableNames.size() > 100)
+ {
+ this->AddVariableNames.removeFirst();
+ this->AddVariableTypes.removeFirst();
+ }
+ // make sure CMAKE_INSTALL_PREFIX is always there
+ if (!this->AddVariableNames.contains("CMAKE_INSTALL_PREFIX"))
+ {
+ this->AddVariableNames << "CMAKE_INSTALL_PREFIX";
+ this->AddVariableTypes << "PATH";
+ }
+ QSettings settings;
+ settings.beginGroup("Settings/StartPath");
+ settings.setValue("AddVariableNames", this->AddVariableNames);
+ settings.setValue("AddVariableTypes", this->AddVariableTypes);
+ }
+ }
+}
+
+void CMakeSetupDialog::startSearch()
+{
+ this->Search->setFocus(Qt::OtherFocusReason);
+ this->Search->selectAll();
+}
+
+void CMakeSetupDialog::setDebugOutput(bool flag)
+{
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
+ "setDebugOutput", Qt::QueuedConnection, Q_ARG(bool, flag));
+}
+
+void CMakeSetupDialog::setGroupedView(bool v)
+{
+ this->CacheValues->cacheModel()->setViewType(v ? QCMakeCacheModel::GroupView : QCMakeCacheModel::FlatView);
+ this->CacheValues->setRootIsDecorated(v);
+
+ QSettings settings;
+ settings.beginGroup("Settings/StartPath");
+ settings.setValue("GroupView", v);
+
+}
+
+void CMakeSetupDialog::setAdvancedView(bool v)
+{
+ this->CacheValues->setShowAdvanced(v);
+ QSettings settings;
+ settings.beginGroup("Settings/StartPath");
+ settings.setValue("AdvancedView", v);
+}
+
+void CMakeSetupDialog::showUserChanges()
+{
+ QSet<QCMakeProperty> changes =
+ qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())->changes();
+
+ QDialog dialog(this);
+ dialog.setWindowTitle(tr("My Changes"));
+ dialog.resize(600, 400);
+ QVBoxLayout* l = new QVBoxLayout(&dialog);
+ QTextEdit* textedit = new QTextEdit(&dialog);
+ textedit->setReadOnly(true);
+ l->addWidget(textedit);
+ QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Close,
+ Qt::Horizontal, &dialog);
+ QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(accept()));
+ l->addWidget(btns);
+
+ QString command;
+ QString cache;
+
+ foreach(QCMakeProperty prop, changes)
+ {
+ QString type;
+ switch(prop.Type)
+ {
+ case QCMakeProperty::BOOL:
+ type = "BOOL";
+ break;
+ case QCMakeProperty::PATH:
+ type = "PATH";
+ break;
+ case QCMakeProperty::FILEPATH:
+ type = "FILEPATH";
+ break;
+ case QCMakeProperty::STRING:
+ type = "STRING";
+ break;
+ }
+ QString value;
+ if(prop.Type == QCMakeProperty::BOOL)
+ {
+ value = prop.Value.toBool() ? "1" : "0";
+ }
+ else
+ {
+ value = prop.Value.toString();
+ }
+
+ QString line("%1:%2=");
+ line = line.arg(prop.Key);
+ line = line.arg(type);
+
+ command += QString("-D%1\"%2\" ").arg(line).arg(value);
+ cache += QString("%1%2\n").arg(line).arg(value);
+ }
+
+ textedit->append(tr("Commandline options:"));
+ textedit->append(command);
+ textedit->append("\n");
+ textedit->append(tr("Cache file:"));
+ textedit->append(cache);
+
+ dialog.exec();
+}
+
+void CMakeSetupDialog::setSearchFilter(const QString& str)
+{
+ this->CacheValues->selectionModel()->clear();
+ this->CacheValues->setSearchFilter(str);
+}
+
+void CMakeSetupDialog::doOutputContextMenu(const QPoint &pt)
+{
+ QMenu *menu = this->Output->createStandardContextMenu();
+
+ menu->addSeparator();
+ menu->addAction(tr("Find..."),
+ this, SLOT(doOutputFindDialog()), QKeySequence::Find);
+ menu->addAction(tr("Find Next"),
+ this, SLOT(doOutputFindNext()), QKeySequence::FindNext);
+ menu->addAction(tr("Find Previous"),
+ this, SLOT(doOutputFindPrev()), QKeySequence::FindPrevious);
+ menu->addSeparator();
+ menu->addAction(tr("Goto Next Error"),
+ this, SLOT(doOutputErrorNext()), QKeySequence(Qt::Key_F8));
+
+ menu->exec(this->Output->mapToGlobal(pt));
+ delete menu;
+}
+
+void CMakeSetupDialog::doOutputFindDialog()
+{
+ QStringList strings(this->FindHistory);
+
+ QString selection = this->Output->textCursor().selectedText();
+ if (!selection.isEmpty() &&
+ !selection.contains(QChar::ParagraphSeparator) &&
+ !selection.contains(QChar::LineSeparator))
+ {
+ strings.push_front(selection);
+ }
+
+ bool ok;
+ QString search = QInputDialog::getItem(this, tr("Find in Output"),
+ tr("Find:"), strings, 0, true, &ok);
+ if (ok && !search.isEmpty())
+ {
+ if (!this->FindHistory.contains(search))
+ {
+ this->FindHistory.push_front(search);
+ }
+ doOutputFindNext();
+ }
+}
+
+void CMakeSetupDialog::doOutputFindPrev()
+{
+ doOutputFindNext(false);
+}
+
+void CMakeSetupDialog::doOutputFindNext(bool directionForward)
+{
+ if (this->FindHistory.isEmpty())
+ {
+ doOutputFindDialog(); //will re-call this function again
+ return;
+ }
+
+ QString search = this->FindHistory.front();
+
+ QTextCursor textCursor = this->Output->textCursor();
+ QTextDocument* document = this->Output->document();
+ QTextDocument::FindFlags flags;
+ if (!directionForward)
+ {
+ flags |= QTextDocument::FindBackward;
+ }
+
+ textCursor = document->find(search, textCursor, flags);
+
+ if (textCursor.isNull())
+ {
+ // first search found nothing, wrap around and search again
+ textCursor = this->Output->textCursor();
+ textCursor.movePosition(directionForward ? QTextCursor::Start
+ : QTextCursor::End);
+ textCursor = document->find(search, textCursor, flags);
+ }
+
+ if (textCursor.hasSelection())
+ {
+ this->Output->setTextCursor(textCursor);
+ }
+}
+
+void CMakeSetupDialog::doOutputErrorNext()
+{
+ QTextCursor textCursor = this->Output->textCursor();
+ bool atEnd = false;
+
+ // move cursor out of current error-block
+ if (textCursor.blockCharFormat() == this->ErrorFormat)
+ {
+ atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
+ }
+
+ // move cursor to next error-block
+ while (textCursor.blockCharFormat() != this->ErrorFormat && !atEnd)
+ {
+ atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
+ }
+
+ if (atEnd)
+ {
+ // first search found nothing, wrap around and search again
+ atEnd = !textCursor.movePosition(QTextCursor::Start);
+
+ // move cursor to next error-block
+ while (textCursor.blockCharFormat() != this->ErrorFormat && !atEnd)
+ {
+ atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
+ }
+ }
+
+ if (!atEnd)
+ {
+ textCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
+
+ QTextCharFormat selectionFormat;
+ selectionFormat.setBackground(Qt::yellow);
+ QTextEdit::ExtraSelection extraSelection = {textCursor, selectionFormat};
+ this->Output->setExtraSelections(QList<QTextEdit::ExtraSelection>()
+ << extraSelection);
+
+ // make the whole error-block visible
+ this->Output->setTextCursor(textCursor);
+
+ // remove the selection to see the extraSelection
+ textCursor.setPosition(textCursor.anchor());
+ this->Output->setTextCursor(textCursor);
+ }
+}
diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h
new file mode 100644
index 0000000000..1b26c648c7
--- /dev/null
+++ b/Source/QtDialog/CMakeSetupDialog.h
@@ -0,0 +1,139 @@
+/*============================================================================
+ 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 CMakeSetupDialog_h
+#define CMakeSetupDialog_h
+
+#include "QCMake.h"
+#include <QMainWindow>
+#include <QThread>
+#include <QEventLoop>
+#include "ui_CMakeSetupDialog.h"
+
+class QCMakeThread;
+class CMakeCacheModel;
+class QProgressBar;
+class QToolButton;
+
+/// Qt user interface for CMake
+class CMakeSetupDialog : public QMainWindow, public Ui::CMakeSetupDialog
+{
+ Q_OBJECT
+public:
+ CMakeSetupDialog();
+ ~CMakeSetupDialog();
+
+public slots:
+ void setBinaryDirectory(const QString& dir);
+ void setSourceDirectory(const QString& dir);
+
+protected slots:
+ void initialize();
+ void doConfigure();
+ void doGenerate();
+ void doInstallForCommandLine();
+ void doHelp();
+ void doAbout();
+ void doInterrupt();
+ void error(const QString& message);
+ void message(const QString& message);
+
+ void doSourceBrowse();
+ void doBinaryBrowse();
+ void doReloadCache();
+ void doDeleteCache();
+ void updateSourceDirectory(const QString& dir);
+ void updateBinaryDirectory(const QString& dir);
+ void showProgress(const QString& msg, float percent);
+ void setEnabledState(bool);
+ bool setupFirstConfigure();
+ void updateGeneratorLabel(const QString& gen);
+ void setExitAfterGenerate(bool);
+ void addBinaryPath(const QString&);
+ QStringList loadBuildPaths();
+ void saveBuildPaths(const QStringList&);
+ void onBinaryDirectoryChanged(const QString& dir);
+ void onSourceDirectoryChanged(const QString& dir);
+ void setCacheModified();
+ void removeSelectedCacheEntries();
+ void selectionChanged();
+ void addCacheEntry();
+ void startSearch();
+ void setDebugOutput(bool);
+ void setAdvancedView(bool);
+ void setGroupedView(bool);
+ void showUserChanges();
+ void setSearchFilter(const QString& str);
+ bool prepareConfigure();
+ bool doConfigureInternal();
+ bool doGenerateInternal();
+ void exitLoop(int);
+ void doOutputContextMenu(const QPoint &);
+ void doOutputFindDialog();
+ void doOutputFindNext(bool directionForward = true);
+ void doOutputFindPrev();
+ void doOutputErrorNext();
+
+protected:
+
+ enum State { Interrupting, ReadyConfigure, ReadyGenerate, Configuring, Generating };
+ void enterState(State s);
+
+ void closeEvent(QCloseEvent*);
+ void dragEnterEvent(QDragEnterEvent*);
+ void dropEvent(QDropEvent*);
+
+ QCMakeThread* CMakeThread;
+ bool ExitAfterGenerate;
+ bool CacheModified;
+ bool ConfigureNeeded;
+ QAction* ReloadCacheAction;
+ QAction* DeleteCacheAction;
+ QAction* ExitAction;
+ QAction* ConfigureAction;
+ QAction* GenerateAction;
+ QAction* SuppressDevWarningsAction;
+ QAction* WarnUninitializedAction;
+ QAction* WarnUnusedAction;
+ QAction* InstallForCommandLineAction;
+ State CurrentState;
+
+ QTextCharFormat ErrorFormat;
+ QTextCharFormat MessageFormat;
+
+ QStringList AddVariableNames;
+ QStringList AddVariableTypes;
+ QStringList FindHistory;
+
+ QEventLoop LocalLoop;
+
+ float ProgressOffset;
+ float ProgressFactor;
+};
+
+// QCMake instance on a thread
+class QCMakeThread : public QThread
+{
+ Q_OBJECT
+public:
+ QCMakeThread(QObject* p);
+ QCMake* cmakeInstance() const;
+
+signals:
+ void cmakeInitialized();
+
+protected:
+ virtual void run();
+ QCMake* CMakeInstance;
+};
+
+#endif // CMakeSetupDialog_h
diff --git a/Source/QtDialog/CMakeSetupDialog.ui b/Source/QtDialog/CMakeSetupDialog.ui
new file mode 100644
index 0000000000..98da249d5e
--- /dev/null
+++ b/Source/QtDialog/CMakeSetupDialog.ui
@@ -0,0 +1,313 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CMakeSetupDialog</class>
+ <widget class="QWidget" name="CMakeSetupDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>707</width>
+ <height>582</height>
+ </rect>
+ </property>
+ <layout class="QGridLayout">
+ <property name="margin">
+ <number>9</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <item row="0" column="0">
+ <layout class="QGridLayout">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Where is the source code:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="SourceDirectory"/>
+ </item>
+ <item row="0" column="2">
+ <widget class="QPushButton" name="BrowseSourceDirectoryButton">
+ <property name="text">
+ <string>Browse &amp;Source...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Where to build the binaries:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="BinaryDirectory">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Ignored" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QPushButton" name="BrowseBinaryDirectoryButton">
+ <property name="text">
+ <string>Browse &amp;Build...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0">
+ <widget class="QSplitter" name="Splitter">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QFrame" name="frame">
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label_4">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>S&amp;earch:</string>
+ </property>
+ <property name="buddy">
+ <cstring>Search</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="Search">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Minimum</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>23</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="groupedCheck">
+ <property name="text">
+ <string>Grouped</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="advancedCheck">
+ <property name="text">
+ <string>Advanced</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="AddEntry">
+ <property name="toolTip">
+ <string>Add New Entry</string>
+ </property>
+ <property name="text">
+ <string>&amp;Add Entry</string>
+ </property>
+ <property name="icon">
+ <iconset resource="CMakeSetup.qrc">
+ <normaloff>:/Icons/Plus16.png</normaloff>:/Icons/Plus16.png</iconset>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="RemoveEntry">
+ <property name="toolTip">
+ <string>Remove Selected Entries</string>
+ </property>
+ <property name="text">
+ <string>&amp;Remove Entry</string>
+ </property>
+ <property name="icon">
+ <iconset resource="CMakeSetup.qrc">
+ <normaloff>:/Icons/Delete16.png</normaloff>:/Icons/Delete16.png</iconset>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCMakeCacheView" name="CacheValues">
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Press Configure to update and display new values in red, then press Generate to generate selected build files.</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QPushButton" name="ConfigureButton">
+ <property name="text">
+ <string>&amp;Configure</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="GenerateButton">
+ <property name="text">
+ <string>&amp;Generate</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="Generator">
+ <property name="text">
+ <string>Current Generator:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>121</width>
+ <height>27</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="ProgressBar">
+ <property name="minimum">
+ <number>0</number>
+ </property>
+ <property name="maximum">
+ <number>100</number>
+ </property>
+ <property name="value">
+ <number>0</number>
+ </property>
+ <property name="textVisible">
+ <bool>false</bool>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="textDirection">
+ <enum>QProgressBar::BottomToTop</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QTextEdit" name="Output">
+ <property name="lineWrapMode">
+ <enum>QTextEdit::NoWrap</enum>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QCMakeCacheView</class>
+ <extends>QTreeView</extends>
+ <header>QCMakeCacheView.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources>
+ <include location="CMakeSetup.qrc"/>
+ </resources>
+ <connections/>
+</ui>
diff --git a/Source/QtDialog/Compilers.h b/Source/QtDialog/Compilers.h
new file mode 100644
index 0000000000..3f7b83411a
--- /dev/null
+++ b/Source/QtDialog/Compilers.h
@@ -0,0 +1,21 @@
+
+
+#ifndef COMPILERS_HPP
+#define COMPILERS_HPP
+
+#include <QWidget>
+#include <ui_Compilers.h>
+
+class Compilers : public QWidget, public Ui::Compilers
+{
+ Q_OBJECT
+public:
+ Compilers(QWidget* p=NULL) :
+ QWidget(p)
+ {
+ this->setupUi(this);
+ }
+};
+
+#endif
+
diff --git a/Source/QtDialog/Compilers.ui b/Source/QtDialog/Compilers.ui
new file mode 100644
index 0000000000..41f70acdb7
--- /dev/null
+++ b/Source/QtDialog/Compilers.ui
@@ -0,0 +1,87 @@
+<ui version="4.0" >
+ <class>Compilers</class>
+ <widget class="QWidget" name="Compilers" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>506</width>
+ <height>115</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="leftMargin" >
+ <number>0</number>
+ </property>
+ <property name="topMargin" >
+ <number>0</number>
+ </property>
+ <property name="rightMargin" >
+ <number>0</number>
+ </property>
+ <property name="bottomMargin" >
+ <number>0</number>
+ </property>
+ <item row="0" column="0" >
+ <widget class="QGroupBox" name="groupBox_4" >
+ <property name="title" >
+ <string>Compilers</string>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="leftMargin" >
+ <number>4</number>
+ </property>
+ <property name="topMargin" >
+ <number>4</number>
+ </property>
+ <property name="rightMargin" >
+ <number>4</number>
+ </property>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label_16" >
+ <property name="text" >
+ <string>C</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QCMakeFilePathEditor" name="CCompiler" />
+ </item>
+ <item row="0" column="2" >
+ <widget class="QLabel" name="label_17" >
+ <property name="text" >
+ <string>C++</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3" >
+ <widget class="QCMakeFilePathEditor" name="CXXCompiler" />
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_18" >
+ <property name="text" >
+ <string>Fortran</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QCMakeFilePathEditor" name="FortranCompiler" />
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QCMakeFilePathEditor</class>
+ <extends>QLineEdit</extends>
+ <header>QCMakeWidgets.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Source/QtDialog/CrossCompiler.ui b/Source/QtDialog/CrossCompiler.ui
new file mode 100644
index 0000000000..1fb1ebf492
--- /dev/null
+++ b/Source/QtDialog/CrossCompiler.ui
@@ -0,0 +1,213 @@
+<ui version="4.0" >
+ <class>CrossCompiler</class>
+ <widget class="QWidget" name="CrossCompiler" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>433</width>
+ <height>319</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>CrossCompiler</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QGroupBox" name="groupBox" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title" >
+ <string>Target System</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label_6" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Operating System</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="systemName" />
+ </item>
+ <item row="0" column="2" colspan="2" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_10" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Version</string>
+ </property>
+ <property name="wordWrap" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QLineEdit" name="systemVersion" />
+ </item>
+ <item row="1" column="2" >
+ <widget class="QLabel" name="label_11" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Processor</string>
+ </property>
+ <property name="wordWrap" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3" >
+ <widget class="QLineEdit" name="systemProcessor" />
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QGroupBox" name="groupBox_2" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title" >
+ <string>Find Program/Library/Include</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label_9" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Target Root</string>
+ </property>
+ <property name="wordWrap" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QCMakePathEditor" name="crossFindRoot" />
+ </item>
+ <item row="0" column="2" >
+ <widget class="QLabel" name="label_12" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Program Mode</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3" >
+ <widget class="QComboBox" name="crossProgramMode" />
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_13" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Library Mode</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QComboBox" name="crossLibraryMode" />
+ </item>
+ <item row="1" column="2" >
+ <widget class="QLabel" name="label_14" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Include Mode</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3" >
+ <widget class="QComboBox" name="crossIncludeMode" />
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="Compilers" native="1" name="CrossCompilers" >
+ <property name="focusPolicy" >
+ <enum>Qt::TabFocus</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QCMakePathEditor</class>
+ <extends>QLineEdit</extends>
+ <header>QCMakeWidgets.h</header>
+ </customwidget>
+ <customwidget>
+ <class>Compilers</class>
+ <extends>QWidget</extends>
+ <header>Compilers.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <tabstops>
+ <tabstop>systemVersion</tabstop>
+ <tabstop>systemProcessor</tabstop>
+ <tabstop>CrossCompilers</tabstop>
+ <tabstop>crossFindRoot</tabstop>
+ <tabstop>crossProgramMode</tabstop>
+ <tabstop>crossLibraryMode</tabstop>
+ <tabstop>crossIncludeMode</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Source/QtDialog/Delete16.png b/Source/QtDialog/Delete16.png
new file mode 100644
index 0000000000..16989fee12
--- /dev/null
+++ b/Source/QtDialog/Delete16.png
Binary files differ
diff --git a/Source/QtDialog/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx
new file mode 100644
index 0000000000..6de9f00ccb
--- /dev/null
+++ b/Source/QtDialog/FirstConfigure.cxx
@@ -0,0 +1,509 @@
+
+#include "FirstConfigure.h"
+#include "Compilers.h"
+
+#include <QSettings>
+#include <QRadioButton>
+#include <QComboBox>
+#include <QVBoxLayout>
+
+
+StartCompilerSetup::StartCompilerSetup(QWidget* p)
+ : QWizardPage(p)
+{
+ QVBoxLayout* l = new QVBoxLayout(this);
+ l->addWidget(new QLabel(tr("Specify the generator for this project")));
+ this->GeneratorOptions = new QComboBox(this);
+ l->addWidget(this->GeneratorOptions);
+ l->addSpacing(6);
+
+ this->CompilerSetupOptions[0] = new QRadioButton(tr("Use default native compilers"), this);
+ this->CompilerSetupOptions[1] = new QRadioButton(tr("Specify native compilers"), this);
+ this->CompilerSetupOptions[2] = new QRadioButton(tr("Specify toolchain file for cross-compiling"), this);
+ this->CompilerSetupOptions[3] = new QRadioButton(tr("Specify options for cross-compiling"), this);
+ l->addWidget(this->CompilerSetupOptions[0]);
+ l->addWidget(this->CompilerSetupOptions[1]);
+ l->addWidget(this->CompilerSetupOptions[2]);
+ l->addWidget(this->CompilerSetupOptions[3]);
+
+ this->CompilerSetupOptions[0]->setChecked(true);
+
+ QObject::connect(this->CompilerSetupOptions[0], SIGNAL(toggled(bool)),
+ this, SLOT(onSelectionChanged(bool)));
+ QObject::connect(this->CompilerSetupOptions[1], SIGNAL(toggled(bool)),
+ this, SLOT(onSelectionChanged(bool)));
+ QObject::connect(this->CompilerSetupOptions[2], SIGNAL(toggled(bool)),
+ this, SLOT(onSelectionChanged(bool)));
+ QObject::connect(this->CompilerSetupOptions[3], SIGNAL(toggled(bool)),
+ this, SLOT(onSelectionChanged(bool)));
+}
+
+StartCompilerSetup::~StartCompilerSetup()
+{
+}
+
+void StartCompilerSetup::setGenerators(const QStringList& gens)
+{
+ this->GeneratorOptions->clear();
+ this->GeneratorOptions->addItems(gens);
+};
+
+void StartCompilerSetup::setCurrentGenerator(const QString& gen)
+{
+ int idx = this->GeneratorOptions->findText(gen);
+ if(idx != -1)
+ {
+ this->GeneratorOptions->setCurrentIndex(idx);
+ }
+}
+
+QString StartCompilerSetup::getGenerator() const
+{
+ return this->GeneratorOptions->currentText();
+};
+
+bool StartCompilerSetup::defaultSetup() const
+{
+ return this->CompilerSetupOptions[0]->isChecked();
+}
+
+bool StartCompilerSetup::compilerSetup() const
+{
+ return this->CompilerSetupOptions[1]->isChecked();
+}
+
+bool StartCompilerSetup::crossCompilerToolChainFile() const
+{
+ return this->CompilerSetupOptions[2]->isChecked();
+}
+
+bool StartCompilerSetup::crossCompilerSetup() const
+{
+ return this->CompilerSetupOptions[3]->isChecked();
+}
+
+void StartCompilerSetup::onSelectionChanged(bool on)
+{
+ if(on)
+ selectionChanged();
+}
+
+int StartCompilerSetup::nextId() const
+{
+ if(compilerSetup())
+ return NativeSetup;
+ if(crossCompilerSetup())
+ return CrossSetup;
+ if(crossCompilerToolChainFile())
+ return ToolchainSetup;
+ return -1;
+}
+
+NativeCompilerSetup::NativeCompilerSetup(QWidget* p)
+ : QWizardPage(p)
+{
+ QVBoxLayout* l = new QVBoxLayout(this);
+ QWidget* c = new QWidget(this);
+ l->addWidget(c);
+ this->setupUi(c);
+}
+
+NativeCompilerSetup::~NativeCompilerSetup()
+{
+}
+
+QString NativeCompilerSetup::getCCompiler() const
+{
+ return this->CCompiler->text();
+}
+
+void NativeCompilerSetup::setCCompiler(const QString& s)
+{
+ this->CCompiler->setText(s);
+}
+
+QString NativeCompilerSetup::getCXXCompiler() const
+{
+ return this->CXXCompiler->text();
+}
+
+void NativeCompilerSetup::setCXXCompiler(const QString& s)
+{
+ this->CXXCompiler->setText(s);
+}
+
+QString NativeCompilerSetup::getFortranCompiler() const
+{
+ return this->FortranCompiler->text();
+}
+
+void NativeCompilerSetup::setFortranCompiler(const QString& s)
+{
+ this->FortranCompiler->setText(s);
+}
+
+
+CrossCompilerSetup::CrossCompilerSetup(QWidget* p)
+ : QWizardPage(p)
+{
+ this->setupUi(this);
+ QWidget::setTabOrder(systemName, systemVersion);
+ QWidget::setTabOrder(systemVersion, systemProcessor);
+ QWidget::setTabOrder(systemProcessor, CrossCompilers->CCompiler);
+ QWidget::setTabOrder(CrossCompilers->CCompiler, CrossCompilers->CXXCompiler);
+ QWidget::setTabOrder(CrossCompilers->CXXCompiler, CrossCompilers->FortranCompiler);
+ QWidget::setTabOrder(CrossCompilers->FortranCompiler, crossFindRoot);
+ QWidget::setTabOrder(crossFindRoot, crossProgramMode);
+ QWidget::setTabOrder(crossProgramMode, crossLibraryMode);
+ QWidget::setTabOrder(crossLibraryMode, crossIncludeMode);
+
+ // fill in combo boxes
+ QStringList modes;
+ modes << tr("Search in Target Root, then native system");
+ modes << tr("Search only in Target Root");
+ modes << tr("Search only in native system");
+ crossProgramMode->addItems(modes);
+ crossLibraryMode->addItems(modes);
+ crossIncludeMode->addItems(modes);
+ crossProgramMode->setCurrentIndex(2);
+ crossLibraryMode->setCurrentIndex(1);
+ crossIncludeMode->setCurrentIndex(1);
+
+ this->registerField("systemName*", this->systemName);
+}
+
+CrossCompilerSetup::~CrossCompilerSetup()
+{
+}
+
+QString CrossCompilerSetup::getCCompiler() const
+{
+ return this->CrossCompilers->CCompiler->text();
+}
+
+void CrossCompilerSetup::setCCompiler(const QString& s)
+{
+ this->CrossCompilers->CCompiler->setText(s);
+}
+
+QString CrossCompilerSetup::getCXXCompiler() const
+{
+ return this->CrossCompilers->CXXCompiler->text();
+}
+
+void CrossCompilerSetup::setCXXCompiler(const QString& s)
+{
+ this->CrossCompilers->CXXCompiler->setText(s);
+}
+
+QString CrossCompilerSetup::getFortranCompiler() const
+{
+ return this->CrossCompilers->FortranCompiler->text();
+}
+
+void CrossCompilerSetup::setFortranCompiler(const QString& s)
+{
+ this->CrossCompilers->FortranCompiler->setText(s);
+}
+
+QString CrossCompilerSetup::getSystem() const
+{
+ return this->systemName->text();
+}
+
+void CrossCompilerSetup::setSystem(const QString& t)
+{
+ this->systemName->setText(t);
+}
+
+
+QString CrossCompilerSetup::getVersion() const
+{
+ return this->systemVersion->text();
+}
+
+void CrossCompilerSetup::setVersion(const QString& t)
+{
+ this->systemVersion->setText(t);
+}
+
+
+QString CrossCompilerSetup::getProcessor() const
+{
+ return this->systemProcessor->text();
+}
+
+void CrossCompilerSetup::setProcessor(const QString& t)
+{
+ this->systemProcessor->setText(t);
+}
+
+QString CrossCompilerSetup::getFindRoot() const
+{
+ return this->crossFindRoot->text();
+}
+
+void CrossCompilerSetup::setFindRoot(const QString& t)
+{
+ return this->crossFindRoot->setText(t);
+}
+
+int CrossCompilerSetup::getProgramMode() const
+{
+ return this->crossProgramMode->currentIndex();
+}
+
+int CrossCompilerSetup::getLibraryMode() const
+{
+ return this->crossLibraryMode->currentIndex();
+}
+
+int CrossCompilerSetup::getIncludeMode() const
+{
+ return this->crossIncludeMode->currentIndex();
+}
+
+void CrossCompilerSetup::setProgramMode(int m)
+{
+ this->crossProgramMode->setCurrentIndex(m);
+}
+
+void CrossCompilerSetup::setLibraryMode(int m)
+{
+ this->crossLibraryMode->setCurrentIndex(m);
+}
+
+void CrossCompilerSetup::setIncludeMode(int m)
+{
+ this->crossIncludeMode->setCurrentIndex(m);
+}
+
+ToolchainCompilerSetup::ToolchainCompilerSetup(QWidget* p)
+ : QWizardPage(p)
+{
+ QVBoxLayout* l = new QVBoxLayout(this);
+ l->addWidget(new QLabel(tr("Specify the Toolchain file")));
+ this->ToolchainFile = new QCMakeFilePathEditor(this);
+ l->addWidget(this->ToolchainFile);
+}
+
+ToolchainCompilerSetup::~ToolchainCompilerSetup()
+{
+}
+
+QString ToolchainCompilerSetup::toolchainFile() const
+{
+ return this->ToolchainFile->text();
+}
+
+void ToolchainCompilerSetup::setToolchainFile(const QString& t)
+{
+ this->ToolchainFile->setText(t);
+}
+
+
+
+FirstConfigure::FirstConfigure()
+{
+ //this->setOption(QWizard::HaveFinishButtonOnEarlyPages, true);
+ this->mStartCompilerSetupPage = new StartCompilerSetup(this);
+ this->setPage(Start, this->mStartCompilerSetupPage);
+ QObject::connect(this->mStartCompilerSetupPage, SIGNAL(selectionChanged()),
+ this, SLOT(restart()));
+
+ this->mNativeCompilerSetupPage = new NativeCompilerSetup(this);
+ this->setPage(NativeSetup, this->mNativeCompilerSetupPage);
+
+ this->mCrossCompilerSetupPage = new CrossCompilerSetup(this);
+ this->setPage(CrossSetup, this->mCrossCompilerSetupPage);
+
+ this->mToolchainCompilerSetupPage = new ToolchainCompilerSetup(this);
+ this->setPage(ToolchainSetup, this->mToolchainCompilerSetupPage);
+}
+
+FirstConfigure::~FirstConfigure()
+{
+}
+
+void FirstConfigure::setGenerators(const QStringList& gens)
+{
+ this->mStartCompilerSetupPage->setGenerators(gens);
+}
+
+QString FirstConfigure::getGenerator() const
+{
+ return this->mStartCompilerSetupPage->getGenerator();
+}
+
+void FirstConfigure::loadFromSettings()
+{
+ QSettings settings;
+ // restore generator
+ settings.beginGroup("Settings/StartPath");
+ QString lastGen = settings.value("LastGenerator").toString();
+ this->mStartCompilerSetupPage->setCurrentGenerator(lastGen);
+ settings.endGroup();
+
+ // restore compiler setup
+ settings.beginGroup("Settings/Compiler");
+ this->mNativeCompilerSetupPage->setCCompiler(settings.value("CCompiler").toString());
+ this->mNativeCompilerSetupPage->setCXXCompiler(settings.value("CXXCompiler").toString());
+ this->mNativeCompilerSetupPage->setFortranCompiler(settings.value("FortranCompiler").toString());
+ settings.endGroup();
+
+ // restore cross compiler setup
+ settings.beginGroup("Settings/CrossCompiler");
+ this->mCrossCompilerSetupPage->setCCompiler(settings.value("CCompiler").toString());
+ this->mCrossCompilerSetupPage->setCXXCompiler(settings.value("CXXCompiler").toString());
+ this->mCrossCompilerSetupPage->setFortranCompiler(settings.value("FortranCompiler").toString());
+ this->mToolchainCompilerSetupPage->setToolchainFile(settings.value("ToolChainFile").toString());
+ this->mCrossCompilerSetupPage->setSystem(settings.value("SystemName").toString());
+ this->mCrossCompilerSetupPage->setVersion(settings.value("SystemVersion").toString());
+ this->mCrossCompilerSetupPage->setProcessor(settings.value("SystemProcessor").toString());
+ this->mCrossCompilerSetupPage->setFindRoot(settings.value("FindRoot").toString());
+ this->mCrossCompilerSetupPage->setProgramMode(settings.value("ProgramMode", 0).toInt());
+ this->mCrossCompilerSetupPage->setLibraryMode(settings.value("LibraryMode", 0).toInt());
+ this->mCrossCompilerSetupPage->setIncludeMode(settings.value("IncludeMode", 0).toInt());
+ settings.endGroup();
+}
+
+void FirstConfigure::saveToSettings()
+{
+ QSettings settings;
+
+ // save generator
+ settings.beginGroup("Settings/StartPath");
+ QString lastGen = this->mStartCompilerSetupPage->getGenerator();
+ settings.setValue("LastGenerator", lastGen);
+ settings.endGroup();
+
+ // save compiler setup
+ settings.beginGroup("Settings/Compiler");
+ settings.setValue("CCompiler", this->mNativeCompilerSetupPage->getCCompiler());
+ settings.setValue("CXXCompiler", this->mNativeCompilerSetupPage->getCXXCompiler());
+ settings.setValue("FortranCompiler", this->mNativeCompilerSetupPage->getFortranCompiler());
+ settings.endGroup();
+
+ // save cross compiler setup
+ settings.beginGroup("Settings/CrossCompiler");
+ settings.setValue("CCompiler", this->mCrossCompilerSetupPage->getCCompiler());
+ settings.setValue("CXXCompiler", this->mCrossCompilerSetupPage->getCXXCompiler());
+ settings.setValue("FortranCompiler", this->mCrossCompilerSetupPage->getFortranCompiler());
+ settings.setValue("ToolChainFile", this->getCrossCompilerToolChainFile());
+ settings.setValue("SystemName", this->mCrossCompilerSetupPage->getSystem());
+ settings.setValue("SystemVersion", this->mCrossCompilerSetupPage->getVersion());
+ settings.setValue("SystemProcessor", this->mCrossCompilerSetupPage->getProcessor());
+ settings.setValue("FindRoot", this->mCrossCompilerSetupPage->getFindRoot());
+ settings.setValue("ProgramMode", this->mCrossCompilerSetupPage->getProgramMode());
+ settings.setValue("LibraryMode", this->mCrossCompilerSetupPage->getLibraryMode());
+ settings.setValue("IncludeMode", this->mCrossCompilerSetupPage->getIncludeMode());
+ settings.endGroup();
+}
+
+bool FirstConfigure::defaultSetup() const
+{
+ return this->mStartCompilerSetupPage->defaultSetup();
+}
+
+bool FirstConfigure::compilerSetup() const
+{
+ return this->mStartCompilerSetupPage->compilerSetup();
+}
+
+bool FirstConfigure::crossCompilerSetup() const
+{
+ return this->mStartCompilerSetupPage->crossCompilerSetup();
+}
+
+bool FirstConfigure::crossCompilerToolChainFile() const
+{
+ return this->mStartCompilerSetupPage->crossCompilerToolChainFile();
+}
+
+QString FirstConfigure::getCrossCompilerToolChainFile() const
+{
+ return this->mToolchainCompilerSetupPage->toolchainFile();
+}
+
+QString FirstConfigure::getSystemName() const
+{
+ return this->mCrossCompilerSetupPage->getSystem();
+}
+
+QString FirstConfigure::getCCompiler() const
+{
+ if(this->compilerSetup())
+ {
+ return this->mNativeCompilerSetupPage->getCCompiler();
+ }
+ else if(this->crossCompilerSetup())
+ {
+ return this->mCrossCompilerSetupPage->getCCompiler();
+ }
+ return QString();
+}
+
+QString FirstConfigure::getCXXCompiler() const
+{
+ if(this->compilerSetup())
+ {
+ return this->mNativeCompilerSetupPage->getCXXCompiler();
+ }
+ else if(this->crossCompilerSetup())
+ {
+ return this->mCrossCompilerSetupPage->getCXXCompiler();
+ }
+ return QString();
+}
+
+QString FirstConfigure::getFortranCompiler() const
+{
+ if(this->compilerSetup())
+ {
+ return this->mNativeCompilerSetupPage->getFortranCompiler();
+ }
+ else if(this->crossCompilerSetup())
+ {
+ return this->mCrossCompilerSetupPage->getFortranCompiler();
+ }
+ return QString();
+}
+
+
+QString FirstConfigure::getSystemVersion() const
+{
+ return this->mCrossCompilerSetupPage->getVersion();
+}
+
+QString FirstConfigure::getSystemProcessor() const
+{
+ return this->mCrossCompilerSetupPage->getProcessor();
+}
+
+QString FirstConfigure::getCrossRoot() const
+{
+ return this->mCrossCompilerSetupPage->getFindRoot();
+}
+
+const QString CrossModes[] =
+{
+ "BOTH",
+ "ONLY",
+ "NEVER"
+};
+
+QString FirstConfigure::getCrossProgramMode() const
+{
+ return CrossModes[this->mCrossCompilerSetupPage->getProgramMode()];
+}
+
+QString FirstConfigure::getCrossLibraryMode() const
+{
+ return CrossModes[this->mCrossCompilerSetupPage->getLibraryMode()];
+}
+
+QString FirstConfigure::getCrossIncludeMode() const
+{
+ return CrossModes[this->mCrossCompilerSetupPage->getIncludeMode()];
+}
+
diff --git a/Source/QtDialog/FirstConfigure.h b/Source/QtDialog/FirstConfigure.h
new file mode 100644
index 0000000000..be390b0fdd
--- /dev/null
+++ b/Source/QtDialog/FirstConfigure.h
@@ -0,0 +1,177 @@
+
+#ifndef FirstConfigure_h
+#define FirstConfigure_h
+
+#include <QWizard>
+#include <QWizardPage>
+#include "ui_Compilers.h"
+#include "ui_CrossCompiler.h"
+
+class QRadioButton;
+class QComboBox;
+
+//! the wizard pages we'll use for the first configure of a build
+enum FirstConfigurePages
+{
+ Start,
+ NativeSetup,
+ ToolchainSetup,
+ CrossSetup,
+ Done
+};
+
+//! the first page that gives basic options for what compilers setup to choose from
+class StartCompilerSetup : public QWizardPage
+{
+ Q_OBJECT
+ public:
+ StartCompilerSetup(QWidget* p);
+ ~StartCompilerSetup();
+ void setGenerators(const QStringList& gens);
+ void setCurrentGenerator(const QString& gen);
+ QString getGenerator() const;
+
+ bool defaultSetup() const;
+ bool compilerSetup() const;
+ bool crossCompilerSetup() const;
+ bool crossCompilerToolChainFile() const;
+
+ int nextId() const;
+
+ signals:
+ void selectionChanged();
+
+ protected slots:
+ void onSelectionChanged(bool);
+
+ protected:
+ QComboBox* GeneratorOptions;
+ QRadioButton* CompilerSetupOptions[4];
+};
+
+//! the page that gives basic options for native compilers
+class NativeCompilerSetup : public QWizardPage, protected Ui::Compilers
+{
+ Q_OBJECT
+ public:
+ NativeCompilerSetup(QWidget* p);
+ ~NativeCompilerSetup();
+
+ QString getCCompiler() const;
+ void setCCompiler(const QString&);
+
+ QString getCXXCompiler() const;
+ void setCXXCompiler(const QString&);
+
+ QString getFortranCompiler() const;
+ void setFortranCompiler(const QString&);
+
+ int nextId() const { return -1; }
+};
+
+//! the page that gives options for cross compilers
+class CrossCompilerSetup : public QWizardPage, protected Ui::CrossCompiler
+{
+ Q_OBJECT
+ public:
+ CrossCompilerSetup(QWidget* p);
+ ~CrossCompilerSetup();
+
+ QString getSystem() const;
+ void setSystem(const QString&);
+
+ QString getVersion() const;
+ void setVersion(const QString&);
+
+ QString getProcessor() const;
+ void setProcessor(const QString&);
+
+ QString getCCompiler() const;
+ void setCCompiler(const QString&);
+
+ QString getCXXCompiler() const;
+ void setCXXCompiler(const QString&);
+
+ QString getFortranCompiler() const;
+ void setFortranCompiler(const QString&);
+
+ QString getFindRoot() const;
+ void setFindRoot(const QString&);
+
+ enum CrossMode
+ {
+ BOTH,
+ ONLY,
+ NEVER
+ };
+
+ int getProgramMode() const;
+ void setProgramMode(int);
+ int getLibraryMode() const;
+ void setLibraryMode(int);
+ int getIncludeMode() const;
+ void setIncludeMode(int);
+
+ int nextId() const { return -1; }
+};
+
+//! the page that gives options for a toolchain file
+class ToolchainCompilerSetup : public QWizardPage
+{
+ Q_OBJECT
+ public:
+ ToolchainCompilerSetup(QWidget* p);
+ ~ToolchainCompilerSetup();
+
+ QString toolchainFile() const;
+ void setToolchainFile(const QString&);
+
+ int nextId() const { return -1; }
+
+ protected:
+ QCMakeFilePathEditor* ToolchainFile;
+};
+
+//! the wizard with the pages
+class FirstConfigure : public QWizard
+{
+ Q_OBJECT
+public:
+ FirstConfigure();
+ ~FirstConfigure();
+
+ void setGenerators(const QStringList& gens);
+ QString getGenerator() const;
+
+ bool defaultSetup() const;
+ bool compilerSetup() const;
+ bool crossCompilerSetup() const;
+ bool crossCompilerToolChainFile() const;
+
+ QString getCCompiler() const;
+ QString getCXXCompiler() const;
+ QString getFortranCompiler() const;
+
+ QString getSystemName() const;
+ QString getSystemVersion() const;
+ QString getSystemProcessor() const;
+ QString getCrossRoot() const;
+ QString getCrossProgramMode() const;
+ QString getCrossLibraryMode() const;
+ QString getCrossIncludeMode() const;
+
+ QString getCrossCompilerToolChainFile() const;
+
+ void loadFromSettings();
+ void saveToSettings();
+
+protected:
+ StartCompilerSetup* mStartCompilerSetupPage;
+ NativeCompilerSetup* mNativeCompilerSetupPage;
+ CrossCompilerSetup* mCrossCompilerSetupPage;
+ ToolchainCompilerSetup* mToolchainCompilerSetupPage;
+
+};
+
+#endif // FirstConfigure_h
+
diff --git a/Source/QtDialog/Info.plist.in b/Source/QtDialog/Info.plist.in
new file mode 100644
index 0000000000..b9c4af5838
--- /dev/null
+++ b/Source/QtDialog/Info.plist.in
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string>${MACOSX_BUNDLE_ICON_FILE}</string>
+ <key>CFBundleIdentifier</key>
+ <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
+ <key>CSResourcesFileMapped</key>
+ <true/>
+ <key>LSApplicationCategoryType</key>
+ <string>public.app-category.developer-tools</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>${MACOSX_BUNDLE_COPYRIGHT}</string>
+</dict>
+</plist>
diff --git a/Source/QtDialog/MacInstallDialog.ui b/Source/QtDialog/MacInstallDialog.ui
new file mode 100644
index 0000000000..c7e31dbbe7
--- /dev/null
+++ b/Source/QtDialog/MacInstallDialog.ui
@@ -0,0 +1,103 @@
+<ui version="4.0" >
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>470</width>
+ <height>159</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Install Command Line Tools</string>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="3" column="1" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="2" column="0" colspan="3" >
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="skipInstallButton" >
+ <property name="text" >
+ <string>Skip Install Command Line </string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="doInstallButton" >
+ <property name="text" >
+ <string>Install Command Line Links</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="0" column="2" >
+ <widget class="QPushButton" name="choosePathButton" >
+ <property name="text" >
+ <string>Choose...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Install Folder:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="InstallPrefix" />
+ </item>
+ <item row="1" column="0" colspan="3" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>This will create symbolic links to the command line tools of cmake into the specified install folder.</string>
+ </property>
+ <property name="wordWrap" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Source/QtDialog/Plus16.png b/Source/QtDialog/Plus16.png
new file mode 100644
index 0000000000..552f6f0045
--- /dev/null
+++ b/Source/QtDialog/Plus16.png
Binary files differ
diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx
new file mode 100644
index 0000000000..b833648c30
--- /dev/null
+++ b/Source/QtDialog/QCMake.cxx
@@ -0,0 +1,447 @@
+/*============================================================================
+ 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 "QCMake.h"
+
+#include <QDir>
+#include <QCoreApplication>
+
+#include "cmake.h"
+#include "cmCacheManager.h"
+#include "cmSystemTools.h"
+#include "cmExternalMakefileProjectGenerator.h"
+
+#ifdef Q_OS_WIN
+#include "qt_windows.h" // For SetErrorMode
+#endif
+
+QCMake::QCMake(QObject* p)
+ : QObject(p)
+{
+ this->SuppressDevWarnings = false;
+ this->WarnUninitializedMode = false;
+ this->WarnUnusedMode = false;
+ qRegisterMetaType<QCMakeProperty>();
+ qRegisterMetaType<QCMakePropertyList>();
+
+ cmSystemTools::DisableRunCommandOutput();
+ cmSystemTools::SetRunCommandHideConsole(true);
+ cmSystemTools::SetMessageCallback(QCMake::messageCallback, this);
+ cmSystemTools::SetStdoutCallback(QCMake::stdoutCallback, this);
+ cmSystemTools::SetStderrCallback(QCMake::stderrCallback, this);
+
+ this->CMakeInstance = new cmake;
+ this->CMakeInstance->SetCMakeEditCommand(
+ cmSystemTools::GetCMakeGUICommand());
+ this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);
+
+ cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this);
+
+ std::vector<std::string> generators;
+ this->CMakeInstance->GetRegisteredGenerators(generators);
+ std::vector<std::string>::iterator iter;
+ for(iter = generators.begin(); iter != generators.end(); ++iter)
+ {
+ // 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")
+ {
+ continue;
+ }
+ this->AvailableGenerators.append(QString::fromLocal8Bit(iter->c_str()));
+ }
+}
+
+QCMake::~QCMake()
+{
+ delete this->CMakeInstance;
+ //cmDynamicLoader::FlushCache();
+}
+
+void QCMake::loadCache(const QString& dir)
+{
+ this->setBinaryDirectory(dir);
+}
+
+void QCMake::setSourceDirectory(const QString& _dir)
+{
+ QString dir =
+ QString::fromLocal8Bit(cmSystemTools::GetActualCaseForPath(_dir.toLocal8Bit().data()).c_str());
+ if(this->SourceDirectory != dir)
+ {
+ this->SourceDirectory = QDir::fromNativeSeparators(dir);
+ emit this->sourceDirChanged(this->SourceDirectory);
+ }
+}
+
+void QCMake::setBinaryDirectory(const QString& _dir)
+{
+ QString dir =
+ QString::fromLocal8Bit(cmSystemTools::GetActualCaseForPath(_dir.toLocal8Bit().data()).c_str());
+ if(this->BinaryDirectory != dir)
+ {
+ this->BinaryDirectory = QDir::fromNativeSeparators(dir);
+ emit this->binaryDirChanged(this->BinaryDirectory);
+ cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
+ this->setGenerator(QString());
+ if(!this->CMakeInstance->GetCacheManager()->LoadCache(
+ this->BinaryDirectory.toLocal8Bit().data()))
+ {
+ QDir testDir(this->BinaryDirectory);
+ if(testDir.exists("CMakeCache.txt"))
+ {
+ cmSystemTools::Error("There is a CMakeCache.txt file for the current binary "
+ "tree but cmake does not have permission to read it. "
+ "Please check the permissions of the directory you are trying to run CMake on.");
+ }
+ }
+
+ QCMakePropertyList props = this->properties();
+ emit this->propertiesChanged(props);
+ cmCacheManager::CacheIterator itm = cachem->NewIterator();
+ if ( itm.Find("CMAKE_HOME_DIRECTORY"))
+ {
+ setSourceDirectory(QString::fromLocal8Bit(itm.GetValue().c_str()));
+ }
+ if ( itm.Find("CMAKE_GENERATOR"))
+ {
+ const char* extraGen = cachem->GetCacheValue("CMAKE_EXTRA_GENERATOR");
+ std::string curGen = cmExternalMakefileProjectGenerator::
+ CreateFullGeneratorName(itm.GetValue(), extraGen? extraGen : "");
+ this->setGenerator(QString::fromLocal8Bit(curGen.c_str()));
+ }
+ }
+}
+
+
+void QCMake::setGenerator(const QString& gen)
+{
+ if(this->Generator != gen)
+ {
+ this->Generator = gen;
+ emit this->generatorChanged(this->Generator);
+ }
+}
+
+void QCMake::configure()
+{
+#ifdef Q_OS_WIN
+ UINT lastErrorMode = SetErrorMode(0);
+#endif
+
+ this->CMakeInstance->SetHomeDirectory(this->SourceDirectory.toLocal8Bit().data());
+ this->CMakeInstance->SetStartDirectory(this->SourceDirectory.toLocal8Bit().data());
+ this->CMakeInstance->SetHomeOutputDirectory(this->BinaryDirectory.toLocal8Bit().data());
+ this->CMakeInstance->SetStartOutputDirectory(this->BinaryDirectory.toLocal8Bit().data());
+ this->CMakeInstance->SetGlobalGenerator(
+ this->CMakeInstance->CreateGlobalGenerator(this->Generator.toLocal8Bit().data()));
+ this->CMakeInstance->LoadCache();
+ this->CMakeInstance->SetSuppressDevWarnings(this->SuppressDevWarnings);
+ this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode);
+ this->CMakeInstance->SetWarnUnused(this->WarnUnusedMode);
+ this->CMakeInstance->PreLoadCMakeFiles();
+
+ InterruptFlag = 0;
+ cmSystemTools::ResetErrorOccuredFlag();
+
+ int err = this->CMakeInstance->Configure();
+
+#ifdef Q_OS_WIN
+ SetErrorMode(lastErrorMode);
+#endif
+
+ emit this->propertiesChanged(this->properties());
+ emit this->configureDone(err);
+}
+
+void QCMake::generate()
+{
+#ifdef Q_OS_WIN
+ UINT lastErrorMode = SetErrorMode(0);
+#endif
+
+ InterruptFlag = 0;
+ cmSystemTools::ResetErrorOccuredFlag();
+
+ int err = this->CMakeInstance->Generate();
+
+#ifdef Q_OS_WIN
+ SetErrorMode(lastErrorMode);
+#endif
+
+ emit this->generateDone(err);
+}
+
+void QCMake::setProperties(const QCMakePropertyList& newProps)
+{
+ QCMakePropertyList props = newProps;
+
+ QStringList toremove;
+
+ // set the value of properties
+ cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
+ for(cmCacheManager::CacheIterator i = cachem->NewIterator();
+ !i.IsAtEnd(); i.Next())
+ {
+
+ if(i.GetType() == cmCacheManager::INTERNAL ||
+ i.GetType() == cmCacheManager::STATIC)
+ {
+ continue;
+ }
+
+ QCMakeProperty prop;
+ prop.Key = QString::fromLocal8Bit(i.GetName().c_str());
+ int idx = props.indexOf(prop);
+ if(idx == -1)
+ {
+ toremove.append(QString::fromLocal8Bit(i.GetName().c_str()));
+ }
+ else
+ {
+ prop = props[idx];
+ if(prop.Value.type() == QVariant::Bool)
+ {
+ i.SetValue(prop.Value.toBool() ? "ON" : "OFF");
+ }
+ else
+ {
+ i.SetValue(prop.Value.toString().toLocal8Bit().data());
+ }
+ props.removeAt(idx);
+ }
+
+ }
+
+ // remove some properites
+ foreach(QString s, toremove)
+ {
+ this->CMakeInstance->UnwatchUnusedCli(s.toLocal8Bit().data());
+
+ cachem->RemoveCacheEntry(s.toLocal8Bit().data());
+ }
+
+ // add some new properites
+ foreach(QCMakeProperty s, props)
+ {
+ this->CMakeInstance->WatchUnusedCli(s.Key.toLocal8Bit().data());
+
+ if(s.Type == QCMakeProperty::BOOL)
+ {
+ this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
+ s.Value.toBool() ? "ON" : "OFF",
+ s.Help.toLocal8Bit().data(),
+ cmCacheManager::BOOL);
+ }
+ else if(s.Type == QCMakeProperty::STRING)
+ {
+ this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
+ s.Value.toString().toLocal8Bit().data(),
+ s.Help.toLocal8Bit().data(),
+ cmCacheManager::STRING);
+ }
+ else if(s.Type == QCMakeProperty::PATH)
+ {
+ this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
+ s.Value.toString().toLocal8Bit().data(),
+ s.Help.toLocal8Bit().data(),
+ cmCacheManager::PATH);
+ }
+ else if(s.Type == QCMakeProperty::FILEPATH)
+ {
+ this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
+ s.Value.toString().toLocal8Bit().data(),
+ s.Help.toLocal8Bit().data(),
+ cmCacheManager::FILEPATH);
+ }
+ }
+
+ cachem->SaveCache(this->BinaryDirectory.toLocal8Bit().data());
+}
+
+QCMakePropertyList QCMake::properties() const
+{
+ QCMakePropertyList ret;
+
+ cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
+ for(cmCacheManager::CacheIterator i = cachem->NewIterator();
+ !i.IsAtEnd(); i.Next())
+ {
+
+ if(i.GetType() == cmCacheManager::INTERNAL ||
+ i.GetType() == cmCacheManager::STATIC ||
+ i.GetType() == cmCacheManager::UNINITIALIZED)
+ {
+ continue;
+ }
+
+ QCMakeProperty prop;
+ prop.Key = QString::fromLocal8Bit(i.GetName().c_str());
+ prop.Help = QString::fromLocal8Bit(i.GetProperty("HELPSTRING"));
+ prop.Value = QString::fromLocal8Bit(i.GetValue().c_str());
+ prop.Advanced = i.GetPropertyAsBool("ADVANCED");
+
+ if(i.GetType() == cmCacheManager::BOOL)
+ {
+ prop.Type = QCMakeProperty::BOOL;
+ prop.Value = cmSystemTools::IsOn(i.GetValue().c_str());
+ }
+ else if(i.GetType() == cmCacheManager::PATH)
+ {
+ prop.Type = QCMakeProperty::PATH;
+ }
+ else if(i.GetType() == cmCacheManager::FILEPATH)
+ {
+ prop.Type = QCMakeProperty::FILEPATH;
+ }
+ else if(i.GetType() == cmCacheManager::STRING)
+ {
+ prop.Type = QCMakeProperty::STRING;
+ if (i.PropertyExists("STRINGS"))
+ {
+ prop.Strings = QString::fromLocal8Bit(i.GetProperty("STRINGS")).split(";");
+ }
+ }
+
+ ret.append(prop);
+ }
+
+ return ret;
+}
+
+void QCMake::interrupt()
+{
+ this->InterruptFlag.ref();
+}
+
+bool QCMake::interruptCallback(void* cd)
+{
+ QCMake* self = reinterpret_cast<QCMake*>(cd);
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+ return self->InterruptFlag;
+#else
+ return self->InterruptFlag.load();
+#endif
+}
+
+void QCMake::progressCallback(const char* msg, float percent, void* cd)
+{
+ QCMake* self = reinterpret_cast<QCMake*>(cd);
+ if(percent >= 0)
+ {
+ emit self->progressChanged(QString::fromLocal8Bit(msg), percent);
+ }
+ else
+ {
+ emit self->outputMessage(QString::fromLocal8Bit(msg));
+ }
+ QCoreApplication::processEvents();
+}
+
+void QCMake::messageCallback(const char* msg, const char* /*title*/,
+ bool& /*stop*/, void* cd)
+{
+ QCMake* self = reinterpret_cast<QCMake*>(cd);
+ emit self->errorMessage(QString::fromLocal8Bit(msg));
+ QCoreApplication::processEvents();
+}
+
+void QCMake::stdoutCallback(const char* msg, size_t len, void* cd)
+{
+ QCMake* self = reinterpret_cast<QCMake*>(cd);
+ emit self->outputMessage(QString::fromLocal8Bit(msg,int(len)));
+ QCoreApplication::processEvents();
+}
+
+void QCMake::stderrCallback(const char* msg, size_t len, void* cd)
+{
+ QCMake* self = reinterpret_cast<QCMake*>(cd);
+ emit self->outputMessage(QString::fromLocal8Bit(msg,int(len)));
+ QCoreApplication::processEvents();
+}
+
+QString QCMake::binaryDirectory() const
+{
+ return this->BinaryDirectory;
+}
+
+QString QCMake::sourceDirectory() const
+{
+ return this->SourceDirectory;
+}
+
+QString QCMake::generator() const
+{
+ return this->Generator;
+}
+
+QStringList QCMake::availableGenerators() const
+{
+ return this->AvailableGenerators;
+}
+
+void QCMake::deleteCache()
+{
+ // delete cache
+ this->CMakeInstance->GetCacheManager()->DeleteCache(this->BinaryDirectory.toLocal8Bit().data());
+ // reload to make our cache empty
+ this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
+ // emit no generator and no properties
+ this->setGenerator(QString());
+ QCMakePropertyList props = this->properties();
+ emit this->propertiesChanged(props);
+}
+
+void QCMake::reloadCache()
+{
+ // emit that the cache was cleaned out
+ QCMakePropertyList props;
+ emit this->propertiesChanged(props);
+ // reload
+ this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
+ // emit new cache properties
+ props = this->properties();
+ emit this->propertiesChanged(props);
+}
+
+void QCMake::setDebugOutput(bool flag)
+{
+ if(flag != this->CMakeInstance->GetDebugOutput())
+ {
+ this->CMakeInstance->SetDebugOutputOn(flag);
+ emit this->debugOutputChanged(flag);
+ }
+}
+
+bool QCMake::getDebugOutput() const
+{
+ return this->CMakeInstance->GetDebugOutput();
+}
+
+
+void QCMake::setSuppressDevWarnings(bool value)
+{
+ this->SuppressDevWarnings = value;
+}
+
+void QCMake::setWarnUninitializedMode(bool value)
+{
+ this->WarnUninitializedMode = value;
+}
+
+void QCMake::setWarnUnusedMode(bool value)
+{
+ this->WarnUnusedMode = value;
+}
diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h
new file mode 100644
index 0000000000..bd82f0de9d
--- /dev/null
+++ b/Source/QtDialog/QCMake.h
@@ -0,0 +1,156 @@
+/*============================================================================
+ 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 __QCMake_h
+#define __QCMake_h
+#ifdef _MSC_VER
+#pragma warning ( disable : 4127 )
+#pragma warning ( disable : 4512 )
+#endif
+
+#include <QObject>
+#include <QString>
+#include <QVariant>
+#include <QList>
+#include <QStringList>
+#include <QMetaType>
+#include <QAtomicInt>
+
+class cmake;
+
+/// struct to represent cmake properties in Qt
+/// Value is of type String or Bool
+struct QCMakeProperty
+{
+ enum PropertyType { BOOL, PATH, FILEPATH, STRING };
+ QString Key;
+ QVariant Value;
+ QStringList Strings;
+ QString Help;
+ PropertyType Type;
+ bool Advanced;
+ bool operator==(const QCMakeProperty& other) const
+ {
+ return this->Key == other.Key;
+ }
+ bool operator<(const QCMakeProperty& other) const
+ {
+ return this->Key < other.Key;
+ }
+};
+
+// list of properties
+typedef QList<QCMakeProperty> QCMakePropertyList;
+
+// allow QVariant to be a property or list of properties
+Q_DECLARE_METATYPE(QCMakeProperty)
+Q_DECLARE_METATYPE(QCMakePropertyList)
+
+/// Qt API for CMake library.
+/// Wrapper like class allows for easier integration with
+/// Qt features such as, signal/slot connections, multi-threading, etc..
+class QCMake : public QObject
+{
+ Q_OBJECT
+public:
+ QCMake(QObject* p=0);
+ ~QCMake();
+public slots:
+ /// load the cache file in a directory
+ void loadCache(const QString& dir);
+ /// set the source directory containing the source
+ void setSourceDirectory(const QString& dir);
+ /// set the binary directory to build in
+ void setBinaryDirectory(const QString& dir);
+ /// set the desired generator to use
+ void setGenerator(const QString& generator);
+ /// do the configure step
+ void configure();
+ /// generate the files
+ void generate();
+ /// set the property values
+ void setProperties(const QCMakePropertyList&);
+ /// interrupt the configure or generate process (if connecting, make a direct connection)
+ void interrupt();
+ /// delete the cache in binary directory
+ void deleteCache();
+ /// reload the cache in binary directory
+ void reloadCache();
+ /// set whether to do debug output
+ void setDebugOutput(bool);
+ /// set whether to do suppress dev warnings
+ void setSuppressDevWarnings(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
+ void setWarnUnusedMode(bool value);
+
+public:
+ /// get the list of cache properties
+ QCMakePropertyList properties() const;
+ /// get the current binary directory
+ QString binaryDirectory() const;
+ /// get the current source directory
+ QString sourceDirectory() const;
+ /// get the current generator
+ QString generator() const;
+ /// get the available generators
+ QStringList availableGenerators() const;
+ /// get whether to do debug output
+ bool getDebugOutput() const;
+
+signals:
+ /// signal when properties change (during read from disk or configure process)
+ void propertiesChanged(const QCMakePropertyList& vars);
+ /// signal when the generator changes
+ void generatorChanged(const QString& gen);
+ /// signal when the source directory changes (binary directory already
+ /// containing a CMakeCache.txt file)
+ void sourceDirChanged(const QString& dir);
+ /// signal when the binary directory changes
+ void binaryDirChanged(const QString& dir);
+ /// signal for progress events
+ void progressChanged(const QString& msg, float percent);
+ /// signal when configure is done
+ void configureDone(int error);
+ /// signal when generate is done
+ void generateDone(int error);
+ /// signal when there is an output message
+ void outputMessage(const QString& msg);
+ /// signal when there is an error message
+ void errorMessage(const QString& msg);
+ /// signal when debug output changes
+ void debugOutputChanged(bool);
+
+protected:
+ cmake* CMakeInstance;
+
+ static bool interruptCallback(void*);
+ static void progressCallback(const char* msg, float percent, void* cd);
+ static void messageCallback(const char* msg, const char* title,
+ 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 CMakeExecutable;
+ QAtomicInt InterruptFlag;
+};
+
+#endif // __QCMake_h
+
diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx
new file mode 100644
index 0000000000..bae6a30a74
--- /dev/null
+++ b/Source/QtDialog/QCMakeCacheView.cxx
@@ -0,0 +1,739 @@
+/*============================================================================
+ 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 "QCMakeCacheView.h"
+
+#include <QHBoxLayout>
+#include <QHeaderView>
+#include <QEvent>
+#include <QStyle>
+#include <QKeyEvent>
+#include <QSortFilterProxyModel>
+#include <QMetaProperty>
+#include <QApplication>
+
+#include "QCMakeWidgets.h"
+
+// filter for searches
+class QCMakeSearchFilter : public QSortFilterProxyModel
+{
+public:
+ QCMakeSearchFilter(QObject* o) : QSortFilterProxyModel(o) {}
+protected:
+ bool filterAcceptsRow(int row, const QModelIndex& p) const
+ {
+ QStringList strs;
+ const QAbstractItemModel* m = this->sourceModel();
+ QModelIndex idx = m->index(row, 0, p);
+
+ // if there are no children, get strings for column 0 and 1
+ if(!m->hasChildren(idx))
+ {
+ strs.append(m->data(idx).toString());
+ idx = m->index(row, 1, p);
+ strs.append(m->data(idx).toString());
+ }
+ else
+ {
+ // get strings for children entries to compare with
+ // instead of comparing with the parent
+ int num = m->rowCount(idx);
+ for(int i=0; i<num; i++)
+ {
+ QModelIndex tmpidx = m->index(i, 0, idx);
+ strs.append(m->data(tmpidx).toString());
+ tmpidx = m->index(i, 1, idx);
+ strs.append(m->data(tmpidx).toString());
+ }
+ }
+
+ // check all strings for a match
+ foreach(QString str, strs)
+ {
+ if(str.contains(this->filterRegExp()))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+};
+
+// filter for searches
+class QCMakeAdvancedFilter : public QSortFilterProxyModel
+{
+public:
+ QCMakeAdvancedFilter(QObject* o)
+ : QSortFilterProxyModel(o), ShowAdvanced(false) {}
+
+ void setShowAdvanced(bool f)
+ {
+ this->ShowAdvanced = f;
+ this->invalidate();
+ }
+ bool showAdvanced() const { return this->ShowAdvanced; }
+
+protected:
+
+ bool ShowAdvanced;
+
+ bool filterAcceptsRow(int row, const QModelIndex& p) const
+ {
+ const QAbstractItemModel* m = this->sourceModel();
+ QModelIndex idx = m->index(row, 0, p);
+
+ // if there are no children
+ if(!m->hasChildren(idx))
+ {
+ bool adv = m->data(idx, QCMakeCacheModel::AdvancedRole).toBool();
+ if(!adv || (adv && this->ShowAdvanced))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ // check children
+ int num = m->rowCount(idx);
+ for(int i=0; i<num; i++)
+ {
+ bool accept = this->filterAcceptsRow(i, idx);
+ if(accept)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+};
+
+QCMakeCacheView::QCMakeCacheView(QWidget* p)
+ : QTreeView(p)
+{
+ // hook up our model and search/filter proxies
+ this->CacheModel = new QCMakeCacheModel(this);
+ this->AdvancedFilter = new QCMakeAdvancedFilter(this);
+ this->AdvancedFilter->setSourceModel(this->CacheModel);
+ this->AdvancedFilter->setDynamicSortFilter(true);
+ this->SearchFilter = new QCMakeSearchFilter(this);
+ this->SearchFilter->setSourceModel(this->AdvancedFilter);
+ this->SearchFilter->setFilterCaseSensitivity(Qt::CaseInsensitive);
+ this->SearchFilter->setDynamicSortFilter(true);
+ this->setModel(this->SearchFilter);
+
+ // our delegate for creating our editors
+ QCMakeCacheModelDelegate* delegate = new QCMakeCacheModelDelegate(this);
+ this->setItemDelegate(delegate);
+
+ this->setUniformRowHeights(true);
+
+ this->setEditTriggers(QAbstractItemView::AllEditTriggers);
+
+ // tab, backtab doesn't step through items
+ this->setTabKeyNavigation(false);
+
+ this->setRootIsDecorated(false);
+}
+
+bool QCMakeCacheView::event(QEvent* e)
+{
+ if(e->type() == QEvent::Show)
+ {
+ this->header()->setDefaultSectionSize(this->viewport()->width()/2);
+ }
+ return QTreeView::event(e);
+}
+
+QCMakeCacheModel* QCMakeCacheView::cacheModel() const
+{
+ return this->CacheModel;
+}
+
+QModelIndex QCMakeCacheView::moveCursor(CursorAction act,
+ Qt::KeyboardModifiers mod)
+{
+ // want home/end to go to begin/end of rows, not columns
+ if(act == MoveHome)
+ {
+ return this->model()->index(0, 1);
+ }
+ else if(act == MoveEnd)
+ {
+ return this->model()->index(this->model()->rowCount()-1, 1);
+ }
+ return QTreeView::moveCursor(act, mod);
+}
+
+void QCMakeCacheView::setShowAdvanced(bool s)
+{
+#if QT_VERSION >= 040300
+ // new 4.3 API that needs to be called. what about an older Qt?
+ this->SearchFilter->invalidate();
+#endif
+
+ this->AdvancedFilter->setShowAdvanced(s);
+}
+
+bool QCMakeCacheView::showAdvanced() const
+{
+ return this->AdvancedFilter->showAdvanced();
+}
+
+void QCMakeCacheView::setSearchFilter(const QString& s)
+{
+ this->SearchFilter->setFilterFixedString(s);
+}
+
+QCMakeCacheModel::QCMakeCacheModel(QObject* p)
+ : QStandardItemModel(p),
+ EditEnabled(true),
+ NewPropertyCount(0),
+ View(FlatView)
+{
+ this->ShowNewProperties = true;
+ QStringList labels;
+ labels << tr("Name") << tr("Value");
+ this->setHorizontalHeaderLabels(labels);
+}
+
+QCMakeCacheModel::~QCMakeCacheModel()
+{
+}
+
+static uint qHash(const QCMakeProperty& p)
+{
+ return qHash(p.Key);
+}
+
+void QCMakeCacheModel::setShowNewProperties(bool f)
+{
+ this->ShowNewProperties = f;
+}
+
+void QCMakeCacheModel::clear()
+{
+ this->QStandardItemModel::clear();
+ this->NewPropertyCount = 0;
+
+ QStringList labels;
+ labels << tr("Name") << tr("Value");
+ this->setHorizontalHeaderLabels(labels);
+}
+
+void QCMakeCacheModel::setProperties(const QCMakePropertyList& props)
+{
+ QSet<QCMakeProperty> newProps, newProps2;
+
+ if(this->ShowNewProperties)
+ {
+ newProps = props.toSet();
+ newProps2 = newProps;
+ QSet<QCMakeProperty> oldProps = this->properties().toSet();
+ oldProps.intersect(newProps);
+ newProps.subtract(oldProps);
+ newProps2.subtract(newProps);
+ }
+ else
+ {
+ newProps2 = props.toSet();
+ }
+
+ bool b = this->blockSignals(true);
+
+ this->clear();
+ this->NewPropertyCount = newProps.size();
+
+ if(View == FlatView)
+ {
+ QCMakePropertyList newP = newProps.toList();
+ QCMakePropertyList newP2 = newProps2.toList();
+ qSort(newP);
+ qSort(newP2);
+ int row_count = 0;
+ foreach(QCMakeProperty p, newP)
+ {
+ this->insertRow(row_count);
+ this->setPropertyData(this->index(row_count, 0), p, true);
+ row_count++;
+ }
+ foreach(QCMakeProperty p, newP2)
+ {
+ this->insertRow(row_count);
+ this->setPropertyData(this->index(row_count, 0), p, false);
+ row_count++;
+ }
+ }
+ else if(this->View == GroupView)
+ {
+ QMap<QString, QCMakePropertyList> newPropsTree;
+ this->breakProperties(newProps, newPropsTree);
+ QMap<QString, QCMakePropertyList> newPropsTree2;
+ this->breakProperties(newProps2, newPropsTree2);
+
+ QStandardItem* root = this->invisibleRootItem();
+
+ foreach(QString key, newPropsTree.keys())
+ {
+ QCMakePropertyList props2 = newPropsTree[key];
+
+ QList<QStandardItem*> parentItems;
+ parentItems.append(
+ new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key)
+ );
+ parentItems.append(new QStandardItem());
+ parentItems[0]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
+ parentItems[1]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
+ parentItems[0]->setData(1, GroupRole);
+ parentItems[1]->setData(1, GroupRole);
+ root->appendRow(parentItems);
+
+ int num = props2.size();
+ for(int i=0; i<num; i++)
+ {
+ QCMakeProperty prop = props2[i];
+ QList<QStandardItem*> items;
+ items.append(new QStandardItem());
+ items.append(new QStandardItem());
+ parentItems[0]->appendRow(items);
+ this->setPropertyData(this->indexFromItem(items[0]), prop, true);
+ }
+ }
+
+ foreach(QString key, newPropsTree2.keys())
+ {
+ QCMakePropertyList props2 = newPropsTree2[key];
+
+ QStandardItem* parentItem =
+ new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key);
+ root->appendRow(parentItem);
+ parentItem->setData(1, GroupRole);
+
+ int num = props2.size();
+ for(int i=0; i<num; i++)
+ {
+ QCMakeProperty prop = props2[i];
+ QList<QStandardItem*> items;
+ items.append(new QStandardItem());
+ items.append(new QStandardItem());
+ parentItem->appendRow(items);
+ this->setPropertyData(this->indexFromItem(items[0]), prop, false);
+ }
+ }
+ }
+
+ this->blockSignals(b);
+ this->reset();
+}
+
+QCMakeCacheModel::ViewType QCMakeCacheModel::viewType() const
+{
+ return this->View;
+}
+
+void QCMakeCacheModel::setViewType(QCMakeCacheModel::ViewType t)
+{
+ this->View = t;
+
+ QCMakePropertyList props = this->properties();
+ QCMakePropertyList oldProps;
+ int numNew = this->NewPropertyCount;
+ int numTotal = props.count();
+ for(int i=numNew; i<numTotal; i++)
+ {
+ oldProps.append(props[i]);
+ }
+
+ bool b = this->blockSignals(true);
+ this->clear();
+ this->setProperties(oldProps);
+ this->setProperties(props);
+ this->blockSignals(b);
+ this->reset();
+}
+
+void QCMakeCacheModel::setPropertyData(const QModelIndex& idx1,
+ const QCMakeProperty& prop, bool isNew)
+{
+ QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
+
+ this->setData(idx1, prop.Key, Qt::DisplayRole);
+ this->setData(idx1, prop.Help, QCMakeCacheModel::HelpRole);
+ this->setData(idx1, prop.Type, QCMakeCacheModel::TypeRole);
+ this->setData(idx1, prop.Advanced, QCMakeCacheModel::AdvancedRole);
+
+ if(prop.Type == QCMakeProperty::BOOL)
+ {
+ int check = prop.Value.toBool() ? Qt::Checked : Qt::Unchecked;
+ this->setData(idx2, check, Qt::CheckStateRole);
+ }
+ else
+ {
+ this->setData(idx2, prop.Value, Qt::DisplayRole);
+ }
+ this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole);
+
+ if (!prop.Strings.isEmpty())
+ {
+ this->setData(idx1, prop.Strings, QCMakeCacheModel::StringsRole);
+ }
+
+ if(isNew)
+ {
+ this->setData(idx1, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
+ this->setData(idx2, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
+ }
+}
+
+void QCMakeCacheModel::getPropertyData(const QModelIndex& idx1,
+ QCMakeProperty& prop) const
+{
+ QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
+
+ prop.Key = this->data(idx1, Qt::DisplayRole).toString();
+ prop.Help = this->data(idx1, HelpRole).toString();
+ prop.Type = static_cast<QCMakeProperty::PropertyType>(this->data(idx1, TypeRole).toInt());
+ prop.Advanced = this->data(idx1, AdvancedRole).toBool();
+ prop.Strings = this->data(idx1, QCMakeCacheModel::StringsRole).toStringList();
+ if(prop.Type == QCMakeProperty::BOOL)
+ {
+ int check = this->data(idx2, Qt::CheckStateRole).toInt();
+ prop.Value = check == Qt::Checked;
+ }
+ else
+ {
+ prop.Value = this->data(idx2, Qt::DisplayRole).toString();
+ }
+}
+
+QString QCMakeCacheModel::prefix(const QString& s)
+{
+ QString prefix = s.section('_', 0, 0);
+ if(prefix == s)
+ {
+ prefix = QString();
+ }
+ return prefix;
+}
+
+void QCMakeCacheModel::breakProperties(const QSet<QCMakeProperty>& props,
+ QMap<QString, QCMakePropertyList>& result)
+{
+ QMap<QString, QCMakePropertyList> tmp;
+ // return a map of properties grouped by prefixes, and sorted
+ foreach(QCMakeProperty p, props)
+ {
+ QString prefix = QCMakeCacheModel::prefix(p.Key);
+ tmp[prefix].append(p);
+ }
+ // sort it and re-org any properties with only one sub item
+ QCMakePropertyList reorgProps;
+ QMap<QString, QCMakePropertyList>::iterator iter;
+ for(iter = tmp.begin(); iter != tmp.end();)
+ {
+ if(iter->count() == 1)
+ {
+ reorgProps.append((*iter)[0]);
+ iter = tmp.erase(iter);
+ }
+ else
+ {
+ qSort(*iter);
+ ++iter;
+ }
+ }
+ if(reorgProps.count())
+ {
+ tmp[QString()] += reorgProps;
+ }
+ result = tmp;
+}
+
+QCMakePropertyList QCMakeCacheModel::properties() const
+{
+ QCMakePropertyList props;
+
+ if(!this->rowCount())
+ {
+ return props;
+ }
+
+ QList<QModelIndex> idxs;
+ idxs.append(this->index(0,0));
+
+ // walk the entire model for property entries
+ // this works regardless of a flat view or a tree view
+ while(!idxs.isEmpty())
+ {
+ QModelIndex idx = idxs.last();
+ if(this->hasChildren(idx) && this->rowCount(idx))
+ {
+ idxs.append(this->index(0,0, idx));
+ }
+ else
+ {
+ if(!data(idx, GroupRole).toInt())
+ {
+ // get data
+ QCMakeProperty prop;
+ this->getPropertyData(idx, prop);
+ props.append(prop);
+ }
+
+ // go to the next in the tree
+ while(!idxs.isEmpty() && (
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) && QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
+ (idxs.last().row()+1) >= rowCount(idxs.last().parent()) ||
+#endif
+ !idxs.last().sibling(idxs.last().row()+1, 0).isValid()))
+ {
+ idxs.removeLast();
+ }
+ if(!idxs.isEmpty())
+ {
+ idxs.last() = idxs.last().sibling(idxs.last().row()+1, 0);
+ }
+ }
+ }
+
+ return props;
+}
+
+bool QCMakeCacheModel::insertProperty(QCMakeProperty::PropertyType t,
+ const QString& name, const QString& description,
+ const QVariant& value, bool advanced)
+{
+ QCMakeProperty prop;
+ prop.Key = name;
+ prop.Value = value;
+ prop.Help = description;
+ prop.Type = t;
+ prop.Advanced = advanced;
+
+ //insert at beginning
+ this->insertRow(0);
+ this->setPropertyData(this->index(0,0), prop, true);
+ this->NewPropertyCount++;
+ return true;
+}
+
+void QCMakeCacheModel::setEditEnabled(bool e)
+{
+ this->EditEnabled = e;
+}
+
+bool QCMakeCacheModel::editEnabled() const
+{
+ return this->EditEnabled;
+}
+
+int QCMakeCacheModel::newPropertyCount() const
+{
+ return this->NewPropertyCount;
+}
+
+Qt::ItemFlags QCMakeCacheModel::flags (const QModelIndex& idx) const
+{
+ Qt::ItemFlags f = QStandardItemModel::flags(idx);
+ if(!this->EditEnabled)
+ {
+ f &= ~Qt::ItemIsEditable;
+ return f;
+ }
+ if(QCMakeProperty::BOOL == this->data(idx, TypeRole).toInt())
+ {
+ f |= Qt::ItemIsUserCheckable;
+ }
+ return f;
+}
+
+QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const
+{
+ if(!this->hasChildren(idx) &&
+ this->data(idx, TypeRole).toInt() != QCMakeProperty::BOOL)
+ {
+ return this->index(idx.row(), 1, idx.parent());
+ }
+ return idx;
+}
+
+QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
+ : QItemDelegate(p), FileDialogFlag(false)
+{
+}
+
+void QCMakeCacheModelDelegate::setFileDialogFlag(bool f)
+{
+ this->FileDialogFlag = f;
+}
+
+QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
+ const QStyleOptionViewItem&, const QModelIndex& idx) const
+{
+ QModelIndex var = idx.sibling(idx.row(), 0);
+ int type = var.data(QCMakeCacheModel::TypeRole).toInt();
+ if(type == QCMakeProperty::BOOL)
+ {
+ return NULL;
+ }
+ else if(type == QCMakeProperty::PATH)
+ {
+ QCMakePathEditor* editor =
+ new QCMakePathEditor(p,
+ var.data(Qt::DisplayRole).toString());
+ QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
+ SLOT(setFileDialogFlag(bool)));
+ return editor;
+ }
+ else if(type == QCMakeProperty::FILEPATH)
+ {
+ QCMakeFilePathEditor* editor =
+ new QCMakeFilePathEditor(p,
+ var.data(Qt::DisplayRole).toString());
+ QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
+ SLOT(setFileDialogFlag(bool)));
+ return editor;
+ }
+ else if(type == QCMakeProperty::STRING &&
+ var.data(QCMakeCacheModel::StringsRole).isValid())
+ {
+ QCMakeComboBox* editor =
+ new QCMakeComboBox(p, var.data(QCMakeCacheModel::StringsRole).toStringList());
+ editor->setFrame(false);
+ return editor;
+ }
+
+ QLineEdit* editor = new QLineEdit(p);
+ editor->setFrame(false);
+ return editor;
+}
+
+bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model,
+ const QStyleOptionViewItem& option, const QModelIndex& index)
+{
+ Qt::ItemFlags flags = model->flags(index);
+ if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled)
+ || !(flags & Qt::ItemIsEnabled))
+ {
+ return false;
+ }
+
+ QVariant value = index.data(Qt::CheckStateRole);
+ if (!value.isValid())
+ {
+ return false;
+ }
+
+ if ((e->type() == QEvent::MouseButtonRelease)
+ || (e->type() == QEvent::MouseButtonDblClick))
+ {
+ // eat the double click events inside the check rect
+ if (e->type() == QEvent::MouseButtonDblClick)
+ {
+ return true;
+ }
+ }
+ else if (e->type() == QEvent::KeyPress)
+ {
+ if(static_cast<QKeyEvent*>(e)->key() != Qt::Key_Space &&
+ static_cast<QKeyEvent*>(e)->key() != Qt::Key_Select)
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+
+ Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
+ ? Qt::Unchecked : Qt::Checked);
+ bool success = model->setData(index, state, Qt::CheckStateRole);
+ if(success)
+ {
+ this->recordChange(model, index);
+ }
+ return success;
+}
+
+// Issue 205903 fixed in Qt 4.5.0.
+// Can remove this function and FileDialogFlag when minimum Qt version is 4.5
+bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* evt)
+{
+ // workaround for what looks like a bug in Qt on Mac OS X
+ // where it doesn't create a QWidget wrapper for the native file dialog
+ // so the Qt library ends up assuming the focus was lost to something else
+
+ if(evt->type() == QEvent::FocusOut && this->FileDialogFlag)
+ {
+ return false;
+ }
+ return QItemDelegate::eventFilter(object, evt);
+}
+
+void QCMakeCacheModelDelegate::setModelData(QWidget* editor,
+ QAbstractItemModel* model, const QModelIndex& index ) const
+{
+ QItemDelegate::setModelData(editor, model, index);
+ const_cast<QCMakeCacheModelDelegate*>(this)->recordChange(model, index);
+}
+
+QSize QCMakeCacheModelDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+ QSize sz = QItemDelegate::sizeHint(option, index);
+ QStyle *style = QApplication::style();
+
+ // increase to checkbox size
+ QStyleOptionButton opt;
+ opt.QStyleOption::operator=(option);
+ sz = sz.expandedTo(style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, NULL).size());
+
+ return sz;
+}
+
+QSet<QCMakeProperty> QCMakeCacheModelDelegate::changes() const
+{
+ return mChanges;
+}
+
+void QCMakeCacheModelDelegate::clearChanges()
+{
+ mChanges.clear();
+}
+
+void QCMakeCacheModelDelegate::recordChange(QAbstractItemModel* model, const QModelIndex& index)
+{
+ QModelIndex idx = index;
+ QAbstractItemModel* mymodel = model;
+ while(qobject_cast<QAbstractProxyModel*>(mymodel))
+ {
+ idx = static_cast<QAbstractProxyModel*>(mymodel)->mapToSource(idx);
+ mymodel = static_cast<QAbstractProxyModel*>(mymodel)->sourceModel();
+ }
+ QCMakeCacheModel* cache_model = qobject_cast<QCMakeCacheModel*>(mymodel);
+ if(cache_model && idx.isValid())
+ {
+ QCMakeProperty prop;
+ idx = idx.sibling(idx.row(), 0);
+ cache_model->getPropertyData(idx, prop);
+
+ // clean out an old one
+ QSet<QCMakeProperty>::iterator iter = mChanges.find(prop);
+ if(iter != mChanges.end())
+ {
+ mChanges.erase(iter);
+ }
+ // now add the new item
+ mChanges.insert(prop);
+ }
+}
+
diff --git a/Source/QtDialog/QCMakeCacheView.h b/Source/QtDialog/QCMakeCacheView.h
new file mode 100644
index 0000000000..41f0bd87cb
--- /dev/null
+++ b/Source/QtDialog/QCMakeCacheView.h
@@ -0,0 +1,172 @@
+/*============================================================================
+ 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 QCMakeCacheView_h
+#define QCMakeCacheView_h
+
+#include "QCMake.h"
+#include <QTreeView>
+#include <QSet>
+#include <QStandardItemModel>
+#include <QItemDelegate>
+
+class QSortFilterProxyModel;
+class QCMakeCacheModel;
+class QCMakeAdvancedFilter;
+
+/// Qt view class for cache properties
+class QCMakeCacheView : public QTreeView
+{
+ Q_OBJECT
+public:
+ QCMakeCacheView(QWidget* p);
+
+ // retrieve the QCMakeCacheModel storing all the pointers
+ // this isn't necessarily the model one would get from model()
+ QCMakeCacheModel* cacheModel() const;
+
+ // get whether to show advanced entries
+ bool showAdvanced() const;
+
+ QSize sizeHint() const { return QSize(200,200); }
+
+public slots:
+ // set whether to show advanced entries
+ void setShowAdvanced(bool);
+ // set the search filter string. any property key or value not matching will
+ // be filtered out
+ void setSearchFilter(const QString&);
+
+protected:
+ QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
+ bool event(QEvent* e);
+ QCMakeCacheModel* CacheModel;
+ QCMakeAdvancedFilter* AdvancedFilter;
+ QSortFilterProxyModel* SearchFilter;
+};
+
+/// Qt model class for cache properties
+class QCMakeCacheModel : public QStandardItemModel
+{
+ Q_OBJECT
+public:
+ QCMakeCacheModel(QObject* parent);
+ ~QCMakeCacheModel();
+
+ // roles used to retrieve extra data such has help strings, types of
+ // properties, and the advanced flag
+ enum { HelpRole = Qt::ToolTipRole,
+ TypeRole = Qt::UserRole,
+ AdvancedRole,
+ StringsRole,
+ GroupRole
+ };
+
+ enum ViewType { FlatView, GroupView };
+
+public slots:
+ // set a list of properties. This list will be sorted and grouped according
+ // to prefix. Any property that existed already and which is found in this
+ // list of properties to set will become an old property. All others will
+ // become new properties and be marked red.
+ void setProperties(const QCMakePropertyList& props);
+
+ // set whether to show new properties in red
+ void setShowNewProperties(bool);
+
+ // clear everything from the model
+ void clear();
+
+ // set flag whether the model can currently be edited.
+ void setEditEnabled(bool);
+
+ // insert a new property at a row specifying all the information about the
+ // property
+ bool insertProperty(QCMakeProperty::PropertyType t,
+ const QString& name, const QString& description,
+ const QVariant& value, bool advanced);
+
+ // set the view type
+ void setViewType(ViewType t);
+ ViewType viewType() const;
+
+public:
+ // get the properties
+ QCMakePropertyList properties() const;
+
+ // editing enabled
+ bool editEnabled() const;
+
+ // returns how many new properties there are
+ int newPropertyCount() const;
+
+ // return flags (overloaded to modify flag based on EditEnabled flag)
+ Qt::ItemFlags flags (const QModelIndex& index) const;
+ QModelIndex buddy(const QModelIndex& idx) const;
+
+ // get the data in the model for this property
+ void getPropertyData(const QModelIndex& idx1,
+ QCMakeProperty& prop) const;
+
+protected:
+ bool EditEnabled;
+ int NewPropertyCount;
+ bool ShowNewProperties;
+ ViewType View;
+
+ // set the data in the model for this property
+ void setPropertyData(const QModelIndex& idx1,
+ const QCMakeProperty& p, bool isNew);
+
+ // breaks up he property list into groups
+ // where each group has the same prefix up to the first underscore
+ static void breakProperties(const QSet<QCMakeProperty>& props,
+ QMap<QString, QCMakePropertyList>& result);
+
+ // gets the prefix of a string up to the first _
+ static QString prefix(const QString& s);
+
+};
+
+/// Qt delegate class for interaction (or other customization)
+/// with cache properties
+class QCMakeCacheModelDelegate : public QItemDelegate
+{
+ Q_OBJECT
+public:
+ QCMakeCacheModelDelegate(QObject* p);
+ /// create our own editors for cache properties
+ QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
+ const QModelIndex& index ) const;
+ bool editorEvent (QEvent* event, QAbstractItemModel* model,
+ const QStyleOptionViewItem& option, const QModelIndex& index);
+ bool eventFilter(QObject* object, QEvent* event);
+ void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const;
+ QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
+
+ QSet<QCMakeProperty> changes() const;
+ void clearChanges();
+
+protected slots:
+ void setFileDialogFlag(bool);
+protected:
+ bool FileDialogFlag;
+ // record a change to an item in the model.
+ // this simply saves the item in the set of changes
+ void recordChange(QAbstractItemModel* model, const QModelIndex& index);
+
+ // properties changed by user via this delegate
+ QSet<QCMakeProperty> mChanges;
+};
+
+#endif
+
diff --git a/Source/QtDialog/QCMakeWidgets.cxx b/Source/QtDialog/QCMakeWidgets.cxx
new file mode 100644
index 0000000000..41f98b5d24
--- /dev/null
+++ b/Source/QtDialog/QCMakeWidgets.cxx
@@ -0,0 +1,136 @@
+/*============================================================================
+ 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 "QCMakeWidgets.h"
+
+#include <QDirModel>
+#include <QFileInfo>
+#include <QFileDialog>
+#include <QToolButton>
+#include <QResizeEvent>
+
+QCMakeFileEditor::QCMakeFileEditor(QWidget* p, const QString& var)
+ : QLineEdit(p), Variable(var)
+{
+ this->ToolButton = new QToolButton(this);
+ this->ToolButton->setText("...");
+ this->ToolButton->setCursor(QCursor(Qt::ArrowCursor));
+ QObject::connect(this->ToolButton, SIGNAL(clicked(bool)),
+ this, SLOT(chooseFile()));
+}
+
+QCMakeFilePathEditor::QCMakeFilePathEditor(QWidget* p, const QString& var)
+ : QCMakeFileEditor(p, var)
+{
+ this->setCompleter(new QCMakeFileCompleter(this, false));
+}
+
+QCMakePathEditor::QCMakePathEditor(QWidget* p, const QString& var)
+ : QCMakeFileEditor(p, var)
+{
+ this->setCompleter(new QCMakeFileCompleter(this, true));
+}
+
+void QCMakeFileEditor::resizeEvent(QResizeEvent* e)
+{
+ // make the tool button fit on the right side
+ int h = e->size().height();
+ // move the line edit to make room for the tool button
+ this->setContentsMargins(0, 0, h, 0);
+ // put the tool button in its place
+ this->ToolButton->resize(h, h);
+ this->ToolButton->move(this->width() - h, 0);
+}
+
+void QCMakeFilePathEditor::chooseFile()
+{
+ // choose a file and set it
+ QString path;
+ QFileInfo info(this->text());
+ QString title;
+ if(this->Variable.isEmpty())
+ {
+ title = tr("Select File");
+ }
+ else
+ {
+ title = tr("Select File for %1");
+ title = title.arg(this->Variable);
+ }
+ this->fileDialogExists(true);
+ path = QFileDialog::getOpenFileName(this, title, info.absolutePath(),
+ QString(), NULL, QFileDialog::DontResolveSymlinks);
+ this->fileDialogExists(false);
+
+ if(!path.isEmpty())
+ {
+ this->setText(QDir::fromNativeSeparators(path));
+ }
+}
+
+void QCMakePathEditor::chooseFile()
+{
+ // choose a file and set it
+ QString path;
+ QString title;
+ if(this->Variable.isEmpty())
+ {
+ title = tr("Select Path");
+ }
+ else
+ {
+ title = tr("Select Path for %1");
+ title = title.arg(this->Variable);
+ }
+ this->fileDialogExists(true);
+ path = QFileDialog::getExistingDirectory(this, title, this->text(),
+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+ this->fileDialogExists(false);
+ if(!path.isEmpty())
+ {
+ this->setText(QDir::fromNativeSeparators(path));
+ }
+}
+
+// use same QDirModel for all completers
+static QDirModel* fileDirModel()
+{
+ static QDirModel* m = NULL;
+ if(!m)
+ {
+ m = new QDirModel();
+ }
+ return m;
+}
+static QDirModel* pathDirModel()
+{
+ static QDirModel* m = NULL;
+ if(!m)
+ {
+ m = new QDirModel();
+ m->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot);
+ }
+ return m;
+}
+
+QCMakeFileCompleter::QCMakeFileCompleter(QObject* o, bool dirs)
+ : QCompleter(o)
+{
+ QDirModel* m = dirs ? pathDirModel() : fileDirModel();
+ this->setModel(m);
+}
+
+QString QCMakeFileCompleter::pathFromIndex(const QModelIndex& idx) const
+{
+ return QDir::fromNativeSeparators(QCompleter::pathFromIndex(idx));
+}
+
diff --git a/Source/QtDialog/QCMakeWidgets.h b/Source/QtDialog/QCMakeWidgets.h
new file mode 100644
index 0000000000..8f58df2bb5
--- /dev/null
+++ b/Source/QtDialog/QCMakeWidgets.h
@@ -0,0 +1,87 @@
+/*============================================================================
+ 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 QCMakeWidgets_h
+#define QCMakeWidgets_h
+
+#include <QLineEdit>
+#include <QComboBox>
+#include <QCompleter>
+class QToolButton;
+
+// common widgets for Qt based CMake
+
+/// Editor widget for editing paths or file paths
+class QCMakeFileEditor : public QLineEdit
+{
+ Q_OBJECT
+public:
+ QCMakeFileEditor(QWidget* p, const QString& var);
+protected slots:
+ virtual void chooseFile() = 0;
+signals:
+ void fileDialogExists(bool);
+protected:
+ void resizeEvent(QResizeEvent* e);
+ QToolButton* ToolButton;
+ QString Variable;
+};
+
+/// editor widget for editing files
+class QCMakePathEditor : public QCMakeFileEditor
+{
+ Q_OBJECT
+public:
+ QCMakePathEditor(QWidget* p = NULL, const QString& var = QString());
+ void chooseFile();
+};
+
+/// editor widget for editing paths
+class QCMakeFilePathEditor : public QCMakeFileEditor
+{
+ Q_OBJECT
+public:
+ QCMakeFilePathEditor(QWidget* p = NULL, const QString& var = QString());
+ void chooseFile();
+};
+
+/// completer class that returns native cmake paths
+class QCMakeFileCompleter : public QCompleter
+{
+ Q_OBJECT
+public:
+ QCMakeFileCompleter(QObject* o, bool dirs);
+ virtual QString pathFromIndex(const QModelIndex& idx) const;
+};
+
+// editor for strings
+class QCMakeComboBox : public QComboBox
+{
+ Q_OBJECT
+ Q_PROPERTY(QString value READ currentText WRITE setValue USER true);
+public:
+ QCMakeComboBox(QWidget* p, QStringList strings) : QComboBox(p)
+ {
+ this->addItems(strings);
+ }
+ void setValue(const QString& v)
+ {
+ int i = this->findText(v);
+ if(i != -1)
+ {
+ this->setCurrentIndex(i);
+ }
+ }
+};
+
+#endif
+
diff --git a/Source/QtDialog/QMacInstallDialog.cxx b/Source/QtDialog/QMacInstallDialog.cxx
new file mode 100644
index 0000000000..8b8c5319f2
--- /dev/null
+++ b/Source/QtDialog/QMacInstallDialog.cxx
@@ -0,0 +1,121 @@
+#include "QMacInstallDialog.h"
+#include <QMessageBox>
+#include "cmSystemTools.h"
+#include <iostream>
+#include <QFileDialog>
+#include "ui_MacInstallDialog.h"
+
+class QMacInstallDialog::QMacInstallDialogInternals : public Ui::Dialog
+{
+public:
+};
+
+QMacInstallDialog::QMacInstallDialog(QWidget*w)
+ :QDialog(w)
+{
+ this->Internals = new QMacInstallDialogInternals;
+ this->Internals->setupUi(this);
+ QObject::connect(this->Internals->choosePathButton, SIGNAL(pressed()),
+ this, SLOT(ShowBrowser()));
+ QObject::connect(this->Internals->skipInstallButton, SIGNAL(pressed()),
+ this, SLOT(SkipInstall()));
+ QObject::connect(this->Internals->doInstallButton, SIGNAL(pressed()),
+ this, SLOT(DoInstall()));
+ this->Internals->InstallPrefix->setText("/usr/bin/");
+
+}
+
+QMacInstallDialog::~QMacInstallDialog()
+{
+ delete this->Internals;
+}
+
+void QMacInstallDialog::DoInstall()
+{
+ QDir installDir(this->Internals->InstallPrefix->text());
+ QString installTo = installDir.path();
+ if(!cmSystemTools::FileExists(installTo.toLocal8Bit().data()))
+ {
+ QString message = tr("Build install does not exist, "
+ "should I create it?\n\n"
+ "Directory: ");
+ message += installDir.path();
+ QString title = tr("Create Directory");
+ QMessageBox::StandardButton btn;
+ btn = QMessageBox::information(this, title, message,
+ QMessageBox::Yes | QMessageBox::No);
+ if(btn == QMessageBox::Yes)
+ {
+ cmSystemTools::MakeDirectory(installTo.toLocal8Bit().data());
+ }
+ }
+ QDir cmExecDir(QApplication::applicationDirPath());
+ cmExecDir.cd("../bin");
+ QFileInfoList list = cmExecDir.entryInfoList();
+ for (int i = 0; i < list.size(); ++i)
+ {
+ QFileInfo fileInfo = list.at(i);
+ QString filename = fileInfo.fileName();
+ if(filename.size() && filename[0] == '.')
+ {
+ continue;
+ }
+ QString file = fileInfo.absoluteFilePath();
+ QString newName = installTo;
+ newName += "/";
+ newName += filename;
+ // Remove the old files
+ if(cmSystemTools::FileExists(newName.toLocal8Bit().data()))
+ {
+ std::cout << "rm [" << newName.toLocal8Bit().data() << "]\n";
+ if(!cmSystemTools::RemoveFile(newName.toLocal8Bit().data()))
+ {
+ QString message = tr("Failed to remove file "
+ "installation may be incomplete: ");
+ message += newName;
+ QString title = tr("Error Removing file");
+ QMessageBox::StandardButton btn =
+ QMessageBox::critical(this, title, message,
+ QMessageBox::Ok|QMessageBox::Abort);
+ if(btn == QMessageBox::Abort)
+ {
+ return;
+ }
+ }
+ }
+ std::cout << "ln -s [" << file.toLocal8Bit().data() << "] [";
+ std::cout << newName.toLocal8Bit().data() << "]\n";
+ if(!cmSystemTools::CreateSymlink(file.toLocal8Bit().data(),
+ newName.toLocal8Bit().data()))
+ {
+ QString message = tr("Failed create symlink "
+ "installation may be incomplete: ");
+ message += newName;
+ QString title = tr("Error Creating Symlink");
+ QMessageBox::StandardButton btn =
+ QMessageBox::critical(this, title, message,
+ QMessageBox::Ok|QMessageBox::Abort);
+ if(btn == QMessageBox::Abort)
+ {
+ return;
+ }
+ }
+ }
+ this->done(0);
+}
+
+void QMacInstallDialog::SkipInstall()
+{
+ this->done(0);
+}
+
+
+void QMacInstallDialog::ShowBrowser()
+{
+ QString dir = QFileDialog::getExistingDirectory(this,
+ tr("Enter Install Prefix"), this->Internals->InstallPrefix->text());
+ if(!dir.isEmpty())
+ {
+ this->Internals->InstallPrefix->setText(dir);
+ }
+}
diff --git a/Source/QtDialog/QMacInstallDialog.h b/Source/QtDialog/QMacInstallDialog.h
new file mode 100644
index 0000000000..efe67dfaf4
--- /dev/null
+++ b/Source/QtDialog/QMacInstallDialog.h
@@ -0,0 +1,20 @@
+#ifndef QMacInstallDialog_h
+#define QMacInstallDialog_h
+#include <QDialog>
+
+class QMacInstallDialog : public QDialog
+{
+ Q_OBJECT;
+public:
+ QMacInstallDialog(QWidget*w);
+ ~QMacInstallDialog();
+private slots:
+ void ShowBrowser();
+ void SkipInstall();
+ void DoInstall();
+private:
+ class QMacInstallDialogInternals;
+ QMacInstallDialogInternals* Internals;
+};
+
+#endif
diff --git a/Source/QtDialog/QtDialogCPack.cmake.in b/Source/QtDialog/QtDialogCPack.cmake.in
new file mode 100644
index 0000000000..7ae8605481
--- /dev/null
+++ b/Source/QtDialog/QtDialogCPack.cmake.in
@@ -0,0 +1,15 @@
+set(IS_APPLE @APPLE@)
+set(CMAKE_PACKAGE_QTGUI @CMAKE_PACKAGE_QTGUI@)
+
+if(CMAKE_PACKAGE_QTGUI)
+ set(CPACK_PACKAGE_EXECUTABLES "cmake-gui" "CMake (cmake-gui)" ${CPACK_PACKAGE_EXECUTABLES})
+ set(CPACK_CREATE_DESKTOP_LINKS "cmake-gui" ${CPACK_CREATE_DESKTOP_LINKS})
+ if(IS_APPLE)
+ # for apple install we set the install prefix to
+ # / and then install
+ # cmake into the bundle for cmake-gui and must use DESTDIR
+ set(CPACK_SET_DESTDIR TRUE)
+ endif()
+endif()
+
+
diff --git a/Source/QtDialog/cmakecache.xml b/Source/QtDialog/cmakecache.xml
new file mode 100644
index 0000000000..a13b5b19c4
--- /dev/null
+++ b/Source/QtDialog/cmakecache.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
+ <mime-type type="application/x-cmakecache">
+ <comment>CMake cache file</comment>
+ <glob pattern="CMakeCache.txt"/>
+ <sub-class-of type="text/plain"/>
+ </mime-type>
+</mime-info>
diff --git a/Source/QtIFW/cmake.org.html b/Source/QtIFW/cmake.org.html
new file mode 100644
index 0000000000..cf5649db6d
--- /dev/null
+++ b/Source/QtIFW/cmake.org.html
@@ -0,0 +1,7 @@
+<html>
+<head>
+<meta http-equiv="Refresh" content="0; url=http://cmake.org/" />
+</head>
+<body>
+</body>
+</html>
diff --git a/Source/QtIFW/installscript.qs.in b/Source/QtIFW/installscript.qs.in
new file mode 100644
index 0000000000..549161121a
--- /dev/null
+++ b/Source/QtIFW/installscript.qs.in
@@ -0,0 +1,24 @@
+function Component()
+{
+ // default constructor
+}
+
+Component.prototype.createOperations = function()
+{
+ // call default implementation to actually install applications!
+ component.createOperations();
+
+ // Create shortcut
+ if (installer.value("os") === "win") {
+
+@_CPACK_IFW_SHORTCUT_OPTIONAL@
+
+ component.addOperation("CreateShortcut",
+ installer.value("TargetDir") + "/cmake.org.html",
+ installer.value("StartMenuDir") + "/CMake Web Site.lnk");
+
+ component.addOperation("CreateShortcut",
+ installer.value("TargetDir") + "/uninstall.exe",
+ installer.value("StartMenuDir") + "/Uninstall.lnk");
+ }
+}
diff --git a/Source/cmAddCompileOptionsCommand.cxx b/Source/cmAddCompileOptionsCommand.cxx
new file mode 100644
index 0000000000..a6c3c005cf
--- /dev/null
+++ b/Source/cmAddCompileOptionsCommand.cxx
@@ -0,0 +1,28 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmAddCompileOptionsCommand.h"
+
+bool cmAddCompileOptionsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ return true;
+ }
+
+ for(std::vector<std::string>::const_iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ this->Makefile->AddCompileOption(i->c_str());
+ }
+ return true;
+}
diff --git a/Source/cmAddCompileOptionsCommand.h b/Source/cmAddCompileOptionsCommand.h
new file mode 100644
index 0000000000..f147ec04ef
--- /dev/null
+++ b/Source/cmAddCompileOptionsCommand.h
@@ -0,0 +1,43 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmAddCompileOptionsCommand_h
+#define cmAddCompileOptionsCommand_h
+
+#include "cmCommand.h"
+
+class cmAddCompileOptionsCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddCompileOptionsCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "add_compile_options";}
+
+ cmTypeMacro(cmAddCompileOptionsCommand, cmCommand);
+};
+
+#endif
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx
new file mode 100644
index 0000000000..6a955506dd
--- /dev/null
+++ b/Source/cmAddCustomCommandCommand.cxx
@@ -0,0 +1,421 @@
+/*============================================================================
+ 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 "cmAddCustomCommandCommand.h"
+
+#include "cmTarget.h"
+
+#include "cmSourceFile.h"
+
+// cmAddCustomCommandCommand
+bool cmAddCustomCommandCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ /* Let's complain at the end of this function about the lack of a particular
+ arg. For the moment, let's say that COMMAND, and either TARGET or SOURCE
+ are required.
+ */
+ if (args.size() < 4)
+ {
+ this->SetError("called with wrong number of arguments.");
+ return false;
+ }
+
+ std::string source, target, main_dependency, working;
+ std::string comment_buffer;
+ const char* comment = 0;
+ std::vector<std::string> depends, outputs, output;
+ bool verbatim = false;
+ bool append = false;
+ std::string implicit_depends_lang;
+ cmCustomCommand::ImplicitDependsList implicit_depends;
+
+ // Accumulate one command line at a time.
+ cmCustomCommandLine currentLine;
+
+ // Save all command lines.
+ cmCustomCommandLines commandLines;
+
+ cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
+
+ enum tdoing {
+ doing_source,
+ doing_command,
+ doing_target,
+ doing_depends,
+ doing_implicit_depends_lang,
+ doing_implicit_depends_file,
+ doing_main_dependency,
+ doing_output,
+ doing_outputs,
+ doing_comment,
+ doing_working_directory,
+ doing_nothing
+ };
+
+ tdoing doing = doing_nothing;
+
+ for (unsigned int j = 0; j < args.size(); ++j)
+ {
+ std::string const& copy = args[j];
+
+ if(copy == "SOURCE")
+ {
+ doing = doing_source;
+ }
+ else if(copy == "COMMAND")
+ {
+ doing = doing_command;
+
+ // Save the current command before starting the next command.
+ if(!currentLine.empty())
+ {
+ commandLines.push_back(currentLine);
+ currentLine.clear();
+ }
+ }
+ else if(copy == "PRE_BUILD")
+ {
+ cctype = cmTarget::PRE_BUILD;
+ }
+ else if(copy == "PRE_LINK")
+ {
+ cctype = cmTarget::PRE_LINK;
+ }
+ else if(copy == "POST_BUILD")
+ {
+ cctype = cmTarget::POST_BUILD;
+ }
+ else if(copy == "VERBATIM")
+ {
+ verbatim = true;
+ }
+ else if(copy == "APPEND")
+ {
+ append = true;
+ }
+ else if(copy == "TARGET")
+ {
+ doing = doing_target;
+ }
+ else if(copy == "ARGS")
+ {
+ // Ignore this old keyword.
+ }
+ else if (copy == "DEPENDS")
+ {
+ doing = doing_depends;
+ }
+ else if (copy == "OUTPUTS")
+ {
+ doing = doing_outputs;
+ }
+ else if (copy == "OUTPUT")
+ {
+ doing = doing_output;
+ }
+ else if (copy == "WORKING_DIRECTORY")
+ {
+ doing = doing_working_directory;
+ }
+ else if (copy == "MAIN_DEPENDENCY")
+ {
+ doing = doing_main_dependency;
+ }
+ else if (copy == "IMPLICIT_DEPENDS")
+ {
+ doing = doing_implicit_depends_lang;
+ }
+ else if (copy == "COMMENT")
+ {
+ doing = doing_comment;
+ }
+ else
+ {
+ std::string filename;
+ switch (doing)
+ {
+ case doing_output:
+ case doing_outputs:
+ if (!cmSystemTools::FileIsFullPath(copy.c_str()))
+ {
+ // This is an output to be generated, so it should be
+ // under the build tree. CMake 2.4 placed this under the
+ // source tree. However the only case that this change
+ // will break is when someone writes
+ //
+ // add_custom_command(OUTPUT out.txt ...)
+ //
+ // and later references "${CMAKE_CURRENT_SOURCE_DIR}/out.txt".
+ // This is fairly obscure so we can wait for someone to
+ // complain.
+ filename = this->Makefile->GetCurrentOutputDirectory();
+ filename += "/";
+ }
+ filename += copy;
+ cmSystemTools::ConvertToUnixSlashes(filename);
+ break;
+ case doing_source:
+ // We do not want to convert the argument to SOURCE because
+ // that option is only available for backward compatibility.
+ // Old-style use of this command may use the SOURCE==TARGET
+ // trick which we must preserve. If we convert the source
+ // to a full path then it will no longer equal the target.
+ default:
+ break;
+ }
+
+ if (cmSystemTools::FileIsFullPath(filename.c_str()))
+ {
+ filename = cmSystemTools::CollapseFullPath(filename);
+ }
+ switch (doing)
+ {
+ case doing_working_directory:
+ working = copy;
+ break;
+ case doing_source:
+ source = copy;
+ break;
+ case doing_output:
+ output.push_back(filename);
+ break;
+ case doing_main_dependency:
+ main_dependency = copy;
+ break;
+ case doing_implicit_depends_lang:
+ implicit_depends_lang = copy;
+ doing = doing_implicit_depends_file;
+ break;
+ case doing_implicit_depends_file:
+ {
+ // An implicit dependency starting point is also an
+ // explicit dependency.
+ std::string dep = copy;
+ cmSystemTools::ConvertToUnixSlashes(dep);
+ depends.push_back(dep);
+
+ // Add the implicit dependency language and file.
+ cmCustomCommand::ImplicitDependsPair
+ entry(implicit_depends_lang, dep);
+ implicit_depends.push_back(entry);
+
+ // Switch back to looking for a language.
+ doing = doing_implicit_depends_lang;
+ }
+ break;
+ case doing_command:
+ currentLine.push_back(copy);
+ break;
+ case doing_target:
+ target = copy;
+ break;
+ case doing_depends:
+ {
+ std::string dep = copy;
+ cmSystemTools::ConvertToUnixSlashes(dep);
+ depends.push_back(dep);
+ }
+ break;
+ case doing_outputs:
+ outputs.push_back(filename);
+ break;
+ case doing_comment:
+ comment_buffer = copy;
+ comment = comment_buffer.c_str();
+ break;
+ default:
+ this->SetError("Wrong syntax. Unknown type of argument.");
+ return false;
+ }
+ }
+ }
+
+ // Store the last command line finished.
+ if(!currentLine.empty())
+ {
+ commandLines.push_back(currentLine);
+ currentLine.clear();
+ }
+
+ // At this point we could complain about the lack of arguments. For
+ // the moment, let's say that COMMAND, TARGET are always required.
+ if(output.empty() && target.empty())
+ {
+ this->SetError("Wrong syntax. A TARGET or OUTPUT must be specified.");
+ return false;
+ }
+
+ if(source.empty() && !target.empty() && !output.empty())
+ {
+ this->SetError(
+ "Wrong syntax. A TARGET and OUTPUT can not both be specified.");
+ return false;
+ }
+ if(append && output.empty())
+ {
+ this->SetError("given APPEND option with no OUTPUT.");
+ return false;
+ }
+
+ // Make sure the output names and locations are safe.
+ if(!this->CheckOutputs(output) || !this->CheckOutputs(outputs))
+ {
+ return false;
+ }
+
+ // Check for an append request.
+ if(append)
+ {
+ // Lookup an existing command.
+ if(cmSourceFile* sf =
+ this->Makefile->GetSourceFileWithOutput(output[0]))
+ {
+ if(cmCustomCommand* cc = sf->GetCustomCommand())
+ {
+ cc->AppendCommands(commandLines);
+ cc->AppendDepends(depends);
+ cc->AppendImplicitDepends(implicit_depends);
+ return true;
+ }
+ }
+
+ // No command for this output exists.
+ cmOStringStream e;
+ e << "given APPEND option with output \"" << output[0]
+ << "\" which is not already a custom command output.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Convert working directory to a full path.
+ if(!working.empty())
+ {
+ const char* build_dir = this->Makefile->GetCurrentOutputDirectory();
+ working = cmSystemTools::CollapseFullPath(working.c_str(), build_dir);
+ }
+
+ // Choose which mode of the command to use.
+ bool escapeOldStyle = !verbatim;
+ if(source.empty() && output.empty())
+ {
+ // Source is empty, use the target.
+ std::vector<std::string> no_depends;
+ this->Makefile->AddCustomCommandToTarget(target, no_depends,
+ commandLines, cctype,
+ comment, working.c_str(),
+ escapeOldStyle);
+ }
+ else if(target.empty())
+ {
+ // Target is empty, use the output.
+ this->Makefile->AddCustomCommandToOutput(output, depends,
+ main_dependency,
+ commandLines, comment,
+ working.c_str(), false,
+ escapeOldStyle);
+
+ // Add implicit dependency scanning requests if any were given.
+ if(!implicit_depends.empty())
+ {
+ bool okay = false;
+ if(cmSourceFile* sf =
+ this->Makefile->GetSourceFileWithOutput(output[0]))
+ {
+ if(cmCustomCommand* cc = sf->GetCustomCommand())
+ {
+ okay = true;
+ cc->SetImplicitDepends(implicit_depends);
+ }
+ }
+ if(!okay)
+ {
+ cmOStringStream e;
+ e << "could not locate source file with a custom command producing \""
+ << output[0] << "\" even though this command tried to create it!";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ }
+ else
+ {
+ bool issueMessage = true;
+ cmOStringStream e;
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0050))
+ {
+ case cmPolicies::WARN:
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0050)) << "\n";
+ break;
+ case cmPolicies::OLD:
+ issueMessage = false;
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW:
+ messageType = cmake::FATAL_ERROR;
+ break;
+ }
+
+ if (issueMessage)
+ {
+ e << "The SOURCE signatures of add_custom_command are no longer "
+ "supported.";
+ this->Makefile->IssueMessage(messageType, e.str());
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return false;
+ }
+ }
+
+ // Use the old-style mode for backward compatibility.
+ this->Makefile->AddCustomCommandOldStyle(target, outputs, depends,
+ source, commandLines,
+ comment);
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmAddCustomCommandCommand
+::CheckOutputs(const std::vector<std::string>& outputs)
+{
+ for(std::vector<std::string>::const_iterator o = outputs.begin();
+ o != outputs.end(); ++o)
+ {
+ // Make sure the file will not be generated into the source
+ // directory during an out of source build.
+ if(!this->Makefile->CanIWriteThisFile(o->c_str()))
+ {
+ std::string e = "attempted to have a file \"" + *o +
+ "\" in a source directory as an output of custom command.";
+ this->SetError(e);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+
+ // Make sure the output file name has no invalid characters.
+ std::string::size_type pos = o->find_first_of("#<>");
+ if(pos != o->npos)
+ {
+ cmOStringStream msg;
+ msg << "called with OUTPUT containing a \"" << (*o)[pos]
+ << "\". This character is not allowed.";
+ this->SetError(msg.str());
+ return false;
+ }
+ }
+ return true;
+}
diff --git a/Source/cmAddCustomCommandCommand.h b/Source/cmAddCustomCommandCommand.h
new file mode 100644
index 0000000000..1d6ddb2880
--- /dev/null
+++ b/Source/cmAddCustomCommandCommand.h
@@ -0,0 +1,52 @@
+/*============================================================================
+ 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 cmAddCustomCommandCommand_h
+#define cmAddCustomCommandCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmAddCustomCommandCommand
+ * \brief cmAddCustomCommandCommand defines a new command (rule) that can
+ * be executed within the build process
+ *
+ */
+
+class cmAddCustomCommandCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddCustomCommandCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "add_custom_command";}
+
+ cmTypeMacro(cmAddCustomCommandCommand, cmCommand);
+protected:
+ bool CheckOutputs(const std::vector<std::string>& outputs);
+};
+
+
+#endif
diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx
new file mode 100644
index 0000000000..2fb0eb369c
--- /dev/null
+++ b/Source/cmAddCustomTargetCommand.cxx
@@ -0,0 +1,235 @@
+/*============================================================================
+ 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 "cmAddCustomTargetCommand.h"
+
+#include "cmGeneratorExpression.h"
+#include "cmGlobalGenerator.h"
+
+// cmAddCustomTargetCommand
+bool cmAddCustomTargetCommand
+::InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus&)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::string targetName = args[0];
+
+ // Check the target name.
+ if(targetName.find_first_of("/\\") != targetName.npos)
+ {
+ cmOStringStream e;
+ e << "called with invalid target name \"" << targetName
+ << "\". Target names may not contain a slash. "
+ << "Use ADD_CUSTOM_COMMAND to generate files.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Accumulate one command line at a time.
+ cmCustomCommandLine currentLine;
+
+ // Save all command lines.
+ cmCustomCommandLines commandLines;
+
+ // Accumulate dependencies.
+ std::vector<std::string> depends;
+ std::string working_directory;
+ bool verbatim = false;
+ std::string comment_buffer;
+ const char* comment = 0;
+ std::vector<std::string> sources;
+
+ // Keep track of parser state.
+ enum tdoing {
+ doing_command,
+ doing_depends,
+ doing_working_directory,
+ doing_comment,
+ doing_source,
+ doing_verbatim
+ };
+ tdoing doing = doing_command;
+
+ // Look for the ALL option.
+ bool excludeFromAll = true;
+ unsigned int start = 1;
+ if(args.size() > 1)
+ {
+ if(args[1] == "ALL")
+ {
+ excludeFromAll = false;
+ start = 2;
+ }
+ }
+
+ // Parse the rest of the arguments.
+ for(unsigned int j = start; j < args.size(); ++j)
+ {
+ std::string const& copy = args[j];
+
+ if(copy == "DEPENDS")
+ {
+ doing = doing_depends;
+ }
+ else if(copy == "WORKING_DIRECTORY")
+ {
+ doing = doing_working_directory;
+ }
+ else if(copy == "VERBATIM")
+ {
+ doing = doing_verbatim;
+ verbatim = true;
+ }
+ else if (copy == "COMMENT")
+ {
+ doing = doing_comment;
+ }
+ else if(copy == "COMMAND")
+ {
+ doing = doing_command;
+
+ // Save the current command before starting the next command.
+ if(!currentLine.empty())
+ {
+ commandLines.push_back(currentLine);
+ currentLine.clear();
+ }
+ }
+ else if(copy == "SOURCES")
+ {
+ doing = doing_source;
+ }
+ else
+ {
+ switch (doing)
+ {
+ case doing_working_directory:
+ working_directory = copy;
+ break;
+ case doing_command:
+ currentLine.push_back(copy);
+ break;
+ case doing_depends:
+ {
+ std::string dep = copy;
+ cmSystemTools::ConvertToUnixSlashes(dep);
+ depends.push_back(dep);
+ }
+ break;
+ case doing_comment:
+ comment_buffer = copy;
+ comment = comment_buffer.c_str();
+ break;
+ case doing_source:
+ sources.push_back(copy);
+ break;
+ default:
+ this->SetError("Wrong syntax. Unknown type of argument.");
+ return false;
+ }
+ }
+ }
+
+ std::string::size_type pos = targetName.find_first_of("#<>");
+ if(pos != targetName.npos)
+ {
+ cmOStringStream msg;
+ msg << "called with target name containing a \"" << targetName[pos]
+ << "\". This character is not allowed.";
+ this->SetError(msg.str());
+ return false;
+ }
+
+ // Some requirements on custom target names already exist
+ // and have been checked at this point.
+ // The following restrictions overlap but depend on policy CMP0037.
+ bool nameOk = cmGeneratorExpression::IsValidTargetName(targetName) &&
+ !cmGlobalGenerator::IsReservedTarget(targetName);
+ if (nameOk)
+ {
+ nameOk = targetName.find(":") == std::string::npos;
+ }
+ if (!nameOk)
+ {
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ cmOStringStream e;
+ bool issueMessage = false;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
+ {
+ case cmPolicies::WARN:
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
+ issueMessage = true;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ issueMessage = true;
+ messageType = cmake::FATAL_ERROR;
+ }
+ if (issueMessage)
+ {
+ e << "The target name \"" << targetName <<
+ "\" is reserved or not valid for certain "
+ "CMake features, such as generator expressions, and may result "
+ "in undefined behavior.";
+ this->Makefile->IssueMessage(messageType, e.str());
+
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return false;
+ }
+ }
+ }
+
+ // Store the last command line finished.
+ if(!currentLine.empty())
+ {
+ commandLines.push_back(currentLine);
+ currentLine.clear();
+ }
+
+ // Enforce name uniqueness.
+ {
+ std::string msg;
+ if(!this->Makefile->EnforceUniqueName(targetName, msg, true))
+ {
+ this->SetError(msg);
+ return false;
+ }
+ }
+
+ // Convert working directory to a full path.
+ if(!working_directory.empty())
+ {
+ const char* build_dir = this->Makefile->GetCurrentOutputDirectory();
+ working_directory =
+ cmSystemTools::CollapseFullPath(working_directory.c_str(), build_dir);
+ }
+
+ // Add the utility target to the makefile.
+ bool escapeOldStyle = !verbatim;
+ cmTarget* target =
+ this->Makefile->AddUtilityCommand(targetName, excludeFromAll,
+ working_directory.c_str(), depends,
+ commandLines, escapeOldStyle, comment);
+
+ // Add additional user-specified source files to the target.
+ target->AddSources(sources);
+
+ return true;
+}
diff --git a/Source/cmAddCustomTargetCommand.h b/Source/cmAddCustomTargetCommand.h
new file mode 100644
index 0000000000..d2b00adf4c
--- /dev/null
+++ b/Source/cmAddCustomTargetCommand.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmAddCustomTargetCommand_h
+#define cmAddCustomTargetCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmAddCustomTargetCommand
+ * \brief Command that adds a target to the build system.
+ *
+ * cmAddCustomTargetCommand adds an extra target to the build system.
+ * This is useful when you would like to add special
+ * targets like "install,", "clean," and so on.
+ */
+class cmAddCustomTargetCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddCustomTargetCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const
+ {return "add_custom_target";}
+
+ cmTypeMacro(cmAddCustomTargetCommand, cmCommand);
+};
+
+#endif
diff --git a/Source/cmAddDefinitionsCommand.cxx b/Source/cmAddDefinitionsCommand.cxx
new file mode 100644
index 0000000000..b813e3eb02
--- /dev/null
+++ b/Source/cmAddDefinitionsCommand.cxx
@@ -0,0 +1,31 @@
+/*============================================================================
+ 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 "cmAddDefinitionsCommand.h"
+
+// cmAddDefinitionsCommand
+bool cmAddDefinitionsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ // it is OK to have no arguments
+ if(args.size() < 1 )
+ {
+ return true;
+ }
+
+ for(std::vector<std::string>::const_iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ this->Makefile->AddDefineFlag(i->c_str());
+ }
+ return true;
+}
+
diff --git a/Source/cmAddDefinitionsCommand.h b/Source/cmAddDefinitionsCommand.h
new file mode 100644
index 0000000000..9800fd291c
--- /dev/null
+++ b/Source/cmAddDefinitionsCommand.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmAddDefinitionsCommand_h
+#define cmAddDefinitionsCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmAddDefinitionsCommand
+ * \brief Specify a list of compiler defines
+ *
+ * cmAddDefinitionsCommand specifies a list of compiler defines. These defines
+ * will be added to the compile command.
+ */
+class cmAddDefinitionsCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddDefinitionsCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "add_definitions";}
+
+ cmTypeMacro(cmAddDefinitionsCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmAddDependenciesCommand.cxx b/Source/cmAddDependenciesCommand.cxx
new file mode 100644
index 0000000000..e897d81b67
--- /dev/null
+++ b/Source/cmAddDependenciesCommand.cxx
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 "cmAddDependenciesCommand.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+
+// cmDependenciesCommand
+bool cmAddDependenciesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::string target_name = args[0];
+ if(this->Makefile->IsAlias(target_name))
+ {
+ cmOStringStream e;
+ e << "Cannot add target-level dependencies to alias target \""
+ << target_name << "\".\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ if(cmTarget* target = this->Makefile->FindTargetToUse(target_name))
+ {
+ if (target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "Cannot add target-level dependencies to INTERFACE library "
+ "target \"" << target_name << "\".\n";
+ this->SetError(e.str());
+ return false;
+ }
+
+ std::vector<std::string>::const_iterator s = args.begin();
+ ++s; // skip over target_name
+ for (; s != args.end(); ++s)
+ {
+ target->AddUtility(*s, this->Makefile);
+ }
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "Cannot add target-level dependencies to non-existent target \""
+ << target_name << "\".\n"
+ << "The add_dependencies works for top-level logical targets created "
+ << "by the add_executable, add_library, or add_custom_target commands. "
+ << "If you want to add file-level dependencies see the DEPENDS option "
+ << "of the add_custom_target and add_custom_command commands.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+
+ return true;
+}
+
diff --git a/Source/cmAddDependenciesCommand.h b/Source/cmAddDependenciesCommand.h
new file mode 100644
index 0000000000..db3712a246
--- /dev/null
+++ b/Source/cmAddDependenciesCommand.h
@@ -0,0 +1,49 @@
+/*============================================================================
+ 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 cmDependenciessCommand_h
+#define cmDependenciessCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmAddDependenciesCommand
+ * \brief Add a dependency to a target
+ *
+ * cmAddDependenciesCommand adds a dependency to a target
+ */
+class cmAddDependenciesCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddDependenciesCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "add_dependencies";}
+
+ cmTypeMacro(cmAddDependenciesCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx
new file mode 100644
index 0000000000..c30e76432b
--- /dev/null
+++ b/Source/cmAddExecutableCommand.cxx
@@ -0,0 +1,249 @@
+/*============================================================================
+ 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 "cmAddExecutableCommand.h"
+
+// cmExecutableCommand
+bool cmAddExecutableCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ std::vector<std::string>::const_iterator s = args.begin();
+
+ std::string exename = *s;
+
+ ++s;
+ bool use_win32 = false;
+ bool use_macbundle = false;
+ bool excludeFromAll = false;
+ bool importTarget = false;
+ bool importGlobal = false;
+ bool isAlias = false;
+ while ( s != args.end() )
+ {
+ if (*s == "WIN32")
+ {
+ ++s;
+ use_win32 = true;
+ }
+ else if ( *s == "MACOSX_BUNDLE" )
+ {
+ ++s;
+ use_macbundle = true;
+ }
+ else if(*s == "EXCLUDE_FROM_ALL")
+ {
+ ++s;
+ excludeFromAll = true;
+ }
+ else if(*s == "IMPORTED")
+ {
+ ++s;
+ importTarget = true;
+ }
+ else if(importTarget && *s == "GLOBAL")
+ {
+ ++s;
+ importGlobal = true;
+ }
+ else if(*s == "ALIAS")
+ {
+ ++s;
+ isAlias = true;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ bool nameOk = cmGeneratorExpression::IsValidTargetName(exename) &&
+ !cmGlobalGenerator::IsReservedTarget(exename);
+
+ if (nameOk && !importTarget && !isAlias)
+ {
+ nameOk = exename.find(":") == std::string::npos;
+ }
+ if (!nameOk)
+ {
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ cmOStringStream e;
+ bool issueMessage = false;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
+ {
+ case cmPolicies::WARN:
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
+ issueMessage = true;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ issueMessage = true;
+ messageType = cmake::FATAL_ERROR;
+ }
+ if (issueMessage)
+ {
+ e << "The target name \"" << exename <<
+ "\" is reserved or not valid for certain "
+ "CMake features, such as generator expressions, and may result "
+ "in undefined behavior.";
+ this->Makefile->IssueMessage(messageType, e.str());
+
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return false;
+ }
+ }
+ }
+
+ // Special modifiers are not allowed with IMPORTED signature.
+ if(importTarget
+ && (use_win32 || use_macbundle || excludeFromAll))
+ {
+ if(use_win32)
+ {
+ this->SetError("may not be given WIN32 for an IMPORTED target.");
+ }
+ else if(use_macbundle)
+ {
+ this->SetError(
+ "may not be given MACOSX_BUNDLE for an IMPORTED target.");
+ }
+ else // if(excludeFromAll)
+ {
+ this->SetError(
+ "may not be given EXCLUDE_FROM_ALL for an IMPORTED target.");
+ }
+ return false;
+ }
+ if (isAlias)
+ {
+ if(!cmGeneratorExpression::IsValidTargetName(exename))
+ {
+ this->SetError("Invalid name for ALIAS: " + exename);
+ return false;
+ }
+ if(excludeFromAll)
+ {
+ this->SetError("EXCLUDE_FROM_ALL with ALIAS makes no sense.");
+ return false;
+ }
+ if(importTarget || importGlobal)
+ {
+ this->SetError("IMPORTED with ALIAS is not allowed.");
+ return false;
+ }
+ if(args.size() != 3)
+ {
+ cmOStringStream e;
+ e << "ALIAS requires exactly one target argument.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ const char *aliasedName = s->c_str();
+ if(this->Makefile->IsAlias(aliasedName))
+ {
+ cmOStringStream e;
+ e << "cannot create ALIAS target \"" << exename
+ << "\" because target \"" << aliasedName << "\" is itself an ALIAS.";
+ this->SetError(e.str());
+ return false;
+ }
+ cmTarget *aliasedTarget =
+ this->Makefile->FindTargetToUse(aliasedName, true);
+ if(!aliasedTarget)
+ {
+ cmOStringStream e;
+ e << "cannot create ALIAS target \"" << exename
+ << "\" because target \"" << aliasedName << "\" does not already "
+ "exist.";
+ this->SetError(e.str());
+ return false;
+ }
+ cmTarget::TargetType type = aliasedTarget->GetType();
+ if(type != cmTarget::EXECUTABLE)
+ {
+ cmOStringStream e;
+ e << "cannot create ALIAS target \"" << exename
+ << "\" because target \"" << aliasedName << "\" is not an "
+ "executable.";
+ this->SetError(e.str());
+ return false;
+ }
+ if(aliasedTarget->IsImported())
+ {
+ cmOStringStream e;
+ e << "cannot create ALIAS target \"" << exename
+ << "\" because target \"" << aliasedName << "\" is IMPORTED.";
+ this->SetError(e.str());
+ return false;
+ }
+ this->Makefile->AddAlias(exename, aliasedTarget);
+ return true;
+ }
+
+ // Handle imported target creation.
+ if(importTarget)
+ {
+ // Make sure the target does not already exist.
+ if(this->Makefile->FindTargetToUse(exename))
+ {
+ cmOStringStream e;
+ e << "cannot create imported target \"" << exename
+ << "\" because another target with the same name already exists.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Create the imported target.
+ this->Makefile->AddImportedTarget(exename, cmTarget::EXECUTABLE,
+ importGlobal);
+ return true;
+ }
+
+ // Enforce name uniqueness.
+ {
+ std::string msg;
+ if(!this->Makefile->EnforceUniqueName(exename, msg))
+ {
+ this->SetError(msg);
+ return false;
+ }
+ }
+
+ if (s == args.end())
+ {
+ this->SetError
+ ("called with incorrect number of arguments, no sources provided");
+ return false;
+ }
+
+ std::vector<std::string> srclists(s, args.end());
+ cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists,
+ excludeFromAll);
+ if ( use_win32 )
+ {
+ tgt->SetProperty("WIN32_EXECUTABLE", "ON");
+ }
+ if ( use_macbundle)
+ {
+ tgt->SetProperty("MACOSX_BUNDLE", "ON");
+ }
+
+ return true;
+}
diff --git a/Source/cmAddExecutableCommand.h b/Source/cmAddExecutableCommand.h
new file mode 100644
index 0000000000..e134077b5a
--- /dev/null
+++ b/Source/cmAddExecutableCommand.h
@@ -0,0 +1,50 @@
+/*============================================================================
+ 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 cmExecutablesCommand_h
+#define cmExecutablesCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmExecutablesCommand
+ * \brief Defines a list of executables to build.
+ *
+ * cmExecutablesCommand defines a list of executable (i.e., test)
+ * programs to create.
+ */
+class cmAddExecutableCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddExecutableCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "add_executable";}
+
+ cmTypeMacro(cmAddExecutableCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx
new file mode 100644
index 0000000000..cdc9f2ad77
--- /dev/null
+++ b/Source/cmAddLibraryCommand.cxx
@@ -0,0 +1,450 @@
+/*============================================================================
+ 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 "cmAddLibraryCommand.h"
+
+#include "cmake.h"
+
+// cmLibraryCommand
+bool cmAddLibraryCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ // Library type defaults to value of BUILD_SHARED_LIBS, if it exists,
+ // otherwise it defaults to static library.
+ cmTarget::TargetType type = cmTarget::SHARED_LIBRARY;
+ if (cmSystemTools::IsOff(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
+ {
+ type = cmTarget::STATIC_LIBRARY;
+ }
+ bool excludeFromAll = false;
+ bool importTarget = false;
+ bool importGlobal = false;
+
+ std::vector<std::string>::const_iterator s = args.begin();
+
+ std::string libName = *s;
+
+ ++s;
+
+ // If the second argument is "SHARED" or "STATIC", then it controls
+ // the type of library. Otherwise, it is treated as a source or
+ // source list name. There may be two keyword arguments, check for them
+ bool haveSpecifiedType = false;
+ bool isAlias = false;
+ while ( s != args.end() )
+ {
+ std::string libType = *s;
+ if(libType == "STATIC")
+ {
+ if (type == cmTarget::INTERFACE_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library specified with conflicting STATIC type.";
+ this->SetError(e.str());
+ return false;
+ }
+ ++s;
+ type = cmTarget::STATIC_LIBRARY;
+ haveSpecifiedType = true;
+ }
+ else if(libType == "SHARED")
+ {
+ if (type == cmTarget::INTERFACE_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library specified with conflicting SHARED type.";
+ this->SetError(e.str());
+ return false;
+ }
+ ++s;
+ type = cmTarget::SHARED_LIBRARY;
+ haveSpecifiedType = true;
+ }
+ else if(libType == "MODULE")
+ {
+ if (type == cmTarget::INTERFACE_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library specified with conflicting MODULE type.";
+ this->SetError(e.str());
+ return false;
+ }
+ ++s;
+ type = cmTarget::MODULE_LIBRARY;
+ haveSpecifiedType = true;
+ }
+ else if(libType == "OBJECT")
+ {
+ if (type == cmTarget::INTERFACE_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library specified with conflicting OBJECT type.";
+ this->SetError(e.str());
+ return false;
+ }
+ ++s;
+ type = cmTarget::OBJECT_LIBRARY;
+ haveSpecifiedType = true;
+ }
+ else if(libType == "UNKNOWN")
+ {
+ if (type == cmTarget::INTERFACE_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library specified with conflicting UNKNOWN type.";
+ this->SetError(e.str());
+ return false;
+ }
+ ++s;
+ type = cmTarget::UNKNOWN_LIBRARY;
+ haveSpecifiedType = true;
+ }
+ else if(libType == "ALIAS")
+ {
+ if (type == cmTarget::INTERFACE_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library specified with conflicting ALIAS type.";
+ this->SetError(e.str());
+ return false;
+ }
+ ++s;
+ isAlias = true;
+ }
+ else if(libType == "INTERFACE")
+ {
+ if (haveSpecifiedType)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library specified with conflicting/multiple types.";
+ this->SetError(e.str());
+ return false;
+ }
+ if (isAlias)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library specified with conflicting ALIAS type.";
+ this->SetError(e.str());
+ return false;
+ }
+ if (excludeFromAll)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library may not be used with EXCLUDE_FROM_ALL.";
+ this->SetError(e.str());
+ return false;
+ }
+ ++s;
+ type = cmTarget::INTERFACE_LIBRARY;
+ haveSpecifiedType = true;
+ }
+ else if(*s == "EXCLUDE_FROM_ALL")
+ {
+ if (type == cmTarget::INTERFACE_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library may not be used with EXCLUDE_FROM_ALL.";
+ this->SetError(e.str());
+ return false;
+ }
+ ++s;
+ excludeFromAll = true;
+ }
+ else if(*s == "IMPORTED")
+ {
+ ++s;
+ importTarget = true;
+ }
+ else if(importTarget && *s == "GLOBAL")
+ {
+ ++s;
+ importGlobal = true;
+ }
+ else if(type == cmTarget::INTERFACE_LIBRARY && *s == "GLOBAL")
+ {
+ cmOStringStream e;
+ e << "GLOBAL option may only be used with IMPORTED libraries.";
+ this->SetError(e.str());
+ return false;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if (type == cmTarget::INTERFACE_LIBRARY)
+ {
+ if (s != args.end())
+ {
+ cmOStringStream e;
+ e << "INTERFACE library requires no source arguments.";
+ this->SetError(e.str());
+ return false;
+ }
+ if (importGlobal && !importTarget)
+ {
+ cmOStringStream e;
+ e << "INTERFACE library specified as GLOBAL, but not as IMPORTED.";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ bool nameOk = cmGeneratorExpression::IsValidTargetName(libName) &&
+ !cmGlobalGenerator::IsReservedTarget(libName);
+
+ if (nameOk && !importTarget && !isAlias)
+ {
+ nameOk = libName.find(":") == std::string::npos;
+ }
+ if (!nameOk)
+ {
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ cmOStringStream e;
+ bool issueMessage = false;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
+ {
+ case cmPolicies::WARN:
+ if(type != cmTarget::INTERFACE_LIBRARY)
+ {
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
+ issueMessage = true;
+ }
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ issueMessage = true;
+ messageType = cmake::FATAL_ERROR;
+ }
+ if (issueMessage)
+ {
+ e << "The target name \"" << libName <<
+ "\" is reserved or not valid for certain "
+ "CMake features, such as generator expressions, and may result "
+ "in undefined behavior.";
+ this->Makefile->IssueMessage(messageType, e.str());
+
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return false;
+ }
+ }
+ }
+
+ if (isAlias)
+ {
+ if(!cmGeneratorExpression::IsValidTargetName(libName))
+ {
+ this->SetError("Invalid name for ALIAS: " + libName);
+ return false;
+ }
+ if(excludeFromAll)
+ {
+ this->SetError("EXCLUDE_FROM_ALL with ALIAS makes no sense.");
+ return false;
+ }
+ if(importTarget || importGlobal)
+ {
+ this->SetError("IMPORTED with ALIAS is not allowed.");
+ return false;
+ }
+ if(args.size() != 3)
+ {
+ cmOStringStream e;
+ e << "ALIAS requires exactly one target argument.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ const char *aliasedName = s->c_str();
+ if(this->Makefile->IsAlias(aliasedName))
+ {
+ cmOStringStream e;
+ e << "cannot create ALIAS target \"" << libName
+ << "\" because target \"" << aliasedName << "\" is itself an ALIAS.";
+ this->SetError(e.str());
+ return false;
+ }
+ cmTarget *aliasedTarget =
+ this->Makefile->FindTargetToUse(aliasedName, true);
+ if(!aliasedTarget)
+ {
+ cmOStringStream e;
+ e << "cannot create ALIAS target \"" << libName
+ << "\" because target \"" << aliasedName << "\" does not already "
+ "exist.";
+ 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)
+ {
+ cmOStringStream e;
+ e << "cannot create ALIAS target \"" << libName
+ << "\" because target \"" << aliasedName << "\" is not a library.";
+ this->SetError(e.str());
+ return false;
+ }
+ if(aliasedTarget->IsImported())
+ {
+ cmOStringStream e;
+ e << "cannot create ALIAS target \"" << libName
+ << "\" because target \"" << aliasedName << "\" is IMPORTED.";
+ this->SetError(e.str());
+ return false;
+ }
+ this->Makefile->AddAlias(libName, aliasedTarget);
+ return true;
+ }
+
+ if(importTarget && excludeFromAll)
+ {
+ this->SetError("excludeFromAll with IMPORTED target makes no sense.");
+ return false;
+ }
+
+ /* ideally we should check whether for the linker language of the target
+ 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::STATIC_LIBRARY) &&
+ (type != cmTarget::OBJECT_LIBRARY) &&
+ (type != cmTarget::INTERFACE_LIBRARY) &&
+ (this->Makefile->GetCMakeInstance()->GetPropertyAsBool(
+ "TARGET_SUPPORTS_SHARED_LIBS") == false))
+ {
+ cmOStringStream w;
+ w <<
+ "ADD_LIBRARY called with " <<
+ (type==cmTarget::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;
+ }
+
+ // Handle imported target creation.
+ if(importTarget)
+ {
+ // The IMPORTED signature requires a type to be specified explicitly.
+ if (!haveSpecifiedType)
+ {
+ this->SetError("called with IMPORTED argument but no library type.");
+ return false;
+ }
+ if(type == cmTarget::OBJECT_LIBRARY)
+ {
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ "The OBJECT library type may not be used for IMPORTED libraries."
+ );
+ return true;
+ }
+ if(type == cmTarget::INTERFACE_LIBRARY)
+ {
+ if (!cmGeneratorExpression::IsValidTargetName(libName))
+ {
+ cmOStringStream e;
+ e << "Invalid name for IMPORTED INTERFACE library target: " << libName;
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // Make sure the target does not already exist.
+ if(this->Makefile->FindTargetToUse(libName))
+ {
+ cmOStringStream e;
+ e << "cannot create imported target \"" << libName
+ << "\" because another target with the same name already exists.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Create the imported target.
+ this->Makefile->AddImportedTarget(libName, type, importGlobal);
+ return true;
+ }
+
+ // A non-imported target may not have UNKNOWN type.
+ if(type == cmTarget::UNKNOWN_LIBRARY)
+ {
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ "The UNKNOWN library type may be used only for IMPORTED libraries."
+ );
+ return true;
+ }
+
+ // Enforce name uniqueness.
+ {
+ std::string msg;
+ if(!this->Makefile->EnforceUniqueName(libName, msg))
+ {
+ this->SetError(msg);
+ return false;
+ }
+ }
+
+ std::vector<std::string> srclists;
+
+ if(type == cmTarget::INTERFACE_LIBRARY)
+ {
+ if (!cmGeneratorExpression::IsValidTargetName(libName)
+ || libName.find("::") != std::string::npos)
+ {
+ cmOStringStream e;
+ e << "Invalid name for INTERFACE library target: " << libName;
+ this->SetError(e.str());
+ return false;
+ }
+
+ this->Makefile->AddLibrary(libName,
+ type,
+ srclists,
+ excludeFromAll);
+ return true;
+ }
+
+ if (s == args.end())
+ {
+ std::string msg = "You have called ADD_LIBRARY for library ";
+ msg += args[0];
+ msg += " without any source files. This typically indicates a problem ";
+ msg += "with your CMakeLists.txt file";
+ cmSystemTools::Message(msg.c_str() ,"Warning");
+ }
+
+ while (s != args.end())
+ {
+ srclists.push_back(*s);
+ ++s;
+ }
+
+ this->Makefile->AddLibrary(libName, type, srclists, excludeFromAll);
+
+ return true;
+}
+
+
diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h
new file mode 100644
index 0000000000..350708b238
--- /dev/null
+++ b/Source/cmAddLibraryCommand.h
@@ -0,0 +1,50 @@
+/*============================================================================
+ 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 cmLibrarysCommand_h
+#define cmLibrarysCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmLibrarysCommand
+ * \brief Defines a list of executables to build.
+ *
+ * cmLibrarysCommand defines a list of executable (i.e., test)
+ * programs to create.
+ */
+class cmAddLibraryCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddLibraryCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "add_library";}
+
+ cmTypeMacro(cmAddLibraryCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmAddSubDirectoryCommand.cxx b/Source/cmAddSubDirectoryCommand.cxx
new file mode 100644
index 0000000000..4ea2524968
--- /dev/null
+++ b/Source/cmAddSubDirectoryCommand.cxx
@@ -0,0 +1,128 @@
+/*============================================================================
+ 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 "cmAddSubDirectoryCommand.h"
+
+// cmAddSubDirectoryCommand
+bool cmAddSubDirectoryCommand::InitialPass
+(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // store the binpath
+ std::string srcArg = args[0];
+ std::string binArg;
+
+ bool excludeFromAll = false;
+
+ // process the rest of the arguments looking for optional args
+ std::vector<std::string>::const_iterator i = args.begin();
+ ++i;
+ for(;i != args.end(); ++i)
+ {
+ if(*i == "EXCLUDE_FROM_ALL")
+ {
+ excludeFromAll = true;
+ continue;
+ }
+ else if (!binArg.size())
+ {
+ binArg = *i;
+ }
+ else
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ }
+
+ // Compute the full path to the specified source directory.
+ // Interpret a relative path with respect to the current source directory.
+ std::string srcPath;
+ if(cmSystemTools::FileIsFullPath(srcArg.c_str()))
+ {
+ srcPath = srcArg;
+ }
+ else
+ {
+ srcPath = this->Makefile->GetCurrentDirectory();
+ srcPath += "/";
+ srcPath += srcArg;
+ }
+ if(!cmSystemTools::FileIsDirectory(srcPath.c_str()))
+ {
+ std::string error = "given source \"";
+ error += srcArg;
+ error += "\" which is not an existing directory.";
+ this->SetError(error);
+ return false;
+ }
+ srcPath = cmSystemTools::CollapseFullPath(srcPath.c_str());
+
+ // Compute the full path to the binary directory.
+ std::string binPath;
+ if(binArg.empty())
+ {
+ // No binary directory was specified. If the source directory is
+ // not a subdirectory of the current directory then it is an
+ // error.
+ if(!cmSystemTools::IsSubDirectory(srcPath.c_str(),
+ this->Makefile->GetCurrentDirectory()))
+ {
+ cmOStringStream e;
+ e << "not given a binary directory but the given source directory "
+ << "\"" << srcPath << "\" is not a subdirectory of \""
+ << this->Makefile->GetCurrentDirectory() << "\". "
+ << "When specifying an out-of-tree source a binary directory "
+ << "must be explicitly specified.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Remove the CurrentDirectory from the srcPath and replace it
+ // with the CurrentOutputDirectory.
+ const char* src = this->Makefile->GetCurrentDirectory();
+ const char* bin = this->Makefile->GetCurrentOutputDirectory();
+ size_t srcLen = strlen(src);
+ size_t binLen = strlen(bin);
+ if(srcLen > 0 && src[srcLen-1] == '/')
+ { --srcLen; }
+ if(binLen > 0 && bin[binLen-1] == '/')
+ { --binLen; }
+ binPath = std::string(bin, binLen) + srcPath.substr(srcLen);
+ }
+ else
+ {
+ // Use the binary directory specified.
+ // Interpret a relative path with respect to the current binary directory.
+ if(cmSystemTools::FileIsFullPath(binArg.c_str()))
+ {
+ binPath = binArg;
+ }
+ else
+ {
+ binPath = this->Makefile->GetCurrentOutputDirectory();
+ binPath += "/";
+ binPath += binArg;
+ }
+ }
+ binPath = cmSystemTools::CollapseFullPath(binPath.c_str());
+
+ // Add the subdirectory using the computed full paths.
+ this->Makefile->AddSubDirectory(srcPath, binPath,
+ excludeFromAll, false, true);
+
+ return true;
+}
diff --git a/Source/cmAddSubDirectoryCommand.h b/Source/cmAddSubDirectoryCommand.h
new file mode 100644
index 0000000000..abf3efcd9e
--- /dev/null
+++ b/Source/cmAddSubDirectoryCommand.h
@@ -0,0 +1,52 @@
+/*============================================================================
+ 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 cmAddSubDirectoryCommand_h
+#define cmAddSubDirectoryCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmAddSubDirectoryCommand
+ * \brief Specify a subdirectory to build
+ *
+ * cmAddSubDirectoryCommand specifies a subdirectory to process
+ * by CMake. CMake will descend
+ * into the specified source directory and process any CMakeLists.txt found.
+ */
+class cmAddSubDirectoryCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddSubDirectoryCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "add_subdirectory";}
+
+ cmTypeMacro(cmAddSubDirectoryCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmAddTestCommand.cxx b/Source/cmAddTestCommand.cxx
new file mode 100644
index 0000000000..2531a1a76d
--- /dev/null
+++ b/Source/cmAddTestCommand.cxx
@@ -0,0 +1,180 @@
+/*============================================================================
+ 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 "cmAddTestCommand.h"
+
+#include "cmTestGenerator.h"
+
+#include "cmTest.h"
+
+
+// cmExecutableCommand
+bool cmAddTestCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(!args.empty() && args[0] == "NAME")
+ {
+ return this->HandleNameMode(args);
+ }
+
+ // First argument is the name of the test Second argument is the name of
+ // the executable to run (a target or external program) Remaining arguments
+ // are the arguments to pass to the executable
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // Collect the command with arguments.
+ std::vector<std::string> command;
+ for(std::vector<std::string>::const_iterator it = args.begin() + 1;
+ it != args.end(); ++it)
+ {
+ command.push_back(*it);
+ }
+
+ // Create the test but add a generator only the first time it is
+ // seen. This preserves behavior from before test generators.
+ cmTest* test = this->Makefile->GetTest(args[0]);
+ if(test)
+ {
+ // If the test was already added by a new-style signature do not
+ // allow it to be duplicated.
+ if(!test->GetOldStyle())
+ {
+ cmOStringStream e;
+ e << " given test name \"" << args[0]
+ << "\" which already exists in this directory.";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else
+ {
+ test = this->Makefile->CreateTest(args[0]);
+ test->SetOldStyle(true);
+ this->Makefile->AddTestGenerator(new cmTestGenerator(test));
+ }
+ test->SetCommand(command);
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
+{
+ std::string name;
+ std::vector<std::string> configurations;
+ std::string working_directory;
+ std::vector<std::string> command;
+
+ // Read the arguments.
+ enum Doing {
+ DoingName,
+ DoingCommand,
+ DoingConfigs,
+ DoingWorkingDirectory,
+ DoingNone
+ };
+ Doing doing = DoingName;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "COMMAND")
+ {
+ if(!command.empty())
+ {
+ this->SetError(" may be given at most one COMMAND.");
+ return false;
+ }
+ doing = DoingCommand;
+ }
+ else if(args[i] == "CONFIGURATIONS")
+ {
+ if(!configurations.empty())
+ {
+ this->SetError(" may be given at most one set of CONFIGURATIONS.");
+ return false;
+ }
+ doing = DoingConfigs;
+ }
+ else if(args[i] == "WORKING_DIRECTORY")
+ {
+ if(!working_directory.empty())
+ {
+ this->SetError(" may be given at most one WORKING_DIRECTORY.");
+ return false;
+ }
+ doing = DoingWorkingDirectory;
+ }
+ else if(doing == DoingName)
+ {
+ name = args[i];
+ doing = DoingNone;
+ }
+ else if(doing == DoingCommand)
+ {
+ command.push_back(args[i]);
+ }
+ else if(doing == DoingConfigs)
+ {
+ configurations.push_back(args[i]);
+ }
+ else if(doing == DoingWorkingDirectory)
+ {
+ working_directory = args[i];
+ doing = DoingNone;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << " given unknown argument:\n " << args[i] << "\n";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // Require a test name.
+ if(name.empty())
+ {
+ this->SetError(" must be given non-empty NAME.");
+ return false;
+ }
+
+ // Require a command.
+ if(command.empty())
+ {
+ this->SetError(" must be given non-empty COMMAND.");
+ return false;
+ }
+
+ // Require a unique test name within the directory.
+ if(this->Makefile->GetTest(name))
+ {
+ cmOStringStream e;
+ e << " given test NAME \"" << name
+ << "\" which already exists in this directory.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Add the test.
+ cmTest* test = this->Makefile->CreateTest(name);
+ test->SetOldStyle(false);
+ test->SetCommand(command);
+ if(!working_directory.empty())
+ {
+ test->SetProperty("WORKING_DIRECTORY", working_directory.c_str());
+ }
+ this->Makefile->AddTestGenerator(new cmTestGenerator(test, configurations));
+
+ return true;
+}
diff --git a/Source/cmAddTestCommand.h b/Source/cmAddTestCommand.h
new file mode 100644
index 0000000000..624288f579
--- /dev/null
+++ b/Source/cmAddTestCommand.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmAddTestCommand_h
+#define cmAddTestCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmAddTestCommand
+ * \brief Add a test to the lists of tests to run.
+ *
+ * cmAddTestCommand adds a test to the list of tests to run .
+ */
+class cmAddTestCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAddTestCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "add_test";}
+
+ cmTypeMacro(cmAddTestCommand, cmCommand);
+private:
+ bool HandleNameMode(std::vector<std::string> const& args);
+};
+
+
+#endif
diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx
new file mode 100644
index 0000000000..a2aecac00e
--- /dev/null
+++ b/Source/cmArchiveWrite.cxx
@@ -0,0 +1,346 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2010 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 "cmArchiveWrite.h"
+
+#include "cmSystemTools.h"
+#include <cmsys/ios/iostream>
+#include <cmsys/Directory.hxx>
+#include <cmsys/FStream.hxx>
+#include <cm_libarchive.h>
+
+//----------------------------------------------------------------------------
+static std::string cm_archive_error_string(struct archive* a)
+{
+ const char* e = archive_error_string(a);
+ return e? e : "unknown error";
+}
+
+//----------------------------------------------------------------------------
+static void cm_archive_entry_copy_pathname(struct archive_entry* e,
+ const std::string& dest)
+{
+#if cmsys_STL_HAS_WSTRING
+ archive_entry_copy_pathname_w(e, cmsys::Encoding::ToWide(dest).c_str());
+#else
+ archive_entry_copy_pathname(e, dest.c_str());
+#endif
+}
+
+//----------------------------------------------------------------------------
+static void cm_archive_entry_copy_sourcepath(struct archive_entry* e,
+ const std::string& file)
+{
+#if cmsys_STL_HAS_WSTRING
+ archive_entry_copy_sourcepath_w(e, cmsys::Encoding::ToWide(file).c_str());
+#else
+ archive_entry_copy_sourcepath(e, file.c_str());
+#endif
+}
+
+//----------------------------------------------------------------------------
+class cmArchiveWrite::Entry
+{
+ struct archive_entry* Object;
+public:
+ Entry(): Object(archive_entry_new()) {}
+ ~Entry() { archive_entry_free(this->Object); }
+ operator struct archive_entry*() { return this->Object; }
+};
+
+//----------------------------------------------------------------------------
+struct cmArchiveWrite::Callback
+{
+ // archive_write_callback
+ static __LA_SSIZE_T Write(struct archive*, void *cd,
+ const void *b, size_t n)
+ {
+ cmArchiveWrite* self = static_cast<cmArchiveWrite*>(cd);
+ if(self->Stream.write(static_cast<const char*>(b),
+ static_cast<cmsys_ios::streamsize>(n)))
+ {
+ return static_cast<__LA_SSIZE_T>(n);
+ }
+ else
+ {
+ return static_cast<__LA_SSIZE_T>(-1);
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, Type t):
+ Stream(os),
+ Archive(archive_write_new()),
+ Disk(archive_read_disk_new()),
+ Verbose(false)
+{
+ switch (c)
+ {
+ case CompressNone:
+ if(archive_write_set_compression_none(this->Archive) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_set_compression_none: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ break;
+ case CompressCompress:
+ if(archive_write_set_compression_compress(this->Archive) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_set_compression_compress: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ break;
+ case CompressGZip:
+ if(archive_write_set_compression_gzip(this->Archive) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_set_compression_gzip: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ break;
+ case CompressBZip2:
+ if(archive_write_set_compression_bzip2(this->Archive) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_set_compression_bzip2: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ break;
+ case CompressLZMA:
+ if(archive_write_set_compression_lzma(this->Archive) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_set_compression_lzma: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ break;
+ case CompressXZ:
+ if(archive_write_set_compression_xz(this->Archive) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_set_compression_xz: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ break;
+ };
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ if (archive_read_disk_set_standard_lookup(this->Disk) != ARCHIVE_OK)
+ {
+ this->Error = "archive_read_disk_set_standard_lookup: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;;
+ }
+#endif
+ switch (t)
+ {
+ case TypeZIP:
+ if(archive_write_set_format_zip(this->Archive) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_set_format_zip: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ break;
+ case TypeTAR:
+ if(archive_write_set_format_pax_restricted(this->Archive) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_set_format_pax_restricted: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ break;
+ case Type7Zip:
+ if(archive_write_set_format_7zip(this->Archive) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_set_format_7zip: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ break;
+ }
+
+ // do not pad the last block!!
+ if (archive_write_set_bytes_in_last_block(this->Archive, 1))
+ {
+ this->Error = "archive_write_set_bytes_in_last_block: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+
+ if(archive_write_open(
+ this->Archive, this, 0,
+ reinterpret_cast<archive_write_callback*>(&Callback::Write),
+ 0) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_open: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmArchiveWrite::~cmArchiveWrite()
+{
+ archive_read_finish(this->Disk);
+ archive_write_finish(this->Archive);
+}
+
+//----------------------------------------------------------------------------
+bool cmArchiveWrite::Add(std::string path, size_t skip, const char* prefix)
+{
+ if(this->Okay())
+ {
+ if(!path.empty() && path[path.size()-1] == '/')
+ {
+ path.erase(path.size()-1);
+ }
+ this->AddPath(path.c_str(), skip, prefix);
+ }
+ return this->Okay();
+}
+
+//----------------------------------------------------------------------------
+bool cmArchiveWrite::AddPath(const char* path,
+ size_t skip, const char* prefix)
+{
+ if(!this->AddFile(path, skip, prefix))
+ {
+ return false;
+ }
+ if(!cmSystemTools::FileIsDirectory(path) ||
+ cmSystemTools::FileIsSymlink(path))
+ {
+ return true;
+ }
+ cmsys::Directory d;
+ if(d.Load(path))
+ {
+ std::string next = path;
+ next += "/";
+ std::string::size_type end = next.size();
+ unsigned long n = d.GetNumberOfFiles();
+ for(unsigned long i = 0; i < n; ++i)
+ {
+ const char* file = d.GetFile(i);
+ if(strcmp(file, ".") != 0 && strcmp(file, "..") != 0)
+ {
+ next.erase(end);
+ next += file;
+ if(!this->AddPath(next.c_str(), skip, prefix))
+ {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmArchiveWrite::AddFile(const char* file,
+ size_t skip, const char* prefix)
+{
+ // Skip the file if we have no name for it. This may happen on a
+ // top-level directory, which does not need to be included anyway.
+ if(skip >= strlen(file))
+ {
+ return true;
+ }
+ const char* out = file + skip;
+
+ // Meta-data.
+ std::string dest = prefix? prefix : "";
+ dest += out;
+ if(this->Verbose)
+ {
+ std::cout << dest << "\n";
+ }
+ Entry e;
+ cm_archive_entry_copy_sourcepath(e, file);
+ cm_archive_entry_copy_pathname(e, dest);
+ if(archive_read_disk_entry_from_file(this->Disk, e, -1, 0) != ARCHIVE_OK)
+ {
+ this->Error = "archive_read_disk_entry_from_file: ";
+ this->Error += cm_archive_error_string(this->Disk);
+ return false;
+ }
+ // Clear acl and xattr fields not useful for distribution.
+ archive_entry_acl_clear(e);
+ archive_entry_xattr_clear(e);
+ archive_entry_set_fflags(e, 0, 0);
+ if(archive_write_header(this->Archive, e) != ARCHIVE_OK)
+ {
+ this->Error = "archive_write_header: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return false;
+ }
+
+ // do not copy content of symlink
+ if (!archive_entry_symlink(e))
+ {
+ // Content.
+ if(size_t size = static_cast<size_t>(archive_entry_size(e)))
+ {
+ return this->AddData(file, size);
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmArchiveWrite::AddData(const char* file, size_t size)
+{
+ cmsys::ifstream fin(file, std::ios::in | cmsys_ios_binary);
+ if(!fin)
+ {
+ this->Error = "Error opening \"";
+ this->Error += file;
+ this->Error += "\": ";
+ this->Error += cmSystemTools::GetLastSystemError();
+ return false;
+ }
+
+ char buffer[16384];
+ size_t nleft = size;
+ while(nleft > 0)
+ {
+ typedef cmsys_ios::streamsize ssize_type;
+ size_t const nnext = nleft > sizeof(buffer)? sizeof(buffer) : nleft;
+ ssize_type const nnext_s = static_cast<ssize_type>(nnext);
+ fin.read(buffer, nnext_s);
+ // Some stream libraries (older HPUX) return failure at end of
+ // file on the last read even if some data were read. Check
+ // gcount instead of trusting the stream error status.
+ if(static_cast<size_t>(fin.gcount()) != nnext)
+ {
+ break;
+ }
+ if(archive_write_data(this->Archive, buffer, nnext) != nnext_s)
+ {
+ this->Error = "archive_write_data: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return false;
+ }
+ nleft -= nnext;
+ }
+ if(nleft > 0)
+ {
+ this->Error = "Error reading \"";
+ this->Error += file;
+ this->Error += "\": ";
+ this->Error += cmSystemTools::GetLastSystemError();
+ return false;
+ }
+ return true;
+}
diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h
new file mode 100644
index 0000000000..a6dcc0e4e5
--- /dev/null
+++ b/Source/cmArchiveWrite.h
@@ -0,0 +1,95 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2010 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 cmArchiveWrite_h
+#define cmArchiveWrite_h
+
+#include "cmStandardIncludes.h"
+
+#if !defined(CMAKE_BUILD_WITH_CMAKE)
+# error "cmArchiveWrite not allowed during bootstrap build!"
+#endif
+
+/** \class cmArchiveWrite
+ * \brief Wrapper around libarchive for writing.
+ *
+ */
+class cmArchiveWrite
+{
+ typedef void (cmArchiveWrite::* safe_bool)();
+ void safe_bool_true() {}
+public:
+ /** Compression type. */
+ enum Compress
+ {
+ CompressNone,
+ CompressCompress,
+ CompressGZip,
+ CompressBZip2,
+ CompressLZMA,
+ CompressXZ
+ };
+
+ /** Archive Type */
+ enum Type
+ {
+ TypeTAR,
+ TypeZIP,
+ Type7Zip
+ };
+
+ /** Construct with output stream to which to write archive. */
+ cmArchiveWrite(std::ostream& os, Compress c = CompressNone, Type = TypeTAR);
+ ~cmArchiveWrite();
+
+ /**
+ * Add a path (file or directory) to the archive. Directories are
+ * added recursively. The "path" must be readable on disk, either
+ * full path or relative to current working directory. The "skip"
+ * value indicates how many leading bytes from the input path to
+ * skip. The remaining part of the input path is appended to the
+ * "prefix" value to construct the final name in the archive.
+ */
+ bool Add(std::string path, size_t skip = 0, const char* prefix = 0);
+
+ /** Returns true if there has been no error. */
+ operator safe_bool() const
+ { return this->Okay()? &cmArchiveWrite::safe_bool_true : 0; }
+
+ /** Returns true if there has been an error. */
+ bool operator!() const { return !this->Okay(); }
+
+ /** Return the error string; empty if none. */
+ std::string GetError() const { return this->Error; }
+
+ // TODO: More general callback instead of hard-coding calls to
+ // std::cout.
+ void SetVerbose(bool v) { this->Verbose = v; }
+
+private:
+ bool Okay() const { return this->Error.empty(); }
+ bool AddPath(const char* path, size_t skip, const char* prefix);
+ bool AddFile(const char* file, size_t skip, const char* prefix);
+ bool AddData(const char* file, size_t size);
+
+ struct Callback;
+ friend struct Callback;
+
+ class Entry;
+
+ std::ostream& Stream;
+ struct archive* Archive;
+ struct archive* Disk;
+ bool Verbose;
+ std::string Error;
+};
+
+#endif
diff --git a/Source/cmAuxSourceDirectoryCommand.cxx b/Source/cmAuxSourceDirectoryCommand.cxx
new file mode 100644
index 0000000000..d8c3c4329e
--- /dev/null
+++ b/Source/cmAuxSourceDirectoryCommand.cxx
@@ -0,0 +1,89 @@
+/*============================================================================
+ 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 "cmAuxSourceDirectoryCommand.h"
+#include "cmSourceFile.h"
+
+#include <cmsys/Directory.hxx>
+
+// cmAuxSourceDirectoryCommand
+bool cmAuxSourceDirectoryCommand::InitialPass
+(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 || args.size() > 2)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::string sourceListValue;
+ std::string templateDirectory = args[0];
+ this->Makefile->AddExtraDirectory(templateDirectory.c_str());
+ std::string tdir;
+ if(!cmSystemTools::FileIsFullPath(templateDirectory.c_str()))
+ {
+ tdir = this->Makefile->GetCurrentDirectory();
+ tdir += "/";
+ tdir += templateDirectory;
+ }
+ else
+ {
+ tdir = templateDirectory;
+ }
+
+ // was the list already populated
+ const char *def = this->Makefile->GetDefinition(args[1]);
+ if (def)
+ {
+ sourceListValue = def;
+ }
+
+ // Load all the files in the directory
+ cmsys::Directory dir;
+ if(dir.Load(tdir.c_str()))
+ {
+ size_t numfiles = dir.GetNumberOfFiles();
+ for(size_t i =0; i < numfiles; ++i)
+ {
+ std::string file = dir.GetFile(static_cast<unsigned long>(i));
+ // Split the filename into base and extension
+ std::string::size_type dotpos = file.rfind(".");
+ if( dotpos != std::string::npos )
+ {
+ std::string ext = file.substr(dotpos+1);
+ std::string base = file.substr(0, dotpos);
+ // Process only source files
+ if( base.size() != 0
+ && std::find( this->Makefile->GetSourceExtensions().begin(),
+ this->Makefile->GetSourceExtensions().end(), ext )
+ != this->Makefile->GetSourceExtensions().end() )
+ {
+ std::string fullname = templateDirectory;
+ fullname += "/";
+ fullname += file;
+ // add the file as a class file so
+ // depends can be done
+ cmSourceFile* sf =
+ this->Makefile->GetOrCreateSource(fullname);
+ sf->SetProperty("ABSTRACT","0");
+ if(!sourceListValue.empty())
+ {
+ sourceListValue += ";";
+ }
+ sourceListValue += fullname;
+ }
+ }
+ }
+ }
+ this->Makefile->AddDefinition(args[1], sourceListValue.c_str());
+ return true;
+}
+
diff --git a/Source/cmAuxSourceDirectoryCommand.h b/Source/cmAuxSourceDirectoryCommand.h
new file mode 100644
index 0000000000..6615273bb8
--- /dev/null
+++ b/Source/cmAuxSourceDirectoryCommand.h
@@ -0,0 +1,54 @@
+/*============================================================================
+ 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 cmAuxSourceDirectoryCommand_h
+#define cmAuxSourceDirectoryCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmAuxSourceDirectoryCommand
+ * \brief Specify auxiliary source code directories.
+ *
+ * cmAuxSourceDirectoryCommand specifies source code directories
+ * that must be built as part of this build process. This directories
+ * are not recursively processed like the SUBDIR command (cmSubdirCommand).
+ * A side effect of this command is to create a subdirectory in the build
+ * directory structure.
+ */
+class cmAuxSourceDirectoryCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmAuxSourceDirectoryCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "aux_source_directory";}
+
+ cmTypeMacro(cmAuxSourceDirectoryCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmBootstrapCommands1.cxx b/Source/cmBootstrapCommands1.cxx
new file mode 100644
index 0000000000..9093579dc8
--- /dev/null
+++ b/Source/cmBootstrapCommands1.cxx
@@ -0,0 +1,91 @@
+/*============================================================================
+ 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.
+============================================================================*/
+// This file is used to compile all the commands
+// that CMake knows about at compile time.
+// This is sort of a boot strapping approach since you would
+// like to have CMake to build CMake.
+#include "cmCommands.h"
+#include "cmAddCustomCommandCommand.cxx"
+#include "cmAddCustomTargetCommand.cxx"
+#include "cmAddDefinitionsCommand.cxx"
+#include "cmAddDependenciesCommand.cxx"
+#include "cmAddExecutableCommand.cxx"
+#include "cmAddLibraryCommand.cxx"
+#include "cmAddSubDirectoryCommand.cxx"
+#include "cmAddTestCommand.cxx"
+#include "cmBreakCommand.cxx"
+#include "cmBuildCommand.cxx"
+#include "cmCMakeMinimumRequired.cxx"
+#include "cmCMakePolicyCommand.cxx"
+#include "cmCommandArgumentsHelper.cxx"
+#include "cmConfigureFileCommand.cxx"
+#include "cmCoreTryCompile.cxx"
+#include "cmCreateTestSourceList.cxx"
+#include "cmDefinePropertyCommand.cxx"
+#include "cmElseCommand.cxx"
+#include "cmEnableLanguageCommand.cxx"
+#include "cmEnableTestingCommand.cxx"
+#include "cmEndForEachCommand.cxx"
+#include "cmEndFunctionCommand.cxx"
+#include "cmEndIfCommand.cxx"
+#include "cmEndMacroCommand.cxx"
+#include "cmEndWhileCommand.cxx"
+#include "cmExecProgramCommand.cxx"
+#include "cmExecuteProcessCommand.cxx"
+#include "cmExternalMakefileProjectGenerator.cxx"
+#include "cmFindBase.cxx"
+#include "cmFindCommon.cxx"
+#include "cmFileCommand.cxx"
+#include "cmFindFileCommand.cxx"
+#include "cmFindLibraryCommand.cxx"
+#include "cmFindPackageCommand.cxx"
+#include "cmFindPathCommand.cxx"
+#include "cmFindProgramCommand.cxx"
+#include "cmForEachCommand.cxx"
+#include "cmFunctionCommand.cxx"
+
+void GetBootstrapCommands1(std::list<cmCommand*>& commands)
+{
+ commands.push_back(new cmAddCustomCommandCommand);
+ commands.push_back(new cmAddCustomTargetCommand);
+ commands.push_back(new cmAddDefinitionsCommand);
+ commands.push_back(new cmAddDependenciesCommand);
+ commands.push_back(new cmAddExecutableCommand);
+ commands.push_back(new cmAddLibraryCommand);
+ commands.push_back(new cmAddSubDirectoryCommand);
+ commands.push_back(new cmAddTestCommand);
+ commands.push_back(new cmBreakCommand);
+ commands.push_back(new cmBuildCommand);
+ commands.push_back(new cmCMakeMinimumRequired);
+ commands.push_back(new cmCMakePolicyCommand);
+ commands.push_back(new cmConfigureFileCommand);
+ commands.push_back(new cmCreateTestSourceList);
+ commands.push_back(new cmDefinePropertyCommand);
+ commands.push_back(new cmElseCommand);
+ commands.push_back(new cmEnableLanguageCommand);
+ commands.push_back(new cmEnableTestingCommand);
+ commands.push_back(new cmEndForEachCommand);
+ commands.push_back(new cmEndFunctionCommand);
+ commands.push_back(new cmEndIfCommand);
+ commands.push_back(new cmEndMacroCommand);
+ commands.push_back(new cmEndWhileCommand);
+ commands.push_back(new cmExecProgramCommand);
+ commands.push_back(new cmExecuteProcessCommand);
+ commands.push_back(new cmFileCommand);
+ commands.push_back(new cmFindFileCommand);
+ commands.push_back(new cmFindLibraryCommand);
+ commands.push_back(new cmFindPackageCommand);
+ commands.push_back(new cmFindPathCommand);
+ commands.push_back(new cmFindProgramCommand);
+ commands.push_back(new cmForEachCommand);
+ commands.push_back(new cmFunctionCommand);
+}
diff --git a/Source/cmBootstrapCommands2.cxx b/Source/cmBootstrapCommands2.cxx
new file mode 100644
index 0000000000..5675295f58
--- /dev/null
+++ b/Source/cmBootstrapCommands2.cxx
@@ -0,0 +1,104 @@
+/*============================================================================
+ 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.
+============================================================================*/
+// This file is used to compile all the commands
+// that CMake knows about at compile time.
+// This is sort of a boot strapping approach since you would
+// like to have CMake to build CMake.
+#include "cmCommands.h"
+#include "cmConditionEvaluator.cxx"
+#include "cmExpandedCommandArgument.cxx"
+#include "cmGeneratorExpressionEvaluationFile.cxx"
+#include "cmGetCMakePropertyCommand.cxx"
+#include "cmGetDirectoryPropertyCommand.cxx"
+#include "cmGetFilenameComponentCommand.cxx"
+#include "cmGetPropertyCommand.cxx"
+#include "cmGetSourceFilePropertyCommand.cxx"
+#include "cmGetTargetPropertyCommand.cxx"
+#include "cmHexFileConverter.cxx"
+#include "cmIfCommand.cxx"
+#include "cmIncludeCommand.cxx"
+#include "cmIncludeDirectoryCommand.cxx"
+#include "cmIncludeRegularExpressionCommand.cxx"
+#include "cmInstallFilesCommand.cxx"
+#include "cmInstallCommandArguments.cxx"
+#include "cmInstallCommand.cxx"
+#include "cmInstallTargetsCommand.cxx"
+#include "cmLinkDirectoriesCommand.cxx"
+#include "cmListCommand.cxx"
+#include "cmMacroCommand.cxx"
+#include "cmMakeDirectoryCommand.cxx"
+#include "cmMarkAsAdvancedCommand.cxx"
+#include "cmMathCommand.cxx"
+#include "cmMessageCommand.cxx"
+#include "cmOptionCommand.cxx"
+#include "cmProjectCommand.cxx"
+#include "cmReturnCommand.cxx"
+#include "cmSeparateArgumentsCommand.cxx"
+#include "cmSetCommand.cxx"
+#include "cmSetDirectoryPropertiesCommand.cxx"
+#include "cmSetPropertyCommand.cxx"
+#include "cmSetSourceFilesPropertiesCommand.cxx"
+#include "cmSetTargetPropertiesCommand.cxx"
+#include "cmSetTestsPropertiesCommand.cxx"
+#include "cmGetTestPropertyCommand.cxx"
+#include "cmSiteNameCommand.cxx"
+#include "cmStringCommand.cxx"
+#include "cmSubdirCommand.cxx"
+#include "cmTargetLinkLibrariesCommand.cxx"
+#include "cmTimestamp.cxx"
+#include "cmTryCompileCommand.cxx"
+#include "cmTryRunCommand.cxx"
+#include "cmUnsetCommand.cxx"
+#include "cmWhileCommand.cxx"
+
+void GetBootstrapCommands2(std::list<cmCommand*>& commands)
+{
+ commands.push_back(new cmGetCMakePropertyCommand);
+ commands.push_back(new cmGetDirectoryPropertyCommand);
+ commands.push_back(new cmGetFilenameComponentCommand);
+ commands.push_back(new cmGetPropertyCommand);
+ commands.push_back(new cmGetSourceFilePropertyCommand);
+ commands.push_back(new cmGetTargetPropertyCommand);
+ commands.push_back(new cmIfCommand);
+ commands.push_back(new cmIncludeCommand);
+ commands.push_back(new cmIncludeDirectoryCommand);
+ commands.push_back(new cmIncludeRegularExpressionCommand);
+ commands.push_back(new cmInstallCommand);
+ commands.push_back(new cmInstallFilesCommand);
+ commands.push_back(new cmInstallTargetsCommand);
+ commands.push_back(new cmLinkDirectoriesCommand);
+ commands.push_back(new cmListCommand);
+ commands.push_back(new cmMacroCommand);
+ commands.push_back(new cmMakeDirectoryCommand);
+ commands.push_back(new cmMarkAsAdvancedCommand);
+ commands.push_back(new cmMathCommand);
+ commands.push_back(new cmMessageCommand);
+ commands.push_back(new cmOptionCommand);
+ commands.push_back(new cmProjectCommand);
+ commands.push_back(new cmReturnCommand);
+ commands.push_back(new cmSeparateArgumentsCommand);
+ commands.push_back(new cmSetCommand);
+ commands.push_back(new cmSetDirectoryPropertiesCommand);
+ commands.push_back(new cmSetPropertyCommand);
+ commands.push_back(new cmSetSourceFilesPropertiesCommand);
+ commands.push_back(new cmSetTargetPropertiesCommand);
+ commands.push_back(new cmGetTestPropertyCommand);
+ commands.push_back(new cmSetTestsPropertiesCommand);
+ commands.push_back(new cmSiteNameCommand);
+ commands.push_back(new cmStringCommand);
+ commands.push_back(new cmSubdirCommand);
+ commands.push_back(new cmTargetLinkLibrariesCommand);
+ commands.push_back(new cmTryCompileCommand);
+ commands.push_back(new cmTryRunCommand);
+ commands.push_back(new cmUnsetCommand);
+ commands.push_back(new cmWhileCommand);
+}
diff --git a/Source/cmBreakCommand.cxx b/Source/cmBreakCommand.cxx
new file mode 100644
index 0000000000..b70e400886
--- /dev/null
+++ b/Source/cmBreakCommand.cxx
@@ -0,0 +1,21 @@
+/*============================================================================
+ 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 "cmBreakCommand.h"
+
+// cmBreakCommand
+bool cmBreakCommand::InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &status)
+{
+ status.SetBreakInvoked(true);
+ return true;
+}
+
diff --git a/Source/cmBreakCommand.h b/Source/cmBreakCommand.h
new file mode 100644
index 0000000000..1fcae505a2
--- /dev/null
+++ b/Source/cmBreakCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmBreakCommand_h
+#define cmBreakCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmBreakCommand
+ * \brief Break from an enclosing foreach or while loop
+ *
+ * cmBreakCommand returns from an enclosing foreach or while loop
+ */
+class cmBreakCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmBreakCommand;
+ }
+
+ /**
+ * 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 "break";}
+
+ cmTypeMacro(cmBreakCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmBuildCommand.cxx b/Source/cmBuildCommand.cxx
new file mode 100644
index 0000000000..93f7801254
--- /dev/null
+++ b/Source/cmBuildCommand.cxx
@@ -0,0 +1,152 @@
+/*============================================================================
+ 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 "cmBuildCommand.h"
+
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+
+//----------------------------------------------------------------------
+bool cmBuildCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ // Support the legacy signature of the command:
+ //
+ if(2 == args.size())
+ {
+ return this->TwoArgsSignature(args);
+ }
+
+ return this->MainSignature(args);
+}
+
+//----------------------------------------------------------------------
+bool cmBuildCommand
+::MainSignature(std::vector<std::string> const& args)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("requires at least one argument naming a CMake variable");
+ return false;
+ }
+
+ // The cmake variable in which to store the result.
+ const char* variable = args[0].c_str();
+
+ // Parse remaining arguments.
+ const char* configuration = 0;
+ const char* project_name = 0;
+ std::string target;
+ enum Doing { DoingNone, DoingConfiguration, DoingProjectName, DoingTarget };
+ Doing doing = DoingNone;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "CONFIGURATION")
+ {
+ doing = DoingConfiguration;
+ }
+ else if(args[i] == "PROJECT_NAME")
+ {
+ doing = DoingProjectName;
+ }
+ else if(args[i] == "TARGET")
+ {
+ doing = DoingTarget;
+ }
+ else if(doing == DoingConfiguration)
+ {
+ doing = DoingNone;
+ configuration = args[i].c_str();
+ }
+ else if(doing == DoingProjectName)
+ {
+ doing = DoingNone;
+ project_name = args[i].c_str();
+ }
+ else if(doing == DoingTarget)
+ {
+ doing = DoingNone;
+ target = args[i];
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "unknown argument \"" << args[i] << "\"";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // If null/empty CONFIGURATION argument, cmake --build uses 'Debug'
+ // in the currently implemented multi-configuration global generators...
+ // so we put this code here to end up with the same default configuration
+ // as the original 2-arg build_command signature:
+ //
+ if(!configuration || !*configuration)
+ {
+ configuration = getenv("CMAKE_CONFIG_TYPE");
+ }
+ if(!configuration || !*configuration)
+ {
+ configuration = "Release";
+ }
+
+ if(project_name && *project_name)
+ {
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ "Ignoring PROJECT_NAME option because it has no effect.");
+ }
+
+ std::string makecommand = this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->GenerateCMakeBuildCommand(target, configuration,
+ "", true);
+
+ this->Makefile->AddDefinition(variable, makecommand.c_str());
+
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmBuildCommand
+::TwoArgsSignature(std::vector<std::string> const& args)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with less than two arguments");
+ return false;
+ }
+
+ const char* define = args[0].c_str();
+ const char* cacheValue
+ = this->Makefile->GetDefinition(define);
+
+ std::string configType = "Release";
+ const char* cfg = getenv("CMAKE_CONFIG_TYPE");
+ if ( cfg )
+ {
+ configType = cfg;
+ }
+
+ std::string makecommand = this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->GenerateCMakeBuildCommand("", configType,
+ "", true);
+
+ if(cacheValue)
+ {
+ return true;
+ }
+ this->Makefile->AddCacheDefinition(define,
+ makecommand.c_str(),
+ "Command used to build entire project "
+ "from the command line.",
+ cmCacheManager::STRING);
+ return true;
+}
diff --git a/Source/cmBuildCommand.h b/Source/cmBuildCommand.h
new file mode 100644
index 0000000000..3fb618f9c5
--- /dev/null
+++ b/Source/cmBuildCommand.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 cmBuildCommand_h
+#define cmBuildCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmBuildCommand
+ * \brief build_command command
+ *
+ * cmBuildCommand implements the build_command CMake command
+ */
+class cmBuildCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmBuildCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The primary command signature with optional, KEYWORD-based args.
+ */
+ virtual bool MainSignature(std::vector<std::string> const& args);
+
+ /**
+ * Legacy "exactly 2 args required" signature.
+ */
+ virtual bool TwoArgsSignature(std::vector<std::string> const& args);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "build_command";}
+
+ cmTypeMacro(cmBuildCommand, cmCommand);
+};
+
+#endif
diff --git a/Source/cmBuildNameCommand.cxx b/Source/cmBuildNameCommand.cxx
new file mode 100644
index 0000000000..c64209f88c
--- /dev/null
+++ b/Source/cmBuildNameCommand.cxx
@@ -0,0 +1,80 @@
+/*============================================================================
+ 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 "cmBuildNameCommand.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+// cmBuildNameCommand
+bool cmBuildNameCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(this->Disallowed(cmPolicies::CMP0036,
+ "The build_name command should not be called; see CMP0036."))
+ { return true; }
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ const char* cacheValue = this->Makefile->GetDefinition(args[0]);
+ if(cacheValue)
+ {
+ // do we need to correct the value?
+ cmsys::RegularExpression reg("[()/]");
+ if (reg.find(cacheValue))
+ {
+ std::string cv = cacheValue;
+ cmSystemTools::ReplaceString(cv,"/", "_");
+ cmSystemTools::ReplaceString(cv,"(", "_");
+ cmSystemTools::ReplaceString(cv,")", "_");
+ this->Makefile->AddCacheDefinition(args[0],
+ cv.c_str(),
+ "Name of build.",
+ cmCacheManager::STRING);
+ }
+ return true;
+ }
+
+
+ std::string buildname = "WinNT";
+ if(this->Makefile->GetDefinition("UNIX"))
+ {
+ buildname = "";
+ cmSystemTools::RunSingleCommand("uname -a", &buildname);
+ if(buildname.length())
+ {
+ std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
+ cmsys::RegularExpression reg( RegExp.c_str() );
+ if(reg.find(buildname.c_str()))
+ {
+ buildname = reg.match(1) + "-" + reg.match(2);
+ }
+ }
+ }
+ std::string compiler = "${CMAKE_CXX_COMPILER}";
+ this->Makefile->ExpandVariablesInString ( compiler );
+ buildname += "-";
+ buildname += cmSystemTools::GetFilenameName(compiler);
+ cmSystemTools::ReplaceString(buildname,
+ "/", "_");
+ cmSystemTools::ReplaceString(buildname,
+ "(", "_");
+ cmSystemTools::ReplaceString(buildname,
+ ")", "_");
+
+ this->Makefile->AddCacheDefinition(args[0],
+ buildname.c_str(),
+ "Name of build.",
+ cmCacheManager::STRING);
+ return true;
+}
+
diff --git a/Source/cmBuildNameCommand.h b/Source/cmBuildNameCommand.h
new file mode 100644
index 0000000000..8f8038febf
--- /dev/null
+++ b/Source/cmBuildNameCommand.h
@@ -0,0 +1,31 @@
+/*============================================================================
+ 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 cmBuildNameCommand_h
+#define cmBuildNameCommand_h
+
+#include "cmCommand.h"
+
+class cmBuildNameCommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmBuildNameCommand, cmCommand);
+ virtual cmCommand* Clone() { return new cmBuildNameCommand; }
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+ virtual std::string GetName() const {return "build_name";}
+ virtual bool IsScriptable() const { return true; }
+ virtual bool IsDiscouraged() const { return true; }
+};
+
+
+
+#endif
diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx
new file mode 100644
index 0000000000..52345389ce
--- /dev/null
+++ b/Source/cmCMakeHostSystemInformationCommand.cxx
@@ -0,0 +1,126 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 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 "cmCMakeHostSystemInformationCommand.h"
+
+#include <cmsys/ios/sstream>
+
+// cmCMakeHostSystemInformation
+bool cmCMakeHostSystemInformationCommand
+::InitialPass(std::vector<std::string> const &args, cmExecutionStatus &)
+{
+ size_t current_index = 0;
+
+ if(args.size() < (current_index + 2) || args[current_index] != "RESULT")
+ {
+ this->SetError("missing RESULT specification.");
+ return false;
+ }
+
+ std::string variable = args[current_index + 1];
+ current_index += 2;
+
+ if(args.size() < (current_index + 2) || args[current_index] != "QUERY")
+ {
+ this->SetError("missing QUERY specification");
+ return false;
+ }
+
+ cmsys::SystemInformation info;
+ info.RunCPUCheck();
+ info.RunOSCheck();
+ info.RunMemoryCheck();
+
+ std::string result_list;
+ for(size_t i = current_index + 1; i < args.size(); ++i)
+ {
+ std::string key = args[i];
+ if(i != current_index + 1)
+ {
+ result_list += ";";
+ }
+ std::string value;
+ if(!this->GetValue(info, key, value)) return false;
+
+ result_list += value;
+ }
+
+ this->Makefile->AddDefinition(variable, result_list.c_str());
+
+ return true;
+}
+
+bool cmCMakeHostSystemInformationCommand
+::GetValue(cmsys::SystemInformation &info,
+ std::string const& key, std::string &value)
+{
+ if(key == "NUMBER_OF_LOGICAL_CORES")
+ {
+ value = this->ValueToString(info.GetNumberOfLogicalCPU());
+ }
+ else if(key == "NUMBER_OF_PHYSICAL_CORES")
+ {
+ value = this->ValueToString(info.GetNumberOfPhysicalCPU());
+ }
+ else if(key == "HOSTNAME")
+ {
+ value = this->ValueToString(info.GetHostname());
+ }
+ else if(key == "FQDN")
+ {
+ value = this->ValueToString(info.GetFullyQualifiedDomainName());
+ }
+ else if(key == "TOTAL_VIRTUAL_MEMORY")
+ {
+ value = this->ValueToString(info.GetTotalVirtualMemory());
+ }
+ else if(key == "AVAILABLE_VIRTUAL_MEMORY")
+ {
+ value = this->ValueToString(info.GetAvailableVirtualMemory());
+ }
+ else if(key == "TOTAL_PHYSICAL_MEMORY")
+ {
+ value = this->ValueToString(info.GetTotalPhysicalMemory());
+ }
+ else if(key == "AVAILABLE_PHYSICAL_MEMORY")
+ {
+ value = this->ValueToString(info.GetAvailablePhysicalMemory());
+ }
+ else
+ {
+ std::string e = "does not recognize <key> " + key;
+ this->SetError(e);
+ return false;
+ }
+
+ return true;
+}
+
+std::string cmCMakeHostSystemInformationCommand
+::ValueToString(size_t value) const
+{
+ cmsys_ios::stringstream tmp;
+ tmp << value;
+ return tmp.str();
+}
+
+std::string cmCMakeHostSystemInformationCommand
+::ValueToString(const char *value) const
+{
+ std::string safe_string = value ? value : "";
+ return safe_string;
+}
+
+std::string cmCMakeHostSystemInformationCommand
+::ValueToString(std::string const& value) const
+{
+ return value;
+}
diff --git a/Source/cmCMakeHostSystemInformationCommand.h b/Source/cmCMakeHostSystemInformationCommand.h
new file mode 100644
index 0000000000..463b180b33
--- /dev/null
+++ b/Source/cmCMakeHostSystemInformationCommand.h
@@ -0,0 +1,67 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 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 cmCMakeHostSystemInformationCommand_h
+#define cmCMakeHostSystemInformationCommand_h
+
+#include "cmCommand.h"
+
+#include <cmsys/SystemInformation.hxx>
+
+/** \class cmCMakeHostSystemInformationCommand
+ * \brief Query host system specific information
+ *
+ * cmCMakeHostSystemInformationCommand queries system information of
+ * the sytem on which CMake runs.
+ */
+class cmCMakeHostSystemInformationCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmCMakeHostSystemInformationCommand;
+ }
+
+ /**
+ * 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_host_system_information";
+ }
+
+ cmTypeMacro(cmCMakeHostSystemInformationCommand, cmCommand);
+
+private:
+ bool GetValue(cmsys::SystemInformation &info,
+ std::string const& key, std::string &value);
+
+ std::string ValueToString(size_t value) const;
+ std::string ValueToString(const char *value) const;
+ std::string ValueToString(std::string const& value) const;
+};
+
+#endif
diff --git a/Source/cmCMakeMinimumRequired.cxx b/Source/cmCMakeMinimumRequired.cxx
new file mode 100644
index 0000000000..58b61deef9
--- /dev/null
+++ b/Source/cmCMakeMinimumRequired.cxx
@@ -0,0 +1,142 @@
+/*============================================================================
+ 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 "cmCMakeMinimumRequired.h"
+
+#include "cmVersion.h"
+
+// cmCMakeMinimumRequired
+bool cmCMakeMinimumRequired
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ // Process arguments.
+ std::string version_string;
+ bool doing_version = false;
+ for(unsigned int i=0; i < args.size(); ++i)
+ {
+ if(args[i] == "VERSION")
+ {
+ doing_version = true;
+ }
+ else if(args[i] == "FATAL_ERROR")
+ {
+ if(doing_version)
+ {
+ this->SetError("called with no value for VERSION.");
+ return false;
+ }
+ doing_version = false;
+ }
+ else if(doing_version)
+ {
+ doing_version = false;
+ version_string = args[i];
+ }
+ else
+ {
+ this->UnknownArguments.push_back(args[i]);
+ }
+ }
+ if(doing_version)
+ {
+ this->SetError("called with no value for VERSION.");
+ return false;
+ }
+
+ // Make sure there was a version to check.
+ if(version_string.empty())
+ {
+ return this->EnforceUnknownArguments();
+ }
+
+ // Save the required version string.
+ this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION",
+ version_string.c_str());
+
+
+ // Get the current version number.
+ int current_major = cmVersion::GetMajorVersion();
+ int current_minor = cmVersion::GetMinorVersion();
+ int current_patch = cmVersion::GetPatchVersion();
+ int current_tweak = cmVersion::GetTweakVersion();
+
+ // Parse at least two components of the version number.
+ // Use zero for those not specified.
+ int required_major = 0;
+ int required_minor = 0;
+ int required_patch = 0;
+ int required_tweak = 0;
+ if(sscanf(version_string.c_str(), "%u.%u.%u.%u",
+ &required_major, &required_minor,
+ &required_patch, &required_tweak) < 2)
+ {
+ cmOStringStream e;
+ e << "could not parse VERSION \"" << version_string << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Compare the version numbers.
+ if((current_major < required_major) ||
+ (current_major == required_major &&
+ current_minor < required_minor) ||
+ (current_major == required_major &&
+ current_minor == required_minor &&
+ current_patch < required_patch) ||
+ (current_major == required_major &&
+ current_minor == required_minor &&
+ current_patch == required_patch &&
+ current_tweak < required_tweak))
+ {
+ // The current version is too low.
+ cmOStringStream e;
+ e << "CMake " << version_string
+ << " or higher is required. You are running version "
+ << cmVersion::GetCMakeVersion();
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+
+ // The version is not from the future, so enforce unknown arguments.
+ if(!this->EnforceUnknownArguments())
+ {
+ return false;
+ }
+
+ if (required_major < 2 || (required_major == 2 && required_minor < 4))
+ {
+ this->Makefile->IssueMessage(
+ cmake::AUTHOR_WARNING,
+ "Compatibility with CMake < 2.4 is not supported by CMake >= 3.0.");
+ this->Makefile->SetPolicyVersion("2.4");
+ }
+ else
+ {
+ this->Makefile->SetPolicyVersion(version_string.c_str());
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmCMakeMinimumRequired::EnforceUnknownArguments()
+{
+ if(!this->UnknownArguments.empty())
+ {
+ cmOStringStream e;
+ e << "called with unknown argument \""
+ << this->UnknownArguments[0] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ return true;
+}
diff --git a/Source/cmCMakeMinimumRequired.h b/Source/cmCMakeMinimumRequired.h
new file mode 100644
index 0000000000..31b727198d
--- /dev/null
+++ b/Source/cmCMakeMinimumRequired.h
@@ -0,0 +1,59 @@
+/*============================================================================
+ 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 cmCMakeMinimumRequired_h
+#define cmCMakeMinimumRequired_h
+
+#include "cmCommand.h"
+
+/** \class cmCMakeMinimumRequired
+ * \brief cmake_minimum_required command
+ *
+ * cmCMakeMinimumRequired implements the cmake_minimum_required CMake command
+ */
+class cmCMakeMinimumRequired : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmCMakeMinimumRequired;
+ }
+
+ /**
+ * 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_minimum_required";}
+
+ cmTypeMacro(cmCMakeMinimumRequired, cmCommand);
+
+private:
+ std::vector<std::string> UnknownArguments;
+ bool EnforceUnknownArguments();
+};
+
+
+
+#endif
diff --git a/Source/cmCMakePolicyCommand.cxx b/Source/cmCMakePolicyCommand.cxx
new file mode 100644
index 0000000000..ddd5d6ad59
--- /dev/null
+++ b/Source/cmCMakePolicyCommand.cxx
@@ -0,0 +1,172 @@
+/*============================================================================
+ 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 "cmCMakePolicyCommand.h"
+
+#include "cmVersion.h"
+
+// cmCMakePolicyCommand
+bool cmCMakePolicyCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("requires at least one argument.");
+ return false;
+ }
+
+ if(args[0] == "SET")
+ {
+ return this->HandleSetMode(args);
+ }
+ else if(args[0] == "GET")
+ {
+ return this->HandleGetMode(args);
+ }
+ else if(args[0] == "PUSH")
+ {
+ if(args.size() > 1)
+ {
+ this->SetError("PUSH may not be given additional arguments.");
+ return false;
+ }
+ this->Makefile->PushPolicy();
+ return true;
+ }
+ else if(args[0] == "POP")
+ {
+ if(args.size() > 1)
+ {
+ this->SetError("POP may not be given additional arguments.");
+ return false;
+ }
+ this->Makefile->PopPolicy();
+ return true;
+ }
+ else if(args[0] == "VERSION")
+ {
+ return this->HandleVersionMode(args);
+ }
+
+ cmOStringStream e;
+ e << "given unknown first argument \"" << args[0] << "\"";
+ this->SetError(e.str());
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+ {
+ this->SetError("SET must be given exactly 2 additional arguments.");
+ return false;
+ }
+
+ cmPolicies::PolicyStatus status;
+ if(args[2] == "OLD")
+ {
+ status = cmPolicies::OLD;
+ }
+ else if(args[2] == "NEW")
+ {
+ status = cmPolicies::NEW;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "SET given unrecognized policy status \"" << args[2] << "\"";
+ this->SetError(e.str());
+ return false;
+ }
+
+ if(!this->Makefile->SetPolicy(args[1].c_str(), status))
+ {
+ this->SetError("SET failed to set policy.");
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+ {
+ this->SetError("GET must be given exactly 2 additional arguments.");
+ return false;
+ }
+
+ // Get arguments.
+ std::string const& id = args[1];
+ std::string const& var = args[2];
+
+ // Lookup the policy number.
+ cmPolicies::PolicyID pid;
+ if(!this->Makefile->GetPolicies()->GetPolicyID(id.c_str(), pid))
+ {
+ cmOStringStream e;
+ e << "GET given policy \"" << id << "\" which is not known to this "
+ << "version of CMake.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Lookup the policy setting.
+ cmPolicies::PolicyStatus status = this->Makefile->GetPolicyStatus(pid);
+ switch (status)
+ {
+ case cmPolicies::OLD:
+ // Report that the policy is set to OLD.
+ this->Makefile->AddDefinition(var, "OLD");
+ break;
+ case cmPolicies::WARN:
+ // Report that the policy is not set.
+ this->Makefile->AddDefinition(var, "");
+ break;
+ case cmPolicies::NEW:
+ // Report that the policy is set to NEW.
+ this->Makefile->AddDefinition(var, "NEW");
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ // The policy is required to be set before anything needs it.
+ {
+ cmOStringStream e;
+ e << this->Makefile->GetPolicies()->GetRequiredPolicyError(pid)
+ << "\n"
+ << "The call to cmake_policy(GET " << id << " ...) at which this "
+ << "error appears requests the policy, and this version of CMake "
+ << "requires that the policy be set to NEW before it is checked.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmCMakePolicyCommand::HandleVersionMode(std::vector<std::string> const& args)
+{
+ if(args.size() <= 1)
+ {
+ this->SetError("VERSION not given an argument");
+ return false;
+ }
+ else if(args.size() >= 3)
+ {
+ this->SetError("VERSION given too many arguments");
+ return false;
+ }
+ this->Makefile->SetPolicyVersion(args[1].c_str());
+ return true;
+}
diff --git a/Source/cmCMakePolicyCommand.h b/Source/cmCMakePolicyCommand.h
new file mode 100644
index 0000000000..8dc8fbeed1
--- /dev/null
+++ b/Source/cmCMakePolicyCommand.h
@@ -0,0 +1,60 @@
+/*============================================================================
+ 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 cmCMakePolicyCommand_h
+#define cmCMakePolicyCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmCMakePolicyCommand
+ * \brief Set how CMake should handle policies
+ *
+ * cmCMakePolicyCommand sets how CMake should deal with backwards
+ * compatibility policies.
+ */
+class cmCMakePolicyCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmCMakePolicyCommand;
+ }
+
+ /**
+ * 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_policy";}
+
+ cmTypeMacro(cmCMakePolicyCommand, cmCommand);
+private:
+ bool HandleSetMode(std::vector<std::string> const& args);
+ bool HandleGetMode(std::vector<std::string> const& args);
+ bool HandleVersionMode(std::vector<std::string> const& args);
+};
+
+
+
+#endif
diff --git a/Source/cmCPackPropertiesGenerator.cxx b/Source/cmCPackPropertiesGenerator.cxx
new file mode 100644
index 0000000000..cf24c136f6
--- /dev/null
+++ b/Source/cmCPackPropertiesGenerator.cxx
@@ -0,0 +1,45 @@
+#include "cmCPackPropertiesGenerator.h"
+
+#include "cmLocalGenerator.h"
+
+cmCPackPropertiesGenerator::cmCPackPropertiesGenerator(
+ cmMakefile* mf,
+ cmInstalledFile const& installedFile,
+ std::vector<std::string> const& configurations):
+ cmScriptGenerator("CPACK_BUILD_CONFIG", configurations),
+ Makefile(mf),
+ InstalledFile(installedFile)
+{
+ this->ActionsPerConfig = true;
+}
+
+void cmCPackPropertiesGenerator::GenerateScriptForConfig(std::ostream& os,
+ const std::string& config, Indent const& indent)
+{
+ std::string const& expandedFileName =
+ this->InstalledFile.GetNameExpression().Evaluate(this->Makefile, config);
+
+ cmInstalledFile::PropertyMapType const& properties =
+ this->InstalledFile.GetProperties();
+
+ for(cmInstalledFile::PropertyMapType::const_iterator i = properties.begin();
+ i != properties.end(); ++i)
+ {
+ std::string const& name = i->first;
+ cmInstalledFile::Property const& property = i->second;
+
+ os << indent << "set_property(INSTALL " <<
+ cmLocalGenerator::EscapeForCMake(expandedFileName) << " PROPERTY " <<
+ cmLocalGenerator::EscapeForCMake(name);
+
+ for(cmInstalledFile::ExpressionVectorType::const_iterator
+ j = property.ValueExpressions.begin();
+ j != property.ValueExpressions.end(); ++j)
+ {
+ std::string value = (*j)->Evaluate(this->Makefile, config);
+ os << " " << cmLocalGenerator::EscapeForCMake(value);
+ }
+
+ os << ")\n";
+ }
+}
diff --git a/Source/cmCPackPropertiesGenerator.h b/Source/cmCPackPropertiesGenerator.h
new file mode 100644
index 0000000000..71e2eaa425
--- /dev/null
+++ b/Source/cmCPackPropertiesGenerator.h
@@ -0,0 +1,38 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmCPackPropertiesGenerator_h
+#define cmCPackPropertiesGenerator_h
+
+#include "cmScriptGenerator.h"
+#include "cmInstalledFile.h"
+
+/** \class cmCPackPropertiesGenerator
+ * \brief Support class for generating CPackProperties.cmake.
+ *
+ */
+class cmCPackPropertiesGenerator: public cmScriptGenerator
+{
+public:
+ cmCPackPropertiesGenerator(
+ cmMakefile* mf,
+ cmInstalledFile const& installedFile,
+ std::vector<std::string> const& configurations);
+
+protected:
+ virtual void GenerateScriptForConfig(std::ostream& os,
+ const std::string& config, Indent const& indent);
+
+ cmMakefile* Makefile;
+ cmInstalledFile const& InstalledFile;
+};
+
+#endif
diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx
new file mode 100644
index 0000000000..dd2a1b8f7f
--- /dev/null
+++ b/Source/cmCPluginAPI.cxx
@@ -0,0 +1,935 @@
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+ this file contains the implementation of the C API to CMake. Generally
+ these routines just manipulate arguments and then call the associated
+ methods on the CMake classes. */
+
+#include "cmMakefile.h"
+#include "cmCPluginAPI.h"
+#include "cmVersion.h"
+
+#include "cmSourceFile.h"
+
+#include <stdlib.h>
+
+#ifdef __QNX__
+# include <malloc.h> /* for malloc/free on QNX */
+#endif
+
+extern "C"
+{
+
+void CCONV *cmGetClientData(void *info)
+{
+ return ((cmLoadedCommandInfo *)info)->ClientData;
+}
+
+void CCONV cmSetClientData(void *info, void *cd)
+{
+ ((cmLoadedCommandInfo *)info)->ClientData = cd;
+}
+
+void CCONV cmSetError(void *info, const char *err)
+{
+ if (((cmLoadedCommandInfo *)info)->Error)
+ {
+ free(((cmLoadedCommandInfo *)info)->Error);
+ }
+ ((cmLoadedCommandInfo *)info)->Error = strdup(err);
+}
+
+unsigned int CCONV cmGetCacheMajorVersion(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetCacheMajorVersion();
+}
+unsigned int CCONV cmGetCacheMinorVersion(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetCacheMinorVersion();
+}
+
+unsigned int CCONV cmGetMajorVersion(void *)
+{
+ return cmVersion::GetMajorVersion();
+}
+
+unsigned int CCONV cmGetMinorVersion(void *)
+{
+ return cmVersion::GetMinorVersion();
+}
+
+void CCONV cmAddDefinition(void *arg, const char* name, const char* value)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ mf->AddDefinition(name,value);
+}
+
+/* Add a definition to this makefile and the global cmake cache. */
+void CCONV cmAddCacheDefinition(void *arg, const char* name,
+ const char* value, const char* doc, int type)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+
+ switch (type)
+ {
+ case CM_CACHE_BOOL:
+ mf->AddCacheDefinition(name,value,doc,
+ cmCacheManager::BOOL);
+ break;
+ case CM_CACHE_PATH:
+ mf->AddCacheDefinition(name,value,doc,
+ cmCacheManager::PATH);
+ break;
+ case CM_CACHE_FILEPATH:
+ mf->AddCacheDefinition(name,value,doc,
+ cmCacheManager::FILEPATH);
+ break;
+ case CM_CACHE_STRING:
+ mf->AddCacheDefinition(name,value,doc,
+ cmCacheManager::STRING);
+ break;
+ case CM_CACHE_INTERNAL:
+ mf->AddCacheDefinition(name,value,doc,
+ cmCacheManager::INTERNAL);
+ break;
+ case CM_CACHE_STATIC:
+ mf->AddCacheDefinition(name,value,doc,
+ cmCacheManager::STATIC);
+ break;
+ }
+}
+
+const char* CCONV cmGetProjectName(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetProjectName();
+}
+
+const char* CCONV cmGetHomeDirectory(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetHomeDirectory();
+}
+const char* CCONV cmGetHomeOutputDirectory(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetHomeOutputDirectory();
+}
+const char* CCONV cmGetStartDirectory(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetStartDirectory();
+}
+const char* CCONV cmGetStartOutputDirectory(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetStartOutputDirectory();
+}
+const char* CCONV cmGetCurrentDirectory(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetCurrentDirectory();
+}
+const char* CCONV cmGetCurrentOutputDirectory(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetCurrentOutputDirectory();
+}
+const char* CCONV cmGetDefinition(void *arg,const char*def)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return mf->GetDefinition(def);
+}
+
+int CCONV cmIsOn(void *arg, const char* name)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return static_cast<int>(mf->IsOn(name));
+}
+
+/** Check if a command exists. */
+int CCONV cmCommandExists(void *arg, const char* name)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ return static_cast<int>(mf->CommandExists(name));
+}
+
+void CCONV cmAddDefineFlag(void *arg, const char* definition)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ mf->AddDefineFlag(definition);
+}
+
+void CCONV cmAddLinkDirectoryForTarget(void *arg, const char *tgt,
+ const char* d)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ mf->AddLinkDirectoryForTarget(tgt,d);
+}
+
+
+void CCONV cmAddExecutable(void *arg, const char *exename,
+ int numSrcs, const char **srcs, int win32)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ std::vector<std::string> srcs2;
+ int i;
+ for (i = 0; i < numSrcs; ++i)
+ {
+ srcs2.push_back(srcs[i]);
+ }
+ cmTarget* tg = mf->AddExecutable(exename, srcs2);
+ if ( win32 )
+ {
+ tg->SetProperty("WIN32_EXECUTABLE", "ON");
+ }
+}
+
+void CCONV cmAddUtilityCommand(void *arg, const char* utilityName,
+ const char* command,
+ const char* arguments,
+ int all,
+ int numDepends,
+ const char **depends,
+ int,
+ const char **)
+{
+ // Get the makefile instance. Perform an extra variable expansion
+ // now because the API caller expects it.
+ cmMakefile* mf = static_cast<cmMakefile*>(arg);
+
+ // Construct the command line for the command.
+ cmCustomCommandLine commandLine;
+ std::string expand = command;
+ commandLine.push_back(mf->ExpandVariablesInString(expand));
+ if(arguments && arguments[0])
+ {
+ // TODO: Parse arguments!
+ expand = arguments;
+ commandLine.push_back(mf->ExpandVariablesInString(expand));
+ }
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+
+ // Accumulate the list of dependencies.
+ std::vector<std::string> depends2;
+ for(int i = 0; i < numDepends; ++i)
+ {
+ expand = depends[i];
+ depends2.push_back(mf->ExpandVariablesInString(expand));
+ }
+
+ // Pass the call to the makefile instance.
+ mf->AddUtilityCommand(utilityName, (all ? false : true),
+ 0, depends2, commandLines);
+}
+void CCONV cmAddCustomCommand(void *arg, const char* source,
+ const char* command,
+ int numArgs, const char **args,
+ int numDepends, const char **depends,
+ int numOutputs, const char **outputs,
+ const char *target)
+{
+ // Get the makefile instance. Perform an extra variable expansion
+ // now because the API caller expects it.
+ cmMakefile* mf = static_cast<cmMakefile*>(arg);
+
+ // Construct the command line for the command.
+ cmCustomCommandLine commandLine;
+ std::string expand = command;
+ commandLine.push_back(mf->ExpandVariablesInString(expand));
+ for(int i=0; i < numArgs; ++i)
+ {
+ expand = args[i];
+ commandLine.push_back(mf->ExpandVariablesInString(expand));
+ }
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+
+ // Accumulate the list of dependencies.
+ std::vector<std::string> depends2;
+ for(int i = 0; i < numDepends; ++i)
+ {
+ expand = depends[i];
+ depends2.push_back(mf->ExpandVariablesInString(expand));
+ }
+
+ // Accumulate the list of outputs.
+ std::vector<std::string> outputs2;
+ for(int i = 0; i < numOutputs; ++i)
+ {
+ expand = outputs[i];
+ outputs2.push_back(mf->ExpandVariablesInString(expand));
+ }
+
+ // Pass the call to the makefile instance.
+ const char* no_comment = 0;
+ mf->AddCustomCommandOldStyle(target, outputs2, depends2, source,
+ commandLines, no_comment);
+}
+
+void CCONV cmAddCustomCommandToOutput(void *arg, const char* output,
+ const char* command,
+ int numArgs, const char **args,
+ const char* main_dependency,
+ int numDepends, const char **depends)
+{
+ // Get the makefile instance. Perform an extra variable expansion
+ // now because the API caller expects it.
+ cmMakefile* mf = static_cast<cmMakefile*>(arg);
+
+ // Construct the command line for the command.
+ cmCustomCommandLine commandLine;
+ std::string expand = command;
+ commandLine.push_back(mf->ExpandVariablesInString(expand));
+ for(int i=0; i < numArgs; ++i)
+ {
+ expand = args[i];
+ commandLine.push_back(mf->ExpandVariablesInString(expand));
+ }
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+
+ // Accumulate the list of dependencies.
+ std::vector<std::string> depends2;
+ for(int i = 0; i < numDepends; ++i)
+ {
+ expand = depends[i];
+ depends2.push_back(mf->ExpandVariablesInString(expand));
+ }
+
+ // Pass the call to the makefile instance.
+ const char* no_comment = 0;
+ const char* no_working_dir = 0;
+ mf->AddCustomCommandToOutput(output, depends2, main_dependency,
+ commandLines, no_comment, no_working_dir);
+}
+
+void CCONV cmAddCustomCommandToTarget(void *arg, const char* target,
+ const char* command,
+ int numArgs, const char **args,
+ int commandType)
+{
+ // Get the makefile instance.
+ cmMakefile* mf = static_cast<cmMakefile*>(arg);
+
+ // Construct the command line for the command. Perform an extra
+ // variable expansion now because the API caller expects it.
+ cmCustomCommandLine commandLine;
+ std::string expand = command;
+ commandLine.push_back(mf->ExpandVariablesInString(expand));
+ for(int i=0; i < numArgs; ++i)
+ {
+ expand = args[i];
+ commandLine.push_back(mf->ExpandVariablesInString(expand));
+ }
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+
+ // Select the command type.
+ cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
+ switch (commandType)
+ {
+ case CM_PRE_BUILD:
+ cctype = cmTarget::PRE_BUILD;
+ break;
+ case CM_PRE_LINK:
+ cctype = cmTarget::PRE_LINK;
+ break;
+ case CM_POST_BUILD:
+ cctype = cmTarget::POST_BUILD;
+ break;
+ }
+
+ // Pass the call to the makefile instance.
+ std::vector<std::string> no_depends;
+ const char* no_comment = 0;
+ const char* no_working_dir = 0;
+ mf->AddCustomCommandToTarget(target, no_depends, commandLines,
+ cctype, no_comment, no_working_dir);
+}
+
+void CCONV cmAddLinkLibraryForTarget(void *arg, const char *tgt,
+ const char*value, int libtype)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+
+ switch (libtype)
+ {
+ case CM_LIBRARY_GENERAL:
+ mf->AddLinkLibraryForTarget(tgt,value, cmTarget::GENERAL);
+ break;
+ case CM_LIBRARY_DEBUG:
+ mf->AddLinkLibraryForTarget(tgt,value, cmTarget::DEBUG);
+ break;
+ case CM_LIBRARY_OPTIMIZED:
+ mf->AddLinkLibraryForTarget(tgt,value, cmTarget::OPTIMIZED);
+ break;
+ }
+}
+
+void CCONV cmAddLibrary(void *arg, const char *libname, int shared,
+ int numSrcs, const char **srcs)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ std::vector<std::string> srcs2;
+ int i;
+ for (i = 0; i < numSrcs; ++i)
+ {
+ srcs2.push_back(srcs[i]);
+ }
+ mf->AddLibrary(libname,
+ (shared? cmTarget::SHARED_LIBRARY : cmTarget::STATIC_LIBRARY),
+ srcs2);
+}
+
+char CCONV *cmExpandVariablesInString(void *arg, const char *source,
+ int escapeQuotes, int atOnly)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ std::string barf = source;
+ std::string result =
+ mf->ExpandVariablesInString(barf,
+ (escapeQuotes ? true : false),
+ (atOnly ? true : false));
+ char *res = static_cast<char *>(malloc(result.size() + 1));
+ if (result.size())
+ {
+ strcpy(res,result.c_str());
+ }
+ res[result.size()] = '\0';
+ return res;
+}
+
+
+int CCONV cmExecuteCommand(void *arg, const char *name,
+ int numArgs, const char **args)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ cmListFileFunction lff;
+ lff.Name = name;
+ for(int i = 0; i < numArgs; ++i)
+ {
+ // Assume all arguments are quoted.
+ lff.Arguments.push_back(
+ cmListFileArgument(args[i], cmListFileArgument::Quoted,
+ "[CMake-Plugin]", 0));
+ }
+ cmExecutionStatus status;
+ return mf->ExecuteCommand(lff,status);
+}
+
+void CCONV cmExpandSourceListArguments(void *arg,
+ int numArgs,
+ const char **args,
+ int *resArgc,
+ char ***resArgv,
+ unsigned int startArgumentIndex)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ std::vector<std::string> result;
+ std::vector<std::string> args2;
+ int i;
+ for (i = 0; i < numArgs; ++i)
+ {
+ args2.push_back(args[i]);
+ }
+ mf->ExpandSourceListArguments(args2, result, startArgumentIndex);
+ int resargc = static_cast<int>(result.size());
+ char **resargv = 0;
+ if (resargc)
+ {
+ resargv = (char **)malloc(resargc*sizeof(char *));
+ }
+ for (i = 0; i < resargc; ++i)
+ {
+ resargv[i] = strdup(result[i].c_str());
+ }
+ *resArgc = resargc;
+ *resArgv = resargv;
+}
+
+void CCONV cmFreeArguments(int argc, char **argv)
+{
+ int i;
+ for (i = 0; i < argc; ++i)
+ {
+ free(argv[i]);
+ }
+ if (argv)
+ {
+ free(argv);
+ }
+}
+
+int CCONV cmGetTotalArgumentSize(int argc, char **argv)
+{
+ int i;
+ int result = 0;
+ for (i = 0; i < argc; ++i)
+ {
+ if (argv[i])
+ {
+ result = result + static_cast<int>(strlen(argv[i]));
+ }
+ }
+ return result;
+}
+
+// Source file proxy object to support the old cmSourceFile/cmMakefile
+// API for source files.
+struct cmCPluginAPISourceFile
+{
+ cmCPluginAPISourceFile(): RealSourceFile(0) {}
+ cmSourceFile* RealSourceFile;
+ std::string SourceName;
+ std::string SourceExtension;
+ std::string FullPath;
+ std::vector<std::string> Depends;
+ cmPropertyMap Properties;
+};
+
+// Keep a map from real cmSourceFile instances stored in a makefile to
+// the CPluginAPI proxy source file.
+class cmCPluginAPISourceFileMap:
+ public std::map<cmSourceFile*, cmCPluginAPISourceFile*>
+{
+public:
+ typedef std::map<cmSourceFile*, cmCPluginAPISourceFile*> derived;
+ typedef derived::iterator iterator;
+ typedef derived::value_type value_type;
+ ~cmCPluginAPISourceFileMap()
+ {
+ for(iterator i=this->begin(); i != this->end(); ++i)
+ {
+ delete i->second;
+ }
+ }
+};
+cmCPluginAPISourceFileMap cmCPluginAPISourceFiles;
+
+void * CCONV cmCreateSourceFile(void)
+{
+ return (void*)new cmCPluginAPISourceFile;
+}
+
+void * CCONV cmCreateNewSourceFile(void *arg)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ cmCPluginAPISourceFile *sf = new cmCPluginAPISourceFile;
+ sf->Properties.SetCMakeInstance(mf->GetCMakeInstance());
+ return (void*)sf;
+}
+
+void CCONV cmDestroySourceFile(void *arg)
+{
+ cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
+ // Only delete if it was created by cmCreateSourceFile or
+ // cmCreateNewSourceFile and is therefore not in the map.
+ if(!sf->RealSourceFile)
+ {
+ delete sf;
+ }
+}
+
+void CCONV *cmGetSource(void *arg, const char *name)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ if(cmSourceFile* rsf = mf->GetSource(name))
+ {
+ // Lookup the proxy source file object for this source.
+ cmCPluginAPISourceFileMap::iterator i = cmCPluginAPISourceFiles.find(rsf);
+ if(i == cmCPluginAPISourceFiles.end())
+ {
+ // Create a proxy source file object for this source.
+ cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
+ sf->RealSourceFile = rsf;
+ sf->FullPath = rsf->GetFullPath();
+ sf->SourceName =
+ cmSystemTools::GetFilenameWithoutLastExtension(sf->FullPath);
+ sf->SourceExtension =
+ cmSystemTools::GetFilenameLastExtension(sf->FullPath);
+
+ // Store the proxy in the map so it can be re-used and deleted later.
+ cmCPluginAPISourceFileMap::value_type entry(rsf, sf);
+ i = cmCPluginAPISourceFiles.insert(entry).first;
+ }
+ return (void *)i->second;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+void * CCONV cmAddSource(void *arg, void *arg2)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ cmCPluginAPISourceFile* osf = static_cast<cmCPluginAPISourceFile*>(arg2);
+ if(osf->FullPath.empty())
+ {
+ return 0;
+ }
+
+ // Create the real cmSourceFile instance and copy over saved information.
+ cmSourceFile* rsf = mf->GetOrCreateSource(osf->FullPath);
+ rsf->GetProperties() = osf->Properties;
+ for(std::vector<std::string>::iterator i = osf->Depends.begin();
+ i != osf->Depends.end(); ++i)
+ {
+ rsf->AddDepend(i->c_str());
+ }
+
+ // Create the proxy for the real source file.
+ cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
+ sf->RealSourceFile = rsf;
+ sf->FullPath = osf->FullPath;
+ sf->SourceName = osf->SourceName;
+ sf->SourceExtension = osf->SourceExtension;
+
+ // Store the proxy in the map so it can be re-used and deleted later.
+ cmCPluginAPISourceFiles[rsf] = sf;
+ return (void *)sf;
+}
+
+const char * CCONV cmSourceFileGetSourceName(void *arg)
+{
+ cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
+ return sf->SourceName.c_str();
+}
+
+const char * CCONV cmSourceFileGetFullPath(void *arg)
+{
+ cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
+ return sf->FullPath.c_str();
+}
+
+const char * CCONV cmSourceFileGetProperty(void *arg,const char *prop)
+{
+ cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
+ if(cmSourceFile* rsf = sf->RealSourceFile)
+ {
+ return rsf->GetProperty(prop);
+ }
+ else
+ {
+ if(!strcmp(prop,"LOCATION"))
+ {
+ return sf->FullPath.c_str();
+ }
+ bool chain = false;
+ // Ignore chain because old code will not expect it and it is a
+ // pain to implement here anyway.
+ return sf->Properties.GetPropertyValue(prop, cmProperty::SOURCE_FILE,
+ chain);
+ }
+}
+
+int CCONV cmSourceFileGetPropertyAsBool(void *arg,const char *prop)
+{
+ cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
+ if(cmSourceFile* rsf = sf->RealSourceFile)
+ {
+ return rsf->GetPropertyAsBool(prop) ? 1:0;
+ }
+ else
+ {
+ return cmSystemTools::IsOn(cmSourceFileGetProperty(arg, prop))? 1:0;
+ }
+}
+
+void CCONV cmSourceFileSetProperty(void *arg,const char *prop,
+ const char *value)
+{
+ cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
+ if(cmSourceFile* rsf = sf->RealSourceFile)
+ {
+ rsf->SetProperty(prop, value);
+ }
+ else if(prop)
+ {
+ if(!value) { value = "NOTFOUND"; }
+ sf->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE);
+ }
+}
+
+void CCONV cmSourceFileAddDepend(void *arg, const char *depend)
+{
+ cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
+ if(cmSourceFile* rsf = sf->RealSourceFile)
+ {
+ rsf->AddDepend(depend);
+ }
+ else
+ {
+ sf->Depends.push_back(depend);
+ }
+}
+
+void CCONV cmSourceFileSetName(void *arg, const char* name, const char* dir,
+ int numSourceExtensions,
+ const char **sourceExtensions,
+ int numHeaderExtensions,
+ const char **headerExtensions)
+{
+ cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
+ if(sf->RealSourceFile)
+ {
+ // SetName is allowed only on temporary source files created by
+ // the command for building and passing to AddSource.
+ return;
+ }
+ std::vector<std::string> sourceExts;
+ std::vector<std::string> headerExts;
+ int i;
+ for (i = 0; i < numSourceExtensions; ++i)
+ {
+ sourceExts.push_back(sourceExtensions[i]);
+ }
+ for (i = 0; i < numHeaderExtensions; ++i)
+ {
+ headerExts.push_back(headerExtensions[i]);
+ }
+
+ // Save the original name given.
+ sf->SourceName = name;
+
+ // Convert the name to a full path in case the given name is a
+ // relative path.
+ std::string pathname = cmSystemTools::CollapseFullPath(name, dir);
+
+ // First try and see whether the listed file can be found
+ // as is without extensions added on.
+ std::string hname = pathname;
+ if(cmSystemTools::FileExists(hname.c_str()))
+ {
+ sf->SourceName = cmSystemTools::GetFilenamePath(name);
+ if ( sf->SourceName.size() > 0 )
+ {
+ sf->SourceName += "/";
+ }
+ sf->SourceName += cmSystemTools::GetFilenameWithoutLastExtension(name);
+ std::string::size_type pos = hname.rfind('.');
+ if(pos != std::string::npos)
+ {
+ sf->SourceExtension = hname.substr(pos+1, hname.size()-pos);
+ if ( cmSystemTools::FileIsFullPath(name) )
+ {
+ std::string::size_type pos2 = hname.rfind('/');
+ if(pos2 != std::string::npos)
+ {
+ sf->SourceName = hname.substr(pos2+1, pos - pos2-1);
+ }
+ }
+ }
+
+ sf->FullPath = hname;
+ return;
+ }
+
+ // Next, try the various source extensions
+ for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
+ ext != sourceExts.end(); ++ext )
+ {
+ hname = pathname;
+ hname += ".";
+ hname += *ext;
+ if(cmSystemTools::FileExists(hname.c_str()))
+ {
+ sf->SourceExtension = *ext;
+ sf->FullPath = hname;
+ return;
+ }
+ }
+
+ // Finally, try the various header extensions
+ for( std::vector<std::string>::const_iterator ext = headerExts.begin();
+ ext != headerExts.end(); ++ext )
+ {
+ hname = pathname;
+ hname += ".";
+ hname += *ext;
+ if(cmSystemTools::FileExists(hname.c_str()))
+ {
+ sf->SourceExtension = *ext;
+ sf->FullPath = hname;
+ return;
+ }
+ }
+
+ cmOStringStream e;
+ e << "Cannot find source file \"" << pathname << "\"";
+ e << "\n\nTried extensions";
+ for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
+ ext != sourceExts.end(); ++ext )
+ {
+ e << " ." << *ext;
+ }
+ for( std::vector<std::string>::const_iterator ext = headerExts.begin();
+ ext != headerExts.end(); ++ext )
+ {
+ e << " ." << *ext;
+ }
+ cmSystemTools::Error(e.str().c_str());
+ return;
+}
+
+void CCONV cmSourceFileSetName2(void *arg, const char* name, const char* dir,
+ const char *ext, int headerFileOnly)
+{
+ cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
+ if(sf->RealSourceFile)
+ {
+ // SetName is allowed only on temporary source files created by
+ // the command for building and passing to AddSource.
+ return;
+ }
+
+ // Implement the old SetName method code here.
+ if(headerFileOnly)
+ {
+ sf->Properties.SetProperty("HEADER_FILE_ONLY", "1",
+ cmProperty::SOURCE_FILE);
+ }
+ sf->SourceName = name;
+ std::string fname = sf->SourceName;
+ if(ext && strlen(ext))
+ {
+ fname += ".";
+ fname += ext;
+ }
+ sf->FullPath = cmSystemTools::CollapseFullPath(fname.c_str(), dir);
+ cmSystemTools::ConvertToUnixSlashes(sf->FullPath);
+ sf->SourceExtension = ext;
+}
+
+char * CCONV cmGetFilenameWithoutExtension(const char *name)
+{
+ std::string sres = cmSystemTools::GetFilenameWithoutExtension(name);
+ char *result = (char *)malloc(sres.size()+1);
+ strcpy(result,sres.c_str());
+ return result;
+}
+
+char * CCONV cmGetFilenamePath(const char *name)
+{
+ std::string sres = cmSystemTools::GetFilenamePath(name);
+ char *result = (char *)malloc(sres.size()+1);
+ strcpy(result,sres.c_str());
+ return result;
+}
+
+char * CCONV cmCapitalized(const char *name)
+{
+ std::string sres = cmSystemTools::Capitalized(name);
+ char *result = (char *)malloc(sres.size()+1);
+ strcpy(result,sres.c_str());
+ return result;
+}
+
+void CCONV cmCopyFileIfDifferent(const char *name1, const char *name2)
+{
+ cmSystemTools::CopyFileIfDifferent(name1,name2);
+}
+
+void CCONV cmRemoveFile(const char *name)
+{
+ cmSystemTools::RemoveFile(name);
+}
+
+void CCONV cmDisplayStatus(void *arg, const char* message)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ mf->DisplayStatus(message, -1);
+}
+
+void CCONV cmFree(void *data)
+{
+ free(data);
+}
+
+void CCONV DefineSourceFileProperty (void *arg, const char *name,
+ const char *briefDocs,
+ const char *longDocs,
+ int chained)
+{
+ cmMakefile *mf = static_cast<cmMakefile *>(arg);
+ mf->GetCMakeInstance()->DefineProperty(name,cmProperty::SOURCE_FILE,
+ briefDocs, longDocs,
+ chained != 0);
+}
+
+} // close the extern "C" scope
+
+cmCAPI cmStaticCAPI =
+{
+ cmGetClientData,
+ cmGetTotalArgumentSize,
+ cmFreeArguments,
+ cmSetClientData,
+ cmSetError,
+ cmAddCacheDefinition,
+ cmAddCustomCommand,
+ cmAddDefineFlag,
+ cmAddDefinition,
+ cmAddExecutable,
+ cmAddLibrary,
+ cmAddLinkDirectoryForTarget,
+ cmAddLinkLibraryForTarget,
+ cmAddUtilityCommand,
+ cmCommandExists,
+ cmExecuteCommand,
+ cmExpandSourceListArguments,
+ cmExpandVariablesInString,
+ cmGetCacheMajorVersion,
+ cmGetCacheMinorVersion,
+ cmGetCurrentDirectory,
+ cmGetCurrentOutputDirectory,
+ cmGetDefinition,
+ cmGetHomeDirectory,
+ cmGetHomeOutputDirectory,
+ cmGetMajorVersion,
+ cmGetMinorVersion,
+ cmGetProjectName,
+ cmGetStartDirectory,
+ cmGetStartOutputDirectory,
+ cmIsOn,
+
+ cmAddSource,
+ cmCreateSourceFile,
+ cmDestroySourceFile,
+ cmGetSource,
+ cmSourceFileAddDepend,
+ cmSourceFileGetProperty,
+ cmSourceFileGetPropertyAsBool,
+ cmSourceFileGetSourceName,
+ cmSourceFileGetFullPath,
+ cmSourceFileSetName,
+ cmSourceFileSetName2,
+ cmSourceFileSetProperty,
+
+ cmCapitalized,
+ cmCopyFileIfDifferent,
+ cmGetFilenameWithoutExtension,
+ cmGetFilenamePath,
+ cmRemoveFile,
+ cmFree,
+
+ cmAddCustomCommandToOutput,
+ cmAddCustomCommandToTarget,
+ cmDisplayStatus,
+ cmCreateNewSourceFile,
+ DefineSourceFileProperty,
+};
+
diff --git a/Source/cmCPluginAPI.h b/Source/cmCPluginAPI.h
new file mode 100644
index 0000000000..5c832c30e7
--- /dev/null
+++ b/Source/cmCPluginAPI.h
@@ -0,0 +1,243 @@
+/*============================================================================
+ 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.
+============================================================================*/
+/* This header file defines the API that loadable commands can use. In many
+ of these commands C++ instances of cmMakefile of cmSourceFile are passed
+ in as arguments or returned. In these cases they are passed as a void *
+ argument. In the function prototypes mf is used to represent a makefile
+ and sf is used to represent a source file. The functions are grouped
+ loosely into four groups 1) Utility 2) cmMakefile 3) cmSourceFile 4)
+ cmSystemTools. Within each grouping functions are listed alphabetically */
+/*=========================================================================*/
+#ifndef cmCPluginAPI_h
+#define cmCPluginAPI_h
+
+#define CMAKE_VERSION_MAJOR 2
+#define CMAKE_VERSION_MINOR 5
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __WATCOMC__
+#define CCONV __cdecl
+#else
+#define CCONV
+#endif
+/*=========================================================================
+this is the structure of function entry points that a plugin may call. This
+structure must be kept in sync with the static decaled at the bottom of
+cmCPLuginAPI.cxx
+=========================================================================*/
+typedef struct
+{
+ /*=========================================================================
+ Here we define the set of functions that a plugin may call. The first goup
+ of functions are utility functions that are specific to the plugin API
+ =========================================================================*/
+ /* set/Get the ClientData in the cmLoadedCommandInfo structure, this is how
+ information is passed from the InitialPass to FInalPass for commands
+ that need a FinalPass and need information from the InitialPass */
+ void *(CCONV *GetClientData) (void *info);
+ /* return the summed size in characters of all the arguments */
+ int (CCONV *GetTotalArgumentSize) (int argc, char **argv);
+ /* free all the memory associated with an argc, argv pair */
+ void (CCONV *FreeArguments) (int argc, char **argv);
+ /* set/Get the ClientData in the cmLoadedCommandInfo structure, this is how
+ information is passed from the InitialPass to FInalPass for commands
+ that need a FinalPass and need information from the InitialPass */
+ void (CCONV *SetClientData) (void *info, void *cd);
+ /* when an error occurs, call this function to set the error string */
+ void (CCONV *SetError) (void *info, const char *err);
+
+ /*=========================================================================
+ The following functions all directly map to methods in the cmMakefile
+ class. See cmMakefile.h for descriptions of what each method does. All of
+ these methods take the void * makefile pointer as their first argument.
+ =========================================================================*/
+ void (CCONV *AddCacheDefinition) (void *mf, const char* name,
+ const char* value,
+ const char* doc, int cachetype);
+ void (CCONV *AddCustomCommand) (void *mf, const char* source,
+ const char* command,
+ int numArgs, const char **args,
+ int numDepends, const char **depends,
+ int numOutputs, const char **outputs,
+ const char *target);
+ void (CCONV *AddDefineFlag) (void *mf, const char* definition);
+ void (CCONV *AddDefinition) (void *mf, const char* name,
+ const char* value);
+ void (CCONV *AddExecutable) (void *mf, const char *exename,
+ int numSrcs, const char **srcs, int win32);
+ void (CCONV *AddLibrary) (void *mf, const char *libname,
+ int shared, int numSrcs, const char **srcs);
+ void (CCONV *AddLinkDirectoryForTarget) (void *mf, const char *tgt,
+ const char* d);
+ void (CCONV *AddLinkLibraryForTarget) (void *mf, const char *tgt,
+ const char *libname, int libtype);
+ void (CCONV *AddUtilityCommand) (void *mf, const char* utilityName,
+ const char *command, const char *arguments,
+ int all, int numDepends, const char **depends,
+ int numOutputs, const char **outputs);
+ int (CCONV *CommandExists) (void *mf, const char* name);
+ int (CCONV *ExecuteCommand) (void *mf, const char *name,
+ int numArgs, const char **args);
+ void (CCONV *ExpandSourceListArguments) (void *mf,int argc,
+ const char **argv,
+ int *resArgc, char ***resArgv,
+ unsigned int startArgumentIndex);
+ char *(CCONV *ExpandVariablesInString) (void *mf, const char *source,
+ int escapeQuotes, int atOnly);
+ unsigned int (CCONV *GetCacheMajorVersion) (void *mf);
+ unsigned int (CCONV *GetCacheMinorVersion) (void *mf);
+ const char* (CCONV *GetCurrentDirectory) (void *mf);
+ const char* (CCONV *GetCurrentOutputDirectory) (void *mf);
+ const char* (CCONV *GetDefinition) (void *mf, const char *def);
+ const char* (CCONV *GetHomeDirectory) (void *mf);
+ const char* (CCONV *GetHomeOutputDirectory) (void *mf);
+ unsigned int (CCONV *GetMajorVersion) (void *mf);
+ unsigned int (CCONV *GetMinorVersion) (void *mf);
+ const char* (CCONV *GetProjectName) (void *mf);
+ const char* (CCONV *GetStartDirectory) (void *mf);
+ const char* (CCONV *GetStartOutputDirectory) (void *mf);
+ int (CCONV *IsOn) (void *mf, const char* name);
+
+
+ /*=========================================================================
+ The following functions are designed to operate or manipulate
+ cmSourceFiles. Please see cmSourceFile.h for additional information on many
+ of these methods. Some of these methods are in cmMakefile.h.
+ =========================================================================*/
+ void *(CCONV *AddSource) (void *mf, void *sf);
+ void *(CCONV *CreateSourceFile) ();
+ void (CCONV *DestroySourceFile) (void *sf);
+ void *(CCONV *GetSource) (void *mf, const char* sourceName);
+ void (CCONV *SourceFileAddDepend) (void *sf, const char *depend);
+ const char *(CCONV *SourceFileGetProperty) (void *sf, const char *prop);
+ int (CCONV *SourceFileGetPropertyAsBool) (void *sf, const char *prop);
+ const char *(CCONV *SourceFileGetSourceName) (void *sf);
+ const char *(CCONV *SourceFileGetFullPath) (void *sf);
+ void (CCONV *SourceFileSetName) (void *sf, const char* name,
+ const char* dir,
+ int numSourceExtensions,
+ const char **sourceExtensions,
+ int numHeaderExtensions,
+ const char **headerExtensions);
+ void (CCONV *SourceFileSetName2) (void *sf, const char* name,
+ const char* dir,
+ const char *ext, int headerFileOnly);
+ void (CCONV *SourceFileSetProperty) (void *sf, const char *prop,
+ const char *value);
+
+
+ /*=========================================================================
+ The following methods are from cmSystemTools.h see that file for specific
+ documentation on each method.
+ =========================================================================*/
+ char *(CCONV *Capitalized)(const char *);
+ void (CCONV *CopyFileIfDifferent)(const char *f1, const char *f2);
+ char *(CCONV *GetFilenameWithoutExtension)(const char *);
+ char *(CCONV *GetFilenamePath)(const char *);
+ void (CCONV *RemoveFile)(const char *f1);
+ void (CCONV *Free)(void *);
+
+ /*=========================================================================
+ The following are new functions added after 1.6
+ =========================================================================*/
+ void (CCONV *AddCustomCommandToOutput) (void *mf, const char* output,
+ const char* command,
+ int numArgs, const char **args,
+ const char* main_dependency,
+ int numDepends, const char **depends);
+ void (CCONV *AddCustomCommandToTarget) (void *mf, const char* target,
+ const char* command,
+ int numArgs, const char **args,
+ int commandType);
+
+ /* display status information */
+ void (CCONV *DisplaySatus) (void *info, const char *message);
+
+ /* new functions added after 2.4 */
+ void *(CCONV *CreateNewSourceFile) (void *mf);
+ void (CCONV *DefineSourceFileProperty) (void *mf, const char *name,
+ const char *briefDocs,
+ const char *longDocs,
+ int chained);
+
+ /* this is the end of the C function stub API structure */
+} cmCAPI;
+
+
+/*=========================================================================
+CM_PLUGIN_EXPORT should be used by plugins
+=========================================================================*/
+#ifdef _WIN32
+#define CM_PLUGIN_EXPORT __declspec( dllexport )
+#else
+#define CM_PLUGIN_EXPORT
+#endif
+
+/*=========================================================================
+define the different types of cache entries, see cmCacheManager.h for more
+information
+=========================================================================*/
+#define CM_CACHE_BOOL 0
+#define CM_CACHE_PATH 1
+#define CM_CACHE_FILEPATH 2
+#define CM_CACHE_STRING 3
+#define CM_CACHE_INTERNAL 4
+#define CM_CACHE_STATIC 5
+
+/*=========================================================================
+define the different types of compiles a library may be
+=========================================================================*/
+#define CM_LIBRARY_GENERAL 0
+#define CM_LIBRARY_DEBUG 1
+#define CM_LIBRARY_OPTIMIZED 2
+
+/*=========================================================================
+define the different types of custom commands for a target
+=========================================================================*/
+#define CM_PRE_BUILD 0
+#define CM_PRE_LINK 1
+#define CM_POST_BUILD 2
+
+/*=========================================================================
+Finally we define the key data structures and function prototypes
+=========================================================================*/
+ typedef const char* (CCONV *CM_DOC_FUNCTION)();
+ typedef int (CCONV *CM_INITIAL_PASS_FUNCTION)(void *info, void *mf,
+ int argc, char *[]);
+ typedef void (CCONV *CM_FINAL_PASS_FUNCTION)(void *info, void *mf);
+ typedef void (CCONV *CM_DESTRUCTOR_FUNCTION)(void *info);
+
+ typedef struct {
+ unsigned long reserved1; /* Reserved for future use. DO NOT USE. */
+ unsigned long reserved2; /* Reserved for future use. DO NOT USE. */
+ cmCAPI *CAPI;
+ int m_Inherited; /* this ivar is no longer used in CMake 2.2 or later */
+ CM_INITIAL_PASS_FUNCTION InitialPass;
+ CM_FINAL_PASS_FUNCTION FinalPass;
+ CM_DESTRUCTOR_FUNCTION Destructor;
+ CM_DOC_FUNCTION GetTerseDocumentation;
+ CM_DOC_FUNCTION GetFullDocumentation;
+ const char *Name;
+ char *Error;
+ void *ClientData;
+ } cmLoadedCommandInfo;
+
+ typedef void (CCONV *CM_INIT_FUNCTION)(cmLoadedCommandInfo *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
new file mode 100644
index 0000000000..a7905a4e00
--- /dev/null
+++ b/Source/cmCTest.cxx
@@ -0,0 +1,3207 @@
+/*============================================================================
+ 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 "cm_curl.h"
+
+#include "cmCTest.h"
+#include "cmake.h"
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include <cmsys/Base64.h>
+#include <cmsys/Directory.hxx>
+#include <cmsys/SystemInformation.hxx>
+#include <cmsys/FStream.hxx>
+#include "cmDynamicLoader.h"
+#include "cmGeneratedFileStream.h"
+#include "cmXMLSafe.h"
+#include "cmVersionMacros.h"
+#include "cmCTestCommand.h"
+#include "cmCTestStartCommand.h"
+
+#include "cmCTestBuildHandler.h"
+#include "cmCTestBuildAndTestHandler.h"
+#include "cmCTestConfigureHandler.h"
+#include "cmCTestCoverageHandler.h"
+#include "cmCTestMemCheckHandler.h"
+#include "cmCTestScriptHandler.h"
+#include "cmCTestSubmitHandler.h"
+#include "cmCTestTestHandler.h"
+#include "cmCTestUpdateHandler.h"
+#include "cmCTestUploadHandler.h"
+
+#include "cmVersion.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Process.h>
+#include <cmsys/Glob.hxx>
+
+#include <stdlib.h>
+#include <math.h>
+#include <float.h>
+#include <ctype.h>
+
+#include <cmsys/auto_ptr.hxx>
+
+#include <cm_zlib.h>
+#include <cmsys/Base64.h>
+
+#if defined(__BEOS__) || defined(__HAIKU__)
+#include <be/kernel/OS.h> /* disable_debugger() API. */
+#endif
+
+
+#define DEBUGOUT std::cout << __LINE__ << " "; std::cout
+#define DEBUGERR std::cerr << __LINE__ << " "; std::cerr
+
+//----------------------------------------------------------------------
+struct tm* cmCTest::GetNightlyTime(std::string str,
+ bool tomorrowtag)
+{
+ struct tm* lctime;
+ time_t tctime = time(0);
+ lctime = gmtime(&tctime);
+ char buf[1024];
+ // add todays year day and month to the time in str because
+ // curl_getdate no longer assumes the day is today
+ sprintf(buf, "%d%02d%02d %s",
+ lctime->tm_year+1900,
+ lctime->tm_mon +1,
+ lctime->tm_mday,
+ str.c_str());
+ cmCTestLog(this, OUTPUT, "Determine Nightly Start Time" << std::endl
+ << " Specified time: " << str << std::endl);
+ //Convert the nightly start time to seconds. Since we are
+ //providing only a time and a timezone, the current date of
+ //the local machine is assumed. Consequently, nightlySeconds
+ //is the time at which the nightly dashboard was opened or
+ //will be opened on the date of the current client machine.
+ //As such, this time may be in the past or in the future.
+ time_t ntime = curl_getdate(buf, &tctime);
+ cmCTestLog(this, DEBUG, " Get curl time: " << ntime << std::endl);
+ tctime = time(0);
+ cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl);
+
+ const int dayLength = 24 * 60 * 60;
+ cmCTestLog(this, DEBUG, "Seconds: " << tctime << std::endl);
+ while ( ntime > tctime )
+ {
+ // If nightlySeconds is in the past, this is the current
+ // open dashboard, then return nightlySeconds. If
+ // nightlySeconds is in the future, this is the next
+ // dashboard to be opened, so subtract 24 hours to get the
+ // time of the current open dashboard
+ ntime -= dayLength;
+ cmCTestLog(this, DEBUG, "Pick yesterday" << std::endl);
+ cmCTestLog(this, DEBUG, " Future time, subtract day: " << ntime
+ << std::endl);
+ }
+ while ( tctime > (ntime + dayLength) )
+ {
+ ntime += dayLength;
+ cmCTestLog(this, DEBUG, " Past time, add day: " << ntime << std::endl);
+ }
+ cmCTestLog(this, DEBUG, "nightlySeconds: " << ntime << std::endl);
+ cmCTestLog(this, DEBUG, " Current time: " << tctime
+ << " Nightly time: " << ntime << std::endl);
+ if ( tomorrowtag )
+ {
+ cmCTestLog(this, OUTPUT, " Use future tag, Add a day" << std::endl);
+ ntime += dayLength;
+ }
+ lctime = gmtime(&ntime);
+ return lctime;
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::CleanString(const std::string& str)
+{
+ std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
+ std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
+ if ( spos == str.npos )
+ {
+ return std::string();
+ }
+ if ( epos != str.npos )
+ {
+ epos = epos - spos + 1;
+ }
+ return str.substr(spos, epos);
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::CurrentTime()
+{
+ time_t currenttime = time(0);
+ struct tm* t = localtime(&currenttime);
+ //return ::CleanString(ctime(&currenttime));
+ char current_time[1024];
+ if ( this->ShortDateFormat )
+ {
+ strftime(current_time, 1000, "%b %d %H:%M %Z", t);
+ }
+ else
+ {
+ strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
+ }
+ cmCTestLog(this, DEBUG, " Current_Time: " << current_time << std::endl);
+ return cmXMLSafe(cmCTest::CleanString(current_time)).str();
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::GetCostDataFile()
+{
+ std::string fname = this->GetCTestConfiguration("CostDataFile");
+ if(fname == "")
+ {
+ fname= this->GetBinaryDir() + "/Testing/Temporary/CTestCostData.txt";
+ }
+ return fname;
+}
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+//----------------------------------------------------------------------------
+static size_t
+HTTPResponseCallback(void *ptr, size_t size, size_t nmemb, void *data)
+{
+ int realsize = (int)(size * nmemb);
+
+ std::string *response
+ = static_cast<std::string*>(data);
+ const char* chPtr = static_cast<char*>(ptr);
+ *response += chPtr;
+
+ return realsize;
+}
+
+//----------------------------------------------------------------------------
+int cmCTest::HTTPRequest(std::string url, HTTPMethod method,
+ std::string& response,
+ std::string fields,
+ std::string putFile, int timeout)
+{
+ CURL* curl;
+ FILE* file;
+ ::curl_global_init(CURL_GLOBAL_ALL);
+ curl = ::curl_easy_init();
+
+ //set request options based on method
+ switch(method)
+ {
+ case cmCTest::HTTP_POST:
+ ::curl_easy_setopt(curl, CURLOPT_POST, 1);
+ ::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str());
+ break;
+ case cmCTest::HTTP_PUT:
+ if(!cmSystemTools::FileExists(putFile.c_str()))
+ {
+ response = "Error: File ";
+ response += putFile + " does not exist.\n";
+ return -1;
+ }
+ ::curl_easy_setopt(curl, CURLOPT_PUT, 1);
+ file = cmsys::SystemTools::Fopen(putFile.c_str(), "rb");
+ ::curl_easy_setopt(curl, CURLOPT_INFILE, file);
+ //fall through to append GET fields
+ case cmCTest::HTTP_GET:
+ if(fields.size())
+ {
+ url += "?" + fields;
+ }
+ break;
+ }
+
+ ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+ ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
+ ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
+
+ //set response options
+ ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPResponseCallback);
+ ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&response);
+ ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+
+ CURLcode res = ::curl_easy_perform(curl);
+
+ ::curl_easy_cleanup(curl);
+ ::curl_global_cleanup();
+
+ return static_cast<int>(res);
+}
+#endif
+
+//----------------------------------------------------------------------
+std::string cmCTest::MakeURLSafe(const std::string& str)
+{
+ cmOStringStream ost;
+ char buffer[10];
+ for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
+ {
+ unsigned char ch = str[pos];
+ if ( ( ch > 126 || ch < 32 ||
+ ch == '&' ||
+ ch == '%' ||
+ ch == '+' ||
+ ch == '=' ||
+ ch == '@'
+ ) && ch != 9 )
+ {
+ sprintf(buffer, "%02x;", (unsigned int)ch);
+ ost << buffer;
+ }
+ else
+ {
+ ost << ch;
+ }
+ }
+ return ost.str();
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTest::DecodeURL(const std::string& in)
+{
+ std::string out;
+ for(const char* c = in.c_str(); *c; ++c)
+ {
+ if(*c == '%' && isxdigit(*(c+1)) && isxdigit(*(c+2)))
+ {
+ char buf[3] = {*(c+1), *(c+2), 0};
+ out.append(1, char(strtoul(buf, 0, 16)));
+ c += 2;
+ }
+ else
+ {
+ out.append(1, *c);
+ }
+ }
+ return out;
+}
+
+//----------------------------------------------------------------------
+cmCTest::cmCTest()
+{
+ this->LabelSummary = true;
+ this->ParallelLevel = 1;
+ this->ParallelLevelSetInCli = false;
+ this->SubmitIndex = 0;
+ this->Failover = false;
+ this->BatchJobs = false;
+ this->ForceNewCTestProcess = false;
+ this->TomorrowTag = false;
+ this->Verbose = false;
+
+ this->Debug = false;
+ this->ShowLineNumbers = false;
+ this->Quiet = false;
+ this->ExtraVerbose = false;
+ this->ProduceXML = false;
+ this->ShowOnly = false;
+ this->RunConfigurationScript = false;
+ this->UseHTTP10 = false;
+ this->PrintLabels = false;
+ this->CompressTestOutput = true;
+ this->CompressMemCheckOutput = true;
+ this->TestModel = cmCTest::EXPERIMENTAL;
+ this->MaxTestNameWidth = 30;
+ this->InteractiveDebugMode = true;
+ this->TimeOut = 0;
+ this->GlobalTimeout = 0;
+ this->LastStopTimeout = 24 * 60 * 60;
+ this->CompressXMLFiles = false;
+ this->CTestConfigFile = "";
+ this->ScheduleType = "";
+ this->StopTime = "";
+ this->NextDayStopTime = false;
+ this->OutputLogFile = 0;
+ this->OutputLogFileLastTag = -1;
+ this->SuppressUpdatingCTestConfiguration = false;
+ this->DartVersion = 1;
+ this->DropSiteCDash = false;
+ this->OutputTestOutputOnTestFailure = false;
+ this->ComputedCompressTestOutput = false;
+ this->ComputedCompressMemCheckOutput = false;
+ if(cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE"))
+ {
+ this->OutputTestOutputOnTestFailure = true;
+ }
+ this->InitStreams();
+
+ this->Parts[PartStart].SetName("Start");
+ this->Parts[PartUpdate].SetName("Update");
+ this->Parts[PartConfigure].SetName("Configure");
+ this->Parts[PartBuild].SetName("Build");
+ this->Parts[PartTest].SetName("Test");
+ this->Parts[PartCoverage].SetName("Coverage");
+ this->Parts[PartMemCheck].SetName("MemCheck");
+ this->Parts[PartSubmit].SetName("Submit");
+ this->Parts[PartNotes].SetName("Notes");
+ this->Parts[PartExtraFiles].SetName("ExtraFiles");
+ this->Parts[PartUpload].SetName("Upload");
+
+ // Fill the part name-to-id map.
+ for(Part p = PartStart; p != PartCount; p = Part(p+1))
+ {
+ this->PartMap[cmSystemTools::LowerCase(this->Parts[p].GetName())] = p;
+ }
+
+ this->ShortDateFormat = true;
+
+ this->TestingHandlers["build"] = new cmCTestBuildHandler;
+ this->TestingHandlers["buildtest"] = new cmCTestBuildAndTestHandler;
+ this->TestingHandlers["coverage"] = new cmCTestCoverageHandler;
+ this->TestingHandlers["script"] = new cmCTestScriptHandler;
+ this->TestingHandlers["test"] = new cmCTestTestHandler;
+ this->TestingHandlers["update"] = new cmCTestUpdateHandler;
+ this->TestingHandlers["configure"] = new cmCTestConfigureHandler;
+ this->TestingHandlers["memcheck"] = new cmCTestMemCheckHandler;
+ this->TestingHandlers["submit"] = new cmCTestSubmitHandler;
+ this->TestingHandlers["upload"] = new cmCTestUploadHandler;
+
+ cmCTest::t_TestingHandlers::iterator it;
+ for ( it = this->TestingHandlers.begin();
+ it != this->TestingHandlers.end(); ++ it )
+ {
+ it->second->SetCTestInstance(this);
+ }
+
+ // Make sure we can capture the build tool output.
+ cmSystemTools::EnableVSConsoleOutput();
+}
+
+//----------------------------------------------------------------------
+cmCTest::~cmCTest()
+{
+ cmCTest::t_TestingHandlers::iterator it;
+ for ( it = this->TestingHandlers.begin();
+ it != this->TestingHandlers.end(); ++ it )
+ {
+ delete it->second;
+ it->second = 0;
+ }
+ this->SetOutputLogFileName(0);
+}
+
+void cmCTest::SetParallelLevel(int level)
+{
+ this->ParallelLevel = level < 1 ? 1 : level;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTest::ShouldCompressTestOutput()
+{
+ if(!this->ComputedCompressTestOutput)
+ {
+ std::string cdashVersion = this->GetCDashVersion();
+ //version >= 1.6?
+ bool cdashSupportsGzip = cmSystemTools::VersionCompare(
+ cmSystemTools::OP_GREATER, cdashVersion.c_str(), "1.6") ||
+ cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
+ cdashVersion.c_str(), "1.6");
+ this->CompressTestOutput &= cdashSupportsGzip;
+ this->ComputedCompressTestOutput = true;
+ }
+ return this->CompressTestOutput;
+}
+
+//----------------------------------------------------------------------------
+bool cmCTest::ShouldCompressMemCheckOutput()
+{
+ if(!this->ComputedCompressMemCheckOutput)
+ {
+ std::string cdashVersion = this->GetCDashVersion();
+
+ bool compressionSupported = cmSystemTools::VersionCompare(
+ cmSystemTools::OP_GREATER, cdashVersion.c_str(), "1.9.0");
+ this->CompressMemCheckOutput &= compressionSupported;
+ this->ComputedCompressMemCheckOutput = true;
+ }
+ return this->CompressMemCheckOutput;
+}
+
+//----------------------------------------------------------------------------
+std::string cmCTest::GetCDashVersion()
+{
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ //First query the server. If that fails, fall back to the local setting
+ std::string response;
+ std::string url = "http://";
+ url += this->GetCTestConfiguration("DropSite");
+
+ std::string cdashUri = this->GetCTestConfiguration("DropLocation");
+ cdashUri = cdashUri.substr(0, cdashUri.find("/submit.php"));
+
+ int res = 1;
+ if ( ! cdashUri.empty() )
+ {
+ url += cdashUri + "/api/getversion.php";
+ res = cmCTest::HTTPRequest(url, cmCTest::HTTP_GET, response, "", "", 3);
+ }
+
+ return res ? this->GetCTestConfiguration("CDashVersion") : response;
+#else
+ return this->GetCTestConfiguration("CDashVersion");
+#endif
+}
+
+//----------------------------------------------------------------------------
+cmCTest::Part cmCTest::GetPartFromName(const char* name)
+{
+ // Look up by lower-case to make names case-insensitive.
+ std::string lower_name = cmSystemTools::LowerCase(name);
+ PartMapType::const_iterator i = this->PartMap.find(lower_name);
+ if(i != this->PartMap.end())
+ {
+ return i->second;
+ }
+
+ // The string does not name a valid part.
+ return PartCount;
+}
+
+//----------------------------------------------------------------------
+int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
+{
+ cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
+ if(!this->InteractiveDebugMode)
+ {
+ this->BlockTestErrorDiagnostics();
+ }
+ else
+ {
+ cmSystemTools::PutEnv("CTEST_INTERACTIVE_DEBUG_MODE=1");
+ }
+
+ this->BinaryDir = binary_dir;
+ cmSystemTools::ConvertToUnixSlashes(this->BinaryDir);
+
+ this->UpdateCTestConfiguration();
+
+ cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
+ if ( this->ProduceXML )
+ {
+ cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
+ cmCTestLog(this, OUTPUT,
+ " Site: " << this->GetCTestConfiguration("Site") << std::endl
+ << " Build name: "
+ << cmCTest::SafeBuildIdField(
+ this->GetCTestConfiguration("BuildName"))
+ << std::endl);
+ cmCTestLog(this, DEBUG, "Produce XML is on" << std::endl);
+ if ( this->TestModel == cmCTest::NIGHTLY &&
+ this->GetCTestConfiguration("NightlyStartTime").empty() )
+ {
+ cmCTestLog(this, WARNING,
+ "WARNING: No nightly start time found please set in"
+ " CTestConfig.cmake or DartConfig.cmake" << std::endl);
+ cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
+ return 0;
+ }
+ }
+
+ cmake cm;
+ cmGlobalGenerator gg;
+ gg.SetCMakeInstance(&cm);
+ cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
+ cmMakefile *mf = lg->GetMakefile();
+ if ( !this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), mf) )
+ {
+ cmCTestLog(this, DEBUG, "Cannot find custom configuration file tree"
+ << std::endl);
+ return 0;
+ }
+
+ if ( this->ProduceXML )
+ {
+ // Verify "Testing" directory exists:
+ //
+ std::string testingDir = this->BinaryDir + "/Testing";
+ if ( cmSystemTools::FileExists(testingDir.c_str()) )
+ {
+ if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "File " << testingDir
+ << " is in the place of the testing directory" << std::endl);
+ return 0;
+ }
+ }
+ else
+ {
+ if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory "
+ << testingDir << std::endl);
+ return 0;
+ }
+ }
+
+ // Create new "TAG" file or read existing one:
+ //
+ bool createNewTag = true;
+ if (command)
+ {
+ createNewTag = command->ShouldCreateNewTag();
+ }
+
+ std::string tagfile = testingDir + "/TAG";
+ cmsys::ifstream tfin(tagfile.c_str());
+ std::string tag;
+
+ if (createNewTag)
+ {
+ time_t tctime = time(0);
+ if ( this->TomorrowTag )
+ {
+ tctime += ( 24 * 60 * 60 );
+ }
+ struct tm *lctime = gmtime(&tctime);
+ if ( tfin && cmSystemTools::GetLineFromStream(tfin, tag) )
+ {
+ int year = 0;
+ int mon = 0;
+ int day = 0;
+ int hour = 0;
+ int min = 0;
+ sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
+ &year, &mon, &day, &hour, &min);
+ if ( year != lctime->tm_year + 1900 ||
+ mon != lctime->tm_mon+1 ||
+ day != lctime->tm_mday )
+ {
+ tag = "";
+ }
+ std::string tagmode;
+ if ( cmSystemTools::GetLineFromStream(tfin, tagmode) )
+ {
+ if (tagmode.size() > 4 && !this->Parts[PartStart])
+ {
+ this->TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
+ }
+ }
+ tfin.close();
+ }
+ if (tag.size() == 0 || (0 != command) || this->Parts[PartStart])
+ {
+ cmCTestLog(this, DEBUG, "TestModel: " << this->GetTestModelString()
+ << std::endl);
+ cmCTestLog(this, DEBUG, "TestModel: " << this->TestModel << std::endl);
+ if ( this->TestModel == cmCTest::NIGHTLY )
+ {
+ lctime = this->GetNightlyTime(
+ this->GetCTestConfiguration("NightlyStartTime"),
+ this->TomorrowTag);
+ }
+ char datestring[100];
+ sprintf(datestring, "%04d%02d%02d-%02d%02d",
+ lctime->tm_year + 1900,
+ lctime->tm_mon+1,
+ lctime->tm_mday,
+ lctime->tm_hour,
+ lctime->tm_min);
+ tag = datestring;
+ cmsys::ofstream ofs(tagfile.c_str());
+ if ( ofs )
+ {
+ ofs << tag << std::endl;
+ ofs << this->GetTestModelString() << std::endl;
+ }
+ ofs.close();
+ if ( 0 == command )
+ {
+ cmCTestLog(this, OUTPUT, "Create new tag: " << tag << " - "
+ << this->GetTestModelString() << std::endl);
+ }
+ }
+ }
+ else
+ {
+ if ( tfin )
+ {
+ cmSystemTools::GetLineFromStream(tfin, tag);
+ tfin.close();
+ }
+
+ if ( tag.empty() )
+ {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Cannot read existing TAG file in " << testingDir
+ << std::endl);
+ return 0;
+ }
+
+ cmCTestLog(this, OUTPUT, " Use existing tag: " << tag << " - "
+ << this->GetTestModelString() << std::endl);
+ }
+
+ this->CurrentTag = tag;
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::InitializeFromCommand(cmCTestStartCommand* command)
+{
+ std::string src_dir
+ = this->GetCTestConfiguration("SourceDirectory");
+ std::string bld_dir = this->GetCTestConfiguration("BuildDirectory");
+ this->DartVersion = 1;
+ this->DropSiteCDash = false;
+ for(Part p = PartStart; p != PartCount; p = Part(p+1))
+ {
+ this->Parts[p].SubmitFiles.clear();
+ }
+
+ cmMakefile* mf = command->GetMakefile();
+ std::string fname;
+
+ std::string src_dir_fname = src_dir;
+ src_dir_fname += "/CTestConfig.cmake";
+ cmSystemTools::ConvertToUnixSlashes(src_dir_fname);
+
+ std::string bld_dir_fname = bld_dir;
+ bld_dir_fname += "/CTestConfig.cmake";
+ cmSystemTools::ConvertToUnixSlashes(bld_dir_fname);
+
+ if ( cmSystemTools::FileExists(bld_dir_fname.c_str()) )
+ {
+ fname = bld_dir_fname;
+ }
+ else if ( cmSystemTools::FileExists(src_dir_fname.c_str()) )
+ {
+ fname = src_dir_fname;
+ }
+
+ if ( !fname.empty() )
+ {
+ cmCTestLog(this, OUTPUT, " Reading ctest configuration file: "
+ << fname << std::endl);
+ bool readit = mf->ReadListFile(mf->GetCurrentListFile(),
+ fname.c_str() );
+ if(!readit)
+ {
+ std::string m = "Could not find include file: ";
+ m += fname;
+ command->SetError(m);
+ return false;
+ }
+ }
+ else
+ {
+ cmCTestLog(this, WARNING,
+ "Cannot locate CTest configuration: in BuildDirectory: "
+ << bld_dir_fname << std::endl);
+ cmCTestLog(this, WARNING,
+ "Cannot locate CTest configuration: in SourceDirectory: "
+ << src_dir_fname << std::endl);
+ }
+
+ this->SetCTestConfigurationFromCMakeVariable(mf, "NightlyStartTime",
+ "CTEST_NIGHTLY_START_TIME");
+ this->SetCTestConfigurationFromCMakeVariable(mf, "Site", "CTEST_SITE");
+ this->SetCTestConfigurationFromCMakeVariable(mf, "BuildName",
+ "CTEST_BUILD_NAME");
+ const char* dartVersion = mf->GetDefinition("CTEST_DART_SERVER_VERSION");
+ if ( dartVersion )
+ {
+ this->DartVersion = atoi(dartVersion);
+ if ( this->DartVersion < 0 )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Invalid Dart server version: "
+ << dartVersion << ". Please specify the version number."
+ << std::endl);
+ return false;
+ }
+ }
+ this->DropSiteCDash = mf->IsOn("CTEST_DROP_SITE_CDASH");
+
+ if ( !this->Initialize(bld_dir.c_str(), command) )
+ {
+ return false;
+ }
+ cmCTestLog(this, OUTPUT, " Use " << this->GetTestModelString()
+ << " tag: " << this->GetCurrentTag() << std::endl);
+ return true;
+}
+
+
+//----------------------------------------------------------------------
+bool cmCTest::UpdateCTestConfiguration()
+{
+ if ( this->SuppressUpdatingCTestConfiguration )
+ {
+ return true;
+ }
+ std::string fileName = this->CTestConfigFile;
+ if ( fileName.empty() )
+ {
+ fileName = this->BinaryDir + "/CTestConfiguration.ini";
+ if ( !cmSystemTools::FileExists(fileName.c_str()) )
+ {
+ fileName = this->BinaryDir + "/DartConfiguration.tcl";
+ }
+ }
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "UpdateCTestConfiguration from :"
+ << fileName << "\n");
+ if ( !cmSystemTools::FileExists(fileName.c_str()) )
+ {
+ // No need to exit if we are not producing XML
+ if ( this->ProduceXML )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Cannot find file: " << fileName
+ << std::endl);
+ return false;
+ }
+ }
+ else
+ {
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Parse Config file:"
+ << fileName << "\n");
+ // parse the dart test file
+ cmsys::ifstream fin(fileName.c_str());
+
+ if(!fin)
+ {
+ return false;
+ }
+
+ char buffer[1024];
+ while ( fin )
+ {
+ buffer[0] = 0;
+ fin.getline(buffer, 1023);
+ buffer[1023] = 0;
+ std::string line = cmCTest::CleanString(buffer);
+ if(line.size() == 0)
+ {
+ continue;
+ }
+ while ( fin && (line[line.size()-1] == '\\') )
+ {
+ line = line.substr(0, line.size()-1);
+ buffer[0] = 0;
+ fin.getline(buffer, 1023);
+ buffer[1023] = 0;
+ line += cmCTest::CleanString(buffer);
+ }
+ if ( line[0] == '#' )
+ {
+ continue;
+ }
+ std::string::size_type cpos = line.find_first_of(":");
+ if ( cpos == line.npos )
+ {
+ continue;
+ }
+ std::string key = line.substr(0, cpos);
+ std::string value
+ = cmCTest::CleanString(line.substr(cpos+1, line.npos));
+ this->CTestConfiguration[key] = value;
+ }
+ fin.close();
+ }
+ if ( !this->GetCTestConfiguration("BuildDirectory").empty() )
+ {
+ this->BinaryDir = this->GetCTestConfiguration("BuildDirectory");
+ cmSystemTools::ChangeDirectory(this->BinaryDir.c_str());
+ }
+ this->TimeOut = atoi(this->GetCTestConfiguration("TimeOut").c_str());
+ if ( this->ProduceXML )
+ {
+ this->CompressXMLFiles = cmSystemTools::IsOn(
+ this->GetCTestConfiguration("CompressSubmission").c_str());
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+void cmCTest::BlockTestErrorDiagnostics()
+{
+ cmSystemTools::PutEnv("DART_TEST_FROM_DART=1");
+ cmSystemTools::PutEnv("DASHBOARD_TEST_FROM_CTEST=" CMake_VERSION);
+#if defined(_WIN32)
+ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
+#elif defined(__BEOS__) || defined(__HAIKU__)
+ disable_debugger(1);
+#endif
+}
+
+//----------------------------------------------------------------------
+void cmCTest::SetTestModel(int mode)
+{
+ this->InteractiveDebugMode = false;
+ this->TestModel = mode;
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::SetTest(const char* ttype, bool report)
+{
+ if ( cmSystemTools::LowerCase(ttype) == "all" )
+ {
+ for(Part p = PartStart; p != PartCount; p = Part(p+1))
+ {
+ this->Parts[p].Enable();
+ }
+ return true;
+ }
+ Part p = this->GetPartFromName(ttype);
+ if(p != PartCount)
+ {
+ this->Parts[p].Enable();
+ return true;
+ }
+ else
+ {
+ if ( report )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Don't know about test \"" << ttype
+ << "\" yet..." << std::endl);
+ }
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------
+void cmCTest::Finalize()
+{
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::OpenOutputFile(const std::string& path,
+ const std::string& name, cmGeneratedFileStream& stream,
+ bool compress)
+{
+ std::string testingDir = this->BinaryDir + "/Testing";
+ if ( path.size() > 0 )
+ {
+ testingDir += "/" + path;
+ }
+ if ( cmSystemTools::FileExists(testingDir.c_str()) )
+ {
+ if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "File " << testingDir
+ << " is in the place of the testing directory"
+ << std::endl);
+ return false;
+ }
+ }
+ else
+ {
+ if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory " << testingDir
+ << std::endl);
+ return false;
+ }
+ }
+ std::string filename = testingDir + "/" + name;
+ stream.Open(filename.c_str());
+ if( !stream )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Problem opening file: " << filename
+ << std::endl);
+ return false;
+ }
+ if ( compress )
+ {
+ if ( this->CompressXMLFiles )
+ {
+ stream.SetCompression(true);
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::AddIfExists(Part part, const char* file)
+{
+ if ( this->CTestFileExists(file) )
+ {
+ this->AddSubmitFile(part, file);
+ }
+ else
+ {
+ std::string name = file;
+ name += ".gz";
+ if ( this->CTestFileExists(name) )
+ {
+ this->AddSubmitFile(part, file);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::CTestFileExists(const std::string& filename)
+{
+ std::string testingDir = this->BinaryDir + "/Testing/" +
+ this->CurrentTag + "/" + filename;
+ return cmSystemTools::FileExists(testingDir.c_str());
+}
+
+//----------------------------------------------------------------------
+cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler)
+{
+ cmCTest::t_TestingHandlers::iterator it =
+ this->TestingHandlers.find(handler);
+ if ( it == this->TestingHandlers.end() )
+ {
+ return 0;
+ }
+ it->second->Initialize();
+ return it->second;
+}
+
+//----------------------------------------------------------------------
+cmCTestGenericHandler* cmCTest::GetHandler(const char* handler)
+{
+ cmCTest::t_TestingHandlers::iterator it =
+ this->TestingHandlers.find(handler);
+ if ( it == this->TestingHandlers.end() )
+ {
+ return 0;
+ }
+ return it->second;
+}
+
+//----------------------------------------------------------------------
+int cmCTest::ExecuteHandler(const char* shandler)
+{
+ cmCTestGenericHandler* handler = this->GetHandler(shandler);
+ if ( !handler )
+ {
+ return -1;
+ }
+ handler->Initialize();
+ return handler->ProcessHandler();
+}
+
+//----------------------------------------------------------------------
+int cmCTest::ProcessTests()
+{
+ int res = 0;
+ bool notest = true;
+ int update_count = 0;
+
+ for(Part p = PartStart; notest && p != PartCount; p = Part(p+1))
+ {
+ notest = !this->Parts[p];
+ }
+ if (this->Parts[PartUpdate] &&
+ (this->GetRemainingTimeAllowed() - 120 > 0))
+ {
+ cmCTestGenericHandler* uphandler = this->GetHandler("update");
+ uphandler->SetPersistentOption("SourceDirectory",
+ this->GetCTestConfiguration("SourceDirectory").c_str());
+ update_count = uphandler->ProcessHandler();
+ if ( update_count < 0 )
+ {
+ res |= cmCTest::UPDATE_ERRORS;
+ }
+ }
+ if ( this->TestModel == cmCTest::CONTINUOUS && !update_count )
+ {
+ return 0;
+ }
+ if (this->Parts[PartConfigure] &&
+ (this->GetRemainingTimeAllowed() - 120 > 0))
+ {
+ if (this->GetHandler("configure")->ProcessHandler() < 0)
+ {
+ res |= cmCTest::CONFIGURE_ERRORS;
+ }
+ }
+ if (this->Parts[PartBuild] &&
+ (this->GetRemainingTimeAllowed() - 120 > 0))
+ {
+ this->UpdateCTestConfiguration();
+ if (this->GetHandler("build")->ProcessHandler() < 0)
+ {
+ res |= cmCTest::BUILD_ERRORS;
+ }
+ }
+ if ((this->Parts[PartTest] || notest) &&
+ (this->GetRemainingTimeAllowed() - 120 > 0))
+ {
+ this->UpdateCTestConfiguration();
+ if (this->GetHandler("test")->ProcessHandler() < 0)
+ {
+ res |= cmCTest::TEST_ERRORS;
+ }
+ }
+ if (this->Parts[PartCoverage] &&
+ (this->GetRemainingTimeAllowed() - 120 > 0))
+ {
+ this->UpdateCTestConfiguration();
+ if (this->GetHandler("coverage")->ProcessHandler() < 0)
+ {
+ res |= cmCTest::COVERAGE_ERRORS;
+ }
+ }
+ if (this->Parts[PartMemCheck] &&
+ (this->GetRemainingTimeAllowed() - 120 > 0))
+ {
+ this->UpdateCTestConfiguration();
+ if (this->GetHandler("memcheck")->ProcessHandler() < 0)
+ {
+ res |= cmCTest::MEMORY_ERRORS;
+ }
+ }
+ if ( !notest )
+ {
+ std::string notes_dir = this->BinaryDir + "/Testing/Notes";
+ if ( cmSystemTools::FileIsDirectory(notes_dir.c_str()) )
+ {
+ cmsys::Directory d;
+ d.Load(notes_dir.c_str());
+ unsigned long kk;
+ for ( kk = 0; kk < d.GetNumberOfFiles(); kk ++ )
+ {
+ const char* file = d.GetFile(kk);
+ std::string fullname = notes_dir + "/" + file;
+ if ( cmSystemTools::FileExists(fullname.c_str()) &&
+ !cmSystemTools::FileIsDirectory(fullname.c_str()) )
+ {
+ if ( this->NotesFiles.size() > 0 )
+ {
+ this->NotesFiles += ";";
+ }
+ this->NotesFiles += fullname;
+ this->Parts[PartNotes].Enable();
+ }
+ }
+ }
+ }
+ if (this->Parts[PartNotes])
+ {
+ this->UpdateCTestConfiguration();
+ if ( this->NotesFiles.size() )
+ {
+ this->GenerateNotesFile(this->NotesFiles.c_str());
+ }
+ }
+ if (this->Parts[PartSubmit])
+ {
+ this->UpdateCTestConfiguration();
+ if (this->GetHandler("submit")->ProcessHandler() < 0)
+ {
+ res |= cmCTest::SUBMIT_ERRORS;
+ }
+ }
+ if ( res != 0 )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Errors while running CTest"
+ << std::endl);
+ }
+ return res;
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::GetTestModelString()
+{
+ if ( !this->SpecificTrack.empty() )
+ {
+ return this->SpecificTrack;
+ }
+ switch ( this->TestModel )
+ {
+ case cmCTest::NIGHTLY:
+ return "Nightly";
+ case cmCTest::CONTINUOUS:
+ return "Continuous";
+ }
+ return "Experimental";
+}
+
+//----------------------------------------------------------------------
+int cmCTest::GetTestModelFromString(const char* str)
+{
+ if ( !str )
+ {
+ return cmCTest::EXPERIMENTAL;
+ }
+ std::string rstr = cmSystemTools::LowerCase(str);
+ if ( cmHasLiteralPrefix(rstr.c_str(), "cont") )
+ {
+ return cmCTest::CONTINUOUS;
+ }
+ if ( cmHasLiteralPrefix(rstr.c_str(), "nigh") )
+ {
+ return cmCTest::NIGHTLY;
+ }
+ return cmCTest::EXPERIMENTAL;
+}
+
+//######################################################################
+//######################################################################
+//######################################################################
+//######################################################################
+
+//----------------------------------------------------------------------
+int cmCTest::RunMakeCommand(const char* command, std::string& output,
+ int* retVal, const char* dir, int timeout, std::ostream& ofs)
+{
+ // First generate the command and arguments
+ std::vector<std::string> args = cmSystemTools::ParseArguments(command);
+
+ if(args.size() < 1)
+ {
+ return false;
+ }
+
+ std::vector<const char*> argv;
+ for(std::vector<std::string>::const_iterator a = args.begin();
+ a != args.end(); ++a)
+ {
+ argv.push_back(a->c_str());
+ }
+ argv.push_back(0);
+
+ output = "";
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Run command:");
+ std::vector<const char*>::iterator ait;
+ for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
+ {
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
+ }
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, std::endl);
+
+ // Now create process object
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetWorkingDirectory(cp, dir);
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+ cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_Execute(cp);
+
+ // Initialize tick's
+ std::string::size_type tick = 0;
+ std::string::size_type tick_len = 1024;
+ std::string::size_type tick_line_len = 50;
+
+ char* data;
+ int length;
+ cmCTestLog(this, HANDLER_OUTPUT,
+ " Each . represents " << tick_len << " bytes of output" << std::endl
+ << " " << std::flush);
+ while(cmsysProcess_WaitForData(cp, &data, &length, 0))
+ {
+ for(int cc =0; cc < length; ++cc)
+ {
+ if(data[cc] == 0)
+ {
+ data[cc] = '\n';
+ }
+ }
+ output.append(data, length);
+ while ( output.size() > (tick * tick_len) )
+ {
+ tick ++;
+ cmCTestLog(this, HANDLER_OUTPUT, "." << std::flush);
+ if ( tick % tick_line_len == 0 && tick > 0 )
+ {
+ cmCTestLog(this, HANDLER_OUTPUT,
+ " Size: "
+ << int((double(output.size()) / 1024.0) + 1)
+ << "K" << std::endl
+ << " " << std::flush);
+ }
+ }
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length));
+ if ( ofs )
+ {
+ ofs << cmCTestLogWrite(data, length);
+ }
+ }
+ cmCTestLog(this, OUTPUT, " Size of output: "
+ << int(double(output.size()) / 1024.0) << "K" << std::endl);
+
+ cmsysProcess_WaitForExit(cp, 0);
+
+ int result = cmsysProcess_GetState(cp);
+
+ if(result == cmsysProcess_State_Exited)
+ {
+ *retVal = cmsysProcess_GetExitValue(cp);
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Command exited with the value: "
+ << *retVal << std::endl);
+ }
+ else if(result == cmsysProcess_State_Exception)
+ {
+ *retVal = cmsysProcess_GetExitException(cp);
+ cmCTestLog(this, WARNING, "There was an exception: " << *retVal
+ << std::endl);
+ }
+ else if(result == cmsysProcess_State_Expired)
+ {
+ cmCTestLog(this, WARNING, "There was a timeout" << std::endl);
+ }
+ else if(result == cmsysProcess_State_Error)
+ {
+ output += "\n*** ERROR executing: ";
+ output += cmsysProcess_GetErrorString(cp);
+ output += "\n***The build process failed.";
+ cmCTestLog(this, ERROR_MESSAGE, "There was an error: "
+ << cmsysProcess_GetErrorString(cp) << std::endl);
+ }
+
+ cmsysProcess_Delete(cp);
+
+ return result;
+}
+
+//######################################################################
+//######################################################################
+//######################################################################
+//######################################################################
+
+//----------------------------------------------------------------------
+int cmCTest::RunTest(std::vector<const char*> argv,
+ std::string* output, int *retVal,
+ std::ostream* log, double testTimeOut,
+ std::vector<std::string>* environment)
+{
+ bool modifyEnv = (environment && environment->size()>0);
+
+ // determine how much time we have
+ double timeout = this->GetRemainingTimeAllowed() - 120;
+ if (this->TimeOut > 0 && this->TimeOut < timeout)
+ {
+ timeout = this->TimeOut;
+ }
+ if (testTimeOut > 0
+ && testTimeOut < this->GetRemainingTimeAllowed())
+ {
+ timeout = testTimeOut;
+ }
+
+ // always have at least 1 second if we got to here
+ if (timeout <= 0)
+ {
+ timeout = 1;
+ }
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
+ "Test timeout computed to be: " << timeout << "\n");
+ if(cmSystemTools::SameFile(
+ argv[0], cmSystemTools::GetCTestCommand().c_str()) &&
+ !this->ForceNewCTestProcess)
+ {
+ cmCTest inst;
+ inst.ConfigType = this->ConfigType;
+ inst.TimeOut = timeout;
+
+ // Capture output of the child ctest.
+ cmOStringStream oss;
+ inst.SetStreams(&oss, &oss);
+
+ std::vector<std::string> args;
+ for(unsigned int i =0; i < argv.size(); ++i)
+ {
+ if(argv[i])
+ {
+ // make sure we pass the timeout in for any build and test
+ // invocations. Since --build-generator is required this is a
+ // good place to check for it, and to add the arguments in
+ if (strcmp(argv[i],"--build-generator") == 0 && timeout > 0)
+ {
+ args.push_back("--test-timeout");
+ cmOStringStream msg;
+ msg << timeout;
+ args.push_back(msg.str());
+ }
+ args.push_back(argv[i]);
+ }
+ }
+ if ( log )
+ {
+ *log << "* Run internal CTest" << std::endl;
+ }
+ std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
+
+ cmsys::auto_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
+ if (modifyEnv)
+ {
+ saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
+ cmSystemTools::AppendEnv(*environment);
+ }
+
+ *retVal = inst.Run(args, output);
+ *output += oss.str();
+ if ( log )
+ {
+ *log << *output;
+ }
+ cmSystemTools::ChangeDirectory(oldpath.c_str());
+
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
+ "Internal cmCTest object used to run test." << std::endl
+ << *output << std::endl);
+
+ return cmsysProcess_State_Exited;
+ }
+ std::vector<char> tempOutput;
+ if ( output )
+ {
+ *output = "";
+ }
+
+ cmsys::auto_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
+ if (modifyEnv)
+ {
+ saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
+ cmSystemTools::AppendEnv(*environment);
+ }
+
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl);
+ if(cmSystemTools::GetRunCommandHideConsole())
+ {
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+ }
+
+ cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_Execute(cp);
+
+ char* data;
+ int length;
+ while(cmsysProcess_WaitForData(cp, &data, &length, 0))
+ {
+ if ( output )
+ {
+ tempOutput.insert(tempOutput.end(), data, data+length);
+ }
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length));
+ if ( log )
+ {
+ log->write(data, length);
+ }
+ }
+
+ cmsysProcess_WaitForExit(cp, 0);
+ if(output && tempOutput.begin() != tempOutput.end())
+ {
+ output->append(&*tempOutput.begin(), tempOutput.size());
+ }
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "-- Process completed"
+ << std::endl);
+
+ int result = cmsysProcess_GetState(cp);
+
+ if(result == cmsysProcess_State_Exited)
+ {
+ *retVal = cmsysProcess_GetExitValue(cp);
+ if(*retVal != 0 && this->OutputTestOutputOnTestFailure)
+ {
+ OutputTestErrors(tempOutput);
+ }
+ }
+ else if(result == cmsysProcess_State_Exception)
+ {
+ if(this->OutputTestOutputOnTestFailure)
+ {
+ OutputTestErrors(tempOutput);
+ }
+ *retVal = cmsysProcess_GetExitException(cp);
+ std::string outerr = "\n*** Exception executing: ";
+ outerr += cmsysProcess_GetExceptionString(cp);
+ *output += outerr;
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl
+ << std::flush);
+ }
+ else if(result == cmsysProcess_State_Error)
+ {
+ std::string outerr = "\n*** ERROR executing: ";
+ outerr += cmsysProcess_GetErrorString(cp);
+ *output += outerr;
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl
+ << std::flush);
+ }
+ cmsysProcess_Delete(cp);
+
+ return result;
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::SafeBuildIdField(const std::string& value)
+{
+ std::string safevalue(value);
+
+ if (safevalue != "")
+ {
+ // Disallow non-filename and non-space whitespace characters.
+ // If they occur, replace them with ""
+ //
+ const char *disallowed = "\\:*?\"<>|\n\r\t\f\v";
+
+ if (safevalue.find_first_of(disallowed) != value.npos)
+ {
+ std::string::size_type i = 0;
+ std::string::size_type n = strlen(disallowed);
+ char replace[2];
+ replace[1] = 0;
+
+ for (i= 0; i<n; ++i)
+ {
+ replace[0] = disallowed[i];
+ cmSystemTools::ReplaceString(safevalue, replace, "");
+ }
+ }
+
+ safevalue = cmXMLSafe(safevalue).str();
+ }
+
+ if (safevalue == "")
+ {
+ safevalue = "(empty)";
+ }
+
+ return safevalue;
+}
+
+//----------------------------------------------------------------------
+void cmCTest::StartXML(std::ostream& ostr, bool append)
+{
+ if(this->CurrentTag.empty())
+ {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Current Tag empty, this may mean"
+ " NightlStartTime was not set correctly." << std::endl);
+ cmSystemTools::SetFatalErrorOccured();
+ }
+
+ // find out about the system
+ cmsys::SystemInformation info;
+ info.RunCPUCheck();
+ info.RunOSCheck();
+ info.RunMemoryCheck();
+
+ std::string buildname = cmCTest::SafeBuildIdField(
+ this->GetCTestConfiguration("BuildName"));
+ std::string stamp = cmCTest::SafeBuildIdField(
+ this->CurrentTag + "-" + this->GetTestModelString());
+ std::string site = cmCTest::SafeBuildIdField(
+ this->GetCTestConfiguration("Site"));
+
+ ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ << "<Site BuildName=\"" << buildname << "\"\n"
+ << "\tBuildStamp=\"" << stamp << "\"\n"
+ << "\tName=\"" << site << "\"\n"
+ << "\tGenerator=\"ctest-" << cmVersion::GetCMakeVersion() << "\"\n"
+ << (append? "\tAppend=\"true\"\n":"")
+ << "\tCompilerName=\"" << this->GetCTestConfiguration("Compiler")
+ << "\"\n"
+#ifdef _COMPILER_VERSION
+ << "\tCompilerVersion=\"_COMPILER_VERSION\"\n"
+#endif
+ << "\tOSName=\"" << info.GetOSName() << "\"\n"
+ << "\tHostname=\"" << info.GetHostname() << "\"\n"
+ << "\tOSRelease=\"" << info.GetOSRelease() << "\"\n"
+ << "\tOSVersion=\"" << info.GetOSVersion() << "\"\n"
+ << "\tOSPlatform=\"" << info.GetOSPlatform() << "\"\n"
+ << "\tIs64Bits=\"" << info.Is64Bits() << "\"\n"
+ << "\tVendorString=\"" << info.GetVendorString() << "\"\n"
+ << "\tVendorID=\"" << info.GetVendorID() << "\"\n"
+ << "\tFamilyID=\"" << info.GetFamilyID() << "\"\n"
+ << "\tModelID=\"" << info.GetModelID() << "\"\n"
+ << "\tProcessorCacheSize=\"" << info.GetProcessorCacheSize() << "\"\n"
+ << "\tNumberOfLogicalCPU=\"" << info.GetNumberOfLogicalCPU() << "\"\n"
+ << "\tNumberOfPhysicalCPU=\""<< info.GetNumberOfPhysicalCPU() << "\"\n"
+ << "\tTotalVirtualMemory=\"" << info.GetTotalVirtualMemory() << "\"\n"
+ << "\tTotalPhysicalMemory=\""<< info.GetTotalPhysicalMemory() << "\"\n"
+ << "\tLogicalProcessorsPerPhysical=\""
+ << info.GetLogicalProcessorsPerPhysical() << "\"\n"
+ << "\tProcessorClockFrequency=\""
+ << info.GetProcessorClockFrequency() << "\"\n"
+ << ">" << std::endl;
+ this->AddSiteProperties(ostr);
+}
+
+//----------------------------------------------------------------------
+void cmCTest::AddSiteProperties(std::ostream& ostr)
+{
+ cmCTestScriptHandler* ch =
+ static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+ cmake* cm = ch->GetCMake();
+ // if no CMake then this is the old style script and props like
+ // this will not work anyway.
+ if(!cm)
+ {
+ return;
+ }
+ // This code should go when cdash is changed to use labels only
+ const char* subproject = cm->GetProperty("SubProject", cmProperty::GLOBAL);
+ if(subproject)
+ {
+ ostr << "<Subproject name=\"" << subproject << "\">\n";
+ const char* labels =
+ ch->GetCMake()->GetProperty("SubProjectLabels", cmProperty::GLOBAL);
+ if(labels)
+ {
+ ostr << " <Labels>\n";
+ std::string l = labels;
+ std::vector<std::string> args;
+ cmSystemTools::ExpandListArgument(l, args);
+ for(std::vector<std::string>::iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ ostr << " <Label>" << *i << "</Label>\n";
+ }
+ ostr << " </Labels>\n";
+ }
+ ostr << "</Subproject>\n";
+ }
+
+ // This code should stay when cdash only does label based sub-projects
+ const char* label = cm->GetProperty("Label", cmProperty::GLOBAL);
+ if(label)
+ {
+ ostr << "<Labels>\n";
+ ostr << " <Label>" << label << "</Label>\n";
+ ostr << "</Labels>\n";
+ }
+}
+
+
+//----------------------------------------------------------------------
+void cmCTest::EndXML(std::ostream& ostr)
+{
+ ostr << "</Site>" << std::endl;
+}
+
+//----------------------------------------------------------------------
+int cmCTest::GenerateCTestNotesOutput(std::ostream& os,
+ const cmCTest::VectorOfStrings& files)
+{
+ std::string buildname = cmCTest::SafeBuildIdField(
+ this->GetCTestConfiguration("BuildName"));
+ cmCTest::VectorOfStrings::const_iterator it;
+ os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ << "<?xml-stylesheet type=\"text/xsl\" "
+ "href=\"Dart/Source/Server/XSL/Build.xsl "
+ "<file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
+ << "<Site BuildName=\"" << buildname
+ << "\" BuildStamp=\""
+ << this->CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
+ << this->GetCTestConfiguration("Site") << "\" Generator=\"ctest"
+ << cmVersion::GetCMakeVersion()
+ << "\">\n";
+ this->AddSiteProperties(os);
+ os << "<Notes>" << std::endl;
+
+ for ( it = files.begin(); it != files.end(); it ++ )
+ {
+ cmCTestLog(this, OUTPUT, "\tAdd file: " << *it << std::endl);
+ std::string note_time = this->CurrentTime();
+ os << "<Note Name=\"" << cmXMLSafe(*it) << "\">\n"
+ << "<Time>" << cmSystemTools::GetTime() << "</Time>\n"
+ << "<DateTime>" << note_time << "</DateTime>\n"
+ << "<Text>" << std::endl;
+ cmsys::ifstream ifs(it->c_str());
+ if ( ifs )
+ {
+ std::string line;
+ while ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ os << cmXMLSafe(line) << std::endl;
+ }
+ ifs.close();
+ }
+ else
+ {
+ os << "Problem reading file: " << *it << std::endl;
+ cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: " << *it
+ << " while creating notes" << std::endl);
+ }
+ os << "</Text>\n"
+ << "</Note>" << std::endl;
+ }
+ os << "</Notes>\n"
+ << "</Site>" << std::endl;
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCTest::GenerateNotesFile(const VectorOfStrings &files)
+{
+ cmGeneratedFileStream ofs;
+ if ( !this->OpenOutputFile(this->CurrentTag, "Notes.xml", ofs) )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file" << std::endl);
+ return 1;
+ }
+
+ this->GenerateCTestNotesOutput(ofs, files);
+ return 0;
+}
+
+//----------------------------------------------------------------------
+int cmCTest::GenerateNotesFile(const char* cfiles)
+{
+ if ( !cfiles )
+ {
+ return 1;
+ }
+
+ VectorOfStrings files;
+
+ cmCTestLog(this, OUTPUT, "Create notes file" << std::endl);
+
+ files = cmSystemTools::SplitString(cfiles, ';');
+ if ( files.size() == 0 )
+ {
+ return 1;
+ }
+
+ return this->GenerateNotesFile(files);
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::Base64GzipEncodeFile(std::string file)
+{
+ std::string tarFile = file + "_temp.tar.gz";
+ std::vector<std::string> files;
+ files.push_back(file);
+
+ if(!cmSystemTools::CreateTar(tarFile.c_str(), files, true, false, false))
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while "
+ "encoding file: " << file << std::endl);
+ return "";
+ }
+ std::string base64 = this->Base64EncodeFile(tarFile);
+ cmSystemTools::RemoveFile(tarFile.c_str());
+ return base64;
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::Base64EncodeFile(std::string file)
+{
+ long len = cmSystemTools::FileLength(file.c_str());
+ cmsys::ifstream ifs(file.c_str(), std::ios::in
+#ifdef _WIN32
+ | std::ios::binary
+#endif
+ );
+ unsigned char *file_buffer = new unsigned char [ len + 1 ];
+ ifs.read(reinterpret_cast<char*>(file_buffer), len);
+ ifs.close();
+
+ unsigned char *encoded_buffer
+ = new unsigned char [ static_cast<int>(
+ static_cast<double>(len) * 1.5 + 5.0) ];
+
+ unsigned long rlen
+ = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
+
+ std::string base64 = "";
+ for(unsigned long i = 0; i < rlen; i++)
+ {
+ base64 += encoded_buffer[i];
+ }
+ delete [] file_buffer;
+ delete [] encoded_buffer;
+
+ return base64;
+}
+
+
+//----------------------------------------------------------------------
+bool cmCTest::SubmitExtraFiles(const VectorOfStrings &files)
+{
+ VectorOfStrings::const_iterator it;
+ for ( it = files.begin();
+ it != files.end();
+ ++ it )
+ {
+ if ( !cmSystemTools::FileExists(it->c_str()) )
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Cannot find extra file: "
+ << *it << " to submit."
+ << std::endl;);
+ return false;
+ }
+ this->AddSubmitFile(PartExtraFiles, it->c_str());
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::SubmitExtraFiles(const char* cfiles)
+{
+ if ( !cfiles )
+ {
+ return 1;
+ }
+
+ VectorOfStrings files;
+
+ cmCTestLog(this, OUTPUT, "Submit extra files" << std::endl);
+
+ files = cmSystemTools::SplitString(cfiles, ';');
+ if ( files.size() == 0 )
+ {
+ return 1;
+ }
+
+ return this->SubmitExtraFiles(files);
+}
+
+
+//-------------------------------------------------------
+// for a -D argument convert the next argument into
+// the proper list of dashboard steps via SetTest
+bool cmCTest::AddTestsForDashboardType(std::string &targ)
+{
+ if ( targ == "Experimental" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("Start");
+ this->SetTest("Configure");
+ this->SetTest("Build");
+ this->SetTest("Test");
+ this->SetTest("Coverage");
+ this->SetTest("Submit");
+ }
+ else if ( targ == "ExperimentalStart" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("Start");
+ }
+ else if ( targ == "ExperimentalUpdate" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("Update");
+ }
+ else if ( targ == "ExperimentalConfigure" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("Configure");
+ }
+ else if ( targ == "ExperimentalBuild" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("Build");
+ }
+ else if ( targ == "ExperimentalTest" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("Test");
+ }
+ else if ( targ == "ExperimentalMemCheck"
+ || targ == "ExperimentalPurify" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("MemCheck");
+ }
+ else if ( targ == "ExperimentalCoverage" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("Coverage");
+ }
+ else if ( targ == "ExperimentalSubmit" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("Submit");
+ }
+ else if ( targ == "Continuous" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ this->SetTest("Start");
+ this->SetTest("Update");
+ this->SetTest("Configure");
+ this->SetTest("Build");
+ this->SetTest("Test");
+ this->SetTest("Coverage");
+ this->SetTest("Submit");
+ }
+ else if ( targ == "ContinuousStart" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ this->SetTest("Start");
+ }
+ else if ( targ == "ContinuousUpdate" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ this->SetTest("Update");
+ }
+ else if ( targ == "ContinuousConfigure" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ this->SetTest("Configure");
+ }
+ else if ( targ == "ContinuousBuild" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ this->SetTest("Build");
+ }
+ else if ( targ == "ContinuousTest" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ this->SetTest("Test");
+ }
+ else if ( targ == "ContinuousMemCheck"
+ || targ == "ContinuousPurify" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ this->SetTest("MemCheck");
+ }
+ else if ( targ == "ContinuousCoverage" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ this->SetTest("Coverage");
+ }
+ else if ( targ == "ContinuousSubmit" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ this->SetTest("Submit");
+ }
+ else if ( targ == "Nightly" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("Start");
+ this->SetTest("Update");
+ this->SetTest("Configure");
+ this->SetTest("Build");
+ this->SetTest("Test");
+ this->SetTest("Coverage");
+ this->SetTest("Submit");
+ }
+ else if ( targ == "NightlyStart" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("Start");
+ }
+ else if ( targ == "NightlyUpdate" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("Update");
+ }
+ else if ( targ == "NightlyConfigure" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("Configure");
+ }
+ else if ( targ == "NightlyBuild" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("Build");
+ }
+ else if ( targ == "NightlyTest" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("Test");
+ }
+ else if ( targ == "NightlyMemCheck"
+ || targ == "NightlyPurify" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("MemCheck");
+ }
+ else if ( targ == "NightlyCoverage" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("Coverage");
+ }
+ else if ( targ == "NightlySubmit" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("Submit");
+ }
+ else if ( targ == "MemoryCheck" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ this->SetTest("Start");
+ this->SetTest("Configure");
+ this->SetTest("Build");
+ this->SetTest("MemCheck");
+ this->SetTest("Coverage");
+ this->SetTest("Submit");
+ }
+ else if ( targ == "NightlyMemoryCheck" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ this->SetTest("Start");
+ this->SetTest("Update");
+ this->SetTest("Configure");
+ this->SetTest("Build");
+ this->SetTest("MemCheck");
+ this->SetTest("Coverage");
+ this->SetTest("Submit");
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+}
+
+
+//----------------------------------------------------------------------
+void cmCTest::ErrorMessageUnknownDashDValue(std::string &val)
+{
+ cmCTestLog(this, ERROR_MESSAGE,
+ "CTest -D called with incorrect option: " << val << std::endl);
+
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Available options are:" << std::endl
+ << " ctest -D Continuous" << std::endl
+ << " ctest -D Continuous(Start|Update|Configure|Build)" << std::endl
+ << " ctest -D Continuous(Test|Coverage|MemCheck|Submit)" << std::endl
+ << " ctest -D Experimental" << std::endl
+ << " ctest -D Experimental(Start|Update|Configure|Build)" << std::endl
+ << " ctest -D Experimental(Test|Coverage|MemCheck|Submit)" << std::endl
+ << " ctest -D Nightly" << std::endl
+ << " ctest -D Nightly(Start|Update|Configure|Build)" << std::endl
+ << " ctest -D Nightly(Test|Coverage|MemCheck|Submit)" << std::endl
+ << " ctest -D NightlyMemoryCheck" << std::endl);
+}
+
+
+//----------------------------------------------------------------------
+bool cmCTest::CheckArgument(const std::string& arg, const char* varg1,
+ const char* varg2)
+{
+ return (varg1 && arg == varg1) || (varg2 && arg == varg2);
+}
+
+
+//----------------------------------------------------------------------
+// Processes one command line argument (and its arguments if any)
+// for many simple options and then returns
+void cmCTest::HandleCommandLineArguments(size_t &i,
+ std::vector<std::string> &args)
+{
+ std::string arg = args[i];
+
+ if(this->CheckArgument(arg, "-F"))
+ {
+ this->Failover = true;
+ }
+ if(this->CheckArgument(arg, "-j", "--parallel") && i < args.size() - 1)
+ {
+ i++;
+ int plevel = atoi(args[i].c_str());
+ this->SetParallelLevel(plevel);
+ this->ParallelLevelSetInCli = true;
+ }
+ else if(arg.find("-j") == 0)
+ {
+ int plevel = atoi(arg.substr(2).c_str());
+ this->SetParallelLevel(plevel);
+ this->ParallelLevelSetInCli = true;
+ }
+
+ if(this->CheckArgument(arg, "--no-compress-output"))
+ {
+ this->CompressTestOutput = false;
+ this->CompressMemCheckOutput = false;
+ }
+
+ if(this->CheckArgument(arg, "--print-labels"))
+ {
+ this->PrintLabels = true;
+ }
+
+ if(this->CheckArgument(arg, "--http1.0"))
+ {
+ this->UseHTTP10 = true;
+ }
+
+ if(this->CheckArgument(arg, "--timeout") && i < args.size() - 1)
+ {
+ i++;
+ double timeout = (double)atof(args[i].c_str());
+ this->GlobalTimeout = timeout;
+ }
+
+ if(this->CheckArgument(arg, "--stop-time") && i < args.size() - 1)
+ {
+ i++;
+ this->SetStopTime(args[i]);
+ }
+
+ if(this->CheckArgument(arg, "-C", "--build-config") &&
+ i < args.size() - 1)
+ {
+ i++;
+ this->SetConfigType(args[i].c_str());
+ }
+
+ if(this->CheckArgument(arg, "--debug"))
+ {
+ this->Debug = true;
+ this->ShowLineNumbers = true;
+ }
+ if(this->CheckArgument(arg, "--track") && i < args.size() - 1)
+ {
+ i++;
+ this->SpecificTrack = args[i];
+ }
+ if(this->CheckArgument(arg, "--show-line-numbers"))
+ {
+ this->ShowLineNumbers = true;
+ }
+ if(this->CheckArgument(arg, "--no-label-summary"))
+ {
+ this->LabelSummary = false;
+ }
+ if(this->CheckArgument(arg, "-Q", "--quiet"))
+ {
+ this->Quiet = true;
+ }
+ if(this->CheckArgument(arg, "-V", "--verbose"))
+ {
+ this->Verbose = true;
+ }
+ if(this->CheckArgument(arg, "-B"))
+ {
+ this->BatchJobs = true;
+ }
+ if(this->CheckArgument(arg, "-VV", "--extra-verbose"))
+ {
+ this->ExtraVerbose = true;
+ this->Verbose = true;
+ }
+ if(this->CheckArgument(arg, "--output-on-failure"))
+ {
+ this->OutputTestOutputOnTestFailure = true;
+ }
+
+ if(this->CheckArgument(arg, "-N", "--show-only"))
+ {
+ this->ShowOnly = true;
+ }
+
+ if(this->CheckArgument(arg, "-O", "--output-log") && i < args.size() - 1 )
+ {
+ i++;
+ this->SetOutputLogFileName(args[i].c_str());
+ }
+
+ if(this->CheckArgument(arg, "--tomorrow-tag"))
+ {
+ this->TomorrowTag = true;
+ }
+ if(this->CheckArgument(arg, "--force-new-ctest-process"))
+ {
+ this->ForceNewCTestProcess = true;
+ }
+ if(this->CheckArgument(arg, "-W", "--max-width") && i < args.size() - 1)
+ {
+ i++;
+ this->MaxTestNameWidth = atoi(args[i].c_str());
+ }
+ if(this->CheckArgument(arg, "--interactive-debug-mode") &&
+ i < args.size() - 1 )
+ {
+ i++;
+ this->InteractiveDebugMode = cmSystemTools::IsOn(args[i].c_str());
+ }
+ if(this->CheckArgument(arg, "--submit-index") && i < args.size() - 1 )
+ {
+ i++;
+ this->SubmitIndex = atoi(args[i].c_str());
+ if ( this->SubmitIndex < 0 )
+ {
+ this->SubmitIndex = 0;
+ }
+ }
+
+ if(this->CheckArgument(arg, "--overwrite") && i < args.size() - 1)
+ {
+ i++;
+ this->AddCTestConfigurationOverwrite(args[i]);
+ }
+ if(this->CheckArgument(arg, "-A", "--add-notes") && i < args.size() - 1)
+ {
+ this->ProduceXML = true;
+ this->SetTest("Notes");
+ i++;
+ this->SetNotesFiles(args[i].c_str());
+ }
+
+ // options that control what tests are run
+ if(this->CheckArgument(arg, "-I", "--tests-information") &&
+ i < args.size() - 1)
+ {
+ i++;
+ this->GetHandler("test")->SetPersistentOption("TestsToRunInformation",
+ args[i].c_str());
+ this->GetHandler("memcheck")->
+ SetPersistentOption("TestsToRunInformation",args[i].c_str());
+ }
+ if(this->CheckArgument(arg, "-U", "--union"))
+ {
+ this->GetHandler("test")->SetPersistentOption("UseUnion", "true");
+ this->GetHandler("memcheck")->SetPersistentOption("UseUnion", "true");
+ }
+ if(this->CheckArgument(arg, "-R", "--tests-regex") && i < args.size() - 1)
+ {
+ i++;
+ this->GetHandler("test")->
+ SetPersistentOption("IncludeRegularExpression", args[i].c_str());
+ this->GetHandler("memcheck")->
+ SetPersistentOption("IncludeRegularExpression", args[i].c_str());
+ }
+ if(this->CheckArgument(arg, "-L", "--label-regex") && i < args.size() - 1)
+ {
+ i++;
+ this->GetHandler("test")->
+ SetPersistentOption("LabelRegularExpression", args[i].c_str());
+ this->GetHandler("memcheck")->
+ SetPersistentOption("LabelRegularExpression", args[i].c_str());
+ }
+ if(this->CheckArgument(arg, "-LE", "--label-exclude") && i < args.size() - 1)
+ {
+ i++;
+ this->GetHandler("test")->
+ SetPersistentOption("ExcludeLabelRegularExpression", args[i].c_str());
+ this->GetHandler("memcheck")->
+ SetPersistentOption("ExcludeLabelRegularExpression", args[i].c_str());
+ }
+
+ if(this->CheckArgument(arg, "-E", "--exclude-regex") &&
+ i < args.size() - 1)
+ {
+ i++;
+ this->GetHandler("test")->
+ SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
+ this->GetHandler("memcheck")->
+ SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
+ }
+
+ if(this->CheckArgument(arg, "--rerun-failed"))
+ {
+ this->GetHandler("test")->SetPersistentOption("RerunFailed", "true");
+ this->GetHandler("memcheck")->SetPersistentOption("RerunFailed", "true");
+ }
+}
+
+//----------------------------------------------------------------------
+// handle the -S -SR and -SP arguments
+void cmCTest::HandleScriptArguments(size_t &i,
+ std::vector<std::string> &args,
+ bool &SRArgumentSpecified)
+{
+ std::string arg = args[i];
+ if(this->CheckArgument(arg, "-SP", "--script-new-process") &&
+ i < args.size() - 1 )
+ {
+ this->RunConfigurationScript = true;
+ i++;
+ cmCTestScriptHandler* ch
+ = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+ // -SR is an internal argument, -SP should be ignored when it is passed
+ if (!SRArgumentSpecified)
+ {
+ ch->AddConfigurationScript(args[i].c_str(),false);
+ }
+ }
+
+ if(this->CheckArgument(arg, "-SR", "--script-run") &&
+ i < args.size() - 1 )
+ {
+ SRArgumentSpecified = true;
+ this->RunConfigurationScript = true;
+ i++;
+ cmCTestScriptHandler* ch
+ = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+ ch->AddConfigurationScript(args[i].c_str(),true);
+ }
+
+ if(this->CheckArgument(arg, "-S", "--script") && i < args.size() - 1 )
+ {
+ this->RunConfigurationScript = true;
+ i++;
+ cmCTestScriptHandler* ch
+ = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+ // -SR is an internal argument, -S should be ignored when it is passed
+ if (!SRArgumentSpecified)
+ {
+ ch->AddConfigurationScript(args[i].c_str(),true);
+ }
+ }
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::AddVariableDefinition(const std::string &arg)
+{
+ std::string name;
+ std::string value;
+ cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
+
+ if (cmCacheManager::ParseEntry(arg, name, value, type))
+ {
+ this->Definitions[name] = value;
+ return true;
+ }
+
+ return false;
+}
+
+//----------------------------------------------------------------------
+// the main entry point of ctest, called from main
+int cmCTest::Run(std::vector<std::string> &args, std::string* output)
+{
+ const char* ctestExec = "ctest";
+ bool cmakeAndTest = false;
+ bool executeTests = true;
+ bool SRArgumentSpecified = false;
+
+ // copy the command line
+ for(size_t i=0; i < args.size(); ++i)
+ {
+ this->InitialCommandLineArguments.push_back(args[i]);
+ }
+
+ // process the command line arguments
+ for(size_t i=1; i < args.size(); ++i)
+ {
+ // handle the simple commandline arguments
+ this->HandleCommandLineArguments(i,args);
+
+ // handle the script arguments -S -SR -SP
+ this->HandleScriptArguments(i,args,SRArgumentSpecified);
+
+ // handle a request for a dashboard
+ std::string arg = args[i];
+ if(this->CheckArgument(arg, "-D", "--dashboard") && i < args.size() - 1 )
+ {
+ this->ProduceXML = true;
+ i++;
+ std::string targ = args[i];
+ // AddTestsForDashboard parses the dashboard type and converts it
+ // into the separate stages
+ if (!this->AddTestsForDashboardType(targ))
+ {
+ if (!this->AddVariableDefinition(targ))
+ {
+ this->ErrorMessageUnknownDashDValue(targ);
+ executeTests = false;
+ }
+ }
+ }
+
+ // If it's not exactly -D, but it starts with -D, then try to parse out
+ // a variable definition from it, same as CMake does. Unsuccessful
+ // attempts are simply ignored since previous ctest versions ignore
+ // this too. (As well as many other unknown command line args.)
+ //
+ if(arg != "-D" && cmSystemTools::StringStartsWith(arg.c_str(), "-D"))
+ {
+ std::string input = arg.substr(2);
+ this->AddVariableDefinition(input);
+ }
+
+ if(this->CheckArgument(arg, "-T", "--test-action") &&
+ (i < args.size() -1) )
+ {
+ this->ProduceXML = true;
+ i++;
+ if ( !this->SetTest(args[i].c_str(), false) )
+ {
+ executeTests = false;
+ cmCTestLog(this, ERROR_MESSAGE,
+ "CTest -T called with incorrect option: "
+ << args[i] << std::endl);
+ cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
+ << " " << ctestExec << " -T all" << std::endl
+ << " " << ctestExec << " -T start" << std::endl
+ << " " << ctestExec << " -T update" << std::endl
+ << " " << ctestExec << " -T configure" << std::endl
+ << " " << ctestExec << " -T build" << std::endl
+ << " " << ctestExec << " -T test" << std::endl
+ << " " << ctestExec << " -T coverage" << std::endl
+ << " " << ctestExec << " -T memcheck" << std::endl
+ << " " << ctestExec << " -T notes" << std::endl
+ << " " << ctestExec << " -T submit" << std::endl);
+ }
+ }
+
+ // what type of test model
+ if(this->CheckArgument(arg, "-M", "--test-model") &&
+ (i < args.size() -1) )
+ {
+ i++;
+ std::string const& str = args[i];
+ if ( cmSystemTools::LowerCase(str) == "nightly" )
+ {
+ this->SetTestModel(cmCTest::NIGHTLY);
+ }
+ else if ( cmSystemTools::LowerCase(str) == "continuous" )
+ {
+ this->SetTestModel(cmCTest::CONTINUOUS);
+ }
+ else if ( cmSystemTools::LowerCase(str) == "experimental" )
+ {
+ this->SetTestModel(cmCTest::EXPERIMENTAL);
+ }
+ else
+ {
+ executeTests = false;
+ cmCTestLog(this, ERROR_MESSAGE,
+ "CTest -M called with incorrect option: " << str
+ << std::endl);
+ cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
+ << " " << ctestExec << " -M Continuous" << std::endl
+ << " " << ctestExec << " -M Experimental" << std::endl
+ << " " << ctestExec << " -M Nightly" << std::endl);
+ }
+ }
+
+ if(this->CheckArgument(arg, "--extra-submit") && i < args.size() - 1)
+ {
+ this->ProduceXML = true;
+ this->SetTest("Submit");
+ i++;
+ if ( !this->SubmitExtraFiles(args[i].c_str()) )
+ {
+ return 0;
+ }
+ }
+
+ // --build-and-test options
+ if(this->CheckArgument(arg, "--build-and-test") && i < args.size() - 1)
+ {
+ cmakeAndTest = true;
+ }
+
+ if(this->CheckArgument(arg, "--schedule-random"))
+ {
+ this->ScheduleType = "Random";
+ }
+
+ // pass the argument to all the handlers as well, but i may no longer be
+ // set to what it was originally so I'm not sure this is working as
+ // intended
+ cmCTest::t_TestingHandlers::iterator it;
+ for ( it = this->TestingHandlers.begin();
+ it != this->TestingHandlers.end();
+ ++ it )
+ {
+ if ( !it->second->ProcessCommandLineArguments(arg, i, args) )
+ {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Problem parsing command line arguments within a handler");
+ return 0;
+ }
+ }
+ } // the close of the for argument loop
+
+ if (!this->ParallelLevelSetInCli)
+ {
+ if (const char *parallel = cmSystemTools::GetEnv("CTEST_PARALLEL_LEVEL"))
+ {
+ int plevel = atoi(parallel);
+ this->SetParallelLevel(plevel);
+ }
+ }
+
+ // now what sould cmake do? if --build-and-test was specified then
+ // we run the build and test handler and return
+ if(cmakeAndTest)
+ {
+ this->Verbose = true;
+ cmCTestBuildAndTestHandler* handler =
+ static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest"));
+ int retv = handler->ProcessHandler();
+ *output = handler->GetOutput();
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmDynamicLoader::FlushCache();
+#endif
+ if(retv != 0)
+ {
+ cmCTestLog(this, DEBUG, "build and test failing returning: " << retv
+ << std::endl);
+ }
+ return retv;
+ }
+
+ if(executeTests)
+ {
+ int res;
+ // call process directory
+ if (this->RunConfigurationScript)
+ {
+ if ( this->ExtraVerbose )
+ {
+ cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl);
+ }
+ cmCTest::t_TestingHandlers::iterator it;
+ for ( it = this->TestingHandlers.begin();
+ it != this->TestingHandlers.end();
+ ++ it )
+ {
+ it->second->SetVerbose(this->ExtraVerbose);
+ it->second->SetSubmitIndex(this->SubmitIndex);
+ }
+ this->GetHandler("script")->SetVerbose(this->Verbose);
+ res = this->GetHandler("script")->ProcessHandler();
+ if(res != 0)
+ {
+ cmCTestLog(this, DEBUG, "running script failing returning: " << res
+ << std::endl);
+ }
+
+ }
+ else
+ {
+ // What is this? -V seems to be the same as -VV,
+ // and Verbose is always on in this case
+ this->ExtraVerbose = this->Verbose;
+ this->Verbose = true;
+ cmCTest::t_TestingHandlers::iterator it;
+ for ( it = this->TestingHandlers.begin();
+ it != this->TestingHandlers.end();
+ ++ it )
+ {
+ it->second->SetVerbose(this->Verbose);
+ it->second->SetSubmitIndex(this->SubmitIndex);
+ }
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ if(!this->Initialize(cwd.c_str(), 0))
+ {
+ res = 12;
+ cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard."
+ << std::endl);
+ }
+ else
+ {
+ res = this->ProcessTests();
+ }
+ this->Finalize();
+ }
+ if(res != 0)
+ {
+ cmCTestLog(this, DEBUG, "Running a test(s) failed returning : " << res
+ << std::endl);
+ }
+ return res;
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+void cmCTest::SetNotesFiles(const char* notes)
+{
+ if ( !notes )
+ {
+ return;
+ }
+ this->NotesFiles = notes;
+}
+
+//----------------------------------------------------------------------
+void cmCTest::SetStopTime(std::string time)
+{
+ this->StopTime = time;
+ this->DetermineNextDayStop();
+}
+
+//----------------------------------------------------------------------
+int cmCTest::ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf)
+{
+ bool found = false;
+ VectorOfStrings dirs;
+ VectorOfStrings ndirs;
+ cmCTestLog(this, DEBUG, "* Read custom CTest configuration directory: "
+ << dir << std::endl);
+
+ std::string fname = dir;
+ fname += "/CTestCustom.cmake";
+ cmCTestLog(this, DEBUG, "* Check for file: "
+ << fname << std::endl);
+ if ( cmSystemTools::FileExists(fname.c_str()) )
+ {
+ cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
+ << fname << std::endl);
+ bool erroroc = cmSystemTools::GetErrorOccuredFlag();
+ cmSystemTools::ResetErrorOccuredFlag();
+
+ if ( !mf->ReadListFile(0, fname.c_str()) ||
+ cmSystemTools::GetErrorOccuredFlag() )
+ {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Problem reading custom configuration: "
+ << fname << std::endl);
+ }
+ found = true;
+ if ( erroroc )
+ {
+ cmSystemTools::SetErrorOccured();
+ }
+ }
+
+ std::string rexpr = dir;
+ rexpr += "/CTestCustom.ctest";
+ cmCTestLog(this, DEBUG, "* Check for file: "
+ << rexpr << std::endl);
+ if ( !found && cmSystemTools::FileExists(rexpr.c_str()) )
+ {
+ cmsys::Glob gl;
+ gl.RecurseOn();
+ gl.FindFiles(rexpr);
+ std::vector<std::string>& files = gl.GetFiles();
+ std::vector<std::string>::iterator fileIt;
+ for ( fileIt = files.begin(); fileIt != files.end();
+ ++ fileIt )
+ {
+ cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
+ << *fileIt << std::endl);
+ if ( !mf->ReadListFile(0, fileIt->c_str()) ||
+ cmSystemTools::GetErrorOccuredFlag() )
+ {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Problem reading custom configuration: "
+ << *fileIt << std::endl);
+ }
+ }
+ found = true;
+ }
+
+ if ( found )
+ {
+ cmCTest::t_TestingHandlers::iterator it;
+ for ( it = this->TestingHandlers.begin();
+ it != this->TestingHandlers.end(); ++ it )
+ {
+ cmCTestLog(this, DEBUG,
+ "* Read custom CTest configuration vectors for handler: "
+ << it->first << " (" << it->second << ")" << std::endl);
+ it->second->PopulateCustomVectors(mf);
+ }
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+void cmCTest::PopulateCustomVector(cmMakefile* mf, const std::string& def,
+ std::vector<std::string>& vec)
+{
+ const char* dval = mf->GetDefinition(def);
+ if ( !dval )
+ {
+ return;
+ }
+ cmCTestLog(this, DEBUG, "PopulateCustomVector: " << def << std::endl);
+ std::vector<std::string> slist;
+ cmSystemTools::ExpandListArgument(dval, slist);
+ std::vector<std::string>::iterator it;
+
+ vec.clear();
+
+ for ( it = slist.begin(); it != slist.end(); ++it )
+ {
+ cmCTestLog(this, DEBUG, " -- " << *it << std::endl);
+ vec.push_back(*it);
+ }
+}
+
+//----------------------------------------------------------------------
+void cmCTest::PopulateCustomInteger(cmMakefile* mf, const std::string& def,
+ int& val)
+{
+ const char* dval = mf->GetDefinition(def);
+ if ( !dval )
+ {
+ return;
+ }
+ val = atoi(dval);
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::GetShortPathToFile(const char* cfname)
+{
+ const std::string& sourceDir
+ = cmSystemTools::CollapseFullPath(
+ this->GetCTestConfiguration("SourceDirectory").c_str());
+ const std::string& buildDir
+ = cmSystemTools::CollapseFullPath(
+ this->GetCTestConfiguration("BuildDirectory").c_str());
+ std::string fname = cmSystemTools::CollapseFullPath(cfname);
+
+ // Find relative paths to both directories
+ std::string srcRelpath
+ = cmSystemTools::RelativePath(sourceDir.c_str(), fname.c_str());
+ std::string bldRelpath
+ = cmSystemTools::RelativePath(buildDir.c_str(), fname.c_str());
+
+ // If any contains "." it is not parent directory
+ bool inSrc = srcRelpath.find("..") == srcRelpath.npos;
+ bool inBld = bldRelpath.find("..") == bldRelpath.npos;
+ // TODO: Handle files with .. in their name
+
+ std::string* res = 0;
+
+ if ( inSrc && inBld )
+ {
+ // If both have relative path with no dots, pick the shorter one
+ if ( srcRelpath.size() < bldRelpath.size() )
+ {
+ res = &srcRelpath;
+ }
+ else
+ {
+ res = &bldRelpath;
+ }
+ }
+ else if ( inSrc )
+ {
+ res = &srcRelpath;
+ }
+ else if ( inBld )
+ {
+ res = &bldRelpath;
+ }
+
+ std::string path;
+
+ if ( !res )
+ {
+ path = fname;
+ }
+ else
+ {
+ cmSystemTools::ConvertToUnixSlashes(*res);
+
+ path = "./" + *res;
+ if ( path[path.size()-1] == '/' )
+ {
+ path = path.substr(0, path.size()-1);
+ }
+ }
+
+ cmsys::SystemTools::ReplaceString(path, ":", "_");
+ cmsys::SystemTools::ReplaceString(path, " ", "_");
+ return path;
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::GetCTestConfiguration(const std::string& name)
+{
+ if ( this->CTestConfigurationOverwrites.find(name) !=
+ this->CTestConfigurationOverwrites.end() )
+ {
+ return this->CTestConfigurationOverwrites[name];
+ }
+ return this->CTestConfiguration[name];
+}
+
+//----------------------------------------------------------------------
+void cmCTest::EmptyCTestConfiguration()
+{
+ this->CTestConfiguration.clear();
+}
+
+//----------------------------------------------------------------------
+void cmCTest::DetermineNextDayStop()
+{
+ struct tm* lctime;
+ time_t current_time = time(0);
+ lctime = gmtime(&current_time);
+ int gm_hour = lctime->tm_hour;
+ time_t gm_time = mktime(lctime);
+ lctime = localtime(&current_time);
+ int local_hour = lctime->tm_hour;
+
+ int tzone_offset = local_hour - gm_hour;
+ if(gm_time > current_time && gm_hour < local_hour)
+ {
+ // this means gm_time is on the next day
+ tzone_offset -= 24;
+ }
+ else if(gm_time < current_time && gm_hour > local_hour)
+ {
+ // this means gm_time is on the previous day
+ tzone_offset += 24;
+ }
+
+ tzone_offset *= 100;
+ char buf[1024];
+ sprintf(buf, "%d%02d%02d %s %+05i",
+ lctime->tm_year + 1900,
+ lctime->tm_mon + 1,
+ lctime->tm_mday,
+ this->StopTime.c_str(),
+ tzone_offset);
+
+ time_t stop_time = curl_getdate(buf, &current_time);
+
+ if(stop_time < current_time)
+ {
+ this->NextDayStopTime = true;
+ }
+}
+
+//----------------------------------------------------------------------
+void cmCTest::SetCTestConfiguration(const char *name, const char* value)
+{
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "SetCTestConfiguration:"
+ << name << ":" << (value ? value : "(null)") << "\n");
+
+ if ( !name )
+ {
+ return;
+ }
+ if ( !value )
+ {
+ this->CTestConfiguration.erase(name);
+ return;
+ }
+ this->CTestConfiguration[name] = value;
+}
+
+
+//----------------------------------------------------------------------
+std::string cmCTest::GetCurrentTag()
+{
+ return this->CurrentTag;
+}
+
+//----------------------------------------------------------------------
+std::string cmCTest::GetBinaryDir()
+{
+ return this->BinaryDir;
+}
+
+//----------------------------------------------------------------------
+std::string const& cmCTest::GetConfigType()
+{
+ return this->ConfigType;
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::GetShowOnly()
+{
+ return this->ShowOnly;
+}
+
+//----------------------------------------------------------------------
+int cmCTest::GetMaxTestNameWidth() const
+{
+ return this->MaxTestNameWidth;
+}
+
+//----------------------------------------------------------------------
+void cmCTest::SetProduceXML(bool v)
+{
+ this->ProduceXML = v;
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::GetProduceXML()
+{
+ return this->ProduceXML;
+}
+
+//----------------------------------------------------------------------
+const char* cmCTest::GetSpecificTrack()
+{
+ if ( this->SpecificTrack.empty() )
+ {
+ return 0;
+ }
+ return this->SpecificTrack.c_str();
+}
+
+//----------------------------------------------------------------------
+void cmCTest::SetSpecificTrack(const char* track)
+{
+ if ( !track )
+ {
+ this->SpecificTrack = "";
+ return;
+ }
+ this->SpecificTrack = track;
+}
+
+//----------------------------------------------------------------------
+void cmCTest::AddSubmitFile(Part part, const char* name)
+{
+ this->Parts[part].SubmitFiles.push_back(name);
+}
+
+//----------------------------------------------------------------------
+void cmCTest::AddCTestConfigurationOverwrite(const std::string& overStr)
+{
+ size_t epos = overStr.find("=");
+ if ( epos == overStr.npos )
+ {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "CTest configuration overwrite specified in the wrong format."
+ << std::endl
+ << "Valid format is: --overwrite key=value" << std::endl
+ << "The specified was: --overwrite " << overStr << std::endl);
+ return;
+ }
+ std::string key = overStr.substr(0, epos);
+ std::string value = overStr.substr(epos+1, overStr.npos);
+ this->CTestConfigurationOverwrites[key] = value;
+}
+
+//----------------------------------------------------------------------
+void cmCTest::SetConfigType(const char* ct)
+{
+ this->ConfigType = ct?ct:"";
+ cmSystemTools::ReplaceString(this->ConfigType, ".\\", "");
+ std::string confTypeEnv
+ = "CMAKE_CONFIG_TYPE=" + this->ConfigType;
+ cmSystemTools::PutEnv(confTypeEnv.c_str());
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::SetCTestConfigurationFromCMakeVariable(cmMakefile* mf,
+ const char* dconfig, const std::string& cmake_var)
+{
+ const char* ctvar;
+ ctvar = mf->GetDefinition(cmake_var);
+ if ( !ctvar )
+ {
+ return false;
+ }
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
+ "SetCTestConfigurationFromCMakeVariable:"
+ << dconfig << ":" << cmake_var << std::endl);
+ this->SetCTestConfiguration(dconfig, ctvar);
+ return true;
+}
+
+bool cmCTest::RunCommand(
+ const char* command,
+ std::string* stdOut,
+ std::string* stdErr,
+ int *retVal,
+ const char* dir,
+ double timeout)
+{
+ std::vector<std::string> args = cmSystemTools::ParseArguments(command);
+
+ if(args.size() < 1)
+ {
+ return false;
+ }
+
+ std::vector<const char*> argv;
+ for(std::vector<std::string>::const_iterator a = args.begin();
+ a != args.end(); ++a)
+ {
+ argv.push_back(a->c_str());
+ }
+ argv.push_back(0);
+
+ *stdOut = "";
+ *stdErr = "";
+
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetWorkingDirectory(cp, dir);
+ if(cmSystemTools::GetRunCommandHideConsole())
+ {
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+ }
+ cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_Execute(cp);
+
+ std::vector<char> tempOutput;
+ std::vector<char> tempError;
+ char* data;
+ int length;
+ int res;
+ bool done = false;
+ while(!done)
+ {
+ res = cmsysProcess_WaitForData(cp, &data, &length, 0);
+ switch ( res )
+ {
+ case cmsysProcess_Pipe_STDOUT:
+ tempOutput.insert(tempOutput.end(), data, data+length);
+ break;
+ case cmsysProcess_Pipe_STDERR:
+ tempError.insert(tempError.end(), data, data+length);
+ break;
+ default:
+ done = true;
+ }
+ if ( (res == cmsysProcess_Pipe_STDOUT ||
+ res == cmsysProcess_Pipe_STDERR) && this->ExtraVerbose )
+ {
+ cmSystemTools::Stdout(data, length);
+ }
+ }
+
+ cmsysProcess_WaitForExit(cp, 0);
+ if ( tempOutput.size() > 0 )
+ {
+ stdOut->append(&*tempOutput.begin(), tempOutput.size());
+ }
+ if ( tempError.size() > 0 )
+ {
+ stdErr->append(&*tempError.begin(), tempError.size());
+ }
+
+ bool result = true;
+ if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
+ {
+ if ( retVal )
+ {
+ *retVal = cmsysProcess_GetExitValue(cp);
+ }
+ else
+ {
+ if ( cmsysProcess_GetExitValue(cp) != 0 )
+ {
+ result = false;
+ }
+ }
+ }
+ else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception)
+ {
+ const char* exception_str = cmsysProcess_GetExceptionString(cp);
+ cmCTestLog(this, ERROR_MESSAGE, exception_str << std::endl);
+ stdErr->append(exception_str, strlen(exception_str));
+ result = false;
+ }
+ else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
+ {
+ const char* error_str = cmsysProcess_GetErrorString(cp);
+ cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
+ stdErr->append(error_str, strlen(error_str));
+ result = false;
+ }
+ else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired)
+ {
+ const char* error_str = "Process terminated due to timeout\n";
+ cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
+ stdErr->append(error_str, strlen(error_str));
+ result = false;
+ }
+
+ cmsysProcess_Delete(cp);
+ return result;
+}
+
+//----------------------------------------------------------------------
+void cmCTest::SetOutputLogFileName(const char* name)
+{
+ if ( this->OutputLogFile)
+ {
+ delete this->OutputLogFile;
+ this->OutputLogFile= 0;
+ }
+ if ( name )
+ {
+ this->OutputLogFile = new cmGeneratedFileStream(name);
+ }
+}
+
+//----------------------------------------------------------------------
+static const char* cmCTestStringLogType[] =
+{
+ "DEBUG",
+ "OUTPUT",
+ "HANDLER_OUTPUT",
+ "HANDLER_VERBOSE_OUTPUT",
+ "WARNING",
+ "ERROR_MESSAGE",
+ 0
+};
+
+//----------------------------------------------------------------------
+#ifdef cerr
+# undef cerr
+#endif
+#ifdef cout
+# undef cout
+#endif
+
+#define cmCTestLogOutputFileLine(stream) \
+ if ( this->ShowLineNumbers ) \
+ { \
+ (stream) << std::endl << file << ":" << line << " "; \
+ }
+
+void cmCTest::InitStreams()
+{
+ // By default we write output to the process output streams.
+ this->StreamOut = &std::cout;
+ this->StreamErr = &std::cerr;
+}
+
+void cmCTest::Log(int logType, const char* file, int line, const char* msg)
+{
+ if ( !msg || !*msg )
+ {
+ return;
+ }
+ if ( this->OutputLogFile )
+ {
+ bool display = true;
+ if ( logType == cmCTest::DEBUG && !this->Debug ) { display = false; }
+ if ( logType == cmCTest::HANDLER_VERBOSE_OUTPUT && !this->Debug &&
+ !this->ExtraVerbose ) { display = false; }
+ if ( display )
+ {
+ cmCTestLogOutputFileLine(*this->OutputLogFile);
+ if ( logType != this->OutputLogFileLastTag )
+ {
+ *this->OutputLogFile << "[";
+ if ( logType >= OTHER || logType < 0 )
+ {
+ *this->OutputLogFile << "OTHER";
+ }
+ else
+ {
+ *this->OutputLogFile << cmCTestStringLogType[logType];
+ }
+ *this->OutputLogFile << "] " << std::endl << std::flush;
+ }
+ *this->OutputLogFile << msg << std::flush;
+ if ( logType != this->OutputLogFileLastTag )
+ {
+ *this->OutputLogFile << std::endl << std::flush;
+ this->OutputLogFileLastTag = logType;
+ }
+ }
+ }
+ if ( !this->Quiet )
+ {
+ std::ostream& out = *this->StreamOut;
+ std::ostream& err = *this->StreamErr;
+ switch ( logType )
+ {
+ case DEBUG:
+ if ( this->Debug )
+ {
+ cmCTestLogOutputFileLine(out);
+ out << msg;
+ out.flush();
+ }
+ break;
+ case OUTPUT: case HANDLER_OUTPUT:
+ if ( this->Debug || this->Verbose )
+ {
+ cmCTestLogOutputFileLine(out);
+ out << msg;
+ out.flush();
+ }
+ break;
+ case HANDLER_VERBOSE_OUTPUT:
+ if ( this->Debug || this->ExtraVerbose )
+ {
+ cmCTestLogOutputFileLine(out);
+ out << msg;
+ out.flush();
+ }
+ break;
+ case WARNING:
+ cmCTestLogOutputFileLine(err);
+ err << msg;
+ err.flush();
+ break;
+ case ERROR_MESSAGE:
+ cmCTestLogOutputFileLine(err);
+ err << msg;
+ err.flush();
+ cmSystemTools::SetErrorOccured();
+ break;
+ default:
+ cmCTestLogOutputFileLine(out);
+ out << msg;
+ out.flush();
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+double cmCTest::GetRemainingTimeAllowed()
+{
+ if (!this->GetHandler("script"))
+ {
+ return 1.0e7;
+ }
+
+ cmCTestScriptHandler* ch
+ = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+
+ return ch->GetRemainingTimeAllowed();
+}
+
+//----------------------------------------------------------------------
+void cmCTest::OutputTestErrors(std::vector<char> const &process_output)
+{
+ std::string test_outputs("\n*** Test Failed:\n");
+ if(process_output.size())
+ {
+ test_outputs.append(&*process_output.begin(), process_output.size());
+ }
+ cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush);
+}
+
+//----------------------------------------------------------------------
+bool cmCTest::CompressString(std::string& str)
+{
+ int ret;
+ z_stream strm;
+
+ unsigned char* in = reinterpret_cast<unsigned char*>(
+ const_cast<char*>(str.c_str()));
+ //zlib makes the guarantee that this is the maximum output size
+ int outSize = static_cast<int>(
+ static_cast<double>(str.size()) * 1.001 + 13.0);
+ unsigned char* out = new unsigned char[outSize];
+
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ ret = deflateInit(&strm, -1); //default compression level
+ if (ret != Z_OK)
+ {
+ delete[] out;
+ return false;
+ }
+
+ strm.avail_in = static_cast<uInt>(str.size());
+ strm.next_in = in;
+ strm.avail_out = outSize;
+ strm.next_out = out;
+ ret = deflate(&strm, Z_FINISH);
+
+ if(ret == Z_STREAM_ERROR || ret != Z_STREAM_END)
+ {
+ cmCTestLog(this, ERROR_MESSAGE, "Error during gzip compression."
+ << std::endl);
+ delete[] out;
+ return false;
+ }
+
+ (void)deflateEnd(&strm);
+
+ // Now base64 encode the resulting binary string
+ unsigned char* base64EncodedBuffer
+ = new unsigned char[static_cast<int>(outSize * 1.5)];
+
+ unsigned long rlen
+ = cmsysBase64_Encode(out, strm.total_out, base64EncodedBuffer, 1);
+
+ str = "";
+ str.append(reinterpret_cast<char*>(base64EncodedBuffer), rlen);
+
+ delete [] base64EncodedBuffer;
+ delete [] out;
+
+ return true;
+}
diff --git a/Source/cmCTest.h b/Source/cmCTest.h
new file mode 100644
index 0000000000..e19d32caac
--- /dev/null
+++ b/Source/cmCTest.h
@@ -0,0 +1,592 @@
+/*============================================================================
+ 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 cmCTest_h
+#define cmCTest_h
+
+#include "cmStandardIncludes.h"
+#include "cmListFileCache.h"
+#include <time.h>
+
+class cmake;
+class cmMakefile;
+class cmCTestGenericHandler;
+class cmGeneratedFileStream;
+class cmCTestCommand;
+class cmCTestScriptHandler;
+class cmCTestStartCommand;
+
+#define cmCTestLog(ctSelf, logType, msg) \
+ do { \
+ cmOStringStream cmCTestLog_msg; \
+ cmCTestLog_msg << msg; \
+ (ctSelf)->Log(cmCTest::logType, __FILE__, __LINE__,\
+ cmCTestLog_msg.str().c_str());\
+ } while ( 0 )
+
+#ifdef cerr
+# undef cerr
+#endif
+#define cerr no_cerr_use_cmCTestLog
+
+#ifdef cout
+# undef cout
+#endif
+#define cout no_cout_use_cmCTestLog
+
+class cmCTest
+{
+ friend class cmCTestRunTest;
+ friend class cmCTestMultiProcessHandler;
+public:
+ /** Enumerate parts of the testing and submission process. */
+ enum Part
+ {
+ PartStart,
+ PartUpdate,
+ PartConfigure,
+ PartBuild,
+ PartTest,
+ PartCoverage,
+ PartMemCheck,
+ PartSubmit,
+ PartNotes,
+ PartExtraFiles,
+ PartUpload,
+ PartCount // Update names in constructor when adding a part
+ };
+
+ /** Representation of one part. */
+ struct PartInfo
+ {
+ PartInfo(): Enabled(false) {}
+
+ void SetName(const std::string& name) { this->Name = name; }
+ const std::string& GetName() const { return this->Name; }
+
+ void Enable() { this->Enabled = true; }
+ operator bool() const { return this->Enabled; }
+
+ std::vector<std::string> SubmitFiles;
+ private:
+ bool Enabled;
+ std::string Name;
+ };
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ enum HTTPMethod {
+ HTTP_GET,
+ HTTP_POST,
+ HTTP_PUT
+ };
+
+ /**
+ * Perform an HTTP request.
+ */
+ static int HTTPRequest(std::string url, HTTPMethod method,
+ std::string& response,
+ std::string fields = "",
+ std::string putFile = "", int timeout = 0);
+#endif
+
+ /** Get a testing part id from its string name. Returns PartCount
+ if the string does not name a valid part. */
+ Part GetPartFromName(const char* name);
+
+ typedef std::vector<cmsys::String> VectorOfStrings;
+ typedef std::set<std::string> SetOfStrings;
+
+ ///! Process Command line arguments
+ int Run(std::vector<std::string> &, std::string* output = 0);
+
+ /**
+ * Initialize and finalize testing
+ */
+ bool InitializeFromCommand(cmCTestStartCommand* command);
+ void Finalize();
+
+ /**
+ * Process the tests. This is the main routine. The execution of the
+ * tests should look like this:
+ *
+ * ctest foo;
+ * foo.Initialize();
+ * // Set some things on foo
+ * foo.ProcessTests();
+ * foo.Finalize();
+ */
+ int ProcessTests();
+
+ /*
+ * A utility function that returns the nightly time
+ */
+ struct tm* GetNightlyTime(std::string str,
+ bool tomorrowtag);
+
+ /*
+ * Is the tomorrow tag set?
+ */
+ bool GetTomorrowTag() { return this->TomorrowTag; }
+
+ /**
+ * Try to run tests of the project
+ */
+ int TestDirectory(bool memcheck);
+
+ ///! what is the configuraiton type, e.g. Debug, Release etc.
+ std::string const& GetConfigType();
+ double GetTimeOut() { return this->TimeOut; }
+ void SetTimeOut(double t) { this->TimeOut = t; }
+
+ double GetGlobalTimeout() { return this->GlobalTimeout; }
+
+ // how many test to run at the same time
+ int GetParallelLevel() { return this->ParallelLevel; }
+ void SetParallelLevel(int);
+
+ /**
+ * Check if CTest file exists
+ */
+ bool CTestFileExists(const std::string& filename);
+ bool AddIfExists(Part part, const char* file);
+
+ /**
+ * Set the cmake test
+ */
+ bool SetTest(const char*, bool report = true);
+
+ /**
+ * Set the cmake test mode (experimental, nightly, continuous).
+ */
+ void SetTestModel(int mode);
+ int GetTestModel() { return this->TestModel; }
+
+ std::string GetTestModelString();
+ static int GetTestModelFromString(const char* str);
+ static std::string CleanString(const std::string& str);
+ std::string GetCTestConfiguration(const std::string& name);
+ void SetCTestConfiguration(const char *name, const char* value);
+ void EmptyCTestConfiguration();
+
+ /**
+ * constructor and destructor
+ */
+ cmCTest();
+ ~cmCTest();
+
+ //! Set the notes files to be created.
+ void SetNotesFiles(const char* notes);
+
+ void PopulateCustomVector(cmMakefile* mf, const std::string& definition,
+ std::vector<std::string>& vec);
+ void PopulateCustomInteger(cmMakefile* mf, const std::string& def,
+ int& val);
+
+ ///! Get the current time as string
+ std::string CurrentTime();
+
+ //! tar/gzip and then base 64 encode a file
+ std::string Base64GzipEncodeFile(std::string file);
+ //! base64 encode a file
+ std::string Base64EncodeFile(std::string file);
+
+ /**
+ * Return the time remaining that the script is allowed to run in
+ * seconds if the user has set the variable CTEST_TIME_LIMIT. If that has
+ * not been set it returns 1e7 seconds
+ */
+ double GetRemainingTimeAllowed();
+
+ ///! Open file in the output directory and set the stream
+ bool OpenOutputFile(const std::string& path,
+ const std::string& name,
+ cmGeneratedFileStream& stream,
+ bool compress = false);
+
+ ///! Should we only show what we would do?
+ bool GetShowOnly();
+
+ bool ShouldUseHTTP10() { return this->UseHTTP10; }
+
+ bool ShouldPrintLabels() { return this->PrintLabels; }
+
+ bool ShouldCompressTestOutput();
+ bool ShouldCompressMemCheckOutput();
+ bool CompressString(std::string& str);
+
+ std::string GetCDashVersion();
+
+ std::string GetStopTime() { return this->StopTime; }
+ void SetStopTime(std::string time);
+
+ //Used for parallel ctest job scheduling
+ std::string GetScheduleType() { return this->ScheduleType; }
+ void SetScheduleType(std::string type) { this->ScheduleType = type; }
+
+ ///! The max output width
+ int GetMaxTestNameWidth() const;
+ void SetMaxTestNameWidth(int w) { this->MaxTestNameWidth = w;}
+
+ /**
+ * Run a single executable command and put the stdout and stderr
+ * in output.
+ *
+ * If verbose is false, no user-viewable output from the program
+ * being run will be generated.
+ *
+ * If timeout is specified, the command will be terminated after
+ * timeout expires. Timeout is specified in seconds.
+ *
+ * Argument retVal should be a pointer to the location where the
+ * exit code will be stored. If the retVal is not specified and
+ * the program exits with a code other than 0, then the this
+ * function will return false.
+ *
+ * If the command has spaces in the path the caller MUST call
+ * cmSystemTools::ConvertToRunCommandPath on the command before passing
+ * it into this function or it will not work. The command must be correctly
+ * escaped for this to with spaces.
+ */
+ bool RunCommand(const char* command,
+ std::string* stdOut, std::string* stdErr,
+ int* retVal = 0, const char* dir = 0, double timeout = 0.0);
+
+ //! Clean/make safe for xml the given value such that it may be used as
+ // one of the key fields by CDash when computing the buildid.
+ static std::string SafeBuildIdField(const std::string& value);
+
+ //! Start CTest XML output file
+ void StartXML(std::ostream& ostr, bool append);
+
+ //! End CTest XML output file
+ void EndXML(std::ostream& ostr);
+
+ //! Run command specialized for make and configure. Returns process status
+ // and retVal is return value or exception.
+ int RunMakeCommand(const char* command, std::string& output,
+ int* retVal, const char* dir, int timeout,
+ std::ostream& ofs);
+
+ /*
+ * return the current tag
+ */
+ std::string GetCurrentTag();
+
+ //! Get the path to the build tree
+ std::string GetBinaryDir();
+
+ //! Get the short path to the file. This means if the file is in binary or
+ //source directory, it will become /.../relative/path/to/file
+ std::string GetShortPathToFile(const char* fname);
+
+ enum {
+ EXPERIMENTAL,
+ NIGHTLY,
+ CONTINUOUS
+ };
+
+ // provide some more detailed info on the return code for ctest
+ enum {
+ UPDATE_ERRORS = 0x01,
+ CONFIGURE_ERRORS = 0x02,
+ BUILD_ERRORS = 0x04,
+ TEST_ERRORS = 0x08,
+ MEMORY_ERRORS = 0x10,
+ COVERAGE_ERRORS = 0x20,
+ SUBMIT_ERRORS = 0x40
+ };
+
+ ///! Are we producing XML
+ bool GetProduceXML();
+ void SetProduceXML(bool v);
+
+ //! Run command specialized for tests. Returns process status and retVal is
+ // return value or exception. If environment is non-null, it is used to set
+ // environment variables prior to running the test. After running the test,
+ // environment variables are restored to their previous values.
+ int RunTest(std::vector<const char*> args, std::string* output, int *retVal,
+ std::ostream* logfile, double testTimeOut,
+ std::vector<std::string>* environment);
+
+ /**
+ * Execute handler and return its result. If the handler fails, it returns
+ * negative value.
+ */
+ int ExecuteHandler(const char* handler);
+
+ /*
+ * Get the handler object
+ */
+ cmCTestGenericHandler* GetHandler(const char* handler);
+ cmCTestGenericHandler* GetInitializedHandler(const char* handler);
+
+ /*
+ * Set the CTest variable from CMake variable
+ */
+ bool SetCTestConfigurationFromCMakeVariable(cmMakefile* mf,
+ const char* dconfig, const std::string& cmake_var);
+
+ //! Make string safe to be send as an URL
+ static std::string MakeURLSafe(const std::string&);
+
+ /** Decode a URL to the original string. */
+ static std::string DecodeURL(const std::string&);
+
+ //! Should ctect configuration be updated. When using new style ctest
+ // script, this should be true.
+ void SetSuppressUpdatingCTestConfiguration(bool val)
+ {
+ this->SuppressUpdatingCTestConfiguration = val;
+ }
+
+ //! Add overwrite to ctest configuration.
+ // The format is key=value
+ void AddCTestConfigurationOverwrite(const std::string& encstr);
+
+ //! Create XML file that contains all the notes specified
+ int GenerateNotesFile(const VectorOfStrings &files);
+
+ //! Submit extra files to the server
+ bool SubmitExtraFiles(const char* files);
+ bool SubmitExtraFiles(const VectorOfStrings &files);
+
+ //! Set the output log file name
+ void SetOutputLogFileName(const char* name);
+
+ //! Set the visual studio or Xcode config type
+ void SetConfigType(const char* ct);
+
+ //! Various log types
+ enum {
+ DEBUG = 0,
+ OUTPUT,
+ HANDLER_OUTPUT,
+ HANDLER_VERBOSE_OUTPUT,
+ WARNING,
+ ERROR_MESSAGE,
+ OTHER
+ };
+
+ //! Add log to the output
+ void Log(int logType, const char* file, int line, const char* msg);
+
+ //! Get the version of dart server
+ int GetDartVersion() { return this->DartVersion; }
+ int GetDropSiteCDash() { return this->DropSiteCDash; }
+
+ //! Add file to be submitted
+ void AddSubmitFile(Part part, const char* name);
+ std::vector<std::string> const& GetSubmitFiles(Part part)
+ { return this->Parts[part].SubmitFiles; }
+ void ClearSubmitFiles(Part part) { this->Parts[part].SubmitFiles.clear(); }
+
+ //! Read the custom configuration files and apply them to the current ctest
+ int ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf);
+
+ std::vector<std::string> &GetInitialCommandLineArguments()
+ { return this->InitialCommandLineArguments; }
+
+ //! Set the track to submit to
+ void SetSpecificTrack(const char* track);
+ const char* GetSpecificTrack();
+
+ void SetFailover(bool failover) { this->Failover = failover; }
+ bool GetFailover() { return this->Failover; }
+
+ void SetBatchJobs(bool batch = true) { this->BatchJobs = batch; }
+ bool GetBatchJobs() { return this->BatchJobs; }
+
+ bool GetVerbose() { return this->Verbose;}
+ bool GetExtraVerbose() { return this->ExtraVerbose;}
+
+ /** Direct process output to given streams. */
+ void SetStreams(std::ostream* out, std::ostream* err)
+ { this->StreamOut = out; this->StreamErr = err; }
+ void AddSiteProperties(std::ostream& );
+ bool GetLabelSummary() { return this->LabelSummary;}
+
+ std::string GetCostDataFile();
+
+ const std::map<std::string, std::string> &GetDefinitions()
+ {
+ return this->Definitions;
+ }
+
+private:
+ std::string ConfigType;
+ std::string ScheduleType;
+ std::string StopTime;
+ bool NextDayStopTime;
+ bool Verbose;
+ bool ExtraVerbose;
+ bool ProduceXML;
+ bool LabelSummary;
+ bool UseHTTP10;
+ bool PrintLabels;
+ bool Failover;
+ bool BatchJobs;
+
+ bool ForceNewCTestProcess;
+
+ bool RunConfigurationScript;
+
+ //flag for lazy getter (optimization)
+ bool ComputedCompressTestOutput;
+ bool ComputedCompressMemCheckOutput;
+
+ int GenerateNotesFile(const char* files);
+
+ void DetermineNextDayStop();
+
+ // these are helper classes
+ typedef std::map<std::string,cmCTestGenericHandler*> t_TestingHandlers;
+ t_TestingHandlers TestingHandlers;
+
+ bool ShowOnly;
+
+ //! Map of configuration properties
+ typedef std::map<std::string, std::string> CTestConfigurationMap;
+
+ std::string CTestConfigFile;
+ // TODO: The ctest configuration should be a hierarchy of
+ // configuration option sources: command-line, script, ini file.
+ // Then the ini file can get re-loaded whenever it changes without
+ // affecting any higher-precedence settings.
+ CTestConfigurationMap CTestConfiguration;
+ CTestConfigurationMap CTestConfigurationOverwrites;
+ PartInfo Parts[PartCount];
+ typedef std::map<std::string, Part> PartMapType;
+ PartMapType PartMap;
+
+ std::string CurrentTag;
+ bool TomorrowTag;
+
+ int TestModel;
+ std::string SpecificTrack;
+
+ double TimeOut;
+
+ double GlobalTimeout;
+
+ int LastStopTimeout;
+
+ int MaxTestNameWidth;
+
+ int ParallelLevel;
+ bool ParallelLevelSetInCli;
+
+ int CompatibilityMode;
+
+ // information for the --build-and-test options
+ std::string BinaryDir;
+
+ std::string NotesFiles;
+
+
+ bool InteractiveDebugMode;
+
+ bool ShortDateFormat;
+
+ bool CompressXMLFiles;
+ bool CompressTestOutput;
+ bool CompressMemCheckOutput;
+
+ void InitStreams();
+ std::ostream* StreamOut;
+ std::ostream* StreamErr;
+
+ void BlockTestErrorDiagnostics();
+
+ /**
+ * Initialize a dashboard run in the given build tree. The "command"
+ * argument is non-NULL when running from a command-driven (ctest_start)
+ * dashboard script, and NULL when running from the CTest command
+ * line. Note that a declarative dashboard script does not actually
+ * call this method because it sets CTEST_COMMAND to drive a build
+ * through the ctest command line.
+ */
+ int Initialize(const char* binary_dir, cmCTestStartCommand* command);
+
+ //! parse the option after -D and convert it into the appropriate steps
+ bool AddTestsForDashboardType(std::string &targ);
+
+ //! read as "emit an error message for an unknown -D value"
+ void ErrorMessageUnknownDashDValue(std::string &val);
+
+ //! add a variable definition from a command line -D value
+ bool AddVariableDefinition(const std::string &arg);
+
+ //! parse and process most common command line arguments
+ void HandleCommandLineArguments(size_t &i,
+ std::vector<std::string> &args);
+
+ //! hande the -S -SP and -SR arguments
+ void HandleScriptArguments(size_t &i,
+ std::vector<std::string> &args,
+ bool &SRArgumentSpecified);
+
+ //! Reread the configuration file
+ bool UpdateCTestConfiguration();
+
+ //! Create note from files.
+ int GenerateCTestNotesOutput(std::ostream& os,
+ const VectorOfStrings& files);
+
+ //! Check if the argument is the one specified
+ bool CheckArgument(const std::string& arg, const char* varg1,
+ const char* varg2 = 0);
+
+ //! Output errors from a test
+ void OutputTestErrors(std::vector<char> const &process_output);
+
+ bool SuppressUpdatingCTestConfiguration;
+
+ bool Debug;
+ bool ShowLineNumbers;
+ bool Quiet;
+
+ int DartVersion;
+ bool DropSiteCDash;
+
+ std::vector<std::string> InitialCommandLineArguments;
+
+ int SubmitIndex;
+
+ cmGeneratedFileStream* OutputLogFile;
+ int OutputLogFileLastTag;
+
+ bool OutputTestOutputOnTestFailure;
+
+ std::map<std::string, std::string> Definitions;
+};
+
+class cmCTestLogWrite
+{
+public:
+ cmCTestLogWrite(const char* data, size_t length)
+ : Data(data), Length(length) {}
+
+ const char* Data;
+ size_t Length;
+};
+
+inline std::ostream& operator<< (std::ostream& os, const cmCTestLogWrite& c)
+{
+ if (!c.Length)
+ {
+ return os;
+ }
+ os.write(c.Data, c.Length);
+ os.flush();
+ return os;
+}
+
+#endif
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
new file mode 100644
index 0000000000..d6b84a0002
--- /dev/null
+++ b/Source/cmCacheManager.cxx
@@ -0,0 +1,938 @@
+/*============================================================================
+ 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 "cmCacheManager.h"
+#include "cmSystemTools.h"
+#include "cmCacheManager.h"
+#include "cmGeneratedFileStream.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include "cmVersion.h"
+
+#include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+#include <cmsys/RegularExpression.hxx>
+
+const char* cmCacheManagerTypes[] =
+{ "BOOL",
+ "PATH",
+ "FILEPATH",
+ "STRING",
+ "INTERNAL",
+ "STATIC",
+ "UNINITIALIZED",
+ 0
+};
+
+cmCacheManager::cmCacheManager(cmake* cm)
+{
+ this->CacheMajorVersion = 0;
+ this->CacheMinorVersion = 0;
+ this->CMakeInstance = cm;
+}
+
+const char* cmCacheManager::TypeToString(cmCacheManager::CacheEntryType type)
+{
+ if ( type > 6 )
+ {
+ return cmCacheManagerTypes[6];
+ }
+ return cmCacheManagerTypes[type];
+}
+
+cmCacheManager::CacheEntryType cmCacheManager::StringToType(const char* s)
+{
+ int i = 0;
+ while(cmCacheManagerTypes[i])
+ {
+ if(strcmp(s, cmCacheManagerTypes[i]) == 0)
+ {
+ return static_cast<CacheEntryType>(i);
+ }
+ ++i;
+ }
+ return STRING;
+}
+
+bool cmCacheManager::IsType(const char* s)
+{
+ for(int i=0; cmCacheManagerTypes[i]; ++i)
+ {
+ if(strcmp(s, cmCacheManagerTypes[i]) == 0)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool cmCacheManager::LoadCache(cmMakefile* mf)
+{
+ return this->LoadCache(mf->GetHomeOutputDirectory());
+}
+
+
+bool cmCacheManager::LoadCache(const std::string& path)
+{
+ return this->LoadCache(path,true);
+}
+
+bool cmCacheManager::LoadCache(const std::string& path,
+ bool internal)
+{
+ std::set<std::string> emptySet;
+ return this->LoadCache(path, internal, 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,
+ 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 = cmCacheManager::StringToType(regQuoted.match(2).c_str());
+ value = regQuoted.match(3);
+ flag = true;
+ }
+ else if (reg.find(entry))
+ {
+ var = reg.match(1);
+ type = cmCacheManager::StringToType(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)
+{
+ std::string glob = path;
+ glob += cmake::GetCMakeFilesDirectory();
+ glob += "/*.cmake";
+ cmsys::Glob globIt;
+ globIt.FindFiles(glob);
+ std::vector<std::string> files = globIt.GetFiles();
+ for(std::vector<std::string>::iterator i = files.begin();
+ i != files.end(); ++i)
+ {
+ cmSystemTools::RemoveFile(i->c_str());
+ }
+}
+
+bool cmCacheManager::LoadCache(const std::string& path,
+ bool internal,
+ std::set<std::string>& excludes,
+ std::set<std::string>& includes)
+{
+ std::string cacheFile = path;
+ cacheFile += "/CMakeCache.txt";
+ // clear the old cache, if we are reading in internal values
+ if ( internal )
+ {
+ this->Cache.clear();
+ }
+ if(!cmSystemTools::FileExists(cacheFile.c_str()))
+ {
+ this->CleanCMakeFiles(path);
+ return false;
+ }
+
+ cmsys::ifstream fin(cacheFile.c_str());
+ if(!fin)
+ {
+ return false;
+ }
+ const char *realbuffer;
+ std::string buffer;
+ std::string entryKey;
+ while(fin)
+ {
+ // Format is key:type=value
+ std::string helpString;
+ CacheEntry e;
+ e.Properties.SetCMakeInstance(this->CMakeInstance);
+ cmSystemTools::GetLineFromStream(fin, buffer);
+ realbuffer = buffer.c_str();
+ while(*realbuffer != '0' &&
+ (*realbuffer == ' ' ||
+ *realbuffer == '\t' ||
+ *realbuffer == '\r' ||
+ *realbuffer == '\n'))
+ {
+ realbuffer++;
+ }
+ // skip blank lines and comment lines
+ if(realbuffer[0] == '#' || realbuffer[0] == 0)
+ {
+ continue;
+ }
+ while(realbuffer[0] == '/' && realbuffer[1] == '/')
+ {
+ if ((realbuffer[2] == '\\') && (realbuffer[3]=='n'))
+ {
+ helpString += "\n";
+ helpString += &realbuffer[4];
+ }
+ else
+ {
+ helpString += &realbuffer[2];
+ }
+ cmSystemTools::GetLineFromStream(fin, buffer);
+ realbuffer = buffer.c_str();
+ if(!fin)
+ {
+ continue;
+ }
+ }
+ e.SetProperty("HELPSTRING", helpString.c_str());
+ if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.Value, e.Type))
+ {
+ if ( excludes.find(entryKey) == excludes.end() )
+ {
+ // Load internal values if internal is set.
+ // If the entry is not internal to the cache being loaded
+ // or if it is in the list of internal entries to be
+ // imported, load it.
+ if ( internal || (e.Type != INTERNAL) ||
+ (includes.find(entryKey) != includes.end()) )
+ {
+ // If we are loading the cache from another project,
+ // make all loaded entries internal so that it is
+ // not visible in the gui
+ if (!internal)
+ {
+ e.Type = INTERNAL;
+ helpString = "DO NOT EDIT, ";
+ helpString += entryKey;
+ helpString += " loaded from external file. "
+ "To change this value edit this file: ";
+ helpString += path;
+ helpString += "/CMakeCache.txt" ;
+ e.SetProperty("HELPSTRING", helpString.c_str());
+ }
+ if(!this->ReadPropertyEntry(entryKey, e))
+ {
+ e.Initialized = true;
+ this->Cache[entryKey] = e;
+ }
+ }
+ }
+ }
+ else
+ {
+ cmSystemTools::Error("Parse error in cache file ", cacheFile.c_str(),
+ ". Offending entry: ", realbuffer);
+ }
+ }
+ this->CacheMajorVersion = 0;
+ this->CacheMinorVersion = 0;
+ if(const char* cmajor = this->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
+ {
+ unsigned int v=0;
+ if(sscanf(cmajor, "%u", &v) == 1)
+ {
+ this->CacheMajorVersion = v;
+ }
+ if(const char* cminor = this->GetCacheValue("CMAKE_CACHE_MINOR_VERSION"))
+ {
+ if(sscanf(cminor, "%u", &v) == 1)
+ {
+ this->CacheMinorVersion = v;
+ }
+ }
+ }
+ else
+ {
+ // CMake version not found in the list file.
+ // Set as version 0.0
+ this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", "0",
+ "Minor version of cmake used to create the "
+ "current loaded cache", cmCacheManager::INTERNAL);
+ this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", "0",
+ "Major version of cmake used to create the "
+ "current loaded cache", cmCacheManager::INTERNAL);
+
+ }
+ // check to make sure the cache directory has not
+ // been moved
+ if ( internal && this->GetCacheValue("CMAKE_CACHEFILE_DIR") )
+ {
+ std::string currentcwd = path;
+ std::string oldcwd = this->GetCacheValue("CMAKE_CACHEFILE_DIR");
+ cmSystemTools::ConvertToUnixSlashes(currentcwd);
+ currentcwd += "/CMakeCache.txt";
+ oldcwd += "/CMakeCache.txt";
+ if(!cmSystemTools::SameFile(oldcwd.c_str(), currentcwd.c_str()))
+ {
+ std::string message =
+ std::string("The current CMakeCache.txt directory ") +
+ currentcwd + std::string(" is different than the directory ") +
+ std::string(this->GetCacheValue("CMAKE_CACHEFILE_DIR")) +
+ std::string(" where CMakeCache.txt was created. This may result "
+ "in binaries being created in the wrong place. If you "
+ "are not sure, reedit the CMakeCache.txt");
+ cmSystemTools::Error(message.c_str());
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+const char* cmCacheManager::PersistentProperties[] =
+{
+ "ADVANCED",
+ "MODIFIED",
+ "STRINGS",
+ 0
+};
+
+//----------------------------------------------------------------------------
+bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
+ CacheEntry& e)
+{
+ // All property entries are internal.
+ if(e.Type != cmCacheManager::INTERNAL)
+ {
+ return false;
+ }
+
+ const char* end = entryKey.c_str() + entryKey.size();
+ for(const char** p = this->PersistentProperties; *p; ++p)
+ {
+ std::string::size_type plen = strlen(*p) + 1;
+ if(entryKey.size() > plen && *(end-plen) == '-' &&
+ strcmp(end-plen+1, *p) == 0)
+ {
+ std::string key = entryKey.substr(0, entryKey.size() - plen);
+ cmCacheManager::CacheIterator it = this->GetCacheIterator(key.c_str());
+ if(it.IsAtEnd())
+ {
+ // Create an entry and store the property.
+ CacheEntry& ne = this->Cache[key];
+ ne.Properties.SetCMakeInstance(this->CMakeInstance);
+ ne.Type = cmCacheManager::UNINITIALIZED;
+ ne.SetProperty(*p, e.Value.c_str());
+ }
+ else
+ {
+ // Store this property on its entry.
+ it.SetProperty(*p, e.Value.c_str());
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmCacheManager::WritePropertyEntries(std::ostream& os,
+ CacheIterator const& i)
+{
+ for(const char** p = this->PersistentProperties; *p; ++p)
+ {
+ if(const char* value = i.GetProperty(*p))
+ {
+ std::string helpstring = *p;
+ helpstring += " property for variable: ";
+ helpstring += i.GetName();
+ cmCacheManager::OutputHelpString(os, helpstring);
+
+ std::string key = i.GetName();
+ key += "-";
+ key += *p;
+ this->OutputKey(os, key);
+ os << ":INTERNAL=";
+ this->OutputValue(os, value);
+ os << "\n";
+ }
+ }
+}
+
+bool cmCacheManager::SaveCache(cmMakefile* mf)
+{
+ return this->SaveCache(mf->GetHomeOutputDirectory());
+}
+
+
+bool cmCacheManager::SaveCache(const std::string& path)
+{
+ std::string cacheFile = path;
+ cacheFile += "/CMakeCache.txt";
+ cmGeneratedFileStream fout(cacheFile.c_str());
+ fout.SetCopyIfDifferent(true);
+ if(!fout)
+ {
+ cmSystemTools::Error("Unable to open cache file for save. ",
+ cacheFile.c_str());
+ cmSystemTools::ReportLastSystemError("");
+ return false;
+ }
+ // before writing the cache, update the version numbers
+ // to the
+ char temp[1024];
+ sprintf(temp, "%d", cmVersion::GetMinorVersion());
+ this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", temp,
+ "Minor version of cmake used to create the "
+ "current loaded cache", cmCacheManager::INTERNAL);
+ sprintf(temp, "%d", cmVersion::GetMajorVersion());
+ this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", temp,
+ "Major version of cmake used to create the "
+ "current loaded cache", cmCacheManager::INTERNAL);
+ sprintf(temp, "%d", cmVersion::GetPatchVersion());
+ this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION", temp,
+ "Patch version of cmake used to create the "
+ "current loaded cache", cmCacheManager::INTERNAL);
+
+ // Let us store the current working directory so that if somebody
+ // Copies it, he will not be surprised
+ std::string currentcwd = path;
+ if ( currentcwd[0] >= 'A' && currentcwd[0] <= 'Z' &&
+ currentcwd[1] == ':' )
+ {
+ // Cast added to avoid compiler warning. Cast is ok because
+ // value is guaranteed to fit in char by the above if...
+ currentcwd[0] = static_cast<char>(currentcwd[0] - 'A' + 'a');
+ }
+ cmSystemTools::ConvertToUnixSlashes(currentcwd);
+ this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd.c_str(),
+ "This is the directory where this CMakeCache.txt"
+ " was created", cmCacheManager::INTERNAL);
+
+ fout << "# This is the CMakeCache file.\n"
+ << "# For build in directory: " << currentcwd << "\n";
+ cmCacheManager::CacheEntry* cmakeCacheEntry
+ = this->GetCacheEntry("CMAKE_COMMAND");
+ if ( cmakeCacheEntry )
+ {
+ fout << "# It was generated by CMake: " <<
+ cmakeCacheEntry->Value << std::endl;
+ }
+
+ fout << "# You can edit this file to change values found and used by cmake."
+ << std::endl
+ << "# If you do not want to change any of the values, simply exit the "
+ "editor." << std::endl
+ << "# If you do want to change a value, simply edit, save, and exit "
+ "the editor." << std::endl
+ << "# The syntax for the file is as follows:\n"
+ << "# KEY:TYPE=VALUE\n"
+ << "# KEY is the name of a variable in the cache.\n"
+ << "# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT "
+ "TYPE!." << std::endl
+ << "# VALUE is the current value for the KEY.\n\n";
+
+ fout << "########################\n";
+ fout << "# EXTERNAL cache entries\n";
+ fout << "########################\n";
+ fout << "\n";
+
+ for( std::map<std::string, CacheEntry>::const_iterator i =
+ this->Cache.begin(); i != this->Cache.end(); ++i)
+ {
+ const CacheEntry& ce = (*i).second;
+ CacheEntryType t = ce.Type;
+ if(!ce.Initialized)
+ {
+ /*
+ // This should be added in, but is not for now.
+ cmSystemTools::Error("Cache entry \"", (*i).first.c_str(),
+ "\" is uninitialized");
+ */
+ }
+ else if(t != INTERNAL)
+ {
+ // Format is key:type=value
+ if(const char* help = ce.GetProperty("HELPSTRING"))
+ {
+ cmCacheManager::OutputHelpString(fout, help);
+ }
+ else
+ {
+ cmCacheManager::OutputHelpString(fout, "Missing description");
+ }
+ this->OutputKey(fout, i->first);
+ fout << ":" << cmCacheManagerTypes[t] << "=";
+ this->OutputValue(fout, ce.Value);
+ fout << "\n\n";
+ }
+ }
+
+ fout << "\n";
+ fout << "########################\n";
+ fout << "# INTERNAL cache entries\n";
+ fout << "########################\n";
+ fout << "\n";
+
+ for( cmCacheManager::CacheIterator i = this->NewIterator();
+ !i.IsAtEnd(); i.Next())
+ {
+ if ( !i.Initialized() )
+ {
+ continue;
+ }
+
+ CacheEntryType t = i.GetType();
+ this->WritePropertyEntries(fout, i);
+ if(t == cmCacheManager::INTERNAL)
+ {
+ // Format is key:type=value
+ if(const char* help = i.GetProperty("HELPSTRING"))
+ {
+ this->OutputHelpString(fout, help);
+ }
+ this->OutputKey(fout, i.GetName());
+ fout << ":" << cmCacheManagerTypes[t] << "=";
+ this->OutputValue(fout, i.GetValue());
+ fout << "\n";
+ }
+ }
+ fout << "\n";
+ fout.Close();
+ std::string checkCacheFile = path;
+ checkCacheFile += cmake::GetCMakeFilesDirectory();
+ cmSystemTools::MakeDirectory(checkCacheFile.c_str());
+ checkCacheFile += "/cmake.check_cache";
+ cmsys::ofstream checkCache(checkCacheFile.c_str());
+ if(!checkCache)
+ {
+ cmSystemTools::Error("Unable to open check cache file for write. ",
+ checkCacheFile.c_str());
+ return false;
+ }
+ checkCache << "# This file is generated by cmake for dependency checking "
+ "of the CMakeCache.txt file\n";
+ return true;
+}
+
+bool cmCacheManager::DeleteCache(const std::string& path)
+{
+ std::string cacheFile = path;
+ cmSystemTools::ConvertToUnixSlashes(cacheFile);
+ std::string cmakeFiles = cacheFile;
+ cacheFile += "/CMakeCache.txt";
+ if(cmSystemTools::FileExists(cacheFile.c_str()))
+ {
+ cmSystemTools::RemoveFile(cacheFile.c_str());
+ // now remove the files in the CMakeFiles directory
+ // this cleans up language cache files
+ cmakeFiles += cmake::GetCMakeFilesDirectory();
+ if(cmSystemTools::FileIsDirectory(cmakeFiles.c_str()))
+ {
+ cmSystemTools::RemoveADirectory(cmakeFiles.c_str());
+ }
+ }
+ return true;
+}
+
+void cmCacheManager::OutputKey(std::ostream& fout, std::string const& key)
+{
+ // support : in key name by double quoting
+ const char* q = (key.find(':') != key.npos ||
+ key.find("//") == 0)? "\"" : "";
+ fout << q << key << q;
+}
+
+void cmCacheManager::OutputValue(std::ostream& fout, std::string const& value)
+{
+ // if value has trailing space or tab, enclose it in single quotes
+ if (value.size() &&
+ (value[value.size() - 1] == ' ' ||
+ value[value.size() - 1] == '\t'))
+ {
+ fout << '\'' << value << '\'';
+ }
+ else
+ {
+ fout << value;
+ }
+}
+
+void cmCacheManager::OutputHelpString(std::ostream& fout,
+ const std::string& helpString)
+{
+ std::string::size_type end = helpString.size();
+ if(end == 0)
+ {
+ return;
+ }
+ std::string oneLine;
+ std::string::size_type pos = 0;
+ for (std::string::size_type i=0; i<=end; i++)
+ {
+ if ((i==end)
+ || (helpString[i]=='\n')
+ || ((i-pos >= 60) && (helpString[i]==' ')))
+ {
+ fout << "//";
+ if (helpString[pos] == '\n')
+ {
+ pos++;
+ fout << "\\n";
+ }
+ oneLine = helpString.substr(pos, i - pos);
+ fout << oneLine << "\n";
+ pos = i;
+ }
+ }
+}
+
+void cmCacheManager::RemoveCacheEntry(const std::string& key)
+{
+ CacheEntryMap::iterator i = this->Cache.find(key);
+ if(i != this->Cache.end())
+ {
+ this->Cache.erase(i);
+ }
+}
+
+
+cmCacheManager::CacheEntry *cmCacheManager::GetCacheEntry(
+ const std::string& key)
+{
+ CacheEntryMap::iterator i = this->Cache.find(key);
+ if(i != this->Cache.end())
+ {
+ return &i->second;
+ }
+ return 0;
+}
+
+cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(
+ const char *key)
+{
+ return CacheIterator(*this, key);
+}
+
+const char* cmCacheManager::GetCacheValue(const std::string& key) const
+{
+ CacheEntryMap::const_iterator i = this->Cache.find(key);
+ if(i != this->Cache.end() &&
+ i->second.Initialized)
+ {
+ return i->second.Value.c_str();
+ }
+ return 0;
+}
+
+
+void cmCacheManager::PrintCache(std::ostream& out) const
+{
+ out << "=================================================" << std::endl;
+ out << "CMakeCache Contents:" << std::endl;
+ for(std::map<std::string, CacheEntry>::const_iterator i =
+ this->Cache.begin(); i != this->Cache.end(); ++i)
+ {
+ if((*i).second.Type != INTERNAL)
+ {
+ out << (*i).first << " = " << (*i).second.Value
+ << std::endl;
+ }
+ }
+ out << "\n\n";
+ out << "To change values in the CMakeCache, "
+ << std::endl << "edit CMakeCache.txt in your output directory.\n";
+ out << "=================================================" << std::endl;
+}
+
+
+void cmCacheManager::AddCacheEntry(const std::string& key,
+ const char* value,
+ const char* helpString,
+ CacheEntryType type)
+{
+ CacheEntry& e = this->Cache[key];
+ e.Properties.SetCMakeInstance(this->CMakeInstance);
+ if ( value )
+ {
+ e.Value = value;
+ e.Initialized = true;
+ }
+ else
+ {
+ e.Value = "";
+ }
+ e.Type = type;
+ // make sure we only use unix style paths
+ if(type == FILEPATH || type == PATH)
+ {
+ if(e.Value.find(';') != e.Value.npos)
+ {
+ std::vector<std::string> paths;
+ cmSystemTools::ExpandListArgument(e.Value, paths);
+ const char* sep = "";
+ e.Value = "";
+ for(std::vector<std::string>::iterator i = paths.begin();
+ i != paths.end(); ++i)
+ {
+ cmSystemTools::ConvertToUnixSlashes(*i);
+ e.Value += sep;
+ e.Value += *i;
+ sep = ";";
+ }
+ }
+ else
+ {
+ cmSystemTools::ConvertToUnixSlashes(e.Value);
+ }
+ }
+ e.SetProperty("HELPSTRING", helpString? helpString :
+ "(This variable does not exist and should not be used)");
+ this->CMakeInstance->UnwatchUnusedCli(key);
+}
+
+bool cmCacheManager::CacheIterator::IsAtEnd() const
+{
+ return this->Position == this->Container.Cache.end();
+}
+
+void cmCacheManager::CacheIterator::Begin()
+{
+ this->Position = this->Container.Cache.begin();
+}
+
+bool cmCacheManager::CacheIterator::Find(const std::string& key)
+{
+ this->Position = this->Container.Cache.find(key);
+ return !this->IsAtEnd();
+}
+
+void cmCacheManager::CacheIterator::Next()
+{
+ if (!this->IsAtEnd())
+ {
+ ++this->Position;
+ }
+}
+
+void cmCacheManager::CacheIterator::SetValue(const char* value)
+{
+ if (this->IsAtEnd())
+ {
+ return;
+ }
+ CacheEntry* entry = &this->GetEntry();
+ if ( value )
+ {
+ entry->Value = value;
+ entry->Initialized = true;
+ }
+ else
+ {
+ entry->Value = "";
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCacheManager::CacheIterator::GetValueAsBool() const
+{
+ return cmSystemTools::IsOn(this->GetEntry().Value.c_str());
+}
+
+//----------------------------------------------------------------------------
+const char*
+cmCacheManager::CacheEntry::GetProperty(const std::string& prop) const
+{
+ if(prop == "TYPE")
+ {
+ return cmCacheManagerTypes[this->Type];
+ }
+ else if(prop == "VALUE")
+ {
+ return this->Value.c_str();
+ }
+ bool c = false;
+ return
+ this->Properties.GetPropertyValue(prop, cmProperty::CACHE, c);
+}
+
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheEntry::SetProperty(const std::string& prop,
+ const char* value)
+{
+ if(prop == "TYPE")
+ {
+ this->Type = cmCacheManager::StringToType(value? value : "STRING");
+ }
+ else if(prop == "VALUE")
+ {
+ this->Value = value? value : "";
+ }
+ else
+ {
+ this->Properties.SetProperty(prop, value, cmProperty::CACHE);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop,
+ const char* value,
+ bool asString)
+{
+ if(prop == "TYPE")
+ {
+ this->Type = cmCacheManager::StringToType(value? value : "STRING");
+ }
+ else if(prop == "VALUE")
+ {
+ if(value)
+ {
+ if(!this->Value.empty() && *value && !asString)
+ {
+ this->Value += ";";
+ }
+ this->Value += value;
+ }
+ }
+ else
+ {
+ this->Properties.AppendProperty(prop, value, cmProperty::CACHE, asString);
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmCacheManager::CacheIterator::GetProperty(
+ const std::string& prop) const
+{
+ if(!this->IsAtEnd())
+ {
+ return this->GetEntry().GetProperty(prop);
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheIterator::SetProperty(const std::string& p,
+ const char* v)
+{
+ if(!this->IsAtEnd())
+ {
+ this->GetEntry().SetProperty(p, v);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheIterator::AppendProperty(const std::string& p,
+ const char* v,
+ bool asString)
+{
+ if(!this->IsAtEnd())
+ {
+ this->GetEntry().AppendProperty(p, v, asString);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCacheManager::CacheIterator::GetPropertyAsBool(
+ const std::string& prop) const
+{
+ if(const char* value = this->GetProperty(prop))
+ {
+ return cmSystemTools::IsOn(value);
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheIterator::SetProperty(const std::string& p, bool v)
+{
+ this->SetProperty(p, v ? "ON" : "OFF");
+}
+
+//----------------------------------------------------------------------------
+bool cmCacheManager::CacheIterator::PropertyExists(
+ const std::string& prop) const
+{
+ return this->GetProperty(prop)? true:false;
+}
+
+//----------------------------------------------------------------------------
+bool cmCacheManager::NeedCacheCompatibility(int major, int minor)
+{
+ // Compatibility is not needed if the cache version is zero because
+ // the cache was created or modified by the user.
+ if(this->CacheMajorVersion == 0)
+ {
+ return false;
+ }
+
+ // Compatibility is needed if the cache version is equal to or lower
+ // than the given version.
+ cmIML_INT_uint64_t actual_compat =
+ CMake_VERSION_ENCODE(this->CacheMajorVersion, this->CacheMinorVersion, 0);
+ return (actual_compat &&
+ actual_compat <= CMake_VERSION_ENCODE(major, minor, 0));
+}
diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h
new file mode 100644
index 0000000000..d9a91123fb
--- /dev/null
+++ b/Source/cmCacheManager.h
@@ -0,0 +1,187 @@
+/*============================================================================
+ 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 cmCacheManager_h
+#define cmCacheManager_h
+
+#include "cmStandardIncludes.h"
+#include "cmPropertyMap.h"
+class cmMakefile;
+class cmMarkAsAdvancedCommand;
+class cmake;
+
+/** \class cmCacheManager
+ * \brief Control class for cmake's cache
+ *
+ * Load and Save CMake cache files.
+ *
+ */
+class cmCacheManager
+{
+public:
+ cmCacheManager(cmake* cm);
+ class CacheIterator;
+ friend class cmCacheManager::CacheIterator;
+ enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
+ UNINITIALIZED };
+
+private:
+ struct CacheEntry
+ {
+ std::string Value;
+ CacheEntryType Type;
+ cmPropertyMap Properties;
+ const char* GetProperty(const std::string&) const;
+ void SetProperty(const std::string& property, const char* value);
+ void AppendProperty(const std::string& property, const char* value,
+ bool asString=false);
+ bool Initialized;
+ CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false)
+ {}
+ };
+
+public:
+ class CacheIterator
+ {
+ public:
+ void Begin();
+ bool Find(const std::string&);
+ bool IsAtEnd() const;
+ void Next();
+ std::string GetName() const {
+ return this->Position->first; }
+ const char* GetProperty(const std::string&) const ;
+ bool GetPropertyAsBool(const std::string&) const ;
+ bool PropertyExists(const std::string&) const;
+ void SetProperty(const std::string& property, const char* value);
+ void AppendProperty(const std::string& property, const char* value,
+ bool asString=false);
+ void SetProperty(const std::string& property, bool value);
+ std::string GetValue() const { return this->GetEntry().Value; }
+ bool GetValueAsBool() const;
+ void SetValue(const char*);
+ CacheEntryType GetType() const { return this->GetEntry().Type; }
+ void SetType(CacheEntryType ty) { this->GetEntry().Type = ty; }
+ bool Initialized() { return this->GetEntry().Initialized; }
+ cmCacheManager &Container;
+ std::map<std::string, CacheEntry>::iterator Position;
+ CacheIterator(cmCacheManager &cm) : Container(cm) {
+ this->Begin();
+ }
+ CacheIterator(cmCacheManager &cm, const char* key) : Container(cm)
+ {
+ if ( key )
+ {
+ this->Find(key);
+ }
+ }
+ private:
+ CacheEntry const& GetEntry() const { return this->Position->second; }
+ CacheEntry& GetEntry() { return this->Position->second; }
+ };
+
+ ///! return an iterator to iterate through the cache map
+ cmCacheManager::CacheIterator NewIterator()
+ {
+ return CacheIterator(*this);
+ }
+
+ /**
+ * Types for the cache entries. These are useful as
+ * hints for a cache editor program. Path should bring
+ * up a file chooser, BOOL a check box, and STRING a
+ * text entry box, FILEPATH is a full path to a file which
+ * can be different than just a path input
+ */
+ static CacheEntryType StringToType(const char*);
+ static const char* TypeToString(CacheEntryType);
+ static bool IsType(const char*);
+
+ ///! Load a cache for given makefile. Loads from ouput home.
+ bool LoadCache(cmMakefile*);
+ ///! 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);
+ bool LoadCache(const std::string& path, bool internal,
+ std::set<std::string>& excludes,
+ std::set<std::string>& includes);
+
+ ///! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
+ bool SaveCache(cmMakefile*) ;
+ ///! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
+ bool SaveCache(const std::string& path) ;
+
+ ///! Delete the cache given
+ bool DeleteCache(const std::string& path);
+
+ ///! Print the cache to a stream
+ void PrintCache(std::ostream&) const;
+
+ ///! Get the iterator for an entry with a given key.
+ cmCacheManager::CacheIterator GetCacheIterator(const char *key=0);
+
+ ///! Remove an entry from the cache
+ void RemoveCacheEntry(const std::string& key);
+
+ ///! Get the number of entries in the cache
+ 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,
+ CacheEntryType& type);
+
+ ///! Get a value from the cache given a key
+ const char* GetCacheValue(const std::string& key) const;
+
+ /** Get the version of CMake that wrote the cache. */
+ unsigned int GetCacheMajorVersion() const
+ { return this->CacheMajorVersion; }
+ unsigned int GetCacheMinorVersion() const
+ { return this->CacheMinorVersion; }
+ bool NeedCacheCompatibility(int major, int minor);
+
+protected:
+ ///! Add an entry into the cache
+ void AddCacheEntry(const std::string& key, const char* value,
+ const char* helpString, CacheEntryType type);
+
+ ///! Get a cache entry object for a key
+ CacheEntry *GetCacheEntry(const std::string& key);
+ ///! Clean out the CMakeFiles directory if no CMakeCache.txt
+ void CleanCMakeFiles(const std::string& path);
+
+ // Cache version info
+ unsigned int CacheMajorVersion;
+ unsigned int CacheMinorVersion;
+private:
+ cmake* CMakeInstance;
+ typedef std::map<std::string, CacheEntry> CacheEntryMap;
+ static void OutputHelpString(std::ostream& fout,
+ const std::string& helpString);
+ static void OutputKey(std::ostream& fout, std::string const& key);
+ static void OutputValue(std::ostream& fout, std::string const& value);
+
+ static const char* PersistentProperties[];
+ bool ReadPropertyEntry(std::string const& key, CacheEntry& e);
+ void WritePropertyEntries(std::ostream& os, CacheIterator const& i);
+
+ CacheEntryMap Cache;
+ // Only cmake and cmMakefile should be able to add cache values
+ // the commands should never use the cmCacheManager directly
+ friend class cmMakefile; // allow access to add cache values
+ friend class cmake; // allow access to add cache values
+ friend class cmMarkAsAdvancedCommand; // allow access to add cache values
+};
+
+#endif
diff --git a/Source/cmCallVisualStudioMacro.cxx b/Source/cmCallVisualStudioMacro.cxx
new file mode 100644
index 0000000000..0c154770d3
--- /dev/null
+++ b/Source/cmCallVisualStudioMacro.cxx
@@ -0,0 +1,540 @@
+/*============================================================================
+ 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 "cmCallVisualStudioMacro.h"
+#include "cmSystemTools.h"
+
+
+#if defined(_MSC_VER)
+#define HAVE_COMDEF_H
+#endif
+
+
+// Just for this file:
+//
+static bool LogErrorsAsMessages;
+
+
+#if defined(HAVE_COMDEF_H)
+
+
+#include <comdef.h>
+
+
+//----------------------------------------------------------------------------
+// Copied from a correct comdef.h to avoid problems with deficient versions
+// of comdef.h that exist in the wild... Fixes issue #7533.
+//
+#if ( _MSC_VER >= 1300 )
+// VS7 and later:
+#ifdef _NATIVE_WCHAR_T_DEFINED
+# ifdef _DEBUG
+# pragma comment(lib, "comsuppwd.lib")
+# else
+# pragma comment(lib, "comsuppw.lib")
+# endif
+#else
+# ifdef _DEBUG
+# pragma comment(lib, "comsuppd.lib")
+# else
+# pragma comment(lib, "comsupp.lib")
+# endif
+#endif
+#else
+// VS6 only had comsupp.lib:
+# pragma comment(lib, "comsupp.lib")
+#endif
+
+
+//----------------------------------------------------------------------------
+///! Use ReportHRESULT to make a cmSystemTools::Message after calling
+///! a COM method that may have failed.
+#define ReportHRESULT(hr, context) \
+ if (FAILED(hr)) \
+ { \
+ if (LogErrorsAsMessages) \
+ { \
+ std::ostringstream oss; \
+ oss.flags(std::ios::hex); \
+ oss << context << " failed HRESULT, hr = 0x" << hr << std::endl; \
+ oss.flags(std::ios::dec); \
+ oss << __FILE__ << "(" << __LINE__ << ")"; \
+ cmSystemTools::Message(oss.str().c_str()); \
+ } \
+ }
+
+
+//----------------------------------------------------------------------------
+///! Using the given instance of Visual Studio, call the named macro
+HRESULT InstanceCallMacro(
+ IDispatch* vsIDE,
+ const std::string& macro,
+ const std::string& args)
+{
+ HRESULT hr = E_POINTER;
+
+ _bstr_t macroName(macro.c_str());
+ _bstr_t macroArgs(args.c_str());
+
+ if (0 != vsIDE)
+ {
+ DISPID dispid = (DISPID) -1;
+ OLECHAR *name = L"ExecuteCommand";
+
+ hr = vsIDE->GetIDsOfNames(IID_NULL, &name, 1,
+ LOCALE_USER_DEFAULT, &dispid);
+ ReportHRESULT(hr, "GetIDsOfNames(ExecuteCommand)");
+
+ if (SUCCEEDED(hr))
+ {
+ VARIANTARG vargs[2];
+ DISPPARAMS params;
+ VARIANT result;
+ EXCEPINFO excep;
+ UINT arg = (UINT) -1;
+
+ // No VariantInit or VariantClear calls are necessary for
+ // these two vargs. They are both local _bstr_t variables
+ // that remain in scope for the duration of the Invoke call.
+ //
+ V_VT(&vargs[1]) = VT_BSTR;
+ V_BSTR(&vargs[1]) = macroName;
+ V_VT(&vargs[0]) = VT_BSTR;
+ V_BSTR(&vargs[0]) = macroArgs;
+
+ params.rgvarg = &vargs[0];
+ params.rgdispidNamedArgs = 0;
+ params.cArgs = sizeof(vargs)/sizeof(vargs[0]);
+ params.cNamedArgs = 0;
+
+ VariantInit(&result);
+
+ memset(&excep, 0, sizeof(excep));
+
+ hr = vsIDE->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
+ DISPATCH_METHOD, &params, &result, &excep, &arg);
+
+ std::ostringstream oss;
+ oss << std::endl;
+ oss << "Invoke(ExecuteCommand)" << std::endl;
+ oss << " Macro: " << macro.c_str() << std::endl;
+ oss << " Args: " << args.c_str() << std::endl;
+
+ if (DISP_E_EXCEPTION == hr)
+ {
+ oss << "DISP_E_EXCEPTION EXCEPINFO:" << excep.wCode << std::endl;
+ oss << " wCode: " << excep.wCode << std::endl;
+ oss << " wReserved: " << excep.wReserved << std::endl;
+ if (excep.bstrSource)
+ {
+ oss << " bstrSource: " <<
+ (const char*)(_bstr_t)excep.bstrSource << std::endl;
+ }
+ if (excep.bstrDescription)
+ {
+ oss << " bstrDescription: " <<
+ (const char*)(_bstr_t)excep.bstrDescription << std::endl;
+ }
+ if (excep.bstrHelpFile)
+ {
+ oss << " bstrHelpFile: " <<
+ (const char*)(_bstr_t)excep.bstrHelpFile << std::endl;
+ }
+ oss << " dwHelpContext: " << excep.dwHelpContext << std::endl;
+ oss << " pvReserved: " << excep.pvReserved << std::endl;
+ oss << " pfnDeferredFillIn: " << excep.pfnDeferredFillIn << std::endl;
+ oss << " scode: " << excep.scode << std::endl;
+ }
+
+ std::string exstr(oss.str());
+ ReportHRESULT(hr, exstr.c_str());
+
+ VariantClear(&result);
+ }
+ }
+
+ return hr;
+}
+
+
+//----------------------------------------------------------------------------
+///! Get the Solution object from the IDE object
+HRESULT GetSolutionObject(
+ IDispatch* vsIDE,
+ IDispatchPtr& vsSolution)
+{
+ HRESULT hr = E_POINTER;
+
+ if (0 != vsIDE)
+ {
+ DISPID dispid = (DISPID) -1;
+ OLECHAR *name = L"Solution";
+
+ hr = vsIDE->GetIDsOfNames(IID_NULL, &name, 1,
+ LOCALE_USER_DEFAULT, &dispid);
+ ReportHRESULT(hr, "GetIDsOfNames(Solution)");
+
+ if (SUCCEEDED(hr))
+ {
+ DISPPARAMS params;
+ VARIANT result;
+ EXCEPINFO excep;
+ UINT arg = (UINT) -1;
+
+ params.rgvarg = 0;
+ params.rgdispidNamedArgs = 0;
+ params.cArgs = 0;
+ params.cNamedArgs = 0;
+
+ VariantInit(&result);
+
+ memset(&excep, 0, sizeof(excep));
+
+ hr = vsIDE->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
+ DISPATCH_PROPERTYGET, &params, &result, &excep, &arg);
+ ReportHRESULT(hr, "Invoke(Solution)");
+
+ if (SUCCEEDED(hr))
+ {
+ vsSolution = V_DISPATCH(&result);
+ }
+
+ VariantClear(&result);
+ }
+ }
+
+ return hr;
+}
+
+
+//----------------------------------------------------------------------------
+///! Get the FullName property from the Solution object
+HRESULT GetSolutionFullName(
+ IDispatch* vsSolution,
+ std::string& fullName)
+{
+ HRESULT hr = E_POINTER;
+
+ if (0 != vsSolution)
+ {
+ DISPID dispid = (DISPID) -1;
+ OLECHAR *name = L"FullName";
+
+ hr = vsSolution->GetIDsOfNames(IID_NULL, &name, 1,
+ LOCALE_USER_DEFAULT, &dispid);
+ ReportHRESULT(hr, "GetIDsOfNames(FullName)");
+
+ if (SUCCEEDED(hr))
+ {
+ DISPPARAMS params;
+ VARIANT result;
+ EXCEPINFO excep;
+ UINT arg = (UINT) -1;
+
+ params.rgvarg = 0;
+ params.rgdispidNamedArgs = 0;
+ params.cArgs = 0;
+ params.cNamedArgs = 0;
+
+ VariantInit(&result);
+
+ memset(&excep, 0, sizeof(excep));
+
+ hr = vsSolution->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
+ DISPATCH_PROPERTYGET, &params, &result, &excep, &arg);
+ ReportHRESULT(hr, "Invoke(FullName)");
+
+ if (SUCCEEDED(hr))
+ {
+ fullName = (std::string) (_bstr_t) V_BSTR(&result);
+ }
+
+ VariantClear(&result);
+ }
+ }
+
+ return hr;
+}
+
+
+//----------------------------------------------------------------------------
+///! Get the FullName property from the Solution object, given the IDE object
+HRESULT GetIDESolutionFullName(
+ IDispatch* vsIDE,
+ std::string& fullName)
+{
+ IDispatchPtr vsSolution;
+ HRESULT hr = GetSolutionObject(vsIDE, vsSolution);
+ ReportHRESULT(hr, "GetSolutionObject");
+
+ if (SUCCEEDED(hr))
+ {
+ GetSolutionFullName(vsSolution, fullName);
+ ReportHRESULT(hr, "GetSolutionFullName");
+ }
+
+ return hr;
+}
+
+
+//----------------------------------------------------------------------------
+///! Get all running objects from the Windows running object table.
+///! Save them in a map by their display names.
+HRESULT GetRunningInstances(std::map<std::string, IUnknownPtr>& mrot)
+{
+ // mrot == Map of the Running Object Table
+
+ IRunningObjectTablePtr runningObjectTable;
+ IEnumMonikerPtr monikerEnumerator;
+ IMonikerPtr moniker;
+ ULONG numFetched = 0;
+
+ HRESULT hr = GetRunningObjectTable(0, &runningObjectTable);
+ ReportHRESULT(hr, "GetRunningObjectTable");
+
+ if(SUCCEEDED(hr))
+ {
+ hr = runningObjectTable->EnumRunning(&monikerEnumerator);
+ ReportHRESULT(hr, "EnumRunning");
+ }
+
+ if(SUCCEEDED(hr))
+ {
+ hr = monikerEnumerator->Reset();
+ ReportHRESULT(hr, "Reset");
+ }
+
+ if(SUCCEEDED(hr))
+ {
+ while (S_OK == monikerEnumerator->Next(1, &moniker, &numFetched))
+ {
+ std::string runningObjectName;
+ IUnknownPtr runningObjectVal;
+ IBindCtxPtr ctx;
+
+ hr = CreateBindCtx(0, &ctx);
+ ReportHRESULT(hr, "CreateBindCtx");
+
+ if(SUCCEEDED(hr))
+ {
+ LPOLESTR displayName = 0;
+ hr = moniker->GetDisplayName(ctx, 0, &displayName);
+ ReportHRESULT(hr, "GetDisplayName");
+ if (displayName)
+ {
+ runningObjectName = (std::string) (_bstr_t) displayName;
+ CoTaskMemFree(displayName);
+ }
+
+ hr = runningObjectTable->GetObject(moniker, &runningObjectVal);
+ ReportHRESULT(hr, "GetObject");
+ if(SUCCEEDED(hr))
+ {
+ mrot.insert(std::make_pair(runningObjectName, runningObjectVal));
+ }
+ }
+
+ numFetched = 0;
+ moniker = 0;
+ }
+ }
+
+ return hr;
+}
+
+
+//----------------------------------------------------------------------------
+///! Do the two file names refer to the same Visual Studio solution? Or are
+///! we perhaps looking for any and all solutions?
+bool FilesSameSolution(
+ const std::string& slnFile,
+ const std::string& slnName)
+{
+ if (slnFile == "ALL" || slnName == "ALL")
+ {
+ return true;
+ }
+
+ // Otherwise, make lowercase local copies, convert to Unix slashes, and
+ // see if the resulting strings are the same:
+ std::string s1 = cmSystemTools::LowerCase(slnFile);
+ std::string s2 = cmSystemTools::LowerCase(slnName);
+ cmSystemTools::ConvertToUnixSlashes(s1);
+ cmSystemTools::ConvertToUnixSlashes(s2);
+
+ return s1 == s2;
+}
+
+
+//----------------------------------------------------------------------------
+///! Find instances of Visual Studio with the given solution file
+///! open. Pass "ALL" for slnFile to gather all running instances
+///! of Visual Studio.
+HRESULT FindVisualStudioInstances(
+ const std::string& slnFile,
+ std::vector<IDispatchPtr>& instances)
+{
+ std::map<std::string, IUnknownPtr> mrot;
+
+ HRESULT hr = GetRunningInstances(mrot);
+ ReportHRESULT(hr, "GetRunningInstances");
+
+ if(SUCCEEDED(hr))
+ {
+ std::map<std::string, IUnknownPtr>::iterator it;
+ for(it = mrot.begin(); it != mrot.end(); ++it)
+ {
+ if (cmSystemTools::StringStartsWith(it->first.c_str(),
+ "!VisualStudio.DTE."))
+ {
+ IDispatchPtr disp(it->second);
+ if (disp != (IDispatch*) 0)
+ {
+ std::string slnName;
+ hr = GetIDESolutionFullName(disp, slnName);
+ ReportHRESULT(hr, "GetIDESolutionFullName");
+
+ if (FilesSameSolution(slnFile, slnName))
+ {
+ instances.push_back(disp);
+
+ //std::cout << "Found Visual Studio instance." << std::endl;
+ //std::cout << " ROT entry name: " << it->first << std::endl;
+ //std::cout << " ROT entry object: "
+ // << (IUnknown*) it->second << std::endl;
+ //std::cout << " slnFile: " << slnFile << std::endl;
+ //std::cout << " slnName: " << slnName << std::endl;
+ }
+ }
+ }
+ }
+ }
+
+ return hr;
+}
+
+
+#endif //defined(HAVE_COMDEF_H)
+
+
+//----------------------------------------------------------------------------
+int cmCallVisualStudioMacro::GetNumberOfRunningVisualStudioInstances(
+ const std::string& slnFile)
+{
+ int count = 0;
+
+ LogErrorsAsMessages = false;
+
+#if defined(HAVE_COMDEF_H)
+ HRESULT hr = CoInitialize(0);
+ ReportHRESULT(hr, "CoInitialize");
+
+ if(SUCCEEDED(hr))
+ {
+ std::vector<IDispatchPtr> instances;
+ hr = FindVisualStudioInstances(slnFile, instances);
+ ReportHRESULT(hr, "FindVisualStudioInstances");
+
+ if(SUCCEEDED(hr))
+ {
+ count = static_cast<int>(instances.size());
+ }
+
+ // Force release all COM pointers before CoUninitialize:
+ instances.clear();
+
+ CoUninitialize();
+ }
+#else
+ (void)slnFile;
+#endif
+
+ return count;
+}
+
+
+//----------------------------------------------------------------------------
+///! Get all running objects from the Windows running object table.
+///! Save them in a map by their display names.
+int cmCallVisualStudioMacro::CallMacro(
+ const std::string& slnFile,
+ const std::string& macro,
+ const std::string& args,
+ const bool logErrorsAsMessages)
+{
+ int err = 1; // no comdef.h
+
+ LogErrorsAsMessages = logErrorsAsMessages;
+
+#if defined(HAVE_COMDEF_H)
+ err = 2; // error initializing
+
+ HRESULT hr = CoInitialize(0);
+ ReportHRESULT(hr, "CoInitialize");
+
+ if(SUCCEEDED(hr))
+ {
+ std::vector<IDispatchPtr> instances;
+ hr = FindVisualStudioInstances(slnFile, instances);
+ ReportHRESULT(hr, "FindVisualStudioInstances");
+
+ if(SUCCEEDED(hr))
+ {
+ err = 0; // no error
+
+ std::vector<IDispatchPtr>::iterator it;
+ for(it = instances.begin(); it != instances.end(); ++it)
+ {
+ hr = InstanceCallMacro(*it, macro, args);
+ ReportHRESULT(hr, "InstanceCallMacro");
+
+ if (FAILED(hr))
+ {
+ err = 3; // error attempting to call the macro
+ }
+ }
+
+ if(0 == instances.size())
+ {
+ // no instances to call
+
+ //cmSystemTools::Message(
+ // "cmCallVisualStudioMacro::CallMacro no instances found to call",
+ // "Warning");
+ }
+ }
+
+ // Force release all COM pointers before CoUninitialize:
+ instances.clear();
+
+ CoUninitialize();
+ }
+#else
+ (void)slnFile;
+ (void)macro;
+ (void)args;
+ if (LogErrorsAsMessages)
+ {
+ cmSystemTools::Message("cmCallVisualStudioMacro::CallMacro is not "
+ "supported on this platform");
+ }
+#endif
+
+ if (err && LogErrorsAsMessages)
+ {
+ std::ostringstream oss;
+ oss << "cmCallVisualStudioMacro::CallMacro failed, err = " << err;
+ cmSystemTools::Message(oss.str().c_str());
+ }
+
+ return 0;
+}
diff --git a/Source/cmCallVisualStudioMacro.h b/Source/cmCallVisualStudioMacro.h
new file mode 100644
index 0000000000..09bddfa250
--- /dev/null
+++ b/Source/cmCallVisualStudioMacro.h
@@ -0,0 +1,45 @@
+/*============================================================================
+ 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 cmCallVisualStudioMacro_h
+#define cmCallVisualStudioMacro_h
+
+#include "cmStandardIncludes.h"
+
+/** \class cmCallVisualStudioMacro
+ * \brief Control class for communicating with CMake's Visual Studio macros
+ *
+ * Find running instances of Visual Studio by full path solution name.
+ * Call a Visual Studio IDE macro in any of those instances.
+ */
+class cmCallVisualStudioMacro
+{
+public:
+ ///! Call the named macro in instances of Visual Studio with the
+ ///! given solution file open. Pass "ALL" for slnFile to call the
+ ///! macro in each Visual Studio instance.
+ static int CallMacro(const std::string& slnFile,
+ const std::string& macro,
+ const std::string& args,
+ const bool logErrorsAsMessages);
+
+ ///! Count the number of running instances of Visual Studio with the
+ ///! given solution file open. Pass "ALL" for slnFile to count all
+ ///! running Visual Studio instances.
+ static int GetNumberOfRunningVisualStudioInstances(
+ const std::string& slnFile);
+
+protected:
+
+private:
+};
+
+#endif
diff --git a/Source/cmCommand.h b/Source/cmCommand.h
new file mode 100644
index 0000000000..a34ea71939
--- /dev/null
+++ b/Source/cmCommand.h
@@ -0,0 +1,204 @@
+/*============================================================================
+ 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 cmCommand_h
+#define cmCommand_h
+
+#include "cmObject.h"
+#include "cmListFileCache.h"
+#include "cmMakefile.h"
+#include "cmCommandArgumentsHelper.h"
+
+/** \class cmCommand
+ * \brief Superclass for all commands in CMake.
+ *
+ * cmCommand is the base class for all commands in CMake. A command
+ * manifests as an entry in CMakeLists.txt and produces one or
+ * more makefile rules. Commands are associated with a particular
+ * makefile. This base class cmCommand defines the API for commands
+ * to support such features as enable/disable, inheritance,
+ * documentation, and construction.
+ */
+class cmCommand : public cmObject
+{
+public:
+ cmTypeMacro(cmCommand, cmObject);
+
+ /**
+ * Construct the command. By default it is enabled with no makefile.
+ */
+ cmCommand()
+ {this->Makefile = 0; this->Enabled = true;}
+
+ /**
+ * Need virtual destructor to destroy real command type.
+ */
+ virtual ~cmCommand() {}
+
+ /**
+ * Specify the makefile.
+ */
+ void SetMakefile(cmMakefile*m)
+ {this->Makefile = m; }
+ cmMakefile* GetMakefile() { return this->Makefile; }
+
+ /**
+ * This is called by the cmMakefile when the command is first
+ * encountered in the CMakeLists.txt file. It expands the command's
+ * arguments and then invokes the InitialPass.
+ */
+ virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus &status)
+ {
+ std::vector<std::string> expandedArguments;
+ if(!this->Makefile->ExpandArguments(args, expandedArguments))
+ {
+ // There was an error expanding arguments. It was already
+ // reported, so we can skip this command without error.
+ return true;
+ }
+ return this->InitialPass(expandedArguments,status);
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &) = 0;
+
+ /**
+ * This is called at the end after all the information
+ * specified by the command is accumulated. Most commands do
+ * not implement this method. At this point, reading and
+ * writing to the cache can be done.
+ */
+ virtual void FinalPass() {}
+
+ /**
+ * Does this command have a final pass? Query after InitialPass.
+ */
+ virtual bool HasFinalPass() const { return false; }
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone() = 0;
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const
+ {
+ return false;
+ }
+
+ /**
+ * This determines if usage of the method is discouraged or not.
+ * This is currently only used for generating the documentation.
+ */
+ virtual bool IsDiscouraged() const
+ {
+ return false;
+ }
+
+ /**
+ * This is used to avoid including this command
+ * in documentation. This is mainly used by
+ * cmMacroHelperCommand and cmFunctionHelperCommand
+ * which cannot provide appropriate documentation.
+ */
+ virtual bool ShouldAppearInDocumentation() const
+ {
+ return true;
+ }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const = 0;
+
+ /**
+ * Enable the command.
+ */
+ void EnabledOn()
+ {this->Enabled = true;}
+
+ /**
+ * Disable the command.
+ */
+ void EnabledOff()
+ {this->Enabled = false;}
+
+ /**
+ * Query whether the command is enabled.
+ */
+ bool GetEnabled() const
+ {return this->Enabled;}
+
+ /**
+ * Disable or enable the command.
+ */
+ void SetEnabled(bool enabled)
+ {this->Enabled = enabled;}
+
+ /**
+ * Return the last error string.
+ */
+ const char* GetError()
+ {
+ if(this->Error.length() == 0)
+ {
+ this->Error = this->GetName();
+ this->Error += " unknown error.";
+ }
+ return this->Error.c_str();
+ }
+
+ /**
+ * Set the error message
+ */
+ void SetError(const std::string& e)
+ {
+ this->Error = this->GetName();
+ this->Error += " ";
+ this->Error += e;
+ }
+
+ /** Check if the command is disallowed by a policy. */
+ bool Disallowed(cmPolicies::PolicyID pol, const char* e)
+ {
+ switch(this->Makefile->GetPolicyStatus(pol))
+ {
+ case cmPolicies::WARN:
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ this->Makefile->GetPolicies()->GetPolicyWarning(pol));
+ case cmPolicies::OLD:
+ return false;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e);
+ break;
+ }
+ return true;
+ }
+
+protected:
+ cmMakefile* Makefile;
+ cmCommandArgumentsHelper Helper;
+
+private:
+ bool Enabled;
+ std::string Error;
+};
+
+#endif
diff --git a/Source/cmCommandArgumentLexer.cxx b/Source/cmCommandArgumentLexer.cxx
new file mode 100644
index 0000000000..e23ef8a8b9
--- /dev/null
+++ b/Source/cmCommandArgumentLexer.cxx
@@ -0,0 +1,2077 @@
+/*============================================================================
+ 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 "cmStandardIncludes.h"
+
+#line 2 "cmCommandArgumentLexer.cxx"
+
+#line 4 "cmCommandArgumentLexer.cxx"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yyg->yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yyg->yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE cmCommandArgument_yyrestart(yyin ,yyscanner )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#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)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = yyg->yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#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
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int 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
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via cmCommandArgument_yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
+ ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
+
+void cmCommandArgument_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void cmCommandArgument_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmCommandArgument_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
+void cmCommandArgument_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmCommandArgument_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmCommandArgument_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+void cmCommandArgument_yypop_buffer_state (yyscan_t yyscanner );
+
+static void cmCommandArgument_yyensure_buffer_stack (yyscan_t yyscanner );
+static void cmCommandArgument_yy_load_buffer_state (yyscan_t yyscanner );
+static void cmCommandArgument_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
+
+#define YY_FLUSH_BUFFER cmCommandArgument_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+
+YY_BUFFER_STATE cmCommandArgument_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmCommandArgument_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmCommandArgument_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+
+void *cmCommandArgument_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *cmCommandArgument_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void cmCommandArgument_yyfree (void * ,yyscan_t yyscanner );
+
+#define yy_new_buffer cmCommandArgument_yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ cmCommandArgument_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmCommandArgument_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ cmCommandArgument_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmCommandArgument_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+#define cmCommandArgument_yywrap(n) 1
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+typedef int yy_state_type;
+
+#define yytext_ptr yytext_r
+
+static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
+static int yy_get_next_buffer (yyscan_t yyscanner );
+static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yyg->yytext_ptr = yy_bp; \
+ yyleng = (size_t) (yy_cp - yy_bp); \
+ yyg->yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yyg->yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 14
+#define YY_END_OF_BUFFER 15
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[30] =
+ { 0,
+ 0, 0, 0, 0, 0, 0, 15, 9, 10, 7,
+ 6, 14, 11, 5, 12, 13, 9, 0, 0, 4,
+ 7, 0, 8, 2, 0, 3, 0, 1, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
+ 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, 3, 1, 1, 1, 1,
+ 1, 1, 4, 1, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
+ 1, 1, 1, 5, 4, 4, 4, 4, 6, 4,
+ 4, 4, 4, 4, 4, 4, 4, 7, 4, 4,
+ 4, 4, 4, 4, 4, 8, 4, 4, 4, 4,
+ 1, 9, 1, 1, 4, 1, 4, 4, 4, 4,
+
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 10, 1, 11, 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, 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, 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, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[12] =
+ { 0,
+ 1, 2, 3, 4, 3, 4, 4, 4, 3, 5,
+ 3
+ } ;
+
+static yyconst flex_int16_t yy_base[35] =
+ { 0,
+ 0, 0, 31, 30, 29, 28, 36, 0, 6, 16,
+ 0, 41, 41, 41, 0, 41, 0, 22, 22, 41,
+ 18, 18, 41, 41, 7, 41, 4, 41, 41, 20,
+ 21, 26, 9, 30
+ } ;
+
+static yyconst flex_int16_t yy_def[35] =
+ { 0,
+ 29, 1, 1, 1, 1, 1, 29, 30, 31, 32,
+ 33, 29, 29, 29, 34, 29, 30, 31, 18, 29,
+ 32, 33, 29, 29, 18, 29, 18, 29, 0, 29,
+ 29, 29, 29, 29
+ } ;
+
+static yyconst flex_int16_t yy_nxt[53] =
+ { 0,
+ 8, 8, 9, 10, 11, 10, 10, 10, 12, 13,
+ 14, 19, 22, 28, 27, 20, 17, 17, 17, 17,
+ 17, 17, 26, 17, 18, 18, 21, 21, 25, 21,
+ 23, 24, 23, 23, 23, 29, 16, 16, 15, 15,
+ 7, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+ 29, 29
+ } ;
+
+static yyconst flex_int16_t yy_chk[53] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 9, 33, 27, 25, 9, 10, 10, 21, 21,
+ 30, 30, 22, 30, 31, 31, 32, 32, 19, 32,
+ 34, 18, 34, 34, 34, 7, 6, 5, 4, 3,
+ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+ 29, 29
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "cmCommandArgumentLexer.in.l"
+#line 2 "cmCommandArgumentLexer.in.l"
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex --prefix=cmCommandArgument_yy --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
+
+Modify cmCommandArgumentLexer.cxx:
+ - add #include "cmStandardIncludes.h" to top of file
+ - put header block at top of file
+ - remove TABs
+ - remove "yyscanner" argument from these methods:
+ yy_fatal_error, cmCommandArgument_yyalloc, cmCommandArgument_yyrealloc, cmCommandArgument_yyfree
+ - remove all YY_BREAK lines occurring right after return statements
+ - change while ( 1 ) to for(;;)
+ - add "return 0;" to end of cmCommandArgument_yylex
+
+Modify cmCommandArgumentLexer.h:
+ - remove TABs
+ - remove the yy_init_globals function
+ - remove the block that includes unistd.h
+ - remove #line directives (avoids bogus warning on old Sun)
+
+*/
+
+#include "cmStandardLexer.h"
+
+#include "cmCommandArgumentParserHelper.h"
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = yyextra->LexInput(buf, max_size); }
+
+/* Include the set of tokens from the parser. */
+#include "cmCommandArgumentParserTokens.h"
+
+/*--------------------------------------------------------------------------*/
+
+
+#line 508 "cmCommandArgumentLexer.cxx"
+
+#define INITIAL 0
+#define ESCAPES 1
+#define NOESCAPES 2
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* Holds the entire state of the reentrant scanner. */
+struct yyguts_t
+ {
+
+ /* User-defined. Not touched by flex. */
+ YY_EXTRA_TYPE yyextra_r;
+
+ /* The rest are the same as the globals declared in the non-reentrant scanner. */
+ FILE *yyin_r, *yyout_r;
+ size_t yy_buffer_stack_top; /**< index of top of stack. */
+ 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;
+ char *yy_c_buf_p;
+ int yy_init;
+ int yy_start;
+ int yy_did_buffer_switch_on_eof;
+ int yy_start_stack_ptr;
+ int yy_start_stack_depth;
+ int *yy_start_stack;
+ yy_state_type yy_last_accepting_state;
+ char* yy_last_accepting_cpos;
+
+ int yylineno_r;
+ int yy_flex_debug_r;
+
+ char *yytext_r;
+ int yy_more_flag;
+ int yy_more_len;
+
+ }; /* end struct yyguts_t */
+
+static int yy_init_globals (yyscan_t yyscanner );
+
+int cmCommandArgument_yylex_init (yyscan_t* scanner);
+
+int cmCommandArgument_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int cmCommandArgument_yylex_destroy (yyscan_t yyscanner );
+
+int cmCommandArgument_yyget_debug (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE cmCommandArgument_yyget_extra (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *cmCommandArgument_yyget_in (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *cmCommandArgument_yyget_out (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+int cmCommandArgument_yyget_leng (yyscan_t yyscanner );
+
+char *cmCommandArgument_yyget_text (yyscan_t yyscanner );
+
+int cmCommandArgument_yyget_lineno (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int cmCommandArgument_yywrap (yyscan_t yyscanner );
+#else
+extern int cmCommandArgument_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#ifdef __cplusplus
+static int yyinput (yyscan_t yyscanner );
+#else
+static int input (yyscan_t yyscanner );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int cmCommandArgument_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int cmCommandArgument_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ yy_state_type yy_current_state;
+ char *yy_cp, *yy_bp;
+ int yy_act;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+#line 64 "cmCommandArgumentLexer.in.l"
+
+
+#line 732 "cmCommandArgumentLexer.cxx"
+
+ if ( !yyg->yy_init )
+ {
+ yyg->yy_init = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! yyg->yy_start )
+ yyg->yy_start = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ cmCommandArgument_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmCommandArgument_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmCommandArgument_yy_load_buffer_state(yyscanner );
+ }
+
+ for(;;) /* loops until end-of-file is reached */
+ {
+ yy_cp = yyg->yy_c_buf_p;
+
+ /* Support of yytext. */
+ *yy_cp = yyg->yy_hold_char;
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yyg->yy_start;
+yy_match:
+ do
+ {
+ 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;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 30 )
+ 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] != 41 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = yyg->yy_hold_char;
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 66 "cmCommandArgumentLexer.in.l"
+{
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
+ return cal_ENVCURLY;
+}
+case 2:
+YY_RULE_SETUP
+#line 72 "cmCommandArgumentLexer.in.l"
+{
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
+ return cal_NCURLY;
+}
+case 3:
+YY_RULE_SETUP
+#line 78 "cmCommandArgumentLexer.in.l"
+{
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
+ return cal_ATNAME;
+}
+case 4:
+YY_RULE_SETUP
+#line 84 "cmCommandArgumentLexer.in.l"
+{
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->DCURLYVariable;
+ return cal_DCURLY;
+}
+case 5:
+YY_RULE_SETUP
+#line 91 "cmCommandArgumentLexer.in.l"
+{
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->RCURLYVariable;
+ return cal_RCURLY;
+}
+case 6:
+YY_RULE_SETUP
+#line 98 "cmCommandArgumentLexer.in.l"
+{
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->ATVariable;
+ return cal_AT;
+}
+case 7:
+YY_RULE_SETUP
+#line 105 "cmCommandArgumentLexer.in.l"
+{
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ return cal_NAME;
+}
+case 8:
+YY_RULE_SETUP
+#line 111 "cmCommandArgumentLexer.in.l"
+{
+ if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
+ {
+ return cal_ERROR;
+ }
+ return cal_SYMBOL;
+}
+case 9:
+/* rule 9 can match eol */
+YY_RULE_SETUP
+#line 119 "cmCommandArgumentLexer.in.l"
+{
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ return cal_SYMBOL;
+}
+case 10:
+YY_RULE_SETUP
+#line 125 "cmCommandArgumentLexer.in.l"
+{
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->DOLLARVariable;
+ return cal_DOLLAR;
+}
+case 11:
+YY_RULE_SETUP
+#line 131 "cmCommandArgumentLexer.in.l"
+{
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->LCURLYVariable;
+ return cal_LCURLY;
+}
+case 12:
+YY_RULE_SETUP
+#line 137 "cmCommandArgumentLexer.in.l"
+{
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->BSLASHVariable;
+ return cal_BSLASH;
+}
+case 13:
+YY_RULE_SETUP
+#line 143 "cmCommandArgumentLexer.in.l"
+{
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->BSLASHVariable;
+ return cal_SYMBOL;
+}
+case 14:
+YY_RULE_SETUP
+#line 149 "cmCommandArgumentLexer.in.l"
+ECHO;
+ YY_BREAK
+#line 943 "cmCommandArgumentLexer.cxx"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(ESCAPES):
+case YY_STATE_EOF(NOESCAPES):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = yyg->yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * cmCommandArgument_yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
+
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++yyg->yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yyg->yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yyg->yy_did_buffer_switch_on_eof = 0;
+
+ if ( cmCommandArgument_yywrap(yyscanner ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p =
+ yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yyg->yy_c_buf_p =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+return 0; /* this should not happen but it quiets some compilers */
+} /* end of cmCommandArgument_yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ char *source = yyg->yytext_ptr;
+ int number_to_move, i;
+ int ret_val;
+
+ if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
+
+ else
+ {
+ int 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;
+
+ 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;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ cmCommandArgument_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* 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 );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ if ( yyg->yy_n_chars == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ cmCommandArgument_yyrestart(yyin ,yyscanner);
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cmCommandArgument_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ yyg->yy_n_chars += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
+{
+ yy_state_type yy_current_state;
+ char *yy_cp;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ yy_current_state = yyg->yy_start;
+
+ for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
+ {
+ YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 30 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
+{
+ int yy_is_jam;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
+ char *yy_cp = yyg->yy_c_buf_p;
+
+ YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 30 )
+ 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 == 29);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (yyscan_t yyscanner)
+#else
+ static int input (yyscan_t yyscanner)
+#endif
+
+{
+ int c;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+
+ if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ /* This was really a NUL. */
+ *yyg->yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ ++yyg->yy_c_buf_p;
+
+ switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ cmCommandArgument_yyrestart(yyin ,yyscanner);
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( cmCommandArgument_yywrap(yyscanner ) )
+ return EOF;
+
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput(yyscanner);
+#else
+ return input(yyscanner);
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
+ *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
+ yyg->yy_hold_char = *++yyg->yy_c_buf_p;
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ * @param yyscanner The scanner object.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void cmCommandArgument_yyrestart (FILE * input_file , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! YY_CURRENT_BUFFER ){
+ cmCommandArgument_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmCommandArgument_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmCommandArgument_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
+ cmCommandArgument_yy_load_buffer_state(yyscanner );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ * @param yyscanner The scanner object.
+ */
+ void cmCommandArgument_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * cmCommandArgument_yypop_buffer_state();
+ * cmCommandArgument_yypush_buffer_state(new_buffer);
+ */
+ cmCommandArgument_yyensure_buffer_stack (yyscanner);
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ cmCommandArgument_yy_load_buffer_state(yyscanner );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (cmCommandArgument_yywrap()) processing, but the only time this flag
+ * is looked at is after cmCommandArgument_yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+static void cmCommandArgument_yy_load_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ yyg->yy_hold_char = *yyg->yy_c_buf_p;
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * @param yyscanner The scanner object.
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE cmCommandArgument_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) cmCommandArgument_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) cmCommandArgument_yyalloc(b->yy_buf_size + 2 ,yyscanner );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ cmCommandArgument_yy_init_buffer(b,file ,yyscanner);
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with cmCommandArgument_yy_create_buffer()
+ * @param yyscanner The scanner object.
+ */
+ void cmCommandArgument_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ cmCommandArgument_yyfree((void *) b->yy_ch_buf ,yyscanner );
+
+ cmCommandArgument_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 cmCommandArgument_yyrestart() or at EOF.
+ */
+ static void cmCommandArgument_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+
+{
+ int oerrno = errno;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ cmCommandArgument_yy_flush_buffer(b ,yyscanner);
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then cmCommandArgument_yy_init_buffer was _probably_
+ * called from cmCommandArgument_yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ * @param yyscanner The scanner object.
+ */
+ void cmCommandArgument_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ cmCommandArgument_yy_load_buffer_state(yyscanner );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ * @param yyscanner The scanner object.
+ */
+void cmCommandArgument_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (new_buffer == NULL)
+ return;
+
+ cmCommandArgument_yyensure_buffer_stack(yyscanner);
+
+ /* This block is copied from cmCommandArgument_yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ yyg->yy_buffer_stack_top++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from cmCommandArgument_yy_switch_to_buffer. */
+ cmCommandArgument_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ * @param yyscanner The scanner object.
+ */
+void cmCommandArgument_yypop_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ cmCommandArgument_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if (yyg->yy_buffer_stack_top > 0)
+ --yyg->yy_buffer_stack_top;
+
+ if (YY_CURRENT_BUFFER) {
+ cmCommandArgument_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void cmCommandArgument_yyensure_buffer_stack (yyscan_t yyscanner)
+{
+ int num_to_alloc;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (!yyg->yy_buffer_stack) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmCommandArgument_yyalloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+ if ( ! yyg->yy_buffer_stack )
+ YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yyensure_buffer_stack()" );
+
+ memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ yyg->yy_buffer_stack_max = num_to_alloc;
+ yyg->yy_buffer_stack_top = 0;
+ return;
+ }
+
+ if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmCommandArgument_yyrealloc
+ (yyg->yy_buffer_stack,
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+ if ( ! yyg->yy_buffer_stack )
+ YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
+ yyg->yy_buffer_stack_max = num_to_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmCommandArgument_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) cmCommandArgument_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ cmCommandArgument_yy_switch_to_buffer(b ,yyscanner );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to cmCommandArgument_yylex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * cmCommandArgument_yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE cmCommandArgument_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+{
+
+ return cmCommandArgument_yy_scan_bytes(yystr,strlen(yystr) ,yyscanner);
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to cmCommandArgument_yylex() will
+ * scan from a @e copy of @a yybytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmCommandArgument_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) cmCommandArgument_yyalloc(n ,yyscanner );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yy_scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = cmCommandArgument_yy_scan_buffer(buf,n ,yyscanner);
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in cmCommandArgument_yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yy_fatal_error (yyconst char* msg , yyscan_t)
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = yyg->yy_hold_char; \
+ yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
+ yyg->yy_hold_char = *yyg->yy_c_buf_p; \
+ *yyg->yy_c_buf_p = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the user-defined data for this scanner.
+ * @param yyscanner The scanner object.
+ */
+YY_EXTRA_TYPE cmCommandArgument_yyget_extra (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyextra;
+}
+
+/** Get the current line number.
+ * @param yyscanner The scanner object.
+ */
+int cmCommandArgument_yyget_lineno (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yylineno;
+}
+
+/** Get the current column number.
+ * @param yyscanner The scanner object.
+ */
+int cmCommandArgument_yyget_column (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yycolumn;
+}
+
+/** Get the input stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmCommandArgument_yyget_in (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyin;
+}
+
+/** Get the output stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmCommandArgument_yyget_out (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyout;
+}
+
+/** Get the length of the current token.
+ * @param yyscanner The scanner object.
+ */
+int cmCommandArgument_yyget_leng (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyleng;
+}
+
+/** Get the current token.
+ * @param yyscanner The scanner object.
+ */
+
+char *cmCommandArgument_yyget_text (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yytext;
+}
+
+/** Set the user-defined data. This data is never touched by the scanner.
+ * @param user_defined The data to be associated with this scanner.
+ * @param yyscanner The scanner object.
+ */
+void cmCommandArgument_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyextra = user_defined ;
+}
+
+/** Set the current line number.
+ * @param line_number The line number to set.
+ * @param yyscanner The scanner object.
+ */
+void cmCommandArgument_yyset_lineno (int line_number , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* lineno is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmCommandArgument_yyset_lineno called with no buffer" , yyscanner);
+
+ yylineno = line_number;
+}
+
+/** Set the current column.
+ * @param column_no The column number to set.
+ * @param yyscanner The scanner object.
+ */
+void cmCommandArgument_yyset_column (int column_no , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* column is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmCommandArgument_yyset_column called with no buffer" , yyscanner);
+
+ yycolumn = column_no;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ * @param yyscanner The scanner object.
+ * @see cmCommandArgument_yy_switch_to_buffer
+ */
+void cmCommandArgument_yyset_in (FILE * in_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyin = in_str ;
+}
+
+void cmCommandArgument_yyset_out (FILE * out_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyout = out_str ;
+}
+
+int cmCommandArgument_yyget_debug (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yy_flex_debug;
+}
+
+void cmCommandArgument_yyset_debug (int bdebug , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yy_flex_debug = bdebug ;
+}
+
+/* Accessor methods for yylval and yylloc */
+
+/* User-visible API */
+
+/* cmCommandArgument_yylex_init is special because it creates the scanner itself, so it is
+ * the ONLY reentrant function that doesn't take the scanner as the last argument.
+ * That's why we explicitly handle the declaration, instead of using our macros.
+ */
+
+int cmCommandArgument_yylex_init(yyscan_t* ptr_yy_globals)
+
+{
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) cmCommandArgument_yyalloc ( sizeof( struct yyguts_t ), NULL );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
+ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+/* cmCommandArgument_yylex_init_extra has the same functionality as cmCommandArgument_yylex_init, but follows the
+ * convention of taking the scanner as the last argument. Note however, that
+ * this is a *pointer* to a scanner, as it will be allocated by this call (and
+ * is the reason, too, why this function also must handle its own declaration).
+ * The user defined value in the first argument will be available to cmCommandArgument_yyalloc in
+ * the yyextra field.
+ */
+
+int cmCommandArgument_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
+
+{
+ struct yyguts_t dummy_yyguts;
+
+ cmCommandArgument_yyset_extra (yy_user_defined, &dummy_yyguts);
+
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) cmCommandArgument_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ /* By setting to 0xAA, we expose bugs in
+ yy_init_globals. Leave at 0x00 for releases. */
+ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+ cmCommandArgument_yyset_extra (yy_user_defined, *ptr_yy_globals);
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+static int yy_init_globals (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from cmCommandArgument_yylex_destroy(), so don't allocate here.
+ */
+
+ yyg->yy_buffer_stack = 0;
+ yyg->yy_buffer_stack_top = 0;
+ yyg->yy_buffer_stack_max = 0;
+ yyg->yy_c_buf_p = (char *) 0;
+ yyg->yy_init = 0;
+ yyg->yy_start = 0;
+
+ yyg->yy_start_stack_ptr = 0;
+ yyg->yy_start_stack_depth = 0;
+ yyg->yy_start_stack = NULL;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ yyin = stdin;
+ yyout = stdout;
+#else
+ yyin = (FILE *) 0;
+ yyout = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * cmCommandArgument_yylex_init()
+ */
+ return 0;
+}
+
+/* cmCommandArgument_yylex_destroy is for both reentrant and non-reentrant scanners. */
+int cmCommandArgument_yylex_destroy (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ cmCommandArgument_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ cmCommandArgument_yypop_buffer_state(yyscanner);
+ }
+
+ /* Destroy the stack itself. */
+ cmCommandArgument_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyg->yy_buffer_stack = NULL;
+
+ /* Destroy the start condition stack. */
+ cmCommandArgument_yyfree(yyg->yy_start_stack ,yyscanner );
+ yyg->yy_start_stack = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * cmCommandArgument_yylex() is called, initialization will occur. */
+ yy_init_globals( yyscanner);
+
+ /* Destroy the main struct (reentrant only). */
+ cmCommandArgument_yyfree ( yyscanner , yyscanner );
+ yyscanner = NULL;
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+{
+ int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+{
+ int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *cmCommandArgument_yyalloc (yy_size_t size , yyscan_t)
+{
+ return (void *) malloc( size );
+}
+
+void *cmCommandArgument_yyrealloc (void * ptr, yy_size_t size , yyscan_t)
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void cmCommandArgument_yyfree (void * ptr , yyscan_t)
+{
+ free( (char *) ptr ); /* see cmCommandArgument_yyrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 149 "cmCommandArgumentLexer.in.l"
+
+
+
+/*--------------------------------------------------------------------------*/
+void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
+{
+ /* Hack into the internal flex-generated scanner to set the state. */
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if(noEscapes)
+ {
+ BEGIN(NOESCAPES);
+ }
+ else
+ {
+ BEGIN(ESCAPES);
+ }
+}
+
diff --git a/Source/cmCommandArgumentLexer.h b/Source/cmCommandArgumentLexer.h
new file mode 100644
index 0000000000..2ea3fa29fb
--- /dev/null
+++ b/Source/cmCommandArgumentLexer.h
@@ -0,0 +1,333 @@
+/*============================================================================
+ 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 cmCommandArgument_yyHEADER_H
+#define cmCommandArgument_yyHEADER_H 1
+#define cmCommandArgument_yyIN_HEADER 1
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+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
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int 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
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+void cmCommandArgument_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void cmCommandArgument_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmCommandArgument_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
+void cmCommandArgument_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmCommandArgument_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmCommandArgument_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+void cmCommandArgument_yypop_buffer_state (yyscan_t yyscanner );
+
+YY_BUFFER_STATE cmCommandArgument_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmCommandArgument_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmCommandArgument_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+
+void *cmCommandArgument_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *cmCommandArgument_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void cmCommandArgument_yyfree (void * ,yyscan_t yyscanner );
+
+/* Begin user sect3 */
+
+#define cmCommandArgument_yywrap(n) 1
+#define YY_SKIP_YYWRAP
+
+#define yytext_ptr yytext_r
+
+#ifdef YY_HEADER_EXPORT_START_CONDITIONS
+#define INITIAL 0
+#define ESCAPES 1
+#define NOESCAPES 2
+
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+int cmCommandArgument_yylex_init (yyscan_t* scanner);
+
+int cmCommandArgument_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int cmCommandArgument_yylex_destroy (yyscan_t yyscanner );
+
+int cmCommandArgument_yyget_debug (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE cmCommandArgument_yyget_extra (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *cmCommandArgument_yyget_in (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *cmCommandArgument_yyget_out (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+int cmCommandArgument_yyget_leng (yyscan_t yyscanner );
+
+char *cmCommandArgument_yyget_text (yyscan_t yyscanner );
+
+int cmCommandArgument_yyget_lineno (yyscan_t yyscanner );
+
+void cmCommandArgument_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int cmCommandArgument_yywrap (yyscan_t yyscanner );
+#else
+extern int cmCommandArgument_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int cmCommandArgument_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int cmCommandArgument_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+#undef YY_NEW_FILE
+#undef YY_FLUSH_BUFFER
+#undef yy_set_bol
+#undef yy_new_buffer
+#undef yy_set_interactive
+#undef YY_DO_BEFORE_ACTION
+
+#ifdef YY_DECL_IS_OURS
+#undef YY_DECL_IS_OURS
+#undef YY_DECL
+#endif
+
+#undef cmCommandArgument_yyIN_HEADER
+#endif /* cmCommandArgument_yyHEADER_H */
diff --git a/Source/cmCommandArgumentLexer.in.l b/Source/cmCommandArgumentLexer.in.l
new file mode 100644
index 0000000000..24a0eec85f
--- /dev/null
+++ b/Source/cmCommandArgumentLexer.in.l
@@ -0,0 +1,162 @@
+%{
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex --prefix=cmCommandArgument_yy --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
+
+Modify cmCommandArgumentLexer.cxx:
+ - add #include "cmStandardIncludes.h" to top of file
+ - put header block at top of file
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - remove "yyscanner" argument from these methods:
+ yy_fatal_error, cmCommandArgument_yyalloc, cmCommandArgument_yyrealloc, cmCommandArgument_yyfree
+ - remove all YY_BREAK lines occurring right after return statements
+ - change while ( 1 ) to for(;;)
+ - add "return 0;" to end of cmCommandArgument_yylex
+
+Modify cmCommandArgumentLexer.h:
+ - remove TABs
+ - remove the yy_init_globals function
+ - remove the block that includes unistd.h
+ - remove #line directives (avoids bogus warning on old Sun)
+
+*/
+
+#include "cmStandardLexer.h"
+
+#include "cmCommandArgumentParserHelper.h"
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = yyextra->LexInput(buf, max_size); }
+
+/* Include the set of tokens from the parser. */
+#include "cmCommandArgumentParserTokens.h"
+
+/*--------------------------------------------------------------------------*/
+%}
+
+%option reentrant
+%option noyywrap
+%option nounput
+%pointer
+%s ESCAPES
+%s NOESCAPES
+
+%%
+
+\$ENV\{ {
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
+ return cal_ENVCURLY;
+}
+
+\$[A-Za-z0-9/_.+-]+\{ {
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
+ return cal_NCURLY;
+}
+
+@[A-Za-z0-9/_.+-]+@ {
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
+ return cal_ATNAME;
+}
+
+"${" {
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->DCURLYVariable;
+ return cal_DCURLY;
+}
+
+"}" {
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->RCURLYVariable;
+ return cal_RCURLY;
+}
+
+"@" {
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->ATVariable;
+ return cal_AT;
+}
+
+[A-Za-z0-9/_.+-]+ {
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ return cal_NAME;
+}
+
+<ESCAPES>\\. {
+ if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
+ {
+ return cal_ERROR;
+ }
+ return cal_SYMBOL;
+}
+
+[^\${}\\@]+ {
+ //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
+ yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ return cal_SYMBOL;
+}
+
+"$" {
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->DOLLARVariable;
+ return cal_DOLLAR;
+}
+
+"{" {
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->LCURLYVariable;
+ return cal_LCURLY;
+}
+
+<ESCAPES>"\\" {
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->BSLASHVariable;
+ return cal_BSLASH;
+}
+
+<NOESCAPES>"\\" {
+ //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ yylvalp->str = yyextra->BSLASHVariable;
+ return cal_SYMBOL;
+}
+
+%%
+
+/*--------------------------------------------------------------------------*/
+void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
+{
+ /* Hack into the internal flex-generated scanner to set the state. */
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if(noEscapes)
+ {
+ BEGIN(NOESCAPES);
+ }
+ else
+ {
+ BEGIN(ESCAPES);
+ }
+}
diff --git a/Source/cmCommandArgumentParser.cxx b/Source/cmCommandArgumentParser.cxx
new file mode 100644
index 0000000000..c5146c5d73
--- /dev/null
+++ b/Source/cmCommandArgumentParser.cxx
@@ -0,0 +1,1835 @@
+/*============================================================================
+ 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.
+============================================================================*/
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton implementation for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "2.3"
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 1
+
+/* Using locations. */
+#define YYLSP_NEEDED 0
+
+/* Substitute the variable and function names. */
+#define yyparse cmCommandArgument_yyparse
+#define yylex cmCommandArgument_yylex
+#define yyerror cmCommandArgument_yyerror
+#define yylval cmCommandArgument_yylval
+#define yychar cmCommandArgument_yychar
+#define yydebug cmCommandArgument_yydebug
+#define yynerrs cmCommandArgument_yynerrs
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ cal_ENVCURLY = 258,
+ cal_NCURLY = 259,
+ cal_DCURLY = 260,
+ cal_DOLLAR = 261,
+ cal_LCURLY = 262,
+ cal_RCURLY = 263,
+ cal_NAME = 264,
+ cal_BSLASH = 265,
+ cal_SYMBOL = 266,
+ cal_AT = 267,
+ cal_ERROR = 268,
+ cal_ATNAME = 269
+ };
+#endif
+/* Tokens. */
+#define cal_ENVCURLY 258
+#define cal_NCURLY 259
+#define cal_DCURLY 260
+#define cal_DOLLAR 261
+#define cal_LCURLY 262
+#define cal_RCURLY 263
+#define cal_NAME 264
+#define cal_BSLASH 265
+#define cal_SYMBOL 266
+#define cal_AT 267
+#define cal_ERROR 268
+#define cal_ATNAME 269
+
+
+
+
+/* Copy the first part of user declarations. */
+#line 1 "cmCommandArgumentParser.y"
+
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run bison like this:
+
+ bison --yacc --name-prefix=cmCommandArgument_yy --defines=cmCommandArgumentParserTokens.h -ocmCommandArgumentParser.cxx cmCommandArgumentParser.y
+
+Modify cmCommandArgumentParser.cxx:
+ - remove TABs
+ - put header block at top of file
+
+*/
+
+#include "cmStandardIncludes.h"
+
+/* Configure the parser to use a lexer object. */
+#define YYPARSE_PARAM yyscanner
+#define YYLEX_PARAM yyscanner
+#define YYERROR_VERBOSE 1
+#define cmCommandArgument_yyerror(x) \
+ cmCommandArgumentError(yyscanner, x)
+#define yyGetParser (cmCommandArgument_yyget_extra(yyscanner))
+
+/* Make sure malloc and free are available on QNX. */
+#ifdef __QNX__
+# include <malloc.h>
+#endif
+
+/* Make sure the parser uses standard memory allocation. The default
+ generated parser malloc/free declarations do not work on all
+ platforms. */
+#include <stdlib.h>
+#define YYMALLOC malloc
+#define YYFREE free
+
+/*-------------------------------------------------------------------------*/
+#include "cmCommandArgumentParserHelper.h" /* Interface to parser object. */
+#include "cmCommandArgumentLexer.h" /* Interface to lexer object. */
+#include "cmCommandArgumentParserTokens.h" /* Need YYSTYPE for YY_DECL. */
+
+/* Forward declare the lexer entry point. */
+YY_DECL;
+
+/* Internal utility functions. */
+static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);
+
+#define YYDEBUG 1
+/* Configure the parser to support large input. */
+#define YYMAXDEPTH 100000
+#define YYINITDEPTH 10000
+
+/* Disable some warnings in the generated code. */
+#ifdef __BORLANDC__
+# pragma warn -8004 /* Variable assigned a value that is not used. */
+# pragma warn -8008 /* condition always returns true */
+# pragma warn -8060 /* possibly incorrect assignment */
+# pragma warn -8066 /* unreachable code */
+#endif
+#ifdef _MSC_VER
+# pragma warning (disable: 4102) /* Unused goto label. */
+# pragma warning (disable: 4065) /* Switch statement contains default but no
+ case. */
+# pragma warning (disable: 4244) /* loss of precision */
+# pragma warning (disable: 4702) /* unreachable code */
+#endif
+
+
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+/* Enabling the token table. */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE 0
+#endif
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef int YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+/* Copy the second part of user declarations. */
+
+
+/* Line 216 of yacc.c. */
+#line 227 "cmCommandArgumentParser.cxx"
+
+#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#elif (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+typedef signed char yytype_int8;
+#else
+typedef short int yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(msgid) msgid
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(e) ((void) (e))
+#else
+# define YYUSE(e) /* empty */
+#endif
+
+/* Identity function, used to suppress warnings about constant conditions. */
+#ifndef lint
+# define YYID(n) (n)
+#else
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static int
+YYID (int i)
+#else
+static int
+YYID (i)
+ int i;
+#endif
+{
+ return i;
+}
+#endif
+
+#if ! defined yyoverflow || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# elif defined __BUILTIN_VA_ARG_INCR
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined _AIX
+# define YYSTACK_ALLOC __alloca
+# elif defined _MSC_VER
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
+# else
+# define YYSTACK_ALLOC alloca
+# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's `empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined _STDLIB_H \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif
+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
+
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yytype_int16 yyss;
+ YYSTYPE yyvs;
+ };
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(To, From, Count) \
+ __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# else
+# define YYCOPY(To, From, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (To)[yyi] = (From)[yyi]; \
+ } \
+ while (YYID (0))
+# endif
+# endif
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack, Stack, yysize); \
+ Stack = &yyptr->Stack; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (YYID (0))
+
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 25
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 40
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 15
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 10
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 24
+/* YYNRULES -- Number of states. */
+#define YYNSTATES 33
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 269
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const yytype_uint8 yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+ YYRHS. */
+static const yytype_uint8 yyprhs[] =
+{
+ 0, 0, 3, 5, 7, 10, 11, 14, 16, 18,
+ 20, 22, 24, 26, 28, 30, 34, 38, 42, 44,
+ 46, 49, 50, 53, 55
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yytype_int8 yyrhs[] =
+{
+ 16, 0, -1, 17, -1, 18, -1, 18, 10, -1,
+ -1, 19, 18, -1, 20, -1, 21, -1, 9, -1,
+ 12, -1, 6, -1, 7, -1, 8, -1, 11, -1,
+ 3, 22, 8, -1, 4, 23, 8, -1, 5, 23,
+ 8, -1, 14, -1, 23, -1, 11, 22, -1, -1,
+ 24, 23, -1, 9, -1, 21, -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const yytype_uint8 yyrline[] =
+{
+ 0, 116, 116, 123, 128, 134, 138, 144, 149, 155,
+ 160, 165, 170, 175, 180, 186, 192, 198, 204, 210,
+ 215, 221, 225, 231, 236
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "$end", "error", "$undefined", "cal_ENVCURLY", "cal_NCURLY",
+ "cal_DCURLY", "\"$\"", "\"{\"", "\"}\"", "cal_NAME", "\"\\\\\"",
+ "cal_SYMBOL", "\"@\"", "cal_ERROR", "cal_ATNAME", "$accept", "Start",
+ "GoalWithOptionalBackSlash", "Goal", "String", "OuterText", "Variable",
+ "EnvVarName", "MultipleIds", "ID", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+ token YYLEX-NUM. */
+static const yytype_uint16 yytoknum[] =
+{
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const yytype_uint8 yyr1[] =
+{
+ 0, 15, 16, 17, 17, 18, 18, 19, 19, 20,
+ 20, 20, 20, 20, 20, 21, 21, 21, 21, 22,
+ 22, 23, 23, 24, 24
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
+static const yytype_uint8 yyr2[] =
+{
+ 0, 2, 1, 1, 2, 0, 2, 1, 1, 1,
+ 1, 1, 1, 1, 1, 3, 3, 3, 1, 1,
+ 2, 0, 2, 1, 1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+ STATE-NUM when YYTABLE doesn't specify something else to do. Zero
+ means the default is an error. */
+static const yytype_uint8 yydefact[] =
+{
+ 5, 21, 21, 21, 11, 12, 13, 9, 14, 10,
+ 18, 0, 2, 3, 5, 7, 8, 23, 21, 24,
+ 0, 19, 21, 0, 0, 1, 4, 6, 20, 15,
+ 22, 16, 17
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yytype_int8 yydefgoto[] =
+{
+ -1, 11, 12, 13, 14, 15, 19, 20, 21, 22
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+#define YYPACT_NINF -3
+static const yytype_int8 yypact[] =
+{
+ 0, 14, 26, 26, -3, -3, -3, -3, -3, -3,
+ -3, 10, -3, 3, 0, -3, -3, -3, 14, -3,
+ 7, -3, 26, 13, 16, -3, -3, -3, -3, -3,
+ -3, -3, -3
+};
+
+/* YYPGOTO[NTERM-NUM]. */
+static const yytype_int8 yypgoto[] =
+{
+ -3, -3, -3, 8, -3, -3, 2, 9, -2, -3
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule which
+ number is the opposite. If zero, do what YYDEFACT says.
+ If YYTABLE_NINF, syntax error. */
+#define YYTABLE_NINF -1
+static const yytype_uint8 yytable[] =
+{
+ 23, 24, 16, 1, 2, 3, 4, 5, 6, 7,
+ 25, 8, 9, 26, 10, 29, 16, 1, 2, 3,
+ 30, 31, 27, 17, 32, 18, 0, 28, 10, 1,
+ 2, 3, 0, 0, 0, 17, 0, 0, 0, 0,
+ 10
+};
+
+static const yytype_int8 yycheck[] =
+{
+ 2, 3, 0, 3, 4, 5, 6, 7, 8, 9,
+ 0, 11, 12, 10, 14, 8, 14, 3, 4, 5,
+ 22, 8, 14, 9, 8, 11, -1, 18, 14, 3,
+ 4, 5, -1, -1, -1, 9, -1, -1, -1, -1,
+ 14
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const yytype_uint8 yystos[] =
+{
+ 0, 3, 4, 5, 6, 7, 8, 9, 11, 12,
+ 14, 16, 17, 18, 19, 20, 21, 9, 11, 21,
+ 22, 23, 24, 23, 23, 0, 10, 18, 22, 8,
+ 23, 8, 8
+};
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+/* Like YYERROR except do call yyerror. This remains here temporarily
+ to ease the transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. */
+
+#define YYFAIL goto yyerrlab
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ yytoken = YYTRANSLATE (yychar); \
+ YYPOPSTACK (1); \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+while (YYID (0))
+
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (YYID (N)) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
+ while (YYID (0))
+#endif
+
+
+/* YY_LOCATION_PRINT -- Print the location on the stream.
+ This macro was not mandated originally: define only if we know
+ we won't break user code: when these are the locations we know. */
+
+#ifndef YY_LOCATION_PRINT
+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+# define YY_LOCATION_PRINT(File, Loc) \
+ fprintf (File, "%d.%d-%d.%d", \
+ (Loc).first_line, (Loc).first_column, \
+ (Loc).last_line, (Loc).last_column)
+# else
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+# endif
+#endif
+
+
+/* YYLEX -- calling `yylex' with the right arguments. */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval)
+#endif
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (YYID (0))
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Type, Value); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (YYID (0))
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+#else
+static void
+yy_symbol_value_print (yyoutput, yytype, yyvaluep)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+#endif
+{
+ if (!yyvaluep)
+ return;
+# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+ YYUSE (yyoutput);
+# endif
+ switch (yytype)
+ {
+ default:
+ break;
+ }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+#else
+static void
+yy_symbol_print (yyoutput, yytype, yyvaluep)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+#endif
+{
+ if (yytype < YYNTOKENS)
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+ yy_symbol_value_print (yyoutput, yytype, yyvaluep);
+ YYFPRINTF (yyoutput, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
+#else
+static void
+yy_stack_print (bottom, top)
+ yytype_int16 *bottom;
+ yytype_int16 *top;
+#endif
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; bottom <= top; ++bottom)
+ YYFPRINTF (stderr, " %d", *bottom);
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (YYID (0))
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
+#else
+static void
+yy_reduce_print (yyvsp, yyrule)
+ YYSTYPE *yyvsp;
+ int yyrule;
+#endif
+{
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ unsigned long int yylno = yyrline[yyrule];
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ fprintf (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
+ &(yyvsp[(yyi + 1) - (yynrhs)])
+ );
+ fprintf (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyvsp, Rule); \
+} while (YYID (0))
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined __GLIBC__ && defined _STRING_H
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static YYSIZE_T
+yystrlen (const char *yystr)
+#else
+static YYSIZE_T
+yystrlen (yystr)
+ const char *yystr;
+#endif
+{
+ YYSIZE_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+#else
+static char *
+yystpcpy (yydest, yysrc)
+ char *yydest;
+ const char *yysrc;
+#endif
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
+static YYSIZE_T
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ YYSIZE_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (! yyres)
+ return yystrlen (yystr);
+
+ return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+/* Copy into YYRESULT an error message about the unexpected token
+ YYCHAR while in state YYSTATE. Return the number of bytes copied,
+ including the terminating null byte. If YYRESULT is null, do not
+ copy anything; just return the number of bytes that would be
+ copied. As a special case, return 0 if an ordinary "syntax error"
+ message will do. Return YYSIZE_MAXIMUM if overflow occurs during
+ size calculation. */
+static YYSIZE_T
+yysyntax_error (char *yyresult, int yystate, int yychar)
+{
+ int yyn = yypact[yystate];
+
+ if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
+ return 0;
+ else
+ {
+ int yytype = YYTRANSLATE (yychar);
+ YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
+ YYSIZE_T yysize = yysize0;
+ YYSIZE_T yysize1;
+ int yysize_overflow = 0;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ int yyx;
+
+# if 0
+ /* This is so xgettext sees the translatable formats that are
+ constructed on the fly. */
+ YY_("syntax error, unexpected %s");
+ YY_("syntax error, unexpected %s, expecting %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
+# endif
+ char *yyfmt;
+ char const *yyf;
+ static char const yyunexpected[] = "syntax error, unexpected %s";
+ static char const yyexpecting[] = ", expecting %s";
+ static char const yyor[] = " or %s";
+ char yyformat[sizeof yyunexpected
+ + sizeof yyexpecting - 1
+ + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
+ * (sizeof yyor - 1))];
+ char const *yyprefix = yyexpecting;
+
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yycount = 1;
+
+ yyarg[0] = yytname[yytype];
+ yyfmt = yystpcpy (yyformat, yyunexpected);
+
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ yyformat[sizeof yyunexpected - 1] = '\0';
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+ yyfmt = yystpcpy (yyfmt, yyprefix);
+ yyprefix = yyor;
+ }
+
+ yyf = YY_(yyformat);
+ yysize1 = yysize + yystrlen (yyf);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+
+ if (yysize_overflow)
+ return YYSIZE_MAXIMUM;
+
+ if (yyresult)
+ {
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ char *yyp = yyresult;
+ int yyi = 0;
+ while ((*yyp = *yyf) != '\0')
+ {
+ if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyf += 2;
+ }
+ else
+ {
+ yyp++;
+ yyf++;
+ }
+ }
+ }
+ return yysize;
+ }
+}
+#endif /* YYERROR_VERBOSE */
+
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yydestruct (yymsg, yytype, yyvaluep)
+ const char *yymsg;
+ int yytype;
+ YYSTYPE *yyvaluep;
+#endif
+{
+ YYUSE (yyvaluep);
+
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ switch (yytype)
+ {
+
+ default:
+ break;
+ }
+}
+
+
+/* Prevent warnings from -Wmissing-prototypes. */
+
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void *YYPARSE_PARAM)
+#else
+int
+yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+#endif
+#else /* ! YYPARSE_PARAM */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void)
+#else
+int
+yyparse ()
+
+#endif
+#endif
+{
+ /* The look-ahead symbol. */
+int yychar;
+
+/* The semantic value of the look-ahead symbol. */
+YYSTYPE yylval;
+
+/* Number of syntax errors so far. */
+int yynerrs;
+
+ int yystate;
+ int yyn;
+ int yyresult;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+ /* Look-ahead token as an internal (translated) token number. */
+ int yytoken = 0;
+#if YYERROR_VERBOSE
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+ /* Three stacks and their tools:
+ `yyss': related to states,
+ `yyvs': related to semantic values,
+ `yyls': related to locations.
+
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss = yyssa;
+ yytype_int16 *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs = yyvsa;
+ YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
+
+ YYSIZE_T yystacksize = YYINITDEPTH;
+
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss;
+ yyvsp = yyvs;
+
+ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ yytype_int16 *yyss1 = yyss;
+
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),
+
+ &yystacksize);
+
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyexhaustedlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yytype_int16 *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE (yyss);
+ YYSTACK_RELOCATE (yyvs);
+
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+ /* Do appropriate processing given the current state. Read a
+ look-ahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to look-ahead token. */
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
+
+ /* Not known => get a look-ahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the look-ahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the shifted token unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ yystate = yyn;
+ *++yyvsp = yylval;
+
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 2:
+#line 117 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = 0;
+ yyGetParser->SetResult((yyvsp[(1) - (1)].str));
+}
+ break;
+
+ case 3:
+#line 124 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 4:
+#line 129 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = yyGetParser->CombineUnions((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str));
+}
+ break;
+
+ case 5:
+#line 134 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = 0;
+}
+ break;
+
+ case 6:
+#line 139 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = yyGetParser->CombineUnions((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str));
+}
+ break;
+
+ case 7:
+#line 145 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 8:
+#line 150 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 9:
+#line 156 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 10:
+#line 161 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 11:
+#line 166 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 12:
+#line 171 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 13:
+#line 176 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 14:
+#line 181 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 15:
+#line 187 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = yyGetParser->ExpandSpecialVariable((yyvsp[(1) - (3)].str),(yyvsp[(2) - (3)].str));
+ //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
+}
+ break;
+
+ case 16:
+#line 193 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = yyGetParser->ExpandSpecialVariable((yyvsp[(1) - (3)].str),(yyvsp[(2) - (3)].str));
+ //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
+}
+ break;
+
+ case 17:
+#line 199 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = yyGetParser->ExpandVariable((yyvsp[(2) - (3)].str));
+ //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
+}
+ break;
+
+ case 18:
+#line 205 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = yyGetParser->ExpandVariableForAt((yyvsp[(1) - (1)].str));
+}
+ break;
+
+ case 19:
+#line 211 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 20:
+#line 216 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (2)].str);
+}
+ break;
+
+ case 21:
+#line 221 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = 0;
+}
+ break;
+
+ case 22:
+#line 226 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = yyGetParser->CombineUnions((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str));
+}
+ break;
+
+ case 23:
+#line 232 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+ case 24:
+#line 237 "cmCommandArgumentParser.y"
+ {
+ (yyval.str) = (yyvsp[(1) - (1)].str);
+}
+ break;
+
+
+/* Line 1267 of yacc.c. */
+#line 1606 "cmCommandArgumentParser.cxx"
+ default: break;
+ }
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+
+
+ /* Now `shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if ! YYERROR_VERBOSE
+ yyerror (YY_("syntax error"));
+#else
+ {
+ YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
+ if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
+ {
+ YYSIZE_T yyalloc = 2 * yysize;
+ if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
+ yyalloc = YYSTACK_ALLOC_MAXIMUM;
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+ yymsg = (char *) YYSTACK_ALLOC (yyalloc);
+ if (yymsg)
+ yymsg_alloc = yyalloc;
+ else
+ {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ }
+ }
+
+ if (0 < yysize && yysize <= yymsg_alloc)
+ {
+ (void) yysyntax_error (yymsg, yystate, yychar);
+ yyerror (yymsg);
+ }
+ else
+ {
+ yyerror (YY_("syntax error"));
+ if (yysize != 0)
+ goto yyexhaustedlab;
+ }
+ }
+#endif
+ }
+
+
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse look-ahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval);
+ yychar = YYEMPTY;
+ }
+ }
+
+ /* Else will try to reuse look-ahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (/*CONSTCOND*/ 0)
+ goto yyerrorlab;
+
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (yyn != YYPACT_NINF)
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ *++yyvsp = yylval;
+
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#ifndef yyoverflow
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here. |
+`-------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+ if (yychar != YYEOF && yychar != YYEMPTY)
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval);
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ yystos[*yyssp], yyvsp);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+#if YYERROR_VERBOSE
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+#endif
+ /* Make sure YYID is used. */
+ return YYID (yyresult);
+}
+
+
+#line 242 "cmCommandArgumentParser.y"
+
+/* End of grammar */
+
+/*--------------------------------------------------------------------------*/
+void cmCommandArgumentError(yyscan_t yyscanner, const char* message)
+{
+ yyGetParser->Error(message);
+}
+
+
diff --git a/Source/cmCommandArgumentParser.y b/Source/cmCommandArgumentParser.y
new file mode 100644
index 0000000000..48f5c8ecdb
--- /dev/null
+++ b/Source/cmCommandArgumentParser.y
@@ -0,0 +1,246 @@
+%{
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run bison like this:
+
+ bison --yacc --name-prefix=cmCommandArgument_yy --defines=cmCommandArgumentParserTokens.h -ocmCommandArgumentParser.cxx cmCommandArgumentParser.y
+
+Modify cmCommandArgumentParser.cxx:
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - put header block at top of file
+
+*/
+
+#include "cmStandardIncludes.h"
+
+/* Configure the parser to use a lexer object. */
+#define YYPARSE_PARAM yyscanner
+#define YYLEX_PARAM yyscanner
+#define YYERROR_VERBOSE 1
+#define cmCommandArgument_yyerror(x) \
+ cmCommandArgumentError(yyscanner, x)
+#define yyGetParser (cmCommandArgument_yyget_extra(yyscanner))
+
+/* Make sure malloc and free are available on QNX. */
+#ifdef __QNX__
+# include <malloc.h>
+#endif
+
+/* Make sure the parser uses standard memory allocation. The default
+ generated parser malloc/free declarations do not work on all
+ platforms. */
+#include <stdlib.h>
+#define YYMALLOC malloc
+#define YYFREE free
+
+/*-------------------------------------------------------------------------*/
+#include "cmCommandArgumentParserHelper.h" /* Interface to parser object. */
+#include "cmCommandArgumentLexer.h" /* Interface to lexer object. */
+#include "cmCommandArgumentParserTokens.h" /* Need YYSTYPE for YY_DECL. */
+
+/* Forward declare the lexer entry point. */
+YY_DECL;
+
+/* Internal utility functions. */
+static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);
+
+#define YYDEBUG 1
+/* Configure the parser to support large input. */
+#define YYMAXDEPTH 100000
+#define YYINITDEPTH 10000
+
+/* Disable some warnings in the generated code. */
+#ifdef __BORLANDC__
+# pragma warn -8004 /* Variable assigned a value that is not used. */
+# pragma warn -8008 /* condition always returns true */
+# pragma warn -8060 /* possibly incorrect assignment */
+# pragma warn -8066 /* unreachable code */
+#endif
+#ifdef _MSC_VER
+# pragma warning (disable: 4102) /* Unused goto label. */
+# pragma warning (disable: 4065) /* Switch statement contains default but no
+ case. */
+# pragma warning (disable: 4244) /* loss of precision */
+# pragma warning (disable: 4702) /* unreachable code */
+#endif
+%}
+
+/* Generate a reentrant parser object. */
+%pure_parser
+
+/*
+%union {
+ char* string;
+}
+*/
+
+/*-------------------------------------------------------------------------*/
+/* Tokens */
+%token cal_ENVCURLY
+%token cal_NCURLY
+%token cal_DCURLY
+%token cal_DOLLAR "$"
+%token cal_LCURLY "{"
+%token cal_RCURLY "}"
+%token cal_NAME
+%token cal_BSLASH "\\"
+%token cal_SYMBOL
+%token cal_AT "@"
+%token cal_ERROR
+%token cal_ATNAME
+
+/*-------------------------------------------------------------------------*/
+/* grammar */
+%%
+
+
+Start:
+GoalWithOptionalBackSlash
+{
+ $<str>$ = 0;
+ yyGetParser->SetResult($<str>1);
+}
+
+GoalWithOptionalBackSlash:
+Goal
+{
+ $<str>$ = $<str>1;
+}
+|
+Goal cal_BSLASH
+{
+ $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
+}
+
+Goal:
+{
+ $<str>$ = 0;
+}
+|
+String Goal
+{
+ $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
+}
+
+String:
+OuterText
+{
+ $<str>$ = $<str>1;
+}
+|
+Variable
+{
+ $<str>$ = $<str>1;
+}
+
+OuterText:
+cal_NAME
+{
+ $<str>$ = $<str>1;
+}
+|
+cal_AT
+{
+ $<str>$ = $<str>1;
+}
+|
+cal_DOLLAR
+{
+ $<str>$ = $<str>1;
+}
+|
+cal_LCURLY
+{
+ $<str>$ = $<str>1;
+}
+|
+cal_RCURLY
+{
+ $<str>$ = $<str>1;
+}
+|
+cal_SYMBOL
+{
+ $<str>$ = $<str>1;
+}
+
+Variable:
+cal_ENVCURLY EnvVarName cal_RCURLY
+{
+ $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
+ //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
+}
+|
+cal_NCURLY MultipleIds cal_RCURLY
+{
+ $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
+ //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
+}
+|
+cal_DCURLY MultipleIds cal_RCURLY
+{
+ $<str>$ = yyGetParser->ExpandVariable($<str>2);
+ //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
+}
+|
+cal_ATNAME
+{
+ $<str>$ = yyGetParser->ExpandVariableForAt($<str>1);
+}
+
+EnvVarName:
+MultipleIds
+{
+ $<str>$ = $<str>1;
+}
+|
+cal_SYMBOL EnvVarName
+{
+ $<str>$ = $<str>1;
+}
+
+MultipleIds:
+{
+ $<str>$ = 0;
+}
+|
+ID MultipleIds
+{
+ $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
+}
+
+ID:
+cal_NAME
+{
+ $<str>$ = $<str>1;
+}
+|
+Variable
+{
+ $<str>$ = $<str>1;
+}
+
+
+%%
+/* End of grammar */
+
+/*--------------------------------------------------------------------------*/
+void cmCommandArgumentError(yyscan_t yyscanner, const char* message)
+{
+ yyGetParser->Error(message);
+}
+
diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx
new file mode 100644
index 0000000000..64b67c968d
--- /dev/null
+++ b/Source/cmCommandArgumentParserHelper.cxx
@@ -0,0 +1,367 @@
+/*============================================================================
+ 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 "cmCommandArgumentParserHelper.h"
+
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+
+#include "cmCommandArgumentLexer.h"
+
+int cmCommandArgument_yyparse( yyscan_t yyscanner );
+//
+cmCommandArgumentParserHelper::cmCommandArgumentParserHelper()
+{
+ this->WarnUninitialized = false;
+ this->CheckSystemVars = false;
+ this->FileLine = -1;
+ this->FileName = 0;
+ this->RemoveEmpty = true;
+ this->EmptyVariable[0] = 0;
+ strcpy(this->DCURLYVariable, "${");
+ strcpy(this->RCURLYVariable, "}");
+ strcpy(this->ATVariable, "@");
+ strcpy(this->DOLLARVariable, "$");
+ strcpy(this->LCURLYVariable, "{");
+ strcpy(this->BSLASHVariable, "\\");
+
+ this->NoEscapeMode = false;
+ this->ReplaceAtSyntax = false;
+}
+
+
+cmCommandArgumentParserHelper::~cmCommandArgumentParserHelper()
+{
+ this->CleanupParser();
+}
+
+void cmCommandArgumentParserHelper::SetLineFile(long line, const char* file)
+{
+ this->FileLine = line;
+ this->FileName = file;
+}
+
+char* cmCommandArgumentParserHelper::AddString(const std::string& str)
+{
+ if ( str.empty() )
+ {
+ return this->EmptyVariable;
+ }
+ char* stVal = new char[str.size()+1];
+ strcpy(stVal, str.c_str());
+ this->Variables.push_back(stVal);
+ return stVal;
+}
+
+char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key,
+ const char* var)
+{
+ if ( !key )
+ {
+ return this->ExpandVariable(var);
+ }
+ if(!var)
+ {
+ return this->EmptyVariable;
+ }
+ if ( strcmp(key, "ENV") == 0 )
+ {
+ char *ptr = getenv(var);
+ if (ptr)
+ {
+ if (this->EscapeQuotes)
+ {
+ return this->AddString(cmSystemTools::EscapeQuotes(ptr));
+ }
+ else
+ {
+ return ptr;
+ }
+ }
+ return this->EmptyVariable;
+ }
+ if ( strcmp(key, "CACHE") == 0 )
+ {
+ if(const char* c = this->Makefile->GetCacheManager()->GetCacheValue(var))
+ {
+ if(this->EscapeQuotes)
+ {
+ return this->AddString(cmSystemTools::EscapeQuotes(c));
+ }
+ else
+ {
+ return this->AddString(c);
+ }
+ }
+ return this->EmptyVariable;
+ }
+ cmOStringStream e;
+ e << "Syntax $" << key << "{} is not supported. "
+ << "Only ${}, $ENV{}, and $CACHE{} are allowed.";
+ this->SetError(e.str());
+ return 0;
+}
+
+char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
+{
+ if(!var)
+ {
+ return 0;
+ }
+ if(this->FileLine >= 0 && strcmp(var, "CMAKE_CURRENT_LIST_LINE") == 0)
+ {
+ cmOStringStream ostr;
+ ostr << this->FileLine;
+ return this->AddString(ostr.str());
+ }
+ const char* value = this->Makefile->GetDefinition(var);
+ if(!value && !this->RemoveEmpty)
+ {
+ // check to see if we need to print a warning
+ // if strict mode is on and the variable has
+ // not been "cleared"/initialized with a set(foo ) call
+ if(this->WarnUninitialized && !this->Makefile->VariableInitialized(var))
+ {
+ if (this->CheckSystemVars ||
+ cmSystemTools::IsSubDirectory(this->FileName,
+ this->Makefile->GetHomeDirectory()) ||
+ cmSystemTools::IsSubDirectory(this->FileName,
+ this->Makefile->GetHomeOutputDirectory()))
+ {
+ cmOStringStream msg;
+ cmListFileBacktrace bt(this->Makefile->GetLocalGenerator());
+ cmListFileContext lfc;
+ lfc.FilePath = this->FileName;
+ lfc.Line = this->FileLine;
+ bt.push_back(lfc);
+ msg << "uninitialized variable \'" << var << "\'";
+ this->Makefile->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
+ msg.str(), bt);
+ }
+ }
+ return 0;
+ }
+ if (this->EscapeQuotes && value)
+ {
+ return this->AddString(cmSystemTools::EscapeQuotes(value));
+ }
+ return this->AddString(value ? value : "");
+}
+
+char* cmCommandArgumentParserHelper::ExpandVariableForAt(const char* var)
+{
+ if(this->ReplaceAtSyntax)
+ {
+ // try to expand the variable
+ char* ret = this->ExpandVariable(var);
+ // if the return was 0 and we want to replace empty strings
+ // then return an empty string
+ if(!ret && this->RemoveEmpty)
+ {
+ return this->AddString("");
+ }
+ // if the ret was not 0, then return it
+ if(ret)
+ {
+ return ret;
+ }
+ }
+ // at this point we want to put it back because of one of these cases:
+ // - this->ReplaceAtSyntax is false
+ // - this->ReplaceAtSyntax is true, but this->RemoveEmpty is false,
+ // and the variable was not defined
+ std::string ref = "@";
+ ref += var;
+ ref += "@";
+ return this->AddString(ref);
+}
+
+char* cmCommandArgumentParserHelper::CombineUnions(char* in1, char* in2)
+{
+ if ( !in1 )
+ {
+ return in2;
+ }
+ else if ( !in2 )
+ {
+ return in1;
+ }
+ size_t len = strlen(in1) + strlen(in2) + 1;
+ char* out = new char [ len ];
+ strcpy(out, in1);
+ strcat(out, in2);
+ this->Variables.push_back(out);
+ return out;
+}
+
+void cmCommandArgumentParserHelper::AllocateParserType
+(cmCommandArgumentParserHelper::ParserType* pt,const char* str, int len)
+{
+ pt->str = 0;
+ if ( len == 0 )
+ {
+ len = static_cast<int>(strlen(str));
+ }
+ if ( len == 0 )
+ {
+ return;
+ }
+ pt->str = new char[ len + 1 ];
+ strncpy(pt->str, str, len);
+ pt->str[len] = 0;
+ this->Variables.push_back(pt->str);
+}
+
+bool cmCommandArgumentParserHelper::HandleEscapeSymbol
+(cmCommandArgumentParserHelper::ParserType* pt, char symbol)
+{
+ switch ( symbol )
+ {
+ case '\\':
+ case '"':
+ case ' ':
+ case '#':
+ case '(':
+ case ')':
+ case '$':
+ case '@':
+ case '^':
+ this->AllocateParserType(pt, &symbol, 1);
+ break;
+ case ';':
+ this->AllocateParserType(pt, "\\;", 2);
+ break;
+ case 't':
+ this->AllocateParserType(pt, "\t", 1);
+ break;
+ case 'n':
+ this->AllocateParserType(pt, "\n", 1);
+ break;
+ case 'r':
+ this->AllocateParserType(pt, "\r", 1);
+ break;
+ case '0':
+ this->AllocateParserType(pt, "\0", 1);
+ break;
+ default:
+ {
+ cmOStringStream e;
+ e << "Invalid escape sequence \\" << symbol;
+ this->SetError(e.str());
+ }
+ return false;
+ }
+ return true;
+}
+
+void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes);
+
+int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
+{
+ if ( !str)
+ {
+ return 0;
+ }
+ this->Verbose = verb;
+ this->InputBuffer = str;
+ this->InputBufferPos = 0;
+ this->CurrentLine = 0;
+
+ this->Result = "";
+
+ yyscan_t yyscanner;
+ cmCommandArgument_yylex_init(&yyscanner);
+ cmCommandArgument_yyset_extra(this, yyscanner);
+ cmCommandArgument_SetupEscapes(yyscanner, this->NoEscapeMode);
+ int res = cmCommandArgument_yyparse(yyscanner);
+ cmCommandArgument_yylex_destroy(yyscanner);
+ if ( res != 0 )
+ {
+ return 0;
+ }
+
+ this->CleanupParser();
+
+ if ( Verbose )
+ {
+ std::cerr << "Expanding [" << str << "] produced: ["
+ << this->Result << "]" << std::endl;
+ }
+ return 1;
+}
+
+void cmCommandArgumentParserHelper::CleanupParser()
+{
+ std::vector<char*>::iterator sit;
+ for ( sit = this->Variables.begin();
+ sit != this->Variables.end();
+ ++ sit )
+ {
+ delete [] *sit;
+ }
+ this->Variables.erase(this->Variables.begin(), this->Variables.end());
+}
+
+int cmCommandArgumentParserHelper::LexInput(char* buf, int maxlen)
+{
+ if ( maxlen < 1 )
+ {
+ return 0;
+ }
+ if ( this->InputBufferPos < this->InputBuffer.size() )
+ {
+ buf[0] = this->InputBuffer[ this->InputBufferPos++ ];
+ if ( buf[0] == '\n' )
+ {
+ this->CurrentLine ++;
+ }
+ return(1);
+ }
+ else
+ {
+ buf[0] = '\n';
+ return( 0 );
+ }
+}
+
+void cmCommandArgumentParserHelper::Error(const char* str)
+{
+ unsigned long pos = static_cast<unsigned long>(this->InputBufferPos);
+ cmOStringStream ostr;
+ ostr << str << " (" << pos << ")";
+ this->SetError(ostr.str());
+}
+
+void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf)
+{
+ this->Makefile = mf;
+ this->WarnUninitialized = mf->GetCMakeInstance()->GetWarnUninitialized();
+ this->CheckSystemVars = mf->GetCMakeInstance()->GetCheckSystemVars();
+}
+
+void cmCommandArgumentParserHelper::SetResult(const char* value)
+{
+ if ( !value )
+ {
+ this->Result = "";
+ return;
+ }
+ this->Result = value;
+}
+
+void cmCommandArgumentParserHelper::SetError(std::string const& msg)
+{
+ // Keep only the first error.
+ if(this->ErrorString.empty())
+ {
+ this->ErrorString = msg;
+ }
+}
diff --git a/Source/cmCommandArgumentParserHelper.h b/Source/cmCommandArgumentParserHelper.h
new file mode 100644
index 0000000000..d375ae6246
--- /dev/null
+++ b/Source/cmCommandArgumentParserHelper.h
@@ -0,0 +1,110 @@
+/*============================================================================
+ 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 cmCommandArgumentParserHelper_h
+#define cmCommandArgumentParserHelper_h
+
+#include "cmStandardIncludes.h"
+
+#define YYSTYPE cmCommandArgumentParserHelper::ParserType
+#define YYSTYPE_IS_DECLARED
+#define YY_EXTRA_TYPE cmCommandArgumentParserHelper*
+#define YY_DECL int cmCommandArgument_yylex(YYSTYPE* yylvalp,\
+ yyscan_t yyscanner)
+
+/** \class cmCommandArgumentParserHelper
+ * \brief Helper class for parsing java source files
+ *
+ * Finds dependencies for java file and list of outputs
+ */
+
+class cmMakefile;
+
+class cmCommandArgumentParserHelper
+{
+public:
+ typedef struct {
+ char* str;
+ } ParserType;
+
+ cmCommandArgumentParserHelper();
+ ~cmCommandArgumentParserHelper();
+
+ int ParseString(const char* str, int verb);
+
+ // For the lexer:
+ void AllocateParserType(cmCommandArgumentParserHelper::ParserType* pt,
+ const char* str, int len = 0);
+ bool HandleEscapeSymbol(cmCommandArgumentParserHelper::ParserType* pt,
+ char symbol);
+
+ int LexInput(char* buf, int maxlen);
+ void Error(const char* str);
+
+ // For yacc
+ char* CombineUnions(char* in1, char* in2);
+
+ char* ExpandSpecialVariable(const char* key, const char* var);
+ char* ExpandVariable(const char* var);
+ char* ExpandVariableForAt(const char* var);
+ void SetResult(const char* value);
+
+ void SetMakefile(const cmMakefile* mf);
+
+ std::string& GetResult() { return this->Result; }
+
+ void SetLineFile(long line, const char* file);
+ void SetEscapeQuotes(bool b) { this->EscapeQuotes = b; }
+ void SetNoEscapeMode(bool b) { this->NoEscapeMode = b; }
+ void SetReplaceAtSyntax(bool b) { this->ReplaceAtSyntax = b; }
+ void SetRemoveEmpty(bool b) { this->RemoveEmpty = b; }
+
+ const char* GetError() { return this->ErrorString.c_str(); }
+ char EmptyVariable[1];
+ char DCURLYVariable[3];
+ char RCURLYVariable[3];
+ char ATVariable[3];
+ char DOLLARVariable[3];
+ char LCURLYVariable[3];
+ char BSLASHVariable[3];
+
+private:
+ std::string::size_type InputBufferPos;
+ std::string InputBuffer;
+ std::vector<char> OutputBuffer;
+ int CurrentLine;
+ int Verbose;
+
+ void Print(const char* place, const char* str);
+ void SafePrintMissing(const char* str, int line, int cnt);
+
+ char* AddString(const std::string& str);
+
+ void CleanupParser();
+ void SetError(std::string const& msg);
+
+ std::vector<char*> Variables;
+ const cmMakefile* Makefile;
+ std::string Result;
+ const char* FileName;
+ bool WarnUninitialized;
+ bool CheckSystemVars;
+ long FileLine;
+ bool EscapeQuotes;
+ std::string ErrorString;
+ bool NoEscapeMode;
+ bool ReplaceAtSyntax;
+ bool RemoveEmpty;
+};
+
+#endif
+
+
diff --git a/Source/cmCommandArgumentParserTokens.h b/Source/cmCommandArgumentParserTokens.h
new file mode 100644
index 0000000000..7fb58e2d9c
--- /dev/null
+++ b/Source/cmCommandArgumentParserTokens.h
@@ -0,0 +1,92 @@
+/*============================================================================
+ 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.
+============================================================================*/
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton interface for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ cal_ENVCURLY = 258,
+ cal_NCURLY = 259,
+ cal_DCURLY = 260,
+ cal_DOLLAR = 261,
+ cal_LCURLY = 262,
+ cal_RCURLY = 263,
+ cal_NAME = 264,
+ cal_BSLASH = 265,
+ cal_SYMBOL = 266,
+ cal_AT = 267,
+ cal_ERROR = 268,
+ cal_ATNAME = 269
+ };
+#endif
+/* Tokens. */
+#define cal_ENVCURLY 258
+#define cal_NCURLY 259
+#define cal_DCURLY 260
+#define cal_DOLLAR 261
+#define cal_LCURLY 262
+#define cal_RCURLY 263
+#define cal_NAME 264
+#define cal_BSLASH 265
+#define cal_SYMBOL 266
+#define cal_AT 267
+#define cal_ERROR 268
+#define cal_ATNAME 269
+
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef int YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
diff --git a/Source/cmCommandArgumentsHelper.cxx b/Source/cmCommandArgumentsHelper.cxx
new file mode 100644
index 0000000000..1d5fc07906
--- /dev/null
+++ b/Source/cmCommandArgumentsHelper.cxx
@@ -0,0 +1,307 @@
+/*============================================================================
+ 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 "cmCommandArgumentsHelper.h"
+
+cmCommandArgument::cmCommandArgument(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group)
+:Key(key)
+,Group(group)
+,WasActive(false)
+,ArgumentsBeforeEmpty(true)
+,CurrentIndex(0)
+{
+ if (args!=0)
+ {
+ args->AddArgument(this);
+ }
+
+ if (this->Group!=0)
+ {
+ this->Group->ContainedArguments.push_back(this);
+ }
+}
+
+void cmCommandArgument::Reset()
+{
+ this->WasActive =false;
+ this->CurrentIndex = 0;
+ this->DoReset();
+}
+
+void cmCommandArgument::Follows(const cmCommandArgument* arg)
+{
+ this->ArgumentsBeforeEmpty = false;
+ this->ArgumentsBefore.insert(arg);
+}
+
+void cmCommandArgument::FollowsGroup(const cmCommandArgumentGroup* group)
+{
+ if (group!=0)
+ {
+ this->ArgumentsBeforeEmpty = false;
+ for(std::vector<cmCommandArgument*>::const_iterator
+ argIt= group->ContainedArguments.begin();
+ argIt != group->ContainedArguments.end();
+ ++argIt)
+ {
+ this->ArgumentsBefore.insert(*argIt);
+ }
+ }
+}
+
+bool cmCommandArgument::MayFollow(const cmCommandArgument* current) const
+{
+ if (this->ArgumentsBeforeEmpty)
+ {
+ return true;
+ }
+
+ std::set<const cmCommandArgument*>::const_iterator argIt
+ = this->ArgumentsBefore.find(current);
+ if (argIt != this->ArgumentsBefore.end())
+ {
+ return true;
+ }
+
+ return false;
+}
+
+bool cmCommandArgument::KeyMatches(const std::string& key) const
+{
+ if ((this->Key==0) || (this->Key[0]=='\0'))
+ {
+ return true;
+ }
+ return (key==this->Key);
+}
+
+void cmCommandArgument::ApplyOwnGroup()
+{
+ if (this->Group!=0)
+ {
+ for (std::vector<cmCommandArgument*>::const_iterator
+ it = this->Group->ContainedArguments.begin();
+ it != this->Group->ContainedArguments.end();
+ ++it)
+ {
+ if(*it != this)
+ {
+ this->ArgumentsBefore.insert(*it);
+ }
+ }
+ }
+}
+
+void cmCommandArgument::Activate()
+{
+ this->WasActive = true;
+ this->CurrentIndex = 0;
+}
+
+bool cmCommandArgument::Consume(const std::string& arg)
+{
+ bool res=this->DoConsume(arg, this->CurrentIndex);
+ this->CurrentIndex++;
+ return res;
+}
+
+
+cmCAStringVector::cmCAStringVector(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group)
+:cmCommandArgument(args, key, group)
+,Ignore(0)
+{
+ if ((key==0) || (*key==0))
+ {
+ this->DataStart = 0;
+ }
+ else
+ {
+ this->DataStart = 1;
+ }
+}
+
+bool cmCAStringVector::DoConsume(const std::string& arg,unsigned int index)
+{
+ if (index >= this->DataStart)
+ {
+ if ((this->Ignore==0) || (arg != this->Ignore))
+ {
+ this->Vector.push_back(arg);
+ }
+ }
+
+ return false;
+}
+
+void cmCAStringVector::DoReset()
+{
+ this->Vector.clear();
+}
+
+cmCAString::cmCAString(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group)
+:cmCommandArgument(args, key, group)
+{
+ if ((key==0) || (*key==0))
+ {
+ this->DataStart = 0;
+ }
+ else
+ {
+ this->DataStart = 1;
+ }
+}
+
+bool cmCAString::DoConsume(const std::string& arg, unsigned int index)
+{
+ if (index == this->DataStart)
+ {
+ this->String = arg;
+ }
+
+ return index >= this->DataStart;
+}
+
+void cmCAString::DoReset()
+{
+ this->String = "";
+}
+
+cmCAEnabler::cmCAEnabler(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group)
+:cmCommandArgument(args, key, group)
+,Enabled(false)
+{}
+
+bool cmCAEnabler::DoConsume(const std::string&, unsigned int index)
+{
+ if (index==0)
+ {
+ this->Enabled = true;
+ }
+ return true;
+}
+
+void cmCAEnabler::DoReset()
+{
+ this->Enabled = false;
+}
+
+cmCADisabler::cmCADisabler(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group)
+:cmCommandArgument(args, key, group)
+,Enabled(true)
+{}
+
+bool cmCADisabler::DoConsume(const std::string&, unsigned int index)
+{
+ if (index==0)
+ {
+ this->Enabled = false;
+ }
+ return true;
+}
+
+void cmCADisabler::DoReset()
+{
+ this->Enabled = true;
+}
+
+void cmCommandArgumentGroup::Follows(const cmCommandArgument* arg)
+{
+ for(std::vector<cmCommandArgument*>::iterator
+ it = this->ContainedArguments.begin();
+ it != this->ContainedArguments.end();
+ ++it)
+ {
+ (*it)->Follows(arg);
+ }
+}
+
+void cmCommandArgumentGroup::FollowsGroup(const cmCommandArgumentGroup* group)
+{
+ for(std::vector<cmCommandArgument*>::iterator
+ it = this->ContainedArguments.begin();
+ it != this->ContainedArguments.end();
+ ++it)
+ {
+ (*it)->FollowsGroup(group);
+ }
+}
+
+void cmCommandArgumentsHelper::Parse(const std::vector<std::string>* args,
+ std::vector<std::string>* unconsumedArgs)
+{
+ if(args==0)
+ {
+ return;
+ }
+
+ for(std::vector<cmCommandArgument*>::iterator
+ argIt = this->Arguments.begin();
+ argIt != this->Arguments.end();
+ ++argIt)
+ {
+ (*argIt)->ApplyOwnGroup();
+ (*argIt)->Reset();
+ }
+
+ cmCommandArgument* activeArgument = 0;
+ const cmCommandArgument* previousArgument = 0;
+ for(std::vector<std::string>::const_iterator it = args->begin();
+ it != args->end();
+ ++it)
+ {
+ for(std::vector<cmCommandArgument*>::iterator
+ argIt = this->Arguments.begin();
+ argIt != this->Arguments.end();
+ ++argIt)
+ {
+ if ((*argIt)->KeyMatches(*it) && ((*argIt)->MayFollow(previousArgument)))
+ {
+ activeArgument = *argIt;
+ activeArgument->Activate();
+ break;
+ }
+ }
+
+ if (activeArgument)
+ {
+ bool argDone = activeArgument->Consume(*it);
+ previousArgument = activeArgument;
+ if (argDone)
+ {
+ activeArgument = 0;
+ }
+ }
+ else
+ {
+ if (unconsumedArgs!=0)
+ {
+ unconsumedArgs->push_back(*it);
+ }
+ }
+ }
+}
+
+void cmCommandArgumentsHelper::AddArgument(cmCommandArgument* arg)
+{
+ this->Arguments.push_back(arg);
+}
+
diff --git a/Source/cmCommandArgumentsHelper.h b/Source/cmCommandArgumentsHelper.h
new file mode 100644
index 0000000000..f732f8f1d3
--- /dev/null
+++ b/Source/cmCommandArgumentsHelper.h
@@ -0,0 +1,204 @@
+/*============================================================================
+ 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 cmCommandArgumentsHelper_h
+#define cmCommandArgumentsHelper_h
+
+#include "cmStandardIncludes.h"
+
+class cmCommandArgumentsHelper;
+class cmCommandArgumentGroup;
+
+/* cmCommandArgumentsHelper, cmCommandArgumentGroup and cmCommandArgument (i.e.
+its derived classes cmCAXXX can be used to simplify the processing of
+arguments to cmake commands. Maybe they can also be used to generate
+documentation.
+
+For every argument supported by a command one cmCommandArgument is created
+and added to cmCommandArgumentsHelper. cmCommand has a cmCommandArgumentsHelper
+as member variable so this should be used.
+
+The order of the arguments is defined using the Follows(arg) method. It says
+that this argument follows immediateley the given argument. It can be used
+with multiple arguments if the argument can follow after different arguments.
+
+Arguments can be arranged in groups using cmCommandArgumentGroup. Every
+member of a group can follow any other member of the group. These groups
+can also be used to define the order.
+
+Once all arguments and groups are set up, cmCommandArgumentsHelper::Parse()
+is called and afterwards the values of the arguments can be evaluated.
+
+For an example see cmExportCommand.cxx.
+*/
+class cmCommandArgument
+{
+ public:
+ cmCommandArgument(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group=0);
+ virtual ~cmCommandArgument() {}
+
+ /// this argument may follow after arg. 0 means it comes first.
+ void Follows(const cmCommandArgument* arg);
+
+ /// this argument may follow after any of the arguments in the given group
+ void FollowsGroup(const cmCommandArgumentGroup* group);
+
+ /// Returns true if the argument was found in the argument list
+ bool WasFound() const {return this->WasActive;}
+
+ // The following methods are only called from
+ // cmCommandArgumentsHelper::Parse(), but making this a friend would
+ // give it access to everything
+
+ /// Make the current argument the currently active argument
+ void Activate();
+ /// Consume the current string
+ bool Consume(const std::string& arg);
+
+ /// Return true if this argument may follow after the given argument.
+ bool MayFollow(const cmCommandArgument* current) const;
+
+ /** Returns true if the given key matches the key for this argument.
+ If this argument has an empty key everything matches. */
+ bool KeyMatches(const std::string& key) const;
+
+ /// Make this argument follow all members of the own group
+ void ApplyOwnGroup();
+
+ /// Reset argument, so it's back to its initial state
+ void Reset();
+ private:
+ const char* Key;
+ std::set<const cmCommandArgument*> ArgumentsBefore;
+ cmCommandArgumentGroup* Group;
+ bool WasActive;
+ bool ArgumentsBeforeEmpty;
+ unsigned int CurrentIndex;
+
+ virtual bool DoConsume(const std::string& arg, unsigned int index) = 0;
+ virtual void DoReset() = 0;
+};
+
+/** cmCAStringVector is to be used for arguments which can consist of more
+than one string, e.g. the FILES argument in INSTALL(FILES f1 f2 f3 ...). */
+class cmCAStringVector : public cmCommandArgument
+{
+ public:
+ cmCAStringVector(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group=0);
+
+ /// Return the vector of strings
+ const std::vector<std::string>& GetVector() const {return this->Vector;}
+
+ /** Is there a keyword which should be skipped in
+ the arguments (e.g. ARGS for ADD_CUSTOM_COMMAND) ? */
+ void SetIgnore(const char* ignore) {this->Ignore=ignore;}
+ private:
+ std::vector<std::string> Vector;
+ unsigned int DataStart;
+ const char* Ignore;
+ cmCAStringVector();
+ virtual bool DoConsume(const std::string& arg, unsigned int index);
+ virtual void DoReset();
+};
+
+/** cmCAString is to be used for arguments which consist of one value,
+e.g. the executable name in ADD_EXECUTABLE(). */
+class cmCAString : public cmCommandArgument
+{
+ public:
+ cmCAString(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group=0);
+
+ /// Return the string
+ const std::string& GetString() const {return this->String;}
+ const char* GetCString() const {return this->String.c_str();}
+ private:
+ std::string String;
+ unsigned int DataStart;
+ virtual bool DoConsume(const std::string& arg, unsigned int index);
+ virtual void DoReset();
+ cmCAString();
+};
+
+/** cmCAEnabler is to be used for options which are off by default and can be
+enabled using a special argument, e.g. EXCLUDE_FROM_ALL in ADD_EXECUTABLE(). */
+class cmCAEnabler : public cmCommandArgument
+{
+ public:
+ cmCAEnabler(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group=0);
+
+ /// Has it been enabled ?
+ bool IsEnabled() const {return this->Enabled;}
+ private:
+ bool Enabled;
+ virtual bool DoConsume(const std::string& arg, unsigned int index);
+ virtual void DoReset();
+ cmCAEnabler();
+};
+
+/** cmCADisable is to be used for options which are on by default and can be
+disabled using a special argument.*/
+class cmCADisabler : public cmCommandArgument
+{
+ public:
+ cmCADisabler(cmCommandArgumentsHelper* args,
+ const char* key,
+ cmCommandArgumentGroup* group=0);
+
+ /// Is it still enabled ?
+ bool IsEnabled() const {return this->Enabled;}
+ private:
+ bool Enabled;
+ virtual bool DoConsume(const std::string& arg, unsigned int index);
+ virtual void DoReset();
+ cmCADisabler();
+};
+
+
+/** Group of arguments, needed for ordering. E.g. WIN32, EXCLUDE_FROM_ALL and
+MACSOX_BUNDLE from ADD_EXECUTABLE() are a group.
+*/
+class cmCommandArgumentGroup
+{
+ friend class cmCommandArgument;
+ public:
+ cmCommandArgumentGroup() {}
+
+ /// All members of this group may follow the given argument
+ void Follows(const cmCommandArgument* arg);
+
+ /// All members of this group may follow all members of the given group
+ void FollowsGroup(const cmCommandArgumentGroup* group);
+ private:
+ std::vector<cmCommandArgument*> ContainedArguments;
+};
+
+class cmCommandArgumentsHelper
+{
+ public:
+ /// Parse the argument list
+ void Parse(const std::vector<std::string>* args,
+ std::vector<std::string>* unconsumedArgs);
+ /// Add an argument.
+ void AddArgument(cmCommandArgument* arg);
+ private:
+ std::vector<cmCommandArgument*> Arguments;
+};
+
+
+#endif
diff --git a/Source/cmCommands.cxx.in b/Source/cmCommands.cxx.in
new file mode 100644
index 0000000000..f0745d780e
--- /dev/null
+++ b/Source/cmCommands.cxx.in
@@ -0,0 +1,19 @@
+/*============================================================================
+ 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 "cmCommands.h"
+
+@COMMAND_INCLUDES@
+
+void GetPredefinedCommands(std::list<cmCommand*>& commands)
+{
+@NEW_COMMANDS@
+}
diff --git a/Source/cmCommands.h b/Source/cmCommands.h
new file mode 100644
index 0000000000..c56673fed5
--- /dev/null
+++ b/Source/cmCommands.h
@@ -0,0 +1,29 @@
+/*============================================================================
+ 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 cmCommands_h
+#define cmCommands_h
+#include "cmStandardIncludes.h"
+
+class cmCommand;
+/**
+ * Global function to return all compiled in commands.
+ * To add a new command edit cmCommands.cxx or cmBootstrapCommands[12].cxx
+ * and add your command.
+ * It is up to the caller to delete the commands created by this
+ * call.
+ */
+void GetBootstrapCommands1(std::list<cmCommand*>& commands);
+void GetBootstrapCommands2(std::list<cmCommand*>& commands);
+void GetPredefinedCommands(std::list<cmCommand*>& commands);
+
+
+#endif
diff --git a/Source/cmCommandsForBootstrap.cxx b/Source/cmCommandsForBootstrap.cxx
new file mode 100644
index 0000000000..15b664eeed
--- /dev/null
+++ b/Source/cmCommandsForBootstrap.cxx
@@ -0,0 +1,16 @@
+/*============================================================================
+ 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 "cmCommands.h"
+
+void GetPredefinedCommands(std::list<cmCommand*>&)
+{
+}
diff --git a/Source/cmComputeComponentGraph.cxx b/Source/cmComputeComponentGraph.cxx
new file mode 100644
index 0000000000..5bec6a1ec1
--- /dev/null
+++ b/Source/cmComputeComponentGraph.cxx
@@ -0,0 +1,159 @@
+/*============================================================================
+ 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 "cmComputeComponentGraph.h"
+
+#include <algorithm>
+
+#include <assert.h>
+
+//----------------------------------------------------------------------------
+cmComputeComponentGraph::cmComputeComponentGraph(Graph const& input):
+ InputGraph(input)
+{
+ // Identify components.
+ this->Tarjan();
+
+ // Compute the component graph.
+ this->ComponentGraph.resize(0);
+ this->ComponentGraph.resize(this->Components.size());
+ this->TransferEdges();
+}
+
+//----------------------------------------------------------------------------
+cmComputeComponentGraph::~cmComputeComponentGraph()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmComputeComponentGraph::Tarjan()
+{
+ int n = static_cast<int>(this->InputGraph.size());
+ TarjanEntry entry = {0,0};
+ this->TarjanEntries.resize(0);
+ this->TarjanEntries.resize(n, entry);
+ this->TarjanComponents.resize(0);
+ this->TarjanComponents.resize(n, -1);
+ this->TarjanWalkId = 0;
+ this->TarjanVisited.resize(0);
+ this->TarjanVisited.resize(n, 0);
+ for(int i = 0; i < n; ++i)
+ {
+ // Start a new DFS from this node if it has never been visited.
+ if(!this->TarjanVisited[i])
+ {
+ assert(this->TarjanStack.empty());
+ ++this->TarjanWalkId;
+ this->TarjanIndex = 0;
+ this->TarjanVisit(i);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeComponentGraph::TarjanVisit(int i)
+{
+ // We are now visiting this node.
+ this->TarjanVisited[i] = this->TarjanWalkId;
+
+ // Initialize the entry.
+ this->TarjanEntries[i].Root = i;
+ this->TarjanComponents[i] = -1;
+ this->TarjanEntries[i].VisitIndex = ++this->TarjanIndex;
+ this->TarjanStack.push(i);
+
+ // Follow outgoing edges.
+ EdgeList const& nl = this->InputGraph[i];
+ for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
+ {
+ int j = *ni;
+
+ // Ignore edges to nodes that have been reached by a previous DFS
+ // walk. Since we did not reach the current node from that walk
+ // it must not belong to the same component and it has already
+ // been assigned to a component.
+ if(this->TarjanVisited[j] > 0 &&
+ this->TarjanVisited[j] < this->TarjanWalkId)
+ {
+ continue;
+ }
+
+ // Visit the destination if it has not yet been visited.
+ if(!this->TarjanVisited[j])
+ {
+ this->TarjanVisit(j);
+ }
+
+ // If the destination has not yet been assigned to a component,
+ // check if it has a better root for the current object.
+ if(this->TarjanComponents[j] < 0)
+ {
+ if(this->TarjanEntries[this->TarjanEntries[j].Root].VisitIndex <
+ this->TarjanEntries[this->TarjanEntries[i].Root].VisitIndex)
+ {
+ this->TarjanEntries[i].Root = this->TarjanEntries[j].Root;
+ }
+ }
+ }
+
+ // Check if we have found a component.
+ if(this->TarjanEntries[i].Root == i)
+ {
+ // Yes. Create it.
+ int c = static_cast<int>(this->Components.size());
+ this->Components.push_back(NodeList());
+ NodeList& component = this->Components[c];
+
+ // Populate the component list.
+ int j;
+ do
+ {
+ // Get the next member of the component.
+ j = this->TarjanStack.top();
+ this->TarjanStack.pop();
+
+ // Assign the member to the component.
+ this->TarjanComponents[j] = c;
+ this->TarjanEntries[j].Root = i;
+
+ // Store the node in its component.
+ component.push_back(j);
+ } while(j != i);
+
+ // Sort the component members for clarity.
+ std::sort(component.begin(), component.end());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeComponentGraph::TransferEdges()
+{
+ // Map inter-component edges in the original graph to edges in the
+ // component graph.
+ int n = static_cast<int>(this->InputGraph.size());
+ for(int i=0; i < n; ++i)
+ {
+ int i_component = this->TarjanComponents[i];
+ EdgeList const& nl = this->InputGraph[i];
+ for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
+ {
+ int j = *ni;
+ int j_component = this->TarjanComponents[j];
+ if(i_component != j_component)
+ {
+ // We do not attempt to combine duplicate edges, but instead
+ // store the inter-component edges with suitable multiplicity.
+ this->ComponentGraph[i_component].push_back(
+ cmGraphEdge(j_component, ni->IsStrong()));
+ }
+ }
+ }
+}
diff --git a/Source/cmComputeComponentGraph.h b/Source/cmComputeComponentGraph.h
new file mode 100644
index 0000000000..a2ce946c1e
--- /dev/null
+++ b/Source/cmComputeComponentGraph.h
@@ -0,0 +1,83 @@
+/*============================================================================
+ 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 cmComputeComponentGraph_h
+#define cmComputeComponentGraph_h
+
+#include "cmStandardIncludes.h"
+
+#include "cmGraphAdjacencyList.h"
+
+#include <stack>
+
+/** \class cmComputeComponentGraph
+ * \brief Analyze a graph to determine strongly connected components.
+ *
+ * Convert a directed graph into a directed acyclic graph whose nodes
+ * correspond to strongly connected components of the original graph.
+ *
+ * We use Tarjan's algorithm to enumerate the components efficiently.
+ * An advantage of this approach is that the components are identified
+ * in a topologically sorted order.
+ */
+class cmComputeComponentGraph
+{
+public:
+ // Represent the graph with an adjacency list.
+ typedef cmGraphNodeList NodeList;
+ typedef cmGraphEdgeList EdgeList;
+ typedef cmGraphAdjacencyList Graph;
+
+ cmComputeComponentGraph(Graph const& input);
+ ~cmComputeComponentGraph();
+
+ /** Get the adjacency list of the component graph. */
+ Graph const& GetComponentGraph() const
+ { return this->ComponentGraph; }
+ EdgeList const& GetComponentGraphEdges(int c) const
+ { return this->ComponentGraph[c]; }
+
+ /** Get map from component index to original node indices. */
+ std::vector<NodeList> const& GetComponents() const
+ { return this->Components; }
+ NodeList const& GetComponent(int c) const
+ { return this->Components[c]; }
+
+ /** Get map from original node index to component index. */
+ std::vector<int> const& GetComponentMap() const
+ { return this->TarjanComponents; }
+
+private:
+ void TransferEdges();
+
+ Graph const& InputGraph;
+ Graph ComponentGraph;
+
+ // Tarjan's algorithm.
+ struct TarjanEntry
+ {
+ int Root;
+ int VisitIndex;
+ };
+ int TarjanWalkId;
+ std::vector<int> TarjanVisited;
+ std::vector<int> TarjanComponents;
+ std::vector<TarjanEntry> TarjanEntries;
+ std::stack<int> TarjanStack;
+ int TarjanIndex;
+ void Tarjan();
+ void TarjanVisit(int i);
+
+ // Connected components.
+ std::vector<NodeList> Components;
+};
+
+#endif
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
new file mode 100644
index 0000000000..b13a125a39
--- /dev/null
+++ b/Source/cmComputeLinkDepends.cxx
@@ -0,0 +1,990 @@
+/*============================================================================
+ 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 "cmComputeLinkDepends.h"
+
+#include "cmComputeComponentGraph.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmTarget.h"
+#include "cmake.h"
+
+#include <cmsys/stl/algorithm>
+
+#include <assert.h>
+
+/*
+
+This file computes an ordered list of link items to use when linking a
+single target in one configuration. Each link item is identified by
+the string naming it. A graph of dependencies is created in which
+each node corresponds to one item and directed edges lead from nodes to
+those which must *follow* them on the link line. For example, the
+graph
+
+ A -> B -> C
+
+will lead to the link line order
+
+ A B C
+
+The set of items placed in the graph is formed with a breadth-first
+search of the link dependencies starting from the main target.
+
+There are two types of items: those with known direct dependencies and
+those without known dependencies. We will call the two types "known
+items" and "unknown items", respectively. Known items are those whose
+names correspond to targets (built or imported) and those for which an
+old-style <item>_LIB_DEPENDS variable is defined. All other items are
+unknown and we must infer dependencies for them. For items that look
+like flags (beginning with '-') we trivially infer no dependencies,
+and do not include them in the dependencies of other items.
+
+Known items have dependency lists ordered based on how the user
+specified them. We can use this order to infer potential dependencies
+of unknown items. For example, if link items A and B are unknown and
+items X and Y are known, then we might have the following dependency
+lists:
+
+ X: Y A B
+ Y: A B
+
+The explicitly known dependencies form graph edges
+
+ X -> Y , X -> A , X -> B , Y -> A , Y -> B
+
+We can also infer the edge
+
+ A -> B
+
+because *every* time A appears B is seen on its right. We do not know
+whether A really needs symbols from B to link, but it *might* so we
+must preserve their order. This is the case also for the following
+explicit lists:
+
+ X: A B Y
+ Y: A B
+
+Here, A is followed by the set {B,Y} in one list, and {B} in the other
+list. The intersection of these sets is {B}, so we can infer that A
+depends on at most B. Meanwhile B is followed by the set {Y} in one
+list and {} in the other. The intersection is {} so we can infer that
+B has no dependencies.
+
+Let's make a more complex example by adding unknown item C and
+considering these dependency lists:
+
+ X: A B Y C
+ Y: A C B
+
+The explicit edges are
+
+ X -> Y , X -> A , X -> B , X -> C , Y -> A , Y -> B , Y -> C
+
+For the unknown items, we infer dependencies by looking at the
+"follow" sets:
+
+ A: intersect( {B,Y,C} , {C,B} ) = {B,C} ; infer edges A -> B , A -> C
+ B: intersect( {Y,C} , {} ) = {} ; infer no edges
+ C: intersect( {} , {B} ) = {} ; infer no edges
+
+Note that targets are never inferred as dependees because outside
+libraries should not depend on them.
+
+------------------------------------------------------------------------------
+
+The initial exploration of dependencies using a BFS associates an
+integer index with each link item. When the graph is built outgoing
+edges are sorted by this index.
+
+After the initial exploration of the link interface tree, any
+transitive (dependent) shared libraries that were encountered and not
+included in the interface are processed in their own BFS. This BFS
+follows only the dependent library lists and not the link interfaces.
+They are added to the link items with a mark indicating that the are
+transitive dependencies. Then cmComputeLinkInformation deals with
+them on a per-platform basis.
+
+The complete graph formed from all known and inferred dependencies may
+not be acyclic, so an acyclic version must be created.
+The original graph is converted to a directed acyclic graph in which
+each node corresponds to a strongly connected component of the
+original graph. For example, the dependency graph
+
+ X -> A -> B -> C -> A -> Y
+
+contains strongly connected components {X}, {A,B,C}, and {Y}. The
+implied directed acyclic graph (DAG) is
+
+ {X} -> {A,B,C} -> {Y}
+
+We then compute a topological order for the DAG nodes to serve as a
+reference for satisfying dependencies efficiently. We perform the DFS
+in reverse order and assign topological order indices counting down so
+that the result is as close to the original BFS order as possible
+without violating dependencies.
+
+------------------------------------------------------------------------------
+
+The final link entry order is constructed as follows. We first walk
+through and emit the *original* link line as specified by the user.
+As each item is emitted, a set of pending nodes in the component DAG
+is maintained. When a pending component has been completely seen, it
+is removed from the pending set and its dependencies (following edges
+of the DAG) are added. A trivial component (those with one item) is
+complete as soon as its item is seen. A non-trivial component (one
+with more than one item; assumed to be static libraries) is complete
+when *all* its entries have been seen *twice* (all entries seen once,
+then all entries seen again, not just each entry twice). A pending
+component tracks which items have been seen and a count of how many
+times the component needs to be seen (once for trivial components,
+twice for non-trivial). If at any time another component finishes and
+re-adds an already pending component, the pending component is reset
+so that it needs to be seen in its entirety again. This ensures that
+all dependencies of a component are satisfied no matter where it
+appears.
+
+After the original link line has been completed, we append to it the
+remaining pending components and their dependencies. This is done by
+repeatedly emitting the first item from the first pending component
+and following the same update rules as when traversing the original
+link line. Since the pending components are kept in topological order
+they are emitted with minimal repeats (we do not want to emit a
+component just to have it added again when another component is
+completed later). This process continues until no pending components
+remain. We know it will terminate because the component graph is
+guaranteed to be acyclic.
+
+The final list of items produced by this procedure consists of the
+original user link line followed by minimal additional items needed to
+satisfy dependencies. The final list is then filtered to de-duplicate
+items that we know the linker will re-use automatically (shared libs).
+
+*/
+
+//----------------------------------------------------------------------------
+cmComputeLinkDepends
+::cmComputeLinkDepends(cmTarget const* target, const std::string& config)
+{
+ // Store context information.
+ this->Target = target;
+ this->Makefile = this->Target->GetMakefile();
+ this->LocalGenerator = this->Makefile->GetLocalGenerator();
+ this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
+ this->CMakeInstance = this->GlobalGenerator->GetCMakeInstance();
+
+ // The configuration being linked.
+ this->HasConfig = !config.empty();
+ this->Config = (this->HasConfig)? config : std::string();
+ this->LinkType = this->Target->ComputeLinkType(this->Config);
+
+ // Enable debug mode if requested.
+ this->DebugMode = this->Makefile->IsOn("CMAKE_LINK_DEPENDS_DEBUG_MODE");
+
+ // Assume no compatibility until set.
+ this->OldLinkDirMode = false;
+
+ // No computation has been done.
+ this->CCG = 0;
+}
+
+//----------------------------------------------------------------------------
+cmComputeLinkDepends::~cmComputeLinkDepends()
+{
+ for(std::vector<DependSetList*>::iterator
+ i = this->InferredDependSets.begin();
+ i != this->InferredDependSets.end(); ++i)
+ {
+ delete *i;
+ }
+ delete this->CCG;
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::SetOldLinkDirMode(bool b)
+{
+ this->OldLinkDirMode = b;
+}
+
+//----------------------------------------------------------------------------
+std::vector<cmComputeLinkDepends::LinkEntry> const&
+cmComputeLinkDepends::Compute()
+{
+ // Follow the link dependencies of the target to be linked.
+ this->AddDirectLinkEntries();
+
+ // Complete the breadth-first search of dependencies.
+ while(!this->BFSQueue.empty())
+ {
+ // Get the next entry.
+ BFSEntry qe = this->BFSQueue.front();
+ this->BFSQueue.pop();
+
+ // Follow the entry's dependencies.
+ this->FollowLinkEntry(qe);
+ }
+
+ // Complete the search of shared library dependencies.
+ while(!this->SharedDepQueue.empty())
+ {
+ // Handle the next entry.
+ this->HandleSharedDependency(this->SharedDepQueue.front());
+ this->SharedDepQueue.pop();
+ }
+
+ // Infer dependencies of targets for which they were not known.
+ this->InferDependencies();
+
+ // Cleanup the constraint graph.
+ this->CleanConstraintGraph();
+
+ // Display the constraint graph.
+ if(this->DebugMode)
+ {
+ fprintf(stderr,
+ "---------------------------------------"
+ "---------------------------------------\n");
+ fprintf(stderr, "Link dependency analysis for target %s, config %s\n",
+ this->Target->GetName().c_str(),
+ this->HasConfig?this->Config.c_str():"noconfig");
+ this->DisplayConstraintGraph();
+ }
+
+ // Compute the final ordering.
+ this->OrderLinkEntires();
+
+ // Compute the final set of link entries.
+ std::set<int> emmitted;
+ for(std::vector<int>::const_iterator li = this->FinalLinkOrder.begin();
+ li != this->FinalLinkOrder.end(); ++li)
+ {
+ int i = *li;
+ LinkEntry const& e = this->EntryList[i];
+ cmTarget const* t = e.Target;
+ // Entries that we know the linker will re-use for symbols
+ // needed by later entries do not need to be repeated.
+ bool uniquify = t && t->GetType() == cmTarget::SHARED_LIBRARY;
+ if(!uniquify || emmitted.insert(i).second)
+ {
+ this->FinalLinkEntries.push_back(e);
+ }
+ }
+
+ // Display the final set.
+ if(this->DebugMode)
+ {
+ this->DisplayFinalEntries();
+ }
+
+ return this->FinalLinkEntries;
+}
+
+//----------------------------------------------------------------------------
+std::map<std::string, int>::iterator
+cmComputeLinkDepends::AllocateLinkEntry(std::string const& item)
+{
+ std::map<std::string, int>::value_type
+ index_entry(item, static_cast<int>(this->EntryList.size()));
+ std::map<std::string, int>::iterator
+ lei = this->LinkEntryIndex.insert(index_entry).first;
+ this->EntryList.push_back(LinkEntry());
+ this->InferredDependSets.push_back(0);
+ this->EntryConstraintGraph.push_back(EdgeList());
+ return lei;
+}
+
+//----------------------------------------------------------------------------
+int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item)
+{
+ // Check if the item entry has already been added.
+ std::map<std::string, int>::iterator lei = this->LinkEntryIndex.find(item);
+ if(lei != this->LinkEntryIndex.end())
+ {
+ // Yes. We do not need to follow the item's dependencies again.
+ return lei->second;
+ }
+
+ // Allocate a spot for the item entry.
+ lei = this->AllocateLinkEntry(item);
+
+ // Initialize the item entry.
+ int index = lei->second;
+ LinkEntry& entry = this->EntryList[index];
+ entry.Item = item;
+ entry.Target = item.Target;
+ entry.IsFlag = (!entry.Target && item[0] == '-' && item[1] != 'l' &&
+ item.substr(0, 10) != "-framework");
+
+ // If the item has dependencies queue it to follow them.
+ if(entry.Target)
+ {
+ // Target dependencies are always known. Follow them.
+ BFSEntry qe = {index, 0};
+ this->BFSQueue.push(qe);
+ }
+ else
+ {
+ // Look for an old-style <item>_LIB_DEPENDS variable.
+ std::string var = entry.Item;
+ var += "_LIB_DEPENDS";
+ if(const char* val = this->Makefile->GetDefinition(var))
+ {
+ // The item dependencies are known. Follow them.
+ BFSEntry qe = {index, val};
+ this->BFSQueue.push(qe);
+ }
+ else if(!entry.IsFlag)
+ {
+ // The item dependencies are not known. We need to infer them.
+ this->InferredDependSets[index] = new DependSetList;
+ }
+ }
+
+ return index;
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::FollowLinkEntry(BFSEntry const& qe)
+{
+ // Get this entry representation.
+ int depender_index = qe.Index;
+ LinkEntry const& entry = this->EntryList[depender_index];
+
+ // Follow the item's dependencies.
+ if(entry.Target)
+ {
+ // Follow the target dependencies.
+ if(cmTarget::LinkInterface const* iface =
+ entry.Target->GetLinkInterface(this->Config, this->Target))
+ {
+ const bool isIface =
+ entry.Target->GetType() == cmTarget::INTERFACE_LIBRARY;
+ // This target provides its own link interface information.
+ this->AddLinkEntries(depender_index, iface->Libraries);
+
+ if (isIface)
+ {
+ return;
+ }
+
+ // Handle dependent shared libraries.
+ this->FollowSharedDeps(depender_index, iface);
+
+ // Support for CMP0003.
+ for(std::vector<cmLinkItem>::const_iterator
+ oi = iface->WrongConfigLibraries.begin();
+ oi != iface->WrongConfigLibraries.end(); ++oi)
+ {
+ this->CheckWrongConfigItem(*oi);
+ }
+ }
+ }
+ else
+ {
+ // Follow the old-style dependency list.
+ this->AddVarLinkEntries(depender_index, qe.LibDepends);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmComputeLinkDepends
+::FollowSharedDeps(int depender_index, cmTarget::LinkInterface const* iface,
+ bool follow_interface)
+{
+ // Follow dependencies if we have not followed them already.
+ if(this->SharedDepFollowed.insert(depender_index).second)
+ {
+ if(follow_interface)
+ {
+ this->QueueSharedDependencies(depender_index, iface->Libraries);
+ }
+ this->QueueSharedDependencies(depender_index, iface->SharedDeps);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmComputeLinkDepends
+::QueueSharedDependencies(int depender_index,
+ std::vector<cmLinkItem> const& deps)
+{
+ for(std::vector<cmLinkItem>::const_iterator li = deps.begin();
+ li != deps.end(); ++li)
+ {
+ SharedDepEntry qe;
+ qe.Item = *li;
+ qe.DependerIndex = depender_index;
+ this->SharedDepQueue.push(qe);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
+{
+ // Check if the target already has an entry.
+ std::map<std::string, int>::iterator lei =
+ this->LinkEntryIndex.find(dep.Item);
+ if(lei == this->LinkEntryIndex.end())
+ {
+ // Allocate a spot for the item entry.
+ lei = this->AllocateLinkEntry(dep.Item);
+
+ // Initialize the item entry.
+ LinkEntry& entry = this->EntryList[lei->second];
+ entry.Item = dep.Item;
+ entry.Target = dep.Item.Target;
+
+ // This item was added specifically because it is a dependent
+ // shared library. It may get special treatment
+ // in cmComputeLinkInformation.
+ entry.IsSharedDep = true;
+ }
+
+ // Get the link entry for this target.
+ int index = lei->second;
+ LinkEntry& entry = this->EntryList[index];
+
+ // This shared library dependency must follow the item that listed
+ // it.
+ this->EntryConstraintGraph[dep.DependerIndex].push_back(index);
+
+ // Target items may have their own dependencies.
+ if(entry.Target)
+ {
+ if(cmTarget::LinkInterface const* iface =
+ entry.Target->GetLinkInterface(this->Config, this->Target))
+ {
+ // Follow public and private dependencies transitively.
+ this->FollowSharedDeps(index, iface, true);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::AddVarLinkEntries(int depender_index,
+ const char* value)
+{
+ // This is called to add the dependencies named by
+ // <item>_LIB_DEPENDS. The variable contains a semicolon-separated
+ // list. The list contains link-type;item pairs and just items.
+ std::vector<std::string> deplist;
+ cmSystemTools::ExpandListArgument(value, deplist);
+
+ // Look for entries meant for this configuration.
+ std::vector<cmLinkItem> actual_libs;
+ cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
+ bool haveLLT = false;
+ for(std::vector<std::string>::const_iterator di = deplist.begin();
+ di != deplist.end(); ++di)
+ {
+ if(*di == "debug")
+ {
+ llt = cmTarget::DEBUG;
+ haveLLT = true;
+ }
+ else if(*di == "optimized")
+ {
+ llt = cmTarget::OPTIMIZED;
+ haveLLT = true;
+ }
+ else if(*di == "general")
+ {
+ llt = cmTarget::GENERAL;
+ haveLLT = true;
+ }
+ else if(!di->empty())
+ {
+ // If no explicit link type was given prior to this entry then
+ // check if the entry has its own link type variable. This is
+ // needed for compatibility with dependency files generated by
+ // the export_library_dependencies command from CMake 2.4 and
+ // lower.
+ if(!haveLLT)
+ {
+ std::string var = *di;
+ var += "_LINK_TYPE";
+ if(const char* val = this->Makefile->GetDefinition(var))
+ {
+ if(strcmp(val, "debug") == 0)
+ {
+ llt = cmTarget::DEBUG;
+ }
+ else if(strcmp(val, "optimized") == 0)
+ {
+ llt = cmTarget::OPTIMIZED;
+ }
+ }
+ }
+
+ // If the library is meant for this link type then use it.
+ if(llt == cmTarget::GENERAL || llt == this->LinkType)
+ {
+ cmLinkItem item(*di, this->FindTargetToLink(depender_index, *di));
+ actual_libs.push_back(item);
+ }
+ else if(this->OldLinkDirMode)
+ {
+ cmLinkItem item(*di, this->FindTargetToLink(depender_index, *di));
+ this->CheckWrongConfigItem(item);
+ }
+
+ // Reset the link type until another explicit type is given.
+ llt = cmTarget::GENERAL;
+ haveLLT = false;
+ }
+ }
+
+ // Add the entries from this list.
+ this->AddLinkEntries(depender_index, actual_libs);
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::AddDirectLinkEntries()
+{
+ // Add direct link dependencies in this configuration.
+ cmTarget::LinkImplementation const* impl =
+ this->Target->GetLinkImplementation(this->Config);
+ this->AddLinkEntries(-1, impl->Libraries);
+ for(std::vector<cmLinkItem>::const_iterator
+ wi = impl->WrongConfigLibraries.begin();
+ wi != impl->WrongConfigLibraries.end(); ++wi)
+ {
+ this->CheckWrongConfigItem(*wi);
+ }
+}
+
+//----------------------------------------------------------------------------
+template <typename T>
+void
+cmComputeLinkDepends::AddLinkEntries(
+ int depender_index, std::vector<T> const& libs)
+{
+ // Track inferred dependency sets implied by this list.
+ std::map<int, DependSet> dependSets;
+
+ // Loop over the libraries linked directly by the depender.
+ for(typename std::vector<T>::const_iterator li = libs.begin();
+ li != libs.end(); ++li)
+ {
+ // Skip entries that will resolve to the target getting linked or
+ // are empty.
+ cmLinkItem const& item = *li;
+ if(item == this->Target->GetName() || item.empty())
+ {
+ continue;
+ }
+
+ // Add a link entry for this item.
+ int dependee_index = this->AddLinkEntry(*li);
+
+ // The dependee must come after the depender.
+ if(depender_index >= 0)
+ {
+ this->EntryConstraintGraph[depender_index].push_back(dependee_index);
+ }
+ else
+ {
+ // This is a direct dependency of the target being linked.
+ this->OriginalEntries.push_back(dependee_index);
+ }
+
+ // Update the inferred dependencies for earlier items.
+ for(std::map<int, DependSet>::iterator dsi = dependSets.begin();
+ dsi != dependSets.end(); ++dsi)
+ {
+ // Add this item to the inferred dependencies of other items.
+ // Target items are never inferred dependees because unknown
+ // items are outside libraries that should not be depending on
+ // targets.
+ if(!this->EntryList[dependee_index].Target &&
+ !this->EntryList[dependee_index].IsFlag &&
+ dependee_index != dsi->first)
+ {
+ dsi->second.insert(dependee_index);
+ }
+ }
+
+ // If this item needs to have dependencies inferred, do so.
+ if(this->InferredDependSets[dependee_index])
+ {
+ // Make sure an entry exists to hold the set for the item.
+ dependSets[dependee_index];
+ }
+ }
+
+ // Store the inferred dependency sets discovered for this list.
+ for(std::map<int, DependSet>::iterator dsi = dependSets.begin();
+ dsi != dependSets.end(); ++dsi)
+ {
+ this->InferredDependSets[dsi->first]->push_back(dsi->second);
+ }
+}
+
+//----------------------------------------------------------------------------
+cmTarget 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;
+ if(depender_index >= 0)
+ {
+ if(cmTarget const* depender = this->EntryList[depender_index].Target)
+ {
+ from = depender;
+ }
+ }
+ return from->FindTargetToLink(name);
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::InferDependencies()
+{
+ // The inferred dependency sets for each item list the possible
+ // dependencies. The intersection of the sets for one item form its
+ // inferred dependencies.
+ for(unsigned int depender_index=0;
+ depender_index < this->InferredDependSets.size(); ++depender_index)
+ {
+ // Skip items for which dependencies do not need to be inferred or
+ // for which the inferred dependency sets are empty.
+ DependSetList* sets = this->InferredDependSets[depender_index];
+ if(!sets || sets->empty())
+ {
+ continue;
+ }
+
+ // Intersect the sets for this item.
+ DependSetList::const_iterator i = sets->begin();
+ DependSet common = *i;
+ for(++i; i != sets->end(); ++i)
+ {
+ DependSet intersection;
+ cmsys_stl::set_intersection
+ (common.begin(), common.end(), i->begin(), i->end(),
+ std::inserter(intersection, intersection.begin()));
+ common = intersection;
+ }
+
+ // Add the inferred dependencies to the graph.
+ for(DependSet::const_iterator j = common.begin(); j != common.end(); ++j)
+ {
+ int dependee_index = *j;
+ this->EntryConstraintGraph[depender_index].push_back(dependee_index);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::CleanConstraintGraph()
+{
+ for(Graph::iterator i = this->EntryConstraintGraph.begin();
+ i != this->EntryConstraintGraph.end(); ++i)
+ {
+ // Sort the outgoing edges for each graph node so that the
+ // original order will be preserved as much as possible.
+ cmsys_stl::sort(i->begin(), i->end());
+
+ // Make the edge list unique.
+ EdgeList::iterator last = cmsys_stl::unique(i->begin(), i->end());
+ i->erase(last, i->end());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::DisplayConstraintGraph()
+{
+ // Display the graph nodes and their edges.
+ cmOStringStream e;
+ for(unsigned int i=0; i < this->EntryConstraintGraph.size(); ++i)
+ {
+ EdgeList const& nl = this->EntryConstraintGraph[i];
+ e << "item " << i << " is [" << this->EntryList[i].Item << "]\n";
+ for(EdgeList::const_iterator j = nl.begin(); j != nl.end(); ++j)
+ {
+ e << " item " << *j << " must follow it\n";
+ }
+ }
+ fprintf(stderr, "%s\n", e.str().c_str());
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::OrderLinkEntires()
+{
+ // Compute the DAG of strongly connected components. The algorithm
+ // used by cmComputeComponentGraph should identify the components in
+ // the same order in which the items were originally discovered in
+ // the BFS. This should preserve the original order when no
+ // constraints disallow it.
+ this->CCG = new cmComputeComponentGraph(this->EntryConstraintGraph);
+
+ // The component graph is guaranteed to be acyclic. Start a DFS
+ // from every entry to compute a topological order for the
+ // components.
+ Graph const& cgraph = this->CCG->GetComponentGraph();
+ int n = static_cast<int>(cgraph.size());
+ this->ComponentVisited.resize(cgraph.size(), 0);
+ this->ComponentOrder.resize(cgraph.size(), n);
+ this->ComponentOrderId = n;
+ // Run in reverse order so the topological order will preserve the
+ // original order where there are no constraints.
+ for(int c = n-1; c >= 0; --c)
+ {
+ this->VisitComponent(c);
+ }
+
+ // Display the component graph.
+ if(this->DebugMode)
+ {
+ this->DisplayComponents();
+ }
+
+ // Start with the original link line.
+ for(std::vector<int>::const_iterator i = this->OriginalEntries.begin();
+ i != this->OriginalEntries.end(); ++i)
+ {
+ this->VisitEntry(*i);
+ }
+
+ // Now explore anything left pending. Since the component graph is
+ // guaranteed to be acyclic we know this will terminate.
+ while(!this->PendingComponents.empty())
+ {
+ // Visit one entry from the first pending component. The visit
+ // logic will update the pending components accordingly. Since
+ // the pending components are kept in topological order this will
+ // not repeat one.
+ int e = *this->PendingComponents.begin()->second.Entries.begin();
+ this->VisitEntry(e);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmComputeLinkDepends::DisplayComponents()
+{
+ fprintf(stderr, "The strongly connected components are:\n");
+ std::vector<NodeList> const& components = this->CCG->GetComponents();
+ for(unsigned int c=0; c < components.size(); ++c)
+ {
+ fprintf(stderr, "Component (%u):\n", c);
+ NodeList const& nl = components[c];
+ for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
+ {
+ int i = *ni;
+ fprintf(stderr, " item %d [%s]\n", i,
+ this->EntryList[i].Item.c_str());
+ }
+ EdgeList const& ol = this->CCG->GetComponentGraphEdges(c);
+ for(EdgeList::const_iterator oi = ol.begin(); oi != ol.end(); ++oi)
+ {
+ int i = *oi;
+ fprintf(stderr, " followed by Component (%d)\n", i);
+ }
+ fprintf(stderr, " topo order index %d\n",
+ this->ComponentOrder[c]);
+ }
+ fprintf(stderr, "\n");
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::VisitComponent(unsigned int c)
+{
+ // Check if the node has already been visited.
+ if(this->ComponentVisited[c])
+ {
+ return;
+ }
+
+ // We are now visiting this component so mark it.
+ this->ComponentVisited[c] = 1;
+
+ // Visit the neighbors of the component first.
+ // Run in reverse order so the topological order will preserve the
+ // original order where there are no constraints.
+ EdgeList const& nl = this->CCG->GetComponentGraphEdges(c);
+ for(EdgeList::const_reverse_iterator ni = nl.rbegin();
+ ni != nl.rend(); ++ni)
+ {
+ this->VisitComponent(*ni);
+ }
+
+ // Assign an ordering id to this component.
+ this->ComponentOrder[c] = --this->ComponentOrderId;
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::VisitEntry(int index)
+{
+ // Include this entry on the link line.
+ this->FinalLinkOrder.push_back(index);
+
+ // This entry has now been seen. Update its component.
+ bool completed = false;
+ int component = this->CCG->GetComponentMap()[index];
+ std::map<int, PendingComponent>::iterator mi =
+ this->PendingComponents.find(this->ComponentOrder[component]);
+ if(mi != this->PendingComponents.end())
+ {
+ // The entry is in an already pending component.
+ PendingComponent& pc = mi->second;
+
+ // Remove the entry from those pending in its component.
+ pc.Entries.erase(index);
+ if(pc.Entries.empty())
+ {
+ // The complete component has been seen since it was last needed.
+ --pc.Count;
+
+ if(pc.Count == 0)
+ {
+ // The component has been completed.
+ this->PendingComponents.erase(mi);
+ completed = true;
+ }
+ else
+ {
+ // The whole component needs to be seen again.
+ NodeList const& nl = this->CCG->GetComponent(component);
+ assert(nl.size() > 1);
+ pc.Entries.insert(nl.begin(), nl.end());
+ }
+ }
+ }
+ else
+ {
+ // The entry is not in an already pending component.
+ NodeList const& nl = this->CCG->GetComponent(component);
+ if(nl.size() > 1)
+ {
+ // This is a non-trivial component. It is now pending.
+ PendingComponent& pc = this->MakePendingComponent(component);
+
+ // The starting entry has already been seen.
+ pc.Entries.erase(index);
+ }
+ else
+ {
+ // This is a trivial component, so it is already complete.
+ completed = true;
+ }
+ }
+
+ // If the entry completed a component, the component's dependencies
+ // are now pending.
+ if(completed)
+ {
+ EdgeList const& ol = this->CCG->GetComponentGraphEdges(component);
+ for(EdgeList::const_iterator oi = ol.begin(); oi != ol.end(); ++oi)
+ {
+ // This entire component is now pending no matter whether it has
+ // been partially seen already.
+ this->MakePendingComponent(*oi);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+cmComputeLinkDepends::PendingComponent&
+cmComputeLinkDepends::MakePendingComponent(unsigned int component)
+{
+ // Create an entry (in topological order) for the component.
+ PendingComponent& pc =
+ this->PendingComponents[this->ComponentOrder[component]];
+ pc.Id = component;
+ NodeList const& nl = this->CCG->GetComponent(component);
+
+ if(nl.size() == 1)
+ {
+ // Trivial components need be seen only once.
+ pc.Count = 1;
+ }
+ else
+ {
+ // This is a non-trivial strongly connected component of the
+ // original graph. It consists of two or more libraries
+ // (archives) that mutually require objects from one another. In
+ // the worst case we may have to repeat the list of libraries as
+ // many times as there are object files in the biggest archive.
+ // For now we just list them twice.
+ //
+ // The list of items in the component has been sorted by the order
+ // of discovery in the original BFS of dependencies. This has the
+ // advantage that the item directly linked by a target requiring
+ // this component will come first which minimizes the number of
+ // repeats needed.
+ pc.Count = this->ComputeComponentCount(nl);
+ }
+
+ // Store the entries to be seen.
+ pc.Entries.insert(nl.begin(), nl.end());
+
+ return pc;
+}
+
+//----------------------------------------------------------------------------
+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(cmTarget::LinkInterface const* iface =
+ target->GetLinkInterface(this->Config, this->Target))
+ {
+ if(iface->Multiplicity > count)
+ {
+ count = iface->Multiplicity;
+ }
+ }
+ }
+ }
+ return count;
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::DisplayFinalEntries()
+{
+ fprintf(stderr, "target [%s] links to:\n", this->Target->GetName().c_str());
+ for(std::vector<LinkEntry>::const_iterator lei =
+ this->FinalLinkEntries.begin();
+ lei != this->FinalLinkEntries.end(); ++lei)
+ {
+ if(lei->Target)
+ {
+ fprintf(stderr, " target [%s]\n", lei->Target->GetName().c_str());
+ }
+ else
+ {
+ fprintf(stderr, " item [%s]\n", lei->Item.c_str());
+ }
+ }
+ fprintf(stderr, "\n");
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkDepends::CheckWrongConfigItem(cmLinkItem const& item)
+{
+ if(!this->OldLinkDirMode)
+ {
+ return;
+ }
+
+ // For CMake 2.4 bug-compatibility we need to consider the output
+ // directories of targets linked in another configuration as link
+ // directories.
+ if(item.Target && !item.Target->IsImported())
+ {
+ this->OldWrongConfigItems.insert(item.Target);
+ }
+}
diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h
new file mode 100644
index 0000000000..a931726d9b
--- /dev/null
+++ b/Source/cmComputeLinkDepends.h
@@ -0,0 +1,170 @@
+/*============================================================================
+ 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 cmComputeLinkDepends_h
+#define cmComputeLinkDepends_h
+
+#include "cmStandardIncludes.h"
+#include "cmTarget.h"
+
+#include "cmGraphAdjacencyList.h"
+
+#include <queue>
+
+class cmComputeComponentGraph;
+class cmGlobalGenerator;
+class cmLocalGenerator;
+class cmMakefile;
+class cmTarget;
+class cmake;
+
+/** \class cmComputeLinkDepends
+ * \brief Compute link dependencies for targets.
+ */
+class cmComputeLinkDepends
+{
+public:
+ cmComputeLinkDepends(cmTarget const* target, const std::string& config);
+ ~cmComputeLinkDepends();
+
+ // Basic information about each link item.
+ struct LinkEntry
+ {
+ std::string Item;
+ cmTarget const* Target;
+ bool IsSharedDep;
+ bool IsFlag;
+ LinkEntry(): Item(), Target(0), IsSharedDep(false), IsFlag(false) {}
+ LinkEntry(LinkEntry const& r):
+ Item(r.Item), Target(r.Target), IsSharedDep(r.IsSharedDep),
+ IsFlag(r.IsFlag) {}
+ };
+
+ typedef std::vector<LinkEntry> EntryVector;
+ EntryVector const& Compute();
+
+ void SetOldLinkDirMode(bool b);
+ std::set<cmTarget const*> const& GetOldWrongConfigItems() const
+ { return this->OldWrongConfigItems; }
+
+private:
+
+ // Context information.
+ cmTarget const* Target;
+ cmMakefile* Makefile;
+ cmLocalGenerator* LocalGenerator;
+ cmGlobalGenerator const* GlobalGenerator;
+ cmake* CMakeInstance;
+ bool DebugMode;
+
+ // Configuration information.
+ bool HasConfig;
+ std::string Config;
+ cmTarget::LinkLibraryType LinkType;
+
+ // Output information.
+ EntryVector FinalLinkEntries;
+
+ typedef cmTarget::LinkLibraryVectorType LinkLibraryVectorType;
+
+ std::map<std::string, int>::iterator
+ AllocateLinkEntry(std::string const& item);
+ int AddLinkEntry(cmLinkItem const& item);
+ void AddVarLinkEntries(int depender_index, const char* value);
+ 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);
+
+ // One entry for each unique item.
+ std::vector<LinkEntry> EntryList;
+ std::map<std::string, int> LinkEntryIndex;
+
+ // BFS of initial dependencies.
+ struct BFSEntry
+ {
+ int Index;
+ const char* LibDepends;
+ };
+ std::queue<BFSEntry> BFSQueue;
+ void FollowLinkEntry(BFSEntry const&);
+
+ // Shared libraries that are included only because they are
+ // dependencies of other shared libraries, not because they are part
+ // of the interface.
+ struct SharedDepEntry
+ {
+ cmLinkItem Item;
+ int DependerIndex;
+ };
+ std::queue<SharedDepEntry> SharedDepQueue;
+ std::set<int> SharedDepFollowed;
+ void FollowSharedDeps(int depender_index,
+ cmTarget::LinkInterface const* iface,
+ bool follow_interface = false);
+ void QueueSharedDependencies(int depender_index,
+ std::vector<cmLinkItem> const& deps);
+ void HandleSharedDependency(SharedDepEntry const& dep);
+
+ // Dependency inferral for each link item.
+ struct DependSet: public std::set<int> {};
+ struct DependSetList: public std::vector<DependSet> {};
+ std::vector<DependSetList*> InferredDependSets;
+ void InferDependencies();
+
+ // Ordering constraint graph adjacency list.
+ typedef cmGraphNodeList NodeList;
+ typedef cmGraphEdgeList EdgeList;
+ typedef cmGraphAdjacencyList Graph;
+ Graph EntryConstraintGraph;
+ void CleanConstraintGraph();
+ void DisplayConstraintGraph();
+
+ // Ordering algorithm.
+ void OrderLinkEntires();
+ std::vector<char> ComponentVisited;
+ std::vector<int> ComponentOrder;
+ int ComponentOrderId;
+ struct PendingComponent
+ {
+ // The real component id. Needed because the map is indexed by
+ // component topological index.
+ int Id;
+
+ // The number of times the component needs to be seen. This is
+ // always 1 for trivial components and is initially 2 for
+ // non-trivial components.
+ int Count;
+
+ // The entries yet to be seen to complete the component.
+ std::set<int> Entries;
+ };
+ std::map<int, PendingComponent> PendingComponents;
+ cmComputeComponentGraph* CCG;
+ std::vector<int> FinalLinkOrder;
+ void DisplayComponents();
+ void VisitComponent(unsigned int c);
+ void VisitEntry(int index);
+ PendingComponent& MakePendingComponent(unsigned int component);
+ int ComputeComponentCount(NodeList const& nl);
+ void DisplayFinalEntries();
+
+ // Record of the original link line.
+ std::vector<int> OriginalEntries;
+
+ // Compatibility help.
+ bool OldLinkDirMode;
+ void CheckWrongConfigItem(cmLinkItem const& item);
+ std::set<cmTarget const*> OldWrongConfigItems;
+};
+
+#endif
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx
new file mode 100644
index 0000000000..e1852a3601
--- /dev/null
+++ b/Source/cmComputeLinkInformation.cxx
@@ -0,0 +1,2046 @@
+/*============================================================================
+ 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 "cmComputeLinkInformation.h"
+
+#include "cmComputeLinkDepends.h"
+#include "cmOrderDirectories.h"
+
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmTarget.h"
+#include "cmake.h"
+
+#include <ctype.h>
+
+//#define CM_COMPUTE_LINK_INFO_DEBUG
+
+/*
+Notes about linking on various platforms:
+
+------------------------------------------------------------------------------
+
+Linux, FreeBSD, Mac OS X, IRIX, Sun, Windows:
+
+Linking to libraries using the full path works fine.
+
+------------------------------------------------------------------------------
+
+On AIX, more work is needed.
+
+ The "-bnoipath" option is needed. From "man ld":
+
+ Note: If you specify a shared object, or an archive file
+ containing a shared object, with an absolute or relative path
+ name, instead of with the -lName flag, the path name is
+ included in the import file ID string in the loader section of
+ the output file. You can override this behavior with the
+ -bnoipath option.
+
+ noipath
+
+ For shared objects listed on the command-line, rather than
+ specified with the -l flag, use a null path component when
+ listing the shared object in the loader section of the
+ output file. A null path component is always used for
+ shared objects specified with the -l flag. This option
+ does not affect the specification of a path component by
+ using a line beginning with #! in an import file. The
+ default is the ipath option.
+
+ This prevents the full path specified on the compile line from being
+ compiled directly into the binary.
+
+ By default the linker places -L paths in the embedded runtime path.
+ In order to implement CMake's RPATH interface correctly, we need the
+ -blibpath:Path option. From "man ld":
+
+ libpath:Path
+
+ Uses Path as the library path when writing the loader section
+ of the output file. Path is neither checked for validity nor
+ used when searching for libraries specified by the -l flag.
+ Path overrides any library paths generated when the -L flag is
+ used.
+
+ If you do not specify any -L flags, or if you specify the
+ nolibpath option, the default library path information is
+ written in the loader section of the output file. The default
+ library path information is the value of the LIBPATH
+ environment variable if it is defined, and /usr/lib:/lib,
+ otherwise.
+
+ We can pass -Wl,-blibpath:/usr/lib:/lib always to avoid the -L stuff
+ and not break when the user sets LIBPATH. Then if we want to add an
+ rpath we insert it into the option before /usr/lib.
+
+------------------------------------------------------------------------------
+
+On HP-UX, more work is needed. There are differences between
+versions.
+
+ld: 92453-07 linker linker ld B.10.33 990520
+
+ Linking with a full path works okay for static and shared libraries.
+ The linker seems to always put the full path to where the library
+ was found in the binary whether using a full path or -lfoo syntax.
+ Transitive link dependencies work just fine due to the full paths.
+
+ It has the "-l:libfoo.sl" option. The +nodefaultrpath is accepted
+ but not documented and does not seem to do anything. There is no
+ +forceload option.
+
+ld: 92453-07 linker ld HP Itanium(R) B.12.41 IPF/IPF
+
+ Linking with a full path works okay for static libraries.
+
+ Linking with a full path works okay for shared libraries. However
+ dependent (transitive) libraries of those linked directly must be
+ either found with an rpath stored in the direct dependencies or
+ found in -L paths as if they were specified with "-l:libfoo.sl"
+ (really "-l:<soname>"). The search matches that of the dynamic
+ loader but only with -L paths. In other words, if we have an
+ executable that links to shared library bar which links to shared
+ library foo, the link line for the exe must contain
+
+ /dir/with/bar/libbar.sl -L/dir/with/foo
+
+ It does not matter whether the exe wants to link to foo directly or
+ whether /dir/with/foo/libfoo.sl is listed. The -L path must still
+ be present. It should match the runtime path computed for the
+ executable taking all directly and transitively linked libraries
+ into account.
+
+ The "+nodefaultrpath" option should be used to avoid getting -L
+ paths in the rpath unless we add our own rpath with +b. This means
+ that skip-build-rpath should use this option.
+
+ See documentation in "man ld", "man dld.so", and
+ http://docs.hp.com/en/B2355-90968/creatingandusinglibraries.htm
+
+ +[no]defaultrpath
+ +defaultrpath is the default. Include any paths that are
+ specified with -L in the embedded path, unless you specify the
+ +b option. If you use +b, only the path list specified by +b is
+ in the embedded path.
+
+ The +nodefaultrpath option removes all library paths that were
+ specified with the -L option from the embedded path. The linker
+ searches the library paths specified by the -L option at link
+ time. At run time, the only library paths searched are those
+ specified by the environment variables LD_LIBRARY_PATH and
+ SHLIB_PATH, library paths specified by the +b linker option, and
+ finally the default library paths.
+
+ +rpathfirst
+ This option will cause the paths specified in RPATH (embedded
+ path) to be used before the paths specified in LD_LIBRARY_PATH
+ or SHLIB_PATH, in searching for shared libraries. This changes
+ the default search order of LD_LIBRARY_PATH, SHLIB_PATH, and
+ RPATH (embedded path).
+
+------------------------------------------------------------------------------
+Notes about dependent (transitive) shared libraries:
+
+On non-Windows systems shared libraries may have transitive
+dependencies. In order to support LINK_INTERFACE_LIBRARIES we must
+support linking to a shared library without listing all the libraries
+to which it links. Some linkers want to be able to find the
+transitive dependencies (dependent libraries) of shared libraries
+listed on the command line.
+
+ - On Windows, DLLs are not directly linked, and the import libraries
+ have no transitive dependencies.
+
+ - On Mac OS X 10.5 and above transitive dependencies are not needed.
+
+ - On Mac OS X 10.4 and below we need to actually list the dependencies.
+ Otherwise when using -isysroot for universal binaries it cannot
+ find the dependent libraries. Listing them on the command line
+ tells the linker where to find them, but unfortunately also links
+ the library.
+
+ - On HP-UX, the linker wants to find the transitive dependencies of
+ shared libraries in the -L paths even if the dependent libraries
+ are given on the link line.
+
+ - On AIX the transitive dependencies are not needed.
+
+ - On SGI, the linker wants to find the transitive dependencies of
+ shared libraries in the -L paths if they are not given on the link
+ line. Transitive linking can be disabled using the options
+
+ -no_transitive_link -Wl,-no_transitive_link
+
+ which disable it. Both options must be given when invoking the
+ linker through the compiler.
+
+ - On Sun, the linker wants to find the transitive dependencies of
+ shared libraries in the -L paths if they are not given on the link
+ line.
+
+ - On Linux, FreeBSD, and QNX:
+
+ The linker wants to find the transitive dependencies of shared
+ libraries in the "-rpath-link" paths option if they have not been
+ given on the link line. The option is like rpath but just for
+ link time:
+
+ -Wl,-rpath-link,"/path1:/path2"
+
+For -rpath-link, we need a separate runtime path ordering pass
+including just the dependent libraries that are not linked.
+
+For -L paths on non-HP, we can do the same thing as with rpath-link
+but put the results in -L paths. The paths should be listed at the
+end to avoid conflicting with user search paths (?).
+
+For -L paths on HP, we should do a runtime path ordering pass with
+all libraries, both linked and non-linked. Even dependent
+libraries that are also linked need to be listed in -L paths.
+
+In our implementation we add all dependent libraries to the runtime
+path computation. Then the auto-generated RPATH will find everything.
+
+------------------------------------------------------------------------------
+Notes about shared libraries with not builtin soname:
+
+Some UNIX shared libraries may be created with no builtin soname. On
+some platforms such libraries cannot be linked using the path to their
+location because the linker will copy the path into the field used to
+find the library at runtime.
+
+ Apple: ../libfoo.dylib ==> libfoo.dylib # ok, uses install_name
+ SGI: ../libfoo.so ==> libfoo.so # ok
+ AIX: ../libfoo.so ==> libfoo.so # ok
+ Linux: ../libfoo.so ==> ../libfoo.so # bad
+ HP-UX: ../libfoo.so ==> ../libfoo.so # bad
+ Sun: ../libfoo.so ==> ../libfoo.so # bad
+ FreeBSD: ../libfoo.so ==> ../libfoo.so # bad
+
+In order to link these libraries we need to use the old-style split
+into -L.. and -lfoo options. This should be fairly safe because most
+problems with -lfoo options were related to selecting shared libraries
+instead of static but in this case we want the shared lib. Link
+directory ordering needs to be done to make sure these shared
+libraries are found first. There should be very few restrictions
+because this need be done only for shared libraries without soname-s.
+
+*/
+
+//----------------------------------------------------------------------------
+cmComputeLinkInformation
+::cmComputeLinkInformation(cmTarget const* target, const std::string& config)
+{
+ // Store context information.
+ this->Target = target;
+ this->Makefile = this->Target->GetMakefile();
+ this->LocalGenerator = this->Makefile->GetLocalGenerator();
+ this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
+ this->CMakeInstance = this->GlobalGenerator->GetCMakeInstance();
+
+ // Check whether to recognize OpenBSD-style library versioned names.
+ this->OpenBSD = this->Makefile->GetCMakeInstance()
+ ->GetPropertyAsBool("FIND_LIBRARY_USE_OPENBSD_VERSIONING");
+
+ // The configuration being linked.
+ this->Config = config;
+
+ // Allocate internals.
+ this->OrderLinkerSearchPath =
+ new cmOrderDirectories(this->GlobalGenerator, target,
+ "linker search path");
+ this->OrderRuntimeSearchPath =
+ new cmOrderDirectories(this->GlobalGenerator, target,
+ "runtime search path");
+ this->OrderDependentRPath = 0;
+
+ // Get the language used for linking this target.
+ this->LinkLanguage = this->Target->GetLinkerLanguage(config);
+ if(this->LinkLanguage.empty())
+ {
+ // The Compute method will do nothing, so skip the rest of the
+ // initialization.
+ return;
+ }
+
+ // Check whether we should use an import library for linking a target.
+ this->UseImportLibrary =
+ this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")?true:false;
+
+ // Check whether we should skip dependencies on shared library files.
+ this->LinkDependsNoShared =
+ 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->GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ std::string loader_flag_var = "CMAKE_SHARED_MODULE_LOADER_";
+ loader_flag_var += this->LinkLanguage;
+ loader_flag_var += "_FLAG";
+ this->LoaderFlag = this->Makefile->GetDefinition(loader_flag_var);
+ }
+
+ // Get options needed to link libraries.
+ this->LibLinkFlag =
+ this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG");
+ this->LibLinkFileFlag =
+ this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FILE_FLAG");
+ this->LibLinkSuffix =
+ this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX");
+
+ // Get options needed to specify RPATHs.
+ this->RuntimeUseChrpath = false;
+ if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
+ {
+ const char* tType =
+ ((this->Target->GetType() == cmTarget::EXECUTABLE)?
+ "EXECUTABLE" : "SHARED_LIBRARY");
+ std::string rtVar = "CMAKE_";
+ rtVar += tType;
+ rtVar += "_RUNTIME_";
+ rtVar += this->LinkLanguage;
+ rtVar += "_FLAG";
+ std::string rtSepVar = rtVar + "_SEP";
+ this->RuntimeFlag = this->Makefile->GetSafeDefinition(rtVar);
+ this->RuntimeSep = this->Makefile->GetSafeDefinition(rtSepVar);
+ this->RuntimeAlways =
+ (this->Makefile->
+ GetSafeDefinition("CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH"));
+ this->RuntimeUseChrpath = this->Target->IsChrpathUsed(config);
+
+ // Get options needed to help find dependent libraries.
+ std::string rlVar = "CMAKE_";
+ rlVar += tType;
+ rlVar += "_RPATH_LINK_";
+ rlVar += this->LinkLanguage;
+ rlVar += "_FLAG";
+ this->RPathLinkFlag = this->Makefile->GetSafeDefinition(rlVar);
+ }
+
+ // Check if we need to include the runtime search path at link time.
+ {
+ std::string var = "CMAKE_SHARED_LIBRARY_LINK_";
+ var += this->LinkLanguage;
+ var += "_WITH_RUNTIME_PATH";
+ this->LinkWithRuntimePath = this->Makefile->IsOn(var);
+ }
+
+ // Check the platform policy for missing soname case.
+ this->NoSONameUsesPath =
+ this->Makefile->IsOn("CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME");
+
+ // Get link type information.
+ this->ComputeLinkTypeInfo();
+
+ // Setup the link item parser.
+ this->ComputeItemParserInfo();
+
+ // Setup framework support.
+ this->ComputeFrameworkInfo();
+
+ // Choose a mode for dealing with shared library dependencies.
+ this->SharedDependencyMode = SharedDepModeNone;
+ if(this->Makefile->IsOn("CMAKE_LINK_DEPENDENT_LIBRARY_FILES"))
+ {
+ this->SharedDependencyMode = SharedDepModeLink;
+ }
+ else if(this->Makefile->IsOn("CMAKE_LINK_DEPENDENT_LIBRARY_DIRS"))
+ {
+ this->SharedDependencyMode = SharedDepModeLibDir;
+ }
+ else if(!this->RPathLinkFlag.empty())
+ {
+ this->SharedDependencyMode = SharedDepModeDir;
+ this->OrderDependentRPath =
+ new cmOrderDirectories(this->GlobalGenerator, target,
+ "dependent library path");
+ }
+
+ // Add the search path entries requested by the user to path ordering.
+ this->OrderLinkerSearchPath
+ ->AddUserDirectories(this->Target->GetLinkDirectories());
+ this->OrderRuntimeSearchPath
+ ->AddUserDirectories(this->Target->GetLinkDirectories());
+
+ // Set up the implicit link directories.
+ this->LoadImplicitLinkInfo();
+ this->OrderLinkerSearchPath
+ ->SetImplicitDirectories(this->ImplicitLinkDirs);
+ this->OrderRuntimeSearchPath
+ ->SetImplicitDirectories(this->ImplicitLinkDirs);
+ if(this->OrderDependentRPath)
+ {
+ this->OrderDependentRPath
+ ->SetImplicitDirectories(this->ImplicitLinkDirs);
+ this->OrderDependentRPath
+ ->AddLanguageDirectories(this->RuntimeLinkDirs);
+ }
+
+ // Decide whether to enable compatible library search path mode.
+ // There exists code that effectively does
+ //
+ // /path/to/libA.so -lB
+ //
+ // where -lB is meant to link to /path/to/libB.so. This is broken
+ // because it specified -lB without specifying a link directory (-L)
+ // in which to search for B. This worked in CMake 2.4 and below
+ // because -L/path/to would be added by the -L/-l split for A. In
+ // 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->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->GetLinkDirectories();
+ for(std::vector<std::string>::const_iterator di = dirs.begin();
+ di != dirs.end(); ++di)
+ {
+ this->OldLinkDirMask.insert(*di);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+cmComputeLinkInformation::~cmComputeLinkInformation()
+{
+ delete this->OrderLinkerSearchPath;
+ delete this->OrderRuntimeSearchPath;
+ delete this->OrderDependentRPath;
+}
+
+//----------------------------------------------------------------------------
+cmComputeLinkInformation::ItemVector const&
+cmComputeLinkInformation::GetItems()
+{
+ return this->Items;
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string> const& cmComputeLinkInformation::GetDirectories()
+{
+ return this->OrderLinkerSearchPath->GetOrderedDirectories();
+}
+
+//----------------------------------------------------------------------------
+std::string cmComputeLinkInformation::GetRPathLinkString()
+{
+ // If there is no separate linker runtime search flag (-rpath-link)
+ // there is no reason to compute a string.
+ if(!this->OrderDependentRPath)
+ {
+ return "";
+ }
+
+ // Construct the linker runtime search path.
+ std::string rpath_link;
+ const char* sep = "";
+ std::vector<std::string> const& dirs =
+ this->OrderDependentRPath->GetOrderedDirectories();
+ for(std::vector<std::string>::const_iterator di = dirs.begin();
+ di != dirs.end(); ++di)
+ {
+ rpath_link += sep;
+ sep = ":";
+ rpath_link += *di;
+ }
+ return rpath_link;
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string> const& cmComputeLinkInformation::GetDepends()
+{
+ return this->Depends;
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string> const& cmComputeLinkInformation::GetFrameworkPaths()
+{
+ return this->FrameworkPaths;
+}
+
+//----------------------------------------------------------------------------
+std::set<cmTarget const*> const&
+cmComputeLinkInformation::GetSharedLibrariesLinked()
+{
+ return this->SharedLibrariesLinked;
+}
+
+//----------------------------------------------------------------------------
+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))
+ {
+ return false;
+ }
+
+ // We require a link language for the target.
+ if(this->LinkLanguage.empty())
+ {
+ cmSystemTools::
+ Error("CMake can not determine linker language for target: ",
+ this->Target->GetName().c_str());
+ return false;
+ }
+
+ // Compute the ordered link line items.
+ cmComputeLinkDepends cld(this->Target, this->Config);
+ cld.SetOldLinkDirMode(this->OldLinkDirMode);
+ cmComputeLinkDepends::EntryVector const& linkEntries = cld.Compute();
+
+ // Add the link line items.
+ for(cmComputeLinkDepends::EntryVector::const_iterator
+ lei = linkEntries.begin();
+ lei != linkEntries.end(); ++lei)
+ {
+ if(lei->IsSharedDep)
+ {
+ this->AddSharedDepItem(lei->Item, lei->Target);
+ }
+ else
+ {
+ this->AddItem(lei->Item, lei->Target);
+ }
+ }
+
+ // Restore the target link type so the correct system runtime
+ // libraries are found.
+ const char* lss = this->Target->GetProperty("LINK_SEARCH_END_STATIC");
+ if(cmSystemTools::IsOn(lss))
+ {
+ this->SetCurrentLinkType(LinkStatic);
+ }
+ else
+ {
+ this->SetCurrentLinkType(this->StartLinkType);
+ }
+
+ // Finish listing compatibility paths.
+ if(this->OldLinkDirMode)
+ {
+ // 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)
+ {
+ cmTarget const* tgt = *i;
+ bool implib =
+ (this->UseImportLibrary &&
+ (tgt->GetType() == cmTarget::SHARED_LIBRARY));
+ std::string lib = tgt->GetFullPath(this->Config , implib, true);
+ this->OldLinkDirItems.push_back(lib);
+ }
+ }
+
+ // Finish setting up linker search directories.
+ if(!this->FinishLinkerSearchDirectories())
+ {
+ return false;
+ }
+
+ // Add implicit language runtime libraries and directories.
+ this->AddImplicitLinkInfo();
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddImplicitLinkInfo()
+{
+ // The link closure lists all languages whose implicit info is needed.
+ cmTarget::LinkClosure const* lc=this->Target->GetLinkClosure(this->Config);
+ for(std::vector<std::string>::const_iterator li = lc->Languages.begin();
+ li != lc->Languages.end(); ++li)
+ {
+ // Skip those of the linker language. They are implicit.
+ if(*li != this->LinkLanguage)
+ {
+ this->AddImplicitLinkInfo(*li);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang)
+{
+ // Add libraries for this language that are not implied by the
+ // linker language.
+ std::string libVar = "CMAKE_";
+ libVar += lang;
+ libVar += "_IMPLICIT_LINK_LIBRARIES";
+ if(const char* libs = this->Makefile->GetDefinition(libVar))
+ {
+ std::vector<std::string> libsVec;
+ cmSystemTools::ExpandListArgument(libs, libsVec);
+ for(std::vector<std::string>::const_iterator i = libsVec.begin();
+ i != libsVec.end(); ++i)
+ {
+ if(this->ImplicitLinkLibs.find(*i) == this->ImplicitLinkLibs.end())
+ {
+ this->AddItem(*i, 0);
+ }
+ }
+ }
+
+ // Add linker search paths for this language that are not
+ // implied by the linker language.
+ std::string dirVar = "CMAKE_";
+ dirVar += lang;
+ dirVar += "_IMPLICIT_LINK_DIRECTORIES";
+ if(const char* dirs = this->Makefile->GetDefinition(dirVar))
+ {
+ std::vector<std::string> dirsVec;
+ cmSystemTools::ExpandListArgument(dirs, dirsVec);
+ this->OrderLinkerSearchPath->AddLanguageDirectories(dirsVec);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddItem(std::string const& item,
+ cmTarget const* tgt)
+{
+ // Compute the proper name to use to link this library.
+ const std::string& config = this->Config;
+ bool impexe = (tgt && tgt->IsExecutableWithExports());
+ if(impexe && !this->UseImportLibrary && !this->LoaderFlag)
+ {
+ // Skip linking to executables on platforms with no import
+ // libraries or loader flags.
+ return;
+ }
+
+ if(tgt && tgt->IsLinkable())
+ {
+ // This is a CMake target. Ask the target for its real name.
+ if(impexe && this->LoaderFlag)
+ {
+ // This link item is an executable that may provide symbols
+ // used by this target. A special flag is needed on this
+ // platform. Add it now.
+ std::string linkItem;
+ linkItem = this->LoaderFlag;
+ 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
+ {
+ // Decide whether to use an import library.
+ bool implib =
+ (this->UseImportLibrary &&
+ (impexe || tgt->GetType() == cmTarget::SHARED_LIBRARY));
+
+ if(tgt->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ this->Items.push_back(Item(std::string(), true, tgt));
+ return;
+ }
+ // Pass the full path to the target file.
+ std::string lib = tgt->GetFullPath(config, implib, true);
+ if(!this->LinkDependsNoShared ||
+ tgt->GetType() != cmTarget::SHARED_LIBRARY)
+ {
+ this->Depends.push_back(lib);
+ }
+
+ this->AddTargetItem(lib, tgt);
+ this->AddLibraryRuntimeInfo(lib, tgt);
+ }
+ }
+ else
+ {
+ // This is not a CMake target. Use the name given.
+ if(cmSystemTools::FileIsFullPath(item.c_str()))
+ {
+ if(cmSystemTools::FileIsDirectory(item.c_str()))
+ {
+ // This is a directory.
+ this->AddDirectoryItem(item);
+ }
+ else
+ {
+ // Use the full path given to the library file.
+ this->Depends.push_back(item);
+ this->AddFullItem(item);
+ this->AddLibraryRuntimeInfo(item);
+ }
+ }
+ else
+ {
+ // This is a library or option specified by the user.
+ this->AddUserItem(item, true);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
+ cmTarget const* tgt)
+{
+ // If dropping shared library dependencies, ignore them.
+ if(this->SharedDependencyMode == SharedDepModeNone)
+ {
+ return;
+ }
+
+ // The user may have incorrectly named an item. Skip items that are
+ // not full paths to shared libraries.
+ if(tgt)
+ {
+ // The target will provide a full path. Make sure it is a shared
+ // library.
+ if(tgt->GetType() != cmTarget::SHARED_LIBRARY)
+ {
+ return;
+ }
+ }
+ else
+ {
+ // Skip items that are not full paths. We will not be able to
+ // reliably specify them.
+ if(!cmSystemTools::FileIsFullPath(item.c_str()))
+ {
+ return;
+ }
+
+ // Get the name of the library from the file name.
+ std::string file = cmSystemTools::GetFilenameName(item);
+ if(!this->ExtractSharedLibraryName.find(file.c_str()))
+ {
+ // This is not the name of a shared library.
+ return;
+ }
+ }
+
+ // If in linking mode, just link to the shared library.
+ if(this->SharedDependencyMode == SharedDepModeLink)
+ {
+ this->AddItem(item, tgt);
+ return;
+ }
+
+ // 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)
+ {
+ lib = tgt->GetFullPath(this->Config, this->UseImportLibrary);
+ this->AddLibraryRuntimeInfo(lib, tgt);
+ }
+ else
+ {
+ lib = item;
+ this->AddLibraryRuntimeInfo(lib);
+ }
+
+ // Check if we need to include the dependent shared library in other
+ // path ordering.
+ cmOrderDirectories* order = 0;
+ if(this->SharedDependencyMode == SharedDepModeLibDir &&
+ !this->LinkWithRuntimePath /* AddLibraryRuntimeInfo adds it */)
+ {
+ // Add the item to the linker search path.
+ order = this->OrderLinkerSearchPath;
+ }
+ else if(this->SharedDependencyMode == SharedDepModeDir)
+ {
+ // Add the item to the separate dependent library search path.
+ order = this->OrderDependentRPath;
+ }
+ if(order)
+ {
+ if(tgt)
+ {
+ std::string soName = tgt->GetSOName(this->Config);
+ const char* soname = soName.empty()? 0 : soName.c_str();
+ order->AddRuntimeLibrary(lib, soname);
+ }
+ else
+ {
+ order->AddRuntimeLibrary(lib);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::ComputeLinkTypeInfo()
+{
+ // Check whether archives may actually be shared libraries.
+ this->ArchivesMayBeShared =
+ this->CMakeInstance->GetPropertyAsBool(
+ "TARGET_ARCHIVES_MAY_BE_SHARED_LIBS");
+
+ // First assume we cannot do link type stuff.
+ this->LinkTypeEnabled = false;
+
+ // Lookup link type selection flags.
+ const char* static_link_type_flag = 0;
+ const char* shared_link_type_flag = 0;
+ 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;
+ default: break;
+ }
+ if(target_type_str)
+ {
+ std::string static_link_type_flag_var = "CMAKE_";
+ static_link_type_flag_var += target_type_str;
+ static_link_type_flag_var += "_LINK_STATIC_";
+ static_link_type_flag_var += this->LinkLanguage;
+ static_link_type_flag_var += "_FLAGS";
+ static_link_type_flag =
+ this->Makefile->GetDefinition(static_link_type_flag_var);
+
+ std::string shared_link_type_flag_var = "CMAKE_";
+ shared_link_type_flag_var += target_type_str;
+ shared_link_type_flag_var += "_LINK_DYNAMIC_";
+ shared_link_type_flag_var += this->LinkLanguage;
+ shared_link_type_flag_var += "_FLAGS";
+ shared_link_type_flag =
+ this->Makefile->GetDefinition(shared_link_type_flag_var);
+ }
+
+ // We can support link type switching only if all needed flags are
+ // known.
+ if(static_link_type_flag && *static_link_type_flag &&
+ shared_link_type_flag && *shared_link_type_flag)
+ {
+ this->LinkTypeEnabled = true;
+ this->StaticLinkTypeFlag = static_link_type_flag;
+ this->SharedLinkTypeFlag = shared_link_type_flag;
+ }
+
+ // Lookup the starting link type from the target (linked statically?).
+ const char* lss = this->Target->GetProperty("LINK_SEARCH_START_STATIC");
+ this->StartLinkType = cmSystemTools::IsOn(lss)? LinkStatic : LinkShared;
+ this->CurrentLinkType = this->StartLinkType;
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::ComputeItemParserInfo()
+{
+ // Get possible library name prefixes.
+ cmMakefile* mf = this->Makefile;
+ this->AddLinkPrefix(mf->GetDefinition("CMAKE_STATIC_LIBRARY_PREFIX"));
+ this->AddLinkPrefix(mf->GetDefinition("CMAKE_SHARED_LIBRARY_PREFIX"));
+
+ // Import library names should be matched and treated as shared
+ // libraries for the purposes of linking.
+ this->AddLinkExtension(mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"),
+ LinkShared);
+ this->AddLinkExtension(mf->GetDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"),
+ LinkStatic);
+ this->AddLinkExtension(mf->GetDefinition("CMAKE_SHARED_LIBRARY_SUFFIX"),
+ LinkShared);
+ this->AddLinkExtension(mf->GetDefinition("CMAKE_LINK_LIBRARY_SUFFIX"),
+ LinkUnknown);
+ if(const char* linkSuffixes =
+ mf->GetDefinition("CMAKE_EXTRA_LINK_EXTENSIONS"))
+ {
+ std::vector<std::string> linkSuffixVec;
+ cmSystemTools::ExpandListArgument(linkSuffixes, linkSuffixVec);
+ for(std::vector<std::string>::iterator i = linkSuffixVec.begin();
+ i != linkSuffixVec.end(); ++i)
+ {
+ this->AddLinkExtension(i->c_str(), LinkUnknown);
+ }
+ }
+ if(const char* sharedSuffixes =
+ mf->GetDefinition("CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES"))
+ {
+ std::vector<std::string> sharedSuffixVec;
+ cmSystemTools::ExpandListArgument(sharedSuffixes, sharedSuffixVec);
+ for(std::vector<std::string>::iterator i = sharedSuffixVec.begin();
+ i != sharedSuffixVec.end(); ++i)
+ {
+ this->AddLinkExtension(i->c_str(), LinkShared);
+ }
+ }
+
+ // Compute a regex to match link extensions.
+ std::string libext = this->CreateExtensionRegex(this->LinkExtensions,
+ LinkUnknown);
+
+ // Create regex to remove any library extension.
+ std::string reg("(.*)");
+ reg += libext;
+ this->OrderLinkerSearchPath->SetLinkExtensionInfo(this->LinkExtensions,
+ reg);
+
+ // Create a regex to match a library name. Match index 1 will be
+ // the prefix if it exists and empty otherwise. Match index 2 will
+ // be the library name. Match index 3 will be the library
+ // extension.
+ reg = "^(";
+ for(std::set<std::string>::iterator p = this->LinkPrefixes.begin();
+ p != this->LinkPrefixes.end(); ++p)
+ {
+ reg += *p;
+ reg += "|";
+ }
+ reg += ")";
+ reg += "([^/:]*)";
+
+ // Create a regex to match any library name.
+ std::string reg_any = reg;
+ reg_any += libext;
+#ifdef CM_COMPUTE_LINK_INFO_DEBUG
+ fprintf(stderr, "any regex [%s]\n", reg_any.c_str());
+#endif
+ this->ExtractAnyLibraryName.compile(reg_any.c_str());
+
+ // Create a regex to match static library names.
+ if(!this->StaticLinkExtensions.empty())
+ {
+ std::string reg_static = reg;
+ reg_static += this->CreateExtensionRegex(this->StaticLinkExtensions,
+ LinkStatic);
+#ifdef CM_COMPUTE_LINK_INFO_DEBUG
+ fprintf(stderr, "static regex [%s]\n", reg_static.c_str());
+#endif
+ this->ExtractStaticLibraryName.compile(reg_static.c_str());
+ }
+
+ // Create a regex to match shared library names.
+ if(!this->SharedLinkExtensions.empty())
+ {
+ std::string reg_shared = reg;
+ this->SharedRegexString =
+ this->CreateExtensionRegex(this->SharedLinkExtensions, LinkShared);
+ reg_shared += this->SharedRegexString;
+#ifdef CM_COMPUTE_LINK_INFO_DEBUG
+ fprintf(stderr, "shared regex [%s]\n", reg_shared.c_str());
+#endif
+ this->ExtractSharedLibraryName.compile(reg_shared.c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddLinkPrefix(const char* p)
+{
+ if(p && *p)
+ {
+ this->LinkPrefixes.insert(p);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddLinkExtension(const char* e, LinkType type)
+{
+ if(e && *e)
+ {
+ if(type == LinkStatic)
+ {
+ this->StaticLinkExtensions.push_back(e);
+ }
+ if(type == LinkShared)
+ {
+ this->SharedLinkExtensions.push_back(e);
+ }
+ this->LinkExtensions.push_back(e);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmComputeLinkInformation
+::CreateExtensionRegex(std::vector<std::string> const& exts, LinkType type)
+{
+ // Build a list of extension choices.
+ std::string libext = "(";
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator i = exts.begin();
+ i != exts.end(); ++i)
+ {
+ // Separate this choice from the previous one.
+ libext += sep;
+ sep = "|";
+
+ // Store this extension choice with the "." escaped.
+ libext += "\\";
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ libext += this->NoCaseExpression(i->c_str());
+#else
+ libext += *i;
+#endif
+ }
+
+ // Finish the list.
+ libext += ")";
+
+ // Add an optional OpenBSD version component.
+ if(this->OpenBSD)
+ {
+ libext += "(\\.[0-9]+\\.[0-9]+)?";
+ }
+ else if(type == LinkShared)
+ {
+ libext += "(\\.[0-9]+)?";
+ }
+
+ libext += "$";
+ return libext;
+}
+
+//----------------------------------------------------------------------------
+std::string cmComputeLinkInformation::NoCaseExpression(const char* str)
+{
+ std::string ret;
+ const char* s = str;
+ while(*s)
+ {
+ if(*s == '.')
+ {
+ ret += *s;
+ }
+ else
+ {
+ ret += "[";
+ ret += static_cast<char>(tolower(*s));
+ ret += static_cast<char>(toupper(*s));
+ ret += "]";
+ }
+ s++;
+ }
+ return ret;
+}
+
+//-------------------------------------------------------------------
+void cmComputeLinkInformation::SetCurrentLinkType(LinkType lt)
+{
+ // If we are changing the current link type add the flag to tell the
+ // linker about it.
+ if(this->CurrentLinkType != lt)
+ {
+ this->CurrentLinkType = lt;
+
+ if(this->LinkTypeEnabled)
+ {
+ switch(this->CurrentLinkType)
+ {
+ case LinkStatic:
+ this->Items.push_back(Item(this->StaticLinkTypeFlag, false));
+ break;
+ case LinkShared:
+ this->Items.push_back(Item(this->SharedLinkTypeFlag, false));
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddTargetItem(std::string const& item,
+ cmTarget 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
+ // shared. This is because dynamic-mode linking can handle both
+ // 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)
+ {
+ this->SetCurrentLinkType(LinkShared);
+ }
+
+ // Keep track of shared library targets linked.
+ if(target->GetType() == cmTarget::SHARED_LIBRARY)
+ {
+ this->SharedLibrariesLinked.insert(target);
+ }
+
+ // Handle case of an imported shared library with no soname.
+ if(this->NoSONameUsesPath &&
+ target->IsImportedSharedLibWithoutSOName(this->Config))
+ {
+ this->AddSharedLibNoSOName(item);
+ return;
+ }
+
+ // If this platform wants a flag before the full path, add it.
+ if(!this->LibLinkFileFlag.empty())
+ {
+ this->Items.push_back(Item(this->LibLinkFileFlag, false));
+ }
+
+ // For compatibility with CMake 2.4 include the item's directory in
+ // the linker search path.
+ if(this->OldLinkDirMode && !target->IsFrameworkOnApple() &&
+ this->OldLinkDirMask.find(cmSystemTools::GetFilenamePath(item)) ==
+ this->OldLinkDirMask.end())
+ {
+ this->OldLinkDirItems.push_back(item);
+ }
+
+ // Now add the full path to the library.
+ this->Items.push_back(Item(item, true, target));
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddFullItem(std::string const& item)
+{
+ // Check for the implicit link directory special case.
+ if(this->CheckImplicitDirItem(item))
+ {
+ return;
+ }
+
+ // Check for case of shared library with no builtin soname.
+ if(this->NoSONameUsesPath && this->CheckSharedLibNoSOName(item))
+ {
+ return;
+ }
+
+ // Full path libraries should specify a valid library file name.
+ // See documentation of CMP0008.
+ std::string generator = this->GlobalGenerator->GetName();
+ if(this->Target->GetPolicyStatusCMP0008() != cmPolicies::NEW &&
+ (generator.find("Visual Studio") != generator.npos ||
+ generator.find("Xcode") != generator.npos))
+ {
+ std::string file = cmSystemTools::GetFilenameName(item);
+ if(!this->ExtractAnyLibraryName.find(file.c_str()))
+ {
+ this->HandleBadFullItem(item, file);
+ return;
+ }
+ }
+
+ // This is called to handle a link item that is a full path.
+ // If the target is not a static library make sure the link type is
+ // shared. This is because dynamic-mode linking can handle both
+ // 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(this->LinkTypeEnabled)
+ {
+ std::string name = cmSystemTools::GetFilenameName(item);
+ if(this->ExtractSharedLibraryName.find(name))
+ {
+ this->SetCurrentLinkType(LinkShared);
+ }
+ else if(!this->ExtractStaticLibraryName.find(item))
+ {
+ // We cannot determine the type. Assume it is the target's
+ // default type.
+ this->SetCurrentLinkType(this->StartLinkType);
+ }
+ }
+
+ // For compatibility with CMake 2.4 include the item's directory in
+ // the linker search path.
+ if(this->OldLinkDirMode &&
+ this->OldLinkDirMask.find(cmSystemTools::GetFilenamePath(item)) ==
+ this->OldLinkDirMask.end())
+ {
+ this->OldLinkDirItems.push_back(item);
+ }
+
+ // If this platform wants a flag before the full path, add it.
+ if(!this->LibLinkFileFlag.empty())
+ {
+ this->Items.push_back(Item(this->LibLinkFileFlag, false));
+ }
+
+ // Now add the full path to the library.
+ this->Items.push_back(Item(item, true));
+}
+
+//----------------------------------------------------------------------------
+bool cmComputeLinkInformation::CheckImplicitDirItem(std::string const& item)
+{
+ // We only switch to a pathless item if the link type may be
+ // enforced. Fortunately only platforms that support link types
+ // seem to have magic per-architecture implicit link directories.
+ if(!this->LinkTypeEnabled)
+ {
+ return false;
+ }
+
+ // Check if this item is in an implicit link directory.
+ std::string dir = cmSystemTools::GetFilenamePath(item);
+ if(this->ImplicitLinkDirs.find(dir) == this->ImplicitLinkDirs.end())
+ {
+ // Only libraries in implicit link directories are converted to
+ // pathless items.
+ return false;
+ }
+
+ // Only apply the policy below if the library file is one that can
+ // be found by the linker.
+ std::string file = cmSystemTools::GetFilenameName(item);
+ if(!this->ExtractAnyLibraryName.find(file))
+ {
+ return false;
+ }
+
+ // Many system linkers support multiple architectures by
+ // automatically selecting the implicit linker search path for the
+ // current architecture. If the library appears in an implicit link
+ // directory then just report the file name without the directory
+ // portion. This will allow the system linker to locate the proper
+ // library for the architecture at link time.
+ this->AddUserItem(file, false);
+
+ // Make sure the link directory ordering will find the library.
+ this->OrderLinkerSearchPath->AddLinkLibrary(item);
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddUserItem(std::string const& item,
+ bool pathNotKnown)
+{
+ // This is called to handle a link item that does not match a CMake
+ // target and is not a full path. We check here if it looks like a
+ // library file name to automatically request the proper link type
+ // from the linker. For example:
+ //
+ // foo ==> -lfoo
+ // libfoo.a ==> -Wl,-Bstatic -lfoo
+
+ // Pass flags through untouched.
+ if(item[0] == '-' || item[0] == '$' || item[0] == '`')
+ {
+ // if this is a -l option then we might need to warn about
+ // CMP0003 so put it in OldUserFlagItems, if it is not a -l
+ // or -Wl,-l (-framework -pthread), then allow it without a
+ // CMP0003 as -L will not affect those other linker flags
+ if(item.find("-l") == 0 || item.find("-Wl,-l") == 0)
+ {
+ // This is a linker option provided by the user.
+ this->OldUserFlagItems.push_back(item);
+ }
+
+ // Restore the target link type since this item does not specify
+ // one.
+ this->SetCurrentLinkType(this->StartLinkType);
+
+ // Use the item verbatim.
+ this->Items.push_back(Item(item, false));
+ return;
+ }
+
+ // Parse out the prefix, base, and suffix components of the
+ // library name. If the name matches that of a shared or static
+ // library then set the link type accordingly.
+ //
+ // Search for shared library names first because some platforms
+ // have shared libraries with names that match the static library
+ // pattern. For example cygwin and msys use the convention
+ // libfoo.dll.a for import libraries and libfoo.a for static
+ // libraries. On AIX a library with the name libfoo.a can be
+ // shared!
+ std::string lib;
+ if(this->ExtractSharedLibraryName.find(item))
+ {
+ // This matches a shared library file name.
+#ifdef CM_COMPUTE_LINK_INFO_DEBUG
+ fprintf(stderr, "shared regex matched [%s] [%s] [%s]\n",
+ this->ExtractSharedLibraryName.match(1).c_str(),
+ this->ExtractSharedLibraryName.match(2).c_str(),
+ this->ExtractSharedLibraryName.match(3).c_str());
+#endif
+ // Set the link type to shared.
+ this->SetCurrentLinkType(LinkShared);
+
+ // Use just the library name so the linker will search.
+ lib = this->ExtractSharedLibraryName.match(2);
+ }
+ else if(this->ExtractStaticLibraryName.find(item))
+ {
+ // This matches a static library file name.
+#ifdef CM_COMPUTE_LINK_INFO_DEBUG
+ fprintf(stderr, "static regex matched [%s] [%s] [%s]\n",
+ this->ExtractStaticLibraryName.match(1).c_str(),
+ this->ExtractStaticLibraryName.match(2).c_str(),
+ this->ExtractStaticLibraryName.match(3).c_str());
+#endif
+ // Set the link type to static.
+ this->SetCurrentLinkType(LinkStatic);
+
+ // Use just the library name so the linker will search.
+ lib = this->ExtractStaticLibraryName.match(2);
+ }
+ else if(this->ExtractAnyLibraryName.find(item))
+ {
+ // This matches a library file name.
+#ifdef CM_COMPUTE_LINK_INFO_DEBUG
+ fprintf(stderr, "any regex matched [%s] [%s] [%s]\n",
+ this->ExtractAnyLibraryName.match(1).c_str(),
+ this->ExtractAnyLibraryName.match(2).c_str(),
+ this->ExtractAnyLibraryName.match(3).c_str());
+#endif
+ // Restore the target link type since this item does not specify
+ // one.
+ this->SetCurrentLinkType(this->StartLinkType);
+
+ // Use just the library name so the linker will search.
+ lib = this->ExtractAnyLibraryName.match(2);
+ }
+ else
+ {
+ // This is a name specified by the user.
+ if(pathNotKnown)
+ {
+ this->OldUserFlagItems.push_back(item);
+ }
+
+ // We must ask the linker to search for a library with this name.
+ // Restore the target link type since this item does not specify
+ // one.
+ this->SetCurrentLinkType(this->StartLinkType);
+ lib = item;
+ }
+
+ // Create an option to ask the linker to search for the library.
+ std::string out = this->LibLinkFlag;
+ out += lib;
+ out += this->LibLinkSuffix;
+ this->Items.push_back(Item(out, false));
+
+ // Here we could try to find the library the linker will find and
+ // add a runtime information entry for it. It would probably not be
+ // reliable and we want to encourage use of full paths for library
+ // specification.
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddFrameworkItem(std::string const& item)
+{
+ // Try to separate the framework name and path.
+ if(!this->SplitFramework.find(item.c_str()))
+ {
+ cmOStringStream e;
+ e << "Could not parse framework path \"" << item << "\" "
+ << "linked by target " << this->Target->GetName() << ".";
+ cmSystemTools::Error(e.str().c_str());
+ return;
+ }
+
+ std::string fw_path = this->SplitFramework.match(1);
+ std::string fw = this->SplitFramework.match(2);
+ std::string full_fw = fw_path;
+ full_fw += "/";
+ full_fw += fw;
+ full_fw += ".framework";
+ full_fw += "/";
+ full_fw += fw;
+
+ // Add the directory portion to the framework search path.
+ this->AddFrameworkPath(fw_path);
+
+ // add runtime information
+ this->AddLibraryRuntimeInfo(full_fw);
+
+ // Add the item using the -framework option.
+ this->Items.push_back(Item("-framework", false));
+ fw = this->LocalGenerator->EscapeForShell(fw);
+ this->Items.push_back(Item(fw, false));
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddDirectoryItem(std::string const& item)
+{
+ if(this->Makefile->IsOn("APPLE")
+ && cmSystemTools::IsPathToFramework(item.c_str()))
+ {
+ this->AddFrameworkItem(item);
+ }
+ else
+ {
+ this->DropDirectoryItem(item);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::DropDirectoryItem(std::string const& item)
+{
+ // A full path to a directory was found as a link item. Warn the
+ // user.
+ cmOStringStream e;
+ e << "WARNING: Target \"" << this->Target->GetName()
+ << "\" requests linking to directory \"" << item << "\". "
+ << "Targets may link only to libraries. "
+ << "CMake is dropping the item.";
+ cmSystemTools::Message(e.str().c_str());
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::ComputeFrameworkInfo()
+{
+ // Avoid adding implicit framework paths.
+ std::vector<std::string> implicitDirVec;
+
+ // Get platform-wide implicit directories.
+ if(const char* implicitLinks = this->Makefile->GetDefinition
+ ("CMAKE_PLATFORM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES"))
+ {
+ cmSystemTools::ExpandListArgument(implicitLinks, implicitDirVec);
+ }
+
+ // Get language-specific implicit directories.
+ std::string implicitDirVar = "CMAKE_";
+ implicitDirVar += this->LinkLanguage;
+ implicitDirVar += "_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES";
+ if(const char* implicitDirs =
+ this->Makefile->GetDefinition(implicitDirVar))
+ {
+ cmSystemTools::ExpandListArgument(implicitDirs, implicitDirVec);
+ }
+
+ for(std::vector<std::string>::const_iterator i = implicitDirVec.begin();
+ i != implicitDirVec.end(); ++i)
+ {
+ this->FrameworkPathsEmmitted.insert(*i);
+ }
+
+ // Regular expression to extract a framework path and name.
+ this->SplitFramework.compile("(.*)/(.*)\\.framework$");
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddFrameworkPath(std::string const& p)
+{
+ if(this->FrameworkPathsEmmitted.insert(p).second)
+ {
+ this->FrameworkPaths.push_back(p);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmComputeLinkInformation::CheckSharedLibNoSOName(std::string const& item)
+{
+ // This platform will use the path to a library as its soname if the
+ // library is given via path and was not built with an soname. If
+ // this is a shared library that might be the case.
+ std::string file = cmSystemTools::GetFilenameName(item);
+ if(this->ExtractSharedLibraryName.find(file))
+ {
+ // If we can guess the soname fairly reliably then assume the
+ // library has one. Otherwise assume the library has no builtin
+ // soname.
+ std::string soname;
+ if(!cmSystemTools::GuessLibrarySOName(item, soname))
+ {
+ this->AddSharedLibNoSOName(item);
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::AddSharedLibNoSOName(std::string const& item)
+{
+ // We have a full path to a shared library with no soname. We need
+ // to ask the linker to locate the item because otherwise the path
+ // we give to it will be embedded in the target linked. Then at
+ // runtime the dynamic linker will search for the library using the
+ // path instead of just the name.
+ std::string file = cmSystemTools::GetFilenameName(item);
+ this->AddUserItem(file, false);
+
+ // Make sure the link directory ordering will find the library.
+ this->OrderLinkerSearchPath->AddLinkLibrary(item);
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::HandleBadFullItem(std::string const& item,
+ std::string const& file)
+{
+ // Do not depend on things that do not exist.
+ std::vector<std::string>::iterator i =
+ std::find(this->Depends.begin(), this->Depends.end(), item);
+ if(i != this->Depends.end())
+ {
+ this->Depends.erase(i);
+ }
+
+ // Tell the linker to search for the item and provide the proper
+ // path for it. Do not contribute to any CMP0003 warning (do not
+ // put in OldLinkDirItems or OldUserFlagItems).
+ this->AddUserItem(file, false);
+ this->OrderLinkerSearchPath->AddLinkLibrary(item);
+
+ // Produce any needed message.
+ switch(this->Target->GetPolicyStatusCMP0008())
+ {
+ case cmPolicies::WARN:
+ {
+ // Print the warning at most once for this item.
+ std::string wid = "CMP0008-WARNING-GIVEN-";
+ wid += item;
+ if(!this->CMakeInstance->GetPropertyAsBool(wid))
+ {
+ this->CMakeInstance->SetProperty(wid, "1");
+ cmOStringStream w;
+ w << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0008)) << "\n"
+ << "Target \"" << this->Target->GetName() << "\" links to item\n"
+ << " " << item << "\n"
+ << "which is a full-path but not a valid library file name.";
+ this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
+ this->Target->GetBacktrace());
+ }
+ }
+ case cmPolicies::OLD:
+ // OLD behavior does not warn.
+ break;
+ case cmPolicies::NEW:
+ // NEW behavior will not get here.
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ {
+ cmOStringStream e;
+ e << (this->Makefile->GetPolicies()->
+ GetRequiredPolicyError(cmPolicies::CMP0008)) << "\n"
+ << "Target \"" << this->Target->GetName() << "\" links to item\n"
+ << " " << item << "\n"
+ << "which is a full-path but not a valid library file name.";
+ this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->Target->GetBacktrace());
+ }
+ break;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
+{
+ // Support broken projects if necessary.
+ if(this->OldLinkDirItems.empty() || this->OldUserFlagItems.empty() ||
+ !this->OldLinkDirMode)
+ {
+ return true;
+ }
+
+ // Enforce policy constraints.
+ switch(this->Target->GetPolicyStatusCMP0003())
+ {
+ case cmPolicies::WARN:
+ if(!this->CMakeInstance->GetPropertyAsBool("CMP0003-WARNING-GIVEN"))
+ {
+ this->CMakeInstance->SetProperty("CMP0003-WARNING-GIVEN", "1");
+ cmOStringStream w;
+ this->PrintLinkPolicyDiagnosis(w);
+ this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
+ this->Target->GetBacktrace());
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to add the paths containing libraries with
+ // known full paths as link directories.
+ break;
+ case cmPolicies::NEW:
+ // Should never happen due to assignment of OldLinkDirMode
+ return true;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ {
+ cmOStringStream e;
+ e << (this->Makefile->GetPolicies()->
+ GetRequiredPolicyError(cmPolicies::CMP0003)) << "\n";
+ this->PrintLinkPolicyDiagnosis(e);
+ this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->Target->GetBacktrace());
+ return false;
+ }
+ }
+
+ // Add the link directories for full path items.
+ for(std::vector<std::string>::const_iterator
+ i = this->OldLinkDirItems.begin();
+ i != this->OldLinkDirItems.end(); ++i)
+ {
+ this->OrderLinkerSearchPath->AddLinkLibrary(*i);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::PrintLinkPolicyDiagnosis(std::ostream& os)
+{
+ // Tell the user what to do.
+ os << "Policy CMP0003 should be set before this line. "
+ << "Add code such as\n"
+ << " if(COMMAND cmake_policy)\n"
+ << " cmake_policy(SET CMP0003 NEW)\n"
+ << " endif(COMMAND cmake_policy)\n"
+ << "as early as possible but after the most recent call to "
+ << "cmake_minimum_required or cmake_policy(VERSION). ";
+
+ // List the items that might need the old-style paths.
+ os << "This warning appears because target \""
+ << this->Target->GetName() << "\" "
+ << "links to some libraries for which the linker must search:\n";
+ {
+ // Format the list of unknown items to be as short as possible while
+ // still fitting in the allowed width (a true solution would be the
+ // bin packing problem if we were allowed to change the order).
+ std::string::size_type max_size = 76;
+ std::string line;
+ const char* sep = " ";
+ for(std::vector<std::string>::const_iterator
+ i = this->OldUserFlagItems.begin();
+ i != this->OldUserFlagItems.end(); ++i)
+ {
+ // If the addition of another item will exceed the limit then
+ // output the current line and reset it. Note that the separator
+ // is either " " or ", " which is always 2 characters.
+ if(!line.empty() && (line.size() + i->size() + 2) > max_size)
+ {
+ os << line << "\n";
+ sep = " ";
+ line = "";
+ }
+ line += sep;
+ line += *i;
+ // Convert to the other separator.
+ sep = ", ";
+ }
+ if(!line.empty())
+ {
+ os << line << "\n";
+ }
+ }
+
+ // List the paths old behavior is adding.
+ os << "and other libraries with known full path:\n";
+ std::set<std::string> emitted;
+ for(std::vector<std::string>::const_iterator
+ i = this->OldLinkDirItems.begin();
+ i != this->OldLinkDirItems.end(); ++i)
+ {
+ if(emitted.insert(cmSystemTools::GetFilenamePath(*i)).second)
+ {
+ os << " " << *i << "\n";
+ }
+ }
+
+ // Explain.
+ os << "CMake is adding directories in the second list to the linker "
+ << "search path in case they are needed to find libraries from the "
+ << "first list (for backwards compatibility with CMake 2.4). "
+ << "Set policy CMP0003 to OLD or NEW to enable or disable this "
+ << "behavior explicitly. "
+ << "Run \"cmake --help-policy CMP0003\" for more information.";
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::LoadImplicitLinkInfo()
+{
+ std::vector<std::string> implicitDirVec;
+
+ // Get platform-wide implicit directories.
+ if(const char* implicitLinks =
+ (this->Makefile->GetDefinition
+ ("CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES")))
+ {
+ cmSystemTools::ExpandListArgument(implicitLinks, implicitDirVec);
+ }
+
+ // Append library architecture to all implicit platform directories
+ // and add them to the set
+ if(const char* libraryArch =
+ this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE"))
+ {
+ for (std::vector<std::string>::const_iterator i = implicitDirVec.begin();
+ i != implicitDirVec.end(); ++i)
+ {
+ this->ImplicitLinkDirs.insert(*i + "/" + libraryArch);
+ }
+ }
+
+ // Get language-specific implicit directories.
+ std::string implicitDirVar = "CMAKE_";
+ implicitDirVar += this->LinkLanguage;
+ implicitDirVar += "_IMPLICIT_LINK_DIRECTORIES";
+ if(const char* implicitDirs =
+ this->Makefile->GetDefinition(implicitDirVar))
+ {
+ cmSystemTools::ExpandListArgument(implicitDirs, implicitDirVec);
+ }
+
+ // Store implicit link directories.
+ for(std::vector<std::string>::const_iterator i = implicitDirVec.begin();
+ i != implicitDirVec.end(); ++i)
+ {
+ this->ImplicitLinkDirs.insert(*i);
+ }
+
+ // Get language-specific implicit libraries.
+ std::vector<std::string> implicitLibVec;
+ std::string implicitLibVar = "CMAKE_";
+ implicitLibVar += this->LinkLanguage;
+ implicitLibVar += "_IMPLICIT_LINK_LIBRARIES";
+ if(const char* implicitLibs =
+ this->Makefile->GetDefinition(implicitLibVar))
+ {
+ cmSystemTools::ExpandListArgument(implicitLibs, implicitLibVec);
+ }
+
+ // Store implicit link libraries.
+ for(std::vector<std::string>::const_iterator i = implicitLibVec.begin();
+ i != implicitLibVec.end(); ++i)
+ {
+ // Items starting in '-' but not '-l' are flags, not libraries,
+ // and should not be filtered by this implicit list.
+ std::string const& item = *i;
+ if(item[0] != '-' || item[1] == 'l')
+ {
+ this->ImplicitLinkLibs.insert(item);
+ }
+ }
+
+ // Get platform specific rpath link directories
+ if(const char *rpathDirs =
+ (this->Makefile->GetDefinition
+ ("CMAKE_PLATFORM_RUNTIME_PATH")))
+ {
+ cmSystemTools::ExpandListArgument(rpathDirs, this->RuntimeLinkDirs);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string> const&
+cmComputeLinkInformation::GetRuntimeSearchPath()
+{
+ return this->OrderRuntimeSearchPath->GetOrderedDirectories();
+}
+
+//----------------------------------------------------------------------------
+void
+cmComputeLinkInformation::AddLibraryRuntimeInfo(std::string const& fullPath,
+ cmTarget const* target)
+{
+ // Ignore targets on Apple where install_name is not @rpath.
+ // The dependenty library can be found with other means such as
+ // @loader_path or full paths.
+ if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ if(!target->HasMacOSXRpathInstallNameDir(this->Config))
+ {
+ return;
+ }
+ }
+
+ // Libraries with unknown type must be handled using just the file
+ // on disk.
+ if(target->GetType() == cmTarget::UNKNOWN_LIBRARY)
+ {
+ this->AddLibraryRuntimeInfo(fullPath);
+ return;
+ }
+
+ // Skip targets that are not shared libraries (modules cannot be linked).
+ if(target->GetType() != cmTarget::SHARED_LIBRARY)
+ {
+ return;
+ }
+
+ // Try to get the soname of the library. Only files with this name
+ // could possibly conflict.
+ std::string soName = target->GetSOName(this->Config);
+ const char* soname = soName.empty()? 0 : soName.c_str();
+
+ // Include this library in the runtime path ordering.
+ this->OrderRuntimeSearchPath->AddRuntimeLibrary(fullPath, soname);
+ if(this->LinkWithRuntimePath)
+ {
+ this->OrderLinkerSearchPath->AddRuntimeLibrary(fullPath, soname);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmComputeLinkInformation::AddLibraryRuntimeInfo(std::string const& fullPath)
+{
+ // Get the name of the library from the file name.
+ bool is_shared_library = false;
+ std::string file = cmSystemTools::GetFilenameName(fullPath);
+
+ if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ // Check that @rpath is part of the install name.
+ // If it isn't, return.
+ std::string soname;
+ if(!cmSystemTools::GuessLibraryInstallName(fullPath, soname))
+ {
+ return;
+ }
+
+ if(soname.find("@rpath") == std::string::npos)
+ {
+ return;
+ }
+ }
+
+ is_shared_library = this->ExtractSharedLibraryName.find(file);
+
+ if(!is_shared_library)
+ {
+ // On some platforms (AIX) a shared library may look static.
+ if(this->ArchivesMayBeShared)
+ {
+ if(this->ExtractStaticLibraryName.find(file.c_str()))
+ {
+ // This is the name of a shared library or archive.
+ is_shared_library = true;
+ }
+ }
+ }
+
+ // It could be an Apple framework
+ if(!is_shared_library)
+ {
+ if(fullPath.find(".framework") != std::string::npos)
+ {
+ static cmsys::RegularExpression
+ splitFramework("^(.*)/(.*).framework/(.*)$");
+ if(splitFramework.find(fullPath) &&
+ (std::string::npos !=
+ splitFramework.match(3).find(splitFramework.match(2))))
+ {
+ is_shared_library = true;
+ }
+ }
+ }
+
+ if(!is_shared_library)
+ {
+ return;
+ }
+
+ // Include this library in the runtime path ordering.
+ this->OrderRuntimeSearchPath->AddRuntimeLibrary(fullPath);
+ if(this->LinkWithRuntimePath)
+ {
+ this->OrderLinkerSearchPath->AddRuntimeLibrary(fullPath);
+ }
+}
+
+//----------------------------------------------------------------------------
+static void cmCLI_ExpandListUnique(const char* str,
+ std::vector<std::string>& out,
+ std::set<std::string>& emitted)
+{
+ std::vector<std::string> tmp;
+ cmSystemTools::ExpandListArgument(str, tmp);
+ for(std::vector<std::string>::iterator i = tmp.begin(); i != tmp.end(); ++i)
+ {
+ if(emitted.insert(*i).second)
+ {
+ out.push_back(*i);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
+ bool for_install)
+{
+ // Select whether to generate runtime search directories.
+ bool outputRuntime =
+ !this->Makefile->IsOn("CMAKE_SKIP_RPATH") && !this->RuntimeFlag.empty();
+
+ // Select whether to generate an rpath for the install tree or the
+ // build tree.
+ bool linking_for_install =
+ (for_install ||
+ this->Target->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"));
+ bool use_install_rpath =
+ (outputRuntime && this->Target->HaveInstallTreeRPATH() &&
+ linking_for_install);
+ bool use_build_rpath =
+ (outputRuntime && this->Target->HaveBuildTreeRPATH(this->Config) &&
+ !linking_for_install);
+ bool use_link_rpath =
+ outputRuntime && linking_for_install &&
+ !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH") &&
+ 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->GetProperty("INSTALL_RPATH");
+ cmCLI_ExpandListUnique(install_rpath, runtimeDirs, emitted);
+ }
+ if(use_build_rpath || use_link_rpath)
+ {
+ std::string rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
+ const char *stagePath
+ = this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX");
+ const char *installPrefix
+ = this->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
+ cmSystemTools::ConvertToUnixSlashes(rootPath);
+ std::vector<std::string> const& rdirs = this->GetRuntimeSearchPath();
+ for(std::vector<std::string>::const_iterator ri = rdirs.begin();
+ ri != rdirs.end(); ++ri)
+ {
+ // Put this directory in the rpath if using build-tree rpath
+ // support or if using the link path as an rpath.
+ if(use_build_rpath)
+ {
+ std::string d = *ri;
+ if (!rootPath.empty() && d.find(rootPath) == 0)
+ {
+ d = d.substr(rootPath.size());
+ }
+ else if (stagePath && *stagePath && d.find(stagePath) == 0)
+ {
+ std::string suffix = d.substr(strlen(stagePath));
+ d = installPrefix;
+ d += "/";
+ d += suffix;
+ cmSystemTools::ConvertToUnixSlashes(d);
+ }
+ if(emitted.insert(d).second)
+ {
+ runtimeDirs.push_back(d);
+ }
+ }
+ 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();
+ if(!cmSystemTools::ComparePath(ri->c_str(), topSourceDir) &&
+ !cmSystemTools::ComparePath(ri->c_str(), topBinaryDir) &&
+ !cmSystemTools::IsSubDirectory(ri->c_str(), topSourceDir) &&
+ !cmSystemTools::IsSubDirectory(ri->c_str(), topBinaryDir))
+ {
+ std::string d = *ri;
+ if (!rootPath.empty() && d.find(rootPath) == 0)
+ {
+ d = d.substr(rootPath.size());
+ }
+ else if (stagePath && *stagePath && d.find(stagePath) == 0)
+ {
+ std::string suffix = d.substr(strlen(stagePath));
+ d = installPrefix;
+ d += "/";
+ d += suffix;
+ cmSystemTools::ConvertToUnixSlashes(d);
+ }
+ if(emitted.insert(d).second)
+ {
+ runtimeDirs.push_back(d);
+ }
+ }
+ }
+ }
+ }
+
+ // Add runtime paths required by the languages to always be
+ // present. This is done even when skipping rpath support.
+ {
+ cmTarget::LinkClosure const* lc =
+ this->Target->GetLinkClosure(this->Config);
+ for(std::vector<std::string>::const_iterator li = lc->Languages.begin();
+ li != lc->Languages.end(); ++li)
+ {
+ std::string useVar = "CMAKE_" + *li +
+ "_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH";
+ if(this->Makefile->IsOn(useVar))
+ {
+ std::string dirVar = "CMAKE_" + *li +
+ "_IMPLICIT_LINK_DIRECTORIES";
+ if(const char* dirs = this->Makefile->GetDefinition(dirVar))
+ {
+ cmCLI_ExpandListUnique(dirs, runtimeDirs, emitted);
+ }
+ }
+ }
+ }
+
+ // Add runtime paths required by the platform to always be
+ // present. This is done even when skipping rpath support.
+ cmCLI_ExpandListUnique(this->RuntimeAlways.c_str(), runtimeDirs, emitted);
+}
+
+//----------------------------------------------------------------------------
+std::string cmComputeLinkInformation::GetRPathString(bool for_install)
+{
+ // Get the directories to use.
+ std::vector<std::string> runtimeDirs;
+ this->GetRPath(runtimeDirs, for_install);
+
+ // Concatenate the paths.
+ std::string rpath;
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator ri = runtimeDirs.begin();
+ ri != runtimeDirs.end(); ++ri)
+ {
+ // Separate from previous path.
+ rpath += sep;
+ sep = this->GetRuntimeSep().c_str();
+
+ // Add this path.
+ rpath += *ri;
+ }
+
+ // If the rpath will be replaced at install time, prepare space.
+ if(!for_install && this->RuntimeUseChrpath)
+ {
+ if(!rpath.empty())
+ {
+ // Add one trailing separator so the linker does not re-use the
+ // rpath .dynstr entry for a symbol name that happens to match
+ // the end of the rpath string.
+ rpath += this->GetRuntimeSep();
+ }
+
+ // Make sure it is long enough to hold the replacement value.
+ std::string::size_type minLength = this->GetChrpathString().length();
+ while(rpath.length() < minLength)
+ {
+ rpath += this->GetRuntimeSep();
+ }
+ }
+
+ return rpath;
+}
+
+//----------------------------------------------------------------------------
+std::string cmComputeLinkInformation::GetChrpathString()
+{
+ if(!this->RuntimeUseChrpath)
+ {
+ return "";
+ }
+
+ return this->GetRPathString(true);
+}
diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h
new file mode 100644
index 0000000000..e5d674abfd
--- /dev/null
+++ b/Source/cmComputeLinkInformation.h
@@ -0,0 +1,188 @@
+/*============================================================================
+ 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 cmComputeLinkInformation_h
+#define cmComputeLinkInformation_h
+
+#include "cmStandardIncludes.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+class cmake;
+class cmGlobalGenerator;
+class cmLocalGenerator;
+class cmMakefile;
+class cmTarget;
+class cmOrderDirectories;
+
+/** \class cmComputeLinkInformation
+ * \brief Compute link information for a target in one configuration.
+ */
+class cmComputeLinkInformation
+{
+public:
+ cmComputeLinkInformation(cmTarget const* target, const std::string& config);
+ ~cmComputeLinkInformation();
+ bool Compute();
+
+ struct Item
+ {
+ 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):
+ Value(v), IsPath(p), Target(target) {}
+ std::string Value;
+ bool IsPath;
+ cmTarget const* Target;
+ };
+ typedef std::vector<Item> ItemVector;
+ ItemVector const& GetItems();
+ std::vector<std::string> const& GetDirectories();
+ std::vector<std::string> const& GetDepends();
+ std::vector<std::string> const& GetFrameworkPaths();
+ std::string GetLinkLanguage() const { return this->LinkLanguage; }
+ std::vector<std::string> const& GetRuntimeSearchPath();
+ std::string const& GetRuntimeFlag() const { return this->RuntimeFlag; }
+ std::string const& GetRuntimeSep() const { return this->RuntimeSep; }
+ 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::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);
+
+ // Output information.
+ ItemVector Items;
+ std::vector<std::string> Directories;
+ std::vector<std::string> Depends;
+ std::vector<std::string> FrameworkPaths;
+ std::vector<std::string> RuntimeSearchPath;
+ std::set<cmTarget const*> SharedLibrariesLinked;
+
+ // Context information.
+ cmTarget const* Target;
+ cmMakefile* Makefile;
+ cmLocalGenerator* LocalGenerator;
+ cmGlobalGenerator* GlobalGenerator;
+ cmake* CMakeInstance;
+
+ // Configuration information.
+ std::string Config;
+ std::string LinkLanguage;
+ bool LinkDependsNoShared;
+
+ // Modes for dealing with dependent shared libraries.
+ enum SharedDepMode
+ {
+ SharedDepModeNone, // Drop
+ SharedDepModeDir, // List dir in -rpath-link flag
+ SharedDepModeLibDir, // List dir in linker search path
+ SharedDepModeLink // List file on link line
+ };
+
+ // System info.
+ bool UseImportLibrary;
+ const char* LoaderFlag;
+ std::string LibLinkFlag;
+ std::string LibLinkFileFlag;
+ std::string LibLinkSuffix;
+ std::string RuntimeFlag;
+ std::string RuntimeSep;
+ std::string RuntimeAlways;
+ bool RuntimeUseChrpath;
+ bool NoSONameUsesPath;
+ bool LinkWithRuntimePath;
+ std::string RPathLinkFlag;
+ SharedDepMode SharedDependencyMode;
+
+ // Link type adjustment.
+ void ComputeLinkTypeInfo();
+ enum LinkType { LinkUnknown, LinkStatic, LinkShared };
+ LinkType StartLinkType;
+ LinkType CurrentLinkType;
+ std::string StaticLinkTypeFlag;
+ std::string SharedLinkTypeFlag;
+ bool LinkTypeEnabled;
+ void SetCurrentLinkType(LinkType lt);
+ bool ArchivesMayBeShared;
+
+ // Link item parsing.
+ void ComputeItemParserInfo();
+ std::vector<std::string> StaticLinkExtensions;
+ std::vector<std::string> SharedLinkExtensions;
+ std::vector<std::string> LinkExtensions;
+ std::set<std::string> LinkPrefixes;
+ cmsys::RegularExpression ExtractStaticLibraryName;
+ cmsys::RegularExpression ExtractSharedLibraryName;
+ cmsys::RegularExpression ExtractAnyLibraryName;
+ std::string SharedRegexString;
+ bool OpenBSD;
+ void AddLinkPrefix(const char* p);
+ void AddLinkExtension(const char* e, LinkType type);
+ std::string CreateExtensionRegex(std::vector<std::string> const& exts,
+ LinkType type);
+ std::string NoCaseExpression(const char* str);
+
+ // Handling of link items.
+ void AddTargetItem(std::string const& item, cmTarget const* target);
+ void AddFullItem(std::string const& item);
+ bool CheckImplicitDirItem(std::string const& item);
+ void AddUserItem(std::string const& item, bool pathNotKnown);
+ void AddDirectoryItem(std::string const& item);
+ void AddFrameworkItem(std::string const& item);
+ void DropDirectoryItem(std::string const& item);
+ bool CheckSharedLibNoSOName(std::string const& item);
+ void AddSharedLibNoSOName(std::string const& item);
+ void HandleBadFullItem(std::string const& item, std::string const& file);
+
+ // Framework info.
+ void ComputeFrameworkInfo();
+ void AddFrameworkPath(std::string const& p);
+ std::set<std::string> FrameworkPathsEmmitted;
+ cmsys::RegularExpression SplitFramework;
+
+ // Linker search path computation.
+ cmOrderDirectories* OrderLinkerSearchPath;
+ bool FinishLinkerSearchDirectories();
+ void PrintLinkPolicyDiagnosis(std::ostream&);
+
+ // Implicit link libraries and directories for linker language.
+ void LoadImplicitLinkInfo();
+ void AddImplicitLinkInfo();
+ void AddImplicitLinkInfo(std::string const& lang);
+ std::set<std::string> ImplicitLinkDirs;
+ std::set<std::string> ImplicitLinkLibs;
+
+ // Additional paths configured by the runtime linker
+ std::vector<std::string> RuntimeLinkDirs;
+
+ // Linker search path compatibility mode.
+ std::set<std::string> OldLinkDirMask;
+ std::vector<std::string> OldLinkDirItems;
+ std::vector<std::string> OldUserFlagItems;
+ bool OldLinkDirMode;
+
+ // Runtime path computation.
+ cmOrderDirectories* OrderRuntimeSearchPath;
+ void AddLibraryRuntimeInfo(std::string const& fullPath,
+ cmTarget const* target);
+ void AddLibraryRuntimeInfo(std::string const& fullPath);
+
+ // Dependent library path computation.
+ cmOrderDirectories* OrderDependentRPath;
+};
+
+#endif
diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx
new file mode 100644
index 0000000000..75d3967bc3
--- /dev/null
+++ b/Source/cmComputeTargetDepends.cxx
@@ -0,0 +1,686 @@
+/*============================================================================
+ 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 "cmComputeTargetDepends.h"
+
+#include "cmComputeComponentGraph.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include "cmSourceFile.h"
+#include "cmTarget.h"
+#include "cmake.h"
+
+#include <algorithm>
+
+#include <assert.h>
+
+/*
+
+This class is meant to analyze inter-target dependencies globally
+during the generation step. The goal is to produce a set of direct
+dependencies for each target such that no cycles are left and the
+build order is safe.
+
+For most target types cyclic dependencies are not allowed. However
+STATIC libraries may depend on each other in a cyclic fashion. In
+general the directed dependency graph forms a directed-acyclic-graph
+of strongly connected components. All strongly connected components
+should consist of only STATIC_LIBRARY targets.
+
+In order to safely break dependency cycles we must preserve all other
+dependencies passing through the corresponding strongly connected component.
+The approach taken by this class is as follows:
+
+ - Collect all targets and form the original dependency graph
+ - Run Tarjan's algorithm to extract the strongly connected components
+ (error if any member of a non-trivial component is not STATIC)
+ - The original dependencies imply a DAG on the components.
+ Use the implied DAG to construct a final safe set of dependencies.
+
+The final dependency set is constructed as follows:
+
+ - For each connected component targets are placed in an arbitrary
+ order. Each target depends on the target following it in the order.
+ The first target is designated the head and the last target the tail.
+ (most components will be just 1 target anyway)
+
+ - Original dependencies between targets in different components are
+ converted to connect the depender's component tail to the
+ dependee's component head.
+
+In most cases this will reproduce the original dependencies. However
+when there are cycles of static libraries they will be broken in a
+safe manner.
+
+For example, consider targets A0, A1, A2, B0, B1, B2, and C with these
+dependencies:
+
+ A0 -> A1 -> A2 -> A0 , B0 -> B1 -> B2 -> B0 -> A0 , C -> B0
+
+Components may be identified as
+
+ Component 0: A0, A1, A2
+ Component 1: B0, B1, B2
+ Component 2: C
+
+Intra-component dependencies are:
+
+ 0: A0 -> A1 -> A2 , head=A0, tail=A2
+ 1: B0 -> B1 -> B2 , head=B0, tail=B2
+ 2: head=C, tail=C
+
+The inter-component dependencies are converted as:
+
+ B0 -> A0 is component 1->0 and becomes B2 -> A0
+ C -> B0 is component 2->1 and becomes C -> B0
+
+This leads to the final target dependencies:
+
+ C -> B0 -> B1 -> B2 -> A0 -> A1 -> A2
+
+These produce a safe build order since C depends directly or
+transitively on all the static libraries it links.
+
+*/
+
+//----------------------------------------------------------------------------
+cmComputeTargetDepends::cmComputeTargetDepends(cmGlobalGenerator* gg)
+{
+ this->GlobalGenerator = gg;
+ cmake* cm = this->GlobalGenerator->GetCMakeInstance();
+ this->DebugMode = cm->GetPropertyAsBool("GLOBAL_DEPENDS_DEBUG_MODE");
+ this->NoCycles = cm->GetPropertyAsBool("GLOBAL_DEPENDS_NO_CYCLES");
+}
+
+//----------------------------------------------------------------------------
+cmComputeTargetDepends::~cmComputeTargetDepends()
+{
+}
+
+//----------------------------------------------------------------------------
+bool cmComputeTargetDepends::Compute()
+{
+ // Build the original graph.
+ this->CollectTargets();
+ this->CollectDepends();
+ if(this->DebugMode)
+ {
+ this->DisplayGraph(this->InitialGraph, "initial");
+ }
+
+ // Identify components.
+ cmComputeComponentGraph ccg(this->InitialGraph);
+ if(this->DebugMode)
+ {
+ this->DisplayComponents(ccg);
+ }
+ if(!this->CheckComponents(ccg))
+ {
+ return false;
+ }
+
+ // Compute the final dependency graph.
+ if(!this->ComputeFinalDepends(ccg))
+ {
+ return false;
+ }
+ if(this->DebugMode)
+ {
+ this->DisplayGraph(this->FinalGraph, "final");
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void
+cmComputeTargetDepends::GetTargetDirectDepends(cmTarget const* t,
+ cmTargetDependSet& deps)
+{
+ // Lookup the index for this target. All targets should be known by
+ // this point.
+ std::map<cmTarget const*, int>::const_iterator tii
+ = this->TargetIndex.find(t);
+ assert(tii != this->TargetIndex.end());
+ int i = tii->second;
+
+ // Get its final dependencies.
+ EdgeList const& nl = this->FinalGraph[i];
+ for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
+ {
+ cmTarget const* dep = this->Targets[*ni];
+ cmTargetDependSet::iterator di = deps.insert(dep).first;
+ di->SetType(ni->IsStrong());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeTargetDepends::CollectTargets()
+{
+ // Collect all targets from all generators.
+ std::vector<cmLocalGenerator*> const& lgens =
+ 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();
+ ti != targets.end(); ++ti)
+ {
+ cmTarget const* target = &ti->second;
+ int index = static_cast<int>(this->Targets.size());
+ this->TargetIndex[target] = index;
+ this->Targets.push_back(target);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeTargetDepends::CollectDepends()
+{
+ // Allocate the dependency graph adjacency lists.
+ this->InitialGraph.resize(this->Targets.size());
+
+ // Compute each dependency list.
+ for(unsigned int i=0; i < this->Targets.size(); ++i)
+ {
+ this->CollectTargetDepends(i);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
+{
+ // Get the depender.
+ cmTarget const* depender = this->Targets[depender_index];
+ if (depender->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ return;
+ }
+
+ // Loop over all targets linked directly in all configs.
+ // We need to make targets depend on the union of all config-specific
+ // dependencies in all targets, because the generated build-systems can't
+ // deal with config-specific dependencies.
+ {
+ std::set<std::string> emitted;
+ cmGeneratorTarget* gt = depender->GetMakefile()->GetLocalGenerator()
+ ->GetGlobalGenerator()
+ ->GetGeneratorTarget(depender);
+
+ std::vector<std::string> configs;
+ depender->GetMakefile()->GetConfigurations(configs);
+ if (configs.empty())
+ {
+ configs.push_back("");
+ }
+ for (std::vector<std::string>::const_iterator it = configs.begin();
+ it != configs.end(); ++it)
+ {
+ std::vector<cmSourceFile const*> objectFiles;
+ gt->GetExternalObjects(objectFiles, *it);
+ for(std::vector<cmSourceFile const*>::const_iterator
+ oi = objectFiles.begin(); oi != objectFiles.end(); ++oi)
+ {
+ 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)
+ {
+ this->GlobalGenerator->GetCMakeInstance()
+ ->IssueMessage(cmake::FATAL_ERROR,
+ "Only executables and non-OBJECT libraries may "
+ "reference target objects.",
+ depender->GetBacktrace());
+ return;
+ }
+ const_cast<cmTarget*>(depender)->AddUtility(objLib);
+ }
+ }
+
+ cmTarget::LinkImplementation const* impl =
+ depender->GetLinkImplementation(*it);
+
+ // A target should not depend on itself.
+ emitted.insert(depender->GetName());
+ for(std::vector<cmLinkImplItem>::const_iterator
+ lib = impl->Libraries.begin();
+ lib != impl->Libraries.end(); ++lib)
+ {
+ // Don't emit the same library twice for this target.
+ if(emitted.insert(*lib).second)
+ {
+ this->AddTargetDepend(depender_index, *lib, true);
+ this->AddInterfaceDepends(depender_index, *lib, emitted);
+ }
+ }
+ }
+ }
+
+ // Loop over all utility dependencies.
+ {
+ std::set<cmLinkItem> const& tutils = depender->GetUtilityItems();
+ std::set<std::string> emitted;
+ // A target should not depend on itself.
+ emitted.insert(depender->GetName());
+ for(std::set<cmLinkItem>::const_iterator util = tutils.begin();
+ util != tutils.end(); ++util)
+ {
+ // Don't emit the same utility twice for this target.
+ if(emitted.insert(*util).second)
+ {
+ this->AddTargetDepend(depender_index, *util, false);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
+ cmTarget const* dependee,
+ const std::string& config,
+ std::set<std::string> &emitted)
+{
+ cmTarget const* depender = this->Targets[depender_index];
+ if(cmTarget::LinkInterface const* iface =
+ dependee->GetLinkInterface(config, depender))
+ {
+ for(std::vector<cmLinkItem>::const_iterator
+ lib = iface->Libraries.begin();
+ lib != iface->Libraries.end(); ++lib)
+ {
+ // Don't emit the same library twice for this target.
+ if(emitted.insert(*lib).second)
+ {
+ this->AddTargetDepend(depender_index, *lib, true);
+ this->AddInterfaceDepends(depender_index, *lib, emitted);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
+ cmLinkItem const& dependee_name,
+ std::set<std::string> &emitted)
+{
+ cmTarget const* depender = this->Targets[depender_index];
+ cmTarget 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->IsExecutableWithExports())
+ {
+ dependee = 0;
+ }
+
+ if(dependee)
+ {
+ this->AddInterfaceDepends(depender_index, dependee, "", emitted);
+ std::vector<std::string> configs;
+ depender->GetMakefile()->GetConfigurations(configs);
+ for (std::vector<std::string>::const_iterator it = configs.begin();
+ it != configs.end(); ++it)
+ {
+ // A target should not depend on itself.
+ emitted.insert(depender->GetName());
+ this->AddInterfaceDepends(depender_index, dependee,
+ *it, emitted);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeTargetDepends::AddTargetDepend(
+ int depender_index, cmLinkItem const& dependee_name,
+ bool linking)
+{
+ // Get the depender.
+ cmTarget const* depender = this->Targets[depender_index];
+
+ // Check the target's makefile first.
+ cmTarget const* dependee = dependee_name.Target;
+
+ if(!dependee && !linking &&
+ (depender->GetType() != cmTarget::GLOBAL_TARGET))
+ {
+ cmMakefile *makefile = depender->GetMakefile();
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ bool issueMessage = false;
+ cmOStringStream e;
+ switch(depender->GetPolicyStatusCMP0046())
+ {
+ case cmPolicies::WARN:
+ e << (makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0046)) << "\n";
+ issueMessage = true;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ issueMessage = true;
+ messageType = cmake::FATAL_ERROR;
+ }
+ if(issueMessage)
+ {
+ cmake* cm = this->GlobalGenerator->GetCMakeInstance();
+
+ e << "The dependency target \"" << dependee_name
+ << "\" of target \"" << depender->GetName() << "\" does not exist.";
+
+ cmListFileBacktrace const* backtrace =
+ depender->GetUtilityBacktrace(dependee_name);
+ if(backtrace)
+ {
+ cm->IssueMessage(messageType, e.str(), *backtrace);
+ }
+ else
+ {
+ cm->IssueMessage(messageType, e.str());
+ }
+
+ }
+ }
+
+ // 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(linking && dependee &&
+ dependee->GetType() == cmTarget::EXECUTABLE &&
+ !dependee->IsExecutableWithExports())
+ {
+ dependee = 0;
+ }
+
+ if(dependee)
+ {
+ this->AddTargetDepend(depender_index, dependee, linking);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmComputeTargetDepends::AddTargetDepend(int depender_index,
+ cmTarget const* dependee,
+ bool linking)
+{
+ if(dependee->IsImported())
+ {
+ // Skip imported targets but follow their utility dependencies.
+ 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)
+ {
+ this->AddTargetDepend(depender_index, transitive_dependee, false);
+ }
+ }
+ }
+ else
+ {
+ // Lookup the index for this target. All targets should be known by
+ // this point.
+ std::map<cmTarget const*, int>::const_iterator tii =
+ this->TargetIndex.find(dependee);
+ assert(tii != this->TargetIndex.end());
+ int dependee_index = tii->second;
+
+ // Add this entry to the dependency graph.
+ this->InitialGraph[depender_index].push_back(
+ cmGraphEdge(dependee_index, !linking));
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmComputeTargetDepends::DisplayGraph(Graph const& graph,
+ const std::string& name)
+{
+ fprintf(stderr, "The %s target dependency graph is:\n", name.c_str());
+ int n = static_cast<int>(graph.size());
+ for(int depender_index = 0; depender_index < n; ++depender_index)
+ {
+ EdgeList const& nl = graph[depender_index];
+ cmTarget const* depender = this->Targets[depender_index];
+ fprintf(stderr, "target %d is [%s]\n",
+ depender_index, depender->GetName().c_str());
+ for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
+ {
+ int dependee_index = *ni;
+ cmTarget const* dependee = this->Targets[dependee_index];
+ fprintf(stderr, " depends on target %d [%s] (%s)\n", dependee_index,
+ dependee->GetName().c_str(), ni->IsStrong()? "strong" : "weak");
+ }
+ }
+ fprintf(stderr, "\n");
+}
+
+//----------------------------------------------------------------------------
+void
+cmComputeTargetDepends
+::DisplayComponents(cmComputeComponentGraph const& ccg)
+{
+ fprintf(stderr, "The strongly connected components are:\n");
+ std::vector<NodeList> const& components = ccg.GetComponents();
+ int n = static_cast<int>(components.size());
+ for(int c = 0; c < n; ++c)
+ {
+ NodeList const& nl = components[c];
+ fprintf(stderr, "Component (%d):\n", c);
+ for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
+ {
+ int i = *ni;
+ fprintf(stderr, " contains target %d [%s]\n",
+ i, this->Targets[i]->GetName().c_str());
+ }
+ }
+ fprintf(stderr, "\n");
+}
+
+//----------------------------------------------------------------------------
+bool
+cmComputeTargetDepends
+::CheckComponents(cmComputeComponentGraph const& ccg)
+{
+ // All non-trivial components should consist only of static
+ // libraries.
+ std::vector<NodeList> const& components = ccg.GetComponents();
+ int nc = static_cast<int>(components.size());
+ for(int c=0; c < nc; ++c)
+ {
+ // Get the current component.
+ NodeList const& nl = components[c];
+
+ // Skip trivial components.
+ if(nl.size() < 2)
+ {
+ continue;
+ }
+
+ // Immediately complain if no cycles are allowed at all.
+ if(this->NoCycles)
+ {
+ this->ComplainAboutBadComponent(ccg, c);
+ return false;
+ }
+
+ // 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)
+ {
+ this->ComplainAboutBadComponent(ccg, c);
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void
+cmComputeTargetDepends
+::ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, int c,
+ bool strong)
+{
+ // Construct the error message.
+ cmOStringStream e;
+ e << "The inter-target dependency graph contains the following "
+ << "strongly connected component (cycle):\n";
+ std::vector<NodeList> const& components = ccg.GetComponents();
+ std::vector<int> const& cmap = ccg.GetComponentMap();
+ NodeList const& cl = components[c];
+ for(NodeList::const_iterator ci = cl.begin(); ci != cl.end(); ++ci)
+ {
+ // Get the depender.
+ int i = *ci;
+ cmTarget const* depender = this->Targets[i];
+
+ // Describe the depender.
+ e << " \"" << depender->GetName() << "\" of type "
+ << cmTarget::GetTargetTypeName(depender->GetType()) << "\n";
+
+ // List its dependencies that are inside the component.
+ EdgeList const& nl = this->InitialGraph[i];
+ for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
+ {
+ int j = *ni;
+ if(cmap[j] == c)
+ {
+ cmTarget const* dependee = this->Targets[j];
+ e << " depends on \"" << dependee->GetName() << "\""
+ << " (" << (ni->IsStrong()? "strong" : "weak") << ")\n";
+ }
+ }
+ }
+ if(strong)
+ {
+ // Custom command executable dependencies cannot occur within a
+ // component of static libraries. The cycle must appear in calls
+ // to add_dependencies.
+ e << "The component contains at least one cycle consisting of strong "
+ << "dependencies (created by add_dependencies) that cannot be broken.";
+ }
+ else if(this->NoCycles)
+ {
+ e << "The GLOBAL_DEPENDS_NO_CYCLES global property is enabled, so "
+ << "cyclic dependencies are not allowed even among static libraries.";
+ }
+ else
+ {
+ e << "At least one of these targets is not a STATIC_LIBRARY. "
+ << "Cyclic dependencies are allowed only among static libraries.";
+ }
+ cmSystemTools::Error(e.str().c_str());
+}
+
+//----------------------------------------------------------------------------
+bool
+cmComputeTargetDepends
+::IntraComponent(std::vector<int> const& cmap, int c, int i, int* head,
+ std::set<int>& emitted, std::set<int>& visited)
+{
+ if(!visited.insert(i).second)
+ {
+ // Cycle in utility depends!
+ return false;
+ }
+ if(emitted.insert(i).second)
+ {
+ // Honor strong intra-component edges in the final order.
+ EdgeList const& el = this->InitialGraph[i];
+ for(EdgeList::const_iterator ei = el.begin(); ei != el.end(); ++ei)
+ {
+ int j = *ei;
+ if(cmap[j] == c && ei->IsStrong())
+ {
+ this->FinalGraph[i].push_back(cmGraphEdge(j, true));
+ if(!this->IntraComponent(cmap, c, j, head, emitted, visited))
+ {
+ return false;
+ }
+ }
+ }
+
+ // Prepend to a linear linked-list of intra-component edges.
+ if(*head >= 0)
+ {
+ this->FinalGraph[i].push_back(cmGraphEdge(*head, false));
+ }
+ else
+ {
+ this->ComponentTail[c] = i;
+ }
+ *head = i;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmComputeTargetDepends
+::ComputeFinalDepends(cmComputeComponentGraph const& ccg)
+{
+ // Get the component graph information.
+ std::vector<NodeList> const& components = ccg.GetComponents();
+ Graph const& cgraph = ccg.GetComponentGraph();
+
+ // Allocate the final graph.
+ this->FinalGraph.resize(0);
+ this->FinalGraph.resize(this->InitialGraph.size());
+
+ // Choose intra-component edges to linearize dependencies.
+ std::vector<int> const& cmap = ccg.GetComponentMap();
+ this->ComponentHead.resize(components.size());
+ this->ComponentTail.resize(components.size());
+ int nc = static_cast<int>(components.size());
+ for(int c=0; c < nc; ++c)
+ {
+ int head = -1;
+ std::set<int> emitted;
+ NodeList const& nl = components[c];
+ for(NodeList::const_reverse_iterator ni = nl.rbegin();
+ ni != nl.rend(); ++ni)
+ {
+ std::set<int> visited;
+ if(!this->IntraComponent(cmap, c, *ni, &head, emitted, visited))
+ {
+ // Cycle in add_dependencies within component!
+ this->ComplainAboutBadComponent(ccg, c, true);
+ return false;
+ }
+ }
+ this->ComponentHead[c] = head;
+ }
+
+ // Convert inter-component edges to connect component tails to heads.
+ int n = static_cast<int>(cgraph.size());
+ for(int depender_component=0; depender_component < n; ++depender_component)
+ {
+ int depender_component_tail = this->ComponentTail[depender_component];
+ EdgeList const& nl = cgraph[depender_component];
+ for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
+ {
+ int dependee_component = *ni;
+ int dependee_component_head = this->ComponentHead[dependee_component];
+ this->FinalGraph[depender_component_tail]
+ .push_back(cmGraphEdge(dependee_component_head, ni->IsStrong()));
+ }
+ }
+ return true;
+}
diff --git a/Source/cmComputeTargetDepends.h b/Source/cmComputeTargetDepends.h
new file mode 100644
index 0000000000..902f342bf5
--- /dev/null
+++ b/Source/cmComputeTargetDepends.h
@@ -0,0 +1,91 @@
+/*============================================================================
+ 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 cmComputeTargetDepends_h
+#define cmComputeTargetDepends_h
+
+#include "cmStandardIncludes.h"
+
+#include "cmGraphAdjacencyList.h"
+
+#include <stack>
+
+class cmComputeComponentGraph;
+class cmGlobalGenerator;
+class cmLinkItem;
+class cmTarget;
+class cmTargetDependSet;
+
+/** \class cmComputeTargetDepends
+ * \brief Compute global interdependencies among targets.
+ *
+ * Static libraries may form cycles in the target dependency graph.
+ * This class evaluates target dependencies globally and adjusts them
+ * to remove cycles while preserving a safe build order.
+ */
+class cmComputeTargetDepends
+{
+public:
+ cmComputeTargetDepends(cmGlobalGenerator* gg);
+ ~cmComputeTargetDepends();
+
+ bool Compute();
+
+ std::vector<cmTarget const*> const&
+ GetTargets() const { return this->Targets; }
+ void GetTargetDirectDepends(cmTarget const* t, cmTargetDependSet& deps);
+private:
+ void CollectTargets();
+ void CollectDepends();
+ void CollectTargetDepends(int depender_index);
+ void AddTargetDepend(int depender_index,
+ cmLinkItem const& dependee_name,
+ bool linking);
+ void AddTargetDepend(int depender_index, cmTarget const* dependee,
+ bool linking);
+ bool ComputeFinalDepends(cmComputeComponentGraph const& ccg);
+ void AddInterfaceDepends(int depender_index,
+ cmLinkItem const& dependee_name,
+ std::set<std::string> &emitted);
+ void AddInterfaceDepends(int depender_index, cmTarget const* dependee,
+ const std::string& config,
+ std::set<std::string> &emitted);
+ cmGlobalGenerator* GlobalGenerator;
+ bool DebugMode;
+ bool NoCycles;
+
+ // Collect all targets.
+ std::vector<cmTarget const*> Targets;
+ std::map<cmTarget const*, int> TargetIndex;
+
+ // Represent the target dependency graph. The entry at each
+ // top-level index corresponds to a depender whose dependencies are
+ // listed.
+ typedef cmGraphNodeList NodeList;
+ typedef cmGraphEdgeList EdgeList;
+ typedef cmGraphAdjacencyList Graph;
+ Graph InitialGraph;
+ Graph FinalGraph;
+ void DisplayGraph(Graph const& graph, const std::string& name);
+
+ // Deal with connected components.
+ void DisplayComponents(cmComputeComponentGraph const& ccg);
+ bool CheckComponents(cmComputeComponentGraph const& ccg);
+ void ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, int c,
+ bool strong = false);
+
+ std::vector<int> ComponentHead;
+ std::vector<int> ComponentTail;
+ bool IntraComponent(std::vector<int> const& cmap, int c, int i, int* head,
+ std::set<int>& emitted, std::set<int>& visited);
+};
+
+#endif
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx
new file mode 100644
index 0000000000..aba26de10c
--- /dev/null
+++ b/Source/cmConditionEvaluator.cxx
@@ -0,0 +1,770 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 "cmConditionEvaluator.h"
+
+cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile):
+ Makefile(makefile),
+ Policy12Status(makefile.GetPolicyStatus(cmPolicies::CMP0012)),
+ Policy54Status(makefile.GetPolicyStatus(cmPolicies::CMP0054))
+{
+
+}
+
+//=========================================================================
+// order of operations,
+// 1. ( ) -- parenthetical groups
+// 2. IS_DIRECTORY EXISTS COMMAND DEFINED etc predicates
+// 3. MATCHES LESS GREATER EQUAL STRLESS STRGREATER STREQUAL etc binary ops
+// 4. NOT
+// 5. AND OR
+//
+// There is an issue on whether the arguments should be values of references,
+// for example IF (FOO AND BAR) should that compare the strings FOO and BAR
+// or should it really do IF (${FOO} AND ${BAR}) Currently IS_DIRECTORY
+// EXISTS COMMAND and DEFINED all take values. EQUAL, LESS and GREATER can
+// take numeric values or variable names. STRLESS and STRGREATER take
+// variable names but if the variable name is not found it will use the name
+// directly. AND OR take variables or the values 0 or 1.
+
+bool cmConditionEvaluator::IsTrue(
+ const std::vector<cmExpandedCommandArgument> &args,
+ std::string &errorString,
+ cmake::MessageType &status)
+{
+ errorString = "";
+
+ // handle empty invocation
+ if (args.size() < 1)
+ {
+ return false;
+ }
+
+ // store the reduced args in this vector
+ cmArgumentList newArgs;
+
+ // copy to the list structure
+ for(unsigned int i = 0; i < args.size(); ++i)
+ {
+ newArgs.push_back(args[i]);
+ }
+
+ // now loop through the arguments and see if we can reduce any of them
+ // we do this multiple times. Once for each level of precedence
+ // parens
+ if (!this->HandleLevel0(newArgs, errorString, status))
+ {
+ return false;
+ }
+ //predicates
+ if (!this->HandleLevel1(newArgs, errorString, status))
+ {
+ return false;
+ }
+ // binary ops
+ if (!this->HandleLevel2(newArgs, errorString, status))
+ {
+ return false;
+ }
+
+ // NOT
+ if (!this->HandleLevel3(newArgs, errorString, status))
+ {
+ return false;
+ }
+ // AND OR
+ if (!this->HandleLevel4(newArgs, errorString, status))
+ {
+ return false;
+ }
+
+ // now at the end there should only be one argument left
+ if (newArgs.size() != 1)
+ {
+ errorString = "Unknown arguments specified";
+ status = cmake::FATAL_ERROR;
+ return false;
+ }
+
+ return this->GetBooleanValueWithAutoDereference(*(newArgs.begin()),
+ errorString, status, true);
+}
+
+//=========================================================================
+const char* cmConditionEvaluator::GetDefinitionIfUnquoted(
+ cmExpandedCommandArgument const& argument) const
+{
+ if((this->Policy54Status != cmPolicies::WARN &&
+ this->Policy54Status != cmPolicies::OLD) &&
+ argument.WasQuoted())
+ {
+ return 0;
+ }
+
+ const char* def = this->Makefile.GetDefinition(argument.GetValue());
+
+ if(def && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN)
+ {
+ bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported(
+ this->Makefile.GetBacktrace()[0]);
+
+ if(!hasBeenReported)
+ {
+ cmOStringStream e;
+ e << (this->Makefile.GetPolicies()->GetPolicyWarning(
+ cmPolicies::CMP0054)) << "\n";
+ e << "Quoted variables like \"" << argument.GetValue() <<
+ "\" will no longer be dereferenced "
+ "when the policy is set to NEW. "
+ "Since the policy is not set the OLD behavior will be used.";
+
+ this->Makefile.IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ }
+ }
+
+ return def;
+}
+
+//=========================================================================
+const char* cmConditionEvaluator::GetVariableOrString(
+ const cmExpandedCommandArgument& argument) const
+{
+ const char* def = this->GetDefinitionIfUnquoted(argument);
+
+ if(!def)
+ {
+ def = argument.c_str();
+ }
+
+ return def;
+}
+
+//=========================================================================
+bool cmConditionEvaluator::IsKeyword(std::string const& keyword,
+ cmExpandedCommandArgument& argument) const
+{
+ if((this->Policy54Status != cmPolicies::WARN &&
+ this->Policy54Status != cmPolicies::OLD) &&
+ argument.WasQuoted())
+ {
+ return false;
+ }
+
+ bool isKeyword = argument.GetValue() == keyword;
+
+ if(isKeyword && argument.WasQuoted() &&
+ this->Policy54Status == cmPolicies::WARN)
+ {
+ bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported(
+ this->Makefile.GetBacktrace()[0]);
+
+ if(!hasBeenReported)
+ {
+ cmOStringStream e;
+ e << (this->Makefile.GetPolicies()->GetPolicyWarning(
+ cmPolicies::CMP0054)) << "\n";
+ e << "Quoted keywords like \"" << argument.GetValue() <<
+ "\" will no longer be interpreted as keywords "
+ "when the policy is set to NEW. "
+ "Since the policy is not set the OLD behavior will be used.";
+
+ this->Makefile.IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ }
+ }
+
+ return isKeyword;
+}
+
+//=========================================================================
+bool cmConditionEvaluator::GetBooleanValue(
+ cmExpandedCommandArgument& arg) const
+{
+ // Check basic constants.
+ if (arg == "0")
+ {
+ return false;
+ }
+ if (arg == "1")
+ {
+ return true;
+ }
+
+ // Check named constants.
+ if (cmSystemTools::IsOn(arg.c_str()))
+ {
+ return true;
+ }
+ if (cmSystemTools::IsOff(arg.c_str()))
+ {
+ return false;
+ }
+
+ // Check for numbers.
+ if(!arg.empty())
+ {
+ char* end;
+ double d = strtod(arg.c_str(), &end);
+ if(*end == '\0')
+ {
+ // The whole string is a number. Use C conversion to bool.
+ return d? true:false;
+ }
+ }
+
+ // Check definition.
+ const char* def = this->GetDefinitionIfUnquoted(arg);
+ return !cmSystemTools::IsOff(def);
+}
+
+//=========================================================================
+// Boolean value behavior from CMake 2.6.4 and below.
+bool cmConditionEvaluator::GetBooleanValueOld(
+ cmExpandedCommandArgument const& arg, bool one) const
+{
+ if(one)
+ {
+ // Old IsTrue behavior for single argument.
+ if(arg == "0")
+ { return false; }
+ else if(arg == "1")
+ { return true; }
+ else
+ {
+ const char* def = this->GetDefinitionIfUnquoted(arg);
+ return !cmSystemTools::IsOff(def);
+ }
+ }
+ else
+ {
+ // Old GetVariableOrNumber behavior.
+ const char* def = this->GetDefinitionIfUnquoted(arg);
+ if(!def && atoi(arg.c_str()))
+ {
+ def = arg.c_str();
+ }
+ return !cmSystemTools::IsOff(def);
+ }
+}
+
+//=========================================================================
+// returns the resulting boolean value
+bool cmConditionEvaluator::GetBooleanValueWithAutoDereference(
+ cmExpandedCommandArgument &newArg,
+ std::string &errorString,
+ cmake::MessageType &status,
+ bool oneArg) const
+{
+ // Use the policy if it is set.
+ if (this->Policy12Status == cmPolicies::NEW)
+ {
+ return GetBooleanValue(newArg);
+ }
+ else if (this->Policy12Status == cmPolicies::OLD)
+ {
+ return GetBooleanValueOld(newArg, oneArg);
+ }
+
+ // Check policy only if old and new results differ.
+ bool newResult = this->GetBooleanValue(newArg);
+ bool oldResult = this->GetBooleanValueOld(newArg, oneArg);
+ if(newResult != oldResult)
+ {
+ switch(this->Policy12Status)
+ {
+ case cmPolicies::WARN:
+ {
+ cmPolicies* policies = this->Makefile.GetPolicies();
+ errorString = "An argument named \"" + newArg.GetValue()
+ + "\" appears in a conditional statement. "
+ + policies->GetPolicyWarning(cmPolicies::CMP0012);
+ status = cmake::AUTHOR_WARNING;
+ }
+ case cmPolicies::OLD:
+ return oldResult;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ {
+ cmPolicies* policies = this->Makefile.GetPolicies();
+ errorString = "An argument named \"" + newArg.GetValue()
+ + "\" appears in a conditional statement. "
+ + policies->GetRequiredPolicyError(cmPolicies::CMP0012);
+ status = cmake::FATAL_ERROR;
+ }
+ case cmPolicies::NEW:
+ break;
+ }
+ }
+ return newResult;
+}
+
+//=========================================================================
+void cmConditionEvaluator::IncrementArguments(cmArgumentList &newArgs,
+ cmArgumentList::iterator &argP1,
+ cmArgumentList::iterator &argP2) const
+{
+ if (argP1 != newArgs.end())
+ {
+ argP1++;
+ argP2 = argP1;
+ if (argP1 != newArgs.end())
+ {
+ argP2++;
+ }
+ }
+}
+
+//=========================================================================
+// helper function to reduce code duplication
+void cmConditionEvaluator::HandlePredicate(bool value, int &reducible,
+ cmArgumentList::iterator &arg,
+ cmArgumentList &newArgs,
+ cmArgumentList::iterator &argP1,
+ cmArgumentList::iterator &argP2) const
+{
+ if(value)
+ {
+ *arg = cmExpandedCommandArgument("1", true);
+ }
+ else
+ {
+ *arg = cmExpandedCommandArgument("0", true);
+ }
+ newArgs.erase(argP1);
+ argP1 = arg;
+ this->IncrementArguments(newArgs,argP1,argP2);
+ reducible = 1;
+}
+
+//=========================================================================
+// helper function to reduce code duplication
+void cmConditionEvaluator::HandleBinaryOp(bool value, int &reducible,
+ cmArgumentList::iterator &arg,
+ cmArgumentList &newArgs,
+ cmArgumentList::iterator &argP1,
+ cmArgumentList::iterator &argP2)
+{
+ if(value)
+ {
+ *arg = cmExpandedCommandArgument("1", true);
+ }
+ else
+ {
+ *arg = cmExpandedCommandArgument("0", true);
+ }
+ newArgs.erase(argP2);
+ newArgs.erase(argP1);
+ argP1 = arg;
+ this->IncrementArguments(newArgs,argP1,argP2);
+ reducible = 1;
+}
+
+//=========================================================================
+// level 0 processes parenthetical expressions
+bool cmConditionEvaluator::HandleLevel0(cmArgumentList &newArgs,
+ std::string &errorString,
+ cmake::MessageType &status)
+{
+ int reducible;
+ do
+ {
+ reducible = 0;
+ cmArgumentList::iterator arg = newArgs.begin();
+ while (arg != newArgs.end())
+ {
+ if (IsKeyword("(", *arg))
+ {
+ // search for the closing paren for this opening one
+ cmArgumentList::iterator argClose;
+ argClose = arg;
+ argClose++;
+ unsigned int depth = 1;
+ while (argClose != newArgs.end() && depth)
+ {
+ if (this->IsKeyword("(", *argClose))
+ {
+ depth++;
+ }
+ if (this->IsKeyword(")", *argClose))
+ {
+ depth--;
+ }
+ argClose++;
+ }
+ if (depth)
+ {
+ errorString = "mismatched parenthesis in condition";
+ status = cmake::FATAL_ERROR;
+ return false;
+ }
+ // store the reduced args in this vector
+ std::vector<cmExpandedCommandArgument> newArgs2;
+
+ // copy to the list structure
+ cmArgumentList::iterator argP1 = arg;
+ argP1++;
+ for(; argP1 != argClose; argP1++)
+ {
+ newArgs2.push_back(*argP1);
+ }
+ newArgs2.pop_back();
+ // now recursively invoke IsTrue to handle the values inside the
+ // parenthetical expression
+ bool value =
+ this->IsTrue(newArgs2, errorString, status);
+ if(value)
+ {
+ *arg = cmExpandedCommandArgument("1", true);
+ }
+ else
+ {
+ *arg = cmExpandedCommandArgument("0", true);
+ }
+ argP1 = arg;
+ argP1++;
+ // remove the now evaluated parenthetical expression
+ newArgs.erase(argP1,argClose);
+ }
+ ++arg;
+ }
+ }
+ while (reducible);
+ return true;
+}
+
+//=========================================================================
+// level one handles most predicates except for NOT
+bool cmConditionEvaluator::HandleLevel1(cmArgumentList &newArgs,
+ std::string &, cmake::MessageType &)
+{
+ int reducible;
+ do
+ {
+ reducible = 0;
+ cmArgumentList::iterator arg = newArgs.begin();
+ cmArgumentList::iterator argP1;
+ cmArgumentList::iterator argP2;
+ while (arg != newArgs.end())
+ {
+ argP1 = arg;
+ this->IncrementArguments(newArgs,argP1,argP2);
+ // does a file exist
+ if (this->IsKeyword("EXISTS", *arg) && argP1 != newArgs.end())
+ {
+ this->HandlePredicate(
+ cmSystemTools::FileExists(argP1->c_str()),
+ reducible, arg, newArgs, argP1, argP2);
+ }
+ // does a directory with this name exist
+ if (this->IsKeyword("IS_DIRECTORY", *arg) && argP1 != newArgs.end())
+ {
+ this->HandlePredicate(
+ cmSystemTools::FileIsDirectory(argP1->c_str()),
+ reducible, arg, newArgs, argP1, argP2);
+ }
+ // does a symlink with this name exist
+ if (this->IsKeyword("IS_SYMLINK", *arg) && argP1 != newArgs.end())
+ {
+ this->HandlePredicate(
+ cmSystemTools::FileIsSymlink(argP1->c_str()),
+ reducible, arg, newArgs, argP1, argP2);
+ }
+ // is the given path an absolute path ?
+ if (this->IsKeyword("IS_ABSOLUTE", *arg) && argP1 != newArgs.end())
+ {
+ this->HandlePredicate(
+ cmSystemTools::FileIsFullPath(argP1->c_str()),
+ reducible, arg, newArgs, argP1, argP2);
+ }
+ // does a command exist
+ if (this->IsKeyword("COMMAND", *arg) && argP1 != newArgs.end())
+ {
+ this->HandlePredicate(
+ this->Makefile.CommandExists(argP1->c_str()),
+ reducible, arg, newArgs, argP1, argP2);
+ }
+ // does a policy exist
+ if (this->IsKeyword("POLICY", *arg) && argP1 != newArgs.end())
+ {
+ cmPolicies::PolicyID pid;
+ this->HandlePredicate(
+ this->Makefile.GetPolicies()->GetPolicyID(
+ argP1->c_str(), pid),
+ reducible, arg, newArgs, argP1, argP2);
+ }
+ // does a target exist
+ if (this->IsKeyword("TARGET", *arg) && argP1 != newArgs.end())
+ {
+ this->HandlePredicate(
+ this->Makefile.FindTargetToUse(argP1->GetValue())?true:false,
+ reducible, arg, newArgs, argP1, argP2);
+ }
+ // is a variable defined
+ if (this->IsKeyword("DEFINED", *arg) && argP1 != newArgs.end())
+ {
+ size_t argP1len = argP1->GetValue().size();
+ bool bdef = false;
+ if(argP1len > 4 && argP1->GetValue().substr(0, 4) == "ENV{" &&
+ argP1->GetValue().operator[](argP1len-1) == '}')
+ {
+ std::string env = argP1->GetValue().substr(4, argP1len-5);
+ bdef = cmSystemTools::GetEnv(env.c_str())?true:false;
+ }
+ else
+ {
+ bdef = this->Makefile.IsDefinitionSet(argP1->GetValue());
+ }
+ this->HandlePredicate(bdef, reducible, arg, newArgs, argP1, argP2);
+ }
+ ++arg;
+ }
+ }
+ while (reducible);
+ return true;
+}
+
+//=========================================================================
+// level two handles most binary operations except for AND OR
+bool cmConditionEvaluator::HandleLevel2(cmArgumentList &newArgs,
+ std::string &errorString,
+ cmake::MessageType &status)
+{
+ int reducible;
+ const char *def;
+ const char *def2;
+ do
+ {
+ reducible = 0;
+ cmArgumentList::iterator arg = newArgs.begin();
+ cmArgumentList::iterator argP1;
+ cmArgumentList::iterator argP2;
+ while (arg != newArgs.end())
+ {
+ argP1 = arg;
+ this->IncrementArguments(newArgs,argP1,argP2);
+ if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
+ IsKeyword("MATCHES", *argP1))
+ {
+ def = this->GetVariableOrString(*arg);
+ const char* rex = argP2->c_str();
+ this->Makefile.ClearMatches();
+ cmsys::RegularExpression regEntry;
+ if ( !regEntry.compile(rex) )
+ {
+ cmOStringStream error;
+ error << "Regular expression \"" << rex << "\" cannot compile";
+ errorString = error.str();
+ status = cmake::FATAL_ERROR;
+ return false;
+ }
+ if (regEntry.find(def))
+ {
+ this->Makefile.StoreMatches(regEntry);
+ *arg = cmExpandedCommandArgument("1", true);
+ }
+ else
+ {
+ *arg = cmExpandedCommandArgument("0", true);
+ }
+ newArgs.erase(argP2);
+ newArgs.erase(argP1);
+ argP1 = arg;
+ this->IncrementArguments(newArgs,argP1,argP2);
+ reducible = 1;
+ }
+
+ if (argP1 != newArgs.end() && this->IsKeyword("MATCHES", *arg))
+ {
+ *arg = cmExpandedCommandArgument("0", true);
+ newArgs.erase(argP1);
+ argP1 = arg;
+ this->IncrementArguments(newArgs,argP1,argP2);
+ reducible = 1;
+ }
+
+ if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
+ (this->IsKeyword("LESS", *argP1) ||
+ this->IsKeyword("GREATER", *argP1) ||
+ this->IsKeyword("EQUAL", *argP1)))
+ {
+ def = this->GetVariableOrString(*arg);
+ def2 = this->GetVariableOrString(*argP2);
+ double lhs;
+ double rhs;
+ bool result;
+ if(sscanf(def, "%lg", &lhs) != 1 ||
+ sscanf(def2, "%lg", &rhs) != 1)
+ {
+ result = false;
+ }
+ else if (*(argP1) == "LESS")
+ {
+ result = (lhs < rhs);
+ }
+ else if (*(argP1) == "GREATER")
+ {
+ result = (lhs > rhs);
+ }
+ else
+ {
+ result = (lhs == rhs);
+ }
+ this->HandleBinaryOp(result,
+ reducible, arg, newArgs, argP1, argP2);
+ }
+
+ if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
+ (this->IsKeyword("STRLESS", *argP1) ||
+ this->IsKeyword("STREQUAL", *argP1) ||
+ this->IsKeyword("STRGREATER", *argP1)))
+ {
+ def = this->GetVariableOrString(*arg);
+ def2 = this->GetVariableOrString(*argP2);
+ int val = strcmp(def,def2);
+ bool result;
+ if (*(argP1) == "STRLESS")
+ {
+ result = (val < 0);
+ }
+ else if (*(argP1) == "STRGREATER")
+ {
+ result = (val > 0);
+ }
+ else // strequal
+ {
+ result = (val == 0);
+ }
+ this->HandleBinaryOp(result,
+ reducible, arg, newArgs, argP1, argP2);
+ }
+
+ if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
+ (this->IsKeyword("VERSION_LESS", *argP1) ||
+ this->IsKeyword("VERSION_GREATER", *argP1) ||
+ this->IsKeyword("VERSION_EQUAL", *argP1)))
+ {
+ def = this->GetVariableOrString(*arg);
+ def2 = this->GetVariableOrString(*argP2);
+ cmSystemTools::CompareOp op = cmSystemTools::OP_EQUAL;
+ if(*argP1 == "VERSION_LESS")
+ {
+ op = cmSystemTools::OP_LESS;
+ }
+ else if(*argP1 == "VERSION_GREATER")
+ {
+ op = cmSystemTools::OP_GREATER;
+ }
+ bool result = cmSystemTools::VersionCompare(op, def, def2);
+ this->HandleBinaryOp(result,
+ reducible, arg, newArgs, argP1, argP2);
+ }
+
+ // is file A newer than file B
+ if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
+ this->IsKeyword("IS_NEWER_THAN", *argP1))
+ {
+ int fileIsNewer=0;
+ bool success=cmSystemTools::FileTimeCompare(arg->GetValue(),
+ (argP2)->GetValue(),
+ &fileIsNewer);
+ this->HandleBinaryOp(
+ (success==false || fileIsNewer==1 || fileIsNewer==0),
+ reducible, arg, newArgs, argP1, argP2);
+ }
+
+ ++arg;
+ }
+ }
+ while (reducible);
+ return true;
+}
+
+//=========================================================================
+// level 3 handles NOT
+bool cmConditionEvaluator::HandleLevel3(cmArgumentList &newArgs,
+ std::string &errorString,
+ cmake::MessageType &status)
+{
+ int reducible;
+ do
+ {
+ reducible = 0;
+ cmArgumentList::iterator arg = newArgs.begin();
+ cmArgumentList::iterator argP1;
+ cmArgumentList::iterator argP2;
+ while (arg != newArgs.end())
+ {
+ argP1 = arg;
+ IncrementArguments(newArgs,argP1,argP2);
+ if (argP1 != newArgs.end() && IsKeyword("NOT", *arg))
+ {
+ bool rhs = this->GetBooleanValueWithAutoDereference(*argP1,
+ errorString,
+ status);
+ this->HandlePredicate(!rhs, reducible, arg, newArgs, argP1, argP2);
+ }
+ ++arg;
+ }
+ }
+ while (reducible);
+ return true;
+}
+
+//=========================================================================
+// level 4 handles AND OR
+bool cmConditionEvaluator::HandleLevel4(cmArgumentList &newArgs,
+ std::string &errorString,
+ cmake::MessageType &status)
+{
+ int reducible;
+ bool lhs;
+ bool rhs;
+ do
+ {
+ reducible = 0;
+ cmArgumentList::iterator arg = newArgs.begin();
+ cmArgumentList::iterator argP1;
+ cmArgumentList::iterator argP2;
+ while (arg != newArgs.end())
+ {
+ argP1 = arg;
+ IncrementArguments(newArgs,argP1,argP2);
+ if (argP1 != newArgs.end() && IsKeyword("AND", *argP1) &&
+ argP2 != newArgs.end())
+ {
+ lhs = this->GetBooleanValueWithAutoDereference(*arg,
+ errorString,
+ status);
+ rhs = this->GetBooleanValueWithAutoDereference(*argP2,
+ errorString,
+ status);
+ this->HandleBinaryOp((lhs && rhs),
+ reducible, arg, newArgs, argP1, argP2);
+ }
+
+ if (argP1 != newArgs.end() && this->IsKeyword("OR", *argP1) &&
+ argP2 != newArgs.end())
+ {
+ lhs = this->GetBooleanValueWithAutoDereference(*arg,
+ errorString,
+ status);
+ rhs = this->GetBooleanValueWithAutoDereference(*argP2,
+ errorString,
+ status);
+ this->HandleBinaryOp((lhs || rhs),
+ reducible, arg, newArgs, argP1, argP2);
+ }
+ ++arg;
+ }
+ }
+ while (reducible);
+ return true;
+}
diff --git a/Source/cmConditionEvaluator.h b/Source/cmConditionEvaluator.h
new file mode 100644
index 0000000000..01624f92cb
--- /dev/null
+++ b/Source/cmConditionEvaluator.h
@@ -0,0 +1,96 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmConditionEvaluator_h
+#define cmConditionEvaluator_h
+
+#include "cmCommand.h"
+#include "cmExpandedCommandArgument.h"
+
+class cmConditionEvaluator
+{
+public:
+ typedef std::list<cmExpandedCommandArgument> cmArgumentList;
+
+ cmConditionEvaluator(cmMakefile& makefile);
+
+ // this is a shared function for both If and Else to determine if the
+ // arguments were valid, and if so, was the response true. If there is
+ // an error, the errorString will be set.
+ bool IsTrue(const std::vector<cmExpandedCommandArgument> &args,
+ std::string &errorString,
+ cmake::MessageType &status);
+
+private:
+ // Filter the given variable definition based on policy CMP0054.
+ const char* GetDefinitionIfUnquoted(
+ const cmExpandedCommandArgument& argument) const;
+
+ const char* GetVariableOrString(
+ const cmExpandedCommandArgument& argument) const;
+
+ bool IsKeyword(std::string const& keyword,
+ cmExpandedCommandArgument& argument) const;
+
+ bool GetBooleanValue(
+ cmExpandedCommandArgument& arg) const;
+
+ bool GetBooleanValueOld(
+ cmExpandedCommandArgument const& arg, bool one) const;
+
+ bool GetBooleanValueWithAutoDereference(
+ cmExpandedCommandArgument &newArg,
+ std::string &errorString,
+ cmake::MessageType &status,
+ bool oneArg = false) const;
+
+ void IncrementArguments(
+ cmArgumentList &newArgs,
+ cmArgumentList::iterator &argP1,
+ cmArgumentList::iterator &argP2) const;
+
+ void HandlePredicate(bool value, int &reducible,
+ cmArgumentList::iterator &arg,
+ cmArgumentList &newArgs,
+ cmArgumentList::iterator &argP1,
+ cmArgumentList::iterator &argP2) const;
+
+ void HandleBinaryOp(bool value, int &reducible,
+ cmArgumentList::iterator &arg,
+ cmArgumentList &newArgs,
+ cmArgumentList::iterator &argP1,
+ cmArgumentList::iterator &argP2);
+
+ bool HandleLevel0(cmArgumentList &newArgs,
+ std::string &errorString,
+ cmake::MessageType &status);
+
+ bool HandleLevel1(cmArgumentList &newArgs,
+ std::string &, cmake::MessageType &);
+
+ bool HandleLevel2(cmArgumentList &newArgs,
+ std::string &errorString,
+ cmake::MessageType &status);
+
+ bool HandleLevel3(cmArgumentList &newArgs,
+ std::string &errorString,
+ cmake::MessageType &status);
+
+ bool HandleLevel4(cmArgumentList &newArgs,
+ std::string &errorString,
+ cmake::MessageType &status);
+
+ cmMakefile& Makefile;
+ cmPolicies::PolicyStatus Policy12Status;
+ cmPolicies::PolicyStatus Policy54Status;
+};
+
+#endif
diff --git a/Source/cmConfigure.cmake.h.in b/Source/cmConfigure.cmake.h.in
new file mode 100644
index 0000000000..2b0280db5a
--- /dev/null
+++ b/Source/cmConfigure.cmake.h.in
@@ -0,0 +1,20 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#cmakedefine CMAKE_NO_STD_NAMESPACE
+#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS
+#cmakedefine CMAKE_NO_ANSI_STRING_STREAM
+#cmakedefine CMAKE_NO_ANSI_FOR_SCOPE
+#cmakedefine HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE
+#cmakedefine HAVE_UNSETENV
+#cmakedefine CMAKE_USE_ELF_PARSER
+#cmakedefine CMAKE_ENCODING_UTF8
+#define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@"
diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx
new file mode 100644
index 0000000000..395e6c8b63
--- /dev/null
+++ b/Source/cmConfigureFileCommand.cxx
@@ -0,0 +1,124 @@
+/*============================================================================
+ 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 "cmConfigureFileCommand.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+// cmConfigureFileCommand
+bool cmConfigureFileCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments, expected 2");
+ return false;
+ }
+
+ const char* inFile = args[0].c_str();
+ if(!cmSystemTools::FileIsFullPath(inFile))
+ {
+ this->InputFile = this->Makefile->GetCurrentDirectory();
+ this->InputFile += "/";
+ }
+ this->InputFile += inFile;
+
+ // If the input location is a directory, error out.
+ if(cmSystemTools::FileIsDirectory(this->InputFile.c_str()))
+ {
+ cmOStringStream e;
+ e << "input location\n"
+ << " " << this->InputFile << "\n"
+ << "is a directory but a file was expected.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ const char* outFile = args[1].c_str();
+ if(!cmSystemTools::FileIsFullPath(outFile))
+ {
+ this->OutputFile = this->Makefile->GetCurrentOutputDirectory();
+ this->OutputFile += "/";
+ }
+ this->OutputFile += outFile;
+
+ // If the output location is already a directory put the file in it.
+ if(cmSystemTools::FileIsDirectory(this->OutputFile.c_str()))
+ {
+ this->OutputFile += "/";
+ this->OutputFile += cmSystemTools::GetFilenameName(inFile);
+ }
+
+ if ( !this->Makefile->CanIWriteThisFile(this->OutputFile.c_str()) )
+ {
+ std::string e = "attempted to configure a file: " + this->OutputFile
+ + " into a source directory.";
+ this->SetError(e);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+ std::string errorMessage;
+ if (!this->NewLineStyle.ReadFromArguments(args, errorMessage))
+ {
+ this->SetError(errorMessage);
+ return false;
+ }
+ this->CopyOnly = false;
+ this->EscapeQuotes = false;
+
+ this->AtOnly = false;
+ for(unsigned int i=2;i < args.size();++i)
+ {
+ if(args[i] == "COPYONLY")
+ {
+ this->CopyOnly = true;
+ if (this->NewLineStyle.IsValid())
+ {
+ this->SetError("COPYONLY could not be used in combination "
+ "with NEWLINE_STYLE");
+ return false;
+ }
+ }
+ else if(args[i] == "ESCAPE_QUOTES")
+ {
+ this->EscapeQuotes = true;
+ }
+ else if(args[i] == "@ONLY")
+ {
+ this->AtOnly = true;
+ }
+ else if(args[i] == "IMMEDIATE")
+ {
+ /* Ignore legacy option. */
+ }
+ }
+
+ if ( !this->ConfigureFile() )
+ {
+ this->SetError("Problem configuring file");
+ return false;
+ }
+
+ return true;
+}
+
+int cmConfigureFileCommand::ConfigureFile()
+{
+ return this->Makefile->ConfigureFile(
+ this->InputFile.c_str(),
+ this->OutputFile.c_str(),
+ this->CopyOnly,
+ this->AtOnly,
+ this->EscapeQuotes,
+ this->NewLineStyle);
+}
+
+
diff --git a/Source/cmConfigureFileCommand.h b/Source/cmConfigureFileCommand.h
new file mode 100644
index 0000000000..8155ef7364
--- /dev/null
+++ b/Source/cmConfigureFileCommand.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 cmConfigureFileCommand_h
+#define cmConfigureFileCommand_h
+
+#include "cmCommand.h"
+
+class cmConfigureFileCommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmConfigureFileCommand, cmCommand);
+
+ virtual cmCommand* Clone()
+ {
+ return new cmConfigureFileCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "configure_file";}
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+private:
+ int ConfigureFile();
+
+ cmNewLineStyle NewLineStyle;
+
+ std::string InputFile;
+ std::string OutputFile;
+ bool CopyOnly;
+ bool EscapeQuotes;
+ bool AtOnly;
+};
+
+
+
+#endif
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
new file mode 100644
index 0000000000..bc5708d35e
--- /dev/null
+++ b/Source/cmCoreTryCompile.cxx
@@ -0,0 +1,667 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2011 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 "cmCoreTryCompile.h"
+#include "cmake.h"
+#include "cmCacheManager.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmExportTryCompileFileGenerator.h"
+#include <cmsys/Directory.hxx>
+
+#include <assert.h>
+
+int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
+{
+ this->BinaryDirectory = argv[1].c_str();
+ this->OutputFile = "";
+ // which signature were we called with ?
+ this->SrcFileSignature = true;
+
+ const char* sourceDirectory = argv[2].c_str();
+ const char* projectName = 0;
+ std::string targetName;
+ std::vector<std::string> cmakeFlags;
+ std::vector<std::string> compileDefs;
+ std::string outputVariable;
+ std::string copyFile;
+ std::string copyFileError;
+ std::vector<cmTarget const*> targets;
+ std::string libsToLink = " ";
+ bool useOldLinkLibs = true;
+ char targetNameBuf[64];
+ bool didOutputVariable = false;
+ bool didCopyFile = false;
+ bool didCopyFileError = false;
+ bool useSources = argv[2] == "SOURCES";
+ std::vector<std::string> sources;
+
+ enum Doing { DoingNone, DoingCMakeFlags, DoingCompileDefinitions,
+ DoingLinkLibraries, DoingOutputVariable, DoingCopyFile,
+ DoingCopyFileError, DoingSources };
+ Doing doing = useSources? DoingSources : DoingNone;
+ for(size_t i=3; i < argv.size(); ++i)
+ {
+ if(argv[i] == "CMAKE_FLAGS")
+ {
+ doing = DoingCMakeFlags;
+ // CMAKE_FLAGS is the first argument because we need an argv[0] that
+ // is not used, so it matches regular command line parsing which has
+ // the program name as arg 0
+ cmakeFlags.push_back(argv[i]);
+ }
+ else if(argv[i] == "COMPILE_DEFINITIONS")
+ {
+ doing = DoingCompileDefinitions;
+ }
+ else if(argv[i] == "LINK_LIBRARIES")
+ {
+ doing = DoingLinkLibraries;
+ useOldLinkLibs = false;
+ }
+ else if(argv[i] == "OUTPUT_VARIABLE")
+ {
+ doing = DoingOutputVariable;
+ didOutputVariable = true;
+ }
+ else if(argv[i] == "COPY_FILE")
+ {
+ doing = DoingCopyFile;
+ didCopyFile = true;
+ }
+ else if(argv[i] == "COPY_FILE_ERROR")
+ {
+ doing = DoingCopyFileError;
+ didCopyFileError = true;
+ }
+ else if(doing == DoingCMakeFlags)
+ {
+ cmakeFlags.push_back(argv[i]);
+ }
+ else if(doing == DoingCompileDefinitions)
+ {
+ compileDefs.push_back(argv[i]);
+ }
+ else if(doing == DoingLinkLibraries)
+ {
+ libsToLink += "\"" + cmSystemTools::TrimWhitespace(argv[i]) + "\" ";
+ if(cmTarget *tgt = this->Makefile->FindTargetToUse(argv[i]))
+ {
+ switch(tgt->GetType())
+ {
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::INTERFACE_LIBRARY:
+ case cmTarget::UNKNOWN_LIBRARY:
+ break;
+ case cmTarget::EXECUTABLE:
+ if (tgt->IsExecutableWithExports())
+ {
+ break;
+ }
+ default:
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "Only libraries may be used as try_compile IMPORTED "
+ "LINK_LIBRARIES. Got " + std::string(tgt->GetName()) + " of "
+ "type " + tgt->GetTargetTypeName(tgt->GetType()) + ".");
+ return -1;
+ }
+ if (tgt->IsImported())
+ {
+ targets.push_back(tgt);
+ }
+ }
+ }
+ else if(doing == DoingOutputVariable)
+ {
+ outputVariable = argv[i].c_str();
+ doing = DoingNone;
+ }
+ else if(doing == DoingCopyFile)
+ {
+ copyFile = argv[i].c_str();
+ doing = DoingNone;
+ }
+ else if(doing == DoingCopyFileError)
+ {
+ copyFileError = argv[i].c_str();
+ doing = DoingNone;
+ }
+ else if(doing == DoingSources)
+ {
+ sources.push_back(argv[i]);
+ }
+ else if(i == 3)
+ {
+ this->SrcFileSignature = false;
+ projectName = argv[i].c_str();
+ }
+ else if(i == 4 && !this->SrcFileSignature)
+ {
+ targetName = argv[i].c_str();
+ }
+ else
+ {
+ cmOStringStream m;
+ m << "try_compile given unknown argument \"" << argv[i] << "\".";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str());
+ }
+ }
+
+ if(didCopyFile && copyFile.empty())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "COPY_FILE must be followed by a file path");
+ return -1;
+ }
+
+ if(didCopyFileError && copyFileError.empty())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "COPY_FILE_ERROR must be followed by a variable name");
+ return -1;
+ }
+
+ if(didCopyFileError && !didCopyFile)
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "COPY_FILE_ERROR may be used only with COPY_FILE");
+ return -1;
+ }
+
+ if(didOutputVariable && outputVariable.empty())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "OUTPUT_VARIABLE must be followed by a variable name");
+ return -1;
+ }
+
+ if(useSources && sources.empty())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "SOURCES must be followed by at least one source file");
+ return -1;
+ }
+
+ // compute the binary dir when TRY_COMPILE is called with a src file
+ // signature
+ if (this->SrcFileSignature)
+ {
+ this->BinaryDirectory += cmake::GetCMakeFilesDirectory();
+ this->BinaryDirectory += "/CMakeTmp";
+ }
+ else
+ {
+ // only valid for srcfile signatures
+ if (compileDefs.size())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "COMPILE_DEFINITIONS specified on a srcdir type TRY_COMPILE");
+ return -1;
+ }
+ if (copyFile.size())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "COPY_FILE specified on a srcdir type TRY_COMPILE");
+ return -1;
+ }
+ }
+ // make sure the binary directory exists
+ cmSystemTools::MakeDirectory(this->BinaryDirectory.c_str());
+
+ // do not allow recursive try Compiles
+ if (this->BinaryDirectory == this->Makefile->GetHomeOutputDirectory())
+ {
+ cmOStringStream e;
+ e << "Attempt at a recursive or nested TRY_COMPILE in directory\n"
+ << " " << this->BinaryDirectory << "\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return -1;
+ }
+
+ std::string outFileName = this->BinaryDirectory + "/CMakeLists.txt";
+ // which signature are we using? If we are using var srcfile bindir
+ if (this->SrcFileSignature)
+ {
+ // remove any CMakeCache.txt files so we will have a clean test
+ std::string ccFile = this->BinaryDirectory + "/CMakeCache.txt";
+ cmSystemTools::RemoveFile(ccFile.c_str());
+
+ // Choose sources.
+ if(!useSources)
+ {
+ sources.push_back(argv[2]);
+ }
+
+ // Detect languages to enable.
+ cmLocalGenerator* lg = this->Makefile->GetLocalGenerator();
+ cmGlobalGenerator* gg = lg->GetGlobalGenerator();
+ std::set<std::string> testLangs;
+ for(std::vector<std::string>::iterator si = sources.begin();
+ si != sources.end(); ++si)
+ {
+ std::string ext = cmSystemTools::GetFilenameLastExtension(*si);
+ std::string lang = gg->GetLanguageFromExtension(ext.c_str());
+ if(!lang.empty())
+ {
+ testLangs.insert(lang);
+ }
+ else
+ {
+ cmOStringStream err;
+ err << "Unknown extension \"" << ext << "\" for file\n"
+ << " " << *si << "\n"
+ << "try_compile() works only for enabled languages. "
+ << "Currently these are:\n ";
+ std::vector<std::string> langs;
+ gg->GetEnabledLanguages(langs);
+ for(std::vector<std::string>::iterator l = langs.begin();
+ l != langs.end(); ++l)
+ {
+ err << " " << *l;
+ }
+ err << "\nSee project() command to enable other languages.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, err.str());
+ return -1;
+ }
+ }
+
+ // we need to create a directory and CMakeLists file etc...
+ // first create the directories
+ sourceDirectory = this->BinaryDirectory.c_str();
+
+ // now create a CMakeLists.txt file in that directory
+ FILE *fout = cmsys::SystemTools::Fopen(outFileName.c_str(),"w");
+ if (!fout)
+ {
+ cmOStringStream e;
+ e << "Failed to open\n"
+ << " " << outFileName << "\n"
+ << cmSystemTools::GetLastSystemError();
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return -1;
+ }
+
+ const char* def = this->Makefile->GetDefinition("CMAKE_MODULE_PATH");
+ fprintf(fout, "cmake_minimum_required(VERSION %u.%u.%u.%u)\n",
+ cmVersion::GetMajorVersion(), cmVersion::GetMinorVersion(),
+ cmVersion::GetPatchVersion(), cmVersion::GetTweakVersion());
+ if(def)
+ {
+ fprintf(fout, "set(CMAKE_MODULE_PATH %s)\n", def);
+ }
+
+ std::string projectLangs;
+ for(std::set<std::string>::iterator li = testLangs.begin();
+ li != testLangs.end(); ++li)
+ {
+ projectLangs += " " + *li;
+ std::string rulesOverrideBase = "CMAKE_USER_MAKE_RULES_OVERRIDE";
+ std::string rulesOverrideLang = rulesOverrideBase + "_" + *li;
+ if(const char* rulesOverridePath =
+ this->Makefile->GetDefinition(rulesOverrideLang))
+ {
+ fprintf(fout, "set(%s \"%s\")\n",
+ rulesOverrideLang.c_str(), rulesOverridePath);
+ }
+ else if(const char* rulesOverridePath2 =
+ this->Makefile->GetDefinition(rulesOverrideBase))
+ {
+ fprintf(fout, "set(%s \"%s\")\n",
+ rulesOverrideBase.c_str(), rulesOverridePath2);
+ }
+ }
+ fprintf(fout, "project(CMAKE_TRY_COMPILE%s)\n", projectLangs.c_str());
+ fprintf(fout, "set(CMAKE_VERBOSE_MAKEFILE 1)\n");
+ for(std::set<std::string>::iterator li = testLangs.begin();
+ li != testLangs.end(); ++li)
+ {
+ std::string langFlags = "CMAKE_" + *li + "_FLAGS";
+ const char* flags = this->Makefile->GetDefinition(langFlags);
+ fprintf(fout, "set(CMAKE_%s_FLAGS %s)\n", li->c_str(),
+ lg->EscapeForCMake(flags?flags:"").c_str());
+ fprintf(fout, "set(CMAKE_%s_FLAGS \"${CMAKE_%s_FLAGS}"
+ " ${COMPILE_DEFINITIONS}\")\n", li->c_str(), li->c_str());
+ }
+ fprintf(fout, "include_directories(${INCLUDE_DIRECTORIES})\n");
+ fprintf(fout, "set(CMAKE_SUPPRESS_REGENERATION 1)\n");
+ fprintf(fout, "link_directories(${LINK_DIRECTORIES})\n");
+ // handle any compile flags we need to pass on
+ if (compileDefs.size())
+ {
+ fprintf(fout, "add_definitions( ");
+ for (size_t i = 0; i < compileDefs.size(); ++i)
+ {
+ fprintf(fout,"%s ",compileDefs[i].c_str());
+ }
+ fprintf(fout, ")\n");
+ }
+
+ /* Use a random file name to avoid rapid creation and deletion
+ of the same executable name (some filesystems fail on that). */
+ sprintf(targetNameBuf, "cmTryCompileExec%u",
+ cmSystemTools::RandomSeed());
+ targetName = targetNameBuf;
+
+ if (!targets.empty())
+ {
+ std::string fname = "/" + std::string(targetName) + "Targets.cmake";
+ cmExportTryCompileFileGenerator tcfg;
+ tcfg.SetExportFile((this->BinaryDirectory + fname).c_str());
+ tcfg.SetExports(targets);
+ tcfg.SetConfig(this->Makefile->GetSafeDefinition(
+ "CMAKE_TRY_COMPILE_CONFIGURATION"));
+
+ if(!tcfg.GenerateImportFile())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "could not write export file.");
+ fclose(fout);
+ return -1;
+ }
+ fprintf(fout,
+ "\ninclude(\"${CMAKE_CURRENT_LIST_DIR}/%s\")\n\n",
+ fname.c_str());
+ }
+
+ /* for the TRY_COMPILEs we want to be able to specify the architecture.
+ So the user can set CMAKE_OSX_ARCHITECTURES to i386;ppc and then set
+ CMAKE_TRY_COMPILE_OSX_ARCHITECTURES first to i386 and then to ppc to
+ have the tests run for each specific architecture. Since
+ cmLocalGenerator doesn't allow building for "the other"
+ architecture only via CMAKE_OSX_ARCHITECTURES.
+ */
+ if(this->Makefile->GetDefinition("CMAKE_TRY_COMPILE_OSX_ARCHITECTURES")!=0)
+ {
+ std::string flag="-DCMAKE_OSX_ARCHITECTURES=";
+ flag += this->Makefile->GetSafeDefinition(
+ "CMAKE_TRY_COMPILE_OSX_ARCHITECTURES");
+ cmakeFlags.push_back(flag);
+ }
+ else if (this->Makefile->GetDefinition("CMAKE_OSX_ARCHITECTURES")!=0)
+ {
+ std::string flag="-DCMAKE_OSX_ARCHITECTURES=";
+ flag += this->Makefile->GetSafeDefinition("CMAKE_OSX_ARCHITECTURES");
+ cmakeFlags.push_back(flag);
+ }
+ /* on APPLE also pass CMAKE_OSX_SYSROOT to the try_compile */
+ if(this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT")!=0)
+ {
+ std::string flag="-DCMAKE_OSX_SYSROOT=";
+ flag += this->Makefile->GetSafeDefinition("CMAKE_OSX_SYSROOT");
+ cmakeFlags.push_back(flag);
+ }
+ /* on APPLE also pass CMAKE_OSX_DEPLOYMENT_TARGET to the try_compile */
+ if(this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET")!=0)
+ {
+ std::string flag="-DCMAKE_OSX_DEPLOYMENT_TARGET=";
+ flag += this->Makefile->GetSafeDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
+ cmakeFlags.push_back(flag);
+ }
+ if (const char *cxxDef
+ = this->Makefile->GetDefinition("CMAKE_CXX_COMPILER_TARGET"))
+ {
+ std::string flag="-DCMAKE_CXX_COMPILER_TARGET=";
+ flag += cxxDef;
+ cmakeFlags.push_back(flag);
+ }
+ if (const char *cDef
+ = this->Makefile->GetDefinition("CMAKE_C_COMPILER_TARGET"))
+ {
+ std::string flag="-DCMAKE_C_COMPILER_TARGET=";
+ flag += cDef;
+ cmakeFlags.push_back(flag);
+ }
+ if (const char *tcxxDef = this->Makefile->GetDefinition(
+ "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN"))
+ {
+ std::string flag="-DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=";
+ flag += tcxxDef;
+ cmakeFlags.push_back(flag);
+ }
+ if (const char *tcDef = this->Makefile->GetDefinition(
+ "CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN"))
+ {
+ std::string flag="-DCMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN=";
+ flag += tcDef;
+ cmakeFlags.push_back(flag);
+ }
+ if (const char *rootDef
+ = this->Makefile->GetDefinition("CMAKE_SYSROOT"))
+ {
+ std::string flag="-DCMAKE_SYSROOT=";
+ flag += rootDef;
+ cmakeFlags.push_back(flag);
+ }
+ if(this->Makefile->GetDefinition("CMAKE_POSITION_INDEPENDENT_CODE")!=0)
+ {
+ fprintf(fout, "set(CMAKE_POSITION_INDEPENDENT_CODE \"ON\")\n");
+ }
+
+ /* Put the executable at a known location (for COPY_FILE). */
+ fprintf(fout, "set(CMAKE_RUNTIME_OUTPUT_DIRECTORY \"%s\")\n",
+ this->BinaryDirectory.c_str());
+ /* Create the actual executable. */
+ fprintf(fout, "add_executable(%s", targetName.c_str());
+ for(std::vector<std::string>::iterator si = sources.begin();
+ si != sources.end(); ++si)
+ {
+ fprintf(fout, " \"%s\"", si->c_str());
+
+ // Add dependencies on any non-temporary sources.
+ if(si->find("CMakeTmp") == si->npos)
+ {
+ this->Makefile->AddCMakeDependFile(*si);
+ }
+ }
+ fprintf(fout, ")\n");
+ if (useOldLinkLibs)
+ {
+ fprintf(fout,
+ "target_link_libraries(%s ${LINK_LIBRARIES})\n",
+ targetName.c_str());
+ }
+ else
+ {
+ fprintf(fout, "target_link_libraries(%s %s)\n",
+ targetName.c_str(),
+ libsToLink.c_str());
+ }
+ fclose(fout);
+ projectName = "CMAKE_TRY_COMPILE";
+ }
+
+ bool erroroc = cmSystemTools::GetErrorOccuredFlag();
+ cmSystemTools::ResetErrorOccuredFlag();
+ std::string output;
+ // actually do the try compile now that everything is setup
+ int res = this->Makefile->TryCompile(sourceDirectory,
+ this->BinaryDirectory,
+ projectName,
+ targetName,
+ this->SrcFileSignature,
+ &cmakeFlags,
+ output);
+ if ( erroroc )
+ {
+ cmSystemTools::SetErrorOccured();
+ }
+
+ // set the result var to the return value to indicate success or failure
+ this->Makefile->AddCacheDefinition(argv[0],
+ (res == 0 ? "TRUE" : "FALSE"),
+ "Result of TRY_COMPILE",
+ cmCacheManager::INTERNAL);
+
+ if ( outputVariable.size() > 0 )
+ {
+ this->Makefile->AddDefinition(outputVariable, output.c_str());
+ }
+
+ if (this->SrcFileSignature)
+ {
+ std::string copyFileErrorMessage;
+ this->FindOutputFile(targetName);
+
+ if ((res==0) && (copyFile.size()))
+ {
+ if(this->OutputFile.empty() ||
+ !cmSystemTools::CopyFileAlways(this->OutputFile.c_str(),
+ copyFile.c_str()))
+ {
+ cmOStringStream emsg;
+ emsg << "Cannot copy output executable\n"
+ << " '" << this->OutputFile << "'\n"
+ << "to destination specified by COPY_FILE:\n"
+ << " '" << copyFile << "'\n";
+ if(!this->FindErrorMessage.empty())
+ {
+ emsg << this->FindErrorMessage.c_str();
+ }
+ if(copyFileError.empty())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, emsg.str());
+ return -1;
+ }
+ else
+ {
+ copyFileErrorMessage = emsg.str();
+ }
+ }
+ }
+
+ if(!copyFileError.empty())
+ {
+ this->Makefile->AddDefinition(copyFileError,
+ copyFileErrorMessage.c_str());
+ }
+ }
+ return res;
+}
+
+void cmCoreTryCompile::CleanupFiles(const char* binDir)
+{
+ if ( !binDir )
+ {
+ return;
+ }
+
+ std::string bdir = binDir;
+ if(bdir.find("CMakeTmp") == std::string::npos)
+ {
+ cmSystemTools::Error(
+ "TRY_COMPILE attempt to remove -rf directory that does not contain "
+ "CMakeTmp:", binDir);
+ return;
+ }
+
+ cmsys::Directory dir;
+ dir.Load(binDir);
+ size_t fileNum;
+ std::set<std::string> deletedFiles;
+ for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum)
+ {
+ if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") &&
+ strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".."))
+ {
+
+ if(deletedFiles.find( dir.GetFile(static_cast<unsigned long>(fileNum)))
+ == deletedFiles.end())
+ {
+ deletedFiles.insert(dir.GetFile(static_cast<unsigned long>(fileNum)));
+ std::string fullPath = binDir;
+ fullPath += "/";
+ fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
+ if(cmSystemTools::FileIsDirectory(fullPath.c_str()))
+ {
+ this->CleanupFiles(fullPath.c_str());
+ cmSystemTools::RemoveADirectory(fullPath.c_str());
+ }
+ else
+ {
+#ifdef _WIN32
+ // Sometimes anti-virus software hangs on to new files so we
+ // cannot delete them immediately. Try a few times.
+ cmSystemTools::WindowsFileRetry retry =
+ cmSystemTools::GetWindowsFileRetry();
+ while(!cmSystemTools::RemoveFile(fullPath.c_str()) &&
+ --retry.Count && cmSystemTools::FileExists(fullPath.c_str()))
+ {
+ cmSystemTools::Delay(retry.Delay);
+ }
+ if(retry.Count == 0)
+#else
+ if(!cmSystemTools::RemoveFile(fullPath.c_str()))
+#endif
+ {
+ std::string m = "Remove failed on file: " + fullPath;
+ cmSystemTools::ReportLastSystemError(m.c_str());
+ }
+ }
+ }
+ }
+ }
+}
+
+void cmCoreTryCompile::FindOutputFile(const std::string& targetName)
+{
+ this->FindErrorMessage = "";
+ this->OutputFile = "";
+ std::string tmpOutputFile = "/";
+ tmpOutputFile += targetName;
+ tmpOutputFile +=this->Makefile->GetSafeDefinition("CMAKE_EXECUTABLE_SUFFIX");
+
+ // a list of directories where to search for the compilation result
+ // at first directly in the binary dir
+ std::vector<std::string> searchDirs;
+ searchDirs.push_back("");
+
+ const char* config = this->Makefile->GetDefinition(
+ "CMAKE_TRY_COMPILE_CONFIGURATION");
+ // if a config was specified try that first
+ if (config && config[0])
+ {
+ std::string tmp = "/";
+ tmp += config;
+ searchDirs.push_back(tmp);
+ }
+ searchDirs.push_back("/Debug");
+#if defined(__APPLE__)
+ std::string app = "/Debug/" + targetName + ".app";
+ searchDirs.push_back(app);
+#endif
+ searchDirs.push_back("/Development");
+
+ for(std::vector<std::string>::const_iterator it = searchDirs.begin();
+ it != searchDirs.end();
+ ++it)
+ {
+ std::string command = this->BinaryDirectory;
+ command += *it;
+ command += tmpOutputFile;
+ if(cmSystemTools::FileExists(command.c_str()))
+ {
+ tmpOutputFile = cmSystemTools::CollapseFullPath(command.c_str());
+ this->OutputFile = tmpOutputFile;
+ return;
+ }
+ }
+
+ cmOStringStream emsg;
+ emsg << "Unable to find the executable at any of:\n";
+ for (unsigned int i = 0; i < searchDirs.size(); ++i)
+ {
+ emsg << " " << this->BinaryDirectory << searchDirs[i]
+ << tmpOutputFile << "\n";
+ }
+ this->FindErrorMessage = emsg.str();
+ return;
+}
diff --git a/Source/cmCoreTryCompile.h b/Source/cmCoreTryCompile.h
new file mode 100644
index 0000000000..3272462d9e
--- /dev/null
+++ b/Source/cmCoreTryCompile.h
@@ -0,0 +1,60 @@
+/*============================================================================
+ 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 cmCoreTryCompile_h
+#define cmCoreTryCompile_h
+
+#include "cmCommand.h"
+
+/** \class cmCoreTryCompile
+ * \brief Base class for cmTryCompileCommand and cmTryRunCommand
+ *
+ * cmCoreTryCompile implements the functionality to build a program.
+ * It is the base class for cmTryCompileCommand and cmTryRunCommand.
+ */
+class cmCoreTryCompile : public cmCommand
+{
+public:
+
+ protected:
+ /**
+ * This is the core code for try compile. It is here so that other
+ * commands, such as TryRun can access the same logic without
+ * duplication.
+ */
+ int TryCompileCode(std::vector<std::string> const& argv);
+
+ /**
+ * This deletes all the files created by TryCompileCode.
+ * This way we do not have to rely on the timing and
+ * dependencies of makefiles.
+ */
+ void CleanupFiles(const char* binDir);
+
+ /**
+ * This tries to find the (executable) file created by
+ TryCompileCode. The result is stored in OutputFile. If nothing is found,
+ the error message is stored in FindErrorMessage.
+ */
+ void FindOutputFile(const std::string& targetName);
+
+
+ cmTypeMacro(cmCoreTryCompile, cmCommand);
+
+ std::string BinaryDirectory;
+ std::string OutputFile;
+ std::string FindErrorMessage;
+ bool SrcFileSignature;
+
+};
+
+
+#endif
diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx
new file mode 100644
index 0000000000..02fb8cb015
--- /dev/null
+++ b/Source/cmCreateTestSourceList.cxx
@@ -0,0 +1,189 @@
+/*============================================================================
+ 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 "cmCreateTestSourceList.h"
+#include "cmSourceFile.h"
+
+// cmCreateTestSourceList
+bool cmCreateTestSourceList
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if (args.size() < 3)
+ {
+ this->SetError("called with wrong number of arguments.");
+ return false;
+ }
+
+
+ std::vector<std::string>::const_iterator i = args.begin();
+ std::string extraInclude;
+ std::string function;
+ std::vector<std::string> tests;
+ // extract extra include and function ot
+ for(; i != args.end(); i++)
+ {
+ if(*i == "EXTRA_INCLUDE")
+ {
+ ++i;
+ if(i == args.end())
+ {
+ this->SetError("incorrect arguments to EXTRA_INCLUDE");
+ return false;
+ }
+ extraInclude = "#include \"";
+ extraInclude += *i;
+ extraInclude += "\"\n";
+ }
+ else if(*i == "FUNCTION")
+ {
+ ++i;
+ if(i == args.end())
+ {
+ this->SetError("incorrect arguments to FUNCTION");
+ return false;
+ }
+ function = *i;
+ function += "(&ac, &av);\n";
+ }
+ else
+ {
+ tests.push_back(*i);
+ }
+ }
+ i = tests.begin();
+
+ // Name of the source list
+
+ const char* sourceList = i->c_str();
+ ++i;
+
+ // Name of the test driver
+ // make sure they specified an extension
+ if (cmSystemTools::GetFilenameExtension(*i).size() < 2)
+ {
+ this->SetError(
+ "You must specify a file extension for the test driver file.");
+ return false;
+ }
+ std::string driver = this->Makefile->GetCurrentOutputDirectory();
+ driver += "/";
+ driver += *i;
+ ++i;
+
+ std::string configFile =
+ this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
+
+ configFile += "/Templates/TestDriver.cxx.in";
+ // Create the test driver file
+
+ std::vector<std::string>::const_iterator testsBegin = i;
+ std::vector<std::string> tests_func_name;
+
+ // The rest of the arguments consist of a list of test source files.
+ // Sadly, they can be in directories. Let's find a unique function
+ // name for the corresponding test, and push it to the tests_func_name
+ // list.
+ // For the moment:
+ // - replace spaces ' ', ':' and '/' with underscores '_'
+ std::string forwardDeclareCode;
+ for(i = testsBegin; i != tests.end(); ++i)
+ {
+ if(*i == "EXTRA_INCLUDE")
+ {
+ break;
+ }
+ std::string func_name;
+ if (cmSystemTools::GetFilenamePath(*i).size() > 0)
+ {
+ func_name = cmSystemTools::GetFilenamePath(*i) + "/" +
+ cmSystemTools::GetFilenameWithoutLastExtension(*i);
+ }
+ else
+ {
+ func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
+ }
+ cmSystemTools::ConvertToUnixSlashes(func_name);
+ cmSystemTools::ReplaceString(func_name, " ", "_");
+ cmSystemTools::ReplaceString(func_name, "/", "_");
+ cmSystemTools::ReplaceString(func_name, ":", "_");
+ tests_func_name.push_back(func_name);
+ forwardDeclareCode += "int ";
+ forwardDeclareCode += func_name;
+ forwardDeclareCode += "(int, char*[]);\n";
+ }
+
+ std::string functionMapCode;
+ int numTests = 0;
+ std::vector<std::string>::iterator j;
+ for(i = testsBegin, j = tests_func_name.begin(); i != tests.end(); ++i, ++j)
+ {
+ std::string func_name;
+ if (cmSystemTools::GetFilenamePath(*i).size() > 0)
+ {
+ func_name = cmSystemTools::GetFilenamePath(*i) + "/" +
+ cmSystemTools::GetFilenameWithoutLastExtension(*i);
+ }
+ else
+ {
+ func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
+ }
+ functionMapCode += " {\n"
+ " \"";
+ functionMapCode += func_name;
+ functionMapCode += "\",\n"
+ " ";
+ functionMapCode += *j;
+ functionMapCode += "\n"
+ " },\n";
+ numTests++;
+ }
+ if(extraInclude.size())
+ {
+ this->Makefile->AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES",
+ extraInclude.c_str());
+ }
+ if(function.size())
+ {
+ this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION",
+ function.c_str());
+ }
+ this->Makefile->AddDefinition("CMAKE_FORWARD_DECLARE_TESTS",
+ forwardDeclareCode.c_str());
+ this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES",
+ functionMapCode.c_str());
+ bool res = true;
+ if ( !this->Makefile->ConfigureFile(configFile.c_str(), driver.c_str(),
+ false, true, false) )
+ {
+ res = false;
+ }
+
+ // Construct the source list.
+ std::string sourceListValue;
+ {
+ cmSourceFile* sf = this->Makefile->GetOrCreateSource(driver);
+ sf->SetProperty("ABSTRACT","0");
+ sourceListValue = args[1];
+ }
+ for(i = testsBegin; i != tests.end(); ++i)
+ {
+ cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
+ sf->SetProperty("ABSTRACT","0");
+ sourceListValue += ";";
+ sourceListValue += *i;
+ }
+
+ this->Makefile->AddDefinition(sourceList, sourceListValue.c_str());
+ return res;
+}
+
+
+
diff --git a/Source/cmCreateTestSourceList.h b/Source/cmCreateTestSourceList.h
new file mode 100644
index 0000000000..2f6b541f8d
--- /dev/null
+++ b/Source/cmCreateTestSourceList.h
@@ -0,0 +1,50 @@
+/*============================================================================
+ 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 cmCreateTestSourceList_h
+#define cmCreateTestSourceList_h
+
+#include "cmCommand.h"
+
+/** \class cmCreateTestSourceList
+ * \brief Test driver generation command
+ *
+ */
+
+class cmCreateTestSourceList : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmCreateTestSourceList;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "create_test_sourcelist";}
+
+ cmTypeMacro(cmCreateTestSourceList, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
new file mode 100644
index 0000000000..74e17b6220
--- /dev/null
+++ b/Source/cmCryptoHash.cxx
@@ -0,0 +1,131 @@
+/*============================================================================
+ 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 "cmCryptoHash.h"
+
+#include <cmsys/MD5.h>
+#include <cmsys/FStream.hxx>
+#include "cm_sha2.h"
+
+//----------------------------------------------------------------------------
+cmsys::auto_ptr<cmCryptoHash> cmCryptoHash::New(const char* algo)
+{
+ if(strcmp(algo,"MD5") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashMD5); }
+ else if(strcmp(algo,"SHA1") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA1); }
+ else if(strcmp(algo,"SHA224") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA224); }
+ else if(strcmp(algo,"SHA256") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA256); }
+ else if(strcmp(algo,"SHA384") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA384); }
+ else if(strcmp(algo,"SHA512") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA512); }
+ else
+ { return cmsys::auto_ptr<cmCryptoHash>(0); }
+}
+
+//----------------------------------------------------------------------------
+std::string cmCryptoHash::HashString(const std::string& input)
+{
+ this->Initialize();
+ this->Append(reinterpret_cast<unsigned char const*>(input.c_str()),
+ static_cast<int>(input.size()));
+ return this->Finalize();
+}
+
+//----------------------------------------------------------------------------
+std::string cmCryptoHash::HashFile(const std::string& file)
+{
+ cmsys::ifstream fin(file.c_str(), std::ios::in | cmsys_ios_binary);
+ if(!fin)
+ {
+ return "";
+ }
+
+ this->Initialize();
+
+ // Should be efficient enough on most system:
+ cm_sha2_uint64_t buffer[512];
+ char* buffer_c = reinterpret_cast<char*>(buffer);
+ unsigned char const* buffer_uc =
+ reinterpret_cast<unsigned char const*>(buffer);
+ // This copy loop is very sensitive on certain platforms with
+ // slightly broken stream libraries (like HPUX). Normally, it is
+ // incorrect to not check the error condition on the fin.read()
+ // before using the data, but the fin.gcount() will be zero if an
+ // error occurred. Therefore, the loop should be safe everywhere.
+ while(fin)
+ {
+ fin.read(buffer_c, sizeof(buffer));
+ if(int gcount = static_cast<int>(fin.gcount()))
+ {
+ this->Append(buffer_uc, gcount);
+ }
+ }
+ if(fin.eof())
+ {
+ return this->Finalize();
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+cmCryptoHashMD5::cmCryptoHashMD5(): MD5(cmsysMD5_New())
+{
+}
+
+//----------------------------------------------------------------------------
+cmCryptoHashMD5::~cmCryptoHashMD5()
+{
+ cmsysMD5_Delete(this->MD5);
+}
+
+//----------------------------------------------------------------------------
+void cmCryptoHashMD5::Initialize()
+{
+ cmsysMD5_Initialize(this->MD5);
+}
+
+//----------------------------------------------------------------------------
+void cmCryptoHashMD5::Append(unsigned char const* buf, int sz)
+{
+ cmsysMD5_Append(this->MD5, buf, sz);
+}
+
+//----------------------------------------------------------------------------
+std::string cmCryptoHashMD5::Finalize()
+{
+ char md5out[32];
+ cmsysMD5_FinalizeHex(this->MD5, md5out);
+ return std::string(md5out, 32);
+}
+
+
+#define cmCryptoHash_SHA_CLASS_IMPL(SHA) \
+cmCryptoHash##SHA::cmCryptoHash##SHA(): SHA(new SHA_CTX) {} \
+cmCryptoHash##SHA::~cmCryptoHash##SHA() { delete this->SHA; } \
+void cmCryptoHash##SHA::Initialize() { SHA##_Init(this->SHA); } \
+void cmCryptoHash##SHA::Append(unsigned char const* buf, int sz) \
+{ SHA##_Update(this->SHA, buf, sz); } \
+std::string cmCryptoHash##SHA::Finalize() \
+{ \
+ char out[SHA##_DIGEST_STRING_LENGTH]; \
+ SHA##_End(this->SHA, out); \
+ return std::string(out, SHA##_DIGEST_STRING_LENGTH-1); \
+}
+
+cmCryptoHash_SHA_CLASS_IMPL(SHA1)
+cmCryptoHash_SHA_CLASS_IMPL(SHA224)
+cmCryptoHash_SHA_CLASS_IMPL(SHA256)
+cmCryptoHash_SHA_CLASS_IMPL(SHA384)
+cmCryptoHash_SHA_CLASS_IMPL(SHA512)
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
new file mode 100644
index 0000000000..88cd240c02
--- /dev/null
+++ b/Source/cmCryptoHash.h
@@ -0,0 +1,65 @@
+/*============================================================================
+ 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 cmCryptoHash_h
+#define cmCryptoHash_h
+
+#include "cmStandardIncludes.h"
+
+#include <cmsys/auto_ptr.hxx>
+
+class cmCryptoHash
+{
+public:
+ virtual ~cmCryptoHash() {}
+ static cmsys::auto_ptr<cmCryptoHash> New(const char* algo);
+ std::string HashString(const std::string& input);
+ std::string HashFile(const std::string& file);
+protected:
+ virtual void Initialize()=0;
+ virtual void Append(unsigned char const*, int)=0;
+ virtual std::string Finalize()=0;
+};
+
+class cmCryptoHashMD5: public cmCryptoHash
+{
+ struct cmsysMD5_s* MD5;
+public:
+ cmCryptoHashMD5();
+ ~cmCryptoHashMD5();
+protected:
+ virtual void Initialize();
+ virtual void Append(unsigned char const* buf, int sz);
+ virtual std::string Finalize();
+};
+
+#define cmCryptoHash_SHA_CLASS_DECL(SHA) \
+ class cmCryptoHash##SHA: public cmCryptoHash \
+ { \
+ union _SHA_CTX* SHA; \
+ public: \
+ cmCryptoHash##SHA(); \
+ ~cmCryptoHash##SHA(); \
+ protected: \
+ virtual void Initialize(); \
+ virtual void Append(unsigned char const* buf, int sz); \
+ virtual std::string Finalize(); \
+ }
+
+cmCryptoHash_SHA_CLASS_DECL(SHA1);
+cmCryptoHash_SHA_CLASS_DECL(SHA224);
+cmCryptoHash_SHA_CLASS_DECL(SHA256);
+cmCryptoHash_SHA_CLASS_DECL(SHA384);
+cmCryptoHash_SHA_CLASS_DECL(SHA512);
+
+#undef cmCryptoHash_SHA_CLASS_DECL
+
+#endif
diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx
new file mode 100644
index 0000000000..c161eb63d3
--- /dev/null
+++ b/Source/cmCustomCommand.cxx
@@ -0,0 +1,186 @@
+/*============================================================================
+ 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 "cmCustomCommand.h"
+
+#include "cmMakefile.h"
+
+#include <cmsys/auto_ptr.hxx>
+
+//----------------------------------------------------------------------------
+cmCustomCommand::cmCustomCommand()
+ : Backtrace(NULL)
+{
+ this->HaveComment = false;
+ this->EscapeOldStyle = true;
+ this->EscapeAllowMakeVars = false;
+}
+
+//----------------------------------------------------------------------------
+cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
+ Outputs(r.Outputs),
+ Depends(r.Depends),
+ CommandLines(r.CommandLines),
+ HaveComment(r.HaveComment),
+ Comment(r.Comment),
+ WorkingDirectory(r.WorkingDirectory),
+ EscapeAllowMakeVars(r.EscapeAllowMakeVars),
+ EscapeOldStyle(r.EscapeOldStyle),
+ Backtrace(r.Backtrace)
+{
+}
+
+//----------------------------------------------------------------------------
+cmCustomCommand& cmCustomCommand::operator=(cmCustomCommand const& r)
+{
+ if(this == &r)
+ {
+ return *this;
+ }
+
+ this->Outputs = r.Outputs;
+ this->Depends = r.Depends;
+ this->CommandLines = r.CommandLines;
+ this->HaveComment = r.HaveComment;
+ this->Comment = r.Comment;
+ this->WorkingDirectory = r.WorkingDirectory;
+ this->EscapeAllowMakeVars = r.EscapeAllowMakeVars;
+ this->EscapeOldStyle = r.EscapeOldStyle;
+ this->ImplicitDepends = r.ImplicitDepends;
+ this->Backtrace = r.Backtrace;
+
+ return *this;
+}
+
+//----------------------------------------------------------------------------
+cmCustomCommand::cmCustomCommand(cmMakefile const* mf,
+ const std::vector<std::string>& outputs,
+ const std::vector<std::string>& depends,
+ const cmCustomCommandLines& commandLines,
+ const char* comment,
+ const char* workingDirectory):
+ Outputs(outputs),
+ Depends(depends),
+ CommandLines(commandLines),
+ HaveComment(comment?true:false),
+ Comment(comment?comment:""),
+ WorkingDirectory(workingDirectory?workingDirectory:""),
+ EscapeAllowMakeVars(false),
+ EscapeOldStyle(true),
+ Backtrace(NULL)
+{
+ this->EscapeOldStyle = true;
+ this->EscapeAllowMakeVars = false;
+ if(mf)
+ {
+ this->Backtrace = mf->GetBacktrace();
+ }
+}
+
+//----------------------------------------------------------------------------
+cmCustomCommand::~cmCustomCommand()
+{
+}
+
+//----------------------------------------------------------------------------
+const std::vector<std::string>& cmCustomCommand::GetOutputs() const
+{
+ return this->Outputs;
+}
+
+//----------------------------------------------------------------------------
+const std::vector<std::string>& cmCustomCommand::GetDepends() const
+{
+ return this->Depends;
+}
+
+//----------------------------------------------------------------------------
+const cmCustomCommandLines& cmCustomCommand::GetCommandLines() const
+{
+ return this->CommandLines;
+}
+
+//----------------------------------------------------------------------------
+const char* cmCustomCommand::GetComment() const
+{
+ const char* no_comment = 0;
+ return this->HaveComment? this->Comment.c_str() : no_comment;
+}
+
+//----------------------------------------------------------------------------
+void cmCustomCommand::AppendCommands(const cmCustomCommandLines& commandLines)
+{
+ for(cmCustomCommandLines::const_iterator i=commandLines.begin();
+ i != commandLines.end(); ++i)
+ {
+ this->CommandLines.push_back(*i);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmCustomCommand::AppendDepends(const std::vector<std::string>& depends)
+{
+ for(std::vector<std::string>::const_iterator i=depends.begin();
+ i != depends.end(); ++i)
+ {
+ this->Depends.push_back(*i);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmCustomCommand::GetEscapeOldStyle() const
+{
+ return this->EscapeOldStyle;
+}
+
+//----------------------------------------------------------------------------
+void cmCustomCommand::SetEscapeOldStyle(bool b)
+{
+ this->EscapeOldStyle = b;
+}
+
+//----------------------------------------------------------------------------
+bool cmCustomCommand::GetEscapeAllowMakeVars() const
+{
+ return this->EscapeAllowMakeVars;
+}
+
+//----------------------------------------------------------------------------
+void cmCustomCommand::SetEscapeAllowMakeVars(bool b)
+{
+ this->EscapeAllowMakeVars = b;
+}
+
+//----------------------------------------------------------------------------
+cmListFileBacktrace const& cmCustomCommand::GetBacktrace() const
+{
+ return this->Backtrace;
+}
+
+//----------------------------------------------------------------------------
+cmCustomCommand::ImplicitDependsList const&
+cmCustomCommand::GetImplicitDepends() const
+{
+ return this->ImplicitDepends;
+}
+
+//----------------------------------------------------------------------------
+void cmCustomCommand::SetImplicitDepends(ImplicitDependsList const& l)
+{
+ this->ImplicitDepends = l;
+}
+
+//----------------------------------------------------------------------------
+void cmCustomCommand::AppendImplicitDepends(ImplicitDependsList const& l)
+{
+ this->ImplicitDepends.insert(this->ImplicitDepends.end(),
+ l.begin(), l.end());
+}
diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h
new file mode 100644
index 0000000000..21dbefb26b
--- /dev/null
+++ b/Source/cmCustomCommand.h
@@ -0,0 +1,95 @@
+/*============================================================================
+ 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 cmCustomCommand_h
+#define cmCustomCommand_h
+
+#include "cmStandardIncludes.h"
+#include "cmListFileCache.h"
+class cmMakefile;
+
+/** \class cmCustomCommand
+ * \brief A class to encapsulate a custom command
+ *
+ * cmCustomCommand encapsulates the properties of a custom command
+ */
+class cmCustomCommand
+{
+public:
+ /** Default and copy constructors for STL containers. */
+ cmCustomCommand();
+ cmCustomCommand(const cmCustomCommand& r);
+ cmCustomCommand& operator=(cmCustomCommand const& r);
+
+ /** Main constructor specifies all information for the command. */
+ cmCustomCommand(cmMakefile const* mf,
+ const std::vector<std::string>& outputs,
+ const std::vector<std::string>& depends,
+ const cmCustomCommandLines& commandLines,
+ const char* comment,
+ const char* workingDirectory);
+
+ ~cmCustomCommand();
+
+ /** Get the output file produced by the command. */
+ const std::vector<std::string>& GetOutputs() const;
+
+ /** Get the vector that holds the list of dependencies. */
+ const std::vector<std::string>& GetDepends() const;
+
+ /** Get the working directory. */
+ std::string const& GetWorkingDirectory() const
+ { return this->WorkingDirectory; }
+
+ /** Get the list of command lines. */
+ const cmCustomCommandLines& GetCommandLines() const;
+
+ /** Get the comment string for the command. */
+ const char* GetComment() const;
+
+ /** Append to the list of command lines. */
+ void AppendCommands(const cmCustomCommandLines& commandLines);
+
+ /** Append to the list of dependencies. */
+ void AppendDepends(const std::vector<std::string>& depends);
+
+ /** Set/Get whether old-style escaping should be used. */
+ bool GetEscapeOldStyle() const;
+ void SetEscapeOldStyle(bool b);
+
+ /** Set/Get whether the build tool can replace variables in
+ arguments to the command. */
+ bool GetEscapeAllowMakeVars() const;
+ void SetEscapeAllowMakeVars(bool b);
+
+ /** Backtrace of the command that created this custom command. */
+ cmListFileBacktrace const& GetBacktrace() const;
+
+ typedef std::pair<std::string, std::string> ImplicitDependsPair;
+ class ImplicitDependsList: public std::vector<ImplicitDependsPair> {};
+ void SetImplicitDepends(ImplicitDependsList const&);
+ void AppendImplicitDepends(ImplicitDependsList const&);
+ ImplicitDependsList const& GetImplicitDepends() const;
+
+private:
+ std::vector<std::string> Outputs;
+ std::vector<std::string> Depends;
+ cmCustomCommandLines CommandLines;
+ bool HaveComment;
+ std::string Comment;
+ std::string WorkingDirectory;
+ bool EscapeAllowMakeVars;
+ bool EscapeOldStyle;
+ cmListFileBacktrace Backtrace;
+ ImplicitDependsList ImplicitDepends;
+};
+
+#endif
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx
new file mode 100644
index 0000000000..1bca6e68ef
--- /dev/null
+++ b/Source/cmCustomCommandGenerator.cxx
@@ -0,0 +1,121 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2010 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 "cmCustomCommandGenerator.h"
+
+#include "cmMakefile.h"
+#include "cmCustomCommand.h"
+#include "cmLocalGenerator.h"
+#include "cmGeneratorExpression.h"
+
+//----------------------------------------------------------------------------
+cmCustomCommandGenerator::cmCustomCommandGenerator(
+ cmCustomCommand const& cc, const std::string& config, cmMakefile* mf):
+ CC(cc), Config(config), Makefile(mf), LG(mf->GetLocalGenerator()),
+ OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars()),
+ GE(new cmGeneratorExpression(&cc.GetBacktrace())), DependsDone(false)
+{
+}
+
+//----------------------------------------------------------------------------
+cmCustomCommandGenerator::~cmCustomCommandGenerator()
+{
+ delete this->GE;
+}
+
+//----------------------------------------------------------------------------
+unsigned int cmCustomCommandGenerator::GetNumberOfCommands() const
+{
+ return static_cast<unsigned int>(this->CC.GetCommandLines().size());
+}
+
+//----------------------------------------------------------------------------
+std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
+{
+ std::string const& argv0 = this->CC.GetCommandLines()[c][0];
+ cmTarget* target = this->Makefile->FindTargetToUse(argv0);
+ if(target && target->GetType() == cmTarget::EXECUTABLE &&
+ (target->IsImported() || !this->Makefile->IsOn("CMAKE_CROSSCOMPILING")))
+ {
+ return target->GetLocation(this->Config);
+ }
+ return this->GE->Parse(argv0)->Evaluate(this->Makefile, this->Config);
+}
+
+//----------------------------------------------------------------------------
+void
+cmCustomCommandGenerator
+::AppendArguments(unsigned int c, std::string& cmd) const
+{
+ cmCustomCommandLine const& commandLine = this->CC.GetCommandLines()[c];
+ for(unsigned int j=1;j < commandLine.size(); ++j)
+ {
+ std::string arg = this->GE->Parse(commandLine[j])->Evaluate(this->Makefile,
+ this->Config);
+ cmd += " ";
+ if(this->OldStyle)
+ {
+ cmd += this->LG->EscapeForShellOldStyle(arg);
+ }
+ else
+ {
+ cmd += this->LG->EscapeForShell(arg, this->MakeVars);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmCustomCommandGenerator::GetComment() const
+{
+ return this->CC.GetComment();
+}
+
+//----------------------------------------------------------------------------
+std::string cmCustomCommandGenerator::GetWorkingDirectory() const
+{
+ return this->CC.GetWorkingDirectory();
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string> const& cmCustomCommandGenerator::GetOutputs() const
+{
+ return this->CC.GetOutputs();
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string> const& cmCustomCommandGenerator::GetDepends() const
+{
+ if (!this->DependsDone)
+ {
+ this->DependsDone = true;
+ std::vector<std::string> depends = this->CC.GetDepends();
+ for(std::vector<std::string>::const_iterator
+ i = depends.begin();
+ i != depends.end(); ++i)
+ {
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
+ = this->GE->Parse(*i);
+ std::vector<std::string> result;
+ cmSystemTools::ExpandListArgument(
+ cge->Evaluate(this->Makefile, this->Config), result);
+ for (std::vector<std::string>::iterator it = result.begin();
+ it != result.end(); ++it)
+ {
+ if (cmSystemTools::FileIsFullPath(it->c_str()))
+ {
+ *it = cmSystemTools::CollapseFullPath(*it);
+ }
+ }
+ this->Depends.insert(this->Depends.end(), result.begin(), result.end());
+ }
+ }
+ return this->Depends;
+}
diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h
new file mode 100644
index 0000000000..0d8a0a4eda
--- /dev/null
+++ b/Source/cmCustomCommandGenerator.h
@@ -0,0 +1,48 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2010 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 cmCustomCommandGenerator_h
+#define cmCustomCommandGenerator_h
+
+#include "cmStandardIncludes.h"
+
+class cmCustomCommand;
+class cmMakefile;
+class cmLocalGenerator;
+class cmGeneratorExpression;
+
+class cmCustomCommandGenerator
+{
+ cmCustomCommand const& CC;
+ std::string Config;
+ cmMakefile* Makefile;
+ cmLocalGenerator* LG;
+ bool OldStyle;
+ bool MakeVars;
+ cmGeneratorExpression* GE;
+ mutable bool DependsDone;
+ mutable std::vector<std::string> Depends;
+public:
+ cmCustomCommandGenerator(cmCustomCommand const& cc,
+ const std::string& config,
+ cmMakefile* mf);
+ ~cmCustomCommandGenerator();
+ cmCustomCommand const& GetCC() const { return this->CC; }
+ unsigned int GetNumberOfCommands() const;
+ std::string GetCommand(unsigned int c) const;
+ void AppendArguments(unsigned int c, std::string& cmd) const;
+ const char* GetComment() const;
+ std::string GetWorkingDirectory() const;
+ std::vector<std::string> const& GetOutputs() const;
+ std::vector<std::string> const& GetDepends() const;
+};
+
+#endif
diff --git a/Source/cmDefinePropertyCommand.cxx b/Source/cmDefinePropertyCommand.cxx
new file mode 100644
index 0000000000..6b729de1e1
--- /dev/null
+++ b/Source/cmDefinePropertyCommand.cxx
@@ -0,0 +1,136 @@
+/*============================================================================
+ 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 "cmDefinePropertyCommand.h"
+#include "cmake.h"
+
+bool cmDefinePropertyCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // Get the scope in which to define the property.
+ cmProperty::ScopeType scope;
+ if(args[0] == "GLOBAL")
+ {
+ scope = cmProperty::GLOBAL;
+ }
+ else if(args[0] == "DIRECTORY")
+ {
+ scope = cmProperty::DIRECTORY;
+ }
+ else if(args[0] == "TARGET")
+ {
+ scope = cmProperty::TARGET;
+ }
+ else if(args[0] == "SOURCE")
+ {
+ scope = cmProperty::SOURCE_FILE;
+ }
+ else if(args[0] == "TEST")
+ {
+ scope = cmProperty::TEST;
+ }
+ else if(args[0] == "VARIABLE")
+ {
+ scope = cmProperty::VARIABLE;
+ }
+ else if (args[0] == "CACHED_VARIABLE")
+ {
+ scope = cmProperty::CACHED_VARIABLE;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given invalid scope " << args[0] << ". "
+ << "Valid scopes are "
+ << "GLOBAL, DIRECTORY, TARGET, SOURCE, "
+ << "TEST, VARIABLE, CACHED_VARIABLE.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Parse remaining arguments.
+ bool inherited = false;
+ enum Doing { DoingNone, DoingProperty, DoingBrief, DoingFull };
+ Doing doing = DoingNone;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "PROPERTY")
+ {
+ doing = DoingProperty;
+ }
+ else if(args[i] == "BRIEF_DOCS")
+ {
+ doing = DoingBrief;
+ }
+ else if(args[i] == "FULL_DOCS")
+ {
+ doing = DoingFull;
+ }
+ else if(args[i] == "INHERITED")
+ {
+ doing = DoingNone;
+ inherited = true;
+ }
+ else if(doing == DoingProperty)
+ {
+ doing = DoingNone;
+ this->PropertyName = args[i];
+ }
+ else if(doing == DoingBrief)
+ {
+ this->BriefDocs += args[i];
+ }
+ else if(doing == DoingFull)
+ {
+ this->FullDocs += args[i];
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given invalid argument \"" << args[i] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // Make sure a property name was found.
+ if(this->PropertyName.empty())
+ {
+ this->SetError("not given a PROPERTY <name> argument.");
+ return false;
+ }
+
+ // Make sure documentation was given.
+ if(this->BriefDocs.empty())
+ {
+ this->SetError("not given a BRIEF_DOCS <brief-doc> argument.");
+ return false;
+ }
+ if(this->FullDocs.empty())
+ {
+ this->SetError("not given a FULL_DOCS <full-doc> argument.");
+ return false;
+ }
+
+ // Actually define the property.
+ this->Makefile->GetCMakeInstance()->DefineProperty
+ (this->PropertyName, scope,
+ this->BriefDocs.c_str(), this->FullDocs.c_str(), inherited);
+
+ return true;
+}
+
diff --git a/Source/cmDefinePropertyCommand.h b/Source/cmDefinePropertyCommand.h
new file mode 100644
index 0000000000..bc5c8a4f80
--- /dev/null
+++ b/Source/cmDefinePropertyCommand.h
@@ -0,0 +1,46 @@
+/*============================================================================
+ 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 cmDefinesPropertyCommand_h
+#define cmDefinesPropertyCommand_h
+
+#include "cmCommand.h"
+
+class cmDefinePropertyCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmDefinePropertyCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "define_property";}
+
+ cmTypeMacro(cmDefinePropertyCommand, cmCommand);
+private:
+ std::string PropertyName;
+ std::string BriefDocs;
+ std::string FullDocs;
+};
+
+
+
+#endif
diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
new file mode 100644
index 0000000000..5515f35516
--- /dev/null
+++ b/Source/cmDefinitions.cxx
@@ -0,0 +1,182 @@
+/*============================================================================
+ 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 "cmDefinitions.h"
+
+//----------------------------------------------------------------------------
+cmDefinitions::Def cmDefinitions::NoDef;
+
+//----------------------------------------------------------------------------
+cmDefinitions::cmDefinitions(cmDefinitions* parent)
+ : Up(parent)
+{
+}
+
+//----------------------------------------------------------------------------
+void cmDefinitions::Reset(cmDefinitions* parent)
+{
+ this->Up = parent;
+ this->Map.clear();
+}
+
+//----------------------------------------------------------------------------
+cmDefinitions::Def const&
+cmDefinitions::GetInternal(const std::string& key) const
+{
+ MapType::const_iterator i = this->Map.find(key);
+ if(i != this->Map.end())
+ {
+ return i->second;
+ }
+ if(cmDefinitions* up = this->Up)
+ {
+ // Query the parent scope.
+ return up->GetInternal(key);
+ }
+ return this->NoDef;
+}
+
+//----------------------------------------------------------------------------
+cmDefinitions::Def const&
+cmDefinitions::SetInternal(const std::string& key, Def const& def)
+{
+ if(this->Up || def.Exists)
+ {
+ // In lower scopes we store keys, defined or not.
+ return (this->Map[key] = def);
+ }
+ else
+ {
+ // In the top-most scope we need not store undefined keys.
+ this->Map.erase(key);
+ return this->NoDef;
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmDefinitions::Get(const std::string& key) const
+{
+ Def const& def = this->GetInternal(key);
+ return def.Exists? def.c_str() : 0;
+}
+
+//----------------------------------------------------------------------------
+void cmDefinitions::Pull(const std::string& key)
+{
+ if (this->Up)
+ {
+ Def const& def = this->Up->GetInternal(key);
+ if (def.Exists)
+ {
+ this->SetInternal(key, def);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmDefinitions::Set(const std::string& key, const char* value)
+{
+ Def const& def = this->SetInternal(key, Def(value));
+ return def.Exists? def.c_str() : 0;
+}
+
+//----------------------------------------------------------------------------
+std::set<std::string> cmDefinitions::LocalKeys() const
+{
+ std::set<std::string> keys;
+ // Consider local definitions.
+ for(MapType::const_iterator mi = this->Map.begin();
+ mi != this->Map.end(); ++mi)
+ {
+ if (mi->second.Exists)
+ {
+ keys.insert(mi->first);
+ }
+ }
+ return keys;
+}
+
+//----------------------------------------------------------------------------
+cmDefinitions cmDefinitions::Closure() const
+{
+ return cmDefinitions(ClosureTag(), this);
+}
+
+//----------------------------------------------------------------------------
+cmDefinitions::cmDefinitions(ClosureTag const&, cmDefinitions const* root):
+ Up(0)
+{
+ std::set<std::string> undefined;
+ this->ClosureImpl(undefined, root);
+}
+
+//----------------------------------------------------------------------------
+void cmDefinitions::ClosureImpl(std::set<std::string>& undefined,
+ cmDefinitions const* defs)
+{
+ // Consider local definitions.
+ for(MapType::const_iterator mi = defs->Map.begin();
+ mi != defs->Map.end(); ++mi)
+ {
+ // Use this key if it is not already set or unset.
+ if(this->Map.find(mi->first) == this->Map.end() &&
+ undefined.find(mi->first) == undefined.end())
+ {
+ if(mi->second.Exists)
+ {
+ this->Map.insert(*mi);
+ }
+ else
+ {
+ undefined.insert(mi->first);
+ }
+ }
+ }
+
+ // Traverse parents.
+ if(cmDefinitions const* up = defs->Up)
+ {
+ this->ClosureImpl(undefined, up);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::set<std::string> cmDefinitions::ClosureKeys() const
+{
+ std::set<std::string> defined;
+ std::set<std::string> undefined;
+ this->ClosureKeys(defined, undefined);
+ return defined;
+}
+
+//----------------------------------------------------------------------------
+void cmDefinitions::ClosureKeys(std::set<std::string>& defined,
+ std::set<std::string>& undefined) const
+{
+ // Consider local definitions.
+ for(MapType::const_iterator mi = this->Map.begin();
+ mi != this->Map.end(); ++mi)
+ {
+ // Use this key if it is not already set or unset.
+ if(defined.find(mi->first) == defined.end() &&
+ undefined.find(mi->first) == undefined.end())
+ {
+ std::set<std::string>& m = mi->second.Exists? defined : undefined;
+ m.insert(mi->first);
+ }
+ }
+
+ // Traverse parents.
+ if(cmDefinitions const* up = this->Up)
+ {
+ up->ClosureKeys(defined, undefined);
+ }
+}
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
new file mode 100644
index 0000000000..5209a8b201
--- /dev/null
+++ b/Source/cmDefinitions.h
@@ -0,0 +1,99 @@
+/*============================================================================
+ 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 cmDefinitions_h
+#define cmDefinitions_h
+
+#include "cmStandardIncludes.h"
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+#include "cmsys/hash_map.hxx"
+#endif
+
+/** \class cmDefinitions
+ * \brief Store a scope of variable definitions for CMake language.
+ *
+ * This stores the state of variable definitions (set or unset) for
+ * one scope. Sets are always local. Gets search parent scopes
+ * transitively and save results locally.
+ */
+class cmDefinitions
+{
+public:
+ /** Construct with the given parent scope. */
+ cmDefinitions(cmDefinitions* parent = 0);
+
+ /** Reset object as if newly constructed. */
+ void Reset(cmDefinitions* parent = 0);
+
+ /** Returns the parent scope, if any. */
+ cmDefinitions* GetParent() const { return this->Up; }
+
+ /** Get the value associated with a key; null if none. */
+ const char* Get(const std::string& key) const;
+
+ /** Pull a variable from the parent. */
+ void Pull(const std::string& key);
+
+ /** Set (or unset if null) a value associated with a key. */
+ const char* Set(const std::string& key, const char* value);
+
+ /** Get the set of all local keys. */
+ std::set<std::string> LocalKeys() const;
+
+ /** Compute the closure of all defined keys with values.
+ This flattens the scope. The result has no parent. */
+ cmDefinitions Closure() const;
+
+ /** Compute the set of all defined keys. */
+ std::set<std::string> ClosureKeys() const;
+
+private:
+ // String with existence boolean.
+ struct Def: public std::string
+ {
+ private:
+ typedef std::string std_string;
+ public:
+ Def(): std_string(), Exists(false) {}
+ Def(const char* v): std_string(v?v:""), Exists(v?true:false) {}
+ Def(const std_string& v): std_string(v), Exists(true) {}
+ Def(Def const& d): std_string(d), Exists(d.Exists) {}
+ bool Exists;
+ };
+ static Def NoDef;
+
+ // Parent scope, if any.
+ cmDefinitions* Up;
+
+ // Local definitions, set or unset.
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ typedef cmsys::hash_map<std::string, Def> MapType;
+#else
+ typedef std::map<std::string, Def> MapType;
+#endif
+ MapType Map;
+
+ // Internal query and update methods.
+ Def const& GetInternal(const std::string& key) const;
+ Def const& SetInternal(const std::string& key, Def const& def);
+
+ // Implementation of Closure() method.
+ struct ClosureTag {};
+ cmDefinitions(ClosureTag const&, cmDefinitions const* root);
+ void ClosureImpl(std::set<std::string>& undefined,
+ cmDefinitions const* defs);
+
+ // Implementation of ClosureKeys() method.
+ void ClosureKeys(std::set<std::string>& defined,
+ std::set<std::string>& undefined) const;
+};
+
+#endif
diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx
new file mode 100644
index 0000000000..134f45b3b3
--- /dev/null
+++ b/Source/cmDepends.cxx
@@ -0,0 +1,320 @@
+/*============================================================================
+ 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 "cmDepends.h"
+
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmSystemTools.h"
+#include "cmFileTimeComparison.h"
+#include <string.h>
+#include <cmsys/FStream.hxx>
+
+//----------------------------------------------------------------------------
+cmDepends::cmDepends(cmLocalGenerator* lg, const char* targetDir):
+ CompileDirectory(),
+ LocalGenerator(lg),
+ Verbose(false),
+ FileComparison(0),
+ TargetDirectory(targetDir),
+ MaxPath(16384),
+ Dependee(new char[MaxPath]),
+ Depender(new char[MaxPath])
+{
+}
+
+//----------------------------------------------------------------------------
+cmDepends::~cmDepends()
+{
+ delete [] this->Dependee;
+ delete [] this->Depender;
+}
+
+//----------------------------------------------------------------------------
+bool cmDepends::Write(std::ostream &makeDepends,
+ std::ostream &internalDepends)
+{
+ // Lookup the set of sources to scan.
+ std::string srcLang = "CMAKE_DEPENDS_CHECK_";
+ srcLang += this->Language;
+ cmMakefile* mf = this->LocalGenerator->GetMakefile();
+ const char* srcStr = mf->GetSafeDefinition(srcLang);
+ std::vector<std::string> pairs;
+ cmSystemTools::ExpandListArgument(srcStr, pairs);
+
+ std::map<std::string, std::set<std::string> > dependencies;
+ for(std::vector<std::string>::iterator si = pairs.begin();
+ si != pairs.end();)
+ {
+ // Get the source and object file.
+ std::string const& src = *si++;
+ if(si == pairs.end()) { break; }
+ std::string const& obj = *si++;
+ dependencies[obj].insert(src);
+ }
+ for(std::map<std::string, std::set<std::string> >::const_iterator
+ it = dependencies.begin(); it != dependencies.end(); ++it)
+ {
+
+ // Write the dependencies for this pair.
+ if(!this->WriteDependencies(it->second, it->first,
+ makeDepends, internalDepends))
+ {
+ return false;
+ }
+ }
+
+ return this->Finalize(makeDepends, internalDepends);
+}
+
+//----------------------------------------------------------------------------
+bool cmDepends::Finalize(std::ostream&,
+ std::ostream&)
+{
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDepends::Check(const char *makeFile, const char *internalFile,
+ std::map<std::string, DependencyVector>& validDeps)
+{
+ // Dependency checks must be done in proper working directory.
+ std::string oldcwd = ".";
+ if(this->CompileDirectory != ".")
+ {
+ // Get the CWD but do not call CollapseFullPath because
+ // we only need it to cd back, and the form does not matter
+ oldcwd = cmSystemTools::GetCurrentWorkingDirectory(false);
+ cmSystemTools::ChangeDirectory(this->CompileDirectory.c_str());
+ }
+
+ // Check whether dependencies must be regenerated.
+ bool okay = true;
+ cmsys::ifstream fin(internalFile);
+ if(!(fin && this->CheckDependencies(fin, internalFile, validDeps)))
+ {
+ // Clear all dependencies so they will be regenerated.
+ this->Clear(makeFile);
+ cmSystemTools::RemoveFile(internalFile);
+ okay = false;
+ }
+
+ // Restore working directory.
+ if(oldcwd != ".")
+ {
+ cmSystemTools::ChangeDirectory(oldcwd.c_str());
+ }
+
+ return okay;
+}
+
+//----------------------------------------------------------------------------
+void cmDepends::Clear(const char *file)
+{
+ // Print verbose output.
+ if(this->Verbose)
+ {
+ cmOStringStream msg;
+ msg << "Clearing dependencies in \"" << file << "\"." << std::endl;
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+
+ // Write an empty dependency file.
+ cmGeneratedFileStream depFileStream(file);
+ depFileStream
+ << "# Empty dependencies file\n"
+ << "# This may be replaced when dependencies are built." << std::endl;
+}
+
+//----------------------------------------------------------------------------
+bool cmDepends::WriteDependencies(
+ const std::set<std::string>&, const std::string&,
+ std::ostream&, std::ostream&)
+{
+ // This should be implemented by the subclass.
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmDepends::CheckDependencies(std::istream& internalDepends,
+ const char* internalDependsFileName,
+ std::map<std::string, DependencyVector>& validDeps)
+{
+ // Parse dependencies from the stream. If any dependee is missing
+ // or newer than the depender then dependencies should be
+ // regenerated.
+ bool okay = true;
+ bool dependerExists = false;
+ DependencyVector* currentDependencies = 0;
+
+ while(internalDepends.getline(this->Dependee, this->MaxPath))
+ {
+ if ( this->Dependee[0] == 0 || this->Dependee[0] == '#' ||
+ this->Dependee[0] == '\r' )
+ {
+ continue;
+ }
+ size_t len = internalDepends.gcount()-1;
+ if ( this->Dependee[len-1] == '\r' )
+ {
+ len --;
+ this->Dependee[len] = 0;
+ }
+ if ( this->Dependee[0] != ' ' )
+ {
+ memcpy(this->Depender, this->Dependee, len+1);
+ // Calling FileExists() for the depender here saves in many cases 50%
+ // of the calls to FileExists() further down in the loop. E.g. for
+ // kdelibs/khtml this reduces the number of calls from 184k down to 92k,
+ // or the time for cmake -E cmake_depends from 0.3 s down to 0.21 s.
+ dependerExists = cmSystemTools::FileExists(this->Depender);
+ // If we erase validDeps[this->Depender] by overwriting it with an empty
+ // vector, we lose dependencies for dependers that have multiple
+ // entries. No need to initialize the entry, std::map will do so on first
+ // access.
+ currentDependencies = &validDeps[this->Depender];
+ continue;
+ }
+ /*
+ // Parse the dependency line.
+ if(!this->ParseDependency(line.c_str()))
+ {
+ continue;
+ }
+ */
+
+ // Dependencies must be regenerated
+ // * if the dependee does not exist
+ // * if the depender exists and is older than the dependee.
+ // * if the depender does not exist, but the dependee is newer than the
+ // depends file
+ bool regenerate = false;
+ const char* dependee = this->Dependee+1;
+ const char* depender = this->Depender;
+ if (currentDependencies != 0)
+ {
+ currentDependencies->push_back(dependee);
+ }
+
+ if(!cmSystemTools::FileExists(dependee))
+ {
+ // The dependee does not exist.
+ regenerate = true;
+
+ // Print verbose output.
+ if(this->Verbose)
+ {
+ cmOStringStream msg;
+ msg << "Dependee \"" << dependee
+ << "\" does not exist for depender \""
+ << depender << "\"." << std::endl;
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ }
+ else
+ {
+ if(dependerExists)
+ {
+ // The dependee and depender both exist. Compare file times.
+ int result = 0;
+ if((!this->FileComparison->FileTimeCompare(depender, dependee,
+ &result) || result < 0))
+ {
+ // The depender is older than the dependee.
+ regenerate = true;
+
+ // Print verbose output.
+ if(this->Verbose)
+ {
+ cmOStringStream msg;
+ msg << "Dependee \"" << dependee
+ << "\" is newer than depender \""
+ << depender << "\"." << std::endl;
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ }
+ }
+ else
+ {
+ // The dependee exists, but the depender doesn't. Regenerate if the
+ // internalDepends file is older than the dependee.
+ int result = 0;
+ if((!this->FileComparison->FileTimeCompare(internalDependsFileName,
+ dependee, &result) || result < 0))
+ {
+ // The depends-file is older than the dependee.
+ regenerate = true;
+
+ // Print verbose output.
+ if(this->Verbose)
+ {
+ cmOStringStream msg;
+ msg << "Dependee \"" << dependee
+ << "\" is newer than depends file \""
+ << internalDependsFileName << "\"." << std::endl;
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ }
+ }
+ }
+ if(regenerate)
+ {
+ // Dependencies must be regenerated.
+ okay = false;
+
+ // Remove the information of this depender from the map, it needs
+ // to be rescanned
+ if (currentDependencies != 0)
+ {
+ validDeps.erase(this->Depender);
+ currentDependencies = 0;
+ }
+
+ // Remove the depender to be sure it is rebuilt.
+ if (dependerExists)
+ {
+ cmSystemTools::RemoveFile(depender);
+ dependerExists = false;
+ }
+ }
+ }
+
+ return okay;
+}
+
+//----------------------------------------------------------------------------
+void cmDepends::SetIncludePathFromLanguage(const std::string& lang)
+{
+ // Look for the new per "TARGET_" variant first:
+ const char * includePath = 0;
+ std::string includePathVar = "CMAKE_";
+ includePathVar += lang;
+ includePathVar += "_TARGET_INCLUDE_PATH";
+ cmMakefile* mf = this->LocalGenerator->GetMakefile();
+ includePath = mf->GetDefinition(includePathVar);
+ if(includePath)
+ {
+ cmSystemTools::ExpandListArgument(includePath, this->IncludePath);
+ }
+ else
+ {
+ // Fallback to the old directory level variable if no per-target var:
+ includePathVar = "CMAKE_";
+ includePathVar += lang;
+ includePathVar += "_INCLUDE_PATH";
+ includePath = mf->GetDefinition(includePathVar);
+ if(includePath)
+ {
+ cmSystemTools::ExpandListArgument(includePath, this->IncludePath);
+ }
+ }
+}
diff --git a/Source/cmDepends.h b/Source/cmDepends.h
new file mode 100644
index 0000000000..4f6517ed49
--- /dev/null
+++ b/Source/cmDepends.h
@@ -0,0 +1,124 @@
+/*============================================================================
+ 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 cmDepends_h
+#define cmDepends_h
+
+#include "cmStandardIncludes.h"
+
+class cmFileTimeComparison;
+class cmLocalGenerator;
+
+/** \class cmDepends
+ * \brief Dependency scanner superclass.
+ *
+ * This class is responsible for maintaining a .depends.make file in
+ * the build tree corresponding to an object file. Subclasses help it
+ * maintain dependencies for particular languages.
+ */
+class cmDepends
+{
+public:
+ /** Instances need to know the build directory name and the relative
+ path from the build directory to the target file. */
+ cmDepends(cmLocalGenerator* lg=0, const char* targetDir="");
+
+ /** at what level will the compile be done from */
+ void SetCompileDirectory(const char *dir) {this->CompileDirectory = dir;}
+
+ /** Set the local generator for the directory in which we are
+ scanning dependencies. This is not a full local generator; it
+ has been setup to do relative path conversions for the current
+ directory. */
+ void SetLocalGenerator(cmLocalGenerator* lg) { this->LocalGenerator = lg; }
+
+ /** Set the specific language to be scanned. */
+ void SetLanguage(const std::string& lang) { this->Language = lang; }
+
+ /** Set the target build directory. */
+ void SetTargetDirectory(const char* dir) { this->TargetDirectory = dir; }
+
+ /** should this be verbose in its output */
+ void SetVerbose(bool verb) { this->Verbose = verb; }
+
+ /** Virtual destructor to cleanup subclasses properly. */
+ virtual ~cmDepends();
+
+ /** Write dependencies for the target file. */
+ bool Write(std::ostream &makeDepends, std::ostream &internalDepends);
+
+ class DependencyVector: public std::vector<std::string> {};
+
+ /** Check dependencies for the target file. Returns true if
+ dependencies are okay and false if they must be generated. If
+ they must be generated Clear has already been called to wipe out
+ the old dependencies.
+ Dependencies which are still valid will be stored in validDeps. */
+ bool Check(const char *makeFile, const char* internalFile,
+ std::map<std::string, DependencyVector>& validDeps);
+
+ /** Clear dependencies for the target file so they will be regenerated. */
+ void Clear(const char *file);
+
+ /** Set the file comparison object */
+ void SetFileComparison(cmFileTimeComparison* fc) {
+ this->FileComparison = fc; }
+
+protected:
+
+ // Write dependencies for the target file to the given stream.
+ // Return true for success and false for failure.
+ virtual bool WriteDependencies(const std::set<std::string>& sources,
+ const std::string& obj,
+ std::ostream& makeDepends,
+ std::ostream& internalDepends);
+
+ // Check dependencies for the target file in the given stream.
+ // Return false if dependencies must be regenerated and true
+ // otherwise.
+ virtual bool CheckDependencies(std::istream& internalDepends,
+ const char* internalDependsFileName,
+ std::map<std::string, DependencyVector>& validDeps);
+
+ // Finalize the dependency information for the target.
+ virtual bool Finalize(std::ostream& makeDepends,
+ std::ostream& internalDepends);
+
+ // The directory in which the build rule for the target file is executed.
+ std::string CompileDirectory;
+
+ // The local generator.
+ cmLocalGenerator* LocalGenerator;
+
+ // Flag for verbose output.
+ bool Verbose;
+ cmFileTimeComparison* FileComparison;
+
+ std::string Language;
+
+ // The full path to the target's build directory.
+ std::string TargetDirectory;
+
+ size_t MaxPath;
+ char* Dependee;
+ char* Depender;
+
+ // The include file search path.
+ std::vector<std::string> IncludePath;
+
+ void SetIncludePathFromLanguage(const std::string& lang);
+
+private:
+ cmDepends(cmDepends const&); // Purposely not implemented.
+ void operator=(cmDepends const&); // Purposely not implemented.
+};
+
+#endif
diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx
new file mode 100644
index 0000000000..a1fc268e1f
--- /dev/null
+++ b/Source/cmDependsC.cxx
@@ -0,0 +1,581 @@
+/*============================================================================
+ 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 "cmDependsC.h"
+
+#include "cmFileTimeComparison.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include <cmsys/FStream.hxx>
+
+#include <ctype.h> // isspace
+
+
+#define INCLUDE_REGEX_LINE \
+ "^[ \t]*#[ \t]*(include|import)[ \t]*[<\"]([^\">]+)([\">])"
+
+#define INCLUDE_REGEX_LINE_MARKER "#IncludeRegexLine: "
+#define INCLUDE_REGEX_SCAN_MARKER "#IncludeRegexScan: "
+#define INCLUDE_REGEX_COMPLAIN_MARKER "#IncludeRegexComplain: "
+#define INCLUDE_REGEX_TRANSFORM_MARKER "#IncludeRegexTransform: "
+
+//----------------------------------------------------------------------------
+cmDependsC::cmDependsC()
+: ValidDeps(0)
+{
+}
+
+//----------------------------------------------------------------------------
+cmDependsC::cmDependsC(cmLocalGenerator* lg,
+ const char* targetDir,
+ const std::string& lang,
+ const std::map<std::string, DependencyVector>* validDeps)
+: cmDepends(lg, targetDir)
+, ValidDeps(validDeps)
+{
+ cmMakefile* mf = lg->GetMakefile();
+
+ // Configure the include file search path.
+ this->SetIncludePathFromLanguage(lang);
+
+ // Configure regular expressions.
+ std::string scanRegex = "^.*$";
+ std::string complainRegex = "^$";
+ {
+ std::string scanRegexVar = "CMAKE_";
+ scanRegexVar += lang;
+ scanRegexVar += "_INCLUDE_REGEX_SCAN";
+ if(const char* sr = mf->GetDefinition(scanRegexVar))
+ {
+ scanRegex = sr;
+ }
+ std::string complainRegexVar = "CMAKE_";
+ complainRegexVar += lang;
+ complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
+ if(const char* cr = mf->GetDefinition(complainRegexVar))
+ {
+ complainRegex = cr;
+ }
+ }
+
+ this->IncludeRegexLine.compile(INCLUDE_REGEX_LINE);
+ this->IncludeRegexScan.compile(scanRegex.c_str());
+ this->IncludeRegexComplain.compile(complainRegex.c_str());
+ this->IncludeRegexLineString = INCLUDE_REGEX_LINE_MARKER INCLUDE_REGEX_LINE;
+ this->IncludeRegexScanString = INCLUDE_REGEX_SCAN_MARKER;
+ this->IncludeRegexScanString += scanRegex;
+ this->IncludeRegexComplainString = INCLUDE_REGEX_COMPLAIN_MARKER;
+ this->IncludeRegexComplainString += complainRegex;
+
+ this->SetupTransforms();
+
+ this->CacheFileName = this->TargetDirectory;
+ this->CacheFileName += "/";
+ this->CacheFileName += lang;
+ this->CacheFileName += ".includecache";
+
+ this->ReadCacheFile();
+}
+
+//----------------------------------------------------------------------------
+cmDependsC::~cmDependsC()
+{
+ this->WriteCacheFile();
+
+ for (std::map<std::string, cmIncludeLines*>::iterator it=
+ this->FileCache.begin(); it!=this->FileCache.end(); ++it)
+ {
+ delete it->second;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
+ const std::string& obj,
+ std::ostream& makeDepends,
+ std::ostream& internalDepends)
+{
+ // Make sure this is a scanning instance.
+ if(sources.empty() || sources.begin()->empty())
+ {
+ cmSystemTools::Error("Cannot scan dependencies without a source file.");
+ return false;
+ }
+ if(obj.empty())
+ {
+ cmSystemTools::Error("Cannot scan dependencies without an object file.");
+ return false;
+ }
+
+ std::set<std::string> dependencies;
+ bool haveDeps = false;
+
+ if (this->ValidDeps != 0)
+ {
+ std::map<std::string, DependencyVector>::const_iterator tmpIt =
+ this->ValidDeps->find(obj);
+ if (tmpIt!= this->ValidDeps->end())
+ {
+ for(DependencyVector::const_iterator i=tmpIt->second.begin();
+ i != tmpIt->second.end(); ++i)
+ {
+ dependencies.insert(*i);
+ }
+ haveDeps = true;
+ }
+ }
+
+ if (!haveDeps)
+ {
+ // Walk the dependency graph starting with the source file.
+ int srcFiles = (int)sources.size();
+ this->Encountered.clear();
+
+ for(std::set<std::string>::const_iterator srcIt = sources.begin();
+ srcIt != sources.end(); ++srcIt)
+ {
+ UnscannedEntry root;
+ root.FileName = *srcIt;
+ this->Unscanned.push(root);
+ this->Encountered.insert(*srcIt);
+ }
+
+ std::set<std::string> scanned;
+
+ // Use reserve to allocate enough memory for tempPathStr
+ // so that during the loops no memory is allocated or freed
+ std::string tempPathStr;
+ tempPathStr.reserve(4*1024);
+
+ while(!this->Unscanned.empty())
+ {
+ // Get the next file to scan.
+ UnscannedEntry current = this->Unscanned.front();
+ this->Unscanned.pop();
+
+ // If not a full path, find the file in the include path.
+ std::string fullName;
+ if((srcFiles>0)
+ || cmSystemTools::FileIsFullPath(current.FileName.c_str()))
+ {
+ if(cmSystemTools::FileExists(current.FileName.c_str(), true))
+ {
+ fullName = current.FileName;
+ }
+ }
+ else if(!current.QuotedLocation.empty() &&
+ cmSystemTools::FileExists(current.QuotedLocation.c_str(), true))
+ {
+ // The include statement producing this entry was a double-quote
+ // include and the included file is present in the directory of
+ // the source containing the include statement.
+ fullName = current.QuotedLocation;
+ }
+ else
+ {
+ std::map<std::string, std::string>::iterator
+ headerLocationIt=this->HeaderLocationCache.find(current.FileName);
+ if (headerLocationIt!=this->HeaderLocationCache.end())
+ {
+ fullName=headerLocationIt->second;
+ }
+ else for(std::vector<std::string>::const_iterator i =
+ this->IncludePath.begin(); i != this->IncludePath.end(); ++i)
+ {
+ // Construct the name of the file as if it were in the current
+ // include directory. Avoid using a leading "./".
+
+ tempPathStr =
+ cmSystemTools::CollapseCombinedPath(*i, current.FileName);
+
+ // Look for the file in this location.
+ if(cmSystemTools::FileExists(tempPathStr.c_str(), true))
+ {
+ fullName = tempPathStr;
+ HeaderLocationCache[current.FileName]=fullName;
+ break;
+ }
+ }
+ }
+
+ // Complain if the file cannot be found and matches the complain
+ // regex.
+ if(fullName.empty() &&
+ this->IncludeRegexComplain.find(current.FileName.c_str()))
+ {
+ cmSystemTools::Error("Cannot find file \"",
+ current.FileName.c_str(), "\".");
+ return false;
+ }
+
+ // Scan the file if it was found and has not been scanned already.
+ if(!fullName.empty() && (scanned.find(fullName) == scanned.end()))
+ {
+ // Record scanned files.
+ scanned.insert(fullName);
+
+ // Check whether this file is already in the cache
+ std::map<std::string, cmIncludeLines*>::iterator fileIt=
+ this->FileCache.find(fullName);
+ if (fileIt!=this->FileCache.end())
+ {
+ fileIt->second->Used=true;
+ dependencies.insert(fullName);
+ for (std::vector<UnscannedEntry>::const_iterator incIt=
+ fileIt->second->UnscannedEntries.begin();
+ incIt!=fileIt->second->UnscannedEntries.end(); ++incIt)
+ {
+ if (this->Encountered.find(incIt->FileName) ==
+ this->Encountered.end())
+ {
+ this->Encountered.insert(incIt->FileName);
+ this->Unscanned.push(*incIt);
+ }
+ }
+ }
+ else
+ {
+
+ // Try to scan the file. Just leave it out if we cannot find
+ // it.
+ cmsys::ifstream fin(fullName.c_str());
+ if(fin)
+ {
+ // Add this file as a dependency.
+ dependencies.insert(fullName);
+
+ // Scan this file for new dependencies. Pass the directory
+ // containing the file to handle double-quote includes.
+ std::string dir = cmSystemTools::GetFilenamePath(fullName);
+ this->Scan(fin, dir.c_str(), fullName);
+ }
+ }
+ }
+
+ srcFiles--;
+ }
+ }
+
+ // Write the dependencies to the output stream. Makefile rules
+ // written by the original local generator for this directory
+ // convert the dependencies to paths relative to the home output
+ // directory. We must do the same here.
+ std::string obj_i =
+ this->LocalGenerator->Convert(obj, cmLocalGenerator::HOME_OUTPUT);
+ std::string obj_m =
+ this->LocalGenerator->ConvertToOutputFormat(obj_i,
+ cmLocalGenerator::MAKERULE);
+ internalDepends << obj_i << std::endl;
+
+ for(std::set<std::string>::const_iterator i=dependencies.begin();
+ i != dependencies.end(); ++i)
+ {
+ makeDepends << obj_m << ": " <<
+ this->LocalGenerator->Convert(*i,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE)
+ << std::endl;
+ internalDepends << " " << *i << std::endl;
+ }
+ makeDepends << std::endl;
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmDependsC::ReadCacheFile()
+{
+ if(this->CacheFileName.size() == 0)
+ {
+ return;
+ }
+ cmsys::ifstream fin(this->CacheFileName.c_str());
+ if(!fin)
+ {
+ return;
+ }
+
+ std::string line;
+ cmIncludeLines* cacheEntry=0;
+ bool haveFileName=false;
+
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ if (line.empty())
+ {
+ cacheEntry=0;
+ haveFileName=false;
+ continue;
+ }
+ //the first line after an empty line is the name of the parsed file
+ if (haveFileName==false)
+ {
+ haveFileName=true;
+ int newer=0;
+ cmFileTimeComparison comp;
+ bool res=comp.FileTimeCompare(this->CacheFileName.c_str(),
+ line.c_str(), &newer);
+
+ if ((res==true) && (newer==1)) //cache is newer than the parsed file
+ {
+ cacheEntry=new cmIncludeLines;
+ this->FileCache[line]=cacheEntry;
+ }
+ // file doesn't exist, check that the regular expressions
+ // haven't changed
+ else if (res==false)
+ {
+ if (line.find(INCLUDE_REGEX_LINE_MARKER) == 0)
+ {
+ if (line != this->IncludeRegexLineString)
+ {
+ return;
+ }
+ }
+ else if (line.find(INCLUDE_REGEX_SCAN_MARKER) == 0)
+ {
+ if (line != this->IncludeRegexScanString)
+ {
+ return;
+ }
+ }
+ else if (line.find(INCLUDE_REGEX_COMPLAIN_MARKER) == 0)
+ {
+ if (line != this->IncludeRegexComplainString)
+ {
+ return;
+ }
+ }
+ else if (line.find(INCLUDE_REGEX_TRANSFORM_MARKER) == 0)
+ {
+ if (line != this->IncludeRegexTransformString)
+ {
+ return;
+ }
+ }
+ }
+ }
+ else if (cacheEntry!=0)
+ {
+ UnscannedEntry entry;
+ entry.FileName = line;
+ if (cmSystemTools::GetLineFromStream(fin, line))
+ {
+ if (line!="-")
+ {
+ entry.QuotedLocation=line;
+ }
+ cacheEntry->UnscannedEntries.push_back(entry);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsC::WriteCacheFile() const
+{
+ if(this->CacheFileName.size() == 0)
+ {
+ return;
+ }
+ cmsys::ofstream cacheOut(this->CacheFileName.c_str());
+ if(!cacheOut)
+ {
+ return;
+ }
+
+ cacheOut << this->IncludeRegexLineString << "\n\n";
+ cacheOut << this->IncludeRegexScanString << "\n\n";
+ cacheOut << this->IncludeRegexComplainString << "\n\n";
+ cacheOut << this->IncludeRegexTransformString << "\n\n";
+
+ for (std::map<std::string, cmIncludeLines*>::const_iterator fileIt=
+ this->FileCache.begin();
+ fileIt!=this->FileCache.end(); ++fileIt)
+ {
+ if (fileIt->second->Used)
+ {
+ cacheOut<<fileIt->first.c_str()<<std::endl;
+
+ for (std::vector<UnscannedEntry>::const_iterator
+ incIt=fileIt->second->UnscannedEntries.begin();
+ incIt!=fileIt->second->UnscannedEntries.end(); ++incIt)
+ {
+ cacheOut<<incIt->FileName.c_str()<<std::endl;
+ if (incIt->QuotedLocation.empty())
+ {
+ cacheOut<<"-"<<std::endl;
+ }
+ else
+ {
+ cacheOut<<incIt->QuotedLocation.c_str()<<std::endl;
+ }
+ }
+ cacheOut<<std::endl;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsC::Scan(std::istream& is, const char* directory,
+ const std::string& fullName)
+{
+ cmIncludeLines* newCacheEntry=new cmIncludeLines;
+ newCacheEntry->Used=true;
+ this->FileCache[fullName]=newCacheEntry;
+
+ // Read one line at a time.
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(is, line))
+ {
+ // Transform the line content first.
+ if(!this->TransformRules.empty())
+ {
+ this->TransformLine(line);
+ }
+
+ // Match include directives.
+ if(this->IncludeRegexLine.find(line.c_str()))
+ {
+ // Get the file being included.
+ UnscannedEntry entry;
+ entry.FileName = this->IncludeRegexLine.match(2);
+ cmSystemTools::ConvertToUnixSlashes(entry.FileName);
+ if(this->IncludeRegexLine.match(3) == "\"" &&
+ !cmSystemTools::FileIsFullPath(entry.FileName.c_str()))
+ {
+ // This was a double-quoted include with a relative path. We
+ // must check for the file in the directory containing the
+ // file we are scanning.
+ entry.QuotedLocation =
+ cmSystemTools::CollapseCombinedPath(directory, entry.FileName);
+ }
+
+ // Queue the file if it has not yet been encountered and it
+ // matches the regular expression for recursive scanning. Note
+ // that this check does not account for the possibility of two
+ // headers with the same name in different directories when one
+ // is included by double-quotes and the other by angle brackets.
+ // It also does not work properly if two header files with the same
+ // name exist in different directories, and both are included from a
+ // file their own directory by simply using "filename.h" (#12619)
+ // This kind of problem will be fixed when a more
+ // preprocessor-like implementation of this scanner is created.
+ if (this->IncludeRegexScan.find(entry.FileName.c_str()))
+ {
+ newCacheEntry->UnscannedEntries.push_back(entry);
+ if(this->Encountered.find(entry.FileName) == this->Encountered.end())
+ {
+ this->Encountered.insert(entry.FileName);
+ this->Unscanned.push(entry);
+ }
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsC::SetupTransforms()
+{
+ // Get the transformation rules.
+ std::vector<std::string> transformRules;
+ cmMakefile* mf = this->LocalGenerator->GetMakefile();
+ if(const char* xform =
+ mf->GetDefinition("CMAKE_INCLUDE_TRANSFORMS"))
+ {
+ cmSystemTools::ExpandListArgument(xform, transformRules, true);
+ }
+ for(std::vector<std::string>::const_iterator tri = transformRules.begin();
+ tri != transformRules.end(); ++tri)
+ {
+ this->ParseTransform(*tri);
+ }
+
+ this->IncludeRegexTransformString = INCLUDE_REGEX_TRANSFORM_MARKER;
+ if(!this->TransformRules.empty())
+ {
+ // Construct the regular expression to match lines to be
+ // transformed.
+ std::string xform = "^([ \t]*#[ \t]*(include|import)[ \t]*)(";
+ const char* sep = "";
+ for(TransformRulesType::const_iterator tri = this->TransformRules.begin();
+ tri != this->TransformRules.end(); ++tri)
+ {
+ xform += sep;
+ xform += tri->first;
+ sep = "|";
+ }
+ xform += ")[ \t]*\\(([^),]*)\\)";
+ this->IncludeRegexTransform.compile(xform.c_str());
+
+ // Build a string that encodes all transformation rules and will
+ // change when rules are changed.
+ this->IncludeRegexTransformString += xform;
+ for(TransformRulesType::const_iterator tri = this->TransformRules.begin();
+ tri != this->TransformRules.end(); ++tri)
+ {
+ this->IncludeRegexTransformString += " ";
+ this->IncludeRegexTransformString += tri->first;
+ this->IncludeRegexTransformString += "(%)=";
+ this->IncludeRegexTransformString += tri->second;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsC::ParseTransform(std::string const& xform)
+{
+ // A transform rule is of the form SOME_MACRO(%)=value-with-%
+ // We can simply separate with "(%)=".
+ std::string::size_type pos = xform.find("(%)=");
+ if(pos == xform.npos || pos == 0)
+ {
+ return;
+ }
+ std::string name = xform.substr(0, pos);
+ std::string value = xform.substr(pos+4, xform.npos);
+ this->TransformRules[name] = value;
+}
+
+//----------------------------------------------------------------------------
+void cmDependsC::TransformLine(std::string& line)
+{
+ // Check for a transform rule match. Return if none.
+ if(!this->IncludeRegexTransform.find(line.c_str()))
+ {
+ return;
+ }
+ TransformRulesType::const_iterator tri =
+ this->TransformRules.find(this->IncludeRegexTransform.match(3));
+ if(tri == this->TransformRules.end())
+ {
+ return;
+ }
+
+ // Construct the transformed line.
+ std::string newline = this->IncludeRegexTransform.match(1);
+ std::string arg = this->IncludeRegexTransform.match(4);
+ for(const char* c = tri->second.c_str(); *c; ++c)
+ {
+ if(*c == '%')
+ {
+ newline += arg;
+ }
+ else
+ {
+ newline += *c;
+ }
+ }
+
+ // Return the transformed line.
+ line = newline;
+}
diff --git a/Source/cmDependsC.h b/Source/cmDependsC.h
new file mode 100644
index 0000000000..07d3c21f34
--- /dev/null
+++ b/Source/cmDependsC.h
@@ -0,0 +1,97 @@
+/*============================================================================
+ 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 cmDependsC_h
+#define cmDependsC_h
+
+#include "cmDepends.h"
+#include <cmsys/RegularExpression.hxx>
+#include <queue>
+
+/** \class cmDependsC
+ * \brief Dependency scanner for C and C++ object files.
+ */
+class cmDependsC: public cmDepends
+{
+public:
+ /** Checking instances need to know the build directory name and the
+ relative path from the build directory to the target file. */
+ cmDependsC();
+ cmDependsC(cmLocalGenerator* lg, const char* targetDir,
+ const std::string& lang,
+ const std::map<std::string, DependencyVector>* validDeps);
+
+ /** Virtual destructor to cleanup subclasses properly. */
+ virtual ~cmDependsC();
+
+protected:
+ // Implement writing/checking methods required by superclass.
+ virtual bool WriteDependencies(const std::set<std::string>& sources,
+ const std::string& obj,
+ std::ostream& makeDepends,
+ std::ostream& internalDepends);
+
+ // Method to scan a single file.
+ void Scan(std::istream& is, const char* directory,
+ const std::string& fullName);
+
+ // Regular expression to identify C preprocessor include directives.
+ cmsys::RegularExpression IncludeRegexLine;
+
+ // Regular expressions to choose which include files to scan
+ // recursively and which to complain about not finding.
+ cmsys::RegularExpression IncludeRegexScan;
+ cmsys::RegularExpression IncludeRegexComplain;
+ std::string IncludeRegexLineString;
+ std::string IncludeRegexScanString;
+ std::string IncludeRegexComplainString;
+
+ // Regex to transform #include lines.
+ std::string IncludeRegexTransformString;
+ cmsys::RegularExpression IncludeRegexTransform;
+ typedef std::map<std::string, std::string> TransformRulesType;
+ TransformRulesType TransformRules;
+ void SetupTransforms();
+ void ParseTransform(std::string const& xform);
+ void TransformLine(std::string& line);
+
+public:
+ // Data structures for dependency graph walk.
+ struct UnscannedEntry
+ {
+ std::string FileName;
+ std::string QuotedLocation;
+ };
+
+ struct cmIncludeLines
+ {
+ cmIncludeLines(): Used(false) {}
+ std::vector<UnscannedEntry> UnscannedEntries;
+ bool Used;
+ };
+protected:
+ const std::map<std::string, DependencyVector>* ValidDeps;
+ std::set<std::string> Encountered;
+ std::queue<UnscannedEntry> Unscanned;
+
+ std::map<std::string, cmIncludeLines *> FileCache;
+ std::map<std::string, std::string> HeaderLocationCache;
+
+ std::string CacheFileName;
+
+ void WriteCacheFile() const;
+ void ReadCacheFile();
+private:
+ cmDependsC(cmDependsC const&); // Purposely not implemented.
+ void operator=(cmDependsC const&); // Purposely not implemented.
+};
+
+#endif
diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx
new file mode 100644
index 0000000000..8fc8347dd7
--- /dev/null
+++ b/Source/cmDependsFortran.cxx
@@ -0,0 +1,1282 @@
+/*============================================================================
+ 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 "cmDependsFortran.h"
+
+#include "cmSystemTools.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+
+#include "cmDependsFortranParser.h" /* Interface to parser object. */
+#include <cmsys/FStream.hxx>
+#include <assert.h>
+#include <stack>
+
+// TODO: Test compiler for the case of the mod file. Some always
+// use lower case and some always use upper case. I do not know if any
+// use the case from the source code.
+
+//----------------------------------------------------------------------------
+// Information about a single source file.
+class cmDependsFortranSourceInfo
+{
+public:
+ // The name of the source file.
+ std::string Source;
+
+ // Set of provided and required modules.
+ std::set<std::string> Provides;
+ std::set<std::string> Requires;
+
+ // Set of files included in the translation unit.
+ std::set<std::string> Includes;
+};
+
+//----------------------------------------------------------------------------
+// Parser methods not included in generated interface.
+
+// Get the current buffer processed by the lexer.
+YY_BUFFER_STATE cmDependsFortranLexer_GetCurrentBuffer(yyscan_t yyscanner);
+
+// The parser entry point.
+int cmDependsFortran_yyparse(yyscan_t);
+
+//----------------------------------------------------------------------------
+// Define parser object internal structure.
+struct cmDependsFortranFile
+{
+ cmDependsFortranFile(FILE* file, YY_BUFFER_STATE buffer,
+ const std::string& dir):
+ File(file), Buffer(buffer), Directory(dir) {}
+ FILE* File;
+ YY_BUFFER_STATE Buffer;
+ std::string Directory;
+};
+
+struct cmDependsFortranParser_s
+{
+ cmDependsFortranParser_s(cmDependsFortran* self,
+ std::set<std::string>& ppDefines,
+ cmDependsFortranSourceInfo& info);
+ ~cmDependsFortranParser_s();
+
+ // Pointer back to the main class.
+ cmDependsFortran* Self;
+
+ // Lexical scanner instance.
+ yyscan_t Scanner;
+
+ // Stack of open files in the translation unit.
+ std::stack<cmDependsFortranFile> FileStack;
+
+ // Buffer for string literals.
+ std::string TokenString;
+
+ // Flag for whether lexer is reading from inside an interface.
+ bool InInterface;
+
+ int OldStartcond;
+ std::set<std::string> PPDefinitions;
+ size_t InPPFalseBranch;
+ std::stack<bool> SkipToEnd;
+
+ // Information about the parsed source.
+ cmDependsFortranSourceInfo& Info;
+};
+
+//----------------------------------------------------------------------------
+class cmDependsFortranInternals
+{
+public:
+ // The set of modules provided by this target.
+ std::set<std::string> TargetProvides;
+
+ // Map modules required by this target to locations.
+ typedef std::map<std::string, std::string> TargetRequiresMap;
+ TargetRequiresMap TargetRequires;
+
+ // Information about each object file.
+ typedef std::map<std::string, cmDependsFortranSourceInfo> ObjectInfoMap;
+ ObjectInfoMap ObjectInfo;
+
+ cmDependsFortranSourceInfo& CreateObjectInfo(const char* obj,
+ const char* src)
+ {
+ std::map<std::string, cmDependsFortranSourceInfo>::iterator i =
+ this->ObjectInfo.find(obj);
+ if(i == this->ObjectInfo.end())
+ {
+ std::map<std::string, cmDependsFortranSourceInfo>::value_type
+ entry(obj, cmDependsFortranSourceInfo());
+ i = this->ObjectInfo.insert(entry).first;
+ i->second.Source = src;
+ }
+ return i->second;
+ }
+};
+
+//----------------------------------------------------------------------------
+cmDependsFortran::cmDependsFortran():
+ PPDefinitions(0), Internal(0)
+{
+}
+
+//----------------------------------------------------------------------------
+cmDependsFortran
+::cmDependsFortran(cmLocalGenerator* lg):
+ cmDepends(lg),
+ Internal(new cmDependsFortranInternals)
+{
+ // Configure the include file search path.
+ this->SetIncludePathFromLanguage("Fortran");
+
+ // Get the list of definitions.
+ std::vector<std::string> definitions;
+ cmMakefile* mf = this->LocalGenerator->GetMakefile();
+ if(const char* c_defines =
+ mf->GetDefinition("CMAKE_TARGET_DEFINITIONS"))
+ {
+ cmSystemTools::ExpandListArgument(c_defines, definitions);
+ }
+
+ // translate i.e. FOO=BAR to FOO and add it to the list of defined
+ // preprocessor symbols
+ for(std::vector<std::string>::const_iterator
+ it = definitions.begin(); it != definitions.end(); ++it)
+ {
+ std::string def = *it;
+ std::string::size_type assignment = def.find("=");
+ if(assignment != std::string::npos)
+ {
+ def = it->substr(0, assignment);
+ }
+ this->PPDefinitions.push_back(def);
+ }
+}
+
+//----------------------------------------------------------------------------
+cmDependsFortran::~cmDependsFortran()
+{
+ delete this->Internal;
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsFortran::WriteDependencies(
+ const std::set<std::string>& sources, const std::string& obj,
+ std::ostream&, std::ostream&)
+{
+ // Make sure this is a scanning instance.
+ if(sources.empty() || sources.begin()->empty())
+ {
+ cmSystemTools::Error("Cannot scan dependencies without a source file.");
+ return false;
+ }
+ if(obj.empty())
+ {
+ cmSystemTools::Error("Cannot scan dependencies without an object file.");
+ return false;
+ }
+
+ bool okay = true;
+ for(std::set<std::string>::const_iterator it = sources.begin();
+ it != sources.end(); ++it)
+ {
+ const std::string& src = *it;
+ // Get the information object for this source.
+ cmDependsFortranSourceInfo& info =
+ this->Internal->CreateObjectInfo(obj.c_str(), src.c_str());
+
+ // Make a copy of the macros defined via ADD_DEFINITIONS
+ std::set<std::string> ppDefines(this->PPDefinitions.begin(),
+ this->PPDefinitions.end());
+
+ // Create the parser object. The constructor takes ppMacro and info per
+ // reference, so we may look into the resulting objects later.
+ cmDependsFortranParser parser(this, ppDefines, info);
+
+ // Push on the starting file.
+ cmDependsFortranParser_FilePush(&parser, src.c_str());
+
+ // Parse the translation unit.
+ if(cmDependsFortran_yyparse(parser.Scanner) != 0)
+ {
+ // Failed to parse the file. Report failure to write dependencies.
+ okay = false;
+ }
+ }
+ return okay;
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsFortran::Finalize(std::ostream& makeDepends,
+ std::ostream& internalDepends)
+{
+ // Prepare the module search process.
+ this->LocateModules();
+
+ // Get the directory in which stamp files will be stored.
+ const char* stamp_dir = this->TargetDirectory.c_str();
+
+ // Get the directory in which module files will be created.
+ const char* mod_dir;
+ cmMakefile* mf = this->LocalGenerator->GetMakefile();
+ if(const char* target_mod_dir =
+ mf->GetDefinition("CMAKE_Fortran_TARGET_MODULE_DIR"))
+ {
+ mod_dir = target_mod_dir;
+ }
+ else
+ {
+ mod_dir =
+ this->LocalGenerator->GetMakefile()->GetCurrentOutputDirectory();
+ }
+
+ // Actually write dependencies to the streams.
+ typedef cmDependsFortranInternals::ObjectInfoMap ObjectInfoMap;
+ ObjectInfoMap const& objInfo = this->Internal->ObjectInfo;
+ for(ObjectInfoMap::const_iterator i = objInfo.begin();
+ i != objInfo.end(); ++i)
+ {
+ if(!this->WriteDependenciesReal(i->first.c_str(), i->second,
+ mod_dir, stamp_dir,
+ makeDepends, internalDepends))
+ {
+ return false;
+ }
+ }
+
+ // Store the list of modules provided by this target.
+ std::string fiName = this->TargetDirectory;
+ fiName += "/fortran.internal";
+ cmGeneratedFileStream fiStream(fiName.c_str());
+ fiStream << "# The fortran modules provided by this target.\n";
+ fiStream << "provides\n";
+ std::set<std::string> const& provides = this->Internal->TargetProvides;
+ for(std::set<std::string>::const_iterator i = provides.begin();
+ i != provides.end(); ++i)
+ {
+ fiStream << " " << *i << "\n";
+ }
+
+ // Create a script to clean the modules.
+ if(!provides.empty())
+ {
+ std::string fcName = this->TargetDirectory;
+ fcName += "/cmake_clean_Fortran.cmake";
+ cmGeneratedFileStream fcStream(fcName.c_str());
+ fcStream << "# Remove fortran modules provided by this target.\n";
+ fcStream << "FILE(REMOVE";
+ for(std::set<std::string>::const_iterator i = provides.begin();
+ i != provides.end(); ++i)
+ {
+ std::string mod_upper = mod_dir;
+ mod_upper += "/";
+ mod_upper += cmSystemTools::UpperCase(*i);
+ mod_upper += ".mod";
+ std::string mod_lower = mod_dir;
+ mod_lower += "/";
+ mod_lower += *i;
+ mod_lower += ".mod";
+ std::string stamp = stamp_dir;
+ stamp += "/";
+ stamp += *i;
+ stamp += ".mod.stamp";
+ fcStream << "\n";
+ fcStream << " \"" <<
+ this->LocalGenerator->Convert(mod_lower,
+ cmLocalGenerator::START_OUTPUT)
+ << "\"\n";
+ fcStream << " \"" <<
+ this->LocalGenerator->Convert(mod_upper,
+ cmLocalGenerator::START_OUTPUT)
+ << "\"\n";
+ fcStream << " \"" <<
+ this->LocalGenerator->Convert(stamp,
+ cmLocalGenerator::START_OUTPUT)
+ << "\"\n";
+ }
+ fcStream << " )\n";
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortran::LocateModules()
+{
+ // Collect the set of modules provided and required by all sources.
+ typedef cmDependsFortranInternals::ObjectInfoMap ObjectInfoMap;
+ ObjectInfoMap const& objInfo = this->Internal->ObjectInfo;
+ for(ObjectInfoMap::const_iterator infoI = objInfo.begin();
+ infoI != objInfo.end(); ++infoI)
+ {
+ cmDependsFortranSourceInfo const& info = infoI->second;
+ for(std::set<std::string>::const_iterator i = info.Provides.begin();
+ i != info.Provides.end(); ++i)
+ {
+ // Include this module in the set provided by this target.
+ this->Internal->TargetProvides.insert(*i);
+ }
+
+ for(std::set<std::string>::const_iterator i = info.Requires.begin();
+ i != info.Requires.end(); ++i)
+ {
+ // Include this module in the set required by this target.
+ this->Internal->TargetRequires[*i] = "";
+ }
+ }
+
+ // Short-circuit for simple targets.
+ if(this->Internal->TargetRequires.empty())
+ {
+ return;
+ }
+
+ // Match modules provided by this target to those it requires.
+ this->MatchLocalModules();
+
+ // Load information about other targets.
+ cmMakefile* mf = this->LocalGenerator->GetMakefile();
+ std::vector<std::string> infoFiles;
+ if(const char* infoFilesValue =
+ mf->GetDefinition("CMAKE_TARGET_LINKED_INFO_FILES"))
+ {
+ cmSystemTools::ExpandListArgument(infoFilesValue, infoFiles);
+ }
+ for(std::vector<std::string>::const_iterator i = infoFiles.begin();
+ i != infoFiles.end(); ++i)
+ {
+ std::string targetDir = cmSystemTools::GetFilenamePath(*i);
+ std::string fname = targetDir + "/fortran.internal";
+ cmsys::ifstream fin(fname.c_str());
+ if(fin)
+ {
+ this->MatchRemoteModules(fin, targetDir.c_str());
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortran::MatchLocalModules()
+{
+ const char* stampDir = this->TargetDirectory.c_str();
+ std::set<std::string> const& provides = this->Internal->TargetProvides;
+ for(std::set<std::string>::const_iterator i = provides.begin();
+ i != provides.end(); ++i)
+ {
+ this->ConsiderModule(i->c_str(), stampDir);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortran::MatchRemoteModules(std::istream& fin,
+ const char* stampDir)
+{
+ std::string line;
+ bool doing_provides = false;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ // Ignore comments and empty lines.
+ if(line.empty() || line[0] == '#' || line[0] == '\r')
+ {
+ continue;
+ }
+
+ if(line[0] == ' ')
+ {
+ if(doing_provides)
+ {
+ this->ConsiderModule(line.c_str()+1, stampDir);
+ }
+ }
+ else if(line == "provides")
+ {
+ doing_provides = true;
+ }
+ else
+ {
+ doing_provides = false;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortran::ConsiderModule(const char* name,
+ const char* stampDir)
+{
+ // Locate each required module.
+ typedef cmDependsFortranInternals::TargetRequiresMap TargetRequiresMap;
+ TargetRequiresMap::iterator required =
+ this->Internal->TargetRequires.find(name);
+ if(required != this->Internal->TargetRequires.end() &&
+ required->second.empty())
+ {
+ // The module is provided by a CMake target. It will have a stamp file.
+ std::string stampFile = stampDir;
+ stampFile += "/";
+ stampFile += name;
+ stampFile += ".mod.stamp";
+ required->second = stampFile;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool
+cmDependsFortran
+::WriteDependenciesReal(const char *obj,
+ cmDependsFortranSourceInfo const& info,
+ const char* mod_dir, const char* stamp_dir,
+ std::ostream& makeDepends,
+ std::ostream& internalDepends)
+{
+ typedef cmDependsFortranInternals::TargetRequiresMap TargetRequiresMap;
+
+ // Get the source file for this object.
+ const char* src = info.Source.c_str();
+
+ // Write the include dependencies to the output stream.
+ std::string obj_i =
+ this->LocalGenerator->Convert(obj, cmLocalGenerator::HOME_OUTPUT);
+ std::string obj_m =
+ this->LocalGenerator->ConvertToOutputFormat(obj_i,
+ cmLocalGenerator::MAKERULE);
+ internalDepends << obj_i << std::endl;
+ internalDepends << " " << src << std::endl;
+ for(std::set<std::string>::const_iterator i = info.Includes.begin();
+ i != info.Includes.end(); ++i)
+ {
+ makeDepends << obj_m << ": " <<
+ this->LocalGenerator->Convert(*i,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE)
+ << std::endl;
+ internalDepends << " " << *i << std::endl;
+ }
+ makeDepends << std::endl;
+
+ // Write module requirements to the output stream.
+ for(std::set<std::string>::const_iterator i = info.Requires.begin();
+ i != info.Requires.end(); ++i)
+ {
+ // Require only modules not provided in the same source.
+ if(std::set<std::string>::const_iterator(info.Provides.find(*i)) !=
+ info.Provides.end())
+ {
+ continue;
+ }
+
+ // If the module is provided in this target special handling is
+ // needed.
+ if(this->Internal->TargetProvides.find(*i) !=
+ this->Internal->TargetProvides.end())
+ {
+ // The module is provided by a different source in the same
+ // target. Add the proxy dependency to make sure the other
+ // source builds first.
+ std::string proxy = stamp_dir;
+ proxy += "/";
+ proxy += *i;
+ proxy += ".mod.proxy";
+ proxy = this->LocalGenerator->Convert(proxy,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE);
+
+ // since we require some things add them to our list of requirements
+ makeDepends << obj_m << ".requires: " << proxy << std::endl;
+ }
+
+ // The object file should depend on timestamped files for the
+ // modules it uses.
+ TargetRequiresMap::const_iterator required =
+ this->Internal->TargetRequires.find(*i);
+ if(required == this->Internal->TargetRequires.end()) { abort(); }
+ if(!required->second.empty())
+ {
+ // This module is known. Depend on its timestamp file.
+ std::string stampFile =
+ this->LocalGenerator->Convert(required->second,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE);
+ makeDepends << obj_m << ": " << stampFile << "\n";
+ }
+ else
+ {
+ // This module is not known to CMake. Try to locate it where
+ // the compiler will and depend on that.
+ std::string module;
+ if(this->FindModule(*i, module))
+ {
+ module =
+ this->LocalGenerator->Convert(module,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE);
+ makeDepends << obj_m << ": " << module << "\n";
+ }
+ }
+ }
+
+ // Write provided modules to the output stream.
+ for(std::set<std::string>::const_iterator i = info.Provides.begin();
+ i != info.Provides.end(); ++i)
+ {
+ std::string proxy = stamp_dir;
+ proxy += "/";
+ proxy += *i;
+ proxy += ".mod.proxy";
+ proxy = this->LocalGenerator->Convert(proxy,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE);
+ makeDepends << proxy << ": " << obj_m << ".provides" << std::endl;
+ }
+
+ // If any modules are provided then they must be converted to stamp files.
+ if(!info.Provides.empty())
+ {
+ // Create a target to copy the module after the object file
+ // changes.
+ makeDepends << obj_m << ".provides.build:\n";
+ for(std::set<std::string>::const_iterator i = info.Provides.begin();
+ i != info.Provides.end(); ++i)
+ {
+ // Include this module in the set provided by this target.
+ this->Internal->TargetProvides.insert(*i);
+
+ // Always use lower case for the mod stamp file name. The
+ // cmake_copy_f90_mod will call back to this class, which will
+ // try various cases for the real mod file name.
+ std::string m = cmSystemTools::LowerCase(*i);
+ std::string modFile = mod_dir;
+ modFile += "/";
+ modFile += *i;
+ modFile =
+ this->LocalGenerator->Convert(modFile,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::SHELL);
+ std::string stampFile = stamp_dir;
+ stampFile += "/";
+ stampFile += m;
+ stampFile += ".mod.stamp";
+ stampFile =
+ this->LocalGenerator->Convert(stampFile,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::SHELL);
+ makeDepends << "\t$(CMAKE_COMMAND) -E cmake_copy_f90_mod "
+ << modFile << " " << stampFile;
+ cmMakefile* mf = this->LocalGenerator->GetMakefile();
+ const char* cid = mf->GetDefinition("CMAKE_Fortran_COMPILER_ID");
+ if(cid && *cid)
+ {
+ makeDepends << " " << cid;
+ }
+ makeDepends << "\n";
+ }
+ // After copying the modules update the timestamp file so that
+ // copying will not be done again until the source rebuilds.
+ makeDepends << "\t$(CMAKE_COMMAND) -E touch " << obj_m
+ << ".provides.build\n";
+
+ // Make sure the module timestamp rule is evaluated by the time
+ // the target finishes building.
+ std::string driver = this->TargetDirectory;
+ driver += "/build";
+ driver = this->LocalGenerator->Convert(driver,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE);
+ makeDepends << driver << ": " << obj_m << ".provides.build\n";
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsFortran::FindModule(std::string const& name,
+ std::string& module)
+{
+ // Construct possible names for the module file.
+ std::string mod_upper = cmSystemTools::UpperCase(name);
+ std::string mod_lower = name;
+ mod_upper += ".mod";
+ mod_lower += ".mod";
+
+ // Search the include path for the module.
+ std::string fullName;
+ for(std::vector<std::string>::const_iterator i =
+ this->IncludePath.begin(); i != this->IncludePath.end(); ++i)
+ {
+ // Try the lower-case name.
+ fullName = *i;
+ fullName += "/";
+ fullName += mod_lower;
+ if(cmSystemTools::FileExists(fullName.c_str(), true))
+ {
+ module = fullName;
+ return true;
+ }
+
+ // Try the upper-case name.
+ fullName = *i;
+ fullName += "/";
+ fullName += mod_upper;
+ if(cmSystemTools::FileExists(fullName.c_str(), true))
+ {
+ module = fullName;
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsFortran::CopyModule(const std::vector<std::string>& args)
+{
+ // Implements
+ //
+ // $(CMAKE_COMMAND) -E cmake_copy_f90_mod input.mod output.mod.stamp
+ // [compiler-id]
+ //
+ // Note that the case of the .mod file depends on the compiler. In
+ // the future this copy could also account for the fact that some
+ // compilers include a timestamp in the .mod file so it changes even
+ // when the interface described in the module does not.
+
+ std::string mod = args[2];
+ std::string stamp = args[3];
+ std::string compilerId;
+ if(args.size() >= 5)
+ {
+ compilerId = args[4];
+ }
+ std::string mod_dir = cmSystemTools::GetFilenamePath(mod);
+ if(!mod_dir.empty()) { mod_dir += "/"; }
+ std::string mod_upper = mod_dir;
+ mod_upper += cmSystemTools::UpperCase(cmSystemTools::GetFilenameName(mod));
+ std::string mod_lower = mod_dir;
+ mod_lower += cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(mod));
+ mod += ".mod";
+ mod_upper += ".mod";
+ mod_lower += ".mod";
+ if(cmSystemTools::FileExists(mod_upper.c_str(), true))
+ {
+ if(cmDependsFortran::ModulesDiffer(mod_upper.c_str(), stamp.c_str(),
+ compilerId.c_str()))
+ {
+ if(!cmSystemTools::CopyFileAlways(mod_upper.c_str(), stamp.c_str()))
+ {
+ std::cerr << "Error copying Fortran module from \""
+ << mod_upper << "\" to \"" << stamp
+ << "\".\n";
+ return false;
+ }
+ }
+ return true;
+ }
+ else if(cmSystemTools::FileExists(mod_lower.c_str(), true))
+ {
+ if(cmDependsFortran::ModulesDiffer(mod_lower.c_str(), stamp.c_str(),
+ compilerId.c_str()))
+ {
+ if(!cmSystemTools::CopyFileAlways(mod_lower.c_str(), stamp.c_str()))
+ {
+ std::cerr << "Error copying Fortran module from \""
+ << mod_lower << "\" to \"" << stamp
+ << "\".\n";
+ return false;
+ }
+ }
+ return true;
+ }
+
+ std::cerr << "Error copying Fortran module \"" << args[2]
+ << "\". Tried \"" << mod_upper
+ << "\" and \"" << mod_lower << "\".\n";
+ return false;
+}
+
+//----------------------------------------------------------------------------
+// Helper function to look for a short sequence in a stream. If this
+// is later used for longer sequences it should be re-written using an
+// efficient string search algorithm such as Boyer-Moore.
+static
+bool cmDependsFortranStreamContainsSequence(std::istream& ifs,
+ const char* seq, int len)
+{
+ assert(len > 0);
+
+ int cur = 0;
+ while(cur < len)
+ {
+ // Get the next character.
+ int token = ifs.get();
+ if(!ifs)
+ {
+ return false;
+ }
+
+ // Check the character.
+ if(token == static_cast<int>(seq[cur]))
+ {
+ ++cur;
+ }
+ else
+ {
+ // Assume the sequence has no repeating subsequence.
+ cur = 0;
+ }
+ }
+
+ // The entire sequence was matched.
+ return true;
+}
+
+//----------------------------------------------------------------------------
+// Helper function to compare the remaining content in two streams.
+static bool cmDependsFortranStreamsDiffer(std::istream& ifs1,
+ std::istream& ifs2)
+{
+ // Compare the remaining content.
+ for(;;)
+ {
+ int ifs1_c = ifs1.get();
+ int ifs2_c = ifs2.get();
+ if(!ifs1 && !ifs2)
+ {
+ // We have reached the end of both streams simultaneously.
+ // The streams are identical.
+ return false;
+ }
+
+ if(!ifs1 || !ifs2 || ifs1_c != ifs2_c)
+ {
+ // We have reached the end of one stream before the other or
+ // found differing content. The streams are different.
+ break;
+ }
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsFortran::ModulesDiffer(const char* modFile,
+ const char* stampFile,
+ const char* compilerId)
+{
+ /*
+ gnu >= 4.9:
+ A mod file is an ascii file compressed with gzip.
+ Compiling twice produces identical modules.
+
+ gnu < 4.9:
+ A mod file is an ascii file.
+ <bar.mod>
+ FORTRAN module created from /path/to/foo.f90 on Sun Dec 30 22:47:58 2007
+ If you edit this, you'll get what you deserve.
+ ...
+ </bar.mod>
+ As you can see the first line contains the date.
+
+ intel:
+ A mod file is a binary file.
+ However, looking into both generated bar.mod files with a hex editor
+ shows that they differ only before a sequence linefeed-zero (0x0A 0x00)
+ which is located some bytes in front of the absoulte path to the source
+ file.
+
+ sun:
+ A mod file is a binary file. Compiling twice produces identical modules.
+
+ others:
+ TODO ...
+ */
+
+
+ /* Compilers which do _not_ produce different mod content when the same
+ * source is compiled twice
+ * -SunPro
+ */
+ if(strcmp(compilerId, "SunPro") == 0)
+ {
+ return cmSystemTools::FilesDiffer(modFile, stampFile);
+ }
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+ cmsys::ifstream finModFile(modFile, std::ios::in | std::ios::binary);
+ cmsys::ifstream finStampFile(stampFile, std::ios::in | std::ios::binary);
+#else
+ cmsys::ifstream finModFile(modFile, std::ios::in);
+ cmsys::ifstream finStampFile(stampFile, std::ios::in);
+#endif
+ if(!finModFile || !finStampFile)
+ {
+ // At least one of the files does not exist. The modules differ.
+ return true;
+ }
+
+ /* Compilers which _do_ produce different mod content when the same
+ * source is compiled twice
+ * -GNU
+ * -Intel
+ *
+ * Eat the stream content until all recompile only related changes
+ * are left behind.
+ */
+ if (strcmp(compilerId, "GNU") == 0 )
+ {
+ // GNU Fortran 4.9 and later compress .mod files with gzip
+ // but also do not include a date so we can fall through to
+ // compare them without skipping any prefix.
+ unsigned char hdr[2];
+ bool okay = finModFile.read(reinterpret_cast<char*>(hdr), 2)? true:false;
+ finModFile.seekg(0);
+ if(!(okay && hdr[0] == 0x1f && hdr[1] == 0x8b))
+ {
+ const char seq[1] = {'\n'};
+ const int seqlen = 1;
+
+ if(!cmDependsFortranStreamContainsSequence(finModFile, seq, seqlen))
+ {
+ // The module is of unexpected format. Assume it is different.
+ std::cerr << compilerId << " fortran module " << modFile
+ << " has unexpected format." << std::endl;
+ return true;
+ }
+
+ if(!cmDependsFortranStreamContainsSequence(finStampFile, seq, seqlen))
+ {
+ // The stamp must differ if the sequence is not contained.
+ return true;
+ }
+ }
+ }
+ else if(strcmp(compilerId, "Intel") == 0)
+ {
+ const char seq[2] = {'\n', '\0'};
+ const int seqlen = 2;
+
+ if(!cmDependsFortranStreamContainsSequence(finModFile, seq, seqlen))
+ {
+ // The module is of unexpected format. Assume it is different.
+ std::cerr << compilerId << " fortran module " << modFile
+ << " has unexpected format." << std::endl;
+ return true;
+ }
+
+ if(!cmDependsFortranStreamContainsSequence(finStampFile, seq, seqlen))
+ {
+ // The stamp must differ if the sequence is not contained.
+ return true;
+ }
+ }
+
+ // Compare the remaining content. If no compiler id matched above,
+ // including the case none was given, this will compare the whole
+ // content.
+ if(!cmDependsFortranStreamsDiffer(finModFile, finStampFile))
+ {
+ return false;
+ }
+
+ // The modules are different.
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsFortran::FindIncludeFile(const char* dir,
+ const char* includeName,
+ std::string& fileName)
+{
+ // If the file is a full path, include it directly.
+ if(cmSystemTools::FileIsFullPath(includeName))
+ {
+ fileName = includeName;
+ return cmSystemTools::FileExists(fileName.c_str(), true);
+ }
+ else
+ {
+ // Check for the file in the directory containing the including
+ // file.
+ std::string fullName = dir;
+ fullName += "/";
+ fullName += includeName;
+ if(cmSystemTools::FileExists(fullName.c_str(), true))
+ {
+ fileName = fullName;
+ return true;
+ }
+
+ // Search the include path for the file.
+ for(std::vector<std::string>::const_iterator i =
+ this->IncludePath.begin(); i != this->IncludePath.end(); ++i)
+ {
+ fullName = *i;
+ fullName += "/";
+ fullName += includeName;
+ if(cmSystemTools::FileExists(fullName.c_str(), true))
+ {
+ fileName = fullName;
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+cmDependsFortranParser_s
+::cmDependsFortranParser_s(cmDependsFortran* self,
+ std::set<std::string>& ppDefines,
+ cmDependsFortranSourceInfo& info):
+ Self(self), PPDefinitions(ppDefines), Info(info)
+{
+ this->InInterface = 0;
+ this->InPPFalseBranch = 0;
+
+ // Initialize the lexical scanner.
+ cmDependsFortran_yylex_init(&this->Scanner);
+ cmDependsFortran_yyset_extra(this, this->Scanner);
+
+ // Create a dummy buffer that is never read but is the fallback
+ // buffer when the last file is popped off the stack.
+ YY_BUFFER_STATE buffer =
+ cmDependsFortran_yy_create_buffer(0, 4, this->Scanner);
+ cmDependsFortran_yy_switch_to_buffer(buffer, this->Scanner);
+}
+
+//----------------------------------------------------------------------------
+cmDependsFortranParser_s::~cmDependsFortranParser_s()
+{
+ cmDependsFortran_yylex_destroy(this->Scanner);
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsFortranParser_FilePush(cmDependsFortranParser* parser,
+ const char* fname)
+{
+ // Open the new file and push it onto the stack. Save the old
+ // buffer with it on the stack.
+ if(FILE* file = cmsys::SystemTools::Fopen(fname, "rb"))
+ {
+ YY_BUFFER_STATE current =
+ cmDependsFortranLexer_GetCurrentBuffer(parser->Scanner);
+ std::string dir = cmSystemTools::GetParentDirectory(fname);
+ cmDependsFortranFile f(file, current, dir);
+ YY_BUFFER_STATE buffer =
+ cmDependsFortran_yy_create_buffer(0, 16384, parser->Scanner);
+ cmDependsFortran_yy_switch_to_buffer(buffer, parser->Scanner);
+ parser->FileStack.push(f);
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsFortranParser_FilePop(cmDependsFortranParser* parser)
+{
+ // Pop one file off the stack and close it. Switch the lexer back
+ // to the next one on the stack.
+ if(parser->FileStack.empty())
+ {
+ return 0;
+ }
+ else
+ {
+ cmDependsFortranFile f = parser->FileStack.top(); parser->FileStack.pop();
+ fclose(f.File);
+ YY_BUFFER_STATE current =
+ cmDependsFortranLexer_GetCurrentBuffer(parser->Scanner);
+ cmDependsFortran_yy_delete_buffer(current, parser->Scanner);
+ cmDependsFortran_yy_switch_to_buffer(f.Buffer, parser->Scanner);
+ return 1;
+ }
+}
+
+//----------------------------------------------------------------------------
+int cmDependsFortranParser_Input(cmDependsFortranParser* parser,
+ char* buffer, size_t bufferSize)
+{
+ // Read from the file on top of the stack. If the stack is empty,
+ // the end of the translation unit has been reached.
+ if(!parser->FileStack.empty())
+ {
+ FILE* file = parser->FileStack.top().File;
+ return (int)fread(buffer, 1, bufferSize, file);
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_StringStart(cmDependsFortranParser* parser)
+{
+ parser->TokenString = "";
+}
+
+//----------------------------------------------------------------------------
+const char* cmDependsFortranParser_StringEnd(cmDependsFortranParser* parser)
+{
+ return parser->TokenString.c_str();
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_StringAppend(cmDependsFortranParser* parser,
+ char c)
+{
+ parser->TokenString += c;
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_SetInInterface(cmDependsFortranParser* parser,
+ bool in)
+{
+ if(parser->InPPFalseBranch)
+ {
+ return;
+ }
+
+ parser->InInterface = in;
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsFortranParser_GetInInterface(cmDependsFortranParser* parser)
+{
+ return parser->InInterface;
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_SetOldStartcond(cmDependsFortranParser* parser,
+ int arg)
+{
+ parser->OldStartcond = arg;
+}
+
+//----------------------------------------------------------------------------
+int cmDependsFortranParser_GetOldStartcond(cmDependsFortranParser* parser)
+{
+ return parser->OldStartcond;
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_Error(cmDependsFortranParser*, const char*)
+{
+ // If there is a parser error just ignore it. The source will not
+ // compile and the user will edit it. Then dependencies will have
+ // to be regenerated anyway.
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleUse(cmDependsFortranParser* parser,
+ const char* name)
+{
+ if(!parser->InPPFalseBranch)
+ {
+ parser->Info.Requires.insert(cmSystemTools::LowerCase(name) );
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleInclude(cmDependsFortranParser* parser,
+ const char* name)
+{
+ if(parser->InPPFalseBranch)
+ {
+ return;
+ }
+
+ // If processing an include statement there must be an open file.
+ assert(!parser->FileStack.empty());
+
+ // Get the directory containing the source in which the include
+ // statement appears. This is always the first search location for
+ // Fortran include files.
+ std::string dir = parser->FileStack.top().Directory;
+
+ // Find the included file. If it cannot be found just ignore the
+ // problem because either the source will not compile or the user
+ // does not care about depending on this included source.
+ std::string fullName;
+ if(parser->Self->FindIncludeFile(dir.c_str(), name, fullName))
+ {
+ // Found the included file. Save it in the set of included files.
+ parser->Info.Includes.insert(fullName);
+
+ // Parse it immediately to translate the source inline.
+ cmDependsFortranParser_FilePush(parser, fullName.c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleModule(cmDependsFortranParser* parser,
+ const char* name)
+{
+ if(!parser->InPPFalseBranch && !parser->InInterface)
+ {
+ parser->Info.Provides.insert(cmSystemTools::LowerCase(name));
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleDefine(cmDependsFortranParser* parser,
+ const char* macro)
+{
+ if(!parser->InPPFalseBranch)
+ {
+ parser->PPDefinitions.insert(macro);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleUndef(cmDependsFortranParser* parser,
+ const char* macro)
+{
+ if(!parser->InPPFalseBranch)
+ {
+ std::set<std::string>::iterator match;
+ match = parser->PPDefinitions.find(macro);
+ if(match != parser->PPDefinitions.end())
+ {
+ parser->PPDefinitions.erase(match);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleIfdef(cmDependsFortranParser* parser,
+ const char* macro)
+{
+ // A new PP branch has been opened
+ parser->SkipToEnd.push(false);
+
+ if (parser->InPPFalseBranch)
+ {
+ parser->InPPFalseBranch++;
+ }
+ else if(parser->PPDefinitions.find(macro) == parser->PPDefinitions.end())
+ {
+ parser->InPPFalseBranch=1;
+ }
+ else
+ {
+ parser->SkipToEnd.top() = true;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleIfndef(cmDependsFortranParser* parser,
+ const char* macro)
+{
+ // A new PP branch has been opened
+ parser->SkipToEnd.push(false);
+
+ if (parser->InPPFalseBranch)
+ {
+ parser->InPPFalseBranch++;
+ }
+ else if(parser->PPDefinitions.find(macro) != parser->PPDefinitions.end())
+ {
+ parser->InPPFalseBranch = 1;
+ }
+ else
+ {
+ // ignore other branches
+ parser->SkipToEnd.top() = true;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleIf(cmDependsFortranParser* parser)
+{
+ /* Note: The current parser is _not_ able to get statements like
+ * #if 0
+ * #if 1
+ * #if MYSMBOL
+ * #if defined(MYSYMBOL)
+ * #if defined(MYSYMBOL) && ...
+ * right. The same for #elif. Thus in
+ * #if SYMBOL_1
+ * ..
+ * #elif SYMBOL_2
+ * ...
+ * ...
+ * #elif SYMBOL_N
+ * ..
+ * #else
+ * ..
+ * #endif
+ * _all_ N+1 branches are considered. If you got something like this
+ * #if defined(MYSYMBOL)
+ * #if !defined(MYSYMBOL)
+ * use
+ * #ifdef MYSYMBOL
+ * #ifndef MYSYMBOL
+ * instead.
+ */
+
+ // A new PP branch has been opened
+ // Never skip! See note above.
+ parser->SkipToEnd.push(false);
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleElif(cmDependsFortranParser* parser)
+{
+ /* Note: There are parser limitations. See the note at
+ * cmDependsFortranParser_RuleIf(..)
+ */
+
+ // Always taken unless an #ifdef or #ifndef-branch has been taken
+ // already. If the second condition isn't meet already
+ // (parser->InPPFalseBranch == 0) correct it.
+ if(!parser->SkipToEnd.empty() &&
+ parser->SkipToEnd.top() && !parser->InPPFalseBranch)
+ {
+ parser->InPPFalseBranch = 1;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleElse(cmDependsFortranParser* parser)
+{
+ // if the parent branch is false do nothing!
+ if(parser->InPPFalseBranch > 1)
+ {
+ return;
+ }
+
+ // parser->InPPFalseBranch is either 0 or 1. We change it depending on
+ // parser->SkipToEnd.top()
+ if(!parser->SkipToEnd.empty() &&
+ parser->SkipToEnd.top())
+ {
+ parser->InPPFalseBranch = 1;
+ }
+ else
+ {
+ parser->InPPFalseBranch = 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDependsFortranParser_RuleEndif(cmDependsFortranParser* parser)
+{
+ if(!parser->SkipToEnd.empty())
+ {
+ parser->SkipToEnd.pop();
+ }
+
+ // #endif doesn't know if there was a "#else" in before, so it
+ // always decreases InPPFalseBranch
+ if(parser->InPPFalseBranch)
+ {
+ parser->InPPFalseBranch--;
+ }
+}
diff --git a/Source/cmDependsFortran.h b/Source/cmDependsFortran.h
new file mode 100644
index 0000000000..cb40796c83
--- /dev/null
+++ b/Source/cmDependsFortran.h
@@ -0,0 +1,92 @@
+/*============================================================================
+ 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 cmDependsFortran_h
+#define cmDependsFortran_h
+
+#include "cmDepends.h"
+
+class cmDependsFortranInternals;
+class cmDependsFortranSourceInfo;
+
+/** \class cmDependsFortran
+ * \brief Dependency scanner for Fortran object files.
+ */
+class cmDependsFortran: public cmDepends
+{
+public:
+ /** Checking instances need to know the build directory name and the
+ relative path from the build directory to the target file. */
+ cmDependsFortran();
+
+ /** Scanning need to know the build directory name, the relative
+ path from the build directory to the target file, the source
+ file from which to start scanning, the include file search
+ path, and the target directory. */
+ cmDependsFortran(cmLocalGenerator* lg);
+
+ /** Virtual destructor to cleanup subclasses properly. */
+ virtual ~cmDependsFortran();
+
+ /** Callback from build system after a .mod file has been generated
+ by a Fortran90 compiler to copy the .mod file to the
+ corresponding stamp file. */
+ static bool CopyModule(const std::vector<std::string>& args);
+
+ /** Determine if a mod file and the corresponding mod.stamp file
+ are representing different module information. */
+ static bool ModulesDiffer(const char* modFile, const char* stampFile,
+ const char* compilerId);
+
+ /** Method to find an included file in the include path. Fortran
+ always searches the directory containing the including source
+ first. */
+ bool FindIncludeFile(const char* dir, const char* includeName,
+ std::string& fileName);
+
+protected:
+ // Finalize the dependency information for the target.
+ virtual bool Finalize(std::ostream& makeDepends,
+ std::ostream& internalDepends);
+
+ // Find all the modules required by the target.
+ void LocateModules();
+ void MatchLocalModules();
+ void MatchRemoteModules(std::istream& fin, const char* stampDir);
+ void ConsiderModule(const char* name, const char* stampDir);
+ bool FindModule(std::string const& name, std::string& module);
+
+ // Implement writing/checking methods required by superclass.
+ virtual bool WriteDependencies(
+ const std::set<std::string>& sources, const std::string& file,
+ std::ostream& makeDepends, std::ostream& internalDepends);
+
+ // Actually write the depenencies to the streams.
+ bool WriteDependenciesReal(const char *obj,
+ cmDependsFortranSourceInfo const& info,
+ const char* mod_dir, const char* stamp_dir,
+ std::ostream& makeDepends,
+ std::ostream& internalDepends);
+
+ // The source file from which to start scanning.
+ std::string SourceFile;
+
+ std::vector<std::string> PPDefinitions;
+
+ // Internal implementation details.
+ cmDependsFortranInternals* Internal;
+
+private:
+ cmDependsFortran(cmDependsFortran const&); // Purposely not implemented.
+ void operator=(cmDependsFortran const&); // Purposely not implemented.
+};
+
+#endif
diff --git a/Source/cmDependsFortranLexer.cxx b/Source/cmDependsFortranLexer.cxx
new file mode 100644
index 0000000000..1eff1e4b40
--- /dev/null
+++ b/Source/cmDependsFortranLexer.cxx
@@ -0,0 +1,2414 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#line 2 "cmDependsFortranLexer.cxx"
+
+#line 4 "cmDependsFortranLexer.cxx"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yyg->yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yyg->yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE cmDependsFortran_yyrestart(yyin ,yyscanner )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
+#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#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)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = yyg->yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#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
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int 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
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via cmDependsFortran_yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
+ ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
+
+void cmDependsFortran_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void cmDependsFortran_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsFortran_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
+void cmDependsFortran_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmDependsFortran_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmDependsFortran_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+void cmDependsFortran_yypop_buffer_state (yyscan_t yyscanner );
+
+static void cmDependsFortran_yyensure_buffer_stack (yyscan_t yyscanner );
+static void cmDependsFortran_yy_load_buffer_state (yyscan_t yyscanner );
+static void cmDependsFortran_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
+
+#define YY_FLUSH_BUFFER cmDependsFortran_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+
+YY_BUFFER_STATE cmDependsFortran_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsFortran_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsFortran_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+
+void *cmDependsFortran_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *cmDependsFortran_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void cmDependsFortran_yyfree (void * ,yyscan_t yyscanner );
+
+#define yy_new_buffer cmDependsFortran_yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ cmDependsFortran_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmDependsFortran_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ cmDependsFortran_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmDependsFortran_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+#define cmDependsFortran_yywrap(n) 1
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+typedef int yy_state_type;
+
+#define yytext_ptr yytext_r
+
+static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
+static int yy_get_next_buffer (yyscan_t yyscanner );
+static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yyg->yytext_ptr = yy_bp; \
+ yyleng = (size_t) (yy_cp - yy_bp); \
+ yyg->yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yyg->yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 44
+#define YY_END_OF_BUFFER 45
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[165] =
+ { 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,
+
+ 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
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 5, 6, 7, 8, 9, 1, 10, 11, 1,
+ 1, 12, 1, 13, 1, 1, 1, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 15, 16, 17,
+ 18, 19, 20, 1, 21, 21, 22, 23, 24, 25,
+ 21, 21, 26, 21, 21, 27, 21, 28, 21, 21,
+ 21, 21, 29, 21, 30, 21, 21, 21, 21, 21,
+ 1, 31, 1, 1, 32, 1, 21, 21, 33, 34,
+
+ 35, 36, 21, 21, 37, 21, 21, 38, 21, 39,
+ 21, 21, 21, 21, 40, 21, 41, 21, 21, 21,
+ 21, 21, 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, 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, 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, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[42] =
+ { 0,
+ 1, 2, 2, 3, 4, 3, 3, 1, 1, 3,
+ 3, 1, 3, 5, 1, 3, 1, 3, 6, 1,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 1, 5, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7
+ } ;
+
+static yyconst flex_int16_t yy_base[174] =
+ { 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
+ } ;
+
+static yyconst flex_int16_t yy_def[174] =
+ { 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
+ } ;
+
+static yyconst flex_int16_t yy_nxt[547] =
+ { 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
+ } ;
+
+static yyconst flex_int16_t yy_chk[547] =
+ { 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,
+ 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
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "cmDependsFortranLexer.in.l"
+#line 2 "cmDependsFortranLexer.in.l"
+/*============================================================================
+ 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.
+============================================================================*/
+/*-------------------------------------------------------------------------
+ Portions of this source have been derived from makedepf90 version 2.8.8,
+
+ Copyright (C) 2000--2006 Erik Edelmann <erik.edelmann@iki.fi>
+
+ The code was originally distributed under the GPL but permission
+ from the copyright holder has been obtained to distribute this
+ derived work under the CMake license.
+-------------------------------------------------------------------------*/
+
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex -i --prefix=cmDependsFortran_yy --header-file=cmDependsFortranLexer.h -ocmDependsFortranLexer.cxx cmDependsFortranLexer.in.l
+
+Modify cmDependsFortranLexer.cxx:
+ - remove TABs
+ - remove "yyscanner" argument from these methods:
+ yy_fatal_error, cmDependsFortran_yyalloc, cmDependsFortran_yyrealloc, cmDependsFortran_yyfree
+ - remove "yyscanner = NULL" from end of cmDependsFortran_yylex_destroy
+ - remove all YY_BREAK lines occurring right after return statements
+ - change while ( 1 ) to for(;;)
+
+Modify cmDependsFortranLexer.h:
+ - remove TABs
+ - remove the yy_init_globals function
+ - remove the block that includes unistd.h
+ - remove #line directives (avoids bogus warning on old Sun)
+
+*/
+
+#include "cmStandardLexer.h"
+
+#define cmDependsFortranLexer_cxx
+#include "cmDependsFortranParser.h" /* Interface to parser object. */
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = cmDependsFortranParser_Input(yyextra, buf, max_size); }
+
+/* Include the set of tokens from the parser. */
+#include "cmDependsFortranParserTokens.h"
+
+/*--------------------------------------------------------------------------*/
+
+
+#line 678 "cmDependsFortranLexer.cxx"
+
+#define INITIAL 0
+#define free_fmt 1
+#define fixed_fmt 2
+#define str_sq 3
+#define str_dq 4
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* Holds the entire state of the reentrant scanner. */
+struct yyguts_t
+ {
+
+ /* User-defined. Not touched by flex. */
+ YY_EXTRA_TYPE yyextra_r;
+
+ /* The rest are the same as the globals declared in the non-reentrant scanner. */
+ FILE *yyin_r, *yyout_r;
+ size_t yy_buffer_stack_top; /**< index of top of stack. */
+ 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;
+ char *yy_c_buf_p;
+ int yy_init;
+ int yy_start;
+ int yy_did_buffer_switch_on_eof;
+ int yy_start_stack_ptr;
+ int yy_start_stack_depth;
+ int *yy_start_stack;
+ yy_state_type yy_last_accepting_state;
+ char* yy_last_accepting_cpos;
+
+ int yylineno_r;
+ int yy_flex_debug_r;
+
+ char *yytext_r;
+ int yy_more_flag;
+ int yy_more_len;
+
+ }; /* end struct yyguts_t */
+
+static int yy_init_globals (yyscan_t yyscanner );
+
+int cmDependsFortran_yylex_init (yyscan_t* scanner);
+
+int cmDependsFortran_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int cmDependsFortran_yylex_destroy (yyscan_t yyscanner );
+
+int cmDependsFortran_yyget_debug (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE cmDependsFortran_yyget_extra (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *cmDependsFortran_yyget_in (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *cmDependsFortran_yyget_out (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+int cmDependsFortran_yyget_leng (yyscan_t yyscanner );
+
+char *cmDependsFortran_yyget_text (yyscan_t yyscanner );
+
+int cmDependsFortran_yyget_lineno (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int cmDependsFortran_yywrap (yyscan_t yyscanner );
+#else
+extern int cmDependsFortran_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+ static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner);
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#ifdef __cplusplus
+static int yyinput (yyscan_t yyscanner );
+#else
+static int input (yyscan_t yyscanner );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
+#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int cmDependsFortran_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int cmDependsFortran_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ if ( yyleng > 0 ) \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \
+ (yytext[yyleng - 1] == '\n'); \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ yy_state_type yy_current_state;
+ char *yy_cp, *yy_bp;
+ int yy_act;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+#line 71 "cmDependsFortranLexer.in.l"
+
+
+#line 914 "cmDependsFortranLexer.cxx"
+
+ if ( !yyg->yy_init )
+ {
+ yyg->yy_init = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! yyg->yy_start )
+ yyg->yy_start = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ cmDependsFortran_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmDependsFortran_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmDependsFortran_yy_load_buffer_state(yyscanner );
+ }
+
+ for(;;) /* loops until end-of-file is reached */
+ {
+ yy_cp = yyg->yy_c_buf_p;
+
+ /* Support of yytext. */
+ *yy_cp = yyg->yy_hold_char;
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yyg->yy_start;
+ yy_current_state += YY_AT_BOL();
+yy_match:
+ do
+ {
+ 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;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 )
+ 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 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = yyg->yy_hold_char;
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 73 "cmDependsFortranLexer.in.l"
+{
+ cmDependsFortranParser_StringStart(yyextra);
+ cmDependsFortranParser_SetOldStartcond(yyextra, YY_START);
+ BEGIN(str_dq);
+}
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 79 "cmDependsFortranLexer.in.l"
+{
+ cmDependsFortranParser_StringStart(yyextra);
+ cmDependsFortranParser_SetOldStartcond(yyextra, YY_START);
+ BEGIN(str_sq);
+}
+ YY_BREAK
+case 3:
+#line 86 "cmDependsFortranLexer.in.l"
+case 4:
+YY_RULE_SETUP
+#line 86 "cmDependsFortranLexer.in.l"
+{
+ BEGIN(cmDependsFortranParser_GetOldStartcond(yyextra) );
+ yylvalp->string = strdup(cmDependsFortranParser_StringEnd(yyextra));
+ return STRING;
+}
+case 5:
+/* rule 5 can match eol */
+#line 93 "cmDependsFortranLexer.in.l"
+case 6:
+/* rule 6 can match eol */
+YY_RULE_SETUP
+#line 93 "cmDependsFortranLexer.in.l"
+/* Ignore (continued strings, free fmt) */
+ YY_BREAK
+case 7:
+/* rule 7 can match eol */
+YY_RULE_SETUP
+#line 95 "cmDependsFortranLexer.in.l"
+{
+ if (cmDependsFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
+ ; /* Ignore (cont. strings, fixed fmt) */
+ else
+ {
+ unput(yytext[strlen(yytext)-1]);
+ }
+}
+ YY_BREAK
+case 8:
+/* rule 8 can match eol */
+YY_RULE_SETUP
+#line 105 "cmDependsFortranLexer.in.l"
+{
+ unput ('\n');
+ BEGIN(INITIAL);
+ return UNTERMINATED_STRING;
+}
+case 9:
+YY_RULE_SETUP
+#line 111 "cmDependsFortranLexer.in.l"
+{
+ cmDependsFortranParser_StringAppend(yyextra, yytext[0]);
+}
+ YY_BREAK
+case 10:
+/* rule 10 can match eol */
+YY_RULE_SETUP
+#line 115 "cmDependsFortranLexer.in.l"
+{ return EOSTMT; } /* Treat comments like */
+case 11:
+/* rule 11 can match eol */
+YY_RULE_SETUP
+#line 116 "cmDependsFortranLexer.in.l"
+{ return EOSTMT; } /* empty lines */
+case 12:
+/* rule 12 can match eol */
+YY_RULE_SETUP
+#line 118 "cmDependsFortranLexer.in.l"
+{
+ yytext[yyleng-1] = 0;
+ yylvalp->string = strdup(strchr(yytext, '<')+1);
+ return CPP_INCLUDE_ANGLE;
+}
+case 13:
+YY_RULE_SETUP
+#line 123 "cmDependsFortranLexer.in.l"
+{ return CPP_INCLUDE; }
+case 14:
+YY_RULE_SETUP
+#line 124 "cmDependsFortranLexer.in.l"
+{ return F90PPR_INCLUDE; }
+case 15:
+YY_RULE_SETUP
+#line 125 "cmDependsFortranLexer.in.l"
+{ return COCO_INCLUDE; }
+case 16:
+YY_RULE_SETUP
+#line 127 "cmDependsFortranLexer.in.l"
+{ return CPP_DEFINE; }
+case 17:
+YY_RULE_SETUP
+#line 128 "cmDependsFortranLexer.in.l"
+{ return F90PPR_DEFINE; }
+case 18:
+YY_RULE_SETUP
+#line 130 "cmDependsFortranLexer.in.l"
+{ return CPP_UNDEF; }
+case 19:
+YY_RULE_SETUP
+#line 131 "cmDependsFortranLexer.in.l"
+{ return F90PPR_UNDEF; }
+case 20:
+YY_RULE_SETUP
+#line 133 "cmDependsFortranLexer.in.l"
+{ return CPP_IFDEF; }
+case 21:
+YY_RULE_SETUP
+#line 134 "cmDependsFortranLexer.in.l"
+{ return CPP_IFNDEF; }
+case 22:
+YY_RULE_SETUP
+#line 135 "cmDependsFortranLexer.in.l"
+{ return CPP_IF; }
+case 23:
+YY_RULE_SETUP
+#line 136 "cmDependsFortranLexer.in.l"
+{ return CPP_ELIF; }
+case 24:
+YY_RULE_SETUP
+#line 137 "cmDependsFortranLexer.in.l"
+{ return CPP_ELSE; }
+case 25:
+YY_RULE_SETUP
+#line 138 "cmDependsFortranLexer.in.l"
+{ return CPP_ENDIF; }
+case 26:
+YY_RULE_SETUP
+#line 140 "cmDependsFortranLexer.in.l"
+{ return F90PPR_IFDEF; }
+case 27:
+YY_RULE_SETUP
+#line 141 "cmDependsFortranLexer.in.l"
+{ return F90PPR_IFNDEF; }
+case 28:
+YY_RULE_SETUP
+#line 142 "cmDependsFortranLexer.in.l"
+{ return F90PPR_IF; }
+case 29:
+YY_RULE_SETUP
+#line 143 "cmDependsFortranLexer.in.l"
+{ return F90PPR_ELIF; }
+case 30:
+YY_RULE_SETUP
+#line 144 "cmDependsFortranLexer.in.l"
+{ return F90PPR_ELSE; }
+case 31:
+YY_RULE_SETUP
+#line 145 "cmDependsFortranLexer.in.l"
+{ return F90PPR_ENDIF; }
+/* Line continuations, possible involving comments. */
+case 32:
+/* rule 32 can match eol */
+YY_RULE_SETUP
+#line 148 "cmDependsFortranLexer.in.l"
+
+ YY_BREAK
+case 33:
+/* rule 33 can match eol */
+YY_RULE_SETUP
+#line 149 "cmDependsFortranLexer.in.l"
+
+ YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 151 "cmDependsFortranLexer.in.l"
+{ return COMMA; }
+case 35:
+YY_RULE_SETUP
+#line 153 "cmDependsFortranLexer.in.l"
+{ return DCOLON; }
+case 36:
+/* rule 36 can match eol */
+YY_RULE_SETUP
+#line 155 "cmDependsFortranLexer.in.l"
+{ return GARBAGE; }
+case 37:
+YY_RULE_SETUP
+#line 157 "cmDependsFortranLexer.in.l"
+{ return ASSIGNMENT_OP; }
+case 38:
+YY_RULE_SETUP
+#line 159 "cmDependsFortranLexer.in.l"
+{
+ yylvalp->string = strdup(yytext);
+ return WORD;
+}
+case 39:
+YY_RULE_SETUP
+#line 164 "cmDependsFortranLexer.in.l"
+{ return GARBAGE; }
+case 40:
+/* rule 40 can match eol */
+YY_RULE_SETUP
+#line 166 "cmDependsFortranLexer.in.l"
+{ return EOSTMT; }
+case 41:
+YY_RULE_SETUP
+#line 169 "cmDependsFortranLexer.in.l"
+/* Ignore */
+ YY_BREAK
+case 42:
+/* rule 42 can match eol */
+YY_RULE_SETUP
+#line 170 "cmDependsFortranLexer.in.l"
+/* Ignore line-endings preceeded by \ */
+ YY_BREAK
+case 43:
+YY_RULE_SETUP
+#line 172 "cmDependsFortranLexer.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 "cmDependsFortranLexer.in.l"
+{
+ if(!cmDependsFortranParser_FilePop(yyextra) )
+ {
+ return YY_NULL;
+ }
+}
+ YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 181 "cmDependsFortranLexer.in.l"
+ECHO;
+ YY_BREAK
+#line 1270 "cmDependsFortranLexer.cxx"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = yyg->yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * cmDependsFortran_yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
+
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++yyg->yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yyg->yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yyg->yy_did_buffer_switch_on_eof = 0;
+
+ if ( cmDependsFortran_yywrap(yyscanner ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p =
+ yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yyg->yy_c_buf_p =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of cmDependsFortran_yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ char *source = yyg->yytext_ptr;
+ int number_to_move, i;
+ int ret_val;
+
+ if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
+
+ else
+ {
+ int 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;
+
+ 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;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ cmDependsFortran_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* 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 );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ if ( yyg->yy_n_chars == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ cmDependsFortran_yyrestart(yyin ,yyscanner);
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cmDependsFortran_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ yyg->yy_n_chars += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
+{
+ yy_state_type yy_current_state;
+ char *yy_cp;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ yy_current_state = yyg->yy_start;
+ yy_current_state += YY_AT_BOL();
+
+ for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
+ {
+ YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
+{
+ int yy_is_jam;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
+ char *yy_cp = yyg->yy_c_buf_p;
+
+ YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 )
+ 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);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+ static void yyunput (int c, char * yy_bp , yyscan_t yyscanner)
+{
+ char *yy_cp;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ yy_cp = yyg->yy_c_buf_p;
+
+ /* undo effects of setting up yytext */
+ *yy_cp = yyg->yy_hold_char;
+
+ 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;
+ char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
+ char *source =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
+
+ while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );
+ }
+
+ *--yy_cp = (char) c;
+
+ yyg->yytext_ptr = yy_bp;
+ yyg->yy_hold_char = *yy_cp;
+ yyg->yy_c_buf_p = yy_cp;
+}
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (yyscan_t yyscanner)
+#else
+ static int input (yyscan_t yyscanner)
+#endif
+
+{
+ int c;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+
+ if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ /* This was really a NUL. */
+ *yyg->yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ ++yyg->yy_c_buf_p;
+
+ switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ cmDependsFortran_yyrestart(yyin ,yyscanner);
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( cmDependsFortran_yywrap(yyscanner ) )
+ return EOF;
+
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput(yyscanner);
+#else
+ return input(yyscanner);
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
+ *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
+ yyg->yy_hold_char = *++yyg->yy_c_buf_p;
+
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n');
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ * @param yyscanner The scanner object.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void cmDependsFortran_yyrestart (FILE * input_file , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! YY_CURRENT_BUFFER ){
+ cmDependsFortran_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmDependsFortran_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmDependsFortran_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
+ cmDependsFortran_yy_load_buffer_state(yyscanner );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ * @param yyscanner The scanner object.
+ */
+ void cmDependsFortran_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * cmDependsFortran_yypop_buffer_state();
+ * cmDependsFortran_yypush_buffer_state(new_buffer);
+ */
+ cmDependsFortran_yyensure_buffer_stack (yyscanner);
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ cmDependsFortran_yy_load_buffer_state(yyscanner );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (cmDependsFortran_yywrap()) processing, but the only time this flag
+ * is looked at is after cmDependsFortran_yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+static void cmDependsFortran_yy_load_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ yyg->yy_hold_char = *yyg->yy_c_buf_p;
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * @param yyscanner The scanner object.
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE cmDependsFortran_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) cmDependsFortran_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsFortran_yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) cmDependsFortran_yyalloc(b->yy_buf_size + 2 ,yyscanner );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsFortran_yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ cmDependsFortran_yy_init_buffer(b,file ,yyscanner);
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with cmDependsFortran_yy_create_buffer()
+ * @param yyscanner The scanner object.
+ */
+ void cmDependsFortran_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ cmDependsFortran_yyfree((void *) b->yy_ch_buf ,yyscanner );
+
+ cmDependsFortran_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 cmDependsFortran_yyrestart() or at EOF.
+ */
+ static void cmDependsFortran_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+
+{
+ int oerrno = errno;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ cmDependsFortran_yy_flush_buffer(b ,yyscanner);
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then cmDependsFortran_yy_init_buffer was _probably_
+ * called from cmDependsFortran_yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ * @param yyscanner The scanner object.
+ */
+ void cmDependsFortran_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ cmDependsFortran_yy_load_buffer_state(yyscanner );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsFortran_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (new_buffer == NULL)
+ return;
+
+ cmDependsFortran_yyensure_buffer_stack(yyscanner);
+
+ /* This block is copied from cmDependsFortran_yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ yyg->yy_buffer_stack_top++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from cmDependsFortran_yy_switch_to_buffer. */
+ cmDependsFortran_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsFortran_yypop_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ cmDependsFortran_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if (yyg->yy_buffer_stack_top > 0)
+ --yyg->yy_buffer_stack_top;
+
+ if (YY_CURRENT_BUFFER) {
+ cmDependsFortran_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void cmDependsFortran_yyensure_buffer_stack (yyscan_t yyscanner)
+{
+ int num_to_alloc;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (!yyg->yy_buffer_stack) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmDependsFortran_yyalloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+ if ( ! yyg->yy_buffer_stack )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsFortran_yyensure_buffer_stack()" );
+
+ memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ yyg->yy_buffer_stack_max = num_to_alloc;
+ yyg->yy_buffer_stack_top = 0;
+ return;
+ }
+
+ if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmDependsFortran_yyrealloc
+ (yyg->yy_buffer_stack,
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+ if ( ! yyg->yy_buffer_stack )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsFortran_yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
+ yyg->yy_buffer_stack_max = num_to_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmDependsFortran_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) cmDependsFortran_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsFortran_yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ cmDependsFortran_yy_switch_to_buffer(b ,yyscanner );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to cmDependsFortran_yylex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * cmDependsFortran_yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE cmDependsFortran_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+{
+
+ return cmDependsFortran_yy_scan_bytes(yystr,strlen(yystr) ,yyscanner);
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to cmDependsFortran_yylex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmDependsFortran_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) cmDependsFortran_yyalloc(n ,yyscanner );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsFortran_yy_scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = cmDependsFortran_yy_scan_buffer(buf,n ,yyscanner);
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in cmDependsFortran_yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yy_fatal_error (yyconst char* msg , yyscan_t)
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = yyg->yy_hold_char; \
+ yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
+ yyg->yy_hold_char = *yyg->yy_c_buf_p; \
+ *yyg->yy_c_buf_p = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the user-defined data for this scanner.
+ * @param yyscanner The scanner object.
+ */
+YY_EXTRA_TYPE cmDependsFortran_yyget_extra (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyextra;
+}
+
+/** Get the current line number.
+ * @param yyscanner The scanner object.
+ */
+int cmDependsFortran_yyget_lineno (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yylineno;
+}
+
+/** Get the current column number.
+ * @param yyscanner The scanner object.
+ */
+int cmDependsFortran_yyget_column (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yycolumn;
+}
+
+/** Get the input stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmDependsFortran_yyget_in (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyin;
+}
+
+/** Get the output stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmDependsFortran_yyget_out (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyout;
+}
+
+/** Get the length of the current token.
+ * @param yyscanner The scanner object.
+ */
+int cmDependsFortran_yyget_leng (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyleng;
+}
+
+/** Get the current token.
+ * @param yyscanner The scanner object.
+ */
+
+char *cmDependsFortran_yyget_text (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yytext;
+}
+
+/** Set the user-defined data. This data is never touched by the scanner.
+ * @param user_defined The data to be associated with this scanner.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsFortran_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyextra = user_defined ;
+}
+
+/** Set the current line number.
+ * @param line_number The line number to set.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsFortran_yyset_lineno (int line_number , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* lineno is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmDependsFortran_yyset_lineno called with no buffer" , yyscanner);
+
+ yylineno = line_number;
+}
+
+/** Set the current column.
+ * @param column_no The column number to set.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsFortran_yyset_column (int column_no , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* column is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmDependsFortran_yyset_column called with no buffer" , yyscanner);
+
+ yycolumn = column_no;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ * @param yyscanner The scanner object.
+ * @see cmDependsFortran_yy_switch_to_buffer
+ */
+void cmDependsFortran_yyset_in (FILE * in_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyin = in_str ;
+}
+
+void cmDependsFortran_yyset_out (FILE * out_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyout = out_str ;
+}
+
+int cmDependsFortran_yyget_debug (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yy_flex_debug;
+}
+
+void cmDependsFortran_yyset_debug (int bdebug , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yy_flex_debug = bdebug ;
+}
+
+/* Accessor methods for yylval and yylloc */
+
+/* User-visible API */
+
+/* cmDependsFortran_yylex_init is special because it creates the scanner itself, so it is
+ * the ONLY reentrant function that doesn't take the scanner as the last argument.
+ * That's why we explicitly handle the declaration, instead of using our macros.
+ */
+
+int cmDependsFortran_yylex_init(yyscan_t* ptr_yy_globals)
+
+{
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) cmDependsFortran_yyalloc ( sizeof( struct yyguts_t ), NULL );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
+ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+/* cmDependsFortran_yylex_init_extra has the same functionality as cmDependsFortran_yylex_init, but follows the
+ * convention of taking the scanner as the last argument. Note however, that
+ * this is a *pointer* to a scanner, as it will be allocated by this call (and
+ * is the reason, too, why this function also must handle its own declaration).
+ * The user defined value in the first argument will be available to cmDependsFortran_yyalloc in
+ * the yyextra field.
+ */
+
+int cmDependsFortran_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
+
+{
+ struct yyguts_t dummy_yyguts;
+
+ cmDependsFortran_yyset_extra (yy_user_defined, &dummy_yyguts);
+
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) cmDependsFortran_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ /* By setting to 0xAA, we expose bugs in
+ yy_init_globals. Leave at 0x00 for releases. */
+ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+ cmDependsFortran_yyset_extra (yy_user_defined, *ptr_yy_globals);
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+static int yy_init_globals (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from cmDependsFortran_yylex_destroy(), so don't allocate here.
+ */
+
+ yyg->yy_buffer_stack = 0;
+ yyg->yy_buffer_stack_top = 0;
+ yyg->yy_buffer_stack_max = 0;
+ yyg->yy_c_buf_p = (char *) 0;
+ yyg->yy_init = 0;
+ yyg->yy_start = 0;
+
+ yyg->yy_start_stack_ptr = 0;
+ yyg->yy_start_stack_depth = 0;
+ yyg->yy_start_stack = NULL;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ yyin = stdin;
+ yyout = stdout;
+#else
+ yyin = (FILE *) 0;
+ yyout = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * cmDependsFortran_yylex_init()
+ */
+ return 0;
+}
+
+/* cmDependsFortran_yylex_destroy is for both reentrant and non-reentrant scanners. */
+int cmDependsFortran_yylex_destroy (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ cmDependsFortran_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ cmDependsFortran_yypop_buffer_state(yyscanner);
+ }
+
+ /* Destroy the stack itself. */
+ cmDependsFortran_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyg->yy_buffer_stack = NULL;
+
+ /* Destroy the start condition stack. */
+ cmDependsFortran_yyfree(yyg->yy_start_stack ,yyscanner );
+ yyg->yy_start_stack = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * cmDependsFortran_yylex() is called, initialization will occur. */
+ yy_init_globals( yyscanner);
+
+ /* Destroy the main struct (reentrant only). */
+ cmDependsFortran_yyfree ( yyscanner , yyscanner );
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+{
+ int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+{
+ int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *cmDependsFortran_yyalloc (yy_size_t size , yyscan_t)
+{
+ return (void *) malloc( size );
+}
+
+void *cmDependsFortran_yyrealloc (void * ptr, yy_size_t size , yyscan_t)
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void cmDependsFortran_yyfree (void * ptr , yyscan_t)
+{
+ free( (char *) ptr ); /* see cmDependsFortran_yyrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 181 "cmDependsFortranLexer.in.l"
+
+
+
+/*--------------------------------------------------------------------------*/
+YY_BUFFER_STATE cmDependsFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
+{
+ /* Hack into the internal flex-generated scanner to get the buffer. */
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return YY_CURRENT_BUFFER;
+}
+
diff --git a/Source/cmDependsFortranLexer.h b/Source/cmDependsFortranLexer.h
new file mode 100644
index 0000000000..8e24cfd801
--- /dev/null
+++ b/Source/cmDependsFortranLexer.h
@@ -0,0 +1,348 @@
+/*============================================================================
+ 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 cmDependsFortran_yyHEADER_H
+#define cmDependsFortran_yyHEADER_H 1
+#define cmDependsFortran_yyIN_HEADER 1
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
+#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
+#endif
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+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
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int 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
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+void cmDependsFortran_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void cmDependsFortran_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsFortran_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
+void cmDependsFortran_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmDependsFortran_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmDependsFortran_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+void cmDependsFortran_yypop_buffer_state (yyscan_t yyscanner );
+
+YY_BUFFER_STATE cmDependsFortran_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsFortran_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsFortran_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+
+void *cmDependsFortran_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *cmDependsFortran_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void cmDependsFortran_yyfree (void * ,yyscan_t yyscanner );
+
+/* Begin user sect3 */
+
+#define cmDependsFortran_yywrap(n) 1
+#define YY_SKIP_YYWRAP
+
+#define yytext_ptr yytext_r
+
+#ifdef YY_HEADER_EXPORT_START_CONDITIONS
+#define INITIAL 0
+#define free_fmt 1
+#define fixed_fmt 2
+#define str_sq 3
+#define str_dq 4
+
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+int cmDependsFortran_yylex_init (yyscan_t* scanner);
+
+int cmDependsFortran_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int cmDependsFortran_yylex_destroy (yyscan_t yyscanner );
+
+int cmDependsFortran_yyget_debug (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE cmDependsFortran_yyget_extra (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *cmDependsFortran_yyget_in (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *cmDependsFortran_yyget_out (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+int cmDependsFortran_yyget_leng (yyscan_t yyscanner );
+
+char *cmDependsFortran_yyget_text (yyscan_t yyscanner );
+
+int cmDependsFortran_yyget_lineno (yyscan_t yyscanner );
+
+void cmDependsFortran_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int cmDependsFortran_yywrap (yyscan_t yyscanner );
+#else
+extern int cmDependsFortran_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
+#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int cmDependsFortran_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int cmDependsFortran_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+#undef YY_NEW_FILE
+#undef YY_FLUSH_BUFFER
+#undef yy_set_bol
+#undef yy_new_buffer
+#undef yy_set_interactive
+#undef YY_DO_BEFORE_ACTION
+
+#ifdef YY_DECL_IS_OURS
+#undef YY_DECL_IS_OURS
+#undef YY_DECL
+#endif
+
+#undef cmDependsFortran_yyIN_HEADER
+#endif /* cmDependsFortran_yyHEADER_H */
diff --git a/Source/cmDependsFortranLexer.in.l b/Source/cmDependsFortranLexer.in.l
new file mode 100644
index 0000000000..01488024e8
--- /dev/null
+++ b/Source/cmDependsFortranLexer.in.l
@@ -0,0 +1,190 @@
+%{
+/*============================================================================
+ 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.
+============================================================================*/
+/*-------------------------------------------------------------------------
+ Portions of this source have been derived from makedepf90 version 2.8.8,
+
+ Copyright (C) 2000--2006 Erik Edelmann <erik.edelmann@iki.fi>
+
+ The code was originally distributed under the GPL but permission
+ from the copyright holder has been obtained to distribute this
+ derived work under the CMake license.
+-------------------------------------------------------------------------*/
+
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex -i --prefix=cmDependsFortran_yy --header-file=cmDependsFortranLexer.h -ocmDependsFortranLexer.cxx cmDependsFortranLexer.in.l
+
+Modify cmDependsFortranLexer.cxx:
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - remove "yyscanner" argument from these methods:
+ yy_fatal_error, cmDependsFortran_yyalloc, cmDependsFortran_yyrealloc, cmDependsFortran_yyfree
+ - remove "yyscanner = NULL" from end of cmDependsFortran_yylex_destroy
+ - remove all YY_BREAK lines occurring right after return statements
+ - change while ( 1 ) to for(;;)
+
+Modify cmDependsFortranLexer.h:
+ - remove TABs
+ - remove the yy_init_globals function
+ - remove the block that includes unistd.h
+ - remove #line directives (avoids bogus warning on old Sun)
+
+*/
+
+#include "cmStandardLexer.h"
+
+#define cmDependsFortranLexer_cxx
+#include "cmDependsFortranParser.h" /* Interface to parser object. */
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = cmDependsFortranParser_Input(yyextra, buf, max_size); }
+
+/* Include the set of tokens from the parser. */
+#include "cmDependsFortranParserTokens.h"
+
+/*--------------------------------------------------------------------------*/
+%}
+
+
+%option reentrant
+%option noyywrap
+%pointer
+
+%s free_fmt fixed_fmt
+%x str_sq str_dq
+
+%%
+
+\" {
+ cmDependsFortranParser_StringStart(yyextra);
+ cmDependsFortranParser_SetOldStartcond(yyextra, YY_START);
+ BEGIN(str_dq);
+}
+
+' {
+ cmDependsFortranParser_StringStart(yyextra);
+ cmDependsFortranParser_SetOldStartcond(yyextra, YY_START);
+ BEGIN(str_sq);
+}
+
+<str_dq>\" |
+<str_sq>' {
+ BEGIN(cmDependsFortranParser_GetOldStartcond(yyextra) );
+ yylvalp->string = strdup(cmDependsFortranParser_StringEnd(yyextra));
+ return STRING;
+}
+
+<str_dq,str_sq>&[ \t]*\n |
+<str_dq,str_sq>&[ \t]*\n[ \t]*& /* Ignore (continued strings, free fmt) */
+
+<fixed_fmt,str_dq,str_sq>\n[ ]{5}[^ \t\n] {
+ if (cmDependsFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
+ ; /* Ignore (cont. strings, fixed fmt) */
+ else
+ {
+ unput(yytext[strlen(yytext)-1]);
+ }
+}
+
+
+<str_dq,str_sq>\n {
+ unput ('\n');
+ BEGIN(INITIAL);
+ return UNTERMINATED_STRING;
+}
+
+<str_sq,str_dq>. {
+ cmDependsFortranParser_StringAppend(yyextra, yytext[0]);
+}
+
+!.*\n { return EOSTMT; } /* Treat comments like */
+<fixed_fmt>^[cC*dD].*\n { return EOSTMT; } /* empty lines */
+
+^[ \t]*#[ \t]*include[ \t]*<[^>]+> {
+ yytext[yyleng-1] = 0;
+ yylvalp->string = strdup(strchr(yytext, '<')+1);
+ return CPP_INCLUDE_ANGLE;
+}
+^[ \t]*#[ \t]*include { return CPP_INCLUDE; }
+\$[ \t]*include { return F90PPR_INCLUDE; }
+\?\?[ \t]*include { return COCO_INCLUDE; }
+
+^[ \t]*#[ \t]*define { return CPP_DEFINE; }
+\$[ \t]*DEFINE { return F90PPR_DEFINE; }
+
+^[ \t]*#[ \t]*undef { return CPP_UNDEF; }
+\$[ \t]*UNDEF { return F90PPR_UNDEF; }
+
+^[ \t]*#[ \t]*ifdef { return CPP_IFDEF; }
+^[ \t]*#[ \t]*ifndef { return CPP_IFNDEF; }
+^[ \t]*#[ \t]*if { return CPP_IF; }
+^[ \t]*#[ \t]*elif { return CPP_ELIF; }
+^[ \t]*#[ \t]*else { return CPP_ELSE; }
+^[ \t]*#[ \t]*endif { return CPP_ENDIF; }
+
+$[ \t]*ifdef { return F90PPR_IFDEF; }
+$[ \t]*ifndef { return F90PPR_IFNDEF; }
+$[ \t]*if { return F90PPR_IF; }
+$[ \t]*elif { return F90PPR_ELIF; }
+$[ \t]*else { return F90PPR_ELSE; }
+$[ \t]*endif { return F90PPR_ENDIF; }
+
+ /* Line continuations, possible involving comments. */
+&([ \t\n]*|!.*)*
+&([ \t\n]*|!.*)*&
+
+, { return COMMA; }
+
+:: { return DCOLON; }
+
+<fixed_fmt>\n[ ]{5}[^ ] { return GARBAGE; }
+
+=|=> { return ASSIGNMENT_OP; }
+
+[a-zA-Z_][a-zA-Z_0-9]* {
+ yylvalp->string = strdup(yytext);
+ return WORD;
+}
+
+[^ \t\n\r;,!'"a-zA-Z=&]+ { return GARBAGE; }
+
+;|\n { return EOSTMT; }
+
+
+[ \t\r,] /* Ignore */
+\\[ \t]*\n /* Ignore line-endings preceeded by \ */
+
+. { return *yytext; }
+
+<<EOF>> {
+ if(!cmDependsFortranParser_FilePop(yyextra) )
+ {
+ return YY_NULL;
+ }
+}
+
+%%
+
+/*--------------------------------------------------------------------------*/
+YY_BUFFER_STATE cmDependsFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
+{
+ /* Hack into the internal flex-generated scanner to get the buffer. */
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return YY_CURRENT_BUFFER;
+}
diff --git a/Source/cmDependsFortranParser.cxx b/Source/cmDependsFortranParser.cxx
new file mode 100644
index 0000000000..7b49a9c5c0
--- /dev/null
+++ b/Source/cmDependsFortranParser.cxx
@@ -0,0 +1,2094 @@
+/* A Bison parser, made by GNU Bison 2.5. */
+
+/* Bison implementation for Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "2.5"
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 1
+
+/* Push parsers. */
+#define YYPUSH 0
+
+/* Pull parsers. */
+#define YYPULL 1
+
+/* Using locations. */
+#define YYLSP_NEEDED 0
+
+/* Substitute the variable and function names. */
+#define yyparse cmDependsFortran_yyparse
+#define yylex cmDependsFortran_yylex
+#define yyerror cmDependsFortran_yyerror
+#define yylval cmDependsFortran_yylval
+#define yychar cmDependsFortran_yychar
+#define yydebug cmDependsFortran_yydebug
+#define yynerrs cmDependsFortran_yynerrs
+
+
+/* Copy the first part of user declarations. */
+
+/* Line 268 of yacc.c */
+#line 1 "cmDependsFortranParser.y"
+
+/*============================================================================
+ 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.
+============================================================================*/
+/*-------------------------------------------------------------------------
+ Portions of this source have been derived from makedepf90 version 2.8.8,
+
+ Copyright (C) 2000--2006 Erik Edelmann <erik.edelmann@iki.fi>
+
+ The code was originally distributed under the GPL but permission
+ from the copyright holder has been obtained to distribute this
+ derived work under the CMake license.
+-------------------------------------------------------------------------*/
+
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run bison like this:
+
+ bison --yacc --name-prefix=cmDependsFortran_yy
+ --defines=cmDependsFortranParserTokens.h
+ -ocmDependsFortranParser.cxx
+ cmDependsFortranParser.y
+
+Modify cmDependsFortranParser.cxx:
+ - remove TABs
+ - Remove the yyerrorlab block in range ["goto yyerrlab1", "yyerrlab1:"]
+*/
+
+/*-------------------------------------------------------------------------*/
+#define cmDependsFortranParser_cxx
+#include "cmDependsFortranParser.h" /* Interface to parser object. */
+#include "cmDependsFortranParserTokens.h" /* Need YYSTYPE for YY_DECL. */
+
+#include <cmsys/String.h>
+
+/* Configure the parser to use a lexer object. */
+#define YYPARSE_PARAM yyscanner
+#define YYLEX_PARAM yyscanner
+#define YYERROR_VERBOSE 1
+#define cmDependsFortran_yyerror(x) \
+ cmDependsFortranError(yyscanner, x)
+
+/* Forward declare the lexer entry point. */
+YY_DECL;
+
+/* Helper function to forward error callback. */
+static void cmDependsFortranError(yyscan_t yyscanner, const char* message)
+{
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_Error(parser, message);
+}
+
+static bool cmDependsFortranParserIsKeyword(const char* word,
+ const char* keyword)
+{
+ return cmsysString_strcasecmp(word, keyword) == 0;
+}
+
+/* Disable some warnings in the generated code. */
+#ifdef __BORLANDC__
+# pragma warn -8004 /* Variable assigned a value that is not used. */
+# pragma warn -8008 /* condition always returns true */
+# pragma warn -8060 /* possibly incorrect assignment */
+# pragma warn -8066 /* unreachable code */
+#endif
+#ifdef _MSC_VER
+# pragma warning (disable: 4102) /* Unused goto label. */
+# pragma warning (disable: 4065) /* Switch contains default but no case. */
+# pragma warning (disable: 4701) /* Local variable may not be initialized. */
+# pragma warning (disable: 4702) /* Unreachable code. */
+# pragma warning (disable: 4127) /* Conditional expression is constant. */
+# pragma warning (disable: 4244) /* Conversion to smaller type, data loss. */
+#endif
+
+
+/* Line 268 of yacc.c */
+#line 165 "cmDependsFortranParser.cxx"
+
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+/* Enabling the token table. */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE 0
+#endif
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ 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
+ };
+#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
+
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+{
+
+/* Line 293 of yacc.c */
+#line 89 "cmDependsFortranParser.y"
+
+ char* string;
+
+
+
+/* Line 293 of yacc.c */
+#line 269 "cmDependsFortranParser.cxx"
+} YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+#endif
+
+
+/* Copy the second part of user declarations. */
+
+
+/* Line 343 of yacc.c */
+#line 281 "cmDependsFortranParser.cxx"
+
+#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#elif (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+typedef signed char yytype_int8;
+#else
+typedef short int yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(msgid) msgid
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(e) ((void) (e))
+#else
+# define YYUSE(e) /* empty */
+#endif
+
+/* Identity function, used to suppress warnings about constant conditions. */
+#ifndef lint
+# define YYID(n) (n)
+#else
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static int
+YYID (int yyi)
+#else
+static int
+YYID (yyi)
+ int yyi;
+#endif
+{
+ return yyi;
+}
+#endif
+
+#if ! defined yyoverflow || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# elif defined __BUILTIN_VA_ARG_INCR
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined _AIX
+# define YYSTACK_ALLOC __alloca
+# elif defined _MSC_VER
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
+# else
+# define YYSTACK_ALLOC alloca
+# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+# endif
+# endif
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's `empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined EXIT_SUCCESS \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif
+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
+
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yytype_int16 yyss_alloc;
+ YYSTYPE yyvs_alloc;
+};
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+# define YYCOPY_NEEDED 1
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
+ Stack = &yyptr->Stack_alloc; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (YYID (0))
+
+#endif
+
+#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
+/* Copy COUNT objects from FROM to TO. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(To, From, Count) \
+ __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# else
+# define YYCOPY(To, From, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (To)[yyi] = (From)[yyi]; \
+ } \
+ while (YYID (0))
+# endif
+# endif
+#endif /* !YYCOPY_NEEDED */
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 2
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 276
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 32
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 16
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 53
+/* YYNRULES -- Number of states. */
+#define YYNSTATES 97
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 286
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const yytype_uint8 yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 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
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+ YYRHS. */
+static const yytype_uint8 yyprhs[] =
+{
+ 0, 0, 3, 4, 7, 9, 11, 16, 19, 24,
+ 30, 38, 43, 47, 52, 57, 62, 67, 72, 76,
+ 80, 84, 88, 93, 97, 99, 101, 103, 105, 107,
+ 109, 111, 113, 115, 117, 119, 121, 123, 125, 127,
+ 129, 131, 133, 135, 137, 139, 140, 143, 145, 147,
+ 149, 151, 153, 155
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yytype_int8 yyrhs[] =
+{
+ 33, 0, -1, -1, 33, 34, -1, 36, -1, 35,
+ -1, 30, 4, 46, 3, -1, 30, 3, -1, 30,
+ 30, 46, 3, -1, 30, 26, 30, 46, 3, -1,
+ 30, 25, 30, 26, 30, 46, 3, -1, 30, 29,
+ 46, 3, -1, 31, 46, 3, -1, 37, 29, 46,
+ 3, -1, 38, 30, 46, 3, -1, 39, 30, 46,
+ 3, -1, 40, 30, 46, 3, -1, 41, 30, 46,
+ 3, -1, 42, 46, 3, -1, 43, 46, 3, -1,
+ 44, 46, 3, -1, 45, 46, 3, -1, 30, 5,
+ 46, 3, -1, 5, 46, 3, -1, 3, -1, 1,
+ -1, 6, -1, 7, -1, 8, -1, 10, -1, 9,
+ -1, 12, -1, 11, -1, 13, -1, 19, -1, 14,
+ -1, 20, -1, 15, -1, 21, -1, 17, -1, 23,
+ -1, 16, -1, 22, -1, 18, -1, 24, -1, -1,
+ 46, 47, -1, 30, -1, 29, -1, 5, -1, 4,
+ -1, 26, -1, 25, -1, 28, -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const yytype_uint16 yyrline[] =
+{
+ 0, 111, 111, 111, 113, 113, 115, 121, 131, 161,
+ 172, 185, 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
+
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+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", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+ token YYLEX-NUM. */
+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
+};
+# endif
+
+/* 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
+};
+
+/* YYR2[YYN] -- Number of symbols composing 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,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 0, 2, 1, 1, 1,
+ 1, 1, 1, 1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
+ Performed when YYTABLE doesn't specify something else to do. Zero
+ 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
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yytype_int8 yydefgoto[] =
+{
+ -1, 1, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35, 36, 37, 38, 39, 65
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+#define YYPACT_NINF -29
+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
+};
+
+/* YYPGOTO[NTERM-NUM]. */
+static const yytype_int8 yypgoto[] =
+{
+ -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
+ -29, -29, -29, -29, -26, -29
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule which
+ number is the opposite. If YYTABLE_NINF, syntax error. */
+#define YYTABLE_NINF -1
+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
+};
+
+#define yypact_value_is_default(yystate) \
+ ((yystate) == (-29))
+
+#define yytable_value_is_error(yytable_value) \
+ YYID (0)
+
+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,
+ 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
+};
+
+/* 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,
+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 24, 30, 31, 34, 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
+};
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+/* Like YYERROR except do call yyerror. This remains here temporarily
+ to ease the transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. However,
+ YYFAIL appears to be in use. Nevertheless, it is formally deprecated
+ in Bison 2.4.2's NEWS entry, where a plan to phase it out is
+ discussed. */
+
+#define YYFAIL goto yyerrlab
+#if defined YYFAIL
+ /* This is here to suppress warnings from the GCC cpp's
+ -Wunused-macros. Normally we don't worry about that warning, but
+ some users do, and we want to make it easy for users to remove
+ YYFAIL uses, which will produce warnings from Bison 2.5. */
+#endif
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ YYPOPSTACK (1); \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+while (YYID (0))
+
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (YYID (N)) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
+ while (YYID (0))
+#endif
+
+
+/* This macro is provided for backward compatibility. */
+
+#ifndef YY_LOCATION_PRINT
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+#endif
+
+
+/* YYLEX -- calling `yylex' with the right arguments. */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval)
+#endif
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (YYID (0))
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Type, Value); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (YYID (0))
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+#else
+static void
+yy_symbol_value_print (yyoutput, yytype, yyvaluep)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+#endif
+{
+ if (!yyvaluep)
+ return;
+# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+ YYUSE (yyoutput);
+# endif
+ switch (yytype)
+ {
+ default:
+ break;
+ }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+#else
+static void
+yy_symbol_print (yyoutput, yytype, yyvaluep)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+#endif
+{
+ if (yytype < YYNTOKENS)
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+ yy_symbol_value_print (yyoutput, yytype, yyvaluep);
+ YYFPRINTF (yyoutput, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
+#else
+static void
+yy_stack_print (yybottom, yytop)
+ yytype_int16 *yybottom;
+ yytype_int16 *yytop;
+#endif
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; yybottom <= yytop; yybottom++)
+ {
+ int yybot = *yybottom;
+ YYFPRINTF (stderr, " %d", yybot);
+ }
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (YYID (0))
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
+#else
+static void
+yy_reduce_print (yyvsp, yyrule)
+ YYSTYPE *yyvsp;
+ int yyrule;
+#endif
+{
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ unsigned long int yylno = yyrline[yyrule];
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ YYFPRINTF (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
+ &(yyvsp[(yyi + 1) - (yynrhs)])
+ );
+ YYFPRINTF (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyvsp, Rule); \
+} while (YYID (0))
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined __GLIBC__ && defined _STRING_H
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static YYSIZE_T
+yystrlen (const char *yystr)
+#else
+static YYSIZE_T
+yystrlen (yystr)
+ const char *yystr;
+#endif
+{
+ YYSIZE_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+#else
+static char *
+yystpcpy (yydest, yysrc)
+ char *yydest;
+ const char *yysrc;
+#endif
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
+static YYSIZE_T
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ YYSIZE_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (! yyres)
+ return yystrlen (yystr);
+
+ return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
+ about the unexpected token YYTOKEN for the state stack whose top is
+ YYSSP.
+
+ Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
+ not large enough to hold the message. In that case, also set
+ *YYMSG_ALLOC to the required number of bytes. Return 2 if the
+ required number of bytes is too large to store. */
+static int
+yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
+ yytype_int16 *yyssp, int yytoken)
+{
+ YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
+ YYSIZE_T yysize = yysize0;
+ YYSIZE_T yysize1;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ /* Internationalized format string. */
+ const char *yyformat = 0;
+ /* Arguments of yyformat. */
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ /* Number of reported tokens (one for the "unexpected", one per
+ "expected"). */
+ int yycount = 0;
+
+ /* There are many possibilities here to consider:
+ - Assume YYFAIL is not used. It's too flawed to consider. See
+ <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
+ for details. YYERROR is fine as it does not invoke this
+ function.
+ - If this state is a consistent state with a default action, then
+ the only way this function was invoked is if the default action
+ is an error action. In that case, don't check for expected
+ tokens because there are none.
+ - The only way there can be no lookahead present (in yychar) is if
+ this state is a consistent state with a default action. Thus,
+ detecting the absence of a lookahead is sufficient to determine
+ that there is no unexpected or expected token to report. In that
+ case, just report a simple "syntax error".
+ - Don't assume there isn't a lookahead just because this state is a
+ consistent state with a default action. There might have been a
+ previous inconsistent state, consistent state with a non-default
+ action, or user semantic action that manipulated yychar.
+ - Of course, the expected token list depends on states to have
+ correct lookahead information, and it depends on the parser not
+ to perform extra reductions after fetching a lookahead from the
+ scanner and before detecting a syntax error. Thus, state merging
+ (from LALR or IELR) and default reductions corrupt the expected
+ token list. However, the list is correct for canonical LR with
+ one exception: it will still contain any token that will not be
+ accepted due to an error action in a later state.
+ */
+ if (yytoken != YYEMPTY)
+ {
+ int yyn = yypact[*yyssp];
+ yyarg[yycount++] = yytname[yytoken];
+ if (!yypact_value_is_default (yyn))
+ {
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. In other words, skip the first -YYN actions for
+ this state because they are default actions. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yyx;
+
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
+ && !yytable_value_is_error (yytable[yyx + yyn]))
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+ if (! (yysize <= yysize1
+ && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+ }
+ }
+ }
+
+ switch (yycount)
+ {
+# define YYCASE_(N, S) \
+ case N: \
+ yyformat = S; \
+ break
+ YYCASE_(0, YY_("syntax error"));
+ YYCASE_(1, YY_("syntax error, unexpected %s"));
+ YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+ YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+ YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+ YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+# undef YYCASE_
+ }
+
+ yysize1 = yysize + yystrlen (yyformat);
+ if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+
+ if (*yymsg_alloc < yysize)
+ {
+ *yymsg_alloc = 2 * yysize;
+ if (! (yysize <= *yymsg_alloc
+ && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
+ *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
+ return 1;
+ }
+
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ {
+ char *yyp = *yymsg;
+ int yyi = 0;
+ while ((*yyp = *yyformat) != '\0')
+ if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyformat += 2;
+ }
+ else
+ {
+ yyp++;
+ yyformat++;
+ }
+ }
+ return 0;
+}
+#endif /* YYERROR_VERBOSE */
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yydestruct (yymsg, yytype, yyvaluep)
+ const char *yymsg;
+ int yytype;
+ YYSTYPE *yyvaluep;
+#endif
+{
+ YYUSE (yyvaluep);
+
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ switch (yytype)
+ {
+
+ default:
+ break;
+ }
+}
+
+
+/* Prevent warnings from -Wmissing-prototypes. */
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void *YYPARSE_PARAM)
+#else
+int
+yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+#endif
+#else /* ! YYPARSE_PARAM */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void)
+#else
+int
+yyparse ()
+
+#endif
+#endif
+{
+/* The lookahead symbol. */
+int yychar;
+
+/* The semantic value of the lookahead symbol. */
+YYSTYPE yylval;
+
+ /* Number of syntax errors so far. */
+ int yynerrs;
+
+ int yystate;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+
+ /* The stacks and their tools:
+ `yyss': related to states.
+ `yyvs': related to semantic values.
+
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss;
+ yytype_int16 *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs;
+ YYSTYPE *yyvsp;
+
+ YYSIZE_T yystacksize;
+
+ int yyn;
+ int yyresult;
+ /* Lookahead token as an internal (translated) token number. */
+ int yytoken;
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+#if YYERROR_VERBOSE
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
+
+ yytoken = 0;
+ yyss = yyssa;
+ yyvs = yyvsa;
+ yystacksize = YYINITDEPTH;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+ yyssp = yyss;
+ yyvsp = yyvs;
+
+ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ yytype_int16 *yyss1 = yyss;
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),
+ &yystacksize);
+
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyexhaustedlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yytype_int16 *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE (yyss_alloc, yyss);
+ YYSTACK_RELOCATE (yyvs_alloc, yyvs);
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ if (yystate == YYFINAL)
+ YYACCEPT;
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+ /* Do appropriate processing given the current state. Read a
+ lookahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to lookahead token. */
+ yyn = yypact[yystate];
+ if (yypact_value_is_default (yyn))
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yytable_value_is_error (yyn))
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the lookahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the shifted token. */
+ yychar = YYEMPTY;
+
+ yystate = yyn;
+ *++yyvsp = yylval;
+
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 6:
+
+/* Line 1806 of yacc.c */
+#line 116 "cmDependsFortranParser.y"
+ {
+ free((yyvsp[(1) - (4)].string));
+ }
+ break;
+
+ case 7:
+
+/* Line 1806 of yacc.c */
+#line 122 "cmDependsFortranParser.y"
+ {
+ if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (2)].string), "interface"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_SetInInterface(parser, true);
+ }
+ free((yyvsp[(1) - (2)].string));
+ }
+ break;
+
+ case 8:
+
+/* Line 1806 of yacc.c */
+#line 132 "cmDependsFortranParser.y"
+ {
+ if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (4)].string), "use"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleUse(parser, (yyvsp[(2) - (4)].string));
+ }
+ else if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (4)].string), "module"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleModule(parser, (yyvsp[(2) - (4)].string));
+ }
+ else if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (4)].string), "interface"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_SetInInterface(parser, true);
+ }
+ else if (cmDependsFortranParserIsKeyword((yyvsp[(2) - (4)].string), "interface") &&
+ cmDependsFortranParserIsKeyword((yyvsp[(1) - (4)].string), "end"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_SetInInterface(parser, false);
+ }
+ free((yyvsp[(1) - (4)].string));
+ free((yyvsp[(2) - (4)].string));
+ }
+ break;
+
+ case 9:
+
+/* Line 1806 of yacc.c */
+#line 162 "cmDependsFortranParser.y"
+ {
+ if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (5)].string), "use"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleUse(parser, (yyvsp[(3) - (5)].string));
+ }
+ free((yyvsp[(1) - (5)].string));
+ free((yyvsp[(3) - (5)].string));
+ }
+ break;
+
+ case 10:
+
+/* Line 1806 of yacc.c */
+#line 173 "cmDependsFortranParser.y"
+ {
+ if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (7)].string), "use") &&
+ cmDependsFortranParserIsKeyword((yyvsp[(3) - (7)].string), "non_intrinsic") )
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleUse(parser, (yyvsp[(5) - (7)].string));
+ }
+ free((yyvsp[(1) - (7)].string));
+ free((yyvsp[(3) - (7)].string));
+ free((yyvsp[(5) - (7)].string));
+ }
+ break;
+
+ case 11:
+
+/* Line 1806 of yacc.c */
+#line 186 "cmDependsFortranParser.y"
+ {
+ if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (4)].string), "include"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleInclude(parser, (yyvsp[(2) - (4)].string));
+ }
+ free((yyvsp[(1) - (4)].string));
+ free((yyvsp[(2) - (4)].string));
+ }
+ break;
+
+ case 12:
+
+/* Line 1806 of yacc.c */
+#line 197 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleInclude(parser, (yyvsp[(1) - (3)].string));
+ free((yyvsp[(1) - (3)].string));
+ }
+ break;
+
+ case 13:
+
+/* Line 1806 of yacc.c */
+#line 204 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleInclude(parser, (yyvsp[(2) - (4)].string));
+ free((yyvsp[(2) - (4)].string));
+ }
+ break;
+
+ case 14:
+
+/* Line 1806 of yacc.c */
+#line 211 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleDefine(parser, (yyvsp[(2) - (4)].string));
+ free((yyvsp[(2) - (4)].string));
+ }
+ break;
+
+ case 15:
+
+/* Line 1806 of yacc.c */
+#line 217 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleUndef(parser, (yyvsp[(2) - (4)].string));
+ free((yyvsp[(2) - (4)].string));
+ }
+ break;
+
+ case 16:
+
+/* Line 1806 of yacc.c */
+#line 223 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleIfdef(parser, (yyvsp[(2) - (4)].string));
+ free((yyvsp[(2) - (4)].string));
+ }
+ break;
+
+ case 17:
+
+/* Line 1806 of yacc.c */
+#line 229 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleIfndef(parser, (yyvsp[(2) - (4)].string));
+ free((yyvsp[(2) - (4)].string));
+ }
+ break;
+
+ case 18:
+
+/* Line 1806 of yacc.c */
+#line 235 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleIf(parser);
+ }
+ break;
+
+ case 19:
+
+/* Line 1806 of yacc.c */
+#line 240 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleElif(parser);
+ }
+ break;
+
+ case 20:
+
+/* Line 1806 of yacc.c */
+#line 245 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleElse(parser);
+ }
+ break;
+
+ case 21:
+
+/* Line 1806 of yacc.c */
+#line 250 "cmDependsFortranParser.y"
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleEndif(parser);
+ }
+ break;
+
+ case 22:
+
+/* Line 1806 of yacc.c */
+#line 255 "cmDependsFortranParser.y"
+ {
+ free((yyvsp[(1) - (4)].string));
+ }
+ break;
+
+ case 47:
+
+/* Line 1806 of yacc.c */
+#line 277 "cmDependsFortranParser.y"
+ { free ((yyvsp[(1) - (1)].string)); }
+ break;
+
+ case 48:
+
+/* Line 1806 of yacc.c */
+#line 278 "cmDependsFortranParser.y"
+ { free ((yyvsp[(1) - (1)].string)); }
+ break;
+
+
+
+/* Line 1806 of yacc.c */
+#line 1860 "cmDependsFortranParser.cxx"
+ default: break;
+ }
+ /* User semantic actions sometimes alter yychar, and that requires
+ that yytoken be updated with the new translation. We take the
+ approach of translating immediately before every use of yytoken.
+ One alternative is translating here after every semantic action,
+ but that translation would be missed if the semantic action invokes
+ YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
+ if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
+ incorrect destructor might then be invoked immediately. In the
+ case of YYERROR or YYBACKUP, subsequent parser actions might lead
+ to an incorrect destructor call or verbose syntax error message
+ before the lookahead is translated. */
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+
+ /* Now `shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
+
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if ! YYERROR_VERBOSE
+ yyerror (YY_("syntax error"));
+#else
+# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
+ yyssp, yytoken)
+ {
+ char const *yymsgp = YY_("syntax error");
+ int yysyntax_error_status;
+ yysyntax_error_status = YYSYNTAX_ERROR;
+ if (yysyntax_error_status == 0)
+ yymsgp = yymsg;
+ else if (yysyntax_error_status == 1)
+ {
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+ yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
+ if (!yymsg)
+ {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ yysyntax_error_status = 2;
+ }
+ else
+ {
+ yysyntax_error_status = YYSYNTAX_ERROR;
+ yymsgp = yymsg;
+ }
+ }
+ yyerror (yymsgp);
+ if (yysyntax_error_status == 2)
+ goto yyexhaustedlab;
+ }
+# undef YYSYNTAX_ERROR
+#endif
+ }
+
+
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval);
+ yychar = YYEMPTY;
+ }
+ }
+
+#if 0
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (/*CONSTCOND*/ 0)
+ goto yyerrorlab;
+
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+#endif
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (!yypact_value_is_default (yyn))
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ *++yyvsp = yylval;
+
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#if !defined(yyoverflow) || YYERROR_VERBOSE
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here. |
+`-------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+ if (yychar != YYEMPTY)
+ {
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = YYTRANSLATE (yychar);
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval);
+ }
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ yystos[*yyssp], yyvsp);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+#if YYERROR_VERBOSE
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+#endif
+ /* Make sure YYID is used. */
+ return YYID (yyresult);
+}
+
+
+
+/* Line 2067 of yacc.c */
+#line 286 "cmDependsFortranParser.y"
+
+/* End of grammar */
diff --git a/Source/cmDependsFortranParser.h b/Source/cmDependsFortranParser.h
new file mode 100644
index 0000000000..399c3c8d96
--- /dev/null
+++ b/Source/cmDependsFortranParser.h
@@ -0,0 +1,96 @@
+/*============================================================================
+ 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 cmDependsFortranParser_h
+#define cmDependsFortranParser_h
+
+#include <stddef.h> /* size_t */
+
+/* Forward declare parser object type. */
+typedef struct cmDependsFortranParser_s cmDependsFortranParser;
+
+/* Functions to enter/exit #include'd files in order. */
+bool cmDependsFortranParser_FilePush(cmDependsFortranParser* parser,
+ const char* fname);
+bool cmDependsFortranParser_FilePop(cmDependsFortranParser* parser);
+
+/* Callbacks for lexer. */
+int cmDependsFortranParser_Input(cmDependsFortranParser* parser,
+ char* buffer, size_t bufferSize);
+
+
+void cmDependsFortranParser_StringStart(cmDependsFortranParser* parser);
+const char* cmDependsFortranParser_StringEnd(cmDependsFortranParser* parser);
+void cmDependsFortranParser_StringAppend(cmDependsFortranParser* parser,
+ char c);
+
+void cmDependsFortranParser_SetInInterface(cmDependsFortranParser* parser,
+ bool is_in);
+bool cmDependsFortranParser_GetInInterface(cmDependsFortranParser* parser);
+
+
+void cmDependsFortranParser_SetInPPFalseBranch(cmDependsFortranParser* parser,
+ bool is_in);
+bool cmDependsFortranParser_GetInPPFalseBranch(cmDependsFortranParser* parser);
+
+
+void cmDependsFortranParser_SetOldStartcond(cmDependsFortranParser* parser,
+ int arg);
+int cmDependsFortranParser_GetOldStartcond(cmDependsFortranParser* parser);
+
+/* Callbacks for parser. */
+void cmDependsFortranParser_Error(cmDependsFortranParser* parser,
+ const char* message);
+void cmDependsFortranParser_RuleUse(cmDependsFortranParser* parser,
+ const char* name);
+void cmDependsFortranParser_RuleInclude(cmDependsFortranParser* parser,
+ const char* name);
+void cmDependsFortranParser_RuleModule(cmDependsFortranParser* parser,
+ const char* name);
+void cmDependsFortranParser_RuleDefine(cmDependsFortranParser* parser,
+ const char* name);
+void cmDependsFortranParser_RuleUndef(cmDependsFortranParser* parser,
+ const char* name);
+void cmDependsFortranParser_RuleIfdef(cmDependsFortranParser* parser,
+ const char* name);
+void cmDependsFortranParser_RuleIfndef(cmDependsFortranParser* parser,
+ const char* name);
+void cmDependsFortranParser_RuleIf(cmDependsFortranParser* parser);
+void cmDependsFortranParser_RuleElif(cmDependsFortranParser* parser);
+void cmDependsFortranParser_RuleElse(cmDependsFortranParser* parser);
+void cmDependsFortranParser_RuleEndif(cmDependsFortranParser* parser);
+
+/* Define the parser stack element type. */
+typedef union cmDependsFortran_yystype_u cmDependsFortran_yystype;
+union cmDependsFortran_yystype_u
+{
+ char* string;
+};
+
+/* Setup the proper yylex interface. */
+#define YY_EXTRA_TYPE cmDependsFortranParser*
+#define YY_DECL \
+int cmDependsFortran_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
+#define YYSTYPE cmDependsFortran_yystype
+#define YYSTYPE_IS_DECLARED 1
+#if !defined(cmDependsFortranLexer_cxx)
+# include "cmDependsFortranLexer.h"
+#endif
+#if !defined(cmDependsFortranLexer_cxx)
+#if !defined(cmDependsFortranParser_cxx)
+# undef YY_EXTRA_TYPE
+# undef YY_DECL
+# undef YYSTYPE
+# undef YYSTYPE_IS_DECLARED
+#endif
+#endif
+
+#endif
diff --git a/Source/cmDependsFortranParser.y b/Source/cmDependsFortranParser.y
new file mode 100644
index 0000000000..d814f30751
--- /dev/null
+++ b/Source/cmDependsFortranParser.y
@@ -0,0 +1,288 @@
+%{
+/*============================================================================
+ 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.
+============================================================================*/
+/*-------------------------------------------------------------------------
+ Portions of this source have been derived from makedepf90 version 2.8.8,
+
+ Copyright (C) 2000--2006 Erik Edelmann <erik.edelmann@iki.fi>
+
+ The code was originally distributed under the GPL but permission
+ from the copyright holder has been obtained to distribute this
+ derived work under the CMake license.
+-------------------------------------------------------------------------*/
+
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run bison like this:
+
+ bison --yacc --name-prefix=cmDependsFortran_yy
+ --defines=cmDependsFortranParserTokens.h
+ -ocmDependsFortranParser.cxx
+ cmDependsFortranParser.y
+
+Modify cmDependsFortranParser.cxx:
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - Remove the yyerrorlab block in range ["goto yyerrlab1", "yyerrlab1:"]
+*/
+
+/*-------------------------------------------------------------------------*/
+#define cmDependsFortranParser_cxx
+#include "cmDependsFortranParser.h" /* Interface to parser object. */
+#include "cmDependsFortranParserTokens.h" /* Need YYSTYPE for YY_DECL. */
+
+#include <cmsys/String.h>
+
+/* Configure the parser to use a lexer object. */
+#define YYPARSE_PARAM yyscanner
+#define YYLEX_PARAM yyscanner
+#define YYERROR_VERBOSE 1
+#define cmDependsFortran_yyerror(x) \
+ cmDependsFortranError(yyscanner, x)
+
+/* Forward declare the lexer entry point. */
+YY_DECL;
+
+/* Helper function to forward error callback. */
+static void cmDependsFortranError(yyscan_t yyscanner, const char* message)
+{
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_Error(parser, message);
+}
+
+static bool cmDependsFortranParserIsKeyword(const char* word,
+ const char* keyword)
+{
+ return cmsysString_strcasecmp(word, keyword) == 0;
+}
+
+/* Disable some warnings in the generated code. */
+#ifdef __BORLANDC__
+# pragma warn -8004 /* Variable assigned a value that is not used. */
+# pragma warn -8008 /* condition always returns true */
+# pragma warn -8060 /* possibly incorrect assignment */
+# pragma warn -8066 /* unreachable code */
+#endif
+#ifdef _MSC_VER
+# pragma warning (disable: 4102) /* Unused goto label. */
+# pragma warning (disable: 4065) /* Switch contains default but no case. */
+# pragma warning (disable: 4701) /* Local variable may not be initialized. */
+# pragma warning (disable: 4702) /* Unreachable code. */
+# pragma warning (disable: 4127) /* Conditional expression is constant. */
+# pragma warning (disable: 4244) /* Conversion to smaller type, data loss. */
+#endif
+%}
+
+/* Generate a reentrant parser object. */
+%pure-parser
+
+%union {
+ char* string;
+}
+
+/*-------------------------------------------------------------------------*/
+/* Tokens */
+%token EOSTMT ASSIGNMENT_OP GARBAGE
+%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
+%token F90PPR_IFDEF F90PPR_IFNDEF F90PPR_IF
+%token F90PPR_ELSE F90PPR_ELIF F90PPR_ENDIF
+%token COMMA DCOLON
+%token <string> CPP_TOENDL
+%token <number> UNTERMINATED_STRING
+%token <string> STRING WORD
+%token <string> CPP_INCLUDE_ANGLE
+
+/*-------------------------------------------------------------------------*/
+/* grammar */
+%%
+
+code: /* empty */ | code stmt;
+
+stmt: keyword_stmt | assignment_stmt;
+
+assignment_stmt: WORD ASSIGNMENT_OP other EOSTMT /* Ignore */
+ {
+ free($1);
+ }
+
+keyword_stmt:
+ WORD EOSTMT
+ {
+ if (cmDependsFortranParserIsKeyword($1, "interface"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_SetInInterface(parser, true);
+ }
+ free($1);
+ }
+| WORD WORD other EOSTMT
+ {
+ if (cmDependsFortranParserIsKeyword($1, "use"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleUse(parser, $2);
+ }
+ else if (cmDependsFortranParserIsKeyword($1, "module"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleModule(parser, $2);
+ }
+ else if (cmDependsFortranParserIsKeyword($1, "interface"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_SetInInterface(parser, true);
+ }
+ else if (cmDependsFortranParserIsKeyword($2, "interface") &&
+ cmDependsFortranParserIsKeyword($1, "end"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_SetInInterface(parser, false);
+ }
+ free($1);
+ free($2);
+ }
+| WORD DCOLON WORD other EOSTMT
+ {
+ if (cmDependsFortranParserIsKeyword($1, "use"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleUse(parser, $3);
+ }
+ free($1);
+ free($3);
+ }
+| WORD COMMA WORD DCOLON WORD other EOSTMT
+ {
+ if (cmDependsFortranParserIsKeyword($1, "use") &&
+ cmDependsFortranParserIsKeyword($3, "non_intrinsic") )
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleUse(parser, $5);
+ }
+ free($1);
+ free($3);
+ free($5);
+ }
+| WORD STRING other EOSTMT /* Ignore */
+ {
+ if (cmDependsFortranParserIsKeyword($1, "include"))
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleInclude(parser, $2);
+ }
+ free($1);
+ free($2);
+ }
+| CPP_INCLUDE_ANGLE other EOSTMT
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleInclude(parser, $1);
+ free($1);
+ }
+| include STRING other EOSTMT
+ {
+ cmDependsFortranParser* parser =
+ cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleInclude(parser, $2);
+ free($2);
+ }
+| define WORD other EOSTMT
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleDefine(parser, $2);
+ free($2);
+ }
+| undef WORD other EOSTMT
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleUndef(parser, $2);
+ free($2);
+ }
+| ifdef WORD other EOSTMT
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleIfdef(parser, $2);
+ free($2);
+ }
+| ifndef WORD other EOSTMT
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleIfndef(parser, $2);
+ free($2);
+ }
+| if other EOSTMT
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleIf(parser);
+ }
+| elif other EOSTMT
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleElif(parser);
+ }
+| else other EOSTMT
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleElse(parser);
+ }
+| endif other EOSTMT
+ {
+ cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
+ cmDependsFortranParser_RuleEndif(parser);
+ }
+| WORD GARBAGE other EOSTMT /* Ignore */
+ {
+ free($1);
+ }
+| GARBAGE other EOSTMT
+| EOSTMT
+| error
+;
+
+
+
+include: CPP_INCLUDE | F90PPR_INCLUDE | COCO_INCLUDE ;
+define: CPP_DEFINE | F90PPR_DEFINE;
+undef: CPP_UNDEF | F90PPR_UNDEF ;
+ifdef: CPP_IFDEF | F90PPR_IFDEF ;
+ifndef: CPP_IFNDEF | F90PPR_IFNDEF ;
+if: CPP_IF | F90PPR_IF ;
+elif: CPP_ELIF | F90PPR_ELIF ;
+else: CPP_ELSE | F90PPR_ELSE ;
+endif: CPP_ENDIF | F90PPR_ENDIF ;
+other: /* empty */ | other misc_code ;
+
+misc_code:
+ WORD { free ($1); }
+| STRING { free ($1); }
+| GARBAGE
+| ASSIGNMENT_OP
+| DCOLON
+| COMMA
+| UNTERMINATED_STRING
+;
+
+%%
+/* End of grammar */
diff --git a/Source/cmDependsFortranParserTokens.h b/Source/cmDependsFortranParserTokens.h
new file mode 100644
index 0000000000..941eda09c4
--- /dev/null
+++ b/Source/cmDependsFortranParserTokens.h
@@ -0,0 +1,122 @@
+/* A Bison parser, made by GNU Bison 2.5. */
+
+/* Bison interface for Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ 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
+ };
+#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
+
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+{
+
+/* Line 2068 of yacc.c */
+#line 89 "cmDependsFortranParser.y"
+
+ char* string;
+
+
+
+/* Line 2068 of yacc.c */
+#line 118 "cmDependsFortranParserTokens.h"
+} YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+#endif
diff --git a/Source/cmDependsJava.cxx b/Source/cmDependsJava.cxx
new file mode 100644
index 0000000000..949d465159
--- /dev/null
+++ b/Source/cmDependsJava.cxx
@@ -0,0 +1,45 @@
+/*============================================================================
+ 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 "cmDependsJava.h"
+
+#include "cmDependsJavaParserHelper.h"
+#include "cmSystemTools.h"
+
+//----------------------------------------------------------------------------
+cmDependsJava::cmDependsJava()
+{
+}
+
+//----------------------------------------------------------------------------
+cmDependsJava::~cmDependsJava()
+{
+}
+
+//----------------------------------------------------------------------------
+bool cmDependsJava::WriteDependencies(const std::set<std::string>& sources,
+ const std::string&, std::ostream&, std::ostream&)
+{
+ // Make sure this is a scanning instance.
+ if(sources.empty() || sources.begin()->empty())
+ {
+ cmSystemTools::Error("Cannot scan dependencies without an source file.");
+ return false;
+ }
+
+ return true;
+}
+
+bool cmDependsJava::CheckDependencies(std::istream&, const char*,
+ std::map<std::string, DependencyVector >&)
+{
+ return true;
+}
diff --git a/Source/cmDependsJava.h b/Source/cmDependsJava.h
new file mode 100644
index 0000000000..22af53f8dc
--- /dev/null
+++ b/Source/cmDependsJava.h
@@ -0,0 +1,44 @@
+/*============================================================================
+ 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 cmDependsJava_h
+#define cmDependsJava_h
+
+#include "cmDepends.h"
+
+/** \class cmDependsJava
+ * \brief Dependency scanner for Java class files.
+ */
+class cmDependsJava: public cmDepends
+{
+public:
+ /** Checking instances need to know the build directory name and the
+ relative path from the build directory to the target file. */
+ cmDependsJava();
+
+ /** Virtual destructor to cleanup subclasses properly. */
+ virtual ~cmDependsJava();
+
+protected:
+ // Implement writing/checking methods required by superclass.
+ virtual bool WriteDependencies(
+ const std::set<std::string>& sources, const std::string& file,
+ std::ostream& makeDepends, std::ostream& internalDepends);
+ virtual bool CheckDependencies(std::istream& internalDepends,
+ const char* internalDependsFileName,
+ std::map<std::string, DependencyVector>& validDeps);
+
+private:
+ cmDependsJava(cmDependsJava const&); // Purposely not implemented.
+ void operator=(cmDependsJava const&); // Purposely not implemented.
+};
+
+#endif
diff --git a/Source/cmDependsJavaLexer.cxx b/Source/cmDependsJavaLexer.cxx
new file mode 100644
index 0000000000..f7676d9c27
--- /dev/null
+++ b/Source/cmDependsJavaLexer.cxx
@@ -0,0 +1,2542 @@
+#include "cmStandardIncludes.h"
+#line 2 "cmDependsJavaLexer.cxx"
+
+#line 4 "cmDependsJavaLexer.cxx"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 31
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#if defined(__BEOS__) || defined (__HAIKU__)
+#include <unistd.h> /* prevents a conflict with a #define later on... */
+#endif
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+int cmDependsJava_yylex_init (yyscan_t* scanner);
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yyg->yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yyg->yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE cmDependsJava_yyrestart(yyin ,yyscanner )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#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)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = yyg->yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef unsigned int yy_size_t;
+#endif
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int 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
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via cmDependsJava_yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
+ ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
+
+void cmDependsJava_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void cmDependsJava_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsJava_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
+void cmDependsJava_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmDependsJava_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmDependsJava_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+void cmDependsJava_yypop_buffer_state (yyscan_t yyscanner );
+
+static void cmDependsJava_yyensure_buffer_stack (yyscan_t yyscanner );
+static void cmDependsJava_yy_load_buffer_state (yyscan_t yyscanner );
+static void cmDependsJava_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
+
+#define YY_FLUSH_BUFFER cmDependsJava_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+
+YY_BUFFER_STATE cmDependsJava_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsJava_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsJava_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+
+void *cmDependsJava_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *cmDependsJava_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void cmDependsJava_yyfree (void * ,yyscan_t yyscanner );
+
+#define yy_new_buffer cmDependsJava_yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ cmDependsJava_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmDependsJava_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ cmDependsJava_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmDependsJava_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+#define cmDependsJava_yywrap(n) 1
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+typedef int yy_state_type;
+
+#define yytext_ptr yytext_r
+
+static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
+static int yy_get_next_buffer (yyscan_t yyscanner );
+static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yyg->yytext_ptr = yy_bp; \
+ yyleng = (size_t) (yy_cp - yy_bp); \
+ yyg->yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yyg->yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 111
+#define YY_END_OF_BUFFER 112
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[327] =
+ { 0,
+ 0, 0, 0, 0, 0, 0, 112, 110, 109, 109,
+ 77, 4, 73, 94, 60, 110, 93, 92, 105, 99,
+ 68, 89, 74, 71, 56, 56, 67, 103, 86, 75,
+ 79, 102, 107, 64, 63, 65, 107, 107, 107, 107,
+ 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
+ 107, 70, 96, 69, 104, 3, 3, 6, 111, 5,
+ 78, 95, 61, 62, 0, 0, 106, 101, 100, 91,
+ 90, 57, 1, 0, 72, 57, 56, 57, 0, 56,
+ 0, 88, 87, 76, 80, 81, 107, 66, 107, 107,
+ 107, 107, 107, 107, 107, 107, 107, 107, 18, 107,
+
+ 107, 107, 107, 107, 107, 26, 107, 107, 107, 107,
+ 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
+ 107, 107, 107, 107, 107, 97, 98, 2, 55, 55,
+ 0, 0, 0, 108, 57, 0, 57, 58, 85, 82,
+ 83, 107, 107, 107, 107, 107, 107, 107, 107, 107,
+ 107, 107, 107, 107, 107, 107, 107, 107, 25, 107,
+ 107, 30, 107, 107, 34, 107, 107, 107, 107, 107,
+ 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
+ 107, 50, 107, 107, 107, 0, 0, 58, 84, 107,
+ 107, 107, 107, 11, 12, 107, 14, 107, 107, 107,
+
+ 107, 20, 107, 107, 107, 107, 107, 107, 107, 107,
+ 32, 107, 59, 107, 107, 107, 107, 107, 107, 107,
+ 107, 107, 107, 107, 46, 107, 107, 54, 51, 107,
+ 107, 107, 107, 107, 10, 13, 15, 107, 107, 107,
+ 107, 22, 24, 107, 107, 107, 107, 107, 107, 107,
+ 107, 107, 107, 40, 107, 107, 43, 107, 107, 47,
+ 107, 107, 53, 107, 8, 107, 107, 107, 19, 107,
+ 107, 107, 28, 107, 107, 33, 107, 107, 107, 38,
+ 39, 41, 107, 44, 107, 48, 107, 107, 107, 9,
+ 107, 17, 21, 23, 107, 107, 107, 35, 36, 107,
+
+ 107, 107, 107, 107, 7, 16, 107, 107, 107, 107,
+ 42, 107, 107, 52, 107, 107, 31, 37, 107, 49,
+ 27, 29, 107, 107, 45, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 2, 2, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 4, 5, 1, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 19,
+ 19, 19, 19, 19, 19, 20, 20, 21, 22, 23,
+ 24, 25, 26, 1, 27, 27, 27, 28, 29, 28,
+ 30, 30, 30, 30, 30, 31, 30, 30, 30, 30,
+ 30, 30, 30, 30, 30, 30, 30, 32, 30, 30,
+ 33, 34, 35, 36, 30, 1, 37, 38, 39, 40,
+
+ 41, 42, 43, 44, 45, 30, 46, 47, 48, 49,
+ 50, 51, 30, 52, 53, 54, 55, 56, 57, 58,
+ 59, 60, 61, 62, 63, 64, 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, 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, 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, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[65] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,
+ 1, 1, 1, 1, 1, 1, 1, 3, 3, 3,
+ 1, 1, 1, 1, 1, 1, 3, 3, 3, 4,
+ 4, 4, 1, 1, 1, 1, 3, 3, 3, 3,
+ 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int16_t yy_base[334] =
+ { 0,
+ 0, 0, 401, 400, 62, 63, 411, 414, 414, 414,
+ 386, 414, 414, 385, 61, 374, 414, 414, 383, 57,
+ 414, 56, 54, 65, 74, 43, 414, 414, 55, 382,
+ 59, 414, 0, 414, 414, 381, 38, 36, 60, 46,
+ 51, 75, 69, 354, 82, 76, 362, 85, 56, 352,
+ 357, 414, 100, 414, 414, 414, 383, 414, 414, 414,
+ 414, 414, 414, 414, 390, 127, 414, 414, 414, 414,
+ 414, 129, 414, 395, 414, 132, 95, 414, 165, 414,
+ 0, 373, 414, 414, 414, 109, 0, 414, 343, 342,
+ 344, 352, 338, 101, 354, 353, 340, 346, 332, 333,
+
+ 331, 337, 334, 332, 329, 0, 329, 110, 330, 324,
+ 320, 329, 336, 93, 336, 319, 322, 89, 320, 325,
+ 320, 114, 131, 120, 323, 414, 414, 414, 414, 358,
+ 170, 357, 362, 414, 173, 157, 176, 150, 414, 414,
+ 340, 309, 321, 314, 323, 318, 317, 318, 304, 302,
+ 300, 316, 314, 310, 309, 296, 311, 310, 0, 153,
+ 292, 304, 301, 298, 0, 295, 295, 284, 285, 291,
+ 282, 284, 281, 289, 292, 278, 292, 277, 279, 279,
+ 286, 0, 286, 288, 277, 189, 314, 414, 414, 270,
+ 269, 279, 273, 0, 0, 274, 0, 264, 271, 260,
+
+ 267, 0, 264, 271, 264, 256, 268, 256, 270, 254,
+ 0, 249, 0, 267, 266, 261, 256, 248, 245, 253,
+ 258, 244, 256, 250, 0, 236, 239, 0, 0, 237,
+ 249, 252, 234, 250, 0, 0, 0, 237, 238, 243,
+ 243, 235, 0, 233, 226, 230, 236, 236, 233, 221,
+ 235, 234, 223, 0, 232, 216, 0, 225, 216, 214,
+ 221, 220, 0, 225, 0, 214, 207, 207, 0, 207,
+ 200, 217, 0, 218, 219, 0, 214, 213, 199, 0,
+ 0, 0, 210, 0, 201, 0, 209, 202, 194, 0,
+ 206, 0, 0, 0, 197, 204, 205, 0, 0, 202,
+
+ 191, 192, 191, 198, 0, 0, 163, 162, 170, 170,
+ 0, 164, 152, 0, 152, 157, 0, 0, 127, 0,
+ 0, 0, 115, 95, 0, 414, 218, 222, 226, 228,
+ 232, 96, 235
+ } ;
+
+static yyconst flex_int16_t yy_def[334] =
+ { 0,
+ 326, 1, 327, 327, 328, 328, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 329, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 25, 326, 326, 326, 326,
+ 326, 326, 330, 326, 326, 326, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 329, 326, 326, 326, 326,
+ 326, 326, 326, 331, 326, 326, 25, 326, 326, 326,
+ 332, 326, 326, 326, 326, 326, 330, 326, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 326, 326, 326, 326, 326,
+ 326, 333, 331, 326, 326, 326, 326, 332, 326, 326,
+ 326, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 326, 333, 326, 326, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 330, 330, 330, 330, 330,
+ 330, 330, 330, 330, 330, 0, 326, 326, 326, 326,
+ 326, 326, 326
+ } ;
+
+static yyconst flex_int16_t yy_nxt[479] =
+ { 0,
+ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+ 18, 19, 20, 21, 22, 23, 24, 25, 26, 26,
+ 27, 28, 29, 30, 31, 32, 33, 33, 33, 33,
+ 33, 33, 34, 8, 35, 36, 37, 38, 39, 40,
+ 41, 42, 33, 33, 43, 33, 44, 33, 45, 33,
+ 46, 47, 48, 49, 33, 50, 51, 33, 33, 33,
+ 52, 53, 54, 55, 59, 59, 60, 60, 63, 68,
+ 70, 72, 72, 72, 326, 89, 73, 82, 83, 71,
+ 69, 74, 85, 86, 64, 91, 98, 92, 75, 76,
+ 90, 77, 77, 77, 93, 99, 94, 100, 138, 122,
+
+ 326, 78, 79, 95, 80, 81, 96, 123, 101, 97,
+ 106, 102, 113, 78, 79, 78, 107, 108, 110, 103,
+ 80, 104, 111, 126, 105, 173, 326, 114, 117, 326,
+ 115, 81, 140, 141, 325, 130, 112, 168, 118, 119,
+ 174, 120, 169, 121, 131, 131, 72, 72, 72, 135,
+ 135, 135, 326, 147, 148, 324, 78, 79, 178, 78,
+ 79, 127, 161, 162, 183, 179, 184, 180, 78, 79,
+ 78, 78, 79, 78, 137, 137, 137, 136, 129, 136,
+ 188, 132, 137, 137, 137, 181, 323, 186, 186, 182,
+ 135, 135, 135, 137, 137, 137, 188, 129, 322, 207,
+
+ 78, 79, 208, 78, 321, 320, 186, 186, 319, 318,
+ 317, 316, 78, 79, 78, 78, 315, 78, 56, 56,
+ 56, 56, 58, 58, 58, 58, 65, 65, 65, 65,
+ 87, 87, 133, 133, 133, 133, 187, 187, 314, 313,
+ 312, 311, 310, 309, 308, 307, 306, 305, 304, 303,
+ 302, 301, 300, 299, 298, 297, 296, 295, 294, 293,
+ 292, 291, 290, 289, 288, 287, 286, 285, 284, 283,
+ 282, 281, 280, 279, 278, 277, 276, 275, 274, 273,
+ 272, 271, 270, 269, 268, 267, 266, 265, 264, 263,
+ 262, 261, 260, 259, 258, 257, 256, 255, 254, 253,
+
+ 252, 251, 250, 249, 248, 247, 246, 245, 244, 243,
+ 242, 228, 241, 240, 239, 238, 237, 236, 235, 234,
+ 233, 232, 129, 231, 230, 229, 228, 227, 226, 225,
+ 224, 223, 222, 221, 220, 219, 218, 217, 216, 215,
+ 214, 213, 212, 211, 210, 209, 206, 205, 204, 203,
+ 202, 201, 200, 199, 198, 197, 196, 195, 194, 193,
+ 192, 191, 190, 189, 134, 129, 129, 185, 177, 176,
+ 175, 172, 171, 170, 167, 166, 165, 164, 163, 160,
+ 159, 158, 157, 156, 155, 154, 153, 152, 151, 150,
+ 149, 146, 145, 144, 143, 142, 139, 134, 129, 128,
+
+ 125, 124, 116, 109, 88, 84, 67, 66, 62, 61,
+ 326, 57, 57, 7, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326
+ } ;
+
+static yyconst flex_int16_t yy_chk[479] =
+ { 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, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 5, 6, 5, 6, 15, 20,
+ 22, 23, 23, 23, 26, 37, 24, 29, 29, 22,
+ 20, 24, 31, 31, 15, 38, 40, 38, 24, 25,
+ 37, 25, 25, 25, 38, 40, 39, 41, 332, 49,
+
+ 26, 25, 25, 39, 25, 25, 39, 49, 41, 39,
+ 43, 42, 46, 25, 25, 25, 43, 43, 45, 42,
+ 25, 42, 45, 53, 42, 118, 77, 46, 48, 66,
+ 46, 25, 86, 86, 324, 66, 45, 114, 48, 48,
+ 118, 48, 114, 48, 66, 66, 72, 72, 72, 76,
+ 76, 76, 77, 94, 94, 323, 72, 72, 122, 76,
+ 76, 53, 108, 108, 124, 122, 124, 123, 72, 72,
+ 72, 76, 76, 76, 136, 136, 136, 79, 131, 79,
+ 138, 66, 79, 79, 79, 123, 319, 131, 131, 123,
+ 135, 135, 135, 137, 137, 137, 138, 186, 316, 160,
+
+ 135, 135, 160, 137, 315, 313, 186, 186, 312, 310,
+ 309, 308, 135, 135, 135, 137, 307, 137, 327, 327,
+ 327, 327, 328, 328, 328, 328, 329, 329, 329, 329,
+ 330, 330, 331, 331, 331, 331, 333, 333, 304, 303,
+ 302, 301, 300, 297, 296, 295, 291, 289, 288, 287,
+ 285, 283, 279, 278, 277, 275, 274, 272, 271, 270,
+ 268, 267, 266, 264, 262, 261, 260, 259, 258, 256,
+ 255, 253, 252, 251, 250, 249, 248, 247, 246, 245,
+ 244, 242, 241, 240, 239, 238, 234, 233, 232, 231,
+ 230, 227, 226, 224, 223, 222, 221, 220, 219, 218,
+
+ 217, 216, 215, 214, 212, 210, 209, 208, 207, 206,
+ 205, 204, 203, 201, 200, 199, 198, 196, 193, 192,
+ 191, 190, 187, 185, 184, 183, 181, 180, 179, 178,
+ 177, 176, 175, 174, 173, 172, 171, 170, 169, 168,
+ 167, 166, 164, 163, 162, 161, 158, 157, 156, 155,
+ 154, 153, 152, 151, 150, 149, 148, 147, 146, 145,
+ 144, 143, 142, 141, 133, 132, 130, 125, 121, 120,
+ 119, 117, 116, 115, 113, 112, 111, 110, 109, 107,
+ 105, 104, 103, 102, 101, 100, 99, 98, 97, 96,
+ 95, 93, 92, 91, 90, 89, 82, 74, 65, 57,
+
+ 51, 50, 47, 44, 36, 30, 19, 16, 14, 11,
+ 7, 4, 3, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
+ 326, 326, 326, 326, 326, 326, 326, 326
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "cmDependsJavaLexer.in.l"
+#line 2 "cmDependsJavaLexer.in.l"
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex --prefix=cmDependsJava_yy --header-file=cmDependsJavaLexer.h -ocmDependsJavaLexer.cxx cmDependsJavaLexer.in.l
+
+Modify cmDependsJavaLexer.c:
+ - remove TABs
+ - remove "yyscanner" argument from these methods:
+ yy_fatal_error, cmDependsJava_yyalloc, cmDependsJava_yyrealloc, cmDependsJava_yyfree
+ - remove all YY_BREAK lines occurring right after return statements
+ - change while ( 1 ) to for(;;)
+
+Modify cmDependsJavaLexer.h:
+ - remove TABs
+ - remove the yy_init_globals function
+ - remove the block that includes unistd.h
+ - remove #line directives (avoids bogus warning on old Sun)
+
+*/
+
+#include "cmStandardLexer.h"
+
+#include "cmDependsJavaParserHelper.h"
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = yyextra->LexInput(buf, max_size); }
+
+/* Include the set of tokens from the parser. */
+#include "cmDependsJavaParserTokens.h"
+
+#define KEYWORD yylvalp->str = 0
+#define SYMBOL yylvalp->str = 0
+#define PRIMITIVE yylvalp->str = 0
+
+/*--------------------------------------------------------------------------*/
+
+
+#line 721 "cmDependsJavaLexer.cxx"
+
+#define INITIAL 0
+#define comment 1
+#define string 2
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* Holds the entire state of the reentrant scanner. */
+struct yyguts_t
+ {
+
+ /* User-defined. Not touched by flex. */
+ YY_EXTRA_TYPE yyextra_r;
+
+ /* The rest are the same as the globals declared in the non-reentrant scanner. */
+ FILE *yyin_r, *yyout_r;
+ size_t yy_buffer_stack_top; /**< index of top of stack. */
+ 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;
+ char *yy_c_buf_p;
+ int yy_init;
+ int yy_start;
+ int yy_did_buffer_switch_on_eof;
+ int yy_start_stack_ptr;
+ int yy_start_stack_depth;
+ int *yy_start_stack;
+ yy_state_type yy_last_accepting_state;
+ char* yy_last_accepting_cpos;
+
+ int yylineno_r;
+ int yy_flex_debug_r;
+
+ char *yytext_r;
+ int yy_more_flag;
+ int yy_more_len;
+
+ }; /* end struct yyguts_t */
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int cmDependsJava_yylex_destroy (yyscan_t yyscanner );
+
+int cmDependsJava_yyget_debug (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE cmDependsJava_yyget_extra (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *cmDependsJava_yyget_in (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *cmDependsJava_yyget_out (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+int cmDependsJava_yyget_leng (yyscan_t yyscanner );
+
+char *cmDependsJava_yyget_text (yyscan_t yyscanner );
+
+int cmDependsJava_yyget_lineno (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int cmDependsJava_yywrap (yyscan_t yyscanner );
+#else
+extern int cmDependsJava_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#ifdef __cplusplus
+static int yyinput (yyscan_t yyscanner );
+#else
+static int input (yyscan_t yyscanner );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int cmDependsJava_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int cmDependsJava_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ yy_state_type yy_current_state;
+ char *yy_cp, *yy_bp;
+ int yy_act;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+#line 88 "cmDependsJavaLexer.in.l"
+
+#line 940 "cmDependsJavaLexer.cxx"
+
+ if ( yyg->yy_init )
+ {
+ yyg->yy_init = 0;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! yyg->yy_start )
+ yyg->yy_start = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ cmDependsJava_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmDependsJava_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmDependsJava_yy_load_buffer_state(yyscanner );
+ }
+
+ for(;;) /* loops until end-of-file is reached */
+ {
+ yy_cp = yyg->yy_c_buf_p;
+
+ /* Support of yytext. */
+ *yy_cp = yyg->yy_hold_char;
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yyg->yy_start;
+yy_match:
+ do
+ {
+ 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;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 327 )
+ 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] != 414 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = yyg->yy_hold_char;
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 89 "cmDependsJavaLexer.in.l"
+{ BEGIN(comment); }
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 90 "cmDependsJavaLexer.in.l"
+{ BEGIN(INITIAL); }
+ YY_BREAK
+case 3:
+/* rule 3 can match eol */
+YY_RULE_SETUP
+#line 91 "cmDependsJavaLexer.in.l"
+{}
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 93 "cmDependsJavaLexer.in.l"
+{ BEGIN(string); }
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 94 "cmDependsJavaLexer.in.l"
+{ BEGIN(INITIAL); return jp_STRINGLITERAL; }
+case 6:
+YY_RULE_SETUP
+#line 95 "cmDependsJavaLexer.in.l"
+{}
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 97 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_ABSTRACT; }
+case 8:
+YY_RULE_SETUP
+#line 98 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_ASSERT; }
+case 9:
+YY_RULE_SETUP
+#line 99 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_BOOLEAN_TYPE; }
+case 10:
+YY_RULE_SETUP
+#line 100 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_BREAK; }
+case 11:
+YY_RULE_SETUP
+#line 101 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_BYTE_TYPE; }
+case 12:
+YY_RULE_SETUP
+#line 102 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_CASE; }
+case 13:
+YY_RULE_SETUP
+#line 103 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_CATCH; }
+case 14:
+YY_RULE_SETUP
+#line 104 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_CHAR_TYPE; }
+case 15:
+YY_RULE_SETUP
+#line 105 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_CLASS; }
+case 16:
+YY_RULE_SETUP
+#line 106 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_CONTINUE; }
+case 17:
+YY_RULE_SETUP
+#line 107 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_DEFAULT; }
+case 18:
+YY_RULE_SETUP
+#line 108 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_DO; }
+case 19:
+YY_RULE_SETUP
+#line 109 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_DOUBLE_TYPE; }
+case 20:
+YY_RULE_SETUP
+#line 110 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_ELSE; }
+case 21:
+YY_RULE_SETUP
+#line 111 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_EXTENDS; }
+case 22:
+YY_RULE_SETUP
+#line 112 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_FINAL; }
+case 23:
+YY_RULE_SETUP
+#line 113 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_FINALLY; }
+case 24:
+YY_RULE_SETUP
+#line 114 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_FLOAT_TYPE; }
+case 25:
+YY_RULE_SETUP
+#line 115 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_FOR; }
+case 26:
+YY_RULE_SETUP
+#line 116 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_IF; }
+case 27:
+YY_RULE_SETUP
+#line 117 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_IMPLEMENTS; }
+case 28:
+YY_RULE_SETUP
+#line 118 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_IMPORT; }
+case 29:
+YY_RULE_SETUP
+#line 119 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_INSTANCEOF; }
+case 30:
+YY_RULE_SETUP
+#line 120 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_INT_TYPE; }
+case 31:
+YY_RULE_SETUP
+#line 121 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_INTERFACE; }
+case 32:
+YY_RULE_SETUP
+#line 122 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_LONG_TYPE; }
+case 33:
+YY_RULE_SETUP
+#line 123 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_NATIVE; }
+case 34:
+YY_RULE_SETUP
+#line 124 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_NEW; }
+case 35:
+YY_RULE_SETUP
+#line 125 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_PACKAGE; }
+case 36:
+YY_RULE_SETUP
+#line 126 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_PRIVATE; }
+case 37:
+YY_RULE_SETUP
+#line 127 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_PROTECTED; }
+case 38:
+YY_RULE_SETUP
+#line 128 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_PUBLIC; }
+case 39:
+YY_RULE_SETUP
+#line 129 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_RETURN; }
+case 40:
+YY_RULE_SETUP
+#line 130 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_SHORT_TYPE; }
+case 41:
+YY_RULE_SETUP
+#line 131 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_STATIC; }
+case 42:
+YY_RULE_SETUP
+#line 132 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_STRICTFP; }
+case 43:
+YY_RULE_SETUP
+#line 133 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_SUPER; }
+case 44:
+YY_RULE_SETUP
+#line 134 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_SWITCH; }
+case 45:
+YY_RULE_SETUP
+#line 135 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_SYNCHRONIZED; }
+case 46:
+YY_RULE_SETUP
+#line 136 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_THIS; }
+case 47:
+YY_RULE_SETUP
+#line 137 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_THROW; }
+case 48:
+YY_RULE_SETUP
+#line 138 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_THROWS; }
+case 49:
+YY_RULE_SETUP
+#line 139 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_TRANSIENT; }
+case 50:
+YY_RULE_SETUP
+#line 140 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_TRY; }
+case 51:
+YY_RULE_SETUP
+#line 141 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_VOID; }
+case 52:
+YY_RULE_SETUP
+#line 142 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_VOLATILE; }
+case 53:
+YY_RULE_SETUP
+#line 143 "cmDependsJavaLexer.in.l"
+{ KEYWORD; return jp_WHILE; }
+case 54:
+YY_RULE_SETUP
+#line 145 "cmDependsJavaLexer.in.l"
+{ PRIMITIVE; return jp_BOOLEANLITERAL; }
+case 55:
+/* rule 55 can match eol */
+YY_RULE_SETUP
+#line 146 "cmDependsJavaLexer.in.l"
+{ PRIMITIVE; return jp_CHARACTERLITERAL; }
+case 56:
+YY_RULE_SETUP
+#line 147 "cmDependsJavaLexer.in.l"
+{ PRIMITIVE; return jp_DECIMALINTEGERLITERAL; }
+case 57:
+YY_RULE_SETUP
+#line 148 "cmDependsJavaLexer.in.l"
+{ PRIMITIVE; return jp_FLOATINGPOINTLITERAL; }
+case 58:
+YY_RULE_SETUP
+#line 149 "cmDependsJavaLexer.in.l"
+{ PRIMITIVE; return jp_HEXINTEGERLITERAL; }
+case 59:
+YY_RULE_SETUP
+#line 150 "cmDependsJavaLexer.in.l"
+{ PRIMITIVE; return jp_NULLLITERAL; }
+case 60:
+YY_RULE_SETUP
+#line 152 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_AND; }
+case 61:
+YY_RULE_SETUP
+#line 153 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_ANDAND; }
+case 62:
+YY_RULE_SETUP
+#line 154 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_ANDEQUALS; }
+case 63:
+YY_RULE_SETUP
+#line 155 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_BRACKETEND; }
+case 64:
+YY_RULE_SETUP
+#line 156 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_BRACKETSTART; }
+case 65:
+YY_RULE_SETUP
+#line 157 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_CARROT; }
+case 66:
+YY_RULE_SETUP
+#line 158 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_CARROTEQUALS; }
+case 67:
+YY_RULE_SETUP
+#line 159 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_COLON; }
+case 68:
+YY_RULE_SETUP
+#line 160 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_COMMA; }
+case 69:
+YY_RULE_SETUP
+#line 161 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_CURLYEND; }
+case 70:
+YY_RULE_SETUP
+#line 162 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_CURLYSTART; }
+case 71:
+YY_RULE_SETUP
+#line 163 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_DIVIDE; }
+case 72:
+YY_RULE_SETUP
+#line 164 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_DIVIDEEQUALS; }
+case 73:
+YY_RULE_SETUP
+#line 165 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_DOLLAR; }
+case 74:
+YY_RULE_SETUP
+#line 166 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_DOT; }
+case 75:
+YY_RULE_SETUP
+#line 167 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_EQUALS; }
+case 76:
+YY_RULE_SETUP
+#line 168 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_EQUALSEQUALS; }
+case 77:
+YY_RULE_SETUP
+#line 169 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_EXCLAMATION; }
+case 78:
+YY_RULE_SETUP
+#line 170 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_EXCLAMATIONEQUALS; }
+case 79:
+YY_RULE_SETUP
+#line 171 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_GREATER; }
+case 80:
+YY_RULE_SETUP
+#line 172 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_GTEQUALS; }
+case 81:
+YY_RULE_SETUP
+#line 173 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_GTGT; }
+case 82:
+YY_RULE_SETUP
+#line 174 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_GTGTEQUALS; }
+case 83:
+YY_RULE_SETUP
+#line 175 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_GTGTGT; }
+case 84:
+YY_RULE_SETUP
+#line 176 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_GTGTGTEQUALS; }
+case 85:
+YY_RULE_SETUP
+#line 177 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_LESLESEQUALS; }
+case 86:
+YY_RULE_SETUP
+#line 178 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_LESSTHAN; }
+case 87:
+YY_RULE_SETUP
+#line 179 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_LTEQUALS; }
+case 88:
+YY_RULE_SETUP
+#line 180 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_LTLT; }
+case 89:
+YY_RULE_SETUP
+#line 181 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_MINUS; }
+case 90:
+YY_RULE_SETUP
+#line 182 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_MINUSEQUALS; }
+case 91:
+YY_RULE_SETUP
+#line 183 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_MINUSMINUS; }
+case 92:
+YY_RULE_SETUP
+#line 184 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PAREEND; }
+case 93:
+YY_RULE_SETUP
+#line 185 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PARESTART; }
+case 94:
+YY_RULE_SETUP
+#line 186 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PERCENT; }
+case 95:
+YY_RULE_SETUP
+#line 187 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PERCENTEQUALS; }
+case 96:
+YY_RULE_SETUP
+#line 188 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PIPE; }
+case 97:
+YY_RULE_SETUP
+#line 189 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PIPEEQUALS; }
+case 98:
+YY_RULE_SETUP
+#line 190 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PIPEPIPE; }
+case 99:
+YY_RULE_SETUP
+#line 191 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PLUS; }
+case 100:
+YY_RULE_SETUP
+#line 192 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PLUSEQUALS; }
+case 101:
+YY_RULE_SETUP
+#line 193 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_PLUSPLUS; }
+case 102:
+YY_RULE_SETUP
+#line 194 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_QUESTION; }
+case 103:
+YY_RULE_SETUP
+#line 195 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_SEMICOL; }
+case 104:
+YY_RULE_SETUP
+#line 196 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_TILDE; }
+case 105:
+YY_RULE_SETUP
+#line 197 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_TIMES; }
+case 106:
+YY_RULE_SETUP
+#line 198 "cmDependsJavaLexer.in.l"
+{ SYMBOL; return jp_TIMESEQUALS; }
+case 107:
+YY_RULE_SETUP
+#line 200 "cmDependsJavaLexer.in.l"
+{
+ yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ return jp_NAME;
+}
+case 108:
+/* rule 108 can match eol */
+YY_RULE_SETUP
+#line 205 "cmDependsJavaLexer.in.l"
+{ }
+ YY_BREAK
+case 109:
+/* rule 109 can match eol */
+YY_RULE_SETUP
+#line 206 "cmDependsJavaLexer.in.l"
+{ }
+ YY_BREAK
+case 110:
+YY_RULE_SETUP
+#line 207 "cmDependsJavaLexer.in.l"
+{
+ std::cerr << "Unknown character: " << yytext[0]
+ << " (" << (int)yytext[0] << ")" << std::endl;
+ yyextra->Error("Unknown character");
+ return jp_ERROR;
+}
+case 111:
+YY_RULE_SETUP
+#line 214 "cmDependsJavaLexer.in.l"
+ECHO;
+ YY_BREAK
+#line 1590 "cmDependsJavaLexer.cxx"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(comment):
+case YY_STATE_EOF(string):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = yyg->yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * cmDependsJava_yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
+
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++yyg->yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yyg->yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yyg->yy_did_buffer_switch_on_eof = 0;
+
+ if ( cmDependsJava_yywrap(yyscanner ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p =
+ yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yyg->yy_c_buf_p =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+return 0; /* this should not happen but it quiets some compilers */
+} /* end of cmDependsJava_yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ char *source = yyg->yytext_ptr;
+ int number_to_move, i;
+ int ret_val;
+
+ if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
+
+ else
+ {
+ size_t nuto_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( nuto_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;
+
+ 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;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ cmDependsJava_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ nuto_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( nuto_read > YY_READ_BUF_SIZE )
+ nuto_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ yyg->yy_n_chars, nuto_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ if ( yyg->yy_n_chars == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ cmDependsJava_yyrestart(yyin ,yyscanner);
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ yyg->yy_n_chars += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
+{
+ yy_state_type yy_current_state;
+ char *yy_cp;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ yy_current_state = yyg->yy_start;
+
+ for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
+ {
+ YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 327 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
+{
+ int yy_is_jam;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ char *yy_cp = yyg->yy_c_buf_p;
+
+ YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 327 )
+ 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 == 326);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (yyscan_t yyscanner)
+#else
+ static int input (yyscan_t yyscanner)
+#endif
+
+{
+ int c;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+
+ if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ /* This was really a NUL. */
+ *yyg->yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ ++yyg->yy_c_buf_p;
+
+ switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ cmDependsJava_yyrestart(yyin ,yyscanner);
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( cmDependsJava_yywrap(yyscanner ) )
+ return EOF;
+
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput(yyscanner);
+#else
+ return input(yyscanner);
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
+ *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
+ yyg->yy_hold_char = *++yyg->yy_c_buf_p;
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ * @param yyscanner The scanner object.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void cmDependsJava_yyrestart (FILE * input_file , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! YY_CURRENT_BUFFER ){
+ cmDependsJava_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmDependsJava_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmDependsJava_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
+ cmDependsJava_yy_load_buffer_state(yyscanner );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ * @param yyscanner The scanner object.
+ */
+ void cmDependsJava_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * cmDependsJava_yypop_buffer_state();
+ * cmDependsJava_yypush_buffer_state(new_buffer);
+ */
+ cmDependsJava_yyensure_buffer_stack (yyscanner);
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ cmDependsJava_yy_load_buffer_state(yyscanner );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (cmDependsJava_yywrap()) processing, but the only time this flag
+ * is looked at is after cmDependsJava_yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+static void cmDependsJava_yy_load_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ yyg->yy_hold_char = *yyg->yy_c_buf_p;
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * @param yyscanner The scanner object.
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE cmDependsJava_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) cmDependsJava_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsJava_yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) cmDependsJava_yyalloc(b->yy_buf_size + 2 ,yyscanner );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsJava_yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ cmDependsJava_yy_init_buffer(b,file ,yyscanner);
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with cmDependsJava_yy_create_buffer()
+ * @param yyscanner The scanner object.
+ */
+ void cmDependsJava_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ cmDependsJava_yyfree((void *) b->yy_ch_buf ,yyscanner );
+
+ cmDependsJava_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 cmDependsJava_yyrestart() or at EOF.
+ */
+ static void cmDependsJava_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+
+{
+ int oerrno = errno;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ cmDependsJava_yy_flush_buffer(b ,yyscanner);
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then cmDependsJava_yy_init_buffer was _probably_
+ * called from cmDependsJava_yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ * @param yyscanner The scanner object.
+ */
+ void cmDependsJava_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ cmDependsJava_yy_load_buffer_state(yyscanner );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsJava_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (new_buffer == NULL)
+ return;
+
+ cmDependsJava_yyensure_buffer_stack(yyscanner);
+
+ /* This block is copied from cmDependsJava_yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ yyg->yy_buffer_stack_top++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from cmDependsJava_yy_switch_to_buffer. */
+ cmDependsJava_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsJava_yypop_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ cmDependsJava_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if (yyg->yy_buffer_stack_top > 0)
+ --yyg->yy_buffer_stack_top;
+
+ if (YY_CURRENT_BUFFER) {
+ cmDependsJava_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void cmDependsJava_yyensure_buffer_stack (yyscan_t yyscanner)
+{
+ int nuto_alloc;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (!yyg->yy_buffer_stack) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ nuto_alloc = 1;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmDependsJava_yyalloc
+ (nuto_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+
+ memset(yyg->yy_buffer_stack, 0, nuto_alloc * sizeof(struct yy_buffer_state*));
+
+ yyg->yy_buffer_stack_max = nuto_alloc;
+ yyg->yy_buffer_stack_top = 0;
+ return;
+ }
+
+ if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ nuto_alloc = yyg->yy_buffer_stack_max + grow_size;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmDependsJava_yyrealloc
+ (yyg->yy_buffer_stack,
+ nuto_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+
+ /* zero only the new slots.*/
+ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
+ yyg->yy_buffer_stack_max = nuto_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmDependsJava_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) cmDependsJava_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsJava_yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ cmDependsJava_yy_switch_to_buffer(b ,yyscanner );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to cmDependsJava_yylex() will
+ * scan from a @e copy of @a yy_str.
+ * @param yy_str a NUL-terminated string to scan
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * cmDependsJava_yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE cmDependsJava_yy_scan_string (yyconst char * yy_str , yyscan_t yyscanner)
+{
+
+ return cmDependsJava_yy_scan_bytes(yy_str,strlen(yy_str) ,yyscanner);
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to cmDependsJava_yylex() will
+ * scan from a @e copy of @a bytes.
+ * @param bytes the byte buffer to scan
+ * @param len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmDependsJava_yy_scan_bytes (yyconst char * bytes, int len , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = len + 2;
+ buf = (char *) cmDependsJava_yyalloc(n ,yyscanner );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmDependsJava_yy_scan_bytes()" );
+
+ for ( i = 0; i < len; ++i )
+ buf[i] = bytes[i];
+
+ buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = cmDependsJava_yy_scan_buffer(buf,n ,yyscanner);
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in cmDependsJava_yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yy_fatal_error (yyconst char* msg , yyscan_t)
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = yyg->yy_hold_char; \
+ yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
+ yyg->yy_hold_char = *yyg->yy_c_buf_p; \
+ *yyg->yy_c_buf_p = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the user-defined data for this scanner.
+ * @param yyscanner The scanner object.
+ */
+YY_EXTRA_TYPE cmDependsJava_yyget_extra (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyextra;
+}
+
+/** Get the current line number.
+ * @param yyscanner The scanner object.
+ */
+int cmDependsJava_yyget_lineno (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yylineno;
+}
+
+/** Get the current column number.
+ * @param yyscanner The scanner object.
+ */
+int cmDependsJava_yyget_column (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yycolumn;
+}
+
+/** Get the input stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmDependsJava_yyget_in (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyin;
+}
+
+/** Get the output stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmDependsJava_yyget_out (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyout;
+}
+
+/** Get the length of the current token.
+ * @param yyscanner The scanner object.
+ */
+int cmDependsJava_yyget_leng (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyleng;
+}
+
+/** Get the current token.
+ * @param yyscanner The scanner object.
+ */
+
+char *cmDependsJava_yyget_text (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yytext;
+}
+
+/** Set the user-defined data. This data is never touched by the scanner.
+ * @param user_defined The data to be associated with this scanner.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsJava_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyextra = user_defined ;
+}
+
+/** Set the current line number.
+ * @param line_number The line number to set.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsJava_yyset_lineno (int line_number , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* lineno is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmDependsJava_yyset_lineno called with no buffer" , yyscanner);
+
+ yylineno = line_number;
+}
+
+/** Set the current column.
+ * @param column_no The column number to set.
+ * @param yyscanner The scanner object.
+ */
+void cmDependsJava_yyset_column (int column_no , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* column is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmDependsJava_yyset_column called with no buffer" , yyscanner);
+
+ yycolumn = column_no;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ * @param yyscanner The scanner object.
+ * @see cmDependsJava_yy_switch_to_buffer
+ */
+void cmDependsJava_yyset_in (FILE * in_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyin = in_str ;
+}
+
+void cmDependsJava_yyset_out (FILE * out_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyout = out_str ;
+}
+
+int cmDependsJava_yyget_debug (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yy_flex_debug;
+}
+
+void cmDependsJava_yyset_debug (int bdebug , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yy_flex_debug = bdebug ;
+}
+
+/* Accessor methods for yylval and yylloc */
+
+static int yy_init_globals (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ /* Initialization is the same as for the non-reentrant scanner.
+ This function is called once per scanner lifetime. */
+
+ yyg->yy_buffer_stack = 0;
+ yyg->yy_buffer_stack_top = 0;
+ yyg->yy_buffer_stack_max = 0;
+ yyg->yy_c_buf_p = (char *) 0;
+ yyg->yy_init = 1;
+ yyg->yy_start = 0;
+ yyg->yy_start_stack_ptr = 0;
+ yyg->yy_start_stack_depth = 0;
+ yyg->yy_start_stack = (int *) 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ yyin = stdin;
+ yyout = stdout;
+#else
+ yyin = (FILE *) 0;
+ yyout = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * cmDependsJava_yylex_init()
+ */
+ return 0;
+}
+
+/* User-visible API */
+
+/* cmDependsJava_yylex_init is special because it creates the scanner itself, so it is
+ * the ONLY reentrant function that doesn't take the scanner as the last argument.
+ * That's why we explicitly handle the declaration, instead of using our macros.
+ */
+
+int cmDependsJava_yylex_init(yyscan_t* ptr_yy_globals)
+
+{
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) cmDependsJava_yyalloc ( sizeof( struct yyguts_t ), NULL );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ memset(*ptr_yy_globals,0,sizeof(struct yyguts_t));
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+/* cmDependsJava_yylex_destroy is for both reentrant and non-reentrant scanners. */
+int cmDependsJava_yylex_destroy (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ cmDependsJava_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ cmDependsJava_yypop_buffer_state(yyscanner);
+ }
+
+ /* Destroy the stack itself. */
+ cmDependsJava_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyg->yy_buffer_stack = NULL;
+
+ /* Destroy the start condition stack. */
+ cmDependsJava_yyfree(yyg->yy_start_stack ,yyscanner );
+ yyg->yy_start_stack = NULL;
+
+ /* Destroy the main struct (reentrant only). */
+ cmDependsJava_yyfree ( yyscanner , yyscanner );
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+{
+ int i;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+{
+ int n;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *cmDependsJava_yyalloc (yy_size_t size , yyscan_t)
+{
+ return (void *) malloc( size );
+}
+
+void *cmDependsJava_yyrealloc (void * ptr, yy_size_t size , yyscan_t)
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void cmDependsJava_yyfree (void * ptr , yyscan_t)
+{
+ free( (char *) ptr ); /* see cmDependsJava_yyrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#undef YY_NEW_FILE
+#undef YY_FLUSH_BUFFER
+#undef yy_set_bol
+#undef yy_new_buffer
+#undef yy_set_interactive
+#undef yytext_ptr
+#undef YY_DO_BEFORE_ACTION
+
+#ifdef YY_DECL_IS_OURS
+#undef YY_DECL_IS_OURS
+#undef YY_DECL
+#endif
+#line 214 "cmDependsJavaLexer.in.l"
+
+
+
diff --git a/Source/cmDependsJavaLexer.h b/Source/cmDependsJavaLexer.h
new file mode 100644
index 0000000000..61aa66de2b
--- /dev/null
+++ b/Source/cmDependsJavaLexer.h
@@ -0,0 +1,334 @@
+/*============================================================================
+ 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 cmDependsJava_yyHEADER_H
+#define cmDependsJava_yyHEADER_H 1
+#define cmDependsJava_yyIN_HEADER 1
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 31
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#if defined(__BEOS__) || defined(__HAIKU__)
+#include <unistd.h> /* prevents a conflict with a #define later on... */
+#endif
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+int cmDependsJava_yylex_init (yyscan_t* scanner);
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef unsigned int yy_size_t;
+#endif
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int 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
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+void cmDependsJava_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void cmDependsJava_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,
+ yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsJava_yy_create_buffer (FILE *file,int size ,
+ yyscan_t yyscanner );
+void cmDependsJava_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmDependsJava_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmDependsJava_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,
+ yyscan_t yyscanner );
+void cmDependsJava_yypop_buffer_state (yyscan_t yyscanner );
+
+YY_BUFFER_STATE cmDependsJava_yy_scan_buffer (char *base,yy_size_t size ,
+ yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsJava_yy_scan_string (yyconst char *yy_str ,
+ yyscan_t yyscanner );
+YY_BUFFER_STATE cmDependsJava_yy_scan_bytes (yyconst char *bytes,int len ,
+ yyscan_t yyscanner );
+
+void *cmDependsJava_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *cmDependsJava_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void cmDependsJava_yyfree (void * ,yyscan_t yyscanner );
+
+/* Begin user sect3 */
+
+#define cmDependsJava_yywrap(n) 1
+#define YY_SKIP_YYWRAP
+
+#define yytext_ptr yytext_r
+
+#ifdef YY_HEADER_EXPORT_START_CONDITIONS
+#define INITIAL 0
+#define comment 1
+#define string 2
+
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int cmDependsJava_yylex_destroy (yyscan_t yyscanner );
+
+int cmDependsJava_yyget_debug (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE cmDependsJava_yyget_extra (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_extra (YY_EXTRA_TYPE user_defined ,
+ yyscan_t yyscanner );
+
+FILE *cmDependsJava_yyget_in (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *cmDependsJava_yyget_out (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+int cmDependsJava_yyget_leng (yyscan_t yyscanner );
+
+char *cmDependsJava_yyget_text (yyscan_t yyscanner );
+
+int cmDependsJava_yyget_lineno (yyscan_t yyscanner );
+
+void cmDependsJava_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int cmDependsJava_yywrap (yyscan_t yyscanner );
+#else
+extern int cmDependsJava_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int cmDependsJava_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int cmDependsJava_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* yy_get_previous_state - get the state just before the
+ EOB char was reached */
+
+#undef YY_NEW_FILE
+#undef YY_FLUSH_BUFFER
+#undef yy_set_bol
+#undef yy_new_buffer
+#undef yy_set_interactive
+#undef yytext_ptr
+#undef YY_DO_BEFORE_ACTION
+
+#ifdef YY_DECL_IS_OURS
+#undef YY_DECL_IS_OURS
+#undef YY_DECL
+#endif
+
+#undef cmDependsJava_yyIN_HEADER
+#endif /* cmDependsJava_yyHEADER_H */
diff --git a/Source/cmDependsJavaLexer.in.l b/Source/cmDependsJavaLexer.in.l
new file mode 100644
index 0000000000..aa2f8a5875
--- /dev/null
+++ b/Source/cmDependsJavaLexer.in.l
@@ -0,0 +1,189 @@
+%{
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex --prefix=cmDependsJava_yy --header-file=cmDependsJavaLexer.h -ocmDependsJavaLexer.cxx cmDependsJavaLexer.in.l
+
+Modify cmDependsJavaLexer.c:
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - remove "yyscanner" argument from these methods:
+ yy_fatal_error, cmDependsJava_yyalloc, cmDependsJava_yyrealloc, cmDependsJava_yyfree
+ - remove all YY_BREAK lines occurring right after return statements
+ - change while ( 1 ) to for(;;)
+
+Modify cmDependsJavaLexer.h:
+ - remove TABs
+ - remove the yy_init_globals function
+ - remove the block that includes unistd.h
+ - remove #line directives (avoids bogus warning on old Sun)
+
+*/
+
+#include "cmStandardLexer.h"
+
+#include "cmDependsJavaParserHelper.h"
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = yyextra->LexInput(buf, max_size); }
+
+/* Include the set of tokens from the parser. */
+#include "cmDependsJavaParserTokens.h"
+
+#define KEYWORD yylvalp->str = 0
+#define SYMBOL yylvalp->str = 0
+#define PRIMITIVE yylvalp->str = 0
+
+/*--------------------------------------------------------------------------*/
+%}
+
+%option reentrant
+%option noyywrap
+%pointer
+
+%x comment
+%x string
+
+%%
+"/*" { BEGIN(comment); }
+<comment>"*/" { BEGIN(INITIAL); }
+<comment>.|\n {}
+
+\" { BEGIN(string); }
+<string>\" { BEGIN(INITIAL); return jp_STRINGLITERAL; }
+<string>. {}
+
+abstract { KEYWORD; return jp_ABSTRACT; }
+assert { KEYWORD; return jp_ASSERT; }
+boolean { KEYWORD; return jp_BOOLEAN_TYPE; }
+break { KEYWORD; return jp_BREAK; }
+byte { KEYWORD; return jp_BYTE_TYPE; }
+case { KEYWORD; return jp_CASE; }
+catch { KEYWORD; return jp_CATCH; }
+char { KEYWORD; return jp_CHAR_TYPE; }
+class { KEYWORD; return jp_CLASS; }
+continue { KEYWORD; return jp_CONTINUE; }
+default { KEYWORD; return jp_DEFAULT; }
+do { KEYWORD; return jp_DO; }
+double { KEYWORD; return jp_DOUBLE_TYPE; }
+else { KEYWORD; return jp_ELSE; }
+extends { KEYWORD; return jp_EXTENDS; }
+final { KEYWORD; return jp_FINAL; }
+finally { KEYWORD; return jp_FINALLY; }
+float { KEYWORD; return jp_FLOAT_TYPE; }
+for { KEYWORD; return jp_FOR; }
+if { KEYWORD; return jp_IF; }
+implements { KEYWORD; return jp_IMPLEMENTS; }
+import { KEYWORD; return jp_IMPORT; }
+instanceof { KEYWORD; return jp_INSTANCEOF; }
+int { KEYWORD; return jp_INT_TYPE; }
+interface { KEYWORD; return jp_INTERFACE; }
+long { KEYWORD; return jp_LONG_TYPE; }
+native { KEYWORD; return jp_NATIVE; }
+new { KEYWORD; return jp_NEW; }
+package { KEYWORD; return jp_PACKAGE; }
+private { KEYWORD; return jp_PRIVATE; }
+protected { KEYWORD; return jp_PROTECTED; }
+public { KEYWORD; return jp_PUBLIC; }
+return { KEYWORD; return jp_RETURN; }
+short { KEYWORD; return jp_SHORT_TYPE; }
+static { KEYWORD; return jp_STATIC; }
+strictfp { KEYWORD; return jp_STRICTFP; }
+super { KEYWORD; return jp_SUPER; }
+switch { KEYWORD; return jp_SWITCH; }
+synchronized { KEYWORD; return jp_SYNCHRONIZED; }
+this { KEYWORD; return jp_THIS; }
+throw { KEYWORD; return jp_THROW; }
+throws { KEYWORD; return jp_THROWS; }
+transient { KEYWORD; return jp_TRANSIENT; }
+try { KEYWORD; return jp_TRY; }
+void { KEYWORD; return jp_VOID; }
+volatile { KEYWORD; return jp_VOLATILE; }
+while { KEYWORD; return jp_WHILE; }
+
+(true|false) { PRIMITIVE; return jp_BOOLEANLITERAL; }
+\'([^\\]|\\.|\\u[0-9a-fA-F]*|\\[0-7]*)\' { PRIMITIVE; return jp_CHARACTERLITERAL; }
+(0|[0-9]+)[lL]? { PRIMITIVE; return jp_DECIMALINTEGERLITERAL; }
+([0-9]+\.[0-9]*|\.[0-9]+|[0-9]+)([eE][+\-]?[0-9]+)?[fFdD]? { PRIMITIVE; return jp_FLOATINGPOINTLITERAL; }
+0[xX][0-9a-fA-F]+[lL]? { PRIMITIVE; return jp_HEXINTEGERLITERAL; }
+null { PRIMITIVE; return jp_NULLLITERAL; }
+
+"&" { SYMBOL; return jp_AND; }
+"&&" { SYMBOL; return jp_ANDAND; }
+"&=" { SYMBOL; return jp_ANDEQUALS; }
+"\]" { SYMBOL; return jp_BRACKETEND; }
+"\[" { SYMBOL; return jp_BRACKETSTART; }
+"\^" { SYMBOL; return jp_CARROT; }
+"\^=" { SYMBOL; return jp_CARROTEQUALS; }
+":" { SYMBOL; return jp_COLON; }
+"," { SYMBOL; return jp_COMMA; }
+"}" { SYMBOL; return jp_CURLYEND; }
+"{" { SYMBOL; return jp_CURLYSTART; }
+"/" { SYMBOL; return jp_DIVIDE; }
+"/=" { SYMBOL; return jp_DIVIDEEQUALS; }
+"\$" { SYMBOL; return jp_DOLLAR; }
+"\." { SYMBOL; return jp_DOT; }
+"=" { SYMBOL; return jp_EQUALS; }
+"==" { SYMBOL; return jp_EQUALSEQUALS; }
+"\!" { SYMBOL; return jp_EXCLAMATION; }
+"\!=" { SYMBOL; return jp_EXCLAMATIONEQUALS; }
+">" { SYMBOL; return jp_GREATER; }
+">=" { SYMBOL; return jp_GTEQUALS; }
+">>" { SYMBOL; return jp_GTGT; }
+">>=" { SYMBOL; return jp_GTGTEQUALS; }
+">>>" { SYMBOL; return jp_GTGTGT; }
+">>>=" { SYMBOL; return jp_GTGTGTEQUALS; }
+"<<=" { SYMBOL; return jp_LESLESEQUALS; }
+"<" { SYMBOL; return jp_LESSTHAN; }
+"<=" { SYMBOL; return jp_LTEQUALS; }
+"<<" { SYMBOL; return jp_LTLT; }
+"-" { SYMBOL; return jp_MINUS; }
+"-=" { SYMBOL; return jp_MINUSEQUALS; }
+"--" { SYMBOL; return jp_MINUSMINUS; }
+"\)" { SYMBOL; return jp_PAREEND; }
+"\(" { SYMBOL; return jp_PARESTART; }
+"%" { SYMBOL; return jp_PERCENT; }
+"%=" { SYMBOL; return jp_PERCENTEQUALS; }
+"\|" { SYMBOL; return jp_PIPE; }
+"\|=" { SYMBOL; return jp_PIPEEQUALS; }
+"\|\|" { SYMBOL; return jp_PIPEPIPE; }
+"\+" { SYMBOL; return jp_PLUS; }
+"\+=" { SYMBOL; return jp_PLUSEQUALS; }
+"\+\+" { SYMBOL; return jp_PLUSPLUS; }
+"\?" { SYMBOL; return jp_QUESTION; }
+";" { SYMBOL; return jp_SEMICOL; }
+"\~" { SYMBOL; return jp_TILDE; }
+"\*" { SYMBOL; return jp_TIMES; }
+"\*=" { SYMBOL; return jp_TIMESEQUALS; }
+
+[a-z_A-Z][a-z_0-9A-Z]* {
+ yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
+ return jp_NAME;
+}
+
+\/\/.*\n { }
+[ \f\t\n\r] { }
+. {
+ std::cerr << "Unknown character: " << yytext[0]
+ << " (" << (int)yytext[0] << ")" << std::endl;
+ yyextra->Error("Unknown character");
+ return jp_ERROR;
+}
+
+%%
diff --git a/Source/cmDependsJavaParser.cxx b/Source/cmDependsJavaParser.cxx
new file mode 100644
index 0000000000..586c0debea
--- /dev/null
+++ b/Source/cmDependsJavaParser.cxx
@@ -0,0 +1,6021 @@
+/* A Bison parser, made by GNU Bison 1.875d. */
+
+/* Skeleton parser for Yacc-like parsing with Bison, Copyright (C) 1984,
+ 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* As a special exception, when this file is copied by Bison into a
+ Bison output file, you may use that output file without restriction.
+ This special exception was added by the Free Software Foundation
+ in version 1.24 of Bison. */
+
+/* Written by Richard Stallman by simplifying the original so called
+ ``semantic'' parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* turn off some warning as this is generated code */
+#if defined(_MSC_VER)
+# pragma warning ( disable : 4702 ) /* unreachable code */
+#endif
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 1
+
+/* Using locations. */
+#define YYLSP_NEEDED 0
+
+/* If NAME_PREFIX is specified substitute the variables and functions
+ names. */
+#define yyparse cmDependsJava_yyparse
+#define yylex cmDependsJava_yylex
+#define yyerror cmDependsJava_yyerror
+#define yylval cmDependsJava_yylval
+#define yychar cmDependsJava_yychar
+#define yydebug cmDependsJava_yydebug
+#define yynerrs cmDependsJava_yynerrs
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ jp_ABSTRACT = 258,
+ jp_ASSERT = 259,
+ jp_BOOLEAN_TYPE = 260,
+ jp_BREAK = 261,
+ jp_BYTE_TYPE = 262,
+ jp_CASE = 263,
+ jp_CATCH = 264,
+ jp_CHAR_TYPE = 265,
+ jp_CLASS = 266,
+ jp_CONTINUE = 267,
+ jp_DEFAULT = 268,
+ jp_DO = 269,
+ jp_DOUBLE_TYPE = 270,
+ jp_ELSE = 271,
+ jp_EXTENDS = 272,
+ jp_FINAL = 273,
+ jp_FINALLY = 274,
+ jp_FLOAT_TYPE = 275,
+ jp_FOR = 276,
+ jp_IF = 277,
+ jp_IMPLEMENTS = 278,
+ jp_IMPORT = 279,
+ jp_INSTANCEOF = 280,
+ jp_INT_TYPE = 281,
+ jp_INTERFACE = 282,
+ jp_LONG_TYPE = 283,
+ jp_NATIVE = 284,
+ jp_NEW = 285,
+ jp_PACKAGE = 286,
+ jp_PRIVATE = 287,
+ jp_PROTECTED = 288,
+ jp_PUBLIC = 289,
+ jp_RETURN = 290,
+ jp_SHORT_TYPE = 291,
+ jp_STATIC = 292,
+ jp_STRICTFP = 293,
+ jp_SUPER = 294,
+ jp_SWITCH = 295,
+ jp_SYNCHRONIZED = 296,
+ jp_THIS = 297,
+ jp_THROW = 298,
+ jp_THROWS = 299,
+ jp_TRANSIENT = 300,
+ jp_TRY = 301,
+ jp_VOID = 302,
+ jp_VOLATILE = 303,
+ jp_WHILE = 304,
+ jp_BOOLEANLITERAL = 305,
+ jp_CHARACTERLITERAL = 306,
+ jp_DECIMALINTEGERLITERAL = 307,
+ jp_FLOATINGPOINTLITERAL = 308,
+ jp_HEXINTEGERLITERAL = 309,
+ jp_NULLLITERAL = 310,
+ jp_STRINGLITERAL = 311,
+ jp_NAME = 312,
+ jp_AND = 313,
+ jp_ANDAND = 314,
+ jp_ANDEQUALS = 315,
+ jp_BRACKETEND = 316,
+ jp_BRACKETSTART = 317,
+ jp_CARROT = 318,
+ jp_CARROTEQUALS = 319,
+ jp_COLON = 320,
+ jp_COMMA = 321,
+ jp_CURLYEND = 322,
+ jp_CURLYSTART = 323,
+ jp_DIVIDE = 324,
+ jp_DIVIDEEQUALS = 325,
+ jp_DOLLAR = 326,
+ jp_DOT = 327,
+ jp_EQUALS = 328,
+ jp_EQUALSEQUALS = 329,
+ jp_EXCLAMATION = 330,
+ jp_EXCLAMATIONEQUALS = 331,
+ jp_GREATER = 332,
+ jp_GTEQUALS = 333,
+ jp_GTGT = 334,
+ jp_GTGTEQUALS = 335,
+ jp_GTGTGT = 336,
+ jp_GTGTGTEQUALS = 337,
+ jp_LESLESEQUALS = 338,
+ jp_LESSTHAN = 339,
+ jp_LTEQUALS = 340,
+ jp_LTLT = 341,
+ jp_MINUS = 342,
+ jp_MINUSEQUALS = 343,
+ jp_MINUSMINUS = 344,
+ jp_PAREEND = 345,
+ jp_PARESTART = 346,
+ jp_PERCENT = 347,
+ jp_PERCENTEQUALS = 348,
+ jp_PIPE = 349,
+ jp_PIPEEQUALS = 350,
+ jp_PIPEPIPE = 351,
+ jp_PLUS = 352,
+ jp_PLUSEQUALS = 353,
+ jp_PLUSPLUS = 354,
+ jp_QUESTION = 355,
+ jp_SEMICOL = 356,
+ jp_TILDE = 357,
+ jp_TIMES = 358,
+ jp_TIMESEQUALS = 359,
+ jp_ERROR = 360
+ };
+#endif
+#define jp_ABSTRACT 258
+#define jp_ASSERT 259
+#define jp_BOOLEAN_TYPE 260
+#define jp_BREAK 261
+#define jp_BYTE_TYPE 262
+#define jp_CASE 263
+#define jp_CATCH 264
+#define jp_CHAR_TYPE 265
+#define jp_CLASS 266
+#define jp_CONTINUE 267
+#define jp_DEFAULT 268
+#define jp_DO 269
+#define jp_DOUBLE_TYPE 270
+#define jp_ELSE 271
+#define jp_EXTENDS 272
+#define jp_FINAL 273
+#define jp_FINALLY 274
+#define jp_FLOAT_TYPE 275
+#define jp_FOR 276
+#define jp_IF 277
+#define jp_IMPLEMENTS 278
+#define jp_IMPORT 279
+#define jp_INSTANCEOF 280
+#define jp_INT_TYPE 281
+#define jp_INTERFACE 282
+#define jp_LONG_TYPE 283
+#define jp_NATIVE 284
+#define jp_NEW 285
+#define jp_PACKAGE 286
+#define jp_PRIVATE 287
+#define jp_PROTECTED 288
+#define jp_PUBLIC 289
+#define jp_RETURN 290
+#define jp_SHORT_TYPE 291
+#define jp_STATIC 292
+#define jp_STRICTFP 293
+#define jp_SUPER 294
+#define jp_SWITCH 295
+#define jp_SYNCHRONIZED 296
+#define jp_THIS 297
+#define jp_THROW 298
+#define jp_THROWS 299
+#define jp_TRANSIENT 300
+#define jp_TRY 301
+#define jp_VOID 302
+#define jp_VOLATILE 303
+#define jp_WHILE 304
+#define jp_BOOLEANLITERAL 305
+#define jp_CHARACTERLITERAL 306
+#define jp_DECIMALINTEGERLITERAL 307
+#define jp_FLOATINGPOINTLITERAL 308
+#define jp_HEXINTEGERLITERAL 309
+#define jp_NULLLITERAL 310
+#define jp_STRINGLITERAL 311
+#define jp_NAME 312
+#define jp_AND 313
+#define jp_ANDAND 314
+#define jp_ANDEQUALS 315
+#define jp_BRACKETEND 316
+#define jp_BRACKETSTART 317
+#define jp_CARROT 318
+#define jp_CARROTEQUALS 319
+#define jp_COLON 320
+#define jp_COMMA 321
+#define jp_CURLYEND 322
+#define jp_CURLYSTART 323
+#define jp_DIVIDE 324
+#define jp_DIVIDEEQUALS 325
+#define jp_DOLLAR 326
+#define jp_DOT 327
+#define jp_EQUALS 328
+#define jp_EQUALSEQUALS 329
+#define jp_EXCLAMATION 330
+#define jp_EXCLAMATIONEQUALS 331
+#define jp_GREATER 332
+#define jp_GTEQUALS 333
+#define jp_GTGT 334
+#define jp_GTGTEQUALS 335
+#define jp_GTGTGT 336
+#define jp_GTGTGTEQUALS 337
+#define jp_LESLESEQUALS 338
+#define jp_LESSTHAN 339
+#define jp_LTEQUALS 340
+#define jp_LTLT 341
+#define jp_MINUS 342
+#define jp_MINUSEQUALS 343
+#define jp_MINUSMINUS 344
+#define jp_PAREEND 345
+#define jp_PARESTART 346
+#define jp_PERCENT 347
+#define jp_PERCENTEQUALS 348
+#define jp_PIPE 349
+#define jp_PIPEEQUALS 350
+#define jp_PIPEPIPE 351
+#define jp_PLUS 352
+#define jp_PLUSEQUALS 353
+#define jp_PLUSPLUS 354
+#define jp_QUESTION 355
+#define jp_SEMICOL 356
+#define jp_TILDE 357
+#define jp_TIMES 358
+#define jp_TIMESEQUALS 359
+#define jp_ERROR 360
+
+
+
+
+/* Copy the first part of user declarations. */
+#line 1 "cmDependsJavaParser.y"
+
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run bison like this:
+
+ bison --yacc --name-prefix=cmDependsJava_yy
+ --defines=cmDependsJavaParserTokens.h -ocmDependsJavaParser.cxx
+ cmDependsJavaParser.y
+
+Modify cmDependsJavaParser.c:
+ - remove TABs
+
+*/
+
+/* Configure the parser to use a lexer object. */
+#define YYPARSE_PARAM yyscanner
+#define YYLEX_PARAM yyscanner
+#define YYERROR_VERBOSE 1
+#define cmDependsJava_yyerror(x) \
+ cmDependsJavaError(yyscanner, x)
+#define yyGetParser (cmDependsJava_yyget_extra(yyscanner))
+
+/*-------------------------------------------------------------------------*/
+#include "cmDependsJavaParserHelper.h" /* Interface to parser object. */
+#include "cmDependsJavaLexer.h" /* Interface to lexer object. */
+#include "cmDependsJavaParserTokens.h" /* Need YYSTYPE for YY_DECL. */
+
+/* Forward declare the lexer entry point. */
+YY_DECL;
+
+/* Internal utility functions. */
+static void cmDependsJavaError(yyscan_t yyscanner, const char* message);
+
+#define YYDEBUG 1
+#define YYMAXDEPTH 1000000
+
+
+#define jpCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp);
+#define jpElementStart(cnt) yyGetParser->PrepareElement(&yyval)
+#define jpStoreClass(str) \
+yyGetParser->AddClassFound(str); yyGetParser->DeallocateParserType(&(str))
+/* Disable some warnings in the generated code. */
+#ifdef __BORLANDC__
+# pragma warn -8004 /* Variable assigned a value that is not used. */
+# pragma warn -8008 /* condition always returns true */
+# pragma warn -8060 /* possibly incorrect assignment */
+# pragma warn -8066 /* unreachable code */
+#endif
+#ifdef _MSC_VER
+# pragma warning (disable: 4102) /* Unused goto label. */
+# pragma warning (disable: 4065) /* Switch statement contains default but
+ no case. */
+#endif
+
+
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
+typedef int YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+/* Copy the second part of user declarations. */
+
+
+/* Line 214 of yacc.c. */
+#line 372 "cmDependsJavaParser.cxx"
+
+#if ! defined (yyoverflow) || YYERROR_VERBOSE
+
+# ifndef YYFREE
+# define YYFREE free
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# endif
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# define YYSTACK_ALLOC alloca
+# endif
+# else
+# if defined (alloca) || defined (_ALLOCA_H)
+# define YYSTACK_ALLOC alloca
+# else
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's `empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# else
+# if defined (__STDC__) || defined (__cplusplus)
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# endif
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# endif
+#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
+
+
+#if (! defined (yyoverflow) \
+ && (! defined (__cplusplus) \
+ || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ short int yyss;
+ YYSTYPE yyvs;
+ };
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined (__GNUC__) && 1 < __GNUC__
+# define YYCOPY(To, From, Count) \
+ __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# else
+# define YYCOPY(To, From, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (To)[yyi] = (From)[yyi]; \
+ } \
+ while (0)
+# endif
+# endif
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack, Stack, yysize); \
+ Stack = &yyptr->Stack; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (0)
+
+#endif
+
+#if defined (__STDC__) || defined (__cplusplus)
+ typedef signed char yysigned_char;
+#else
+ typedef short int yysigned_char;
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 23
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 2215
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 106
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 158
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 351
+/* YYNRULES -- Number of states. */
+#define YYNSTATES 575
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 360
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const unsigned char yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 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, 32, 33, 34,
+ 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
+ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
+ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
+ 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
+ 105
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+ YYRHS. */
+static const unsigned short int yyprhs[] =
+{
+ 0, 0, 3, 5, 7, 9, 11, 13, 15, 17,
+ 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,
+ 39, 41, 43, 45, 47, 49, 51, 54, 57, 59,
+ 61, 63, 65, 68, 72, 76, 80, 84, 86, 88,
+ 92, 93, 95, 96, 99, 100, 103, 107, 109, 111,
+ 115, 121, 123, 125, 127, 129, 132, 134, 136, 138,
+ 140, 142, 144, 146, 148, 150, 152, 154, 158, 161,
+ 165, 169, 174, 175, 177, 180, 183, 185, 189, 193,
+ 194, 197, 199, 201, 203, 205, 207, 209, 214, 216,
+ 220, 222, 226, 228, 232, 234, 236, 239, 242, 246,
+ 251, 256, 257, 259, 264, 268, 269, 271, 273, 277,
+ 281, 284, 286, 290, 292, 295, 300, 306, 311, 316,
+ 317, 320, 326, 332, 336, 340, 341, 343, 346, 350,
+ 354, 355, 358, 360, 362, 364, 367, 369, 372, 374,
+ 377, 379, 382, 386, 387, 389, 392, 394, 398, 402,
+ 403, 405, 407, 410, 412, 414, 416, 419, 423, 426,
+ 428, 430, 432, 434, 436, 438, 440, 442, 444, 446,
+ 448, 450, 452, 454, 456, 458, 460, 462, 464, 466,
+ 468, 470, 472, 474, 478, 482, 485, 487, 489, 491,
+ 493, 495, 497, 499, 505, 513, 521, 527, 532, 533,
+ 535, 536, 539, 542, 544, 547, 551, 554, 560, 566,
+ 574, 584, 585, 587, 588, 590, 600, 601, 603, 605,
+ 607, 609, 611, 615, 619, 625, 629, 630, 632, 636,
+ 640, 644, 650, 654, 659, 660, 662, 664, 667, 673,
+ 676, 678, 680, 682, 684, 688, 690, 692, 694, 696,
+ 703, 704, 706, 707, 709, 711, 715, 720, 725, 730,
+ 735, 736, 738, 740, 743, 747, 750, 754, 758, 762,
+ 766, 770, 775, 782, 789, 796, 801, 806, 808, 810,
+ 814, 816, 818, 821, 824, 826, 828, 831, 834, 836,
+ 839, 842, 844, 847, 850, 852, 858, 863, 869, 871,
+ 875, 879, 883, 885, 889, 893, 895, 899, 903, 907,
+ 909, 913, 917, 921, 925, 929, 931, 935, 939, 941,
+ 945, 947, 951, 953, 957, 959, 963, 965, 969, 971,
+ 977, 979, 981, 985, 987, 989, 991, 993, 995, 997,
+ 999, 1001, 1003, 1005, 1007, 1009, 1011, 1013, 1015, 1017,
+ 1019, 1021
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const short int yyrhs[] =
+{
+ 107, 0, -1, 122, -1, 109, -1, 53, -1, 50,
+ -1, 51, -1, 56, -1, 55, -1, 52, -1, 54,
+ -1, 111, -1, 112, -1, 7, -1, 36, -1, 26,
+ -1, 28, -1, 10, -1, 20, -1, 15, -1, 5,
+ -1, 113, -1, 116, -1, 117, -1, 113, -1, 113,
+ -1, 111, 234, -1, 117, 234, -1, 118, -1, 120,
+ -1, 119, -1, 57, -1, 71, 57, -1, 117, 72,
+ 119, -1, 117, 72, 11, -1, 117, 72, 42, -1,
+ 121, 72, 11, -1, 111, -1, 47, -1, 123, 124,
+ 125, -1, -1, 126, -1, -1, 124, 127, -1, -1,
+ 125, 130, -1, 31, 117, 101, -1, 128, -1, 129,
+ -1, 24, 117, 101, -1, 24, 117, 72, 103, 101,
+ -1, 134, -1, 165, -1, 101, -1, 132, -1, 131,
+ 132, -1, 34, -1, 33, -1, 32, -1, 37, -1,
+ 3, -1, 18, -1, 29, -1, 41, -1, 45, -1,
+ 48, -1, 38, -1, 135, 11, 119, -1, 133, 139,
+ -1, 133, 137, 139, -1, 133, 136, 139, -1, 133,
+ 136, 137, 139, -1, -1, 131, -1, 17, 114, -1,
+ 23, 138, -1, 115, -1, 138, 66, 115, -1, 68,
+ 140, 67, -1, -1, 140, 141, -1, 142, -1, 158,
+ -1, 159, -1, 130, -1, 143, -1, 148, -1, 135,
+ 110, 144, 101, -1, 145, -1, 144, 66, 145, -1,
+ 146, -1, 146, 73, 147, -1, 119, -1, 146, 62,
+ 61, -1, 261, -1, 174, -1, 149, 101, -1, 149,
+ 157, -1, 149, 157, 101, -1, 135, 110, 151, 150,
+ -1, 135, 47, 151, 150, -1, -1, 155, -1, 119,
+ 91, 152, 90, -1, 151, 62, 61, -1, -1, 153,
+ -1, 154, -1, 153, 66, 154, -1, 135, 110, 146,
+ -1, 44, 156, -1, 114, -1, 156, 66, 114, -1,
+ 177, -1, 37, 177, -1, 135, 160, 150, 161, -1,
+ 135, 160, 150, 161, 101, -1, 118, 91, 152, 90,
+ -1, 68, 162, 178, 67, -1, -1, 162, 163, -1,
+ 42, 91, 228, 90, 101, -1, 39, 91, 228, 90,
+ 101, -1, 135, 27, 119, -1, 164, 166, 168, -1,
+ -1, 167, -1, 17, 115, -1, 167, 66, 115, -1,
+ 68, 169, 67, -1, -1, 169, 170, -1, 171, -1,
+ 172, -1, 134, -1, 134, 101, -1, 165, -1, 165,
+ 101, -1, 143, -1, 149, 173, -1, 101, -1, 173,
+ 101, -1, 68, 175, 67, -1, -1, 176, -1, 176,
+ 66, -1, 147, -1, 176, 66, 147, -1, 68, 178,
+ 67, -1, -1, 179, -1, 180, -1, 179, 180, -1,
+ 181, -1, 183, -1, 134, -1, 182, 101, -1, 131,
+ 110, 144, -1, 110, 144, -1, 185, -1, 187, -1,
+ 191, -1, 192, -1, 201, -1, 204, -1, 185, -1,
+ 188, -1, 193, -1, 202, -1, 207, -1, 177, -1,
+ 186, -1, 189, -1, 194, -1, 203, -1, 213, -1,
+ 215, -1, 216, -1, 218, -1, 217, -1, 219, -1,
+ 212, -1, 101, -1, 119, 65, 183, -1, 119, 65,
+ 184, -1, 190, 101, -1, 258, -1, 242, -1, 243,
+ -1, 239, -1, 240, -1, 236, -1, 226, -1, 22,
+ 91, 261, 90, 183, -1, 22, 91, 261, 90, 184,
+ 16, 183, -1, 22, 91, 261, 90, 184, 16, 184,
+ -1, 40, 91, 261, 90, 195, -1, 68, 197, 196,
+ 67, -1, -1, 199, -1, -1, 197, 198, -1, 199,
+ 179, -1, 200, -1, 199, 200, -1, 8, 262, 65,
+ -1, 13, 65, -1, 49, 91, 261, 90, 183, -1,
+ 49, 91, 261, 90, 184, -1, 14, 183, 49, 91,
+ 261, 90, 101, -1, 21, 91, 206, 101, 208, 101,
+ 205, 90, 183, -1, -1, 210, -1, -1, 209, -1,
+ 21, 91, 206, 101, 208, 101, 205, 90, 184, -1,
+ -1, 261, -1, 211, -1, 182, -1, 211, -1, 190,
+ -1, 211, 66, 190, -1, 4, 261, 101, -1, 4,
+ 261, 65, 261, 101, -1, 6, 214, 101, -1, -1,
+ 119, -1, 12, 214, 101, -1, 35, 208, 101, -1,
+ 43, 261, 101, -1, 41, 91, 261, 90, 177, -1,
+ 46, 177, 221, -1, 46, 177, 220, 223, -1, -1,
+ 221, -1, 222, -1, 221, 222, -1, 9, 91, 154,
+ 90, 177, -1, 19, 177, -1, 225, -1, 230, -1,
+ 108, -1, 42, -1, 91, 261, 90, -1, 226, -1,
+ 235, -1, 236, -1, 237, -1, 263, 114, 91, 228,
+ 90, 227, -1, -1, 139, -1, -1, 229, -1, 261,
+ -1, 229, 66, 261, -1, 263, 111, 232, 231, -1,
+ 263, 113, 232, 231, -1, 263, 111, 234, 174, -1,
+ 263, 113, 234, 174, -1, -1, 234, -1, 233, -1,
+ 232, 233, -1, 62, 261, 61, -1, 62, 61, -1,
+ 234, 62, 61, -1, 224, 72, 119, -1, 39, 72,
+ 119, -1, 42, 72, 119, -1, 224, 72, 42, -1,
+ 117, 91, 228, 90, -1, 224, 72, 119, 91, 228,
+ 90, -1, 39, 72, 119, 91, 228, 90, -1, 42,
+ 72, 119, 91, 228, 90, -1, 117, 62, 261, 61,
+ -1, 225, 62, 261, 61, -1, 224, -1, 117, -1,
+ 116, 72, 11, -1, 239, -1, 240, -1, 238, 99,
+ -1, 238, 89, -1, 242, -1, 243, -1, 97, 241,
+ -1, 87, 241, -1, 244, -1, 99, 241, -1, 89,
+ 241, -1, 238, -1, 102, 241, -1, 75, 241, -1,
+ 245, -1, 91, 111, 231, 90, 241, -1, 91, 261,
+ 90, 244, -1, 91, 117, 234, 90, 244, -1, 241,
+ -1, 246, 103, 241, -1, 246, 69, 241, -1, 246,
+ 92, 241, -1, 246, -1, 247, 97, 246, -1, 247,
+ 87, 246, -1, 247, -1, 248, 86, 247, -1, 248,
+ 79, 247, -1, 248, 81, 247, -1, 248, -1, 249,
+ 84, 248, -1, 249, 77, 248, -1, 249, 85, 248,
+ -1, 249, 78, 248, -1, 249, 25, 112, -1, 249,
+ -1, 250, 74, 249, -1, 250, 76, 249, -1, 250,
+ -1, 251, 58, 250, -1, 251, -1, 252, 63, 251,
+ -1, 252, -1, 253, 94, 252, -1, 253, -1, 254,
+ 59, 253, -1, 254, -1, 255, 96, 254, -1, 255,
+ -1, 255, 100, 261, 65, 256, -1, 256, -1, 258,
+ -1, 259, 260, 257, -1, 117, -1, 235, -1, 237,
+ -1, 73, -1, 104, -1, 70, -1, 93, -1, 98,
+ -1, 88, -1, 83, -1, 80, -1, 82, -1, 60,
+ -1, 64, -1, 95, -1, 257, -1, 261, -1, 30,
+ -1, 117, 72, 30, -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const unsigned short int yyrline[] =
+{
+ 0, 191, 191, 200, 208, 216, 224, 232, 240, 249,
+ 257, 266, 274, 283, 288, 293, 298, 303, 308, 313,
+ 318, 324, 332, 341, 351, 360, 369, 377, 387, 393,
+ 400, 407, 413, 420, 429, 439, 449, 458, 466, 475,
+ 484, 490, 499, 505, 514, 520, 529, 541, 549, 558,
+ 570, 583, 591, 599, 608, 616, 625, 625, 625, 626,
+ 627, 627, 627, 627, 627, 627, 628, 631, 641, 650,
+ 659, 668, 678, 684, 693, 702, 711, 719, 728, 737,
+ 743, 752, 760, 768, 776, 785, 793, 802, 808, 816,
+ 825, 833, 842, 851, 860, 868, 877, 885, 893, 902,
+ 911, 921, 928, 938, 948, 955, 962, 965, 971, 981,
+ 991, 1001, 1007, 1017, 1027, 1037, 1046, 1056, 1067, 1077,
+ 1084, 1094, 1103, 1113, 1122, 1132, 1138, 1148, 1157, 1167,
+ 1177, 1184, 1193, 1202, 1211, 1220, 1228, 1237, 1246, 1256,
+ 1266, 1275, 1285, 1295, 1302, 1311, 1321, 1330, 1340, 1349,
+ 1356, 1366, 1375, 1385, 1394, 1403, 1413, 1423, 1432, 1442,
+ 1451, 1460, 1469, 1478, 1487, 1497, 1506, 1515, 1524, 1533,
+ 1543, 1552, 1561, 1570, 1579, 1588, 1597, 1606, 1615, 1624,
+ 1633, 1642, 1652, 1662, 1673, 1683, 1693, 1702, 1711, 1720,
+ 1729, 1738, 1747, 1757, 1767, 1777, 1787, 1794, 1801, 1808,
+ 1818, 1825, 1835, 1845, 1854, 1864, 1873, 1883, 1890, 1897,
+ 1904, 1912, 1919, 1929, 1936, 1946, 1956, 1963, 1973, 1982,
+ 1992, 2002, 2011, 2021, 2030, 2040, 2051, 2058, 2065, 2076,
+ 2086, 2096, 2106, 2115, 2125, 2132, 2142, 2151, 2161, 2168,
+ 2178, 2187, 2197, 2206, 2212, 2221, 2230, 2239, 2248, 2258,
+ 2268, 2275, 2285, 2292, 2302, 2311, 2321, 2330, 2339, 2348,
+ 2358, 2365, 2375, 2384, 2394, 2404, 2410, 2417, 2427, 2437,
+ 2447, 2458, 2468, 2479, 2489, 2500, 2510, 2520, 2529, 2538,
+ 2547, 2556, 2566, 2576, 2586, 2595, 2604, 2613, 2622, 2632,
+ 2642, 2652, 2661, 2670, 2679, 2689, 2698, 2707, 2714, 2723,
+ 2732, 2741, 2751, 2760, 2769, 2779, 2788, 2797, 2806, 2816,
+ 2825, 2834, 2843, 2852, 2861, 2871, 2880, 2889, 2899, 2908,
+ 2918, 2927, 2937, 2946, 2956, 2965, 2975, 2984, 2994, 3003,
+ 3013, 3022, 3032, 3042, 3052, 3061, 3071, 3080, 3089, 3098,
+ 3107, 3116, 3125, 3134, 3143, 3152, 3161, 3170, 3180, 3190,
+ 3200, 3209
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE
+/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "$end", "error", "$undefined", "jp_ABSTRACT", "jp_ASSERT",
+ "jp_BOOLEAN_TYPE", "jp_BREAK", "jp_BYTE_TYPE", "jp_CASE", "jp_CATCH",
+ "jp_CHAR_TYPE", "jp_CLASS", "jp_CONTINUE", "jp_DEFAULT", "jp_DO",
+ "jp_DOUBLE_TYPE", "jp_ELSE", "jp_EXTENDS", "jp_FINAL", "jp_FINALLY",
+ "jp_FLOAT_TYPE", "jp_FOR", "jp_IF", "jp_IMPLEMENTS", "jp_IMPORT",
+ "jp_INSTANCEOF", "jp_INT_TYPE", "jp_INTERFACE", "jp_LONG_TYPE",
+ "jp_NATIVE", "jp_NEW", "jp_PACKAGE", "jp_PRIVATE", "jp_PROTECTED",
+ "jp_PUBLIC", "jp_RETURN", "jp_SHORT_TYPE", "jp_STATIC", "jp_STRICTFP",
+ "jp_SUPER", "jp_SWITCH", "jp_SYNCHRONIZED", "jp_THIS", "jp_THROW",
+ "jp_THROWS", "jp_TRANSIENT", "jp_TRY", "jp_VOID", "jp_VOLATILE",
+ "jp_WHILE", "jp_BOOLEANLITERAL", "jp_CHARACTERLITERAL",
+ "jp_DECIMALINTEGERLITERAL", "jp_FLOATINGPOINTLITERAL",
+ "jp_HEXINTEGERLITERAL", "jp_NULLLITERAL", "jp_STRINGLITERAL", "jp_NAME",
+ "jp_AND", "jp_ANDAND", "jp_ANDEQUALS", "jp_BRACKETEND",
+ "jp_BRACKETSTART", "jp_CARROT", "jp_CARROTEQUALS", "jp_COLON",
+ "jp_COMMA", "jp_CURLYEND", "jp_CURLYSTART", "jp_DIVIDE",
+ "jp_DIVIDEEQUALS", "jp_DOLLAR", "jp_DOT", "jp_EQUALS", "jp_EQUALSEQUALS",
+ "jp_EXCLAMATION", "jp_EXCLAMATIONEQUALS", "jp_GREATER", "jp_GTEQUALS",
+ "jp_GTGT", "jp_GTGTEQUALS", "jp_GTGTGT", "jp_GTGTGTEQUALS",
+ "jp_LESLESEQUALS", "jp_LESSTHAN", "jp_LTEQUALS", "jp_LTLT", "jp_MINUS",
+ "jp_MINUSEQUALS", "jp_MINUSMINUS", "jp_PAREEND", "jp_PARESTART",
+ "jp_PERCENT", "jp_PERCENTEQUALS", "jp_PIPE", "jp_PIPEEQUALS",
+ "jp_PIPEPIPE", "jp_PLUS", "jp_PLUSEQUALS", "jp_PLUSPLUS", "jp_QUESTION",
+ "jp_SEMICOL", "jp_TILDE", "jp_TIMES", "jp_TIMESEQUALS", "jp_ERROR",
+ "$accept", "Goal", "Literal", "IntegerLiteral", "Type", "PrimitiveType",
+ "ReferenceType", "ClassOrInterfaceType", "ClassType", "InterfaceType",
+ "ArrayType", "Name", "SimpleName", "Identifier", "QualifiedName",
+ "SimpleType", "CompilationUnit", "PackageDeclarationopt",
+ "ImportDeclarations", "TypeDeclarations", "PackageDeclaration",
+ "ImportDeclaration", "SingleTypeImportDeclaration",
+ "TypeImportOnDemandDeclaration", "TypeDeclaration", "Modifiers",
+ "Modifier", "ClassHeader", "ClassDeclaration", "Modifiersopt", "Super",
+ "Interfaces", "InterfaceTypeList", "ClassBody", "ClassBodyDeclarations",
+ "ClassBodyDeclaration", "ClassMemberDeclaration", "FieldDeclaration",
+ "VariableDeclarators", "VariableDeclarator", "VariableDeclaratorId",
+ "VariableInitializer", "MethodDeclaration", "MethodHeader", "Throwsopt",
+ "MethodDeclarator", "FormalParameterListopt", "FormalParameterList",
+ "FormalParameter", "Throws", "ClassTypeList", "MethodBody",
+ "StaticInitializer", "ConstructorDeclaration", "ConstructorDeclarator",
+ "ConstructorBody", "ExplicitConstructorInvocationopt",
+ "ExplicitConstructorInvocation", "InterfaceHeader",
+ "InterfaceDeclaration", "ExtendsInterfacesopt", "ExtendsInterfaces",
+ "InterfaceBody", "InterfaceMemberDeclarations",
+ "InterfaceMemberDeclaration", "ConstantDeclaration",
+ "AbstractMethodDeclaration", "Semicols", "ArrayInitializer",
+ "VariableInitializersOptional", "VariableInitializers", "Block",
+ "BlockStatementsopt", "BlockStatements", "BlockStatement",
+ "LocalVariableDeclarationStatement", "LocalVariableDeclaration",
+ "Statement", "StatementNoShortIf",
+ "StatementWithoutTrailingSubstatement", "EmptyStatement",
+ "LabeledStatement", "LabeledStatementNoShortIf", "ExpressionStatement",
+ "StatementExpression", "IfThenStatement", "IfThenElseStatement",
+ "IfThenElseStatementNoShortIf", "SwitchStatement", "SwitchBlock",
+ "SwitchLabelsopt", "SwitchBlockStatementGroups",
+ "SwitchBlockStatementGroup", "SwitchLabels", "SwitchLabel",
+ "WhileStatement", "WhileStatementNoShortIf", "DoStatement",
+ "ForStatement", "ForUpdateopt", "ForInitopt", "ForStatementNoShortIf",
+ "Expressionopt", "ForInit", "ForUpdate", "StatementExpressionList",
+ "AssertStatement", "BreakStatement", "Identifieropt",
+ "ContinueStatement", "ReturnStatement", "ThrowStatement",
+ "SynchronizedStatement", "TryStatement", "Catchesopt", "Catches",
+ "CatchClause", "Finally", "Primary", "PrimaryNoNewArray",
+ "ClassInstanceCreationExpression", "ClassBodyOpt", "ArgumentListopt",
+ "ArgumentList", "ArrayCreationExpression", "Dimsopt", "DimExprs",
+ "DimExpr", "Dims", "FieldAccess", "MethodInvocation", "ArrayAccess",
+ "PostfixExpression", "PostIncrementExpression",
+ "PostDecrementExpression", "UnaryExpression", "PreIncrementExpression",
+ "PreDecrementExpression", "UnaryExpressionNotPlusMinus",
+ "CastExpression", "MultiplicativeExpression", "AdditiveExpression",
+ "ShiftExpression", "RelationalExpression", "EqualityExpression",
+ "AndExpression", "ExclusiveOrExpression", "InclusiveOrExpression",
+ "ConditionalAndExpression", "ConditionalOrExpression",
+ "ConditionalExpression", "AssignmentExpression", "Assignment",
+ "LeftHandSide", "AssignmentOperator", "Expression", "ConstantExpression",
+ "New", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+ token YYLEX-NUM. */
+static const unsigned short int 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, 287, 288, 289, 290, 291, 292, 293, 294,
+ 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
+ 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
+ 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
+ 325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
+ 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
+ 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
+ 355, 356, 357, 358, 359, 360
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const unsigned short int yyr1[] =
+{
+ 0, 106, 107, 108, 108, 108, 108, 108, 108, 109,
+ 109, 110, 110, 111, 111, 111, 111, 111, 111, 111,
+ 111, 112, 112, 113, 114, 115, 116, 116, 117, 117,
+ 118, 119, 119, 120, 120, 120, 120, 121, 121, 122,
+ 123, 123, 124, 124, 125, 125, 126, 127, 127, 128,
+ 129, 130, 130, 130, 131, 131, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 132, 133, 134, 134,
+ 134, 134, 135, 135, 136, 137, 138, 138, 139, 140,
+ 140, 141, 141, 141, 141, 142, 142, 143, 144, 144,
+ 145, 145, 146, 146, 147, 147, 148, 148, 148, 149,
+ 149, 150, 150, 151, 151, 152, 152, 153, 153, 154,
+ 155, 156, 156, 157, 158, 159, 159, 160, 161, 162,
+ 162, 163, 163, 164, 165, 166, 166, 167, 167, 168,
+ 169, 169, 170, 170, 170, 170, 170, 170, 171, 172,
+ 173, 173, 174, 175, 175, 175, 176, 176, 177, 178,
+ 178, 179, 179, 180, 180, 180, 181, 182, 182, 183,
+ 183, 183, 183, 183, 183, 184, 184, 184, 184, 184,
+ 185, 185, 185, 185, 185, 185, 185, 185, 185, 185,
+ 185, 185, 186, 187, 188, 189, 190, 190, 190, 190,
+ 190, 190, 190, 191, 192, 193, 194, 195, 196, 196,
+ 197, 197, 198, 199, 199, 200, 200, 201, 202, 203,
+ 204, 205, 205, 206, 206, 207, 208, 208, 209, 209,
+ 210, 211, 211, 212, 212, 213, 214, 214, 215, 216,
+ 217, 218, 219, 219, 220, 220, 221, 221, 222, 223,
+ 224, 224, 225, 225, 225, 225, 225, 225, 225, 226,
+ 227, 227, 228, 228, 229, 229, 230, 230, 230, 230,
+ 231, 231, 232, 232, 233, 234, 234, 235, 235, 235,
+ 235, 236, 236, 236, 236, 237, 237, 238, 238, 238,
+ 238, 238, 239, 240, 241, 241, 241, 241, 241, 242,
+ 243, 244, 244, 244, 244, 245, 245, 245, 246, 246,
+ 246, 246, 247, 247, 247, 248, 248, 248, 248, 249,
+ 249, 249, 249, 249, 249, 250, 250, 250, 251, 251,
+ 252, 252, 253, 253, 254, 254, 255, 255, 256, 256,
+ 257, 257, 258, 259, 259, 259, 260, 260, 260, 260,
+ 260, 260, 260, 260, 260, 260, 260, 260, 261, 262,
+ 263, 263
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
+static const unsigned char yyr2[] =
+{
+ 0, 2, 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, 2, 1, 1,
+ 1, 1, 2, 3, 3, 3, 3, 1, 1, 3,
+ 0, 1, 0, 2, 0, 2, 3, 1, 1, 3,
+ 5, 1, 1, 1, 1, 2, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 3, 2, 3,
+ 3, 4, 0, 1, 2, 2, 1, 3, 3, 0,
+ 2, 1, 1, 1, 1, 1, 1, 4, 1, 3,
+ 1, 3, 1, 3, 1, 1, 2, 2, 3, 4,
+ 4, 0, 1, 4, 3, 0, 1, 1, 3, 3,
+ 2, 1, 3, 1, 2, 4, 5, 4, 4, 0,
+ 2, 5, 5, 3, 3, 0, 1, 2, 3, 3,
+ 0, 2, 1, 1, 1, 2, 1, 2, 1, 2,
+ 1, 2, 3, 0, 1, 2, 1, 3, 3, 0,
+ 1, 1, 2, 1, 1, 1, 2, 3, 2, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 3, 3, 2, 1, 1, 1, 1,
+ 1, 1, 1, 5, 7, 7, 5, 4, 0, 1,
+ 0, 2, 2, 1, 2, 3, 2, 5, 5, 7,
+ 9, 0, 1, 0, 1, 9, 0, 1, 1, 1,
+ 1, 1, 3, 3, 5, 3, 0, 1, 3, 3,
+ 3, 5, 3, 4, 0, 1, 1, 2, 5, 2,
+ 1, 1, 1, 1, 3, 1, 1, 1, 1, 6,
+ 0, 1, 0, 1, 1, 3, 4, 4, 4, 4,
+ 0, 1, 1, 2, 3, 2, 3, 3, 3, 3,
+ 3, 4, 6, 6, 6, 4, 4, 1, 1, 3,
+ 1, 1, 2, 2, 1, 1, 2, 2, 1, 2,
+ 2, 1, 2, 2, 1, 5, 4, 5, 1, 3,
+ 3, 3, 1, 3, 3, 1, 3, 3, 3, 1,
+ 3, 3, 3, 3, 3, 1, 3, 3, 1, 3,
+ 1, 3, 1, 3, 1, 3, 1, 3, 1, 5,
+ 1, 1, 3, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 3
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+ STATE-NUM when YYTABLE doesn't specify something else to do. Zero
+ means the default is an error. */
+static const unsigned short int yydefact[] =
+{
+ 40, 0, 0, 2, 42, 41, 20, 13, 17, 19,
+ 18, 15, 16, 14, 38, 31, 0, 37, 0, 28,
+ 30, 29, 0, 1, 44, 32, 0, 46, 0, 0,
+ 72, 43, 47, 48, 34, 35, 33, 36, 0, 60,
+ 61, 62, 58, 57, 56, 59, 66, 63, 64, 65,
+ 53, 45, 73, 54, 0, 51, 0, 125, 52, 0,
+ 49, 55, 0, 0, 79, 0, 0, 68, 0, 0,
+ 0, 0, 126, 0, 24, 74, 23, 25, 76, 75,
+ 72, 0, 70, 69, 67, 123, 127, 130, 124, 0,
+ 50, 0, 59, 78, 84, 0, 80, 81, 85, 86,
+ 0, 82, 83, 71, 72, 128, 77, 72, 114, 38,
+ 0, 11, 12, 21, 22, 23, 28, 101, 96, 97,
+ 113, 129, 134, 0, 138, 0, 136, 131, 132, 133,
+ 0, 226, 226, 0, 0, 0, 350, 216, 0, 0,
+ 63, 243, 0, 0, 0, 5, 6, 9, 4, 10,
+ 8, 7, 0, 0, 0, 182, 242, 3, 0, 22,
+ 333, 30, 73, 155, 0, 170, 0, 72, 151, 153,
+ 0, 154, 159, 171, 160, 172, 0, 161, 162, 173,
+ 163, 174, 164, 181, 175, 176, 177, 179, 178, 180,
+ 277, 240, 245, 241, 246, 247, 248, 0, 189, 190,
+ 187, 188, 186, 0, 0, 0, 101, 92, 0, 88,
+ 90, 101, 0, 26, 27, 72, 0, 0, 102, 98,
+ 135, 140, 139, 137, 0, 0, 0, 0, 0, 37,
+ 0, 278, 245, 247, 291, 280, 281, 298, 284, 285,
+ 288, 294, 302, 305, 309, 315, 318, 320, 322, 324,
+ 326, 328, 330, 348, 331, 0, 227, 0, 0, 0,
+ 0, 213, 0, 0, 217, 0, 0, 0, 0, 0,
+ 234, 0, 278, 246, 248, 290, 0, 289, 92, 158,
+ 0, 0, 0, 252, 0, 0, 148, 152, 156, 185,
+ 0, 0, 283, 282, 345, 346, 338, 336, 343, 344,
+ 342, 341, 339, 347, 340, 337, 0, 37, 24, 0,
+ 72, 0, 100, 0, 87, 0, 0, 99, 265, 0,
+ 0, 0, 106, 107, 111, 110, 119, 115, 141, 293,
+ 287, 37, 278, 0, 286, 292, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 223, 225,
+ 228, 0, 0, 219, 221, 0, 214, 218, 0, 229,
+ 268, 0, 0, 269, 230, 0, 0, 232, 236, 0,
+ 244, 279, 0, 351, 0, 253, 254, 183, 157, 270,
+ 267, 0, 332, 0, 260, 262, 0, 260, 0, 252,
+ 0, 104, 89, 93, 143, 91, 95, 94, 266, 0,
+ 117, 72, 0, 72, 116, 0, 26, 27, 244, 300,
+ 301, 299, 304, 303, 307, 308, 306, 314, 311, 313,
+ 310, 312, 316, 317, 319, 321, 323, 325, 327, 0,
+ 0, 0, 216, 0, 0, 252, 0, 0, 252, 72,
+ 0, 233, 237, 0, 275, 271, 0, 252, 276, 0,
+ 256, 263, 261, 258, 257, 259, 0, 103, 146, 0,
+ 144, 109, 108, 112, 0, 243, 120, 0, 0, 0,
+ 296, 0, 224, 0, 0, 222, 0, 0, 0, 30,
+ 193, 0, 159, 166, 167, 168, 169, 0, 200, 196,
+ 231, 0, 0, 239, 207, 255, 0, 264, 250, 142,
+ 145, 252, 252, 118, 295, 297, 329, 0, 211, 213,
+ 0, 0, 0, 0, 273, 198, 274, 0, 272, 251,
+ 249, 147, 0, 0, 209, 0, 212, 220, 0, 0,
+ 0, 184, 194, 0, 0, 0, 201, 72, 203, 238,
+ 0, 0, 0, 216, 0, 0, 349, 0, 206, 197,
+ 202, 204, 122, 121, 210, 0, 0, 208, 205, 211,
+ 0, 0, 195, 0, 215
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const short int yydefgoto[] =
+{
+ -1, 2, 156, 157, 158, 229, 112, 113, 75, 78,
+ 230, 231, 19, 20, 21, 22, 3, 4, 24, 30,
+ 5, 31, 32, 33, 51, 52, 53, 54, 163, 164,
+ 65, 66, 79, 67, 80, 96, 97, 98, 208, 209,
+ 210, 405, 99, 100, 217, 206, 321, 322, 323, 218,
+ 325, 119, 101, 102, 117, 327, 413, 476, 57, 58,
+ 71, 72, 88, 104, 127, 128, 129, 222, 406, 469,
+ 470, 165, 166, 167, 168, 169, 170, 171, 491, 172,
+ 173, 174, 493, 175, 176, 177, 178, 494, 179, 499,
+ 545, 525, 546, 547, 548, 180, 495, 181, 182, 535,
+ 365, 496, 263, 366, 536, 367, 183, 184, 257, 185,
+ 186, 187, 188, 189, 376, 377, 378, 451, 190, 191,
+ 232, 530, 384, 385, 193, 415, 394, 395, 214, 194,
+ 233, 196, 234, 235, 236, 237, 238, 239, 240, 241,
+ 242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
+ 252, 253, 254, 203, 306, 386, 557, 204
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+#define YYPACT_NINF -503
+static const short int yypact[] =
+{
+ 159, 1039, 236, -503, -503, -503, -503, -503, -503, -503,
+ -503, -503, -503, -503, -503, -503, 186, -503, 56, -503,
+ -503, -503, 178, -503, 35, -503, 21, -503, 248, 1039,
+ 273, -503, -503, -503, -503, -503, -503, -503, 78, -503,
+ -503, -503, -503, -503, -503, -503, -503, -503, -503, -503,
+ -503, -503, 2088, -503, 32, -503, 16, 245, -503, 28,
+ -503, -503, 1039, 1039, -503, 80, 206, -503, 129, 129,
+ 1039, 221, 228, 194, -503, -503, 225, -503, -503, 234,
+ 164, 206, -503, -503, -503, -503, -503, -503, -503, 1039,
+ -503, 1039, 233, -503, -503, 739, -503, -503, -503, -503,
+ -49, -503, -503, -503, 1116, -503, -503, 1276, -503, 129,
+ 129, 40, -503, -503, -503, 122, 212, 265, -503, 215,
+ -503, -503, 219, 739, -503, 222, 224, -503, -503, -503,
+ 1820, 129, 129, 1627, 237, 238, -503, 1820, 241, 239,
+ 242, 283, 1820, 233, 266, -503, -503, -503, -503, -503,
+ -503, -503, 1820, 1820, 1820, -503, -503, -503, 129, 284,
+ 476, 293, 2067, -503, 349, -503, 296, 1366, -503, -503,
+ 264, -503, -503, -503, -503, -503, 268, -503, -503, -503,
+ -503, -503, -503, -503, -503, -503, -503, -503, -503, -503,
+ 294, 305, 72, -503, 2070, 88, 2084, 121, 130, 148,
+ -503, -503, -503, 2111, 1039, 281, 133, 281, -25, -503,
+ 126, 133, 314, 315, 315, 921, 1039, 308, -503, -503,
+ -503, -503, 277, -503, 1820, 1820, 1820, 1820, 1820, 317,
+ 284, 545, -503, -503, 121, -503, -503, -503, -503, -503,
+ -503, -503, 73, 124, 163, 59, 196, 323, 319, 290,
+ 324, 18, -503, -503, -503, -30, -503, 285, 286, 242,
+ 342, 1941, 1820, 291, -503, 129, 1820, 1820, 129, 292,
+ 385, 1820, 96, -503, -503, -503, 310, -503, -503, 329,
+ 387, 1085, 3, 1820, 1627, 129, -503, -503, -503, -503,
+ 175, 1820, -503, -503, -503, -503, -503, -503, -503, -503,
+ -503, -503, -503, -503, -503, -503, 1820, 339, 339, 311,
+ 921, 343, -503, 129, -503, 344, 1766, -503, -503, 346,
+ 1039, 313, 347, -503, -503, 353, -503, 307, -503, -503,
+ -503, 6, 545, 326, -503, -503, 1820, 1820, 1820, 1820,
+ 1820, 1820, 1820, 1820, 1039, 1820, 1820, 1820, 1820, 1820,
+ 1820, 1820, 1820, 1820, 1820, 1820, 1820, 1820, -503, -503,
+ -503, 330, 2067, -503, -503, 327, -503, 354, 334, -503,
+ 345, 335, 340, 348, -503, 351, 416, 232, -503, 356,
+ -503, -503, 376, -503, 357, 377, -503, -503, 329, -503,
+ 358, 390, -503, 1085, 339, -503, 154, 339, 154, 1820,
+ 362, -503, -503, -503, 1766, -503, -503, -503, -503, 129,
+ -503, 2088, 1039, 1456, -503, 363, 70, 93, 1874, -503,
+ -503, -503, 73, 73, 124, 124, 124, -503, 163, 163,
+ 163, 163, 59, 59, 196, 323, 319, 290, 324, 383,
+ 360, 1820, 1820, 1995, 1699, 1820, 386, 233, 1820, 2088,
+ 233, -503, -503, 1627, -503, -503, 1820, 1820, -503, 394,
+ -503, -503, 315, -503, -503, -503, 369, -503, -503, 396,
+ 404, 410, -503, -503, 26, 113, -503, 407, 1820, 1874,
+ -503, 1820, -503, 391, 374, -503, 393, 395, 397, 411,
+ -503, 466, 471, -503, -503, -503, -503, 399, -503, -503,
+ -503, 400, 401, -503, -503, -503, 402, -503, 206, -503,
+ 1766, 1820, 1820, -503, -503, -503, -503, 403, 1995, 1941,
+ 1820, 1820, 1699, 1627, -503, 34, -503, 233, -503, -503,
+ -503, -503, 405, 412, -503, 413, -503, 354, 406, 418,
+ 421, -503, -503, 1820, 429, 430, -503, 1186, -503, -503,
+ 419, 422, 1627, 1820, 1699, 1699, -503, 447, -503, -503,
+ 1555, -503, -503, -503, -503, 423, 497, -503, -503, 1995,
+ 1699, 432, -503, 1699, -503
+};
+
+/* YYPGOTO[NTERM-NUM]. */
+static const short int yypgoto[] =
+{
+ -503, -503, -503, -503, -85, 2, 181, -41, -198, -45,
+ -87, -1, 431, 14, -503, -503, -503, -503, -503, -503,
+ -503, -503, -503, -503, 448, -81, -47, -503, 7, -23,
+ -503, 462, -503, -64, -503, -503, -503, 425, -146, 217,
+ 123, -391, -503, 427, -101, 424, 230, -503, -360, -503,
+ -503, -503, -503, -503, -503, -503, -503, -503, -503, 439,
+ -503, -503, -503, -503, -503, -503, -503, -503, -110, -503,
+ -503, -77, 138, -12, -163, -503, -250, -13, -421, -414,
+ -503, -503, -503, -503, -252, -503, -503, -503, -503, -503,
+ -503, -503, -503, -503, 5, -503, -503, -503, -503, -16,
+ 36, -503, -418, -503, -503, -502, -503, -503, 440, -503,
+ -503, -503, -503, -503, -503, -503, 179, -503, -503, -503,
+ -54, -503, -341, -503, -503, -149, 255, -136, 102, 652,
+ 101, 688, 145, 157, 201, -98, 289, 338, -384, -503,
+ -59, -58, -92, -57, 213, 226, 218, 223, 227, -503,
+ 95, 274, 350, -503, -503, 660, -503, -503
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule which
+ number is the opposite. If zero, do what YYDEFACT says.
+ If YYTABLE_NINF, syntax error. */
+#define YYTABLE_NINF -336
+static const short int yytable[] =
+{
+ 18, 82, 83, 17, 287, 61, 309, 56, 114, 364,
+ 110, 363, 279, 468, 34, 108, 537, 103, 324, 107,
+ 159, 74, 77, 120, 484, 86, 162, 68, 38, 77,
+ 492, 17, 34, 383, 480, 357, 114, 55, 110, 34,
+ 36, 313, 543, 69, 105, 35, 106, 544, 77, 62,
+ 77, 472, 118, 192, 275, 63, 277, 95, 466, 29,
+ 15, 76, 76, 35, 17, 17, 270, 537, 212, 76,
+ 35, 358, 17, 36, 16, 114, 314, 285, 15, 192,
+ 159, 123, 84, 85, 344, 15, 162, 55, 76, 502,
+ 76, 17, 16, 17, 115, 515, -260, 111, 265, 16,
+ 64, 541, 212, 63, 497, 312, 160, 501, 492, 111,
+ 317, 122, -37, 192, 355, 61, 506, 511, 356, 531,
+ 260, 161, 115, 205, 207, 111, 329, 330, 26, 334,
+ 335, 73, 319, 566, 567, 565, 345, 346, -192, 388,
+ 492, 492, 336, 347, 348, 256, 256, 161, 64, 572,
+ 59, 272, 574, 272, -191, 319, 492, 27, 281, 492,
+ -261, 115, -192, 308, 111, 337, 160, 39, 282, 111,
+ 532, 533, 278, -192, 159, 74, 338, 216, -191, 60,
+ 362, 161, 40, 479, 212, 268, 15, 283, 315, -191,
+ 1, 485, 320, 41, 26, 311, 42, 43, 44, 316,
+ 16, 92, 46, 76, 512, 47, 307, 192, 195, 48,
+ 292, 339, 49, 213, 473, 76, 319, 389, 17, -280,
+ 293, 340, 404, 272, 272, 332, 272, 272, 331, -280,
+ 192, 93, 15, 114, 195, 409, 23, -281, 419, 420,
+ 421, 375, 341, 25, 342, 460, 16, -281, 464, 343,
+ 28, -235, 197, 428, 429, 430, 431, 114, 461, 37,
+ 160, 461, 70, 111, 198, 50, 364, 364, 195, 363,
+ 349, 387, 350, -39, 64, 114, 39, 285, 197, 370,
+ 422, 423, 373, 424, 425, 426, 463, 320, 465, 87,
+ 198, 40, 432, 433, 89, 90, 36, 26, 161, 278,
+ 91, 107, 41, 215, 390, 42, 43, 44, 199, 216,
+ 45, 46, 197, 265, 47, 61, 219, 364, 48, 115,
+ 220, 49, 111, 221, 198, 223, 159, 278, 261, 262,
+ 266, 213, 162, 267, 199, 272, 272, 272, 272, 272,
+ 272, 272, 272, 115, 272, 272, 272, 272, 272, 272,
+ 272, 272, 272, 272, 272, 268, 280, 271, 284, 192,
+ 68, 115, 195, 286, 111, 288, 290, 291, 199, 289,
+ 500, 74, 310, 503, 50, 318, 326, 319, 328, 212,
+ 514, 351, 352, 354, 353, 195, 359, 360, 320, 192,
+ 192, 361, 369, 374, 375, 313, 200, 287, 381, 192,
+ 380, 393, 399, 410, 401, 403, 197, 408, 414, 396,
+ 398, 76, 160, 411, 17, 111, 418, 272, 198, 412,
+ 443, 441, 200, 278, 444, 446, 320, 161, 442, 197,
+ 447, 490, 159, 416, 417, 450, 445, 454, 362, 448,
+ 504, 198, 449, 456, 529, 201, 453, 455, 481, 457,
+ 549, 458, 467, 478, 498, 507, 200, 202, 489, 508,
+ 159, 482, 199, 509, 192, 192, 162, 161, 192, 192,
+ 510, 201, 315, 159, 513, 518, 522, 272, 272, 162,
+ 272, 517, 523, 202, 519, 199, 520, -165, 521, 524,
+ 526, 527, 528, 192, 558, 550, 462, 559, 192, 462,
+ 192, 192, 551, 552, 534, 201, 192, 553, 554, 387,
+ 542, 555, 568, 570, 195, 192, 192, 202, 160, 192,
+ 562, 111, 573, 563, 569, 427, 116, 81, 94, 124,
+ 402, 125, 471, -23, 211, 560, 489, 161, 281, 564,
+ 400, 490, 504, 126, 195, 195, 160, -23, 282, 111,
+ 200, 477, 561, 571, 195, 538, 452, 542, 197, 160,
+ 564, 161, 111, 397, 434, -278, 161, 283, 489, 489,
+ 198, 436, 258, 200, 161, -278, 516, 437, 435, 0,
+ 392, 0, 438, 0, 489, 0, 0, 489, 197, 197,
+ 0, 0, 0, 0, 0, 0, 0, 0, 197, 201,
+ 198, 198, 0, 0, 0, -333, 0, 281, 0, -333,
+ 198, 202, 0, 0, 199, -333, 0, 282, -333, 195,
+ 195, 0, 201, 195, 195, -333, 0, -333, -333, 0,
+ 0, 0, 0, -333, 202, 0, 283, 0, -333, 0,
+ -333, 0, 0, -333, 199, 199, 0, 0, 195, -333,
+ 0, 0, 0, 195, 199, 195, 195, 0, 0, 0,
+ 0, 195, 0, 197, 197, 0, 0, 197, 197, 0,
+ 195, 195, 0, 0, 195, 198, 198, 0, 0, 198,
+ 198, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 197, 0, 0, 0, 0, 197, 0, 197,
+ 197, 0, 200, 0, 198, 197, 0, 0, 0, 198,
+ 0, 198, 198, 0, 197, 197, 0, 198, 197, 199,
+ 199, 0, 0, 199, 199, 0, 198, 198, 0, 0,
+ 198, 0, 200, 200, 0, 0, 0, 0, 0, 0,
+ 0, 0, 200, 0, 6, 0, 7, 0, 199, 8,
+ 68, 201, 0, 199, 9, 199, 199, 0, 0, 10,
+ 0, 199, 0, 202, 0, 11, 69, 12, 0, 0,
+ 199, 199, 0, 0, 199, 13, 0, 0, 0, 0,
+ 0, 201, 201, 0, 0, 0, 109, 0, 0, 0,
+ 255, 201, 0, 202, 202, 0, 15, 264, 0, 0,
+ 0, 0, 269, 202, 273, 0, 273, 200, 200, 0,
+ 16, 200, 200, 276, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 200, 0, 0, 0,
+ 274, 200, 274, 200, 200, 0, 0, 0, 0, 200,
+ 0, 0, 0, 0, 0, 0, 201, 201, 200, 200,
+ 201, 201, 200, 0, 0, 0, 0, 0, 202, 202,
+ 0, 0, 202, 202, 0, 0, 273, 273, 0, 273,
+ 273, 0, 0, 0, 0, 201, 333, 0, 0, 0,
+ 201, 0, 201, 201, 0, 0, 0, 202, 201, 0,
+ 0, 0, 202, 0, 202, 202, 0, 201, 201, 0,
+ 202, 201, 274, 274, 0, 274, 274, 0, 0, 202,
+ 202, 0, 368, 202, 39, 0, 371, 372, 0, 0,
+ 0, 379, 0, 0, 0, 0, 0, 0, 0, 40,
+ 0, 382, 0, 0, 0, 0, 0, 0, 0, 0,
+ 41, 391, 0, 42, 43, 44, 0, 0, 45, 46,
+ 0, 0, 47, 0, 0, 0, 48, 0, 0, 49,
+ 0, 0, 0, 0, 0, 0, 407, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 273, 273,
+ 273, 273, 273, 273, 273, 273, 0, 273, 273, 273,
+ 273, 273, 273, 273, 273, 273, 273, 273, 0, 0,
+ 0, -105, 0, 0, 0, 0, 439, 440, 0, 0,
+ 0, 0, 0, 0, 274, 274, 274, 274, 274, 274,
+ 274, 274, 0, 274, 274, 274, 274, 274, 274, 274,
+ 274, 274, 274, 274, 6, 0, 7, 0, 0, 8,
+ 0, 0, 0, 459, 9, 0, 0, 0, 0, 10,
+ 0, 0, 0, 0, 407, 11, 0, 12, 0, 0,
+ 273, 0, 0, 0, 0, 13, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 14, 0, 0, 0,
+ 6, 0, 7, 0, 0, 8, 15, 0, 0, 0,
+ 9, 483, 264, 0, 0, 10, 274, 0, 0, 0,
+ 16, 11, 0, 12, 0, 136, 505, 0, 0, 39,
+ 0, 13, 0, 0, 138, 0, 0, 141, 0, 0,
+ 273, 273, 14, 273, 40, 145, 146, 147, 148, 149,
+ 150, 151, 15, 0, 0, 41, 318, 0, 42, 43,
+ 44, 0, 0, 45, 46, 0, 16, 47, 0, 0,
+ 224, 48, 0, 0, 49, 0, 274, 274, 0, 274,
+ 407, 0, 225, 0, 152, 0, 226, 0, 0, 0,
+ 539, 540, 227, 121, 154, 0, 0, 228, 0, 39,
+ 130, 6, 131, 7, 543, 0, 8, 0, 132, 544,
+ 133, 9, 0, 556, 40, 0, 10, 134, 135, 0,
+ 0, 0, 11, 264, 12, 41, 136, 0, 42, 43,
+ 44, 137, 13, 45, 46, 138, 139, 140, 141, 142,
+ 0, 48, 143, 14, 49, 144, 145, 146, 147, 148,
+ 149, 150, 151, 15, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -199, 107, 0, 0, 16, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 152, 0, 153, 0, 39,
+ 130, 6, 131, 7, 0, 154, 8, 155, 132, 0,
+ 133, 9, 0, 0, 40, 0, 10, 134, 135, 0,
+ 0, 0, 11, 0, 12, 41, 136, 0, 42, 43,
+ 44, 137, 13, 45, 46, 138, 139, 140, 141, 142,
+ 0, 48, 143, 14, 49, 144, 145, 146, 147, 148,
+ 149, 150, 151, 15, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -149, 107, 0, 0, 16, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 152, 0, 153, 0, 39,
+ 130, 6, 131, 7, 0, 154, 8, 155, 132, 0,
+ 133, 9, 0, 0, 40, 0, 10, 134, 135, 0,
+ 0, 0, 11, 0, 12, 41, 136, 0, 42, 43,
+ 44, 137, 13, 45, 46, 138, 139, 140, 141, 142,
+ 0, 48, 143, 14, 49, 144, 145, 146, 147, 148,
+ 149, 150, 151, 15, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -150, 107, 0, 0, 16, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 152, 0, 153, 0, 39,
+ 130, 6, 131, 7, 0, 154, 8, 155, 132, 0,
+ 133, 9, 0, 0, 40, 0, 10, 134, 135, 0,
+ 0, 0, 11, 0, 12, 41, 136, 0, 42, 43,
+ 44, 137, 13, 45, 46, 474, 139, 140, 475, 142,
+ 0, 48, 143, 14, 49, 144, 145, 146, 147, 148,
+ 149, 150, 151, 15, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -149, 107, 0, 0, 16, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 152, 0, 153, 0, 0,
+ 0, 0, 0, 0, 0, 154, 0, 155, 39, 130,
+ 6, 131, 7, 0, 0, 8, -72, 132, 0, 133,
+ 9, 0, 0, 40, 0, 10, 134, 135, 0, 0,
+ 0, 11, 0, 12, 41, 136, 0, 42, 43, 44,
+ 137, 13, 45, 46, 138, 139, 140, 141, 142, 0,
+ 48, 143, 14, 49, 144, 145, 146, 147, 148, 149,
+ 150, 151, 15, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 107, 0, 0, 16, 0, 0, 0,
+ 0, 130, 6, 131, 7, 0, 0, 8, 0, 132,
+ 0, 133, 9, 0, 152, 0, 153, 10, 134, 135,
+ 0, 0, 0, 11, 154, 12, 155, 136, 0, 0,
+ 0, 0, 137, 13, 0, 0, 138, 139, 259, 141,
+ 142, 0, 0, 143, 14, 0, 144, 145, 146, 147,
+ 148, 149, 150, 151, 15, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 107, 0, 0, 16, 0,
+ 0, 0, 0, 130, 6, 131, 7, 0, 0, 8,
+ 0, 132, 0, 133, 9, 0, 152, 0, 153, 10,
+ 486, 487, 0, 0, 0, 11, 154, 12, 155, 136,
+ 0, 0, 0, 0, 137, 13, 0, 0, 138, 139,
+ 259, 141, 142, 0, 0, 143, 14, 0, 488, 145,
+ 146, 147, 148, 149, 150, 151, 15, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 107, 0, 0,
+ 16, 6, 0, 7, 0, 0, 8, 0, 0, 0,
+ 0, 9, 0, 0, 0, 0, 10, 0, 152, 0,
+ 153, 0, 11, 0, 12, 0, 136, 0, 154, 0,
+ 155, 0, 13, 0, 0, 138, 0, 0, 141, 0,
+ 0, 0, 0, 14, 0, 0, 145, 146, 147, 148,
+ 149, 150, 151, 15, 0, 6, 0, 7, 0, 0,
+ 8, 0, 0, 0, 404, 9, 0, 16, 0, 0,
+ 10, 224, 0, 0, 0, 0, 11, 0, 12, 0,
+ 136, 0, 0, 225, 0, 152, 13, 226, 0, 138,
+ 0, 0, 141, 227, 0, 154, 0, 14, 228, 0,
+ 145, 146, 147, 148, 149, 150, 151, 15, 0, 6,
+ 0, 7, 0, 0, 8, 0, 0, 0, 0, 9,
+ 0, 16, 0, 0, 10, 224, 0, 0, 0, 0,
+ 11, 0, 12, 0, 136, 0, 0, 225, 0, 152,
+ 13, 226, 0, 138, 0, 0, 141, 227, 0, 154,
+ 0, 14, 228, 0, 145, 146, 147, 148, 149, 150,
+ 151, 15, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 39, 16, 6, 0, 7, 224,
+ 0, 8, 0, 0, 0, 0, 9, 0, 0, 40,
+ 0, 10, 0, 0, 0, 226, 0, 11, 0, 12,
+ 41, 136, 0, 42, 43, 44, 228, 13, 45, 46,
+ 138, 0, 47, 141, 0, 0, 48, 0, 14, 49,
+ 0, 145, 146, 147, 148, 149, 150, 151, 15, 0,
+ 6, 0, 7, 0, 0, 8, 0, 0, 0, 0,
+ 9, 0, 16, 0, 0, 10, 0, 0, 0, 0,
+ 0, 11, 0, 12, 0, 136, 0, 0, 0, 0,
+ 152, 13, 153, 0, 138, 0, 0, 141, 0, 0,
+ 154, 0, 14, 0, 0, 145, 146, 147, 148, 149,
+ 150, 151, 15, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 16, 0, 0, 0,
+ 39, 0, 6, 0, 7, 0, 0, 8, 0, 0,
+ 0, 0, 9, 0, 152, 40, 153, 10, 0, 0,
+ 0, 39, 0, 11, 154, 12, 41, 0, 0, 42,
+ 43, 44, 0, 13, 45, 46, 40, 0, 47, 0,
+ 0, 0, 48, 0, 14, 49, 0, 41, 0, 0,
+ 42, 43, 44, 0, 15, 45, 46, 0, 0, 47,
+ -334, 0, 0, 48, -334, 0, 49, 0, 16, 0,
+ -334, 0, 0, -334, -335, 0, 0, 0, -335, 0,
+ -334, 0, -334, -334, -335, 0, 0, -335, -334, 0,
+ 0, 0, 0, -334, -335, -334, -335, -335, -334, 0,
+ 0, 294, -335, 0, -334, 295, 0, -335, 0, -335,
+ 0, 296, -335, 0, 297, 0, 0, 0, -335, 0,
+ 0, 298, 0, 299, 300, 0, 0, 0, 0, 301,
+ 0, 0, 0, 0, 302, 0, 303, 0, 0, 304,
+ 0, 0, 0, 0, 0, 305
+};
+
+static const short int yycheck[] =
+{
+ 1, 65, 66, 1, 167, 52, 204, 30, 95, 261,
+ 95, 261, 158, 404, 11, 92, 518, 81, 216, 68,
+ 107, 62, 63, 100, 442, 70, 107, 11, 29, 70,
+ 444, 29, 11, 30, 418, 65, 123, 30, 123, 11,
+ 26, 66, 8, 27, 89, 42, 91, 13, 89, 17,
+ 91, 411, 101, 107, 152, 23, 154, 80, 399, 24,
+ 57, 62, 63, 42, 62, 63, 143, 569, 62, 70,
+ 42, 101, 70, 59, 71, 162, 101, 162, 57, 133,
+ 167, 104, 68, 69, 25, 57, 167, 80, 89, 449,
+ 91, 89, 71, 91, 95, 479, 90, 95, 72, 71,
+ 68, 522, 62, 23, 445, 206, 107, 448, 522, 107,
+ 211, 104, 72, 167, 96, 162, 457, 91, 100, 510,
+ 133, 107, 123, 109, 110, 123, 224, 225, 72, 227,
+ 228, 103, 62, 554, 555, 553, 77, 78, 66, 285,
+ 554, 555, 69, 84, 85, 131, 132, 133, 68, 570,
+ 72, 152, 573, 154, 66, 62, 570, 101, 62, 573,
+ 90, 162, 90, 204, 162, 92, 167, 3, 72, 167,
+ 511, 512, 158, 101, 261, 216, 103, 44, 90, 101,
+ 261, 167, 18, 90, 62, 72, 57, 91, 62, 101,
+ 31, 443, 215, 29, 72, 62, 32, 33, 34, 73,
+ 71, 37, 38, 204, 91, 41, 204, 261, 107, 45,
+ 89, 87, 48, 111, 412, 216, 62, 42, 216, 89,
+ 99, 97, 68, 224, 225, 226, 227, 228, 226, 99,
+ 284, 67, 57, 320, 133, 320, 0, 89, 336, 337,
+ 338, 9, 79, 57, 81, 394, 71, 99, 397, 86,
+ 72, 19, 107, 345, 346, 347, 348, 344, 394, 11,
+ 261, 397, 17, 261, 107, 101, 518, 519, 167, 519,
+ 74, 284, 76, 0, 68, 362, 3, 362, 133, 265,
+ 339, 340, 268, 341, 342, 343, 396, 310, 398, 68,
+ 133, 18, 349, 350, 66, 101, 282, 72, 284, 285,
+ 66, 68, 29, 91, 290, 32, 33, 34, 107, 44,
+ 37, 38, 167, 72, 41, 362, 101, 569, 45, 320,
+ 101, 48, 320, 101, 167, 101, 413, 313, 91, 91,
+ 91, 229, 413, 91, 133, 336, 337, 338, 339, 340,
+ 341, 342, 343, 344, 345, 346, 347, 348, 349, 350,
+ 351, 352, 353, 354, 355, 72, 72, 91, 65, 413,
+ 11, 362, 261, 67, 362, 101, 72, 62, 167, 101,
+ 447, 412, 91, 450, 101, 61, 68, 62, 101, 62,
+ 478, 58, 63, 59, 94, 284, 101, 101, 411, 443,
+ 444, 49, 101, 101, 9, 66, 107, 560, 11, 453,
+ 90, 62, 91, 90, 61, 61, 261, 61, 101, 307,
+ 308, 412, 413, 66, 412, 413, 90, 418, 261, 66,
+ 66, 91, 133, 409, 90, 90, 449, 413, 101, 284,
+ 90, 444, 519, 331, 332, 19, 91, 61, 519, 91,
+ 453, 284, 91, 66, 508, 107, 90, 90, 65, 91,
+ 527, 61, 90, 90, 68, 61, 167, 107, 444, 90,
+ 547, 101, 261, 67, 518, 519, 547, 453, 522, 523,
+ 66, 133, 62, 560, 67, 101, 65, 478, 479, 560,
+ 481, 90, 16, 133, 91, 284, 91, 16, 91, 90,
+ 90, 90, 90, 547, 65, 90, 394, 67, 552, 397,
+ 554, 555, 90, 90, 101, 167, 560, 101, 90, 522,
+ 523, 90, 65, 16, 413, 569, 570, 167, 519, 573,
+ 101, 519, 90, 101, 101, 344, 95, 65, 80, 104,
+ 313, 104, 409, 57, 110, 547, 522, 523, 62, 552,
+ 310, 554, 555, 104, 443, 444, 547, 71, 72, 547,
+ 261, 413, 547, 569, 453, 519, 377, 570, 413, 560,
+ 573, 547, 560, 308, 351, 89, 552, 91, 554, 555,
+ 413, 353, 132, 284, 560, 99, 481, 354, 352, -1,
+ 306, -1, 355, -1, 570, -1, -1, 573, 443, 444,
+ -1, -1, -1, -1, -1, -1, -1, -1, 453, 261,
+ 443, 444, -1, -1, -1, 60, -1, 62, -1, 64,
+ 453, 261, -1, -1, 413, 70, -1, 72, 73, 518,
+ 519, -1, 284, 522, 523, 80, -1, 82, 83, -1,
+ -1, -1, -1, 88, 284, -1, 91, -1, 93, -1,
+ 95, -1, -1, 98, 443, 444, -1, -1, 547, 104,
+ -1, -1, -1, 552, 453, 554, 555, -1, -1, -1,
+ -1, 560, -1, 518, 519, -1, -1, 522, 523, -1,
+ 569, 570, -1, -1, 573, 518, 519, -1, -1, 522,
+ 523, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, 547, -1, -1, -1, -1, 552, -1, 554,
+ 555, -1, 413, -1, 547, 560, -1, -1, -1, 552,
+ -1, 554, 555, -1, 569, 570, -1, 560, 573, 518,
+ 519, -1, -1, 522, 523, -1, 569, 570, -1, -1,
+ 573, -1, 443, 444, -1, -1, -1, -1, -1, -1,
+ -1, -1, 453, -1, 5, -1, 7, -1, 547, 10,
+ 11, 413, -1, 552, 15, 554, 555, -1, -1, 20,
+ -1, 560, -1, 413, -1, 26, 27, 28, -1, -1,
+ 569, 570, -1, -1, 573, 36, -1, -1, -1, -1,
+ -1, 443, 444, -1, -1, -1, 47, -1, -1, -1,
+ 130, 453, -1, 443, 444, -1, 57, 137, -1, -1,
+ -1, -1, 142, 453, 152, -1, 154, 518, 519, -1,
+ 71, 522, 523, 153, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 547, -1, -1, -1,
+ 152, 552, 154, 554, 555, -1, -1, -1, -1, 560,
+ -1, -1, -1, -1, -1, -1, 518, 519, 569, 570,
+ 522, 523, 573, -1, -1, -1, -1, -1, 518, 519,
+ -1, -1, 522, 523, -1, -1, 224, 225, -1, 227,
+ 228, -1, -1, -1, -1, 547, 226, -1, -1, -1,
+ 552, -1, 554, 555, -1, -1, -1, 547, 560, -1,
+ -1, -1, 552, -1, 554, 555, -1, 569, 570, -1,
+ 560, 573, 224, 225, -1, 227, 228, -1, -1, 569,
+ 570, -1, 262, 573, 3, -1, 266, 267, -1, -1,
+ -1, 271, -1, -1, -1, -1, -1, -1, -1, 18,
+ -1, 281, -1, -1, -1, -1, -1, -1, -1, -1,
+ 29, 291, -1, 32, 33, 34, -1, -1, 37, 38,
+ -1, -1, 41, -1, -1, -1, 45, -1, -1, 48,
+ -1, -1, -1, -1, -1, -1, 316, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 336, 337,
+ 338, 339, 340, 341, 342, 343, -1, 345, 346, 347,
+ 348, 349, 350, 351, 352, 353, 354, 355, -1, -1,
+ -1, 90, -1, -1, -1, -1, 356, 357, -1, -1,
+ -1, -1, -1, -1, 336, 337, 338, 339, 340, 341,
+ 342, 343, -1, 345, 346, 347, 348, 349, 350, 351,
+ 352, 353, 354, 355, 5, -1, 7, -1, -1, 10,
+ -1, -1, -1, 393, 15, -1, -1, -1, -1, 20,
+ -1, -1, -1, -1, 404, 26, -1, 28, -1, -1,
+ 418, -1, -1, -1, -1, 36, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 47, -1, -1, -1,
+ 5, -1, 7, -1, -1, 10, 57, -1, -1, -1,
+ 15, 441, 442, -1, -1, 20, 418, -1, -1, -1,
+ 71, 26, -1, 28, -1, 30, 456, -1, -1, 3,
+ -1, 36, -1, -1, 39, -1, -1, 42, -1, -1,
+ 478, 479, 47, 481, 18, 50, 51, 52, 53, 54,
+ 55, 56, 57, -1, -1, 29, 61, -1, 32, 33,
+ 34, -1, -1, 37, 38, -1, 71, 41, -1, -1,
+ 75, 45, -1, -1, 48, -1, 478, 479, -1, 481,
+ 510, -1, 87, -1, 89, -1, 91, -1, -1, -1,
+ 520, 521, 97, 67, 99, -1, -1, 102, -1, 3,
+ 4, 5, 6, 7, 8, -1, 10, -1, 12, 13,
+ 14, 15, -1, 543, 18, -1, 20, 21, 22, -1,
+ -1, -1, 26, 553, 28, 29, 30, -1, 32, 33,
+ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
+ -1, 45, 46, 47, 48, 49, 50, 51, 52, 53,
+ 54, 55, 56, 57, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 67, 68, -1, -1, 71, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 89, -1, 91, -1, 3,
+ 4, 5, 6, 7, -1, 99, 10, 101, 12, -1,
+ 14, 15, -1, -1, 18, -1, 20, 21, 22, -1,
+ -1, -1, 26, -1, 28, 29, 30, -1, 32, 33,
+ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
+ -1, 45, 46, 47, 48, 49, 50, 51, 52, 53,
+ 54, 55, 56, 57, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 67, 68, -1, -1, 71, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 89, -1, 91, -1, 3,
+ 4, 5, 6, 7, -1, 99, 10, 101, 12, -1,
+ 14, 15, -1, -1, 18, -1, 20, 21, 22, -1,
+ -1, -1, 26, -1, 28, 29, 30, -1, 32, 33,
+ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
+ -1, 45, 46, 47, 48, 49, 50, 51, 52, 53,
+ 54, 55, 56, 57, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 67, 68, -1, -1, 71, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 89, -1, 91, -1, 3,
+ 4, 5, 6, 7, -1, 99, 10, 101, 12, -1,
+ 14, 15, -1, -1, 18, -1, 20, 21, 22, -1,
+ -1, -1, 26, -1, 28, 29, 30, -1, 32, 33,
+ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
+ -1, 45, 46, 47, 48, 49, 50, 51, 52, 53,
+ 54, 55, 56, 57, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 67, 68, -1, -1, 71, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 89, -1, 91, -1, -1,
+ -1, -1, -1, -1, -1, 99, -1, 101, 3, 4,
+ 5, 6, 7, -1, -1, 10, 11, 12, -1, 14,
+ 15, -1, -1, 18, -1, 20, 21, 22, -1, -1,
+ -1, 26, -1, 28, 29, 30, -1, 32, 33, 34,
+ 35, 36, 37, 38, 39, 40, 41, 42, 43, -1,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 68, -1, -1, 71, -1, -1, -1,
+ -1, 4, 5, 6, 7, -1, -1, 10, -1, 12,
+ -1, 14, 15, -1, 89, -1, 91, 20, 21, 22,
+ -1, -1, -1, 26, 99, 28, 101, 30, -1, -1,
+ -1, -1, 35, 36, -1, -1, 39, 40, 41, 42,
+ 43, -1, -1, 46, 47, -1, 49, 50, 51, 52,
+ 53, 54, 55, 56, 57, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 68, -1, -1, 71, -1,
+ -1, -1, -1, 4, 5, 6, 7, -1, -1, 10,
+ -1, 12, -1, 14, 15, -1, 89, -1, 91, 20,
+ 21, 22, -1, -1, -1, 26, 99, 28, 101, 30,
+ -1, -1, -1, -1, 35, 36, -1, -1, 39, 40,
+ 41, 42, 43, -1, -1, 46, 47, -1, 49, 50,
+ 51, 52, 53, 54, 55, 56, 57, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, 68, -1, -1,
+ 71, 5, -1, 7, -1, -1, 10, -1, -1, -1,
+ -1, 15, -1, -1, -1, -1, 20, -1, 89, -1,
+ 91, -1, 26, -1, 28, -1, 30, -1, 99, -1,
+ 101, -1, 36, -1, -1, 39, -1, -1, 42, -1,
+ -1, -1, -1, 47, -1, -1, 50, 51, 52, 53,
+ 54, 55, 56, 57, -1, 5, -1, 7, -1, -1,
+ 10, -1, -1, -1, 68, 15, -1, 71, -1, -1,
+ 20, 75, -1, -1, -1, -1, 26, -1, 28, -1,
+ 30, -1, -1, 87, -1, 89, 36, 91, -1, 39,
+ -1, -1, 42, 97, -1, 99, -1, 47, 102, -1,
+ 50, 51, 52, 53, 54, 55, 56, 57, -1, 5,
+ -1, 7, -1, -1, 10, -1, -1, -1, -1, 15,
+ -1, 71, -1, -1, 20, 75, -1, -1, -1, -1,
+ 26, -1, 28, -1, 30, -1, -1, 87, -1, 89,
+ 36, 91, -1, 39, -1, -1, 42, 97, -1, 99,
+ -1, 47, 102, -1, 50, 51, 52, 53, 54, 55,
+ 56, 57, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, 3, 71, 5, -1, 7, 75,
+ -1, 10, -1, -1, -1, -1, 15, -1, -1, 18,
+ -1, 20, -1, -1, -1, 91, -1, 26, -1, 28,
+ 29, 30, -1, 32, 33, 34, 102, 36, 37, 38,
+ 39, -1, 41, 42, -1, -1, 45, -1, 47, 48,
+ -1, 50, 51, 52, 53, 54, 55, 56, 57, -1,
+ 5, -1, 7, -1, -1, 10, -1, -1, -1, -1,
+ 15, -1, 71, -1, -1, 20, -1, -1, -1, -1,
+ -1, 26, -1, 28, -1, 30, -1, -1, -1, -1,
+ 89, 36, 91, -1, 39, -1, -1, 42, -1, -1,
+ 99, -1, 47, -1, -1, 50, 51, 52, 53, 54,
+ 55, 56, 57, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 71, -1, -1, -1,
+ 3, -1, 5, -1, 7, -1, -1, 10, -1, -1,
+ -1, -1, 15, -1, 89, 18, 91, 20, -1, -1,
+ -1, 3, -1, 26, 99, 28, 29, -1, -1, 32,
+ 33, 34, -1, 36, 37, 38, 18, -1, 41, -1,
+ -1, -1, 45, -1, 47, 48, -1, 29, -1, -1,
+ 32, 33, 34, -1, 57, 37, 38, -1, -1, 41,
+ 60, -1, -1, 45, 64, -1, 48, -1, 71, -1,
+ 70, -1, -1, 73, 60, -1, -1, -1, 64, -1,
+ 80, -1, 82, 83, 70, -1, -1, 73, 88, -1,
+ -1, -1, -1, 93, 80, 95, 82, 83, 98, -1,
+ -1, 60, 88, -1, 104, 64, -1, 93, -1, 95,
+ -1, 70, 98, -1, 73, -1, -1, -1, 104, -1,
+ -1, 80, -1, 82, 83, -1, -1, -1, -1, 88,
+ -1, -1, -1, -1, 93, -1, 95, -1, -1, 98,
+ -1, -1, -1, -1, -1, 104
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const unsigned short int yystos[] =
+{
+ 0, 31, 107, 122, 123, 126, 5, 7, 10, 15,
+ 20, 26, 28, 36, 47, 57, 71, 111, 117, 118,
+ 119, 120, 121, 0, 124, 57, 72, 101, 72, 24,
+ 125, 127, 128, 129, 11, 42, 119, 11, 117, 3,
+ 18, 29, 32, 33, 34, 37, 38, 41, 45, 48,
+ 101, 130, 131, 132, 133, 134, 135, 164, 165, 72,
+ 101, 132, 17, 23, 68, 136, 137, 139, 11, 27,
+ 17, 166, 167, 103, 113, 114, 117, 113, 115, 138,
+ 140, 137, 139, 139, 119, 119, 115, 68, 168, 66,
+ 101, 66, 37, 67, 130, 135, 141, 142, 143, 148,
+ 149, 158, 159, 139, 169, 115, 115, 68, 177, 47,
+ 110, 111, 112, 113, 116, 117, 118, 160, 101, 157,
+ 177, 67, 134, 135, 143, 149, 165, 170, 171, 172,
+ 4, 6, 12, 14, 21, 22, 30, 35, 39, 40,
+ 41, 42, 43, 46, 49, 50, 51, 52, 53, 54,
+ 55, 56, 89, 91, 99, 101, 108, 109, 110, 116,
+ 117, 119, 131, 134, 135, 177, 178, 179, 180, 181,
+ 182, 183, 185, 186, 187, 189, 190, 191, 192, 194,
+ 201, 203, 204, 212, 213, 215, 216, 217, 218, 219,
+ 224, 225, 226, 230, 235, 236, 237, 238, 239, 240,
+ 242, 243, 258, 259, 263, 119, 151, 119, 144, 145,
+ 146, 151, 62, 234, 234, 91, 44, 150, 155, 101,
+ 101, 101, 173, 101, 75, 87, 91, 97, 102, 111,
+ 116, 117, 226, 236, 238, 239, 240, 241, 242, 243,
+ 244, 245, 246, 247, 248, 249, 250, 251, 252, 253,
+ 254, 255, 256, 257, 258, 261, 119, 214, 214, 41,
+ 183, 91, 91, 208, 261, 72, 91, 91, 72, 261,
+ 177, 91, 117, 235, 237, 241, 261, 241, 119, 144,
+ 72, 62, 72, 91, 65, 110, 67, 180, 101, 101,
+ 72, 62, 89, 99, 60, 64, 70, 73, 80, 82,
+ 83, 88, 93, 95, 98, 104, 260, 111, 113, 114,
+ 91, 62, 150, 66, 101, 62, 73, 150, 61, 62,
+ 135, 152, 153, 154, 114, 156, 68, 161, 101, 241,
+ 241, 111, 117, 261, 241, 241, 69, 92, 103, 87,
+ 97, 79, 81, 86, 25, 77, 78, 84, 85, 74,
+ 76, 58, 63, 94, 59, 96, 100, 65, 101, 101,
+ 101, 49, 131, 182, 190, 206, 209, 211, 261, 101,
+ 119, 261, 261, 119, 101, 9, 220, 221, 222, 261,
+ 90, 11, 261, 30, 228, 229, 261, 183, 144, 42,
+ 119, 261, 257, 62, 232, 233, 234, 232, 234, 91,
+ 152, 61, 145, 61, 68, 147, 174, 261, 61, 110,
+ 90, 66, 66, 162, 101, 231, 234, 234, 90, 241,
+ 241, 241, 246, 246, 247, 247, 247, 112, 248, 248,
+ 248, 248, 249, 249, 250, 251, 252, 253, 254, 261,
+ 261, 91, 101, 66, 90, 91, 90, 90, 91, 91,
+ 19, 223, 222, 90, 61, 90, 66, 91, 61, 261,
+ 231, 233, 234, 174, 231, 174, 228, 90, 147, 175,
+ 176, 146, 154, 114, 39, 42, 163, 178, 90, 90,
+ 244, 65, 101, 261, 208, 190, 21, 22, 49, 119,
+ 183, 184, 185, 188, 193, 202, 207, 228, 68, 195,
+ 177, 228, 154, 177, 183, 261, 228, 61, 90, 67,
+ 66, 91, 91, 67, 241, 244, 256, 90, 101, 91,
+ 91, 91, 65, 16, 90, 197, 90, 90, 90, 139,
+ 227, 147, 228, 228, 101, 205, 210, 211, 206, 261,
+ 261, 184, 183, 8, 13, 196, 198, 199, 200, 177,
+ 90, 90, 90, 101, 90, 90, 261, 262, 65, 67,
+ 179, 200, 101, 101, 183, 208, 184, 184, 65, 101,
+ 16, 205, 184, 90, 184
+};
+
+#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
+# define YYSIZE_T __SIZE_TYPE__
+#endif
+#if ! defined (YYSIZE_T) && defined (size_t)
+# define YYSIZE_T size_t
+#endif
+#if ! defined (YYSIZE_T)
+# if defined (__STDC__) || defined (__cplusplus)
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# endif
+#endif
+#if ! defined (YYSIZE_T)
+# define YYSIZE_T unsigned int
+#endif
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+/* Like YYERROR except do call yyerror. This remains here temporarily
+ to ease the transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. */
+
+#define YYFAIL goto yyerrlab
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ yytoken = YYTRANSLATE (yychar); \
+ YYPOPSTACK; \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror ("syntax error: cannot back up");\
+ YYERROR; \
+ } \
+while (0)
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+/* YYLLOC_DEFAULT -- Compute the default location (before the actions
+ are run). */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ ((Current).first_line = (Rhs)[1].first_line, \
+ (Current).first_column = (Rhs)[1].first_column, \
+ (Current).last_line = (Rhs)[N].last_line, \
+ (Current).last_column = (Rhs)[N].last_column)
+#endif
+
+/* YYLEX -- calling `yylex' with the right arguments. */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval)
+#endif
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (0)
+
+# define YYDSYMPRINT(Args) \
+do { \
+ if (yydebug) \
+ yysymprint Args; \
+} while (0)
+
+# define YYDSYMPRINTF(Title, Token, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yysymprint (stderr, \
+ Token, Value); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (0)
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yy_stack_print (short int *bottom, short int *top)
+#else
+static void
+yy_stack_print (bottom, top)
+ short int *bottom;
+ short int *top;
+#endif
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (/* Nothing. */; bottom <= top; ++bottom)
+ YYFPRINTF (stderr, " %d", *bottom);
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (0)
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yy_reduce_print (int yyrule)
+#else
+static void
+yy_reduce_print (yyrule)
+ int yyrule;
+#endif
+{
+ int yyi;
+ unsigned int yylno = yyrline[yyrule];
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
+ yyrule - 1, yylno);
+ /* Print the symbols being reduced, and their result. */
+ for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
+ YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
+ YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (Rule); \
+} while (0)
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YYDSYMPRINT(Args)
+# define YYDSYMPRINTF(Title, Token, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#if defined (YYMAXDEPTH) && YYMAXDEPTH == 0
+# undef YYMAXDEPTH
+#endif
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined (__GLIBC__) && defined (_STRING_H)
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+static YYSIZE_T
+# if defined (__STDC__) || defined (__cplusplus)
+yystrlen (const char *yystr)
+# else
+yystrlen (yystr)
+ const char *yystr;
+# endif
+{
+ const char *yys = yystr;
+
+ while (*yys++ != '\0')
+ continue;
+
+ return yys - yystr - 1;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+static char *
+# if defined (__STDC__) || defined (__cplusplus)
+yystpcpy (char *yydest, const char *yysrc)
+# else
+yystpcpy (yydest, yysrc)
+ char *yydest;
+ const char *yysrc;
+# endif
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+#endif /* !YYERROR_VERBOSE */
+
+
+
+#if YYDEBUG
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yysymprint (yyoutput, yytype, yyvaluep)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE *yyvaluep;
+#endif
+{
+ /* Pacify ``unused variable'' warnings. */
+ (void) yyvaluep;
+
+ if (yytype < YYNTOKENS)
+ {
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+# ifdef YYPRINT
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# endif
+ }
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+ switch (yytype)
+ {
+ default:
+ break;
+ }
+ YYFPRINTF (yyoutput, ")");
+}
+
+#endif /* ! YYDEBUG */
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yydestruct (int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yydestruct (yytype, yyvaluep)
+ int yytype;
+ YYSTYPE *yyvaluep;
+#endif
+{
+ /* Pacify ``unused variable'' warnings. */
+ (void) yyvaluep;
+
+ switch (yytype)
+ {
+
+ default:
+ break;
+ }
+}
+
+
+/* Prevent warnings from -Wmissing-prototypes. */
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM);
+# else
+int yyparse ();
+# endif
+#else /* ! YYPARSE_PARAM */
+#if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM)
+# else
+int yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+# endif
+#else /* ! YYPARSE_PARAM */
+#if defined (__STDC__) || defined (__cplusplus)
+int
+yyparse (void)
+#else
+int
+yyparse ()
+
+#endif
+#endif
+{
+ /* The lookahead symbol. */
+int yychar;
+
+/* The semantic value of the lookahead symbol. */
+YYSTYPE yylval;
+
+/* Number of syntax errors so far. */
+int yynerrs;
+
+ int yystate;
+ int yyn;
+ int yyresult;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+ /* Lookahead token as an internal (translated) token number. */
+ int yytoken = 0;
+
+ /* Three stacks and their tools:
+ `yyss': related to states,
+ `yyvs': related to semantic values,
+ `yyls': related to locations.
+
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ short int yyssa[YYINITDEPTH];
+ short int *yyss = yyssa;
+ short int *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs = yyvsa;
+ YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK (yyvsp--, yyssp--)
+
+ YYSIZE_T yystacksize = YYINITDEPTH;
+
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+
+ /* When reducing, the number of symbols on the RHS of the reduced
+ rule. */
+ int yylen;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss;
+ yyvsp = yyvs;
+
+
+ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. so pushing a state here evens the stacks.
+ */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ short int *yyss1 = yyss;
+
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow ("parser stack overflow",
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),
+
+ &yystacksize);
+
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyoverflowlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyoverflowlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ short int *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyoverflowlab;
+ YYSTACK_RELOCATE (yyss);
+ YYSTACK_RELOCATE (yyvs);
+
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+/* Do appropriate processing given the current state. */
+/* Read a lookahead token if we need one and don't already have one. */
+/* yyresume: */
+
+ /* First try to decide what to do without reference to lookahead token. */
+
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Shift the lookahead token. */
+ YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
+
+ /* Discard the token being shifted unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ *++yyvsp = yylval;
+
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 2:
+#line 192 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 3:
+#line 201 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 4:
+#line 209 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 5:
+#line 217 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 6:
+#line 225 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 7:
+#line 233 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 8:
+#line 241 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 9:
+#line 250 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 10:
+#line 258 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 11:
+#line 267 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 12:
+#line 275 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 13:
+#line 284 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+}
+ break;
+
+ case 14:
+#line 289 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+}
+ break;
+
+ case 15:
+#line 294 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+}
+ break;
+
+ case 16:
+#line 299 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+}
+ break;
+
+ case 17:
+#line 304 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+}
+ break;
+
+ case 18:
+#line 309 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+}
+ break;
+
+ case 19:
+#line 314 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+}
+ break;
+
+ case 20:
+#line 319 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+}
+ break;
+
+ case 21:
+#line 325 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 22:
+#line 333 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 23:
+#line 342 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpStoreClass(yyvsp[0].str);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 24:
+#line 352 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 25:
+#line 361 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 26:
+#line 370 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 27:
+#line 378 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpStoreClass(yyvsp[-1].str);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 28:
+#line 388 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyval.str = yyvsp[0].str;
+}
+ break;
+
+ case 29:
+#line 394 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyval.str = yyvsp[0].str;
+}
+ break;
+
+ case 30:
+#line 401 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyval.str = yyvsp[0].str;
+}
+ break;
+
+ case 31:
+#line 408 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyval.str = yyvsp[0].str;
+}
+ break;
+
+ case 32:
+#line 414 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ yyval.str = yyvsp[0].str;
+}
+ break;
+
+ case 33:
+#line 421 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->AddClassFound(yyvsp[-2].str);
+ yyGetParser->UpdateCombine(yyvsp[-2].str, yyvsp[0].str);
+ yyGetParser->DeallocateParserType(&(yyvsp[-2].str));
+ yyval.str = const_cast<char*>(yyGetParser->GetCurrentCombine());
+}
+ break;
+
+ case 34:
+#line 430 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpStoreClass(yyvsp[-2].str);
+ jpCheckEmpty(3);
+ yyGetParser->SetCurrentCombine("");
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 35:
+#line 440 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpStoreClass(yyvsp[-2].str);
+ yyGetParser->SetCurrentCombine("");
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 36:
+#line 450 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 37:
+#line 459 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 38:
+#line 467 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 39:
+#line 476 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 40:
+#line 484 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 41:
+#line 491 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 42:
+#line 499 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 43:
+#line 506 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 44:
+#line 514 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 45:
+#line 521 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 46:
+#line 530 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->SetCurrentPackage(yyvsp[-1].str);
+ yyGetParser->DeallocateParserType(&(yyvsp[-1].str));
+ yyGetParser->SetCurrentCombine("");
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 47:
+#line 542 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 48:
+#line 550 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 49:
+#line 559 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->AddPackagesImport(yyvsp[-1].str);
+ yyGetParser->DeallocateParserType(&(yyvsp[-1].str));
+ yyGetParser->SetCurrentCombine("");
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 50:
+#line 571 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+ std::string str = yyvsp[-3].str;
+ str += ".*";
+ yyGetParser->AddPackagesImport(str.c_str());
+ yyGetParser->DeallocateParserType(&(yyvsp[-3].str));
+ yyGetParser->SetCurrentCombine("");
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 51:
+#line 584 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 52:
+#line 592 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 53:
+#line 600 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 54:
+#line 609 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 55:
+#line 617 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 67:
+#line 632 "cmDependsJavaParser.y"
+ {
+ yyGetParser->StartClass(yyvsp[0].str);
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&(yyvsp[0].str));
+ jpCheckEmpty(3);
+}
+ break;
+
+ case 68:
+#line 642 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+ break;
+
+ case 69:
+#line 651 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+ break;
+
+ case 70:
+#line 660 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+ break;
+
+ case 71:
+#line 669 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+ break;
+
+ case 72:
+#line 678 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 73:
+#line 685 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 74:
+#line 694 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 75:
+#line 703 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 76:
+#line 712 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 77:
+#line 720 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 78:
+#line 729 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 79:
+#line 737 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 80:
+#line 744 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 81:
+#line 753 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 82:
+#line 761 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 83:
+#line 769 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 84:
+#line 777 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 85:
+#line 786 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 86:
+#line 794 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 87:
+#line 803 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+}
+ break;
+
+ case 88:
+#line 809 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 89:
+#line 817 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 90:
+#line 826 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 91:
+#line 834 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 92:
+#line 843 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyGetParser->DeallocateParserType(&(yyvsp[0].str));
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 93:
+#line 852 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 94:
+#line 861 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 95:
+#line 869 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 96:
+#line 878 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 97:
+#line 886 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 98:
+#line 894 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 99:
+#line 903 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 100:
+#line 912 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 101:
+#line 921 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 102:
+#line 929 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 103:
+#line 939 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ yyGetParser->DeallocateParserType(&(yyvsp[-3].str));
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 104:
+#line 949 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+
+}
+ break;
+
+ case 105:
+#line 955 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 107:
+#line 966 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+
+}
+ break;
+
+ case 108:
+#line 972 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 109:
+#line 982 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 110:
+#line 992 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 111:
+#line 1002 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+
+}
+ break;
+
+ case 112:
+#line 1008 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 113:
+#line 1018 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 114:
+#line 1028 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 115:
+#line 1038 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 116:
+#line 1047 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 117:
+#line 1057 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ yyGetParser->DeallocateParserType(&(yyvsp[-3].str));
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 118:
+#line 1068 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 119:
+#line 1077 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 120:
+#line 1085 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 121:
+#line 1095 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 122:
+#line 1104 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 123:
+#line 1114 "cmDependsJavaParser.y"
+ {
+ yyGetParser->StartClass(yyvsp[0].str);
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&(yyvsp[0].str));
+ jpCheckEmpty(3);
+}
+ break;
+
+ case 124:
+#line 1123 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+ break;
+
+ case 125:
+#line 1132 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+ break;
+
+ case 126:
+#line 1139 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 127:
+#line 1149 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 128:
+#line 1158 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 129:
+#line 1168 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 130:
+#line 1177 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 131:
+#line 1185 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 132:
+#line 1194 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 133:
+#line 1203 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 134:
+#line 1212 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 135:
+#line 1221 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 136:
+#line 1229 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 137:
+#line 1238 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 138:
+#line 1247 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 139:
+#line 1257 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 140:
+#line 1267 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 141:
+#line 1276 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 142:
+#line 1286 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 143:
+#line 1295 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 144:
+#line 1303 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 145:
+#line 1312 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 146:
+#line 1322 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 147:
+#line 1331 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 148:
+#line 1341 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 149:
+#line 1349 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 150:
+#line 1357 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 151:
+#line 1367 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 152:
+#line 1376 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 153:
+#line 1386 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 154:
+#line 1395 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 155:
+#line 1404 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 156:
+#line 1414 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 157:
+#line 1424 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 158:
+#line 1433 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 159:
+#line 1443 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 160:
+#line 1452 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 161:
+#line 1461 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 162:
+#line 1470 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 163:
+#line 1479 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 164:
+#line 1488 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 165:
+#line 1498 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 166:
+#line 1507 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 167:
+#line 1516 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 168:
+#line 1525 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 169:
+#line 1534 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 170:
+#line 1544 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 171:
+#line 1553 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 172:
+#line 1562 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 173:
+#line 1571 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 174:
+#line 1580 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 175:
+#line 1589 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 176:
+#line 1598 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 177:
+#line 1607 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 178:
+#line 1616 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 179:
+#line 1625 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 180:
+#line 1634 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 181:
+#line 1643 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 182:
+#line 1653 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 183:
+#line 1663 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&(yyvsp[-2].str));
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 184:
+#line 1674 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 185:
+#line 1684 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 186:
+#line 1694 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 187:
+#line 1703 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 188:
+#line 1712 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 189:
+#line 1721 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 190:
+#line 1730 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 191:
+#line 1739 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 192:
+#line 1748 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 193:
+#line 1758 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 194:
+#line 1768 "cmDependsJavaParser.y"
+ {
+ jpElementStart(7);
+ jpCheckEmpty(7);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 195:
+#line 1778 "cmDependsJavaParser.y"
+ {
+ jpElementStart(7);
+ jpCheckEmpty(7);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 196:
+#line 1788 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+
+}
+ break;
+
+ case 197:
+#line 1795 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+
+}
+ break;
+
+ case 198:
+#line 1801 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 199:
+#line 1809 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 200:
+#line 1818 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 201:
+#line 1826 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 202:
+#line 1836 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 203:
+#line 1846 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 204:
+#line 1855 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 205:
+#line 1865 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 206:
+#line 1874 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 207:
+#line 1884 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+
+}
+ break;
+
+ case 208:
+#line 1891 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+
+}
+ break;
+
+ case 209:
+#line 1898 "cmDependsJavaParser.y"
+ {
+ jpElementStart(7);
+
+}
+ break;
+
+ case 210:
+#line 1906 "cmDependsJavaParser.y"
+ {
+ jpElementStart(9);
+
+}
+ break;
+
+ case 211:
+#line 1912 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 212:
+#line 1920 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 213:
+#line 1929 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 214:
+#line 1937 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 215:
+#line 1948 "cmDependsJavaParser.y"
+ {
+ jpElementStart(9);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 216:
+#line 1956 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 217:
+#line 1964 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 218:
+#line 1974 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 219:
+#line 1983 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 220:
+#line 1993 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 221:
+#line 2003 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 222:
+#line 2012 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 223:
+#line 2022 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 224:
+#line 2031 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 225:
+#line 2041 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&(yyvsp[-1].str));
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 226:
+#line 2051 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 227:
+#line 2059 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+
+}
+ break;
+
+ case 228:
+#line 2066 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&(yyvsp[-1].str));
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 229:
+#line 2077 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 230:
+#line 2087 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 231:
+#line 2097 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 232:
+#line 2107 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 233:
+#line 2116 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 234:
+#line 2125 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 235:
+#line 2133 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 236:
+#line 2143 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 237:
+#line 2152 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 238:
+#line 2162 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+
+}
+ break;
+
+ case 239:
+#line 2169 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 240:
+#line 2179 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 241:
+#line 2188 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 242:
+#line 2198 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 243:
+#line 2207 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+
+}
+ break;
+
+ case 244:
+#line 2213 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 245:
+#line 2222 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 246:
+#line 2231 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 247:
+#line 2240 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 248:
+#line 2249 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 249:
+#line 2259 "cmDependsJavaParser.y"
+ {
+ jpElementStart(6);
+ jpCheckEmpty(6);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 250:
+#line 2268 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 251:
+#line 2276 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 252:
+#line 2285 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 253:
+#line 2293 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 254:
+#line 2303 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 255:
+#line 2312 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 256:
+#line 2322 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 257:
+#line 2331 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 258:
+#line 2340 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 259:
+#line 2349 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 260:
+#line 2358 "cmDependsJavaParser.y"
+ {
+ jpElementStart(0);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 261:
+#line 2366 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 262:
+#line 2376 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 263:
+#line 2385 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 264:
+#line 2395 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 265:
+#line 2405 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+
+}
+ break;
+
+ case 266:
+#line 2411 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+
+}
+ break;
+
+ case 267:
+#line 2418 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&(yyvsp[0].str));
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 268:
+#line 2428 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&(yyvsp[0].str));
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 269:
+#line 2438 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&(yyvsp[0].str));
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 270:
+#line 2448 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&(yyvsp[0].str));
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 271:
+#line 2459 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ yyGetParser->DeallocateParserType(&(yyvsp[-3].str));
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 272:
+#line 2469 "cmDependsJavaParser.y"
+ {
+ jpElementStart(6);
+ yyGetParser->DeallocateParserType(&(yyvsp[-5].str));
+ yyGetParser->DeallocateParserType(&(yyvsp[-3].str));
+ jpCheckEmpty(6);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 273:
+#line 2480 "cmDependsJavaParser.y"
+ {
+ jpElementStart(6);
+ yyGetParser->DeallocateParserType(&(yyvsp[-3].str));
+ jpCheckEmpty(6);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 274:
+#line 2490 "cmDependsJavaParser.y"
+ {
+ jpElementStart(6);
+ yyGetParser->DeallocateParserType(&(yyvsp[-3].str));
+ jpCheckEmpty(6);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 275:
+#line 2501 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ yyGetParser->DeallocateParserType(&(yyvsp[-3].str));
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 276:
+#line 2511 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 277:
+#line 2521 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 278:
+#line 2530 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyGetParser->DeallocateParserType(&(yyvsp[0].str));
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 279:
+#line 2539 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 280:
+#line 2548 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 281:
+#line 2557 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 282:
+#line 2567 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 283:
+#line 2577 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 284:
+#line 2587 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 285:
+#line 2596 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 286:
+#line 2605 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 287:
+#line 2614 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 288:
+#line 2623 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 289:
+#line 2633 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 290:
+#line 2643 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 291:
+#line 2653 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 292:
+#line 2662 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 293:
+#line 2671 "cmDependsJavaParser.y"
+ {
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 294:
+#line 2680 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 295:
+#line 2690 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 296:
+#line 2699 "cmDependsJavaParser.y"
+ {
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 297:
+#line 2708 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+
+}
+ break;
+
+ case 298:
+#line 2715 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 299:
+#line 2724 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 300:
+#line 2733 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 301:
+#line 2742 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 302:
+#line 2752 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 303:
+#line 2761 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 304:
+#line 2770 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 305:
+#line 2780 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 306:
+#line 2789 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 307:
+#line 2798 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 308:
+#line 2807 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 309:
+#line 2817 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 310:
+#line 2826 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 311:
+#line 2835 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 312:
+#line 2844 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 313:
+#line 2853 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 314:
+#line 2862 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 315:
+#line 2872 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 316:
+#line 2881 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 317:
+#line 2890 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 318:
+#line 2900 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 319:
+#line 2909 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 320:
+#line 2919 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 321:
+#line 2928 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 322:
+#line 2938 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 323:
+#line 2947 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 324:
+#line 2957 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 325:
+#line 2966 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 326:
+#line 2976 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 327:
+#line 2985 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 328:
+#line 2995 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 329:
+#line 3004 "cmDependsJavaParser.y"
+ {
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 330:
+#line 3014 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 331:
+#line 3023 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 332:
+#line 3033 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 333:
+#line 3043 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ yyGetParser->DeallocateParserType(&(yyvsp[0].str));
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 334:
+#line 3053 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 335:
+#line 3062 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 336:
+#line 3072 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 337:
+#line 3081 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 338:
+#line 3090 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 339:
+#line 3099 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 340:
+#line 3108 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 341:
+#line 3117 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 342:
+#line 3126 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 343:
+#line 3135 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 344:
+#line 3144 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 345:
+#line 3153 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 346:
+#line 3162 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 347:
+#line 3171 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 348:
+#line 3181 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 349:
+#line 3191 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 350:
+#line 3201 "cmDependsJavaParser.y"
+ {
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+ case 351:
+#line 3210 "cmDependsJavaParser.y"
+ {
+ jpElementStart(3);
+ jpStoreClass(yyvsp[-2].str);
+ jpCheckEmpty(3);
+ yyval.str = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+ break;
+
+
+ }
+
+/* Line 1010 of yacc.c. */
+#line 5780 "cmDependsJavaParser.cxx"
+
+ yyvsp -= yylen;
+ yyssp -= yylen;
+
+
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+
+
+ /* Now `shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if YYERROR_VERBOSE
+ yyn = yypact[yystate];
+
+ if (YYPACT_NINF < yyn && yyn < YYLAST)
+ {
+ YYSIZE_T yysize = 0;
+ int yytype = YYTRANSLATE (yychar);
+ const char* yyprefix;
+ char *yymsg;
+ int yyx;
+
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yycount = 0;
+
+ yyprefix = ", expecting ";
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+ {
+ yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
+ yycount += 1;
+ if (yycount == 5)
+ {
+ yysize = 0;
+ break;
+ }
+ }
+ yysize += (sizeof ("syntax error, unexpected ")
+ + yystrlen (yytname[yytype]));
+ yymsg = (char *) YYSTACK_ALLOC (yysize);
+ if (yymsg != 0)
+ {
+ char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
+ yyp = yystpcpy (yyp, yytname[yytype]);
+
+ if (yycount < 5)
+ {
+ yyprefix = ", expecting ";
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+ {
+ yyp = yystpcpy (yyp, yyprefix);
+ yyp = yystpcpy (yyp, yytname[yyx]);
+ yyprefix = " or ";
+ }
+ }
+ yyerror (yymsg);
+ YYSTACK_FREE (yymsg);
+ }
+ else
+ yyerror ("syntax error; also virtual memory exhausted");
+ }
+ else
+#endif /* YYERROR_VERBOSE */
+ yyerror ("syntax error");
+ }
+
+
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* If at end of input, pop the error token,
+ then the rest of the stack, then return failure. */
+ if (yychar == YYEOF)
+ for (;;)
+ {
+ YYPOPSTACK;
+ if (yyssp == yyss)
+ YYABORT;
+ YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+ yydestruct (yystos[*yyssp], yyvsp);
+ }
+ }
+ else
+ {
+ YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
+ yydestruct (yytoken, &yylval);
+ yychar = YYEMPTY;
+
+ }
+ }
+
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+#if defined(__GNUC__) || defined(__HP_aCC)
+ /* Pacify GCC when the user code never invokes YYERROR and the label
+ yyerrorlab therefore never appears in user code. */
+ if (0)
+ goto yyerrorlab;
+#endif
+
+ yyvsp -= yylen;
+ yyssp -= yylen;
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (yyn != YYPACT_NINF)
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+ YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+ yydestruct (yystos[yystate], yyvsp);
+ YYPOPSTACK;
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ YYDPRINTF ((stderr, "Shifting error token, "));
+
+ *++yyvsp = yylval;
+
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#ifndef yyoverflow
+/*----------------------------------------------.
+| yyoverflowlab -- parser overflow comes here. |
+`----------------------------------------------*/
+yyoverflowlab:
+ yyerror ("parser stack overflow");
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+ return yyresult;
+}
+
+
+#line 3219 "cmDependsJavaParser.y"
+
+/* End of grammar */
+
+/*--------------------------------------------------------------------------*/
+void cmDependsJavaError(yyscan_t yyscanner, const char* message)
+{
+ yyGetParser->Error(message);
+}
+
+
diff --git a/Source/cmDependsJavaParser.y b/Source/cmDependsJavaParser.y
new file mode 100644
index 0000000000..944d4b5ced
--- /dev/null
+++ b/Source/cmDependsJavaParser.y
@@ -0,0 +1,3227 @@
+%{
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run bison like this:
+
+ bison --yacc --name-prefix=cmDependsJava_yy --defines=cmDependsJavaParserTokens.h -ocmDependsJavaParser.cxx cmDependsJavaParser.y
+
+Modify cmDependsJavaParser.cxx:
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - add __HP_aCC to the #if test for yyerrorlab warning suppression
+
+*/
+
+/* Configure the parser to use a lexer object. */
+#define YYPARSE_PARAM yyscanner
+#define YYLEX_PARAM yyscanner
+#define YYERROR_VERBOSE 1
+#define cmDependsJava_yyerror(x) \
+ cmDependsJavaError(yyscanner, x)
+#define yyGetParser (cmDependsJava_yyget_extra(yyscanner))
+
+/*-------------------------------------------------------------------------*/
+#include "cmDependsJavaParserHelper.h" /* Interface to parser object. */
+#include "cmDependsJavaLexer.h" /* Interface to lexer object. */
+#include "cmDependsJavaParserTokens.h" /* Need YYSTYPE for YY_DECL. */
+
+/* Forward declare the lexer entry point. */
+YY_DECL;
+
+/* Internal utility functions. */
+static void cmDependsJavaError(yyscan_t yyscanner, const char* message);
+
+#define YYDEBUG 1
+#define YYMAXDEPTH 1000000
+
+
+#define jpCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp);
+#define jpElementStart(cnt) yyGetParser->PrepareElement(&yyval)
+#define jpStoreClass(str) yyGetParser->AddClassFound(str); yyGetParser->DeallocateParserType(&(str))
+/* Disable some warnings in the generated code. */
+#ifdef __BORLANDC__
+# pragma warn -8004 /* Variable assigned a value that is not used. */
+# pragma warn -8008 /* condition always returns true */
+# pragma warn -8060 /* possibly incorrect assignment */
+# pragma warn -8066 /* unreachable code */
+#endif
+#ifdef _MSC_VER
+# pragma warning (disable: 4102) /* Unused goto label. */
+# pragma warning (disable: 4065) /* Switch statement contains default but no case. */
+#endif
+%}
+
+/* Generate a reentrant parser object. */
+%pure_parser
+
+/*
+%union {
+ char* string;
+}
+*/
+
+/*-------------------------------------------------------------------------*/
+/* Tokens */
+%token jp_ABSTRACT
+%token jp_ASSERT
+%token jp_BOOLEAN_TYPE
+%token jp_BREAK
+%token jp_BYTE_TYPE
+%token jp_CASE
+%token jp_CATCH
+%token jp_CHAR_TYPE
+%token jp_CLASS
+%token jp_CONTINUE
+%token jp_DEFAULT
+%token jp_DO
+%token jp_DOUBLE_TYPE
+%token jp_ELSE
+%token jp_EXTENDS
+%token jp_FINAL
+%token jp_FINALLY
+%token jp_FLOAT_TYPE
+%token jp_FOR
+%token jp_IF
+%token jp_IMPLEMENTS
+%token jp_IMPORT
+%token jp_INSTANCEOF
+%token jp_INT_TYPE
+%token jp_INTERFACE
+%token jp_LONG_TYPE
+%token jp_NATIVE
+%token jp_NEW
+%token jp_PACKAGE
+%token jp_PRIVATE
+%token jp_PROTECTED
+%token jp_PUBLIC
+%token jp_RETURN
+%token jp_SHORT_TYPE
+%token jp_STATIC
+%token jp_STRICTFP
+%token jp_SUPER
+%token jp_SWITCH
+%token jp_SYNCHRONIZED
+%token jp_THIS
+%token jp_THROW
+%token jp_THROWS
+%token jp_TRANSIENT
+%token jp_TRY
+%token jp_VOID
+%token jp_VOLATILE
+%token jp_WHILE
+
+%token jp_BOOLEANLITERAL
+%token jp_CHARACTERLITERAL
+%token jp_DECIMALINTEGERLITERAL
+%token jp_FLOATINGPOINTLITERAL
+%token jp_HEXINTEGERLITERAL
+%token jp_NULLLITERAL
+%token jp_STRINGLITERAL
+
+%token jp_NAME
+
+%token jp_AND
+%token jp_ANDAND
+%token jp_ANDEQUALS
+%token jp_BRACKETEND
+%token jp_BRACKETSTART
+%token jp_CARROT
+%token jp_CARROTEQUALS
+%token jp_COLON
+%token jp_COMMA
+%token jp_CURLYEND
+%token jp_CURLYSTART
+%token jp_DIVIDE
+%token jp_DIVIDEEQUALS
+%token jp_DOLLAR
+%token jp_DOT
+%token jp_EQUALS
+%token jp_EQUALSEQUALS
+%token jp_EXCLAMATION
+%token jp_EXCLAMATIONEQUALS
+%token jp_GREATER
+%token jp_GTEQUALS
+%token jp_GTGT
+%token jp_GTGTEQUALS
+%token jp_GTGTGT
+%token jp_GTGTGTEQUALS
+%token jp_LESLESEQUALS
+%token jp_LESSTHAN
+%token jp_LTEQUALS
+%token jp_LTLT
+%token jp_MINUS
+%token jp_MINUSEQUALS
+%token jp_MINUSMINUS
+%token jp_PAREEND
+%token jp_PARESTART
+%token jp_PERCENT
+%token jp_PERCENTEQUALS
+%token jp_PIPE
+%token jp_PIPEEQUALS
+%token jp_PIPEPIPE
+%token jp_PLUS
+%token jp_PLUSEQUALS
+%token jp_PLUSPLUS
+%token jp_QUESTION
+%token jp_SEMICOL
+%token jp_TILDE
+%token jp_TIMES
+%token jp_TIMESEQUALS
+
+%token jp_ERROR
+
+/*-------------------------------------------------------------------------*/
+/* grammar */
+%%
+
+Goal:
+CompilationUnit
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+Literal:
+IntegerLiteral
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+jp_FLOATINGPOINTLITERAL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+jp_BOOLEANLITERAL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+jp_CHARACTERLITERAL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+jp_STRINGLITERAL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+jp_NULLLITERAL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+IntegerLiteral:
+jp_DECIMALINTEGERLITERAL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+jp_HEXINTEGERLITERAL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+Type:
+PrimitiveType
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+ReferenceType
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+PrimitiveType:
+jp_BYTE_TYPE
+{
+ jpElementStart(0);
+}
+|
+jp_SHORT_TYPE
+{
+ jpElementStart(0);
+}
+|
+jp_INT_TYPE
+{
+ jpElementStart(0);
+}
+|
+jp_LONG_TYPE
+{
+ jpElementStart(0);
+}
+|
+jp_CHAR_TYPE
+{
+ jpElementStart(0);
+}
+|
+jp_FLOAT_TYPE
+{
+ jpElementStart(0);
+}
+|
+jp_DOUBLE_TYPE
+{
+ jpElementStart(0);
+}
+|
+jp_BOOLEAN_TYPE
+{
+ jpElementStart(0);
+}
+
+ReferenceType:
+ClassOrInterfaceType
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+ArrayType
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+ClassOrInterfaceType:
+Name
+{
+ jpElementStart(1);
+ jpStoreClass($<str>1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+ClassType:
+ClassOrInterfaceType
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+InterfaceType:
+ClassOrInterfaceType
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+ArrayType:
+PrimitiveType Dims
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+Name Dims
+{
+ jpElementStart(2);
+ jpStoreClass($<str>1);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+Name:
+SimpleName
+{
+ jpElementStart(1);
+ $<str>$ = $<str>1;
+}
+|
+QualifiedName
+{
+ jpElementStart(1);
+ $<str>$ = $<str>1;
+}
+
+SimpleName:
+Identifier
+{
+ jpElementStart(1);
+ $<str>$ = $<str>1;
+}
+
+Identifier:
+jp_NAME
+{
+ jpElementStart(1);
+ $<str>$ = $<str>1;
+}
+|
+jp_DOLLAR jp_NAME
+{
+ jpElementStart(2);
+ $<str>$ = $<str>2;
+}
+
+QualifiedName:
+Name jp_DOT Identifier
+{
+ jpElementStart(3);
+ yyGetParser->AddClassFound($<str>1);
+ yyGetParser->UpdateCombine($<str>1, $<str>3);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ $<str>$ = const_cast<char*>(yyGetParser->GetCurrentCombine());
+}
+|
+Name jp_DOT jp_CLASS
+{
+ jpElementStart(3);
+ jpStoreClass($<str>1);
+ jpCheckEmpty(3);
+ yyGetParser->SetCurrentCombine("");
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+Name jp_DOT jp_THIS
+{
+ jpElementStart(3);
+ jpStoreClass($<str>1);
+ yyGetParser->SetCurrentCombine("");
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+SimpleType jp_DOT jp_CLASS
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+SimpleType:
+PrimitiveType
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+jp_VOID
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+CompilationUnit:
+PackageDeclarationopt ImportDeclarations TypeDeclarations
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+PackageDeclarationopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+PackageDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+ImportDeclarations:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+ImportDeclarations ImportDeclaration
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+TypeDeclarations:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+TypeDeclarations TypeDeclaration
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+PackageDeclaration:
+jp_PACKAGE Name jp_SEMICOL
+{
+ jpElementStart(3);
+ yyGetParser->SetCurrentPackage($<str>2);
+ yyGetParser->DeallocateParserType(&($<str>2));
+ yyGetParser->SetCurrentCombine("");
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+ImportDeclaration:
+SingleTypeImportDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+TypeImportOnDemandDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+SingleTypeImportDeclaration:
+jp_IMPORT Name jp_SEMICOL
+{
+ jpElementStart(3);
+ yyGetParser->AddPackagesImport($<str>2);
+ yyGetParser->DeallocateParserType(&($<str>2));
+ yyGetParser->SetCurrentCombine("");
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+TypeImportOnDemandDeclaration:
+jp_IMPORT Name jp_DOT jp_TIMES jp_SEMICOL
+{
+ jpElementStart(5);
+ std::string str = $<str>2;
+ str += ".*";
+ yyGetParser->AddPackagesImport(str.c_str());
+ yyGetParser->DeallocateParserType(&($<str>2));
+ yyGetParser->SetCurrentCombine("");
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+TypeDeclaration:
+ClassDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+InterfaceDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+jp_SEMICOL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+Modifiers:
+Modifier
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+Modifiers Modifier
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+Modifier:
+jp_PUBLIC | jp_PROTECTED | jp_PRIVATE |
+jp_STATIC |
+jp_ABSTRACT | jp_FINAL | jp_NATIVE | jp_SYNCHRONIZED | jp_TRANSIENT | jp_VOLATILE |
+jp_STRICTFP
+
+ClassHeader:
+Modifiersopt jp_CLASS Identifier
+{
+ yyGetParser->StartClass($<str>3);
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&($<str>3));
+ jpCheckEmpty(3);
+}
+
+
+ClassDeclaration:
+ClassHeader ClassBody
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+|
+ClassHeader Interfaces ClassBody
+{
+ jpElementStart(3);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+|
+ClassHeader Super ClassBody
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+|
+ClassHeader Super Interfaces ClassBody
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+
+Modifiersopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+Modifiers
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+Super:
+jp_EXTENDS ClassType
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+Interfaces:
+jp_IMPLEMENTS InterfaceTypeList
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+InterfaceTypeList:
+InterfaceType
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+InterfaceTypeList jp_COMMA InterfaceType
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+ClassBody:
+jp_CURLYSTART ClassBodyDeclarations jp_CURLYEND
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+ClassBodyDeclarations:
+{
+ jpElementStart(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+ClassBodyDeclarations ClassBodyDeclaration
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+ClassBodyDeclaration:
+ClassMemberDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+StaticInitializer
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+ConstructorDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+TypeDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+ClassMemberDeclaration:
+FieldDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+MethodDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+FieldDeclaration:
+Modifiersopt Type VariableDeclarators jp_SEMICOL
+{
+ jpElementStart(4);
+}
+
+VariableDeclarators:
+VariableDeclarator
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+VariableDeclarators jp_COMMA VariableDeclarator
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+VariableDeclarator:
+VariableDeclaratorId
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+VariableDeclaratorId jp_EQUALS VariableInitializer
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+VariableDeclaratorId:
+Identifier
+{
+ jpElementStart(1);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+VariableDeclaratorId jp_BRACKETSTART jp_BRACKETEND
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+VariableInitializer:
+Expression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+ArrayInitializer
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+MethodDeclaration:
+MethodHeader jp_SEMICOL
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+MethodHeader MethodBody
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+MethodHeader MethodBody jp_SEMICOL
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+
+MethodHeader:
+Modifiersopt Type MethodDeclarator Throwsopt
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Modifiersopt jp_VOID MethodDeclarator Throwsopt
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Throwsopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Throws
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+MethodDeclarator:
+Identifier jp_PARESTART FormalParameterListopt jp_PAREEND
+{
+ jpElementStart(4);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+MethodDeclarator jp_BRACKETSTART jp_BRACKETEND
+{
+ jpElementStart(3);
+
+}
+
+FormalParameterListopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+FormalParameterList
+
+FormalParameterList:
+FormalParameter
+{
+ jpElementStart(1);
+
+}
+|
+FormalParameterList jp_COMMA FormalParameter
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+FormalParameter:
+Modifiersopt Type VariableDeclaratorId
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Throws:
+jp_THROWS ClassTypeList
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ClassTypeList:
+ClassType
+{
+ jpElementStart(1);
+
+}
+|
+ClassTypeList jp_COMMA ClassType
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+MethodBody:
+Block
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+StaticInitializer:
+jp_STATIC Block
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ConstructorDeclaration:
+Modifiersopt ConstructorDeclarator Throwsopt ConstructorBody
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Modifiersopt ConstructorDeclarator Throwsopt ConstructorBody jp_SEMICOL
+{
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ConstructorDeclarator:
+SimpleName jp_PARESTART FormalParameterListopt jp_PAREEND
+{
+ jpElementStart(4);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ConstructorBody:
+jp_CURLYSTART ExplicitConstructorInvocationopt BlockStatementsopt jp_CURLYEND
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ExplicitConstructorInvocationopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ExplicitConstructorInvocationopt ExplicitConstructorInvocation
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ExplicitConstructorInvocation:
+jp_THIS jp_PARESTART ArgumentListopt jp_PAREEND jp_SEMICOL
+{
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_SUPER jp_PARESTART ArgumentListopt jp_PAREEND jp_SEMICOL
+{
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+InterfaceHeader:
+Modifiersopt jp_INTERFACE Identifier
+{
+ yyGetParser->StartClass($<str>3);
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&($<str>3));
+ jpCheckEmpty(3);
+}
+
+InterfaceDeclaration:
+InterfaceHeader ExtendsInterfacesopt InterfaceBody
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+ yyGetParser->EndClass();
+}
+
+ExtendsInterfacesopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+}
+|
+ExtendsInterfaces
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ExtendsInterfaces:
+jp_EXTENDS InterfaceType
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ExtendsInterfaces jp_COMMA InterfaceType
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+InterfaceBody:
+jp_CURLYSTART InterfaceMemberDeclarations jp_CURLYEND
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+InterfaceMemberDeclarations:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+InterfaceMemberDeclarations InterfaceMemberDeclaration
+{
+ jpElementStart(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+InterfaceMemberDeclaration:
+ConstantDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+AbstractMethodDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ClassDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ClassDeclaration jp_SEMICOL
+{
+ jpElementStart(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+InterfaceDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+InterfaceDeclaration jp_SEMICOL
+{
+ jpElementStart(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ConstantDeclaration:
+FieldDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+AbstractMethodDeclaration:
+MethodHeader Semicols
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Semicols:
+jp_SEMICOL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Semicols jp_SEMICOL
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ArrayInitializer:
+jp_CURLYSTART VariableInitializersOptional jp_CURLYEND
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+VariableInitializersOptional:
+{
+ jpElementStart(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+VariableInitializers
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+VariableInitializers jp_COMMA
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+VariableInitializers:
+VariableInitializer
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+VariableInitializers jp_COMMA VariableInitializer
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Block:
+jp_CURLYSTART BlockStatementsopt jp_CURLYEND
+{
+ jpElementStart(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+BlockStatementsopt:
+{
+ jpElementStart(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+BlockStatements
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+BlockStatements:
+BlockStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+BlockStatements BlockStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+BlockStatement:
+LocalVariableDeclarationStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Statement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ClassDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+LocalVariableDeclarationStatement:
+LocalVariableDeclaration jp_SEMICOL
+{
+ jpElementStart(1);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+LocalVariableDeclaration:
+Modifiers Type VariableDeclarators
+{
+ jpElementStart(1);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Type VariableDeclarators
+{
+ jpElementStart(1);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Statement:
+StatementWithoutTrailingSubstatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+LabeledStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+IfThenStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+IfThenElseStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+WhileStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ForStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+StatementNoShortIf:
+StatementWithoutTrailingSubstatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+LabeledStatementNoShortIf
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+IfThenElseStatementNoShortIf
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+WhileStatementNoShortIf
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ForStatementNoShortIf
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+StatementWithoutTrailingSubstatement:
+Block
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+EmptyStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ExpressionStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+SwitchStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+DoStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+BreakStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ContinueStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ReturnStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+SynchronizedStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ThrowStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+TryStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+AssertStatement
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+EmptyStatement:
+jp_SEMICOL
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+LabeledStatement:
+Identifier jp_COLON Statement
+{
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+LabeledStatementNoShortIf:
+Identifier jp_COLON StatementNoShortIf
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ExpressionStatement:
+StatementExpression jp_SEMICOL
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+StatementExpression:
+Assignment
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+PreIncrementExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+PreDecrementExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+PostIncrementExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+PostDecrementExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+MethodInvocation
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ClassInstanceCreationExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+IfThenStatement:
+jp_IF jp_PARESTART Expression jp_PAREEND Statement
+{
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+IfThenElseStatement:
+jp_IF jp_PARESTART Expression jp_PAREEND StatementNoShortIf jp_ELSE Statement
+{
+ jpElementStart(7);
+ jpCheckEmpty(7);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+IfThenElseStatementNoShortIf:
+jp_IF jp_PARESTART Expression jp_PAREEND StatementNoShortIf jp_ELSE StatementNoShortIf
+{
+ jpElementStart(7);
+ jpCheckEmpty(7);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+SwitchStatement:
+jp_SWITCH jp_PARESTART Expression jp_PAREEND SwitchBlock
+{
+ jpElementStart(5);
+
+}
+
+SwitchBlock:
+jp_CURLYSTART SwitchBlockStatementGroups SwitchLabelsopt jp_CURLYEND
+{
+ jpElementStart(4);
+
+}
+
+SwitchLabelsopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+SwitchLabels
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+SwitchBlockStatementGroups:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+SwitchBlockStatementGroups SwitchBlockStatementGroup
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+SwitchBlockStatementGroup:
+SwitchLabels BlockStatements
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+SwitchLabels:
+SwitchLabel
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+SwitchLabels SwitchLabel
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+SwitchLabel:
+jp_CASE ConstantExpression jp_COLON
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_DEFAULT jp_COLON
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+WhileStatement:
+jp_WHILE jp_PARESTART Expression jp_PAREEND Statement
+{
+ jpElementStart(5);
+
+}
+
+WhileStatementNoShortIf:
+jp_WHILE jp_PARESTART Expression jp_PAREEND StatementNoShortIf
+{
+ jpElementStart(5);
+
+}
+
+DoStatement:
+jp_DO Statement jp_WHILE jp_PARESTART Expression jp_PAREEND jp_SEMICOL
+{
+ jpElementStart(7);
+
+}
+
+ForStatement:
+jp_FOR jp_PARESTART ForInitopt jp_SEMICOL Expressionopt jp_SEMICOL ForUpdateopt jp_PAREEND
+Statement
+{
+ jpElementStart(9);
+
+}
+
+ForUpdateopt:
+{
+ jpElementStart(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ForUpdate
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ForInitopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ForInit
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ForStatementNoShortIf:
+jp_FOR jp_PARESTART ForInitopt jp_SEMICOL Expressionopt jp_SEMICOL ForUpdateopt jp_PAREEND
+StatementNoShortIf
+{
+ jpElementStart(9);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Expressionopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Expression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ForInit:
+StatementExpressionList
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+LocalVariableDeclaration
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ForUpdate:
+StatementExpressionList
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+StatementExpressionList:
+StatementExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+StatementExpressionList jp_COMMA StatementExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+AssertStatement:
+jp_ASSERT Expression jp_SEMICOL
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_ASSERT Expression jp_COLON Expression jp_SEMICOL
+{
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+BreakStatement:
+jp_BREAK Identifieropt jp_SEMICOL
+{
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&($<str>2));
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Identifieropt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Identifier
+{
+ jpElementStart(1);
+
+}
+
+ContinueStatement:
+jp_CONTINUE Identifieropt jp_SEMICOL
+{
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&($<str>2));
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ReturnStatement:
+jp_RETURN Expressionopt jp_SEMICOL
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ThrowStatement:
+jp_THROW Expression jp_SEMICOL
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+SynchronizedStatement:
+jp_SYNCHRONIZED jp_PARESTART Expression jp_PAREEND Block
+{
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+TryStatement:
+jp_TRY Block Catches
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_TRY Block Catchesopt Finally
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Catchesopt:
+{
+ jpElementStart(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Catches
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Catches:
+CatchClause
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Catches CatchClause
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+CatchClause:
+jp_CATCH jp_PARESTART FormalParameter jp_PAREEND Block
+{
+ jpElementStart(5);
+
+}
+
+Finally:
+jp_FINALLY Block
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Primary:
+PrimaryNoNewArray
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ArrayCreationExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+PrimaryNoNewArray:
+Literal
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_THIS
+{
+ jpElementStart(1);
+
+}
+|
+jp_PARESTART Expression jp_PAREEND
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ClassInstanceCreationExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+FieldAccess
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+MethodInvocation
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ArrayAccess
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ClassInstanceCreationExpression:
+New ClassType jp_PARESTART ArgumentListopt jp_PAREEND ClassBodyOpt
+{
+ jpElementStart(6);
+ jpCheckEmpty(6);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ClassBodyOpt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ClassBody
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ArgumentListopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ArgumentList
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ArgumentList:
+Expression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ArgumentList jp_COMMA Expression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ArrayCreationExpression:
+New PrimitiveType DimExprs Dimsopt
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+New ClassOrInterfaceType DimExprs Dimsopt
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+New PrimitiveType Dims ArrayInitializer
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+New ClassOrInterfaceType Dims ArrayInitializer
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Dimsopt:
+{
+ jpElementStart(0);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Dims
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+DimExprs:
+DimExpr
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+DimExprs DimExpr
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+DimExpr:
+jp_BRACKETSTART Expression jp_BRACKETEND
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Dims:
+jp_BRACKETSTART jp_BRACKETEND
+{
+ jpElementStart(2);
+
+}
+|
+Dims jp_BRACKETSTART jp_BRACKETEND
+{
+ jpElementStart(3);
+
+}
+
+FieldAccess:
+Primary jp_DOT Identifier
+{
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&($<str>3));
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_SUPER jp_DOT Identifier
+{
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&($<str>3));
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_THIS jp_DOT Identifier
+{
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&($<str>3));
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Primary jp_DOT jp_THIS
+{
+ jpElementStart(3);
+ yyGetParser->DeallocateParserType(&($<str>3));
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+MethodInvocation:
+Name jp_PARESTART ArgumentListopt jp_PAREEND
+{
+ jpElementStart(4);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Primary jp_DOT Identifier jp_PARESTART ArgumentListopt jp_PAREEND
+{
+ jpElementStart(6);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ yyGetParser->DeallocateParserType(&($<str>3));
+ jpCheckEmpty(6);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_SUPER jp_DOT Identifier jp_PARESTART ArgumentListopt jp_PAREEND
+{
+ jpElementStart(6);
+ yyGetParser->DeallocateParserType(&($<str>3));
+ jpCheckEmpty(6);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_THIS jp_DOT Identifier jp_PARESTART ArgumentListopt jp_PAREEND
+{
+ jpElementStart(6);
+ yyGetParser->DeallocateParserType(&($<str>3));
+ jpCheckEmpty(6);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ArrayAccess:
+Name jp_BRACKETSTART Expression jp_BRACKETEND
+{
+ jpElementStart(4);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+PrimaryNoNewArray jp_BRACKETSTART Expression jp_BRACKETEND
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+PostfixExpression:
+Primary
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Name
+{
+ jpElementStart(1);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ArrayType jp_DOT jp_CLASS
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+PostIncrementExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+PostDecrementExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+PostIncrementExpression:
+PostfixExpression jp_PLUSPLUS
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+PostDecrementExpression:
+PostfixExpression jp_MINUSMINUS
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+UnaryExpression:
+PreIncrementExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+PreDecrementExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_PLUS UnaryExpression
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_MINUS UnaryExpression
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+UnaryExpressionNotPlusMinus
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+PreIncrementExpression:
+jp_PLUSPLUS UnaryExpression
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+PreDecrementExpression:
+jp_MINUSMINUS UnaryExpression
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+UnaryExpressionNotPlusMinus:
+PostfixExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_TILDE UnaryExpression
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_EXCLAMATION UnaryExpression
+{
+ jpElementStart(2);
+ jpCheckEmpty(2);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+CastExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+CastExpression:
+jp_PARESTART PrimitiveType Dimsopt jp_PAREEND UnaryExpression
+{
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_PARESTART Expression jp_PAREEND UnaryExpressionNotPlusMinus
+{
+ jpElementStart(4);
+ jpCheckEmpty(4);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_PARESTART Name Dims jp_PAREEND UnaryExpressionNotPlusMinus
+{
+ jpElementStart(5);
+
+}
+
+MultiplicativeExpression:
+UnaryExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+MultiplicativeExpression jp_TIMES UnaryExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+MultiplicativeExpression jp_DIVIDE UnaryExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+MultiplicativeExpression jp_PERCENT UnaryExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+AdditiveExpression:
+MultiplicativeExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+AdditiveExpression jp_PLUS MultiplicativeExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+AdditiveExpression jp_MINUS MultiplicativeExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ShiftExpression:
+AdditiveExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ShiftExpression jp_LTLT AdditiveExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ShiftExpression jp_GTGT AdditiveExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ShiftExpression jp_GTGTGT AdditiveExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+RelationalExpression:
+ShiftExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+RelationalExpression jp_LESSTHAN ShiftExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+RelationalExpression jp_GREATER ShiftExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+RelationalExpression jp_LTEQUALS ShiftExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+RelationalExpression jp_GTEQUALS ShiftExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+RelationalExpression jp_INSTANCEOF ReferenceType
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+EqualityExpression:
+RelationalExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+EqualityExpression jp_EQUALSEQUALS RelationalExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+EqualityExpression jp_EXCLAMATIONEQUALS RelationalExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+AndExpression:
+EqualityExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+AndExpression jp_AND EqualityExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ExclusiveOrExpression:
+AndExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ExclusiveOrExpression jp_CARROT AndExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+InclusiveOrExpression:
+ExclusiveOrExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+InclusiveOrExpression jp_PIPE ExclusiveOrExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ConditionalAndExpression:
+InclusiveOrExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ConditionalAndExpression jp_ANDAND InclusiveOrExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ConditionalOrExpression:
+ConditionalAndExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ConditionalOrExpression jp_PIPEPIPE ConditionalAndExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ConditionalExpression:
+ConditionalOrExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ConditionalOrExpression jp_QUESTION Expression jp_COLON ConditionalExpression
+{
+ jpElementStart(5);
+ jpCheckEmpty(5);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+AssignmentExpression:
+ConditionalExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Assignment
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Assignment:
+LeftHandSide AssignmentOperator AssignmentExpression
+{
+ jpElementStart(3);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+LeftHandSide:
+Name
+{
+ jpElementStart(1);
+ yyGetParser->DeallocateParserType(&($<str>1));
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+FieldAccess
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+ArrayAccess
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+AssignmentOperator:
+jp_EQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_TIMESEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_DIVIDEEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_PERCENTEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_PLUSEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_MINUSEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_LESLESEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_GTGTEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_GTGTGTEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_ANDEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_CARROTEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+jp_PIPEEQUALS
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+Expression:
+AssignmentExpression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+ConstantExpression:
+Expression
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+New:
+jp_NEW
+{
+ jpElementStart(1);
+ jpCheckEmpty(1);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+|
+Name jp_DOT jp_NEW
+{
+ jpElementStart(3);
+ jpStoreClass($<str>1);
+ jpCheckEmpty(3);
+ $<str>$ = 0;
+ yyGetParser->SetCurrentCombine("");
+
+}
+
+%%
+/* End of grammar */
+
+/*--------------------------------------------------------------------------*/
+void cmDependsJavaError(yyscan_t yyscanner, const char* message)
+{
+ yyGetParser->Error(message);
+}
+
diff --git a/Source/cmDependsJavaParserHelper.cxx b/Source/cmDependsJavaParserHelper.cxx
new file mode 100644
index 0000000000..02f2d21d68
--- /dev/null
+++ b/Source/cmDependsJavaParserHelper.cxx
@@ -0,0 +1,430 @@
+/*============================================================================
+ 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 "cmDependsJavaParserHelper.h"
+
+#include "cmSystemTools.h"
+#include "cmDependsJavaLexer.h"
+#include <cmsys/FStream.hxx>
+
+int cmDependsJava_yyparse( yyscan_t yyscanner );
+
+cmDependsJavaParserHelper::cmDependsJavaParserHelper()
+{
+ this->CurrentDepth = 0;
+
+ this->UnionsAvailable = 0;
+ this->LastClassId = 0;
+
+ CurrentClass tl;
+ tl.Name = "*";
+ this->ClassStack.push_back(tl);
+}
+
+
+cmDependsJavaParserHelper::~cmDependsJavaParserHelper()
+{
+ this->CleanupParser();
+}
+
+void cmDependsJavaParserHelper::CurrentClass
+::AddFileNamesForPrinting(std::vector<std::string> *files,
+ const char* prefix, const char* sep)
+{
+ std::string rname = "";
+ if ( prefix )
+ {
+ rname += prefix;
+ rname += sep;
+ }
+ rname += this->Name;
+ files->push_back(rname);
+ std::vector<CurrentClass>::iterator it;
+ for ( it = this->NestedClasses->begin();
+ it != this->NestedClasses->end();
+ ++ it )
+ {
+ it->AddFileNamesForPrinting(files, rname.c_str(), sep);
+ }
+}
+
+void cmDependsJavaParserHelper::DeallocateParserType(char** pt)
+{
+ if (!pt)
+ {
+ return;
+ }
+ if (!*pt)
+ {
+ return;
+ }
+ *pt = 0;
+ this->UnionsAvailable --;
+}
+
+void cmDependsJavaParserHelper::AddClassFound(const char* sclass)
+{
+ if( ! sclass )
+ {
+ return;
+ }
+ std::vector<std::string>::iterator it;
+ for ( it = this->ClassesFound.begin();
+ it != this->ClassesFound.end();
+ it ++ )
+ {
+ if ( *it == sclass )
+ {
+ return;
+ }
+ }
+ this->ClassesFound.push_back(sclass);
+}
+
+void cmDependsJavaParserHelper::AddPackagesImport(const char* sclass)
+{
+ std::vector<std::string>::iterator it;
+ for ( it = this->PackagesImport.begin();
+ it != this->PackagesImport.end();
+ it ++ )
+ {
+ if ( *it == sclass )
+ {
+ return;
+ }
+ }
+ this->PackagesImport.push_back(sclass);
+}
+
+void cmDependsJavaParserHelper::SafePrintMissing(const char* str,
+ int line, int cnt)
+{
+ if ( str )
+ {
+ std::cout << line << " String " << cnt << " exists: ";
+ unsigned int cc;
+ for ( cc = 0; cc < strlen(str); cc ++ )
+ {
+ unsigned char ch = str[cc];
+ if ( ch >= 32 && ch <= 126 )
+ {
+ std::cout << (char)ch;
+ }
+ else
+ {
+ std::cout << "<" << (int)ch << ">";
+ break;
+ }
+ }
+ std::cout << "- " << strlen(str) << std::endl;
+ }
+}
+void cmDependsJavaParserHelper::Print(const char* place, const char* str)
+{
+ if ( this->Verbose )
+ {
+ std::cout << "[" << place << "=" << str << "]" << std::endl;
+ }
+}
+
+void cmDependsJavaParserHelper::CombineUnions(char** out,
+ const char* in1, char** in2,
+ const char* sep)
+{
+ size_t len = 1;
+ if ( in1 )
+ {
+ len += strlen(in1);
+ }
+ if ( *in2 )
+ {
+ len += strlen(*in2);
+ }
+ if ( sep )
+ {
+ len += strlen(sep);
+ }
+ *out = new char [ len ];
+ *out[0] = 0;
+ if ( in1 )
+ {
+ strcat(*out, in1);
+ }
+ if ( sep )
+ {
+ strcat(*out, sep);
+ }
+ if ( *in2 )
+ {
+ strcat(*out, *in2);
+ }
+ if ( *in2 )
+ {
+ this->DeallocateParserType(in2);
+ }
+ this->UnionsAvailable ++;
+}
+
+void cmDependsJavaParserHelper
+::CheckEmpty(int line, int cnt, cmDependsJavaParserHelper::ParserType* pt)
+{
+ int cc;
+ int kk = -cnt + 1;
+ for ( cc = 1; cc <= cnt; cc ++)
+ {
+ cmDependsJavaParserHelper::ParserType* cpt = pt + kk;
+ this->SafePrintMissing(cpt->str, line, cc);
+ kk ++;
+ }
+}
+
+void cmDependsJavaParserHelper
+::PrepareElement(cmDependsJavaParserHelper::ParserType* me)
+{
+ // Inititalize self
+ me->str = 0;
+}
+
+void cmDependsJavaParserHelper
+::AllocateParserType(cmDependsJavaParserHelper::ParserType* pt,
+ const char* str, int len)
+{
+ pt->str = 0;
+ if ( len == 0 )
+ {
+ len = (int)strlen(str);
+ }
+ if ( len == 0 )
+ {
+ return;
+ }
+ this->UnionsAvailable ++;
+ pt->str = new char[ len + 1 ];
+ strncpy(pt->str, str, len);
+ pt->str[len] = 0;
+ this->Allocates.push_back(pt->str);
+}
+
+void cmDependsJavaParserHelper::StartClass(const char* cls)
+{
+ CurrentClass cl;
+ cl.Name = cls;
+ this->ClassStack.push_back(cl);
+
+ this->CurrentDepth ++;
+}
+
+void cmDependsJavaParserHelper::EndClass()
+{
+ CurrentClass* parent = 0;
+ CurrentClass* current = 0;
+ if ( this->ClassStack.size() > 0 )
+ {
+ current = &(*(this->ClassStack.end() - 1));
+ if ( this->ClassStack.size() > 1 )
+ {
+ parent = &(*(this->ClassStack.end() - 2));
+ }
+ }
+ if ( current == 0 )
+ {
+ std::cerr << "Error when parsing. Current class is null" << std::endl;
+ abort();
+ }
+ if ( parent == 0 )
+ {
+ std::cerr << "Error when parsing. Parent class is null" << std::endl;
+ abort();
+ }
+ this->CurrentDepth --;
+ parent->NestedClasses->push_back(*current);
+ this->ClassStack.erase(this->ClassStack.end()-1, this->ClassStack.end());
+}
+
+void cmDependsJavaParserHelper::PrintClasses()
+{
+ if ( this->ClassStack.size() == 0 )
+ {
+ std::cerr << "Error when parsing. No classes on class stack" << std::endl;
+ abort();
+ }
+ std::vector<std::string> files = this->GetFilesProduced();
+ std::vector<std::string>::iterator sit;
+ for ( sit = files.begin();
+ sit != files.end();
+ ++ sit )
+ {
+ std::cout << " " << *sit << ".class" << std::endl;
+ }
+}
+
+std::vector<std::string> cmDependsJavaParserHelper::GetFilesProduced()
+{
+ std::vector<std::string> files;
+ CurrentClass* toplevel = &(*(this->ClassStack.begin()));
+ std::vector<CurrentClass>::iterator it;
+ for ( it = toplevel->NestedClasses->begin();
+ it != toplevel->NestedClasses->end();
+ ++ it )
+ {
+ it->AddFileNamesForPrinting(&files, 0, "$");
+ }
+ return files;
+}
+
+int cmDependsJavaParserHelper::ParseString(const char* str, int verb)
+{
+ if ( !str)
+ {
+ return 0;
+ }
+ this->Verbose = verb;
+ this->InputBuffer = str;
+ this->InputBufferPos = 0;
+ this->CurrentLine = 0;
+
+
+ yyscan_t yyscanner;
+ cmDependsJava_yylex_init(&yyscanner);
+ cmDependsJava_yyset_extra(this, yyscanner);
+ int res = cmDependsJava_yyparse(yyscanner);
+ cmDependsJava_yylex_destroy(yyscanner);
+ if ( res != 0 )
+ {
+ std::cout << "JP_Parse returned: " << res << std::endl;
+ return 0;
+ }
+
+ if ( verb )
+ {
+ if ( this->CurrentPackage.size() > 0 )
+ {
+ std::cout << "Current package is: " <<
+ this->CurrentPackage << std::endl;
+ }
+ std::cout << "Imports packages:";
+ if ( this->PackagesImport.size() > 0 )
+ {
+ std::vector<std::string>::iterator it;
+ for ( it = this->PackagesImport.begin();
+ it != this->PackagesImport.end();
+ ++ it )
+ {
+ std::cout << " " << *it;
+ }
+ }
+ std::cout << std::endl;
+ std::cout << "Depends on:";
+ if ( this->ClassesFound.size() > 0 )
+ {
+ std::vector<std::string>::iterator it;
+ for ( it = this->ClassesFound.begin();
+ it != this->ClassesFound.end();
+ ++ it )
+ {
+ std::cout << " " << *it;
+ }
+ }
+ std::cout << std::endl;
+ std::cout << "Generated files:" << std::endl;
+ this->PrintClasses();
+ if ( this->UnionsAvailable != 0 )
+ {
+ std::cout << "There are still " <<
+ this->UnionsAvailable << " unions available" << std::endl;
+ }
+ }
+ this->CleanupParser();
+ return 1;
+}
+
+void cmDependsJavaParserHelper::CleanupParser()
+{
+ std::vector<char*>::iterator it;
+ for ( it = this->Allocates.begin();
+ it != this->Allocates.end();
+ ++ it )
+ {
+ delete [] *it;
+ }
+ this->Allocates.erase(this->Allocates.begin(),
+ this->Allocates.end());
+}
+
+int cmDependsJavaParserHelper::LexInput(char* buf, int maxlen)
+{
+ if ( maxlen < 1 )
+ {
+ return 0;
+ }
+ if ( this->InputBufferPos < this->InputBuffer.size() )
+ {
+ buf[0] = this->InputBuffer[ this->InputBufferPos++ ];
+ if ( buf[0] == '\n' )
+ {
+ this->CurrentLine ++;
+ }
+ return(1);
+ }
+ else
+ {
+ buf[0] = '\n';
+ return( 0 );
+ }
+}
+void cmDependsJavaParserHelper::Error(const char* str)
+{
+ unsigned long pos = static_cast<unsigned long>(this->InputBufferPos);
+ fprintf(stderr, "JPError: %s (%lu / Line: %d)\n",
+ str, pos, this->CurrentLine);
+ int cc;
+ std::cerr << "String: [";
+ for ( cc = 0;
+ cc < 30 && *(this->InputBuffer.c_str() + this->InputBufferPos + cc);
+ cc ++ )
+ {
+ std::cerr << *(this->InputBuffer.c_str() + this->InputBufferPos + cc);
+ }
+ std::cerr << "]" << std::endl;
+}
+
+void cmDependsJavaParserHelper::UpdateCombine(const char* str1,
+ const char* str2)
+{
+ if ( this->CurrentCombine == "" && str1 != 0)
+ {
+ this->CurrentCombine = str1;
+ }
+ this->CurrentCombine += ".";
+ this->CurrentCombine += str2;
+}
+
+int cmDependsJavaParserHelper::ParseFile(const char* file)
+{
+ if ( !cmSystemTools::FileExists(file))
+ {
+ return 0;
+ }
+ cmsys::ifstream ifs(file);
+ if ( !ifs )
+ {
+ return 0;
+ }
+
+ std::string fullfile = "";
+ std::string line;
+ while ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ fullfile += line + "\n";
+ }
+ return this->ParseString(fullfile.c_str(), 0);
+}
+
diff --git a/Source/cmDependsJavaParserHelper.h b/Source/cmDependsJavaParserHelper.h
new file mode 100644
index 0000000000..5542018946
--- /dev/null
+++ b/Source/cmDependsJavaParserHelper.h
@@ -0,0 +1,128 @@
+/*============================================================================
+ 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 cmDependsJavaParserHelper_h
+#define cmDependsJavaParserHelper_h
+
+#include "cmStandardIncludes.h"
+
+#define YYSTYPE cmDependsJavaParserHelper::ParserType
+#define YYSTYPE_IS_DECLARED
+#define YY_EXTRA_TYPE cmDependsJavaParserHelper*
+#define YY_DECL int cmDependsJava_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
+
+/** \class cmDependsJavaParserHelper
+ * \brief Helper class for parsing java source files
+ *
+ * Finds dependencies for java file and list of outputs
+ */
+
+class cmDependsJavaParserHelper
+{
+public:
+ typedef struct {
+ char* str;
+ } ParserType;
+
+ cmDependsJavaParserHelper();
+ ~cmDependsJavaParserHelper();
+
+ int ParseString(const char* str, int verb);
+ int ParseFile(const char* file);
+
+ // For the lexer:
+ void AllocateParserType(cmDependsJavaParserHelper::ParserType* pt,
+ const char* str, int len = 0);
+
+ int LexInput(char* buf, int maxlen);
+ void Error(const char* str);
+
+ // For yacc
+ void AddClassFound(const char* sclass);
+ void PrepareElement(ParserType* opt);
+ void DeallocateParserType(char** pt);
+ void CheckEmpty(int line, int cnt, ParserType* pt);
+ void StartClass(const char* cls);
+ void EndClass();
+ void AddPackagesImport(const char* sclass);
+ void SetCurrentPackage(const char* pkg) { this->CurrentPackage = pkg; }
+ const char* GetCurrentPackage() { return this->CurrentPackage.c_str(); }
+ void SetCurrentCombine(const char* cmb) { this->CurrentCombine = cmb; }
+ const char* GetCurrentCombine() { return this->CurrentCombine.c_str(); }
+ void UpdateCombine(const char* str1, const char* str2);
+
+ std::vector<std::string>& GetClassesFound() { return this->ClassesFound; }
+
+ std::vector<std::string> GetFilesProduced();
+
+private:
+ class CurrentClass
+ {
+ public:
+ std::string Name;
+ std::vector<CurrentClass>* NestedClasses;
+ CurrentClass()
+ {
+ this->NestedClasses = new std::vector<CurrentClass>;
+ }
+ ~CurrentClass()
+ {
+ delete this->NestedClasses;
+ }
+ CurrentClass& operator=(CurrentClass const& c)
+ {
+ this->NestedClasses->clear();
+ this->Name = c.Name;
+ std::copy(
+ c.NestedClasses->begin(),
+ c.NestedClasses->end(),
+ std::back_inserter(
+ *this->NestedClasses)
+ );
+ return *this;
+ }
+ CurrentClass(CurrentClass const& c)
+ {
+ (*this) = c;
+ }
+ void AddFileNamesForPrinting(std::vector<std::string> *files,
+ const char* prefix, const char* sep);
+ };
+ std::string CurrentPackage;
+ std::string::size_type InputBufferPos;
+ std::string InputBuffer;
+ std::vector<char> OutputBuffer;
+ std::vector<std::string> ClassesFound;
+ std::vector<std::string> PackagesImport;
+ std::string CurrentCombine;
+
+ std::vector<CurrentClass> ClassStack;
+
+ int CurrentLine;
+ int UnionsAvailable;
+ int LastClassId;
+ int CurrentDepth;
+ int Verbose;
+
+ std::vector<char*> Allocates;
+
+ void PrintClasses();
+
+ void Print(const char* place, const char* str);
+ void CombineUnions(char** out, const char* in1, char** in2,
+ const char* sep);
+ void SafePrintMissing(const char* str, int line, int cnt);
+
+ void CleanupParser();
+};
+
+#endif
+
diff --git a/Source/cmDependsJavaParserTokens.h b/Source/cmDependsJavaParserTokens.h
new file mode 100644
index 0000000000..c7a414f07b
--- /dev/null
+++ b/Source/cmDependsJavaParserTokens.h
@@ -0,0 +1,254 @@
+/* A Bison parser, made by GNU Bison 1.875d. */
+
+/* Skeleton parser for Yacc-like parsing with Bison, Copyright (C) 1984,
+ 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* As a special exception, when this file is copied by Bison into a
+ Bison output file, you may use that output file without restriction.
+ This special exception was added by the Free Software Foundation
+ in version 1.24 of Bison. */
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ jp_ABSTRACT = 258,
+ jp_ASSERT = 259,
+ jp_BOOLEAN_TYPE = 260,
+ jp_BREAK = 261,
+ jp_BYTE_TYPE = 262,
+ jp_CASE = 263,
+ jp_CATCH = 264,
+ jp_CHAR_TYPE = 265,
+ jp_CLASS = 266,
+ jp_CONTINUE = 267,
+ jp_DEFAULT = 268,
+ jp_DO = 269,
+ jp_DOUBLE_TYPE = 270,
+ jp_ELSE = 271,
+ jp_EXTENDS = 272,
+ jp_FINAL = 273,
+ jp_FINALLY = 274,
+ jp_FLOAT_TYPE = 275,
+ jp_FOR = 276,
+ jp_IF = 277,
+ jp_IMPLEMENTS = 278,
+ jp_IMPORT = 279,
+ jp_INSTANCEOF = 280,
+ jp_INT_TYPE = 281,
+ jp_INTERFACE = 282,
+ jp_LONG_TYPE = 283,
+ jp_NATIVE = 284,
+ jp_NEW = 285,
+ jp_PACKAGE = 286,
+ jp_PRIVATE = 287,
+ jp_PROTECTED = 288,
+ jp_PUBLIC = 289,
+ jp_RETURN = 290,
+ jp_SHORT_TYPE = 291,
+ jp_STATIC = 292,
+ jp_STRICTFP = 293,
+ jp_SUPER = 294,
+ jp_SWITCH = 295,
+ jp_SYNCHRONIZED = 296,
+ jp_THIS = 297,
+ jp_THROW = 298,
+ jp_THROWS = 299,
+ jp_TRANSIENT = 300,
+ jp_TRY = 301,
+ jp_VOID = 302,
+ jp_VOLATILE = 303,
+ jp_WHILE = 304,
+ jp_BOOLEANLITERAL = 305,
+ jp_CHARACTERLITERAL = 306,
+ jp_DECIMALINTEGERLITERAL = 307,
+ jp_FLOATINGPOINTLITERAL = 308,
+ jp_HEXINTEGERLITERAL = 309,
+ jp_NULLLITERAL = 310,
+ jp_STRINGLITERAL = 311,
+ jp_NAME = 312,
+ jp_AND = 313,
+ jp_ANDAND = 314,
+ jp_ANDEQUALS = 315,
+ jp_BRACKETEND = 316,
+ jp_BRACKETSTART = 317,
+ jp_CARROT = 318,
+ jp_CARROTEQUALS = 319,
+ jp_COLON = 320,
+ jp_COMMA = 321,
+ jp_CURLYEND = 322,
+ jp_CURLYSTART = 323,
+ jp_DIVIDE = 324,
+ jp_DIVIDEEQUALS = 325,
+ jp_DOLLAR = 326,
+ jp_DOT = 327,
+ jp_EQUALS = 328,
+ jp_EQUALSEQUALS = 329,
+ jp_EXCLAMATION = 330,
+ jp_EXCLAMATIONEQUALS = 331,
+ jp_GREATER = 332,
+ jp_GTEQUALS = 333,
+ jp_GTGT = 334,
+ jp_GTGTEQUALS = 335,
+ jp_GTGTGT = 336,
+ jp_GTGTGTEQUALS = 337,
+ jp_LESLESEQUALS = 338,
+ jp_LESSTHAN = 339,
+ jp_LTEQUALS = 340,
+ jp_LTLT = 341,
+ jp_MINUS = 342,
+ jp_MINUSEQUALS = 343,
+ jp_MINUSMINUS = 344,
+ jp_PAREEND = 345,
+ jp_PARESTART = 346,
+ jp_PERCENT = 347,
+ jp_PERCENTEQUALS = 348,
+ jp_PIPE = 349,
+ jp_PIPEEQUALS = 350,
+ jp_PIPEPIPE = 351,
+ jp_PLUS = 352,
+ jp_PLUSEQUALS = 353,
+ jp_PLUSPLUS = 354,
+ jp_QUESTION = 355,
+ jp_SEMICOL = 356,
+ jp_TILDE = 357,
+ jp_TIMES = 358,
+ jp_TIMESEQUALS = 359,
+ jp_ERROR = 360
+ };
+#endif
+#define jp_ABSTRACT 258
+#define jp_ASSERT 259
+#define jp_BOOLEAN_TYPE 260
+#define jp_BREAK 261
+#define jp_BYTE_TYPE 262
+#define jp_CASE 263
+#define jp_CATCH 264
+#define jp_CHAR_TYPE 265
+#define jp_CLASS 266
+#define jp_CONTINUE 267
+#define jp_DEFAULT 268
+#define jp_DO 269
+#define jp_DOUBLE_TYPE 270
+#define jp_ELSE 271
+#define jp_EXTENDS 272
+#define jp_FINAL 273
+#define jp_FINALLY 274
+#define jp_FLOAT_TYPE 275
+#define jp_FOR 276
+#define jp_IF 277
+#define jp_IMPLEMENTS 278
+#define jp_IMPORT 279
+#define jp_INSTANCEOF 280
+#define jp_INT_TYPE 281
+#define jp_INTERFACE 282
+#define jp_LONG_TYPE 283
+#define jp_NATIVE 284
+#define jp_NEW 285
+#define jp_PACKAGE 286
+#define jp_PRIVATE 287
+#define jp_PROTECTED 288
+#define jp_PUBLIC 289
+#define jp_RETURN 290
+#define jp_SHORT_TYPE 291
+#define jp_STATIC 292
+#define jp_STRICTFP 293
+#define jp_SUPER 294
+#define jp_SWITCH 295
+#define jp_SYNCHRONIZED 296
+#define jp_THIS 297
+#define jp_THROW 298
+#define jp_THROWS 299
+#define jp_TRANSIENT 300
+#define jp_TRY 301
+#define jp_VOID 302
+#define jp_VOLATILE 303
+#define jp_WHILE 304
+#define jp_BOOLEANLITERAL 305
+#define jp_CHARACTERLITERAL 306
+#define jp_DECIMALINTEGERLITERAL 307
+#define jp_FLOATINGPOINTLITERAL 308
+#define jp_HEXINTEGERLITERAL 309
+#define jp_NULLLITERAL 310
+#define jp_STRINGLITERAL 311
+#define jp_NAME 312
+#define jp_AND 313
+#define jp_ANDAND 314
+#define jp_ANDEQUALS 315
+#define jp_BRACKETEND 316
+#define jp_BRACKETSTART 317
+#define jp_CARROT 318
+#define jp_CARROTEQUALS 319
+#define jp_COLON 320
+#define jp_COMMA 321
+#define jp_CURLYEND 322
+#define jp_CURLYSTART 323
+#define jp_DIVIDE 324
+#define jp_DIVIDEEQUALS 325
+#define jp_DOLLAR 326
+#define jp_DOT 327
+#define jp_EQUALS 328
+#define jp_EQUALSEQUALS 329
+#define jp_EXCLAMATION 330
+#define jp_EXCLAMATIONEQUALS 331
+#define jp_GREATER 332
+#define jp_GTEQUALS 333
+#define jp_GTGT 334
+#define jp_GTGTEQUALS 335
+#define jp_GTGTGT 336
+#define jp_GTGTGTEQUALS 337
+#define jp_LESLESEQUALS 338
+#define jp_LESSTHAN 339
+#define jp_LTEQUALS 340
+#define jp_LTLT 341
+#define jp_MINUS 342
+#define jp_MINUSEQUALS 343
+#define jp_MINUSMINUS 344
+#define jp_PAREEND 345
+#define jp_PARESTART 346
+#define jp_PERCENT 347
+#define jp_PERCENTEQUALS 348
+#define jp_PIPE 349
+#define jp_PIPEEQUALS 350
+#define jp_PIPEPIPE 351
+#define jp_PLUS 352
+#define jp_PLUSEQUALS 353
+#define jp_PLUSPLUS 354
+#define jp_QUESTION 355
+#define jp_SEMICOL 356
+#define jp_TILDE 357
+#define jp_TIMES 358
+#define jp_TIMESEQUALS 359
+#define jp_ERROR 360
+
+
+
+
+#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
+typedef int YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+
+
diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx
new file mode 100644
index 0000000000..3ff1017daa
--- /dev/null
+++ b/Source/cmDocumentation.cxx
@@ -0,0 +1,945 @@
+/*============================================================================
+ 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 "cmDocumentation.h"
+
+#include "cmSystemTools.h"
+#include "cmVersion.h"
+#include "cmRST.h"
+
+#include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+
+#include <ctype.h>
+
+#include <algorithm>
+
+//----------------------------------------------------------------------------
+static const char *cmDocumentationStandardOptions[][2] =
+{
+ {"--help,-help,-usage,-h,-H,/?",
+ "Print usage information and exit."},
+ {"--version,-version,/V [<f>]",
+ "Print version number and exit."},
+ {"--help-full [<f>]",
+ "Print all help manuals and exit."},
+ {"--help-manual <man> [<f>]",
+ "Print one help manual and exit."},
+ {"--help-manual-list [<f>]",
+ "List help manuals available and exit."},
+ {"--help-command <cmd> [<f>]",
+ "Print help for one command and exit."},
+ {"--help-command-list [<f>]",
+ "List commands with help available and exit."},
+ {"--help-commands [<f>]",
+ "Print cmake-commands manual and exit."},
+ {"--help-module <mod> [<f>]",
+ "Print help for one module and exit."},
+ {"--help-module-list [<f>]",
+ "List modules with help available and exit."},
+ {"--help-modules [<f>]",
+ "Print cmake-modules manual and exit."},
+ {"--help-policy <cmp> [<f>]",
+ "Print help for one policy and exit."},
+ {"--help-policy-list [<f>]",
+ "List policies with help available and exit."},
+ {"--help-policies [<f>]",
+ "Print cmake-policies manual and exit."},
+ {"--help-property <prop> [<f>]",
+ "Print help for one property and exit."},
+ {"--help-property-list [<f>]",
+ "List properties with help available and exit."},
+ {"--help-properties [<f>]",
+ "Print cmake-properties manual and exit."},
+ {"--help-variable var [<f>]",
+ "Print help for one variable and exit."},
+ {"--help-variable-list [<f>]",
+ "List variables with help available and exit."},
+ {"--help-variables [<f>]",
+ "Print cmake-variables manual and exit."},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char *cmDocumentationGeneratorsHeader[][2] =
+{
+ {0,
+ "The following generators are available on this platform:"},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+cmDocumentation::cmDocumentation()
+{
+ this->addCommonStandardDocSections();
+ this->ShowGenerators = true;
+}
+
+//----------------------------------------------------------------------------
+cmDocumentation::~cmDocumentation()
+{
+ for(std::map<std::string,cmDocumentationSection *>::iterator i =
+ this->AllSections.begin();
+ i != this->AllSections.end(); ++i)
+ {
+ delete i->second;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintVersion(std::ostream& os)
+{
+ os <<
+ this->GetNameString() <<
+ " version " << cmVersion::GetCMakeVersion() << "\n"
+ "\n"
+ "CMake suite maintained and supported by Kitware (kitware.com/cmake).\n"
+ ;
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
+{
+ switch (ht)
+ {
+ case cmDocumentation::Usage:
+ return this->PrintUsage(os);
+ case cmDocumentation::Help:
+ return this->PrintHelp(os);
+ case cmDocumentation::Full:
+ return this->PrintHelpFull(os);
+ case cmDocumentation::OneManual:
+ return this->PrintHelpOneManual(os);
+ case cmDocumentation::OneCommand:
+ return this->PrintHelpOneCommand(os);
+ case cmDocumentation::OneModule:
+ return this->PrintHelpOneModule(os);
+ case cmDocumentation::OnePolicy:
+ return this->PrintHelpOnePolicy(os);
+ case cmDocumentation::OneProperty:
+ return this->PrintHelpOneProperty(os);
+ case cmDocumentation::OneVariable:
+ return this->PrintHelpOneVariable(os);
+ case cmDocumentation::ListManuals:
+ return this->PrintHelpListManuals(os);
+ case cmDocumentation::ListCommands:
+ return this->PrintHelpListCommands(os);
+ case cmDocumentation::ListModules:
+ return this->PrintHelpListModules(os);
+ case cmDocumentation::ListProperties:
+ return this->PrintHelpListProperties(os);
+ case cmDocumentation::ListVariables:
+ return this->PrintHelpListVariables(os);
+ case cmDocumentation::ListPolicies:
+ return this->PrintHelpListPolicies(os);
+ case cmDocumentation::Version:
+ return this->PrintVersion(os);
+ case cmDocumentation::OldCustomModules:
+ return this->PrintOldCustomModules(os);
+ default: return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
+{
+ int count = 0;
+ bool result = true;
+
+ // Loop over requested documentation types.
+ for(std::vector<RequestedHelpItem>::const_iterator
+ i = this->RequestedHelpItems.begin();
+ i != this->RequestedHelpItems.end();
+ ++i)
+ {
+ this->CurrentArgument = i->Argument;
+ // If a file name was given, use it. Otherwise, default to the
+ // given stream.
+ cmsys::ofstream* fout = 0;
+ std::ostream* s = &os;
+ if(i->Filename.length() > 0)
+ {
+ fout = new cmsys::ofstream(i->Filename.c_str(), std::ios::out);
+ if(fout)
+ {
+ s = fout;
+ }
+ else
+ {
+ result = false;
+ }
+ }
+ else if(++count > 1)
+ {
+ os << "\n\n";
+ }
+
+ // Print this documentation type to the stream.
+ if(!this->PrintDocumentation(i->HelpType, *s) || !*s)
+ {
+ result = false;
+ }
+
+ // Close the file if we wrote one.
+ if(fout)
+ {
+ delete fout;
+ }
+ }
+ return result;
+}
+
+#define GET_OPT_ARGUMENT(target) \
+ if((i+1 < argc) && !this->IsOption(argv[i+1])) \
+ { \
+ target = argv[i+1]; \
+ i = i+1; \
+ };
+
+
+void cmDocumentation::WarnFormFromFilename(
+ cmDocumentation::RequestedHelpItem& request, bool& result)
+{
+ std::string ext = cmSystemTools::GetFilenameLastExtension(request.Filename);
+ ext = cmSystemTools::UpperCase(ext);
+ if ((ext == ".HTM") || (ext == ".HTML"))
+ {
+ request.HelpType = cmDocumentation::None;
+ result = true;
+ cmSystemTools::Message("Warning: HTML help format no longer supported");
+ }
+ else if (ext == ".DOCBOOK")
+ {
+ request.HelpType = cmDocumentation::None;
+ result = true;
+ cmSystemTools::Message("Warning: Docbook help format no longer supported");
+ }
+ // ".1" to ".9" should be manpages
+ else if ((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9'))
+ {
+ request.HelpType = cmDocumentation::None;
+ result = true;
+ cmSystemTools::Message("Warning: Man help format no longer supported");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::addCommonStandardDocSections()
+{
+ cmDocumentationSection *sec;
+
+ sec = new cmDocumentationSection("Options","OPTIONS");
+ sec->Append(cmDocumentationStandardOptions);
+ this->AllSections["Options"] = sec;
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::addCMakeStandardDocSections()
+{
+ cmDocumentationSection *sec;
+
+ sec = new cmDocumentationSection("Generators","GENERATORS");
+ sec->Append(cmDocumentationGeneratorsHeader);
+ this->AllSections["Generators"] = sec;
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::addCTestStandardDocSections()
+{
+ // This is currently done for backward compatibility reason
+ // We may suppress some of these.
+ addCMakeStandardDocSections();
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::addCPackStandardDocSections()
+{
+ cmDocumentationSection *sec;
+
+ sec = new cmDocumentationSection("Generators","GENERATORS");
+ sec->Append(cmDocumentationGeneratorsHeader);
+ this->AllSections["Generators"] = sec;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::CheckOptions(int argc, const char* const* argv,
+ const char* exitOpt)
+{
+ // Providing zero arguments gives usage information.
+ if(argc == 1)
+ {
+ RequestedHelpItem help;
+ help.HelpType = cmDocumentation::Usage;
+ this->RequestedHelpItems.push_back(help);
+ return true;
+ }
+
+ // Search for supported help options.
+
+ bool result = false;
+ for(int i=1; i < argc; ++i)
+ {
+ if(exitOpt && strcmp(argv[i], exitOpt) == 0)
+ {
+ return result;
+ }
+ RequestedHelpItem help;
+ // Check if this is a supported help option.
+ if((strcmp(argv[i], "-help") == 0) ||
+ (strcmp(argv[i], "--help") == 0) ||
+ (strcmp(argv[i], "/?") == 0) ||
+ (strcmp(argv[i], "-usage") == 0) ||
+ (strcmp(argv[i], "-h") == 0) ||
+ (strcmp(argv[i], "-H") == 0))
+ {
+ help.HelpType = cmDocumentation::Help;
+ GET_OPT_ARGUMENT(help.Argument);
+ help.Argument = cmSystemTools::LowerCase(help.Argument);
+ // special case for single command
+ if (!help.Argument.empty())
+ {
+ help.HelpType = cmDocumentation::OneCommand;
+ }
+ }
+ else if(strcmp(argv[i], "--help-properties") == 0)
+ {
+ help.HelpType = cmDocumentation::OneManual;
+ help.Argument = "cmake-properties.7";
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-policies") == 0)
+ {
+ help.HelpType = cmDocumentation::OneManual;
+ help.Argument = "cmake-policies.7";
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-variables") == 0)
+ {
+ help.HelpType = cmDocumentation::OneManual;
+ help.Argument = "cmake-variables.7";
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-modules") == 0)
+ {
+ help.HelpType = cmDocumentation::OneManual;
+ help.Argument = "cmake-modules.7";
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-custom-modules") == 0)
+ {
+ GET_OPT_ARGUMENT(help.Filename);
+ cmSystemTools::Message(
+ "Warning: --help-custom-modules no longer supported");
+ if(help.Filename.empty())
+ {
+ return true;
+ }
+ // Avoid breaking old project builds completely by at least generating
+ // the output file. Abuse help.Argument to give the file name to
+ // PrintOldCustomModules without disrupting our internal API.
+ help.HelpType = cmDocumentation::OldCustomModules;
+ help.Argument = cmSystemTools::GetFilenameName(help.Filename);
+ }
+ else if(strcmp(argv[i], "--help-commands") == 0)
+ {
+ help.HelpType = cmDocumentation::OneManual;
+ help.Argument = "cmake-commands.7";
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-compatcommands") == 0)
+ {
+ GET_OPT_ARGUMENT(help.Filename);
+ cmSystemTools::Message(
+ "Warning: --help-compatcommands no longer supported");
+ return true;
+ }
+ else if(strcmp(argv[i], "--help-full") == 0)
+ {
+ help.HelpType = cmDocumentation::Full;
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-html") == 0)
+ {
+ GET_OPT_ARGUMENT(help.Filename);
+ cmSystemTools::Message("Warning: --help-html no longer supported");
+ return true;
+ }
+ else if(strcmp(argv[i], "--help-man") == 0)
+ {
+ GET_OPT_ARGUMENT(help.Filename);
+ cmSystemTools::Message("Warning: --help-man no longer supported");
+ return true;
+ }
+ else if(strcmp(argv[i], "--help-command") == 0)
+ {
+ help.HelpType = cmDocumentation::OneCommand;
+ GET_OPT_ARGUMENT(help.Argument);
+ GET_OPT_ARGUMENT(help.Filename);
+ help.Argument = cmSystemTools::LowerCase(help.Argument);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-module") == 0)
+ {
+ help.HelpType = cmDocumentation::OneModule;
+ GET_OPT_ARGUMENT(help.Argument);
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-property") == 0)
+ {
+ help.HelpType = cmDocumentation::OneProperty;
+ GET_OPT_ARGUMENT(help.Argument);
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-policy") == 0)
+ {
+ help.HelpType = cmDocumentation::OnePolicy;
+ GET_OPT_ARGUMENT(help.Argument);
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-variable") == 0)
+ {
+ help.HelpType = cmDocumentation::OneVariable;
+ GET_OPT_ARGUMENT(help.Argument);
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-manual") == 0)
+ {
+ help.HelpType = cmDocumentation::OneManual;
+ GET_OPT_ARGUMENT(help.Argument);
+ GET_OPT_ARGUMENT(help.Filename);
+ this->WarnFormFromFilename(help, result);
+ }
+ else if(strcmp(argv[i], "--help-command-list") == 0)
+ {
+ help.HelpType = cmDocumentation::ListCommands;
+ GET_OPT_ARGUMENT(help.Filename);
+ }
+ else if(strcmp(argv[i], "--help-module-list") == 0)
+ {
+ help.HelpType = cmDocumentation::ListModules;
+ GET_OPT_ARGUMENT(help.Filename);
+ }
+ else if(strcmp(argv[i], "--help-property-list") == 0)
+ {
+ help.HelpType = cmDocumentation::ListProperties;
+ GET_OPT_ARGUMENT(help.Filename);
+ }
+ else if(strcmp(argv[i], "--help-variable-list") == 0)
+ {
+ help.HelpType = cmDocumentation::ListVariables;
+ GET_OPT_ARGUMENT(help.Filename);
+ }
+ else if(strcmp(argv[i], "--help-policy-list") == 0)
+ {
+ help.HelpType = cmDocumentation::ListPolicies;
+ GET_OPT_ARGUMENT(help.Filename);
+ }
+ else if(strcmp(argv[i], "--help-manual-list") == 0)
+ {
+ help.HelpType = cmDocumentation::ListManuals;
+ GET_OPT_ARGUMENT(help.Filename);
+ }
+ else if(strcmp(argv[i], "--copyright") == 0)
+ {
+ GET_OPT_ARGUMENT(help.Filename);
+ cmSystemTools::Message("Warning: --copyright no longer supported");
+ return true;
+ }
+ else if((strcmp(argv[i], "--version") == 0) ||
+ (strcmp(argv[i], "-version") == 0) ||
+ (strcmp(argv[i], "/V") == 0))
+ {
+ help.HelpType = cmDocumentation::Version;
+ GET_OPT_ARGUMENT(help.Filename);
+ }
+ if(help.HelpType != None)
+ {
+ // This is a help option. See if there is a file name given.
+ result = true;
+ this->RequestedHelpItems.push_back(help);
+ }
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::SetName(const std::string& name)
+{
+ this->NameString = name;
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::SetSection(const char *name,
+ cmDocumentationSection *section)
+{
+ if (this->AllSections.find(name) != this->AllSections.end())
+ {
+ delete this->AllSections[name];
+ }
+ this->AllSections[name] = section;
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::SetSection(const char *name,
+ std::vector<cmDocumentationEntry> &docs)
+{
+ cmDocumentationSection *sec =
+ new cmDocumentationSection(name,
+ cmSystemTools::UpperCase(name).c_str());
+ sec->Append(docs);
+ this->SetSection(name,sec);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::SetSection(const char *name,
+ const char *docs[][2])
+{
+ cmDocumentationSection *sec =
+ new cmDocumentationSection(name,
+ cmSystemTools::UpperCase(name).c_str());
+ sec->Append(docs);
+ this->SetSection(name,sec);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation
+::SetSections(std::map<std::string,cmDocumentationSection *> &sections)
+{
+ for (std::map<std::string,cmDocumentationSection *>::const_iterator
+ it = sections.begin(); it != sections.end(); ++it)
+ {
+ this->SetSection(it->first.c_str(),it->second);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::PrependSection(const char *name,
+ const char *docs[][2])
+{
+ cmDocumentationSection *sec = 0;
+ if (this->AllSections.find(name) == this->AllSections.end())
+ {
+ sec = new cmDocumentationSection
+ (name, cmSystemTools::UpperCase(name).c_str());
+ this->SetSection(name,sec);
+ }
+ else
+ {
+ sec = this->AllSections[name];
+ }
+ sec->Prepend(docs);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::PrependSection(const char *name,
+ std::vector<cmDocumentationEntry> &docs)
+{
+ cmDocumentationSection *sec = 0;
+ if (this->AllSections.find(name) == this->AllSections.end())
+ {
+ sec = new cmDocumentationSection
+ (name, cmSystemTools::UpperCase(name).c_str());
+ this->SetSection(name,sec);
+ }
+ else
+ {
+ sec = this->AllSections[name];
+ }
+ sec->Prepend(docs);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::AppendSection(const char *name,
+ const char *docs[][2])
+{
+ cmDocumentationSection *sec = 0;
+ if (this->AllSections.find(name) == this->AllSections.end())
+ {
+ sec = new cmDocumentationSection
+ (name, cmSystemTools::UpperCase(name).c_str());
+ this->SetSection(name,sec);
+ }
+ else
+ {
+ sec = this->AllSections[name];
+ }
+ sec->Append(docs);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::AppendSection(const char *name,
+ std::vector<cmDocumentationEntry> &docs)
+{
+ cmDocumentationSection *sec = 0;
+ if (this->AllSections.find(name) == this->AllSections.end())
+ {
+ sec = new cmDocumentationSection
+ (name, cmSystemTools::UpperCase(name).c_str());
+ this->SetSection(name,sec);
+ }
+ else
+ {
+ sec = this->AllSections[name];
+ }
+ sec->Append(docs);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::AppendSection(const char *name,
+ cmDocumentationEntry &docs)
+{
+
+ std::vector<cmDocumentationEntry> docsVec;
+ docsVec.push_back(docs);
+ this->AppendSection(name,docsVec);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::PrependSection(const char *name,
+ cmDocumentationEntry &docs)
+{
+
+ std::vector<cmDocumentationEntry> docsVec;
+ docsVec.push_back(docs);
+ this->PrependSection(name,docsVec);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::GlobHelp(std::vector<std::string>& files,
+ std::string const& pattern)
+{
+ cmsys::Glob gl;
+ std::string findExpr =
+ cmSystemTools::GetCMakeRoot() + "/Help/" + pattern + ".rst";
+ if(gl.FindFiles(findExpr))
+ {
+ files = gl.GetFiles();
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentation::PrintNames(std::ostream& os,
+ std::string const& pattern)
+{
+ std::vector<std::string> files;
+ this->GlobHelp(files, pattern);
+ std::vector<std::string> names;
+ for (std::vector<std::string>::const_iterator i = files.begin();
+ i != files.end(); ++i)
+ {
+ std::string line;
+ cmsys::ifstream fin(i->c_str());
+ while(fin && cmSystemTools::GetLineFromStream(fin, line))
+ {
+ if(!line.empty() && (isalnum(line[0]) || line[0] == '<'))
+ {
+ names.push_back(line);
+ break;
+ }
+ }
+ }
+ std::sort(names.begin(), names.end());
+ for (std::vector<std::string>::iterator i = names.begin();
+ i != names.end(); ++i)
+ {
+ os << *i << "\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintFiles(std::ostream& os,
+ std::string const& pattern)
+{
+ bool found = false;
+ std::vector<std::string> files;
+ this->GlobHelp(files, pattern);
+ std::sort(files.begin(), files.end());
+ cmRST r(os, cmSystemTools::GetCMakeRoot() + "/Help");
+ for (std::vector<std::string>::const_iterator i = files.begin();
+ i != files.end(); ++i)
+ {
+ found = r.ProcessFile(*i) || found;
+ }
+ return found;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpFull(std::ostream& os)
+{
+ return this->PrintFiles(os, "index");
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpOneManual(std::ostream& os)
+{
+ std::string mname = this->CurrentArgument;
+ std::string::size_type mlen = mname.length();
+ if(mlen > 3 && mname[mlen-3] == '(' &&
+ mname[mlen-1] == ')')
+ {
+ mname = mname.substr(0, mlen-3) + "." + mname[mlen-2];
+ }
+ if(this->PrintFiles(os, "manual/" + mname) ||
+ this->PrintFiles(os, "manual/" + mname + ".[0-9]"))
+ {
+ return true;
+ }
+ // Argument was not a manual. Complain.
+ os << "Argument \"" << this->CurrentArgument
+ << "\" to --help-manual is not an available manual. "
+ << "Use --help-manual-list to see all available manuals.\n";
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpListManuals(std::ostream& os)
+{
+ this->PrintNames(os, "manual/*");
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpOneCommand(std::ostream& os)
+{
+ std::string cname = cmSystemTools::LowerCase(this->CurrentArgument);
+ if(this->PrintFiles(os, "command/" + cname))
+ {
+ return true;
+ }
+ // Argument was not a command. Complain.
+ os << "Argument \"" << this->CurrentArgument
+ << "\" to --help-command is not a CMake command. "
+ << "Use --help-command-list to see all commands.\n";
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpListCommands(std::ostream& os)
+{
+ this->PrintNames(os, "command/*");
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpOneModule(std::ostream& os)
+{
+ std::string mname = this->CurrentArgument;
+ if(this->PrintFiles(os, "module/" + mname))
+ {
+ return true;
+ }
+ // Argument was not a module. Complain.
+ os << "Argument \"" << this->CurrentArgument
+ << "\" to --help-module is not a CMake module.\n";
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpListModules(std::ostream& os)
+{
+ std::vector<std::string> files;
+ this->GlobHelp(files, "module/*");
+ std::vector<std::string> modules;
+ for (std::vector<std::string>::iterator fi = files.begin();
+ fi != files.end(); ++fi)
+ {
+ std::string module = cmSystemTools::GetFilenameName(*fi);
+ modules.push_back(module.substr(0, module.size()-4));
+ }
+ std::sort(modules.begin(), modules.end());
+ for (std::vector<std::string>::iterator i = modules.begin();
+ i != modules.end(); ++i)
+ {
+ os << *i << "\n";
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpOneProperty(std::ostream& os)
+{
+ std::string pname = cmSystemTools::HelpFileName(this->CurrentArgument);
+ if(this->PrintFiles(os, "prop_*/" + pname))
+ {
+ return true;
+ }
+ // Argument was not a property. Complain.
+ os << "Argument \"" << this->CurrentArgument
+ << "\" to --help-property is not a CMake property. "
+ << "Use --help-property-list to see all properties.\n";
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpListProperties(std::ostream& os)
+{
+ this->PrintNames(os, "prop_*/*");
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpOnePolicy(std::ostream& os)
+{
+ std::string pname = this->CurrentArgument;
+ std::vector<std::string> files;
+ if(this->PrintFiles(os, "policy/" + pname))
+ {
+ return true;
+ }
+
+ // Argument was not a policy. Complain.
+ os << "Argument \"" << this->CurrentArgument
+ << "\" to --help-policy is not a CMake policy.\n";
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpListPolicies(std::ostream& os)
+{
+ this->PrintNames(os, "policy/*");
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpOneVariable(std::ostream& os)
+{
+ std::string vname = cmSystemTools::HelpFileName(this->CurrentArgument);
+ if(this->PrintFiles(os, "variable/" + vname))
+ {
+ return true;
+ }
+ // Argument was not a variable. Complain.
+ os << "Argument \"" << this->CurrentArgument
+ << "\" to --help-variable is not a defined variable. "
+ << "Use --help-variable-list to see all defined variables.\n";
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelpListVariables(std::ostream& os)
+{
+ this->PrintNames(os, "variable/*");
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintUsage(std::ostream& os)
+{
+ std::map<std::string,cmDocumentationSection*>::iterator si;
+ si = this->AllSections.find("Usage");
+ if(si != this->AllSections.end())
+ {
+ this->Formatter.PrintSection(os, *si->second);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintHelp(std::ostream& os)
+{
+ std::map<std::string,cmDocumentationSection*>::iterator si;
+ si = this->AllSections.find("Usage");
+ if(si != this->AllSections.end())
+ {
+ this->Formatter.PrintSection(os, *si->second);
+ }
+ si = this->AllSections.find("Options");
+ if(si != this->AllSections.end())
+ {
+ this->Formatter.PrintSection(os, *si->second);
+ }
+ if(this->ShowGenerators)
+ {
+ si = this->AllSections.find("Generators");
+ if(si != this->AllSections.end())
+ {
+ this->Formatter.PrintSection(os, *si->second);
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+const char* cmDocumentation::GetNameString() const
+{
+ if(this->NameString.length() > 0)
+ {
+ return this->NameString.c_str();
+ }
+ else
+ {
+ return "CMake";
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::IsOption(const char* arg) const
+{
+ return ((arg[0] == '-') || (strcmp(arg, "/V") == 0) ||
+ (strcmp(arg, "/?") == 0));
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::PrintOldCustomModules(std::ostream& os)
+{
+ // CheckOptions abuses the Argument field to give us the file name.
+ std::string filename = this->CurrentArgument;
+ std::string ext = cmSystemTools::UpperCase(
+ cmSystemTools::GetFilenameLastExtension(filename));
+ std::string name = cmSystemTools::GetFilenameWithoutLastExtension(filename);
+
+ const char* summary = "cmake --help-custom-modules no longer supported\n";
+ const char* detail =
+ "CMake versions prior to 3.0 exposed their internal module help page\n"
+ "generation functionality through the --help-custom-modules option.\n"
+ "CMake versions 3.0 and above use other means to generate their module\n"
+ "help pages so this functionality is no longer available to be exposed.\n"
+ "\n"
+ "This file was generated as a placeholder to provide this information.\n"
+ ;
+ if((ext == ".HTM") || (ext == ".HTML"))
+ {
+ os << "<html><title>" << name << "</title><body>\n"
+ << summary << "<p/>\n" << detail << "</body></html>\n";
+ }
+ else if((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9'))
+ {
+ os <<
+ ".TH " << name << " " << ext[1] << " \"" <<
+ cmSystemTools::GetCurrentDateTime("%B %d, %Y") <<
+ "\" \"cmake " << cmVersion::GetCMakeVersion() << "\"\n"
+ ".SH NAME\n"
+ ".PP\n" <<
+ name << " \\- " << summary <<
+ "\n"
+ ".SH DESCRIPTION\n"
+ ".PP\n" <<
+ detail
+ ;
+ }
+ else
+ {
+ os << name << "\n\n" << summary << "\n" << detail;
+ }
+ return true;
+}
diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h
new file mode 100644
index 0000000000..b72b5fe27c
--- /dev/null
+++ b/Source/cmDocumentation.h
@@ -0,0 +1,146 @@
+/*============================================================================
+ 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 _cmDocumentation_h
+#define _cmDocumentation_h
+
+#include "cmStandardIncludes.h"
+#include "cmProperty.h"
+#include "cmDocumentationFormatter.h"
+#include "cmDocumentationSection.h"
+#include "cmake.h"
+
+namespace cmsys
+{
+ class Directory;
+}
+
+/** Class to generate documentation. */
+class cmDocumentation: public cmDocumentationEnums
+{
+public:
+ cmDocumentation();
+
+ ~cmDocumentation();
+
+ /**
+ * Check command line arguments for documentation options. Returns
+ * true if documentation options are found, and false otherwise.
+ * When true is returned, PrintRequestedDocumentation should be
+ * called. exitOpt can be used for things like cmake -E, so that
+ * all arguments after the -E are ignored and not searched for
+ * help arguments.
+ */
+ bool CheckOptions(int argc, const char* const* argv,
+ const char* exitOpt =0);
+
+ /**
+ * Print help requested on the command line. Call after
+ * CheckOptions returns true. Returns true on success, and false
+ * otherwise. Failure can occur when output files specified on the
+ * command line cannot be written.
+ */
+ bool PrintRequestedDocumentation(std::ostream& os);
+
+ /** Print help of the given type. */
+ bool PrintDocumentation(Type ht, std::ostream& os);
+
+ void SetShowGenerators(bool showGen) { this->ShowGenerators = showGen; }
+
+ /** Set the program name for standard document generation. */
+ void SetName(const std::string& name);
+
+ /** Set a section of the documentation. Typical sections include Name,
+ Usage, Description, Options */
+ void SetSection(const char *sectionName,
+ cmDocumentationSection *section);
+ void SetSection(const char *sectionName,
+ std::vector<cmDocumentationEntry> &docs);
+ void SetSection(const char *sectionName,
+ const char *docs[][2]);
+ void SetSections(std::map<std::string,cmDocumentationSection *>
+ &sections);
+
+ /** Add the documentation to the beginning/end of the section */
+ void PrependSection(const char *sectionName,
+ const char *docs[][2]);
+ void PrependSection(const char *sectionName,
+ std::vector<cmDocumentationEntry> &docs);
+ void PrependSection(const char *sectionName,
+ cmDocumentationEntry &docs);
+ void AppendSection(const char *sectionName,
+ const char *docs[][2]);
+ void AppendSection(const char *sectionName,
+ std::vector<cmDocumentationEntry> &docs);
+ void AppendSection(const char *sectionName,
+ cmDocumentationEntry &docs);
+
+ /** Add common (to all tools) documentation section(s) */
+ void addCommonStandardDocSections();
+
+ /** Add the CMake standard documentation section(s) */
+ void addCMakeStandardDocSections();
+
+ /** Add the CTest standard documentation section(s) */
+ void addCTestStandardDocSections();
+
+ /** Add the CPack standard documentation section(s) */
+ void addCPackStandardDocSections();
+
+private:
+
+ void GlobHelp(std::vector<std::string>& files, std::string const& pattern);
+ void PrintNames(std::ostream& os, std::string const& pattern);
+ bool PrintFiles(std::ostream& os, std::string const& pattern);
+
+ bool PrintVersion(std::ostream& os);
+ bool PrintUsage(std::ostream& os);
+ bool PrintHelp(std::ostream& os);
+ bool PrintHelpFull(std::ostream& os);
+ bool PrintHelpOneManual(std::ostream& os);
+ bool PrintHelpOneCommand(std::ostream& os);
+ bool PrintHelpOneModule(std::ostream& os);
+ bool PrintHelpOnePolicy(std::ostream& os);
+ bool PrintHelpOneProperty(std::ostream& os);
+ bool PrintHelpOneVariable(std::ostream& os);
+ bool PrintHelpListManuals(std::ostream& os);
+ bool PrintHelpListCommands(std::ostream& os);
+ bool PrintHelpListModules(std::ostream& os);
+ bool PrintHelpListProperties(std::ostream& os);
+ bool PrintHelpListVariables(std::ostream& os);
+ bool PrintHelpListPolicies(std::ostream& os);
+ bool PrintOldCustomModules(std::ostream& os);
+
+ const char* GetNameString() const;
+ bool IsOption(const char* arg) const;
+
+ bool ShowGenerators;
+
+ std::string NameString;
+ std::map<std::string,cmDocumentationSection*> AllSections;
+
+ std::string CurrentArgument;
+
+ struct RequestedHelpItem
+ {
+ RequestedHelpItem(): HelpType(None) {}
+ cmDocumentationEnums::Type HelpType;
+ std::string Filename;
+ std::string Argument;
+ };
+
+ std::vector<RequestedHelpItem> RequestedHelpItems;
+ cmDocumentationFormatter Formatter;
+
+ static void WarnFormFromFilename(RequestedHelpItem& request, bool& result);
+};
+
+#endif
diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx
new file mode 100644
index 0000000000..29c806dcc3
--- /dev/null
+++ b/Source/cmDocumentationFormatter.cxx
@@ -0,0 +1,230 @@
+/*============================================================================
+ 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 "cmDocumentationFormatter.h"
+
+#include "cmDocumentationSection.h"
+
+cmDocumentationFormatter::cmDocumentationFormatter():
+ TextWidth(77), TextIndent("")
+{
+}
+
+cmDocumentationFormatter::~cmDocumentationFormatter()
+{
+}
+
+void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
+ const char* text)
+{
+ if(!text)
+ {
+ return;
+ }
+ const char* ptr = text;
+ while(*ptr)
+ {
+ // Any ptrs starting in a space are treated as preformatted text.
+ std::string preformatted;
+ while(*ptr == ' ')
+ {
+ for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
+ {
+ preformatted.append(1, ch);
+ }
+ if(*ptr)
+ {
+ ++ptr;
+ preformatted.append(1, '\n');
+ }
+ }
+ if(preformatted.length())
+ {
+ this->PrintPreformatted(os, preformatted.c_str());
+ }
+
+ // Other ptrs are treated as paragraphs.
+ std::string paragraph;
+ for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
+ {
+ paragraph.append(1, ch);
+ }
+ if(*ptr)
+ {
+ ++ptr;
+ paragraph.append(1, '\n');
+ }
+ if(paragraph.length())
+ {
+ this->PrintParagraph(os, paragraph.c_str());
+ }
+ }
+}
+
+void cmDocumentationFormatter::PrintPreformatted(std::ostream& os,
+ const char* text)
+{
+ bool newline = true;
+ for(const char* ptr = text; *ptr; ++ptr)
+ {
+ if(newline && *ptr != '\n')
+ {
+ os << this->TextIndent;
+ newline = false;
+ }
+ os << *ptr;
+ if(*ptr == '\n')
+ {
+ newline = true;
+ }
+ }
+ os << "\n";
+}
+
+void cmDocumentationFormatter::PrintParagraph(std::ostream& os,
+ const char* text)
+{
+ os << this->TextIndent;
+ this->PrintColumn(os, text);
+ os << "\n";
+}
+
+void cmDocumentationFormatter::SetIndent(const char* indent)
+{
+ this->TextIndent = indent;
+}
+
+void cmDocumentationFormatter::PrintColumn(std::ostream& os,
+ const char* text)
+{
+ // Print text arranged in an indented column of fixed witdh.
+ const char* l = text;
+ long column = 0;
+ bool newSentence = false;
+ bool firstLine = true;
+ int width = this->TextWidth - static_cast<int>(strlen(this->TextIndent));
+
+ // Loop until the end of the text.
+ while(*l)
+ {
+ // Parse the next word.
+ const char* r = l;
+ while(*r && (*r != '\n') && (*r != ' ')) { ++r; }
+
+ // Does it fit on this line?
+ if(r-l < (width-column-(newSentence?1:0)))
+ {
+ // Word fits on this line.
+ if(r > l)
+ {
+ if(column)
+ {
+ // Not first word on line. Separate from the previous word
+ // by a space, or two if this is a new sentence.
+ if(newSentence)
+ {
+ os << " ";
+ column += 2;
+ }
+ else
+ {
+ os << " ";
+ column += 1;
+ }
+ }
+ else
+ {
+ // First word on line. Print indentation unless this is the
+ // first line.
+ os << (firstLine?"":this->TextIndent);
+ }
+
+ // Print the word.
+ os.write(l, static_cast<long>(r-l));
+ newSentence = (*(r-1) == '.');
+ }
+
+ if(*r == '\n')
+ {
+ // Text provided a newline. Start a new line.
+ os << "\n";
+ ++r;
+ column = 0;
+ firstLine = false;
+ }
+ else
+ {
+ // No provided newline. Continue this line.
+ column += static_cast<long>(r-l);
+ }
+ }
+ else
+ {
+ // Word does not fit on this line. Start a new line.
+ os << "\n";
+ firstLine = false;
+ if(r > l)
+ {
+ os << this->TextIndent;
+ os.write(l, static_cast<long>(r-l));
+ column = static_cast<long>(r-l);
+ newSentence = (*(r-1) == '.');
+ }
+ else
+ {
+ column = 0;
+ }
+ }
+
+ // Move to beginning of next word. Skip over whitespace.
+ l = r;
+ while(*l && (*l == ' ')) { ++l; }
+ }
+}
+
+void cmDocumentationFormatter
+::PrintSection(std::ostream& os,
+ cmDocumentationSection const& section)
+{
+ os << section.GetName() << "\n";
+
+ const std::vector<cmDocumentationEntry> &entries =
+ section.GetEntries();
+ for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin();
+ op != entries.end(); ++op)
+ {
+ if(op->Name.size())
+ {
+ os << " " << op->Name;
+ this->TextIndent = " ";
+ int align = static_cast<int>(strlen(this->TextIndent))-4;
+ for(int i = static_cast<int>(op->Name.size()); i < align; ++i)
+ {
+ os << " ";
+ }
+ if (op->Name.size() > strlen(this->TextIndent)-4 )
+ {
+ os << "\n";
+ os.write(this->TextIndent, strlen(this->TextIndent)-2);
+ }
+ os << "= ";
+ this->PrintColumn(os, op->Brief.c_str());
+ os << "\n";
+ }
+ else
+ {
+ os << "\n";
+ this->TextIndent = "";
+ this->PrintFormatted(os, op->Brief.c_str());
+ }
+ }
+ os << "\n";
+}
diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h
new file mode 100644
index 0000000000..59513ccb57
--- /dev/null
+++ b/Source/cmDocumentationFormatter.h
@@ -0,0 +1,57 @@
+/*============================================================================
+ 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 _cmDocumentationFormatter_h
+#define _cmDocumentationFormatter_h
+
+#include "cmStandardIncludes.h"
+
+/** This is just a helper class to make it build with MSVC 6.0.
+Actually the enums and internal classes could directly go into
+cmDocumentation, but then MSVC6 complains in RequestedHelpItem that
+cmDocumentation is an undefined type and so it doesn't know the enums.
+Moving the enums to a class which is then already completely parsed helps
+against this. */
+class cmDocumentationEnums
+{
+public:
+ /** Types of help provided. */
+ enum Type
+ {
+ None, Version, Usage, Help, Full, ListManuals,
+ ListCommands, ListModules, ListProperties, ListVariables, ListPolicies,
+ OneManual, OneCommand, OneModule, OneProperty, OneVariable, OnePolicy,
+ OldCustomModules
+ };
+};
+
+class cmDocumentationSection;
+
+/** Print documentation in a simple text format. */
+class cmDocumentationFormatter
+{
+public:
+ cmDocumentationFormatter();
+ virtual ~cmDocumentationFormatter();
+ void PrintFormatted(std::ostream& os, const char* text);
+
+ virtual void PrintSection(std::ostream& os,
+ cmDocumentationSection const& section);
+ virtual void PrintPreformatted(std::ostream& os, const char* text);
+ virtual void PrintParagraph(std::ostream& os, const char* text);
+ void PrintColumn(std::ostream& os, const char* text);
+ void SetIndent(const char* indent);
+private:
+ int TextWidth;
+ const char* TextIndent;
+};
+
+#endif
diff --git a/Source/cmDocumentationSection.cxx b/Source/cmDocumentationSection.cxx
new file mode 100644
index 0000000000..b0dd8ef64a
--- /dev/null
+++ b/Source/cmDocumentationSection.cxx
@@ -0,0 +1,45 @@
+/*============================================================================
+ 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 "cmDocumentationSection.h"
+
+
+//----------------------------------------------------------------------------
+void cmDocumentationSection::Append(const char *data[][2])
+{
+ int i = 0;
+ while(data[i][1])
+ {
+ this->Entries.push_back(cmDocumentationEntry(data[i][0],
+ data[i][1]));
+ data += 1;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentationSection::Prepend(const char *data[][2])
+{
+ std::vector<cmDocumentationEntry> tmp;
+ int i = 0;
+ while(data[i][1])
+ {
+ tmp.push_back(cmDocumentationEntry(data[i][0],
+ data[i][1]));
+ data += 1;
+ }
+ this->Entries.insert(this->Entries.begin(),tmp.begin(),tmp.end());
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentationSection::Append(const char *n, const char *b)
+{
+ this->Entries.push_back(cmDocumentationEntry(n,b));
+}
diff --git a/Source/cmDocumentationSection.h b/Source/cmDocumentationSection.h
new file mode 100644
index 0000000000..d796da84b6
--- /dev/null
+++ b/Source/cmDocumentationSection.h
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 _cmDocumentationSection_h
+#define _cmDocumentationSection_h
+
+#include "cmStandardIncludes.h"
+#include "cmDocumentationFormatter.h"
+
+// Low-level interface for custom documents:
+/** Internal class representing a section of the documentation.
+ * Cares e.g. for the different section titles in the different
+ * output formats.
+ */
+class cmDocumentationSection
+{
+public:
+ /** Create a cmSection, with a special name for man-output mode. */
+ cmDocumentationSection(const char* name, const char*)
+ :Name(name) {}
+
+ /** Has any content been added to this section or is it empty ? */
+ bool IsEmpty() const { return this->Entries.empty(); }
+
+ /** Clear contents. */
+ void Clear() { this->Entries.clear(); }
+
+ /** Return the name of this section. */
+ std::string GetName() const
+ { return this->Name; }
+
+ /** Return a pointer to the first entry of this section. */
+ const std::vector<cmDocumentationEntry> &GetEntries() const
+ { return this->Entries; }
+
+ /** Append an entry to this section. */
+ void Append(const cmDocumentationEntry& entry)
+ { this->Entries.push_back(entry); }
+ void Append(const std::vector<cmDocumentationEntry> &entries)
+ { this->Entries.insert(this->Entries.end(),entries.begin(),entries.end()); }
+
+ /** Append an entry to this section using NULL terminated chars */
+ void Append(const char *[][2]);
+ void Append(const char *n, const char *b);
+
+ /** prepend some documentation to this section */
+ void Prepend(const char *[][2]);
+ void Prepend(const std::vector<cmDocumentationEntry> &entries)
+ { this->Entries.insert(this->Entries.begin(),
+ entries.begin(),entries.end()); }
+
+
+private:
+ std::string Name;
+ std::vector<cmDocumentationEntry> Entries;
+};
+
+#endif
diff --git a/Source/cmDynamicLoader.cxx b/Source/cmDynamicLoader.cxx
new file mode 100644
index 0000000000..944a000726
--- /dev/null
+++ b/Source/cmDynamicLoader.cxx
@@ -0,0 +1,112 @@
+/*============================================================================
+ 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 "cmDynamicLoader.h"
+
+class cmDynamicLoaderCache
+{
+public:
+ ~cmDynamicLoaderCache();
+ void CacheFile(const char* path,
+ const cmsys::DynamicLoader::LibraryHandle&);
+ bool GetCacheFile(const char* path, cmsys::DynamicLoader::LibraryHandle&);
+ bool FlushCache(const char* path);
+ void FlushCache();
+ static cmDynamicLoaderCache* GetInstance();
+
+private:
+ std::map<std::string, cmsys::DynamicLoader::LibraryHandle> CacheMap;
+ static cmDynamicLoaderCache* Instance;
+};
+
+cmDynamicLoaderCache* cmDynamicLoaderCache::Instance = 0;
+
+cmDynamicLoaderCache::~cmDynamicLoaderCache()
+{
+}
+
+void cmDynamicLoaderCache::CacheFile(const char* path,
+ const cmsys::DynamicLoader::LibraryHandle& p)
+{
+ cmsys::DynamicLoader::LibraryHandle h;
+ if ( this->GetCacheFile(path, h) )
+ {
+ this->FlushCache(path);
+ }
+ this->CacheMap[path] = p;
+}
+
+bool cmDynamicLoaderCache::GetCacheFile(const char* path,
+ cmsys::DynamicLoader::LibraryHandle& p)
+{
+ std::map<std::string, cmsys::DynamicLoader::LibraryHandle>::iterator it
+ = this->CacheMap.find(path);
+ if ( it != this->CacheMap.end() )
+ {
+ p = it->second;
+ return true;
+ }
+ return false;
+}
+
+bool cmDynamicLoaderCache::FlushCache(const char* path)
+{
+ std::map<std::string, cmsys::DynamicLoader::LibraryHandle>::iterator it
+ = this->CacheMap.find(path);
+ bool ret = false;
+ if ( it != this->CacheMap.end() )
+ {
+ cmsys::DynamicLoader::CloseLibrary(it->second);
+ this->CacheMap.erase(it);
+ ret = true;
+ }
+ return ret;
+}
+
+void cmDynamicLoaderCache::FlushCache()
+{
+ for ( std::map<std::string,
+ cmsys::DynamicLoader::LibraryHandle>::iterator it
+ = this->CacheMap.begin();
+ it != this->CacheMap.end(); it++ )
+ {
+ cmsys::DynamicLoader::CloseLibrary(it->second);
+ }
+ delete cmDynamicLoaderCache::Instance;
+ cmDynamicLoaderCache::Instance = 0;
+}
+
+cmDynamicLoaderCache* cmDynamicLoaderCache::GetInstance()
+{
+ if ( !cmDynamicLoaderCache::Instance )
+ {
+ cmDynamicLoaderCache::Instance = new cmDynamicLoaderCache;
+ }
+ return cmDynamicLoaderCache::Instance;
+}
+
+cmsys::DynamicLoader::LibraryHandle cmDynamicLoader::OpenLibrary(
+ const char* libname )
+{
+ cmsys::DynamicLoader::LibraryHandle lh;
+ if ( cmDynamicLoaderCache::GetInstance()->GetCacheFile(libname, lh) )
+ {
+ return lh;
+ }
+ lh = cmsys::DynamicLoader::OpenLibrary(libname);
+ cmDynamicLoaderCache::GetInstance()->CacheFile(libname, lh);
+ return lh;
+}
+
+void cmDynamicLoader::FlushCache()
+{
+ cmDynamicLoaderCache::GetInstance()->FlushCache();
+}
diff --git a/Source/cmDynamicLoader.h b/Source/cmDynamicLoader.h
new file mode 100644
index 0000000000..d038b5cb10
--- /dev/null
+++ b/Source/cmDynamicLoader.h
@@ -0,0 +1,47 @@
+/*============================================================================
+ 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.
+============================================================================*/
+// .NAME cmDynamicLoader - class interface to system dynamic libraries
+// .SECTION Description
+// cmDynamicLoader provides a portable interface to loading dynamic
+// libraries into a process.
+
+
+#ifndef __cmDynamicLoader_h
+#define __cmDynamicLoader_h
+
+#include "cmStandardIncludes.h"
+
+#include <cmsys/DynamicLoader.hxx>
+
+class cmDynamicLoader
+{
+public:
+ // Description:
+ // Load a dynamic library into the current process.
+ // The returned cmsys::DynamicLoader::LibraryHandle can be used to access
+ // the symbols in the library.
+ static cmsys::DynamicLoader::LibraryHandle OpenLibrary(const char*);
+
+ // Description:
+ // Flush the cache of dynamic loader.
+ static void FlushCache();
+
+protected:
+ cmDynamicLoader() {}
+ ~cmDynamicLoader() {}
+
+private:
+ cmDynamicLoader(const cmDynamicLoader&); // Not implemented.
+ void operator=(const cmDynamicLoader&); // Not implemented.
+};
+
+#endif
diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx
new file mode 100644
index 0000000000..cab23b7598
--- /dev/null
+++ b/Source/cmELF.cxx
@@ -0,0 +1,949 @@
+/*============================================================================
+ 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 "cmStandardIncludes.h" // to get CMAKE_USE_ELF_PARSER first
+#include "cmELF.h"
+
+#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>
+# include <elf_abi.h>
+#elif defined(__HAIKU__)
+# include <elf32.h>
+# include <elf64.h>
+ typedef struct Elf32_Ehdr Elf32_Ehdr;
+ typedef struct Elf32_Shdr Elf32_Shdr;
+ typedef struct Elf32_Sym Elf32_Sym;
+ typedef struct Elf32_Rel Elf32_Rel;
+ typedef struct Elf32_Rela Elf32_Rela;
+# define ELFMAG0 0x7F
+# define ELFMAG1 'E'
+# define ELFMAG2 'L'
+# define ELFMAG3 'F'
+# define ET_NONE 0
+# define ET_REL 1
+# define ET_EXEC 2
+# define ET_DYN 3
+# define ET_CORE 4
+# define EM_386 3
+# define EM_SPARC 2
+# define EM_PPC 20
+#else
+# include <elf.h>
+#endif
+#if defined(__sun)
+# include <sys/link.h> // For dynamic section information
+#endif
+
+//----------------------------------------------------------------------------
+// Low-level byte swapping implementation.
+template <size_t s> struct cmELFByteSwapSize {};
+void cmELFByteSwap(char*, cmELFByteSwapSize<1> const&)
+{
+}
+void cmELFByteSwap(char* data, cmELFByteSwapSize<2> const&)
+{
+ char one_byte;
+ one_byte = data[0]; data[0] = data[1]; data[1] = one_byte;
+}
+void cmELFByteSwap(char* data, cmELFByteSwapSize<4> const&)
+{
+ char one_byte;
+ one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
+ one_byte = data[1]; data[1] = data[2]; data[2] = one_byte;
+}
+void cmELFByteSwap(char* data, cmELFByteSwapSize<8> const&)
+{
+ char one_byte;
+ one_byte = data[0]; data[0] = data[7]; data[7] = one_byte;
+ one_byte = data[1]; data[1] = data[6]; data[6] = one_byte;
+ one_byte = data[2]; data[2] = data[5]; data[5] = one_byte;
+ one_byte = data[3]; data[3] = data[4]; data[4] = one_byte;
+}
+
+// Low-level byte swapping interface.
+template <typename T>
+void cmELFByteSwap(T& x)
+{
+ cmELFByteSwap(reinterpret_cast<char*>(&x), cmELFByteSwapSize<sizeof(T)>());
+}
+
+//----------------------------------------------------------------------------
+class cmELFInternal
+{
+public:
+ typedef cmELF::StringEntry StringEntry;
+ enum ByteOrderType { ByteOrderMSB, ByteOrderLSB };
+
+ // Construct and take ownership of the file stream object.
+ cmELFInternal(cmELF* external,
+ cmsys::auto_ptr<cmsys::ifstream>& fin,
+ ByteOrderType order):
+ External(external),
+ Stream(*fin.release()),
+ ByteOrder(order),
+ ELFType(cmELF::FileTypeInvalid)
+ {
+ // 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
+ this->NeedSwap = (this->ByteOrder == ByteOrderMSB);
+#elif cmsys_CPU_ENDIAN_ID == cmsys_CPU_ENDIAN_ID_BIG
+ this->NeedSwap = (this->ByteOrder == ByteOrderLSB);
+#else
+ this->NeedSwap = false; // Final decision is at runtime anyway.
+#endif
+
+ // We have not yet loaded the section info.
+ this->DynamicSectionIndex = -1;
+ }
+
+ // Destruct and delete the file stream object.
+ virtual ~cmELFInternal()
+ {
+ delete &this->Stream;
+ }
+
+ // Forward to the per-class implementation.
+ virtual unsigned int GetNumberOfSections() const = 0;
+ virtual unsigned int GetDynamicEntryCount() = 0;
+ virtual unsigned long GetDynamicEntryPosition(int j) = 0;
+ virtual StringEntry const* GetDynamicSectionString(unsigned int tag) = 0;
+ virtual void PrintInfo(std::ostream& os) const = 0;
+
+ bool ReadBytes(unsigned long pos, unsigned long size, char* buf)
+ {
+ this->Stream.seekg(pos);
+ this->Stream.read(buf, size);
+ return this->Stream?true:false;
+ }
+
+ // Lookup the SONAME in the DYNAMIC section.
+ StringEntry const* GetSOName()
+ {
+ return this->GetDynamicSectionString(DT_SONAME);
+ }
+
+ // Lookup the RPATH in the DYNAMIC section.
+ StringEntry const* GetRPath()
+ {
+ return this->GetDynamicSectionString(DT_RPATH);
+ }
+
+ // Lookup the RUNPATH in the DYNAMIC section.
+ StringEntry const* GetRunPath()
+ {
+#if defined(DT_RUNPATH)
+ return this->GetDynamicSectionString(DT_RUNPATH);
+#else
+ return 0;
+#endif
+ }
+
+ // Return the recorded ELF type.
+ cmELF::FileType GetFileType() const { return this->ELFType; }
+protected:
+ // Data common to all ELF class implementations.
+
+ // The external cmELF object.
+ cmELF* External;
+
+ // The stream from which to read.
+ std::istream& Stream;
+
+ // The byte order of the ELF file.
+ ByteOrderType ByteOrder;
+
+ // The ELF file type.
+ cmELF::FileType ELFType;
+
+ // Whether we need to byte-swap structures read from the stream.
+ bool NeedSwap;
+
+ // The section header index of the DYNAMIC section (-1 if none).
+ int DynamicSectionIndex;
+
+ // Helper methods for subclasses.
+ void SetErrorMessage(const char* msg)
+ {
+ this->External->ErrorMessage = msg;
+ this->ELFType = cmELF::FileTypeInvalid;
+ }
+
+ // Store string table entry states.
+ std::map<unsigned int, StringEntry> DynamicSectionStrings;
+};
+
+//----------------------------------------------------------------------------
+// Configure the implementation template for 32-bit ELF files.
+struct cmELFTypes32
+{
+ typedef Elf32_Ehdr ELF_Ehdr;
+ typedef Elf32_Shdr ELF_Shdr;
+ typedef Elf32_Dyn ELF_Dyn;
+ typedef Elf32_Half ELF_Half;
+ typedef cmIML_INT_uint32_t tagtype;
+ static const char* GetName() { return "32-bit"; }
+};
+
+// Configure the implementation template for 64-bit ELF files.
+struct cmELFTypes64
+{
+ typedef Elf64_Ehdr ELF_Ehdr;
+ typedef Elf64_Shdr ELF_Shdr;
+ typedef Elf64_Dyn ELF_Dyn;
+ typedef Elf64_Half ELF_Half;
+ typedef cmIML_INT_uint64_t tagtype;
+ static const char* GetName() { return "64-bit"; }
+};
+
+//----------------------------------------------------------------------------
+// Parser implementation template.
+template <class Types>
+class cmELFInternalImpl: public cmELFInternal
+{
+public:
+ // Copy the ELF file format types from our configuration parameter.
+ typedef typename Types::ELF_Ehdr ELF_Ehdr;
+ typedef typename Types::ELF_Shdr ELF_Shdr;
+ typedef typename Types::ELF_Dyn ELF_Dyn;
+ typedef typename Types::ELF_Half ELF_Half;
+ typedef typename Types::tagtype tagtype;
+
+ // Construct with a stream and byte swap indicator.
+ cmELFInternalImpl(cmELF* external,
+ cmsys::auto_ptr<cmsys::ifstream>& fin,
+ ByteOrderType order);
+
+ // Return the number of sections as specified by the ELF header.
+ virtual unsigned int GetNumberOfSections() const
+ {
+ return static_cast<unsigned int>(this->ELFHeader.e_shnum);
+ }
+
+ // Get the file position and size of a dynamic section entry.
+ virtual unsigned int GetDynamicEntryCount();
+ virtual unsigned long GetDynamicEntryPosition(int j);
+
+ // Lookup a string from the dynamic section with the given tag.
+ virtual StringEntry const* GetDynamicSectionString(unsigned int tag);
+
+ // Print information about the ELF file.
+ virtual void PrintInfo(std::ostream& os) const
+ {
+ os << "ELF " << Types::GetName();
+ if(this->ByteOrder == ByteOrderMSB)
+ {
+ os << " MSB";
+ }
+ else if(this->ByteOrder == ByteOrderLSB)
+ {
+ os << " LSB";
+ }
+ switch(this->ELFType)
+ {
+ case cmELF::FileTypeInvalid:
+ os << " invalid file";
+ break;
+ case cmELF::FileTypeRelocatableObject:
+ os << " relocatable object";
+ break;
+ case cmELF::FileTypeExecutable:
+ os << " executable";
+ break;
+ case cmELF::FileTypeSharedLibrary:
+ os << " shared library";
+ break;
+ case cmELF::FileTypeCore:
+ os << " core file";
+ break;
+ case cmELF::FileTypeSpecificOS:
+ os << " os-specific type";
+ break;
+ case cmELF::FileTypeSpecificProc:
+ os << " processor-specific type";
+ break;
+ }
+ os << "\n";
+ }
+
+private:
+ void ByteSwap(ELF_Ehdr& elf_header)
+ {
+ cmELFByteSwap(elf_header.e_type);
+ cmELFByteSwap(elf_header.e_machine);
+ cmELFByteSwap(elf_header.e_version);
+ cmELFByteSwap(elf_header.e_entry);
+ cmELFByteSwap(elf_header.e_phoff);
+ cmELFByteSwap(elf_header.e_shoff);
+ cmELFByteSwap(elf_header.e_flags);
+ cmELFByteSwap(elf_header.e_ehsize);
+ cmELFByteSwap(elf_header.e_phentsize);
+ cmELFByteSwap(elf_header.e_phnum);
+ cmELFByteSwap(elf_header.e_shentsize);
+ cmELFByteSwap(elf_header.e_shnum);
+ cmELFByteSwap(elf_header.e_shstrndx);
+ }
+
+ void ByteSwap(ELF_Shdr& sec_header)
+ {
+ cmELFByteSwap(sec_header.sh_name);
+ cmELFByteSwap(sec_header.sh_type);
+ cmELFByteSwap(sec_header.sh_flags);
+ cmELFByteSwap(sec_header.sh_addr);
+ cmELFByteSwap(sec_header.sh_offset);
+ cmELFByteSwap(sec_header.sh_size);
+ cmELFByteSwap(sec_header.sh_link);
+ cmELFByteSwap(sec_header.sh_info);
+ cmELFByteSwap(sec_header.sh_addralign);
+ cmELFByteSwap(sec_header.sh_entsize);
+ }
+
+ void ByteSwap(ELF_Dyn& dyn)
+ {
+ cmELFByteSwap(dyn.d_tag);
+ switch (dyn.d_tag)
+ {
+ case DT_NULL: /* dyn.d_un ignored */ break;
+ case DT_NEEDED: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_PLTRELSZ: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_PLTGOT: cmELFByteSwap(dyn.d_un.d_ptr); break;
+ case DT_HASH: cmELFByteSwap(dyn.d_un.d_ptr); break;
+ case DT_STRTAB: cmELFByteSwap(dyn.d_un.d_ptr); break;
+ case DT_SYMTAB: cmELFByteSwap(dyn.d_un.d_ptr); break;
+ case DT_RELA: cmELFByteSwap(dyn.d_un.d_ptr); break;
+ case DT_RELASZ: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_RELAENT: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_STRSZ: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_SYMENT: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_INIT: cmELFByteSwap(dyn.d_un.d_ptr); break;
+ case DT_FINI: cmELFByteSwap(dyn.d_un.d_ptr); break;
+ case DT_SONAME: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_RPATH: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_SYMBOLIC: /* dyn.d_un ignored */ break;
+ case DT_REL: cmELFByteSwap(dyn.d_un.d_ptr); break;
+ case DT_RELSZ: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_RELENT: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_PLTREL: cmELFByteSwap(dyn.d_un.d_val); break;
+ case DT_DEBUG: cmELFByteSwap(dyn.d_un.d_ptr); break;
+ case DT_TEXTREL: /* dyn.d_un ignored */ break;
+ case DT_JMPREL: cmELFByteSwap(dyn.d_un.d_ptr); break;
+#ifdef T_BIND_NOW
+ case T_BIND_NOW: /* dyn.d_un ignored */ break;
+#endif
+#ifdef DT_INIT_ARRAY
+ case DT_INIT_ARRAY: cmELFByteSwap(dyn.d_un.d_ptr); break;
+#endif
+#ifdef DT_FINI_ARRAY
+ case DT_FINI_ARRAY: cmELFByteSwap(dyn.d_un.d_ptr); break;
+#endif
+#ifdef DT_INIT_ARRAYSZ
+ case DT_INIT_ARRAYSZ: cmELFByteSwap(dyn.d_un.d_val); break;
+#endif
+#ifdef DT_FINI_ARRAYSZ
+ case DT_FINI_ARRAYSZ: cmELFByteSwap(dyn.d_un.d_val); break;
+#endif
+#ifdef DT_RUNPATH
+ case DT_RUNPATH: cmELFByteSwap(dyn.d_un.d_val); break;
+#endif
+#ifdef DT_FLAGS
+ case DT_FLAGS: cmELFByteSwap(dyn.d_un.d_val); break;
+#endif
+#ifdef DT_PREINIT_ARRAY
+ case DT_PREINIT_ARRAY: cmELFByteSwap(dyn.d_un.d_ptr); break;
+#endif
+#ifdef DT_PREINIT_ARRAYSZ
+ case DT_PREINIT_ARRAYSZ: cmELFByteSwap(dyn.d_un.d_val); break;
+#endif
+ }
+ }
+
+ bool FileTypeValid(ELF_Half et)
+ {
+ unsigned int eti = static_cast<unsigned int>(et);
+ if(eti == ET_NONE || eti == ET_REL || eti == ET_EXEC ||
+ eti == ET_DYN || eti == ET_CORE)
+ {
+ return true;
+ }
+#if defined(ET_LOOS) && defined(ET_HIOS)
+ if(eti >= ET_LOOS && eti <= ET_HIOS)
+ {
+ return true;
+ }
+#endif
+#if defined(ET_LOPROC) && defined(ET_HIPROC)
+ if(eti >= ET_LOPROC && eti <= ET_HIPROC)
+ {
+ return true;
+ }
+#endif
+ return false;
+ }
+
+ bool Read(ELF_Ehdr& x)
+ {
+ // Read the header from the file.
+ if(!this->Stream.read(reinterpret_cast<char*>(&x), sizeof(x)))
+ {
+ return false;
+ }
+
+ // The byte order of ELF header fields may not match that of the
+ // processor-specific data. The header fields are ordered to
+ // match the target execution environment, so we may need to
+ // memorize the order of all platforms based on the e_machine
+ // value. As a heuristic, if the type is invalid but its
+ // swapped value is okay then flip our swap mode.
+ ELF_Half et = x.e_type;
+ if(this->NeedSwap)
+ {
+ cmELFByteSwap(et);
+ }
+ if(!this->FileTypeValid(et))
+ {
+ cmELFByteSwap(et);
+ if(this->FileTypeValid(et))
+ {
+ // The previous byte order guess was wrong. Flip it.
+ this->NeedSwap = !this->NeedSwap;
+ }
+ }
+
+ // Fix the byte order of the header.
+ if(this->NeedSwap)
+ {
+ ByteSwap(x);
+ }
+ return true;
+ }
+ bool Read(ELF_Shdr& x)
+ {
+ if(this->Stream.read(reinterpret_cast<char*>(&x), sizeof(x)) &&
+ this->NeedSwap)
+ {
+ ByteSwap(x);
+ }
+ return this->Stream? true:false;
+ }
+ bool Read(ELF_Dyn& x)
+ {
+ if(this->Stream.read(reinterpret_cast<char*>(&x), sizeof(x)) &&
+ this->NeedSwap)
+ {
+ ByteSwap(x);
+ }
+ return this->Stream? true:false;
+ }
+
+ bool LoadSectionHeader(ELF_Half i)
+ {
+ // Read the section header from the file.
+ this->Stream.seekg(this->ELFHeader.e_shoff +
+ this->ELFHeader.e_shentsize * i);
+ if(!this->Read(this->SectionHeaders[i]))
+ {
+ return false;
+ }
+
+ // Identify some important sections.
+ if(this->SectionHeaders[i].sh_type == SHT_DYNAMIC)
+ {
+ this->DynamicSectionIndex = i;
+ }
+ return true;
+ }
+
+ bool LoadDynamicSection();
+
+ // Store the main ELF header.
+ ELF_Ehdr ELFHeader;
+
+ // Store all the section headers.
+ std::vector<ELF_Shdr> SectionHeaders;
+
+ // Store all entries of the DYNAMIC section.
+ std::vector<ELF_Dyn> DynamicSectionEntries;
+};
+
+//----------------------------------------------------------------------------
+template <class Types>
+cmELFInternalImpl<Types>
+::cmELFInternalImpl(cmELF* external,
+ cmsys::auto_ptr<cmsys::ifstream>& fin,
+ ByteOrderType order):
+ cmELFInternal(external, fin, order)
+{
+ // Read the main header.
+ if(!this->Read(this->ELFHeader))
+ {
+ this->SetErrorMessage("Failed to read main ELF header.");
+ return;
+ }
+
+ // Determine the ELF file type.
+ switch(this->ELFHeader.e_type)
+ {
+ case ET_NONE:
+ this->SetErrorMessage("ELF file type is NONE.");
+ return;
+ case ET_REL:
+ this->ELFType = cmELF::FileTypeRelocatableObject;
+ break;
+ case ET_EXEC:
+ this->ELFType = cmELF::FileTypeExecutable;
+ break;
+ case ET_DYN:
+ this->ELFType = cmELF::FileTypeSharedLibrary;
+ break;
+ case ET_CORE:
+ this->ELFType = cmELF::FileTypeCore;
+ break;
+ default:
+ {
+ unsigned int eti = static_cast<unsigned int>(this->ELFHeader.e_type);
+#if defined(ET_LOOS) && defined(ET_HIOS)
+ if(eti >= ET_LOOS && eti <= ET_HIOS)
+ {
+ this->ELFType = cmELF::FileTypeSpecificOS;
+ break;
+ }
+#endif
+#if defined(ET_LOPROC) && defined(ET_HIPROC)
+ if(eti >= ET_LOPROC && eti <= ET_HIPROC)
+ {
+ this->ELFType = cmELF::FileTypeSpecificProc;
+ break;
+ }
+#endif
+ cmOStringStream e;
+ e << "Unknown ELF file type " << eti;
+ this->SetErrorMessage(e.str().c_str());
+ return;
+ }
+ }
+
+ // Load the section headers.
+ this->SectionHeaders.resize(this->ELFHeader.e_shnum);
+ for(ELF_Half i=0; i < this->ELFHeader.e_shnum; ++i)
+ {
+ if(!this->LoadSectionHeader(i))
+ {
+ this->SetErrorMessage("Failed to load section headers.");
+ return;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+template <class Types>
+bool cmELFInternalImpl<Types>::LoadDynamicSection()
+{
+ // If there is no dynamic section we are done.
+ if(this->DynamicSectionIndex < 0)
+ {
+ return false;
+ }
+
+ // If the section was already loaded we are done.
+ if(!this->DynamicSectionEntries.empty())
+ {
+ return true;
+ }
+
+ // Allocate the dynamic section entries.
+ ELF_Shdr const& sec = this->SectionHeaders[this->DynamicSectionIndex];
+ int n = static_cast<int>(sec.sh_size / sec.sh_entsize);
+ this->DynamicSectionEntries.resize(n);
+
+ // Read each entry.
+ for(int j=0; j < n; ++j)
+ {
+ // Seek to the beginning of the section entry.
+ this->Stream.seekg(sec.sh_offset + sec.sh_entsize*j);
+ ELF_Dyn& dyn = this->DynamicSectionEntries[j];
+
+ // Try reading the entry.
+ if(!this->Read(dyn))
+ {
+ this->SetErrorMessage("Error reading entry from DYNAMIC section.");
+ this->DynamicSectionIndex = -1;
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+template <class Types>
+unsigned int cmELFInternalImpl<Types>::GetDynamicEntryCount()
+{
+ if(!this->LoadDynamicSection())
+ {
+ return 0;
+ }
+ for(unsigned int i = 0; i < this->DynamicSectionEntries.size(); ++i)
+ {
+ if(this->DynamicSectionEntries[i].d_tag == DT_NULL)
+ {
+ return i;
+ }
+ }
+ return static_cast<unsigned int>(this->DynamicSectionEntries.size());
+}
+
+//----------------------------------------------------------------------------
+template <class Types>
+unsigned long cmELFInternalImpl<Types>::GetDynamicEntryPosition(int j)
+{
+ if(!this->LoadDynamicSection())
+ {
+ return 0;
+ }
+ if(j < 0 || j >= static_cast<int>(this->DynamicSectionEntries.size()))
+ {
+ return 0;
+ }
+ ELF_Shdr const& sec = this->SectionHeaders[this->DynamicSectionIndex];
+ return static_cast<unsigned long>(sec.sh_offset + sec.sh_entsize*j);
+}
+
+//----------------------------------------------------------------------------
+template <class Types>
+cmELF::StringEntry const*
+cmELFInternalImpl<Types>::GetDynamicSectionString(unsigned int tag)
+{
+ // Short-circuit if already checked.
+ std::map<unsigned int, StringEntry>::iterator dssi =
+ this->DynamicSectionStrings.find(tag);
+ if(dssi != this->DynamicSectionStrings.end())
+ {
+ if(dssi->second.Position > 0)
+ {
+ return &dssi->second;
+ }
+ return 0;
+ }
+
+ // Create an entry for this tag. Assume it is missing until found.
+ StringEntry& se = this->DynamicSectionStrings[tag];
+ se.Position = 0;
+ se.Size = 0;
+ se.IndexInSection = -1;
+
+ // Try reading the dynamic section.
+ if(!this->LoadDynamicSection())
+ {
+ return 0;
+ }
+
+ // Get the string table referenced by the DYNAMIC section.
+ ELF_Shdr const& sec = this->SectionHeaders[this->DynamicSectionIndex];
+ if(sec.sh_link >= this->SectionHeaders.size())
+ {
+ this->SetErrorMessage("Section DYNAMIC has invalid string table index.");
+ return 0;
+ }
+ ELF_Shdr const& strtab = this->SectionHeaders[sec.sh_link];
+
+ // Look for the requested entry.
+ for(typename std::vector<ELF_Dyn>::iterator
+ di = this->DynamicSectionEntries.begin();
+ di != this->DynamicSectionEntries.end(); ++di)
+ {
+ ELF_Dyn& dyn = *di;
+ if(static_cast<tagtype>(dyn.d_tag) == static_cast<tagtype>(tag))
+ {
+ // We found the tag requested.
+ // Make sure the position given is within the string section.
+ if(dyn.d_un.d_val >= strtab.sh_size)
+ {
+ this->SetErrorMessage("Section DYNAMIC references string beyond "
+ "the end of its string section.");
+ return 0;
+ }
+
+ // Seek to the position reported by the entry.
+ unsigned long first = static_cast<unsigned long>(dyn.d_un.d_val);
+ unsigned long last = first;
+ unsigned long end = static_cast<unsigned long>(strtab.sh_size);
+ this->Stream.seekg(strtab.sh_offset + first);
+
+ // Read the string. It may be followed by more than one NULL
+ // terminator. Count the total size of the region allocated to
+ // the string. This assumes that the next string in the table
+ // is non-empty, but the "chrpath" tool makes the same
+ // assumption.
+ bool terminated = false;
+ char c;
+ while(last != end && this->Stream.get(c) && !(terminated && c))
+ {
+ ++last;
+ if(c)
+ {
+ se.Value += c;
+ }
+ else
+ {
+ terminated = true;
+ }
+ }
+
+ // Make sure the whole value was read.
+ if(!this->Stream)
+ {
+ this->SetErrorMessage("Dynamic section specifies unreadable RPATH.");
+ se.Value = "";
+ return 0;
+ }
+
+ // The value has been read successfully. Report it.
+ se.Position = static_cast<unsigned long>(strtab.sh_offset + first);
+ se.Size = last - first;
+ se.IndexInSection =
+ static_cast<int>(di - this->DynamicSectionEntries.begin());
+ return &se;
+ }
+ }
+ return 0;
+}
+
+//============================================================================
+// External class implementation.
+
+//----------------------------------------------------------------------------
+cmELF::cmELF(const char* fname): Internal(0)
+{
+ // Try to open the file.
+ cmsys::auto_ptr<cmsys::ifstream> fin(new cmsys::ifstream(fname));
+
+ // Quit now if the file could not be opened.
+ if(!fin.get() || !*fin)
+ {
+ this->ErrorMessage = "Error opening input file.";
+ return;
+ }
+
+ // Read the ELF identification block.
+ char ident[EI_NIDENT];
+ if(!fin->read(ident, EI_NIDENT))
+ {
+ this->ErrorMessage = "Error reading ELF identification.";
+ return;
+ }
+ if(!fin->seekg(0))
+ {
+ this->ErrorMessage = "Error seeking to beginning of file.";
+ return;
+ }
+
+ // Verify the ELF identification.
+ if(!(ident[EI_MAG0] == ELFMAG0 &&
+ ident[EI_MAG1] == ELFMAG1 &&
+ ident[EI_MAG2] == ELFMAG2 &&
+ ident[EI_MAG3] == ELFMAG3))
+ {
+ this->ErrorMessage = "File does not have a valid ELF identification.";
+ return;
+ }
+
+ // Check the byte order in which the rest of the file is encoded.
+ cmELFInternal::ByteOrderType order;
+ if(ident[EI_DATA] == ELFDATA2LSB)
+ {
+ // File is LSB.
+ order = cmELFInternal::ByteOrderLSB;
+ }
+ else if(ident[EI_DATA] == ELFDATA2MSB)
+ {
+ // File is MSB.
+ order = cmELFInternal::ByteOrderMSB;
+ }
+ else
+ {
+ this->ErrorMessage = "ELF file is not LSB or MSB encoded.";
+ return;
+ }
+
+ // Check the class of the file and construct the corresponding
+ // parser implementation.
+ if(ident[EI_CLASS] == ELFCLASS32)
+ {
+ // 32-bit ELF
+ this->Internal = new cmELFInternalImpl<cmELFTypes32>(this, fin, order);
+ }
+ else if(ident[EI_CLASS] == ELFCLASS64)
+ {
+ // 64-bit ELF
+ this->Internal = new cmELFInternalImpl<cmELFTypes64>(this, fin, order);
+ }
+ else
+ {
+ this->ErrorMessage = "ELF file class is not 32-bit or 64-bit.";
+ return;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmELF::~cmELF()
+{
+ delete this->Internal;
+}
+
+//----------------------------------------------------------------------------
+bool cmELF::Valid() const
+{
+ return this->Internal && this->Internal->GetFileType() != FileTypeInvalid;
+}
+
+//----------------------------------------------------------------------------
+cmELF::FileType cmELF::GetFileType() const
+{
+ if(this->Valid())
+ {
+ return this->Internal->GetFileType();
+ }
+ else
+ {
+ return FileTypeInvalid;
+ }
+}
+
+//----------------------------------------------------------------------------
+unsigned int cmELF::GetNumberOfSections() const
+{
+ if(this->Valid())
+ {
+ return this->Internal->GetNumberOfSections();
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+unsigned int cmELF::GetDynamicEntryCount() const
+{
+ if(this->Valid())
+ {
+ return this->Internal->GetDynamicEntryCount();
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+unsigned long cmELF::GetDynamicEntryPosition(int index) const
+{
+ if(this->Valid())
+ {
+ return this->Internal->GetDynamicEntryPosition(index);
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmELF::ReadBytes(unsigned long pos, unsigned long size, char* buf) const
+{
+ if(this->Valid())
+ {
+ return this->Internal->ReadBytes(pos, size, buf);
+ }
+ else
+ {
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmELF::GetSOName(std::string& soname)
+{
+ if(StringEntry const* se = this->GetSOName())
+ {
+ soname = se->Value;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmELF::StringEntry const* cmELF::GetSOName()
+{
+ if(this->Valid() &&
+ this->Internal->GetFileType() == cmELF::FileTypeSharedLibrary)
+ {
+ return this->Internal->GetSOName();
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmELF::StringEntry const* cmELF::GetRPath()
+{
+ if(this->Valid() &&
+ (this->Internal->GetFileType() == cmELF::FileTypeExecutable ||
+ this->Internal->GetFileType() == cmELF::FileTypeSharedLibrary))
+ {
+ return this->Internal->GetRPath();
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmELF::StringEntry const* cmELF::GetRunPath()
+{
+ if(this->Valid() &&
+ (this->Internal->GetFileType() == cmELF::FileTypeExecutable ||
+ this->Internal->GetFileType() == cmELF::FileTypeSharedLibrary))
+ {
+ return this->Internal->GetRunPath();
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmELF::PrintInfo(std::ostream& os) const
+{
+ if(this->Valid())
+ {
+ this->Internal->PrintInfo(os);
+ }
+ else
+ {
+ os << "Not a valid ELF file.\n";
+ }
+}
diff --git a/Source/cmELF.h b/Source/cmELF.h
new file mode 100644
index 0000000000..ab9be42450
--- /dev/null
+++ b/Source/cmELF.h
@@ -0,0 +1,108 @@
+/*============================================================================
+ 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 cmELF_h
+#define cmELF_h
+
+#if !defined(CMAKE_USE_ELF_PARSER)
+# error "This file may be included only if CMAKE_USE_ELF_PARSER is enabled."
+#endif
+
+class cmELFInternal;
+
+/** \class cmELF
+ * \brief Executable and Link Format (ELF) parser.
+ */
+class cmELF
+{
+public:
+ /** Construct with the name of the ELF input file to parse. */
+ cmELF(const char* fname);
+
+ /** Destruct. */
+ ~cmELF();
+
+ /** Get the error message if any. */
+ std::string const& GetErrorMessage() const
+ {
+ return this->ErrorMessage;
+ }
+
+ /** Boolean conversion. True if the ELF file is valid. */
+ operator bool() const { return this->Valid(); }
+
+ /** Enumeration of ELF file types. */
+ enum FileType
+ {
+ FileTypeInvalid,
+ FileTypeRelocatableObject,
+ FileTypeExecutable,
+ FileTypeSharedLibrary,
+ FileTypeCore,
+ FileTypeSpecificOS,
+ FileTypeSpecificProc
+ };
+
+ /** Represent string table entries. */
+ struct StringEntry
+ {
+ // The string value itself.
+ std::string Value;
+
+ // The position in the file at which the string appears.
+ unsigned long Position;
+
+ // The size of the string table entry. This includes the space
+ // allocated for one or more null terminators.
+ unsigned long Size;
+
+ // The index of the section entry referencing the string.
+ int IndexInSection;
+ };
+
+ /** Get the type of the file opened. */
+ FileType GetFileType() const;
+
+ /** Get the number of ELF sections present. */
+ unsigned int GetNumberOfSections() const;
+
+ /** Get the number of DYNAMIC section entries before the first
+ DT_NULL. Returns zero on error. */
+ unsigned int GetDynamicEntryCount() const;
+
+ /** Get the position of a DYNAMIC section header entry. Returns
+ zero on error. */
+ unsigned long GetDynamicEntryPosition(int index) const;
+
+ /** Read bytes from the file. */
+ bool ReadBytes(unsigned long pos, unsigned long size, char* buf) const;
+
+ /** Get the SONAME field if any. */
+ bool GetSOName(std::string& soname);
+ StringEntry const* GetSOName();
+
+ /** Get the RPATH field if any. */
+ StringEntry const* GetRPath();
+
+ /** Get the RUNPATH field if any. */
+ StringEntry const* GetRunPath();
+
+ /** Print human-readable information about the ELF file. */
+ void PrintInfo(std::ostream& os) const;
+
+private:
+ friend class cmELFInternal;
+ bool Valid() const;
+ cmELFInternal* Internal;
+ std::string ErrorMessage;
+};
+
+#endif
diff --git a/Source/cmElseCommand.cxx b/Source/cmElseCommand.cxx
new file mode 100644
index 0000000000..163d006ad1
--- /dev/null
+++ b/Source/cmElseCommand.cxx
@@ -0,0 +1,21 @@
+/*============================================================================
+ 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 "cmElseCommand.h"
+
+bool cmElseCommand::InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &)
+{
+ this->SetError("An ELSE command was found outside of a proper "
+ "IF ENDIF structure. Or its arguments did not match "
+ "the opening IF command.");
+ return false;
+}
diff --git a/Source/cmElseCommand.h b/Source/cmElseCommand.h
new file mode 100644
index 0000000000..dde5fcc618
--- /dev/null
+++ b/Source/cmElseCommand.h
@@ -0,0 +1,54 @@
+/*============================================================================
+ 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 cmElseCommand_h
+#define cmElseCommand_h
+
+#include "cmIfCommand.h"
+
+/** \class cmElseCommand
+ * \brief ends an if block
+ *
+ * cmElseCommand ends an if block
+ */
+class cmElseCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmElseCommand;
+ }
+
+ /**
+ * 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 "else";}
+
+ cmTypeMacro(cmElseCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmElseIfCommand.cxx b/Source/cmElseIfCommand.cxx
new file mode 100644
index 0000000000..cd9742bbd4
--- /dev/null
+++ b/Source/cmElseIfCommand.cxx
@@ -0,0 +1,20 @@
+/*============================================================================
+ 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 "cmElseIfCommand.h"
+
+bool cmElseIfCommand::InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &)
+{
+ this->SetError("An ELSEIF command was found outside of a proper "
+ "IF ENDIF structure.");
+ return false;
+}
diff --git a/Source/cmElseIfCommand.h b/Source/cmElseIfCommand.h
new file mode 100644
index 0000000000..c627cbe5e0
--- /dev/null
+++ b/Source/cmElseIfCommand.h
@@ -0,0 +1,54 @@
+/*============================================================================
+ 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 cmElseIfCommand_h
+#define cmElseIfCommand_h
+
+#include "cmIfCommand.h"
+
+/** \class cmElseIfCommand
+ * \brief ends an if block
+ *
+ * cmElseIfCommand ends an if block
+ */
+class cmElseIfCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmElseIfCommand;
+ }
+
+ /**
+ * 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 "elseif";}
+
+ cmTypeMacro(cmElseIfCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmEnableLanguageCommand.cxx b/Source/cmEnableLanguageCommand.cxx
new file mode 100644
index 0000000000..dcabf6a468
--- /dev/null
+++ b/Source/cmEnableLanguageCommand.cxx
@@ -0,0 +1,43 @@
+/*============================================================================
+ 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 "cmEnableLanguageCommand.h"
+
+// cmEnableLanguageCommand
+bool cmEnableLanguageCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ bool optional = false;
+ std::vector<std::string> languages;
+ if(args.size() < 1 )
+ {
+ this->SetError
+ ("called with incorrect number of arguments");
+ return false;
+ }
+ for (std::vector<std::string>::const_iterator it = args.begin();
+ it != args.end();
+ ++it)
+ {
+ if ((*it) == "OPTIONAL")
+ {
+ optional = true;
+ }
+ else
+ {
+ languages.push_back(*it);
+ }
+ }
+
+ this->Makefile->EnableLanguage(languages, optional);
+ return true;
+}
+
diff --git a/Source/cmEnableLanguageCommand.h b/Source/cmEnableLanguageCommand.h
new file mode 100644
index 0000000000..2b09e1186a
--- /dev/null
+++ b/Source/cmEnableLanguageCommand.h
@@ -0,0 +1,53 @@
+/*============================================================================
+ 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 cmEnableLanguageCommand_h
+#define cmEnableLanguageCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmEnableLanguageCommand
+ * \brief Specify the name for this build project.
+ *
+ * cmEnableLanguageCommand is used to specify a name for this build project.
+ * It is defined once per set of CMakeList.txt files (including
+ * all subdirectories). Currently it just sets the name of the workspace
+ * file for Microsoft Visual C++
+ */
+class cmEnableLanguageCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmEnableLanguageCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "enable_language";}
+
+ cmTypeMacro(cmEnableLanguageCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmEnableTestingCommand.cxx b/Source/cmEnableTestingCommand.cxx
new file mode 100644
index 0000000000..aa41ef73b9
--- /dev/null
+++ b/Source/cmEnableTestingCommand.cxx
@@ -0,0 +1,22 @@
+/*============================================================================
+ 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 "cmEnableTestingCommand.h"
+#include "cmLocalGenerator.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;
+}
diff --git a/Source/cmEnableTestingCommand.h b/Source/cmEnableTestingCommand.h
new file mode 100644
index 0000000000..d028c59b44
--- /dev/null
+++ b/Source/cmEnableTestingCommand.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 cmEnableTestingCommand_h
+#define cmEnableTestingCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmEnableTestingCommand
+ * \brief Enable testing for this directory and below.
+ *
+ * Produce the output testfile. This produces a file in the build directory
+ * called CMakeTestfile with a syntax similar to CMakeLists.txt. It contains
+ * the SUBDIRS() and ADD_TEST() commands from the source CMakeLists.txt
+ * file with CMake variables expanded. Only the subdirs and tests
+ * within the valid control structures are replicated in Testfile
+ * (i.e. SUBDIRS() and ADD_TEST() commands within IF() commands that are
+ * not entered by CMake are not replicated in Testfile).
+ * Note that CTest expects to find this file in the build directory root;
+ * therefore, this command should be in the source directory root too.
+ */
+class cmEnableTestingCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmEnableTestingCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "enable_testing";}
+
+ cmTypeMacro(cmEnableTestingCommand, cmCommand);
+
+};
+
+
+#endif
diff --git a/Source/cmEndForEachCommand.cxx b/Source/cmEndForEachCommand.cxx
new file mode 100644
index 0000000000..7f11ae5f95
--- /dev/null
+++ b/Source/cmEndForEachCommand.cxx
@@ -0,0 +1,23 @@
+/*============================================================================
+ 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 "cmEndForEachCommand.h"
+
+bool cmEndForEachCommand
+::InvokeInitialPass(std::vector<cmListFileArgument> const&,
+ cmExecutionStatus &)
+{
+ this->SetError("An ENDFOREACH command was found outside of a proper "
+ "FOREACH ENDFOREACH structure. Or its arguments did "
+ "not match the opening FOREACH command.");
+ return false;
+}
+
diff --git a/Source/cmEndForEachCommand.h b/Source/cmEndForEachCommand.h
new file mode 100644
index 0000000000..c3be3879bb
--- /dev/null
+++ b/Source/cmEndForEachCommand.h
@@ -0,0 +1,61 @@
+/*============================================================================
+ 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 cmEndForEachCommand_h
+#define cmEndForEachCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmEndForEachCommand
+ * \brief ends an if block
+ *
+ * cmEndForEachCommand ends an if block
+ */
+class cmEndForEachCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmEndForEachCommand;
+ }
+
+ /**
+ * Override cmCommand::InvokeInitialPass to get arguments before
+ * expansion.
+ */
+ virtual bool InvokeInitialPass(std::vector<cmListFileArgument> const&,
+ cmExecutionStatus &);
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &) {return false;}
+
+ /**
+ * 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 "endforeach";}
+
+ cmTypeMacro(cmEndForEachCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmEndFunctionCommand.cxx b/Source/cmEndFunctionCommand.cxx
new file mode 100644
index 0000000000..04b242d707
--- /dev/null
+++ b/Source/cmEndFunctionCommand.cxx
@@ -0,0 +1,23 @@
+/*============================================================================
+ 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 "cmEndFunctionCommand.h"
+
+bool cmEndFunctionCommand
+::InvokeInitialPass(std::vector<cmListFileArgument> const&,
+ cmExecutionStatus &)
+{
+ this->SetError("An ENDFUNCTION command was found outside of a proper "
+ "FUNCTION ENDFUNCTION structure. Or its arguments did not "
+ "match the opening FUNCTION command.");
+ return false;
+}
+
diff --git a/Source/cmEndFunctionCommand.h b/Source/cmEndFunctionCommand.h
new file mode 100644
index 0000000000..3a42c17432
--- /dev/null
+++ b/Source/cmEndFunctionCommand.h
@@ -0,0 +1,61 @@
+/*============================================================================
+ 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 cmEndFunctionCommand_h
+#define cmEndFunctionCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmEndFunctionCommand
+ * \brief ends an if block
+ *
+ * cmEndFunctionCommand ends an if block
+ */
+class cmEndFunctionCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmEndFunctionCommand;
+ }
+
+ /**
+ * Override cmCommand::InvokeInitialPass to get arguments before
+ * expansion.
+ */
+ virtual bool InvokeInitialPass(std::vector<cmListFileArgument> const&,
+ cmExecutionStatus &);
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &) {return false;}
+
+ /**
+ * 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 "endfunction";}
+
+ cmTypeMacro(cmEndFunctionCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmEndIfCommand.cxx b/Source/cmEndIfCommand.cxx
new file mode 100644
index 0000000000..0ac09de727
--- /dev/null
+++ b/Source/cmEndIfCommand.cxx
@@ -0,0 +1,29 @@
+/*============================================================================
+ 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 "cmEndIfCommand.h"
+#include <stdlib.h> // required for atof
+bool cmEndIfCommand::InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &)
+{
+ const char* versionValue
+ = this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
+ if (!versionValue || (atof(versionValue) <= 1.4))
+ {
+ return true;
+ }
+
+ this->SetError("An ENDIF command was found outside of a proper "
+ "IF ENDIF structure. Or its arguments did not match "
+ "the opening IF command.");
+ return false;
+}
+
diff --git a/Source/cmEndIfCommand.h b/Source/cmEndIfCommand.h
new file mode 100644
index 0000000000..a8248c81a5
--- /dev/null
+++ b/Source/cmEndIfCommand.h
@@ -0,0 +1,54 @@
+/*============================================================================
+ 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 cmEndIfCommand_h
+#define cmEndIfCommand_h
+
+#include "cmIfCommand.h"
+
+/** \class cmEndIfCommand
+ * \brief ends an if block
+ *
+ * cmEndIfCommand ends an if block
+ */
+class cmEndIfCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmEndIfCommand;
+ }
+
+ /**
+ * 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 "endif";}
+
+ cmTypeMacro(cmEndIfCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmEndMacroCommand.cxx b/Source/cmEndMacroCommand.cxx
new file mode 100644
index 0000000000..86d907ba4d
--- /dev/null
+++ b/Source/cmEndMacroCommand.cxx
@@ -0,0 +1,23 @@
+/*============================================================================
+ 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 "cmEndMacroCommand.h"
+
+bool cmEndMacroCommand
+::InvokeInitialPass(std::vector<cmListFileArgument> const&,
+ cmExecutionStatus &)
+{
+ this->SetError("An ENDMACRO command was found outside of a proper "
+ "MACRO ENDMACRO structure. Or its arguments did not "
+ "match the opening MACRO command.");
+ return false;
+}
+
diff --git a/Source/cmEndMacroCommand.h b/Source/cmEndMacroCommand.h
new file mode 100644
index 0000000000..fdc04eebb1
--- /dev/null
+++ b/Source/cmEndMacroCommand.h
@@ -0,0 +1,61 @@
+/*============================================================================
+ 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 cmEndMacroCommand_h
+#define cmEndMacroCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmEndMacroCommand
+ * \brief ends an if block
+ *
+ * cmEndMacroCommand ends an if block
+ */
+class cmEndMacroCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmEndMacroCommand;
+ }
+
+ /**
+ * Override cmCommand::InvokeInitialPass to get arguments before
+ * expansion.
+ */
+ virtual bool InvokeInitialPass(std::vector<cmListFileArgument> const&,
+ cmExecutionStatus &);
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &) {return false;}
+
+ /**
+ * 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 "endmacro";}
+
+ cmTypeMacro(cmEndMacroCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmEndWhileCommand.cxx b/Source/cmEndWhileCommand.cxx
new file mode 100644
index 0000000000..abb9e5e0b3
--- /dev/null
+++ b/Source/cmEndWhileCommand.cxx
@@ -0,0 +1,32 @@
+/*============================================================================
+ 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 "cmEndWhileCommand.h"
+
+bool cmEndWhileCommand
+::InvokeInitialPass(std::vector<cmListFileArgument> const& args,
+ cmExecutionStatus &)
+{
+ if (args.empty())
+ {
+ this->SetError("An ENDWHILE command was found outside of a proper "
+ "WHILE ENDWHILE structure.");
+ }
+ else
+ {
+ this->SetError("An ENDWHILE command was found outside of a proper "
+ "WHILE ENDWHILE structure. Or its arguments did not "
+ "match the opening WHILE command.");
+ }
+
+ return false;
+}
+
diff --git a/Source/cmEndWhileCommand.h b/Source/cmEndWhileCommand.h
new file mode 100644
index 0000000000..ec1cb652fa
--- /dev/null
+++ b/Source/cmEndWhileCommand.h
@@ -0,0 +1,61 @@
+/*============================================================================
+ 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 cmEndWhileCommand_h
+#define cmEndWhileCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmEndWhileCommand
+ * \brief ends a while loop
+ *
+ * cmEndWhileCommand ends a while loop
+ */
+class cmEndWhileCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmEndWhileCommand;
+ }
+
+ /**
+ * Override cmCommand::InvokeInitialPass to get arguments before
+ * expansion.
+ */
+ virtual bool InvokeInitialPass(std::vector<cmListFileArgument> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &) {return false;}
+
+ /**
+ * 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 "endwhile";}
+
+ cmTypeMacro(cmEndWhileCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx
new file mode 100644
index 0000000000..9b5908899d
--- /dev/null
+++ b/Source/cmExecProgramCommand.cxx
@@ -0,0 +1,333 @@
+/*============================================================================
+ 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 "cmExecProgramCommand.h"
+#include "cmSystemTools.h"
+
+#include <cmsys/Process.h>
+
+// cmExecProgramCommand
+bool cmExecProgramCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ std::string arguments;
+ bool doingargs = false;
+ int count = 0;
+ std::string output_variable;
+ bool haveoutput_variable = false;
+ std::string return_variable;
+ bool havereturn_variable = false;
+ for(size_t i=0; i < args.size(); ++i)
+ {
+ if(args[i] == "OUTPUT_VARIABLE")
+ {
+ count++;
+ doingargs = false;
+ havereturn_variable = false;
+ haveoutput_variable = true;
+ }
+ else if ( haveoutput_variable )
+ {
+ if ( output_variable.size() > 0 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ output_variable = args[i];
+ haveoutput_variable = false;
+ count ++;
+ }
+ else if(args[i] == "RETURN_VALUE")
+ {
+ count++;
+ doingargs = false;
+ haveoutput_variable = false;
+ havereturn_variable = true;
+ }
+ else if ( havereturn_variable )
+ {
+ if ( return_variable.size() > 0 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ return_variable = args[i];
+ havereturn_variable = false;
+ count ++;
+ }
+ else if(args[i] == "ARGS")
+ {
+ count++;
+ havereturn_variable = false;
+ haveoutput_variable = false;
+ doingargs = true;
+ }
+ else if(doingargs)
+ {
+ arguments += args[i];
+ arguments += " ";
+ count++;
+ }
+ }
+
+ std::string command;
+ if(arguments.size())
+ {
+ command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str());
+ command += " ";
+ command += arguments;
+ }
+ else
+ {
+ command = args[0];
+ }
+ bool verbose = true;
+ if(output_variable.size() > 0)
+ {
+ verbose = false;
+ }
+ int retVal = 0;
+ std::string output;
+ bool result = true;
+ if(args.size() - count == 2)
+ {
+ cmSystemTools::MakeDirectory(args[1].c_str());
+ result = cmExecProgramCommand::RunCommand(command.c_str(), output, retVal,
+ args[1].c_str(), verbose);
+ }
+ else
+ {
+ result = cmExecProgramCommand::RunCommand(command.c_str(), output,
+ retVal, 0, verbose);
+ }
+ if(!result)
+ {
+ retVal = -1;
+ }
+
+ if ( output_variable.size() > 0 )
+ {
+ std::string::size_type first = output.find_first_not_of(" \n\t\r");
+ std::string::size_type last = output.find_last_not_of(" \n\t\r");
+ if(first == std::string::npos)
+ {
+ first = 0;
+ }
+ if(last == std::string::npos)
+ {
+ last = output.size()-1;
+ }
+
+ std::string coutput = std::string(output, first, last-first+1);
+ this->Makefile->AddDefinition(output_variable, coutput.c_str());
+ }
+
+ if ( return_variable.size() > 0 )
+ {
+ char buffer[100];
+ sprintf(buffer, "%d", retVal);
+ this->Makefile->AddDefinition(return_variable, buffer);
+ }
+
+ return true;
+}
+
+bool cmExecProgramCommand::RunCommand(const char* command,
+ std::string& output,
+ int &retVal,
+ const char* dir,
+ bool verbose)
+{
+ if(cmSystemTools::GetRunCommandOutput())
+ {
+ verbose = false;
+ }
+
+#if defined(WIN32) && !defined(__CYGWIN__)
+ // if the command does not start with a quote, then
+ // try to find the program, and if the program can not be
+ // found use system to run the command as it must be a built in
+ // shell command like echo or dir
+ int count = 0;
+ std::string shortCmd;
+ if(command[0] == '\"')
+ {
+ // count the number of quotes
+ for(const char* s = command; *s != 0; ++s)
+ {
+ if(*s == '\"')
+ {
+ count++;
+ if(count > 2)
+ {
+ break;
+ }
+ }
+ }
+ // if there are more than two double quotes use
+ // GetShortPathName, the cmd.exe program in windows which
+ // is used by system fails to execute if there are more than
+ // one set of quotes in the arguments
+ if(count > 2)
+ {
+ cmsys::RegularExpression quoted("^\"([^\"]*)\"[ \t](.*)");
+ if(quoted.find(command))
+ {
+ std::string cmd = quoted.match(1);
+ std::string args = quoted.match(2);
+ if(! cmSystemTools::FileExists(cmd.c_str()) )
+ {
+ shortCmd = cmd;
+ }
+ else if(!cmSystemTools::GetShortPath(cmd.c_str(), shortCmd))
+ {
+ cmSystemTools::Error("GetShortPath failed for " , cmd.c_str());
+ return false;
+ }
+ shortCmd += " ";
+ shortCmd += args;
+
+ command = shortCmd.c_str();
+ }
+ else
+ {
+ cmSystemTools::Error("Could not parse command line with quotes ",
+ command);
+ }
+ }
+ }
+#endif
+
+ // Allocate a process instance.
+ cmsysProcess* cp = cmsysProcess_New();
+ if(!cp)
+ {
+ cmSystemTools::Error("Error allocating process instance.");
+ return false;
+ }
+
+#if defined(WIN32) && !defined(__CYGWIN__)
+ if(dir)
+ {
+ cmsysProcess_SetWorkingDirectory(cp, dir);
+ }
+ if(cmSystemTools::GetRunCommandHideConsole())
+ {
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+ }
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
+ const char* cmd[] = {command, 0};
+ cmsysProcess_SetCommand(cp, cmd);
+#else
+ std::string commandInDir;
+ if(dir)
+ {
+ commandInDir = "cd \"";
+ commandInDir += dir;
+ commandInDir += "\" && ";
+ commandInDir += command;
+ }
+ else
+ {
+ commandInDir = command;
+ }
+#ifndef __VMS
+ commandInDir += " 2>&1";
+#endif
+ command = commandInDir.c_str();
+ if(verbose)
+ {
+ cmSystemTools::Stdout("running ");
+ cmSystemTools::Stdout(command);
+ cmSystemTools::Stdout("\n");
+ }
+ fflush(stdout);
+ fflush(stderr);
+ const char* cmd[] = {"/bin/sh", "-c", command, 0};
+ cmsysProcess_SetCommand(cp, cmd);
+#endif
+
+ cmsysProcess_Execute(cp);
+
+ // Read the process output.
+ int length;
+ char* data;
+ int p;
+ while((p = cmsysProcess_WaitForData(cp, &data, &length, 0), p))
+ {
+ if(p == cmsysProcess_Pipe_STDOUT || p == cmsysProcess_Pipe_STDERR)
+ {
+ if(verbose)
+ {
+ cmSystemTools::Stdout(data, length);
+ }
+ output.append(data, length);
+ }
+ }
+
+ // All output has been read. Wait for the process to exit.
+ cmsysProcess_WaitForExit(cp, 0);
+
+ // Check the result of running the process.
+ std::string msg;
+ switch(cmsysProcess_GetState(cp))
+ {
+ case cmsysProcess_State_Exited:
+ retVal = cmsysProcess_GetExitValue(cp);
+ break;
+ case cmsysProcess_State_Exception:
+ retVal = -1;
+ msg += "\nProcess terminated due to: ";
+ msg += cmsysProcess_GetExceptionString(cp);
+ break;
+ case cmsysProcess_State_Error:
+ retVal = -1;
+ msg += "\nProcess failed because: ";
+ msg += cmsysProcess_GetErrorString(cp);
+ break;
+ case cmsysProcess_State_Expired:
+ retVal = -1;
+ msg += "\nProcess terminated due to timeout.";
+ break;
+ }
+ if(!msg.empty())
+ {
+#if defined(WIN32) && !defined(__CYGWIN__)
+ // Old Windows process execution printed this info.
+ msg += "\n\nfor command: ";
+ msg += command;
+ if(dir)
+ {
+ msg += "\nin dir: ";
+ msg += dir;
+ }
+ msg += "\n";
+ if(verbose)
+ {
+ cmSystemTools::Stdout(msg.c_str());
+ }
+ output += msg;
+#else
+ // Old UNIX process execution only put message in output.
+ output += msg;
+#endif
+ }
+
+ // Delete the process instance.
+ cmsysProcess_Delete(cp);
+
+ return true;
+}
diff --git a/Source/cmExecProgramCommand.h b/Source/cmExecProgramCommand.h
new file mode 100644
index 0000000000..23d10f9f14
--- /dev/null
+++ b/Source/cmExecProgramCommand.h
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 cmExecProgramCommand_h
+#define cmExecProgramCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmExecProgramCommand
+ * \brief Command that adds a target to the build system.
+ *
+ * cmExecProgramCommand adds an extra target to the build system.
+ * This is useful when you would like to add special
+ * targets like "install,", "clean," and so on.
+ */
+class cmExecProgramCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmExecProgramCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const
+ {return "exec_program";}
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ /** This command is kept for compatibility with older CMake versions. */
+ virtual bool IsDiscouraged() const
+ {
+ return true;
+ }
+
+ cmTypeMacro(cmExecProgramCommand, cmCommand);
+private:
+ static bool RunCommand(const char* command, std::string& output,
+ int &retVal, const char* directory = 0,
+ bool verbose = true);
+};
+
+#endif
diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx
new file mode 100644
index 0000000000..11f8ae55ba
--- /dev/null
+++ b/Source/cmExecuteProcessCommand.cxx
@@ -0,0 +1,422 @@
+/*============================================================================
+ 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 "cmExecuteProcessCommand.h"
+#include "cmSystemTools.h"
+
+#include <cmsys/Process.h>
+
+#include <ctype.h> /* isspace */
+
+static bool cmExecuteProcessCommandIsWhitespace(char c)
+{
+ return (isspace((int)c) || c == '\n' || c == '\r');
+}
+
+void cmExecuteProcessCommandFixText(std::vector<char>& output,
+ bool strip_trailing_whitespace);
+void cmExecuteProcessCommandAppend(std::vector<char>& output,
+ const char* data, int length);
+
+// cmExecuteProcessCommand
+bool cmExecuteProcessCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ std::vector< std::vector<const char*> > cmds;
+ std::string arguments;
+ bool doing_command = false;
+ size_t command_index = 0;
+ bool output_quiet = false;
+ bool error_quiet = false;
+ bool output_strip_trailing_whitespace = false;
+ bool error_strip_trailing_whitespace = false;
+ std::string timeout_string;
+ std::string input_file;
+ std::string output_file;
+ std::string error_file;
+ std::string output_variable;
+ std::string error_variable;
+ std::string result_variable;
+ std::string working_directory;
+ for(size_t i=0; i < args.size(); ++i)
+ {
+ if(args[i] == "COMMAND")
+ {
+ doing_command = true;
+ command_index = cmds.size();
+ cmds.push_back(std::vector<const char*>());
+ }
+ else if(args[i] == "OUTPUT_VARIABLE")
+ {
+ doing_command = false;
+ if(++i < args.size())
+ {
+ output_variable = args[i];
+ }
+ else
+ {
+ this->SetError(" called with no value for OUTPUT_VARIABLE.");
+ return false;
+ }
+ }
+ else if(args[i] == "ERROR_VARIABLE")
+ {
+ doing_command = false;
+ if(++i < args.size())
+ {
+ error_variable = args[i];
+ }
+ else
+ {
+ this->SetError(" called with no value for ERROR_VARIABLE.");
+ return false;
+ }
+ }
+ else if(args[i] == "RESULT_VARIABLE")
+ {
+ doing_command = false;
+ if(++i < args.size())
+ {
+ result_variable = args[i];
+ }
+ else
+ {
+ this->SetError(" called with no value for RESULT_VARIABLE.");
+ return false;
+ }
+ }
+ else if(args[i] == "WORKING_DIRECTORY")
+ {
+ doing_command = false;
+ if(++i < args.size())
+ {
+ working_directory = args[i];
+ }
+ else
+ {
+ this->SetError(" called with no value for WORKING_DIRECTORY.");
+ return false;
+ }
+ }
+ else if(args[i] == "INPUT_FILE")
+ {
+ doing_command = false;
+ if(++i < args.size())
+ {
+ input_file = args[i];
+ }
+ else
+ {
+ this->SetError(" called with no value for INPUT_FILE.");
+ return false;
+ }
+ }
+ else if(args[i] == "OUTPUT_FILE")
+ {
+ doing_command = false;
+ if(++i < args.size())
+ {
+ output_file = args[i];
+ }
+ else
+ {
+ this->SetError(" called with no value for OUTPUT_FILE.");
+ return false;
+ }
+ }
+ else if(args[i] == "ERROR_FILE")
+ {
+ doing_command = false;
+ if(++i < args.size())
+ {
+ error_file = args[i];
+ }
+ else
+ {
+ this->SetError(" called with no value for ERROR_FILE.");
+ return false;
+ }
+ }
+ else if(args[i] == "TIMEOUT")
+ {
+ doing_command = false;
+ if(++i < args.size())
+ {
+ timeout_string = args[i];
+ }
+ else
+ {
+ this->SetError(" called with no value for TIMEOUT.");
+ return false;
+ }
+ }
+ else if(args[i] == "OUTPUT_QUIET")
+ {
+ doing_command = false;
+ output_quiet = true;
+ }
+ else if(args[i] == "ERROR_QUIET")
+ {
+ doing_command = false;
+ error_quiet = true;
+ }
+ else if(args[i] == "OUTPUT_STRIP_TRAILING_WHITESPACE")
+ {
+ doing_command = false;
+ output_strip_trailing_whitespace = true;
+ }
+ else if(args[i] == "ERROR_STRIP_TRAILING_WHITESPACE")
+ {
+ doing_command = false;
+ error_strip_trailing_whitespace = true;
+ }
+ else if(doing_command)
+ {
+ cmds[command_index].push_back(args[i].c_str());
+ }
+ else
+ {
+ cmOStringStream e;
+ e << " given unknown argument \"" << args[i] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ if ( !this->Makefile->CanIWriteThisFile(output_file.c_str()) )
+ {
+ std::string e = "attempted to output into a file: " + output_file
+ + " into a source directory.";
+ this->SetError(e);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+
+ // Check for commands given.
+ if(cmds.empty())
+ {
+ this->SetError(" called with no COMMAND argument.");
+ return false;
+ }
+ for(unsigned int i=0; i < cmds.size(); ++i)
+ {
+ if(cmds[i].empty())
+ {
+ this->SetError(" given COMMAND argument with no value.");
+ return false;
+ }
+ else
+ {
+ // Add the null terminating pointer to the command argument list.
+ cmds[i].push_back(0);
+ }
+ }
+
+ // Parse the timeout string.
+ double timeout = -1;
+ if(!timeout_string.empty())
+ {
+ if(sscanf(timeout_string.c_str(), "%lg", &timeout) != 1)
+ {
+ this->SetError(" called with TIMEOUT value that could not be parsed.");
+ return false;
+ }
+ }
+
+ // Create a process instance.
+ cmsysProcess* cp = cmsysProcess_New();
+
+ // Set the command sequence.
+ for(unsigned int i=0; i < cmds.size(); ++i)
+ {
+ cmsysProcess_AddCommand(cp, &*cmds[i].begin());
+ }
+
+ // Set the process working directory.
+ if(!working_directory.empty())
+ {
+ cmsysProcess_SetWorkingDirectory(cp, working_directory.c_str());
+ }
+
+ // Always hide the process window.
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+
+ // Check the output variables.
+ bool merge_output = (output_variable == error_variable);
+ if(!input_file.empty())
+ {
+ cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDIN, input_file.c_str());
+ }
+ if(!output_file.empty())
+ {
+ cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDOUT,
+ output_file.c_str());
+ }
+ if(!error_file.empty())
+ {
+ cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDERR,
+ error_file.c_str());
+ }
+
+ // Set the timeout if any.
+ if(timeout >= 0)
+ {
+ cmsysProcess_SetTimeout(cp, timeout);
+ }
+
+ // Start the process.
+ cmsysProcess_Execute(cp);
+
+ // Read the process output.
+ std::vector<char> tempOutput;
+ std::vector<char> tempError;
+ int length;
+ char* data;
+ int p;
+ while((p = cmsysProcess_WaitForData(cp, &data, &length, 0), p))
+ {
+ // Put the output in the right place.
+ if((p == cmsysProcess_Pipe_STDOUT && !output_quiet) ||
+ (p == cmsysProcess_Pipe_STDERR && !error_quiet && merge_output))
+ {
+ if(output_variable.empty())
+ {
+ cmSystemTools::Stdout(data, length);
+ }
+ else
+ {
+ cmExecuteProcessCommandAppend(tempOutput, data, length);
+ }
+ }
+ else if(p == cmsysProcess_Pipe_STDERR && !error_quiet)
+ {
+ if(error_variable.empty())
+ {
+ cmSystemTools::Stderr(data, length);
+ }
+ else
+ {
+ cmExecuteProcessCommandAppend(tempError, data, length);
+ }
+ }
+ }
+
+ // All output has been read. Wait for the process to exit.
+ cmsysProcess_WaitForExit(cp, 0);
+
+ // Fix the text in the output strings.
+ cmExecuteProcessCommandFixText(tempOutput,
+ output_strip_trailing_whitespace);
+ cmExecuteProcessCommandFixText(tempError,
+ error_strip_trailing_whitespace);
+
+ // Store the output obtained.
+ if(!output_variable.empty() && tempOutput.size())
+ {
+ this->Makefile->AddDefinition(output_variable,
+ &*tempOutput.begin());
+ }
+ if(!merge_output && !error_variable.empty() && tempError.size())
+ {
+ this->Makefile->AddDefinition(error_variable,
+ &*tempError.begin());
+ }
+
+ // Store the result of running the process.
+ if(!result_variable.empty())
+ {
+ switch(cmsysProcess_GetState(cp))
+ {
+ case cmsysProcess_State_Exited:
+ {
+ int v = cmsysProcess_GetExitValue(cp);
+ char buf[100];
+ sprintf(buf, "%d", v);
+ this->Makefile->AddDefinition(result_variable, buf);
+ }
+ break;
+ case cmsysProcess_State_Exception:
+ this->Makefile->AddDefinition(result_variable,
+ cmsysProcess_GetExceptionString(cp));
+ break;
+ case cmsysProcess_State_Error:
+ this->Makefile->AddDefinition(result_variable,
+ cmsysProcess_GetErrorString(cp));
+ break;
+ case cmsysProcess_State_Expired:
+ this->Makefile->AddDefinition(result_variable,
+ "Process terminated due to timeout");
+ break;
+ }
+ }
+
+ // Delete the process instance.
+ cmsysProcess_Delete(cp);
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmExecuteProcessCommandFixText(std::vector<char>& output,
+ bool strip_trailing_whitespace)
+{
+ // Remove \0 characters and the \r part of \r\n pairs.
+ unsigned int in_index = 0;
+ unsigned int out_index = 0;
+ while(in_index < output.size())
+ {
+ char c = output[in_index++];
+ if((c != '\r' || !(in_index < output.size() && output[in_index] == '\n'))
+ && c != '\0')
+ {
+ output[out_index++] = c;
+ }
+ }
+
+ // Remove trailing whitespace if requested.
+ if(strip_trailing_whitespace)
+ {
+ while(out_index > 0 &&
+ cmExecuteProcessCommandIsWhitespace(output[out_index-1]))
+ {
+ --out_index;
+ }
+ }
+
+ // Shrink the vector to the size needed.
+ output.resize(out_index);
+
+ // Put a terminator on the text string.
+ output.push_back('\0');
+}
+
+//----------------------------------------------------------------------------
+void cmExecuteProcessCommandAppend(std::vector<char>& output,
+ const char* data, int length)
+{
+#if defined(__APPLE__)
+ // HACK on Apple to work around bug with inserting at the
+ // end of an empty vector. This resulted in random failures
+ // that were hard to reproduce.
+ if(output.empty() && length > 0)
+ {
+ output.push_back(data[0]);
+ ++data;
+ --length;
+ }
+#endif
+ output.insert(output.end(), data, data+length);
+}
diff --git a/Source/cmExecuteProcessCommand.h b/Source/cmExecuteProcessCommand.h
new file mode 100644
index 0000000000..6906a08a87
--- /dev/null
+++ b/Source/cmExecuteProcessCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmExecuteProcessCommand_h
+#define cmExecuteProcessCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmExecuteProcessCommand
+ * \brief Command that adds a target to the build system.
+ *
+ * cmExecuteProcessCommand is a CMake language interface to the KWSys
+ * Process Execution implementation.
+ */
+class cmExecuteProcessCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmExecuteProcessCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const
+ {return "execute_process";}
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ cmTypeMacro(cmExecuteProcessCommand, cmCommand);
+};
+
+#endif
diff --git a/Source/cmExecutionStatus.h b/Source/cmExecutionStatus.h
new file mode 100644
index 0000000000..5c94a97585
--- /dev/null
+++ b/Source/cmExecutionStatus.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmExecutionStatus_h
+#define cmExecutionStatus_h
+
+#include "cmObject.h"
+
+/** \class cmExecutionStatus
+ * \brief Superclass for all command status classes
+ *
+ * when a command is involked it may set values on a command status instance
+ */
+class cmExecutionStatus : public cmObject
+{
+public:
+ cmTypeMacro(cmExecutionStatus, cmObject);
+
+ cmExecutionStatus() { this->Clear();}
+
+ virtual void SetReturnInvoked(bool val)
+ { this->ReturnInvoked = val; }
+ virtual bool GetReturnInvoked()
+ { return this->ReturnInvoked; }
+
+ virtual void SetBreakInvoked(bool val)
+ { this->BreakInvoked = val; }
+ virtual bool GetBreakInvoked()
+ { return this->BreakInvoked; }
+
+ virtual void Clear()
+ {
+ this->ReturnInvoked = false;
+ this->BreakInvoked = false;
+ this->NestedError = false;
+ }
+ virtual void SetNestedError(bool val) { this->NestedError = val; }
+ virtual bool GetNestedError() { return this->NestedError; }
+
+
+protected:
+ bool ReturnInvoked;
+ bool BreakInvoked;
+ bool NestedError;
+};
+
+#endif
diff --git a/Source/cmExpandedCommandArgument.cxx b/Source/cmExpandedCommandArgument.cxx
new file mode 100644
index 0000000000..4477cf5a09
--- /dev/null
+++ b/Source/cmExpandedCommandArgument.cxx
@@ -0,0 +1,51 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 "cmExpandedCommandArgument.h"
+
+cmExpandedCommandArgument::cmExpandedCommandArgument():
+ Quoted(false)
+{
+
+}
+
+cmExpandedCommandArgument::cmExpandedCommandArgument(
+ std::string const& value, bool quoted):
+ Value(value), Quoted(quoted)
+{
+
+}
+
+std::string const& cmExpandedCommandArgument::GetValue() const
+{
+ return this->Value;
+}
+
+bool cmExpandedCommandArgument::WasQuoted() const
+{
+ return this->Quoted;
+}
+
+bool cmExpandedCommandArgument::operator== (std::string const& value) const
+{
+ return this->Value == value;
+}
+
+bool cmExpandedCommandArgument::empty() const
+{
+ return this->Value.empty();
+}
+
+const char* cmExpandedCommandArgument::c_str() const
+{
+ return this->Value.c_str();
+}
diff --git a/Source/cmExpandedCommandArgument.h b/Source/cmExpandedCommandArgument.h
new file mode 100644
index 0000000000..f4e151704d
--- /dev/null
+++ b/Source/cmExpandedCommandArgument.h
@@ -0,0 +1,45 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmExpandedCommandArgument_h
+#define cmExpandedCommandArgument_h
+
+#include "cmStandardIncludes.h"
+
+/** \class cmExpandedCommandArgument
+ * \brief Represents an expanded command argument
+ *
+ * cmCommandArgument stores a string representing an expanded
+ * command argument and context information.
+ */
+
+class cmExpandedCommandArgument
+{
+public:
+ cmExpandedCommandArgument();
+ cmExpandedCommandArgument(std::string const& value, bool quoted);
+
+ std::string const& GetValue() const;
+
+ bool WasQuoted() const;
+
+ bool operator== (std::string const& value) const;
+
+ bool empty() const;
+
+ const char* c_str() const;
+
+private:
+ std::string Value;
+ bool Quoted;
+};
+
+#endif
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
new file mode 100644
index 0000000000..30a52d4764
--- /dev/null
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -0,0 +1,339 @@
+/*============================================================================
+ 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 "cmExportBuildFileGenerator.h"
+
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmExportSet.h"
+#include "cmTargetExport.h"
+
+//----------------------------------------------------------------------------
+cmExportBuildFileGenerator::cmExportBuildFileGenerator()
+ : Backtrace(NULL)
+{
+ this->Makefile = 0;
+ this->ExportSet = 0;
+}
+
+//----------------------------------------------------------------------------
+bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
+{
+ {
+ std::string expectedTargets;
+ std::string sep;
+ std::vector<std::string> targets;
+ this->GetTargets(targets);
+ for(std::vector<std::string>::const_iterator
+ tei = targets.begin();
+ tei != targets.end(); ++tei)
+ {
+ cmTarget *te = this->Makefile->FindTargetToUse(*tei);
+ expectedTargets += sep + this->Namespace + te->GetExportName();
+ sep = " ";
+ if(this->ExportedTargets.insert(te).second)
+ {
+ this->Exports.push_back(te);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given target \"" << te->GetName() << "\" more than once.";
+ this->Makefile->GetCMakeInstance()
+ ->IssueMessage(cmake::FATAL_ERROR, e.str(), this->Backtrace);
+ return false;
+ }
+ if (te->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ this->GenerateRequiredCMakeVersion(os, "3.0.0");
+ }
+ }
+
+ this->GenerateExpectedTargetsCode(os, expectedTargets);
+ }
+
+ std::vector<std::string> missingTargets;
+
+ // Create all the imported targets.
+ for(std::vector<cmTarget*>::const_iterator
+ tei = this->Exports.begin();
+ tei != this->Exports.end(); ++tei)
+ {
+ cmTarget* te = *tei;
+ this->GenerateImportTargetCode(os, te);
+
+ te->AppendBuildInterfaceIncludes();
+
+ ImportPropertyMap properties;
+
+ this->PopulateInterfaceProperty("INTERFACE_INCLUDE_DIRECTORIES", te,
+ cmGeneratorExpression::BuildInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS", te,
+ cmGeneratorExpression::BuildInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS", te,
+ cmGeneratorExpression::BuildInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS", te,
+ cmGeneratorExpression::BuildInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", te,
+ cmGeneratorExpression::BuildInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE",
+ te, properties);
+ const bool newCMP0022Behavior =
+ te->GetPolicyStatusCMP0022() != cmPolicies::WARN
+ && te->GetPolicyStatusCMP0022() != cmPolicies::OLD;
+ if (newCMP0022Behavior)
+ {
+ this->PopulateInterfaceLinkLibrariesProperty(te,
+ cmGeneratorExpression::BuildInterface,
+ properties, missingTargets);
+ }
+ this->PopulateCompatibleInterfaceProperties(te, properties);
+
+ this->GenerateInterfaceProperties(te, os, properties);
+ }
+
+ // Generate import file content for each configuration.
+ for(std::vector<std::string>::const_iterator
+ ci = this->Configurations.begin();
+ ci != this->Configurations.end(); ++ci)
+ {
+ this->GenerateImportConfig(os, *ci, missingTargets);
+ }
+
+ this->GenerateMissingTargetsCheckCode(os, missingTargets);
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportBuildFileGenerator
+::GenerateImportTargetsConfig(std::ostream& os,
+ const std::string& config,
+ std::string const& suffix,
+ std::vector<std::string> &missingTargets)
+{
+ for(std::vector<cmTarget*>::const_iterator
+ tei = this->Exports.begin();
+ tei != this->Exports.end(); ++tei)
+ {
+ // Collect import properties for this target.
+ cmTarget* target = *tei;
+ ImportPropertyMap properties;
+
+ if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ this->SetImportLocationProperty(config, suffix, target, properties);
+ }
+ if(!properties.empty())
+ {
+ // Get the rest of the target details.
+ if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ this->SetImportDetailProperties(config, suffix,
+ target, properties, missingTargets);
+ this->SetImportLinkInterface(config, suffix,
+ cmGeneratorExpression::BuildInterface,
+ target, properties, missingTargets);
+ }
+
+ // TOOD: PUBLIC_HEADER_LOCATION
+ // This should wait until the build feature propagation stuff
+ // is done. Then this can be a propagated include directory.
+ // this->GenerateImportProperty(config, te->HeaderGenerator,
+ // properties);
+
+ // Generate code in the export file.
+ this->GenerateImportPropertyCode(os, config, target, properties);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmExportBuildFileGenerator::SetExportSet(cmExportSet *exportSet)
+{
+ this->ExportSet = exportSet;
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportBuildFileGenerator
+::SetImportLocationProperty(const std::string& config,
+ std::string const& suffix,
+ cmTarget* target, ImportPropertyMap& properties)
+{
+ // Get the makefile in which to lookup target information.
+ cmMakefile* mf = target->GetMakefile();
+
+ // Add the main target file.
+ {
+ std::string prop = "IMPORTED_LOCATION";
+ prop += suffix;
+ std::string value;
+ if(target->IsAppBundleOnApple())
+ {
+ value = target->GetFullPath(config, false);
+ }
+ else
+ {
+ value = target->GetFullPath(config, false, true);
+ }
+ 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->IsExecutableWithExports()) &&
+ mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
+ {
+ std::string prop = "IMPORTED_IMPLIB";
+ prop += suffix;
+ std::string value = target->GetFullPath(config, true);
+ target->GetImplibGNUtoMS(value, value,
+ "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
+ properties[prop] = value;
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportBuildFileGenerator::HandleMissingTarget(
+ std::string& link_libs, std::vector<std::string>& missingTargets,
+ cmMakefile* mf, cmTarget* depender, cmTarget* 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);
+
+ int targetOccurrences = (int)namespaces.size();
+ if (targetOccurrences == 1)
+ {
+ std::string missingTarget = namespaces[0];
+
+ missingTarget += dependee->GetExportName();
+ link_libs += missingTarget;
+ missingTargets.push_back(missingTarget);
+ return;
+ }
+ else
+ {
+ // We are not appending, so all exported targets should be
+ // known here. This is probably user-error.
+ this->ComplainAboutMissingTarget(depender, dependee, targetOccurrences);
+ }
+ }
+ // Assume the target will be exported by another command.
+ // Append it with the export namespace.
+ link_libs += this->Namespace;
+ link_libs += dependee->GetExportName();
+}
+
+//----------------------------------------------------------------------------
+void cmExportBuildFileGenerator
+::GetTargets(std::vector<std::string> &targets) const
+{
+ if (this->ExportSet)
+ {
+ for(std::vector<cmTargetExport*>::const_iterator
+ tei = this->ExportSet->GetTargetExports()->begin();
+ tei != this->ExportSet->GetTargetExports()->end(); ++tei)
+ {
+ targets.push_back((*tei)->Target->GetName());
+ }
+ return;
+ }
+ targets = this->Targets;
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string>
+cmExportBuildFileGenerator
+::FindNamespaces(cmMakefile* mf, const std::string& name)
+{
+ std::vector<std::string> namespaces;
+ cmGlobalGenerator* gg = mf->GetLocalGenerator()->GetGlobalGenerator();
+
+ std::map<std::string, cmExportBuildFileGenerator*>& exportSets
+ = gg->GetBuildExportSets();
+
+ for(std::map<std::string, cmExportBuildFileGenerator*>::const_iterator
+ expIt = exportSets.begin(); expIt != exportSets.end(); ++expIt)
+ {
+ const cmExportBuildFileGenerator* exportSet = expIt->second;
+ std::vector<std::string> targets;
+ exportSet->GetTargets(targets);
+ if (std::find(targets.begin(), targets.end(), name) != targets.end())
+ {
+ namespaces.push_back(exportSet->GetNamespace());
+ }
+ }
+
+ return namespaces;
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportBuildFileGenerator
+::ComplainAboutMissingTarget(cmTarget* depender,
+ cmTarget* dependee,
+ int occurrences)
+{
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ return;
+ }
+
+ cmOStringStream e;
+ e << "export called with target \"" << depender->GetName()
+ << "\" which requires target \"" << dependee->GetName() << "\" ";
+ if (occurrences == 0)
+ {
+ e << "that is not in the export set.\n";
+ }
+ else
+ {
+ e << "that is not in this export set, but " << occurrences
+ << " times in others.\n";
+ }
+ 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);
+}
+
+std::string
+cmExportBuildFileGenerator::InstallNameDir(cmTarget* target,
+ const std::string& config)
+{
+ std::string install_name_dir;
+
+ cmMakefile* mf = target->GetMakefile();
+ if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ install_name_dir =
+ target->GetInstallNameDirForBuildTree(config);
+ }
+
+ return install_name_dir;
+}
diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h
new file mode 100644
index 0000000000..8b5694c395
--- /dev/null
+++ b/Source/cmExportBuildFileGenerator.h
@@ -0,0 +1,86 @@
+/*============================================================================
+ 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 cmExportBuildFileGenerator_h
+#define cmExportBuildFileGenerator_h
+
+#include "cmExportFileGenerator.h"
+#include "cmListFileCache.h"
+
+class cmExportSet;
+
+/** \class cmExportBuildFileGenerator
+ * \brief Generate a file exporting targets from a build tree.
+ *
+ * cmExportBuildFileGenerator generates a file exporting targets from
+ * a build tree. A single file exports information for all
+ * configurations built.
+ *
+ * This is used to implement the EXPORT() command.
+ */
+class cmExportBuildFileGenerator: public cmExportFileGenerator
+{
+public:
+ cmExportBuildFileGenerator();
+
+ /** Set the list of targets to export. */
+ void SetTargets(std::vector<std::string> const& targets)
+ { this->Targets = targets; }
+ void GetTargets(std::vector<std::string> &targets) const;
+ void AppendTargets(std::vector<std::string> const& targets)
+ { this->Targets.insert(this->Targets.end(),
+ targets.begin(), targets.end()); }
+ void SetExportSet(cmExportSet*);
+
+ /** 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();
+ }
+
+protected:
+ // Implement virtual methods from the superclass.
+ virtual bool GenerateMainFile(std::ostream& os);
+ virtual void GenerateImportTargetsConfig(std::ostream& os,
+ const std::string& config,
+ std::string const& suffix,
+ std::vector<std::string> &missingTargets);
+ virtual void HandleMissingTarget(std::string& link_libs,
+ std::vector<std::string>& missingTargets,
+ cmMakefile* mf,
+ cmTarget* depender,
+ cmTarget* dependee);
+
+ void ComplainAboutMissingTarget(cmTarget* depender,
+ cmTarget* dependee,
+ int occurrences);
+
+ /** Fill in properties indicating built file locations. */
+ void SetImportLocationProperty(const std::string& config,
+ std::string const& suffix,
+ cmTarget* target,
+ ImportPropertyMap& properties);
+
+ std::string InstallNameDir(cmTarget* target, const std::string& config);
+
+ std::vector<std::string>
+ FindNamespaces(cmMakefile* mf, const std::string& name);
+
+ std::vector<std::string> Targets;
+ cmExportSet *ExportSet;
+ std::vector<cmTarget*> Exports;
+ cmMakefile* Makefile;
+ cmListFileBacktrace Backtrace;
+};
+
+#endif
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
new file mode 100644
index 0000000000..db21c49fb6
--- /dev/null
+++ b/Source/cmExportCommand.cxx
@@ -0,0 +1,411 @@
+/*============================================================================
+ 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 "cmExportCommand.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmake.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Encoding.hxx>
+
+#include "cmExportBuildFileGenerator.h"
+
+#if defined(__HAIKU__)
+#include <FindDirectory.h>
+#include <StorageDefs.h>
+#endif
+
+cmExportCommand::cmExportCommand()
+:cmCommand()
+,ArgumentGroup()
+,Targets(&Helper, "TARGETS")
+,Append(&Helper, "APPEND", &ArgumentGroup)
+,ExportSetName(&Helper, "EXPORT", &ArgumentGroup)
+,Namespace(&Helper, "NAMESPACE", &ArgumentGroup)
+,Filename(&Helper, "FILE", &ArgumentGroup)
+,ExportOld(&Helper, "EXPORT_LINK_INTERFACE_LIBRARIES", &ArgumentGroup)
+{
+ this->ExportSet = 0;
+}
+
+
+// cmExportCommand
+bool cmExportCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with too few arguments");
+ return false;
+ }
+
+ if(args[0] == "PACKAGE")
+ {
+ return this->HandlePackage(args);
+ }
+ else if (args[0] == "EXPORT")
+ {
+ this->ExportSetName.Follows(0);
+ this->ArgumentGroup.Follows(&this->ExportSetName);
+ }
+ else
+ {
+ this->Targets.Follows(0);
+ this->ArgumentGroup.Follows(&this->Targets);
+ }
+
+ std::vector<std::string> unknownArgs;
+ this->Helper.Parse(&args, &unknownArgs);
+
+ if (!unknownArgs.empty())
+ {
+ this->SetError("Unknown arguments.");
+ return false;
+ }
+
+ std::string fname;
+ if(!this->Filename.WasFound())
+ {
+ if (args[0] != "EXPORT")
+ {
+ this->SetError("FILE <filename> option missing.");
+ return false;
+ }
+ fname = this->ExportSetName.GetString() + ".cmake";
+ }
+ else
+ {
+ // Make sure the file has a .cmake extension.
+ if(cmSystemTools::GetFilenameLastExtension(this->Filename.GetCString())
+ != ".cmake")
+ {
+ cmOStringStream e;
+ e << "FILE option given filename \"" << this->Filename.GetString()
+ << "\" which does not have an extension of \".cmake\".\n";
+ this->SetError(e.str());
+ return false;
+ }
+ fname = this->Filename.GetString();
+ }
+
+ // Get the file to write.
+ if(cmSystemTools::FileIsFullPath(fname.c_str()))
+ {
+ if(!this->Makefile->CanIWriteThisFile(fname.c_str()))
+ {
+ cmOStringStream e;
+ e << "FILE option given filename \"" << fname
+ << "\" which is in the source tree.\n";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else
+ {
+ // Interpret relative paths with respect to the current build dir.
+ std::string dir = this->Makefile->GetCurrentOutputDirectory();
+ fname = dir + "/" + fname;
+ }
+
+ std::vector<std::string> targets;
+
+ cmGlobalGenerator *gg = this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator();
+
+ if(args[0] == "EXPORT")
+ {
+ if (this->Append.IsEnabled())
+ {
+ cmOStringStream e;
+ e << "EXPORT signature does not recognise the APPEND option.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ if (this->ExportOld.IsEnabled())
+ {
+ cmOStringStream e;
+ e << "EXPORT signature does not recognise the "
+ "EXPORT_LINK_INTERFACE_LIBRARIES option.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ cmExportSetMap &setMap = gg->GetExportSets();
+ std::string setName = this->ExportSetName.GetString();
+ if (setMap.find(setName) == setMap.end())
+ {
+ cmOStringStream e;
+ e << "Export set \"" << setName << "\" not found.";
+ this->SetError(e.str());
+ return false;
+ }
+ this->ExportSet = setMap[setName];
+ }
+ else if (this->Targets.WasFound())
+ {
+ for(std::vector<std::string>::const_iterator
+ currentTarget = this->Targets.GetVector().begin();
+ currentTarget != this->Targets.GetVector().end();
+ ++currentTarget)
+ {
+ if (this->Makefile->IsAlias(*currentTarget))
+ {
+ cmOStringStream e;
+ e << "given ALIAS target \"" << *currentTarget
+ << "\" which may not be exported.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ if(cmTarget* target = gg->FindTarget(*currentTarget))
+ {
+ if(target->GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "given OBJECT library \"" << *currentTarget
+ << "\" which may not be exported.";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given target \"" << *currentTarget
+ << "\" which is not built by this project.";
+ this->SetError(e.str());
+ return false;
+ }
+ targets.push_back(*currentTarget);
+ }
+ if (this->Append.IsEnabled())
+ {
+ if (cmExportBuildFileGenerator *ebfg = gg->GetExportedTargetsFile(fname))
+ {
+ ebfg->AppendTargets(targets);
+ return true;
+ }
+ }
+ }
+ else
+ {
+ this->SetError("EXPORT or TARGETS specifier missing.");
+ return false;
+ }
+
+ // Setup export file generation.
+ cmExportBuildFileGenerator *ebfg = new cmExportBuildFileGenerator;
+ ebfg->SetExportFile(fname.c_str());
+ ebfg->SetNamespace(this->Namespace.GetCString());
+ ebfg->SetAppendMode(this->Append.IsEnabled());
+ if (this->ExportSet)
+ {
+ ebfg->SetExportSet(this->ExportSet);
+ }
+ else
+ {
+ ebfg->SetTargets(targets);
+ }
+ ebfg->SetMakefile(this->Makefile);
+ ebfg->SetExportOld(this->ExportOld.IsEnabled());
+
+ // Compute the set of configurations exported.
+ std::vector<std::string> configurationTypes;
+ this->Makefile->GetConfigurations(configurationTypes);
+ if(configurationTypes.empty())
+ {
+ configurationTypes.push_back("");
+ }
+ for(std::vector<std::string>::const_iterator
+ ci = configurationTypes.begin();
+ ci != configurationTypes.end(); ++ci)
+ {
+ ebfg->AddConfiguration(*ci);
+ }
+ if (this->ExportSet)
+ {
+ gg->AddBuildExportExportSet(ebfg);
+ }
+ else
+ {
+ gg->AddBuildExportSet(ebfg);
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmExportCommand::HandlePackage(std::vector<std::string> const& args)
+{
+ // Parse PACKAGE mode arguments.
+ enum Doing { DoingNone, DoingPackage };
+ Doing doing = DoingPackage;
+ std::string package;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(doing == DoingPackage)
+ {
+ package = args[i];
+ doing = DoingNone;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "PACKAGE given unknown argument: " << args[i];
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // Verify the package name.
+ if(package.empty())
+ {
+ this->SetError("PACKAGE must be given a package name.");
+ return false;
+ }
+ const char* packageExpr = "^[A-Za-z0-9_.-]+$";
+ cmsys::RegularExpression packageRegex(packageExpr);
+ if(!packageRegex.find(package.c_str()))
+ {
+ cmOStringStream e;
+ e << "PACKAGE given invalid package name \"" << package << "\". "
+ << "Package names must match \"" << packageExpr << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // If the CMAKE_EXPORT_NO_PACKAGE_REGISTRY variable is set the command
+ // export(PACKAGE) does nothing.
+ if(this->Makefile->IsOn("CMAKE_EXPORT_NO_PACKAGE_REGISTRY"))
+ {
+ return true;
+ }
+
+ // We store the current build directory in the registry as a value
+ // named by a hash of its own content. This is deterministic and is
+ // unique with high probability.
+ const char* outDir = this->Makefile->GetCurrentOutputDirectory();
+ std::string hash = cmSystemTools::ComputeStringMD5(outDir);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ this->StorePackageRegistryWin(package, outDir, hash.c_str());
+#else
+ this->StorePackageRegistryDir(package, outDir, hash.c_str());
+#endif
+
+ return true;
+}
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# include <windows.h>
+# undef GetCurrentDirectory
+//----------------------------------------------------------------------------
+void cmExportCommand::ReportRegistryError(std::string const& msg,
+ std::string const& key,
+ long err)
+{
+ cmOStringStream e;
+ e << msg << "\n"
+ << " HKEY_CURRENT_USER\\" << key << "\n";
+ wchar_t winmsg[1024];
+ if(FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS, 0, err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ winmsg, 1024, 0) > 0)
+ {
+ e << "Windows reported:\n"
+ << " " << cmsys::Encoding::ToNarrow(winmsg);
+ }
+ this->Makefile->IssueMessage(cmake::WARNING, e.str());
+}
+
+//----------------------------------------------------------------------------
+void cmExportCommand::StorePackageRegistryWin(std::string const& package,
+ const char* content,
+ const char* hash)
+{
+ std::string key = "Software\\Kitware\\CMake\\Packages\\";
+ key += package;
+ HKEY hKey;
+ LONG err = RegCreateKeyExW(HKEY_CURRENT_USER,
+ cmsys::Encoding::ToWide(key).c_str(),
+ 0, 0, REG_OPTION_NON_VOLATILE,
+ KEY_SET_VALUE, 0, &hKey, 0);
+ if(err != ERROR_SUCCESS)
+ {
+ this->ReportRegistryError(
+ "Cannot create/open registry key", key, err);
+ return;
+ }
+
+ std::wstring wcontent = cmsys::Encoding::ToWide(content);
+ err = RegSetValueExW(hKey, cmsys::Encoding::ToWide(hash).c_str(),
+ 0, REG_SZ, (BYTE const*)wcontent.c_str(),
+ static_cast<DWORD>(wcontent.size()+1)*sizeof(wchar_t));
+ RegCloseKey(hKey);
+ if(err != ERROR_SUCCESS)
+ {
+ cmOStringStream msg;
+ msg << "Cannot set registry value \"" << hash << "\" under key";
+ this->ReportRegistryError(msg.str(), key, err);
+ return;
+ }
+}
+#else
+//----------------------------------------------------------------------------
+void cmExportCommand::StorePackageRegistryDir(std::string const& package,
+ const char* content,
+ const char* hash)
+{
+#if defined(__HAIKU__)
+ char dir[B_PATH_NAME_LENGTH];
+ if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) !=
+ B_OK)
+ {
+ return;
+ }
+ std::string fname = dir;
+ fname += "/cmake/packages/";
+ fname += package;
+#else
+ const char* home = cmSystemTools::GetEnv("HOME");
+ if(!home)
+ {
+ return;
+ }
+ std::string fname = home;
+ cmSystemTools::ConvertToUnixSlashes(fname);
+ fname += "/.cmake/packages/";
+ fname += package;
+#endif
+ cmSystemTools::MakeDirectory(fname.c_str());
+ fname += "/";
+ fname += hash;
+ if(!cmSystemTools::FileExists(fname.c_str()))
+ {
+ cmGeneratedFileStream entry(fname.c_str(), true);
+ if(entry)
+ {
+ entry << content << "\n";
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "Cannot create package registry file:\n"
+ << " " << fname << "\n"
+ << cmSystemTools::GetLastSystemError() << "\n";
+ this->Makefile->IssueMessage(cmake::WARNING, e.str());
+ }
+ }
+}
+#endif
diff --git a/Source/cmExportCommand.h b/Source/cmExportCommand.h
new file mode 100644
index 0000000000..f9506bbdde
--- /dev/null
+++ b/Source/cmExportCommand.h
@@ -0,0 +1,76 @@
+/*============================================================================
+ 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 cmExportCommand_h
+#define cmExportCommand_h
+
+#include "cmCommand.h"
+
+class cmExportBuildFileGenerator;
+class cmExportSet;
+
+/** \class cmExportLibraryDependenciesCommand
+ * \brief Add a test to the lists of tests to run.
+ *
+ * cmExportLibraryDependenciesCommand adds a test to the list of tests to run
+ *
+ */
+class cmExportCommand : public cmCommand
+{
+public:
+ cmExportCommand();
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmExportCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "export";}
+
+ cmTypeMacro(cmExportCommand, cmCommand);
+
+private:
+ cmCommandArgumentGroup ArgumentGroup;
+ cmCAStringVector Targets;
+ cmCAEnabler Append;
+ cmCAString ExportSetName;
+ cmCAString Namespace;
+ cmCAString Filename;
+ cmCAEnabler ExportOld;
+
+ cmExportSet *ExportSet;
+
+ friend class cmExportBuildFileGenerator;
+ std::string ErrorMessage;
+
+ bool HandlePackage(std::vector<std::string> const& args);
+ void StorePackageRegistryWin(std::string const& package,
+ const char* content, const char* hash);
+ void StorePackageRegistryDir(std::string const& package,
+ const char* content, const char* hash);
+ void ReportRegistryError(std::string const& msg, std::string const& key,
+ long err);
+};
+
+
+#endif
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
new file mode 100644
index 0000000000..1f39d7af97
--- /dev/null
+++ b/Source/cmExportFileGenerator.cxx
@@ -0,0 +1,1186 @@
+/*============================================================================
+ 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 "cmExportFileGenerator.h"
+
+#include "cmExportSet.h"
+#include "cmGeneratedFileStream.h"
+#include "cmGlobalGenerator.h"
+#include "cmInstallExportGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include "cmTarget.h"
+#include "cmTargetExport.h"
+#include "cmVersion.h"
+#include "cmComputeLinkInformation.h"
+
+#include <cmsys/auto_ptr.hxx>
+#include <cmsys/FStream.hxx>
+#include <assert.h>
+
+//----------------------------------------------------------------------------
+cmExportFileGenerator::cmExportFileGenerator()
+{
+ this->AppendMode = false;
+ this->ExportOld = false;
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::AddConfiguration(const std::string& config)
+{
+ this->Configurations.push_back(config);
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::SetExportFile(const char* mainFile)
+{
+ this->MainImportFile = mainFile;
+ this->FileDir =
+ cmSystemTools::GetFilenamePath(this->MainImportFile);
+ this->FileBase =
+ cmSystemTools::GetFilenameWithoutLastExtension(this->MainImportFile);
+ this->FileExt =
+ cmSystemTools::GetFilenameLastExtension(this->MainImportFile);
+}
+
+//----------------------------------------------------------------------------
+const char* cmExportFileGenerator::GetMainExportFileName() const
+{
+ return this->MainImportFile.c_str();
+}
+
+//----------------------------------------------------------------------------
+bool cmExportFileGenerator::GenerateImportFile()
+{
+ // Open the output file to generate it.
+ cmsys::auto_ptr<cmsys::ofstream> foutPtr;
+ if(this->AppendMode)
+ {
+ // Open for append.
+ cmsys::auto_ptr<cmsys::ofstream>
+ ap(new cmsys::ofstream(this->MainImportFile.c_str(), std::ios::app));
+ foutPtr = ap;
+ }
+ else
+ {
+ // Generate atomically and with copy-if-different.
+ cmsys::auto_ptr<cmGeneratedFileStream>
+ ap(new cmGeneratedFileStream(this->MainImportFile.c_str(), true));
+ ap->SetCopyIfDifferent(true);
+ foutPtr = ap;
+ }
+ if(!foutPtr.get() || !*foutPtr)
+ {
+ std::string se = cmSystemTools::GetLastSystemError();
+ cmOStringStream e;
+ e << "cannot write to file \"" << this->MainImportFile
+ << "\": " << se;
+ cmSystemTools::Error(e.str().c_str());
+ return false;
+ }
+ std::ostream& os = *foutPtr;
+
+ // Protect that file against use with older CMake versions.
+ os << "# Generated by CMake " << cmVersion::GetCMakeVersion() << "\n\n";
+ os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.5)\n"
+ << " message(FATAL_ERROR \"CMake >= 2.6.0 required\")\n"
+ << "endif()\n";
+
+ // Isolate the file policy level.
+ // We use 2.6 here instead of the current version because newer
+ // versions of CMake should be able to export files imported by 2.6
+ // until the import format changes.
+ os << "cmake_policy(PUSH)\n"
+ << "cmake_policy(VERSION 2.6)\n";
+
+ // Start with the import file header.
+ this->GenerateImportHeaderCode(os);
+
+ // Create all the imported targets.
+ bool result = this->GenerateMainFile(os);
+
+ // End with the import file footer.
+ this->GenerateImportFooterCode(os);
+ os << "cmake_policy(POP)\n";
+
+ return result;
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::GenerateImportConfig(std::ostream& os,
+ const std::string& config,
+ std::vector<std::string> &missingTargets)
+{
+ // Construct the property configuration suffix.
+ std::string suffix = "_";
+ if(!config.empty())
+ {
+ suffix += cmSystemTools::UpperCase(config);
+ }
+ else
+ {
+ suffix += "NOCONFIG";
+ }
+
+ // Generate the per-config target information.
+ this->GenerateImportTargetsConfig(os, config, suffix, missingTargets);
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::PopulateInterfaceProperty(
+ const std::string& propName,
+ cmTarget *target,
+ ImportPropertyMap &properties)
+{
+ const char *input = target->GetProperty(propName);
+ if (input)
+ {
+ properties[propName] = input;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::PopulateInterfaceProperty(
+ const std::string& propName,
+ const std::string& outputName,
+ cmTarget *target,
+ cmGeneratorExpression::PreprocessContext preprocessRule,
+ ImportPropertyMap &properties,
+ std::vector<std::string> &missingTargets)
+{
+ const char *input = target->GetProperty(propName);
+ if (input)
+ {
+ if (!*input)
+ {
+ // Set to empty
+ properties[outputName] = "";
+ return;
+ }
+
+ std::string prepro = cmGeneratorExpression::Preprocess(input,
+ preprocessRule);
+ if (!prepro.empty())
+ {
+ this->ResolveTargetsInGeneratorExpressions(prepro, target,
+ missingTargets);
+ properties[outputName] = prepro;
+ }
+ }
+}
+
+void cmExportFileGenerator::GenerateRequiredCMakeVersion(std::ostream& os,
+ const char *versionString)
+{
+ os << "if(CMAKE_VERSION VERSION_LESS " << versionString << ")\n"
+ " message(FATAL_ERROR \"This file relies on consumers using "
+ "CMake " << versionString << " or greater.\")\n"
+ "endif()\n\n";
+}
+
+//----------------------------------------------------------------------------
+bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
+ cmTarget *target,
+ cmGeneratorExpression::PreprocessContext preprocessRule,
+ ImportPropertyMap &properties,
+ std::vector<std::string> &missingTargets)
+{
+ if(!target->IsLinkable())
+ {
+ return false;
+ }
+ const char *input = target->GetProperty("INTERFACE_LINK_LIBRARIES");
+ if (input)
+ {
+ std::string prepro = cmGeneratorExpression::Preprocess(input,
+ preprocessRule);
+ if (!prepro.empty())
+ {
+ this->ResolveTargetsInGeneratorExpressions(prepro, target,
+ missingTargets,
+ ReplaceFreeTargets);
+ properties["INTERFACE_LINK_LIBRARIES"] = prepro;
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+static bool isSubDirectory(const char* a, const char* b)
+{
+ return (cmSystemTools::ComparePath(a, b) ||
+ cmSystemTools::IsSubDirectory(a, b));
+}
+
+//----------------------------------------------------------------------------
+static bool checkInterfaceDirs(const std::string &prepro,
+ cmTarget *target)
+{
+ const char* installDir =
+ target->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
+ const char* topSourceDir = target->GetMakefile()->GetHomeDirectory();
+ const char* topBinaryDir = target->GetMakefile()->GetHomeOutputDirectory();
+
+ std::vector<std::string> parts;
+ cmGeneratorExpression::Split(prepro, parts);
+
+ const bool inSourceBuild = strcmp(topSourceDir, topBinaryDir) == 0;
+
+ bool hadFatalError = false;
+
+ for(std::vector<std::string>::iterator li = parts.begin();
+ li != parts.end(); ++li)
+ {
+ size_t genexPos = cmGeneratorExpression::Find(*li);
+ if (genexPos == 0)
+ {
+ continue;
+ }
+ cmake::MessageType messageType = cmake::FATAL_ERROR;
+ cmOStringStream e;
+ if (genexPos != std::string::npos)
+ {
+ switch (target->GetPolicyStatusCMP0041())
+ {
+ case cmPolicies::WARN:
+ messageType = cmake::WARNING;
+ e << target->GetMakefile()->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0041) << "\n";
+ break;
+ case cmPolicies::OLD:
+ continue;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ hadFatalError = true;
+ break; // Issue fatal message.
+ }
+ }
+ if (cmHasLiteralPrefix(li->c_str(), "${_IMPORT_PREFIX}"))
+ {
+ continue;
+ }
+ if (!cmSystemTools::FileIsFullPath(li->c_str()))
+ {
+ e << "Target \"" << target->GetName() << "\" "
+ "INTERFACE_INCLUDE_DIRECTORIES property contains relative path:\n"
+ " \"" << *li << "\"";
+ target->GetMakefile()->IssueMessage(messageType, e.str());
+ }
+ bool inBinary = isSubDirectory(li->c_str(), topBinaryDir);
+ bool inSource = isSubDirectory(li->c_str(), topSourceDir);
+ if (isSubDirectory(li->c_str(), installDir))
+ {
+ // The include directory is inside the install tree. If the
+ // install tree is not inside the source tree or build tree then
+ // fall through to the checks below that the include directory is not
+ // also inside the source tree or build tree.
+ bool shouldContinue =
+ (!inBinary || isSubDirectory(installDir, topBinaryDir)) &&
+ (!inSource || isSubDirectory(installDir, topSourceDir));
+
+ if (!shouldContinue)
+ {
+ switch(target->GetPolicyStatusCMP0052())
+ {
+ case cmPolicies::WARN:
+ {
+ cmOStringStream s;
+ s << target->GetMakefile()->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0052) << "\n";
+ s << "Directory:\n \"" << *li << "\"\nin "
+ "INTERFACE_INCLUDE_DIRECTORIES of target \""
+ << target->GetName() << "\" is a subdirectory of the install "
+ "directory:\n \"" << installDir << "\"\nhowever it is also "
+ "a subdirectory of the " << (inBinary ? "build" : "source")
+ << " tree:\n \"" << (inBinary ? topBinaryDir : topSourceDir)
+ << "\"" << std::endl;
+ target->GetMakefile()->IssueMessage(cmake::AUTHOR_WARNING,
+ s.str());
+ }
+ case cmPolicies::OLD:
+ shouldContinue = true;
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW:
+ break;
+ }
+ }
+ if (shouldContinue)
+ {
+ continue;
+ }
+ }
+ if (inBinary)
+ {
+ e << "Target \"" << target->GetName() << "\" "
+ "INTERFACE_INCLUDE_DIRECTORIES property contains path:\n"
+ " \"" << *li << "\"\nwhich is prefixed in the build directory.";
+ target->GetMakefile()->IssueMessage(messageType, e.str());
+ }
+ if (!inSourceBuild)
+ {
+ if (inSource)
+ {
+ e << "Target \"" << target->GetName() << "\" "
+ "INTERFACE_INCLUDE_DIRECTORIES property contains path:\n"
+ " \"" << *li << "\"\nwhich is prefixed in the source directory.";
+ target->GetMakefile()->IssueMessage(messageType, e.str());
+ }
+ }
+ }
+ return !hadFatalError;
+}
+
+//----------------------------------------------------------------------------
+static void prefixItems(std::string &exportDirs)
+{
+ std::vector<std::string> entries;
+ cmGeneratorExpression::Split(exportDirs, entries);
+ exportDirs = "";
+ const char *sep = "";
+ for(std::vector<std::string>::const_iterator ei = entries.begin();
+ ei != entries.end(); ++ei)
+ {
+ exportDirs += sep;
+ sep = ";";
+ if (!cmSystemTools::FileIsFullPath(ei->c_str())
+ && ei->find("${_IMPORT_PREFIX}") == std::string::npos)
+ {
+ exportDirs += "${_IMPORT_PREFIX}/";
+ }
+ exportDirs += *ei;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
+ cmTargetExport *tei,
+ cmGeneratorExpression::PreprocessContext preprocessRule,
+ ImportPropertyMap &properties,
+ std::vector<std::string> &missingTargets)
+{
+ cmTarget *target = tei->Target;
+ assert(preprocessRule == cmGeneratorExpression::InstallInterface);
+
+ const char *propName = "INTERFACE_INCLUDE_DIRECTORIES";
+ const char *input = target->GetProperty(propName);
+
+ cmGeneratorExpression ge;
+
+ std::string dirs = cmGeneratorExpression::Preprocess(
+ tei->InterfaceIncludeDirectories,
+ preprocessRule,
+ true);
+ this->ReplaceInstallPrefix(dirs);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
+ std::string exportDirs = cge->Evaluate(target->GetMakefile(), "",
+ false, target);
+
+ if (cge->GetHadContextSensitiveCondition())
+ {
+ cmMakefile* mf = target->GetMakefile();
+ cmOStringStream 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());
+ return;
+ }
+
+ if (!input && exportDirs.empty())
+ {
+ return;
+ }
+ if ((input && !*input) && exportDirs.empty())
+ {
+ // Set to empty
+ properties[propName] = "";
+ return;
+ }
+
+ prefixItems(exportDirs);
+
+ std::string includes = (input?input:"");
+ const char* sep = input ? ";" : "";
+ includes += sep + exportDirs;
+ std::string prepro = cmGeneratorExpression::Preprocess(includes,
+ preprocessRule,
+ true);
+ if (!prepro.empty())
+ {
+ this->ResolveTargetsInGeneratorExpressions(prepro, target,
+ missingTargets);
+
+ if (!checkInterfaceDirs(prepro, target))
+ {
+ return;
+ }
+ properties[propName] = prepro;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::PopulateInterfaceProperty(
+ const std::string& propName,
+ cmTarget *target,
+ cmGeneratorExpression::PreprocessContext preprocessRule,
+ ImportPropertyMap &properties,
+ std::vector<std::string> &missingTargets)
+{
+ this->PopulateInterfaceProperty(propName, propName, target, preprocessRule,
+ properties, missingTargets);
+}
+
+
+//----------------------------------------------------------------------------
+void getPropertyContents(cmTarget const* tgt, const std::string& prop,
+ std::set<std::string> &ifaceProperties)
+{
+ const char *p = tgt->GetProperty(prop);
+ if (!p)
+ {
+ return;
+ }
+ std::vector<std::string> content;
+ cmSystemTools::ExpandListArgument(p, content);
+ for (std::vector<std::string>::const_iterator ci = content.begin();
+ ci != content.end(); ++ci)
+ {
+ ifaceProperties.insert(*ci);
+ }
+}
+
+//----------------------------------------------------------------------------
+void getCompatibleInterfaceProperties(cmTarget *target,
+ std::set<std::string> &ifaceProperties,
+ const std::string& config)
+{
+ cmComputeLinkInformation *info = target->GetLinkInformation(config);
+
+ if (!info)
+ {
+ cmMakefile* mf = target->GetMakefile();
+ cmOStringStream e;
+ e << "Exporting the target \"" << target->GetName() << "\" is not "
+ "allowed since its linker language cannot be determined";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+
+ const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
+
+ for(cmComputeLinkInformation::ItemVector::const_iterator li =
+ deps.begin();
+ li != deps.end(); ++li)
+ {
+ if (!li->Target)
+ {
+ continue;
+ }
+ getPropertyContents(li->Target,
+ "COMPATIBLE_INTERFACE_BOOL",
+ ifaceProperties);
+ getPropertyContents(li->Target,
+ "COMPATIBLE_INTERFACE_STRING",
+ ifaceProperties);
+ getPropertyContents(li->Target,
+ "COMPATIBLE_INTERFACE_NUMBER_MIN",
+ ifaceProperties);
+ getPropertyContents(li->Target,
+ "COMPATIBLE_INTERFACE_NUMBER_MAX",
+ ifaceProperties);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
+ cmTarget *target,
+ ImportPropertyMap &properties)
+{
+ this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_BOOL",
+ target, properties);
+ this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_STRING",
+ target, properties);
+ this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MIN",
+ target, properties);
+ this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MAX",
+ target, properties);
+
+ std::set<std::string> ifaceProperties;
+
+ getPropertyContents(target, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties);
+ getPropertyContents(target, "COMPATIBLE_INTERFACE_STRING", ifaceProperties);
+ getPropertyContents(target, "COMPATIBLE_INTERFACE_NUMBER_MIN",
+ ifaceProperties);
+ getPropertyContents(target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
+ ifaceProperties);
+
+ if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ getCompatibleInterfaceProperties(target, ifaceProperties, "");
+
+ std::vector<std::string> configNames;
+ target->GetMakefile()->GetConfigurations(configNames);
+
+ for (std::vector<std::string>::const_iterator ci = configNames.begin();
+ ci != configNames.end(); ++ci)
+ {
+ getCompatibleInterfaceProperties(target, ifaceProperties, *ci);
+ }
+ }
+
+ for (std::set<std::string>::const_iterator it = ifaceProperties.begin();
+ it != ifaceProperties.end(); ++it)
+ {
+ this->PopulateInterfaceProperty("INTERFACE_" + *it,
+ target, properties);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget const* target,
+ std::ostream& os,
+ const ImportPropertyMap &properties)
+{
+ if (!properties.empty())
+ {
+ std::string targetName = this->Namespace;
+ targetName += target->GetExportName();
+ os << "set_target_properties(" << targetName << " PROPERTIES\n";
+ for(ImportPropertyMap::const_iterator pi = properties.begin();
+ pi != properties.end(); ++pi)
+ {
+ os << " " << pi->first << " \"" << pi->second << "\"\n";
+ }
+ os << ")\n\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+bool
+cmExportFileGenerator::AddTargetNamespace(std::string &input,
+ cmTarget* target,
+ std::vector<std::string> &missingTargets)
+{
+ cmMakefile *mf = target->GetMakefile();
+
+ cmTarget *tgt = mf->FindTargetToUse(input);
+ if (!tgt)
+ {
+ return false;
+ }
+
+ if(tgt->IsImported())
+ {
+ return true;
+ }
+ if(this->ExportedTargets.find(tgt) != this->ExportedTargets.end())
+ {
+ input = this->Namespace + tgt->GetExportName();
+ }
+ else
+ {
+ std::string namespacedTarget;
+ this->HandleMissingTarget(namespacedTarget, missingTargets,
+ mf, target, tgt);
+ if (!namespacedTarget.empty())
+ {
+ input = namespacedTarget;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
+ std::string &input,
+ cmTarget* target,
+ std::vector<std::string> &missingTargets,
+ FreeTargetsReplace replace)
+{
+ if (replace == NoReplaceFreeTargets)
+ {
+ this->ResolveTargetsInGeneratorExpression(input, target, missingTargets);
+ return;
+ }
+ std::vector<std::string> parts;
+ cmGeneratorExpression::Split(input, parts);
+
+ std::string sep;
+ input = "";
+ for(std::vector<std::string>::iterator li = parts.begin();
+ li != parts.end(); ++li)
+ {
+ if (cmGeneratorExpression::Find(*li) == std::string::npos)
+ {
+ this->AddTargetNamespace(*li, target, missingTargets);
+ }
+ else
+ {
+ this->ResolveTargetsInGeneratorExpression(
+ *li,
+ target,
+ missingTargets);
+ }
+ input += sep + *li;
+ sep = ";";
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
+ std::string &input,
+ cmTarget* 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 +
+ sizeof("$<TARGET_PROPERTY:") - 1;
+ std::string::size_type closePos = input.find(">", nameStartPos);
+ std::string::size_type commaPos = input.find(",", nameStartPos);
+ std::string::size_type nextOpenPos = input.find("$<", nameStartPos);
+ if (commaPos == input.npos // Implied 'this' target
+ || closePos == input.npos // Imcomplete expression.
+ || closePos < commaPos // Implied 'this' target
+ || nextOpenPos < commaPos) // Non-literal
+ {
+ lastPos = nameStartPos;
+ continue;
+ }
+
+ std::string targetName = input.substr(nameStartPos,
+ commaPos - nameStartPos);
+
+ if (this->AddTargetNamespace(targetName, target, missingTargets))
+ {
+ input.replace(nameStartPos, commaPos - nameStartPos, targetName);
+ }
+ lastPos = nameStartPos + targetName.size() + 1;
+ }
+
+ std::string errorString;
+ pos = 0;
+ lastPos = pos;
+ while((pos = input.find("$<TARGET_NAME:", lastPos)) != input.npos)
+ {
+ std::string::size_type nameStartPos = pos + sizeof("$<TARGET_NAME:") - 1;
+ std::string::size_type endPos = input.find(">", nameStartPos);
+ if (endPos == input.npos)
+ {
+ errorString = "$<TARGET_NAME:...> expression incomplete";
+ break;
+ }
+ std::string targetName = input.substr(nameStartPos,
+ endPos - nameStartPos);
+ if(targetName.find("$<") != input.npos)
+ {
+ errorString = "$<TARGET_NAME:...> requires its parameter to be a "
+ "literal.";
+ break;
+ }
+ if (!this->AddTargetNamespace(targetName, target, missingTargets))
+ {
+ errorString = "$<TARGET_NAME:...> requires its parameter to be a "
+ "reachable target.";
+ break;
+ }
+ input.replace(pos, endPos - pos + 1, targetName);
+ lastPos = endPos;
+ }
+
+ this->ReplaceInstallPrefix(input);
+
+ if (!errorString.empty())
+ {
+ mf->IssueMessage(cmake::FATAL_ERROR, errorString);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator::ReplaceInstallPrefix(std::string &)
+{
+ // Do nothing
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator
+::SetImportLinkInterface(const std::string& config, std::string const& suffix,
+ cmGeneratorExpression::PreprocessContext preprocessRule,
+ cmTarget* target, ImportPropertyMap& properties,
+ std::vector<std::string>& missingTargets)
+{
+ // Add the transitive link dependencies for this configuration.
+ cmTarget::LinkInterface const* iface = target->GetLinkInterface(config,
+ target);
+ if (!iface)
+ {
+ return;
+ }
+
+ if (iface->ImplementationIsInterface)
+ {
+ // Policy CMP0022 must not be NEW.
+ this->SetImportLinkProperty(suffix, target,
+ "IMPORTED_LINK_INTERFACE_LIBRARIES",
+ iface->Libraries, properties, missingTargets);
+ return;
+ }
+
+ const char *propContent;
+
+ if (const char *prop_suffixed = target->GetProperty(
+ "LINK_INTERFACE_LIBRARIES" + suffix))
+ {
+ propContent = prop_suffixed;
+ }
+ else if (const char *prop = target->GetProperty(
+ "LINK_INTERFACE_LIBRARIES"))
+ {
+ propContent = prop;
+ }
+ else
+ {
+ return;
+ }
+
+ const bool newCMP0022Behavior =
+ target->GetPolicyStatusCMP0022() != cmPolicies::WARN
+ && target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
+
+ if(newCMP0022Behavior && !this->ExportOld)
+ {
+ cmMakefile *mf = target->GetMakefile();
+ cmOStringStream 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());
+ return;
+ }
+
+ if (!*propContent)
+ {
+ properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = "";
+ return;
+ }
+
+ std::string prepro = cmGeneratorExpression::Preprocess(propContent,
+ preprocessRule);
+ if (!prepro.empty())
+ {
+ this->ResolveTargetsInGeneratorExpressions(prepro, target,
+ missingTargets,
+ ReplaceFreeTargets);
+ properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro;
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator
+::SetImportDetailProperties(const std::string& config,
+ std::string const& suffix,
+ cmTarget* target, ImportPropertyMap& properties,
+ std::vector<std::string>& missingTargets
+ )
+{
+ // Get the makefile in which to lookup target information.
+ cmMakefile* mf = target->GetMakefile();
+
+ // Add the soname for unix shared libraries.
+ if(target->GetType() == cmTarget::SHARED_LIBRARY ||
+ target->GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ // Check whether this is a DLL platform.
+ bool dll_platform =
+ (mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
+ if(!dll_platform)
+ {
+ std::string prop;
+ std::string value;
+ if(target->HasSOName(config))
+ {
+ if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ value = this->InstallNameDir(target, config);
+ }
+ prop = "IMPORTED_SONAME";
+ value += target->GetSOName(config);
+ }
+ else
+ {
+ prop = "IMPORTED_NO_SONAME";
+ value = "TRUE";
+ }
+ prop += suffix;
+ properties[prop] = value;
+ }
+ }
+
+ // Add the transitive link dependencies for this configuration.
+ if(cmTarget::LinkInterface const* iface = target->GetLinkInterface(config,
+ target))
+ {
+ this->SetImportLinkProperty(suffix, target,
+ "IMPORTED_LINK_INTERFACE_LANGUAGES",
+ iface->Languages, properties, missingTargets);
+
+ std::vector<std::string> dummy;
+ this->SetImportLinkProperty(suffix, target,
+ "IMPORTED_LINK_DEPENDENT_LIBRARIES",
+ iface->SharedDeps, properties, dummy);
+ if(iface->Multiplicity > 0)
+ {
+ std::string prop = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
+ prop += suffix;
+ cmOStringStream m;
+ m << iface->Multiplicity;
+ properties[prop] = m.str();
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+template <typename T>
+void
+cmExportFileGenerator
+::SetImportLinkProperty(std::string const& suffix,
+ cmTarget* target,
+ const std::string& propName,
+ std::vector<T> const& entries,
+ ImportPropertyMap& properties,
+ std::vector<std::string>& missingTargets
+ )
+{
+ // Skip the property if there are no entries.
+ if(entries.empty())
+ {
+ return;
+ }
+
+ // Construct the property value.
+ std::string link_entries;
+ const char* sep = "";
+ for(typename std::vector<T>::const_iterator li = entries.begin();
+ li != entries.end(); ++li)
+ {
+ // Separate this from the previous entry.
+ link_entries += sep;
+ sep = ";";
+
+ std::string temp = *li;
+ this->AddTargetNamespace(temp, target, missingTargets);
+ link_entries += temp;
+ }
+
+ // Store the property.
+ std::string prop = propName;
+ prop += suffix;
+ properties[prop] = link_entries;
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os,
+ const std::string& config)
+{
+ os << "#----------------------------------------------------------------\n"
+ << "# Generated CMake target import file";
+ if(!config.empty())
+ {
+ os << " for configuration \"" << config << "\".\n";
+ }
+ else
+ {
+ os << ".\n";
+ }
+ os << "#----------------------------------------------------------------\n"
+ << "\n";
+ this->GenerateImportVersionCode(os);
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::GenerateImportFooterCode(std::ostream& os)
+{
+ os << "# Commands beyond this point should not need to know the version.\n"
+ << "set(CMAKE_IMPORT_FILE_VERSION)\n";
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
+{
+ // Store an import file format version. This will let us change the
+ // format later while still allowing old import files to work.
+ os << "# Commands may need to know the format version.\n"
+ << "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
+ << "\n";
+}
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os,
+ const std::string &expectedTargets)
+{
+ os << "# Protect against multiple inclusion, which would fail when already "
+ "imported targets are added once more.\n"
+ "set(_targetsDefined)\n"
+ "set(_targetsNotDefined)\n"
+ "set(_expectedTargets)\n"
+ "foreach(_expectedTarget " << expectedTargets << ")\n"
+ " list(APPEND _expectedTargets ${_expectedTarget})\n"
+ " if(NOT TARGET ${_expectedTarget})\n"
+ " list(APPEND _targetsNotDefined ${_expectedTarget})\n"
+ " endif()\n"
+ " if(TARGET ${_expectedTarget})\n"
+ " list(APPEND _targetsDefined ${_expectedTarget})\n"
+ " endif()\n"
+ "endforeach()\n"
+ "if(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
+ " set(CMAKE_IMPORT_FILE_VERSION)\n"
+ " cmake_policy(POP)\n"
+ " return()\n"
+ "endif()\n"
+ "if(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
+ " message(FATAL_ERROR \"Some (but not all) targets in this export "
+ "set were already defined.\\nTargets Defined: ${_targetsDefined}\\n"
+ "Targets not yet defined: ${_targetsNotDefined}\\n\")\n"
+ "endif()\n"
+ "unset(_targetsDefined)\n"
+ "unset(_targetsNotDefined)\n"
+ "unset(_expectedTargets)\n"
+ "\n\n";
+}
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator
+::GenerateImportTargetCode(std::ostream& os, cmTarget const* target)
+{
+ // Construct the imported target name.
+ std::string targetName = this->Namespace;
+
+ targetName += target->GetExportName();
+
+ // Create the imported target.
+ os << "# Create imported target " << targetName << "\n";
+ switch(target->GetType())
+ {
+ case cmTarget::EXECUTABLE:
+ os << "add_executable(" << targetName << " IMPORTED)\n";
+ break;
+ case cmTarget::STATIC_LIBRARY:
+ os << "add_library(" << targetName << " STATIC IMPORTED)\n";
+ break;
+ case cmTarget::SHARED_LIBRARY:
+ os << "add_library(" << targetName << " SHARED IMPORTED)\n";
+ break;
+ case cmTarget::MODULE_LIBRARY:
+ os << "add_library(" << targetName << " MODULE IMPORTED)\n";
+ break;
+ case cmTarget::UNKNOWN_LIBRARY:
+ os << "add_library(" << targetName << " UNKNOWN IMPORTED)\n";
+ break;
+ case cmTarget::INTERFACE_LIBRARY:
+ os << "add_library(" << targetName << " INTERFACE IMPORTED)\n";
+ break;
+ default: // should never happen
+ break;
+ }
+
+ // Mark the imported executable if it has exports.
+ if(target->IsExecutableWithExports())
+ {
+ os << "set_property(TARGET " << targetName
+ << " PROPERTY ENABLE_EXPORTS 1)\n";
+ }
+
+ // Mark the imported library if it is a framework.
+ if(target->IsFrameworkOnApple())
+ {
+ os << "set_property(TARGET " << targetName
+ << " PROPERTY FRAMEWORK 1)\n";
+ }
+
+ // Mark the imported executable if it is an application bundle.
+ if(target->IsAppBundleOnApple())
+ {
+ os << "set_property(TARGET " << targetName
+ << " PROPERTY MACOSX_BUNDLE 1)\n";
+ }
+
+ if (target->IsCFBundleOnApple())
+ {
+ os << "set_property(TARGET " << targetName
+ << " PROPERTY BUNDLE 1)\n";
+ }
+ os << "\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator
+::GenerateImportPropertyCode(std::ostream& os, const std::string& config,
+ cmTarget const* target,
+ ImportPropertyMap const& properties)
+{
+ // Construct the imported target name.
+ std::string targetName = this->Namespace;
+
+ targetName += target->GetExportName();
+
+ // Set the import properties.
+ os << "# Import target \"" << targetName << "\" for configuration \""
+ << config << "\"\n";
+ os << "set_property(TARGET " << targetName
+ << " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
+ if(!config.empty())
+ {
+ os << cmSystemTools::UpperCase(config);
+ }
+ else
+ {
+ os << "NOCONFIG";
+ }
+ os << ")\n";
+ os << "set_target_properties(" << targetName << " PROPERTIES\n";
+ for(ImportPropertyMap::const_iterator pi = properties.begin();
+ pi != properties.end(); ++pi)
+ {
+ os << " " << pi->first << " \"" << pi->second << "\"\n";
+ }
+ os << " )\n"
+ << "\n";
+}
+
+
+//----------------------------------------------------------------------------
+void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os,
+ const std::vector<std::string>& missingTargets)
+{
+ if (missingTargets.empty())
+ {
+ os << "# This file does not depend on other imported targets which have\n"
+ "# been exported from the same project but in a separate "
+ "export set.\n\n";
+ return;
+ }
+ os << "# Make sure the targets which have been exported in some other \n"
+ "# export set exist.\n"
+ "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
+ "foreach(_target ";
+ std::set<std::string> emitted;
+ for(unsigned int i=0; i<missingTargets.size(); ++i)
+ {
+ if (emitted.insert(missingTargets[i]).second)
+ {
+ os << "\"" << missingTargets[i] << "\" ";
+ }
+ }
+ os << ")\n"
+ " if(NOT TARGET \"${_target}\" )\n"
+ " set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
+ "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets} ${_target}\")"
+ "\n"
+ " endif()\n"
+ "endforeach()\n"
+ "\n"
+ "if(DEFINED ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
+ " if(CMAKE_FIND_PACKAGE_NAME)\n"
+ " set( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n"
+ " set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
+ "\"The following imported targets are "
+ "referenced, but are missing: "
+ "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
+ " else()\n"
+ " message(FATAL_ERROR \"The following imported targets are "
+ "referenced, but are missing: "
+ "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
+ " endif()\n"
+ "endif()\n"
+ "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
+ "\n";
+}
+
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
+{
+ // Add code which verifies at cmake time that the file which is being
+ // imported actually exists on disk. This should in theory always be theory
+ // case, but still when packages are split into normal and development
+ // packages this might get broken (e.g. the Config.cmake could be part of
+ // the non-development package, something similar happened to me without
+ // on SUSE with a mysql pkg-config file, which claimed everything is fine,
+ // but the development package was not installed.).
+ os << "# Loop over all imported files and verify that they actually exist\n"
+ "foreach(target ${_IMPORT_CHECK_TARGETS} )\n"
+ " foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n"
+ " if(NOT EXISTS \"${file}\" )\n"
+ " message(FATAL_ERROR \"The imported target \\\"${target}\\\""
+ " references the file\n"
+ " \\\"${file}\\\"\n"
+ "but this file does not exist. Possible reasons include:\n"
+ "* The file was deleted, renamed, or moved to another location.\n"
+ "* An install or uninstall procedure did not complete successfully.\n"
+ "* The installation package was faulty and contained\n"
+ " \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
+ "but not all the files it references.\n"
+ "\")\n"
+ " endif()\n"
+ " endforeach()\n"
+ " unset(_IMPORT_CHECK_FILES_FOR_${target})\n"
+ "endforeach()\n"
+ "unset(_IMPORT_CHECK_TARGETS)\n"
+ "\n";
+}
+
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator
+::GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
+ ImportPropertyMap const& properties,
+ const std::set<std::string>& importedLocations)
+{
+ // Construct the imported target name.
+ std::string targetName = this->Namespace;
+ targetName += target->GetExportName();
+
+ os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName << " )\n"
+ "list(APPEND _IMPORT_CHECK_FILES_FOR_" << targetName << " ";
+
+ for(std::set<std::string>::const_iterator li = importedLocations.begin();
+ li != importedLocations.end();
+ ++li)
+ {
+ ImportPropertyMap::const_iterator pi = properties.find(*li);
+ if (pi != properties.end())
+ {
+ os << "\"" << pi->second << "\" ";
+ }
+ }
+
+ os << ")\n\n";
+}
diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h
new file mode 100644
index 0000000000..919924e0e0
--- /dev/null
+++ b/Source/cmExportFileGenerator.h
@@ -0,0 +1,200 @@
+/*============================================================================
+ 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 cmExportFileGenerator_h
+#define cmExportFileGenerator_h
+
+#include "cmCommand.h"
+#include "cmGeneratorExpression.h"
+
+#include "cmVersionMacros.h"
+#include "cmVersion.h"
+
+#define STRINGIFY_HELPER(X) #X
+#define STRINGIFY(X) STRINGIFY_HELPER(X)
+
+#define DEVEL_CMAKE_VERSION(major, minor) ( \
+ CMake_VERSION_ENCODE(major, minor, 0) > \
+ CMake_VERSION_ENCODE(CMake_VERSION_MAJOR, CMake_VERSION_MINOR, 0) ? \
+ STRINGIFY(CMake_VERSION_MAJOR) "." STRINGIFY(CMake_VERSION_MINOR) "." \
+ STRINGIFY(CMake_VERSION_PATCH) \
+ : #major "." #minor ".0" \
+ )
+
+class cmTargetExport;
+
+/** \class cmExportFileGenerator
+ * \brief Generate a file exporting targets from a build or install tree.
+ *
+ * cmExportFileGenerator is the superclass for
+ * cmExportBuildFileGenerator and cmExportInstallFileGenerator. It
+ * contains common code generation routines for the two kinds of
+ * export implementations.
+ */
+class cmExportFileGenerator
+{
+public:
+ cmExportFileGenerator();
+ virtual ~cmExportFileGenerator() {}
+
+ /** Set the full path to the export file to generate. */
+ void SetExportFile(const char* mainFile);
+ const char *GetMainExportFileName() const;
+
+ /** Set the namespace in which to place exported target names. */
+ void SetNamespace(const std::string& ns) { this->Namespace = ns; }
+ std::string GetNamespace() const { return this->Namespace; }
+
+ void SetExportOld(bool exportOld) { this->ExportOld = exportOld; }
+
+ /** Add a configuration to be exported. */
+ void AddConfiguration(const std::string& config);
+
+ /** Actually generate the export file. Returns whether there was an
+ error. */
+ bool GenerateImportFile();
+protected:
+
+ typedef std::map<std::string, std::string> ImportPropertyMap;
+
+ // Generate per-configuration target information to the given output
+ // stream.
+ void GenerateImportConfig(std::ostream& os, const std::string& config,
+ std::vector<std::string> &missingTargets);
+
+ // Methods to implement export file code generation.
+ void GenerateImportHeaderCode(std::ostream& os,
+ const std::string& config = "");
+ void GenerateImportFooterCode(std::ostream& os);
+ void GenerateImportVersionCode(std::ostream& os);
+ void GenerateImportTargetCode(std::ostream& os, cmTarget const* target);
+ void GenerateImportPropertyCode(std::ostream& os, const std::string& config,
+ cmTarget const* target,
+ ImportPropertyMap const& properties);
+ void GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
+ ImportPropertyMap const& properties,
+ const std::set<std::string>& importedLocations);
+ void GenerateImportedFileCheckLoop(std::ostream& os);
+ void GenerateMissingTargetsCheckCode(std::ostream& os,
+ const std::vector<std::string>& missingTargets);
+
+ void GenerateExpectedTargetsCode(std::ostream& os,
+ const std::string &expectedTargets);
+
+ // Collect properties with detailed information about targets beyond
+ // their location on disk.
+ void SetImportDetailProperties(const std::string& config,
+ std::string const& suffix, cmTarget* target,
+ ImportPropertyMap& properties,
+ std::vector<std::string>& missingTargets);
+
+ template <typename T>
+ void SetImportLinkProperty(std::string const& suffix,
+ cmTarget* target, const std::string& propName,
+ std::vector<T> const& entries,
+ ImportPropertyMap& properties,
+ std::vector<std::string>& missingTargets);
+
+ /** Each subclass knows how to generate its kind of export file. */
+ virtual bool GenerateMainFile(std::ostream& os) = 0;
+
+ /** Each subclass knows where the target files are located. */
+ virtual void GenerateImportTargetsConfig(std::ostream& os,
+ const std::string& config,
+ std::string const& suffix,
+ std::vector<std::string> &missingTargets) = 0;
+
+ /** Each subclass knows how to deal with a target that is missing from an
+ * export set. */
+ virtual void HandleMissingTarget(std::string& link_libs,
+ std::vector<std::string>& missingTargets,
+ cmMakefile* mf,
+ cmTarget* depender,
+ cmTarget* dependee) = 0;
+ void PopulateInterfaceProperty(const std::string&,
+ cmTarget *target,
+ cmGeneratorExpression::PreprocessContext,
+ ImportPropertyMap &properties,
+ std::vector<std::string> &missingTargets);
+ bool PopulateInterfaceLinkLibrariesProperty(cmTarget *target,
+ cmGeneratorExpression::PreprocessContext,
+ ImportPropertyMap &properties,
+ std::vector<std::string> &missingTargets);
+ void PopulateInterfaceProperty(const std::string& propName, cmTarget *target,
+ ImportPropertyMap &properties);
+ void PopulateCompatibleInterfaceProperties(cmTarget *target,
+ ImportPropertyMap &properties);
+ void GenerateInterfaceProperties(cmTarget const* target, std::ostream& os,
+ const ImportPropertyMap &properties);
+ void PopulateIncludeDirectoriesInterface(
+ cmTargetExport *target,
+ cmGeneratorExpression::PreprocessContext preprocessRule,
+ ImportPropertyMap &properties,
+ std::vector<std::string> &missingTargets);
+
+ void SetImportLinkInterface(const std::string& config,
+ std::string const& suffix,
+ cmGeneratorExpression::PreprocessContext preprocessRule,
+ cmTarget* target, ImportPropertyMap& properties,
+ std::vector<std::string>& missingTargets);
+
+ enum FreeTargetsReplace {
+ ReplaceFreeTargets,
+ NoReplaceFreeTargets
+ };
+
+ void ResolveTargetsInGeneratorExpressions(std::string &input,
+ cmTarget* target,
+ std::vector<std::string> &missingTargets,
+ FreeTargetsReplace replace = NoReplaceFreeTargets);
+
+ void GenerateRequiredCMakeVersion(std::ostream& os,
+ const char *versionString);
+
+ // The namespace in which the exports are placed in the generated file.
+ std::string Namespace;
+
+ bool ExportOld;
+
+ // The set of configurations to export.
+ std::vector<std::string> Configurations;
+
+ // The file to generate.
+ std::string MainImportFile;
+ std::string FileDir;
+ std::string FileBase;
+ std::string FileExt;
+ bool AppendMode;
+
+ // The set of targets included in the export.
+ std::set<cmTarget*> ExportedTargets;
+
+private:
+ void PopulateInterfaceProperty(const std::string&, const std::string&,
+ cmTarget *target,
+ cmGeneratorExpression::PreprocessContext,
+ ImportPropertyMap &properties,
+ std::vector<std::string> &missingTargets);
+
+ bool AddTargetNamespace(std::string &input, cmTarget* target,
+ std::vector<std::string> &missingTargets);
+
+ void ResolveTargetsInGeneratorExpression(std::string &input,
+ cmTarget* target,
+ std::vector<std::string> &missingTargets);
+
+ virtual void ReplaceInstallPrefix(std::string &input);
+
+ virtual std::string InstallNameDir(cmTarget* target,
+ const std::string& config) = 0;
+};
+
+#endif
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
new file mode 100644
index 0000000000..89071c052c
--- /dev/null
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -0,0 +1,557 @@
+/*============================================================================
+ 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 "cmExportInstallFileGenerator.h"
+
+#include "cmExportSet.h"
+#include "cmExportSetMap.h"
+#include "cmGeneratedFileStream.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmInstallExportGenerator.h"
+#include "cmInstallTargetGenerator.h"
+#include "cmTargetExport.h"
+
+//----------------------------------------------------------------------------
+cmExportInstallFileGenerator
+::cmExportInstallFileGenerator(cmInstallExportGenerator* iegen):
+ IEGen(iegen)
+{
+}
+
+//----------------------------------------------------------------------------
+std::string cmExportInstallFileGenerator::GetConfigImportFileGlob()
+{
+ std::string glob = this->FileBase;
+ glob += "-*";
+ glob += this->FileExt;
+ return glob;
+}
+
+//----------------------------------------------------------------------------
+bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
+{
+ std::vector<cmTargetExport*> allTargets;
+ {
+ std::string expectedTargets;
+ std::string sep;
+ for(std::vector<cmTargetExport*>::const_iterator
+ tei = this->IEGen->GetExportSet()->GetTargetExports()->begin();
+ tei != this->IEGen->GetExportSet()->GetTargetExports()->end(); ++tei)
+ {
+ expectedTargets += sep + this->Namespace + (*tei)->Target->GetExportName();
+ sep = " ";
+ cmTargetExport * te = *tei;
+ if(this->ExportedTargets.insert(te->Target).second)
+ {
+ allTargets.push_back(te);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "install(EXPORT \""
+ << this->IEGen->GetExportSet()->GetName()
+ << "\" ...) " << "includes target \"" << te->Target->GetName()
+ << "\" more than once in the export set.";
+ cmSystemTools::Error(e.str().c_str());
+ return false;
+ }
+ }
+
+ this->GenerateExpectedTargetsCode(os, expectedTargets);
+ }
+
+ // Add code to compute the installation prefix relative to the
+ // import file location.
+ const char* installDest = this->IEGen->GetDestination();
+ if(!cmSystemTools::FileIsFullPath(installDest))
+ {
+ std::string installPrefix =
+ this->IEGen->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
+ std::string absDest = installPrefix + "/" + installDest;
+ std::string absDestS = absDest + "/";
+ os << "# Compute the installation prefix relative to this file.\n"
+ << "get_filename_component(_IMPORT_PREFIX"
+ << " \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n";
+ if(cmHasLiteralPrefix(absDestS.c_str(), "/lib/") ||
+ cmHasLiteralPrefix(absDestS.c_str(), "/lib64/") ||
+ cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib/") ||
+ cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib64/"))
+ {
+ // Handle "/usr move" symlinks created by some Linux distros.
+ os <<
+ "# Use original install prefix when loaded through a\n"
+ "# cross-prefix symbolic link such as /lib -> /usr/lib.\n"
+ "get_filename_component(_realCurr \"${_IMPORT_PREFIX}\" REALPATH)\n"
+ "get_filename_component(_realOrig \"" << absDest << "\" REALPATH)\n"
+ "if(_realCurr STREQUAL _realOrig)\n"
+ " set(_IMPORT_PREFIX \"" << absDest << "\")\n"
+ "endif()\n"
+ "unset(_realOrig)\n"
+ "unset(_realCurr)\n";
+ }
+ std::string dest = installDest;
+ while(!dest.empty())
+ {
+ os <<
+ "get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" PATH)\n";
+ dest = cmSystemTools::GetFilenamePath(dest);
+ }
+ os << "\n";
+
+ // Import location properties may reference this variable.
+ this->ImportPrefix = "${_IMPORT_PREFIX}/";
+ }
+
+ std::vector<std::string> missingTargets;
+
+ bool require2_8_12 = false;
+ bool require3_0_0 = false;
+ bool requiresConfigFiles = false;
+ // Create all the imported targets.
+ for(std::vector<cmTargetExport*>::const_iterator
+ tei = allTargets.begin();
+ tei != allTargets.end(); ++tei)
+ {
+ cmTarget* te = (*tei)->Target;
+
+ requiresConfigFiles = requiresConfigFiles
+ || te->GetType() != cmTarget::INTERFACE_LIBRARY;
+
+ this->GenerateImportTargetCode(os, te);
+
+ ImportPropertyMap properties;
+
+ this->PopulateIncludeDirectoriesInterface(*tei,
+ cmGeneratorExpression::InstallInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES",
+ te,
+ cmGeneratorExpression::InstallInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS",
+ te,
+ cmGeneratorExpression::InstallInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS",
+ te,
+ cmGeneratorExpression::InstallInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS",
+ te,
+ cmGeneratorExpression::InstallInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES",
+ te,
+ cmGeneratorExpression::InstallInterface,
+ properties, missingTargets);
+
+ const bool newCMP0022Behavior =
+ te->GetPolicyStatusCMP0022() != cmPolicies::WARN
+ && te->GetPolicyStatusCMP0022() != cmPolicies::OLD;
+ if (newCMP0022Behavior)
+ {
+ if (this->PopulateInterfaceLinkLibrariesProperty(te,
+ cmGeneratorExpression::InstallInterface,
+ properties, missingTargets)
+ && !this->ExportOld)
+ {
+ require2_8_12 = true;
+ }
+ }
+ if (te->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ require3_0_0 = true;
+ }
+ this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE",
+ te, properties);
+ this->PopulateCompatibleInterfaceProperties(te, properties);
+
+ this->GenerateInterfaceProperties(te, os, properties);
+ }
+
+ if (require3_0_0)
+ {
+ this->GenerateRequiredCMakeVersion(os, "3.0.0");
+ }
+ else if (require2_8_12)
+ {
+ this->GenerateRequiredCMakeVersion(os, "2.8.12");
+ }
+
+ // Now load per-configuration properties for them.
+ os << "# Load information for each installed configuration.\n"
+ << "get_filename_component(_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n"
+ << "file(GLOB CONFIG_FILES \"${_DIR}/"
+ << this->GetConfigImportFileGlob() << "\")\n"
+ << "foreach(f ${CONFIG_FILES})\n"
+ << " include(${f})\n"
+ << "endforeach()\n"
+ << "\n";
+
+ // Cleanup the import prefix variable.
+ if(!this->ImportPrefix.empty())
+ {
+ os << "# Cleanup temporary variables.\n"
+ << "set(_IMPORT_PREFIX)\n"
+ << "\n";
+ }
+ this->GenerateImportedFileCheckLoop(os);
+
+ bool result = true;
+ // Generate an import file for each configuration.
+ // Don't do this if we only export INTERFACE_LIBRARY targets.
+ if (requiresConfigFiles)
+ {
+ for(std::vector<std::string>::const_iterator
+ ci = this->Configurations.begin();
+ ci != this->Configurations.end(); ++ci)
+ {
+ if(!this->GenerateImportFileConfig(*ci, missingTargets))
+ {
+ result = false;
+ }
+ }
+ }
+
+ this->GenerateMissingTargetsCheckCode(os, missingTargets);
+
+ return result;
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportInstallFileGenerator::ReplaceInstallPrefix(std::string &input)
+{
+ std::string::size_type pos = 0;
+ std::string::size_type lastPos = pos;
+
+ while((pos = input.find("$<INSTALL_PREFIX>", lastPos)) != input.npos)
+ {
+ std::string::size_type endPos = pos + sizeof("$<INSTALL_PREFIX>") - 1;
+ input.replace(pos, endPos - pos, "${_IMPORT_PREFIX}");
+ lastPos = endPos;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool
+cmExportInstallFileGenerator::GenerateImportFileConfig(
+ const std::string& config,
+ std::vector<std::string> &missingTargets)
+{
+ // Skip configurations not enabled for this export.
+ if(!this->IEGen->InstallsForConfig(config))
+ {
+ return true;
+ }
+
+ // Construct the name of the file to generate.
+ std::string fileName = this->FileDir;
+ fileName += "/";
+ fileName += this->FileBase;
+ fileName += "-";
+ if(!config.empty())
+ {
+ fileName += cmSystemTools::LowerCase(config);
+ }
+ else
+ {
+ fileName += "noconfig";
+ }
+ fileName += this->FileExt;
+
+ // Open the output file to generate it.
+ cmGeneratedFileStream exportFileStream(fileName.c_str(), true);
+ if(!exportFileStream)
+ {
+ std::string se = cmSystemTools::GetLastSystemError();
+ cmOStringStream e;
+ e << "cannot write to file \"" << fileName
+ << "\": " << se;
+ cmSystemTools::Error(e.str().c_str());
+ return false;
+ }
+ std::ostream& os = exportFileStream;
+
+ // Start with the import file header.
+ this->GenerateImportHeaderCode(os, config);
+
+ // Generate the per-config target information.
+ this->GenerateImportConfig(os, config, missingTargets);
+
+ // End with the import file footer.
+ this->GenerateImportFooterCode(os);
+
+ // Record this per-config import file.
+ this->ConfigImportFiles[config] = fileName;
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportInstallFileGenerator
+::GenerateImportTargetsConfig(std::ostream& os,
+ const std::string& config,
+ std::string const& suffix,
+ std::vector<std::string> &missingTargets)
+{
+ // Add each target in the set to the export.
+ for(std::vector<cmTargetExport*>::const_iterator
+ tei = this->IEGen->GetExportSet()->GetTargetExports()->begin();
+ tei != this->IEGen->GetExportSet()->GetTargetExports()->end(); ++tei)
+ {
+ // Collect import properties for this target.
+ cmTargetExport const* te = *tei;
+ if (te->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+
+ ImportPropertyMap properties;
+ std::set<std::string> importedLocations;
+
+ this->SetImportLocationProperty(config, suffix, te->ArchiveGenerator,
+ properties, importedLocations);
+ this->SetImportLocationProperty(config, suffix, te->LibraryGenerator,
+ properties, importedLocations);
+ this->SetImportLocationProperty(config, suffix,
+ te->RuntimeGenerator, properties,
+ importedLocations);
+ this->SetImportLocationProperty(config, suffix, te->FrameworkGenerator,
+ properties, importedLocations);
+ this->SetImportLocationProperty(config, suffix, te->BundleGenerator,
+ properties, importedLocations);
+
+ // If any file location was set for the target add it to the
+ // import file.
+ if(!properties.empty())
+ {
+ // Get the rest of the target details.
+ this->SetImportDetailProperties(config, suffix,
+ te->Target, properties, missingTargets);
+
+ this->SetImportLinkInterface(config, suffix,
+ cmGeneratorExpression::InstallInterface,
+ te->Target, properties, missingTargets);
+
+ // TOOD: PUBLIC_HEADER_LOCATION
+ // This should wait until the build feature propagation stuff
+ // is done. Then this can be a propagated include directory.
+ // this->GenerateImportProperty(config, te->HeaderGenerator,
+ // properties);
+
+ // Generate code in the export file.
+ this->GenerateImportPropertyCode(os, config, te->Target, properties);
+ this->GenerateImportedFileChecksCode(os, te->Target, properties,
+ importedLocations);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportInstallFileGenerator
+::SetImportLocationProperty(const std::string& config,
+ std::string const& suffix,
+ cmInstallTargetGenerator* itgen,
+ ImportPropertyMap& properties,
+ std::set<std::string>& importedLocations
+ )
+{
+ // Skip rules that do not match this configuration.
+ if(!(itgen && itgen->InstallsForConfig(config)))
+ {
+ return;
+ }
+
+ // Get the target to be installed.
+ cmTarget* target = itgen->GetTarget();
+
+ // Construct the installed location of the target.
+ std::string dest = itgen->GetDestination();
+ std::string value;
+ if(!cmSystemTools::FileIsFullPath(dest.c_str()))
+ {
+ // The target is installed relative to the installation prefix.
+ if(this->ImportPrefix.empty())
+ {
+ this->ComplainAboutImportPrefix(itgen);
+ }
+ value = this->ImportPrefix;
+ }
+ value += dest;
+ value += "/";
+
+ if(itgen->IsImportLibrary())
+ {
+ // Construct the property name.
+ std::string prop = "IMPORTED_IMPLIB";
+ prop += suffix;
+
+ // Append the installed file name.
+ value += itgen->GetInstallFilename(target, config,
+ cmInstallTargetGenerator::NameImplib);
+
+ // Store the property.
+ properties[prop] = value;
+ importedLocations.insert(prop);
+ }
+ else
+ {
+ // Construct the property name.
+ std::string prop = "IMPORTED_LOCATION";
+ prop += suffix;
+
+ // Append the installed file name.
+ if(target->IsAppBundleOnApple())
+ {
+ value += itgen->GetInstallFilename(target, config);
+ value += ".app/Contents/MacOS/";
+ value += itgen->GetInstallFilename(target, config);
+ }
+ else
+ {
+ value += itgen->GetInstallFilename(target, config,
+ cmInstallTargetGenerator::NameReal);
+ }
+
+ // Store the property.
+ properties[prop] = value;
+ importedLocations.insert(prop);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportInstallFileGenerator::HandleMissingTarget(
+ std::string& link_libs, std::vector<std::string>& missingTargets,
+ cmMakefile* mf, cmTarget* depender, cmTarget* dependee)
+{
+ const std::string name = dependee->GetName();
+ std::vector<std::string> namespaces = this->FindNamespaces(mf, name);
+ int targetOccurrences = (int)namespaces.size();
+ if (targetOccurrences == 1)
+ {
+ std::string missingTarget = namespaces[0];
+
+ missingTarget += dependee->GetExportName();
+ link_libs += missingTarget;
+ missingTargets.push_back(missingTarget);
+ }
+ else
+ {
+ // All exported targets should be known here and should be unique.
+ // This is probably user-error.
+ this->ComplainAboutMissingTarget(depender, dependee, targetOccurrences);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string>
+cmExportInstallFileGenerator
+::FindNamespaces(cmMakefile* mf, const std::string& name)
+{
+ std::vector<std::string> namespaces;
+ cmGlobalGenerator* gg = mf->GetLocalGenerator()->GetGlobalGenerator();
+ const cmExportSetMap& exportSets = gg->GetExportSets();
+
+ for(cmExportSetMap::const_iterator expIt = exportSets.begin();
+ expIt != exportSets.end();
+ ++expIt)
+ {
+ const cmExportSet* exportSet = expIt->second;
+ std::vector<cmTargetExport*> const* targets =
+ exportSet->GetTargetExports();
+
+ bool containsTarget = false;
+ for(unsigned int i=0; i<targets->size(); i++)
+ {
+ if (name == (*targets)[i]->Target->GetName())
+ {
+ containsTarget = true;
+ break;
+ }
+ }
+
+ if (containsTarget)
+ {
+ std::vector<cmInstallExportGenerator const*> const* installs =
+ exportSet->GetInstallations();
+ for(unsigned int i=0; i<installs->size(); i++)
+ {
+ namespaces.push_back((*installs)[i]->GetNamespace());
+ }
+ }
+ }
+
+ return namespaces;
+}
+
+
+//----------------------------------------------------------------------------
+void
+cmExportInstallFileGenerator
+::ComplainAboutImportPrefix(cmInstallTargetGenerator* itgen)
+{
+ const char* installDest = this->IEGen->GetDestination();
+ cmOStringStream e;
+ e << "install(EXPORT \""
+ << this->IEGen->GetExportSet()->GetName()
+ << "\") given absolute "
+ << "DESTINATION \"" << installDest << "\" but the export "
+ << "references an installation of target \""
+ << itgen->GetTarget()->GetName() << "\" which has relative "
+ << "DESTINATION \"" << itgen->GetDestination() << "\".";
+ cmSystemTools::Error(e.str().c_str());
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportInstallFileGenerator
+::ComplainAboutMissingTarget(cmTarget* depender,
+ cmTarget* dependee,
+ int occurrences)
+{
+ cmOStringStream e;
+ e << "install(EXPORT \""
+ << this->IEGen->GetExportSet()->GetName()
+ << "\" ...) "
+ << "includes target \"" << depender->GetName()
+ << "\" which requires target \"" << dependee->GetName() << "\" ";
+ if (occurrences == 0)
+ {
+ e << "that is not in the export set.";
+ }
+ else
+ {
+ e << "that is not in this export set, but " << occurrences
+ << " times in others.";
+ }
+ cmSystemTools::Error(e.str().c_str());
+}
+
+std::string
+cmExportInstallFileGenerator::InstallNameDir(cmTarget* target,
+ const std::string&)
+{
+ std::string install_name_dir;
+
+ cmMakefile* mf = target->GetMakefile();
+ if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ install_name_dir =
+ target->GetInstallNameDirForInstallTree();
+ }
+
+ return install_name_dir;
+}
diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h
new file mode 100644
index 0000000000..b851ad5f3c
--- /dev/null
+++ b/Source/cmExportInstallFileGenerator.h
@@ -0,0 +1,98 @@
+/*============================================================================
+ 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 cmExportInstallFileGenerator_h
+#define cmExportInstallFileGenerator_h
+
+#include "cmExportFileGenerator.h"
+
+class cmInstallExportGenerator;
+class cmInstallTargetGenerator;
+
+/** \class cmExportInstallFileGenerator
+ * \brief Generate a file exporting targets from an install tree.
+ *
+ * cmExportInstallFileGenerator generates files exporting targets from
+ * install an installation tree. The files are placed in a temporary
+ * location for installation by cmInstallExportGenerator. One main
+ * file is generated that creates the imported targets and loads
+ * per-configuration files. Target locations and settings for each
+ * configuration are written to these per-configuration files. After
+ * installation the main file loads the configurations that have been
+ * installed.
+ *
+ * This is used to implement the INSTALL(EXPORT) command.
+ */
+class cmExportInstallFileGenerator: public cmExportFileGenerator
+{
+public:
+ /** Construct with the export installer that will install the
+ files. */
+ cmExportInstallFileGenerator(cmInstallExportGenerator* iegen);
+
+ /** Get the per-config file generated for each configuraiton. This
+ maps from the configuration name to the file temporary location
+ for installation. */
+ std::map<std::string, std::string> const& GetConfigImportFiles()
+ { return this->ConfigImportFiles; }
+
+ /** Compute the globbing expression used to load per-config import
+ files from the main file. */
+ std::string GetConfigImportFileGlob();
+protected:
+
+ // Implement virtual methods from the superclass.
+ virtual bool GenerateMainFile(std::ostream& os);
+ virtual void GenerateImportTargetsConfig(std::ostream& os,
+ const std::string& config,
+ std::string const& suffix,
+ std::vector<std::string> &missingTargets);
+ virtual void HandleMissingTarget(std::string& link_libs,
+ std::vector<std::string>& missingTargets,
+ cmMakefile* mf,
+ cmTarget* depender,
+ cmTarget* dependee);
+
+ virtual void ReplaceInstallPrefix(std::string &input);
+
+ void ComplainAboutMissingTarget(cmTarget* depender,
+ cmTarget* dependee,
+ int occurrences);
+
+ std::vector<std::string> FindNamespaces(cmMakefile* mf,
+ const std::string& name);
+
+
+ /** Generate a per-configuration file for the targets. */
+ bool GenerateImportFileConfig(const std::string& config,
+ std::vector<std::string> &missingTargets);
+
+ /** Fill in properties indicating installed file locations. */
+ void SetImportLocationProperty(const std::string& config,
+ std::string const& suffix,
+ cmInstallTargetGenerator* itgen,
+ ImportPropertyMap& properties,
+ std::set<std::string>& importedLocations
+ );
+
+ void ComplainAboutImportPrefix(cmInstallTargetGenerator* itgen);
+
+ std::string InstallNameDir(cmTarget* target, const std::string& config);
+
+ cmInstallExportGenerator* IEGen;
+
+ std::string ImportPrefix;
+
+ // The import file generated for each configuration.
+ std::map<std::string, std::string> ConfigImportFiles;
+};
+
+#endif
diff --git a/Source/cmExportLibraryDependenciesCommand.cxx b/Source/cmExportLibraryDependenciesCommand.cxx
new file mode 100644
index 0000000000..cb150a79ce
--- /dev/null
+++ b/Source/cmExportLibraryDependenciesCommand.cxx
@@ -0,0 +1,206 @@
+/*============================================================================
+ 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 "cmExportLibraryDependenciesCommand.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmake.h"
+#include "cmVersion.h"
+
+#include <cmsys/auto_ptr.hxx>
+
+bool cmExportLibraryDependenciesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(this->Disallowed(cmPolicies::CMP0033,
+ "The export_library_dependencies command should not be called; "
+ "see CMP0033."))
+ { return true; }
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // store the arguments for the final pass
+ this->Filename = args[0];
+ this->Append = false;
+ if(args.size() > 1)
+ {
+ if(args[1] == "APPEND")
+ {
+ this->Append = true;
+ }
+ }
+ return true;
+}
+
+
+void cmExportLibraryDependenciesCommand::FinalPass()
+{
+ // export_library_dependencies() shouldn't modify anything
+ // ensure this by calling a const method
+ this->ConstFinalPass();
+}
+
+void cmExportLibraryDependenciesCommand::ConstFinalPass() const
+{
+ // Use copy-if-different if not appending.
+ cmsys::auto_ptr<cmsys::ofstream> foutPtr;
+ if(this->Append)
+ {
+ cmsys::auto_ptr<cmsys::ofstream> ap(
+ new cmsys::ofstream(this->Filename.c_str(), std::ios::app));
+ foutPtr = ap;
+ }
+ else
+ {
+ cmsys::auto_ptr<cmGeneratedFileStream> ap(
+ new cmGeneratedFileStream(this->Filename.c_str(), true));
+ ap->SetCopyIfDifferent(true);
+ foutPtr = ap;
+ }
+ std::ostream& fout = *foutPtr.get();
+
+ if (!fout)
+ {
+ cmSystemTools::Error("Error Writing ", this->Filename.c_str());
+ cmSystemTools::ReportLastSystemError("");
+ return;
+ }
+
+ // Collect dependency information about all library targets built in
+ // the project.
+ cmake* cm = this->Makefile->GetCMakeInstance();
+ cmGlobalGenerator* global = cm->GetGlobalGenerator();
+ const std::vector<cmLocalGenerator *>& locals = global->GetLocalGenerators();
+ std::map<std::string, std::string> libDepsOld;
+ std::map<std::string, std::string> libDepsNew;
+ std::map<std::string, std::string> libTypes;
+ for(std::vector<cmLocalGenerator *>::const_iterator i = locals.begin();
+ i != locals.end(); ++i)
+ {
+ const cmLocalGenerator* gen = *i;
+ const cmTargets &tgts = gen->GetMakefile()->GetTargets();
+ for(cmTargets::const_iterator l = tgts.begin();
+ l != tgts.end(); ++l)
+ {
+ // Get the current target.
+ cmTarget const& target = l->second;
+
+ // Skip non-library targets.
+ if(target.GetType() < cmTarget::STATIC_LIBRARY
+ || target.GetType() > cmTarget::MODULE_LIBRARY)
+ {
+ continue;
+ }
+
+ // Construct the dependency variable name.
+ std::string targetEntry = target.GetName();
+ targetEntry += "_LIB_DEPENDS";
+
+ // Construct the dependency variable value with the direct link
+ // dependencies.
+ std::string valueOld;
+ std::string valueNew;
+ cmTarget::LinkLibraryVectorType const& libs =
+ target.GetOriginalLinkLibraries();
+ for(cmTarget::LinkLibraryVectorType::const_iterator li = libs.begin();
+ li != libs.end(); ++li)
+ {
+ std::string ltVar = li->first;
+ ltVar += "_LINK_TYPE";
+ std::string ltValue;
+ switch(li->second)
+ {
+ case cmTarget::GENERAL:
+ valueNew += "general;";
+ ltValue = "general";
+ break;
+ case cmTarget::DEBUG:
+ valueNew += "debug;";
+ ltValue = "debug";
+ break;
+ case cmTarget::OPTIMIZED:
+ valueNew += "optimized;";
+ ltValue = "optimized";
+ break;
+ }
+ std::string lib = li->first;
+ if(cmTarget* libtgt = global->FindTarget(lib))
+ {
+ // Handle simple output name changes. This command is
+ // deprecated so we do not support full target name
+ // translation (which requires per-configuration info).
+ if(const char* outname = libtgt->GetProperty("OUTPUT_NAME"))
+ {
+ lib = outname;
+ }
+ }
+ valueOld += lib;
+ valueOld += ";";
+ valueNew += lib;
+ valueNew += ";";
+
+ std::string& ltEntry = libTypes[ltVar];
+ if(ltEntry.empty())
+ {
+ ltEntry = ltValue;
+ }
+ else if(ltEntry != ltValue)
+ {
+ ltEntry = "general";
+ }
+ }
+ libDepsNew[targetEntry] = valueNew;
+ libDepsOld[targetEntry] = valueOld;
+ }
+ }
+
+ // Generate dependency information for both old and new style CMake
+ // versions.
+ const char* vertest =
+ "\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" GREATER 2.4";
+ fout << "# Generated by CMake " << cmVersion::GetCMakeVersion() << "\n\n";
+ fout << "if(" << vertest << ")\n";
+ fout << " # Information for CMake 2.6 and above.\n";
+ for(std::map<std::string, std::string>::const_iterator
+ i = libDepsNew.begin();
+ i != libDepsNew.end(); ++i)
+ {
+ if(!i->second.empty())
+ {
+ fout << " set(\"" << i->first << "\" \"" << i->second << "\")\n";
+ }
+ }
+ fout << "else()\n";
+ fout << " # Information for CMake 2.4 and lower.\n";
+ for(std::map<std::string, std::string>::const_iterator
+ i = libDepsOld.begin();
+ i != libDepsOld.end(); ++i)
+ {
+ if(!i->second.empty())
+ {
+ fout << " set(\"" << i->first << "\" \"" << i->second << "\")\n";
+ }
+ }
+ for(std::map<std::string, std::string>::const_iterator i = libTypes.begin();
+ i != libTypes.end(); ++i)
+ {
+ if(i->second != "general")
+ {
+ fout << " set(\"" << i->first << "\" \"" << i->second << "\")\n";
+ }
+ }
+ fout << "endif()\n";
+ return;
+}
diff --git a/Source/cmExportLibraryDependenciesCommand.h b/Source/cmExportLibraryDependenciesCommand.h
new file mode 100644
index 0000000000..2ea4e79b92
--- /dev/null
+++ b/Source/cmExportLibraryDependenciesCommand.h
@@ -0,0 +1,37 @@
+/*============================================================================
+ 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 cmExportLibraryDependenciesCommand_h
+#define cmExportLibraryDependenciesCommand_h
+
+#include "cmCommand.h"
+
+class cmExportLibraryDependenciesCommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmExportLibraryDependenciesCommand, cmCommand);
+ virtual cmCommand* Clone() { return new cmExportLibraryDependenciesCommand; }
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+ virtual std::string GetName() const { return "export_library_dependencies";}
+ virtual bool IsDiscouraged() const { return true; }
+
+ virtual void FinalPass();
+ virtual bool HasFinalPass() const { return true; }
+
+private:
+ std::string Filename;
+ bool Append;
+ void ConstFinalPass() const;
+};
+
+
+#endif
diff --git a/Source/cmExportSet.cxx b/Source/cmExportSet.cxx
new file mode 100644
index 0000000000..33b0630379
--- /dev/null
+++ b/Source/cmExportSet.cxx
@@ -0,0 +1,32 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 "cmExportSet.h"
+#include "cmTargetExport.h"
+
+cmExportSet::~cmExportSet()
+{
+ for(unsigned int i = 0; i < this->TargetExports.size(); ++ i)
+ {
+ delete this->TargetExports[i];
+ }
+}
+
+void cmExportSet::AddTargetExport(cmTargetExport* te)
+{
+ this->TargetExports.push_back(te);
+}
+
+void cmExportSet::AddInstallation(cmInstallExportGenerator const* installation)
+{
+ this->Installations.push_back(installation);
+}
diff --git a/Source/cmExportSet.h b/Source/cmExportSet.h
new file mode 100644
index 0000000000..a57aa12044
--- /dev/null
+++ b/Source/cmExportSet.h
@@ -0,0 +1,46 @@
+/*============================================================================
+ 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 cmExportSet_h
+#define cmExportSet_h
+
+#include "cmSystemTools.h"
+class cmTargetExport;
+class cmInstallExportGenerator;
+
+/// A set of targets that were installed with the same EXPORT parameter.
+class cmExportSet
+{
+public:
+ /// Construct an empty export set named \a name
+ cmExportSet(const std::string &name) : Name(name) {}
+ /// Destructor
+ ~cmExportSet();
+
+ void AddTargetExport(cmTargetExport* tgt);
+
+ void AddInstallation(cmInstallExportGenerator const* installation);
+
+ std::string const& GetName() const { return this->Name; }
+
+ std::vector<cmTargetExport*> const* GetTargetExports() const
+ { return &this->TargetExports; }
+
+ std::vector<cmInstallExportGenerator const*> const* GetInstallations() const
+ { return &this->Installations; }
+
+private:
+ std::vector<cmTargetExport*> TargetExports;
+ std::string Name;
+ std::vector<cmInstallExportGenerator const*> Installations;
+};
+
+#endif
diff --git a/Source/cmExportSetMap.cxx b/Source/cmExportSetMap.cxx
new file mode 100644
index 0000000000..5174118870
--- /dev/null
+++ b/Source/cmExportSetMap.cxx
@@ -0,0 +1,40 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 "cmExportSetMap.h"
+#include "cmExportSet.h"
+
+cmExportSet* cmExportSetMap::operator[](const std::string &name)
+{
+ std::map<std::string, cmExportSet*>::iterator it = this->find(name);
+ if (it == this->end()) // Export set not found
+ {
+ it = this->insert(std::make_pair(name, new cmExportSet(name))).first;
+ }
+ return it->second;
+}
+
+void cmExportSetMap::clear()
+{
+ for(std::map<std::string, cmExportSet*>::iterator it = this->begin();
+ it != this->end();
+ ++ it)
+ {
+ delete it->second;
+ }
+ this->derived::clear();
+}
+
+cmExportSetMap::~cmExportSetMap()
+{
+ this->clear();
+}
diff --git a/Source/cmExportSetMap.h b/Source/cmExportSetMap.h
new file mode 100644
index 0000000000..965046ceff
--- /dev/null
+++ b/Source/cmExportSetMap.h
@@ -0,0 +1,36 @@
+/*============================================================================
+ 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 cmExportSetMap_h
+#define cmExportSetMap_h
+
+#include "cmSystemTools.h"
+class cmExportSet;
+
+/// A name -> cmExportSet map with overloaded operator[].
+class cmExportSetMap : public std::map<std::string, cmExportSet*>
+{
+ typedef std::map<std::string, cmExportSet*> derived;
+public:
+ /** \brief Overloaded operator[].
+ *
+ * The operator is overloaded because cmExportSet has no default constructor:
+ * we do not want unnamed export sets.
+ */
+ cmExportSet* operator[](const std::string &name);
+
+ void clear();
+
+ /// Overloaded destructor deletes all member export sets.
+ ~cmExportSetMap();
+};
+
+#endif
diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx
new file mode 100644
index 0000000000..eb8d1935f4
--- /dev/null
+++ b/Source/cmExportTryCompileFileGenerator.cxx
@@ -0,0 +1,135 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmExportTryCompileFileGenerator.h"
+
+#include "cmGeneratedFileStream.h"
+#include "cmGeneratorExpressionDAGChecker.h"
+
+//----------------------------------------------------------------------------
+bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
+{
+ std::set<cmTarget const*> emitted;
+ std::set<cmTarget const*> emittedDeps;
+ while(!this->Exports.empty())
+ {
+ cmTarget const* te = this->Exports.back();
+ this->Exports.pop_back();
+ if (emitted.insert(te).second)
+ {
+ emittedDeps.insert(te);
+ this->GenerateImportTargetCode(os, te);
+
+ ImportPropertyMap properties;
+
+#define FIND_TARGETS(PROPERTY) \
+ this->FindTargets("INTERFACE_" #PROPERTY, te, emittedDeps);
+
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
+
+#undef FIND_TARGETS
+
+ this->PopulateProperties(te, properties, emittedDeps);
+
+ this->GenerateInterfaceProperties(te, os, properties);
+ }
+ }
+ return true;
+}
+
+std::string cmExportTryCompileFileGenerator::FindTargets(
+ const std::string& propName,
+ cmTarget const* tgt,
+ std::set<cmTarget const*> &emitted)
+{
+ const char *prop = tgt->GetProperty(propName);
+ if(!prop)
+ {
+ return std::string();
+ }
+
+ cmGeneratorExpression ge;
+
+ cmGeneratorExpressionDAGChecker dagChecker(
+ tgt->GetName(),
+ propName, 0, 0);
+
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
+
+ cmTarget dummyHead;
+ dummyHead.SetType(cmTarget::EXECUTABLE, "try_compile_dummy_exe");
+ dummyHead.SetMakefile(tgt->GetMakefile());
+
+ std::string result = cge->Evaluate(tgt->GetMakefile(), this->Config,
+ false, &dummyHead, tgt, &dagChecker);
+
+ const std::set<cmTarget const*> &allTargets = cge->GetAllTargetsSeen();
+ for(std::set<cmTarget const*>::const_iterator li = allTargets.begin();
+ li != allTargets.end(); ++li)
+ {
+ if(emitted.insert(*li).second)
+ {
+ this->Exports.push_back(*li);
+ }
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+void
+cmExportTryCompileFileGenerator::PopulateProperties(cmTarget const* target,
+ ImportPropertyMap& properties,
+ std::set<cmTarget const*> &emitted)
+{
+ cmPropertyMap props = target->GetProperties();
+ for(cmPropertyMap::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)
+ {
+ const std::string libs = i->second.GetValue();
+
+ std::string evalResult = this->FindTargets(i->first,
+ target, emitted);
+
+ std::vector<std::string> depends;
+ cmSystemTools::ExpandListArgument(evalResult, depends);
+ for(std::vector<std::string>::const_iterator li = depends.begin();
+ li != depends.end(); ++li)
+ {
+ cmTarget *tgt = target->GetMakefile()->FindTargetToUse(*li);
+ if(tgt && emitted.insert(tgt).second)
+ {
+ this->Exports.push_back(tgt);
+ }
+ }
+ }
+ }
+}
+std::string
+cmExportTryCompileFileGenerator::InstallNameDir(cmTarget* target,
+ const std::string& config)
+{
+ std::string install_name_dir;
+
+ cmMakefile* mf = target->GetMakefile();
+ if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ install_name_dir =
+ target->GetInstallNameDirForBuildTree(config);
+ }
+
+ return install_name_dir;
+}
diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h
new file mode 100644
index 0000000000..ec70d81035
--- /dev/null
+++ b/Source/cmExportTryCompileFileGenerator.h
@@ -0,0 +1,57 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmExportInstallFileGenerator_h
+#define cmExportInstallFileGenerator_h
+
+#include "cmExportFileGenerator.h"
+
+class cmInstallExportGenerator;
+class cmInstallTargetGenerator;
+
+class cmExportTryCompileFileGenerator: public cmExportFileGenerator
+{
+public:
+ /** 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:
+
+ // Implement virtual methods from the superclass.
+ virtual bool GenerateMainFile(std::ostream& os);
+
+ virtual void GenerateImportTargetsConfig(std::ostream&,
+ const std::string&,
+ std::string const&,
+ std::vector<std::string>&) {}
+ virtual void HandleMissingTarget(std::string&,
+ std::vector<std::string>&,
+ cmMakefile*,
+ cmTarget*,
+ cmTarget*) {}
+
+ void PopulateProperties(cmTarget const* target,
+ ImportPropertyMap& properties,
+ std::set<cmTarget const*> &emitted);
+
+ std::string InstallNameDir(cmTarget* target,
+ const std::string& config);
+private:
+ std::string FindTargets(const std::string& prop, cmTarget const* tgt,
+ std::set<cmTarget const*> &emitted);
+
+
+ std::vector<cmTarget const*> Exports;
+ std::string Config;
+};
+
+#endif
diff --git a/Source/cmExprLexer.cxx b/Source/cmExprLexer.cxx
new file mode 100644
index 0000000000..4704f03685
--- /dev/null
+++ b/Source/cmExprLexer.cxx
@@ -0,0 +1,1928 @@
+#include "cmStandardIncludes.h"
+#line 2 "/home/andy/vtk/CMake-bin/Source/cmExprLexer.cxx"
+
+#line 4 "/home/andy/vtk/CMake-bin/Source/cmExprLexer.cxx"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 31
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+int cmExpr_yylex_init (yyscan_t* scanner);
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yyg->yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yyg->yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE cmExpr_yyrestart(yyin ,yyscanner )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#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)
+
+/* Return all but the first "n" matched characters back to the input
+ stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = yyg->yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef unsigned int yy_size_t;
+#endif
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int 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
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via cmExpr_yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
+ ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is
+ * not NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
+
+void cmExpr_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void cmExpr_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmExpr_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
+void cmExpr_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmExpr_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmExpr_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+void cmExpr_yypop_buffer_state (yyscan_t yyscanner );
+
+static void cmExpr_yyensure_buffer_stack (yyscan_t yyscanner );
+static void cmExpr_yy_load_buffer_state (yyscan_t yyscanner );
+static void cmExpr_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
+
+#define YY_FLUSH_BUFFER cmExpr_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+
+YY_BUFFER_STATE cmExpr_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmExpr_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmExpr_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+
+void *cmExpr_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *cmExpr_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void cmExpr_yyfree (void * ,yyscan_t yyscanner );
+
+#define yy_new_buffer cmExpr_yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ cmExpr_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmExpr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ cmExpr_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmExpr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+#define cmExpr_yywrap(n) 1
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+typedef int yy_state_type;
+
+#define yytext_ptr yytext_r
+
+static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,
+ yyscan_t yyscanner);
+static int yy_get_next_buffer (yyscan_t yyscanner );
+static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yyg->yytext_ptr = yy_bp; \
+ yyleng = (size_t) (yy_cp - yy_bp); \
+ yyg->yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yyg->yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 15
+#define YY_END_OF_BUFFER 16
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[23] =
+ { 0,
+ 0, 0, 16, 15, 6, 8, 13, 14, 4, 2,
+ 3, 5, 1, 15, 15, 9, 7, 10, 1, 11,
+ 12, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 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, 2, 3, 1, 4,
+ 5, 6, 7, 1, 8, 1, 9, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 1, 1, 11,
+ 1, 12, 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, 13, 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, 14, 1, 15, 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, 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, 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, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[16] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int16_t yy_base[23] =
+ { 0,
+ 0, 0, 20, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 9, 7, 5, 21, 21, 21, 6, 21,
+ 21, 21
+ } ;
+
+static yyconst flex_int16_t yy_def[23] =
+ { 0,
+ 22, 1, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 0
+ } ;
+
+static yyconst flex_int16_t yy_nxt[37] =
+ { 0,
+ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 17, 18, 19, 21, 20, 19, 22,
+ 3, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22
+ } ;
+
+static yyconst flex_int16_t yy_chk[37] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 19, 15, 14, 13, 3,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+#line 2 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex --prefix=cmExpr_yy --header-file=cmExprLexer.h -ocmExprLexer.cxx cmExprLexer.in.l
+
+Modify cmExprLexer.cxx:
+ - remove TABs
+ - remove "yyscanner" argument from these methods:
+ yy_fatal_error, cmExpr_yyalloc, cmExpr_yyrealloc, cmExpr_yyfree
+ - remove all YY_BREAK lines occurring right after return statements
+ - change while ( 1 ) to for(;;)
+
+Modify cmExprLexer.h:
+ - remove TABs
+ - remove the yy_init_globals function
+ - remove the block that includes unistd.h
+ - remove #line directives (avoids bogus warning on old Sun)
+
+*/
+
+#include "cmStandardLexer.h"
+
+#include "cmExprParserHelper.h"
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = yyextra->LexInput(buf, max_size); }
+
+/* Include the set of tokens from the parser. */
+#include "cmExprParserTokens.h"
+
+/*--------------------------------------------------------------------------*/
+#line 518 "/home/andy/vtk/CMake-bin/Source/cmExprLexer.cxx"
+
+#define INITIAL 0
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* Holds the entire state of the reentrant scanner. */
+struct yyguts_t
+ {
+
+ /* User-defined. Not touched by flex. */
+ YY_EXTRA_TYPE yyextra_r;
+
+ /* The rest are the same as the globals declared in the non-reentrant
+ scanner. */
+ FILE *yyin_r, *yyout_r;
+ size_t yy_buffer_stack_top; /**< index of top of stack. */
+ 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;
+ char *yy_c_buf_p;
+ int yy_init;
+ int yy_start;
+ int yy_did_buffer_switch_on_eof;
+ int yy_start_stack_ptr;
+ int yy_start_stack_depth;
+ int *yy_start_stack;
+ yy_state_type yy_last_accepting_state;
+ char* yy_last_accepting_cpos;
+
+ int yylineno_r;
+ int yy_flex_debug_r;
+
+ char *yytext_r;
+ int yy_more_flag;
+ int yy_more_len;
+
+ }; /* end struct yyguts_t */
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int cmExpr_yylex_destroy (yyscan_t yyscanner );
+
+int cmExpr_yyget_debug (yyscan_t yyscanner );
+
+void cmExpr_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE cmExpr_yyget_extra (yyscan_t yyscanner );
+
+void cmExpr_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *cmExpr_yyget_in (yyscan_t yyscanner );
+
+void cmExpr_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *cmExpr_yyget_out (yyscan_t yyscanner );
+
+void cmExpr_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+int cmExpr_yyget_leng (yyscan_t yyscanner );
+
+char *cmExpr_yyget_text (yyscan_t yyscanner );
+
+int cmExpr_yyget_lineno (yyscan_t yyscanner );
+
+void cmExpr_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int cmExpr_yywrap (yyscan_t yyscanner );
+#else
+extern int cmExpr_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#ifdef __cplusplus
+static int yyinput (yyscan_t yyscanner );
+#else
+static int input (yyscan_t yyscanner );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int cmExpr_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int cmExpr_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ yy_state_type yy_current_state;
+ char *yy_cp, *yy_bp;
+ int yy_act;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+#line 86 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+
+
+#line 736 "/home/andy/vtk/CMake-bin/Source/cmExprLexer.cxx"
+
+ if ( yyg->yy_init )
+ {
+ yyg->yy_init = 0;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! yyg->yy_start )
+ yyg->yy_start = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ cmExpr_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmExpr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmExpr_yy_load_buffer_state(yyscanner );
+ }
+
+ for(;;) /* loops until end-of-file is reached */
+ {
+ yy_cp = yyg->yy_c_buf_p;
+
+ /* Support of yytext. */
+ *yy_cp = yyg->yy_hold_char;
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yyg->yy_start;
+yy_match:
+ do
+ {
+ 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;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 23 )
+ 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] != 21 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = yyg->yy_hold_char;
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 88 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ yylvalp->Number = atoi(yytext); return exp_NUMBER; }
+case 2:
+YY_RULE_SETUP
+#line 90 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_PLUS; }
+case 3:
+YY_RULE_SETUP
+#line 91 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_MINUS; }
+case 4:
+YY_RULE_SETUP
+#line 92 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_TIMES; }
+case 5:
+YY_RULE_SETUP
+#line 93 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_DIVIDE; }
+case 6:
+YY_RULE_SETUP
+#line 94 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_MOD; }
+case 7:
+YY_RULE_SETUP
+#line 95 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_OR; }
+case 8:
+YY_RULE_SETUP
+#line 96 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_AND; }
+case 9:
+YY_RULE_SETUP
+#line 97 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_XOR; }
+case 10:
+YY_RULE_SETUP
+#line 98 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_NOT; }
+case 11:
+YY_RULE_SETUP
+#line 99 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_SHIFTLEFT; }
+case 12:
+YY_RULE_SETUP
+#line 100 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_SHIFTRIGHT; }
+case 13:
+YY_RULE_SETUP
+#line 101 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_OPENPARENT; }
+case 14:
+YY_RULE_SETUP
+#line 102 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+{ return exp_CLOSEPARENT; }
+case 15:
+YY_RULE_SETUP
+#line 104 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+ECHO;
+ YY_BREAK
+#line 894 "/home/andy/vtk/CMake-bin/Source/cmExprLexer.cxx"
+case YY_STATE_EOF(INITIAL):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = yyg->yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * cmExpr_yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
+
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++yyg->yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yyg->yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yyg->yy_did_buffer_switch_on_eof = 0;
+
+ if ( cmExpr_yywrap(yyscanner ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p =
+ yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yyg->yy_c_buf_p =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+return 0; /* this should not happen but it quiets some compilers */
+} /* end of cmExpr_yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ char *source = yyg->yytext_ptr;
+ int number_to_move, i;
+ int ret_val;
+
+ if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
+
+ else
+ {
+ size_t nuto_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( nuto_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;
+
+ 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;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ cmExpr_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ nuto_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( nuto_read > YY_READ_BUF_SIZE )
+ nuto_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ yyg->yy_n_chars, nuto_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ if ( yyg->yy_n_chars == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ cmExpr_yyrestart(yyin ,yyscanner);
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ yyg->yy_n_chars += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was
+ reached */
+
+ static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
+{
+ yy_state_type yy_current_state;
+ char *yy_cp;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ yy_current_state = yyg->yy_start;
+
+ for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
+ {
+ YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 23 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
+{
+ int yy_is_jam;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ char *yy_cp = yyg->yy_c_buf_p;
+
+ YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 23 )
+ 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 == 22);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (yyscan_t yyscanner)
+#else
+ static int input (yyscan_t yyscanner)
+#endif
+
+{
+ int c;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+
+ if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ /* This was really a NUL. */
+ *yyg->yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ ++yyg->yy_c_buf_p;
+
+ switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ cmExpr_yyrestart(yyin ,yyscanner);
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( cmExpr_yywrap(yyscanner ) )
+ return EOF;
+
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput(yyscanner);
+#else
+ return input(yyscanner);
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
+ *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
+ yyg->yy_hold_char = *++yyg->yy_c_buf_p;
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ * @param yyscanner The scanner object.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void cmExpr_yyrestart (FILE * input_file , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! YY_CURRENT_BUFFER ){
+ cmExpr_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmExpr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmExpr_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
+ cmExpr_yy_load_buffer_state(yyscanner );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ * @param yyscanner The scanner object.
+ */
+ void cmExpr_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * cmExpr_yypop_buffer_state();
+ * cmExpr_yypush_buffer_state(new_buffer);
+ */
+ cmExpr_yyensure_buffer_stack (yyscanner);
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ cmExpr_yy_load_buffer_state(yyscanner );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (cmExpr_yywrap()) processing, but the only time this flag
+ * is looked at is after cmExpr_yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+static void cmExpr_yy_load_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ yyg->yy_hold_char = *yyg->yy_c_buf_p;
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * @param yyscanner The scanner object.
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE cmExpr_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) cmExpr_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmExpr_yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) cmExpr_yyalloc(b->yy_buf_size + 2 ,yyscanner );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmExpr_yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ cmExpr_yy_init_buffer(b,file ,yyscanner);
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with cmExpr_yy_create_buffer()
+ * @param yyscanner The scanner object.
+ */
+ void cmExpr_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ cmExpr_yyfree((void *) b->yy_ch_buf ,yyscanner );
+
+ cmExpr_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 cmExpr_yyrestart() or at EOF.
+ */
+ static void cmExpr_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+
+{
+ int oerrno = errno;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ cmExpr_yy_flush_buffer(b ,yyscanner);
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then cmExpr_yy_init_buffer was _probably_
+ * called from cmExpr_yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ * @param yyscanner The scanner object.
+ */
+ void cmExpr_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ cmExpr_yy_load_buffer_state(yyscanner );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ * @param yyscanner The scanner object.
+ */
+void cmExpr_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (new_buffer == NULL)
+ return;
+
+ cmExpr_yyensure_buffer_stack(yyscanner);
+
+ /* This block is copied from cmExpr_yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ yyg->yy_buffer_stack_top++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from cmExpr_yy_switch_to_buffer. */
+ cmExpr_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ * @param yyscanner The scanner object.
+ */
+void cmExpr_yypop_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ cmExpr_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if (yyg->yy_buffer_stack_top > 0)
+ --yyg->yy_buffer_stack_top;
+
+ if (YY_CURRENT_BUFFER) {
+ cmExpr_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void cmExpr_yyensure_buffer_stack (yyscan_t yyscanner)
+{
+ int nuto_alloc;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (!yyg->yy_buffer_stack) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ nuto_alloc = 1;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmExpr_yyalloc
+ (nuto_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+
+ memset(yyg->yy_buffer_stack, 0, nuto_alloc * sizeof(struct yy_buffer_state*));
+
+ yyg->yy_buffer_stack_max = nuto_alloc;
+ yyg->yy_buffer_stack_top = 0;
+ return;
+ }
+
+ if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ nuto_alloc = yyg->yy_buffer_stack_max + grow_size;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmExpr_yyrealloc
+ (yyg->yy_buffer_stack,
+ nuto_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+
+ /* zero only the new slots.*/
+ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
+ yyg->yy_buffer_stack_max = nuto_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmExpr_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) cmExpr_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmExpr_yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ cmExpr_yy_switch_to_buffer(b ,yyscanner );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to cmExpr_yylex() will
+ * scan from a @e copy of @a yy_str.
+ * @param yy_str a NUL-terminated string to scan
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * cmExpr_yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE cmExpr_yy_scan_string (yyconst char * yy_str , yyscan_t yyscanner)
+{
+
+ return cmExpr_yy_scan_bytes(yy_str,strlen(yy_str) ,yyscanner);
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to cmExpr_yylex() will
+ * scan from a @e copy of @a bytes.
+ * @param bytes the byte buffer to scan
+ * @param len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmExpr_yy_scan_bytes (yyconst char * bytes, int len , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = len + 2;
+ buf = (char *) cmExpr_yyalloc(n ,yyscanner );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmExpr_yy_scan_bytes()" );
+
+ for ( i = 0; i < len; ++i )
+ buf[i] = bytes[i];
+
+ buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = cmExpr_yy_scan_buffer(buf,n ,yyscanner);
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in cmExpr_yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yy_fatal_error (yyconst char* msg , yyscan_t)
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = yyg->yy_hold_char; \
+ yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
+ yyg->yy_hold_char = *yyg->yy_c_buf_p; \
+ *yyg->yy_c_buf_p = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the user-defined data for this scanner.
+ * @param yyscanner The scanner object.
+ */
+YY_EXTRA_TYPE cmExpr_yyget_extra (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyextra;
+}
+
+/** Get the current line number.
+ * @param yyscanner The scanner object.
+ */
+int cmExpr_yyget_lineno (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yylineno;
+}
+
+/** Get the current column number.
+ * @param yyscanner The scanner object.
+ */
+int cmExpr_yyget_column (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yycolumn;
+}
+
+/** Get the input stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmExpr_yyget_in (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyin;
+}
+
+/** Get the output stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmExpr_yyget_out (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyout;
+}
+
+/** Get the length of the current token.
+ * @param yyscanner The scanner object.
+ */
+int cmExpr_yyget_leng (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyleng;
+}
+
+/** Get the current token.
+ * @param yyscanner The scanner object.
+ */
+
+char *cmExpr_yyget_text (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yytext;
+}
+
+/** Set the user-defined data. This data is never touched by the scanner.
+ * @param user_defined The data to be associated with this scanner.
+ * @param yyscanner The scanner object.
+ */
+void cmExpr_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyextra = user_defined ;
+}
+
+/** Set the current line number.
+ * @param line_number The line number to set.
+ * @param yyscanner The scanner object.
+ */
+void cmExpr_yyset_lineno (int line_number , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* lineno is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmExpr_yyset_lineno called with no buffer" , yyscanner);
+
+ yylineno = line_number;
+}
+
+/** Set the current column.
+ * @param column_no The column number to set.
+ * @param yyscanner The scanner object.
+ */
+void cmExpr_yyset_column (int column_no , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* column is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmExpr_yyset_column called with no buffer" , yyscanner);
+
+ yycolumn = column_no;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ * @param yyscanner The scanner object.
+ * @see cmExpr_yy_switch_to_buffer
+ */
+void cmExpr_yyset_in (FILE * in_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyin = in_str ;
+}
+
+void cmExpr_yyset_out (FILE * out_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyout = out_str ;
+}
+
+int cmExpr_yyget_debug (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yy_flex_debug;
+}
+
+void cmExpr_yyset_debug (int bdebug , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yy_flex_debug = bdebug ;
+}
+
+/* Accessor methods for yylval and yylloc */
+
+static int yy_init_globals (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ /* Initialization is the same as for the non-reentrant scanner.
+ This function is called once per scanner lifetime. */
+
+ yyg->yy_buffer_stack = 0;
+ yyg->yy_buffer_stack_top = 0;
+ yyg->yy_buffer_stack_max = 0;
+ yyg->yy_c_buf_p = (char *) 0;
+ yyg->yy_init = 1;
+ yyg->yy_start = 0;
+ yyg->yy_start_stack_ptr = 0;
+ yyg->yy_start_stack_depth = 0;
+ yyg->yy_start_stack = (int *) 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ yyin = stdin;
+ yyout = stdout;
+#else
+ yyin = (FILE *) 0;
+ yyout = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * cmExpr_yylex_init()
+ */
+ return 0;
+}
+
+/* User-visible API */
+
+/* cmExpr_yylex_init is special because it creates the scanner itself, so it is
+ * the ONLY reentrant function that doesn't take the scanner as the last argument.
+ * That's why we explicitly handle the declaration, instead of using our macros.
+ */
+
+int cmExpr_yylex_init(yyscan_t* ptr_yy_globals)
+
+{
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) cmExpr_yyalloc ( sizeof( struct yyguts_t ), NULL );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ memset(*ptr_yy_globals,0,sizeof(struct yyguts_t));
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+/* cmExpr_yylex_destroy is for both reentrant and non-reentrant scanners. */
+int cmExpr_yylex_destroy (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ cmExpr_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ cmExpr_yypop_buffer_state(yyscanner);
+ }
+
+ /* Destroy the stack itself. */
+ cmExpr_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyg->yy_buffer_stack = NULL;
+
+ /* Destroy the start condition stack. */
+ cmExpr_yyfree(yyg->yy_start_stack ,yyscanner );
+ yyg->yy_start_stack = NULL;
+
+ /* Destroy the main struct (reentrant only). */
+ cmExpr_yyfree ( yyscanner , yyscanner );
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+{
+ int i;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+{
+ int n;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *cmExpr_yyalloc (yy_size_t size , yyscan_t)
+{
+ return (void *) malloc( size );
+}
+
+void *cmExpr_yyrealloc (void * ptr, yy_size_t size , yyscan_t)
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void cmExpr_yyfree (void * ptr , yyscan_t)
+{
+ free( (char *) ptr ); /* see cmExpr_yyrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#undef YY_NEW_FILE
+#undef YY_FLUSH_BUFFER
+#undef yy_set_bol
+#undef yy_new_buffer
+#undef yy_set_interactive
+#undef yytext_ptr
+#undef YY_DO_BEFORE_ACTION
+
+#ifdef YY_DECL_IS_OURS
+#undef YY_DECL_IS_OURS
+#undef YY_DECL
+#endif
+#line 104 "/home/andy/vtk/CMake/Source/cmExprLexer.in.l"
+
+
+
diff --git a/Source/cmExprLexer.h b/Source/cmExprLexer.h
new file mode 100644
index 0000000000..03b36cec55
--- /dev/null
+++ b/Source/cmExprLexer.h
@@ -0,0 +1,334 @@
+/*============================================================================
+ 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 cmExpr_yyHEADER_H
+#define cmExpr_yyHEADER_H 1
+#define cmExpr_yyIN_HEADER 1
+
+
+
+
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 31
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+int cmExpr_yylex_init (yyscan_t* scanner);
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef unsigned int yy_size_t;
+#endif
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int 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
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+void cmExpr_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void cmExpr_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,
+ yyscan_t yyscanner );
+YY_BUFFER_STATE cmExpr_yy_create_buffer (FILE *file,int size ,
+ yyscan_t yyscanner );
+void cmExpr_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmExpr_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmExpr_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,
+ yyscan_t yyscanner );
+void cmExpr_yypop_buffer_state (yyscan_t yyscanner );
+
+YY_BUFFER_STATE cmExpr_yy_scan_buffer (char *base,yy_size_t size ,
+ yyscan_t yyscanner );
+YY_BUFFER_STATE cmExpr_yy_scan_string (yyconst char *yy_str ,
+ yyscan_t yyscanner );
+YY_BUFFER_STATE cmExpr_yy_scan_bytes (yyconst char *bytes,int len ,
+ yyscan_t yyscanner );
+
+void *cmExpr_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *cmExpr_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void cmExpr_yyfree (void * ,yyscan_t yyscanner );
+
+/* Begin user sect3 */
+
+#define cmExpr_yywrap(n) 1
+#define YY_SKIP_YYWRAP
+
+#define yytext_ptr yytext_r
+
+#ifdef YY_HEADER_EXPORT_START_CONDITIONS
+#define INITIAL 0
+
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int cmExpr_yylex_destroy (yyscan_t yyscanner );
+
+int cmExpr_yyget_debug (yyscan_t yyscanner );
+
+void cmExpr_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE cmExpr_yyget_extra (yyscan_t yyscanner );
+
+void cmExpr_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *cmExpr_yyget_in (yyscan_t yyscanner );
+
+void cmExpr_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *cmExpr_yyget_out (yyscan_t yyscanner );
+
+void cmExpr_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+int cmExpr_yyget_leng (yyscan_t yyscanner );
+
+char *cmExpr_yyget_text (yyscan_t yyscanner );
+
+int cmExpr_yyget_lineno (yyscan_t yyscanner );
+
+void cmExpr_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int cmExpr_yywrap (yyscan_t yyscanner );
+#else
+extern int cmExpr_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int cmExpr_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int cmExpr_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* yy_get_previous_state - get the state just before the EOB char was
+ reached */
+
+#undef YY_NEW_FILE
+#undef YY_FLUSH_BUFFER
+#undef yy_set_bol
+#undef yy_new_buffer
+#undef yy_set_interactive
+#undef yytext_ptr
+#undef YY_DO_BEFORE_ACTION
+
+#ifdef YY_DECL_IS_OURS
+#undef YY_DECL_IS_OURS
+#undef YY_DECL
+#endif
+
+
+
+
+#undef cmExpr_yyIN_HEADER
+#endif /* cmExpr_yyHEADER_H */
diff --git a/Source/cmExprLexer.in.l b/Source/cmExprLexer.in.l
new file mode 100644
index 0000000000..febd244fe1
--- /dev/null
+++ b/Source/cmExprLexer.in.l
@@ -0,0 +1,74 @@
+%{
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex --prefix=cmExpr_yy --header-file=cmExprLexer.h -ocmExprLexer.cxx cmExprLexer.in.l
+
+Modify cmExprLexer.cxx:
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - remove "yyscanner" argument from these methods:
+ yy_fatal_error, cmExpr_yyalloc, cmExpr_yyrealloc, cmExpr_yyfree
+ - remove all YY_BREAK lines occurring right after return statements
+ - change while ( 1 ) to for(;;)
+
+Modify cmExprLexer.h:
+ - remove TABs
+ - remove the yy_init_globals function
+ - remove the block that includes unistd.h
+ - remove #line directives (avoids bogus warning on old Sun)
+
+*/
+
+#include "cmStandardLexer.h"
+
+#include "cmExprParserHelper.h"
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = yyextra->LexInput(buf, max_size); }
+
+/* Include the set of tokens from the parser. */
+#include "cmExprParserTokens.h"
+
+/*--------------------------------------------------------------------------*/
+%}
+
+%option reentrant
+%option noyywrap
+%pointer
+
+%%
+
+[0-9][0-9]* { yylvalp->Number = atoi(yytext); return exp_NUMBER; }
+
+"+" { return exp_PLUS; }
+"-" { return exp_MINUS; }
+"*" { return exp_TIMES; }
+"/" { return exp_DIVIDE; }
+"%" { return exp_MOD; }
+"\|" { return exp_OR; }
+"&" { return exp_AND; }
+"^" { return exp_XOR; }
+"~" { return exp_NOT; }
+"<<" { return exp_SHIFTLEFT; }
+">>" { return exp_SHIFTRIGHT; }
+"(" { return exp_OPENPARENT; }
+")" { return exp_CLOSEPARENT; }
+
+%%
diff --git a/Source/cmExprParser.cxx b/Source/cmExprParser.cxx
new file mode 100644
index 0000000000..77880c0a35
--- /dev/null
+++ b/Source/cmExprParser.cxx
@@ -0,0 +1,1433 @@
+/* A Bison parser, made by GNU Bison 1.875d. */
+
+/* Skeleton parser for Yacc-like parsing with Bison, Copyright (C) 1984,
+ 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* As a special exception, when this file is copied by Bison into a
+ Bison output file, you may use that output file without restriction.
+ This special exception was added by the Free Software Foundation
+ in version 1.24 of Bison. */
+
+/* Written by Richard Stallman by simplifying the original so called
+ ``semantic'' parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* turn off some warning as this is generated code */
+#if defined(_MSC_VER)
+# pragma warning ( disable : 4702 ) /* unreachable code */
+#endif
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 1
+
+/* Using locations. */
+#define YYLSP_NEEDED 0
+
+/* If NAME_PREFIX is specified substitute the variables and functions
+ names. */
+#define yyparse cmExpr_yyparse
+#define yylex cmExpr_yylex
+#define yyerror cmExpr_yyerror
+#define yylval cmExpr_yylval
+#define yychar cmExpr_yychar
+#define yydebug cmExpr_yydebug
+#define yynerrs cmExpr_yynerrs
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ exp_PLUS = 258,
+ exp_MINUS = 259,
+ exp_TIMES = 260,
+ exp_DIVIDE = 261,
+ exp_MOD = 262,
+ exp_SHIFTLEFT = 263,
+ exp_SHIFTRIGHT = 264,
+ exp_OPENPARENT = 265,
+ exp_CLOSEPARENT = 266,
+ exp_OR = 267,
+ exp_AND = 268,
+ exp_XOR = 269,
+ exp_NOT = 270,
+ exp_NUMBER = 271
+ };
+#endif
+#define exp_PLUS 258
+#define exp_MINUS 259
+#define exp_TIMES 260
+#define exp_DIVIDE 261
+#define exp_MOD 262
+#define exp_SHIFTLEFT 263
+#define exp_SHIFTRIGHT 264
+#define exp_OPENPARENT 265
+#define exp_CLOSEPARENT 266
+#define exp_OR 267
+#define exp_AND 268
+#define exp_XOR 269
+#define exp_NOT 270
+#define exp_NUMBER 271
+
+
+
+
+/* Copy the first part of user declarations. */
+
+
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run bison like this:
+
+ bison --yacc --name-prefix=cmExpr_yy --defines=cmExprParserTokens.h
+ -ocmExprParser.cxx cmExprParser.y
+
+Modify cmExprParser.cxx:
+ - remove TABs
+ - add __HP_aCC to the #if test for yyerrorlab warning suppression
+
+*/
+
+/* Configure the parser to use a lexer object. */
+#define YYPARSE_PARAM yyscanner
+#define YYLEX_PARAM yyscanner
+#define YYERROR_VERBOSE 1
+#define cmExpr_yyerror(x) \
+ cmExprError(yyscanner, x)
+#define yyGetParser (cmExpr_yyget_extra(yyscanner))
+
+/*-------------------------------------------------------------------------*/
+#include "cmExprParserHelper.h" /* Interface to parser object. */
+#include "cmExprLexer.h" /* Interface to lexer object. */
+#include "cmExprParserTokens.h" /* Need YYSTYPE for YY_DECL. */
+
+#include <math.h>
+
+/* Forward declare the lexer entry point. */
+YY_DECL;
+
+/* Internal utility functions. */
+static void cmExprError(yyscan_t yyscanner, const char* message);
+
+#define YYDEBUG 1
+//#define YYMAXDEPTH 100000
+//#define YYINITDEPTH 10000
+
+
+/* Disable some warnings in the generated code. */
+#ifdef __BORLANDC__
+# pragma warn -8004 /* Variable assigned a value that is not used. */
+# pragma warn -8008 /* condition always returns true */
+# pragma warn -8060 /* possibly incorrect assignment */
+# pragma warn -8066 /* unreachable code */
+#endif
+#ifdef _MSC_VER
+# pragma warning (disable: 4102) /* Unused goto label. */
+# pragma warning (disable: 4065) /* Switch statement contains default but
+ no case. */
+#endif
+
+
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
+typedef int YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+/* Copy the second part of user declarations. */
+
+
+/* Line 214 of yacc.c. */
+
+
+#if ! defined (yyoverflow) || YYERROR_VERBOSE
+
+# ifndef YYFREE
+# define YYFREE free
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# endif
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# define YYSTACK_ALLOC alloca
+# endif
+# else
+# if defined (alloca) || defined (_ALLOCA_H)
+# define YYSTACK_ALLOC alloca
+# else
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's `empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# else
+# if defined (__STDC__) || defined (__cplusplus)
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# endif
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# endif
+#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
+
+
+#if (! defined (yyoverflow) \
+ && (! defined (__cplusplus) \
+ || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ short int yyss;
+ YYSTYPE yyvs;
+ };
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined (__GNUC__) && 1 < __GNUC__
+# define YYCOPY(To, From, Count) \
+ __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# else
+# define YYCOPY(To, From, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (To)[yyi] = (From)[yyi]; \
+ } \
+ while (0)
+# endif
+# endif
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack, Stack, yysize); \
+ Stack = &yyptr->Stack; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (0)
+
+#endif
+
+#if defined (__STDC__) || defined (__cplusplus)
+ typedef signed char yysigned_char;
+#else
+ typedef short int yysigned_char;
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 12
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 25
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 17
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 9
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 20
+/* YYNRULES -- Number of states. */
+#define YYNSTATES 34
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 271
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const unsigned char yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+ YYRHS. */
+static const unsigned char yyprhs[] =
+{
+ 0, 0, 3, 5, 7, 11, 13, 17, 19, 23,
+ 25, 29, 33, 35, 39, 43, 45, 49, 53, 57,
+ 59
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yysigned_char yyrhs[] =
+{
+ 18, 0, -1, 19, -1, 20, -1, 19, 12, 20,
+ -1, 21, -1, 20, 14, 21, -1, 22, -1, 21,
+ 13, 22, -1, 23, -1, 22, 8, 23, -1, 22,
+ 9, 23, -1, 24, -1, 23, 3, 24, -1, 23,
+ 4, 24, -1, 25, -1, 24, 5, 25, -1, 24,
+ 6, 25, -1, 24, 7, 25, -1, 16, -1, 10,
+ 19, 11, -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const unsigned char yyrline[] =
+{
+ 0, 94, 94, 100, 103, 107, 110, 114, 117, 121,
+ 124, 127, 132, 135, 138, 142, 145, 148, 151, 155,
+ 158
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE
+/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "$end", "error", "$undefined", "exp_PLUS", "exp_MINUS", "exp_TIMES",
+ "exp_DIVIDE", "exp_MOD", "exp_SHIFTLEFT", "exp_SHIFTRIGHT",
+ "exp_OPENPARENT", "exp_CLOSEPARENT", "exp_OR", "exp_AND", "exp_XOR",
+ "exp_NOT", "exp_NUMBER", "$accept", "Start", "exp", "bitwiseor",
+ "bitwisexor", "bitwiseand", "shift", "term", "factor", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+ token YYLEX-NUM. */
+static const unsigned short int yytoknum[] =
+{
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, 271
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const unsigned char yyr1[] =
+{
+ 0, 17, 18, 19, 19, 20, 20, 21, 21, 22,
+ 22, 22, 23, 23, 23, 24, 24, 24, 24, 25,
+ 25
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
+static const unsigned char yyr2[] =
+{
+ 0, 2, 1, 1, 3, 1, 3, 1, 3, 1,
+ 3, 3, 1, 3, 3, 1, 3, 3, 3, 1,
+ 3
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+ STATE-NUM when YYTABLE doesn't specify something else to do. Zero
+ means the default is an error. */
+static const unsigned char yydefact[] =
+{
+ 0, 0, 19, 0, 2, 3, 5, 7, 9, 12,
+ 15, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 20, 4, 6, 8, 10, 11, 13,
+ 14, 16, 17, 18
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yysigned_char yydefgoto[] =
+{
+ -1, 3, 4, 5, 6, 7, 8, 9, 10
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+#define YYPACT_NINF -14
+static const yysigned_char yypact[] =
+{
+ -10, -10, -14, 18, 7, 6, 8, 2, 1, -4,
+ -14, 3, -14, -10, -10, -10, -10, -10, -10, -10,
+ -10, -10, -10, -14, 6, 8, 2, 1, 1, -4,
+ -4, -14, -14, -14
+};
+
+/* YYPGOTO[NTERM-NUM]. */
+static const yysigned_char yypgoto[] =
+{
+ -14, -14, 21, 10, 11, 9, 0, -6, -13
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule which
+ number is the opposite. If zero, do what YYDEFACT says.
+ If YYTABLE_NINF, syntax error. */
+#define YYTABLE_NINF -1
+static const unsigned char yytable[] =
+{
+ 1, 20, 21, 22, 18, 19, 2, 31, 32, 33,
+ 16, 17, 29, 30, 23, 13, 27, 28, 12, 13,
+ 14, 15, 11, 24, 26, 25
+};
+
+static const unsigned char yycheck[] =
+{
+ 10, 5, 6, 7, 3, 4, 16, 20, 21, 22,
+ 8, 9, 18, 19, 11, 12, 16, 17, 0, 12,
+ 14, 13, 1, 13, 15, 14
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const unsigned char yystos[] =
+{
+ 0, 10, 16, 18, 19, 20, 21, 22, 23, 24,
+ 25, 19, 0, 12, 14, 13, 8, 9, 3, 4,
+ 5, 6, 7, 11, 20, 21, 22, 23, 23, 24,
+ 24, 25, 25, 25
+};
+
+#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
+# define YYSIZE_T __SIZE_TYPE__
+#endif
+#if ! defined (YYSIZE_T) && defined (size_t)
+# define YYSIZE_T size_t
+#endif
+#if ! defined (YYSIZE_T)
+# if defined (__STDC__) || defined (__cplusplus)
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# endif
+#endif
+#if ! defined (YYSIZE_T)
+# define YYSIZE_T unsigned int
+#endif
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+/* Like YYERROR except do call yyerror. This remains here temporarily
+ to ease the transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. */
+
+#define YYFAIL goto yyerrlab
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ yytoken = YYTRANSLATE (yychar); \
+ YYPOPSTACK; \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror ("syntax error: cannot back up");\
+ YYERROR; \
+ } \
+while (0)
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+/* YYLLOC_DEFAULT -- Compute the default location (before the actions
+ are run). */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ ((Current).first_line = (Rhs)[1].first_line, \
+ (Current).first_column = (Rhs)[1].first_column, \
+ (Current).last_line = (Rhs)[N].last_line, \
+ (Current).last_column = (Rhs)[N].last_column)
+#endif
+
+/* YYLEX -- calling `yylex' with the right arguments. */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval)
+#endif
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (0)
+
+# define YYDSYMPRINT(Args) \
+do { \
+ if (yydebug) \
+ yysymprint Args; \
+} while (0)
+
+# define YYDSYMPRINTF(Title, Token, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yysymprint (stderr, \
+ Token, Value); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (0)
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yy_stack_print (short int *bottom, short int *top)
+#else
+static void
+yy_stack_print (bottom, top)
+ short int *bottom;
+ short int *top;
+#endif
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (/* Nothing. */; bottom <= top; ++bottom)
+ YYFPRINTF (stderr, " %d", *bottom);
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (0)
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yy_reduce_print (int yyrule)
+#else
+static void
+yy_reduce_print (yyrule)
+ int yyrule;
+#endif
+{
+ int yyi;
+ unsigned int yylno = yyrline[yyrule];
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
+ yyrule - 1, yylno);
+ /* Print the symbols being reduced, and their result. */
+ for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
+ YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
+ YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (Rule); \
+} while (0)
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YYDSYMPRINT(Args)
+# define YYDSYMPRINTF(Title, Token, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#if defined (YYMAXDEPTH) && YYMAXDEPTH == 0
+# undef YYMAXDEPTH
+#endif
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined (__GLIBC__) && defined (_STRING_H)
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+static YYSIZE_T
+# if defined (__STDC__) || defined (__cplusplus)
+yystrlen (const char *yystr)
+# else
+yystrlen (yystr)
+ const char *yystr;
+# endif
+{
+ const char *yys = yystr;
+
+ while (*yys++ != '\0')
+ continue;
+
+ return yys - yystr - 1;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+static char *
+# if defined (__STDC__) || defined (__cplusplus)
+yystpcpy (char *yydest, const char *yysrc)
+# else
+yystpcpy (yydest, yysrc)
+ char *yydest;
+ const char *yysrc;
+# endif
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+#endif /* !YYERROR_VERBOSE */
+
+
+
+#if YYDEBUG
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yysymprint (yyoutput, yytype, yyvaluep)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE *yyvaluep;
+#endif
+{
+ /* Pacify ``unused variable'' warnings. */
+ (void) yyvaluep;
+
+ if (yytype < YYNTOKENS)
+ {
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+# ifdef YYPRINT
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# endif
+ }
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+ switch (yytype)
+ {
+ default:
+ break;
+ }
+ YYFPRINTF (yyoutput, ")");
+}
+
+#endif /* ! YYDEBUG */
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yydestruct (int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yydestruct (yytype, yyvaluep)
+ int yytype;
+ YYSTYPE *yyvaluep;
+#endif
+{
+ /* Pacify ``unused variable'' warnings. */
+ (void) yyvaluep;
+
+ switch (yytype)
+ {
+
+ default:
+ break;
+ }
+}
+
+
+/* Prevent warnings from -Wmissing-prototypes. */
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM);
+# else
+int yyparse ();
+# endif
+#else /* ! YYPARSE_PARAM */
+#if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM)
+# else
+int yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+# endif
+#else /* ! YYPARSE_PARAM */
+#if defined (__STDC__) || defined (__cplusplus)
+int
+yyparse (void)
+#else
+int
+yyparse ()
+
+#endif
+#endif
+{
+ /* The lookahead symbol. */
+int yychar;
+
+/* The semantic value of the lookahead symbol. */
+YYSTYPE yylval;
+
+/* Number of syntax errors so far. */
+int yynerrs;
+
+ int yystate;
+ int yyn;
+ int yyresult;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+ /* Lookahead token as an internal (translated) token number. */
+ int yytoken = 0;
+
+ /* Three stacks and their tools:
+ `yyss': related to states,
+ `yyvs': related to semantic values,
+ `yyls': related to locations.
+
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ short int yyssa[YYINITDEPTH];
+ short int *yyss = yyssa;
+ short int *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs = yyvsa;
+ YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK (yyvsp--, yyssp--)
+
+ YYSIZE_T yystacksize = YYINITDEPTH;
+
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+
+ /* When reducing, the number of symbols on the RHS of the reduced
+ rule. */
+ int yylen;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss;
+ yyvsp = yyvs;
+
+
+ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. so pushing a state here evens the stacks.
+ */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ short int *yyss1 = yyss;
+
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow ("parser stack overflow",
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),
+
+ &yystacksize);
+
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyoverflowlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyoverflowlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ short int *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyoverflowlab;
+ YYSTACK_RELOCATE (yyss);
+ YYSTACK_RELOCATE (yyvs);
+
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+/* Do appropriate processing given the current state. */
+/* Read a lookahead token if we need one and don't already have one. */
+/* yyresume: */
+
+ /* First try to decide what to do without reference to lookahead token. */
+
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Shift the lookahead token. */
+ YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
+
+ /* Discard the token being shifted unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ *++yyvsp = yylval;
+
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 2:
+
+ {
+ yyGetParser->SetResult(yyvsp[0].Number);
+}
+ break;
+
+ case 3:
+
+ {yyval.Number = yyvsp[0].Number;}
+ break;
+
+ case 4:
+
+ {yyval.Number = yyvsp[-2].Number | yyvsp[0].Number;}
+ break;
+
+ case 5:
+
+ {yyval.Number = yyvsp[0].Number;}
+ break;
+
+ case 6:
+
+ {yyval.Number = yyvsp[-2].Number ^ yyvsp[0].Number;}
+ break;
+
+ case 7:
+
+ {yyval.Number = yyvsp[0].Number;}
+ break;
+
+ case 8:
+
+ {yyval.Number = yyvsp[-2].Number & yyvsp[0].Number;}
+ break;
+
+ case 9:
+
+ {yyval.Number = yyvsp[0].Number;}
+ break;
+
+ case 10:
+
+ {yyval.Number = yyvsp[-2].Number << yyvsp[0].Number;}
+ break;
+
+ case 11:
+
+ {yyval.Number = yyvsp[-2].Number >> yyvsp[0].Number;}
+ break;
+
+ case 12:
+
+ {yyval.Number = yyvsp[0].Number;}
+ break;
+
+ case 13:
+
+ {yyval.Number = yyvsp[-2].Number + yyvsp[0].Number;}
+ break;
+
+ case 14:
+
+ {yyval.Number = yyvsp[-2].Number - yyvsp[0].Number;}
+ break;
+
+ case 15:
+
+ {yyval.Number = yyvsp[0].Number;}
+ break;
+
+ case 16:
+
+ {yyval.Number = yyvsp[-2].Number * yyvsp[0].Number;}
+ break;
+
+ case 17:
+
+ {yyval.Number = yyvsp[-2].Number / yyvsp[0].Number;}
+ break;
+
+ case 18:
+
+ {yyval.Number = yyvsp[-2].Number % yyvsp[0].Number;}
+ break;
+
+ case 19:
+
+ {yyval.Number = yyvsp[0].Number;}
+ break;
+
+ case 20:
+
+ {yyval.Number = yyvsp[-1].Number;}
+ break;
+
+
+ }
+
+/* Line 1010 of yacc.c. */
+
+
+ yyvsp -= yylen;
+ yyssp -= yylen;
+
+
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+
+
+ /* Now `shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if YYERROR_VERBOSE
+ yyn = yypact[yystate];
+
+ if (YYPACT_NINF < yyn && yyn < YYLAST)
+ {
+ YYSIZE_T yysize = 0;
+ int yytype = YYTRANSLATE (yychar);
+ const char* yyprefix;
+ char *yymsg;
+ int yyx;
+
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yycount = 0;
+
+ yyprefix = ", expecting ";
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+ {
+ yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
+ yycount += 1;
+ if (yycount == 5)
+ {
+ yysize = 0;
+ break;
+ }
+ }
+ yysize += (sizeof ("syntax error, unexpected ")
+ + yystrlen (yytname[yytype]));
+ yymsg = (char *) YYSTACK_ALLOC (yysize);
+ if (yymsg != 0)
+ {
+ char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
+ yyp = yystpcpy (yyp, yytname[yytype]);
+
+ if (yycount < 5)
+ {
+ yyprefix = ", expecting ";
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+ {
+ yyp = yystpcpy (yyp, yyprefix);
+ yyp = yystpcpy (yyp, yytname[yyx]);
+ yyprefix = " or ";
+ }
+ }
+ yyerror (yymsg);
+ YYSTACK_FREE (yymsg);
+ }
+ else
+ yyerror ("syntax error; also virtual memory exhausted");
+ }
+ else
+#endif /* YYERROR_VERBOSE */
+ yyerror ("syntax error");
+ }
+
+
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* If at end of input, pop the error token,
+ then the rest of the stack, then return failure. */
+ if (yychar == YYEOF)
+ for (;;)
+ {
+ YYPOPSTACK;
+ if (yyssp == yyss)
+ YYABORT;
+ YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+ yydestruct (yystos[*yyssp], yyvsp);
+ }
+ }
+ else
+ {
+ YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
+ yydestruct (yytoken, &yylval);
+ yychar = YYEMPTY;
+
+ }
+ }
+
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+#if defined( __GNUC__ ) || defined(__HP_aCC)
+ /* Pacify GCC when the user code never invokes YYERROR and the label
+ yyerrorlab therefore never appears in user code. */
+ if (0)
+ goto yyerrorlab;
+#endif
+
+ yyvsp -= yylen;
+ yyssp -= yylen;
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (yyn != YYPACT_NINF)
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+ YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+ yydestruct (yystos[yystate], yyvsp);
+ YYPOPSTACK;
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ YYDPRINTF ((stderr, "Shifting error token, "));
+
+ *++yyvsp = yylval;
+
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#ifndef yyoverflow
+/*----------------------------------------------.
+| yyoverflowlab -- parser overflow comes here. |
+`----------------------------------------------*/
+yyoverflowlab:
+ yyerror ("parser stack overflow");
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+ return yyresult;
+}
+
+
+
+
+/* End of grammar */
+
+/*--------------------------------------------------------------------------*/
+void cmExprError(yyscan_t yyscanner, const char* message)
+{
+ yyGetParser->Error(message);
+}
+
+
diff --git a/Source/cmExprParser.y b/Source/cmExprParser.y
new file mode 100644
index 0000000000..12c2e48062
--- /dev/null
+++ b/Source/cmExprParser.y
@@ -0,0 +1,170 @@
+%{
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run bison like this:
+
+ bison --yacc --name-prefix=cmExpr_yy --defines=cmExprParserTokens.h -ocmExprParser.cxx cmExprParser.y
+
+Modify cmExprParser.cxx:
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - add __HP_aCC to the #if test for yyerrorlab warning suppression
+
+*/
+
+/* Configure the parser to use a lexer object. */
+#define YYPARSE_PARAM yyscanner
+#define YYLEX_PARAM yyscanner
+#define YYERROR_VERBOSE 1
+#define cmExpr_yyerror(x) \
+ cmExprError(yyscanner, x)
+#define yyGetParser (cmExpr_yyget_extra(yyscanner))
+
+/*-------------------------------------------------------------------------*/
+#include "cmExprParserHelper.h" /* Interface to parser object. */
+#include "cmExprLexer.h" /* Interface to lexer object. */
+#include "cmExprParserTokens.h" /* Need YYSTYPE for YY_DECL. */
+
+#include <math.h>
+
+/* Forward declare the lexer entry point. */
+YY_DECL;
+
+/* Internal utility functions. */
+static void cmExprError(yyscan_t yyscanner, const char* message);
+
+#define YYDEBUG 1
+//#define YYMAXDEPTH 100000
+//#define YYINITDEPTH 10000
+
+
+/* Disable some warnings in the generated code. */
+#ifdef __BORLANDC__
+# pragma warn -8004 /* Variable assigned a value that is not used. */
+# pragma warn -8008 /* condition always returns true */
+# pragma warn -8060 /* possibly incorrect assignment */
+# pragma warn -8066 /* unreachable code */
+#endif
+#ifdef _MSC_VER
+# pragma warning (disable: 4102) /* Unused goto label. */
+# pragma warning (disable: 4065) /* Switch statement contains default but no case. */
+#endif
+%}
+
+/* Generate a reentrant parser object. */
+%pure_parser
+
+/*-------------------------------------------------------------------------*/
+/* Tokens */
+%token exp_PLUS
+%token exp_MINUS
+%token exp_TIMES
+%token exp_DIVIDE
+%token exp_MOD
+%token exp_SHIFTLEFT
+%token exp_SHIFTRIGHT
+%token exp_OPENPARENT
+%token exp_CLOSEPARENT
+%token exp_OR;
+%token exp_AND;
+%token exp_XOR;
+%token exp_NOT;
+%token exp_NUMBER;
+
+/*-------------------------------------------------------------------------*/
+/* grammar */
+%%
+
+
+Start:
+exp
+{
+ yyGetParser->SetResult($<Number>1);
+}
+
+exp:
+bitwiseor
+{$<Number>$ = $<Number>1;}
+|
+exp exp_OR bitwiseor
+{$<Number>$ = $<Number>1 | $<Number>3;}
+
+bitwiseor:
+bitwisexor
+{$<Number>$ = $<Number>1;}
+|
+bitwiseor exp_XOR bitwisexor
+{$<Number>$ = $<Number>1 ^ $<Number>3;}
+
+bitwisexor:
+bitwiseand
+{$<Number>$ = $<Number>1;}
+|
+bitwisexor exp_AND bitwiseand
+{$<Number>$ = $<Number>1 & $<Number>3;}
+
+bitwiseand:
+shift
+{$<Number>$ = $<Number>1;}
+|
+bitwiseand exp_SHIFTLEFT shift
+{$<Number>$ = $<Number>1 << $<Number>3;}
+|
+bitwiseand exp_SHIFTRIGHT shift
+{$<Number>$ = $<Number>1 >> $<Number>3;}
+
+
+shift:
+term
+{$<Number>$ = $<Number>1;}
+|
+shift exp_PLUS term
+{$<Number>$ = $<Number>1 + $<Number>3;}
+|
+shift exp_MINUS term
+{$<Number>$ = $<Number>1 - $<Number>3;}
+
+term:
+factor
+{$<Number>$ = $<Number>1;}
+|
+term exp_TIMES factor
+{$<Number>$ = $<Number>1 * $<Number>3;}
+|
+term exp_DIVIDE factor
+{$<Number>$ = $<Number>1 / $<Number>3;}
+|
+term exp_MOD factor
+{$<Number>$ = $<Number>1 % $<Number>3;}
+
+factor:
+exp_NUMBER
+{$<Number>$ = $<Number>1;}
+|
+exp_OPENPARENT exp exp_CLOSEPARENT
+{$<Number>$ = $<Number>2;}
+;
+
+
+%%
+/* End of grammar */
+
+/*--------------------------------------------------------------------------*/
+void cmExprError(yyscan_t yyscanner, const char* message)
+{
+ yyGetParser->Error(message);
+}
+
diff --git a/Source/cmExprParserHelper.cxx b/Source/cmExprParserHelper.cxx
new file mode 100644
index 0000000000..cc35f84cd6
--- /dev/null
+++ b/Source/cmExprParserHelper.cxx
@@ -0,0 +1,112 @@
+/*============================================================================
+ 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 "cmExprParserHelper.h"
+
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+
+#include "cmExprLexer.h"
+
+int cmExpr_yyparse( yyscan_t yyscanner );
+//
+cmExprParserHelper::cmExprParserHelper()
+{
+ this->FileLine = -1;
+ this->FileName = 0;
+}
+
+
+cmExprParserHelper::~cmExprParserHelper()
+{
+ this->CleanupParser();
+}
+
+int cmExprParserHelper::ParseString(const char* str, int verb)
+{
+ if ( !str)
+ {
+ return 0;
+ }
+ //printf("Do some parsing: %s\n", str);
+
+ this->Verbose = verb;
+ this->InputBuffer = str;
+ this->InputBufferPos = 0;
+ this->CurrentLine = 0;
+
+ this->Result = 0;
+
+ yyscan_t yyscanner;
+ cmExpr_yylex_init(&yyscanner);
+ cmExpr_yyset_extra(this, yyscanner);
+ int res = cmExpr_yyparse(yyscanner);
+ cmExpr_yylex_destroy(yyscanner);
+ if ( res != 0 )
+ {
+ //str << "CAL_Parser returned: " << res << std::endl;
+ //std::cerr << "When parsing: [" << str << "]" << std::endl;
+ return 0;
+ }
+
+ this->CleanupParser();
+
+ if ( Verbose )
+ {
+ std::cerr << "Expanding [" << str << "] produced: ["
+ << this->Result << "]" << std::endl;
+ }
+ return 1;
+}
+
+void cmExprParserHelper::CleanupParser()
+{
+}
+
+int cmExprParserHelper::LexInput(char* buf, int maxlen)
+{
+ //std::cout << "JPLexInput ";
+ //std::cout.write(buf, maxlen);
+ //std::cout << std::endl;
+ if ( maxlen < 1 )
+ {
+ return 0;
+ }
+ if ( this->InputBufferPos < this->InputBuffer.size() )
+ {
+ buf[0] = this->InputBuffer[ this->InputBufferPos++ ];
+ if ( buf[0] == '\n' )
+ {
+ this->CurrentLine ++;
+ }
+ return(1);
+ }
+ else
+ {
+ buf[0] = '\n';
+ return( 0 );
+ }
+}
+
+void cmExprParserHelper::Error(const char* str)
+{
+ unsigned long pos = static_cast<unsigned long>(this->InputBufferPos);
+ cmOStringStream ostr;
+ ostr << str << " (" << pos << ")";
+ this->ErrorString = ostr.str();
+}
+
+void cmExprParserHelper::SetResult(int value)
+{
+ this->Result = value;
+}
+
+
diff --git a/Source/cmExprParserHelper.h b/Source/cmExprParserHelper.h
new file mode 100644
index 0000000000..8d6b2cd479
--- /dev/null
+++ b/Source/cmExprParserHelper.h
@@ -0,0 +1,71 @@
+/*============================================================================
+ 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 cmExprParserHelper_h
+#define cmExprParserHelper_h
+
+#include "cmStandardIncludes.h"
+
+#define YYSTYPE cmExprParserHelper::ParserType
+#define YYSTYPE_IS_DECLARED
+#define YY_EXTRA_TYPE cmExprParserHelper*
+#define YY_DECL int cmExpr_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
+
+/** \class cmExprParserHelper
+ * \brief Helper class for parsing java source files
+ *
+ * Finds dependencies for java file and list of outputs
+ */
+
+class cmMakefile;
+
+class cmExprParserHelper
+{
+public:
+ typedef struct {
+ int Number;
+ } ParserType;
+
+ cmExprParserHelper();
+ ~cmExprParserHelper();
+
+ int ParseString(const char* str, int verb);
+
+ int LexInput(char* buf, int maxlen);
+ void Error(const char* str);
+
+ void SetResult(int value);
+
+ int GetResult() { return this->Result; }
+
+ const char* GetError() { return this->ErrorString.c_str(); }
+
+private:
+ std::string::size_type InputBufferPos;
+ std::string InputBuffer;
+ std::vector<char> OutputBuffer;
+ int CurrentLine;
+ int Verbose;
+
+ void Print(const char* place, const char* str);
+
+ void CleanupParser();
+
+ int Result;
+ const char* FileName;
+ long FileLine;
+ std::string ErrorString;
+};
+
+#endif
+
+
+
diff --git a/Source/cmExprParserTokens.h b/Source/cmExprParserTokens.h
new file mode 100644
index 0000000000..0309c09a12
--- /dev/null
+++ b/Source/cmExprParserTokens.h
@@ -0,0 +1,76 @@
+/* A Bison parser, made by GNU Bison 1.875d. */
+
+/* Skeleton parser for Yacc-like parsing with Bison, Copyright (C) 1984,
+ 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* As a special exception, when this file is copied by Bison into a
+ Bison output file, you may use that output file without restriction.
+ This special exception was added by the Free Software Foundation
+ in version 1.24 of Bison. */
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ exp_PLUS = 258,
+ exp_MINUS = 259,
+ exp_TIMES = 260,
+ exp_DIVIDE = 261,
+ exp_MOD = 262,
+ exp_SHIFTLEFT = 263,
+ exp_SHIFTRIGHT = 264,
+ exp_OPENPARENT = 265,
+ exp_CLOSEPARENT = 266,
+ exp_OR = 267,
+ exp_AND = 268,
+ exp_XOR = 269,
+ exp_NOT = 270,
+ exp_NUMBER = 271
+ };
+#endif
+#define exp_PLUS 258
+#define exp_MINUS 259
+#define exp_TIMES 260
+#define exp_DIVIDE 261
+#define exp_MOD 262
+#define exp_SHIFTLEFT 263
+#define exp_SHIFTRIGHT 264
+#define exp_OPENPARENT 265
+#define exp_CLOSEPARENT 266
+#define exp_OR 267
+#define exp_AND 268
+#define exp_XOR 269
+#define exp_NOT 270
+#define exp_NUMBER 271
+
+
+
+
+#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
+typedef int YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+
+
diff --git a/Source/cmExternalMakefileProjectGenerator.cxx b/Source/cmExternalMakefileProjectGenerator.cxx
new file mode 100644
index 0000000000..9264671a36
--- /dev/null
+++ b/Source/cmExternalMakefileProjectGenerator.cxx
@@ -0,0 +1,70 @@
+/*============================================================================
+ 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 <assert.h>
+
+#include "cmExternalMakefileProjectGenerator.h"
+
+void cmExternalMakefileProjectGenerator
+::EnableLanguage(std::vector<std::string> const&,
+ cmMakefile *, bool)
+{
+}
+
+std::string cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
+ const std::string& globalGenerator,
+ const std::string& extraGenerator)
+{
+ std::string fullName;
+ if (!globalGenerator.empty())
+ {
+ if (!extraGenerator.empty())
+ {
+ fullName = extraGenerator;
+ fullName += " - ";
+ }
+ fullName += globalGenerator;
+ }
+ return fullName;
+}
+
+std::string cmExternalMakefileProjectGenerator::GetGlobalGeneratorName(
+ const std::string& fullName)
+{
+ // at least one global generator must be supported
+ assert(!this->SupportedGlobalGenerators.empty());
+
+ if (fullName.empty())
+ {
+ return "";
+ }
+
+ std::string currentName = fullName;
+ // if we get only the short name, take the first global generator as default
+ if (currentName == this->GetName())
+ {
+ return this->SupportedGlobalGenerators[0];
+ }
+
+ // otherwise search for the matching global generator
+ for (std::vector<std::string>::const_iterator
+ it = this->SupportedGlobalGenerators.begin();
+ it != this->SupportedGlobalGenerators.end();
+ ++it)
+ {
+ if (this->CreateFullGeneratorName(*it, this->GetName())
+ == currentName)
+ {
+ return *it;
+ }
+ }
+ return "";
+}
diff --git a/Source/cmExternalMakefileProjectGenerator.h b/Source/cmExternalMakefileProjectGenerator.h
new file mode 100644
index 0000000000..cba1c76ddc
--- /dev/null
+++ b/Source/cmExternalMakefileProjectGenerator.h
@@ -0,0 +1,73 @@
+/*============================================================================
+ 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 cmExternalMakefileProjectGenerator_h
+#define cmExternalMakefileProjectGenerator_h
+
+#include "cmStandardIncludes.h"
+
+#include "cmDocumentation.h"
+
+class cmGlobalGenerator;
+
+/** \class cmExternalMakefileProjectGenerator
+ * \brief Base class for generators for "External Makefile based IDE projects".
+ *
+ * cmExternalMakefileProjectGenerator is a base class for generators
+ * for "external makefile based projects", i.e. IDE projects which work
+ * an already existing makefiles.
+ * See cmGlobalKdevelopGenerator as an example.
+ * After the makefiles have been generated by one of the Makefile
+ * generators, the Generate() method is called and this generator
+ * can iterate over the local generators and/or projects to produce the
+ * project files for the IDE.
+ */
+class cmExternalMakefileProjectGenerator
+{
+public:
+
+ virtual ~cmExternalMakefileProjectGenerator() {}
+
+ ///! Get the name for this generator.
+ virtual std::string GetName() const = 0;
+ /** Get the documentation entry for this generator. */
+ virtual void GetDocumentation(cmDocumentationEntry& entry,
+ const std::string& fullName) const = 0;
+ virtual void EnableLanguage(std::vector<std::string> const& languages,
+ cmMakefile *, bool optional);
+
+ ///! set the global generator which will generate the makefiles
+ virtual void SetGlobalGenerator(cmGlobalGenerator* generator)
+ {this->GlobalGenerator = generator;}
+
+ ///! Return the list of global generators supported by this extra generator
+ const std::vector<std::string>& GetSupportedGlobalGenerators() const
+ {return this->SupportedGlobalGenerators;}
+
+ ///! Get the name of the global generator for the given full name
+ std::string GetGlobalGeneratorName(const std::string& fullName);
+ /** Create a full name from the given global generator name and the
+ * extra generator name
+ */
+ static std::string CreateFullGeneratorName(
+ const std::string& globalGenerator,
+ const std::string& extraGenerator);
+
+ ///! Generate the project files, the Makefiles have already been generated
+ virtual void Generate() = 0;
+protected:
+ ///! Contains the names of the global generators support by this generator.
+ std::vector<std::string> SupportedGlobalGenerators;
+ ///! the global generator which creates the makefiles
+ const cmGlobalGenerator* GlobalGenerator;
+};
+
+#endif
diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx
new file mode 100644
index 0000000000..56a6edbbd9
--- /dev/null
+++ b/Source/cmExtraCodeBlocksGenerator.cxx
@@ -0,0 +1,804 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@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 "cmExtraCodeBlocksGenerator.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include "cmSourceFile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmTarget.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/SystemTools.hxx>
+
+/* Some useful URLs:
+Homepage:
+http://www.codeblocks.org
+
+File format docs:
+http://wiki.codeblocks.org/index.php?title=File_formats_description
+http://wiki.codeblocks.org/index.php?title=Workspace_file
+http://wiki.codeblocks.org/index.php?title=Project_file
+
+Discussion:
+http://forums.codeblocks.org/index.php/topic,6789.0.html
+*/
+
+//----------------------------------------------------------------------------
+void cmExtraCodeBlocksGenerator
+::GetDocumentation(cmDocumentationEntry& entry, const std::string&) const
+{
+ entry.Name = this->GetName();
+ entry.Brief = "Generates CodeBlocks project files.";
+}
+
+cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator()
+:cmExternalMakefileProjectGenerator()
+{
+#if defined(_WIN32)
+ this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
+ this->SupportedGlobalGenerators.push_back("NMake Makefiles");
+// disable until somebody actually tests it:
+// this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
+#endif
+ this->SupportedGlobalGenerators.push_back("Ninja");
+ this->SupportedGlobalGenerators.push_back("Unix Makefiles");
+}
+
+
+void cmExtraCodeBlocksGenerator::Generate()
+{
+ // for each sub project in the project create a codeblocks project
+ for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
+ it = this->GlobalGenerator->GetProjectMap().begin();
+ it!= this->GlobalGenerator->GetProjectMap().end();
+ ++it)
+ {
+ // create a project file
+ this->CreateProjectFile(it->second);
+ }
+}
+
+
+/* create the project file */
+void cmExtraCodeBlocksGenerator::CreateProjectFile(
+ const std::vector<cmLocalGenerator*>& lgs)
+{
+ const cmMakefile* mf=lgs[0]->GetMakefile();
+ std::string outputDir=mf->GetStartOutputDirectory();
+ std::string projectName=mf->GetProjectName();
+
+ std::string filename=outputDir+"/";
+ filename+=projectName+".cbp";
+ std::string sessionFilename=outputDir+"/";
+ sessionFilename+=projectName+".layout";
+
+ this->CreateNewProjectFile(lgs, filename);
+}
+
+
+/* Tree is used to create a "Virtual Folder" in CodeBlocks, in which all
+ CMake files this project depends on will be put. This means additionally
+ to the "Sources" and "Headers" virtual folders of CodeBlocks, there will
+ now also be a "CMake Files" virtual folder.
+ Patch by Daniel Teske <daniel.teske AT nokia.com> (which use C::B project
+ files in QtCreator).*/
+struct Tree
+{
+ std::string path; //only one component of the path
+ std::vector<Tree> folders;
+ std::vector<std::string> files;
+ void InsertPath(const std::vector<std::string>& splitted,
+ std::vector<std::string>::size_type start,
+ const std::string& fileName);
+ void BuildVirtualFolder(std::string& virtualFolders) const;
+ void BuildVirtualFolderImpl(std::string& virtualFolders,
+ const std::string& prefix) const;
+ void BuildUnit(std::string& unitString, const std::string& fsPath) const;
+ void BuildUnitImpl(std::string& unitString,
+ const std::string& virtualFolderPath,
+ const std::string& fsPath) const;
+};
+
+
+void Tree::InsertPath(const std::vector<std::string>& splitted,
+ std::vector<std::string>::size_type start,
+ const std::string& fileName)
+{
+ if (start == splitted.size())
+ {
+ files.push_back(fileName);
+ return;
+ }
+ for (std::vector<Tree>::iterator
+ it = folders.begin();
+ it != folders.end();
+ ++it)
+ {
+ if ((*it).path == splitted[start])
+ {
+ if (start + 1 < splitted.size())
+ {
+ it->InsertPath(splitted, start + 1, fileName);
+ return;
+ }
+ else
+ {
+ // last part of splitted
+ it->files.push_back(fileName);
+ return;
+ }
+ }
+ }
+ // Not found in folders, thus insert
+ Tree newFolder;
+ newFolder.path = splitted[start];
+ if (start + 1 < splitted.size())
+ {
+ newFolder.InsertPath(splitted, start + 1, fileName);
+ folders.push_back(newFolder);
+ return;
+ }
+ else
+ {
+ // last part of splitted
+ newFolder.files.push_back(fileName);
+ folders.push_back(newFolder);
+ return;
+ }
+}
+
+
+void Tree::BuildVirtualFolder(std::string& virtualFolders) const
+{
+ virtualFolders += "<Option virtualFolders=\"CMake Files\\;";
+ for (std::vector<Tree>::const_iterator it = folders.begin();
+ it != folders.end();
+ ++it)
+ {
+ it->BuildVirtualFolderImpl(virtualFolders, "");
+ }
+ virtualFolders += "\" />";
+}
+
+
+void Tree::BuildVirtualFolderImpl(std::string& virtualFolders,
+ const std::string& prefix) const
+{
+ virtualFolders += "CMake Files\\" + prefix + path + "\\;";
+ for (std::vector<Tree>::const_iterator it = folders.begin();
+ it != folders.end();
+ ++it)
+ {
+ it->BuildVirtualFolderImpl(virtualFolders, prefix + path + "\\");
+ }
+}
+
+
+void Tree::BuildUnit(std::string& unitString, const std::string& fsPath) const
+{
+ for (std::vector<std::string>::const_iterator it = files.begin();
+ it != files.end();
+ ++it)
+ {
+ unitString += " <Unit filename=\"" + fsPath + *it + "\">\n";
+ unitString += " <Option virtualFolder=\"CMake Files\\\" />\n";
+ unitString += " </Unit>\n";
+ }
+ for (std::vector<Tree>::const_iterator it = folders.begin();
+ it != folders.end();
+ ++it)
+ {
+ it->BuildUnitImpl(unitString, "", fsPath);
+ }
+}
+
+
+void Tree::BuildUnitImpl(std::string& unitString,
+ const std::string& virtualFolderPath,
+ const std::string& fsPath) const
+{
+ for (std::vector<std::string>::const_iterator it = files.begin();
+ it != files.end();
+ ++it)
+ {
+ unitString += " <Unit filename=\"" +fsPath+path+ "/" + *it + "\">\n";
+ unitString += " <Option virtualFolder=\"CMake Files\\"
+ + virtualFolderPath + path + "\\\" />\n";
+ unitString += " </Unit>\n";
+ }
+ for (std::vector<Tree>::const_iterator it = folders.begin();
+ it != folders.end();
+ ++it)
+ {
+ it->BuildUnitImpl(unitString,
+ virtualFolderPath + path + "\\", fsPath + path + "/");
+ }
+}
+
+
+void cmExtraCodeBlocksGenerator
+ ::CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
+ const std::string& filename)
+{
+ const cmMakefile* mf=lgs[0]->GetMakefile();
+ cmGeneratedFileStream fout(filename.c_str());
+ if(!fout)
+ {
+ return;
+ }
+
+ Tree tree;
+
+ // build tree of virtual folders
+ for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
+ it = this->GlobalGenerator->GetProjectMap().begin();
+ it != this->GlobalGenerator->GetProjectMap().end();
+ ++it)
+ {
+ // Collect all files
+ std::vector<std::string> listFiles;
+ for (std::vector<cmLocalGenerator *>::const_iterator
+ jt = it->second.begin();
+ jt != it->second.end();
+ ++jt)
+ {
+ const std::vector<std::string> & files =
+ (*jt)->GetMakefile()->GetListFiles();
+ listFiles.insert(listFiles.end(), files.begin(), files.end());
+ }
+
+ // Convert
+ const char* cmakeRoot = mf->GetDefinition("CMAKE_ROOT");
+ for (std::vector<std::string>::const_iterator jt = listFiles.begin();
+ jt != listFiles.end();
+ ++jt)
+ {
+ // don't put cmake's own files into the project (#12110):
+ if (jt->find(cmakeRoot) == 0)
+ {
+ continue;
+ }
+
+ const std::string &relative = cmSystemTools::RelativePath(
+ it->second[0]->GetMakefile()->GetHomeDirectory(),
+ jt->c_str());
+ std::vector<std::string> splitted;
+ cmSystemTools::SplitPath(relative.c_str(), splitted, false);
+ // Split filename from path
+ std::string fileName = *(splitted.end()-1);
+ splitted.erase(splitted.end() - 1, splitted.end());
+
+ // We don't want paths with CMakeFiles in them
+ // or do we?
+ // In speedcrunch those where purely internal
+ if (splitted.size() >= 1
+ && relative.find("CMakeFiles") == std::string::npos)
+ {
+ tree.InsertPath(splitted, 1, fileName);
+ }
+ }
+ }
+
+ // Now build a virtual tree string
+ std::string virtualFolders;
+ tree.BuildVirtualFolder(virtualFolders);
+ // And one for <Unit>
+ std::string unitFiles;
+ tree.BuildUnit(unitFiles, std::string(mf->GetHomeDirectory()) + "/");
+
+ // figure out the compiler
+ std::string compiler = this->GetCBCompilerId(mf);
+ std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+
+ fout<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"
+ "<CodeBlocks_project_file>\n"
+ " <FileVersion major=\"1\" minor=\"6\" />\n"
+ " <Project>\n"
+ " <Option title=\"" << mf->GetProjectName()<<"\" />\n"
+ " <Option makefile_is_custom=\"1\" />\n"
+ " <Option compiler=\"" << compiler << "\" />\n"
+ " "<<virtualFolders<<"\n"
+ " <Build>\n";
+
+ this->AppendTarget(fout, "all", 0, make.c_str(), mf, compiler.c_str());
+
+ // add all executable and library targets and some of the GLOBAL
+ // and UTILITY targets
+ 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();
+ ti != targets.end(); ti++)
+ {
+ switch(ti->second.GetType())
+ {
+ case cmTarget::GLOBAL_TARGET:
+ {
+ // Only add the global targets from CMAKE_BINARY_DIR,
+ // not from the subdirs
+ if (strcmp(makefile->GetStartOutputDirectory(),
+ makefile->GetHomeOutputDirectory())==0)
+ {
+ this->AppendTarget(fout, ti->first, 0,
+ make.c_str(), makefile, compiler.c_str());
+ }
+ }
+ break;
+ case cmTarget::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")))
+ {
+ break;
+ }
+
+ this->AppendTarget(fout, ti->first, 0,
+ make.c_str(), makefile, compiler.c_str());
+ break;
+ case cmTarget::EXECUTABLE:
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ case cmTarget::OBJECT_LIBRARY:
+ {
+ this->AppendTarget(fout, ti->first, &ti->second,
+ make.c_str(), makefile, compiler.c_str());
+ std::string fastTarget = ti->first;
+ fastTarget += "/fast";
+ this->AppendTarget(fout, fastTarget, &ti->second,
+ make.c_str(), makefile, compiler.c_str());
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ fout<<" </Build>\n";
+
+
+ // Collect all used source files in the project
+ // Sort them into two containers, one for C/C++ implementation files
+ // which may have an acompanying header, one for all other files
+ 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();
+ ti != targets.end(); ti++)
+ {
+ switch(ti->second.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
+ {
+ std::vector<cmSourceFile*> sources;
+ ti->second.GetSourceFiles(sources,
+ makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
+ si!=sources.end(); si++)
+ {
+ // don't add source files which have the GENERATED property set:
+ if ((*si)->GetPropertyAsBool("GENERATED"))
+ {
+ continue;
+ }
+
+ // check whether it is a C/C++ implementation file
+ bool isCFile = false;
+ std::string lang = (*si)->GetLanguage();
+ if (lang == "C" || lang == "CXX")
+ {
+ std::string srcext = (*si)->GetExtension();
+ for(std::vector<std::string>::const_iterator
+ ext = mf->GetSourceExtensions().begin();
+ ext != mf->GetSourceExtensions().end();
+ ++ext)
+ {
+ if (srcext == *ext)
+ {
+ isCFile = true;
+ break;
+ }
+ }
+ }
+
+ // then put it accordingly into one of the two containers
+ if (isCFile)
+ {
+ cFiles[(*si)->GetFullPath()] = *si ;
+ }
+ else
+ {
+ otherFiles.insert((*si)->GetFullPath());
+ }
+ }
+ }
+ default: // intended fallthrough
+ break;
+ }
+ }
+ }
+
+ // The following loop tries to add header files matching to implementation
+ // files to the project. It does that by iterating over all source files,
+ // replacing the file name extension with ".h" and checks whether such a
+ // file exists. If it does, it is inserted into the map of files.
+ // A very similar version of that code exists also in the kdevelop
+ // project generator.
+ for (std::map<std::string, cmSourceFile*>::const_iterator
+ sit=cFiles.begin();
+ sit!=cFiles.end();
+ ++sit)
+ {
+ std::string headerBasename=cmSystemTools::GetFilenamePath(sit->first);
+ headerBasename+="/";
+ headerBasename+=cmSystemTools::GetFilenameWithoutExtension(sit->first);
+
+ // check if there's a matching header around
+ for(std::vector<std::string>::const_iterator
+ ext = mf->GetHeaderExtensions().begin();
+ ext != mf->GetHeaderExtensions().end();
+ ++ext)
+ {
+ std::string hname=headerBasename;
+ hname += ".";
+ hname += *ext;
+ // if it's already in the set, don't check if it exists on disk
+ std::set<std::string>::const_iterator headerIt=otherFiles.find(hname);
+ if (headerIt != otherFiles.end())
+ {
+ break;
+ }
+
+ if(cmSystemTools::FileExists(hname.c_str()))
+ {
+ otherFiles.insert(hname);
+ break;
+ }
+ }
+ }
+
+ // insert all source files in the CodeBlocks project
+ // first the C/C++ implementation files, then all others
+ for (std::map<std::string, cmSourceFile*>::const_iterator
+ sit=cFiles.begin();
+ sit!=cFiles.end();
+ ++sit)
+ {
+ fout<<" <Unit filename=\""<< sit->first <<"\">\n"
+ " </Unit>\n";
+ }
+ for (std::set<std::string>::const_iterator
+ sit=otherFiles.begin();
+ sit!=otherFiles.end();
+ ++sit)
+ {
+ fout<<" <Unit filename=\""<< *sit <<"\">\n"
+ " </Unit>\n";
+ }
+
+ // Add CMakeLists.txt
+ fout<<unitFiles;
+
+ fout<<" </Project>\n"
+ "</CodeBlocks_project_file>\n";
+}
+
+
+// Write a dummy file for OBJECT libraries, so C::B can reference some file
+std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile(
+ cmMakefile* mf, cmTarget* target) const
+{
+ // 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->GetCurrentOutputDirectory();
+ filename += "/";
+ filename += mf->GetLocalGenerator()->GetTargetDirectory(*target);
+ filename += "/";
+ filename += target->GetName();
+ filename += ".objlib";
+ cmGeneratedFileStream fout(filename.c_str());
+ if(fout)
+ {
+ fout << "# This is a dummy file for the OBJECT library "
+ << target->GetName()
+ << " for the CMake CodeBlocks project generator.\n"
+ << "# Don't edit, this file will be overwritten.\n";
+ }
+ return filename;
+}
+
+
+// Generate the xml code for one target.
+void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
+ const std::string& targetName,
+ cmTarget* target,
+ const char* make,
+ const cmMakefile* makefile,
+ const char* compiler)
+{
+ std::string makefileName = makefile->GetStartOutputDirectory();
+ makefileName += "/Makefile";
+
+ fout<<" <Target title=\"" << targetName << "\">\n";
+ if (target!=0)
+ {
+ int cbTargetType = this->GetCBTargetType(target);
+ std::string workingDir = makefile->GetStartOutputDirectory();
+ if ( target->GetType()==cmTarget::EXECUTABLE)
+ {
+ // Determine the directory where the executable target is created, and
+ // set the working directory to this dir.
+ const char* runtimeOutputDir = makefile->GetDefinition(
+ "CMAKE_RUNTIME_OUTPUT_DIRECTORY");
+ if (runtimeOutputDir != 0)
+ {
+ workingDir = runtimeOutputDir;
+ }
+ else
+ {
+ const char* executableOutputDir = makefile->GetDefinition(
+ "EXECUTABLE_OUTPUT_PATH");
+ if (executableOutputDir != 0)
+ {
+ workingDir = executableOutputDir;
+ }
+ }
+ }
+
+ std::string buildType = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ std::string location;
+ if ( target->GetType()==cmTarget::OBJECT_LIBRARY)
+ {
+ location = this->CreateDummyTargetFile(const_cast<cmMakefile*>(makefile),
+ target);
+ }
+ else
+ {
+ location = target->GetLocation(buildType);
+ }
+
+ fout<<" <Option output=\"" << location
+ << "\" prefix_auto=\"0\" extension_auto=\"0\" />\n"
+ " <Option working_dir=\"" << workingDir << "\" />\n"
+ " <Option object_output=\"./\" />\n"
+ " <Option type=\"" << cbTargetType << "\" />\n"
+ " <Option compiler=\"" << compiler << "\" />\n"
+ " <Compiler>\n";
+
+ cmGeneratorTarget *gtgt = this->GlobalGenerator
+ ->GetGeneratorTarget(target);
+
+ // the compilerdefines for this target
+ std::vector<std::string> cdefs;
+ target->GetCompileDefinitions(cdefs, buildType);
+
+ // Expand the list.
+ for(std::vector<std::string>::const_iterator di = cdefs.begin();
+ di != cdefs.end(); ++di)
+ {
+ cmXMLSafe safedef(di->c_str());
+ fout <<" <Add option=\"-D" << safedef.str() << "\" />\n";
+ }
+
+ // the include directories for this target
+ std::set<std::string> uniqIncludeDirs;
+
+ std::vector<std::string> includes;
+ target->GetMakefile()->GetLocalGenerator()->
+ GetIncludeDirectories(includes, gtgt, "C", buildType);
+ for(std::vector<std::string>::const_iterator dirIt=includes.begin();
+ dirIt != includes.end();
+ ++dirIt)
+ {
+ uniqIncludeDirs.insert(*dirIt);
+ }
+
+ std::string systemIncludeDirs = makefile->GetSafeDefinition(
+ "CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
+ if (!systemIncludeDirs.empty())
+ {
+ std::vector<std::string> dirs;
+ cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
+ for(std::vector<std::string>::const_iterator dirIt=dirs.begin();
+ dirIt != dirs.end();
+ ++dirIt)
+ {
+ uniqIncludeDirs.insert(*dirIt);
+ }
+ }
+
+ systemIncludeDirs = makefile->GetSafeDefinition(
+ "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
+ if (!systemIncludeDirs.empty())
+ {
+ std::vector<std::string> dirs;
+ cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
+ for(std::vector<std::string>::const_iterator dirIt=dirs.begin();
+ dirIt != dirs.end();
+ ++dirIt)
+ {
+ uniqIncludeDirs.insert(*dirIt);
+ }
+ }
+
+ for(std::set<std::string>::const_iterator dirIt=uniqIncludeDirs.begin();
+ dirIt != uniqIncludeDirs.end();
+ ++dirIt)
+ {
+ fout <<" <Add directory=\"" << *dirIt << "\" />\n";
+ }
+
+ fout<<" </Compiler>\n";
+ }
+ else // e.g. all and the GLOBAL and UTILITY targets
+ {
+ fout<<" <Option working_dir=\""
+ << makefile->GetStartOutputDirectory() << "\" />\n"
+ <<" <Option type=\"" << 4 << "\" />\n";
+ }
+
+ fout<<" <MakeCommands>\n"
+ " <Build command=\""
+ << this->BuildMakeCommand(make, makefileName.c_str(), targetName)
+ << "\" />\n"
+ " <CompileFile command=\""
+ << this->BuildMakeCommand(make, makefileName.c_str(),"&quot;$file&quot;")
+ << "\" />\n"
+ " <Clean command=\""
+ << this->BuildMakeCommand(make, makefileName.c_str(), "clean")
+ << "\" />\n"
+ " <DistClean command=\""
+ << this->BuildMakeCommand(make, makefileName.c_str(), "clean")
+ << "\" />\n"
+ " </MakeCommands>\n"
+ " </Target>\n";
+
+}
+
+
+// Translate the cmake compiler id into the CodeBlocks compiler id
+std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
+{
+ // figure out which language to use
+ // for now care only for C and C++
+ std::string compilerIdVar = "CMAKE_CXX_COMPILER_ID";
+ if (this->GlobalGenerator->GetLanguageEnabled("CXX") == false)
+ {
+ 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")
+ {
+ compiler = "msvc8";
+ }
+ else if (compilerId == "Borland")
+ {
+ compiler = "bcc";
+ }
+ else if (compilerId == "SDCC")
+ {
+ compiler = "sdcc";
+ }
+ else if (compilerId == "Intel")
+ {
+ compiler = "icc";
+ }
+ else if (compilerId == "Watcom" || compilerId == "OpenWatcom")
+ {
+ compiler = "ow";
+ }
+ else if (compilerId == "GNU")
+ {
+ compiler = "gcc";
+ }
+ return compiler;
+}
+
+
+// Translate the cmake target type into the CodeBlocks target type id
+int cmExtraCodeBlocksGenerator::GetCBTargetType(cmTarget* target)
+{
+ if ( target->GetType()==cmTarget::EXECUTABLE)
+ {
+ if ((target->GetPropertyAsBool("WIN32_EXECUTABLE"))
+ || (target->GetPropertyAsBool("MACOSX_BUNDLE")))
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ else if (( target->GetType()==cmTarget::STATIC_LIBRARY)
+ || (target->GetType()==cmTarget::OBJECT_LIBRARY))
+ {
+ return 2;
+ }
+ else if ((target->GetType()==cmTarget::SHARED_LIBRARY)
+ || (target->GetType()==cmTarget::MODULE_LIBRARY))
+ {
+ return 3;
+ }
+ return 4;
+}
+
+// Create the command line for building the given target using the selected
+// make
+std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
+ const std::string& make, const char* makefile,
+ const std::string& target)
+{
+ std::string command = make;
+ std::string generator = this->GlobalGenerator->GetName();
+ if (generator == "NMake Makefiles")
+ {
+ // For Windows ConvertToOutputPath already adds quotes when required.
+ // These need to be escaped, see
+ // http://public.kitware.com/Bug/view.php?id=13952
+ std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
+ command += " /NOLOGO /f ";
+ command += cmXMLSafe(makefileName).str();
+ command += " VERBOSE=1 ";
+ command += target;
+ }
+ else if (generator == "MinGW Makefiles")
+ {
+ // no escaping of spaces in this case, see
+ // http://public.kitware.com/Bug/view.php?id=10014
+ std::string makefileName = makefile;
+ command += " -f &quot;";
+ command += makefileName;
+ command += "&quot; ";
+ command += " VERBOSE=1 ";
+ command += target;
+ }
+ else if (generator == "Ninja")
+ {
+ command += " -v ";
+ command += target;
+ }
+ else
+ {
+ std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
+ command += " -f &quot;";
+ command += makefileName;
+ command += "&quot; ";
+ command += " VERBOSE=1 ";
+ command += target;
+ }
+ return command;
+}
diff --git a/Source/cmExtraCodeBlocksGenerator.h b/Source/cmExtraCodeBlocksGenerator.h
new file mode 100644
index 0000000000..0435ad8c93
--- /dev/null
+++ b/Source/cmExtraCodeBlocksGenerator.h
@@ -0,0 +1,62 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@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.
+============================================================================*/
+#ifndef cmExtraCodeBlocksGenerator_h
+#define cmExtraCodeBlocksGenerator_h
+
+#include "cmExternalMakefileProjectGenerator.h"
+
+class cmLocalGenerator;
+class cmMakefile;
+class cmTarget;
+class cmGeneratedFileStream;
+
+/** \class cmExtraCodeBlocksGenerator
+ * \brief Write CodeBlocks project files for Makefile based projects
+ */
+class cmExtraCodeBlocksGenerator : public cmExternalMakefileProjectGenerator
+{
+public:
+ cmExtraCodeBlocksGenerator();
+
+ virtual std::string GetName() const
+ { return cmExtraCodeBlocksGenerator::GetActualName();}
+ static std::string GetActualName() { return "CodeBlocks";}
+ static cmExternalMakefileProjectGenerator* New()
+ { return new cmExtraCodeBlocksGenerator; }
+ /** Get the documentation entry for this generator. */
+ virtual void GetDocumentation(cmDocumentationEntry& entry,
+ const std::string& fullName) const;
+
+ virtual void Generate();
+private:
+
+ void CreateProjectFile(const std::vector<cmLocalGenerator*>& lgs);
+
+ void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
+ const std::string& filename);
+ std::string CreateDummyTargetFile(cmMakefile* mf, cmTarget* target) const;
+
+ std::string GetCBCompilerId(const cmMakefile* mf);
+ int GetCBTargetType(cmTarget* 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,
+ const char* make,
+ const cmMakefile* makefile,
+ const char* compiler);
+
+};
+
+#endif
diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx
new file mode 100644
index 0000000000..cc42bcae6b
--- /dev/null
+++ b/Source/cmExtraCodeLiteGenerator.cxx
@@ -0,0 +1,490 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@kde.org)
+ Copyright 2013 Eran Ifrah (eran.ifrah@gmail.com)
+
+ 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 "cmExtraCodeLiteGenerator.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include "cmSourceFile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmSystemTools.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/SystemInformation.hxx>
+#include <cmsys/Directory.hxx>
+#include "cmStandardIncludes.h"
+#include "cmXMLSafe.h"
+
+//----------------------------------------------------------------------------
+void cmExtraCodeLiteGenerator::GetDocumentation(cmDocumentationEntry& entry,
+ const std::string&) const
+{
+ entry.Name = this->GetName();
+ entry.Brief = "Generates CodeLite project files.";
+}
+
+cmExtraCodeLiteGenerator::cmExtraCodeLiteGenerator()
+ : cmExternalMakefileProjectGenerator()
+ , ConfigName("NoConfig")
+ , CpuCount(2)
+{
+#if defined(_WIN32)
+ this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
+ this->SupportedGlobalGenerators.push_back("NMake Makefiles");
+#endif
+ this->SupportedGlobalGenerators.push_back("Ninja");
+ this->SupportedGlobalGenerators.push_back("Unix Makefiles");
+}
+
+void cmExtraCodeLiteGenerator::Generate()
+{
+ // Hold root tree information for creating the workspace
+ std::string workspaceProjectName;
+ std::string workspaceOutputDir;
+ std::string workspaceFileName;
+ std::string workspaceSourcePath;
+ std::string lprjdebug;
+
+ cmGeneratedFileStream fout;
+
+ // loop projects and locate the root project.
+ // and extract the information for creating the worspace
+ for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
+ it = this->GlobalGenerator->GetProjectMap().begin();
+ it!= this->GlobalGenerator->GetProjectMap().end();
+ ++it)
+ {
+ const cmMakefile* mf =it->second[0]->GetMakefile();
+ this->ConfigName = GetConfigurationName( mf );
+
+ if (strcmp(mf->GetStartOutputDirectory(),
+ mf->GetHomeOutputDirectory()) == 0)
+ {
+ workspaceOutputDir = mf->GetStartOutputDirectory();
+ workspaceProjectName = mf->GetProjectName();
+ workspaceSourcePath = mf->GetHomeDirectory();
+ workspaceFileName = workspaceOutputDir+"/";
+ workspaceFileName += workspaceProjectName + ".workspace";
+ this->WorkspacePath = mf->GetStartOutputDirectory();;
+
+ fout.Open(workspaceFileName.c_str(), false, false);
+ fout << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<CodeLite_Workspace Name=\"" << workspaceProjectName << "\" >\n";
+ }
+ }
+
+ // for each sub project in the workspace create a codelite project
+ for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
+ it = this->GlobalGenerator->GetProjectMap().begin();
+ it!= this->GlobalGenerator->GetProjectMap().end();
+ ++it)
+ {
+ // retrive project information
+ const cmMakefile* mf = it->second[0]->GetMakefile();
+ std::string outputDir = mf->GetStartOutputDirectory();
+ std::string projectName = mf->GetProjectName();
+ std::string filename = outputDir + "/" + projectName + ".project";
+
+ // Make the project file relative to the workspace
+ filename = cmSystemTools::RelativePath(this->WorkspacePath.c_str(),
+ filename.c_str());
+
+ // create a project file
+ this->CreateProjectFile(it->second);
+ fout << " <Project Name=\"" << projectName << "\" Path=\""
+ << filename << "\" Active=\"No\"/>\n";
+ lprjdebug += "<Project Name=\"" + projectName
+ + "\" ConfigName=\"" + this->ConfigName + "\"/>\n";
+ }
+
+ fout << " <BuildMatrix>\n"
+ " <WorkspaceConfiguration Name=\""
+ << this->ConfigName << "\" Selected=\"yes\">\n"
+ " " << lprjdebug << ""
+ " </WorkspaceConfiguration>\n"
+ " </BuildMatrix>\n"
+ "</CodeLite_Workspace>\n";
+}
+
+/* create the project file */
+void cmExtraCodeLiteGenerator::CreateProjectFile(
+ const std::vector<cmLocalGenerator*>& lgs)
+{
+ const cmMakefile* mf = lgs[0]->GetMakefile();
+ std::string outputDir = mf->GetStartOutputDirectory();
+ std::string projectName = mf->GetProjectName();
+ std::string filename = outputDir + "/";
+
+ filename += projectName + ".project";
+ this->CreateNewProjectFile(lgs, filename);
+}
+
+void cmExtraCodeLiteGenerator
+::CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
+ const std::string& filename)
+{
+ const cmMakefile* mf=lgs[0]->GetMakefile();
+ cmGeneratedFileStream fout(filename.c_str());
+ if(!fout)
+ {
+ return;
+ }
+
+ // figure out the compiler
+ //std::string compiler = this->GetCBCompilerId(mf);
+ std::string workspaceSourcePath = mf->GetHomeDirectory();
+ std::string workspaceOutputDir = mf->GetHomeOutputDirectory();
+ std::vector<std::string> outputFiles = mf->GetOutputFiles();
+ std::string projectName = mf->GetProjectName();
+ std::string incDirs;
+ std::vector<cmValueWithOrigin> incDirsVec =
+ mf->GetIncludeDirectoriesEntries();
+ std::vector<cmValueWithOrigin>::const_iterator iterInc = incDirsVec.begin();
+
+ //std::cout << "GetIncludeDirectories:" << std::endl;
+ for(; iterInc != incDirsVec.end(); ++iterInc )
+ {
+ //std::cout << (*ItStrVec) << std::endl;
+ incDirs += iterInc->Value + " ";
+ }
+
+ ////////////////////////////////////
+ fout << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<CodeLite_Project Name=\"" << mf->GetProjectName()
+ << "\" InternalType=\"\">\n";
+
+ // Collect all used source files in the project
+ // Sort them into two containers, one for C/C++ implementation files
+ // which may have an acompanying header, one for all other files
+ std::string projectType;
+
+ 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();
+ ti != targets.end(); ti++)
+ {
+
+ switch(ti->second.GetType())
+ {
+ case cmTarget::EXECUTABLE:
+ {
+ projectType = "Executable";
+ }
+ break;
+ case cmTarget::STATIC_LIBRARY:
+ {
+ projectType = "Static Library";
+ }
+ break;
+ case cmTarget::SHARED_LIBRARY:
+ {
+ projectType = "Dynamic Library";
+ }
+ break;
+ case cmTarget::MODULE_LIBRARY:
+ {
+ projectType = "Dynamic Library";
+ }
+ break;
+ default: // intended fallthrough
+ break;
+ }
+
+ switch(ti->second.GetType())
+ {
+ case cmTarget::EXECUTABLE:
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ {
+ std::vector<cmSourceFile*> sources;
+ ti->second.GetSourceFiles(sources,
+ makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
+ si!=sources.end(); si++)
+ {
+ // check whether it is a C/C++ implementation file
+ bool isCFile = false;
+ std::string lang = (*si)->GetLanguage();
+ if (lang == "C" || lang == "CXX")
+ {
+ std::string srcext = (*si)->GetExtension();
+ for(std::vector<std::string>::const_iterator
+ ext = mf->GetSourceExtensions().begin();
+ ext != mf->GetSourceExtensions().end();
+ ++ext)
+ {
+ if (srcext == *ext)
+ {
+ isCFile = true;
+ break;
+ }
+ }
+ }
+
+ // then put it accordingly into one of the two containers
+ if (isCFile)
+ {
+ cFiles[(*si)->GetFullPath()] = *si ;
+ }
+ else
+ {
+ otherFiles.insert((*si)->GetFullPath());
+ }
+ }
+ }
+ default: // intended fallthrough
+ break;
+ }
+ }
+ }
+
+ // The following loop tries to add header files matching to implementation
+ // files to the project. It does that by iterating over all source files,
+ // replacing the file name extension with ".h" and checks whether such a
+ // file exists. If it does, it is inserted into the map of files.
+ // A very similar version of that code exists also in the kdevelop
+ // project generator.
+ for (std::map<std::string, cmSourceFile*>::const_iterator
+ sit=cFiles.begin();
+ sit!=cFiles.end();
+ ++sit)
+ {
+ std::string headerBasename=cmSystemTools::GetFilenamePath(sit->first);
+ headerBasename+="/";
+ headerBasename+=cmSystemTools::GetFilenameWithoutExtension(sit->first);
+
+ // check if there's a matching header around
+ for(std::vector<std::string>::const_iterator
+ ext = mf->GetHeaderExtensions().begin();
+ ext != mf->GetHeaderExtensions().end();
+ ++ext)
+ {
+ std::string hname=headerBasename;
+ hname += ".";
+ hname += *ext;
+ // if it's already in the set, don't check if it exists on disk
+ std::set<std::string>::const_iterator headerIt=otherFiles.find(hname);
+ if (headerIt != otherFiles.end())
+ {
+ break;
+ }
+
+ if(cmSystemTools::FileExists(hname.c_str()))
+ {
+ otherFiles.insert(hname);
+ break;
+ }
+ }
+ }
+
+ // Get the project path ( we need it later to convert files to
+ // their relative path)
+ std::string projectPath = cmSystemTools::GetFilenamePath(filename);
+
+ // Create 2 virtual folders: src and include
+ // and place all the implementation files into the src
+ // folder, the rest goes to the include folder
+ fout<< " <VirtualDirectory Name=\"src\">\n";
+
+ // insert all source files in the codelite project
+ // first the C/C++ implementation files, then all others
+ for (std::map<std::string, cmSourceFile*>::const_iterator
+ sit=cFiles.begin();
+ sit!=cFiles.end();
+ ++sit)
+ {
+ std::string relativePath =
+ cmSystemTools::RelativePath(projectPath.c_str(), sit->first.c_str());
+ fout<< " <File Name=\"" << relativePath << "\"/>\n";
+ }
+ fout<< " </VirtualDirectory>\n";
+ fout<< " <VirtualDirectory Name=\"include\">\n";
+ for (std::set<std::string>::const_iterator
+ sit=otherFiles.begin();
+ sit!=otherFiles.end();
+ ++sit)
+ {
+ std::string relativePath =
+ cmSystemTools::RelativePath(projectPath.c_str(), sit->c_str());
+ fout << " <File Name=\"" << relativePath << "\"/>\n";
+ }
+ fout << " </VirtualDirectory>\n";
+
+ // Get the number of CPUs. We use this information for the make -jN
+ // command
+ cmsys::SystemInformation info;
+ info.RunCPUCheck();
+
+ this->CpuCount = info.GetNumberOfLogicalCPU() *
+ info.GetNumberOfPhysicalCPU();
+
+ std::string cleanCommand = GetCleanCommand(mf);
+ std::string buildCommand = GetBuildCommand(mf);
+ std::string rebuildCommand = GetRebuildCommand(mf);
+ std::string singleFileCommand = GetSingleFileBuildCommand(mf);
+
+ std::string codeliteCompilerName = this->GetCodeLiteCompilerName(mf);
+
+ fout << "\n"
+ " <Settings Type=\"" << projectType << "\">\n"
+ " <Configuration Name=\"" << this->ConfigName << "\" CompilerType=\""
+ << codeliteCompilerName << "\" DebuggerType=\"GNU gdb debugger\" "
+ "Type=\""
+ << projectType << "\" BuildCmpWithGlobalSettings=\"append\" "
+ "BuildLnkWithGlobalSettings=\"append\" "
+ "BuildResWithGlobalSettings=\"append\">\n"
+ " <Compiler Options=\"-g\" "
+ "Required=\"yes\" PreCompiledHeader=\"\">\n"
+ " <IncludePath Value=\".\"/>\n"
+ " </Compiler>\n"
+ " <Linker Options=\"\" Required=\"yes\"/>\n"
+ " <ResourceCompiler Options=\"\" Required=\"no\"/>\n"
+ " <General OutputFile=\"$(IntermediateDirectory)/$(ProjectName)\" "
+ "IntermediateDirectory=\"./\" Command=\"./$(ProjectName)\" "
+ "CommandArguments=\"\" WorkingDirectory=\"$(IntermediateDirectory)\" "
+ "PauseExecWhenProcTerminates=\"yes\"/>\n"
+ " <Debugger IsRemote=\"no\" RemoteHostName=\"\" "
+ "RemoteHostPort=\"\" DebuggerPath=\"\">\n"
+ " <PostConnectCommands/>\n"
+ " <StartupCommands/>\n"
+ " </Debugger>\n"
+ " <PreBuild/>\n"
+ " <PostBuild/>\n"
+ " <CustomBuild Enabled=\"yes\">\n"
+ " <RebuildCommand>" << rebuildCommand << "</RebuildCommand>\n"
+ " <CleanCommand>" << cleanCommand << "</CleanCommand>\n"
+ " <BuildCommand>" << buildCommand << "</BuildCommand>\n"
+ " <SingleFileCommand>" << singleFileCommand
+ << "</SingleFileCommand>\n"
+ " <PreprocessFileCommand/>\n"
+ " <WorkingDirectory>$(WorkspacePath)</WorkingDirectory>\n"
+ " </CustomBuild>\n"
+ " <AdditionalRules>\n"
+ " <CustomPostBuild/>\n"
+ " <CustomPreBuild/>\n"
+ " </AdditionalRules>\n"
+ " </Configuration>\n"
+ " <GlobalSettings>\n"
+ " <Compiler Options=\"\">\n"
+ " <IncludePath Value=\".\"/>\n"
+ " </Compiler>\n"
+ " <Linker Options=\"\">\n"
+ " <LibraryPath Value=\".\"/>\n"
+ " </Linker>\n"
+ " <ResourceCompiler Options=\"\"/>\n"
+ " </GlobalSettings>\n"
+ " </Settings>\n"
+ "</CodeLite_Project>\n";
+}
+
+std::string
+cmExtraCodeLiteGenerator::GetCodeLiteCompilerName(const cmMakefile* mf) const
+{
+ // figure out which language to use
+ // for now care only for C and C++
+ std::string compilerIdVar = "CMAKE_CXX_COMPILER_ID";
+ if (this->GlobalGenerator->GetLanguageEnabled("CXX") == false)
+ {
+ compilerIdVar = "CMAKE_C_COMPILER_ID";
+ }
+
+ std::string compilerId = mf->GetSafeDefinition(compilerIdVar);
+ std::string compiler = "gnu g++"; // default to g++
+
+ // Since we need the compiler for parsing purposes only
+ // it does not matter if we use clang or clang++, same as
+ // "gnu gcc" vs "gnu g++"
+ if (compilerId == "MSVC")
+ {
+ compiler = "VC++";
+ }
+ else if (compilerId == "Clang")
+ {
+ compiler = "clang++";
+ }
+ else if (compilerId == "GNU")
+ {
+ compiler = "gnu g++";
+ }
+ return compiler;
+}
+
+std::string
+cmExtraCodeLiteGenerator::GetConfigurationName(const cmMakefile* mf) const
+{
+ std::string confName = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ // Trim the configuration name from whitespaces (left and right)
+ confName.erase(0, confName.find_first_not_of(" \t\r\v\n"));
+ confName.erase(confName.find_last_not_of(" \t\r\v\n")+1);
+ if ( confName.empty() )
+ {
+ confName = "NoConfig";
+ }
+ return confName;
+}
+
+std::string
+cmExtraCodeLiteGenerator::GetBuildCommand(const cmMakefile* mf) const
+{
+ std::string generator = mf->GetSafeDefinition("CMAKE_GENERATOR");
+ std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ std::string buildCommand = make; // Default
+ if ( generator == "NMake Makefiles" ||
+ generator == "Ninja" )
+ {
+ buildCommand = make;
+ }
+ else if ( generator == "MinGW Makefiles" ||
+ generator == "Unix Makefiles" )
+ {
+ cmOStringStream ss;
+ ss << make << " -j " << this->CpuCount;
+ buildCommand = ss.str();
+ }
+ return buildCommand;
+}
+
+std::string
+cmExtraCodeLiteGenerator::GetCleanCommand(const cmMakefile* mf) const
+{
+ return GetBuildCommand(mf) + " clean";
+}
+
+std::string
+cmExtraCodeLiteGenerator::GetRebuildCommand(const cmMakefile* mf) const
+{
+ return GetCleanCommand(mf) + cmXMLSafe(" && ").str() + GetBuildCommand(mf);
+}
+
+std::string
+cmExtraCodeLiteGenerator::GetSingleFileBuildCommand
+(const cmMakefile* mf) const
+{
+ std::string buildCommand;
+ std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ std::string generator = mf->GetSafeDefinition("CMAKE_GENERATOR");
+ if ( generator == "Unix Makefiles" || generator == "MinGW Makefiles" )
+ {
+ cmOStringStream ss;
+ ss << make << " -f$(ProjectPath)/Makefile $(CurrentFileName).cpp.o";
+ buildCommand = ss.str();
+ }
+ return buildCommand;
+}
diff --git a/Source/cmExtraCodeLiteGenerator.h b/Source/cmExtraCodeLiteGenerator.h
new file mode 100644
index 0000000000..6b4965d5a6
--- /dev/null
+++ b/Source/cmExtraCodeLiteGenerator.h
@@ -0,0 +1,54 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@kde.org)
+ Copyright 2013 Eran Ifrah (eran.ifrah@gmail.com)
+
+ 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 cmGlobalCodeLiteGenerator_h
+#define cmGlobalCodeLiteGenerator_h
+
+#include "cmExternalMakefileProjectGenerator.h"
+
+class cmLocalGenerator;
+
+class cmExtraCodeLiteGenerator : public cmExternalMakefileProjectGenerator
+{
+protected:
+ std::string ConfigName;
+ std::string WorkspacePath;
+ unsigned int CpuCount;
+
+protected:
+ std::string GetCodeLiteCompilerName(const cmMakefile* mf) const;
+ std::string GetConfigurationName( const cmMakefile* mf ) const;
+ std::string GetBuildCommand(const cmMakefile* mf) const;
+ std::string GetCleanCommand(const cmMakefile* mf) const;
+ std::string GetRebuildCommand(const cmMakefile* mf) const;
+ std::string GetSingleFileBuildCommand(const cmMakefile* mf) const;
+public:
+ cmExtraCodeLiteGenerator();
+
+ virtual std::string GetName() const
+ { return cmExtraCodeLiteGenerator::GetActualName();}
+ static std::string GetActualName() { return "CodeLite";}
+ static cmExternalMakefileProjectGenerator* New()
+ { return new cmExtraCodeLiteGenerator; }
+ /** Get the documentation entry for this generator. */
+ virtual void GetDocumentation(cmDocumentationEntry& entry,
+ const std::string& fullName) const;
+
+ virtual void Generate();
+ void CreateProjectFile(const std::vector<cmLocalGenerator*>& lgs);
+
+ void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
+ const std::string& filename);
+};
+
+#endif
diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx
new file mode 100644
index 0000000000..1beb3fd11a
--- /dev/null
+++ b/Source/cmExtraEclipseCDT4Generator.cxx
@@ -0,0 +1,1366 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@kde.org)
+ Copyright 2007 Miguel A. Figueroa-Villanueva
+
+ 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 "cmExtraEclipseCDT4Generator.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmTarget.h"
+#include "cmSourceFile.h"
+
+#include "cmSystemTools.h"
+#include <stdlib.h>
+#include <assert.h>
+
+//----------------------------------------------------------------------------
+cmExtraEclipseCDT4Generator
+::cmExtraEclipseCDT4Generator() : cmExternalMakefileProjectGenerator()
+{
+// TODO: Verify if __CYGWIN__ should be checked.
+//#if defined(_WIN32) && !defined(__CYGWIN__)
+#if defined(_WIN32)
+ this->SupportedGlobalGenerators.push_back("NMake Makefiles");
+ this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
+// this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
+#endif
+ this->SupportedGlobalGenerators.push_back("Ninja");
+ this->SupportedGlobalGenerators.push_back("Unix Makefiles");
+
+ this->SupportsVirtualFolders = true;
+ this->GenerateLinkedResources = true;
+ this->SupportsGmakeErrorParser = true;
+ this->SupportsMachO64Parser = true;
+}
+
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator
+::GetDocumentation(cmDocumentationEntry& entry, const std::string&) const
+{
+ entry.Name = this->GetName();
+ entry.Brief = "Generates Eclipse CDT 4.0 project files.";
+}
+
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator
+::EnableLanguage(std::vector<std::string> const& languages,
+ cmMakefile *, bool)
+{
+ for (std::vector<std::string>::const_iterator lit = languages.begin();
+ lit != languages.end(); ++lit)
+ {
+ if (*lit == "CXX")
+ {
+ this->Natures.insert("org.eclipse.cdt.core.ccnature");
+ }
+ else if (*lit == "C")
+ {
+ this->Natures.insert("org.eclipse.cdt.core.cnature");
+ }
+ else if (*lit == "Java")
+ {
+ this->Natures.insert("org.eclipse.jdt.core.javanature");
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator::Generate()
+{
+ const cmMakefile* mf
+ = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
+
+ std::string eclipseVersion = mf->GetSafeDefinition("CMAKE_ECLIPSE_VERSION");
+ cmsys::RegularExpression regex(".*([0-9]+\\.[0-9]+).*");
+ if (regex.find(eclipseVersion.c_str()))
+ {
+ unsigned int majorVersion = 0;
+ unsigned int minorVersion = 0;
+ int res=sscanf(regex.match(1).c_str(), "%u.%u", &majorVersion,
+ &minorVersion);
+ if (res == 2)
+ {
+ int version = majorVersion * 1000 + minorVersion;
+ if (version < 3006) // 3.6 is Helios
+ {
+ this->SupportsVirtualFolders = false;
+ this->SupportsMachO64Parser = false;
+ }
+ if (version < 3007) // 3.7 is Indigo
+ {
+ this->SupportsGmakeErrorParser = false;
+ }
+ }
+ }
+
+ // TODO: Decide if these are local or member variables
+ this->HomeDirectory = mf->GetHomeDirectory();
+ this->HomeOutputDirectory = mf->GetHomeOutputDirectory();
+
+ this->GenerateLinkedResources = mf->IsOn(
+ "CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES");
+
+ this->IsOutOfSourceBuild = (this->HomeDirectory!=this->HomeOutputDirectory);
+
+ this->GenerateSourceProject = (this->IsOutOfSourceBuild &&
+ mf->IsOn("CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT"));
+
+ if ((this->GenerateSourceProject == false)
+ && (mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT")))
+ {
+ mf->IssueMessage(cmake::WARNING,
+ "ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT is set to TRUE, "
+ "but this variable is not supported anymore since CMake 2.8.7.\n"
+ "Enable CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT instead.");
+ }
+
+ if (cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(),
+ this->HomeDirectory.c_str()))
+ {
+ mf->IssueMessage(cmake::WARNING, "The build directory is a subdirectory "
+ "of the source directory.\n"
+ "This is not supported well by Eclipse. It is strongly "
+ "recommended to use a build directory which is a "
+ "sibling of the source directory.");
+ }
+
+ // NOTE: This is not good, since it pollutes the source tree. However,
+ // Eclipse doesn't allow CVS/SVN to work when the .project is not in
+ // the cvs/svn root directory. Hence, this is provided as an option.
+ if (this->GenerateSourceProject)
+ {
+ // create .project file in the source tree
+ this->CreateSourceProjectFile();
+ }
+
+ // create a .project file
+ this->CreateProjectFile();
+
+ // create a .cproject file
+ this->CreateCProjectFile();
+}
+
+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",
+ this->GetPathBasename(this->HomeDirectory));
+
+ const std::string filename = this->HomeDirectory + "/.project";
+ cmGeneratedFileStream fout(filename.c_str());
+ if (!fout)
+ {
+ return;
+ }
+
+ fout <<
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<projectDescription>\n"
+ "\t<name>" << this->EscapeForXML(name) << "</name>\n"
+ "\t<comment></comment>\n"
+ "\t<projects>\n"
+ "\t</projects>\n"
+ "\t<buildSpec>\n"
+ "\t</buildSpec>\n"
+ "\t<natures>\n"
+ "\t</natures>\n"
+ "\t<linkedResources>\n";
+
+ if (this->SupportsVirtualFolders)
+ {
+ this->CreateLinksToSubprojects(fout, this->HomeDirectory);
+ this->SrcLinkedResources.clear();
+ }
+
+ fout <<
+ "\t</linkedResources>\n"
+ "</projectDescription>\n"
+ ;
+}
+
+
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
+ const char* envVar, cmMakefile* mf)
+{
+ // get the variables from the environment and from the cache and then
+ // figure out which one to use:
+
+ const char* envVarValue = getenv(envVar);
+
+ std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_";
+ cacheEntryName += envVar;
+ const char* cacheValue = mf->GetCacheManager()->GetCacheValue(
+ cacheEntryName);
+
+ // now we have both, decide which one to use
+ std::string valueToUse;
+ if (envVarValue==0 && cacheValue==0)
+ {
+ // nothing known, do nothing
+ valueToUse = "";
+ }
+ else if (envVarValue!=0 && cacheValue==0)
+ {
+ // The variable is in the env, but not in the cache. Use it and put it
+ // in the cache
+ valueToUse = envVarValue;
+ mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
+ cacheEntryName.c_str(), cmCacheManager::STRING,
+ true);
+ mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory());
+ }
+ else if (envVarValue==0 && cacheValue!=0)
+ {
+ // It is already in the cache, but not in the env, so use it from the cache
+ valueToUse = cacheValue;
+ }
+ else
+ {
+ // It is both in the cache and in the env.
+ // Use the version from the env. except if the value from the env is
+ // completely contained in the value from the cache (for the case that we
+ // now have a PATH without MSVC dirs in the env. but had the full PATH with
+ // all MSVC dirs during the cmake run which stored the var in the cache:
+ valueToUse = cacheValue;
+ if (valueToUse.find(envVarValue) == std::string::npos)
+ {
+ valueToUse = envVarValue;
+ mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
+ cacheEntryName.c_str(), cmCacheManager::STRING,
+ true);
+ mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory());
+ }
+ }
+
+ if (!valueToUse.empty())
+ {
+ fout << envVar << "=" << valueToUse << "|";
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator::CreateProjectFile()
+{
+ cmMakefile* mf
+ = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
+
+ const std::string filename = this->HomeOutputDirectory + "/.project";
+
+ cmGeneratedFileStream fout(filename.c_str());
+ if (!fout)
+ {
+ return;
+ }
+
+ std::string compilerId = mf->GetSafeDefinition("CMAKE_C_COMPILER_ID");
+ if (compilerId.empty()) // no C compiler, try the C++ compiler:
+ {
+ compilerId = mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID");
+ }
+
+ fout <<
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<projectDescription>\n"
+ "\t<name>" <<
+ this->GenerateProjectName(mf->GetProjectName(),
+ mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
+ this->GetPathBasename(this->HomeOutputDirectory))
+ << "</name>\n"
+ "\t<comment></comment>\n"
+ "\t<projects>\n"
+ "\t</projects>\n"
+ "\t<buildSpec>\n"
+ "\t\t<buildCommand>\n"
+ "\t\t\t<name>org.eclipse.cdt.make.core.makeBuilder</name>\n"
+ "\t\t\t<triggers>clean,full,incremental,</triggers>\n"
+ "\t\t\t<arguments>\n"
+ ;
+
+ // use clean target
+ fout <<
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>\n"
+ "\t\t\t\t\t<value>clean</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableCleanBuild</key>\n"
+ "\t\t\t\t\t<value>true</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.append_environment</key>\n"
+ "\t\t\t\t\t<value>true</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.stopOnError</key>\n"
+ "\t\t\t\t\t<value>true</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ ;
+
+ // set the make command
+ std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string makeArgs = mf->GetSafeDefinition(
+ "CMAKE_ECLIPSE_MAKE_ARGUMENTS");
+
+ fout <<
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key>\n"
+ "\t\t\t\t\t<value>true</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.command</key>\n"
+ "\t\t\t\t\t<value>" << this->GetEclipsePath(make) << "</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.contents</key>\n"
+ "\t\t\t\t\t<value>org.eclipse.cdt.make.core.activeConfigSettings</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.inc</key>\n"
+ "\t\t\t\t\t<value>all</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.arguments</key>\n"
+ "\t\t\t\t\t<value>" << makeArgs << "</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.buildLocation</key>\n"
+ "\t\t\t\t\t<value>"
+ << this->GetEclipsePath(this->HomeOutputDirectory) << "</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>\n"
+ "\t\t\t\t\t<value>false</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ ;
+
+ // set project specific environment
+ fout <<
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.environment</key>\n"
+ "\t\t\t\t\t<value>VERBOSE=1|CMAKE_NO_VERBOSE=1|" //verbose Makefile output
+ ;
+ // set vsvars32.bat environment available at CMake time,
+ // 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);
+ }
+ 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);
+ }
+ fout <<
+ "</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ ;
+
+ fout <<
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableFullBuild</key>\n"
+ "\t\t\t\t\t<value>true</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.auto</key>\n"
+ "\t\t\t\t\t<value>all</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableAutoBuild</key>\n"
+ "\t\t\t\t\t<value>false</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.clean</key>\n"
+ "\t\t\t\t\t<value>clean</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.fullBuildTarget</key>\n"
+ "\t\t\t\t\t<value>all</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.buildArguments</key>\n"
+ "\t\t\t\t\t<value></value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.location</key>\n"
+ "\t\t\t\t\t<value>"
+ << this->GetEclipsePath(this->HomeOutputDirectory) << "</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.make.core.autoBuildTarget</key>\n"
+ "\t\t\t\t\t<value>all</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ ;
+
+ // set error parsers
+ fout <<
+ "\t\t\t\t<dictionary>\n"
+ "\t\t\t\t\t<key>org.eclipse.cdt.core.errorOutputParser</key>\n"
+ "\t\t\t\t\t<value>"
+ ;
+ if (compilerId == "MSVC")
+ {
+ fout << "org.eclipse.cdt.core.VCErrorParser;";
+ }
+ else if (compilerId == "Intel")
+ {
+ fout << "org.eclipse.cdt.core.ICCErrorParser;";
+ }
+
+ if (this->SupportsGmakeErrorParser)
+ {
+ fout << "org.eclipse.cdt.core.GmakeErrorParser;";
+ }
+ else
+ {
+ fout << "org.eclipse.cdt.core.MakeErrorParser;";
+ }
+
+ fout <<
+ "org.eclipse.cdt.core.GCCErrorParser;"
+ "org.eclipse.cdt.core.GASErrorParser;"
+ "org.eclipse.cdt.core.GLDErrorParser;"
+ "</value>\n"
+ "\t\t\t\t</dictionary>\n"
+ ;
+
+ fout <<
+ "\t\t\t</arguments>\n"
+ "\t\t</buildCommand>\n"
+ "\t\t<buildCommand>\n"
+ "\t\t\t<name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name>\n"
+ "\t\t\t<arguments>\n"
+ "\t\t\t</arguments>\n"
+ "\t\t</buildCommand>\n"
+ "\t</buildSpec>\n"
+ ;
+
+ // set natures for c/c++ projects
+ fout <<
+ "\t<natures>\n"
+ "\t\t<nature>org.eclipse.cdt.make.core.makeNature</nature>\n"
+ "\t\t<nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature>\n";
+
+ for (std::set<std::string>::const_iterator nit=this->Natures.begin();
+ nit != this->Natures.end(); ++nit)
+ {
+ fout << "\t\t<nature>" << *nit << "</nature>\n";
+ }
+
+ if (const char *extraNaturesProp = mf->GetCMakeInstance()->
+ GetProperty("ECLIPSE_EXTRA_NATURES", cmProperty::GLOBAL))
+ {
+ std::vector<std::string> extraNatures;
+ cmSystemTools::ExpandListArgument(extraNaturesProp, extraNatures);
+ for (std::vector<std::string>::const_iterator nit = extraNatures.begin();
+ nit != extraNatures.end(); ++nit)
+ {
+ fout << "\t\t<nature>" << *nit << "</nature>\n";
+ }
+ }
+
+ fout << "\t</natures>\n";
+
+ fout << "\t<linkedResources>\n";
+ // create linked resources
+ if (this->IsOutOfSourceBuild)
+ {
+ // create a linked resource to CMAKE_SOURCE_DIR
+ // (this is not done anymore for each project because of
+ // http://public.kitware.com/Bug/view.php?id=9978 and because I found it
+ // actually quite confusing in bigger projects with many directories and
+ // projects, Alex
+
+ std::string sourceLinkedResourceName = "[Source directory]";
+ std::string linkSourceDirectory = this->GetEclipsePath(
+ mf->GetStartDirectory());
+ // .project dir can't be subdir of a linked resource dir
+ if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(),
+ linkSourceDirectory.c_str()))
+ {
+ this->AppendLinkedResource(fout, sourceLinkedResourceName,
+ this->GetEclipsePath(linkSourceDirectory),
+ LinkToFolder);
+ this->SrcLinkedResources.push_back(sourceLinkedResourceName);
+ }
+
+ }
+
+ if (this->SupportsVirtualFolders)
+ {
+ this->CreateLinksToSubprojects(fout, this->HomeOutputDirectory);
+
+ this->CreateLinksForTargets(fout);
+ }
+
+ fout << "\t</linkedResources>\n";
+
+ fout << "</projectDescription>\n";
+}
+
+
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator::CreateLinksForTargets(
+ cmGeneratedFileStream& fout)
+{
+ std::string linkName = "[Targets]";
+ this->AppendLinkedResource(fout, linkName, "virtual:/virtual",VirtualFolder);
+
+ for (std::vector<cmLocalGenerator*>::const_iterator
+ lgIt = this->GlobalGenerator->GetLocalGenerators().begin();
+ lgIt != this->GlobalGenerator->GetLocalGenerators().end();
+ ++lgIt)
+ {
+ cmMakefile* makefile = (*lgIt)->GetMakefile();
+ const cmTargets& targets = makefile->GetTargets();
+
+ for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end();++ti)
+ {
+ std::string linkName2 = linkName;
+ linkName2 += "/";
+ switch(ti->second.GetType())
+ {
+ case cmTarget::EXECUTABLE:
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ case cmTarget::OBJECT_LIBRARY:
+ {
+ const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ?
+ "[exe] " : "[lib] ");
+ linkName2 += prefix;
+ linkName2 += ti->first;
+ this->AppendLinkedResource(fout, linkName2, "virtual:/virtual",
+ VirtualFolder);
+ if (!this->GenerateLinkedResources)
+ {
+ break; // skip generating the linked resources to the source files
+ }
+ 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);
+ std::vector<cmSourceFile*> files;
+ tgt->GetSourceFiles(files,
+ makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ for(std::vector<cmSourceFile*>::const_iterator sfIt = files.begin();
+ sfIt != files.end();
+ sfIt++)
+ {
+ // Add the file to the list of sources.
+ std::string source = (*sfIt)->GetFullPath();
+ cmSourceGroup* sourceGroup =
+ makefile->FindSourceGroup(source.c_str(), sourceGroups);
+ sourceGroup->AssignSource(*sfIt);
+ }
+
+ for(std::vector<cmSourceGroup>::iterator sgIt = sourceGroups.begin();
+ sgIt != sourceGroups.end();
+ ++sgIt)
+ {
+ std::string linkName3 = linkName2;
+ linkName3 += "/";
+ linkName3 += sgIt->GetFullName();
+ this->AppendLinkedResource(fout, linkName3, "virtual:/virtual",
+ VirtualFolder);
+
+ std::vector<const cmSourceFile*> sFiles = sgIt->GetSourceFiles();
+ for(std::vector<const cmSourceFile*>::const_iterator fileIt =
+ sFiles.begin();
+ fileIt != sFiles.end();
+ ++fileIt)
+ {
+ std::string fullPath = (*fileIt)->GetFullPath();
+ if (!cmSystemTools::FileIsDirectory(fullPath.c_str()))
+ {
+ std::string linkName4 = linkName3;
+ linkName4 += "/";
+ linkName4 += cmSystemTools::GetFilenameName(fullPath);
+ this->AppendLinkedResource(fout, linkName4,
+ fullPath, LinkToFile);
+ }
+ }
+ }
+ }
+ break;
+ // ignore all others:
+ default:
+ break;
+ }
+ }
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects(
+ cmGeneratedFileStream& fout, const std::string& baseDir)
+{
+ if (!this->GenerateLinkedResources)
+ {
+ return;
+ }
+
+ // for each sub project create a linked resource to the source dir
+ // - only if it is an out-of-source build
+ this->AppendLinkedResource(fout, "[Subprojects]",
+ "virtual:/virtual", VirtualFolder);
+
+ for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
+ it = this->GlobalGenerator->GetProjectMap().begin();
+ it != this->GlobalGenerator->GetProjectMap().end();
+ ++it)
+ {
+ std::string linkSourceDirectory = this->GetEclipsePath(
+ it->second[0]->GetMakefile()->GetStartDirectory());
+ // a linked resource must not point to a parent directory of .project or
+ // .project itself
+ if ((baseDir != linkSourceDirectory) &&
+ !cmSystemTools::IsSubDirectory(baseDir.c_str(),
+ linkSourceDirectory.c_str()))
+ {
+ std::string linkName = "[Subprojects]/";
+ linkName += it->first;
+ this->AppendLinkedResource(fout, linkName,
+ this->GetEclipsePath(linkSourceDirectory),
+ LinkToFolder
+ );
+ // Don't add it to the srcLinkedResources, because listing multiple
+ // directories confuses the Eclipse indexer (#13596).
+ }
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator::AppendIncludeDirectories(
+ cmGeneratedFileStream& fout,
+ const std::vector<std::string>& includeDirs,
+ std::set<std::string>& emittedDirs)
+{
+ for(std::vector<std::string>::const_iterator inc = includeDirs.begin();
+ inc != includeDirs.end();
+ ++inc)
+ {
+ if (!inc->empty())
+ {
+ std::string dir = cmSystemTools::CollapseFullPath(inc->c_str());
+
+ // handle framework include dirs on OSX, the remainder after the
+ // Frameworks/ part has to be stripped
+ // /System/Library/Frameworks/GLUT.framework/Headers
+ cmsys::RegularExpression frameworkRx("(.+/Frameworks)/.+\\.framework/");
+ if(frameworkRx.find(dir.c_str()))
+ {
+ dir = frameworkRx.match(1);
+ }
+
+ if(emittedDirs.find(dir) == emittedDirs.end())
+ {
+ emittedDirs.insert(dir);
+ fout << "<pathentry include=\""
+ << cmExtraEclipseCDT4Generator::EscapeForXML(
+ cmExtraEclipseCDT4Generator::GetEclipsePath(dir))
+ << "\" kind=\"inc\" path=\"\" system=\"true\"/>\n";
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
+{
+ std::set<std::string> emmited;
+
+ const cmMakefile* mf
+ = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
+
+ const std::string filename = this->HomeOutputDirectory + "/.cproject";
+
+ cmGeneratedFileStream fout(filename.c_str());
+ if (!fout)
+ {
+ return;
+ }
+
+ // add header
+ fout <<
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+ "<?fileVersion 4.0.0?>\n\n"
+ "<cproject>\n"
+ "<storageModule moduleId=\"org.eclipse.cdt.core.settings\">\n"
+ ;
+
+ fout << "<cconfiguration id=\"org.eclipse.cdt.core.default.config.1\">\n";
+
+ // Configuration settings...
+ fout <<
+ "<storageModule"
+ " buildSystemId=\"org.eclipse.cdt.core.defaultConfigDataProvider\""
+ " id=\"org.eclipse.cdt.core.default.config.1\""
+ " moduleId=\"org.eclipse.cdt.core.settings\" name=\"Configuration\">\n"
+ "<externalSettings/>\n"
+ "<extensions>\n"
+ ;
+ // TODO: refactor this out...
+ std::string executableFormat = mf->GetSafeDefinition(
+ "CMAKE_EXECUTABLE_FORMAT");
+ if (executableFormat == "ELF")
+ {
+ fout << "<extension id=\"org.eclipse.cdt.core.ELF\""
+ " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
+ ;
+ fout << "<extension id=\"org.eclipse.cdt.core.GNU_ELF\""
+ " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
+ "<attribute key=\"addr2line\" value=\"addr2line\"/>\n"
+ "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
+ "</extension>\n"
+ ;
+ }
+ else
+ {
+ std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
+ if (systemName == "CYGWIN")
+ {
+ fout << "<extension id=\"org.eclipse.cdt.core.Cygwin_PE\""
+ " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
+ "<attribute key=\"addr2line\" value=\"addr2line\"/>\n"
+ "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
+ "<attribute key=\"cygpath\" value=\"cygpath\"/>\n"
+ "<attribute key=\"nm\" value=\"nm\"/>\n"
+ "</extension>\n"
+ ;
+ }
+ else if (systemName == "Windows")
+ {
+ fout << "<extension id=\"org.eclipse.cdt.core.PE\""
+ " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
+ ;
+ }
+ else if (systemName == "Darwin")
+ {
+ fout << "<extension id=\"" <<
+ (this->SupportsMachO64Parser ? "org.eclipse.cdt.core.MachO64"
+ : "org.eclipse.cdt.core.MachO") << "\""
+ " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
+ "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
+ "</extension>\n"
+ ;
+ }
+ else
+ {
+ // *** Should never get here ***
+ fout << "<error_toolchain_type/>\n";
+ }
+ }
+
+ fout << "</extensions>\n"
+ "</storageModule>\n"
+ ;
+
+ // ???
+ fout <<
+ "<storageModule moduleId=\"org.eclipse.cdt.core.language.mapping\">\n"
+ "<project-mappings/>\n"
+ "</storageModule>\n"
+ ;
+
+ // ???
+ fout<<"<storageModule moduleId=\"org.eclipse.cdt.core.externalSettings\"/>\n"
+ ;
+
+ // set the path entries (includes, libs, source dirs, etc.)
+ fout << "<storageModule moduleId=\"org.eclipse.cdt.core.pathentry\">\n"
+ ;
+ // for each sub project with a linked resource to the source dir:
+ // - make it type 'src'
+ // - and exclude it from type 'out'
+ std::string excludeFromOut;
+/* I don't know what the pathentry kind="src" are good for, e.g. autocompletion
+ * works also without them. Done wrong, the indexer complains, see #12417
+ * and #12213.
+ * According to #13596, this entry at least limits the directories the
+ * indexer is searching for files. So now the "src" entry contains only
+ * the linked resource to CMAKE_SOURCE_DIR.
+ * The CDT documentation is very terse on that:
+ * "CDT_SOURCE: Entry kind constant describing a path entry identifying a
+ * folder containing source code to be compiled."
+ * Also on the cdt-dev list didn't bring any information:
+ * http://web.archiveorange.com/archive/v/B4NlJDNIpYoOS1SbxFNy
+ * Alex */
+
+ for (std::vector<std::string>::const_iterator
+ it = this->SrcLinkedResources.begin();
+ it != this->SrcLinkedResources.end();
+ ++it)
+ {
+ fout << "<pathentry kind=\"src\" path=\"" << this->EscapeForXML(*it)
+ << "\"/>\n";
+
+ // exlude source directory from output search path
+ // - only if not named the same as an output directory
+ if (!cmSystemTools::FileIsDirectory(
+ std::string(this->HomeOutputDirectory + "/" + *it).c_str()))
+ {
+ excludeFromOut += this->EscapeForXML(*it) + "/|";
+ }
+ }
+
+ excludeFromOut += "**/CMakeFiles/";
+ fout << "<pathentry excluding=\"" << excludeFromOut
+ << "\" kind=\"out\" path=\"\"/>\n";
+
+ // add pre-processor definitions to allow eclipse to gray out sections
+ emmited.clear();
+ for (std::vector<cmLocalGenerator*>::const_iterator
+ it = this->GlobalGenerator->GetLocalGenerators().begin();
+ it != this->GlobalGenerator->GetLocalGenerators().end();
+ ++it)
+ {
+
+ if(const char* cdefs = (*it)->GetMakefile()->GetProperty(
+ "COMPILE_DEFINITIONS"))
+ {
+ // Expand the list.
+ std::vector<std::string> defs;
+ cmGeneratorExpression::Split(cdefs, defs);
+
+ for(std::vector<std::string>::const_iterator di = defs.begin();
+ di != defs.end(); ++di)
+ {
+ if (cmGeneratorExpression::Find(*di) != std::string::npos)
+ {
+ continue;
+ }
+
+ std::string::size_type equals = di->find('=', 0);
+ std::string::size_type enddef = di->length();
+
+ std::string def;
+ std::string val;
+ if (equals != std::string::npos && equals < enddef)
+ {
+ // we have -DFOO=BAR
+ def = di->substr(0, equals);
+ val = di->substr(equals + 1, enddef - equals + 1);
+ }
+ else
+ {
+ // we have -DFOO
+ def = *di;
+ }
+
+ // insert the definition if not already added.
+ if(emmited.find(def) == emmited.end())
+ {
+ emmited.insert(def);
+ fout << "<pathentry kind=\"mac\" name=\"" << def
+ << "\" path=\"\" value=\"" << this->EscapeForXML(val)
+ << "\"/>\n";
+ }
+ }
+ }
+ }
+ // add system defined c macros
+ const char* cDefs=mf->GetDefinition(
+ "CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS");
+ if(cDefs)
+ {
+ // Expand the list.
+ std::vector<std::string> defs;
+ cmSystemTools::ExpandListArgument(cDefs, defs, true);
+
+ // the list must contain only definition-value pairs:
+ if ((defs.size() % 2) == 0)
+ {
+ std::vector<std::string>::const_iterator di = defs.begin();
+ while (di != defs.end())
+ {
+ std::string def = *di;
+ ++di;
+ std::string val;
+ if (di != defs.end())
+ {
+ val = *di;
+ ++di;
+ }
+
+ // insert the definition if not already added.
+ if(emmited.find(def) == emmited.end())
+ {
+ emmited.insert(def);
+ fout << "<pathentry kind=\"mac\" name=\"" << def
+ << "\" path=\"\" value=\"" << this->EscapeForXML(val)
+ << "\"/>\n";
+ }
+ }
+ }
+ }
+ // add system defined c++ macros
+ const char* cxxDefs = mf->GetDefinition(
+ "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS");
+ if(cxxDefs)
+ {
+ // Expand the list.
+ std::vector<std::string> defs;
+ cmSystemTools::ExpandListArgument(cxxDefs, defs, true);
+
+ // the list must contain only definition-value pairs:
+ if ((defs.size() % 2) == 0)
+ {
+ std::vector<std::string>::const_iterator di = defs.begin();
+ while (di != defs.end())
+ {
+ std::string def = *di;
+ ++di;
+ std::string val;
+ if (di != defs.end())
+ {
+ val = *di;
+ ++di;
+ }
+
+ // insert the definition if not already added.
+ if(emmited.find(def) == emmited.end())
+ {
+ emmited.insert(def);
+ fout << "<pathentry kind=\"mac\" name=\"" << def
+ << "\" path=\"\" value=\"" << this->EscapeForXML(val)
+ << "\"/>\n";
+ }
+ }
+ }
+ }
+
+ // include dirs
+ emmited.clear();
+ for (std::vector<cmLocalGenerator*>::const_iterator
+ it = this->GlobalGenerator->GetLocalGenerators().begin();
+ it != this->GlobalGenerator->GetLocalGenerators().end();
+ ++it)
+ {
+ cmGeneratorTargetsType targets = (*it)->GetMakefile()
+ ->GetGeneratorTargets();
+ for (cmGeneratorTargetsType::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);
+ this->AppendIncludeDirectories(fout, includeDirs, emmited);
+ }
+ }
+ // now also the system include directories, in case we found them in
+ // CMakeSystemSpecificInformation.cmake. This makes Eclipse find the
+ // standard headers.
+ std::string compiler = mf->GetSafeDefinition("CMAKE_C_COMPILER");
+ if (!compiler.empty())
+ {
+ std::string systemIncludeDirs = mf->GetSafeDefinition(
+ "CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
+ std::vector<std::string> dirs;
+ cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
+ this->AppendIncludeDirectories(fout, dirs, emmited);
+ }
+ compiler = mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
+ if (!compiler.empty())
+ {
+ std::string systemIncludeDirs = mf->GetSafeDefinition(
+ "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
+ std::vector<std::string> dirs;
+ cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
+ this->AppendIncludeDirectories(fout, dirs, emmited);
+ }
+
+ fout << "</storageModule>\n";
+
+ // add build targets
+ fout <<
+ "<storageModule moduleId=\"org.eclipse.cdt.make.core.buildtargets\">\n"
+ "<buildTargets>\n"
+ ;
+ emmited.clear();
+ const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string makeArgs = mf->GetSafeDefinition(
+ "CMAKE_ECLIPSE_MAKE_ARGUMENTS");
+ const std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
+
+ cmGlobalGenerator* generator
+ = const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
+
+ std::string allTarget;
+ std::string cleanTarget;
+ if (generator->GetAllTargetName())
+ {
+ allTarget = generator->GetAllTargetName();
+ }
+ if (generator->GetCleanTargetName())
+ {
+ cleanTarget = generator->GetCleanTargetName();
+ }
+
+ // add all executable and library targets and some of the GLOBAL
+ // and UTILITY targets
+ for (std::vector<cmLocalGenerator*>::const_iterator
+ it = this->GlobalGenerator->GetLocalGenerators().begin();
+ it != this->GlobalGenerator->GetLocalGenerators().end();
+ ++it)
+ {
+ const cmTargets& targets = (*it)->GetMakefile()->GetTargets();
+ cmMakefile* makefile=(*it)->GetMakefile();
+ std::string subdir = (*it)->Convert(makefile->GetCurrentOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+ if (subdir == ".")
+ {
+ subdir = "";
+ }
+
+ for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end(); ++ti)
+ {
+ switch(ti->second.GetType())
+ {
+ case cmTarget::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, ": ");
+ }
+ }
+ break;
+ case cmTarget::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")))
+ {
+ break;
+ }
+
+ this->AppendTarget(fout, ti->first, make, makeArgs, subdir, ": ");
+ break;
+ case cmTarget::EXECUTABLE:
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ case cmTarget::OBJECT_LIBRARY:
+ {
+ const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ?
+ "[exe] " : "[lib] ");
+ this->AppendTarget(fout, ti->first, make, makeArgs, subdir, prefix);
+ std::string fastTarget = ti->first;
+ fastTarget += "/fast";
+ this->AppendTarget(fout, fastTarget, make, makeArgs, subdir, prefix);
+
+ // Add Build and Clean targets in the virtual folder of targets:
+ if (this->SupportsVirtualFolders)
+ {
+ std::string virtDir = "[Targets]/";
+ virtDir += prefix;
+ virtDir += ti->first;
+ std::string buildArgs = "-C \"";
+ buildArgs += makefile->GetHomeOutputDirectory();
+ buildArgs += "\" ";
+ buildArgs += makeArgs;
+ this->AppendTarget(fout, "Build", make, buildArgs, virtDir, "",
+ ti->first.c_str());
+
+ std::string cleanArgs = "-E chdir \"";
+ cleanArgs += makefile->GetCurrentOutputDirectory();
+ cleanArgs += "\" \"";
+ cleanArgs += cmake;
+ cleanArgs += "\" -P \"";
+ cleanArgs += (*it)->GetTargetDirectory(ti->second);
+ cleanArgs += "/cmake_clean.cmake\"";
+ this->AppendTarget(fout, "Clean", cmake, cleanArgs, virtDir, "", "");
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ // insert the all and clean targets in every subdir
+ if (!allTarget.empty())
+ {
+ this->AppendTarget(fout, allTarget, make, makeArgs, subdir, ": ");
+ }
+ if (!cleanTarget.empty())
+ {
+ this->AppendTarget(fout, cleanTarget, make, makeArgs, subdir, ": ");
+ }
+
+ //insert rules for compiling, preprocessing and assembling individual files
+ std::vector<std::string> objectFileTargets;
+ (*it)->GetIndividualFileTargets(objectFileTargets);
+ for(std::vector<std::string>::const_iterator fit=objectFileTargets.begin();
+ fit != objectFileTargets.end();
+ ++fit)
+ {
+ const char* prefix = "[obj] ";
+ if ((*fit)[fit->length()-1] == 's')
+ {
+ prefix = "[to asm] ";
+ }
+ else if ((*fit)[fit->length()-1] == 'i')
+ {
+ prefix = "[pre] ";
+ }
+ this->AppendTarget(fout, *fit, make, makeArgs, subdir, prefix);
+ }
+ }
+
+ fout << "</buildTargets>\n"
+ "</storageModule>\n"
+ ;
+
+ this->AppendStorageScanners(fout, *mf);
+
+ 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())
+ << "\"/>\n"
+ "</storageModule>\n"
+ "</cproject>\n"
+ ;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmExtraEclipseCDT4Generator::GetEclipsePath(const std::string& path)
+{
+#if defined(__CYGWIN__)
+ std::string cmd = "cygpath -m " + path;
+ std::string out;
+ if (!cmSystemTools::RunSingleCommand(cmd.c_str(), &out))
+ {
+ return path;
+ }
+ else
+ {
+ out.erase(out.find_last_of('\n'));
+ return out;
+ }
+#else
+ return path;
+#endif
+}
+
+std::string
+cmExtraEclipseCDT4Generator::GetPathBasename(const std::string& path)
+{
+ std::string outputBasename = path;
+ while (outputBasename.size() > 0 &&
+ (outputBasename[outputBasename.size() - 1] == '/' ||
+ outputBasename[outputBasename.size() - 1] == '\\'))
+ {
+ outputBasename.resize(outputBasename.size() - 1);
+ }
+ std::string::size_type loc = outputBasename.find_last_of("/\\");
+ if (loc != std::string::npos)
+ {
+ outputBasename = outputBasename.substr(loc + 1);
+ }
+
+ return outputBasename;
+}
+
+std::string
+cmExtraEclipseCDT4Generator::GenerateProjectName(const std::string& name,
+ const std::string& type,
+ const std::string& path)
+{
+ return cmExtraEclipseCDT4Generator::EscapeForXML(name)
+ +(type.empty() ? "" : "-") + type + "@" + path;
+}
+
+std::string cmExtraEclipseCDT4Generator::EscapeForXML(const std::string& value)
+{
+ std::string str = value;
+ cmSystemTools::ReplaceString(str, "&", "&amp;");
+ cmSystemTools::ReplaceString(str, "<", "&lt;");
+ cmSystemTools::ReplaceString(str, ">", "&gt;");
+ cmSystemTools::ReplaceString(str, "\"", "&quot;");
+ // NOTE: This one is not necessary, since as of Eclipse CDT4 it will
+ // automatically change this to the original value (').
+ //cmSystemTools::ReplaceString(str, "'", "&apos;");
+ return str;
+}
+
+//----------------------------------------------------------------------------
+// Helper functions
+//----------------------------------------------------------------------------
+void cmExtraEclipseCDT4Generator
+::AppendStorageScanners(cmGeneratedFileStream& fout,
+ const cmMakefile& makefile)
+{
+ // we need the "make" and the C (or C++) compiler which are used, Alex
+ std::string make = makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ std::string compiler = makefile.GetSafeDefinition("CMAKE_C_COMPILER");
+ std::string arg1 = makefile.GetSafeDefinition("CMAKE_C_COMPILER_ARG1");
+ if (compiler.empty())
+ {
+ compiler = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER");
+ arg1 = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER_ARG1");
+ }
+ if (compiler.empty()) //Hmm, what to do now ?
+ {
+ compiler = "gcc";
+ }
+
+ // the following right now hardcodes gcc behaviour :-/
+ std::string compilerArgs =
+ "-E -P -v -dD ${plugin_state_location}/${specs_file}";
+ if (!arg1.empty())
+ {
+ arg1 += " ";
+ compilerArgs = arg1 + compilerArgs;
+ }
+
+ fout <<
+ "<storageModule moduleId=\"scannerConfiguration\">\n"
+ "<autodiscovery enabled=\"true\" problemReportingEnabled=\"true\""
+ " selectedProfileId="
+ "\"org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile\"/>\n"
+ ;
+ cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
+ "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile",
+ true, "", true, "specsFile",
+ compilerArgs,
+ compiler, true, true);
+ cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
+ "org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile",
+ true, "", true, "makefileGenerator",
+ "-f ${project_name}_scd.mk",
+ make, true, true);
+
+ fout << "</storageModule>\n";
+}
+
+// The prefix is prepended before the actual name of the target. The purpose
+// of that is to sort the targets in the view of Eclipse, so that at first
+// the global/utility/all/clean targets appear ": ", then the executable
+// targets "[exe] ", then the libraries "[lib]", then the rules for the
+// object files "[obj]", then for preprocessing only "[pre] " and
+// finally the assembly files "[to asm] ". Note the "to" in "to asm",
+// without it, "asm" would be the first targets in the list, with the "to"
+// they are the last targets, which makes more sense.
+void cmExtraEclipseCDT4Generator::AppendTarget(cmGeneratedFileStream& fout,
+ const std::string& target,
+ const std::string& make,
+ const std::string& makeArgs,
+ const std::string& path,
+ const char* prefix,
+ const char* makeTarget
+ )
+{
+ std::string targetXml = cmExtraEclipseCDT4Generator::EscapeForXML(target);
+ std::string makeTargetXml = targetXml;
+ if (makeTarget != NULL)
+ {
+ makeTargetXml = cmExtraEclipseCDT4Generator::EscapeForXML(makeTarget);
+ }
+ cmExtraEclipseCDT4Generator::EscapeForXML(target);
+ std::string pathXml = cmExtraEclipseCDT4Generator::EscapeForXML(path);
+ fout <<
+ "<target name=\"" << prefix << targetXml << "\""
+ " path=\"" << pathXml << "\""
+ " targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">\n"
+ "<buildCommand>"
+ << cmExtraEclipseCDT4Generator::GetEclipsePath(make)
+ << "</buildCommand>\n"
+ "<buildArguments>" << makeArgs << "</buildArguments>\n"
+ "<buildTarget>" << makeTargetXml << "</buildTarget>\n"
+ "<stopOnError>true</stopOnError>\n"
+ "<useDefaultCommand>false</useDefaultCommand>\n"
+ "</target>\n"
+ ;
+}
+
+void cmExtraEclipseCDT4Generator
+::AppendScannerProfile(cmGeneratedFileStream& fout,
+ const std::string& profileID,
+ bool openActionEnabled,
+ const std::string& openActionFilePath,
+ bool pParserEnabled,
+ const std::string& scannerInfoProviderID,
+ const std::string& runActionArguments,
+ const std::string& runActionCommand,
+ bool runActionUseDefault,
+ bool sipParserEnabled)
+{
+ fout <<
+ "<profile id=\"" << profileID << "\">\n"
+ "<buildOutputProvider>\n"
+ "<openAction enabled=\"" << (openActionEnabled ? "true" : "false")
+ << "\" filePath=\"" << openActionFilePath << "\"/>\n"
+ "<parser enabled=\"" << (pParserEnabled ? "true" : "false") << "\"/>\n"
+ "</buildOutputProvider>\n"
+ "<scannerInfoProvider id=\"" << scannerInfoProviderID << "\">\n"
+ "<runAction arguments=\"" << runActionArguments << "\""
+ " command=\"" << runActionCommand
+ << "\" useDefault=\"" << (runActionUseDefault ? "true":"false") << "\"/>\n"
+ "<parser enabled=\"" << (sipParserEnabled ? "true" : "false") << "\"/>\n"
+ "</scannerInfoProvider>\n"
+ "</profile>\n"
+ ;
+}
+
+void cmExtraEclipseCDT4Generator
+::AppendLinkedResource (cmGeneratedFileStream& fout,
+ const std::string& name,
+ const std::string& path,
+ LinkType linkType)
+{
+ const char* locationTag = "location";
+ const char* typeTag = "2";
+ if (linkType == VirtualFolder) // ... and not a linked folder
+ {
+ locationTag = "locationURI";
+ }
+ if (linkType == LinkToFile)
+ {
+ typeTag = "1";
+ }
+
+ fout <<
+ "\t\t<link>\n"
+ "\t\t\t<name>"
+ << cmExtraEclipseCDT4Generator::EscapeForXML(name)
+ << "</name>\n"
+ "\t\t\t<type>" << typeTag << "</type>\n"
+ "\t\t\t<" << locationTag << ">"
+ << cmExtraEclipseCDT4Generator::EscapeForXML(path)
+ << "</" << locationTag << ">\n"
+ "\t\t</link>\n"
+ ;
+}
diff --git a/Source/cmExtraEclipseCDT4Generator.h b/Source/cmExtraEclipseCDT4Generator.h
new file mode 100644
index 0000000000..ef99760e54
--- /dev/null
+++ b/Source/cmExtraEclipseCDT4Generator.h
@@ -0,0 +1,122 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@kde.org)
+ Copyright 2007 Miguel A. Figueroa-Villanueva
+
+ 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 cmExtraEclipseCDT4Generator_h
+#define cmExtraEclipseCDT4Generator_h
+
+#include "cmExternalMakefileProjectGenerator.h"
+
+class cmMakefile;
+class cmGeneratedFileStream;
+
+/** \class cmExtraEclipseCDT4Generator
+ * \brief Write Eclipse project files for Makefile based projects
+ */
+class cmExtraEclipseCDT4Generator : public cmExternalMakefileProjectGenerator
+{
+public:
+ enum LinkType {VirtualFolder, LinkToFolder, LinkToFile };
+
+ cmExtraEclipseCDT4Generator();
+
+ static cmExternalMakefileProjectGenerator* New() {
+ return new cmExtraEclipseCDT4Generator;
+ }
+
+ virtual std::string GetName() const {
+ return cmExtraEclipseCDT4Generator::GetActualName();
+ }
+
+ static std::string GetActualName() { return "Eclipse CDT4"; }
+
+ virtual void GetDocumentation(cmDocumentationEntry& entry,
+ const std::string& fullName) const;
+ virtual void EnableLanguage(std::vector<std::string> const& languages,
+ cmMakefile *, bool optional);
+
+ virtual void Generate();
+
+private:
+ // create .project file in the source tree
+ void CreateSourceProjectFile();
+
+ // create .project file
+ void CreateProjectFile();
+
+ // create .cproject file
+ void CreateCProjectFile() const;
+
+ // If built with cygwin cmake, convert posix to windows path.
+ static std::string GetEclipsePath(const std::string& path);
+
+ // Extract basename.
+ static std::string GetPathBasename(const std::string& path);
+
+ // Generate the project name as: <name>-<type>@<path>
+ static std::string GenerateProjectName(const std::string& name,
+ const std::string& type,
+ const std::string& path);
+
+ static std::string EscapeForXML(const std::string& value);
+
+ // Helper functions
+ static void AppendStorageScanners(cmGeneratedFileStream& fout,
+ const cmMakefile& makefile);
+ static void AppendTarget (cmGeneratedFileStream& fout,
+ const std::string& target,
+ const std::string& make,
+ const std::string& makeArguments,
+ const std::string& path,
+ const char* prefix = "",
+ const char* makeTarget = NULL);
+ static void AppendScannerProfile (cmGeneratedFileStream& fout,
+ const std::string& profileID,
+ bool openActionEnabled,
+ const std::string& openActionFilePath,
+ bool pParserEnabled,
+ const std::string& scannerInfoProviderID,
+ const std::string& runActionArguments,
+ const std::string& runActionCommand,
+ bool runActionUseDefault,
+ bool sipParserEnabled);
+
+ static void AppendLinkedResource (cmGeneratedFileStream& fout,
+ const std::string& name,
+ const std::string& path,
+ LinkType linkType);
+
+ static void AppendIncludeDirectories(cmGeneratedFileStream& fout,
+ const std::vector<std::string>& includeDirs,
+ std::set<std::string>& emittedDirs);
+
+ static void AddEnvVar(cmGeneratedFileStream& fout, const char* envVar,
+ cmMakefile* mf);
+
+ void CreateLinksToSubprojects(cmGeneratedFileStream& fout,
+ const std::string& baseDir);
+ void CreateLinksForTargets(cmGeneratedFileStream& fout);
+
+ std::vector<std::string> SrcLinkedResources;
+ std::set<std::string> Natures;
+ std::string HomeDirectory;
+ std::string HomeOutputDirectory;
+ bool IsOutOfSourceBuild;
+ bool GenerateSourceProject;
+ bool GenerateLinkedResources;
+ bool SupportsVirtualFolders;
+ bool SupportsGmakeErrorParser;
+ bool SupportsMachO64Parser;
+
+};
+
+#endif
diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx
new file mode 100644
index 0000000000..567542e31f
--- /dev/null
+++ b/Source/cmExtraKateGenerator.cxx
@@ -0,0 +1,350 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@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 "cmExtraKateGenerator.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include "cmSourceFile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmTarget.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/SystemTools.hxx>
+
+//----------------------------------------------------------------------------
+void cmExtraKateGenerator
+::GetDocumentation(cmDocumentationEntry& entry, const std::string&) const
+{
+ entry.Name = this->GetName();
+ entry.Brief = "Generates Kate project files.";
+}
+
+cmExtraKateGenerator::cmExtraKateGenerator()
+:cmExternalMakefileProjectGenerator()
+{
+#if defined(_WIN32)
+ this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
+ this->SupportedGlobalGenerators.push_back("NMake Makefiles");
+// disable until somebody actually tests it:
+// this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
+#endif
+ this->SupportedGlobalGenerators.push_back("Ninja");
+ this->SupportedGlobalGenerators.push_back("Unix Makefiles");
+}
+
+
+void cmExtraKateGenerator::Generate()
+{
+ const cmMakefile* mf
+ = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
+ this->ProjectName = this->GenerateProjectName(mf->GetProjectName(),
+ mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
+ this->GetPathBasename(mf->GetHomeOutputDirectory()));
+ this->UseNinja = (this->GlobalGenerator->GetName() == "Ninja");
+
+ this->CreateKateProjectFile(mf);
+ this->CreateDummyKateProjectFile(mf);
+}
+
+
+void cmExtraKateGenerator::CreateKateProjectFile(const cmMakefile* mf) const
+{
+ std::string filename = mf->GetHomeOutputDirectory();
+ filename += "/.kateproject";
+ cmGeneratedFileStream fout(filename.c_str());
+ if (!fout)
+ {
+ 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);
+ fout << "}\n";
+}
+
+
+void
+cmExtraKateGenerator::WriteTargets(const cmMakefile* mf,
+ cmGeneratedFileStream& fout) const
+{
+ const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string makeArgs = mf->GetSafeDefinition(
+ "CMAKE_KATE_MAKE_ARGUMENTS");
+ const char* homeOutputDir = mf->GetHomeOutputDirectory();
+
+ fout <<
+ "\t\"build\": {\n"
+ "\t\t\"directory\": \"" << mf->GetHomeOutputDirectory() << "\",\n"
+ "\t\t\"default_target\": \"all\",\n"
+ "\t\t\"clean_target\": \"clean\",\n";
+
+ // build, clean and quick are for the build plugin kate <= 4.12:
+ fout << "\t\t\"build\": \"" << make << " -C \\\"" << homeOutputDir
+ << "\\\" " << makeArgs << " " << "all\",\n";
+ fout << "\t\t\"clean\": \"" << make << " -C \\\"" << homeOutputDir
+ << "\\\" " << makeArgs << " " << "clean\",\n";
+ fout << "\t\t\"quick\": \"" << make << " -C \\\"" << homeOutputDir
+ << "\\\" " << makeArgs << " " << "install\",\n";
+
+ // this is for kate >= 4.13:
+ fout <<
+ "\t\t\"targets\":[\n";
+
+ this->AppendTarget(fout, "all", make, makeArgs,
+ homeOutputDir, homeOutputDir);
+ this->AppendTarget(fout, "clean", make, makeArgs,
+ homeOutputDir, homeOutputDir);
+
+ // add all executable and library targets and some of the GLOBAL
+ // and UTILITY targets
+ for (std::vector<cmLocalGenerator*>::const_iterator
+ it = this->GlobalGenerator->GetLocalGenerators().begin();
+ it != this->GlobalGenerator->GetLocalGenerators().end();
+ ++it)
+ {
+ const cmTargets& targets = (*it)->GetMakefile()->GetTargets();
+ cmMakefile* makefile=(*it)->GetMakefile();
+ std::string currentDir = makefile->GetCurrentOutputDirectory();
+ bool topLevel = (currentDir == makefile->GetHomeOutputDirectory());
+
+ for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end(); ++ti)
+ {
+ switch(ti->second.GetType())
+ {
+ case cmTarget::GLOBAL_TARGET:
+ {
+ bool insertTarget = false;
+ // Only add the global targets from CMAKE_BINARY_DIR,
+ // not from the subdirs
+ if (topLevel)
+ {
+ 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")
+ {
+ const char* editCommand = makefile->GetDefinition
+ ("CMAKE_EDIT_COMMAND");
+ if (editCommand == 0)
+ {
+ insertTarget = false;
+ }
+ else if (strstr(editCommand, "ccmake")!=NULL)
+ {
+ insertTarget = false;
+ }
+ }
+ }
+ if (insertTarget)
+ {
+ this->AppendTarget(fout, ti->first, make, makeArgs,
+ currentDir, homeOutputDir);
+ }
+ }
+ break;
+ case cmTarget::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")))
+ {
+ break;
+ }
+
+ this->AppendTarget(fout, ti->first, make, makeArgs,
+ currentDir, homeOutputDir);
+ break;
+ case cmTarget::EXECUTABLE:
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ case cmTarget::OBJECT_LIBRARY:
+ {
+ this->AppendTarget(fout, ti->first, make, makeArgs,
+ currentDir, homeOutputDir);
+ std::string fastTarget = ti->first;
+ fastTarget += "/fast";
+ this->AppendTarget(fout, fastTarget, make, makeArgs,
+ currentDir, homeOutputDir);
+
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ //insert rules for compiling, preprocessing and assembling individual files
+ std::vector<std::string> objectFileTargets;
+ (*it)->GetIndividualFileTargets(objectFileTargets);
+ for(std::vector<std::string>::const_iterator fit=objectFileTargets.begin();
+ fit != objectFileTargets.end();
+ ++fit)
+ {
+ this->AppendTarget(fout, *fit, make, makeArgs, currentDir,homeOutputDir);
+ }
+ }
+
+ fout <<
+ "\t] }\n";
+}
+
+
+void
+cmExtraKateGenerator::AppendTarget(cmGeneratedFileStream& fout,
+ const std::string& target,
+ const std::string& make,
+ const std::string& makeArgs,
+ const std::string& path,
+ const char* homeOutputDir
+ ) const
+{
+ static char JsonSep = ' ';
+
+ fout <<
+ "\t\t\t" << JsonSep << "{\"name\":\"" << target << "\", "
+ "\"build_cmd\":\"" << make
+ << " -C \\\"" << (this->UseNinja ? homeOutputDir : path.c_str())
+ << "\\\" " << makeArgs << " "
+ << target << "\"}\n";
+
+ JsonSep = ',';
+}
+
+
+
+void
+cmExtraKateGenerator::CreateDummyKateProjectFile(const cmMakefile* mf) const
+{
+ std::string filename = mf->GetHomeOutputDirectory();
+ filename += "/";
+ filename += this->ProjectName;
+ filename += ".kateproject";
+ cmGeneratedFileStream fout(filename.c_str());
+ if (!fout)
+ {
+ return;
+ }
+
+ fout << "#Generated by " << mf->GetRequiredDefinition("CMAKE_COMMAND")
+ << ", do not edit.\n";
+}
+
+
+std::string
+cmExtraKateGenerator::GenerateFilesString(const cmMakefile* mf) const
+{
+ std::string s = mf->GetHomeDirectory();
+ s += "/.git";
+ if(cmSystemTools::FileExists(s.c_str()))
+ {
+ return std::string("\"git\": 1 ");
+ }
+
+ s = mf->GetHomeDirectory();
+ s += "/.svn";
+ if(cmSystemTools::FileExists(s.c_str()))
+ {
+ return std::string("\"svn\": 1 ");
+ }
+
+ s = mf->GetHomeDirectory();
+ s += "/";
+
+ std::set<std::string> files;
+ std::string tmp;
+ const std::vector<cmLocalGenerator *>& lgs =
+ this->GlobalGenerator->GetLocalGenerators();
+
+ for (std::vector<cmLocalGenerator*>::const_iterator it=lgs.begin();
+ it!=lgs.end(); it++)
+ {
+ cmMakefile* makefile=(*it)->GetMakefile();
+ const std::vector<std::string>& listFiles=makefile->GetListFiles();
+ for (std::vector<std::string>::const_iterator lt=listFiles.begin();
+ lt!=listFiles.end(); lt++)
+ {
+ tmp=*lt;
+ {
+ files.insert(tmp);
+ }
+ }
+
+ const std::vector<cmSourceFile*>& sources = makefile->GetSourceFiles();
+ for (std::vector<cmSourceFile*>::const_iterator sfIt = sources.begin();
+ sfIt != sources.end(); sfIt++)
+ {
+ cmSourceFile* sf = *sfIt;
+ if (sf->GetPropertyAsBool("GENERATED"))
+ {
+ continue;
+ }
+
+ tmp = sf->GetFullPath();
+ files.insert(tmp);
+ }
+ }
+
+ const char* sep = "";
+ tmp = "\"list\": [";
+ for(std::set<std::string>::const_iterator it = files.begin();
+ it != files.end(); ++it)
+ {
+ tmp += sep;
+ tmp += " \"";
+ tmp += *it;
+ tmp += "\"";
+ sep = ",";
+ }
+ tmp += "] ";
+
+ return tmp;
+}
+
+
+std::string cmExtraKateGenerator::GenerateProjectName(const std::string& name,
+ const std::string& type,
+ const std::string& path) const
+{
+ return name + (type.empty() ? "" : "-") + type + "@" + path;
+}
+
+
+std::string cmExtraKateGenerator::GetPathBasename(const std::string& path)const
+{
+ std::string outputBasename = path;
+ while (outputBasename.size() > 0 &&
+ (outputBasename[outputBasename.size() - 1] == '/' ||
+ outputBasename[outputBasename.size() - 1] == '\\'))
+ {
+ outputBasename.resize(outputBasename.size() - 1);
+ }
+ std::string::size_type loc = outputBasename.find_last_of("/\\");
+ if (loc != std::string::npos)
+ {
+ outputBasename = outputBasename.substr(loc + 1);
+ }
+
+ return outputBasename;
+}
diff --git a/Source/cmExtraKateGenerator.h b/Source/cmExtraKateGenerator.h
new file mode 100644
index 0000000000..f800febe8d
--- /dev/null
+++ b/Source/cmExtraKateGenerator.h
@@ -0,0 +1,62 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2013 Alexander Neundorf (neundorf@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.
+============================================================================*/
+#ifndef cmExtraKateGenerator_h
+#define cmExtraKateGenerator_h
+
+#include "cmExternalMakefileProjectGenerator.h"
+
+class cmLocalGenerator;
+class cmMakefile;
+class cmTarget;
+class cmGeneratedFileStream;
+
+/** \class cmExtraKateGenerator
+ * \brief Write Kate project files for Makefile or ninja based projects
+ */
+class cmExtraKateGenerator : public cmExternalMakefileProjectGenerator
+{
+public:
+ cmExtraKateGenerator();
+
+ virtual std::string GetName() const
+ { return cmExtraKateGenerator::GetActualName();}
+ static std::string GetActualName() { return "Kate";}
+ static cmExternalMakefileProjectGenerator* New()
+ { return new cmExtraKateGenerator; }
+ /** Get the documentation entry for this generator. */
+ virtual void GetDocumentation(cmDocumentationEntry& entry,
+ const std::string& fullName) const;
+
+ 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 AppendTarget(cmGeneratedFileStream& fout,
+ const std::string& target,
+ const std::string& make,
+ const std::string& makeArgs,
+ const std::string& path,
+ const char* homeOutputDir) const;
+
+ std::string GenerateFilesString(const cmMakefile* mf) const;
+ std::string GetPathBasename(const std::string& path) const;
+ std::string GenerateProjectName(const std::string& name,
+ const std::string& type,
+ const std::string& path) const;
+
+ std::string ProjectName;
+ bool UseNinja;
+};
+
+#endif
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
new file mode 100644
index 0000000000..5fff0fb275
--- /dev/null
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -0,0 +1,451 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@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 "cmExtraSublimeTextGenerator.h"
+#include "cmake.h"
+#include "cmGeneratedFileStream.h"
+#include "cmGeneratorTarget.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalGenerator.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmSystemTools.h"
+#include "cmTarget.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/SystemTools.hxx>
+
+/*
+Sublime Text 2 Generator
+Author: Morné Chamberlain
+This generator was initially based off of the CodeBlocks generator.
+
+Some useful URLs:
+Homepage:
+http://www.sublimetext.com/
+
+File format docs:
+http://www.sublimetext.com/docs/2/projects.html
+http://sublimetext.info/docs/en/reference/build_systems.html
+*/
+
+//----------------------------------------------------------------------------
+void cmExtraSublimeTextGenerator
+::GetDocumentation(cmDocumentationEntry& entry, const std::string&) const
+{
+ entry.Name = this->GetName();
+ entry.Brief = "Generates Sublime Text 2 project files.";
+}
+
+cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator()
+:cmExternalMakefileProjectGenerator()
+{
+#if defined(_WIN32)
+ this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
+ this->SupportedGlobalGenerators.push_back("NMake Makefiles");
+// disable until somebody actually tests it:
+// this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
+#endif
+ this->SupportedGlobalGenerators.push_back("Ninja");
+ this->SupportedGlobalGenerators.push_back("Unix Makefiles");
+}
+
+
+void cmExtraSublimeTextGenerator::Generate()
+{
+ // for each sub project in the project create a sublime text 2 project
+ for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
+ it = this->GlobalGenerator->GetProjectMap().begin();
+ it!= this->GlobalGenerator->GetProjectMap().end();
+ ++it)
+ {
+ // create a project file
+ this->CreateProjectFile(it->second);
+ }
+}
+
+
+void cmExtraSublimeTextGenerator::CreateProjectFile(
+ const std::vector<cmLocalGenerator*>& lgs)
+{
+ const cmMakefile* mf=lgs[0]->GetMakefile();
+ std::string outputDir=mf->GetStartOutputDirectory();
+ std::string projectName=mf->GetProjectName();
+
+ const std::string filename =
+ outputDir + "/" + projectName + ".sublime-project";
+
+ this->CreateNewProjectFile(lgs, filename);
+}
+
+void cmExtraSublimeTextGenerator
+ ::CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
+ const std::string& filename)
+{
+ const cmMakefile* mf=lgs[0]->GetMakefile();
+ cmGeneratedFileStream fout(filename.c_str());
+ if(!fout)
+ {
+ return;
+ }
+
+ const std::string &sourceRootRelativeToOutput = cmSystemTools::RelativePath(
+ mf->GetHomeOutputDirectory(),
+ mf->GetHomeDirectory());
+ // Write the folder entries to the project file
+ fout << "{\n";
+ fout << "\t\"folders\":\n\t[\n\t";
+ if (!sourceRootRelativeToOutput.empty())
+ {
+ fout << "\t{\n\t\t\t\"path\": \"" << sourceRootRelativeToOutput << "\"";
+ const std::string &outputRelativeToSourceRoot =
+ cmSystemTools::RelativePath(mf->GetHomeDirectory(),
+ mf->GetHomeOutputDirectory());
+ if ((!outputRelativeToSourceRoot.empty()) &&
+ ((outputRelativeToSourceRoot.length() < 3) ||
+ (outputRelativeToSourceRoot.substr(0, 3) != "../")))
+ {
+ fout << ",\n\t\t\t\"folder_exclude_patterns\": [\"" <<
+ outputRelativeToSourceRoot << "\"]";
+ }
+ }
+ else
+ {
+ fout << "\t{\n\t\t\t\"path\": \"./\"";
+ }
+ fout << "\n\t\t}";
+ // End of the folders section
+ fout << "\n\t]";
+
+ // Write the beginning of the build systems section to the project file
+ fout << ",\n\t\"build_systems\":\n\t[\n\t";
+
+ // Set of include directories over all targets (sublime text/sublimeclang
+ // doesn't currently support these settings per build system, only project
+ // wide
+ MapSourceFileFlags sourceFileFlags;
+ AppendAllTargets(lgs, mf, fout, sourceFileFlags);
+
+ // End of build_systems
+ fout << "\n\t]";
+ fout << "\n\t}";
+}
+
+
+void cmExtraSublimeTextGenerator::
+ AppendAllTargets(const std::vector<cmLocalGenerator*>& lgs,
+ const cmMakefile* mf,
+ cmGeneratedFileStream& fout,
+ MapSourceFileFlags& sourceFileFlags)
+{
+ std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ std::string compiler = "";
+ if (!lgs.empty())
+ {
+ this->AppendTarget(fout, "all", lgs[0], 0, make.c_str(), mf,
+ compiler.c_str(), sourceFileFlags, true);
+ this->AppendTarget(fout, "clean", lgs[0], 0, make.c_str(), mf,
+ compiler.c_str(), sourceFileFlags, false);
+ }
+
+ // add all executable and library targets and some of the GLOBAL
+ // and UTILITY targets
+ 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();
+ ti != targets.end(); ti++)
+ {
+ switch(ti->second.GetType())
+ {
+ case cmTarget::GLOBAL_TARGET:
+ {
+ // Only add the global targets from CMAKE_BINARY_DIR,
+ // not from the subdirs
+ if (strcmp(makefile->GetStartOutputDirectory(),
+ makefile->GetHomeOutputDirectory())==0)
+ {
+ this->AppendTarget(fout, ti->first, *lg, 0,
+ make.c_str(), makefile, compiler.c_str(),
+ sourceFileFlags, false);
+ }
+ }
+ break;
+ case cmTarget::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")))
+ {
+ break;
+ }
+
+ this->AppendTarget(fout, ti->first, *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:
+ {
+ this->AppendTarget(fout, ti->first, *lg, &ti->second,
+ make.c_str(), makefile, compiler.c_str(),
+ sourceFileFlags, false);
+ std::string fastTarget = ti->first;
+ fastTarget += "/fast";
+ this->AppendTarget(fout, fastTarget, *lg, &ti->second,
+ make.c_str(), makefile, compiler.c_str(),
+ sourceFileFlags, false);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
+
+void cmExtraSublimeTextGenerator::
+ AppendTarget(cmGeneratedFileStream& fout,
+ const std::string& targetName,
+ cmLocalGenerator* lg,
+ cmTarget* target,
+ const char* make,
+ const cmMakefile* makefile,
+ const char*, //compiler
+ MapSourceFileFlags& sourceFileFlags,
+ bool firstTarget)
+{
+
+ if (target != 0)
+ {
+ cmGeneratorTarget *gtgt = this->GlobalGenerator
+ ->GetGeneratorTarget(target);
+ std::vector<cmSourceFile*> sourceFiles;
+ target->GetSourceFiles(sourceFiles,
+ makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ std::vector<cmSourceFile*>::const_iterator sourceFilesEnd =
+ sourceFiles.end();
+ for (std::vector<cmSourceFile*>::const_iterator iter =
+ sourceFiles.begin(); iter != sourceFilesEnd; ++iter)
+ {
+ cmSourceFile* sourceFile = *iter;
+ MapSourceFileFlags::iterator sourceFileFlagsIter =
+ sourceFileFlags.find(sourceFile->GetFullPath());
+ if (sourceFileFlagsIter == sourceFileFlags.end())
+ {
+ sourceFileFlagsIter =
+ sourceFileFlags.insert(MapSourceFileFlags::value_type(
+ sourceFile->GetFullPath(), std::vector<std::string>())).first;
+ }
+ std::vector<std::string>& flags = sourceFileFlagsIter->second;
+ std::string flagsString =
+ this->ComputeFlagsForObject(*iter, lg, target, gtgt);
+ std::string definesString =
+ this->ComputeDefines(*iter, lg, target, gtgt);
+ flags.clear();
+ cmsys::RegularExpression flagRegex;
+ // Regular expression to extract compiler flags from a string
+ // https://gist.github.com/3944250
+ const char* regexString =
+ "(^|[ ])-[DIOUWfgs][^= ]+(=\\\"[^\"]+\\\"|=[^\"][^ ]+)?";
+ flagRegex.compile(regexString);
+ std::string workString = flagsString + " " + definesString;
+ while (flagRegex.find(workString))
+ {
+ std::string::size_type start = flagRegex.start();
+ if (workString[start] == ' ')
+ {
+ start++;
+ }
+ flags.push_back(workString.substr(start,
+ flagRegex.end() - start));
+ if (flagRegex.end() < workString.size())
+ {
+ workString = workString.substr(flagRegex.end());
+ }
+ else
+ {
+ workString = "";
+ }
+ }
+ }
+ }
+
+ // Ninja uses ninja.build files (look for a way to get the output file name
+ // from cmMakefile or something)
+ std::string makefileName;
+ if (this->GlobalGenerator->GetName() == "Ninja")
+ {
+ makefileName = "build.ninja";
+ }
+ else
+ {
+ makefileName = "Makefile";
+ }
+ if (!firstTarget)
+ {
+ fout << ",\n\t";
+ }
+ fout << "\t{\n\t\t\t\"name\": \"" << makefile->GetProjectName() << " - " <<
+ targetName << "\",\n";
+ fout << "\t\t\t\"cmd\": [" <<
+ this->BuildMakeCommand(make, makefileName.c_str(), targetName) <<
+ "],\n";
+ fout << "\t\t\t\"working_dir\": \"${project_path}\",\n";
+ fout << "\t\t\t\"file_regex\": \"^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$\"\n";
+ fout << "\t\t}";
+}
+
+// Create the command line for building the given target using the selected
+// make
+std::string cmExtraSublimeTextGenerator::BuildMakeCommand(
+ const std::string& make, const char* makefile,
+ const std::string& target)
+{
+ std::string command = "\"";
+ command += make + "\"";
+ std::string generator = this->GlobalGenerator->GetName();
+ if (generator == "NMake Makefiles")
+ {
+ std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
+ command += ", \"/NOLOGO\", \"/f\", \"";
+ command += makefileName + "\"";
+ command += ", \"VERBOSE=1\", \"";
+ command += target;
+ command += "\"";
+ }
+ else if (generator == "Ninja")
+ {
+ std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
+ command += ", \"-f\", \"";
+ command += makefileName + "\"";
+ command += ", \"-v\", \"";
+ command += target;
+ command += "\"";
+ }
+ else
+ {
+ std::string makefileName;
+ if (generator == "MinGW Makefiles")
+ {
+ // no escaping of spaces in this case, see
+ // http://public.kitware.com/Bug/view.php?id=10014
+ makefileName = makefile;
+ }
+ else
+ {
+ makefileName = cmSystemTools::ConvertToOutputPath(makefile);
+ }
+ command += ", \"-f\", \"";
+ command += makefileName + "\"";
+ command += ", \"VERBOSE=1\", \"";
+ command += target;
+ command += "\"";
+ }
+ return command;
+}
+
+// TODO: Most of the code is picked up from the Ninja generator, refactor it.
+std::string
+cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
+ cmLocalGenerator* lg,
+ cmTarget *target,
+ cmGeneratorTarget* gtgt)
+{
+ std::string flags;
+
+ cmMakefile *makefile = lg->GetMakefile();
+ std::string language = source->GetLanguage();
+ if (language.empty())
+ {
+ language = "C";
+ }
+ const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ // Add language-specific flags.
+ lg->AddLanguageFlags(flags, language, config);
+
+ lg->AddArchitectureFlags(flags, gtgt, language, config);
+
+ // TODO: Fortran support.
+ // // Fortran-specific flags computed for this target.
+ // if(*l == "Fortran")
+ // {
+ // this->AddFortranFlags(flags);
+ // }
+
+ // Add shared-library flags if needed.
+ lg->AddCMP0018Flags(flags, target, language, config);
+
+ // Add include directory flags.
+ {
+ std::vector<std::string> includes;
+ lg->GetIncludeDirectories(includes, gtgt, language, config);
+ std::string includeFlags =
+ lg->GetIncludeFlags(includes, gtgt, language, true); // full include paths
+ lg->AppendFlags(flags, includeFlags);
+ }
+
+ // Append old-style preprocessor definition flags.
+ lg->AppendFlags(flags, makefile->GetDefineFlags());
+
+ // Add target-specific flags.
+ lg->AddCompileOptions(flags, target, language, config);
+
+ // Add source file specific flags.
+ lg->AppendFlags(flags, source->GetProperty("COMPILE_FLAGS"));
+
+ // TODO: Handle Apple frameworks.
+
+ return flags;
+}
+
+// TODO: Refactor with
+// void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
+std::string
+cmExtraSublimeTextGenerator::
+ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg, cmTarget *target,
+ cmGeneratorTarget*)
+
+{
+ std::set<std::string> defines;
+ cmMakefile *makefile = lg->GetMakefile();
+ const std::string& language = source->GetLanguage();
+ const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+
+ // Add the export symbol definition for shared library objects.
+ if(const char* exportMacro = target->GetExportMacro())
+ {
+ lg->AppendDefines(defines, exportMacro);
+ }
+
+ // Add preprocessor definitions for this target and configuration.
+ lg->AddCompileDefinitions(defines, target, config);
+ lg->AppendDefines(defines, source->GetProperty("COMPILE_DEFINITIONS"));
+ {
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += cmSystemTools::UpperCase(config);
+ lg->AppendDefines(defines, source->GetProperty(defPropName));
+ }
+
+ std::string definesString;
+ lg->JoinDefines(defines, definesString, language);
+
+ return definesString;
+}
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
new file mode 100644
index 0000000000..4173b7de38
--- /dev/null
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -0,0 +1,89 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@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.
+============================================================================*/
+#ifndef cmExtraSublimeTextGenerator_h
+#define cmExtraSublimeTextGenerator_h
+
+#include "cmExternalMakefileProjectGenerator.h"
+#include "cmSourceFile.h"
+
+class cmLocalGenerator;
+class cmMakefile;
+class cmTarget;
+class cmGeneratedFileStream;
+class cmGeneratorTarget;
+
+/** \class cmExtraSublimeTextGenerator
+ * \brief Write Sublime Text 2 project files for Makefile based projects
+ */
+class cmExtraSublimeTextGenerator : public cmExternalMakefileProjectGenerator
+{
+public:
+ typedef std::map<std::string, std::vector<std::string> > MapSourceFileFlags;
+ cmExtraSublimeTextGenerator();
+
+ virtual std::string GetName() const
+ { return cmExtraSublimeTextGenerator::GetActualName();}
+ static std::string GetActualName()
+ { return "Sublime Text 2";}
+ static cmExternalMakefileProjectGenerator* New()
+ { return new cmExtraSublimeTextGenerator; }
+ /** Get the documentation entry for this generator. */
+ virtual void GetDocumentation(cmDocumentationEntry& entry,
+ const std::string& fullName) const;
+
+ virtual void Generate();
+private:
+
+ void CreateProjectFile(const std::vector<cmLocalGenerator*>& lgs);
+
+ void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
+ const std::string& filename);
+
+ /** Appends all targets as build systems to the project file and get all
+ * include directories and compiler definitions used.
+ */
+ void AppendAllTargets(const std::vector<cmLocalGenerator*>& lgs,
+ const cmMakefile* mf,
+ cmGeneratedFileStream& fout,
+ MapSourceFileFlags& sourceFileFlags);
+ /** Returns the build command that needs to be executed to build the
+ * specified target.
+ */
+ std::string BuildMakeCommand(const std::string& make, const char* makefile,
+ const std::string& target);
+ /** Appends the specified target to the generated project file as a Sublime
+ * Text build system.
+ */
+ void AppendTarget(cmGeneratedFileStream& fout,
+ const std::string& targetName,
+ cmLocalGenerator* lg,
+ cmTarget* target,
+ const char* make,
+ const cmMakefile* makefile,
+ const char* compiler,
+ MapSourceFileFlags& sourceFileFlags, bool firstTarget);
+ /**
+ * Compute the flags for compilation of object files for a given @a language.
+ * @note Generally it is the value of the variable whose name is computed
+ * by LanguageFlagsVarName().
+ */
+ std::string ComputeFlagsForObject(cmSourceFile *source,
+ cmLocalGenerator* lg,
+ cmTarget *target,
+ cmGeneratorTarget* gtgt);
+
+ std::string ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg,
+ cmTarget *target, cmGeneratorTarget* gtgt);
+};
+
+#endif
diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx
new file mode 100644
index 0000000000..f7d8243473
--- /dev/null
+++ b/Source/cmFLTKWrapUICommand.cxx
@@ -0,0 +1,177 @@
+/*============================================================================
+ 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 "cmFLTKWrapUICommand.h"
+
+#include "cmSourceFile.h"
+
+// cmFLTKWrapUICommand
+bool cmFLTKWrapUICommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // what is the current source dir
+ std::string cdir = this->Makefile->GetCurrentDirectory();
+ const char* fluid_exe =
+ this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE");
+
+ // get parameter for the command
+ this->Target = args[0]; // Target that will use the generated files
+
+ std::vector<std::string> newArgs;
+ this->Makefile->ExpandSourceListArguments(args,newArgs, 1);
+
+ // get the list of GUI files from which .cxx and .h will be generated
+ std::string outputDirectory = this->Makefile->GetCurrentOutputDirectory();
+
+ {
+ // Some of the generated files are *.h so the directory "GUI"
+ // where they are created have to be added to the include path
+ std::vector<std::string> outputDirectories;
+ outputDirectories.push_back(outputDirectory);
+ this->Makefile->AddIncludeDirectories( outputDirectories );
+ }
+
+ for(std::vector<std::string>::iterator i = (newArgs.begin() + 1);
+ i != newArgs.end(); i++)
+ {
+ cmSourceFile *curr = this->Makefile->GetSource(*i);
+ // if we should use the source GUI
+ // to generate .cxx and .h files
+ if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
+ {
+ std::string outName = outputDirectory;
+ outName += "/";
+ outName += cmSystemTools::GetFilenameWithoutExtension(*i);
+ std::string hname = outName;
+ hname += ".h";
+ std::string origname = cdir + "/" + *i;
+ // add starting depends
+ std::vector<std::string> depends;
+ depends.push_back(origname);
+ depends.push_back(fluid_exe);
+ std::string cxxres = outName;
+ cxxres += ".cxx";
+
+ cmCustomCommandLine commandLine;
+ commandLine.push_back(fluid_exe);
+ commandLine.push_back("-c"); // instructs Fluid to run in command line
+ commandLine.push_back("-h"); // optionally rename .h files
+ commandLine.push_back(hname);
+ commandLine.push_back("-o"); // optionally rename .cxx files
+ commandLine.push_back(cxxres);
+ commandLine.push_back(origname);// name of the GUI fluid file
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+
+ // Add command for generating the .h and .cxx files
+ std::string no_main_dependency = "";
+ const char* no_comment = 0;
+ const char* no_working_dir = 0;
+ this->Makefile->AddCustomCommandToOutput(cxxres,
+ depends, no_main_dependency,
+ commandLines, no_comment,
+ no_working_dir);
+ this->Makefile->AddCustomCommandToOutput(hname,
+ depends, no_main_dependency,
+ commandLines, no_comment,
+ no_working_dir);
+
+ cmSourceFile *sf = this->Makefile->GetSource(cxxres);
+ sf->AddDepend(hname.c_str());
+ sf->AddDepend(origname.c_str());
+ this->GeneratedSourcesClasses.push_back(sf);
+ }
+ }
+
+ // create the variable with the list of sources in it
+ size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
+ std::string sourceListValue;
+ for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
+ {
+ if (classNum)
+ {
+ sourceListValue += ";";
+ }
+ sourceListValue += this->GeneratedSourcesClasses[classNum]->GetFullPath();
+ }
+ std::string varName = this->Target;
+ varName += "_FLTK_UI_SRCS";
+ this->Makefile->AddDefinition(varName, sourceListValue.c_str());
+
+ return true;
+}
+
+void cmFLTKWrapUICommand::FinalPass()
+{
+ // people should add the srcs to the target themselves, but the old command
+ // didn't support that, so check and see if they added the files in and if
+ // they didn;t then print a warning and add then anyhow
+ cmTarget* target = this->Makefile->FindTarget(this->Target);
+ if(!target)
+ {
+ std::string msg =
+ "FLTK_WRAP_UI was called with a target that was never created: ";
+ msg += this->Target;
+ msg +=". The problem was found while processing the source directory: ";
+ msg += this->Makefile->GetStartDirectory();
+ msg += ". This FLTK_WRAP_UI call will be ignored.";
+ 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->GetStartDirectory();
+ 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/cmFLTKWrapUICommand.h b/Source/cmFLTKWrapUICommand.h
new file mode 100644
index 0000000000..617fcd9553
--- /dev/null
+++ b/Source/cmFLTKWrapUICommand.h
@@ -0,0 +1,72 @@
+/*============================================================================
+ 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 cmFLTKWrapUICommand_h
+#define cmFLTKWrapUICommand_h
+
+#include "cmCommand.h"
+
+/** \class cmFLTKWrapUICommand
+ * \brief Create .h and .cxx files rules for FLTK user interfaces files
+ *
+ * cmFLTKWrapUICommand is used to create wrappers for FLTK classes into
+ * normal C++
+ */
+class cmFLTKWrapUICommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmFLTKWrapUICommand, cmCommand);
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmFLTKWrapUICommand;
+ }
+
+ /**
+ * 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 is called at the end after all the information
+ * specified by the command is accumulated. Most commands do
+ * not implement this method. At this point, reading and
+ * writing to the cache can be done.
+ */
+ virtual void FinalPass();
+ virtual bool HasFinalPass() const { return true; }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "fltk_wrap_ui";}
+
+private:
+ /**
+ * List of produced files.
+ */
+ std::vector<cmSourceFile *> GeneratedSourcesClasses;
+
+ /**
+ * List of Fluid files that provide the source
+ * generating .cxx and .h files
+ */
+ std::string Target;
+};
+
+
+
+#endif
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
new file mode 100644
index 0000000000..1325cec928
--- /dev/null
+++ b/Source/cmFileCommand.cxx
@@ -0,0 +1,3517 @@
+/*============================================================================
+ 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 "cmFileCommand.h"
+#include "cmCryptoHash.h"
+#include "cmake.h"
+#include "cmHexFileConverter.h"
+#include "cmInstallType.h"
+#include "cmFileTimeComparison.h"
+#include "cmCryptoHash.h"
+
+#include "cmTimestamp.h"
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+#include "cm_curl.h"
+#endif
+
+#undef GetCurrentDirectory
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <cmsys/auto_ptr.hxx>
+#include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/FStream.hxx>
+
+// Table of permissions flags.
+#if defined(_WIN32) && !defined(__CYGWIN__)
+static mode_t mode_owner_read = S_IREAD;
+static mode_t mode_owner_write = S_IWRITE;
+static mode_t mode_owner_execute = S_IEXEC;
+static mode_t mode_group_read = 0;
+static mode_t mode_group_write = 0;
+static mode_t mode_group_execute = 0;
+static mode_t mode_world_read = 0;
+static mode_t mode_world_write = 0;
+static mode_t mode_world_execute = 0;
+static mode_t mode_setuid = 0;
+static mode_t mode_setgid = 0;
+#else
+static mode_t mode_owner_read = S_IRUSR;
+static mode_t mode_owner_write = S_IWUSR;
+static mode_t mode_owner_execute = S_IXUSR;
+static mode_t mode_group_read = S_IRGRP;
+static mode_t mode_group_write = S_IWGRP;
+static mode_t mode_group_execute = S_IXGRP;
+static mode_t mode_world_read = S_IROTH;
+static mode_t mode_world_write = S_IWOTH;
+static mode_t mode_world_execute = S_IXOTH;
+static mode_t mode_setuid = S_ISUID;
+static mode_t mode_setgid = S_ISGID;
+#endif
+
+// cmLibraryCommand
+bool cmFileCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("must be called with at least two arguments.");
+ return false;
+ }
+ std::string subCommand = args[0];
+ if ( subCommand == "WRITE" )
+ {
+ return this->HandleWriteCommand(args, false);
+ }
+ else if ( subCommand == "APPEND" )
+ {
+ return this->HandleWriteCommand(args, true);
+ }
+ else if ( subCommand == "DOWNLOAD" )
+ {
+ return this->HandleDownloadCommand(args);
+ }
+ else if ( subCommand == "UPLOAD" )
+ {
+ return this->HandleUploadCommand(args);
+ }
+ else if ( subCommand == "READ" )
+ {
+ return this->HandleReadCommand(args);
+ }
+ else if ( subCommand == "MD5" ||
+ subCommand == "SHA1" ||
+ subCommand == "SHA224" ||
+ subCommand == "SHA256" ||
+ subCommand == "SHA384" ||
+ subCommand == "SHA512" )
+ {
+ return this->HandleHashCommand(args);
+ }
+ else if ( subCommand == "STRINGS" )
+ {
+ return this->HandleStringsCommand(args);
+ }
+ else if ( subCommand == "GLOB" )
+ {
+ return this->HandleGlobCommand(args, false);
+ }
+ else if ( subCommand == "GLOB_RECURSE" )
+ {
+ return this->HandleGlobCommand(args, true);
+ }
+ else if ( subCommand == "MAKE_DIRECTORY" )
+ {
+ return this->HandleMakeDirectoryCommand(args);
+ }
+ else if ( subCommand == "RENAME" )
+ {
+ return this->HandleRename(args);
+ }
+ else if ( subCommand == "REMOVE" )
+ {
+ return this->HandleRemove(args, false);
+ }
+ else if ( subCommand == "REMOVE_RECURSE" )
+ {
+ return this->HandleRemove(args, true);
+ }
+ else if ( subCommand == "COPY" )
+ {
+ return this->HandleCopyCommand(args);
+ }
+ else if ( subCommand == "INSTALL" )
+ {
+ return this->HandleInstallCommand(args);
+ }
+ else if ( subCommand == "DIFFERENT" )
+ {
+ return this->HandleDifferentCommand(args);
+ }
+ else if ( subCommand == "RPATH_CHANGE" || subCommand == "CHRPATH" )
+ {
+ return this->HandleRPathChangeCommand(args);
+ }
+ else if ( subCommand == "RPATH_CHECK" )
+ {
+ return this->HandleRPathCheckCommand(args);
+ }
+ else if ( subCommand == "RPATH_REMOVE" )
+ {
+ return this->HandleRPathRemoveCommand(args);
+ }
+ else if ( subCommand == "RELATIVE_PATH" )
+ {
+ return this->HandleRelativePathCommand(args);
+ }
+ else if ( subCommand == "TO_CMAKE_PATH" )
+ {
+ return this->HandleCMakePathCommand(args, false);
+ }
+ else if ( subCommand == "TO_NATIVE_PATH" )
+ {
+ return this->HandleCMakePathCommand(args, true);
+ }
+ else if ( subCommand == "TIMESTAMP" )
+ {
+ return this->HandleTimestampCommand(args);
+ }
+ else if ( subCommand == "GENERATE" )
+ {
+ return this->HandleGenerateCommand(args);
+ }
+
+ std::string e = "does not recognize sub-command "+subCommand;
+ this->SetError(e);
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
+ bool append)
+{
+ std::string message;
+ std::vector<std::string>::const_iterator i = args.begin();
+
+ i++; // Get rid of subcommand
+
+ std::string fileName = *i;
+ if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
+ {
+ fileName = this->Makefile->GetCurrentDirectory();
+ fileName += "/" + *i;
+ }
+
+ i++;
+
+ for(;i != args.end(); ++i)
+ {
+ message += *i;
+ }
+ if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) )
+ {
+ std::string e
+ = "attempted to write a file: " + fileName +
+ " into a source directory.";
+ this->SetError(e);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+ std::string dir = cmSystemTools::GetFilenamePath(fileName);
+ cmSystemTools::MakeDirectory(dir.c_str());
+
+ mode_t mode = 0;
+
+ // Set permissions to writable
+ if ( cmSystemTools::GetPermissions(fileName.c_str(), mode) )
+ {
+ cmSystemTools::SetPermissions(fileName.c_str(),
+#if defined( _MSC_VER ) || defined( __MINGW32__ )
+ mode | S_IWRITE
+#elif defined( __BORLANDC__ )
+ mode | S_IWUSR
+#else
+ mode | S_IWUSR | S_IWGRP
+#endif
+ );
+ }
+ // If GetPermissions fails, pretend like it is ok. File open will fail if
+ // the file is not writable
+ cmsys::ofstream file(fileName.c_str(), append?std::ios::app: std::ios::out);
+ if ( !file )
+ {
+ std::string error = "failed to open for writing (";
+ error += cmSystemTools::GetLastSystemError();
+ error += "):\n ";
+ error += fileName;
+ this->SetError(error);
+ return false;
+ }
+ file << message;
+ file.close();
+ if(mode)
+ {
+ cmSystemTools::SetPermissions(fileName.c_str(), mode);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
+{
+ if ( args.size() < 3 )
+ {
+ this->SetError("READ must be called with at least two additional "
+ "arguments");
+ return false;
+ }
+
+ cmCommandArgumentsHelper argHelper;
+ cmCommandArgumentGroup group;
+
+ cmCAString readArg (&argHelper, "READ");
+ cmCAString fileNameArg (&argHelper, 0);
+ cmCAString resultArg (&argHelper, 0);
+
+ cmCAString offsetArg (&argHelper, "OFFSET", &group);
+ cmCAString limitArg (&argHelper, "LIMIT", &group);
+ cmCAEnabler hexOutputArg (&argHelper, "HEX", &group);
+ readArg.Follows(0);
+ fileNameArg.Follows(&readArg);
+ resultArg.Follows(&fileNameArg);
+ group.Follows(&resultArg);
+ argHelper.Parse(&args, 0);
+
+ std::string fileName = fileNameArg.GetString();
+ if ( !cmsys::SystemTools::FileIsFullPath(fileName.c_str()) )
+ {
+ fileName = this->Makefile->GetCurrentDirectory();
+ fileName += "/" + fileNameArg.GetString();
+ }
+
+ std::string variable = resultArg.GetString();
+
+ // Open the specified file.
+#if defined(_WIN32) || defined(__CYGWIN__)
+ cmsys::ifstream file(fileName.c_str(), std::ios::in |
+ (hexOutputArg.IsEnabled() ? std::ios::binary : std::ios::in));
+#else
+ cmsys::ifstream file(fileName.c_str(), std::ios::in);
+#endif
+
+ if ( !file )
+ {
+ std::string error = "failed to open for reading (";
+ error += cmSystemTools::GetLastSystemError();
+ error += "):\n ";
+ error += fileName;
+ this->SetError(error);
+ return false;
+ }
+
+ // is there a limit?
+ long sizeLimit = -1;
+ if (limitArg.GetString().size() > 0)
+ {
+ sizeLimit = atoi(limitArg.GetCString());
+ }
+
+ // is there an offset?
+ long offset = 0;
+ if (offsetArg.GetString().size() > 0)
+ {
+ offset = atoi(offsetArg.GetCString());
+ }
+
+ file.seekg(offset, std::ios::beg); // explicit ios::beg for IBM VisualAge 6
+
+ std::string output;
+
+ if (hexOutputArg.IsEnabled())
+ {
+ // Convert part of the file into hex code
+ char c;
+ while((sizeLimit != 0) && (file.get(c)))
+ {
+ char hex[4];
+ sprintf(hex, "%.2x", c&0xff);
+ output += hex;
+ if (sizeLimit > 0)
+ {
+ sizeLimit--;
+ }
+ }
+ }
+ else
+ {
+ std::string line;
+ bool has_newline = false;
+ while (sizeLimit != 0 &&
+ cmSystemTools::GetLineFromStream(file, line, &has_newline,
+ sizeLimit) )
+ {
+ if (sizeLimit > 0)
+ {
+ sizeLimit = sizeLimit - static_cast<long>(line.size());
+ if (has_newline)
+ {
+ sizeLimit--;
+ }
+ if (sizeLimit < 0)
+ {
+ sizeLimit = 0;
+ }
+ }
+ output += line;
+ if ( has_newline )
+ {
+ output += "\n";
+ }
+ }
+ }
+ this->Makefile->AddDefinition(variable, output.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleHashCommand(std::vector<std::string> const& args)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ if(args.size() != 3)
+ {
+ cmOStringStream e;
+ e << args[0] << " requires a file name and output variable";
+ this->SetError(e.str());
+ return false;
+ }
+
+ cmsys::auto_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str()));
+ if(hash.get())
+ {
+ std::string out = hash->HashFile(args[1]);
+ if(!out.empty())
+ {
+ this->Makefile->AddDefinition(args[2], out.c_str());
+ return true;
+ }
+ cmOStringStream e;
+ e << args[0] << " failed to read file \"" << args[1] << "\": "
+ << cmSystemTools::GetLastSystemError();
+ this->SetError(e.str());
+ }
+ return false;
+#else
+ cmOStringStream e;
+ e << args[0] << " not available during bootstrap";
+ this->SetError(e.str().c_str());
+ return false;
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
+{
+ if(args.size() < 3)
+ {
+ this->SetError("STRINGS requires a file name and output variable");
+ return false;
+ }
+
+ // Get the file to read.
+ std::string fileName = args[1];
+ if(!cmsys::SystemTools::FileIsFullPath(fileName.c_str()))
+ {
+ fileName = this->Makefile->GetCurrentDirectory();
+ fileName += "/" + args[1];
+ }
+
+ // Get the variable in which to store the results.
+ std::string outVar = args[2];
+
+ // Parse the options.
+ enum { arg_none,
+ arg_limit_input,
+ arg_limit_output,
+ arg_limit_count,
+ arg_length_minimum,
+ arg_length_maximum,
+ arg__maximum,
+ arg_regex,
+ arg_encoding };
+ unsigned int minlen = 0;
+ unsigned int maxlen = 0;
+ int limit_input = -1;
+ int limit_output = -1;
+ unsigned int limit_count = 0;
+ cmsys::RegularExpression regex;
+ bool have_regex = false;
+ bool newline_consume = false;
+ bool hex_conversion_enabled = true;
+ bool utf8_encoding = false;
+ int arg_mode = arg_none;
+ for(unsigned int i=3; i < args.size(); ++i)
+ {
+ if(args[i] == "LIMIT_INPUT")
+ {
+ arg_mode = arg_limit_input;
+ }
+ else if(args[i] == "LIMIT_OUTPUT")
+ {
+ arg_mode = arg_limit_output;
+ }
+ else if(args[i] == "LIMIT_COUNT")
+ {
+ arg_mode = arg_limit_count;
+ }
+ else if(args[i] == "LENGTH_MINIMUM")
+ {
+ arg_mode = arg_length_minimum;
+ }
+ else if(args[i] == "LENGTH_MAXIMUM")
+ {
+ arg_mode = arg_length_maximum;
+ }
+ else if(args[i] == "REGEX")
+ {
+ arg_mode = arg_regex;
+ }
+ else if(args[i] == "NEWLINE_CONSUME")
+ {
+ newline_consume = true;
+ arg_mode = arg_none;
+ }
+ else if(args[i] == "NO_HEX_CONVERSION")
+ {
+ hex_conversion_enabled = false;
+ arg_mode = arg_none;
+ }
+ else if(args[i] == "ENCODING")
+ {
+ arg_mode = arg_encoding;
+ }
+ else if(arg_mode == arg_limit_input)
+ {
+ if(sscanf(args[i].c_str(), "%d", &limit_input) != 1 ||
+ limit_input < 0)
+ {
+ cmOStringStream e;
+ e << "STRINGS option LIMIT_INPUT value \""
+ << args[i] << "\" is not an unsigned integer.";
+ this->SetError(e.str());
+ return false;
+ }
+ arg_mode = arg_none;
+ }
+ else if(arg_mode == arg_limit_output)
+ {
+ if(sscanf(args[i].c_str(), "%d", &limit_output) != 1 ||
+ limit_output < 0)
+ {
+ cmOStringStream e;
+ e << "STRINGS option LIMIT_OUTPUT value \""
+ << args[i] << "\" is not an unsigned integer.";
+ this->SetError(e.str());
+ return false;
+ }
+ arg_mode = arg_none;
+ }
+ else if(arg_mode == arg_limit_count)
+ {
+ int count;
+ if(sscanf(args[i].c_str(), "%d", &count) != 1 || count < 0)
+ {
+ cmOStringStream e;
+ e << "STRINGS option LIMIT_COUNT value \""
+ << args[i] << "\" is not an unsigned integer.";
+ this->SetError(e.str());
+ return false;
+ }
+ limit_count = count;
+ arg_mode = arg_none;
+ }
+ else if(arg_mode == arg_length_minimum)
+ {
+ int len;
+ if(sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0)
+ {
+ cmOStringStream e;
+ e << "STRINGS option LENGTH_MINIMUM value \""
+ << args[i] << "\" is not an unsigned integer.";
+ this->SetError(e.str());
+ return false;
+ }
+ minlen = len;
+ arg_mode = arg_none;
+ }
+ else if(arg_mode == arg_length_maximum)
+ {
+ int len;
+ if(sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0)
+ {
+ cmOStringStream e;
+ e << "STRINGS option LENGTH_MAXIMUM value \""
+ << args[i] << "\" is not an unsigned integer.";
+ this->SetError(e.str());
+ return false;
+ }
+ maxlen = len;
+ arg_mode = arg_none;
+ }
+ else if(arg_mode == arg_regex)
+ {
+ if(!regex.compile(args[i].c_str()))
+ {
+ cmOStringStream e;
+ e << "STRINGS option REGEX value \""
+ << args[i] << "\" could not be compiled.";
+ this->SetError(e.str());
+ return false;
+ }
+ have_regex = true;
+ arg_mode = arg_none;
+ }
+ else if(arg_mode == arg_encoding)
+ {
+ if(args[i] == "UTF-8")
+ {
+ utf8_encoding = true;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "STRINGS option ENCODING \""
+ << args[i] << "\" not recognized.";
+ this->SetError(e.str());
+ return false;
+ }
+ arg_mode = arg_none;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "STRINGS given unknown argument \""
+ << args[i] << "\"";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ if (hex_conversion_enabled)
+ {
+ // TODO: should work without temp file, but just on a memory buffer
+ std::string binaryFileName = this->Makefile->GetCurrentOutputDirectory();
+ binaryFileName += cmake::GetCMakeFilesDirectory();
+ binaryFileName += "/FileCommandStringsBinaryFile";
+ if(cmHexFileConverter::TryConvert(fileName.c_str(),binaryFileName.c_str()))
+ {
+ fileName = binaryFileName;
+ }
+ }
+
+ // Open the specified file.
+#if defined(_WIN32) || defined(__CYGWIN__)
+ cmsys::ifstream fin(fileName.c_str(), std::ios::in | std::ios::binary);
+#else
+ cmsys::ifstream fin(fileName.c_str(), std::ios::in);
+#endif
+ if(!fin)
+ {
+ cmOStringStream e;
+ e << "STRINGS file \"" << fileName << "\" cannot be read.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Parse strings out of the file.
+ int output_size = 0;
+ std::vector<std::string> strings;
+ std::string s;
+ while((!limit_count || strings.size() < limit_count) &&
+ (limit_input < 0 || static_cast<int>(fin.tellg()) < limit_input) &&
+ fin)
+ {
+ std::string current_str;
+
+ int c = fin.get();
+
+ if(c == '\r')
+ {
+ // Ignore CR character to make output always have UNIX newlines.
+ continue;
+ }
+
+ else if((c >= 0x20 && c < 0x7F) || c == '\t' ||
+ (c == '\n' && newline_consume))
+ {
+ // This is an ASCII character that may be part of a string.
+ // Cast added to avoid compiler warning. Cast is ok because
+ // c is guaranteed to fit in char by the above if...
+ current_str += static_cast<char>(c);
+ }
+ else if(utf8_encoding)
+ {
+ // Check for UTF-8 encoded string (up to 4 octets)
+ static const unsigned char utf8_check_table[3][2] =
+ {
+ {0xE0, 0xC0},
+ {0xF0, 0xE0},
+ {0xF8, 0xF0},
+ };
+
+ // how many octets are there?
+ unsigned int num_utf8_bytes = 0;
+ for(unsigned int j=0; num_utf8_bytes == 0 && j<3; j++)
+ {
+ if((c & utf8_check_table[j][0]) == utf8_check_table[j][1])
+ num_utf8_bytes = j+2;
+ }
+
+ // get subsequent octets and check that they are valid
+ for(unsigned int j=0; j<num_utf8_bytes; j++)
+ {
+ if(j != 0)
+ {
+ c = fin.get();
+ if(!fin || (c & 0xC0) != 0x80)
+ {
+ fin.putback(static_cast<char>(c));
+ break;
+ }
+ }
+ current_str += static_cast<char>(c);
+ }
+
+ // if this was an invalid utf8 sequence, discard the data, and put
+ // back subsequent characters
+ if((current_str.length() != num_utf8_bytes))
+ {
+ for(unsigned int j=0; j<current_str.size()-1; j++)
+ {
+ c = current_str[current_str.size() - 1 - j];
+ fin.putback(static_cast<char>(c));
+ }
+ current_str = "";
+ }
+ }
+
+
+ if(c == '\n' && !newline_consume)
+ {
+ // The current line has been terminated. Check if the current
+ // string matches the requirements. The length may now be as
+ // low as zero since blank lines are allowed.
+ if(s.length() >= minlen &&
+ (!have_regex || regex.find(s.c_str())))
+ {
+ output_size += static_cast<int>(s.size()) + 1;
+ if(limit_output >= 0 && output_size >= limit_output)
+ {
+ s = "";
+ break;
+ }
+ strings.push_back(s);
+ }
+
+ // Reset the string to empty.
+ s = "";
+ }
+ else if(current_str.empty())
+ {
+ // A non-string character has been found. Check if the current
+ // string matches the requirements. We require that the length
+ // be at least one no matter what the user specified.
+ if(s.length() >= minlen && s.length() >= 1 &&
+ (!have_regex || regex.find(s.c_str())))
+ {
+ output_size += static_cast<int>(s.size()) + 1;
+ if(limit_output >= 0 && output_size >= limit_output)
+ {
+ s = "";
+ break;
+ }
+ strings.push_back(s);
+ }
+
+ // Reset the string to empty.
+ s = "";
+ }
+ else
+ {
+ s += current_str;
+ }
+
+
+ if(maxlen > 0 && s.size() == maxlen)
+ {
+ // Terminate a string if the maximum length is reached.
+ if(s.length() >= minlen &&
+ (!have_regex || regex.find(s.c_str())))
+ {
+ output_size += static_cast<int>(s.size()) + 1;
+ if(limit_output >= 0 && output_size >= limit_output)
+ {
+ s = "";
+ break;
+ }
+ strings.push_back(s);
+ }
+ s = "";
+ }
+ }
+
+ // If there is a non-empty current string we have hit the end of the
+ // input file or the input size limit. Check if the current string
+ // matches the requirements.
+ if((!limit_count || strings.size() < limit_count) &&
+ !s.empty() && s.length() >= minlen &&
+ (!have_regex || regex.find(s.c_str())))
+ {
+ output_size += static_cast<int>(s.size()) + 1;
+ if(limit_output < 0 || output_size < limit_output)
+ {
+ strings.push_back(s);
+ }
+ }
+
+ // Encode the result in a CMake list.
+ const char* sep = "";
+ std::string output;
+ for(std::vector<std::string>::const_iterator si = strings.begin();
+ si != strings.end(); ++si)
+ {
+ // Separate the strings in the output to make it a list.
+ output += sep;
+ sep = ";";
+
+ // Store the string in the output, but escape semicolons to
+ // make sure it is a list.
+ std::string const& sr = *si;
+ for(unsigned int i=0; i < sr.size(); ++i)
+ {
+ if(sr[i] == ';')
+ {
+ output += '\\';
+ }
+ output += sr[i];
+ }
+ }
+
+ // Save the output in a makefile variable.
+ this->Makefile->AddDefinition(outVar, output.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
+ bool recurse)
+{
+ // File commands has at least one argument
+ assert(args.size() > 1);
+
+ std::vector<std::string>::const_iterator i = args.begin();
+
+ i++; // Get rid of subcommand
+
+ std::string variable = *i;
+ i++;
+ cmsys::Glob g;
+ g.SetRecurse(recurse);
+
+ bool explicitFollowSymlinks = false;
+ cmPolicies::PolicyStatus status =
+ this->Makefile->GetPolicyStatus(cmPolicies::CMP0009);
+ if(recurse)
+ {
+ switch(status)
+ {
+ case cmPolicies::NEW:
+ g.RecurseThroughSymlinksOff();
+ break;
+ case cmPolicies::OLD:
+ case cmPolicies::WARN:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ g.RecurseThroughSymlinksOn();
+ break;
+ }
+ }
+
+ std::string output = "";
+ bool first = true;
+ for ( ; i != args.end(); ++i )
+ {
+ if ( recurse && (*i == "FOLLOW_SYMLINKS") )
+ {
+ explicitFollowSymlinks = true;
+ g.RecurseThroughSymlinksOn();
+ ++i;
+ if ( i == args.end() )
+ {
+ this->SetError(
+ "GLOB_RECURSE requires a glob expression after FOLLOW_SYMLINKS");
+ return false;
+ }
+ }
+
+ if ( *i == "RELATIVE" )
+ {
+ ++i; // skip RELATIVE
+ if ( i == args.end() )
+ {
+ this->SetError("GLOB requires a directory after the RELATIVE tag");
+ return false;
+ }
+ g.SetRelative(i->c_str());
+ ++i;
+ if(i == args.end())
+ {
+ this->SetError("GLOB requires a glob expression after the directory");
+ return false;
+ }
+ }
+
+ if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
+ {
+ std::string expr = this->Makefile->GetCurrentDirectory();
+ // Handle script mode
+ if ( expr.size() > 0 )
+ {
+ expr += "/" + *i;
+ g.FindFiles(expr);
+ }
+ else
+ {
+ g.FindFiles(*i);
+ }
+ }
+ else
+ {
+ g.FindFiles(*i);
+ }
+
+ std::vector<std::string>::size_type cc;
+ std::vector<std::string>& files = g.GetFiles();
+ for ( cc = 0; cc < files.size(); cc ++ )
+ {
+ if ( !first )
+ {
+ output += ";";
+ }
+ output += files[cc];
+ first = false;
+ }
+ }
+
+ if(recurse && !explicitFollowSymlinks)
+ {
+ switch (status)
+ {
+ case cmPolicies::NEW:
+ // Correct behavior, yay!
+ break;
+ case cmPolicies::OLD:
+ // Probably not really the expected behavior, but the author explicitly
+ // asked for the old behavior... no warning.
+ case cmPolicies::WARN:
+ // Possibly unexpected old behavior *and* we actually traversed
+ // symlinks without being explicitly asked to: warn the author.
+ if(g.GetFollowedSymlinkCount() != 0)
+ {
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ this->Makefile->GetPolicies()->
+ GetPolicyWarning(cmPolicies::CMP0009));
+ }
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ this->SetError("policy CMP0009 error");
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ this->Makefile->GetPolicies()->
+ GetRequiredPolicyError(cmPolicies::CMP0009));
+ return false;
+ }
+ }
+
+ this->Makefile->AddDefinition(variable, output.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleMakeDirectoryCommand(
+ std::vector<std::string> const& args)
+{
+ // File command has at least one argument
+ assert(args.size() > 1);
+
+ std::vector<std::string>::const_iterator i = args.begin();
+
+ i++; // Get rid of subcommand
+
+ std::string expr;
+ for ( ; i != args.end(); ++i )
+ {
+ const std::string* cdir = &(*i);
+ if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
+ {
+ expr = this->Makefile->GetCurrentDirectory();
+ expr += "/" + *i;
+ cdir = &expr;
+ }
+ if ( !this->Makefile->CanIWriteThisFile(cdir->c_str()) )
+ {
+ std::string e = "attempted to create a directory: " + *cdir
+ + " into a source directory.";
+ this->SetError(e);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+ if ( !cmSystemTools::MakeDirectory(cdir->c_str()) )
+ {
+ std::string error = "problem creating directory: " + *cdir;
+ this->SetError(error);
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmFileCommand::HandleDifferentCommand(std::vector<std::string> const& args)
+{
+ /*
+ FILE(DIFFERENT <variable> FILES <lhs> <rhs>)
+ */
+
+ // Evaluate arguments.
+ const char* file_lhs = 0;
+ const char* file_rhs = 0;
+ const char* var = 0;
+ enum Doing { DoingNone, DoingVar, DoingFileLHS, DoingFileRHS };
+ Doing doing = DoingVar;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "FILES")
+ {
+ doing = DoingFileLHS;
+ }
+ else if(doing == DoingVar)
+ {
+ var = args[i].c_str();
+ doing = DoingNone;
+ }
+ else if(doing == DoingFileLHS)
+ {
+ file_lhs = args[i].c_str();
+ doing = DoingFileRHS;
+ }
+ else if(doing == DoingFileRHS)
+ {
+ file_rhs = args[i].c_str();
+ doing = DoingNone;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "DIFFERENT given unknown argument " << args[i];
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ if(!var)
+ {
+ this->SetError("DIFFERENT not given result variable name.");
+ return false;
+ }
+ if(!file_lhs || !file_rhs)
+ {
+ this->SetError("DIFFERENT not given FILES option with two file names.");
+ return false;
+ }
+
+ // Compare the files.
+ const char* result =
+ cmSystemTools::FilesDiffer(file_lhs, file_rhs)? "1" : "0";
+ this->Makefile->AddDefinition(var, result);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+// File installation helper class.
+struct cmFileCopier
+{
+ cmFileCopier(cmFileCommand* command, const char* name = "COPY"):
+ FileCommand(command),
+ Makefile(command->GetMakefile()),
+ Name(name),
+ Always(false),
+ MatchlessFiles(true),
+ FilePermissions(0),
+ DirPermissions(0),
+ CurrentMatchRule(0),
+ UseGivenPermissionsFile(false),
+ UseGivenPermissionsDir(false),
+ UseSourcePermissions(true),
+ Doing(DoingNone)
+ {
+ }
+ virtual ~cmFileCopier() {}
+
+ bool Run(std::vector<std::string> const& args);
+protected:
+
+ cmFileCommand* FileCommand;
+ cmMakefile* Makefile;
+ const char* Name;
+ bool Always;
+ cmFileTimeComparison FileTimes;
+
+ // Whether to install a file not matching any expression.
+ bool MatchlessFiles;
+
+ // Permissions for files and directories installed by this object.
+ mode_t FilePermissions;
+ mode_t DirPermissions;
+
+ // Properties set by pattern and regex match rules.
+ struct MatchProperties
+ {
+ bool Exclude;
+ mode_t Permissions;
+ MatchProperties(): Exclude(false), Permissions(0) {}
+ };
+ struct MatchRule;
+ friend struct MatchRule;
+ struct MatchRule
+ {
+ cmsys::RegularExpression Regex;
+ MatchProperties Properties;
+ std::string RegexString;
+ MatchRule(std::string const& regex):
+ Regex(regex.c_str()), RegexString(regex) {}
+ };
+ std::vector<MatchRule> MatchRules;
+
+ // Get the properties from rules matching this input file.
+ MatchProperties CollectMatchProperties(const char* file)
+ {
+ // Match rules are case-insensitive on some platforms.
+#if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
+ std::string lower = cmSystemTools::LowerCase(file);
+ const char* file_to_match = lower.c_str();
+#else
+ const char* file_to_match = file;
+#endif
+
+ // Collect properties from all matching rules.
+ bool matched = false;
+ MatchProperties result;
+ for(std::vector<MatchRule>::iterator mr = this->MatchRules.begin();
+ mr != this->MatchRules.end(); ++mr)
+ {
+ if(mr->Regex.find(file_to_match))
+ {
+ matched = true;
+ result.Exclude |= mr->Properties.Exclude;
+ result.Permissions |= mr->Properties.Permissions;
+ }
+ }
+ if(!matched && !this->MatchlessFiles)
+ {
+ result.Exclude = !cmSystemTools::FileIsDirectory(file);
+ }
+ return result;
+ }
+
+ bool SetPermissions(const char* toFile, mode_t permissions)
+ {
+ if(permissions && !cmSystemTools::SetPermissions(toFile, permissions))
+ {
+ cmOStringStream e;
+ e << this->Name << " cannot set permissions on \"" << toFile << "\"";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+ return true;
+ }
+
+ // Translate an argument to a permissions bit.
+ bool CheckPermissions(std::string const& arg, mode_t& permissions)
+ {
+ if(arg == "OWNER_READ") { permissions |= mode_owner_read; }
+ else if(arg == "OWNER_WRITE") { permissions |= mode_owner_write; }
+ else if(arg == "OWNER_EXECUTE") { permissions |= mode_owner_execute; }
+ else if(arg == "GROUP_READ") { permissions |= mode_group_read; }
+ else if(arg == "GROUP_WRITE") { permissions |= mode_group_write; }
+ else if(arg == "GROUP_EXECUTE") { permissions |= mode_group_execute; }
+ else if(arg == "WORLD_READ") { permissions |= mode_world_read; }
+ else if(arg == "WORLD_WRITE") { permissions |= mode_world_write; }
+ else if(arg == "WORLD_EXECUTE") { permissions |= mode_world_execute; }
+ else if(arg == "SETUID") { permissions |= mode_setuid; }
+ else if(arg == "SETGID") { permissions |= mode_setgid; }
+ else
+ {
+ cmOStringStream e;
+ e << this->Name << " given invalid permission \"" << arg << "\".";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+ return true;
+ }
+
+ bool InstallSymlink(const char* fromFile, const char* toFile);
+ bool InstallFile(const char* fromFile, const char* toFile,
+ MatchProperties const& match_properties);
+ bool InstallDirectory(const char* source, const char* destination,
+ MatchProperties const& match_properties);
+ virtual bool Install(const char* fromFile, const char* toFile);
+ virtual std::string const& ToName(std::string const& fromName)
+ { return fromName; }
+
+ enum Type
+ {
+ TypeFile,
+ TypeDir,
+ TypeLink
+ };
+ virtual void ReportCopy(const char*, Type, bool) {}
+ virtual bool ReportMissing(const char* fromFile)
+ {
+ // The input file does not exist and installation is not optional.
+ cmOStringStream e;
+ e << this->Name << " cannot find \"" << fromFile << "\".";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+
+ MatchRule* CurrentMatchRule;
+ bool UseGivenPermissionsFile;
+ bool UseGivenPermissionsDir;
+ bool UseSourcePermissions;
+ std::string Destination;
+ std::vector<std::string> Files;
+ int Doing;
+
+ virtual bool Parse(std::vector<std::string> const& args);
+ enum
+ {
+ DoingNone,
+ DoingError,
+ DoingDestination,
+ DoingFiles,
+ DoingPattern,
+ DoingRegex,
+ DoingPermissionsFile,
+ DoingPermissionsDir,
+ DoingPermissionsMatch,
+ DoingLast1
+ };
+ virtual bool CheckKeyword(std::string const& arg);
+ virtual bool CheckValue(std::string const& arg);
+
+ void NotBeforeMatch(std::string const& arg)
+ {
+ cmOStringStream e;
+ e << "option " << arg << " may not appear before PATTERN or REGEX.";
+ this->FileCommand->SetError(e.str());
+ this->Doing = DoingError;
+ }
+ void NotAfterMatch(std::string const& arg)
+ {
+ cmOStringStream e;
+ e << "option " << arg << " may not appear after PATTERN or REGEX.";
+ this->FileCommand->SetError(e.str());
+ this->Doing = DoingError;
+ }
+ virtual void DefaultFilePermissions()
+ {
+ // Use read/write permissions.
+ this->FilePermissions = 0;
+ this->FilePermissions |= mode_owner_read;
+ this->FilePermissions |= mode_owner_write;
+ this->FilePermissions |= mode_group_read;
+ this->FilePermissions |= mode_world_read;
+ }
+ virtual void DefaultDirectoryPermissions()
+ {
+ // Use read/write/executable permissions.
+ this->DirPermissions = 0;
+ this->DirPermissions |= mode_owner_read;
+ this->DirPermissions |= mode_owner_write;
+ this->DirPermissions |= mode_owner_execute;
+ this->DirPermissions |= mode_group_read;
+ this->DirPermissions |= mode_group_execute;
+ this->DirPermissions |= mode_world_read;
+ this->DirPermissions |= mode_world_execute;
+ }
+};
+
+//----------------------------------------------------------------------------
+bool cmFileCopier::Parse(std::vector<std::string> const& args)
+{
+ this->Doing = DoingFiles;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ // Check this argument.
+ if(!this->CheckKeyword(args[i]) &&
+ !this->CheckValue(args[i]))
+ {
+ cmOStringStream e;
+ e << "called with unknown argument \"" << args[i] << "\".";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+
+ // Quit if an argument is invalid.
+ if(this->Doing == DoingError)
+ {
+ return false;
+ }
+ }
+
+ // Require a destination.
+ if(this->Destination.empty())
+ {
+ cmOStringStream e;
+ e << this->Name << " given no DESTINATION";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+
+ // If file permissions were not specified set default permissions.
+ if(!this->UseGivenPermissionsFile && !this->UseSourcePermissions)
+ {
+ this->DefaultFilePermissions();
+ }
+
+ // If directory permissions were not specified set default permissions.
+ if(!this->UseGivenPermissionsDir && !this->UseSourcePermissions)
+ {
+ this->DefaultDirectoryPermissions();
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCopier::CheckKeyword(std::string const& arg)
+{
+ if(arg == "DESTINATION")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingDestination;
+ }
+ }
+ else if(arg == "PATTERN")
+ {
+ this->Doing = DoingPattern;
+ }
+ else if(arg == "REGEX")
+ {
+ this->Doing = DoingRegex;
+ }
+ else if(arg == "EXCLUDE")
+ {
+ // Add this property to the current match rule.
+ if(this->CurrentMatchRule)
+ {
+ this->CurrentMatchRule->Properties.Exclude = true;
+ this->Doing = DoingNone;
+ }
+ else
+ {
+ this->NotBeforeMatch(arg);
+ }
+ }
+ else if(arg == "PERMISSIONS")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->Doing = DoingPermissionsMatch;
+ }
+ else
+ {
+ this->NotBeforeMatch(arg);
+ }
+ }
+ else if(arg == "FILE_PERMISSIONS")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingPermissionsFile;
+ this->UseGivenPermissionsFile = true;
+ }
+ }
+ else if(arg == "DIRECTORY_PERMISSIONS")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingPermissionsDir;
+ this->UseGivenPermissionsDir = true;
+ }
+ }
+ else if(arg == "USE_SOURCE_PERMISSIONS")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingNone;
+ this->UseSourcePermissions = true;
+ }
+ }
+ else if(arg == "NO_SOURCE_PERMISSIONS")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingNone;
+ this->UseSourcePermissions = false;
+ }
+ }
+ else if(arg == "FILES_MATCHING")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingNone;
+ this->MatchlessFiles = false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCopier::CheckValue(std::string const& arg)
+{
+ switch(this->Doing)
+ {
+ case DoingFiles:
+ if(arg.empty() || cmSystemTools::FileIsFullPath(arg.c_str()))
+ {
+ this->Files.push_back(arg);
+ }
+ else
+ {
+ std::string file = this->Makefile->GetCurrentDirectory();
+ file += "/" + arg;
+ this->Files.push_back(file);
+ }
+ break;
+ case DoingDestination:
+ if(arg.empty() || cmSystemTools::FileIsFullPath(arg.c_str()))
+ {
+ this->Destination = arg;
+ }
+ else
+ {
+ this->Destination = this->Makefile->GetCurrentOutputDirectory();
+ this->Destination += "/" + arg;
+ }
+ this->Doing = DoingNone;
+ break;
+ case DoingPattern:
+ {
+ // Convert the pattern to a regular expression. Require a
+ // leading slash and trailing end-of-string in the matched
+ // string to make sure the pattern matches only whole file
+ // names.
+ std::string regex = "/";
+ regex += cmsys::Glob::PatternToRegex(arg, false);
+ regex += "$";
+ this->MatchRules.push_back(MatchRule(regex));
+ this->CurrentMatchRule = &*(this->MatchRules.end()-1);
+ if(this->CurrentMatchRule->Regex.is_valid())
+ {
+ this->Doing = DoingNone;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "could not compile PATTERN \"" << arg << "\".";
+ this->FileCommand->SetError(e.str());
+ this->Doing = DoingError;
+ }
+ }
+ break;
+ case DoingRegex:
+ this->MatchRules.push_back(MatchRule(arg));
+ this->CurrentMatchRule = &*(this->MatchRules.end()-1);
+ if(this->CurrentMatchRule->Regex.is_valid())
+ {
+ this->Doing = DoingNone;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "could not compile REGEX \"" << arg << "\".";
+ this->FileCommand->SetError(e.str());
+ this->Doing = DoingError;
+ }
+ break;
+ case DoingPermissionsFile:
+ if(!this->CheckPermissions(arg, this->FilePermissions))
+ {
+ this->Doing = DoingError;
+ }
+ break;
+ case DoingPermissionsDir:
+ if(!this->CheckPermissions(arg, this->DirPermissions))
+ {
+ this->Doing = DoingError;
+ }
+ break;
+ case DoingPermissionsMatch:
+ if(!this->CheckPermissions(
+ arg, this->CurrentMatchRule->Properties.Permissions))
+ {
+ this->Doing = DoingError;
+ }
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCopier::Run(std::vector<std::string> const& args)
+{
+ if(!this->Parse(args))
+ {
+ return false;
+ }
+
+ std::vector<std::string> const& files = this->Files;
+ for(std::vector<std::string>::size_type i = 0; i < files.size(); ++i)
+ {
+ // Split the input file into its directory and name components.
+ std::vector<std::string> fromPathComponents;
+ cmSystemTools::SplitPath(files[i].c_str(), fromPathComponents);
+ std::string fromName = *(fromPathComponents.end()-1);
+ std::string fromDir = cmSystemTools::JoinPath(fromPathComponents.begin(),
+ fromPathComponents.end()-1);
+
+ // Compute the full path to the destination file.
+ std::string toFile = this->Destination;
+ std::string const& toName = this->ToName(fromName);
+ if(!toName.empty())
+ {
+ toFile += "/";
+ toFile += toName;
+ }
+
+ // Construct the full path to the source file. The file name may
+ // have been changed above.
+ std::string fromFile = fromDir;
+ if(!fromName.empty())
+ {
+ fromFile += "/";
+ fromFile += fromName;
+ }
+
+ if(!this->Install(fromFile.c_str(), toFile.c_str()))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCopier::Install(const char* fromFile, const char* toFile)
+{
+ if(!*fromFile)
+ {
+ cmOStringStream e;
+ e << "INSTALL encountered an empty string input file name.";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+
+ // Collect any properties matching this file name.
+ MatchProperties match_properties = this->CollectMatchProperties(fromFile);
+
+ // Skip the file if it is excluded.
+ if(match_properties.Exclude)
+ {
+ return true;
+ }
+
+ if(cmSystemTools::SameFile(fromFile, toFile))
+ {
+ return true;
+ }
+ else if(cmSystemTools::FileIsSymlink(fromFile))
+ {
+ return this->InstallSymlink(fromFile, toFile);
+ }
+ else if(cmSystemTools::FileIsDirectory(fromFile))
+ {
+ return this->InstallDirectory(fromFile, toFile, match_properties);
+ }
+ else if(cmSystemTools::FileExists(fromFile))
+ {
+ return this->InstallFile(fromFile, toFile, match_properties);
+ }
+ return this->ReportMissing(fromFile);
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCopier::InstallSymlink(const char* fromFile, const char* toFile)
+{
+ // Read the original symlink.
+ std::string symlinkTarget;
+ if(!cmSystemTools::ReadSymlink(fromFile, symlinkTarget))
+ {
+ cmOStringStream e;
+ e << this->Name << " cannot read symlink \"" << fromFile
+ << "\" to duplicate at \"" << toFile << "\".";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+
+ // Compare the symlink value to that at the destination if not
+ // always installing.
+ bool copy = true;
+ if(!this->Always)
+ {
+ std::string oldSymlinkTarget;
+ if(cmSystemTools::ReadSymlink(toFile, oldSymlinkTarget))
+ {
+ if(symlinkTarget == oldSymlinkTarget)
+ {
+ copy = false;
+ }
+ }
+ }
+
+ // Inform the user about this file installation.
+ this->ReportCopy(toFile, TypeLink, copy);
+
+ if(copy)
+ {
+ // Remove the destination file so we can always create the symlink.
+ cmSystemTools::RemoveFile(toFile);
+
+ // Create the symlink.
+ if(!cmSystemTools::CreateSymlink(symlinkTarget.c_str(), toFile))
+ {
+ cmOStringStream e;
+ e << this->Name << " cannot duplicate symlink \"" << fromFile
+ << "\" at \"" << toFile << "\".";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCopier::InstallFile(const char* fromFile, const char* toFile,
+ MatchProperties const& match_properties)
+{
+ // Determine whether we will copy the file.
+ bool copy = true;
+ if(!this->Always)
+ {
+ // If both files exist with the same time do not copy.
+ if(!this->FileTimes.FileTimesDiffer(fromFile, toFile))
+ {
+ copy = false;
+ }
+ }
+
+ // Inform the user about this file installation.
+ this->ReportCopy(toFile, TypeFile, copy);
+
+ // Copy the file.
+ if(copy && !cmSystemTools::CopyAFile(fromFile, toFile, true))
+ {
+ cmOStringStream e;
+ e << this->Name << " cannot copy file \"" << fromFile
+ << "\" to \"" << toFile << "\".";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+
+ // Set the file modification time of the destination file.
+ if(copy && !this->Always)
+ {
+ // Add write permission so we can set the file time.
+ // Permissions are set unconditionally below anyway.
+ mode_t perm = 0;
+ if(cmSystemTools::GetPermissions(toFile, perm))
+ {
+ cmSystemTools::SetPermissions(toFile, perm | mode_owner_write);
+ }
+ if (!cmSystemTools::CopyFileTime(fromFile, toFile))
+ {
+ cmOStringStream e;
+ e << this->Name << " cannot set modification time on \""
+ << toFile << "\"";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+ }
+
+ // Set permissions of the destination file.
+ mode_t permissions = (match_properties.Permissions?
+ match_properties.Permissions : this->FilePermissions);
+ if(!permissions)
+ {
+ // No permissions were explicitly provided but the user requested
+ // that the source file permissions be used.
+ cmSystemTools::GetPermissions(fromFile, permissions);
+ }
+ return this->SetPermissions(toFile, permissions);
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCopier::InstallDirectory(const char* source,
+ const char* destination,
+ MatchProperties const& match_properties)
+{
+ // Inform the user about this directory installation.
+ this->ReportCopy(destination, TypeDir,
+ !cmSystemTools::FileIsDirectory(destination));
+
+ // Make sure the destination directory exists.
+ if(!cmSystemTools::MakeDirectory(destination))
+ {
+ cmOStringStream e;
+ e << this->Name << " cannot make directory \"" << destination << "\": "
+ << cmSystemTools::GetLastSystemError();
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+
+ // Compute the requested permissions for the destination directory.
+ mode_t permissions = (match_properties.Permissions?
+ match_properties.Permissions : this->DirPermissions);
+ if(!permissions)
+ {
+ // No permissions were explicitly provided but the user requested
+ // that the source directory permissions be used.
+ cmSystemTools::GetPermissions(source, permissions);
+ }
+
+ // Compute the set of permissions required on this directory to
+ // recursively install files and subdirectories safely.
+ mode_t required_permissions =
+ mode_owner_read | mode_owner_write | mode_owner_execute;
+
+ // If the required permissions are specified it is safe to set the
+ // final permissions now. Otherwise we must add the required
+ // permissions temporarily during file installation.
+ mode_t permissions_before = 0;
+ mode_t permissions_after = 0;
+ if((permissions & required_permissions) == required_permissions)
+ {
+ permissions_before = permissions;
+ }
+ else
+ {
+ permissions_before = permissions | required_permissions;
+ permissions_after = permissions;
+ }
+
+ // Set the required permissions of the destination directory.
+ if(!this->SetPermissions(destination, permissions_before))
+ {
+ return false;
+ }
+
+ // Load the directory contents to traverse it recursively.
+ cmsys::Directory dir;
+ if(source && *source)
+ {
+ dir.Load(source);
+ }
+ unsigned long numFiles = static_cast<unsigned long>(dir.GetNumberOfFiles());
+ for(unsigned long fileNum = 0; fileNum < numFiles; ++fileNum)
+ {
+ if(!(strcmp(dir.GetFile(fileNum), ".") == 0 ||
+ strcmp(dir.GetFile(fileNum), "..") == 0))
+ {
+ cmsys_stl::string fromPath = source;
+ fromPath += "/";
+ fromPath += dir.GetFile(fileNum);
+ std::string toPath = destination;
+ toPath += "/";
+ toPath += dir.GetFile(fileNum);
+ if(!this->Install(fromPath.c_str(), toPath.c_str()))
+ {
+ return false;
+ }
+ }
+ }
+
+ // Set the requested permissions of the destination directory.
+ return this->SetPermissions(destination, permissions_after);
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleCopyCommand(std::vector<std::string> const& args)
+{
+ cmFileCopier copier(this);
+ return copier.Run(args);
+}
+
+//----------------------------------------------------------------------------
+struct cmFileInstaller: public cmFileCopier
+{
+ cmFileInstaller(cmFileCommand* command):
+ cmFileCopier(command, "INSTALL"),
+ InstallType(cmInstallType_FILES),
+ Optional(false),
+ MessageAlways(false),
+ MessageLazy(false),
+ MessageNever(false),
+ DestDirLength(0)
+ {
+ // Installation does not use source permissions by default.
+ this->UseSourcePermissions = false;
+ // Check whether to copy files always or only if they have changed.
+ this->Always =
+ cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_INSTALL_ALWAYS"));
+ // Get the current manifest.
+ this->Manifest =
+ this->Makefile->GetSafeDefinition("CMAKE_INSTALL_MANIFEST_FILES");
+ }
+ ~cmFileInstaller()
+ {
+ // Save the updated install manifest.
+ this->Makefile->AddDefinition("CMAKE_INSTALL_MANIFEST_FILES",
+ this->Manifest.c_str());
+ }
+
+protected:
+ cmInstallType InstallType;
+ bool Optional;
+ bool MessageAlways;
+ bool MessageLazy;
+ bool MessageNever;
+ int DestDirLength;
+ std::string Rename;
+
+ std::string Manifest;
+ void ManifestAppend(std::string const& file)
+ {
+ this->Manifest += ";";
+ this->Manifest += file.substr(this->DestDirLength);
+ }
+
+ virtual std::string const& ToName(std::string const& fromName)
+ { return this->Rename.empty()? fromName : this->Rename; }
+
+ virtual void ReportCopy(const char* toFile, Type type, bool copy)
+ {
+ if(!this->MessageNever && (copy || !this->MessageLazy))
+ {
+ std::string message = (copy? "Installing: " : "Up-to-date: ");
+ message += toFile;
+ this->Makefile->DisplayStatus(message.c_str(), -1);
+ }
+ if(type != TypeDir)
+ {
+ // Add the file to the manifest.
+ this->ManifestAppend(toFile);
+ }
+ }
+ virtual bool ReportMissing(const char* fromFile)
+ {
+ return (this->Optional ||
+ this->cmFileCopier::ReportMissing(fromFile));
+ }
+ virtual bool Install(const char* fromFile, const char* toFile)
+ {
+ // Support installing from empty source to make a directory.
+ if(this->InstallType == cmInstallType_DIRECTORY && !*fromFile)
+ {
+ return this->InstallDirectory(fromFile, toFile, MatchProperties());
+ }
+ return this->cmFileCopier::Install(fromFile, toFile);
+ }
+
+ virtual bool Parse(std::vector<std::string> const& args);
+ enum
+ {
+ DoingType = DoingLast1,
+ DoingRename,
+ DoingLast2
+ };
+ virtual bool CheckKeyword(std::string const& arg);
+ virtual bool CheckValue(std::string const& arg);
+ virtual void DefaultFilePermissions()
+ {
+ this->cmFileCopier::DefaultFilePermissions();
+ // Add execute permissions based on the target type.
+ switch(this->InstallType)
+ {
+ case cmInstallType_SHARED_LIBRARY:
+ case cmInstallType_MODULE_LIBRARY:
+ if(this->Makefile->IsOn("CMAKE_INSTALL_SO_NO_EXE"))
+ {
+ break;
+ }
+ case cmInstallType_EXECUTABLE:
+ case cmInstallType_PROGRAMS:
+ this->FilePermissions |= mode_owner_execute;
+ this->FilePermissions |= mode_group_execute;
+ this->FilePermissions |= mode_world_execute;
+ break;
+ default: break;
+ }
+ }
+ bool GetTargetTypeFromString(const std::string& stype);
+ bool HandleInstallDestination();
+};
+
+//----------------------------------------------------------------------------
+bool cmFileInstaller::Parse(std::vector<std::string> const& args)
+{
+ if(!this->cmFileCopier::Parse(args))
+ {
+ return false;
+ }
+
+ if(!this->Rename.empty())
+ {
+ if(this->InstallType != cmInstallType_FILES &&
+ this->InstallType != cmInstallType_PROGRAMS)
+ {
+ this->FileCommand->SetError("INSTALL option RENAME may be used "
+ "only with FILES or PROGRAMS.");
+ return false;
+ }
+ if(this->Files.size() > 1)
+ {
+ this->FileCommand->SetError("INSTALL option RENAME may be used "
+ "only with one file.");
+ return false;
+ }
+ }
+
+ if(!this->HandleInstallDestination())
+ {
+ return false;
+ }
+
+ if(((this->MessageAlways?1:0) +
+ (this->MessageLazy?1:0) +
+ (this->MessageNever?1:0)) > 1)
+ {
+ this->FileCommand->SetError("INSTALL options MESSAGE_ALWAYS, "
+ "MESSAGE_LAZY, and MESSAGE_NEVER "
+ "are mutually exclusive.");
+ return false;
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileInstaller::CheckKeyword(std::string const& arg)
+{
+ if(arg == "TYPE")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingType;
+ }
+ }
+ else if(arg == "FILES")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingFiles;
+ }
+ }
+ else if(arg == "RENAME")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingRename;
+ }
+ }
+ else if(arg == "OPTIONAL")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingNone;
+ this->Optional = true;
+ }
+ }
+ else if(arg == "MESSAGE_ALWAYS")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingNone;
+ this->MessageAlways = true;
+ }
+ }
+ else if(arg == "MESSAGE_LAZY")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingNone;
+ this->MessageLazy = true;
+ }
+ }
+ else if(arg == "MESSAGE_NEVER")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ this->Doing = DoingNone;
+ this->MessageNever = true;
+ }
+ }
+ else if(arg == "PERMISSIONS")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->Doing = DoingPermissionsMatch;
+ }
+ else
+ {
+ // file(INSTALL) aliases PERMISSIONS to FILE_PERMISSIONS
+ this->Doing = DoingPermissionsFile;
+ this->UseGivenPermissionsFile = true;
+ }
+ }
+ else if(arg == "DIR_PERMISSIONS")
+ {
+ if(this->CurrentMatchRule)
+ {
+ this->NotAfterMatch(arg);
+ }
+ else
+ {
+ // file(INSTALL) aliases DIR_PERMISSIONS to DIRECTORY_PERMISSIONS
+ this->Doing = DoingPermissionsDir;
+ this->UseGivenPermissionsDir = true;
+ }
+ }
+ else if(arg == "COMPONENTS" || arg == "CONFIGURATIONS" ||
+ arg == "PROPERTIES")
+ {
+ cmOStringStream e;
+ e << "INSTALL called with old-style " << arg << " argument. "
+ << "This script was generated with an older version of CMake. "
+ << "Re-run this cmake version on your build tree.";
+ this->FileCommand->SetError(e.str());
+ this->Doing = DoingError;
+ }
+ else
+ {
+ return this->cmFileCopier::CheckKeyword(arg);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileInstaller::CheckValue(std::string const& arg)
+{
+ switch(this->Doing)
+ {
+ case DoingType:
+ if(!this->GetTargetTypeFromString(arg))
+ {
+ this->Doing = DoingError;
+ }
+ break;
+ case DoingRename:
+ this->Rename = arg;
+ break;
+ default:
+ return this->cmFileCopier::CheckValue(arg);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileInstaller
+::GetTargetTypeFromString(const std::string& stype)
+{
+ if ( stype == "EXECUTABLE" )
+ {
+ this->InstallType = cmInstallType_EXECUTABLE;
+ }
+ else if ( stype == "FILE" )
+ {
+ this->InstallType = cmInstallType_FILES;
+ }
+ else if ( stype == "PROGRAM" )
+ {
+ this->InstallType = cmInstallType_PROGRAMS;
+ }
+ else if ( stype == "STATIC_LIBRARY" )
+ {
+ this->InstallType = cmInstallType_STATIC_LIBRARY;
+ }
+ else if ( stype == "SHARED_LIBRARY" )
+ {
+ this->InstallType = cmInstallType_SHARED_LIBRARY;
+ }
+ else if ( stype == "MODULE" )
+ {
+ this->InstallType = cmInstallType_MODULE_LIBRARY;
+ }
+ else if ( stype == "DIRECTORY" )
+ {
+ this->InstallType = cmInstallType_DIRECTORY;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "Option TYPE given unknown value \"" << stype << "\".";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileInstaller::HandleInstallDestination()
+{
+ std::string& destination = this->Destination;
+
+ // allow for / to be a valid destination
+ if ( destination.size() < 2 && destination != "/" )
+ {
+ this->FileCommand->SetError("called with inappropriate arguments. "
+ "No DESTINATION provided or .");
+ return false;
+ }
+
+ const char* destdir = cmSystemTools::GetEnv("DESTDIR");
+ if ( destdir && *destdir )
+ {
+ std::string sdestdir = destdir;
+ cmSystemTools::ConvertToUnixSlashes(sdestdir);
+ char ch1 = destination[0];
+ char ch2 = destination[1];
+ char ch3 = 0;
+ if ( destination.size() > 2 )
+ {
+ ch3 = destination[2];
+ }
+ int skip = 0;
+ if ( ch1 != '/' )
+ {
+ int relative = 0;
+ if (((ch1 >= 'a' && ch1 <= 'z') || (ch1 >= 'A' && ch1 <= 'Z')) &&
+ ch2 == ':' )
+ {
+ // Assume windows
+ // let's do some destdir magic:
+ skip = 2;
+ if ( ch3 != '/' )
+ {
+ relative = 1;
+ }
+ }
+ else
+ {
+ relative = 1;
+ }
+ if ( relative )
+ {
+ // This is relative path on unix or windows. Since we are doing
+ // destdir, this case does not make sense.
+ this->FileCommand->SetError(
+ "called with relative DESTINATION. This "
+ "does not make sense when using DESTDIR. Specify "
+ "absolute path or remove DESTDIR environment variable.");
+ return false;
+ }
+ }
+ else
+ {
+ if ( ch2 == '/' )
+ {
+ // looks like a network path.
+ std::string message = "called with network path DESTINATION. This "
+ "does not make sense when using DESTDIR. Specify local "
+ "absolute path or remove DESTDIR environment variable."
+ "\nDESTINATION=\n";
+ message += destination;
+ this->FileCommand->SetError(message);
+ return false;
+ }
+ }
+ destination = sdestdir + (destination.c_str() + skip);
+ this->DestDirLength = int(sdestdir.size());
+ }
+
+ if(this->InstallType != cmInstallType_DIRECTORY)
+ {
+ if ( !cmSystemTools::FileExists(destination.c_str()) )
+ {
+ if ( !cmSystemTools::MakeDirectory(destination.c_str()) )
+ {
+ std::string errstring = "cannot create directory: " + destination +
+ ". Maybe need administrative privileges.";
+ this->FileCommand->SetError(errstring);
+ return false;
+ }
+ }
+ if ( !cmSystemTools::FileIsDirectory(destination.c_str()) )
+ {
+ std::string errstring = "INSTALL destination: " + destination +
+ " is not a directory.";
+ this->FileCommand->SetError(errstring);
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmFileCommand::HandleRPathChangeCommand(std::vector<std::string> const& args)
+{
+ // Evaluate arguments.
+ const char* file = 0;
+ const char* oldRPath = 0;
+ const char* newRPath = 0;
+ enum Doing { DoingNone, DoingFile, DoingOld, DoingNew };
+ Doing doing = DoingNone;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "OLD_RPATH")
+ {
+ doing = DoingOld;
+ }
+ else if(args[i] == "NEW_RPATH")
+ {
+ doing = DoingNew;
+ }
+ else if(args[i] == "FILE")
+ {
+ doing = DoingFile;
+ }
+ else if(doing == DoingFile)
+ {
+ file = args[i].c_str();
+ doing = DoingNone;
+ }
+ else if(doing == DoingOld)
+ {
+ oldRPath = args[i].c_str();
+ doing = DoingNone;
+ }
+ else if(doing == DoingNew)
+ {
+ newRPath = args[i].c_str();
+ doing = DoingNone;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "RPATH_CHANGE given unknown argument " << args[i];
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ if(!file)
+ {
+ this->SetError("RPATH_CHANGE not given FILE option.");
+ return false;
+ }
+ if(!oldRPath)
+ {
+ this->SetError("RPATH_CHANGE not given OLD_RPATH option.");
+ return false;
+ }
+ if(!newRPath)
+ {
+ this->SetError("RPATH_CHANGE not given NEW_RPATH option.");
+ return false;
+ }
+ if(!cmSystemTools::FileExists(file, true))
+ {
+ cmOStringStream e;
+ e << "RPATH_CHANGE given FILE \"" << file << "\" that does not exist.";
+ this->SetError(e.str());
+ return false;
+ }
+ bool success = true;
+ cmSystemToolsFileTime* ft = cmSystemTools::FileTimeNew();
+ bool have_ft = cmSystemTools::FileTimeGet(file, ft);
+ std::string emsg;
+ bool changed;
+ if(!cmSystemTools::ChangeRPath(file, oldRPath, newRPath, &emsg, &changed))
+ {
+ cmOStringStream e;
+ e << "RPATH_CHANGE could not write new RPATH:\n"
+ << " " << newRPath << "\n"
+ << "to the file:\n"
+ << " " << file << "\n"
+ << emsg;
+ this->SetError(e.str());
+ success = false;
+ }
+ if(success)
+ {
+ if(changed)
+ {
+ std::string message = "Set runtime path of \"";
+ message += file;
+ message += "\" to \"";
+ message += newRPath;
+ message += "\"";
+ this->Makefile->DisplayStatus(message.c_str(), -1);
+ }
+ if(have_ft)
+ {
+ cmSystemTools::FileTimeSet(file, ft);
+ }
+ }
+ cmSystemTools::FileTimeDelete(ft);
+ return success;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmFileCommand::HandleRPathRemoveCommand(std::vector<std::string> const& args)
+{
+ // Evaluate arguments.
+ const char* file = 0;
+ enum Doing { DoingNone, DoingFile };
+ Doing doing = DoingNone;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "FILE")
+ {
+ doing = DoingFile;
+ }
+ else if(doing == DoingFile)
+ {
+ file = args[i].c_str();
+ doing = DoingNone;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "RPATH_REMOVE given unknown argument " << args[i];
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ if(!file)
+ {
+ this->SetError("RPATH_REMOVE not given FILE option.");
+ return false;
+ }
+ if(!cmSystemTools::FileExists(file, true))
+ {
+ cmOStringStream e;
+ e << "RPATH_REMOVE given FILE \"" << file << "\" that does not exist.";
+ this->SetError(e.str());
+ return false;
+ }
+ bool success = true;
+ cmSystemToolsFileTime* ft = cmSystemTools::FileTimeNew();
+ bool have_ft = cmSystemTools::FileTimeGet(file, ft);
+ std::string emsg;
+ bool removed;
+ if(!cmSystemTools::RemoveRPath(file, &emsg, &removed))
+ {
+ cmOStringStream e;
+ e << "RPATH_REMOVE could not remove RPATH from file:\n"
+ << " " << file << "\n"
+ << emsg;
+ this->SetError(e.str());
+ success = false;
+ }
+ if(success)
+ {
+ if(removed)
+ {
+ std::string message = "Removed runtime path from \"";
+ message += file;
+ message += "\"";
+ this->Makefile->DisplayStatus(message.c_str(), -1);
+ }
+ if(have_ft)
+ {
+ cmSystemTools::FileTimeSet(file, ft);
+ }
+ }
+ cmSystemTools::FileTimeDelete(ft);
+ return success;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmFileCommand::HandleRPathCheckCommand(std::vector<std::string> const& args)
+{
+ // Evaluate arguments.
+ const char* file = 0;
+ const char* rpath = 0;
+ enum Doing { DoingNone, DoingFile, DoingRPath };
+ Doing doing = DoingNone;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "RPATH")
+ {
+ doing = DoingRPath;
+ }
+ else if(args[i] == "FILE")
+ {
+ doing = DoingFile;
+ }
+ else if(doing == DoingFile)
+ {
+ file = args[i].c_str();
+ doing = DoingNone;
+ }
+ else if(doing == DoingRPath)
+ {
+ rpath = args[i].c_str();
+ doing = DoingNone;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "RPATH_CHECK given unknown argument " << args[i];
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ if(!file)
+ {
+ this->SetError("RPATH_CHECK not given FILE option.");
+ return false;
+ }
+ if(!rpath)
+ {
+ this->SetError("RPATH_CHECK not given RPATH option.");
+ return false;
+ }
+
+ // If the file exists but does not have the desired RPath then
+ // delete it. This is used during installation to re-install a file
+ // if its RPath will change.
+ if(cmSystemTools::FileExists(file, true) &&
+ !cmSystemTools::CheckRPath(file, rpath))
+ {
+ cmSystemTools::RemoveFile(file);
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
+{
+ cmFileInstaller installer(this);
+ return installer.Run(args);
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleRelativePathCommand(
+ std::vector<std::string> const& args)
+{
+ if(args.size() != 4 )
+ {
+ this->SetError("RELATIVE_PATH called with incorrect number of arguments");
+ return false;
+ }
+
+ const std::string& outVar = args[1];
+ const std::string& directoryName = args[2];
+ const std::string& fileName = args[3];
+
+ if(!cmSystemTools::FileIsFullPath(directoryName.c_str()))
+ {
+ std::string errstring =
+ "RELATIVE_PATH must be passed a full path to the directory: "
+ + directoryName;
+ this->SetError(errstring);
+ return false;
+ }
+ if(!cmSystemTools::FileIsFullPath(fileName.c_str()))
+ {
+ std::string errstring =
+ "RELATIVE_PATH must be passed a full path to the file: "
+ + fileName;
+ this->SetError(errstring);
+ return false;
+ }
+
+ std::string res = cmSystemTools::RelativePath(directoryName.c_str(),
+ fileName.c_str());
+ this->Makefile->AddDefinition(outVar,
+ res.c_str());
+ return true;
+}
+
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleRename(std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+ {
+ this->SetError("RENAME given incorrect number of arguments.");
+ return false;
+ }
+
+ // Compute full path for old and new names.
+ std::string oldname = args[1];
+ if(!cmsys::SystemTools::FileIsFullPath(oldname.c_str()))
+ {
+ oldname = this->Makefile->GetCurrentDirectory();
+ oldname += "/" + args[1];
+ }
+ std::string newname = args[2];
+ if(!cmsys::SystemTools::FileIsFullPath(newname.c_str()))
+ {
+ newname = this->Makefile->GetCurrentDirectory();
+ newname += "/" + args[2];
+ }
+
+ if(!cmSystemTools::RenameFile(oldname.c_str(), newname.c_str()))
+ {
+ std::string err = cmSystemTools::GetLastSystemError();
+ cmOStringStream e;
+ e << "RENAME failed to rename\n"
+ << " " << oldname << "\n"
+ << "to\n"
+ << " " << newname << "\n"
+ << "because: " << err << "\n";
+ this->SetError(e.str());
+ return false;
+ }
+ return true;
+}
+
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
+ bool recurse)
+{
+
+ std::string message;
+ std::vector<std::string>::const_iterator i = args.begin();
+
+ i++; // Get rid of subcommand
+ for(;i != args.end(); ++i)
+ {
+ std::string fileName = *i;
+ if(!cmsys::SystemTools::FileIsFullPath(fileName.c_str()))
+ {
+ fileName = this->Makefile->GetCurrentDirectory();
+ fileName += "/" + *i;
+ }
+
+ if(cmSystemTools::FileIsDirectory(fileName.c_str()) &&
+ !cmSystemTools::FileIsSymlink(fileName.c_str()) && recurse)
+ {
+ cmSystemTools::RemoveADirectory(fileName.c_str());
+ }
+ else
+ {
+ cmSystemTools::RemoveFile(fileName.c_str());
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleCMakePathCommand(std::vector<std::string>
+ const& args,
+ bool nativePath)
+{
+ std::vector<std::string>::const_iterator i = args.begin();
+ if(args.size() != 3)
+ {
+ this->SetError("FILE([TO_CMAKE_PATH|TO_NATIVE_PATH] path result) must be "
+ "called with exactly three arguments.");
+ return false;
+ }
+ i++; // Get rid of subcommand
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ char pathSep = ';';
+#else
+ char pathSep = ':';
+#endif
+ std::vector<cmsys::String> path = cmSystemTools::SplitString(i->c_str(),
+ pathSep);
+ i++;
+ const char* var = i->c_str();
+ std::string value;
+ for(std::vector<cmsys::String>::iterator j = path.begin();
+ j != path.end(); ++j)
+ {
+ if(j != path.begin())
+ {
+ value += ";";
+ }
+ if(!nativePath)
+ {
+ cmSystemTools::ConvertToUnixSlashes(*j);
+ }
+ else
+ {
+ *j = cmSystemTools::ConvertToOutputPath(j->c_str());
+ // remove double quotes in the path
+ cmsys::String& s = *j;
+
+ if(s.size() > 1 && s[0] == '\"' && s[s.size()-1] == '\"')
+ {
+ s = s.substr(1,s.size()-2);
+ }
+ }
+ value += *j;
+ }
+ this->Makefile->AddDefinition(var, value.c_str());
+ return true;
+}
+
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+
+// Stuff for curl download/upload
+typedef std::vector<char> cmFileCommandVectorOfChar;
+
+namespace {
+
+ size_t
+ cmWriteToFileCallback(void *ptr, size_t size, size_t nmemb,
+ void *data)
+ {
+ int realsize = (int)(size * nmemb);
+ cmsys::ofstream* fout = static_cast<cmsys::ofstream*>(data);
+ const char* chPtr = static_cast<char*>(ptr);
+ fout->write(chPtr, realsize);
+ return realsize;
+ }
+
+
+ size_t
+ cmWriteToMemoryCallback(void *ptr, size_t size, size_t nmemb,
+ void *data)
+ {
+ int realsize = (int)(size * nmemb);
+ cmFileCommandVectorOfChar *vec
+ = static_cast<cmFileCommandVectorOfChar*>(data);
+ const char* chPtr = static_cast<char*>(ptr);
+ vec->insert(vec->end(), chPtr, chPtr + realsize);
+ return realsize;
+ }
+
+
+ static size_t
+ cmFileCommandCurlDebugCallback(CURL *, curl_infotype, char *chPtr,
+ size_t size, void *data)
+ {
+ cmFileCommandVectorOfChar *vec
+ = static_cast<cmFileCommandVectorOfChar*>(data);
+ vec->insert(vec->end(), chPtr, chPtr + size);
+ return size;
+ }
+
+
+ class cURLProgressHelper
+ {
+ public:
+ cURLProgressHelper(cmFileCommand *fc, const char *text)
+ {
+ this->CurrentPercentage = -1;
+ this->FileCommand = fc;
+ this->Text = text;
+ }
+
+ bool UpdatePercentage(double value, double total, std::string &status)
+ {
+ int OldPercentage = this->CurrentPercentage;
+
+ if (total > 0.0)
+ {
+ this->CurrentPercentage = static_cast<int>(value/total*100.0 + 0.5);
+ if(this->CurrentPercentage > 100)
+ {
+ // Avoid extra progress reports for unexpected data beyond total.
+ this->CurrentPercentage = 100;
+ }
+ }
+
+ bool updated = (OldPercentage != this->CurrentPercentage);
+
+ if (updated)
+ {
+ cmOStringStream oss;
+ oss << "[" << this->Text << " " << this->CurrentPercentage
+ << "% complete]";
+ status = oss.str();
+ }
+
+ return updated;
+ }
+
+ cmFileCommand *GetFileCommand()
+ {
+ return this->FileCommand;
+ }
+
+ private:
+ int CurrentPercentage;
+ cmFileCommand *FileCommand;
+ std::string Text;
+ };
+
+
+ static int
+ cmFileDownloadProgressCallback(void *clientp,
+ double dltotal, double dlnow,
+ double ultotal, double ulnow)
+ {
+ cURLProgressHelper *helper =
+ reinterpret_cast<cURLProgressHelper *>(clientp);
+
+ static_cast<void>(ultotal);
+ static_cast<void>(ulnow);
+
+ std::string status;
+ if (helper->UpdatePercentage(dlnow, dltotal, status))
+ {
+ cmFileCommand *fc = helper->GetFileCommand();
+ cmMakefile *mf = fc->GetMakefile();
+ mf->DisplayStatus(status.c_str(), -1);
+ }
+
+ return 0;
+ }
+
+
+ static int
+ cmFileUploadProgressCallback(void *clientp,
+ double dltotal, double dlnow,
+ double ultotal, double ulnow)
+ {
+ cURLProgressHelper *helper =
+ reinterpret_cast<cURLProgressHelper *>(clientp);
+
+ static_cast<void>(dltotal);
+ static_cast<void>(dlnow);
+
+ std::string status;
+ if (helper->UpdatePercentage(ulnow, ultotal, status))
+ {
+ cmFileCommand *fc = helper->GetFileCommand();
+ cmMakefile *mf = fc->GetMakefile();
+ mf->DisplayStatus(status.c_str(), -1);
+ }
+
+ return 0;
+ }
+}
+
+
+namespace {
+
+ class cURLEasyGuard
+ {
+ public:
+ cURLEasyGuard(CURL * easy)
+ : Easy(easy)
+ {}
+
+ ~cURLEasyGuard(void)
+ {
+ if (this->Easy)
+ {
+ ::curl_easy_cleanup(this->Easy);
+ }
+ }
+
+ inline void release(void)
+ {
+ this->Easy = 0;
+ return;
+ }
+
+ private:
+ ::CURL * Easy;
+ };
+
+}
+#endif
+
+
+#define check_curl_result(result, errstr) \
+ if (result != CURLE_OK) \
+ { \
+ std::string e(errstr); \
+ e += ::curl_easy_strerror(result); \
+ this->SetError(e); \
+ return false; \
+ }
+
+
+bool
+cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ std::vector<std::string>::const_iterator i = args.begin();
+ if(args.size() < 3)
+ {
+ this->SetError("DOWNLOAD must be called with at least three arguments.");
+ return false;
+ }
+ ++i; // Get rid of subcommand
+ std::string url = *i;
+ ++i;
+ std::string file = *i;
+ ++i;
+
+ long timeout = 0;
+ long inactivity_timeout = 0;
+ std::string verboseLog;
+ std::string statusVar;
+ bool tls_verify = this->Makefile->IsOn("CMAKE_TLS_VERIFY");
+ const char* cainfo = this->Makefile->GetDefinition("CMAKE_TLS_CAINFO");
+ std::string expectedHash;
+ std::string hashMatchMSG;
+ cmsys::auto_ptr<cmCryptoHash> hash;
+ bool showProgress = false;
+
+ while(i != args.end())
+ {
+ if(*i == "TIMEOUT")
+ {
+ ++i;
+ if(i != args.end())
+ {
+ timeout = atol(i->c_str());
+ }
+ else
+ {
+ this->SetError("DOWNLOAD missing time for TIMEOUT.");
+ return false;
+ }
+ }
+ else if(*i == "INACTIVITY_TIMEOUT")
+ {
+ ++i;
+ if(i != args.end())
+ {
+ inactivity_timeout = atol(i->c_str());
+ }
+ else
+ {
+ this->SetError("DOWNLOAD missing time for INACTIVITY_TIMEOUT.");
+ return false;
+ }
+ }
+ else if(*i == "LOG")
+ {
+ ++i;
+ if( i == args.end())
+ {
+ this->SetError("DOWNLOAD missing VAR for LOG.");
+ return false;
+ }
+ verboseLog = *i;
+ }
+ else if(*i == "STATUS")
+ {
+ ++i;
+ if( i == args.end())
+ {
+ this->SetError("DOWNLOAD missing VAR for STATUS.");
+ return false;
+ }
+ statusVar = *i;
+ }
+ else if(*i == "TLS_VERIFY")
+ {
+ ++i;
+ if(i != args.end())
+ {
+ tls_verify = cmSystemTools::IsOn(i->c_str());
+ }
+ else
+ {
+ this->SetError("TLS_VERIFY missing bool value.");
+ return false;
+ }
+ }
+ else if(*i == "TLS_CAINFO")
+ {
+ ++i;
+ if(i != args.end())
+ {
+ cainfo = i->c_str();
+ }
+ else
+ {
+ this->SetError("TLS_CAFILE missing file value.");
+ return false;
+ }
+ }
+ else if(*i == "EXPECTED_MD5")
+ {
+ ++i;
+ if( i == args.end())
+ {
+ this->SetError("DOWNLOAD missing sum value for EXPECTED_MD5.");
+ return false;
+ }
+ hash = cmsys::auto_ptr<cmCryptoHash>(cmCryptoHash::New("MD5"));
+ hashMatchMSG = "MD5 sum";
+ expectedHash = cmSystemTools::LowerCase(*i);
+ }
+ else if(*i == "SHOW_PROGRESS")
+ {
+ showProgress = true;
+ }
+ else if(*i == "EXPECTED_HASH")
+ {
+ ++i;
+ if(i == args.end())
+ {
+ this->SetError("DOWNLOAD missing ALGO=value for EXPECTED_HASH.");
+ return false;
+ }
+ std::string::size_type pos = i->find("=");
+ if(pos == std::string::npos)
+ {
+ std::string err =
+ "DOWNLOAD EXPECTED_HASH expects ALGO=value but got: ";
+ err += *i;
+ this->SetError(err);
+ return false;
+ }
+ std::string algo = i->substr(0, pos);
+ expectedHash = cmSystemTools::LowerCase(i->substr(pos+1));
+ hash = cmsys::auto_ptr<cmCryptoHash>(cmCryptoHash::New(algo.c_str()));
+ if(!hash.get())
+ {
+ std::string err = "DOWNLOAD EXPECTED_HASH given unknown ALGO: ";
+ err += algo;
+ this->SetError(err);
+ return false;
+ }
+ hashMatchMSG = algo + " hash";
+ }
+ ++i;
+ }
+ // If file exists already, and caller specified an expected md5 or sha,
+ // and the existing file already has the expected hash, then simply
+ // return.
+ //
+ if(cmSystemTools::FileExists(file.c_str()) && hash.get())
+ {
+ std::string msg;
+ std::string actualHash = hash->HashFile(file);
+ if(actualHash == expectedHash)
+ {
+ msg = "returning early; file already exists with expected ";
+ msg += hashMatchMSG;
+ msg += "\"";
+ if(statusVar.size())
+ {
+ cmOStringStream result;
+ result << (int)0 << ";\"" << msg;
+ this->Makefile->AddDefinition(statusVar,
+ result.str().c_str());
+ }
+ return true;
+ }
+ }
+ // Make sure parent directory exists so we can write to the file
+ // as we receive downloaded bits from curl...
+ //
+ std::string dir = cmSystemTools::GetFilenamePath(file);
+ if(!cmSystemTools::FileExists(dir.c_str()) &&
+ !cmSystemTools::MakeDirectory(dir.c_str()))
+ {
+ std::string errstring = "DOWNLOAD error: cannot create directory '"
+ + dir + "' - Specify file by full path name and verify that you "
+ "have directory creation and file write privileges.";
+ this->SetError(errstring);
+ return false;
+ }
+
+ cmsys::ofstream fout(file.c_str(), std::ios::binary);
+ if(!fout)
+ {
+ this->SetError("DOWNLOAD cannot open file for write.");
+ return false;
+ }
+
+ ::CURL *curl;
+ ::curl_global_init(CURL_GLOBAL_DEFAULT);
+ curl = ::curl_easy_init();
+ if(!curl)
+ {
+ this->SetError("DOWNLOAD error initializing curl.");
+ return false;
+ }
+
+ cURLEasyGuard g_curl(curl);
+ ::CURLcode res = ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+ check_curl_result(res, "DOWNLOAD cannot set url: ");
+
+ // enable HTTP ERROR parsing
+ res = ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+ check_curl_result(res, "DOWNLOAD cannot set http failure option: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/" LIBCURL_VERSION);
+ check_curl_result(res, "DOWNLOAD cannot set user agent option: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
+ cmWriteToFileCallback);
+ check_curl_result(res, "DOWNLOAD cannot set write function: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
+ cmFileCommandCurlDebugCallback);
+ check_curl_result(res, "DOWNLOAD cannot set debug function: ");
+
+ // check to see if TLS verification is requested
+ if(tls_verify)
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
+ check_curl_result(res, "Unable to set TLS/SSL Verify on: ");
+ }
+ else
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
+ check_curl_result(res, "Unable to set TLS/SSL Verify off: ");
+ }
+ // check to see if a CAINFO file has been specified
+ // command arg comes first
+ if(cainfo && *cainfo)
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_CAINFO, cainfo);
+ check_curl_result(res, "Unable to set TLS/SSL Verify CAINFO: ");
+ }
+
+ cmFileCommandVectorOfChar chunkDebug;
+
+ res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&fout);
+ check_curl_result(res, "DOWNLOAD cannot set write data: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
+ check_curl_result(res, "DOWNLOAD cannot set debug data: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ check_curl_result(res, "DOWNLOAD cannot set follow-redirect option: ");
+
+ if(verboseLog.size())
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ check_curl_result(res, "DOWNLOAD cannot set verbose: ");
+ }
+
+ if(timeout > 0)
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout );
+ check_curl_result(res, "DOWNLOAD cannot set timeout: ");
+ }
+
+ if(inactivity_timeout > 0)
+ {
+ // Give up if there is no progress for a long time.
+ ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
+ ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, inactivity_timeout);
+ }
+
+ // Need the progress helper's scope to last through the duration of
+ // the curl_easy_perform call... so this object is declared at function
+ // scope intentionally, rather than inside the "if(showProgress)"
+ // block...
+ //
+ cURLProgressHelper helper(this, "download");
+
+ if(showProgress)
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
+ check_curl_result(res, "DOWNLOAD cannot set noprogress value: ");
+
+ res = ::curl_easy_setopt(curl,
+ CURLOPT_PROGRESSFUNCTION, cmFileDownloadProgressCallback);
+ check_curl_result(res, "DOWNLOAD cannot set progress function: ");
+
+ res = ::curl_easy_setopt(curl,
+ CURLOPT_PROGRESSDATA, reinterpret_cast<void*>(&helper));
+ check_curl_result(res, "DOWNLOAD cannot set progress data: ");
+ }
+
+ res = ::curl_easy_perform(curl);
+
+ /* always cleanup */
+ g_curl.release();
+ ::curl_easy_cleanup(curl);
+
+ if(statusVar.size())
+ {
+ cmOStringStream result;
+ result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\"";
+ this->Makefile->AddDefinition(statusVar,
+ result.str().c_str());
+ }
+
+ ::curl_global_cleanup();
+
+ // Explicitly flush/close so we can measure the md5 accurately.
+ //
+ fout.flush();
+ fout.close();
+
+ // Verify MD5 sum if requested:
+ //
+ if (hash.get())
+ {
+ std::string actualHash = hash->HashFile(file);
+ if (actualHash.size() == 0)
+ {
+ this->SetError("DOWNLOAD cannot compute hash on downloaded file");
+ return false;
+ }
+
+ if (expectedHash != actualHash)
+ {
+ cmOStringStream oss;
+ oss << "DOWNLOAD HASH mismatch" << std::endl
+ << " for file: [" << file << "]" << std::endl
+ << " expected hash: [" << expectedHash << "]" << std::endl
+ << " actual hash: [" << actualHash << "]" << std::endl
+ << " status: [" << (int)res << ";\""
+ << ::curl_easy_strerror(res) << "\"]" << std::endl
+ ;
+ this->SetError(oss.str());
+ return false;
+ }
+ }
+
+ if(chunkDebug.size())
+ {
+ chunkDebug.push_back(0);
+ if(CURLE_OPERATION_TIMEOUTED == res)
+ {
+ std::string output = &*chunkDebug.begin();
+
+ if(verboseLog.size())
+ {
+ this->Makefile->AddDefinition(verboseLog,
+ &*chunkDebug.begin());
+ }
+ }
+
+ this->Makefile->AddDefinition(verboseLog,
+ &*chunkDebug.begin());
+ }
+
+ return true;
+#else
+ this->SetError("DOWNLOAD not supported by bootstrap cmake.");
+ return false;
+#endif
+}
+
+
+bool
+cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ if(args.size() < 3)
+ {
+ this->SetError("UPLOAD must be called with at least three arguments.");
+ return false;
+ }
+ std::vector<std::string>::const_iterator i = args.begin();
+ ++i;
+ std::string filename = *i;
+ ++i;
+ std::string url = *i;
+ ++i;
+
+ long timeout = 0;
+ long inactivity_timeout = 0;
+ std::string logVar;
+ std::string statusVar;
+ bool showProgress = false;
+
+ while(i != args.end())
+ {
+ if(*i == "TIMEOUT")
+ {
+ ++i;
+ if(i != args.end())
+ {
+ timeout = atol(i->c_str());
+ }
+ else
+ {
+ this->SetError("UPLOAD missing time for TIMEOUT.");
+ return false;
+ }
+ }
+ else if(*i == "INACTIVITY_TIMEOUT")
+ {
+ ++i;
+ if(i != args.end())
+ {
+ inactivity_timeout = atol(i->c_str());
+ }
+ else
+ {
+ this->SetError("UPLOAD missing time for INACTIVITY_TIMEOUT.");
+ return false;
+ }
+ }
+ else if(*i == "LOG")
+ {
+ ++i;
+ if( i == args.end())
+ {
+ this->SetError("UPLOAD missing VAR for LOG.");
+ return false;
+ }
+ logVar = *i;
+ }
+ else if(*i == "STATUS")
+ {
+ ++i;
+ if( i == args.end())
+ {
+ this->SetError("UPLOAD missing VAR for STATUS.");
+ return false;
+ }
+ statusVar = *i;
+ }
+ else if(*i == "SHOW_PROGRESS")
+ {
+ showProgress = true;
+ }
+
+ ++i;
+ }
+
+ // Open file for reading:
+ //
+ FILE *fin = cmsys::SystemTools::Fopen(filename.c_str(), "rb");
+ if(!fin)
+ {
+ std::string errStr = "UPLOAD cannot open file '";
+ errStr += filename + "' for reading.";
+ this->SetError(errStr);
+ return false;
+ }
+
+ unsigned long file_size = cmsys::SystemTools::FileLength(filename.c_str());
+
+ ::CURL *curl;
+ ::curl_global_init(CURL_GLOBAL_DEFAULT);
+ curl = ::curl_easy_init();
+ if(!curl)
+ {
+ this->SetError("UPLOAD error initializing curl.");
+ fclose(fin);
+ return false;
+ }
+
+ cURLEasyGuard g_curl(curl);
+
+ // enable HTTP ERROR parsing
+ ::CURLcode res = ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+
+ // enable uploading
+ res = ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
+ check_curl_result(res, "UPLOAD cannot set upload flag: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+ check_curl_result(res, "UPLOAD cannot set url: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
+ cmWriteToMemoryCallback);
+ check_curl_result(res, "UPLOAD cannot set write function: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
+ cmFileCommandCurlDebugCallback);
+ check_curl_result(res, "UPLOAD cannot set debug function: ");
+
+ cmFileCommandVectorOfChar chunkResponse;
+ cmFileCommandVectorOfChar chunkDebug;
+
+ res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunkResponse);
+ check_curl_result(res, "UPLOAD cannot set write data: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
+ check_curl_result(res, "UPLOAD cannot set debug data: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ check_curl_result(res, "UPLOAD cannot set follow-redirect option: ");
+
+ if(logVar.size())
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ check_curl_result(res, "UPLOAD cannot set verbose: ");
+ }
+
+ if(timeout > 0)
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout );
+ check_curl_result(res, "UPLOAD cannot set timeout: ");
+ }
+
+ if(inactivity_timeout > 0)
+ {
+ // Give up if there is no progress for a long time.
+ ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
+ ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, inactivity_timeout);
+ }
+
+ // Need the progress helper's scope to last through the duration of
+ // the curl_easy_perform call... so this object is declared at function
+ // scope intentionally, rather than inside the "if(showProgress)"
+ // block...
+ //
+ cURLProgressHelper helper(this, "upload");
+
+ if(showProgress)
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
+ check_curl_result(res, "UPLOAD cannot set noprogress value: ");
+
+ res = ::curl_easy_setopt(curl,
+ CURLOPT_PROGRESSFUNCTION, cmFileUploadProgressCallback);
+ check_curl_result(res, "UPLOAD cannot set progress function: ");
+
+ res = ::curl_easy_setopt(curl,
+ CURLOPT_PROGRESSDATA, reinterpret_cast<void*>(&helper));
+ check_curl_result(res, "UPLOAD cannot set progress data: ");
+ }
+
+ // now specify which file to upload
+ res = ::curl_easy_setopt(curl, CURLOPT_INFILE, fin);
+ check_curl_result(res, "UPLOAD cannot set input file: ");
+
+ // and give the size of the upload (optional)
+ res = ::curl_easy_setopt(curl,
+ CURLOPT_INFILESIZE, static_cast<long>(file_size));
+ check_curl_result(res, "UPLOAD cannot set input file size: ");
+
+ res = ::curl_easy_perform(curl);
+
+ /* always cleanup */
+ g_curl.release();
+ ::curl_easy_cleanup(curl);
+
+ if(statusVar.size())
+ {
+ cmOStringStream result;
+ result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\"";
+ this->Makefile->AddDefinition(statusVar,
+ result.str().c_str());
+ }
+
+ ::curl_global_cleanup();
+
+ fclose(fin);
+ fin = NULL;
+
+ if(logVar.size())
+ {
+ std::string log;
+
+ if(chunkResponse.size())
+ {
+ chunkResponse.push_back(0);
+ log += "Response:\n";
+ log += &*chunkResponse.begin();
+ log += "\n";
+ }
+
+ if(chunkDebug.size())
+ {
+ chunkDebug.push_back(0);
+ log += "Debug:\n";
+ log += &*chunkDebug.begin();
+ log += "\n";
+ }
+
+ this->Makefile->AddDefinition(logVar, log.c_str());
+ }
+
+ return true;
+#else
+ this->SetError("UPLOAD not supported by bootstrap cmake.");
+ return false;
+#endif
+}
+
+//----------------------------------------------------------------------------
+void cmFileCommand::AddEvaluationFile(const std::string &inputName,
+ const std::string &outputExpr,
+ const std::string &condition,
+ bool inputIsContent
+ )
+{
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+
+ cmGeneratorExpression outputGe(&lfbt);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> outputCge
+ = outputGe.Parse(outputExpr);
+
+ cmGeneratorExpression conditionGe(&lfbt);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> conditionCge
+ = conditionGe.Parse(condition);
+
+ this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->AddEvaluationFile(inputName,
+ outputCge,
+ this->Makefile,
+ conditionCge,
+ inputIsContent);
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleGenerateCommand(
+ std::vector<std::string> const& args)
+{
+ if (args.size() < 5)
+ {
+ this->SetError("Incorrect arguments to GENERATE subcommand.");
+ return false;
+ }
+ if (args[1] != "OUTPUT")
+ {
+ this->SetError("Incorrect arguments to GENERATE subcommand.");
+ return false;
+ }
+ std::string condition;
+ if (args.size() > 5)
+ {
+ if (args[5] != "CONDITION")
+ {
+ this->SetError("Incorrect arguments to GENERATE subcommand.");
+ return false;
+ }
+ if (args.size() != 7)
+ {
+ this->SetError("Incorrect arguments to GENERATE subcommand.");
+ return false;
+ }
+ condition = args[6];
+ if (condition.empty())
+ {
+ this->SetError("CONDITION of sub-command GENERATE must not be empty if "
+ "specified.");
+ return false;
+ }
+ }
+ std::string output = args[2];
+ const bool inputIsContent = args[3] != "INPUT";
+ if (inputIsContent && args[3] != "CONTENT")
+ {
+ this->SetError("Incorrect arguments to GENERATE subcommand.");
+ return false;
+ }
+ std::string input = args[4];
+
+ this->AddEvaluationFile(input, output, condition, inputIsContent);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleTimestampCommand(
+ std::vector<std::string> const& args)
+{
+ if(args.size() < 3)
+ {
+ this->SetError("sub-command TIMESTAMP requires at least two arguments.");
+ return false;
+ }
+ else if(args.size() > 5)
+ {
+ this->SetError("sub-command TIMESTAMP takes at most four arguments.");
+ return false;
+ }
+
+ unsigned int argsIndex = 1;
+
+ const std::string& filename = args[argsIndex++];
+
+ const std::string& outputVariable = args[argsIndex++];
+
+ std::string formatString;
+ if(args.size() > argsIndex && args[argsIndex] != "UTC")
+ {
+ formatString = args[argsIndex++];
+ }
+
+ bool utcFlag = false;
+ if(args.size() > argsIndex)
+ {
+ if(args[argsIndex] == "UTC")
+ {
+ utcFlag = true;
+ }
+ else
+ {
+ std::string e = " TIMESTAMP sub-command does not recognize option " +
+ args[argsIndex] + ".";
+ this->SetError(e);
+ return false;
+ }
+ }
+
+ cmTimestamp timestamp;
+ std::string result = timestamp.FileModificationTime(
+ filename.c_str(), formatString, utcFlag);
+ this->Makefile->AddDefinition(outputVariable, result.c_str());
+
+ return true;
+}
diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h
new file mode 100644
index 0000000000..8d66fdf186
--- /dev/null
+++ b/Source/cmFileCommand.h
@@ -0,0 +1,87 @@
+/*============================================================================
+ 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 cmFileCommand_h
+#define cmFileCommand_h
+
+#include "cmCommand.h"
+
+struct cmFileInstaller;
+
+/** \class cmFileCommand
+ * \brief Command for manipulation of files
+ *
+ */
+class cmFileCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmFileCommand;
+ }
+
+ /**
+ * 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 "file";}
+
+ cmTypeMacro(cmFileCommand, cmCommand);
+
+protected:
+ bool HandleRename(std::vector<std::string> const& args);
+ bool HandleRemove(std::vector<std::string> const& args, bool recurse);
+ bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
+ bool HandleReadCommand(std::vector<std::string> const& args);
+ bool HandleHashCommand(std::vector<std::string> const& args);
+ bool HandleStringsCommand(std::vector<std::string> const& args);
+ bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
+ bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
+
+ bool HandleRelativePathCommand(std::vector<std::string> const& args);
+ bool HandleCMakePathCommand(std::vector<std::string> const& args,
+ bool nativePath);
+ bool HandleRPathChangeCommand(std::vector<std::string> const& args);
+ bool HandleRPathCheckCommand(std::vector<std::string> const& args);
+ bool HandleRPathRemoveCommand(std::vector<std::string> const& args);
+ bool HandleDifferentCommand(std::vector<std::string> const& args);
+
+ bool HandleCopyCommand(std::vector<std::string> const& args);
+ bool HandleInstallCommand(std::vector<std::string> const& args);
+ bool HandleDownloadCommand(std::vector<std::string> const& args);
+ bool HandleUploadCommand(std::vector<std::string> const& args);
+
+ bool HandleTimestampCommand(std::vector<std::string> const& args);
+ bool HandleGenerateCommand(std::vector<std::string> const& args);
+
+private:
+ void AddEvaluationFile(const std::string &inputName,
+ const std::string &outputExpr,
+ const std::string &condition,
+ bool inputIsContent);
+};
+
+
+#endif
diff --git a/Source/cmFileTimeComparison.cxx b/Source/cmFileTimeComparison.cxx
new file mode 100644
index 0000000000..57274708bb
--- /dev/null
+++ b/Source/cmFileTimeComparison.cxx
@@ -0,0 +1,277 @@
+/*============================================================================
+ 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 "cmFileTimeComparison.h"
+
+// Use a hash table to avoid duplicate file time checks from disk.
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include <cmsys/hash_map.hxx>
+#endif
+
+#include <cmsys/Encoding.hxx>
+
+// Use a platform-specific API to get file times efficiently.
+#if !defined(_WIN32) || defined(__CYGWIN__)
+# define cmFileTimeComparison_Type struct stat
+# include <ctype.h>
+# include <sys/stat.h>
+#else
+# define cmFileTimeComparison_Type FILETIME
+# include <windows.h>
+#endif
+
+//----------------------------------------------------------------------------
+class cmFileTimeComparisonInternal
+{
+public:
+ // Internal comparison method.
+ inline bool FileTimeCompare(const char* f1, const char* f2, int* result);
+
+ bool FileTimesDiffer(const char* f1, const char* f2);
+
+private:
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ // Use a hash table to efficiently map from file name to modification time.
+ class HashString
+ {
+ public:
+ size_t operator()(const std::string& s) const
+ {
+ return h(s.c_str());
+ }
+ cmsys::hash<const char*> h;
+ };
+ typedef cmsys::hash_map<std::string,
+ cmFileTimeComparison_Type, HashString> FileStatsMap;
+ FileStatsMap Files;
+#endif
+
+ // Internal methods to lookup and compare modification times.
+ inline bool Stat(const char* fname, cmFileTimeComparison_Type* st);
+ inline int Compare(cmFileTimeComparison_Type* st1,
+ cmFileTimeComparison_Type* st2);
+ inline bool TimesDiffer(cmFileTimeComparison_Type* st1,
+ cmFileTimeComparison_Type* st2);
+};
+
+//----------------------------------------------------------------------------
+bool cmFileTimeComparisonInternal::Stat(const char* fname,
+ cmFileTimeComparison_Type* st)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ // Use the stored time if available.
+ cmFileTimeComparisonInternal::FileStatsMap::iterator fit =
+ this->Files.find(fname);
+ if ( fit != this->Files.end() )
+ {
+ *st = fit->second;
+ return true;
+ }
+#endif
+
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ // POSIX version. Use the stat function.
+ int res = ::stat(fname, st);
+ if ( res != 0 )
+ {
+ return false;
+ }
+#else
+ // Windows version. Get the modification time from extended file
+ // attributes.
+ WIN32_FILE_ATTRIBUTE_DATA fdata;
+ if(!GetFileAttributesExW(cmsys::Encoding::ToWide(fname).c_str(),
+ GetFileExInfoStandard, &fdata))
+ {
+ return false;
+ }
+
+ // Copy the file time to the output location.
+ *st = fdata.ftLastWriteTime;
+#endif
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ // Store the time for future use.
+ this->Files[fname] = *st;
+#endif
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+cmFileTimeComparison::cmFileTimeComparison()
+{
+ this->Internals = new cmFileTimeComparisonInternal;
+}
+
+//----------------------------------------------------------------------------
+cmFileTimeComparison::~cmFileTimeComparison()
+{
+ delete this->Internals;
+}
+
+//----------------------------------------------------------------------------
+bool cmFileTimeComparison::FileTimeCompare(const char* f1,
+ const char* f2, int* result)
+{
+ return this->Internals->FileTimeCompare(f1, f2, result);
+}
+
+//----------------------------------------------------------------------------
+bool cmFileTimeComparison::FileTimesDiffer(const char* f1, const char* f2)
+{
+ return this->Internals->FileTimesDiffer(f1, f2);
+}
+
+//----------------------------------------------------------------------------
+int cmFileTimeComparisonInternal::Compare(cmFileTimeComparison_Type* s1,
+ cmFileTimeComparison_Type* s2)
+{
+#if !defined(_WIN32) || defined(__CYGWIN__)
+# if cmsys_STAT_HAS_ST_MTIM
+ // Compare using nanosecond resolution.
+ if(s1->st_mtim.tv_sec < s2->st_mtim.tv_sec)
+ {
+ return -1;
+ }
+ else if(s1->st_mtim.tv_sec > s2->st_mtim.tv_sec)
+ {
+ return 1;
+ }
+ else if(s1->st_mtim.tv_nsec < s2->st_mtim.tv_nsec)
+ {
+ return -1;
+ }
+ else if(s1->st_mtim.tv_nsec > s2->st_mtim.tv_nsec)
+ {
+ return 1;
+ }
+# else
+ // Compare using 1 second resolution.
+ if(s1->st_mtime < s2->st_mtime)
+ {
+ return -1;
+ }
+ else if(s1->st_mtime > s2->st_mtime)
+ {
+ return 1;
+ }
+# endif
+ // Files have the same time.
+ return 0;
+#else
+ // Compare using system-provided function.
+ return (int)CompareFileTime(s1, s2);
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1,
+ cmFileTimeComparison_Type* s2)
+{
+#if !defined(_WIN32) || defined(__CYGWIN__)
+# if cmsys_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;
+ long long t2 = s2->st_mtim.tv_sec * bil + s2->st_mtim.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)
+ {
+ return (s2->st_mtime - s1->st_mtime) >= 1;
+ }
+ else if(s1->st_mtime > s2->st_mtime)
+ {
+ return (s1->st_mtime - s2->st_mtime) >= 1;
+ }
+ else
+ {
+ return false;
+ }
+# endif
+#else
+ // Times are integers in units of 100ns.
+ LARGE_INTEGER t1;
+ LARGE_INTEGER t2;
+ t1.LowPart = s1->dwLowDateTime;
+ t1.HighPart = s1->dwHighDateTime;
+ t2.LowPart = s2->dwLowDateTime;
+ t2.HighPart = s2->dwHighDateTime;
+ if(t1.QuadPart < t2.QuadPart)
+ {
+ return (t2.QuadPart - t1.QuadPart) >= static_cast<LONGLONG>(10000000);
+ }
+ else if(t2.QuadPart < t1.QuadPart)
+ {
+ return (t1.QuadPart - t2.QuadPart) >= static_cast<LONGLONG>(10000000);
+ }
+ else
+ {
+ return false;
+ }
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool cmFileTimeComparisonInternal::FileTimeCompare(const char* f1,
+ const char* f2,
+ int* result)
+{
+ // Get the modification time for each file.
+ cmFileTimeComparison_Type s1;
+ cmFileTimeComparison_Type s2;
+ if(this->Stat(f1, &s1) &&
+ this->Stat(f2, &s2))
+ {
+ // Compare the two modification times.
+ *result = this->Compare(&s1, &s2);
+ return true;
+ }
+ else
+ {
+ // No comparison available. Default to the same time.
+ *result = 0;
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmFileTimeComparisonInternal::FileTimesDiffer(const char* f1,
+ const char* f2)
+{
+ // Get the modification time for each file.
+ cmFileTimeComparison_Type s1;
+ cmFileTimeComparison_Type s2;
+ if(this->Stat(f1, &s1) &&
+ this->Stat(f2, &s2))
+ {
+ // Compare the two modification times.
+ return this->TimesDiffer(&s1, &s2);
+ }
+ else
+ {
+ // No comparison available. Default to different times.
+ return true;
+ }
+}
diff --git a/Source/cmFileTimeComparison.h b/Source/cmFileTimeComparison.h
new file mode 100644
index 0000000000..cc1ef633d8
--- /dev/null
+++ b/Source/cmFileTimeComparison.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmFileTimeComparison_h
+#define cmFileTimeComparison_h
+
+#include "cmStandardIncludes.h"
+
+class cmFileTimeComparisonInternal;
+
+/** \class cmFileTimeComparison
+ * \brief Helper class for performing globbing searches.
+ *
+ * Finds all files that match a given globbing expression.
+ */
+class cmFileTimeComparison
+{
+public:
+ cmFileTimeComparison();
+ ~cmFileTimeComparison();
+
+ /**
+ * Compare file modification times.
+ * Return true for successful comparison and false for error.
+ * When true is returned, result has -1, 0, +1 for
+ * f1 older, same, or newer than f2.
+ */
+ bool FileTimeCompare(const char* f1, const char* f2, int* result);
+
+ /**
+ * Compare file modification times. Return true unless both files
+ * exist and have modification times less than 1 second apart.
+ */
+ bool FileTimesDiffer(const char* f1, const char* f2);
+
+protected:
+
+ cmFileTimeComparisonInternal* Internals;
+};
+
+
+#endif
+
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
new file mode 100644
index 0000000000..e4e819a001
--- /dev/null
+++ b/Source/cmFindBase.cxx
@@ -0,0 +1,495 @@
+/*============================================================================
+ 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 "cmFindBase.h"
+
+cmFindBase::cmFindBase()
+{
+ this->AlreadyInCache = false;
+ this->AlreadyInCacheWithoutMetaInfo = false;
+ this->NamesPerDir = false;
+ this->NamesPerDirAllowed = false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
+{
+ if(argsIn.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // copy argsIn into args so it can be modified,
+ // in the process extract the DOC "documentation"
+ size_t size = argsIn.size();
+ std::vector<std::string> args;
+ bool foundDoc = false;
+ for(unsigned int j = 0; j < size; ++j)
+ {
+ if(foundDoc || argsIn[j] != "DOC" )
+ {
+ if(argsIn[j] == "ENV")
+ {
+ if(j+1 < size)
+ {
+ j++;
+ cmSystemTools::GetPath(args, argsIn[j].c_str());
+ }
+ }
+ else
+ {
+ args.push_back(argsIn[j]);
+ }
+ }
+ else
+ {
+ if(j+1 < size)
+ {
+ foundDoc = true;
+ this->VariableDocumentation = argsIn[j+1];
+ j++;
+ if(j >= size)
+ {
+ break;
+ }
+ }
+ }
+ }
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ this->VariableName = args[0];
+ if(this->CheckForVariableInCache())
+ {
+ this->AlreadyInCache = true;
+ return true;
+ }
+ this->AlreadyInCache = false;
+
+ // Find the current root path mode.
+ this->SelectDefaultRootPathMode();
+
+ // Find the current bundle/framework search policy.
+ this->SelectDefaultMacMode();
+
+ bool newStyle = false;
+ enum Doing { DoingNone, DoingNames, DoingPaths, DoingPathSuffixes,
+ DoingHints };
+ Doing doing = DoingNames; // assume it starts with a name
+ for (unsigned int j = 1; j < args.size(); ++j)
+ {
+ if(args[j] == "NAMES")
+ {
+ doing = DoingNames;
+ newStyle = true;
+ }
+ else if (args[j] == "PATHS")
+ {
+ doing = DoingPaths;
+ newStyle = true;
+ }
+ else if (args[j] == "HINTS")
+ {
+ doing = DoingHints;
+ newStyle = true;
+ }
+ else if (args[j] == "PATH_SUFFIXES")
+ {
+ doing = DoingPathSuffixes;
+ newStyle = true;
+ }
+ else if (args[j] == "NAMES_PER_DIR")
+ {
+ doing = DoingNone;
+ if(this->NamesPerDirAllowed)
+ {
+ this->NamesPerDir = true;
+ }
+ else
+ {
+ this->SetError("does not support NAMES_PER_DIR");
+ return false;
+ }
+ }
+ else if (args[j] == "NO_SYSTEM_PATH")
+ {
+ doing = DoingNone;
+ this->NoDefaultPath = true;
+ }
+ else if (this->CheckCommonArgument(args[j]))
+ {
+ doing = DoingNone;
+ // Some common arguments were accidentally supported by CMake
+ // 2.4 and 2.6.0 in the short-hand form of the command, so we
+ // must support it even though it is not documented.
+ }
+ else if(doing == DoingNames)
+ {
+ this->Names.push_back(args[j]);
+ }
+ else if(doing == DoingPaths)
+ {
+ this->AddUserPath(args[j], this->UserPaths);
+ }
+ else if(doing == DoingHints)
+ {
+ this->AddUserPath(args[j], this->UserHints);
+ }
+ else if(doing == DoingPathSuffixes)
+ {
+ this->AddPathSuffix(args[j]);
+ }
+ }
+
+ if(this->VariableDocumentation.size() == 0)
+ {
+ this->VariableDocumentation = "Where can ";
+ if(this->Names.size() == 0)
+ {
+ this->VariableDocumentation += "the (unknown) library be found";
+ }
+ else if(this->Names.size() == 1)
+ {
+ this->VariableDocumentation += "the "
+ + this->Names[0] + " library be found";
+ }
+ else
+ {
+ this->VariableDocumentation += "one of the " + this->Names[0];
+ for (unsigned int j = 1; j < this->Names.size() - 1; ++j)
+ {
+ this->VariableDocumentation += ", " + this->Names[j];
+ }
+ this->VariableDocumentation += " or "
+ + this->Names[this->Names.size() - 1] + " libraries be found";
+ }
+ }
+
+ // look for old style
+ // FIND_*(VAR name path1 path2 ...)
+ if(!newStyle)
+ {
+ // All the short-hand arguments have been recorded as names.
+ std::vector<std::string> shortArgs = this->Names;
+ this->Names.clear(); // clear out any values in Names
+ this->Names.push_back(shortArgs[0]);
+ for(unsigned int j = 1; j < shortArgs.size(); ++j)
+ {
+ this->AddUserPath(shortArgs[j], this->UserPaths);
+ }
+ }
+ this->ExpandPaths();
+
+ // Filter out ignored paths from the prefix list
+ std::set<std::string> ignored;
+ this->GetIgnoredPaths(ignored);
+ this->FilterPaths(this->SearchPaths, ignored);
+
+ this->ComputeFinalPaths();
+
+ return true;
+}
+
+void cmFindBase::ExpandPaths()
+{
+ this->AddCMakeVariablePath();
+ this->AddCMakeEnvironmentPath();
+ this->AddUserHintsPath();
+ this->AddSystemEnvironmentPath();
+ this->AddCMakeSystemVariablePath();
+ this->AddUserGuessPath();
+
+ // Add suffixes and clean up paths.
+ this->AddPathSuffixes();
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddPrefixPaths(std::vector<std::string> const& in_paths,
+ PathType pathType)
+{
+ // default for programs
+ std::string subdir = "bin";
+
+ if (this->CMakePathName == "INCLUDE")
+ {
+ subdir = "include";
+ }
+ else if (this->CMakePathName == "LIBRARY")
+ {
+ subdir = "lib";
+ }
+ else if (this->CMakePathName == "FRAMEWORK")
+ {
+ subdir = ""; // ? what to do for frameworks ?
+ }
+
+ for(std::vector<std::string>::const_iterator it = in_paths.begin();
+ it != in_paths.end(); ++it)
+ {
+ std::string dir = *it;
+ if(!subdir.empty() && !dir.empty() && dir[dir.size()-1] != '/')
+ {
+ dir += "/";
+ }
+ if(subdir == "include" || subdir == "lib")
+ {
+ const char* arch =
+ this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE");
+ if(arch && *arch)
+ {
+ this->AddPathInternal(dir+subdir+"/"+arch, pathType);
+ }
+ }
+ std::string add = dir + subdir;
+ if(add != "/")
+ {
+ this->AddPathInternal(add, pathType);
+ }
+ if (subdir == "bin")
+ {
+ this->AddPathInternal(dir+"sbin", pathType);
+ }
+ if(!subdir.empty() && *it != "/")
+ {
+ this->AddPathInternal(*it, pathType);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddCMakePrefixPath(const std::string& variable)
+{
+ // Get a path from a CMake variable.
+ if(const char* varPath = this->Makefile->GetDefinition(variable))
+ {
+ std::vector<std::string> tmp;
+ cmSystemTools::ExpandListArgument(varPath, tmp);
+ this->AddPrefixPaths(tmp, CMakePath);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddEnvPrefixPath(const std::string& variable)
+{
+ // Get a path from the environment.
+ std::vector<std::string> tmp;
+ cmSystemTools::GetPath(tmp, variable.c_str());
+ this->AddPrefixPaths(tmp, EnvPath);
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddCMakeEnvironmentPath()
+{
+ if(!this->NoCMakeEnvironmentPath && !this->NoDefaultPath)
+ {
+ // Add CMAKE_*_PATH environment variables
+ std::string var = "CMAKE_";
+ var += this->CMakePathName;
+ var += "_PATH";
+ this->AddEnvPrefixPath("CMAKE_PREFIX_PATH");
+ this->AddEnvPath(var.c_str());
+
+ if(this->CMakePathName == "PROGRAM")
+ {
+ this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
+ }
+ else
+ {
+ this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddCMakeVariablePath()
+{
+ if(!this->NoCMakePath && !this->NoDefaultPath)
+ {
+ // Add CMake varibles of the same name as the previous environment
+ // varibles CMAKE_*_PATH to be used most of the time with -D
+ // command line options
+ std::string var = "CMAKE_";
+ var += this->CMakePathName;
+ var += "_PATH";
+ this->AddCMakePrefixPath("CMAKE_PREFIX_PATH");
+ this->AddCMakePath(var);
+
+ if(this->CMakePathName == "PROGRAM")
+ {
+ this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
+ }
+ else
+ {
+ this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddSystemEnvironmentPath()
+{
+ if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath)
+ {
+ // Add LIB or INCLUDE
+ if(!this->EnvironmentPath.empty())
+ {
+ this->AddEnvPath(this->EnvironmentPath.c_str());
+ }
+ // Add PATH
+ this->AddEnvPath(0);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddCMakeSystemVariablePath()
+{
+ if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
+ {
+ std::string var = "CMAKE_SYSTEM_";
+ var += this->CMakePathName;
+ var += "_PATH";
+ this->AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH");
+ this->AddCMakePath(var);
+
+ if(this->CMakePathName == "PROGRAM")
+ {
+ this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
+ }
+ else
+ {
+ this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddUserHintsPath()
+{
+ this->AddPathsInternal(this->UserHints, CMakePath);
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddUserGuessPath()
+{
+ this->AddPathsInternal(this->UserPaths, CMakePath);
+}
+
+//----------------------------------------------------------------------------
+void cmFindBase::AddPathSuffixes()
+{
+ std::vector<std::string>& paths = this->SearchPaths;
+ std::vector<std::string> finalPath = paths;
+ std::vector<std::string>::iterator i;
+ // clear the path
+ paths.clear();
+ // convert all paths to unix slashes and add search path suffixes
+ // if there are any
+ for(i = finalPath.begin();
+ i != finalPath.end(); ++i)
+ {
+ cmSystemTools::ConvertToUnixSlashes(*i);
+ // copy each finalPath combined with SearchPathSuffixes
+ // to the SearchPaths ivar
+ for(std::vector<std::string>::iterator j =
+ this->SearchPathSuffixes.begin();
+ j != this->SearchPathSuffixes.end(); ++j)
+ {
+ // if *i is only / then do not add a //
+ // this will get incorrectly considered a network
+ // path on windows and cause huge delays.
+ std::string p = *i;
+ if(p.size() && p[p.size()-1] != '/')
+ {
+ p += std::string("/");
+ }
+ p += *j;
+ // add to all paths because the search path may be modified
+ // later with lib being replaced for lib64 which may exist
+ paths.push_back(p);
+ }
+ // now put the path without the path suffixes in the SearchPaths
+ paths.push_back(*i);
+ }
+}
+
+void cmFindBase::PrintFindStuff()
+{
+ std::cerr << "SearchFrameworkLast: " << this->SearchFrameworkLast << "\n";
+ std::cerr << "SearchFrameworkOnly: " << this->SearchFrameworkOnly << "\n";
+ std::cerr << "SearchFrameworkFirst: " << this->SearchFrameworkFirst << "\n";
+ std::cerr << "SearchAppBundleLast: " << this->SearchAppBundleLast << "\n";
+ std::cerr << "SearchAppBundleOnly: " << this->SearchAppBundleOnly << "\n";
+ std::cerr << "SearchAppBundleFirst: " << this->SearchAppBundleFirst << "\n";
+ std::cerr << "VariableName " << this->VariableName << "\n";
+ std::cerr << "VariableDocumentation "
+ << this->VariableDocumentation << "\n";
+ std::cerr << "NoDefaultPath " << this->NoDefaultPath << "\n";
+ std::cerr << "NoCMakeEnvironmentPath "
+ << this->NoCMakeEnvironmentPath << "\n";
+ std::cerr << "NoCMakePath " << this->NoCMakePath << "\n";
+ std::cerr << "NoSystemEnvironmentPath "
+ << this->NoSystemEnvironmentPath << "\n";
+ std::cerr << "NoCMakeSystemPath " << this->NoCMakeSystemPath << "\n";
+ std::cerr << "EnvironmentPath " << this->EnvironmentPath << "\n";
+ std::cerr << "CMakePathName " << this->CMakePathName << "\n";
+ std::cerr << "Names ";
+ for(unsigned int i =0; i < this->Names.size(); ++i)
+ {
+ std::cerr << this->Names[i] << " ";
+ }
+ std::cerr << "\n";
+ std::cerr << "\n";
+ std::cerr << "SearchPathSuffixes ";
+ for(unsigned int i =0; i < this->SearchPathSuffixes.size(); ++i)
+ {
+ std::cerr << this->SearchPathSuffixes[i] << "\n";
+ }
+ std::cerr << "\n";
+ std::cerr << "SearchPaths\n";
+ for(unsigned int i =0; i < this->SearchPaths.size(); ++i)
+ {
+ std::cerr << "[" << this->SearchPaths[i] << "]\n";
+ }
+}
+
+bool cmFindBase::CheckForVariableInCache()
+{
+ if(const char* cacheValue =
+ this->Makefile->GetDefinition(this->VariableName))
+ {
+ cmCacheManager::CacheIterator it =
+ this->Makefile->GetCacheManager()->
+ GetCacheIterator(this->VariableName.c_str());
+ bool found = !cmSystemTools::IsNOTFOUND(cacheValue);
+ bool cached = !it.IsAtEnd();
+ if(found)
+ {
+ // If the user specifies the entry on the command line without a
+ // type we should add the type and docstring but keep the
+ // original value. Tell the subclass implementations to do
+ // this.
+ if(cached && it.GetType() == cmCacheManager::UNINITIALIZED)
+ {
+ this->AlreadyInCacheWithoutMetaInfo = true;
+ }
+ return true;
+ }
+ else if(cached)
+ {
+ const char* hs = it.GetProperty("HELPSTRING");
+ this->VariableDocumentation = hs?hs:"(none)";
+ }
+ }
+ return false;
+}
diff --git a/Source/cmFindBase.h b/Source/cmFindBase.h
new file mode 100644
index 0000000000..42d9bc1c04
--- /dev/null
+++ b/Source/cmFindBase.h
@@ -0,0 +1,74 @@
+/*============================================================================
+ 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 cmFindBase_h
+#define cmFindBase_h
+
+#include "cmFindCommon.h"
+
+/** \class cmFindBase
+ * \brief Base class for most FIND_XXX commands.
+ *
+ * cmFindBase is a parent class for cmFindProgramCommand, cmFindPathCommand,
+ * and cmFindLibraryCommand, cmFindFileCommand
+ */
+class cmFindBase : public cmFindCommon
+{
+public:
+ cmFindBase();
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool ParseArguments(std::vector<std::string> const& args);
+ cmTypeMacro(cmFindBase, cmFindCommon);
+
+protected:
+ void PrintFindStuff();
+ void ExpandPaths();
+ void AddPathSuffixes();
+
+ // see if the VariableName is already set in the cache,
+ // also copy the documentation from the cache to VariableDocumentation
+ // if it has documentation in the cache
+ bool CheckForVariableInCache();
+
+ // use by command during find
+ std::string VariableDocumentation;
+ std::string VariableName;
+ std::vector<std::string> Names;
+ bool NamesPerDir;
+ bool NamesPerDirAllowed;
+
+ // CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM
+ std::string EnvironmentPath; // LIB,INCLUDE
+
+ bool AlreadyInCache;
+ bool AlreadyInCacheWithoutMetaInfo;
+private:
+ // Add pieces of the search.
+ void AddCMakeEnvironmentPath();
+ void AddCMakeVariablePath();
+ void AddSystemEnvironmentPath();
+ void AddCMakeSystemVariablePath();
+ void AddUserHintsPath();
+ void AddUserGuessPath();
+
+ // Helpers.
+ void AddCMakePrefixPath(const std::string& variable);
+ void AddEnvPrefixPath(const std::string& variable);
+ void AddPrefixPaths(std::vector<std::string> const& in_paths,
+ PathType pathType);
+};
+
+
+
+#endif
diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx
new file mode 100644
index 0000000000..10241f2475
--- /dev/null
+++ b/Source/cmFindCommon.cxx
@@ -0,0 +1,472 @@
+/*============================================================================
+ 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 "cmFindCommon.h"
+
+//----------------------------------------------------------------------------
+cmFindCommon::cmFindCommon()
+{
+ this->FindRootPathMode = RootPathModeBoth;
+ this->NoDefaultPath = false;
+ this->NoCMakePath = false;
+ this->NoCMakeEnvironmentPath = false;
+ this->NoSystemEnvironmentPath = false;
+ this->NoCMakeSystemPath = false;
+
+ // OS X Bundle and Framework search policy. The default is to
+ // search frameworks first on apple.
+#if defined(__APPLE__)
+ this->SearchFrameworkFirst = true;
+ this->SearchAppBundleFirst = true;
+#else
+ this->SearchFrameworkFirst = false;
+ this->SearchAppBundleFirst = false;
+#endif
+ this->SearchFrameworkOnly = false;
+ this->SearchFrameworkLast = false;
+ this->SearchAppBundleOnly = false;
+ this->SearchAppBundleLast = false;
+}
+
+//----------------------------------------------------------------------------
+cmFindCommon::~cmFindCommon()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::SelectDefaultRootPathMode()
+{
+ // Use both by default.
+ this->FindRootPathMode = RootPathModeBoth;
+
+ // Check the policy variable for this find command type.
+ std::string findRootPathVar = "CMAKE_FIND_ROOT_PATH_MODE_";
+ findRootPathVar += this->CMakePathName;
+ std::string rootPathMode =
+ this->Makefile->GetSafeDefinition(findRootPathVar);
+ if (rootPathMode=="NEVER")
+ {
+ this->FindRootPathMode = RootPathModeNoRootPath;
+ }
+ else if (rootPathMode=="ONLY")
+ {
+ this->FindRootPathMode = RootPathModeOnlyRootPath;
+ }
+ else if (rootPathMode=="BOTH")
+ {
+ this->FindRootPathMode = RootPathModeBoth;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::SelectDefaultMacMode()
+{
+ std::string ff = this->Makefile->GetSafeDefinition("CMAKE_FIND_FRAMEWORK");
+ if(ff == "NEVER")
+ {
+ this->SearchFrameworkLast = false;
+ this->SearchFrameworkFirst = false;
+ this->SearchFrameworkOnly = false;
+ }
+ else if(ff == "ONLY")
+ {
+ this->SearchFrameworkLast = false;
+ this->SearchFrameworkFirst = false;
+ this->SearchFrameworkOnly = true;
+ }
+ else if(ff == "FIRST")
+ {
+ this->SearchFrameworkLast = false;
+ this->SearchFrameworkFirst = true;
+ this->SearchFrameworkOnly = false;
+ }
+ else if(ff == "LAST")
+ {
+ this->SearchFrameworkLast = true;
+ this->SearchFrameworkFirst = false;
+ this->SearchFrameworkOnly = false;
+ }
+
+ std::string fab = this->Makefile->GetSafeDefinition("CMAKE_FIND_APPBUNDLE");
+ if(fab == "NEVER")
+ {
+ this->SearchAppBundleLast = false;
+ this->SearchAppBundleFirst = false;
+ this->SearchAppBundleOnly = false;
+ }
+ else if(fab == "ONLY")
+ {
+ this->SearchAppBundleLast = false;
+ this->SearchAppBundleFirst = false;
+ this->SearchAppBundleOnly = true;
+ }
+ else if(fab == "FIRST")
+ {
+ this->SearchAppBundleLast = false;
+ this->SearchAppBundleFirst = true;
+ this->SearchAppBundleOnly = false;
+ }
+ else if(fab == "LAST")
+ {
+ this->SearchAppBundleLast = true;
+ this->SearchAppBundleFirst = false;
+ this->SearchAppBundleOnly = false;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
+{
+#if 0
+ for(std::vector<std::string>::const_iterator i = paths.begin();
+ i != paths.end(); ++i)
+ {
+ fprintf(stderr, "[%s]\n", i->c_str());
+ }
+#endif
+
+ // Short-circuit if there is nothing to do.
+ if(this->FindRootPathMode == RootPathModeNoRootPath)
+ {
+ return;
+ }
+ const char* sysroot =
+ this->Makefile->GetDefinition("CMAKE_SYSROOT");
+ const char* rootPath =
+ this->Makefile->GetDefinition("CMAKE_FIND_ROOT_PATH");
+ const bool noSysroot = !sysroot || !*sysroot;
+ const bool noRootPath = !rootPath || !*rootPath;
+ if(noSysroot && noRootPath)
+ {
+ return;
+ }
+
+ // Construct the list of path roots with no trailing slashes.
+ std::vector<std::string> roots;
+ if (rootPath)
+ {
+ cmSystemTools::ExpandListArgument(rootPath, roots);
+ }
+ if (sysroot)
+ {
+ roots.push_back(sysroot);
+ }
+ for(std::vector<std::string>::iterator ri = roots.begin();
+ ri != roots.end(); ++ri)
+ {
+ cmSystemTools::ConvertToUnixSlashes(*ri);
+ }
+
+ const char* stagePrefix =
+ this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX");
+
+ // Copy the original set of unrooted paths.
+ std::vector<std::string> unrootedPaths = paths;
+ paths.clear();
+
+ for(std::vector<std::string>::const_iterator ri = roots.begin();
+ ri != roots.end(); ++ri)
+ {
+ for(std::vector<std::string>::const_iterator ui = unrootedPaths.begin();
+ ui != unrootedPaths.end(); ++ui)
+ {
+ // Place the unrooted path under the current root if it is not
+ // already inside. Skip the unrooted path if it is relative to
+ // a user home directory or is empty.
+ std::string rootedDir;
+ if(cmSystemTools::IsSubDirectory(ui->c_str(), ri->c_str())
+ || (stagePrefix
+ && cmSystemTools::IsSubDirectory(ui->c_str(), stagePrefix)))
+ {
+ rootedDir = *ui;
+ }
+ else if(!ui->empty() && (*ui)[0] != '~')
+ {
+ // Start with the new root.
+ rootedDir = *ri;
+ rootedDir += "/";
+
+ // Append the original path with its old root removed.
+ rootedDir += cmSystemTools::SplitPathRootComponent(ui->c_str());
+ }
+
+ // Store the new path.
+ paths.push_back(rootedDir);
+ }
+ }
+
+ // If searching both rooted and unrooted paths add the original
+ // paths again.
+ if(this->FindRootPathMode == RootPathModeBoth)
+ {
+ paths.insert(paths.end(), unrootedPaths.begin(), unrootedPaths.end());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::FilterPaths(std::vector<std::string>& paths,
+ const std::set<std::string>& ignore)
+{
+ // Now filter out anything that's in the ignore set.
+ std::vector<std::string> unfiltered;
+ unfiltered.swap(paths);
+
+ for(std::vector<std::string>::iterator pi = unfiltered.begin();
+ pi != unfiltered.end(); ++pi)
+ {
+ if (ignore.count(*pi) == 0)
+ {
+ paths.push_back(*pi);
+ }
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
+{
+ // null-terminated list of paths.
+ static const char *paths[] =
+ { "CMAKE_SYSTEM_IGNORE_PATH", "CMAKE_IGNORE_PATH", 0 };
+
+ // Construct the list of path roots with no trailing slashes.
+ for(const char **pathName = paths; *pathName; ++pathName)
+ {
+ // Get the list of paths to ignore from the variable.
+ const char* ignorePath = this->Makefile->GetDefinition(*pathName);
+ if((ignorePath == 0) || (strlen(ignorePath) == 0))
+ {
+ continue;
+ }
+
+ cmSystemTools::ExpandListArgument(ignorePath, ignore);
+ }
+
+ for(std::vector<std::string>::iterator i = ignore.begin();
+ i != ignore.end(); ++i)
+ {
+ cmSystemTools::ConvertToUnixSlashes(*i);
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmFindCommon::GetIgnoredPaths(std::set<std::string>& ignore)
+{
+ std::vector<std::string> ignoreVec;
+ GetIgnoredPaths(ignoreVec);
+ ignore.insert(ignoreVec.begin(), ignoreVec.end());
+}
+
+
+
+//----------------------------------------------------------------------------
+bool cmFindCommon::CheckCommonArgument(std::string const& arg)
+{
+ if(arg == "NO_DEFAULT_PATH")
+ {
+ this->NoDefaultPath = true;
+ }
+ else if(arg == "NO_CMAKE_ENVIRONMENT_PATH")
+ {
+ this->NoCMakeEnvironmentPath = true;
+ }
+ else if(arg == "NO_CMAKE_PATH")
+ {
+ this->NoCMakePath = true;
+ }
+ else if(arg == "NO_SYSTEM_ENVIRONMENT_PATH")
+ {
+ this->NoSystemEnvironmentPath = true;
+ }
+ else if(arg == "NO_CMAKE_SYSTEM_PATH")
+ {
+ this->NoCMakeSystemPath = true;
+ }
+ else if(arg == "NO_CMAKE_FIND_ROOT_PATH")
+ {
+ this->FindRootPathMode = RootPathModeNoRootPath;
+ }
+ else if(arg == "ONLY_CMAKE_FIND_ROOT_PATH")
+ {
+ this->FindRootPathMode = RootPathModeOnlyRootPath;
+ }
+ else if(arg == "CMAKE_FIND_ROOT_PATH_BOTH")
+ {
+ this->FindRootPathMode = RootPathModeBoth;
+ }
+ else
+ {
+ // The argument is not one of the above.
+ return false;
+ }
+
+ // The argument is one of the above.
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::AddPathSuffix(std::string const& arg)
+{
+ std::string suffix = arg;
+
+ // Strip leading and trailing slashes.
+ if(suffix.empty())
+ {
+ return;
+ }
+ if(suffix[0] == '/')
+ {
+ suffix = suffix.substr(1, suffix.npos);
+ }
+ if(suffix.empty())
+ {
+ return;
+ }
+ if(suffix[suffix.size()-1] == '/')
+ {
+ suffix = suffix.substr(0, suffix.size()-1);
+ }
+ if(suffix.empty())
+ {
+ return;
+ }
+
+ // Store the suffix.
+ this->SearchPathSuffixes.push_back(suffix);
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::AddUserPath(std::string const& p,
+ std::vector<std::string>& paths)
+{
+ // We should view the registry as the target application would view
+ // it.
+ cmSystemTools::KeyWOW64 view = cmSystemTools::KeyWOW64_32;
+ cmSystemTools::KeyWOW64 other_view = cmSystemTools::KeyWOW64_64;
+ if(this->Makefile->PlatformIs64Bit())
+ {
+ view = cmSystemTools::KeyWOW64_64;
+ other_view = cmSystemTools::KeyWOW64_32;
+ }
+
+ // Expand using the view of the target application.
+ std::string expanded = p;
+ cmSystemTools::ExpandRegistryValues(expanded, view);
+ cmSystemTools::GlobDirs(expanded, paths);
+
+ // Executables can be either 32-bit or 64-bit, so expand using the
+ // alternative view.
+ if(expanded != p && this->CMakePathName == "PROGRAM")
+ {
+ expanded = p;
+ cmSystemTools::ExpandRegistryValues(expanded, other_view);
+ cmSystemTools::GlobDirs(expanded, paths);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::AddCMakePath(const std::string& variable)
+{
+ // Get a path from a CMake variable.
+ if(const char* varPath = this->Makefile->GetDefinition(variable))
+ {
+ std::vector<std::string> tmp;
+ cmSystemTools::ExpandListArgument(varPath, tmp);
+
+ // Relative paths are interpreted with respect to the current
+ // source directory.
+ this->AddPathsInternal(tmp, CMakePath);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::AddEnvPath(const char* variable)
+{
+ // Get a path from the environment.
+ std::vector<std::string> tmp;
+ cmSystemTools::GetPath(tmp, variable);
+ // Relative paths are interpreted with respect to the current
+ // working directory.
+ this->AddPathsInternal(tmp, EnvPath);
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::AddPathsInternal(std::vector<std::string> const& in_paths,
+ PathType pathType)
+{
+ for(std::vector<std::string>::const_iterator i = in_paths.begin();
+ i != in_paths.end(); ++i)
+ {
+ this->AddPathInternal(*i, pathType);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::AddPathInternal(std::string const& in_path,
+ PathType pathType)
+{
+ if(in_path.empty())
+ {
+ return;
+ }
+
+ // Select the base path with which to interpret relative paths.
+ const char* relbase = 0;
+ if(pathType == CMakePath)
+ {
+ relbase = this->Makefile->GetCurrentDirectory();
+ }
+
+ // Convert to clean full path.
+ std::string fullPath =
+ cmSystemTools::CollapseFullPath(in_path.c_str(), relbase);
+
+ // Insert the path if has not already been emitted.
+ if(this->SearchPathsEmitted.insert(fullPath).second)
+ {
+ this->SearchPaths.push_back(fullPath);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::ComputeFinalPaths()
+{
+ std::vector<std::string>& paths = this->SearchPaths;
+
+ // Expand list of paths inside all search roots.
+ this->RerootPaths(paths);
+
+ // Add a trailing slash to all paths to aid the search process.
+ for(std::vector<std::string>::iterator i = paths.begin();
+ i != paths.end(); ++i)
+ {
+ std::string& p = *i;
+ if(!p.empty() && p[p.size()-1] != '/')
+ {
+ p += "/";
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindCommon::SetMakefile(cmMakefile* makefile)
+{
+ cmCommand::SetMakefile(makefile);
+
+ // If we are building for Apple (OSX or also iphone), make sure
+ // that frameworks and bundles are searched first.
+ if(this->Makefile->IsOn("APPLE"))
+ {
+ this->SearchFrameworkFirst = true;
+ this->SearchAppBundleFirst = true;
+ }
+}
diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h
new file mode 100644
index 0000000000..5a905cd20a
--- /dev/null
+++ b/Source/cmFindCommon.h
@@ -0,0 +1,95 @@
+/*============================================================================
+ 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 cmFindCommon_h
+#define cmFindCommon_h
+
+#include "cmCommand.h"
+
+/** \class cmFindCommon
+ * \brief Base class for FIND_XXX implementations.
+ *
+ * cmFindCommon is a parent class for cmFindBase,
+ * cmFindProgramCommand, cmFindPathCommand, cmFindLibraryCommand,
+ * cmFindFileCommand, and cmFindPackageCommand.
+ */
+class cmFindCommon : public cmCommand
+{
+public:
+ cmFindCommon();
+ ~cmFindCommon();
+ cmTypeMacro(cmFindCommon, cmCommand);
+
+protected:
+
+ enum RootPathMode { RootPathModeBoth,
+ RootPathModeOnlyRootPath,
+ RootPathModeNoRootPath };
+
+ enum PathType { FullPath, CMakePath, EnvPath };
+
+ /** Place a set of search paths under the search roots. */
+ void RerootPaths(std::vector<std::string>& paths);
+
+ /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_path variables. */
+ void GetIgnoredPaths(std::vector<std::string>& ignore);
+ void GetIgnoredPaths(std::set<std::string>& ignore);
+
+ /** Remove paths in the ignore set from the supplied vector. */
+ void FilterPaths(std::vector<std::string>& paths,
+ const std::set<std::string>& ignore);
+
+ /** Compute final search path list (reroot + trailing slash). */
+ void ComputeFinalPaths();
+
+ /** Compute the current default root path mode. */
+ void SelectDefaultRootPathMode();
+
+ /** Compute the current default bundle/framework search policy. */
+ void SelectDefaultMacMode();
+
+ std::string CMakePathName;
+ RootPathMode FindRootPathMode;
+
+ bool CheckCommonArgument(std::string const& arg);
+ void AddPathSuffix(std::string const& arg);
+ void AddUserPath(std::string const& p,
+ std::vector<std::string>& paths);
+ void AddCMakePath(const std::string& variable);
+ void AddEnvPath(const char* variable);
+ void AddPathsInternal(std::vector<std::string> const& in_paths,
+ PathType pathType);
+ void AddPathInternal(std::string const& in_path, PathType pathType);
+
+ void SetMakefile(cmMakefile* makefile);
+
+ bool NoDefaultPath;
+ bool NoCMakePath;
+ bool NoCMakeEnvironmentPath;
+ bool NoSystemEnvironmentPath;
+ bool NoCMakeSystemPath;
+
+ std::vector<std::string> SearchPathSuffixes;
+ std::vector<std::string> UserPaths;
+ std::vector<std::string> UserHints;
+ std::vector<std::string> SearchPaths;
+ std::set<std::string> SearchPathsEmitted;
+
+ bool SearchFrameworkFirst;
+ bool SearchFrameworkOnly;
+ bool SearchFrameworkLast;
+
+ bool SearchAppBundleFirst;
+ bool SearchAppBundleOnly;
+ bool SearchAppBundleLast;
+};
+
+#endif
diff --git a/Source/cmFindFileCommand.cxx b/Source/cmFindFileCommand.cxx
new file mode 100644
index 0000000000..615e7c1d29
--- /dev/null
+++ b/Source/cmFindFileCommand.cxx
@@ -0,0 +1,18 @@
+/*============================================================================
+ 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 "cmFindFileCommand.h"
+#include "cmSystemTools.h"
+
+cmFindFileCommand::cmFindFileCommand()
+{
+ this->IncludeFileInPath = true;
+}
diff --git a/Source/cmFindFileCommand.h b/Source/cmFindFileCommand.h
new file mode 100644
index 0000000000..daf1d6582f
--- /dev/null
+++ b/Source/cmFindFileCommand.h
@@ -0,0 +1,43 @@
+/*============================================================================
+ 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 cmFindFileCommand_h
+#define cmFindFileCommand_h
+
+#include "cmFindPathCommand.h"
+
+/** \class cmFindFileCommand
+ * \brief Define a command to search for an executable program.
+ *
+ * cmFindFileCommand is used to define a CMake variable
+ * that specifies an executable program. The command searches
+ * in the current path (e.g., PATH environment variable) for
+ * an executable that matches one of the supplied names.
+ */
+class cmFindFileCommand : public cmFindPathCommand
+{
+public:
+ cmFindFileCommand();
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmFindFileCommand;
+ }
+ virtual std::string GetName() const { return "find_file";}
+
+ cmTypeMacro(cmFindFileCommand, cmFindPathCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx
new file mode 100644
index 0000000000..fe5e45f25b
--- /dev/null
+++ b/Source/cmFindLibraryCommand.cxx
@@ -0,0 +1,544 @@
+/*============================================================================
+ 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 "cmFindLibraryCommand.h"
+#include "cmCacheManager.h"
+#include <cmsys/Directory.hxx>
+#include <cmsys/stl/algorithm>
+
+cmFindLibraryCommand::cmFindLibraryCommand()
+{
+ this->EnvironmentPath = "LIB";
+ this->NamesPerDirAllowed = true;
+}
+
+// cmFindLibraryCommand
+bool cmFindLibraryCommand
+::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
+{
+ this->VariableDocumentation = "Path to a library.";
+ this->CMakePathName = "LIBRARY";
+ if(!this->ParseArguments(argsIn))
+ {
+ return false;
+ }
+ if(this->AlreadyInCache)
+ {
+ // If the user specifies the entry on the command line without a
+ // type we should add the type and docstring but keep the original
+ // value.
+ if(this->AlreadyInCacheWithoutMetaInfo)
+ {
+ this->Makefile->AddCacheDefinition(this->VariableName, "",
+ this->VariableDocumentation.c_str(),
+ cmCacheManager::FILEPATH);
+ }
+ return true;
+ }
+
+ if(const char* abi_name =
+ this->Makefile->GetDefinition("CMAKE_INTERNAL_PLATFORM_ABI"))
+ {
+ std::string abi = abi_name;
+ if(abi.find("ELF N32") != abi.npos)
+ {
+ // Convert lib to lib32.
+ this->AddArchitecturePaths("32");
+ }
+ }
+
+ if(this->Makefile->GetCMakeInstance()
+ ->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
+ {
+ // add special 64 bit paths if this is a 64 bit compile.
+ if(this->Makefile->PlatformIs64Bit())
+ {
+ this->AddArchitecturePaths("64");
+ }
+ }
+
+ std::string library = this->FindLibrary();
+ if(library != "")
+ {
+ // Save the value in the cache
+ this->Makefile->AddCacheDefinition(this->VariableName,
+ library.c_str(),
+ this->VariableDocumentation.c_str(),
+ cmCacheManager::FILEPATH);
+ return true;
+ }
+ std::string notfound = this->VariableName + "-NOTFOUND";
+ this->Makefile->AddCacheDefinition(this->VariableName,
+ notfound.c_str(),
+ this->VariableDocumentation.c_str(),
+ cmCacheManager::FILEPATH);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix)
+{
+ std::vector<std::string> original;
+ original.swap(this->SearchPaths);
+ for(std::vector<std::string>::iterator i = original.begin();
+ i != original.end(); ++i)
+ {
+ this->AddArchitecturePath(*i, 0, suffix);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindLibraryCommand::AddArchitecturePath(
+ std::string const& dir, std::string::size_type start_pos,
+ const char* suffix, bool fresh)
+{
+ std::string::size_type pos = dir.find("lib/", start_pos);
+ if(pos != std::string::npos)
+ {
+ std::string cur_dir = dir.substr(0,pos+3);
+
+ // Follow "lib<suffix>".
+ std::string next_dir = cur_dir + suffix;
+ if(cmSystemTools::FileIsDirectory(next_dir.c_str()))
+ {
+ next_dir += dir.substr(pos+3);
+ std::string::size_type next_pos = pos+3+strlen(suffix)+1;
+ this->AddArchitecturePath(next_dir, next_pos, suffix);
+ }
+
+ // Follow "lib".
+ if(cmSystemTools::FileIsDirectory(cur_dir.c_str()))
+ {
+ this->AddArchitecturePath(dir, pos+3+1, suffix, false);
+ }
+ }
+ if(fresh)
+ {
+ // Check for <dir><suffix>/.
+ std::string cur_dir = dir + suffix + "/";
+ if(cmSystemTools::FileIsDirectory(cur_dir.c_str()))
+ {
+ this->SearchPaths.push_back(cur_dir);
+ }
+
+ // Now add the original unchanged path
+ if(cmSystemTools::FileIsDirectory(dir.c_str()))
+ {
+ this->SearchPaths.push_back(dir);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindLibraryCommand::FindLibrary()
+{
+ std::string library;
+ if(this->SearchFrameworkFirst || this->SearchFrameworkOnly)
+ {
+ library = this->FindFrameworkLibrary();
+ }
+ if(library.empty() && !this->SearchFrameworkOnly)
+ {
+ library = this->FindNormalLibrary();
+ }
+ if(library.empty() && this->SearchFrameworkLast)
+ {
+ library = this->FindFrameworkLibrary();
+ }
+ return library;
+}
+
+//----------------------------------------------------------------------------
+struct cmFindLibraryHelper
+{
+ cmFindLibraryHelper(cmMakefile* mf);
+
+ // Context information.
+ cmMakefile* Makefile;
+ cmGlobalGenerator* GG;
+
+ // List of valid prefixes and suffixes.
+ std::vector<std::string> Prefixes;
+ std::vector<std::string> Suffixes;
+ std::string PrefixRegexStr;
+ std::string SuffixRegexStr;
+
+ // Keep track of the best library file found so far.
+ typedef std::vector<std::string>::size_type size_type;
+ std::string BestPath;
+
+ // Support for OpenBSD shared library naming: lib<name>.so.<major>.<minor>
+ bool OpenBSD;
+
+ // Current names under consideration.
+ struct Name
+ {
+ bool TryRaw;
+ std::string Raw;
+ cmsys::RegularExpression Regex;
+ Name(): TryRaw(false) {}
+ };
+ std::vector<Name> Names;
+
+ // Current full path under consideration.
+ std::string TestPath;
+
+ void RegexFromLiteral(std::string& out, std::string const& in);
+ void RegexFromList(std::string& out, std::vector<std::string> const& in);
+ size_type GetPrefixIndex(std::string const& prefix)
+ {
+ return cmsys_stl::find(this->Prefixes.begin(), this->Prefixes.end(),
+ prefix) - this->Prefixes.begin();
+ }
+ size_type GetSuffixIndex(std::string const& suffix)
+ {
+ return cmsys_stl::find(this->Suffixes.begin(), this->Suffixes.end(),
+ suffix) - this->Suffixes.begin();
+ }
+ bool HasValidSuffix(std::string const& name);
+ void AddName(std::string const& name);
+ bool CheckDirectory(std::string const& path);
+ bool CheckDirectoryForName(std::string const& path, Name& name);
+};
+
+//----------------------------------------------------------------------------
+cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf):
+ Makefile(mf)
+{
+ this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
+
+ // Collect the list of library name prefixes/suffixes to try.
+ const char* prefixes_list =
+ this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_PREFIXES");
+ const char* suffixes_list =
+ this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_SUFFIXES");
+ cmSystemTools::ExpandListArgument(prefixes_list, this->Prefixes, true);
+ cmSystemTools::ExpandListArgument(suffixes_list, this->Suffixes, true);
+ this->RegexFromList(this->PrefixRegexStr, this->Prefixes);
+ this->RegexFromList(this->SuffixRegexStr, this->Suffixes);
+
+ // Check whether to use OpenBSD-style library version comparisons.
+ this->OpenBSD =
+ this->Makefile->GetCMakeInstance()
+ ->GetPropertyAsBool("FIND_LIBRARY_USE_OPENBSD_VERSIONING");
+}
+
+//----------------------------------------------------------------------------
+void cmFindLibraryHelper::RegexFromLiteral(std::string& out,
+ std::string const& in)
+{
+ for(std::string::const_iterator ci = in.begin(); ci != in.end(); ++ci)
+ {
+ char ch = *ci;
+ if(ch == '[' || ch == ']' || ch == '(' || ch == ')' || ch == '\\' ||
+ ch == '.' || ch == '*' || ch == '+' || ch == '?' || ch == '-' ||
+ ch == '^' || ch == '$')
+ {
+ out += "\\";
+ }
+#if defined(_WIN32) || defined(__APPLE__)
+ out += tolower(ch);
+#else
+ out += ch;
+#endif
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindLibraryHelper::RegexFromList(std::string& out,
+ std::vector<std::string> const& in)
+{
+ // Surround the list in parens so the '|' does not apply to anything
+ // else and the result can be checked after matching.
+ out += "(";
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator si = in.begin();
+ si != in.end(); ++si)
+ {
+ // Separate from previous item.
+ out += sep;
+ sep = "|";
+
+ // Append this item.
+ this->RegexFromLiteral(out, *si);
+ }
+ out += ")";
+}
+
+//----------------------------------------------------------------------------
+bool cmFindLibraryHelper::HasValidSuffix(std::string const& name)
+{
+ for(std::vector<std::string>::const_iterator si = this->Suffixes.begin();
+ si != this->Suffixes.end(); ++si)
+ {
+ std::string suffix = *si;
+ if(name.length() <= suffix.length())
+ {
+ continue;
+ }
+ // Check if the given name ends in a valid library suffix.
+ if(name.substr(name.size()-suffix.length()) == suffix)
+ {
+ return true;
+ }
+ // Check if a valid library suffix is somewhere in the name,
+ // this may happen e.g. for versioned shared libraries: libfoo.so.2
+ suffix += ".";
+ if(name.find(suffix) != name.npos)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmFindLibraryHelper::AddName(std::string const& name)
+{
+ Name entry;
+
+ // Consider checking the raw name too.
+ entry.TryRaw = this->HasValidSuffix(name);
+ entry.Raw = name;
+
+ // Build a regular expression to match library names.
+ std::string regex = "^";
+ regex += this->PrefixRegexStr;
+ this->RegexFromLiteral(regex, name);
+ regex += this->SuffixRegexStr;
+ if(this->OpenBSD)
+ {
+ regex += "(\\.[0-9]+\\.[0-9]+)?";
+ }
+ regex += "$";
+ entry.Regex.compile(regex.c_str());
+ this->Names.push_back(entry);
+}
+
+//----------------------------------------------------------------------------
+bool cmFindLibraryHelper::CheckDirectory(std::string const& path)
+{
+ for(std::vector<Name>::iterator i = this->Names.begin();
+ i != this->Names.end(); ++i)
+ {
+ if(this->CheckDirectoryForName(path, *i))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path,
+ Name& name)
+{
+ // If the original library name provided by the user matches one of
+ // the suffixes, try it first. This allows users to search
+ // specifically for a static library on some platforms (on MS tools
+ // one cannot tell just from the library name whether it is a static
+ // library or an import library).
+ if(name.TryRaw)
+ {
+ this->TestPath = path;
+ this->TestPath += name.Raw;
+ if(cmSystemTools::FileExists(this->TestPath.c_str(), true))
+ {
+ this->BestPath =
+ cmSystemTools::CollapseFullPath(this->TestPath.c_str());
+ cmSystemTools::ConvertToUnixSlashes(this->BestPath);
+ return true;
+ }
+ }
+
+ // No library file has yet been found.
+ size_type bestPrefix = this->Prefixes.size();
+ size_type bestSuffix = this->Suffixes.size();
+ unsigned int bestMajor = 0;
+ unsigned int bestMinor = 0;
+
+ // Search for a file matching the library name regex.
+ std::string dir = path;
+ cmSystemTools::ConvertToUnixSlashes(dir);
+ std::set<std::string> const& files = this->GG->GetDirectoryContent(dir);
+ for(std::set<std::string>::const_iterator fi = files.begin();
+ fi != files.end(); ++fi)
+ {
+ std::string const& origName = *fi;
+#if defined(_WIN32) || defined(__APPLE__)
+ std::string testName = cmSystemTools::LowerCase(origName);
+#else
+ std::string const& testName = origName;
+#endif
+ if(name.Regex.find(testName))
+ {
+ this->TestPath = path;
+ this->TestPath += origName;
+ if(!cmSystemTools::FileIsDirectory(this->TestPath.c_str()))
+ {
+ // This is a matching file. Check if it is better than the
+ // best name found so far. Earlier prefixes are preferred,
+ // followed by earlier suffixes. For OpenBSD, shared library
+ // version extensions are compared.
+ size_type prefix = this->GetPrefixIndex(name.Regex.match(1));
+ size_type suffix = this->GetSuffixIndex(name.Regex.match(2));
+ unsigned int major = 0;
+ unsigned int minor = 0;
+ if(this->OpenBSD)
+ {
+ sscanf(name.Regex.match(3).c_str(), ".%u.%u", &major, &minor);
+ }
+ if(this->BestPath.empty() || prefix < bestPrefix ||
+ (prefix == bestPrefix && suffix < bestSuffix) ||
+ (prefix == bestPrefix && suffix == bestSuffix &&
+ (major > bestMajor ||
+ (major == bestMajor && minor > bestMinor))))
+ {
+ this->BestPath = this->TestPath;
+ bestPrefix = prefix;
+ bestSuffix = suffix;
+ bestMajor = major;
+ bestMinor = minor;
+ }
+ }
+ }
+ }
+
+ // Use the best candidate found in this directory, if any.
+ return !this->BestPath.empty();
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindLibraryCommand::FindNormalLibrary()
+{
+ if(this->NamesPerDir)
+ {
+ return this->FindNormalLibraryNamesPerDir();
+ }
+ else
+ {
+ return this->FindNormalLibraryDirsPerName();
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindLibraryCommand::FindNormalLibraryNamesPerDir()
+{
+ // Search for all names in each directory.
+ cmFindLibraryHelper helper(this->Makefile);
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end() ; ++ni)
+ {
+ helper.AddName(*ni);
+ }
+ // Search every directory.
+ for(std::vector<std::string>::const_iterator
+ p = this->SearchPaths.begin(); p != this->SearchPaths.end(); ++p)
+ {
+ if(helper.CheckDirectory(*p))
+ {
+ return helper.BestPath;
+ }
+ }
+ // Couldn't find the library.
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindLibraryCommand::FindNormalLibraryDirsPerName()
+{
+ // Search the entire path for each name.
+ cmFindLibraryHelper helper(this->Makefile);
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end() ; ++ni)
+ {
+ // Switch to searching for this name.
+ std::string const& name = *ni;
+ helper.AddName(name);
+
+ // Search every directory.
+ for(std::vector<std::string>::const_iterator
+ p = this->SearchPaths.begin();
+ p != this->SearchPaths.end(); ++p)
+ {
+ if(helper.CheckDirectory(*p))
+ {
+ return helper.BestPath;
+ }
+ }
+ }
+ // Couldn't find the library.
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindLibraryCommand::FindFrameworkLibrary()
+{
+ if(this->NamesPerDir)
+ {
+ return this->FindFrameworkLibraryNamesPerDir();
+ }
+ else
+ {
+ return this->FindFrameworkLibraryDirsPerName();
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindLibraryCommand::FindFrameworkLibraryNamesPerDir()
+{
+ std::string fwPath;
+ // Search for all names in each search path.
+ for(std::vector<std::string>::const_iterator di = this->SearchPaths.begin();
+ di != this->SearchPaths.end(); ++di)
+ {
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end() ; ++ni)
+ {
+ fwPath = *di;
+ fwPath += *ni;
+ fwPath += ".framework";
+ if(cmSystemTools::FileIsDirectory(fwPath.c_str()))
+ {
+ return cmSystemTools::CollapseFullPath(fwPath.c_str());
+ }
+ }
+ }
+
+ // No framework found.
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindLibraryCommand::FindFrameworkLibraryDirsPerName()
+{
+ std::string fwPath;
+ // Search for each name in all search paths.
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end() ; ++ni)
+ {
+ for(std::vector<std::string>::const_iterator
+ di = this->SearchPaths.begin();
+ di != this->SearchPaths.end(); ++di)
+ {
+ fwPath = *di;
+ fwPath += *ni;
+ fwPath += ".framework";
+ if(cmSystemTools::FileIsDirectory(fwPath.c_str()))
+ {
+ return cmSystemTools::CollapseFullPath(fwPath.c_str());
+ }
+ }
+ }
+
+ // No framework found.
+ return "";
+}
diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h
new file mode 100644
index 0000000000..e25717446e
--- /dev/null
+++ b/Source/cmFindLibraryCommand.h
@@ -0,0 +1,74 @@
+/*============================================================================
+ 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 cmFindLibraryCommand_h
+#define cmFindLibraryCommand_h
+
+#include "cmFindBase.h"
+
+
+/** \class cmFindLibraryCommand
+ * \brief Define a command to search for a library.
+ *
+ * cmFindLibraryCommand is used to define a CMake variable
+ * that specifies a library. The command searches for a given
+ * file in a list of directories.
+ */
+class cmFindLibraryCommand : public cmFindBase
+{
+public:
+ cmFindLibraryCommand();
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmFindLibraryCommand;
+ }
+
+ /**
+ * 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 "find_library";}
+
+ cmTypeMacro(cmFindLibraryCommand, cmFindBase);
+
+protected:
+ void AddArchitecturePaths(const char* suffix);
+ void AddArchitecturePath(std::string const& dir,
+ std::string::size_type start_pos,
+ const char* suffix,
+ bool fresh = true);
+ std::string FindLibrary();
+private:
+ std::string FindNormalLibrary();
+ std::string FindNormalLibraryNamesPerDir();
+ std::string FindNormalLibraryDirsPerName();
+ std::string FindFrameworkLibrary();
+ std::string FindFrameworkLibraryNamesPerDir();
+ std::string FindFrameworkLibraryDirsPerName();
+};
+
+
+
+#endif
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
new file mode 100644
index 0000000000..55a61f5b1f
--- /dev/null
+++ b/Source/cmFindPackageCommand.cxx
@@ -0,0 +1,2261 @@
+/*============================================================================
+ 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 "cmFindPackageCommand.h"
+
+#include <cmsys/Directory.hxx>
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Encoding.hxx>
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+#include "cmVariableWatch.h"
+#endif
+
+#if defined(__HAIKU__)
+#include <string.h>
+#include <FindDirectory.h>
+#include <StorageDefs.h>
+#endif
+
+//----------------------------------------------------------------------------
+cmFindPackageCommand::cmFindPackageCommand()
+{
+ this->CMakePathName = "PACKAGE";
+ this->Quiet = false;
+ this->Required = false;
+ this->NoUserRegistry = false;
+ this->NoSystemRegistry = false;
+ this->NoBuilds = false;
+ this->UseConfigFiles = true;
+ this->UseFindModules = true;
+ this->DebugMode = false;
+ this->UseLib64Paths = false;
+ this->PolicyScope = true;
+ this->VersionMajor = 0;
+ this->VersionMinor = 0;
+ this->VersionPatch = 0;
+ this->VersionTweak = 0;
+ this->VersionCount = 0;
+ this->VersionExact = false;
+ this->VersionFoundMajor = 0;
+ this->VersionFoundMinor = 0;
+ this->VersionFoundPatch = 0;
+ this->VersionFoundTweak = 0;
+ this->VersionFoundCount = 0;
+ this->RequiredCMakeVersion = 0;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // Lookup required version of CMake.
+ if(const char* rv =
+ this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"))
+ {
+ unsigned int v[3] = {0,0,0};
+ sscanf(rv, "%u.%u.%u", &v[0], &v[1], &v[2]);
+ this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0],v[1],v[2]);
+ }
+
+ // Check for debug mode.
+ this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE");
+
+ // Lookup target architecture, if any.
+ if(const char* arch =
+ this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE"))
+ {
+ this->LibraryArchitecture = arch;
+ }
+
+ // Lookup whether lib64 paths should be used.
+ if(this->Makefile->PlatformIs64Bit() &&
+ this->Makefile->GetCMakeInstance()
+ ->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
+ {
+ this->UseLib64Paths = true;
+ }
+
+ // Check if User Package Registry should be disabled
+ if(this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY"))
+ {
+ this->NoUserRegistry = true;
+ }
+
+ // Check if System Package Registry should be disabled
+ if(this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY"))
+ {
+ this->NoSystemRegistry = true;
+ }
+
+ // Find the current root path mode.
+ this->SelectDefaultRootPathMode();
+
+ // Find the current bundle/framework search policy.
+ this->SelectDefaultMacMode();
+
+ // Record options.
+ this->Name = args[0];
+ std::string components;
+ const char* components_sep = "";
+ std::set<std::string> requiredComponents;
+ std::set<std::string> optionalComponents;
+
+ // Always search directly in a generated path.
+ this->SearchPathSuffixes.push_back("");
+
+ // Parse the arguments.
+ enum Doing { DoingNone, DoingComponents, DoingOptionalComponents, DoingNames,
+ DoingPaths, DoingPathSuffixes, DoingConfigs, DoingHints };
+ Doing doing = DoingNone;
+ cmsys::RegularExpression version("^[0-9.]+$");
+ bool haveVersion = false;
+ std::set<unsigned int> configArgs;
+ std::set<unsigned int> moduleArgs;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "QUIET")
+ {
+ this->Quiet = true;
+ doing = DoingNone;
+ }
+ else if(args[i] == "EXACT")
+ {
+ this->VersionExact = true;
+ doing = DoingNone;
+ }
+ else if(args[i] == "MODULE")
+ {
+ moduleArgs.insert(i);
+ doing = DoingNone;
+ }
+ else if(args[i] == "CONFIG")
+ {
+ configArgs.insert(i);
+ doing = DoingNone;
+ }
+ else if(args[i] == "NO_MODULE")
+ {
+ configArgs.insert(i);
+ doing = DoingNone;
+ }
+ else if(args[i] == "REQUIRED")
+ {
+ this->Required = true;
+ doing = DoingComponents;
+ }
+ else if(args[i] == "COMPONENTS")
+ {
+ doing = DoingComponents;
+ }
+ else if(args[i] == "OPTIONAL_COMPONENTS")
+ {
+ doing = DoingOptionalComponents;
+ }
+ else if(args[i] == "NAMES")
+ {
+ configArgs.insert(i);
+ doing = DoingNames;
+ }
+ else if(args[i] == "PATHS")
+ {
+ configArgs.insert(i);
+ doing = DoingPaths;
+ }
+ else if(args[i] == "HINTS")
+ {
+ configArgs.insert(i);
+ doing = DoingHints;
+ }
+ else if(args[i] == "PATH_SUFFIXES")
+ {
+ configArgs.insert(i);
+ doing = DoingPathSuffixes;
+ }
+ else if(args[i] == "CONFIGS")
+ {
+ configArgs.insert(i);
+ doing = DoingConfigs;
+ }
+ else if(args[i] == "NO_POLICY_SCOPE")
+ {
+ this->PolicyScope = false;
+ doing = DoingNone;
+ }
+ else if(args[i] == "NO_CMAKE_PACKAGE_REGISTRY")
+ {
+ this->NoUserRegistry = true;
+ configArgs.insert(i);
+ doing = DoingNone;
+ }
+ else if(args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY")
+ {
+ this->NoSystemRegistry = true;
+ configArgs.insert(i);
+ doing = DoingNone;
+ }
+ else if(args[i] == "NO_CMAKE_BUILDS_PATH")
+ {
+ this->NoBuilds = true;
+ configArgs.insert(i);
+ doing = DoingNone;
+ }
+ else if(this->CheckCommonArgument(args[i]))
+ {
+ configArgs.insert(i);
+ doing = DoingNone;
+ }
+ else if((doing == DoingComponents) || (doing == DoingOptionalComponents))
+ {
+ // Set a variable telling the find script whether this component
+ // is required.
+ const char* isRequired = "1";
+ if (doing == DoingOptionalComponents)
+ {
+ isRequired = "0";
+ optionalComponents.insert(args[i]);
+ }
+ else
+ {
+ requiredComponents.insert(args[i]);
+ }
+
+ std::string req_var = this->Name + "_FIND_REQUIRED_" + args[i];
+ this->AddFindDefinition(req_var, isRequired);
+
+ // Append to the list of required components.
+ components += components_sep;
+ components += args[i];
+ components_sep = ";";
+ }
+ else if(doing == DoingNames)
+ {
+ this->Names.push_back(args[i]);
+ }
+ else if(doing == DoingPaths)
+ {
+ this->AddUserPath(args[i], this->UserPaths);
+ }
+ else if(doing == DoingHints)
+ {
+ this->AddUserPath(args[i], this->UserHints);
+ }
+ else if(doing == DoingPathSuffixes)
+ {
+ this->AddPathSuffix(args[i]);
+ }
+ else if(doing == DoingConfigs)
+ {
+ if(args[i].find_first_of(":/\\") != args[i].npos ||
+ cmSystemTools::GetFilenameLastExtension(args[i]) != ".cmake")
+ {
+ cmOStringStream e;
+ e << "given CONFIGS option followed by invalid file name \""
+ << args[i] << "\". The names given must be file names without "
+ << "a path and with a \".cmake\" extension.";
+ this->SetError(e.str());
+ return false;
+ }
+ this->Configs.push_back(args[i]);
+ }
+ else if(!haveVersion && version.find(args[i].c_str()))
+ {
+ haveVersion = true;
+ this->Version = args[i];
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "called with invalid argument \"" << args[i] << "\"";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ std::vector<std::string> doubledComponents;
+ std::set_intersection(requiredComponents.begin(), requiredComponents.end(),
+ optionalComponents.begin(), optionalComponents.end(),
+ std::back_inserter(doubledComponents));
+ if(!doubledComponents.empty())
+ {
+ cmOStringStream e;
+ e << "called with components that are both required and optional:\n";
+ for(unsigned int i=0; i<doubledComponents.size(); ++i)
+ {
+ e << " " << doubledComponents[i] << "\n";
+ }
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Maybe choose one mode exclusively.
+ this->UseFindModules = configArgs.empty();
+ this->UseConfigFiles = moduleArgs.empty();
+ if(!this->UseFindModules && !this->UseConfigFiles)
+ {
+ cmOStringStream e;
+ e << "given options exclusive to Module mode:\n";
+ for(std::set<unsigned int>::const_iterator si = moduleArgs.begin();
+ si != moduleArgs.end(); ++si)
+ {
+ e << " " << args[*si] << "\n";
+ }
+ e << "and options exclusive to Config mode:\n";
+ for(std::set<unsigned int>::const_iterator si = configArgs.begin();
+ si != configArgs.end(); ++si)
+ {
+ e << " " << args[*si] << "\n";
+ }
+ e << "The options are incompatible.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Ignore EXACT with no version.
+ if(this->Version.empty() && this->VersionExact)
+ {
+ this->VersionExact = false;
+ this->Makefile->IssueMessage(
+ cmake::AUTHOR_WARNING, "Ignoring EXACT since no version is requested.");
+ }
+
+ if(this->Version.empty() || components.empty())
+ {
+ // Check whether we are recursing inside "Find<name>.cmake" within
+ // another find_package(<name>) call.
+ std::string mod = this->Name;
+ mod += "_FIND_MODULE";
+ if(this->Makefile->IsOn(mod))
+ {
+ if(this->Version.empty())
+ {
+ // Get version information from the outer call if necessary.
+ // Requested version string.
+ std::string ver = this->Name;
+ ver += "_FIND_VERSION";
+ this->Version = this->Makefile->GetSafeDefinition(ver);
+
+ // Whether an exact version is required.
+ std::string exact = this->Name;
+ exact += "_FIND_VERSION_EXACT";
+ this->VersionExact = this->Makefile->IsOn(exact);
+ }
+ if(components.empty())
+ {
+ std::string components_var = this->Name + "_FIND_COMPONENTS";
+ components = this->Makefile->GetSafeDefinition(components_var);
+ }
+ }
+ }
+
+ if(!this->Version.empty())
+ {
+ // Try to parse the version number and store the results that were
+ // successfully parsed.
+ unsigned int parsed_major;
+ unsigned int parsed_minor;
+ unsigned int parsed_patch;
+ unsigned int parsed_tweak;
+ this->VersionCount = sscanf(this->Version.c_str(), "%u.%u.%u.%u",
+ &parsed_major, &parsed_minor,
+ &parsed_patch, &parsed_tweak);
+ switch(this->VersionCount)
+ {
+ case 4: this->VersionTweak = parsed_tweak; // no break!
+ case 3: this->VersionPatch = parsed_patch; // no break!
+ case 2: this->VersionMinor = parsed_minor; // no break!
+ case 1: this->VersionMajor = parsed_major; // no break!
+ default: break;
+ }
+ }
+
+ std::string disableFindPackageVar = "CMAKE_DISABLE_FIND_PACKAGE_";
+ disableFindPackageVar += this->Name;
+ if(this->Makefile->IsOn(disableFindPackageVar))
+ {
+ if (this->Required)
+ {
+ cmOStringStream e;
+ e << "for module " << this->Name << " called with REQUIRED, but "
+ << disableFindPackageVar
+ << " is enabled. A REQUIRED package cannot be disabled.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ return true;
+ }
+
+
+ this->SetModuleVariables(components);
+
+ // See if there is a Find<package>.cmake module.
+ if(this->UseFindModules)
+ {
+ bool foundModule = false;
+ if(!this->FindModule(foundModule))
+ {
+ this->AppendSuccessInformation();
+ return false;
+ }
+ if(foundModule)
+ {
+ this->AppendSuccessInformation();
+ return true;
+ }
+ }
+
+ if(this->UseFindModules && this->UseConfigFiles &&
+ this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE"))
+ {
+ cmOStringStream aw;
+ if(this->RequiredCMakeVersion >= CMake_VERSION_ENCODE(2,8,8))
+ {
+ aw << "find_package called without either MODULE or CONFIG option and "
+ "no Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. "
+ "Add MODULE to exclusively request Module mode and fail if "
+ "Find" << this->Name << ".cmake is missing. "
+ "Add CONFIG to exclusively request Config mode and search for a "
+ "package configuration file provided by " << this->Name <<
+ " (" << this->Name << "Config.cmake or " <<
+ cmSystemTools::LowerCase(this->Name) << "-config.cmake). ";
+ }
+ else
+ {
+ aw << "find_package called without NO_MODULE option and no "
+ "Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. "
+ "Add NO_MODULE to exclusively request Config mode and search for a "
+ "package configuration file provided by " << this->Name <<
+ " (" << this->Name << "Config.cmake or " <<
+ cmSystemTools::LowerCase(this->Name) << "-config.cmake). "
+ "Otherwise make Find" << this->Name << ".cmake available in "
+ "CMAKE_MODULE_PATH.";
+ }
+ aw << "\n"
+ "(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this warning.)";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str());
+ }
+
+ // No find module. Assume the project has a CMake config file. Use
+ // a <package>_DIR cache variable to locate it.
+ this->Variable = this->Name;
+ this->Variable += "_DIR";
+
+ // Add the default name.
+ if(this->Names.empty())
+ {
+ this->Names.push_back(this->Name);
+ }
+
+ // Add the default configs.
+ if(this->Configs.empty())
+ {
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni)
+ {
+ std::string config = *ni;
+ config += "Config.cmake";
+ this->Configs.push_back(config);
+
+ config = cmSystemTools::LowerCase(*ni);
+ config += "-config.cmake";
+ this->Configs.push_back(config);
+ }
+ }
+
+ // get igonored paths from vars and reroot them.
+ std::vector<std::string> ignored;
+ this->GetIgnoredPaths(ignored);
+ this->RerootPaths(ignored);
+
+ // Construct a set of ignored paths
+ this->IgnoredPaths.clear();
+ this->IgnoredPaths.insert(ignored.begin(), ignored.end());
+
+ // Find and load the package.
+ bool result = this->HandlePackageMode();
+ this->AppendSuccessInformation();
+ return result;
+}
+
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::SetModuleVariables(const std::string& components)
+{
+ this->AddFindDefinition("CMAKE_FIND_PACKAGE_NAME", this->Name.c_str());
+
+ // Store the list of components.
+ std::string components_var = this->Name + "_FIND_COMPONENTS";
+ this->AddFindDefinition(components_var, components.c_str());
+
+ if(this->Quiet)
+ {
+ // Tell the module that is about to be read that it should find
+ // quietly.
+ std::string quietly = this->Name;
+ quietly += "_FIND_QUIETLY";
+ this->AddFindDefinition(quietly, "1");
+ }
+
+ if(this->Required)
+ {
+ // Tell the module that is about to be read that it should report
+ // a fatal error if the package is not found.
+ std::string req = this->Name;
+ req += "_FIND_REQUIRED";
+ this->AddFindDefinition(req, "1");
+ }
+
+ if(!this->Version.empty())
+ {
+ // Tell the module that is about to be read what version of the
+ // package has been requested.
+ std::string ver = this->Name;
+ ver += "_FIND_VERSION";
+ this->AddFindDefinition(ver, this->Version.c_str());
+ char buf[64];
+ sprintf(buf, "%u", this->VersionMajor);
+ this->AddFindDefinition(ver+"_MAJOR", buf);
+ sprintf(buf, "%u", this->VersionMinor);
+ this->AddFindDefinition(ver+"_MINOR", buf);
+ sprintf(buf, "%u", this->VersionPatch);
+ this->AddFindDefinition(ver+"_PATCH", buf);
+ sprintf(buf, "%u", this->VersionTweak);
+ this->AddFindDefinition(ver+"_TWEAK", buf);
+ sprintf(buf, "%u", this->VersionCount);
+ this->AddFindDefinition(ver+"_COUNT", buf);
+
+ // Tell the module whether an exact version has been requested.
+ std::string exact = this->Name;
+ exact += "_FIND_VERSION_EXACT";
+ this->AddFindDefinition(exact, this->VersionExact? "1":"0");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddFindDefinition(const std::string& var,
+ const char* val)
+{
+ if(const char* old = this->Makefile->GetDefinition(var))
+ {
+ this->OriginalDefs[var].exists = true;
+ this->OriginalDefs[var].value = old;
+ }
+ else
+ {
+ this->OriginalDefs[var].exists = false;
+ }
+ this->Makefile->AddDefinition(var, val);
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::RestoreFindDefinitions()
+{
+ for(std::map<std::string, OriginalDef>::iterator
+ i = this->OriginalDefs.begin(); i != this->OriginalDefs.end(); ++i)
+ {
+ OriginalDef const& od = i->second;
+ if(od.exists)
+ {
+ this->Makefile->AddDefinition(i->first, od.value.c_str());
+ }
+ else
+ {
+ this->Makefile->RemoveDefinition(i->first);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::FindModule(bool& found)
+{
+ std::string module = "Find";
+ module += this->Name;
+ module += ".cmake";
+ std::string mfile = this->Makefile->GetModulesFile(module.c_str());
+ if ( mfile.size() )
+ {
+ // Load the module we found, and set "<name>_FIND_MODULE" to true
+ // while inside it.
+ found = true;
+ std::string var = this->Name;
+ var += "_FIND_MODULE";
+ this->Makefile->AddDefinition(var, "1");
+ bool result = this->ReadListFile(mfile.c_str(), DoPolicyScope);
+ this->Makefile->RemoveDefinition(var);
+ return result;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::HandlePackageMode()
+{
+ this->ConsideredConfigs.clear();
+
+ // Support old capitalization behavior.
+ std::string upperDir = cmSystemTools::UpperCase(this->Name);
+ std::string upperFound = cmSystemTools::UpperCase(this->Name);
+ upperDir += "_DIR";
+ upperFound += "_FOUND";
+
+ // Try to find the config file.
+ const char* def = this->Makefile->GetDefinition(this->Variable);
+
+ // Try to load the config file if the directory is known
+ bool fileFound = false;
+ if (this->UseConfigFiles)
+ {
+ if(!cmSystemTools::IsOff(def))
+ {
+ // Get the directory from the variable value.
+ std::string dir = def;
+ cmSystemTools::ConvertToUnixSlashes(dir);
+
+ // Treat relative paths with respect to the current source dir.
+ if(!cmSystemTools::FileIsFullPath(dir.c_str()))
+ {
+ dir = "/" + dir;
+ dir = this->Makefile->GetCurrentDirectory() + dir;
+ }
+ // The file location was cached. Look for the correct file.
+ std::string file;
+ if (this->FindConfigFile(dir, file))
+ {
+ this->FileFound = file;
+ fileFound = true;
+ }
+ def = this->Makefile->GetDefinition(this->Variable);
+ }
+
+ // Search for the config file if it is not already found.
+ if(cmSystemTools::IsOff(def) || !fileFound)
+ {
+ fileFound = this->FindConfig();
+ def = this->Makefile->GetDefinition(this->Variable);
+ }
+
+ // Sanity check.
+ if(fileFound && this->FileFound.empty())
+ {
+ this->Makefile->IssueMessage(
+ cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!");
+ fileFound = false;
+ }
+ }
+
+ std::string foundVar = this->Name;
+ foundVar += "_FOUND";
+ std::string notFoundMessageVar = this->Name;
+ notFoundMessageVar += "_NOT_FOUND_MESSAGE";
+ std::string notFoundMessage;
+
+ // If the directory for the config file was found, try to read the file.
+ bool result = true;
+ bool found = false;
+ bool configFileSetFOUNDFalse = false;
+
+ if(fileFound)
+ {
+ if ((this->Makefile->IsDefinitionSet(foundVar))
+ && (this->Makefile->IsOn(foundVar) == false))
+ {
+ // by removing Foo_FOUND here if it is FALSE, we don't really change
+ // the situation for the Config file which is about to be included,
+ // but we make it possible to detect later on whether the Config file
+ // has set Foo_FOUND to FALSE itself:
+ this->Makefile->RemoveDefinition(foundVar);
+ }
+ this->Makefile->RemoveDefinition(notFoundMessageVar);
+
+ // Set the version variables before loading the config file.
+ // It may override them.
+ this->StoreVersionFound();
+
+ // Parse the configuration file.
+ if(this->ReadListFile(this->FileFound.c_str(), DoPolicyScope))
+ {
+ // The package has been found.
+ found = true;
+
+ // Check whether the Config file has set Foo_FOUND to FALSE:
+ if ((this->Makefile->IsDefinitionSet(foundVar))
+ && (this->Makefile->IsOn(foundVar) == false))
+ {
+ // we get here if the Config file has set Foo_FOUND actively to FALSE
+ found = false;
+ configFileSetFOUNDFalse = true;
+ notFoundMessage = this->Makefile->GetSafeDefinition(
+ notFoundMessageVar);
+ }
+ }
+ else
+ {
+ // The configuration file is invalid.
+ result = false;
+ }
+ }
+
+ if (result && !found && (!this->Quiet || this->Required))
+ {
+ // The variable is not set.
+ cmOStringStream e;
+ cmOStringStream aw;
+ if (configFileSetFOUNDFalse)
+ {
+ e << "Found package configuration file:\n"
+ " " << this->FileFound << "\n"
+ "but it set " << foundVar << " to FALSE so package \"" <<
+ this->Name << "\" is considered to be NOT FOUND.";
+ if (!notFoundMessage.empty())
+ {
+ e << " Reason given by package: \n" << notFoundMessage << "\n";
+ }
+ }
+ // If there are files in ConsideredConfigs, it means that FooConfig.cmake
+ // have been found, but they didn't have appropriate versions.
+ else if (this->ConsideredConfigs.size() > 0)
+ {
+ e << "Could not find a configuration file for package \""
+ << this->Name << "\" that "
+ << (this->VersionExact? "exactly matches" : "is compatible with")
+ << " requested version \"" << this->Version << "\".\n"
+ << "The following configuration files were considered but not "
+ "accepted:\n";
+ for(std::vector<ConfigFileInfo>::size_type i=0;
+ i<this->ConsideredConfigs.size(); i++)
+ {
+ e << " " << this->ConsideredConfigs[i].filename
+ << ", version: " << this->ConsideredConfigs[i].version << "\n";
+ }
+ }
+ else
+ {
+ std::string requestedVersionString;
+ if(!this->Version.empty())
+ {
+ requestedVersionString = " (requested version ";
+ requestedVersionString += this->Version;
+ requestedVersionString += ")";
+ }
+
+ if (this->UseConfigFiles)
+ {
+ if(this->UseFindModules)
+ {
+ e << "By not providing \"Find" << this->Name << ".cmake\" in "
+ "CMAKE_MODULE_PATH this project has asked CMake to find a "
+ "package configuration file provided by \""<<this->Name<< "\", "
+ "but CMake did not find one.\n";
+ }
+
+ if(this->Configs.size() == 1)
+ {
+ e << "Could not find a package configuration file named \""
+ << this->Configs[0] << "\" provided by package \""
+ << this->Name << "\"" << requestedVersionString <<".\n";
+ }
+ else
+ {
+ e << "Could not find a package configuration file provided by \""
+ << this->Name << "\"" << requestedVersionString
+ << " with any of the following names:\n";
+ for(std::vector<std::string>::const_iterator ci =
+ this->Configs.begin();
+ ci != this->Configs.end(); ++ci)
+ {
+ e << " " << *ci << "\n";
+ }
+ }
+
+ e << "Add the installation prefix of \"" << this->Name << "\" to "
+ "CMAKE_PREFIX_PATH or set \"" << this->Variable << "\" to a "
+ "directory containing one of the above files. "
+ "If \"" << this->Name << "\" provides a separate development "
+ "package or SDK, be sure it has been installed.";
+ }
+ else // if(!this->UseFindModules && !this->UseConfigFiles)
+ {
+ e << "No \"Find" << this->Name << ".cmake\" found in "
+ << "CMAKE_MODULE_PATH.";
+
+ aw<< "Find"<< this->Name <<".cmake must either be part of this "
+ "project itself, in this case adjust CMAKE_MODULE_PATH so that "
+ "it points to the correct location inside its source tree.\n"
+ "Or it must be installed by a package which has already been "
+ "found via find_package(). In this case make sure that "
+ "package has indeed been found and adjust CMAKE_MODULE_PATH to "
+ "contain the location where that package has installed "
+ "Find" << this->Name << ".cmake. This must be a location "
+ "provided by that package. This error in general means that "
+ "the buildsystem of this project is relying on a Find-module "
+ "without ensuring that it is actually available.\n";
+ }
+ }
+
+
+ this->Makefile->IssueMessage(
+ this->Required? cmake::FATAL_ERROR : cmake::WARNING, e.str());
+ if (this->Required)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ }
+
+ if (!aw.str().empty())
+ {
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,aw.str());
+ }
+ }
+
+ // Set a variable marking whether the package was found.
+ this->Makefile->AddDefinition(foundVar, found? "1":"0");
+
+ // Set a variable naming the configuration file that was found.
+ std::string fileVar = this->Name;
+ fileVar += "_CONFIG";
+ if(found)
+ {
+ this->Makefile->AddDefinition(fileVar, this->FileFound.c_str());
+ }
+ else
+ {
+ this->Makefile->RemoveDefinition(fileVar);
+ }
+
+ std::string consideredConfigsVar = this->Name;
+ consideredConfigsVar += "_CONSIDERED_CONFIGS";
+ std::string consideredVersionsVar = this->Name;
+ consideredVersionsVar += "_CONSIDERED_VERSIONS";
+
+ std::string consideredConfigFiles;
+ std::string consideredVersions;
+
+ const char* sep = "";
+ for(std::vector<ConfigFileInfo>::size_type i=0;
+ i<this->ConsideredConfigs.size(); i++)
+ {
+ consideredConfigFiles += sep;
+ consideredVersions += sep;
+ consideredConfigFiles += this->ConsideredConfigs[i].filename;
+ consideredVersions += this->ConsideredConfigs[i].version;
+ sep = ";";
+ }
+
+ this->Makefile->AddDefinition(consideredConfigsVar,
+ consideredConfigFiles.c_str());
+
+ this->Makefile->AddDefinition(consideredVersionsVar,
+ consideredVersions.c_str());
+
+ return result;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::FindConfig()
+{
+ // Compute the set of search prefixes.
+ this->ComputePrefixes();
+
+ // Look for the project's configuration file.
+ bool found = false;
+
+ // Search for frameworks.
+ if(!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly))
+ {
+ found = this->FindFrameworkConfig();
+ }
+
+ // Search for apps.
+ if(!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly))
+ {
+ found = this->FindAppBundleConfig();
+ }
+
+ // Search prefixes.
+ if(!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
+ {
+ found = this->FindPrefixedConfig();
+ }
+
+ // Search for frameworks.
+ if(!found && this->SearchFrameworkLast)
+ {
+ found = this->FindFrameworkConfig();
+ }
+
+ // Search for apps.
+ if(!found && this->SearchAppBundleLast)
+ {
+ found = this->FindAppBundleConfig();
+ }
+
+ // Store the entry in the cache so it can be set by the user.
+ std::string init;
+ if(found)
+ {
+ init = cmSystemTools::GetFilenamePath(this->FileFound);
+ }
+ else
+ {
+ init = this->Variable + "-NOTFOUND";
+ }
+ std::string help =
+ "The directory containing a CMake configuration file for ";
+ help += this->Name;
+ help += ".";
+ // We force the value since we do not get here if it was already set.
+ this->Makefile->AddCacheDefinition(this->Variable,
+ init.c_str(), help.c_str(),
+ cmCacheManager::PATH, true);
+ return found;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::FindPrefixedConfig()
+{
+ std::vector<std::string>& prefixes = this->SearchPaths;
+ for(std::vector<std::string>::const_iterator pi = prefixes.begin();
+ pi != prefixes.end(); ++pi)
+ {
+ if(this->SearchPrefix(*pi))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::FindFrameworkConfig()
+{
+ std::vector<std::string>& prefixes = this->SearchPaths;
+ for(std::vector<std::string>::const_iterator i = prefixes.begin();
+ i != prefixes.end(); ++i)
+ {
+ if(this->SearchFrameworkPrefix(*i))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::FindAppBundleConfig()
+{
+ std::vector<std::string>& prefixes = this->SearchPaths;
+ for(std::vector<std::string>::const_iterator i = prefixes.begin();
+ i != prefixes.end(); ++i)
+ {
+ if(this->SearchAppBundlePrefix(*i))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr)
+{
+ if(this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(), f, 0,
+ !this->PolicyScope || psr == NoPolicyScope))
+ {
+ return true;
+ }
+ std::string e = "Error reading CMake code from \"";
+ e += f;
+ e += "\".";
+ this->SetError(e);
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AppendToFoundProperty(bool found)
+{
+ std::vector<std::string> foundContents;
+ const char *foundProp =
+ this->Makefile->GetCMakeInstance()->GetProperty("PACKAGES_FOUND");
+ if (foundProp && *foundProp)
+ {
+ std::string tmp = foundProp;
+
+ cmSystemTools::ExpandListArgument(tmp, foundContents, false);
+ std::vector<std::string>::iterator nameIt = std::find(
+ foundContents.begin(), foundContents.end(), this->Name);
+ if(nameIt != foundContents.end())
+ {
+ foundContents.erase(nameIt);
+ }
+ }
+
+ std::vector<std::string> notFoundContents;
+ const char *notFoundProp =
+ this->Makefile->GetCMakeInstance()->GetProperty("PACKAGES_NOT_FOUND");
+ if (notFoundProp && *notFoundProp)
+ {
+ std::string tmp = notFoundProp;
+
+ cmSystemTools::ExpandListArgument(tmp, notFoundContents, false);
+ std::vector<std::string>::iterator nameIt = std::find(
+ notFoundContents.begin(), notFoundContents.end(), this->Name);
+ if(nameIt != notFoundContents.end())
+ {
+ notFoundContents.erase(nameIt);
+ }
+ }
+
+ if(found)
+ {
+ foundContents.push_back(this->Name);
+ }
+ else
+ {
+ notFoundContents.push_back(this->Name);
+ }
+
+
+ std::string tmp;
+ const char* sep ="";
+ for(size_t i=0; i<foundContents.size(); i++)
+ {
+ tmp += sep;
+ tmp += foundContents[i];
+ sep = ";";
+ }
+
+ this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_FOUND",
+ tmp.c_str());
+
+ tmp = "";
+ sep = "";
+ for(size_t i=0; i<notFoundContents.size(); i++)
+ {
+ tmp += sep;
+ tmp += notFoundContents[i];
+ sep = ";";
+ }
+ this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND",
+ tmp.c_str());
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AppendSuccessInformation()
+{
+ {
+ std::string transitivePropName = "_CMAKE_";
+ transitivePropName += this->Name + "_TRANSITIVE_DEPENDENCY";
+ this->Makefile->GetCMakeInstance()
+ ->SetProperty(transitivePropName, "False");
+ }
+ std::string found = this->Name;
+ found += "_FOUND";
+ std::string upperFound = cmSystemTools::UpperCase(found);
+
+ const char* upperResult = this->Makefile->GetDefinition(upperFound);
+ const char* result = this->Makefile->GetDefinition(found);
+ bool packageFound = ((cmSystemTools::IsOn(result))
+ || (cmSystemTools::IsOn(upperResult)));
+
+ this->AppendToFoundProperty(packageFound);
+
+ // Record whether the find was quiet or not, so this can be used
+ // e.g. in FeatureSummary.cmake
+ std::string quietInfoPropName = "_CMAKE_";
+ quietInfoPropName += this->Name;
+ quietInfoPropName += "_QUIET";
+ this->Makefile->GetCMakeInstance()->SetProperty(quietInfoPropName,
+ this->Quiet ? "TRUE" : "FALSE");
+
+ // set a global property to record the required version of this package
+ std::string versionInfoPropName = "_CMAKE_";
+ versionInfoPropName += this->Name;
+ versionInfoPropName += "_REQUIRED_VERSION";
+ std::string versionInfo;
+ if(!this->Version.empty())
+ {
+ versionInfo = this->VersionExact ? "==" : ">=";
+ versionInfo += " ";
+ versionInfo += this->Version;
+ }
+ this->Makefile->GetCMakeInstance()->SetProperty(versionInfoPropName,
+ versionInfo.c_str());
+ if (this->Required)
+ {
+ std::string requiredInfoPropName = "_CMAKE_";
+ requiredInfoPropName += this->Name;
+ requiredInfoPropName += "_TYPE";
+ this->Makefile->GetCMakeInstance()->SetProperty(
+ requiredInfoPropName, "REQUIRED");
+ }
+
+
+ // Restore original state of "_FIND_" variables we set.
+ this->RestoreFindDefinitions();
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::ComputePrefixes()
+{
+ this->AddPrefixesCMakeVariable();
+ this->AddPrefixesCMakeEnvironment();
+ this->AddPrefixesUserHints();
+ this->AddPrefixesSystemEnvironment();
+ this->AddPrefixesUserRegistry();
+ this->AddPrefixesBuilds();
+ this->AddPrefixesCMakeSystemVariable();
+ this->AddPrefixesSystemRegistry();
+ this->AddPrefixesUserGuess();
+ this->ComputeFinalPaths();
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddPrefixesCMakeEnvironment()
+{
+ if(!this->NoCMakeEnvironmentPath && !this->NoDefaultPath)
+ {
+ // Check the environment variable with the same name as the cache
+ // entry.
+ std::string env;
+ if(cmSystemTools::GetEnv(this->Variable.c_str(), env) && env.length() > 0)
+ {
+ cmSystemTools::ConvertToUnixSlashes(env);
+ this->AddPathInternal(env, EnvPath);
+ }
+
+ this->AddEnvPath("CMAKE_PREFIX_PATH");
+ this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
+ this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddPrefixesCMakeVariable()
+{
+ if(!this->NoCMakePath && !this->NoDefaultPath)
+ {
+ this->AddCMakePath("CMAKE_PREFIX_PATH");
+ this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
+ this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddPrefixesSystemEnvironment()
+{
+ if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath)
+ {
+ // Use the system search path to generate prefixes.
+ // Relative paths are interpreted with respect to the current
+ // working directory.
+ std::vector<std::string> tmp;
+ cmSystemTools::GetPath(tmp);
+ for(std::vector<std::string>::iterator i = tmp.begin();
+ i != tmp.end(); ++i)
+ {
+ std::string const& d = *i;
+
+ // If the path is a PREFIX/bin case then add its parent instead.
+ if((cmHasLiteralSuffix(d, "/bin")) ||
+ (cmHasLiteralSuffix(d, "/sbin")))
+ {
+ this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath);
+ }
+ else
+ {
+ this->AddPathInternal(d, EnvPath);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddPrefixesUserRegistry()
+{
+ if(this->NoUserRegistry || this->NoDefaultPath)
+ {
+ return;
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ this->LoadPackageRegistryWinUser();
+#elif defined(__HAIKU__)
+ char dir[B_PATH_NAME_LENGTH];
+ if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) ==
+ B_OK)
+ {
+ std::string fname = dir;
+ fname += "/cmake/packages/";
+ fname += Name;
+ this->LoadPackageRegistryDir(fname);
+ }
+#else
+ if(const char* home = cmSystemTools::GetEnv("HOME"))
+ {
+ std::string dir = home;
+ dir += "/.cmake/packages/";
+ dir += this->Name;
+ this->LoadPackageRegistryDir(dir);
+ }
+#endif
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddPrefixesSystemRegistry()
+{
+ if(this->NoSystemRegistry || this->NoDefaultPath)
+ {
+ return;
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ this->LoadPackageRegistryWinSystem();
+#endif
+}
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# include <windows.h>
+# undef GetCurrentDirectory
+ // http://msdn.microsoft.com/en-us/library/aa384253%28v=vs.85%29.aspx
+# if !defined(KEY_WOW64_32KEY)
+# define KEY_WOW64_32KEY 0x0200
+# endif
+# if !defined(KEY_WOW64_64KEY)
+# define KEY_WOW64_64KEY 0x0100
+# endif
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::LoadPackageRegistryWinUser()
+{
+ // HKEY_CURRENT_USER\\Software shares 32-bit and 64-bit views.
+ this->LoadPackageRegistryWin(true, 0);
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::LoadPackageRegistryWinSystem()
+{
+ // HKEY_LOCAL_MACHINE\\SOFTWARE has separate 32-bit and 64-bit views.
+ // Prefer the target platform view first.
+ if(this->Makefile->PlatformIs64Bit())
+ {
+ this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY);
+ this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY);
+ }
+ else
+ {
+ this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY);
+ this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::LoadPackageRegistryWin(bool user,
+ unsigned int view)
+{
+ std::wstring key = L"Software\\Kitware\\CMake\\Packages\\";
+ key += cmsys::Encoding::ToWide(this->Name);
+ std::set<std::wstring> bad;
+ HKEY hKey;
+ if(RegOpenKeyExW(user? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
+ 0, KEY_QUERY_VALUE|view, &hKey) == ERROR_SUCCESS)
+ {
+ DWORD valueType = REG_NONE;
+ wchar_t name[16383]; // RegEnumValue docs limit name to 32767 _bytes_
+ std::vector<wchar_t> data(512);
+ bool done = false;
+ DWORD index = 0;
+ while(!done)
+ {
+ DWORD nameSize = static_cast<DWORD>(sizeof(name));
+ DWORD dataSize = static_cast<DWORD>(data.size()*sizeof(data[0]));
+ switch(RegEnumValueW(hKey, index, name, &nameSize,
+ 0, &valueType, (BYTE*)&data[0], &dataSize))
+ {
+ case ERROR_SUCCESS:
+ ++index;
+ if(valueType == REG_SZ)
+ {
+ data[dataSize] = 0;
+ cmsys_ios::stringstream ss(cmsys::Encoding::ToNarrow(&data[0]));
+ if(!this->CheckPackageRegistryEntry(ss))
+ {
+ // The entry is invalid.
+ bad.insert(name);
+ }
+ }
+ break;
+ case ERROR_MORE_DATA:
+ data.resize((dataSize+sizeof(data[0])-1)/sizeof(data[0]));
+ break;
+ case ERROR_NO_MORE_ITEMS: default: done = true; break;
+ }
+ }
+ RegCloseKey(hKey);
+ }
+
+ // Remove bad values if possible.
+ if(user && !bad.empty() &&
+ RegOpenKeyExW(HKEY_CURRENT_USER, key.c_str(),
+ 0, KEY_SET_VALUE|view, &hKey) == ERROR_SUCCESS)
+ {
+ for(std::set<std::wstring>::const_iterator vi = bad.begin();
+ vi != bad.end(); ++vi)
+ {
+ RegDeleteValueW(hKey, vi->c_str());
+ }
+ RegCloseKey(hKey);
+ }
+}
+#else
+//----------------------------------------------------------------------------
+class cmFindPackageCommandHoldFile
+{
+ const char* File;
+public:
+ cmFindPackageCommandHoldFile(const char* f): File(f) {}
+ ~cmFindPackageCommandHoldFile()
+ { if(this->File) { cmSystemTools::RemoveFile(this->File); } }
+ void Release() { this->File = 0; }
+};
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir)
+{
+ cmsys::Directory files;
+ if(!files.Load(dir.c_str()))
+ {
+ return;
+ }
+
+ std::string fname;
+ for(unsigned long i=0; i < files.GetNumberOfFiles(); ++i)
+ {
+ fname = dir;
+ fname += "/";
+ fname += files.GetFile(i);
+
+ if(!cmSystemTools::FileIsDirectory(fname.c_str()))
+ {
+ // Hold this file hostage until it behaves.
+ cmFindPackageCommandHoldFile holdFile(fname.c_str());
+
+ // Load the file.
+ cmsys::ifstream fin(fname.c_str(), std::ios::in | cmsys_ios_binary);
+ if(fin && this->CheckPackageRegistryEntry(fin))
+ {
+ // The file references an existing package, so release it.
+ holdFile.Release();
+ }
+ }
+ }
+
+ // TODO: Wipe out the directory if it is empty.
+}
+#endif
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::CheckPackageRegistryEntry(std::istream& is)
+{
+ // Parse the content of one package registry entry.
+ std::string fname;
+ if(cmSystemTools::GetLineFromStream(is, fname) &&
+ cmSystemTools::FileIsFullPath(fname.c_str()))
+ {
+ // The first line in the stream is the full path to a file or
+ // directory containing the package.
+ if(cmSystemTools::FileExists(fname.c_str()))
+ {
+ // The path exists. Look for the package here.
+ if(!cmSystemTools::FileIsDirectory(fname.c_str()))
+ {
+ fname = cmSystemTools::GetFilenamePath(fname);
+ }
+ this->AddPathInternal(fname, FullPath);
+ return true;
+ }
+ else
+ {
+ // The path does not exist. Assume the stream content is
+ // associated with an old package that no longer exists, and
+ // delete it to keep the package registry clean.
+ return false;
+ }
+ }
+ else
+ {
+ // The first line in the stream is not the full path to a file or
+ // directory. Assume the stream content was created by a future
+ // version of CMake that uses a different format, and leave it.
+ return true;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddPrefixesBuilds()
+{
+ if(!this->NoBuilds && !this->NoDefaultPath)
+ {
+ // It is likely that CMake will have recently built the project.
+ for(int i=0; i <= 10; ++i)
+ {
+ cmOStringStream r;
+ r <<
+ "[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\"
+ "Settings\\StartPath;WhereBuild" << i << "]";
+ std::string f = r.str();
+ cmSystemTools::ExpandRegistryValues(f);
+ cmSystemTools::ConvertToUnixSlashes(f);
+ if(cmSystemTools::FileIsFullPath(f.c_str()) &&
+ cmSystemTools::FileIsDirectory(f.c_str()))
+ {
+ this->AddPathInternal(f, FullPath);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddPrefixesCMakeSystemVariable()
+{
+ if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
+ {
+ this->AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
+ this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
+ this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddPrefixesUserGuess()
+{
+ // Add guesses specified by the caller.
+ this->AddPathsInternal(this->UserPaths, CMakePath);
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::AddPrefixesUserHints()
+{
+ // Add hints specified by the caller.
+ this->AddPathsInternal(this->UserHints, CMakePath);
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::SearchDirectory(std::string const& dir)
+{
+ assert(!dir.empty() && dir[dir.size()-1] == '/');
+
+ // Check each path suffix on this directory.
+ for(std::vector<std::string>::const_iterator
+ si = this->SearchPathSuffixes.begin();
+ si != this->SearchPathSuffixes.end(); ++si)
+ {
+ std::string d = dir;
+ if(!si->empty())
+ {
+ d += *si;
+ d += "/";
+ }
+ if(this->CheckDirectory(d))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
+{
+ assert(!dir.empty() && dir[dir.size()-1] == '/');
+
+ // Look for the file in this directory.
+ std::string d = dir.substr(0, dir.size()-1);
+ if(this->FindConfigFile(d, this->FileFound))
+ {
+ // Remove duplicate slashes.
+ cmSystemTools::ConvertToUnixSlashes(this->FileFound);
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
+ std::string& file)
+{
+ if (this->IgnoredPaths.count(dir))
+ {
+ return false;
+ }
+
+ for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
+ ci != this->Configs.end(); ++ci)
+ {
+ file = dir;
+ file += "/";
+ file += *ci;
+ if(this->DebugMode)
+ {
+ fprintf(stderr, "Checking file [%s]\n", file.c_str());
+ }
+ if(cmSystemTools::FileExists(file.c_str(), true) &&
+ this->CheckVersion(file))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
+{
+ bool result = false; // by default, assume the version is not ok.
+ bool haveResult = false;
+ std::string version = "unknown";
+
+ // Get the filename without the .cmake extension.
+ std::string::size_type pos = config_file.rfind('.');
+ std::string version_file_base = config_file.substr(0, pos);
+
+ // Look for foo-config-version.cmake
+ std::string version_file = version_file_base;
+ version_file += "-version.cmake";
+ if ((haveResult == false)
+ && (cmSystemTools::FileExists(version_file.c_str(), true)))
+ {
+ result = this->CheckVersionFile(version_file, version);
+ haveResult = true;
+ }
+
+ // Look for fooConfigVersion.cmake
+ version_file = version_file_base;
+ version_file += "Version.cmake";
+ if ((haveResult == false)
+ && (cmSystemTools::FileExists(version_file.c_str(), true)))
+ {
+ result = this->CheckVersionFile(version_file, version);
+ haveResult = true;
+ }
+
+
+ // If no version was requested a versionless package is acceptable.
+ if ((haveResult == false) && (this->Version.empty()))
+ {
+ result = true;
+ haveResult = true;
+ }
+
+ ConfigFileInfo configFileInfo;
+ configFileInfo.filename = config_file;
+ configFileInfo.version = version;
+ this->ConsideredConfigs.push_back(configFileInfo);
+
+ return result;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
+ std::string& result_version)
+{
+ // The version file will be loaded in an isolated scope.
+ cmMakefile::ScopePushPop varScope(this->Makefile);
+ cmMakefile::PolicyPushPop polScope(this->Makefile);
+ static_cast<void>(varScope);
+ static_cast<void>(polScope);
+
+ // Clear the output variables.
+ this->Makefile->RemoveDefinition("PACKAGE_VERSION");
+ this->Makefile->RemoveDefinition("PACKAGE_VERSION_UNSUITABLE");
+ this->Makefile->RemoveDefinition("PACKAGE_VERSION_COMPATIBLE");
+ this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT");
+
+ // Set the input variables.
+ this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name.c_str());
+ this->Makefile->AddDefinition("PACKAGE_FIND_VERSION",
+ this->Version.c_str());
+ char buf[64];
+ sprintf(buf, "%u", this->VersionMajor);
+ this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MAJOR", buf);
+ sprintf(buf, "%u", this->VersionMinor);
+ this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MINOR", buf);
+ sprintf(buf, "%u", this->VersionPatch);
+ this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_PATCH", buf);
+ sprintf(buf, "%u", this->VersionTweak);
+ this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_TWEAK", buf);
+ sprintf(buf, "%u", this->VersionCount);
+ this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_COUNT", buf);
+
+ // Load the version check file. Pass NoPolicyScope because we do
+ // our own policy push/pop independent of CMP0011.
+ bool suitable = false;
+ if(this->ReadListFile(version_file.c_str(), NoPolicyScope))
+ {
+ // Check the output variables.
+ bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
+ bool unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
+ if(!okay && !this->VersionExact)
+ {
+ okay = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
+ }
+
+ // The package is suitable if the version is okay and not
+ // explicitly unsuitable.
+ suitable = !unsuitable && (okay || this->Version.empty());
+ if(suitable)
+ {
+ // Get the version found.
+ this->VersionFound =
+ this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
+
+ // Try to parse the version number and store the results that were
+ // successfully parsed.
+ unsigned int parsed_major;
+ unsigned int parsed_minor;
+ unsigned int parsed_patch;
+ unsigned int parsed_tweak;
+ this->VersionFoundCount =
+ sscanf(this->VersionFound.c_str(), "%u.%u.%u.%u",
+ &parsed_major, &parsed_minor,
+ &parsed_patch, &parsed_tweak);
+ switch(this->VersionFoundCount)
+ {
+ case 4: this->VersionFoundTweak = parsed_tweak; // no break!
+ case 3: this->VersionFoundPatch = parsed_patch; // no break!
+ case 2: this->VersionFoundMinor = parsed_minor; // no break!
+ case 1: this->VersionFoundMajor = parsed_major; // no break!
+ default: break;
+ }
+ }
+ }
+
+ result_version = this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
+ if (result_version.empty())
+ {
+ result_version = "unknown";
+ }
+
+ // Succeed if the version is suitable.
+ return suitable;
+}
+
+//----------------------------------------------------------------------------
+void cmFindPackageCommand::StoreVersionFound()
+{
+ // Store the whole version string.
+ std::string ver = this->Name;
+ ver += "_VERSION";
+ if(this->VersionFound.empty())
+ {
+ this->Makefile->RemoveDefinition(ver);
+ }
+ else
+ {
+ this->Makefile->AddDefinition(ver, this->VersionFound.c_str());
+ }
+
+ // Store the version components.
+ char buf[64];
+ sprintf(buf, "%u", this->VersionFoundMajor);
+ this->Makefile->AddDefinition(ver+"_MAJOR", buf);
+ sprintf(buf, "%u", this->VersionFoundMinor);
+ this->Makefile->AddDefinition(ver+"_MINOR", buf);
+ sprintf(buf, "%u", this->VersionFoundPatch);
+ this->Makefile->AddDefinition(ver+"_PATCH", buf);
+ sprintf(buf, "%u", this->VersionFoundTweak);
+ this->Makefile->AddDefinition(ver+"_TWEAK", buf);
+ sprintf(buf, "%u", this->VersionFoundCount);
+ this->Makefile->AddDefinition(ver+"_COUNT", buf);
+}
+
+//----------------------------------------------------------------------------
+#include <cmsys/Glob.hxx>
+#include <cmsys/String.h>
+#include <cmsys/auto_ptr.hxx>
+
+class cmFileList;
+class cmFileListGeneratorBase
+{
+public:
+ virtual ~cmFileListGeneratorBase() {}
+protected:
+ bool Consider(std::string const& fullPath, cmFileList& listing);
+private:
+ bool Search(cmFileList&);
+ virtual bool Search(std::string const& parent, cmFileList&) = 0;
+ virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const = 0;
+ friend class cmFileList;
+ cmFileListGeneratorBase* SetNext(cmFileListGeneratorBase const& next);
+ cmsys::auto_ptr<cmFileListGeneratorBase> Next;
+};
+
+class cmFileList
+{
+public:
+ cmFileList(): First(), Last(0) {}
+ virtual ~cmFileList() {}
+ cmFileList& operator/(cmFileListGeneratorBase const& rhs)
+ {
+ if(this->Last)
+ {
+ this->Last = this->Last->SetNext(rhs);
+ }
+ else
+ {
+ this->First = rhs.Clone();
+ this->Last = this->First.get();
+ }
+ return *this;
+ }
+ bool Search()
+ {
+ if(this->First.get())
+ {
+ return this->First->Search(*this);
+ }
+ return false;
+ }
+private:
+ virtual bool Visit(std::string const& fullPath) = 0;
+ friend class cmFileListGeneratorBase;
+ cmsys::auto_ptr<cmFileListGeneratorBase> First;
+ cmFileListGeneratorBase* Last;
+};
+
+class cmFindPackageFileList: public cmFileList
+{
+public:
+ cmFindPackageFileList(cmFindPackageCommand* fpc,
+ bool use_suffixes = true):
+ cmFileList(), FPC(fpc), UseSuffixes(use_suffixes) {}
+private:
+ bool Visit(std::string const& fullPath)
+ {
+ if(this->UseSuffixes)
+ {
+ return this->FPC->SearchDirectory(fullPath);
+ }
+ else
+ {
+ return this->FPC->CheckDirectory(fullPath);
+ }
+ }
+ cmFindPackageCommand* FPC;
+ bool UseSuffixes;
+};
+
+bool cmFileListGeneratorBase::Search(cmFileList& listing)
+{
+ return this->Search("", listing);
+}
+
+cmFileListGeneratorBase*
+cmFileListGeneratorBase::SetNext(cmFileListGeneratorBase const& next)
+{
+ this->Next = next.Clone();
+ return this->Next.get();
+}
+
+bool cmFileListGeneratorBase::Consider(std::string const& fullPath,
+ cmFileList& listing)
+{
+ if(this->Next.get())
+ {
+ return this->Next->Search(fullPath + "/", listing);
+ }
+ else
+ {
+ return listing.Visit(fullPath + "/");
+ }
+}
+
+class cmFileListGeneratorFixed: public cmFileListGeneratorBase
+{
+public:
+ cmFileListGeneratorFixed(std::string const& str):
+ cmFileListGeneratorBase(), String(str) {}
+ cmFileListGeneratorFixed(cmFileListGeneratorFixed const& r):
+ cmFileListGeneratorBase(), String(r.String) {}
+private:
+ std::string String;
+ virtual bool Search(std::string const& parent, cmFileList& lister)
+ {
+ std::string fullPath = parent + this->String;
+ return this->Consider(fullPath, lister);
+ }
+ virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase>
+ g(new cmFileListGeneratorFixed(*this));
+ return g;
+ }
+};
+
+class cmFileListGeneratorEnumerate: public cmFileListGeneratorBase
+{
+public:
+ cmFileListGeneratorEnumerate(std::vector<std::string> const& v):
+ cmFileListGeneratorBase(), Vector(v) {}
+ cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r):
+ cmFileListGeneratorBase(), Vector(r.Vector) {}
+private:
+ std::vector<std::string> const& Vector;
+ virtual bool Search(std::string const& parent, cmFileList& lister)
+ {
+ for(std::vector<std::string>::const_iterator i = this->Vector.begin();
+ i != this->Vector.end(); ++i)
+ {
+ if(this->Consider(parent + *i, lister))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase>
+ g(new cmFileListGeneratorEnumerate(*this));
+ return g;
+ }
+};
+
+class cmFileListGeneratorProject: public cmFileListGeneratorBase
+{
+public:
+ cmFileListGeneratorProject(std::vector<std::string> const& names):
+ cmFileListGeneratorBase(), Names(names) {}
+ cmFileListGeneratorProject(cmFileListGeneratorProject const& r):
+ cmFileListGeneratorBase(), Names(r.Names) {}
+private:
+ std::vector<std::string> const& Names;
+ virtual bool Search(std::string const& parent, cmFileList& lister)
+ {
+ // Construct a list of matches.
+ std::vector<std::string> matches;
+ cmsys::Directory d;
+ d.Load(parent.c_str());
+ for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
+ {
+ const char* fname = d.GetFile(i);
+ if(strcmp(fname, ".") == 0 ||
+ strcmp(fname, "..") == 0)
+ {
+ continue;
+ }
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni)
+ {
+ if(cmsysString_strncasecmp(fname, ni->c_str(),
+ ni->length()) == 0)
+ {
+ matches.push_back(fname);
+ }
+ }
+ }
+
+ for(std::vector<std::string>::const_iterator i = matches.begin();
+ i != matches.end(); ++i)
+ {
+ if(this->Consider(parent + *i, lister))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase>
+ g(new cmFileListGeneratorProject(*this));
+ return g;
+ }
+};
+
+class cmFileListGeneratorMacProject: public cmFileListGeneratorBase
+{
+public:
+ cmFileListGeneratorMacProject(std::vector<std::string> const& names,
+ const char* ext):
+ cmFileListGeneratorBase(), Names(names), Extension(ext) {}
+ cmFileListGeneratorMacProject(cmFileListGeneratorMacProject const& r):
+ cmFileListGeneratorBase(), Names(r.Names), Extension(r.Extension) {}
+private:
+ std::vector<std::string> const& Names;
+ std::string Extension;
+ virtual bool Search(std::string const& parent, cmFileList& lister)
+ {
+ // Construct a list of matches.
+ std::vector<std::string> matches;
+ cmsys::Directory d;
+ d.Load(parent.c_str());
+ for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
+ {
+ const char* fname = d.GetFile(i);
+ if(strcmp(fname, ".") == 0 ||
+ strcmp(fname, "..") == 0)
+ {
+ continue;
+ }
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni)
+ {
+ std::string name = *ni;
+ name += this->Extension;
+ if(cmsysString_strcasecmp(fname, name.c_str()) == 0)
+ {
+ matches.push_back(fname);
+ }
+ }
+ }
+
+ for(std::vector<std::string>::const_iterator i = matches.begin();
+ i != matches.end(); ++i)
+ {
+ if(this->Consider(parent + *i, lister))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase>
+ g(new cmFileListGeneratorMacProject(*this));
+ return g;
+ }
+};
+
+class cmFileListGeneratorCaseInsensitive: public cmFileListGeneratorBase
+{
+public:
+ cmFileListGeneratorCaseInsensitive(std::string const& str):
+ cmFileListGeneratorBase(), String(str) {}
+ cmFileListGeneratorCaseInsensitive(
+ cmFileListGeneratorCaseInsensitive const& r):
+ cmFileListGeneratorBase(), String(r.String) {}
+private:
+ std::string String;
+ virtual bool Search(std::string const& parent, cmFileList& lister)
+ {
+ // Look for matching files.
+ std::vector<std::string> matches;
+ cmsys::Directory d;
+ d.Load(parent.c_str());
+ for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
+ {
+ const char* fname = d.GetFile(i);
+ if(strcmp(fname, ".") == 0 ||
+ strcmp(fname, "..") == 0)
+ {
+ continue;
+ }
+ if(cmsysString_strcasecmp(fname, this->String.c_str()) == 0)
+ {
+ if(this->Consider(parent + fname, lister))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase>
+ g(new cmFileListGeneratorCaseInsensitive(*this));
+ return g;
+ }
+};
+
+class cmFileListGeneratorGlob: public cmFileListGeneratorBase
+{
+public:
+ cmFileListGeneratorGlob(std::string const& str):
+ cmFileListGeneratorBase(), Pattern(str) {}
+ cmFileListGeneratorGlob(cmFileListGeneratorGlob const& r):
+ cmFileListGeneratorBase(), Pattern(r.Pattern) {}
+private:
+ std::string Pattern;
+ virtual bool Search(std::string const& parent, cmFileList& lister)
+ {
+ // Glob the set of matching files.
+ std::string expr = parent;
+ expr += this->Pattern;
+ cmsys::Glob g;
+ if(!g.FindFiles(expr))
+ {
+ return false;
+ }
+ std::vector<std::string> const& files = g.GetFiles();
+
+ // Look for directories among the matches.
+ for(std::vector<std::string>::const_iterator fi = files.begin();
+ fi != files.end(); ++fi)
+ {
+ if(cmSystemTools::FileIsDirectory(fi->c_str()))
+ {
+ if(this->Consider(*fi, lister))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase>
+ g(new cmFileListGeneratorGlob(*this));
+ return g;
+ }
+};
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
+{
+ assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
+ if(this->DebugMode)
+ {
+ fprintf(stderr, "Checking prefix [%s]\n", prefix_in.c_str());
+ }
+
+ // Skip this if the prefix does not exist.
+ if(!cmSystemTools::FileIsDirectory(prefix_in.c_str()))
+ {
+ return false;
+ }
+
+ // PREFIX/ (useful on windows or in build trees)
+ if(this->SearchDirectory(prefix_in))
+ {
+ return true;
+ }
+
+ // Strip the trailing slash because the path generator is about to
+ // add one.
+ std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
+
+ // PREFIX/(cmake|CMake)/ (useful on windows or in build trees)
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorCaseInsensitive("cmake");
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ // PREFIX/(Foo|foo|FOO).*/
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorProject(this->Names);
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ // PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorProject(this->Names)
+ / cmFileListGeneratorCaseInsensitive("cmake");
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ // Construct list of common install locations (lib and share).
+ std::vector<std::string> common;
+ if(!this->LibraryArchitecture.empty())
+ {
+ common.push_back("lib/"+this->LibraryArchitecture);
+ }
+ if(this->UseLib64Paths)
+ {
+ common.push_back("lib64");
+ }
+ common.push_back("lib");
+ common.push_back("share");
+
+ // PREFIX/(lib/ARCH|lib|share)/cmake/(Foo|foo|FOO).*/
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorEnumerate(common)
+ / cmFileListGeneratorFixed("cmake")
+ / cmFileListGeneratorProject(this->Names);
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ // PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorEnumerate(common)
+ / cmFileListGeneratorProject(this->Names);
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ // PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/(cmake|CMake)/
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorEnumerate(common)
+ / cmFileListGeneratorProject(this->Names)
+ / cmFileListGeneratorCaseInsensitive("cmake");
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in)
+{
+ assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
+ if(this->DebugMode)
+ {
+ fprintf(stderr, "Checking framework prefix [%s]\n", prefix_in.c_str());
+ }
+
+ // Strip the trailing slash because the path generator is about to
+ // add one.
+ std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
+
+ // <prefix>/Foo.framework/Resources/
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorMacProject(this->Names, ".framework")
+ / cmFileListGeneratorFixed("Resources");
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+ // <prefix>/Foo.framework/Resources/CMake/
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorMacProject(this->Names, ".framework")
+ / cmFileListGeneratorFixed("Resources")
+ / cmFileListGeneratorCaseInsensitive("cmake");
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ // <prefix>/Foo.framework/Versions/*/Resources/
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorMacProject(this->Names, ".framework")
+ / cmFileListGeneratorFixed("Versions")
+ / cmFileListGeneratorGlob("*/Resources");
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ // <prefix>/Foo.framework/Versions/*/Resources/CMake/
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorMacProject(this->Names, ".framework")
+ / cmFileListGeneratorFixed("Versions")
+ / cmFileListGeneratorGlob("*/Resources")
+ / cmFileListGeneratorCaseInsensitive("cmake");
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in)
+{
+ assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
+ if(this->DebugMode)
+ {
+ fprintf(stderr, "Checking bundle prefix [%s]\n", prefix_in.c_str());
+ }
+
+ // Strip the trailing slash because the path generator is about to
+ // add one.
+ std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
+
+ // <prefix>/Foo.app/Contents/Resources
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorMacProject(this->Names, ".app")
+ / cmFileListGeneratorFixed("Contents/Resources");
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ // <prefix>/Foo.app/Contents/Resources/CMake
+ {
+ cmFindPackageFileList lister(this);
+ lister
+ / cmFileListGeneratorFixed(prefix)
+ / cmFileListGeneratorMacProject(this->Names, ".app")
+ / cmFileListGeneratorFixed("Contents/Resources")
+ / cmFileListGeneratorCaseInsensitive("cmake");
+ if(lister.Search())
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// TODO: Debug cmsys::Glob double slash problem.
diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h
new file mode 100644
index 0000000000..2249459486
--- /dev/null
+++ b/Source/cmFindPackageCommand.h
@@ -0,0 +1,137 @@
+/*============================================================================
+ 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 cmFindPackageCommand_h
+#define cmFindPackageCommand_h
+
+#include "cmFindCommon.h"
+
+class cmFindPackageFileList;
+
+/** \class cmFindPackageCommand
+ * \brief Load settings from an external project.
+ *
+ * cmFindPackageCommand
+ */
+class cmFindPackageCommand : public cmFindCommon
+{
+public:
+ cmFindPackageCommand();
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmFindPackageCommand;
+ }
+
+ /**
+ * 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 "find_package";}
+
+ cmTypeMacro(cmFindPackageCommand, cmFindCommon);
+private:
+ void AppendSuccessInformation();
+ void AppendToFoundProperty(bool found);
+ void SetModuleVariables(const std::string& components);
+ bool FindModule(bool& found);
+ void AddFindDefinition(const std::string& var, const char* val);
+ void RestoreFindDefinitions();
+ bool HandlePackageMode();
+ bool FindConfig();
+ bool FindPrefixedConfig();
+ bool FindFrameworkConfig();
+ bool FindAppBundleConfig();
+ enum PolicyScopeRule { NoPolicyScope, DoPolicyScope };
+ bool ReadListFile(const char* f, PolicyScopeRule psr);
+ void StoreVersionFound();
+
+ void ComputePrefixes();
+ void AddPrefixesCMakeEnvironment();
+ void AddPrefixesCMakeVariable();
+ void AddPrefixesSystemEnvironment();
+ void AddPrefixesUserRegistry();
+ void AddPrefixesSystemRegistry();
+ void AddPrefixesBuilds();
+ void AddPrefixesCMakeSystemVariable();
+ void AddPrefixesUserGuess();
+ void AddPrefixesUserHints();
+ void LoadPackageRegistryDir(std::string const& dir);
+ void LoadPackageRegistryWinUser();
+ void LoadPackageRegistryWinSystem();
+ void LoadPackageRegistryWin(bool user, unsigned int view);
+ bool CheckPackageRegistryEntry(std::istream& is);
+ bool SearchDirectory(std::string const& dir);
+ bool CheckDirectory(std::string const& dir);
+ bool FindConfigFile(std::string const& dir, std::string& file);
+ bool CheckVersion(std::string const& config_file);
+ bool CheckVersionFile(std::string const& version_file,
+ std::string& result_version);
+ bool SearchPrefix(std::string const& prefix);
+ bool SearchFrameworkPrefix(std::string const& prefix_in);
+ bool SearchAppBundlePrefix(std::string const& prefix_in);
+
+ friend class cmFindPackageFileList;
+
+ struct OriginalDef { bool exists; std::string value; };
+ std::map<std::string, OriginalDef> OriginalDefs;
+
+ std::string Name;
+ std::string Variable;
+ std::string Version;
+ unsigned int VersionMajor;
+ unsigned int VersionMinor;
+ unsigned int VersionPatch;
+ unsigned int VersionTweak;
+ unsigned int VersionCount;
+ bool VersionExact;
+ std::string FileFound;
+ std::string VersionFound;
+ unsigned int VersionFoundMajor;
+ unsigned int VersionFoundMinor;
+ unsigned int VersionFoundPatch;
+ unsigned int VersionFoundTweak;
+ unsigned int VersionFoundCount;
+ cmIML_INT_uint64_t RequiredCMakeVersion;
+ bool Quiet;
+ bool Required;
+ bool UseConfigFiles;
+ bool UseFindModules;
+ bool NoUserRegistry;
+ bool NoSystemRegistry;
+ bool NoBuilds;
+ bool DebugMode;
+ bool UseLib64Paths;
+ bool PolicyScope;
+ std::string LibraryArchitecture;
+ std::vector<std::string> Names;
+ std::vector<std::string> Configs;
+ std::set<std::string> IgnoredPaths;
+
+ struct ConfigFileInfo { std::string filename; std::string version; };
+ std::vector<ConfigFileInfo> ConsideredConfigs;
+};
+
+#endif
diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx
new file mode 100644
index 0000000000..5531cdff4b
--- /dev/null
+++ b/Source/cmFindPathCommand.cxx
@@ -0,0 +1,197 @@
+/*============================================================================
+ 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 "cmFindPathCommand.h"
+#include "cmCacheManager.h"
+
+#include <cmsys/Glob.hxx>
+
+cmFindPathCommand::cmFindPathCommand()
+{
+ this->EnvironmentPath = "INCLUDE";
+ this->IncludeFileInPath = false;
+}
+
+// cmFindPathCommand
+bool cmFindPathCommand
+::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
+{
+ this->VariableDocumentation = "Path to a file.";
+ this->CMakePathName = "INCLUDE";
+ if(!this->ParseArguments(argsIn))
+ {
+ return false;
+ }
+ if(this->AlreadyInCache)
+ {
+ // If the user specifies the entry on the command line without a
+ // type we should add the type and docstring but keep the original
+ // value.
+ if(this->AlreadyInCacheWithoutMetaInfo)
+ {
+ this->Makefile->AddCacheDefinition(
+ this->VariableName, "",
+ this->VariableDocumentation.c_str(),
+ (this->IncludeFileInPath ?
+ cmCacheManager::FILEPATH :cmCacheManager::PATH)
+ );
+ }
+ return true;
+ }
+
+ std::string result = this->FindHeader();
+ if(result.size() != 0)
+ {
+ this->Makefile->AddCacheDefinition
+ (this->VariableName, result.c_str(),
+ this->VariableDocumentation.c_str(),
+ (this->IncludeFileInPath) ?
+ cmCacheManager::FILEPATH :cmCacheManager::PATH);
+ return true;
+ }
+ this->Makefile->AddCacheDefinition
+ (this->VariableName,
+ (this->VariableName + "-NOTFOUND").c_str(),
+ this->VariableDocumentation.c_str(),
+ (this->IncludeFileInPath) ?
+ cmCacheManager::FILEPATH :cmCacheManager::PATH);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindPathCommand::FindHeader()
+{
+ std::string header;
+ if(this->SearchFrameworkFirst || this->SearchFrameworkOnly)
+ {
+ header = this->FindFrameworkHeader();
+ }
+ if(header.empty() && !this->SearchFrameworkOnly)
+ {
+ header = this->FindNormalHeader();
+ }
+ if(header.empty() && this->SearchFrameworkLast)
+ {
+ header = this->FindFrameworkHeader();
+ }
+ return header;
+}
+
+std::string
+cmFindPathCommand::FindHeaderInFramework(std::string const& file,
+ std::string const& dir)
+{
+ std::string fileName = file;
+ std::string frameWorkName;
+ std::string::size_type pos = fileName.find("/");
+ // if there is a / in the name try to find the header as a framework
+ // For example bar/foo.h would look for:
+ // bar.framework/Headers/foo.h
+ if(pos != fileName.npos)
+ {
+ // remove the name from the slash;
+ fileName = fileName.substr(pos+1);
+ frameWorkName = file;
+ frameWorkName =
+ frameWorkName.substr(0, frameWorkName.size()-fileName.size()-1);
+ // if the framework has a path in it then just use the filename
+ if(frameWorkName.find("/") != frameWorkName.npos)
+ {
+ fileName = file;
+ frameWorkName = "";
+ }
+ if(frameWorkName.size())
+ {
+ std::string fpath = dir;
+ fpath += frameWorkName;
+ fpath += ".framework";
+ std::string intPath = fpath;
+ intPath += "/Headers/";
+ intPath += fileName;
+ if(cmSystemTools::FileExists(intPath.c_str()))
+ {
+ if(this->IncludeFileInPath)
+ {
+ return intPath;
+ }
+ return fpath;
+ }
+ }
+ }
+ // if it is not found yet or not a framework header, then do a glob search
+ // for all frameworks in the directory: dir/*.framework/Headers/<file>
+ std::string glob = dir;
+ glob += "*.framework/Headers/";
+ glob += file;
+ cmsys::Glob globIt;
+ globIt.FindFiles(glob);
+ std::vector<std::string> files = globIt.GetFiles();
+ if(files.size())
+ {
+ std::string fheader = cmSystemTools::CollapseFullPath(files[0].c_str());
+ if(this->IncludeFileInPath)
+ {
+ return fheader;
+ }
+ fheader = cmSystemTools::GetFilenamePath(fheader);
+ return fheader;
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindPathCommand::FindNormalHeader()
+{
+ std::string tryPath;
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end() ; ++ni)
+ {
+ for(std::vector<std::string>::const_iterator
+ p = this->SearchPaths.begin();
+ p != this->SearchPaths.end(); ++p)
+ {
+ tryPath = *p;
+ tryPath += *ni;
+ if(cmSystemTools::FileExists(tryPath.c_str()))
+ {
+ if(this->IncludeFileInPath)
+ {
+ return tryPath;
+ }
+ else
+ {
+ return *p;
+ }
+ }
+ }
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindPathCommand::FindFrameworkHeader()
+{
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end() ; ++ni)
+ {
+ for(std::vector<std::string>::const_iterator
+ p = this->SearchPaths.begin();
+ p != this->SearchPaths.end(); ++p)
+ {
+ std::string fwPath = this->FindHeaderInFramework(*ni, *p);
+ if(!fwPath.empty())
+ {
+ return fwPath;
+ }
+ }
+ }
+ return "";
+}
diff --git a/Source/cmFindPathCommand.h b/Source/cmFindPathCommand.h
new file mode 100644
index 0000000000..a51da7920f
--- /dev/null
+++ b/Source/cmFindPathCommand.h
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 cmFindPathCommand_h
+#define cmFindPathCommand_h
+
+#include "cmFindBase.h"
+
+
+/** \class cmFindPathCommand
+ * \brief Define a command to search for a library.
+ *
+ * cmFindPathCommand is used to define a CMake variable
+ * that specifies a library. The command searches for a given
+ * file in a list of directories.
+ */
+class cmFindPathCommand : public cmFindBase
+{
+public:
+ cmFindPathCommand();
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmFindPathCommand;
+ }
+
+ /**
+ * 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 "find_path";}
+
+ cmTypeMacro(cmFindPathCommand, cmFindBase);
+ bool IncludeFileInPath;
+private:
+ std::string FindHeaderInFramework(std::string const& file,
+ std::string const& dir);
+ std::string FindHeader();
+ std::string FindNormalHeader();
+ std::string FindFrameworkHeader();
+};
+
+
+
+#endif
diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx
new file mode 100644
index 0000000000..f6e37f6941
--- /dev/null
+++ b/Source/cmFindProgramCommand.cxx
@@ -0,0 +1,160 @@
+/*============================================================================
+ 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 "cmFindProgramCommand.h"
+#include "cmCacheManager.h"
+#include <stdlib.h>
+
+#if defined(__APPLE__)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
+// cmFindProgramCommand
+bool cmFindProgramCommand
+::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
+{
+ this->VariableDocumentation = "Path to a program.";
+ this->CMakePathName = "PROGRAM";
+ // call cmFindBase::ParseArguments
+ if(!this->ParseArguments(argsIn))
+ {
+ return false;
+ }
+ if(this->AlreadyInCache)
+ {
+ // If the user specifies the entry on the command line without a
+ // type we should add the type and docstring but keep the original
+ // value.
+ if(this->AlreadyInCacheWithoutMetaInfo)
+ {
+ this->Makefile->AddCacheDefinition(this->VariableName, "",
+ this->VariableDocumentation.c_str(),
+ cmCacheManager::FILEPATH);
+ }
+ return true;
+ }
+
+ std::string result = FindProgram(this->Names);
+ if(result != "")
+ {
+ // Save the value in the cache
+ this->Makefile->AddCacheDefinition(this->VariableName,
+ result.c_str(),
+ this->VariableDocumentation.c_str(),
+ cmCacheManager::FILEPATH);
+
+ return true;
+ }
+ this->Makefile->AddCacheDefinition(this->VariableName,
+ (this->VariableName + "-NOTFOUND").c_str(),
+ this->VariableDocumentation.c_str(),
+ cmCacheManager::FILEPATH);
+ return true;
+}
+
+std::string cmFindProgramCommand::FindProgram(std::vector<std::string> names)
+{
+ std::string program = "";
+
+ if(this->SearchAppBundleFirst || this->SearchAppBundleOnly)
+ {
+ program = FindAppBundle(names);
+ }
+ if(program.empty() && !this->SearchAppBundleOnly)
+ {
+ program = cmSystemTools::FindProgram(names, this->SearchPaths, true);
+ }
+
+ if(program.empty() && this->SearchAppBundleLast)
+ {
+ program = this->FindAppBundle(names);
+ }
+ return program;
+}
+
+std::string cmFindProgramCommand
+::FindAppBundle(std::vector<std::string> names)
+{
+ for(std::vector<std::string>::const_iterator name = names.begin();
+ name != names.end() ; ++name)
+ {
+
+ std::string appName = *name + std::string(".app");
+ std::string appPath = cmSystemTools::FindDirectory(appName.c_str(),
+ this->SearchPaths,
+ true);
+
+ if ( !appPath.empty() )
+ {
+ std::string executable = GetBundleExecutable(appPath);
+ if (!executable.empty())
+ {
+ return cmSystemTools::CollapseFullPath(executable.c_str());
+ }
+ }
+ }
+
+ // Couldn't find app bundle
+ return "";
+}
+
+std::string cmFindProgramCommand::GetBundleExecutable(std::string bundlePath)
+{
+ std::string executable = "";
+ (void)bundlePath;
+#if defined(__APPLE__)
+ // Started with an example on developer.apple.com about finding bundles
+ // and modified from that.
+
+ // Get a CFString of the app bundle path
+ // XXX - Is it safe to assume everything is in UTF8?
+ CFStringRef bundlePathCFS =
+ CFStringCreateWithCString(kCFAllocatorDefault ,
+ bundlePath.c_str(), kCFStringEncodingUTF8 );
+
+ // Make a CFURLRef from the CFString representation of the
+ // bundle’s path.
+ CFURLRef bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
+ bundlePathCFS,
+ kCFURLPOSIXPathStyle,
+ true );
+
+ // Make a bundle instance using the URLRef.
+ CFBundleRef appBundle = CFBundleCreate( kCFAllocatorDefault, bundleURL );
+
+ // returned executableURL is relative to <appbundle>/Contents/MacOS/
+ CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle);
+
+ if (executableURL != NULL)
+ {
+ const int MAX_OSX_PATH_SIZE = 1024;
+ char buffer[MAX_OSX_PATH_SIZE];
+
+ // Convert the CFString to a C string
+ CFStringGetCString( CFURLGetString(executableURL), buffer,
+ MAX_OSX_PATH_SIZE, kCFStringEncodingUTF8 );
+
+ // And finally to a c++ string
+ executable = bundlePath + "/Contents/MacOS/" + std::string(buffer);
+ // Only release CFURLRef if it's not null
+ CFRelease( executableURL );
+ }
+
+ // Any CF objects returned from functions with "create" or
+ // "copy" in their names must be released by us!
+ CFRelease( bundlePathCFS );
+ CFRelease( bundleURL );
+ CFRelease( appBundle );
+#endif
+
+ return executable;
+}
+
diff --git a/Source/cmFindProgramCommand.h b/Source/cmFindProgramCommand.h
new file mode 100644
index 0000000000..70f758ff83
--- /dev/null
+++ b/Source/cmFindProgramCommand.h
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 cmFindProgramCommand_h
+#define cmFindProgramCommand_h
+
+#include "cmFindBase.h"
+
+/** \class cmFindProgramCommand
+ * \brief Define a command to search for an executable program.
+ *
+ * cmFindProgramCommand is used to define a CMake variable
+ * that specifies an executable program. The command searches
+ * in the current path (e.g., PATH environment variable) for
+ * an executable that matches one of the supplied names.
+ */
+class cmFindProgramCommand : public cmFindBase
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmFindProgramCommand;
+ }
+
+ /**
+ * 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 "find_program";}
+
+ cmTypeMacro(cmFindProgramCommand, cmFindBase);
+
+protected:
+ std::string FindProgram(std::vector<std::string> names);
+
+private:
+ std::string FindAppBundle(std::vector<std::string> names);
+ std::string GetBundleExecutable(std::string bundlePath);
+
+};
+
+
+
+#endif
diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx
new file mode 100644
index 0000000000..e3f66c1c3b
--- /dev/null
+++ b/Source/cmForEachCommand.cxx
@@ -0,0 +1,246 @@
+/*============================================================================
+ 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 "cmForEachCommand.h"
+
+#include <cmsys/auto_ptr.hxx>
+
+bool cmForEachFunctionBlocker::
+IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
+ cmExecutionStatus &inStatus)
+{
+ if (!cmSystemTools::Strucmp(lff.Name.c_str(),"foreach"))
+ {
+ // record the number of nested foreach commands
+ this->Depth++;
+ }
+ else if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endforeach"))
+ {
+ // if this is the endofreach for this statement
+ if (!this->Depth)
+ {
+ // Remove the function blocker for this scope or bail.
+ cmsys::auto_ptr<cmFunctionBlocker>
+ fb(mf.RemoveFunctionBlocker(this, lff));
+ if(!fb.get()) { return false; }
+
+ // at end of for each execute recorded commands
+ // store the old value
+ std::string oldDef;
+ if (mf.GetDefinition(this->Args[0]))
+ {
+ oldDef = mf.GetDefinition(this->Args[0]);
+ }
+ std::vector<std::string>::const_iterator j = this->Args.begin();
+ ++j;
+
+ std::string tmps;
+ cmListFileArgument arg;
+ for( ; j != this->Args.end(); ++j)
+ {
+ // set the variable to the loop value
+ mf.AddDefinition(this->Args[0],j->c_str());
+ // Invoke all the functions that were collected in the block.
+ cmExecutionStatus status;
+ for(unsigned int c = 0; c < this->Functions.size(); ++c)
+ {
+ status.Clear();
+ mf.ExecuteCommand(this->Functions[c],status);
+ if (status.GetReturnInvoked())
+ {
+ inStatus.SetReturnInvoked(true);
+ // restore the variable to its prior value
+ mf.AddDefinition(this->Args[0],oldDef.c_str());
+ return true;
+ }
+ if (status.GetBreakInvoked())
+ {
+ // restore the variable to its prior value
+ mf.AddDefinition(this->Args[0],oldDef.c_str());
+ return true;
+ }
+ if(cmSystemTools::GetFatalErrorOccured() )
+ {
+ return true;
+ }
+ }
+ }
+ // restore the variable to its prior value
+ mf.AddDefinition(this->Args[0],oldDef.c_str());
+ return true;
+ }
+ else
+ {
+ // close out a nested foreach
+ this->Depth--;
+ }
+ }
+
+ // record the command
+ this->Functions.push_back(lff);
+
+ // always return true
+ return true;
+}
+
+bool cmForEachFunctionBlocker::
+ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf)
+{
+ if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endforeach"))
+ {
+ std::vector<std::string> expandedArguments;
+ mf.ExpandArguments(lff.Arguments, expandedArguments);
+ // if the endforeach has arguments then make sure
+ // they match the begin foreach arguments
+ if ((expandedArguments.empty() ||
+ (expandedArguments[0] == this->Args[0])))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool cmForEachCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ if(args.size() > 1 && args[1] == "IN")
+ {
+ return this->HandleInMode(args);
+ }
+
+ // create a function blocker
+ cmForEachFunctionBlocker *f = new cmForEachFunctionBlocker();
+ if ( args.size() > 1 )
+ {
+ if ( args[1] == "RANGE" )
+ {
+ int start = 0;
+ int stop = 0;
+ int step = 0;
+ if ( args.size() == 3 )
+ {
+ stop = atoi(args[2].c_str());
+ }
+ if ( args.size() == 4 )
+ {
+ start = atoi(args[2].c_str());
+ stop = atoi(args[3].c_str());
+ }
+ if ( args.size() == 5 )
+ {
+ start = atoi(args[2].c_str());
+ stop = atoi(args[3].c_str());
+ step = atoi(args[4].c_str());
+ }
+ if ( step == 0 )
+ {
+ if ( start > stop )
+ {
+ step = -1;
+ }
+ else
+ {
+ step = 1;
+ }
+ }
+ if (
+ (start > stop && step > 0) ||
+ (start < stop && step < 0) ||
+ step == 0
+ )
+ {
+ cmOStringStream str;
+ str << "called with incorrect range specification: start ";
+ str << start << ", stop " << stop << ", step " << step;
+ this->SetError(str.str());
+ return false;
+ }
+ std::vector<std::string> range;
+ char buffer[100];
+ range.push_back(args[0]);
+ int cc;
+ for ( cc = start; ; cc += step )
+ {
+ if ( (step > 0 && cc > stop) || (step < 0 && cc < stop) )
+ {
+ break;
+ }
+ sprintf(buffer, "%d", cc);
+ range.push_back(buffer);
+ if ( cc == stop )
+ {
+ break;
+ }
+ }
+ f->Args = range;
+ }
+ else
+ {
+ f->Args = args;
+ }
+ }
+ else
+ {
+ f->Args = args;
+ }
+ this->Makefile->AddFunctionBlocker(f);
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args)
+{
+ cmsys::auto_ptr<cmForEachFunctionBlocker> f(new cmForEachFunctionBlocker());
+ f->Args.push_back(args[0]);
+
+ enum Doing { DoingNone, DoingLists, DoingItems };
+ Doing doing = DoingNone;
+ for(unsigned int i=2; i < args.size(); ++i)
+ {
+ if(doing == DoingItems)
+ {
+ f->Args.push_back(args[i]);
+ }
+ else if(args[i] == "LISTS")
+ {
+ doing = DoingLists;
+ }
+ else if(args[i] == "ITEMS")
+ {
+ doing = DoingItems;
+ }
+ else if(doing == DoingLists)
+ {
+ const char* value = this->Makefile->GetDefinition(args[i]);
+ if(value && *value)
+ {
+ cmSystemTools::ExpandListArgument(value, f->Args, true);
+ }
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "Unknown argument:\n" << " " << args[i] << "\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return true;
+ }
+ }
+
+ this->Makefile->AddFunctionBlocker(f.release()); // TODO: pass auto_ptr
+ return true;
+}
diff --git a/Source/cmForEachCommand.h b/Source/cmForEachCommand.h
new file mode 100644
index 0000000000..9b7c85a4df
--- /dev/null
+++ b/Source/cmForEachCommand.h
@@ -0,0 +1,70 @@
+/*============================================================================
+ 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 cmForEachCommand_h
+#define cmForEachCommand_h
+
+#include "cmCommand.h"
+#include "cmFunctionBlocker.h"
+#include "cmListFileCache.h"
+
+class cmForEachFunctionBlocker : public cmFunctionBlocker
+{
+public:
+ cmForEachFunctionBlocker() {this->Depth = 0;}
+ virtual ~cmForEachFunctionBlocker() {}
+ virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
+ cmMakefile &mf,
+ cmExecutionStatus &);
+ virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf);
+
+ std::vector<std::string> Args;
+ std::vector<cmListFileFunction> Functions;
+private:
+ int Depth;
+};
+
+/// Starts foreach() ... endforeach() block
+class cmForEachCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmForEachCommand;
+ }
+
+ /**
+ * 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 "foreach";}
+
+ cmTypeMacro(cmForEachCommand, cmCommand);
+private:
+ bool HandleInMode(std::vector<std::string> const& args);
+};
+
+
+#endif
diff --git a/Source/cmFunctionBlocker.h b/Source/cmFunctionBlocker.h
new file mode 100644
index 0000000000..68bf76286a
--- /dev/null
+++ b/Source/cmFunctionBlocker.h
@@ -0,0 +1,48 @@
+/*============================================================================
+ 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 cmFunctionBlocker_h
+#define cmFunctionBlocker_h
+
+#include "cmStandardIncludes.h"
+#include "cmExecutionStatus.h"
+#include "cmListFileCache.h"
+class cmMakefile;
+
+class cmFunctionBlocker
+{
+public:
+ /**
+ * should a function be blocked
+ */
+ virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
+ cmMakefile&mf,
+ cmExecutionStatus &status) = 0;
+
+ /**
+ * should this function blocker be removed, useful when one function adds a
+ * blocker and another must remove it
+ */
+ virtual bool ShouldRemove(const cmListFileFunction&,
+ cmMakefile&) {return false;}
+
+ virtual ~cmFunctionBlocker() {}
+
+ /** Set/Get the context in which this blocker is created. */
+ void SetStartingContext(cmListFileContext const& lfc)
+ { this->StartingContext = lfc; }
+ cmListFileContext const& GetStartingContext()
+ { return this->StartingContext; }
+private:
+ cmListFileContext StartingContext;
+};
+
+#endif
diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx
new file mode 100644
index 0000000000..3580374aae
--- /dev/null
+++ b/Source/cmFunctionCommand.cxx
@@ -0,0 +1,282 @@
+/*============================================================================
+ 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 "cmFunctionCommand.h"
+
+#include "cmake.h"
+
+// define the class for function commands
+class cmFunctionHelperCommand : public cmCommand
+{
+public:
+ cmFunctionHelperCommand() {}
+
+ ///! clean up any memory allocated by the function
+ ~cmFunctionHelperCommand() {}
+
+ /**
+ * This is used to avoid including this command
+ * in documentation. This is mainly used by
+ * cmMacroHelperCommand and cmFunctionHelperCommand
+ * which cannot provide appropriate documentation.
+ */
+ virtual bool ShouldAppearInDocumentation() const
+ {
+ return false;
+ }
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmFunctionHelperCommand *newC = new cmFunctionHelperCommand;
+ // we must copy when we clone
+ newC->Args = this->Args;
+ newC->Functions = this->Functions;
+ newC->Policies = this->Policies;
+ return newC;
+ }
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus &);
+
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &) { return false; }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return this->Args[0]; }
+
+ cmTypeMacro(cmFunctionHelperCommand, cmCommand);
+
+ std::vector<std::string> Args;
+ std::vector<cmListFileFunction> Functions;
+ cmPolicies::PolicyMap Policies;
+};
+
+
+bool cmFunctionHelperCommand::InvokeInitialPass
+(const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus & inStatus)
+{
+ // Expand the argument list to the function.
+ std::vector<std::string> expandedArgs;
+ this->Makefile->ExpandArguments(args, expandedArgs);
+
+ // make sure the number of arguments passed is at least the number
+ // required by the signature
+ if (expandedArgs.size() < this->Args.size() - 1)
+ {
+ std::string errorMsg =
+ "Function invoked with incorrect arguments for function named: ";
+ errorMsg += this->Args[0];
+ this->SetError(errorMsg);
+ return false;
+ }
+
+ // we push a scope on the makefile
+ cmMakefile::LexicalPushPop lexScope(this->Makefile);
+ cmMakefile::ScopePushPop varScope(this->Makefile);
+ static_cast<void>(varScope);
+
+ // Push a weak policy scope which restores the policies recorded at
+ // function creation.
+ cmMakefile::PolicyPushPop polScope(this->Makefile, true, this->Policies);
+
+ // set the value of argc
+ cmOStringStream strStream;
+ strStream << expandedArgs.size();
+ this->Makefile->AddDefinition("ARGC",strStream.str().c_str());
+ this->Makefile->MarkVariableAsUsed("ARGC");
+
+ // set the values for ARGV0 ARGV1 ...
+ for (unsigned int t = 0; t < expandedArgs.size(); ++t)
+ {
+ cmOStringStream tmpStream;
+ tmpStream << "ARGV" << t;
+ this->Makefile->AddDefinition(tmpStream.str(),
+ expandedArgs[t].c_str());
+ this->Makefile->MarkVariableAsUsed(tmpStream.str());
+ }
+
+ // define the formal arguments
+ for (unsigned int j = 1; j < this->Args.size(); ++j)
+ {
+ this->Makefile->AddDefinition(this->Args[j],
+ expandedArgs[j-1].c_str());
+ }
+
+ // define ARGV and ARGN
+ std::vector<std::string>::const_iterator eit;
+ std::string argvDef;
+ std::string argnDef;
+ unsigned int cnt = 0;
+ for ( eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit )
+ {
+ if ( argvDef.size() > 0 )
+ {
+ argvDef += ";";
+ }
+ argvDef += *eit;
+ if ( cnt >= this->Args.size()-1 )
+ {
+ if ( argnDef.size() > 0 )
+ {
+ argnDef += ";";
+ }
+ argnDef += *eit;
+ }
+ cnt ++;
+ }
+ this->Makefile->AddDefinition("ARGV", argvDef.c_str());
+ this->Makefile->MarkVariableAsUsed("ARGV");
+ this->Makefile->AddDefinition("ARGN", argnDef.c_str());
+ this->Makefile->MarkVariableAsUsed("ARGN");
+
+ // Invoke all the functions that were collected in the block.
+ // for each function
+ for(unsigned int c = 0; c < this->Functions.size(); ++c)
+ {
+ cmExecutionStatus status;
+ if (!this->Makefile->ExecuteCommand(this->Functions[c],status) ||
+ status.GetNestedError())
+ {
+ // The error message should have already included the call stack
+ // so we do not need to report an error here.
+ lexScope.Quiet();
+ polScope.Quiet();
+ inStatus.SetNestedError(true);
+ return false;
+ }
+ if (status.GetReturnInvoked())
+ {
+ return true;
+ }
+ }
+
+ // pop scope on the makefile
+ return true;
+}
+
+bool cmFunctionFunctionBlocker::
+IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
+ cmExecutionStatus &)
+{
+ // record commands until we hit the ENDFUNCTION
+ // at the ENDFUNCTION call we shift gears and start looking for invocations
+ if(!cmSystemTools::Strucmp(lff.Name.c_str(),"function"))
+ {
+ this->Depth++;
+ }
+ else if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endfunction"))
+ {
+ // if this is the endfunction for this function then execute
+ if (!this->Depth)
+ {
+ std::string name = this->Args[0];
+ std::vector<std::string>::size_type cc;
+ name += "(";
+ for ( cc = 0; cc < this->Args.size(); cc ++ )
+ {
+ name += " " + this->Args[cc];
+ }
+ name += " )";
+
+ // create a new command and add it to cmake
+ cmFunctionHelperCommand *f = new cmFunctionHelperCommand();
+ f->Args = this->Args;
+ f->Functions = this->Functions;
+ mf.RecordPolicies(f->Policies);
+
+ // Set the FilePath on the arguments to match the function since it is
+ // not stored and the original values may be freed
+ for (unsigned int i = 0; i < f->Functions.size(); ++i)
+ {
+ for (unsigned int j = 0; j < f->Functions[i].Arguments.size(); ++j)
+ {
+ f->Functions[i].Arguments[j].FilePath =
+ f->Functions[i].FilePath.c_str();
+ }
+ }
+
+ std::string newName = "_" + this->Args[0];
+ mf.GetCMakeInstance()->RenameCommand(this->Args[0],
+ newName);
+ mf.AddCommand(f);
+
+ // remove the function blocker now that the function is defined
+ mf.RemoveFunctionBlocker(this, lff);
+ return true;
+ }
+ else
+ {
+ // decrement for each nested function that ends
+ this->Depth--;
+ }
+ }
+
+ // if it wasn't an endfunction and we are not executing then we must be
+ // recording
+ this->Functions.push_back(lff);
+ return true;
+}
+
+
+bool cmFunctionFunctionBlocker::
+ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf)
+{
+ if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endfunction"))
+ {
+ std::vector<std::string> expandedArguments;
+ mf.ExpandArguments(lff.Arguments, expandedArguments);
+ // if the endfunction has arguments then make sure
+ // they match the ones in the opening function command
+ if ((expandedArguments.empty() ||
+ (expandedArguments[0] == this->Args[0])))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool cmFunctionCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // create a function blocker
+ cmFunctionFunctionBlocker *f = new cmFunctionFunctionBlocker();
+ for(std::vector<std::string>::const_iterator j = args.begin();
+ j != args.end(); ++j)
+ {
+ f->Args.push_back(*j);
+ }
+ this->Makefile->AddFunctionBlocker(f);
+ return true;
+}
+
diff --git a/Source/cmFunctionCommand.h b/Source/cmFunctionCommand.h
new file mode 100644
index 0000000000..2df435e711
--- /dev/null
+++ b/Source/cmFunctionCommand.h
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 cmFunctionCommand_h
+#define cmFunctionCommand_h
+
+#include "cmCommand.h"
+#include "cmFunctionBlocker.h"
+
+class cmFunctionFunctionBlocker : public cmFunctionBlocker
+{
+public:
+ cmFunctionFunctionBlocker() {this->Depth=0;}
+ virtual ~cmFunctionFunctionBlocker() {}
+ virtual bool IsFunctionBlocked(const cmListFileFunction&,
+ cmMakefile &mf,
+ cmExecutionStatus &);
+ virtual bool ShouldRemove(const cmListFileFunction&, cmMakefile &mf);
+
+ std::vector<std::string> Args;
+ std::vector<cmListFileFunction> Functions;
+ int Depth;
+};
+
+/// Starts function() ... endfunction() block
+class cmFunctionCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmFunctionCommand;
+ }
+
+ /**
+ * 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 "function";}
+
+ cmTypeMacro(cmFunctionCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx
new file mode 100644
index 0000000000..78ad4b2e5f
--- /dev/null
+++ b/Source/cmGeneratedFileStream.cxx
@@ -0,0 +1,255 @@
+/*============================================================================
+ 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 "cmGeneratedFileStream.h"
+
+#include "cmSystemTools.h"
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include <cm_zlib.h>
+#endif
+
+//----------------------------------------------------------------------------
+cmGeneratedFileStream::cmGeneratedFileStream():
+ cmGeneratedFileStreamBase(), Stream()
+{
+}
+
+//----------------------------------------------------------------------------
+cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet):
+ cmGeneratedFileStreamBase(name),
+ Stream(TempName.c_str())
+{
+ // Check if the file opened.
+ if(!*this && !quiet)
+ {
+ cmSystemTools::Error("Cannot open file for write: ",
+ this->TempName.c_str());
+ cmSystemTools::ReportLastSystemError("");
+ }
+}
+
+//----------------------------------------------------------------------------
+cmGeneratedFileStream::~cmGeneratedFileStream()
+{
+ // This is the first destructor called. Check the status of the
+ // stream and give the information to the private base. Next the
+ // stream will be destroyed which will close the temporary file.
+ // Finally the base destructor will be called to replace the
+ // destination file.
+ this->Okay = (*this)?true:false;
+}
+
+//----------------------------------------------------------------------------
+cmGeneratedFileStream&
+cmGeneratedFileStream::Open(const char* name, bool quiet, bool binaryFlag)
+{
+ // Store the file name and construct the temporary file name.
+ this->cmGeneratedFileStreamBase::Open(name);
+
+ // Open the temporary output file.
+ if ( binaryFlag )
+ {
+ this->Stream::open(this->TempName.c_str(),
+ std::ios::out | std::ios::binary);
+ }
+ else
+ {
+ this->Stream::open(this->TempName.c_str(), std::ios::out);
+ }
+
+ // Check if the file opened.
+ if(!*this && !quiet)
+ {
+ cmSystemTools::Error("Cannot open file for write: ",
+ this->TempName.c_str());
+ cmSystemTools::ReportLastSystemError("");
+ }
+ return *this;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGeneratedFileStream::Close()
+{
+ // Save whether the temporary output file is valid before closing.
+ this->Okay = (*this)?true:false;
+
+ // Close the temporary output file.
+ this->Stream::close();
+
+ // Remove the temporary file (possibly by renaming to the real file).
+ return this->cmGeneratedFileStreamBase::Close();
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratedFileStream::SetCopyIfDifferent(bool copy_if_different)
+{
+ this->CopyIfDifferent = copy_if_different;
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratedFileStream::SetCompression(bool compression)
+{
+ this->Compress = compression;
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratedFileStream::SetCompressionExtraExtension(bool ext)
+{
+ this->CompressExtraExtension = ext;
+}
+
+//----------------------------------------------------------------------------
+cmGeneratedFileStreamBase::cmGeneratedFileStreamBase():
+ Name(),
+ TempName(),
+ CopyIfDifferent(false),
+ Okay(false),
+ Compress(false),
+ CompressExtraExtension(true)
+{
+}
+
+//----------------------------------------------------------------------------
+cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name):
+ Name(),
+ TempName(),
+ CopyIfDifferent(false),
+ Okay(false),
+ Compress(false),
+ CompressExtraExtension(true)
+{
+ this->Open(name);
+}
+
+//----------------------------------------------------------------------------
+cmGeneratedFileStreamBase::~cmGeneratedFileStreamBase()
+{
+ this->Close();
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratedFileStreamBase::Open(const char* name)
+{
+ // Save the original name of the file.
+ this->Name = name;
+
+ // Create the name of the temporary file.
+ this->TempName = name;
+#if defined(__VMS)
+ this->TempName += "_tmp";
+#else
+ this->TempName += ".tmp";
+#endif
+
+ // Make sure the temporary file that will be used is not present.
+ cmSystemTools::RemoveFile(this->TempName.c_str());
+
+ std::string dir = cmSystemTools::GetFilenamePath(this->TempName);
+ cmSystemTools::MakeDirectory(dir.c_str());
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratedFileStreamBase::Close()
+{
+ bool replaced = false;
+
+ std::string resname = this->Name;
+ if ( this->Compress && this->CompressExtraExtension )
+ {
+ resname += ".gz";
+ }
+
+ // Only consider replacing the destination file if no error
+ // occurred.
+ if(!this->Name.empty() &&
+ this->Okay &&
+ (!this->CopyIfDifferent ||
+ cmSystemTools::FilesDiffer(this->TempName.c_str(), resname.c_str())))
+ {
+ // The destination is to be replaced. Rename the temporary to the
+ // destination atomically.
+ if ( this->Compress )
+ {
+ std::string gzname = this->TempName + ".temp.gz";
+ if ( this->CompressFile(this->TempName.c_str(), gzname.c_str()) )
+ {
+ this->RenameFile(gzname.c_str(), resname.c_str());
+ }
+ cmSystemTools::RemoveFile(gzname.c_str());
+ }
+ else
+ {
+ this->RenameFile(this->TempName.c_str(), resname.c_str());
+ }
+
+ replaced = true;
+ }
+
+ // Else, the destination was not replaced.
+ //
+ // Always delete the temporary file. We never want it to stay around.
+ cmSystemTools::RemoveFile(this->TempName.c_str());
+
+ return replaced;
+}
+
+//----------------------------------------------------------------------------
+#ifdef CMAKE_BUILD_WITH_CMAKE
+int cmGeneratedFileStreamBase::CompressFile(const char* oldname,
+ const char* newname)
+{
+ gzFile gf = gzopen(newname, "w");
+ if ( !gf )
+ {
+ return 0;
+ }
+ FILE* ifs = cmsys::SystemTools::Fopen(oldname, "r");
+ if ( !ifs )
+ {
+ return 0;
+ }
+ size_t res;
+ const size_t BUFFER_SIZE = 1024;
+ char buffer[BUFFER_SIZE];
+ while ( (res = fread(buffer, 1, BUFFER_SIZE, ifs)) > 0 )
+ {
+ if ( !gzwrite(gf, buffer, static_cast<int>(res)) )
+ {
+ fclose(ifs);
+ gzclose(gf);
+ return 0;
+ }
+ }
+ fclose(ifs);
+ gzclose(gf);
+ return 1;
+}
+#else
+int cmGeneratedFileStreamBase::CompressFile(const char*, const char*)
+{
+ return 0;
+}
+#endif
+
+//----------------------------------------------------------------------------
+int cmGeneratedFileStreamBase::RenameFile(const char* oldname,
+ const char* newname)
+{
+ return cmSystemTools::RenameFile(oldname, newname);
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratedFileStream::SetName(const std::string& fname)
+{
+ this->Name = fname;
+}
diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h
new file mode 100644
index 0000000000..7adee7b7d0
--- /dev/null
+++ b/Source/cmGeneratedFileStream.h
@@ -0,0 +1,153 @@
+/*============================================================================
+ 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 cmGeneratedFileStream_h
+#define cmGeneratedFileStream_h
+
+#include "cmStandardIncludes.h"
+#include <cmsys/FStream.hxx>
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 1375 /* base class destructor not virtual */
+#endif
+
+// This is the first base class of cmGeneratedFileStream. It will be
+// created before and destroyed after the ofstream portion and can
+// therefore be used to manage the temporary file.
+class cmGeneratedFileStreamBase
+{
+protected:
+ // This constructor does not prepare the temporary file. The open
+ // method must be used.
+ cmGeneratedFileStreamBase();
+
+ // This constructor prepares the temporary output file.
+ cmGeneratedFileStreamBase(const char* name);
+
+ // The destructor renames the temporary output file to the real name.
+ ~cmGeneratedFileStreamBase();
+
+ // Internal methods to handle the temporary file. Open is always
+ // called before the real stream is opened. Close is always called
+ // after the real stream is closed and Okay is set to whether the
+ // real stream was still valid for writing when it was closed.
+ void Open(const char* name);
+ bool Close();
+
+ // Internal file replacement implementation.
+ int RenameFile(const char* oldname, const char* newname);
+
+ // Internal file compression implementation.
+ int CompressFile(const char* oldname, const char* newname);
+
+ // The name of the final destination file for the output.
+ std::string Name;
+
+ // The name of the temporary file.
+ std::string TempName;
+
+ // Whether to do a copy-if-different.
+ bool CopyIfDifferent;
+
+ // Whether the real file stream was valid when it was closed.
+ bool Okay;
+
+ // Whether the destionation file is compressed
+ bool Compress;
+
+ // Whether the destionation file is compressed
+ bool CompressExtraExtension;
+};
+
+/** \class cmGeneratedFileStream
+ * \brief Output stream for generated files.
+ *
+ * File generation should be atomic so that if CMake is killed then a
+ * generated file is either the original version or the complete new
+ * version. This stream is used to make sure file generation is
+ * atomic. Optionally the output file is only replaced if its
+ * contents have changed to prevent the file modification time from
+ * being updated.
+ */
+class cmGeneratedFileStream: private cmGeneratedFileStreamBase,
+ public cmsys::ofstream
+{
+public:
+ typedef cmsys::ofstream Stream;
+
+ /**
+ * This constructor prepares a default stream. The open method must
+ * be used before writing to the stream.
+ */
+ cmGeneratedFileStream();
+
+ /**
+ * This constructor takes the name of the file to be generated. It
+ * automatically generates a name for the temporary file. If the
+ * file cannot be opened an error message is produced unless the
+ * second argument is set to true.
+ */
+ cmGeneratedFileStream(const char* name, bool quiet=false);
+
+ /**
+ * The destructor checks the stream status to be sure the temporary
+ * file was successfully written before allowing the original to be
+ * replaced.
+ */
+ ~cmGeneratedFileStream();
+
+ /**
+ * Open an output file by name. This should be used only with a
+ * non-open stream. It automatically generates a name for the
+ * temporary file. If the file cannot be opened an error message is
+ * produced unless the second argument is set to true.
+ */
+ cmGeneratedFileStream& Open(const char* name, bool quiet=false,
+ bool binaryFlag=false);
+
+ /**
+ * Close the output file. This should be used only with an open
+ * stream. The temporary file is atomically renamed to the
+ * destionation file if the stream is still valid when this method
+ * is called.
+ */
+ bool Close();
+
+ /**
+ * Set whether copy-if-different is done.
+ */
+ void SetCopyIfDifferent(bool copy_if_different);
+
+ /**
+ * Set whether compression is done.
+ */
+ void SetCompression(bool compression);
+
+ /**
+ * Set whether compression has extra extension
+ */
+ void SetCompressionExtraExtension(bool ext);
+
+ /**
+ * Set name of the file that will hold the actual output. This method allows
+ * the output file to be changed during the use of cmGeneratedFileStream.
+ */
+ void SetName(const std::string& fname);
+
+private:
+ cmGeneratedFileStream(cmGeneratedFileStream const&); // not implemented
+};
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma reset woff 1375 /* base class destructor not virtual */
+#endif
+
+#endif
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx
new file mode 100644
index 0000000000..7fc1464c36
--- /dev/null
+++ b/Source/cmGeneratorExpression.cxx
@@ -0,0 +1,494 @@
+/*============================================================================
+ 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 "cmGeneratorExpression.h"
+
+#include "cmMakefile.h"
+#include "cmTarget.h"
+#include "assert.h"
+
+#include <cmsys/String.h>
+
+#include "cmGeneratorExpressionEvaluator.h"
+#include "cmGeneratorExpressionLexer.h"
+#include "cmGeneratorExpressionParser.h"
+#include "cmGeneratorExpressionDAGChecker.h"
+
+//----------------------------------------------------------------------------
+cmGeneratorExpression::cmGeneratorExpression(
+ cmListFileBacktrace const* backtrace):
+ Backtrace(backtrace)
+{
+}
+
+//----------------------------------------------------------------------------
+cmsys::auto_ptr<cmCompiledGeneratorExpression>
+cmGeneratorExpression::Parse(std::string const& input)
+{
+#if !defined(__BORLANDC__)
+ return cmsys::auto_ptr<cmCompiledGeneratorExpression>(
+ new cmCompiledGeneratorExpression(
+ this->Backtrace ? *this->Backtrace : cmListFileBacktrace(NULL),
+ input));
+#else
+ cmListFileBacktrace emptyBacktrace(NULL);
+ return cmsys::auto_ptr<cmCompiledGeneratorExpression>(
+ new cmCompiledGeneratorExpression(
+ this->Backtrace ? *this->Backtrace : emptyBacktrace,
+ input));
+#endif
+}
+
+//----------------------------------------------------------------------------
+cmsys::auto_ptr<cmCompiledGeneratorExpression>
+cmGeneratorExpression::Parse(const char* input)
+{
+ return this->Parse(std::string(input ? input : ""));
+}
+
+cmGeneratorExpression::~cmGeneratorExpression()
+{
+}
+
+//----------------------------------------------------------------------------
+const char *cmCompiledGeneratorExpression::Evaluate(
+ cmMakefile* mf, const std::string& config, bool quiet,
+ cmTarget const* headTarget,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+{
+ return this->Evaluate(mf,
+ config,
+ quiet,
+ headTarget,
+ headTarget,
+ dagChecker);
+}
+
+//----------------------------------------------------------------------------
+const char *cmCompiledGeneratorExpression::Evaluate(
+ cmMakefile* mf, const std::string& config, bool quiet,
+ cmTarget const* headTarget,
+ cmTarget const* currentTarget,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+{
+ if (!this->NeedsEvaluation)
+ {
+ return this->Input.c_str();
+ }
+
+ this->Output = "";
+
+ std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
+ = this->Evaluators.begin();
+ const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
+ = this->Evaluators.end();
+
+ cmGeneratorExpressionContext context;
+ context.Makefile = mf;
+ context.Config = config;
+ context.Quiet = quiet;
+ context.HadError = false;
+ context.HadContextSensitiveCondition = false;
+ context.HadHeadSensitiveCondition = false;
+ context.HeadTarget = headTarget;
+ context.EvaluateForBuildsystem = this->EvaluateForBuildsystem;
+ context.CurrentTarget = currentTarget ? currentTarget : headTarget;
+ context.Backtrace = this->Backtrace;
+
+ for ( ; it != end; ++it)
+ {
+ this->Output += (*it)->Evaluate(&context, dagChecker);
+
+ for(std::set<std::string>::const_iterator
+ p = context.SeenTargetProperties.begin();
+ p != context.SeenTargetProperties.end(); ++p)
+ {
+ this->SeenTargetProperties.insert(*p);
+ }
+ if (context.HadError)
+ {
+ this->Output = "";
+ break;
+ }
+ }
+
+ this->MaxLanguageStandard = context.MaxLanguageStandard;
+
+ if (!context.HadError)
+ {
+ this->HadContextSensitiveCondition = context.HadContextSensitiveCondition;
+ this->HadHeadSensitiveCondition = context.HadHeadSensitiveCondition;
+ }
+
+ this->DependTargets = context.DependTargets;
+ this->AllTargetsSeen = context.AllTargets;
+ // TODO: Return a std::string from here instead?
+ return this->Output.c_str();
+}
+
+cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
+ cmListFileBacktrace const& backtrace,
+ const std::string& input)
+ : Backtrace(backtrace), Input(input),
+ HadContextSensitiveCondition(false),
+ HadHeadSensitiveCondition(false),
+ EvaluateForBuildsystem(false)
+{
+ cmGeneratorExpressionLexer l;
+ std::vector<cmGeneratorExpressionToken> tokens =
+ l.Tokenize(this->Input);
+ this->NeedsEvaluation = l.GetSawGeneratorExpression();
+
+ if (this->NeedsEvaluation)
+ {
+ cmGeneratorExpressionParser p(tokens);
+ p.Parse(this->Evaluators);
+ }
+}
+
+
+//----------------------------------------------------------------------------
+cmCompiledGeneratorExpression::~cmCompiledGeneratorExpression()
+{
+ std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
+ = this->Evaluators.begin();
+ const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
+ = this->Evaluators.end();
+
+ for ( ; it != end; ++it)
+ {
+ delete *it;
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmGeneratorExpression::StripEmptyListElements(
+ const std::string &input)
+{
+ if (input.find(';') == input.npos)
+ {
+ return input;
+ }
+ std::string result;
+ result.reserve(input.size());
+
+ const char *c = input.c_str();
+ const char *last = c;
+ bool skipSemiColons = true;
+ for ( ; *c; ++c)
+ {
+ if(*c == ';')
+ {
+ if(skipSemiColons)
+ {
+ result.append(last, c - last);
+ last = c + 1;
+ }
+ skipSemiColons = true;
+ }
+ else
+ {
+ skipSemiColons = false;
+ }
+ }
+ result.append(last);
+
+ if (!result.empty() && *(result.end() - 1) == ';')
+ {
+ result.resize(result.size() - 1);
+ }
+
+ return result;
+}
+
+//----------------------------------------------------------------------------
+static std::string stripAllGeneratorExpressions(const std::string &input)
+{
+ std::string result;
+ std::string::size_type pos = 0;
+ std::string::size_type lastPos = pos;
+ int nestingLevel = 0;
+ while((pos = input.find("$<", lastPos)) != input.npos)
+ {
+ result += input.substr(lastPos, pos - lastPos);
+ pos += 2;
+ nestingLevel = 1;
+ const char *c = input.c_str() + pos;
+ const char * const cStart = c;
+ for ( ; *c; ++c)
+ {
+ if(c[0] == '$' && c[1] == '<')
+ {
+ ++nestingLevel;
+ ++c;
+ continue;
+ }
+ if(c[0] == '>')
+ {
+ --nestingLevel;
+ if (nestingLevel == 0)
+ {
+ break;
+ }
+ }
+ }
+ const std::string::size_type traversed = (c - cStart) + 1;
+ if (!*c)
+ {
+ result += "$<" + input.substr(pos, traversed);
+ }
+ pos += traversed;
+ lastPos = pos;
+ }
+ if (nestingLevel == 0)
+ {
+ result += input.substr(lastPos);
+ }
+ return cmGeneratorExpression::StripEmptyListElements(result);
+}
+
+//----------------------------------------------------------------------------
+static void prefixItems(const std::string &content, std::string &result,
+ const std::string &prefix)
+{
+ std::vector<std::string> entries;
+ cmGeneratorExpression::Split(content, entries);
+ const char *sep = "";
+ for(std::vector<std::string>::const_iterator ei = entries.begin();
+ ei != entries.end(); ++ei)
+ {
+ result += sep;
+ sep = ";";
+ if (!cmSystemTools::FileIsFullPath(ei->c_str())
+ && cmGeneratorExpression::Find(*ei) != 0)
+ {
+ result += prefix;
+ }
+ result += *ei;
+ }
+}
+
+//----------------------------------------------------------------------------
+static std::string stripExportInterface(const std::string &input,
+ cmGeneratorExpression::PreprocessContext context,
+ bool resolveRelative)
+{
+ std::string result;
+
+ int nestingLevel = 0;
+ std::string::size_type pos = 0;
+ std::string::size_type lastPos = pos;
+ while (true)
+ {
+ std::string::size_type bPos = input.find("$<BUILD_INTERFACE:", lastPos);
+ std::string::size_type iPos = input.find("$<INSTALL_INTERFACE:", lastPos);
+
+ if (bPos == std::string::npos && iPos == std::string::npos)
+ {
+ break;
+ }
+
+ if (bPos == std::string::npos)
+ {
+ pos = iPos;
+ }
+ else if (iPos == std::string::npos)
+ {
+ pos = bPos;
+ }
+ else
+ {
+ pos = (bPos < iPos) ? bPos : iPos;
+ }
+
+ result += input.substr(lastPos, pos - lastPos);
+ const bool gotInstallInterface = input[pos + 2] == 'I';
+ pos += gotInstallInterface ? sizeof("$<INSTALL_INTERFACE:") - 1
+ : sizeof("$<BUILD_INTERFACE:") - 1;
+ nestingLevel = 1;
+ const char *c = input.c_str() + pos;
+ const char * const cStart = c;
+ for ( ; *c; ++c)
+ {
+ if(c[0] == '$' && c[1] == '<')
+ {
+ ++nestingLevel;
+ ++c;
+ continue;
+ }
+ if(c[0] == '>')
+ {
+ --nestingLevel;
+ if (nestingLevel != 0)
+ {
+ continue;
+ }
+ if(context == cmGeneratorExpression::BuildInterface
+ && !gotInstallInterface)
+ {
+ result += input.substr(pos, c - cStart);
+ }
+ else if(context == cmGeneratorExpression::InstallInterface
+ && gotInstallInterface)
+ {
+ const std::string content = input.substr(pos, c - cStart);
+ if (resolveRelative)
+ {
+ prefixItems(content, result, "${_IMPORT_PREFIX}/");
+ }
+ else
+ {
+ result += content;
+ }
+ }
+ break;
+ }
+ }
+ const std::string::size_type traversed = (c - cStart) + 1;
+ if (!*c)
+ {
+ result += std::string(gotInstallInterface ? "$<INSTALL_INTERFACE:"
+ : "$<BUILD_INTERFACE:")
+ + input.substr(pos, traversed);
+ }
+ pos += traversed;
+ lastPos = pos;
+ }
+ if (nestingLevel == 0)
+ {
+ result += input.substr(lastPos);
+ }
+
+ return cmGeneratorExpression::StripEmptyListElements(result);
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorExpression::Split(const std::string &input,
+ std::vector<std::string> &output)
+{
+ std::string::size_type pos = 0;
+ std::string::size_type lastPos = pos;
+ while((pos = input.find("$<", lastPos)) != input.npos)
+ {
+ std::string part = input.substr(lastPos, pos - lastPos);
+ std::string preGenex;
+ if (!part.empty())
+ {
+ std::string::size_type startPos = input.rfind(";", pos);
+ if (startPos == std::string::npos)
+ {
+ preGenex = part;
+ part = "";
+ }
+ else if (startPos != pos - 1 && startPos >= lastPos)
+ {
+ part = input.substr(lastPos, startPos - lastPos);
+ preGenex = input.substr(startPos + 1, pos - startPos - 1);
+ }
+ if(!part.empty())
+ {
+ cmSystemTools::ExpandListArgument(part, output);
+ }
+ }
+ pos += 2;
+ int nestingLevel = 1;
+ const char *c = input.c_str() + pos;
+ const char * const cStart = c;
+ for ( ; *c; ++c)
+ {
+ if(c[0] == '$' && c[1] == '<')
+ {
+ ++nestingLevel;
+ ++c;
+ continue;
+ }
+ if(c[0] == '>')
+ {
+ --nestingLevel;
+ if (nestingLevel == 0)
+ {
+ break;
+ }
+ }
+ }
+ for ( ; *c; ++c)
+ {
+ // Capture the part after the genex and before the next ';'
+ if(c[0] == ';')
+ {
+ --c;
+ break;
+ }
+ }
+ const std::string::size_type traversed = (c - cStart) + 1;
+ output.push_back(preGenex + "$<" + input.substr(pos, traversed));
+ pos += traversed;
+ lastPos = pos;
+ }
+ if (lastPos < input.size())
+ {
+ cmSystemTools::ExpandListArgument(input.substr(lastPos), output);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmGeneratorExpression::Preprocess(const std::string &input,
+ PreprocessContext context,
+ bool resolveRelative)
+{
+ if (context == StripAllGeneratorExpressions)
+ {
+ return stripAllGeneratorExpressions(input);
+ }
+ else if (context == BuildInterface || context == InstallInterface)
+ {
+ return stripExportInterface(input, context, resolveRelative);
+ }
+
+ assert(!"cmGeneratorExpression::Preprocess called with invalid args");
+ return std::string();
+}
+
+//----------------------------------------------------------------------------
+std::string::size_type cmGeneratorExpression::Find(const std::string &input)
+{
+ const std::string::size_type openpos = input.find("$<");
+ if (openpos != std::string::npos
+ && input.find(">", openpos) != std::string::npos)
+ {
+ return openpos;
+ }
+ return std::string::npos;
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorExpression::IsValidTargetName(const std::string &input)
+{
+ // The ':' is supported to allow use with IMPORTED targets. At least
+ // Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter.
+ static cmsys::RegularExpression targetNameValidator("^[A-Za-z0-9_.:+-]+$");
+
+ return targetNameValidator.find(input);
+}
+
+//----------------------------------------------------------------------------
+void
+cmCompiledGeneratorExpression::GetMaxLanguageStandard(cmTarget const* tgt,
+ std::map<std::string, std::string>& mapping)
+{
+ typedef std::map<cmTarget const*,
+ std::map<std::string, std::string> > MapType;
+ MapType::const_iterator it = this->MaxLanguageStandard.find(tgt);
+ if (it != this->MaxLanguageStandard.end())
+ {
+ mapping = it->second;
+ }
+}
diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h
new file mode 100644
index 0000000000..b952520e60
--- /dev/null
+++ b/Source/cmGeneratorExpression.h
@@ -0,0 +1,152 @@
+/*============================================================================
+ 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 cmGeneratorExpression_h
+#define cmGeneratorExpression_h
+
+#include "cmStandardIncludes.h"
+#include "cmListFileCache.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/auto_ptr.hxx>
+
+class cmTarget;
+class cmMakefile;
+class cmListFileBacktrace;
+
+struct cmGeneratorExpressionEvaluator;
+struct cmGeneratorExpressionDAGChecker;
+
+class cmCompiledGeneratorExpression;
+
+/** \class cmGeneratorExpression
+ * \brief Evaluate generate-time query expression syntax.
+ *
+ * cmGeneratorExpression instances are used by build system generator
+ * implementations to evaluate the $<> generator expression syntax.
+ * Generator expressions are evaluated just before the generate step
+ * writes strings into the build system. They have knowledge of the
+ * build configuration which is not available at configure time.
+ */
+class cmGeneratorExpression
+{
+public:
+ /** Construct. */
+ cmGeneratorExpression(cmListFileBacktrace const* backtrace = NULL);
+ ~cmGeneratorExpression();
+
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(
+ std::string const& input);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(const char* input);
+
+ enum PreprocessContext {
+ StripAllGeneratorExpressions,
+ BuildInterface,
+ InstallInterface
+ };
+
+ static std::string Preprocess(const std::string &input,
+ PreprocessContext context,
+ bool resolveRelative = false);
+
+ static void Split(const std::string &input,
+ std::vector<std::string> &output);
+
+ static std::string::size_type Find(const std::string &input);
+
+ static bool IsValidTargetName(const std::string &input);
+
+ static std::string StripEmptyListElements(const std::string &input);
+private:
+ cmGeneratorExpression(const cmGeneratorExpression &);
+ void operator=(const cmGeneratorExpression &);
+
+ cmListFileBacktrace const* Backtrace;
+};
+
+class cmCompiledGeneratorExpression
+{
+public:
+ const char* Evaluate(cmMakefile* mf, const std::string& config,
+ bool quiet = false,
+ cmTarget const* headTarget = 0,
+ cmTarget const* currentTarget = 0,
+ cmGeneratorExpressionDAGChecker *dagChecker = 0) const;
+ const char* Evaluate(cmMakefile* mf, const std::string& config,
+ bool quiet,
+ cmTarget const* headTarget,
+ cmGeneratorExpressionDAGChecker *dagChecker) const;
+
+ /** Get set of targets found during evaluations. */
+ std::set<cmTarget*> const& GetTargets() const
+ { return this->DependTargets; }
+
+ std::set<std::string> const& GetSeenTargetProperties() const
+ { return this->SeenTargetProperties; }
+
+ std::set<cmTarget const*> const& GetAllTargetsSeen() const
+ { return this->AllTargetsSeen; }
+
+ ~cmCompiledGeneratorExpression();
+
+ std::string const& GetInput() const
+ {
+ return this->Input;
+ }
+
+ cmListFileBacktrace GetBacktrace() const
+ {
+ return this->Backtrace;
+ }
+ bool GetHadContextSensitiveCondition() const
+ {
+ return this->HadContextSensitiveCondition;
+ }
+ bool GetHadHeadSensitiveCondition() const
+ {
+ return this->HadHeadSensitiveCondition;
+ }
+
+ void SetEvaluateForBuildsystem(bool eval)
+ {
+ this->EvaluateForBuildsystem = eval;
+ }
+
+ void GetMaxLanguageStandard(cmTarget const* tgt,
+ std::map<std::string, std::string>& mapping);
+
+private:
+ cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
+ const std::string& input);
+
+ friend class cmGeneratorExpression;
+
+ cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
+ void operator=(const cmCompiledGeneratorExpression &);
+
+ cmListFileBacktrace Backtrace;
+ std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
+ const std::string Input;
+ bool NeedsEvaluation;
+
+ mutable std::set<cmTarget*> DependTargets;
+ mutable std::set<cmTarget const*> AllTargetsSeen;
+ mutable std::set<std::string> SeenTargetProperties;
+ mutable std::map<cmTarget const*, std::map<std::string, std::string> >
+ MaxLanguageStandard;
+ mutable std::string Output;
+ mutable bool HadContextSensitiveCondition;
+ mutable bool HadHeadSensitiveCondition;
+ bool EvaluateForBuildsystem;
+};
+
+#endif
diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx
new file mode 100644
index 0000000000..75a84cb63d
--- /dev/null
+++ b/Source/cmGeneratorExpressionDAGChecker.cxx
@@ -0,0 +1,247 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmGeneratorExpressionDAGChecker.h"
+
+#include "cmMakefile.h"
+
+//----------------------------------------------------------------------------
+cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
+ const cmListFileBacktrace &backtrace,
+ const std::string &target,
+ const std::string &property,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *parent)
+ : Parent(parent), Target(target), Property(property),
+ Content(content), Backtrace(backtrace), TransitivePropertiesOnly(false)
+{
+ Initialize();
+}
+
+//----------------------------------------------------------------------------
+cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
+ const std::string &target,
+ const std::string &property,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *parent)
+ : Parent(parent), Target(target), Property(property),
+ Content(content), Backtrace(NULL), TransitivePropertiesOnly(false)
+{
+ Initialize();
+}
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorExpressionDAGChecker::Initialize()
+{
+ const cmGeneratorExpressionDAGChecker *top = this;
+ const cmGeneratorExpressionDAGChecker *p = this->Parent;
+ while (p)
+ {
+ top = p;
+ p = p->Parent;
+ }
+ this->CheckResult = this->CheckGraph();
+
+#define TEST_TRANSITIVE_PROPERTY_METHOD(METHOD) \
+ top->METHOD () ||
+
+ if (CheckResult == DAG && (
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(TEST_TRANSITIVE_PROPERTY_METHOD)
+ false)
+ )
+#undef TEST_TRANSITIVE_PROPERTY_METHOD
+ {
+ std::map<std::string, std::set<std::string> >::const_iterator it
+ = top->Seen.find(this->Target);
+ if (it != top->Seen.end())
+ {
+ const std::set<std::string> &propSet = it->second;
+ const std::set<std::string>::const_iterator i
+ = propSet.find(this->Property);
+ if (i != propSet.end())
+ {
+ this->CheckResult = ALREADY_SEEN;
+ return;
+ }
+ }
+ const_cast<cmGeneratorExpressionDAGChecker *>(top)
+ ->Seen[this->Target].insert(this->Property);
+ }
+}
+
+//----------------------------------------------------------------------------
+cmGeneratorExpressionDAGChecker::Result
+cmGeneratorExpressionDAGChecker::Check() const
+{
+ return this->CheckResult;
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorExpressionDAGChecker::ReportError(
+ cmGeneratorExpressionContext *context,
+ const std::string &expr)
+{
+ if (this->CheckResult == DAG)
+ {
+ return;
+ }
+
+ context->HadError = true;
+ if (context->Quiet)
+ {
+ return;
+ }
+
+ const cmGeneratorExpressionDAGChecker *parent = this->Parent;
+
+ if (parent && !parent->Parent)
+ {
+ cmOStringStream e;
+ e << "Error evaluating generator expression:\n"
+ << " " << expr << "\n"
+ << "Self reference on target \""
+ << context->HeadTarget->GetName() << "\".\n";
+ context->Makefile->GetCMakeInstance()
+ ->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ parent->Backtrace);
+ return;
+ }
+
+ {
+ cmOStringStream e;
+ e << "Error evaluating generator expression:\n"
+ << " " << expr << "\n"
+ << "Dependency loop found.";
+ context->Makefile->GetCMakeInstance()
+ ->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ context->Backtrace);
+ }
+
+ int loopStep = 1;
+ while (parent)
+ {
+ cmOStringStream e;
+ e << "Loop step " << loopStep << "\n"
+ << " "
+ << (parent->Content ? parent->Content->GetOriginalExpression() : expr)
+ << "\n";
+ context->Makefile->GetCMakeInstance()
+ ->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ parent->Backtrace);
+ parent = parent->Parent;
+ ++loopStep;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmGeneratorExpressionDAGChecker::Result
+cmGeneratorExpressionDAGChecker::CheckGraph() const
+{
+ const cmGeneratorExpressionDAGChecker *parent = this->Parent;
+ while (parent)
+ {
+ if (this->Target == parent->Target && this->Property == parent->Property)
+ {
+ return (parent == this->Parent) ? SELF_REFERENCE : CYCLIC_REFERENCE;
+ }
+ parent = parent->Parent;
+ }
+ return DAG;
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnly()
+{
+ const cmGeneratorExpressionDAGChecker *top = this;
+ const cmGeneratorExpressionDAGChecker *parent = this->Parent;
+ while (parent)
+ {
+ top = parent;
+ parent = parent->Parent;
+ }
+
+ return top->TransitivePropertiesOnly;
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(const char *tgt)
+{
+ const cmGeneratorExpressionDAGChecker *top = this;
+ const cmGeneratorExpressionDAGChecker *parent = this->Parent;
+ while (parent)
+ {
+ top = parent;
+ parent = parent->Parent;
+ }
+
+ const char *prop = top->Property.c_str();
+
+ if (tgt)
+ {
+ return top->Target == tgt && strcmp(prop, "LINK_LIBRARIES") == 0;
+ }
+
+ return (strcmp(prop, "LINK_LIBRARIES") == 0
+ || strcmp(prop, "LINK_INTERFACE_LIBRARIES") == 0
+ || strcmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
+ || cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES_")
+ || cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES_"))
+ || strcmp(prop, "INTERFACE_LINK_LIBRARIES") == 0;
+}
+
+std::string cmGeneratorExpressionDAGChecker::TopTarget() const
+{
+ const cmGeneratorExpressionDAGChecker *top = this;
+ const cmGeneratorExpressionDAGChecker *parent = this->Parent;
+ while (parent)
+ {
+ top = parent;
+ parent = parent->Parent;
+ }
+ return top->Target;
+}
+
+enum TransitiveProperty {
+#define DEFINE_ENUM_ENTRY(NAME) NAME,
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(DEFINE_ENUM_ENTRY)
+#undef DEFINE_ENUM_ENTRY
+ TransitivePropertyTerminal
+};
+
+template<TransitiveProperty>
+bool additionalTest(const char* const)
+{
+ return false;
+}
+
+template<>
+bool additionalTest<COMPILE_DEFINITIONS>(const char* const prop)
+{
+ return cmHasLiteralPrefix(prop, "COMPILE_DEFINITIONS_");
+}
+
+#define DEFINE_TRANSITIVE_PROPERTY_METHOD(METHOD, PROPERTY) \
+bool cmGeneratorExpressionDAGChecker::METHOD() const \
+{ \
+ const char* const prop = this->Property.c_str(); \
+ if (strcmp(prop, #PROPERTY) == 0 \
+ || strcmp(prop, "INTERFACE_" #PROPERTY) == 0) \
+ { \
+ return true; \
+ } \
+ return additionalTest<PROPERTY>(prop); \
+}
+
+CM_FOR_EACH_TRANSITIVE_PROPERTY(DEFINE_TRANSITIVE_PROPERTY_METHOD)
+
+#undef DEFINE_TRANSITIVE_PROPERTY_METHOD
diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h
new file mode 100644
index 0000000000..10f9fa7460
--- /dev/null
+++ b/Source/cmGeneratorExpressionDAGChecker.h
@@ -0,0 +1,96 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmGeneratorExpressionDAGChecker_h
+#define cmGeneratorExpressionDAGChecker_h
+
+#include "cmStandardIncludes.h"
+
+#include "cmGeneratorExpressionEvaluator.h"
+
+#define CM_SELECT_BOTH(F, A1, A2) F(A1, A2)
+#define CM_SELECT_FIRST(F, A1, A2) F(A1)
+#define CM_SELECT_SECOND(F, A1, A2) F(A2)
+
+#define CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, SELECT) \
+ SELECT(F, EvaluatingIncludeDirectories, INCLUDE_DIRECTORIES) \
+ SELECT(F, EvaluatingSystemIncludeDirectories, SYSTEM_INCLUDE_DIRECTORIES) \
+ SELECT(F, EvaluatingCompileDefinitions, COMPILE_DEFINITIONS) \
+ SELECT(F, EvaluatingCompileOptions, COMPILE_OPTIONS) \
+ SELECT(F, EvaluatingAutoUicOptions, AUTOUIC_OPTIONS) \
+ SELECT(F, EvaluatingSources, SOURCES) \
+ SELECT(F, EvaluatingCompileFeatures, COMPILE_FEATURES)
+
+#define CM_FOR_EACH_TRANSITIVE_PROPERTY(F) \
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_BOTH)
+
+#define CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(F) \
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_FIRST)
+
+#define CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(F) \
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_SECOND)
+
+//----------------------------------------------------------------------------
+struct cmGeneratorExpressionDAGChecker
+{
+ cmGeneratorExpressionDAGChecker(const cmListFileBacktrace &backtrace,
+ const std::string &target,
+ const std::string &property,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *parent);
+ cmGeneratorExpressionDAGChecker(const std::string &target,
+ const std::string &property,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *parent);
+
+ enum Result {
+ DAG,
+ SELF_REFERENCE,
+ CYCLIC_REFERENCE,
+ ALREADY_SEEN
+ };
+
+ Result Check() const;
+
+ void ReportError(cmGeneratorExpressionContext *context,
+ const std::string &expr);
+
+ bool EvaluatingLinkLibraries(const char *tgt = 0);
+
+#define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) \
+ bool METHOD () const;
+
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(DECLARE_TRANSITIVE_PROPERTY_METHOD)
+
+#undef DECLARE_TRANSITIVE_PROPERTY_METHOD
+
+ bool GetTransitivePropertiesOnly();
+ void SetTransitivePropertiesOnly()
+ { this->TransitivePropertiesOnly = true; }
+
+ std::string TopTarget() const;
+
+private:
+ Result CheckGraph() const;
+ void Initialize();
+
+private:
+ const cmGeneratorExpressionDAGChecker * const Parent;
+ const std::string Target;
+ const std::string Property;
+ std::map<std::string, std::set<std::string> > Seen;
+ const GeneratorExpressionContent * const Content;
+ const cmListFileBacktrace Backtrace;
+ Result CheckResult;
+ bool TransitivePropertiesOnly;
+};
+
+#endif
diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx
new file mode 100644
index 0000000000..f9067cf9a9
--- /dev/null
+++ b/Source/cmGeneratorExpressionEvaluationFile.cxx
@@ -0,0 +1,140 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmGeneratorExpressionEvaluationFile.h"
+
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include <cmsys/FStream.hxx>
+
+#include <assert.h>
+
+//----------------------------------------------------------------------------
+cmGeneratorExpressionEvaluationFile::cmGeneratorExpressionEvaluationFile(
+ const std::string &input,
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> outputFileExpr,
+ cmMakefile *makefile,
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
+ bool inputIsContent)
+ : Input(input),
+ OutputFileExpr(outputFileExpr),
+ Makefile(makefile),
+ Condition(condition),
+ InputIsContent(inputIsContent)
+{
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config,
+ cmCompiledGeneratorExpression* inputExpression,
+ std::map<std::string, std::string> &outputFiles)
+{
+ std::string rawCondition = this->Condition->GetInput();
+ if (!rawCondition.empty())
+ {
+ std::string condResult = this->Condition->Evaluate(this->Makefile, config);
+ if (condResult == "0")
+ {
+ return;
+ }
+ if (condResult != "1")
+ {
+ cmOStringStream e;
+ e << "Evaluation file condition \"" << rawCondition << "\" did "
+ "not evaluate to valid content. Got \"" << condResult << "\".";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ }
+
+ const std::string outputFileName
+ = this->OutputFileExpr->Evaluate(this->Makefile, config);
+ const std::string outputContent
+ = inputExpression->Evaluate(this->Makefile, config);
+
+ std::map<std::string, std::string>::iterator it
+ = outputFiles.find(outputFileName);
+
+ if(it != outputFiles.end())
+ {
+ if (it->second == outputContent)
+ {
+ return;
+ }
+ cmOStringStream e;
+ e << "Evaluation file to be written multiple times for different "
+ "configurations with different content:\n " << outputFileName;
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+
+ this->Files.push_back(outputFileName);
+ outputFiles[outputFileName] = outputContent;
+
+ cmGeneratedFileStream fout(outputFileName.c_str());
+ fout.SetCopyIfDifferent(true);
+ fout << outputContent;
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorExpressionEvaluationFile::Generate()
+{
+ std::string inputContent;
+ if (this->InputIsContent)
+ {
+ inputContent = this->Input;
+ }
+ else
+ {
+ cmsys::ifstream fin(this->Input.c_str());
+ if(!fin)
+ {
+ cmOStringStream e;
+ e << "Evaluation file \"" << this->Input << "\" cannot be read.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+
+ std::string line;
+ std::string sep;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ inputContent += sep + line;
+ sep = "\n";
+ }
+ inputContent += sep;
+ }
+
+ cmListFileBacktrace lfbt = this->OutputFileExpr->GetBacktrace();
+ cmGeneratorExpression contentGE(&lfbt);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> inputExpression
+ = contentGE.Parse(inputContent);
+
+ std::map<std::string, std::string> outputFiles;
+
+ std::vector<std::string> allConfigs;
+ this->Makefile->GetConfigurations(allConfigs);
+
+ if (allConfigs.empty())
+ {
+ allConfigs.push_back("");
+ }
+ for(std::vector<std::string>::const_iterator li = allConfigs.begin();
+ li != allConfigs.end(); ++li)
+ {
+ this->Generate(*li, inputExpression.get(), outputFiles);
+ if(cmSystemTools::GetFatalErrorOccured())
+ {
+ return;
+ }
+ }
+}
diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h
new file mode 100644
index 0000000000..f939916d6e
--- /dev/null
+++ b/Source/cmGeneratorExpressionEvaluationFile.h
@@ -0,0 +1,48 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmGeneratorExpressionEvaluationFile_h
+#define cmGeneratorExpressionEvaluationFile_h
+
+#include "cmStandardIncludes.h"
+#include <cmsys/auto_ptr.hxx>
+
+#include "cmGeneratorExpression.h"
+
+//----------------------------------------------------------------------------
+class cmGeneratorExpressionEvaluationFile
+{
+public:
+ cmGeneratorExpressionEvaluationFile(const std::string &input,
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> outputFileExpr,
+ cmMakefile *makefile,
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
+ bool inputIsContent);
+
+ void Generate();
+
+ std::vector<std::string> GetFiles() const { return this->Files; }
+
+private:
+ void Generate(const std::string& config,
+ cmCompiledGeneratorExpression* inputExpression,
+ std::map<std::string, std::string> &outputFiles);
+
+private:
+ const std::string Input;
+ const cmsys::auto_ptr<cmCompiledGeneratorExpression> OutputFileExpr;
+ cmMakefile *Makefile;
+ const cmsys::auto_ptr<cmCompiledGeneratorExpression> Condition;
+ std::vector<std::string> Files;
+ const bool InputIsContent;
+};
+
+#endif
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
new file mode 100644
index 0000000000..c1478df729
--- /dev/null
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -0,0 +1,2069 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmMakefile.h"
+
+#include "cmGeneratorExpressionEvaluator.h"
+#include "cmGeneratorExpressionParser.h"
+#include "cmGeneratorExpressionDAGChecker.h"
+#include "cmGeneratorExpression.h"
+#include "cmLocalGenerator.h"
+#include "cmSourceFile.h"
+
+#include <cmsys/String.h>
+
+#include <assert.h>
+#include <errno.h>
+
+//----------------------------------------------------------------------------
+#if !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x510
+static
+#endif
+void reportError(cmGeneratorExpressionContext *context,
+ const std::string &expr, const std::string &result)
+{
+ context->HadError = true;
+ if (context->Quiet)
+ {
+ return;
+ }
+
+ cmOStringStream e;
+ e << "Error evaluating generator expression:\n"
+ << " " << expr << "\n"
+ << result;
+ context->Makefile->GetCMakeInstance()
+ ->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ context->Backtrace);
+}
+
+//----------------------------------------------------------------------------
+struct cmGeneratorExpressionNode
+{
+ enum {
+ DynamicParameters = 0,
+ OneOrMoreParameters = -1,
+ OneOrZeroParameters = -2
+ };
+ virtual ~cmGeneratorExpressionNode() {}
+
+ virtual bool GeneratesContent() const { return true; }
+
+ virtual bool RequiresLiteralInput() const { return false; }
+
+ virtual bool AcceptsArbitraryContentParameter() const
+ { return false; }
+
+ virtual int NumExpectedParameters() const { return 1; }
+
+ virtual std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *dagChecker
+ ) const = 0;
+};
+
+//----------------------------------------------------------------------------
+static const struct ZeroNode : public cmGeneratorExpressionNode
+{
+ ZeroNode() {}
+
+ virtual bool GeneratesContent() const { return false; }
+
+ virtual bool AcceptsArbitraryContentParameter() const { return true; }
+
+ std::string Evaluate(const std::vector<std::string> &,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return std::string();
+ }
+} zeroNode;
+
+//----------------------------------------------------------------------------
+static const struct OneNode : public cmGeneratorExpressionNode
+{
+ OneNode() {}
+
+ virtual bool AcceptsArbitraryContentParameter() const { return true; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return parameters.front();
+ }
+} oneNode;
+
+//----------------------------------------------------------------------------
+static const struct OneNode buildInterfaceNode;
+
+//----------------------------------------------------------------------------
+static const struct ZeroNode installInterfaceNode;
+
+//----------------------------------------------------------------------------
+#define BOOLEAN_OP_NODE(OPNAME, OP, SUCCESS_VALUE, FAILURE_VALUE) \
+static const struct OP ## Node : public cmGeneratorExpressionNode \
+{ \
+ OP ## Node () {} \
+ virtual int NumExpectedParameters() const { return OneOrMoreParameters; } \
+ \
+ std::string Evaluate(const std::vector<std::string> &parameters, \
+ cmGeneratorExpressionContext *context, \
+ const GeneratorExpressionContent *content, \
+ cmGeneratorExpressionDAGChecker *) const \
+ { \
+ std::vector<std::string>::const_iterator it = parameters.begin(); \
+ const std::vector<std::string>::const_iterator end = parameters.end(); \
+ for ( ; it != end; ++it) \
+ { \
+ if (*it == #FAILURE_VALUE) \
+ { \
+ return #FAILURE_VALUE; \
+ } \
+ else if (*it != #SUCCESS_VALUE) \
+ { \
+ reportError(context, content->GetOriginalExpression(), \
+ "Parameters to $<" #OP "> must resolve to either '0' or '1'."); \
+ return std::string(); \
+ } \
+ } \
+ return #SUCCESS_VALUE; \
+ } \
+} OPNAME;
+
+BOOLEAN_OP_NODE(andNode, AND, 1, 0)
+BOOLEAN_OP_NODE(orNode, OR, 0, 1)
+
+#undef BOOLEAN_OP_NODE
+
+//----------------------------------------------------------------------------
+static const struct NotNode : public cmGeneratorExpressionNode
+{
+ NotNode() {}
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ if (*parameters.begin() != "0" && *parameters.begin() != "1")
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<NOT> parameter must resolve to exactly one '0' or '1' value.");
+ return std::string();
+ }
+ return *parameters.begin() == "0" ? "1" : "0";
+ }
+} notNode;
+
+//----------------------------------------------------------------------------
+static const struct BoolNode : public cmGeneratorExpressionNode
+{
+ BoolNode() {}
+
+ virtual int NumExpectedParameters() const { return 1; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return !cmSystemTools::IsOff(parameters.begin()->c_str()) ? "1" : "0";
+ }
+} boolNode;
+
+//----------------------------------------------------------------------------
+static const struct StrEqualNode : public cmGeneratorExpressionNode
+{
+ StrEqualNode() {}
+
+ virtual int NumExpectedParameters() const { return 2; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return *parameters.begin() == parameters[1] ? "1" : "0";
+ }
+} strEqualNode;
+
+//----------------------------------------------------------------------------
+static const struct EqualNode : public cmGeneratorExpressionNode
+{
+ EqualNode() {}
+
+ virtual int NumExpectedParameters() const { return 2; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ char *pEnd;
+
+ int base = 0;
+ bool flipSign = false;
+
+ const char *lhs = parameters[0].c_str();
+ if (cmHasLiteralPrefix(lhs, "0b") || cmHasLiteralPrefix(lhs, "0B"))
+ {
+ base = 2;
+ lhs += 2;
+ }
+ if (cmHasLiteralPrefix(lhs, "-0b") || cmHasLiteralPrefix(lhs, "-0B"))
+ {
+ base = 2;
+ lhs += 3;
+ flipSign = true;
+ }
+ if (cmHasLiteralPrefix(lhs, "+0b") || cmHasLiteralPrefix(lhs, "+0B"))
+ {
+ base = 2;
+ lhs += 3;
+ }
+
+ long lnum = strtol(lhs, &pEnd, base);
+ if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<EQUAL> parameter " + parameters[0] + " is not a valid integer.");
+ return std::string();
+ }
+
+ if (flipSign)
+ {
+ lnum = -lnum;
+ }
+
+ base = 0;
+ flipSign = false;
+
+ const char *rhs = parameters[1].c_str();
+ if (cmHasLiteralPrefix(rhs, "0b") || cmHasLiteralPrefix(rhs, "0B"))
+ {
+ base = 2;
+ rhs += 2;
+ }
+ if (cmHasLiteralPrefix(rhs, "-0b") || cmHasLiteralPrefix(rhs, "-0B"))
+ {
+ base = 2;
+ rhs += 3;
+ flipSign = true;
+ }
+ if (cmHasLiteralPrefix(rhs, "+0b") || cmHasLiteralPrefix(rhs, "+0B"))
+ {
+ base = 2;
+ rhs += 3;
+ }
+
+ long rnum = strtol(rhs, &pEnd, base);
+ if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<EQUAL> parameter " + parameters[1] + " is not a valid integer.");
+ return std::string();
+ }
+
+ if (flipSign)
+ {
+ rnum = -rnum;
+ }
+
+ return lnum == rnum ? "1" : "0";
+ }
+} equalNode;
+
+//----------------------------------------------------------------------------
+static const struct LowerCaseNode : public cmGeneratorExpressionNode
+{
+ LowerCaseNode() {}
+
+ bool AcceptsArbitraryContentParameter() const { return true; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return cmSystemTools::LowerCase(parameters.front());
+ }
+} lowerCaseNode;
+
+//----------------------------------------------------------------------------
+static const struct UpperCaseNode : public cmGeneratorExpressionNode
+{
+ UpperCaseNode() {}
+
+ bool AcceptsArbitraryContentParameter() const { return true; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return cmSystemTools::UpperCase(parameters.front());
+ }
+} upperCaseNode;
+
+//----------------------------------------------------------------------------
+static const struct MakeCIdentifierNode : public cmGeneratorExpressionNode
+{
+ MakeCIdentifierNode() {}
+
+ bool AcceptsArbitraryContentParameter() const { return true; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return cmSystemTools::MakeCidentifier(parameters.front().c_str());
+ }
+} makeCIdentifierNode;
+
+//----------------------------------------------------------------------------
+static const struct Angle_RNode : public cmGeneratorExpressionNode
+{
+ Angle_RNode() {}
+
+ virtual int NumExpectedParameters() const { return 0; }
+
+ std::string Evaluate(const std::vector<std::string> &,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return ">";
+ }
+} angle_rNode;
+
+//----------------------------------------------------------------------------
+static const struct CommaNode : public cmGeneratorExpressionNode
+{
+ CommaNode() {}
+
+ virtual int NumExpectedParameters() const { return 0; }
+
+ std::string Evaluate(const std::vector<std::string> &,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return ",";
+ }
+} commaNode;
+
+//----------------------------------------------------------------------------
+static const struct SemicolonNode : public cmGeneratorExpressionNode
+{
+ SemicolonNode() {}
+
+ virtual int NumExpectedParameters() const { return 0; }
+
+ std::string Evaluate(const std::vector<std::string> &,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return ";";
+ }
+} semicolonNode;
+
+//----------------------------------------------------------------------------
+struct CompilerIdNode : public cmGeneratorExpressionNode
+{
+ CompilerIdNode() {}
+
+ virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
+
+ std::string EvaluateWithLanguage(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *,
+ const std::string &lang) const
+ {
+ const char *compilerId =
+ context->Makefile->GetSafeDefinition("CMAKE_" + lang + "_COMPILER_ID");
+ if (parameters.size() == 0)
+ {
+ return compilerId ? compilerId : "";
+ }
+ static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$");
+ if (!compilerIdValidator.find(*parameters.begin()))
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "Expression syntax not recognized.");
+ return std::string();
+ }
+ if (!compilerId)
+ {
+ return parameters.front().empty() ? "1" : "0";
+ }
+
+ if (strcmp(parameters.begin()->c_str(), compilerId) == 0)
+ {
+ return "1";
+ }
+
+ if (cmsysString_strcasecmp(parameters.begin()->c_str(), compilerId) == 0)
+ {
+ switch(context->Makefile->GetPolicyStatus(cmPolicies::CMP0044))
+ {
+ case cmPolicies::WARN:
+ {
+ cmOStringStream e;
+ e << context->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0044);
+ context->Makefile->GetCMakeInstance()
+ ->IssueMessage(cmake::AUTHOR_WARNING,
+ e.str(), context->Backtrace);
+ }
+ case cmPolicies::OLD:
+ return "1";
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ break;
+ }
+ }
+ return "0";
+ }
+};
+
+//----------------------------------------------------------------------------
+static const struct CCompilerIdNode : public CompilerIdNode
+{
+ CCompilerIdNode() {}
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+ {
+ if (!context->HeadTarget)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<C_COMPILER_ID> may only be used with binary targets. It may "
+ "not be used with add_custom_command or add_custom_target.");
+ return std::string();
+ }
+ return this->EvaluateWithLanguage(parameters, context, content,
+ dagChecker, "C");
+ }
+} cCompilerIdNode;
+
+//----------------------------------------------------------------------------
+static const struct CXXCompilerIdNode : public CompilerIdNode
+{
+ CXXCompilerIdNode() {}
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+ {
+ if (!context->HeadTarget)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<CXX_COMPILER_ID> may only be used with binary targets. It may "
+ "not be used with add_custom_command or add_custom_target.");
+ return std::string();
+ }
+ return this->EvaluateWithLanguage(parameters, context, content,
+ dagChecker, "CXX");
+ }
+} cxxCompilerIdNode;
+
+//----------------------------------------------------------------------------
+struct CompilerVersionNode : public cmGeneratorExpressionNode
+{
+ CompilerVersionNode() {}
+
+ virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
+
+ std::string EvaluateWithLanguage(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *,
+ const std::string &lang) const
+ {
+ const char *compilerVersion = context->Makefile->GetSafeDefinition(
+ "CMAKE_" + lang + "_COMPILER_VERSION");
+ if (parameters.size() == 0)
+ {
+ return compilerVersion ? compilerVersion : "";
+ }
+
+ static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$");
+ if (!compilerIdValidator.find(*parameters.begin()))
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "Expression syntax not recognized.");
+ return std::string();
+ }
+ if (!compilerVersion)
+ {
+ return parameters.front().empty() ? "1" : "0";
+ }
+
+ return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
+ parameters.begin()->c_str(),
+ compilerVersion) ? "1" : "0";
+ }
+};
+
+//----------------------------------------------------------------------------
+static const struct CCompilerVersionNode : public CompilerVersionNode
+{
+ CCompilerVersionNode() {}
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+ {
+ if (!context->HeadTarget)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<C_COMPILER_VERSION> may only be used with binary targets. It "
+ "may not be used with add_custom_command or add_custom_target.");
+ return std::string();
+ }
+ return this->EvaluateWithLanguage(parameters, context, content,
+ dagChecker, "C");
+ }
+} cCompilerVersionNode;
+
+//----------------------------------------------------------------------------
+static const struct CxxCompilerVersionNode : public CompilerVersionNode
+{
+ CxxCompilerVersionNode() {}
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+ {
+ if (!context->HeadTarget)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<CXX_COMPILER_VERSION> may only be used with binary targets. It "
+ "may not be used with add_custom_command or add_custom_target.");
+ return std::string();
+ }
+ return this->EvaluateWithLanguage(parameters, context, content,
+ dagChecker, "CXX");
+ }
+} cxxCompilerVersionNode;
+
+
+//----------------------------------------------------------------------------
+struct PlatformIdNode : public cmGeneratorExpressionNode
+{
+ PlatformIdNode() {}
+
+ virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ const char *platformId =
+ context->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME");
+ if (parameters.size() == 0)
+ {
+ return platformId ? platformId : "";
+ }
+
+ if (!platformId)
+ {
+ return parameters.front().empty() ? "1" : "0";
+ }
+
+ if (strcmp(parameters.begin()->c_str(), platformId) == 0)
+ {
+ return "1";
+ }
+ return "0";
+ }
+} platformIdNode;
+
+//----------------------------------------------------------------------------
+static const struct VersionGreaterNode : public cmGeneratorExpressionNode
+{
+ VersionGreaterNode() {}
+
+ virtual int NumExpectedParameters() const { return 2; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER,
+ parameters.front().c_str(),
+ parameters[1].c_str()) ? "1" : "0";
+ }
+} versionGreaterNode;
+
+//----------------------------------------------------------------------------
+static const struct VersionLessNode : public cmGeneratorExpressionNode
+{
+ VersionLessNode() {}
+
+ virtual int NumExpectedParameters() const { return 2; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
+ parameters.front().c_str(),
+ parameters[1].c_str()) ? "1" : "0";
+ }
+} versionLessNode;
+
+//----------------------------------------------------------------------------
+static const struct VersionEqualNode : public cmGeneratorExpressionNode
+{
+ VersionEqualNode() {}
+
+ virtual int NumExpectedParameters() const { return 2; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
+ parameters.front().c_str(),
+ parameters[1].c_str()) ? "1" : "0";
+ }
+} versionEqualNode;
+
+//----------------------------------------------------------------------------
+static const struct LinkOnlyNode : public cmGeneratorExpressionNode
+{
+ LinkOnlyNode() {}
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+ {
+ if(!dagChecker->GetTransitivePropertiesOnly())
+ {
+ return parameters.front();
+ }
+ return "";
+ }
+} linkOnlyNode;
+
+//----------------------------------------------------------------------------
+static const struct ConfigurationNode : public cmGeneratorExpressionNode
+{
+ ConfigurationNode() {}
+
+ virtual int NumExpectedParameters() const { return 0; }
+
+ std::string Evaluate(const std::vector<std::string> &,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ context->HadContextSensitiveCondition = true;
+ return context->Config;
+ }
+} configurationNode;
+
+//----------------------------------------------------------------------------
+static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
+{
+ ConfigurationTestNode() {}
+
+ virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ if (parameters.empty())
+ {
+ return configurationNode.Evaluate(parameters, context, content, 0);
+ }
+ static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$");
+ if (!configValidator.find(*parameters.begin()))
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "Expression syntax not recognized.");
+ return std::string();
+ }
+ context->HadContextSensitiveCondition = true;
+ if (context->Config.empty())
+ {
+ return parameters.front().empty() ? "1" : "0";
+ }
+
+ if (cmsysString_strcasecmp(parameters.begin()->c_str(),
+ context->Config.c_str()) == 0)
+ {
+ return "1";
+ }
+
+ if (context->CurrentTarget
+ && context->CurrentTarget->IsImported())
+ {
+ const char* loc = 0;
+ const char* imp = 0;
+ std::string suffix;
+ if (context->CurrentTarget->GetMappedConfig(context->Config,
+ &loc,
+ &imp,
+ suffix))
+ {
+ // This imported target has an appropriate location
+ // for this (possibly mapped) config.
+ // Check if there is a proper config mapping for the tested config.
+ std::vector<std::string> mappedConfigs;
+ std::string mapProp = "MAP_IMPORTED_CONFIG_";
+ mapProp += cmSystemTools::UpperCase(context->Config);
+ if(const char* mapValue =
+ context->CurrentTarget->GetProperty(mapProp))
+ {
+ cmSystemTools::ExpandListArgument(cmSystemTools::UpperCase(mapValue),
+ mappedConfigs);
+ return std::find(mappedConfigs.begin(), mappedConfigs.end(),
+ cmSystemTools::UpperCase(parameters.front()))
+ != mappedConfigs.end() ? "1" : "0";
+ }
+ }
+ }
+ return "0";
+ }
+} configurationTestNode;
+
+static const struct JoinNode : public cmGeneratorExpressionNode
+{
+ JoinNode() {}
+
+ virtual int NumExpectedParameters() const { return 2; }
+
+ virtual bool AcceptsArbitraryContentParameter() const { return true; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ std::string result;
+
+ std::vector<std::string> list;
+ cmSystemTools::ExpandListArgument(parameters.front(), list);
+ std::string sep;
+ for(std::vector<std::string>::const_iterator li = list.begin();
+ li != list.end(); ++li)
+ {
+ result += sep + *li;
+ sep = parameters[1];
+ }
+ return result;
+ }
+} joinNode;
+
+#define TRANSITIVE_PROPERTY_NAME(PROPERTY) \
+ , "INTERFACE_" #PROPERTY
+
+//----------------------------------------------------------------------------
+static const char* targetPropertyTransitiveWhitelist[] = {
+ 0
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_NAME)
+};
+
+#undef TRANSITIVE_PROPERTY_NAME
+
+template <typename T>
+std::string
+getLinkedTargetsContent(
+ std::vector<T> const &libraries,
+ cmTarget const* target,
+ cmTarget const* headTarget,
+ cmGeneratorExpressionContext *context,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ const std::string &interfacePropertyName)
+{
+ std::string linkedTargetsContent;
+ std::string sep;
+ std::string depString;
+ for (typename std::vector<T>::const_iterator it = libraries.begin();
+ it != libraries.end(); ++it)
+ {
+ // Broken code can have a target in its own link interface.
+ // Don't follow such link interface entries so as not to create a
+ // self-referencing loop.
+ if (it->Target && it->Target != target)
+ {
+ depString +=
+ sep + "$<TARGET_PROPERTY:" +
+ it->Target->GetName() + "," + interfacePropertyName + ">";
+ sep = ";";
+ }
+ }
+ if(!depString.empty())
+ {
+ cmGeneratorExpression ge(&context->Backtrace);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(depString);
+ linkedTargetsContent = cge->Evaluate(target->GetMakefile(),
+ context->Config,
+ context->Quiet,
+ headTarget,
+ target,
+ dagChecker);
+ if (cge->GetHadContextSensitiveCondition())
+ {
+ context->HadContextSensitiveCondition = true;
+ }
+ if (cge->GetHadHeadSensitiveCondition())
+ {
+ context->HadHeadSensitiveCondition = true;
+ }
+ }
+ linkedTargetsContent =
+ cmGeneratorExpression::StripEmptyListElements(linkedTargetsContent);
+ return linkedTargetsContent;
+}
+
+//----------------------------------------------------------------------------
+static const struct TargetPropertyNode : public cmGeneratorExpressionNode
+{
+ TargetPropertyNode() {}
+
+ // This node handles errors on parameter count itself.
+ virtual int NumExpectedParameters() const { return OneOrMoreParameters; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *dagCheckerParent
+ ) const
+ {
+ if (parameters.size() != 1 && parameters.size() != 2)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_PROPERTY:...> expression requires one or two parameters");
+ return std::string();
+ }
+ static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
+
+ cmTarget const* target = context->HeadTarget;
+ std::string propertyName = *parameters.begin();
+
+ if (parameters.size() == 1)
+ {
+ context->HadHeadSensitiveCondition = true;
+ }
+ if (!target && parameters.size() == 1)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_PROPERTY:prop> may only be used with binary targets. "
+ "It may not be used with add_custom_command or add_custom_target. "
+ "Specify the target to read a property from using the "
+ "$<TARGET_PROPERTY:tgt,prop> signature instead.");
+ return std::string();
+ }
+
+ if (parameters.size() == 2)
+ {
+ if (parameters.begin()->empty() && parameters[1].empty())
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
+ "target name and property name.");
+ return std::string();
+ }
+ if (parameters.begin()->empty())
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
+ "target name.");
+ return std::string();
+ }
+
+ std::string targetName = parameters.front();
+ propertyName = parameters[1];
+ if (!cmGeneratorExpression::IsValidTargetName(targetName))
+ {
+ if (!propertyNameValidator.find(propertyName.c_str()))
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "Target name and property name not supported.");
+ return std::string();
+ }
+ ::reportError(context, content->GetOriginalExpression(),
+ "Target name not supported.");
+ return std::string();
+ }
+ if(propertyName == "ALIASED_TARGET")
+ {
+ if(context->Makefile->IsAlias(targetName))
+ {
+ if(cmTarget* tgt = context->Makefile->FindTargetToUse(targetName))
+ {
+ return tgt->GetName();
+ }
+ }
+ return "";
+ }
+ target = context->Makefile->FindTargetToUse(targetName);
+
+ if (!target)
+ {
+ cmOStringStream e;
+ e << "Target \""
+ << targetName
+ << "\" not found.";
+ reportError(context, content->GetOriginalExpression(), e.str());
+ return std::string();
+ }
+ context->AllTargets.insert(target);
+ }
+
+ if (target == context->HeadTarget)
+ {
+ // Keep track of the properties seen while processing.
+ // The evaluation of the LINK_LIBRARIES generator expressions
+ // will check this to ensure that properties have one consistent
+ // value for all evaluations.
+ context->SeenTargetProperties.insert(propertyName);
+ }
+
+ if (propertyName.empty())
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_PROPERTY:...> expression requires a non-empty property "
+ "name.");
+ return std::string();
+ }
+
+ if (!propertyNameValidator.find(propertyName))
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "Property name not supported.");
+ return std::string();
+ }
+
+ assert(target);
+
+ if (propertyName == "LINKER_LANGUAGE")
+ {
+ if (target->LinkLanguagePropagatesToDependents() &&
+ dagCheckerParent && (dagCheckerParent->EvaluatingLinkLibraries()
+ || dagCheckerParent->EvaluatingSources()))
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "LINKER_LANGUAGE target property can not be used while evaluating "
+ "link libraries for a static library");
+ return std::string();
+ }
+ return target->GetLinkerLanguage(context->Config);
+ }
+
+ cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
+ target->GetName(),
+ propertyName,
+ content,
+ dagCheckerParent);
+
+ switch (dagChecker.Check())
+ {
+ case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
+ dagChecker.ReportError(context, content->GetOriginalExpression());
+ return std::string();
+ case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
+ // No error. We just skip cyclic references.
+ return std::string();
+ case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
+ for (size_t i = 1;
+ i < cmArraySize(targetPropertyTransitiveWhitelist);
+ ++i)
+ {
+ if (targetPropertyTransitiveWhitelist[i] == propertyName)
+ {
+ // No error. We're not going to find anything new here.
+ return std::string();
+ }
+ }
+ case cmGeneratorExpressionDAGChecker::DAG:
+ break;
+ }
+
+ const char *prop = target->GetProperty(propertyName);
+
+ if (dagCheckerParent)
+ {
+ if (dagCheckerParent->EvaluatingLinkLibraries())
+ {
+#define TRANSITIVE_PROPERTY_COMPARE(PROPERTY) \
+ (#PROPERTY == propertyName || "INTERFACE_" #PROPERTY == propertyName) ||
+ if (CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_COMPARE)
+ false)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_PROPERTY:...> expression in link libraries "
+ "evaluation depends on target property which is transitive "
+ "over the link libraries, creating a recursion.");
+ return std::string();
+ }
+#undef TRANSITIVE_PROPERTY_COMPARE
+
+ if(!prop)
+ {
+ return std::string();
+ }
+ }
+ else
+ {
+#define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) \
+ dagCheckerParent->METHOD () ||
+
+ assert(
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
+ ASSERT_TRANSITIVE_PROPERTY_METHOD)
+ false);
+#undef ASSERT_TRANSITIVE_PROPERTY_METHOD
+ }
+ }
+
+ std::string linkedTargetsContent;
+
+ std::string interfacePropertyName;
+ bool isInterfaceProperty = false;
+
+#define POPULATE_INTERFACE_PROPERTY_NAME(prop) \
+ if (propertyName == #prop) \
+ { \
+ interfacePropertyName = "INTERFACE_" #prop; \
+ } \
+ else if (propertyName == "INTERFACE_" #prop) \
+ { \
+ interfacePropertyName = "INTERFACE_" #prop; \
+ isInterfaceProperty = true; \
+ } \
+ else
+
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
+ // Note that the above macro terminates with an else
+ /* else */ if (cmHasLiteralPrefix(propertyName.c_str(),
+ "COMPILE_DEFINITIONS_"))
+ {
+ cmPolicies::PolicyStatus polSt =
+ context->Makefile->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
+ ? context->HeadTarget : target;
+
+ if(isInterfaceProperty)
+ {
+ if(cmTarget::LinkInterfaceLibraries const* iface =
+ target->GetLinkInterfaceLibraries(context->Config, headTarget, true))
+ {
+ linkedTargetsContent =
+ getLinkedTargetsContent(iface->Libraries, target,
+ headTarget,
+ context, &dagChecker,
+ interfacePropertyName);
+ }
+ }
+ else if(!interfacePropertyName.empty())
+ {
+ if(cmTarget::LinkImplementationLibraries const* impl =
+ target->GetLinkImplementationLibraries(context->Config))
+ {
+ linkedTargetsContent =
+ getLinkedTargetsContent(impl->Libraries, target,
+ target,
+ context, &dagChecker,
+ interfacePropertyName);
+ }
+ }
+
+ if (!prop)
+ {
+ if (target->IsImported()
+ || target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ return linkedTargetsContent;
+ }
+ if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
+ context->Config))
+ {
+ context->HadContextSensitiveCondition = true;
+ return target->GetLinkInterfaceDependentBoolProperty(
+ propertyName,
+ context->Config) ? "1" : "0";
+ }
+ if (target->IsLinkInterfaceDependentStringProperty(propertyName,
+ context->Config))
+ {
+ context->HadContextSensitiveCondition = true;
+ const char *propContent =
+ target->GetLinkInterfaceDependentStringProperty(
+ propertyName,
+ context->Config);
+ return propContent ? propContent : "";
+ }
+ if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
+ context->Config))
+ {
+ context->HadContextSensitiveCondition = true;
+ const char *propContent =
+ target->GetLinkInterfaceDependentNumberMinProperty(
+ propertyName,
+ context->Config);
+ return propContent ? propContent : "";
+ }
+ if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
+ context->Config))
+ {
+ context->HadContextSensitiveCondition = true;
+ const char *propContent =
+ target->GetLinkInterfaceDependentNumberMaxProperty(
+ propertyName,
+ context->Config);
+ return propContent ? propContent : "";
+ }
+
+ return linkedTargetsContent;
+ }
+
+ if (!target->IsImported()
+ && dagCheckerParent && !dagCheckerParent->EvaluatingLinkLibraries())
+ {
+ if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
+ context->Config))
+ {
+ context->HadContextSensitiveCondition = true;
+ const char *propContent =
+ target->GetLinkInterfaceDependentNumberMinProperty(
+ propertyName,
+ context->Config);
+ return propContent ? propContent : "";
+ }
+ if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
+ context->Config))
+ {
+ context->HadContextSensitiveCondition = true;
+ const char *propContent =
+ target->GetLinkInterfaceDependentNumberMaxProperty(
+ propertyName,
+ context->Config);
+ return propContent ? propContent : "";
+ }
+ }
+ if(!interfacePropertyName.empty())
+ {
+ cmGeneratorExpression ge(&context->Backtrace);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
+ cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem);
+ std::string result = cge->Evaluate(context->Makefile,
+ context->Config,
+ context->Quiet,
+ headTarget,
+ target,
+ &dagChecker);
+
+ if (cge->GetHadContextSensitiveCondition())
+ {
+ context->HadContextSensitiveCondition = true;
+ }
+ if (cge->GetHadHeadSensitiveCondition())
+ {
+ context->HadHeadSensitiveCondition = true;
+ }
+ if (!linkedTargetsContent.empty())
+ {
+ result += (result.empty() ? "" : ";") + linkedTargetsContent;
+ }
+ return result;
+ }
+ return prop;
+ }
+} targetPropertyNode;
+
+//----------------------------------------------------------------------------
+static const struct TargetNameNode : public cmGeneratorExpressionNode
+{
+ TargetNameNode() {}
+
+ virtual bool GeneratesContent() const { return true; }
+
+ virtual bool AcceptsArbitraryContentParameter() const { return true; }
+ virtual bool RequiresLiteralInput() const { return true; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return parameters.front();
+ }
+
+ virtual int NumExpectedParameters() const { return 1; }
+
+} targetNameNode;
+
+//----------------------------------------------------------------------------
+static const struct TargetObjectsNode : public cmGeneratorExpressionNode
+{
+ TargetObjectsNode() {}
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ if (!context->EvaluateForBuildsystem)
+ {
+ cmOStringStream e;
+ e << "The evaluation of the TARGET_OBJECTS generator expression "
+ "is only suitable for consumption by CMake. It is not suitable "
+ "for writing out elsewhere.";
+ reportError(context, content->GetOriginalExpression(), e.str());
+ return std::string();
+ }
+
+ std::string tgtName = parameters.front();
+ cmGeneratorTarget* gt =
+ context->Makefile->FindGeneratorTargetToUse(tgtName.c_str());
+ if (!gt)
+ {
+ cmOStringStream e;
+ e << "Objects of target \"" << tgtName
+ << "\" referenced but no such target exists.";
+ reportError(context, content->GetOriginalExpression(), e.str());
+ return std::string();
+ }
+ if (gt->GetType() != cmTarget::OBJECT_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "Objects of target \"" << tgtName
+ << "\" referenced but is not an OBJECT library.";
+ reportError(context, content->GetOriginalExpression(), e.str());
+ return std::string();
+ }
+
+ std::vector<cmSourceFile const*> objectSources;
+ gt->GetObjectSources(objectSources, context->Config);
+ std::map<cmSourceFile const*, std::string> mapping;
+
+ for(std::vector<cmSourceFile const*>::const_iterator it
+ = objectSources.begin(); it != objectSources.end(); ++it)
+ {
+ mapping[*it];
+ }
+
+ gt->LocalGenerator->ComputeObjectFilenames(mapping, gt);
+
+ std::string obj_dir = gt->ObjectDirectory;
+ std::string result;
+ const char* sep = "";
+ for(std::map<cmSourceFile const*, std::string>::const_iterator it
+ = mapping.begin(); it != mapping.end(); ++it)
+ {
+ assert(!it->second.empty());
+ result += sep;
+ std::string objFile = obj_dir + it->second;
+ cmSourceFile* sf = context->Makefile->GetOrCreateSource(objFile, true);
+ sf->SetObjectLibrary(tgtName);
+ sf->SetProperty("EXTERNAL_OBJECT", "1");
+ result += objFile;
+ sep = ";";
+ }
+ return result;
+ }
+} targetObjectsNode;
+
+//----------------------------------------------------------------------------
+static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
+{
+ CompileFeaturesNode() {}
+
+ virtual int NumExpectedParameters() const { return OneOrMoreParameters; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+ {
+ cmTarget const* target = context->HeadTarget;
+ if (!target)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<COMPILE_FEATURE> may only be used with binary targets. It may "
+ "not be used with add_custom_command or add_custom_target.");
+ return std::string();
+ }
+ context->HadHeadSensitiveCondition = true;
+
+ typedef std::map<std::string, std::vector<std::string> > LangMap;
+ static LangMap availableFeatures;
+
+ LangMap testedFeatures;
+
+ for (std::vector<std::string>::const_iterator it = parameters.begin();
+ it != parameters.end(); ++it)
+ {
+ std::string error;
+ std::string lang;
+ if (!context->Makefile->CompileFeatureKnown(context->HeadTarget,
+ *it, lang, &error))
+ {
+ reportError(context, content->GetOriginalExpression(), error);
+ return std::string();
+ }
+ testedFeatures[lang].push_back(*it);
+
+ if (availableFeatures.find(lang) == availableFeatures.end())
+ {
+ const char* featuresKnown
+ = context->Makefile->CompileFeaturesAvailable(lang, &error);
+ if (!featuresKnown)
+ {
+ reportError(context, content->GetOriginalExpression(), error);
+ return std::string();
+ }
+ cmSystemTools::ExpandListArgument(featuresKnown,
+ availableFeatures[lang]);
+ }
+ }
+
+ bool evalLL = dagChecker && dagChecker->EvaluatingLinkLibraries();
+
+ std::string result;
+
+ for (LangMap::const_iterator lit = testedFeatures.begin();
+ lit != testedFeatures.end(); ++lit)
+ {
+ for (std::vector<std::string>::const_iterator it = lit->second.begin();
+ it != lit->second.end(); ++it)
+ {
+ if (!context->Makefile->HaveFeatureAvailable(target,
+ lit->first, *it))
+ {
+ if (evalLL)
+ {
+ const char* l = target->GetProperty(lit->first + "_STANDARD");
+ if (!l)
+ {
+ l = context->Makefile
+ ->GetDefinition("CMAKE_" + lit->first + "_STANDARD_DEFAULT");
+ }
+ assert(l);
+ context->MaxLanguageStandard[target][lit->first] = l;
+ }
+ else
+ {
+ return "0";
+ }
+ }
+ }
+ }
+ return "1";
+ }
+} compileFeaturesNode;
+
+//----------------------------------------------------------------------------
+static const char* targetPolicyWhitelist[] = {
+ 0
+#define TARGET_POLICY_STRING(POLICY) \
+ , #POLICY
+
+ CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)
+
+#undef TARGET_POLICY_STRING
+};
+
+cmPolicies::PolicyStatus statusForTarget(cmTarget const* tgt,
+ const char *policy)
+{
+#define RETURN_POLICY(POLICY) \
+ if (strcmp(policy, #POLICY) == 0) \
+ { \
+ return tgt->GetPolicyStatus ## POLICY (); \
+ } \
+
+ CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY)
+
+#undef RETURN_POLICY
+
+ assert("!Unreachable code. Not a valid policy");
+ return cmPolicies::WARN;
+}
+
+cmPolicies::PolicyID policyForString(const char *policy_id)
+{
+#define RETURN_POLICY_ID(POLICY_ID) \
+ if (strcmp(policy_id, #POLICY_ID) == 0) \
+ { \
+ return cmPolicies:: POLICY_ID; \
+ } \
+
+ CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY_ID)
+
+#undef RETURN_POLICY_ID
+
+ assert("!Unreachable code. Not a valid policy");
+ return cmPolicies::CMP0002;
+}
+
+//----------------------------------------------------------------------------
+static const struct TargetPolicyNode : public cmGeneratorExpressionNode
+{
+ TargetPolicyNode() {}
+
+ virtual int NumExpectedParameters() const { return 1; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context ,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ if (!context->HeadTarget)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_POLICY:prop> may only be used with binary targets. It "
+ "may not be used with add_custom_command or add_custom_target.");
+ return std::string();
+ }
+
+ context->HadContextSensitiveCondition = true;
+ context->HadHeadSensitiveCondition = true;
+
+ for (size_t i = 1; i < cmArraySize(targetPolicyWhitelist); ++i)
+ {
+ const char *policy = targetPolicyWhitelist[i];
+ if (parameters.front() == policy)
+ {
+ cmMakefile *mf = context->HeadTarget->GetMakefile();
+ switch(statusForTarget(context->HeadTarget, policy))
+ {
+ case cmPolicies::WARN:
+ mf->IssueMessage(cmake::AUTHOR_WARNING,
+ mf->GetPolicies()->
+ GetPolicyWarning(policyForString(policy)));
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::OLD:
+ return "0";
+ case cmPolicies::NEW:
+ return "1";
+ }
+ }
+ }
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_POLICY:prop> may only be used with a limited number of "
+ "policies. Currently it may be used with the following policies:\n"
+
+#define STRINGIFY_HELPER(X) #X
+#define STRINGIFY(X) STRINGIFY_HELPER(X)
+
+#define TARGET_POLICY_LIST_ITEM(POLICY) \
+ " * " STRINGIFY(POLICY) "\n"
+
+ CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_LIST_ITEM)
+
+#undef TARGET_POLICY_LIST_ITEM
+ );
+ return std::string();
+ }
+
+} targetPolicyNode;
+
+//----------------------------------------------------------------------------
+static const struct InstallPrefixNode : public cmGeneratorExpressionNode
+{
+ InstallPrefixNode() {}
+
+ virtual bool GeneratesContent() const { return true; }
+ virtual int NumExpectedParameters() const { return 0; }
+
+ std::string Evaluate(const std::vector<std::string> &,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "INSTALL_PREFIX is a marker for install(EXPORT) only. It "
+ "should never be evaluated.");
+ return std::string();
+ }
+
+} installPrefixNode;
+
+//----------------------------------------------------------------------------
+class ArtifactNameTag;
+class ArtifactLinkerTag;
+class ArtifactSonameTag;
+class ArtifactPdbTag;
+
+class ArtifactPathTag;
+class ArtifactDirTag;
+class ArtifactNameTag;
+
+//----------------------------------------------------------------------------
+template<typename ArtifactT>
+struct TargetFilesystemArtifactResultCreator
+{
+ static std::string Create(cmTarget* target,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content);
+};
+
+//----------------------------------------------------------------------------
+template<>
+struct TargetFilesystemArtifactResultCreator<ArtifactSonameTag>
+{
+ static std::string Create(cmTarget* target,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content)
+ {
+ // The target soname file (.so.1).
+ 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)
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "TARGET_SONAME_FILE is allowed only for "
+ "SHARED libraries.");
+ return std::string();
+ }
+ std::string result = target->GetDirectory(context->Config);
+ result += "/";
+ result += target->GetSOName(context->Config);
+ return result;
+ }
+};
+
+//----------------------------------------------------------------------------
+template<>
+struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
+{
+ static std::string Create(cmTarget* target,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content)
+ {
+ std::string language = target->GetLinkerLanguage(context->Config);
+
+ std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
+
+ if(!context->Makefile->IsOn(pdbSupportVar))
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "TARGET_PDB_FILE is not supported by the target linker.");
+ return std::string();
+ }
+
+ cmTarget::TargetType targetType = target->GetType();
+
+ if(targetType != cmTarget::SHARED_LIBRARY &&
+ targetType != cmTarget::MODULE_LIBRARY &&
+ targetType != cmTarget::EXECUTABLE)
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "TARGET_PDB_FILE is allowed only for "
+ "targets with linker created artifacts.");
+ return std::string();
+ }
+
+ std::string result = target->GetPDBDirectory(context->Config);
+ result += "/";
+ result += target->GetPDBName(context->Config);
+ return result;
+ }
+};
+
+//----------------------------------------------------------------------------
+template<>
+struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
+{
+ static std::string Create(cmTarget* target,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content)
+ {
+ // The file used to link to the target (.so, .lib, .a).
+ if(!target->IsLinkable())
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "TARGET_LINKER_FILE is allowed only for libraries and "
+ "executables with ENABLE_EXPORTS.");
+ return std::string();
+ }
+ return target->GetFullPath(context->Config,
+ target->HasImportLibrary());
+ }
+};
+
+//----------------------------------------------------------------------------
+template<>
+struct TargetFilesystemArtifactResultCreator<ArtifactNameTag>
+{
+ static std::string Create(cmTarget* target,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *)
+ {
+ return target->GetFullPath(context->Config, false, true);
+ }
+};
+
+
+//----------------------------------------------------------------------------
+template<typename ArtifactT>
+struct TargetFilesystemArtifactResultGetter
+{
+ static std::string Get(const std::string &result);
+};
+
+//----------------------------------------------------------------------------
+template<>
+struct TargetFilesystemArtifactResultGetter<ArtifactNameTag>
+{
+ static std::string Get(const std::string &result)
+ { return cmSystemTools::GetFilenameName(result); }
+};
+
+//----------------------------------------------------------------------------
+template<>
+struct TargetFilesystemArtifactResultGetter<ArtifactDirTag>
+{
+ static std::string Get(const std::string &result)
+ { return cmSystemTools::GetFilenamePath(result); }
+};
+
+//----------------------------------------------------------------------------
+template<>
+struct TargetFilesystemArtifactResultGetter<ArtifactPathTag>
+{
+ static std::string Get(const std::string &result)
+ { return result; }
+};
+
+//----------------------------------------------------------------------------
+template<typename ArtifactT, typename ComponentT>
+struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
+{
+ TargetFilesystemArtifact() {}
+
+ virtual int NumExpectedParameters() const { return 1; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+ {
+ // Lookup the referenced target.
+ std::string name = *parameters.begin();
+
+ if (!cmGeneratorExpression::IsValidTargetName(name))
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "Expression syntax not recognized.");
+ return std::string();
+ }
+ cmTarget* target = context->Makefile->FindTargetToUse(name);
+ if(!target)
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "No target \"" + name + "\"");
+ return std::string();
+ }
+ if(target->GetType() >= cmTarget::OBJECT_LIBRARY &&
+ target->GetType() != cmTarget::UNKNOWN_LIBRARY)
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "Target \"" + name + "\" is not an executable or library.");
+ return std::string();
+ }
+ if (dagChecker && (dagChecker->EvaluatingLinkLibraries(name.c_str())
+ || (dagChecker->EvaluatingSources()
+ && name == dagChecker->TopTarget())))
+ {
+ ::reportError(context, content->GetOriginalExpression(),
+ "Expressions which require the linker language may not "
+ "be used while evaluating link libraries");
+ return std::string();
+ }
+ context->DependTargets.insert(target);
+ context->AllTargets.insert(target);
+
+ std::string result =
+ TargetFilesystemArtifactResultCreator<ArtifactT>::Create(
+ target,
+ context,
+ content);
+ if (context->HadError)
+ {
+ return std::string();
+ }
+ return
+ TargetFilesystemArtifactResultGetter<ComponentT>::Get(result);
+ }
+};
+
+//----------------------------------------------------------------------------
+template<typename ArtifactT>
+struct TargetFilesystemArtifactNodeGroup
+{
+ TargetFilesystemArtifactNodeGroup()
+ {
+ }
+
+ TargetFilesystemArtifact<ArtifactT, ArtifactPathTag> File;
+ TargetFilesystemArtifact<ArtifactT, ArtifactNameTag> FileName;
+ TargetFilesystemArtifact<ArtifactT, ArtifactDirTag> FileDir;
+};
+
+//----------------------------------------------------------------------------
+static const
+TargetFilesystemArtifactNodeGroup<ArtifactNameTag> targetNodeGroup;
+
+static const
+TargetFilesystemArtifactNodeGroup<ArtifactLinkerTag> targetLinkerNodeGroup;
+
+static const
+TargetFilesystemArtifactNodeGroup<ArtifactSonameTag> targetSoNameNodeGroup;
+
+static const
+TargetFilesystemArtifactNodeGroup<ArtifactPdbTag> targetPdbNodeGroup;
+
+//----------------------------------------------------------------------------
+static const
+cmGeneratorExpressionNode* GetNode(const std::string &identifier)
+{
+ typedef std::map<std::string, const cmGeneratorExpressionNode*> NodeMap;
+ static NodeMap nodeMap;
+ if (nodeMap.empty())
+ {
+ nodeMap["0"] = &zeroNode;
+ nodeMap["1"] = &oneNode;
+ nodeMap["AND"] = &andNode;
+ nodeMap["OR"] = &orNode;
+ nodeMap["NOT"] = &notNode;
+ nodeMap["C_COMPILER_ID"] = &cCompilerIdNode;
+ nodeMap["CXX_COMPILER_ID"] = &cxxCompilerIdNode;
+ nodeMap["VERSION_GREATER"] = &versionGreaterNode;
+ nodeMap["VERSION_LESS"] = &versionLessNode;
+ nodeMap["VERSION_EQUAL"] = &versionEqualNode;
+ nodeMap["C_COMPILER_VERSION"] = &cCompilerVersionNode;
+ nodeMap["CXX_COMPILER_VERSION"] = &cxxCompilerVersionNode;
+ nodeMap["PLATFORM_ID"] = &platformIdNode;
+ nodeMap["COMPILE_FEATURES"] = &compileFeaturesNode;
+ nodeMap["CONFIGURATION"] = &configurationNode;
+ nodeMap["CONFIG"] = &configurationTestNode;
+ nodeMap["TARGET_FILE"] = &targetNodeGroup.File;
+ nodeMap["TARGET_LINKER_FILE"] = &targetLinkerNodeGroup.File;
+ nodeMap["TARGET_SONAME_FILE"] = &targetSoNameNodeGroup.File;
+ nodeMap["TARGET_PDB_FILE"] = &targetPdbNodeGroup.File;
+ nodeMap["TARGET_FILE_NAME"] = &targetNodeGroup.FileName;
+ nodeMap["TARGET_LINKER_FILE_NAME"] = &targetLinkerNodeGroup.FileName;
+ nodeMap["TARGET_SONAME_FILE_NAME"] = &targetSoNameNodeGroup.FileName;
+ nodeMap["TARGET_PDB_FILE_NAME"] = &targetPdbNodeGroup.FileName;
+ nodeMap["TARGET_FILE_DIR"] = &targetNodeGroup.FileDir;
+ nodeMap["TARGET_LINKER_FILE_DIR"] = &targetLinkerNodeGroup.FileDir;
+ nodeMap["TARGET_SONAME_FILE_DIR"] = &targetSoNameNodeGroup.FileDir;
+ nodeMap["TARGET_PDB_FILE_DIR"] = &targetPdbNodeGroup.FileDir;
+ nodeMap["STREQUAL"] = &strEqualNode;
+ nodeMap["EQUAL"] = &equalNode;
+ nodeMap["LOWER_CASE"] = &lowerCaseNode;
+ nodeMap["UPPER_CASE"] = &upperCaseNode;
+ nodeMap["MAKE_C_IDENTIFIER"] = &makeCIdentifierNode;
+ nodeMap["BOOL"] = &boolNode;
+ nodeMap["ANGLE-R"] = &angle_rNode;
+ nodeMap["COMMA"] = &commaNode;
+ nodeMap["SEMICOLON"] = &semicolonNode;
+ nodeMap["TARGET_PROPERTY"] = &targetPropertyNode;
+ nodeMap["TARGET_NAME"] = &targetNameNode;
+ nodeMap["TARGET_OBJECTS"] = &targetObjectsNode;
+ nodeMap["TARGET_POLICY"] = &targetPolicyNode;
+ nodeMap["BUILD_INTERFACE"] = &buildInterfaceNode;
+ nodeMap["INSTALL_INTERFACE"] = &installInterfaceNode;
+ nodeMap["INSTALL_PREFIX"] = &installPrefixNode;
+ nodeMap["JOIN"] = &joinNode;
+ nodeMap["LINK_ONLY"] = &linkOnlyNode;
+ }
+ NodeMap::const_iterator i = nodeMap.find(identifier);
+ if (i == nodeMap.end())
+ {
+ return 0;
+ }
+ return i->second;
+
+}
+
+//----------------------------------------------------------------------------
+GeneratorExpressionContent::GeneratorExpressionContent(
+ const char *startContent,
+ size_t length)
+ : StartContent(startContent), ContentLength(length)
+{
+
+}
+
+//----------------------------------------------------------------------------
+std::string GeneratorExpressionContent::GetOriginalExpression() const
+{
+ return std::string(this->StartContent, this->ContentLength);
+}
+
+//----------------------------------------------------------------------------
+std::string GeneratorExpressionContent::ProcessArbitraryContent(
+ const cmGeneratorExpressionNode *node,
+ const std::string &identifier,
+ cmGeneratorExpressionContext *context,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
+ pit) const
+{
+ std::string result;
+
+ const
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
+ pend = this->ParamChildren.end();
+ for ( ; pit != pend; ++pit)
+ {
+ std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
+ = pit->begin();
+ const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
+ = pit->end();
+ for ( ; it != end; ++it)
+ {
+ if (node->RequiresLiteralInput())
+ {
+ if ((*it)->GetType() != cmGeneratorExpressionEvaluator::Text)
+ {
+ reportError(context, this->GetOriginalExpression(),
+ "$<" + identifier + "> expression requires literal input.");
+ return std::string();
+ }
+ }
+ result += (*it)->Evaluate(context, dagChecker);
+ if (context->HadError)
+ {
+ return std::string();
+ }
+ }
+ if ((pit + 1) != pend)
+ {
+ result += ",";
+ }
+ }
+ if (node->RequiresLiteralInput())
+ {
+ std::vector<std::string> parameters;
+ parameters.push_back(result);
+ return node->Evaluate(parameters, context, this, dagChecker);
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+std::string GeneratorExpressionContent::Evaluate(
+ cmGeneratorExpressionContext *context,
+ cmGeneratorExpressionDAGChecker *dagChecker) const
+{
+ std::string identifier;
+ {
+ std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
+ = this->IdentifierChildren.begin();
+ const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
+ = this->IdentifierChildren.end();
+ for ( ; it != end; ++it)
+ {
+ identifier += (*it)->Evaluate(context, dagChecker);
+ if (context->HadError)
+ {
+ return std::string();
+ }
+ }
+ }
+
+ const cmGeneratorExpressionNode *node = GetNode(identifier);
+
+ if (!node)
+ {
+ reportError(context, this->GetOriginalExpression(),
+ "Expression did not evaluate to a known generator expression");
+ return std::string();
+ }
+
+ if (!node->GeneratesContent())
+ {
+ if (node->NumExpectedParameters() == 1
+ && node->AcceptsArbitraryContentParameter())
+ {
+ if (this->ParamChildren.empty())
+ {
+ reportError(context, this->GetOriginalExpression(),
+ "$<" + identifier + "> expression requires a parameter.");
+ }
+ }
+ else
+ {
+ std::vector<std::string> parameters;
+ this->EvaluateParameters(node, identifier, context, dagChecker,
+ parameters);
+ }
+ return std::string();
+ }
+
+ std::vector<std::string> parameters;
+ this->EvaluateParameters(node, identifier, context, dagChecker, parameters);
+ if (context->HadError)
+ {
+ return std::string();
+ }
+
+ return node->Evaluate(parameters, context, this, dagChecker);
+}
+
+//----------------------------------------------------------------------------
+std::string GeneratorExpressionContent::EvaluateParameters(
+ const cmGeneratorExpressionNode *node,
+ const std::string &identifier,
+ cmGeneratorExpressionContext *context,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ std::vector<std::string> &parameters) const
+{
+ const int numExpected = node->NumExpectedParameters();
+ {
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
+ pit = this->ParamChildren.begin();
+ const
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
+ pend = this->ParamChildren.end();
+ const bool acceptsArbitraryContent
+ = node->AcceptsArbitraryContentParameter();
+ int counter = 1;
+ for ( ; pit != pend; ++pit, ++counter)
+ {
+ if (acceptsArbitraryContent && counter == numExpected)
+ {
+ std::string lastParam = this->ProcessArbitraryContent(node, identifier,
+ context,
+ dagChecker,
+ pit);
+ parameters.push_back(lastParam);
+ return std::string();
+ }
+ else
+ {
+ std::string parameter;
+ std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it =
+ pit->begin();
+ const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end =
+ pit->end();
+ for ( ; it != end; ++it)
+ {
+ parameter += (*it)->Evaluate(context, dagChecker);
+ if (context->HadError)
+ {
+ return std::string();
+ }
+ }
+ parameters.push_back(parameter);
+ }
+ }
+ }
+
+ if ((numExpected > cmGeneratorExpressionNode::DynamicParameters
+ && (unsigned int)numExpected != parameters.size()))
+ {
+ if (numExpected == 0)
+ {
+ reportError(context, this->GetOriginalExpression(),
+ "$<" + identifier + "> expression requires no parameters.");
+ }
+ else if (numExpected == 1)
+ {
+ reportError(context, this->GetOriginalExpression(),
+ "$<" + identifier + "> expression requires "
+ "exactly one parameter.");
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "$<" + identifier + "> expression requires "
+ << numExpected
+ << " comma separated parameters, but got "
+ << parameters.size() << " instead.";
+ reportError(context, this->GetOriginalExpression(), e.str());
+ }
+ return std::string();
+ }
+
+ if (numExpected == cmGeneratorExpressionNode::OneOrMoreParameters
+ && parameters.empty())
+ {
+ reportError(context, this->GetOriginalExpression(), "$<" + identifier
+ + "> expression requires at least one parameter.");
+ }
+ if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters
+ && parameters.size() > 1)
+ {
+ reportError(context, this->GetOriginalExpression(), "$<" + identifier
+ + "> expression requires one or zero parameters.");
+ }
+ return std::string();
+}
+
+//----------------------------------------------------------------------------
+static void deleteAll(const std::vector<cmGeneratorExpressionEvaluator*> &c)
+{
+ std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
+ = c.begin();
+ const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
+ = c.end();
+ for ( ; it != end; ++it)
+ {
+ delete *it;
+ }
+}
+
+//----------------------------------------------------------------------------
+GeneratorExpressionContent::~GeneratorExpressionContent()
+{
+ deleteAll(this->IdentifierChildren);
+
+ typedef std::vector<cmGeneratorExpressionEvaluator*> EvaluatorVector;
+ std::vector<EvaluatorVector>::const_iterator pit =
+ this->ParamChildren.begin();
+ const std::vector<EvaluatorVector>::const_iterator pend =
+ this->ParamChildren.end();
+ for ( ; pit != pend; ++pit)
+ {
+ deleteAll(*pit);
+ }
+}
diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h
new file mode 100644
index 0000000000..8a529e88d0
--- /dev/null
+++ b/Source/cmGeneratorExpressionEvaluator.h
@@ -0,0 +1,156 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmGeneratorExpressionEvaluator_h
+#define cmGeneratorExpressionEvaluator_h
+
+#include <vector>
+#include <string>
+
+#include "cmListFileCache.h"
+
+class cmTarget;
+
+//----------------------------------------------------------------------------
+struct cmGeneratorExpressionContext
+{
+ cmGeneratorExpressionContext()
+ : Backtrace(NULL)
+ {
+ }
+
+ cmListFileBacktrace Backtrace;
+ std::set<cmTarget*> DependTargets;
+ std::set<cmTarget const*> AllTargets;
+ std::set<std::string> SeenTargetProperties;
+ std::map<cmTarget const*, std::map<std::string, std::string> >
+ MaxLanguageStandard;
+ cmMakefile *Makefile;
+ std::string Config;
+ 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.
+ bool Quiet;
+ bool HadError;
+ bool HadContextSensitiveCondition;
+ bool HadHeadSensitiveCondition;
+ bool EvaluateForBuildsystem;
+};
+
+struct cmGeneratorExpressionDAGChecker;
+struct cmGeneratorExpressionNode;
+
+//----------------------------------------------------------------------------
+struct cmGeneratorExpressionEvaluator
+{
+ cmGeneratorExpressionEvaluator() {}
+ virtual ~cmGeneratorExpressionEvaluator() {}
+
+ enum Type
+ {
+ Text,
+ Generator
+ };
+
+ virtual Type GetType() const = 0;
+
+ virtual std::string Evaluate(cmGeneratorExpressionContext *context,
+ cmGeneratorExpressionDAGChecker *) const = 0;
+
+private:
+ cmGeneratorExpressionEvaluator(const cmGeneratorExpressionEvaluator &);
+ void operator=(const cmGeneratorExpressionEvaluator &);
+};
+
+struct TextContent : public cmGeneratorExpressionEvaluator
+{
+ TextContent(const char *start, size_t length)
+ : Content(start), Length(length)
+ {
+
+ }
+
+ std::string Evaluate(cmGeneratorExpressionContext *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return std::string(this->Content, this->Length);
+ }
+
+ Type GetType() const
+ {
+ return cmGeneratorExpressionEvaluator::Text;
+ }
+
+ void Extend(size_t length)
+ {
+ this->Length += length;
+ }
+
+ size_t GetLength()
+ {
+ return this->Length;
+ }
+
+private:
+ const char *Content;
+ size_t Length;
+};
+
+//----------------------------------------------------------------------------
+struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
+{
+ GeneratorExpressionContent(const char *startContent, size_t length);
+ void SetIdentifier(std::vector<cmGeneratorExpressionEvaluator*> identifier)
+ {
+ this->IdentifierChildren = identifier;
+ }
+
+ void SetParameters(
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*> > parameters)
+ {
+ this->ParamChildren = parameters;
+ }
+
+ Type GetType() const
+ {
+ return cmGeneratorExpressionEvaluator::Generator;
+ }
+
+ std::string Evaluate(cmGeneratorExpressionContext *context,
+ cmGeneratorExpressionDAGChecker *) const;
+
+ std::string GetOriginalExpression() const;
+
+ ~GeneratorExpressionContent();
+
+private:
+ std::string EvaluateParameters(const cmGeneratorExpressionNode *node,
+ const std::string &identifier,
+ cmGeneratorExpressionContext *context,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ std::vector<std::string> &parameters) const;
+
+ std::string ProcessArbitraryContent(
+ const cmGeneratorExpressionNode *node,
+ const std::string &identifier,
+ cmGeneratorExpressionContext *context,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
+ pit) const;
+
+private:
+ std::vector<cmGeneratorExpressionEvaluator*> IdentifierChildren;
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*> > ParamChildren;
+ const char *StartContent;
+ size_t ContentLength;
+};
+
+#endif
diff --git a/Source/cmGeneratorExpressionLexer.cxx b/Source/cmGeneratorExpressionLexer.cxx
new file mode 100644
index 0000000000..1c83466ce4
--- /dev/null
+++ b/Source/cmGeneratorExpressionLexer.cxx
@@ -0,0 +1,83 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmGeneratorExpressionLexer.h"
+
+
+//----------------------------------------------------------------------------
+cmGeneratorExpressionLexer::cmGeneratorExpressionLexer()
+ : SawBeginExpression(false), SawGeneratorExpression(false)
+{
+
+}
+
+//----------------------------------------------------------------------------
+static void InsertText(const char *upto, const char *c,
+ std::vector<cmGeneratorExpressionToken> &result)
+{
+ if (upto != c)
+ {
+ result.push_back(cmGeneratorExpressionToken(
+ cmGeneratorExpressionToken::Text, upto, c - upto));
+ }
+}
+
+//----------------------------------------------------------------------------
+std::vector<cmGeneratorExpressionToken>
+cmGeneratorExpressionLexer::Tokenize(const std::string& input)
+{
+ std::vector<cmGeneratorExpressionToken> result;
+
+ const char *c = input.c_str();
+ const char *upto = c;
+
+ for ( ; *c; ++c)
+ {
+ switch(*c)
+ {
+ case '$':
+ if(c[1] == '<')
+ {
+ InsertText(upto, c, result);
+ result.push_back(cmGeneratorExpressionToken(
+ cmGeneratorExpressionToken::BeginExpression, c, 2));
+ upto = c + 2;
+ ++c;
+ SawBeginExpression = true;
+ }
+ break;
+ case '>':
+ InsertText(upto, c, result);
+ result.push_back(cmGeneratorExpressionToken(
+ cmGeneratorExpressionToken::EndExpression, c, 1));
+ upto = c + 1;
+ SawGeneratorExpression = SawBeginExpression;
+ break;
+ case ':':
+ InsertText(upto, c, result);
+ result.push_back(cmGeneratorExpressionToken(
+ cmGeneratorExpressionToken::ColonSeparator, c, 1));
+ upto = c + 1;
+ break;
+ case ',':
+ InsertText(upto, c, result);
+ result.push_back(cmGeneratorExpressionToken(
+ cmGeneratorExpressionToken::CommaSeparator, c, 1));
+ upto = c + 1;
+ break;
+ default:
+ break;
+ }
+ }
+ InsertText(upto, c, result);
+
+ return result;
+}
diff --git a/Source/cmGeneratorExpressionLexer.h b/Source/cmGeneratorExpressionLexer.h
new file mode 100644
index 0000000000..1e2e8c25eb
--- /dev/null
+++ b/Source/cmGeneratorExpressionLexer.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmGeneratorExpressionLexer_h
+#define cmGeneratorExpressionLexer_h
+
+#include "cmStandardIncludes.h"
+
+#include <vector>
+
+//----------------------------------------------------------------------------
+struct cmGeneratorExpressionToken
+{
+ cmGeneratorExpressionToken(unsigned type, const char *c, size_t l)
+ : TokenType(type), Content(c), Length(l)
+ {
+ }
+ enum {
+ Text,
+ BeginExpression,
+ EndExpression,
+ ColonSeparator,
+ CommaSeparator
+ };
+ unsigned TokenType;
+ const char *Content;
+ size_t Length;
+};
+
+/** \class cmGeneratorExpressionLexer
+ *
+ */
+class cmGeneratorExpressionLexer
+{
+public:
+ cmGeneratorExpressionLexer();
+
+ std::vector<cmGeneratorExpressionToken> Tokenize(const std::string& input);
+
+ bool GetSawGeneratorExpression() const
+ {
+ return this->SawGeneratorExpression;
+ }
+
+private:
+ bool SawBeginExpression;
+ bool SawGeneratorExpression;
+};
+
+#endif
diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx
new file mode 100644
index 0000000000..a41a6e5212
--- /dev/null
+++ b/Source/cmGeneratorExpressionParser.cxx
@@ -0,0 +1,302 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmGeneratorExpressionParser.h"
+
+#include "cmGeneratorExpressionEvaluator.h"
+
+#include "assert.h"
+
+//----------------------------------------------------------------------------
+cmGeneratorExpressionParser::cmGeneratorExpressionParser(
+ const std::vector<cmGeneratorExpressionToken> &tokens)
+ : Tokens(tokens), NestingLevel(0)
+{
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorExpressionParser::Parse(
+ std::vector<cmGeneratorExpressionEvaluator*> &result)
+{
+ it = this->Tokens.begin();
+
+ while (this->it != this->Tokens.end())
+ {
+ this->ParseContent(result);
+ }
+}
+
+//----------------------------------------------------------------------------
+static void extendText(std::vector<cmGeneratorExpressionEvaluator*> &result,
+ std::vector<cmGeneratorExpressionToken>::const_iterator it)
+{
+ if (result.size() > 0
+ && (*(result.end() - 1))->GetType()
+ == cmGeneratorExpressionEvaluator::Text)
+ {
+ TextContent *textContent = static_cast<TextContent*>(*(result.end() - 1));
+ textContent->Extend(it->Length);
+ }
+ else
+ {
+ TextContent *textContent = new TextContent(it->Content, it->Length);
+ result.push_back(textContent);
+ }
+}
+
+//----------------------------------------------------------------------------
+static void extendResult(std::vector<cmGeneratorExpressionEvaluator*> &result,
+ const std::vector<cmGeneratorExpressionEvaluator*> &contents)
+{
+ if (result.size() > 0
+ && (*(result.end() - 1))->GetType()
+ == cmGeneratorExpressionEvaluator::Text
+ && (*contents.begin())->GetType()
+ == cmGeneratorExpressionEvaluator::Text)
+ {
+ TextContent *textContent = static_cast<TextContent*>(*(result.end() - 1));
+ textContent->Extend(
+ static_cast<TextContent*>(*contents.begin())->GetLength());
+ delete *contents.begin();
+ result.insert(result.end(), contents.begin() + 1, contents.end());
+ } else {
+ result.insert(result.end(), contents.begin(), contents.end());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorExpressionParser::ParseGeneratorExpression(
+ std::vector<cmGeneratorExpressionEvaluator*> &result)
+{
+ assert(this->it != this->Tokens.end());
+ unsigned int nestedLevel = this->NestingLevel;
+ ++this->NestingLevel;
+
+ std::vector<cmGeneratorExpressionToken>::const_iterator startToken
+ = this->it - 1;
+
+ std::vector<cmGeneratorExpressionEvaluator*> identifier;
+ while(this->it->TokenType != cmGeneratorExpressionToken::EndExpression
+ && this->it->TokenType != cmGeneratorExpressionToken::ColonSeparator)
+ {
+ if (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator)
+ {
+ extendText(identifier, this->it);
+ ++this->it;
+ }
+ else
+ {
+ this->ParseContent(identifier);
+ }
+ if (this->it == this->Tokens.end())
+ {
+ break;
+ }
+ }
+ if (identifier.empty())
+ {
+ // ERROR
+ }
+
+ if (this->it != this->Tokens.end() &&
+ this->it->TokenType == cmGeneratorExpressionToken::EndExpression)
+ {
+ GeneratorExpressionContent *content = new GeneratorExpressionContent(
+ startToken->Content, this->it->Content
+ - startToken->Content
+ + this->it->Length);
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ --this->NestingLevel;
+ content->SetIdentifier(identifier);
+ result.push_back(content);
+ return;
+ }
+
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*> > parameters;
+ std::vector<std::vector<cmGeneratorExpressionToken>::const_iterator>
+ commaTokens;
+ std::vector<cmGeneratorExpressionToken>::const_iterator colonToken;
+
+ bool emptyParamTermination = false;
+
+ if (this->it != this->Tokens.end() &&
+ this->it->TokenType == cmGeneratorExpressionToken::ColonSeparator)
+ {
+ colonToken = this->it;
+ parameters.resize(parameters.size() + 1);
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ if(this->it == this->Tokens.end())
+ {
+ emptyParamTermination = true;
+ }
+
+ while (this->it != this->Tokens.end() &&
+ this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator)
+ {
+ commaTokens.push_back(this->it);
+ parameters.resize(parameters.size() + 1);
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ if(this->it == this->Tokens.end())
+ {
+ emptyParamTermination = true;
+ }
+ }
+ while (this->it != this->Tokens.end() &&
+ this->it->TokenType == cmGeneratorExpressionToken::ColonSeparator)
+ {
+ extendText(*(parameters.end() - 1), this->it);
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ }
+ while (this->it != this->Tokens.end() &&
+ this->it->TokenType != cmGeneratorExpressionToken::EndExpression)
+ {
+ this->ParseContent(*(parameters.end() - 1));
+ if (this->it == this->Tokens.end())
+ {
+ break;
+ }
+ while (this->it != this->Tokens.end() &&
+ this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator)
+ {
+ commaTokens.push_back(this->it);
+ parameters.resize(parameters.size() + 1);
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ if(this->it == this->Tokens.end())
+ {
+ emptyParamTermination = true;
+ }
+ }
+ while (this->it != this->Tokens.end() &&
+ this->it->TokenType == cmGeneratorExpressionToken::ColonSeparator)
+ {
+ extendText(*(parameters.end() - 1), this->it);
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ }
+ }
+ if(this->it != this->Tokens.end()
+ && this->it->TokenType == cmGeneratorExpressionToken::EndExpression)
+ {
+ --this->NestingLevel;
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ }
+ }
+
+ if (nestedLevel != this->NestingLevel)
+ {
+ // There was a '$<' in the text, but no corresponding '>'. Rebuild to
+ // treat the '$<' as having been plain text, along with the
+ // corresponding : and , tokens that might have been found.
+ extendText(result, startToken);
+ extendResult(result, identifier);
+ if (!parameters.empty())
+ {
+ extendText(result, colonToken);
+
+ typedef std::vector<cmGeneratorExpressionEvaluator*> EvaluatorVector;
+ typedef std::vector<cmGeneratorExpressionToken> TokenVector;
+ std::vector<EvaluatorVector>::const_iterator pit = parameters.begin();
+ const std::vector<EvaluatorVector>::const_iterator pend =
+ parameters.end();
+ std::vector<TokenVector::const_iterator>::const_iterator commaIt =
+ commaTokens.begin();
+ assert(parameters.size() > commaTokens.size());
+ for ( ; pit != pend; ++pit, ++commaIt)
+ {
+ if (!pit->empty() && !emptyParamTermination)
+ {
+ extendResult(result, *pit);
+ }
+ if (commaIt != commaTokens.end())
+ {
+ extendText(result, *commaIt);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ return;
+ }
+
+ size_t contentLength = ((this->it - 1)->Content
+ - startToken->Content)
+ + (this->it - 1)->Length;
+ GeneratorExpressionContent *content = new GeneratorExpressionContent(
+ startToken->Content, contentLength);
+ content->SetIdentifier(identifier);
+ content->SetParameters(parameters);
+ result.push_back(content);
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorExpressionParser::ParseContent(
+ std::vector<cmGeneratorExpressionEvaluator*> &result)
+{
+ assert(this->it != this->Tokens.end());
+ switch(this->it->TokenType)
+ {
+ case cmGeneratorExpressionToken::Text:
+ {
+ if (this->NestingLevel == 0)
+ {
+ if (result.size() > 0
+ && (*(result.end() - 1))->GetType()
+ == cmGeneratorExpressionEvaluator::Text)
+ {
+ // A comma in 'plain text' could have split text that should
+ // otherwise be continuous. Extend the last text content instead of
+ // creating a new one.
+ TextContent *textContent =
+ static_cast<TextContent*>(*(result.end() - 1));
+ textContent->Extend(this->it->Length);
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ return;
+ }
+ }
+ cmGeneratorExpressionEvaluator* n = new TextContent(this->it->Content,
+ this->it->Length);
+ result.push_back(n);
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ return ;
+ }
+ case cmGeneratorExpressionToken::BeginExpression:
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ this->ParseGeneratorExpression(result);
+ return;
+ case cmGeneratorExpressionToken::EndExpression:
+ case cmGeneratorExpressionToken::ColonSeparator:
+ case cmGeneratorExpressionToken::CommaSeparator:
+ if (this->NestingLevel == 0)
+ {
+ extendText(result, this->it);
+ }
+ else
+ {
+ assert(!"Got unexpected syntax token.");
+ }
+ assert(this->it != this->Tokens.end());
+ ++this->it;
+ return;
+ }
+ assert(!"Unhandled token in generator expression.");
+}
diff --git a/Source/cmGeneratorExpressionParser.h b/Source/cmGeneratorExpressionParser.h
new file mode 100644
index 0000000000..28f14410fe
--- /dev/null
+++ b/Source/cmGeneratorExpressionParser.h
@@ -0,0 +1,45 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmGeneratorExpressionParser_h
+#define cmGeneratorExpressionParser_h
+
+#include "cmGeneratorExpressionLexer.h"
+
+#include <set>
+#include <vector>
+
+#include "cmListFileCache.h"
+
+class cmMakefile;
+class cmTarget;
+struct cmGeneratorExpressionEvaluator;
+
+//----------------------------------------------------------------------------
+struct cmGeneratorExpressionParser
+{
+ cmGeneratorExpressionParser(
+ const std::vector<cmGeneratorExpressionToken> &tokens);
+
+ void Parse(std::vector<cmGeneratorExpressionEvaluator*> &result);
+
+private:
+ void ParseContent(std::vector<cmGeneratorExpressionEvaluator*> &);
+ void ParseGeneratorExpression(
+ std::vector<cmGeneratorExpressionEvaluator*> &);
+
+private:
+ std::vector<cmGeneratorExpressionToken>::const_iterator it;
+ const std::vector<cmGeneratorExpressionToken> Tokens;
+ unsigned int NestingLevel;
+};
+
+#endif
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
new file mode 100644
index 0000000000..14b5a927f5
--- /dev/null
+++ b/Source/cmGeneratorTarget.cxx
@@ -0,0 +1,1159 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 "cmGeneratorTarget.h"
+
+#include "cmTarget.h"
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmSourceFile.h"
+#include "cmGeneratorExpression.h"
+#include "cmGeneratorExpressionDAGChecker.h"
+#include "cmComputeLinkInformation.h"
+#include "cmCustomCommandGenerator.h"
+
+#include <queue>
+
+#include "assert.h"
+
+//----------------------------------------------------------------------------
+void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
+ cmTarget *target, cmake *cm)
+{
+ if(!badObjLib.empty())
+ {
+ cmOStringStream e;
+ e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
+ for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
+ i != badObjLib.end(); ++i)
+ {
+ e << " " << (*i)->GetLocation().GetName() << "\n";
+ }
+ 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->GetBacktrace());
+ }
+}
+
+struct ObjectSourcesTag {};
+struct CustomCommandsTag {};
+struct ExtraSourcesTag {};
+struct HeaderSourcesTag {};
+struct ExternalObjectsTag {};
+struct IDLSourcesTag {};
+struct ResxTag {};
+struct ModuleDefinitionFileTag {};
+struct AppManifestTag{};
+struct CertificatesTag{};
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1310
+template<typename Tag, typename OtherTag>
+struct IsSameTag
+{
+ enum {
+ Result = false
+ };
+};
+
+template<typename Tag>
+struct IsSameTag<Tag, Tag>
+{
+ enum {
+ Result = true
+ };
+};
+#else
+struct IsSameTagBase
+{
+ typedef char (&no_type)[1];
+ typedef char (&yes_type)[2];
+ template<typename T> struct Check;
+ template<typename T> static yes_type check(Check<T>*, Check<T>*);
+ static no_type check(...);
+};
+template<typename Tag1, typename Tag2>
+struct IsSameTag: public IsSameTagBase
+{
+ enum {
+ Result = (sizeof(check(static_cast< Check<Tag1>* >(0),
+ static_cast< Check<Tag2>* >(0))) ==
+ sizeof(yes_type))
+ };
+};
+#endif
+
+template<bool>
+struct DoAccept
+{
+ template <typename T> static void Do(T&, cmSourceFile*) {}
+};
+
+template<>
+struct DoAccept<true>
+{
+ static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
+ {
+ files.push_back(f);
+ }
+ static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
+ {
+ // Build and save the name of the corresponding .h file
+ // This relationship will be used later when building the project files.
+ // Both names would have been auto generated from Visual Studio
+ // where the user supplied the file name and Visual Studio
+ // appended the suffix.
+ std::string resx = f->GetFullPath();
+ std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
+ data.ExpectedResxHeaders.insert(hFileName);
+ data.ResxSources.push_back(f);
+ }
+ static void Do(std::string& data, cmSourceFile* f)
+ {
+ data = f->GetFullPath();
+ }
+};
+
+//----------------------------------------------------------------------------
+template<typename Tag, typename DataType = std::vector<cmSourceFile const*> >
+struct TagVisitor
+{
+ DataType& Data;
+ std::vector<cmSourceFile*> BadObjLibFiles;
+ cmTarget *Target;
+ cmGlobalGenerator *GlobalGenerator;
+ cmsys::RegularExpression Header;
+ bool IsObjLib;
+
+ TagVisitor(cmTarget *target, DataType& data)
+ : Data(data), Target(target),
+ GlobalGenerator(target->GetMakefile()
+ ->GetLocalGenerator()->GetGlobalGenerator()),
+ Header(CM_HEADER_REGEX),
+ IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ }
+
+ ~TagVisitor()
+ {
+ reportBadObjLib(this->BadObjLibFiles, this->Target,
+ this->GlobalGenerator->GetCMakeInstance());
+ }
+
+ void Accept(cmSourceFile *sf)
+ {
+ std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
+ if(sf->GetCustomCommand())
+ {
+ DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
+ }
+ else if(this->Target->GetType() == cmTarget::UTILITY)
+ {
+ DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
+ {
+ DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
+ {
+ DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
+ if(this->IsObjLib)
+ {
+ this->BadObjLibFiles.push_back(sf);
+ }
+ }
+ else if(!sf->GetLanguage().empty())
+ {
+ DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else if(ext == "def")
+ {
+ DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
+ sf);
+ if(this->IsObjLib)
+ {
+ this->BadObjLibFiles.push_back(sf);
+ }
+ }
+ else if(ext == "idl")
+ {
+ DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
+ if(this->IsObjLib)
+ {
+ this->BadObjLibFiles.push_back(sf);
+ }
+ }
+ else if(ext == "resx")
+ {
+ DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
+ }
+ else if (ext == "appxmanifest")
+ {
+ DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
+ }
+ else if (ext == "pfx")
+ {
+ DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
+ }
+ else if(this->Header.find(sf->GetFullPath().c_str()))
+ {
+ DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
+ {
+ DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else
+ {
+ DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+cmGeneratorTarget::cmGeneratorTarget(cmTarget* t): Target(t),
+ SourceFileFlagsConstructed(false)
+{
+ this->Makefile = this->Target->GetMakefile();
+ this->LocalGenerator = this->Makefile->GetLocalGenerator();
+ this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
+}
+
+//----------------------------------------------------------------------------
+int cmGeneratorTarget::GetType() const
+{
+ return this->Target->GetType();
+}
+
+//----------------------------------------------------------------------------
+std::string cmGeneratorTarget::GetName() const
+{
+ return this->Target->GetName();
+}
+
+//----------------------------------------------------------------------------
+const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
+{
+ return this->Target->GetProperty(prop);
+}
+
+//----------------------------------------------------------------------------
+std::vector<cmSourceFile*> const*
+cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
+{
+ SourceEntriesType::const_iterator i = this->SourceEntries.find(sf);
+ if(i != this->SourceEntries.end())
+ {
+ return &i->second.Depends;
+ }
+ return 0;
+}
+
+static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
+ const std::string& config,
+ cmTarget *headTarget,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ std::vector<std::string>& result,
+ bool excludeImported)
+{
+ if (const char* dirs =
+ depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"))
+ {
+ cmGeneratorExpression ge;
+ cmSystemTools::ExpandListArgument(ge.Parse(dirs)
+ ->Evaluate(mf,
+ config, false, headTarget,
+ depTgt, dagChecker), result);
+ }
+ if (!depTgt->IsImported() || excludeImported)
+ {
+ return;
+ }
+
+ if (const char* dirs =
+ depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES"))
+ {
+ cmGeneratorExpression ge;
+ cmSystemTools::ExpandListArgument(ge.Parse(dirs)
+ ->Evaluate(mf,
+ config, false, headTarget,
+ depTgt, dagChecker), result);
+ }
+}
+
+#define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
+ { \
+ std::vector<cmSourceFile*> sourceFiles; \
+ this->Target->GetSourceFiles(sourceFiles, config); \
+ TagVisitor<DATA ## Tag DATATYPE> visitor(this->Target, data); \
+ for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
+ si != sourceFiles.end(); ++si) \
+ { \
+ visitor.Accept(*si); \
+ } \
+ } \
+
+
+#define IMPLEMENT_VISIT(DATA) \
+ IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
+
+#define EMPTY
+#define COMMA ,
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorTarget
+::GetObjectSources(std::vector<cmSourceFile const*> &data,
+ const std::string& config) const
+{
+ IMPLEMENT_VISIT(ObjectSources);
+
+ if (!this->Objects.empty())
+ {
+ return;
+ }
+
+ for(std::vector<cmSourceFile const*>::const_iterator it = data.begin();
+ it != data.end(); ++it)
+ {
+ this->Objects[*it];
+ }
+
+ this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
+}
+
+void cmGeneratorTarget::ComputeObjectMapping()
+{
+ if(!this->Objects.empty())
+ {
+ return;
+ }
+
+ std::vector<std::string> configs;
+ this->Makefile->GetConfigurations(configs);
+ if (configs.empty())
+ {
+ configs.push_back("");
+ }
+ for(std::vector<std::string>::const_iterator ci = configs.begin();
+ ci != configs.end(); ++ci)
+ {
+ std::vector<cmSourceFile const*> sourceFiles;
+ this->GetObjectSources(sourceFiles, *ci);
+ }
+}
+
+//----------------------------------------------------------------------------
+const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
+{
+ this->ComputeObjectMapping();
+ return this->Objects[file];
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
+{
+ this->ExplicitObjectName.insert(sf);
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
+{
+ const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
+ std::set<cmSourceFile const*>::const_iterator it
+ = this->ExplicitObjectName.find(file);
+ return it != this->ExplicitObjectName.end();
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget
+::GetIDLSources(std::vector<cmSourceFile const*>& data,
+ const std::string& config) const
+{
+ IMPLEMENT_VISIT(IDLSources);
+}
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorTarget
+::GetHeaderSources(std::vector<cmSourceFile const*>& data,
+ const std::string& config) const
+{
+ IMPLEMENT_VISIT(HeaderSources);
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget
+::GetExtraSources(std::vector<cmSourceFile const*>& data,
+ const std::string& config) const
+{
+ IMPLEMENT_VISIT(ExtraSources);
+}
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorTarget
+::GetCustomCommands(std::vector<cmSourceFile const*>& data,
+ const std::string& config) const
+{
+ IMPLEMENT_VISIT(CustomCommands);
+}
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorTarget
+::GetExternalObjects(std::vector<cmSourceFile const*>& data,
+ const std::string& config) const
+{
+ IMPLEMENT_VISIT(ExternalObjects);
+}
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
+ const std::string& config) const
+{
+ ResxData data;
+ IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
+ srcs = data.ExpectedResxHeaders;
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget
+::GetResxSources(std::vector<cmSourceFile const*>& srcs,
+ const std::string& config) const
+{
+ ResxData data;
+ IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
+ srcs = data.ResxSources;
+}
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorTarget
+::GetAppManifest(std::vector<cmSourceFile const*>& data,
+ const std::string& config) const
+{
+ IMPLEMENT_VISIT(AppManifest);
+}
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorTarget
+::GetCertificates(std::vector<cmSourceFile const*>& data,
+ const std::string& config) const
+{
+ IMPLEMENT_VISIT(Certificates);
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
+ const std::string& config) const
+{
+ assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
+ std::string config_upper;
+ if(!config.empty())
+ {
+ config_upper = cmSystemTools::UpperCase(config);
+ }
+
+ typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
+ IncludeCacheType::const_iterator iter =
+ this->SystemIncludesCache.find(config_upper);
+
+ if (iter == this->SystemIncludesCache.end())
+ {
+ cmGeneratorExpressionDAGChecker dagChecker(
+ this->GetName(),
+ "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
+
+ bool excludeImported
+ = this->Target->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
+
+ std::vector<std::string> result;
+ for (std::set<std::string>::const_iterator
+ it = this->Target->GetSystemIncludeDirectories().begin();
+ it != this->Target->GetSystemIncludeDirectories().end(); ++it)
+ {
+ cmGeneratorExpression ge;
+ cmSystemTools::ExpandListArgument(ge.Parse(*it)
+ ->Evaluate(this->Makefile,
+ config, false, this->Target,
+ &dagChecker), result);
+ }
+
+ std::vector<cmTarget const*> const& deps =
+ this->Target->GetLinkImplementationClosure(config);
+ for(std::vector<cmTarget const*>::const_iterator
+ li = deps.begin(), le = deps.end(); li != le; ++li)
+ {
+ handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
+ &dagChecker, result, excludeImported);
+ }
+
+ std::set<std::string> unique;
+ for(std::vector<std::string>::iterator li = result.begin();
+ li != result.end(); ++li)
+ {
+ cmSystemTools::ConvertToUnixSlashes(*li);
+ unique.insert(*li);
+ }
+ result.clear();
+ for(std::set<std::string>::iterator li = unique.begin();
+ li != unique.end(); ++li)
+ {
+ result.push_back(*li);
+ }
+
+ IncludeCacheType::value_type entry(config_upper, result);
+ iter = this->SystemIncludesCache.insert(entry).first;
+ }
+
+ return std::binary_search(iter->second.begin(), iter->second.end(), dir);
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
+{
+ return this->Target->GetPropertyAsBool(prop);
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
+ const std::string& config) const
+{
+ this->Target->GetSourceFiles(files, config);
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
+{
+ std::string data;
+ IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
+ return data;
+}
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
+ const std::string &config) const
+{
+ std::vector<cmSourceFile const*> objectFiles;
+ this->GetExternalObjects(objectFiles, config);
+ std::vector<cmTarget*> objectLibraries;
+ std::set<cmTarget*> emitted;
+ 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 (emitted.insert(tgt).second)
+ {
+ objectLibraries.push_back(tgt);
+ }
+ }
+ }
+
+ for(std::vector<cmTarget*>::const_iterator
+ ti = objectLibraries.begin();
+ ti != objectLibraries.end(); ++ti)
+ {
+ cmTarget* objLib = *ti;
+ cmGeneratorTarget* ogt =
+ this->GlobalGenerator->GetGeneratorTarget(objLib);
+ std::vector<cmSourceFile const*> objectSources;
+ ogt->GetObjectSources(objectSources, config);
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = objectSources.begin();
+ si != objectSources.end(); ++si)
+ {
+ std::string obj = ogt->ObjectDirectory;
+ obj += ogt->Objects[*si];
+ objs.push_back(obj);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+class cmTargetTraceDependencies
+{
+public:
+ cmTargetTraceDependencies(cmGeneratorTarget* target);
+ void Trace();
+private:
+ cmTarget* Target;
+ cmGeneratorTarget* GeneratorTarget;
+ cmMakefile* Makefile;
+ cmGlobalGenerator const* GlobalGenerator;
+ typedef cmGeneratorTarget::SourceEntry SourceEntry;
+ SourceEntry* CurrentEntry;
+ std::queue<cmSourceFile*> SourceQueue;
+ std::set<cmSourceFile*> SourcesQueued;
+ typedef std::map<std::string, cmSourceFile*> NameMapType;
+ NameMapType NameMap;
+ std::vector<std::string> NewSources;
+
+ void QueueSource(cmSourceFile* sf);
+ void FollowName(std::string const& name);
+ void FollowNames(std::vector<std::string> const& names);
+ bool IsUtility(std::string const& dep);
+ void CheckCustomCommand(cmCustomCommand const& cc);
+ void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
+ void FollowCommandDepends(cmCustomCommand const& cc,
+ const std::string& config,
+ std::set<std::string>& emitted);
+};
+
+//----------------------------------------------------------------------------
+cmTargetTraceDependencies
+::cmTargetTraceDependencies(cmGeneratorTarget* target):
+ Target(target->Target), GeneratorTarget(target)
+{
+ // Convenience.
+ this->Makefile = this->Target->GetMakefile();
+ this->GlobalGenerator =
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
+ this->CurrentEntry = 0;
+
+ // Queue all the source files already specified for the target.
+ if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ std::vector<std::string> configs;
+ this->Makefile->GetConfigurations(configs);
+ if (configs.empty())
+ {
+ configs.push_back("");
+ }
+ std::set<cmSourceFile*> emitted;
+ for(std::vector<std::string>::const_iterator ci = configs.begin();
+ ci != configs.end(); ++ci)
+ {
+ std::vector<cmSourceFile*> sources;
+ this->Target->GetSourceFiles(sources, *ci);
+ for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
+ si != sources.end(); ++si)
+ {
+ cmSourceFile* sf = *si;
+ if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
+ {
+ this->SourceQueue.push(sf);
+ }
+ }
+ }
+ }
+
+ // 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());
+}
+
+//----------------------------------------------------------------------------
+void cmTargetTraceDependencies::Trace()
+{
+ // Process one dependency at a time until the queue is empty.
+ while(!this->SourceQueue.empty())
+ {
+ // Get the next source from the queue.
+ cmSourceFile* sf = this->SourceQueue.front();
+ this->SourceQueue.pop();
+ this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
+
+ // Queue dependencies added explicitly by the user.
+ if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
+ {
+ std::vector<std::string> objDeps;
+ cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
+ this->FollowNames(objDeps);
+ }
+
+ // Queue the source needed to generate this file, if any.
+ this->FollowName(sf->GetFullPath());
+
+ // Queue dependencies added programatically by commands.
+ this->FollowNames(sf->GetDepends());
+
+ // Queue custom command dependencies.
+ if(cmCustomCommand const* cc = sf->GetCustomCommand())
+ {
+ this->CheckCustomCommand(*cc);
+ }
+ }
+ this->CurrentEntry = 0;
+
+ this->Target->AddTracedSources(this->NewSources);
+}
+
+//----------------------------------------------------------------------------
+void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
+{
+ if(this->SourcesQueued.insert(sf).second)
+ {
+ this->SourceQueue.push(sf);
+
+ // Make sure this file is in the target at the end.
+ this->NewSources.push_back(sf->GetFullPath());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTargetTraceDependencies::FollowName(std::string const& name)
+{
+ NameMapType::iterator i = this->NameMap.find(name);
+ if(i == this->NameMap.end())
+ {
+ // Check if we know how to generate this file.
+ cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
+ NameMapType::value_type entry(name, sf);
+ i = this->NameMap.insert(entry).first;
+ }
+ if(cmSourceFile* sf = i->second)
+ {
+ // Record the dependency we just followed.
+ if(this->CurrentEntry)
+ {
+ this->CurrentEntry->Depends.push_back(sf);
+ }
+ this->QueueSource(sf);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
+{
+ for(std::vector<std::string>::const_iterator i = names.begin();
+ i != names.end(); ++i)
+ {
+ this->FollowName(*i);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
+{
+ // Dependencies on targets (utilities) are supposed to be named by
+ // just the target name. However for compatibility we support
+ // naming the output file generated by the target (assuming there is
+ // no output-name property which old code would not have set). In
+ // that case the target name will be the file basename of the
+ // dependency.
+ std::string util = cmSystemTools::GetFilenameName(dep);
+ if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
+ {
+ util = cmSystemTools::GetFilenameWithoutLastExtension(util);
+ }
+
+ // Check for a target with this name.
+ if(cmTarget* t = this->Makefile->FindTargetToUse(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)
+ {
+ // This is really only for compatibility so we do not need to
+ // worry about configuration names and output names.
+ std::string tLocation = t->GetLocationForBuild();
+ tLocation = cmSystemTools::GetFilenamePath(tLocation);
+ std::string depLocation = cmSystemTools::GetFilenamePath(dep);
+ depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
+ tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
+ if(depLocation == tLocation)
+ {
+ this->Target->AddUtility(util);
+ return true;
+ }
+ }
+ }
+ else
+ {
+ // 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);
+ return true;
+ }
+ }
+
+ // The dependency does not name a target built in this project.
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void
+cmTargetTraceDependencies
+::CheckCustomCommand(cmCustomCommand const& cc)
+{
+ // Transform command names that reference targets built in this
+ // project to corresponding target-level dependencies.
+ cmGeneratorExpression ge(&cc.GetBacktrace());
+
+ // Add target-level dependencies referenced by generator expressions.
+ std::set<cmTarget*> 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(t->GetType() == cmTarget::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);
+ }
+ }
+
+ // Check for target references in generator expressions.
+ for(cmCustomCommandLine::const_iterator cli = cit->begin();
+ cli != cit->end(); ++cli)
+ {
+ const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
+ = ge.Parse(*cli);
+ cge->Evaluate(this->Makefile, "", true);
+ std::set<cmTarget*> geTargets = cge->GetTargets();
+ for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
+ it != geTargets.end(); ++it)
+ {
+ targets.insert(*it);
+ }
+ }
+ }
+
+ for(std::set<cmTarget*>::iterator ti = targets.begin();
+ ti != targets.end(); ++ti)
+ {
+ this->Target->AddUtility((*ti)->GetName());
+ }
+
+ // Queue the custom command dependencies.
+ std::vector<std::string> configs;
+ std::set<std::string> emitted;
+ this->Makefile->GetConfigurations(configs);
+ if (configs.empty())
+ {
+ configs.push_back("");
+ }
+ for(std::vector<std::string>::const_iterator ci = configs.begin();
+ ci != configs.end(); ++ci)
+ {
+ this->FollowCommandDepends(cc, *ci, emitted);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
+ const std::string& config,
+ std::set<std::string>& emitted)
+{
+ cmCustomCommandGenerator ccg(cc, config, this->Makefile);
+
+ const std::vector<std::string>& depends = ccg.GetDepends();
+
+ for(std::vector<std::string>::const_iterator di = depends.begin();
+ di != depends.end(); ++di)
+ {
+ std::string const& dep = *di;
+ if(emitted.insert(dep).second)
+ {
+ if(!this->IsUtility(dep))
+ {
+ // The dependency does not name a target and may be a file we
+ // know how to generate. Queue it.
+ this->FollowName(dep);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmTargetTraceDependencies
+::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
+{
+ for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
+ cli != commands.end(); ++cli)
+ {
+ this->CheckCustomCommand(*cli);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::TraceDependencies()
+{
+ // CMake-generated targets have no dependencies to trace. Normally tracing
+ // 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)
+ {
+ return;
+ }
+
+ // Use a helper object to trace the dependencies.
+ cmTargetTraceDependencies tracer(this);
+ tracer.Trace();
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::GetAppleArchs(const std::string& config,
+ std::vector<std::string>& archVec) const
+{
+ const char* archs = 0;
+ if(!config.empty())
+ {
+ std::string defVarName = "OSX_ARCHITECTURES_";
+ defVarName += cmSystemTools::UpperCase(config);
+ archs = this->Target->GetProperty(defVarName);
+ }
+ if(!archs)
+ {
+ archs = this->Target->GetProperty("OSX_ARCHITECTURES");
+ }
+ if(archs)
+ {
+ cmSystemTools::ExpandListArgument(std::string(archs), archVec);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
+ std::string const& config) const
+{
+ switch(this->GetType())
+ {
+ case cmTarget::STATIC_LIBRARY:
+ {
+ std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
+ if(this->Target->GetFeatureAsBool(
+ "INTERPROCEDURAL_OPTIMIZATION", config))
+ {
+ std::string varIPO = var + "_IPO";
+ if(this->Makefile->GetDefinition(varIPO))
+ {
+ return varIPO;
+ }
+ }
+ return var;
+ }
+ case cmTarget::SHARED_LIBRARY:
+ return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
+ case cmTarget::MODULE_LIBRARY:
+ return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
+ case cmTarget::EXECUTABLE:
+ return "CMAKE_" + lang + "_LINK_EXECUTABLE";
+ default:
+ break;
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string>
+cmGeneratorTarget::GetIncludeDirectories(const std::string& config) const
+{
+ return this->Target->GetIncludeDirectories(config);
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::GenerateTargetManifest(
+ const std::string& config) const
+{
+ if (this->Target->IsImported())
+ {
+ return;
+ }
+ cmMakefile* mf = this->Target->GetMakefile();
+ cmLocalGenerator* lg = mf->GetLocalGenerator();
+ cmGlobalGenerator* gg = lg->GetGlobalGenerator();
+
+ // Get the names.
+ std::string name;
+ std::string soName;
+ std::string realName;
+ std::string impName;
+ std::string pdbName;
+ if(this->GetType() == cmTarget::EXECUTABLE)
+ {
+ this->Target->GetExecutableNames(name, realName, impName, pdbName,
+ config);
+ }
+ else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
+ this->GetType() == cmTarget::SHARED_LIBRARY ||
+ this->GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ this->Target->GetLibraryNames(name, soName, realName, impName, pdbName,
+ config);
+ }
+ else
+ {
+ return;
+ }
+
+ // Get the directory.
+ std::string dir = this->Target->GetDirectory(config, false);
+
+ // Add each name.
+ std::string f;
+ if(!name.empty())
+ {
+ f = dir;
+ f += "/";
+ f += name;
+ gg->AddToManifest(config, f);
+ }
+ if(!soName.empty())
+ {
+ f = dir;
+ f += "/";
+ f += soName;
+ gg->AddToManifest(config, f);
+ }
+ if(!realName.empty())
+ {
+ f = dir;
+ f += "/";
+ f += realName;
+ gg->AddToManifest(config, f);
+ }
+ if(!pdbName.empty())
+ {
+ f = dir;
+ f += "/";
+ f += pdbName;
+ gg->AddToManifest(config, f);
+ }
+ if(!impName.empty())
+ {
+ f = this->Target->GetDirectory(config, true);
+ f += "/";
+ f += impName;
+ gg->AddToManifest(config, f);
+ }
+}
+
+bool cmStrictTargetComparison::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()->GetStartOutputDirectory(),
+ t2->GetMakefile()->GetStartOutputDirectory()) < 0;
+ }
+ return nameResult < 0;
+}
+
+//----------------------------------------------------------------------------
+struct cmGeneratorTarget::SourceFileFlags
+cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
+{
+ struct SourceFileFlags flags;
+ this->ConstructSourceFileFlags();
+ std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
+ this->SourceFlagsMap.find(sf);
+ if(si != this->SourceFlagsMap.end())
+ {
+ flags = si->second;
+ }
+ else
+ {
+ // Handle the MACOSX_PACKAGE_LOCATION property on source files that
+ // were not listed in one of the other lists.
+ if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
+ {
+ flags.MacFolder = location;
+ if(strcmp(location, "Resources") == 0)
+ {
+ flags.Type = cmGeneratorTarget::SourceFileTypeResource;
+ }
+ else
+ {
+ flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
+ }
+ }
+ }
+ return flags;
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::ConstructSourceFileFlags() const
+{
+ if(this->SourceFileFlagsConstructed)
+ {
+ return;
+ }
+ this->SourceFileFlagsConstructed = true;
+
+ // Process public headers to mark the source files.
+ if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
+ {
+ std::vector<std::string> relFiles;
+ cmSystemTools::ExpandListArgument(files, relFiles);
+ for(std::vector<std::string>::iterator it = relFiles.begin();
+ it != relFiles.end(); ++it)
+ {
+ if(cmSourceFile* sf = this->Makefile->GetSource(*it))
+ {
+ SourceFileFlags& flags = this->SourceFlagsMap[sf];
+ flags.MacFolder = "Headers";
+ flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
+ }
+ }
+ }
+
+ // 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"))
+ {
+ std::vector<std::string> relFiles;
+ cmSystemTools::ExpandListArgument(files, relFiles);
+ for(std::vector<std::string>::iterator it = relFiles.begin();
+ it != relFiles.end(); ++it)
+ {
+ if(cmSourceFile* sf = this->Makefile->GetSource(*it))
+ {
+ SourceFileFlags& flags = this->SourceFlagsMap[sf];
+ flags.MacFolder = "PrivateHeaders";
+ flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
+ }
+ }
+ }
+
+ // Mark sources listed as resources.
+ if(const char* files = this->Target->GetProperty("RESOURCE"))
+ {
+ std::vector<std::string> relFiles;
+ cmSystemTools::ExpandListArgument(files, relFiles);
+ for(std::vector<std::string>::iterator it = relFiles.begin();
+ it != relFiles.end(); ++it)
+ {
+ if(cmSourceFile* sf = this->Makefile->GetSource(*it))
+ {
+ SourceFileFlags& flags = this->SourceFlagsMap[sf];
+ flags.MacFolder = "Resources";
+ flags.Type = cmGeneratorTarget::SourceFileTypeResource;
+ }
+ }
+ }
+}
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
new file mode 100644
index 0000000000..2083b88587
--- /dev/null
+++ b/Source/cmGeneratorTarget.h
@@ -0,0 +1,161 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 cmGeneratorTarget_h
+#define cmGeneratorTarget_h
+
+#include "cmStandardIncludes.h"
+
+class cmCustomCommand;
+class cmGlobalGenerator;
+class cmLocalGenerator;
+class cmMakefile;
+class cmSourceFile;
+class cmTarget;
+
+class cmGeneratorTarget
+{
+public:
+ cmGeneratorTarget(cmTarget*);
+
+ int GetType() const;
+ std::string GetName() const;
+ const char *GetProperty(const std::string& prop) const;
+ bool GetPropertyAsBool(const std::string& prop) const;
+ void GetSourceFiles(std::vector<cmSourceFile*>& files,
+ const std::string& config) const;
+
+ void GetObjectSources(std::vector<cmSourceFile const*> &,
+ const std::string& config) const;
+ const std::string& GetObjectName(cmSourceFile const* file);
+
+ bool HasExplicitObjectName(cmSourceFile const* file) const;
+ void AddExplicitObjectName(cmSourceFile const* sf);
+
+ void GetResxSources(std::vector<cmSourceFile const*>&,
+ const std::string& config) const;
+ void GetIDLSources(std::vector<cmSourceFile const*>&,
+ const std::string& config) const;
+ void GetExternalObjects(std::vector<cmSourceFile const*>&,
+ const std::string& config) const;
+ void GetHeaderSources(std::vector<cmSourceFile const*>&,
+ const std::string& config) const;
+ void GetExtraSources(std::vector<cmSourceFile const*>&,
+ const std::string& config) const;
+ void GetCustomCommands(std::vector<cmSourceFile const*>&,
+ const std::string& config) const;
+ void GetExpectedResxHeaders(std::set<std::string>&,
+ const std::string& config) const;
+ void GetAppManifest(std::vector<cmSourceFile const*>&,
+ const std::string& config) const;
+ void GetCertificates(std::vector<cmSourceFile const*>&,
+ const std::string& config) const;
+
+ void ComputeObjectMapping();
+
+ cmTarget* Target;
+ cmMakefile* Makefile;
+ cmLocalGenerator* LocalGenerator;
+ cmGlobalGenerator const* GlobalGenerator;
+
+ std::string GetModuleDefinitionFile(const std::string& config) const;
+
+ /** Full path with trailing slash to the top-level directory
+ holding object files for this target. Includes the build
+ time config name placeholder if needed for the generator. */
+ std::string ObjectDirectory;
+
+ void UseObjectLibraries(std::vector<std::string>& objs,
+ const std::string& config) const;
+
+ void GetAppleArchs(const std::string& config,
+ std::vector<std::string>& archVec) const;
+
+ /** Return the rule variable used to create this type of target. */
+ std::string GetCreateRuleVariable(std::string const& lang,
+ std::string const& config) const;
+
+ /** Get the include directories for this target. */
+ std::vector<std::string> GetIncludeDirectories(
+ const std::string& config) const;
+
+ bool IsSystemIncludeDirectory(const std::string& dir,
+ const std::string& config) const;
+
+ /** Add the target output files to the global generator manifest. */
+ void GenerateTargetManifest(const std::string& config) const;
+
+ /**
+ * Trace through the source files in this target and add al source files
+ * that they depend on, used by all generators
+ */
+ void TraceDependencies();
+
+ /** Get sources that must be built before the given source. */
+ std::vector<cmSourceFile*> const*
+ GetSourceDepends(cmSourceFile const* sf) const;
+
+ /**
+ * 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.
+ */
+ enum SourceFileType
+ {
+ SourceFileTypeNormal,
+ SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
+ SourceFileTypePublicHeader, // is in "PUBLIC_HEADER" target property
+ SourceFileTypeResource, // is in "RESOURCE" target property *or*
+ // has MACOSX_PACKAGE_LOCATION=="Resources"
+ SourceFileTypeMacContent // has MACOSX_PACKAGE_LOCATION!="Resources"
+ };
+ struct SourceFileFlags
+ {
+ SourceFileFlags(): Type(SourceFileTypeNormal), MacFolder(0) {}
+ SourceFileFlags(SourceFileFlags const& r):
+ Type(r.Type), MacFolder(r.MacFolder) {}
+ SourceFileType Type;
+ const char* MacFolder; // location inside Mac content folders
+ };
+
+ struct SourceFileFlags
+ GetTargetSourceFileFlags(const cmSourceFile* sf) const;
+
+ struct ResxData {
+ mutable std::set<std::string> ExpectedResxHeaders;
+ mutable std::vector<cmSourceFile const*> ResxSources;
+ };
+private:
+ friend class cmTargetTraceDependencies;
+ struct SourceEntry { std::vector<cmSourceFile*> Depends; };
+ typedef std::map<cmSourceFile const*, SourceEntry> SourceEntriesType;
+ SourceEntriesType SourceEntries;
+
+ mutable std::map<cmSourceFile const*, std::string> Objects;
+ std::set<cmSourceFile const*> ExplicitObjectName;
+ mutable std::map<std::string, std::vector<std::string> > SystemIncludesCache;
+
+ void ConstructSourceFileFlags() const;
+ mutable bool SourceFileFlagsConstructed;
+ mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
+
+ cmGeneratorTarget(cmGeneratorTarget const&);
+ void operator=(cmGeneratorTarget const&);
+};
+
+struct cmStrictTargetComparison {
+ bool operator()(cmTarget const* t1, cmTarget const* t2) const;
+};
+
+typedef std::map<cmTarget const*,
+ cmGeneratorTarget*,
+ cmStrictTargetComparison> cmGeneratorTargetsType;
+
+#endif
diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx
new file mode 100644
index 0000000000..e88f498b7c
--- /dev/null
+++ b/Source/cmGetCMakePropertyCommand.cxx
@@ -0,0 +1,79 @@
+/*============================================================================
+ 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 "cmGetCMakePropertyCommand.h"
+
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmake.h"
+
+// cmGetCMakePropertyCommand
+bool cmGetCMakePropertyCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::vector<std::string>::size_type cc;
+ std::string variable = args[0];
+ std::string output = "NOTFOUND";
+
+ if ( args[1] == "VARIABLES" )
+ {
+ int cacheonly = 0;
+ std::vector<std::string> vars = this->Makefile->GetDefinitions(cacheonly);
+ if (vars.size()>0)
+ {
+ output = vars[0];
+ }
+ for ( cc = 1; cc < vars.size(); ++cc )
+ {
+ output += ";";
+ output += vars[cc];
+ }
+ }
+ else if ( args[1] == "MACROS" )
+ {
+ this->Makefile->GetListOfMacros(output);
+ }
+ else if ( args[1] == "COMPONENTS" )
+ {
+ const std::set<std::string>* components
+ = this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->GetInstallComponents();
+ std::set<std::string>::const_iterator compIt;
+ output = "";
+ for (compIt = components->begin(); compIt != components->end(); ++compIt)
+ {
+ if (compIt != components->begin())
+ {
+ output += ";";
+ }
+ output += *compIt;
+ }
+ }
+ else
+ {
+ const char *prop =
+ this->Makefile->GetCMakeInstance()->GetProperty(args[1]);
+ if (prop)
+ {
+ output = prop;
+ }
+ }
+
+ this->Makefile->AddDefinition(variable, output.c_str());
+
+ return true;
+}
diff --git a/Source/cmGetCMakePropertyCommand.h b/Source/cmGetCMakePropertyCommand.h
new file mode 100644
index 0000000000..15114064ed
--- /dev/null
+++ b/Source/cmGetCMakePropertyCommand.h
@@ -0,0 +1,47 @@
+/*============================================================================
+ 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 cmGetCMakePropertyCommand_h
+#define cmGetCMakePropertyCommand_h
+
+#include "cmCommand.h"
+
+class cmGetCMakePropertyCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmGetCMakePropertyCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input 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 "get_cmake_property";}
+
+ cmTypeMacro(cmGetCMakePropertyCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmGetDirectoryPropertyCommand.cxx b/Source/cmGetDirectoryPropertyCommand.cxx
new file mode 100644
index 0000000000..fcc3da16e5
--- /dev/null
+++ b/Source/cmGetDirectoryPropertyCommand.cxx
@@ -0,0 +1,96 @@
+/*============================================================================
+ 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 "cmGetDirectoryPropertyCommand.h"
+
+#include "cmake.h"
+
+// cmGetDirectoryPropertyCommand
+bool cmGetDirectoryPropertyCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::vector<std::string>::const_iterator i = args.begin();
+ std::string variable = *i;
+ ++i;
+ std::string output = "";
+
+ // get the directory argument if there is one
+ cmMakefile *dir = this->Makefile;
+ if (*i == "DIRECTORY")
+ {
+ ++i;
+ if (i == args.end())
+ {
+ this->SetError
+ ("DIRECTORY argument provided without subsequent arguments");
+ return false;
+ }
+ std::string sd = *i;
+ // make sure the start dir is a full path
+ if (!cmSystemTools::FileIsFullPath(sd.c_str()))
+ {
+ sd = this->Makefile->GetStartDirectory();
+ sd += "/";
+ sd += *i;
+ }
+
+ // The local generators are associated with collapsed paths.
+ sd = cmSystemTools::CollapseFullPath(sd.c_str());
+
+ // lookup the makefile from the directory name
+ cmLocalGenerator *lg =
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
+ FindLocalGenerator(sd);
+ if (!lg)
+ {
+ this->SetError
+ ("DIRECTORY argument provided but requested directory not found. "
+ "This could be because the directory argument was invalid or, "
+ "it is valid but has not been processed yet.");
+ return false;
+ }
+ dir = lg->GetMakefile();
+ ++i;
+ }
+
+ // OK, now we have the directory to process, we just get the requested
+ // information out of it
+
+ if ( *i == "DEFINITION" )
+ {
+ ++i;
+ if (i == args.end())
+ {
+ this->SetError("A request for a variable definition was made without "
+ "providing the name of the variable to get.");
+ return false;
+ }
+ output = dir->GetSafeDefinition(*i);
+ this->Makefile->AddDefinition(variable, output.c_str());
+ return true;
+ }
+
+ const char *prop = dir->GetProperty(*i);
+ if (prop)
+ {
+ this->Makefile->AddDefinition(variable, prop);
+ return true;
+ }
+ this->Makefile->AddDefinition(variable, "");
+ return true;
+}
+
diff --git a/Source/cmGetDirectoryPropertyCommand.h b/Source/cmGetDirectoryPropertyCommand.h
new file mode 100644
index 0000000000..6c5750a9c8
--- /dev/null
+++ b/Source/cmGetDirectoryPropertyCommand.h
@@ -0,0 +1,47 @@
+/*============================================================================
+ 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 cmGetDirectoryPropertyCommand_h
+#define cmGetDirectoryPropertyCommand_h
+
+#include "cmCommand.h"
+
+class cmGetDirectoryPropertyCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmGetDirectoryPropertyCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input 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 "get_directory_property";}
+
+ cmTypeMacro(cmGetDirectoryPropertyCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmGetFilenameComponentCommand.cxx b/Source/cmGetFilenameComponentCommand.cxx
new file mode 100644
index 0000000000..10406d2d03
--- /dev/null
+++ b/Source/cmGetFilenameComponentCommand.cxx
@@ -0,0 +1,139 @@
+/*============================================================================
+ 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 "cmGetFilenameComponentCommand.h"
+#include "cmSystemTools.h"
+
+// cmGetFilenameComponentCommand
+bool cmGetFilenameComponentCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 3)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // Check and see if the value has been stored in the cache
+ // already, if so use that value
+ if(args.size() == 4 && args[3] == "CACHE")
+ {
+ const char* cacheValue = this->Makefile->GetDefinition(args[0]);
+ if(cacheValue && !cmSystemTools::IsNOTFOUND(cacheValue))
+ {
+ return true;
+ }
+ }
+
+ std::string result;
+ std::string filename = args[1];
+ if(filename.find("[HKEY") != filename.npos)
+ {
+ // Check the registry as the target application would view it.
+ cmSystemTools::KeyWOW64 view = cmSystemTools::KeyWOW64_32;
+ cmSystemTools::KeyWOW64 other_view = cmSystemTools::KeyWOW64_64;
+ if(this->Makefile->PlatformIs64Bit())
+ {
+ view = cmSystemTools::KeyWOW64_64;
+ other_view = cmSystemTools::KeyWOW64_32;
+ }
+ cmSystemTools::ExpandRegistryValues(filename, view);
+ if(filename.find("/registry") != filename.npos)
+ {
+ std::string other = args[1];
+ cmSystemTools::ExpandRegistryValues(other, other_view);
+ if(other.find("/registry") == other.npos)
+ {
+ filename = other;
+ }
+ }
+ }
+ std::string storeArgs;
+ std::string programArgs;
+ if (args[2] == "DIRECTORY" || args[2] == "PATH")
+ {
+ result = cmSystemTools::GetFilenamePath(filename);
+ }
+ else if (args[2] == "NAME")
+ {
+ result = cmSystemTools::GetFilenameName(filename);
+ }
+ else if (args[2] == "PROGRAM")
+ {
+ for(unsigned int i=2; i < args.size(); ++i)
+ {
+ if(args[i] == "PROGRAM_ARGS")
+ {
+ i++;
+ if(i < args.size())
+ {
+ storeArgs = args[i];
+ }
+ }
+ }
+ cmSystemTools::SplitProgramFromArgs(filename.c_str(),
+ result, programArgs);
+ }
+ else if (args[2] == "EXT")
+ {
+ result = cmSystemTools::GetFilenameExtension(filename);
+ }
+ else if (args[2] == "NAME_WE")
+ {
+ result = cmSystemTools::GetFilenameWithoutExtension(filename);
+ }
+ else if (args[2] == "ABSOLUTE" ||
+ args[2] == "REALPATH")
+ {
+ // Collapse the path to its simplest form.
+ // If the path given is relative evaluate it relative to the
+ // current source directory.
+ result = cmSystemTools::CollapseFullPath(
+ filename.c_str(), this->Makefile->GetCurrentDirectory());
+ if(args[2] == "REALPATH")
+ {
+ // Resolve symlinks if possible
+ result = cmSystemTools::GetRealPath(result.c_str());
+ }
+ }
+ else
+ {
+ std::string err = "unknown component " + args[2];
+ this->SetError(err);
+ return false;
+ }
+
+ if(args.size() == 4 && args[3] == "CACHE")
+ {
+ if(programArgs.size() && storeArgs.size())
+ {
+ this->Makefile->AddCacheDefinition
+ (storeArgs, programArgs.c_str(),
+ "", args[2] == "PATH" ? cmCacheManager::FILEPATH
+ : cmCacheManager::STRING);
+ }
+ this->Makefile->AddCacheDefinition
+ (args[0], result.c_str(), "",
+ args[2] == "PATH" ? cmCacheManager::FILEPATH
+ : cmCacheManager::STRING);
+ }
+ else
+ {
+ if(programArgs.size() && storeArgs.size())
+ {
+ this->Makefile->AddDefinition(storeArgs, programArgs.c_str());
+ }
+ this->Makefile->AddDefinition(args[0], result.c_str());
+ }
+
+ return true;
+}
+
diff --git a/Source/cmGetFilenameComponentCommand.h b/Source/cmGetFilenameComponentCommand.h
new file mode 100644
index 0000000000..534de53d10
--- /dev/null
+++ b/Source/cmGetFilenameComponentCommand.h
@@ -0,0 +1,56 @@
+/*============================================================================
+ 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 cmGetFilenameComponentCommand_h
+#define cmGetFilenameComponentCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmGetFilenameComponentCommand
+ * \brief Get a specific component of a filename.
+ *
+ * cmGetFilenameComponentCommand is a utility command used to get the path,
+ * name, extension or name without extension of a full filename.
+ */
+class cmGetFilenameComponentCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmGetFilenameComponentCommand;
+ }
+
+ /**
+ * 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 "get_filename_component";}
+
+ cmTypeMacro(cmGetFilenameComponentCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx
new file mode 100644
index 0000000000..9a88191f41
--- /dev/null
+++ b/Source/cmGetPropertyCommand.cxx
@@ -0,0 +1,432 @@
+/*============================================================================
+ 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 "cmGetPropertyCommand.h"
+
+#include "cmake.h"
+#include "cmTest.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSourceFile.h"
+#include "cmPropertyDefinition.h"
+
+//----------------------------------------------------------------------------
+cmGetPropertyCommand::cmGetPropertyCommand()
+{
+ this->InfoType = OutValue;
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 3 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // The cmake variable in which to store the result.
+ this->Variable = args[0];
+
+ // Get the scope from which to get the property.
+ cmProperty::ScopeType scope;
+ if(args[1] == "GLOBAL")
+ {
+ scope = cmProperty::GLOBAL;
+ }
+ else if(args[1] == "DIRECTORY")
+ {
+ scope = cmProperty::DIRECTORY;
+ }
+ else if(args[1] == "TARGET")
+ {
+ scope = cmProperty::TARGET;
+ }
+ else if(args[1] == "SOURCE")
+ {
+ scope = cmProperty::SOURCE_FILE;
+ }
+ else if(args[1] == "TEST")
+ {
+ scope = cmProperty::TEST;
+ }
+ else if(args[1] == "VARIABLE")
+ {
+ scope = cmProperty::VARIABLE;
+ }
+ else if(args[1] == "CACHE")
+ {
+ scope = cmProperty::CACHE;
+ }
+ else if(args[1] == "INSTALL")
+ {
+ scope = cmProperty::INSTALL;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given invalid scope " << args[1] << ". "
+ << "Valid scopes are "
+ << "GLOBAL, DIRECTORY, TARGET, SOURCE, TEST, VARIABLE, CACHE, INSTALL.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Parse remaining arguments.
+ enum Doing { DoingNone, DoingName, DoingProperty, DoingType };
+ Doing doing = DoingName;
+ for(unsigned int i=2; i < args.size(); ++i)
+ {
+ if(args[i] == "PROPERTY")
+ {
+ doing = DoingProperty;
+ }
+ else if(args[i] == "BRIEF_DOCS")
+ {
+ doing = DoingNone;
+ this->InfoType = OutBriefDoc;
+ }
+ else if(args[i] == "FULL_DOCS")
+ {
+ doing = DoingNone;
+ this->InfoType = OutFullDoc;
+ }
+ else if(args[i] == "SET")
+ {
+ doing = DoingNone;
+ this->InfoType = OutSet;
+ }
+ else if(args[i] == "DEFINED")
+ {
+ doing = DoingNone;
+ this->InfoType = OutDefined;
+ }
+ else if(doing == DoingName)
+ {
+ doing = DoingNone;
+ this->Name = args[i];
+ }
+ else if(doing == DoingProperty)
+ {
+ doing = DoingNone;
+ this->PropertyName = args[i];
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given invalid argument \"" << args[i] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // Make sure a property name was found.
+ if(this->PropertyName.empty())
+ {
+ this->SetError("not given a PROPERTY <name> argument.");
+ return false;
+ }
+
+ // Compute requested output.
+ if(this->InfoType == OutBriefDoc)
+ {
+ // Lookup brief documentation.
+ std::string output;
+ if(cmPropertyDefinition* def =
+ this->Makefile->GetCMakeInstance()->
+ GetPropertyDefinition(this->PropertyName, scope))
+ {
+ output = def->GetShortDescription();
+ }
+ else
+ {
+ output = "NOTFOUND";
+ }
+ this->Makefile->AddDefinition(this->Variable, output.c_str());
+ }
+ else if(this->InfoType == OutFullDoc)
+ {
+ // Lookup full documentation.
+ std::string output;
+ if(cmPropertyDefinition* def =
+ this->Makefile->GetCMakeInstance()->
+ GetPropertyDefinition(this->PropertyName, scope))
+ {
+ output = def->GetFullDescription();
+ }
+ else
+ {
+ output = "NOTFOUND";
+ }
+ this->Makefile->AddDefinition(this->Variable, output.c_str());
+ }
+ else if(this->InfoType == OutDefined)
+ {
+ // Lookup if the property is defined
+ if(this->Makefile->GetCMakeInstance()->
+ GetPropertyDefinition(this->PropertyName, scope))
+ {
+ this->Makefile->AddDefinition(this->Variable, "1");
+ }
+ else
+ {
+ this->Makefile->AddDefinition(this->Variable, "0");
+ }
+ }
+ else
+ {
+ // Dispatch property getting.
+ switch(scope)
+ {
+ case cmProperty::GLOBAL: return this->HandleGlobalMode();
+ case cmProperty::DIRECTORY: return this->HandleDirectoryMode();
+ case cmProperty::TARGET: return this->HandleTargetMode();
+ case cmProperty::SOURCE_FILE: return this->HandleSourceMode();
+ case cmProperty::TEST: return this->HandleTestMode();
+ case cmProperty::VARIABLE: return this->HandleVariableMode();
+ case cmProperty::CACHE: return this->HandleCacheMode();
+ case cmProperty::INSTALL: return this->HandleInstallMode();
+
+ case cmProperty::CACHED_VARIABLE:
+ break; // should never happen
+ }
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand::StoreResult(const char* value)
+{
+ if(this->InfoType == OutSet)
+ {
+ this->Makefile->AddDefinition(this->Variable, value? "1":"0");
+ }
+ else // if(this->InfoType == OutValue)
+ {
+ if(value)
+ {
+ this->Makefile->AddDefinition(this->Variable, value);
+ }
+ else
+ {
+ this->Makefile->RemoveDefinition(this->Variable);
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand::HandleGlobalMode()
+{
+ if(!this->Name.empty())
+ {
+ this->SetError("given name for GLOBAL scope.");
+ return false;
+ }
+
+ // Get the property.
+ cmake* cm = this->Makefile->GetCMakeInstance();
+ return this->StoreResult(cm->GetProperty(this->PropertyName));
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand::HandleDirectoryMode()
+{
+ // Default to the current directory.
+ cmMakefile* mf = this->Makefile;
+
+ // Lookup the directory if given.
+ if(!this->Name.empty())
+ {
+ // Construct the directory name. Interpret relative paths with
+ // respect to the current directory.
+ std::string dir = this->Name;
+ if(!cmSystemTools::FileIsFullPath(dir.c_str()))
+ {
+ dir = this->Makefile->GetCurrentDirectory();
+ dir += "/";
+ dir += this->Name;
+ }
+
+ // The local generators are associated with collapsed paths.
+ dir = cmSystemTools::CollapseFullPath(dir.c_str());
+
+ // Lookup the generator.
+ if(cmLocalGenerator* lg =
+ (this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->FindLocalGenerator(dir)))
+ {
+ // Use the makefile for the directory found.
+ mf = lg->GetMakefile();
+ }
+ else
+ {
+ // Could not find the directory.
+ this->SetError
+ ("DIRECTORY scope provided but requested directory was not found. "
+ "This could be because the directory argument was invalid or, "
+ "it is valid but has not been processed yet.");
+ return false;
+ }
+ }
+
+ // Get the property.
+ return this->StoreResult(mf->GetProperty(this->PropertyName));
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand::HandleTargetMode()
+{
+ if(this->Name.empty())
+ {
+ this->SetError("not given name for TARGET scope.");
+ return false;
+ }
+
+ if(this->PropertyName == "ALIASED_TARGET")
+ {
+ if(this->Makefile->IsAlias(this->Name))
+ {
+ if(cmTarget* target =
+ this->Makefile->FindTargetToUse(this->Name))
+ {
+ return this->StoreResult(target->GetName().c_str());
+ }
+ }
+ return this->StoreResult((this->Variable + "-NOTFOUND").c_str());
+ }
+ if(cmTarget* target = this->Makefile->FindTargetToUse(this->Name))
+ {
+ return this->StoreResult(target->GetProperty(this->PropertyName,
+ this->Makefile));
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "could not find TARGET " << this->Name
+ << ". Perhaps it has not yet been created.";
+ this->SetError(e.str());
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand::HandleSourceMode()
+{
+ if(this->Name.empty())
+ {
+ this->SetError("not given name for SOURCE scope.");
+ return false;
+ }
+
+ // Get the source file.
+ if(cmSourceFile* sf =
+ this->Makefile->GetOrCreateSource(this->Name))
+ {
+ return
+ this->StoreResult(sf->GetPropertyForUser(this->PropertyName));
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given SOURCE name that could not be found or created: "
+ << this->Name;
+ this->SetError(e.str());
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand::HandleTestMode()
+{
+ if(this->Name.empty())
+ {
+ this->SetError("not given name for TEST scope.");
+ return false;
+ }
+
+ // Loop over all tests looking for matching names.
+ if(cmTest* test = this->Makefile->GetTest(this->Name))
+ {
+ return this->StoreResult(test->GetProperty(this->PropertyName));
+ }
+
+ // If not found it is an error.
+ cmOStringStream e;
+ e << "given TEST name that does not exist: " << this->Name;
+ this->SetError(e.str());
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand::HandleVariableMode()
+{
+ if(!this->Name.empty())
+ {
+ this->SetError("given name for VARIABLE scope.");
+ return false;
+ }
+
+ return this->StoreResult
+ (this->Makefile->GetDefinition(this->PropertyName));
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand::HandleCacheMode()
+{
+ if(this->Name.empty())
+ {
+ this->SetError("not given name for CACHE scope.");
+ return false;
+ }
+
+ const char* value = 0;
+ cmCacheManager::CacheIterator it =
+ this->Makefile->GetCacheManager()->GetCacheIterator(this->Name.c_str());
+ if(!it.IsAtEnd())
+ {
+ value = it.GetProperty(this->PropertyName);
+ }
+ this->StoreResult(value);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGetPropertyCommand::HandleInstallMode()
+{
+ if(this->Name.empty())
+ {
+ this->SetError("not given name for INSTALL scope.");
+ return false;
+ }
+
+ // Get the installed file.
+ cmake* cm = this->Makefile->GetCMakeInstance();
+
+ if(cmInstalledFile* file = cm->GetOrCreateInstalledFile(
+ this->Makefile, this->Name))
+ {
+ std::string value;
+ bool isSet = file->GetProperty(this->PropertyName, value);
+
+ return this->StoreResult(isSet ? value.c_str() : 0);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given INSTALL name that could not be found or created: "
+ << this->Name;
+ this->SetError(e.str());
+ return false;
+ }
+}
diff --git a/Source/cmGetPropertyCommand.h b/Source/cmGetPropertyCommand.h
new file mode 100644
index 0000000000..40b7dbc009
--- /dev/null
+++ b/Source/cmGetPropertyCommand.h
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 cmGetPropertyCommand_h
+#define cmGetPropertyCommand_h
+
+#include "cmCommand.h"
+
+class cmGetPropertyCommand : public cmCommand
+{
+public:
+ cmGetPropertyCommand();
+
+ virtual cmCommand* Clone()
+ {
+ return new cmGetPropertyCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input 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 "get_property";}
+
+ cmTypeMacro(cmGetPropertyCommand, cmCommand);
+private:
+ enum OutType { OutValue, OutDefined, OutBriefDoc, OutFullDoc, OutSet };
+ std::string Variable;
+ std::string Name;
+ std::string PropertyName;
+ OutType InfoType;
+
+ // Implementation of result storage.
+ bool StoreResult(const char* value);
+
+ // Implementation of each property type.
+ bool HandleGlobalMode();
+ bool HandleDirectoryMode();
+ bool HandleTargetMode();
+ bool HandleSourceMode();
+ bool HandleTestMode();
+ bool HandleVariableMode();
+ bool HandleCacheMode();
+ bool HandleInstallMode();
+};
+
+#endif
diff --git a/Source/cmGetSourceFilePropertyCommand.cxx b/Source/cmGetSourceFilePropertyCommand.cxx
new file mode 100644
index 0000000000..7667a8592a
--- /dev/null
+++ b/Source/cmGetSourceFilePropertyCommand.cxx
@@ -0,0 +1,52 @@
+/*============================================================================
+ 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 "cmGetSourceFilePropertyCommand.h"
+
+#include "cmSourceFile.h"
+
+// cmSetSourceFilePropertyCommand
+bool cmGetSourceFilePropertyCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() != 3 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ const char* var = args[0].c_str();
+ const char* file = args[1].c_str();
+ cmSourceFile* sf = this->Makefile->GetSource(file);
+
+ // for the location we must create a source file first
+ if (!sf && args[2] == "LOCATION")
+ {
+ sf = this->Makefile->CreateSource(file);
+ }
+ if(sf)
+ {
+ if(args[2] == "LANGUAGE")
+ {
+ this->Makefile->AddDefinition(var, sf->GetLanguage().c_str());
+ return true;
+ }
+ const char *prop = sf->GetPropertyForUser(args[2]);
+ if (prop)
+ {
+ this->Makefile->AddDefinition(var, prop);
+ return true;
+ }
+ }
+
+ this->Makefile->AddDefinition(var, "NOTFOUND");
+ return true;
+}
+
diff --git a/Source/cmGetSourceFilePropertyCommand.h b/Source/cmGetSourceFilePropertyCommand.h
new file mode 100644
index 0000000000..ab8ce365b7
--- /dev/null
+++ b/Source/cmGetSourceFilePropertyCommand.h
@@ -0,0 +1,42 @@
+/*============================================================================
+ 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 cmGetSourceFilePropertyCommand_h
+#define cmGetSourceFilePropertyCommand_h
+
+#include "cmCommand.h"
+
+class cmGetSourceFilePropertyCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmGetSourceFilePropertyCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "get_source_file_property";}
+
+ cmTypeMacro(cmGetSourceFilePropertyCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx
new file mode 100644
index 0000000000..aa6f0c11cc
--- /dev/null
+++ b/Source/cmGetTargetPropertyCommand.cxx
@@ -0,0 +1,85 @@
+/*============================================================================
+ 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 "cmGetTargetPropertyCommand.h"
+
+// cmSetTargetPropertyCommand
+bool cmGetTargetPropertyCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() != 3 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ std::string var = args[0];
+ const std::string& targetName = args[1];
+ std::string prop;
+
+ if(args[2] == "ALIASED_TARGET")
+ {
+ if(this->Makefile->IsAlias(targetName))
+ {
+ if(cmTarget* target =
+ this->Makefile->FindTargetToUse(targetName))
+ {
+ prop = target->GetName();
+ }
+ }
+ }
+ else if(cmTarget* tgt = this->Makefile->FindTargetToUse(targetName))
+ {
+ cmTarget& target = *tgt;
+ const char* prop_cstr = target.GetProperty(args[2], this->Makefile);
+ if(prop_cstr)
+ {
+ prop = prop_cstr;
+ }
+ }
+ else
+ {
+ bool issueMessage = false;
+ cmOStringStream e;
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0045))
+ {
+ case cmPolicies::WARN:
+ issueMessage = true;
+ e << this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0045) << "\n";
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ issueMessage = true;
+ messageType = cmake::FATAL_ERROR;
+ }
+ if (issueMessage)
+ {
+ e << "get_target_property() called with non-existent target \""
+ << targetName << "\".";
+ this->Makefile->IssueMessage(messageType, e.str());
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return false;
+ }
+ }
+ }
+ if (!prop.empty())
+ {
+ this->Makefile->AddDefinition(var, prop.c_str());
+ return true;
+ }
+ this->Makefile->AddDefinition(var, (var+"-NOTFOUND").c_str());
+ return true;
+}
+
diff --git a/Source/cmGetTargetPropertyCommand.h b/Source/cmGetTargetPropertyCommand.h
new file mode 100644
index 0000000000..a35c6fe9d0
--- /dev/null
+++ b/Source/cmGetTargetPropertyCommand.h
@@ -0,0 +1,42 @@
+/*============================================================================
+ 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 cmGetTargetPropertyCommand_h
+#define cmGetTargetPropertyCommand_h
+
+#include "cmCommand.h"
+
+class cmGetTargetPropertyCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmGetTargetPropertyCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "get_target_property";}
+
+ cmTypeMacro(cmGetTargetPropertyCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmGetTestPropertyCommand.cxx b/Source/cmGetTestPropertyCommand.cxx
new file mode 100644
index 0000000000..b3df4c3bca
--- /dev/null
+++ b/Source/cmGetTestPropertyCommand.cxx
@@ -0,0 +1,42 @@
+/*============================================================================
+ 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 "cmGetTestPropertyCommand.h"
+
+#include "cmake.h"
+#include "cmTest.h"
+
+// cmGetTestPropertyCommand
+bool cmGetTestPropertyCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 3 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::string testName = args[0];
+ std::string var = args[2];
+ cmTest *test = this->Makefile->GetTest(testName);
+ if (test)
+ {
+ const char *prop = test->GetProperty(args[1]);
+ if (prop)
+ {
+ this->Makefile->AddDefinition(var, prop);
+ return true;
+ }
+ }
+ this->Makefile->AddDefinition(var, "NOTFOUND");
+ return true;
+}
+
diff --git a/Source/cmGetTestPropertyCommand.h b/Source/cmGetTestPropertyCommand.h
new file mode 100644
index 0000000000..2819492eed
--- /dev/null
+++ b/Source/cmGetTestPropertyCommand.h
@@ -0,0 +1,42 @@
+/*============================================================================
+ 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 cmGetTestPropertyCommand_h
+#define cmGetTestPropertyCommand_h
+
+#include "cmCommand.h"
+
+class cmGetTestPropertyCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmGetTestPropertyCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "get_test_property";}
+
+ cmTypeMacro(cmGetTestPropertyCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmGlobalBorlandMakefileGenerator.cxx b/Source/cmGlobalBorlandMakefileGenerator.cxx
new file mode 100644
index 0000000000..6c209522d0
--- /dev/null
+++ b/Source/cmGlobalBorlandMakefileGenerator.cxx
@@ -0,0 +1,62 @@
+/*============================================================================
+ 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 "cmGlobalBorlandMakefileGenerator.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+
+cmGlobalBorlandMakefileGenerator::cmGlobalBorlandMakefileGenerator()
+{
+ this->EmptyRuleHackDepends = "NUL";
+ this->FindMakeProgramFile = "CMakeBorlandFindMake.cmake";
+ this->ForceUnixPaths = false;
+ this->ToolSupportsColor = true;
+ this->UseLinkScript = false;
+}
+
+
+void cmGlobalBorlandMakefileGenerator
+::EnableLanguage(std::vector<std::string>const& l,
+ cmMakefile *mf,
+ bool optional)
+{
+ std::string outdir = this->CMakeInstance->GetStartOutputDirectory();
+ mf->AddDefinition("BORLAND", "1");
+ mf->AddDefinition("CMAKE_GENERATOR_CC", "bcc32");
+ mf->AddDefinition("CMAKE_GENERATOR_CXX", "bcc32");
+ this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalBorlandMakefileGenerator::CreateLocalGenerator()
+{
+ cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
+ lg->SetIncludeDirective("!include");
+ lg->SetWindowsShell(true);
+ lg->SetDefineWindowsNULL(true);
+ lg->SetMakefileVariableSize(32);
+ lg->SetPassMakeflags(true);
+ lg->SetGlobalGenerator(this);
+ lg->SetUnixCD(false);
+ lg->SetMakeCommandEscapeTargetTwice(true);
+ lg->SetBorlandMakeCurlyHack(true);
+ return lg;
+}
+
+
+//----------------------------------------------------------------------------
+void cmGlobalBorlandMakefileGenerator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalBorlandMakefileGenerator::GetActualName();
+ entry.Brief = "Generates Borland makefiles.";
+}
diff --git a/Source/cmGlobalBorlandMakefileGenerator.h b/Source/cmGlobalBorlandMakefileGenerator.h
new file mode 100644
index 0000000000..120d2f8075
--- /dev/null
+++ b/Source/cmGlobalBorlandMakefileGenerator.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmGlobalBorlandMakefileGenerator_h
+#define cmGlobalBorlandMakefileGenerator_h
+
+#include "cmGlobalNMakeMakefileGenerator.h"
+
+/** \class cmGlobalBorlandMakefileGenerator
+ * \brief Write a Borland makefiles.
+ *
+ * cmGlobalBorlandMakefileGenerator manages nmake build process for a tree
+ */
+class cmGlobalBorlandMakefileGenerator : public cmGlobalNMakeMakefileGenerator
+{
+public:
+ cmGlobalBorlandMakefileGenerator();
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalBorlandMakefileGenerator>(); }
+
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalBorlandMakefileGenerator::GetActualName();}
+ static std::string GetActualName() {return "Borland Makefiles";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+
+ virtual bool AllowNotParallel() const { return false; }
+};
+
+#endif
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
new file mode 100644
index 0000000000..ae0e807681
--- /dev/null
+++ b/Source/cmGlobalGenerator.cxx
@@ -0,0 +1,3067 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include "windows.h" // this must be first to define GetCurrentDirectory
+#endif
+
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmExternalMakefileProjectGenerator.h"
+#include "cmake.h"
+#include "cmMakefile.h"
+#include "cmQtAutoGenerators.h"
+#include "cmSourceFile.h"
+#include "cmVersion.h"
+#include "cmTargetExport.h"
+#include "cmComputeTargetDepends.h"
+#include "cmGeneratedFileStream.h"
+#include "cmGeneratorTarget.h"
+#include "cmGeneratorExpression.h"
+#include "cmGeneratorExpressionEvaluationFile.h"
+#include "cmExportBuildFileGenerator.h"
+#include "cmCPackPropertiesGenerator.h"
+
+#include <cmsys/Directory.hxx>
+#include <cmsys/FStream.hxx>
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include <cmsys/MD5.h>
+#endif
+
+#include <stdlib.h> // required for atof
+
+#include <assert.h>
+
+cmGlobalGenerator::cmGlobalGenerator()
+{
+ // By default the .SYMBOLIC dependency is not needed on symbolic rules.
+ this->NeedSymbolicMark = false;
+
+ // by default use the native paths
+ this->ForceUnixPaths = false;
+
+ // By default do not try to support color.
+ this->ToolSupportsColor = false;
+
+ // By default do not use link scripts.
+ this->UseLinkScript = false;
+
+ // Whether an install target is needed.
+ this->InstallTargetEnabled = false;
+
+ // how long to let try compiles run
+ this->TryCompileTimeout = 0;
+
+ this->ExtraGenerator = 0;
+ this->CurrentLocalGenerator = 0;
+ this->TryCompileOuterMakefile = 0;
+}
+
+cmGlobalGenerator::~cmGlobalGenerator()
+{
+ this->ClearGeneratorMembers();
+
+ if (this->ExtraGenerator)
+ {
+ delete this->ExtraGenerator;
+ }
+}
+
+bool cmGlobalGenerator::SetGeneratorPlatform(std::string const& p,
+ cmMakefile* mf)
+{
+ if(p.empty())
+ {
+ return true;
+ }
+ else
+ {
+ cmOStringStream e;
+ e <<
+ "Generator\n"
+ " " << this->GetName() << "\n"
+ "does not support platform specification, but platform\n"
+ " " << p << "\n"
+ "was specified.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+}
+
+bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts,
+ cmMakefile* mf)
+{
+ if(ts.empty())
+ {
+ return true;
+ }
+ else
+ {
+ cmOStringStream e;
+ e <<
+ "Generator\n"
+ " " << this->GetName() << "\n"
+ "does not support toolset specification, but toolset\n"
+ " " << ts << "\n"
+ "was specified.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+}
+
+std::string cmGlobalGenerator::SelectMakeProgram(
+ const std::string& inMakeProgram,
+ const std::string& makeDefault) const
+{
+ std::string makeProgram = inMakeProgram;
+ if(cmSystemTools::IsOff(makeProgram.c_str()))
+ {
+ const char* makeProgramCSTR =
+ this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
+ if(cmSystemTools::IsOff(makeProgramCSTR))
+ {
+ makeProgram = makeDefault;
+ }
+ else
+ {
+ makeProgram = makeProgramCSTR;
+ }
+ if(cmSystemTools::IsOff(makeProgram.c_str()) &&
+ !makeProgram.empty())
+ {
+ makeProgram = "CMAKE_MAKE_PROGRAM-NOTFOUND";
+ }
+ }
+ return makeProgram;
+}
+
+void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang,
+ cmMakefile *mf,
+ bool optional) const
+{
+ std::string langComp = "CMAKE_";
+ langComp += lang;
+ langComp += "_COMPILER";
+
+ if(!mf->GetDefinition(langComp))
+ {
+ if(!optional)
+ {
+ cmSystemTools::Error(langComp.c_str(),
+ " not set, after EnableLanguage");
+ }
+ return;
+ }
+ const char* name = mf->GetRequiredDefinition(langComp);
+ std::string path;
+ if(!cmSystemTools::FileIsFullPath(name))
+ {
+ path = cmSystemTools::FindProgram(name);
+ }
+ else
+ {
+ path = name;
+ }
+ if((path.size() == 0 || !cmSystemTools::FileExists(path.c_str()))
+ && (optional==false))
+ {
+ return;
+ }
+ const char* cname = this->GetCMakeInstance()->
+ GetCacheManager()->GetCacheValue(langComp);
+ std::string changeVars;
+ if(cname && !optional)
+ {
+ std::string cnameString;
+ if(!cmSystemTools::FileIsFullPath(cname))
+ {
+ cnameString = cmSystemTools::FindProgram(cname);
+ }
+ else
+ {
+ cnameString = cname;
+ }
+ std::string pathString = path;
+ // get rid of potentially multiple slashes:
+ cmSystemTools::ConvertToUnixSlashes(cnameString);
+ cmSystemTools::ConvertToUnixSlashes(pathString);
+ if (cnameString != pathString)
+ {
+ const char* cvars =
+ this->GetCMakeInstance()->GetProperty(
+ "__CMAKE_DELETE_CACHE_CHANGE_VARS_");
+ if(cvars)
+ {
+ changeVars += cvars;
+ changeVars += ";";
+ }
+ changeVars += langComp;
+ changeVars += ";";
+ changeVars += cname;
+ this->GetCMakeInstance()->SetProperty(
+ "__CMAKE_DELETE_CACHE_CHANGE_VARS_",
+ changeVars.c_str());
+ }
+ }
+}
+
+void cmGlobalGenerator::AddBuildExportSet(cmExportBuildFileGenerator* gen)
+{
+ this->BuildExportSets[gen->GetMainExportFileName()] = gen;
+}
+
+void
+cmGlobalGenerator::AddBuildExportExportSet(cmExportBuildFileGenerator* gen)
+{
+ this->BuildExportSets[gen->GetMainExportFileName()] = gen;
+ this->BuildExportExportSets[gen->GetMainExportFileName()] = gen;
+}
+
+bool cmGlobalGenerator::GenerateImportFile(const std::string &file)
+{
+ std::map<std::string, cmExportBuildFileGenerator*>::iterator it
+ = this->BuildExportSets.find(file);
+ if (it != this->BuildExportSets.end())
+ {
+ bool result = it->second->GenerateImportFile();
+ delete it->second;
+ it->second = 0;
+ this->BuildExportSets.erase(it);
+ return result;
+ }
+ return false;
+}
+
+void cmGlobalGenerator::ForceLinkerLanguages()
+{
+
+}
+
+bool
+cmGlobalGenerator::IsExportedTargetsFile(const std::string &filename) const
+{
+ const std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
+ = this->BuildExportSets.find(filename);
+ if (it == this->BuildExportSets.end())
+ {
+ return false;
+ }
+ return this->BuildExportExportSets.find(filename)
+ == this->BuildExportExportSets.end();
+}
+
+// Find the make program for the generator, required for try compiles
+void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
+{
+ if(this->FindMakeProgramFile.size() == 0)
+ {
+ cmSystemTools::Error(
+ "Generator implementation error, "
+ "all generators must specify this->FindMakeProgramFile");
+ }
+ if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
+ || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
+ {
+ std::string setMakeProgram =
+ mf->GetModulesFile(this->FindMakeProgramFile.c_str());
+ if(setMakeProgram.size())
+ {
+ mf->ReadListFile(0, setMakeProgram.c_str());
+ }
+ }
+ if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
+ || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
+ {
+ cmOStringStream err;
+ err << "CMake was unable to find a build program corresponding to \""
+ << this->GetName() << "\". CMAKE_MAKE_PROGRAM is not set. You "
+ << "probably need to select a different build tool.";
+ cmSystemTools::Error(err.str().c_str());
+ cmSystemTools::SetFatalErrorOccured();
+ return;
+ }
+ std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ // if there are spaces in the make program use short path
+ // but do not short path the actual program name, as
+ // this can cause trouble with VSExpress
+ if(makeProgram.find(' ') != makeProgram.npos)
+ {
+ std::string dir;
+ std::string file;
+ cmSystemTools::SplitProgramPath(makeProgram.c_str(),
+ dir, file);
+ std::string saveFile = file;
+ cmSystemTools::GetShortPath(makeProgram.c_str(), makeProgram);
+ cmSystemTools::SplitProgramPath(makeProgram.c_str(),
+ dir, file);
+ makeProgram = dir;
+ makeProgram += "/";
+ makeProgram += saveFile;
+ mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", makeProgram.c_str(),
+ "make program",
+ cmCacheManager::FILEPATH);
+ }
+
+ if(makeProgram.find("xcodebuild") != makeProgram.npos)
+ {
+ // due to the text file busy /bin/sh problem with xcodebuild
+ // use the cmakexbuild wrapper instead. This program
+ // will run xcodebuild and if it sees the error text file busy
+ // it will stop forwarding output, and let the build finish.
+ // Then it will retry the build. It will continue this
+ // until no text file busy errors occur.
+ std::string cmakexbuild =
+ this->CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_COMMAND");
+ cmakexbuild = cmakexbuild.substr(0, cmakexbuild.length()-5);
+ cmakexbuild += "cmakexbuild";
+
+ mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM",
+ cmakexbuild.c_str(),
+ "make program",
+ cmCacheManager::FILEPATH);
+ }
+}
+
+// enable the given language
+//
+// The following files are loaded in this order:
+//
+// First figure out what OS we are running on:
+//
+// CMakeSystem.cmake - configured file created by CMakeDetermineSystem.cmake
+// CMakeDetermineSystem.cmake - figure out os info and create
+// CMakeSystem.cmake IF CMAKE_SYSTEM
+// not set
+// CMakeSystem.cmake - configured file created by
+// CMakeDetermineSystem.cmake IF CMAKE_SYSTEM_LOADED
+
+// CMakeSystemSpecificInitialize.cmake
+// - includes Platform/${CMAKE_SYSTEM_NAME}-Initialize.cmake
+
+// Next try and enable all languages found in the languages vector
+//
+// FOREACH LANG in languages
+// CMake(LANG)Compiler.cmake - configured file create by
+// CMakeDetermine(LANG)Compiler.cmake
+// CMakeDetermine(LANG)Compiler.cmake - Finds compiler for LANG and
+// creates CMake(LANG)Compiler.cmake
+// CMake(LANG)Compiler.cmake - configured file created by
+// CMakeDetermine(LANG)Compiler.cmake
+//
+// CMakeSystemSpecificInformation.cmake
+// - includes Platform/${CMAKE_SYSTEM_NAME}.cmake
+// may use compiler stuff
+
+// FOREACH LANG in languages
+// CMake(LANG)Information.cmake
+// - loads Platform/${CMAKE_SYSTEM_NAME}-${COMPILER}.cmake
+// CMakeTest(LANG)Compiler.cmake
+// - Make sure the compiler works with a try compile if
+// CMakeDetermine(LANG) was loaded
+//
+// Now load a few files that can override values set in any of the above
+// (PROJECTNAME)Compatibility.cmake
+// - load any backwards compatibility stuff for current project
+// ${CMAKE_USER_MAKE_RULES_OVERRIDE}
+// - allow users a chance to override system variables
+//
+//
+
+void
+cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *mf, bool optional)
+{
+ if(languages.size() == 0)
+ {
+ cmSystemTools::Error("EnableLanguage must have a lang specified!");
+ cmSystemTools::SetFatalErrorOccured();
+ return;
+ }
+
+ if(this->TryCompileOuterMakefile)
+ {
+ // In a try-compile we can only enable languages provided by caller.
+ for(std::vector<std::string>::const_iterator li = languages.begin();
+ li != languages.end(); ++li)
+ {
+ if(*li == "NONE")
+ {
+ this->SetLanguageEnabled("NONE", mf);
+ }
+ else
+ {
+ const char* lang = li->c_str();
+ if(this->LanguagesReady.find(lang) == this->LanguagesReady.end())
+ {
+ cmOStringStream e;
+ e << "The test project needs language "
+ << lang << " which is not enabled.";
+ this->TryCompileOuterMakefile
+ ->IssueMessage(cmake::FATAL_ERROR, e.str());
+ cmSystemTools::SetFatalErrorOccured();
+ return;
+ }
+ }
+ }
+ }
+
+ bool fatalError = false;
+
+ mf->AddDefinition("RUN_CONFIGURE", true);
+ std::string rootBin = mf->GetHomeOutputDirectory();
+ rootBin += cmake::GetCMakeFilesDirectory();
+
+ // If the configuration files path has been set,
+ // then we are in a try compile and need to copy the enable language
+ // files from the parent cmake bin dir, into the try compile bin dir
+ if(this->ConfiguredFilesPath.size())
+ {
+ rootBin = this->ConfiguredFilesPath;
+ }
+ rootBin += "/";
+ rootBin += cmVersion::GetCMakeVersion();
+
+ // set the dir for parent files so they can be used by modules
+ mf->AddDefinition("CMAKE_PLATFORM_INFO_DIR",rootBin.c_str());
+
+ // find and make sure CMAKE_MAKE_PROGRAM is defined
+ this->FindMakeProgram(mf);
+
+ // try and load the CMakeSystem.cmake if it is there
+ std::string fpath = rootBin;
+ bool const readCMakeSystem = !mf->GetDefinition("CMAKE_SYSTEM_LOADED");
+ if(readCMakeSystem)
+ {
+ fpath += "/CMakeSystem.cmake";
+ if(cmSystemTools::FileExists(fpath.c_str()))
+ {
+ mf->ReadListFile(0,fpath.c_str());
+ }
+ }
+ // Load the CMakeDetermineSystem.cmake file and find out
+ // what platform we are running on
+ if (!mf->GetDefinition("CMAKE_SYSTEM"))
+ {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Windows version number data. */
+ OSVERSIONINFO osvi;
+ ZeroMemory(&osvi, sizeof(osvi));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx (&osvi);
+ cmOStringStream windowsVersionString;
+ windowsVersionString << osvi.dwMajorVersion << "." << osvi.dwMinorVersion;
+ windowsVersionString.str();
+ mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION",
+ windowsVersionString.str().c_str());
+#endif
+ // Read the DetermineSystem file
+ std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake");
+ mf->ReadListFile(0, systemFile.c_str());
+ // load the CMakeSystem.cmake from the binary directory
+ // this file is configured by the CMakeDetermineSystem.cmake file
+ fpath = rootBin;
+ fpath += "/CMakeSystem.cmake";
+ mf->ReadListFile(0,fpath.c_str());
+ }
+
+ if(readCMakeSystem)
+ {
+ // Tell the generator about the target system.
+ std::string system = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
+ if(!this->SetSystemName(system, mf))
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ return;
+ }
+
+ // Tell the generator about the platform, if any.
+ std::string platform = mf->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM");
+ if(!this->SetGeneratorPlatform(platform, mf))
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ return;
+ }
+
+ // Tell the generator about the toolset, if any.
+ std::string toolset = mf->GetSafeDefinition("CMAKE_GENERATOR_TOOLSET");
+ if(!this->SetGeneratorToolset(toolset, mf))
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ return;
+ }
+ }
+
+ // **** Load the system specific initialization if not yet loaded
+ if (!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INITIALIZE_LOADED"))
+ {
+ fpath = mf->GetModulesFile("CMakeSystemSpecificInitialize.cmake");
+ if(!mf->ReadListFile(0,fpath.c_str()))
+ {
+ cmSystemTools::Error("Could not find cmake module file: "
+ "CMakeSystemSpecificInitialize.cmake");
+ }
+ }
+
+ std::map<std::string, bool> needTestLanguage;
+ std::map<std::string, bool> needSetLanguageEnabledMaps;
+ // foreach language
+ // load the CMakeDetermine(LANG)Compiler.cmake file to find
+ // the compiler
+
+ for(std::vector<std::string>::const_iterator l = languages.begin();
+ l != languages.end(); ++l)
+ {
+ const char* lang = l->c_str();
+ needSetLanguageEnabledMaps[lang] = false;
+ if(*l == "NONE")
+ {
+ this->SetLanguageEnabled("NONE", mf);
+ continue;
+ }
+ std::string loadedLang = "CMAKE_";
+ loadedLang += lang;
+ loadedLang += "_COMPILER_LOADED";
+ if(!mf->GetDefinition(loadedLang))
+ {
+ fpath = rootBin;
+ fpath += "/CMake";
+ fpath += lang;
+ fpath += "Compiler.cmake";
+
+ // If the existing build tree was already configured with this
+ // version of CMake then try to load the configured file first
+ // to avoid duplicate compiler tests.
+ if(cmSystemTools::FileExists(fpath.c_str()))
+ {
+ if(!mf->ReadListFile(0,fpath.c_str()))
+ {
+ cmSystemTools::Error("Could not find cmake module file: ",
+ fpath.c_str());
+ }
+ // if this file was found then the language was already determined
+ // to be working
+ needTestLanguage[lang] = false;
+ this->SetLanguageEnabledFlag(lang, mf);
+ needSetLanguageEnabledMaps[lang] = true;
+ // this can only be called after loading CMake(LANG)Compiler.cmake
+ }
+ }
+
+ if(!this->GetLanguageEnabled(lang) )
+ {
+ if (this->CMakeInstance->GetIsInTryCompile())
+ {
+ cmSystemTools::Error("This should not have happened. "
+ "If you see this message, you are probably "
+ "using a broken CMakeLists.txt file or a "
+ "problematic release of CMake");
+ }
+ // if the CMake(LANG)Compiler.cmake file was not found then
+ // load CMakeDetermine(LANG)Compiler.cmake
+ std::string determineCompiler = "CMakeDetermine";
+ determineCompiler += lang;
+ determineCompiler += "Compiler.cmake";
+ std::string determineFile =
+ mf->GetModulesFile(determineCompiler.c_str());
+ if(!mf->ReadListFile(0,determineFile.c_str()))
+ {
+ cmSystemTools::Error("Could not find cmake module file: ",
+ determineCompiler.c_str());
+ }
+ needTestLanguage[lang] = true;
+ // Some generators like visual studio should not use the env variables
+ // So the global generator can specify that in this variable
+ if(!mf->GetDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV"))
+ {
+ // put ${CMake_(LANG)_COMPILER_ENV_VAR}=${CMAKE_(LANG)_COMPILER
+ // into the environment, in case user scripts want to run
+ // configure, or sub cmakes
+ std::string compilerName = "CMAKE_";
+ compilerName += lang;
+ compilerName += "_COMPILER";
+ std::string compilerEnv = "CMAKE_";
+ compilerEnv += lang;
+ compilerEnv += "_COMPILER_ENV_VAR";
+ std::string envVar = mf->GetRequiredDefinition(compilerEnv);
+ std::string envVarValue =
+ mf->GetRequiredDefinition(compilerName);
+ std::string env = envVar;
+ env += "=";
+ env += envVarValue;
+ cmSystemTools::PutEnv(env.c_str());
+ }
+
+ // if determineLanguage was called then load the file it
+ // configures CMake(LANG)Compiler.cmake
+ fpath = rootBin;
+ fpath += "/CMake";
+ fpath += lang;
+ fpath += "Compiler.cmake";
+ if(!mf->ReadListFile(0,fpath.c_str()))
+ {
+ cmSystemTools::Error("Could not find cmake module file: ",
+ fpath.c_str());
+ }
+ this->SetLanguageEnabledFlag(lang, mf);
+ needSetLanguageEnabledMaps[lang] = true;
+ // this can only be called after loading CMake(LANG)Compiler.cmake
+ // the language must be enabled for try compile to work, but we do
+ // not know if it is a working compiler yet so set the test language
+ // flag
+ needTestLanguage[lang] = true;
+ } // end if(!this->GetLanguageEnabled(lang) )
+ } // end loop over languages
+
+ // **** Load the system specific information if not yet loaded
+ if (!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED"))
+ {
+ fpath = mf->GetModulesFile("CMakeSystemSpecificInformation.cmake");
+ if(!mf->ReadListFile(0,fpath.c_str()))
+ {
+ cmSystemTools::Error("Could not find cmake module file: "
+ "CMakeSystemSpecificInformation.cmake");
+ }
+ }
+ // loop over languages again loading CMake(LANG)Information.cmake
+ //
+ for(std::vector<std::string>::const_iterator l = languages.begin();
+ l != languages.end(); ++l)
+ {
+ const char* lang = l->c_str();
+ if(*l == "NONE")
+ {
+ this->SetLanguageEnabled("NONE", mf);
+ continue;
+ }
+
+ // Check that the compiler was found.
+ std::string compilerName = "CMAKE_";
+ compilerName += lang;
+ compilerName += "_COMPILER";
+ std::string compilerEnv = "CMAKE_";
+ compilerEnv += lang;
+ compilerEnv += "_COMPILER_ENV_VAR";
+ cmOStringStream noCompiler;
+ const char* compilerFile = mf->GetDefinition(compilerName);
+ if(!compilerFile || !*compilerFile ||
+ cmSystemTools::IsNOTFOUND(compilerFile))
+ {
+ noCompiler <<
+ "No " << compilerName << " could be found.\n"
+ ;
+ }
+ else if(strcmp(lang, "RC") != 0 &&
+ strcmp(lang, "ASM_MASM") != 0)
+ {
+ if(!cmSystemTools::FileIsFullPath(compilerFile))
+ {
+ noCompiler <<
+ "The " << compilerName << ":\n"
+ " " << compilerFile << "\n"
+ "is not a full path and was not found in the PATH.\n"
+ ;
+ }
+ else if(!cmSystemTools::FileExists(compilerFile))
+ {
+ noCompiler <<
+ "The " << compilerName << ":\n"
+ " " << compilerFile << "\n"
+ "is not a full path to an existing compiler tool.\n"
+ ;
+ }
+ }
+ if(!noCompiler.str().empty())
+ {
+ // Skip testing this language since the compiler is not found.
+ needTestLanguage[lang] = false;
+ if(!optional)
+ {
+ // The compiler was not found and it is not optional. Remove
+ // CMake(LANG)Compiler.cmake so we try again next time CMake runs.
+ std::string compilerLangFile = rootBin;
+ compilerLangFile += "/CMake";
+ compilerLangFile += lang;
+ compilerLangFile += "Compiler.cmake";
+ cmSystemTools::RemoveFile(compilerLangFile.c_str());
+ if(!this->CMakeInstance->GetIsInTryCompile())
+ {
+ this->PrintCompilerAdvice(noCompiler, lang,
+ mf->GetDefinition(compilerEnv));
+ mf->IssueMessage(cmake::FATAL_ERROR, noCompiler.str());
+ fatalError = true;
+ }
+ }
+ }
+
+ std::string langLoadedVar = "CMAKE_";
+ langLoadedVar += lang;
+ langLoadedVar += "_INFORMATION_LOADED";
+ if (!mf->GetDefinition(langLoadedVar))
+ {
+ fpath = "CMake";
+ fpath += lang;
+ fpath += "Information.cmake";
+ std::string informationFile = mf->GetModulesFile(fpath.c_str());
+ if (informationFile.empty())
+ {
+ cmSystemTools::Error("Could not find cmake module file: ",
+ fpath.c_str());
+ }
+ else if(!mf->ReadListFile(0, informationFile.c_str()))
+ {
+ cmSystemTools::Error("Could not process cmake module file: ",
+ informationFile.c_str());
+ }
+ }
+ if (needSetLanguageEnabledMaps[lang])
+ {
+ this->SetLanguageEnabledMaps(lang, mf);
+ }
+ this->LanguagesReady.insert(lang);
+
+ // Test the compiler for the language just setup
+ // (but only if a compiler has been actually found)
+ // At this point we should have enough info for a try compile
+ // which is used in the backward stuff
+ // If the language is untested then test it now with a try compile.
+ if(needTestLanguage[lang])
+ {
+ if (!this->CMakeInstance->GetIsInTryCompile())
+ {
+ std::string testLang = "CMakeTest";
+ testLang += lang;
+ testLang += "Compiler.cmake";
+ std::string ifpath = mf->GetModulesFile(testLang.c_str());
+ if(!mf->ReadListFile(0,ifpath.c_str()))
+ {
+ cmSystemTools::Error("Could not find cmake module file: ",
+ testLang.c_str());
+ }
+ std::string compilerWorks = "CMAKE_";
+ compilerWorks += lang;
+ compilerWorks += "_COMPILER_WORKS";
+ // if the compiler did not work, then remove the
+ // CMake(LANG)Compiler.cmake file so that it will get tested the
+ // next time cmake is run
+ if(!mf->IsOn(compilerWorks))
+ {
+ std::string compilerLangFile = rootBin;
+ compilerLangFile += "/CMake";
+ compilerLangFile += lang;
+ compilerLangFile += "Compiler.cmake";
+ cmSystemTools::RemoveFile(compilerLangFile.c_str());
+ }
+ } // end if in try compile
+ } // end need test language
+ // Store the shared library flags so that we can satisfy CMP0018
+ std::string sharedLibFlagsVar = "CMAKE_SHARED_LIBRARY_";
+ sharedLibFlagsVar += lang;
+ sharedLibFlagsVar += "_FLAGS";
+ const char* sharedLibFlags =
+ mf->GetSafeDefinition(sharedLibFlagsVar);
+ if (sharedLibFlags)
+ {
+ this->LanguageToOriginalSharedLibFlags[lang] = sharedLibFlags;
+ }
+
+ // Translate compiler ids for compatibility.
+ this->CheckCompilerIdCompatibility(mf, lang);
+ } // end for each language
+
+ // Now load files that can override any settings on the platform or for
+ // the project First load the project compatibility file if it is in
+ // cmake
+ std::string projectCompatibility = mf->GetDefinition("CMAKE_ROOT");
+ projectCompatibility += "/Modules/";
+ projectCompatibility += mf->GetSafeDefinition("PROJECT_NAME");
+ projectCompatibility += "Compatibility.cmake";
+ if(cmSystemTools::FileExists(projectCompatibility.c_str()))
+ {
+ mf->ReadListFile(0,projectCompatibility.c_str());
+ }
+ // Inform any extra generator of the new language.
+ if (this->ExtraGenerator)
+ {
+ this->ExtraGenerator->EnableLanguage(languages, mf, false);
+ }
+
+ if(fatalError)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os,
+ std::string const& lang,
+ const char* envVar) const
+{
+ // Subclasses override this method if they do not support this advice.
+ os <<
+ "Tell CMake where to find the compiler by setting "
+ ;
+ if(envVar)
+ {
+ os <<
+ "either the environment variable \"" << envVar << "\" or "
+ ;
+ }
+ os <<
+ "the CMake cache entry CMAKE_" << lang << "_COMPILER "
+ "to the full path to the compiler, or to the compiler name "
+ "if it is in the PATH."
+ ;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::CheckCompilerIdCompatibility(cmMakefile* mf,
+ std::string const& lang) const
+{
+ std::string compilerIdVar = "CMAKE_" + lang + "_COMPILER_ID";
+ const char* compilerId = mf->GetDefinition(compilerIdVar);
+ if(!compilerId)
+ {
+ return;
+ }
+
+ if(strcmp(compilerId, "AppleClang") == 0)
+ {
+ cmPolicies* policies = this->CMakeInstance->GetPolicies();
+ switch(mf->GetPolicyStatus(cmPolicies::CMP0025))
+ {
+ case cmPolicies::WARN:
+ if(!this->CMakeInstance->GetIsInTryCompile() &&
+ mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0025"))
+ {
+ cmOStringStream w;
+ w << policies->GetPolicyWarning(cmPolicies::CMP0025) << "\n"
+ "Converting " << lang <<
+ " compiler id \"AppleClang\" to \"Clang\" for compatibility."
+ ;
+ mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to convert AppleClang to Clang.
+ mf->AddDefinition(compilerIdVar, "Clang");
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ mf->IssueMessage(
+ cmake::FATAL_ERROR,
+ policies->GetRequiredPolicyError(cmPolicies::CMP0025)
+ );
+ case cmPolicies::NEW:
+ // NEW behavior is to keep AppleClang.
+ break;
+ }
+ }
+
+ if(strcmp(compilerId, "QCC") == 0)
+ {
+ cmPolicies* policies = this->CMakeInstance->GetPolicies();
+ switch(mf->GetPolicyStatus(cmPolicies::CMP0047))
+ {
+ case cmPolicies::WARN:
+ if(!this->CMakeInstance->GetIsInTryCompile() &&
+ mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0047"))
+ {
+ cmOStringStream w;
+ w << policies->GetPolicyWarning(cmPolicies::CMP0047) << "\n"
+ "Converting " << lang <<
+ " compiler id \"QCC\" to \"GNU\" for compatibility."
+ ;
+ mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to convert QCC to GNU.
+ mf->AddDefinition(compilerIdVar, "GNU");
+ if(lang == "C")
+ {
+ mf->AddDefinition("CMAKE_COMPILER_IS_GNUCC", "1");
+ }
+ else if(lang == "CXX")
+ {
+ mf->AddDefinition("CMAKE_COMPILER_IS_GNUCXX", "1");
+ }
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ mf->IssueMessage(
+ cmake::FATAL_ERROR,
+ policies->GetRequiredPolicyError(cmPolicies::CMP0047)
+ );
+ case cmPolicies::NEW:
+ // NEW behavior is to keep QCC.
+ break;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source) const
+{
+ const std::string& lang = source.GetLanguage();
+ if(!lang.empty())
+ {
+ std::map<std::string, std::string>::const_iterator it =
+ this->LanguageToOutputExtension.find(lang);
+
+ if(it != this->LanguageToOutputExtension.end())
+ {
+ return it->second;
+ }
+ }
+ else
+ {
+ // if no language is found then check to see if it is already an
+ // ouput extension for some language. In that case it should be ignored
+ // and in this map, so it will not be compiled but will just be used.
+ std::string const& ext = source.GetExtension();
+ if(!ext.empty())
+ {
+ if(this->OutputExtensions.count(ext))
+ {
+ return ext;
+ }
+ }
+ }
+ return "";
+}
+
+
+std::string cmGlobalGenerator::GetLanguageFromExtension(const char* ext) const
+{
+ // if there is an extension and it starts with . then move past the
+ // . because the extensions are not stored with a . in the map
+ if(ext && *ext == '.')
+ {
+ ++ext;
+ }
+ std::map<std::string, std::string>::const_iterator it
+ = this->ExtensionToLanguage.find(ext);
+ if(it != this->ExtensionToLanguage.end())
+ {
+ return it->second;
+ }
+ return "";
+}
+
+/* SetLanguageEnabled() is now split in two parts:
+at first the enabled-flag is set. This can then be used in EnabledLanguage()
+for checking whether the language is already enabled. After setting this
+flag still the values from the cmake variables have to be copied into the
+internal maps, this is done in SetLanguageEnabledMaps() which is called
+after the system- and compiler specific files have been loaded.
+
+This split was done originally so that compiler-specific configuration
+files could change the object file extension
+(CMAKE_<LANG>_OUTPUT_EXTENSION) before the CMake variables were copied
+to the C++ maps.
+*/
+void cmGlobalGenerator::SetLanguageEnabled(const std::string& l,
+ cmMakefile* mf)
+{
+ this->SetLanguageEnabledFlag(l, mf);
+ this->SetLanguageEnabledMaps(l, mf);
+}
+
+void cmGlobalGenerator::SetLanguageEnabledFlag(const std::string& l,
+ cmMakefile* mf)
+{
+ this->LanguageEnabled[l] = true;
+
+ // Fill the language-to-extension map with the current variable
+ // settings to make sure it is available for the try_compile()
+ // command source file signature. In SetLanguageEnabledMaps this
+ // will be done again to account for any compiler- or
+ // platform-specific entries.
+ this->FillExtensionToLanguageMap(l, mf);
+}
+
+void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
+ cmMakefile* mf)
+{
+ // use LanguageToLinkerPreference to detect whether this functions has
+ // run before
+ if (this->LanguageToLinkerPreference.find(l) !=
+ this->LanguageToLinkerPreference.end())
+ {
+ return;
+ }
+
+ std::string linkerPrefVar = std::string("CMAKE_") +
+ std::string(l) + std::string("_LINKER_PREFERENCE");
+ const char* linkerPref = mf->GetDefinition(linkerPrefVar);
+ int preference = 0;
+ if(linkerPref)
+ {
+ if (sscanf(linkerPref, "%d", &preference)!=1)
+ {
+ // backward compatibility: before 2.6 LINKER_PREFERENCE
+ // was either "None" or "Preferred", and only the first character was
+ // tested. So if there is a custom language out there and it is
+ // "Preferred", set its preference high
+ if (linkerPref[0]=='P')
+ {
+ preference = 100;
+ }
+ else
+ {
+ preference = 0;
+ }
+ }
+ }
+
+ if (preference < 0)
+ {
+ std::string msg = linkerPrefVar;
+ msg += " is negative, adjusting it to 0";
+ cmSystemTools::Message(msg.c_str(), "Warning");
+ preference = 0;
+ }
+
+ this->LanguageToLinkerPreference[l] = preference;
+
+ std::string outputExtensionVar = std::string("CMAKE_") +
+ std::string(l) + std::string("_OUTPUT_EXTENSION");
+ const char* outputExtension = mf->GetDefinition(outputExtensionVar);
+ if(outputExtension)
+ {
+ this->LanguageToOutputExtension[l] = outputExtension;
+ this->OutputExtensions[outputExtension] = outputExtension;
+ if(outputExtension[0] == '.')
+ {
+ this->OutputExtensions[outputExtension+1] = outputExtension+1;
+ }
+ }
+
+ // The map was originally filled by SetLanguageEnabledFlag, but
+ // since then the compiler- and platform-specific files have been
+ // loaded which might have added more entries.
+ this->FillExtensionToLanguageMap(l, mf);
+
+ std::string ignoreExtensionsVar = std::string("CMAKE_") +
+ std::string(l) + std::string("_IGNORE_EXTENSIONS");
+ std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar);
+ std::vector<std::string> extensionList;
+ cmSystemTools::ExpandListArgument(ignoreExts, extensionList);
+ for(std::vector<std::string>::iterator i = extensionList.begin();
+ i != extensionList.end(); ++i)
+ {
+ this->IgnoreExtensions[*i] = true;
+ }
+
+}
+
+void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l,
+ cmMakefile* mf)
+{
+ std::string extensionsVar = std::string("CMAKE_") +
+ std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS");
+ std::string exts = mf->GetSafeDefinition(extensionsVar);
+ std::vector<std::string> extensionList;
+ cmSystemTools::ExpandListArgument(exts, extensionList);
+ for(std::vector<std::string>::iterator i = extensionList.begin();
+ i != extensionList.end(); ++i)
+ {
+ this->ExtensionToLanguage[*i] = l;
+ }
+}
+
+bool cmGlobalGenerator::IgnoreFile(const char* ext) const
+{
+ if(!this->GetLanguageFromExtension(ext).empty())
+ {
+ return false;
+ }
+ return (this->IgnoreExtensions.count(ext) > 0);
+}
+
+bool cmGlobalGenerator::GetLanguageEnabled(const std::string& l) const
+{
+ return (this->LanguageEnabled.find(l)!= this->LanguageEnabled.end());
+}
+
+void cmGlobalGenerator::ClearEnabledLanguages()
+{
+ this->LanguageEnabled.clear();
+}
+
+void cmGlobalGenerator::Configure()
+{
+ this->FirstTimeProgress = 0.0f;
+ this->ClearGeneratorMembers();
+
+ // start with this directory
+ cmLocalGenerator *lg = this->CreateLocalGenerator();
+ this->LocalGenerators.push_back(lg);
+
+ // set the Start directories
+ cmMakefile* mf = lg->GetMakefile();
+ lg->GetMakefile()->SetStartDirectory
+ (this->CMakeInstance->GetStartDirectory());
+ lg->GetMakefile()->SetStartOutputDirectory
+ (this->CMakeInstance->GetStartOutputDirectory());
+ lg->GetMakefile()->MakeStartDirectoriesCurrent();
+
+ this->BinaryDirectories.insert(mf->GetStartOutputDirectory());
+
+ // now do it
+ lg->Configure();
+
+ // update the cache entry for the number of local generators, this is used
+ // for progress
+ char num[100];
+ sprintf(num,"%d",static_cast<int>(this->LocalGenerators.size()));
+ this->GetCMakeInstance()->AddCacheEntry
+ ("CMAKE_NUMBER_OF_LOCAL_GENERATORS", num,
+ "number of local generators", cmCacheManager::INTERNAL);
+
+ // check for link libraries and include directories containing "NOTFOUND"
+ // and for infinite loops
+ this->CheckLocalGenerators();
+
+ // at this point this->LocalGenerators has been filled,
+ // so create the map from project name to vector of local generators
+ this->FillProjectMap();
+
+ if ( this->CMakeInstance->GetWorkingMode() == cmake::NORMAL_MODE)
+ {
+ cmOStringStream msg;
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ msg << "Configuring incomplete, errors occurred!";
+ const char* logs[] = {"CMakeOutput.log", "CMakeError.log", 0};
+ for(const char** log = logs; *log; ++log)
+ {
+ std::string f = this->CMakeInstance->GetHomeOutputDirectory();
+ f += this->CMakeInstance->GetCMakeFilesDirectory();
+ f += "/";
+ f += *log;
+ if(cmSystemTools::FileExists(f.c_str()))
+ {
+ msg << "\nSee also \"" << f << "\".";
+ }
+ }
+ }
+ else
+ {
+ msg << "Configuring done";
+ }
+ this->CMakeInstance->UpdateProgress(msg.str().c_str(), -1);
+ }
+}
+
+cmExportBuildFileGenerator*
+cmGlobalGenerator::GetExportedTargetsFile(const std::string &filename) const
+{
+ std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
+ = this->BuildExportSets.find(filename);
+ return it == this->BuildExportSets.end() ? 0 : it->second;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target)
+{
+ this->CMP0042WarnTargets.insert(target);
+}
+
+bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const
+{
+ // If the property is not enabled then okay.
+ if(!this->CMakeInstance
+ ->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
+ {
+ return true;
+ }
+
+ // This generator does not support duplicate custom targets.
+ cmOStringStream e;
+ e << "This project has enabled the ALLOW_DUPLICATE_CUSTOM_TARGETS "
+ << "global property. "
+ << "The \"" << this->GetName() << "\" generator does not support "
+ << "duplicate custom targets. "
+ << "Consider using a Makefiles generator or fix the project to not "
+ << "use duplicate target names.";
+ cmSystemTools::Error(e.str().c_str());
+ return false;
+}
+
+void cmGlobalGenerator::DoGenerate()
+{
+ // Some generators track files replaced during the Generate.
+ // Start with an empty vector:
+ this->FilesReplacedDuringGenerate.clear();
+
+ // clear targets to issue warning CMP0042 for
+ this->CMP0042WarnTargets.clear();
+
+ this->Generate();
+}
+
+void cmGlobalGenerator::Generate()
+{
+ // Check whether this generator is allowed to run.
+ if(!this->CheckALLOW_DUPLICATE_CUSTOM_TARGETS())
+ {
+ return;
+ }
+
+ this->FinalizeTargetCompileInfo();
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ // Iterate through all targets and set up automoc for those which have
+ // the AUTOMOC, AUTOUIC or AUTORCC property set
+ AutogensType autogens;
+ this->CreateQtAutoGeneratorsTargets(autogens);
+#endif
+
+ // For each existing cmLocalGenerator
+ unsigned int i;
+
+ // Put a copy of each global target in every directory.
+ cmTargets globalTargets;
+ this->CreateDefaultGlobalTargets(&globalTargets);
+ for (i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ cmMakefile* mf = this->LocalGenerators[i]->GetMakefile();
+ cmTargets* targets = &(mf->GetTargets());
+ cmTargets::iterator tit;
+ for ( tit = globalTargets.begin(); tit != globalTargets.end(); ++ tit )
+ {
+ (*targets)[tit->first] = tit->second;
+ (*targets)[tit->first].SetMakefile(mf);
+ }
+ }
+
+ // Add generator specific helper commands
+ for (i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ this->LocalGenerators[i]->AddHelperCommands();
+ }
+
+ // Create per-target generator information.
+ this->CreateGeneratorTargets();
+
+ this->ForceLinkerLanguages();
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ for (AutogensType::iterator it = autogens.begin(); it != autogens.end();
+ ++it)
+ {
+ it->first.SetupAutoGenerateTarget(it->second);
+ }
+#endif
+
+ // Trace the dependencies, after that no custom commands should be added
+ // because their dependencies might not be handled correctly
+ for (i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ this->LocalGenerators[i]->TraceDependencies();
+ }
+
+ // Compute the manifest of main targets generated.
+ for (i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ this->LocalGenerators[i]->GenerateTargetManifest();
+ }
+
+ this->ProcessEvaluationFiles();
+
+ // Compute the inter-target dependencies.
+ if(!this->ComputeTargetDepends())
+ {
+ return;
+ }
+
+ // Create a map from local generator to the complete set of targets
+ // it builds by default.
+ this->FillLocalGeneratorToTargetMap();
+
+ // Generate project files
+ for (i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ this->LocalGenerators[i]->GetMakefile()->SetGeneratingBuildSystem();
+ this->SetCurrentLocalGenerator(this->LocalGenerators[i]);
+ this->LocalGenerators[i]->Generate();
+ if(!this->LocalGenerators[i]->GetMakefile()->IsOn(
+ "CMAKE_SKIP_INSTALL_RULES"))
+ {
+ this->LocalGenerators[i]->GenerateInstallRules();
+ }
+ this->LocalGenerators[i]->GenerateTestFiles();
+ this->CMakeInstance->UpdateProgress("Generating",
+ (static_cast<float>(i)+1.0f)/
+ static_cast<float>(this->LocalGenerators.size()));
+ }
+ this->SetCurrentLocalGenerator(0);
+
+ if(!this->GenerateCPackPropertiesFile())
+ {
+ this->GetCMakeInstance()->IssueMessage(
+ cmake::FATAL_ERROR, "Could not write CPack properties file.");
+ }
+
+ for (std::map<std::string, cmExportBuildFileGenerator*>::iterator
+ it = this->BuildExportSets.begin(); it != this->BuildExportSets.end();
+ ++it)
+ {
+ if (!it->second->GenerateImportFile()
+ && !cmSystemTools::GetErrorOccuredFlag())
+ {
+ this->GetCMakeInstance()
+ ->IssueMessage(cmake::FATAL_ERROR, "Could not write export file.");
+ return;
+ }
+ }
+ // Update rule hashes.
+ this->CheckRuleHashes();
+
+ this->WriteSummary();
+
+ if (this->ExtraGenerator != 0)
+ {
+ this->ExtraGenerator->Generate();
+ }
+
+ if(!this->CMP0042WarnTargets.empty())
+ {
+ cmOStringStream w;
+ w <<
+ (this->GetCMakeInstance()->GetPolicies()->
+ GetPolicyWarning(cmPolicies::CMP0042)) << "\n";
+ w << "MACOSX_RPATH is not specified for"
+ " the following targets:\n";
+ for(std::set<std::string>::iterator
+ iter = this->CMP0042WarnTargets.begin();
+ iter != this->CMP0042WarnTargets.end();
+ ++iter)
+ {
+ w << " " << *iter << "\n";
+ }
+ this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }
+
+ this->CMakeInstance->UpdateProgress("Generating done", -1);
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalGenerator::ComputeTargetDepends()
+{
+ cmComputeTargetDepends ctd(this);
+ if(!ctd.Compute())
+ {
+ return false;
+ }
+ std::vector<cmTarget const*> const& targets = ctd.GetTargets();
+ for(std::vector<cmTarget const*>::const_iterator ti = targets.begin();
+ ti != targets.end(); ++ti)
+ {
+ ctd.GetTargetDirectDepends(*ti, this->TargetDependencies[*ti]);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::CreateQtAutoGeneratorsTargets(AutogensType &autogens)
+{
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
+ {
+ cmTargets& targets =
+ this->LocalGenerators[i]->GetMakefile()->GetTargets();
+ for(cmTargets::iterator ti = targets.begin();
+ ti != targets.end(); ++ti)
+ {
+ cmTarget& target = ti->second;
+ 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)
+ {
+ if((target.GetPropertyAsBool("AUTOMOC")
+ || target.GetPropertyAsBool("AUTOUIC")
+ || target.GetPropertyAsBool("AUTORCC"))
+ && !target.IsImported())
+ {
+ cmQtAutoGenerators autogen;
+ if(autogen.InitializeAutogenTarget(&target))
+ {
+ autogens.push_back(AutogensType::value_type(autogen, &target));
+ }
+ }
+ }
+ }
+ }
+#else
+ (void)autogens;
+#endif
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::FinalizeTargetCompileInfo()
+{
+ // Construct per-target generator information.
+ for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
+ {
+ cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
+
+ const std::vector<cmValueWithOrigin> noconfig_compile_definitions =
+ mf->GetCompileDefinitionsEntries();
+
+ cmTargets& targets = mf->GetTargets();
+ for(cmTargets::iterator ti = targets.begin();
+ ti != targets.end(); ++ti)
+ {
+ cmTarget* t = &ti->second;
+
+ t->AppendBuildInterfaceIncludes();
+
+ if (t->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+
+ for (std::vector<cmValueWithOrigin>::const_iterator it
+ = noconfig_compile_definitions.begin();
+ it != noconfig_compile_definitions.end(); ++it)
+ {
+ t->InsertCompileDefinition(*it);
+ }
+
+ cmPolicies::PolicyStatus polSt
+ = mf->GetPolicyStatus(cmPolicies::CMP0043);
+ if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
+ {
+ std::vector<std::string> configs;
+ mf->GetConfigurations(configs);
+
+ for(std::vector<std::string>::const_iterator ci = configs.begin();
+ ci != configs.end(); ++ci)
+ {
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += cmSystemTools::UpperCase(*ci);
+ t->AppendProperty(defPropName,
+ mf->GetProperty(defPropName));
+ }
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::CreateGeneratorTargets(cmMakefile *mf)
+{
+ cmGeneratorTargetsType generatorTargets;
+ cmTargets& targets = mf->GetTargets();
+ for(cmTargets::iterator ti = targets.begin();
+ ti != targets.end(); ++ti)
+ {
+ cmTarget* t = &ti->second;
+ cmGeneratorTarget* gt = new cmGeneratorTarget(t);
+ this->ComputeTargetObjectDirectory(gt);
+ this->GeneratorTargets[t] = gt;
+ generatorTargets[t] = gt;
+ }
+
+ for(std::vector<cmTarget*>::const_iterator
+ j = mf->GetOwnedImportedTargets().begin();
+ j != mf->GetOwnedImportedTargets().end(); ++j)
+ {
+ cmGeneratorTarget* gt = new cmGeneratorTarget(*j);
+ this->GeneratorTargets[*j] = gt;
+ generatorTargets[*j] = gt;
+ }
+ mf->SetGeneratorTargets(generatorTargets);
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::CreateGeneratorTargets()
+{
+ // Construct per-target generator information.
+ for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
+ {
+ this->CreateGeneratorTargets(this->LocalGenerators[i]->GetMakefile());
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::ClearGeneratorMembers()
+{
+ for(cmGeneratorTargetsType::iterator i = this->GeneratorTargets.begin();
+ i != this->GeneratorTargets.end(); ++i)
+ {
+ delete i->second;
+ }
+ this->GeneratorTargets.clear();
+
+ for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
+ li = this->EvaluationFiles.begin();
+ li != this->EvaluationFiles.end();
+ ++li)
+ {
+ delete *li;
+ }
+ this->EvaluationFiles.clear();
+
+ for(std::map<std::string, cmExportBuildFileGenerator*>::iterator
+ i = this->BuildExportSets.begin();
+ i != this->BuildExportSets.end(); ++i)
+ {
+ delete i->second;
+ }
+ this->BuildExportSets.clear();
+
+ for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ delete this->LocalGenerators[i];
+ }
+ this->LocalGenerators.clear();
+
+ this->ExportSets.clear();
+ this->TargetDependencies.clear();
+ this->TotalTargets.clear();
+ this->ImportedTargets.clear();
+ this->LocalGeneratorToTargetMap.clear();
+ this->ProjectMap.clear();
+ this->RuleHashes.clear();
+ this->DirectoryContentMap.clear();
+ this->BinaryDirectories.clear();
+}
+
+//----------------------------------------------------------------------------
+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
+{
+}
+
+void cmGlobalGenerator::CheckLocalGenerators()
+{
+ std::map<std::string, std::string> notFoundMap;
+// std::set<std::string> notFoundMap;
+ // after it is all done do a ConfigureFinalPass
+ cmCacheManager* manager = 0;
+ for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ manager = this->LocalGenerators[i]->GetMakefile()->GetCacheManager();
+ this->LocalGenerators[i]->ConfigureFinalPass();
+ cmTargets &targets =
+ this->LocalGenerators[i]->GetMakefile()->GetTargets();
+ for (cmTargets::iterator l = targets.begin();
+ l != targets.end(); l++)
+ {
+ if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ const cmTarget::LinkLibraryVectorType& libs =
+ l->second.GetOriginalLinkLibraries();
+ for(cmTarget::LinkLibraryVectorType::const_iterator lib = libs.begin();
+ lib != libs.end(); ++lib)
+ {
+ if(lib->first.size() > 9 &&
+ cmSystemTools::IsNOTFOUND(lib->first.c_str()))
+ {
+ std::string varName = lib->first.substr(0, lib->first.size()-9);
+ cmCacheManager::CacheIterator it =
+ manager->GetCacheIterator(varName.c_str());
+ if(it.GetPropertyAsBool("ADVANCED"))
+ {
+ varName += " (ADVANCED)";
+ }
+ std::string text = notFoundMap[varName];
+ text += "\n linked by target \"";
+ text += l->second.GetName();
+ text += "\" in directory ";
+ text+=this->LocalGenerators[i]->GetMakefile()->GetCurrentDirectory();
+ notFoundMap[varName] = text;
+ }
+ }
+ std::vector<std::string> incs;
+ const char *incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES");
+ if (!incDirProp)
+ {
+ continue;
+ }
+
+ std::string incDirs = cmGeneratorExpression::Preprocess(incDirProp,
+ cmGeneratorExpression::StripAllGeneratorExpressions);
+
+ cmSystemTools::ExpandListArgument(incDirs, incs);
+
+ for( std::vector<std::string>::const_iterator incDir = incs.begin();
+ incDir != incs.end(); ++incDir)
+ {
+ if(incDir->size() > 9 &&
+ cmSystemTools::IsNOTFOUND(incDir->c_str()))
+ {
+ std::string varName = incDir->substr(0, incDir->size()-9);
+ cmCacheManager::CacheIterator it =
+ manager->GetCacheIterator(varName.c_str());
+ if(it.GetPropertyAsBool("ADVANCED"))
+ {
+ varName += " (ADVANCED)";
+ }
+ std::string text = notFoundMap[varName];
+ text += "\n used as include directory in directory ";
+ text += this->LocalGenerators[i]
+ ->GetMakefile()->GetCurrentDirectory();
+ notFoundMap[varName] = text;
+ }
+ }
+ }
+ this->CMakeInstance->UpdateProgress
+ ("Configuring", 0.9f+0.1f*(static_cast<float>(i)+1.0f)/
+ static_cast<float>(this->LocalGenerators.size()));
+ }
+
+ if(notFoundMap.size())
+ {
+ std::string notFoundVars;
+ for(std::map<std::string, std::string>::const_iterator
+ ii = notFoundMap.begin();
+ ii != notFoundMap.end();
+ ++ii)
+ {
+ notFoundVars += ii->first;
+ notFoundVars += ii->second;
+ notFoundVars += "\n";
+ }
+ cmSystemTools::Error("The following variables are used in this project, "
+ "but they are set to NOTFOUND.\n"
+ "Please set them or make sure they are set and "
+ "tested correctly in the CMake files:\n",
+ notFoundVars.c_str());
+ }
+}
+
+int cmGlobalGenerator::TryCompile(const std::string& srcdir,
+ const std::string& bindir,
+ const std::string& projectName,
+ const std::string& target, bool fast,
+ std::string& output, cmMakefile *mf)
+{
+ // if this is not set, then this is a first time configure
+ // and there is a good chance that the try compile stuff will
+ // take the bulk of the time, so try and guess some progress
+ // by getting closer and closer to 100 without actually getting there.
+ if (!this->CMakeInstance->GetCacheManager()->GetCacheValue
+ ("CMAKE_NUMBER_OF_LOCAL_GENERATORS"))
+ {
+ // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
+ // we are in the first time progress and we have no
+ // idea how long it will be. So, just move 1/10th of the way
+ // there each time, and don't go over 95%
+ this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
+ if(this->FirstTimeProgress > 0.95f)
+ {
+ this->FirstTimeProgress = 0.95f;
+ }
+ this->CMakeInstance->UpdateProgress("Configuring",
+ this->FirstTimeProgress);
+ }
+
+ std::string newTarget;
+ if (!target.empty())
+ {
+ newTarget += target;
+#if 0
+#if defined(_WIN32) || defined(__CYGWIN__)
+ std::string tmp = target;
+ // if the target does not already end in . something
+ // then assume .exe
+ if(tmp.size() < 4 || tmp[tmp.size()-4] != '.')
+ {
+ newTarget += ".exe";
+ }
+#endif // WIN32
+#endif
+ }
+ std::string config =
+ mf->GetSafeDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
+ return this->Build(srcdir,bindir,projectName,
+ newTarget,
+ output,"",config,false,fast,
+ this->TryCompileTimeout);
+}
+
+void cmGlobalGenerator::GenerateBuildCommand(
+ std::vector<std::string>& makeCommand, const std::string&,
+ const std::string&, const std::string&, const std::string&,
+ const std::string&, bool,
+ std::vector<std::string> const&)
+{
+ makeCommand.push_back(
+ "cmGlobalGenerator::GenerateBuildCommand not implemented");
+}
+
+int cmGlobalGenerator::Build(
+ const std::string&, const std::string& bindir,
+ const std::string& projectName, const std::string& target,
+ std::string& output,
+ const std::string& makeCommandCSTR,
+ const std::string& config,
+ bool clean, bool fast,
+ double timeout,
+ cmSystemTools::OutputOption outputflag,
+ std::vector<std::string> const& nativeOptions)
+{
+ /**
+ * Run an executable command and put the stdout in output.
+ */
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(bindir.c_str());
+ output += "Change Dir: ";
+ output += bindir;
+ output += "\n";
+
+ int retVal;
+ bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
+ cmSystemTools::SetRunCommandHideConsole(true);
+ std::string outputBuffer;
+ std::string* outputPtr = &outputBuffer;
+
+ // should we do a clean first?
+ if (clean)
+ {
+ std::vector<std::string> cleanCommand;
+ this->GenerateBuildCommand(cleanCommand, makeCommandCSTR, projectName,
+ bindir, "clean", config, fast);
+ output += "\nRun Clean Command:";
+ output += cmSystemTools::PrintSingleCommand(cleanCommand);
+ output += "\n";
+
+ if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr,
+ &retVal, 0, outputflag, timeout))
+ {
+ cmSystemTools::SetRunCommandHideConsole(hideconsole);
+ cmSystemTools::Error("Generator: execution of make clean failed.");
+ output += *outputPtr;
+ output += "\nGenerator: execution of make clean failed.\n";
+
+ // return to the original directory
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ return 1;
+ }
+ output += *outputPtr;
+ }
+
+ // now build
+ std::vector<std::string> makeCommand;
+ this->GenerateBuildCommand(makeCommand, makeCommandCSTR, projectName,
+ bindir, target, config, fast, nativeOptions);
+ std::string makeCommandStr = cmSystemTools::PrintSingleCommand(makeCommand);
+ output += "\nRun Build Command:";
+ output += makeCommandStr;
+ output += "\n";
+
+ if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr,
+ &retVal, 0, outputflag, timeout))
+ {
+ cmSystemTools::SetRunCommandHideConsole(hideconsole);
+ cmSystemTools::Error
+ ("Generator: execution of make failed. Make command was: ",
+ makeCommandStr.c_str());
+ output += *outputPtr;
+ output += "\nGenerator: execution of make failed. Make command was: "
+ + makeCommandStr + "\n";
+
+ // return to the original directory
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ return 1;
+ }
+ output += *outputPtr;
+ cmSystemTools::SetRunCommandHideConsole(hideconsole);
+
+ // The SGI MipsPro 7.3 compiler does not return an error code when
+ // the source has a #error in it! This is a work-around for such
+ // compilers.
+ if((retVal == 0) && (output.find("#error") != std::string::npos))
+ {
+ retVal = 1;
+ }
+
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ return retVal;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalGenerator::GenerateCMakeBuildCommand(
+ const std::string& target, const std::string& config,
+ const std::string& native,
+ bool ignoreErrors)
+{
+ std::string makeCommand = cmSystemTools::GetCMakeCommand();
+ makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
+ makeCommand += " --build .";
+ if(!config.empty())
+ {
+ makeCommand += " --config \"";
+ makeCommand += config;
+ makeCommand += "\"";
+ }
+ if(!target.empty())
+ {
+ makeCommand += " --target \"";
+ makeCommand += target;
+ makeCommand += "\"";
+ }
+ const char* sep = " -- ";
+ if(ignoreErrors)
+ {
+ const char* iflag = this->GetBuildIgnoreErrorsFlag();
+ if(iflag && *iflag)
+ {
+ makeCommand += sep;
+ makeCommand += iflag;
+ sep = " ";
+ }
+ }
+ if(!native.empty())
+ {
+ makeCommand += sep;
+ makeCommand += native;
+ }
+ return makeCommand;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::AddLocalGenerator(cmLocalGenerator *lg)
+{
+ this->LocalGenerators.push_back(lg);
+
+ // update progress
+ // estimate how many lg there will be
+ const char *numGenC =
+ this->CMakeInstance->GetCacheManager()->GetCacheValue
+ ("CMAKE_NUMBER_OF_LOCAL_GENERATORS");
+
+ if (!numGenC)
+ {
+ // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
+ // we are in the first time progress and we have no
+ // idea how long it will be. So, just move half way
+ // there each time, and don't go over 95%
+ this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
+ if(this->FirstTimeProgress > 0.95f)
+ {
+ this->FirstTimeProgress = 0.95f;
+ }
+ this->CMakeInstance->UpdateProgress("Configuring",
+ this->FirstTimeProgress);
+ return;
+ }
+
+ int numGen = atoi(numGenC);
+ float prog = 0.9f*static_cast<float>(this->LocalGenerators.size())/
+ static_cast<float>(numGen);
+ if (prog > 0.9f)
+ {
+ prog = 0.9f;
+ }
+ this->CMakeInstance->UpdateProgress("Configuring", prog);
+}
+
+void cmGlobalGenerator::AddInstallComponent(const char* component)
+{
+ if(component && *component)
+ {
+ this->InstallComponents.insert(component);
+ }
+}
+
+void cmGlobalGenerator::EnableInstallTarget()
+{
+ this->InstallTargetEnabled = true;
+}
+
+cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
+{
+ cmLocalGenerator *lg = new cmLocalGenerator;
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
+ cmMakefile* mf)
+{
+ this->SetConfiguredFilesPath(gen);
+ this->TryCompileOuterMakefile = mf;
+ const char* make =
+ gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
+ this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make,
+ "make program",
+ cmCacheManager::FILEPATH);
+ // copy the enabled languages
+ this->LanguageEnabled = gen->LanguageEnabled;
+ this->LanguagesReady = gen->LanguagesReady;
+ this->ExtensionToLanguage = gen->ExtensionToLanguage;
+ this->IgnoreExtensions = gen->IgnoreExtensions;
+ this->LanguageToOutputExtension = gen->LanguageToOutputExtension;
+ this->LanguageToLinkerPreference = gen->LanguageToLinkerPreference;
+ this->OutputExtensions = gen->OutputExtensions;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::SetConfiguredFilesPath(cmGlobalGenerator* gen)
+{
+ if(!gen->ConfiguredFilesPath.empty())
+ {
+ this->ConfiguredFilesPath = gen->ConfiguredFilesPath;
+ }
+ else
+ {
+ this->ConfiguredFilesPath = gen->CMakeInstance->GetHomeOutputDirectory();
+ this->ConfiguredFilesPath += cmake::GetCMakeFilesDirectory();
+ }
+}
+
+bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
+ cmLocalGenerator* gen) const
+{
+ if(!gen || gen == root)
+ {
+ // No directory excludes itself.
+ return false;
+ }
+
+ if(gen->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+ {
+ // This directory is excluded from its parent.
+ return true;
+ }
+
+ // This directory is included in its parent. Check whether the
+ // parent is excluded.
+ return this->IsExcluded(root, gen->GetParent());
+}
+
+bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
+ cmTarget const& target) const
+{
+ if(target.GetType() == cmTarget::INTERFACE_LIBRARY
+ || target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+ {
+ // This target is excluded from its directory.
+ return true;
+ }
+ else
+ {
+ // This target is included in its directory. Check whether the
+ // directory is excluded.
+ return this->IsExcluded(root, target.GetMakefile()->GetLocalGenerator());
+ }
+}
+
+void
+cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang) const
+{
+ for(std::map<std::string, bool>::const_iterator i =
+ this->LanguageEnabled.begin(); i != this->LanguageEnabled.end(); ++i)
+ {
+ lang.push_back(i->first);
+ }
+}
+
+int cmGlobalGenerator::GetLinkerPreference(const std::string& lang) const
+{
+ std::map<std::string, int>::const_iterator it =
+ this->LanguageToLinkerPreference.find(lang);
+ if (it != this->LanguageToLinkerPreference.end())
+ {
+ return it->second;
+ }
+ return 0;
+}
+
+void cmGlobalGenerator::FillProjectMap()
+{
+ this->ProjectMap.clear(); // make sure we start with a clean map
+ unsigned int i;
+ for(i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ // for each local generator add all projects
+ cmLocalGenerator *lg = this->LocalGenerators[i];
+ std::string name;
+ do
+ {
+ if (name != lg->GetMakefile()->GetProjectName())
+ {
+ name = lg->GetMakefile()->GetProjectName();
+ this->ProjectMap[name].push_back(this->LocalGenerators[i]);
+ }
+ lg = lg->GetParent();
+ }
+ while (lg);
+ }
+}
+
+
+// Build a map that contains a the set of targets used by each local
+// generator directory level.
+void cmGlobalGenerator::FillLocalGeneratorToTargetMap()
+{
+ this->LocalGeneratorToTargetMap.clear();
+ // Loop over all targets in all local generators.
+ for(std::vector<cmLocalGenerator*>::const_iterator
+ lgi = this->LocalGenerators.begin();
+ 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)
+ {
+ cmTarget const& target = t->second;
+
+ // Consider the directory containing the target and all its
+ // parents until something excludes the target.
+ for(cmLocalGenerator* clg = lg; clg && !this->IsExcluded(clg, target);
+ clg = clg->GetParent())
+ {
+ // This local generator includes the target.
+ std::set<cmTarget const*>& targetSet =
+ this->LocalGeneratorToTargetMap[clg];
+ targetSet.insert(&target);
+
+ // Add dependencies of the included target. An excluded
+ // target may still be included if it is a dependency of a
+ // non-excluded target.
+ TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
+ for(TargetDependSet::const_iterator ti = tgtdeps.begin();
+ ti != tgtdeps.end(); ++ti)
+ {
+ cmTarget const* ttt = *ti;
+ targetSet.insert(ttt);
+ }
+ }
+ }
+ }
+}
+
+
+///! Find a local generator by its startdirectory
+cmLocalGenerator*
+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()->GetStartDirectory();
+ if (sd == start_dir)
+ {
+ return *it;
+ }
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::AddAlias(const std::string& name, cmTarget *tgt)
+{
+ this->AliasTargets[name] = tgt;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalGenerator::IsAlias(const std::string& name) const
+{
+ return this->AliasTargets.find(name) != this->AliasTargets.end();
+}
+
+//----------------------------------------------------------------------------
+cmTarget*
+cmGlobalGenerator::FindTarget(const std::string& name,
+ bool excludeAliases) const
+{
+ if (!excludeAliases)
+ {
+ TargetMap::const_iterator ai = this->AliasTargets.find(name);
+ if (ai != this->AliasTargets.end())
+ {
+ return 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 i->second;
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalGenerator::NameResolvesToFramework(const std::string& libname) const
+{
+ if(cmSystemTools::IsPathToFramework(libname.c_str()))
+ {
+ return true;
+ }
+
+ if(cmTarget* tgt = this->FindTarget(libname))
+ {
+ if(tgt->IsFrameworkOnApple())
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+//----------------------------------------------------------------------------
+inline std::string removeQuotes(const std::string& s)
+{
+ if(s[0] == '\"' && s[s.size()-1] == '\"')
+ {
+ return s.substr(1, s.size()-2);
+ }
+ return s;
+}
+
+void cmGlobalGenerator::SetCMakeInstance(cmake* cm)
+{
+ // Store a pointer to the cmake object instance.
+ this->CMakeInstance = cm;
+}
+
+void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
+{
+ cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
+ const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
+ const char* cmakeCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
+
+ // CPack
+ std::string workingDir = mf->GetStartOutputDirectory();
+ cmCustomCommandLines cpackCommandLines;
+ std::vector<std::string> depends;
+ cmCustomCommandLine singleLine;
+ singleLine.push_back(cmSystemTools::GetCPackCommand());
+ if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
+ {
+ singleLine.push_back("-C");
+ singleLine.push_back(cmakeCfgIntDir);
+ }
+ singleLine.push_back("--config");
+ std::string configFile = mf->GetStartOutputDirectory();;
+ configFile += "/CPackConfig.cmake";
+ std::string relConfigFile = "./CPackConfig.cmake";
+ singleLine.push_back(relConfigFile);
+ cpackCommandLines.push_back(singleLine);
+ if ( this->GetPreinstallTargetName() )
+ {
+ depends.push_back(this->GetPreinstallTargetName());
+ }
+ else
+ {
+ const char* noPackageAll =
+ mf->GetDefinition("CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY");
+ if(!noPackageAll || cmSystemTools::IsOff(noPackageAll))
+ {
+ depends.push_back(this->GetAllTargetName());
+ }
+ }
+ if(cmSystemTools::FileExists(configFile.c_str()))
+ {
+ (*targets)[this->GetPackageTargetName()]
+ = this->CreateGlobalTarget(this->GetPackageTargetName(),
+ "Run CPack packaging tool...",
+ &cpackCommandLines, depends,
+ workingDir.c_str());
+ }
+ // CPack source
+ const char* packageSourceTargetName = this->GetPackageSourceTargetName();
+ if ( packageSourceTargetName )
+ {
+ cpackCommandLines.erase(cpackCommandLines.begin(),
+ cpackCommandLines.end());
+ singleLine.erase(singleLine.begin(), singleLine.end());
+ depends.erase(depends.begin(), depends.end());
+ singleLine.push_back(cmSystemTools::GetCPackCommand());
+ singleLine.push_back("--config");
+ configFile = mf->GetStartOutputDirectory();;
+ configFile += "/CPackSourceConfig.cmake";
+ relConfigFile = "./CPackSourceConfig.cmake";
+ singleLine.push_back(relConfigFile);
+ if(cmSystemTools::FileExists(configFile.c_str()))
+ {
+ singleLine.push_back(configFile);
+ cpackCommandLines.push_back(singleLine);
+ (*targets)[packageSourceTargetName]
+ = this->CreateGlobalTarget(packageSourceTargetName,
+ "Run CPack packaging tool for source...",
+ &cpackCommandLines, depends,
+ workingDir.c_str()
+ );
+ }
+ }
+
+ // Test
+ if(mf->IsOn("CMAKE_TESTING_ENABLED"))
+ {
+ cpackCommandLines.erase(cpackCommandLines.begin(),
+ cpackCommandLines.end());
+ singleLine.erase(singleLine.begin(), singleLine.end());
+ depends.erase(depends.begin(), depends.end());
+ singleLine.push_back(cmSystemTools::GetCTestCommand());
+ singleLine.push_back("--force-new-ctest-process");
+ if(cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.')
+ {
+ singleLine.push_back("-C");
+ singleLine.push_back(cmakeCfgIntDir);
+ }
+ else // TODO: This is a hack. Should be something to do with the generator
+ {
+ singleLine.push_back("$(ARGS)");
+ }
+ cpackCommandLines.push_back(singleLine);
+ (*targets)[this->GetTestTargetName()]
+ = this->CreateGlobalTarget(this->GetTestTargetName(),
+ "Running tests...", &cpackCommandLines, depends, 0);
+ }
+
+ //Edit Cache
+ const char* editCacheTargetName = this->GetEditCacheTargetName();
+ if ( editCacheTargetName )
+ {
+ cpackCommandLines.erase(cpackCommandLines.begin(),
+ cpackCommandLines.end());
+ singleLine.erase(singleLine.begin(), singleLine.end());
+ depends.erase(depends.begin(), depends.end());
+
+ // Use generator preference for the edit_cache rule if it is defined.
+ std::string edit_cmd = this->GetEditCacheCommand();
+ if (!edit_cmd.empty())
+ {
+ singleLine.push_back(edit_cmd);
+ singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
+ singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
+ cpackCommandLines.push_back(singleLine);
+ (*targets)[editCacheTargetName] =
+ this->CreateGlobalTarget(
+ editCacheTargetName, "Running CMake cache editor...",
+ &cpackCommandLines, depends, 0);
+ }
+ else
+ {
+ singleLine.push_back(cmakeCommand);
+ singleLine.push_back("-E");
+ singleLine.push_back("echo");
+ singleLine.push_back("No interactive CMake dialog available.");
+ cpackCommandLines.push_back(singleLine);
+ (*targets)[editCacheTargetName] =
+ this->CreateGlobalTarget(
+ editCacheTargetName,
+ "No interactive CMake dialog available...",
+ &cpackCommandLines, depends, 0);
+ }
+ }
+
+ //Rebuild Cache
+ const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName();
+ if ( rebuildCacheTargetName )
+ {
+ cpackCommandLines.erase(cpackCommandLines.begin(),
+ cpackCommandLines.end());
+ singleLine.erase(singleLine.begin(), singleLine.end());
+ depends.erase(depends.begin(), depends.end());
+ singleLine.push_back(cmakeCommand);
+ singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
+ singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
+ cpackCommandLines.push_back(singleLine);
+ (*targets)[rebuildCacheTargetName] =
+ this->CreateGlobalTarget(
+ rebuildCacheTargetName, "Running CMake to regenerate build system...",
+ &cpackCommandLines, depends, 0);
+ }
+
+ //Install
+ bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES");
+ if(this->InstallTargetEnabled && skipInstallRules)
+ {
+ mf->IssueMessage(cmake::WARNING,
+ "CMAKE_SKIP_INSTALL_RULES was enabled even though "
+ "installation rules have been specified");
+ }
+ else if(this->InstallTargetEnabled && !skipInstallRules)
+ {
+ if(!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.')
+ {
+ std::set<std::string>* componentsSet = &this->InstallComponents;
+ cpackCommandLines.erase(cpackCommandLines.begin(),
+ cpackCommandLines.end());
+ depends.erase(depends.begin(), depends.end());
+ cmOStringStream ostr;
+ if ( componentsSet->size() > 0 )
+ {
+ ostr << "Available install components are:";
+ std::set<std::string>::iterator it;
+ for (
+ it = componentsSet->begin();
+ it != componentsSet->end();
+ ++ it )
+ {
+ ostr << " \"" << *it << "\"";
+ }
+ }
+ else
+ {
+ ostr << "Only default component available";
+ }
+ singleLine.push_back(ostr.str());
+ (*targets)["list_install_components"]
+ = this->CreateGlobalTarget("list_install_components",
+ ostr.str().c_str(),
+ &cpackCommandLines, depends, 0);
+ }
+ std::string cmd = cmakeCommand;
+ cpackCommandLines.erase(cpackCommandLines.begin(),
+ cpackCommandLines.end());
+ singleLine.erase(singleLine.begin(), singleLine.end());
+ depends.erase(depends.begin(), depends.end());
+ if ( this->GetPreinstallTargetName() )
+ {
+ depends.push_back(this->GetPreinstallTargetName());
+ }
+ else
+ {
+ const char* noall =
+ mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
+ if(!noall || cmSystemTools::IsOff(noall))
+ {
+ depends.push_back(this->GetAllTargetName());
+ }
+ }
+ if(mf->GetDefinition("CMake_BINARY_DIR"))
+ {
+ // We are building CMake itself. We cannot use the original
+ // executable to install over itself. The generator will
+ // automatically convert this name to the build-time location.
+ cmd = "cmake";
+ }
+ singleLine.push_back(cmd);
+ if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
+ {
+ std::string cfgArg = "-DBUILD_TYPE=";
+ cfgArg += mf->GetDefinition("CMAKE_CFG_INTDIR");
+ singleLine.push_back(cfgArg);
+ }
+ singleLine.push_back("-P");
+ singleLine.push_back("cmake_install.cmake");
+ cpackCommandLines.push_back(singleLine);
+ (*targets)[this->GetInstallTargetName()] =
+ this->CreateGlobalTarget(
+ this->GetInstallTargetName(), "Install the project...",
+ &cpackCommandLines, depends, 0);
+
+ // install_local
+ if(const char* install_local = this->GetInstallLocalTargetName())
+ {
+ cmCustomCommandLine localCmdLine = singleLine;
+
+ localCmdLine.insert(localCmdLine.begin()+1,
+ "-DCMAKE_INSTALL_LOCAL_ONLY=1");
+ cpackCommandLines.erase(cpackCommandLines.begin(),
+ cpackCommandLines.end());
+ cpackCommandLines.push_back(localCmdLine);
+
+ (*targets)[install_local] =
+ this->CreateGlobalTarget(
+ install_local, "Installing only the local directory...",
+ &cpackCommandLines, depends, 0);
+ }
+
+ // install_strip
+ const char* install_strip = this->GetInstallStripTargetName();
+ if((install_strip !=0) && (mf->IsSet("CMAKE_STRIP")))
+ {
+ cmCustomCommandLine stripCmdLine = singleLine;
+
+ stripCmdLine.insert(stripCmdLine.begin()+1,"-DCMAKE_INSTALL_DO_STRIP=1");
+ cpackCommandLines.erase(cpackCommandLines.begin(),
+ cpackCommandLines.end());
+ cpackCommandLines.push_back(stripCmdLine);
+
+ (*targets)[install_strip] =
+ this->CreateGlobalTarget(
+ install_strip, "Installing the project stripped...",
+ &cpackCommandLines, depends, 0);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmGlobalGenerator::GetPredefinedTargetsFolder()
+{
+ const char* prop =
+ this->GetCMakeInstance()->GetProperty("PREDEFINED_TARGETS_FOLDER");
+
+ if (prop)
+ {
+ return prop;
+ }
+
+ return "CMakePredefinedTargets";
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalGenerator::UseFolderProperty()
+{
+ const char* prop = this->GetCMakeInstance()->GetProperty("USE_FOLDERS");
+
+ // If this property is defined, let the setter turn this on or off...
+ //
+ if (prop)
+ {
+ return cmSystemTools::IsOn(prop);
+ }
+
+ // By default, this feature is OFF, since it is not supported in the
+ // Visual Studio Express editions until VS11:
+ //
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::EnableMinGWLanguage(cmMakefile *mf)
+{
+ this->FindMakeProgram(mf);
+ std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ std::vector<std::string> locations;
+ locations.push_back(cmSystemTools::GetProgramPath(makeProgram.c_str()));
+ locations.push_back("/mingw/bin");
+ locations.push_back("c:/mingw/bin");
+ std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
+ std::string gcc = "gcc.exe";
+ if(tgcc.size())
+ {
+ gcc = tgcc;
+ }
+ std::string tgxx = cmSystemTools::FindProgram("g++", locations);
+ std::string gxx = "g++.exe";
+ if(tgxx.size())
+ {
+ gxx = tgxx;
+ }
+ std::string trc = cmSystemTools::FindProgram("windres", locations);
+ std::string rc = "windres.exe";
+ if(trc.size())
+ {
+ rc = trc;
+ }
+ mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
+ mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
+ mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
+}
+
+//----------------------------------------------------------------------------
+cmTarget cmGlobalGenerator::CreateGlobalTarget(
+ const std::string& name, const char* message,
+ const cmCustomCommandLines* commandLines,
+ std::vector<std::string> depends,
+ const char* workingDirectory)
+{
+ // Package
+ cmTarget target;
+ target.GetProperties().SetCMakeInstance(this->CMakeInstance);
+ target.SetType(cmTarget::GLOBAL_TARGET, name);
+ target.SetProperty("EXCLUDE_FROM_ALL","TRUE");
+
+ std::vector<std::string> no_outputs;
+ std::vector<std::string> no_depends;
+ // Store the custom command in the target.
+ cmCustomCommand cc(0, no_outputs, no_depends, *commandLines, 0,
+ workingDirectory);
+ target.AddPostBuildCommand(cc);
+ target.SetProperty("EchoString", message);
+ std::vector<std::string>::iterator dit;
+ for ( dit = depends.begin(); dit != depends.end(); ++ dit )
+ {
+ target.AddUtility(*dit);
+ }
+
+ // Organize in the "predefined targets" folder:
+ //
+ if (this->UseFolderProperty())
+ {
+ target.SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
+ }
+
+ return target;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalGenerator::GenerateRuleFile(std::string const& output) const
+{
+ std::string ruleFile = output;
+ ruleFile += ".rule";
+ const char* dir = this->GetCMakeCFGIntDir();
+ if(dir && dir[0] == '$')
+ {
+ cmSystemTools::ReplaceString(ruleFile, dir,
+ cmake::GetCMakeFilesDirectory());
+ }
+ return ruleFile;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalGenerator::GetSharedLibFlagsForLanguage(
+ std::string const& l) const
+{
+ std::map<std::string, std::string>::const_iterator it =
+ this->LanguageToOriginalSharedLibFlags.find(l);
+ if(it != this->LanguageToOriginalSharedLibFlags.end())
+ {
+ return it->second;
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::AppendDirectoryForConfig(const std::string&,
+ const std::string&,
+ const std::string&,
+ std::string&)
+{
+ // Subclasses that support multiple configurations should implement
+ // this method to append the subdirectory for the given build
+ // configuration.
+}
+
+//----------------------------------------------------------------------------
+cmGlobalGenerator::TargetDependSet const&
+cmGlobalGenerator::GetTargetDirectDepends(cmTarget 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
+ // by one or more of the cmake generators.
+
+ // Adding additional targets to this list will require a policy!
+ const char* reservedTargets[] =
+ {
+ "all", "ALL_BUILD",
+ "help",
+ "install", "INSTALL",
+ "preinstall",
+ "clean",
+ "edit_cache",
+ "rebuild_cache",
+ "test", "RUN_TESTS",
+ "package", "PACKAGE",
+ "package_source",
+ "ZERO_CHECK",
+ 0
+ };
+
+ for(const char** reservedTarget = reservedTargets;
+ *reservedTarget; ++reservedTarget)
+ {
+ if(name == *reservedTarget) return true;
+ }
+
+ return false;
+}
+
+void cmGlobalGenerator::SetExternalMakefileProjectGenerator(
+ cmExternalMakefileProjectGenerator *extraGenerator)
+{
+ this->ExtraGenerator = extraGenerator;
+ if (this->ExtraGenerator!=0)
+ {
+ this->ExtraGenerator->SetGlobalGenerator(this);
+ }
+}
+
+std::string cmGlobalGenerator::GetExtraGeneratorName() const
+{
+ return this->ExtraGenerator? this->ExtraGenerator->GetName() : std::string();
+}
+
+void cmGlobalGenerator::FileReplacedDuringGenerate(const std::string& filename)
+{
+ this->FilesReplacedDuringGenerate.push_back(filename);
+}
+
+void
+cmGlobalGenerator
+::GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames)
+{
+ filenames.clear();
+ std::copy(
+ this->FilesReplacedDuringGenerate.begin(),
+ this->FilesReplacedDuringGenerate.end(),
+ std::back_inserter(filenames));
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
+ TargetDependSet& originalTargets,
+ cmLocalGenerator* root,
+ GeneratorVector const& generators)
+{
+ // loop over all local generators
+ for(std::vector<cmLocalGenerator*>::const_iterator i = generators.begin();
+ i != generators.end(); ++i)
+ {
+ // check to make sure generator is not excluded
+ if(this->IsExcluded(root, *i))
+ {
+ continue;
+ }
+ cmMakefile* mf = (*i)->GetMakefile();
+ // Get the targets in the makefile
+ cmTargets &tgts = mf->GetTargets();
+ // loop over all the targets
+ for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
+ {
+ cmTarget* target = &l->second;
+ if(this->IsRootOnlyTarget(target) &&
+ target->GetMakefile() != root->GetMakefile())
+ {
+ continue;
+ }
+ // put the target in the set of original targets
+ originalTargets.insert(target);
+ // Get the set of targets that depend on target
+ this->AddTargetDepends(target, projectTargets);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalGenerator::IsRootOnlyTarget(cmTarget* target) const
+{
+ return (target->GetType() == cmTarget::GLOBAL_TARGET ||
+ target->GetName() == this->GetAllTargetName());
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::AddTargetDepends(cmTarget const* target,
+ TargetDependSet& projectTargets)
+{
+ // add the target itself
+ if(projectTargets.insert(target).second)
+ {
+ // This is the first time we have encountered the target.
+ // Recursively follow its dependencies.
+ TargetDependSet const& ts = this->GetTargetDirectDepends(*target);
+ for(TargetDependSet::const_iterator i = ts.begin(); i != ts.end(); ++i)
+ {
+ cmTarget const* dtarget = *i;
+ this->AddTargetDepends(dtarget, projectTargets);
+ }
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::AddToManifest(const std::string& config,
+ std::string const& f)
+{
+ // Add to the main manifest for this configuration.
+ this->TargetManifest[config].insert(f);
+
+ // Add to the content listing for the file's directory.
+ std::string dir = cmSystemTools::GetFilenamePath(f);
+ std::string file = cmSystemTools::GetFilenameName(f);
+ this->DirectoryContentMap[dir].insert(file);
+}
+
+//----------------------------------------------------------------------------
+std::set<std::string> const&
+cmGlobalGenerator::GetDirectoryContent(std::string const& dir, bool needDisk)
+{
+ DirectoryContent& dc = this->DirectoryContentMap[dir];
+ if(needDisk && !dc.LoadedFromDisk)
+ {
+ // Load the directory content from disk.
+ cmsys::Directory d;
+ if(d.Load(dir.c_str()))
+ {
+ unsigned long n = d.GetNumberOfFiles();
+ for(unsigned long i = 0; i < n; ++i)
+ {
+ const char* f = d.GetFile(i);
+ if(strcmp(f, ".") != 0 && strcmp(f, "..") != 0)
+ {
+ dc.insert(f);
+ }
+ }
+ }
+ dc.LoadedFromDisk = true;
+ }
+ return dc;
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
+ std::string const& content)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ // Ignore if there are no outputs.
+ if(outputs.empty())
+ {
+ return;
+ }
+
+ // Compute a hash of the rule.
+ RuleHash hash;
+ {
+ unsigned char const* data =
+ reinterpret_cast<unsigned char const*>(content.c_str());
+ int length = static_cast<int>(content.length());
+ cmsysMD5* sum = cmsysMD5_New();
+ cmsysMD5_Initialize(sum);
+ cmsysMD5_Append(sum, data, length);
+ cmsysMD5_FinalizeHex(sum, hash.Data);
+ cmsysMD5_Delete(sum);
+ }
+
+ // Shorten the output name (in expected use case).
+ cmLocalGenerator* lg = this->GetLocalGenerators()[0];
+ std::string fname = lg->Convert(outputs[0],
+ cmLocalGenerator::HOME_OUTPUT);
+
+ // Associate the hash with this output.
+ this->RuleHashes[fname] = hash;
+#else
+ (void)outputs;
+ (void)content;
+#endif
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::CheckRuleHashes()
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ std::string home = this->GetCMakeInstance()->GetHomeOutputDirectory();
+ std::string pfile = home;
+ pfile += this->GetCMakeInstance()->GetCMakeFilesDirectory();
+ pfile += "/CMakeRuleHashes.txt";
+ this->CheckRuleHashes(pfile, home);
+ this->WriteRuleHashes(pfile);
+#endif
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::CheckRuleHashes(std::string const& pfile,
+ std::string const& home)
+{
+#if defined(_WIN32) || defined(__CYGWIN__)
+ cmsys::ifstream fin(pfile.c_str(), std::ios::in | std::ios::binary);
+#else
+ cmsys::ifstream fin(pfile.c_str(), std::ios::in);
+#endif
+ if(!fin)
+ {
+ return;
+ }
+ std::string line;
+ std::string fname;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ // Line format is a 32-byte hex string followed by a space
+ // followed by a file name (with no escaping).
+
+ // Skip blank and comment lines.
+ if(line.size() < 34 || line[0] == '#')
+ {
+ continue;
+ }
+
+ // Get the filename.
+ fname = line.substr(33, line.npos);
+
+ // Look for a hash for this file's rule.
+ std::map<std::string, RuleHash>::const_iterator rhi =
+ this->RuleHashes.find(fname);
+ if(rhi != this->RuleHashes.end())
+ {
+ // Compare the rule hash in the file to that we were given.
+ if(strncmp(line.c_str(), rhi->second.Data, 32) != 0)
+ {
+ // The rule has changed. Delete the output so it will be
+ // built again.
+ fname = cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
+ cmSystemTools::RemoveFile(fname.c_str());
+ }
+ }
+ else
+ {
+ // We have no hash for a rule previously listed. This may be a
+ // case where a user has turned off a build option and might
+ // want to turn it back on later, so do not delete the file.
+ // Instead, we keep the rule hash as long as the file exists so
+ // that if the feature is turned back on and the rule has
+ // changed the file is still rebuilt.
+ std::string fpath =
+ cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
+ if(cmSystemTools::FileExists(fpath.c_str()))
+ {
+ RuleHash hash;
+ strncpy(hash.Data, line.c_str(), 32);
+ this->RuleHashes[fname] = hash;
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile)
+{
+ // Now generate a new persistence file with the current hashes.
+ if(this->RuleHashes.empty())
+ {
+ cmSystemTools::RemoveFile(pfile.c_str());
+ }
+ else
+ {
+ cmGeneratedFileStream fout(pfile.c_str());
+ fout << "# Hashes of file build rules.\n";
+ for(std::map<std::string, RuleHash>::const_iterator
+ rhi = this->RuleHashes.begin(); rhi != this->RuleHashes.end(); ++rhi)
+ {
+ fout.write(rhi->second.Data, 32);
+ fout << " " << rhi->first << "\n";
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::WriteSummary()
+{
+ cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
+
+ // Record all target directories in a central location.
+ std::string fname = mf->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)
+ {
+ if ((ti->second)->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ this->WriteSummary(ti->second);
+ fout << ti->second->GetSupportDirectory() << "\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::WriteSummary(cmTarget* target)
+{
+ // Place the labels file in a per-target support directory.
+ std::string dir = target->GetSupportDirectory();
+ std::string file = dir;
+ file += "/Labels.txt";
+
+ // Check whether labels are enabled for this target.
+ if(const char* value = target->GetProperty("LABELS"))
+ {
+ cmSystemTools::MakeDirectory(dir.c_str());
+ cmGeneratedFileStream fout(file.c_str());
+
+ // List the target-wide labels. All sources in the target get
+ // these labels.
+ std::vector<std::string> labels;
+ cmSystemTools::ExpandListArgument(value, labels);
+ if(!labels.empty())
+ {
+ fout << "# Target labels\n";
+ for(std::vector<std::string>::const_iterator li = labels.begin();
+ li != labels.end(); ++li)
+ {
+ fout << " " << *li << "\n";
+ }
+ }
+
+ // List the source files with any per-source labels.
+ fout << "# Source files and their labels\n";
+ std::vector<cmSourceFile*> sources;
+ std::vector<std::string> configs;
+ target->GetMakefile()->GetConfigurations(configs);
+ if (configs.empty())
+ {
+ configs.push_back("");
+ }
+ for(std::vector<std::string>::const_iterator ci = configs.begin();
+ ci != configs.end(); ++ci)
+ {
+ target->GetSourceFiles(sources, *ci);
+ }
+ std::set<cmSourceFile*> emitted;
+ for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
+ si != sources.end(); ++si)
+ {
+ if (!emitted.insert(*si).second)
+ {
+ continue;
+ }
+ cmSourceFile* sf = *si;
+ fout << sf->GetFullPath() << "\n";
+ if(const char* svalue = sf->GetProperty("LABELS"))
+ {
+ labels.clear();
+ cmSystemTools::ExpandListArgument(svalue, labels);
+ for(std::vector<std::string>::const_iterator li = labels.begin();
+ li != labels.end(); ++li)
+ {
+ fout << " " << *li << "\n";
+ }
+ }
+ }
+ }
+ else
+ {
+ cmSystemTools::RemoveFile(file.c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+// static
+std::string cmGlobalGenerator::EscapeJSON(const std::string& s) {
+ std::string result;
+ for (std::string::size_type i = 0; i < s.size(); ++i) {
+ if (s[i] == '"' || s[i] == '\\') {
+ result += '\\';
+ }
+ result += s[i];
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::AddEvaluationFile(const std::string &inputFile,
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> outputExpr,
+ cmMakefile *makefile,
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
+ bool inputIsContent)
+{
+ this->EvaluationFiles.push_back(
+ new cmGeneratorExpressionEvaluationFile(inputFile, outputExpr,
+ makefile, condition,
+ inputIsContent));
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::ProcessEvaluationFiles()
+{
+ std::set<std::string> generatedFiles;
+ for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
+ li = this->EvaluationFiles.begin();
+ li != this->EvaluationFiles.end();
+ ++li)
+ {
+ (*li)->Generate();
+ if (cmSystemTools::GetFatalErrorOccured())
+ {
+ return;
+ }
+ std::vector<std::string> files = (*li)->GetFiles();
+ for(std::vector<std::string>::const_iterator fi = files.begin();
+ fi != files.end(); ++fi)
+ {
+ if (!generatedFiles.insert(*fi).second)
+ {
+ cmSystemTools::Error("File to be generated by multiple different "
+ "commands: ", fi->c_str());
+ return;
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalGenerator::ExpandCFGIntDir(const std::string& str,
+ const std::string& /*config*/) const
+{
+ return str;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalGenerator::GenerateCPackPropertiesFile()
+{
+ cmake::InstalledFilesMap const& installedFiles =
+ this->CMakeInstance->GetInstalledFiles();
+
+ cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
+
+ std::vector<std::string> configs;
+ std::string config = mf->GetConfigurations(configs, false);
+
+ std::string path = this->CMakeInstance->GetStartOutputDirectory();
+ path += "/CPackProperties.cmake";
+
+ if(!cmSystemTools::FileExists(path.c_str()) && installedFiles.empty())
+ {
+ return true;
+ }
+
+ cmGeneratedFileStream file(path.c_str());
+ file << "# CPack properties\n";
+
+ for(cmake::InstalledFilesMap::const_iterator i = installedFiles.begin();
+ i != installedFiles.end(); ++i)
+ {
+ cmInstalledFile const& installedFile = i->second;
+
+ cmCPackPropertiesGenerator cpackPropertiesGenerator(
+ mf, installedFile, configs);
+
+ cpackPropertiesGenerator.Generate(file, config, configs);
+ }
+
+ return true;
+}
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
new file mode 100644
index 0000000000..ddd7e910d7
--- /dev/null
+++ b/Source/cmGlobalGenerator.h
@@ -0,0 +1,493 @@
+/*============================================================================
+ 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 cmGlobalGenerator_h
+#define cmGlobalGenerator_h
+
+#include "cmStandardIncludes.h"
+
+#include "cmTarget.h" // For cmTargets
+#include "cmTargetDepend.h" // For cmTargetDependSet
+#include "cmSystemTools.h" // for cmSystemTools::OutputOption
+#include "cmExportSetMap.h" // For cmExportSetMap
+#include "cmGeneratorTarget.h"
+#include "cmGeneratorExpression.h"
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include <cmsys/hash_map.hxx>
+#endif
+
+class cmake;
+class cmGeneratorTarget;
+class cmGeneratorExpressionEvaluationFile;
+class cmMakefile;
+class cmLocalGenerator;
+class cmExternalMakefileProjectGenerator;
+class cmTarget;
+class cmInstallTargetGenerator;
+class cmInstallFilesGenerator;
+class cmExportBuildFileGenerator;
+class cmQtAutoGenerators;
+
+/** \class cmGlobalGenerator
+ * \brief Responsible for overseeing the generation process for the entire tree
+ *
+ * Subclasses of this class generate makefiles for various
+ * platforms.
+ */
+class cmGlobalGenerator
+{
+public:
+ ///! Free any memory allocated with the GlobalGenerator
+ cmGlobalGenerator();
+ virtual ~cmGlobalGenerator();
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ ///! Get the name for this generator
+ virtual std::string GetName() const { return "Generic"; }
+
+ /** Check whether the given name matches the current generator. */
+ virtual bool MatchesGeneratorName(const std::string& name) const
+ { return this->GetName() == name; }
+
+ /** Tell the generator about the target system. */
+ virtual bool SetSystemName(std::string const&, cmMakefile*)
+ { return true; }
+
+ /** Set the generator-specific platform name. Returns true if platform
+ is supported and false otherwise. */
+ virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
+
+ /** Set the generator-specific toolset name. Returns true if toolset
+ is supported and false otherwise. */
+ virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf);
+
+ /**
+ * Create LocalGenerators and process the CMakeLists files. This does not
+ * actually produce any makefiles, DSPs, etc.
+ */
+ virtual void Configure();
+
+ /**
+ * Generate the all required files for building this project/tree. This
+ * basically creates a series of LocalGenerators for each directory and
+ * requests that they Generate.
+ */
+ void DoGenerate();
+
+ /**
+ * Set/Get and Clear the enabled languages.
+ */
+ void SetLanguageEnabled(const std::string&, cmMakefile* mf);
+ bool GetLanguageEnabled(const std::string&) const;
+ void ClearEnabledLanguages();
+ void GetEnabledLanguages(std::vector<std::string>& lang) const;
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+
+ /**
+ * Resolve the CMAKE_<lang>_COMPILER setting for the given language.
+ * Intended to be called from EnableLanguage.
+ */
+ void ResolveLanguageCompiler(const std::string &lang, cmMakefile *mf,
+ bool optional) const;
+
+ /**
+ * Try to determine system information, get it from another generator
+ */
+ virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
+ cmMakefile* mf);
+
+ /**
+ * Try running cmake and building a file. This is used for dynamically
+ * loaded commands, not as part of the usual build process.
+ */
+ virtual int TryCompile(const std::string& srcdir, const std::string& bindir,
+ const std::string& projectName,
+ const std::string& targetName,
+ bool fast, std::string& output, cmMakefile* mf);
+
+
+ /**
+ * Build a file given the following information. This is a more direct call
+ * that is used by both CTest and TryCompile. If target name is NULL or
+ * empty then all is assumed. clean indicates if a "make clean" should be
+ * done first.
+ */
+ int Build(const std::string& srcdir, const std::string& bindir,
+ const std::string& projectName, const std::string& targetName,
+ std::string& output,
+ const std::string& makeProgram, const std::string& config,
+ bool clean, bool fast,
+ double timeout,
+ cmSystemTools::OutputOption outputflag=cmSystemTools::OUTPUT_NONE,
+ std::vector<std::string> const& nativeOptions =
+ std::vector<std::string>());
+
+ virtual void GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName, const std::string& projectDir,
+ const std::string& targetName, const std::string& config, bool fast,
+ std::vector<std::string> const& makeOptions = std::vector<std::string>()
+ );
+
+ /** Generate a "cmake --build" call for a given target and config. */
+ std::string GenerateCMakeBuildCommand(const std::string& target,
+ const std::string& config,
+ const std::string& native,
+ bool ignoreErrors);
+
+ ///! Set the CMake instance
+ void SetCMakeInstance(cmake *cm);
+
+ ///! Get the CMake instance
+ cmake *GetCMakeInstance() const { return this->CMakeInstance; }
+
+ void SetConfiguredFilesPath(cmGlobalGenerator* gen);
+ const std::vector<cmLocalGenerator *>& GetLocalGenerators() const {
+ return this->LocalGenerators;}
+
+ cmLocalGenerator* GetCurrentLocalGenerator()
+ {return this->CurrentLocalGenerator;}
+
+ void SetCurrentLocalGenerator(cmLocalGenerator* lg)
+ {this->CurrentLocalGenerator = lg;}
+
+ void AddLocalGenerator(cmLocalGenerator *lg);
+
+ ///! Set an generator for an "external makefile based project"
+ void SetExternalMakefileProjectGenerator(
+ cmExternalMakefileProjectGenerator *extraGenerator);
+
+ std::string GetExtraGeneratorName() const;
+
+ void AddInstallComponent(const char* component);
+
+ const std::set<std::string>* GetInstallComponents() const
+ { return &this->InstallComponents; }
+
+ cmExportSetMap& GetExportSets() {return this->ExportSets;}
+
+ /** Add a file to the manifest of generated targets for a configuration. */
+ void AddToManifest(const std::string& config, std::string const& f);
+
+ void EnableInstallTarget();
+
+ int TryCompileTimeout;
+
+ bool GetForceUnixPaths() const { return this->ForceUnixPaths; }
+ bool GetToolSupportsColor() const { return this->ToolSupportsColor; }
+
+ ///! return the language for the given extension
+ std::string GetLanguageFromExtension(const char* ext) const;
+ ///! is an extension to be ignored
+ bool IgnoreFile(const char* ext) const;
+ ///! What is the preference for linkers and this language (None or Preferred)
+ int GetLinkerPreference(const std::string& lang) const;
+ ///! What is the object file extension for a given source file?
+ std::string GetLanguageOutputExtension(cmSourceFile const&) const;
+
+ ///! What is the configurations directory variable called?
+ virtual const char* GetCMakeCFGIntDir() const { return "."; }
+
+ ///! expand CFGIntDir for a configuration
+ virtual std::string ExpandCFGIntDir(const std::string& str,
+ const std::string& config) const;
+
+ /** Get whether the generator should use a script for link commands. */
+ bool GetUseLinkScript() const { return this->UseLinkScript; }
+
+ /** Get whether the generator should produce special marks on rules
+ producing symbolic (non-file) outputs. */
+ bool GetNeedSymbolicMark() const { return this->NeedSymbolicMark; }
+
+ /*
+ * Determine what program to use for building the project.
+ */
+ virtual void FindMakeProgram(cmMakefile*);
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /** Is this the Visual Studio 6 generator? */
+ virtual bool IsForVS6() const { return false; }
+#endif
+
+ ///! Find a target by name by searching the local generators.
+ cmTarget* FindTarget(const std::string& name,
+ bool excludeAliases = false) const;
+
+ void AddAlias(const std::string& name, cmTarget *tgt);
+ bool IsAlias(const std::string& name) const;
+
+ /** Determine if a name resolves to a framework on disk or a built target
+ that is a framework. */
+ bool NameResolvesToFramework(const std::string& libname) const;
+
+ ///! Find a local generator by its startdirectory
+ cmLocalGenerator* FindLocalGenerator(const std::string& start_dir) const;
+
+ /** Append the subdirectory for the given configuration. If anything is
+ appended the given prefix and suffix will be appended around it, which
+ is useful for leading or trailing slashes. */
+ virtual void AppendDirectoryForConfig(const std::string& prefix,
+ const std::string& config,
+ const std::string& suffix,
+ std::string& dir);
+
+ /** Get the manifest of all targets that will be built for each
+ configuration. This is valid during generation only. */
+ cmTargetManifest const& GetTargetManifest() const
+ { return this->TargetManifest; }
+
+ /** Get the content of a directory. Directory listings are loaded
+ from disk at most once and cached. During the generation step
+ the content will include the target files to be built even if
+ they do not yet exist. */
+ std::set<std::string> const& GetDirectoryContent(std::string const& dir,
+ bool needDisk = true);
+
+ void AddTarget(cmTarget* t);
+
+ static bool IsReservedTarget(std::string const& name);
+
+ virtual const char* GetAllTargetName() const { return "ALL_BUILD"; }
+ virtual const char* GetInstallTargetName() const { return "INSTALL"; }
+ virtual const char* GetInstallLocalTargetName() const { return 0; }
+ virtual const char* GetInstallStripTargetName() const { return 0; }
+ virtual const char* GetPreinstallTargetName() const { return 0; }
+ virtual const char* GetTestTargetName() const { return "RUN_TESTS"; }
+ virtual const char* GetPackageTargetName() const { return "PACKAGE"; }
+ virtual const char* GetPackageSourceTargetName() const { return 0; }
+ virtual const char* GetEditCacheTargetName() const { return 0; }
+ virtual const char* GetRebuildCacheTargetName() const { return 0; }
+ virtual const char* GetCleanTargetName() const { return 0; }
+
+ // Lookup edit_cache target command preferred by this generator.
+ virtual std::string GetEditCacheCommand() const { return ""; }
+
+ // Class to track a set of dependencies.
+ typedef cmTargetDependSet TargetDependSet;
+
+ // what targets does the specified target depend on directly
+ // via a target_link_libraries or add_dependencies
+ TargetDependSet const& GetTargetDirectDepends(cmTarget const& target);
+
+ /** Get per-target generator information. */
+ cmGeneratorTarget* GetGeneratorTarget(cmTarget const*) const;
+
+ const std::map<std::string, std::vector<cmLocalGenerator*> >& GetProjectMap()
+ const {return this->ProjectMap;}
+
+ // track files replaced during a Generate
+ void FileReplacedDuringGenerate(const std::string& filename);
+ void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
+
+ void AddRuleHash(const std::vector<std::string>& outputs,
+ std::string const& content);
+
+ /** Return whether the given binary directory is unused. */
+ bool BinaryDirectoryIsNew(const std::string& dir)
+ {
+ return this->BinaryDirectories.insert(dir).second;
+ }
+ /** Supported systems creates a GUID for the given name */
+ virtual void CreateGUID(const std::string&) {}
+
+ /** Return true if the generated build tree may contain multiple builds.
+ i.e. "Can I build Debug and Release in the same tree?" */
+ virtual bool IsMultiConfig() { return false; }
+
+ std::string GetSharedLibFlagsForLanguage(std::string const& lang) const;
+
+ /** Generate an <output>.rule file path for a given command output. */
+ virtual std::string GenerateRuleFile(std::string const& output) const;
+
+ static std::string EscapeJSON(const std::string& s);
+
+ void AddEvaluationFile(const std::string &inputFile,
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> outputName,
+ cmMakefile *makefile,
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
+ bool inputIsContent);
+
+ void ProcessEvaluationFiles();
+
+ std::map<std::string, cmExportBuildFileGenerator*>& GetBuildExportSets()
+ {return this->BuildExportSets;}
+ void AddBuildExportSet(cmExportBuildFileGenerator*);
+ void AddBuildExportExportSet(cmExportBuildFileGenerator*);
+ bool IsExportedTargetsFile(const std::string &filename) const;
+ bool GenerateImportFile(const std::string &file);
+ cmExportBuildFileGenerator*
+ GetExportedTargetsFile(const std::string &filename) const;
+ void AddCMP0042WarnTarget(const std::string& target);
+
+ virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
+
+ bool GenerateCPackPropertiesFile();
+
+protected:
+ virtual void Generate();
+
+ typedef std::vector<cmLocalGenerator*> GeneratorVector;
+ // for a project collect all its targets by following depend
+ // information, and also collect all the targets
+ virtual void GetTargetSets(TargetDependSet& projectTargets,
+ TargetDependSet& originalTargets,
+ cmLocalGenerator* root, GeneratorVector const&);
+ bool IsRootOnlyTarget(cmTarget* target) const;
+ void AddTargetDepends(cmTarget const* target,
+ TargetDependSet& projectTargets);
+ void SetLanguageEnabledFlag(const std::string& l, cmMakefile* mf);
+ void SetLanguageEnabledMaps(const std::string& l, cmMakefile* mf);
+ void FillExtensionToLanguageMap(const std::string& l, cmMakefile* mf);
+
+ virtual bool ComputeTargetDepends();
+
+ virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const;
+
+ typedef std::vector<std::pair<cmQtAutoGenerators,
+ cmTarget const*> > AutogensType;
+ void CreateQtAutoGeneratorsTargets(AutogensType& autogens);
+
+ std::string SelectMakeProgram(const std::string& makeProgram,
+ const std::string& makeDefault = "") const;
+
+ // Fill the ProjectMap, this must be called after LocalGenerators
+ // has been populated.
+ void FillProjectMap();
+ void CheckLocalGenerators();
+ bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen) const;
+ bool IsExcluded(cmLocalGenerator* root, cmTarget const& target) const;
+ void FillLocalGeneratorToTargetMap();
+ void CreateDefaultGlobalTargets(cmTargets* targets);
+ cmTarget CreateGlobalTarget(const std::string& name, const char* message,
+ const cmCustomCommandLines* commandLines,
+ std::vector<std::string> depends, const char* workingDir);
+
+ bool NeedSymbolicMark;
+ bool UseLinkScript;
+ bool ForceUnixPaths;
+ bool ToolSupportsColor;
+ std::string FindMakeProgramFile;
+ std::string ConfiguredFilesPath;
+ cmake *CMakeInstance;
+ std::vector<cmLocalGenerator *> LocalGenerators;
+ cmLocalGenerator* CurrentLocalGenerator;
+ // map from project name to vector of local generators in that project
+ std::map<std::string, std::vector<cmLocalGenerator*> > ProjectMap;
+ std::map<cmLocalGenerator*, std::set<cmTarget const*> >
+ LocalGeneratorToTargetMap;
+
+ // Set of named installation components requested by the project.
+ std::set<std::string> InstallComponents;
+ bool InstallTargetEnabled;
+ // Sets of named target exports
+ cmExportSetMap ExportSets;
+ std::map<std::string, cmExportBuildFileGenerator*> BuildExportSets;
+ std::map<std::string, cmExportBuildFileGenerator*> BuildExportExportSets;
+
+ // Manifest of all targets that will be built for each configuration.
+ // This is computed just before local generators generate.
+ cmTargetManifest TargetManifest;
+
+ // All targets in the entire project.
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
+#else
+ typedef std::map<std::string,cmTarget *> TargetMap;
+#endif
+ TargetMap TotalTargets;
+ TargetMap AliasTargets;
+ TargetMap ImportedTargets;
+ std::vector<cmGeneratorExpressionEvaluationFile*> EvaluationFiles;
+
+ virtual const char* GetPredefinedTargetsFolder();
+ virtual bool UseFolderProperty();
+ void EnableMinGWLanguage(cmMakefile *mf);
+
+private:
+ cmMakefile* TryCompileOuterMakefile;
+ float FirstTimeProgress;
+ // If you add a new map here, make sure it is copied
+ // in EnableLanguagesFromGenerator
+ std::map<std::string, bool> IgnoreExtensions;
+ std::map<std::string, bool> LanguageEnabled;
+ std::set<std::string> LanguagesReady; // Ready for try_compile
+ std::map<std::string, std::string> OutputExtensions;
+ std::map<std::string, std::string> LanguageToOutputExtension;
+ std::map<std::string, std::string> ExtensionToLanguage;
+ std::map<std::string, int> LanguageToLinkerPreference;
+ std::map<std::string, std::string> LanguageToOriginalSharedLibFlags;
+
+ // Record hashes for rules and outputs.
+ struct RuleHash { char Data[32]; };
+ std::map<std::string, RuleHash> RuleHashes;
+ void CheckRuleHashes();
+ void CheckRuleHashes(std::string const& pfile, std::string const& home);
+ void WriteRuleHashes(std::string const& pfile);
+
+ void WriteSummary();
+ void WriteSummary(cmTarget* target);
+ void FinalizeTargetCompileInfo();
+
+ virtual void ForceLinkerLanguages();
+
+ virtual void PrintCompilerAdvice(std::ostream& os, std::string const& lang,
+ const char* envVar) const;
+ void CheckCompilerIdCompatibility(cmMakefile* mf,
+ std::string const& lang) const;
+
+ cmExternalMakefileProjectGenerator* ExtraGenerator;
+
+ // track files replaced during a Generate
+ std::vector<std::string> FilesReplacedDuringGenerate;
+
+ // Store computed inter-target dependencies.
+ typedef std::map<cmTarget const*, TargetDependSet> TargetDependMap;
+ TargetDependMap TargetDependencies;
+
+ // Per-target generator information.
+ cmGeneratorTargetsType GeneratorTargets;
+ friend class cmake;
+ void CreateGeneratorTargets(cmMakefile* mf);
+ void CreateGeneratorTargets();
+
+ void ClearGeneratorMembers();
+
+ virtual const char* GetBuildIgnoreErrorsFlag() const { return 0; }
+
+ // Cache directory content and target files to be built.
+ struct DirectoryContent: public std::set<std::string>
+ {
+ typedef std::set<std::string> derived;
+ bool LoadedFromDisk;
+ DirectoryContent(): LoadedFromDisk(false) {}
+ DirectoryContent(DirectoryContent const& dc):
+ derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
+ };
+ std::map<std::string, DirectoryContent> DirectoryContentMap;
+
+ // Set of binary directories on disk.
+ std::set<std::string> BinaryDirectories;
+
+ // track targets to issue CMP0042 warning for.
+ std::set<std::string> CMP0042WarnTargets;
+};
+
+#endif
diff --git a/Source/cmGlobalGeneratorFactory.h b/Source/cmGlobalGeneratorFactory.h
new file mode 100644
index 0000000000..3c2cd60429
--- /dev/null
+++ b/Source/cmGlobalGeneratorFactory.h
@@ -0,0 +1,61 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 cmGlobalGeneratorFactory_h
+#define cmGlobalGeneratorFactory_h
+
+#include "cmStandardIncludes.h"
+
+class cmGlobalGenerator;
+struct cmDocumentationEntry;
+
+/** \class cmGlobalGeneratorFactory
+ * \brief Responable for creating cmGlobalGenerator instances
+ *
+ * Subclasses of this class generate instances of cmGlobalGenerator.
+ */
+class cmGlobalGeneratorFactory
+{
+public:
+ virtual ~cmGlobalGeneratorFactory() {}
+
+ /** Create a GlobalGenerator */
+ virtual cmGlobalGenerator* CreateGlobalGenerator(
+ const std::string& n) const = 0;
+
+ /** Get the documentation entry for this factory */
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const = 0;
+
+ /** Get the names of the current registered generators */
+ virtual void GetGenerators(std::vector<std::string>& names) const = 0;
+};
+
+template<class T>
+class cmGlobalGeneratorSimpleFactory : public cmGlobalGeneratorFactory
+{
+public:
+ /** Create a GlobalGenerator */
+ virtual cmGlobalGenerator* CreateGlobalGenerator(
+ const std::string& name) const {
+ if (name != T::GetActualName()) return 0;
+ return new T; }
+
+ /** Get the documentation entry for this factory */
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const {
+ T::GetDocumentation(entry); }
+
+ /** Get the names of the current registered generators */
+ virtual void GetGenerators(std::vector<std::string>& names) const {
+ names.push_back(T::GetActualName()); }
+};
+
+#endif
diff --git a/Source/cmGlobalJOMMakefileGenerator.cxx b/Source/cmGlobalJOMMakefileGenerator.cxx
new file mode 100644
index 0000000000..bc15ef297c
--- /dev/null
+++ b/Source/cmGlobalJOMMakefileGenerator.cxx
@@ -0,0 +1,68 @@
+/*============================================================================
+ 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 "cmGlobalJOMMakefileGenerator.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+
+cmGlobalJOMMakefileGenerator::cmGlobalJOMMakefileGenerator()
+{
+ this->FindMakeProgramFile = "CMakeJOMFindMake.cmake";
+ this->ForceUnixPaths = false;
+ this->ToolSupportsColor = true;
+ this->UseLinkScript = false;
+}
+
+void cmGlobalJOMMakefileGenerator
+::EnableLanguage(std::vector<std::string>const& l,
+ cmMakefile *mf,
+ bool optional)
+{
+ // pick a default
+ mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
+ mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
+ if(!(cmSystemTools::GetEnv("INCLUDE") &&
+ cmSystemTools::GetEnv("LIB"))
+ )
+ {
+ std::string message = "To use the JOM generator, cmake must be run "
+ "from a shell that can use the compiler cl from the command line. "
+ "This environment does not contain INCLUDE, LIB, or LIBPATH, and "
+ "these must be set for the cl compiler to work. ";
+ mf->IssueMessage(cmake::WARNING,
+ message);
+ }
+
+ this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalJOMMakefileGenerator::CreateLocalGenerator()
+{
+ cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
+ lg->SetDefineWindowsNULL(true);
+ lg->SetWindowsShell(true);
+ lg->SetMakeSilentFlag("/nologo");
+ lg->SetGlobalGenerator(this);
+ lg->SetIgnoreLibPrefix(true);
+ lg->SetPassMakeflags(true);
+ lg->SetNMake(true);
+ lg->SetUnixCD(false);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalJOMMakefileGenerator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalJOMMakefileGenerator::GetActualName();
+ entry.Brief = "Generates JOM makefiles.";
+}
diff --git a/Source/cmGlobalJOMMakefileGenerator.h b/Source/cmGlobalJOMMakefileGenerator.h
new file mode 100644
index 0000000000..fbb35f34f8
--- /dev/null
+++ b/Source/cmGlobalJOMMakefileGenerator.h
@@ -0,0 +1,50 @@
+/*============================================================================
+ 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 cmGlobalJOMMakefileGenerator_h
+#define cmGlobalJOMMakefileGenerator_h
+
+#include "cmGlobalUnixMakefileGenerator3.h"
+
+/** \class cmGlobalJOMMakefileGenerator
+ * \brief Write a JOM makefiles.
+ *
+ * cmGlobalJOMMakefileGenerator manages nmake build process for a tree
+ */
+class cmGlobalJOMMakefileGenerator : public cmGlobalUnixMakefileGenerator3
+{
+public:
+ cmGlobalJOMMakefileGenerator();
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalJOMMakefileGenerator>(); }
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalJOMMakefileGenerator::GetActualName();}
+ // use NMake Makefiles in the name so that scripts/tests that depend on the
+ // name NMake Makefiles will work
+ static std::string GetActualName() {return "NMake Makefiles JOM";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+};
+
+#endif
diff --git a/Source/cmGlobalKdevelopGenerator.cxx b/Source/cmGlobalKdevelopGenerator.cxx
new file mode 100644
index 0000000000..89d25c4377
--- /dev/null
+++ b/Source/cmGlobalKdevelopGenerator.cxx
@@ -0,0 +1,612 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@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 "cmGlobalKdevelopGenerator.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include "cmSourceFile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmSystemTools.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Directory.hxx>
+#include <cmsys/FStream.hxx>
+
+//----------------------------------------------------------------------------
+void cmGlobalKdevelopGenerator
+::GetDocumentation(cmDocumentationEntry& entry, const std::string&) const
+{
+ entry.Name = this->GetName();
+ entry.Brief = "Generates KDevelop 3 project files.";
+}
+
+cmGlobalKdevelopGenerator::cmGlobalKdevelopGenerator()
+:cmExternalMakefileProjectGenerator()
+{
+ this->SupportedGlobalGenerators.push_back("Unix Makefiles");
+#ifdef CMAKE_USE_NINJA
+ this->SupportedGlobalGenerators.push_back("Ninja");
+#endif
+}
+
+void cmGlobalKdevelopGenerator::Generate()
+{
+ // for each sub project in the project create
+ // a kdevelop project
+ for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
+ it = this->GlobalGenerator->GetProjectMap().begin();
+ it!= this->GlobalGenerator->GetProjectMap().end();
+ ++it)
+ {
+ cmMakefile* mf = it->second[0]->GetMakefile();
+ std::string outputDir=mf->GetStartOutputDirectory();
+ std::string projectDir=mf->GetHomeDirectory();
+ std::string projectName=mf->GetProjectName();
+ std::string cmakeFilePattern("CMakeLists.txt;*.cmake;");
+ std::string fileToOpen;
+ const std::vector<cmLocalGenerator*>& lgs= it->second;
+ // create the project.kdevelop.filelist file
+ if(!this->CreateFilelistFile(lgs, outputDir, projectDir,
+ projectName, cmakeFilePattern, fileToOpen))
+ {
+ cmSystemTools::Error("Can not create filelist file");
+ return;
+ }
+ //try to find the name of an executable so we have something to
+ //run from kdevelop for now just pick the first executable found
+ std::string executable;
+ 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();
+ ti != targets.end(); ti++)
+ {
+ if (ti->second.GetType()==cmTarget::EXECUTABLE)
+ {
+ executable = ti->second.GetLocation("");
+ break;
+ }
+ }
+ if (!executable.empty())
+ {
+ break;
+ }
+ }
+
+ // now create a project file
+ this->CreateProjectFile(outputDir, projectDir, projectName,
+ executable, cmakeFilePattern, fileToOpen);
+ }
+}
+
+bool cmGlobalKdevelopGenerator
+::CreateFilelistFile(const std::vector<cmLocalGenerator*>& lgs,
+ const std::string& outputDir,
+ const std::string& projectDirIn,
+ const std::string& projectname,
+ std::string& cmakeFilePattern,
+ std::string& fileToOpen)
+{
+ std::string projectDir = projectDirIn + "/";
+ std::string filename = outputDir+ "/" + projectname +".kdevelop.filelist";
+
+ std::set<std::string> files;
+ std::string tmp;
+
+ for (std::vector<cmLocalGenerator*>::const_iterator it=lgs.begin();
+ it!=lgs.end(); it++)
+ {
+ cmMakefile* makefile=(*it)->GetMakefile();
+ const std::vector<std::string>& listFiles=makefile->GetListFiles();
+ for (std::vector<std::string>::const_iterator lt=listFiles.begin();
+ lt!=listFiles.end(); lt++)
+ {
+ tmp=*lt;
+ cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
+ // make sure the file is part of this source tree
+ if ((tmp[0]!='/') &&
+ (strstr(tmp.c_str(),
+ cmake::GetCMakeFilesDirectoryPostSlash())==0))
+ {
+ files.insert(tmp);
+ tmp=cmSystemTools::GetFilenameName(tmp);
+ //add all files which dont match the default
+ // */CMakeLists.txt;*cmake; to the file pattern
+ if ((tmp!="CMakeLists.txt")
+ && (strstr(tmp.c_str(), ".cmake")==0))
+ {
+ cmakeFilePattern+=tmp+";";
+ }
+ }
+ }
+
+ //get all sources
+ cmTargets& targets=makefile->GetTargets();
+ for (cmTargets::iterator ti = targets.begin();
+ ti != targets.end(); ti++)
+ {
+ std::vector<cmSourceFile*> sources;
+ ti->second.GetSourceFiles(sources, ti->second.GetMakefile()
+ ->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
+ si!=sources.end(); si++)
+ {
+ tmp=(*si)->GetFullPath();
+ std::string headerBasename=cmSystemTools::GetFilenamePath(tmp);
+ headerBasename+="/";
+ headerBasename+=cmSystemTools::GetFilenameWithoutExtension(tmp);
+
+ cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
+
+ if ((tmp[0]!='/') &&
+ (strstr(tmp.c_str(),
+ cmake::GetCMakeFilesDirectoryPostSlash())==0) &&
+ (cmSystemTools::GetFilenameExtension(tmp)!=".moc"))
+ {
+ files.insert(tmp);
+
+ // check if there's a matching header around
+ for(std::vector<std::string>::const_iterator
+ ext = makefile->GetHeaderExtensions().begin();
+ ext != makefile->GetHeaderExtensions().end(); ++ext)
+ {
+ std::string hname=headerBasename;
+ hname += ".";
+ hname += *ext;
+ if(cmSystemTools::FileExists(hname.c_str()))
+ {
+ cmSystemTools::ReplaceString(hname, projectDir.c_str(), "");
+ files.insert(hname);
+ break;
+ }
+ }
+ }
+ }
+ for (std::vector<std::string>::const_iterator lt=listFiles.begin();
+ lt!=listFiles.end(); lt++)
+ {
+ tmp=*lt;
+ cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
+ if ((tmp[0]!='/') &&
+ (strstr(tmp.c_str(),
+ cmake::GetCMakeFilesDirectoryPostSlash())==0))
+ {
+ files.insert(tmp);
+ }
+ }
+ }
+ }
+
+ //check if the output file already exists and read it
+ //insert all files which exist into the set of files
+ cmsys::ifstream oldFilelist(filename.c_str());
+ if (oldFilelist)
+ {
+ while (cmSystemTools::GetLineFromStream(oldFilelist, tmp))
+ {
+ if (tmp[0]=='/')
+ {
+ continue;
+ }
+ std::string completePath=projectDir+tmp;
+ if (cmSystemTools::FileExists(completePath.c_str()))
+ {
+ files.insert(tmp);
+ }
+ }
+ oldFilelist.close();
+ }
+
+ //now write the new filename
+ cmGeneratedFileStream fout(filename.c_str());
+ if(!fout)
+ {
+ return false;
+ }
+
+ fileToOpen="";
+ for (std::set<std::string>::const_iterator it=files.begin();
+ it!=files.end(); it++)
+ {
+ // get the full path to the file
+ tmp=cmSystemTools::CollapseFullPath(it->c_str(), projectDir.c_str());
+ // just select the first source file
+ if (fileToOpen.empty())
+ {
+ std::string ext = cmSystemTools::GetFilenameExtension(tmp);
+ if ((ext==".c") || (ext==".cc") || (ext==".cpp") || (ext==".cxx")
+ || (ext==".C") || (ext==".h") || (ext==".hpp"))
+ {
+ fileToOpen=tmp;
+ }
+ }
+ // make it relative to the project dir
+ cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
+ // only put relative paths
+ if (tmp.size() && tmp[0] != '/')
+ {
+ fout << tmp.c_str() <<"\n";
+ }
+ }
+ return true;
+}
+
+
+/* create the project file, if it already exists, merge it with the
+existing one, otherwise create a new one */
+void cmGlobalKdevelopGenerator
+::CreateProjectFile(const std::string& outputDir,
+ const std::string& projectDir,
+ const std::string& projectname,
+ const std::string& executable,
+ const std::string& cmakeFilePattern,
+ const std::string& fileToOpen)
+{
+ this->Blacklist.clear();
+
+ std::string filename=outputDir+"/";
+ filename+=projectname+".kdevelop";
+ std::string sessionFilename=outputDir+"/";
+ sessionFilename+=projectname+".kdevses";
+
+ if (cmSystemTools::FileExists(filename.c_str()))
+ {
+ this->MergeProjectFiles(outputDir, projectDir, filename,
+ executable, cmakeFilePattern,
+ fileToOpen, sessionFilename);
+ }
+ else
+ {
+ // add all subdirectories which are cmake build directories to the
+ // kdevelop blacklist so they are not monitored for added or removed files
+ // since this is handled by adding files to the cmake files
+ cmsys::Directory d;
+ if (d.Load(projectDir.c_str()))
+ {
+ size_t numf = d.GetNumberOfFiles();
+ for (unsigned int i = 0; i < numf; i++)
+ {
+ std::string nextFile = d.GetFile(i);
+ if ((nextFile!=".") && (nextFile!=".."))
+ {
+ std::string tmp = projectDir;
+ tmp += "/";
+ tmp += nextFile;
+ if (cmSystemTools::FileIsDirectory(tmp.c_str()))
+ {
+ tmp += "/CMakeCache.txt";
+ if ((nextFile == "CMakeFiles")
+ || (cmSystemTools::FileExists(tmp.c_str())))
+ {
+ this->Blacklist.push_back(nextFile);
+ }
+ }
+ }
+ }
+ }
+ this->CreateNewProjectFile(outputDir, projectDir, filename,
+ executable, cmakeFilePattern,
+ fileToOpen, sessionFilename);
+ }
+
+}
+
+void cmGlobalKdevelopGenerator
+::MergeProjectFiles(const std::string& outputDir,
+ const std::string& projectDir,
+ const std::string& filename,
+ const std::string& executable,
+ const std::string& cmakeFilePattern,
+ const std::string& fileToOpen,
+ const std::string& sessionFilename)
+{
+ cmsys::ifstream oldProjectFile(filename.c_str());
+ if (!oldProjectFile)
+ {
+ this->CreateNewProjectFile(outputDir, projectDir, filename,
+ executable, cmakeFilePattern,
+ fileToOpen, sessionFilename);
+ return;
+ }
+
+ /* Read the existing project file (line by line), copy all lines
+ into the new project file, except the ones which can be reliably
+ set from contents of the CMakeLists.txt */
+ std::string tmp;
+ std::vector<std::string> lines;
+ while (cmSystemTools::GetLineFromStream(oldProjectFile, tmp))
+ {
+ lines.push_back(tmp);
+ }
+ oldProjectFile.close();
+
+ cmGeneratedFileStream fout(filename.c_str());
+ if(!fout)
+ {
+ return;
+ }
+
+ for (std::vector<std::string>::const_iterator it=lines.begin();
+ it!=lines.end(); it++)
+ {
+ const char* line=(*it).c_str();
+ // skip these tags as they are always replaced
+ if ((strstr(line, "<projectdirectory>")!=0)
+ || (strstr(line, "<projectmanagement>")!=0)
+ || (strstr(line, "<absoluteprojectpath>")!=0)
+ || (strstr(line, "<filelistdirectory>")!=0)
+ || (strstr(line, "<buildtool>")!=0)
+ || (strstr(line, "<builddir>")!=0))
+ {
+ continue;
+ }
+
+ // output the line from the file if it is not one of the above tags
+ fout<<*it<<"\n";
+ // if this is the <general> tag output the stuff that goes in the
+ // general tag
+ if (strstr(line, "<general>"))
+ {
+ fout<< " <projectmanagement>KDevCustomProject</projectmanagement>\n";
+ fout<< " <projectdirectory>" <<projectDir
+ << "</projectdirectory>\n"; //this one is important
+ fout<<" <absoluteprojectpath>true</absoluteprojectpath>\n";
+ //and this one
+ }
+ // inside kdevcustomproject the <filelistdirectory> must be put
+ if (strstr(line, "<kdevcustomproject>"))
+ {
+ fout<<" <filelistdirectory>"<<outputDir
+ <<"</filelistdirectory>\n";
+ }
+ // buildtool and builddir go inside <build>
+ if (strstr(line, "<build>"))
+ {
+ fout<<" <buildtool>make</buildtool>\n";
+ fout<<" <builddir>"<<outputDir<<"</builddir>\n";
+ }
+ }
+}
+
+void cmGlobalKdevelopGenerator
+::CreateNewProjectFile(const std::string& outputDir,
+ const std::string& projectDir,
+ const std::string& filename,
+ const std::string& executable,
+ const std::string& cmakeFilePattern,
+ const std::string& fileToOpen,
+ const std::string& sessionFilename)
+{
+ cmGeneratedFileStream fout(filename.c_str());
+ if(!fout)
+ {
+ return;
+ }
+
+ // check for a version control system
+ bool hasSvn = cmSystemTools::FileExists((projectDir + "/.svn").c_str());
+ bool hasCvs = cmSystemTools::FileExists((projectDir + "/CVS").c_str());
+
+ bool enableCxx = (this->GlobalGenerator->GetLanguageEnabled("C")
+ || this->GlobalGenerator->GetLanguageEnabled("CXX"));
+ bool enableFortran = this->GlobalGenerator->GetLanguageEnabled("Fortran");
+ std::string primaryLanguage = "C++";
+ if (enableFortran && !enableCxx)
+ {
+ primaryLanguage="Fortran77";
+ }
+
+ fout<<"<?xml version = '1.0'?>\n"
+ "<kdevelop>\n"
+ " <general>\n"
+ " <author></author>\n"
+ " <email></email>\n"
+ " <version>$VERSION$</version>\n"
+ " <projectmanagement>KDevCustomProject</projectmanagement>\n"
+ " <primarylanguage>" << primaryLanguage << "</primarylanguage>\n"
+ " <ignoreparts/>\n"
+ " <projectdirectory>" << projectDir <<
+ "</projectdirectory>\n"; //this one is important
+ fout<<" <absoluteprojectpath>true</absoluteprojectpath>\n"; //and this one
+
+ // setup additional languages
+ fout<<" <secondaryLanguages>\n";
+ if (enableFortran && enableCxx)
+ {
+ fout<<" <language>Fortran</language>\n";
+ }
+ if (enableCxx)
+ {
+ fout<<" <language>C</language>\n";
+ }
+ fout<<" </secondaryLanguages>\n";
+
+ if (hasSvn)
+ {
+ fout << " <versioncontrol>kdevsubversion</versioncontrol>\n";
+ }
+ else if (hasCvs)
+ {
+ fout << " <versioncontrol>kdevcvsservice</versioncontrol>\n";
+ }
+
+ fout<<" </general>\n"
+ " <kdevcustomproject>\n"
+ " <filelistdirectory>" << outputDir <<
+ "</filelistdirectory>\n"
+ " <run>\n"
+ " <mainprogram>" << executable << "</mainprogram>\n"
+ " <directoryradio>custom</directoryradio>\n"
+ " <customdirectory>"<<outputDir<<"</customdirectory>\n"
+ " <programargs></programargs>\n"
+ " <terminal>false</terminal>\n"
+ " <autocompile>true</autocompile>\n"
+ " <envvars/>\n"
+ " </run>\n"
+ " <build>\n"
+ " <buildtool>make</buildtool>\n"; //this one is important
+ fout<<" <builddir>"<<outputDir<<"</builddir>\n"; //and this one
+ fout<<" </build>\n"
+ " <make>\n"
+ " <abortonerror>false</abortonerror>\n"
+ " <numberofjobs>1</numberofjobs>\n"
+ " <dontact>false</dontact>\n"
+ " <makebin>" << this->GlobalGenerator->GetLocalGenerators()[0]->
+ GetMakefile()->GetRequiredDefinition("CMAKE_MAKE_PROGRAM")
+ << " </makebin>\n"
+ " <selectedenvironment>default</selectedenvironment>\n"
+ " <environments>\n"
+ " <default>\n"
+ " <envvar value=\"1\" name=\"VERBOSE\" />\n"
+ " <envvar value=\"1\" name=\"CMAKE_NO_VERBOSE\" />\n"
+ " </default>\n"
+ " </environments>\n"
+ " </make>\n";
+
+ fout<<" <blacklist>\n";
+ for(std::vector<std::string>::const_iterator dirIt=this->Blacklist.begin();
+ dirIt != this->Blacklist.end();
+ ++dirIt)
+ {
+ fout<<" <path>" << *dirIt << "</path>\n";
+ }
+ fout<<" </blacklist>\n";
+
+ fout<<" </kdevcustomproject>\n"
+ " <kdevfilecreate>\n"
+ " <filetypes/>\n"
+ " <useglobaltypes>\n"
+ " <type ext=\"ui\" />\n"
+ " <type ext=\"cpp\" />\n"
+ " <type ext=\"h\" />\n"
+ " </useglobaltypes>\n"
+ " </kdevfilecreate>\n"
+ " <kdevdoctreeview>\n"
+ " <projectdoc>\n"
+ " <userdocDir>html/</userdocDir>\n"
+ " <apidocDir>html/</apidocDir>\n"
+ " </projectdoc>\n"
+ " <ignoreqt_xml/>\n"
+ " <ignoredoxygen/>\n"
+ " <ignorekdocs/>\n"
+ " <ignoretocs/>\n"
+ " <ignoredevhelp/>\n"
+ " </kdevdoctreeview>\n";
+
+ if (enableCxx)
+ {
+ fout<<" <cppsupportpart>\n"
+ " <filetemplates>\n"
+ " <interfacesuffix>.h</interfacesuffix>\n"
+ " <implementationsuffix>.cpp</implementationsuffix>\n"
+ " </filetemplates>\n"
+ " </cppsupportpart>\n"
+ " <kdevcppsupport>\n"
+ " <codecompletion>\n"
+ " <includeGlobalFunctions>true</includeGlobalFunctions>\n"
+ " <includeTypes>true</includeTypes>\n"
+ " <includeEnums>true</includeEnums>\n"
+ " <includeTypedefs>false</includeTypedefs>\n"
+ " <automaticCodeCompletion>true</automaticCodeCompletion>\n"
+ " <automaticArgumentsHint>true</automaticArgumentsHint>\n"
+ " <automaticHeaderCompletion>true</automaticHeaderCompletion>\n"
+ " <codeCompletionDelay>250</codeCompletionDelay>\n"
+ " <argumentsHintDelay>400</argumentsHintDelay>\n"
+ " <headerCompletionDelay>250</headerCompletionDelay>\n"
+ " </codecompletion>\n"
+ " <references/>\n"
+ " </kdevcppsupport>\n";
+ }
+
+ if (enableFortran)
+ {
+ fout<<" <kdevfortransupport>\n"
+ " <ftnchek>\n"
+ " <division>false</division>\n"
+ " <extern>false</extern>\n"
+ " <declare>false</declare>\n"
+ " <pure>false</pure>\n"
+ " <argumentsall>false</argumentsall>\n"
+ " <commonall>false</commonall>\n"
+ " <truncationall>false</truncationall>\n"
+ " <usageall>false</usageall>\n"
+ " <f77all>false</f77all>\n"
+ " <portabilityall>false</portabilityall>\n"
+ " <argumentsonly/>\n"
+ " <commononly/>\n"
+ " <truncationonly/>\n"
+ " <usageonly/>\n"
+ " <f77only/>\n"
+ " <portabilityonly/>\n"
+ " </ftnchek>\n"
+ " </kdevfortransupport>\n";
+ }
+
+ // set up file groups. maybe this can be used with the CMake SOURCE_GROUP()
+ // command
+ fout<<" <kdevfileview>\n"
+ " <groups>\n"
+ " <group pattern=\"" << cmakeFilePattern <<
+ "\" name=\"CMake\" />\n";
+
+ if (enableCxx)
+ {
+ fout<<" <group pattern=\"*.h;*.hxx;*.hpp\" name=\"Header\" />\n"
+ " <group pattern=\"*.c\" name=\"C Sources\" />\n"
+ " <group pattern=\"*.cpp;*.C;*.cxx;*.cc\" name=\"C++ Sources\""
+ "/>\n";
+ }
+
+ if (enableFortran)
+ {
+ fout<<" <group pattern=\"*.f;*.F;*.f77;*.F77;*.f90;*.F90;*.for;*.f95;"
+ "*.F95\" name=\"Fortran Sources\" />\n";
+ }
+
+ fout<<" <group pattern=\"*.ui\" name=\"Qt Designer files\" />\n"
+ " <hidenonprojectfiles>true</hidenonprojectfiles>\n"
+ " </groups>\n"
+ " <tree>\n"
+ " <hidepatterns>*.o,*.lo,CVS,*~,cmake*</hidepatterns>\n"
+ " <hidenonprojectfiles>true</hidenonprojectfiles>\n"
+ " </tree>\n"
+ " </kdevfileview>\n"
+ "</kdevelop>\n";
+
+ if (sessionFilename.empty())
+ {
+ return;
+ }
+
+ // and a session file, so that kdevelop opens a file if it opens the
+ // project the first time
+ cmGeneratedFileStream devses(sessionFilename.c_str());
+ if(!devses)
+ {
+ return;
+ }
+ devses<<"<?xml version = '1.0' encoding = \'UTF-8\'?>\n"
+ "<!DOCTYPE KDevPrjSession>\n"
+ "<KDevPrjSession>\n"
+ " <DocsAndViews NumberOfDocuments=\"1\" >\n"
+ " <Doc0 NumberOfViews=\"1\" URL=\"file://" << fileToOpen <<
+ "\" >\n"
+ " <View0 line=\"0\" Type=\"Source\" />\n"
+ " </Doc0>\n"
+ " </DocsAndViews>\n"
+ "</KDevPrjSession>\n";
+}
+
diff --git a/Source/cmGlobalKdevelopGenerator.h b/Source/cmGlobalKdevelopGenerator.h
new file mode 100644
index 0000000000..0d59fc578a
--- /dev/null
+++ b/Source/cmGlobalKdevelopGenerator.h
@@ -0,0 +1,92 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2009 Kitware, Inc.
+ Copyright 2004 Alexander Neundorf (neundorf@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.
+============================================================================*/
+#ifndef cmGlobalKdevelopGenerator_h
+#define cmGlobalKdevelopGenerator_h
+
+#include "cmExternalMakefileProjectGenerator.h"
+
+class cmLocalGenerator;
+
+/** \class cmGlobalKdevelopGenerator
+ * \brief Write Unix Makefiles accompanied by KDevelop3 project files.
+ *
+ * cmGlobalKdevelopGenerator produces a project file for KDevelop 3 (KDevelop
+ * > 3.1.1). The project is based on the "Custom Makefile based C/C++"
+ * project of KDevelop. Such a project consists of Unix Makefiles in the
+ * build directory together with a \<your_project\>.kdevelop project file,
+ * which contains the project settings and a \<your_project\>.kdevelop.filelist
+ * file, which lists the source files relative to the kdevelop project
+ * directory. The kdevelop project directory is the base source directory.
+ */
+class cmGlobalKdevelopGenerator : public cmExternalMakefileProjectGenerator
+{
+public:
+ cmGlobalKdevelopGenerator();
+
+ virtual std::string GetName() const
+ { return cmGlobalKdevelopGenerator::GetActualName();}
+ static std::string GetActualName() { return "KDevelop3";}
+ static cmExternalMakefileProjectGenerator* New()
+ { return new cmGlobalKdevelopGenerator; }
+ /** Get the documentation entry for this generator. */
+ virtual void GetDocumentation(cmDocumentationEntry& entry,
+ const std::string& fullName) const;
+
+ virtual void Generate();
+private:
+ /*** Create the foo.kdevelop.filelist file, return false if it doesn't
+ succeed. If the file already exists the contents will be merged.
+ */
+ bool CreateFilelistFile(const std::vector<cmLocalGenerator*>& lgs,
+ const std::string& outputDir,
+ const std::string& projectDirIn,
+ const std::string& projectname,
+ std::string& cmakeFilePattern,
+ std::string& fileToOpen);
+
+ /** Create the foo.kdevelop file. This one calls MergeProjectFiles()
+ if it already exists, otherwise createNewProjectFile() The project
+ files will be created in \a outputDir (in the build tree), the
+ kdevelop project dir will be set to \a projectDir (in the source
+ tree). \a cmakeFilePattern consists of a lists of all cmake
+ listfiles used by this CMakeLists.txt */
+ void CreateProjectFile(const std::string& outputDir,
+ const std::string& projectDir,
+ const std::string& projectname,
+ const std::string& executable,
+ const std::string& cmakeFilePattern,
+ const std::string& fileToOpen);
+
+ /*** Reads the old foo.kdevelop line by line and only replaces the
+ "important" lines
+ */
+ void MergeProjectFiles(const std::string& outputDir,
+ const std::string& projectDir,
+ const std::string& filename,
+ const std::string& executable,
+ const std::string& cmakeFilePattern,
+ const std::string& fileToOpen,
+ const std::string& sessionFilename);
+ ///! Creates a new foo.kdevelop and a new foo.kdevses file
+ void CreateNewProjectFile(const std::string& outputDir,
+ const std::string& projectDir,
+ const std::string& filename,
+ const std::string& executable,
+ const std::string& cmakeFilePattern,
+ const std::string& fileToOpen,
+ const std::string& sessionFilename);
+
+ std::vector<std::string> Blacklist;
+};
+
+#endif
diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx
new file mode 100644
index 0000000000..16f05e5edf
--- /dev/null
+++ b/Source/cmGlobalMSYSMakefileGenerator.cxx
@@ -0,0 +1,114 @@
+/*============================================================================
+ 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 "cmGlobalMSYSMakefileGenerator.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include <cmsys/FStream.hxx>
+
+cmGlobalMSYSMakefileGenerator::cmGlobalMSYSMakefileGenerator()
+{
+ this->FindMakeProgramFile = "CMakeMSYSFindMake.cmake";
+ this->ForceUnixPaths = true;
+ this->ToolSupportsColor = true;
+ this->UseLinkScript = false;
+}
+
+std::string
+cmGlobalMSYSMakefileGenerator::FindMinGW(std::string const& makeloc)
+{
+ std::string fstab = makeloc;
+ fstab += "/../etc/fstab";
+ cmsys::ifstream fin(fstab.c_str());
+ std::string path;
+ std::string mount;
+ std::string mingwBin;
+ while(fin)
+ {
+ fin >> path;
+ fin >> mount;
+ if(mount == "/mingw")
+ {
+ mingwBin = path;
+ mingwBin += "/bin";
+ }
+ }
+ return mingwBin;
+}
+
+void cmGlobalMSYSMakefileGenerator
+::EnableLanguage(std::vector<std::string>const& l,
+ cmMakefile *mf,
+ bool optional)
+{
+ this->FindMakeProgram(mf);
+ std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ std::vector<std::string> locations;
+ std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str());
+ locations.push_back(this->FindMinGW(makeloc));
+ locations.push_back(makeloc);
+ locations.push_back("/mingw/bin");
+ locations.push_back("c:/mingw/bin");
+ std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
+ std::string gcc = "gcc.exe";
+ if(tgcc.size())
+ {
+ gcc = tgcc;
+ }
+ std::string tgxx = cmSystemTools::FindProgram("g++", locations);
+ std::string gxx = "g++.exe";
+ if(tgxx.size())
+ {
+ gxx = tgxx;
+ }
+ std::string trc = cmSystemTools::FindProgram("windres", locations);
+ std::string rc = "windres.exe";
+ if(trc.size())
+ {
+ rc = trc;
+ }
+ mf->AddDefinition("MSYS", "1");
+ mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
+ mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
+ mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
+ this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
+
+ if(!mf->IsSet("CMAKE_AR") &&
+ !this->CMakeInstance->GetIsInTryCompile() &&
+ !(1==l.size() && l[0]=="NONE"))
+ {
+ cmSystemTools::Error
+ ("CMAKE_AR was not found, please set to archive program. ",
+ mf->GetDefinition("CMAKE_AR"));
+ }
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalMSYSMakefileGenerator::CreateLocalGenerator()
+{
+ cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
+ lg->SetWindowsShell(false);
+ lg->SetMSYSShell(true);
+ lg->SetGlobalGenerator(this);
+ lg->SetIgnoreLibPrefix(true);
+ lg->SetPassMakeflags(false);
+ lg->SetUnixCD(true);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalMSYSMakefileGenerator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalMSYSMakefileGenerator::GetActualName();
+ entry.Brief = "Generates MSYS makefiles.";
+}
diff --git a/Source/cmGlobalMSYSMakefileGenerator.h b/Source/cmGlobalMSYSMakefileGenerator.h
new file mode 100644
index 0000000000..baecde7420
--- /dev/null
+++ b/Source/cmGlobalMSYSMakefileGenerator.h
@@ -0,0 +1,52 @@
+/*============================================================================
+ 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 cmGlobalMSYSMakefileGenerator_h
+#define cmGlobalMSYSMakefileGenerator_h
+
+#include "cmGlobalUnixMakefileGenerator3.h"
+
+/** \class cmGlobalMSYSMakefileGenerator
+ * \brief Write a NMake makefiles.
+ *
+ * cmGlobalMSYSMakefileGenerator manages nmake build process for a tree
+ */
+class cmGlobalMSYSMakefileGenerator : public cmGlobalUnixMakefileGenerator3
+{
+public:
+ cmGlobalMSYSMakefileGenerator();
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalMSYSMakefileGenerator>(); }
+
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalMSYSMakefileGenerator::GetActualName();}
+ static std::string GetActualName() {return "MSYS Makefiles";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+
+private:
+ std::string FindMinGW(std::string const& makeloc);
+};
+
+#endif
diff --git a/Source/cmGlobalMinGWMakefileGenerator.cxx b/Source/cmGlobalMinGWMakefileGenerator.cxx
new file mode 100644
index 0000000000..e00c7ddc81
--- /dev/null
+++ b/Source/cmGlobalMinGWMakefileGenerator.cxx
@@ -0,0 +1,52 @@
+/*============================================================================
+ 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 "cmGlobalMinGWMakefileGenerator.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+
+cmGlobalMinGWMakefileGenerator::cmGlobalMinGWMakefileGenerator()
+{
+ this->FindMakeProgramFile = "CMakeMinGWFindMake.cmake";
+ this->ForceUnixPaths = true;
+ this->ToolSupportsColor = true;
+ this->UseLinkScript = true;
+}
+
+void cmGlobalMinGWMakefileGenerator
+::EnableLanguage(std::vector<std::string>const& l,
+ cmMakefile *mf,
+ bool optional)
+{
+ this->EnableMinGWLanguage(mf);
+ this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalMinGWMakefileGenerator::CreateLocalGenerator()
+{
+ cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
+ lg->SetWindowsShell(true);
+ lg->SetGlobalGenerator(this);
+ lg->SetIgnoreLibPrefix(true);
+ lg->SetPassMakeflags(false);
+ lg->SetUnixCD(true);
+ lg->SetMinGWMake(true);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalMinGWMakefileGenerator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalMinGWMakefileGenerator::GetActualName();
+ entry.Brief = "Generates a make file for use with mingw32-make.";
+}
diff --git a/Source/cmGlobalMinGWMakefileGenerator.h b/Source/cmGlobalMinGWMakefileGenerator.h
new file mode 100644
index 0000000000..fa8d9f24ed
--- /dev/null
+++ b/Source/cmGlobalMinGWMakefileGenerator.h
@@ -0,0 +1,48 @@
+/*============================================================================
+ 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 cmGlobalMinGWMakefileGenerator_h
+#define cmGlobalMinGWMakefileGenerator_h
+
+#include "cmGlobalUnixMakefileGenerator3.h"
+
+/** \class cmGlobalMinGWMakefileGenerator
+ * \brief Write a NMake makefiles.
+ *
+ * cmGlobalMinGWMakefileGenerator manages nmake build process for a tree
+ */
+class cmGlobalMinGWMakefileGenerator : public cmGlobalUnixMakefileGenerator3
+{
+public:
+ cmGlobalMinGWMakefileGenerator();
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalMinGWMakefileGenerator>(); }
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalMinGWMakefileGenerator::GetActualName();}
+ static std::string GetActualName() {return "MinGW Makefiles";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+};
+
+#endif
diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx
new file mode 100644
index 0000000000..4fbabe4059
--- /dev/null
+++ b/Source/cmGlobalNMakeMakefileGenerator.cxx
@@ -0,0 +1,68 @@
+/*============================================================================
+ 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 "cmGlobalNMakeMakefileGenerator.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+
+cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator()
+{
+ this->FindMakeProgramFile = "CMakeNMakeFindMake.cmake";
+ this->ForceUnixPaths = false;
+ this->ToolSupportsColor = true;
+ this->UseLinkScript = false;
+}
+
+void cmGlobalNMakeMakefileGenerator
+::EnableLanguage(std::vector<std::string>const& l,
+ cmMakefile *mf,
+ bool optional)
+{
+ // pick a default
+ mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
+ mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
+ if(!(cmSystemTools::GetEnv("INCLUDE") &&
+ cmSystemTools::GetEnv("LIB"))
+ )
+ {
+ std::string message = "To use the NMake generator, cmake must be run "
+ "from a shell that can use the compiler cl from the command line. "
+ "This environment does not contain INCLUDE, LIB, or LIBPATH, and "
+ "these must be set for the cl compiler to work. ";
+ mf->IssueMessage(cmake::WARNING,
+ message);
+ }
+
+ this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalNMakeMakefileGenerator::CreateLocalGenerator()
+{
+ cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
+ lg->SetDefineWindowsNULL(true);
+ lg->SetWindowsShell(true);
+ lg->SetMakeSilentFlag("/nologo");
+ lg->SetGlobalGenerator(this);
+ lg->SetIgnoreLibPrefix(true);
+ lg->SetPassMakeflags(true);
+ lg->SetNMake(true);
+ lg->SetUnixCD(false);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalNMakeMakefileGenerator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalNMakeMakefileGenerator::GetActualName();
+ entry.Brief = "Generates NMake makefiles.";
+}
diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h
new file mode 100644
index 0000000000..e7b03ddb95
--- /dev/null
+++ b/Source/cmGlobalNMakeMakefileGenerator.h
@@ -0,0 +1,48 @@
+/*============================================================================
+ 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 cmGlobalNMakeMakefileGenerator_h
+#define cmGlobalNMakeMakefileGenerator_h
+
+#include "cmGlobalUnixMakefileGenerator3.h"
+
+/** \class cmGlobalNMakeMakefileGenerator
+ * \brief Write a NMake makefiles.
+ *
+ * cmGlobalNMakeMakefileGenerator manages nmake build process for a tree
+ */
+class cmGlobalNMakeMakefileGenerator : public cmGlobalUnixMakefileGenerator3
+{
+public:
+ cmGlobalNMakeMakefileGenerator();
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalNMakeMakefileGenerator>(); }
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalNMakeMakefileGenerator::GetActualName();}
+ static std::string GetActualName() {return "NMake Makefiles";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+};
+
+#endif
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
new file mode 100644
index 0000000000..6e7b06bfa4
--- /dev/null
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -0,0 +1,1232 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 "cmGeneratedFileStream.h"
+#include "cmGeneratorExpressionEvaluationFile.h"
+#include "cmGeneratorTarget.h"
+#include "cmGlobalNinjaGenerator.h"
+#include "cmLocalNinjaGenerator.h"
+#include "cmMakefile.h"
+#include "cmVersion.h"
+
+#include <algorithm>
+#include <assert.h>
+
+const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja";
+const char* cmGlobalNinjaGenerator::NINJA_RULES_FILE = "rules.ninja";
+const char* cmGlobalNinjaGenerator::INDENT = " ";
+
+void cmGlobalNinjaGenerator::Indent(std::ostream& os, int count)
+{
+ for(int i = 0; i < count; ++i)
+ os << cmGlobalNinjaGenerator::INDENT;
+}
+
+void cmGlobalNinjaGenerator::WriteDivider(std::ostream& os)
+{
+ os
+ << "# ======================================"
+ << "=======================================\n";
+}
+
+void cmGlobalNinjaGenerator::WriteComment(std::ostream& os,
+ const std::string& comment)
+{
+ if (comment.empty())
+ return;
+
+ std::string replace = comment;
+ std::string::size_type lpos = 0;
+ std::string::size_type rpos;
+ os << "\n#############################################\n";
+ while((rpos = replace.find('\n', lpos)) != std::string::npos)
+ {
+ os << "# " << replace.substr(lpos, rpos - lpos) << "\n";
+ lpos = rpos + 1;
+ }
+ os << "# " << replace.substr(lpos) << "\n\n";
+}
+
+static bool IsIdentChar(char c)
+{
+ return
+ ('a' <= c && c <= 'z') ||
+ ('+' <= c && c <= '9') || // +,-./ and numbers
+ ('A' <= c && c <= 'Z') ||
+ (c == '_') || (c == '$') || (c == '\\') ||
+ (c == ' ') || (c == ':');
+}
+
+std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string &ident,
+ std::ostream &vars) {
+ if (std::find_if(ident.begin(), ident.end(),
+ std::not1(std::ptr_fun(IsIdentChar))) != ident.end()) {
+ static unsigned VarNum = 0;
+ cmOStringStream names;
+ names << "ident" << VarNum++;
+ vars << names.str() << " = " << ident << "\n";
+ return "$" + names.str();
+ } else {
+ std::string result = ident;
+ cmSystemTools::ReplaceString(result, " ", "$ ");
+ cmSystemTools::ReplaceString(result, ":", "$:");
+ return result;
+ }
+}
+
+std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string &lit)
+{
+ std::string result = lit;
+ cmSystemTools::ReplaceString(result, "$", "$$");
+ cmSystemTools::ReplaceString(result, "\n", "$\n");
+ return result;
+}
+
+std::string cmGlobalNinjaGenerator::EncodePath(const std::string &path)
+{
+ std::string result = path;
+#ifdef _WIN32
+ if(UsingMinGW)
+ cmSystemTools::ReplaceString(result, "\\", "/");
+ else
+ cmSystemTools::ReplaceString(result, "/", "\\");
+#endif
+ return EncodeLiteral(result);
+}
+
+std::string cmGlobalNinjaGenerator::EncodeDepfileSpace(const std::string &path)
+{
+ std::string result = path;
+ cmSystemTools::ReplaceString(result, " ", "\\ ");
+ return result;
+}
+
+void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
+ const std::string& comment,
+ const std::string& rule,
+ const cmNinjaDeps& outputs,
+ const cmNinjaDeps& explicitDeps,
+ const cmNinjaDeps& implicitDeps,
+ const cmNinjaDeps& orderOnlyDeps,
+ const cmNinjaVars& variables,
+ const std::string& rspfile,
+ int cmdLineLimit)
+{
+ // Make sure there is a rule.
+ if(rule.empty())
+ {
+ cmSystemTools::Error("No rule for WriteBuildStatement! called "
+ "with comment: ",
+ comment.c_str());
+ return;
+ }
+
+ // Make sure there is at least one output file.
+ if(outputs.empty())
+ {
+ cmSystemTools::Error("No output files for WriteBuildStatement! called "
+ "with comment: ",
+ comment.c_str());
+ return;
+ }
+
+ cmGlobalNinjaGenerator::WriteComment(os, comment);
+
+ std::string arguments;
+
+ // TODO: Better formatting for when there are multiple input/output files.
+
+ // Write explicit dependencies.
+ for(cmNinjaDeps::const_iterator i = explicitDeps.begin();
+ i != explicitDeps.end();
+ ++i)
+ {
+ arguments += " " + EncodeIdent(EncodePath(*i), os);
+ }
+
+ // Write implicit dependencies.
+ if(!implicitDeps.empty())
+ {
+ arguments += " |";
+ for(cmNinjaDeps::const_iterator i = implicitDeps.begin();
+ i != implicitDeps.end();
+ ++i)
+ arguments += " " + EncodeIdent(EncodePath(*i), os);
+ }
+
+ // Write order-only dependencies.
+ if(!orderOnlyDeps.empty())
+ {
+ arguments += " ||";
+ for(cmNinjaDeps::const_iterator i = orderOnlyDeps.begin();
+ i != orderOnlyDeps.end();
+ ++i)
+ arguments += " " + EncodeIdent(EncodePath(*i), os);
+ }
+
+ arguments += "\n";
+
+ std::string build;
+
+ // Write outputs files.
+ build += "build";
+ for(cmNinjaDeps::const_iterator i = outputs.begin();
+ i != outputs.end(); ++i)
+ {
+ build += " " + EncodeIdent(EncodePath(*i), os);
+ this->CombinedBuildOutputs.insert( EncodePath(*i) );
+ }
+ build += ":";
+
+ // Write the rule.
+ build += " " + rule;
+
+ // Write the variables bound to this build statement.
+ cmOStringStream variable_assignments;
+ for(cmNinjaVars::const_iterator i = variables.begin();
+ i != variables.end(); ++i)
+ cmGlobalNinjaGenerator::WriteVariable(variable_assignments,
+ i->first, i->second, "", 1);
+
+ // check if a response file rule should be used
+ std::string buildstr = build;
+ std::string assignments = variable_assignments.str();
+ const std::string& args = arguments;
+ if (cmdLineLimit > 0
+ && args.size() + buildstr.size() + assignments.size()
+ > (size_t) cmdLineLimit) {
+ buildstr += "_RSP_FILE";
+ variable_assignments.str(std::string());
+ cmGlobalNinjaGenerator::WriteVariable(variable_assignments,
+ "RSP_FILE", rspfile, "", 1);
+ assignments += variable_assignments.str();
+ }
+
+ os << buildstr << args << assignments;
+}
+
+void cmGlobalNinjaGenerator::WritePhonyBuild(std::ostream& os,
+ const std::string& comment,
+ const cmNinjaDeps& outputs,
+ const cmNinjaDeps& explicitDeps,
+ const cmNinjaDeps& implicitDeps,
+ const cmNinjaDeps& orderOnlyDeps,
+ const cmNinjaVars& variables)
+{
+ this->WriteBuild(os,
+ comment,
+ "phony",
+ outputs,
+ explicitDeps,
+ implicitDeps,
+ orderOnlyDeps,
+ variables);
+}
+
+void cmGlobalNinjaGenerator::AddCustomCommandRule()
+{
+ this->AddRule("CUSTOM_COMMAND",
+ "$COMMAND",
+ "$DESC",
+ "Rule for running custom commands.",
+ /*depfile*/ "",
+ /*deptype*/ "",
+ /*rspfile*/ "",
+ /*rspcontent*/ "",
+ /*restat*/ true,
+ /*generator*/ false);
+}
+
+void
+cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command,
+ const std::string& description,
+ const std::string& comment,
+ const cmNinjaDeps& outputs,
+ const cmNinjaDeps& deps,
+ const cmNinjaDeps& orderOnly)
+{
+ std::string cmd = command;
+#ifdef _WIN32
+ if (cmd.empty())
+ // TODO Shouldn't an empty command be handled by ninja?
+ cmd = "cmd.exe /c";
+#endif
+
+ this->AddCustomCommandRule();
+
+ cmNinjaVars vars;
+ vars["COMMAND"] = cmd;
+ vars["DESC"] = EncodeLiteral(description);
+
+ this->WriteBuild(*this->BuildFileStream,
+ comment,
+ "CUSTOM_COMMAND",
+ outputs,
+ deps,
+ cmNinjaDeps(),
+ orderOnly,
+ vars);
+
+ //we need to track every dependency that comes in, since we are trying
+ //to find dependencies that are side effects of build commands
+ for(cmNinjaDeps::const_iterator i = deps.begin(); i != deps.end(); ++i)
+ {
+ this->CombinedCustomCommandExplicitDependencies.insert( EncodePath(*i) );
+ }
+}
+
+void
+cmGlobalNinjaGenerator::AddMacOSXContentRule()
+{
+ cmLocalGenerator *lg = this->LocalGenerators[0];
+ cmMakefile* mfRoot = lg->GetMakefile();
+
+ cmOStringStream cmd;
+ cmd << lg->ConvertToOutputFormat(
+ mfRoot->GetRequiredDefinition("CMAKE_COMMAND"),
+ cmLocalGenerator::SHELL)
+ << " -E copy $in $out";
+
+ this->AddRule("COPY_OSX_CONTENT",
+ cmd.str(),
+ "Copying OS X Content $out",
+ "Rule for copying OS X bundle content file.",
+ /*depfile*/ "",
+ /*deptype*/ "",
+ /*rspfile*/ "",
+ /*rspcontent*/ "",
+ /*restat*/ false,
+ /*generator*/ false);
+}
+
+void
+cmGlobalNinjaGenerator::WriteMacOSXContentBuild(const std::string& input,
+ const std::string& output)
+{
+ this->AddMacOSXContentRule();
+
+ cmNinjaDeps outputs;
+ outputs.push_back(output);
+ cmNinjaDeps deps;
+ deps.push_back(input);
+ cmNinjaVars vars;
+
+ this->WriteBuild(*this->BuildFileStream,
+ "",
+ "COPY_OSX_CONTENT",
+ outputs,
+ deps,
+ cmNinjaDeps(),
+ cmNinjaDeps(),
+ cmNinjaVars());
+}
+
+void cmGlobalNinjaGenerator::WriteRule(std::ostream& os,
+ const std::string& name,
+ const std::string& command,
+ const std::string& description,
+ const std::string& comment,
+ const std::string& depfile,
+ const std::string& deptype,
+ const std::string& rspfile,
+ const std::string& rspcontent,
+ bool restat,
+ bool generator)
+{
+ // Make sure the rule has a name.
+ if(name.empty())
+ {
+ cmSystemTools::Error("No name given for WriteRuleStatement! called "
+ "with comment: ",
+ comment.c_str());
+ return;
+ }
+
+ // Make sure a command is given.
+ if(command.empty())
+ {
+ cmSystemTools::Error("No command given for WriteRuleStatement! called "
+ "with comment: ",
+ comment.c_str());
+ return;
+ }
+
+ cmGlobalNinjaGenerator::WriteComment(os, comment);
+
+ // Write the rule.
+ os << "rule " << name << "\n";
+
+ // Write the depfile if any.
+ if(!depfile.empty())
+ {
+ cmGlobalNinjaGenerator::Indent(os, 1);
+ os << "depfile = " << depfile << "\n";
+ }
+
+ // Write the deptype if any.
+ if (!deptype.empty())
+ {
+ cmGlobalNinjaGenerator::Indent(os, 1);
+ os << "deps = " << deptype << "\n";
+ }
+
+ // Write the command.
+ cmGlobalNinjaGenerator::Indent(os, 1);
+ os << "command = " << command << "\n";
+
+ // Write the description if any.
+ if(!description.empty())
+ {
+ cmGlobalNinjaGenerator::Indent(os, 1);
+ os << "description = " << description << "\n";
+ }
+
+ if(!rspfile.empty())
+ {
+ if (rspcontent.empty())
+ {
+ cmSystemTools::Error("No rspfile_content given!", comment.c_str());
+ return;
+ }
+ cmGlobalNinjaGenerator::Indent(os, 1);
+ os << "rspfile = " << rspfile << "\n";
+ cmGlobalNinjaGenerator::Indent(os, 1);
+ os << "rspfile_content = " << rspcontent << "\n";
+ }
+
+ if(restat)
+ {
+ cmGlobalNinjaGenerator::Indent(os, 1);
+ os << "restat = 1\n";
+ }
+
+ if(generator)
+ {
+ cmGlobalNinjaGenerator::Indent(os, 1);
+ os << "generator = 1\n";
+ }
+
+ os << "\n";
+}
+
+void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os,
+ const std::string& name,
+ const std::string& value,
+ const std::string& comment,
+ int indent)
+{
+ // Make sure we have a name.
+ if(name.empty())
+ {
+ cmSystemTools::Error("No name given for WriteVariable! called "
+ "with comment: ",
+ comment.c_str());
+ return;
+ }
+
+ // Do not add a variable if the value is empty.
+ std::string val = cmSystemTools::TrimWhitespace(value);
+ if(val.empty())
+ {
+ return;
+ }
+
+ cmGlobalNinjaGenerator::WriteComment(os, comment);
+ cmGlobalNinjaGenerator::Indent(os, indent);
+ os << name << " = " << val << "\n";
+}
+
+void cmGlobalNinjaGenerator::WriteInclude(std::ostream& os,
+ const std::string& filename,
+ const std::string& comment)
+{
+ cmGlobalNinjaGenerator::WriteComment(os, comment);
+ os << "include " << filename << "\n";
+}
+
+void cmGlobalNinjaGenerator::WriteDefault(std::ostream& os,
+ const cmNinjaDeps& targets,
+ const std::string& comment)
+{
+ cmGlobalNinjaGenerator::WriteComment(os, comment);
+ os << "default";
+ for(cmNinjaDeps::const_iterator i = targets.begin(); i != targets.end(); ++i)
+ os << " " << *i;
+ os << "\n";
+}
+
+
+cmGlobalNinjaGenerator::cmGlobalNinjaGenerator()
+ : cmGlobalGenerator()
+ , BuildFileStream(0)
+ , RulesFileStream(0)
+ , CompileCommandsStream(0)
+ , Rules()
+ , AllDependencies()
+{
+ // // Ninja is not ported to non-Unix OS yet.
+ // this->ForceUnixPaths = true;
+ this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake";
+}
+
+
+//----------------------------------------------------------------------------
+// Virtual public methods.
+
+cmLocalGenerator* cmGlobalNinjaGenerator::CreateLocalGenerator()
+{
+ cmLocalGenerator* lg = new cmLocalNinjaGenerator;
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+void cmGlobalNinjaGenerator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalNinjaGenerator::GetActualName();
+ entry.Brief = "Generates build.ninja files (experimental).";
+}
+
+// Implemented in all cmGlobaleGenerator sub-classes.
+// Used in:
+// Source/cmLocalGenerator.cxx
+// Source/cmake.cxx
+void cmGlobalNinjaGenerator::Generate()
+{
+ this->OpenBuildFileStream();
+ this->OpenRulesFileStream();
+
+ this->cmGlobalGenerator::Generate();
+
+ this->WriteAssumedSourceDependencies();
+ this->WriteTargetAliases(*this->BuildFileStream);
+ this->WriteUnknownExplicitDependencies(*this->BuildFileStream);
+ this->WriteBuiltinTargets(*this->BuildFileStream);
+
+ if (cmSystemTools::GetErrorOccuredFlag()) {
+ this->RulesFileStream->setstate(std::ios_base::failbit);
+ this->BuildFileStream->setstate(std::ios_base::failbit);
+ }
+
+ this->CloseCompileCommandsStream();
+ this->CloseRulesFileStream();
+ this->CloseBuildFileStream();
+}
+
+// Implemented in all cmGlobaleGenerator sub-classes.
+// Used in:
+// Source/cmMakefile.cxx:
+void cmGlobalNinjaGenerator
+::EnableLanguage(std::vector<std::string>const& langs,
+ cmMakefile* makefile,
+ bool optional)
+{
+ if (makefile->IsOn("CMAKE_COMPILER_IS_MINGW"))
+ {
+ UsingMinGW = true;
+ this->EnableMinGWLanguage(makefile);
+ }
+ if (std::find(langs.begin(), langs.end(), "Fortran") != langs.end())
+ {
+ cmSystemTools::Error("The Ninja generator does not support Fortran yet.");
+ }
+ this->cmGlobalGenerator::EnableLanguage(langs, makefile, optional);
+ for(std::vector<std::string>::const_iterator l = langs.begin();
+ l != langs.end(); ++l)
+ {
+ if(*l == "NONE")
+ {
+ continue;
+ }
+ this->ResolveLanguageCompiler(*l, makefile, optional);
+ }
+}
+
+bool cmGlobalNinjaGenerator::UsingMinGW = false;
+
+// Implemented by:
+// cmGlobalUnixMakefileGenerator3
+// cmGlobalVisualStudio10Generator
+// cmGlobalVisualStudio6Generator
+// cmGlobalVisualStudio7Generator
+// cmGlobalXCodeGenerator
+// Called by:
+// cmGlobalGenerator::Build()
+void cmGlobalNinjaGenerator
+::GenerateBuildCommand(std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& /*projectName*/,
+ const std::string& /*projectDir*/,
+ const std::string& targetName,
+ const std::string& /*config*/,
+ bool /*fast*/,
+ std::vector<std::string> const& makeOptions)
+{
+ makeCommand.push_back(
+ this->SelectMakeProgram(makeProgram)
+ );
+
+ makeCommand.insert(makeCommand.end(),
+ makeOptions.begin(), makeOptions.end());
+ if(!targetName.empty())
+ {
+ if(targetName == "clean")
+ {
+ makeCommand.push_back("-t");
+ makeCommand.push_back("clean");
+ }
+ else
+ {
+ makeCommand.push_back(targetName);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+// Non-virtual public methods.
+
+void cmGlobalNinjaGenerator::AddRule(const std::string& name,
+ const std::string& command,
+ const std::string& description,
+ const std::string& comment,
+ const std::string& depfile,
+ const std::string& deptype,
+ const std::string& rspfile,
+ const std::string& rspcontent,
+ bool restat,
+ bool generator)
+{
+ // Do not add the same rule twice.
+ if (this->HasRule(name))
+ {
+ return;
+ }
+
+ this->Rules.insert(name);
+ cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream,
+ name,
+ command,
+ description,
+ comment,
+ depfile,
+ deptype,
+ rspfile,
+ rspcontent,
+ restat,
+ generator);
+
+ this->RuleCmdLength[name] = (int) command.size();
+}
+
+bool cmGlobalNinjaGenerator::HasRule(const std::string &name)
+{
+ RulesSetType::const_iterator rule = this->Rules.find(name);
+ return (rule != this->Rules.end());
+}
+
+//----------------------------------------------------------------------------
+// Private virtual overrides
+
+std::string cmGlobalNinjaGenerator::GetEditCacheCommand() const
+{
+ // Ninja by design does not run interactive tools in the terminal,
+ // so our only choice is cmake-gui.
+ return cmSystemTools::GetCMakeGUICommand();
+}
+
+//----------------------------------------------------------------------------
+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->GetCurrentOutputDirectory();
+ dir += "/";
+ dir += gt->LocalGenerator->GetTargetDirectory(*target);
+ dir += "/";
+ gt->ObjectDirectory = dir;
+}
+
+//----------------------------------------------------------------------------
+// Private methods
+
+void cmGlobalNinjaGenerator::OpenBuildFileStream()
+{
+ // Compute Ninja's build file path.
+ std::string buildFilePath =
+ this->GetCMakeInstance()->GetHomeOutputDirectory();
+ buildFilePath += "/";
+ buildFilePath += cmGlobalNinjaGenerator::NINJA_BUILD_FILE;
+
+ // Get a stream where to generate things.
+ if (!this->BuildFileStream)
+ {
+ this->BuildFileStream = new cmGeneratedFileStream(buildFilePath.c_str());
+ if (!this->BuildFileStream)
+ {
+ // An error message is generated by the constructor if it cannot
+ // open the file.
+ return;
+ }
+ }
+
+ // Write the do not edit header.
+ this->WriteDisclaimer(*this->BuildFileStream);
+
+ // Write a comment about this file.
+ *this->BuildFileStream
+ << "# This file contains all the build statements describing the\n"
+ << "# compilation DAG.\n\n"
+ ;
+}
+
+void cmGlobalNinjaGenerator::CloseBuildFileStream()
+{
+ if (this->BuildFileStream)
+ {
+ delete this->BuildFileStream;
+ this->BuildFileStream = 0;
+ }
+ else
+ {
+ cmSystemTools::Error("Build file stream was not open.");
+ }
+}
+
+void cmGlobalNinjaGenerator::OpenRulesFileStream()
+{
+ // Compute Ninja's build file path.
+ std::string rulesFilePath =
+ this->GetCMakeInstance()->GetHomeOutputDirectory();
+ rulesFilePath += "/";
+ rulesFilePath += cmGlobalNinjaGenerator::NINJA_RULES_FILE;
+
+ // Get a stream where to generate things.
+ if (!this->RulesFileStream)
+ {
+ this->RulesFileStream = new cmGeneratedFileStream(rulesFilePath.c_str());
+ if (!this->RulesFileStream)
+ {
+ // An error message is generated by the constructor if it cannot
+ // open the file.
+ return;
+ }
+ }
+
+ // Write the do not edit header.
+ this->WriteDisclaimer(*this->RulesFileStream);
+
+ // Write comment about this file.
+ *this->RulesFileStream
+ << "# This file contains all the rules used to get the outputs files\n"
+ << "# built from the input files.\n"
+ << "# It is included in the main '" << NINJA_BUILD_FILE << "'.\n\n"
+ ;
+}
+
+void cmGlobalNinjaGenerator::CloseRulesFileStream()
+{
+ if (this->RulesFileStream)
+ {
+ delete this->RulesFileStream;
+ this->RulesFileStream = 0;
+ }
+ else
+ {
+ cmSystemTools::Error("Rules file stream was not open.");
+ }
+}
+
+void cmGlobalNinjaGenerator::AddCXXCompileCommand(
+ const std::string &commandLine,
+ const std::string &sourceFile)
+{
+ // Compute Ninja's build file path.
+ std::string buildFileDir =
+ this->GetCMakeInstance()->GetHomeOutputDirectory();
+ if (!this->CompileCommandsStream)
+ {
+ std::string buildFilePath = buildFileDir + "/compile_commands.json";
+
+ // Get a stream where to generate things.
+ this->CompileCommandsStream =
+ new cmGeneratedFileStream(buildFilePath.c_str());
+ *this->CompileCommandsStream << "[";
+ } else {
+ *this->CompileCommandsStream << "," << std::endl;
+ }
+
+ std::string sourceFileName = sourceFile;
+ if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
+ {
+ sourceFileName = cmSystemTools::CollapseFullPath(
+ sourceFileName.c_str(),
+ this->GetCMakeInstance()->GetHomeOutputDirectory());
+ }
+
+
+ *this->CompileCommandsStream << "\n{\n"
+ << " \"directory\": \""
+ << cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n"
+ << " \"command\": \""
+ << cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n"
+ << " \"file\": \""
+ << cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n"
+ << "}";
+}
+
+void cmGlobalNinjaGenerator::CloseCompileCommandsStream()
+{
+ if (this->CompileCommandsStream)
+ {
+ *this->CompileCommandsStream << "\n]";
+ delete this->CompileCommandsStream;
+ this->CompileCommandsStream = 0;
+ }
+
+}
+
+void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os)
+{
+ os
+ << "# CMAKE generated file: DO NOT EDIT!\n"
+ << "# Generated by \"" << this->GetName() << "\""
+ << " Generator, CMake Version "
+ << cmVersion::GetMajorVersion() << "."
+ << cmVersion::GetMinorVersion() << "\n\n";
+}
+
+void cmGlobalNinjaGenerator::AddDependencyToAll(cmTarget* target)
+{
+ this->AppendTargetOutputs(target, this->AllDependencies);
+}
+
+void cmGlobalNinjaGenerator::AddDependencyToAll(const std::string& input)
+{
+ this->AllDependencies.push_back(input);
+}
+
+void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
+{
+ for (std::map<std::string, std::set<std::string> >::iterator
+ i = this->AssumedSourceDependencies.begin();
+ i != this->AssumedSourceDependencies.end(); ++i) {
+ cmNinjaDeps deps;
+ std::copy(i->second.begin(), i->second.end(), std::back_inserter(deps));
+ WriteCustomCommandBuild(/*command=*/"", /*description=*/"",
+ "Assume dependencies for generated source file.",
+ cmNinjaDeps(1, i->first), deps);
+ }
+}
+
+void
+cmGlobalNinjaGenerator
+::AppendTargetOutputs(cmTarget const* target, cmNinjaDeps& outputs)
+{
+ std::string configName =
+ target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ cmLocalNinjaGenerator *ng =
+ static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
+
+ // for frameworks, we want the real name, not smple name
+ // frameworks always appear versioned, and the build.ninja
+ // will always attempt to manage symbolic links instead
+ // of letting cmOSXBundleGenerator do it.
+ bool realname = target->IsFrameworkOnApple();
+
+ switch (target->GetType()) {
+ case cmTarget::EXECUTABLE:
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ outputs.push_back(ng->ConvertToNinjaPath(
+ target->GetFullPath(configName, false, realname).c_str()));
+ break;
+
+ case cmTarget::OBJECT_LIBRARY:
+ case cmTarget::UTILITY: {
+ std::string path = ng->ConvertToNinjaPath(
+ target->GetMakefile()->GetStartOutputDirectory());
+ if (path.empty() || path == ".")
+ outputs.push_back(target->GetName());
+ else {
+ path += "/";
+ path += target->GetName();
+ outputs.push_back(path);
+ }
+ break;
+ }
+
+ case cmTarget::GLOBAL_TARGET:
+ // Always use the target in HOME instead of an unused duplicate in a
+ // subdirectory.
+ outputs.push_back(target->GetName());
+ break;
+
+ default:
+ return;
+ }
+}
+
+void
+cmGlobalNinjaGenerator
+::AppendTargetDepends(cmTarget const* target, cmNinjaDeps& outputs)
+{
+ if (target->GetType() == cmTarget::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 {
+ cmTargetDependSet const& targetDeps =
+ this->GetTargetDirectDepends(*target);
+ for (cmTargetDependSet::const_iterator i = targetDeps.begin();
+ i != targetDeps.end(); ++i)
+ {
+ if ((*i)->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ this->AppendTargetOutputs(*i, outputs);
+ }
+ }
+}
+
+void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
+ cmTarget* target) {
+ cmNinjaDeps outputs;
+ this->AppendTargetOutputs(target, outputs);
+ // Mark the target's outputs as ambiguous to ensure that no other target uses
+ // the output as an alias.
+ for (cmNinjaDeps::iterator i = outputs.begin(); i != outputs.end(); ++i)
+ TargetAliases[*i] = 0;
+
+ // Insert the alias into the map. If the alias was already present in the
+ // map and referred to another target, mark it as ambiguous.
+ std::pair<TargetAliasMap::iterator, bool> newAlias =
+ TargetAliases.insert(std::make_pair(alias, target));
+ if (newAlias.second && newAlias.first->second != target)
+ newAlias.first->second = 0;
+}
+
+void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
+{
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os << "# Target aliases.\n\n";
+
+ for (TargetAliasMap::const_iterator i = TargetAliases.begin();
+ i != TargetAliases.end(); ++i) {
+ // Don't write ambiguous aliases.
+ if (!i->second)
+ continue;
+
+ cmNinjaDeps deps;
+ this->AppendTargetOutputs(i->second, deps);
+
+ this->WritePhonyBuild(os,
+ "",
+ cmNinjaDeps(1, i->first),
+ deps);
+ }
+}
+
+void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
+{
+ //now write out the unknown explicit dependencies.
+
+ //union the configured files, evaluations files and the CombinedBuildOutputs,
+ //and then difference with CombinedExplicitDependencies to find the explicit
+ //dependencies that we have no rule for
+
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os << "# Unknown Build Time Dependencies.\n"
+ << "# Tell Ninja that they may appear as side effects of build rules\n"
+ << "# otherwise ordered by order-only dependencies.\n\n";
+
+ //get the list of files that cmake itself has generated as a
+ //product of configuration.
+ cmLocalNinjaGenerator *ng =
+ static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
+
+ std::set<std::string> knownDependencies;
+ for (std::vector<cmLocalGenerator *>::const_iterator i =
+ this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i)
+ {
+ //get the vector of files created by this makefile and convert them
+ //to ninja paths, which are all relative in respect to the build directory
+ const std::vector<std::string>& files =
+ (*i)->GetMakefile()->GetOutputFiles();
+ typedef std::vector<std::string>::const_iterator vect_it;
+ for(vect_it j = files.begin(); j != files.end(); ++j)
+ {
+ knownDependencies.insert( ng->ConvertToNinjaPath( j->c_str() ) );
+ }
+ //get list files which are implicit dependencies as well and will be phony
+ //for rebuild manifest
+ std::vector<std::string> const& lf = (*i)->GetMakefile()->GetListFiles();
+ typedef std::vector<std::string>::const_iterator vect_it;
+ for(vect_it j = lf.begin(); j != lf.end(); ++j)
+ {
+ knownDependencies.insert( ng->ConvertToNinjaPath( j->c_str() ) );
+ }
+ }
+ knownDependencies.insert( "CMakeCache.txt" );
+
+ for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
+ li = this->EvaluationFiles.begin();
+ li != this->EvaluationFiles.end();
+ ++li)
+ {
+ //get all the files created by generator expressions and convert them
+ //to ninja paths
+ std::vector<std::string> files = (*li)->GetFiles();
+ typedef std::vector<std::string>::const_iterator vect_it;
+ for(vect_it j = files.begin(); j != files.end(); ++j)
+ {
+ knownDependencies.insert( ng->ConvertToNinjaPath( j->c_str() ) );
+ }
+ }
+
+ for(TargetAliasMap::const_iterator i= this->TargetAliases.begin();
+ i != this->TargetAliases.end();
+ ++i)
+ {
+ knownDependencies.insert( ng->ConvertToNinjaPath(i->first.c_str()) );
+ }
+
+ //remove all source files we know will exist.
+ typedef std::map<std::string, std::set<std::string> >::const_iterator map_it;
+ for(map_it i = this->AssumedSourceDependencies.begin();
+ i != this->AssumedSourceDependencies.end();
+ ++i)
+ {
+ knownDependencies.insert( ng->ConvertToNinjaPath(i->first.c_str()) );
+ }
+
+ //insert outputs from all WirteBuild commands
+ for(std::set<std::string>::iterator i = this->CombinedBuildOutputs.begin();
+ i != this->CombinedBuildOutputs.end(); ++i)
+ {
+ //these paths have already be encoded when added to CombinedBuildOutputs
+ knownDependencies.insert(*i);
+ }
+
+ //after we have combined the data into knownDependencies we have no need
+ //to keep this data around
+ this->CombinedBuildOutputs.clear();
+
+ //now we difference with CombinedCustomCommandExplicitDependencies to find
+ //the list of items we know nothing about.
+ //We have encoded all the paths in CombinedCustomCommandExplicitDependencies
+ //and knownDependencies so no matter if unix or windows paths they
+ //should all match now.
+
+ std::vector<std::string> unkownExplicitDepends;
+ this->CombinedCustomCommandExplicitDependencies.erase("all");
+
+ std::set_difference(this->CombinedCustomCommandExplicitDependencies.begin(),
+ this->CombinedCustomCommandExplicitDependencies.end(),
+ knownDependencies.begin(),
+ knownDependencies.end(),
+ std::back_inserter(unkownExplicitDepends));
+
+
+ std::string const rootBuildDirectory =
+ this->GetCMakeInstance()->GetHomeOutputDirectory();
+ for (std::vector<std::string>::const_iterator
+ i = unkownExplicitDepends.begin();
+ i != unkownExplicitDepends.end();
+ ++i)
+ {
+ //verify the file is in the build directory
+ std::string const absDepPath = cmSystemTools::CollapseFullPath(
+ i->c_str(), rootBuildDirectory.c_str());
+ bool const inBuildDir = cmSystemTools::IsSubDirectory(absDepPath.c_str(),
+ rootBuildDirectory.c_str());
+ if(inBuildDir)
+ {
+ cmNinjaDeps deps(1,*i);
+ this->WritePhonyBuild(os,
+ "",
+ deps,
+ deps);
+ }
+ }
+}
+
+void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os)
+{
+ // Write headers.
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os << "# Built-in targets\n\n";
+
+ this->WriteTargetAll(os);
+ this->WriteTargetRebuildManifest(os);
+ this->WriteTargetClean(os);
+ this->WriteTargetHelp(os);
+}
+
+void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os)
+{
+ cmNinjaDeps outputs;
+ outputs.push_back("all");
+
+ this->WritePhonyBuild(os,
+ "The main all target.",
+ outputs,
+ this->AllDependencies);
+
+ cmGlobalNinjaGenerator::WriteDefault(os,
+ outputs,
+ "Make the all target the default.");
+}
+
+void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
+{
+ cmLocalGenerator *lg = this->LocalGenerators[0];
+ cmMakefile* mfRoot = lg->GetMakefile();
+
+ cmOStringStream cmd;
+ cmd << lg->ConvertToOutputFormat(
+ mfRoot->GetRequiredDefinition("CMAKE_COMMAND"),
+ cmLocalGenerator::SHELL)
+ << " -H"
+ << lg->ConvertToOutputFormat(mfRoot->GetHomeDirectory(),
+ cmLocalGenerator::SHELL)
+ << " -B"
+ << lg->ConvertToOutputFormat(mfRoot->GetHomeOutputDirectory(),
+ cmLocalGenerator::SHELL);
+ WriteRule(*this->RulesFileStream,
+ "RERUN_CMAKE",
+ cmd.str(),
+ "Re-running CMake...",
+ "Rule for re-running cmake.",
+ /*depfile=*/ "",
+ /*deptype=*/ "",
+ /*rspfile=*/ "",
+ /*rspcontent*/ "",
+ /*restat=*/ false,
+ /*generator=*/ true);
+
+ cmLocalNinjaGenerator *ng = static_cast<cmLocalNinjaGenerator *>(lg);
+
+ cmNinjaDeps implicitDeps;
+ for(std::vector<cmLocalGenerator*>::const_iterator i =
+ this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i)
+ {
+ std::vector<std::string> const& lf = (*i)->GetMakefile()->GetListFiles();
+ for(std::vector<std::string>::const_iterator fi = lf.begin();
+ fi != lf.end(); ++fi)
+ {
+ implicitDeps.push_back(ng->ConvertToNinjaPath(fi->c_str()));
+ }
+ }
+ implicitDeps.push_back("CMakeCache.txt");
+
+ std::sort(implicitDeps.begin(), implicitDeps.end());
+ implicitDeps.erase(std::unique(implicitDeps.begin(), implicitDeps.end()),
+ implicitDeps.end());
+
+ cmNinjaVars variables;
+ // Use 'console' pool to get non buffered output of the CMake re-run call
+ // Available since Ninja 1.5
+ if(cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
+ ninjaVersion().c_str(),
+ "1.5") == false)
+ {
+ variables["pool"] = "console";
+ }
+
+ this->WriteBuild(os,
+ "Re-run CMake if any of its inputs changed.",
+ "RERUN_CMAKE",
+ /*outputs=*/ cmNinjaDeps(1, NINJA_BUILD_FILE),
+ /*explicitDeps=*/ cmNinjaDeps(),
+ implicitDeps,
+ /*orderOnlyDeps=*/ cmNinjaDeps(),
+ variables);
+
+ this->WritePhonyBuild(os,
+ "A missing CMake input file is not an error.",
+ implicitDeps,
+ cmNinjaDeps());
+}
+
+std::string cmGlobalNinjaGenerator::ninjaCmd() const
+{
+ cmLocalGenerator* lgen = this->LocalGenerators[0];
+ if (lgen) {
+ return lgen->ConvertToOutputFormat(
+ lgen->GetMakefile()->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"),
+ cmLocalGenerator::SHELL);
+ }
+ return "ninja";
+}
+
+std::string cmGlobalNinjaGenerator::ninjaVersion() const
+{
+ std::string version;
+ std::string command = ninjaCmd() + " --version";
+ cmSystemTools::RunSingleCommand(command.c_str(),
+ &version, 0, 0,
+ cmSystemTools::OUTPUT_NONE);
+
+ return version;
+}
+
+void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
+{
+ WriteRule(*this->RulesFileStream,
+ "CLEAN",
+ ninjaCmd() + " -t clean",
+ "Cleaning all built files...",
+ "Rule for cleaning all built files.",
+ /*depfile=*/ "",
+ /*deptype=*/ "",
+ /*rspfile=*/ "",
+ /*rspcontent*/ "",
+ /*restat=*/ false,
+ /*generator=*/ false);
+ WriteBuild(os,
+ "Clean all the built files.",
+ "CLEAN",
+ /*outputs=*/ cmNinjaDeps(1, "clean"),
+ /*explicitDeps=*/ cmNinjaDeps(),
+ /*implicitDeps=*/ cmNinjaDeps(),
+ /*orderOnlyDeps=*/ cmNinjaDeps(),
+ /*variables=*/ cmNinjaVars());
+}
+
+void cmGlobalNinjaGenerator::WriteTargetHelp(std::ostream& os)
+{
+ WriteRule(*this->RulesFileStream,
+ "HELP",
+ ninjaCmd() + " -t targets",
+ "All primary targets available:",
+ "Rule for printing all primary targets available.",
+ /*depfile=*/ "",
+ /*deptype=*/ "",
+ /*rspfile=*/ "",
+ /*rspcontent*/ "",
+ /*restat=*/ false,
+ /*generator=*/ false);
+ WriteBuild(os,
+ "Print all primary targets available.",
+ "HELP",
+ /*outputs=*/ cmNinjaDeps(1, "help"),
+ /*explicitDeps=*/ cmNinjaDeps(),
+ /*implicitDeps=*/ cmNinjaDeps(),
+ /*orderOnlyDeps=*/ cmNinjaDeps(),
+ /*variables=*/ cmNinjaVars());
+}
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
new file mode 100644
index 0000000000..f666ee3591
--- /dev/null
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -0,0 +1,386 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 cmGlobalNinjaGenerator_h
+# define cmGlobalNinjaGenerator_h
+
+# include "cmGlobalGenerator.h"
+# include "cmGlobalGeneratorFactory.h"
+# include "cmNinjaTypes.h"
+
+//#define NINJA_GEN_VERBOSE_FILES
+
+class cmLocalGenerator;
+class cmGeneratedFileStream;
+class cmGeneratorTarget;
+
+/**
+ * \class cmGlobalNinjaGenerator
+ * \brief Write a build.ninja file.
+ *
+ * The main differences between this generator and the UnixMakefile
+ * generator family are:
+ * - We don't care about VERBOSE variable or RULE_MESSAGES property since
+ * it is handle by Ninja's -v option.
+ * - We don't care about computing any progress status since Ninja manages
+ * it itself.
+ * - We don't care about generating a clean target since Ninja already have
+ * a clean tool.
+ * - We generate one build.ninja and one rules.ninja per project.
+ * - We try to minimize the number of generated rules: one per target and
+ * language.
+ * - We use Ninja special variable $in and $out to produce nice output.
+ * - We extensively use Ninja variable overloading system to minimize the
+ * number of generated rules.
+ */
+class cmGlobalNinjaGenerator : public cmGlobalGenerator
+{
+public:
+ /// The default name of Ninja's build file. Typically: build.ninja.
+ static const char* NINJA_BUILD_FILE;
+
+ /// The default name of Ninja's rules file. Typically: rules.ninja.
+ /// It is included in the main build.ninja file.
+ static const char* NINJA_RULES_FILE;
+
+ /// The indentation string used when generating Ninja's build file.
+ static const char* INDENT;
+
+ /// Write @a count times INDENT level to output stream @a os.
+ static void Indent(std::ostream& os, int count);
+
+ /// Write a divider in the given output stream @a os.
+ static void WriteDivider(std::ostream& os);
+
+ static std::string EncodeIdent(const std::string &ident, std::ostream &vars);
+ static std::string EncodeLiteral(const std::string &lit);
+ static std::string EncodePath(const std::string &path);
+ static std::string EncodeDepfileSpace(const std::string &path);
+
+ /**
+ * Write the given @a comment to the output stream @a os. It
+ * handles new line character properly.
+ */
+ static void WriteComment(std::ostream& os, const std::string& comment);
+
+ /**
+ * 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.
+ * @warning no escaping of any kind is done here.
+ */
+ void WriteBuild(std::ostream& os,
+ const std::string& comment,
+ const std::string& rule,
+ const cmNinjaDeps& outputs,
+ const cmNinjaDeps& explicitDeps,
+ const cmNinjaDeps& implicitDeps,
+ const cmNinjaDeps& orderOnlyDeps,
+ const cmNinjaVars& variables,
+ const std::string& rspfile = std::string(),
+ int cmdLineLimit = -1);
+
+ /**
+ * Helper to write a build statement with the special 'phony' rule.
+ */
+ void WritePhonyBuild(std::ostream& os,
+ const std::string& comment,
+ const cmNinjaDeps& outputs,
+ const cmNinjaDeps& explicitDeps,
+ const cmNinjaDeps& implicitDeps = cmNinjaDeps(),
+ const cmNinjaDeps& orderOnlyDeps = cmNinjaDeps(),
+ const cmNinjaVars& variables = cmNinjaVars());
+
+ void WriteCustomCommandBuild(const std::string& command,
+ const std::string& description,
+ const std::string& comment,
+ const cmNinjaDeps& outputs,
+ const cmNinjaDeps& deps = cmNinjaDeps(),
+ const cmNinjaDeps& orderOnly = cmNinjaDeps());
+ void WriteMacOSXContentBuild(const std::string& input,
+ const std::string& output);
+
+ /**
+ * Write a rule statement named @a name to @a os with the @a comment,
+ * the mandatory @a command, the @a depfile and the @a description.
+ * It also writes the variables bound to this rule statement.
+ * @warning no escaping of any kind is done here.
+ */
+ static void WriteRule(std::ostream& os,
+ const std::string& name,
+ const std::string& command,
+ const std::string& description,
+ const std::string& comment,
+ const std::string& depfile,
+ const std::string& deptype,
+ const std::string& rspfile,
+ const std::string& rspcontent,
+ bool restat,
+ bool generator);
+
+ /**
+ * Write a variable named @a name to @a os with value @a value and an
+ * optional @a comment. An @a indent level can be specified.
+ * @warning no escaping of any kind is done here.
+ */
+ static void WriteVariable(std::ostream& os,
+ const std::string& name,
+ const std::string& value,
+ const std::string& comment = "",
+ int indent = 0);
+
+ /**
+ * Write an include statement including @a filename with an optional
+ * @a comment to the @a os stream.
+ */
+ static void WriteInclude(std::ostream& os,
+ const std::string& filename,
+ const std::string& comment = "");
+
+ /**
+ * Write a default target statement specifying @a targets as
+ * the default targets.
+ */
+ static void WriteDefault(std::ostream& os,
+ const cmNinjaDeps& targets,
+ const std::string& comment = "");
+
+
+ static bool IsMinGW() { return UsingMinGW; }
+
+
+public:
+ /// Default constructor.
+ cmGlobalNinjaGenerator();
+
+ /// Convenience method for creating an instance of this class.
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaGenerator>(); }
+
+ /// Destructor.
+ virtual ~cmGlobalNinjaGenerator() { }
+
+ /// Overloaded methods. @see cmGlobalGenerator::CreateLocalGenerator()
+ virtual cmLocalGenerator* CreateLocalGenerator();
+
+ /// Overloaded methods. @see cmGlobalGenerator::GetName().
+ virtual std::string GetName() const {
+ return cmGlobalNinjaGenerator::GetActualName(); }
+
+ /// @return the name of this generator.
+ static std::string GetActualName() { return "Ninja"; }
+
+ /// Overloaded methods. @see cmGlobalGenerator::GetDocumentation()
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ /// Overloaded methods. @see cmGlobalGenerator::EnableLanguage()
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile* mf,
+ bool optional);
+
+ /// Overloaded methods. @see cmGlobalGenerator::GenerateBuildCommand()
+ virtual void GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& projectDir,
+ const std::string& targetName,
+ const std::string& config,
+ bool fast,
+ std::vector<std::string> const& makeOptions = std::vector<std::string>()
+ );
+
+ // Setup target names
+ virtual const char* GetAllTargetName() const { return "all"; }
+ virtual const char* GetInstallTargetName() const { return "install"; }
+ virtual const char* GetInstallLocalTargetName() const {
+ return "install/local";
+ }
+ virtual const char* GetInstallStripTargetName() const {
+ return "install/strip";
+ }
+ virtual const char* GetTestTargetName() const { return "test"; }
+ virtual const char* GetPackageTargetName() const { return "package"; }
+ virtual const char* GetPackageSourceTargetName() const {
+ return "package_source";
+ }
+ virtual const char* GetEditCacheTargetName() const {
+ return "edit_cache";
+ }
+ virtual const char* GetRebuildCacheTargetName() const {
+ return "rebuild_cache";
+ }
+ virtual const char* GetCleanTargetName() const { return "clean"; }
+
+
+ cmGeneratedFileStream* GetBuildFileStream() const {
+ return this->BuildFileStream; }
+
+ cmGeneratedFileStream* GetRulesFileStream() const {
+ return this->RulesFileStream; }
+
+ void AddCXXCompileCommand(const std::string &commandLine,
+ const std::string &sourceFile);
+
+ /**
+ * Add a rule to the generated build system.
+ * Call WriteRule() behind the scene but perform some check before like:
+ * - Do not add twice the same rule.
+ */
+ void AddRule(const std::string& name,
+ const std::string& command,
+ const std::string& description,
+ const std::string& comment,
+ const std::string& depfile,
+ const std::string& deptype,
+ const std::string& rspfile,
+ const std::string& rspcontent,
+ bool restat,
+ bool generator);
+
+ bool HasRule(const std::string& name);
+
+ void AddCustomCommandRule();
+ void AddMacOSXContentRule();
+
+ bool HasCustomCommandOutput(const std::string &output) {
+ return this->CustomCommandOutputs.find(output) !=
+ this->CustomCommandOutputs.end();
+ }
+
+ /// Called when we have seen the given custom command. Returns true
+ /// if we has seen it before.
+ bool SeenCustomCommand(cmCustomCommand const *cc) {
+ return !this->CustomCommands.insert(cc).second;
+ }
+
+ /// Called when we have seen the given custom command output.
+ void SeenCustomCommandOutput(const std::string &output) {
+ this->CustomCommandOutputs.insert(output);
+ // We don't need the assumed dependencies anymore, because we have
+ // an output.
+ this->AssumedSourceDependencies.erase(output);
+ }
+
+ void AddAssumedSourceDependencies(const std::string &source,
+ const cmNinjaDeps &deps) {
+ std::set<std::string> &ASD = this->AssumedSourceDependencies[source];
+ // Because we may see the same source file multiple times (same source
+ // specified in multiple targets), compute the union of any assumed
+ // dependencies.
+ 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 AddDependencyToAll(const std::string& input);
+
+ const std::vector<cmLocalGenerator*>& GetLocalGenerators() const {
+ return LocalGenerators; }
+
+ bool IsExcluded(cmLocalGenerator* root, cmTarget& target) {
+ return cmGlobalGenerator::IsExcluded(root, target); }
+
+ int GetRuleCmdLength(const std::string& name) {
+ return RuleCmdLength[name]; }
+
+ void AddTargetAlias(const std::string& alias, cmTarget* target);
+
+ virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
+
+ std::string ninjaVersion() const;
+protected:
+
+ /// Overloaded methods. @see cmGlobalGenerator::Generate()
+ virtual void Generate();
+
+ /// Overloaded methods.
+ /// @see cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS()
+ virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const { return true; }
+
+
+private:
+ virtual std::string GetEditCacheCommand() const;
+
+
+ void OpenBuildFileStream();
+ void CloseBuildFileStream();
+
+ void CloseCompileCommandsStream();
+
+ void OpenRulesFileStream();
+ void CloseRulesFileStream();
+
+ /// Write the common disclaimer text at the top of each build file.
+ void WriteDisclaimer(std::ostream& os);
+
+ void WriteAssumedSourceDependencies();
+
+ void WriteTargetAliases(std::ostream& os);
+ void WriteUnknownExplicitDependencies(std::ostream& os);
+
+ void WriteBuiltinTargets(std::ostream& os);
+ void WriteTargetAll(std::ostream& os);
+ void WriteTargetRebuildManifest(std::ostream& os);
+ void WriteTargetClean(std::ostream& os);
+ void WriteTargetHelp(std::ostream& os);
+
+ std::string ninjaCmd() const;
+
+ /// The file containing the build statement. (the relationship of the
+ /// compilation DAG).
+ cmGeneratedFileStream* BuildFileStream;
+ /// The file containing the rule statements. (The action attached to each
+ /// edge of the compilation DAG).
+ cmGeneratedFileStream* RulesFileStream;
+ cmGeneratedFileStream* CompileCommandsStream;
+
+ /// The type used to store the set of rules added to the generated build
+ /// system.
+ typedef std::set<std::string> RulesSetType;
+
+ /// The set of rules added to the generated build system.
+ RulesSetType Rules;
+
+ /// Length of rule command, used by rsp file evaluation
+ std::map<std::string, int> RuleCmdLength;
+
+ /// The set of dependencies to add to the "all" target.
+ cmNinjaDeps AllDependencies;
+
+ /// The set of custom commands we have seen.
+ std::set<cmCustomCommand const*> CustomCommands;
+
+ /// The set of custom command outputs we have seen.
+ std::set<std::string> CustomCommandOutputs;
+
+ /// The combined explicit dependencies of custom build commands
+ std::set<std::string> CombinedCustomCommandExplicitDependencies;
+
+ /// When combined with CombinedCustomCommandExplicitDependencies it allows
+ /// us to detect the set of explicit dependencies that have
+ std::set<std::string> CombinedBuildOutputs;
+
+ /// The mapping from source file to assumed dependencies.
+ std::map<std::string, std::set<std::string> > AssumedSourceDependencies;
+
+ typedef std::map<std::string, cmTarget*> TargetAliasMap;
+ TargetAliasMap TargetAliases;
+
+ static cmLocalGenerator* LocalGenerator;
+
+ static bool UsingMinGW;
+
+};
+
+#endif // ! cmGlobalNinjaGenerator_h
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx
new file mode 100644
index 0000000000..3478534f71
--- /dev/null
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -0,0 +1,1098 @@
+/*============================================================================
+ 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 "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefileTargetGenerator.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include "cmGeneratedFileStream.h"
+#include "cmSourceFile.h"
+#include "cmTarget.h"
+#include "cmGeneratorTarget.h"
+
+cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3()
+{
+ // This type of makefile always requires unix style paths
+ this->ForceUnixPaths = true;
+ this->FindMakeProgramFile = "CMakeUnixFindMake.cmake";
+ this->ToolSupportsColor = true;
+
+#if defined(_WIN32) || defined(__VMS)
+ this->UseLinkScript = false;
+#else
+ this->UseLinkScript = true;
+#endif
+ this->CommandDatabase = NULL;
+}
+
+void cmGlobalUnixMakefileGenerator3
+::EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *mf,
+ bool optional)
+{
+ this->cmGlobalGenerator::EnableLanguage(languages, mf, optional);
+ for(std::vector<std::string>::const_iterator l = languages.begin();
+ l != languages.end(); ++l)
+ {
+ if(*l == "NONE")
+ {
+ continue;
+ }
+ this->ResolveLanguageCompiler(*l, mf, optional);
+ }
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalUnixMakefileGenerator3::CreateLocalGenerator()
+{
+ cmLocalGenerator* lg = new cmLocalUnixMakefileGenerator3;
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalUnixMakefileGenerator3
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalUnixMakefileGenerator3::GetActualName();
+ entry.Brief = "Generates standard UNIX makefiles.";
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalUnixMakefileGenerator3::GetEditCacheCommand() const
+{
+ // If generating for an extra IDE, the edit_cache target cannot
+ // launch a terminal-interactive tool, so always use cmake-gui.
+ if(!this->GetExtraGeneratorName().empty())
+ {
+ return cmSystemTools::GetCMakeGUICommand();
+ }
+
+ // Use an internal cache entry to track the latest dialog used
+ // to edit the cache, and use that for the edit_cache target.
+ cmake* cm = this->GetCMakeInstance();
+ std::string editCacheCommand = cm->GetCMakeEditCommand();
+ if(!cm->GetCacheDefinition("CMAKE_EDIT_COMMAND") ||
+ !editCacheCommand.empty())
+ {
+ if(editCacheCommand.empty())
+ {
+ editCacheCommand = cmSystemTools::GetCMakeCursesCommand();
+ }
+ if(editCacheCommand.empty())
+ {
+ editCacheCommand = cmSystemTools::GetCMakeGUICommand();
+ }
+ if(!editCacheCommand.empty())
+ {
+ cm->AddCacheEntry
+ ("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(),
+ "Path to cache edit program executable.", cmCacheManager::INTERNAL);
+ }
+ }
+ const char* edit_cmd = cm->GetCacheDefinition("CMAKE_EDIT_COMMAND");
+ return edit_cmd? edit_cmd : "";
+}
+
+//----------------------------------------------------------------------------
+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->GetCurrentOutputDirectory();
+ dir += "/";
+ dir += gt->LocalGenerator->GetTargetDirectory(*target);
+ dir += "/";
+ gt->ObjectDirectory = dir;
+}
+
+void cmGlobalUnixMakefileGenerator3::Configure()
+{
+ // Initialize CMAKE_EDIT_COMMAND cache entry.
+ this->GetEditCacheCommand();
+
+ this->cmGlobalGenerator::Configure();
+}
+
+void cmGlobalUnixMakefileGenerator3::Generate()
+{
+ // first do superclass method
+ this->cmGlobalGenerator::Generate();
+
+ // initialize progress
+ unsigned long total = 0;
+ for(ProgressMapType::const_iterator pmi = this->ProgressMap.begin();
+ pmi != this->ProgressMap.end(); ++pmi)
+ {
+ total += pmi->second.NumberOfActions;
+ }
+
+ // write each target's progress.make this loop is done twice. Bascially the
+ // Generate pass counts all the actions, the first loop below determines
+ // how many actions have progress updates for each target and writes to
+ // corrrect variable values for everything except the all targets. The
+ // second loop actually writes out correct values for the all targets as
+ // well. This is because the all targets require more information that is
+ // computed in the first loop.
+ unsigned long current = 0;
+ for(ProgressMapType::iterator pmi = this->ProgressMap.begin();
+ pmi != this->ProgressMap.end(); ++pmi)
+ {
+ pmi->second.WriteProgressVariables(total, current);
+ }
+ for(unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ cmLocalUnixMakefileGenerator3 *lg =
+ static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
+ std::string markFileName = lg->GetMakefile()->GetStartOutputDirectory();
+ markFileName += "/";
+ markFileName += cmake::GetCMakeFilesDirectory();
+ markFileName += "/progress.marks";
+ cmGeneratedFileStream markFile(markFileName.c_str());
+ markFile << this->CountProgressMarksInAll(lg) << "\n";
+ }
+
+ // write the main makefile
+ this->WriteMainMakefile2();
+ this->WriteMainCMakefile();
+
+ if (this->CommandDatabase != NULL) {
+ *this->CommandDatabase << std::endl << "]";
+ delete this->CommandDatabase;
+ this->CommandDatabase = NULL;
+ }
+}
+
+void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand(
+ const std::string &sourceFile, const std::string &workingDirectory,
+ const std::string &compileCommand) {
+ if (this->CommandDatabase == NULL)
+ {
+ std::string commandDatabaseName =
+ std::string(this->GetCMakeInstance()->GetHomeOutputDirectory())
+ + "/compile_commands.json";
+ this->CommandDatabase =
+ new cmGeneratedFileStream(commandDatabaseName.c_str());
+ *this->CommandDatabase << "[" << std::endl;
+ } else {
+ *this->CommandDatabase << "," << std::endl;
+ }
+ *this->CommandDatabase << "{" << std::endl
+ << " \"directory\": \""
+ << cmGlobalGenerator::EscapeJSON(workingDirectory) << "\","
+ << std::endl
+ << " \"command\": \"" <<
+ cmGlobalGenerator::EscapeJSON(compileCommand) << "\","
+ << std::endl
+ << " \"file\": \"" <<
+ cmGlobalGenerator::EscapeJSON(sourceFile) << "\""
+ << std::endl << "}";
+}
+
+void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
+{
+ // Open the output file. This should not be copy-if-different
+ // because the check-build-system step compares the makefile time to
+ // see if the build system must be regenerated.
+ std::string makefileName =
+ this->GetCMakeInstance()->GetHomeOutputDirectory();
+ makefileName += cmake::GetCMakeFilesDirectory();
+ makefileName += "/Makefile2";
+ cmGeneratedFileStream makefileStream(makefileName.c_str());
+ if(!makefileStream)
+ {
+ return;
+ }
+
+ // get a local generator for some useful methods
+ cmLocalUnixMakefileGenerator3 *lg =
+ static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[0]);
+
+ // Write the do not edit header.
+ lg->WriteDisclaimer(makefileStream);
+
+ // Write the main entry point target. This must be the VERY first
+ // target so that make with no arguments will run it.
+ // Just depend on the all target to drive the build.
+ std::vector<std::string> depends;
+ std::vector<std::string> no_commands;
+ depends.push_back("all");
+
+ // Write the rule.
+ lg->WriteMakeRule(makefileStream,
+ "Default target executed when no arguments are "
+ "given to make.",
+ "default_target",
+ depends,
+ no_commands, true);
+
+ depends.clear();
+
+ // The all and preinstall rules might never have any dependencies
+ // added to them.
+ if(this->EmptyRuleHackDepends != "")
+ {
+ depends.push_back(this->EmptyRuleHackDepends);
+ }
+
+ // Write and empty all:
+ lg->WriteMakeRule(makefileStream,
+ "The main recursive all target", "all",
+ depends, no_commands, true);
+
+ // Write an empty preinstall:
+ lg->WriteMakeRule(makefileStream,
+ "The main recursive preinstall target", "preinstall",
+ depends, no_commands, true);
+
+ // Write out the "special" stuff
+ lg->WriteSpecialTargetsTop(makefileStream);
+
+ // write the target convenience rules
+ unsigned int i;
+ for (i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ lg =
+ static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
+ this->WriteConvenienceRules2(makefileStream,lg);
+ }
+
+ lg = static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[0]);
+ lg->WriteSpecialTargetsBottom(makefileStream);
+}
+
+
+//----------------------------------------------------------------------------
+void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
+{
+ // Open the output file. This should not be copy-if-different
+ // because the check-build-system step compares the makefile time to
+ // see if the build system must be regenerated.
+ std::string cmakefileName =
+ this->GetCMakeInstance()->GetHomeOutputDirectory();
+ cmakefileName += cmake::GetCMakeFilesDirectory();
+ cmakefileName += "/Makefile.cmake";
+ cmGeneratedFileStream cmakefileStream(cmakefileName.c_str());
+ if(!cmakefileStream)
+ {
+ return;
+ }
+
+ std::string makefileName =
+ this->GetCMakeInstance()->GetHomeOutputDirectory();
+ makefileName += "/Makefile";
+
+ // get a local generator for some useful methods
+ cmLocalUnixMakefileGenerator3 *lg =
+ static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[0]);
+
+ // Write the do not edit header.
+ lg->WriteDisclaimer(cmakefileStream);
+
+ // Save the generator name
+ cmakefileStream
+ << "# The generator used is:\n"
+ << "set(CMAKE_DEPENDS_GENERATOR \"" << this->GetName() << "\")\n\n";
+
+ // for each cmMakefile get its list of dependencies
+ std::vector<std::string> lfiles;
+ for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ lg =
+ static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
+
+ // Get the list of files contributing to this generation step.
+ lfiles.insert(lfiles.end(),lg->GetMakefile()->GetListFiles().begin(),
+ lg->GetMakefile()->GetListFiles().end());
+ }
+ // Sort the list and remove duplicates.
+ std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
+#if !defined(__VMS) // The Compaq STL on VMS crashes, so accept duplicates.
+ std::vector<std::string>::iterator new_end =
+ std::unique(lfiles.begin(),lfiles.end());
+ lfiles.erase(new_end, lfiles.end());
+#endif
+
+ // reset lg to the first makefile
+ lg = static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[0]);
+
+ // Build the path to the cache file.
+ std::string cache = this->GetCMakeInstance()->GetHomeOutputDirectory();
+ cache += "/CMakeCache.txt";
+
+ // Save the list to the cmake file.
+ cmakefileStream
+ << "# The top level Makefile was generated from the following files:\n"
+ << "set(CMAKE_MAKEFILE_DEPENDS\n"
+ << " \""
+ << lg->Convert(cache,
+ cmLocalGenerator::START_OUTPUT) << "\"\n";
+ for(std::vector<std::string>::const_iterator i = lfiles.begin();
+ i != lfiles.end(); ++i)
+ {
+ cmakefileStream
+ << " \""
+ << lg->Convert(*i, cmLocalGenerator::START_OUTPUT)
+ << "\"\n";
+ }
+ cmakefileStream
+ << " )\n\n";
+
+ // Build the path to the cache check file.
+ std::string check = this->GetCMakeInstance()->GetHomeOutputDirectory();
+ check += cmake::GetCMakeFilesDirectory();
+ check += "/cmake.check_cache";
+
+ // Set the corresponding makefile in the cmake file.
+ cmakefileStream
+ << "# The corresponding makefile is:\n"
+ << "set(CMAKE_MAKEFILE_OUTPUTS\n"
+ << " \""
+ << lg->Convert(makefileName,
+ cmLocalGenerator::START_OUTPUT) << "\"\n"
+ << " \""
+ << lg->Convert(check,
+ cmLocalGenerator::START_OUTPUT) << "\"\n";
+ cmakefileStream << " )\n\n";
+
+ // CMake must rerun if a byproduct is missing.
+ {
+ cmakefileStream
+ << "# Byproducts of CMake generate step:\n"
+ << "set(CMAKE_MAKEFILE_PRODUCTS\n";
+ const std::vector<std::string>& outfiles =
+ lg->GetMakefile()->GetOutputFiles();
+ for(std::vector<std::string>::const_iterator k = outfiles.begin();
+ k != outfiles.end(); ++k)
+ {
+ cmakefileStream << " \"" <<
+ lg->Convert(*k,cmLocalGenerator::HOME_OUTPUT)
+ << "\"\n";
+ }
+
+ // add in all the directory information files
+ std::string tmpStr;
+ for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ lg =
+ static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
+ tmpStr = lg->GetMakefile()->GetStartOutputDirectory();
+ tmpStr += cmake::GetCMakeFilesDirectory();
+ tmpStr += "/CMakeDirectoryInformation.cmake";
+ cmakefileStream << " \"" <<
+ lg->Convert(tmpStr,cmLocalGenerator::HOME_OUTPUT)
+ << "\"\n";
+ }
+ cmakefileStream << " )\n\n";
+ }
+
+ this->WriteMainCMakefileLanguageRules(cmakefileStream,
+ this->LocalGenerators);
+}
+
+void cmGlobalUnixMakefileGenerator3
+::WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
+ std::vector<cmLocalGenerator *> &lGenerators
+ )
+{
+ cmLocalUnixMakefileGenerator3 *lg;
+
+ // now list all the target info files
+ cmakefileStream
+ << "# Dependency information for all targets:\n";
+ cmakefileStream
+ << "set(CMAKE_DEPEND_INFO_FILES\n";
+ for (unsigned int i = 0; i < lGenerators.size(); ++i)
+ {
+ 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++)
+ {
+ 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))
+ {
+ std::string tname = lg->GetRelativeTargetDirectory(l->second);
+ tname += "/DependInfo.cmake";
+ cmSystemTools::ConvertToUnixSlashes(tname);
+ cmakefileStream << " \"" << tname << "\"\n";
+ }
+ }
+ }
+ cmakefileStream << " )\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalUnixMakefileGenerator3
+::WriteDirectoryRule2(std::ostream& ruleFileStream,
+ cmLocalUnixMakefileGenerator3* lg,
+ const char* pass, bool check_all,
+ bool check_relink)
+{
+ // Get the relative path to the subdirectory from the top.
+ std::string makeTarget = lg->GetMakefile()->GetStartOutputDirectory();
+ 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();
+ l != targets.end(); ++l)
+ {
+ cmGeneratorTarget* gtarget = l->second;
+ 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(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->Target
+ ->NeedRelinkBeforeInstall(lg->ConfigurationName)))
+ {
+ std::string tname = lg->GetRelativeTargetDirectory(*gtarget->Target);
+ tname += "/";
+ tname += pass;
+ depends.push_back(tname);
+ }
+ }
+ }
+
+ // The directory-level rule should depend on the directory-level
+ // rules of the subdirectories.
+ for(std::vector<cmLocalGenerator*>::iterator sdi =
+ lg->GetChildren().begin(); sdi != lg->GetChildren().end(); ++sdi)
+ {
+ cmLocalUnixMakefileGenerator3* slg =
+ static_cast<cmLocalUnixMakefileGenerator3*>(*sdi);
+ std::string subdir = slg->GetMakefile()->GetStartOutputDirectory();
+ subdir += "/";
+ subdir += pass;
+ depends.push_back(subdir);
+ }
+
+ // Work-around for makes that drop rules that have no dependencies
+ // or commands.
+ if(depends.empty() && this->EmptyRuleHackDepends != "")
+ {
+ depends.push_back(this->EmptyRuleHackDepends);
+ }
+
+ // Write the rule.
+ std::string doc = "Convenience name for \"";
+ doc += pass;
+ doc += "\" pass in the directory.";
+ std::vector<std::string> no_commands;
+ lg->WriteMakeRule(ruleFileStream, doc.c_str(),
+ makeTarget, depends, no_commands, true);
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalUnixMakefileGenerator3
+::WriteDirectoryRules2(std::ostream& ruleFileStream,
+ cmLocalUnixMakefileGenerator3* lg)
+{
+ // Only subdirectories need these rules.
+ if(!lg->GetParent())
+ {
+ return;
+ }
+
+ // Begin the directory-level rules section.
+ std::string dir = lg->GetMakefile()->GetStartOutputDirectory();
+ dir = lg->Convert(dir, cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE);
+ lg->WriteDivider(ruleFileStream);
+ ruleFileStream
+ << "# Directory level rules for directory "
+ << dir << "\n\n";
+
+ // Write directory-level rules for "all".
+ this->WriteDirectoryRule2(ruleFileStream, lg, "all", true, false);
+
+ // Write directory-level rules for "clean".
+ this->WriteDirectoryRule2(ruleFileStream, lg, "clean", false, false);
+
+ // Write directory-level rules for "preinstall".
+ this->WriteDirectoryRule2(ruleFileStream, lg, "preinstall", true, true);
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalUnixMakefileGenerator3
+::GenerateBuildCommand(std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& /*projectName*/,
+ const std::string& /*projectDir*/,
+ const std::string& targetName,
+ const std::string& /*config*/,
+ bool fast,
+ std::vector<std::string> const& makeOptions)
+{
+ makeCommand.push_back(
+ this->SelectMakeProgram(makeProgram)
+ );
+
+ // Since we have full control over the invocation of nmake, let us
+ // make it quiet.
+ if ( this->GetName() == "NMake Makefiles" )
+ {
+ makeCommand.push_back("/NOLOGO");
+ }
+ makeCommand.insert(makeCommand.end(),
+ makeOptions.begin(), makeOptions.end());
+ if (!targetName.empty())
+ {
+ cmLocalUnixMakefileGenerator3 *lg;
+ if (this->LocalGenerators.size())
+ {
+ lg = static_cast<cmLocalUnixMakefileGenerator3 *>
+ (this->LocalGenerators[0]);
+ }
+ else
+ {
+ lg = static_cast<cmLocalUnixMakefileGenerator3 *>
+ (this->CreateLocalGenerator());
+ // set the Start directories
+ lg->GetMakefile()->SetStartDirectory
+ (this->CMakeInstance->GetStartDirectory());
+ lg->GetMakefile()->SetStartOutputDirectory
+ (this->CMakeInstance->GetStartOutputDirectory());
+ lg->GetMakefile()->MakeStartDirectoriesCurrent();
+ }
+
+ std::string tname = targetName;
+ if(fast)
+ {
+ tname += "/fast";
+ }
+ tname = lg->Convert(tname,cmLocalGenerator::HOME_OUTPUT);
+ cmSystemTools::ConvertToOutputSlashes(tname);
+ makeCommand.push_back(tname);
+ if (!this->LocalGenerators.size())
+ {
+ delete lg;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalUnixMakefileGenerator3
+::WriteConvenienceRules(std::ostream& ruleFileStream,
+ std::set<std::string> &emitted)
+{
+ std::vector<std::string> depends;
+ std::vector<std::string> commands;
+
+ depends.push_back("cmake_check_build_system");
+
+ // write the target convenience rules
+ unsigned int i;
+ cmLocalUnixMakefileGenerator3 *lg;
+ for (i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ 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();
+ t != targets.end(); ++t)
+ {
+ cmGeneratorTarget* gtarget = t->second;
+ if(gtarget->Target->IsImported())
+ {
+ continue;
+ }
+ // Don't emit the same rule twice (e.g. two targets with the same
+ // simple name)
+ int type = gtarget->GetType();
+ std::string name = gtarget->GetName();
+ if(!name.empty() &&
+ 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)))
+ {
+ // Add a rule to build the target by name.
+ lg->WriteDivider(ruleFileStream);
+ ruleFileStream
+ << "# Target rules for targets named "
+ << name << "\n\n";
+
+ // Write the rule.
+ commands.clear();
+ std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
+ tmp += "Makefile2";
+ commands.push_back(lg->GetRecursiveMakeCall
+ (tmp.c_str(),name));
+ depends.clear();
+ depends.push_back("cmake_check_build_system");
+ lg->WriteMakeRule(ruleFileStream,
+ "Build rule for target.",
+ name, depends, commands,
+ true);
+
+ // Add a fast rule to build the target
+ std::string localName =
+ lg->GetRelativeTargetDirectory(*gtarget->Target);
+ std::string makefileName;
+ makefileName = localName;
+ makefileName += "/build.make";
+ depends.clear();
+ commands.clear();
+ std::string makeTargetName = localName;
+ makeTargetName += "/build";
+ localName = name;
+ localName += "/fast";
+ commands.push_back(lg->GetRecursiveMakeCall
+ (makefileName.c_str(), makeTargetName));
+ lg->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(gtarget->Target
+ ->NeedRelinkBeforeInstall(lg->ConfigurationName))
+ {
+ makeTargetName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+ makeTargetName += "/preinstall";
+ localName = name;
+ localName += "/preinstall";
+ depends.clear();
+ commands.clear();
+ commands.push_back(lg->GetRecursiveMakeCall
+ (makefileName.c_str(), makeTargetName));
+ lg->WriteMakeRule(ruleFileStream,
+ "Manual pre-install relink rule for target.",
+ localName, depends, commands, true);
+ }
+ }
+ }
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void
+cmGlobalUnixMakefileGenerator3
+::WriteConvenienceRules2(std::ostream& ruleFileStream,
+ cmLocalUnixMakefileGenerator3 *lg)
+{
+ std::vector<std::string> depends;
+ std::vector<std::string> commands;
+ std::string localName;
+ std::string makeTargetName;
+
+
+ // write the directory level rules for this local gen
+ this->WriteDirectoryRules2(ruleFileStream,lg);
+
+ 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();
+ t != targets.end(); ++t)
+ {
+ cmGeneratorTarget* gtarget = t->second;
+ if(gtarget->Target->IsImported())
+ {
+ continue;
+ }
+ 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)))
+ {
+ std::string makefileName;
+ // Add a rule to build the target by name.
+ localName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+ makefileName = localName;
+ makefileName += "/build.make";
+
+ bool needRequiresStep = this->NeedRequiresStep(*gtarget->Target);
+
+ lg->WriteDivider(ruleFileStream);
+ ruleFileStream
+ << "# Target rules for target "
+ << localName << "\n\n";
+
+ commands.clear();
+ makeTargetName = localName;
+ makeTargetName += "/depend";
+ commands.push_back(lg->GetRecursiveMakeCall
+ (makefileName.c_str(),makeTargetName));
+
+ // add requires if we need it for this generator
+ if (needRequiresStep)
+ {
+ makeTargetName = localName;
+ makeTargetName += "/requires";
+ commands.push_back(lg->GetRecursiveMakeCall
+ (makefileName.c_str(),makeTargetName));
+ }
+ makeTargetName = localName;
+ makeTargetName += "/build";
+ commands.push_back(lg->GetRecursiveMakeCall
+ (makefileName.c_str(),makeTargetName));
+
+ // Write the rule.
+ localName += "/all";
+ depends.clear();
+
+ std::string progressDir =
+ lg->GetMakefile()->GetHomeOutputDirectory();
+ progressDir += cmake::GetCMakeFilesDirectory();
+ {
+ cmOStringStream progCmd;
+ progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
+ // all target counts
+ progCmd << lg->Convert(progressDir,
+ cmLocalGenerator::FULL,
+ cmLocalGenerator::SHELL);
+ progCmd << " ";
+ std::vector<unsigned long>& progFiles =
+ this->ProgressMap[gtarget->Target].Marks;
+ for (std::vector<unsigned long>::iterator i = progFiles.begin();
+ i != progFiles.end(); ++i)
+ {
+ progCmd << " " << *i;
+ }
+ commands.push_back(progCmd.str());
+ }
+ progressDir = "Built target ";
+ progressDir += name;
+ lg->AppendEcho(commands,progressDir.c_str());
+
+ this->AppendGlobalTargetDepends(depends,*gtarget->Target);
+ lg->WriteMakeRule(ruleFileStream, "All Build rule for target.",
+ localName, depends, commands, true);
+
+ // add the all/all dependency
+ if(!this->IsExcluded(this->LocalGenerators[0], *gtarget->Target))
+ {
+ depends.clear();
+ depends.push_back(localName);
+ commands.clear();
+ lg->WriteMakeRule(ruleFileStream, "Include target in all.",
+ "all", depends, commands, true);
+ }
+
+ // Write the rule.
+ commands.clear();
+ progressDir = lg->GetMakefile()->GetHomeOutputDirectory();
+ progressDir += cmake::GetCMakeFilesDirectory();
+
+ {
+ // TODO: Convert the total progress count to a make variable.
+ cmOStringStream progCmd;
+ progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start ";
+ // # in target
+ progCmd << lg->Convert(progressDir,
+ cmLocalGenerator::FULL,
+ cmLocalGenerator::SHELL);
+ //
+ std::set<cmTarget const*> emitted;
+ progCmd << " "
+ << this->CountProgressMarksInTarget(gtarget->Target, emitted);
+ commands.push_back(progCmd.str());
+ }
+ std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
+ tmp += "Makefile2";
+ commands.push_back(lg->GetRecursiveMakeCall
+ (tmp.c_str(),localName));
+ {
+ cmOStringStream progCmd;
+ progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
+ progCmd << lg->Convert(progressDir,
+ cmLocalGenerator::FULL,
+ cmLocalGenerator::SHELL);
+ progCmd << " 0";
+ commands.push_back(progCmd.str());
+ }
+ depends.clear();
+ depends.push_back("cmake_check_build_system");
+ localName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+ localName += "/rule";
+ lg->WriteMakeRule(ruleFileStream,
+ "Build rule for subdir invocation for target.",
+ localName, depends, commands, true);
+
+ // Add a target with the canonical name (no prefix, suffix or path).
+ commands.clear();
+ depends.clear();
+ depends.push_back(localName);
+ lg->WriteMakeRule(ruleFileStream, "Convenience name for target.",
+ name, depends, commands, true);
+
+ // Add rules to prepare the target for installation.
+ if(gtarget->Target
+ ->NeedRelinkBeforeInstall(lg->ConfigurationName))
+ {
+ localName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+ localName += "/preinstall";
+ depends.clear();
+ commands.clear();
+ commands.push_back(lg->GetRecursiveMakeCall
+ (makefileName.c_str(), localName));
+ lg->WriteMakeRule(ruleFileStream,
+ "Pre-install relink rule for target.",
+ localName, depends, commands, true);
+
+ if(!this->IsExcluded(this->LocalGenerators[0], *gtarget->Target))
+ {
+ depends.clear();
+ depends.push_back(localName);
+ commands.clear();
+ lg->WriteMakeRule(ruleFileStream, "Prepare target for install.",
+ "preinstall", depends, commands, true);
+ }
+ }
+
+ // add the clean rule
+ localName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+ makeTargetName = localName;
+ makeTargetName += "/clean";
+ depends.clear();
+ commands.clear();
+ commands.push_back(lg->GetRecursiveMakeCall
+ (makefileName.c_str(), makeTargetName));
+ lg->WriteMakeRule(ruleFileStream, "clean rule for target.",
+ makeTargetName, depends, commands, true);
+ commands.clear();
+ depends.push_back(makeTargetName);
+ lg->WriteMakeRule(ruleFileStream, "clean rule for target.",
+ "clean", depends, commands, true);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+size_t
+cmGlobalUnixMakefileGenerator3
+::CountProgressMarksInTarget(cmTarget const* target,
+ std::set<cmTarget const*>& emitted)
+{
+ size_t count = 0;
+ if(emitted.insert(target).second)
+ {
+ 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)
+ {
+ continue;
+ }
+ count += this->CountProgressMarksInTarget(*di, emitted);
+ }
+ }
+ return count;
+}
+
+//----------------------------------------------------------------------------
+size_t
+cmGlobalUnixMakefileGenerator3
+::CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg)
+{
+ size_t count = 0;
+ std::set<cmTarget const*> emitted;
+ std::set<cmTarget const*> const& targets
+ = this->LocalGeneratorToTargetMap[lg];
+ for(std::set<cmTarget const*>::const_iterator t = targets.begin();
+ t != targets.end(); ++t)
+ {
+ count += this->CountProgressMarksInTarget(*t, emitted);
+ }
+ return count;
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalUnixMakefileGenerator3::RecordTargetProgress(
+ cmMakefileTargetGenerator* tg)
+{
+ TargetProgress& tp = this->ProgressMap[tg->GetTarget()];
+ tp.NumberOfActions = tg->GetNumberOfProgressActions();
+ tp.VariableFile = tg->GetProgressFileNameFull();
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalUnixMakefileGenerator3::TargetProgress
+::WriteProgressVariables(unsigned long total, unsigned long &current)
+{
+ cmGeneratedFileStream fout(this->VariableFile.c_str());
+ for(unsigned long i = 1; i <= this->NumberOfActions; ++i)
+ {
+ fout << "CMAKE_PROGRESS_" << i << " = ";
+ if (total <= 100)
+ {
+ unsigned long num = i + current;
+ fout << num;
+ this->Marks.push_back(num);
+ }
+ else if (((i+current)*100)/total > ((i-1+current)*100)/total)
+ {
+ unsigned long num = ((i+current)*100)/total;
+ fout << num;
+ this->Marks.push_back(num);
+ }
+ fout << "\n";
+ }
+ fout << "\n";
+ current += this->NumberOfActions;
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalUnixMakefileGenerator3
+::AppendGlobalTargetDepends(std::vector<std::string>& depends,
+ cmTarget& target)
+{
+ TargetDependSet const& depends_set = this->GetTargetDirectDepends(target);
+ for(TargetDependSet::const_iterator i = depends_set.begin();
+ i != depends_set.end(); ++i)
+ {
+ // Create the target-level dependency.
+ cmTarget const* dep = *i;
+ if (dep->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ cmLocalUnixMakefileGenerator3* lg3 =
+ static_cast<cmLocalUnixMakefileGenerator3*>
+ (dep->GetMakefile()->GetLocalGenerator());
+ std::string tgtName = lg3->GetRelativeTargetDirectory(*dep);
+ tgtName += "/all";
+ depends.push_back(tgtName);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalUnixMakefileGenerator3::WriteHelpRule
+(std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3 *lg)
+{
+ // add the help target
+ std::string path;
+ std::vector<std::string> no_depends;
+ std::vector<std::string> commands;
+ lg->AppendEcho(commands,"The following are some of the valid targets "
+ "for this Makefile:");
+ lg->AppendEcho(commands,"... all (the default if no target is provided)");
+ lg->AppendEcho(commands,"... clean");
+ lg->AppendEcho(commands,"... depend");
+
+ // Keep track of targets already listed.
+ std::set<std::string> emittedTargets;
+
+ // for each local generator
+ unsigned int i;
+ cmLocalUnixMakefileGenerator3 *lg2;
+ for (i = 0; i < this->LocalGenerators.size(); ++i)
+ {
+ lg2 =
+ 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->GetParent())
+ {
+ // 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)
+ {
+ 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))
+ {
+ std::string name = target.GetName();
+ if(emittedTargets.insert(name).second)
+ {
+ path = "... ";
+ path += name;
+ lg->AppendEcho(commands,path.c_str());
+ }
+ }
+ }
+ }
+ }
+ std::vector<std::string> const& localHelp = lg->GetLocalHelp();
+ for(std::vector<std::string>::const_iterator o = localHelp.begin();
+ o != localHelp.end(); ++o)
+ {
+ path = "... ";
+ path += *o;
+ lg->AppendEcho(commands, path.c_str());
+ }
+ lg->WriteMakeRule(ruleFileStream, "Help Target",
+ "help",
+ no_depends, commands, true);
+ ruleFileStream << "\n\n";
+}
+
+
+bool cmGlobalUnixMakefileGenerator3
+::NeedRequiresStep(cmTarget const& target)
+{
+ std::set<std::string> languages;
+ target.GetLanguages(languages,
+ 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))
+ {
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h
new file mode 100644
index 0000000000..c61c36e06b
--- /dev/null
+++ b/Source/cmGlobalUnixMakefileGenerator3.h
@@ -0,0 +1,202 @@
+/*============================================================================
+ 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 cmGlobalUnixMakefileGenerator3_h
+#define cmGlobalUnixMakefileGenerator3_h
+
+#include "cmGlobalGenerator.h"
+#include "cmGlobalGeneratorFactory.h"
+
+class cmGeneratedFileStream;
+class cmMakefileTargetGenerator;
+class cmLocalUnixMakefileGenerator3;
+
+/** \class cmGlobalUnixMakefileGenerator3
+ * \brief Write a Unix makefiles.
+ *
+ * cmGlobalUnixMakefileGenerator3 manages UNIX build process for a tree
+
+
+ The basic approach of this generator is to produce Makefiles that will all
+ be run with the current working directory set to the Home Output
+ directory. The one exception to this is the subdirectory Makefiles which are
+ created as a convenience and just cd up to the Home Output directory and
+ invoke the main Makefiles.
+
+ The make process starts with Makefile. Makefile should only contain the
+ targets the user is likely to invoke directly from a make command line. No
+ internal targets should be in this file. Makefile2 contains the internal
+ targets that are required to make the process work.
+
+ Makefile2 in turn will recursively make targets in the correct order. Each
+ target has its own directory \<target\>.dir and its own makefile build.make in
+ that directory. Also in that directory is a couple makefiles per source file
+ used by the target. Typically these are named source.obj.build.make and
+ source.obj.build.depend.make. The source.obj.build.make contains the rules
+ for building, cleaning, and computing dependencies for the given source
+ file. The build.depend.make contains additional dependencies that were
+ computed during dependency scanning. An additional file called
+ source.obj.depend is used as a marker to indicate when dependencies must be
+ rescanned.
+
+ Rules for custom commands follow the same model as rules for source files.
+
+ */
+
+class cmGlobalUnixMakefileGenerator3 : public cmGlobalGenerator
+{
+public:
+ cmGlobalUnixMakefileGenerator3();
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalUnixMakefileGenerator3>(); }
+
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalUnixMakefileGenerator3::GetActualName();}
+ static std::string GetActualName() {return "Unix Makefiles";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator3
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+
+ virtual void Configure();
+
+ /**
+ * Generate the all required files for building this project/tree. This
+ * basically creates a series of LocalGenerators for each directory and
+ * requests that they Generate.
+ */
+ virtual void Generate();
+
+
+ void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
+ std::vector<cmLocalGenerator *> &);
+
+ // write out the help rule listing the valid targets
+ void WriteHelpRule(std::ostream& ruleFileStream,
+ cmLocalUnixMakefileGenerator3 *);
+
+ // write the top level target rules
+ void WriteConvenienceRules(std::ostream& ruleFileStream,
+ std::set<std::string> &emitted);
+
+ /** Get the command to use for a target that has no rule. This is
+ used for multiple output dependencies and for cmake_force. */
+ std::string GetEmptyRuleHackCommand() { return this->EmptyRuleHackCommand; }
+
+ /** Get the fake dependency to use when a rule has no real commands
+ or dependencies. */
+ std::string GetEmptyRuleHackDepends() { return this->EmptyRuleHackDepends; }
+
+ // change the build command for speed
+ virtual void GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& projectDir,
+ const std::string& targetName,
+ const std::string& config,
+ bool fast,
+ std::vector<std::string> const& makeOptions = std::vector<std::string>()
+ );
+
+ /** Record per-target progress information. */
+ void RecordTargetProgress(cmMakefileTargetGenerator* tg);
+
+ void AddCXXCompileCommand(const std::string &sourceFile,
+ const std::string &workingDirectory,
+ const std::string &compileCommand);
+
+ /** Does the make tool tolerate .NOTPARALLEL? */
+ virtual bool AllowNotParallel() const { return true; }
+
+ virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
+protected:
+ void WriteMainMakefile2();
+ void WriteMainCMakefile();
+
+ void WriteConvenienceRules2(std::ostream& ruleFileStream,
+ cmLocalUnixMakefileGenerator3*);
+
+ void WriteDirectoryRule2(std::ostream& ruleFileStream,
+ cmLocalUnixMakefileGenerator3* lg,
+ const char* pass, bool check_all,
+ bool check_relink);
+ void WriteDirectoryRules2(std::ostream& ruleFileStream,
+ cmLocalUnixMakefileGenerator3* lg);
+
+ void AppendGlobalTargetDepends(std::vector<std::string>& depends,
+ cmTarget& target);
+
+ // does this generator need a requires step for any of its targets
+ bool NeedRequiresStep(cmTarget const&);
+
+ // Target name hooks for superclass.
+ const char* GetAllTargetName() const { return "all"; }
+ const char* GetInstallTargetName() const { return "install"; }
+ const char* GetInstallLocalTargetName() const { return "install/local"; }
+ const char* GetInstallStripTargetName() const { return "install/strip"; }
+ const char* GetPreinstallTargetName() const { return "preinstall"; }
+ const char* GetTestTargetName() const { return "test"; }
+ const char* GetPackageTargetName() const { return "package"; }
+ const char* GetPackageSourceTargetName() const { return "package_source"; }
+ const char* GetEditCacheTargetName() const { return "edit_cache"; }
+ const char* GetRebuildCacheTargetName() const { return "rebuild_cache"; }
+ const char* GetCleanTargetName() const { return "clean"; }
+
+ virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const { return true; }
+
+ // Some make programs (Borland) do not keep a rule if there are no
+ // dependencies or commands. This is a problem for creating rules
+ // that might not do anything but might have other dependencies
+ // added later. If non-empty this variable holds a fake dependency
+ // that can be added.
+ std::string EmptyRuleHackDepends;
+
+ // Some make programs (Watcom) do not like rules with no commands.
+ // If non-empty this variable holds a bogus command that may be put
+ // in the rule to satisfy the make program.
+ std::string EmptyRuleHackCommand;
+
+ // Store per-target progress counters.
+ struct TargetProgress
+ {
+ TargetProgress(): NumberOfActions(0) {}
+ unsigned long NumberOfActions;
+ std::string VariableFile;
+ std::vector<unsigned long> Marks;
+ void WriteProgressVariables(unsigned long total, unsigned long& current);
+ };
+ typedef std::map<cmTarget const*, TargetProgress,
+ cmStrictTargetComparison> ProgressMapType;
+ ProgressMapType ProgressMap;
+
+ size_t CountProgressMarksInTarget(cmTarget const* target,
+ std::set<cmTarget const*>& emitted);
+ size_t CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg);
+
+ cmGeneratedFileStream *CommandDatabase;
+private:
+ virtual const char* GetBuildIgnoreErrorsFlag() const { return "-i"; }
+ virtual std::string GetEditCacheCommand() const;
+};
+
+#endif
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx
new file mode 100644
index 0000000000..d70d2afe42
--- /dev/null
+++ b/Source/cmGlobalVisualStudio10Generator.cxx
@@ -0,0 +1,636 @@
+/*============================================================================
+ 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 "windows.h" // this must be first to define GetCurrentDirectory
+#include "cmGlobalVisualStudio10Generator.h"
+#include "cmLocalVisualStudio10Generator.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmVisualStudioSlnData.h"
+#include "cmVisualStudioSlnParser.h"
+#include "cmake.h"
+
+static const char vs10generatorName[] = "Visual Studio 10 2010";
+
+// Map generator name without year to name with year.
+static const char* cmVS10GenName(const std::string& name, std::string& genName)
+{
+ if(strncmp(name.c_str(), vs10generatorName,
+ sizeof(vs10generatorName)-6) != 0)
+ {
+ return 0;
+ }
+ const char* p = name.c_str() + sizeof(vs10generatorName) - 6;
+ if(cmHasLiteralPrefix(p, " 2010"))
+ {
+ p += 5;
+ }
+ genName = std::string(vs10generatorName) + p;
+ return p;
+}
+
+class cmGlobalVisualStudio10Generator::Factory
+ : public cmGlobalGeneratorFactory
+{
+public:
+ virtual cmGlobalGenerator* CreateGlobalGenerator(
+ const std::string& name) const
+ {
+ std::string genName;
+ const char* p = cmVS10GenName(name, genName);
+ if(!p)
+ { return 0; }
+ if(!*p)
+ {
+ return new cmGlobalVisualStudio10Generator(
+ genName, "");
+ }
+ if(*p++ != ' ')
+ { return 0; }
+ if(strcmp(p, "Win64") == 0)
+ {
+ return new cmGlobalVisualStudio10Generator(
+ genName, "x64");
+ }
+ if(strcmp(p, "IA64") == 0)
+ {
+ return new cmGlobalVisualStudio10Generator(
+ genName, "Itanium");
+ }
+ return 0;
+ }
+
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const
+ {
+ entry.Name = vs10generatorName;
+ entry.Brief = "Generates Visual Studio 10 (VS 2010) project files.";
+ }
+
+ virtual void GetGenerators(std::vector<std::string>& names) const
+ {
+ names.push_back(vs10generatorName);
+ names.push_back(vs10generatorName + std::string(" IA64"));
+ names.push_back(vs10generatorName + std::string(" Win64"));
+ }
+};
+
+//----------------------------------------------------------------------------
+cmGlobalGeneratorFactory* cmGlobalVisualStudio10Generator::NewFactory()
+{
+ return new Factory;
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator(
+ const std::string& name, const std::string& platformName)
+ : cmGlobalVisualStudio8Generator(name, platformName)
+{
+ std::string vc10Express;
+ this->ExpressEdition = cmSystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\10.0\\Setup\\VC;"
+ "ProductDir", vc10Express, cmSystemTools::KeyWOW64_32);
+ this->SystemIsWindowsCE = false;
+ this->SystemIsWindowsPhone = false;
+ this->SystemIsWindowsStore = false;
+ this->MSBuildCommandInitialized = false;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudio10Generator::MatchesGeneratorName(
+ const std::string& name) const
+{
+ std::string genName;
+ if(cmVS10GenName(name, genName))
+ {
+ return genName == this->GetName();
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
+ cmMakefile* mf)
+{
+ this->SystemName = s;
+ this->SystemVersion = mf->GetSafeDefinition("CMAKE_SYSTEM_VERSION");
+ if(!this->InitializeSystem(mf))
+ {
+ return false;
+ }
+ return this->cmGlobalVisualStudio8Generator::SetSystemName(s, mf);
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudio10Generator::SetGeneratorPlatform(std::string const& p,
+ cmMakefile* mf)
+{
+ if(!this->cmGlobalVisualStudio8Generator::SetGeneratorPlatform(p, mf))
+ {
+ return false;
+ }
+ if(this->GetPlatformName() == "Itanium" || this->GetPlatformName() == "x64")
+ {
+ if(this->IsExpressEdition() && !this->Find64BitTools(mf))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudio10Generator::SetGeneratorToolset(std::string const& ts,
+ cmMakefile* mf)
+{
+ if (this->SystemIsWindowsCE && ts.empty() &&
+ this->DefaultPlatformToolset.empty())
+ {
+ cmOStringStream e;
+ e << this->GetName() << " Windows CE version '" << this->SystemVersion
+ << "' requires CMAKE_GENERATOR_TOOLSET to be set.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ this->GeneratorToolset = ts;
+ if(const char* toolset = this->GetPlatformToolset())
+ {
+ mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET", toolset);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf)
+{
+ if (this->SystemName == "WindowsCE")
+ {
+ this->SystemIsWindowsCE = true;
+ if (!this->InitializeWindowsCE(mf))
+ {
+ return false;
+ }
+ }
+ else if(this->SystemName == "WindowsPhone")
+ {
+ this->SystemIsWindowsPhone = true;
+ if(!this->InitializeWindowsPhone(mf))
+ {
+ return false;
+ }
+ }
+ else if(this->SystemName == "WindowsStore")
+ {
+ this->SystemIsWindowsStore = true;
+ if(!this->InitializeWindowsStore(mf))
+ {
+ return false;
+ }
+ }
+ else if(this->SystemName == "Android")
+ {
+ if(this->DefaultPlatformName != "Win32")
+ {
+ cmOStringStream e;
+ e << "CMAKE_SYSTEM_NAME is 'Android' but CMAKE_GENERATOR "
+ << "specifies a platform too: '" << this->GetName() << "'";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+ std::string v = this->GetInstalledNsightTegraVersion();
+ if(v.empty())
+ {
+ mf->IssueMessage(cmake::FATAL_ERROR,
+ "CMAKE_SYSTEM_NAME is 'Android' but "
+ "'NVIDIA Nsight Tegra Visual Studio Edition' "
+ "is not installed.");
+ return false;
+ }
+ this->DefaultPlatformName = "Tegra-Android";
+ this->DefaultPlatformToolset = "Default";
+ this->NsightTegraVersion = v;
+ mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v.c_str());
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile* mf)
+{
+ if (this->DefaultPlatformName != "Win32")
+ {
+ cmOStringStream e;
+ e << "CMAKE_SYSTEM_NAME is 'WindowsCE' but CMAKE_GENERATOR "
+ << "specifies a platform too: '" << this->GetName() << "'";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ this->DefaultPlatformToolset = this->SelectWindowsCEToolset();
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::InitializeWindowsPhone(cmMakefile* mf)
+{
+ cmOStringStream e;
+ e << this->GetName() << " does not support Windows Phone.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
+{
+ cmOStringStream e;
+ e << this->GetName() << " does not support Windows Store.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
+{
+ if (this->SystemVersion == "8.0")
+ {
+ return "CE800";
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio10Generator::WriteSLNHeader(std::ostream& fout)
+{
+ fout << "Microsoft Visual Studio Solution File, Format Version 11.00\n";
+ if (this->ExpressEdition)
+ {
+ fout << "# Visual C++ Express 2010\n";
+ }
+ else
+ {
+ fout << "# Visual Studio 2010\n";
+ }
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalVisualStudio10Generator::CreateLocalGenerator()
+{
+ cmLocalVisualStudio10Generator* lg =
+ new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS10);
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio10Generator::Generate()
+{
+ this->LongestSource = LongestSourcePath();
+ this->cmGlobalVisualStudio8Generator::Generate();
+ if(this->LongestSource.Length > 0)
+ {
+ cmMakefile* mf = this->LongestSource.Target->GetMakefile();
+ cmOStringStream e;
+ e <<
+ "The binary and/or source directory paths may be too long to generate "
+ "Visual Studio 10 files for this project. "
+ "Consider choosing shorter directory names to build this project with "
+ "Visual Studio 10. "
+ "A more detailed explanation follows."
+ "\n"
+ "There is a bug in the VS 10 IDE that renders property dialog fields "
+ "blank for files referenced by full path in the project file. "
+ "However, CMake must reference at least one file by full path:\n"
+ " " << 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->GetCurrentOutputDirectory() << "/"
+ << 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());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio10Generator
+::EnableLanguage(std::vector<std::string>const & lang,
+ cmMakefile *mf, bool optional)
+{
+ cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
+}
+
+//----------------------------------------------------------------------------
+const char* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
+{
+ if(!this->GeneratorToolset.empty())
+ {
+ return this->GeneratorToolset.c_str();
+ }
+ if(!this->DefaultPlatformToolset.empty())
+ {
+ return this->DefaultPlatformToolset.c_str();
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio10Generator::GetUserMacrosDirectory()
+{
+ std::string base;
+ std::string path;
+
+ // base begins with the VisualStudioProjectsLocation reg value...
+ if (cmSystemTools::ReadRegistryValue(
+ "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\10.0;"
+ "VisualStudioProjectsLocation",
+ base))
+ {
+ cmSystemTools::ConvertToUnixSlashes(base);
+
+ // 9.0 macros folder:
+ path = base + "/VSMacros80";
+ // *NOT* a typo; right now in Visual Studio 2008 beta the macros
+ // folder is VSMacros80... They may change it to 90 before final
+ // release of 2008 or they may not... we'll have to keep our eyes
+ // on it
+ }
+
+ // path is (correctly) still empty if we did not read the base value from
+ // the Registry value
+ return path;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio10Generator::GetUserMacrosRegKeyBase()
+{
+ return "Software\\Microsoft\\VisualStudio\\10.0\\vsmacros";
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf)
+{
+ this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf);
+ mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND",
+ this->GetMSBuildCommand().c_str());
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand()
+{
+ if(!this->MSBuildCommandInitialized)
+ {
+ this->MSBuildCommandInitialized = true;
+ this->MSBuildCommand = this->FindMSBuildCommand();
+ }
+ return this->MSBuildCommand;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
+{
+ std::string msbuild;
+ std::string mskey =
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\";
+ mskey += this->GetToolsVersion();
+ mskey += ";MSBuildToolsPath";
+ if(cmSystemTools::ReadRegistryValue(mskey.c_str(), msbuild,
+ cmSystemTools::KeyWOW64_32))
+ {
+ cmSystemTools::ConvertToUnixSlashes(msbuild);
+ msbuild += "/";
+ }
+ msbuild += "MSBuild.exe";
+ return msbuild;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand()
+{
+ if(this->ExpressEdition)
+ {
+ // Visual Studio Express >= 10 do not have "devenv.com" or
+ // "VCExpress.exe" that we can use to build reliably.
+ // Tell the caller it needs to use MSBuild instead.
+ return "";
+ }
+ // Skip over the cmGlobalVisualStudio8Generator implementation because
+ // we expect a real devenv and do not want to look for VCExpress.
+ return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand();
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio10Generator::GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& projectDir,
+ const std::string& targetName,
+ const std::string& config,
+ bool fast,
+ std::vector<std::string> const& makeOptions)
+{
+ // Select the caller- or user-preferred make program, else MSBuild.
+ std::string makeProgramSelected =
+ this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
+
+ // Check if the caller explicitly requested a devenv tool.
+ std::string makeProgramLower = makeProgramSelected;
+ cmSystemTools::LowerCase(makeProgramLower);
+ bool useDevEnv =
+ (makeProgramLower.find("devenv") != std::string::npos ||
+ makeProgramLower.find("vcexpress") != std::string::npos);
+
+ // MSBuild is preferred (and required for VS Express), but if the .sln has
+ // an Intel Fortran .vfproj then we have to use devenv. Parse it to find out.
+ cmSlnData slnData;
+ {
+ std::string slnFile;
+ if(!projectDir.empty())
+ {
+ slnFile = projectDir;
+ slnFile += "/";
+ }
+ slnFile += projectName;
+ slnFile += ".sln";
+ cmVisualStudioSlnParser parser;
+ if(parser.ParseFile(slnFile, slnData,
+ cmVisualStudioSlnParser::DataGroupProjects))
+ {
+ std::vector<cmSlnProjectEntry> slnProjects = slnData.GetProjects();
+ for(std::vector<cmSlnProjectEntry>::iterator i = slnProjects.begin();
+ !useDevEnv && i != slnProjects.end(); ++i)
+ {
+ std::string proj = i->GetRelativePath();
+ if(proj.size() > 7 &&
+ proj.substr(proj.size()-7) == ".vfproj")
+ {
+ useDevEnv = true;
+ }
+ }
+ }
+ }
+ if(useDevEnv)
+ {
+ // Use devenv to build solutions containing Intel Fortran projects.
+ cmGlobalVisualStudio7Generator::GenerateBuildCommand(
+ makeCommand, makeProgram, projectName, projectDir,
+ targetName, config, fast, makeOptions);
+ return;
+ }
+
+ makeCommand.push_back(makeProgramSelected);
+
+ std::string realTarget = targetName;
+ // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug /target:ALL_BUILD
+ if(realTarget.empty())
+ {
+ realTarget = "ALL_BUILD";
+ }
+ if ( realTarget == "clean" )
+ {
+ makeCommand.push_back(std::string(projectName)+".sln");
+ makeCommand.push_back("/t:Clean");
+ }
+ else
+ {
+ std::string targetProject(realTarget);
+ targetProject += ".vcxproj";
+ if (targetProject.find('/') == std::string::npos)
+ {
+ // it might be in a subdir
+ if (cmSlnProjectEntry const* proj =
+ slnData.GetProjectByName(realTarget))
+ {
+ targetProject = proj->GetRelativePath();
+ cmSystemTools::ConvertToUnixSlashes(targetProject);
+ }
+ }
+ makeCommand.push_back(targetProject);
+ }
+ std::string configArg = "/p:Configuration=";
+ if(!config.empty())
+ {
+ configArg += config;
+ }
+ else
+ {
+ configArg += "Debug";
+ }
+ makeCommand.push_back(configArg);
+ makeCommand.push_back(std::string("/p:VisualStudioVersion=")+
+ this->GetIDEVersion());
+ makeCommand.insert(makeCommand.end(),
+ makeOptions.begin(), makeOptions.end());
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
+{
+ if(this->GetPlatformToolset())
+ {
+ return true;
+ }
+ // This edition does not come with 64-bit tools. Look for them.
+ //
+ // TODO: Detect available tools? x64\v100 exists but does not work?
+ // HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0;VCTargetsPath
+ // c:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/Platforms/
+ // {Itanium,Win32,x64}/PlatformToolsets/{v100,v90,Windows7.1SDK}
+ std::string winSDK_7_1;
+ if(cmSystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\"
+ "Windows\\v7.1;InstallationFolder", winSDK_7_1))
+ {
+ cmOStringStream m;
+ m << "Found Windows SDK v7.1: " << winSDK_7_1;
+ mf->DisplayStatus(m.str().c_str(), -1);
+ this->DefaultPlatformToolset = "Windows7.1SDK";
+ return true;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "Cannot enable 64-bit tools with Visual Studio 2010 Express.\n"
+ << "Install the Microsoft Windows SDK v7.1 to get 64-bit tools:\n"
+ << " http://msdn.microsoft.com/en-us/windows/bb980924.aspx";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalVisualStudio10Generator
+::GenerateRuleFile(std::string const& output) const
+{
+ // The VS 10 generator needs to create the .rule files on disk.
+ // Hide them away under the CMakeFiles directory.
+ std::string ruleDir = this->GetCMakeInstance()->GetHomeOutputDirectory();
+ ruleDir += cmake::GetCMakeFilesDirectory();
+ ruleDir += "/";
+ ruleDir += cmSystemTools::ComputeStringMD5(
+ cmSystemTools::GetFilenamePath(output).c_str());
+ std::string ruleFile = ruleDir + "/";
+ ruleFile += cmSystemTools::GetFilenameName(output);
+ ruleFile += ".rule";
+ return ruleFile;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio10Generator::PathTooLong(
+ cmTarget* target, cmSourceFile const* sf, std::string const& sfRel)
+{
+ size_t len = (strlen(target->GetMakefile()->GetCurrentOutputDirectory()) +
+ 1 + sfRel.length());
+ if(len > this->LongestSource.Length)
+ {
+ this->LongestSource.Length = len;
+ this->LongestSource.Target = target;
+ this->LongestSource.SourceFile = sf;
+ this->LongestSource.SourceRel = sfRel;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::UseFolderProperty()
+{
+ return IsExpressEdition() ? false : cmGlobalGenerator::UseFolderProperty();
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
+{
+ return !this->NsightTegraVersion.empty();
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio10Generator::GetNsightTegraVersion() const
+{
+ return this->NsightTegraVersion;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
+{
+ std::string version;
+ cmSystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;"
+ "Version", version, cmSystemTools::KeyWOW64_32);
+ return version;
+}
diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h
new file mode 100644
index 0000000000..686dcdf596
--- /dev/null
+++ b/Source/cmGlobalVisualStudio10Generator.h
@@ -0,0 +1,159 @@
+/*============================================================================
+ 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 cmGlobalVisualStudio10Generator_h
+#define cmGlobalVisualStudio10Generator_h
+
+#include "cmGlobalVisualStudio8Generator.h"
+
+
+/** \class cmGlobalVisualStudio10Generator
+ * \brief Write a Unix makefiles.
+ *
+ * cmGlobalVisualStudio10Generator manages UNIX build process for a tree
+ */
+class cmGlobalVisualStudio10Generator :
+ public cmGlobalVisualStudio8Generator
+{
+public:
+ cmGlobalVisualStudio10Generator(const std::string& name,
+ const std::string& platformName);
+ static cmGlobalGeneratorFactory* NewFactory();
+
+ virtual bool MatchesGeneratorName(const std::string& name) const;
+
+ virtual bool SetSystemName(std::string const& s, cmMakefile* mf);
+ virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
+ virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf);
+
+ virtual void GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& projectDir,
+ const std::string& targetName,
+ const std::string& config,
+ bool fast,
+ std::vector<std::string> const& makeOptions = std::vector<std::string>()
+ );
+
+ ///! create the correct local generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+ virtual void WriteSLNHeader(std::ostream& fout);
+
+ /** Is the installed VS an Express edition? */
+ bool IsExpressEdition() const { return this->ExpressEdition; }
+
+ /** Generating for Nsight Tegra VS plugin? */
+ bool IsNsightTegra() const;
+ std::string GetNsightTegraVersion() const;
+
+ /** The toolset name for the target platform. */
+ const char* GetPlatformToolset() const;
+
+ /** Return the CMAKE_SYSTEM_NAME. */
+ std::string const& GetSystemName() const { return this->SystemName; }
+
+ /** Return the CMAKE_SYSTEM_VERSION. */
+ std::string const& GetSystemVersion() const { return this->SystemVersion; }
+
+ /** Return true if building for WindowsCE */
+ bool TargetsWindowsCE() const
+ { return this->SystemIsWindowsCE; }
+
+ /** Return true if building for WindowsPhone */
+ bool TargetsWindowsPhone() const
+ { return this->SystemIsWindowsPhone; }
+
+ /** Return true if building for WindowsStore */
+ bool TargetsWindowsStore() const
+ { return this->SystemIsWindowsStore; }
+
+ /**
+ * Where does this version of Visual Studio look for macros for the
+ * current user? Returns the empty string if this version of Visual
+ * Studio does not implement support for VB macros.
+ */
+ virtual std::string GetUserMacrosDirectory();
+
+ /**
+ * What is the reg key path to "vsmacros" for this version of Visual
+ * Studio?
+ */
+ virtual std::string GetUserMacrosRegKeyBase();
+ virtual const char* GetCMakeCFGIntDir() const
+ { return "$(Configuration)";}
+ bool Find64BitTools(cmMakefile* mf);
+
+ /** 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,
+ std::string const& sfRel);
+
+ virtual const char* GetToolsVersion() { return "4.0"; }
+
+ virtual void FindMakeProgram(cmMakefile*);
+
+ static std::string GetInstalledNsightTegraVersion();
+
+protected:
+ virtual void Generate();
+ virtual bool InitializeSystem(cmMakefile* mf);
+ virtual bool InitializeWindowsCE(cmMakefile* mf);
+ virtual bool InitializeWindowsPhone(cmMakefile* mf);
+ virtual bool InitializeWindowsStore(cmMakefile* mf);
+ virtual std::string SelectWindowsCEToolset() const;
+ virtual std::string SelectWindowsPhoneToolset() const { return ""; }
+ virtual std::string SelectWindowsStoreToolset() const { return ""; }
+
+ virtual const char* GetIDEVersion() { return "10.0"; }
+
+ std::string const& GetMSBuildCommand();
+
+ std::string GeneratorToolset;
+ std::string DefaultPlatformToolset;
+ std::string SystemName;
+ std::string SystemVersion;
+ std::string NsightTegraVersion;
+ bool SystemIsWindowsCE;
+ bool SystemIsWindowsPhone;
+ bool SystemIsWindowsStore;
+ bool ExpressEdition;
+
+ bool UseFolderProperty();
+
+private:
+ class Factory;
+ struct LongestSourcePath
+ {
+ LongestSourcePath(): Length(0), Target(0), SourceFile(0) {}
+ size_t Length;
+ cmTarget* Target;
+ cmSourceFile const* SourceFile;
+ std::string SourceRel;
+ };
+ LongestSourcePath LongestSource;
+
+ std::string MSBuildCommand;
+ bool MSBuildCommandInitialized;
+ virtual std::string FindMSBuildCommand();
+ virtual std::string FindDevEnvCommand();
+ virtual std::string GetVSMakeProgram() { return this->GetMSBuildCommand(); }
+};
+#endif
diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx
new file mode 100644
index 0000000000..39bbdc0758
--- /dev/null
+++ b/Source/cmGlobalVisualStudio11Generator.cxx
@@ -0,0 +1,258 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2011 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 "cmGlobalVisualStudio11Generator.h"
+#include "cmLocalVisualStudio10Generator.h"
+#include "cmMakefile.h"
+
+static const char vs11generatorName[] = "Visual Studio 11 2012";
+
+// Map generator name without year to name with year.
+static const char* cmVS11GenName(const std::string& name, std::string& genName)
+{
+ if(strncmp(name.c_str(), vs11generatorName,
+ sizeof(vs11generatorName)-6) != 0)
+ {
+ return 0;
+ }
+ const char* p = name.c_str() + sizeof(vs11generatorName) - 6;
+ if(cmHasLiteralPrefix(p, " 2012"))
+ {
+ p += 5;
+ }
+ genName = std::string(vs11generatorName) + p;
+ return p;
+}
+
+class cmGlobalVisualStudio11Generator::Factory
+ : public cmGlobalGeneratorFactory
+{
+public:
+ virtual cmGlobalGenerator* CreateGlobalGenerator(
+ const std::string& name) const
+ {
+ std::string genName;
+ const char* p = cmVS11GenName(name, genName);
+ if(!p)
+ { return 0; }
+ if(!*p)
+ {
+ return new cmGlobalVisualStudio11Generator(
+ genName, "");
+ }
+ if(*p++ != ' ')
+ { return 0; }
+ if(strcmp(p, "Win64") == 0)
+ {
+ return new cmGlobalVisualStudio11Generator(
+ genName, "x64");
+ }
+ if(strcmp(p, "ARM") == 0)
+ {
+ return new cmGlobalVisualStudio11Generator(
+ genName, "ARM");
+ }
+
+ std::set<std::string> installedSDKs =
+ cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
+
+ if(installedSDKs.find(p) == installedSDKs.end())
+ {
+ return 0;
+ }
+
+ cmGlobalVisualStudio11Generator* ret =
+ new cmGlobalVisualStudio11Generator(name, p);
+ ret->WindowsCEVersion = "8.00";
+ return ret;
+ }
+
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const
+ {
+ entry.Name = vs11generatorName;
+ entry.Brief = "Generates Visual Studio 11 (VS 2012) project files.";
+ }
+
+ virtual void GetGenerators(std::vector<std::string>& names) const
+ {
+ names.push_back(vs11generatorName);
+ names.push_back(vs11generatorName + std::string(" ARM"));
+ names.push_back(vs11generatorName + std::string(" Win64"));
+
+ std::set<std::string> installedSDKs =
+ cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
+ for(std::set<std::string>::const_iterator i =
+ installedSDKs.begin(); i != installedSDKs.end(); ++i)
+ {
+ names.push_back(std::string(vs11generatorName) + " " + *i);
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory()
+{
+ return new Factory;
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator(
+ const std::string& name, const std::string& platformName)
+ : cmGlobalVisualStudio10Generator(name, platformName)
+{
+ std::string vc11Express;
+ this->ExpressEdition = cmSystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\11.0\\Setup\\VC;"
+ "ProductDir", vc11Express, cmSystemTools::KeyWOW64_32);
+ this->DefaultPlatformToolset = "v110";
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudio11Generator::MatchesGeneratorName(
+ const std::string& name) const
+{
+ std::string genName;
+ if(cmVS11GenName(name, genName))
+ {
+ return genName == this->GetName();
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio11Generator::InitializeWindowsPhone(cmMakefile* mf)
+{
+ this->DefaultPlatformToolset = this->SelectWindowsPhoneToolset();
+ if(this->DefaultPlatformToolset.empty())
+ {
+ cmOStringStream e;
+ e << this->GetName() << " supports Windows Phone '8.0', but not '"
+ << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio11Generator::InitializeWindowsStore(cmMakefile* mf)
+{
+ this->DefaultPlatformToolset = this->SelectWindowsStoreToolset();
+ if(this->DefaultPlatformToolset.empty())
+ {
+ cmOStringStream e;
+ e << this->GetName() << " supports Windows Store '8.0', but not '"
+ << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset() const
+{
+ if(this->SystemVersion == "8.0")
+ {
+ return "v110_wp80";
+ }
+ return this->cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset();
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset() const
+{
+ if(this->SystemVersion == "8.0")
+ {
+ return "v110";
+ }
+ return this->cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset();
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio11Generator::WriteSLNHeader(std::ostream& fout)
+{
+ fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
+ if (this->ExpressEdition)
+ {
+ fout << "# Visual Studio Express 2012 for Windows Desktop\n";
+ }
+ else
+ {
+ fout << "# Visual Studio 2012\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+cmLocalGenerator *cmGlobalVisualStudio11Generator::CreateLocalGenerator()
+{
+ cmLocalVisualStudio10Generator* lg =
+ new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS11);
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio11Generator::UseFolderProperty()
+{
+ // Intentionally skip over the parent class implementation and call the
+ // grand-parent class's implementation. Folders are not supported by the
+ // Express editions in VS10 and earlier, but they are in VS11 Express.
+ return cmGlobalVisualStudio8Generator::UseFolderProperty();
+}
+
+//----------------------------------------------------------------------------
+std::set<std::string>
+cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
+{
+ const char sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
+ "Windows CE Tools\\SDKs";
+
+ std::vector<std::string> subkeys;
+ cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys,
+ cmSystemTools::KeyWOW64_32);
+
+ std::set<std::string> ret;
+ for(std::vector<std::string>::const_iterator i =
+ subkeys.begin(); i != subkeys.end(); ++i)
+ {
+ std::string key = sdksKey;
+ key += '\\';
+ key += *i;
+ key += ';';
+
+ std::string path;
+ if(cmSystemTools::ReadRegistryValue(key.c_str(),
+ path,
+ cmSystemTools::KeyWOW64_32) &&
+ !path.empty())
+ {
+ ret.insert(*i);
+ }
+ }
+
+ return ret;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudio11Generator::NeedsDeploy(cmTarget::TargetType type) const
+{
+ if((type == cmTarget::EXECUTABLE ||
+ type == cmTarget::SHARED_LIBRARY) &&
+ (this->SystemIsWindowsPhone ||
+ this->SystemIsWindowsStore))
+ {
+ return true;
+ }
+ return cmGlobalVisualStudio10Generator::NeedsDeploy(type);
+}
diff --git a/Source/cmGlobalVisualStudio11Generator.h b/Source/cmGlobalVisualStudio11Generator.h
new file mode 100644
index 0000000000..bbd935cb14
--- /dev/null
+++ b/Source/cmGlobalVisualStudio11Generator.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2011 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 cmGlobalVisualStudio11Generator_h
+#define cmGlobalVisualStudio11Generator_h
+
+#include "cmGlobalVisualStudio10Generator.h"
+
+
+/** \class cmGlobalVisualStudio11Generator */
+class cmGlobalVisualStudio11Generator:
+ public cmGlobalVisualStudio10Generator
+{
+public:
+ cmGlobalVisualStudio11Generator(const std::string& name,
+ const std::string& platformName);
+ static cmGlobalGeneratorFactory* NewFactory();
+
+ virtual bool MatchesGeneratorName(const std::string& name) const;
+
+ virtual void WriteSLNHeader(std::ostream& fout);
+
+ ///! create the correct local generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /** TODO: VS 11 user macro support. */
+ virtual std::string GetUserMacrosDirectory() { return ""; }
+protected:
+ virtual bool InitializeWindowsPhone(cmMakefile* mf);
+ virtual bool InitializeWindowsStore(cmMakefile* mf);
+ virtual std::string SelectWindowsPhoneToolset() const;
+ virtual std::string SelectWindowsStoreToolset() const;
+ virtual const char* GetIDEVersion() { return "11.0"; }
+ bool UseFolderProperty();
+ static std::set<std::string> GetInstalledWindowsCESDKs();
+
+ /** Return true if the configuration needs to be deployed */
+ virtual bool NeedsDeploy(cmTarget::TargetType type) const;
+private:
+ class Factory;
+ friend class Factory;
+};
+#endif
diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx
new file mode 100644
index 0000000000..29ecfe00b2
--- /dev/null
+++ b/Source/cmGlobalVisualStudio12Generator.cxx
@@ -0,0 +1,182 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2011 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 "cmGlobalVisualStudio12Generator.h"
+#include "cmLocalVisualStudio10Generator.h"
+#include "cmMakefile.h"
+
+static const char vs12generatorName[] = "Visual Studio 12 2013";
+
+// Map generator name without year to name with year.
+static const char* cmVS12GenName(const std::string& name, std::string& genName)
+{
+ if(strncmp(name.c_str(), vs12generatorName,
+ sizeof(vs12generatorName)-6) != 0)
+ {
+ return 0;
+ }
+ const char* p = name.c_str() + sizeof(vs12generatorName) - 6;
+ if(cmHasLiteralPrefix(p, " 2013"))
+ {
+ p += 5;
+ }
+ genName = std::string(vs12generatorName) + p;
+ return p;
+}
+
+class cmGlobalVisualStudio12Generator::Factory
+ : public cmGlobalGeneratorFactory
+{
+public:
+ virtual cmGlobalGenerator* CreateGlobalGenerator(
+ const std::string& name) const
+ {
+ std::string genName;
+ const char* p = cmVS12GenName(name, genName);
+ if(!p)
+ { return 0; }
+ if(!*p)
+ {
+ return new cmGlobalVisualStudio12Generator(
+ genName, "");
+ }
+ if(*p++ != ' ')
+ { return 0; }
+ if(strcmp(p, "Win64") == 0)
+ {
+ return new cmGlobalVisualStudio12Generator(
+ genName, "x64");
+ }
+ if(strcmp(p, "ARM") == 0)
+ {
+ return new cmGlobalVisualStudio12Generator(
+ genName, "ARM");
+ }
+ return 0;
+ }
+
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const
+ {
+ entry.Name = vs12generatorName;
+ entry.Brief = "Generates Visual Studio 12 (VS 2013) project files.";
+ }
+
+ virtual void GetGenerators(std::vector<std::string>& names) const
+ {
+ names.push_back(vs12generatorName);
+ names.push_back(vs12generatorName + std::string(" ARM"));
+ names.push_back(vs12generatorName + std::string(" Win64"));
+ }
+};
+
+//----------------------------------------------------------------------------
+cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory()
+{
+ return new Factory;
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudio12Generator::cmGlobalVisualStudio12Generator(
+ const std::string& name, const std::string& platformName)
+ : cmGlobalVisualStudio11Generator(name, platformName)
+{
+ std::string vc12Express;
+ this->ExpressEdition = cmSystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\12.0\\Setup\\VC;"
+ "ProductDir", vc12Express, cmSystemTools::KeyWOW64_32);
+ this->DefaultPlatformToolset = "v120";
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudio12Generator::MatchesGeneratorName(
+ const std::string& name) const
+{
+ std::string genName;
+ if(cmVS12GenName(name, genName))
+ {
+ return genName == this->GetName();
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio12Generator::InitializeWindowsPhone(cmMakefile* mf)
+{
+ this->DefaultPlatformToolset = this->SelectWindowsPhoneToolset();
+ if(this->DefaultPlatformToolset.empty())
+ {
+ cmOStringStream e;
+ e << this->GetName() << " supports Windows Phone '8.0' and '8.1', "
+ "but not '" << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio12Generator::InitializeWindowsStore(cmMakefile* mf)
+{
+ this->DefaultPlatformToolset = this->SelectWindowsStoreToolset();
+ if(this->DefaultPlatformToolset.empty())
+ {
+ cmOStringStream e;
+ e << this->GetName() << " supports Windows Store '8.0' and '8.1', "
+ "but not '" << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio12Generator::SelectWindowsPhoneToolset() const
+{
+ if(this->SystemVersion == "8.1")
+ {
+ return "v120_wp81";
+ }
+ return this->cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset();
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio12Generator::SelectWindowsStoreToolset() const
+{
+ if(this->SystemVersion == "8.1")
+ {
+ return "v120";
+ }
+ return this->cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset();
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio12Generator::WriteSLNHeader(std::ostream& fout)
+{
+ fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
+ if (this->ExpressEdition)
+ {
+ fout << "# Visual Studio Express 2013 for Windows Desktop\n";
+ }
+ else
+ {
+ fout << "# Visual Studio 2013\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+cmLocalGenerator *cmGlobalVisualStudio12Generator::CreateLocalGenerator()
+{
+ cmLocalVisualStudio10Generator* lg =
+ new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS12);
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
diff --git a/Source/cmGlobalVisualStudio12Generator.h b/Source/cmGlobalVisualStudio12Generator.h
new file mode 100644
index 0000000000..ec85f1011f
--- /dev/null
+++ b/Source/cmGlobalVisualStudio12Generator.h
@@ -0,0 +1,50 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2011 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 cmGlobalVisualStudio12Generator_h
+#define cmGlobalVisualStudio12Generator_h
+
+#include "cmGlobalVisualStudio11Generator.h"
+
+
+/** \class cmGlobalVisualStudio12Generator */
+class cmGlobalVisualStudio12Generator:
+ public cmGlobalVisualStudio11Generator
+{
+public:
+ cmGlobalVisualStudio12Generator(const std::string& name,
+ const std::string& platformName);
+ static cmGlobalGeneratorFactory* NewFactory();
+
+ virtual bool MatchesGeneratorName(const std::string& name) const;
+
+ virtual void WriteSLNHeader(std::ostream& fout);
+
+ ///! create the correct local generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /** TODO: VS 12 user macro support. */
+ virtual std::string GetUserMacrosDirectory() { return ""; }
+
+ //in Visual Studio 2013 they detached the MSBuild tools version
+ //from the .Net Framework version and instead made it have it's own
+ //version number
+ virtual const char* GetToolsVersion() { return "12.0"; }
+protected:
+ virtual bool InitializeWindowsPhone(cmMakefile* mf);
+ virtual bool InitializeWindowsStore(cmMakefile* mf);
+ virtual std::string SelectWindowsPhoneToolset() const;
+ virtual std::string SelectWindowsStoreToolset() const;
+ virtual const char* GetIDEVersion() { return "12.0"; }
+private:
+ class Factory;
+};
+#endif
diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx
new file mode 100644
index 0000000000..d001f93167
--- /dev/null
+++ b/Source/cmGlobalVisualStudio14Generator.cxx
@@ -0,0 +1,113 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2014 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 "cmGlobalVisualStudio14Generator.h"
+#include "cmLocalVisualStudio10Generator.h"
+#include "cmMakefile.h"
+
+static const char vs14generatorName[] = "Visual Studio 14";
+
+class cmGlobalVisualStudio14Generator::Factory
+ : public cmGlobalGeneratorFactory
+{
+public:
+ virtual cmGlobalGenerator* CreateGlobalGenerator(
+ const std::string& genName) const
+ {
+ if(strncmp(genName.c_str(), vs14generatorName,
+ sizeof(vs14generatorName) - 1) != 0)
+ {
+ return 0;
+ }
+ const char* p = genName.c_str() + sizeof(vs14generatorName) - 1;
+ if(!*p)
+ {
+ return new cmGlobalVisualStudio14Generator(
+ genName, "");
+ }
+ if(*p++ != ' ')
+ { return 0; }
+ if(strcmp(p, "Win64") == 0)
+ {
+ return new cmGlobalVisualStudio14Generator(
+ genName, "x64");
+ }
+ if(strcmp(p, "ARM") == 0)
+ {
+ return new cmGlobalVisualStudio14Generator(
+ genName, "ARM");
+ }
+ return 0;
+ }
+
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const
+ {
+ entry.Name = vs14generatorName;
+ entry.Brief = "Generates Visual Studio 14 project files.";
+ }
+
+ virtual void GetGenerators(std::vector<std::string>& names) const
+ {
+ names.push_back(vs14generatorName);
+ names.push_back(vs14generatorName + std::string(" ARM"));
+ names.push_back(vs14generatorName + std::string(" Win64"));
+ }
+};
+
+//----------------------------------------------------------------------------
+cmGlobalGeneratorFactory* cmGlobalVisualStudio14Generator::NewFactory()
+{
+ return new Factory;
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudio14Generator::cmGlobalVisualStudio14Generator(
+ const std::string& name, const std::string& platformName)
+ : cmGlobalVisualStudio12Generator(name, platformName)
+{
+ std::string vc14Express;
+ this->ExpressEdition = cmSystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\14.0\\Setup\\VC;"
+ "ProductDir", vc14Express, cmSystemTools::KeyWOW64_32);
+ this->DefaultPlatformToolset = "v140";
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudio14Generator::MatchesGeneratorName(
+ const std::string& name) const
+{
+ return name == this->GetName();
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio14Generator::WriteSLNHeader(std::ostream& fout)
+{
+ // Visual Studio 14 writes .sln format 12.00
+ fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
+ if (this->ExpressEdition)
+ {
+ fout << "# Visual Studio Express 14 for Windows Desktop\n";
+ }
+ else
+ {
+ fout << "# Visual Studio 14\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+cmLocalGenerator *cmGlobalVisualStudio14Generator::CreateLocalGenerator()
+{
+ cmLocalVisualStudio10Generator* lg =
+ new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS14);
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h
new file mode 100644
index 0000000000..3fd60a0bbd
--- /dev/null
+++ b/Source/cmGlobalVisualStudio14Generator.h
@@ -0,0 +1,43 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2014 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 cmGlobalVisualStudio14Generator_h
+#define cmGlobalVisualStudio14Generator_h
+
+#include "cmGlobalVisualStudio12Generator.h"
+
+
+/** \class cmGlobalVisualStudio14Generator */
+class cmGlobalVisualStudio14Generator:
+ public cmGlobalVisualStudio12Generator
+{
+public:
+ cmGlobalVisualStudio14Generator(const std::string& name,
+ const std::string& platformName);
+ static cmGlobalGeneratorFactory* NewFactory();
+
+ virtual bool MatchesGeneratorName(const std::string& name) const;
+
+ virtual void WriteSLNHeader(std::ostream& fout);
+
+ ///! create the correct local generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /** TODO: VS 14 user macro support. */
+ virtual std::string GetUserMacrosDirectory() { return ""; }
+
+ virtual const char* GetToolsVersion() { return "14.0"; }
+protected:
+ virtual const char* GetIDEVersion() { return "14.0"; }
+private:
+ class Factory;
+};
+#endif
diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx
new file mode 100644
index 0000000000..455a7a2d9a
--- /dev/null
+++ b/Source/cmGlobalVisualStudio6Generator.cxx
@@ -0,0 +1,431 @@
+/*============================================================================
+ 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 "cmGlobalVisualStudio6Generator.h"
+#include "cmLocalVisualStudio6Generator.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include "cmGeneratedFileStream.h"
+#include <cmsys/FStream.hxx>
+
+// Utility function to make a valid VS6 *.dsp filename out
+// of a CMake target name:
+//
+std::string GetVS6TargetName(const std::string& targetName)
+{
+ std::string name(targetName);
+
+ // Eliminate hyphens. VS6 cannot handle hyphens in *.dsp filenames...
+ // Replace them with underscores.
+ //
+ cmSystemTools::ReplaceString(name, "-", "_");
+
+ return name;
+}
+
+cmGlobalVisualStudio6Generator::cmGlobalVisualStudio6Generator()
+{
+ this->MSDevCommandInitialized = false;
+}
+
+void cmGlobalVisualStudio6Generator
+::EnableLanguage(std::vector<std::string>const& lang,
+ cmMakefile *mf,
+ bool optional)
+{
+ mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
+ mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
+ this->GenerateConfigurations(mf);
+ this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
+}
+
+void cmGlobalVisualStudio6Generator::GenerateConfigurations(cmMakefile* mf)
+{
+ std::string fname= mf->GetRequiredDefinition("CMAKE_ROOT");
+ const char* def= mf->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY");
+ if(def)
+ {
+ fname = def;
+ }
+ else
+ {
+ fname += "/Templates";
+ }
+ fname += "/CMakeVisualStudio6Configurations.cmake";
+ if(!mf->ReadListFile(mf->GetCurrentListFile(), fname.c_str()))
+ {
+ cmSystemTools::Error("Cannot open ", fname.c_str(),
+ ". Please copy this file from the main "
+ "CMake/Templates directory and edit it for "
+ "your build configurations.");
+ }
+ else if(!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
+ {
+ cmSystemTools::Error("CMAKE_CONFIGURATION_TYPES not set by ",
+ fname.c_str(),
+ ". Please copy this file from the main "
+ "CMake/Templates directory and edit it for "
+ "your build configurations.");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio6Generator::FindMakeProgram(cmMakefile* mf)
+{
+ this->cmGlobalVisualStudioGenerator::FindMakeProgram(mf);
+ mf->AddDefinition("CMAKE_VS_MSDEV_COMMAND",
+ this->GetMSDevCommand().c_str());
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmGlobalVisualStudio6Generator::GetMSDevCommand()
+{
+ if(!this->MSDevCommandInitialized)
+ {
+ this->MSDevCommandInitialized = true;
+ this->MSDevCommand = this->FindMSDevCommand();
+ }
+ return this->MSDevCommand;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio6Generator::FindMSDevCommand()
+{
+ std::string vscmd;
+ std::string vskey = this->GetRegistryBase() + "\\Setup;VsCommonDir";
+ if(cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
+ cmSystemTools::KeyWOW64_32))
+ {
+ cmSystemTools::ConvertToUnixSlashes(vscmd);
+ vscmd += "/MSDev98/Bin/";
+ }
+ vscmd += "msdev.exe";
+ return vscmd;
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalVisualStudio6Generator::GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& /*projectDir*/,
+ const std::string& targetName,
+ const std::string& config,
+ bool /*fast*/,
+ std::vector<std::string> const& makeOptions
+ )
+{
+ // now build the test
+ makeCommand.push_back(
+ this->SelectMakeProgram(makeProgram, this->GetMSDevCommand())
+ );
+
+ makeCommand.push_back(std::string(projectName)+".dsw");
+ makeCommand.push_back("/MAKE");
+ std::string targetArg;
+ bool clean = false;
+ std::string realTarget = targetName;
+ if ( realTarget == "clean" )
+ {
+ clean = true;
+ realTarget = "ALL_BUILD";
+ }
+ if (!realTarget.empty())
+ {
+ targetArg += realTarget;
+ }
+ else
+ {
+ targetArg += "ALL_BUILD";
+ }
+ targetArg += " - ";
+ if(!config.empty())
+ {
+ targetArg += config;
+ }
+ else
+ {
+ targetArg += "Debug";
+ }
+ makeCommand.push_back(targetArg);
+ if(clean)
+ {
+ makeCommand.push_back("/CLEAN");
+ }
+ else
+ {
+ makeCommand.push_back("/BUILD");
+ }
+ makeCommand.insert(makeCommand.end(),
+ makeOptions.begin(), makeOptions.end());
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalVisualStudio6Generator::CreateLocalGenerator()
+{
+ cmLocalGenerator *lg = new cmLocalVisualStudio6Generator;
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+
+void cmGlobalVisualStudio6Generator::Generate()
+{
+ // first do the superclass method
+ this->cmGlobalVisualStudioGenerator::Generate();
+
+ // Now write out the DSW
+ this->OutputDSWFile();
+}
+
+// Write a DSW file to the stream
+void cmGlobalVisualStudio6Generator
+::WriteDSWFile(std::ostream& fout,cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators)
+{
+ // Write out the header for a DSW file
+ this->WriteDSWHeader(fout);
+
+ // Collect all targets under this root generator and the transitive
+ // closure of their dependencies.
+ TargetDependSet projectTargets;
+ TargetDependSet originalTargets;
+ this->GetTargetSets(projectTargets, originalTargets, root, generators);
+ OrderedTargetDependSet orderedProjectTargets(projectTargets);
+
+ for(OrderedTargetDependSet::const_iterator
+ tt = orderedProjectTargets.begin();
+ tt != orderedProjectTargets.end(); ++tt)
+ {
+ cmTarget const* target = *tt;
+ if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ // Write the project into the DSW file
+ const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
+ if(expath)
+ {
+ std::string project = target->GetName();
+ std::string location = expath;
+ this->WriteExternalProject(fout, project.c_str(),
+ location.c_str(), target->GetUtilities());
+ }
+ else
+ {
+ std::string dspname = GetVS6TargetName(target->GetName());
+ std::string dir = target->GetMakefile()->GetStartOutputDirectory();
+ dir = root->Convert(dir.c_str(), cmLocalGenerator::START_OUTPUT);
+ this->WriteProject(fout, dspname.c_str(), dir.c_str(), *target);
+ }
+ }
+
+ // Write the footer for the DSW file
+ this->WriteDSWFooter(fout);
+}
+
+void cmGlobalVisualStudio6Generator
+::OutputDSWFile(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators)
+{
+ if(generators.size() == 0)
+ {
+ return;
+ }
+ std::string fname = root->GetMakefile()->GetStartOutputDirectory();
+ fname += "/";
+ fname += root->GetMakefile()->GetProjectName();
+ fname += ".dsw";
+ cmsys::ofstream fout(fname.c_str());
+ if(!fout)
+ {
+ cmSystemTools::Error("Error can not open DSW file for write: ",
+ fname.c_str());
+ cmSystemTools::ReportLastSystemError("");
+ return;
+ }
+ this->WriteDSWFile(fout, root, generators);
+}
+
+// output the DSW file
+void cmGlobalVisualStudio6Generator::OutputDSWFile()
+{
+ std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
+ for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
+ {
+ this->OutputDSWFile(it->second[0], it->second);
+ }
+}
+
+// Write a dsp file into the DSW file,
+// 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)
+{
+ fout << "#########################################################"
+ "######################\n\n";
+ fout << "Project: \"" << dspname << "\"="
+ << dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n";
+ fout << "Package=<5>\n{{{\n}}}\n\n";
+ fout << "Package=<4>\n";
+ fout << "{{{\n";
+ VSDependSet const& depends = this->VSTargetDepends[&target];
+ for(VSDependSet::const_iterator di = depends.begin();
+ di != depends.end(); ++di)
+ {
+ const char* name = di->c_str();
+ fout << "Begin Project Dependency\n";
+ fout << "Project_Dep_Name " << GetVS6TargetName(name) << "\n";
+ fout << "End Project Dependency\n";
+ }
+ fout << "}}}\n\n";
+
+ UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
+ if(ui != this->UtilityDepends.end())
+ {
+ const char* uname = ui->second.c_str();
+ fout << "Project: \"" << uname << "\"="
+ << dir << "\\" << uname << ".dsp - Package Owner=<4>\n\n";
+ fout <<
+ "Package=<5>\n{{{\n}}}\n\n"
+ "Package=<4>\n"
+ "{{{\n"
+ "Begin Project Dependency\n"
+ "Project_Dep_Name " << dspname << "\n"
+ "End Project Dependency\n"
+ "}}}\n\n";
+ ;
+ }
+}
+
+
+// Write a dsp file into the DSW file,
+// Note, that dependencies from executables to
+// the libraries it uses are also done here
+void cmGlobalVisualStudio6Generator::WriteExternalProject(std::ostream& fout,
+ const std::string& name,
+ const char* location,
+ const std::set<std::string>& dependencies)
+{
+ fout << "#########################################################"
+ "######################\n\n";
+ fout << "Project: \"" << name << "\"="
+ << location << " - Package Owner=<4>\n\n";
+ fout << "Package=<5>\n{{{\n}}}\n\n";
+ fout << "Package=<4>\n";
+ fout << "{{{\n";
+
+
+ std::set<std::string>::const_iterator i, end;
+ // write dependencies.
+ i = dependencies.begin();
+ end = dependencies.end();
+ for(;i!= end; ++i)
+ {
+ fout << "Begin Project Dependency\n";
+ fout << "Project_Dep_Name " << GetVS6TargetName(*i) << "\n";
+ fout << "End Project Dependency\n";
+ }
+ fout << "}}}\n\n";
+}
+
+
+
+// Standard end of dsw file
+void cmGlobalVisualStudio6Generator::WriteDSWFooter(std::ostream& fout)
+{
+ fout << "######################################################"
+ "#########################\n\n";
+ fout << "Global:\n\n";
+ fout << "Package=<5>\n{{{\n}}}\n\n";
+ fout << "Package=<3>\n{{{\n}}}\n\n";
+ fout << "#####################################################"
+ "##########################\n\n";
+}
+
+
+// ouput standard header for dsw file
+void cmGlobalVisualStudio6Generator::WriteDSWHeader(std::ostream& fout)
+{
+ fout << "Microsoft Developer Studio Workspace File, Format Version 6.00\n";
+ fout << "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n";
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalVisualStudio6Generator::WriteUtilityDepend(cmTarget const* target)
+{
+ std::string pname = target->GetName();
+ pname += "_UTILITY";
+ pname = GetVS6TargetName(pname.c_str());
+ std::string fname = target->GetMakefile()->GetStartOutputDirectory();
+ fname += "/";
+ fname += pname;
+ fname += ".dsp";
+ cmGeneratedFileStream fout(fname.c_str());
+ fout.SetCopyIfDifferent(true);
+ fout <<
+ "# Microsoft Developer Studio Project File - Name=\""
+ << pname << "\" - Package Owner=<4>\n"
+ "# Microsoft Developer Studio Generated Build File, Format Version 6.00\n"
+ "# ** DO NOT EDIT **\n"
+ "\n"
+ "# TARGTYPE \"Win32 (x86) Generic Project\" 0x010a\n"
+ "\n"
+ "CFG=" << pname << " - Win32 Debug\n"
+ "!MESSAGE \"" << pname << " - Win32 Debug\""
+ " (based on \"Win32 (x86) Generic Project\")\n"
+ "!MESSAGE \"" << pname << " - Win32 Release\" "
+ "(based on \"Win32 (x86) Generic Project\")\n"
+ "!MESSAGE \"" << pname << " - Win32 MinSizeRel\" "
+ "(based on \"Win32 (x86) Generic Project\")\n"
+ "!MESSAGE \"" << pname << " - Win32 RelWithDebInfo\" "
+ "(based on \"Win32 (x86) Generic Project\")\n"
+ "\n"
+ "# Begin Project\n"
+ "# Begin Target\n"
+ "# Name \"" << pname << " - Win32 Debug\"\n"
+ "# Name \"" << pname << " - Win32 Release\"\n"
+ "# Name \"" << pname << " - Win32 MinSizeRel\"\n"
+ "# Name \"" << pname << " - Win32 RelWithDebInfo\"\n"
+ "# End Target\n"
+ "# End Project\n"
+ ;
+ return pname;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio6Generator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalVisualStudio6Generator::GetActualName();
+ entry.Brief = "Generates Visual Studio 6 project files.";
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalVisualStudio6Generator
+::AppendDirectoryForConfig(const std::string& prefix,
+ const std::string& config,
+ const std::string& suffix,
+ std::string& dir)
+{
+ if(!config.empty())
+ {
+ dir += prefix;
+ dir += config;
+ dir += suffix;
+ }
+}
diff --git a/Source/cmGlobalVisualStudio6Generator.h b/Source/cmGlobalVisualStudio6Generator.h
new file mode 100644
index 0000000000..58efb2553c
--- /dev/null
+++ b/Source/cmGlobalVisualStudio6Generator.h
@@ -0,0 +1,111 @@
+/*============================================================================
+ 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 cmGlobalVisualStudio6Generator_h
+#define cmGlobalVisualStudio6Generator_h
+
+#include "cmGlobalVisualStudioGenerator.h"
+#include "cmGlobalGeneratorFactory.h"
+
+class cmTarget;
+
+/** \class cmGlobalVisualStudio6Generator
+ * \brief Write a Unix makefiles.
+ *
+ * cmGlobalVisualStudio6Generator manages UNIX build process for a tree
+ */
+class cmGlobalVisualStudio6Generator : public cmGlobalVisualStudioGenerator
+{
+public:
+ cmGlobalVisualStudio6Generator();
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalVisualStudio6Generator>(); }
+
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalVisualStudio6Generator::GetActualName();}
+ static std::string GetActualName() {return "Visual Studio 6";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+
+ /**
+ * Try running cmake and building a file. This is used for dynalically
+ * loaded commands, not as part of the usual build process.
+ */
+ virtual void GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& projectDir,
+ const std::string& targetName,
+ const std::string& config,
+ bool fast,
+ std::vector<std::string> const& makeOptions = std::vector<std::string>()
+ );
+
+ /**
+ * Generate the DSW workspace file.
+ */
+ virtual void OutputDSWFile();
+ virtual void OutputDSWFile(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+ virtual void WriteDSWFile(std::ostream& fout,
+ cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+
+ /** Append the subdirectory for the given configuration. */
+ virtual void AppendDirectoryForConfig(const std::string& prefix,
+ const std::string& config,
+ const std::string& suffix,
+ std::string& dir);
+
+ ///! What is the configurations directory variable called?
+ virtual const char* GetCMakeCFGIntDir() const { return "$(IntDir)"; }
+
+ virtual void FindMakeProgram(cmMakefile*);
+
+ virtual bool IsForVS6() const { return true; }
+
+protected:
+ virtual void Generate();
+ virtual const char* GetIDEVersion() { return "6.0"; }
+private:
+ virtual std::string GetVSMakeProgram() { return this->GetMSDevCommand(); }
+ void GenerateConfigurations(cmMakefile* mf);
+ void WriteDSWFile(std::ostream& fout);
+ void WriteDSWHeader(std::ostream& fout);
+ void WriteProject(std::ostream& fout,
+ const std::string& name, const char* path,
+ cmTarget 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);
+ std::string MSDevCommand;
+ bool MSDevCommandInitialized;
+ std::string const& GetMSDevCommand();
+ std::string FindMSDevCommand();
+};
+
+#endif
diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx
new file mode 100644
index 0000000000..a67a649140
--- /dev/null
+++ b/Source/cmGlobalVisualStudio71Generator.cxx
@@ -0,0 +1,316 @@
+/*============================================================================
+ 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 "windows.h" // this must be first to define GetCurrentDirectory
+#include "cmGlobalVisualStudio71Generator.h"
+#include "cmLocalVisualStudio7Generator.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator(
+ const std::string& platformName)
+ : cmGlobalVisualStudio7Generator(platformName)
+{
+ this->ProjectConfigurationSectionName = "ProjectConfiguration";
+}
+
+//----------------------------------------------------------------------------
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalVisualStudio71Generator::CreateLocalGenerator()
+{
+ cmLocalVisualStudio7Generator *lg =
+ new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS71);
+ lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio71Generator::GetUserMacrosDirectory()
+{
+ // Macros not supported on Visual Studio 7.1 and earlier because
+ // they do not appear to work *during* a build when called by an
+ // outside agent...
+ //
+ return "";
+
+#if 0
+ //
+ // The COM result from calling a Visual Studio macro with 7.1 indicates
+ // that the call succeeds, but the macro does not appear to execute...
+ //
+ // So, I am leaving this code here to show how to do it, but have not
+ // yet figured out what the issue is in terms of why the macro does not
+ // appear to execute...
+ //
+ std::string base;
+ std::string path;
+
+ // base begins with the VisualStudioProjectsLocation reg value...
+ if (cmSystemTools::ReadRegistryValue(
+ "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\7.1;"
+ "VisualStudioProjectsLocation",
+ base))
+ {
+ cmSystemTools::ConvertToUnixSlashes(base);
+
+ // 7.1 macros folder:
+ path = base + "/VSMacros71";
+ }
+
+ // path is (correctly) still empty if we did not read the base value from
+ // the Registry value
+ return path;
+#endif
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio71Generator::GetUserMacrosRegKeyBase()
+{
+ // Macros not supported on Visual Studio 7.1 and earlier because
+ // they do not appear to work *during* a build when called by an
+ // outside agent...
+ //
+ return "";
+
+#if 0
+ return "Software\\Microsoft\\VisualStudio\\7.1\\vsmacros";
+#endif
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio71Generator
+::WriteSLNFile(std::ostream& fout,
+ cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators)
+{
+ // Write out the header for a SLN file
+ this->WriteSLNHeader(fout);
+
+ // Collect all targets under this root generator and the transitive
+ // closure of their dependencies.
+ TargetDependSet projectTargets;
+ TargetDependSet originalTargets;
+ this->GetTargetSets(projectTargets, originalTargets, root, generators);
+ OrderedTargetDependSet orderedProjectTargets(projectTargets);
+
+ this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
+
+ bool useFolderProperty = this->UseFolderProperty();
+ if (useFolderProperty)
+ {
+ this->WriteFolders(fout);
+ }
+
+ // Write out the configurations information for the solution
+ fout << "Global\n";
+ // Write out the configurations for the solution
+ this->WriteSolutionConfigurations(fout);
+ fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
+ << ") = postSolution\n";
+ // Write out the configurations for all the targets in the project
+ this->WriteTargetConfigurations(fout, orderedProjectTargets);
+ fout << "\tEndGlobalSection\n";
+
+ if (useFolderProperty)
+ {
+ // Write out project folders
+ fout << "\tGlobalSection(NestedProjects) = preSolution\n";
+ this->WriteFoldersContent(fout);
+ fout << "\tEndGlobalSection\n";
+ }
+
+ // Write out global sections
+ this->WriteSLNGlobalSections(fout, root);
+
+ // Write the footer for the SLN file
+ this->WriteSLNFooter(fout);
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalVisualStudio71Generator
+::WriteSolutionConfigurations(std::ostream& fout)
+{
+ fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
+ for(std::vector<std::string>::iterator i = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ fout << "\t\t" << *i << " = " << *i << "\n";
+ }
+ fout << "\tEndGlobalSection\n";
+}
+
+//----------------------------------------------------------------------------
+// Write a dsp file into the SLN file,
+// Note, that dependencies from executables to
+// the libraries it uses are also done here
+void
+cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
+ const std::string& dspname,
+ const char* dir,
+ cmTarget const& t)
+{
+ // check to see if this is a fortran build
+ const char* ext = ".vcproj";
+ const char* project =
+ "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
+ if(this->TargetIsFortranOnly(t))
+ {
+ ext = ".vfproj";
+ project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
+ }
+ const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
+ if(targetExt)
+ {
+ ext = targetExt;
+ }
+
+ std::string guid = this->GetGUID(dspname);
+ fout << project
+ << dspname << "\", \""
+ << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
+ << dspname << ext << "\", \"{" << guid << "}\"\n";
+ fout << "\tProjectSection(ProjectDependencies) = postProject\n";
+ this->WriteProjectDepends(fout, dspname, dir, t);
+ fout << "\tEndProjectSection\n";
+
+ fout <<"EndProject\n";
+
+ UtilityDependsMap::iterator ui = this->UtilityDepends.find(&t);
+ if(ui != this->UtilityDepends.end())
+ {
+ const char* uname = ui->second.c_str();
+ fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
+ << uname << "\", \""
+ << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
+ << uname << ".vcproj" << "\", \"{"
+ << this->GetGUID(uname) << "}\"\n"
+ << "\tProjectSection(ProjectDependencies) = postProject\n"
+ << "\t\t{" << guid << "} = {" << guid << "}\n"
+ << "\tEndProjectSection\n"
+ << "EndProject\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+// Write a dsp file into the SLN file,
+// Note, that dependencies from executables to
+// the libraries it uses are also done here
+void
+cmGlobalVisualStudio71Generator
+::WriteProjectDepends(std::ostream& fout,
+ const std::string&,
+ const char*, cmTarget const& target)
+{
+ VSDependSet const& depends = this->VSTargetDepends[&target];
+ for(VSDependSet::const_iterator di = depends.begin();
+ di != depends.end(); ++di)
+ {
+ const char* name = di->c_str();
+ std::string guid = this->GetGUID(name);
+ if(guid.size() == 0)
+ {
+ std::string m = "Target: ";
+ m += target.GetName();
+ m += " depends on unknown target: ";
+ m += name;
+ cmSystemTools::Error(m.c_str());
+ }
+ fout << "\t\t{" << guid << "} = {" << guid << "}\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+// Write a dsp file into the SLN file, Note, that dependencies from
+// executables to the libraries it uses are also done here
+void cmGlobalVisualStudio71Generator
+::WriteExternalProject(std::ostream& fout,
+ const std::string& name,
+ const char* location,
+ const char* typeGuid,
+ const std::set<std::string>& depends)
+{
+ fout << "Project(\"{"
+ << (typeGuid ? typeGuid : this->ExternalProjectType(location))
+ << "}\") = \""
+ << name << "\", \""
+ << this->ConvertToSolutionPath(location) << "\", \"{"
+ << this->GetGUID(name)
+ << "}\"\n";
+
+ // write out the dependencies here VS 7.1 includes dependencies with the
+ // project instead of in the global section
+ if(!depends.empty())
+ {
+ fout << "\tProjectSection(ProjectDependencies) = postProject\n";
+ std::set<std::string>::const_iterator it;
+ for(it = depends.begin(); it != depends.end(); ++it)
+ {
+ if(it->size() > 0)
+ {
+ fout << "\t\t{"
+ << this->GetGUID(it->c_str())
+ << "} = {"
+ << this->GetGUID(it->c_str())
+ << "}\n";
+ }
+ }
+ fout << "\tEndProjectSection\n";
+ }
+
+ fout << "EndProject\n";
+
+
+}
+
+//----------------------------------------------------------------------------
+// Write a dsp file into the SLN file, Note, that dependencies from
+// executables to the libraries it uses are also done here
+void cmGlobalVisualStudio71Generator
+::WriteProjectConfigurations(
+ std::ostream& fout, const std::string& name, cmTarget::TargetType,
+ const std::set<std::string>& configsPartOfDefaultBuild,
+ std::string const& platformMapping)
+{
+ const std::string& platformName =
+ !platformMapping.empty() ? platformMapping : this->GetPlatformName();
+ std::string guid = this->GetGUID(name);
+ for(std::vector<std::string>::iterator i = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ fout << "\t\t{" << guid << "}." << *i
+ << ".ActiveCfg = " << *i << "|" << platformName << std::endl;
+ std::set<std::string>::const_iterator
+ ci = configsPartOfDefaultBuild.find(*i);
+ if(!(ci == configsPartOfDefaultBuild.end()))
+ {
+ fout << "\t\t{" << guid << "}." << *i
+ << ".Build.0 = " << *i << "|" << platformName << std::endl;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+// ouput standard header for dsw file
+void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
+{
+ fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio71Generator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalVisualStudio71Generator::GetActualName();
+ entry.Brief = "Generates Visual Studio .NET 2003 project files.";
+}
diff --git a/Source/cmGlobalVisualStudio71Generator.h b/Source/cmGlobalVisualStudio71Generator.h
new file mode 100644
index 0000000000..2b5259a762
--- /dev/null
+++ b/Source/cmGlobalVisualStudio71Generator.h
@@ -0,0 +1,80 @@
+/*============================================================================
+ 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 cmGlobalVisualStudio71Generator_h
+#define cmGlobalVisualStudio71Generator_h
+
+#include "cmGlobalVisualStudio7Generator.h"
+
+
+/** \class cmGlobalVisualStudio71Generator
+ * \brief Write a Unix makefiles.
+ *
+ * cmGlobalVisualStudio71Generator manages UNIX build process for a tree
+ */
+class cmGlobalVisualStudio71Generator : public cmGlobalVisualStudio7Generator
+{
+public:
+ cmGlobalVisualStudio71Generator(const std::string& platformName = "");
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalVisualStudio71Generator>(); }
+
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalVisualStudio71Generator::GetActualName();}
+ static std::string GetActualName() {return "Visual Studio 7 .NET 2003";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Where does this version of Visual Studio look for macros for the
+ * current user? Returns the empty string if this version of Visual
+ * Studio does not implement support for VB macros.
+ */
+ virtual std::string GetUserMacrosDirectory();
+
+ /**
+ * What is the reg key path to "vsmacros" for this version of Visual
+ * Studio?
+ */
+ virtual std::string GetUserMacrosRegKeyBase();
+
+protected:
+ virtual const char* GetIDEVersion() { return "7.1"; }
+ virtual void WriteSLNFile(std::ostream& fout,
+ cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+ virtual void WriteSolutionConfigurations(std::ostream& fout);
+ virtual void WriteProject(std::ostream& fout,
+ const std::string& name, const char* path,
+ cmTarget const& t);
+ virtual void WriteProjectDepends(std::ostream& fout,
+ const std::string& name, const char* path,
+ cmTarget const& t);
+ virtual void WriteProjectConfigurations(
+ std::ostream& fout, const std::string& name, cmTarget::TargetType type,
+ const std::set<std::string>& configsPartOfDefaultBuild,
+ const std::string& platformMapping = "");
+ virtual void WriteExternalProject(std::ostream& fout,
+ const std::string& name,
+ const char* path,
+ const char* typeGuid,
+ const std::set<std::string>& depends);
+ virtual void WriteSLNHeader(std::ostream& fout);
+
+ std::string ProjectConfigurationSectionName;
+};
+#endif
diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx
new file mode 100644
index 0000000000..401e4758d1
--- /dev/null
+++ b/Source/cmGlobalVisualStudio7Generator.cxx
@@ -0,0 +1,1092 @@
+/*============================================================================
+ 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 "windows.h" // this must be first to define GetCurrentDirectory
+#include <assert.h>
+#include "cmGlobalVisualStudio7Generator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmLocalVisualStudio7Generator.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include <cmsys/Encoding.hxx>
+
+cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator(
+ const std::string& platformName)
+{
+ this->IntelProjectVersion = 0;
+ this->DevEnvCommandInitialized = false;
+ this->MasmEnabled = false;
+
+ if (platformName.empty())
+ {
+ this->DefaultPlatformName = "Win32";
+ }
+ else
+ {
+ this->DefaultPlatformName = platformName;
+ }
+}
+
+cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator()
+{
+ free(this->IntelProjectVersion);
+}
+
+// Package GUID of Intel Visual Fortran plugin to VS IDE
+#define CM_INTEL_PLUGIN_GUID "{B68A201D-CB9B-47AF-A52F-7EEC72E217E4}"
+
+const char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion()
+{
+ if(!this->IntelProjectVersion)
+ {
+ // Compute the version of the Intel plugin to the VS IDE.
+ // If the key does not exist then use a default guess.
+ std::string intelVersion;
+ std::string vskey = this->GetRegistryBase();
+ vskey += "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion";
+ cmSystemTools::ReadRegistryValue(vskey.c_str(), intelVersion,
+ cmSystemTools::KeyWOW64_32);
+ unsigned int intelVersionNumber = ~0u;
+ sscanf(intelVersion.c_str(), "%u", &intelVersionNumber);
+ if(intelVersionNumber >= 11)
+ {
+ // Default to latest known project file version.
+ intelVersion = "11.0";
+ }
+ else if(intelVersionNumber == 10)
+ {
+ // Version 10.x actually uses 9.10 in project files!
+ intelVersion = "9.10";
+ }
+ else
+ {
+ // Version <= 9: use ProductVersion from registry.
+ }
+ this->IntelProjectVersion = strdup(intelVersion.c_str());
+ }
+ return this->IntelProjectVersion;
+}
+
+void cmGlobalVisualStudio7Generator
+::EnableLanguage(std::vector<std::string>const & lang,
+ cmMakefile *mf, bool optional)
+{
+ mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
+ mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
+ if(!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
+ {
+ mf->AddCacheDefinition(
+ "CMAKE_CONFIGURATION_TYPES",
+ "Debug;Release;MinSizeRel;RelWithDebInfo",
+ "Semicolon separated list of supported configuration types, "
+ "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
+ "anything else will be ignored.",
+ cmCacheManager::STRING);
+ }
+
+ // Create list of configurations requested by user's cache, if any.
+ this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
+ this->GenerateConfigurations(mf);
+
+ // if this environment variable is set, then copy it to
+ // a static cache entry. It will be used by
+ // cmLocalGenerator::ConstructScript, to add an extra PATH
+ // to all custom commands. This is because the VS IDE
+ // does not use the environment it is run in, and this allows
+ // for running commands and using dll's that the IDE environment
+ // does not know about.
+ const char* extraPath = cmSystemTools::GetEnv("CMAKE_MSVCIDE_RUN_PATH");
+ if(extraPath)
+ {
+ mf->AddCacheDefinition
+ ("CMAKE_MSVCIDE_RUN_PATH", extraPath,
+ "Saved environment variable CMAKE_MSVCIDE_RUN_PATH",
+ cmCacheManager::STATIC);
+ }
+
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio7Generator::FindMakeProgram(cmMakefile* mf)
+{
+ this->cmGlobalVisualStudioGenerator::FindMakeProgram(mf);
+ mf->AddDefinition("CMAKE_VS_DEVENV_COMMAND",
+ this->GetDevEnvCommand().c_str());
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmGlobalVisualStudio7Generator::GetDevEnvCommand()
+{
+ if(!this->DevEnvCommandInitialized)
+ {
+ this->DevEnvCommandInitialized = true;
+ this->DevEnvCommand = this->FindDevEnvCommand();
+ }
+ return this->DevEnvCommand;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand()
+{
+ std::string vscmd;
+ std::string vskey = this->GetRegistryBase() + ";InstallDir";
+ if(cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
+ cmSystemTools::KeyWOW64_32))
+ {
+ cmSystemTools::ConvertToUnixSlashes(vscmd);
+ vscmd += "/";
+ }
+ vscmd += "devenv.com";
+ return vscmd;
+}
+
+//----------------------------------------------------------------------------
+const char* cmGlobalVisualStudio7Generator::ExternalProjectType(
+ const char* location)
+{
+ std::string extension = cmSystemTools::GetFilenameLastExtension(location);
+ if (extension == ".vbproj")
+ {
+ return "F184B08F-C81C-45F6-A57F-5ABD9991F28F";
+ }
+ else if (extension == ".csproj")
+ {
+ return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
+ }
+ else if (extension == ".fsproj")
+ {
+ return "F2A71F9B-5D33-465A-A702-920D77279786";
+ }
+ else if (extension == ".vdproj")
+ {
+ return "54435603-DBB4-11D2-8724-00A0C9A8B90C";
+ }
+ else if (extension == ".dbproj")
+ {
+ return "C8D11400-126E-41CD-887F-60BD40844F9E";
+ }
+ else if (extension == ".wixproj")
+ {
+ return "930C7802-8A8C-48F9-8165-68863BCCD9DD";
+ }
+ else if (extension == ".pyproj")
+ {
+ return "888888A0-9F3D-457C-B088-3A5042F75D52";
+ }
+ return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";
+}
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio7Generator::GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& /*projectDir*/,
+ const std::string& targetName,
+ const std::string& config,
+ bool /*fast*/,
+ std::vector<std::string> const& makeOptions)
+{
+ // Select the caller- or user-preferred make program, else devenv.
+ std::string makeProgramSelected =
+ this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand());
+
+ // Ignore the above preference if it is msbuild.
+ // Assume any other value is either a devenv or
+ // command-line compatible with devenv.
+ std::string makeProgramLower = makeProgramSelected;
+ cmSystemTools::LowerCase(makeProgramLower);
+ if(makeProgramLower.find("msbuild") != std::string::npos)
+ {
+ makeProgramSelected = this->GetDevEnvCommand();
+ }
+
+ makeCommand.push_back(makeProgramSelected);
+
+ makeCommand.push_back(std::string(projectName) + ".sln");
+ std::string realTarget = targetName;
+ bool clean = false;
+ if ( realTarget == "clean" )
+ {
+ clean = true;
+ realTarget = "ALL_BUILD";
+ }
+ if(clean)
+ {
+ makeCommand.push_back("/clean");
+ }
+ else
+ {
+ makeCommand.push_back("/build");
+ }
+
+ if(!config.empty())
+ {
+ makeCommand.push_back(config);
+ }
+ else
+ {
+ makeCommand.push_back("Debug");
+ }
+ makeCommand.push_back("/project");
+
+ if (!realTarget.empty())
+ {
+ makeCommand.push_back(realTarget);
+ }
+ else
+ {
+ makeCommand.push_back("ALL_BUILD");
+ }
+ makeCommand.insert(makeCommand.end(),
+ makeOptions.begin(), makeOptions.end());
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
+{
+ cmLocalVisualStudio7Generator *lg =
+ new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS7);
+ lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
+{
+ if(!this->GeneratorPlatform.empty())
+ {
+ return this->GeneratorPlatform;
+ }
+ return this->DefaultPlatformName;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
+ cmMakefile* mf)
+{
+ mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
+ this->GetIntelProjectVersion());
+ return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio7Generator::SetGeneratorPlatform(std::string const& p,
+ cmMakefile* mf)
+{
+ if(this->GetPlatformName() == "x64")
+ {
+ mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE");
+ }
+ else if(this->GetPlatformName() == "Itanium")
+ {
+ mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
+ }
+ mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str());
+ return this->cmGlobalVisualStudioGenerator::SetGeneratorPlatform(p, mf);
+}
+
+void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)
+{
+ // process the configurations
+ const char* ct
+ = this->CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES");
+ if ( ct )
+ {
+ std::vector<std::string> argsOut;
+ cmSystemTools::ExpandListArgument(ct, argsOut);
+ for(std::vector<std::string>::iterator i = argsOut.begin();
+ i != argsOut.end(); ++i)
+ {
+ if(std::find(this->Configurations.begin(),
+ this->Configurations.end(),
+ *i) == this->Configurations.end())
+ {
+ this->Configurations.push_back(*i);
+ }
+ }
+ }
+ // default to at least Debug and Release
+ if(this->Configurations.size() == 0)
+ {
+ this->Configurations.push_back("Debug");
+ this->Configurations.push_back("Release");
+ }
+
+ // Reset the entry to have a semi-colon separated list.
+ std::string configs = this->Configurations[0];
+ for(unsigned int i=1; i < this->Configurations.size(); ++i)
+ {
+ configs += ";";
+ configs += this->Configurations[i];
+ }
+
+ mf->AddCacheDefinition(
+ "CMAKE_CONFIGURATION_TYPES",
+ configs.c_str(),
+ "Semicolon separated list of supported configuration types, "
+ "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
+ "anything else will be ignored.",
+ cmCacheManager::STRING);
+}
+
+void cmGlobalVisualStudio7Generator::Generate()
+{
+ // first do the superclass method
+ this->cmGlobalVisualStudioGenerator::Generate();
+
+ // Now write out the DSW
+ this->OutputSLNFile();
+ // If any solution or project files changed during the generation,
+ // tell Visual Studio to reload them...
+ if(!cmSystemTools::GetErrorOccuredFlag())
+ {
+ this->CallVisualStudioMacro(MacroReload);
+ }
+}
+
+void cmGlobalVisualStudio7Generator
+::OutputSLNFile(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators)
+{
+ if(generators.size() == 0)
+ {
+ return;
+ }
+ this->CurrentProject = root->GetMakefile()->GetProjectName();
+ std::string fname = root->GetMakefile()->GetStartOutputDirectory();
+ fname += "/";
+ fname += root->GetMakefile()->GetProjectName();
+ fname += ".sln";
+ cmGeneratedFileStream fout(fname.c_str());
+ fout.SetCopyIfDifferent(true);
+ if(!fout)
+ {
+ return;
+ }
+ this->WriteSLNFile(fout, root, generators);
+ if (fout.Close())
+ {
+ this->FileReplacedDuringGenerate(fname);
+ }
+}
+
+// output the SLN file
+void cmGlobalVisualStudio7Generator::OutputSLNFile()
+{
+ std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
+ for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
+ {
+ this->OutputSLNFile(it->second[0], it->second);
+ }
+}
+
+
+void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
+ std::ostream& fout,
+ OrderedTargetDependSet const& projectTargets)
+{
+ // loop over again and write out configurations for each target
+ // in the solution
+ for(OrderedTargetDependSet::const_iterator tt =
+ projectTargets.begin(); tt != projectTargets.end(); ++tt)
+ {
+ cmTarget const* target = *tt;
+ if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
+ if(expath)
+ {
+ std::set<std::string> allConfigurations(this->Configurations.begin(),
+ this->Configurations.end());
+ const char* mapping = target->GetProperty("VS_PLATFORM_MAPPING");
+ this->WriteProjectConfigurations(
+ fout, target->GetName().c_str(), target->GetType(),
+ allConfigurations, mapping ? mapping : "");
+ }
+ else
+ {
+ const std::set<std::string>& configsPartOfDefaultBuild =
+ this->IsPartOfDefaultBuild(projectTargets, target);
+ const char *vcprojName =
+ target->GetProperty("GENERATOR_FILE_NAME");
+ if (vcprojName)
+ {
+ this->WriteProjectConfigurations(fout, vcprojName, target->GetType(),
+ configsPartOfDefaultBuild);
+ }
+ }
+ }
+}
+
+
+void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
+ std::ostream& fout,
+ cmLocalGenerator* root,
+ OrderedTargetDependSet const& projectTargets)
+{
+ VisualStudioFolders.clear();
+
+ for(OrderedTargetDependSet::const_iterator tt =
+ projectTargets.begin(); tt != projectTargets.end(); ++tt)
+ {
+ cmTarget const* target = *tt;
+ if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ bool written = false;
+
+ // handle external vc project files
+ const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
+ if(expath)
+ {
+ std::string project = target->GetName();
+ std::string location = expath;
+
+ this->WriteExternalProject(fout,
+ project.c_str(),
+ location.c_str(),
+ target->GetProperty("VS_PROJECT_TYPE"),
+ target->GetUtilities());
+ written = true;
+ }
+ else
+ {
+ const char *vcprojName =
+ target->GetProperty("GENERATOR_FILE_NAME");
+ if(vcprojName)
+ {
+ cmMakefile* tmf = target->GetMakefile();
+ std::string dir = tmf->GetStartOutputDirectory();
+ dir = root->Convert(dir.c_str(),
+ cmLocalGenerator::START_OUTPUT);
+ if(dir == ".")
+ {
+ dir = ""; // msbuild cannot handle ".\" prefix
+ }
+ this->WriteProject(fout, vcprojName, dir.c_str(),
+ *target);
+ written = true;
+ }
+ }
+
+ // Create "solution folder" information from FOLDER target property
+ //
+ if (written && this->UseFolderProperty())
+ {
+ const char *targetFolder = target->GetProperty("FOLDER");
+ if (targetFolder)
+ {
+ std::vector<cmsys::String> tokens =
+ cmSystemTools::SplitString(targetFolder, '/', false);
+
+ std::string cumulativePath = "";
+
+ for(std::vector<cmsys::String>::iterator iter = tokens.begin();
+ iter != tokens.end(); ++iter)
+ {
+ if(!iter->size())
+ {
+ continue;
+ }
+
+ if (cumulativePath.empty())
+ {
+ cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
+ }
+ else
+ {
+ VisualStudioFolders[cumulativePath].insert(
+ cumulativePath + "/" + *iter);
+
+ cumulativePath = cumulativePath + "/" + *iter;
+ }
+
+ this->CreateGUID(cumulativePath.c_str());
+ }
+
+ if (!cumulativePath.empty())
+ {
+ VisualStudioFolders[cumulativePath].insert(target->GetName());
+ }
+ }
+ }
+ }
+}
+
+
+void cmGlobalVisualStudio7Generator::WriteTargetDepends(
+ std::ostream& fout,
+ OrderedTargetDependSet const& projectTargets
+ )
+{
+ for(OrderedTargetDependSet::const_iterator tt =
+ projectTargets.begin(); tt != projectTargets.end(); ++tt)
+ {
+ cmTarget const* target = *tt;
+ if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ cmMakefile* mf = target->GetMakefile();
+ const char *vcprojName =
+ target->GetProperty("GENERATOR_FILE_NAME");
+ if (vcprojName)
+ {
+ std::string dir = mf->GetStartDirectory();
+ this->WriteProjectDepends(fout, vcprojName,
+ dir.c_str(), *target);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+// Write a SLN file to the stream
+void cmGlobalVisualStudio7Generator
+::WriteSLNFile(std::ostream& fout,
+ cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators)
+{
+ // Write out the header for a SLN file
+ this->WriteSLNHeader(fout);
+
+ // Collect all targets under this root generator and the transitive
+ // closure of their dependencies.
+ TargetDependSet projectTargets;
+ TargetDependSet originalTargets;
+ this->GetTargetSets(projectTargets, originalTargets, root, generators);
+ OrderedTargetDependSet orderedProjectTargets(projectTargets);
+
+ this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
+
+ bool useFolderProperty = this->UseFolderProperty();
+ if (useFolderProperty)
+ {
+ this->WriteFolders(fout);
+ }
+
+ // Write out the configurations information for the solution
+ fout << "Global\n"
+ << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
+
+ int c = 0;
+ for(std::vector<std::string>::iterator i = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ fout << "\t\tConfigName." << c << " = " << *i << "\n";
+ c++;
+ }
+ fout << "\tEndGlobalSection\n";
+ // Write out project(target) depends
+ fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
+ this->WriteTargetDepends(fout, orderedProjectTargets);
+ fout << "\tEndGlobalSection\n";
+
+ if (useFolderProperty)
+ {
+ // Write out project folders
+ fout << "\tGlobalSection(NestedProjects) = preSolution\n";
+ this->WriteFoldersContent(fout);
+ fout << "\tEndGlobalSection\n";
+ }
+
+ // Write out the configurations for all the targets in the project
+ fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
+ this->WriteTargetConfigurations(fout, orderedProjectTargets);
+ fout << "\tEndGlobalSection\n";
+
+ // Write out global sections
+ this->WriteSLNGlobalSections(fout, root);
+
+ // Write the footer for the SLN file
+ this->WriteSLNFooter(fout);
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
+{
+ const char *prefix = "CMAKE_FOLDER_GUID_";
+ const std::string::size_type skip_prefix = strlen(prefix);
+ std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
+ for(std::map<std::string,std::set<std::string> >::iterator iter =
+ VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
+ {
+ std::string fullName = iter->first;
+ std::string guid = this->GetGUID(fullName.c_str());
+
+ cmSystemTools::ReplaceString(fullName, "/", "\\");
+ if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix))
+ {
+ fullName = fullName.substr(skip_prefix);
+ }
+
+ std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
+
+ fout << "Project(\"{" <<
+ guidProjectTypeFolder << "}\") = \"" <<
+ nameOnly << "\", \"" <<
+ fullName << "\", \"{" <<
+ guid <<
+ "}\"\nEndProject\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
+{
+ for(std::map<std::string,std::set<std::string> >::iterator iter =
+ VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
+ {
+ std::string key(iter->first);
+ std::string guidParent(this->GetGUID(key.c_str()));
+
+ for(std::set<std::string>::iterator it = iter->second.begin();
+ it != iter->second.end(); ++it)
+ {
+ std::string value(*it);
+ std::string guid(this->GetGUID(value.c_str()));
+
+ fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
+{
+ // Convert to backslashes. Do not use ConvertToOutputPath because
+ // we will add quoting ourselves, and we know these projects always
+ // use windows slashes.
+ std::string d = path;
+ std::string::size_type pos = 0;
+ while((pos = d.find('/', pos)) != d.npos)
+ {
+ d[pos++] = '\\';
+ }
+ return d;
+}
+
+// Write a dsp file into the SLN file,
+// Note, that dependencies from executables to
+// the libraries it uses are also done here
+void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
+ const std::string& dspname,
+ const char* dir, cmTarget const& target)
+{
+ // check to see if this is a fortran build
+ const char* ext = ".vcproj";
+ const char* project =
+ "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
+ if(this->TargetIsFortranOnly(target))
+ {
+ ext = ".vfproj";
+ project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
+ }
+
+ fout << project
+ << dspname << "\", \""
+ << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
+ << dspname << ext << "\", \"{"
+ << this->GetGUID(dspname) << "}\"\nEndProject\n";
+
+ UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
+ if(ui != this->UtilityDepends.end())
+ {
+ const char* uname = ui->second.c_str();
+ fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
+ << uname << "\", \""
+ << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
+ << uname << ".vcproj" << "\", \"{"
+ << this->GetGUID(uname) << "}\"\n"
+ << "EndProject\n";
+ }
+}
+
+
+
+// Write a dsp file into the SLN file,
+// Note, that dependencies from executables to
+// the libraries it uses are also done here
+void
+cmGlobalVisualStudio7Generator
+::WriteProjectDepends(std::ostream& fout,
+ const std::string& dspname,
+ const char*, cmTarget const& target)
+{
+ int depcount = 0;
+ std::string dspguid = this->GetGUID(dspname);
+ VSDependSet const& depends = this->VSTargetDepends[&target];
+ for(VSDependSet::const_iterator di = depends.begin();
+ di != depends.end(); ++di)
+ {
+ const char* name = di->c_str();
+ std::string guid = this->GetGUID(name);
+ if(guid.size() == 0)
+ {
+ std::string m = "Target: ";
+ m += target.GetName();
+ m += " depends on unknown target: ";
+ m += name;
+ cmSystemTools::Error(m.c_str());
+ }
+ fout << "\t\t{" << dspguid << "}." << depcount << " = {" << guid << "}\n";
+ depcount++;
+ }
+
+ UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
+ if(ui != this->UtilityDepends.end())
+ {
+ const char* uname = ui->second.c_str();
+ fout << "\t\t{" << this->GetGUID(uname) << "}.0 = {" << dspguid << "}\n";
+ }
+}
+
+
+// Write a dsp file into the SLN file, Note, that dependencies from
+// executables to the libraries it uses are also done here
+void cmGlobalVisualStudio7Generator
+::WriteProjectConfigurations(
+ std::ostream& fout, const std::string& name, cmTarget::TargetType,
+ const std::set<std::string>& configsPartOfDefaultBuild,
+ const std::string& platformMapping)
+{
+ const std::string& platformName =
+ !platformMapping.empty() ? platformMapping : this->GetPlatformName();
+ std::string guid = this->GetGUID(name);
+ for(std::vector<std::string>::iterator i = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ fout << "\t\t{" << guid << "}." << *i
+ << ".ActiveCfg = " << *i << "|" << platformName << "\n";
+ std::set<std::string>::const_iterator
+ ci = configsPartOfDefaultBuild.find(*i);
+ if(!(ci == configsPartOfDefaultBuild.end()))
+ {
+ fout << "\t\t{" << guid << "}." << *i
+ << ".Build.0 = " << *i << "|" << platformName << "\n";
+ }
+ }
+}
+
+
+
+// Write a dsp file into the SLN file,
+// Note, that dependencies from executables to
+// the libraries it uses are also done here
+void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
+ const std::string& name,
+ const char* location,
+ const char* typeGuid,
+ const std::set<std::string>&)
+{
+ fout << "Project("
+ << "\"{"
+ << (typeGuid ? typeGuid : this->ExternalProjectType(location))
+ << "}\") = \""
+ << name << "\", \""
+ << this->ConvertToSolutionPath(location) << "\", \"{"
+ << this->GetGUID(name)
+ << "}\"\n";
+ fout << "EndProject\n";
+}
+
+
+
+void cmGlobalVisualStudio7Generator
+::WriteSLNGlobalSections(std::ostream& fout,
+ cmLocalGenerator* root)
+{
+ bool extensibilityGlobalsOverridden = false;
+ bool extensibilityAddInsOverridden = false;
+ const cmPropertyMap& props = root->GetMakefile()->GetProperties();
+ for(cmPropertyMap::const_iterator itProp = props.begin();
+ itProp != props.end(); ++itProp)
+ {
+ if(itProp->first.find("VS_GLOBAL_SECTION_") == 0)
+ {
+ std::string sectionType;
+ std::string name = itProp->first.substr(18);
+ if(name.find("PRE_") == 0)
+ {
+ name = name.substr(4);
+ sectionType = "preSolution";
+ }
+ else if(name.find("POST_") == 0)
+ {
+ name = name.substr(5);
+ sectionType = "postSolution";
+ }
+ else
+ continue;
+ if(!name.empty())
+ {
+ if(name == "ExtensibilityGlobals" && sectionType == "postSolution")
+ extensibilityGlobalsOverridden = true;
+ else if(name == "ExtensibilityAddIns" && sectionType == "postSolution")
+ extensibilityAddInsOverridden = true;
+ fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
+ std::vector<std::string> keyValuePairs;
+ cmSystemTools::ExpandListArgument(itProp->second.GetValue(),
+ keyValuePairs);
+ for(std::vector<std::string>::const_iterator itPair =
+ keyValuePairs.begin(); itPair != keyValuePairs.end(); ++itPair)
+ {
+ const std::string::size_type posEqual = itPair->find('=');
+ if(posEqual != std::string::npos)
+ {
+ const std::string key =
+ cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
+ const std::string value =
+ cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
+ fout << "\t\t" << key << " = " << value << "\n";
+ }
+ }
+ fout << "\tEndGlobalSection\n";
+ }
+ }
+ }
+ if(!extensibilityGlobalsOverridden)
+ fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
+ << "\tEndGlobalSection\n";
+ if(!extensibilityAddInsOverridden)
+ fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
+ << "\tEndGlobalSection\n";
+}
+
+
+
+// Standard end of dsw file
+void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
+{
+ fout << "EndGlobal\n";
+}
+
+
+// ouput standard header for dsw file
+void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
+{
+ fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalVisualStudio7Generator::WriteUtilityDepend(cmTarget const* target)
+{
+ std::string pname = target->GetName();
+ pname += "_UTILITY";
+ std::string fname = target->GetMakefile()->GetStartOutputDirectory();
+ fname += "/";
+ fname += pname;
+ fname += ".vcproj";
+ cmGeneratedFileStream fout(fname.c_str());
+ fout.SetCopyIfDifferent(true);
+ this->CreateGUID(pname.c_str());
+ std::string guid = this->GetGUID(pname.c_str());
+
+ fout <<
+ "<?xml version=\"1.0\" encoding = \""
+ << this->Encoding() << "\"?>\n"
+ "<VisualStudioProject\n"
+ "\tProjectType=\"Visual C++\"\n"
+ "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
+ "\tName=\"" << pname << "\"\n"
+ "\tProjectGUID=\"{" << guid << "}\"\n"
+ "\tKeyword=\"Win32Proj\">\n"
+ "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
+ "\t<Configurations>\n"
+ ;
+ for(std::vector<std::string>::iterator i = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ fout <<
+ "\t\t<Configuration\n"
+ "\t\t\tName=\"" << *i << "|Win32\"\n"
+ "\t\t\tOutputDirectory=\"" << *i << "\"\n"
+ "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
+ "\t\t\tConfigurationType=\"10\"\n"
+ "\t\t\tUseOfMFC=\"0\"\n"
+ "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
+ "\t\t\tCharacterSet=\"2\">\n"
+ "\t\t</Configuration>\n"
+ ;
+ }
+ fout <<
+ "\t</Configurations>\n"
+ "\t<Files></Files>\n"
+ "\t<Globals></Globals>\n"
+ "</VisualStudioProject>\n"
+ ;
+
+ if(fout.Close())
+ {
+ this->FileReplacedDuringGenerate(fname);
+ }
+ return pname;
+}
+
+std::string cmGlobalVisualStudio7Generator::GetGUID(const std::string& name)
+{
+ std::string guidStoreName = name;
+ guidStoreName += "_GUID_CMAKE";
+ const char* storedGUID =
+ this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
+ if(storedGUID)
+ {
+ return std::string(storedGUID);
+ }
+ cmSystemTools::Error("Unknown Target referenced : ",
+ name.c_str());
+ return "";
+}
+
+
+void cmGlobalVisualStudio7Generator::CreateGUID(const std::string& name)
+{
+ std::string guidStoreName = name;
+ guidStoreName += "_GUID_CMAKE";
+ if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
+ {
+ return;
+ }
+ std::string ret;
+ UUID uid;
+ unsigned short *uidstr;
+ UuidCreate(&uid);
+ UuidToStringW(&uid,&uidstr);
+ ret = cmsys::Encoding::ToNarrow(reinterpret_cast<wchar_t*>(uidstr));
+ RpcStringFreeW(&uidstr);
+ ret = cmSystemTools::UpperCase(ret);
+ this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
+ ret.c_str(), "Stored GUID",
+ cmCacheManager::INTERNAL);
+}
+
+std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
+{
+ return &this->Configurations;
+};
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio7Generator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalVisualStudio7Generator::GetActualName();
+ entry.Brief = "Generates Visual Studio .NET 2002 project files.";
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalVisualStudio7Generator
+::AppendDirectoryForConfig(const std::string& prefix,
+ const std::string& config,
+ const std::string& suffix,
+ std::string& dir)
+{
+ if(!config.empty())
+ {
+ dir += prefix;
+ dir += config;
+ dir += suffix;
+ }
+}
+
+std::set<std::string>
+cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
+ OrderedTargetDependSet const& projectTargets, cmTarget 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)
+ {
+ return activeConfigs;
+ }
+ if(type == cmTarget::UTILITY && !this->IsDependedOn(projectTargets, target))
+ {
+ return activeConfigs;
+ }
+ // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
+ for(std::vector<std::string>::iterator i = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ const char* propertyValue =
+ target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
+ if(cmSystemTools::IsOff(propertyValue))
+ {
+ activeConfigs.insert(*i);
+ }
+ }
+ return activeConfigs;
+}
+
+bool
+cmGlobalVisualStudio7Generator
+::IsDependedOn(OrderedTargetDependSet const& projectTargets,
+ cmTarget const* targetIn)
+{
+ for (OrderedTargetDependSet::const_iterator l = projectTargets.begin();
+ l != projectTargets.end(); ++l)
+ {
+ cmTarget const& target = **l;
+ TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
+ if(tgtdeps.count(targetIn))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+static cmVS7FlagTable cmVS7ExtraFlagTable[] =
+{
+ // Precompiled header and related options. Note that the
+ // UsePrecompiledHeader entries are marked as "Continue" so that the
+ // corresponding PrecompiledHeaderThrough entry can be found.
+ {"UsePrecompiledHeader", "YX", "Automatically Generate", "2",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"WholeProgramOptimization", "LTCG", "WholeProgramOptimization", "true", 0},
+
+ // Exception handling mode. If no entries match, it will be FALSE.
+ {"ExceptionHandling", "GX", "enable c++ exceptions", "true", 0},
+ {"ExceptionHandling", "EHsc", "enable c++ exceptions", "true", 0},
+ // The EHa option does not have an IDE setting. Let it go to false,
+ // and have EHa passed on the command line by leaving out the table
+ // entry.
+
+ {0,0,0,0,0}
+};
+cmIDEFlagTable const* cmGlobalVisualStudio7Generator::GetExtraFlagTableVS7()
+{
+ return cmVS7ExtraFlagTable;
+}
+
+std::string cmGlobalVisualStudio7Generator::Encoding()
+{
+ std::ostringstream encoding;
+#ifdef CMAKE_ENCODING_UTF8
+ encoding << "UTF-8";
+#else
+ encoding << "Windows-1252";
+#endif
+ return encoding.str();
+}
diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h
new file mode 100644
index 0000000000..201a6a61d4
--- /dev/null
+++ b/Source/cmGlobalVisualStudio7Generator.h
@@ -0,0 +1,193 @@
+/*============================================================================
+ 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 cmGlobalVisualStudio7Generator_h
+#define cmGlobalVisualStudio7Generator_h
+
+#include "cmGlobalVisualStudioGenerator.h"
+#include "cmGlobalGeneratorFactory.h"
+
+class cmTarget;
+struct cmIDEFlagTable;
+
+/** \class cmGlobalVisualStudio7Generator
+ * \brief Write a Unix makefiles.
+ *
+ * cmGlobalVisualStudio7Generator manages UNIX build process for a tree
+ */
+class cmGlobalVisualStudio7Generator : public cmGlobalVisualStudioGenerator
+{
+public:
+ cmGlobalVisualStudio7Generator(const std::string& platformName = "");
+ ~cmGlobalVisualStudio7Generator();
+
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalVisualStudio7Generator>(); }
+
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalVisualStudio7Generator::GetActualName();}
+ static std::string GetActualName() {return "Visual Studio 7";}
+
+ ///! Get the name for the platform.
+ std::string const& GetPlatformName() const;
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ virtual bool SetSystemName(std::string const& s, cmMakefile* mf);
+
+ virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+
+ /**
+ * Try running cmake and building a file. This is used for dynamically
+ * loaded commands, not as part of the usual build process.
+ */
+ virtual void GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& projectDir,
+ const std::string& targetName,
+ const std::string& config,
+ bool fast,
+ std::vector<std::string> const& makeOptions = std::vector<std::string>()
+ );
+
+ /**
+ * Generate the DSW workspace file.
+ */
+ virtual void OutputSLNFile();
+
+ /**
+ * Get the list of configurations
+ */
+ std::vector<std::string> *GetConfigurations();
+
+ ///! Create a GUID or get an existing one.
+ void CreateGUID(const std::string& name);
+ std::string GetGUID(const std::string& name);
+
+ /** Append the subdirectory for the given configuration. */
+ virtual void AppendDirectoryForConfig(const std::string& prefix,
+ const std::string& config,
+ const std::string& suffix,
+ std::string& dir);
+
+ ///! What is the configurations directory variable called?
+ virtual const char* GetCMakeCFGIntDir() const { return "$(OutDir)"; }
+
+ /** Return true if the target project file should have the option
+ LinkLibraryDependencies and link to .sln dependencies. */
+ virtual bool NeedLinkLibraryDependencies(cmTarget&) { return false; }
+
+ const char* GetIntelProjectVersion();
+
+ virtual void FindMakeProgram(cmMakefile*);
+
+ /** Is the Microsoft Assembler enabled? */
+ bool IsMasmEnabled() const { return this->MasmEnabled; }
+
+ // Encoding for Visual Studio files
+ virtual std::string Encoding();
+
+protected:
+ virtual void Generate();
+ virtual const char* GetIDEVersion() { return "7.0"; }
+
+ std::string const& GetDevEnvCommand();
+ virtual std::string FindDevEnvCommand();
+
+ static const char* ExternalProjectType(const char* location);
+
+ static cmIDEFlagTable const* GetExtraFlagTableVS7();
+ virtual void OutputSLNFile(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+ virtual void WriteSLNFile(std::ostream& fout, cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+ virtual void WriteProject(std::ostream& fout,
+ const std::string& name, const char* path,
+ cmTarget const& t);
+ virtual void WriteProjectDepends(std::ostream& fout,
+ const std::string& name, const char* path,
+ cmTarget const&t);
+ virtual void WriteProjectConfigurations(
+ std::ostream& fout, const std::string& name, cmTarget::TargetType type,
+ const std::set<std::string>& configsPartOfDefaultBuild,
+ const std::string& platformMapping = "");
+ virtual void WriteSLNGlobalSections(std::ostream& fout,
+ cmLocalGenerator* root);
+ virtual void WriteSLNFooter(std::ostream& fout);
+ virtual void WriteSLNHeader(std::ostream& fout);
+ virtual std::string WriteUtilityDepend(cmTarget const* target);
+
+ virtual void WriteTargetsToSolution(
+ std::ostream& fout,
+ cmLocalGenerator* root,
+ OrderedTargetDependSet const& projectTargets);
+ virtual void WriteTargetDepends(
+ std::ostream& fout,
+ OrderedTargetDependSet const& projectTargets);
+ virtual void WriteTargetConfigurations(
+ std::ostream& fout,
+ OrderedTargetDependSet const& projectTargets);
+
+ void GenerateConfigurations(cmMakefile* mf);
+
+ virtual void WriteExternalProject(std::ostream& fout,
+ const std::string& name,
+ const char* path,
+ const char* typeGuid,
+ const std::set<std::string>&
+ dependencies);
+
+ std::string ConvertToSolutionPath(const char* path);
+
+ std::set<std::string>
+ IsPartOfDefaultBuild(OrderedTargetDependSet const& projectTargets,
+ cmTarget const* target);
+ bool IsDependedOn(OrderedTargetDependSet const& projectTargets,
+ cmTarget const* target);
+ std::vector<std::string> Configurations;
+ std::map<std::string, std::string> GUIDMap;
+
+ virtual void WriteFolders(std::ostream& fout);
+ virtual void WriteFoldersContent(std::ostream& fout);
+ std::map<std::string,std::set<std::string> > VisualStudioFolders;
+
+ // Set during OutputSLNFile with the name of the current project.
+ // There is one SLN file per project.
+ std::string CurrentProject;
+ std::string GeneratorPlatform;
+ std::string DefaultPlatformName;
+ bool MasmEnabled;
+
+private:
+ char* IntelProjectVersion;
+ std::string DevEnvCommand;
+ bool DevEnvCommandInitialized;
+ virtual std::string GetVSMakeProgram() { return this->GetDevEnvCommand(); }
+};
+
+#define CMAKE_CHECK_BUILD_SYSTEM_TARGET "ZERO_CHECK"
+
+#endif
diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx
new file mode 100644
index 0000000000..745515bcf1
--- /dev/null
+++ b/Source/cmGlobalVisualStudio8Generator.cxx
@@ -0,0 +1,533 @@
+/*============================================================================
+ 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 "windows.h" // this must be first to define GetCurrentDirectory
+#include "cmGlobalVisualStudio8Generator.h"
+#include "cmLocalVisualStudio7Generator.h"
+#include "cmMakefile.h"
+#include "cmVisualStudioWCEPlatformParser.h"
+#include "cmake.h"
+#include "cmGeneratedFileStream.h"
+#include "cmSourceFile.h"
+
+static const char vs8generatorName[] = "Visual Studio 8 2005";
+
+class cmGlobalVisualStudio8Generator::Factory
+ : public cmGlobalGeneratorFactory
+{
+public:
+ virtual cmGlobalGenerator* CreateGlobalGenerator(
+ const std::string& name) const {
+ if(strncmp(name.c_str(), vs8generatorName,
+ sizeof(vs8generatorName) - 1) != 0)
+ {
+ return 0;
+ }
+
+ const char* p = name.c_str() + sizeof(vs8generatorName) - 1;
+ if(p[0] == '\0')
+ {
+ return new cmGlobalVisualStudio8Generator(
+ name, "");
+ }
+
+ if(p[0] != ' ')
+ {
+ return 0;
+ }
+
+ ++p;
+
+ if(!strcmp(p, "Win64"))
+ {
+ return new cmGlobalVisualStudio8Generator(
+ name, "x64");
+ }
+
+ cmVisualStudioWCEPlatformParser parser(p);
+ parser.ParseVersion("8.0");
+ if (!parser.Found())
+ {
+ return 0;
+ }
+
+ cmGlobalVisualStudio8Generator* ret = new cmGlobalVisualStudio8Generator(
+ name, p);
+ ret->WindowsCEVersion = parser.GetOSVersion();
+ return ret;
+ }
+
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const {
+ entry.Name = vs8generatorName;
+ entry.Brief = "Generates Visual Studio 8 2005 project files.";
+ }
+
+ virtual void GetGenerators(std::vector<std::string>& names) const {
+ names.push_back(vs8generatorName);
+ names.push_back(vs8generatorName + std::string(" Win64"));
+ cmVisualStudioWCEPlatformParser parser;
+ parser.ParseVersion("8.0");
+ const std::vector<std::string>& availablePlatforms =
+ parser.GetAvailablePlatforms();
+ for(std::vector<std::string>::const_iterator i =
+ availablePlatforms.begin(); i != availablePlatforms.end(); ++i)
+ {
+ names.push_back("Visual Studio 8 2005 " + *i);
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+cmGlobalGeneratorFactory* cmGlobalVisualStudio8Generator::NewFactory()
+{
+ return new Factory;
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator(
+ const std::string& name, const std::string& platformName)
+ : cmGlobalVisualStudio71Generator(platformName)
+{
+ this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms";
+ this->Name = name;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio8Generator::FindDevEnvCommand()
+{
+ // First look for VCExpress.
+ std::string vsxcmd;
+ std::string vsxkey =
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\";
+ vsxkey += this->GetIDEVersion();
+ vsxkey += ";InstallDir";
+ if(cmSystemTools::ReadRegistryValue(vsxkey.c_str(), vsxcmd,
+ cmSystemTools::KeyWOW64_32))
+ {
+ cmSystemTools::ConvertToUnixSlashes(vsxcmd);
+ vsxcmd += "/VCExpress.exe";
+ return vsxcmd;
+ }
+ // Now look for devenv.
+ return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand();
+}
+
+//----------------------------------------------------------------------------
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator()
+{
+ cmLocalVisualStudio7Generator *lg =
+ new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS8);
+ lg->SetExtraFlagTable(this->GetExtraFlagTableVS8());
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio8Generator
+::EnableLanguage(std::vector<std::string>const & lang,
+ cmMakefile *mf, bool optional)
+{
+ for(std::vector<std::string>::const_iterator it = lang.begin();
+ it != lang.end(); ++it)
+ {
+ if(*it == "ASM_MASM")
+ {
+ this->MasmEnabled = true;
+ }
+ }
+ this->AddPlatformDefinitions(mf);
+ cmGlobalVisualStudio7Generator::EnableLanguage(lang, mf, optional);
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf)
+{
+ if(this->TargetsWindowsCE())
+ {
+ mf->AddDefinition("CMAKE_VS_WINCE_VERSION",
+ this->WindowsCEVersion.c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio8Generator::SetGeneratorPlatform(std::string const& p,
+ cmMakefile* mf)
+{
+ if(this->DefaultPlatformName == "Win32")
+ {
+ this->GeneratorPlatform = p;
+ return this->cmGlobalVisualStudio7Generator::SetGeneratorPlatform("", mf);
+ }
+ else
+ {
+ return this->cmGlobalVisualStudio7Generator::SetGeneratorPlatform(p, mf);
+ }
+}
+
+//----------------------------------------------------------------------------
+// ouput standard header for dsw file
+void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)
+{
+ fout << "Microsoft Visual Studio Solution File, Format Version 9.00\n";
+ fout << "# Visual Studio 2005\n";
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio8Generator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalVisualStudio8Generator::GetActualName();
+ entry.Brief = "Generates Visual Studio 8 2005 project files.";
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio8Generator::Configure()
+{
+ this->cmGlobalVisualStudio7Generator::Configure();
+ this->CreateGUID(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio8Generator::GetUserMacrosDirectory()
+{
+ // Some VS8 sp0 versions cannot run macros.
+ // See http://support.microsoft.com/kb/928209
+ const char* vc8sp1Registry =
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
+ "InstalledProducts\\KB926601;";
+ const char* vc8exSP1Registry =
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
+ "InstalledProducts\\KB926748;";
+ std::string vc8sp1;
+ if (!cmSystemTools::ReadRegistryValue(vc8sp1Registry, vc8sp1) &&
+ !cmSystemTools::ReadRegistryValue(vc8exSP1Registry, vc8sp1))
+ {
+ return "";
+ }
+
+ std::string base;
+ std::string path;
+
+ // base begins with the VisualStudioProjectsLocation reg value...
+ if (cmSystemTools::ReadRegistryValue(
+ "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0;"
+ "VisualStudioProjectsLocation",
+ base))
+ {
+ cmSystemTools::ConvertToUnixSlashes(base);
+
+ // 8.0 macros folder:
+ path = base + "/VSMacros80";
+ }
+
+ // path is (correctly) still empty if we did not read the base value from
+ // the Registry value
+ return path;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio8Generator::GetUserMacrosRegKeyBase()
+{
+ return "Software\\Microsoft\\VisualStudio\\8.0\\vsmacros";
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio8Generator::AddCheckTarget()
+{
+ // Add a special target on which all other targets depend that
+ // checks the build system and optionally re-runs CMake.
+ const char* no_working_directory = 0;
+ std::vector<std::string> no_depends;
+ std::vector<cmLocalGenerator*> const& generators = this->LocalGenerators;
+ cmLocalVisualStudio7Generator* lg =
+ static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
+ cmMakefile* mf = lg->GetMakefile();
+
+ // Skip the target if no regeneration is to be done.
+ if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION"))
+ {
+ return false;
+ }
+
+ std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
+ cmCustomCommandLines noCommandLines;
+ cmTarget* tgt =
+ mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
+ no_working_directory, no_depends,
+ noCommandLines);
+
+ // Organize in the "predefined targets" folder:
+ //
+ if (this->UseFolderProperty())
+ {
+ tgt->SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
+ }
+
+ // Create a list of all stamp files for this project.
+ std::vector<std::string> stamps;
+ std::string stampList = cmake::GetCMakeFilesDirectoryPostSlash();
+ stampList += "generate.stamp.list";
+ {
+ std::string stampListFile =
+ generators[0]->GetMakefile()->GetCurrentOutputDirectory();
+ stampListFile += "/";
+ stampListFile += stampList;
+ std::string stampFile;
+ cmGeneratedFileStream fout(stampListFile.c_str());
+ for(std::vector<cmLocalGenerator*>::const_iterator
+ gi = generators.begin(); gi != generators.end(); ++gi)
+ {
+ stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory();
+ stampFile += "/";
+ stampFile += cmake::GetCMakeFilesDirectoryPostSlash();
+ stampFile += "generate.stamp";
+ fout << stampFile << "\n";
+ stamps.push_back(stampFile);
+ }
+ }
+
+ // Add a custom rule to re-run CMake if any input files changed.
+ {
+ // Collect the input files used to generate all targets in this
+ // project.
+ std::vector<std::string> listFiles;
+ for(unsigned int j = 0; j < generators.size(); ++j)
+ {
+ cmMakefile* lmf = generators[j]->GetMakefile();
+ listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
+ lmf->GetListFiles().end());
+ }
+ // Sort the list of input files and remove duplicates.
+ std::sort(listFiles.begin(), listFiles.end(),
+ std::less<std::string>());
+ std::vector<std::string>::iterator new_end =
+ std::unique(listFiles.begin(), listFiles.end());
+ listFiles.erase(new_end, listFiles.end());
+
+ // Create a rule to re-run CMake.
+ std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
+ stampName += "generate.stamp";
+ const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND");
+ cmCustomCommandLine commandLine;
+ commandLine.push_back(dsprule);
+ std::string argH = "-H";
+ argH += lg->Convert(mf->GetHomeDirectory(),
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED, true);
+ commandLine.push_back(argH);
+ std::string argB = "-B";
+ argB += lg->Convert(mf->GetHomeOutputDirectory(),
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED, true);
+ commandLine.push_back(argB);
+ commandLine.push_back("--check-stamp-list");
+ commandLine.push_back(stampList.c_str());
+ commandLine.push_back("--vs-solution-file");
+ commandLine.push_back("\"$(SolutionPath)\"");
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+
+ // Add the rule. Note that we cannot use the CMakeLists.txt
+ // file as the main dependency because it would get
+ // overwritten by the CreateVCProjBuildRule.
+ // (this could be avoided with per-target source files)
+ std::string no_main_dependency = "";
+ if(cmSourceFile* file =
+ mf->AddCustomCommandToOutput(
+ stamps, listFiles,
+ no_main_dependency, commandLines, "Checking Build System",
+ no_working_directory, true))
+ {
+ tgt->AddSource(file->GetFullPath());
+ }
+ else
+ {
+ cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
+ }
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio8Generator::Generate()
+{
+ 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)
+ {
+ if(ti->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
+ {
+ ti->second->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
+ }
+ }
+ }
+
+ // Now perform the main generation.
+ this->cmGlobalVisualStudio7Generator::Generate();
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalVisualStudio8Generator
+::WriteSolutionConfigurations(std::ostream& fout)
+{
+ fout << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
+ for(std::vector<std::string>::iterator i = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ fout << "\t\t" << *i << "|" << this->GetPlatformName()
+ << " = " << *i << "|" << this->GetPlatformName() << "\n";
+ }
+ fout << "\tEndGlobalSection\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalVisualStudio8Generator
+::WriteProjectConfigurations(
+ std::ostream& fout, const std::string& name, cmTarget::TargetType type,
+ const std::set<std::string>& configsPartOfDefaultBuild,
+ std::string const& platformMapping)
+{
+ std::string guid = this->GetGUID(name);
+ for(std::vector<std::string>::iterator i = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ fout << "\t\t{" << guid << "}." << *i
+ << "|" << this->GetPlatformName() << ".ActiveCfg = " << *i << "|"
+ << (!platformMapping.empty()?
+ platformMapping : this->GetPlatformName())
+ << "\n";
+ std::set<std::string>::const_iterator
+ ci = configsPartOfDefaultBuild.find(*i);
+ if(!(ci == configsPartOfDefaultBuild.end()))
+ {
+ fout << "\t\t{" << guid << "}." << *i
+ << "|" << this->GetPlatformName() << ".Build.0 = " << *i << "|"
+ << (!platformMapping.empty()?
+ platformMapping : this->GetPlatformName())
+ << "\n";
+ }
+ if(this->NeedsDeploy(type))
+ {
+ fout << "\t\t{" << guid << "}." << *i
+ << "|" << this->GetPlatformName() << ".Deploy.0 = " << *i << "|"
+ << (!platformMapping.empty()?
+ platformMapping : this->GetPlatformName())
+ << "\n";
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudio8Generator::NeedsDeploy(cmTarget::TargetType type) const
+{
+ bool needsDeploy = (type == cmTarget::EXECUTABLE ||
+ type == cmTarget::SHARED_LIBRARY);
+ return this->TargetsWindowsCE() && needsDeploy;
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio8Generator::ComputeTargetDepends()
+{
+ // Skip over the cmGlobalVisualStudioGenerator implementation!
+ // We do not need the support that VS <= 7.1 needs.
+ return this->cmGlobalGenerator::ComputeTargetDepends();
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio8Generator::WriteProjectDepends(
+ std::ostream& fout, const std::string&, const char*, cmTarget const& t)
+{
+ TargetDependSet const& unordered = this->GetTargetDirectDepends(t);
+ OrderedTargetDependSet depends(unordered);
+ for(OrderedTargetDependSet::const_iterator i = depends.begin();
+ i != depends.end(); ++i)
+ {
+ if((*i)->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ std::string guid = this->GetGUID((*i)->GetName().c_str());
+ fout << "\t\t{" << guid << "} = {" << guid << "}\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies(
+ cmTarget& target)
+{
+ // Look for utility dependencies that magically link.
+ for(std::set<std::string>::const_iterator ui =
+ target.GetUtilities().begin();
+ ui != target.GetUtilities().end(); ++ui)
+ {
+ if(cmTarget* depTarget = this->FindTarget(ui->c_str()))
+ {
+ if(depTarget->GetType() != cmTarget::INTERFACE_LIBRARY
+ && depTarget->GetProperty("EXTERNAL_MSPROJECT"))
+ {
+ // This utility dependency names an external .vcproj target.
+ // We use LinkLibraryDependencies="true" to link to it without
+ // predicting the .lib file location or name.
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+static cmVS7FlagTable cmVS8ExtraFlagTable[] =
+{
+ {"CallingConvention", "Gd", "cdecl", "0", 0 },
+ {"CallingConvention", "Gr", "fastcall", "1", 0 },
+ {"CallingConvention", "Gz", "stdcall", "2", 0 },
+
+ {"Detect64BitPortabilityProblems", "Wp64",
+ "Detect 64Bit Portability Problems", "true", 0 },
+ {"ErrorReporting", "errorReport:prompt", "Report immediately", "1", 0 },
+ {"ErrorReporting", "errorReport:queue", "Queue for next login", "2", 0 },
+ // Precompiled header and related options. Note that the
+ // UsePrecompiledHeader entries are marked as "Continue" so that the
+ // corresponding PrecompiledHeaderThrough entry can be found.
+ {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "2",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
+ cmVS7FlagTable::UserValueRequired},
+ // There is no YX option in the VS8 IDE.
+
+ // Exception handling mode. If no entries match, it will be FALSE.
+ {"ExceptionHandling", "GX", "enable c++ exceptions", "1", 0},
+ {"ExceptionHandling", "EHsc", "enable c++ exceptions", "1", 0},
+ {"ExceptionHandling", "EHa", "enable SEH exceptions", "2", 0},
+
+ {"EnablePREfast", "analyze", "", "true", 0},
+ {"EnablePREfast", "analyze-", "", "false", 0},
+
+ // Language options
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t",
+ "wchar_t is a built-in type", "true", 0},
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t-",
+ "wchar_t is not a built-in type", "false", 0},
+
+ {0,0,0,0,0}
+};
+cmIDEFlagTable const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
+{
+ return cmVS8ExtraFlagTable;
+}
diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h
new file mode 100644
index 0000000000..4b41ed7d66
--- /dev/null
+++ b/Source/cmGlobalVisualStudio8Generator.h
@@ -0,0 +1,104 @@
+/*============================================================================
+ 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 cmGlobalVisualStudio8Generator_h
+#define cmGlobalVisualStudio8Generator_h
+
+#include "cmGlobalVisualStudio71Generator.h"
+
+
+/** \class cmGlobalVisualStudio8Generator
+ * \brief Write a Unix makefiles.
+ *
+ * cmGlobalVisualStudio8Generator manages UNIX build process for a tree
+ */
+class cmGlobalVisualStudio8Generator : public cmGlobalVisualStudio71Generator
+{
+public:
+ cmGlobalVisualStudio8Generator(const std::string& name,
+ const std::string& platformName);
+ static cmGlobalGeneratorFactory* NewFactory();
+
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {return this->Name;}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+ virtual void AddPlatformDefinitions(cmMakefile* mf);
+
+ virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
+
+ /**
+ * Override Configure and Generate to add the build-system check
+ * target.
+ */
+ virtual void Configure();
+
+ /**
+ * Where does this version of Visual Studio look for macros for the
+ * current user? Returns the empty string if this version of Visual
+ * Studio does not implement support for VB macros.
+ */
+ virtual std::string GetUserMacrosDirectory();
+
+ /**
+ * What is the reg key path to "vsmacros" for this version of Visual
+ * Studio?
+ */
+ virtual std::string GetUserMacrosRegKeyBase();
+
+ /** Return true if the target project file should have the option
+ LinkLibraryDependencies and link to .sln dependencies. */
+ virtual bool NeedLinkLibraryDependencies(cmTarget& target);
+
+ /** Return true if building for Windows CE */
+ virtual bool TargetsWindowsCE() const {
+ return !this->WindowsCEVersion.empty(); }
+
+protected:
+ virtual void Generate();
+ virtual const char* GetIDEVersion() { return "8.0"; }
+
+ virtual std::string FindDevEnvCommand();
+
+ virtual bool VSLinksDependencies() const { return false; }
+
+ bool AddCheckTarget();
+
+ /** Return true if the configuration needs to be deployed */
+ virtual bool NeedsDeploy(cmTarget::TargetType type) const;
+
+ static cmIDEFlagTable const* GetExtraFlagTableVS8();
+ virtual void WriteSLNHeader(std::ostream& fout);
+ virtual void WriteSolutionConfigurations(std::ostream& fout);
+ virtual void WriteProjectConfigurations(
+ std::ostream& fout, const std::string& name, cmTarget::TargetType type,
+ 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);
+
+ std::string Name;
+ std::string WindowsCEVersion;
+
+private:
+ class Factory;
+ friend class Factory;
+};
+#endif
diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx
new file mode 100644
index 0000000000..1d73b5c08e
--- /dev/null
+++ b/Source/cmGlobalVisualStudio9Generator.cxx
@@ -0,0 +1,154 @@
+/*============================================================================
+ 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 "windows.h" // this must be first to define GetCurrentDirectory
+#include "cmGlobalVisualStudio9Generator.h"
+#include "cmLocalVisualStudio7Generator.h"
+#include "cmMakefile.h"
+#include "cmVisualStudioWCEPlatformParser.h"
+#include "cmake.h"
+
+static const char vs9generatorName[] = "Visual Studio 9 2008";
+
+class cmGlobalVisualStudio9Generator::Factory
+ : public cmGlobalGeneratorFactory
+{
+public:
+ virtual cmGlobalGenerator* CreateGlobalGenerator(
+ const std::string& name) const {
+ if(strncmp(name.c_str(), vs9generatorName,
+ sizeof(vs9generatorName) - 1) != 0)
+ {
+ return 0;
+ }
+
+ const char* p = name.c_str() + sizeof(vs9generatorName) - 1;
+ if(p[0] == '\0')
+ {
+ return new cmGlobalVisualStudio9Generator(
+ name, "");
+ }
+
+ if(p[0] != ' ')
+ {
+ return 0;
+ }
+
+ ++p;
+
+ if(!strcmp(p, "IA64"))
+ {
+ return new cmGlobalVisualStudio9Generator(
+ name, "Itanium");
+ }
+
+ if(!strcmp(p, "Win64"))
+ {
+ return new cmGlobalVisualStudio9Generator(
+ name, "x64");
+ }
+
+ cmVisualStudioWCEPlatformParser parser(p);
+ parser.ParseVersion("9.0");
+ if (!parser.Found())
+ {
+ return 0;
+ }
+
+ cmGlobalVisualStudio9Generator* ret = new cmGlobalVisualStudio9Generator(
+ name, p);
+ ret->WindowsCEVersion = parser.GetOSVersion();
+ return ret;
+ }
+
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const {
+ entry.Name = vs9generatorName;
+ entry.Brief = "Generates Visual Studio 9 2008 project files.";
+ }
+
+ virtual void GetGenerators(std::vector<std::string>& names) const {
+ names.push_back(vs9generatorName);
+ names.push_back(vs9generatorName + std::string(" Win64"));
+ names.push_back(vs9generatorName + std::string(" IA64"));
+ cmVisualStudioWCEPlatformParser parser;
+ parser.ParseVersion("9.0");
+ const std::vector<std::string>& availablePlatforms =
+ parser.GetAvailablePlatforms();
+ for(std::vector<std::string>::const_iterator i =
+ availablePlatforms.begin(); i != availablePlatforms.end(); ++i)
+ {
+ names.push_back("Visual Studio 9 2008 " + *i);
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+cmGlobalGeneratorFactory* cmGlobalVisualStudio9Generator::NewFactory()
+{
+ return new Factory;
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudio9Generator::cmGlobalVisualStudio9Generator(
+ const std::string& name, const std::string& platformName)
+ : cmGlobalVisualStudio8Generator(name, platformName)
+{
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudio9Generator::WriteSLNHeader(std::ostream& fout)
+{
+ fout << "Microsoft Visual Studio Solution File, Format Version 10.00\n";
+ fout << "# Visual Studio 2008\n";
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalVisualStudio9Generator::CreateLocalGenerator()
+{
+ cmLocalVisualStudio7Generator *lg
+ = new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS9);
+ lg->SetExtraFlagTable(this->GetExtraFlagTableVS8());
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio9Generator::GetUserMacrosDirectory()
+{
+ std::string base;
+ std::string path;
+
+ // base begins with the VisualStudioProjectsLocation reg value...
+ if (cmSystemTools::ReadRegistryValue(
+ "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\9.0;"
+ "VisualStudioProjectsLocation",
+ base))
+ {
+ cmSystemTools::ConvertToUnixSlashes(base);
+
+ // 9.0 macros folder:
+ path = base + "/VSMacros80";
+ // *NOT* a typo; right now in Visual Studio 2008 beta the macros
+ // folder is VSMacros80... They may change it to 90 before final
+ // release of 2008 or they may not... we'll have to keep our eyes
+ // on it
+ }
+
+ // path is (correctly) still empty if we did not read the base value from
+ // the Registry value
+ return path;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio9Generator::GetUserMacrosRegKeyBase()
+{
+ return "Software\\Microsoft\\VisualStudio\\9.0\\vsmacros";
+}
diff --git a/Source/cmGlobalVisualStudio9Generator.h b/Source/cmGlobalVisualStudio9Generator.h
new file mode 100644
index 0000000000..0a191cde44
--- /dev/null
+++ b/Source/cmGlobalVisualStudio9Generator.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 cmGlobalVisualStudio9Generator_h
+#define cmGlobalVisualStudio9Generator_h
+
+#include "cmGlobalVisualStudio8Generator.h"
+
+
+/** \class cmGlobalVisualStudio9Generator
+ * \brief Write a Unix makefiles.
+ *
+ * cmGlobalVisualStudio9Generator manages UNIX build process for a tree
+ */
+class cmGlobalVisualStudio9Generator :
+ public cmGlobalVisualStudio8Generator
+{
+public:
+ cmGlobalVisualStudio9Generator(const std::string& name,
+ const std::string& platformName);
+ static cmGlobalGeneratorFactory* NewFactory();
+
+ ///! create the correct local generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void WriteSLNHeader(std::ostream& fout);
+
+ /**
+ * Where does this version of Visual Studio look for macros for the
+ * current user? Returns the empty string if this version of Visual
+ * Studio does not implement support for VB macros.
+ */
+ virtual std::string GetUserMacrosDirectory();
+
+ /**
+ * What is the reg key path to "vsmacros" for this version of Visual
+ * Studio?
+ */
+ virtual std::string GetUserMacrosRegKeyBase();
+protected:
+ virtual const char* GetIDEVersion() { return "9.0"; }
+private:
+ class Factory;
+ friend class Factory;
+};
+#endif
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
new file mode 100644
index 0000000000..2dab23c1b2
--- /dev/null
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -0,0 +1,881 @@
+
+/*============================================================================
+ 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 "cmGlobalVisualStudioGenerator.h"
+
+#include "cmCallVisualStudioMacro.h"
+#include "cmGeneratorTarget.h"
+#include "cmLocalVisualStudioGenerator.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmTarget.h"
+#include <cmsys/Encoding.hxx>
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudioGenerator::~cmGlobalVisualStudioGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudioGenerator::GetRegistryBase()
+{
+ return cmGlobalVisualStudioGenerator::GetRegistryBase(
+ this->GetIDEVersion());
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudioGenerator::GetRegistryBase(
+ const char* version)
+{
+ std::string key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\";
+ return key + version;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudioGenerator::Generate()
+{
+ // Add a special target that depends on ALL projects for easy build
+ // of one configuration only.
+ const char* no_working_dir = 0;
+ std::vector<std::string> no_depends;
+ cmCustomCommandLines no_commands;
+ std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
+ for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
+ {
+ std::vector<cmLocalGenerator*>& gen = it->second;
+ // add the ALL_BUILD to the first local generator of each project
+ if(gen.size())
+ {
+ // Use no actual command lines so that the target itself is not
+ // considered always out of date.
+ cmTarget* allBuild =
+ gen[0]->GetMakefile()->
+ AddUtilityCommand("ALL_BUILD", true, no_working_dir,
+ no_depends, no_commands, false,
+ "Build all projects");
+
+#if 0
+ // Can't activate this code because we want ALL_BUILD
+ // selected as the default "startup project" when first
+ // opened in Visual Studio... And if it's nested in a
+ // folder, then that doesn't happen.
+ //
+ // Organize in the "predefined targets" folder:
+ //
+ if (this->UseFolderProperty())
+ {
+ allBuild->SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
+ }
+#endif
+
+ // Now make all targets depend on the ALL_BUILD target
+ for(std::vector<cmLocalGenerator*>::iterator i = gen.begin();
+ i != gen.end(); ++i)
+ {
+ cmTargets& targets = (*i)->GetMakefile()->GetTargets();
+ for(cmTargets::iterator t = targets.begin();
+ t != targets.end(); ++t)
+ {
+ if(!this->IsExcluded(gen[0], t->second))
+ {
+ allBuild->AddUtility(t->second.GetName());
+ }
+ }
+ }
+ }
+ }
+
+ // Configure CMake Visual Studio macros, for this user on this version
+ // of Visual Studio.
+ this->ConfigureCMakeVisualStudioMacros();
+
+ // Add CMakeLists.txt with custom command to rerun CMake.
+ for(std::vector<cmLocalGenerator*>::const_iterator
+ lgi = this->LocalGenerators.begin();
+ lgi != this->LocalGenerators.end(); ++lgi)
+ {
+ cmLocalVisualStudioGenerator* lg =
+ static_cast<cmLocalVisualStudioGenerator*>(*lgi);
+ lg->AddCMakeListsRules();
+ }
+
+ // Run all the local generators.
+ this->cmGlobalGenerator::Generate();
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudioGenerator
+::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const
+{
+ std::string dir = gt->Makefile->GetCurrentOutputDirectory();
+ dir += "/";
+ std::string tgtDir = gt->LocalGenerator->GetTargetDirectory(*gt->Target);
+ if(!tgtDir.empty())
+ {
+ dir += tgtDir;
+ dir += "/";
+ }
+ const char* cd = this->GetCMakeCFGIntDir();
+ if(cd && *cd)
+ {
+ dir += cd;
+ dir += "/";
+ }
+ gt->ObjectDirectory = dir;
+}
+
+//----------------------------------------------------------------------------
+bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
+ const std::string& regKeyBase,
+ std::string& nextAvailableSubKeyName);
+
+void RegisterVisualStudioMacros(const std::string& macrosFile,
+ const std::string& regKeyBase);
+
+//----------------------------------------------------------------------------
+#define CMAKE_VSMACROS_FILENAME \
+ "CMakeVSMacros2.vsmacros"
+
+#define CMAKE_VSMACROS_RELOAD_MACRONAME \
+ "Macros.CMakeVSMacros2.Macros.ReloadProjects"
+
+#define CMAKE_VSMACROS_STOP_MACRONAME \
+ "Macros.CMakeVSMacros2.Macros.StopBuild"
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
+{
+ cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
+ std::string dir = this->GetUserMacrosDirectory();
+
+ if (mf != 0 && dir != "")
+ {
+ std::string src = mf->GetRequiredDefinition("CMAKE_ROOT");
+ src += "/Templates/" CMAKE_VSMACROS_FILENAME;
+
+ std::string dst = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
+
+ // Copy the macros file to the user directory only if the
+ // destination does not exist or the source location is newer.
+ // This will allow the user to edit the macros for development
+ // purposes but newer versions distributed with CMake will replace
+ // older versions in user directories.
+ int res;
+ if(!cmSystemTools::FileTimeCompare(src.c_str(), dst.c_str(), &res) ||
+ res > 0)
+ {
+ if (!cmSystemTools::CopyFileAlways(src.c_str(), dst.c_str()))
+ {
+ std::ostringstream oss;
+ oss << "Could not copy from: " << src << std::endl;
+ oss << " to: " << dst << std::endl;
+ cmSystemTools::Message(oss.str().c_str(), "Warning");
+ }
+ }
+
+ RegisterVisualStudioMacros(dst, this->GetUserMacrosRegKeyBase());
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalVisualStudioGenerator
+::CallVisualStudioMacro(MacroName m,
+ const char* vsSolutionFile)
+{
+ // If any solution or project files changed during the generation,
+ // tell Visual Studio to reload them...
+ cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
+ std::string dir = this->GetUserMacrosDirectory();
+
+ // Only really try to call the macro if:
+ // - mf is non-NULL
+ // - there is a UserMacrosDirectory
+ // - the CMake vsmacros file exists
+ // - the CMake vsmacros file is registered
+ // - there were .sln/.vcproj files changed during generation
+ //
+ if (mf != 0 && dir != "")
+ {
+ std::string macrosFile = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
+ std::string nextSubkeyName;
+ if (cmSystemTools::FileExists(macrosFile.c_str()) &&
+ IsVisualStudioMacrosFileRegistered(macrosFile,
+ this->GetUserMacrosRegKeyBase(), nextSubkeyName)
+ )
+ {
+ std::string topLevelSlnName;
+ if(vsSolutionFile)
+ {
+ topLevelSlnName = vsSolutionFile;
+ }
+ else
+ {
+ topLevelSlnName = mf->GetStartOutputDirectory();
+ topLevelSlnName += "/";
+ topLevelSlnName += mf->GetProjectName();
+ topLevelSlnName += ".sln";
+ }
+
+ if(m == MacroReload)
+ {
+ std::vector<std::string> filenames;
+ this->GetFilesReplacedDuringGenerate(filenames);
+ if (filenames.size() > 0)
+ {
+ // Convert vector to semi-colon delimited string of filenames:
+ std::string projects;
+ std::vector<std::string>::iterator it = filenames.begin();
+ if (it != filenames.end())
+ {
+ projects = *it;
+ ++it;
+ }
+ for (; it != filenames.end(); ++it)
+ {
+ projects += ";";
+ projects += *it;
+ }
+ cmCallVisualStudioMacro::CallMacro(topLevelSlnName,
+ CMAKE_VSMACROS_RELOAD_MACRONAME, projects,
+ this->GetCMakeInstance()->GetDebugOutput());
+ }
+ }
+ else if(m == MacroStop)
+ {
+ cmCallVisualStudioMacro::CallMacro(topLevelSlnName,
+ CMAKE_VSMACROS_STOP_MACRONAME, "",
+ this->GetCMakeInstance()->GetDebugOutput());
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudioGenerator::GetUserMacrosDirectory()
+{
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudioGenerator::GetUserMacrosRegKeyBase()
+{
+ return "";
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudioGenerator::FillLinkClosure(cmTarget const* target,
+ TargetSet& linked)
+{
+ if(linked.insert(target).second)
+ {
+ TargetDependSet const& depends = this->GetTargetDirectDepends(*target);
+ for(TargetDependSet::const_iterator di = depends.begin();
+ di != depends.end(); ++di)
+ {
+ if(di->IsLink())
+ {
+ this->FillLinkClosure(*di, linked);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudioGenerator::TargetSet const&
+cmGlobalVisualStudioGenerator::GetTargetLinkClosure(cmTarget* target)
+{
+ TargetSetMap::iterator i = this->TargetLinkClosure.find(target);
+ if(i == this->TargetLinkClosure.end())
+ {
+ TargetSetMap::value_type entry(target, TargetSet());
+ i = this->TargetLinkClosure.insert(entry).first;
+ this->FillLinkClosure(target, i->second);
+ }
+ return i->second;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudioGenerator::FollowLinkDepends(
+ cmTarget const* target, std::set<cmTarget const*>& linked)
+{
+ if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ return;
+ }
+ if(linked.insert(target).second &&
+ target->GetType() == cmTarget::STATIC_LIBRARY)
+ {
+ // Static library targets do not list their link dependencies so
+ // we must follow them transitively now.
+ TargetDependSet const& depends = this->GetTargetDirectDepends(*target);
+ for(TargetDependSet::const_iterator di = depends.begin();
+ di != depends.end(); ++di)
+ {
+ if(di->IsLink())
+ {
+ this->FollowLinkDepends(*di, linked);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudioGenerator::ComputeTargetDepends()
+{
+ if(!this->cmGlobalGenerator::ComputeTargetDepends())
+ {
+ return false;
+ }
+ std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
+ for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
+ {
+ std::vector<cmLocalGenerator*>& gen = it->second;
+ for(std::vector<cmLocalGenerator*>::iterator i = gen.begin();
+ i != gen.end(); ++i)
+ {
+ cmTargets& targets = (*i)->GetMakefile()->GetTargets();
+ for(cmTargets::iterator ti = targets.begin();
+ ti != targets.end(); ++ti)
+ {
+ this->ComputeVSTargetDepends(ti->second);
+ }
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+static bool VSLinkable(cmTarget const* t)
+{
+ return t->IsLinkable() || t->GetType() == cmTarget::OBJECT_LIBRARY;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(cmTarget& target)
+{
+ if(this->VSTargetDepends.find(&target) != this->VSTargetDepends.end())
+ {
+ return;
+ }
+ 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
+ // library cause that library to be linked. We use an intermedite
+ // empty utility target to express the dependency. (VS 8 and above
+ // provide a project file "LinkLibraryDependencies" setting to
+ // choose whether to activate this behavior. We disable it except
+ // when linking external project files.)
+ //
+ // (2) We cannot let static libraries depend directly on targets to
+ // which they "link" because the librarian tool will copy the
+ // targets into the static library. While the work-around for
+ // behavior (1) would also avoid this, it would create a large
+ // number of extra utility targets for little gain. Instead, use
+ // the above work-around only for dependencies explicitly added by
+ // the add_dependencies() command. Approximate link dependencies by
+ // 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);
+
+ 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)
+ {
+ for(TargetDependSet::const_iterator di = depends.begin();
+ di != depends.end(); ++di)
+ {
+ cmTargetDepend dep = *di;
+ if(dep.IsLink())
+ {
+ this->FollowLinkDepends(dep, linkDepends);
+ }
+ }
+ }
+
+ // Collect explicit util dependencies (add_dependencies).
+ std::set<cmTarget const*> utilDepends;
+ for(TargetDependSet::const_iterator di = depends.begin();
+ di != depends.end(); ++di)
+ {
+ cmTargetDepend dep = *di;
+ if(dep.IsUtil())
+ {
+ this->FollowLinkDepends(dep, utilDepends);
+ }
+ }
+
+ // Collect all targets linked by this target so we can avoid
+ // intermediate targets below.
+ TargetSet linked;
+ if(target.GetType() != cmTarget::STATIC_LIBRARY)
+ {
+ linked = this->GetTargetLinkClosure(&target);
+ }
+
+ // Emit link dependencies.
+ for(std::set<cmTarget const*>::iterator di = linkDepends.begin();
+ di != linkDepends.end(); ++di)
+ {
+ cmTarget const* dep = *di;
+ vsTargetDepend.insert(dep->GetName());
+ }
+
+ // Emit util dependencies. Possibly use intermediate targets.
+ for(std::set<cmTarget const*>::iterator di = utilDepends.begin();
+ di != utilDepends.end(); ++di)
+ {
+ cmTarget const* dep = *di;
+ if(allowLinkable || !VSLinkable(dep) || linked.count(dep))
+ {
+ // Direct dependency allowed.
+ vsTargetDepend.insert(dep->GetName());
+ }
+ else
+ {
+ // Direct dependency on linkable target not allowed.
+ // Use an intermediate utility target.
+ vsTargetDepend.insert(this->GetUtilityDepend(dep));
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudioGenerator::FindMakeProgram(cmMakefile* mf)
+{
+ // Visual Studio generators know how to lookup their build tool
+ // directly instead of needing a helper module to do it, so we
+ // do not actually need to put CMAKE_MAKE_PROGRAM into the cache.
+ if(cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
+ {
+ mf->AddDefinition("CMAKE_MAKE_PROGRAM",
+ this->GetVSMakeProgram().c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalVisualStudioGenerator::GetUtilityDepend(cmTarget const* target)
+{
+ UtilityDependsMap::iterator i = this->UtilityDepends.find(target);
+ if(i == this->UtilityDepends.end())
+ {
+ std::string name = this->WriteUtilityDepend(target);
+ UtilityDependsMap::value_type entry(target, name);
+ i = this->UtilityDepends.insert(entry).first;
+ }
+ return i->second;
+}
+
+//----------------------------------------------------------------------------
+#include <windows.h>
+
+//----------------------------------------------------------------------------
+bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
+ const std::string& regKeyBase,
+ std::string& nextAvailableSubKeyName)
+{
+ bool macrosRegistered = false;
+
+ std::string s1;
+ std::string s2;
+
+ // Make lowercase local copies, convert to Unix slashes, and
+ // see if the resulting strings are the same:
+ s1 = cmSystemTools::LowerCase(macrosFile);
+ cmSystemTools::ConvertToUnixSlashes(s1);
+
+ std::string keyname;
+ HKEY hkey = NULL;
+ LONG result = ERROR_SUCCESS;
+ DWORD index = 0;
+
+ keyname = regKeyBase + "\\OtherProjects7";
+ hkey = NULL;
+ result = RegOpenKeyExW(HKEY_CURRENT_USER,
+ cmsys::Encoding::ToWide(keyname).c_str(),
+ 0, KEY_READ, &hkey);
+ if (ERROR_SUCCESS == result)
+ {
+ // Iterate the subkeys and look for the values of interest in each subkey:
+ wchar_t subkeyname[256];
+ DWORD cch_subkeyname = sizeof(subkeyname)*sizeof(subkeyname[0]);
+ wchar_t keyclass[256];
+ DWORD cch_keyclass = sizeof(keyclass)*sizeof(keyclass[0]);
+ FILETIME lastWriteTime;
+ lastWriteTime.dwHighDateTime = 0;
+ lastWriteTime.dwLowDateTime = 0;
+
+ while (ERROR_SUCCESS == RegEnumKeyExW(hkey, index, subkeyname,
+ &cch_subkeyname,
+ 0, keyclass, &cch_keyclass, &lastWriteTime))
+ {
+ // Open the subkey and query the values of interest:
+ HKEY hsubkey = NULL;
+ result = RegOpenKeyExW(hkey, subkeyname, 0, KEY_READ, &hsubkey);
+ if (ERROR_SUCCESS == result)
+ {
+ DWORD valueType = REG_SZ;
+ wchar_t data1[256];
+ DWORD cch_data1 = sizeof(data1)*sizeof(data1[0]);
+ RegQueryValueExW(hsubkey, L"Path", 0, &valueType,
+ (LPBYTE) &data1[0], &cch_data1);
+
+ DWORD data2 = 0;
+ DWORD cch_data2 = sizeof(data2);
+ RegQueryValueExW(hsubkey, L"Security", 0, &valueType,
+ (LPBYTE) &data2, &cch_data2);
+
+ DWORD data3 = 0;
+ DWORD cch_data3 = sizeof(data3);
+ RegQueryValueExW(hsubkey, L"StorageFormat", 0, &valueType,
+ (LPBYTE) &data3, &cch_data3);
+
+ s2 = cmSystemTools::LowerCase(cmsys::Encoding::ToNarrow(data1));
+ cmSystemTools::ConvertToUnixSlashes(s2);
+ if (s2 == s1)
+ {
+ macrosRegistered = true;
+ }
+
+ std::string fullname = cmsys::Encoding::ToNarrow(data1);
+ std::string filename;
+ std::string filepath;
+ std::string filepathname;
+ std::string filepathpath;
+ if (cmSystemTools::FileExists(fullname.c_str()))
+ {
+ filename = cmSystemTools::GetFilenameName(fullname);
+ filepath = cmSystemTools::GetFilenamePath(fullname);
+ filepathname = cmSystemTools::GetFilenameName(filepath);
+ filepathpath = cmSystemTools::GetFilenamePath(filepath);
+ }
+
+ //std::cout << keyname << "\\" << subkeyname << ":" << std::endl;
+ //std::cout << " Path: " << data1 << std::endl;
+ //std::cout << " Security: " << data2 << std::endl;
+ //std::cout << " StorageFormat: " << data3 << std::endl;
+ //std::cout << " filename: " << filename << std::endl;
+ //std::cout << " filepath: " << filepath << std::endl;
+ //std::cout << " filepathname: " << filepathname << std::endl;
+ //std::cout << " filepathpath: " << filepathpath << std::endl;
+ //std::cout << std::endl;
+
+ RegCloseKey(hsubkey);
+ }
+ else
+ {
+ std::cout << "error opening subkey: " << subkeyname << std::endl;
+ std::cout << std::endl;
+ }
+
+ ++index;
+ cch_subkeyname = sizeof(subkeyname)*sizeof(subkeyname[0]);
+ cch_keyclass = sizeof(keyclass)*sizeof(keyclass[0]);
+ lastWriteTime.dwHighDateTime = 0;
+ lastWriteTime.dwLowDateTime = 0;
+ }
+
+ RegCloseKey(hkey);
+ }
+ else
+ {
+ std::cout << "error opening key: " << keyname << std::endl;
+ std::cout << std::endl;
+ }
+
+
+ // Pass back next available sub key name, assuming sub keys always
+ // follow the expected naming scheme. Expected naming scheme is that
+ // the subkeys of OtherProjects7 is 0 to n-1, so it's ok to use "n"
+ // as the name of the next subkey.
+ std::ostringstream ossNext;
+ ossNext << index;
+ nextAvailableSubKeyName = ossNext.str();
+
+
+ keyname = regKeyBase + "\\RecordingProject7";
+ hkey = NULL;
+ result = RegOpenKeyExW(HKEY_CURRENT_USER,
+ cmsys::Encoding::ToWide(keyname).c_str(),
+ 0, KEY_READ, &hkey);
+ if (ERROR_SUCCESS == result)
+ {
+ DWORD valueType = REG_SZ;
+ wchar_t data1[256];
+ DWORD cch_data1 = sizeof(data1)*sizeof(data1[0]);
+ RegQueryValueExW(hkey, L"Path", 0, &valueType,
+ (LPBYTE) &data1[0], &cch_data1);
+
+ DWORD data2 = 0;
+ DWORD cch_data2 = sizeof(data2);
+ RegQueryValueExW(hkey, L"Security", 0, &valueType,
+ (LPBYTE) &data2, &cch_data2);
+
+ DWORD data3 = 0;
+ DWORD cch_data3 = sizeof(data3);
+ RegQueryValueExW(hkey, L"StorageFormat", 0, &valueType,
+ (LPBYTE) &data3, &cch_data3);
+
+ s2 = cmSystemTools::LowerCase(cmsys::Encoding::ToNarrow(data1));
+ cmSystemTools::ConvertToUnixSlashes(s2);
+ if (s2 == s1)
+ {
+ macrosRegistered = true;
+ }
+
+ //std::cout << keyname << ":" << std::endl;
+ //std::cout << " Path: " << data1 << std::endl;
+ //std::cout << " Security: " << data2 << std::endl;
+ //std::cout << " StorageFormat: " << data3 << std::endl;
+ //std::cout << std::endl;
+
+ RegCloseKey(hkey);
+ }
+ else
+ {
+ std::cout << "error opening key: " << keyname << std::endl;
+ std::cout << std::endl;
+ }
+
+ return macrosRegistered;
+}
+
+//----------------------------------------------------------------------------
+void WriteVSMacrosFileRegistryEntry(
+ const std::string& nextAvailableSubKeyName,
+ const std::string& macrosFile,
+ const std::string& regKeyBase)
+{
+ std::string keyname = regKeyBase + "\\OtherProjects7";
+ HKEY hkey = NULL;
+ LONG result = RegOpenKeyExW(HKEY_CURRENT_USER,
+ cmsys::Encoding::ToWide(keyname).c_str(), 0,
+ KEY_READ|KEY_WRITE, &hkey);
+ if (ERROR_SUCCESS == result)
+ {
+ // Create the subkey and set the values of interest:
+ HKEY hsubkey = NULL;
+ wchar_t lpClass[] = L"";
+ result = RegCreateKeyExW(hkey,
+ cmsys::Encoding::ToWide(nextAvailableSubKeyName).c_str(), 0,
+ lpClass, 0, KEY_READ|KEY_WRITE, 0, &hsubkey, 0);
+ if (ERROR_SUCCESS == result)
+ {
+ DWORD dw = 0;
+
+ std::string s(macrosFile);
+ cmSystemTools::ReplaceString(s, "/", "\\");
+ std::wstring ws = cmsys::Encoding::ToWide(s);
+
+ result = RegSetValueExW(hsubkey, L"Path", 0, REG_SZ, (LPBYTE)ws.c_str(),
+ static_cast<DWORD>(ws.size() + 1)*sizeof(wchar_t));
+ if (ERROR_SUCCESS != result)
+ {
+ std::cout << "error result 1: " << result << std::endl;
+ std::cout << std::endl;
+ }
+
+ // Security value is always "1" for sample macros files (seems to be "2"
+ // if you put the file somewhere outside the standard VSMacros folder)
+ dw = 1;
+ result = RegSetValueExW(hsubkey, L"Security",
+ 0, REG_DWORD, (LPBYTE) &dw, sizeof(DWORD));
+ if (ERROR_SUCCESS != result)
+ {
+ std::cout << "error result 2: " << result << std::endl;
+ std::cout << std::endl;
+ }
+
+ // StorageFormat value is always "0" for sample macros files
+ dw = 0;
+ result = RegSetValueExW(hsubkey, L"StorageFormat",
+ 0, REG_DWORD, (LPBYTE) &dw, sizeof(DWORD));
+ if (ERROR_SUCCESS != result)
+ {
+ std::cout << "error result 3: " << result << std::endl;
+ std::cout << std::endl;
+ }
+
+ RegCloseKey(hsubkey);
+ }
+ else
+ {
+ std::cout << "error creating subkey: "
+ << nextAvailableSubKeyName << std::endl;
+ std::cout << std::endl;
+ }
+ RegCloseKey(hkey);
+ }
+ else
+ {
+ std::cout << "error opening key: " << keyname << std::endl;
+ std::cout << std::endl;
+ }
+}
+
+//----------------------------------------------------------------------------
+void RegisterVisualStudioMacros(const std::string& macrosFile,
+ const std::string& regKeyBase)
+{
+ bool macrosRegistered;
+ std::string nextAvailableSubKeyName;
+
+ macrosRegistered = IsVisualStudioMacrosFileRegistered(macrosFile,
+ regKeyBase, nextAvailableSubKeyName);
+
+ if (!macrosRegistered)
+ {
+ int count = cmCallVisualStudioMacro::
+ GetNumberOfRunningVisualStudioInstances("ALL");
+
+ // Only register the macros file if there are *no* instances of Visual
+ // Studio running. If we register it while one is running, first, it has
+ // no effect on the running instance; second, and worse, Visual Studio
+ // removes our newly added registration entry when it quits. Instead,
+ // emit a warning asking the user to exit all running Visual Studio
+ // instances...
+ //
+ if (0 != count)
+ {
+ std::ostringstream oss;
+ oss << "Could not register CMake's Visual Studio macros file '"
+ << CMAKE_VSMACROS_FILENAME "' while Visual Studio is running."
+ << " Please exit all running instances of Visual Studio before"
+ << " continuing." << std::endl
+ << std::endl
+ << "CMake needs to register Visual Studio macros when its macros"
+ << " file is updated or when it detects that its current macros file"
+ << " is no longer registered with Visual Studio."
+ << std::endl;
+ cmSystemTools::Message(oss.str().c_str(), "Warning");
+
+ // Count them again now that the warning is over. In the case of a GUI
+ // warning, the user may have gone to close Visual Studio and then come
+ // back to the CMake GUI and clicked ok on the above warning. If so,
+ // then register the macros *now* if the count is *now* 0...
+ //
+ count = cmCallVisualStudioMacro::
+ GetNumberOfRunningVisualStudioInstances("ALL");
+
+ // Also re-get the nextAvailableSubKeyName in case Visual Studio
+ // wrote out new registered macros information as it was exiting:
+ //
+ if (0 == count)
+ {
+ IsVisualStudioMacrosFileRegistered(macrosFile, regKeyBase,
+ nextAvailableSubKeyName);
+ }
+ }
+
+ // Do another if check - 'count' may have changed inside the above if:
+ //
+ if (0 == count)
+ {
+ WriteVSMacrosFileRegistryEntry(nextAvailableSubKeyName, macrosFile,
+ regKeyBase);
+ }
+ }
+}
+bool
+cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmTarget const& target)
+{
+ // check to see if this is a fortran build
+ std::set<std::string> languages;
+ {
+ // Issue diagnostic if the source files depend on the config.
+ std::vector<cmSourceFile*> sources;
+ if (!target.GetConfigCommonSourceFiles(sources))
+ {
+ return false;
+ }
+ }
+ target.GetLanguages(languages, "");
+ if(languages.size() == 1)
+ {
+ if(*languages.begin() == "Fortran")
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudioGenerator::TargetCompare
+::operator()(cmTarget const* l, cmTarget const* r) const
+{
+ // Make sure ALL_BUILD is first so it is the default active project.
+ if(r->GetName() == "ALL_BUILD")
+ {
+ return false;
+ }
+ if(l->GetName() == "ALL_BUILD")
+ {
+ return true;
+ }
+ return strcmp(l->GetName().c_str(), r->GetName().c_str()) < 0;
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudioGenerator::OrderedTargetDependSet
+::OrderedTargetDependSet(TargetDependSet const& targets)
+{
+ for(TargetDependSet::const_iterator ti =
+ targets.begin(); ti != targets.end(); ++ti)
+ {
+ this->insert(*ti);
+ }
+}
+
+//----------------------------------------------------------------------------
+cmGlobalVisualStudioGenerator::OrderedTargetDependSet
+::OrderedTargetDependSet(TargetSet const& targets)
+{
+ for(TargetSet::const_iterator ti = targets.begin();
+ ti != targets.end(); ++ti)
+ {
+ this->insert(*ti);
+ }
+}
+
+std::string cmGlobalVisualStudioGenerator::ExpandCFGIntDir(
+ const std::string& str,
+ const std::string& config) const
+{
+ std::string replace = GetCMakeCFGIntDir();
+
+ std::string tmp = str;
+ for(std::string::size_type i = tmp.find(replace);
+ i != std::string::npos;
+ i = tmp.find(replace, i))
+ {
+ tmp.replace(i, replace.size(), config);
+ i += config.size();
+ }
+ return tmp;
+}
diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h
new file mode 100644
index 0000000000..356f4d4181
--- /dev/null
+++ b/Source/cmGlobalVisualStudioGenerator.h
@@ -0,0 +1,135 @@
+/*============================================================================
+ 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 cmGlobalVisualStudioGenerator_h
+#define cmGlobalVisualStudioGenerator_h
+
+#include "cmGlobalGenerator.h"
+
+/** \class cmGlobalVisualStudioGenerator
+ * \brief Base class for global Visual Studio generators.
+ *
+ * cmGlobalVisualStudioGenerator provides functionality common to all
+ * global Visual Studio generators.
+ */
+class cmGlobalVisualStudioGenerator : public cmGlobalGenerator
+{
+public:
+ cmGlobalVisualStudioGenerator();
+ virtual ~cmGlobalVisualStudioGenerator();
+
+ /**
+ * Configure CMake's Visual Studio macros file into the user's Visual
+ * Studio macros directory.
+ */
+ virtual void ConfigureCMakeVisualStudioMacros();
+
+ /**
+ * Where does this version of Visual Studio look for macros for the
+ * current user? Returns the empty string if this version of Visual
+ * Studio does not implement support for VB macros.
+ */
+ virtual std::string GetUserMacrosDirectory();
+
+ /**
+ * What is the reg key path to "vsmacros" for this version of Visual
+ * Studio?
+ */
+ virtual std::string GetUserMacrosRegKeyBase();
+
+ enum MacroName {MacroReload, MacroStop};
+
+ /**
+ * Call the ReloadProjects macro if necessary based on
+ * GetFilesReplacedDuringGenerate results.
+ */
+ virtual void CallVisualStudioMacro(MacroName m,
+ const char* vsSolutionFile = 0);
+
+ // return true if target is fortran only
+ bool TargetIsFortranOnly(cmTarget const& t);
+
+ /** Get the top-level registry key for this VS version. */
+ std::string GetRegistryBase();
+
+ /** Get the top-level registry key for the given VS version. */
+ static std::string GetRegistryBase(const char* version);
+
+ /** Return true if the generated build tree may contain multiple builds.
+ i.e. "Can I build Debug and Release in the same tree?" */
+ virtual bool IsMultiConfig() { return true; }
+
+ /** Return true if building for Windows CE */
+ virtual bool TargetsWindowsCE() const { return false; }
+
+ class TargetSet: public std::set<cmTarget const*> {};
+ struct TargetCompare
+ {
+ bool operator()(cmTarget const* l, cmTarget const* r) const;
+ };
+ class OrderedTargetDependSet;
+
+ virtual void FindMakeProgram(cmMakefile*);
+
+
+ virtual std::string ExpandCFGIntDir(const std::string& str,
+ const std::string& config) const;
+
+ void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
+protected:
+ virtual void Generate();
+
+ // Does this VS version link targets to each other if there are
+ // dependencies in the SLN file? This was done for VS versions
+ // below 8.
+ virtual bool VSLinksDependencies() const { return true; }
+
+ virtual const char* GetIDEVersion() = 0;
+
+ virtual bool ComputeTargetDepends();
+ class VSDependSet: public std::set<std::string> {};
+ class VSDependMap: public std::map<cmTarget 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;
+ UtilityDependsMap UtilityDepends;
+
+private:
+ virtual std::string GetVSMakeProgram() = 0;
+ void PrintCompilerAdvice(std::ostream&, std::string const&,
+ const char*) const {}
+
+ void FollowLinkDepends(cmTarget const* target,
+ std::set<cmTarget const*>& linked);
+
+ class TargetSetMap: public std::map<cmTarget*, TargetSet> {};
+ TargetSetMap TargetLinkClosure;
+ void FillLinkClosure(cmTarget const* target, TargetSet& linked);
+ TargetSet const& GetTargetLinkClosure(cmTarget* target);
+};
+
+class cmGlobalVisualStudioGenerator::OrderedTargetDependSet:
+ public std::multiset<cmTargetDepend,
+ cmGlobalVisualStudioGenerator::TargetCompare>
+{
+public:
+ typedef cmGlobalGenerator::TargetDependSet TargetDependSet;
+ typedef cmGlobalVisualStudioGenerator::TargetSet TargetSet;
+ OrderedTargetDependSet(TargetDependSet const&);
+ OrderedTargetDependSet(TargetSet const&);
+};
+
+#endif
diff --git a/Source/cmGlobalWatcomWMakeGenerator.cxx b/Source/cmGlobalWatcomWMakeGenerator.cxx
new file mode 100644
index 0000000000..e44ed79341
--- /dev/null
+++ b/Source/cmGlobalWatcomWMakeGenerator.cxx
@@ -0,0 +1,67 @@
+/*============================================================================
+ 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 "cmGlobalWatcomWMakeGenerator.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+
+cmGlobalWatcomWMakeGenerator::cmGlobalWatcomWMakeGenerator()
+{
+ this->FindMakeProgramFile = "CMakeFindWMake.cmake";
+#ifdef _WIN32
+ this->ForceUnixPaths = false;
+#endif
+ this->ToolSupportsColor = true;
+ this->NeedSymbolicMark = true;
+ this->EmptyRuleHackCommand = "@cd .";
+}
+
+void cmGlobalWatcomWMakeGenerator
+::EnableLanguage(std::vector<std::string>const& l,
+ cmMakefile *mf,
+ bool optional)
+{
+ // pick a default
+ mf->AddDefinition("WATCOM", "1");
+ mf->AddDefinition("CMAKE_QUOTE_INCLUDE_PATHS", "1");
+ mf->AddDefinition("CMAKE_MANGLE_OBJECT_FILE_NAMES", "1");
+ mf->AddDefinition("CMAKE_MAKE_LINE_CONTINUE", "&");
+ mf->AddDefinition("CMAKE_MAKE_SYMBOLIC_RULE", ".SYMBOLIC");
+ mf->AddDefinition("CMAKE_GENERATOR_CC", "wcl386");
+ mf->AddDefinition("CMAKE_GENERATOR_CXX", "wcl386");
+ this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
+}
+
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalWatcomWMakeGenerator::CreateLocalGenerator()
+{
+ cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
+ lg->SetDefineWindowsNULL(true);
+#ifdef _WIN32
+ lg->SetWindowsShell(true);
+#endif
+ lg->SetWatcomWMake(true);
+ lg->SetMakeSilentFlag("-h");
+ lg->SetGlobalGenerator(this);
+ lg->SetIgnoreLibPrefix(true);
+ lg->SetPassMakeflags(false);
+ lg->SetUnixCD(false);
+ lg->SetIncludeDirective("!include");
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalWatcomWMakeGenerator
+::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalWatcomWMakeGenerator::GetActualName();
+ entry.Brief = "Generates Watcom WMake makefiles.";
+}
diff --git a/Source/cmGlobalWatcomWMakeGenerator.h b/Source/cmGlobalWatcomWMakeGenerator.h
new file mode 100644
index 0000000000..0e577b5d62
--- /dev/null
+++ b/Source/cmGlobalWatcomWMakeGenerator.h
@@ -0,0 +1,50 @@
+/*============================================================================
+ 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 cmGlobalWatcomWMakeGenerator_h
+#define cmGlobalWatcomWMakeGenerator_h
+
+#include "cmGlobalUnixMakefileGenerator3.h"
+
+/** \class cmGlobalWatcomWMakeGenerator
+ * \brief Write a NMake makefiles.
+ *
+ * cmGlobalWatcomWMakeGenerator manages nmake build process for a tree
+ */
+class cmGlobalWatcomWMakeGenerator : public cmGlobalUnixMakefileGenerator3
+{
+public:
+ cmGlobalWatcomWMakeGenerator();
+ static cmGlobalGeneratorFactory* NewFactory() {
+ return new cmGlobalGeneratorSimpleFactory
+ <cmGlobalWatcomWMakeGenerator>(); }
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalWatcomWMakeGenerator::GetActualName();}
+ static std::string GetActualName() {return "Watcom WMake";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+
+ virtual bool AllowNotParallel() const { return false; }
+};
+
+#endif
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
new file mode 100644
index 0000000000..13e6988581
--- /dev/null
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -0,0 +1,3998 @@
+/*============================================================================
+ 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 "cmGlobalXCodeGenerator.h"
+#include "cmLocalXCodeGenerator.h"
+#include "cmMakefile.h"
+#include "cmXCodeObject.h"
+#include "cmXCode21Object.h"
+#include "cmake.h"
+#include "cmGeneratedFileStream.h"
+#include "cmComputeLinkInformation.h"
+#include "cmSourceFile.h"
+#include "cmCustomCommandGenerator.h"
+#include "cmGeneratorTarget.h"
+#include "cmGlobalGeneratorFactory.h"
+
+#include <cmsys/auto_ptr.hxx>
+
+//----------------------------------------------------------------------------
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+#include "cmXMLParser.h"
+
+// parse the xml file storing the installed version of Xcode on
+// the machine
+class cmXcodeVersionParser : public cmXMLParser
+{
+public:
+ cmXcodeVersionParser(): Version("1.5") {}
+ void StartElement(const std::string&, const char**)
+ {
+ this->Data = "";
+ }
+ void EndElement(const std::string& name)
+ {
+ if(name == "key")
+ {
+ this->Key = this->Data;
+ }
+ else if(name == "string")
+ {
+ if(this->Key == "CFBundleShortVersionString")
+ {
+ this->Version = this->Data;
+ }
+ }
+ }
+ void CharacterDataHandler(const char* data, int length)
+ {
+ this->Data.append(data, length);
+ }
+ std::string Version;
+ std::string Key;
+ std::string Data;
+};
+#endif
+
+// Builds either an object list or a space-separated string from the
+// given inputs.
+class cmGlobalXCodeGenerator::BuildObjectListOrString
+{
+ cmGlobalXCodeGenerator *Generator;
+ cmXCodeObject *Group;
+ bool Empty;
+ std::string String;
+
+public:
+ BuildObjectListOrString(cmGlobalXCodeGenerator *gen, bool buildObjectList)
+ : Generator(gen), Group(0), Empty(true)
+ {
+ if (buildObjectList)
+ {
+ this->Group = this->Generator->CreateObject(cmXCodeObject::OBJECT_LIST);
+ }
+ }
+
+ bool IsEmpty() const { return this->Empty; }
+
+ void Add(const char *newString)
+ {
+ this->Empty = false;
+
+ if (this->Group)
+ {
+ this->Group->AddObject(this->Generator->CreateString(newString));
+ }
+ else
+ {
+ this->String += newString;
+ this->String += ' ';
+ }
+ }
+
+ const std::string &GetString() const { return this->String; }
+
+ cmXCodeObject *CreateList()
+ {
+ if (this->Group)
+ {
+ return this->Group;
+ }
+ else
+ {
+ return this->Generator->CreateString(this->String.c_str());
+ }
+ }
+};
+
+class cmGlobalXCodeGenerator::Factory : public cmGlobalGeneratorFactory
+{
+public:
+ virtual cmGlobalGenerator* CreateGlobalGenerator(
+ const std::string& name) const;
+
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const {
+ cmGlobalXCodeGenerator::GetDocumentation(entry); }
+
+ virtual void GetGenerators(std::vector<std::string>& names) const {
+ names.push_back(cmGlobalXCodeGenerator::GetActualName()); }
+};
+
+//----------------------------------------------------------------------------
+cmGlobalXCodeGenerator::cmGlobalXCodeGenerator(std::string const& version)
+{
+ this->VersionString = version;
+
+ // Compute an integer form of the version number.
+ unsigned int v[2] = {0,0};
+ sscanf(this->VersionString.c_str(), "%u.%u", &v[0], &v[1]);
+ this->XcodeVersion = 10*v[0] + v[1];
+
+ this->FindMakeProgramFile = "CMakeFindXCode.cmake";
+ this->RootObject = 0;
+ this->MainGroupChildren = 0;
+ this->SourcesGroupChildren = 0;
+ this->ResourcesGroupChildren = 0;
+ this->CurrentMakefile = 0;
+ this->CurrentLocalGenerator = 0;
+}
+
+//----------------------------------------------------------------------------
+cmGlobalGeneratorFactory* cmGlobalXCodeGenerator::NewFactory()
+{
+ return new Factory;
+}
+
+//----------------------------------------------------------------------------
+cmGlobalGenerator* cmGlobalXCodeGenerator::Factory
+::CreateGlobalGenerator(const std::string& name) const
+{
+ if (name != GetActualName())
+ return 0;
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ cmXcodeVersionParser parser;
+ std::string versionFile;
+ {
+ std::string out;
+ std::string::size_type pos;
+ if(cmSystemTools::RunSingleCommand("xcode-select --print-path", &out, 0, 0,
+ cmSystemTools::OUTPUT_NONE) &&
+ (pos = out.find(".app/"), pos != out.npos))
+ {
+ versionFile = out.substr(0, pos+5)+"Contents/version.plist";
+ }
+ }
+ if(!versionFile.empty() && cmSystemTools::FileExists(versionFile.c_str()))
+ {
+ parser.ParseFile(versionFile.c_str());
+ }
+ else if (cmSystemTools::FileExists(
+ "/Applications/Xcode.app/Contents/version.plist"))
+ {
+ parser.ParseFile
+ ("/Applications/Xcode.app/Contents/version.plist");
+ }
+ else
+ {
+ parser.ParseFile
+ ("/Developer/Applications/Xcode.app/Contents/version.plist");
+ }
+ cmsys::auto_ptr<cmGlobalXCodeGenerator>
+ gg(new cmGlobalXCodeGenerator(parser.Version));
+ if (gg->XcodeVersion == 20)
+ {
+ cmSystemTools::Message("Xcode 2.0 not really supported by cmake, "
+ "using Xcode 15 generator\n");
+ gg->XcodeVersion = 15;
+ }
+ return gg.release();
+#else
+ std::cerr << "CMake should be built with cmake to use Xcode, "
+ "default to Xcode 1.5\n";
+ return new cmGlobalXCodeGenerator;
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts,
+ cmMakefile* mf)
+{
+ if(this->XcodeVersion >= 30)
+ {
+ this->GeneratorToolset = ts;
+ if(!this->GeneratorToolset.empty())
+ {
+ mf->AddDefinition("CMAKE_XCODE_PLATFORM_TOOLSET",
+ this->GeneratorToolset.c_str());
+ }
+ return true;
+ }
+ else
+ {
+ return cmGlobalGenerator::SetGeneratorToolset(ts, mf);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
+ lang,
+ cmMakefile * mf, bool optional)
+{
+ mf->AddDefinition("XCODE","1");
+ mf->AddDefinition("XCODE_VERSION", this->VersionString.c_str());
+ if(this->XcodeVersion == 15)
+ {
+ }
+ else
+ {
+ if(!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
+ {
+ mf->AddCacheDefinition(
+ "CMAKE_CONFIGURATION_TYPES",
+ "Debug;Release;MinSizeRel;RelWithDebInfo",
+ "Semicolon separated list of supported configuration types, "
+ "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
+ "anything else will be ignored.",
+ cmCacheManager::STRING);
+ }
+ }
+ mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
+ this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
+ const char* osxArch =
+ mf->GetDefinition("CMAKE_OSX_ARCHITECTURES");
+ const char* sysroot =
+ mf->GetDefinition("CMAKE_OSX_SYSROOT");
+ if(osxArch && sysroot)
+ {
+ this->Architectures.clear();
+ cmSystemTools::ExpandListArgument(std::string(osxArch),
+ this->Architectures);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalXCodeGenerator::GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& /*projectDir*/,
+ const std::string& targetName,
+ const std::string& config,
+ bool /*fast*/,
+ std::vector<std::string> const& makeOptions)
+{
+ // now build the test
+ makeCommand.push_back(
+ this->SelectMakeProgram(makeProgram, "xcodebuild")
+ );
+
+ makeCommand.push_back("-project");
+ std::string projectArg = projectName;
+ projectArg += ".xcode";
+ if(this->XcodeVersion > 20)
+ {
+ projectArg += "proj";
+ }
+ makeCommand.push_back(projectArg);
+
+ bool clean = false;
+ std::string realTarget = targetName;
+ if ( realTarget == "clean" )
+ {
+ clean = true;
+ realTarget = "ALL_BUILD";
+ }
+ if(clean)
+ {
+ makeCommand.push_back("clean");
+ }
+ else
+ {
+ makeCommand.push_back("build");
+ }
+ makeCommand.push_back("-target");
+ if (!realTarget.empty())
+ {
+ makeCommand.push_back(realTarget);
+ }
+ else
+ {
+ makeCommand.push_back("ALL_BUILD");
+ }
+ if(this->XcodeVersion == 15)
+ {
+ makeCommand.push_back("-buildstyle");
+ makeCommand.push_back("Development");
+ }
+ else
+ {
+ makeCommand.push_back("-configuration");
+ makeCommand.push_back(!config.empty()?config:"Debug");
+ }
+ makeCommand.insert(makeCommand.end(),
+ makeOptions.begin(), makeOptions.end());
+}
+
+//----------------------------------------------------------------------------
+///! Create a local generator appropriate to this Global Generator
+cmLocalGenerator *cmGlobalXCodeGenerator::CreateLocalGenerator()
+{
+ cmLocalGenerator *lg = new cmLocalXCodeGenerator;
+ lg->SetGlobalGenerator(this);
+ return lg;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::Generate()
+{
+ 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
+ for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
+ {
+ cmLocalGenerator* root = it->second[0];
+ this->SetGenerationRoot(root);
+ // add ALL_BUILD, INSTALL, etc
+ this->AddExtraTargets(root, it->second);
+ }
+ this->cmGlobalGenerator::Generate();
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ return;
+ }
+ for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
+ {
+ cmLocalGenerator* root = it->second[0];
+ this->SetGenerationRoot(root);
+ // now create the project
+ this->OutputXCodeProject(root, it->second);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::SetGenerationRoot(cmLocalGenerator* root)
+{
+ this->CurrentProject = root->GetMakefile()->GetProjectName();
+ this->SetCurrentLocalGenerator(root);
+ cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentDirectory(),
+ this->ProjectSourceDirectoryComponents);
+ cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentOutputDirectory(),
+ this->ProjectOutputDirectoryComponents);
+
+ this->CurrentXCodeHackMakefile =
+ root->GetMakefile()->GetCurrentOutputDirectory();
+ this->CurrentXCodeHackMakefile += "/CMakeScripts";
+ cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile.c_str());
+ this->CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make";
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalXCodeGenerator::PostBuildMakeTarget(std::string const& tName,
+ std::string const& configName)
+{
+ std::string target = tName;
+ cmSystemTools::ReplaceString(target, " ", "_");
+ std::string out = "PostBuild." + target;
+ if(this->XcodeVersion > 20)
+ {
+ out += "." + configName;
+ }
+ return out;
+}
+
+//----------------------------------------------------------------------------
+#define CMAKE_CHECK_BUILD_SYSTEM_TARGET "ZERO_CHECK"
+
+//----------------------------------------------------------------------------
+void
+cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& gens)
+{
+ cmMakefile* mf = root->GetMakefile();
+
+ // Add ALL_BUILD
+ const char* no_working_directory = 0;
+ std::vector<std::string> no_depends;
+ mf->AddUtilityCommand("ALL_BUILD", true, no_depends,
+ no_working_directory,
+ "echo", "Build all projects");
+ cmTarget* allbuild = mf->FindTarget("ALL_BUILD");
+
+ // Refer to the main build configuration file for easy editing.
+ std::string listfile = mf->GetStartDirectory();
+ listfile += "/";
+ listfile += "CMakeLists.txt";
+ allbuild->AddSourceCMP0049(listfile.c_str());
+
+ // Add XCODE depend helper
+ std::string dir = mf->GetCurrentOutputDirectory();
+ cmCustomCommandLine makeHelper;
+ if(this->XcodeVersion < 50)
+ {
+ makeHelper.push_back("make");
+ makeHelper.push_back("-C");
+ makeHelper.push_back(dir.c_str());
+ makeHelper.push_back("-f");
+ makeHelper.push_back(this->CurrentXCodeHackMakefile.c_str());
+ makeHelper.push_back(""); // placeholder, see below
+ }
+
+ // Add ZERO_CHECK
+ bool regenerate = !mf->IsOn("CMAKE_SUPPRESS_REGENERATION");
+ if (regenerate)
+ {
+ this->CreateReRunCMakeFile(root, gens);
+ std::string file = this->ConvertToRelativeForMake(
+ this->CurrentReRunCMakeMakefile.c_str());
+ cmSystemTools::ReplaceString(file, "\\ ", " ");
+ mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, true, no_depends,
+ no_working_directory,
+ "make", "-f", file.c_str());
+ }
+
+ // now make the allbuild depend on all the non-utility targets
+ // in the project
+ for(std::vector<cmLocalGenerator*>::iterator i = gens.begin();
+ i != gens.end(); ++i)
+ {
+ cmLocalGenerator* lg = *i;
+ if(this->IsExcluded(root, *i))
+ {
+ continue;
+ }
+
+ cmTargets& tgts = lg->GetMakefile()->GetTargets();
+ for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
+ {
+ cmTarget& target = l->second;
+
+ if (regenerate && (l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET))
+ {
+ target.AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
+ }
+
+ // make all exe, shared libs and modules
+ // run the depend check makefile as a post build rule
+ // this will make sure that when the next target is built
+ // things are up-to-date
+ if(!makeHelper.empty() &&
+ (target.GetType() == cmTarget::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))
+ {
+ makeHelper[makeHelper.size()-1] = // fill placeholder
+ this->PostBuildMakeTarget(target.GetName(), "$(CONFIGURATION)");
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(makeHelper);
+ lg->GetMakefile()->AddCustomCommandToTarget(target.GetName(),
+ no_depends,
+ commandLines,
+ cmTarget::POST_BUILD,
+ "Depend check for xcode",
+ dir.c_str());
+ }
+
+ if(target.GetType() != cmTarget::INTERFACE_LIBRARY
+ && !target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+ {
+ allbuild->AddUtility(target.GetName());
+ }
+
+ // Refer to the build configuration file for easy editing.
+ listfile = lg->GetMakefile()->GetStartDirectory();
+ listfile += "/";
+ listfile += "CMakeLists.txt";
+ target.AddSourceCMP0049(listfile.c_str());
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+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)
+ {
+ std::vector<std::string> const& lf = (*gi)->GetMakefile()->GetListFiles();
+ lfiles.insert(lfiles.end(), lf.begin(), lf.end());
+ }
+
+ // sort the array
+ std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
+ std::vector<std::string>::iterator new_end =
+ std::unique(lfiles.begin(), lfiles.end());
+ lfiles.erase(new_end, lfiles.end());
+ this->CurrentReRunCMakeMakefile = mf->GetStartOutputDirectory();
+ this->CurrentReRunCMakeMakefile += "/CMakeScripts";
+ cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile.c_str());
+ this->CurrentReRunCMakeMakefile += "/ReRunCMake.make";
+ cmGeneratedFileStream makefileStream
+ (this->CurrentReRunCMakeMakefile.c_str());
+ makefileStream.SetCopyIfDifferent(true);
+ makefileStream << "# Generated by CMake, DO NOT EDIT\n";
+ std::string checkCache = mf->GetHomeOutputDirectory();
+ checkCache += "/";
+ checkCache += cmake::GetCMakeFilesDirectoryPostSlash();
+ checkCache += "cmake.check_cache";
+ makefileStream << this->ConvertToRelativeForMake(checkCache.c_str())
+ << ": ";
+ for(std::vector<std::string>::const_iterator i = lfiles.begin();
+ i != lfiles.end(); ++i)
+ {
+ makefileStream << "\\\n" << this->ConvertToRelativeForMake(i->c_str());
+ }
+ std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
+ makefileStream << "\n\t" << this->ConvertToRelativeForMake(cmake.c_str())
+ << " -H" << this->ConvertToRelativeForMake(
+ mf->GetHomeDirectory())
+ << " -B" << this->ConvertToRelativeForMake(
+ mf->GetHomeOutputDirectory()) << "\n";
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::ClearXCodeObjects()
+{
+ this->TargetDoneSet.clear();
+ for(unsigned int i = 0; i < this->XCodeObjects.size(); ++i)
+ {
+ delete this->XCodeObjects[i];
+ }
+ this->XCodeObjects.clear();
+ this->XCodeObjectIDs.clear();
+ this->GroupMap.clear();
+ this->GroupNameMap.clear();
+ this->TargetGroup.clear();
+ this->FileRefs.clear();
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::addObject(cmXCodeObject *obj)
+{
+ if(obj->GetType() == cmXCodeObject::OBJECT)
+ {
+ std::string id = obj->GetId();
+
+ // If this is a duplicate id, it's an error:
+ //
+ if(this->XCodeObjectIDs.count(id))
+ {
+ cmSystemTools::Error(
+ "Xcode generator: duplicate object ids not allowed");
+ }
+
+ this->XCodeObjectIDs.insert(id);
+ }
+
+ this->XCodeObjects.push_back(obj);
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
+{
+ cmXCodeObject* obj;
+ if(this->XcodeVersion == 15)
+ {
+ obj = new cmXCodeObject(ptype, cmXCodeObject::OBJECT);
+ }
+ else
+ {
+ obj = new cmXCode21Object(ptype, cmXCodeObject::OBJECT);
+ }
+ this->addObject(obj);
+ return obj;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
+{
+ cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
+ this->addObject(obj);
+ return obj;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateString(const std::string& s)
+{
+ cmXCodeObject* obj = this->CreateObject(cmXCodeObject::STRING);
+ obj->SetString(s);
+ return obj;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject* cmGlobalXCodeGenerator
+::CreateObjectReference(cmXCodeObject* ref)
+{
+ cmXCodeObject* obj = this->CreateObject(cmXCodeObject::OBJECT_REF);
+ obj->SetObject(ref);
+ return obj;
+}
+
+//----------------------------------------------------------------------------
+std::string
+GetGroupMapKeyFromPath(cmTarget& cmtarget, const std::string& fullpath)
+{
+ std::string key(cmtarget.GetName());
+ key += "-";
+ key += fullpath;
+ return key;
+}
+
+//----------------------------------------------------------------------------
+std::string
+GetGroupMapKey(cmTarget& cmtarget, cmSourceFile* sf)
+{
+ return GetGroupMapKeyFromPath(cmtarget, sf->GetFullPath());
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath(
+ const std::string &fullpath,
+ cmTarget& cmtarget,
+ const std::string &lang,
+ cmSourceFile* sf)
+{
+ // Using a map and the full path guarantees that we will always get the same
+ // fileRef object for any given full path.
+ //
+ cmXCodeObject* fileRef =
+ this->CreateXCodeFileReferenceFromPath(fullpath, cmtarget, lang, sf);
+
+ cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
+ buildFile->SetComment(fileRef->GetComment());
+ buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
+
+ return buildFile;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
+ cmSourceFile* sf,
+ cmTarget& cmtarget)
+{
+ // Add flags from target and source file properties.
+ std::string flags;
+ const char* srcfmt = sf->GetProperty("Fortran_FORMAT");
+ switch(this->CurrentLocalGenerator->GetFortranFormat(srcfmt))
+ {
+ case cmLocalGenerator::FortranFormatFixed: flags="-fixed "+flags; break;
+ case cmLocalGenerator::FortranFormatFree: flags="-free "+flags; break;
+ default: break;
+ }
+ lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
+
+ // Add per-source definitions.
+ BuildObjectListOrString flagsBuild(this, false);
+ this->AppendDefines(flagsBuild,
+ sf->GetProperty("COMPILE_DEFINITIONS"), true);
+ if (!flagsBuild.IsEmpty())
+ {
+ if (flags.size())
+ {
+ flags += ' ';
+ }
+ flags += flagsBuild.GetString();
+ }
+
+ std::string lang =
+ this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
+
+ cmXCodeObject* buildFile =
+ this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), cmtarget, lang, sf);
+ cmXCodeObject* fileRef = buildFile->GetObject("fileRef")->GetObject();
+
+ cmXCodeObject* settings =
+ this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str()));
+
+ // Is this a resource file in this target? Add it to the resources group...
+ //
+ cmGeneratorTarget::SourceFileFlags tsFlags =
+ this->GetGeneratorTarget(&cmtarget)->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(tsFlags.Type == cmGeneratorTarget::SourceFileTypePrivateHeader)
+ {
+ cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ attrs->AddObject(this->CreateString("Private"));
+ settings->AddAttribute("ATTRIBUTES", attrs);
+ isResource = true;
+ }
+ else if(tsFlags.Type == cmGeneratorTarget::SourceFileTypePublicHeader)
+ {
+ cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ attrs->AddObject(this->CreateString("Public"));
+ settings->AddAttribute("ATTRIBUTES", attrs);
+ isResource = true;
+ }
+ }
+
+ // Add the fileRef to the top level Resources group/folder if it is not
+ // already there.
+ //
+ if(isResource && this->ResourcesGroupChildren &&
+ !this->ResourcesGroupChildren->HasObject(fileRef))
+ {
+ this->ResourcesGroupChildren->AddObject(fileRef);
+ }
+
+ buildFile->AddAttribute("settings", settings);
+ return buildFile;
+}
+
+//----------------------------------------------------------------------------
+std::string
+GetSourcecodeValueFromFileExtension(const std::string& _ext,
+ const std::string& lang,
+ bool& keepLastKnownFileType)
+{
+ std::string ext = cmSystemTools::LowerCase(_ext);
+ std::string sourcecode = "sourcecode";
+
+ if(ext == "o")
+ {
+ sourcecode = "compiled.mach-o.objfile";
+ }
+ else if(ext == "xib")
+ {
+ keepLastKnownFileType = true;
+ sourcecode = "file.xib";
+ }
+ else if(ext == "storyboard")
+ {
+ keepLastKnownFileType = true;
+ sourcecode = "file.storyboard";
+ }
+ else if(ext == "mm")
+ {
+ sourcecode += ".cpp.objcpp";
+ }
+ else if(ext == "m")
+ {
+ sourcecode += ".c.objc";
+ }
+ else if(ext == "plist")
+ {
+ sourcecode += ".text.plist";
+ }
+ else if(ext == "h")
+ {
+ sourcecode += ".c.h";
+ }
+ else if(ext == "hxx" || ext == "hpp" || ext == "txx"
+ || ext == "pch" || ext == "hh")
+ {
+ sourcecode += ".cpp.h";
+ }
+ else if(ext == "png" || ext == "gif" || ext == "jpg")
+ {
+ keepLastKnownFileType = true;
+ sourcecode = "image";
+ }
+ else if(ext == "txt")
+ {
+ sourcecode += ".text";
+ }
+ else if(lang == "CXX")
+ {
+ sourcecode += ".cpp.cpp";
+ }
+ else if(lang == "C")
+ {
+ sourcecode += ".c.c";
+ }
+ else if(lang == "Fortran")
+ {
+ sourcecode += ".fortran.f90";
+ }
+ else if(lang == "ASM")
+ {
+ sourcecode += ".asm";
+ }
+ //else
+ // {
+ // // Already specialized above or we leave sourcecode == "sourcecode"
+ // // which is probably the most correct choice. Extensionless headers,
+ // // for example... Or file types unknown to Xcode that do not map to a
+ // // valid explicitFileType value.
+ // }
+
+ return sourcecode;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
+ const std::string &fullpath,
+ cmTarget& cmtarget,
+ const std::string &lang,
+ cmSourceFile* sf)
+{
+ std::string key = GetGroupMapKeyFromPath(cmtarget, fullpath);
+ cmXCodeObject* fileRef = this->FileRefs[key];
+ if(!fileRef)
+ {
+ fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
+ fileRef->SetComment(fullpath);
+ this->FileRefs[key] = fileRef;
+ }
+ cmXCodeObject* group = this->GroupMap[key];
+ cmXCodeObject* children = group->GetObject("children");
+ if (!children->HasObject(fileRef))
+ {
+ children->AddObject(fileRef);
+ }
+ fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
+
+ bool useLastKnownFileType = false;
+ std::string fileType;
+ if(sf)
+ {
+ if(const char* e = sf->GetProperty("XCODE_EXPLICIT_FILE_TYPE"))
+ {
+ fileType = e;
+ }
+ else if(const char* l = sf->GetProperty("XCODE_LAST_KNOWN_FILE_TYPE"))
+ {
+ useLastKnownFileType = true;
+ fileType = l;
+ }
+ }
+ if(fileType.empty())
+ {
+ // Compute the extension without leading '.'.
+ std::string ext = cmSystemTools::GetFilenameLastExtension(fullpath);
+ if(!ext.empty())
+ {
+ ext = ext.substr(1);
+ }
+
+ // If fullpath references a directory, then we need to specify
+ // lastKnownFileType as folder in order for Xcode to be able to
+ // open the contents of the folder.
+ // (Xcode 4.6 does not like explicitFileType=folder).
+ if(cmSystemTools::FileIsDirectory(fullpath.c_str()))
+ {
+ fileType = (ext == "xcassets"? "folder.assetcatalog" : "folder");
+ useLastKnownFileType = true;
+ }
+ else
+ {
+ fileType = GetSourcecodeValueFromFileExtension(
+ ext, lang, useLastKnownFileType);
+ }
+ }
+
+ fileRef->AddAttribute(useLastKnownFileType? "lastKnownFileType"
+ : "explicitFileType",
+ this->CreateString(fileType));
+
+ // Store the file path relative to the top of the source tree.
+ std::string path = this->RelativeToSource(fullpath.c_str());
+ std::string name = cmSystemTools::GetFilenameName(path.c_str());
+ const char* sourceTree = (cmSystemTools::FileIsFullPath(path.c_str())?
+ "<absolute>" : "SOURCE_ROOT");
+ fileRef->AddAttribute("name", this->CreateString(name.c_str()));
+ fileRef->AddAttribute("path", this->CreateString(path.c_str()));
+ fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree));
+ if(this->XcodeVersion == 15)
+ {
+ fileRef->AddAttribute("refType", this->CreateString("4"));
+ }
+ return fileRef;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf,
+ cmTarget& cmtarget)
+{
+ std::string lang =
+ this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
+
+ return this->CreateXCodeFileReferenceFromPath(
+ sf->GetFullPath(), cmtarget, lang, sf);
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalXCodeGenerator::SpecialTargetEmitted(std::string const& tname)
+{
+ if(tname == "ALL_BUILD" || tname == "XCODE_DEPEND_HELPER" ||
+ tname == "install" || tname == "package" || tname == "RUN_TESTS" ||
+ tname == CMAKE_CHECK_BUILD_SYSTEM_TARGET )
+ {
+ if(this->TargetDoneSet.find(tname) != this->TargetDoneSet.end())
+ {
+ return true;
+ }
+ this->TargetDoneSet.insert(tname);
+ return false;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::SetCurrentLocalGenerator(cmLocalGenerator* gen)
+{
+ this->CurrentLocalGenerator = gen;
+ this->CurrentMakefile = gen->GetMakefile();
+ std::string outdir =
+ cmSystemTools::CollapseFullPath(this->CurrentMakefile->
+ GetCurrentOutputDirectory());
+ cmSystemTools::SplitPath(outdir.c_str(),
+ this->CurrentOutputDirectoryComponents);
+
+ // Select the current set of configuration types.
+ this->CurrentConfigurationTypes.clear();
+ this->CurrentMakefile->GetConfigurations(this->CurrentConfigurationTypes);
+ if(this->CurrentConfigurationTypes.empty())
+ {
+ this->CurrentConfigurationTypes.push_back("");
+ }
+}
+
+//----------------------------------------------------------------------------
+struct cmSourceFilePathCompare
+{
+ bool operator()(cmSourceFile* l, cmSourceFile* r)
+ {
+ return l->GetFullPath() < r->GetFullPath();
+ }
+};
+
+//----------------------------------------------------------------------------
+void
+cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
+ std::vector<cmXCodeObject*>&
+ targets)
+{
+ this->SetCurrentLocalGenerator(gen);
+ cmTargets &tgts = this->CurrentMakefile->GetTargets();
+ for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
+ {
+ cmTarget& cmtarget = l->second;
+ cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget);
+
+ // make sure ALL_BUILD, INSTALL, etc are only done once
+ if(this->SpecialTargetEmitted(l->first.c_str()))
+ {
+ continue;
+ }
+
+ if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+
+ if(cmtarget.GetType() == cmTarget::UTILITY ||
+ cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
+ {
+ targets.push_back(this->CreateUtilityTarget(cmtarget));
+ continue;
+ }
+
+ // organize the sources
+ std::vector<cmSourceFile*> classes;
+ if (!cmtarget.GetConfigCommonSourceFiles(classes))
+ {
+ return;
+ }
+ std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare());
+
+ gtgt->ComputeObjectMapping();
+
+ std::vector<cmXCodeObject*> externalObjFiles;
+ std::vector<cmXCodeObject*> headerFiles;
+ std::vector<cmXCodeObject*> resourceFiles;
+ std::vector<cmXCodeObject*> sourceFiles;
+ for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
+ i != classes.end(); ++i)
+ {
+ cmXCodeObject* xsf =
+ this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
+ *i, cmtarget);
+ cmXCodeObject* fr = xsf->GetObject("fileRef");
+ cmXCodeObject* filetype =
+ fr->GetObject()->GetObject("explicitFileType");
+
+ cmGeneratorTarget::SourceFileFlags tsFlags =
+ gtgt->GetTargetSourceFileFlags(*i);
+
+ if(filetype &&
+ filetype->GetString() == "compiled.mach-o.objfile")
+ {
+ if ((*i)->GetObjectLibrary().empty())
+ {
+ externalObjFiles.push_back(xsf);
+ }
+ }
+ else if(this->IsHeaderFile(*i) ||
+ (tsFlags.Type == cmGeneratorTarget::SourceFileTypePrivateHeader) ||
+ (tsFlags.Type == cmGeneratorTarget::SourceFileTypePublicHeader))
+ {
+ headerFiles.push_back(xsf);
+ }
+ else if(tsFlags.Type == cmGeneratorTarget::SourceFileTypeResource)
+ {
+ resourceFiles.push_back(xsf);
+ }
+ else if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
+ {
+ // Include this file in the build if it has a known language
+ // and has not been listed as an ignored extension for this
+ // generator.
+ if(!this->CurrentLocalGenerator->GetSourceFileLanguage(**i).empty() &&
+ !this->IgnoreFile((*i)->GetExtension().c_str()))
+ {
+ sourceFiles.push_back(xsf);
+ }
+ }
+ }
+
+ if(this->XcodeVersion < 50)
+ {
+ // Add object library contents as external objects. (Equivalent to
+ // the externalObjFiles above, except each one is not a cmSourceFile
+ // within the target.)
+ std::vector<std::string> objs;
+ gtgt->UseObjectLibraries(objs, "");
+ for(std::vector<std::string>::const_iterator
+ oi = objs.begin(); oi != objs.end(); ++oi)
+ {
+ std::string obj = *oi;
+ cmXCodeObject* xsf =
+ this->CreateXCodeSourceFileFromPath(obj, cmtarget, "", 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();
+
+ cmXCodeObject* buildFiles = 0;
+
+ // create source build phase
+ cmXCodeObject* sourceBuildPhase = 0;
+ if (!sourceFiles.empty())
+ {
+ sourceBuildPhase =
+ this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
+ sourceBuildPhase->SetComment("Sources");
+ sourceBuildPhase->AddAttribute("buildActionMask",
+ this->CreateString("2147483647"));
+ buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ for(std::vector<cmXCodeObject*>::iterator i = sourceFiles.begin();
+ i != sourceFiles.end(); ++i)
+ {
+ buildFiles->AddObject(*i);
+ }
+ sourceBuildPhase->AddAttribute("files", buildFiles);
+ sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ }
+
+ // create header build phase - only for framework targets
+ cmXCodeObject* headerBuildPhase = 0;
+ if (!headerFiles.empty() && isFrameworkTarget)
+ {
+ headerBuildPhase =
+ this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
+ headerBuildPhase->SetComment("Headers");
+ headerBuildPhase->AddAttribute("buildActionMask",
+ this->CreateString("2147483647"));
+ buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ for(std::vector<cmXCodeObject*>::iterator i = headerFiles.begin();
+ i != headerFiles.end(); ++i)
+ {
+ buildFiles->AddObject(*i);
+ }
+ headerBuildPhase->AddAttribute("files", buildFiles);
+ headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ }
+
+ // create resource build phase - only for framework or bundle targets
+ cmXCodeObject* resourceBuildPhase = 0;
+ if (!resourceFiles.empty() &&
+ (isFrameworkTarget || isBundleTarget || isCFBundleTarget))
+ {
+ resourceBuildPhase =
+ this->CreateObject(cmXCodeObject::PBXResourcesBuildPhase);
+ resourceBuildPhase->SetComment("Resources");
+ resourceBuildPhase->AddAttribute("buildActionMask",
+ this->CreateString("2147483647"));
+ buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ for(std::vector<cmXCodeObject*>::iterator i = resourceFiles.begin();
+ i != resourceFiles.end(); ++i)
+ {
+ buildFiles->AddObject(*i);
+ }
+ resourceBuildPhase->AddAttribute("files", buildFiles);
+ resourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ }
+
+ // create vector of "non-resource content file" build phases - only for
+ // framework or bundle targets
+ std::vector<cmXCodeObject*> contentBuildPhases;
+ if (isFrameworkTarget || isBundleTarget || isCFBundleTarget)
+ {
+ typedef std::map<std::string, std::vector<cmSourceFile*> >
+ mapOfVectorOfSourceFiles;
+ mapOfVectorOfSourceFiles bundleFiles;
+ for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
+ i != classes.end(); ++i)
+ {
+ cmGeneratorTarget::SourceFileFlags tsFlags =
+ gtgt->GetTargetSourceFileFlags(*i);
+ if(tsFlags.Type == cmGeneratorTarget::SourceFileTypeMacContent)
+ {
+ bundleFiles[tsFlags.MacFolder].push_back(*i);
+ }
+ }
+ mapOfVectorOfSourceFiles::iterator mit;
+ for ( mit = bundleFiles.begin(); mit != bundleFiles.end(); ++ mit )
+ {
+ cmXCodeObject* copyFilesBuildPhase =
+ this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase);
+ copyFilesBuildPhase->SetComment("Copy files");
+ copyFilesBuildPhase->AddAttribute("buildActionMask",
+ this->CreateString("2147483647"));
+ copyFilesBuildPhase->AddAttribute("dstSubfolderSpec",
+ this->CreateString("6"));
+ cmOStringStream ostr;
+ if (cmtarget.IsFrameworkOnApple())
+ {
+ // dstPath in frameworks is relative to Versions/<version>
+ ostr << mit->first;
+ }
+ else if ( mit->first != "MacOS" )
+ {
+ // dstPath in bundles is relative to Contents/MacOS
+ ostr << "../" << mit->first.c_str();
+ }
+ copyFilesBuildPhase->AddAttribute("dstPath",
+ this->CreateString(ostr.str().c_str()));
+ copyFilesBuildPhase->AddAttribute(
+ "runOnlyForDeploymentPostprocessing", this->CreateString("0"));
+ buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ copyFilesBuildPhase->AddAttribute("files", buildFiles);
+ std::vector<cmSourceFile*>::iterator sfIt;
+ for ( sfIt = mit->second.begin(); sfIt != mit->second.end(); ++ sfIt )
+ {
+ cmXCodeObject* xsf =
+ this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
+ *sfIt, cmtarget);
+ buildFiles->AddObject(xsf);
+ }
+ contentBuildPhases.push_back(copyFilesBuildPhase);
+ }
+ }
+
+ // create framework build phase
+ cmXCodeObject* frameworkBuildPhase = 0;
+ if (!externalObjFiles.empty())
+ {
+ frameworkBuildPhase =
+ this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
+ frameworkBuildPhase->SetComment("Frameworks");
+ frameworkBuildPhase->AddAttribute("buildActionMask",
+ this->CreateString("2147483647"));
+ buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ frameworkBuildPhase->AddAttribute("files", buildFiles);
+ for(std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin();
+ i != externalObjFiles.end(); ++i)
+ {
+ buildFiles->AddObject(*i);
+ }
+ frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ }
+
+ // create list of build phases and create the Xcode target
+ cmXCodeObject* buildPhases =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+
+ this->CreateCustomCommands(buildPhases, sourceBuildPhase,
+ headerBuildPhase, resourceBuildPhase,
+ contentBuildPhases,
+ frameworkBuildPhase, cmtarget);
+
+ targets.push_back(this->CreateXCodeTarget(cmtarget, buildPhases));
+ }
+}
+
+//----------------------------------------------------------------------------
+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)
+ {
+ this->ForceLinkerLanguage(*ti->second);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
+{
+ // This matters only for targets that link.
+ if(cmtarget.GetType() != cmTarget::EXECUTABLE &&
+ cmtarget.GetType() != cmTarget::SHARED_LIBRARY &&
+ cmtarget.GetType() != cmTarget::MODULE_LIBRARY)
+ {
+ return;
+ }
+
+ std::string llang = cmtarget.GetLinkerLanguage("NOCONFIG");
+ if(llang.empty()) { return; }
+
+ // If the language is compiled as a source trust Xcode to link with it.
+ cmTarget::LinkImplementation const* impl =
+ cmtarget.GetLinkImplementation("NOCONFIG");
+ for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
+ li != impl->Languages.end(); ++li)
+ {
+ if(*li == llang) { return; }
+ }
+
+ // 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->GetCurrentOutputDirectory();
+ fname += cmake::GetCMakeFilesDirectory();
+ fname += "/";
+ fname += cmtarget.GetName();
+ fname += "-CMakeForceLinker";
+ fname += ".";
+ fname += cmSystemTools::LowerCase(llang);
+ {
+ cmGeneratedFileStream fout(fname.c_str());
+ fout << "\n";
+ }
+ if(cmSourceFile* sf = mf->GetOrCreateSource(fname.c_str()))
+ {
+ sf->SetProperty("LANGUAGE", llang.c_str());
+ cmtarget.AddSource(fname);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
+{
+ const std::vector<std::string>& hdrExts =
+ this->CurrentMakefile->GetHeaderExtensions();
+ return (std::find(hdrExts.begin(), hdrExts.end(), sf->GetExtension()) !=
+ hdrExts.end());
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
+ const char* name2,
+ cmTarget& cmtarget,
+ const std::vector<cmCustomCommand>&
+ commands)
+{
+ if(commands.size() == 0 && strcmp(name, "CMake ReRun") != 0)
+ {
+ return 0;
+ }
+ cmXCodeObject* buildPhase =
+ this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
+ buildPhase->AddAttribute("buildActionMask",
+ this->CreateString("2147483647"));
+ cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ buildPhase->AddAttribute("files", buildFiles);
+ buildPhase->AddAttribute("name",
+ this->CreateString(name));
+ buildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ buildPhase->AddAttribute("shellPath",
+ this->CreateString("/bin/sh"));
+ this->AddCommandsToBuildPhase(buildPhase, cmtarget, commands,
+ name2);
+ return buildPhase;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
+ cmXCodeObject*
+ sourceBuildPhase,
+ cmXCodeObject*
+ headerBuildPhase,
+ cmXCodeObject*
+ resourceBuildPhase,
+ std::vector<cmXCodeObject*>
+ contentBuildPhases,
+ cmXCodeObject*
+ frameworkBuildPhase,
+ cmTarget& cmtarget)
+{
+ std::vector<cmCustomCommand> const & prebuild
+ = cmtarget.GetPreBuildCommands();
+ std::vector<cmCustomCommand> const & prelink
+ = cmtarget.GetPreLinkCommands();
+ std::vector<cmCustomCommand> postbuild
+ = cmtarget.GetPostBuildCommands();
+
+ if(cmtarget.GetType() == cmTarget::SHARED_LIBRARY &&
+ !cmtarget.IsFrameworkOnApple())
+ {
+ cmCustomCommandLines cmd;
+ cmd.resize(1);
+ cmd[0].push_back(this->CurrentMakefile->GetDefinition("CMAKE_COMMAND"));
+ cmd[0].push_back("-E");
+ cmd[0].push_back("cmake_symlink_library");
+ std::string str_file = "$<TARGET_FILE:";
+ str_file += cmtarget.GetName();
+ str_file += ">";
+ std::string str_so_file = "$<TARGET_SONAME_FILE:";
+ str_so_file += cmtarget.GetName();
+ str_so_file += ">";
+ std::string str_link_file = "$<TARGET_LINKER_FILE:";
+ str_link_file += cmtarget.GetName();
+ str_link_file += ">";
+ cmd[0].push_back(str_file);
+ cmd[0].push_back(str_so_file);
+ cmd[0].push_back(str_link_file);
+
+ cmCustomCommand command(this->CurrentMakefile,
+ std::vector<std::string>(),
+ std::vector<std::string>(),
+ cmd,
+ "Creating symlinks",
+ "");
+
+ postbuild.push_back(command);
+ }
+
+ std::vector<cmSourceFile*> classes;
+ if (!cmtarget.GetConfigCommonSourceFiles(classes))
+ {
+ return;
+ }
+ // add all the sources
+ std::vector<cmCustomCommand> commands;
+ for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
+ i != classes.end(); ++i)
+ {
+ if((*i)->GetCustomCommand())
+ {
+ commands.push_back(*(*i)->GetCustomCommand());
+ }
+ }
+ // create prebuild phase
+ cmXCodeObject* cmakeRulesBuildPhase =
+ this->CreateBuildPhase("CMake Rules",
+ "cmakeRulesBuildPhase",
+ cmtarget, commands);
+ // create prebuild phase
+ cmXCodeObject* preBuildPhase =
+ this->CreateBuildPhase("CMake PreBuild Rules", "preBuildCommands",
+ cmtarget, prebuild);
+ // create prelink phase
+ cmXCodeObject* preLinkPhase =
+ this->CreateBuildPhase("CMake PreLink Rules", "preLinkCommands",
+ cmtarget, prelink);
+ // create postbuild phase
+ cmXCodeObject* postBuildPhase =
+ this->CreateBuildPhase("CMake PostBuild Rules", "postBuildPhase",
+ cmtarget, postbuild);
+
+ // The order here is the order they will be built in.
+ // The order "headers, resources, sources" mimics a native project generated
+ // from an xcode template...
+ //
+ if(preBuildPhase)
+ {
+ buildPhases->AddObject(preBuildPhase);
+ }
+ if(cmakeRulesBuildPhase)
+ {
+ buildPhases->AddObject(cmakeRulesBuildPhase);
+ }
+ if(headerBuildPhase)
+ {
+ buildPhases->AddObject(headerBuildPhase);
+ }
+ if(resourceBuildPhase)
+ {
+ buildPhases->AddObject(resourceBuildPhase);
+ }
+ std::vector<cmXCodeObject*>::iterator cit;
+ for (cit = contentBuildPhases.begin(); cit != contentBuildPhases.end();
+ ++cit)
+ {
+ buildPhases->AddObject(*cit);
+ }
+ if(sourceBuildPhase)
+ {
+ buildPhases->AddObject(sourceBuildPhase);
+ }
+ if(preLinkPhase)
+ {
+ buildPhases->AddObject(preLinkPhase);
+ }
+ if(frameworkBuildPhase)
+ {
+ buildPhases->AddObject(frameworkBuildPhase);
+ }
+ if(postBuildPhase)
+ {
+ buildPhases->AddObject(postBuildPhase);
+ }
+}
+
+//----------------------------------------------------------------------------
+// This function removes each occurrence of the flag and returns the last one
+// (i.e., the dominant flag in GCC)
+std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
+ std::string& flags)
+{
+ std::string retFlag;
+ std::string::size_type lastOccurancePos = flags.rfind(flag);
+ bool saved = false;
+ while(lastOccurancePos != flags.npos)
+ {
+ //increment pos, we use lastOccurancePos to reduce search space on next inc
+ std::string::size_type pos = lastOccurancePos;
+ if(pos == 0 || flags[pos-1]==' ')
+ {
+ while(pos < flags.size() && flags[pos] != ' ')
+ {
+ if(!saved)
+ {
+ retFlag += flags[pos];
+ }
+ flags[pos] = ' ';
+ pos++;
+ }
+ saved = true;
+ }
+ //decrement lastOccurancePos while making sure we don't loop around
+ //and become a very large positive number since size_type is unsigned
+ lastOccurancePos = lastOccurancePos == 0 ? 0 : lastOccurancePos-1;
+ lastOccurancePos = flags.rfind(flag,lastOccurancePos);
+ }
+ return retFlag;
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
+ cmTarget& target,
+ std::vector<cmCustomCommand>
+ const & commands,
+ const char* name)
+{
+ bool haveMultipleOutputPairs = false;
+ std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
+ dir += "/CMakeScripts";
+ cmSystemTools::MakeDirectory(dir.c_str());
+ std::string makefile = dir;
+ makefile += "/";
+ makefile += target.GetName();
+ makefile += "_";
+ makefile += name;
+ makefile += ".make";
+
+ for (std::vector<std::string>::const_iterator currentConfig=
+ this->CurrentConfigurationTypes.begin();
+ currentConfig!=this->CurrentConfigurationTypes.end();
+ currentConfig++ )
+ {
+ this->CreateCustomRulesMakefile(makefile.c_str(),
+ target,
+ commands,
+ currentConfig->c_str(),
+ haveMultipleOutputPairs);
+ }
+
+ std::string cdir = this->CurrentMakefile->GetCurrentOutputDirectory();
+ cdir = this->ConvertToRelativeForXCode(cdir.c_str());
+ std::string makecmd = "make -C ";
+ makecmd += cdir;
+ makecmd += " -f ";
+ makecmd += this->ConvertToRelativeForMake(
+ (makefile+"$CONFIGURATION").c_str());
+ if(haveMultipleOutputPairs)
+ {
+ makecmd += " cmake_check_multiple_outputs";
+ }
+ makecmd += " all";
+ cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
+ buildphase->AddAttribute("shellScript",
+ this->CreateString(makecmd.c_str()));
+ buildphase->AddAttribute("showEnvVarsInLog",
+ this->CreateString("0"));
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator
+::CreateCustomRulesMakefile(const char* makefileBasename,
+ cmTarget& target,
+ std::vector<cmCustomCommand>
+ const & commands,
+ const std::string& configName,
+ bool& haveMultipleOutputPairs)
+{
+ std::string makefileName=makefileBasename;
+ if(this->XcodeVersion > 20)
+ {
+ makefileName+=configName;
+ }
+ cmGeneratedFileStream makefileStream(makefileName.c_str());
+ if(!makefileStream)
+ {
+ return;
+ }
+ makefileStream.SetCopyIfDifferent(true);
+ makefileStream << "# Generated by CMake, DO NOT EDIT\n";
+ makefileStream << "# Custom rules for " << target.GetName() << "\n";
+
+ // disable the implicit rules
+ makefileStream << ".SUFFIXES: " << "\n";
+
+ // have all depend on all outputs
+ makefileStream << "all: ";
+ std::map<const cmCustomCommand*, std::string> tname;
+ int count = 0;
+ std::map<std::string, std::string> multipleOutputPairs;
+ for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
+ i != commands.end(); ++i)
+ {
+ cmCustomCommandGenerator ccg(*i, configName, this->CurrentMakefile);
+ if(ccg.GetNumberOfCommands() > 0)
+ {
+ const std::vector<std::string>& outputs = ccg.GetOutputs();
+ if(!outputs.empty())
+ {
+ for(std::vector<std::string>::const_iterator o = outputs.begin();
+ o != outputs.end(); ++o)
+ {
+ makefileStream
+ << "\\\n\t" << this->ConvertToRelativeForMake(o->c_str());
+ }
+
+ // If there is more than one output treat the first as the
+ // primary output and make the rest depend on it.
+ std::vector<std::string>::const_iterator o = outputs.begin();
+ std::string primaryOutput = this->ConvertToRelativeForMake(o->c_str());
+ for(++o; o != outputs.end(); ++o)
+ {
+ std::string currentOutput=this->ConvertToRelativeForMake(o->c_str());
+ multipleOutputPairs[currentOutput] = primaryOutput;
+ }
+ }
+ else
+ {
+ cmOStringStream str;
+ str << "_buildpart_" << count++ ;
+ tname[&ccg.GetCC()] = std::string(target.GetName()) + str.str();
+ makefileStream << "\\\n\t" << tname[&ccg.GetCC()];
+ }
+ }
+ }
+ makefileStream << "\n\n";
+ for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
+ i != commands.end(); ++i)
+ {
+ cmCustomCommandGenerator ccg(*i, configName, this->CurrentMakefile);
+ if(ccg.GetNumberOfCommands() > 0)
+ {
+ makefileStream << "\n";
+ const std::vector<std::string>& outputs = ccg.GetOutputs();
+ if(!outputs.empty())
+ {
+ // There is at least one output, start the rule for it
+ std::string primary_output =
+ this->ConvertToRelativeForMake(outputs.begin()->c_str());
+ makefileStream << primary_output << ": ";
+ }
+ else
+ {
+ // There are no outputs. Use the generated force rule name.
+ makefileStream << tname[&ccg.GetCC()] << ": ";
+ }
+ for(std::vector<std::string>::const_iterator d =
+ ccg.GetDepends().begin();
+ d != ccg.GetDepends().end(); ++d)
+ {
+ std::string dep;
+ if(this->CurrentLocalGenerator
+ ->GetRealDependency(d->c_str(), configName, dep))
+ {
+ makefileStream << "\\\n" <<
+ this->ConvertToRelativeForMake(dep.c_str());
+ }
+ }
+ makefileStream << "\n";
+
+ if(const char* comment = ccg.GetComment())
+ {
+ std::string echo_cmd = "echo ";
+ echo_cmd += (this->CurrentLocalGenerator->
+ EscapeForShell(comment, ccg.GetCC().GetEscapeAllowMakeVars()));
+ makefileStream << "\t" << echo_cmd.c_str() << "\n";
+ }
+
+ // Add each command line to the set of commands.
+ for(unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c)
+ {
+ // Build the command line in a single string.
+ std::string cmd2 = ccg.GetCommand(c);
+ cmSystemTools::ReplaceString(cmd2, "/./", "/");
+ cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
+ std::string cmd;
+ std::string wd = ccg.GetWorkingDirectory();
+ if(!wd.empty())
+ {
+ cmd += "cd ";
+ cmd += this->ConvertToRelativeForMake(wd.c_str());
+ cmd += " && ";
+ }
+ cmd += cmd2;
+ ccg.AppendArguments(c, cmd);
+ makefileStream << "\t" << cmd.c_str() << "\n";
+ }
+ }
+ }
+
+ // Add rules to deal with multiple outputs of custom commands.
+ if(!multipleOutputPairs.empty())
+ {
+ makefileStream <<
+ "\n# Dependencies of multiple outputs to their primary outputs \n";
+
+ for(std::map<std::string, std::string>::const_iterator o =
+ multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
+ {
+ makefileStream << o->first << ": " << o->second << "\n";
+ }
+
+ makefileStream <<
+ "\n"
+ "cmake_check_multiple_outputs:\n";
+ for(std::map<std::string, std::string>::const_iterator o =
+ multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
+ {
+ makefileStream << "\t@if [ ! -f "
+ << o->first << " ]; then rm -f "
+ << o->second << "; fi\n";
+ }
+ }
+
+ haveMultipleOutputPairs =
+ haveMultipleOutputPairs || !multipleOutputPairs.empty();
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
+ cmXCodeObject* buildSettings,
+ const std::string& configName)
+{
+ if(target.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ return;
+ }
+
+ std::string flags;
+ 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) ||
+ shared);
+
+ std::string lang = target.GetLinkerLanguage(configName);
+ std::string cflags;
+ if(!lang.empty())
+ {
+ // for c++ projects get the c flags as well
+ if(lang == "CXX")
+ {
+ this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
+ this->CurrentLocalGenerator->AddCMP0018Flags(cflags, &target,
+ "C", configName);
+ this->CurrentLocalGenerator->
+ AddCompileOptions(cflags, &target, "C", configName);
+ }
+
+ // Add language-specific flags.
+ this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);
+
+ // Add shared-library flags if needed.
+ this->CurrentLocalGenerator->AddCMP0018Flags(flags, &target,
+ lang, configName);
+
+ this->CurrentLocalGenerator->AddVisibilityPresetFlags(flags, &target,
+ lang);
+
+ this->CurrentLocalGenerator->
+ AddCompileOptions(flags, &target, lang, configName);
+ }
+ else if(binary)
+ {
+ cmSystemTools::Error
+ ("CMake can not determine linker language for target: ",
+ target.GetName().c_str());
+ return;
+ }
+
+ // Add define flags
+ this->CurrentLocalGenerator->
+ AppendFlags(defFlags,
+ this->CurrentMakefile->GetDefineFlags());
+
+ // Add preprocessor definitions for this target and configuration.
+ BuildObjectListOrString ppDefs(this, this->XcodeVersion >= 30);
+ if(this->XcodeVersion > 15)
+ {
+ this->AppendDefines(ppDefs,
+ "CMAKE_INTDIR=\"$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)\"");
+ }
+ if(const char* exportMacro = target.GetExportMacro())
+ {
+ // Add the export symbol definition for shared library objects.
+ this->AppendDefines(ppDefs, exportMacro);
+ }
+ cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
+ std::vector<std::string> targetDefines;
+ target.GetCompileDefinitions(targetDefines, configName);
+ this->AppendDefines(ppDefs, targetDefines);
+ buildSettings->AddAttribute
+ ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList());
+
+ std::string extraLinkOptionsVar;
+ std::string extraLinkOptions;
+ if(target.GetType() == cmTarget::EXECUTABLE)
+ {
+ extraLinkOptionsVar = "CMAKE_EXE_LINKER_FLAGS";
+ }
+ else if(target.GetType() == cmTarget::SHARED_LIBRARY)
+ {
+ extraLinkOptionsVar = "CMAKE_SHARED_LINKER_FLAGS";
+ }
+ else if(target.GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ extraLinkOptionsVar = "CMAKE_MODULE_LINKER_FLAGS";
+ }
+ if(extraLinkOptionsVar.size())
+ {
+ this->CurrentLocalGenerator
+ ->AddConfigVariableFlags(extraLinkOptions,
+ extraLinkOptionsVar.c_str(),
+ configName);
+ }
+
+ if(target.GetType() == cmTarget::OBJECT_LIBRARY ||
+ target.GetType() == cmTarget::STATIC_LIBRARY)
+ {
+ this->CurrentLocalGenerator
+ ->GetStaticLibraryFlags(extraLinkOptions,
+ cmSystemTools::UpperCase(configName),
+ &target);
+ }
+ else
+ {
+ const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
+ if(targetLinkFlags)
+ {
+ this->CurrentLocalGenerator->
+ AppendFlags(extraLinkOptions, targetLinkFlags);
+ }
+ if(!configName.empty())
+ {
+ std::string linkFlagsVar = "LINK_FLAGS_";
+ linkFlagsVar += cmSystemTools::UpperCase(configName);
+ if(const char* linkFlags = target.GetProperty(linkFlagsVar.c_str()))
+ {
+ this->CurrentLocalGenerator->
+ AppendFlags(extraLinkOptions, linkFlags);
+ }
+ }
+ }
+
+ // Set target-specific architectures.
+ std::vector<std::string> archs;
+ gtgt->GetAppleArchs(configName, archs);
+
+ if(!archs.empty())
+ {
+ // Enable ARCHS attribute.
+ buildSettings->AddAttribute("ONLY_ACTIVE_ARCH",
+ this->CreateString("NO"));
+
+ // Store ARCHS value.
+ if(archs.size() == 1)
+ {
+ buildSettings->AddAttribute("ARCHS",
+ this->CreateString(archs[0].c_str()));
+ }
+ else
+ {
+ cmXCodeObject* archObjects =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ for(std::vector<std::string>::iterator i = archs.begin();
+ i != archs.end(); i++)
+ {
+ archObjects->AddObject(this->CreateString((*i).c_str()));
+ }
+ buildSettings->AddAttribute("ARCHS", archObjects);
+ }
+ }
+
+ // Get the product name components.
+ std::string pnprefix;
+ std::string pnbase;
+ std::string pnsuffix;
+ target.GetFullNameComponents(pnprefix, pnbase, pnsuffix, configName);
+
+ const char* version = target.GetProperty("VERSION");
+ const char* soversion = target.GetProperty("SOVERSION");
+ if(!target.HasSOName(configName) || target.IsFrameworkOnApple())
+ {
+ version = 0;
+ soversion = 0;
+ }
+ if(version && !soversion)
+ {
+ soversion = version;
+ }
+ if(!version && soversion)
+ {
+ version = soversion;
+ }
+
+ std::string realName = pnbase;
+ std::string soName = pnbase;
+ if(version && soversion)
+ {
+ realName += ".";
+ realName += version;
+ soName += ".";
+ soName += soversion;
+ }
+
+ // Set attributes to specify the proper name for the target.
+ std::string pndir = this->CurrentMakefile->GetCurrentOutputDirectory();
+ if(target.GetType() == cmTarget::STATIC_LIBRARY ||
+ target.GetType() == cmTarget::SHARED_LIBRARY ||
+ target.GetType() == cmTarget::MODULE_LIBRARY ||
+ target.GetType() == cmTarget::EXECUTABLE)
+ {
+ if(this->XcodeVersion >= 21)
+ {
+ if(!target.UsesDefaultOutputDir(configName, false))
+ {
+ std::string pncdir = target.GetDirectory(configName);
+ buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
+ this->CreateString(pncdir.c_str()));
+ }
+ }
+ else
+ {
+ buildSettings->AddAttribute("OBJROOT",
+ this->CreateString(pndir.c_str()));
+ pndir = target.GetDirectory(configName);
+ }
+
+ if(target.IsFrameworkOnApple() || target.IsCFBundleOnApple())
+ {
+ pnprefix = "";
+ }
+
+ buildSettings->AddAttribute("EXECUTABLE_PREFIX",
+ this->CreateString(pnprefix.c_str()));
+ buildSettings->AddAttribute("EXECUTABLE_SUFFIX",
+ this->CreateString(pnsuffix.c_str()));
+ }
+ else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ pnprefix = "lib";
+ pnbase = target.GetName();
+ pnsuffix = ".a";
+
+ if(this->XcodeVersion >= 21)
+ {
+ std::string pncdir = this->GetObjectsNormalDirectory(
+ this->CurrentProject, configName, &target);
+ buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
+ this->CreateString(pncdir.c_str()));
+ }
+ else
+ {
+ buildSettings->AddAttribute("OBJROOT",
+ this->CreateString(pndir.c_str()));
+ pndir = this->GetObjectsNormalDirectory(
+ this->CurrentProject, configName, &target);
+ }
+ }
+
+ // Store the product name for all target types.
+ buildSettings->AddAttribute("PRODUCT_NAME",
+ this->CreateString(realName.c_str()));
+ buildSettings->AddAttribute("SYMROOT",
+ this->CreateString(pndir.c_str()));
+
+ // Handle settings for each target type.
+ switch(target.GetType())
+ {
+ case cmTarget::OBJECT_LIBRARY:
+ case cmTarget::STATIC_LIBRARY:
+ {
+ buildSettings->AddAttribute("LIBRARY_STYLE",
+ this->CreateString("STATIC"));
+ break;
+ }
+
+ case cmTarget::MODULE_LIBRARY:
+ {
+ buildSettings->AddAttribute("LIBRARY_STYLE",
+ this->CreateString("BUNDLE"));
+ if (target.GetPropertyAsBool("BUNDLE"))
+ {
+ // It turns out that a BUNDLE is basically the same
+ // in many ways as an application bundle, as far as
+ // link flags go
+ std::string createFlags =
+ this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
+ "-bundle");
+ if(!createFlags.empty())
+ {
+ extraLinkOptions += " ";
+ extraLinkOptions += createFlags;
+ }
+ std::string plist = this->ComputeInfoPListLocation(target);
+ // 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)",
+ plist.c_str());
+ std::string path =
+ this->ConvertToRelativeForXCode(plist.c_str());
+ buildSettings->AddAttribute("INFOPLIST_FILE",
+ this->CreateString(path.c_str()));
+ }
+ else if(this->XcodeVersion >= 22)
+ {
+ buildSettings->AddAttribute("MACH_O_TYPE",
+ this->CreateString("mh_bundle"));
+ buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
+ this->CreateString("NO"));
+ // Add the flags to create an executable.
+ std::string createFlags =
+ this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
+ if(!createFlags.empty())
+ {
+ extraLinkOptions += " ";
+ extraLinkOptions += createFlags;
+ }
+ }
+ else
+ {
+ // Add the flags to create a module.
+ std::string createFlags =
+ this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
+ "-bundle");
+ if(!createFlags.empty())
+ {
+ extraLinkOptions += " ";
+ extraLinkOptions += createFlags;
+ }
+ }
+ break;
+ }
+ case cmTarget::SHARED_LIBRARY:
+ {
+ if(target.GetPropertyAsBool("FRAMEWORK"))
+ {
+ std::string fw_version = target.GetFrameworkVersion();
+ buildSettings->AddAttribute("FRAMEWORK_VERSION",
+ this->CreateString(fw_version.c_str()));
+
+ std::string plist = this->ComputeInfoPListLocation(target);
+ // 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)",
+ plist.c_str());
+ std::string path =
+ this->ConvertToRelativeForXCode(plist.c_str());
+ buildSettings->AddAttribute("INFOPLIST_FILE",
+ this->CreateString(path.c_str()));
+ }
+ else
+ {
+ // Add the flags to create a shared library.
+ std::string createFlags =
+ this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS",
+ "-dynamiclib");
+ if(!createFlags.empty())
+ {
+ extraLinkOptions += " ";
+ extraLinkOptions += createFlags;
+ }
+ }
+
+ buildSettings->AddAttribute("LIBRARY_STYLE",
+ this->CreateString("DYNAMIC"));
+ break;
+ }
+ case cmTarget::EXECUTABLE:
+ {
+ // Add the flags to create an executable.
+ std::string createFlags =
+ this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
+ if(!createFlags.empty())
+ {
+ extraLinkOptions += " ";
+ extraLinkOptions += createFlags;
+ }
+
+ // Handle bundles and normal executables separately.
+ if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
+ {
+ std::string plist = this->ComputeInfoPListLocation(target);
+ // 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)",
+ plist.c_str());
+ std::string path =
+ this->ConvertToRelativeForXCode(plist.c_str());
+ buildSettings->AddAttribute("INFOPLIST_FILE",
+ this->CreateString(path.c_str()));
+
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ if(this->XcodeVersion >= 22 && this->XcodeVersion < 40)
+ {
+ buildSettings->AddAttribute("PREBINDING",
+ this->CreateString("NO"));
+ }
+
+ BuildObjectListOrString dirs(this, this->XcodeVersion >= 30);
+ BuildObjectListOrString fdirs(this, this->XcodeVersion >= 30);
+ std::vector<std::string> includes;
+ this->CurrentLocalGenerator->GetIncludeDirectories(includes, gtgt,
+ "C", configName);
+ std::set<std::string> emitted;
+ emitted.insert("/System/Library/Frameworks");
+ for(std::vector<std::string>::iterator i = includes.begin();
+ i != includes.end(); ++i)
+ {
+ if(this->NameResolvesToFramework(i->c_str()))
+ {
+ std::string frameworkDir = *i;
+ frameworkDir += "/../";
+ frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
+ if(emitted.insert(frameworkDir).second)
+ {
+ fdirs.Add(this->XCodeEscapePath(frameworkDir.c_str()).c_str());
+ }
+ }
+ else
+ {
+ std::string incpath =
+ this->XCodeEscapePath(i->c_str());
+ dirs.Add(incpath.c_str());
+ }
+ }
+ // Add framework search paths needed for linking.
+ if(cmComputeLinkInformation* cli = target.GetLinkInformation(configName))
+ {
+ std::vector<std::string> const& fwDirs = cli->GetFrameworkPaths();
+ for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
+ fdi != fwDirs.end(); ++fdi)
+ {
+ if(emitted.insert(*fdi).second)
+ {
+ fdirs.Add(this->XCodeEscapePath(fdi->c_str()).c_str());
+ }
+ }
+ }
+ if(!fdirs.IsEmpty())
+ {
+ buildSettings->AddAttribute("FRAMEWORK_SEARCH_PATHS",
+ fdirs.CreateList());
+ }
+ if(!dirs.IsEmpty())
+ {
+ buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
+ dirs.CreateList());
+ }
+ std::string oflagc = this->ExtractFlag("-O", cflags);
+ char optLevel[2];
+ optLevel[0] = '0';
+ optLevel[1] = 0;
+ if(oflagc.size() == 3)
+ {
+ optLevel[0] = oflagc[2];
+ }
+ if(oflagc.size() == 2)
+ {
+ optLevel[0] = '1';
+ }
+ std::string oflag = this->ExtractFlag("-O", flags);
+ if(oflag.size() == 3)
+ {
+ optLevel[0] = oflag[2];
+ }
+ if(oflag.size() == 2)
+ {
+ optLevel[0] = '1';
+ }
+ std::string gflagc = this->ExtractFlag("-g", cflags);
+ // put back gdwarf-2 if used since there is no way
+ // to represent it in the gui, but we still want debug yes
+ if(gflagc == "-gdwarf-2")
+ {
+ cflags += " ";
+ cflags += gflagc;
+ }
+ std::string gflag = this->ExtractFlag("-g", flags);
+ if(gflag == "-gdwarf-2")
+ {
+ flags += " ";
+ flags += gflag;
+ }
+ const char* debugStr = "YES";
+ // We can't set the Xcode flag differently depending on the language,
+ // so put them back in this case.
+ if( (lang == "CXX") && gflag != gflagc )
+ {
+ cflags += " ";
+ cflags += gflagc;
+ flags += " ";
+ flags += gflag;
+ debugStr = "NO";
+ }
+ if( gflag == "-g0" || gflag.size() == 0 )
+ {
+ debugStr = "NO";
+ }
+
+ buildSettings->AddAttribute("COMBINE_HIDPI_IMAGES",
+ this->CreateString("YES"));
+ buildSettings->AddAttribute("GCC_GENERATE_DEBUGGING_SYMBOLS",
+ this->CreateString(debugStr));
+ buildSettings->AddAttribute("GCC_OPTIMIZATION_LEVEL",
+ this->CreateString(optLevel));
+ buildSettings->AddAttribute("GCC_SYMBOLS_PRIVATE_EXTERN",
+ this->CreateString("NO"));
+ buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
+ this->CreateString("NO"));
+ if(lang == "CXX")
+ {
+ flags += " ";
+ flags += defFlags;
+ buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
+ this->CreateString(flags.c_str()));
+ cflags += " ";
+ cflags += defFlags;
+ buildSettings->AddAttribute("OTHER_CFLAGS",
+ this->CreateString(cflags.c_str()));
+
+ }
+ else
+ {
+ flags += " ";
+ flags += defFlags;
+ buildSettings->AddAttribute("OTHER_CFLAGS",
+ this->CreateString(flags.c_str()));
+ }
+
+ // Add Fortran source format attribute if property is set.
+ const char* format = 0;
+ const char* tgtfmt = target.GetProperty("Fortran_FORMAT");
+ switch(this->CurrentLocalGenerator->GetFortranFormat(tgtfmt))
+ {
+ case cmLocalGenerator::FortranFormatFixed: format = "fixed"; break;
+ case cmLocalGenerator::FortranFormatFree: format = "free"; break;
+ default: break;
+ }
+ if(format)
+ {
+ buildSettings->AddAttribute("IFORT_LANG_SRCFMT",
+ this->CreateString(format));
+ }
+
+ // Create the INSTALL_PATH attribute.
+ std::string install_name_dir;
+ if(target.GetType() == cmTarget::SHARED_LIBRARY)
+ {
+ // Get the install_name directory for the build tree.
+ install_name_dir = target.GetInstallNameDirForBuildTree(configName);
+ // Xcode doesn't create the correct install_name in some cases.
+ // That is, if the INSTALL_PATH is empty, or if we have versioning
+ // of dylib libraries, we want to specify the install_name.
+ // This is done by adding a link flag to create an install_name
+ // with just the library soname.
+ std::string install_name;
+ if(!install_name_dir.empty())
+ {
+ // Convert to a path for the native build tool.
+ cmSystemTools::ConvertToUnixSlashes(install_name_dir);
+ install_name += install_name_dir;
+ install_name += "/";
+ }
+ install_name += target.GetSOName(configName);
+
+ if((realName != soName) || install_name_dir.empty())
+ {
+ install_name_dir = "";
+ extraLinkOptions += " -install_name ";
+ extraLinkOptions += XCodeEscapePath(install_name.c_str());
+ }
+ }
+ buildSettings->AddAttribute("INSTALL_PATH",
+ this->CreateString(install_name_dir.c_str()));
+
+ // Create the LD_RUNPATH_SEARCH_PATHS
+ cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
+ if(pcli)
+ {
+ std::string search_paths;
+ std::vector<std::string> runtimeDirs;
+ pcli->GetRPath(runtimeDirs, false);
+ // runpath dirs needs to be unique to prevent corruption
+ std::set<std::string> unique_dirs;
+
+ for(std::vector<std::string>::const_iterator i = runtimeDirs.begin();
+ i != runtimeDirs.end(); ++i)
+ {
+ std::string runpath = *i;
+ runpath = this->ExpandCFGIntDir(runpath, configName);
+
+ if(unique_dirs.find(runpath) == unique_dirs.end())
+ {
+ unique_dirs.insert(runpath);
+ if(!search_paths.empty())
+ {
+ search_paths += " ";
+ }
+ search_paths += this->XCodeEscapePath(runpath.c_str());
+ }
+ }
+ if(!search_paths.empty())
+ {
+ buildSettings->AddAttribute("LD_RUNPATH_SEARCH_PATHS",
+ this->CreateString(search_paths.c_str()));
+ }
+ }
+
+ buildSettings->AddAttribute(this->GetTargetLinkFlagsVar(target),
+ this->CreateString(extraLinkOptions.c_str()));
+ buildSettings->AddAttribute("OTHER_REZFLAGS",
+ this->CreateString(""));
+ buildSettings->AddAttribute("SECTORDER_FLAGS",
+ this->CreateString(""));
+ buildSettings->AddAttribute("USE_HEADERMAP",
+ this->CreateString("NO"));
+ if (this->XcodeVersion >= 30)
+ {
+ cmXCodeObject *group = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ group->AddObject(this->CreateString("-Wmost"));
+ group->AddObject(this->CreateString("-Wno-four-char-constants"));
+ group->AddObject(this->CreateString("-Wno-unknown-pragmas"));
+ buildSettings->AddAttribute("WARNING_CFLAGS", group);
+ }
+ else
+ {
+ buildSettings->AddAttribute("WARNING_CFLAGS",
+ this->CreateString(
+ "-Wmost -Wno-four-char-constants"
+ " -Wno-unknown-pragmas"));
+ }
+
+ // Runtime version information.
+ if(target.GetType() == cmTarget::SHARED_LIBRARY)
+ {
+ int major;
+ int minor;
+ int patch;
+
+ // VERSION -> current_version
+ target.GetTargetVersion(false, major, minor, patch);
+ cmOStringStream v;
+
+ // Xcode always wants at least 1.0.0 or nothing
+ if(!(major == 0 && minor == 0 && patch == 0))
+ {
+ v << major << "." << minor << "." << patch;
+ }
+ buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
+ this->CreateString(v.str().c_str()));
+
+ // SOVERSION -> compatibility_version
+ target.GetTargetVersion(true, major, minor, patch);
+ cmOStringStream vso;
+
+ // Xcode always wants at least 1.0.0 or nothing
+ if(!(major == 0 && minor == 0 && patch == 0))
+ {
+ vso << major << "." << minor << "." << patch;
+ }
+ buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
+ this->CreateString(vso.str().c_str()));
+ }
+ // 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();
+ i != props.end(); ++i)
+ {
+ if(i->first.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();
+ }
+ }
+ }
+
+ if (!attribute.empty())
+ {
+ buildSettings->AddAttribute(attribute.c_str(),
+ this->CreateString(i->second.GetValue()));
+ }
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
+{
+ cmXCodeObject* shellBuildPhase =
+ this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
+ shellBuildPhase->AddAttribute("buildActionMask",
+ this->CreateString("2147483647"));
+ cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ shellBuildPhase->AddAttribute("files", buildFiles);
+ cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ shellBuildPhase->AddAttribute("inputPaths", inputPaths);
+ cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ shellBuildPhase->AddAttribute("outputPaths", outputPaths);
+ shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ shellBuildPhase->AddAttribute("shellPath",
+ this->CreateString("/bin/sh"));
+ shellBuildPhase->AddAttribute("shellScript",
+ this->CreateString(
+ "# shell script goes here\nexit 0"));
+ shellBuildPhase->AddAttribute("showEnvVarsInLog",
+ this->CreateString("0"));
+
+ cmXCodeObject* target =
+ this->CreateObject(cmXCodeObject::PBXAggregateTarget);
+ target->SetComment(cmtarget.GetName().c_str());
+ cmXCodeObject* buildPhases =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ std::vector<cmXCodeObject*> emptyContentVector;
+ this->CreateCustomCommands(buildPhases, 0, 0, 0, emptyContentVector, 0,
+ cmtarget);
+ target->AddAttribute("buildPhases", buildPhases);
+ if(this->XcodeVersion > 20)
+ {
+ this->AddConfigurations(target, cmtarget);
+ }
+ else
+ {
+ std::string theConfig =
+ this->CurrentMakefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ cmXCodeObject* buildSettings =
+ this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ this->CreateBuildSettings(cmtarget, 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);
+
+ // Add source files without build rules for editing convenience.
+ if(cmtarget.GetType() == cmTarget::UTILITY)
+ {
+ std::vector<cmSourceFile*> sources;
+ if (!cmtarget.GetConfigCommonSourceFiles(sources))
+ {
+ return 0;
+ }
+
+ for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
+ i != sources.end(); ++i)
+ {
+ if(!(*i)->GetPropertyAsBool("GENERATED"))
+ {
+ this->CreateXCodeFileReference(*i, cmtarget);
+ }
+ }
+ }
+
+ target->SetId(this->GetOrCreateId(
+ cmtarget.GetName(), target->GetId()).c_str());
+
+ return target;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
+ cmTarget& cmtarget)
+{
+ std::string configTypes =
+ this->CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES");
+ std::vector<std::string> configVectorIn;
+ std::vector<std::string> configVector;
+ configVectorIn.push_back(configTypes);
+ cmSystemTools::ExpandList(configVectorIn, configVector);
+ cmXCodeObject* configlist =
+ this->CreateObject(cmXCodeObject::XCConfigurationList);
+ cmXCodeObject* buildConfigurations =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ configlist->AddAttribute("buildConfigurations", buildConfigurations);
+ std::string comment = "Build configuration list for ";
+ comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
+ comment += " \"";
+ comment += cmtarget.GetName();
+ comment += "\"";
+ configlist->SetComment(comment.c_str());
+ target->AddAttribute("buildConfigurationList",
+ this->CreateObjectReference(configlist));
+ for(unsigned int i = 0; i < configVector.size(); ++i)
+ {
+ cmXCodeObject* config =
+ this->CreateObject(cmXCodeObject::XCBuildConfiguration);
+ buildConfigurations->AddObject(config);
+ cmXCodeObject* buildSettings =
+ this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ this->CreateBuildSettings(cmtarget, buildSettings,
+ configVector[i].c_str());
+ config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
+ config->SetComment(configVector[i].c_str());
+ config->AddAttribute("buildSettings", buildSettings);
+ }
+ if(configVector.size())
+ {
+ configlist->AddAttribute("defaultConfigurationName",
+ this->CreateString(configVector[0].c_str()));
+ configlist->AddAttribute("defaultConfigurationIsVisible",
+ this->CreateString("0"));
+ return configVector[0];
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+const char*
+cmGlobalXCodeGenerator::GetTargetLinkFlagsVar(cmTarget const& cmtarget) const
+{
+ if(this->XcodeVersion >= 60 &&
+ (cmtarget.GetType() == cmTarget::STATIC_LIBRARY ||
+ cmtarget.GetType() == cmTarget::OBJECT_LIBRARY))
+ {
+ return "OTHER_LIBTOOLFLAGS";
+ }
+ else
+ {
+ return "OTHER_LDFLAGS";
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmGlobalXCodeGenerator::GetTargetFileType(cmTarget& cmtarget)
+{
+ switch(cmtarget.GetType())
+ {
+ case cmTarget::OBJECT_LIBRARY:
+ case cmTarget::STATIC_LIBRARY:
+ return "archive.ar";
+ case cmTarget::MODULE_LIBRARY:
+ if (cmtarget.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")?
+ "wrapper.framework" : "compiled.mach-o.dylib");
+ case cmTarget::EXECUTABLE:
+ return "compiled.mach-o.executable";
+ default: break;
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+const char* cmGlobalXCodeGenerator::GetTargetProductType(cmTarget& cmtarget)
+{
+ switch(cmtarget.GetType())
+ {
+ case cmTarget::OBJECT_LIBRARY:
+ case cmTarget::STATIC_LIBRARY:
+ return "com.apple.product-type.library.static";
+ case cmTarget::MODULE_LIBRARY:
+ if (cmtarget.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")?
+ "com.apple.product-type.framework" :
+ "com.apple.product-type.library.dynamic");
+ case cmTarget::EXECUTABLE:
+ return (cmtarget.GetPropertyAsBool("MACOSX_BUNDLE")?
+ "com.apple.product-type.application" :
+ "com.apple.product-type.tool");
+ default: break;
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject*
+cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
+ cmXCodeObject* buildPhases)
+{
+ if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ return 0;
+ }
+ cmXCodeObject* target =
+ this->CreateObject(cmXCodeObject::PBXNativeTarget);
+ target->AddAttribute("buildPhases", buildPhases);
+ cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ target->AddAttribute("buildRules", buildRules);
+ std::string defConfig;
+ if(this->XcodeVersion > 20)
+ {
+ defConfig = this->AddConfigurations(target, cmtarget);
+ }
+ else
+ {
+ cmXCodeObject* buildSettings =
+ this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ defConfig = this->CurrentMakefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ this->CreateBuildSettings(cmtarget, 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()));
+
+ cmXCodeObject* fileRef =
+ this->CreateObject(cmXCodeObject::PBXFileReference);
+ if(const char* fileType = this->GetTargetFileType(cmtarget))
+ {
+ fileRef->AddAttribute("explicitFileType", this->CreateString(fileType));
+ }
+ std::string fullName;
+ if(cmtarget.GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ fullName = "lib";
+ fullName += cmtarget.GetName();
+ fullName += ".a";
+ }
+ else
+ {
+ fullName = cmtarget.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());
+ target->AddAttribute("productReference",
+ this->CreateObjectReference(fileRef));
+ if(const char* productType = this->GetTargetProductType(cmtarget))
+ {
+ target->AddAttribute("productType", this->CreateString(productType));
+ }
+ target->SetTarget(&cmtarget);
+ target->SetId(this->GetOrCreateId(
+ cmtarget.GetName(), target->GetId()).c_str());
+ return target;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget const* t)
+{
+ if(!t)
+ {
+ return 0;
+ }
+ for(std::vector<cmXCodeObject*>::iterator i = this->XCodeObjects.begin();
+ i != this->XCodeObjects.end(); ++i)
+ {
+ cmXCodeObject* o = *i;
+ if(o->GetTarget() == t)
+ {
+ return o;
+ }
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalXCodeGenerator::GetOrCreateId(const std::string& name,
+ const std::string& id)
+{
+ std::string guidStoreName = name;
+ guidStoreName += "_GUID_CMAKE";
+ const char* storedGUID =
+ this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
+
+ if(storedGUID)
+ {
+ return storedGUID;
+ }
+
+ this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
+ id.c_str(), "Stored Xcode object GUID", cmCacheManager::INTERNAL);
+
+ return id;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
+ cmXCodeObject* dependTarget)
+{
+ // This is called once for every edge in the target dependency graph.
+ cmXCodeObject* container =
+ this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
+ container->SetComment("PBXContainerItemProxy");
+ container->AddAttribute("containerPortal",
+ this->CreateObjectReference(this->RootObject));
+ container->AddAttribute("proxyType", this->CreateString("1"));
+ container->AddAttribute("remoteGlobalIDString",
+ this->CreateObjectReference(dependTarget));
+ container->AddAttribute("remoteInfo",
+ this->CreateString(
+ dependTarget->GetTarget()->GetName()));
+ cmXCodeObject* targetdep =
+ this->CreateObject(cmXCodeObject::PBXTargetDependency);
+ targetdep->SetComment("PBXTargetDependency");
+ targetdep->AddAttribute("target",
+ this->CreateObjectReference(dependTarget));
+ targetdep->AddAttribute("targetProxy",
+ this->CreateObjectReference(container));
+
+ cmXCodeObject* depends = target->GetObject("dependencies");
+ if(!depends)
+ {
+ cmSystemTools::
+ Error("target does not have dependencies attribute error..");
+
+ }
+ else
+ {
+ depends->AddUniqueObject(targetdep);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
+ const char* attribute,
+ const char* value)
+{
+ if(settings)
+ {
+ cmXCodeObject* attr = settings->GetObject(attribute);
+ if(!attr)
+ {
+ settings->AddAttribute(attribute, this->CreateString(value));
+ }
+ else
+ {
+ std::string oldValue = attr->GetString();
+ oldValue += " ";
+ oldValue += value;
+ attr->SetString(oldValue.c_str());
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator
+::AppendBuildSettingAttribute(cmXCodeObject* target,
+ const char* attribute,
+ const char* value,
+ const std::string& configName)
+{
+ if(this->XcodeVersion < 21)
+ {
+ // There is only one configuration. Add the setting to the buildSettings
+ // of the target.
+ this->AppendOrAddBuildSetting(target->GetObject("buildSettings"),
+ attribute, value);
+ }
+ else
+ {
+ // There are multiple configurations. Add the setting to the
+ // buildSettings of the configuration name given.
+ cmXCodeObject* configurationList =
+ target->GetObject("buildConfigurationList")->GetObject();
+ cmXCodeObject* buildConfigs =
+ configurationList->GetObject("buildConfigurations");
+ std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList();
+ // each configuration and the target itself has a buildSettings in it
+ //list.push_back(target);
+ for(std::vector<cmXCodeObject*>::iterator i = list.begin();
+ i != list.end(); ++i)
+ {
+ if(!configName.empty())
+ {
+ if((*i)->GetObject("name")->GetString() == configName)
+ {
+ cmXCodeObject* settings = (*i)->GetObject("buildSettings");
+ this->AppendOrAddBuildSetting(settings, attribute, value);
+ }
+ }
+ else
+ {
+ cmXCodeObject* settings = (*i)->GetObject("buildSettings");
+ this->AppendOrAddBuildSetting(settings, attribute, value);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator
+::AddDependAndLinkInformation(cmXCodeObject* target)
+{
+ cmTarget* cmtarget = target->GetTarget();
+ if(cmtarget->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ return;
+ }
+ if(!cmtarget)
+ {
+ cmSystemTools::Error("Error no target on xobject\n");
+ return;
+ }
+
+ // Add dependencies on other CMake targets.
+ TargetDependSet const& deps = this->GetTargetDirectDepends(*cmtarget);
+ for(TargetDependSet::const_iterator i = deps.begin(); i != deps.end(); ++i)
+ {
+ if(cmXCodeObject* dptarget = this->FindXCodeTarget(*i))
+ {
+ this->AddDependTarget(target, dptarget);
+ }
+ }
+
+ // Loop over configuration types and set per-configuration info.
+ for(std::vector<std::string>::iterator i =
+ this->CurrentConfigurationTypes.begin();
+ i != this->CurrentConfigurationTypes.end(); ++i)
+ {
+ // Get the current configuration name.
+ std::string configName = *i;
+
+ if(this->XcodeVersion >= 50)
+ {
+ // Add object library contents as link flags.
+ std::string linkObjs;
+ const char* sep = "";
+ std::vector<std::string> objs;
+ this->GetGeneratorTarget(cmtarget)->UseObjectLibraries(objs, "");
+ for(std::vector<std::string>::const_iterator
+ oi = objs.begin(); oi != objs.end(); ++oi)
+ {
+ linkObjs += sep;
+ sep = " ";
+ linkObjs += this->XCodeEscapePath(oi->c_str());
+ }
+ this->AppendBuildSettingAttribute(
+ target, this->GetTargetLinkFlagsVar(*cmtarget),
+ linkObjs.c_str(), configName);
+ }
+
+ // Skip link information for object libraries.
+ if(cmtarget->GetType() == cmTarget::OBJECT_LIBRARY ||
+ cmtarget->GetType() == cmTarget::STATIC_LIBRARY)
+ {
+ continue;
+ }
+
+ // Compute the link library and directory information.
+ cmComputeLinkInformation* pcli = cmtarget->GetLinkInformation(configName);
+ if(!pcli)
+ {
+ continue;
+ }
+ cmComputeLinkInformation& cli = *pcli;
+
+ // Add dependencies directly on library files.
+ {
+ std::vector<std::string> const& libDeps = cli.GetDepends();
+ for(std::vector<std::string>::const_iterator j = libDeps.begin();
+ j != libDeps.end(); ++j)
+ {
+ target->AddDependLibrary(configName, j->c_str());
+ }
+ }
+
+ // add the library search paths
+ {
+ std::vector<std::string> const& libDirs = cli.GetDirectories();
+ std::string linkDirs;
+ for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
+ libDir != libDirs.end(); ++libDir)
+ {
+ if(libDir->size() && *libDir != "/usr/lib")
+ {
+ if(this->XcodeVersion > 15)
+ {
+ // Now add the same one but append
+ // $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) to it:
+ linkDirs += " ";
+ linkDirs += this->XCodeEscapePath(
+ (*libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)").c_str());
+ }
+ linkDirs += " ";
+ linkDirs += this->XCodeEscapePath(libDir->c_str());
+ }
+ }
+ this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
+ linkDirs.c_str(), configName);
+ }
+
+ // now add the link libraries
+ {
+ std::string linkLibs;
+ const char* sep = "";
+ typedef cmComputeLinkInformation::ItemVector ItemVector;
+ ItemVector const& libNames = cli.GetItems();
+ for(ItemVector::const_iterator li = libNames.begin();
+ li != libNames.end(); ++li)
+ {
+ linkLibs += sep;
+ sep = " ";
+ if(li->IsPath)
+ {
+ linkLibs += this->XCodeEscapePath(li->Value.c_str());
+ }
+ else if (!li->Target
+ || li->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ linkLibs += li->Value;
+ }
+ if(li->Target && !li->Target->IsImported())
+ {
+ target->AddDependTarget(configName, li->Target->GetName());
+ }
+ }
+ this->AppendBuildSettingAttribute(
+ target, this->GetTargetLinkFlagsVar(*cmtarget),
+ linkLibs.c_str(), configName);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>&
+ generators)
+{
+ for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
+ i != generators.end(); ++i)
+ {
+ if(this->IsExcluded(root, *i))
+ {
+ continue;
+ }
+ cmMakefile* mf = (*i)->GetMakefile();
+ std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
+ cmTargets &tgts = mf->GetTargets();
+ for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
+ {
+ cmTarget& cmtarget = l->second;
+
+ // 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)
+ {
+ continue;
+ }
+ if(cmtarget.GetType() == cmTarget::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"))
+ {
+ std::string plist = this->ComputeInfoPListLocation(cmtarget);
+ mf->GetOrCreateSource(plist, true);
+ cmtarget.AddSource(plist);
+ }
+
+ std::vector<cmSourceFile*> classes;
+ if (!cmtarget.GetConfigCommonSourceFiles(classes))
+ {
+ return;
+ }
+ // Put cmSourceFile instances in proper groups:
+ for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
+ s != classes.end(); s++)
+ {
+ cmSourceFile* sf = *s;
+ // Add the file to the list of sources.
+ std::string const& source = sf->GetFullPath();
+ cmSourceGroup* sourceGroup =
+ mf->FindSourceGroup(source.c_str(), sourceGroups);
+ cmXCodeObject* pbxgroup =
+ this->CreateOrGetPBXGroup(cmtarget, sourceGroup);
+ std::string key = GetGroupMapKey(cmtarget, sf);
+ this->GroupMap[key] = pbxgroup;
+ }
+
+ // Put OBJECT_LIBRARY objects in proper groups:
+ std::vector<std::string> objs;
+ this->GetGeneratorTarget(&cmtarget)->UseObjectLibraries(objs, "");
+ for(std::vector<std::string>::const_iterator
+ oi = objs.begin(); oi != objs.end(); ++oi)
+ {
+ std::string const& source = *oi;
+ cmSourceGroup* sourceGroup =
+ mf->FindSourceGroup(source.c_str(), sourceGroups);
+ cmXCodeObject* pbxgroup =
+ this->CreateOrGetPBXGroup(cmtarget, sourceGroup);
+ std::string key = GetGroupMapKeyFromPath(cmtarget, source);
+ this->GroupMap[key] = pbxgroup;
+ }
+ }
+ }
+}
+
+cmXCodeObject *cmGlobalXCodeGenerator
+::CreatePBXGroup(cmXCodeObject *parent, std::string name)
+{
+ cmXCodeObject* parentChildren = NULL;
+ if(parent)
+ parentChildren = parent->GetObject("children");
+ cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
+ cmXCodeObject* groupChildren =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ group->AddAttribute("name", this->CreateString(name.c_str()));
+ group->AddAttribute("children", groupChildren);
+ if(this->XcodeVersion == 15)
+ {
+ group->AddAttribute("refType", this->CreateString("4"));
+ }
+ group->AddAttribute("sourceTree", this->CreateString("<group>"));
+ if(parentChildren)
+ parentChildren->AddObject(group);
+ return group;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject* cmGlobalXCodeGenerator
+::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg)
+{
+ std::string s;
+ std::string target;
+ const char *targetFolder= cmtarget.GetProperty("FOLDER");
+ if(targetFolder) {
+ target = targetFolder;
+ target += "/";
+ }
+ target += cmtarget.GetName();
+ s = target + "/";
+ s += sg->GetFullName();
+ std::map<std::string, cmXCodeObject* >::iterator it =
+ this->GroupNameMap.find(s);
+ if(it != this->GroupNameMap.end())
+ {
+ return it->second;
+ }
+
+ it = this->TargetGroup.find(target);
+ cmXCodeObject* tgroup = 0;
+ if(it != this->TargetGroup.end())
+ {
+ tgroup = it->second;
+ }
+ else
+ {
+ std::vector<std::string> tgt_folders =
+ cmSystemTools::tokenize(target, "/");
+ std::string curr_tgt_folder;
+ for(std::vector<std::string>::size_type i = 0; i < tgt_folders.size();i++)
+ {
+ if (i != 0)
+ {
+ curr_tgt_folder += "/";
+ }
+ curr_tgt_folder += tgt_folders[i];
+ it = this->TargetGroup.find(curr_tgt_folder);
+ if(it != this->TargetGroup.end())
+ {
+ tgroup = it->second;
+ continue;
+ }
+ tgroup = this->CreatePBXGroup(tgroup,tgt_folders[i]);
+ this->TargetGroup[curr_tgt_folder] = tgroup;
+ if(i == 0)
+ {
+ this->SourcesGroupChildren->AddObject(tgroup);
+ }
+ }
+ }
+ this->TargetGroup[target] = tgroup;
+
+ // If it's the default source group (empty name) then put the source file
+ // directly in the tgroup...
+ //
+ if (std::string(sg->GetFullName()) == "")
+ {
+ this->GroupNameMap[s] = tgroup;
+ return tgroup;
+ }
+
+ //It's a recursive folder structure, let's find the real parent group
+ if(std::string(sg->GetFullName()) != std::string(sg->GetName()))
+ {
+ std::vector<std::string> folders =
+ cmSystemTools::tokenize(sg->GetFullName(), "\\");
+ std::string curr_folder = target;
+ curr_folder += "/";
+ for(std::vector<std::string>::size_type i = 0; i < folders.size();i++)
+ {
+ curr_folder += folders[i];
+ std::map<std::string, cmXCodeObject* >::iterator i_folder =
+ this->GroupNameMap.find(curr_folder);
+ //Create new folder
+ if(i_folder == this->GroupNameMap.end())
+ {
+ cmXCodeObject *group = this->CreatePBXGroup(tgroup,folders[i]);
+ this->GroupNameMap[curr_folder] = group;
+ tgroup = group;
+ }
+ else
+ {
+ tgroup = i_folder->second;
+ }
+ curr_folder = curr_folder + "\\";
+ }
+ return tgroup;
+ }
+ cmXCodeObject *group = this->CreatePBXGroup(tgroup,sg->GetName());
+ this->GroupNameMap[s] = group;
+ return group;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator
+::CreateXCodeObjects(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>&
+ generators)
+{
+ this->ClearXCodeObjects();
+ this->RootObject = 0;
+ this->SourcesGroupChildren = 0;
+ this->ResourcesGroupChildren = 0;
+ this->MainGroupChildren = 0;
+ cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
+ cmXCodeObject* developBuildStyle =
+ this->CreateObject(cmXCodeObject::PBXBuildStyle);
+ cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ if(this->XcodeVersion == 15)
+ {
+ developBuildStyle->AddAttribute("name",
+ this->CreateString("Development"));
+ developBuildStyle->AddAttribute("buildSettings", group);
+ listObjs->AddObject(developBuildStyle);
+ group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
+ cmXCodeObject* deployBuildStyle =
+ this->CreateObject(cmXCodeObject::PBXBuildStyle);
+ deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
+ deployBuildStyle->AddAttribute("buildSettings", group);
+ listObjs->AddObject(deployBuildStyle);
+ }
+ else
+ {
+ for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
+ {
+ cmXCodeObject* buildStyle =
+ this->CreateObject(cmXCodeObject::PBXBuildStyle);
+ const char* name = this->CurrentConfigurationTypes[i].c_str();
+ buildStyle->AddAttribute("name", this->CreateString(name));
+ buildStyle->SetComment(name);
+ cmXCodeObject* sgroup =
+ this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ sgroup->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
+ buildStyle->AddAttribute("buildSettings", sgroup);
+ listObjs->AddObject(buildStyle);
+ }
+ }
+
+ cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
+ this->MainGroupChildren =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ mainGroup->AddAttribute("children", this->MainGroupChildren);
+ if(this->XcodeVersion == 15)
+ {
+ mainGroup->AddAttribute("refType", this->CreateString("4"));
+ }
+ mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
+
+ cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
+ this->SourcesGroupChildren =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
+ sourcesGroup->AddAttribute("children", this->SourcesGroupChildren);
+ if(this->XcodeVersion == 15)
+ {
+ sourcesGroup->AddAttribute("refType", this->CreateString("4"));
+ }
+ sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
+ this->MainGroupChildren->AddObject(sourcesGroup);
+
+ cmXCodeObject* resourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
+ this->ResourcesGroupChildren =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ resourcesGroup->AddAttribute("name", this->CreateString("Resources"));
+ resourcesGroup->AddAttribute("children", this->ResourcesGroupChildren);
+ if(this->XcodeVersion == 15)
+ {
+ resourcesGroup->AddAttribute("refType", this->CreateString("4"));
+ }
+ resourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
+ this->MainGroupChildren->AddObject(resourcesGroup);
+
+ // now create the cmake groups
+ this->CreateGroups(root, generators);
+
+ cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
+ productGroup->AddAttribute("name", this->CreateString("Products"));
+ if(this->XcodeVersion == 15)
+ {
+ productGroup->AddAttribute("refType", this->CreateString("4"));
+ }
+ productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
+ cmXCodeObject* productGroupChildren =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ productGroup->AddAttribute("children", productGroupChildren);
+ this->MainGroupChildren->AddObject(productGroup);
+
+
+ this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
+ this->RootObject->SetComment("Project object");
+
+ std::string project_id = "PROJECT_";
+ project_id += root->GetMakefile()->GetProjectName();
+ this->RootObject->SetId(this->GetOrCreateId(
+ project_id.c_str(), this->RootObject->GetId()).c_str());
+
+ group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ this->RootObject->AddAttribute("mainGroup",
+ this->CreateObjectReference(mainGroup));
+ this->RootObject->AddAttribute("buildSettings", group);
+ this->RootObject->AddAttribute("buildStyles", listObjs);
+ this->RootObject->AddAttribute("hasScannedForEncodings",
+ this->CreateString("0"));
+ if (this->XcodeVersion >= 30)
+ {
+ group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ group->AddAttribute("BuildIndependentTargetsInParallel",
+ this->CreateString("YES"));
+ this->RootObject->AddAttribute("attributes", group);
+ if (this->XcodeVersion >= 32)
+ this->RootObject->AddAttribute("compatibilityVersion",
+ this->CreateString("Xcode 3.2"));
+ else if (this->XcodeVersion >= 31)
+ this->RootObject->AddAttribute("compatibilityVersion",
+ this->CreateString("Xcode 3.1"));
+ else
+ this->RootObject->AddAttribute("compatibilityVersion",
+ this->CreateString("Xcode 3.0"));
+ }
+ // Point Xcode at the top of the source tree.
+ {
+ std::string pdir =
+ this->RelativeToBinary(root->GetMakefile()->GetCurrentDirectory());
+ this->RootObject->AddAttribute("projectDirPath",
+ this->CreateString(pdir.c_str()));
+ this->RootObject->AddAttribute("projectRoot", this->CreateString(""));
+ }
+ cmXCodeObject* configlist =
+ this->CreateObject(cmXCodeObject::XCConfigurationList);
+ cmXCodeObject* buildConfigurations =
+ this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ std::vector<cmXCodeObject*> 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);
+ cmXCodeObject* configRelease =
+ this->CreateObject(cmXCodeObject::XCBuildConfiguration);
+ configRelease->AddAttribute("name", this->CreateString("Release"));
+ configs.push_back(configRelease);
+ }
+ else
+ {
+ for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i)
+ {
+ const char* name = this->CurrentConfigurationTypes[i].c_str();
+ if (0 == i)
+ {
+ defaultConfigName = name;
+ }
+ cmXCodeObject* config =
+ this->CreateObject(cmXCodeObject::XCBuildConfiguration);
+ config->AddAttribute("name", this->CreateString(name));
+ configs.push_back(config);
+ }
+ }
+ for(std::vector<cmXCodeObject*>::iterator c = configs.begin();
+ c != configs.end(); ++c)
+ {
+ buildConfigurations->AddObject(*c);
+ }
+ configlist->AddAttribute("buildConfigurations", buildConfigurations);
+
+ std::string comment = "Build configuration list for PBXProject ";
+ comment += " \"";
+ comment += this->CurrentProject;
+ comment += "\"";
+ configlist->SetComment(comment.c_str());
+ configlist->AddAttribute("defaultConfigurationIsVisible",
+ this->CreateString("0"));
+ configlist->AddAttribute("defaultConfigurationName",
+ this->CreateString(defaultConfigName));
+ cmXCodeObject* buildSettings =
+ this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
+ const char* osxArch =
+ this->CurrentMakefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
+ if(!osxArch || strlen(osxArch) == 0)
+ {
+ if(this->XcodeVersion >= 32)
+ {
+ osxArch = "$(ARCHS_STANDARD_32_64_BIT)";
+ }
+ else if(this->XcodeVersion == 31)
+ {
+ osxArch = "$(ARCHS_STANDARD_32_BIT)";
+ }
+ else if(this->XcodeVersion <= 30)
+ {
+#ifdef __ppc__
+ osxArch = "ppc";
+#endif
+#ifdef __i386
+ osxArch = "i386";
+#endif
+ }
+ buildSettings->AddAttribute("ONLY_ACTIVE_ARCH",
+ this->CreateString("YES"));
+ }
+
+ const char* sysroot =
+ this->CurrentMakefile->GetDefinition("CMAKE_OSX_SYSROOT");
+ const char* deploymentTarget =
+ this->CurrentMakefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
+ if(osxArch && sysroot)
+ {
+ // recompute this as it may have been changed since enable language
+ this->Architectures.clear();
+ cmSystemTools::ExpandListArgument(std::string(osxArch),
+ this->Architectures);
+ buildSettings->AddAttribute("SDKROOT",
+ this->CreateString(sysroot));
+ std::string archString;
+ const char* sep = "";
+ for( std::vector<std::string>::iterator i =
+ this->Architectures.begin();
+ i != this->Architectures.end(); ++i)
+ {
+ archString += sep;
+ archString += *i;
+ sep = " ";
+ }
+ buildSettings->AddAttribute("ARCHS",
+ this->CreateString(archString.c_str()));
+ }
+ if(deploymentTarget && *deploymentTarget)
+ {
+ buildSettings->AddAttribute("MACOSX_DEPLOYMENT_TARGET",
+ this->CreateString(deploymentTarget));
+ }
+ if(!this->GeneratorToolset.empty())
+ {
+ buildSettings->AddAttribute("GCC_VERSION",
+ 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()->GetCurrentOutputDirectory();
+ symroot += "/build";
+ buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot.c_str()));
+
+ for( std::vector<cmXCodeObject*>::iterator i = configs.begin();
+ i != configs.end(); ++i)
+ {
+ (*i)->AddAttribute("buildSettings", buildSettings);
+ }
+
+ this->RootObject->AddAttribute("buildConfigurationList",
+ this->CreateObjectReference(configlist));
+
+ std::vector<cmXCodeObject*> targets;
+ for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
+ i != generators.end(); ++i)
+ {
+ if(!this->IsExcluded(root, *i))
+ {
+ this->CreateXCodeTargets(*i, targets);
+ }
+ }
+ // loop over all targets and add link and depend info
+ for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
+ i != targets.end(); ++i)
+ {
+ cmXCodeObject* t = *i;
+ this->AddDependAndLinkInformation(t);
+ }
+ if(this->XcodeVersion < 50)
+ {
+ // now create xcode depend hack makefile
+ this->CreateXCodeDependHackTarget(targets);
+ }
+ // now add all targets to the root object
+ cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
+ i != targets.end(); ++i)
+ {
+ cmXCodeObject* t = *i;
+ allTargets->AddObject(t);
+ cmXCodeObject* productRef = t->GetObject("productReference");
+ if(productRef)
+ {
+ productGroupChildren->AddObject(productRef->GetObject());
+ }
+ }
+ this->RootObject->AddAttribute("targets", allTargets);
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalXCodeGenerator::GetObjectsNormalDirectory(
+ const std::string &projName,
+ const std::string &configName,
+ const cmTarget *t) const
+{
+ std::string dir =
+ t->GetMakefile()->GetCurrentOutputDirectory();
+ dir += "/";
+ dir += projName;
+ dir += ".build/";
+ dir += configName;
+ dir += "/";
+ dir += t->GetName();
+ dir += ".build/Objects-normal/";
+
+ return dir;
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
+ std::vector<cmXCodeObject*>& targets)
+{
+ cmGeneratedFileStream
+ makefileStream(this->CurrentXCodeHackMakefile.c_str());
+ if(!makefileStream)
+ {
+ cmSystemTools::Error("Could not create",
+ this->CurrentXCodeHackMakefile.c_str());
+ return;
+ }
+ makefileStream.SetCopyIfDifferent(true);
+ // one more pass for external depend information not handled
+ // correctly by xcode
+ makefileStream << "# DO NOT EDIT\n";
+ makefileStream << "# This makefile makes sure all linkable targets are\n";
+ makefileStream << "# up-to-date with anything they link to\n"
+ "default:\n"
+ "\techo \"Do not invoke directly\"\n"
+ "\n";
+ makefileStream
+ << "# For each target create a dummy rule "
+ "so the target does not have to exist\n";
+ std::set<std::string> emitted;
+ for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
+ i != targets.end(); ++i)
+ {
+ cmXCodeObject* target = *i;
+ std::map<std::string, cmXCodeObject::StringVec> const& deplibs =
+ target->GetDependLibraries();
+ for(std::map<std::string, cmXCodeObject::StringVec>::const_iterator ci
+ = deplibs.begin(); ci != deplibs.end(); ++ci)
+ {
+ for(cmXCodeObject::StringVec::const_iterator d = ci->second.begin();
+ d != ci->second.end(); ++d)
+ {
+ if(emitted.insert(*d).second)
+ {
+ makefileStream <<
+ this->ConvertToRelativeForMake(d->c_str()) << ":\n";
+ }
+ }
+ }
+ }
+ makefileStream << "\n\n";
+
+ // Write rules to help Xcode relink things at the right time.
+ makefileStream <<
+ "# Rules to remove targets that are older than anything to which they\n"
+ "# link. This forces Xcode to relink the targets from scratch. It\n"
+ "# does not seem to check these dependencies itself.\n";
+ for(std::vector<std::string>::const_iterator
+ ct = this->CurrentConfigurationTypes.begin();
+ ct != this->CurrentConfigurationTypes.end(); ++ct)
+ {
+ std::string configName = *ct;
+ for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
+ i != targets.end(); ++i)
+ {
+ cmXCodeObject* target = *i;
+ cmTarget* t =target->GetTarget();
+
+ if(t->GetType() == cmTarget::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)
+ {
+ // Declare an entry point for the target post-build phase.
+ makefileStream << this->PostBuildMakeTarget(t->GetName(), *ct)
+ << ":\n";
+ }
+
+ if(t->GetType() == cmTarget::EXECUTABLE ||
+ t->GetType() == cmTarget::SHARED_LIBRARY ||
+ t->GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ std::string tfull = t->GetFullPath(configName);
+ std::string trel = this->ConvertToRelativeForMake(tfull.c_str());
+
+ // Add this target to the post-build phases of its dependencies.
+ std::map<std::string, cmXCodeObject::StringVec>::const_iterator
+ y = target->GetDependTargets().find(*ct);
+ if(y != target->GetDependTargets().end())
+ {
+ std::vector<std::string> const& deptgts = y->second;
+ for(std::vector<std::string>::const_iterator d = deptgts.begin();
+ d != deptgts.end(); ++d)
+ {
+ makefileStream << this->PostBuildMakeTarget(*d, *ct) << ": "
+ << trel << "\n";
+ }
+ }
+
+ // Create a rule for this target.
+ makefileStream << trel << ":";
+
+ // List dependencies if any exist.
+ std::map<std::string, cmXCodeObject::StringVec>::const_iterator
+ x = target->GetDependLibraries().find(*ct);
+ if(x != target->GetDependLibraries().end())
+ {
+ std::vector<std::string> const& deplibs = x->second;
+ for(std::vector<std::string>::const_iterator d = deplibs.begin();
+ d != deplibs.end(); ++d)
+ {
+ makefileStream << "\\\n\t" <<
+ this->ConvertToRelativeForMake(d->c_str());
+ }
+ }
+ // Write the action to remove the target if it is out of date.
+ makefileStream << "\n";
+ makefileStream << "\t/bin/rm -f "
+ << this->ConvertToRelativeForMake(tfull.c_str())
+ << "\n";
+ // if building for more than one architecture
+ // then remove those exectuables as well
+ if(this->Architectures.size() > 1)
+ {
+ std::string universal = this->GetObjectsNormalDirectory(
+ this->CurrentProject, configName, t);
+ for( std::vector<std::string>::iterator arch =
+ this->Architectures.begin();
+ arch != this->Architectures.end(); ++arch)
+ {
+ std::string universalFile = universal;
+ universalFile += *arch;
+ universalFile += "/";
+ universalFile += t->GetFullName(configName);
+ makefileStream << "\t/bin/rm -f "
+ <<
+ this->ConvertToRelativeForMake(universalFile.c_str())
+ << "\n";
+ }
+ }
+ makefileStream << "\n\n";
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>&
+ generators)
+{
+ if(generators.size() == 0)
+ {
+ return;
+ }
+ // Skip local generators that are excluded from this project.
+ for(std::vector<cmLocalGenerator*>::iterator g = generators.begin();
+ g != generators.end(); ++g)
+ {
+ if(this->IsExcluded(root, *g))
+ {
+ continue;
+ }
+ }
+
+ this->CreateXCodeObjects(root,
+ generators);
+ std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
+ xcodeDir += "/";
+ xcodeDir += root->GetMakefile()->GetProjectName();
+ xcodeDir += ".xcode";
+ if(this->XcodeVersion > 20)
+ {
+ xcodeDir += "proj";
+ }
+ cmSystemTools::MakeDirectory(xcodeDir.c_str());
+ std::string xcodeProjFile = xcodeDir + "/project.pbxproj";
+ cmGeneratedFileStream fout(xcodeProjFile.c_str());
+ fout.SetCopyIfDifferent(true);
+ if(!fout)
+ {
+ return;
+ }
+ this->WriteXCodePBXProj(fout, root, generators);
+ this->ClearXCodeObjects();
+
+ // Since this call may have created new cache entries, save the cache:
+ //
+ root->GetMakefile()->GetCacheManager()->SaveCache(
+ root->GetMakefile()->GetHomeOutputDirectory());
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
+ cmLocalGenerator* ,
+ std::vector<cmLocalGenerator*>& )
+{
+ fout << "// !$*UTF8*$!\n";
+ fout << "{\n";
+ cmXCodeObject::Indent(1, fout);
+ fout << "archiveVersion = 1;\n";
+ cmXCodeObject::Indent(1, fout);
+ fout << "classes = {\n";
+ cmXCodeObject::Indent(1, fout);
+ fout << "};\n";
+ cmXCodeObject::Indent(1, fout);
+ if(this->XcodeVersion >= 21)
+ {
+ if (this->XcodeVersion >= 32)
+ fout << "objectVersion = 46;\n";
+ else if (this->XcodeVersion >= 31)
+ fout << "objectVersion = 45;\n";
+ else if (this->XcodeVersion >= 30)
+ fout << "objectVersion = 44;\n";
+ else
+ fout << "objectVersion = 42;\n";
+ cmXCode21Object::PrintList(this->XCodeObjects, fout);
+ }
+ else
+ {
+ fout << "objectVersion = 39;\n";
+ cmXCodeObject::PrintList(this->XCodeObjects, fout);
+ }
+ cmXCodeObject::Indent(1, fout);
+ fout << "rootObject = " << this->RootObject->GetId() << ";\n";
+ fout << "}\n";
+}
+
+//----------------------------------------------------------------------------
+const char* cmGlobalXCodeGenerator::GetCMakeCFGIntDir() const
+{
+ return this->XcodeVersion >= 21 ?
+ "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" : ".";
+}
+
+std::string cmGlobalXCodeGenerator::ExpandCFGIntDir(const std::string& str,
+ const std::string& config) const
+{
+ std::string replace1 = "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
+ std::string replace2 = "$(CONFIGURATION)";
+
+ std::string tmp = str;
+ for(std::string::size_type i = tmp.find(replace1);
+ i != std::string::npos;
+ i = tmp.find(replace1, i))
+ {
+ tmp.replace(i, replace1.size(), config);
+ i += config.size();
+ }
+ for(std::string::size_type i = tmp.find(replace2);
+ i != std::string::npos;
+ i = tmp.find(replace2, i))
+ {
+ tmp.replace(i, replace2.size(), config);
+ i += config.size();
+ }
+ return tmp;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
+{
+ entry.Name = cmGlobalXCodeGenerator::GetActualName();
+ entry.Brief = "Generate Xcode project files.";
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
+{
+ if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
+ {
+ return cmSystemTools::ConvertToOutputPath(p);
+ }
+ else
+ {
+ std::string ret =
+ this->CurrentLocalGenerator->
+ ConvertToRelativePath(this->CurrentOutputDirectoryComponents, p);
+ return cmSystemTools::ConvertToOutputPath(ret.c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p)
+{
+ if ( !this->CurrentMakefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
+ {
+ return cmSystemTools::ConvertToOutputPath(p);
+ }
+ else
+ {
+ std::string ret =
+ this->CurrentLocalGenerator->
+ ConvertToRelativePath(this->ProjectOutputDirectoryComponents, p);
+ return cmSystemTools::ConvertToOutputPath(ret.c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalXCodeGenerator::RelativeToSource(const char* p)
+{
+ // We force conversion because Xcode breakpoints do not work unless
+ // they are in a file named relative to the source tree.
+ return this->CurrentLocalGenerator->
+ ConvertToRelativePath(this->ProjectSourceDirectoryComponents, p, true);
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalXCodeGenerator::RelativeToBinary(const char* p)
+{
+ return this->CurrentLocalGenerator->
+ ConvertToRelativePath(this->ProjectOutputDirectoryComponents, p);
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
+{
+ std::string ret = p;
+ if(ret.find(' ') != ret.npos)
+ {
+ std::string t = ret;
+ ret = "\"";
+ ret += t;
+ ret += "\"";
+ }
+ return ret;
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalXCodeGenerator
+::AppendDirectoryForConfig(const std::string& prefix,
+ const std::string& config,
+ const std::string& suffix,
+ std::string& dir)
+{
+ if(this->XcodeVersion > 20)
+ {
+ if(!config.empty())
+ {
+ dir += prefix;
+ dir += config;
+ dir += suffix;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalXCodeGenerator::LookupFlags(
+ const std::string& varNamePrefix,
+ const std::string& varNameLang,
+ const std::string& varNameSuffix,
+ const std::string& default_flags)
+{
+ if(!varNameLang.empty())
+ {
+ std::string varName = varNamePrefix;
+ varName += varNameLang;
+ varName += varNameSuffix;
+ if(const char* varValue =
+ this->CurrentMakefile->GetDefinition(varName.c_str()))
+ {
+ if(*varValue)
+ {
+ return varValue;
+ }
+ }
+ }
+ return default_flags;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::AppendDefines(BuildObjectListOrString& defs,
+ const char* defines_list,
+ bool dflag)
+{
+ // Skip this if there are no definitions.
+ if(!defines_list)
+ {
+ return;
+ }
+
+ // Expand the list of definitions.
+ std::vector<std::string> defines;
+ cmSystemTools::ExpandListArgument(defines_list, defines);
+
+ // Store the definitions in the string.
+ this->AppendDefines(defs, defines, dflag);
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalXCodeGenerator::AppendDefines(BuildObjectListOrString& defs,
+ std::vector<std::string> const& defines,
+ bool dflag)
+{
+ // GCC_PREPROCESSOR_DEFINITIONS is a space-separated list of definitions.
+ std::string def;
+ for(std::vector<std::string>::const_iterator di = defines.begin();
+ di != defines.end(); ++di)
+ {
+ // Start with -D if requested.
+ def = dflag? "-D": "";
+ def += *di;
+
+ // Append the flag with needed escapes.
+ std::string tmp;
+ this->AppendFlag(tmp, def);
+ defs.Add(tmp.c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::AppendFlag(std::string& flags,
+ std::string const& flag)
+{
+ // Short-circuit for an empty flag.
+ if(flag.empty())
+ {
+ return;
+ }
+
+ // Separate from previous flags.
+ if(!flags.empty())
+ {
+ flags += " ";
+ }
+
+ // Check if the flag needs quoting.
+ bool quoteFlag =
+ flag.find_first_of("`~!@#$%^&*()+={}[]|:;\"'<>,.? ") != flag.npos;
+
+ // 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
+ // Note that in the code below we need one more level of escapes for
+ // C string syntax in this source file.
+ //
+ // The final level of escaping is done when the string is stored
+ // into the project file by cmXCodeObject::PrintString.
+
+ if(quoteFlag)
+ {
+ // Open single quote.
+ flags += "'";
+ }
+
+ // Flag value with escaped quotes and backslashes.
+ for(const char* c = flag.c_str(); *c; ++c)
+ {
+ if(*c == '\'')
+ {
+ if (this->XcodeVersion >= 40)
+ {
+ flags += "'\\\\''";
+ }
+ else
+ {
+ flags += "\\\\'";
+ }
+ }
+ else if(*c == '\\')
+ {
+ flags += "\\\\\\\\";
+ }
+ else
+ {
+ flags += *c;
+ }
+ }
+
+ if(quoteFlag)
+ {
+ // Close single quote.
+ flags += "'";
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGlobalXCodeGenerator::ComputeInfoPListLocation(cmTarget& target)
+{
+ std::string plist = target.GetMakefile()->GetCurrentOutputDirectory();
+ plist += cmake::GetCMakeFilesDirectory();
+ plist += "/";
+ plist += target.GetName();
+ plist += ".dir/Info.plist";
+ return plist;
+}
+
+//----------------------------------------------------------------------------
+// Return true if the generated build tree may contain multiple builds.
+// i.e. "Can I build Debug and Release in the same tree?"
+bool cmGlobalXCodeGenerator::IsMultiConfig()
+{
+ // Old Xcode 1.5 is single config:
+ if(this->XcodeVersion == 15)
+ {
+ return false;
+ }
+
+ // Newer Xcode versions are multi config:
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator
+::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const
+{
+ std::string configName = this->GetCMakeCFGIntDir();
+ std::string dir = this->GetObjectsNormalDirectory(
+ "$(PROJECT_NAME)", configName, gt->Target);
+ if(this->XcodeVersion >= 21)
+ {
+ dir += "$(CURRENT_ARCH)/";
+ }
+ else
+ {
+#ifdef __ppc__
+ dir += "ppc/";
+#endif
+#ifdef __i386
+ dir += "i386/";
+#endif
+ }
+ gt->ObjectDirectory = dir;
+}
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
new file mode 100644
index 0000000000..9d7b784ad4
--- /dev/null
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -0,0 +1,248 @@
+/*============================================================================
+ 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 cmGlobalXCodeGenerator_h
+#define cmGlobalXCodeGenerator_h
+
+#include "cmGlobalGenerator.h"
+#include "cmXCodeObject.h"
+#include "cmCustomCommand.h"
+class cmGlobalGeneratorFactory;
+class cmTarget;
+class cmSourceFile;
+class cmSourceGroup;
+
+
+/** \class cmGlobalXCodeGenerator
+ * \brief Write a Unix makefiles.
+ *
+ * cmGlobalXCodeGenerator manages UNIX build process for a tree
+ */
+class cmGlobalXCodeGenerator : public cmGlobalGenerator
+{
+public:
+ cmGlobalXCodeGenerator(std::string const& version);
+ static cmGlobalGeneratorFactory* NewFactory();
+
+ ///! Get the name for the generator.
+ virtual std::string GetName() const {
+ return cmGlobalXCodeGenerator::GetActualName();}
+ static std::string GetActualName() {return "Xcode";}
+
+ /** Get the documentation entry for this generator. */
+ static void GetDocumentation(cmDocumentationEntry& entry);
+
+ ///! Create a local generator appropriate to this Global Generator
+ virtual cmLocalGenerator *CreateLocalGenerator();
+
+ /**
+ * Try to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ virtual void EnableLanguage(std::vector<std::string>const& languages,
+ cmMakefile *, bool optional);
+ /**
+ * Try running cmake and building a file. This is used for dynalically
+ * loaded commands, not as part of the usual build process.
+ */
+ virtual void GenerateBuildCommand(
+ std::vector<std::string>& makeCommand,
+ const std::string& makeProgram,
+ const std::string& projectName,
+ const std::string& projectDir,
+ const std::string& targetName,
+ const std::string& config,
+ bool fast,
+ std::vector<std::string> const& makeOptions = std::vector<std::string>()
+ );
+
+ /** Append the subdirectory for the given configuration. */
+ virtual void AppendDirectoryForConfig(const std::string& prefix,
+ const std::string& config,
+ const std::string& suffix,
+ std::string& dir);
+
+ ///! What is the configurations directory variable called?
+ virtual const char* GetCMakeCFGIntDir() const;
+ ///! expand CFGIntDir
+ virtual std::string ExpandCFGIntDir(const std::string& str,
+ const std::string& config) const;
+
+ void SetCurrentLocalGenerator(cmLocalGenerator*);
+
+ /** Return true if the generated build tree may contain multiple builds.
+ i.e. "Can I build Debug and Release in the same tree?" */
+ virtual bool IsMultiConfig();
+
+ virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf);
+ void AppendFlag(std::string& flags, std::string const& flag);
+protected:
+ virtual void Generate();
+private:
+ cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget,
+ cmSourceGroup* sg);
+ cmXCodeObject* CreatePBXGroup(cmXCodeObject *parent,
+ std::string name);
+ void CreateGroups(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>&
+ generators);
+ 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,
+ cmXCodeObject* headerBuildPhase,
+ cmXCodeObject* resourceBuildPhase,
+ std::vector<cmXCodeObject*> contentBuildPhases,
+ cmXCodeObject* frameworkBuildPhase,
+ cmTarget& cmtarget);
+
+ std::string ComputeInfoPListLocation(cmTarget& target);
+
+ void AddCommandsToBuildPhase(cmXCodeObject* buildphase,
+ cmTarget& target,
+ std::vector<cmCustomCommand>
+ const & commands,
+ const char* commandFileName);
+
+ void CreateCustomRulesMakefile(const char* makefileBasename,
+ cmTarget& target,
+ std::vector<cmCustomCommand> const & commands,
+ const std::string& configName,
+ bool& haveMultipleOutputPairs);
+
+ cmXCodeObject* FindXCodeTarget(cmTarget const*);
+ std::string GetOrCreateId(const std::string& name, const std::string& id);
+
+ // create cmXCodeObject from these functions so that memory can be managed
+ // correctly. All objects created are stored in this->XCodeObjects.
+ cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
+ cmXCodeObject* CreateObject(cmXCodeObject::Type type);
+ cmXCodeObject* CreateString(const std::string& s);
+ cmXCodeObject* CreateObjectReference(cmXCodeObject*);
+ cmXCodeObject* CreateXCodeTarget(cmTarget& target,
+ 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 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);
+ void AddDependAndLinkInformation(cmXCodeObject* target);
+ void CreateBuildSettings(cmTarget& target,
+ cmXCodeObject* buildSettings,
+ const std::string& buildType);
+ std::string ExtractFlag(const char* flag, std::string& flags);
+ // delete all objects in the this->XCodeObjects vector.
+ void ClearXCodeObjects();
+ void CreateXCodeObjects(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+ void OutputXCodeProject(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+ void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+ cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string &fullpath,
+ cmTarget& cmtarget,
+ const std::string &lang,
+ cmSourceFile* sf);
+ cmXCodeObject* CreateXCodeSourceFileFromPath(const std::string &fullpath,
+ cmTarget& cmtarget,
+ const std::string &lang,
+ cmSourceFile* sf);
+ cmXCodeObject* CreateXCodeFileReference(cmSourceFile* sf,
+ cmTarget& cmtarget);
+ cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen,
+ cmSourceFile* sf,
+ cmTarget& cmtarget);
+ void CreateXCodeTargets(cmLocalGenerator* gen,
+ std::vector<cmXCodeObject*>&);
+ bool IsHeaderFile(cmSourceFile*);
+ void AddDependTarget(cmXCodeObject* target,
+ cmXCodeObject* dependTarget);
+ void CreateXCodeDependHackTarget(std::vector<cmXCodeObject*>& targets);
+ bool SpecialTargetEmitted(std::string const& tname);
+ void SetGenerationRoot(cmLocalGenerator* root);
+ void AddExtraTargets(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& gens);
+ cmXCodeObject* CreateBuildPhase(const char* name,
+ const char* name2,
+ cmTarget& cmtarget,
+ const std::vector<cmCustomCommand>&);
+ void CreateReRunCMakeFile(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*> const& gens);
+
+ std::string LookupFlags(const std::string& varNamePrefix,
+ const std::string& varNameLang,
+ const std::string& varNameSuffix,
+ const std::string& default_flags);
+
+ class Factory;
+ class BuildObjectListOrString;
+ friend class BuildObjectListOrString;
+
+ void AppendDefines(BuildObjectListOrString& defs, const char* defines_list,
+ bool dflag = false);
+ void AppendDefines(BuildObjectListOrString& defs,
+ std::vector<std::string> const& defines,
+ bool dflag = false);
+
+ void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
+protected:
+ virtual const char* GetInstallTargetName() const { return "install"; }
+ virtual const char* GetPackageTargetName() const { return "package"; }
+
+ unsigned int XcodeVersion;
+ std::string VersionString;
+ std::set<std::string> XCodeObjectIDs;
+ std::vector<cmXCodeObject*> XCodeObjects;
+ cmXCodeObject* RootObject;
+private:
+ void PrintCompilerAdvice(std::ostream&, std::string const&,
+ const char*) const {}
+
+ std::string GetObjectsNormalDirectory(
+ const std::string &projName,
+ const std::string &configName,
+ const cmTarget *t) const;
+
+ void addObject(cmXCodeObject *obj);
+ std::string PostBuildMakeTarget(std::string const& tName,
+ std::string const& configName);
+ cmXCodeObject* MainGroupChildren;
+ cmXCodeObject* SourcesGroupChildren;
+ cmXCodeObject* ResourcesGroupChildren;
+ cmMakefile* CurrentMakefile;
+ cmLocalGenerator* CurrentLocalGenerator;
+ std::vector<std::string> CurrentConfigurationTypes;
+ std::string CurrentReRunCMakeMakefile;
+ std::string CurrentXCodeHackMakefile;
+ std::string CurrentProject;
+ std::set<std::string> TargetDoneSet;
+ std::vector<std::string> CurrentOutputDirectoryComponents;
+ std::vector<std::string> ProjectSourceDirectoryComponents;
+ std::vector<std::string> ProjectOutputDirectoryComponents;
+ std::map<std::string, cmXCodeObject* > GroupMap;
+ std::map<std::string, cmXCodeObject* > GroupNameMap;
+ std::map<std::string, cmXCodeObject* > TargetGroup;
+ std::map<std::string, cmXCodeObject* > FileRefs;
+ std::vector<std::string> Architectures;
+ std::string GeneratorToolset;
+};
+
+#endif
diff --git a/Source/cmGraphAdjacencyList.h b/Source/cmGraphAdjacencyList.h
new file mode 100644
index 0000000000..0149d33bd7
--- /dev/null
+++ b/Source/cmGraphAdjacencyList.h
@@ -0,0 +1,40 @@
+/*============================================================================
+ 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 cmGraphAdjacencyList_h
+#define cmGraphAdjacencyList_h
+
+#include "cmStandardIncludes.h"
+
+/**
+ * Graph edge representation. Most use cases just need the
+ * destination vertex, so we support conversion to/from an int. We
+ * also store boolean to indicate whether an edge is "strong".
+ */
+class cmGraphEdge
+{
+public:
+ cmGraphEdge(): Dest(0), Strong(true) {}
+ cmGraphEdge(int n): Dest(n), Strong(true) {}
+ cmGraphEdge(int n, bool s): Dest(n), Strong(s) {}
+ cmGraphEdge(cmGraphEdge const& r): Dest(r.Dest), Strong(r.Strong) {}
+ operator int() const { return this->Dest; }
+
+ bool IsStrong() const { return this->Strong; }
+private:
+ int Dest;
+ bool Strong;
+};
+struct cmGraphEdgeList: public std::vector<cmGraphEdge> {};
+struct cmGraphNodeList: public std::vector<int> {};
+struct cmGraphAdjacencyList: public std::vector<cmGraphEdgeList> {};
+
+#endif
diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx
new file mode 100644
index 0000000000..601993f95e
--- /dev/null
+++ b/Source/cmGraphVizWriter.cxx
@@ -0,0 +1,599 @@
+/*============================================================================
+ 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 "cmGraphVizWriter.h"
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmGeneratedFileStream.h"
+
+
+
+static const char* getShapeForTarget(const cmTarget* target)
+{
+ if (!target)
+ {
+ return "ellipse";
+ }
+
+ switch ( target->GetType() )
+ {
+ case cmTarget::EXECUTABLE:
+ return "house";
+ case cmTarget::STATIC_LIBRARY:
+ return "diamond";
+ case cmTarget::SHARED_LIBRARY:
+ return "polygon";
+ case cmTarget::MODULE_LIBRARY:
+ return "octagon";
+ default:
+ break;
+ }
+
+ return "box";
+}
+
+
+cmGraphVizWriter::cmGraphVizWriter(const std::vector<cmLocalGenerator*>&
+ localGenerators)
+:GraphType("digraph")
+,GraphName("GG")
+,GraphHeader("node [\n fontsize = \"12\"\n];")
+,GraphNodePrefix("node")
+,GenerateForExecutables(true)
+,GenerateForStaticLibs(true)
+,GenerateForSharedLibs(true)
+,GenerateForModuleLibs(true)
+,GenerateForExternals(true)
+,GeneratePerTarget(true)
+,GenerateDependers(true)
+,LocalGenerators(localGenerators)
+,HaveTargetsAndLibs(false)
+{
+}
+
+
+void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
+ const char* fallbackSettingsFileName)
+{
+ cmake cm;
+ cmGlobalGenerator ggi;
+ ggi.SetCMakeInstance(&cm);
+ cmsys::auto_ptr<cmLocalGenerator> lg(ggi.CreateLocalGenerator());
+ cmMakefile *mf = lg->GetMakefile();
+
+ const char* inFileName = settingsFileName;
+
+ if ( !cmSystemTools::FileExists(inFileName) )
+ {
+ inFileName = fallbackSettingsFileName;
+ if ( !cmSystemTools::FileExists(inFileName) )
+ {
+ return;
+ }
+ }
+
+ if ( !mf->ReadListFile(0, inFileName) )
+ {
+ cmSystemTools::Error("Problem opening GraphViz options file: ",
+ inFileName);
+ return;
+ }
+
+ std::cout << "Reading GraphViz options file: " << inFileName << std::endl;
+
+#define __set_if_set(var, cmakeDefinition) \
+ { \
+ const char* value = mf->GetDefinition(cmakeDefinition); \
+ if ( value ) \
+ { \
+ var = value; \
+ } \
+ }
+
+ __set_if_set(this->GraphType, "GRAPHVIZ_GRAPH_TYPE");
+ __set_if_set(this->GraphName, "GRAPHVIZ_GRAPH_NAME");
+ __set_if_set(this->GraphHeader, "GRAPHVIZ_GRAPH_HEADER");
+ __set_if_set(this->GraphNodePrefix, "GRAPHVIZ_NODE_PREFIX");
+
+#define __set_bool_if_set(var, cmakeDefinition) \
+ { \
+ const char* value = mf->GetDefinition(cmakeDefinition); \
+ if ( value ) \
+ { \
+ var = mf->IsOn(cmakeDefinition); \
+ } \
+ }
+
+ __set_bool_if_set(this->GenerateForExecutables, "GRAPHVIZ_EXECUTABLES");
+ __set_bool_if_set(this->GenerateForStaticLibs, "GRAPHVIZ_STATIC_LIBS");
+ __set_bool_if_set(this->GenerateForSharedLibs, "GRAPHVIZ_SHARED_LIBS");
+ __set_bool_if_set(this->GenerateForModuleLibs, "GRAPHVIZ_MODULE_LIBS");
+ __set_bool_if_set(this->GenerateForExternals, "GRAPHVIZ_EXTERNAL_LIBS");
+ __set_bool_if_set(this->GeneratePerTarget, "GRAPHVIZ_GENERATE_PER_TARGET");
+ __set_bool_if_set(this->GenerateDependers, "GRAPHVIZ_GENERATE_DEPENDERS");
+
+ std::string ignoreTargetsRegexes;
+ __set_if_set(ignoreTargetsRegexes, "GRAPHVIZ_IGNORE_TARGETS");
+
+ this->TargetsToIgnoreRegex.clear();
+ if (ignoreTargetsRegexes.size() > 0)
+ {
+ std::vector<std::string> ignoreTargetsRegExVector;
+ cmSystemTools::ExpandListArgument(ignoreTargetsRegexes,
+ ignoreTargetsRegExVector);
+ for(std::vector<std::string>::const_iterator itvIt
+ = ignoreTargetsRegExVector.begin();
+ itvIt != ignoreTargetsRegExVector.end();
+ ++ itvIt )
+ {
+ std::string currentRegexString(*itvIt);
+ cmsys::RegularExpression currentRegex;
+ if (!currentRegex.compile(currentRegexString.c_str()))
+ {
+ std::cerr << "Could not compile bad regex \"" << currentRegexString
+ << "\"" << std::endl;
+ }
+ this->TargetsToIgnoreRegex.push_back(currentRegex);
+ }
+ }
+
+}
+
+
+// Iterate over all targets and write for each one a graph which shows
+// which other targets depend on it.
+void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName)
+{
+ if(this->GenerateDependers == false)
+ {
+ return;
+ }
+
+ this->CollectTargetsAndLibs();
+
+ for(std::map<std::string, const cmTarget*>::const_iterator ptrIt =
+ this->TargetPtrs.begin();
+ ptrIt != this->TargetPtrs.end();
+ ++ptrIt)
+ {
+ if (ptrIt->second == NULL)
+ {
+ continue;
+ }
+
+ if (this->GenerateForTargetType(ptrIt->second->GetType()) == false)
+ {
+ continue;
+ }
+
+ std::string currentFilename = fileName;
+ currentFilename += ".";
+ currentFilename += ptrIt->first;
+ currentFilename += ".dependers";
+
+ cmGeneratedFileStream str(currentFilename.c_str());
+ if ( !str )
+ {
+ return;
+ }
+
+ std::set<std::string> insertedConnections;
+ std::set<std::string> insertedNodes;
+
+ std::cout << "Writing " << currentFilename << "..." << std::endl;
+ this->WriteHeader(str);
+
+ this->WriteDependerConnections(ptrIt->first,
+ insertedNodes, insertedConnections, str);
+
+ this->WriteFooter(str);
+ }
+}
+
+
+// Iterate over all targets and write for each one a graph which shows
+// on which targets it depends.
+void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
+{
+ if(this->GeneratePerTarget == false)
+ {
+ return;
+ }
+
+ this->CollectTargetsAndLibs();
+
+ for(std::map<std::string, const cmTarget*>::const_iterator ptrIt =
+ this->TargetPtrs.begin();
+ ptrIt != this->TargetPtrs.end();
+ ++ptrIt)
+ {
+ if (ptrIt->second == NULL)
+ {
+ continue;
+ }
+
+ if (this->GenerateForTargetType(ptrIt->second->GetType()) == false)
+ {
+ continue;
+ }
+
+ std::set<std::string> insertedConnections;
+ std::set<std::string> insertedNodes;
+
+ std::string currentFilename = fileName;
+ currentFilename += ".";
+ currentFilename += ptrIt->first;
+ cmGeneratedFileStream str(currentFilename.c_str());
+ if ( !str )
+ {
+ return;
+ }
+
+ std::cout << "Writing " << currentFilename << "..." << std::endl;
+ this->WriteHeader(str);
+
+ this->WriteConnections(ptrIt->first,
+ insertedNodes, insertedConnections, str);
+ this->WriteFooter(str);
+ }
+
+}
+
+
+void cmGraphVizWriter::WriteGlobalFile(const char* fileName)
+{
+ this->CollectTargetsAndLibs();
+
+ cmGeneratedFileStream str(fileName);
+ if ( !str )
+ {
+ return;
+ }
+ this->WriteHeader(str);
+
+ std::cout << "Writing " << fileName << "..." << std::endl;
+
+ std::set<std::string> insertedConnections;
+ std::set<std::string> insertedNodes;
+
+ for(std::map<std::string, const cmTarget*>::const_iterator ptrIt =
+ this->TargetPtrs.begin();
+ ptrIt != this->TargetPtrs.end();
+ ++ptrIt)
+ {
+ if (ptrIt->second == NULL)
+ {
+ continue;
+ }
+
+ if (this->GenerateForTargetType(ptrIt->second->GetType()) == false)
+ {
+ continue;
+ }
+
+ this->WriteConnections(ptrIt->first,
+ insertedNodes, insertedConnections, str);
+ }
+ this->WriteFooter(str);
+}
+
+
+void cmGraphVizWriter::WriteHeader(cmGeneratedFileStream& str) const
+{
+ str << this->GraphType << " " << this->GraphName << " {" << std::endl;
+ str << this->GraphHeader << std::endl;
+}
+
+
+void cmGraphVizWriter::WriteFooter(cmGeneratedFileStream& str) const
+{
+ str << "}" << std::endl;
+}
+
+
+void cmGraphVizWriter::WriteConnections(const std::string& targetName,
+ std::set<std::string>& insertedNodes,
+ std::set<std::string>& insertedConnections,
+ cmGeneratedFileStream& str) const
+{
+ std::map<std::string, const cmTarget* >::const_iterator targetPtrIt =
+ this->TargetPtrs.find(targetName);
+
+ if (targetPtrIt == this->TargetPtrs.end()) // not found at all
+ {
+ return;
+ }
+
+ this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
+
+ if (targetPtrIt->second == NULL) // it's an external library
+ {
+ return;
+ }
+
+
+ std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
+
+ const cmTarget::LinkLibraryVectorType* ll =
+ &(targetPtrIt->second->GetOriginalLinkLibraries());
+
+ for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
+ llit != ll->end();
+ ++ llit )
+ {
+ const char* libName = llit->first.c_str();
+ std::map<std::string, std::string>::const_iterator libNameIt =
+ this->TargetNamesNodes.find(libName);
+
+ // can happen e.g. if GRAPHVIZ_TARGET_IGNORE_REGEX is used
+ if(libNameIt == this->TargetNamesNodes.end())
+ {
+ continue;
+ }
+
+ std::string connectionName = myNodeName;
+ connectionName += "-";
+ connectionName += libNameIt->second;
+ if (insertedConnections.find(connectionName) == insertedConnections.end())
+ {
+ insertedConnections.insert(connectionName);
+ this->WriteNode(libName, this->TargetPtrs.find(libName)->second,
+ insertedNodes, str);
+
+ str << " \"" << myNodeName << "\" -> \""
+ << libNameIt->second << "\"";
+ str << " // " << targetName << " -> " << libName << std::endl;
+ this->WriteConnections(libName, insertedNodes, insertedConnections, str);
+ }
+ }
+
+}
+
+
+void cmGraphVizWriter::WriteDependerConnections(const std::string& targetName,
+ std::set<std::string>& insertedNodes,
+ std::set<std::string>& insertedConnections,
+ cmGeneratedFileStream& str) const
+{
+ std::map<std::string, const cmTarget* >::const_iterator targetPtrIt =
+ this->TargetPtrs.find(targetName);
+
+ if (targetPtrIt == this->TargetPtrs.end()) // not found at all
+ {
+ return;
+ }
+
+ this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
+
+ if (targetPtrIt->second == NULL) // it's an external library
+ {
+ return;
+ }
+
+
+ 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();
+ dependerIt != this->TargetPtrs.end();
+ ++dependerIt)
+ {
+ if (dependerIt->second == NULL)
+ {
+ continue;
+ }
+
+ if (this->GenerateForTargetType(dependerIt->second->GetType()) == false)
+ {
+ continue;
+ }
+
+ // 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());
+
+ for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
+ llit != ll->end();
+ ++ llit )
+ {
+ std::string libName = llit->first;
+ if (libName == targetName)
+ {
+ // So this target links against targetName.
+ std::map<std::string, std::string>::const_iterator dependerNodeNameIt =
+ this->TargetNamesNodes.find(dependerIt->first);
+
+ if(dependerNodeNameIt != this->TargetNamesNodes.end())
+ {
+ std::string connectionName = dependerNodeNameIt->second;
+ connectionName += "-";
+ connectionName += myNodeName;
+
+ if (insertedConnections.find(connectionName) ==
+ insertedConnections.end())
+ {
+ insertedConnections.insert(connectionName);
+ this->WriteNode(dependerIt->first, dependerIt->second,
+ insertedNodes, str);
+
+ str << " \"" << dependerNodeNameIt->second << "\" -> \""
+ << myNodeName << "\"";
+ str << " // " <<targetName<< " -> " <<dependerIt->first<<std::endl;
+ this->WriteDependerConnections(dependerIt->first,
+ insertedNodes, insertedConnections, str);
+ }
+
+
+ }
+ break;
+ }
+ }
+ }
+
+}
+
+
+void cmGraphVizWriter::WriteNode(const std::string& targetName,
+ const cmTarget* target,
+ std::set<std::string>& insertedNodes,
+ cmGeneratedFileStream& str) const
+{
+ if (insertedNodes.find(targetName) == insertedNodes.end())
+ {
+ insertedNodes.insert(targetName);
+ std::map<std::string, std::string>::const_iterator nameIt =
+ this->TargetNamesNodes.find(targetName);
+
+ str << " \"" << nameIt->second << "\" [ label=\""
+ << targetName << "\" shape=\"" << getShapeForTarget(target)
+ << "\"];" << std::endl;
+ }
+}
+
+
+void cmGraphVizWriter::CollectTargetsAndLibs()
+{
+ if (this->HaveTargetsAndLibs == false)
+ {
+ this->HaveTargetsAndLibs = true;
+ int cnt = this->CollectAllTargets();
+ if (this->GenerateForExternals)
+ {
+ this->CollectAllExternalLibs(cnt);
+ }
+ }
+}
+
+
+int cmGraphVizWriter::CollectAllTargets()
+{
+ int cnt = 0;
+ // First pass get the list of all cmake targets
+ for (std::vector<cmLocalGenerator*>::const_iterator lit =
+ this->LocalGenerators.begin();
+ lit != this->LocalGenerators.end();
+ ++ lit )
+ {
+ const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
+ for ( cmTargets::const_iterator tit = targets->begin();
+ tit != targets->end();
+ ++ tit )
+ {
+ const char* realTargetName = tit->first.c_str();
+ if(this->IgnoreThisTarget(realTargetName))
+ {
+ // Skip ignored targets
+ continue;
+ }
+ //std::cout << "Found target: " << tit->first.c_str() << std::endl;
+ cmOStringStream ostr;
+ ostr << this->GraphNodePrefix << cnt++;
+ this->TargetNamesNodes[realTargetName] = ostr.str();
+ this->TargetPtrs[realTargetName] = &tit->second;
+ }
+ }
+
+ return cnt;
+}
+
+
+int cmGraphVizWriter::CollectAllExternalLibs(int cnt)
+{
+ // Ok, now find all the stuff we link to that is not in cmake
+ for (std::vector<cmLocalGenerator*>::const_iterator lit =
+ this->LocalGenerators.begin();
+ lit != this->LocalGenerators.end();
+ ++ lit )
+ {
+ const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
+ for ( cmTargets::const_iterator tit = targets->begin();
+ tit != targets->end();
+ ++ tit )
+ {
+ const char* realTargetName = tit->first.c_str();
+ if (this->IgnoreThisTarget(realTargetName))
+ {
+ // Skip ignored targets
+ continue;
+ }
+ const cmTarget::LinkLibraryVectorType* ll =
+ &(tit->second.GetOriginalLinkLibraries());
+ for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
+ llit != ll->end();
+ ++ llit )
+ {
+ const char* libName = llit->first.c_str();
+ if (this->IgnoreThisTarget(libName))
+ {
+ // Skip ignored targets
+ continue;
+ }
+
+ std::map<std::string, const cmTarget*>::const_iterator tarIt =
+ this->TargetPtrs.find(libName);
+ if ( tarIt == this->TargetPtrs.end() )
+ {
+ cmOStringStream ostr;
+ ostr << this->GraphNodePrefix << cnt++;
+ this->TargetNamesNodes[libName] = ostr.str();
+ this->TargetPtrs[libName] = NULL;
+ // str << " \"" << ostr.c_str() << "\" [ label=\"" << libName
+ // << "\" shape=\"ellipse\"];" << std::endl;
+ }
+ }
+ }
+ }
+ return cnt;
+}
+
+
+bool cmGraphVizWriter::IgnoreThisTarget(const std::string& name)
+{
+ for(std::vector<cmsys::RegularExpression>::iterator itvIt
+ = this->TargetsToIgnoreRegex.begin();
+ itvIt != this->TargetsToIgnoreRegex.end();
+ ++ itvIt )
+ {
+ cmsys::RegularExpression& regEx = *itvIt;
+ if (regEx.is_valid())
+ {
+ if (regEx.find(name))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+
+bool cmGraphVizWriter::GenerateForTargetType(cmTarget::TargetType targetType)
+ const
+{
+ switch (targetType)
+ {
+ case cmTarget::EXECUTABLE:
+ return this->GenerateForExecutables;
+ case cmTarget::STATIC_LIBRARY:
+ return this->GenerateForStaticLibs;
+ case cmTarget::SHARED_LIBRARY:
+ return this->GenerateForSharedLibs;
+ case cmTarget::MODULE_LIBRARY:
+ return this->GenerateForModuleLibs;
+ default:
+ break;
+ }
+ return false;
+}
diff --git a/Source/cmGraphVizWriter.h b/Source/cmGraphVizWriter.h
new file mode 100644
index 0000000000..a7acd0e54b
--- /dev/null
+++ b/Source/cmGraphVizWriter.h
@@ -0,0 +1,91 @@
+#ifndef CMGRAPHVIZWRITER_H
+#define CMGRAPHVIZWRITER_H
+/*============================================================================
+ 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 "cmStandardIncludes.h"
+#include "cmLocalGenerator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmTarget.h"
+#include <cmsys/RegularExpression.hxx>
+
+
+/** This class implements writing files for graphviz (dot) for graphs
+ * representing the dependencies between the targets in the project. */
+class cmGraphVizWriter
+{
+public:
+
+ cmGraphVizWriter(const std::vector<cmLocalGenerator*>& localGenerators);
+
+ void ReadSettings(const char* settingsFileName,
+ const char* fallbackSettingsFileName);
+
+ void WritePerTargetFiles(const char* fileName);
+ void WriteTargetDependersFiles(const char* fileName);
+
+ void WriteGlobalFile(const char* fileName);
+
+protected:
+
+ void CollectTargetsAndLibs();
+
+ int CollectAllTargets();
+
+ int CollectAllExternalLibs(int cnt);
+
+ void WriteHeader(cmGeneratedFileStream& str) const;
+
+ void WriteConnections(const std::string& targetName,
+ std::set<std::string>& insertedNodes,
+ std::set<std::string>& insertedConnections,
+ cmGeneratedFileStream& str) const;
+
+ void WriteDependerConnections(const std::string& targetName,
+ std::set<std::string>& insertedNodes,
+ std::set<std::string>& insertedConnections,
+ cmGeneratedFileStream& str) const;
+
+ void WriteNode(const std::string& targetName, const cmTarget* target,
+ std::set<std::string>& insertedNodes,
+ cmGeneratedFileStream& str) const;
+
+ void WriteFooter(cmGeneratedFileStream& str) const;
+
+ bool IgnoreThisTarget(const std::string& name);
+
+ bool GenerateForTargetType(cmTarget::TargetType targetType) const;
+
+ std::string GraphType;
+ std::string GraphName;
+ std::string GraphHeader;
+ std::string GraphNodePrefix;
+
+ bool GenerateForExecutables;
+ bool GenerateForStaticLibs;
+ bool GenerateForSharedLibs;
+ bool GenerateForModuleLibs;
+ bool GenerateForExternals;
+ bool GeneratePerTarget;
+ bool GenerateDependers;
+
+ std::vector<cmsys::RegularExpression> TargetsToIgnoreRegex;
+
+ const std::vector<cmLocalGenerator*>& LocalGenerators;
+
+ std::map<std::string, const cmTarget*> TargetPtrs;
+ // maps from the actual target names to node names in dot:
+ std::map<std::string, std::string> TargetNamesNodes;
+
+ bool HaveTargetsAndLibs;
+};
+
+#endif
diff --git a/Source/cmHexFileConverter.cxx b/Source/cmHexFileConverter.cxx
new file mode 100644
index 0000000000..6ea597ea50
--- /dev/null
+++ b/Source/cmHexFileConverter.cxx
@@ -0,0 +1,265 @@
+/*============================================================================
+ 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 "cmHexFileConverter.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#define INTEL_HEX_MIN_LINE_LENGTH (1+8 +2)
+#define INTEL_HEX_MAX_LINE_LENGTH (1+8+(256*2)+2)
+#define MOTOROLA_SREC_MIN_LINE_LENGTH (2+2+4 +2)
+#define MOTOROLA_SREC_MAX_LINE_LENGTH (2+2+8+(256*2)+2)
+
+// might go to SystemTools ?
+static bool cm_IsHexChar(char c)
+{
+ return (((c >= '0') && (c <= '9'))
+ || ((c >= 'a') && (c <= 'f'))
+ || ((c >= 'A') && (c <= 'F')));
+}
+
+static unsigned int ChompStrlen(const char* line)
+{
+ if (line == 0)
+ {
+ return 0;
+ }
+ unsigned int length = static_cast<unsigned int>(strlen(line));
+ if ((line[length-1] == '\n') || (line[length-1] == '\r'))
+ {
+ length--;
+ }
+ if ((line[length-1] == '\n') || (line[length-1] == '\r'))
+ {
+ length--;
+ }
+ return length;
+}
+
+static bool OutputBin(FILE* file, const char * buf,
+ unsigned int startIndex, unsigned int stopIndex)
+{
+ bool success = true;
+ char hexNumber[3];
+ hexNumber[2] = '\0';
+ char outBuf[256];
+ unsigned int outBufCount = 0;
+ for (unsigned int i = startIndex; i < stopIndex; i += 2)
+ {
+ hexNumber[0] = buf[i];
+ hexNumber[1] = buf[i+1];
+ unsigned int convertedByte = 0;
+ if (sscanf(hexNumber, "%x", &convertedByte) != 1)
+ {
+ success = false;
+ break;
+ }
+ outBuf[outBufCount] = static_cast<char>(convertedByte & 0xff);
+ outBufCount++;
+ }
+ if (success)
+ {
+ success = (fwrite(outBuf, 1, outBufCount, file)==outBufCount);
+ }
+ return success;
+}
+
+// see http://www.die.net/doc/linux/man/man5/srec.5.html
+static bool ConvertMotorolaSrecLine(const char* buf, FILE* outFile)
+{
+ unsigned int slen = ChompStrlen(buf);
+ if ((slen < MOTOROLA_SREC_MIN_LINE_LENGTH)
+ || (slen > MOTOROLA_SREC_MAX_LINE_LENGTH))
+ {
+ return false;
+ }
+
+ // line length must be even
+ if (slen % 2 == 1)
+ {
+ return false;
+ }
+
+ if (buf[0] != 'S')
+ {
+ return false;
+ }
+
+ unsigned int dataStart = 0;
+ // ignore extra address records
+ if ((buf[1] == '5') || (buf[1] == '7') || (buf[1] == '8') || (buf[1] == '9'))
+ {
+ return true;
+ }
+ else if (buf[1] == '1')
+ {
+ dataStart = 8;
+ }
+ else if (buf[1] == '2')
+ {
+ dataStart = 10;
+ }
+ else if (buf[1] == '3')
+ {
+ dataStart = 12;
+ }
+ else // unknown record type
+ {
+ return false;
+ }
+
+ // ignore the last two bytes (checksum)
+ return OutputBin(outFile, buf, dataStart, slen - 2);
+}
+
+// see http://en.wikipedia.org/wiki/Intel_hex
+static bool ConvertIntelHexLine(const char* buf, FILE* outFile)
+{
+ unsigned int slen = ChompStrlen(buf);
+ if ((slen < INTEL_HEX_MIN_LINE_LENGTH)
+ || (slen > INTEL_HEX_MAX_LINE_LENGTH))
+ {
+ return false;
+ }
+
+ // line length must be odd
+ if (slen % 2 == 0)
+ {
+ return false;
+ }
+
+ if ((buf[0] != ':') || (buf[7] != '0'))
+ {
+ return false;
+ }
+
+ unsigned int dataStart = 0;
+ if ((buf[8] == '0') || (buf[8] == '1'))
+ {
+ dataStart = 9;
+ }
+ // ignore extra address records
+ else if ((buf[8] == '2') || (buf[8] == '3') || (buf[8] == '4')
+ || (buf[8] == '5'))
+ {
+ return true;
+ }
+ else // unknown record type
+ {
+ return false;
+ }
+
+// ignore the last two bytes (checksum)
+ return OutputBin(outFile, buf, dataStart, slen - 2);
+}
+
+cmHexFileConverter::FileType cmHexFileConverter::DetermineFileType(
+ const char* inFileName)
+{
+ char buf[1024];
+ FILE* inFile = cmsys::SystemTools::Fopen(inFileName, "rb");
+ if (inFile == 0)
+ {
+ return Binary;
+ }
+
+ if(!fgets(buf, 1024, inFile))
+ {
+ buf[0] = 0;
+ }
+ fclose(inFile);
+ FileType type = Binary;
+ unsigned int minLineLength = 0;
+ unsigned int maxLineLength = 0;
+ if (buf[0] == ':') // might be an intel hex file
+ {
+ type = IntelHex;
+ minLineLength = INTEL_HEX_MIN_LINE_LENGTH;
+ maxLineLength = INTEL_HEX_MAX_LINE_LENGTH;
+ }
+ else if (buf[0] == 'S') // might be a motorola srec file
+ {
+ type = MotorolaSrec;
+ minLineLength = MOTOROLA_SREC_MIN_LINE_LENGTH;
+ maxLineLength = MOTOROLA_SREC_MAX_LINE_LENGTH;
+ }
+ else
+ {
+ return Binary;
+ }
+
+ unsigned int slen = ChompStrlen(buf);
+ if ((slen < minLineLength) || (slen > maxLineLength))
+ {
+ return Binary;
+ }
+
+ for (unsigned int i = 1; i < slen; i++)
+ {
+ if (!cm_IsHexChar(buf[i]))
+ {
+ return Binary;
+ }
+ }
+ return type;
+}
+
+bool cmHexFileConverter::TryConvert(const char* inFileName,
+ const char* outFileName)
+{
+ FileType type = DetermineFileType(inFileName);
+ if (type == Binary)
+ {
+ return false;
+ }
+
+ // try to open the file
+ FILE* inFile = cmsys::SystemTools::Fopen(inFileName, "rb");
+ FILE* outFile = cmsys::SystemTools::Fopen(outFileName, "wb");
+ if ((inFile == 0) || (outFile == 0))
+ {
+ if (inFile != 0)
+ {
+ fclose(inFile);
+ }
+ if (outFile != 0)
+ {
+ fclose(outFile);
+ }
+ return false;
+ }
+
+ // convert them line by line
+ bool success = false;
+ char buf[1024];
+ while (fgets(buf, 1024, inFile) != 0)
+ {
+ if (type == MotorolaSrec)
+ {
+ success = ConvertMotorolaSrecLine(buf, outFile);
+ }
+ else if (type == IntelHex)
+ {
+ success = ConvertIntelHexLine(buf, outFile);
+ }
+ if (success == false)
+ {
+ break;
+ }
+ }
+
+ // close them again
+ fclose(inFile);
+ fclose(outFile);
+ return success;
+}
+
diff --git a/Source/cmHexFileConverter.h b/Source/cmHexFileConverter.h
new file mode 100644
index 0000000000..e11d74a2fe
--- /dev/null
+++ b/Source/cmHexFileConverter.h
@@ -0,0 +1,28 @@
+/*============================================================================
+ 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 cmHexFileConverter_h
+#define cmHexFileConverter_h
+
+/** \class cmHexFileConverter
+ * \brief Can detects Intel Hex and Motorola S-record files and convert them
+ * to binary files.
+ *
+ */
+class cmHexFileConverter
+{
+public:
+ enum FileType {Binary, IntelHex, MotorolaSrec};
+ static FileType DetermineFileType(const char* inFileName);
+ static bool TryConvert(const char* inFileName, const char* outFileName);
+};
+
+#endif
diff --git a/Source/cmIDEFlagTable.h b/Source/cmIDEFlagTable.h
new file mode 100644
index 0000000000..d9a045d6bc
--- /dev/null
+++ b/Source/cmIDEFlagTable.h
@@ -0,0 +1,41 @@
+/*============================================================================
+ 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 cmIDEFlagTable_h
+#define cmIDEFlagTable_h
+
+// This is a table mapping XML tag IDE names to command line options
+struct cmIDEFlagTable
+{
+ const char* IDEName; // name used in the IDE xml file
+ const char* commandFlag; // command line flag
+ const char* comment; // comment
+ const char* value; // string value
+ unsigned int special; // flags for special handling requests
+ enum
+ {
+ UserValue = (1<<0), // flag contains a user-specified value
+ UserIgnored = (1<<1), // ignore any user value
+ UserRequired = (1<<2), // match only when user value is non-empty
+ Continue = (1<<3), // continue looking for matching entries
+ SemicolonAppendable = (1<<4), // a flag that if specified multiple times
+ // should have its value appended to the
+ // old value with semicolons (e.g.
+ // /NODEFAULTLIB: =>
+ // IgnoreDefaultLibraryNames)
+ UserFollowing = (1<<5), // expect value in following argument
+
+ UserValueIgnored = UserValue | UserIgnored,
+ UserValueRequired = UserValue | UserRequired
+ };
+};
+
+#endif
diff --git a/Source/cmIDEOptions.cxx b/Source/cmIDEOptions.cxx
new file mode 100644
index 0000000000..0eb903d843
--- /dev/null
+++ b/Source/cmIDEOptions.cxx
@@ -0,0 +1,235 @@
+/*============================================================================
+ 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 "cmIDEOptions.h"
+
+#include "cmSystemTools.h"
+
+//----------------------------------------------------------------------------
+cmIDEOptions::cmIDEOptions()
+{
+ this->DoingDefine = false;
+ this->AllowDefine = true;
+ this->AllowSlash = false;
+ this->DoingFollowing = 0;
+ for(int i=0; i < FlagTableCount; ++i)
+ {
+ this->FlagTable[i] = 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmIDEOptions::~cmIDEOptions()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmIDEOptions::HandleFlag(const char* flag)
+{
+ // If the last option was -D then this option is the definition.
+ if(this->DoingDefine)
+ {
+ this->DoingDefine = false;
+ this->Defines.push_back(flag);
+ return;
+ }
+
+ // If the last option expected a following value, this is it.
+ if(this->DoingFollowing)
+ {
+ this->FlagMapUpdate(this->DoingFollowing, flag);
+ this->DoingFollowing = 0;
+ return;
+ }
+
+ // Look for known arguments.
+ if(flag[0] == '-' || (this->AllowSlash && flag[0] == '/'))
+ {
+ // Look for preprocessor definitions.
+ if(this->AllowDefine && flag[1] == 'D')
+ {
+ if(flag[2] == '\0')
+ {
+ // The next argument will have the definition.
+ this->DoingDefine = true;
+ }
+ else
+ {
+ // Store this definition.
+ this->Defines.push_back(flag+2);
+ }
+ return;
+ }
+
+ // Look through the available flag tables.
+ bool flag_handled = false;
+ for(int i=0; i < FlagTableCount && this->FlagTable[i]; ++i)
+ {
+ if(this->CheckFlagTable(this->FlagTable[i], flag, flag_handled))
+ {
+ return;
+ }
+ }
+
+ // If any map entry handled the flag we are done.
+ if(flag_handled)
+ {
+ return;
+ }
+ }
+
+ // This option is not known. Store it in the output flags.
+ this->StoreUnknownFlag(flag);
+}
+
+//----------------------------------------------------------------------------
+bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
+ const char* flag, bool& flag_handled)
+{
+ // Look for an entry in the flag table matching this flag.
+ for(cmIDEFlagTable const* entry = table; entry->IDEName; ++entry)
+ {
+ bool entry_found = false;
+ if(entry->special & cmIDEFlagTable::UserValue)
+ {
+ // This flag table entry accepts a user-specified value. If
+ // 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 &&
+ (!(entry->special & cmIDEFlagTable::UserRequired) ||
+ static_cast<int>(strlen(flag+1)) > n))
+ {
+ this->FlagMapUpdate(entry, flag+n+1);
+ entry_found = true;
+ }
+ }
+ else if(strcmp(flag+1, entry->commandFlag) == 0)
+ {
+ if(entry->special & cmIDEFlagTable::UserFollowing)
+ {
+ // This flag expects a value in the following argument.
+ this->DoingFollowing = entry;
+ }
+ else
+ {
+ // This flag table entry provides a fixed value.
+ this->FlagMap[entry->IDEName] = entry->value;
+ }
+ entry_found = true;
+ }
+
+ // If the flag has been handled by an entry not requesting a
+ // search continuation we are done.
+ if(entry_found && !(entry->special & cmIDEFlagTable::Continue))
+ {
+ return true;
+ }
+
+ // If the entry was found the flag has been handled.
+ flag_handled = flag_handled || entry_found;
+ }
+
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry,
+ const char* new_value)
+{
+ if(entry->special & cmIDEFlagTable::UserIgnored)
+ {
+ // Ignore the user-specified value.
+ this->FlagMap[entry->IDEName] = entry->value;
+ }
+ else if(entry->special & cmIDEFlagTable::SemicolonAppendable)
+ {
+ this->FlagMap[entry->IDEName].push_back(new_value);
+ }
+ else
+ {
+ // Use the user-specified value.
+ this->FlagMap[entry->IDEName] = new_value;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmIDEOptions::AddDefine(const std::string& def)
+{
+ this->Defines.push_back(def);
+}
+
+//----------------------------------------------------------------------------
+void cmIDEOptions::AddDefines(const char* defines)
+{
+ if(defines)
+ {
+ // Expand the list of definitions.
+ cmSystemTools::ExpandListArgument(defines, this->Defines);
+ }
+}
+//----------------------------------------------------------------------------
+void cmIDEOptions::AddDefines(const std::vector<std::string> &defines)
+{
+ this->Defines.insert(this->Defines.end(), defines.begin(), defines.end());
+}
+
+//----------------------------------------------------------------------------
+void cmIDEOptions::AddFlag(const char* flag, const char* value)
+{
+ this->FlagMap[flag] = value;
+}
+
+//----------------------------------------------------------------------------
+void cmIDEOptions::AddFlag(const char* flag,
+ std::vector<std::string> const& value)
+{
+ this->FlagMap[flag] = value;
+}
+
+//----------------------------------------------------------------------------
+void cmIDEOptions::AppendFlag(std::string const& flag,
+ std::string const& value)
+{
+ this->FlagMap[flag].push_back(value);
+}
+
+//----------------------------------------------------------------------------
+void cmIDEOptions::AppendFlag(std::string const& flag,
+ std::vector<std::string> const& value)
+{
+ FlagValue& fv = this->FlagMap[flag];
+ std::copy(value.begin(), value.end(), std::back_inserter(fv));
+}
+
+//----------------------------------------------------------------------------
+void cmIDEOptions::RemoveFlag(const char* flag)
+{
+ this->FlagMap.erase(flag);
+}
+
+//----------------------------------------------------------------------------
+bool cmIDEOptions::HasFlag(std::string const& flag) const
+{
+ return this->FlagMap.find(flag) != this->FlagMap.end();
+}
+
+//----------------------------------------------------------------------------
+const char* cmIDEOptions::GetFlag(const char* flag)
+{
+ // This method works only for single-valued flags!
+ std::map<std::string, FlagValue>::iterator i = this->FlagMap.find(flag);
+ if(i != this->FlagMap.end() && i->second.size() == 1)
+ {
+ return i->second[0].c_str();
+ }
+ return 0;
+}
diff --git a/Source/cmIDEOptions.h b/Source/cmIDEOptions.h
new file mode 100644
index 0000000000..73860164d6
--- /dev/null
+++ b/Source/cmIDEOptions.h
@@ -0,0 +1,85 @@
+/*============================================================================
+ 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 cmIDEOptions_h
+#define cmIDEOptions_h
+
+#include "cmStandardIncludes.h"
+#include "cmIDEFlagTable.h"
+
+/** \class cmIDEOptions
+ * \brief Superclass for IDE option processing
+ */
+class cmIDEOptions
+{
+public:
+ cmIDEOptions();
+ virtual ~cmIDEOptions();
+
+ // Store definitions and flags.
+ void AddDefine(const std::string& define);
+ void AddDefines(const char* defines);
+ void AddDefines(const std::vector<std::string> &defines);
+ void AddFlag(const char* flag, const char* value);
+ void AddFlag(const char* flag, std::vector<std::string> const& value);
+ void AppendFlag(std::string const& flag, std::string const& value);
+ void AppendFlag(std::string const& flag,
+ std::vector<std::string> const& value);
+ void RemoveFlag(const char* flag);
+ bool HasFlag(std::string const& flag) const;
+ const char* GetFlag(const char* flag);
+
+protected:
+ // create a map of xml tags to the values they should have in the output
+ // for example, "BufferSecurityCheck" = "TRUE"
+ // first fill this table with the values for the configuration
+ // Debug, Release, etc,
+ // Then parse the command line flags specified in CMAKE_CXX_FLAGS
+ // and CMAKE_C_FLAGS
+ // and overwrite or add new values to this map
+ class FlagValue: public std::vector<std::string>
+ {
+ typedef std::vector<std::string> derived;
+ public:
+ FlagValue& operator=(std::string const& r)
+ {
+ this->resize(1);
+ this->operator[](0) = r;
+ return *this;
+ }
+ FlagValue& operator=(std::vector<std::string> const& r)
+ {
+ this->derived::operator=(r);
+ return *this;
+ }
+ };
+ std::map<std::string, FlagValue > FlagMap;
+
+ // Preprocessor definitions.
+ std::vector<std::string> Defines;
+
+ // Unrecognized flags that get no special handling.
+ std::string FlagString;
+
+ bool DoingDefine;
+ bool AllowDefine;
+ bool AllowSlash;
+ cmIDEFlagTable const* DoingFollowing;
+ enum { FlagTableCount = 16 };
+ cmIDEFlagTable const* FlagTable[FlagTableCount];
+ void HandleFlag(const char* flag);
+ bool CheckFlagTable(cmIDEFlagTable const* table, const char* flag,
+ bool& flag_handled);
+ void FlagMapUpdate(cmIDEFlagTable const* entry, const char* new_value);
+ virtual void StoreUnknownFlag(const char* flag) = 0;
+};
+
+#endif
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
new file mode 100644
index 0000000000..f728c15e3c
--- /dev/null
+++ b/Source/cmIfCommand.cxx
@@ -0,0 +1,230 @@
+/*============================================================================
+ 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 "cmIfCommand.h"
+#include "cmStringCommand.h"
+
+#include "cmConditionEvaluator.h"
+
+#include <stdlib.h> // required for atof
+#include <list>
+#include <cmsys/RegularExpression.hxx>
+
+
+static std::string cmIfCommandError(
+ cmMakefile* mf, std::vector<cmExpandedCommandArgument> const& args)
+{
+ cmLocalGenerator* lg = mf->GetLocalGenerator();
+ std::string err = "given arguments:\n ";
+ for(std::vector<cmExpandedCommandArgument>::const_iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ err += " ";
+ err += lg->EscapeForCMake(i->GetValue());
+ }
+ err += "\n";
+ return err;
+}
+
+//=========================================================================
+bool cmIfFunctionBlocker::
+IsFunctionBlocked(const cmListFileFunction& lff,
+ cmMakefile &mf,
+ cmExecutionStatus &inStatus)
+{
+ // we start by recording all the functions
+ if (!cmSystemTools::Strucmp(lff.Name.c_str(),"if"))
+ {
+ this->ScopeDepth++;
+ }
+ if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endif"))
+ {
+ this->ScopeDepth--;
+ // if this is the endif for this if statement, then start executing
+ if (!this->ScopeDepth)
+ {
+ // Remove the function blocker for this scope or bail.
+ cmsys::auto_ptr<cmFunctionBlocker>
+ fb(mf.RemoveFunctionBlocker(this, lff));
+ if(!fb.get()) { return false; }
+
+ // execute the functions for the true parts of the if statement
+ cmExecutionStatus status;
+ int scopeDepth = 0;
+ for(unsigned int c = 0; c < this->Functions.size(); ++c)
+ {
+ // keep track of scope depth
+ if (!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(),"if"))
+ {
+ scopeDepth++;
+ }
+ if (!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(),"endif"))
+ {
+ scopeDepth--;
+ }
+ // watch for our state change
+ if (scopeDepth == 0 &&
+ !cmSystemTools::Strucmp(this->Functions[c].Name.c_str(),"else"))
+ {
+ this->IsBlocking = this->HasRun;
+ this->HasRun = true;
+
+ // if trace is enabled, print a (trivially) evaluated "else"
+ // statement
+ if(!this->IsBlocking && mf.GetCMakeInstance()->GetTrace())
+ {
+ mf.PrintCommandTrace(this->Functions[c]);
+ }
+ }
+ else if (scopeDepth == 0 && !cmSystemTools::Strucmp
+ (this->Functions[c].Name.c_str(),"elseif"))
+ {
+ if (this->HasRun)
+ {
+ this->IsBlocking = true;
+ }
+ else
+ {
+ // Place this call on the call stack.
+ cmMakefileCall stack_manager(&mf, this->Functions[c], status);
+ static_cast<void>(stack_manager);
+
+ // if trace is enabled, print the evaluated "elseif" statement
+ if(mf.GetCMakeInstance()->GetTrace())
+ {
+ mf.PrintCommandTrace(this->Functions[c]);
+ }
+
+ std::string errorString;
+
+ std::vector<cmExpandedCommandArgument> expandedArguments;
+ mf.ExpandArguments(this->Functions[c].Arguments,
+ expandedArguments);
+
+ cmake::MessageType messType;
+
+ cmConditionEvaluator conditionEvaluator(mf);
+
+ bool isTrue = conditionEvaluator.IsTrue(
+ expandedArguments, errorString, messType);
+
+ if (errorString.size())
+ {
+ std::string err = cmIfCommandError(&mf, expandedArguments);
+ err += errorString;
+ mf.IssueMessage(messType, err);
+ if (messType == cmake::FATAL_ERROR)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+ }
+
+ if (isTrue)
+ {
+ this->IsBlocking = false;
+ this->HasRun = true;
+ }
+ }
+ }
+
+ // should we execute?
+ else if (!this->IsBlocking)
+ {
+ status.Clear();
+ mf.ExecuteCommand(this->Functions[c],status);
+ if (status.GetReturnInvoked())
+ {
+ inStatus.SetReturnInvoked(true);
+ return true;
+ }
+ if (status.GetBreakInvoked())
+ {
+ inStatus.SetBreakInvoked(true);
+ return true;
+ }
+ }
+ }
+ return true;
+ }
+ }
+
+ // record the command
+ this->Functions.push_back(lff);
+
+ // always return true
+ return true;
+}
+
+//=========================================================================
+bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
+ cmMakefile&)
+{
+ if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endif"))
+ {
+ // if the endif has arguments, then make sure
+ // they match the arguments of the matching if
+ if (lff.Arguments.size() == 0 ||
+ lff.Arguments == this->Args)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+//=========================================================================
+bool cmIfCommand
+::InvokeInitialPass(const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus &)
+{
+ std::string errorString;
+
+ std::vector<cmExpandedCommandArgument> expandedArguments;
+ this->Makefile->ExpandArguments(args, expandedArguments);
+
+ cmake::MessageType status;
+
+ cmConditionEvaluator conditionEvaluator(*(this->Makefile));
+
+ bool isTrue = conditionEvaluator.IsTrue(
+ expandedArguments, errorString, status);
+
+ if (errorString.size())
+ {
+ std::string err = cmIfCommandError(this->Makefile, expandedArguments);
+ err += errorString;
+ if (status == cmake::FATAL_ERROR)
+ {
+ this->SetError(err);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+ else
+ {
+ this->Makefile->IssueMessage(status, err);
+ }
+ }
+
+ cmIfFunctionBlocker *f = new cmIfFunctionBlocker();
+ // if is isn't true block the commands
+ f->ScopeDepth = 1;
+ f->IsBlocking = !isTrue;
+ if (isTrue)
+ {
+ f->HasRun = true;
+ }
+ f->Args = args;
+ this->Makefile->AddFunctionBlocker(f);
+
+ return true;
+}
diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h
new file mode 100644
index 0000000000..689efce656
--- /dev/null
+++ b/Source/cmIfCommand.h
@@ -0,0 +1,81 @@
+/*============================================================================
+ 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 cmIfCommand_h
+#define cmIfCommand_h
+
+#include "cmCommand.h"
+#include "cmFunctionBlocker.h"
+
+class cmIfFunctionBlocker : public cmFunctionBlocker
+{
+public:
+ cmIfFunctionBlocker() {
+ this->HasRun = false; this->ScopeDepth = 0; }
+ virtual ~cmIfFunctionBlocker() {}
+ virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
+ cmMakefile &mf,
+ cmExecutionStatus &);
+ virtual bool ShouldRemove(const cmListFileFunction& lff,
+ cmMakefile &mf);
+
+ std::vector<cmListFileArgument> Args;
+ std::vector<cmListFileFunction> Functions;
+ bool IsBlocking;
+ bool HasRun;
+ unsigned int ScopeDepth;
+};
+
+/// Starts an if block
+class cmIfCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmIfCommand;
+ }
+
+ /**
+ * This overrides the default InvokeInitialPass implementation.
+ * It records the arguments before expansion.
+ */
+ virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus &);
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &) { return false;}
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "if";}
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ // Filter the given variable definition based on policy CMP0054.
+ static const char* GetDefinitionIfUnquoted(
+ const cmMakefile* mf, cmExpandedCommandArgument const& argument);
+
+ cmTypeMacro(cmIfCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx
new file mode 100644
index 0000000000..0a4f5c97f5
--- /dev/null
+++ b/Source/cmIncludeCommand.cxx
@@ -0,0 +1,158 @@
+/*============================================================================
+ 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 "cmIncludeCommand.h"
+
+
+// cmIncludeCommand
+bool cmIncludeCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if (args.size()< 1 || args.size() > 4)
+ {
+ this->SetError("called with wrong number of arguments. "
+ "include() only takes one file.");
+ return false;
+ }
+ bool optional = false;
+ bool noPolicyScope = false;
+ std::string fname = args[0];
+ std::string resultVarName;
+
+ for (unsigned int i=1; i<args.size(); i++)
+ {
+ if (args[i] == "OPTIONAL")
+ {
+ if (optional)
+ {
+ this->SetError("called with invalid arguments: OPTIONAL used twice");
+ return false;
+ }
+ optional = true;
+ }
+ else if(args[i] == "RESULT_VARIABLE")
+ {
+ if (resultVarName.size() > 0)
+ {
+ this->SetError("called with invalid arguments: "
+ "only one result variable allowed");
+ return false;
+ }
+ if(++i < args.size())
+ {
+ resultVarName = args[i];
+ }
+ else
+ {
+ this->SetError("called with no value for RESULT_VARIABLE.");
+ return false;
+ }
+ }
+ else if(args[i] == "NO_POLICY_SCOPE")
+ {
+ noPolicyScope = true;
+ }
+ else if(i > 1) // compat.: in previous cmake versions the second
+ // parameter was ignored if it wasn't "OPTIONAL"
+ {
+ std::string errorText = "called with invalid argument: ";
+ errorText += args[i];
+ this->SetError(errorText);
+ return false;
+ }
+ }
+
+ if(fname.empty())
+ {
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ "include() given empty file name (ignored).");
+ return true;
+ }
+
+ if(!cmSystemTools::FileIsFullPath(fname.c_str()))
+ {
+ // Not a path. Maybe module.
+ std::string module = fname;
+ module += ".cmake";
+ std::string mfile = this->Makefile->GetModulesFile(module.c_str());
+ if ( mfile.size() )
+ {
+ fname = mfile.c_str();
+ }
+ }
+
+ std::string fname_abs =
+ cmSystemTools::CollapseFullPath(fname.c_str(),
+ this->Makefile->GetStartDirectory());
+
+ cmGlobalGenerator *gg = this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator();
+ if (gg->IsExportedTargetsFile(fname_abs))
+ {
+ const char *modal = 0;
+ cmOStringStream e;
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0024))
+ {
+ case cmPolicies::WARN:
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0024)) << "\n";
+ modal = "should";
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ modal = "may";
+ messageType = cmake::FATAL_ERROR;
+ }
+ if (modal)
+ {
+ e << "The file\n " << fname_abs << "\nwas generated by the export() "
+ "command. It " << modal << " not be used as the argument to the "
+ "include() command. Use ALIAS targets instead to refer to targets "
+ "by alternative names.\n";
+ this->Makefile->IssueMessage(messageType, e.str());
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return false;
+ }
+ }
+ gg->GenerateImportFile(fname_abs);
+ }
+
+ std::string fullFilePath;
+ bool readit =
+ this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
+ fname.c_str(), &fullFilePath,
+ noPolicyScope);
+
+ // add the location of the included file if a result variable was given
+ if (resultVarName.size())
+ {
+ this->Makefile->AddDefinition(resultVarName,
+ readit?fullFilePath.c_str():"NOTFOUND");
+ }
+
+ if(!optional && !readit && !cmSystemTools::GetFatalErrorOccured())
+ {
+ std::string m =
+ "could not find load file:\n"
+ " ";
+ m += fname;
+ this->SetError(m);
+ return false;
+ }
+ return true;
+}
+
+
diff --git a/Source/cmIncludeCommand.h b/Source/cmIncludeCommand.h
new file mode 100644
index 0000000000..0dcd7de8b4
--- /dev/null
+++ b/Source/cmIncludeCommand.h
@@ -0,0 +1,56 @@
+/*============================================================================
+ 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 cmIncludeCommand_h
+#define cmIncludeCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmIncludeCommand
+ * \brief cmIncludeCommand defines a list of distant
+ * files that can be "included" in the current list file.
+ * In almost every sense, this is identical to a C/C++
+ * #include command. Arguments are first expended as usual.
+ */
+class cmIncludeCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmIncludeCommand;
+ }
+
+ /**
+ * 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 "include";}
+
+ cmTypeMacro(cmIncludeCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx
new file mode 100644
index 0000000000..df5508e5d3
--- /dev/null
+++ b/Source/cmIncludeDirectoryCommand.cxx
@@ -0,0 +1,163 @@
+/*============================================================================
+ 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 "cmIncludeDirectoryCommand.h"
+
+// cmIncludeDirectoryCommand
+bool cmIncludeDirectoryCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ return true;
+ }
+
+ std::vector<std::string>::const_iterator i = args.begin();
+
+ bool before = this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE");
+ bool system = false;
+
+ if ((*i) == "BEFORE")
+ {
+ before = true;
+ ++i;
+ }
+ else if ((*i) == "AFTER")
+ {
+ before = false;
+ ++i;
+ }
+
+ std::vector<std::string> beforeIncludes;
+ std::vector<std::string> afterIncludes;
+ std::set<std::string> systemIncludes;
+
+ for(; i != args.end(); ++i)
+ {
+ if(*i == "SYSTEM")
+ {
+ system = true;
+ continue;
+ }
+ if(i->size() == 0)
+ {
+ this->SetError("given empty-string as include directory.");
+ return false;
+ }
+
+ std::vector<std::string> includes;
+
+ this->GetIncludes(*i, includes);
+
+ if (before)
+ {
+ beforeIncludes.insert(beforeIncludes.end(),
+ includes.begin(),
+ includes.end());
+ }
+ else
+ {
+ afterIncludes.insert(afterIncludes.end(),
+ includes.begin(),
+ includes.end());
+ }
+ if (system)
+ {
+ for (std::vector<std::string>::const_iterator li = includes.begin();
+ li != includes.end(); ++li)
+ {
+ systemIncludes.insert(*li);
+ }
+ }
+ }
+ std::reverse(beforeIncludes.begin(), beforeIncludes.end());
+
+ this->Makefile->AddIncludeDirectories(afterIncludes);
+ this->Makefile->AddIncludeDirectories(beforeIncludes, before);
+ this->Makefile->AddSystemIncludeDirectories(systemIncludes);
+
+ return true;
+}
+
+static bool StartsWithGeneratorExpression(const std::string &input)
+{
+ return input[0] == '$' && input[1] == '<';
+}
+
+// do a lot of cleanup on the arguments because this is one place where folks
+// sometimes take the output of a program and pass it directly into this
+// command not thinking that a single argument could be filled with spaces
+// and newlines etc liek below:
+//
+// " /foo/bar
+// /boo/hoo /dingle/berry "
+//
+// ideally that should be three separate arguments but when sucking the
+// output from a program and passing it into a command the cleanup doesn't
+// always happen
+//
+void cmIncludeDirectoryCommand::GetIncludes(const std::string &arg,
+ std::vector<std::string> &incs)
+{
+ // break apart any line feed arguments
+ std::string::size_type pos = 0;
+ std::string::size_type lastPos = 0;
+ while((pos = arg.find('\n', lastPos)) != std::string::npos)
+ {
+ if (pos)
+ {
+ std::string inc = arg.substr(lastPos,pos);
+ this->NormalizeInclude(inc);
+ if (!inc.empty())
+ {
+ incs.push_back(inc);
+ }
+ }
+ lastPos = pos + 1;
+ }
+ std::string inc = arg.substr(lastPos);
+ this->NormalizeInclude(inc);
+ if (!inc.empty())
+ {
+ incs.push_back(inc);
+ }
+}
+
+void cmIncludeDirectoryCommand::NormalizeInclude(std::string &inc)
+{
+ std::string::size_type b = inc.find_first_not_of(" \r");
+ std::string::size_type e = inc.find_last_not_of(" \r");
+ if ((b!=inc.npos) && (e!=inc.npos))
+ {
+ inc.assign(inc, b, 1+e-b); // copy the remaining substring
+ }
+ else
+ {
+ inc = "";
+ return;
+ }
+
+ if (!cmSystemTools::IsOff(inc.c_str()))
+ {
+ cmSystemTools::ConvertToUnixSlashes(inc);
+
+ if(!cmSystemTools::FileIsFullPath(inc.c_str()))
+ {
+ if(!StartsWithGeneratorExpression(inc))
+ {
+ std::string tmp = this->Makefile->GetStartDirectory();
+ tmp += "/";
+ tmp += inc;
+ inc = tmp;
+ }
+ }
+ }
+}
diff --git a/Source/cmIncludeDirectoryCommand.h b/Source/cmIncludeDirectoryCommand.h
new file mode 100644
index 0000000000..6cc2c8335e
--- /dev/null
+++ b/Source/cmIncludeDirectoryCommand.h
@@ -0,0 +1,56 @@
+/*============================================================================
+ 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 cmIncludeDirectoryCommand_h
+#define cmIncludeDirectoryCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmIncludeDirectoryCommand
+ * \brief Add include directories to the build.
+ *
+ * cmIncludeDirectoryCommand is used to specify directory locations
+ * to search for included files.
+ */
+class cmIncludeDirectoryCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmIncludeDirectoryCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "include_directories";}
+
+ cmTypeMacro(cmIncludeDirectoryCommand, cmCommand);
+
+protected:
+ // used internally
+ void GetIncludes(const std::string &arg, std::vector<std::string> &incs);
+ void NormalizeInclude(std::string &inc);
+};
+
+
+
+#endif
diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx
new file mode 100644
index 0000000000..d40d8fe722
--- /dev/null
+++ b/Source/cmIncludeExternalMSProjectCommand.cxx
@@ -0,0 +1,101 @@
+/*============================================================================
+ 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 "cmIncludeExternalMSProjectCommand.h"
+
+// cmIncludeExternalMSProjectCommand
+bool cmIncludeExternalMSProjectCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2)
+ {
+ this->SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect "
+ "number of arguments");
+ return false;
+ }
+// only compile this for win32 to avoid coverage errors
+#ifdef _WIN32
+ if(this->Makefile->GetDefinition("WIN32"))
+ {
+ enum Doing { DoingNone, DoingType, DoingGuid, DoingPlatform };
+
+ Doing doing = DoingNone;
+
+ std::string customType;
+ std::string customGuid;
+ std::string platformMapping;
+
+ std::vector<std::string> depends;
+ for (unsigned int i=2; i<args.size(); ++i)
+ {
+ if (args[i] == "TYPE")
+ {
+ doing = DoingType;
+ }
+ else if (args[i] == "GUID")
+ {
+ doing = DoingGuid;
+ }
+ else if (args[i] == "PLATFORM")
+ {
+ doing = DoingPlatform;
+ }
+ else
+ {
+ switch (doing)
+ {
+ case DoingNone: depends.push_back(args[i]); break;
+ case DoingType: customType = args[i]; break;
+ case DoingGuid: customGuid = args[i]; break;
+ case DoingPlatform: platformMapping = args[i]; break;
+ }
+ doing = DoingNone;
+ }
+ }
+
+ // Hack together a utility target storing enough information
+ // to reproduce the target inclusion.
+ std::string utility_name = args[0];
+
+ std::string path = args[1];
+ cmSystemTools::ConvertToUnixSlashes(path);
+
+ if (!customGuid.empty())
+ {
+ std::string guidVariable = utility_name + "_GUID_CMAKE";
+ this->Makefile->GetCMakeInstance()->AddCacheEntry(
+ guidVariable.c_str(), customGuid.c_str(),
+ "Stored GUID", cmCacheManager::INTERNAL);
+ }
+
+ // Create a target instance for this utility.
+ cmTarget* target=this->Makefile->AddNewTarget(cmTarget::UTILITY,
+ utility_name.c_str());
+
+ target->SetProperty("GENERATOR_FILE_NAME", utility_name.c_str());
+ target->SetProperty("EXTERNAL_MSPROJECT", path.c_str());
+ target->SetProperty("EXCLUDE_FROM_ALL", "FALSE");
+
+ if (!customType.empty())
+ target->SetProperty("VS_PROJECT_TYPE",customType.c_str());
+ if (!platformMapping.empty())
+ target->SetProperty("VS_PLATFORM_MAPPING",platformMapping.c_str());
+
+ for (std::vector<std::string>::const_iterator it = depends.begin();
+ it != depends.end();
+ ++it)
+ {
+ target->AddUtility(it->c_str());
+ }
+ }
+#endif
+ return true;
+}
diff --git a/Source/cmIncludeExternalMSProjectCommand.h b/Source/cmIncludeExternalMSProjectCommand.h
new file mode 100644
index 0000000000..081f77a01d
--- /dev/null
+++ b/Source/cmIncludeExternalMSProjectCommand.h
@@ -0,0 +1,52 @@
+/*============================================================================
+ 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 cmIncludeExternalMSProjectCommand_h
+#define cmIncludeExternalMSProjectCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmIncludeExternalMSProjectCommand
+ * \brief Specify an external MS project file for inclusion in the workspace.
+ *
+ * cmIncludeExternalMSProjectCommand is used to specify an externally
+ * generated Microsoft project file for inclusion in the default workspace
+ * generated by CMake.
+ */
+class cmIncludeExternalMSProjectCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmIncludeExternalMSProjectCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "include_external_msproject";}
+
+ cmTypeMacro(cmIncludeExternalMSProjectCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmIncludeRegularExpressionCommand.cxx b/Source/cmIncludeRegularExpressionCommand.cxx
new file mode 100644
index 0000000000..d6dfdd2a35
--- /dev/null
+++ b/Source/cmIncludeRegularExpressionCommand.cxx
@@ -0,0 +1,32 @@
+/*============================================================================
+ 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 "cmIncludeRegularExpressionCommand.h"
+
+// cmIncludeRegularExpressionCommand
+bool cmIncludeRegularExpressionCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if((args.size() < 1) || (args.size() > 2))
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ this->Makefile->SetIncludeRegularExpression(args[0].c_str());
+
+ if(args.size() > 1)
+ {
+ this->Makefile->SetComplainRegularExpression(args[1]);
+ }
+
+ return true;
+}
+
diff --git a/Source/cmIncludeRegularExpressionCommand.h b/Source/cmIncludeRegularExpressionCommand.h
new file mode 100644
index 0000000000..c58f01876d
--- /dev/null
+++ b/Source/cmIncludeRegularExpressionCommand.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmIncludeRegularExpressionCommand_h
+#define cmIncludeRegularExpressionCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmIncludeRegularExpressionCommand
+ * \brief Set the regular expression for following #includes.
+ *
+ * cmIncludeRegularExpressionCommand is used to specify the regular expression
+ * that determines whether to follow a #include file in dependency checking.
+ */
+class cmIncludeRegularExpressionCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmIncludeRegularExpressionCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "include_regular_expression";}
+
+ cmTypeMacro(cmIncludeRegularExpressionCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx
new file mode 100644
index 0000000000..ec500d9668
--- /dev/null
+++ b/Source/cmInstallCommand.cxx
@@ -0,0 +1,1438 @@
+/*============================================================================
+ 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 "cmInstallCommand.h"
+
+#include "cmInstallDirectoryGenerator.h"
+#include "cmInstallFilesGenerator.h"
+#include "cmInstallScriptGenerator.h"
+#include "cmInstallTargetGenerator.h"
+#include "cmInstallExportGenerator.h"
+#include "cmInstallCommandArguments.h"
+#include "cmTargetExport.h"
+#include "cmExportSet.h"
+
+#include <cmsys/Glob.hxx>
+
+static cmInstallTargetGenerator* CreateInstallTargetGenerator(cmTarget& target,
+ const cmInstallCommandArguments& args, bool impLib, bool forceOpt = false)
+{
+ cmInstallGenerator::MessageLevel message =
+ cmInstallGenerator::SelectMessageLevel(target.GetMakefile());
+ return new cmInstallTargetGenerator(target, args.GetDestination().c_str(),
+ impLib, args.GetPermissions().c_str(),
+ args.GetConfigurations(), args.GetComponent().c_str(),
+ message,
+ args.GetOptional() || forceOpt);
+}
+
+static cmInstallFilesGenerator* CreateInstallFilesGenerator(
+ cmMakefile* mf,
+ const std::vector<std::string>& absFiles,
+ const cmInstallCommandArguments& args, bool programs)
+{
+ cmInstallGenerator::MessageLevel message =
+ cmInstallGenerator::SelectMessageLevel(mf);
+ return new cmInstallFilesGenerator(mf,
+ absFiles, args.GetDestination().c_str(),
+ programs, args.GetPermissions().c_str(),
+ args.GetConfigurations(), args.GetComponent().c_str(),
+ message,
+ args.GetRename().c_str(), args.GetOptional());
+}
+
+
+// cmInstallCommand
+bool cmInstallCommand::InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &)
+{
+ // Allow calling with no arguments so that arguments may be built up
+ // using a variable that may be left empty.
+ if(args.empty())
+ {
+ return true;
+ }
+
+ // Enable the install target.
+ this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->EnableInstallTarget();
+
+ this->DefaultComponentName = this->Makefile->GetSafeDefinition(
+ "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
+ if (this->DefaultComponentName.empty())
+ {
+ this->DefaultComponentName = "Unspecified";
+ }
+
+ // Switch among the command modes.
+ if(args[0] == "SCRIPT")
+ {
+ return this->HandleScriptMode(args);
+ }
+ else if(args[0] == "CODE")
+ {
+ return this->HandleScriptMode(args);
+ }
+ else if(args[0] == "TARGETS")
+ {
+ return this->HandleTargetsMode(args);
+ }
+ else if(args[0] == "FILES")
+ {
+ return this->HandleFilesMode(args);
+ }
+ else if(args[0] == "PROGRAMS")
+ {
+ return this->HandleFilesMode(args);
+ }
+ else if(args[0] == "DIRECTORY")
+ {
+ return this->HandleDirectoryMode(args);
+ }
+ else if(args[0] == "EXPORT")
+ {
+ return this->HandleExportMode(args);
+ }
+
+ // Unknown mode.
+ std::string e = "called with unknown mode ";
+ e += args[0];
+ this->SetError(e);
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
+{
+ std::string component = this->DefaultComponentName;
+ int componentCount = 0;
+ bool doing_script = false;
+ bool doing_code = false;
+
+ // Scan the args once for COMPONENT. Only allow one.
+ //
+ for(size_t i=0; i < args.size(); ++i)
+ {
+ if(args[i] == "COMPONENT" && i+1 < args.size())
+ {
+ ++componentCount;
+ ++i;
+ component = args[i];
+ }
+ }
+
+ if(componentCount>1)
+ {
+ this->SetError("given more than one COMPONENT for the SCRIPT or CODE "
+ "signature of the INSTALL command. "
+ "Use multiple INSTALL commands with one COMPONENT each.");
+ return false;
+ }
+
+ // Scan the args again, this time adding install generators each time we
+ // encounter a SCRIPT or CODE arg:
+ //
+ for(size_t i=0; i < args.size(); ++i)
+ {
+ if(args[i] == "SCRIPT")
+ {
+ doing_script = true;
+ doing_code = false;
+ }
+ else if(args[i] == "CODE")
+ {
+ doing_script = false;
+ doing_code = true;
+ }
+ else if(args[i] == "COMPONENT")
+ {
+ doing_script = false;
+ doing_code = false;
+ }
+ else if(doing_script)
+ {
+ doing_script = false;
+ std::string script = args[i];
+ if(!cmSystemTools::FileIsFullPath(script.c_str()))
+ {
+ script = this->Makefile->GetCurrentDirectory();
+ script += "/";
+ script += args[i];
+ }
+ if(cmSystemTools::FileIsDirectory(script.c_str()))
+ {
+ this->SetError("given a directory as value of SCRIPT argument.");
+ return false;
+ }
+ this->Makefile->AddInstallGenerator(
+ new cmInstallScriptGenerator(script.c_str(), false,
+ component.c_str()));
+ }
+ else if(doing_code)
+ {
+ doing_code = false;
+ std::string code = args[i];
+ this->Makefile->AddInstallGenerator(
+ new cmInstallScriptGenerator(code.c_str(), true,
+ component.c_str()));
+ }
+ }
+
+ if(doing_script)
+ {
+ this->SetError("given no value for SCRIPT argument.");
+ return false;
+ }
+ if(doing_code)
+ {
+ this->SetError("given no value for CODE argument.");
+ return false;
+ }
+
+ //Tell the global generator about any installation component names specified.
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(component.c_str());
+
+ return true;
+}
+
+
+/*struct InstallPart
+{
+ InstallPart(cmCommandArgumentsHelper* helper, const char* key,
+ cmCommandArgumentGroup* group);
+ cmCAStringVector argVector;
+ cmInstallCommandArguments args;
+};*/
+
+//----------------------------------------------------------------------------
+bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
+{
+ // This is the TARGETS mode.
+ std::vector<cmTarget*> targets;
+
+ cmCommandArgumentsHelper argHelper;
+ cmCommandArgumentGroup group;
+ cmCAStringVector genericArgVector (&argHelper,0);
+ cmCAStringVector archiveArgVector (&argHelper,"ARCHIVE",&group);
+ cmCAStringVector libraryArgVector (&argHelper,"LIBRARY",&group);
+ cmCAStringVector runtimeArgVector (&argHelper,"RUNTIME",&group);
+ cmCAStringVector frameworkArgVector (&argHelper,"FRAMEWORK",&group);
+ cmCAStringVector bundleArgVector (&argHelper,"BUNDLE",&group);
+ cmCAStringVector includesArgVector (&argHelper,"INCLUDES",&group);
+ cmCAStringVector privateHeaderArgVector(&argHelper,"PRIVATE_HEADER",&group);
+ cmCAStringVector publicHeaderArgVector (&argHelper,"PUBLIC_HEADER",&group);
+ cmCAStringVector resourceArgVector (&argHelper,"RESOURCE",&group);
+ genericArgVector.Follows(0);
+ group.Follows(&genericArgVector);
+
+ argHelper.Parse(&args, 0);
+
+ // now parse the generic args (i.e. the ones not specialized on LIBRARY/
+ // ARCHIVE, RUNTIME etc. (see above)
+ // These generic args also contain the targets and the export stuff
+ std::vector<std::string> unknownArgs;
+ cmInstallCommandArguments genericArgs(this->DefaultComponentName);
+ cmCAStringVector targetList(&genericArgs.Parser, "TARGETS");
+ cmCAString exports(&genericArgs.Parser,"EXPORT", &genericArgs.ArgumentGroup);
+ targetList.Follows(0);
+ genericArgs.ArgumentGroup.Follows(&targetList);
+ genericArgs.Parse(&genericArgVector.GetVector(), &unknownArgs);
+ bool success = genericArgs.Finalize();
+
+ cmInstallCommandArguments archiveArgs(this->DefaultComponentName);
+ cmInstallCommandArguments libraryArgs(this->DefaultComponentName);
+ cmInstallCommandArguments runtimeArgs(this->DefaultComponentName);
+ cmInstallCommandArguments frameworkArgs(this->DefaultComponentName);
+ cmInstallCommandArguments bundleArgs(this->DefaultComponentName);
+ cmInstallCommandArguments privateHeaderArgs(this->DefaultComponentName);
+ cmInstallCommandArguments publicHeaderArgs(this->DefaultComponentName);
+ cmInstallCommandArguments resourceArgs(this->DefaultComponentName);
+ cmInstallCommandIncludesArgument includesArgs;
+
+ // now parse the args for specific parts of the target (e.g. LIBRARY,
+ // RUNTIME, ARCHIVE etc.
+ archiveArgs.Parse (&archiveArgVector.GetVector(), &unknownArgs);
+ libraryArgs.Parse (&libraryArgVector.GetVector(), &unknownArgs);
+ runtimeArgs.Parse (&runtimeArgVector.GetVector(), &unknownArgs);
+ frameworkArgs.Parse (&frameworkArgVector.GetVector(), &unknownArgs);
+ bundleArgs.Parse (&bundleArgVector.GetVector(), &unknownArgs);
+ privateHeaderArgs.Parse(&privateHeaderArgVector.GetVector(), &unknownArgs);
+ publicHeaderArgs.Parse (&publicHeaderArgVector.GetVector(), &unknownArgs);
+ resourceArgs.Parse (&resourceArgVector.GetVector(), &unknownArgs);
+ includesArgs.Parse (&includesArgVector.GetVector(), &unknownArgs);
+
+ if(!unknownArgs.empty())
+ {
+ // Unknown argument.
+ cmOStringStream e;
+ e << "TARGETS given unknown argument \"" << unknownArgs[0] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // apply generic args
+ archiveArgs.SetGenericArguments(&genericArgs);
+ libraryArgs.SetGenericArguments(&genericArgs);
+ runtimeArgs.SetGenericArguments(&genericArgs);
+ frameworkArgs.SetGenericArguments(&genericArgs);
+ bundleArgs.SetGenericArguments(&genericArgs);
+ privateHeaderArgs.SetGenericArguments(&genericArgs);
+ publicHeaderArgs.SetGenericArguments(&genericArgs);
+ resourceArgs.SetGenericArguments(&genericArgs);
+
+ success = success && archiveArgs.Finalize();
+ success = success && libraryArgs.Finalize();
+ success = success && runtimeArgs.Finalize();
+ success = success && frameworkArgs.Finalize();
+ success = success && bundleArgs.Finalize();
+ success = success && privateHeaderArgs.Finalize();
+ success = success && publicHeaderArgs.Finalize();
+ success = success && resourceArgs.Finalize();
+
+ if(!success)
+ {
+ return false;
+ }
+
+ // Enforce argument rules too complex to specify for the
+ // general-purpose parser.
+ if(archiveArgs.GetNamelinkOnly() ||
+ runtimeArgs.GetNamelinkOnly() ||
+ frameworkArgs.GetNamelinkOnly() ||
+ bundleArgs.GetNamelinkOnly() ||
+ privateHeaderArgs.GetNamelinkOnly() ||
+ publicHeaderArgs.GetNamelinkOnly() ||
+ resourceArgs.GetNamelinkOnly())
+ {
+ this->SetError(
+ "TARGETS given NAMELINK_ONLY option not in LIBRARY group. "
+ "The NAMELINK_ONLY option may be specified only following LIBRARY."
+ );
+ return false;
+ }
+ if(archiveArgs.GetNamelinkSkip() ||
+ runtimeArgs.GetNamelinkSkip() ||
+ frameworkArgs.GetNamelinkSkip() ||
+ bundleArgs.GetNamelinkSkip() ||
+ privateHeaderArgs.GetNamelinkSkip() ||
+ publicHeaderArgs.GetNamelinkSkip() ||
+ resourceArgs.GetNamelinkSkip())
+ {
+ this->SetError(
+ "TARGETS given NAMELINK_SKIP option not in LIBRARY group. "
+ "The NAMELINK_SKIP option may be specified only following LIBRARY."
+ );
+ return false;
+ }
+ if(libraryArgs.GetNamelinkOnly() && libraryArgs.GetNamelinkSkip())
+ {
+ this->SetError(
+ "TARGETS given NAMELINK_ONLY and NAMELINK_SKIP. "
+ "At most one of these two options may be specified."
+ );
+ return false;
+ }
+
+ // Select the mode for installing symlinks to versioned shared libraries.
+ cmInstallTargetGenerator::NamelinkModeType
+ namelinkMode = cmInstallTargetGenerator::NamelinkModeNone;
+ if(libraryArgs.GetNamelinkOnly())
+ {
+ namelinkMode = cmInstallTargetGenerator::NamelinkModeOnly;
+ }
+ else if(libraryArgs.GetNamelinkSkip())
+ {
+ namelinkMode = cmInstallTargetGenerator::NamelinkModeSkip;
+ }
+
+ // Check if there is something to do.
+ if(targetList.GetVector().empty())
+ {
+ return true;
+ }
+
+ // Check whether this is a DLL platform.
+ bool dll_platform = (this->Makefile->IsOn("WIN32") ||
+ this->Makefile->IsOn("CYGWIN") ||
+ this->Makefile->IsOn("MINGW"));
+
+ for(std::vector<std::string>::const_iterator
+ targetIt=targetList.GetVector().begin();
+ targetIt!=targetList.GetVector().end();
+ ++targetIt)
+ {
+
+ if (this->Makefile->IsAlias(*targetIt))
+ {
+ cmOStringStream e;
+ e << "TARGETS given target \"" << (*targetIt)
+ << "\" which is an alias.";
+ this->SetError(e.str());
+ return false;
+ }
+ // Lookup this target in the current directory.
+ 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)
+ {
+ cmOStringStream e;
+ e << "TARGETS given target \"" << (*targetIt)
+ << "\" which is not an executable, library, or module.";
+ this->SetError(e.str());
+ return false;
+ }
+ else if(target->GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "TARGETS given OBJECT library \"" << (*targetIt)
+ << "\" which may not be installed.";
+ this->SetError(e.str());
+ return false;
+ }
+ // Store the target in the list to be installed.
+ targets.push_back(target);
+ }
+ else
+ {
+ // Did not find the target.
+ cmOStringStream e;
+ e << "TARGETS given target \"" << (*targetIt)
+ << "\" which does not exist in this directory.";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // Keep track of whether we will be performing an installation of
+ // any files of the given type.
+ bool installsArchive = false;
+ bool installsLibrary = false;
+ bool installsRuntime = false;
+ bool installsFramework = false;
+ bool installsBundle = false;
+ bool installsPrivateHeader = false;
+ bool installsPublicHeader = false;
+ bool installsResource = false;
+
+ // Generate install script code to install the given targets.
+ for(std::vector<cmTarget*>::iterator ti = targets.begin();
+ ti != targets.end(); ++ti)
+ {
+ // Handle each target type.
+ cmTarget& target = *(*ti);
+ cmInstallTargetGenerator* archiveGenerator = 0;
+ cmInstallTargetGenerator* libraryGenerator = 0;
+ cmInstallTargetGenerator* runtimeGenerator = 0;
+ cmInstallTargetGenerator* frameworkGenerator = 0;
+ cmInstallTargetGenerator* bundleGenerator = 0;
+ cmInstallFilesGenerator* privateHeaderGenerator = 0;
+ cmInstallFilesGenerator* publicHeaderGenerator = 0;
+ cmInstallFilesGenerator* resourceGenerator = 0;
+
+ // Track whether this is a namelink-only rule.
+ bool namelinkOnly = false;
+
+ switch(target.GetType())
+ {
+ case cmTarget::SHARED_LIBRARY:
+ {
+ // Shared libraries are handled differently on DLL and non-DLL
+ // platforms. All windows platforms are DLL platforms including
+ // cygwin. Currently no other platform is a DLL platform.
+ if(dll_platform)
+ {
+ // When in namelink only mode skip all libraries on Windows.
+ if(namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly)
+ {
+ continue;
+ }
+
+ // This is a DLL platform.
+ if(!archiveArgs.GetDestination().empty())
+ {
+ // The import library uses the ARCHIVE properties.
+ archiveGenerator = CreateInstallTargetGenerator(target,
+ archiveArgs, true);
+ }
+ if(!runtimeArgs.GetDestination().empty())
+ {
+ // The DLL uses the RUNTIME properties.
+ runtimeGenerator = CreateInstallTargetGenerator(target,
+ runtimeArgs, false);
+ }
+ if ((archiveGenerator==0) && (runtimeGenerator==0))
+ {
+ this->SetError("Library TARGETS given no DESTINATION!");
+ return false;
+ }
+ }
+ else
+ {
+ // This is a non-DLL platform.
+ // If it is marked with FRAMEWORK property use the FRAMEWORK set of
+ // INSTALL properties. Otherwise, use the LIBRARY properties.
+ if(target.IsFrameworkOnApple())
+ {
+ // When in namelink only mode skip frameworks.
+ if(namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly)
+ {
+ continue;
+ }
+
+ // Use the FRAMEWORK properties.
+ if (!frameworkArgs.GetDestination().empty())
+ {
+ frameworkGenerator = CreateInstallTargetGenerator(target,
+ frameworkArgs, false);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "TARGETS given no FRAMEWORK DESTINATION for shared library "
+ "FRAMEWORK target \"" << target.GetName() << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else
+ {
+ // The shared library uses the LIBRARY properties.
+ if (!libraryArgs.GetDestination().empty())
+ {
+ libraryGenerator = CreateInstallTargetGenerator(target,
+ libraryArgs, false);
+ libraryGenerator->SetNamelinkMode(namelinkMode);
+ namelinkOnly =
+ (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "TARGETS given no LIBRARY DESTINATION for shared library "
+ "target \"" << target.GetName() << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ }
+ }
+ break;
+ case cmTarget::STATIC_LIBRARY:
+ {
+ // Static libraries use ARCHIVE properties.
+ if (!archiveArgs.GetDestination().empty())
+ {
+ archiveGenerator = CreateInstallTargetGenerator(target, archiveArgs,
+ false);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "TARGETS given no ARCHIVE DESTINATION for static library "
+ "target \"" << target.GetName() << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ break;
+ case cmTarget::MODULE_LIBRARY:
+ {
+ // Modules use LIBRARY properties.
+ if (!libraryArgs.GetDestination().empty())
+ {
+ libraryGenerator = CreateInstallTargetGenerator(target, libraryArgs,
+ false);
+ libraryGenerator->SetNamelinkMode(namelinkMode);
+ namelinkOnly =
+ (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "TARGETS given no LIBRARY DESTINATION for module target \""
+ << target.GetName() << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ break;
+ case cmTarget::EXECUTABLE:
+ {
+ if(target.IsAppBundleOnApple())
+ {
+ // Application bundles use the BUNDLE properties.
+ if (!bundleArgs.GetDestination().empty())
+ {
+ bundleGenerator = CreateInstallTargetGenerator(target, bundleArgs,
+ false);
+ }
+ else if(!runtimeArgs.GetDestination().empty())
+ {
+ bool failure = false;
+ if(this->CheckCMP0006(failure))
+ {
+ // For CMake 2.4 compatibility fallback to the RUNTIME
+ // properties.
+ bundleGenerator =
+ CreateInstallTargetGenerator(target, runtimeArgs, false);
+ }
+ else if(failure)
+ {
+ return false;
+ }
+ }
+ if(!bundleGenerator)
+ {
+ cmOStringStream e;
+ e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE "
+ "executable target \"" << target.GetName() << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else
+ {
+ // Executables use the RUNTIME properties.
+ if (!runtimeArgs.GetDestination().empty())
+ {
+ runtimeGenerator = CreateInstallTargetGenerator(target,
+ runtimeArgs, false);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "TARGETS given no RUNTIME DESTINATION for executable "
+ "target \"" << target.GetName() << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // On DLL platforms an executable may also have an import
+ // library. Install it to the archive destination if it
+ // exists.
+ if(dll_platform && !archiveArgs.GetDestination().empty() &&
+ target.IsExecutableWithExports())
+ {
+ // The import library uses the ARCHIVE properties.
+ archiveGenerator = CreateInstallTargetGenerator(target,
+ archiveArgs, true, true);
+ }
+ }
+ break;
+ case cmTarget::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.
+ break;
+ default:
+ // This should never happen due to the above type check.
+ // Ignore the case.
+ break;
+ }
+
+ // These well-known sets of files are installed *automatically* for
+ // FRAMEWORK SHARED library targets on the Mac as part of installing the
+ // FRAMEWORK. For other target types or on other platforms, they are not
+ // installed automatically and so we need to create install files
+ // generators for them.
+ bool createInstallGeneratorsForTargetFileSets = true;
+
+ if(target.IsFrameworkOnApple()
+ || target.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ createInstallGeneratorsForTargetFileSets = false;
+ }
+
+ if(createInstallGeneratorsForTargetFileSets && !namelinkOnly)
+ {
+ const char* files = target.GetProperty("PRIVATE_HEADER");
+ if ((files) && (*files))
+ {
+ std::vector<std::string> relFiles;
+ cmSystemTools::ExpandListArgument(files, relFiles);
+ std::vector<std::string> absFiles;
+ if (!this->MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles))
+ {
+ return false;
+ }
+
+ // Create the files install generator.
+ if (!privateHeaderArgs.GetDestination().empty())
+ {
+ privateHeaderGenerator =
+ CreateInstallFilesGenerator(this->Makefile, absFiles,
+ privateHeaderArgs, false);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "INSTALL TARGETS - target " << target.GetName() << " has "
+ << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
+ cmSystemTools::Message(e.str().c_str(), "Warning");
+ }
+ }
+
+ files = target.GetProperty("PUBLIC_HEADER");
+ if ((files) && (*files))
+ {
+ std::vector<std::string> relFiles;
+ cmSystemTools::ExpandListArgument(files, relFiles);
+ std::vector<std::string> absFiles;
+ if (!this->MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles))
+ {
+ return false;
+ }
+
+ // Create the files install generator.
+ if (!publicHeaderArgs.GetDestination().empty())
+ {
+ publicHeaderGenerator =
+ CreateInstallFilesGenerator(this->Makefile, absFiles,
+ publicHeaderArgs, false);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "INSTALL TARGETS - target " << target.GetName() << " has "
+ << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
+ cmSystemTools::Message(e.str().c_str(), "Warning");
+ }
+ }
+
+ files = target.GetProperty("RESOURCE");
+ if ((files) && (*files))
+ {
+ std::vector<std::string> relFiles;
+ cmSystemTools::ExpandListArgument(files, relFiles);
+ std::vector<std::string> absFiles;
+ if (!this->MakeFilesFullPath("RESOURCE", relFiles, absFiles))
+ {
+ return false;
+ }
+
+ // Create the files install generator.
+ if (!resourceArgs.GetDestination().empty())
+ {
+ resourceGenerator = CreateInstallFilesGenerator(
+ this->Makefile, absFiles, resourceArgs, false);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "INSTALL TARGETS - target " << target.GetName() << " has "
+ << "RESOURCE files but no RESOURCE DESTINATION.";
+ cmSystemTools::Message(e.str().c_str(), "Warning");
+ }
+ }
+ }
+
+ // Keep track of whether we're installing anything in each category
+ installsArchive = installsArchive || archiveGenerator != 0;
+ installsLibrary = installsLibrary || libraryGenerator != 0;
+ installsRuntime = installsRuntime || runtimeGenerator != 0;
+ installsFramework = installsFramework || frameworkGenerator != 0;
+ installsBundle = installsBundle || bundleGenerator != 0;
+ installsPrivateHeader = installsPrivateHeader
+ || privateHeaderGenerator != 0;
+ installsPublicHeader = installsPublicHeader || publicHeaderGenerator != 0;
+ installsResource = installsResource || resourceGenerator;
+
+ this->Makefile->AddInstallGenerator(archiveGenerator);
+ this->Makefile->AddInstallGenerator(libraryGenerator);
+ this->Makefile->AddInstallGenerator(runtimeGenerator);
+ this->Makefile->AddInstallGenerator(frameworkGenerator);
+ this->Makefile->AddInstallGenerator(bundleGenerator);
+ this->Makefile->AddInstallGenerator(privateHeaderGenerator);
+ this->Makefile->AddInstallGenerator(publicHeaderGenerator);
+ this->Makefile->AddInstallGenerator(resourceGenerator);
+
+ // Add this install rule to an export if one was specified and
+ // this is not a namelink-only rule.
+ if(!exports.GetString().empty() && !namelinkOnly)
+ {
+ cmTargetExport *te = new cmTargetExport;
+ te->Target = &target;
+ te->ArchiveGenerator = archiveGenerator;
+ te->BundleGenerator = bundleGenerator;
+ te->FrameworkGenerator = frameworkGenerator;
+ te->HeaderGenerator = publicHeaderGenerator;
+ te->LibraryGenerator = libraryGenerator;
+ te->RuntimeGenerator = runtimeGenerator;
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->GetExportSets()[exports.GetString()]->AddTargetExport(te);
+
+ std::vector<std::string> dirs = includesArgs.GetIncludeDirs();
+ if(!dirs.empty())
+ {
+ std::string dirString;
+ const char *sep = "";
+ for (std::vector<std::string>::const_iterator it = dirs.begin();
+ it != dirs.end(); ++it)
+ {
+ te->InterfaceIncludeDirectories += sep;
+ te->InterfaceIncludeDirectories += *it;
+ sep = ";";
+ }
+ }
+ }
+ }
+
+ // Tell the global generator about any installation component names
+ // specified
+ if (installsArchive)
+ {
+ this->Makefile->GetLocalGenerator()->
+ GetGlobalGenerator()
+ ->AddInstallComponent(archiveArgs.GetComponent().c_str());
+ }
+ if (installsLibrary)
+ {
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(libraryArgs.GetComponent().c_str());
+ }
+ if (installsRuntime)
+ {
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(runtimeArgs.GetComponent().c_str());
+ }
+ if (installsFramework)
+ {
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(frameworkArgs.GetComponent().c_str());
+ }
+ if (installsBundle)
+ {
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(bundleArgs.GetComponent().c_str());
+ }
+ if (installsPrivateHeader)
+ {
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(privateHeaderArgs.GetComponent().c_str());
+ }
+ if (installsPublicHeader)
+ {
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(publicHeaderArgs.GetComponent().c_str());
+ }
+ if (installsResource)
+ {
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(resourceArgs.GetComponent().c_str());
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
+{
+ // This is the FILES mode.
+ bool programs = (args[0] == "PROGRAMS");
+ cmInstallCommandArguments ica(this->DefaultComponentName);
+ cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES");
+ files.Follows(0);
+ ica.ArgumentGroup.Follows(&files);
+ std::vector<std::string> unknownArgs;
+ ica.Parse(&args, &unknownArgs);
+
+ if(!unknownArgs.empty())
+ {
+ // Unknown argument.
+ cmOStringStream e;
+ e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Check if there is something to do.
+ if(files.GetVector().empty())
+ {
+ return true;
+ }
+
+ if(!ica.GetRename().empty() && files.GetVector().size() > 1)
+ {
+ // The rename option works only with one file.
+ cmOStringStream e;
+ e << args[0] << " given RENAME option with more than one file.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ std::vector<std::string> absFiles;
+ if (!this->MakeFilesFullPath(args[0].c_str(), files.GetVector(), absFiles))
+ {
+ return false;
+ }
+
+ if (!ica.Finalize())
+ {
+ return false;
+ }
+
+ if(ica.GetDestination().empty())
+ {
+ // A destination is required.
+ cmOStringStream e;
+ e << args[0] << " given no DESTINATION!";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Create the files install generator.
+ this->Makefile->AddInstallGenerator(
+ CreateInstallFilesGenerator(this->Makefile, absFiles, ica, programs));
+
+ //Tell the global generator about any installation component names specified.
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(ica.GetComponent().c_str());
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
+{
+ enum Doing { DoingNone, DoingDirs, DoingDestination, DoingPattern,
+ DoingRegex, DoingPermsFile, DoingPermsDir, DoingPermsMatch,
+ DoingConfigurations, DoingComponent };
+ Doing doing = DoingDirs;
+ bool in_match_mode = false;
+ bool optional = false;
+ bool message_never = false;
+ std::vector<std::string> dirs;
+ const char* destination = 0;
+ std::string permissions_file;
+ std::string permissions_dir;
+ std::vector<std::string> configurations;
+ std::string component = this->DefaultComponentName;
+ std::string literal_args;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "DESTINATION")
+ {
+ if(in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Switch to setting the destination property.
+ doing = DoingDestination;
+ }
+ else if(args[i] == "OPTIONAL")
+ {
+ if(in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Mark the rule as optional.
+ optional = true;
+ doing = DoingNone;
+ }
+ else if(args[i] == "MESSAGE_NEVER")
+ {
+ if(in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Mark the rule as quiet.
+ message_never = true;
+ doing = DoingNone;
+ }
+ else if(args[i] == "PATTERN")
+ {
+ // Switch to a new pattern match rule.
+ doing = DoingPattern;
+ in_match_mode = true;
+ }
+ else if(args[i] == "REGEX")
+ {
+ // Switch to a new regex match rule.
+ doing = DoingRegex;
+ in_match_mode = true;
+ }
+ else if(args[i] == "EXCLUDE")
+ {
+ // Add this property to the current match rule.
+ if(!in_match_mode || doing == DoingPattern || doing == DoingRegex)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" before a PATTERN or REGEX is given.";
+ this->SetError(e.str());
+ return false;
+ }
+ literal_args += " EXCLUDE";
+ doing = DoingNone;
+ }
+ else if(args[i] == "PERMISSIONS")
+ {
+ if(!in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" before a PATTERN or REGEX is given.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Switch to setting the current match permissions property.
+ literal_args += " PERMISSIONS";
+ doing = DoingPermsMatch;
+ }
+ else if(args[i] == "FILE_PERMISSIONS")
+ {
+ if(in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Switch to setting the file permissions property.
+ doing = DoingPermsFile;
+ }
+ else if(args[i] == "DIRECTORY_PERMISSIONS")
+ {
+ if(in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Switch to setting the directory permissions property.
+ doing = DoingPermsDir;
+ }
+ else if(args[i] == "USE_SOURCE_PERMISSIONS")
+ {
+ if(in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Add this option literally.
+ literal_args += " USE_SOURCE_PERMISSIONS";
+ doing = DoingNone;
+ }
+ else if(args[i] == "FILES_MATCHING")
+ {
+ if(in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Add this option literally.
+ literal_args += " FILES_MATCHING";
+ doing = DoingNone;
+ }
+ else if(args[i] == "CONFIGURATIONS")
+ {
+ if(in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Switch to setting the configurations property.
+ doing = DoingConfigurations;
+ }
+ else if(args[i] == "COMPONENT")
+ {
+ if(in_match_mode)
+ {
+ cmOStringStream e;
+ e << args[0] << " does not allow \""
+ << args[i] << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Switch to setting the component property.
+ doing = DoingComponent;
+ }
+ else if(doing == DoingDirs)
+ {
+ // Convert this directory to a full path.
+ std::string dir = args[i];
+ if(!cmSystemTools::FileIsFullPath(dir.c_str()))
+ {
+ dir = this->Makefile->GetCurrentDirectory();
+ dir += "/";
+ dir += args[i];
+ }
+
+ // Make sure the name is a directory.
+ if(cmSystemTools::FileExists(dir.c_str()) &&
+ !cmSystemTools::FileIsDirectory(dir.c_str()))
+ {
+ cmOStringStream e;
+ e << args[0] << " given non-directory \""
+ << args[i] << "\" to install.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Store the directory for installation.
+ dirs.push_back(dir);
+ }
+ else if(doing == DoingConfigurations)
+ {
+ configurations.push_back(args[i]);
+ }
+ else if(doing == DoingDestination)
+ {
+ destination = args[i].c_str();
+ doing = DoingNone;
+ }
+ else if(doing == DoingPattern)
+ {
+ // Convert the pattern to a regular expression. Require a
+ // leading slash and trailing end-of-string in the matched
+ // string to make sure the pattern matches only whole file
+ // names.
+ literal_args += " REGEX \"/";
+ std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
+ cmSystemTools::ReplaceString(regex, "\\", "\\\\");
+ literal_args += regex;
+ literal_args += "$\"";
+ doing = DoingNone;
+ }
+ else if(doing == DoingRegex)
+ {
+ literal_args += " REGEX \"";
+ // Match rules are case-insensitive on some platforms.
+#if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
+ std::string regex = cmSystemTools::LowerCase(args[i]);
+#else
+ std::string regex = args[i];
+#endif
+ cmSystemTools::ReplaceString(regex, "\\", "\\\\");
+ literal_args += regex;
+ literal_args += "\"";
+ doing = DoingNone;
+ }
+ else if(doing == DoingComponent)
+ {
+ component = args[i];
+ doing = DoingNone;
+ }
+ else if(doing == DoingPermsFile)
+ {
+ // Check the requested permission.
+ if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_file))
+ {
+ cmOStringStream e;
+ e << args[0] << " given invalid file permission \""
+ << args[i] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else if(doing == DoingPermsDir)
+ {
+ // Check the requested permission.
+ if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_dir))
+ {
+ cmOStringStream e;
+ e << args[0] << " given invalid directory permission \""
+ << args[i] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else if(doing == DoingPermsMatch)
+ {
+ // Check the requested permission.
+ if(!cmInstallCommandArguments::CheckPermissions(args[i], literal_args))
+ {
+ cmOStringStream e;
+ e << args[0] << " given invalid permission \""
+ << args[i] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else
+ {
+ // Unknown argument.
+ cmOStringStream e;
+ e << args[0] << " given unknown argument \"" << args[i] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // Support installing an empty directory.
+ if(dirs.empty() && destination)
+ {
+ dirs.push_back("");
+ }
+
+ // Check if there is something to do.
+ if(dirs.empty())
+ {
+ return true;
+ }
+ if(!destination)
+ {
+ // A destination is required.
+ cmOStringStream e;
+ e << args[0] << " given no DESTINATION!";
+ this->SetError(e.str());
+ return false;
+ }
+
+ cmInstallGenerator::MessageLevel message =
+ cmInstallGenerator::SelectMessageLevel(this->Makefile, message_never);
+
+ // Create the directory install generator.
+ this->Makefile->AddInstallGenerator(
+ new cmInstallDirectoryGenerator(dirs, destination,
+ permissions_file.c_str(),
+ permissions_dir.c_str(),
+ configurations,
+ component.c_str(),
+ message,
+ literal_args.c_str(),
+ optional));
+
+ // Tell the global generator about any installation component names
+ // specified.
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(component.c_str());
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
+{
+ // This is the EXPORT mode.
+ cmInstallCommandArguments ica(this->DefaultComponentName);
+ cmCAString exp(&ica.Parser, "EXPORT");
+ cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup);
+ cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES",
+ &ica.ArgumentGroup);
+ cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup);
+ exp.Follows(0);
+
+ ica.ArgumentGroup.Follows(&exp);
+ std::vector<std::string> unknownArgs;
+ ica.Parse(&args, &unknownArgs);
+
+ if (!unknownArgs.empty())
+ {
+ // Unknown argument.
+ cmOStringStream e;
+ e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+
+ if (!ica.Finalize())
+ {
+ return false;
+ }
+
+ // Make sure there is a destination.
+ if(ica.GetDestination().empty())
+ {
+ // A destination is required.
+ cmOStringStream e;
+ e << args[0] << " given no DESTINATION!";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Check the file name.
+ std::string fname = filename.GetString();
+ if(fname.find_first_of(":/\\") != fname.npos)
+ {
+ cmOStringStream e;
+ e << args[0] << " given invalid export file name \"" << fname << "\". "
+ << "The FILE argument may not contain a path. "
+ << "Specify the path in the DESTINATION argument.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Check the file extension.
+ if(!fname.empty() &&
+ cmSystemTools::GetFilenameLastExtension(fname) != ".cmake")
+ {
+ cmOStringStream e;
+ e << args[0] << " given invalid export file name \"" << fname << "\". "
+ << "The FILE argument must specify a name ending in \".cmake\".";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Construct the file name.
+ if(fname.empty())
+ {
+ fname = exp.GetString();
+ fname += ".cmake";
+
+ if(fname.find_first_of(":/\\") != fname.npos)
+ {
+ cmOStringStream e;
+ e << args[0] << " given export name \"" << exp.GetString() << "\". "
+ << "This name cannot be safely converted to a file name. "
+ << "Specify a different export name or use the FILE option to set "
+ << "a file name explicitly.";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ cmExportSet *exportSet = this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->GetExportSets()[exp.GetString()];
+ if (exportOld.IsEnabled())
+ {
+ for(std::vector<cmTargetExport*>::const_iterator
+ tei = exportSet->GetTargetExports()->begin();
+ tei != exportSet->GetTargetExports()->end(); ++tei)
+ {
+ cmTargetExport const* te = *tei;
+ const bool newCMP0022Behavior =
+ te->Target->GetPolicyStatusCMP0022() != cmPolicies::WARN
+ && te->Target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
+
+ if(!newCMP0022Behavior)
+ {
+ cmOStringStream e;
+ e << "INSTALL(EXPORT) given keyword \""
+ << "EXPORT_LINK_INTERFACE_LIBRARIES" << "\", but target \""
+ << te->Target->GetName()
+ << "\" does not have policy CMP0022 set to NEW.";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ }
+
+ cmInstallGenerator::MessageLevel message =
+ cmInstallGenerator::SelectMessageLevel(this->Makefile);
+
+ // Create the export install generator.
+ cmInstallExportGenerator* exportGenerator =
+ new cmInstallExportGenerator(
+ exportSet,
+ ica.GetDestination().c_str(),
+ ica.GetPermissions().c_str(), ica.GetConfigurations(),
+ ica.GetComponent().c_str(), message, fname.c_str(),
+ name_space.GetCString(), exportOld.IsEnabled(), this->Makefile);
+ this->Makefile->AddInstallGenerator(exportGenerator);
+
+ return true;
+}
+
+bool cmInstallCommand::MakeFilesFullPath(const char* modeName,
+ const std::vector<std::string>& relFiles,
+ std::vector<std::string>& absFiles)
+{
+ for(std::vector<std::string>::const_iterator fileIt = relFiles.begin();
+ fileIt != relFiles.end();
+ ++fileIt)
+ {
+ std::string file = (*fileIt);
+ std::string::size_type gpos = cmGeneratorExpression::Find(file);
+ if(gpos != 0 && !cmSystemTools::FileIsFullPath(file.c_str()))
+ {
+ file = this->Makefile->GetCurrentDirectory();
+ file += "/";
+ file += *fileIt;
+ }
+
+ // Make sure the file is not a directory.
+ if(gpos == file.npos && cmSystemTools::FileIsDirectory(file.c_str()))
+ {
+ cmOStringStream e;
+ e << modeName << " given directory \"" << (*fileIt) << "\" to install.";
+ this->SetError(e.str());
+ return false;
+ }
+ // Store the file for installation.
+ absFiles.push_back(file);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmInstallCommand::CheckCMP0006(bool& failure)
+{
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0006))
+ {
+ case cmPolicies::WARN:
+ {
+ this->Makefile->IssueMessage(
+ cmake::AUTHOR_WARNING,
+ this->Makefile->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0006)
+ );
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to allow compatibility
+ return true;
+ case cmPolicies::NEW:
+ // NEW behavior is to disallow compatibility
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ failure = true;
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ this->Makefile->GetPolicies()
+ ->GetRequiredPolicyError(cmPolicies::CMP0006)
+ );
+ break;
+ }
+ return false;
+}
diff --git a/Source/cmInstallCommand.h b/Source/cmInstallCommand.h
new file mode 100644
index 0000000000..8e14a08287
--- /dev/null
+++ b/Source/cmInstallCommand.h
@@ -0,0 +1,63 @@
+/*============================================================================
+ 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 cmInstallCommand_h
+#define cmInstallCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmInstallCommand
+ * \brief Specifies where to install some files
+ *
+ * cmInstallCommand is a general-purpose interface command for
+ * specifying install rules.
+ */
+class cmInstallCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmInstallCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "install";}
+
+ cmTypeMacro(cmInstallCommand, cmCommand);
+
+private:
+ bool HandleScriptMode(std::vector<std::string> const& args);
+ bool HandleTargetsMode(std::vector<std::string> const& args);
+ bool HandleFilesMode(std::vector<std::string> const& args);
+ bool HandleDirectoryMode(std::vector<std::string> const& args);
+ bool HandleExportMode(std::vector<std::string> const& args);
+ bool MakeFilesFullPath(const char* modeName,
+ const std::vector<std::string>& relFiles,
+ std::vector<std::string>& absFiles);
+ bool CheckCMP0006(bool& failure);
+
+ std::string DefaultComponentName;
+};
+
+
+#endif
diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx
new file mode 100644
index 0000000000..236ca1febb
--- /dev/null
+++ b/Source/cmInstallCommandArguments.cxx
@@ -0,0 +1,234 @@
+/*============================================================================
+ 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 "cmInstallCommandArguments.h"
+#include "cmSystemTools.h"
+
+// Table of valid permissions.
+const char* cmInstallCommandArguments::PermissionsTable[] =
+{
+ "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE",
+ "GROUP_READ", "GROUP_WRITE", "GROUP_EXECUTE",
+ "WORLD_READ", "WORLD_WRITE", "WORLD_EXECUTE",
+ "SETUID", "SETGID", 0
+};
+
+const std::string cmInstallCommandArguments::EmptyString;
+
+cmInstallCommandArguments::cmInstallCommandArguments(
+ const std::string& defaultComponent)
+:Parser()
+,ArgumentGroup()
+,Destination (&Parser, "DESTINATION" , &ArgumentGroup)
+,Component (&Parser, "COMPONENT" , &ArgumentGroup)
+,Rename (&Parser, "RENAME" , &ArgumentGroup)
+,Permissions (&Parser, "PERMISSIONS" , &ArgumentGroup)
+,Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup)
+,Optional (&Parser, "OPTIONAL" , &ArgumentGroup)
+,NamelinkOnly (&Parser, "NAMELINK_ONLY" , &ArgumentGroup)
+,NamelinkSkip (&Parser, "NAMELINK_SKIP" , &ArgumentGroup)
+,GenericArguments(0)
+,DefaultComponentName(defaultComponent)
+{
+}
+
+const std::string& cmInstallCommandArguments::GetDestination() const
+{
+ if (!this->DestinationString.empty())
+ {
+ return this->DestinationString;
+ }
+ if (this->GenericArguments!=0)
+ {
+ return this->GenericArguments->GetDestination();
+ }
+ return this->EmptyString;
+}
+
+const std::string& cmInstallCommandArguments::GetComponent() const
+{
+ if (!this->Component.GetString().empty())
+ {
+ return this->Component.GetString();
+ }
+ if (this->GenericArguments!=0)
+ {
+ return this->GenericArguments->GetComponent();
+ }
+ if (!this->DefaultComponentName.empty())
+ {
+ return this->DefaultComponentName;
+ }
+ static std::string unspecifiedComponent = "Unspecified";
+ return unspecifiedComponent;
+}
+
+const std::string& cmInstallCommandArguments::GetRename() const
+{
+ if (!this->Rename.GetString().empty())
+ {
+ return this->Rename.GetString();
+ }
+ if (this->GenericArguments!=0)
+ {
+ return this->GenericArguments->GetRename();
+ }
+ return this->EmptyString;
+}
+
+const std::string& cmInstallCommandArguments::GetPermissions() const
+{
+ if (!this->PermissionsString.empty())
+ {
+ return this->PermissionsString;
+ }
+ if (this->GenericArguments!=0)
+ {
+ return this->GenericArguments->GetPermissions();
+ }
+ return this->EmptyString;
+}
+
+bool cmInstallCommandArguments::GetOptional() const
+{
+ if (this->Optional.IsEnabled())
+ {
+ return true;
+ }
+ if (this->GenericArguments!=0)
+ {
+ return this->GenericArguments->GetOptional();
+ }
+ return false;
+}
+
+bool cmInstallCommandArguments::GetNamelinkOnly() const
+{
+ if (this->NamelinkOnly.IsEnabled())
+ {
+ return true;
+ }
+ if (this->GenericArguments!=0)
+ {
+ return this->GenericArguments->GetNamelinkOnly();
+ }
+ return false;
+}
+
+bool cmInstallCommandArguments::GetNamelinkSkip() const
+{
+ if (this->NamelinkSkip.IsEnabled())
+ {
+ return true;
+ }
+ if (this->GenericArguments!=0)
+ {
+ return this->GenericArguments->GetNamelinkSkip();
+ }
+ return false;
+}
+
+const std::vector<std::string>&
+ cmInstallCommandArguments::GetConfigurations() const
+{
+ if (!this->Configurations.GetVector().empty())
+ {
+ return this->Configurations.GetVector();
+ }
+ if (this->GenericArguments!=0)
+ {
+ return this->GenericArguments->GetConfigurations();
+ }
+ return this->Configurations.GetVector();
+}
+
+
+bool cmInstallCommandArguments::Finalize()
+{
+ if (!this->CheckPermissions())
+ {
+ return false;
+ }
+ this->DestinationString = this->Destination.GetString();
+ cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
+ return true;
+}
+
+void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
+ std::vector<std::string>* unconsumedArgs)
+{
+ this->Parser.Parse(args, unconsumedArgs);
+}
+
+
+bool cmInstallCommandArguments::CheckPermissions()
+{
+ this->PermissionsString = "";
+ for(std::vector<std::string>::const_iterator
+ permIt = this->Permissions.GetVector().begin();
+ permIt != this->Permissions.GetVector().end();
+ ++permIt)
+ {
+ if (!this->CheckPermissions(*permIt, this->PermissionsString))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool cmInstallCommandArguments::CheckPermissions(
+ const std::string& onePermission, std::string& permissions)
+{
+ // Check the permission against the table.
+ for(const char** valid = cmInstallCommandArguments::PermissionsTable;
+ *valid; ++valid)
+ {
+ if(onePermission == *valid)
+ {
+ // This is a valid permission.
+ permissions += " ";
+ permissions += onePermission;
+ return true;
+ }
+ }
+ // This is not a valid permission.
+ return false;
+}
+
+cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument()
+{
+
+}
+
+const std::vector<std::string>&
+cmInstallCommandIncludesArgument::GetIncludeDirs() const
+{
+ return this->IncludeDirs;
+}
+
+void cmInstallCommandIncludesArgument::Parse(
+ const std::vector<std::string>* args,
+ std::vector<std::string>*)
+{
+ if(args->empty())
+ {
+ return;
+ }
+ std::vector<std::string>::const_iterator it = args->begin();
+ ++it;
+ for ( ; it != args->end(); ++it)
+ {
+ std::string dir = *it;
+ cmSystemTools::ConvertToUnixSlashes(dir);
+ this->IncludeDirs.push_back(dir);
+ }
+}
diff --git a/Source/cmInstallCommandArguments.h b/Source/cmInstallCommandArguments.h
new file mode 100644
index 0000000000..90347e6686
--- /dev/null
+++ b/Source/cmInstallCommandArguments.h
@@ -0,0 +1,81 @@
+/*============================================================================
+ 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 cmInstallCommandArguments_h
+#define cmInstallCommandArguments_h
+
+#include "cmStandardIncludes.h"
+#include "cmCommandArgumentsHelper.h"
+
+class cmInstallCommandArguments
+{
+ public:
+ cmInstallCommandArguments(const std::string& defaultComponent);
+ void SetGenericArguments(cmInstallCommandArguments* args)
+ {this->GenericArguments = args;}
+ void Parse(const std::vector<std::string>* args,
+ std::vector<std::string>* unconsumedArgs);
+
+ // Compute destination path.and check permissions
+ bool Finalize();
+
+ const std::string& GetDestination() const;
+ const std::string& GetComponent() const;
+ const std::string& GetRename() const;
+ const std::string& GetPermissions() const;
+ const std::vector<std::string>& GetConfigurations() const;
+ bool GetOptional() const;
+ bool GetNamelinkOnly() const;
+ bool GetNamelinkSkip() const;
+
+ // once HandleDirectoryMode() is also switched to using
+ // cmInstallCommandArguments then these two functions can become non-static
+ // private member functions without arguments
+ static bool CheckPermissions(const std::string& onePerm,
+ std::string& perm);
+ cmCommandArgumentsHelper Parser;
+ cmCommandArgumentGroup ArgumentGroup;
+ private:
+ cmInstallCommandArguments(); // disabled
+ cmCAString Destination;
+ cmCAString Component;
+ cmCAString Rename;
+ cmCAStringVector Permissions;
+ cmCAStringVector Configurations;
+ cmCAEnabler Optional;
+ cmCAEnabler NamelinkOnly;
+ cmCAEnabler NamelinkSkip;
+
+ std::string DestinationString;
+ std::string PermissionsString;
+
+ cmInstallCommandArguments* GenericArguments;
+ static const char* PermissionsTable[];
+ static const std::string EmptyString;
+ std::string DefaultComponentName;
+ bool CheckPermissions();
+};
+
+class cmInstallCommandIncludesArgument
+{
+ public:
+ cmInstallCommandIncludesArgument();
+ void Parse(const std::vector<std::string>* args,
+ std::vector<std::string>* unconsumedArgs);
+
+ const std::vector<std::string>& GetIncludeDirs() const;
+
+ private:
+ std::vector<std::string> IncludeDirs;
+};
+
+#endif
diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx
new file mode 100644
index 0000000000..8c13bab588
--- /dev/null
+++ b/Source/cmInstallDirectoryGenerator.cxx
@@ -0,0 +1,54 @@
+/*============================================================================
+ 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 "cmInstallDirectoryGenerator.h"
+
+#include "cmTarget.h"
+
+//----------------------------------------------------------------------------
+cmInstallDirectoryGenerator
+::cmInstallDirectoryGenerator(std::vector<std::string> const& dirs,
+ const char* dest,
+ const char* file_permissions,
+ const char* dir_permissions,
+ std::vector<std::string> const& configurations,
+ const char* component,
+ MessageLevel message,
+ const char* literal_args,
+ bool optional):
+ cmInstallGenerator(dest, configurations, component, message),
+ Directories(dirs),
+ FilePermissions(file_permissions), DirPermissions(dir_permissions),
+ LiteralArguments(literal_args), Optional(optional)
+{
+}
+
+//----------------------------------------------------------------------------
+cmInstallDirectoryGenerator
+::~cmInstallDirectoryGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+void
+cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os,
+ Indent const& indent)
+{
+ // Write code to install the directories.
+ const char* no_rename = 0;
+ this->AddInstallRule(os, cmInstallType_DIRECTORY,
+ this->Directories,
+ this->Optional,
+ this->FilePermissions.c_str(),
+ this->DirPermissions.c_str(),
+ no_rename, this->LiteralArguments.c_str(),
+ indent);
+}
diff --git a/Source/cmInstallDirectoryGenerator.h b/Source/cmInstallDirectoryGenerator.h
new file mode 100644
index 0000000000..165ab91547
--- /dev/null
+++ b/Source/cmInstallDirectoryGenerator.h
@@ -0,0 +1,43 @@
+/*============================================================================
+ 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 cmInstallDirectoryGenerator_h
+#define cmInstallDirectoryGenerator_h
+
+#include "cmInstallGenerator.h"
+
+/** \class cmInstallDirectoryGenerator
+ * \brief Generate directory installation rules.
+ */
+class cmInstallDirectoryGenerator: public cmInstallGenerator
+{
+public:
+ cmInstallDirectoryGenerator(std::vector<std::string> const& dirs,
+ const char* dest,
+ const char* file_permissions,
+ const char* dir_permissions,
+ std::vector<std::string> const& configurations,
+ const char* component,
+ MessageLevel message,
+ const char* literal_args,
+ bool optional = false);
+ virtual ~cmInstallDirectoryGenerator();
+
+protected:
+ virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
+ std::vector<std::string> Directories;
+ std::string FilePermissions;
+ std::string DirPermissions;
+ std::string LiteralArguments;
+ bool Optional;
+};
+
+#endif
diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx
new file mode 100644
index 0000000000..ddfd6c59c4
--- /dev/null
+++ b/Source/cmInstallExportGenerator.cxx
@@ -0,0 +1,229 @@
+/*============================================================================
+ 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 "cmInstallExportGenerator.h"
+
+#include <stdio.h>
+
+#include "cmake.h"
+#include "cmInstallTargetGenerator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+
+#include "cmInstallFilesGenerator.h"
+
+#include "cmExportInstallFileGenerator.h"
+#include "cmExportSet.h"
+
+//----------------------------------------------------------------------------
+cmInstallExportGenerator::cmInstallExportGenerator(
+ cmExportSet* exportSet,
+ const char* destination,
+ const char* file_permissions,
+ std::vector<std::string> const& configurations,
+ const char* component,
+ MessageLevel message,
+ const char* filename, const char* name_space,
+ bool exportOld,
+ cmMakefile* mf)
+ :cmInstallGenerator(destination, configurations, component, message)
+ ,ExportSet(exportSet)
+ ,FilePermissions(file_permissions)
+ ,FileName(filename)
+ ,Namespace(name_space)
+ ,ExportOld(exportOld)
+ ,Makefile(mf)
+{
+ this->EFGen = new cmExportInstallFileGenerator(this);
+ exportSet->AddInstallation(this);
+}
+
+//----------------------------------------------------------------------------
+cmInstallExportGenerator::~cmInstallExportGenerator()
+{
+ delete this->EFGen;
+}
+
+//----------------------------------------------------------------------------
+void cmInstallExportGenerator::ComputeTempDir()
+{
+ // Choose a temporary directory in which to generate the import
+ // files to be installed.
+ this->TempDir = this->Makefile->GetCurrentOutputDirectory();
+ this->TempDir += cmake::GetCMakeFilesDirectory();
+ this->TempDir += "/Export";
+ if(this->Destination.empty())
+ {
+ return;
+ }
+ else
+ {
+ this->TempDir += "/";
+ }
+
+ // Enforce a maximum length.
+ bool useMD5 = false;
+#if defined(_WIN32) || defined(__CYGWIN__)
+ std::string::size_type const max_total_len = 250;
+#else
+ std::string::size_type const max_total_len = 1000;
+#endif
+ if(this->TempDir.size() < max_total_len)
+ {
+ // Keep the total path length below the limit.
+ std::string::size_type max_len = max_total_len - this->TempDir.size();
+ if(this->Destination.size() > max_len)
+ {
+ useMD5 = true;
+ }
+ }
+ else
+ {
+ useMD5 = true;
+ }
+ if(useMD5)
+ {
+ // Replace the destination path with a hash to keep it short.
+ this->TempDir +=
+ cmSystemTools::ComputeStringMD5(this->Destination);
+ }
+ else
+ {
+ std::string dest = this->Destination;
+ // Avoid unix full paths.
+ if(dest[0] == '/')
+ {
+ dest[0] = '_';
+ }
+ // Avoid windows full paths by removing colons.
+ cmSystemTools::ReplaceString(dest, ":", "_");
+ // Avoid relative paths that go up the tree.
+ cmSystemTools::ReplaceString(dest, "../", "__/");
+ // Avoid spaces.
+ cmSystemTools::ReplaceString(dest, " ", "_");
+ this->TempDir += dest;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmInstallExportGenerator::GenerateScript(std::ostream& os)
+{
+ // Skip empty sets.
+ if(ExportSet->GetTargetExports()->empty())
+ {
+ cmOStringStream e;
+ e << "INSTALL(EXPORT) given unknown export \""
+ << ExportSet->GetName() << "\"";
+ cmSystemTools::Error(e.str().c_str());
+ return;
+ }
+
+ // Create the temporary directory in which to store the files.
+ this->ComputeTempDir();
+ cmSystemTools::MakeDirectory(this->TempDir.c_str());
+
+ // Construct a temporary location for the file.
+ this->MainImportFile = this->TempDir;
+ this->MainImportFile += "/";
+ this->MainImportFile += this->FileName;
+
+ // Generate the import file for this export set.
+ this->EFGen->SetExportFile(this->MainImportFile.c_str());
+ this->EFGen->SetNamespace(this->Namespace);
+ this->EFGen->SetExportOld(this->ExportOld);
+ if(this->ConfigurationTypes->empty())
+ {
+ if(!this->ConfigurationName.empty())
+ {
+ this->EFGen->AddConfiguration(this->ConfigurationName);
+ }
+ else
+ {
+ this->EFGen->AddConfiguration("");
+ }
+ }
+ else
+ {
+ for(std::vector<std::string>::const_iterator
+ ci = this->ConfigurationTypes->begin();
+ ci != this->ConfigurationTypes->end(); ++ci)
+ {
+ this->EFGen->AddConfiguration(*ci);
+ }
+ }
+ this->EFGen->GenerateImportFile();
+
+ // Perform the main install script generation.
+ this->cmInstallGenerator::GenerateScript(os);
+}
+
+//----------------------------------------------------------------------------
+void
+cmInstallExportGenerator::GenerateScriptConfigs(std::ostream& os,
+ Indent const& indent)
+{
+ // Create the main install rules first.
+ this->cmInstallGenerator::GenerateScriptConfigs(os, indent);
+
+ // Now create a configuration-specific install rule for the import
+ // file of each configuration.
+ std::vector<std::string> files;
+ for(std::map<std::string, std::string>::const_iterator
+ i = this->EFGen->GetConfigImportFiles().begin();
+ i != this->EFGen->GetConfigImportFiles().end(); ++i)
+ {
+ files.push_back(i->second);
+ std::string config_test = this->CreateConfigTest(i->first);
+ os << indent << "if(" << config_test << ")\n";
+ this->AddInstallRule(os, cmInstallType_FILES, files, false,
+ this->FilePermissions.c_str(), 0, 0, 0,
+ indent.Next());
+ os << indent << "endif()\n";
+ files.clear();
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmInstallExportGenerator::GenerateScriptActions(std::ostream& os,
+ Indent const& indent)
+{
+ // Remove old per-configuration export files if the main changes.
+ std::string installedDir = "$ENV{DESTDIR}";
+ installedDir += this->GetInstallDestination();
+ installedDir += "/";
+ std::string installedFile = installedDir;
+ installedFile += this->FileName;
+ os << indent << "if(EXISTS \"" << installedFile << "\")\n";
+ Indent indentN = indent.Next();
+ Indent indentNN = indentN.Next();
+ Indent indentNNN = indentNN.Next();
+ os << indentN << "file(DIFFERENT EXPORT_FILE_CHANGED FILES\n"
+ << indentN << " \"" << installedFile << "\"\n"
+ << indentN << " \"" << this->MainImportFile << "\")\n";
+ os << indentN << "if(EXPORT_FILE_CHANGED)\n";
+ os << indentNN << "file(GLOB OLD_CONFIG_FILES \"" << installedDir
+ << this->EFGen->GetConfigImportFileGlob() << "\")\n";
+ os << indentNN << "if(OLD_CONFIG_FILES)\n";
+ os << indentNNN << "message(STATUS \"Old export file \\\"" << installedFile
+ << "\\\" will be replaced. Removing files [${OLD_CONFIG_FILES}].\")\n";
+ os << indentNNN << "file(REMOVE ${OLD_CONFIG_FILES})\n";
+ os << indentNN << "endif()\n";
+ os << indentN << "endif()\n";
+ os << indent << "endif()\n";
+
+ // Install the main export file.
+ std::vector<std::string> files;
+ files.push_back(this->MainImportFile);
+ this->AddInstallRule(os, cmInstallType_FILES, files, false,
+ this->FilePermissions.c_str(), 0, 0, 0, indent);
+}
diff --git a/Source/cmInstallExportGenerator.h b/Source/cmInstallExportGenerator.h
new file mode 100644
index 0000000000..eb8c28bbe9
--- /dev/null
+++ b/Source/cmInstallExportGenerator.h
@@ -0,0 +1,64 @@
+/*============================================================================
+ 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 cmInstallExportGenerator_h
+#define cmInstallExportGenerator_h
+
+#include "cmInstallGenerator.h"
+
+class cmExportInstallFileGenerator;
+class cmInstallFilesGenerator;
+class cmInstallTargetGenerator;
+class cmExportSet;
+class cmMakefile;
+
+/** \class cmInstallExportGenerator
+ * \brief Generate rules for creating an export files.
+ */
+class cmInstallExportGenerator: public cmInstallGenerator
+{
+public:
+ cmInstallExportGenerator(cmExportSet* exportSet,
+ const char* dest, const char* file_permissions,
+ const std::vector<std::string>& configurations,
+ const char* component,
+ MessageLevel message,
+ const char* filename, const char* name_space,
+ bool exportOld, cmMakefile* mf);
+ ~cmInstallExportGenerator();
+
+ cmExportSet* GetExportSet() {return this->ExportSet;}
+
+ cmMakefile* GetMakefile() const { return this->Makefile; }
+
+ const std::string& GetNamespace() const { return this->Namespace; }
+
+protected:
+ virtual void GenerateScript(std::ostream& os);
+ virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
+ virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
+ void GenerateImportFile(cmExportSet const* exportSet);
+ void GenerateImportFile(const char* config, cmExportSet const* exportSet);
+ void ComputeTempDir();
+
+ cmExportSet* ExportSet;
+ std::string FilePermissions;
+ std::string FileName;
+ std::string Namespace;
+ bool ExportOld;
+ cmMakefile* Makefile;
+
+ std::string TempDir;
+ std::string MainImportFile;
+ cmExportInstallFileGenerator* EFGen;
+};
+
+#endif
diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx
new file mode 100644
index 0000000000..f106e1a808
--- /dev/null
+++ b/Source/cmInstallFilesCommand.cxx
@@ -0,0 +1,184 @@
+/*============================================================================
+ 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 "cmInstallFilesCommand.h"
+
+#include "cmInstallFilesGenerator.h"
+
+// cmExecutableCommand
+bool cmInstallFilesCommand
+::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
+{
+ if(argsIn.size() < 2)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // Enable the install target.
+ this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->EnableInstallTarget();
+
+ std::vector<std::string> args;
+ this->Makefile->ExpandSourceListArguments(argsIn, args, 2);
+
+ this->Destination = args[0];
+
+ if((args.size() > 1) && (args[1] == "FILES"))
+ {
+ this->IsFilesForm = true;
+ for(std::vector<std::string>::const_iterator s = args.begin()+2;
+ s != args.end(); ++s)
+ {
+ // Find the source location for each file listed.
+ std::string f = this->FindInstallSource(s->c_str());
+ this->Files.push_back(f);
+ }
+ this->CreateInstallGenerator();
+ }
+ else
+ {
+ this->IsFilesForm = false;
+ std::vector<std::string>::const_iterator s = args.begin();
+ for (++s;s != args.end(); ++s)
+ {
+ this->FinalArgs.push_back(*s);
+ }
+ }
+
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(this->Makefile->GetSafeDefinition(
+ "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
+
+ return true;
+}
+
+void cmInstallFilesCommand::FinalPass()
+{
+ // No final pass for "FILES" form of arguments.
+ if(this->IsFilesForm)
+ {
+ return;
+ }
+
+ std::string testf;
+ std::string ext = this->FinalArgs[0];
+
+ // two different options
+ if (this->FinalArgs.size() > 1)
+ {
+ // now put the files into the list
+ std::vector<std::string>::iterator s = this->FinalArgs.begin();
+ ++s;
+ // for each argument, get the files
+ for (;s != this->FinalArgs.end(); ++s)
+ {
+ // replace any variables
+ std::string temps = *s;
+ if (cmSystemTools::GetFilenamePath(temps).size() > 0)
+ {
+ testf = cmSystemTools::GetFilenamePath(temps) + "/" +
+ cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
+ }
+ else
+ {
+ testf = cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
+ }
+
+ // add to the result
+ this->Files.push_back(this->FindInstallSource(testf.c_str()));
+ }
+ }
+ else // reg exp list
+ {
+ std::vector<std::string> files;
+ std::string regex = this->FinalArgs[0];
+ cmSystemTools::Glob(this->Makefile->GetCurrentDirectory(),
+ regex, files);
+
+ std::vector<std::string>::iterator s = files.begin();
+ // for each argument, get the files
+ for (;s != files.end(); ++s)
+ {
+ this->Files.push_back(this->FindInstallSource(s->c_str()));
+ }
+ }
+
+ this->CreateInstallGenerator();
+}
+
+void cmInstallFilesCommand::CreateInstallGenerator() const
+{
+ // Construct the destination. This command always installs under
+ // the prefix. We skip the leading slash given by the user.
+ std::string destination = this->Destination.substr(1);
+ cmSystemTools::ConvertToUnixSlashes(destination);
+ if(destination.empty())
+ {
+ destination = ".";
+ }
+
+ // Use a file install generator.
+ const char* no_permissions = "";
+ const char* no_rename = "";
+ std::string no_component = this->Makefile->GetSafeDefinition(
+ "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
+ std::vector<std::string> no_configurations;
+ cmInstallGenerator::MessageLevel message =
+ cmInstallGenerator::SelectMessageLevel(this->Makefile);
+ this->Makefile->AddInstallGenerator(
+ new cmInstallFilesGenerator(this->Makefile, this->Files,
+ destination.c_str(), false,
+ no_permissions, no_configurations,
+ no_component.c_str(), message, no_rename));
+}
+
+
+/**
+ * Find a file in the build or source tree for installation given a
+ * relative path from the CMakeLists.txt file. This will favor files
+ * present in the build tree. If a full path is given, it is just
+ * returned.
+ */
+std::string cmInstallFilesCommand::FindInstallSource(const char* name) const
+{
+ if(cmSystemTools::FileIsFullPath(name) ||
+ cmGeneratorExpression::Find(name) == 0)
+ {
+ // This is a full path.
+ return name;
+ }
+
+ // This is a relative path.
+ std::string tb = this->Makefile->GetCurrentOutputDirectory();
+ tb += "/";
+ tb += name;
+ std::string ts = this->Makefile->GetCurrentDirectory();
+ ts += "/";
+ ts += name;
+
+ if(cmSystemTools::FileExists(tb.c_str()))
+ {
+ // The file exists in the binary tree. Use it.
+ return tb;
+ }
+ else if(cmSystemTools::FileExists(ts.c_str()))
+ {
+ // The file exists in the source tree. Use it.
+ return ts;
+ }
+ else
+ {
+ // The file doesn't exist. Assume it will be present in the
+ // binary tree when the install occurs.
+ return tb;
+ }
+}
diff --git a/Source/cmInstallFilesCommand.h b/Source/cmInstallFilesCommand.h
new file mode 100644
index 0000000000..4551ab14f9
--- /dev/null
+++ b/Source/cmInstallFilesCommand.h
@@ -0,0 +1,75 @@
+/*============================================================================
+ 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 cmInstallFilesCommand_h
+#define cmInstallFilesCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmInstallFilesCommand
+ * \brief Specifies where to install some files
+ *
+ * cmInstallFilesCommand specifies the relative path where a list of
+ * files should be installed.
+ */
+class cmInstallFilesCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmInstallFilesCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "install_files";}
+
+ /**
+ * This is called at the end after all the information
+ * specified by the command is accumulated. Most commands do
+ * not implement this method. At this point, reading and
+ * writing to the cache can be done.
+ */
+ virtual void FinalPass();
+ virtual bool HasFinalPass() const { return !this->IsFilesForm; }
+
+ /** This command is kept for compatibility with older CMake versions. */
+ virtual bool IsDiscouraged() const
+ {
+ return true;
+ }
+
+ cmTypeMacro(cmInstallFilesCommand, cmCommand);
+
+protected:
+ void CreateInstallGenerator() const;
+ std::string FindInstallSource(const char* name) const;
+
+ private:
+ std::vector<std::string> FinalArgs;
+ bool IsFilesForm;
+ std::string Destination;
+ std::vector<std::string> Files;
+};
+
+
+#endif
diff --git a/Source/cmInstallFilesGenerator.cxx b/Source/cmInstallFilesGenerator.cxx
new file mode 100644
index 0000000000..91b102a349
--- /dev/null
+++ b/Source/cmInstallFilesGenerator.cxx
@@ -0,0 +1,98 @@
+/*============================================================================
+ 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 "cmInstallFilesGenerator.h"
+
+#include "cmGeneratorExpression.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+
+//----------------------------------------------------------------------------
+cmInstallFilesGenerator
+::cmInstallFilesGenerator(cmMakefile* mf,
+ std::vector<std::string> const& files,
+ const char* dest, bool programs,
+ const char* file_permissions,
+ std::vector<std::string> const& configurations,
+ const char* component,
+ MessageLevel message,
+ const char* rename,
+ bool optional):
+ cmInstallGenerator(dest, configurations, component, message),
+ Makefile(mf),
+ Files(files), Programs(programs),
+ FilePermissions(file_permissions),
+ Rename(rename), Optional(optional)
+{
+ // We need per-config actions if any files have generator expressions.
+ for(std::vector<std::string>::const_iterator i = files.begin();
+ !this->ActionsPerConfig && i != files.end(); ++i)
+ {
+ if(cmGeneratorExpression::Find(*i) != std::string::npos)
+ {
+ this->ActionsPerConfig = true;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+cmInstallFilesGenerator
+::~cmInstallFilesGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmInstallFilesGenerator::AddFilesInstallRule(
+ std::ostream& os, Indent const& indent,
+ std::vector<std::string> const& files)
+{
+ // Write code to install the files.
+ const char* no_dir_permissions = 0;
+ this->AddInstallRule(os,
+ (this->Programs
+ ? cmInstallType_PROGRAMS
+ : cmInstallType_FILES),
+ files,
+ this->Optional,
+ this->FilePermissions.c_str(), no_dir_permissions,
+ this->Rename.c_str(), 0, indent);
+}
+
+//----------------------------------------------------------------------------
+void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
+ Indent const& indent)
+{
+ if(this->ActionsPerConfig)
+ {
+ this->cmInstallGenerator::GenerateScriptActions(os, indent);
+ }
+ else
+ {
+ this->AddFilesInstallRule(os, indent, this->Files);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmInstallFilesGenerator::GenerateScriptForConfig(std::ostream& os,
+ const std::string& config,
+ Indent const& indent)
+{
+ std::vector<std::string> files;
+ cmGeneratorExpression ge;
+ for(std::vector<std::string>::const_iterator i = this->Files.begin();
+ i != this->Files.end(); ++i)
+ {
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
+ cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile, config),
+ files);
+ }
+ this->AddFilesInstallRule(os, indent, files);
+}
diff --git a/Source/cmInstallFilesGenerator.h b/Source/cmInstallFilesGenerator.h
new file mode 100644
index 0000000000..0dbd712713
--- /dev/null
+++ b/Source/cmInstallFilesGenerator.h
@@ -0,0 +1,52 @@
+/*============================================================================
+ 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 cmInstallFilesGenerator_h
+#define cmInstallFilesGenerator_h
+
+#include "cmInstallGenerator.h"
+
+class cmMakefile;
+
+/** \class cmInstallFilesGenerator
+ * \brief Generate file installation rules.
+ */
+class cmInstallFilesGenerator: public cmInstallGenerator
+{
+public:
+ cmInstallFilesGenerator(cmMakefile* mf,
+ std::vector<std::string> const& files,
+ const char* dest, bool programs,
+ const char* file_permissions,
+ std::vector<std::string> const& configurations,
+ const char* component,
+ MessageLevel message,
+ const char* rename,
+ bool optional = false);
+ virtual ~cmInstallFilesGenerator();
+
+protected:
+ virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
+ virtual void GenerateScriptForConfig(std::ostream& os,
+ const std::string& config,
+ Indent const& indent);
+ void AddFilesInstallRule(std::ostream& os, Indent const& indent,
+ std::vector<std::string> const& files);
+
+ cmMakefile* Makefile;
+ std::vector<std::string> Files;
+ bool Programs;
+ std::string FilePermissions;
+ std::string Rename;
+ bool Optional;
+};
+
+#endif
diff --git a/Source/cmInstallGenerator.cxx b/Source/cmInstallGenerator.cxx
new file mode 100644
index 0000000000..b261cbfd02
--- /dev/null
+++ b/Source/cmInstallGenerator.cxx
@@ -0,0 +1,216 @@
+/*============================================================================
+ 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 "cmInstallGenerator.h"
+
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+
+//----------------------------------------------------------------------------
+cmInstallGenerator
+::cmInstallGenerator(const char* destination,
+ std::vector<std::string> const& configurations,
+ const char* component,
+ MessageLevel message):
+ cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations),
+ Destination(destination? destination:""),
+ Component(component? component:""),
+ Message(message)
+{
+}
+
+//----------------------------------------------------------------------------
+cmInstallGenerator
+::~cmInstallGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmInstallGenerator
+::AddInstallRule(
+ std::ostream& os,
+ cmInstallType type,
+ std::vector<std::string> const& files,
+ bool optional /* = false */,
+ const char* permissions_file /* = 0 */,
+ const char* permissions_dir /* = 0 */,
+ const char* rename /* = 0 */,
+ const char* literal_args /* = 0 */,
+ Indent const& indent
+ )
+{
+ // Use the FILE command to install the file.
+ std::string stype;
+ switch(type)
+ {
+ case cmInstallType_DIRECTORY: stype = "DIRECTORY"; break;
+ case cmInstallType_PROGRAMS: stype = "PROGRAM"; break;
+ case cmInstallType_EXECUTABLE: stype = "EXECUTABLE"; break;
+ case cmInstallType_STATIC_LIBRARY: stype = "STATIC_LIBRARY"; break;
+ case cmInstallType_SHARED_LIBRARY: stype = "SHARED_LIBRARY"; break;
+ case cmInstallType_MODULE_LIBRARY: stype = "MODULE"; break;
+ case cmInstallType_FILES: stype = "FILE"; break;
+ }
+ os << indent;
+ std::string dest = this->GetInstallDestination();
+ if (cmSystemTools::FileIsFullPath(dest.c_str()))
+ {
+ os << "list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES\n";
+ os << indent << " \"";
+ for(std::vector<std::string>::const_iterator fi = files.begin();
+ fi != files.end(); ++fi)
+ {
+ if (fi!=files.begin())
+ {
+ os << ";";
+ }
+ os << dest << "/";
+ if (rename && *rename)
+ {
+ os << rename;
+ }
+ else
+ {
+ os << cmSystemTools::GetFilenameName(*fi);
+ }
+ }
+ os << "\")\n";
+ os << indent << "if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
+ os << indent << indent << "message(WARNING \"ABSOLUTE path INSTALL "
+ << "DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
+ os << indent << "endif()\n";
+
+ os << indent << "if(CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
+ os << indent << indent << "message(FATAL_ERROR \"ABSOLUTE path INSTALL "
+ << "DESTINATION forbidden (by caller): "
+ << "${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
+ os << indent << "endif()\n";
+ }
+ os << "file(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype;
+ if(optional)
+ {
+ os << " OPTIONAL";
+ }
+ switch(this->Message)
+ {
+ case MessageDefault: break;
+ case MessageAlways: os << " MESSAGE_ALWAYS"; break;
+ case MessageLazy: os << " MESSAGE_LAZY"; break;
+ case MessageNever: os << " MESSAGE_NEVER"; break;
+ }
+ if(permissions_file && *permissions_file)
+ {
+ os << " PERMISSIONS" << permissions_file;
+ }
+ if(permissions_dir && *permissions_dir)
+ {
+ os << " DIR_PERMISSIONS" << permissions_dir;
+ }
+ if(rename && *rename)
+ {
+ os << " RENAME \"" << rename << "\"";
+ }
+ os << " FILES";
+ if(files.size() == 1)
+ {
+ os << " \"" << files[0] << "\"";
+ }
+ else
+ {
+ for(std::vector<std::string>::const_iterator fi = files.begin();
+ fi != files.end(); ++fi)
+ {
+ os << "\n" << indent << " \"" << *fi << "\"";
+ }
+ os << "\n" << indent << " ";
+ if(!(literal_args && *literal_args))
+ {
+ os << " ";
+ }
+ }
+ if(literal_args && *literal_args)
+ {
+ os << literal_args;
+ }
+ os << ")\n";
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmInstallGenerator::CreateComponentTest(const char* component)
+{
+ std::string result = "NOT CMAKE_INSTALL_COMPONENT OR "
+ "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
+ result += component;
+ result += "\"";
+ return result;
+}
+
+//----------------------------------------------------------------------------
+void cmInstallGenerator::GenerateScript(std::ostream& os)
+{
+ // Track indentation.
+ Indent indent;
+
+ // Begin this block of installation.
+ std::string component_test =
+ this->CreateComponentTest(this->Component.c_str());
+ os << indent << "if(" << component_test << ")\n";
+
+ // Generate the script possibly with per-configuration code.
+ this->GenerateScriptConfigs(os, indent.Next());
+
+ // End this block of installation.
+ os << indent << "endif()\n\n";
+}
+
+//----------------------------------------------------------------------------
+bool cmInstallGenerator::InstallsForConfig(const std::string& config)
+{
+ return this->GeneratesForConfig(config);
+}
+
+//----------------------------------------------------------------------------
+std::string cmInstallGenerator::GetInstallDestination() const
+{
+ std::string result;
+ if(!this->Destination.empty() &&
+ !cmSystemTools::FileIsFullPath(this->Destination.c_str()))
+ {
+ result = "${CMAKE_INSTALL_PREFIX}/";
+ }
+ result += this->Destination;
+ return result;
+}
+
+//----------------------------------------------------------------------------
+cmInstallGenerator::MessageLevel
+cmInstallGenerator::SelectMessageLevel(cmMakefile* mf, bool never)
+{
+ if(never)
+ {
+ return MessageNever;
+ }
+ std::string m = mf->GetSafeDefinition("CMAKE_INSTALL_MESSAGE");
+ if(m == "ALWAYS")
+ {
+ return MessageAlways;
+ }
+ if(m == "LAZY")
+ {
+ return MessageLazy;
+ }
+ if(m == "NEVER")
+ {
+ return MessageNever;
+ }
+ return MessageDefault;
+}
diff --git a/Source/cmInstallGenerator.h b/Source/cmInstallGenerator.h
new file mode 100644
index 0000000000..38aac9185c
--- /dev/null
+++ b/Source/cmInstallGenerator.h
@@ -0,0 +1,77 @@
+/*============================================================================
+ 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 cmInstallGenerator_h
+#define cmInstallGenerator_h
+
+#include "cmInstallType.h"
+#include "cmScriptGenerator.h"
+
+class cmLocalGenerator;
+class cmMakefile;
+
+/** \class cmInstallGenerator
+ * \brief Support class for generating install scripts.
+ *
+ */
+class cmInstallGenerator: public cmScriptGenerator
+{
+public:
+ enum MessageLevel
+ {
+ MessageDefault,
+ MessageAlways,
+ MessageLazy,
+ MessageNever
+ };
+
+ cmInstallGenerator(const char* destination,
+ std::vector<std::string> const& configurations,
+ const char* component,
+ MessageLevel message);
+ virtual ~cmInstallGenerator();
+
+ void AddInstallRule(
+ std::ostream& os, cmInstallType type,
+ std::vector<std::string> const& files,
+ bool optional = false,
+ const char* permissions_file = 0,
+ const char* permissions_dir = 0,
+ const char* rename = 0,
+ const char* literal_args = 0,
+ Indent const& indent = Indent()
+ );
+
+ const char* GetDestination() const
+ { return this->Destination.c_str(); }
+
+ /** Get the install destination as it should appear in the
+ installation script. */
+ std::string GetInstallDestination() const;
+
+ /** Test if this generator installs something for a given configuration. */
+ bool InstallsForConfig(const std::string& config);
+
+ /** Select message level from CMAKE_INSTALL_MESSAGE or 'never'. */
+ static MessageLevel SelectMessageLevel(cmMakefile* mf, bool never = false);
+
+protected:
+ virtual void GenerateScript(std::ostream& os);
+
+ std::string CreateComponentTest(const char* component);
+
+ // Information shared by most generator types.
+ std::string Destination;
+ std::string Component;
+ MessageLevel Message;
+};
+
+#endif
diff --git a/Source/cmInstallProgramsCommand.cxx b/Source/cmInstallProgramsCommand.cxx
new file mode 100644
index 0000000000..0405769bbf
--- /dev/null
+++ b/Source/cmInstallProgramsCommand.cxx
@@ -0,0 +1,145 @@
+/*============================================================================
+ 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 "cmInstallProgramsCommand.h"
+#include "cmInstallFilesGenerator.h"
+// cmExecutableCommand
+bool cmInstallProgramsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // Enable the install target.
+ this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->EnableInstallTarget();
+
+ this->Destination = args[0];
+
+ std::vector<std::string>::const_iterator s = args.begin();
+ for (++s;s != args.end(); ++s)
+ {
+ this->FinalArgs.push_back(*s);
+ }
+
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(this->Makefile->GetSafeDefinition(
+ "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
+
+ return true;
+}
+
+void cmInstallProgramsCommand::FinalPass()
+{
+ bool files_mode = false;
+ if(!this->FinalArgs.empty() && this->FinalArgs[0] == "FILES")
+ {
+ files_mode = true;
+ }
+
+ // two different options
+ if (this->FinalArgs.size() > 1 || files_mode)
+ {
+ // for each argument, get the programs
+ std::vector<std::string>::iterator s = this->FinalArgs.begin();
+ if(files_mode)
+ {
+ // Skip the FILES argument in files mode.
+ ++s;
+ }
+ for(;s != this->FinalArgs.end(); ++s)
+ {
+ // add to the result
+ this->Files.push_back(this->FindInstallSource(s->c_str()));
+ }
+ }
+ else // reg exp list
+ {
+ std::vector<std::string> programs;
+ cmSystemTools::Glob(this->Makefile->GetCurrentDirectory(),
+ this->FinalArgs[0], programs);
+
+ std::vector<std::string>::iterator s = programs.begin();
+ // for each argument, get the programs
+ for (;s != programs.end(); ++s)
+ {
+ this->Files.push_back(this->FindInstallSource(s->c_str()));
+ }
+ }
+
+ // Construct the destination. This command always installs under
+ // the prefix. We skip the leading slash given by the user.
+ std::string destination = this->Destination.substr(1);
+ cmSystemTools::ConvertToUnixSlashes(destination);
+ if(destination.empty())
+ {
+ destination = ".";
+ }
+
+ // Use a file install generator.
+ const char* no_permissions = "";
+ const char* no_rename = "";
+ std::string no_component = this->Makefile->GetSafeDefinition(
+ "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
+ std::vector<std::string> no_configurations;
+ cmInstallGenerator::MessageLevel message =
+ cmInstallGenerator::SelectMessageLevel(this->Makefile);
+ this->Makefile->AddInstallGenerator(
+ new cmInstallFilesGenerator(this->Makefile, this->Files,
+ destination.c_str(), true,
+ no_permissions, no_configurations,
+ no_component.c_str(), message, no_rename));
+}
+
+/**
+ * Find a file in the build or source tree for installation given a
+ * relative path from the CMakeLists.txt file. This will favor files
+ * present in the build tree. If a full path is given, it is just
+ * returned.
+ */
+std::string cmInstallProgramsCommand
+::FindInstallSource(const char* name) const
+{
+ if(cmSystemTools::FileIsFullPath(name) ||
+ cmGeneratorExpression::Find(name) == 0)
+ {
+ // This is a full path.
+ return name;
+ }
+
+ // This is a relative path.
+ std::string tb = this->Makefile->GetCurrentOutputDirectory();
+ tb += "/";
+ tb += name;
+ std::string ts = this->Makefile->GetCurrentDirectory();
+ ts += "/";
+ ts += name;
+
+ if(cmSystemTools::FileExists(tb.c_str()))
+ {
+ // The file exists in the binary tree. Use it.
+ return tb;
+ }
+ else if(cmSystemTools::FileExists(ts.c_str()))
+ {
+ // The file exists in the source tree. Use it.
+ return ts;
+ }
+ else
+ {
+ // The file doesn't exist. Assume it will be present in the
+ // binary tree when the install occurs.
+ return tb;
+ }
+}
diff --git a/Source/cmInstallProgramsCommand.h b/Source/cmInstallProgramsCommand.h
new file mode 100644
index 0000000000..90c7ba3ac5
--- /dev/null
+++ b/Source/cmInstallProgramsCommand.h
@@ -0,0 +1,73 @@
+/*============================================================================
+ 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 cmInstallProgramsCommand_h
+#define cmInstallProgramsCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmInstallProgramsCommand
+ * \brief Specifies where to install some programs
+ *
+ * cmInstallProgramsCommand specifies the relative path where a list of
+ * programs should be installed.
+ */
+class cmInstallProgramsCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmInstallProgramsCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "install_programs";}
+
+ /**
+ * This is called at the end after all the information
+ * specified by the command is accumulated. Most commands do
+ * not implement this method. At this point, reading and
+ * writing to the cache can be done.
+ */
+ virtual void FinalPass();
+
+ virtual bool HasFinalPass() const { return true; }
+
+ /** This command is kept for compatibility with older CMake versions. */
+ virtual bool IsDiscouraged() const
+ {
+ return true;
+ }
+
+ cmTypeMacro(cmInstallProgramsCommand, cmCommand);
+
+protected:
+ std::string FindInstallSource(const char* name) const;
+private:
+ std::vector<std::string> FinalArgs;
+ std::string Destination;
+ std::vector<std::string> Files;
+};
+
+
+#endif
diff --git a/Source/cmInstallScriptGenerator.cxx b/Source/cmInstallScriptGenerator.cxx
new file mode 100644
index 0000000000..933aa07823
--- /dev/null
+++ b/Source/cmInstallScriptGenerator.cxx
@@ -0,0 +1,47 @@
+/*============================================================================
+ 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 "cmInstallScriptGenerator.h"
+
+//----------------------------------------------------------------------------
+cmInstallScriptGenerator
+::cmInstallScriptGenerator(const char* script, bool code,
+ const char* component) :
+ cmInstallGenerator(0, std::vector<std::string>(), component, MessageDefault),
+ Script(script), Code(code)
+{
+}
+
+//----------------------------------------------------------------------------
+cmInstallScriptGenerator
+::~cmInstallScriptGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmInstallScriptGenerator::GenerateScript(std::ostream& os)
+{
+ Indent indent;
+ std::string component_test =
+ this->CreateComponentTest(this->Component.c_str());
+ os << indent << "if(" << component_test << ")\n";
+
+ if(this->Code)
+ {
+ os << indent.Next() << this->Script << "\n";
+ }
+ else
+ {
+ os << indent.Next() << "include(\"" << this->Script << "\")\n";
+ }
+
+ os << indent << "endif()\n\n";
+}
diff --git a/Source/cmInstallScriptGenerator.h b/Source/cmInstallScriptGenerator.h
new file mode 100644
index 0000000000..54a7b2195c
--- /dev/null
+++ b/Source/cmInstallScriptGenerator.h
@@ -0,0 +1,33 @@
+/*============================================================================
+ 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 cmInstallScriptGenerator_h
+#define cmInstallScriptGenerator_h
+
+#include "cmInstallGenerator.h"
+
+/** \class cmInstallScriptGenerator
+ * \brief Generate target installation rules.
+ */
+class cmInstallScriptGenerator: public cmInstallGenerator
+{
+public:
+ cmInstallScriptGenerator(const char* script, bool code,
+ const char* component);
+ virtual ~cmInstallScriptGenerator();
+
+protected:
+ virtual void GenerateScript(std::ostream& os);
+ std::string Script;
+ bool Code;
+};
+
+#endif
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx
new file mode 100644
index 0000000000..d689c89ae7
--- /dev/null
+++ b/Source/cmInstallTargetGenerator.cxx
@@ -0,0 +1,840 @@
+/*============================================================================
+ 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 "cmInstallTargetGenerator.h"
+
+#include "cmComputeLinkInformation.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+
+#include <assert.h>
+
+//----------------------------------------------------------------------------
+cmInstallTargetGenerator
+::cmInstallTargetGenerator(cmTarget& t, const char* dest, bool implib,
+ const char* file_permissions,
+ std::vector<std::string> const& configurations,
+ const char* component,
+ MessageLevel message,
+ bool optional):
+ cmInstallGenerator(dest, configurations, component, message), Target(&t),
+ ImportLibrary(implib), FilePermissions(file_permissions), Optional(optional)
+{
+ this->ActionsPerConfig = true;
+ this->NamelinkMode = NamelinkModeNone;
+ this->Target->SetHaveInstallRule(true);
+}
+
+//----------------------------------------------------------------------------
+cmInstallTargetGenerator
+::~cmInstallTargetGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
+{
+ // Warn if installing an exclude-from-all target.
+ if(this->Target->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+ {
+ cmOStringStream msg;
+ msg << "WARNING: Target \"" << this->Target->GetName()
+ << "\" has EXCLUDE_FROM_ALL set and will not be built by default "
+ << "but an install rule has been provided for it. CMake does "
+ << "not define behavior for this case.";
+ cmSystemTools::Message(msg.str().c_str(), "Warning");
+ }
+
+ // Perform the main install script generation.
+ this->cmInstallGenerator::GenerateScript(os);
+}
+
+//----------------------------------------------------------------------------
+void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
+ const std::string& config,
+ Indent const& indent)
+{
+ // Compute the build tree directory from which to copy the target.
+ std::string fromDirConfig;
+ if(this->Target->NeedRelinkBeforeInstall(config))
+ {
+ fromDirConfig = this->Target->GetMakefile()->GetStartOutputDirectory();
+ fromDirConfig += cmake::GetCMakeFilesDirectory();
+ fromDirConfig += "/CMakeRelink.dir/";
+ }
+ else
+ {
+ fromDirConfig = this->Target->GetDirectory(config, this->ImportLibrary);
+ fromDirConfig += "/";
+ }
+ std::string toDir = this->GetInstallDestination();
+ toDir += "/";
+
+ // Compute the list of files to install for this target.
+ std::vector<std::string> filesFrom;
+ std::vector<std::string> filesTo;
+ std::string literal_args;
+ cmTarget::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:
+ // Not reachable. We never create a cmInstallTargetGenerator for
+ // an INTERFACE_LIBRARY.
+ assert(!"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->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR,
+ "cmInstallTargetGenerator created with non-installable target.");
+ return;
+ }
+ if(targetType == cmTarget::EXECUTABLE)
+ {
+ // There is a bug in cmInstallCommand if this fails.
+ assert(this->NamelinkMode == NamelinkModeNone);
+
+ std::string targetName;
+ std::string targetNameReal;
+ std::string targetNameImport;
+ std::string targetNamePDB;
+ this->Target->GetExecutableNames(targetName, targetNameReal,
+ targetNameImport, targetNamePDB,
+ config);
+ if(this->ImportLibrary)
+ {
+ std::string from1 = fromDirConfig + targetNameImport;
+ std::string to1 = toDir + targetNameImport;
+ filesFrom.push_back(from1);
+ filesTo.push_back(to1);
+ std::string targetNameImportLib;
+ if(this->Target->GetImplibGNUtoMS(targetNameImport,
+ targetNameImportLib))
+ {
+ filesFrom.push_back(fromDirConfig + targetNameImportLib);
+ filesTo.push_back(toDir + targetNameImportLib);
+ }
+
+ // An import library looks like a static library.
+ type = cmInstallType_STATIC_LIBRARY;
+ }
+ else
+ {
+ std::string from1 = fromDirConfig + targetName;
+ std::string to1 = toDir + targetName;
+
+ // Handle OSX Bundles.
+ if(this->Target->IsAppBundleOnApple())
+ {
+ // 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 += targetName;
+ }
+ else
+ {
+ // Tweaks apply to the real file, so list it first.
+ if(targetNameReal != targetName)
+ {
+ std::string from2 = fromDirConfig + targetNameReal;
+ std::string to2 = toDir += targetNameReal;
+ filesFrom.push_back(from2);
+ filesTo.push_back(to2);
+ }
+ }
+
+ filesFrom.push_back(from1);
+ filesTo.push_back(to1);
+ }
+ }
+ else
+ {
+ std::string targetName;
+ std::string targetNameSO;
+ std::string targetNameReal;
+ std::string targetNameImport;
+ std::string targetNamePDB;
+ this->Target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
+ targetNameImport, targetNamePDB,
+ config);
+ if(this->ImportLibrary)
+ {
+ // There is a bug in cmInstallCommand if this fails.
+ assert(this->NamelinkMode == NamelinkModeNone);
+
+ std::string from1 = fromDirConfig + targetNameImport;
+ std::string to1 = toDir + targetNameImport;
+ filesFrom.push_back(from1);
+ filesTo.push_back(to1);
+ std::string targetNameImportLib;
+ if(this->Target->GetImplibGNUtoMS(targetNameImport,
+ targetNameImportLib))
+ {
+ filesFrom.push_back(fromDirConfig + targetNameImportLib);
+ filesTo.push_back(toDir + targetNameImportLib);
+ }
+
+ // An import library looks like a static library.
+ type = cmInstallType_STATIC_LIBRARY;
+ }
+ else if(this->Target->IsFrameworkOnApple())
+ {
+ // There is a bug in cmInstallCommand if this fails.
+ assert(this->NamelinkMode == NamelinkModeNone);
+
+ // Install the whole framework directory.
+ type = cmInstallType_DIRECTORY;
+ literal_args += " USE_SOURCE_PERMISSIONS";
+
+ std::string from1 = fromDirConfig + targetName;
+ from1 = cmSystemTools::GetFilenamePath(from1);
+
+ // Tweaks apply to the binary inside the bundle.
+ std::string to1 = toDir + targetNameReal;
+
+ filesFrom.push_back(from1);
+ filesTo.push_back(to1);
+ }
+ else if(this->Target->IsCFBundleOnApple())
+ {
+ // Install the whole app bundle directory.
+ type = cmInstallType_DIRECTORY;
+ literal_args += " USE_SOURCE_PERMISSIONS";
+
+ std::string targetNameBase = targetName.substr(0, targetName.find('/'));
+
+ std::string from1 = fromDirConfig + targetNameBase;
+ std::string to1 = toDir + targetName;
+
+ filesFrom.push_back(from1);
+ filesTo.push_back(to1);
+ }
+ else
+ {
+ bool haveNamelink = false;
+
+ // Library link name.
+ std::string fromName = fromDirConfig + targetName;
+ std::string toName = toDir + targetName;
+
+ // Library interface name.
+ std::string fromSOName;
+ std::string toSOName;
+ if(targetNameSO != targetName)
+ {
+ haveNamelink = true;
+ fromSOName = fromDirConfig + targetNameSO;
+ toSOName = toDir + targetNameSO;
+ }
+
+ // Library implementation name.
+ std::string fromRealName;
+ std::string toRealName;
+ if(targetNameReal != targetName &&
+ targetNameReal != targetNameSO)
+ {
+ haveNamelink = true;
+ fromRealName = fromDirConfig + targetNameReal;
+ toRealName = toDir + targetNameReal;
+ }
+
+ // Add the names based on the current namelink mode.
+ if(haveNamelink)
+ {
+ // With a namelink we need to check the mode.
+ if(this->NamelinkMode == NamelinkModeOnly)
+ {
+ // Install the namelink only.
+ filesFrom.push_back(fromName);
+ filesTo.push_back(toName);
+ }
+ else
+ {
+ // Install the real file if it has its own name.
+ if(!fromRealName.empty())
+ {
+ filesFrom.push_back(fromRealName);
+ filesTo.push_back(toRealName);
+ }
+
+ // Install the soname link if it has its own name.
+ if(!fromSOName.empty())
+ {
+ filesFrom.push_back(fromSOName);
+ filesTo.push_back(toSOName);
+ }
+
+ // Install the namelink if it is not to be skipped.
+ if(this->NamelinkMode != NamelinkModeSkip)
+ {
+ filesFrom.push_back(fromName);
+ filesTo.push_back(toName);
+ }
+ }
+ }
+ else
+ {
+ // Without a namelink there will be only one file. Install it
+ // if this is not a namelink-only rule.
+ if(this->NamelinkMode != NamelinkModeOnly)
+ {
+ filesFrom.push_back(fromName);
+ filesTo.push_back(toName);
+ }
+ }
+ }
+ }
+
+ // If this fails the above code is buggy.
+ assert(filesFrom.size() == filesTo.size());
+
+ // Skip this rule if no files are to be installed for the target.
+ if(filesFrom.empty())
+ {
+ return;
+ }
+
+ // Add pre-installation tweaks.
+ this->AddTweak(os, indent, config, filesTo,
+ &cmInstallTargetGenerator::PreReplacementTweaks);
+
+ // Write code to install the target file.
+ const char* no_dir_permissions = 0;
+ const char* no_rename = 0;
+ bool optional = this->Optional || this->ImportLibrary;
+ this->AddInstallRule(os, type, filesFrom,
+ optional,
+ this->FilePermissions.c_str(), no_dir_permissions,
+ no_rename, literal_args.c_str(),
+ indent);
+
+ // Add post-installation tweaks.
+ this->AddTweak(os, indent, config, filesTo,
+ &cmInstallTargetGenerator::PostReplacementTweaks);
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmInstallTargetGenerator::GetInstallFilename(const std::string& config) const
+{
+ NameType nameType = this->ImportLibrary? NameImplib : NameNormal;
+ return
+ cmInstallTargetGenerator::GetInstallFilename(this->Target, config,
+ nameType);
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmInstallTargetGenerator::GetInstallFilename(cmTarget const* target,
+ const std::string& config,
+ NameType nameType)
+{
+ std::string fname;
+ // Compute the name of the library.
+ if(target->GetType() == cmTarget::EXECUTABLE)
+ {
+ std::string targetName;
+ std::string targetNameReal;
+ std::string targetNameImport;
+ std::string targetNamePDB;
+ target->GetExecutableNames(targetName, targetNameReal,
+ targetNameImport, targetNamePDB,
+ config);
+ if(nameType == NameImplib)
+ {
+ // Use the import library name.
+ if(!target->GetImplibGNUtoMS(targetNameImport, fname,
+ "${CMAKE_IMPORT_LIBRARY_SUFFIX}"))
+ {
+ fname = targetNameImport;
+ }
+ }
+ else if(nameType == NameReal)
+ {
+ // Use the canonical name.
+ fname = targetNameReal;
+ }
+ else
+ {
+ // Use the canonical name.
+ fname = targetName;
+ }
+ }
+ else
+ {
+ std::string targetName;
+ std::string targetNameSO;
+ std::string targetNameReal;
+ std::string targetNameImport;
+ std::string targetNamePDB;
+ target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
+ targetNameImport, targetNamePDB, config);
+ if(nameType == NameImplib)
+ {
+ // Use the import library name.
+ if(!target->GetImplibGNUtoMS(targetNameImport, fname,
+ "${CMAKE_IMPORT_LIBRARY_SUFFIX}"))
+ {
+ fname = targetNameImport;
+ }
+ }
+ else if(nameType == NameSO)
+ {
+ // Use the soname.
+ fname = targetNameSO;
+ }
+ else if(nameType == NameReal)
+ {
+ // Use the real name.
+ fname = targetNameReal;
+ }
+ else
+ {
+ // Use the canonical name.
+ fname = targetName;
+ }
+ }
+
+ return fname;
+}
+
+//----------------------------------------------------------------------------
+void
+cmInstallTargetGenerator
+::AddTweak(std::ostream& os, Indent const& indent, const std::string& config,
+ std::string const& file, TweakMethod tweak)
+{
+ cmOStringStream tw;
+ (this->*tweak)(tw, indent.Next(), config, file);
+ std::string tws = tw.str();
+ if(!tws.empty())
+ {
+ os << indent << "if(EXISTS \"" << file << "\" AND\n"
+ << indent << " NOT IS_SYMLINK \"" << file << "\")\n";
+ os << tws;
+ os << indent << "endif()\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmInstallTargetGenerator
+::AddTweak(std::ostream& os, Indent const& indent, const std::string& config,
+ std::vector<std::string> const& files, TweakMethod tweak)
+{
+ if(files.size() == 1)
+ {
+ // Tweak a single file.
+ this->AddTweak(os, indent, config, this->GetDestDirPath(files[0]), tweak);
+ }
+ else
+ {
+ // Generate a foreach loop to tweak multiple files.
+ cmOStringStream tw;
+ this->AddTweak(tw, indent.Next(), config, "${file}", tweak);
+ std::string tws = tw.str();
+ if(!tws.empty())
+ {
+ Indent indent2 = indent.Next().Next();
+ os << indent << "foreach(file\n";
+ for(std::vector<std::string>::const_iterator i = files.begin();
+ i != files.end(); ++i)
+ {
+ os << indent2 << "\"" << this->GetDestDirPath(*i) << "\"\n";
+ }
+ os << indent2 << ")\n";
+ os << tws;
+ os << indent << "endforeach()\n";
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmInstallTargetGenerator::GetDestDirPath(std::string const& file)
+{
+ // Construct the path of the file on disk after installation on
+ // which tweaks may be performed.
+ std::string toDestDirPath = "$ENV{DESTDIR}";
+ if(file[0] != '/' && file[0] != '$')
+ {
+ toDestDirPath += "/";
+ }
+ toDestDirPath += file;
+ return toDestDirPath;
+}
+
+//----------------------------------------------------------------------------
+void cmInstallTargetGenerator::PreReplacementTweaks(std::ostream& os,
+ Indent const& indent,
+ const std::string& config,
+ std::string const& file)
+{
+ this->AddRPathCheckRule(os, indent, config, file);
+}
+
+//----------------------------------------------------------------------------
+void cmInstallTargetGenerator::PostReplacementTweaks(std::ostream& os,
+ Indent const& indent,
+ const std::string& config,
+ std::string const& file)
+{
+ this->AddInstallNamePatchRule(os, indent, config, file);
+ this->AddChrpathPatchRule(os, indent, config, file);
+ this->AddRanlibRule(os, indent, file);
+ this->AddStripRule(os, indent, file);
+}
+
+//----------------------------------------------------------------------------
+void
+cmInstallTargetGenerator
+::AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
+ const std::string& config,
+ std::string const& toDestDirPath)
+{
+ if(this->ImportLibrary ||
+ !(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
+ this->Target->GetType() == cmTarget::MODULE_LIBRARY ||
+ this->Target->GetType() == cmTarget::EXECUTABLE))
+ {
+ return;
+ }
+
+ // Fix the install_name settings in installed binaries.
+ std::string installNameTool =
+ this->Target->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
+
+ if(!installNameTool.size())
+ {
+ return;
+ }
+
+ // Build a map of build-tree install_name to install-tree install_name for
+ // shared libraries linked to this target.
+ std::map<std::string, std::string> install_name_remap;
+ if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config))
+ {
+ std::set<cmTarget const*> const& sharedLibs
+ = cli->GetSharedLibrariesLinked();
+ for(std::set<cmTarget const*>::const_iterator j = sharedLibs.begin();
+ j != sharedLibs.end(); ++j)
+ {
+ cmTarget const* tgt = *j;
+
+ // The install_name of an imported target does not change.
+ if(tgt->IsImported())
+ {
+ continue;
+ }
+
+ // 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 = tgt->GetInstallNameDirForBuildTree(config);
+ std::string for_install = tgt->GetInstallNameDirForInstallTree();
+ if(for_build != for_install)
+ {
+ // The directory portions differ. Append the filename to
+ // create the mapping.
+ std::string fname =
+ this->GetInstallFilename(tgt, config, NameSO);
+
+ // Map from the build-tree install_name.
+ for_build += fname;
+
+ // Map to the install-tree install_name.
+ for_install += fname;
+
+ // Store the mapping entry.
+ install_name_remap[for_build] = for_install;
+ }
+ }
+ }
+
+ // Edit the install_name of the target itself if necessary.
+ std::string new_id;
+ if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
+ {
+ std::string for_build =
+ this->Target->GetInstallNameDirForBuildTree(config);
+ std::string for_install =
+ this->Target->GetInstallNameDirForInstallTree();
+
+ if(this->Target->IsFrameworkOnApple() && for_install.empty())
+ {
+ // Frameworks seem to have an id corresponding to their own full
+ // path.
+ // ...
+ // for_install = fullDestPath_without_DESTDIR_or_name;
+ }
+
+ // If the install name will change on installation set the new id
+ // on the installed file.
+ if(for_build != for_install)
+ {
+ // Prepare to refer to the install-tree install_name.
+ new_id = for_install;
+ new_id += this->GetInstallFilename(this->Target, config, NameSO);
+ }
+ }
+
+ // Write a rule to run install_name_tool to set the install-tree
+ // install_name value and references.
+ if(!new_id.empty() || !install_name_remap.empty())
+ {
+ os << indent << "execute_process(COMMAND \"" << installNameTool;
+ os << "\"";
+ if(!new_id.empty())
+ {
+ os << "\n" << indent << " -id \"" << new_id << "\"";
+ }
+ for(std::map<std::string, std::string>::const_iterator
+ i = install_name_remap.begin();
+ i != install_name_remap.end(); ++i)
+ {
+ os << "\n" << indent << " -change \""
+ << i->first << "\" \"" << i->second << "\"";
+ }
+ os << "\n" << indent << " \"" << toDestDirPath << "\")\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmInstallTargetGenerator
+::AddRPathCheckRule(std::ostream& os, Indent const& indent,
+ const std::string& config,
+ std::string const& toDestDirPath)
+{
+ // Skip the chrpath if the target does not need it.
+ if(this->ImportLibrary || !this->Target->IsChrpathUsed(config))
+ {
+ return;
+ }
+
+ // Skip if on Apple
+ if(this->Target->GetMakefile()->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ return;
+ }
+
+ // Get the link information for this target.
+ // It can provide the RPATH.
+ cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config);
+ if(!cli)
+ {
+ return;
+ }
+
+ // Get the install RPATH from the link information.
+ std::string newRpath = cli->GetChrpathString();
+
+ // Write a rule to remove the installed file if its rpath is not the
+ // new rpath. This is needed for existing build/install trees when
+ // the installed rpath changes but the file is not rebuilt.
+ os << indent << "file(RPATH_CHECK\n"
+ << indent << " FILE \"" << toDestDirPath << "\"\n"
+ << indent << " RPATH \"" << newRpath << "\")\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmInstallTargetGenerator
+::AddChrpathPatchRule(std::ostream& os, Indent const& indent,
+ const std::string& config,
+ std::string const& toDestDirPath)
+{
+ // Skip the chrpath if the target does not need it.
+ if(this->ImportLibrary || !this->Target->IsChrpathUsed(config))
+ {
+ return;
+ }
+
+ // Get the link information for this target.
+ // It can provide the RPATH.
+ cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config);
+ if(!cli)
+ {
+ return;
+ }
+
+ cmMakefile* mf = this->Target->GetMakefile();
+
+ if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ // If using install_name_tool, set up the rules to modify the rpaths.
+ std::string installNameTool =
+ mf->GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
+
+ std::vector<std::string> oldRuntimeDirs, newRuntimeDirs;
+ cli->GetRPath(oldRuntimeDirs, false);
+ cli->GetRPath(newRuntimeDirs, true);
+
+ std::string darwin_major_version_s =
+ mf->GetSafeDefinition("DARWIN_MAJOR_VERSION");
+
+ std::stringstream ss(darwin_major_version_s);
+ int darwin_major_version;
+ ss >> darwin_major_version;
+ if(!ss.fail() && darwin_major_version <= 9 &&
+ (!oldRuntimeDirs.empty() || !newRuntimeDirs.empty())
+ )
+ {
+ cmOStringStream msg;
+ msg << "WARNING: Target \"" << this->Target->GetName()
+ << "\" has runtime paths which cannot be changed during install. "
+ << "To change runtime paths, OS X version 10.6 or newer is required. "
+ << "Therefore, runtime paths will not be changed when installing. "
+ << "CMAKE_BUILD_WITH_INSTALL_RPATH may be used to work around"
+ " this limitation.";
+ mf->IssueMessage(cmake::WARNING, msg.str());
+ }
+ else
+ {
+ // Note: These paths are kept unique to avoid
+ // install_name_tool corruption.
+ std::set<std::string> runpaths;
+ for(std::vector<std::string>::const_iterator i = oldRuntimeDirs.begin();
+ i != oldRuntimeDirs.end(); ++i)
+ {
+ std::string runpath =
+ mf->GetLocalGenerator()->
+ GetGlobalGenerator()->ExpandCFGIntDir(*i, config);
+
+ if(runpaths.find(runpath) == runpaths.end())
+ {
+ runpaths.insert(runpath);
+ os << indent << "execute_process(COMMAND " << installNameTool <<"\n";
+ os << indent << " -delete_rpath \"" << runpath << "\"\n";
+ os << indent << " \"" << toDestDirPath << "\")\n";
+ }
+ }
+
+ runpaths.clear();
+ for(std::vector<std::string>::const_iterator i = newRuntimeDirs.begin();
+ i != newRuntimeDirs.end(); ++i)
+ {
+ std::string runpath =
+ mf->GetLocalGenerator()->
+ GetGlobalGenerator()->ExpandCFGIntDir(*i, config);
+
+ if(runpaths.find(runpath) == runpaths.end())
+ {
+ os << indent << "execute_process(COMMAND " << installNameTool <<"\n";
+ os << indent << " -add_rpath \"" << runpath << "\"\n";
+ os << indent << " \"" << toDestDirPath << "\")\n";
+ }
+ }
+ }
+ }
+ else
+ {
+ // Construct the original rpath string to be replaced.
+ std::string oldRpath = cli->GetRPathString(false);
+
+ // Get the install RPATH from the link information.
+ std::string newRpath = cli->GetChrpathString();
+
+ // Skip the rule if the paths are identical
+ if(oldRpath == newRpath)
+ {
+ return;
+ }
+
+ // 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";
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmInstallTargetGenerator::AddStripRule(std::ostream& os,
+ Indent const& indent,
+ const std::string& toDestDirPath)
+{
+
+ // 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)
+ {
+ return;
+ }
+
+ // Don't handle OSX Bundles.
+ if(this->Target->GetMakefile()->IsOn("APPLE") &&
+ this->Target->GetPropertyAsBool("MACOSX_BUNDLE"))
+ {
+ return;
+ }
+
+ if(! this->Target->GetMakefile()->IsSet("CMAKE_STRIP"))
+ {
+ return;
+ }
+
+ os << indent << "if(CMAKE_INSTALL_DO_STRIP)\n";
+ os << indent << " execute_process(COMMAND \""
+ << this->Target->GetMakefile()->GetDefinition("CMAKE_STRIP")
+ << "\" \"" << toDestDirPath << "\")\n";
+ os << indent << "endif()\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
+ Indent const& indent,
+ const std::string& toDestDirPath)
+{
+ // Static libraries need ranlib on this platform.
+ if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
+ {
+ return;
+ }
+
+ // Perform post-installation processing on the file depending
+ // on its type.
+ if(!this->Target->GetMakefile()->IsOn("APPLE"))
+ {
+ return;
+ }
+
+ std::string ranlib =
+ this->Target->GetMakefile()->GetRequiredDefinition("CMAKE_RANLIB");
+ if(ranlib.empty())
+ {
+ return;
+ }
+
+ os << indent << "execute_process(COMMAND \""
+ << ranlib << "\" \"" << toDestDirPath << "\")\n";
+}
diff --git a/Source/cmInstallTargetGenerator.h b/Source/cmInstallTargetGenerator.h
new file mode 100644
index 0000000000..7e5cc71a74
--- /dev/null
+++ b/Source/cmInstallTargetGenerator.h
@@ -0,0 +1,108 @@
+/*============================================================================
+ 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 cmInstallTargetGenerator_h
+#define cmInstallTargetGenerator_h
+
+#include "cmInstallGenerator.h"
+#include "cmTarget.h"
+#include "cmGeneratorTarget.h"
+
+/** \class cmInstallTargetGenerator
+ * \brief Generate target installation rules.
+ */
+class cmInstallTargetGenerator: public cmInstallGenerator
+{
+public:
+ cmInstallTargetGenerator(
+ cmTarget& t, const char* dest, bool implib,
+ const char* file_permissions,
+ std::vector<std::string> const& configurations,
+ const char* component,
+ MessageLevel message,
+ bool optional
+ );
+ virtual ~cmInstallTargetGenerator();
+
+ /** Select the policy for installing shared library linkable name
+ symlinks. */
+ enum NamelinkModeType
+ {
+ NamelinkModeNone,
+ NamelinkModeOnly,
+ NamelinkModeSkip
+ };
+ void SetNamelinkMode(NamelinkModeType mode) { this->NamelinkMode = mode; }
+ NamelinkModeType GetNamelinkMode() const { return this->NamelinkMode; }
+
+ std::string GetInstallFilename(const std::string& config) const;
+
+ enum NameType
+ {
+ NameNormal,
+ NameImplib,
+ NameSO,
+ NameReal
+ };
+
+ static std::string GetInstallFilename(cmTarget const* target,
+ const std::string& config,
+ NameType nameType = NameNormal);
+
+ cmTarget* GetTarget() const { return this->Target; }
+ bool IsImportLibrary() const { return this->ImportLibrary; }
+
+protected:
+ virtual void GenerateScript(std::ostream& os);
+ virtual void GenerateScriptForConfig(std::ostream& os,
+ const std::string& config,
+ Indent const& indent);
+ typedef void (cmInstallTargetGenerator::*TweakMethod)(
+ std::ostream&, Indent const&, const std::string&, std::string const&
+ );
+ void AddTweak(std::ostream& os, Indent const& indent,
+ const std::string& config, std::string const& file,
+ TweakMethod tweak);
+ void AddTweak(std::ostream& os, Indent const& indent,
+ const std::string& config,
+ std::vector<std::string> const& files,
+ TweakMethod tweak);
+ std::string GetDestDirPath(std::string const& file);
+ void PreReplacementTweaks(std::ostream& os, Indent const& indent,
+ const std::string& config,
+ std::string const& file);
+ void PostReplacementTweaks(std::ostream& os, Indent const& indent,
+ const std::string& config,
+ std::string const& file);
+ void AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
+ const std::string& config,
+ const std::string& toDestDirPath);
+ void AddChrpathPatchRule(std::ostream& os, Indent const& indent,
+ const std::string& config,
+ std::string const& toDestDirPath);
+ void AddRPathCheckRule(std::ostream& os, Indent const& indent,
+ const std::string& config,
+ std::string const& toDestDirPath);
+
+ void AddStripRule(std::ostream& os, Indent const& indent,
+ const std::string& toDestDirPath);
+ void AddRanlibRule(std::ostream& os, Indent const& indent,
+ const std::string& toDestDirPath);
+
+ cmTarget* Target;
+ bool ImportLibrary;
+ std::string FilePermissions;
+ bool Optional;
+ NamelinkModeType NamelinkMode;
+ cmGeneratorTarget* GeneratorTarget;
+};
+
+#endif
diff --git a/Source/cmInstallTargetsCommand.cxx b/Source/cmInstallTargetsCommand.cxx
new file mode 100644
index 0000000000..b738844a17
--- /dev/null
+++ b/Source/cmInstallTargetsCommand.cxx
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 "cmInstallTargetsCommand.h"
+
+// cmExecutableCommand
+bool cmInstallTargetsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // Enable the install target.
+ this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->EnableInstallTarget();
+
+ cmTargets &tgts = this->Makefile->GetTargets();
+ std::vector<std::string>::const_iterator s = args.begin();
+ ++s;
+ std::string runtime_dir = "/bin";
+ for (;s != args.end(); ++s)
+ {
+ if (*s == "RUNTIME_DIRECTORY")
+ {
+ ++s;
+ if ( s == args.end() )
+ {
+ this->SetError("called with RUNTIME_DIRECTORY but no actual "
+ "directory");
+ return false;
+ }
+
+ runtime_dir = *s;
+ }
+ else if (tgts.find(*s) != tgts.end())
+ {
+ tgts[*s].SetInstallPath(args[0].c_str());
+ tgts[*s].SetRuntimeInstallPath(runtime_dir.c_str());
+ tgts[*s].SetHaveInstallRule(true);
+ }
+ else
+ {
+ std::string str = "Cannot find target: \"" + *s + "\" to install.";
+ this->SetError(str);
+ return false;
+ }
+ }
+
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
+ ->AddInstallComponent(this->Makefile->GetSafeDefinition(
+ "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
+
+ return true;
+}
+
diff --git a/Source/cmInstallTargetsCommand.h b/Source/cmInstallTargetsCommand.h
new file mode 100644
index 0000000000..e6cbe6e35d
--- /dev/null
+++ b/Source/cmInstallTargetsCommand.h
@@ -0,0 +1,57 @@
+/*============================================================================
+ 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 cmInstallTargetsCommand_h
+#define cmInstallTargetsCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmInstallTargetsCommand
+ * \brief Specifies where to install some targets
+ *
+ * cmInstallTargetsCommand specifies the relative path where a list of
+ * targets should be installed. The targets can be executables or
+ * libraries.
+ */
+class cmInstallTargetsCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmInstallTargetsCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "install_targets";}
+
+ /** This command is kept for compatibility with older CMake versions. */
+ virtual bool IsDiscouraged() const
+ {
+ return true;
+ }
+
+ cmTypeMacro(cmInstallTargetsCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmInstallType.h b/Source/cmInstallType.h
new file mode 100644
index 0000000000..a8373682cd
--- /dev/null
+++ b/Source/cmInstallType.h
@@ -0,0 +1,29 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 cmInstallType_h
+#define cmInstallType_h
+
+/**
+ * Enumerate types known to file(INSTALL).
+ */
+enum cmInstallType
+{
+ cmInstallType_EXECUTABLE,
+ cmInstallType_STATIC_LIBRARY,
+ cmInstallType_SHARED_LIBRARY,
+ cmInstallType_MODULE_LIBRARY,
+ cmInstallType_FILES,
+ cmInstallType_PROGRAMS,
+ cmInstallType_DIRECTORY
+};
+
+#endif
diff --git a/Source/cmInstalledFile.cxx b/Source/cmInstalledFile.cxx
new file mode 100644
index 0000000000..4b53752b4f
--- /dev/null
+++ b/Source/cmInstalledFile.cxx
@@ -0,0 +1,131 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 "cmInstalledFile.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+
+//----------------------------------------------------------------------------
+cmInstalledFile::cmInstalledFile():
+ NameExpression(0)
+{
+
+}
+
+//----------------------------------------------------------------------------
+cmInstalledFile::~cmInstalledFile()
+{
+ if(NameExpression)
+ {
+ delete NameExpression;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name)
+{
+ cmListFileBacktrace backtrace = mf->GetBacktrace();
+ cmGeneratorExpression ge(&backtrace);
+
+ this->Name = name;
+ this->NameExpression = ge.Parse(name).release();
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmInstalledFile::GetName() const
+{
+ return this->Name;
+}
+
+//----------------------------------------------------------------------------
+cmCompiledGeneratorExpression const& cmInstalledFile::GetNameExpression() const
+{
+ return *(this->NameExpression);
+}
+
+//----------------------------------------------------------------------------
+void cmInstalledFile::RemoveProperty(const std::string& prop)
+{
+ this->Properties.erase(prop);
+}
+
+//----------------------------------------------------------------------------
+void cmInstalledFile::SetProperty(cmMakefile const* mf,
+ const std::string& prop, const char* value)
+{
+ this->RemoveProperty(prop);
+ this->AppendProperty(mf, prop, value);
+}
+
+//----------------------------------------------------------------------------
+void cmInstalledFile::AppendProperty(cmMakefile const* mf,
+ const std::string& prop, const char* value, bool /*asString*/)
+{
+ cmListFileBacktrace backtrace = mf->GetBacktrace();
+ cmGeneratorExpression ge(&backtrace);
+
+ Property& property = this->Properties[prop];
+ property.ValueExpressions.push_back(ge.Parse(value).release());
+}
+
+//----------------------------------------------------------------------------
+bool cmInstalledFile::HasProperty(
+ const std::string& prop) const
+{
+ return this->Properties.find(prop) != this->Properties.end();
+}
+
+//----------------------------------------------------------------------------
+bool cmInstalledFile::GetProperty(
+ const std::string& prop, std::string& value) const
+{
+ PropertyMapType::const_iterator i = this->Properties.find(prop);
+ if(i == this->Properties.end())
+ {
+ return false;
+ }
+
+ Property const& property = i->second;
+
+ std::string output;
+ std::string separator;
+
+ for(ExpressionVectorType::const_iterator
+ j = property.ValueExpressions.begin();
+ j != property.ValueExpressions.end(); ++j)
+ {
+ output += separator;
+ output += (*j)->GetInput();
+ separator = ";";
+ }
+
+ value = output;
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmInstalledFile::GetPropertyAsBool(const std::string& prop) const
+{
+ std::string value;
+ bool isSet = this->GetProperty(prop, value);
+ return isSet && cmSystemTools::IsOn(value.c_str());
+}
+
+//----------------------------------------------------------------------------
+void cmInstalledFile::GetPropertyAsList(const std::string& prop,
+ std::vector<std::string>& list) const
+{
+ std::string value;
+ this->GetProperty(prop, value);
+
+ list.clear();
+ cmSystemTools::ExpandListArgument(value, list);
+}
diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h
new file mode 100644
index 0000000000..7134a4e323
--- /dev/null
+++ b/Source/cmInstalledFile.h
@@ -0,0 +1,88 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmInstalledFile_h
+#define cmInstalledFile_h
+
+#include "cmGeneratorExpression.h"
+
+/** \class cmInstalledFile
+ * \brief Represents a file intended for installation.
+ *
+ * cmInstalledFile represents a file intended for installation.
+ */
+class cmInstalledFile
+{
+public:
+
+ typedef cmsys::auto_ptr<cmCompiledGeneratorExpression>
+ CompiledGeneratorExpressionPtrType;
+
+ typedef std::vector<cmCompiledGeneratorExpression*>
+ ExpressionVectorType;
+
+ struct Property
+ {
+ Property()
+ {
+
+ }
+
+ ~Property()
+ {
+ for(ExpressionVectorType::iterator i = ValueExpressions.begin();
+ i != ValueExpressions.end(); ++i)
+ {
+ delete *i;
+ }
+ }
+
+ ExpressionVectorType ValueExpressions;
+ };
+
+ typedef std::map<std::string, Property> PropertyMapType;
+
+ cmInstalledFile();
+
+ ~cmInstalledFile();
+
+ void RemoveProperty(const std::string& prop);
+
+ void SetProperty(cmMakefile const* mf,
+ const std::string& prop, const char *value);
+
+ void AppendProperty(cmMakefile const* mf,
+ const std::string& prop, const char* value,bool asString=false);
+
+ bool HasProperty(const std::string& prop) const;
+
+ bool GetProperty(const std::string& prop, std::string& value) const;
+
+ bool GetPropertyAsBool(const std::string& prop) const;
+
+ void GetPropertyAsList(const std::string& prop,
+ std::vector<std::string>& list) const;
+
+ void SetName(cmMakefile* mf, const std::string& name);
+
+ std::string const& GetName() const;
+
+ cmCompiledGeneratorExpression const& GetNameExpression() const;
+
+ PropertyMapType const& GetProperties() const { return this->Properties; }
+
+private:
+ std::string Name;
+ cmCompiledGeneratorExpression* NameExpression;
+ PropertyMapType Properties;
+};
+
+#endif
diff --git a/Source/cmLinkDirectoriesCommand.cxx b/Source/cmLinkDirectoriesCommand.cxx
new file mode 100644
index 0000000000..3644d93f23
--- /dev/null
+++ b/Source/cmLinkDirectoriesCommand.cxx
@@ -0,0 +1,70 @@
+/*============================================================================
+ 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 "cmLinkDirectoriesCommand.h"
+
+// cmLinkDirectoriesCommand
+bool cmLinkDirectoriesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ return true;
+ }
+
+ for(std::vector<std::string>::const_iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ this->AddLinkDir(*i);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir)
+{
+ std::string unixPath = dir;
+ cmSystemTools::ConvertToUnixSlashes(unixPath);
+ if(!cmSystemTools::FileIsFullPath(unixPath.c_str()))
+ {
+ bool convertToAbsolute = false;
+ cmOStringStream e;
+ e << "This command specifies the relative path\n"
+ << " " << unixPath << "\n"
+ << "as a link directory.\n";
+ cmPolicies* policies = this->Makefile->GetPolicies();
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0015))
+ {
+ case cmPolicies::WARN:
+ e << policies->GetPolicyWarning(cmPolicies::CMP0015);
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ case cmPolicies::OLD:
+ // OLD behavior does not convert
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ e << policies->GetRequiredPolicyError(cmPolicies::CMP0015);
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ case cmPolicies::NEW:
+ // NEW behavior converts
+ convertToAbsolute = true;
+ break;
+ }
+ if (convertToAbsolute)
+ {
+ std::string tmp = this->Makefile->GetStartDirectory();
+ tmp += "/";
+ tmp += unixPath;
+ unixPath = tmp;
+ }
+ }
+ this->Makefile->AddLinkDirectory(unixPath);
+}
diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h
new file mode 100644
index 0000000000..8e04bafcda
--- /dev/null
+++ b/Source/cmLinkDirectoriesCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmLinkDirectoriesCommand_h
+#define cmLinkDirectoriesCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmLinkDirectoriesCommand
+ * \brief Define a list of directories containing files to link.
+ *
+ * cmLinkDirectoriesCommand is used to specify a list
+ * of directories containing files to link into executable(s).
+ * Note that the command supports the use of CMake built-in variables
+ * such as CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR.
+ */
+class cmLinkDirectoriesCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmLinkDirectoriesCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "link_directories";}
+
+ cmTypeMacro(cmLinkDirectoriesCommand, cmCommand);
+private:
+ void AddLinkDir(std::string const& dir);
+};
+
+
+
+#endif
diff --git a/Source/cmLinkLibrariesCommand.cxx b/Source/cmLinkLibrariesCommand.cxx
new file mode 100644
index 0000000000..996b5382fb
--- /dev/null
+++ b/Source/cmLinkLibrariesCommand.cxx
@@ -0,0 +1,59 @@
+/*============================================================================
+ 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 "cmLinkLibrariesCommand.h"
+
+// cmLinkLibrariesCommand
+bool cmLinkLibrariesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ return true;
+ }
+ // add libraries, nothe that there is an optional prefix
+ // of debug and optimized than can be used
+ for(std::vector<std::string>::const_iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ if (*i == "debug")
+ {
+ ++i;
+ if(i == args.end())
+ {
+ this->SetError("The \"debug\" argument must be followed by "
+ "a library");
+ return false;
+ }
+ this->Makefile->AddLinkLibrary(*i,
+ cmTarget::DEBUG);
+ }
+ else if (*i == "optimized")
+ {
+ ++i;
+ if(i == args.end())
+ {
+ this->SetError("The \"optimized\" argument must be followed by "
+ "a library");
+ return false;
+ }
+ this->Makefile->AddLinkLibrary(*i,
+ cmTarget::OPTIMIZED);
+ }
+ else
+ {
+ this->Makefile->AddLinkLibrary(*i);
+ }
+ }
+
+ return true;
+}
+
diff --git a/Source/cmLinkLibrariesCommand.h b/Source/cmLinkLibrariesCommand.h
new file mode 100644
index 0000000000..c572439e52
--- /dev/null
+++ b/Source/cmLinkLibrariesCommand.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 cmLinkLibrariesCommand_h
+#define cmLinkLibrariesCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmLinkLibrariesCommand
+ * \brief Specify a list of libraries to link into executables.
+ *
+ * cmLinkLibrariesCommand is used to specify a list of libraries to link
+ * into executable(s) or shared objects. The names of the libraries
+ * should be those defined by the LIBRARY(library) command(s).
+ */
+class cmLinkLibrariesCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmLinkLibrariesCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "link_libraries";}
+
+ /** This command is kept for compatibility with older CMake versions. */
+ virtual bool IsDiscouraged() const
+ {
+ return true;
+ }
+
+ cmTypeMacro(cmLinkLibrariesCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
new file mode 100644
index 0000000000..f1ea088203
--- /dev/null
+++ b/Source/cmListCommand.cxx
@@ -0,0 +1,608 @@
+/*============================================================================
+ 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 "cmListCommand.h"
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/SystemTools.hxx>
+
+#include <stdlib.h> // required for atoi
+#include <ctype.h>
+#include <assert.h>
+//----------------------------------------------------------------------------
+bool cmListCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2)
+ {
+ this->SetError("must be called with at least two arguments.");
+ return false;
+ }
+
+ const std::string &subCommand = args[0];
+ if(subCommand == "LENGTH")
+ {
+ return this->HandleLengthCommand(args);
+ }
+ if(subCommand == "GET")
+ {
+ return this->HandleGetCommand(args);
+ }
+ if(subCommand == "APPEND")
+ {
+ return this->HandleAppendCommand(args);
+ }
+ if(subCommand == "FIND")
+ {
+ return this->HandleFindCommand(args);
+ }
+ if(subCommand == "INSERT")
+ {
+ return this->HandleInsertCommand(args);
+ }
+ if(subCommand == "REMOVE_AT")
+ {
+ return this->HandleRemoveAtCommand(args);
+ }
+ if(subCommand == "REMOVE_ITEM")
+ {
+ return this->HandleRemoveItemCommand(args);
+ }
+ if(subCommand == "REMOVE_DUPLICATES")
+ {
+ return this->HandleRemoveDuplicatesCommand(args);
+ }
+ if(subCommand == "SORT")
+ {
+ return this->HandleSortCommand(args);
+ }
+ if(subCommand == "REVERSE")
+ {
+ return this->HandleReverseCommand(args);
+ }
+
+ std::string e = "does not recognize sub-command "+subCommand;
+ this->SetError(e);
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand::GetListString(std::string& listString,
+ const std::string& var)
+{
+ // get the old value
+ const char* cacheValue
+ = this->Makefile->GetDefinition(var);
+ if(!cacheValue)
+ {
+ return false;
+ }
+ listString = cacheValue;
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand::GetList(std::vector<std::string>& list,
+ const std::string& var)
+{
+ std::string listString;
+ if ( !this->GetListString(listString, var) )
+ {
+ return false;
+ }
+ // if the size of the list
+ if(listString.size() == 0)
+ {
+ return true;
+ }
+ // expand the variable into a list
+ cmSystemTools::ExpandListArgument(listString, list, true);
+ // check the list for empty values
+ bool hasEmpty = false;
+ for(std::vector<std::string>::iterator i = list.begin();
+ i != list.end(); ++i)
+ {
+ if(i->size() == 0)
+ {
+ hasEmpty = true;
+ break;
+ }
+ }
+ // if no empty elements then just return
+ if(!hasEmpty)
+ {
+ return true;
+ }
+ // if we have empty elements we need to check policy CMP0007
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0007))
+ {
+ case cmPolicies::WARN:
+ {
+ // Default is to warn and use old behavior
+ // OLD behavior is to allow compatibility, so recall
+ // ExpandListArgument without the true which will remove
+ // empty values
+ list.clear();
+ cmSystemTools::ExpandListArgument(listString, list);
+ std::string warn = this->Makefile->GetPolicies()->
+ GetPolicyWarning(cmPolicies::CMP0007);
+ warn += " List has value = [";
+ warn += listString;
+ warn += "].";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ warn);
+ return true;
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to allow compatibility, so recall
+ // ExpandListArgument without the true which will remove
+ // empty values
+ list.clear();
+ cmSystemTools::ExpandListArgument(listString, list);
+ return true;
+ case cmPolicies::NEW:
+ return true;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ this->Makefile->GetPolicies()
+ ->GetRequiredPolicyError(cmPolicies::CMP0007)
+ );
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand::HandleLengthCommand(std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+ {
+ this->SetError("sub-command LENGTH requires two arguments.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ const std::string& variableName = args[args.size() - 1];
+ std::vector<std::string> varArgsExpanded;
+ // do not check the return value here
+ // if the list var is not found varArgsExpanded will have size 0
+ // and we will return 0
+ this->GetList(varArgsExpanded, listName);
+ size_t length = varArgsExpanded.size();
+ char buffer[1024];
+ sprintf(buffer, "%d", static_cast<int>(length));
+
+ this->Makefile->AddDefinition(variableName, buffer);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args)
+{
+ if(args.size() < 4)
+ {
+ this->SetError("sub-command GET requires at least three arguments.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ const std::string& variableName = args[args.size() - 1];
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if ( !this->GetList(varArgsExpanded, listName) )
+ {
+ this->Makefile->AddDefinition(variableName, "NOTFOUND");
+ return true;
+ }
+ // FIXME: Add policy to make non-existing lists an error like empty lists.
+ if(varArgsExpanded.empty())
+ {
+ this->SetError("GET given empty list");
+ return false;
+ }
+
+ std::string value;
+ size_t cc;
+ const char* sep = "";
+ for ( cc = 2; cc < args.size()-1; cc ++ )
+ {
+ int item = atoi(args[cc].c_str());
+ value += sep;
+ sep = ";";
+ size_t nitem = varArgsExpanded.size();
+ if ( item < 0 )
+ {
+ item = (int)nitem + item;
+ }
+ if ( item < 0 || nitem <= (size_t)item )
+ {
+ cmOStringStream str;
+ str << "index: " << item << " out of range (-"
+ << varArgsExpanded.size() << ", "
+ << varArgsExpanded.size()-1 << ")";
+ this->SetError(str.str());
+ return false;
+ }
+ value += varArgsExpanded[item];
+ }
+
+ this->Makefile->AddDefinition(variableName, value.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args)
+{
+ assert(args.size() >= 2);
+
+ // Skip if nothing to append.
+ if(args.size() < 3)
+ {
+ return true;
+ }
+
+ const std::string& listName = args[1];
+ // expand the variable
+ std::string listString;
+ this->GetListString(listString, listName);
+ size_t cc;
+ for ( cc = 2; cc < args.size(); ++ cc )
+ {
+ if(listString.size())
+ {
+ listString += ";";
+ }
+ listString += args[cc];
+ }
+
+ this->Makefile->AddDefinition(listName, listString.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args)
+{
+ if(args.size() != 4)
+ {
+ this->SetError("sub-command FIND requires three arguments.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ const std::string& variableName = args[args.size() - 1];
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if ( !this->GetList(varArgsExpanded, listName) )
+ {
+ this->Makefile->AddDefinition(variableName, "-1");
+ return true;
+ }
+
+ std::vector<std::string>::iterator it;
+ unsigned int index = 0;
+ for ( it = varArgsExpanded.begin(); it != varArgsExpanded.end(); ++ it )
+ {
+ if ( *it == args[2] )
+ {
+ char indexString[32];
+ sprintf(indexString, "%d", index);
+ this->Makefile->AddDefinition(variableName, indexString);
+ return true;
+ }
+ index++;
+ }
+
+ this->Makefile->AddDefinition(variableName, "-1");
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
+{
+ if(args.size() < 4)
+ {
+ this->SetError("sub-command INSERT requires at least three arguments.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+
+ // expand the variable
+ int item = atoi(args[2].c_str());
+ std::vector<std::string> varArgsExpanded;
+ if((!this->GetList(varArgsExpanded, listName)
+ || varArgsExpanded.empty()) && item != 0)
+ {
+ cmOStringStream str;
+ str << "index: " << item << " out of range (0, 0)";
+ this->SetError(str.str());
+ return false;
+ }
+
+ if ( varArgsExpanded.size() != 0 )
+ {
+ size_t nitem = varArgsExpanded.size();
+ if ( item < 0 )
+ {
+ item = (int)nitem + item;
+ }
+ if ( item < 0 || nitem <= (size_t)item )
+ {
+ cmOStringStream str;
+ str << "index: " << item << " out of range (-"
+ << varArgsExpanded.size() << ", "
+ << (varArgsExpanded.size() == 0?0:(varArgsExpanded.size()-1)) << ")";
+ this->SetError(str.str());
+ return false;
+ }
+ }
+ size_t cc;
+ size_t cnt = 0;
+ for ( cc = 3; cc < args.size(); ++ cc )
+ {
+ varArgsExpanded.insert(varArgsExpanded.begin()+item+cnt, args[cc]);
+ cnt ++;
+ }
+
+ std::string value;
+ const char* sep = "";
+ for ( cc = 0; cc < varArgsExpanded.size(); cc ++ )
+ {
+ value += sep;
+ value += varArgsExpanded[cc];
+ sep = ";";
+ }
+
+ this->Makefile->AddDefinition(listName, value.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand
+::HandleRemoveItemCommand(std::vector<std::string> const& args)
+{
+ if(args.size() < 3)
+ {
+ this->SetError("sub-command REMOVE_ITEM requires two or more arguments.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if ( !this->GetList(varArgsExpanded, listName) )
+ {
+ this->SetError("sub-command REMOVE_ITEM requires list to be present.");
+ return false;
+ }
+
+ size_t cc;
+ for ( cc = 2; cc < args.size(); ++ cc )
+ {
+ size_t kk = 0;
+ while ( kk < varArgsExpanded.size() )
+ {
+ if ( varArgsExpanded[kk] == args[cc] )
+ {
+ varArgsExpanded.erase(varArgsExpanded.begin()+kk);
+ }
+ else
+ {
+ kk ++;
+ }
+ }
+ }
+
+ std::string value;
+ const char* sep = "";
+ for ( cc = 0; cc < varArgsExpanded.size(); cc ++ )
+ {
+ value += sep;
+ value += varArgsExpanded[cc];
+ sep = ";";
+ }
+
+ this->Makefile->AddDefinition(listName, value.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand
+::HandleReverseCommand(std::vector<std::string> const& args)
+{
+ assert(args.size() >= 2);
+ if(args.size() > 2)
+ {
+ this->SetError(
+ "sub-command REVERSE only takes one argument.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if ( !this->GetList(varArgsExpanded, listName) )
+ {
+ this->SetError("sub-command REVERSE requires list to be present.");
+ return false;
+ }
+
+ std::string value;
+ std::vector<std::string>::reverse_iterator it;
+ const char* sep = "";
+ for ( it = varArgsExpanded.rbegin(); it != varArgsExpanded.rend(); ++ it )
+ {
+ value += sep;
+ value += it->c_str();
+ sep = ";";
+ }
+
+ this->Makefile->AddDefinition(listName, value.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand
+::HandleRemoveDuplicatesCommand(std::vector<std::string> const& args)
+{
+ assert(args.size() >= 2);
+ if(args.size() > 2)
+ {
+ this->SetError(
+ "sub-command REMOVE_DUPLICATES only takes one argument.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if ( !this->GetList(varArgsExpanded, listName) )
+ {
+ this->SetError(
+ "sub-command REMOVE_DUPLICATES requires list to be present.");
+ return false;
+ }
+
+ std::string value;
+
+
+ std::set<std::string> unique;
+ std::vector<std::string>::iterator it;
+ const char* sep = "";
+ for ( it = varArgsExpanded.begin(); it != varArgsExpanded.end(); ++ it )
+ {
+ if (unique.find(*it) != unique.end())
+ {
+ continue;
+ }
+ unique.insert(*it);
+ value += sep;
+ value += it->c_str();
+ sep = ";";
+ }
+
+
+ this->Makefile->AddDefinition(listName, value.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand
+::HandleSortCommand(std::vector<std::string> const& args)
+{
+ assert(args.size() >= 2);
+ if(args.size() > 2)
+ {
+ this->SetError(
+ "sub-command SORT only takes one argument.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if ( !this->GetList(varArgsExpanded, listName) )
+ {
+ this->SetError("sub-command SORT requires list to be present.");
+ return false;
+ }
+
+ std::sort(varArgsExpanded.begin(), varArgsExpanded.end());
+
+ std::string value;
+ std::vector<std::string>::iterator it;
+ const char* sep = "";
+ for ( it = varArgsExpanded.begin(); it != varArgsExpanded.end(); ++ it )
+ {
+ value += sep;
+ value += it->c_str();
+ sep = ";";
+ }
+
+ this->Makefile->AddDefinition(listName, value.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListCommand::HandleRemoveAtCommand(
+ std::vector<std::string> const& args)
+{
+ if(args.size() < 3)
+ {
+ this->SetError("sub-command REMOVE_AT requires at least "
+ "two arguments.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if ( !this->GetList(varArgsExpanded, listName) )
+ {
+ this->SetError("sub-command REMOVE_AT requires list to be present.");
+ return false;
+ }
+ // FIXME: Add policy to make non-existing lists an error like empty lists.
+ if(varArgsExpanded.empty())
+ {
+ this->SetError("REMOVE_AT given empty list");
+ return false;
+ }
+
+ size_t cc;
+ std::vector<size_t> removed;
+ for ( cc = 2; cc < args.size(); ++ cc )
+ {
+ int item = atoi(args[cc].c_str());
+ size_t nitem = varArgsExpanded.size();
+ if ( item < 0 )
+ {
+ item = (int)nitem + item;
+ }
+ if ( item < 0 || nitem <= (size_t)item )
+ {
+ cmOStringStream str;
+ str << "index: " << item << " out of range (-"
+ << varArgsExpanded.size() << ", "
+ << varArgsExpanded.size()-1 << ")";
+ this->SetError(str.str());
+ return false;
+ }
+ removed.push_back(static_cast<size_t>(item));
+ }
+
+ std::string value;
+ const char* sep = "";
+ for ( cc = 0; cc < varArgsExpanded.size(); ++ cc )
+ {
+ size_t kk;
+ bool found = false;
+ for ( kk = 0; kk < removed.size(); ++ kk )
+ {
+ if ( cc == removed[kk] )
+ {
+ found = true;
+ }
+ }
+
+ if ( !found )
+ {
+ value += sep;
+ value += varArgsExpanded[cc];
+ sep = ";";
+ }
+ }
+
+ this->Makefile->AddDefinition(listName, value.c_str());
+ return true;
+}
+
diff --git a/Source/cmListCommand.h b/Source/cmListCommand.h
new file mode 100644
index 0000000000..5ea1d9f182
--- /dev/null
+++ b/Source/cmListCommand.h
@@ -0,0 +1,68 @@
+/*============================================================================
+ 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 cmListCommand_h
+#define cmListCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmListCommand
+ * \brief Common list operations
+ *
+ */
+class cmListCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmListCommand;
+ }
+
+ /**
+ * 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 "list";}
+
+ cmTypeMacro(cmListCommand, cmCommand);
+protected:
+ bool HandleLengthCommand(std::vector<std::string> const& args);
+ bool HandleGetCommand(std::vector<std::string> const& args);
+ bool HandleAppendCommand(std::vector<std::string> const& args);
+ bool HandleFindCommand(std::vector<std::string> const& args);
+ bool HandleInsertCommand(std::vector<std::string> const& args);
+ bool HandleRemoveAtCommand(std::vector<std::string> const& args);
+ bool HandleRemoveItemCommand(std::vector<std::string> const& args);
+ bool HandleRemoveDuplicatesCommand(std::vector<std::string> const& args);
+ bool HandleSortCommand(std::vector<std::string> const& args);
+ bool HandleReverseCommand(std::vector<std::string> const& args);
+
+
+ bool GetList(std::vector<std::string>& list, const std::string& var);
+ bool GetListString(std::string& listString, const std::string& var);
+};
+
+
+#endif
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
new file mode 100644
index 0000000000..3fc5b69c46
--- /dev/null
+++ b/Source/cmListFileCache.cxx
@@ -0,0 +1,442 @@
+/*============================================================================
+ 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 "cmListFileCache.h"
+
+#include "cmListFileLexer.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmVersion.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+#ifdef __BORLANDC__
+# pragma warn -8060 /* possibly incorrect assignment */
+#endif
+
+//----------------------------------------------------------------------------
+struct cmListFileParser
+{
+ cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename);
+ ~cmListFileParser();
+ bool ParseFile();
+ bool ParseFunction(const char* name, long line);
+ bool AddArgument(cmListFileLexer_Token* token,
+ cmListFileArgument::Delimiter delim);
+ cmListFile* ListFile;
+ cmMakefile* Makefile;
+ const char* FileName;
+ cmListFileLexer* Lexer;
+ cmListFileFunction Function;
+ enum { SeparationOkay, SeparationWarning, SeparationError} Separation;
+};
+
+//----------------------------------------------------------------------------
+cmListFileParser::cmListFileParser(cmListFile* lf, cmMakefile* mf,
+ const char* filename):
+ ListFile(lf), Makefile(mf), FileName(filename),
+ Lexer(cmListFileLexer_New())
+{
+}
+
+//----------------------------------------------------------------------------
+cmListFileParser::~cmListFileParser()
+{
+ cmListFileLexer_Delete(this->Lexer);
+}
+
+//----------------------------------------------------------------------------
+bool cmListFileParser::ParseFile()
+{
+ // Open the file.
+ cmListFileLexer_BOM bom;
+ if(!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom))
+ {
+ cmSystemTools::Error("cmListFileCache: error can not open file ",
+ this->FileName);
+ return false;
+ }
+
+ // Verify the Byte-Order-Mark, if any.
+ if(bom != cmListFileLexer_BOM_None &&
+ bom != cmListFileLexer_BOM_UTF8)
+ {
+ cmListFileLexer_SetFileName(this->Lexer, 0, 0);
+ cmOStringStream m;
+ m << "File\n " << this->FileName << "\n"
+ << "starts with a Byte-Order-Mark that is not UTF-8.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str());
+ return false;
+ }
+
+ // Use a simple recursive-descent parser to process the token
+ // stream.
+ bool haveNewline = true;
+ while(cmListFileLexer_Token* token =
+ cmListFileLexer_Scan(this->Lexer))
+ {
+ if(token->type == cmListFileLexer_Token_Space)
+ {
+ }
+ else if(token->type == cmListFileLexer_Token_Newline)
+ {
+ haveNewline = true;
+ }
+ else if(token->type == cmListFileLexer_Token_CommentBracket)
+ {
+ haveNewline = false;
+ }
+ else if(token->type == cmListFileLexer_Token_Identifier)
+ {
+ if(haveNewline)
+ {
+ haveNewline = false;
+ if(this->ParseFunction(token->text, token->line))
+ {
+ this->ListFile->Functions.push_back(this->Function);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ cmOStringStream error;
+ error << "Error in cmake code at\n"
+ << this->FileName << ":" << token->line << ":\n"
+ << "Parse error. Expected a newline, got "
+ << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
+ << " with text \"" << token->text << "\".";
+ cmSystemTools::Error(error.str().c_str());
+ return false;
+ }
+ }
+ else
+ {
+ cmOStringStream error;
+ error << "Error in cmake code at\n"
+ << this->FileName << ":" << token->line << ":\n"
+ << "Parse error. Expected a command name, got "
+ << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
+ << " with text \""
+ << token->text << "\".";
+ cmSystemTools::Error(error.str().c_str());
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListFile::ParseFile(const char* filename,
+ bool topLevel,
+ cmMakefile *mf)
+{
+ if(!cmSystemTools::FileExists(filename) ||
+ cmSystemTools::FileIsDirectory(filename))
+ {
+ return false;
+ }
+
+ bool parseError = false;
+ this->ModifiedTime = cmSystemTools::ModifiedTime(filename);
+
+ {
+ cmListFileParser parser(this, mf, filename);
+ parseError = !parser.ParseFile();
+ }
+
+ if(parseError)
+ {
+ this->ModifiedTime = 0;
+ }
+
+ // do we need a cmake_policy(VERSION call?
+ if(topLevel)
+ {
+ bool hasVersion = false;
+ // search for the right policy command
+ for(std::vector<cmListFileFunction>::iterator i
+ = this->Functions.begin();
+ i != this->Functions.end(); ++i)
+ {
+ if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required")
+ {
+ hasVersion = true;
+ break;
+ }
+ }
+ // if no policy command is found this is an error if they use any
+ // non advanced functions or a lot of functions
+ if(!hasVersion)
+ {
+ bool isProblem = true;
+ if (this->Functions.size() < 30)
+ {
+ // the list of simple commands DO NOT ADD TO THIS LIST!!!!!
+ // these commands must have backwards compatibility forever and
+ // and that is a lot longer than your tiny mind can comprehend mortal
+ std::set<std::string> allowedCommands;
+ allowedCommands.insert("project");
+ allowedCommands.insert("set");
+ allowedCommands.insert("if");
+ allowedCommands.insert("endif");
+ allowedCommands.insert("else");
+ allowedCommands.insert("elseif");
+ allowedCommands.insert("add_executable");
+ allowedCommands.insert("add_library");
+ allowedCommands.insert("target_link_libraries");
+ allowedCommands.insert("option");
+ allowedCommands.insert("message");
+ isProblem = false;
+ for(std::vector<cmListFileFunction>::iterator i
+ = this->Functions.begin();
+ i != this->Functions.end(); ++i)
+ {
+ std::string name = cmSystemTools::LowerCase(i->Name);
+ if (allowedCommands.find(name) == allowedCommands.end())
+ {
+ isProblem = true;
+ break;
+ }
+ }
+ }
+
+ if (isProblem)
+ {
+ // Tell the top level cmMakefile to diagnose
+ // this violation of CMP0000.
+ mf->SetCheckCMP0000(true);
+
+ // Implicitly set the version for the user.
+ mf->SetPolicyVersion("2.4");
+ }
+ }
+ }
+
+ if(topLevel)
+ {
+ bool hasProject = false;
+ // search for a project command
+ for(std::vector<cmListFileFunction>::iterator i
+ = this->Functions.begin();
+ i != this->Functions.end(); ++i)
+ {
+ if(cmSystemTools::LowerCase(i->Name) == "project")
+ {
+ hasProject = true;
+ break;
+ }
+ }
+ // if no project command is found, add one
+ if(!hasProject)
+ {
+ cmListFileFunction project;
+ project.Name = "PROJECT";
+ cmListFileArgument prj("Project", cmListFileArgument::Unquoted,
+ filename, 0);
+ project.Arguments.push_back(prj);
+ this->Functions.insert(this->Functions.begin(),project);
+ }
+ }
+ if(parseError)
+ {
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmListFileParser::ParseFunction(const char* name, long line)
+{
+ // Inintialize a new function call.
+ this->Function = cmListFileFunction();
+ this->Function.FilePath = this->FileName;
+ this->Function.Name = name;
+ this->Function.Line = line;
+
+ // Command name has already been parsed. Read the left paren.
+ cmListFileLexer_Token* token;
+ while((token = cmListFileLexer_Scan(this->Lexer)) &&
+ token->type == cmListFileLexer_Token_Space) {}
+ if(!token)
+ {
+ cmOStringStream error;
+ error << "Error in cmake code at\n" << this->FileName << ":"
+ << cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n"
+ << "Parse error. Function missing opening \"(\".";
+ cmSystemTools::Error(error.str().c_str());
+ return false;
+ }
+ if(token->type != cmListFileLexer_Token_ParenLeft)
+ {
+ cmOStringStream error;
+ error << "Error in cmake code at\n" << this->FileName << ":"
+ << cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n"
+ << "Parse error. Expected \"(\", got "
+ << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
+ << " with text \"" << token->text << "\".";
+ cmSystemTools::Error(error.str().c_str());
+ return false;
+ }
+
+ // Arguments.
+ unsigned long lastLine;
+ unsigned long parenDepth = 0;
+ this->Separation = SeparationOkay;
+ while((lastLine = cmListFileLexer_GetCurrentLine(this->Lexer),
+ token = cmListFileLexer_Scan(this->Lexer)))
+ {
+ if(token->type == cmListFileLexer_Token_Space ||
+ token->type == cmListFileLexer_Token_Newline)
+ {
+ this->Separation = SeparationOkay;
+ continue;
+ }
+ if(token->type == cmListFileLexer_Token_ParenLeft)
+ {
+ parenDepth++;
+ this->Separation = SeparationOkay;
+ if(!this->AddArgument(token, cmListFileArgument::Unquoted))
+ {
+ return false;
+ }
+ }
+ else if(token->type == cmListFileLexer_Token_ParenRight)
+ {
+ if (parenDepth == 0)
+ {
+ return true;
+ }
+ parenDepth--;
+ this->Separation = SeparationOkay;
+ if(!this->AddArgument(token, cmListFileArgument::Unquoted))
+ {
+ return false;
+ }
+ this->Separation = SeparationWarning;
+ }
+ else if(token->type == cmListFileLexer_Token_Identifier ||
+ token->type == cmListFileLexer_Token_ArgumentUnquoted)
+ {
+ if(!this->AddArgument(token, cmListFileArgument::Unquoted))
+ {
+ return false;
+ }
+ this->Separation = SeparationWarning;
+ }
+ else if(token->type == cmListFileLexer_Token_ArgumentQuoted)
+ {
+ if(!this->AddArgument(token, cmListFileArgument::Quoted))
+ {
+ return false;
+ }
+ this->Separation = SeparationWarning;
+ }
+ else if(token->type == cmListFileLexer_Token_ArgumentBracket)
+ {
+ if(!this->AddArgument(token, cmListFileArgument::Bracket))
+ {
+ return false;
+ }
+ this->Separation = SeparationError;
+ }
+ else if(token->type == cmListFileLexer_Token_CommentBracket)
+ {
+ this->Separation = SeparationError;
+ }
+ else
+ {
+ // Error.
+ cmOStringStream error;
+ error << "Error in cmake code at\n" << this->FileName << ":"
+ << cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n"
+ << "Parse error. Function missing ending \")\". "
+ << "Instead found "
+ << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
+ << " with text \"" << token->text << "\".";
+ cmSystemTools::Error(error.str().c_str());
+ return false;
+ }
+ }
+
+ cmOStringStream error;
+ error << "Error in cmake code at\n"
+ << this->FileName << ":" << lastLine << ":\n"
+ << "Parse error. Function missing ending \")\". "
+ << "End of file reached.";
+ cmSystemTools::Error(error.str().c_str());
+
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
+ cmListFileArgument::Delimiter delim)
+{
+ cmListFileArgument a(token->text, delim, this->FileName, token->line);
+ this->Function.Arguments.push_back(a);
+ if(this->Separation == SeparationOkay)
+ {
+ return true;
+ }
+ bool isError = (this->Separation == SeparationError ||
+ delim == cmListFileArgument::Bracket);
+ cmOStringStream m;
+ m << "Syntax " << (isError? "Error":"Warning") << " in cmake code at\n"
+ << " " << this->FileName << ":" << token->line << ":"
+ << token->column << "\n"
+ << "Argument not separated from preceding token by whitespace.";
+ if(isError)
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str());
+ return false;
+ }
+ else
+ {
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str());
+ return true;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmListFileBacktrace::MakeRelative()
+{
+ if (this->Relative)
+ {
+ return;
+ }
+ for (cmListFileBacktrace::iterator i = this->begin();
+ i != this->end(); ++i)
+ {
+ i->FilePath = this->LocalGenerator->Convert(i->FilePath,
+ cmLocalGenerator::HOME);
+ }
+ this->Relative = true;
+}
+
+
+//----------------------------------------------------------------------------
+std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
+{
+ os << lfc.FilePath;
+ if(lfc.Line)
+ {
+ os << ":" << lfc.Line;
+ if(!lfc.Name.empty())
+ {
+ os << " (" << lfc.Name << ")";
+ }
+ }
+ return os;
+}
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h
new file mode 100644
index 0000000000..2ca9b8ea0a
--- /dev/null
+++ b/Source/cmListFileCache.h
@@ -0,0 +1,109 @@
+/*============================================================================
+ 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 cmListFileCache_h
+#define cmListFileCache_h
+
+#include "cmStandardIncludes.h"
+
+class cmLocalGenerator;
+
+/** \class cmListFileCache
+ * \brief A class to cache list file contents.
+ *
+ * cmListFileCache is a class used to cache the contents of parsed
+ * cmake list files.
+ */
+
+class cmMakefile;
+
+struct cmListFileArgument
+{
+ enum Delimiter
+ {
+ Unquoted,
+ Quoted,
+ Bracket
+ };
+ cmListFileArgument(): Value(), Delim(Unquoted), FilePath(0), Line(0) {}
+ cmListFileArgument(const cmListFileArgument& r):
+ Value(r.Value), Delim(r.Delim), FilePath(r.FilePath), Line(r.Line) {}
+ cmListFileArgument(const std::string& v, Delimiter d, const char* file,
+ long line): Value(v), Delim(d),
+ FilePath(file), Line(line) {}
+ bool operator == (const cmListFileArgument& r) const
+ {
+ return (this->Value == r.Value) && (this->Delim == r.Delim);
+ }
+ bool operator != (const cmListFileArgument& r) const
+ {
+ return !(*this == r);
+ }
+ std::string Value;
+ Delimiter Delim;
+ const char* FilePath;
+ long Line;
+};
+
+struct cmListFileContext
+{
+ std::string Name;
+ std::string FilePath;
+ long Line;
+ cmListFileContext(): Name(), FilePath(), Line(0) {}
+};
+
+std::ostream& operator<<(std::ostream&, cmListFileContext const&);
+
+struct cmListFileFunction: public cmListFileContext
+{
+ std::vector<cmListFileArgument> Arguments;
+};
+
+class cmListFileBacktrace: public std::vector<cmListFileContext>
+{
+ public:
+ cmListFileBacktrace(cmLocalGenerator* localGen)
+ : LocalGenerator(localGen)
+ , Relative(localGen ? false : true)
+ {
+ }
+
+ void MakeRelative();
+ private:
+ cmLocalGenerator* LocalGenerator;
+ bool Relative;
+};
+
+struct cmListFile
+{
+ cmListFile()
+ :ModifiedTime(0)
+ {
+ }
+ bool ParseFile(const char* path,
+ bool topLevel,
+ cmMakefile *mf);
+
+ long int ModifiedTime;
+ 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/cmListFileLexer.c b/Source/cmListFileLexer.c
new file mode 100644
index 0000000000..af4fc3dcd9
--- /dev/null
+++ b/Source/cmListFileLexer.c
@@ -0,0 +1,2670 @@
+#line 2 "cmListFileLexer.c"
+
+#line 4 "cmListFileLexer.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yyg->yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yyg->yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE cmListFileLexer_yyrestart(yyin ,yyscanner )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
+#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires
+ * access to the local variable yy_act. Since yyless() is a macro, it would break
+ * existing scanners that call yyless() from OUTSIDE cmListFileLexer_yylex.
+ * One obvious solution it to make yy_act a global. I tried that, and saw
+ * a 5% performance hit in a non-yylineno scanner, because yy_act is
+ * normally declared as a register variable-- so it is not worth it.
+ */
+ #define YY_LESS_LINENO(n) \
+ do { \
+ int yyl;\
+ for ( yyl = n; yyl < yyleng; ++yyl )\
+ if ( yytext[yyl] == '\n' )\
+ --yylineno;\
+ }while(0)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = yyg->yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#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
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int 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
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via cmListFileLexer_yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
+ ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
+
+void cmListFileLexer_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void cmListFileLexer_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmListFileLexer_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
+void cmListFileLexer_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmListFileLexer_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void cmListFileLexer_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+void cmListFileLexer_yypop_buffer_state (yyscan_t yyscanner );
+
+static void cmListFileLexer_yyensure_buffer_stack (yyscan_t yyscanner );
+static void cmListFileLexer_yy_load_buffer_state (yyscan_t yyscanner );
+static void cmListFileLexer_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
+
+#define YY_FLUSH_BUFFER cmListFileLexer_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+
+YY_BUFFER_STATE cmListFileLexer_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmListFileLexer_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmListFileLexer_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+
+void *cmListFileLexer_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *cmListFileLexer_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void cmListFileLexer_yyfree (void * ,yyscan_t yyscanner );
+
+#define yy_new_buffer cmListFileLexer_yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ cmListFileLexer_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmListFileLexer_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ cmListFileLexer_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ cmListFileLexer_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+#define cmListFileLexer_yywrap(n) 1
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+typedef int yy_state_type;
+
+#define yytext_ptr yytext_r
+
+static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
+static int yy_get_next_buffer (yyscan_t yyscanner );
+static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yyg->yytext_ptr = yy_bp; \
+ yyleng = (size_t) (yy_cp - yy_bp); \
+ yyg->yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yyg->yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 24
+#define YY_END_OF_BUFFER 25
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[77] =
+ { 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 4, 4,
+ 25, 13, 22, 1, 16, 3, 13, 5, 6, 7,
+ 15, 23, 17, 19, 20, 21, 10, 11, 8, 12,
+ 9, 4, 13, 0, 13, 0, 22, 0, 0, 7,
+ 13, 0, 13, 0, 2, 0, 13, 17, 0, 18,
+ 10, 8, 4, 0, 14, 0, 0, 0, 0, 14,
+ 0, 0, 14, 0, 0, 0, 2, 14, 0, 0,
+ 0, 0, 0, 0, 0, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 5, 6, 7, 1, 1, 1, 8,
+ 9, 1, 1, 1, 1, 1, 1, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 1, 1, 1,
+ 11, 1, 1, 1, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 13, 14, 15, 1, 12, 1, 12, 12, 12, 12,
+
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 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, 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, 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, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[16] =
+ { 0,
+ 1, 1, 2, 3, 4, 3, 1, 3, 5, 6,
+ 1, 6, 1, 1, 7
+ } ;
+
+static yyconst flex_int16_t yy_base[95] =
+ { 0,
+ 0, 0, 13, 25, 14, 16, 17, 18, 90, 88,
+ 88, 39, 20, 237, 237, 74, 78, 237, 237, 13,
+ 54, 0, 71, 237, 237, 31, 0, 237, 73, 237,
+ 237, 0, 0, 65, 75, 0, 33, 30, 72, 0,
+ 0, 75, 70, 0, 74, 0, 0, 62, 70, 237,
+ 0, 63, 0, 85, 99, 65, 111, 62, 34, 0,
+ 54, 116, 0, 54, 127, 51, 237, 50, 0, 48,
+ 47, 39, 33, 29, 17, 237, 136, 143, 150, 157,
+ 164, 171, 178, 184, 191, 198, 201, 207, 214, 217,
+ 219, 225, 228, 230
+
+ } ;
+
+static yyconst flex_int16_t yy_def[95] =
+ { 0,
+ 76, 1, 77, 77, 78, 78, 79, 79, 80, 80,
+ 76, 76, 76, 76, 76, 76, 12, 76, 76, 12,
+ 76, 81, 82, 76, 76, 82, 83, 76, 76, 76,
+ 76, 84, 12, 85, 12, 86, 76, 76, 87, 20,
+ 12, 88, 12, 21, 76, 89, 12, 82, 82, 76,
+ 83, 76, 84, 85, 76, 54, 85, 90, 76, 55,
+ 87, 88, 55, 62, 88, 91, 76, 55, 92, 93,
+ 90, 94, 91, 93, 94, 0, 76, 76, 76, 76,
+ 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
+ 76, 76, 76, 76
+
+ } ;
+
+static yyconst flex_int16_t yy_nxt[253] =
+ { 0,
+ 12, 13, 14, 13, 15, 16, 17, 18, 19, 12,
+ 12, 20, 21, 22, 12, 24, 28, 25, 28, 28,
+ 28, 37, 40, 37, 40, 62, 26, 24, 29, 25,
+ 29, 31, 31, 50, 37, 48, 37, 54, 26, 33,
+ 59, 63, 45, 34, 59, 35, 45, 62, 33, 33,
+ 33, 33, 36, 33, 41, 55, 54, 58, 42, 63,
+ 43, 72, 60, 41, 44, 41, 45, 46, 41, 55,
+ 55, 56, 70, 52, 48, 49, 67, 66, 57, 63,
+ 60, 64, 58, 52, 49, 39, 38, 76, 65, 55,
+ 14, 56, 14, 76, 76, 76, 76, 76, 57, 55,
+
+ 76, 76, 76, 34, 76, 68, 76, 76, 55, 55,
+ 55, 55, 69, 55, 54, 76, 54, 76, 54, 54,
+ 63, 76, 64, 76, 76, 76, 76, 76, 76, 65,
+ 62, 76, 62, 76, 62, 62, 23, 23, 23, 23,
+ 23, 23, 23, 27, 27, 27, 27, 27, 27, 27,
+ 30, 30, 30, 30, 30, 30, 30, 32, 32, 32,
+ 32, 32, 32, 32, 47, 76, 47, 47, 47, 47,
+ 47, 48, 76, 48, 76, 48, 48, 48, 51, 76,
+ 51, 51, 51, 51, 53, 76, 53, 53, 53, 53,
+ 53, 54, 76, 76, 54, 76, 54, 54, 33, 76,
+
+ 33, 33, 33, 33, 33, 61, 61, 62, 76, 76,
+ 62, 76, 62, 62, 41, 76, 41, 41, 41, 41,
+ 41, 71, 71, 73, 73, 55, 76, 55, 55, 55,
+ 55, 55, 74, 74, 75, 75, 11, 76, 76, 76,
+ 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
+ 76, 76
+ } ;
+
+static yyconst flex_int16_t yy_chk[253] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 3, 5, 3, 6, 7,
+ 8, 13, 20, 13, 20, 75, 3, 4, 5, 4,
+ 6, 7, 8, 26, 37, 26, 37, 74, 4, 12,
+ 38, 73, 38, 12, 59, 12, 59, 72, 12, 12,
+ 12, 12, 12, 12, 21, 71, 70, 68, 21, 66,
+ 21, 64, 61, 21, 21, 21, 21, 21, 21, 34,
+ 58, 34, 56, 52, 49, 48, 45, 43, 34, 42,
+ 39, 42, 35, 29, 23, 17, 16, 11, 42, 54,
+ 10, 54, 9, 0, 0, 0, 0, 0, 54, 55,
+
+ 0, 0, 0, 55, 0, 55, 0, 0, 55, 55,
+ 55, 55, 55, 55, 57, 0, 57, 0, 57, 57,
+ 62, 0, 62, 0, 0, 0, 0, 0, 0, 62,
+ 65, 0, 65, 0, 65, 65, 77, 77, 77, 77,
+ 77, 77, 77, 78, 78, 78, 78, 78, 78, 78,
+ 79, 79, 79, 79, 79, 79, 79, 80, 80, 80,
+ 80, 80, 80, 80, 81, 0, 81, 81, 81, 81,
+ 81, 82, 0, 82, 0, 82, 82, 82, 83, 0,
+ 83, 83, 83, 83, 84, 0, 84, 84, 84, 84,
+ 84, 85, 0, 0, 85, 0, 85, 85, 86, 0,
+
+ 86, 86, 86, 86, 86, 87, 87, 88, 0, 0,
+ 88, 0, 88, 88, 89, 0, 89, 89, 89, 89,
+ 89, 90, 90, 91, 91, 92, 0, 92, 92, 92,
+ 92, 92, 93, 93, 94, 94, 76, 76, 76, 76,
+ 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
+ 76, 76
+ } ;
+
+/* Table of booleans, true if rule could match eol. */
+static yyconst flex_int32_t yy_rule_can_match_eol[25] =
+ { 0,
+1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1,
+ 0, 0, 0, 0, 0, };
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "cmListFileLexer.in.l"
+#line 2 "cmListFileLexer.in.l"
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex --prefix=cmListFileLexer_yy -ocmListFileLexer.c cmListFileLexer.in.l
+
+Modify cmListFileLexer.c:
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - remove the yyunput function
+ - add a statement "(void)yyscanner;" to the top of these methods:
+ yy_fatal_error, cmListFileLexer_yyalloc, cmListFileLexer_yyrealloc, cmListFileLexer_yyfree
+ - remove statement "yyscanner = NULL;" from cmListFileLexer_yylex_destroy
+ - remove all YY_BREAK lines occurring right after return statements
+ - remove the isatty forward declaration
+
+*/
+
+#include "cmStandardLexer.h"
+#ifdef WIN32
+#include <cmsys/Encoding.h>
+#endif
+
+/* Setup the proper cmListFileLexer_yylex declaration. */
+#define YY_EXTRA_TYPE cmListFileLexer*
+#define YY_DECL int cmListFileLexer_yylex (yyscan_t yyscanner, cmListFileLexer* lexer)
+
+#include "cmListFileLexer.h"
+
+/*--------------------------------------------------------------------------*/
+struct cmListFileLexer_s
+{
+ cmListFileLexer_Token token;
+ int bracket;
+ int comment;
+ int line;
+ int column;
+ int size;
+ FILE* file;
+ size_t cr;
+ char* string_buffer;
+ char* string_position;
+ int string_left;
+ yyscan_t scanner;
+};
+
+static void cmListFileLexerSetToken(cmListFileLexer* lexer, const char* text,
+ int length);
+static void cmListFileLexerAppend(cmListFileLexer* lexer, const char* text,
+ int length);
+static int cmListFileLexerInput(cmListFileLexer* lexer, char* buffer,
+ size_t bufferSize);
+static void cmListFileLexerInit(cmListFileLexer* lexer);
+static void cmListFileLexerDestroy(cmListFileLexer* lexer);
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = cmListFileLexerInput(cmListFileLexer_yyget_extra(yyscanner), buf, max_size); }
+
+/*--------------------------------------------------------------------------*/
+
+
+
+
+#line 628 "cmListFileLexer.c"
+
+#define INITIAL 0
+#define STRING 1
+#define BRACKET 2
+#define BRACKETEND 3
+#define COMMENT 4
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* Holds the entire state of the reentrant scanner. */
+struct yyguts_t
+ {
+
+ /* User-defined. Not touched by flex. */
+ YY_EXTRA_TYPE yyextra_r;
+
+ /* The rest are the same as the globals declared in the non-reentrant scanner. */
+ FILE *yyin_r, *yyout_r;
+ size_t yy_buffer_stack_top; /**< index of top of stack. */
+ 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;
+ char *yy_c_buf_p;
+ int yy_init;
+ int yy_start;
+ int yy_did_buffer_switch_on_eof;
+ int yy_start_stack_ptr;
+ int yy_start_stack_depth;
+ int *yy_start_stack;
+ yy_state_type yy_last_accepting_state;
+ char* yy_last_accepting_cpos;
+
+ int yylineno_r;
+ int yy_flex_debug_r;
+
+ char *yytext_r;
+ int yy_more_flag;
+ int yy_more_len;
+
+ }; /* end struct yyguts_t */
+
+static int yy_init_globals (yyscan_t yyscanner );
+
+int cmListFileLexer_yylex_init (yyscan_t* scanner);
+
+int cmListFileLexer_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int cmListFileLexer_yylex_destroy (yyscan_t yyscanner );
+
+int cmListFileLexer_yyget_debug (yyscan_t yyscanner );
+
+void cmListFileLexer_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE cmListFileLexer_yyget_extra (yyscan_t yyscanner );
+
+void cmListFileLexer_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *cmListFileLexer_yyget_in (yyscan_t yyscanner );
+
+void cmListFileLexer_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *cmListFileLexer_yyget_out (yyscan_t yyscanner );
+
+void cmListFileLexer_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+int cmListFileLexer_yyget_leng (yyscan_t yyscanner );
+
+char *cmListFileLexer_yyget_text (yyscan_t yyscanner );
+
+int cmListFileLexer_yyget_lineno (yyscan_t yyscanner );
+
+void cmListFileLexer_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+int cmListFileLexer_yyget_column (yyscan_t yyscanner );
+
+void cmListFileLexer_yyset_column (int column_no ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int cmListFileLexer_yywrap (yyscan_t yyscanner );
+#else
+extern int cmListFileLexer_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#ifdef __cplusplus
+static int yyinput (yyscan_t yyscanner );
+#else
+static int input (yyscan_t yyscanner );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
+#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int cmListFileLexer_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int cmListFileLexer_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ yy_state_type yy_current_state;
+ char *yy_cp, *yy_bp;
+ int yy_act;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+#line 91 "cmListFileLexer.in.l"
+
+
+#line 865 "cmListFileLexer.c"
+
+ if ( !yyg->yy_init )
+ {
+ yyg->yy_init = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! yyg->yy_start )
+ yyg->yy_start = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ cmListFileLexer_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmListFileLexer_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmListFileLexer_yy_load_buffer_state(yyscanner );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = yyg->yy_c_buf_p;
+
+ /* Support of yytext. */
+ *yy_cp = yyg->yy_hold_char;
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yyg->yy_start;
+yy_match:
+ do
+ {
+ 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;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 77 )
+ 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] != 237 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+ if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
+ {
+ int yyl;
+ for ( yyl = 0; yyl < yyleng; ++yyl )
+ if ( yytext[yyl] == '\n' )
+
+ do{ yylineno++;
+ yycolumn=0;
+ }while(0)
+;
+ }
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = yyg->yy_hold_char;
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ goto yy_find_action;
+
+case 1:
+/* rule 1 can match eol */
+YY_RULE_SETUP
+#line 93 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_Newline;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ ++lexer->line;
+ lexer->column = 1;
+ BEGIN(INITIAL);
+ return 1;
+}
+case 2:
+/* rule 2 can match eol */
+YY_RULE_SETUP
+#line 102 "cmListFileLexer.in.l"
+{
+ const char* bracket = yytext;
+ lexer->comment = yytext[0] == '#';
+ if(lexer->comment)
+ {
+ lexer->token.type = cmListFileLexer_Token_CommentBracket;
+ bracket += 1;
+ }
+ else
+ {
+ lexer->token.type = cmListFileLexer_Token_ArgumentBracket;
+ }
+ cmListFileLexerSetToken(lexer, "", 0);
+ lexer->bracket = (int)(strchr(bracket+1, '[') - bracket);
+ if(yytext[yyleng-1] == '\n')
+ {
+ ++lexer->line;
+ lexer->column = 1;
+ }
+ else
+ {
+ lexer->column += yyleng;
+ }
+ BEGIN(BRACKET);
+}
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 128 "cmListFileLexer.in.l"
+{
+ lexer->column += yyleng;
+ BEGIN(COMMENT);
+}
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 133 "cmListFileLexer.in.l"
+{
+ lexer->column += yyleng;
+}
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 137 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_ParenLeft;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+case 6:
+YY_RULE_SETUP
+#line 144 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_ParenRight;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+case 7:
+YY_RULE_SETUP
+#line 151 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_Identifier;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+case 8:
+YY_RULE_SETUP
+#line 158 "cmListFileLexer.in.l"
+{
+ /* Handle ]]====]=======]*/
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ if(yyleng == lexer->bracket)
+ {
+ BEGIN(BRACKETEND);
+ }
+}
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 168 "cmListFileLexer.in.l"
+{
+ lexer->column += yyleng;
+ /* Erase the partial bracket from the token. */
+ lexer->token.length -= lexer->bracket;
+ lexer->token.text[lexer->token.length] = 0;
+ BEGIN(INITIAL);
+ return 1;
+}
+case 10:
+YY_RULE_SETUP
+#line 177 "cmListFileLexer.in.l"
+{
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+}
+ YY_BREAK
+case 11:
+/* rule 11 can match eol */
+YY_RULE_SETUP
+#line 182 "cmListFileLexer.in.l"
+{
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ ++lexer->line;
+ lexer->column = 1;
+ BEGIN(BRACKET);
+}
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 189 "cmListFileLexer.in.l"
+{
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ BEGIN(BRACKET);
+}
+ YY_BREAK
+case YY_STATE_EOF(BRACKET):
+case YY_STATE_EOF(BRACKETEND):
+#line 195 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_BadBracket;
+ BEGIN(INITIAL);
+ return 1;
+}
+case 13:
+YY_RULE_SETUP
+#line 201 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+case 14:
+YY_RULE_SETUP
+#line 208 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+case 15:
+YY_RULE_SETUP
+#line 215 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+case 16:
+YY_RULE_SETUP
+#line 222 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_ArgumentQuoted;
+ cmListFileLexerSetToken(lexer, "", 0);
+ lexer->column += yyleng;
+ BEGIN(STRING);
+}
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 229 "cmListFileLexer.in.l"
+{
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+}
+ YY_BREAK
+case 18:
+/* rule 18 can match eol */
+YY_RULE_SETUP
+#line 234 "cmListFileLexer.in.l"
+{
+ /* Continuation: text is not part of string */
+ ++lexer->line;
+ lexer->column = 1;
+}
+ YY_BREAK
+case 19:
+/* rule 19 can match eol */
+YY_RULE_SETUP
+#line 240 "cmListFileLexer.in.l"
+{
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ ++lexer->line;
+ lexer->column = 1;
+}
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 246 "cmListFileLexer.in.l"
+{
+ lexer->column += yyleng;
+ BEGIN(INITIAL);
+ return 1;
+}
+case 21:
+YY_RULE_SETUP
+#line 252 "cmListFileLexer.in.l"
+{
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+}
+ YY_BREAK
+case YY_STATE_EOF(STRING):
+#line 257 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_BadString;
+ BEGIN(INITIAL);
+ return 1;
+}
+case 22:
+YY_RULE_SETUP
+#line 263 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_Space;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+case 23:
+YY_RULE_SETUP
+#line 270 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_BadCharacter;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(COMMENT):
+#line 277 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_None;
+ cmListFileLexerSetToken(lexer, 0, 0);
+ return 0;
+}
+case 24:
+YY_RULE_SETUP
+#line 283 "cmListFileLexer.in.l"
+ECHO;
+ YY_BREAK
+#line 1238 "cmListFileLexer.c"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = yyg->yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * cmListFileLexer_yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
+
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++yyg->yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yyg->yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yyg->yy_did_buffer_switch_on_eof = 0;
+
+ if ( cmListFileLexer_yywrap(yyscanner ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p =
+ yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yyg->yy_c_buf_p =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of cmListFileLexer_yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ char *source = yyg->yytext_ptr;
+ int number_to_move, i;
+ int ret_val;
+
+ if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
+
+ else
+ {
+ int 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;
+
+ 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;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ cmListFileLexer_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* 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 );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ if ( yyg->yy_n_chars == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ cmListFileLexer_yyrestart(yyin ,yyscanner);
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cmListFileLexer_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ yyg->yy_n_chars += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
+{
+ yy_state_type yy_current_state;
+ char *yy_cp;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ yy_current_state = yyg->yy_start;
+
+ for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
+ {
+ YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 77 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
+{
+ int yy_is_jam;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
+ char *yy_cp = yyg->yy_c_buf_p;
+
+ YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ 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 >= 77 )
+ 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 == 76);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (yyscan_t yyscanner)
+#else
+ static int input (yyscan_t yyscanner)
+#endif
+
+{
+ int c;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+
+ if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ /* This was really a NUL. */
+ *yyg->yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ ++yyg->yy_c_buf_p;
+
+ switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ cmListFileLexer_yyrestart(yyin ,yyscanner);
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( cmListFileLexer_yywrap(yyscanner ) )
+ return EOF;
+
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput(yyscanner);
+#else
+ return input(yyscanner);
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
+ *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
+ yyg->yy_hold_char = *++yyg->yy_c_buf_p;
+
+ if ( c == '\n' )
+
+ do{ yylineno++;
+ yycolumn=0;
+ }while(0)
+;
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ * @param yyscanner The scanner object.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void cmListFileLexer_yyrestart (FILE * input_file , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! YY_CURRENT_BUFFER ){
+ cmListFileLexer_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ cmListFileLexer_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ cmListFileLexer_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
+ cmListFileLexer_yy_load_buffer_state(yyscanner );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ * @param yyscanner The scanner object.
+ */
+ void cmListFileLexer_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * cmListFileLexer_yypop_buffer_state();
+ * cmListFileLexer_yypush_buffer_state(new_buffer);
+ */
+ cmListFileLexer_yyensure_buffer_stack (yyscanner);
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ cmListFileLexer_yy_load_buffer_state(yyscanner );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (cmListFileLexer_yywrap()) processing, but the only time this flag
+ * is looked at is after cmListFileLexer_yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+static void cmListFileLexer_yy_load_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ yyg->yy_hold_char = *yyg->yy_c_buf_p;
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * @param yyscanner The scanner object.
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE cmListFileLexer_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) cmListFileLexer_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) cmListFileLexer_yyalloc(b->yy_buf_size + 2 ,yyscanner );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ cmListFileLexer_yy_init_buffer(b,file ,yyscanner);
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with cmListFileLexer_yy_create_buffer()
+ * @param yyscanner The scanner object.
+ */
+ void cmListFileLexer_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ cmListFileLexer_yyfree((void *) b->yy_ch_buf ,yyscanner );
+
+ cmListFileLexer_yyfree((void *) b ,yyscanner );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a cmListFileLexer_yyrestart() or at EOF.
+ */
+ static void cmListFileLexer_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+
+{
+ int oerrno = errno;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ cmListFileLexer_yy_flush_buffer(b ,yyscanner);
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then cmListFileLexer_yy_init_buffer was _probably_
+ * called from cmListFileLexer_yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ * @param yyscanner The scanner object.
+ */
+ void cmListFileLexer_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ cmListFileLexer_yy_load_buffer_state(yyscanner );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ * @param yyscanner The scanner object.
+ */
+void cmListFileLexer_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (new_buffer == NULL)
+ return;
+
+ cmListFileLexer_yyensure_buffer_stack(yyscanner);
+
+ /* This block is copied from cmListFileLexer_yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ yyg->yy_buffer_stack_top++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from cmListFileLexer_yy_switch_to_buffer. */
+ cmListFileLexer_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ * @param yyscanner The scanner object.
+ */
+void cmListFileLexer_yypop_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ cmListFileLexer_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if (yyg->yy_buffer_stack_top > 0)
+ --yyg->yy_buffer_stack_top;
+
+ if (YY_CURRENT_BUFFER) {
+ cmListFileLexer_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void cmListFileLexer_yyensure_buffer_stack (yyscan_t yyscanner)
+{
+ int num_to_alloc;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (!yyg->yy_buffer_stack) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmListFileLexer_yyalloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+ if ( ! yyg->yy_buffer_stack )
+ YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yyensure_buffer_stack()" );
+
+ memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ yyg->yy_buffer_stack_max = num_to_alloc;
+ yyg->yy_buffer_stack_top = 0;
+ return;
+ }
+
+ if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)cmListFileLexer_yyrealloc
+ (yyg->yy_buffer_stack,
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+ if ( ! yyg->yy_buffer_stack )
+ YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
+ yyg->yy_buffer_stack_max = num_to_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmListFileLexer_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) cmListFileLexer_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ cmListFileLexer_yy_switch_to_buffer(b ,yyscanner );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to cmListFileLexer_yylex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * cmListFileLexer_yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE cmListFileLexer_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+{
+
+ return cmListFileLexer_yy_scan_bytes(yystr,strlen(yystr) ,yyscanner);
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to cmListFileLexer_yylex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE cmListFileLexer_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) cmListFileLexer_yyalloc(n ,yyscanner );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yy_scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = cmListFileLexer_yy_scan_buffer(buf,n ,yyscanner);
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in cmListFileLexer_yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
+{
+ (void)yyscanner;
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = yyg->yy_hold_char; \
+ yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
+ yyg->yy_hold_char = *yyg->yy_c_buf_p; \
+ *yyg->yy_c_buf_p = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the user-defined data for this scanner.
+ * @param yyscanner The scanner object.
+ */
+YY_EXTRA_TYPE cmListFileLexer_yyget_extra (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyextra;
+}
+
+/** Get the current line number.
+ * @param yyscanner The scanner object.
+ */
+int cmListFileLexer_yyget_lineno (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yylineno;
+}
+
+/** Get the current column number.
+ * @param yyscanner The scanner object.
+ */
+int cmListFileLexer_yyget_column (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yycolumn;
+}
+
+/** Get the input stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmListFileLexer_yyget_in (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyin;
+}
+
+/** Get the output stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *cmListFileLexer_yyget_out (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyout;
+}
+
+/** Get the length of the current token.
+ * @param yyscanner The scanner object.
+ */
+int cmListFileLexer_yyget_leng (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyleng;
+}
+
+/** Get the current token.
+ * @param yyscanner The scanner object.
+ */
+
+char *cmListFileLexer_yyget_text (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yytext;
+}
+
+/** Set the user-defined data. This data is never touched by the scanner.
+ * @param user_defined The data to be associated with this scanner.
+ * @param yyscanner The scanner object.
+ */
+void cmListFileLexer_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyextra = user_defined ;
+}
+
+/** Set the current line number.
+ * @param line_number
+ * @param yyscanner The scanner object.
+ */
+void cmListFileLexer_yyset_lineno (int line_number , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* lineno is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmListFileLexer_yyset_lineno called with no buffer" , yyscanner);
+
+ yylineno = line_number;
+}
+
+/** Set the current column.
+ * @param line_number
+ * @param yyscanner The scanner object.
+ */
+void cmListFileLexer_yyset_column (int column_no , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* column is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ yy_fatal_error( "cmListFileLexer_yyset_column called with no buffer" , yyscanner);
+
+ yycolumn = column_no;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ * @param yyscanner The scanner object.
+ * @see cmListFileLexer_yy_switch_to_buffer
+ */
+void cmListFileLexer_yyset_in (FILE * in_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyin = in_str ;
+}
+
+void cmListFileLexer_yyset_out (FILE * out_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyout = out_str ;
+}
+
+int cmListFileLexer_yyget_debug (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yy_flex_debug;
+}
+
+void cmListFileLexer_yyset_debug (int bdebug , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yy_flex_debug = bdebug ;
+}
+
+/* Accessor methods for yylval and yylloc */
+
+/* User-visible API */
+
+/* cmListFileLexer_yylex_init is special because it creates the scanner itself, so it is
+ * the ONLY reentrant function that doesn't take the scanner as the last argument.
+ * That's why we explicitly handle the declaration, instead of using our macros.
+ */
+
+int cmListFileLexer_yylex_init(yyscan_t* ptr_yy_globals)
+
+{
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) cmListFileLexer_yyalloc ( sizeof( struct yyguts_t ), NULL );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
+ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+/* cmListFileLexer_yylex_init_extra has the same functionality as cmListFileLexer_yylex_init, but follows the
+ * convention of taking the scanner as the last argument. Note however, that
+ * this is a *pointer* to a scanner, as it will be allocated by this call (and
+ * is the reason, too, why this function also must handle its own declaration).
+ * The user defined value in the first argument will be available to cmListFileLexer_yyalloc in
+ * the yyextra field.
+ */
+
+int cmListFileLexer_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
+
+{
+ struct yyguts_t dummy_yyguts;
+
+ cmListFileLexer_yyset_extra (yy_user_defined, &dummy_yyguts);
+
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) cmListFileLexer_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ /* By setting to 0xAA, we expose bugs in
+ yy_init_globals. Leave at 0x00 for releases. */
+ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+ cmListFileLexer_yyset_extra (yy_user_defined, *ptr_yy_globals);
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+static int yy_init_globals (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from cmListFileLexer_yylex_destroy(), so don't allocate here.
+ */
+
+ yyg->yy_buffer_stack = 0;
+ yyg->yy_buffer_stack_top = 0;
+ yyg->yy_buffer_stack_max = 0;
+ yyg->yy_c_buf_p = (char *) 0;
+ yyg->yy_init = 0;
+ yyg->yy_start = 0;
+
+ yyg->yy_start_stack_ptr = 0;
+ yyg->yy_start_stack_depth = 0;
+ yyg->yy_start_stack = NULL;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ yyin = stdin;
+ yyout = stdout;
+#else
+ yyin = (FILE *) 0;
+ yyout = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * cmListFileLexer_yylex_init()
+ */
+ return 0;
+}
+
+/* cmListFileLexer_yylex_destroy is for both reentrant and non-reentrant scanners. */
+int cmListFileLexer_yylex_destroy (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ cmListFileLexer_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ cmListFileLexer_yypop_buffer_state(yyscanner);
+ }
+
+ /* Destroy the stack itself. */
+ cmListFileLexer_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyg->yy_buffer_stack = NULL;
+
+ /* Destroy the start condition stack. */
+ cmListFileLexer_yyfree(yyg->yy_start_stack ,yyscanner );
+ yyg->yy_start_stack = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * cmListFileLexer_yylex() is called, initialization will occur. */
+ yy_init_globals( yyscanner);
+
+ /* Destroy the main struct (reentrant only). */
+ cmListFileLexer_yyfree ( yyscanner , yyscanner );
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+{
+ int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+{
+ int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *cmListFileLexer_yyalloc (yy_size_t size , yyscan_t yyscanner)
+{
+ (void)yyscanner;
+ return (void *) malloc( size );
+}
+
+void *cmListFileLexer_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ (void)yyscanner;
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void cmListFileLexer_yyfree (void * ptr , yyscan_t yyscanner)
+{
+ (void)yyscanner;
+ free( (char *) ptr ); /* see cmListFileLexer_yyrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 282 "cmListFileLexer.in.l"
+
+
+
+/*--------------------------------------------------------------------------*/
+static void cmListFileLexerSetToken(cmListFileLexer* lexer, const char* text,
+ int length)
+{
+ /* Set the token line and column number. */
+ lexer->token.line = lexer->line;
+ lexer->token.column = lexer->column;
+
+ /* Use the same buffer if possible. */
+ if(lexer->token.text)
+ {
+ if(text && length < lexer->size)
+ {
+ strcpy(lexer->token.text, text);
+ lexer->token.length = length;
+ return;
+ }
+ free(lexer->token.text);
+ lexer->token.text = 0;
+ lexer->size = 0;
+ }
+
+ /* Need to extend the buffer. */
+ if(text)
+ {
+ lexer->token.text = strdup(text);
+ lexer->token.length = length;
+ lexer->size = length+1;
+ }
+ else
+ {
+ lexer->token.length = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static void cmListFileLexerAppend(cmListFileLexer* lexer, const char* text,
+ int length)
+{
+ char* temp;
+ int newSize;
+
+ /* If the appended text will fit in the buffer, do not reallocate. */
+ newSize = lexer->token.length + length + 1;
+ if(lexer->token.text && newSize <= lexer->size)
+ {
+ strcpy(lexer->token.text+lexer->token.length, text);
+ lexer->token.length += length;
+ return;
+ }
+
+ /* We need to extend the buffer. */
+ temp = malloc(newSize);
+ if(lexer->token.text)
+ {
+ memcpy(temp, lexer->token.text, lexer->token.length);
+ free(lexer->token.text);
+ }
+ memcpy(temp+lexer->token.length, text, length);
+ temp[lexer->token.length+length] = 0;
+ lexer->token.text = temp;
+ lexer->token.length += length;
+ lexer->size = newSize;
+}
+
+/*--------------------------------------------------------------------------*/
+static int cmListFileLexerInput(cmListFileLexer* lexer, char* buffer,
+ size_t bufferSize)
+{
+ if(lexer)
+ {
+ if(lexer->file)
+ {
+ /* Convert CRLF -> LF explicitly. The C FILE "t"ext mode
+ does not convert newlines on all platforms. Move any
+ trailing CR to the start of the buffer for the next read. */
+ size_t cr = lexer->cr;
+ size_t n;
+ buffer[0] = '\r';
+ n = fread(buffer+cr, 1, bufferSize-cr, lexer->file);
+ if(n)
+ {
+ char* o = buffer;
+ const char* i = buffer;
+ const char* e;
+ n += cr;
+ cr = (buffer[n-1] == '\r')? 1:0;
+ e = buffer + n - cr;
+ while(i != e)
+ {
+ if(i[0] == '\r' && i[1] == '\n')
+ {
+ ++i;
+ }
+ *o++ = *i++;
+ }
+ n = o - buffer;
+ }
+ else
+ {
+ n = cr;
+ cr = 0;
+ }
+ lexer->cr = cr;
+ return n;
+ }
+ else if(lexer->string_left)
+ {
+ int length = lexer->string_left;
+ if((int)bufferSize < length) { length = (int)bufferSize; }
+ memcpy(buffer, lexer->string_position, length);
+ lexer->string_position += length;
+ lexer->string_left -= length;
+ return length;
+ }
+ }
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+static void cmListFileLexerInit(cmListFileLexer* lexer)
+{
+ if(lexer->file || lexer->string_buffer)
+ {
+ cmListFileLexer_yylex_init(&lexer->scanner);
+ cmListFileLexer_yyset_extra(lexer, lexer->scanner);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static void cmListFileLexerDestroy(cmListFileLexer* lexer)
+{
+ cmListFileLexerSetToken(lexer, 0, 0);
+ if(lexer->file || lexer->string_buffer)
+ {
+ cmListFileLexer_yylex_destroy(lexer->scanner);
+ if(lexer->file)
+ {
+ fclose(lexer->file);
+ lexer->file = 0;
+ }
+ if(lexer->string_buffer)
+ {
+ free(lexer->string_buffer);
+ lexer->string_buffer = 0;
+ lexer->string_left = 0;
+ lexer->string_position = 0;
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+cmListFileLexer* cmListFileLexer_New()
+{
+ cmListFileLexer* lexer = (cmListFileLexer*)malloc(sizeof(cmListFileLexer));
+ if(!lexer)
+ {
+ return 0;
+ }
+ memset(lexer, 0, sizeof(*lexer));
+ lexer->line = 1;
+ lexer->column = 1;
+ return lexer;
+}
+
+/*--------------------------------------------------------------------------*/
+void cmListFileLexer_Delete(cmListFileLexer* lexer)
+{
+ cmListFileLexer_SetFileName(lexer, 0, 0);
+ free(lexer);
+}
+
+/*--------------------------------------------------------------------------*/
+static cmListFileLexer_BOM cmListFileLexer_ReadBOM(FILE* f)
+{
+ unsigned char b[2];
+ if(fread(b, 1, 2, f) == 2)
+ {
+ if(b[0] == 0xEF && b[1] == 0xBB)
+ {
+ if(fread(b, 1, 1, f) == 1 && b[0] == 0xBF)
+ {
+ return cmListFileLexer_BOM_UTF8;
+ }
+ }
+ else if(b[0] == 0xFE && b[1] == 0xFF)
+ {
+ /* UTF-16 BE */
+ return cmListFileLexer_BOM_UTF16BE;
+ }
+ else if(b[0] == 0 && b[1] == 0)
+ {
+ if(fread(b, 1, 2, f) == 2 && b[0] == 0xFE && b[1] == 0xFF)
+ {
+ return cmListFileLexer_BOM_UTF32BE;
+ }
+ }
+ else if(b[0] == 0xFF && b[1] == 0xFE)
+ {
+ fpos_t p;
+ fgetpos(f, &p);
+ if(fread(b, 1, 2, f) == 2 && b[0] == 0 && b[1] == 0)
+ {
+ return cmListFileLexer_BOM_UTF32LE;
+ }
+ fsetpos(f, &p);
+ return cmListFileLexer_BOM_UTF16LE;
+ }
+ }
+ rewind(f);
+ return cmListFileLexer_BOM_None;
+}
+
+/*--------------------------------------------------------------------------*/
+int cmListFileLexer_SetFileName(cmListFileLexer* lexer, const char* name,
+ cmListFileLexer_BOM* bom)
+{
+ int result = 1;
+ cmListFileLexerDestroy(lexer);
+ if(name)
+ {
+#ifdef _WIN32
+ wchar_t* wname = cmsysEncoding_DupToWide(name);
+ lexer->file = _wfopen(wname, L"rb");
+ free(wname);
+#else
+ lexer->file = fopen(name, "rb");
+#endif
+ if(lexer->file)
+ {
+ if(bom)
+ {
+ *bom = cmListFileLexer_ReadBOM(lexer->file);
+ }
+ }
+ else
+ {
+ result = 0;
+ }
+ }
+ cmListFileLexerInit(lexer);
+ return result;
+}
+
+/*--------------------------------------------------------------------------*/
+int cmListFileLexer_SetString(cmListFileLexer* lexer, const char* text)
+{
+ int result = 1;
+ cmListFileLexerDestroy(lexer);
+ if(text)
+ {
+ int length = (int)strlen(text);
+ lexer->string_buffer = (char*)malloc(length+1);
+ if(lexer->string_buffer)
+ {
+ strcpy(lexer->string_buffer, text);
+ lexer->string_position = lexer->string_buffer;
+ lexer->string_left = length;
+ }
+ else
+ {
+ result = 0;
+ }
+ }
+ cmListFileLexerInit(lexer);
+ return result;
+}
+
+/*--------------------------------------------------------------------------*/
+cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer* lexer)
+{
+ if(!lexer->file)
+ {
+ return 0;
+ }
+ if(cmListFileLexer_yylex(lexer->scanner, lexer))
+ {
+ return &lexer->token;
+ }
+ else
+ {
+ cmListFileLexer_SetFileName(lexer, 0, 0);
+ return 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+long cmListFileLexer_GetCurrentLine(cmListFileLexer* lexer)
+{
+ if(lexer->file)
+ {
+ return lexer->line;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+long cmListFileLexer_GetCurrentColumn(cmListFileLexer* lexer)
+{
+ if(lexer->file)
+ {
+ return lexer->column;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer,
+ cmListFileLexer_Type type)
+{
+ (void)lexer;
+ switch(type)
+ {
+ case cmListFileLexer_Token_None: return "nothing";
+ case cmListFileLexer_Token_Space: return "space";
+ case cmListFileLexer_Token_Newline: return "newline";
+ case cmListFileLexer_Token_Identifier: return "identifier";
+ case cmListFileLexer_Token_ParenLeft: return "left paren";
+ case cmListFileLexer_Token_ParenRight: return "right paren";
+ case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument";
+ case cmListFileLexer_Token_ArgumentQuoted: return "quoted argument";
+ case cmListFileLexer_Token_ArgumentBracket: return "bracket argument";
+ case cmListFileLexer_Token_CommentBracket: return "bracket comment";
+ case cmListFileLexer_Token_BadCharacter: return "bad character";
+ case cmListFileLexer_Token_BadBracket: return "unterminated bracket";
+ case cmListFileLexer_Token_BadString: return "unterminated string";
+ }
+ return "unknown token";
+}
diff --git a/Source/cmListFileLexer.h b/Source/cmListFileLexer.h
new file mode 100644
index 0000000000..bd2868ab6b
--- /dev/null
+++ b/Source/cmListFileLexer.h
@@ -0,0 +1,75 @@
+/*============================================================================
+ 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 cmListFileLexer_h
+#define cmListFileLexer_h
+
+typedef enum cmListFileLexer_Type_e
+{
+ cmListFileLexer_Token_None,
+ cmListFileLexer_Token_Space,
+ cmListFileLexer_Token_Newline,
+ cmListFileLexer_Token_Identifier,
+ cmListFileLexer_Token_ParenLeft,
+ cmListFileLexer_Token_ParenRight,
+ cmListFileLexer_Token_ArgumentUnquoted,
+ cmListFileLexer_Token_ArgumentQuoted,
+ cmListFileLexer_Token_ArgumentBracket,
+ cmListFileLexer_Token_CommentBracket,
+ cmListFileLexer_Token_BadCharacter,
+ cmListFileLexer_Token_BadBracket,
+ cmListFileLexer_Token_BadString
+} cmListFileLexer_Type;
+
+typedef struct cmListFileLexer_Token_s cmListFileLexer_Token;
+struct cmListFileLexer_Token_s
+{
+ cmListFileLexer_Type type;
+ char* text;
+ int length;
+ int line;
+ int column;
+};
+
+enum cmListFileLexer_BOM_e
+{
+ cmListFileLexer_BOM_None,
+ cmListFileLexer_BOM_UTF8,
+ cmListFileLexer_BOM_UTF16BE,
+ cmListFileLexer_BOM_UTF16LE,
+ cmListFileLexer_BOM_UTF32BE,
+ cmListFileLexer_BOM_UTF32LE
+};
+typedef enum cmListFileLexer_BOM_e cmListFileLexer_BOM;
+
+typedef struct cmListFileLexer_s cmListFileLexer;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+cmListFileLexer* cmListFileLexer_New();
+int cmListFileLexer_SetFileName(cmListFileLexer*, const char*,
+ cmListFileLexer_BOM* bom);
+int cmListFileLexer_SetString(cmListFileLexer*, const char*);
+cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer*);
+long cmListFileLexer_GetCurrentLine(cmListFileLexer*);
+long cmListFileLexer_GetCurrentColumn(cmListFileLexer*);
+const char* cmListFileLexer_GetTypeAsString(cmListFileLexer*,
+ cmListFileLexer_Type);
+void cmListFileLexer_Delete(cmListFileLexer*);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/Source/cmListFileLexer.in.l b/Source/cmListFileLexer.in.l
new file mode 100644
index 0000000000..a520c7221b
--- /dev/null
+++ b/Source/cmListFileLexer.in.l
@@ -0,0 +1,619 @@
+%{
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+
+This file must be translated to C and modified to build everywhere.
+
+Run flex like this:
+
+ flex --prefix=cmListFileLexer_yy -ocmListFileLexer.c cmListFileLexer.in.l
+
+Modify cmListFileLexer.c:
+ - remove TABs
+ - remove use of the 'register' storage class specifier
+ - remove the yyunput function
+ - add a statement "(void)yyscanner;" to the top of these methods:
+ yy_fatal_error, cmListFileLexer_yyalloc, cmListFileLexer_yyrealloc, cmListFileLexer_yyfree
+ - remove statement "yyscanner = NULL;" from cmListFileLexer_yylex_destroy
+ - remove all YY_BREAK lines occurring right after return statements
+ - remove the isatty forward declaration
+
+*/
+
+#include "cmStandardLexer.h"
+#ifdef WIN32
+#include <cmsys/Encoding.h>
+#endif
+
+/* Setup the proper cmListFileLexer_yylex declaration. */
+#define YY_EXTRA_TYPE cmListFileLexer*
+#define YY_DECL int cmListFileLexer_yylex (yyscan_t yyscanner, cmListFileLexer* lexer)
+
+#include "cmListFileLexer.h"
+
+/*--------------------------------------------------------------------------*/
+struct cmListFileLexer_s
+{
+ cmListFileLexer_Token token;
+ int bracket;
+ int comment;
+ int line;
+ int column;
+ int size;
+ FILE* file;
+ size_t cr;
+ char* string_buffer;
+ char* string_position;
+ int string_left;
+ yyscan_t scanner;
+};
+
+static void cmListFileLexerSetToken(cmListFileLexer* lexer, const char* text,
+ int length);
+static void cmListFileLexerAppend(cmListFileLexer* lexer, const char* text,
+ int length);
+static int cmListFileLexerInput(cmListFileLexer* lexer, char* buffer,
+ size_t bufferSize);
+static void cmListFileLexerInit(cmListFileLexer* lexer);
+static void cmListFileLexerDestroy(cmListFileLexer* lexer);
+
+/* Replace the lexer input function. */
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) \
+ { result = cmListFileLexerInput(cmListFileLexer_yyget_extra(yyscanner), buf, max_size); }
+
+/*--------------------------------------------------------------------------*/
+%}
+
+%option reentrant
+%option yylineno
+%option noyywrap
+%pointer
+%x STRING
+%x BRACKET
+%x BRACKETEND
+%x COMMENT
+
+MAKEVAR \$\([A-Za-z0-9_]*\)
+UNQUOTED ([^ \t\r\n\(\)#\\\"[=]|\\.)
+LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
+
+%%
+
+<INITIAL,COMMENT>\n {
+ lexer->token.type = cmListFileLexer_Token_Newline;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ ++lexer->line;
+ lexer->column = 1;
+ BEGIN(INITIAL);
+ return 1;
+}
+
+#?\[=*\[\n? {
+ const char* bracket = yytext;
+ lexer->comment = yytext[0] == '#';
+ if(lexer->comment)
+ {
+ lexer->token.type = cmListFileLexer_Token_CommentBracket;
+ bracket += 1;
+ }
+ else
+ {
+ lexer->token.type = cmListFileLexer_Token_ArgumentBracket;
+ }
+ cmListFileLexerSetToken(lexer, "", 0);
+ lexer->bracket = (int)(strchr(bracket+1, '[') - bracket);
+ if(yytext[yyleng-1] == '\n')
+ {
+ ++lexer->line;
+ lexer->column = 1;
+ }
+ else
+ {
+ lexer->column += yyleng;
+ }
+ BEGIN(BRACKET);
+}
+
+# {
+ lexer->column += yyleng;
+ BEGIN(COMMENT);
+}
+
+<COMMENT>.* {
+ lexer->column += yyleng;
+}
+
+\( {
+ lexer->token.type = cmListFileLexer_Token_ParenLeft;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+
+\) {
+ lexer->token.type = cmListFileLexer_Token_ParenRight;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+
+[A-Za-z_][A-Za-z0-9_]* {
+ lexer->token.type = cmListFileLexer_Token_Identifier;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+
+<BRACKET>\]=* {
+ /* Handle ]]====]=======]*/
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ if(yyleng == lexer->bracket)
+ {
+ BEGIN(BRACKETEND);
+ }
+}
+
+<BRACKETEND>\] {
+ lexer->column += yyleng;
+ /* Erase the partial bracket from the token. */
+ lexer->token.length -= lexer->bracket;
+ lexer->token.text[lexer->token.length] = 0;
+ BEGIN(INITIAL);
+ return 1;
+}
+
+<BRACKET>([^]\n])+ {
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+}
+
+<BRACKET,BRACKETEND>\n {
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ ++lexer->line;
+ lexer->column = 1;
+ BEGIN(BRACKET);
+}
+
+<BRACKET,BRACKETEND>. {
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ BEGIN(BRACKET);
+}
+
+<BRACKET,BRACKETEND><<EOF>> {
+ lexer->token.type = cmListFileLexer_Token_BadBracket;
+ BEGIN(INITIAL);
+ return 1;
+}
+
+({UNQUOTED}|=|\[=*{UNQUOTED})({UNQUOTED}|[[=])* {
+ lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+
+({MAKEVAR}|{UNQUOTED}|=|\[=*{LEGACY})({LEGACY}|[[=])* {
+ lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+
+\[ {
+ lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+
+\" {
+ lexer->token.type = cmListFileLexer_Token_ArgumentQuoted;
+ cmListFileLexerSetToken(lexer, "", 0);
+ lexer->column += yyleng;
+ BEGIN(STRING);
+}
+
+<STRING>([^\\\n\"]|\\.)+ {
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+}
+
+<STRING>\\\n {
+ /* Continuation: text is not part of string */
+ ++lexer->line;
+ lexer->column = 1;
+}
+
+<STRING>\n {
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ ++lexer->line;
+ lexer->column = 1;
+}
+
+<STRING>\" {
+ lexer->column += yyleng;
+ BEGIN(INITIAL);
+ return 1;
+}
+
+<STRING>. {
+ cmListFileLexerAppend(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+}
+
+<STRING><<EOF>> {
+ lexer->token.type = cmListFileLexer_Token_BadString;
+ BEGIN(INITIAL);
+ return 1;
+}
+
+[ \t\r]+ {
+ lexer->token.type = cmListFileLexer_Token_Space;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+
+. {
+ lexer->token.type = cmListFileLexer_Token_BadCharacter;
+ cmListFileLexerSetToken(lexer, yytext, yyleng);
+ lexer->column += yyleng;
+ return 1;
+}
+
+<<EOF>> {
+ lexer->token.type = cmListFileLexer_Token_None;
+ cmListFileLexerSetToken(lexer, 0, 0);
+ return 0;
+}
+
+%%
+
+/*--------------------------------------------------------------------------*/
+static void cmListFileLexerSetToken(cmListFileLexer* lexer, const char* text,
+ int length)
+{
+ /* Set the token line and column number. */
+ lexer->token.line = lexer->line;
+ lexer->token.column = lexer->column;
+
+ /* Use the same buffer if possible. */
+ if(lexer->token.text)
+ {
+ if(text && length < lexer->size)
+ {
+ strcpy(lexer->token.text, text);
+ lexer->token.length = length;
+ return;
+ }
+ free(lexer->token.text);
+ lexer->token.text = 0;
+ lexer->size = 0;
+ }
+
+ /* Need to extend the buffer. */
+ if(text)
+ {
+ lexer->token.text = strdup(text);
+ lexer->token.length = length;
+ lexer->size = length+1;
+ }
+ else
+ {
+ lexer->token.length = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static void cmListFileLexerAppend(cmListFileLexer* lexer, const char* text,
+ int length)
+{
+ char* temp;
+ int newSize;
+
+ /* If the appended text will fit in the buffer, do not reallocate. */
+ newSize = lexer->token.length + length + 1;
+ if(lexer->token.text && newSize <= lexer->size)
+ {
+ strcpy(lexer->token.text+lexer->token.length, text);
+ lexer->token.length += length;
+ return;
+ }
+
+ /* We need to extend the buffer. */
+ temp = malloc(newSize);
+ if(lexer->token.text)
+ {
+ memcpy(temp, lexer->token.text, lexer->token.length);
+ free(lexer->token.text);
+ }
+ memcpy(temp+lexer->token.length, text, length);
+ temp[lexer->token.length+length] = 0;
+ lexer->token.text = temp;
+ lexer->token.length += length;
+ lexer->size = newSize;
+}
+
+/*--------------------------------------------------------------------------*/
+static int cmListFileLexerInput(cmListFileLexer* lexer, char* buffer,
+ size_t bufferSize)
+{
+ if(lexer)
+ {
+ if(lexer->file)
+ {
+ /* Convert CRLF -> LF explicitly. The C FILE "t"ext mode
+ does not convert newlines on all platforms. Move any
+ trailing CR to the start of the buffer for the next read. */
+ size_t cr = lexer->cr;
+ size_t n;
+ buffer[0] = '\r';
+ n = fread(buffer+cr, 1, bufferSize-cr, lexer->file);
+ if(n)
+ {
+ char* o = buffer;
+ const char* i = buffer;
+ const char* e;
+ n += cr;
+ cr = (buffer[n-1] == '\r')? 1:0;
+ e = buffer + n - cr;
+ while(i != e)
+ {
+ if(i[0] == '\r' && i[1] == '\n')
+ {
+ ++i;
+ }
+ *o++ = *i++;
+ }
+ n = o - buffer;
+ }
+ else
+ {
+ n = cr;
+ cr = 0;
+ }
+ lexer->cr = cr;
+ return n;
+ }
+ else if(lexer->string_left)
+ {
+ int length = lexer->string_left;
+ if((int)bufferSize < length) { length = (int)bufferSize; }
+ memcpy(buffer, lexer->string_position, length);
+ lexer->string_position += length;
+ lexer->string_left -= length;
+ return length;
+ }
+ }
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+static void cmListFileLexerInit(cmListFileLexer* lexer)
+{
+ if(lexer->file || lexer->string_buffer)
+ {
+ cmListFileLexer_yylex_init(&lexer->scanner);
+ cmListFileLexer_yyset_extra(lexer, lexer->scanner);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static void cmListFileLexerDestroy(cmListFileLexer* lexer)
+{
+ cmListFileLexerSetToken(lexer, 0, 0);
+ if(lexer->file || lexer->string_buffer)
+ {
+ cmListFileLexer_yylex_destroy(lexer->scanner);
+ if(lexer->file)
+ {
+ fclose(lexer->file);
+ lexer->file = 0;
+ }
+ if(lexer->string_buffer)
+ {
+ free(lexer->string_buffer);
+ lexer->string_buffer = 0;
+ lexer->string_left = 0;
+ lexer->string_position = 0;
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+cmListFileLexer* cmListFileLexer_New()
+{
+ cmListFileLexer* lexer = (cmListFileLexer*)malloc(sizeof(cmListFileLexer));
+ if(!lexer)
+ {
+ return 0;
+ }
+ memset(lexer, 0, sizeof(*lexer));
+ lexer->line = 1;
+ lexer->column = 1;
+ return lexer;
+}
+
+/*--------------------------------------------------------------------------*/
+void cmListFileLexer_Delete(cmListFileLexer* lexer)
+{
+ cmListFileLexer_SetFileName(lexer, 0, 0);
+ free(lexer);
+}
+
+/*--------------------------------------------------------------------------*/
+static cmListFileLexer_BOM cmListFileLexer_ReadBOM(FILE* f)
+{
+ unsigned char b[2];
+ if(fread(b, 1, 2, f) == 2)
+ {
+ if(b[0] == 0xEF && b[1] == 0xBB)
+ {
+ if(fread(b, 1, 1, f) == 1 && b[0] == 0xBF)
+ {
+ return cmListFileLexer_BOM_UTF8;
+ }
+ }
+ else if(b[0] == 0xFE && b[1] == 0xFF)
+ {
+ /* UTF-16 BE */
+ return cmListFileLexer_BOM_UTF16BE;
+ }
+ else if(b[0] == 0 && b[1] == 0)
+ {
+ if(fread(b, 1, 2, f) == 2 && b[0] == 0xFE && b[1] == 0xFF)
+ {
+ return cmListFileLexer_BOM_UTF32BE;
+ }
+ }
+ else if(b[0] == 0xFF && b[1] == 0xFE)
+ {
+ fpos_t p;
+ fgetpos(f, &p);
+ if(fread(b, 1, 2, f) == 2 && b[0] == 0 && b[1] == 0)
+ {
+ return cmListFileLexer_BOM_UTF32LE;
+ }
+ fsetpos(f, &p);
+ return cmListFileLexer_BOM_UTF16LE;
+ }
+ }
+ rewind(f);
+ return cmListFileLexer_BOM_None;
+}
+
+/*--------------------------------------------------------------------------*/
+int cmListFileLexer_SetFileName(cmListFileLexer* lexer, const char* name,
+ cmListFileLexer_BOM* bom)
+{
+ int result = 1;
+ cmListFileLexerDestroy(lexer);
+ if(name)
+ {
+#ifdef _WIN32
+ wchar_t* wname = cmsysEncoding_DupToWide(name);
+ lexer->file = _wfopen(wname, L"rb");
+ free(wname);
+#else
+ lexer->file = fopen(name, "rb");
+#endif
+ if(lexer->file)
+ {
+ if(bom)
+ {
+ *bom = cmListFileLexer_ReadBOM(lexer->file);
+ }
+ }
+ else
+ {
+ result = 0;
+ }
+ }
+ cmListFileLexerInit(lexer);
+ return result;
+}
+
+/*--------------------------------------------------------------------------*/
+int cmListFileLexer_SetString(cmListFileLexer* lexer, const char* text)
+{
+ int result = 1;
+ cmListFileLexerDestroy(lexer);
+ if(text)
+ {
+ int length = (int)strlen(text);
+ lexer->string_buffer = (char*)malloc(length+1);
+ if(lexer->string_buffer)
+ {
+ strcpy(lexer->string_buffer, text);
+ lexer->string_position = lexer->string_buffer;
+ lexer->string_left = length;
+ }
+ else
+ {
+ result = 0;
+ }
+ }
+ cmListFileLexerInit(lexer);
+ return result;
+}
+
+/*--------------------------------------------------------------------------*/
+cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer* lexer)
+{
+ if(!lexer->file)
+ {
+ return 0;
+ }
+ if(cmListFileLexer_yylex(lexer->scanner, lexer))
+ {
+ return &lexer->token;
+ }
+ else
+ {
+ cmListFileLexer_SetFileName(lexer, 0, 0);
+ return 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+long cmListFileLexer_GetCurrentLine(cmListFileLexer* lexer)
+{
+ if(lexer->file)
+ {
+ return lexer->line;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+long cmListFileLexer_GetCurrentColumn(cmListFileLexer* lexer)
+{
+ if(lexer->file)
+ {
+ return lexer->column;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer,
+ cmListFileLexer_Type type)
+{
+ (void)lexer;
+ switch(type)
+ {
+ case cmListFileLexer_Token_None: return "nothing";
+ case cmListFileLexer_Token_Space: return "space";
+ case cmListFileLexer_Token_Newline: return "newline";
+ case cmListFileLexer_Token_Identifier: return "identifier";
+ case cmListFileLexer_Token_ParenLeft: return "left paren";
+ case cmListFileLexer_Token_ParenRight: return "right paren";
+ case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument";
+ case cmListFileLexer_Token_ArgumentQuoted: return "quoted argument";
+ case cmListFileLexer_Token_ArgumentBracket: return "bracket argument";
+ case cmListFileLexer_Token_CommentBracket: return "bracket comment";
+ case cmListFileLexer_Token_BadCharacter: return "bad character";
+ case cmListFileLexer_Token_BadBracket: return "unterminated bracket";
+ case cmListFileLexer_Token_BadString: return "unterminated string";
+ }
+ return "unknown token";
+}
diff --git a/Source/cmLoadCacheCommand.cxx b/Source/cmLoadCacheCommand.cxx
new file mode 100644
index 0000000000..427e29df60
--- /dev/null
+++ b/Source/cmLoadCacheCommand.cxx
@@ -0,0 +1,197 @@
+/*============================================================================
+ 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 "cmLoadCacheCommand.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/FStream.hxx>
+
+// cmLoadCacheCommand
+bool cmLoadCacheCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if (args.size()< 1)
+ {
+ this->SetError("called with wrong number of arguments.");
+ }
+
+ if(args.size() >= 2 && args[1] == "READ_WITH_PREFIX")
+ {
+ return this->ReadWithPrefix(args);
+ }
+
+ // Cache entries to be excluded from the import list.
+ // If this set is empty, all cache entries are brought in
+ // and they can not be overridden.
+ bool excludeFiles=false;
+ unsigned int i;
+ std::set<std::string> excludes;
+
+ for(i=0; i<args.size(); i++)
+ {
+ if (excludeFiles)
+ {
+ excludes.insert(args[i]);
+ }
+ if (args[i] == "EXCLUDE")
+ {
+ excludeFiles=true;
+ }
+ if (excludeFiles && (args[i] == "INCLUDE_INTERNALS"))
+ {
+ break;
+ }
+ }
+
+ // Internal cache entries to be imported.
+ // If this set is empty, no internal cache entries are
+ // brought in.
+ bool includeFiles=false;
+ std::set<std::string> includes;
+
+ for(i=0; i<args.size(); i++)
+ {
+ if (includeFiles)
+ {
+ includes.insert(args[i]);
+ }
+ if (args[i] == "INCLUDE_INTERNALS")
+ {
+ includeFiles=true;
+ }
+ if (includeFiles && (args[i] == "EXCLUDE"))
+ {
+ break;
+ }
+ }
+
+ // Loop over each build directory listed in the arguments. Each
+ // directory has a cache file.
+ for(i=0; i<args.size(); i++)
+ {
+ if ((args[i] == "EXCLUDE") || (args[i] == "INCLUDE_INTERNALS"))
+ {
+ break;
+ }
+ this->Makefile->GetCacheManager()->LoadCache(args[i], false,
+ excludes, includes);
+ }
+
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args)
+{
+ // Make sure we have a prefix.
+ if(args.size() < 3)
+ {
+ this->SetError("READ_WITH_PREFIX form must specify a prefix.");
+ return false;
+ }
+
+ // Make sure the cache file exists.
+ std::string cacheFile = args[0]+"/CMakeCache.txt";
+ if(!cmSystemTools::FileExists(cacheFile.c_str()))
+ {
+ std::string e = "Cannot load cache file from " + cacheFile;
+ this->SetError(e);
+ return false;
+ }
+
+ // Prepare the table of variables to read.
+ this->Prefix = args[2];
+ for(unsigned int i=3; i < args.size(); ++i)
+ {
+ this->VariablesToRead.insert(args[i]);
+ }
+
+ // Read the cache file.
+ cmsys::ifstream fin(cacheFile.c_str());
+
+ // This is a big hack read loop to overcome a buggy ifstream
+ // implementation on HP-UX. This should work on all platforms even
+ // for small buffer sizes.
+ const int bufferSize = 4096;
+ char buffer[bufferSize];
+ std::string line;
+ while(fin)
+ {
+ // Read a block of the file.
+ fin.read(buffer, bufferSize);
+ if(fin.gcount())
+ {
+ // Parse for newlines directly.
+ const char* i = buffer;
+ const char* end = buffer+fin.gcount();
+ while(i != end)
+ {
+ const char* begin = i;
+ while(i != end && *i != '\n') { ++i; }
+ if(i == begin || *(i-1) != '\r')
+ {
+ // Include this portion of the line.
+ line += std::string(begin, i-begin);
+ }
+ else
+ {
+ // Include this portion of the line.
+ // Don't include the \r in a \r\n pair.
+ line += std::string(begin, i-1-begin);
+ }
+ if(i != end)
+ {
+ // Completed a line.
+ this->CheckLine(line.c_str());
+ line = "";
+
+ // Skip the newline character.
+ ++i;
+ }
+ }
+ }
+ }
+ if(line.length())
+ {
+ // Partial last line.
+ this->CheckLine(line.c_str());
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmLoadCacheCommand::CheckLine(const char* line)
+{
+ // Check one line of the cache file.
+ std::string var;
+ std::string value;
+ cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
+ if(cmCacheManager::ParseEntry(line, var, value, type))
+ {
+ // Found a real entry. See if this one was requested.
+ if(this->VariablesToRead.find(var) != this->VariablesToRead.end())
+ {
+ // This was requested. Set this variable locally with the given
+ // prefix.
+ var = this->Prefix + var;
+ if(value.length())
+ {
+ this->Makefile->AddDefinition(var, value.c_str());
+ }
+ else
+ {
+ this->Makefile->RemoveDefinition(var);
+ }
+ }
+ }
+}
diff --git a/Source/cmLoadCacheCommand.h b/Source/cmLoadCacheCommand.h
new file mode 100644
index 0000000000..04207d0dd0
--- /dev/null
+++ b/Source/cmLoadCacheCommand.h
@@ -0,0 +1,56 @@
+/*============================================================================
+ 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 cmLoadCacheCommand_h
+#define cmLoadCacheCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmLoadCacheCommand
+ * \brief load a cache file
+ *
+ * cmLoadCacheCommand loads the non internal values of a cache file
+ */
+class cmLoadCacheCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmLoadCacheCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "load_cache";}
+
+ cmTypeMacro(cmLoadCacheCommand, cmCommand);
+protected:
+
+ std::set<std::string> VariablesToRead;
+ std::string Prefix;
+
+ bool ReadWithPrefix(std::vector<std::string> const& args);
+ void CheckLine(const char* line);
+};
+
+
+#endif
diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx
new file mode 100644
index 0000000000..a4063a680d
--- /dev/null
+++ b/Source/cmLoadCommandCommand.cxx
@@ -0,0 +1,283 @@
+/*============================================================================
+ 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 "cmLoadCommandCommand.h"
+#include "cmCPluginAPI.h"
+#include "cmCPluginAPI.cxx"
+#include "cmDynamicLoader.h"
+
+#include <cmsys/DynamicLoader.hxx>
+
+#include <stdlib.h>
+
+#ifdef __QNX__
+# include <malloc.h> /* for malloc/free on QNX */
+#endif
+
+#include <signal.h>
+extern "C" void TrapsForSignalsCFunction(int sig);
+
+
+// a class for loadabple commands
+class cmLoadedCommand : public cmCommand
+{
+public:
+ cmLoadedCommand() {
+ memset(&this->info,0,sizeof(this->info));
+ this->info.CAPI = &cmStaticCAPI;
+ }
+
+ ///! clean up any memory allocated by the plugin
+ ~cmLoadedCommand();
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmLoadedCommand *newC = new cmLoadedCommand;
+ // we must copy when we clone
+ memcpy(&newC->info,&this->info,sizeof(info));
+ return newC;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &);
+
+ /**
+ * This is called at the end after all the information
+ * specified by the command is accumulated. Most commands do
+ * not implement this method. At this point, reading and
+ * writing to the cache can be done.
+ */
+ virtual void FinalPass();
+ virtual bool HasFinalPass() const
+ { return this->info.FinalPass? true:false; }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return info.Name; }
+
+ static const char* LastName;
+ static void TrapsForSignals(int sig)
+ {
+ fprintf(stderr, "CMake loaded command %s crashed with signal: %d.\n",
+ cmLoadedCommand::LastName, sig);
+ }
+ static void InstallSignalHandlers(const char* name, int remove = 0)
+ {
+ cmLoadedCommand::LastName = name;
+ if(!name)
+ {
+ cmLoadedCommand::LastName = "????";
+ }
+
+ if(!remove)
+ {
+ signal(SIGSEGV, TrapsForSignalsCFunction);
+#ifdef SIGBUS
+ signal(SIGBUS, TrapsForSignalsCFunction);
+#endif
+ signal(SIGILL, TrapsForSignalsCFunction);
+ }
+ else
+ {
+ signal(SIGSEGV, 0);
+#ifdef SIGBUS
+ signal(SIGBUS, 0);
+#endif
+ signal(SIGILL, 0);
+ }
+ }
+
+ cmTypeMacro(cmLoadedCommand, cmCommand);
+
+ cmLoadedCommandInfo info;
+};
+
+extern "C" void TrapsForSignalsCFunction(int sig)
+{
+ cmLoadedCommand::TrapsForSignals(sig);
+}
+
+
+const char* cmLoadedCommand::LastName = 0;
+
+bool cmLoadedCommand::InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &)
+{
+ if (!info.InitialPass)
+ {
+ return true;
+ }
+
+ // clear the error string
+ if (this->info.Error)
+ {
+ free(this->info.Error);
+ }
+
+ // create argc and argv and then invoke the command
+ int argc = static_cast<int> (args.size());
+ char **argv = 0;
+ if (argc)
+ {
+ argv = (char **)malloc(argc*sizeof(char *));
+ }
+ int i;
+ for (i = 0; i < argc; ++i)
+ {
+ argv[i] = strdup(args[i].c_str());
+ }
+ cmLoadedCommand::InstallSignalHandlers(info.Name);
+ int result = info.InitialPass((void *)&info,
+ (void *)this->Makefile,argc,argv);
+ cmLoadedCommand::InstallSignalHandlers(info.Name, 1);
+ cmFreeArguments(argc,argv);
+
+ if (result)
+ {
+ return true;
+ }
+
+ /* Initial Pass must have failed so set the error string */
+ if (this->info.Error)
+ {
+ this->SetError(this->info.Error);
+ }
+ return false;
+}
+
+void cmLoadedCommand::FinalPass()
+{
+ if (this->info.FinalPass)
+ {
+ cmLoadedCommand::InstallSignalHandlers(info.Name);
+ this->info.FinalPass((void *)&this->info,(void *)this->Makefile);
+ cmLoadedCommand::InstallSignalHandlers(info.Name, 1);
+ }
+}
+
+cmLoadedCommand::~cmLoadedCommand()
+{
+ if (this->info.Destructor)
+ {
+ cmLoadedCommand::InstallSignalHandlers(info.Name);
+ this->info.Destructor((void *)&this->info);
+ cmLoadedCommand::InstallSignalHandlers(info.Name, 1);
+ }
+ if (this->info.Error)
+ {
+ free(this->info.Error);
+ }
+}
+
+// cmLoadCommandCommand
+bool cmLoadCommandCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(this->Disallowed(cmPolicies::CMP0031,
+ "The load_command command should not be called; see CMP0031."))
+ { return true; }
+ if(args.size() < 1 )
+ {
+ return true;
+ }
+
+ // Construct a variable to report what file was loaded, if any.
+ // Start by removing the definition in case of failure.
+ std::string reportVar = "CMAKE_LOADED_COMMAND_";
+ reportVar += args[0];
+ this->Makefile->RemoveDefinition(reportVar);
+
+ // the file must exist
+ std::string moduleName =
+ this->Makefile->GetRequiredDefinition("CMAKE_SHARED_MODULE_PREFIX");
+ moduleName += "cm" + args[0];
+ moduleName +=
+ this->Makefile->GetRequiredDefinition("CMAKE_SHARED_MODULE_SUFFIX");
+
+ // search for the file
+ std::vector<std::string> path;
+ for (unsigned int j = 1; j < args.size(); j++)
+ {
+ // expand variables
+ std::string exp = args[j];
+ cmSystemTools::ExpandRegistryValues(exp);
+
+ // Glob the entry in case of wildcards.
+ cmSystemTools::GlobDirs(exp, path);
+ }
+
+ // Try to find the program.
+ std::string fullPath = cmSystemTools::FindFile(moduleName.c_str(), path);
+ if (fullPath == "")
+ {
+ cmOStringStream e;
+ e << "Attempt to load command failed from file \""
+ << moduleName << "\"";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // try loading the shared library / dll
+ cmsys::DynamicLoader::LibraryHandle lib
+ = cmDynamicLoader::OpenLibrary(fullPath.c_str());
+ if(!lib)
+ {
+ std::string err = "Attempt to load the library ";
+ err += fullPath + " failed.";
+ const char* error = cmsys::DynamicLoader::LastError();
+ if ( error )
+ {
+ err += " Additional error info is:\n";
+ err += error;
+ }
+ this->SetError(err);
+ return false;
+ }
+
+ // Report what file was loaded for this command.
+ this->Makefile->AddDefinition(reportVar, fullPath.c_str());
+
+ // find the init function
+ std::string initFuncName = args[0] + "Init";
+ CM_INIT_FUNCTION initFunction
+ = (CM_INIT_FUNCTION)
+ cmsys::DynamicLoader::GetSymbolAddress(lib, initFuncName.c_str());
+ if ( !initFunction )
+ {
+ initFuncName = "_";
+ initFuncName += args[0];
+ initFuncName += "Init";
+ initFunction = (CM_INIT_FUNCTION)(
+ cmsys::DynamicLoader::GetSymbolAddress(lib, initFuncName.c_str()));
+ }
+ // if the symbol is found call it to set the name on the
+ // function blocker
+ if(initFunction)
+ {
+ // create a function blocker and set it up
+ cmLoadedCommand *f = new cmLoadedCommand();
+ (*initFunction)(&f->info);
+ this->Makefile->AddCommand(f);
+ return true;
+ }
+ this->SetError("Attempt to load command failed. "
+ "No init function found.");
+ return false;
+}
+
diff --git a/Source/cmLoadCommandCommand.h b/Source/cmLoadCommandCommand.h
new file mode 100644
index 0000000000..45812694f4
--- /dev/null
+++ b/Source/cmLoadCommandCommand.h
@@ -0,0 +1,30 @@
+/*============================================================================
+ 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 cmLoadCommandCommand_h
+#define cmLoadCommandCommand_h
+
+#include "cmCommand.h"
+
+class cmLoadCommandCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone() { return new cmLoadCommandCommand; }
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+ virtual std::string GetName() const {return "load_command";}
+ virtual bool IsDiscouraged() const { return true; }
+ cmTypeMacro(cmLoadCommandCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
new file mode 100644
index 0000000000..50e279b483
--- /dev/null
+++ b/Source/cmLocalGenerator.cxx
@@ -0,0 +1,3754 @@
+/*============================================================================
+ 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 "cmLocalGenerator.h"
+
+#include "cmComputeLinkInformation.h"
+#include "cmGeneratedFileStream.h"
+#include "cmGlobalGenerator.h"
+#include "cmInstallGenerator.h"
+#include "cmInstallFilesGenerator.h"
+#include "cmInstallScriptGenerator.h"
+#include "cmInstallTargetGenerator.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmTest.h"
+#include "cmTestGenerator.h"
+#include "cmCustomCommandGenerator.h"
+#include "cmVersion.h"
+#include "cmake.h"
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# define CM_LG_ENCODE_OBJECT_NAMES
+# include <cmsys/MD5.h>
+#endif
+
+#include <cmsys/System.h>
+
+#include <ctype.h> // for isalpha
+
+#include <assert.h>
+
+#if defined(__HAIKU__)
+#include <FindDirectory.h>
+#include <StorageDefs.h>
+#endif
+
+cmLocalGenerator::cmLocalGenerator()
+{
+ this->Makefile = 0; // moved to after set on global
+ this->Parent = 0;
+ this->WindowsShell = false;
+ this->WindowsVSIDE = false;
+ this->WatcomWMake = false;
+ this->MinGWMake = false;
+ this->NMake = false;
+ this->MSYSShell = false;
+ this->LinkScriptShell = false;
+ this->IgnoreLibPrefix = false;
+ this->UseRelativePaths = false;
+ this->Configured = false;
+ this->EmitUniversalBinaryFlags = true;
+ this->RelativePathsConfigured = false;
+ this->PathConversionsSetup = false;
+ this->BackwardsCompatibility = 0;
+ this->BackwardsCompatibilityFinal = false;
+}
+
+cmLocalGenerator::~cmLocalGenerator()
+{
+ delete this->Makefile;
+}
+
+//----------------------------------------------------------------------------
+class cmLocalGeneratorCurrent
+{
+ cmGlobalGenerator* GG;
+ cmLocalGenerator* LG;
+public:
+ cmLocalGeneratorCurrent(cmLocalGenerator* lg)
+ {
+ this->GG = lg->GetGlobalGenerator();
+ this->LG = this->GG->GetCurrentLocalGenerator();
+ this->GG->SetCurrentLocalGenerator(lg);
+ }
+ ~cmLocalGeneratorCurrent()
+ {
+ this->GG->SetCurrentLocalGenerator(this->LG);
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::Configure()
+{
+ // Manage the global generator's current local generator.
+ cmLocalGeneratorCurrent clg(this);
+ static_cast<void>(clg);
+
+ // make sure the CMakeFiles dir is there
+ std::string filesDir = this->Makefile->GetStartOutputDirectory();
+ filesDir += cmake::GetCMakeFilesDirectory();
+ cmSystemTools::MakeDirectory(filesDir.c_str());
+
+ // find & read the list file
+ this->ReadInputFile();
+
+ // at the end of the ReadListFile handle any old style subdirs
+ // first get all the subdirectories
+ std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
+
+ // for each subdir recurse
+ std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
+ for (; sdi != subdirs.end(); ++sdi)
+ {
+ if (!(*sdi)->Configured)
+ {
+ this->Makefile->ConfigureSubDirectory(*sdi);
+ }
+ }
+
+ this->Makefile->AddCMakeDependFilesFromUser();
+
+ // Check whether relative paths should be used for optionally
+ // relative paths.
+ this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
+
+ this->ComputeObjectMaxPath();
+
+ this->Configured = true;
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::ComputeObjectMaxPath()
+{
+ // Choose a maximum object file name length.
+#if defined(_WIN32) || defined(__CYGWIN__)
+ this->ObjectPathMax = 250;
+#else
+ this->ObjectPathMax = 1000;
+#endif
+ const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
+ if(plen && *plen)
+ {
+ unsigned int pmax;
+ if(sscanf(plen, "%u", &pmax) == 1)
+ {
+ if(pmax >= 128)
+ {
+ this->ObjectPathMax = pmax;
+ }
+ else
+ {
+ cmOStringStream w;
+ w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
+ << ", which is less than the minimum of 128. "
+ << "The value will be ignored.";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }
+ }
+ else
+ {
+ cmOStringStream w;
+ w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
+ << "\", which fails to parse as a positive integer. "
+ << "The value will be ignored.";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }
+ }
+ this->ObjectMaxPathViolations.clear();
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::ReadInputFile()
+{
+ // Look for the CMakeLists.txt file.
+ std::string currentStart = this->Makefile->GetStartDirectory();
+ currentStart += "/CMakeLists.txt";
+ if(cmSystemTools::FileExists(currentStart.c_str(), true))
+ {
+ this->Makefile->ReadListFile(currentStart.c_str());
+ return;
+ }
+
+ if(!this->Parent)
+ {
+ return;
+ }
+
+ // The file is missing. Check policy CMP0014.
+ cmMakefile* mf = this->Parent->GetMakefile();
+ cmOStringStream e;
+ e << "The source directory\n"
+ << " " << this->Makefile->GetStartDirectory() << "\n"
+ << "does not contain a CMakeLists.txt file.";
+ switch (mf->GetPolicyStatus(cmPolicies::CMP0014))
+ {
+ case cmPolicies::WARN:
+ // Print the warning.
+ e << "\n"
+ << "CMake does not support this case but it used "
+ << "to work accidentally and is being allowed for "
+ << "compatibility."
+ << "\n"
+ << mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0014);
+ mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ case cmPolicies::OLD:
+ // OLD behavior does not warn.
+ return;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ e << "\n"
+ << mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0014);
+ case cmPolicies::NEW:
+ // NEW behavior prints the error.
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ break;
+ }
+}
+
+void cmLocalGenerator::SetupPathConversions()
+{
+ // Setup the current output directory components for use by
+ // Convert
+ std::string outdir;
+ outdir =
+ cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
+ cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
+ outdir =
+ cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
+ cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
+
+ outdir = cmSystemTools::CollapseFullPath
+ (this->Makefile->GetHomeOutputDirectory());
+ cmSystemTools::SplitPath(outdir.c_str(),
+ this->HomeOutputDirectoryComponents);
+
+ outdir = cmSystemTools::CollapseFullPath
+ (this->Makefile->GetStartOutputDirectory());
+ cmSystemTools::SplitPath(outdir.c_str(),
+ this->StartOutputDirectoryComponents);
+}
+
+
+void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
+{
+ this->GlobalGenerator = gg;
+ this->Makefile = new cmMakefile;
+ this->Makefile->SetLocalGenerator(this);
+
+ // setup the home directories
+ this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
+ this->Makefile->SetHomeDirectory(
+ gg->GetCMakeInstance()->GetHomeDirectory());
+ this->Makefile->SetHomeOutputDirectory(
+ gg->GetCMakeInstance()->GetHomeOutputDirectory());
+}
+
+void cmLocalGenerator::ConfigureFinalPass()
+{
+ this->Makefile->ConfigureFinalPass();
+}
+
+void cmLocalGenerator::TraceDependencies()
+{
+ // Generate the rule files for each target.
+ cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
+ for(cmGeneratorTargetsType::iterator t = targets.begin();
+ t != targets.end(); ++t)
+ {
+ if (t->second->Target->IsImported()
+ || t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ t->second->TraceDependencies();
+ }
+}
+
+void cmLocalGenerator::GenerateTestFiles()
+{
+ if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
+ {
+ return;
+ }
+
+ // Compute the set of configurations.
+ std::vector<std::string> configurationTypes;
+ const std::string& config =
+ this->Makefile->GetConfigurations(configurationTypes, false);
+
+ std::string file = this->Makefile->GetStartOutputDirectory();
+ file += "/";
+ file += "CTestTestfile.cmake";
+
+ cmGeneratedFileStream fout(file.c_str());
+ fout.SetCopyIfDifferent(true);
+
+ fout << "# CMake generated Testfile for " << std::endl
+ << "# Source directory: "
+ << this->Makefile->GetStartDirectory() << std::endl
+ << "# Build directory: "
+ << this->Makefile->GetStartOutputDirectory() << std::endl
+ << "# " << std::endl
+ << "# This file includes the relevant testing commands "
+ << "required for " << std::endl
+ << "# testing this directory and lists subdirectories to "
+ << "be tested as well." << std::endl;
+
+ const char* testIncludeFile =
+ this->Makefile->GetProperty("TEST_INCLUDE_FILE");
+ if ( testIncludeFile )
+ {
+ fout << "include(\"" << testIncludeFile << "\")" << std::endl;
+ }
+
+ // Ask each test generator to write its code.
+ std::vector<cmTestGenerator*> const&
+ testers = this->Makefile->GetTestGenerators();
+ for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
+ gi != testers.end(); ++gi)
+ {
+ (*gi)->Generate(fout, config, configurationTypes);
+ }
+ if ( this->Children.size())
+ {
+ size_t i;
+ for(i = 0; i < this->Children.size(); ++i)
+ {
+ // TODO: Use add_subdirectory instead?
+ fout << "subdirs(";
+ std::string outP =
+ this->Children[i]->GetMakefile()->GetStartOutputDirectory();
+ fout << this->Convert(outP,START_OUTPUT);
+ fout << ")" << std::endl;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::GenerateInstallRules()
+{
+ // Compute the install prefix.
+ const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ std::string prefix_win32;
+ if(!prefix)
+ {
+ if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
+ {
+ prefix_win32 = "C:";
+ }
+ const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
+ if(project_name && project_name[0])
+ {
+ prefix_win32 += "/Program Files/";
+ prefix_win32 += project_name;
+ }
+ else
+ {
+ prefix_win32 += "/InstalledCMakeProject";
+ }
+ prefix = prefix_win32.c_str();
+ }
+#elif defined(__HAIKU__)
+ char dir[B_PATH_NAME_LENGTH];
+ if (!prefix)
+ {
+ if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir))
+ == B_OK)
+ {
+ prefix = dir;
+ }
+ else
+ {
+ prefix = "/boot/system";
+ }
+ }
+#else
+ if (!prefix)
+ {
+ prefix = "/usr/local";
+ }
+#endif
+ if (const char *stagingPrefix
+ = this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX"))
+ {
+ prefix = stagingPrefix;
+ }
+
+ // Compute the set of configurations.
+ std::vector<std::string> configurationTypes;
+ const std::string& config =
+ this->Makefile->GetConfigurations(configurationTypes, false);
+
+ // Choose a default install configuration.
+ const char* default_config = config.c_str();
+ const char* default_order[] = {"RELEASE", "MINSIZEREL",
+ "RELWITHDEBINFO", "DEBUG", 0};
+ for(const char** c = default_order; *c && !default_config; ++c)
+ {
+ for(std::vector<std::string>::iterator i = configurationTypes.begin();
+ i != configurationTypes.end(); ++i)
+ {
+ if(cmSystemTools::UpperCase(*i) == *c)
+ {
+ default_config = i->c_str();
+ }
+ }
+ }
+ if(!default_config && !configurationTypes.empty())
+ {
+ default_config = configurationTypes[0].c_str();
+ }
+ if(!default_config)
+ {
+ default_config = "Release";
+ }
+
+ // Create the install script file.
+ std::string file = this->Makefile->GetStartOutputDirectory();
+ std::string homedir = this->Makefile->GetHomeOutputDirectory();
+ std::string currdir = this->Makefile->GetCurrentOutputDirectory();
+ cmSystemTools::ConvertToUnixSlashes(file);
+ cmSystemTools::ConvertToUnixSlashes(homedir);
+ cmSystemTools::ConvertToUnixSlashes(currdir);
+ int toplevel_install = 0;
+ if ( currdir == homedir )
+ {
+ toplevel_install = 1;
+ }
+ file += "/cmake_install.cmake";
+ cmGeneratedFileStream fout(file.c_str());
+ fout.SetCopyIfDifferent(true);
+
+ // Write the header.
+ fout << "# Install script for directory: "
+ << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
+ fout << "# Set the install prefix" << std::endl
+ << "if(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
+ << " set(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
+ << "endif()" << std::endl
+ << "string(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
+ << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
+ << std::endl;
+
+ // Write support code for generating per-configuration install rules.
+ fout <<
+ "# Set the install configuration name.\n"
+ "if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
+ " if(BUILD_TYPE)\n"
+ " string(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
+ " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
+ " else()\n"
+ " set(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
+ " endif()\n"
+ " message(STATUS \"Install configuration: "
+ "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
+ "endif()\n"
+ "\n";
+
+ // Write support code for dealing with component-specific installs.
+ fout <<
+ "# Set the component getting installed.\n"
+ "if(NOT CMAKE_INSTALL_COMPONENT)\n"
+ " if(COMPONENT)\n"
+ " message(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
+ " set(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
+ " else()\n"
+ " set(CMAKE_INSTALL_COMPONENT)\n"
+ " endif()\n"
+ "endif()\n"
+ "\n";
+
+ // Copy user-specified install options to the install code.
+ if(const char* so_no_exe =
+ this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
+ {
+ fout <<
+ "# Install shared libraries without execute permission?\n"
+ "if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
+ " set(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
+ "endif()\n"
+ "\n";
+ }
+
+ // Ask each install generator to write its code.
+ std::vector<cmInstallGenerator*> const& installers =
+ this->Makefile->GetInstallGenerators();
+ for(std::vector<cmInstallGenerator*>::const_iterator
+ gi = installers.begin();
+ gi != installers.end(); ++gi)
+ {
+ (*gi)->Generate(fout, config, configurationTypes);
+ }
+
+ // Write rules from old-style specification stored in targets.
+ this->GenerateTargetInstallRules(fout, config, configurationTypes);
+
+ // Include install scripts from subdirectories.
+ if(!this->Children.empty())
+ {
+ fout << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
+ fout << " # Include the install script for each subdirectory.\n";
+ for(std::vector<cmLocalGenerator*>::const_iterator
+ ci = this->Children.begin(); ci != this->Children.end(); ++ci)
+ {
+ if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+ {
+ std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
+ cmSystemTools::ConvertToUnixSlashes(odir);
+ fout << " include(\"" << odir
+ << "/cmake_install.cmake\")" << std::endl;
+ }
+ }
+ fout << "\n";
+ fout << "endif()\n\n";
+ }
+
+ // Record the install manifest.
+ if ( toplevel_install )
+ {
+ fout <<
+ "if(CMAKE_INSTALL_COMPONENT)\n"
+ " set(CMAKE_INSTALL_MANIFEST \"install_manifest_"
+ "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
+ "else()\n"
+ " set(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
+ "endif()\n\n";
+ fout
+ << "file(WRITE \""
+ << homedir << "/${CMAKE_INSTALL_MANIFEST}\" "
+ << "\"\")" << std::endl;
+ fout
+ << "foreach(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
+ << " file(APPEND \""
+ << homedir << "/${CMAKE_INSTALL_MANIFEST}\" "
+ << "\"${file}\\n\")" << std::endl
+ << "endforeach()" << std::endl;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::GenerateTargetManifest()
+{
+ // Collect the set of configuration types.
+ std::vector<std::string> configNames;
+ this->Makefile->GetConfigurations(configNames);
+ if(configNames.empty())
+ {
+ configNames.push_back("");
+ }
+
+ // Add our targets to the manifest for each configuration.
+ cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
+ for(cmGeneratorTargetsType::iterator t = targets.begin();
+ t != targets.end(); ++t)
+ {
+ cmGeneratorTarget& target = *t->second;
+ if (target.Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ if (target.Target->IsImported())
+ {
+ continue;
+ }
+ for(std::vector<std::string>::iterator ci = configNames.begin();
+ ci != configNames.end(); ++ci)
+ {
+ const char* config = ci->c_str();
+ target.GenerateTargetManifest(config);
+ }
+ }
+}
+
+void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
+ const std::string& lang,
+ cmSourceFile& source,
+ cmGeneratorTarget& target)
+{
+ std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
+ objectDir = this->Convert(objectDir,START_OUTPUT,SHELL);
+ std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
+ std::string sourceFile =
+ this->Convert(source.GetFullPath(),START_OUTPUT,SHELL,true);
+ std::string varString = "CMAKE_";
+ varString += lang;
+ varString += "_COMPILE_OBJECT";
+ std::vector<std::string> rules;
+ rules.push_back(this->Makefile->GetRequiredDefinition(varString));
+ varString = "CMAKE_";
+ varString += lang;
+ varString += "_FLAGS";
+ std::string flags;
+ flags += this->Makefile->GetSafeDefinition(varString);
+ flags += " ";
+ {
+ std::vector<std::string> includes;
+ this->GetIncludeDirectories(includes, &target, lang);
+ flags += this->GetIncludeFlags(includes, &target, lang);
+ }
+ flags += this->Makefile->GetDefineFlags();
+
+ // Construct the command lines.
+ cmCustomCommandLines commandLines;
+ std::vector<std::string> commands;
+ cmSystemTools::ExpandList(rules, commands);
+ cmLocalGenerator::RuleVariables vars;
+ vars.Language = lang.c_str();
+ vars.Source = sourceFile.c_str();
+ vars.Object = objectFile.c_str();
+ vars.ObjectDir = objectDir.c_str();
+ vars.Flags = flags.c_str();
+ for(std::vector<std::string>::iterator i = commands.begin();
+ i != commands.end(); ++i)
+ {
+ // Expand the full command line string.
+ this->ExpandRuleVariables(*i, vars);
+
+ // Parse the string to get the custom command line.
+ cmCustomCommandLine commandLine;
+ std::vector<std::string> cmd = cmSystemTools::ParseArguments(i->c_str());
+ for(std::vector<std::string>::iterator a = cmd.begin();
+ a != cmd.end(); ++a)
+ {
+ commandLine.push_back(*a);
+ }
+
+ // Store this command line.
+ commandLines.push_back(commandLine);
+ }
+
+ // Check for extra object-file dependencies.
+ std::vector<std::string> depends;
+ const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
+ if(additionalDeps)
+ {
+ cmSystemTools::ExpandListArgument(additionalDeps, depends);
+ }
+
+ // Generate a meaningful comment for the command.
+ std::string comment = "Building ";
+ comment += lang;
+ comment += " object ";
+ comment += this->Convert(ofname, START_OUTPUT);
+
+ // Add the custom command to build the object file.
+ this->Makefile->AddCustomCommandToOutput(
+ ofname,
+ depends,
+ source.GetFullPath(),
+ commandLines,
+ comment.c_str(),
+ this->Makefile->GetStartOutputDirectory()
+ );
+}
+
+void cmLocalGenerator::AddBuildTargetRule(const std::string& llang,
+ cmGeneratorTarget& target)
+{
+ std::string objs;
+ std::vector<std::string> objVector;
+ std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ // Add all the sources outputs to the depends of the target
+ std::vector<cmSourceFile*> classes;
+ target.GetSourceFiles(classes, config);
+ for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
+ i != classes.end(); ++i)
+ {
+ cmSourceFile* sf = *i;
+ if(!sf->GetCustomCommand() &&
+ !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
+ !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
+ {
+ std::string dir_max;
+ dir_max += this->Makefile->GetCurrentOutputDirectory();
+ dir_max += "/";
+ std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
+ if(!obj.empty())
+ {
+ std::string ofname = this->Makefile->GetCurrentOutputDirectory();
+ ofname += "/";
+ ofname += obj;
+ objVector.push_back(ofname);
+ this->AddCustomCommandToCreateObject(ofname.c_str(),
+ llang, *(*i), target);
+ objs += this->Convert(ofname,START_OUTPUT,SHELL);
+ objs += " ";
+ }
+ }
+ }
+ std::string createRule = target.GetCreateRuleVariable(llang, config);
+ bool useWatcomQuote = this->Makefile->IsOn(createRule+"_USE_WATCOM_QUOTE");
+ std::string targetName = target.Target->GetFullName();
+ // Executable :
+ // Shared Library:
+ // Static Library:
+ // Shared Module:
+ std::string linkLibs; // should be set
+ std::string frameworkPath;
+ std::string linkPath;
+ std::string flags; // should be set
+ std::string linkFlags; // should be set
+ this->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags,
+ &target, useWatcomQuote);
+ linkLibs = frameworkPath + linkPath + linkLibs;
+ cmLocalGenerator::RuleVariables vars;
+ vars.Language = llang.c_str();
+ vars.Objects = objs.c_str();
+ vars.ObjectDir = ".";
+ vars.Target = targetName.c_str();
+ vars.LinkLibraries = linkLibs.c_str();
+ vars.Flags = flags.c_str();
+ vars.LinkFlags = linkFlags.c_str();
+
+ std::string langFlags;
+ this->AddLanguageFlags(langFlags, llang, "");
+ this->AddArchitectureFlags(langFlags, &target, llang, "");
+ vars.LanguageCompileFlags = langFlags.c_str();
+
+ cmCustomCommandLines commandLines;
+ std::vector<std::string> rules;
+ rules.push_back(this->Makefile->GetRequiredDefinition(createRule));
+ std::vector<std::string> commands;
+ cmSystemTools::ExpandList(rules, commands);
+ for(std::vector<std::string>::iterator i = commands.begin();
+ i != commands.end(); ++i)
+ {
+ // Expand the full command line string.
+ this->ExpandRuleVariables(*i, vars);
+ // Parse the string to get the custom command line.
+ cmCustomCommandLine commandLine;
+ std::vector<std::string> cmd = cmSystemTools::ParseArguments(i->c_str());
+ for(std::vector<std::string>::iterator a = cmd.begin();
+ a != cmd.end(); ++a)
+ {
+ commandLine.push_back(*a);
+ }
+
+ // Store this command line.
+ commandLines.push_back(commandLine);
+ }
+ std::string targetFullPath = target.Target->GetFullPath();
+ // Generate a meaningful comment for the command.
+ std::string comment = "Linking ";
+ comment += llang;
+ comment += " target ";
+ comment += this->Convert(targetFullPath, START_OUTPUT);
+ this->Makefile->AddCustomCommandToOutput(
+ targetFullPath,
+ objVector,
+ "",
+ commandLines,
+ comment.c_str(),
+ this->Makefile->GetStartOutputDirectory()
+ );
+ this->Makefile->GetSource(targetFullPath);
+ target.Target->AddSource(targetFullPath);
+}
+
+
+void cmLocalGenerator
+::CreateCustomTargetsAndCommands(std::set<std::string> const& lang)
+{
+ cmGeneratorTargetsType tgts = this->Makefile->GetGeneratorTargets();
+ for(cmGeneratorTargetsType::iterator l = tgts.begin();
+ l != tgts.end(); l++)
+ {
+ if (l->first->IsImported())
+ {
+ continue;
+ }
+ cmGeneratorTarget& target = *l->second;
+ switch(target.GetType())
+ {
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ case cmTarget::EXECUTABLE:
+ {
+ std::string llang = target.Target->GetLinkerLanguage();
+ if(llang.empty())
+ {
+ cmSystemTools::Error
+ ("CMake can not determine linker language for target: ",
+ target.Target->GetName().c_str());
+ return;
+ }
+ // if the language is not in the set lang then create custom
+ // commands to build the target
+ if(lang.count(llang) == 0)
+ {
+ this->AddBuildTargetRule(llang, target);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+// List of variables that are replaced when
+// rules are expanced. These variables are
+// replaced in the form <var> with GetSafeDefinition(var).
+// ${LANG} is replaced in the variable first with all enabled
+// languages.
+static const char* ruleReplaceVars[] =
+{
+ "CMAKE_${LANG}_COMPILER",
+ "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
+ "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
+ "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
+ "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
+ "CMAKE_${LANG}_LINK_FLAGS",
+ "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
+ "CMAKE_${LANG}_ARCHIVE",
+ "CMAKE_AR",
+ "CMAKE_CURRENT_SOURCE_DIR",
+ "CMAKE_CURRENT_BINARY_DIR",
+ "CMAKE_RANLIB",
+ "CMAKE_LINKER",
+ "CMAKE_CL_SHOWINCLUDES_PREFIX",
+ 0
+};
+
+std::string
+cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
+ const RuleVariables& replaceValues)
+{
+ if(replaceValues.LinkFlags)
+ {
+ if(variable == "LINK_FLAGS")
+ {
+ return replaceValues.LinkFlags;
+ }
+ }
+ if(replaceValues.Flags)
+ {
+ if(variable == "FLAGS")
+ {
+ return replaceValues.Flags;
+ }
+ }
+
+ if(replaceValues.Source)
+ {
+ if(variable == "SOURCE")
+ {
+ return replaceValues.Source;
+ }
+ }
+ if(replaceValues.PreprocessedSource)
+ {
+ if(variable == "PREPROCESSED_SOURCE")
+ {
+ return replaceValues.PreprocessedSource;
+ }
+ }
+ if(replaceValues.AssemblySource)
+ {
+ if(variable == "ASSEMBLY_SOURCE")
+ {
+ return replaceValues.AssemblySource;
+ }
+ }
+ if(replaceValues.Object)
+ {
+ if(variable == "OBJECT")
+ {
+ return replaceValues.Object;
+ }
+ }
+ if(replaceValues.ObjectDir)
+ {
+ if(variable == "OBJECT_DIR")
+ {
+ return replaceValues.ObjectDir;
+ }
+ }
+ if(replaceValues.ObjectFileDir)
+ {
+ if(variable == "OBJECT_FILE_DIR")
+ {
+ return replaceValues.ObjectFileDir;
+ }
+ }
+ if(replaceValues.Objects)
+ {
+ if(variable == "OBJECTS")
+ {
+ return replaceValues.Objects;
+ }
+ }
+ if(replaceValues.ObjectsQuoted)
+ {
+ if(variable == "OBJECTS_QUOTED")
+ {
+ return replaceValues.ObjectsQuoted;
+ }
+ }
+ if(replaceValues.Defines && variable == "DEFINES")
+ {
+ return replaceValues.Defines;
+ }
+ if(replaceValues.TargetPDB )
+ {
+ if(variable == "TARGET_PDB")
+ {
+ return replaceValues.TargetPDB;
+ }
+ }
+ if(replaceValues.TargetCompilePDB)
+ {
+ if(variable == "TARGET_COMPILE_PDB")
+ {
+ return replaceValues.TargetCompilePDB;
+ }
+ }
+ if(replaceValues.DependencyFile )
+ {
+ if(variable == "DEP_FILE")
+ {
+ return replaceValues.DependencyFile;
+ }
+ }
+
+ if(replaceValues.Target)
+ {
+ if(variable == "TARGET_QUOTED")
+ {
+ std::string targetQuoted = replaceValues.Target;
+ if(targetQuoted.size() && targetQuoted[0] != '\"')
+ {
+ targetQuoted = '\"';
+ targetQuoted += replaceValues.Target;
+ targetQuoted += '\"';
+ }
+ return targetQuoted;
+ }
+ if(variable == "TARGET_UNQUOTED")
+ {
+ std::string unquoted = replaceValues.Target;
+ std::string::size_type sz = unquoted.size();
+ if(sz > 2 && unquoted[0] == '\"' && unquoted[sz-1] == '\"')
+ {
+ unquoted = unquoted.substr(1, sz-2);
+ }
+ return unquoted;
+ }
+ if(replaceValues.LanguageCompileFlags)
+ {
+ if(variable == "LANGUAGE_COMPILE_FLAGS")
+ {
+ return replaceValues.LanguageCompileFlags;
+ }
+ }
+ if(replaceValues.Target)
+ {
+ if(variable == "TARGET")
+ {
+ return replaceValues.Target;
+ }
+ }
+ if(variable == "TARGET_IMPLIB")
+ {
+ return this->TargetImplib;
+ }
+ if(variable == "TARGET_VERSION_MAJOR")
+ {
+ if(replaceValues.TargetVersionMajor)
+ {
+ return replaceValues.TargetVersionMajor;
+ }
+ else
+ {
+ return "0";
+ }
+ }
+ if(variable == "TARGET_VERSION_MINOR")
+ {
+ if(replaceValues.TargetVersionMinor)
+ {
+ return replaceValues.TargetVersionMinor;
+ }
+ else
+ {
+ return "0";
+ }
+ }
+ if(replaceValues.Target)
+ {
+ if(variable == "TARGET_BASE")
+ {
+ // Strip the last extension off the target name.
+ std::string targetBase = replaceValues.Target;
+ std::string::size_type pos = targetBase.rfind(".");
+ if(pos != targetBase.npos)
+ {
+ return targetBase.substr(0, pos);
+ }
+ else
+ {
+ return targetBase;
+ }
+ }
+ }
+ }
+ if(variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
+ variable == "TARGET_INSTALLNAME_DIR")
+ {
+ // All these variables depend on TargetSOName
+ if(replaceValues.TargetSOName)
+ {
+ if(variable == "TARGET_SONAME")
+ {
+ return replaceValues.TargetSOName;
+ }
+ if(variable == "SONAME_FLAG" && replaceValues.SONameFlag)
+ {
+ return replaceValues.SONameFlag;
+ }
+ if(replaceValues.TargetInstallNameDir &&
+ variable == "TARGET_INSTALLNAME_DIR")
+ {
+ return replaceValues.TargetInstallNameDir;
+ }
+ }
+ return "";
+ }
+ if(replaceValues.LinkLibraries)
+ {
+ if(variable == "LINK_LIBRARIES")
+ {
+ return replaceValues.LinkLibraries;
+ }
+ }
+ if(replaceValues.Language)
+ {
+ if(variable == "LANGUAGE")
+ {
+ return replaceValues.Language;
+ }
+ }
+ if(replaceValues.CMTarget)
+ {
+ if(variable == "TARGET_NAME")
+ {
+ return replaceValues.CMTarget->GetName();
+ }
+ if(variable == "TARGET_TYPE")
+ {
+ return cmTarget::GetTargetTypeName(replaceValues.CMTarget->GetType());
+ }
+ }
+ if(replaceValues.Output)
+ {
+ if(variable == "OUTPUT")
+ {
+ return replaceValues.Output;
+ }
+ }
+ if(variable == "CMAKE_COMMAND")
+ {
+ const char* cmcommand =
+ this->GetMakefile()->GetDefinition("CMAKE_COMMAND");
+ return this->Convert(cmcommand, FULL, SHELL);
+ }
+ std::vector<std::string> enabledLanguages;
+ this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
+ // loop over language specific replace variables
+ int pos = 0;
+ while(ruleReplaceVars[pos])
+ {
+ for(std::vector<std::string>::iterator i = enabledLanguages.begin();
+ i != enabledLanguages.end(); ++i)
+ {
+ const char* lang = i->c_str();
+ std::string actualReplace = ruleReplaceVars[pos];
+ // If this is the compiler then look for the extra variable
+ // _COMPILER_ARG1 which must be the first argument to the compiler
+ const char* compilerArg1 = 0;
+ const char* compilerTarget = 0;
+ const char* compilerOptionTarget = 0;
+ const char* compilerExternalToolchain = 0;
+ const char* compilerOptionExternalToolchain = 0;
+ const char* compilerSysroot = 0;
+ const char* compilerOptionSysroot = 0;
+ if(actualReplace == "CMAKE_${LANG}_COMPILER")
+ {
+ std::string arg1 = actualReplace + "_ARG1";
+ cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
+ compilerArg1 = this->Makefile->GetDefinition(arg1);
+ compilerTarget
+ = this->Makefile->GetDefinition(
+ std::string("CMAKE_") + lang + "_COMPILER_TARGET");
+ compilerOptionTarget
+ = this->Makefile->GetDefinition(
+ std::string("CMAKE_") + lang +
+ "_COMPILE_OPTIONS_TARGET");
+ compilerExternalToolchain
+ = this->Makefile->GetDefinition(
+ std::string("CMAKE_") + lang +
+ "_COMPILER_EXTERNAL_TOOLCHAIN");
+ compilerOptionExternalToolchain
+ = this->Makefile->GetDefinition(
+ std::string("CMAKE_") + lang +
+ "_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN");
+ compilerSysroot
+ = this->Makefile->GetDefinition("CMAKE_SYSROOT");
+ compilerOptionSysroot
+ = this->Makefile->GetDefinition(
+ std::string("CMAKE_") + lang +
+ "_COMPILE_OPTIONS_SYSROOT");
+ }
+ if(actualReplace.find("${LANG}") != actualReplace.npos)
+ {
+ cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
+ }
+ if(actualReplace == variable)
+ {
+ std::string replace =
+ this->Makefile->GetSafeDefinition(variable);
+ // if the variable is not a FLAG then treat it like a path
+ if(variable.find("_FLAG") == variable.npos)
+ {
+ std::string ret = this->ConvertToOutputForExisting(replace);
+ // if there is a required first argument to the compiler add it
+ // to the compiler string
+ if(compilerArg1)
+ {
+ ret += " ";
+ ret += compilerArg1;
+ }
+ if (compilerTarget && compilerOptionTarget)
+ {
+ ret += " ";
+ ret += compilerOptionTarget;
+ ret += compilerTarget;
+ }
+ if (compilerExternalToolchain && compilerOptionExternalToolchain)
+ {
+ ret += " ";
+ ret += compilerOptionExternalToolchain;
+ ret += this->EscapeForShell(compilerExternalToolchain, true);
+ }
+ if (compilerSysroot && compilerOptionSysroot)
+ {
+ ret += " ";
+ ret += compilerOptionSysroot;
+ ret += this->EscapeForShell(compilerSysroot, true);
+ }
+ return ret;
+ }
+ return replace;
+ }
+ }
+ pos++;
+ }
+ return variable;
+}
+
+
+void
+cmLocalGenerator::ExpandRuleVariables(std::string& s,
+ const RuleVariables& replaceValues)
+{
+ if(replaceValues.RuleLauncher)
+ {
+ this->InsertRuleLauncher(s, replaceValues.CMTarget,
+ replaceValues.RuleLauncher);
+ }
+ std::string::size_type start = s.find('<');
+ // no variables to expand
+ if(start == s.npos)
+ {
+ return;
+ }
+ std::string::size_type pos = 0;
+ std::string expandedInput;
+ while(start != s.npos && start < s.size()-2)
+ {
+ std::string::size_type end = s.find('>', start);
+ // if we find a < with no > we are done
+ if(end == s.npos)
+ {
+ return;
+ }
+ char c = s[start+1];
+ // if the next char after the < is not A-Za-z then
+ // skip it and try to find the next < in the string
+ if(!isalpha(c))
+ {
+ start = s.find('<', start+1);
+ }
+ else
+ {
+ // extract the var
+ std::string var = s.substr(start+1, end - start-1);
+ std::string replace = this->ExpandRuleVariable(var,
+ replaceValues);
+ expandedInput += s.substr(pos, start-pos);
+ expandedInput += replace;
+ // move to next one
+ start = s.find('<', start+var.size()+2);
+ pos = end+1;
+ }
+ }
+ // add the rest of the input
+ expandedInput += s.substr(pos, s.size()-pos);
+ s = expandedInput;
+}
+
+//----------------------------------------------------------------------------
+const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
+ const std::string& prop)
+{
+ if(target)
+ {
+ return target->GetProperty(prop);
+ }
+ else
+ {
+ return this->Makefile->GetProperty(prop);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
+ const std::string& prop)
+{
+ if(const char* val = this->GetRuleLauncher(target, prop))
+ {
+ cmOStringStream wrapped;
+ wrapped << val << " " << s;
+ s = wrapped.str();
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator::ConvertToOutputForExistingCommon(const std::string& remote,
+ std::string const& result,
+ OutputFormat format)
+{
+ // If this is a windows shell, the result has a space, and the path
+ // already exists, we can use a short-path to reference it without a
+ // space.
+ if(this->WindowsShell && result.find(' ') != result.npos &&
+ cmSystemTools::FileExists(remote.c_str()))
+ {
+ std::string tmp;
+ if(cmSystemTools::GetShortPath(remote.c_str(), tmp))
+ {
+ return this->Convert(tmp, NONE, format, true);
+ }
+ }
+
+ // Otherwise, leave it unchanged.
+ return result;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator::ConvertToOutputForExisting(const std::string& remote,
+ RelativeRoot local,
+ OutputFormat format)
+{
+ // Perform standard conversion.
+ std::string result = this->Convert(remote, local, format, true);
+
+ // Consider short-path.
+ return this->ConvertToOutputForExistingCommon(remote, result, format);
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote,
+ const std::string& local,
+ OutputFormat format)
+{
+ // Perform standard conversion.
+ std::string result = this->Convert(remote, local, format, true);
+
+ // Consider short-path.
+ const char* remotePath = this->GetRelativeRootPath(remote);
+ return this->ConvertToOutputForExistingCommon(remotePath, result, format);
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator::ConvertToIncludeReference(std::string const& path,
+ OutputFormat format,
+ bool forceFullPaths)
+{
+ return this->ConvertToOutputForExisting(
+ path, forceFullPaths? FULL : START_OUTPUT, format);
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::GetIncludeFlags(
+ const std::vector<std::string> &includes,
+ cmGeneratorTarget* target,
+ const std::string& lang,
+ bool forceFullPaths,
+ bool forResponseFile,
+ const std::string& config)
+{
+ if(lang.empty())
+ {
+ return "";
+ }
+
+ OutputFormat shellFormat = forResponseFile? RESPONSE : SHELL;
+ cmOStringStream includeFlags;
+
+ std::string flagVar = "CMAKE_INCLUDE_FLAG_";
+ flagVar += lang;
+ const char* includeFlag =
+ this->Makefile->GetSafeDefinition(flagVar);
+ flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
+ flagVar += lang;
+ const char* sep = this->Makefile->GetDefinition(flagVar);
+ bool quotePaths = false;
+ if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
+ {
+ quotePaths = true;
+ }
+ bool repeatFlag = true;
+ // should the include flag be repeated like ie. -IA -IB
+ if(!sep)
+ {
+ sep = " ";
+ }
+ else
+ {
+ // if there is a separator then the flag is not repeated but is only
+ // given once i.e. -classpath a:b:c
+ repeatFlag = false;
+ }
+
+ // Support special system include flag if it is available and the
+ // normal flag is repeated for each directory.
+ std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
+ sysFlagVar += lang;
+ const char* sysIncludeFlag = 0;
+ if(repeatFlag)
+ {
+ sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar);
+ }
+
+ std::string fwSearchFlagVar = "CMAKE_";
+ fwSearchFlagVar += lang;
+ fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
+ const char* fwSearchFlag =
+ this->Makefile->GetDefinition(fwSearchFlagVar);
+
+ std::string sysFwSearchFlagVar = "CMAKE_";
+ sysFwSearchFlagVar += lang;
+ sysFwSearchFlagVar += "_SYSTEM_FRAMEWORK_SEARCH_FLAG";
+ const char* sysFwSearchFlag =
+ this->Makefile->GetDefinition(sysFwSearchFlagVar);
+
+ bool flagUsed = false;
+ std::set<std::string> emitted;
+#ifdef __APPLE__
+ emitted.insert("/System/Library/Frameworks");
+#endif
+ std::vector<std::string>::const_iterator i;
+ for(i = includes.begin(); i != includes.end(); ++i)
+ {
+ if(fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE")
+ && cmSystemTools::IsPathToFramework(i->c_str()))
+ {
+ std::string frameworkDir = *i;
+ frameworkDir += "/../";
+ frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
+ if(emitted.insert(frameworkDir).second)
+ {
+ if (sysFwSearchFlag && target &&
+ target->IsSystemIncludeDirectory(*i, config))
+ {
+ includeFlags << sysFwSearchFlag;
+ }
+ else
+ {
+ includeFlags << fwSearchFlag;
+ }
+ includeFlags << this->Convert(frameworkDir, START_OUTPUT,
+ shellFormat, true)
+ << " ";
+ }
+ continue;
+ }
+
+ if(!flagUsed || repeatFlag)
+ {
+ if(sysIncludeFlag && target &&
+ target->IsSystemIncludeDirectory(*i, config))
+ {
+ includeFlags << sysIncludeFlag;
+ }
+ else
+ {
+ includeFlags << includeFlag;
+ }
+ flagUsed = true;
+ }
+ std::string includePath =
+ this->ConvertToIncludeReference(*i, shellFormat, forceFullPaths);
+ if(quotePaths && includePath.size() && includePath[0] != '\"')
+ {
+ includeFlags << "\"";
+ }
+ includeFlags << includePath;
+ if(quotePaths && includePath.size() && includePath[0] != '\"')
+ {
+ includeFlags << "\"";
+ }
+ includeFlags << sep;
+ }
+ std::string flags = includeFlags.str();
+ // remove trailing separators
+ if((sep[0] != ' ') && flags.size()>0 && flags[flags.size()-1] == sep[0])
+ {
+ flags[flags.size()-1] = ' ';
+ }
+ return flags;
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
+ cmTarget const* target,
+ const std::string& config)
+{
+ std::vector<std::string> targetDefines;
+ target->GetCompileDefinitions(targetDefines,
+ config);
+ this->AppendDefines(defines, targetDefines);
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddCompileOptions(
+ std::string& flags, cmTarget* target,
+ const std::string& lang, const std::string& config
+ )
+{
+ std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX";
+ if(const char* langFlagRegexStr =
+ this->Makefile->GetDefinition(langFlagRegexVar))
+ {
+ // Filter flags acceptable to this language.
+ cmsys::RegularExpression r(langFlagRegexStr);
+ std::vector<std::string> opts;
+ if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
+ {
+ cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
+ }
+ target->GetCompileOptions(opts, config);
+ for(std::vector<std::string>::const_iterator i = opts.begin();
+ i != opts.end(); ++i)
+ {
+ if(r.find(i->c_str()))
+ {
+ // (Re-)Escape this flag. COMPILE_FLAGS were already parsed
+ // as a command line above, and COMPILE_OPTIONS are escaped.
+ this->AppendFlagEscape(flags, *i);
+ }
+ }
+ }
+ else
+ {
+ // Use all flags.
+ if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
+ {
+ // COMPILE_FLAGS are not escaped for historical reasons.
+ this->AppendFlags(flags, targetFlags);
+ }
+ std::vector<std::string> opts;
+ target->GetCompileOptions(opts, config);
+ for(std::vector<std::string>::const_iterator i = opts.begin();
+ i != opts.end(); ++i)
+ {
+ // COMPILE_OPTIONS are escaped.
+ this->AppendFlagEscape(flags, *i);
+ }
+ }
+ std::vector<std::string> features;
+ target->GetCompileFeatures(features, config);
+ for(std::vector<std::string>::const_iterator it = features.begin();
+ it != features.end(); ++it)
+ {
+ if (!this->Makefile->AddRequiredTargetFeature(target, *it))
+ {
+ return;
+ }
+ }
+
+ for(std::map<std::string, std::string>::const_iterator it
+ = target->GetMaxLanguageStandards().begin();
+ it != target->GetMaxLanguageStandards().end(); ++it)
+ {
+ const char* standard = target->GetProperty(it->first + "_STANDARD");
+ if(!standard)
+ {
+ continue;
+ }
+ if (this->Makefile->IsLaterStandard(it->first, standard, it->second))
+ {
+ cmOStringStream e;
+ e << "The COMPILE_FEATURES property of target \""
+ << target->GetName() << "\" was evaluated when computing the link "
+ "implementation, and the \"" << it->first << "_STANDARD\" was \""
+ << it->second << "\" for that computation. Computing the "
+ "COMPILE_FEATURES based on the link implementation resulted in a "
+ "higher \"" << it->first << "_STANDARD\" \"" << standard << "\". "
+ "This is not permitted. The COMPILE_FEATURES may not both depend on "
+ "and be depended on by the link implementation." << std::endl;
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ }
+ this->AddCompilerRequirementFlag(flags, target, lang);
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
+ cmGeneratorTarget* target,
+ const std::string& lang,
+ const std::string& config,
+ bool stripImplicitInclDirs
+ )
+{
+ // Need to decide whether to automatically include the source and
+ // binary directories at the beginning of the include path.
+ bool includeSourceDir = false;
+ bool includeBinaryDir = false;
+
+ // When automatic include directories are requested for a build then
+ // include the source and binary directories at the beginning of the
+ // include path to approximate include file behavior for an
+ // in-source build. This does not account for the case of a source
+ // file in a subdirectory of the current source directory but we
+ // cannot fix this because not all native build tools support
+ // per-source-file include paths.
+ if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
+ {
+ includeSourceDir = true;
+ includeBinaryDir = true;
+ }
+
+ // Do not repeat an include path.
+ std::set<std::string> emitted;
+
+ // Store the automatic include paths.
+ if(includeBinaryDir)
+ {
+ if(emitted.find(
+ this->Makefile->GetStartOutputDirectory()) == emitted.end())
+ {
+ dirs.push_back(this->Makefile->GetStartOutputDirectory());
+ emitted.insert(this->Makefile->GetStartOutputDirectory());
+ }
+ }
+ if(includeSourceDir)
+ {
+ if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
+ {
+ dirs.push_back(this->Makefile->GetStartDirectory());
+ emitted.insert(this->Makefile->GetStartDirectory());
+ }
+ }
+
+ if(!target)
+ {
+ return;
+ }
+
+ std::string rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
+
+ std::vector<std::string> implicitDirs;
+ // Load implicit include directories for this language.
+ std::string impDirVar = "CMAKE_";
+ impDirVar += lang;
+ impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
+ if(const char* value = this->Makefile->GetDefinition(impDirVar))
+ {
+ std::vector<std::string> impDirVec;
+ cmSystemTools::ExpandListArgument(value, impDirVec);
+ for(std::vector<std::string>::const_iterator i = impDirVec.begin();
+ i != impDirVec.end(); ++i)
+ {
+ std::string d = rootPath + *i;
+ cmSystemTools::ConvertToUnixSlashes(d);
+ emitted.insert(d);
+ if (!stripImplicitInclDirs)
+ {
+ implicitDirs.push_back(*i);
+ }
+ }
+ }
+
+ // Get the target-specific include directories.
+ std::vector<std::string> includes;
+
+ includes = target->GetIncludeDirectories(config);
+
+ // Support putting all the in-project include directories first if
+ // it is requested by the project.
+ if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
+ {
+ const char* topSourceDir = this->Makefile->GetHomeDirectory();
+ const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
+ for(std::vector<std::string>::const_iterator i = includes.begin();
+ i != includes.end(); ++i)
+ {
+ // Emit this directory only if it is a subdirectory of the
+ // top-level source or binary tree.
+ if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
+ cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
+ cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
+ cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
+ {
+ if(emitted.insert(*i).second)
+ {
+ dirs.push_back(*i);
+ }
+ }
+ }
+ }
+
+ // Construct the final ordered include directory list.
+ for(std::vector<std::string>::const_iterator i = includes.begin();
+ i != includes.end(); ++i)
+ {
+ if(emitted.insert(*i).second)
+ {
+ dirs.push_back(*i);
+ }
+ }
+
+ for(std::vector<std::string>::const_iterator i = implicitDirs.begin();
+ i != implicitDirs.end(); ++i)
+ {
+ if(std::find(includes.begin(), includes.end(), *i) != includes.end())
+ {
+ dirs.push_back(*i);
+ }
+ }
+}
+
+void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
+ std::string const& config,
+ cmTarget* target)
+{
+ this->AppendFlags(flags,
+ this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"));
+ if(!config.empty())
+ {
+ std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config;
+ this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name));
+ }
+ this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
+ if(!config.empty())
+ {
+ std::string name = "STATIC_LIBRARY_FLAGS_" + config;
+ this->AppendFlags(flags, target->GetProperty(name));
+ }
+}
+
+void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
+ std::string& flags,
+ std::string& linkFlags,
+ std::string& frameworkPath,
+ std::string& linkPath,
+ cmGeneratorTarget* target,
+ bool useWatcomQuote)
+{
+ std::string buildType =
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ buildType = cmSystemTools::UpperCase(buildType);
+ const char* libraryLinkVariable =
+ "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
+
+ switch(target->GetType())
+ {
+ case cmTarget::STATIC_LIBRARY:
+ this->GetStaticLibraryFlags(linkFlags, buildType, target->Target);
+ break;
+ case cmTarget::MODULE_LIBRARY:
+ libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
+ case cmTarget::SHARED_LIBRARY:
+ {
+ linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
+ linkFlags += " ";
+ if(!buildType.empty())
+ {
+ std::string build = libraryLinkVariable;
+ build += "_";
+ build += buildType;
+ linkFlags += this->Makefile->GetSafeDefinition(build);
+ linkFlags += " ";
+ }
+ if(this->Makefile->IsOn("WIN32") &&
+ !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
+ {
+ std::vector<cmSourceFile*> sources;
+ target->GetSourceFiles(sources, buildType);
+ for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
+ i != sources.end(); ++i)
+ {
+ cmSourceFile* sf = *i;
+ if(sf->GetExtension() == "def")
+ {
+ linkFlags +=
+ this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
+ linkFlags += this->Convert(sf->GetFullPath(),
+ FULL, SHELL);
+ linkFlags += " ";
+ }
+ }
+ }
+ const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
+ if(targetLinkFlags)
+ {
+ linkFlags += targetLinkFlags;
+ linkFlags += " ";
+ }
+ if(!buildType.empty())
+ {
+ std::string configLinkFlags = "LINK_FLAGS_";
+ configLinkFlags += buildType;
+ targetLinkFlags = target->GetProperty(configLinkFlags);
+ if(targetLinkFlags)
+ {
+ linkFlags += targetLinkFlags;
+ linkFlags += " ";
+ }
+ }
+ this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
+ *target, false, false, useWatcomQuote);
+ }
+ break;
+ case cmTarget::EXECUTABLE:
+ {
+ linkFlags +=
+ this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
+ linkFlags += " ";
+ if(!buildType.empty())
+ {
+ std::string build = "CMAKE_EXE_LINKER_FLAGS_";
+ build += buildType;
+ linkFlags += this->Makefile->GetSafeDefinition(build);
+ linkFlags += " ";
+ }
+ std::string linkLanguage = target->Target->GetLinkerLanguage(buildType);
+ if(linkLanguage.empty())
+ {
+ cmSystemTools::Error
+ ("CMake can not determine linker language for target: ",
+ target->Target->GetName().c_str());
+ return;
+ }
+ this->AddLanguageFlags(flags, linkLanguage, buildType);
+ this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
+ *target, false, false, useWatcomQuote);
+ if(cmSystemTools::IsOn
+ (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
+ {
+ std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
+ + linkLanguage + std::string("_FLAGS");
+ linkFlags += this->Makefile->GetSafeDefinition(sFlagVar);
+ linkFlags += " ";
+ }
+ if ( target->GetPropertyAsBool("WIN32_EXECUTABLE") )
+ {
+ linkFlags +=
+ this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
+ linkFlags += " ";
+ }
+ else
+ {
+ linkFlags +=
+ this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
+ linkFlags += " ";
+ }
+ if (target->Target->IsExecutableWithExports())
+ {
+ std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
+ exportFlagVar += linkLanguage;
+ exportFlagVar += "_FLAG";
+
+ linkFlags +=
+ this->Makefile->GetSafeDefinition(exportFlagVar);
+ linkFlags += " ";
+ }
+ const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
+ if(targetLinkFlags)
+ {
+ linkFlags += targetLinkFlags;
+ linkFlags += " ";
+ }
+ if(!buildType.empty())
+ {
+ std::string configLinkFlags = "LINK_FLAGS_";
+ configLinkFlags += buildType;
+ targetLinkFlags = target->GetProperty(configLinkFlags);
+ if(targetLinkFlags)
+ {
+ linkFlags += targetLinkFlags;
+ linkFlags += " ";
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib,
+ OutputFormat format)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ // Work-ardound command line parsing limitations in MSVC 6.0
+ if(this->Makefile->IsOn("MSVC60"))
+ {
+ // Search for the last space.
+ std::string::size_type pos = lib.rfind(' ');
+ if(pos != lib.npos)
+ {
+ // Find the slash after the last space, if any.
+ pos = lib.find('/', pos);
+
+ // Convert the portion of the path with a space to a short path.
+ std::string sp;
+ if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
+ {
+ // Append the rest of the path with no space.
+ sp += lib.substr(pos);
+
+ // Convert to an output path.
+ return this->Convert(sp.c_str(), NONE, format);
+ }
+ }
+ }
+#endif
+
+ // Normal behavior.
+ return this->Convert(lib, START_OUTPUT, format);
+}
+
+/**
+ * Output the linking rules on a command line. For executables,
+ * targetLibrary should be a NULL pointer. For libraries, it should point
+ * to the name of the library. This will not link a library against itself.
+ */
+void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
+ std::string& frameworkPath,
+ std::string& linkPath,
+ cmGeneratorTarget &tgt,
+ bool relink,
+ bool forResponseFile,
+ bool useWatcomQuote)
+{
+ OutputFormat shellFormat = (forResponseFile) ? RESPONSE :
+ ((useWatcomQuote) ? WATCOMQUOTE : SHELL);
+ bool escapeAllowMakeVars = !forResponseFile;
+ cmOStringStream fout;
+ std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ cmComputeLinkInformation* pcli = tgt.Target->GetLinkInformation(config);
+ if(!pcli)
+ {
+ return;
+ }
+ cmComputeLinkInformation& cli = *pcli;
+
+ // Collect library linking flags command line options.
+ std::string linkLibs;
+
+ std::string linkLanguage = cli.GetLinkLanguage();
+
+ std::string libPathFlag =
+ this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
+ std::string libPathTerminator =
+ this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
+
+ // Flags to link an executable to shared libraries.
+ std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
+ linkFlagsVar += linkLanguage;
+ linkFlagsVar += "_FLAGS";
+ if( tgt.GetType() == cmTarget::EXECUTABLE )
+ {
+ linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar);
+ linkLibs += " ";
+ }
+
+ // Append the framework search path flags.
+ std::string fwSearchFlagVar = "CMAKE_";
+ fwSearchFlagVar += linkLanguage;
+ fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
+ const char* fwSearchFlag =
+ this->Makefile->GetDefinition(fwSearchFlagVar);
+ if(fwSearchFlag && *fwSearchFlag)
+ {
+ std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
+ for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
+ fdi != fwDirs.end(); ++fdi)
+ {
+ frameworkPath += fwSearchFlag;
+ frameworkPath += this->Convert(*fdi, NONE, shellFormat, false);
+ frameworkPath += " ";
+ }
+ }
+
+ // Append the library search path flags.
+ std::vector<std::string> const& libDirs = cli.GetDirectories();
+ for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
+ libDir != libDirs.end(); ++libDir)
+ {
+ std::string libpath = this->ConvertToOutputForExisting(*libDir,
+ START_OUTPUT,
+ shellFormat);
+ linkPath += " " + libPathFlag;
+ linkPath += libpath;
+ linkPath += libPathTerminator;
+ linkPath += " ";
+ }
+
+ // Append the link items.
+ typedef cmComputeLinkInformation::ItemVector ItemVector;
+ 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)
+ {
+ continue;
+ }
+ if(li->IsPath)
+ {
+ linkLibs += this->ConvertToLinkReference(li->Value, shellFormat);
+ }
+ else
+ {
+ linkLibs += li->Value;
+ }
+ linkLibs += " ";
+ }
+
+ // Write the library flags to the build rule.
+ fout << linkLibs;
+
+ // Get the RPATH entries.
+ std::vector<std::string> runtimeDirs;
+ cli.GetRPath(runtimeDirs, relink);
+
+ // Check what kind of rpath flags to use.
+ if(cli.GetRuntimeSep().empty())
+ {
+ // Each rpath entry gets its own option ("-R a -R b -R c")
+ std::string rpath;
+ for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
+ ri != runtimeDirs.end(); ++ri)
+ {
+ rpath += cli.GetRuntimeFlag();
+ rpath += this->Convert(*ri, NONE, shellFormat, false);
+ rpath += " ";
+ }
+ fout << rpath;
+ }
+ else
+ {
+ // All rpath entries are combined ("-Wl,-rpath,a:b:c").
+ std::string rpath = cli.GetRPathString(relink);
+
+ // Store the rpath option in the stream.
+ if(!rpath.empty())
+ {
+ fout << cli.GetRuntimeFlag();
+ fout << this->EscapeForShell(rpath, escapeAllowMakeVars);
+ fout << " ";
+ }
+ }
+
+ // Add the linker runtime search path if any.
+ std::string rpath_link = cli.GetRPathLinkString();
+ if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
+ {
+ fout << cli.GetRPathLinkFlag();
+ fout << this->EscapeForShell(rpath_link, escapeAllowMakeVars);
+ fout << " ";
+ }
+
+ // Add standard libraries for this language.
+ std::string standardLibsVar = "CMAKE_";
+ standardLibsVar += cli.GetLinkLanguage();
+ standardLibsVar += "_STANDARD_LIBRARIES";
+ if(const char* stdLibs =
+ this->Makefile->GetDefinition(standardLibsVar))
+ {
+ fout << stdLibs << " ";
+ }
+
+ linkLibraries = fout.str();
+}
+
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
+ cmGeneratorTarget* target,
+ const std::string& lang,
+ const std::string& config)
+{
+ // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
+ if(!this->Makefile->IsOn("APPLE"))
+ {
+ return;
+ }
+
+ if(this->EmitUniversalBinaryFlags)
+ {
+ std::vector<std::string> archs;
+ target->GetAppleArchs(config, archs);
+ const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
+ if(sysroot && sysroot[0] == '/' && !sysroot[1])
+ { sysroot = 0; }
+ std::string sysrootFlagVar =
+ std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
+ const char* sysrootFlag =
+ this->Makefile->GetDefinition(sysrootFlagVar);
+ const char* deploymentTarget =
+ this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
+ std::string deploymentTargetFlagVar =
+ std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
+ const char* deploymentTargetFlag =
+ this->Makefile->GetDefinition(deploymentTargetFlagVar);
+ if(!archs.empty() && !lang.empty() && (lang[0] =='C' || lang[0] == 'F'))
+ {
+ for(std::vector<std::string>::iterator i = archs.begin();
+ i != archs.end(); ++i)
+ {
+ flags += " -arch ";
+ flags += *i;
+ }
+ }
+
+ if(sysrootFlag && *sysrootFlag && sysroot && *sysroot)
+ {
+ flags += " ";
+ flags += sysrootFlag;
+ flags += " ";
+ flags += this->Convert(sysroot, NONE, SHELL);
+ }
+
+ if (deploymentTargetFlag && *deploymentTargetFlag &&
+ deploymentTarget && *deploymentTarget)
+ {
+ flags += " ";
+ flags += deploymentTargetFlag;
+ flags += deploymentTarget;
+ }
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddLanguageFlags(std::string& flags,
+ const std::string& lang,
+ const std::string& config)
+{
+ // Add language-specific flags.
+ std::string flagsVar = "CMAKE_";
+ flagsVar += lang;
+ flagsVar += "_FLAGS";
+ this->AddConfigVariableFlags(flags, flagsVar, config);
+}
+
+//----------------------------------------------------------------------------
+bool cmLocalGenerator::GetRealDependency(const std::string& inName,
+ const std::string& config,
+ std::string& dep)
+{
+ // Older CMake code may specify the dependency using the target
+ // output file rather than the target name. Such code would have
+ // been written before there was support for target properties that
+ // modify the name so stripping down to just the file name should
+ // produce the target name in this case.
+ std::string name = cmSystemTools::GetFilenameName(inName);
+
+ // If the input name is the empty string, there is no real
+ // dependency. Short-circuit the other checks:
+ if(name == "")
+ {
+ return false;
+ }
+
+ if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
+ {
+ name = cmSystemTools::GetFilenameWithoutLastExtension(name);
+ }
+
+ // Look for a CMake target with the given name.
+ if(cmTarget* target = this->Makefile->FindTargetToUse(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)
+ {
+ tLocation = target->GetLocation(config);
+ tLocation = cmSystemTools::GetFilenamePath(tLocation);
+ tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
+ }
+ std::string depLocation = cmSystemTools::GetFilenamePath(
+ std::string(inName));
+ depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
+ if(depLocation != tLocation)
+ {
+ // it is a full path to a depend that has the same name
+ // as a target but is in a different location so do not use
+ // the target as the depend
+ dep = inName;
+ return true;
+ }
+ }
+ switch (target->GetType())
+ {
+ case cmTarget::EXECUTABLE:
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ case cmTarget::UNKNOWN_LIBRARY:
+ dep = target->GetLocation(config);
+ return true;
+ case cmTarget::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:
+ // 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:
+ // A utility target has no file on which to depend. This was listed
+ // only to get the target-level dependency.
+ return false;
+ }
+ }
+
+ // The name was not that of a CMake target. It must name a file.
+ if(cmSystemTools::FileIsFullPath(inName.c_str()))
+ {
+ // This is a full path. Return it as given.
+ dep = inName;
+ return true;
+ }
+
+ // Check for a source file in this directory that matches the
+ // dependency.
+ if(cmSourceFile* sf = this->Makefile->GetSource(inName))
+ {
+ dep = sf->GetFullPath();
+ return true;
+ }
+
+ // Treat the name as relative to the source directory in which it
+ // was given.
+ dep = this->Makefile->GetCurrentDirectory();
+ dep += "/";
+ dep += inName;
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddSharedFlags(std::string& flags,
+ const std::string& lang,
+ bool shared)
+{
+ std::string flagsVar;
+
+ // Add flags for dealing with shared libraries for this language.
+ if(shared)
+ {
+ flagsVar = "CMAKE_SHARED_LIBRARY_";
+ flagsVar += lang;
+ flagsVar += "_FLAGS";
+ this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::
+AddCompilerRequirementFlag(std::string &flags, cmTarget* target,
+ const std::string& lang)
+{
+ if (lang.empty())
+ {
+ return;
+ }
+ std::string stdProp = lang + "_STANDARD";
+ const char *standardProp = target->GetProperty(stdProp);
+ if (!standardProp)
+ {
+ return;
+ }
+ std::string extProp = lang + "_EXTENSIONS";
+ std::string type = "EXTENSION";
+ bool ext = true;
+ if (const char* extPropValue = target->GetProperty(extProp))
+ {
+ if (cmSystemTools::IsOff(extPropValue))
+ {
+ ext = false;
+ type = "STANDARD";
+ }
+ }
+
+ if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED"))
+ {
+ std::string option_flag =
+ "CMAKE_" + lang + standardProp
+ + "_" + type + "_COMPILE_OPTION";
+
+ const char *opt = target->GetMakefile()->GetDefinition(option_flag);
+ if (!opt)
+ {
+ cmOStringStream e;
+ e << "Target \"" << target->GetName() << "\" requires the language "
+ "dialect \"" << lang << standardProp << "\" "
+ << (ext ? "(with compiler extensions)" : "") << ", but CMake "
+ "does not know the compile flags to use to enable it.";
+ this->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ else
+ {
+ this->AppendFlagEscape(flags, opt);
+ }
+ return;
+ }
+
+ static std::map<std::string, std::vector<std::string> > langStdMap;
+ if (langStdMap.empty())
+ {
+ // Maintain sorted order, most recent first.
+ langStdMap["CXX"].push_back("14");
+ langStdMap["CXX"].push_back("11");
+ langStdMap["CXX"].push_back("98");
+
+ langStdMap["C"].push_back("11");
+ langStdMap["C"].push_back("99");
+ langStdMap["C"].push_back("90");
+ }
+
+ std::string standard(standardProp);
+
+ std::vector<std::string>& stds = langStdMap[lang];
+
+ std::vector<std::string>::const_iterator stdIt =
+ std::find(stds.begin(), stds.end(), standard);
+ assert(stdIt != stds.end());
+
+ const char* defaultStd
+ = this->Makefile->GetDefinition("CMAKE_" + lang + "_STANDARD_DEFAULT");
+ std::vector<std::string>::const_iterator defaultStdIt;
+ if (defaultStd)
+ {
+ defaultStdIt = std::find(stds.begin(), stds.end(), defaultStd);
+ assert(defaultStdIt != stds.end());
+ }
+ else
+ {
+ defaultStdIt = stds.end() - 1;
+ }
+
+ for ( ; stdIt <= defaultStdIt; ++stdIt)
+ {
+ std::string option_flag =
+ "CMAKE_" + lang + *stdIt
+ + "_" + type + "_COMPILE_OPTION";
+
+ if (const char *opt = target->GetMakefile()->GetDefinition(option_flag))
+ {
+ this->AppendFlagEscape(flags, opt);
+ return;
+ }
+ }
+}
+
+static void AddVisibilityCompileOption(std::string &flags, cmTarget* target,
+ cmLocalGenerator *lg,
+ const std::string& lang)
+{
+ std::string l(lang);
+ std::string compileOption = "CMAKE_" + l + "_COMPILE_OPTIONS_VISIBILITY";
+ const char *opt = lg->GetMakefile()->GetDefinition(compileOption);
+ if (!opt)
+ {
+ return;
+ }
+ std::string flagDefine = l + "_VISIBILITY_PRESET";
+
+ const char *prop = target->GetProperty(flagDefine);
+ if (!prop)
+ {
+ return;
+ }
+ if (strcmp(prop, "hidden") != 0
+ && strcmp(prop, "default") != 0
+ && strcmp(prop, "protected") != 0
+ && strcmp(prop, "internal") != 0 )
+ {
+ cmOStringStream e;
+ e << "Target " << target->GetName() << " uses unsupported value \""
+ << prop << "\" for " << flagDefine << ".";
+ cmSystemTools::Error(e.str().c_str());
+ return;
+ }
+ std::string option = std::string(opt) + prop;
+ lg->AppendFlags(flags, option);
+}
+
+static void AddInlineVisibilityCompileOption(std::string &flags,
+ cmTarget* target,
+ cmLocalGenerator *lg)
+{
+ std::string compileOption
+ = "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN";
+ const char *opt = lg->GetMakefile()->GetDefinition(compileOption);
+ if (!opt)
+ {
+ return;
+ }
+
+ bool prop = target->GetPropertyAsBool("VISIBILITY_INLINES_HIDDEN");
+ if (!prop)
+ {
+ return;
+ }
+ lg->AppendFlags(flags, opt);
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator
+::AddVisibilityPresetFlags(std::string &flags, cmTarget* target,
+ const std::string& lang)
+{
+ int targetType = target->GetType();
+ bool suitableTarget = ((targetType == cmTarget::SHARED_LIBRARY)
+ || (targetType == cmTarget::MODULE_LIBRARY)
+ || (target->IsExecutableWithExports()));
+
+ if (!suitableTarget)
+ {
+ return;
+ }
+
+ if (lang.empty())
+ {
+ return;
+ }
+ AddVisibilityCompileOption(flags, target, this, lang);
+
+ if(lang == "CXX")
+ {
+ AddInlineVisibilityCompileOption(flags, target, this);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddCMP0018Flags(std::string &flags, cmTarget* target,
+ std::string const& lang,
+ const std::string& config)
+{
+ int targetType = target->GetType();
+
+ bool shared = ((targetType == cmTarget::SHARED_LIBRARY) ||
+ (targetType == cmTarget::MODULE_LIBRARY));
+
+ if (this->GetShouldUseOldFlags(shared, lang))
+ {
+ this->AddSharedFlags(flags, lang, shared);
+ }
+ else
+ {
+ if (target->GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE"))
+ {
+ this->AddPositionIndependentFlags(flags, lang, targetType);
+ }
+ return;
+ }
+
+ if (target->GetLinkInterfaceDependentBoolProperty(
+ "POSITION_INDEPENDENT_CODE",
+ config))
+ {
+ this->AddPositionIndependentFlags(flags, lang, targetType);
+ }
+ if (shared)
+ {
+ this->AppendFeatureOptions(flags, lang, "DLL");
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
+ const std::string &lang) const
+{
+ std::string originalFlags =
+ this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
+ if (shared)
+ {
+ std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
+ flagsVar += lang;
+ flagsVar += "_FLAGS";
+ const char* flags =
+ this->Makefile->GetSafeDefinition(flagsVar);
+
+ if (flags && flags != originalFlags)
+ {
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0018))
+ {
+ case cmPolicies::WARN:
+ {
+ cmOStringStream e;
+ e << "Variable " << flagsVar << " has been modified. CMake "
+ "will ignore the POSITION_INDEPENDENT_CODE target property for "
+ "shared libraries and will use the " << flagsVar << " variable "
+ "instead. This may cause errors if the original content of "
+ << flagsVar << " was removed.\n"
+ << this->Makefile->GetPolicies()->GetPolicyWarning(
+ cmPolicies::CMP0018);
+
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ // fall through to OLD behaviour
+ }
+ case cmPolicies::OLD:
+ return true;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ return false;
+ }
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
+ std::string const& lang,
+ int targetType)
+{
+ const char* picFlags = 0;
+
+ if(targetType == cmTarget::EXECUTABLE)
+ {
+ std::string flagsVar = "CMAKE_";
+ flagsVar += lang;
+ flagsVar += "_COMPILE_OPTIONS_PIE";
+ picFlags = this->Makefile->GetSafeDefinition(flagsVar);
+ }
+ if (!picFlags)
+ {
+ std::string flagsVar = "CMAKE_";
+ flagsVar += lang;
+ flagsVar += "_COMPILE_OPTIONS_PIC";
+ picFlags = this->Makefile->GetSafeDefinition(flagsVar);
+ }
+ if (picFlags)
+ {
+ std::vector<std::string> options;
+ cmSystemTools::ExpandListArgument(picFlags, options);
+ for(std::vector<std::string>::const_iterator oi = options.begin();
+ oi != options.end(); ++oi)
+ {
+ this->AppendFlagEscape(flags, *oi);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
+ const std::string& var,
+ const std::string& config)
+{
+ // Add the flags from the variable itself.
+ std::string flagsVar = var;
+ this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
+ // Add the flags from the build-type specific variable.
+ if(!config.empty())
+ {
+ flagsVar += "_";
+ flagsVar += cmSystemTools::UpperCase(config);
+ this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AppendFlags(std::string& flags,
+ const std::string& newFlags)
+{
+ if(!newFlags.empty())
+ {
+ if(flags.size())
+ {
+ flags += " ";
+ }
+ flags += newFlags;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AppendFlags(std::string& flags,
+ const char* newFlags)
+{
+ if(newFlags && *newFlags)
+ {
+ this->AppendFlags(flags, std::string(newFlags));
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AppendFlagEscape(std::string& flags,
+ const std::string& rawFlag)
+{
+ this->AppendFlags(flags, this->EscapeForShell(rawFlag));
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
+ const char* defines_list)
+{
+ // Short-circuit if there are no definitions.
+ if(!defines_list)
+ {
+ return;
+ }
+
+ // Expand the list of definitions.
+ std::vector<std::string> defines_vec;
+ cmSystemTools::ExpandListArgument(defines_list, defines_vec);
+ this->AppendDefines(defines, defines_vec);
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
+ const std::vector<std::string> &defines_vec)
+{
+ for(std::vector<std::string>::const_iterator di = defines_vec.begin();
+ di != defines_vec.end(); ++di)
+ {
+ // Skip unsupported definitions.
+ if(!this->CheckDefinition(*di))
+ {
+ continue;
+ }
+ defines.insert(*di);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
+ std::string &definesString,
+ const std::string& lang)
+{
+ // Lookup the define flag for the current language.
+ std::string dflag = "-D";
+ if(!lang.empty())
+ {
+ std::string defineFlagVar = "CMAKE_";
+ defineFlagVar += lang;
+ defineFlagVar += "_DEFINE_FLAG";
+ const char* df = this->Makefile->GetDefinition(defineFlagVar);
+ if(df && *df)
+ {
+ dflag = df;
+ }
+ }
+
+ std::set<std::string>::const_iterator defineIt = defines.begin();
+ const std::set<std::string>::const_iterator defineEnd = defines.end();
+ const char* itemSeparator = definesString.empty() ? "" : " ";
+ for( ; defineIt != defineEnd; ++defineIt)
+ {
+ // Append the definition with proper escaping.
+ std::string def = dflag;
+ if(this->WatcomWMake)
+ {
+ // The Watcom compiler does its own command line parsing instead
+ // of using the windows shell rules. Definitions are one of
+ // -DNAME
+ // -DNAME=<cpp-token>
+ // -DNAME="c-string with spaces and other characters(?@#$)"
+ //
+ // Watcom will properly parse each of these cases from the
+ // command line without any escapes. However we still have to
+ // get the '$' and '#' characters through WMake as '$$' and
+ // '$#'.
+ for(const char* c = defineIt->c_str(); *c; ++c)
+ {
+ if(*c == '$' || *c == '#')
+ {
+ def += '$';
+ }
+ def += *c;
+ }
+ }
+ else
+ {
+ // Make the definition appear properly on the command line. Use
+ // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
+ std::string::size_type eq = defineIt->find("=");
+ def += defineIt->substr(0, eq);
+ if(eq != defineIt->npos)
+ {
+ def += "=";
+ def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
+ }
+ }
+ definesString += itemSeparator;
+ itemSeparator = " ";
+ definesString += def;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AppendFeatureOptions(
+ std::string& flags, const std::string& lang, const char* feature)
+{
+ std::string optVar = "CMAKE_";
+ optVar += lang;
+ optVar += "_COMPILE_OPTIONS_";
+ optVar += feature;
+ if(const char* optionList = this->Makefile->GetDefinition(optVar))
+ {
+ std::vector<std::string> options;
+ cmSystemTools::ExpandListArgument(optionList, options);
+ for(std::vector<std::string>::const_iterator oi = options.begin();
+ oi != options.end(); ++oi)
+ {
+ this->AppendFlagEscape(flags, *oi);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator::ConstructComment(cmCustomCommandGenerator const& ccg,
+ const char* default_comment)
+{
+ // Check for a comment provided with the command.
+ if(ccg.GetComment())
+ {
+ return ccg.GetComment();
+ }
+
+ // Construct a reasonable default comment if possible.
+ if(!ccg.GetOutputs().empty())
+ {
+ std::string comment;
+ comment = "Generating ";
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin();
+ o != ccg.GetOutputs().end(); ++o)
+ {
+ comment += sep;
+ comment += this->Convert(*o, cmLocalGenerator::START_OUTPUT);
+ sep = ", ";
+ }
+ return comment;
+ }
+
+ // Otherwise use the provided default.
+ return default_comment;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(
+ const std::string& remote)
+{
+ return this->Convert(remote, START_OUTPUT, SHELL, true);
+}
+
+//----------------------------------------------------------------------------
+const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
+{
+ switch (relroot)
+ {
+ case HOME: return this->Makefile->GetHomeDirectory();
+ case START: return this->Makefile->GetStartDirectory();
+ case HOME_OUTPUT: return this->Makefile->GetHomeOutputDirectory();
+ case START_OUTPUT: return this->Makefile->GetStartOutputDirectory();
+ default: break;
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::Convert(const std::string& source,
+ RelativeRoot relative,
+ OutputFormat output,
+ bool optional)
+{
+ // Make sure the relative path conversion components are set.
+ if(!this->PathConversionsSetup)
+ {
+ this->SetupPathConversions();
+ this->PathConversionsSetup = true;
+ }
+
+ // Convert the path to a relative path.
+ std::string result = source;
+
+ if (!optional || this->UseRelativePaths)
+ {
+ switch (relative)
+ {
+ case HOME:
+ //result = cmSystemTools::CollapseFullPath(result.c_str());
+ result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
+ result);
+ break;
+ case START:
+ //result = cmSystemTools::CollapseFullPath(result.c_str());
+ result = this->ConvertToRelativePath(this->StartDirectoryComponents,
+ result);
+ break;
+ case HOME_OUTPUT:
+ //result = cmSystemTools::CollapseFullPath(result.c_str());
+ result =
+ this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
+ result);
+ break;
+ case START_OUTPUT:
+ //result = cmSystemTools::CollapseFullPath(result.c_str());
+ result =
+ this->ConvertToRelativePath(this->StartOutputDirectoryComponents,
+ result);
+ break;
+ case FULL:
+ result = cmSystemTools::CollapseFullPath(result.c_str());
+ break;
+ case NONE:
+ break;
+ }
+ }
+ return this->ConvertToOutputFormat(result, output);
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::ConvertToOutputFormat(const std::string& source,
+ OutputFormat output)
+{
+ std::string result = source;
+ // Convert it to an output path.
+ if (output == MAKERULE)
+ {
+ result = cmSystemTools::ConvertToOutputPath(result.c_str());
+ }
+ else if(output == SHELL || output == WATCOMQUOTE)
+ {
+ // For the MSYS shell convert drive letters to posix paths, so
+ // that c:/some/path becomes /c/some/path. This is needed to
+ // avoid problems with the shell path translation.
+ if(this->MSYSShell && !this->LinkScriptShell)
+ {
+ if(result.size() > 2 && result[1] == ':')
+ {
+ result[1] = result[0];
+ result[0] = '/';
+ }
+ }
+ if(this->WindowsShell)
+ {
+ std::string::size_type pos = 0;
+ while((pos = result.find('/', pos)) != std::string::npos)
+ {
+ result[pos] = '\\';
+ pos++;
+ }
+ }
+ result = this->EscapeForShell(result, true, false, output == WATCOMQUOTE);
+ }
+ else if(output == RESPONSE)
+ {
+ result = this->EscapeForShell(result, false, false, false);
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::Convert(RelativeRoot remote,
+ const std::string& local,
+ OutputFormat output,
+ bool optional)
+{
+ const char* remotePath = this->GetRelativeRootPath(remote);
+
+ // The relative root must have a path (i.e. not FULL or NONE)
+ assert(remotePath != 0);
+
+ if(!local.empty() && (!optional || this->UseRelativePaths))
+ {
+ std::vector<std::string> components;
+ cmSystemTools::SplitPath(local.c_str(), components);
+ std::string result = this->ConvertToRelativePath(components, remotePath);
+ return this->ConvertToOutputFormat(result, output);
+ }
+ else
+ {
+ return this->ConvertToOutputFormat(remotePath, output);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::FindRelativePathTopSource()
+{
+ // Relative path conversion within a single tree managed by CMake is
+ // safe. We can use our parent relative path top if and only if
+ // this is a subdirectory of that top.
+ if(cmLocalGenerator* parent = this->GetParent())
+ {
+ std::string parentTop = parent->FindRelativePathTopSource();
+ if(cmSystemTools::IsSubDirectory(
+ this->Makefile->GetStartDirectory(), parentTop.c_str()))
+ {
+ return parentTop;
+ }
+ }
+
+ // Otherwise this directory itself is the new top.
+ return this->Makefile->GetStartDirectory();
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::FindRelativePathTopBinary()
+{
+ // Relative path conversion within a single tree managed by CMake is
+ // safe. We can use our parent relative path top if and only if
+ // this is a subdirectory of that top.
+ if(cmLocalGenerator* parent = this->GetParent())
+ {
+ std::string parentTop = parent->FindRelativePathTopBinary();
+ if(cmSystemTools::IsSubDirectory(
+ this->Makefile->GetStartOutputDirectory(), parentTop.c_str()))
+ {
+ return parentTop;
+ }
+ }
+
+ // Otherwise this directory itself is the new top.
+ return this->Makefile->GetStartOutputDirectory();
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::ConfigureRelativePaths()
+{
+ // Relative path conversion inside the source tree is not used to
+ // construct relative paths passed to build tools so it is safe to
+ // even when the source is a network path.
+ std::string source = this->FindRelativePathTopSource();
+ this->RelativePathTopSource = source;
+
+ // The current working directory on Windows cannot be a network
+ // path. Therefore relative paths cannot work when the binary tree
+ // is a network path.
+ std::string binary = this->FindRelativePathTopBinary();
+ if(binary.size() < 2 || binary.substr(0, 2) != "//")
+ {
+ this->RelativePathTopBinary = binary;
+ }
+ else
+ {
+ this->RelativePathTopBinary = "";
+ }
+}
+
+//----------------------------------------------------------------------------
+static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
+{
+ return (cmSystemTools::ComparePath(a, b) ||
+ cmSystemTools::IsSubDirectory(a, b));
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
+ const std::string& in_remote,
+ bool force)
+{
+ // The path should never be quoted.
+ assert(in_remote[0] != '\"');
+
+ // The local path should never have a trailing slash.
+ assert(local.size() > 0 && !(local[local.size()-1] == ""));
+
+ // If the path is already relative then just return the path.
+ if(!cmSystemTools::FileIsFullPath(in_remote.c_str()))
+ {
+ return in_remote;
+ }
+
+ // Make sure relative path conversion is configured.
+ if(!this->RelativePathsConfigured)
+ {
+ this->ConfigureRelativePaths();
+ this->RelativePathsConfigured = true;
+ }
+
+ if(!force)
+ {
+ // Skip conversion if the path and local are not both in the source
+ // or both in the binary tree.
+ std::string local_path = cmSystemTools::JoinPath(local);
+ if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
+ this->RelativePathTopBinary.c_str()) &&
+ cmLocalGeneratorNotAbove(in_remote.c_str(),
+ this->RelativePathTopBinary.c_str())) ||
+ (cmLocalGeneratorNotAbove(local_path.c_str(),
+ this->RelativePathTopSource.c_str()) &&
+ cmLocalGeneratorNotAbove(in_remote.c_str(),
+ this->RelativePathTopSource.c_str()))))
+ {
+ return in_remote;
+ }
+ }
+
+ // Identify the longest shared path component between the remote
+ // path and the local path.
+ std::vector<std::string> remote;
+ cmSystemTools::SplitPath(in_remote.c_str(), remote);
+ unsigned int common=0;
+ while(common < remote.size() &&
+ common < local.size() &&
+ cmSystemTools::ComparePath(remote[common].c_str(),
+ local[common].c_str()))
+ {
+ ++common;
+ }
+
+ // If no part of the path is in common then return the full path.
+ if(common == 0)
+ {
+ return in_remote;
+ }
+
+ // If the entire path is in common then just return a ".".
+ if(common == remote.size() &&
+ common == local.size())
+ {
+ return ".";
+ }
+
+ // If the entire path is in common except for a trailing slash then
+ // just return a "./".
+ if(common+1 == remote.size() &&
+ remote[common].size() == 0 &&
+ common == local.size())
+ {
+ return "./";
+ }
+
+ // Construct the relative path.
+ std::string relative;
+
+ // First add enough ../ to get up to the level of the shared portion
+ // of the path. Leave off the trailing slash. Note that the last
+ // component of local will never be empty because local should never
+ // have a trailing slash.
+ for(unsigned int i=common; i < local.size(); ++i)
+ {
+ relative += "..";
+ if(i < local.size()-1)
+ {
+ relative += "/";
+ }
+ }
+
+ // Now add the portion of the destination path that is not included
+ // in the shared portion of the path. Add a slash the first time
+ // only if there was already something in the path. If there was a
+ // trailing slash in the input then the last iteration of the loop
+ // will add a slash followed by an empty string which will preserve
+ // the trailing slash in the output.
+ for(unsigned int i=common; i < remote.size(); ++i)
+ {
+ if(relative.size() > 0)
+ {
+ relative += "/";
+ }
+ relative += remote[i];
+ }
+
+ // Finally return the path.
+ return relative;
+}
+
+//----------------------------------------------------------------------------
+class cmInstallTargetGeneratorLocal: public cmInstallTargetGenerator
+{
+public:
+ cmInstallTargetGeneratorLocal(cmTarget& t, const char* dest, bool implib):
+ cmInstallTargetGenerator(
+ t, dest, implib, "", std::vector<std::string>(), "Unspecified",
+ cmInstallGenerator::SelectMessageLevel(t.GetMakefile()),
+ false) {}
+};
+
+//----------------------------------------------------------------------------
+void
+cmLocalGenerator
+::GenerateTargetInstallRules(
+ std::ostream& os, const std::string& config,
+ std::vector<std::string> const& configurationTypes)
+{
+ // 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)
+ {
+ if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+
+ // Include the user-specified pre-install script for this target.
+ if(const char* preinstall = l->second.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() != "")
+ {
+ // 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);
+ cmSystemTools::ConvertToUnixSlashes(destination);
+ if(destination.empty())
+ {
+ destination = ".";
+ }
+
+ // Generate the proper install generator for this target type.
+ switch(l->second.GetType())
+ {
+ case cmTarget::EXECUTABLE:
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ {
+ // Use a target install generator.
+ cmInstallTargetGeneratorLocal
+ g(l->second, destination.c_str(), false);
+ g.Generate(os, config, configurationTypes);
+ }
+ break;
+ case cmTarget::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(l->second, 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);
+ cmSystemTools::ConvertToUnixSlashes(destination);
+ cmInstallTargetGeneratorLocal
+ g2(l->second, destination.c_str(), false);
+ g2.Generate(os, config, configurationTypes);
+#else
+ // Use a target install generator.
+ cmInstallTargetGeneratorLocal
+ g(l->second, destination.c_str(), false);
+ g.Generate(os, config, configurationTypes);
+#endif
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ // Include the user-specified post-install script for this target.
+ if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
+ {
+ cmInstallScriptGenerator g(postinstall, false, 0);
+ g.Generate(os, config, configurationTypes);
+ }
+ }
+}
+
+#if defined(CM_LG_ENCODE_OBJECT_NAMES)
+static std::string cmLocalGeneratorMD5(const char* input)
+{
+ char md5out[32];
+ cmsysMD5* md5 = cmsysMD5_New();
+ cmsysMD5_Initialize(md5);
+ cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
+ cmsysMD5_FinalizeHex(md5, md5out);
+ cmsysMD5_Delete(md5);
+ return std::string(md5out, 32);
+}
+
+static bool
+cmLocalGeneratorShortenObjectName(std::string& objName,
+ std::string::size_type max_len)
+{
+ // Replace the beginning of the path portion of the object name with
+ // its own md5 sum.
+ std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
+ if(pos != objName.npos)
+ {
+ std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
+ md5name += objName.substr(pos);
+ objName = md5name;
+
+ // The object name is now short enough.
+ return true;
+ }
+ else
+ {
+ // The object name could not be shortened enough.
+ return false;
+ }
+}
+
+static
+bool cmLocalGeneratorCheckObjectName(std::string& objName,
+ std::string::size_type dir_len,
+ std::string::size_type max_total_len)
+{
+ // Enforce the maximum file name length if possible.
+ std::string::size_type max_obj_len = max_total_len;
+ if(dir_len < max_total_len)
+ {
+ max_obj_len = max_total_len - dir_len;
+ if(objName.size() > max_obj_len)
+ {
+ // The current object file name is too long. Try to shorten it.
+ return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
+ }
+ else
+ {
+ // The object file name is short enough.
+ return true;
+ }
+ }
+ else
+ {
+ // The build directory in which the object will be stored is
+ // already too deep.
+ return false;
+ }
+}
+#endif
+
+//----------------------------------------------------------------------------
+std::string&
+cmLocalGenerator
+::CreateSafeUniqueObjectFileName(const std::string& sin,
+ std::string const& dir_max)
+{
+ // Look for an existing mapped name for this object file.
+ std::map<std::string,std::string>::iterator it =
+ this->UniqueObjectNamesMap.find(sin);
+
+ // If no entry exists create one.
+ if(it == this->UniqueObjectNamesMap.end())
+ {
+ // Start with the original name.
+ std::string ssin = sin;
+
+ // Avoid full paths by removing leading slashes.
+ std::string::size_type pos = 0;
+ for(;pos < ssin.size() && ssin[pos] == '/'; ++pos)
+ {
+ }
+ ssin = ssin.substr(pos);
+
+ // Avoid full paths by removing colons.
+ cmSystemTools::ReplaceString(ssin, ":", "_");
+
+ // Avoid relative paths that go up the tree.
+ cmSystemTools::ReplaceString(ssin, "../", "__/");
+
+ // Avoid spaces.
+ cmSystemTools::ReplaceString(ssin, " ", "_");
+
+ // Mangle the name if necessary.
+ if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
+ {
+ bool done;
+ int cc = 0;
+ char rpstr[100];
+ sprintf(rpstr, "_p_");
+ cmSystemTools::ReplaceString(ssin, "+", rpstr);
+ std::string sssin = sin;
+ do
+ {
+ done = true;
+ for ( it = this->UniqueObjectNamesMap.begin();
+ it != this->UniqueObjectNamesMap.end();
+ ++ it )
+ {
+ if ( it->second == ssin )
+ {
+ done = false;
+ }
+ }
+ if ( done )
+ {
+ break;
+ }
+ sssin = ssin;
+ cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
+ sprintf(rpstr, "_p%d_", cc++);
+ }
+ while ( !done );
+ }
+
+#if defined(CM_LG_ENCODE_OBJECT_NAMES)
+ if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
+ this->ObjectPathMax))
+ {
+ // Warn if this is the first time the path has been seen.
+ if(this->ObjectMaxPathViolations.insert(dir_max).second)
+ {
+ cmOStringStream m;
+ m << "The object file directory\n"
+ << " " << dir_max << "\n"
+ << "has " << dir_max.size() << " characters. "
+ << "The maximum full path to an object file is "
+ << this->ObjectPathMax << " characters "
+ << "(see CMAKE_OBJECT_PATH_MAX). "
+ << "Object file\n"
+ << " " << ssin << "\n"
+ << "cannot be safely placed under this directory. "
+ << "The build may not work correctly.";
+ this->Makefile->IssueMessage(cmake::WARNING, m.str());
+ }
+ }
+#else
+ (void)dir_max;
+#endif
+
+ // Insert the newly mapped object file name.
+ std::map<std::string, std::string>::value_type e(sin, ssin);
+ it = this->UniqueObjectNamesMap.insert(e).first;
+ }
+
+ // Return the map entry.
+ return it->second;
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>&,
+ cmGeneratorTarget const*)
+{
+
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator
+::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
+ std::string const& dir_max,
+ bool* hasSourceExtension)
+{
+ // Construct the object file name using the full path to the source
+ // file which is its only unique identification.
+ const char* fullPath = source.GetFullPath().c_str();
+
+ // Try referencing the source relative to the source tree.
+ std::string relFromSource = this->Convert(fullPath, START);
+ assert(!relFromSource.empty());
+ bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
+ bool subSource = relSource && relFromSource[0] != '.';
+
+ // Try referencing the source relative to the binary tree.
+ std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
+ assert(!relFromBinary.empty());
+ bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
+ bool subBinary = relBinary && relFromBinary[0] != '.';
+
+ // Select a nice-looking reference to the source file to construct
+ // the object file name.
+ std::string objectName;
+ if((relSource && !relBinary) || (subSource && !subBinary))
+ {
+ objectName = relFromSource;
+ }
+ else if((relBinary && !relSource) || (subBinary && !subSource))
+ {
+ objectName = relFromBinary;
+ }
+ else if(relFromBinary.length() < relFromSource.length())
+ {
+ objectName = relFromBinary;
+ }
+ else
+ {
+ objectName = relFromSource;
+ }
+
+ // if it is still a full path check for the try compile case
+ // try compile never have in source sources, and should not
+ // have conflicting source file names in the same target
+ if(cmSystemTools::FileIsFullPath(objectName.c_str()))
+ {
+ if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
+ {
+ objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
+ }
+ }
+
+ // Replace the original source file extension with the object file
+ // extension.
+ bool keptSourceExtension = true;
+ if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
+ {
+ // Decide whether this language wants to replace the source
+ // extension with the object extension. For CMake 2.4
+ // compatibility do this by default.
+ bool replaceExt = this->NeedBackwardsCompatibility_2_4();
+ if(!replaceExt)
+ {
+ std::string lang = source.GetLanguage();
+ if(!lang.empty())
+ {
+ std::string repVar = "CMAKE_";
+ repVar += lang;
+ repVar += "_OUTPUT_EXTENSION_REPLACE";
+ replaceExt = this->Makefile->IsOn(repVar);
+ }
+ }
+
+ // Remove the source extension if it is to be replaced.
+ if(replaceExt)
+ {
+ keptSourceExtension = false;
+ std::string::size_type dot_pos = objectName.rfind(".");
+ if(dot_pos != std::string::npos)
+ {
+ objectName = objectName.substr(0, dot_pos);
+ }
+ }
+
+ // Store the new extension.
+ objectName +=
+ this->GlobalGenerator->GetLanguageOutputExtension(source);
+ }
+ if(hasSourceExtension)
+ {
+ *hasSourceExtension = keptSourceExtension;
+ }
+
+ // Convert to a safe name.
+ return this->CreateSafeUniqueObjectFileName(objectName, dir_max);
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator
+::GetSourceFileLanguage(const cmSourceFile& source)
+{
+ return source.GetLanguage();
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::EscapeForShellOldStyle(const std::string& str)
+{
+ std::string result;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ // if there are spaces
+ std::string temp = str;
+ if (temp.find(" ") != std::string::npos &&
+ temp.find("\"")==std::string::npos)
+ {
+ result = "\"";
+ result += str;
+ result += "\"";
+ return result;
+ }
+ return str;
+#else
+ for(const char* ch = str.c_str(); *ch != '\0'; ++ch)
+ {
+ if(*ch == ' ')
+ {
+ result += '\\';
+ }
+ result += *ch;
+ }
+ return result;
+#endif
+}
+
+//----------------------------------------------------------------------------
+static bool cmLocalGeneratorIsShellOperator(const std::string& str)
+{
+ static std::set<std::string> shellOperators;
+ if(shellOperators.empty())
+ {
+ shellOperators.insert("<");
+ shellOperators.insert(">");
+ shellOperators.insert("<<");
+ shellOperators.insert(">>");
+ shellOperators.insert("|");
+ shellOperators.insert("||");
+ shellOperators.insert("&&");
+ shellOperators.insert("&>");
+ shellOperators.insert("1>");
+ shellOperators.insert("2>");
+ shellOperators.insert("2>&1");
+ shellOperators.insert("1>&2");
+ }
+ return shellOperators.count(str) > 0;
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::EscapeForShell(const std::string& str,
+ bool makeVars,
+ bool forEcho,
+ bool useWatcomQuote)
+{
+ // Do not escape shell operators.
+ if(cmLocalGeneratorIsShellOperator(str))
+ {
+ return str;
+ }
+
+ // Compute the flags for the target shell environment.
+ int flags = 0;
+ if(this->WindowsVSIDE)
+ {
+ flags |= cmsysSystem_Shell_Flag_VSIDE;
+ }
+ else if(!this->LinkScriptShell)
+ {
+ flags |= cmsysSystem_Shell_Flag_Make;
+ }
+ if(makeVars)
+ {
+ flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
+ }
+ if(forEcho)
+ {
+ flags |= cmsysSystem_Shell_Flag_EchoWindows;
+ }
+ if(useWatcomQuote)
+ {
+ flags |= cmsysSystem_Shell_Flag_WatcomQuote;
+ }
+ if(this->WatcomWMake)
+ {
+ flags |= cmsysSystem_Shell_Flag_WatcomWMake;
+ }
+ if(this->MinGWMake)
+ {
+ flags |= cmsysSystem_Shell_Flag_MinGWMake;
+ }
+ if(this->NMake)
+ {
+ flags |= cmsysSystem_Shell_Flag_NMake;
+ }
+
+ // Compute the buffer size needed.
+ int size = (this->WindowsShell ?
+ cmsysSystem_Shell_GetArgumentSizeForWindows(str.c_str(), flags) :
+ cmsysSystem_Shell_GetArgumentSizeForUnix(str.c_str(), flags));
+
+ // Compute the shell argument itself.
+ std::vector<char> arg(size);
+ if(this->WindowsShell)
+ {
+ cmsysSystem_Shell_GetArgumentForWindows(str.c_str(), &arg[0], flags);
+ }
+ else
+ {
+ cmsysSystem_Shell_GetArgumentForUnix(str.c_str(), &arg[0], flags);
+ }
+ return std::string(&arg[0]);
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::EscapeForCMake(const std::string& str)
+{
+ // Always double-quote the argument to take care of most escapes.
+ std::string result = "\"";
+ for(const char* c = str.c_str(); *c; ++c)
+ {
+ if(*c == '"')
+ {
+ // Escape the double quote to avoid ending the argument.
+ result += "\\\"";
+ }
+ else if(*c == '$')
+ {
+ // Escape the dollar to avoid expanding variables.
+ result += "\\$";
+ }
+ else if(*c == '\\')
+ {
+ // Escape the backslash to avoid other escapes.
+ result += "\\\\";
+ }
+ else
+ {
+ // Other characters will be parsed correctly.
+ result += *c;
+ }
+ }
+ result += "\"";
+ return result;
+}
+
+//----------------------------------------------------------------------------
+cmLocalGenerator::FortranFormat
+cmLocalGenerator::GetFortranFormat(const char* value)
+{
+ FortranFormat format = FortranFormatNone;
+ if(value && *value)
+ {
+ std::vector<std::string> fmt;
+ cmSystemTools::ExpandListArgument(value, fmt);
+ for(std::vector<std::string>::iterator fi = fmt.begin();
+ fi != fmt.end(); ++fi)
+ {
+ if(*fi == "FIXED")
+ {
+ format = FortranFormatFixed;
+ }
+ if(*fi == "FREE")
+ {
+ format = FortranFormatFree;
+ }
+ }
+ }
+ return format;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
+{
+ cmSystemTools::Error("GetTargetDirectory"
+ " called on cmLocalGenerator");
+ return "";
+}
+
+//----------------------------------------------------------------------------
+cmIML_INT_uint64_t cmLocalGenerator::GetBackwardsCompatibility()
+{
+ // The computed version may change until the project is fully
+ // configured.
+ if(!this->BackwardsCompatibilityFinal)
+ {
+ unsigned int major = 0;
+ unsigned int minor = 0;
+ unsigned int patch = 0;
+ if(const char* value
+ = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
+ {
+ switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
+ {
+ case 2: patch = 0; break;
+ case 1: minor = 0; patch = 0; break;
+ default: break;
+ }
+ }
+ this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
+ this->BackwardsCompatibilityFinal = this->Configured;
+ }
+
+ return this->BackwardsCompatibility;
+}
+
+//----------------------------------------------------------------------------
+bool cmLocalGenerator::NeedBackwardsCompatibility_2_4()
+{
+ // Check the policy to decide whether to pay attention to this
+ // variable.
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
+ {
+ case cmPolicies::WARN:
+ // WARN is just OLD without warning because user code does not
+ // always affect whether this check is done.
+ case cmPolicies::OLD:
+ // Old behavior is to check the variable.
+ break;
+ case cmPolicies::NEW:
+ // New behavior is to ignore the variable.
+ return false;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ // This will never be the case because the only way to require
+ // the setting is to require the user to specify version policy
+ // 2.6 or higher. Once we add that requirement then this whole
+ // method can be removed anyway.
+ return false;
+ }
+
+ // 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();
+ return (actual_compat &&
+ actual_compat <= CMake_VERSION_ENCODE(2, 4, 255));
+}
+
+//----------------------------------------------------------------------------
+bool cmLocalGenerator::CheckDefinition(std::string const& define) const
+{
+ // Many compilers do not support -DNAME(arg)=sdf so we disable it.
+ bool function_style = false;
+ for(const char* c = define.c_str(); *c && *c != '='; ++c)
+ {
+ if(*c == '(')
+ {
+ function_style = true;
+ break;
+ }
+ }
+ if(function_style)
+ {
+ cmOStringStream e;
+ e << "WARNING: Function-style preprocessor definitions may not be "
+ << "passed on the compiler command line because many compilers "
+ << "do not support it.\n"
+ << "CMake is dropping a preprocessor definition: " << define << "\n"
+ << "Consider defining the macro in a (configured) header file.\n";
+ cmSystemTools::Message(e.str().c_str());
+ return false;
+ }
+
+ // Many compilers do not support # in the value so we disable it.
+ if(define.find_first_of("#") != define.npos)
+ {
+ cmOStringStream e;
+ e << "WARNING: Preprocessor definitions containing '#' may not be "
+ << "passed on the compiler command line because many compilers "
+ << "do not support it.\n"
+ << "CMake is dropping a preprocessor definition: " << define << "\n"
+ << "Consider defining the macro in a (configured) header file.\n";
+ cmSystemTools::Message(e.str().c_str());
+ return false;
+ }
+
+ // Assume it is supported.
+ return true;
+}
+
+//----------------------------------------------------------------------------
+static void cmLGInfoProp(cmMakefile* mf, cmTarget* target,
+ const std::string& prop)
+{
+ if(const char* val = target->GetProperty(prop))
+ {
+ mf->AddDefinition(prop, val);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
+ const std::string& targetName,
+ const char* fname)
+{
+ // Find the Info.plist template.
+ const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
+ std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
+ if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
+ {
+ std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
+ if(!inMod.empty())
+ {
+ inFile = inMod;
+ }
+ }
+ if(!cmSystemTools::FileExists(inFile.c_str(), true))
+ {
+ cmOStringStream e;
+ e << "Target " << target->GetName() << " Info.plist template \""
+ << inFile << "\" could not be found.";
+ cmSystemTools::Error(e.str().c_str());
+ return;
+ }
+
+ // Convert target properties to variables in an isolated makefile
+ // scope to configure the file. If properties are set they will
+ // override user make variables. If not the configuration will fall
+ // back to the directory-level values set by the user.
+ cmMakefile* mf = this->Makefile;
+ mf->PushScope();
+ mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName.c_str());
+ cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
+ cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
+ cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
+ cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
+ cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
+ cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
+ cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
+ cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
+ mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
+ mf->PopScope();
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
+ const std::string& targetName,
+ const char* fname)
+{
+ // Find the Info.plist template.
+ const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
+ std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
+ if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
+ {
+ std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
+ if(!inMod.empty())
+ {
+ inFile = inMod;
+ }
+ }
+ if(!cmSystemTools::FileExists(inFile.c_str(), true))
+ {
+ cmOStringStream e;
+ e << "Target " << target->GetName() << " Info.plist template \""
+ << inFile << "\" could not be found.";
+ cmSystemTools::Error(e.str().c_str());
+ return;
+ }
+
+ // Convert target properties to variables in an isolated makefile
+ // scope to configure the file. If properties are set they will
+ // override user make variables. If not the configuration will fall
+ // back to the directory-level values set by the user.
+ cmMakefile* mf = this->Makefile;
+ mf->PushScope();
+ mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName.c_str());
+ cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
+ cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
+ cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
+ cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
+ mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
+ mf->PopScope();
+}
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
new file mode 100644
index 0000000000..3a9d5be808
--- /dev/null
+++ b/Source/cmLocalGenerator.h
@@ -0,0 +1,503 @@
+/*============================================================================
+ 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 cmLocalGenerator_h
+#define cmLocalGenerator_h
+
+#include "cmStandardIncludes.h"
+
+class cmMakefile;
+class cmGlobalGenerator;
+class cmGeneratorTarget;
+class cmTarget;
+class cmTargetManifest;
+class cmSourceFile;
+class cmCustomCommand;
+class cmCustomCommandGenerator;
+
+/** \class cmLocalGenerator
+ * \brief Create required build files for a directory.
+ *
+ * Subclasses of this abstract class generate makefiles, DSP, etc for various
+ * platforms. This class should never be constructed directly. A
+ * GlobalGenerator will create it and invoke the appropriate commands on it.
+ */
+class cmLocalGenerator
+{
+public:
+ cmLocalGenerator();
+ virtual ~cmLocalGenerator();
+
+ /**
+ * Generate the makefile for this directory.
+ */
+ virtual void Generate() {}
+
+ /**
+ * Process the CMakeLists files for this directory to fill in the
+ * Makefile ivar
+ */
+ virtual void Configure();
+
+ /**
+ * Calls TraceVSDependencies() on all targets of this generator.
+ */
+ void TraceDependencies();
+
+ virtual void AddHelperCommands() {}
+
+ /**
+ * Perform any final calculations prior to generation
+ */
+ void ConfigureFinalPass();
+
+ /**
+ * Generate the install rules files in this directory.
+ */
+ void GenerateInstallRules();
+
+ /**
+ * Generate the test files for tests.
+ */
+ void GenerateTestFiles();
+
+ /**
+ * Generate a manifest of target files that will be built.
+ */
+ void GenerateTargetManifest();
+
+ ///! Get the makefile for this generator
+ cmMakefile *GetMakefile() {
+ return this->Makefile; }
+
+ ///! Get the makefile for this generator, const version
+ const cmMakefile *GetMakefile() const {
+ return this->Makefile; }
+
+ ///! Get the GlobalGenerator this is associated with
+ cmGlobalGenerator *GetGlobalGenerator() {
+ return this->GlobalGenerator; }
+ const cmGlobalGenerator *GetGlobalGenerator() const {
+ return this->GlobalGenerator; }
+
+ ///! Set the Global Generator, done on creation by the GlobalGenerator
+ void SetGlobalGenerator(cmGlobalGenerator *gg);
+
+ /**
+ * Convert something to something else. This is a centralized conversion
+ * routine used by the generators to handle relative paths and the like.
+ * The flags determine what is actually done.
+ *
+ * relative: treat the argument as a directory and convert it to make it
+ * relative or full or unchanged. If relative (HOME, START etc) then that
+ * specifies what it should be relative to.
+ *
+ * output: make the result suitable for output to a...
+ *
+ * optional: should any relative path operation be controlled by the rel
+ * path setting
+ */
+ enum RelativeRoot { NONE, FULL, HOME, START, HOME_OUTPUT, START_OUTPUT };
+ enum OutputFormat { UNCHANGED, MAKERULE, SHELL, WATCOMQUOTE, RESPONSE };
+ std::string ConvertToOutputFormat(const std::string& source,
+ OutputFormat output);
+ std::string Convert(const std::string& remote, RelativeRoot local,
+ OutputFormat output = UNCHANGED,
+ bool optional = false);
+ std::string Convert(RelativeRoot remote, const std::string& local,
+ OutputFormat output = UNCHANGED,
+ bool optional = false);
+
+ /**
+ * Get path for the specified relative root.
+ */
+ const char* GetRelativeRootPath(RelativeRoot relroot);
+
+ /**
+ * Convert the given path to an output path that is optionally
+ * relative based on the cache option CMAKE_USE_RELATIVE_PATHS. The
+ * remote path must use forward slashes and not already be escaped
+ * or quoted.
+ */
+ std::string ConvertToOptionallyRelativeOutputPath(const std::string& remote);
+
+ ///! set/get the parent generator
+ cmLocalGenerator* GetParent(){return this->Parent;}
+ void SetParent(cmLocalGenerator* g) { this->Parent = g; g->AddChild(this); }
+
+ ///! set/get the children
+ void AddChild(cmLocalGenerator* g) { this->Children.push_back(g); }
+ std::vector<cmLocalGenerator*>& GetChildren() { return this->Children; }
+
+
+ void AddArchitectureFlags(std::string& flags, cmGeneratorTarget* target,
+ const std::string&lang, const std::string& config);
+
+ void AddLanguageFlags(std::string& flags, const std::string& lang,
+ const std::string& config);
+ void AddCMP0018Flags(std::string &flags, cmTarget* target,
+ std::string const& lang, const std::string& config);
+ void AddVisibilityPresetFlags(std::string &flags, cmTarget* target,
+ const std::string& lang);
+ void AddConfigVariableFlags(std::string& flags, const std::string& var,
+ const std::string& config);
+ void AddCompilerRequirementFlag(std::string &flags, cmTarget* target,
+ const std::string& lang);
+ ///! Append flags to a string.
+ virtual void AppendFlags(std::string& flags, const std::string& newFlags);
+ virtual void AppendFlags(std::string& flags, const char* newFlags);
+ virtual void AppendFlagEscape(std::string& flags,
+ const std::string& rawFlag);
+ ///! Get the include flags for the current makefile and language
+ std::string GetIncludeFlags(const std::vector<std::string> &includes,
+ cmGeneratorTarget* target,
+ const std::string& lang,
+ bool forceFullPaths = false,
+ bool forResponseFile = false,
+ const std::string& config = "");
+
+ /**
+ * Encode a list of preprocessor definitions for the compiler
+ * command line.
+ */
+ void AppendDefines(std::set<std::string>& defines,
+ const char* defines_list);
+ void AppendDefines(std::set<std::string>& defines,
+ std::string defines_list)
+ {
+ this->AppendDefines(defines, defines_list.c_str());
+ }
+ void AppendDefines(std::set<std::string>& defines,
+ const std::vector<std::string> &defines_vec);
+
+ /**
+ * Join a set of defines into a definesString with a space separator.
+ */
+ void JoinDefines(const std::set<std::string>& defines,
+ std::string &definesString,
+ const std::string& lang);
+
+ /** Lookup and append options associated with a particular feature. */
+ void AppendFeatureOptions(std::string& flags, const std::string& lang,
+ const char* feature);
+
+ /** \brief Get absolute path to dependency \a name
+ *
+ * Translate a dependency as given in CMake code to the name to
+ * appear in a generated build file.
+ * - If \a name is a utility target, returns false.
+ * - If \a name is a CMake target, it will be transformed to the real output
+ * location of that target for the given configuration.
+ * - If \a name is the full path to a file, it will be returned.
+ * - Otherwise \a name is treated as a relative path with respect to
+ * the source directory of this generator. This should only be
+ * used for dependencies of custom commands.
+ */
+ bool GetRealDependency(const std::string& name, const std::string& config,
+ std::string& dep);
+
+ ///! for existing files convert to output path and short path if spaces
+ std::string ConvertToOutputForExisting(const std::string& remote,
+ RelativeRoot local = START_OUTPUT,
+ OutputFormat format = SHELL);
+
+ /** For existing path identified by RelativeRoot convert to output
+ path and short path if spaces. */
+ std::string ConvertToOutputForExisting(RelativeRoot remote,
+ const std::string& local = "",
+ OutputFormat format = SHELL);
+
+ virtual std::string ConvertToIncludeReference(std::string const& path,
+ OutputFormat format = SHELL,
+ bool forceFullPaths = false);
+
+ /** Called from command-line hook to clear dependencies. */
+ virtual void ClearDependencies(cmMakefile* /* mf */,
+ bool /* verbose */) {}
+
+ /** Called from command-line hook to update dependencies. */
+ virtual bool UpdateDependencies(const char* /* tgtInfo */,
+ bool /*verbose*/,
+ bool /*color*/)
+ { return true; }
+
+ /** Get the include flags for the current makefile and language. */
+ void GetIncludeDirectories(std::vector<std::string>& dirs,
+ cmGeneratorTarget* target,
+ const std::string& lang = "C",
+ const std::string& config = "",
+ bool stripImplicitInclDirs = true);
+ void AddCompileOptions(std::string& flags, cmTarget* target,
+ const std::string& lang, const std::string& config);
+ void AddCompileDefinitions(std::set<std::string>& defines,
+ cmTarget const* target,
+ const std::string& config);
+
+ /** 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>&) {}
+
+ // Create a struct to hold the varibles passed into
+ // ExpandRuleVariables
+ struct RuleVariables
+ {
+ RuleVariables()
+ {
+ memset(this, 0, sizeof(*this));
+ }
+ cmTarget* CMTarget;
+ const char* TargetPDB;
+ const char* TargetCompilePDB;
+ const char* TargetVersionMajor;
+ const char* TargetVersionMinor;
+ const char* Language;
+ const char* Objects;
+ const char* Target;
+ const char* LinkLibraries;
+ const char* Source;
+ const char* AssemblySource;
+ const char* PreprocessedSource;
+ const char* Output;
+ const char* Object;
+ const char* ObjectDir;
+ const char* ObjectFileDir;
+ const char* Flags;
+ const char* ObjectsQuoted;
+ const char* SONameFlag;
+ const char* TargetSOName;
+ const char* TargetInstallNameDir;
+ const char* LinkFlags;
+ const char* LanguageCompileFlags;
+ const char* Defines;
+ const char* RuleLauncher;
+ const char* DependencyFile;
+ const char* FilterPrefix;
+ };
+
+ /** Set whether to treat conversions to SHELL as a link script shell. */
+ void SetLinkScriptShell(bool b) { this->LinkScriptShell = b; }
+
+ /** Escape the given string to be used as a command line argument in
+ the native build system shell. Optionally allow the build
+ system to replace make variable references. Optionally adjust
+ escapes for the special case of passing to the native echo
+ command. */
+ std::string EscapeForShell(const std::string& str, bool makeVars = false,
+ bool forEcho = false,
+ bool useWatcomQuote = false);
+
+ /** Backwards-compatibility version of EscapeForShell. */
+ std::string EscapeForShellOldStyle(const std::string& str);
+
+ /** Escape the given string as an argument in a CMake script. */
+ static std::string EscapeForCMake(const std::string& str);
+
+ enum FortranFormat
+ {
+ FortranFormatNone,
+ FortranFormatFixed,
+ FortranFormatFree
+ };
+ FortranFormat GetFortranFormat(const char* value);
+
+ /**
+ * Convert the given remote path to a relative path with respect to
+ * the given local path. The local path must be given in component
+ * form (see SystemTools::SplitPath) without a trailing slash. The
+ * remote path must use forward slashes and not already be escaped
+ * or quoted.
+ */
+ std::string ConvertToRelativePath(const std::vector<std::string>& local,
+ const std::string& remote,
+ bool force=false);
+
+ /**
+ * Get the relative path from the generator output directory to a
+ * per-target support directory.
+ */
+ virtual std::string GetTargetDirectory(cmTarget const& target) const;
+
+ /**
+ * Get the level of backwards compatibility requested by the project
+ * in this directory. This is the value of the CMake variable
+ * CMAKE_BACKWARDS_COMPATIBILITY whose format is
+ * "major.minor[.patch]". The returned integer is encoded as
+ *
+ * CMake_VERSION_ENCODE(major, minor, patch)
+ *
+ * and is monotonically increasing with the CMake version.
+ */
+ cmIML_INT_uint64_t GetBackwardsCompatibility();
+
+ /**
+ * Test whether compatibility is set to a given version or lower.
+ */
+ bool NeedBackwardsCompatibility_2_4();
+
+ /**
+ * Generate a Mac OS X application bundle Info.plist file.
+ */
+ void GenerateAppleInfoPList(cmTarget* target, const std::string& targetName,
+ const char* fname);
+
+ /**
+ * Generate a Mac OS X framework Info.plist file.
+ */
+ void GenerateFrameworkInfoPList(cmTarget* target,
+ const std::string& targetName,
+ const char* fname);
+ /** Construct a comment for a custom command. */
+ std::string ConstructComment(cmCustomCommandGenerator const& ccg,
+ const char* default_comment = "");
+ // Compute object file names.
+ std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source,
+ std::string const& dir_max,
+ bool* hasSourceExtension = 0);
+
+ /** Fill out the static linker flags for the given target. */
+ void GetStaticLibraryFlags(std::string& flags,
+ std::string const& config,
+ cmTarget* target);
+
+ /** Fill out these strings for the given target. Libraries to link,
+ * flags, and linkflags. */
+ void GetTargetFlags(std::string& linkLibs,
+ std::string& flags,
+ std::string& linkFlags,
+ std::string& frameworkPath,
+ std::string& linkPath,
+ cmGeneratorTarget* target,
+ bool useWatcomQuote);
+
+ virtual void ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt = 0);
+
+protected:
+ ///! put all the libraries for a target on into the given stream
+ virtual void OutputLinkLibraries(std::string& linkLibraries,
+ std::string& frameworkPath,
+ std::string& linkPath,
+ cmGeneratorTarget &,
+ bool relink,
+ bool forResponseFile,
+ bool useWatcomQuote);
+
+ // Expand rule variables in CMake of the type found in language rules
+ void ExpandRuleVariables(std::string& string,
+ const RuleVariables& replaceValues);
+ // Expand rule variables in a single string
+ 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 std::string& prop);
+
+
+ /** Convert a target to a utility target for unsupported
+ * languages of a generator */
+ void AddBuildTargetRule(const std::string& llang,
+ cmGeneratorTarget& target);
+ ///! add a custom command to build a .o file that is part of a target
+ void AddCustomCommandToCreateObject(const char* ofname,
+ const std::string& lang,
+ cmSourceFile& source,
+ cmGeneratorTarget& target);
+ // Create Custom Targets and commands for unsupported languages
+ // The set passed in should contain the languages supported by the
+ // generator directly. Any targets containing files that are not
+ // of the types listed will be compiled as custom commands and added
+ // to a custom target.
+ void CreateCustomTargetsAndCommands(std::set<std::string> const&);
+
+ // Handle old-style install rules stored in the targets.
+ void GenerateTargetInstallRules(
+ std::ostream& os, const std::string& config,
+ std::vector<std::string> const& configurationTypes);
+
+ std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
+ std::string const& dir_max);
+ void ComputeObjectMaxPath();
+
+ void ConfigureRelativePaths();
+ std::string FindRelativePathTopSource();
+ std::string FindRelativePathTopBinary();
+ void SetupPathConversions();
+
+ virtual std::string ConvertToLinkReference(std::string const& lib,
+ OutputFormat format = SHELL);
+
+ /** Check whether the native build system supports the given
+ definition. Issues a warning. */
+ virtual bool CheckDefinition(std::string const& define) const;
+
+ /** Read the input CMakeLists.txt file. */
+ void ReadInputFile();
+
+ cmMakefile *Makefile;
+ cmGlobalGenerator *GlobalGenerator;
+ // members used for relative path function ConvertToMakefilePath
+ std::string RelativePathToSourceDir;
+ std::string RelativePathToBinaryDir;
+ std::vector<std::string> HomeDirectoryComponents;
+ std::vector<std::string> StartDirectoryComponents;
+ std::vector<std::string> HomeOutputDirectoryComponents;
+ std::vector<std::string> StartOutputDirectoryComponents;
+ cmLocalGenerator* Parent;
+ std::vector<cmLocalGenerator*> Children;
+ std::map<std::string, std::string> UniqueObjectNamesMap;
+ std::string::size_type ObjectPathMax;
+ std::set<std::string> ObjectMaxPathViolations;
+ bool WindowsShell;
+ bool WindowsVSIDE;
+ bool WatcomWMake;
+ bool MinGWMake;
+ bool NMake;
+ bool ForceUnixPath;
+ bool MSYSShell;
+ bool LinkScriptShell;
+ bool UseRelativePaths;
+ bool IgnoreLibPrefix;
+ bool Configured;
+ bool EmitUniversalBinaryFlags;
+ // Hack for ExpandRuleVariable until object-oriented version is
+ // committed.
+ std::string TargetImplib;
+
+ // The top-most directories for relative path conversion. Both the
+ // source and destination location of a relative path conversion
+ // must be underneath one of these directories (both under source or
+ // both under binary) in order for the relative path to be evaluated
+ // safely by the build tools.
+ std::string RelativePathTopSource;
+ std::string RelativePathTopBinary;
+ bool RelativePathsConfigured;
+ bool PathConversionsSetup;
+
+ cmIML_INT_uint64_t BackwardsCompatibility;
+ bool BackwardsCompatibilityFinal;
+private:
+ std::string ConvertToOutputForExistingCommon(const std::string& remote,
+ std::string const& result,
+ OutputFormat format);
+
+ void AddSharedFlags(std::string& flags, const std::string& lang,
+ bool shared);
+ bool GetShouldUseOldFlags(bool shared, const std::string &lang) const;
+ void AddPositionIndependentFlags(std::string& flags, std::string const& l,
+ int targetType);
+};
+
+#endif
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
new file mode 100644
index 0000000000..398b55a452
--- /dev/null
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -0,0 +1,551 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 "cmLocalNinjaGenerator.h"
+#include "cmCustomCommandGenerator.h"
+#include "cmMakefile.h"
+#include "cmGlobalNinjaGenerator.h"
+#include "cmNinjaTargetGenerator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmSourceFile.h"
+#include "cmake.h"
+
+#include <assert.h>
+
+cmLocalNinjaGenerator::cmLocalNinjaGenerator()
+ : cmLocalGenerator()
+ , ConfigName("")
+ , HomeRelativeOutputPath("")
+{
+#ifdef _WIN32
+ this->WindowsShell = true;
+#endif
+ this->TargetImplib = "$TARGET_IMPLIB";
+}
+
+//----------------------------------------------------------------------------
+// Virtual public methods.
+
+cmLocalNinjaGenerator::~cmLocalNinjaGenerator()
+{
+}
+
+void cmLocalNinjaGenerator::Generate()
+{
+ this->SetConfigName();
+
+ this->WriteProcessedMakefile(this->GetBuildFileStream());
+#ifdef NINJA_GEN_VERBOSE_FILES
+ this->WriteProcessedMakefile(this->GetRulesFileStream());
+#endif
+
+ // We do that only once for the top CMakeLists.txt file.
+ if(this->isRootMakefile())
+ {
+ this->WriteBuildFileTop();
+
+ this->WritePools(this->GetRulesFileStream());
+
+ const std::string showIncludesPrefix = this->GetMakefile()
+ ->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX");
+ if (!showIncludesPrefix.empty())
+ {
+ cmGlobalNinjaGenerator::WriteComment(this->GetRulesFileStream(),
+ "localized /showIncludes string");
+ this->GetRulesFileStream()
+ << "msvc_deps_prefix = " << showIncludesPrefix << "\n\n";
+ }
+ }
+
+ cmGeneratorTargetsType targets = this->GetMakefile()->GetGeneratorTargets();
+ for(cmGeneratorTargetsType::iterator t = targets.begin();
+ t != targets.end(); ++t)
+ {
+ if (t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY
+ || t->second->Target->IsImported())
+ {
+ continue;
+ }
+ cmNinjaTargetGenerator* tg = cmNinjaTargetGenerator::New(t->second);
+ if(tg)
+ {
+ tg->Generate();
+ // Add the target to "all" if required.
+ if (!this->GetGlobalNinjaGenerator()->IsExcluded(
+ this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0],
+ *t->second->Target))
+ this->GetGlobalNinjaGenerator()->AddDependencyToAll(t->second->Target);
+ delete tg;
+ }
+ }
+
+ this->WriteCustomCommandBuildStatements();
+}
+
+// Implemented in:
+// cmLocalUnixMakefileGenerator3.
+// Used in:
+// Source/cmMakefile.cxx
+// Source/cmGlobalGenerator.cxx
+void cmLocalNinjaGenerator::Configure()
+{
+ // Compute the path to use when referencing the current output
+ // directory from the top output directory.
+ this->HomeRelativeOutputPath =
+ this->Convert(this->Makefile->GetStartOutputDirectory(), HOME_OUTPUT);
+ if(this->HomeRelativeOutputPath == ".")
+ {
+ this->HomeRelativeOutputPath = "";
+ }
+ this->cmLocalGenerator::Configure();
+
+}
+
+// TODO: Picked up from cmLocalUnixMakefileGenerator3. Refactor it.
+std::string cmLocalNinjaGenerator
+::GetTargetDirectory(cmTarget const& target) const
+{
+ std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
+ dir += target.GetName();
+#if defined(__VMS)
+ dir += "_dir";
+#else
+ dir += ".dir";
+#endif
+ return dir;
+}
+
+//----------------------------------------------------------------------------
+// Non-virtual public methods.
+
+const cmGlobalNinjaGenerator*
+cmLocalNinjaGenerator::GetGlobalNinjaGenerator() const
+{
+ return
+ static_cast<const cmGlobalNinjaGenerator*>(this->GetGlobalGenerator());
+}
+
+cmGlobalNinjaGenerator* cmLocalNinjaGenerator::GetGlobalNinjaGenerator()
+{
+ return static_cast<cmGlobalNinjaGenerator*>(this->GetGlobalGenerator());
+}
+
+//----------------------------------------------------------------------------
+// Virtual protected methods.
+
+std::string
+cmLocalNinjaGenerator::ConvertToLinkReference(std::string const& lib,
+ OutputFormat format)
+{
+ return this->Convert(lib, HOME_OUTPUT, format);
+}
+
+std::string
+cmLocalNinjaGenerator::ConvertToIncludeReference(std::string const& path,
+ OutputFormat format,
+ bool forceFullPaths)
+{
+ return this->Convert(path, forceFullPaths? FULL : HOME_OUTPUT, format);
+}
+
+//----------------------------------------------------------------------------
+// Private methods.
+
+cmGeneratedFileStream& cmLocalNinjaGenerator::GetBuildFileStream() const
+{
+ return *this->GetGlobalNinjaGenerator()->GetBuildFileStream();
+}
+
+cmGeneratedFileStream& cmLocalNinjaGenerator::GetRulesFileStream() const
+{
+ return *this->GetGlobalNinjaGenerator()->GetRulesFileStream();
+}
+
+const cmake* cmLocalNinjaGenerator::GetCMakeInstance() const
+{
+ return this->GetGlobalGenerator()->GetCMakeInstance();
+}
+
+cmake* cmLocalNinjaGenerator::GetCMakeInstance()
+{
+ return this->GetGlobalGenerator()->GetCMakeInstance();
+}
+
+bool cmLocalNinjaGenerator::isRootMakefile() const
+{
+ return (strcmp(this->Makefile->GetCurrentDirectory(),
+ this->GetCMakeInstance()->GetHomeDirectory()) == 0);
+}
+
+void cmLocalNinjaGenerator::WriteBuildFileTop()
+{
+ // For the build file.
+ this->WriteProjectHeader(this->GetBuildFileStream());
+ this->WriteNinjaRequiredVersion(this->GetBuildFileStream());
+ this->WriteNinjaFilesInclusion(this->GetBuildFileStream());
+
+ // For the rule file.
+ this->WriteProjectHeader(this->GetRulesFileStream());
+}
+
+void cmLocalNinjaGenerator::WriteProjectHeader(std::ostream& os)
+{
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os
+ << "# Project: " << this->GetMakefile()->GetProjectName() << std::endl
+ << "# Configuration: " << this->ConfigName << std::endl
+ ;
+ cmGlobalNinjaGenerator::WriteDivider(os);
+}
+
+void cmLocalNinjaGenerator::WriteNinjaRequiredVersion(std::ostream& os)
+{
+ // Default required version
+ // Ninja generator uses 'deps' and 'msvc_deps_prefix' introduced in 1.3
+ std::string requiredVersion = "1.3";
+
+ // Ninja generator uses the 'console' pool if available (>= 1.5)
+ std::string usedVersion = this->GetGlobalNinjaGenerator()->ninjaVersion();
+ if(cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
+ usedVersion.c_str(),
+ "1.5") == false)
+ {
+ requiredVersion = "1.5";
+ }
+
+ cmGlobalNinjaGenerator::WriteComment(os,
+ "Minimal version of Ninja required by this file");
+ os
+ << "ninja_required_version = "
+ << requiredVersion
+ << std::endl << std::endl
+ ;
+}
+
+void cmLocalNinjaGenerator::WritePools(std::ostream& os)
+{
+ cmGlobalNinjaGenerator::WriteDivider(os);
+
+ const char* jobpools = this->GetCMakeInstance()
+ ->GetProperty("JOB_POOLS", cmProperty::GLOBAL);
+ if (jobpools)
+ {
+ cmGlobalNinjaGenerator::WriteComment(os,
+ "Pools defined by global property JOB_POOLS");
+ std::vector<std::string> pools;
+ cmSystemTools::ExpandListArgument(jobpools, pools);
+ for (size_t i = 0; i < pools.size(); ++i)
+ {
+ const std::string pool = pools[i];
+ const std::string::size_type eq = pool.find("=");
+ unsigned int jobs;
+ if (eq != std::string::npos &&
+ sscanf(pool.c_str() + eq, "=%u", &jobs) == 1)
+ {
+ os << "pool " << pool.substr(0, eq) << std::endl;
+ os << " depth = " << jobs << std::endl;
+ os << std::endl;
+ }
+ else
+ {
+ cmSystemTools::Error("Invalid pool defined by property 'JOB_POOLS': ",
+ pool.c_str());
+ }
+ }
+ }
+}
+
+void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os)
+{
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os
+ << "# Include auxiliary files.\n"
+ << "\n"
+ ;
+ cmGlobalNinjaGenerator::WriteInclude(os,
+ cmGlobalNinjaGenerator::NINJA_RULES_FILE,
+ "Include rules file.");
+ os << "\n";
+}
+
+void cmLocalNinjaGenerator::SetConfigName()
+{
+ // Store the configuration name that will be generated.
+ if(const char* config =
+ this->GetMakefile()->GetDefinition("CMAKE_BUILD_TYPE"))
+ {
+ // Use the build type given by the user.
+ this->ConfigName = config;
+ }
+ else
+ {
+ // No configuration type given.
+ this->ConfigName = "";
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalNinjaGenerator::ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt)
+{
+ for(std::map<cmSourceFile const*, std::string>::iterator
+ si = mapping.begin(); si != mapping.end(); ++si)
+ {
+ cmSourceFile const* sf = si->first;
+ si->second = this->GetObjectFileNameWithoutTarget(*sf,
+ gt->ObjectDirectory);
+ }
+}
+
+void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
+{
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os
+ << "# Write statements declared in CMakeLists.txt:" << std::endl
+ << "# " << this->Makefile->GetCurrentListFile() << std::endl
+ ;
+ if(this->isRootMakefile())
+ os << "# Which is the root file." << std::endl;
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os << std::endl;
+}
+
+std::string cmLocalNinjaGenerator::ConvertToNinjaPath(const std::string& path)
+{
+ std::string convPath = this->Convert(path, cmLocalGenerator::HOME_OUTPUT);
+#ifdef _WIN32
+ cmSystemTools::ReplaceString(convPath, "/", "\\");
+#endif
+ return convPath;
+}
+
+void
+cmLocalNinjaGenerator
+::AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs)
+{
+ this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs);
+}
+
+void
+cmLocalNinjaGenerator
+::AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs)
+{
+ this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs);
+}
+
+void cmLocalNinjaGenerator::AppendCustomCommandDeps(
+ cmCustomCommandGenerator const& ccg,
+ cmNinjaDeps &ninjaDeps)
+{
+ const std::vector<std::string> &deps = ccg.GetDepends();
+ for (std::vector<std::string>::const_iterator i = deps.begin();
+ i != deps.end(); ++i) {
+ std::string dep;
+ if (this->GetRealDependency(*i, this->GetConfigName(), dep))
+ ninjaDeps.push_back(ConvertToNinjaPath(dep.c_str()));
+ }
+}
+
+std::string cmLocalNinjaGenerator::BuildCommandLine(
+ const std::vector<std::string> &cmdLines)
+{
+ // If we have no commands but we need to build a command anyway, use ":".
+ // This happens when building a POST_BUILD value for link targets that
+ // don't use POST_BUILD.
+ if (cmdLines.empty())
+#ifdef _WIN32
+ return "cd .";
+#else
+ return ":";
+#endif
+
+ cmOStringStream cmd;
+ for (std::vector<std::string>::const_iterator li = cmdLines.begin();
+ li != cmdLines.end(); ++li)
+#ifdef _WIN32
+ {
+ if (li != cmdLines.begin())
+ {
+ cmd << " && ";
+ }
+ else if (cmdLines.size() > 1)
+ {
+ cmd << "cmd.exe /C \"";
+ }
+ cmd << *li;
+ }
+ if (cmdLines.size() > 1)
+ {
+ cmd << "\"";
+ }
+#else
+ {
+ if (li != cmdLines.begin())
+ {
+ cmd << " && ";
+ }
+ cmd << *li;
+ }
+#endif
+ return cmd.str();
+}
+
+void cmLocalNinjaGenerator::AppendCustomCommandLines(
+ cmCustomCommandGenerator const& ccg,
+ std::vector<std::string> &cmdLines)
+{
+ if (ccg.GetNumberOfCommands() > 0) {
+ std::string wd = ccg.GetWorkingDirectory();
+ if (wd.empty())
+ wd = this->GetMakefile()->GetStartOutputDirectory();
+
+ cmOStringStream cdCmd;
+#ifdef _WIN32
+ std::string cdStr = "cd /D ";
+#else
+ std::string cdStr = "cd ";
+#endif
+ cdCmd << cdStr << this->ConvertToOutputFormat(wd, SHELL);
+ cmdLines.push_back(cdCmd.str());
+ }
+
+ std::string launcher = this->MakeCustomLauncher(ccg);
+
+ for (unsigned i = 0; i != ccg.GetNumberOfCommands(); ++i) {
+ cmdLines.push_back(launcher +
+ this->ConvertToOutputFormat(ccg.GetCommand(i), SHELL));
+
+ std::string& cmd = cmdLines.back();
+ ccg.AppendArguments(i, cmd);
+ }
+}
+
+void
+cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
+ cmCustomCommand const *cc, const cmNinjaDeps& orderOnlyDeps)
+{
+ if (this->GetGlobalNinjaGenerator()->SeenCustomCommand(cc))
+ return;
+
+ cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->Makefile);
+
+ const std::vector<std::string> &outputs = ccg.GetOutputs();
+ cmNinjaDeps ninjaOutputs(outputs.size()), ninjaDeps;
+
+ std::transform(outputs.begin(), outputs.end(),
+ ninjaOutputs.begin(), MapToNinjaPath());
+ this->AppendCustomCommandDeps(ccg, ninjaDeps);
+
+ for (cmNinjaDeps::iterator i = ninjaOutputs.begin(); i != ninjaOutputs.end();
+ ++i)
+ this->GetGlobalNinjaGenerator()->SeenCustomCommandOutput(*i);
+
+ std::vector<std::string> cmdLines;
+ this->AppendCustomCommandLines(ccg, cmdLines);
+
+ if (cmdLines.empty()) {
+ this->GetGlobalNinjaGenerator()->WritePhonyBuild(
+ this->GetBuildFileStream(),
+ "Phony custom command for " +
+ ninjaOutputs[0],
+ ninjaOutputs,
+ ninjaDeps,
+ cmNinjaDeps(),
+ orderOnlyDeps,
+ cmNinjaVars());
+ } else {
+ this->GetGlobalNinjaGenerator()->WriteCustomCommandBuild(
+ this->BuildCommandLine(cmdLines),
+ this->ConstructComment(ccg),
+ "Custom command for " + ninjaOutputs[0],
+ ninjaOutputs,
+ ninjaDeps,
+ orderOnlyDeps);
+ }
+}
+
+void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
+ cmTarget* target)
+{
+ this->CustomCommandTargets[cc].insert(target);
+}
+
+void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
+{
+ for (CustomCommandTargetMap::iterator i = this->CustomCommandTargets.begin();
+ i != this->CustomCommandTargets.end(); ++i) {
+ // A custom command may appear on multiple targets. However, some build
+ // systems exist where the target dependencies on some of the targets are
+ // overspecified, leading to a dependency cycle. If we assume all target
+ // dependencies are a superset of the true target dependencies for this
+ // custom command, we can take the set intersection of all target
+ // dependencies to obtain a correct dependency list.
+ //
+ // FIXME: This won't work in certain obscure scenarios involving indirect
+ // dependencies.
+ std::set<cmTarget*>::iterator j = i->second.begin();
+ assert(j != i->second.end());
+ std::vector<std::string> ccTargetDeps;
+ this->AppendTargetDepends(*j, ccTargetDeps);
+ std::sort(ccTargetDeps.begin(), ccTargetDeps.end());
+ ++j;
+
+ for (; j != i->second.end(); ++j) {
+ std::vector<std::string> jDeps, depsIntersection;
+ this->AppendTargetDepends(*j, jDeps);
+ std::sort(jDeps.begin(), jDeps.end());
+ std::set_intersection(ccTargetDeps.begin(), ccTargetDeps.end(),
+ jDeps.begin(), jDeps.end(),
+ std::back_inserter(depsIntersection));
+ ccTargetDeps = depsIntersection;
+ }
+
+ this->WriteCustomCommandBuildStatement(i->first, ccTargetDeps);
+ }
+}
+
+std::string cmLocalNinjaGenerator::MakeCustomLauncher(
+ cmCustomCommandGenerator const& ccg)
+{
+ const char* property = "RULE_LAUNCH_CUSTOM";
+ const char* property_value = this->Makefile->GetProperty(property);
+
+ if(!property_value || !*property_value)
+ {
+ return std::string();
+ }
+
+ // Expand rules in the empty string. It may insert the launcher and
+ // perform replacements.
+ RuleVariables vars;
+ vars.RuleLauncher = property;
+ std::string output;
+ const std::vector<std::string>& outputs = ccg.GetOutputs();
+ if(!outputs.empty())
+ {
+ RelativeRoot relative_root =
+ ccg.GetWorkingDirectory().empty() ? START_OUTPUT : NONE;
+
+ output = this->Convert(outputs[0], relative_root, SHELL);
+ }
+ vars.Output = output.c_str();
+
+ std::string launcher;
+ this->ExpandRuleVariables(launcher, vars);
+ if(!launcher.empty())
+ {
+ launcher += " ";
+ }
+
+ return launcher;
+}
diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h
new file mode 100644
index 0000000000..1d27224f59
--- /dev/null
+++ b/Source/cmLocalNinjaGenerator.h
@@ -0,0 +1,144 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 cmLocalNinjaGenerator_h
+# define cmLocalNinjaGenerator_h
+
+# include "cmLocalGenerator.h"
+# include "cmNinjaTypes.h"
+
+class cmCustomCommandGenerator;
+class cmGlobalNinjaGenerator;
+class cmGeneratedFileStream;
+class cmake;
+
+/**
+ * \class cmLocalNinjaGenerator
+ * \brief Write a local build.ninja file.
+ *
+ * cmLocalNinjaGenerator produces a local build.ninja file from its
+ * member Makefile.
+ */
+class cmLocalNinjaGenerator : public cmLocalGenerator
+{
+public:
+ /// Default constructor.
+ cmLocalNinjaGenerator();
+
+ /// Destructor.
+ virtual ~cmLocalNinjaGenerator();
+
+ /// Overloaded methods. @see cmLocalGenerator::Generate()
+ virtual void Generate();
+
+ /// Overloaded methods. @see cmLocalGenerator::Configure()
+ virtual void Configure();
+
+ /// Overloaded methods. @see cmLocalGenerator::GetTargetDirectory()
+ virtual std::string GetTargetDirectory(cmTarget const& target) const;
+
+ const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
+ cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
+
+ /**
+ * Shortcut to get the cmake instance throw the global generator.
+ * @return an instance of the cmake object.
+ */
+ const cmake* GetCMakeInstance() const;
+ cmake* GetCMakeInstance();
+
+ std::string const& GetConfigName() const
+ { return this->ConfigName; }
+
+ /// @return whether we are processing the top CMakeLists.txt file.
+ bool isRootMakefile() const;
+
+ /// @returns the relative path between the HomeOutputDirectory and this
+ /// local generators StartOutputDirectory.
+ std::string GetHomeRelativeOutputPath() const
+ { return this->HomeRelativeOutputPath; }
+
+ std::string ConvertToNinjaPath(const std::string& path);
+
+ struct map_to_ninja_path {
+ cmLocalNinjaGenerator *LocalGenerator;
+ map_to_ninja_path(cmLocalNinjaGenerator *LocalGen)
+ : LocalGenerator(LocalGen) {}
+ std::string operator()(const std::string &path) {
+ return LocalGenerator->ConvertToNinjaPath(path.c_str());
+ }
+ };
+
+ map_to_ninja_path MapToNinjaPath() {
+ return map_to_ninja_path(this);
+ }
+
+ void ExpandRuleVariables(std::string& string,
+ const RuleVariables& replaceValues) {
+ cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
+ }
+
+ std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
+
+ void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
+ void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
+
+ void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target);
+ void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
+ std::vector<std::string> &cmdLines);
+ void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
+ cmNinjaDeps &ninjaDeps);
+
+ virtual std::string ConvertToLinkReference(std::string const& lib,
+ OutputFormat format = SHELL);
+
+ virtual void ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt = 0);
+
+
+protected:
+ virtual std::string ConvertToIncludeReference(std::string const& path,
+ OutputFormat format = SHELL,
+ bool forceFullPaths = false);
+
+
+private:
+ cmGeneratedFileStream& GetBuildFileStream() const;
+ cmGeneratedFileStream& GetRulesFileStream() const;
+
+ void WriteBuildFileTop();
+ void WriteProjectHeader(std::ostream& os);
+ void WriteNinjaRequiredVersion(std::ostream& os);
+ void WriteNinjaFilesInclusion(std::ostream& os);
+ void WriteProcessedMakefile(std::ostream& os);
+ void WritePools(std::ostream& os);
+
+ void SetConfigName();
+
+ void WriteCustomCommandRule();
+ void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
+ const cmNinjaDeps& orderOnlyDeps);
+
+ void WriteCustomCommandBuildStatements();
+
+ std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
+
+ std::string ConfigName;
+ std::string HomeRelativeOutputPath;
+
+ typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
+ CustomCommandTargetMap;
+ CustomCommandTargetMap CustomCommandTargets;
+};
+
+#endif // ! cmLocalNinjaGenerator_h
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
new file mode 100644
index 0000000000..23513face1
--- /dev/null
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -0,0 +1,2353 @@
+/*============================================================================
+ 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 "cmLocalUnixMakefileGenerator3.h"
+
+#include "cmGeneratedFileStream.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmMakefileTargetGenerator.h"
+#include "cmSourceFile.h"
+#include "cmake.h"
+#include "cmVersion.h"
+#include "cmFileTimeComparison.h"
+#include "cmCustomCommandGenerator.h"
+
+// Include dependency scanners for supported languages. Only the
+// C/C++ scanner is needed for bootstrapping CMake.
+#include "cmDependsC.h"
+#ifdef CMAKE_BUILD_WITH_CMAKE
+# include "cmDependsFortran.h"
+# include "cmDependsJava.h"
+# include <cmsys/Terminal.h>
+#endif
+
+#include <cmsys/auto_ptr.hxx>
+
+#include <queue>
+
+//----------------------------------------------------------------------------
+// Escape special characters in Makefile dependency lines
+class cmMakeSafe
+{
+public:
+ cmMakeSafe(const char* s): Data(s) {}
+ cmMakeSafe(std::string const& s): Data(s.c_str()) {}
+private:
+ const char* Data;
+ friend std::ostream& operator<<(std::ostream& os,
+ cmMakeSafe const& self)
+ {
+ for(const char* c = self.Data; *c; ++c)
+ {
+ switch (*c)
+ {
+ case '=': os << "$(EQUALS)"; break;
+ default: os << *c; break;
+ }
+ }
+ return os;
+ }
+};
+
+//----------------------------------------------------------------------------
+// Helper function used below.
+static std::string cmSplitExtension(std::string const& in, std::string& base)
+{
+ std::string ext;
+ std::string::size_type dot_pos = in.rfind(".");
+ if(dot_pos != std::string::npos)
+ {
+ // Remove the extension first in case &base == &in.
+ ext = in.substr(dot_pos, std::string::npos);
+ base = in.substr(0, dot_pos);
+ }
+ else
+ {
+ base = in;
+ }
+ return ext;
+}
+
+//----------------------------------------------------------------------------
+cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3()
+{
+ this->WindowsShell = false;
+ this->IncludeDirective = "include";
+ this->MakefileVariableSize = 0;
+ this->IgnoreLibPrefix = false;
+ this->PassMakeflags = false;
+ this->DefineWindowsNULL = false;
+ this->UnixCD = true;
+ this->ColorMakefile = false;
+ this->SkipPreprocessedSourceRules = false;
+ this->SkipAssemblySourceRules = false;
+ this->MakeCommandEscapeTargetTwice = false;
+ this->BorlandMakeCurlyHack = false;
+}
+
+//----------------------------------------------------------------------------
+cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::Configure()
+{
+ // Compute the path to use when referencing the current output
+ // directory from the top output directory.
+ this->HomeRelativeOutputPath =
+ this->Convert(this->Makefile->GetStartOutputDirectory(), HOME_OUTPUT);
+ if(this->HomeRelativeOutputPath == ".")
+ {
+ this->HomeRelativeOutputPath = "";
+ }
+ if(!this->HomeRelativeOutputPath.empty())
+ {
+ this->HomeRelativeOutputPath += "/";
+ }
+ this->cmLocalGenerator::Configure();
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::Generate()
+{
+ // Store the configuration name that will be generated.
+ if(const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
+ {
+ // Use the build type given by the user.
+ this->ConfigurationName = config;
+ }
+ else
+ {
+ // No configuration type given.
+ this->ConfigurationName = "";
+ }
+
+ // Record whether some options are enabled to avoid checking many
+ // times later.
+ if(!this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
+ {
+ this->ColorMakefile = this->Makefile->IsOn("CMAKE_COLOR_MAKEFILE");
+ }
+ this->SkipPreprocessedSourceRules =
+ this->Makefile->IsOn("CMAKE_SKIP_PREPROCESSED_SOURCE_RULES");
+ this->SkipAssemblySourceRules =
+ this->Makefile->IsOn("CMAKE_SKIP_ASSEMBLY_SOURCE_RULES");
+
+ // Generate the rule files for each target.
+ cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
+ cmGlobalUnixMakefileGenerator3* gg =
+ static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
+ for(cmGeneratorTargetsType::iterator t = targets.begin();
+ t != targets.end(); ++t)
+ {
+ if (t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY
+ || t->second->Target->IsImported())
+ {
+ continue;
+ }
+ cmsys::auto_ptr<cmMakefileTargetGenerator> tg(
+ cmMakefileTargetGenerator::New(t->second));
+ if (tg.get())
+ {
+ tg->WriteRuleFiles();
+ gg->RecordTargetProgress(tg.get());
+ }
+ }
+
+ // write the local Makefile
+ this->WriteLocalMakefile();
+
+ // Write the cmake file with information for this directory.
+ this->WriteDirectoryInformationFile();
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt)
+{
+ for(std::map<cmSourceFile const*, std::string>::iterator
+ si = mapping.begin(); si != mapping.end(); ++si)
+ {
+ cmSourceFile const* sf = si->first;
+ si->second = this->GetObjectFileNameWithoutTarget(*sf,
+ gt->ObjectDirectory);
+ }
+}
+
+//----------------------------------------------------------------------------
+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();
+ ti != targets.end(); ++ti)
+ {
+ cmGeneratorTarget* gt = ti->second;
+ if (gt->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ std::vector<cmSourceFile const*> objectSources;
+ gt->GetObjectSources(objectSources, this->Makefile
+ ->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ // Compute full path to object file directory for this target.
+ std::string dir;
+ dir += gt->Makefile->GetCurrentOutputDirectory();
+ dir += "/";
+ dir += this->GetTargetDirectory(*gt->Target);
+ dir += "/";
+ // Compute the name of each object file.
+ for(std::vector<cmSourceFile const*>::iterator
+ si = objectSources.begin();
+ si != objectSources.end(); ++si)
+ {
+ cmSourceFile const* sf = *si;
+ bool hasSourceExtension = true;
+ std::string objectName = this->GetObjectFileNameWithoutTarget(*sf,
+ dir,
+ &hasSourceExtension);
+ if(cmSystemTools::FileIsFullPath(objectName.c_str()))
+ {
+ objectName = cmSystemTools::GetFilenameName(objectName);
+ }
+ LocalObjectInfo& info = localObjectFiles[objectName];
+ info.HasSourceExtension = hasSourceExtension;
+ info.push_back(LocalObjectEntry(gt->Target, sf->GetLanguage()));
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::GetIndividualFileTargets
+ (std::vector<std::string>& targets)
+{
+ std::map<std::string, LocalObjectInfo> localObjectFiles;
+ this->GetLocalObjectFiles(localObjectFiles);
+ for (std::map<std::string, LocalObjectInfo>::iterator lo =
+ localObjectFiles.begin();
+ lo != localObjectFiles.end(); ++lo)
+ {
+ targets.push_back(lo->first);
+
+ std::string::size_type dot_pos = lo->first.rfind(".");
+ std::string base = lo->first.substr(0, dot_pos);
+ if(lo->second.HasPreprocessRule)
+ {
+ targets.push_back(base + ".i");
+ }
+
+ if(lo->second.HasAssembleRule)
+ {
+ targets.push_back(base + ".s");
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
+{
+ // generate the includes
+ std::string ruleFileName = "Makefile";
+
+ // Open the rule file. This should be copy-if-different because the
+ // rules may depend on this file itself.
+ std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
+ cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
+ if(!ruleFileStream)
+ {
+ return;
+ }
+ // always write the top makefile
+ if (this->Parent)
+ {
+ ruleFileStream.SetCopyIfDifferent(true);
+ }
+
+ // write the all rules
+ this->WriteLocalAllRules(ruleFileStream);
+
+ // only write local targets unless at the top Keep track of targets already
+ // listed.
+ std::set<std::string> emittedTargets;
+ if (this->Parent)
+ {
+ // write our targets, and while doing it collect up the object
+ // file rules
+ this->WriteLocalMakefileTargets(ruleFileStream,emittedTargets);
+ }
+ else
+ {
+ cmGlobalUnixMakefileGenerator3 *gg =
+ static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
+ gg->WriteConvenienceRules(ruleFileStream,emittedTargets);
+ }
+
+ bool do_preprocess_rules =
+ this->GetCreatePreprocessedSourceRules();
+ bool do_assembly_rules =
+ this->GetCreateAssemblySourceRules();
+
+ std::map<std::string, LocalObjectInfo> localObjectFiles;
+ this->GetLocalObjectFiles(localObjectFiles);
+
+ // now write out the object rules
+ // for each object file name
+ for (std::map<std::string, LocalObjectInfo>::iterator lo =
+ localObjectFiles.begin();
+ lo != localObjectFiles.end(); ++lo)
+ {
+ // Add a convenience rule for building the object file.
+ this->WriteObjectConvenienceRule(ruleFileStream,
+ "target to build an object file",
+ lo->first.c_str(), lo->second);
+
+ // Check whether preprocessing and assembly rules make sense.
+ // They make sense only for C and C++ sources.
+ bool lang_is_c_or_cxx = false;
+ for(std::vector<LocalObjectEntry>::const_iterator ei =
+ lo->second.begin(); ei != lo->second.end(); ++ei)
+ {
+ if(ei->Language == "C" || ei->Language == "CXX")
+ {
+ lang_is_c_or_cxx = true;
+ break;
+ }
+ }
+
+ // Add convenience rules for preprocessed and assembly files.
+ if(lang_is_c_or_cxx && (do_preprocess_rules || do_assembly_rules))
+ {
+ std::string::size_type dot_pos = lo->first.rfind(".");
+ std::string base = lo->first.substr(0, dot_pos);
+ if(do_preprocess_rules)
+ {
+ this->WriteObjectConvenienceRule(
+ ruleFileStream, "target to preprocess a source file",
+ (base + ".i").c_str(), lo->second);
+ lo->second.HasPreprocessRule = true;
+ }
+ if(do_assembly_rules)
+ {
+ this->WriteObjectConvenienceRule(
+ ruleFileStream, "target to generate assembly for a file",
+ (base + ".s").c_str(), lo->second);
+ lo->second.HasAssembleRule = true;
+ }
+ }
+ }
+
+ // add a help target as long as there isn;t a real target named help
+ if(emittedTargets.insert("help").second)
+ {
+ cmGlobalUnixMakefileGenerator3 *gg =
+ static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
+ gg->WriteHelpRule(ruleFileStream,this);
+ }
+
+ this->WriteSpecialTargetsBottom(ruleFileStream);
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::WriteObjectConvenienceRule(std::ostream& ruleFileStream,
+ const char* comment, const char* output,
+ LocalObjectInfo const& info)
+{
+ // If the rule includes the source file extension then create a
+ // version that has the extension removed. The help should include
+ // only the version without source extension.
+ bool inHelp = true;
+ if(info.HasSourceExtension)
+ {
+ // Remove the last extension. This should be kept.
+ std::string outBase1 = output;
+ std::string outExt1 = cmSplitExtension(outBase1, outBase1);
+
+ // Now remove the source extension and put back the last
+ // extension.
+ std::string outNoExt;
+ cmSplitExtension(outBase1, outNoExt);
+ outNoExt += outExt1;
+
+ // Add a rule to drive the rule below.
+ std::vector<std::string> depends;
+ depends.push_back(output);
+ std::vector<std::string> no_commands;
+ this->WriteMakeRule(ruleFileStream, 0,
+ outNoExt, depends, no_commands, true, true);
+ inHelp = false;
+ }
+
+ // Recursively make the rule for each target using the object file.
+ std::vector<std::string> commands;
+ for(std::vector<LocalObjectEntry>::const_iterator t = info.begin();
+ t != info.end(); ++t)
+ {
+ std::string tgtMakefileName =
+ this->GetRelativeTargetDirectory(*(t->Target));
+ std::string targetName = tgtMakefileName;
+ tgtMakefileName += "/build.make";
+ targetName += "/";
+ targetName += output;
+ commands.push_back(
+ this->GetRecursiveMakeCall(tgtMakefileName.c_str(), targetName)
+ );
+ }
+ this->CreateCDCommand(commands,
+ this->Makefile->GetHomeOutputDirectory(),
+ cmLocalGenerator::START_OUTPUT);
+
+ // Write the rule to the makefile.
+ std::vector<std::string> no_depends;
+ this->WriteMakeRule(ruleFileStream, comment,
+ output, no_depends, commands, true, inHelp);
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3
+::WriteLocalMakefileTargets(std::ostream& ruleFileStream,
+ std::set<std::string> &emitted)
+{
+ std::vector<std::string> depends;
+ std::vector<std::string> commands;
+
+ // 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::string localName;
+ for(cmGeneratorTargetsType::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->second->Target->IsImported())
+ {
+ continue;
+ }
+
+ emitted.insert(t->second->GetName());
+
+ // for subdirs add a rule to build this specific target by name.
+ localName = this->GetRelativeTargetDirectory(*t->second->Target);
+ localName += "/rule";
+ commands.clear();
+ depends.clear();
+
+ // Build the target for this pass.
+ std::string makefile2 = cmake::GetCMakeFilesDirectoryPostSlash();
+ makefile2 += "Makefile2";
+ commands.push_back(this->GetRecursiveMakeCall
+ (makefile2.c_str(),localName));
+ this->CreateCDCommand(commands,
+ this->Makefile->GetHomeOutputDirectory(),
+ 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())
+ {
+ commands.clear();
+ depends.push_back(localName);
+ this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
+ t->second->GetName(), depends, commands, true);
+ }
+
+ // Add a fast rule to build the target
+ std::string makefileName =
+ this->GetRelativeTargetDirectory(*t->second->Target);
+ makefileName += "/build.make";
+ // make sure the makefile name is suitable for a makefile
+ std::string makeTargetName =
+ this->GetRelativeTargetDirectory(*t->second->Target);
+ makeTargetName += "/build";
+ localName = t->second->GetName();
+ localName += "/fast";
+ depends.clear();
+ commands.clear();
+ commands.push_back(this->GetRecursiveMakeCall
+ (makefileName.c_str(), makeTargetName));
+ this->CreateCDCommand(commands,
+ this->Makefile->GetHomeOutputDirectory(),
+ 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->Target
+ ->NeedRelinkBeforeInstall(this->ConfigurationName))
+ {
+ makeTargetName = this->GetRelativeTargetDirectory(*t->second->Target);
+ makeTargetName += "/preinstall";
+ localName = t->second->GetName();
+ localName += "/preinstall";
+ depends.clear();
+ commands.clear();
+ commands.push_back(this->GetRecursiveMakeCall
+ (makefile2.c_str(), makeTargetName));
+ this->CreateCDCommand(commands,
+ this->Makefile->GetHomeOutputDirectory(),
+ cmLocalGenerator::START_OUTPUT);
+ this->WriteMakeRule(ruleFileStream,
+ "Manual pre-install relink rule for target.",
+ localName, depends, commands, true);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
+{
+ std::string infoFileName = this->Makefile->GetStartOutputDirectory();
+ infoFileName += cmake::GetCMakeFilesDirectory();
+ infoFileName += "/CMakeDirectoryInformation.cmake";
+
+ // Open the output file.
+ cmGeneratedFileStream infoFileStream(infoFileName.c_str());
+ if(!infoFileStream)
+ {
+ return;
+ }
+
+ infoFileStream.SetCopyIfDifferent(true);
+ // Write the do not edit header.
+ this->WriteDisclaimer(infoFileStream);
+
+ // Setup relative path conversion tops.
+ infoFileStream
+ << "# Relative path conversion top directories.\n"
+ << "set(CMAKE_RELATIVE_PATH_TOP_SOURCE \"" << this->RelativePathTopSource
+ << "\")\n"
+ << "set(CMAKE_RELATIVE_PATH_TOP_BINARY \"" << this->RelativePathTopBinary
+ << "\")\n"
+ << "\n";
+
+ // Tell the dependency scanner to use unix paths if necessary.
+ if(cmSystemTools::GetForceUnixPaths())
+ {
+ infoFileStream
+ << "# Force unix paths in dependencies.\n"
+ << "set(CMAKE_FORCE_UNIX_PATHS 1)\n"
+ << "\n";
+ }
+
+ // Store the include regular expressions for this directory.
+ infoFileStream
+ << "\n"
+ << "# The C and CXX include file regular expressions for "
+ << "this directory.\n";
+ infoFileStream
+ << "set(CMAKE_C_INCLUDE_REGEX_SCAN ";
+ this->WriteCMakeArgument(infoFileStream,
+ this->Makefile->GetIncludeRegularExpression());
+ infoFileStream
+ << ")\n";
+ infoFileStream
+ << "set(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
+ this->WriteCMakeArgument(infoFileStream,
+ this->Makefile->GetComplainRegularExpression());
+ infoFileStream
+ << ")\n";
+ infoFileStream
+ << "set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
+ infoFileStream
+ << "set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN "
+ "${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalUnixMakefileGenerator3
+::ConvertToFullPath(const std::string& localPath)
+{
+ std::string dir = this->Makefile->GetStartOutputDirectory();
+ dir += "/";
+ dir += localPath;
+ return dir;
+}
+
+
+const std::string &cmLocalUnixMakefileGenerator3::GetHomeRelativeOutputPath()
+{
+ return this->HomeRelativeOutputPath;
+}
+
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::WriteMakeRule(std::ostream& os,
+ const char* comment,
+ const std::string& target,
+ const std::vector<std::string>& depends,
+ const std::vector<std::string>& commands,
+ bool symbolic,
+ bool in_help)
+{
+ // Make sure there is a target.
+ if(target.empty())
+ {
+ cmSystemTools::Error("No target for WriteMakeRule! called with comment: ",
+ comment);
+ return;
+ }
+
+ std::string replace;
+
+ // Write the comment describing the rule in the makefile.
+ if(comment)
+ {
+ replace = comment;
+ std::string::size_type lpos = 0;
+ std::string::size_type rpos;
+ while((rpos = replace.find('\n', lpos)) != std::string::npos)
+ {
+ os << "# " << replace.substr(lpos, rpos-lpos) << "\n";
+ lpos = rpos+1;
+ }
+ os << "# " << replace.substr(lpos) << "\n";
+ }
+
+ // Construct the left hand side of the rule.
+ replace = target;
+ std::string tgt = this->Convert(replace,HOME_OUTPUT,MAKERULE);
+ const char* space = "";
+ if(tgt.size() == 1)
+ {
+ // Add a space before the ":" to avoid drive letter confusion on
+ // Windows.
+ space = " ";
+ }
+
+ // Mark the rule as symbolic if requested.
+ if(symbolic)
+ {
+ if(const char* sym =
+ this->Makefile->GetDefinition("CMAKE_MAKE_SYMBOLIC_RULE"))
+ {
+ os << cmMakeSafe(tgt) << space << ": " << sym << "\n";
+ }
+ }
+
+ // Write the rule.
+ if(depends.empty())
+ {
+ // No dependencies. The commands will always run.
+ os << cmMakeSafe(tgt) << space << ":\n";
+ }
+ else
+ {
+ // Split dependencies into multiple rule lines. This allows for
+ // very long dependency lists even on older make implementations.
+ for(std::vector<std::string>::const_iterator dep = depends.begin();
+ dep != depends.end(); ++dep)
+ {
+ replace = *dep;
+ replace = this->Convert(replace,HOME_OUTPUT,MAKERULE);
+ os << cmMakeSafe(tgt) << space << ": " << cmMakeSafe(replace) << "\n";
+ }
+ }
+
+ // Write the list of commands.
+ for(std::vector<std::string>::const_iterator i = commands.begin();
+ i != commands.end(); ++i)
+ {
+ replace = *i;
+ os << "\t" << replace << "\n";
+ }
+ if(symbolic && !this->WatcomWMake)
+ {
+ os << ".PHONY : " << cmMakeSafe(tgt) << "\n";
+ }
+ os << "\n";
+ // Add the output to the local help if requested.
+ if(in_help)
+ {
+ this->LocalHelp.push_back(target);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalUnixMakefileGenerator3
+::ConvertShellCommand(std::string const& cmd, RelativeRoot root)
+{
+ if(this->WatcomWMake &&
+ cmSystemTools::FileIsFullPath(cmd.c_str()) &&
+ cmd.find_first_of("( )") != cmd.npos)
+ {
+ // On Watcom WMake use the windows short path for the command
+ // name. This is needed to avoid funny quoting problems on
+ // lines with shell redirection operators.
+ std::string scmd;
+ if(cmSystemTools::GetShortPath(cmd.c_str(), scmd))
+ {
+ return this->Convert(scmd, NONE, SHELL);
+ }
+ }
+ return this->Convert(cmd, root, SHELL);
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::WriteMakeVariables(std::ostream& makefileStream)
+{
+ this->WriteDivider(makefileStream);
+ makefileStream
+ << "# Set environment variables for the build.\n"
+ << "\n";
+ if(this->DefineWindowsNULL)
+ {
+ makefileStream
+ << "!IF \"$(OS)\" == \"Windows_NT\"\n"
+ << "NULL=\n"
+ << "!ELSE\n"
+ << "NULL=nul\n"
+ << "!ENDIF\n";
+ }
+ if(this->WindowsShell)
+ {
+ makefileStream
+ << "SHELL = cmd.exe\n"
+ << "\n";
+ }
+ else
+ {
+#if !defined(__VMS)
+ makefileStream
+ << "# The shell in which to execute make rules.\n"
+ << "SHELL = /bin/sh\n"
+ << "\n";
+#endif
+ }
+
+ std::string cmakecommand =
+ this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
+ makefileStream
+ << "# The CMake executable.\n"
+ << "CMAKE_COMMAND = "
+ << this->ConvertShellCommand(cmakecommand, FULL)
+ << "\n"
+ << "\n";
+ makefileStream
+ << "# The command to remove a file.\n"
+ << "RM = "
+ << this->ConvertShellCommand(cmakecommand, FULL)
+ << " -E remove -f\n"
+ << "\n";
+ makefileStream
+ << "# Escaping for special characters.\n"
+ << "EQUALS = =\n"
+ << "\n";
+ makefileStream
+ << "# The top-level source directory on which CMake was run.\n"
+ << "CMAKE_SOURCE_DIR = "
+ << this->Convert(this->Makefile->GetHomeDirectory(), 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)
+ << "\n"
+ << "\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::WriteSpecialTargetsTop(std::ostream& makefileStream)
+{
+ this->WriteDivider(makefileStream);
+ makefileStream
+ << "# Special targets provided by cmake.\n"
+ << "\n";
+
+ std::vector<std::string> no_commands;
+ std::vector<std::string> no_depends;
+
+ // Special target to cleanup operation of make tool.
+ // This should be the first target except for the default_target in
+ // the interface Makefile.
+ this->WriteMakeRule(
+ makefileStream, "Disable implicit rules so canonical targets will work.",
+ ".SUFFIXES", no_depends, no_commands, false);
+
+ if(!this->NMake && !this->WatcomWMake && !this->BorlandMakeCurlyHack)
+ {
+ // turn off RCS and SCCS automatic stuff from gmake
+ makefileStream
+ << "# Remove some rules from gmake that .SUFFIXES does not remove.\n"
+ << "SUFFIXES =\n\n";
+ }
+ // Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make.
+ std::vector<std::string> depends;
+ depends.push_back(".hpux_make_needs_suffix_list");
+ this->WriteMakeRule(makefileStream, 0,
+ ".SUFFIXES", depends, no_commands, false);
+ if(this->WatcomWMake)
+ {
+ // Switch on WMake feature, if an error or interrupt occurs during
+ // makefile processing, the current target being made may be deleted
+ // without prompting (the same as command line -e option).
+ makefileStream <<
+ "\n"
+ ".ERASE\n"
+ "\n"
+ ;
+ }
+ if(this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
+ {
+ makefileStream
+ << "# Produce verbose output by default.\n"
+ << "VERBOSE = 1\n"
+ << "\n";
+ }
+ if(this->WatcomWMake)
+ {
+ makefileStream <<
+ "!ifndef VERBOSE\n"
+ ".SILENT\n"
+ "!endif\n"
+ "\n"
+ ;
+ }
+ else
+ {
+ // Write special target to silence make output. This must be after
+ // the default target in case VERBOSE is set (which changes the
+ // name). The setting of CMAKE_VERBOSE_MAKEFILE to ON will cause a
+ // "VERBOSE=1" to be added as a make variable which will change the
+ // name of this special target. This gives a make-time choice to
+ // the user.
+ this->WriteMakeRule(makefileStream,
+ "Suppress display of executed commands.",
+ "$(VERBOSE).SILENT",
+ no_depends,
+ no_commands, false);
+ }
+
+ // Work-around for makes that drop rules that have no dependencies
+ // or commands.
+ cmGlobalUnixMakefileGenerator3* gg =
+ static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
+ std::string hack = gg->GetEmptyRuleHackDepends();
+ if(!hack.empty())
+ {
+ no_depends.push_back(hack);
+ }
+ std::string hack_cmd = gg->GetEmptyRuleHackCommand();
+ if(!hack_cmd.empty())
+ {
+ no_commands.push_back(hack_cmd);
+ }
+
+ // Special symbolic target that never exists to force dependers to
+ // run their rules.
+ this->WriteMakeRule
+ (makefileStream,
+ "A target that is always out of date.",
+ "cmake_force", no_depends, no_commands, true);
+
+ // Variables for reference by other rules.
+ this->WriteMakeVariables(makefileStream);
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3
+::WriteSpecialTargetsBottom(std::ostream& makefileStream)
+{
+ this->WriteDivider(makefileStream);
+ makefileStream
+ << "# Special targets to cleanup operation of make.\n"
+ << "\n";
+
+ // Write special "cmake_check_build_system" target to run cmake with
+ // the --check-build-system flag.
+ {
+ // Build command to run CMake to check if anything needs regenerating.
+ std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
+ cmakefileName += "Makefile.cmake";
+ std::string runRule =
+ "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
+ runRule += " --check-build-system ";
+ runRule += this->Convert(cmakefileName,NONE,SHELL);
+ runRule += " 0";
+
+ std::vector<std::string> no_depends;
+ std::vector<std::string> commands;
+ commands.push_back(runRule);
+ if(this->Parent)
+ {
+ this->CreateCDCommand(commands,
+ this->Makefile->GetHomeOutputDirectory(),
+ cmLocalGenerator::START_OUTPUT);
+ }
+ this->WriteMakeRule(makefileStream,
+ "Special rule to run CMake to check the build system "
+ "integrity.\n"
+ "No rule that depends on this can have "
+ "commands that come from listfiles\n"
+ "because they might be regenerated.",
+ "cmake_check_build_system",
+ no_depends,
+ commands, true);
+ }
+}
+
+
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::WriteConvenienceRule(std::ostream& ruleFileStream,
+ const std::string& realTarget,
+ const std::string& helpTarget)
+{
+ // A rule is only needed if the names are different.
+ if(realTarget != helpTarget)
+ {
+ // The helper target depends on the real target.
+ std::vector<std::string> depends;
+ depends.push_back(realTarget);
+
+ // There are no commands.
+ std::vector<std::string> no_commands;
+
+ // Write the rule.
+ this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
+ helpTarget, depends, no_commands, true);
+ }
+}
+
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalUnixMakefileGenerator3
+::GetRelativeTargetDirectory(cmTarget const& target)
+{
+ std::string dir = this->HomeRelativeOutputPath;
+ dir += this->GetTargetDirectory(target);
+ return this->Convert(dir,NONE,UNCHANGED);
+}
+
+
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags,
+ const std::string& newFlags)
+{
+ if(this->WatcomWMake && !newFlags.empty())
+ {
+ std::string newf = newFlags;
+ if(newf.find("\\\"") != newf.npos)
+ {
+ cmSystemTools::ReplaceString(newf, "\\\"", "\"");
+ this->cmLocalGenerator::AppendFlags(flags, newf);
+ return;
+ }
+ }
+ this->cmLocalGenerator::AppendFlags(flags, newFlags);
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags,
+ const char* newFlags)
+{
+ this->cmLocalGenerator::AppendFlags(flags, newFlags);
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::AppendRuleDepend(std::vector<std::string>& depends,
+ const char* ruleFileName)
+{
+ // Add a dependency on the rule file itself unless an option to skip
+ // it is specifically enabled by the user or project.
+ const char* nodep =
+ this->Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
+ if(!nodep || cmSystemTools::IsOff(nodep))
+ {
+ depends.push_back(ruleFileName);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::AppendRuleDepends(std::vector<std::string>& depends,
+ std::vector<std::string> const& ruleFiles)
+{
+ // Add a dependency on the rule file itself unless an option to skip
+ // it is specifically enabled by the user or project.
+ if(!this->Makefile->IsOn("CMAKE_SKIP_RULE_DEPENDENCY"))
+ {
+ depends.insert(depends.end(), ruleFiles.begin(), ruleFiles.end());
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::AppendCustomDepends(std::vector<std::string>& depends,
+ const std::vector<cmCustomCommand>& ccs)
+{
+ for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
+ i != ccs.end(); ++i)
+ {
+ cmCustomCommandGenerator ccg(*i, this->ConfigurationName,
+ this->Makefile);
+ this->AppendCustomDepend(depends, ccg);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::AppendCustomDepend(std::vector<std::string>& depends,
+ cmCustomCommandGenerator const& ccg)
+{
+ for(std::vector<std::string>::const_iterator d = ccg.GetDepends().begin();
+ d != ccg.GetDepends().end(); ++d)
+ {
+ // Lookup the real name of the dependency in case it is a CMake target.
+ std::string dep;
+ if(this->GetRealDependency(*d, this->ConfigurationName,
+ dep))
+ {
+ depends.push_back(dep);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::AppendCustomCommands(std::vector<std::string>& commands,
+ const std::vector<cmCustomCommand>& ccs,
+ cmTarget* target,
+ cmLocalGenerator::RelativeRoot relative)
+{
+ for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
+ i != ccs.end(); ++i)
+ {
+ cmCustomCommandGenerator ccg(*i, this->ConfigurationName,
+ this->Makefile);
+ this->AppendCustomCommand(commands, ccg, target, true, relative);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::AppendCustomCommand(std::vector<std::string>& commands,
+ cmCustomCommandGenerator const& ccg,
+ cmTarget* target,
+ bool echo_comment,
+ cmLocalGenerator::RelativeRoot relative,
+ std::ostream* content)
+{
+ // Optionally create a command to display the custom command's
+ // comment text. This is used for pre-build, pre-link, and
+ // post-build command comments. Custom build step commands have
+ // their comments generated elsewhere.
+ if(echo_comment)
+ {
+ const char* comment = ccg.GetComment();
+ if(comment && !*comment)
+ {
+ this->AppendEcho(commands, comment,
+ cmLocalUnixMakefileGenerator3::EchoGenerate);
+ }
+ }
+
+ // if the command specified a working directory use it.
+ std::string dir = this->Makefile->GetStartOutputDirectory();
+ std::string workingDir = ccg.GetWorkingDirectory();
+ if(!workingDir.empty())
+ {
+ dir = workingDir;
+ }
+ if(content)
+ {
+ *content << dir;
+ }
+
+ // Add each command line to the set of commands.
+ std::vector<std::string> commands1;
+ for(unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c)
+ {
+ // Build the command line in a single string.
+ std::string cmd = ccg.GetCommand(c);
+ if (cmd.size())
+ {
+ // Use "call " before any invocations of .bat or .cmd files
+ // invoked as custom commands in the WindowsShell.
+ //
+ bool useCall = false;
+
+ if (this->WindowsShell)
+ {
+ std::string suffix;
+ if (cmd.size() > 4)
+ {
+ suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size()-4));
+ if (suffix == ".bat" || suffix == ".cmd")
+ {
+ useCall = true;
+ }
+ }
+ }
+
+ cmSystemTools::ReplaceString(cmd, "/./", "/");
+ // Convert the command to a relative path only if the current
+ // working directory will be the start-output directory.
+ bool had_slash = cmd.find("/") != cmd.npos;
+ if(workingDir.empty())
+ {
+ cmd = this->Convert(cmd,START_OUTPUT);
+ }
+ bool has_slash = cmd.find("/") != cmd.npos;
+ if(had_slash && !has_slash)
+ {
+ // This command was specified as a path to a file in the
+ // current directory. Add a leading "./" so it can run
+ // without the current directory being in the search path.
+ cmd = "./" + cmd;
+ }
+ std::string launcher =
+ this->MakeLauncher(ccg, target,
+ workingDir.empty()? START_OUTPUT : NONE);
+ cmd = launcher + this->ConvertShellCommand(cmd, NONE);
+
+ ccg.AppendArguments(c, cmd);
+ if(content)
+ {
+ // Rule content does not include the launcher.
+ *content << (cmd.c_str()+launcher.size());
+ }
+ if(this->BorlandMakeCurlyHack)
+ {
+ // Borland Make has a very strange bug. If the first curly
+ // brace anywhere in the command string is a left curly, it
+ // must be written {{} instead of just {. Otherwise some
+ // curly braces are removed. The hack can be skipped if the
+ // first curly brace is the last character.
+ std::string::size_type lcurly = cmd.find("{");
+ if(lcurly != cmd.npos && lcurly < (cmd.size()-1))
+ {
+ std::string::size_type rcurly = cmd.find("}");
+ if(rcurly == cmd.npos || rcurly > lcurly)
+ {
+ // The first curly is a left curly. Use the hack.
+ std::string hack_cmd = cmd.substr(0, lcurly);
+ hack_cmd += "{{}";
+ hack_cmd += cmd.substr(lcurly+1);
+ cmd = hack_cmd;
+ }
+ }
+ }
+ if (launcher.empty())
+ {
+ if (useCall)
+ {
+ cmd = "call " + cmd;
+ }
+ else if (this->NMake && cmd[0]=='"')
+ {
+ cmd = "echo >nul && " + cmd;
+ }
+ }
+ commands1.push_back(cmd);
+ }
+ }
+
+ // Setup the proper working directory for the commands.
+ this->CreateCDCommand(commands1, dir.c_str(), relative);
+
+ // push back the custom commands
+ commands.insert(commands.end(), commands1.begin(), commands1.end());
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalUnixMakefileGenerator3::MakeLauncher(
+ cmCustomCommandGenerator const& ccg,
+ cmTarget* target, RelativeRoot relative)
+{
+ // Short-circuit if there is no launcher.
+ const char* prop = "RULE_LAUNCH_CUSTOM";
+ const char* val = this->GetRuleLauncher(target, prop);
+ if(!(val && *val))
+ {
+ return "";
+ }
+
+ // Expand rules in the empty string. It may insert the launcher and
+ // perform replacements.
+ RuleVariables vars;
+ vars.RuleLauncher = prop;
+ vars.CMTarget = target;
+ std::string output;
+ const std::vector<std::string>& outputs = ccg.GetOutputs();
+ if(!outputs.empty())
+ {
+ output = this->Convert(outputs[0], relative, SHELL);
+ }
+ vars.Output = output.c_str();
+
+ std::string launcher;
+ this->ExpandRuleVariables(launcher, vars);
+ if(!launcher.empty())
+ {
+ launcher += " ";
+ }
+ return launcher;
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::AppendCleanCommand(std::vector<std::string>& commands,
+ const std::vector<std::string>& files,
+ cmTarget& target, const char* filename)
+{
+ std::string cleanfile = this->Makefile->GetCurrentOutputDirectory();
+ cleanfile += "/";
+ cleanfile += this->GetTargetDirectory(target);
+ cleanfile += "/cmake_clean";
+ if(filename)
+ {
+ cleanfile += "_";
+ cleanfile += filename;
+ }
+ cleanfile += ".cmake";
+ std::string cleanfilePath = this->Convert(cleanfile, FULL);
+ cmsys::ofstream fout(cleanfilePath.c_str());
+ if(!fout)
+ {
+ cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
+ }
+ if(!files.empty())
+ {
+ fout << "file(REMOVE_RECURSE\n";
+ for(std::vector<std::string>::const_iterator f = files.begin();
+ f != files.end(); ++f)
+ {
+ std::string fc = this->Convert(*f,START_OUTPUT,UNCHANGED);
+ fout << " " << this->EscapeForCMake(fc) << "\n";
+ }
+ fout << ")\n";
+ }
+ std::string remove = "$(CMAKE_COMMAND) -P ";
+ remove += this->Convert(cleanfile, START_OUTPUT, SHELL);
+ commands.push_back(remove);
+
+ // For the main clean rule add per-language cleaning.
+ if(!filename)
+ {
+ // Get the set of source languages in the target.
+ std::set<std::string> languages;
+ target.GetLanguages(languages,
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ fout << "\n"
+ << "# Per-language clean rules from dependency scanning.\n"
+ << "foreach(lang";
+ for(std::set<std::string>::const_iterator l = languages.begin();
+ l != languages.end(); ++l)
+ {
+ fout << " " << *l;
+ }
+ fout << ")\n"
+ << " include(" << this->GetTargetDirectory(target)
+ << "/cmake_clean_${lang}.cmake OPTIONAL)\n"
+ << "endforeach()\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
+ const char* text,
+ EchoColor color)
+{
+ // Choose the color for the text.
+ std::string color_name;
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ if(this->GlobalGenerator->GetToolSupportsColor() && this->ColorMakefile)
+ {
+ // See cmake::ExecuteEchoColor in cmake.cxx for these options.
+ // This color set is readable on both black and white backgrounds.
+ switch(color)
+ {
+ case EchoNormal:
+ break;
+ case EchoDepend:
+ color_name = "--magenta --bold ";
+ break;
+ case EchoBuild:
+ color_name = "--green ";
+ break;
+ case EchoLink:
+ color_name = "--red --bold ";
+ break;
+ case EchoGenerate:
+ color_name = "--blue --bold ";
+ break;
+ case EchoGlobal:
+ color_name = "--cyan ";
+ break;
+ }
+ }
+#else
+ (void)color;
+#endif
+
+ // Echo one line at a time.
+ std::string line;
+ line.reserve(200);
+ for(const char* c = text;; ++c)
+ {
+ if(*c == '\n' || *c == '\0')
+ {
+ // Avoid writing a blank last line on end-of-string.
+ if(*c != '\0' || !line.empty())
+ {
+ // Add a command to echo this line.
+ std::string cmd;
+ if(color_name.empty())
+ {
+ // Use the native echo command.
+ cmd = "@echo ";
+ cmd += this->EscapeForShell(line, false, true);
+ }
+ else
+ {
+ // Use cmake to echo the text in color.
+ cmd = "@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ";
+ cmd += color_name;
+ cmd += this->EscapeForShell(line);
+ }
+ commands.push_back(cmd);
+ }
+
+ // Reset the line to emtpy.
+ line = "";
+
+ // Terminate on end-of-string.
+ if(*c == '\0')
+ {
+ return;
+ }
+ }
+ else if(*c != '\r')
+ {
+ // Append this character to the current line.
+ line += *c;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalUnixMakefileGenerator3
+::CreateMakeVariable(const std::string& sin, const std::string& s2in)
+{
+ std::string s = sin;
+ std::string s2 = s2in;
+ std::string unmodified = s;
+ unmodified += s2;
+ // if there is no restriction on the length of make variables
+ // and there are no "." characters in the string, then return the
+ // unmodified combination.
+ if((!this->MakefileVariableSize && unmodified.find('.') == s.npos)
+ && (!this->MakefileVariableSize && unmodified.find('+') == s.npos)
+ && (!this->MakefileVariableSize && unmodified.find('-') == s.npos))
+ {
+ return unmodified;
+ }
+
+ // see if the variable has been defined before and return
+ // the modified version of the variable
+ std::map<std::string, std::string>::iterator i =
+ this->MakeVariableMap.find(unmodified);
+ if(i != this->MakeVariableMap.end())
+ {
+ return i->second;
+ }
+ // start with the unmodified variable
+ std::string ret = unmodified;
+ // if this there is no value for this->MakefileVariableSize then
+ // the string must have bad characters in it
+ if(!this->MakefileVariableSize)
+ {
+ cmSystemTools::ReplaceString(ret, ".", "_");
+ cmSystemTools::ReplaceString(ret, "-", "__");
+ cmSystemTools::ReplaceString(ret, "+", "___");
+ int ni = 0;
+ char buffer[5];
+ // make sure the _ version is not already used, if
+ // it is used then add number to the end of the variable
+ while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
+ {
+ ++ni;
+ sprintf(buffer, "%04d", ni);
+ ret = unmodified + buffer;
+ }
+ this->ShortMakeVariableMap[ret] = "1";
+ this->MakeVariableMap[unmodified] = ret;
+ return ret;
+ }
+
+ // if the string is greater than 32 chars it is an invalid variable name
+ // for borland make
+ if(static_cast<int>(ret.size()) > this->MakefileVariableSize)
+ {
+ int keep = this->MakefileVariableSize - 8;
+ int size = keep + 3;
+ std::string str1 = s;
+ std::string str2 = s2;
+ // we must shorten the combined string by 4 characters
+ // keep no more than 24 characters from the second string
+ if(static_cast<int>(str2.size()) > keep)
+ {
+ str2 = str2.substr(0, keep);
+ }
+ if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
+ {
+ str1 = str1.substr(0, size - str2.size());
+ }
+ char buffer[5];
+ int ni = 0;
+ sprintf(buffer, "%04d", ni);
+ ret = str1 + str2 + buffer;
+ while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
+ {
+ ++ni;
+ sprintf(buffer, "%04d", ni);
+ ret = str1 + str2 + buffer;
+ }
+ if(ni == 1000)
+ {
+ cmSystemTools::Error("Borland makefile variable length too long");
+ return unmodified;
+ }
+ // once an unused variable is found
+ this->ShortMakeVariableMap[ret] = "1";
+ }
+ // always make an entry into the unmodified to variable map
+ this->MakeVariableMap[unmodified] = ret;
+ return ret;
+}
+
+//----------------------------------------------------------------------------
+bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
+ bool verbose,
+ bool color)
+{
+ // read in the target info file
+ if(!this->Makefile->ReadListFile(0, tgtInfo) ||
+ cmSystemTools::GetErrorOccuredFlag())
+ {
+ cmSystemTools::Error("Target DependInfo.cmake file not found");
+ }
+
+ // Check if any multiple output pairs have a missing file.
+ this->CheckMultipleOutputs(verbose);
+
+ std::string dir = cmSystemTools::GetFilenamePath(tgtInfo);
+ std::string internalDependFile = dir + "/depend.internal";
+ std::string dependFile = dir + "/depend.make";
+
+ // If the target DependInfo.cmake file has changed since the last
+ // time dependencies were scanned then force rescanning. This may
+ // happen when a new source file is added and CMake regenerates the
+ // project but no other sources were touched.
+ bool needRescanDependInfo = false;
+ cmFileTimeComparison* ftc =
+ this->GlobalGenerator->GetCMakeInstance()->GetFileComparison();
+ {
+ int result;
+ if(!ftc->FileTimeCompare(internalDependFile.c_str(), tgtInfo, &result) ||
+ result < 0)
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Dependee \"" << tgtInfo
+ << "\" is newer than depender \""
+ << internalDependFile << "\"." << std::endl;
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ needRescanDependInfo = true;
+ }
+ }
+
+ // 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->GetStartOutputDirectory();
+ dirInfoFile += cmake::GetCMakeFilesDirectory();
+ dirInfoFile += "/CMakeDirectoryInformation.cmake";
+ {
+ int result;
+ if(!ftc->FileTimeCompare(internalDependFile.c_str(),
+ dirInfoFile.c_str(), &result) || result < 0)
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Dependee \"" << dirInfoFile
+ << "\" is newer than depender \""
+ << internalDependFile << "\"." << std::endl;
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ needRescanDirInfo = true;
+ }
+ }
+
+ // Check the implicit dependencies to see if they are up to date.
+ // The build.make file may have explicit dependencies for the object
+ // files but these will not affect the scanning process so they need
+ // not be considered.
+ std::map<std::string, cmDepends::DependencyVector> validDependencies;
+ bool needRescanDependencies = false;
+ if (needRescanDirInfo == false)
+ {
+ cmDependsC checker;
+ checker.SetVerbose(verbose);
+ checker.SetFileComparison(ftc);
+ // cmDependsC::Check() fills the vector validDependencies() with the
+ // dependencies for those files where they are still valid, i.e. neither
+ // the files themselves nor any files they depend on have changed.
+ // We don't do that if the CMakeDirectoryInformation.cmake file has
+ // changed, because then potentially all dependencies have changed.
+ // This information is given later on to cmDependsC, which then only
+ // rescans the files where it did not get valid dependencies via this
+ // dependency vector. This means that in the normal case, when only
+ // few or one file have been edited, then also only this one file is
+ // actually scanned again, instead of all files for this target.
+ needRescanDependencies = !checker.Check(dependFile.c_str(),
+ internalDependFile.c_str(),
+ validDependencies);
+ }
+
+ if(needRescanDependInfo || needRescanDirInfo || needRescanDependencies)
+ {
+ // The dependencies must be regenerated.
+ std::string targetName = cmSystemTools::GetFilenameName(dir);
+ targetName = targetName.substr(0, targetName.length()-4);
+ std::string message = "Scanning dependencies of target ";
+ message += targetName;
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmSystemTools::MakefileColorEcho(
+ cmsysTerminal_Color_ForegroundMagenta |
+ cmsysTerminal_Color_ForegroundBold,
+ message.c_str(), true, color);
+#else
+ fprintf(stdout, "%s\n", message.c_str());
+#endif
+
+ return this->ScanDependencies(dir.c_str(), validDependencies);
+ }
+
+ // The dependencies are already up-to-date.
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmLocalUnixMakefileGenerator3
+::ScanDependencies(const char* targetDir,
+ std::map<std::string, cmDepends::DependencyVector>& validDeps)
+{
+ // Read the directory information file.
+ cmMakefile* mf = this->Makefile;
+ bool haveDirectoryInfo = false;
+ std::string dirInfoFile = this->Makefile->GetStartOutputDirectory();
+ dirInfoFile += cmake::GetCMakeFilesDirectory();
+ dirInfoFile += "/CMakeDirectoryInformation.cmake";
+ if(mf->ReadListFile(0, dirInfoFile.c_str()) &&
+ !cmSystemTools::GetErrorOccuredFlag())
+ {
+ haveDirectoryInfo = true;
+ }
+
+ // Lookup useful directory information.
+ if(haveDirectoryInfo)
+ {
+ // Test whether we need to force Unix paths.
+ if(const char* force = mf->GetDefinition("CMAKE_FORCE_UNIX_PATHS"))
+ {
+ if(!cmSystemTools::IsOff(force))
+ {
+ cmSystemTools::SetForceUnixPaths(true);
+ }
+ }
+
+ // Setup relative path top directories.
+ this->RelativePathsConfigured = true;
+ if(const char* relativePathTopSource =
+ mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_SOURCE"))
+ {
+ this->RelativePathTopSource = relativePathTopSource;
+ }
+ if(const char* relativePathTopBinary =
+ mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_BINARY"))
+ {
+ this->RelativePathTopBinary = relativePathTopBinary;
+ }
+ }
+ else
+ {
+ cmSystemTools::Error("Directory Information file not found");
+ }
+
+ // create the file stream for the depends file
+ std::string dir = targetDir;
+
+ // Open the make depends file. This should be copy-if-different
+ // because the make tool may try to reload it needlessly otherwise.
+ std::string ruleFileNameFull = dir;
+ ruleFileNameFull += "/depend.make";
+ cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
+ ruleFileStream.SetCopyIfDifferent(true);
+ if(!ruleFileStream)
+ {
+ return false;
+ }
+
+ // Open the cmake dependency tracking file. This should not be
+ // copy-if-different because dependencies are re-scanned when it is
+ // older than the DependInfo.cmake.
+ std::string internalRuleFileNameFull = dir;
+ internalRuleFileNameFull += "/depend.internal";
+ cmGeneratedFileStream
+ internalRuleFileStream(internalRuleFileNameFull.c_str());
+ if(!internalRuleFileStream)
+ {
+ return false;
+ }
+
+ this->WriteDisclaimer(ruleFileStream);
+ this->WriteDisclaimer(internalRuleFileStream);
+
+ // for each language we need to scan, scan it
+ const char *langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES");
+ std::vector<std::string> langs;
+ cmSystemTools::ExpandListArgument(langStr, langs);
+ for (std::vector<std::string>::iterator li =
+ langs.begin(); li != langs.end(); ++li)
+ {
+ // construct the checker
+ std::string lang = *li;
+
+ // Create the scanner for this language
+ cmDepends *scanner = 0;
+ if(lang == "C" || lang == "CXX" || lang == "RC" || lang == "ASM")
+ {
+ // TODO: Handle RC (resource files) dependencies correctly.
+ scanner = new cmDependsC(this, targetDir, lang, &validDeps);
+ }
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ else if(lang == "Fortran")
+ {
+ scanner = new cmDependsFortran(this);
+ }
+ else if(lang == "Java")
+ {
+ scanner = new cmDependsJava();
+ }
+#endif
+
+ if (scanner)
+ {
+ scanner->SetLocalGenerator(this);
+ scanner->SetFileComparison
+ (this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
+ scanner->SetLanguage(lang);
+ scanner->SetTargetDirectory(dir.c_str());
+ scanner->Write(ruleFileStream, internalRuleFileStream);
+
+ // free the scanner for this language
+ delete scanner;
+ }
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::CheckMultipleOutputs(bool verbose)
+{
+ cmMakefile* mf = this->Makefile;
+
+ // Get the string listing the multiple output pairs.
+ const char* pairs_string = mf->GetDefinition("CMAKE_MULTIPLE_OUTPUT_PAIRS");
+ if(!pairs_string)
+ {
+ return;
+ }
+
+ // Convert the string to a list and preserve empty entries.
+ std::vector<std::string> pairs;
+ cmSystemTools::ExpandListArgument(pairs_string, pairs, true);
+ for(std::vector<std::string>::const_iterator i = pairs.begin();
+ i != pairs.end() && (i+1) != pairs.end();)
+ {
+ const std::string& depender = *i++;
+ const std::string& dependee = *i++;
+
+ // If the depender is missing then delete the dependee to make
+ // sure both will be regenerated.
+ if(cmSystemTools::FileExists(dependee.c_str()) &&
+ !cmSystemTools::FileExists(depender.c_str()))
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Deleting primary custom command output \"" << dependee
+ << "\" because another output \""
+ << depender << "\" does not exist." << std::endl;
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ cmSystemTools::RemoveFile(dependee.c_str());
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3
+::WriteLocalAllRules(std::ostream& ruleFileStream)
+{
+ this->WriteDisclaimer(ruleFileStream);
+
+ // Write the main entry point target. This must be the VERY first
+ // target so that make with no arguments will run it.
+ {
+ // Just depend on the all target to drive the build.
+ std::vector<std::string> depends;
+ std::vector<std::string> no_commands;
+ depends.push_back("all");
+
+ // Write the rule.
+ this->WriteMakeRule(ruleFileStream,
+ "Default target executed when no arguments are "
+ "given to make.",
+ "default_target",
+ depends,
+ no_commands, true);
+
+ // Help out users that try "gmake target1 target2 -j".
+ cmGlobalUnixMakefileGenerator3* gg =
+ static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
+ if(gg->AllowNotParallel())
+ {
+ std::vector<std::string> no_depends;
+ this->WriteMakeRule(ruleFileStream,
+ "Allow only one \"make -f Makefile2\" at a time, but pass parallelism.",
+ ".NOTPARALLEL", no_depends, no_commands, true);
+ }
+ }
+
+ this->WriteSpecialTargetsTop(ruleFileStream);
+
+ // Include the progress variables for the target.
+ // Write all global targets
+ this->WriteDivider(ruleFileStream);
+ ruleFileStream
+ << "# Targets provided globally by CMake.\n"
+ << "\n";
+ cmTargets* targets = &(this->Makefile->GetTargets());
+ cmTargets::iterator glIt;
+ for ( glIt = targets->begin(); glIt != targets->end(); ++ glIt )
+ {
+ if ( glIt->second.GetType() == cmTarget::GLOBAL_TARGET )
+ {
+ std::string targetString = "Special rule for the target " + glIt->first;
+ std::vector<std::string> commands;
+ std::vector<std::string> depends;
+
+ const char* text = glIt->second.GetProperty("EchoString");
+ if ( !text )
+ {
+ text = "Running external command ...";
+ }
+ std::set<std::string>::const_iterator dit;
+ for ( dit = glIt->second.GetUtilities().begin();
+ dit != glIt->second.GetUtilities().end();
+ ++ dit )
+ {
+ depends.push_back(*dit);
+ }
+ this->AppendEcho(commands, text,
+ cmLocalUnixMakefileGenerator3::EchoGlobal);
+
+ // Global targets store their rules in pre- and post-build commands.
+ this->AppendCustomDepends(depends,
+ glIt->second.GetPreBuildCommands());
+ this->AppendCustomDepends(depends,
+ glIt->second.GetPostBuildCommands());
+ this->AppendCustomCommands(commands,
+ glIt->second.GetPreBuildCommands(),
+ &glIt->second,
+ cmLocalGenerator::START_OUTPUT);
+ this->AppendCustomCommands(commands,
+ glIt->second.GetPostBuildCommands(),
+ &glIt->second,
+ cmLocalGenerator::START_OUTPUT);
+ std::string targetName = glIt->second.GetName();
+ this->WriteMakeRule(ruleFileStream, targetString.c_str(),
+ targetName, depends, commands, true);
+
+ // Provide a "/fast" version of the target.
+ depends.clear();
+ if((targetName == "install")
+ || (targetName == "install_local")
+ || (targetName == "install_strip"))
+ {
+ // Provide a fast install target that does not depend on all
+ // but has the same command.
+ depends.push_back("preinstall/fast");
+ }
+ else
+ {
+ // Just forward to the real target so at least it will work.
+ depends.push_back(targetName);
+ commands.clear();
+ }
+ targetName += "/fast";
+ this->WriteMakeRule(ruleFileStream, targetString.c_str(),
+ targetName, depends, commands, true);
+ }
+ }
+
+ std::vector<std::string> depends;
+ std::vector<std::string> commands;
+
+ // Write the all rule.
+ std::string dir;
+ std::string recursiveTarget = this->Makefile->GetStartOutputDirectory();
+ recursiveTarget += "/all";
+
+ depends.push_back("cmake_check_build_system");
+
+ std::string progressDir = this->Makefile->GetHomeOutputDirectory();
+ progressDir += cmake::GetCMakeFilesDirectory();
+ {
+ cmOStringStream progCmd;
+ progCmd <<
+ "$(CMAKE_COMMAND) -E cmake_progress_start ";
+ progCmd << this->Convert(progressDir,
+ cmLocalGenerator::FULL,
+ cmLocalGenerator::SHELL);
+
+ std::string progressFile = cmake::GetCMakeFilesDirectory();
+ progressFile += "/progress.marks";
+ std::string progressFileNameFull =
+ this->ConvertToFullPath(progressFile);
+ progCmd << " " << this->Convert(progressFileNameFull,
+ cmLocalGenerator::FULL,
+ cmLocalGenerator::SHELL);
+ commands.push_back(progCmd.str());
+ }
+ std::string mf2Dir = cmake::GetCMakeFilesDirectoryPostSlash();
+ mf2Dir += "Makefile2";
+ commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
+ recursiveTarget));
+ this->CreateCDCommand(commands,
+ this->Makefile->GetHomeOutputDirectory(),
+ cmLocalGenerator::START_OUTPUT);
+ {
+ cmOStringStream progCmd;
+ progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
+ progCmd << this->Convert(progressDir,
+ cmLocalGenerator::FULL,
+ cmLocalGenerator::SHELL);
+ progCmd << " 0";
+ commands.push_back(progCmd.str());
+ }
+ this->WriteMakeRule(ruleFileStream, "The main all target", "all",
+ depends, commands, true);
+
+ // Write the clean rule.
+ recursiveTarget = this->Makefile->GetStartOutputDirectory();
+ recursiveTarget += "/clean";
+ commands.clear();
+ depends.clear();
+ commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
+ recursiveTarget));
+ this->CreateCDCommand(commands,
+ this->Makefile->GetHomeOutputDirectory(),
+ cmLocalGenerator::START_OUTPUT);
+ this->WriteMakeRule(ruleFileStream, "The main clean target", "clean",
+ depends, commands, true);
+ commands.clear();
+ depends.clear();
+ depends.push_back("clean");
+ this->WriteMakeRule(ruleFileStream, "The main clean target", "clean/fast",
+ depends, commands, true);
+
+ // Write the preinstall rule.
+ recursiveTarget = this->Makefile->GetStartOutputDirectory();
+ recursiveTarget += "/preinstall";
+ commands.clear();
+ depends.clear();
+ const char* noall =
+ this->Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
+ if(!noall || cmSystemTools::IsOff(noall))
+ {
+ // Drive the build before installing.
+ depends.push_back("all");
+ }
+ else
+ {
+ // At least make sure the build system is up to date.
+ depends.push_back("cmake_check_build_system");
+ }
+ commands.push_back
+ (this->GetRecursiveMakeCall(mf2Dir.c_str(), recursiveTarget));
+ this->CreateCDCommand(commands,
+ this->Makefile->GetHomeOutputDirectory(),
+ cmLocalGenerator::START_OUTPUT);
+ this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
+ "preinstall", depends, commands, true);
+ depends.clear();
+ this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
+ "preinstall/fast", depends, commands, true);
+
+ // write the depend rule, really a recompute depends rule
+ depends.clear();
+ commands.clear();
+ std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
+ cmakefileName += "Makefile.cmake";
+ std::string runRule =
+ "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
+ runRule += " --check-build-system ";
+ runRule += this->Convert(cmakefileName,cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ runRule += " 1";
+ commands.push_back(runRule);
+ this->CreateCDCommand(commands,
+ this->Makefile->GetHomeOutputDirectory(),
+ cmLocalGenerator::START_OUTPUT);
+ this->WriteMakeRule(ruleFileStream, "clear depends",
+ "depend",
+ depends, commands, true);
+}
+
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::ClearDependencies(cmMakefile* mf,
+ bool verbose)
+{
+ // Get the list of target files to check
+ const char* infoDef = mf->GetDefinition("CMAKE_DEPEND_INFO_FILES");
+ if(!infoDef)
+ {
+ return;
+ }
+ std::vector<std::string> files;
+ cmSystemTools::ExpandListArgument(infoDef, files);
+
+ // Each depend information file corresponds to a target. Clear the
+ // dependencies for that target.
+ cmDepends clearer;
+ clearer.SetVerbose(verbose);
+ for(std::vector<std::string>::iterator l = files.begin();
+ l != files.end(); ++l)
+ {
+ std::string dir = cmSystemTools::GetFilenamePath(*l);
+
+ // Clear the implicit dependency makefile.
+ std::string dependFile = dir + "/depend.make";
+ clearer.Clear(dependFile.c_str());
+
+ // Remove the internal dependency check file to force
+ // regeneration.
+ std::string internalDependFile = dir + "/depend.internal";
+ cmSystemTools::RemoveFile(internalDependFile.c_str());
+ }
+}
+
+
+void cmLocalUnixMakefileGenerator3
+::WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &target)
+{
+ ImplicitDependLanguageMap const& implicitLangs =
+ this->GetImplicitDepends(target);
+
+ // list the languages
+ cmakefileStream
+ << "# The set of languages for which implicit dependencies are needed:\n";
+ cmakefileStream
+ << "set(CMAKE_DEPENDS_LANGUAGES\n";
+ for(ImplicitDependLanguageMap::const_iterator
+ l = implicitLangs.begin(); l != implicitLangs.end(); ++l)
+ {
+ cmakefileStream << " \"" << l->first << "\"\n";
+ }
+ cmakefileStream << " )\n";
+
+ // now list the files for each language
+ cmakefileStream
+ << "# The set of files for implicit dependencies of each language:\n";
+ for(ImplicitDependLanguageMap::const_iterator
+ l = implicitLangs.begin(); l != implicitLangs.end(); ++l)
+ {
+ cmakefileStream
+ << "set(CMAKE_DEPENDS_CHECK_" << l->first << "\n";
+ ImplicitDependFileMap const& implicitPairs = l->second;
+
+ // for each file pair
+ for(ImplicitDependFileMap::const_iterator pi = implicitPairs.begin();
+ pi != implicitPairs.end(); ++pi)
+ {
+ for(cmDepends::DependencyVector::const_iterator di = pi->second.begin();
+ di != pi->second.end(); ++ di)
+ {
+ cmakefileStream << " \"" << *di << "\" ";
+ cmakefileStream << "\"" << pi->first << "\"\n";
+ }
+ }
+ cmakefileStream << " )\n";
+
+ // Tell the dependency scanner what compiler is used.
+ std::string cidVar = "CMAKE_";
+ cidVar += l->first;
+ cidVar += "_COMPILER_ID";
+ const char* cid = this->Makefile->GetDefinition(cidVar);
+ if(cid && *cid)
+ {
+ cmakefileStream
+ << "set(CMAKE_" << l->first << "_COMPILER_ID \""
+ << cid << "\")\n";
+ }
+ }
+
+ // Build a list of preprocessor definitions for the target.
+ std::set<std::string> defines;
+ this->AddCompileDefinitions(defines, &target,
+ this->ConfigurationName);
+ if(!defines.empty())
+ {
+ cmakefileStream
+ << "\n"
+ << "# Preprocessor definitions for this target.\n"
+ << "set(CMAKE_TARGET_DEFINITIONS\n";
+ for(std::set<std::string>::const_iterator di = defines.begin();
+ di != defines.end(); ++di)
+ {
+ cmakefileStream
+ << " " << this->EscapeForCMake(*di) << "\n";
+ }
+ cmakefileStream
+ << " )\n";
+ }
+
+ // Store include transform rule properties. Write the directory
+ // rules first because they may be overridden by later target rules.
+ std::vector<std::string> transformRules;
+ if(const char* xform =
+ this->Makefile->GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"))
+ {
+ cmSystemTools::ExpandListArgument(xform, transformRules);
+ }
+ if(const char* xform =
+ target.GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"))
+ {
+ cmSystemTools::ExpandListArgument(xform, transformRules);
+ }
+ if(!transformRules.empty())
+ {
+ cmakefileStream
+ << "set(CMAKE_INCLUDE_TRANSFORMS\n";
+ for(std::vector<std::string>::const_iterator tri = transformRules.begin();
+ tri != transformRules.end(); ++tri)
+ {
+ cmakefileStream << " " << this->EscapeForCMake(*tri) << "\n";
+ }
+ cmakefileStream
+ << " )\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
+{
+ os
+ << "# CMAKE generated file: DO NOT EDIT!\n"
+ << "# Generated by \"" << this->GlobalGenerator->GetName() << "\""
+ << " Generator, CMake Version "
+ << cmVersion::GetMajorVersion() << "."
+ << cmVersion::GetMinorVersion() << "\n\n";
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalUnixMakefileGenerator3
+::GetRecursiveMakeCall(const char *makefile, const std::string& tgt)
+{
+ // Call make on the given file.
+ std::string cmd;
+ cmd += "$(MAKE) -f ";
+ cmd += this->Convert(makefile,NONE,SHELL);
+ cmd += " ";
+
+ // Pass down verbosity level.
+ if(this->GetMakeSilentFlag().size())
+ {
+ cmd += this->GetMakeSilentFlag();
+ cmd += " ";
+ }
+
+ // Most unix makes will pass the command line flags to make down to
+ // sub-invoked makes via an environment variable. However, some
+ // makes do not support that, so you have to pass the flags
+ // explicitly.
+ if(this->GetPassMakeflags())
+ {
+ cmd += "-$(MAKEFLAGS) ";
+ }
+
+ // Add the target.
+ if (!tgt.empty())
+ {
+ // The make target is always relative to the top of the build tree.
+ std::string tgt2 = this->Convert(tgt, HOME_OUTPUT);
+
+ // The target may have been written with windows paths.
+ cmSystemTools::ConvertToOutputSlashes(tgt2);
+
+ // Escape one extra time if the make tool requires it.
+ if(this->MakeCommandEscapeTargetTwice)
+ {
+ tgt2 = this->EscapeForShell(tgt2, true, false);
+ }
+
+ // The target name is now a string that should be passed verbatim
+ // on the command line.
+ cmd += this->EscapeForShell(tgt2, true, false);
+ }
+ return cmd;
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
+{
+ os
+ << "#======================================"
+ << "=======================================\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3
+::WriteCMakeArgument(std::ostream& os, const char* s)
+{
+ // Write the given string to the stream with escaping to get it back
+ // into CMake through the lexical scanner.
+ os << "\"";
+ for(const char* c = s; *c; ++c)
+ {
+ if(*c == '\\')
+ {
+ os << "\\\\";
+ }
+ else if(*c == '"')
+ {
+ os << "\\\"";
+ }
+ else
+ {
+ os << *c;
+ }
+ }
+ os << "\"";
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p,
+ bool useWatcomQuote)
+{
+ // Split the path into its components.
+ std::vector<std::string> components;
+ cmSystemTools::SplitPath(p, components);
+
+ // Open the quoted result.
+ std::string result;
+ if(useWatcomQuote)
+ {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ result = "'";
+#else
+ result = "\"'";
+#endif
+ }
+ else
+ {
+ result = "\"";
+ }
+
+ // Return an empty path if there are no components.
+ if(!components.empty())
+ {
+ // Choose a slash direction and fix root component.
+ const char* slash = "/";
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if(!cmSystemTools::GetForceUnixPaths())
+ {
+ slash = "\\";
+ for(std::string::iterator i = components[0].begin();
+ i != components[0].end(); ++i)
+ {
+ if(*i == '/')
+ {
+ *i = '\\';
+ }
+ }
+ }
+#endif
+
+ // Begin the quoted result with the root component.
+ result += components[0];
+
+ // Now add the rest of the components separated by the proper slash
+ // direction for this platform.
+ bool first = true;
+ for(unsigned int i=1; i < components.size(); ++i)
+ {
+ // Only the last component can be empty to avoid double slashes.
+ if(components[i].length() > 0 || (i == (components.size()-1)))
+ {
+ if(!first)
+ {
+ result += slash;
+ }
+ result += components[i];
+ first = false;
+ }
+ }
+ }
+
+ // Close the quoted result.
+ if(useWatcomQuote)
+ {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ result += "'";
+#else
+ result += "'\"";
+#endif
+ }
+ else
+ {
+ result += "\"";
+ }
+
+ return result;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalUnixMakefileGenerator3
+::GetTargetDirectory(cmTarget const& target) const
+{
+ std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
+ dir += target.GetName();
+#if defined(__VMS)
+ dir += "_dir";
+#else
+ dir += ".dir";
+#endif
+ return dir;
+}
+
+//----------------------------------------------------------------------------
+cmLocalUnixMakefileGenerator3::ImplicitDependLanguageMap const&
+cmLocalUnixMakefileGenerator3::GetImplicitDepends(cmTarget const& tgt)
+{
+ return this->ImplicitDepends[tgt.GetName()];
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalUnixMakefileGenerator3::AddImplicitDepends(cmTarget const& tgt,
+ const std::string& lang,
+ const char* obj,
+ const char* src)
+{
+ this->ImplicitDepends[tgt.GetName()][lang][obj].push_back(src);
+}
+
+//----------------------------------------------------------------------------
+void cmLocalUnixMakefileGenerator3
+::CreateCDCommand(std::vector<std::string>& commands, const char *tgtDir,
+ cmLocalGenerator::RelativeRoot relRetDir)
+{
+ const char* retDir = this->GetRelativeRootPath(relRetDir);
+
+ // do we need to cd?
+ if (!strcmp(tgtDir,retDir))
+ {
+ return;
+ }
+
+ // In a Windows shell we must change drive letter too. The shell
+ // used by NMake and Borland make does not support "cd /d" so this
+ // feature simply cannot work with them (Borland make does not even
+ // support changing the drive letter with just "d:").
+ const char* cd_cmd = this->MinGWMake? "cd /d " : "cd ";
+
+ if(!this->UnixCD)
+ {
+ // On Windows we must perform each step separately and then change
+ // back because the shell keeps the working directory between
+ // commands.
+ std::string cmd = cd_cmd;
+ cmd += this->ConvertToOutputForExisting(tgtDir, relRetDir);
+ commands.insert(commands.begin(),cmd);
+
+ // Change back to the starting directory.
+ cmd = cd_cmd;
+ cmd += this->ConvertToOutputForExisting(relRetDir, tgtDir);
+ commands.push_back(cmd);
+ }
+ else
+ {
+ // On UNIX we must construct a single shell command to change
+ // directory and build because make resets the directory between
+ // each command.
+ std::vector<std::string>::iterator i = commands.begin();
+ for (; i != commands.end(); ++i)
+ {
+ std::string cmd = cd_cmd;
+ cmd += this->ConvertToOutputForExisting(tgtDir, relRetDir);
+ cmd += " && ";
+ cmd += *i;
+ *i = cmd;
+ }
+ }
+}
diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h
new file mode 100644
index 0000000000..4f2e4a0355
--- /dev/null
+++ b/Source/cmLocalUnixMakefileGenerator3.h
@@ -0,0 +1,385 @@
+/*============================================================================
+ 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 cmLocalUnixMakefileGenerator3_h
+#define cmLocalUnixMakefileGenerator3_h
+
+#include "cmLocalGenerator.h"
+
+// for cmDepends::DependencyVector
+#include "cmDepends.h"
+
+class cmCustomCommand;
+class cmCustomCommandGenerator;
+class cmDependInformation;
+class cmDepends;
+class cmMakefileTargetGenerator;
+class cmTarget;
+class cmSourceFile;
+
+/** \class cmLocalUnixMakefileGenerator3
+ * \brief Write a LocalUnix makefiles.
+ *
+ * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
+ * member Makefile.
+ */
+class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator
+{
+public:
+ cmLocalUnixMakefileGenerator3();
+ virtual ~cmLocalUnixMakefileGenerator3();
+
+ /**
+ * Process the CMakeLists files for this directory to fill in the
+ * Makefile ivar
+ */
+ virtual void Configure();
+
+ /**
+ * Generate the makefile for this directory.
+ */
+ virtual void Generate();
+
+
+ // this returns the relative path between the HomeOutputDirectory and this
+ // local generators StartOutputDirectory
+ const std::string &GetHomeRelativeOutputPath();
+
+ // Write out a make rule
+ void WriteMakeRule(std::ostream& os,
+ const char* comment,
+ const std::string& target,
+ const std::vector<std::string>& depends,
+ const std::vector<std::string>& commands,
+ bool symbolic,
+ bool in_help = false);
+
+ // write the main variables used by the makefiles
+ void WriteMakeVariables(std::ostream& makefileStream);
+
+ /**
+ * If true, then explicitly pass MAKEFLAGS on the make all target for makes
+ * that do not use environment variables.
+ *
+ */
+ void SetPassMakeflags(bool s){this->PassMakeflags = s;}
+ bool GetPassMakeflags() { return this->PassMakeflags; }
+
+ /**
+ * Set the flag used to keep the make program silent.
+ */
+ void SetMakeSilentFlag(const std::string& s) { this->MakeSilentFlag = s; }
+ std::string &GetMakeSilentFlag() { return this->MakeSilentFlag; }
+
+ /**
+ * Set to true if the shell being used is the windows shell.
+ * This controls if statements in the makefile and the SHELL variable.
+ * The default is false.
+ */
+ void SetWindowsShell(bool v) {this->WindowsShell = v;}
+
+ /**
+ * Set to true if the make tool being used is Watcom WMake.
+ */
+ void SetWatcomWMake(bool v) {this->WatcomWMake = v;}
+
+ /**
+ * Set to true if the make tool being used is MinGW Make.
+ */
+ void SetMinGWMake(bool v) {this->MinGWMake = v;}
+
+ /**
+ * Set to true if the make tool being used is NMake.
+ */
+ void SetNMake(bool v) {this->NMake = v;}
+
+ /**
+ * Set to true if the shell being used is the MSYS shell.
+ * This controls if statements in the makefile and the SHELL variable.
+ * The default is false.
+ */
+ void SetMSYSShell(bool v) {this->MSYSShell = v;}
+
+ /**
+ * If set to true, then NULL is set to nil for non Windows_NT.
+ * This uses make syntax used by nmake and borland.
+ * The default is false.
+ */
+ void SetDefineWindowsNULL(bool v) {this->DefineWindowsNULL = v;}
+
+ /**
+ * If set to true, cd dir && command is used to
+ * run commands in a different directory.
+ */
+ void SetUnixCD(bool v) {this->UnixCD = v;}
+
+ /**
+ * Set the string used to include one makefile into another default
+ * is include.
+ */
+ void SetIncludeDirective(const std::string& s)
+ { this->IncludeDirective = s; }
+ const std::string& GetIncludeDirective() { return this->IncludeDirective; }
+
+ /**
+ * Set max makefile variable size, default is 0 which means unlimited.
+ */
+ void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
+
+ /**
+ * If ignore lib prefix is true, then do not strip lib from the name
+ * of a library.
+ */
+ void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
+
+ /**
+ * Set whether passing a make target on a command line requires an
+ * extra level of escapes.
+ */
+ void SetMakeCommandEscapeTargetTwice(bool b)
+ { this->MakeCommandEscapeTargetTwice = b; }
+
+ /**
+ * Set whether the Borland curly brace command line hack should be
+ * applied.
+ */
+ void SetBorlandMakeCurlyHack(bool b)
+ { this->BorlandMakeCurlyHack = b; }
+
+ // used in writing out Cmake files such as WriteDirectoryInformation
+ static void WriteCMakeArgument(std::ostream& os, const char* s);
+
+ /** creates the common disclaimer text at the top of each makefile */
+ void WriteDisclaimer(std::ostream& os);
+
+ // write a comment line #====... in the stream
+ void WriteDivider(std::ostream& os);
+
+ /** used to create a recursive make call */
+ std::string GetRecursiveMakeCall(const char *makefile,
+ const std::string& tgt);
+
+ // append flags to a string
+ virtual void AppendFlags(std::string& flags, const std::string& newFlags);
+ virtual void AppendFlags(std::string& flags, const char* newFlags);
+
+ // append an echo command
+ enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
+ EchoGenerate, EchoGlobal };
+ void AppendEcho(std::vector<std::string>& commands, const char* text,
+ EchoColor color = EchoNormal);
+
+ /** Get whether the makefile is to have color. */
+ bool GetColorMakefile() const { return this->ColorMakefile; }
+
+ virtual std::string GetTargetDirectory(cmTarget const& target) const;
+
+ // create a command that cds to the start dir then runs the commands
+ void CreateCDCommand(std::vector<std::string>& commands,
+ const char *targetDir,
+ cmLocalGenerator::RelativeRoot returnDir);
+
+ static std::string ConvertToQuotedOutputPath(const char* p,
+ bool useWatcomQuote);
+
+ std::string CreateMakeVariable(const std::string& sin,
+ const std::string& s2in);
+
+ /** Called from command-line hook to bring dependencies up to date
+ for a target. */
+ virtual bool UpdateDependencies(const char* tgtInfo,
+ bool verbose, bool color);
+
+ /** Called from command-line hook to clear dependencies. */
+ virtual void ClearDependencies(cmMakefile* mf, bool verbose);
+
+ /** write some extra rules such as make test etc */
+ void WriteSpecialTargetsTop(std::ostream& makefileStream);
+ void WriteSpecialTargetsBottom(std::ostream& makefileStream);
+
+ std::string GetRelativeTargetDirectory(cmTarget const& target);
+
+ // File pairs for implicit dependency scanning. The key of the map
+ // is the depender and the value is the explicit dependee.
+ struct ImplicitDependFileMap:
+ public std::map<std::string, cmDepends::DependencyVector> {};
+ struct ImplicitDependLanguageMap:
+ public std::map<std::string, ImplicitDependFileMap> {};
+ struct ImplicitDependTargetMap:
+ public std::map<std::string, ImplicitDependLanguageMap> {};
+ ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
+
+ void AddImplicitDepends(cmTarget const& tgt, const std::string& lang,
+ const char* obj, const char* src);
+
+ void AppendGlobalTargetDepends(std::vector<std::string>& depends,
+ cmTarget& target);
+
+ // write the target rules for the local Makefile into the stream
+ void WriteLocalAllRules(std::ostream& ruleFileStream);
+
+ std::vector<std::string> const& GetLocalHelp() { return this->LocalHelp; }
+
+ /** Get whether to create rules to generate preprocessed and
+ assembly sources. This could be converted to a variable lookup
+ later. */
+ bool GetCreatePreprocessedSourceRules()
+ {
+ return !this->SkipPreprocessedSourceRules;
+ }
+ bool GetCreateAssemblySourceRules()
+ {
+ return !this->SkipAssemblySourceRules;
+ }
+
+ // Fill the vector with the target names for the object files,
+ // preprocessed files and assembly files. Currently only used by the
+ // Eclipse generator.
+ void GetIndividualFileTargets(std::vector<std::string>& targets);
+
+protected:
+ void WriteLocalMakefile();
+
+
+ // write the target rules for the local Makefile into the stream
+ void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
+ std::set<std::string> &emitted);
+
+ // this method Writes the Directory information files
+ void WriteDirectoryInformationFile();
+
+
+ // write the depend info
+ void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
+
+ // write the local help rule
+ void WriteHelpRule(std::ostream& ruleFileStream);
+
+ // this converts a file name that is relative to the StartOuputDirectory
+ // into a full path
+ std::string ConvertToFullPath(const std::string& localPath);
+
+
+ void WriteConvenienceRule(std::ostream& ruleFileStream,
+ const std::string& realTarget,
+ const std::string& helpTarget);
+
+ void WriteTargetDependRule(std::ostream& ruleFileStream,
+ cmTarget& target);
+ void WriteTargetCleanRule(std::ostream& ruleFileStream,
+ cmTarget& target,
+ const std::vector<std::string>& files);
+ void WriteTargetRequiresRule(std::ostream& ruleFileStream,
+ cmTarget& target,
+ const std::vector<std::string>& objects);
+
+ void AppendRuleDepend(std::vector<std::string>& depends,
+ const char* ruleFileName);
+ void AppendRuleDepends(std::vector<std::string>& depends,
+ std::vector<std::string> const& ruleFiles);
+ void AppendCustomDepends(std::vector<std::string>& depends,
+ const std::vector<cmCustomCommand>& ccs);
+ void AppendCustomDepend(std::vector<std::string>& depends,
+ cmCustomCommandGenerator const& cc);
+ void AppendCustomCommands(std::vector<std::string>& commands,
+ const std::vector<cmCustomCommand>& ccs,
+ cmTarget* target,
+ cmLocalGenerator::RelativeRoot relative =
+ cmLocalGenerator::HOME_OUTPUT);
+ void AppendCustomCommand(std::vector<std::string>& commands,
+ cmCustomCommandGenerator const& ccg,
+ cmTarget* 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);
+
+ // Helper methods for dependeny updates.
+ bool ScanDependencies(const char* targetDir,
+ std::map<std::string, cmDepends::DependencyVector>& validDeps);
+ void CheckMultipleOutputs(bool verbose);
+
+private:
+ std::string ConvertShellCommand(std::string const& cmd, RelativeRoot root);
+ std::string MakeLauncher(cmCustomCommandGenerator const& ccg,
+ cmTarget* target, RelativeRoot relative);
+
+ virtual void ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt = 0);
+
+ friend class cmMakefileTargetGenerator;
+ friend class cmMakefileExecutableTargetGenerator;
+ friend class cmMakefileLibraryTargetGenerator;
+ friend class cmMakefileUtilityTargetGenerator;
+ friend class cmGlobalUnixMakefileGenerator3;
+
+ ImplicitDependTargetMap ImplicitDepends;
+
+ //==========================================================================
+ // Configuration settings.
+ int MakefileVariableSize;
+ std::string IncludeDirective;
+ std::string MakeSilentFlag;
+ std::string ConfigurationName;
+ bool DefineWindowsNULL;
+ bool UnixCD;
+ bool PassMakeflags;
+ bool MakeCommandEscapeTargetTwice;
+ bool BorlandMakeCurlyHack;
+ //==========================================================================
+
+ std::string HomeRelativeOutputPath;
+
+ /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
+ beginning of generation to avoid many duplicate lookups. */
+ bool ColorMakefile;
+
+ /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
+ CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
+ avoid many duplicate lookups. */
+ bool SkipPreprocessedSourceRules;
+ bool SkipAssemblySourceRules;
+
+ struct LocalObjectEntry
+ {
+ cmTarget* Target;
+ std::string Language;
+ LocalObjectEntry(): Target(0), Language() {}
+ LocalObjectEntry(cmTarget* t, const std::string& lang):
+ Target(t), Language(lang) {}
+ };
+ struct LocalObjectInfo: public std::vector<LocalObjectEntry>
+ {
+ bool HasSourceExtension;
+ bool HasPreprocessRule;
+ bool HasAssembleRule;
+ LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
+ HasAssembleRule(false) {}
+ };
+ void GetLocalObjectFiles(
+ std::map<std::string, LocalObjectInfo> &localObjectFiles);
+
+ void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
+ const char* comment, const char* output,
+ LocalObjectInfo const& info);
+
+ std::vector<std::string> LocalHelp;
+
+ /* does the work for each target */
+ std::map<std::string, std::string> MakeVariableMap;
+ std::map<std::string, std::string> ShortMakeVariableMap;
+};
+
+#endif
diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx
new file mode 100644
index 0000000000..aa70ab9d6d
--- /dev/null
+++ b/Source/cmLocalVisualStudio10Generator.cxx
@@ -0,0 +1,128 @@
+/*============================================================================
+ 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 "cmLocalVisualStudio10Generator.h"
+#include "cmTarget.h"
+#include "cmMakefile.h"
+#include "cmVisualStudio10TargetGenerator.h"
+#include "cmGlobalVisualStudio10Generator.h"
+#include <cm_expat.h>
+#include "cmXMLParser.h"
+class cmVS10XMLParser : public cmXMLParser
+{
+ public:
+ virtual void EndElement(const std::string& /* name */)
+ {
+ }
+ virtual void CharacterDataHandler(const char* data, int length)
+ {
+ if(this->DoGUID )
+ {
+ this->GUID.assign(data+1, length-2);
+ this->DoGUID = false;
+ }
+ }
+ virtual void StartElement(const std::string& name, const char**)
+ {
+ // once the GUID is found do nothing
+ if(this->GUID.size())
+ {
+ return;
+ }
+ if("ProjectGUID" == name || "ProjectGuid" == name)
+ {
+ this->DoGUID = true;
+ }
+ }
+ int InitializeParser()
+ {
+ this->DoGUID = false;
+ int ret = cmXMLParser::InitializeParser();
+ if(ret == 0)
+ {
+ return ret;
+ }
+ // visual studio projects have a strange encoding, but it is
+ // really utf-8
+ XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
+ return 1;
+ }
+ std::string GUID;
+ bool DoGUID;
+};
+
+
+//----------------------------------------------------------------------------
+cmLocalVisualStudio10Generator::cmLocalVisualStudio10Generator(VSVersion v):
+ cmLocalVisualStudio7Generator(v)
+{
+}
+
+cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
+{
+}
+
+void cmLocalVisualStudio10Generator::Generate()
+{
+
+ cmTargets &tgts = this->Makefile->GetTargets();
+ for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
+ {
+ if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
+ ->TargetIsFortranOnly(l->second))
+ {
+ this->CreateSingleVCProj(l->first.c_str(),l->second);
+ }
+ else
+ {
+ cmVisualStudio10TargetGenerator tg(
+ &l->second, static_cast<cmGlobalVisualStudio10Generator*>(
+ this->GetGlobalGenerator()));
+ tg.Generate();
+ }
+ }
+ this->WriteStampFiles();
+}
+
+
+void cmLocalVisualStudio10Generator
+::ReadAndStoreExternalGUID(const std::string& name,
+ const char* path)
+{
+ cmVS10XMLParser parser;
+ parser.ParseFile(path);
+
+ // if we can not find a GUID then create one
+ if(parser.GUID.empty())
+ {
+ this->GlobalGenerator->CreateGUID(name);
+ return;
+ }
+
+ std::string guidStoreName = name;
+ guidStoreName += "_GUID_CMAKE";
+ // save the GUID in the cache
+ this->GlobalGenerator->GetCMakeInstance()->
+ AddCacheEntry(guidStoreName.c_str(),
+ parser.GUID.c_str(),
+ "Stored GUID",
+ cmCacheManager::INTERNAL);
+}
+
+//----------------------------------------------------------------------------
+const char* cmLocalVisualStudio10Generator::ReportErrorLabel() const
+{
+ return ":VCEnd";
+}
diff --git a/Source/cmLocalVisualStudio10Generator.h b/Source/cmLocalVisualStudio10Generator.h
new file mode 100644
index 0000000000..b50e3458ba
--- /dev/null
+++ b/Source/cmLocalVisualStudio10Generator.h
@@ -0,0 +1,46 @@
+/*============================================================================
+ 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 cmLocalVisualStudio10Generator_h
+#define cmLocalVisualStudio10Generator_h
+
+#include "cmLocalVisualStudio7Generator.h"
+
+
+/** \class cmLocalVisualStudio10Generator
+ * \brief Write Visual Studio 10 project files.
+ *
+ * cmLocalVisualStudio10Generator produces a Visual Studio 10 project
+ * file for each target in its directory.
+ */
+class cmLocalVisualStudio10Generator : public cmLocalVisualStudio7Generator
+{
+public:
+ ///! Set cache only and recurse to false by default.
+ cmLocalVisualStudio10Generator(VSVersion v);
+
+ virtual ~cmLocalVisualStudio10Generator();
+
+
+ /**
+ * Generate the makefile for this directory.
+ */
+ virtual void Generate();
+ virtual void ReadAndStoreExternalGUID(const std::string& name,
+ const char* path);
+
+protected:
+ virtual const char* ReportErrorLabel() const;
+ virtual bool CustomCommandUseLocal() const { return true; }
+
+private:
+};
+#endif
diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx
new file mode 100644
index 0000000000..c14fb2b67b
--- /dev/null
+++ b/Source/cmLocalVisualStudio6Generator.cxx
@@ -0,0 +1,2010 @@
+/*============================================================================
+ 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 "cmGlobalGenerator.h"
+#include "cmLocalVisualStudio6Generator.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include "cmSourceFile.h"
+#include "cmCacheManager.h"
+#include "cmGeneratorTarget.h"
+#include "cmCustomCommandGenerator.h"
+#include "cmake.h"
+
+#include "cmComputeLinkInformation.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/FStream.hxx>
+
+cmLocalVisualStudio6Generator::cmLocalVisualStudio6Generator():
+ cmLocalVisualStudioGenerator(VS6)
+{
+}
+
+cmLocalVisualStudio6Generator::~cmLocalVisualStudio6Generator()
+{
+}
+
+//----------------------------------------------------------------------------
+// Helper class to write build events.
+class cmLocalVisualStudio6Generator::EventWriter
+{
+public:
+ EventWriter(cmLocalVisualStudio6Generator* lg,
+ const std::string& config, std::string& code):
+ LG(lg), Config(config), Code(code), First(true) {}
+ void Start(const char* event)
+ {
+ this->First = true;
+ this->Event = event;
+ }
+ void Finish()
+ {
+ this->Code += (this->First? "" : "\n");
+ }
+ void Write(std::vector<cmCustomCommand> const& ccs)
+ {
+ for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
+ ci != ccs.end(); ++ci)
+ {
+ this->Write(*ci);
+ }
+ }
+ void Write(cmCustomCommand const& cc)
+ {
+ cmCustomCommandGenerator ccg(cc, this->Config, this->LG->GetMakefile());
+ if(this->First)
+ {
+ this->Code += this->Event + "_Cmds=";
+ this->First = false;
+ }
+ else
+ {
+ this->Code += "\\\n\t";
+ }
+ this->Code += this->LG->ConstructScript(ccg, "\\\n\t");
+ }
+private:
+ cmLocalVisualStudio6Generator* LG;
+ std::string Config;
+ std::string& Code;
+ bool First;
+ std::string Event;
+};
+
+void cmLocalVisualStudio6Generator::AddHelperCommands()
+{
+ std::set<std::string> lang;
+ lang.insert("C");
+ lang.insert("CXX");
+ this->CreateCustomTargetsAndCommands(lang);
+}
+
+void cmLocalVisualStudio6Generator::AddCMakeListsRules()
+{
+ cmTargets &tgts = this->Makefile->GetTargets();
+ for(cmTargets::iterator l = tgts.begin();
+ l != tgts.end(); l++)
+ {
+ if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+
+ // Add a rule to regenerate the build system when the target
+ // specification source changes.
+ const char* suppRegenRule =
+ this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
+ if (!cmSystemTools::IsOn(suppRegenRule))
+ {
+ this->AddDSPBuildRule(l->second);
+ }
+ }
+}
+
+void cmLocalVisualStudio6Generator::Generate()
+{
+ this->OutputDSPFile();
+}
+
+void cmLocalVisualStudio6Generator::OutputDSPFile()
+{
+ // If not an in source build, then create the output directory
+ if(strcmp(this->Makefile->GetStartOutputDirectory(),
+ this->Makefile->GetHomeDirectory()) != 0)
+ {
+ if(!cmSystemTools::MakeDirectory
+ (this->Makefile->GetStartOutputDirectory()))
+ {
+ cmSystemTools::Error("Error creating directory ",
+ this->Makefile->GetStartOutputDirectory());
+ }
+ }
+
+ // 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++)
+ {
+ switch(l->second.GetType())
+ {
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::OBJECT_LIBRARY:
+ this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second);
+ break;
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ this->SetBuildType(DLL, l->first.c_str(), l->second);
+ break;
+ case cmTarget::EXECUTABLE:
+ this->SetBuildType(EXECUTABLE,l->first.c_str(), l->second);
+ break;
+ case cmTarget::UTILITY:
+ case cmTarget::GLOBAL_TARGET:
+ this->SetBuildType(UTILITY, l->first.c_str(), l->second);
+ break;
+ case cmTarget::INTERFACE_LIBRARY:
+ continue;
+ default:
+ cmSystemTools::Error("Bad target type: ", l->first.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");
+ if(!path)
+ {
+ // check to see if the dsp is going into a sub-directory
+ std::string::size_type pos = l->first.rfind('/');
+ if(pos != std::string::npos)
+ {
+ std::string dir = this->Makefile->GetStartOutputDirectory();
+ dir += "/";
+ dir += l->first.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);
+ }
+ }
+}
+
+// Utility function to make a valid VS6 *.dsp filename out
+// of a CMake target name:
+//
+extern std::string GetVS6TargetName(const std::string& targetName);
+
+void cmLocalVisualStudio6Generator::CreateSingleDSP(const std::string& lname,
+ cmTarget &target)
+{
+ // add to the list of projects
+ std::string pname = GetVS6TargetName(lname);
+
+ // create the dsp.cmake file
+ std::string fname;
+ fname = this->Makefile->GetStartOutputDirectory();
+ fname += "/";
+ fname += pname;
+ fname += ".dsp";
+ // save the name of the real dsp file
+ std::string realDSP = fname;
+ fname += ".cmake";
+ cmsys::ofstream fout(fname.c_str());
+ if(!fout)
+ {
+ cmSystemTools::Error("Error Writing ", fname.c_str());
+ cmSystemTools::ReportLastSystemError("");
+ }
+ this->WriteDSPFile(fout,pname.c_str(),target);
+ fout.close();
+ // if the dsp file has changed, then write it.
+ cmSystemTools::CopyFileIfDifferent(fname.c_str(), realDSP.c_str());
+}
+
+
+void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt)
+{
+ std::string dspname = GetVS6TargetName(tgt.GetName());
+ dspname += ".dsp.cmake";
+ const char* dsprule =
+ this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
+ cmCustomCommandLine commandLine;
+ commandLine.push_back(dsprule);
+ std::string makefileIn = this->Makefile->GetStartDirectory();
+ makefileIn += "/";
+ makefileIn += "CMakeLists.txt";
+ if(!cmSystemTools::FileExists(makefileIn.c_str()))
+ {
+ return;
+ }
+ std::string comment = "Building Custom Rule ";
+ comment += makefileIn;
+ std::string args;
+ args = "-H";
+ args += this->Convert(this->Makefile->GetHomeDirectory(),
+ START_OUTPUT, UNCHANGED, true);
+ commandLine.push_back(args);
+ args = "-B";
+ args +=
+ this->Convert(this->Makefile->GetHomeOutputDirectory(),
+ START_OUTPUT, UNCHANGED, true);
+ commandLine.push_back(args);
+
+ std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
+
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+ const char* no_working_directory = 0;
+ this->Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles,
+ makefileIn.c_str(), commandLines,
+ comment.c_str(),
+ no_working_directory, true);
+ if(this->Makefile->GetSource(makefileIn.c_str()))
+ {
+ tgt.AddSource(makefileIn);
+ }
+ else
+ {
+ cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
+ }
+}
+
+
+void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
+ const std::string& libName,
+ cmTarget &target)
+{
+ // For utility targets need custom command since pre- and post-
+ // build does not do anything in Visual Studio 6. In order for the
+ // rules to run in the correct order as custom commands, we need
+ // 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()))
+ {
+ // 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)
+ {
+ 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)
+ {
+ depends.insert(depends.end(),
+ cr->GetDepends().begin(), cr->GetDepends().end());
+ }
+
+ // 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)
+ {
+ this->AddUtilityCommandHack(target, count++, depends, *cr);
+ }
+ for (std::vector<cmCustomCommand>::const_iterator cr =
+ target.GetPostBuildCommands().begin();
+ cr != target.GetPostBuildCommands().end(); ++cr)
+ {
+ this->AddUtilityCommandHack(target, count++, depends, *cr);
+ }
+ }
+
+ // We may be modifying the source groups temporarily, so make a copy.
+ std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
+
+ // get the classes from the source lists then add them to the groups
+ std::vector<cmSourceFile*> classes;
+ if (!target.GetConfigCommonSourceFiles(classes))
+ {
+ return;
+ }
+
+ // now all of the source files have been properly assigned to the target
+ // now stick them into source groups using the reg expressions
+ for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
+ i != classes.end(); i++)
+ {
+ if (!(*i)->GetObjectLibrary().empty())
+ {
+ continue;
+ }
+
+ // Add the file to the list of sources.
+ std::string source = (*i)->GetFullPath();
+ cmSourceGroup* sourceGroup =
+ this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
+ sourceGroup->AssignSource(*i);
+ // while we are at it, if it is a .rule file then for visual studio 6 we
+ // must generate it
+ if ((*i)->GetPropertyAsBool("__CMAKE_RULE"))
+ {
+ if(!cmSystemTools::FileExists(source.c_str()))
+ {
+ cmSystemTools::ReplaceString(source, "$(IntDir)/", "");
+ // Make sure the path exists for the file
+ std::string path = cmSystemTools::GetFilenamePath(source);
+ cmSystemTools::MakeDirectory(path.c_str());
+#if defined(_WIN32) || defined(__CYGWIN__)
+ cmsys::ofstream sourceFout(source.c_str(),
+ std::ios::binary | std::ios::out
+ | std::ios::trunc);
+#else
+ cmsys::ofstream sourceFout(source.c_str(),
+ std::ios::out | std::ios::trunc);
+#endif
+ if(sourceFout)
+ {
+ sourceFout.write("# generated from CMake",22);
+ sourceFout.flush();
+ sourceFout.close();
+ }
+ }
+ }
+ }
+
+ // Write the DSP file's header.
+ this->WriteDSPHeader(fout, libName, target, sourceGroups);
+
+
+ // Loop through every source group.
+ for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
+ sg != sourceGroups.end(); ++sg)
+ {
+ this->WriteGroup(&(*sg), target, fout, libName);
+ }
+
+ // Write the DSP file's footer.
+ this->WriteDSPFooter(fout);
+}
+
+void cmLocalVisualStudio6Generator
+::WriteGroup(const cmSourceGroup *sg, cmTarget& 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.
+
+ if(sourceFiles.empty() && sg->GetGroupChildren().empty())
+ {
+ return;
+ }
+
+ // If the group has a name, write the header.
+ std::string name = sg->GetName();
+ if(name != "")
+ {
+ this->WriteDSPBeginGroup(fout, name.c_str(), "");
+ }
+
+ // Loop through each source in the source group.
+ for(std::vector<const cmSourceFile *>::const_iterator sf =
+ sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
+ {
+ if (!(*sf)->GetObjectLibrary().empty())
+ {
+ continue;
+ }
+
+ std::string source = (*sf)->GetFullPath();
+ const cmCustomCommand *command =
+ (*sf)->GetCustomCommand();
+ std::string compileFlags;
+ std::vector<std::string> depends;
+ std::string objectNameDir;
+ if(gt->HasExplicitObjectName(*sf))
+ {
+ objectNameDir = cmSystemTools::GetFilenamePath(gt->GetObjectName(*sf));
+ }
+
+ // Add per-source file flags.
+ if(const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS"))
+ {
+ compileFlags += cflags;
+ }
+
+ const std::string& lang = this->GetSourceFileLanguage(*(*sf));
+ if(lang == "CXX")
+ {
+ // force a C++ file type
+ compileFlags += " /TP ";
+ }
+ else if(lang == "C")
+ {
+ // force to c file type
+ compileFlags += " /TC ";
+ }
+
+ // Add per-source and per-configuration preprocessor definitions.
+ std::map<std::string, std::string> cdmap;
+
+ {
+ std::set<std::string> targetCompileDefinitions;
+
+ this->AppendDefines(targetCompileDefinitions,
+ (*sf)->GetProperty("COMPILE_DEFINITIONS"));
+ this->JoinDefines(targetCompileDefinitions, compileFlags, lang);
+ }
+
+ if(const char* cdefs = (*sf)->GetProperty("COMPILE_DEFINITIONS_DEBUG"))
+ {
+ std::set<std::string> debugCompileDefinitions;
+ this->AppendDefines(debugCompileDefinitions, cdefs);
+ this->JoinDefines(debugCompileDefinitions, cdmap["DEBUG"], lang);
+ }
+ if(const char* cdefs = (*sf)->GetProperty("COMPILE_DEFINITIONS_RELEASE"))
+ {
+ std::set<std::string> releaseCompileDefinitions;
+ this->AppendDefines(releaseCompileDefinitions, cdefs);
+ this->JoinDefines(releaseCompileDefinitions, cdmap["RELEASE"], lang);
+ }
+ if(const char* cdefs =
+ (*sf)->GetProperty("COMPILE_DEFINITIONS_MINSIZEREL"))
+ {
+ std::set<std::string> minsizerelCompileDefinitions;
+ this->AppendDefines(minsizerelCompileDefinitions, cdefs);
+ this->JoinDefines(minsizerelCompileDefinitions, cdmap["MINSIZEREL"],
+ lang);
+ }
+ if(const char* cdefs =
+ (*sf)->GetProperty("COMPILE_DEFINITIONS_RELWITHDEBINFO"))
+ {
+ std::set<std::string> relwithdebinfoCompileDefinitions;
+ this->AppendDefines(relwithdebinfoCompileDefinitions, cdefs);
+ this->JoinDefines(relwithdebinfoCompileDefinitions,
+ cdmap["RELWITHDEBINFO"], lang);
+ }
+
+ bool excludedFromBuild =
+ (!lang.empty() && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
+
+ // Check for extra object-file dependencies.
+ const char* dependsValue = (*sf)->GetProperty("OBJECT_DEPENDS");
+ if(dependsValue)
+ {
+ cmSystemTools::ExpandListArgument(dependsValue, depends);
+ }
+ if (GetVS6TargetName(source) != libName ||
+ target.GetType() == cmTarget::UTILITY ||
+ target.GetType() == cmTarget::GLOBAL_TARGET)
+ {
+ fout << "# Begin Source File\n\n";
+
+ // Tell MS-Dev what the source is. If the compiler knows how to
+ // build it, then it will.
+ fout << "SOURCE=" <<
+ this->ConvertToOptionallyRelativeOutputPath(source.c_str()) << "\n\n";
+ if(!depends.empty())
+ {
+ // Write out the dependencies for the rule.
+ fout << "USERDEP__HACK=";
+ for(std::vector<std::string>::const_iterator d = depends.begin();
+ d != depends.end(); ++d)
+ {
+ fout << "\\\n\t" <<
+ this->ConvertToOptionallyRelativeOutputPath(d->c_str());
+ }
+ fout << "\n";
+ }
+ if (command)
+ {
+ const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
+ this->WriteCustomRule(fout, source.c_str(), *command, flags);
+ }
+ else if(!compileFlags.empty() || !objectNameDir.empty() ||
+ excludedFromBuild || !cdmap.empty())
+ {
+ for(std::vector<std::string>::iterator i
+ = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ // Strip the subdirectory name out of the configuration name.
+ std::string config = this->GetConfigName(*i);
+ if (i == this->Configurations.begin())
+ {
+ fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
+ }
+ else
+ {
+ fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
+ }
+ if(excludedFromBuild)
+ {
+ fout << "# PROP Exclude_From_Build 1\n";
+ }
+ if(!compileFlags.empty())
+ {
+ fout << "\n# ADD CPP " << compileFlags << "\n\n";
+ }
+ std::map<std::string, std::string>::iterator cdi =
+ cdmap.find(cmSystemTools::UpperCase(config));
+ if(cdi != cdmap.end() && !cdi->second.empty())
+ {
+ fout << "\n# ADD CPP " << cdi->second << "\n\n";
+ }
+ if(!objectNameDir.empty())
+ {
+ // Setup an alternate object file directory.
+ fout << "\n# PROP Intermediate_Dir \""
+ << config << "/" << objectNameDir << "\"\n\n";
+ }
+ }
+ fout << "!ENDIF\n\n";
+ }
+ fout << "# End Source File\n";
+ }
+ }
+
+ std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
+
+ for(unsigned int i=0;i<children.size();++i)
+ {
+ this->WriteGroup(&children[i], target, fout, libName);
+ }
+
+
+
+
+ // If the group has a name, write the footer.
+ if(name != "")
+ {
+ this->WriteDSPEndGroup(fout);
+ }
+
+}
+
+
+void
+cmLocalVisualStudio6Generator
+::AddUtilityCommandHack(cmTarget& 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->GetStartOutputDirectory()) +
+ target.GetName().size() + 30)];
+ sprintf(output,"%s/%s_force_%i", this->Makefile->GetStartOutputDirectory(),
+ target.GetName().c_str(), count);
+ const char* comment = origCommand.GetComment();
+ if(!comment && origCommand.GetOutputs().empty())
+ {
+ comment = "<hack>";
+ }
+
+ // Add the rule with the given dependencies and commands.
+ std::string no_main_dependency = "";
+ if(cmSourceFile* outsf =
+ this->Makefile->AddCustomCommandToOutput(
+ output, depends, no_main_dependency,
+ origCommand.GetCommandLines(), comment,
+ origCommand.GetWorkingDirectory().c_str()))
+ {
+ target.AddSource(outsf->GetFullPath());
+ }
+
+ // Replace the dependencies with the output of this rule so that the
+ // next rule added will run after this one.
+ depends.clear();
+ depends.push_back(output);
+
+ // Free the fake output name.
+ delete [] output;
+}
+
+void
+cmLocalVisualStudio6Generator
+::WriteCustomRule(std::ostream& fout,
+ const char* source,
+ const cmCustomCommand& command,
+ const char* flags)
+{
+ // Write the rule for each configuration.
+ std::vector<std::string>::iterator i;
+ for(i = this->Configurations.begin(); i != this->Configurations.end(); ++i)
+ {
+ std::string config = this->GetConfigName(*i);
+ cmCustomCommandGenerator ccg(command, config, this->Makefile);
+ std::string comment =
+ this->ConstructComment(ccg, "Building Custom Rule $(InputPath)");
+ if(comment == "<hack>")
+ {
+ comment = "";
+ }
+
+ std::string script =
+ this->ConstructScript(ccg, "\\\n\t");
+
+ if (i == this->Configurations.begin())
+ {
+ fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
+ }
+ else
+ {
+ fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
+ }
+ if(flags)
+ {
+ fout << "\n# ADD CPP " << flags << "\n\n";
+ }
+ // Write out the dependencies for the rule.
+ fout << "USERDEP__HACK=";
+ for(std::vector<std::string>::const_iterator d =
+ ccg.GetDepends().begin();
+ d != ccg.GetDepends().end();
+ ++d)
+ {
+ // Lookup the real name of the dependency in case it is a CMake target.
+ std::string dep;
+ if(this->GetRealDependency(d->c_str(), config.c_str(), dep))
+ {
+ fout << "\\\n\t" <<
+ this->ConvertToOptionallyRelativeOutputPath(dep.c_str());
+ }
+ }
+ fout << "\n";
+
+ fout << "# PROP Ignore_Default_Tool 1\n";
+ fout << "# Begin Custom Build -";
+ if(!comment.empty())
+ {
+ fout << " " << comment.c_str();
+ }
+ fout << "\n\n";
+ if(ccg.GetOutputs().empty())
+ {
+ fout << source
+ << "_force : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
+ fout << script.c_str() << "\n\n";
+ }
+ else
+ {
+ for(std::vector<std::string>::const_iterator o =
+ ccg.GetOutputs().begin();
+ o != ccg.GetOutputs().end();
+ ++o)
+ {
+ // Write a rule for every output generated by this command.
+ fout << this->ConvertToOptionallyRelativeOutputPath(o->c_str())
+ << " : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
+ fout << script.c_str() << "\n\n";
+ }
+ }
+ fout << "# End Custom Build\n\n";
+ }
+
+ fout << "!ENDIF\n\n";
+}
+
+
+void cmLocalVisualStudio6Generator::WriteDSPBeginGroup(std::ostream& fout,
+ const char* group,
+ const char* filter)
+{
+ fout << "# Begin Group \"" << group << "\"\n"
+ "# PROP Default_Filter \"" << filter << "\"\n";
+}
+
+
+void cmLocalVisualStudio6Generator::WriteDSPEndGroup(std::ostream& fout)
+{
+ fout << "# End Group\n";
+}
+
+
+
+
+void cmLocalVisualStudio6Generator::SetBuildType(BuildType b,
+ const std::string& libName,
+ cmTarget& target)
+{
+ std::string root= this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
+ const char *def=
+ this->Makefile->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY");
+
+ if( def)
+ {
+ root = def;
+ }
+ else
+ {
+ root += "/Templates";
+ }
+
+ switch(b)
+ {
+ case WIN32_EXECUTABLE:
+ break;
+ case STATIC_LIBRARY:
+ this->DSPHeaderTemplate = root;
+ this->DSPHeaderTemplate += "/staticLibHeader.dsptemplate";
+ this->DSPFooterTemplate = root;
+ this->DSPFooterTemplate += "/staticLibFooter.dsptemplate";
+ break;
+ case DLL:
+ this->DSPHeaderTemplate = root;
+ this->DSPHeaderTemplate += "/DLLHeader.dsptemplate";
+ this->DSPFooterTemplate = root;
+ this->DSPFooterTemplate += "/DLLFooter.dsptemplate";
+ break;
+ case EXECUTABLE:
+ if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
+ {
+ this->DSPHeaderTemplate = root;
+ this->DSPHeaderTemplate += "/EXEWinHeader.dsptemplate";
+ this->DSPFooterTemplate = root;
+ this->DSPFooterTemplate += "/EXEFooter.dsptemplate";
+ }
+ else
+ {
+ this->DSPHeaderTemplate = root;
+ this->DSPHeaderTemplate += "/EXEHeader.dsptemplate";
+ this->DSPFooterTemplate = root;
+ this->DSPFooterTemplate += "/EXEFooter.dsptemplate";
+ }
+ break;
+ case UTILITY:
+ this->DSPHeaderTemplate = root;
+ this->DSPHeaderTemplate += "/UtilityHeader.dsptemplate";
+ this->DSPFooterTemplate = root;
+ this->DSPFooterTemplate += "/UtilityFooter.dsptemplate";
+ break;
+ }
+
+ // once the build type is set, determine what configurations are
+ // possible
+ cmsys::ifstream fin(this->DSPHeaderTemplate.c_str());
+
+ cmsys::RegularExpression reg("# Name ");
+ if(!fin)
+ {
+ cmSystemTools::Error("Error Reading ", this->DSPHeaderTemplate.c_str());
+ }
+
+ // reset this->Configurations
+ this->Configurations.erase(this->Configurations.begin(),
+ this->Configurations.end());
+
+ // now add all the configurations possible
+ std::string vs6name = GetVS6TargetName(libName);
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME", vs6name.c_str());
+ if (reg.find(line))
+ {
+ this->Configurations.push_back(line.substr(reg.end()));
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+cmsys::auto_ptr<cmCustomCommand>
+cmLocalVisualStudio6Generator::MaybeCreateOutputDir(cmTarget& 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);
+
+ // Add a pre-link event to create the directory.
+ cmCustomCommandLine command;
+ command.push_back(this->Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
+ command.push_back("-E");
+ command.push_back("make_directory");
+ command.push_back(outDir);
+ std::vector<std::string> no_output;
+ std::vector<std::string> no_depends;
+ cmCustomCommandLines commands;
+ commands.push_back(command);
+ pcc.reset(new cmCustomCommand(0, no_output, no_depends, commands, 0, 0));
+ pcc->SetEscapeOldStyle(false);
+ pcc->SetEscapeAllowMakeVars(true);
+ return pcc;
+}
+
+// look for custom rules on a target and collect them together
+std::string
+cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target,
+ const std::string& configName,
+ const std::string& /* libName */)
+{
+ if (target.GetType() >= cmTarget::UTILITY )
+ {
+ return "";
+ }
+
+ std::string customRuleCode = "# Begin Special Build Tool\n";
+ EventWriter event(this, configName, customRuleCode);
+
+ // Write the pre-build and pre-link together (VS6 does not support both).
+ event.Start("PreLink");
+ event.Write(target.GetPreBuildCommands());
+ event.Write(target.GetPreLinkCommands());
+ cmsys::auto_ptr<cmCustomCommand> pcc(
+ this->MaybeCreateImplibDir(target, configName, false));
+ if(pcc.get())
+ {
+ event.Write(*pcc);
+ }
+ pcc = this->MaybeCreateOutputDir(target, configName);
+ if(pcc.get())
+ {
+ event.Write(*pcc);
+ }
+ event.Finish();
+
+ // Write the post-build rules.
+ event.Start("PostBuild");
+ event.Write(target.GetPostBuildCommands());
+ event.Finish();
+
+ customRuleCode += "# End Special Build Tool\n";
+ return customRuleCode;
+}
+
+
+inline std::string removeQuotes(const std::string& s)
+{
+ if(s[0] == '\"' && s[s.size()-1] == '\"')
+ {
+ return s.substr(1, s.size()-2);
+ }
+ return s;
+}
+
+
+std::string
+cmLocalVisualStudio6Generator::GetTargetIncludeOptions(cmTarget &target,
+ const std::string& config)
+{
+ std::string includeOptions;
+
+ // Setup /I and /LIBPATH options for the resulting DSP file. VS 6
+ // truncates long include paths so make it as short as possible if
+ // the length threatens this problem.
+ 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);
+
+ std::vector<std::string>::iterator i;
+ for(i = includes.begin(); i != includes.end(); ++i)
+ {
+ std::string tmp =
+ this->ConvertToOptionallyRelativeOutputPath(i->c_str());
+ if(useShortPath)
+ {
+ cmSystemTools::GetShortPath(tmp.c_str(), tmp);
+ }
+ includeOptions += " /I ";
+
+ // quote if not already quoted
+ if (tmp[0] != '"')
+ {
+ includeOptions += "\"";
+ includeOptions += tmp;
+ includeOptions += "\"";
+ }
+ else
+ {
+ includeOptions += tmp;
+ }
+ }
+
+ if(j == 0 && includeOptions.size() > maxIncludeLength)
+ {
+ includeOptions = "";
+ useShortPath = true;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ return includeOptions;
+}
+
+
+// Code in blocks surrounded by a test for this definition is needed
+// only for compatibility with user project's replacement DSP
+// templates. The CMake templates no longer use them.
+#define CM_USE_OLD_VS6
+
+void cmLocalVisualStudio6Generator
+::WriteDSPHeader(std::ostream& fout,
+ const std::string& libName, cmTarget &target,
+ std::vector<cmSourceGroup> &)
+{
+ bool targetBuilds = (target.GetType() >= cmTarget::EXECUTABLE &&
+ target.GetType() <= cmTarget::MODULE_LIBRARY);
+#ifdef CM_USE_OLD_VS6
+ // Lookup the library and executable output directories.
+ std::string libPath;
+ if(this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
+ {
+ libPath = this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
+ }
+ std::string exePath;
+ if(this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
+ {
+ exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
+ }
+
+ // Make sure there are trailing slashes.
+ if(!libPath.empty())
+ {
+ if(libPath[libPath.size()-1] != '/')
+ {
+ libPath += "/";
+ }
+ }
+ if(!exePath.empty())
+ {
+ if(exePath[exePath.size()-1] != '/')
+ {
+ exePath += "/";
+ }
+ }
+
+ std::set<std::string> pathEmitted;
+
+ // determine the link directories
+ std::string libOptions;
+ std::string libDebugOptions;
+ std::string libOptimizedOptions;
+
+ std::string libMultiLineOptions;
+ std::string libMultiLineOptionsForDebug;
+ std::string libMultiLineDebugOptions;
+ std::string libMultiLineOptimizedOptions;
+
+ if(libPath.size())
+ {
+ std::string lpath =
+ this->ConvertToOptionallyRelativeOutputPath(libPath.c_str());
+ if(lpath.size() == 0)
+ {
+ lpath = ".";
+ }
+ std::string lpathIntDir = libPath + "$(INTDIR)";
+ lpathIntDir =
+ this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
+ if(pathEmitted.insert(lpath).second)
+ {
+ libOptions += " /LIBPATH:";
+ libOptions += lpathIntDir;
+ libOptions += " ";
+ libOptions += " /LIBPATH:";
+ libOptions += lpath;
+ libOptions += " ";
+ libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
+ libMultiLineOptions += lpathIntDir;
+ libMultiLineOptions += " ";
+ libMultiLineOptions += " /LIBPATH:";
+ libMultiLineOptions += lpath;
+ libMultiLineOptions += " \n";
+ libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
+ libMultiLineOptionsForDebug += lpathIntDir;
+ libMultiLineOptionsForDebug += " ";
+ libMultiLineOptionsForDebug += " /LIBPATH:";
+ libMultiLineOptionsForDebug += lpath;
+ libMultiLineOptionsForDebug += " \n";
+ }
+ }
+ if(exePath.size())
+ {
+ std::string lpath =
+ this->ConvertToOptionallyRelativeOutputPath(exePath.c_str());
+ if(lpath.size() == 0)
+ {
+ lpath = ".";
+ }
+ std::string lpathIntDir = exePath + "$(INTDIR)";
+ lpathIntDir =
+ this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
+
+ if(pathEmitted.insert(lpath).second)
+ {
+ libOptions += " /LIBPATH:";
+ libOptions += lpathIntDir;
+ libOptions += " ";
+ libOptions += " /LIBPATH:";
+ libOptions += lpath;
+ libOptions += " ";
+ libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
+ libMultiLineOptions += lpathIntDir;
+ libMultiLineOptions += " ";
+ libMultiLineOptions += " /LIBPATH:";
+ libMultiLineOptions += lpath;
+ libMultiLineOptions += " \n";
+ libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
+ libMultiLineOptionsForDebug += lpathIntDir;
+ libMultiLineOptionsForDebug += " ";
+ libMultiLineOptionsForDebug += " /LIBPATH:";
+ libMultiLineOptionsForDebug += lpath;
+ libMultiLineOptionsForDebug += " \n";
+ }
+ }
+ std::vector<std::string>::const_iterator i;
+ const std::vector<std::string>& libdirs = target.GetLinkDirectories();
+ for(i = libdirs.begin(); i != libdirs.end(); ++i)
+ {
+ std::string path = *i;
+ if(path[path.size()-1] != '/')
+ {
+ path += "/";
+ }
+ std::string lpath =
+ this->ConvertToOptionallyRelativeOutputPath(path.c_str());
+ if(lpath.size() == 0)
+ {
+ lpath = ".";
+ }
+ std::string lpathIntDir = path + "$(INTDIR)";
+ lpathIntDir =
+ this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
+ if(pathEmitted.insert(lpath).second)
+ {
+ libOptions += " /LIBPATH:";
+ libOptions += lpathIntDir;
+ libOptions += " ";
+ libOptions += " /LIBPATH:";
+ libOptions += lpath;
+ libOptions += " ";
+
+ libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
+ libMultiLineOptions += lpathIntDir;
+ libMultiLineOptions += " ";
+ libMultiLineOptions += " /LIBPATH:";
+ libMultiLineOptions += lpath;
+ libMultiLineOptions += " \n";
+ libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
+ libMultiLineOptionsForDebug += lpathIntDir;
+ libMultiLineOptionsForDebug += " ";
+ libMultiLineOptionsForDebug += " /LIBPATH:";
+ libMultiLineOptionsForDebug += lpath;
+ libMultiLineOptionsForDebug += " \n";
+ }
+ }
+ // find link libraries
+ const cmTarget::LinkLibraryVectorType& libs =
+ 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
+ && libName != GetVS6TargetName(j->first)) ||
+ (target.GetType()==cmTarget::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());
+ if(tgt)
+ {
+ lib = cmSystemTools::GetFilenameWithoutExtension
+ (tgt->GetFullName().c_str());
+ libDebug = cmSystemTools::GetFilenameWithoutExtension
+ (tgt->GetFullName("Debug").c_str());
+ lib += ".lib";
+ libDebug += ".lib";
+ }
+ else
+ {
+ lib = j->first.c_str();
+ libDebug = j->first.c_str();
+ if(j->first.find(".lib") == std::string::npos)
+ {
+ lib += ".lib";
+ libDebug += ".lib";
+ }
+ }
+ lib = this->ConvertToOptionallyRelativeOutputPath(lib.c_str());
+ libDebug =
+ this->ConvertToOptionallyRelativeOutputPath(libDebug.c_str());
+
+ if (j->second == cmTarget::GENERAL)
+ {
+ libOptions += " ";
+ libOptions += lib;
+ libMultiLineOptions += "# ADD LINK32 ";
+ libMultiLineOptions += lib;
+ libMultiLineOptions += "\n";
+ libMultiLineOptionsForDebug += "# ADD LINK32 ";
+ libMultiLineOptionsForDebug += libDebug;
+ libMultiLineOptionsForDebug += "\n";
+ }
+ if (j->second == cmTarget::DEBUG)
+ {
+ libDebugOptions += " ";
+ libDebugOptions += lib;
+
+ libMultiLineDebugOptions += "# ADD LINK32 ";
+ libMultiLineDebugOptions += libDebug;
+ libMultiLineDebugOptions += "\n";
+ }
+ if (j->second == cmTarget::OPTIMIZED)
+ {
+ libOptimizedOptions += " ";
+ libOptimizedOptions += lib;
+
+ libMultiLineOptimizedOptions += "# ADD LINK32 ";
+ libMultiLineOptimizedOptions += lib;
+ libMultiLineOptimizedOptions += "\n";
+ }
+ }
+ }
+#endif
+
+ // Get include options for this target.
+ std::string includeOptionsDebug = this->GetTargetIncludeOptions(target,
+ "DEBUG");
+ std::string includeOptionsRelease = this->GetTargetIncludeOptions(target,
+ "RELEASE");
+ std::string includeOptionsRelWithDebInfo = this->GetTargetIncludeOptions(
+ target,
+ "RELWITHDEBINFO");
+ std::string includeOptionsMinSizeRel = this->GetTargetIncludeOptions(target,
+ "MINSIZEREL");
+
+ // Get extra linker options for this target type.
+ std::string extraLinkOptions;
+ std::string extraLinkOptionsDebug;
+ std::string extraLinkOptionsRelease;
+ std::string extraLinkOptionsMinSizeRel;
+ std::string extraLinkOptionsRelWithDebInfo;
+ if(target.GetType() == cmTarget::EXECUTABLE)
+ {
+ extraLinkOptions = this->Makefile->
+ GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
+ extraLinkOptionsDebug = this->Makefile->
+ GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS_DEBUG");
+ extraLinkOptionsRelease = this->Makefile->
+ GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS_RELEASE");
+ extraLinkOptionsMinSizeRel = this->Makefile->
+ GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS_MINSIZEREL");
+ extraLinkOptionsRelWithDebInfo = this->Makefile->
+ GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO");
+ }
+ if(target.GetType() == cmTarget::SHARED_LIBRARY)
+ {
+ extraLinkOptions = this->Makefile->
+ GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
+ extraLinkOptionsDebug = this->Makefile->
+ GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS_DEBUG");
+ extraLinkOptionsRelease = this->Makefile->
+ GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS_RELEASE");
+ extraLinkOptionsMinSizeRel = this->Makefile->
+ GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL");
+ extraLinkOptionsRelWithDebInfo = this->Makefile->
+ GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO");
+ }
+ if(target.GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ extraLinkOptions = this->Makefile->
+ GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
+ extraLinkOptionsDebug = this->Makefile->
+ GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS_DEBUG");
+ extraLinkOptionsRelease = this->Makefile->
+ GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS_RELEASE");
+ extraLinkOptionsMinSizeRel = this->Makefile->
+ GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL");
+ extraLinkOptionsRelWithDebInfo = this->Makefile->
+ GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO");
+ }
+
+ // Get extra linker options for this target.
+ if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"))
+ {
+ extraLinkOptions += " ";
+ extraLinkOptions += targetLinkFlags;
+ }
+
+ if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_DEBUG"))
+ {
+ extraLinkOptionsDebug += " ";
+ extraLinkOptionsDebug += targetLinkFlags;
+ }
+
+ if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_RELEASE"))
+ {
+ extraLinkOptionsRelease += " ";
+ extraLinkOptionsRelease += targetLinkFlags;
+ }
+
+ if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_MINSIZEREL"))
+ {
+ extraLinkOptionsMinSizeRel += " ";
+ extraLinkOptionsMinSizeRel += targetLinkFlags;
+ }
+
+ if(const char* targetLinkFlags =
+ target.GetProperty("LINK_FLAGS_RELWITHDEBINFO"))
+ {
+ extraLinkOptionsRelWithDebInfo += " ";
+ extraLinkOptionsRelWithDebInfo += targetLinkFlags;
+ }
+
+
+
+
+ // Get standard libraries for this language.
+ if(targetBuilds)
+ {
+ // Get the language to use for linking.
+ std::vector<std::string> configs;
+ target.GetMakefile()->GetConfigurations(configs);
+ std::vector<std::string>::const_iterator it = configs.begin();
+ const std::string& linkLanguage = target.GetLinkerLanguage(*it);
+ for ( ; it != configs.end(); ++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());
+ }
+ }
+ if(linkLanguage.empty())
+ {
+ cmSystemTools::Error
+ ("CMake can not determine linker language for target: ",
+ target.GetName().c_str());
+ return;
+ }
+
+ // Compute the variable name to lookup standard libraries for this
+ // language.
+ std::string standardLibsVar = "CMAKE_";
+ standardLibsVar += linkLanguage;
+ standardLibsVar += "_STANDARD_LIBRARIES";
+
+ // Add standard libraries.
+ if(const char* stdLibs =
+ this->Makefile->GetDefinition(standardLibsVar.c_str()))
+ {
+ extraLinkOptions += " ";
+ extraLinkOptions += stdLibs;
+ }
+ }
+
+ // Compute version number information.
+ std::string targetVersionFlag;
+ if(target.GetType() == cmTarget::EXECUTABLE ||
+ target.GetType() == cmTarget::SHARED_LIBRARY ||
+ target.GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ int major;
+ int minor;
+ target.GetTargetVersion(major, minor);
+ cmOStringStream targetVersionStream;
+ targetVersionStream << "/version:" << major << "." << minor;
+ targetVersionFlag = targetVersionStream.str();
+ }
+
+ // Compute the real name of the target.
+ std::string outputName =
+ "(OUTPUT_NAME is for libraries and executables only)";
+ std::string outputNameDebug = outputName;
+ 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)
+ {
+ 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)
+ {
+ outputName = target.GetName();
+ outputName += ".lib";
+ outputNameDebug = outputName;
+ outputNameRelease = outputName;
+ outputNameMinSizeRel = outputName;
+ outputNameRelWithDebInfo = outputName;
+ }
+
+ // Compute the output directory for the target.
+ std::string outputDirOld;
+ std::string outputDirDebug;
+ 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)
+ {
+#ifdef CM_USE_OLD_VS6
+ outputDirOld =
+ removeQuotes(this->ConvertToOptionallyRelativeOutputPath
+ (target.GetDirectory().c_str()));
+#endif
+ outputDirDebug =
+ removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
+ target.GetDirectory("Debug").c_str()));
+ outputDirRelease =
+ removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
+ target.GetDirectory("Release").c_str()));
+ outputDirMinSizeRel =
+ removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
+ target.GetDirectory("MinSizeRel").c_str()));
+ outputDirRelWithDebInfo =
+ removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
+ target.GetDirectory("RelWithDebInfo").c_str()));
+ }
+ else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ std::string outputDir = cmake::GetCMakeFilesDirectoryPostSlash();
+ outputDirDebug = outputDir + "Debug";
+ outputDirRelease = outputDir + "Release";
+ outputDirMinSizeRel = outputDir + "MinSizeRel";
+ outputDirRelWithDebInfo = outputDir + "RelWithDebInfo";
+ }
+
+ // Compute the proper link information for the target.
+ std::string optionsDebug;
+ std::string optionsRelease;
+ std::string optionsMinSizeRel;
+ std::string optionsRelWithDebInfo;
+ if(target.GetType() == cmTarget::EXECUTABLE ||
+ target.GetType() == cmTarget::SHARED_LIBRARY ||
+ target.GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ extraLinkOptionsDebug =
+ extraLinkOptions + " " + extraLinkOptionsDebug;
+ extraLinkOptionsRelease =
+ extraLinkOptions + " " + extraLinkOptionsRelease;
+ extraLinkOptionsMinSizeRel =
+ extraLinkOptions + " " + extraLinkOptionsMinSizeRel;
+ extraLinkOptionsRelWithDebInfo =
+ extraLinkOptions + " " + extraLinkOptionsRelWithDebInfo;
+ this->ComputeLinkOptions(target, "Debug", extraLinkOptionsDebug,
+ optionsDebug);
+ this->ComputeLinkOptions(target, "Release", extraLinkOptionsRelease,
+ optionsRelease);
+ this->ComputeLinkOptions(target, "MinSizeRel", extraLinkOptionsMinSizeRel,
+ optionsMinSizeRel);
+ this->ComputeLinkOptions(target, "RelWithDebInfo",
+ extraLinkOptionsRelWithDebInfo,
+ optionsRelWithDebInfo);
+ }
+
+ // Compute the path of the import library.
+ std::string targetImplibFlagDebug;
+ std::string targetImplibFlagRelease;
+ std::string targetImplibFlagMinSizeRel;
+ std::string targetImplibFlagRelWithDebInfo;
+ if(target.GetType() == cmTarget::SHARED_LIBRARY ||
+ target.GetType() == cmTarget::MODULE_LIBRARY ||
+ target.GetType() == cmTarget::EXECUTABLE)
+ {
+ std::string fullPathImpDebug = target.GetDirectory("Debug", true);
+ std::string fullPathImpRelease = target.GetDirectory("Release", true);
+ std::string fullPathImpMinSizeRel =
+ target.GetDirectory("MinSizeRel", true);
+ std::string fullPathImpRelWithDebInfo =
+ target.GetDirectory("RelWithDebInfo", true);
+ fullPathImpDebug += "/";
+ fullPathImpRelease += "/";
+ fullPathImpMinSizeRel += "/";
+ fullPathImpRelWithDebInfo += "/";
+ fullPathImpDebug += target.GetFullName("Debug", true);
+ fullPathImpRelease += target.GetFullName("Release", true);
+ fullPathImpMinSizeRel += target.GetFullName("MinSizeRel", true);
+ fullPathImpRelWithDebInfo += target.GetFullName("RelWithDebInfo", true);
+
+ targetImplibFlagDebug = "/implib:";
+ targetImplibFlagRelease = "/implib:";
+ targetImplibFlagMinSizeRel = "/implib:";
+ targetImplibFlagRelWithDebInfo = "/implib:";
+ targetImplibFlagDebug +=
+ this->ConvertToOptionallyRelativeOutputPath(fullPathImpDebug.c_str());
+ targetImplibFlagRelease +=
+ this->ConvertToOptionallyRelativeOutputPath(fullPathImpRelease.c_str());
+ targetImplibFlagMinSizeRel +=
+ this->ConvertToOptionallyRelativeOutputPath(
+ fullPathImpMinSizeRel.c_str());
+ targetImplibFlagRelWithDebInfo +=
+ this->ConvertToOptionallyRelativeOutputPath(
+ fullPathImpRelWithDebInfo.c_str());
+ }
+
+#ifdef CM_USE_OLD_VS6
+ // Compute link information for the target.
+ if(extraLinkOptions.size())
+ {
+ libOptions += " ";
+ libOptions += extraLinkOptions;
+ libOptions += " ";
+ libMultiLineOptions += "# ADD LINK32 ";
+ libMultiLineOptions += extraLinkOptions;
+ libMultiLineOptions += " \n";
+ libMultiLineOptionsForDebug += "# ADD LINK32 ";
+ libMultiLineOptionsForDebug += extraLinkOptions;
+ libMultiLineOptionsForDebug += " \n";
+ }
+#endif
+
+ // are there any custom rules on the target itself
+ // only if the target is a lib or exe
+ std::string customRuleCodeRelease
+ = this->CreateTargetRules(target, "RELEASE", libName);
+ std::string customRuleCodeDebug
+ = this->CreateTargetRules(target, "DEBUG", libName);
+ std::string customRuleCodeMinSizeRel
+ = this->CreateTargetRules(target, "MINSIZEREL", libName);
+ std::string customRuleCodeRelWithDebInfo
+ = this->CreateTargetRules(target, "RELWITHDEBINFO", libName);
+
+ cmsys::ifstream fin(this->DSPHeaderTemplate.c_str());
+ if(!fin)
+ {
+ cmSystemTools::Error("Error Reading ", this->DSPHeaderTemplate.c_str());
+ }
+ std::string staticLibOptions;
+ std::string staticLibOptionsDebug;
+ std::string staticLibOptionsRelease;
+ std::string staticLibOptionsMinSizeRel;
+ std::string staticLibOptionsRelWithDebInfo;
+ if(target.GetType() == cmTarget::STATIC_LIBRARY )
+ {
+ const char *libflagsGlobal =
+ this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS");
+ this->AppendFlags(staticLibOptions, libflagsGlobal);
+ this->AppendFlags(staticLibOptionsDebug, libflagsGlobal);
+ this->AppendFlags(staticLibOptionsRelease, libflagsGlobal);
+ this->AppendFlags(staticLibOptionsMinSizeRel, libflagsGlobal);
+ this->AppendFlags(staticLibOptionsRelWithDebInfo, libflagsGlobal);
+
+ this->AppendFlags(staticLibOptionsDebug, this->Makefile->
+ GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS_DEBUG"));
+ this->AppendFlags(staticLibOptionsRelease, this->Makefile->
+ GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS_RELEASE"));
+ this->AppendFlags(staticLibOptionsMinSizeRel, this->Makefile->
+ GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL"));
+ this->AppendFlags(staticLibOptionsRelWithDebInfo, this->Makefile->
+ GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO"));
+
+ const char *libflags = target.GetProperty("STATIC_LIBRARY_FLAGS");
+ this->AppendFlags(staticLibOptions, libflags);
+ this->AppendFlags(staticLibOptionsDebug, libflags);
+ this->AppendFlags(staticLibOptionsRelease, libflags);
+ this->AppendFlags(staticLibOptionsMinSizeRel, libflags);
+ this->AppendFlags(staticLibOptionsRelWithDebInfo, libflags);
+
+ this->AppendFlags(staticLibOptionsDebug,
+ target.GetProperty("STATIC_LIBRARY_FLAGS_DEBUG"));
+ this->AppendFlags(staticLibOptionsRelease,
+ target.GetProperty("STATIC_LIBRARY_FLAGS_RELEASE"));
+ this->AppendFlags(staticLibOptionsMinSizeRel,
+ target.GetProperty("STATIC_LIBRARY_FLAGS_MINSIZEREL"));
+ this->AppendFlags(staticLibOptionsRelWithDebInfo,
+ target.GetProperty("STATIC_LIBRARY_FLAGS_RELWITHDEBINFO"));
+
+ std::string objects;
+ this->OutputObjects(target, "LIB", objects);
+ if(!objects.empty())
+ {
+ objects = "\n" + objects;
+ staticLibOptionsDebug += objects;
+ staticLibOptionsRelease += objects;
+ staticLibOptionsMinSizeRel += objects;
+ staticLibOptionsRelWithDebInfo += objects;
+ }
+ }
+
+ // Add the export symbol definition for shared library objects.
+ std::string exportSymbol;
+ if(const char* exportMacro = target.GetExportMacro())
+ {
+ exportSymbol = exportMacro;
+ }
+
+ std::string line;
+ std::string libnameExports;
+ if(exportSymbol.size())
+ {
+ libnameExports = "/D \"";
+ libnameExports += exportSymbol;
+ libnameExports += "\"";
+ }
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
+ if(!mfcFlag)
+ {
+ mfcFlag = "0";
+ }
+ cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME_EXPORTS",
+ libnameExports.c_str());
+ cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
+ mfcFlag);
+ if(target.GetType() == cmTarget::STATIC_LIBRARY ||
+ target.GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_DEBUG",
+ staticLibOptionsDebug.c_str());
+ cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_RELEASE",
+ staticLibOptionsRelease.c_str());
+ cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_MINSIZEREL",
+ staticLibOptionsMinSizeRel.c_str());
+ cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_RELWITHDEBINFO",
+ staticLibOptionsRelWithDebInfo.c_str());
+ cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS",
+ staticLibOptions.c_str());
+ }
+ if(this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
+ {
+ cmSystemTools::ReplaceString(line, "/nologo", "");
+ }
+
+#ifdef CM_USE_OLD_VS6
+ cmSystemTools::ReplaceString(line, "CM_LIBRARIES",
+ libOptions.c_str());
+ cmSystemTools::ReplaceString(line, "CM_DEBUG_LIBRARIES",
+ libDebugOptions.c_str());
+ cmSystemTools::ReplaceString(line, "CM_OPTIMIZED_LIBRARIES",
+ libOptimizedOptions.c_str());
+ cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES_FOR_DEBUG",
+ libMultiLineOptionsForDebug.c_str());
+ cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES",
+ libMultiLineOptions.c_str());
+ cmSystemTools::ReplaceString(line, "CM_MULTILINE_DEBUG_LIBRARIES",
+ libMultiLineDebugOptions.c_str());
+ cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIMIZED_LIBRARIES",
+ libMultiLineOptimizedOptions.c_str());
+#endif
+
+ // Substitute the rules for custom command. When specifying just the
+ // target name for the command the command can be different for
+ // different configs
+ cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE_RELEASE",
+ customRuleCodeRelease.c_str());
+ cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE_DEBUG",
+ customRuleCodeDebug.c_str());
+ cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE_MINSIZEREL",
+ customRuleCodeMinSizeRel.c_str());
+ cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE_RELWITHDEBINFO",
+ customRuleCodeRelWithDebInfo.c_str());
+
+ // Substitute the real output name into the template.
+ cmSystemTools::ReplaceString(line, "OUTPUT_NAME_DEBUG",
+ outputNameDebug.c_str());
+ cmSystemTools::ReplaceString(line, "OUTPUT_NAME_RELEASE",
+ outputNameRelease.c_str());
+ cmSystemTools::ReplaceString(line, "OUTPUT_NAME_MINSIZEREL",
+ outputNameMinSizeRel.c_str());
+ cmSystemTools::ReplaceString(line, "OUTPUT_NAME_RELWITHDEBINFO",
+ outputNameRelWithDebInfo.c_str());
+ cmSystemTools::ReplaceString(line, "OUTPUT_NAME", outputName.c_str());
+
+ // Substitute the proper link information into the template.
+ cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIONS_DEBUG",
+ optionsDebug.c_str());
+ cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIONS_RELEASE",
+ optionsRelease.c_str());
+ cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIONS_MINSIZEREL",
+ optionsMinSizeRel.c_str());
+ cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIONS_RELWITHDEBINFO",
+ optionsRelWithDebInfo.c_str());
+
+ cmSystemTools::ReplaceString(line, "BUILD_INCLUDES_DEBUG",
+ includeOptionsDebug.c_str());
+ cmSystemTools::ReplaceString(line, "BUILD_INCLUDES_RELEASE",
+ includeOptionsRelease.c_str());
+ cmSystemTools::ReplaceString(line, "BUILD_INCLUDES_MINSIZEREL",
+ includeOptionsMinSizeRel.c_str());
+ cmSystemTools::ReplaceString(line, "BUILD_INCLUDES_RELWITHDEBINFO",
+ includeOptionsRelWithDebInfo.c_str());
+
+ cmSystemTools::ReplaceString(line, "TARGET_VERSION_FLAG",
+ targetVersionFlag.c_str());
+ cmSystemTools::ReplaceString(line, "TARGET_IMPLIB_FLAG_DEBUG",
+ targetImplibFlagDebug.c_str());
+ cmSystemTools::ReplaceString(line, "TARGET_IMPLIB_FLAG_RELEASE",
+ targetImplibFlagRelease.c_str());
+ cmSystemTools::ReplaceString(line, "TARGET_IMPLIB_FLAG_MINSIZEREL",
+ targetImplibFlagMinSizeRel.c_str());
+ cmSystemTools::ReplaceString(line, "TARGET_IMPLIB_FLAG_RELWITHDEBINFO",
+ targetImplibFlagRelWithDebInfo.c_str());
+
+ std::string vs6name = GetVS6TargetName(libName);
+ cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME", vs6name.c_str());
+
+#ifdef CM_USE_OLD_VS6
+ // because LIBRARY_OUTPUT_PATH and EXECUTABLE_OUTPUT_PATH
+ // are already quoted in the template file,
+ // we need to remove the quotes here, we still need
+ // to convert to output path for unix to win32 conversion
+ cmSystemTools::ReplaceString
+ (line, "LIBRARY_OUTPUT_PATH",
+ removeQuotes(this->ConvertToOptionallyRelativeOutputPath
+ (libPath.c_str())).c_str());
+ cmSystemTools::ReplaceString
+ (line, "EXECUTABLE_OUTPUT_PATH",
+ removeQuotes(this->ConvertToOptionallyRelativeOutputPath
+ (exePath.c_str())).c_str());
+#endif
+
+ if(targetBuilds || target.GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_DEBUG",
+ outputDirDebug.c_str());
+ cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_RELEASE",
+ outputDirRelease.c_str());
+ cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_MINSIZEREL",
+ outputDirMinSizeRel.c_str());
+ cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_RELWITHDEBINFO",
+ outputDirRelWithDebInfo.c_str());
+ if(!outputDirOld.empty())
+ {
+ cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY",
+ outputDirOld.c_str());
+ }
+ }
+
+ cmSystemTools::ReplaceString(line,
+ "EXTRA_DEFINES",
+ this->Makefile->GetDefineFlags());
+ const char* debugPostfix
+ = this->Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
+ cmSystemTools::ReplaceString(line, "DEBUG_POSTFIX",
+ debugPostfix?debugPostfix:"");
+ // store flags for each configuration
+ std::string flags = " ";
+ std::string flagsRelease = " ";
+ std::string flagsMinSizeRel = " ";
+ std::string flagsDebug = " ";
+ std::string flagsRelWithDebInfo = " ";
+ if(target.GetType() >= cmTarget::EXECUTABLE &&
+ target.GetType() <= cmTarget::OBJECT_LIBRARY)
+ {
+ std::vector<std::string> configs;
+ target.GetMakefile()->GetConfigurations(configs);
+ std::vector<std::string>::const_iterator it = configs.begin();
+ const std::string& linkLanguage = target.GetLinkerLanguage(*it);
+ for ( ; it != configs.end(); ++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());
+ }
+ }
+ if(linkLanguage.empty())
+ {
+ cmSystemTools::Error
+ ("CMake can not determine linker language for target: ",
+ target.GetName().c_str());
+ return;
+ }
+ // if CXX is on and the target contains cxx code then add the cxx flags
+ std::string baseFlagVar = "CMAKE_";
+ baseFlagVar += linkLanguage;
+ baseFlagVar += "_FLAGS";
+ flags = this->Makefile->GetSafeDefinition(baseFlagVar.c_str());
+
+ std::string flagVar = baseFlagVar + "_RELEASE";
+ flagsRelease = this->Makefile->GetSafeDefinition(flagVar.c_str());
+ flagsRelease += " -DCMAKE_INTDIR=\\\"Release\\\" ";
+
+ flagVar = baseFlagVar + "_MINSIZEREL";
+ flagsMinSizeRel = this->Makefile->GetSafeDefinition(flagVar.c_str());
+ flagsMinSizeRel += " -DCMAKE_INTDIR=\\\"MinSizeRel\\\" ";
+
+ flagVar = baseFlagVar + "_DEBUG";
+ flagsDebug = this->Makefile->GetSafeDefinition(flagVar.c_str());
+ flagsDebug += " -DCMAKE_INTDIR=\\\"Debug\\\" ";
+
+ flagVar = baseFlagVar + "_RELWITHDEBINFO";
+ 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,
+ "MinSizeRel");
+ this->AddCompileOptions(flagsRelWithDebInfo, &target, linkLanguage,
+ "RelWithDebInfo");
+ }
+
+ // if _UNICODE and _SBCS are not found, then add -D_MBCS
+ std::string defs = this->Makefile->GetDefineFlags();
+ if(flags.find("D_UNICODE") == flags.npos &&
+ defs.find("D_UNICODE") == flags.npos &&
+ flags.find("D_SBCS") == flags.npos &&
+ defs.find("D_SBCS") == flags.npos)
+ {
+ flags += " /D \"_MBCS\"";
+ }
+
+ // Add per-target and per-configuration preprocessor definitions.
+ std::set<std::string> definesSet;
+ std::set<std::string> debugDefinesSet;
+ std::set<std::string> releaseDefinesSet;
+ std::set<std::string> minsizeDefinesSet;
+ std::set<std::string> debugrelDefinesSet;
+
+ this->AddCompileDefinitions(definesSet, &target, "");
+ this->AddCompileDefinitions(debugDefinesSet, &target, "DEBUG");
+ this->AddCompileDefinitions(releaseDefinesSet, &target, "RELEASE");
+ this->AddCompileDefinitions(minsizeDefinesSet, &target, "MINSIZEREL");
+ this->AddCompileDefinitions(debugrelDefinesSet, &target, "RELWITHDEBINFO");
+
+ std::string defines = " ";
+ std::string debugDefines = " ";
+ std::string releaseDefines = " ";
+ std::string minsizeDefines = " ";
+ std::string debugrelDefines = " ";
+
+ this->JoinDefines(definesSet, defines, "");
+ this->JoinDefines(debugDefinesSet, debugDefines, "");
+ this->JoinDefines(releaseDefinesSet, releaseDefines, "");
+ this->JoinDefines(minsizeDefinesSet, minsizeDefines, "");
+ this->JoinDefines(debugrelDefinesSet, debugrelDefines, "");
+
+ flags += defines;
+ flagsDebug += debugDefines;
+ flagsRelease += releaseDefines;
+ flagsMinSizeRel += minsizeDefines;
+ flagsRelWithDebInfo += debugrelDefines;
+
+ // The template files have CXX FLAGS in them, that need to be replaced.
+ // There are not separate CXX and C template files, so we use the same
+ // variable names. The previous code sets up flags* variables to contain
+ // the correct C or CXX flags
+ cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_MINSIZEREL",
+ flagsMinSizeRel.c_str());
+ cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_DEBUG",
+ flagsDebug.c_str());
+ cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELWITHDEBINFO",
+ flagsRelWithDebInfo.c_str());
+ cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELEASE",
+ flagsRelease.c_str());
+ cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS", flags.c_str());
+
+ cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS_MINSIZEREL",
+ minsizeDefines.c_str());
+ cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS_DEBUG",
+ debugDefines.c_str());
+ cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS_RELWITHDEBINFO",
+ debugrelDefines.c_str());
+ cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS_RELEASE",
+ releaseDefines.c_str());
+ cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS", defines.c_str());
+
+ fout << line.c_str() << std::endl;
+ }
+}
+
+void cmLocalVisualStudio6Generator::WriteDSPFooter(std::ostream& fout)
+{
+ cmsys::ifstream fin(this->DSPFooterTemplate.c_str());
+ if(!fin)
+ {
+ cmSystemTools::Error("Error Reading ",
+ this->DSPFooterTemplate.c_str());
+ }
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ fout << line << std::endl;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalVisualStudio6Generator
+::ComputeLinkOptions(cmTarget& target,
+ const std::string& configName,
+ const std::string extraOptions,
+ std::string& options)
+{
+ // Compute the link information for this configuration.
+ cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
+ if(!pcli)
+ {
+ return;
+ }
+ cmComputeLinkInformation& cli = *pcli;
+ typedef cmComputeLinkInformation::ItemVector ItemVector;
+ ItemVector const& linkLibs = cli.GetItems();
+ std::vector<std::string> const& linkDirs = cli.GetDirectories();
+
+ this->OutputObjects(target, "LINK", options);
+
+ // Build the link options code.
+ for(std::vector<std::string>::const_iterator d = linkDirs.begin();
+ d != linkDirs.end(); ++d)
+ {
+ std::string dir = *d;
+ if(!dir.empty())
+ {
+ if(dir[dir.size()-1] != '/')
+ {
+ dir += "/";
+ }
+ dir += "$(IntDir)";
+ options += "# ADD LINK32 /LIBPATH:";
+ options += this->ConvertToOptionallyRelativeOutputPath(dir.c_str());
+ options += " /LIBPATH:";
+ options += this->ConvertToOptionallyRelativeOutputPath(d->c_str());
+ options += "\n";
+ }
+ }
+ for(ItemVector::const_iterator l = linkLibs.begin();
+ l != linkLibs.end(); ++l)
+ {
+ options += "# ADD LINK32 ";
+ if(l->IsPath)
+ {
+ options +=
+ this->ConvertToOptionallyRelativeOutputPath(l->Value.c_str());
+ }
+ else if (!l->Target
+ || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ options += l->Value;
+ }
+ options += "\n";
+ }
+
+ // Add extra options if any.
+ if(!extraOptions.empty())
+ {
+ options += "# ADD LINK32 ";
+ options += extraOptions;
+ options += "\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalVisualStudio6Generator
+::OutputObjects(cmTarget& 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, "");
+ for(std::vector<std::string>::const_iterator
+ oi = objs.begin(); oi != objs.end(); ++oi)
+ {
+ options += "# ADD ";
+ options += tool;
+ options += "32 ";
+ options += this->ConvertToOptionallyRelativeOutputPath(oi->c_str());
+ options += "\n";
+ }
+}
+
+std::string
+cmLocalVisualStudio6Generator
+::GetTargetDirectory(cmTarget const&) const
+{
+ // No per-target directory for this generator (yet).
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalVisualStudio6Generator
+::ComputeLongestObjectDirectory(cmTarget&) const
+{
+ // Compute the maximum length configuration name.
+ std::string config_max;
+ for(std::vector<std::string>::const_iterator
+ i = this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ // Strip the subdirectory name out of the configuration name.
+ std::string config = this->GetConfigName(*i);
+ if(config.size() > config_max.size())
+ {
+ config_max = config;
+ }
+ }
+
+ // Compute the maximum length full path to the intermediate
+ // 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->GetCurrentOutputDirectory();
+ dir_max += "/";
+ dir_max += config_max;
+ dir_max += "/";
+ return dir_max;
+}
+
+std::string
+cmLocalVisualStudio6Generator
+::GetConfigName(std::string const& configuration) const
+{
+ // Strip the subdirectory name out of the configuration name.
+ std::string config = configuration;
+ std::string::size_type pos = config.find_last_of(" ");
+ config = config.substr(pos+1, std::string::npos);
+ config = config.substr(0, config.size()-1);
+ return config;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmLocalVisualStudio6Generator
+::CheckDefinition(std::string const& define) const
+{
+ // Perform the standard check first.
+ if(!this->cmLocalGenerator::CheckDefinition(define))
+ {
+ return false;
+ }
+
+ // Now do the VS6-specific check.
+ if(define.find_first_of(" ") != define.npos &&
+ define.find_first_of("\"$;") != define.npos)
+ {
+ cmOStringStream e;
+ e << "WARNING: The VS6 IDE does not support preprocessor definition "
+ << "values with spaces and '\"', '$', or ';'.\n"
+ << "CMake is dropping a preprocessor definition: " << define << "\n"
+ << "Consider defining the macro in a (configured) header file.\n";
+ cmSystemTools::Message(e.str().c_str());
+ return false;
+ }
+
+ // Assume it is supported.
+ return true;
+}
diff --git a/Source/cmLocalVisualStudio6Generator.h b/Source/cmLocalVisualStudio6Generator.h
new file mode 100644
index 0000000000..47718337b7
--- /dev/null
+++ b/Source/cmLocalVisualStudio6Generator.h
@@ -0,0 +1,104 @@
+/*============================================================================
+ 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 cmLocalVisualStudio6Generator_h
+#define cmLocalVisualStudio6Generator_h
+
+#include "cmLocalVisualStudioGenerator.h"
+
+class cmTarget;
+class cmSourceFile;
+class cmSourceGroup;
+class cmCustomCommand;
+
+/** \class cmLocalVisualStudio6Generator
+ * \brief Write a LocalUnix makefiles.
+ *
+ * cmLocalVisualStudio6Generator produces a LocalUnix makefile from its
+ * member this->Makefile.
+ */
+class cmLocalVisualStudio6Generator : public cmLocalVisualStudioGenerator
+{
+public:
+ ///! Set cache only and recurse to false by default.
+ cmLocalVisualStudio6Generator();
+
+ virtual ~cmLocalVisualStudio6Generator();
+
+ virtual void AddHelperCommands();
+ virtual void AddCMakeListsRules();
+
+ /**
+ * Generate the makefile for this directory.
+ */
+ virtual void Generate();
+
+ void OutputDSPFile();
+
+ enum BuildType {STATIC_LIBRARY, DLL, EXECUTABLE, WIN32_EXECUTABLE, UTILITY};
+
+ /**
+ * Specify the type of the build: static, dll, or executable.
+ */
+ void SetBuildType(BuildType, const std::string& libName, cmTarget&);
+
+ virtual std::string GetTargetDirectory(cmTarget const& target) const;
+ virtual std::string ComputeLongestObjectDirectory(cmTarget&) const;
+private:
+ std::string DSPHeaderTemplate;
+ std::string DSPFooterTemplate;
+
+ void CreateSingleDSP(const std::string& lname, cmTarget &tgt);
+ void WriteDSPFile(std::ostream& fout, const std::string& libName,
+ cmTarget &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);
+
+ void WriteDSPFooter(std::ostream& fout);
+ void AddDSPBuildRule(cmTarget& tgt);
+ void WriteCustomRule(std::ostream& fout,
+ const char* source,
+ const cmCustomCommand& command,
+ const char* flags);
+ void AddUtilityCommandHack(cmTarget& target, int count,
+ std::vector<std::string>& depends,
+ const cmCustomCommand& origCommand);
+ void WriteGroup(const cmSourceGroup *sg, cmTarget& 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,
+ const std::string& configName,
+ const std::string& libName);
+ void ComputeLinkOptions(cmTarget& target, const std::string& configName,
+ const std::string extraOptions,
+ std::string& options);
+ void OutputObjects(cmTarget& target, const char* tool,
+ std::string& options);
+ std::string GetTargetIncludeOptions(cmTarget &target,
+ const std::string& config);
+ std::vector<std::string> Configurations;
+
+ std::string GetConfigName(std::string const& configuration) const;
+
+ // Special definition check for VS6.
+ virtual bool CheckDefinition(std::string const& define) const;
+};
+
+#endif
+
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
new file mode 100644
index 0000000000..eb4542391e
--- /dev/null
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -0,0 +1,2333 @@
+/*============================================================================
+ 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 "cmGlobalVisualStudio7Generator.h"
+#include "cmLocalVisualStudio7Generator.h"
+#include "cmXMLParser.h"
+#include <cm_expat.h>
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include "cmSourceFile.h"
+#include "cmCacheManager.h"
+#include "cmGeneratorTarget.h"
+#include "cmCustomCommandGenerator.h"
+#include "cmake.h"
+
+#include "cmComputeLinkInformation.h"
+#include "cmGeneratedFileStream.h"
+
+#include <cmsys/System.h>
+
+#include <ctype.h> // for isspace
+
+static bool cmLVS6G_IsFAT(const char* dir);
+
+class cmLocalVisualStudio7GeneratorInternals
+{
+public:
+ cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator* e):
+ 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);
+private:
+ cmLocalVisualStudio7Generator* LocalGenerator;
+};
+
+extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
+
+static void cmConvertToWindowsSlash(std::string& s)
+{
+ std::string::size_type pos = 0;
+ while((pos = s.find('/', pos)) != std::string::npos)
+ {
+ s[pos] = '\\';
+ pos++;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator(VSVersion v):
+ cmLocalVisualStudioGenerator(v)
+{
+ this->ExtraFlagTable = 0;
+ this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
+}
+
+cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
+{
+ delete this->Internal;
+}
+
+void cmLocalVisualStudio7Generator::AddHelperCommands()
+{
+ std::set<std::string> lang;
+ lang.insert("C");
+ lang.insert("CXX");
+ lang.insert("RC");
+ lang.insert("IDL");
+ lang.insert("DEF");
+ lang.insert("Fortran");
+ this->CreateCustomTargetsAndCommands(lang);
+
+ // Now create GUIDs for targets
+ cmTargets &tgts = this->Makefile->GetTargets();
+
+ cmGlobalVisualStudio7Generator* gg =
+ static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
+ for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
+ {
+ if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
+ if(path)
+ {
+ this->ReadAndStoreExternalGUID(
+ l->second.GetName().c_str(), path);
+ }
+ else
+ {
+ gg->CreateGUID(l->first.c_str());
+ }
+ }
+
+
+ this->FixGlobalTargets();
+}
+
+void cmLocalVisualStudio7Generator::Generate()
+{
+ this->WriteProjectFiles();
+ this->WriteStampFiles();
+}
+
+void cmLocalVisualStudio7Generator::AddCMakeListsRules()
+{
+ cmTargets &tgts = this->Makefile->GetTargets();
+ // Create the regeneration custom rule.
+ if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
+ {
+ // Create a rule to regenerate the build system when the target
+ // specification source changes.
+ if(cmSourceFile* sf = this->CreateVCProjBuildRule())
+ {
+ // Add the rule to targets that need it.
+ for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
+ {
+ if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
+ {
+ l->second.AddSource(sf->GetFullPath());
+ }
+ }
+ }
+ }
+}
+
+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();
+ l != tgts.end(); l++)
+ {
+ cmTarget& tgt = l->second;
+ if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
+ {
+ std::vector<std::string> no_depends;
+ cmCustomCommandLine force_command;
+ force_command.push_back("cd");
+ force_command.push_back(".");
+ cmCustomCommandLines force_commands;
+ force_commands.push_back(force_command);
+ std::string no_main_dependency = "";
+ std::string force = this->Makefile->GetStartOutputDirectory();
+ force += cmake::GetCMakeFilesDirectory();
+ force += "/";
+ force += tgt.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());
+ }
+ }
+ }
+}
+
+// TODO
+// for CommandLine= need to repleace quotes with &quot
+// write out configurations
+void cmLocalVisualStudio7Generator::WriteProjectFiles()
+{
+ // If not an in source build, then create the output directory
+ if(strcmp(this->Makefile->GetStartOutputDirectory(),
+ this->Makefile->GetHomeDirectory()) != 0)
+ {
+ if(!cmSystemTools::MakeDirectory
+ (this->Makefile->GetStartOutputDirectory()))
+ {
+ cmSystemTools::Error("Error creating directory ",
+ this->Makefile->GetStartOutputDirectory());
+ }
+ }
+
+ // Get the set of targets in this directory.
+ cmTargets &tgts = this->Makefile->GetTargets();
+
+ // Create the project file for each target.
+ for(cmTargets::iterator l = tgts.begin();
+ l != tgts.end(); l++)
+ {
+ if(l->second.GetType() == cmTarget::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"))
+ {
+ this->CreateSingleVCProj(l->first.c_str(),l->second);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalVisualStudio7Generator::WriteStampFiles()
+{
+ // Touch a timestamp file used to determine when the project file is
+ // out of date.
+ std::string stampName = this->Makefile->GetStartOutputDirectory();
+ stampName += cmake::GetCMakeFilesDirectory();
+ cmSystemTools::MakeDirectory(stampName.c_str());
+ stampName += "/";
+ stampName += "generate.stamp";
+ cmsys::ofstream stamp(stampName.c_str());
+ stamp << "# CMake generation timestamp file for this directory.\n";
+
+ // Create a helper file so CMake can determine when it is run
+ // through the rule created by CreateVCProjBuildRule whether it
+ // really needs to regenerate the project. This file lists its own
+ // dependencies. If any file listed in it is newer than itself then
+ // CMake must rerun. Otherwise the project files are up to date and
+ // the stamp file can just be touched.
+ std::string depName = stampName;
+ depName += ".depend";
+ cmsys::ofstream depFile(depName.c_str());
+ depFile << "# CMake generation dependency list for this directory.\n";
+ std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
+ for(std::vector<std::string>::const_iterator lf = listFiles.begin();
+ lf != listFiles.end(); ++lf)
+ {
+ depFile << *lf << std::endl;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalVisualStudio7Generator
+::CreateSingleVCProj(const std::string& lname, cmTarget &target)
+{
+ this->FortranProject =
+ static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
+ ->TargetIsFortranOnly(target);
+ this->WindowsCEProject =
+ static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
+ ->TargetsWindowsCE();
+
+ // Intel Fortran for VS10 uses VS9 format ".vfproj" files.
+ VSVersion realVersion = this->Version;
+ if(this->FortranProject && this->Version >= VS10)
+ {
+ this->Version = VS9;
+ }
+
+ // add to the list of projects
+ target.SetProperty("GENERATOR_FILE_NAME",lname.c_str());
+ // create the dsp.cmake file
+ std::string fname;
+ fname = this->Makefile->GetStartOutputDirectory();
+ fname += "/";
+ fname += lname;
+ if(this->FortranProject)
+ {
+ fname += ".vfproj";
+ }
+ else
+ {
+ fname += ".vcproj";
+ }
+
+ // Generate the project file and replace it atomically with
+ // copy-if-different. We use a separate timestamp so that the IDE
+ // does not reload project files unnecessarily.
+ cmGeneratedFileStream fout(fname.c_str());
+ fout.SetCopyIfDifferent(true);
+ this->WriteVCProjFile(fout,lname,target);
+ if (fout.Close())
+ {
+ this->GlobalGenerator->FileReplacedDuringGenerate(fname);
+ }
+
+ this->Version = realVersion;
+}
+
+//----------------------------------------------------------------------------
+cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
+{
+ std::string stampName = this->Makefile->GetCurrentOutputDirectory();
+ stampName += "/";
+ stampName += cmake::GetCMakeFilesDirectoryPostSlash();
+ stampName += "generate.stamp";
+ const char* dsprule =
+ this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
+ cmCustomCommandLine commandLine;
+ commandLine.push_back(dsprule);
+ std::string makefileIn = this->Makefile->GetStartDirectory();
+ makefileIn += "/";
+ makefileIn += "CMakeLists.txt";
+ makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
+ if(!cmSystemTools::FileExists(makefileIn.c_str()))
+ {
+ return 0;
+ }
+ std::string comment = "Building Custom Rule ";
+ comment += makefileIn;
+ std::string args;
+ args = "-H";
+ args += this->Convert(this->Makefile->GetHomeDirectory(),
+ START_OUTPUT, UNCHANGED, true);
+ commandLine.push_back(args);
+ args = "-B";
+ args +=
+ this->Convert(this->Makefile->GetHomeOutputDirectory(),
+ START_OUTPUT, UNCHANGED, true);
+ commandLine.push_back(args);
+ commandLine.push_back("--check-stamp-file");
+ std::string stampFilename = this->Convert(stampName.c_str(), FULL,
+ SHELL);
+ commandLine.push_back(stampFilename.c_str());
+
+ std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
+
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+ const char* no_working_directory = 0;
+ std::string fullpathStampName = this->Convert(stampName.c_str(), FULL,
+ UNCHANGED);
+ this->Makefile->AddCustomCommandToOutput(fullpathStampName.c_str(),
+ listFiles, makefileIn.c_str(),
+ commandLines, comment.c_str(),
+ no_working_directory, true);
+ if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
+ {
+ return file;
+ }
+ else
+ {
+ cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
+ return 0;
+ }
+}
+
+void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
+ const std::string& libName,
+ cmTarget &target)
+{
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+
+ fout << "\t<Configurations>\n";
+ for( std::vector<std::string>::iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ this->WriteConfiguration(fout, i->c_str(), libName, target);
+ }
+ fout << "\t</Configurations>\n";
+}
+cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable[] =
+{
+ {"Preprocess", "fpp", "Run Preprocessor on files", "preprocessYes", 0},
+ {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
+ {"SourceFileFormat", "fixed", "Use Fixed Format", "fileFormatFixed", 0},
+ {"SourceFileFormat", "free", "Use Free Format", "fileFormatFree", 0},
+ {"DebugInformationFormat", "Zi", "full debug", "debugEnabled", 0},
+ {"DebugInformationFormat", "debug:full", "full debug", "debugEnabled", 0},
+ {"DebugInformationFormat", "Z7", "c7 compat", "debugOldStyleInfo", 0},
+ {"DebugInformationFormat", "Zd", "line numbers", "debugLineInfoOnly", 0},
+ {"Optimization", "Od", "disable optimization", "optimizeDisabled", 0},
+ {"Optimization", "O1", "min space", "optimizeMinSpace", 0},
+ {"Optimization", "O3", "full optimize", "optimizeFull", 0},
+ {"GlobalOptimizations", "Og", "global optimize", "true", 0},
+ {"InlineFunctionExpansion", "Ob0", "", "expandDisable", 0},
+ {"InlineFunctionExpansion", "Ob1", "", "expandOnlyInline", 0},
+ {"FavorSizeOrSpeed", "Os", "", "favorSize", 0},
+ {"OmitFramePointers", "Oy-", "", "false", 0},
+ {"OptimizeForProcessor", "GB", "", "procOptimizeBlended", 0},
+ {"OptimizeForProcessor", "G5", "", "procOptimizePentium", 0},
+ {"OptimizeForProcessor", "G6", "", "procOptimizePentiumProThruIII", 0},
+ {"UseProcessorExtensions", "QzxK", "", "codeForStreamingSIMD", 0},
+ {"OptimizeForProcessor", "QaxN", "", "codeForPentium4", 0},
+ {"OptimizeForProcessor", "QaxB", "", "codeForPentiumM", 0},
+ {"OptimizeForProcessor", "QaxP", "", "codeForCodeNamedPrescott", 0},
+ {"OptimizeForProcessor", "QaxT", "", "codeForCore2Duo", 0},
+ {"OptimizeForProcessor", "QxK", "", "codeExclusivelyStreamingSIMD", 0},
+ {"OptimizeForProcessor", "QxN", "", "codeExclusivelyPentium4", 0},
+ {"OptimizeForProcessor", "QxB", "", "codeExclusivelyPentiumM", 0},
+ {"OptimizeForProcessor", "QxP", "", "codeExclusivelyCodeNamedPrescott", 0},
+ {"OptimizeForProcessor", "QxT", "", "codeExclusivelyCore2Duo", 0},
+ {"OptimizeForProcessor", "QxO", "", "codeExclusivelyCore2StreamingSIMD", 0},
+ {"OptimizeForProcessor", "QxS", "", "codeExclusivelyCore2StreamingSIMD4", 0},
+
+ {"ModulePath", "module:", "", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"LoopUnrolling", "Qunroll:", "", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"AutoParallelThreshold", "Qpar-threshold:", "", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"HeapArrays", "heap-arrays:", "", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"ObjectText", "bintext:", "", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"Parallelization", "Qparallel", "", "true", 0},
+ {"PrefetchInsertion", "Qprefetch-", "", "false", 0},
+ {"BufferedIO", "assume:buffered_io", "", "true", 0},
+ {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
+ {"CallingConvention", "iface:cref", "", "callConventionCRef", 0},
+ {"CallingConvention", "iface:stdref", "", "callConventionStdRef", 0},
+ {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
+ {"CallingConvention", "iface:cvf", "", "callConventionCVF", 0},
+ {"EnableRecursion", "recursive", "", "true", 0},
+ {"ReentrantCode", "reentrancy", "", "true", 0},
+ // done up to Language
+ {0,0,0,0,0}
+};
+// fill the table here currently the comment field is not used for
+// anything other than documentation NOTE: Make sure the longer
+// commandFlag comes FIRST!
+cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
+{
+ // option flags (some flags map to the same option)
+ {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
+ {"BasicRuntimeChecks", "RTCsu",
+ "Both stack and uninitialized checks", "3", 0},
+ {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
+ {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
+ {"BasicRuntimeChecks", "RTC1",
+ "Both stack and uninitialized checks", "3", 0},
+ {"DebugInformationFormat", "Z7", "debug format", "1", 0},
+ {"DebugInformationFormat", "Zd", "debug format", "2", 0},
+ {"DebugInformationFormat", "Zi", "debug format", "3", 0},
+ {"DebugInformationFormat", "ZI", "debug format", "4", 0},
+ {"EnableEnhancedInstructionSet", "arch:SSE2",
+ "Use sse2 instructions", "2", 0},
+ {"EnableEnhancedInstructionSet", "arch:SSE",
+ "Use sse instructions", "1", 0},
+ {"FloatingPointModel", "fp:precise",
+ "Use precise floating point model", "0", 0},
+ {"FloatingPointModel", "fp:strict",
+ "Use strict floating point model", "1", 0},
+ {"FloatingPointModel", "fp:fast", "Use fast floating point model", "2", 0},
+ {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
+ {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
+ {"CompileAs", "TC", "Compile as c code", "1", 0},
+ {"CompileAs", "TP", "Compile as c++ code", "2", 0},
+ {"Optimization", "Od", "Non Debug", "0", 0},
+ {"Optimization", "O1", "Min Size", "1", 0},
+ {"Optimization", "O2", "Max Speed", "2", 0},
+ {"Optimization", "Ox", "Max Optimization", "3", 0},
+ {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
+ {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
+ {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
+ {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
+ {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
+ {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
+ {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
+ {"RuntimeLibrary", "MTd", "Multithreaded debug", "1", 0},
+ {"RuntimeLibrary", "MT", "Multithreaded", "0", 0},
+ {"RuntimeLibrary", "MDd", "Multithreaded dll debug", "3", 0},
+ {"RuntimeLibrary", "MD", "Multithreaded dll", "2", 0},
+ {"RuntimeLibrary", "MLd", "Single Thread debug", "5", 0},
+ {"RuntimeLibrary", "ML", "Single Thread", "4", 0},
+ {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
+ {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
+ {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
+ {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
+ {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
+ {"WarningLevel", "W0", "Warning level", "0", 0},
+ {"WarningLevel", "W1", "Warning level", "1", 0},
+ {"WarningLevel", "W2", "Warning level", "2", 0},
+ {"WarningLevel", "W3", "Warning level", "3", 0},
+ {"WarningLevel", "W4", "Warning level", "4", 0},
+ {"DisableSpecificWarnings", "wd", "Disable specific warnings", "",
+ cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ // Precompiled header and related options. Note that the
+ // UsePrecompiledHeader entries are marked as "Continue" so that the
+ // corresponding PrecompiledHeaderThrough entry can be found.
+ {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
+ cmVS7FlagTable::UserValue},
+ // The YX and Yu options are in a per-global-generator table because
+ // their values differ based on the VS IDE version.
+ {"ForcedIncludeFiles", "FI", "Forced include files", "",
+ cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SemicolonAppendable},
+
+ {"AssemblerListingLocation", "Fa", "ASM List Location", "",
+ cmVS7FlagTable::UserValue},
+ {"ProgramDataBaseFileName", "Fd", "Program Database File Name", "",
+ cmVS7FlagTable::UserValue},
+
+ // boolean flags
+ {"BufferSecurityCheck", "GS", "Buffer security check", "true", 0},
+ {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "false", 0},
+ {"Detect64BitPortabilityProblems", "Wp64",
+ "Detect 64-bit Portability Problems", "true", 0},
+ {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
+ "true", 0},
+ {"EnableFunctionLevelLinking", "Gy",
+ "EnableFunctionLevelLinking", "true", 0},
+ {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "true", 0},
+ {"GlobalOptimizations", "Og", "Global Optimize", "true", 0},
+ {"ImproveFloatingPointConsistency", "Op",
+ "ImproveFloatingPointConsistency", "true", 0},
+ {"MinimalRebuild", "Gm", "minimal rebuild", "true", 0},
+ {"OmitFramePointers", "Oy", "OmitFramePointers", "true", 0},
+ {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "true", 0},
+ {"RuntimeTypeInfo", "GR",
+ "Turn on Run time type information for c++", "true", 0},
+ {"RuntimeTypeInfo", "GR-",
+ "Turn off Run time type information for c++", "false", 0},
+ {"SmallerTypeCheck", "RTCc", "smaller type check", "true", 0},
+ {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
+ {"WholeProgramOptimization", "GL",
+ "Enables whole program optimization", "true", 0},
+ {"WholeProgramOptimization", "GL-",
+ "Disables whole program optimization", "false", 0},
+ {"WarnAsError", "WX", "Treat warnings as errors", "true", 0},
+ {"BrowseInformation", "FR", "Generate browse information", "1", 0},
+ {"StringPooling", "GF", "Enable StringPooling", "true", 0},
+ {0,0,0,0,0}
+};
+
+
+
+cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
+{
+ // option flags (some flags map to the same option)
+ {"GenerateManifest", "MANIFEST:NO",
+ "disable manifest generation", "false", 0},
+ {"GenerateManifest", "MANIFEST", "enable manifest generation", "true", 0},
+ {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
+ {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
+ {"DataExecutionPrevention", "NXCOMPAT:NO",
+ "Not known to work with Windows Data Execution Prevention", "1", 0},
+ {"DataExecutionPrevention", "NXCOMPAT",
+ "Known to work with Windows Data Execution Prevention", "2", 0},
+ {"DelaySign", "DELAYSIGN:NO", "", "false", 0},
+ {"DelaySign", "DELAYSIGN", "", "true", 0},
+ {"EntryPointSymbol", "ENTRY:", "sets the starting address", "",
+ cmVS7FlagTable::UserValue},
+ {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
+ cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
+ "true", 0},
+ {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
+ {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
+ "2", 0},
+ {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
+ "1", 0},
+ {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
+ {"ResourceOnlyDLL", "NOENTRY", "Create DLL with no entry point", "true", 0},
+ {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
+ {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
+ {"Profile", "PROFILE", "", "true", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE:NO",
+ "Image may not be rebased at load-time", "1", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE",
+ "Image may be rebased at load-time", "2", 0},
+ {"SetChecksum", "RELEASE", "Enable setting checksum in header", "true", 0},
+ {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
+ {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
+ {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
+ {"TargetMachine", "MACHINE:AM33", "Machine AM33", "2", 0},
+ {"TargetMachine", "MACHINE:ARM", "Machine ARM", "3", 0},
+ {"TargetMachine", "MACHINE:EBC", "Machine EBC", "4", 0},
+ {"TargetMachine", "MACHINE:IA64", "Machine IA64", "5", 0},
+ {"TargetMachine", "MACHINE:M32R", "Machine M32R", "6", 0},
+ {"TargetMachine", "MACHINE:MIPS", "Machine MIPS", "7", 0},
+ {"TargetMachine", "MACHINE:MIPS16", "Machine MIPS16", "8", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU)", "Machine MIPSFPU", "9", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU16", "Machine MIPSFPU16", "10", 0},
+ {"TargetMachine", "MACHINE:MIPSR41XX", "Machine MIPSR41XX", "11", 0},
+ {"TargetMachine", "MACHINE:SH3", "Machine SH3", "12", 0},
+ {"TargetMachine", "MACHINE:SH3DSP", "Machine SH3DSP", "13", 0},
+ {"TargetMachine", "MACHINE:SH4", "Machine SH4", "14", 0},
+ {"TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0},
+ {"TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0},
+ {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
+ {"TurnOffAssemblyGeneration", "NOASSEMBLY",
+ "No assembly even if CLR information is present in objects.", "true", 0},
+ {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
+ cmVS7FlagTable::UserValue},
+ {"GenerateMapFile", "MAP", "enable generation of map file", "true", 0},
+ {0,0,0,0,0}
+};
+
+//----------------------------------------------------------------------------
+// Helper class to write build event <Tool .../> elements.
+class cmLocalVisualStudio7Generator::EventWriter
+{
+public:
+ EventWriter(cmLocalVisualStudio7Generator* lg,
+ const std::string& config, std::ostream& os):
+ LG(lg), Config(config), Stream(os), First(true) {}
+ void Start(const char* tool)
+ {
+ this->First = true;
+ this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
+ }
+ void Finish()
+ {
+ this->Stream << (this->First? "" : "\"") << "/>\n";
+ }
+ void Write(std::vector<cmCustomCommand> const& ccs)
+ {
+ for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
+ ci != ccs.end(); ++ci)
+ {
+ this->Write(*ci);
+ }
+ }
+ void Write(cmCustomCommand const& cc)
+ {
+ cmCustomCommandGenerator ccg(cc, this->Config, this->LG->GetMakefile());
+ if(this->First)
+ {
+ const char* comment = ccg.GetComment();
+ if(comment && *comment)
+ {
+ this->Stream << "\nDescription=\""
+ << this->LG->EscapeForXML(comment) << "\"";
+ }
+ this->Stream << "\nCommandLine=\"";
+ this->First = false;
+ }
+ else
+ {
+ this->Stream << this->LG->EscapeForXML("\n");
+ }
+ std::string script = this->LG->ConstructScript(ccg);
+ this->Stream << this->LG->EscapeForXML(script.c_str());
+ }
+private:
+ cmLocalVisualStudio7Generator* LG;
+ std::string Config;
+ std::ostream& Stream;
+ bool First;
+};
+
+//----------------------------------------------------------------------------
+void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
+ const std::string& configName,
+ const std::string& libName,
+ cmTarget &target)
+{
+ const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
+ if(!mfcFlag)
+ {
+ mfcFlag = "0";
+ }
+ cmGlobalVisualStudio7Generator* gg =
+ static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
+ fout << "\t\t<Configuration\n"
+ << "\t\t\tName=\"" << configName
+ << "|" << gg->GetPlatformName() << "\"\n"
+ << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
+ // This is an internal type to Visual Studio, it seems that:
+ // 4 == static library
+ // 2 == dll
+ // 1 == executable
+ // 10 == utility
+ const char* configType = "10";
+ const char* projectType = 0;
+ bool targetBuilds = true;
+ switch(target.GetType())
+ {
+ case cmTarget::OBJECT_LIBRARY:
+ targetBuilds = false; // no manifest tool for object library
+ case cmTarget::STATIC_LIBRARY:
+ projectType = "typeStaticLibrary";
+ configType = "4";
+ break;
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ projectType = "typeDynamicLibrary";
+ configType = "2";
+ break;
+ case cmTarget::EXECUTABLE:
+ configType = "1";
+ break;
+ case cmTarget::UTILITY:
+ case cmTarget::GLOBAL_TARGET:
+ configType = "10";
+ default:
+ targetBuilds = false;
+ break;
+ }
+ if(this->FortranProject && projectType)
+ {
+ configType = projectType;
+ }
+ std::string flags;
+ if(strcmp(configType, "10") != 0)
+ {
+ const std::string& linkLanguage = (this->FortranProject?
+ std::string("Fortran"):
+ target.GetLinkerLanguage(configName));
+ if(linkLanguage.empty())
+ {
+ cmSystemTools::Error
+ ("CMake can not determine linker language for target: ",
+ target.GetName().c_str());
+ return;
+ }
+ if(linkLanguage == "C" || linkLanguage == "CXX"
+ || linkLanguage == "Fortran")
+ {
+ std::string baseFlagVar = "CMAKE_";
+ baseFlagVar += linkLanguage;
+ baseFlagVar += "_FLAGS";
+ flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
+ std::string flagVar = baseFlagVar + std::string("_") +
+ cmSystemTools::UpperCase(configName);
+ flags += " ";
+ flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
+ }
+ // set the correct language
+ if(linkLanguage == "C")
+ {
+ flags += " /TC ";
+ }
+ if(linkLanguage == "CXX")
+ {
+ flags += " /TP ";
+ }
+
+ // Add the target-specific flags.
+ this->AddCompileOptions(flags, &target, linkLanguage, configName);
+ }
+
+ if(this->FortranProject)
+ {
+ switch(this->GetFortranFormat(target.GetProperty("Fortran_FORMAT")))
+ {
+ case FortranFormatFixed: flags += " -fixed"; break;
+ case FortranFormatFree: flags += " -free"; break;
+ default: break;
+ }
+ }
+
+ // Get preprocessor definitions for this directory.
+ std::string defineFlags = this->Makefile->GetDefineFlags();
+ Options::Tool t = Options::Compiler;
+ cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
+ if(this->FortranProject)
+ {
+ t = Options::FortranCompiler;
+ table = cmLocalVisualStudio7GeneratorFortranFlagTable;
+ }
+ Options targetOptions(this, t,
+ table,
+ this->ExtraFlagTable);
+ targetOptions.FixExceptionHandlingDefault();
+ std::string asmLocation = configName + "/";
+ targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
+ targetOptions.Parse(flags.c_str());
+ targetOptions.Parse(defineFlags.c_str());
+ targetOptions.ParseFinish();
+ cmGeneratorTarget* gt =
+ this->GlobalGenerator->GetGeneratorTarget(&target);
+ std::vector<std::string> targetDefines;
+ target.GetCompileDefinitions(targetDefines, configName);
+ targetOptions.AddDefines(targetDefines);
+ targetOptions.SetVerboseMakefile(
+ this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
+
+ // Add a definition for the configuration name.
+ std::string configDefine = "CMAKE_INTDIR=\"";
+ configDefine += configName;
+ configDefine += "\"";
+ targetOptions.AddDefine(configDefine);
+
+ // Add the export symbol definition for shared library objects.
+ if(const char* exportMacro = target.GetExportMacro())
+ {
+ targetOptions.AddDefine(exportMacro);
+ }
+
+ // The intermediate directory name consists of a directory for the
+ // target and a subdirectory for the configuration name.
+ std::string intermediateDir = this->GetTargetDirectory(target);
+ intermediateDir += "/";
+ intermediateDir += configName;
+ fout << "\t\t\tIntermediateDirectory=\""
+ << this->ConvertToXMLOutputPath(intermediateDir.c_str())
+ << "\"\n"
+ << "\t\t\tConfigurationType=\"" << configType << "\"\n"
+ << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
+ << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
+
+ if (this->FortranProject)
+ {
+ // Intel Fortran >= 15.0 uses TargetName property.
+ std::string targetNameFull = target.GetFullName(configName);
+ std::string targetName =
+ cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
+ std::string targetExt =
+ cmSystemTools::GetFilenameLastExtension(targetNameFull);
+ fout <<
+ "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n"
+ "\t\t\tTargetExt=\"" << this->EscapeForXML(targetExt) << "\"\n"
+ ;
+ }
+
+ // If unicode is enabled change the character set to unicode, if not
+ // then default to MBCS.
+ if(targetOptions.UsingUnicode())
+ {
+ fout << "\t\t\tCharacterSet=\"1\">\n";
+ }
+ else if(targetOptions.UsingSBCS())
+ {
+ fout << "\t\t\tCharacterSet=\"0\">\n";
+ }
+ else
+ {
+ fout << "\t\t\tCharacterSet=\"2\">\n";
+ }
+ const char* tool = "VCCLCompilerTool";
+ if(this->FortranProject)
+ {
+ tool = "VFFortranCompilerTool";
+ }
+ fout << "\t\t\t<Tool\n"
+ << "\t\t\t\tName=\"" << tool << "\"\n";
+ if(this->FortranProject)
+ {
+ const char* target_mod_dir =
+ target.GetProperty("Fortran_MODULE_DIRECTORY");
+ std::string modDir;
+ if(target_mod_dir)
+ {
+ modDir = this->Convert(target_mod_dir,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED);
+ }
+ else
+ {
+ modDir = ".";
+ }
+ fout << "\t\t\t\tModulePath=\""
+ << this->ConvertToXMLOutputPath(modDir.c_str())
+ << "\\$(ConfigurationName)\"\n";
+ }
+ targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
+ fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
+ std::vector<std::string> includes;
+ this->GetIncludeDirectories(includes, gt, "C", configName);
+ std::vector<std::string>::iterator i = includes.begin();
+ for(;i != includes.end(); ++i)
+ {
+ // output the include path
+ std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
+ fout << ipath << ";";
+ // if this is fortran then output the include with
+ // a ConfigurationName on the end of it.
+ if(this->FortranProject)
+ {
+ ipath = i->c_str();
+ ipath += "/$(ConfigurationName)";
+ ipath = this->ConvertToXMLOutputPath(ipath.c_str());
+ fout << ipath << ";";
+ }
+ }
+ fout << "\"\n";
+ 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)
+ {
+ // Specify the compiler program database file if configured.
+ std::string pdb = target.GetCompilePDBPath(configName);
+ if(!pdb.empty())
+ {
+ fout << "\t\t\t\tProgramDataBaseFileName=\""
+ << this->ConvertToXMLOutputPathSingle(pdb.c_str())
+ << "\"\n";
+ }
+ }
+ fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
+ if(gg->IsMasmEnabled() && !this->FortranProject)
+ {
+ Options masmOptions(this, Options::MasmCompiler, 0, 0);
+ fout <<
+ "\t\t\t<Tool\n"
+ "\t\t\t\tName=\"MASM\"\n"
+ "\t\t\t\tIncludePaths=\""
+ ;
+ const char* sep = "";
+ for(i = includes.begin(); i != includes.end(); ++i)
+ {
+ std::string inc = *i;
+ cmConvertToWindowsSlash(inc);
+ fout << sep << this->EscapeForXML(inc);
+ sep = ";";
+ }
+ fout << "\"\n";
+ // Use same preprocessor definitions as VCCLCompilerTool.
+ targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
+ "ASM_MASM");
+ masmOptions.OutputFlagMap(fout, "\t\t\t\t");
+ fout <<
+ "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
+ "\t\t\t/>\n";
+ }
+ tool = "VCCustomBuildTool";
+ if(this->FortranProject)
+ {
+ tool = "VFCustomBuildTool";
+ }
+ fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
+ tool = "VCResourceCompilerTool";
+ if(this->FortranProject)
+ {
+ tool = "VFResourceCompilerTool";
+ }
+ fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
+ << "\t\t\t\tAdditionalIncludeDirectories=\"";
+ for(i = includes.begin();i != includes.end(); ++i)
+ {
+ std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
+ fout << ipath << ";";
+ }
+ // add the -D flags to the RC tool
+ fout << "\"";
+ targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
+ fout << "/>\n";
+ tool = "VCMIDLTool";
+ if(this->FortranProject)
+ {
+ tool = "VFMIDLTool";
+ }
+ fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
+ fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
+ for(i = includes.begin(); i != includes.end(); ++i)
+ {
+ std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
+ fout << ipath << ";";
+ }
+ fout << "\"\n";
+ fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
+ if( gg->GetPlatformName() == "x64" )
+ {
+ fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
+ }
+ else if( gg->GetPlatformName() == "ia64" )
+ {
+ fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
+ }
+ else
+ {
+ fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
+ }
+ fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
+ fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
+ fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
+ fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
+ fout << "\t\t\t\tDLLDataFileName=\"\"\n";
+ fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
+ fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
+ // end of <Tool Name=VCMIDLTool
+
+ // Check if we need the FAT32 workaround.
+ if(targetBuilds && this->Version >= VS8)
+ {
+ // Check the filesystem type where the target will be written.
+ 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
+ // to be embedded into the resulting executable. See CMake
+ // bug #2617.
+ const char* manifestTool = "VCManifestTool";
+ if(this->FortranProject)
+ {
+ manifestTool = "VFManifestTool";
+ }
+ fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << manifestTool << "\"\n"
+ << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
+ << "\t\t\t/>\n";
+ }
+ }
+
+ this->OutputTargetRules(fout, configName, target, libName);
+ this->OutputBuildTool(fout, configName, target, targetOptions);
+ fout << "\t\t</Configuration>\n";
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalVisualStudio7Generator
+::GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
+ const std::string& configName)
+{
+ std::string configTypeUpper = cmSystemTools::UpperCase(configName);
+ std::string extraLinkOptionsBuildTypeDef =
+ rootLinkerFlags + "_" + configTypeUpper;
+
+ std::string extraLinkOptionsBuildType =
+ this->Makefile->GetRequiredDefinition
+ (extraLinkOptionsBuildTypeDef.c_str());
+
+ return extraLinkOptionsBuildType;
+}
+
+void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
+ const std::string& configName, cmTarget &target,
+ const Options& targetOptions)
+{
+ cmGlobalVisualStudio7Generator* gg =
+ static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
+ std::string temp;
+ std::string extraLinkOptions;
+ if(target.GetType() == cmTarget::EXECUTABLE)
+ {
+ extraLinkOptions =
+ this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
+ + std::string(" ")
+ + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
+ }
+ if(target.GetType() == cmTarget::SHARED_LIBRARY)
+ {
+ extraLinkOptions =
+ this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
+ + std::string(" ")
+ + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
+ }
+ if(target.GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ extraLinkOptions =
+ this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
+ + std::string(" ")
+ + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
+ }
+
+ const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
+ if(targetLinkFlags)
+ {
+ extraLinkOptions += " ";
+ extraLinkOptions += targetLinkFlags;
+ }
+ std::string configTypeUpper = cmSystemTools::UpperCase(configName);
+ std::string linkFlagsConfig = "LINK_FLAGS_";
+ linkFlagsConfig += configTypeUpper;
+ targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
+ if(targetLinkFlags)
+ {
+ extraLinkOptions += " ";
+ extraLinkOptions += targetLinkFlags;
+ }
+ Options linkOptions(this, Options::Linker,
+ cmLocalVisualStudio7GeneratorLinkFlagTable);
+ linkOptions.Parse(extraLinkOptions.c_str());
+ if(!this->ModuleDefinitionFile.empty())
+ {
+ std::string defFile =
+ this->ConvertToOptionallyRelativeOutputPath(this->ModuleDefinitionFile);
+ linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
+ }
+ switch(target.GetType())
+ {
+ case cmTarget::UNKNOWN_LIBRARY:
+ break;
+ case cmTarget::OBJECT_LIBRARY:
+ {
+ std::string libpath = this->GetTargetDirectory(target);
+ libpath += "/";
+ libpath += configName;
+ libpath += "/";
+ libpath += target.GetName();
+ libpath += ".lib";
+ const char* tool =
+ this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
+ fout << "\t\t\t<Tool\n"
+ << "\t\t\t\tName=\"" << tool << "\"\n";
+ fout << "\t\t\t\tOutputFile=\""
+ << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
+ break;
+ }
+ case cmTarget::STATIC_LIBRARY:
+ {
+ std::string targetNameFull = target.GetFullName(configName);
+ std::string libpath = target.GetDirectory(configName);
+ libpath += "/";
+ libpath += targetNameFull;
+ const char* tool = "VCLibrarianTool";
+ if(this->FortranProject)
+ {
+ tool = "VFLibrarianTool";
+ }
+ fout << "\t\t\t<Tool\n"
+ << "\t\t\t\tName=\"" << tool << "\"\n";
+
+ if(this->GetVersion() < VS8 || this->FortranProject)
+ {
+ cmOStringStream libdeps;
+ 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);
+ if(!libflags.empty())
+ {
+ fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
+ }
+ fout << "\t\t\t\tOutputFile=\""
+ << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
+ break;
+ }
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ {
+ std::string targetName;
+ std::string targetNameSO;
+ std::string targetNameFull;
+ std::string targetNameImport;
+ std::string targetNamePDB;
+ target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
+ targetNameImport, targetNamePDB, configName);
+
+ // Compute the link library and directory information.
+ cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
+ if(!pcli)
+ {
+ return;
+ }
+ cmComputeLinkInformation& cli = *pcli;
+ std::string linkLanguage = cli.GetLinkLanguage();
+
+ // Compute the variable name to lookup standard libraries for this
+ // language.
+ std::string standardLibsVar = "CMAKE_";
+ standardLibsVar += linkLanguage;
+ standardLibsVar += "_STANDARD_LIBRARIES";
+ const char* tool = "VCLinkerTool";
+ if(this->FortranProject)
+ {
+ tool = "VFLinkerTool";
+ }
+ fout << "\t\t\t<Tool\n"
+ << "\t\t\t\tName=\"" << tool << "\"\n";
+ if(!gg->NeedLinkLibraryDependencies(target))
+ {
+ fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
+ }
+ linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
+ // Use the NOINHERIT macro to avoid getting VS project default
+ // libraries which may be set by the user to something bad.
+ fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
+ << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
+ if(this->GetVersion() < VS8 || this->FortranProject)
+ {
+ this->Internal->OutputObjects(fout, &target, " ");
+ }
+ fout << " ";
+ this->Internal->OutputLibraries(fout, cli.GetItems());
+ fout << "\"\n";
+ temp = target.GetDirectory(configName);
+ temp += "/";
+ temp += targetNameFull;
+ fout << "\t\t\t\tOutputFile=\""
+ << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
+ this->WriteTargetVersionAttribute(fout, target);
+ linkOptions.OutputFlagMap(fout, "\t\t\t\t");
+ fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
+ this->OutputLibraryDirectories(fout, cli.GetDirectories());
+ fout << "\"\n";
+ temp = target.GetPDBDirectory(configName);
+ temp += "/";
+ temp += targetNamePDB;
+ fout << "\t\t\t\tProgramDatabaseFile=\"" <<
+ this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
+ if(targetOptions.IsDebug())
+ {
+ fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
+ }
+ if(this->WindowsCEProject)
+ {
+ if(this->GetVersion() < VS9)
+ {
+ fout << "\t\t\t\tSubSystem=\"9\"\n";
+ }
+ else
+ {
+ fout << "\t\t\t\tSubSystem=\"8\"\n";
+ }
+ }
+ std::string stackVar = "CMAKE_";
+ stackVar += linkLanguage;
+ stackVar += "_STACK_SIZE";
+ const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
+ if(stackVal)
+ {
+ fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
+ }
+ temp = target.GetDirectory(configName, true);
+ temp += "/";
+ temp += targetNameImport;
+ fout << "\t\t\t\tImportLibrary=\""
+ << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
+ if(this->FortranProject)
+ {
+ fout << "\n\t\t\t\tLinkDLL=\"true\"";
+ }
+ fout << "/>\n";
+ }
+ break;
+ case cmTarget::EXECUTABLE:
+ {
+ std::string targetName;
+ std::string targetNameFull;
+ std::string targetNameImport;
+ std::string targetNamePDB;
+ target.GetExecutableNames(targetName, targetNameFull,
+ targetNameImport, targetNamePDB, configName);
+
+ // Compute the link library and directory information.
+ cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
+ if(!pcli)
+ {
+ return;
+ }
+ cmComputeLinkInformation& cli = *pcli;
+ std::string linkLanguage = cli.GetLinkLanguage();
+
+ bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE");
+
+ // Compute the variable name to lookup standard libraries for this
+ // language.
+ std::string standardLibsVar = "CMAKE_";
+ standardLibsVar += linkLanguage;
+ standardLibsVar += "_STANDARD_LIBRARIES";
+ const char* tool = "VCLinkerTool";
+ if(this->FortranProject)
+ {
+ tool = "VFLinkerTool";
+ }
+ fout << "\t\t\t<Tool\n"
+ << "\t\t\t\tName=\"" << tool << "\"\n";
+ if(!gg->NeedLinkLibraryDependencies(target))
+ {
+ fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
+ }
+ linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
+ // Use the NOINHERIT macro to avoid getting VS project default
+ // libraries which may be set by the user to something bad.
+ fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
+ << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
+ if(this->GetVersion() < VS8 || this->FortranProject)
+ {
+ this->Internal->OutputObjects(fout, &target, " ");
+ }
+ fout << " ";
+ this->Internal->OutputLibraries(fout, cli.GetItems());
+ fout << "\"\n";
+ temp = target.GetDirectory(configName);
+ temp += "/";
+ temp += targetNameFull;
+ fout << "\t\t\t\tOutputFile=\""
+ << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
+ this->WriteTargetVersionAttribute(fout, target);
+ linkOptions.OutputFlagMap(fout, "\t\t\t\t");
+ fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
+ this->OutputLibraryDirectories(fout, cli.GetDirectories());
+ fout << "\"\n";
+ std::string path = this->ConvertToXMLOutputPathSingle(
+ target.GetPDBDirectory(configName).c_str());
+ fout << "\t\t\t\tProgramDatabaseFile=\""
+ << path << "/" << targetNamePDB
+ << "\"\n";
+ if(targetOptions.IsDebug())
+ {
+ fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
+ }
+ if ( this->WindowsCEProject )
+ {
+ if(this->GetVersion() < VS9)
+ {
+ fout << "\t\t\t\tSubSystem=\"9\"\n";
+ }
+ else
+ {
+ fout << "\t\t\t\tSubSystem=\"8\"\n";
+ }
+
+ if(!linkOptions.GetFlag("EntryPointSymbol"))
+ {
+ const char* entryPointSymbol = targetOptions.UsingUnicode() ?
+ (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup") :
+ (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
+ fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
+ }
+ }
+ else if ( this->FortranProject )
+ {
+ fout << "\t\t\t\tSubSystem=\""
+ << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
+ << "\"\n";
+ }
+ else
+ {
+ fout << "\t\t\t\tSubSystem=\""
+ << (isWin32Executable ? "2" : "1")
+ << "\"\n";
+ }
+ std::string stackVar = "CMAKE_";
+ stackVar += linkLanguage;
+ stackVar += "_STACK_SIZE";
+ const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
+ if(stackVal)
+ {
+ fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
+ }
+ 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:
+ break;
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalVisualStudio7Generator
+::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
+{
+ int major;
+ int minor;
+ target.GetTargetVersion(major, minor);
+ fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalVisualStudio7GeneratorInternals
+::OutputLibraries(std::ostream& fout, ItemVector const& libs)
+{
+ cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
+ for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
+ {
+ if(l->IsPath)
+ {
+ std::string rel = lg->Convert(l->Value.c_str(),
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED);
+ fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
+ }
+ else if (!l->Target
+ || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ fout << l->Value << " ";
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalVisualStudio7GeneratorInternals
+::OutputObjects(std::ostream& fout, cmTarget* t, 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 : "";
+ for(std::vector<std::string>::const_iterator
+ oi = objs.begin(); oi != objs.end(); ++oi)
+ {
+ std::string rel = lg->Convert(oi->c_str(),
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED);
+ fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
+ sep = " ";
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmLocalVisualStudio7Generator
+::OutputLibraryDirectories(std::ostream& fout,
+ std::vector<std::string> const& dirs)
+{
+ const char* comma = "";
+ for(std::vector<std::string>::const_iterator d = dirs.begin();
+ d != dirs.end(); ++d)
+ {
+ // Remove any trailing slash and skip empty paths.
+ std::string dir = *d;
+ if(dir[dir.size()-1] == '/')
+ {
+ dir = dir.substr(0, dir.size()-1);
+ }
+ if(dir.empty())
+ {
+ continue;
+ }
+
+ // Switch to a relative path specification if it is shorter.
+ if(cmSystemTools::FileIsFullPath(dir.c_str()))
+ {
+ std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
+ if(rel.size() < dir.size())
+ {
+ dir = rel;
+ }
+ }
+
+ // First search a configuration-specific subdirectory and then the
+ // original directory.
+ fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
+ << "," << this->ConvertToXMLOutputPath(dir.c_str());
+ comma = ",";
+ }
+}
+
+void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
+ const std::string& libName,
+ cmTarget &target)
+{
+ // get the configurations
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+
+ // We may be modifying the source groups temporarily, so make a copy.
+ std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
+
+ // get the classes from the source lists then add them to the groups
+ this->ModuleDefinitionFile = "";
+ std::vector<cmSourceFile*> classes;
+ if (!target.GetConfigCommonSourceFiles(classes))
+ {
+ return;
+ }
+ for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
+ i != classes.end(); i++)
+ {
+ if (!(*i)->GetObjectLibrary().empty())
+ {
+ continue;
+ }
+ // Add the file to the list of sources.
+ std::string source = (*i)->GetFullPath();
+ if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
+ {
+ this->ModuleDefinitionFile = (*i)->GetFullPath();
+ }
+ cmSourceGroup* sourceGroup =
+ this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
+ sourceGroup->AssignSource(*i);
+ }
+
+ // open the project
+ this->WriteProjectStart(fout, libName, target, sourceGroups);
+ // write the configuration information
+ this->WriteConfigurations(fout, libName, target);
+
+ fout << "\t<Files>\n";
+
+
+ // Loop through every source group.
+ for(unsigned int i = 0; i < sourceGroups.size(); ++i)
+ {
+ cmSourceGroup sg = sourceGroups[i];
+ this->WriteGroup(&sg, target, fout, libName, configs);
+ }
+
+ if(this->GetVersion() >= VS8 && !this->FortranProject)
+ {
+ // VS >= 8 support per-config source locations so we
+ // list object library content as external objects.
+ cmGeneratorTarget* gt =
+ this->GlobalGenerator->GetGeneratorTarget(&target);
+ std::vector<std::string> objs;
+ gt->UseObjectLibraries(objs, "");
+ if(!objs.empty())
+ {
+ // TODO: Separate sub-filter for each object library used?
+ fout << "\t\t<Filter Name=\"Object Libraries\">\n";
+ for(std::vector<std::string>::const_iterator
+ oi = objs.begin(); oi != objs.end(); ++oi)
+ {
+ std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str());
+ fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n";
+ }
+ fout << "\t\t</Filter>\n";
+ }
+ }
+
+ fout << "\t</Files>\n";
+
+ // Write the VCProj file's footer.
+ this->WriteVCProjFooter(fout, target);
+}
+
+struct cmLVS7GFileConfig
+{
+ std::string ObjectName;
+ std::string CompileFlags;
+ std::string CompileDefs;
+ std::string CompileDefsConfig;
+ std::string AdditionalDeps;
+ bool ExcludedFromBuild;
+};
+
+class cmLocalVisualStudio7GeneratorFCInfo
+{
+public:
+ cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
+ cmTarget& target,
+ cmSourceFile const& sf,
+ std::vector<std::string>* configs);
+ std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
+};
+
+cmLocalVisualStudio7GeneratorFCInfo
+::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
+ cmTarget& target,
+ cmSourceFile const& sf,
+ std::vector<std::string>* configs)
+{
+ cmGeneratorTarget* gt =
+ lg->GetGlobalGenerator()->GetGeneratorTarget(&target);
+ std::string objectName;
+ if(gt->HasExplicitObjectName(&sf))
+ {
+ objectName = gt->GetObjectName(&sf);
+ }
+
+ // Compute per-source, per-config information.
+ for(std::vector<std::string>::iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ std::string configUpper = cmSystemTools::UpperCase(*i);
+ cmLVS7GFileConfig fc;
+ bool needfc = false;
+ if(!objectName.empty())
+ {
+ fc.ObjectName = objectName;
+ needfc = true;
+ }
+ if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
+ {
+ fc.CompileFlags = cflags;
+ needfc = true;
+ }
+ if(lg->FortranProject)
+ {
+ switch(lg->GetFortranFormat(sf.GetProperty("Fortran_FORMAT")))
+ {
+ case cmLocalGenerator::FortranFormatFixed:
+ fc.CompileFlags = "-fixed " + fc.CompileFlags;
+ needfc = true;
+ break;
+ case cmLocalGenerator::FortranFormatFree:
+ fc.CompileFlags = "-free " + fc.CompileFlags;
+ needfc = true;
+ break;
+ default: break;
+ }
+ }
+ if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
+ {
+ fc.CompileDefs = cdefs;
+ needfc = true;
+ }
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += configUpper;
+ if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
+ {
+ fc.CompileDefsConfig = ccdefs;
+ needfc = true;
+ }
+
+ // Check for extra object-file dependencies.
+ if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
+ {
+ std::vector<std::string> depends;
+ cmSystemTools::ExpandListArgument(deps, depends);
+ const char* sep = "";
+ for(std::vector<std::string>::iterator j = depends.begin();
+ j != depends.end(); ++j)
+ {
+ fc.AdditionalDeps += sep;
+ fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
+ sep = ";";
+ needfc = true;
+ }
+ }
+
+ std::string lang =
+ lg->GlobalGenerator->GetLanguageFromExtension
+ (sf.GetExtension().c_str());
+ const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
+ const std::string& linkLanguage = target.GetLinkerLanguage(i->c_str());
+ bool needForceLang = false;
+ // source file does not match its extension language
+ if(lang != sourceLang)
+ {
+ needForceLang = true;
+ lang = sourceLang;
+ }
+ // If HEADER_FILE_ONLY is set, we must suppress this generation in
+ // the project file
+ fc.ExcludedFromBuild =
+ (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
+ if(fc.ExcludedFromBuild)
+ {
+ needfc = true;
+ }
+
+ // if the source file does not match the linker language
+ // then force c or c++
+ if(needForceLang || (linkLanguage != lang))
+ {
+ if(lang == "CXX")
+ {
+ // force a C++ file type
+ fc.CompileFlags += " /TP ";
+ needfc = true;
+ }
+ else if(lang == "C")
+ {
+ // force to c
+ fc.CompileFlags += " /TC ";
+ needfc = true;
+ }
+ }
+
+ if(needfc)
+ {
+ this->FileConfigMap[*i] = fc;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalVisualStudio7Generator
+::ComputeLongestObjectDirectory(cmTarget& target) const
+{
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+ // Compute the maximum length configuration name.
+ std::string config_max;
+ for(std::vector<std::string>::iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ if(i->size() > config_max.size())
+ {
+ config_max = *i;
+ }
+ }
+
+ // Compute the maximum length full path to the intermediate
+ // 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->GetCurrentOutputDirectory();
+ dir_max += "/";
+ dir_max += this->GetTargetDirectory(target);
+ dir_max += "/";
+ dir_max += config_max;
+ dir_max += "/";
+ return dir_max;
+}
+
+bool cmLocalVisualStudio7Generator
+::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
+ std::ostream &fout, const std::string& libName,
+ std::vector<std::string> *configs)
+{
+ cmGlobalVisualStudio7Generator* gg =
+ static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
+ const std::vector<const cmSourceFile *> &sourceFiles =
+ sg->GetSourceFiles();
+ std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
+
+ // Write the children to temporary output.
+ bool hasChildrenWithSources = false;
+ cmOStringStream tmpOut;
+ for(unsigned int i=0;i<children.size();++i)
+ {
+ if(this->WriteGroup(&children[i], target, tmpOut, libName, configs))
+ {
+ hasChildrenWithSources = true;
+ }
+ }
+
+ // If the group is empty, don't write it at all.
+ if(sourceFiles.empty() && !hasChildrenWithSources)
+ {
+ return false;
+ }
+
+ // If the group has a name, write the header.
+ std::string name = sg->GetName();
+ if(name != "")
+ {
+ this->WriteVCProjBeginGroup(fout, name.c_str(), "");
+ }
+
+ // 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 )
+ {
+ fout << "\t\t\t<File\n";
+ std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
+ // Tell MS-Dev what the source is. If the compiler knows how to
+ // build it, then it will.
+ fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
+ if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
+ {
+ this->WriteCustomRule(fout, source.c_str(), *command, fcinfo);
+ }
+ else if(!fcinfo.FileConfigMap.empty())
+ {
+ const char* aCompilerTool = "VCCLCompilerTool";
+ const char* ppLang = "CXX";
+ if(this->FortranProject)
+ {
+ aCompilerTool = "VFFortranCompilerTool";
+ }
+ std::string const& lang = (*sf)->GetLanguage();
+ std::string ext = (*sf)->GetExtension();
+ ext = cmSystemTools::LowerCase(ext);
+ if(ext == "idl")
+ {
+ aCompilerTool = "VCMIDLTool";
+ if(this->FortranProject)
+ {
+ aCompilerTool = "VFMIDLTool";
+ }
+ }
+ if(ext == "rc")
+ {
+ aCompilerTool = "VCResourceCompilerTool";
+ ppLang = "RC";
+ if(this->FortranProject)
+ {
+ aCompilerTool = "VFResourceCompilerTool";
+ }
+ }
+ if(ext == "def")
+ {
+ aCompilerTool = "VCCustomBuildTool";
+ if(this->FortranProject)
+ {
+ aCompilerTool = "VFCustomBuildTool";
+ }
+ }
+ if (gg->IsMasmEnabled() && !this->FortranProject &&
+ lang == "ASM_MASM")
+ {
+ aCompilerTool = "MASM";
+ }
+ for(std::map<std::string, cmLVS7GFileConfig>::const_iterator
+ fci = fcinfo.FileConfigMap.begin();
+ fci != fcinfo.FileConfigMap.end(); ++fci)
+ {
+ cmLVS7GFileConfig const& fc = fci->second;
+ fout << "\t\t\t\t<FileConfiguration\n"
+ << "\t\t\t\t\tName=\"" << fci->first
+ << "|" << gg->GetPlatformName() << "\"";
+ if(fc.ExcludedFromBuild)
+ {
+ fout << " ExcludedFromBuild=\"true\"";
+ }
+ fout << ">\n";
+ fout << "\t\t\t\t\t<Tool\n"
+ << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
+ if(!fc.CompileFlags.empty() ||
+ !fc.CompileDefs.empty() ||
+ !fc.CompileDefsConfig.empty())
+ {
+ Options::Tool tool = Options::Compiler;
+ cmVS7FlagTable const* table =
+ cmLocalVisualStudio7GeneratorFlagTable;
+ if(this->FortranProject)
+ {
+ tool = Options::FortranCompiler;
+ table = cmLocalVisualStudio7GeneratorFortranFlagTable;
+ }
+ Options fileOptions(this, tool, table,
+ this->ExtraFlagTable);
+ fileOptions.Parse(fc.CompileFlags.c_str());
+ fileOptions.AddDefines(fc.CompileDefs.c_str());
+ fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
+ fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
+ fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
+ fileOptions.OutputPreprocessorDefinitions(fout,
+ "\t\t\t\t\t", "\n",
+ ppLang);
+ }
+ if(!fc.AdditionalDeps.empty())
+ {
+ fout << "\t\t\t\t\tAdditionalDependencies=\""
+ << fc.AdditionalDeps.c_str() << "\"\n";
+ }
+ if(!fc.ObjectName.empty())
+ {
+ fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
+ << fc.ObjectName.c_str() << "\"\n";
+ }
+ fout << "\t\t\t\t\t/>\n"
+ << "\t\t\t\t</FileConfiguration>\n";
+ }
+ }
+ fout << "\t\t\t</File>\n";
+ }
+ }
+
+ // If the group has children with source files, write the children.
+ if(hasChildrenWithSources)
+ {
+ fout << tmpOut.str();
+ }
+
+ // If the group has a name, write the footer.
+ if(name != "")
+ {
+ this->WriteVCProjEndGroup(fout);
+ }
+
+ return true;
+}
+
+void cmLocalVisualStudio7Generator::
+WriteCustomRule(std::ostream& fout,
+ const char* source,
+ const cmCustomCommand& command,
+ FCInfo& fcinfo)
+{
+ cmGlobalVisualStudio7Generator* gg =
+ static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
+
+ // Write the rule for each configuration.
+ std::vector<std::string>::iterator i;
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+ const char* compileTool = "VCCLCompilerTool";
+ if(this->FortranProject)
+ {
+ compileTool = "VFCLCompilerTool";
+ }
+ const char* customTool = "VCCustomBuildTool";
+ if(this->FortranProject)
+ {
+ customTool = "VFCustomBuildTool";
+ }
+ for(i = configs->begin(); i != configs->end(); ++i)
+ {
+ cmCustomCommandGenerator ccg(command, *i, this->Makefile);
+ cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
+ fout << "\t\t\t\t<FileConfiguration\n";
+ fout << "\t\t\t\t\tName=\"" << *i << "|"
+ << gg->GetPlatformName() << "\">\n";
+ if(!fc.CompileFlags.empty())
+ {
+ fout << "\t\t\t\t\t<Tool\n"
+ << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
+ << "\t\t\t\t\tAdditionalOptions=\""
+ << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
+ }
+
+ std::string comment = this->ConstructComment(ccg);
+ std::string script = this->ConstructScript(ccg);
+ if(this->FortranProject)
+ {
+ cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
+ }
+ fout << "\t\t\t\t\t<Tool\n"
+ << "\t\t\t\t\tName=\"" << customTool << "\"\n"
+ << "\t\t\t\t\tDescription=\""
+ << this->EscapeForXML(comment.c_str()) << "\"\n"
+ << "\t\t\t\t\tCommandLine=\""
+ << this->EscapeForXML(script.c_str()) << "\"\n"
+ << "\t\t\t\t\tAdditionalDependencies=\"";
+ if(ccg.GetDepends().empty())
+ {
+ // There are no real dependencies. Produce an artificial one to
+ // make sure the rule runs reliably.
+ if(!cmSystemTools::FileExists(source))
+ {
+ cmsys::ofstream depout(source);
+ depout << "Artificial dependency for a custom command.\n";
+ }
+ fout << this->ConvertToXMLOutputPath(source);
+ }
+ else
+ {
+ // Write out the dependencies for the rule.
+ for(std::vector<std::string>::const_iterator d =
+ ccg.GetDepends().begin();
+ d != ccg.GetDepends().end();
+ ++d)
+ {
+ // Get the real name of the dependency in case it is a CMake target.
+ std::string dep;
+ if(this->GetRealDependency(d->c_str(), i->c_str(), dep))
+ {
+ fout << this->ConvertToXMLOutputPath(dep.c_str())
+ << ";";
+ }
+ }
+ }
+ fout << "\"\n";
+ fout << "\t\t\t\t\tOutputs=\"";
+ if(ccg.GetOutputs().empty())
+ {
+ fout << source << "_force";
+ }
+ else
+ {
+ // Write a rule for the output generated by this command.
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator o =
+ ccg.GetOutputs().begin();
+ o != ccg.GetOutputs().end();
+ ++o)
+ {
+ fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
+ sep = ";";
+ }
+ }
+ fout << "\"/>\n";
+ fout << "\t\t\t\t</FileConfiguration>\n";
+ }
+}
+
+
+void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
+ const char* group,
+ const char* )
+{
+ fout << "\t\t<Filter\n"
+ << "\t\t\tName=\"" << group << "\"\n"
+ << "\t\t\tFilter=\"\">\n";
+}
+
+
+void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
+{
+ fout << "\t\t</Filter>\n";
+}
+
+
+// look for custom rules on a target and collect them together
+void cmLocalVisualStudio7Generator
+::OutputTargetRules(std::ostream& fout,
+ const std::string& configName,
+ cmTarget &target,
+ const std::string& /*libName*/)
+{
+ if (target.GetType() > cmTarget::GLOBAL_TARGET)
+ {
+ return;
+ }
+ EventWriter event(this, configName, fout);
+
+ // Add pre-build event.
+ const char* tool =
+ this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
+ event.Start(tool);
+ event.Write(target.GetPreBuildCommands());
+ event.Finish();
+
+ // Add pre-link event.
+ tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
+ event.Start(tool);
+ event.Write(target.GetPreLinkCommands());
+ cmsys::auto_ptr<cmCustomCommand> pcc(
+ this->MaybeCreateImplibDir(target, configName, this->FortranProject));
+ if(pcc.get())
+ {
+ event.Write(*pcc);
+ }
+ event.Finish();
+
+ // Add post-build event.
+ tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
+ event.Start(tool);
+ event.Write(target.GetPostBuildCommands());
+ event.Finish();
+}
+
+void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
+ cmTarget& 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");
+
+ if(vsProvider && vsLocalpath && vsProjectname)
+ {
+ fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
+ << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
+ << "\tSccProvider=\"" << vsProvider << "\"\n";
+
+ const char* vsAuxPath = target.GetProperty("VS_SCC_AUXPATH");
+ if(vsAuxPath)
+ {
+ fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
+ }
+ }
+}
+
+void
+cmLocalVisualStudio7Generator
+::WriteProjectStartFortran(std::ostream& fout,
+ const std::string& libName,
+ cmTarget & target)
+{
+
+ cmGlobalVisualStudio7Generator* gg =
+ static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
+ fout << "<?xml version=\"1.0\" encoding = \""
+ << gg->Encoding() << "\"?>\n"
+ << "<VisualStudioProject\n"
+ << "\tProjectCreator=\"Intel Fortran\"\n"
+ << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
+ const char* keyword = target.GetProperty("VS_KEYWORD");
+ if(!keyword)
+ {
+ keyword = "Console Application";
+ }
+ const char* projectType = 0;
+ switch(target.GetType())
+ {
+ case cmTarget::STATIC_LIBRARY:
+ projectType = "typeStaticLibrary";
+ if(keyword)
+ {
+ keyword = "Static Library";
+ }
+ break;
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ projectType = "typeDynamicLibrary";
+ if(!keyword)
+ {
+ keyword = "Dll";
+ }
+ break;
+ case cmTarget::EXECUTABLE:
+ if(!keyword)
+ {
+ keyword = "Console Application";
+ }
+ projectType = 0;
+ break;
+ case cmTarget::UTILITY:
+ case cmTarget::GLOBAL_TARGET:
+ default:
+ break;
+ }
+ if(projectType)
+ {
+ fout << "\tProjectType=\"" << projectType << "\"\n";
+ }
+ this->WriteProjectSCC(fout, target);
+ fout<< "\tKeyword=\"" << keyword << "\">\n"
+ << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
+ << "\t<Platforms>\n"
+ << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
+ << "\t</Platforms>\n";
+}
+
+
+void
+cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
+ const std::string& libName,
+ cmTarget & target,
+ std::vector<cmSourceGroup> &)
+{
+ if(this->FortranProject)
+ {
+ this->WriteProjectStartFortran(fout, libName, target);
+ return;
+ }
+
+ cmGlobalVisualStudio7Generator* gg =
+ static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
+
+ fout << "<?xml version=\"1.0\" encoding = \""
+ << gg->Encoding() << "\"?>\n"
+ << "<VisualStudioProject\n"
+ << "\tProjectType=\"Visual C++\"\n";
+ if(this->Version == VS71)
+ {
+ fout << "\tVersion=\"7.10\"\n";
+ }
+ else
+ {
+ fout << "\tVersion=\"" << (this->Version/10) << ".00\"\n";
+ }
+ const char* projLabel = target.GetProperty("PROJECT_LABEL");
+ if(!projLabel)
+ {
+ projLabel = libName.c_str();
+ }
+ const char* keyword = target.GetProperty("VS_KEYWORD");
+ if(!keyword)
+ {
+ keyword = "Win32Proj";
+ }
+ fout << "\tName=\"" << projLabel << "\"\n";
+ if(this->Version >= VS8)
+ {
+ fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
+ }
+ this->WriteProjectSCC(fout, target);
+ if(const char* targetFrameworkVersion =
+ target.GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
+ {
+ fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
+ }
+ fout << "\tKeyword=\"" << keyword << "\">\n"
+ << "\t<Platforms>\n"
+ << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
+ << "\t</Platforms>\n";
+ if(gg->IsMasmEnabled())
+ {
+ fout <<
+ "\t<ToolFiles>\n"
+ "\t\t<DefaultToolFile\n"
+ "\t\t\tFileName=\"masm.rules\"\n"
+ "\t\t/>\n"
+ "\t</ToolFiles>\n"
+ ;
+ }
+}
+
+
+void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout,
+ cmTarget &target)
+{
+ fout << "\t<Globals>\n";
+
+ cmPropertyMap const& props = target.GetProperties();
+ for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
+ {
+ if(i->first.find("VS_GLOBAL_") == 0)
+ {
+ std::string name = i->first.substr(10);
+ if(name != "")
+ {
+ fout << "\t\t<Global\n"
+ << "\t\t\tName=\"" << name << "\"\n"
+ << "\t\t\tValue=\"" << i->second.GetValue() << "\"\n"
+ << "\t\t/>\n";
+ }
+ }
+ }
+
+ fout << "\t</Globals>\n"
+ << "</VisualStudioProject>\n";
+}
+
+std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
+{
+ std::string ret = s;
+ cmSystemTools::ReplaceString(ret, "&", "&amp;");
+ cmSystemTools::ReplaceString(ret, "\"", "&quot;");
+ cmSystemTools::ReplaceString(ret, "<", "&lt;");
+ cmSystemTools::ReplaceString(ret, ">", "&gt;");
+ cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
+ return ret;
+}
+
+std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
+{
+ return cmLocalVisualStudio7GeneratorEscapeForXML(s);
+}
+
+std::string cmLocalVisualStudio7Generator
+::ConvertToXMLOutputPath(const char* path)
+{
+ std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
+ cmSystemTools::ReplaceString(ret, "&", "&amp;");
+ cmSystemTools::ReplaceString(ret, "\"", "&quot;");
+ cmSystemTools::ReplaceString(ret, "<", "&lt;");
+ cmSystemTools::ReplaceString(ret, ">", "&gt;");
+ return ret;
+}
+
+std::string cmLocalVisualStudio7Generator
+::ConvertToXMLOutputPathSingle(const char* path)
+{
+ std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
+ cmSystemTools::ReplaceString(ret, "\"", "");
+ cmSystemTools::ReplaceString(ret, "&", "&amp;");
+ cmSystemTools::ReplaceString(ret, "<", "&lt;");
+ cmSystemTools::ReplaceString(ret, ">", "&gt;");
+ return ret;
+}
+
+
+// This class is used to parse an existing vs 7 project
+// and extract the GUID
+class cmVS7XMLParser : public cmXMLParser
+{
+public:
+ virtual void EndElement(const std::string& /* name */)
+ {
+ }
+ virtual void StartElement(const std::string& name, const char** atts)
+ {
+ // once the GUID is found do nothing
+ if(this->GUID.size())
+ {
+ return;
+ }
+ int i =0;
+ if("VisualStudioProject" == name)
+ {
+ while(atts[i])
+ {
+ if(strcmp(atts[i], "ProjectGUID") == 0)
+ {
+ if(atts[i+1])
+ {
+ this->GUID = atts[i+1];
+ this->GUID = this->GUID.substr(1, this->GUID.size()-2);
+ }
+ else
+ {
+ this->GUID = "";
+ }
+ return;
+ }
+ ++i;
+ }
+ }
+ }
+ int InitializeParser()
+ {
+ int ret = cmXMLParser::InitializeParser();
+ if(ret == 0)
+ {
+ return ret;
+ }
+ // visual studio projects have a strange encoding, but it is
+ // really utf-8
+ XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
+ return 1;
+ }
+ std::string GUID;
+};
+
+void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
+ const std::string& name,
+ const char* path)
+{
+ cmVS7XMLParser parser;
+ parser.ParseFile(path);
+ // if we can not find a GUID then create one
+ if(parser.GUID.size() == 0)
+ {
+ cmGlobalVisualStudio7Generator* gg =
+ static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
+ gg->CreateGUID(name);
+ return;
+ }
+ std::string guidStoreName = name;
+ guidStoreName += "_GUID_CMAKE";
+ // save the GUID in the cache
+ this->GlobalGenerator->GetCMakeInstance()->
+ AddCacheEntry(guidStoreName.c_str(),
+ parser.GUID.c_str(),
+ "Stored GUID",
+ cmCacheManager::INTERNAL);
+}
+
+
+//----------------------------------------------------------------------------
+std::string cmLocalVisualStudio7Generator
+::GetTargetDirectory(cmTarget const& target) const
+{
+ std::string dir;
+ dir += target.GetName();
+ dir += ".dir";
+ return dir;
+}
+
+//----------------------------------------------------------------------------
+#include <windows.h>
+static bool cmLVS6G_IsFAT(const char* dir)
+{
+ if(dir[0] && dir[1] == ':')
+ {
+ char volRoot[4] = "_:/";
+ volRoot[0] = dir[0];
+ char fsName[16];
+ if(GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
+ strstr(fsName, "FAT") != 0)
+ {
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h
new file mode 100644
index 0000000000..c2caa26f3e
--- /dev/null
+++ b/Source/cmLocalVisualStudio7Generator.h
@@ -0,0 +1,130 @@
+/*============================================================================
+ 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 cmLocalVisualStudio7Generator_h
+#define cmLocalVisualStudio7Generator_h
+
+#include "cmLocalVisualStudioGenerator.h"
+#include "cmVisualStudioGeneratorOptions.h"
+
+class cmTarget;
+class cmSourceFile;
+class cmCustomCommand;
+class cmSourceGroup;
+
+
+class cmLocalVisualStudio7GeneratorOptions;
+class cmLocalVisualStudio7GeneratorFCInfo;
+class cmLocalVisualStudio7GeneratorInternals;
+
+/** \class cmLocalVisualStudio7Generator
+ * \brief Write Visual Studio .NET project files.
+ *
+ * cmLocalVisualStudio7Generator produces a Visual Studio .NET project
+ * file for each target in its directory.
+ */
+class cmLocalVisualStudio7Generator : public cmLocalVisualStudioGenerator
+{
+public:
+ ///! Set cache only and recurse to false by default.
+ cmLocalVisualStudio7Generator(VSVersion v);
+
+ virtual ~cmLocalVisualStudio7Generator();
+
+ virtual void AddHelperCommands();
+
+ /**
+ * Generate the makefile for this directory.
+ */
+ virtual void Generate();
+
+ enum BuildType {STATIC_LIBRARY, DLL, EXECUTABLE, WIN32_EXECUTABLE, UTILITY};
+
+ /**
+ * Specify the type of the build: static, dll, or executable.
+ */
+ void SetBuildType(BuildType,const std::string& name);
+
+ void SetExtraFlagTable(cmVS7FlagTable const* table)
+ { this->ExtraFlagTable = table; }
+ virtual std::string GetTargetDirectory(cmTarget const&) const;
+ cmSourceFile* CreateVCProjBuildRule();
+ void WriteStampFiles();
+ virtual std::string ComputeLongestObjectDirectory(cmTarget&) const;
+
+ virtual void ReadAndStoreExternalGUID(const std::string& name,
+ const char* path);
+ virtual void AddCMakeListsRules();
+protected:
+ void CreateSingleVCProj(const std::string& lname, cmTarget &tgt);
+private:
+ typedef cmVisualStudioGeneratorOptions Options;
+ typedef cmLocalVisualStudio7GeneratorFCInfo FCInfo;
+ std::string GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
+ const std::string& configName);
+ 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);
+ void WriteVCProjFile(std::ostream& fout, const std::string& libName,
+ cmTarget &tgt);
+ void WriteConfigurations(std::ostream& fout,
+ const std::string& libName, cmTarget &tgt);
+ void WriteConfiguration(std::ostream& fout,
+ const std::string& configName,
+ const std::string& libName, cmTarget &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);
+ void OutputBuildTool(std::ostream& fout, const std::string& configName,
+ cmTarget& t, const Options& targetOptions);
+ void OutputLibraryDirectories(std::ostream& fout,
+ std::vector<std::string> const& dirs);
+ void WriteProjectSCC(std::ostream& fout, cmTarget& target);
+ void WriteProjectStart(std::ostream& fout, const std::string& libName,
+ cmTarget &tgt, std::vector<cmSourceGroup> &sgs);
+ void WriteProjectStartFortran(std::ostream& fout, const std::string& libName,
+ cmTarget &tgt);
+ void WriteVCProjBeginGroup(std::ostream& fout,
+ const char* group,
+ const char* filter);
+ void WriteVCProjEndGroup(std::ostream& fout);
+
+ void WriteCustomRule(std::ostream& fout,
+ const char* source,
+ const cmCustomCommand& command,
+ FCInfo& fcinfo);
+ void WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target);
+
+ bool WriteGroup(const cmSourceGroup *sg,
+ cmTarget& target, std::ostream &fout,
+ const std::string& libName,
+ std::vector<std::string> *configs);
+
+ friend class cmLocalVisualStudio7GeneratorFCInfo;
+ friend class cmLocalVisualStudio7GeneratorInternals;
+
+ class EventWriter;
+ friend class EventWriter;
+
+ cmVS7FlagTable const* ExtraFlagTable;
+ std::string ModuleDefinitionFile;
+ bool FortranProject;
+ bool WindowsCEProject;
+ cmLocalVisualStudio7GeneratorInternals* Internal;
+};
+
+
+#endif
+
diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx
new file mode 100644
index 0000000000..9680d43b1a
--- /dev/null
+++ b/Source/cmLocalVisualStudioGenerator.cxx
@@ -0,0 +1,243 @@
+/*============================================================================
+ 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 "cmLocalVisualStudioGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmSystemTools.h"
+#include "cmCustomCommandGenerator.h"
+#include "windows.h"
+
+//----------------------------------------------------------------------------
+cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator(VSVersion v)
+{
+ this->WindowsShell = true;
+ this->WindowsVSIDE = true;
+ this->Version = v;
+}
+
+//----------------------------------------------------------------------------
+cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt)
+{
+ std::string dir_max = this->ComputeLongestObjectDirectory(*gt->Target);
+
+ // Count the number of object files with each name. Note that
+ // windows file names are not case sensitive.
+ std::map<std::string, int> counts;
+
+ for(std::map<cmSourceFile const*, std::string>::iterator
+ si = mapping.begin(); si != mapping.end(); ++si)
+ {
+ cmSourceFile const* sf = si->first;
+ std::string objectNameLower = cmSystemTools::LowerCase(
+ cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
+ objectNameLower += ".obj";
+ counts[objectNameLower] += 1;
+ }
+
+ // For all source files producing duplicate names we need unique
+ // object name computation.
+
+ for(std::map<cmSourceFile const*, std::string>::iterator
+ si = mapping.begin(); si != mapping.end(); ++si)
+ {
+ cmSourceFile const* sf = si->first;
+ std::string objectName =
+ cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
+ objectName += ".obj";
+ if(counts[cmSystemTools::LowerCase(objectName)] > 1)
+ {
+ const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
+ objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
+ }
+ si->second = objectName;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmsys::auto_ptr<cmCustomCommand>
+cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmTarget& target,
+ const std::string& config,
+ bool isFortran)
+{
+ cmsys::auto_ptr<cmCustomCommand> pcc;
+
+ // 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))
+ { return pcc; }
+ 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.
+ cmCustomCommandLine command;
+ command.push_back(this->Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
+ command.push_back("-E");
+ command.push_back("make_directory");
+ command.push_back(impDir);
+ std::vector<std::string> no_output;
+ std::vector<std::string> no_depends;
+ cmCustomCommandLines commands;
+ commands.push_back(command);
+ pcc.reset(new cmCustomCommand(0, no_output, no_depends, commands, 0, 0));
+ pcc->SetEscapeOldStyle(false);
+ pcc->SetEscapeAllowMakeVars(true);
+ return pcc;
+}
+
+//----------------------------------------------------------------------------
+const char* cmLocalVisualStudioGenerator::ReportErrorLabel() const
+{
+ return ":VCReportError";
+}
+
+//----------------------------------------------------------------------------
+const char* cmLocalVisualStudioGenerator::GetReportErrorLabel() const
+{
+ return this->ReportErrorLabel();
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalVisualStudioGenerator
+::ConstructScript(cmCustomCommandGenerator const& ccg,
+ const std::string& newline_text)
+{
+ bool useLocal = this->CustomCommandUseLocal();
+ std::string workingDirectory = ccg.GetWorkingDirectory();
+ RelativeRoot relativeRoot = workingDirectory.empty()? START_OUTPUT : NONE;
+
+ // Avoid leading or trailing newlines.
+ std::string newline = "";
+
+ // Line to check for error between commands.
+ std::string check_error = newline_text;
+ if(useLocal)
+ {
+ check_error += "if %errorlevel% neq 0 goto :cmEnd";
+ }
+ else
+ {
+ check_error += "if errorlevel 1 goto ";
+ check_error += this->GetReportErrorLabel();
+ }
+
+ // Store the script in a string.
+ std::string script;
+
+ // Open a local context.
+ if(useLocal)
+ {
+ script += newline;
+ newline = newline_text;
+ script += "setlocal";
+ }
+
+ if(!workingDirectory.empty())
+ {
+ // Change the working directory.
+ script += newline;
+ newline = newline_text;
+ script += "cd ";
+ script += this->Convert(workingDirectory, FULL, SHELL);
+ script += check_error;
+
+ // Change the working drive.
+ if(workingDirectory.size() > 1 && workingDirectory[1] == ':')
+ {
+ script += newline;
+ newline = newline_text;
+ script += workingDirectory[0];
+ script += workingDirectory[1];
+ script += check_error;
+ }
+ }
+
+ // for visual studio IDE add extra stuff to the PATH
+ // if CMAKE_MSVCIDE_RUN_PATH is set.
+ if(this->Makefile->GetDefinition("MSVC_IDE"))
+ {
+ const char* extraPath =
+ this->Makefile->GetDefinition("CMAKE_MSVCIDE_RUN_PATH");
+ if(extraPath)
+ {
+ script += newline;
+ newline = newline_text;
+ script += "set PATH=";
+ script += extraPath;
+ script += ";%PATH%";
+ }
+ }
+
+ // Write each command on a single line.
+ for(unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c)
+ {
+ // Start a new line.
+ script += newline;
+ newline = newline_text;
+
+ // Add this command line.
+ std::string cmd = ccg.GetCommand(c);
+
+ // Use "call " before any invocations of .bat or .cmd files
+ // invoked as custom commands.
+ //
+ std::string suffix;
+ if (cmd.size() > 4)
+ {
+ suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size()-4));
+ if (suffix == ".bat" || suffix == ".cmd")
+ {
+ script += "call ";
+ }
+ }
+
+ script += this->Convert(cmd.c_str(), relativeRoot, SHELL);
+ ccg.AppendArguments(c, script);
+
+ // After each custom command, check for an error result.
+ // If there was an error, jump to the VCReportError label,
+ // skipping the run of any subsequent commands in this
+ // sequence.
+ script += check_error;
+ }
+
+ // Close the local context.
+ if(useLocal)
+ {
+ script += newline;
+ script += ":cmEnd";
+ script += newline;
+ script += "endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone";
+ script += newline;
+ script += ":cmErrorLevel";
+ script += newline;
+ script += "exit /b %1";
+ script += newline;
+ script += ":cmDone";
+ script += newline;
+ script += "if %errorlevel% neq 0 goto ";
+ script += this->GetReportErrorLabel();
+ }
+
+ return script;
+}
diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h
new file mode 100644
index 0000000000..d26c2eaf05
--- /dev/null
+++ b/Source/cmLocalVisualStudioGenerator.h
@@ -0,0 +1,82 @@
+/*============================================================================
+ 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 cmLocalVisualStudioGenerator_h
+#define cmLocalVisualStudioGenerator_h
+
+#include "cmLocalGenerator.h"
+
+#include <cmsys/auto_ptr.hxx>
+
+class cmSourceFile;
+class cmSourceGroup;
+class cmCustomCommand;
+class cmCustomCommandGenerator;
+
+/** \class cmLocalVisualStudioGenerator
+ * \brief Base class for Visual Studio generators.
+ *
+ * cmLocalVisualStudioGenerator provides functionality common to all
+ * Visual Studio generators.
+ */
+class cmLocalVisualStudioGenerator : public cmLocalGenerator
+{
+public:
+ /** Known versions of Visual Studio. */
+ enum VSVersion
+ {
+ VS6 = 60,
+ VS7 = 70,
+ VS71 = 71,
+ VS8 = 80,
+ VS9 = 90,
+ VS10 = 100,
+ VS11 = 110,
+ VS12 = 120,
+ /* VS13 = 130 was skipped */
+ VS14 = 140
+ };
+
+ cmLocalVisualStudioGenerator(VSVersion v);
+ virtual ~cmLocalVisualStudioGenerator();
+
+ /** Construct a script from the given list of command lines. */
+ std::string ConstructScript(cmCustomCommandGenerator const& ccg,
+ const std::string& newline = "\n");
+
+ /** Label to which to jump in a batch file after a failed step in a
+ sequence of custom commands. */
+ const char* GetReportErrorLabel() const;
+
+ /** Version of Visual Studio. */
+ VSVersion GetVersion() const { return this->Version; }
+
+ virtual std::string ComputeLongestObjectDirectory(cmTarget&) const = 0;
+
+ virtual void AddCMakeListsRules() = 0;
+
+ virtual void ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* = 0);
+
+protected:
+ virtual const char* ReportErrorLabel() const;
+ virtual bool CustomCommandUseLocal() const { return false; }
+
+ /** Construct a custom command to make exe import lib dir. */
+ cmsys::auto_ptr<cmCustomCommand>
+ MaybeCreateImplibDir(cmTarget& target, const std::string& config,
+ bool isFortran);
+
+ VSVersion Version;
+};
+
+#endif
diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx
new file mode 100644
index 0000000000..8ff6c87d68
--- /dev/null
+++ b/Source/cmLocalXCodeGenerator.cxx
@@ -0,0 +1,101 @@
+/*============================================================================
+ 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 "cmLocalXCodeGenerator.h"
+#include "cmGlobalXCodeGenerator.h"
+#include "cmSourceFile.h"
+#include "cmMakefile.h"
+
+//----------------------------------------------------------------------------
+cmLocalXCodeGenerator::cmLocalXCodeGenerator()
+{
+ // the global generator does this, so do not
+ // put these flags into the language flags
+ this->EmitUniversalBinaryFlags = false;
+}
+
+//----------------------------------------------------------------------------
+cmLocalXCodeGenerator::~cmLocalXCodeGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalXCodeGenerator::GetTargetDirectory(cmTarget const&) const
+{
+ // No per-target directory for this generator (yet).
+ return "";
+}
+
+//----------------------------------------------------------------------------
+void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags,
+ const std::string& rawFlag)
+{
+ cmGlobalXCodeGenerator* gg =
+ static_cast<cmGlobalXCodeGenerator*>(this->GlobalGenerator);
+ gg->AppendFlag(flags, rawFlag);
+}
+
+//----------------------------------------------------------------------------
+void cmLocalXCodeGenerator::Generate()
+{
+ cmLocalGenerator::Generate();
+
+ cmTargets& targets = this->Makefile->GetTargets();
+ for(cmTargets::iterator iter = targets.begin();
+ iter != targets.end(); ++iter)
+ {
+ cmTarget* t = &iter->second;
+ t->HasMacOSXRpathInstallNameDir("");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalXCodeGenerator::GenerateInstallRules()
+{
+ cmLocalGenerator::GenerateInstallRules();
+
+ cmTargets& targets = this->Makefile->GetTargets();
+ for(cmTargets::iterator iter = targets.begin();
+ iter != targets.end(); ++iter)
+ {
+ cmTarget* t = &iter->second;
+ t->HasMacOSXRpathInstallNameDir("");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalXCodeGenerator::ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const*)
+{
+ // Count the number of object files with each name. Warn about duplicate
+ // names since Xcode names them uniquely automatically with a numeric suffix
+ // to avoid exact duplicate file names. Note that Mac file names are not
+ // typically case sensitive, hence the LowerCase.
+ std::map<std::string, int> counts;
+ for(std::map<cmSourceFile const*, std::string>::iterator
+ si = mapping.begin(); si != mapping.end(); ++si)
+ {
+ cmSourceFile const* sf = si->first;
+ std::string objectName =
+ cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
+ objectName += ".o";
+
+ std::string objectNameLower = cmSystemTools::LowerCase(objectName);
+ counts[objectNameLower] += 1;
+ if (2 == counts[objectNameLower])
+ {
+ // TODO: emit warning about duplicate name?
+ }
+ si->second = objectName;
+ }
+}
diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h
new file mode 100644
index 0000000000..f553a17ef6
--- /dev/null
+++ b/Source/cmLocalXCodeGenerator.h
@@ -0,0 +1,43 @@
+/*============================================================================
+ 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 cmLocalXCodeGenerator_h
+#define cmLocalXCodeGenerator_h
+
+#include "cmLocalGenerator.h"
+
+/** \class cmLocalXCodeGenerator
+ * \brief Write a local Xcode project
+ *
+ * cmLocalXCodeGenerator produces a LocalUnix makefile from its
+ * member Makefile.
+ */
+class cmLocalXCodeGenerator : public cmLocalGenerator
+{
+public:
+ ///! Set cache only and recurse to false by default.
+ cmLocalXCodeGenerator();
+
+ virtual ~cmLocalXCodeGenerator();
+ virtual std::string GetTargetDirectory(cmTarget const& target) const;
+ virtual void AppendFlagEscape(std::string& flags,
+ const std::string& rawFlag);
+ virtual void Generate();
+ virtual void GenerateInstallRules();
+ virtual void ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt = 0);
+private:
+
+};
+
+#endif
+
diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx
new file mode 100644
index 0000000000..ae81c58dfb
--- /dev/null
+++ b/Source/cmMacroCommand.cxx
@@ -0,0 +1,339 @@
+/*============================================================================
+ 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 "cmMacroCommand.h"
+
+#include "cmake.h"
+
+// define the class for macro commands
+class cmMacroHelperCommand : public cmCommand
+{
+public:
+ cmMacroHelperCommand() {}
+
+ ///! clean up any memory allocated by the macro
+ ~cmMacroHelperCommand() {}
+
+ /**
+ * This is used to avoid including this command
+ * in documentation. This is mainly used by
+ * cmMacroHelperCommand and cmFunctionHelperCommand
+ * which cannot provide appropriate documentation.
+ */
+ virtual bool ShouldAppearInDocumentation() const
+ {
+ return false;
+ }
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ cmMacroHelperCommand *newC = new cmMacroHelperCommand;
+ // we must copy when we clone
+ newC->Args = this->Args;
+ newC->Functions = this->Functions;
+ newC->FilePath = this->FilePath;
+ newC->Policies = this->Policies;
+ return newC;
+ }
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus &);
+
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &) { return false; }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return this->Args[0]; }
+
+ cmTypeMacro(cmMacroHelperCommand, cmCommand);
+
+ std::vector<std::string> Args;
+ std::vector<cmListFileFunction> Functions;
+ cmPolicies::PolicyMap Policies;
+ std::string FilePath;
+};
+
+
+bool cmMacroHelperCommand::InvokeInitialPass
+(const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus &inStatus)
+{
+ // Expand the argument list to the macro.
+ std::vector<std::string> expandedArgs;
+ this->Makefile->ExpandArguments(args, expandedArgs);
+
+ std::string tmps;
+ cmListFileArgument arg;
+ std::string variable;
+
+ // make sure the number of arguments passed is at least the number
+ // required by the signature
+ if (expandedArgs.size() < this->Args.size() - 1)
+ {
+ std::string errorMsg =
+ "Macro invoked with incorrect arguments for macro named: ";
+ errorMsg += this->Args[0];
+ this->SetError(errorMsg);
+ return false;
+ }
+
+ // Enforce matching logical blocks inside the macro.
+ cmMakefile::LexicalPushPop lexScope(this->Makefile);
+
+ // Push a weak policy scope which restores the policies recorded at
+ // macro creation.
+ cmMakefile::PolicyPushPop polScope(this->Makefile, true, this->Policies);
+
+ // set the value of argc
+ cmOStringStream argcDefStream;
+ argcDefStream << expandedArgs.size();
+ std::string argcDef = argcDefStream.str();
+
+ // declare varuiables for ARGV ARGN but do not compute until needed
+ std::string argvDef;
+ std::string argnDef;
+ bool argnDefInitialized = false;
+ bool argvDefInitialized = false;
+ if( this->Functions.size())
+ {
+ this->FilePath = this->Functions[0].FilePath;
+ }
+ // Invoke all the functions that were collected in the block.
+ cmListFileFunction newLFF;
+ // for each function
+ for(unsigned int c = 0; c < this->Functions.size(); ++c)
+ {
+ // Replace the formal arguments and then invoke the command.
+ newLFF.Arguments.clear();
+ newLFF.Arguments.reserve(this->Functions[c].Arguments.size());
+ newLFF.Name = this->Functions[c].Name;
+ newLFF.FilePath = this->Functions[c].FilePath;
+ newLFF.Line = this->Functions[c].Line;
+
+ // for each argument of the current function
+ for (std::vector<cmListFileArgument>::iterator k =
+ this->Functions[c].Arguments.begin();
+ k != this->Functions[c].Arguments.end(); ++k)
+ {
+ // Set the FilePath on the arguments to match the function since it is
+ // not stored and the original values may be freed
+ k->FilePath = this->FilePath.c_str();
+ if(k->Delim == cmListFileArgument::Bracket)
+ {
+ arg.Value = k->Value;
+ }
+ else
+ {
+ tmps = k->Value;
+ // replace formal arguments
+ for (unsigned int j = 1; j < this->Args.size(); ++j)
+ {
+ variable = "${";
+ variable += this->Args[j];
+ variable += "}";
+ cmSystemTools::ReplaceString(tmps, variable.c_str(),
+ expandedArgs[j-1].c_str());
+ }
+ // replace argc
+ cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str());
+
+ // repleace ARGN
+ if (tmps.find("${ARGN}") != std::string::npos)
+ {
+ if (!argnDefInitialized)
+ {
+ std::vector<std::string>::const_iterator eit;
+ std::vector<std::string>::size_type cnt = 0;
+ for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit)
+ {
+ if ( cnt >= this->Args.size()-1 )
+ {
+ if ( argnDef.size() > 0 )
+ {
+ argnDef += ";";
+ }
+ argnDef += *eit;
+ }
+ cnt ++;
+ }
+ argnDefInitialized = true;
+ }
+ cmSystemTools::ReplaceString(tmps, "${ARGN}", argnDef.c_str());
+ }
+
+ // if the current argument of the current function has ${ARGV in it
+ // then try replacing ARGV values
+ if (tmps.find("${ARGV") != std::string::npos)
+ {
+ char argvName[60];
+
+ // repleace ARGV, compute it only once
+ if (!argvDefInitialized)
+ {
+ std::vector<std::string>::const_iterator eit;
+ for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit)
+ {
+ if ( argvDef.size() > 0 )
+ {
+ argvDef += ";";
+ }
+ argvDef += *eit;
+ }
+ argvDefInitialized = true;
+ }
+ cmSystemTools::ReplaceString(tmps, "${ARGV}", argvDef.c_str());
+
+ // also replace the ARGV1 ARGV2 ... etc
+ for (unsigned int t = 0; t < expandedArgs.size(); ++t)
+ {
+ sprintf(argvName,"${ARGV%i}",t);
+ cmSystemTools::ReplaceString(tmps, argvName,
+ expandedArgs[t].c_str());
+ }
+ }
+
+ arg.Value = tmps;
+ }
+ arg.Delim = k->Delim;
+ arg.FilePath = k->FilePath;
+ arg.Line = k->Line;
+ newLFF.Arguments.push_back(arg);
+ }
+ cmExecutionStatus status;
+ if(!this->Makefile->ExecuteCommand(newLFF, status) ||
+ status.GetNestedError())
+ {
+ // The error message should have already included the call stack
+ // so we do not need to report an error here.
+ lexScope.Quiet();
+ polScope.Quiet();
+ inStatus.SetNestedError(true);
+ return false;
+ }
+ if (status.GetReturnInvoked())
+ {
+ inStatus.SetReturnInvoked(true);
+ return true;
+ }
+ if (status.GetBreakInvoked())
+ {
+ inStatus.SetBreakInvoked(true);
+ return true;
+ }
+ }
+ return true;
+}
+
+bool cmMacroFunctionBlocker::
+IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
+ cmExecutionStatus &)
+{
+ // record commands until we hit the ENDMACRO
+ // at the ENDMACRO call we shift gears and start looking for invocations
+ if(!cmSystemTools::Strucmp(lff.Name.c_str(),"macro"))
+ {
+ this->Depth++;
+ }
+ else if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endmacro"))
+ {
+ // if this is the endmacro for this macro then execute
+ if (!this->Depth)
+ {
+ std::string name = this->Args[0];
+ std::vector<std::string>::size_type cc;
+ name += "(";
+ for ( cc = 0; cc < this->Args.size(); cc ++ )
+ {
+ name += " " + this->Args[cc];
+ }
+ name += " )";
+ mf.AddMacro(this->Args[0].c_str(), name.c_str());
+ // create a new command and add it to cmake
+ cmMacroHelperCommand *f = new cmMacroHelperCommand();
+ f->Args = this->Args;
+ f->Functions = this->Functions;
+ mf.RecordPolicies(f->Policies);
+ std::string newName = "_" + this->Args[0];
+ mf.GetCMakeInstance()->RenameCommand(this->Args[0],
+ newName);
+ mf.AddCommand(f);
+
+ // remove the function blocker now that the macro is defined
+ mf.RemoveFunctionBlocker(this, lff);
+ return true;
+ }
+ else
+ {
+ // decrement for each nested macro that ends
+ this->Depth--;
+ }
+ }
+
+ // if it wasn't an endmacro and we are not executing then we must be
+ // recording
+ this->Functions.push_back(lff);
+ return true;
+}
+
+
+bool cmMacroFunctionBlocker::
+ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf)
+{
+ if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endmacro"))
+ {
+ std::vector<std::string> expandedArguments;
+ mf.ExpandArguments(lff.Arguments, expandedArguments);
+ // if the endmacro has arguments make sure they
+ // match the arguments of the macro
+ if ((expandedArguments.empty() ||
+ (expandedArguments[0] == this->Args[0])))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool cmMacroCommand::InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // create a function blocker
+ cmMacroFunctionBlocker *f = new cmMacroFunctionBlocker();
+ for(std::vector<std::string>::const_iterator j = args.begin();
+ j != args.end(); ++j)
+ {
+ f->Args.push_back(*j);
+ }
+ this->Makefile->AddFunctionBlocker(f);
+ return true;
+}
+
diff --git a/Source/cmMacroCommand.h b/Source/cmMacroCommand.h
new file mode 100644
index 0000000000..5c1cc000af
--- /dev/null
+++ b/Source/cmMacroCommand.h
@@ -0,0 +1,66 @@
+/*============================================================================
+ 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 cmMacroCommand_h
+#define cmMacroCommand_h
+
+#include "cmCommand.h"
+#include "cmFunctionBlocker.h"
+
+class cmMacroFunctionBlocker : public cmFunctionBlocker
+{
+public:
+ cmMacroFunctionBlocker() {this->Depth=0;}
+ virtual ~cmMacroFunctionBlocker() {}
+ virtual bool IsFunctionBlocked(const cmListFileFunction&,
+ cmMakefile &mf,
+ cmExecutionStatus &);
+ virtual bool ShouldRemove(const cmListFileFunction&, cmMakefile &mf);
+
+ std::vector<std::string> Args;
+ std::vector<cmListFileFunction> Functions;
+ int Depth;
+};
+
+/// Starts macro() ... endmacro() block
+class cmMacroCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmMacroCommand;
+ }
+
+ /**
+ * 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 "macro";}
+
+ cmTypeMacro(cmMacroCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmMakeDepend.cxx b/Source/cmMakeDepend.cxx
new file mode 100644
index 0000000000..52832dbf16
--- /dev/null
+++ b/Source/cmMakeDepend.cxx
@@ -0,0 +1,365 @@
+/*============================================================================
+ 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 <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()
+{
+ for(DependInformationMapType::iterator i =
+ this->DependInformationMap.begin();
+ i != this->DependInformationMap.end(); ++i)
+ {
+ delete i->second;
+ }
+}
+
+
+// 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->IncludeFileRegularExpression.c_str());
+ 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.size() && 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.size() && path[path.size() - 1] != '/')
+ {
+ path = path + "/";
+ }
+ path = path + fname;
+ if(cmSystemTools::FileExists(path.c_str(), true)
+ && !cmSystemTools::FileIsDirectory(path.c_str()))
+ {
+ std::string fp = cmSystemTools::CollapseFullPath(path.c_str());
+ this->DirectoryToFileToPathMap[extraPath? extraPath: ""][fname] = fp;
+ return fp;
+ }
+ }
+
+ if (extraPath)
+ {
+ std::string path = extraPath;
+ if (path.size() && path[path.size() - 1] != '/')
+ {
+ path = path + "/";
+ }
+ path = path + fname;
+ if(cmSystemTools::FileExists(path.c_str(), true)
+ && !cmSystemTools::FileIsDirectory(path.c_str()))
+ {
+ std::string fp = cmSystemTools::CollapseFullPath(path.c_str());
+ 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
new file mode 100644
index 0000000000..2c9d515412
--- /dev/null
+++ b/Source/cmMakeDepend.h
@@ -0,0 +1,150 @@
+/*============================================================================
+ 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/cmMakeDirectoryCommand.cxx b/Source/cmMakeDirectoryCommand.cxx
new file mode 100644
index 0000000000..cc871c93c3
--- /dev/null
+++ b/Source/cmMakeDirectoryCommand.cxx
@@ -0,0 +1,34 @@
+/*============================================================================
+ 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 "cmMakeDirectoryCommand.h"
+
+// cmMakeDirectoryCommand
+bool cmMakeDirectoryCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() != 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ if ( !this->Makefile->CanIWriteThisFile(args[0].c_str()) )
+ {
+ std::string e = "attempted to create a directory: " + args[0]
+ + " into a source directory.";
+ this->SetError(e);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+ cmSystemTools::MakeDirectory(args[0].c_str());
+ return true;
+}
+
diff --git a/Source/cmMakeDirectoryCommand.h b/Source/cmMakeDirectoryCommand.h
new file mode 100644
index 0000000000..71b97eb28c
--- /dev/null
+++ b/Source/cmMakeDirectoryCommand.h
@@ -0,0 +1,65 @@
+/*============================================================================
+ 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 cmMakeDirectoryCommand_h
+#define cmMakeDirectoryCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmMakeDirectoryCommand
+ * \brief Specify auxiliary source code directories.
+ *
+ * cmMakeDirectoryCommand specifies source code directories
+ * that must be built as part of this build process. This directories
+ * are not recursively processed like the SUBDIR command (cmSubdirCommand).
+ * A side effect of this command is to create a subdirectory in the build
+ * directory structure.
+ */
+class cmMakeDirectoryCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmMakeDirectoryCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "make_directory";}
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ /** This command is kept for compatibility with older CMake versions. */
+ virtual bool IsDiscouraged() const
+ {
+ return true;
+ }
+
+ cmTypeMacro(cmMakeDirectoryCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
new file mode 100644
index 0000000000..880620544d
--- /dev/null
+++ b/Source/cmMakefile.cxx
@@ -0,0 +1,5511 @@
+/*============================================================================
+ 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 "cmMakefile.h"
+#include "cmVersion.h"
+#include "cmCommand.h"
+#include "cmSourceFile.h"
+#include "cmSourceFileLocation.h"
+#include "cmSystemTools.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmCommands.h"
+#include "cmCacheManager.h"
+#include "cmFunctionBlocker.h"
+#include "cmListFileCache.h"
+#include "cmCommandArgumentParserHelper.h"
+#include "cmGeneratorExpression.h"
+#include "cmTest.h"
+#ifdef CMAKE_BUILD_WITH_CMAKE
+# include "cmVariableWatch.h"
+#endif
+#include "cmInstallGenerator.h"
+#include "cmTestGenerator.h"
+#include "cmDefinitions.h"
+#include "cmake.h"
+#include <stdlib.h> // required for atoi
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/FStream.hxx>
+#include <cmsys/auto_ptr.hxx>
+
+#include <stack>
+#include <ctype.h> // for isspace
+#include <assert.h>
+
+class cmMakefile::Internals
+{
+public:
+ std::stack<cmDefinitions, std::list<cmDefinitions> > VarStack;
+ std::stack<std::set<std::string> > VarInitStack;
+ std::stack<std::set<std::string> > VarUsageStack;
+ bool IsSourceFileTryCompile;
+};
+
+// default is not to be building executables
+cmMakefile::cmMakefile(): Internal(new Internals)
+{
+ const cmDefinitions& defs = cmDefinitions();
+ const std::set<std::string> globalKeys = defs.LocalKeys();
+ this->Internal->VarStack.push(defs);
+ this->Internal->VarInitStack.push(globalKeys);
+ this->Internal->VarUsageStack.push(globalKeys);
+ this->Internal->IsSourceFileTryCompile = false;
+
+ // Initialize these first since AddDefaultDefinitions calls AddDefinition
+ this->WarnUnused = false;
+ this->CheckSystemVars = false;
+
+ // Setup the default include file regular expression (match everything).
+ this->IncludeFileRegularExpression = "^.*$";
+ // 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->LocalGenerator = 0;
+
+ this->AddDefaultDefinitions();
+ this->Initialize();
+ this->PreOrder = false;
+ this->GeneratingBuildSystem = false;
+
+ this->NumLastMatches = 0;
+ this->SuppressWatches = false;
+}
+
+cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
+{
+ this->Internal->VarStack.push(mf.Internal->VarStack.top().Closure());
+ this->Internal->VarInitStack.push(mf.Internal->VarInitStack.top());
+ this->Internal->VarUsageStack.push(mf.Internal->VarUsageStack.top());
+
+ this->Prefix = mf.Prefix;
+ this->AuxSourceDirectories = mf.AuxSourceDirectories;
+ this->cmStartDirectory = mf.cmStartDirectory;
+ this->StartOutputDirectory = mf.StartOutputDirectory;
+ this->cmHomeDirectory = mf.cmHomeDirectory;
+ this->HomeOutputDirectory = mf.HomeOutputDirectory;
+ this->cmCurrentListFile = mf.cmCurrentListFile;
+ this->ProjectName = mf.ProjectName;
+ this->Targets = mf.Targets;
+ this->SourceFiles = mf.SourceFiles;
+ this->Tests = mf.Tests;
+ this->LinkDirectories = mf.LinkDirectories;
+ this->SystemIncludeDirectories = mf.SystemIncludeDirectories;
+ this->ListFiles = mf.ListFiles;
+ this->OutputFiles = mf.OutputFiles;
+ this->LinkLibraries = mf.LinkLibraries;
+ this->InstallGenerators = mf.InstallGenerators;
+ this->TestGenerators = mf.TestGenerators;
+ this->IncludeFileRegularExpression = mf.IncludeFileRegularExpression;
+ this->ComplainFileRegularExpression = mf.ComplainFileRegularExpression;
+ this->SourceFileExtensions = mf.SourceFileExtensions;
+ this->HeaderFileExtensions = mf.HeaderFileExtensions;
+ this->DefineFlags = mf.DefineFlags;
+ this->DefineFlagsOrig = mf.DefineFlagsOrig;
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ this->SourceGroups = mf.SourceGroups;
+#endif
+
+ this->LocalGenerator = mf.LocalGenerator;
+ this->FunctionBlockers = mf.FunctionBlockers;
+ this->MacrosMap = mf.MacrosMap;
+ this->SubDirectoryOrder = mf.SubDirectoryOrder;
+ this->Properties = mf.Properties;
+ this->PreOrder = mf.PreOrder;
+ this->WarnUnused = mf.WarnUnused;
+ this->Initialize();
+ this->CheckSystemVars = mf.CheckSystemVars;
+ this->ListFileStack = mf.ListFileStack;
+ this->OutputToSource = mf.OutputToSource;
+
+ this->NumLastMatches = mf.NumLastMatches;
+ this->SuppressWatches = mf.SuppressWatches;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::Initialize()
+{
+ 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/.+-]+@)");
+ this->cmNamedCurly.compile("^[A-Za-z0-9/_.+-]+{");
+
+ // Enter a policy level for this directory.
+ this->PushPolicy();
+
+ // Protect the directory-level policies.
+ this->PushPolicyBarrier();
+
+ // By default the check is not done. It is enabled by
+ // cmListFileCache in the top level if necessary.
+ this->CheckCMP0000 = false;
+}
+
+unsigned int cmMakefile::GetCacheMajorVersion() const
+{
+ return this->GetCacheManager()->GetCacheMajorVersion();
+}
+
+unsigned int cmMakefile::GetCacheMinorVersion() const
+{
+ return this->GetCacheManager()->GetCacheMinorVersion();
+}
+
+bool cmMakefile::NeedCacheCompatibility(int major, int minor) const
+{
+ return this->GetCacheManager()->NeedCacheCompatibility(major, minor);
+}
+
+cmMakefile::~cmMakefile()
+{
+ for(std::vector<cmInstallGenerator*>::iterator
+ i = this->InstallGenerators.begin();
+ i != this->InstallGenerators.end(); ++i)
+ {
+ delete *i;
+ }
+ for(std::vector<cmTestGenerator*>::iterator
+ i = this->TestGenerators.begin();
+ i != this->TestGenerators.end(); ++i)
+ {
+ delete *i;
+ }
+ for(std::vector<cmSourceFile*>::iterator i = this->SourceFiles.begin();
+ i != this->SourceFiles.end(); ++i)
+ {
+ delete *i;
+ }
+ for(std::map<std::string, cmTest*>::iterator i = this->Tests.begin();
+ i != this->Tests.end(); ++i)
+ {
+ delete i->second;
+ }
+ for(std::vector<cmTarget*>::iterator
+ i = this->ImportedTargetsOwned.begin();
+ i != this->ImportedTargetsOwned.end(); ++i)
+ {
+ delete *i;
+ }
+ for(unsigned int i=0; i < this->FinalPassCommands.size(); i++)
+ {
+ delete this->FinalPassCommands[i];
+ }
+ std::vector<cmFunctionBlocker*>::iterator pos;
+ for (pos = this->FunctionBlockers.begin();
+ pos != this->FunctionBlockers.end(); ++pos)
+ {
+ cmFunctionBlocker* b = *pos;
+ delete b;
+ }
+ this->FunctionBlockers.clear();
+ if (this->PolicyStack.size() != 1)
+ {
+ cmSystemTools::Error("Internal CMake Error, Policy Stack has not been"
+ " popped properly");
+ }
+}
+
+void cmMakefile::PrintStringVector(const char* s,
+ const std::vector<std::string>& v) const
+{
+ std::cout << s << ": ( \n";
+ for(std::vector<std::string>::const_iterator i = v.begin();
+ i != v.end(); ++i)
+ {
+ std::cout << *i << " ";
+ }
+ std::cout << " )\n";
+}
+
+void cmMakefile
+::PrintStringVector(const char* s,
+ const std::vector<std::pair<std::string, bool> >& v) const
+{
+ std::cout << s << ": ( \n";
+ for(std::vector<std::pair<std::string, bool> >::const_iterator i
+ = v.begin(); i != v.end(); ++i)
+ {
+ std::cout << i->first << " " << i->second;
+ }
+ std::cout << " )\n";
+}
+
+
+// call print on all the classes in the makefile
+void cmMakefile::Print() const
+{
+ // print the class lists
+ std::cout << "classes:\n";
+
+ std::cout << " this->Targets: ";
+ for (cmTargets::iterator l = this->Targets.begin();
+ l != this->Targets.end(); l++)
+ {
+ std::cout << l->first << std::endl;
+ }
+
+ std::cout << " this->StartOutputDirectory; " <<
+ this->StartOutputDirectory << std::endl;
+ std::cout << " this->HomeOutputDirectory; " <<
+ this->HomeOutputDirectory << std::endl;
+ std::cout << " this->cmStartDirectory; " <<
+ this->cmStartDirectory << std::endl;
+ std::cout << " this->cmHomeDirectory; " <<
+ this->cmHomeDirectory << std::endl;
+ std::cout << " this->ProjectName; "
+ << this->ProjectName << std::endl;
+ this->PrintStringVector("this->LinkDirectories", this->LinkDirectories);
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ for( std::vector<cmSourceGroup>::const_iterator i =
+ this->SourceGroups.begin(); i != this->SourceGroups.end(); ++i)
+ {
+ std::cout << "Source Group: " << i->GetName() << std::endl;
+ }
+#endif
+}
+
+bool cmMakefile::CommandExists(const char* name) const
+{
+ return this->GetCMakeInstance()->CommandExists(name);
+}
+
+
+//----------------------------------------------------------------------------
+void cmMakefile::IssueMessage(cmake::MessageType t,
+ std::string const& text) const
+{
+ // Collect context information.
+ cmLocalGenerator* localGen = this->GetLocalGenerator();
+ if(this->CallStack.empty() && this->GetCMakeInstance()->GetIsInTryCompile())
+ {
+ localGen = 0;
+ }
+ cmListFileBacktrace backtrace(localGen);
+ if(!this->CallStack.empty())
+ {
+ if((t == cmake::FATAL_ERROR) || (t == cmake::INTERNAL_ERROR))
+ {
+ this->CallStack.back().Status->SetNestedError(true);
+ }
+ backtrace = this->GetBacktrace();
+ }
+ else
+ {
+ cmListFileContext lfc;
+ if(this->ListFileStack.empty())
+ {
+ // We are not processing the project. Add the directory-level context.
+ lfc.FilePath = this->GetCurrentDirectory();
+ lfc.FilePath += "/CMakeLists.txt";
+ }
+ else
+ {
+ // We are processing the project but are not currently executing a
+ // command. Add whatever context information we have.
+ lfc.FilePath = this->ListFileStack.back();
+ }
+ lfc.Line = 0;
+ backtrace.push_back(lfc);
+ }
+
+ // Issue the message.
+ this->GetCMakeInstance()->IssueMessage(t, text, backtrace);
+}
+
+//----------------------------------------------------------------------------
+cmListFileBacktrace cmMakefile::GetBacktrace() const
+{
+ cmListFileBacktrace backtrace(this->GetLocalGenerator());
+ for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin();
+ i != this->CallStack.rend(); ++i)
+ {
+ backtrace.push_back(*i->Context);
+ }
+ return backtrace;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const
+{
+ cmOStringStream msg;
+ msg << lff.FilePath << "(" << lff.Line << "): ";
+ msg << lff.Name << "(";
+ for(std::vector<cmListFileArgument>::const_iterator i =
+ lff.Arguments.begin(); i != lff.Arguments.end(); ++i)
+ {
+ msg << i->Value;
+ msg << " ";
+ }
+ msg << ")";
+ cmSystemTools::Message(msg.str().c_str());
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
+ cmExecutionStatus &status)
+{
+ bool result = true;
+
+ // quick return if blocked
+ if(this->IsFunctionBlocked(lff,status))
+ {
+ // No error.
+ return result;
+ }
+
+ std::string name = lff.Name;
+
+ // Place this call on the call stack.
+ cmMakefileCall stack_manager(this, lff, status);
+ static_cast<void>(stack_manager);
+
+ // Lookup the command prototype.
+ if(cmCommand* proto = this->GetCMakeInstance()->GetCommand(name))
+ {
+ // Clone the prototype.
+ cmsys::auto_ptr<cmCommand> pcmd(proto->Clone());
+ pcmd->SetMakefile(this);
+
+ // Decide whether to invoke the command.
+ if(pcmd->GetEnabled() && !cmSystemTools::GetFatalErrorOccured() &&
+ (this->GetCMakeInstance()->GetWorkingMode() != cmake::SCRIPT_MODE
+ || pcmd->IsScriptable()))
+
+ {
+ // if trace is enabled, print out invoke information
+ if(this->GetCMakeInstance()->GetTrace())
+ {
+ this->PrintCommandTrace(lff);
+ }
+ // Try invoking the command.
+ if(!pcmd->InvokeInitialPass(lff.Arguments,status) ||
+ status.GetNestedError())
+ {
+ if(!status.GetNestedError())
+ {
+ // The command invocation requested that we report an error.
+ this->IssueMessage(cmake::FATAL_ERROR, pcmd->GetError());
+ }
+ result = false;
+ if ( this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ }
+ }
+ else if(pcmd->HasFinalPass())
+ {
+ // use the command
+ this->FinalPassCommands.push_back(pcmd.release());
+ }
+ }
+ else if ( this->GetCMakeInstance()->GetWorkingMode() == cmake::SCRIPT_MODE
+ && !pcmd->IsScriptable() )
+ {
+ std::string error = "Command ";
+ error += pcmd->GetName();
+ error += "() is not scriptable";
+ this->IssueMessage(cmake::FATAL_ERROR, error);
+ result = false;
+ cmSystemTools::SetFatalErrorOccured();
+ }
+ }
+ else
+ {
+ if(!cmSystemTools::GetFatalErrorOccured())
+ {
+ std::string error = "Unknown CMake command \"";
+ error += lff.Name;
+ error += "\".";
+ this->IssueMessage(cmake::FATAL_ERROR, error);
+ result = false;
+ cmSystemTools::SetFatalErrorOccured();
+ }
+ }
+
+ return result;
+}
+
+//----------------------------------------------------------------------------
+class cmMakefile::IncludeScope
+{
+public:
+ IncludeScope(cmMakefile* mf, const char* fname, bool noPolicyScope);
+ ~IncludeScope();
+ void Quiet() { this->ReportError = false; }
+private:
+ cmMakefile* Makefile;
+ const char* File;
+ bool NoPolicyScope;
+ bool CheckCMP0011;
+ bool ReportError;
+ void EnforceCMP0011();
+};
+
+//----------------------------------------------------------------------------
+cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf, const char* fname,
+ bool noPolicyScope):
+ Makefile(mf), File(fname), NoPolicyScope(noPolicyScope),
+ CheckCMP0011(false), ReportError(true)
+{
+ if(!this->NoPolicyScope)
+ {
+ // Check CMP0011 to determine the policy scope type.
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0011))
+ {
+ case cmPolicies::WARN:
+ // We need to push a scope to detect whether the script sets
+ // any policies that would affect the includer and therefore
+ // requires a warning. We use a weak scope to simulate OLD
+ // behavior by allowing policy changes to affect the includer.
+ this->Makefile->PushPolicy(true);
+ this->CheckCMP0011 = true;
+ break;
+ case cmPolicies::OLD:
+ // OLD behavior is to not push a scope at all.
+ this->NoPolicyScope = true;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ // We should never make this policy required, but we handle it
+ // here just in case.
+ this->CheckCMP0011 = true;
+ case cmPolicies::NEW:
+ // NEW behavior is to push a (strong) scope.
+ this->Makefile->PushPolicy();
+ break;
+ }
+ }
+
+ // The included file cannot pop our policy scope.
+ this->Makefile->PushPolicyBarrier();
+}
+
+//----------------------------------------------------------------------------
+cmMakefile::IncludeScope::~IncludeScope()
+{
+ // Enforce matching policy scopes inside the included file.
+ this->Makefile->PopPolicyBarrier(this->ReportError);
+
+ if(!this->NoPolicyScope)
+ {
+ // If we need to enforce policy CMP0011 then the top entry is the
+ // one we pushed above. If the entry is empty, then the included
+ // script did not set any policies that might affect the includer so
+ // we do not need to enforce the policy.
+ if(this->CheckCMP0011 && this->Makefile->PolicyStack.back().empty())
+ {
+ this->CheckCMP0011 = false;
+ }
+
+ // Pop the scope we pushed for the script.
+ this->Makefile->PopPolicy();
+
+ // We enforce the policy after the script's policy stack entry has
+ // been removed.
+ if(this->CheckCMP0011)
+ {
+ this->EnforceCMP0011();
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::IncludeScope::EnforceCMP0011()
+{
+ // We check the setting of this policy again because the included
+ // script might actually set this policy for its includer.
+ cmPolicies* policies = this->Makefile->GetPolicies();
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0011))
+ {
+ case cmPolicies::WARN:
+ // Warn because the user did not set this policy.
+ {
+ cmOStringStream w;
+ w << policies->GetPolicyWarning(cmPolicies::CMP0011) << "\n"
+ << "The included script\n " << this->File << "\n"
+ << "affects policy settings. "
+ << "CMake is implying the NO_POLICY_SCOPE option for compatibility, "
+ << "so the effects are applied to the including context.";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ {
+ cmOStringStream e;
+ e << policies->GetRequiredPolicyError(cmPolicies::CMP0011) << "\n"
+ << "The included script\n " << this->File << "\n"
+ << "affects policy settings, so it requires this policy to be set.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ break;
+ case cmPolicies::OLD:
+ case cmPolicies::NEW:
+ // The script set this policy. We assume the purpose of the
+ // script is to initialize policies for its includer, and since
+ // the policy is now set for later scripts, we do not warn.
+ break;
+ }
+}
+
+//----------------------------------------------------------------------------
+// Parse the given CMakeLists.txt file executing all commands
+//
+bool cmMakefile::ReadListFile(const char* filename_in,
+ const char *external_in,
+ std::string* fullPath,
+ bool noPolicyScope)
+{
+ std::string currentParentFile
+ = this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE");
+ std::string currentFile
+ = this->GetSafeDefinition("CMAKE_CURRENT_LIST_FILE");
+ this->AddDefinition("CMAKE_PARENT_LIST_FILE", filename_in);
+ this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE");
+
+ const char* external = 0;
+ std::string external_abs;
+
+ const char* filename = filename_in;
+ std::string filename_abs;
+
+ if (external_in)
+ {
+ external_abs =
+ cmSystemTools::CollapseFullPath(external_in,
+ this->cmStartDirectory.c_str());
+ external = external_abs.c_str();
+ if (filename_in)
+ {
+ filename_abs =
+ cmSystemTools::CollapseFullPath(filename_in,
+ this->cmStartDirectory.c_str());
+ filename = filename_abs.c_str();
+ }
+ }
+
+ // keep track of the current file being read
+ if (filename)
+ {
+ if(this->cmCurrentListFile != filename)
+ {
+ this->cmCurrentListFile = filename;
+ }
+ }
+
+ // Now read the input file
+ const char *filenametoread= filename;
+
+ if( external)
+ {
+ filenametoread= external;
+ }
+
+ this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread);
+ this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
+ this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
+ cmSystemTools::GetFilenamePath(filenametoread).c_str());
+ this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
+
+ // try to see if the list file is the top most
+ // list file for a project, and if it is, then it
+ // must have a project command. If there is not
+ // one, then cmake will provide one via the
+ // cmListFileCache class.
+ bool requireProjectCommand = false;
+ if(!external && this->cmStartDirectory == this->cmHomeDirectory)
+ {
+ if(cmSystemTools::LowerCase(
+ cmSystemTools::GetFilenameName(filename)) == "cmakelists.txt")
+ {
+ requireProjectCommand = true;
+ }
+ }
+
+ // push the listfile onto the stack
+ this->ListFileStack.push_back(filenametoread);
+ if(fullPath!=0)
+ {
+ *fullPath=filenametoread;
+ }
+ cmListFile cacheFile;
+ if( !cacheFile.ParseFile(filenametoread, requireProjectCommand, this) )
+ {
+ // pop the listfile off the stack
+ this->ListFileStack.pop_back();
+ if(fullPath!=0)
+ {
+ *fullPath = "";
+ }
+ this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
+ this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE");
+ this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
+ this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
+ this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
+ cmSystemTools::GetFilenamePath(currentFile).c_str());
+ this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
+ return false;
+ }
+ // add this list file to the list of dependencies
+ this->ListFiles.push_back( filenametoread);
+
+ // Enforce balanced blocks (if/endif, function/endfunction, etc.).
+ {
+ LexicalPushPop lexScope(this);
+ IncludeScope incScope(this, filenametoread, noPolicyScope);
+
+ // Run the parsed commands.
+ const size_t numberFunctions = cacheFile.Functions.size();
+ for(size_t i =0; i < numberFunctions; ++i)
+ {
+ cmExecutionStatus status;
+ this->ExecuteCommand(cacheFile.Functions[i],status);
+ if(cmSystemTools::GetFatalErrorOccured())
+ {
+ // Exit early due to error.
+ lexScope.Quiet();
+ incScope.Quiet();
+ break;
+ }
+ if(status.GetReturnInvoked())
+ {
+ // Exit early due to return command.
+ break;
+ }
+ }
+ }
+
+ // If this is the directory-level CMakeLists.txt file then perform
+ // some extra checks.
+ if(this->ListFileStack.size() == 1)
+ {
+ this->EnforceDirectoryLevelRules();
+ }
+
+ this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
+ this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE");
+ this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
+ this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
+ this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
+ cmSystemTools::GetFilenamePath(currentFile).c_str());
+ this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
+
+ // pop the listfile off the stack
+ this->ListFileStack.pop_back();
+
+ // Check for unused variables
+ this->CheckForUnusedVariables();
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::EnforceDirectoryLevelRules() const
+{
+ // Diagnose a violation of CMP0000 if necessary.
+ if(this->CheckCMP0000)
+ {
+ cmOStringStream msg;
+ msg << "No cmake_minimum_required command is present. "
+ << "A line of code such as\n"
+ << " cmake_minimum_required(VERSION "
+ << cmVersion::GetMajorVersion() << "."
+ << cmVersion::GetMinorVersion()
+ << ")\n"
+ << "should be added at the top of the file. "
+ << "The version specified may be lower if you wish to "
+ << "support older CMake versions for this project. "
+ << "For more information run "
+ << "\"cmake --help-policy CMP0000\".";
+ switch (this->GetPolicyStatus(cmPolicies::CMP0000))
+ {
+ case cmPolicies::WARN:
+ // Warn because the user did not provide a mimimum required
+ // version.
+ this->IssueMessage(cmake::AUTHOR_WARNING, msg.str());
+ case cmPolicies::OLD:
+ // OLD behavior is to use policy version 2.4 set in
+ // cmListFileCache.
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ // NEW behavior is to issue an error.
+ this->IssueMessage(cmake::FATAL_ERROR, msg.str());
+ cmSystemTools::SetFatalErrorOccured();
+ return;
+ }
+ }
+}
+
+void cmMakefile::AddCommand(cmCommand* wg)
+{
+ this->GetCMakeInstance()->AddCommand(wg);
+}
+
+// Set the make file
+void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg)
+{
+ this->LocalGenerator = lg;
+ // the source groups need to access the global generator
+ // so don't create them until the lg is set
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ this->AddSourceGroup("", "^.*$");
+ this->AddSourceGroup
+ ("Source Files",
+ "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|f|f90|for|fpp"
+ "|ftn|m|mm|rc|def|r|odl|idl|hpj|bat)$");
+ this->AddSourceGroup("Header Files", CM_HEADER_REGEX);
+ this->AddSourceGroup("CMake Rules", "\\.rule$");
+ this->AddSourceGroup("Resources", "\\.plist$");
+ this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$");
+#endif
+
+ this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
+ this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
+}
+
+namespace
+{
+ struct file_not_persistent
+ {
+ bool operator()(const std::string& path) const
+ {
+ return !(path.find("CMakeTmp") == path.npos &&
+ cmSystemTools::FileExists(path.c_str()));
+ }
+ };
+}
+
+void cmMakefile::FinalPass()
+{
+ // do all the variable expansions here
+ this->ExpandVariablesCMP0019();
+
+ // give all the commands a chance to do something
+ // after the file has been parsed before generation
+ for(std::vector<cmCommand*>::iterator i = this->FinalPassCommands.begin();
+ i != this->FinalPassCommands.end(); ++i)
+ {
+ (*i)->FinalPass();
+ }
+
+ //go through all configured files and see which ones still exist.
+ //we don't want cmake to re-run if a configured file is created and deleted
+ //during processing as that would make it a transient file that can't
+ //influence the build process
+
+ //remove_if will move all items that don't have a valid file name to the
+ //back of the vector
+ std::vector<std::string>::iterator new_output_files_end = std::remove_if(
+ this->OutputFiles.begin(),
+ this->OutputFiles.end(),
+ file_not_persistent() );
+ //we just have to erase all items at the back
+ this->OutputFiles.erase(new_output_files_end, this->OutputFiles.end() );
+
+ //if a configured file is used as input for another configured file,
+ //and then deleted it will show up in the input list files so we
+ //need to scan those too
+ std::vector<std::string>::iterator new_list_files_end = std::remove_if(
+ this->ListFiles.begin(),
+ this->ListFiles.end(),
+ file_not_persistent() );
+
+ this->ListFiles.erase(new_list_files_end, this->ListFiles.end() );
+}
+
+// Generate the output file
+void cmMakefile::ConfigureFinalPass()
+{
+ this->FinalPass();
+ const char* oldValue
+ = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
+ if (oldValue && cmSystemTools::VersionCompare(
+ cmSystemTools::OP_LESS, oldValue, "2.4"))
+ {
+ this->IssueMessage(
+ cmake::FATAL_ERROR,
+ "You have set CMAKE_BACKWARDS_COMPATIBILITY to a CMake version less "
+ "than 2.4. This version of CMake only supports backwards compatibility "
+ "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 (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ l->second.FinishConfigure();
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefile::AddCustomCommandToTarget(const std::string& target,
+ const std::vector<std::string>& depends,
+ const cmCustomCommandLines& commandLines,
+ cmTarget::CustomCommandType type,
+ const char* comment,
+ const char* workingDir,
+ bool escapeOldStyle) const
+{
+ // Find the target to which to add the custom command.
+ cmTargets::iterator ti = this->Targets.find(target);
+
+ if(ti == this->Targets.end())
+ {
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ bool issueMessage = false;
+ cmOStringStream e;
+ switch(this->GetPolicyStatus(cmPolicies::CMP0040))
+ {
+ case cmPolicies::WARN:
+ e << (this->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0040)) << "\n";
+ issueMessage = true;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ issueMessage = true;
+ messageType = cmake::FATAL_ERROR;
+ }
+
+ if(issueMessage)
+ {
+ e << "The target name \"" << target << "\" is unknown in this context.";
+ IssueMessage(messageType, e.str());
+ }
+
+ return;
+ }
+
+ if(ti->second.GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "Target \"" << target << "\" is an OBJECT library "
+ "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands.";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ if(ti->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "Target \"" << target << "\" is an INTERFACE library "
+ "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands.";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ // Add the command to the appropriate build step for the target.
+ std::vector<std::string> no_output;
+ cmCustomCommand cc(this, no_output, depends,
+ commandLines, comment, workingDir);
+ cc.SetEscapeOldStyle(escapeOldStyle);
+ cc.SetEscapeAllowMakeVars(true);
+ switch(type)
+ {
+ case cmTarget::PRE_BUILD:
+ ti->second.AddPreBuildCommand(cc);
+ break;
+ case cmTarget::PRE_LINK:
+ ti->second.AddPreLinkCommand(cc);
+ break;
+ case cmTarget::POST_BUILD:
+ ti->second.AddPostBuildCommand(cc);
+ break;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmSourceFile*
+cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs,
+ const std::vector<std::string>& depends,
+ const std::string& main_dependency,
+ const cmCustomCommandLines& commandLines,
+ const char* comment,
+ const char* workingDir,
+ bool replace,
+ bool escapeOldStyle)
+{
+ // Make sure there is at least one output.
+ if(outputs.empty())
+ {
+ cmSystemTools::Error("Attempt to add a custom rule with no output!");
+ return 0;
+ }
+
+ // Validate custom commands. TODO: More strict?
+ for(cmCustomCommandLines::const_iterator i=commandLines.begin();
+ i != commandLines.end(); ++i)
+ {
+ cmCustomCommandLine const& cl = *i;
+ if(!cl.empty() && !cl[0].empty() && cl[0][0] == '"')
+ {
+ cmOStringStream e;
+ e << "COMMAND may not contain literal quotes:\n " << cl[0] << "\n";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return 0;
+ }
+ }
+
+ // Choose a source file on which to store the custom command.
+ cmSourceFile* file = 0;
+ if(!commandLines.empty() && !main_dependency.empty())
+ {
+ // The main dependency was specified. Use it unless a different
+ // custom command already used it.
+ file = this->GetSource(main_dependency);
+ if(file && file->GetCustomCommand() && !replace)
+ {
+ // The main dependency already has a custom command.
+ if(commandLines == file->GetCustomCommand()->GetCommandLines())
+ {
+ // The existing custom command is identical. Silently ignore
+ // the duplicate.
+ return file;
+ }
+ else
+ {
+ // The existing custom command is different. We need to
+ // generate a rule file for this new command.
+ file = 0;
+ }
+ }
+ else if (!file)
+ {
+ file = this->CreateSource(main_dependency);
+ }
+ }
+
+ // Generate a rule file if the main dependency is not available.
+ if(!file)
+ {
+ cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
+
+ // Construct a rule file associated with the first output produced.
+ std::string outName = gg->GenerateRuleFile(outputs[0]);
+
+ // Check if the rule file already exists.
+ file = this->GetSource(outName);
+ if(file && file->GetCustomCommand() && !replace)
+ {
+ // The rule file already exists.
+ if(commandLines != file->GetCustomCommand()->GetCommandLines())
+ {
+ cmSystemTools::Error("Attempt to add a custom rule to output \"",
+ outName.c_str(),
+ "\" which already has a custom rule.");
+ }
+ return file;
+ }
+
+ // Create a cmSourceFile for the rule file.
+ if (!file)
+ {
+ file = this->CreateSource(outName, true);
+ }
+ file->SetProperty("__CMAKE_RULE", "1");
+ }
+
+ // Always create the output sources and mark them generated.
+ for(std::vector<std::string>::const_iterator o = outputs.begin();
+ o != outputs.end(); ++o)
+ {
+ if(cmSourceFile* out = this->GetOrCreateSource(*o, true))
+ {
+ out->SetProperty("GENERATED", "1");
+ }
+ }
+
+ // Attach the custom command to the file.
+ if(file)
+ {
+ // Construct a complete list of dependencies.
+ std::vector<std::string> depends2(depends);
+ if(!main_dependency.empty())
+ {
+ depends2.push_back(main_dependency);
+ }
+
+ cmCustomCommand* cc =
+ new cmCustomCommand(this, outputs, depends2, commandLines,
+ comment, workingDir);
+ cc->SetEscapeOldStyle(escapeOldStyle);
+ cc->SetEscapeAllowMakeVars(true);
+ file->SetCustomCommand(cc);
+ this->UpdateOutputToSourceMap(outputs, file);
+ }
+ return file;
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefile::UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
+ cmSourceFile* source)
+{
+ for(std::vector<std::string>::const_iterator o = outputs.begin();
+ o != outputs.end(); ++o)
+ {
+ this->UpdateOutputToSourceMap(*o, source);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefile::UpdateOutputToSourceMap(std::string const& output,
+ cmSourceFile* source)
+{
+ OutputToSourceMap::iterator i = this->OutputToSource.find(output);
+ if(i != this->OutputToSource.end())
+ {
+ // Multiple custom commands produce the same output but may
+ // be attached to a different source file (MAIN_DEPENDENCY).
+ // LinearGetSourceFileWithOutput would return the first one,
+ // so keep the mapping for the first one.
+ //
+ // TODO: Warn the user about this case. However, the VS 8 generator
+ // triggers it for separate generate.stamp rules in ZERO_CHECK and
+ // individual targets.
+ return;
+ }
+ this->OutputToSource[output] = source;
+}
+
+//----------------------------------------------------------------------------
+cmSourceFile*
+cmMakefile::AddCustomCommandToOutput(const std::string& output,
+ const std::vector<std::string>& depends,
+ const std::string& main_dependency,
+ const cmCustomCommandLines& commandLines,
+ const char* comment,
+ const char* workingDir,
+ bool replace,
+ bool escapeOldStyle)
+{
+ std::vector<std::string> outputs;
+ outputs.push_back(output);
+ return this->AddCustomCommandToOutput(outputs, depends, main_dependency,
+ commandLines, comment, workingDir,
+ replace, escapeOldStyle);
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefile::AddCustomCommandOldStyle(const std::string& target,
+ const std::vector<std::string>& outputs,
+ const std::vector<std::string>& depends,
+ const std::string& source,
+ const cmCustomCommandLines& commandLines,
+ const char* comment)
+{
+ // Translate the old-style signature to one of the new-style
+ // signatures.
+ if(source == target)
+ {
+ // In the old-style signature if the source and target were the
+ // same then it added a post-build rule to the target. Preserve
+ // this behavior.
+ this->AddCustomCommandToTarget(target, depends, commandLines,
+ cmTarget::POST_BUILD, comment, 0);
+ return;
+ }
+
+ // Each output must get its own copy of this rule.
+ cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|"
+ "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|"
+ "hm|hpp|hxx|in|txx|inl)$");
+ for(std::vector<std::string>::const_iterator oi = outputs.begin();
+ oi != outputs.end(); ++oi)
+ {
+ // Get the name of this output.
+ const char* output = oi->c_str();
+ cmSourceFile* sf;
+
+ // Choose whether to use a main dependency.
+ if(sourceFiles.find(source))
+ {
+ // The source looks like a real file. Use it as the main dependency.
+ sf = this->AddCustomCommandToOutput(output, depends, source,
+ commandLines, comment, 0);
+ }
+ else
+ {
+ // The source may not be a real file. Do not use a main dependency.
+ std::string no_main_dependency = "";
+ std::vector<std::string> depends2 = depends;
+ depends2.push_back(source);
+ sf = this->AddCustomCommandToOutput(output, depends2, no_main_dependency,
+ commandLines, comment, 0);
+ }
+
+ // If the rule was added to the source (and not a .rule file),
+ // then add the source to the target to make sure the rule is
+ // included.
+ if(sf && !sf->GetPropertyAsBool("__CMAKE_RULE"))
+ {
+ if (this->Targets.find(target) != this->Targets.end())
+ {
+ this->Targets[target].AddSource(sf->GetFullPath());
+ }
+ else
+ {
+ cmSystemTools::Error("Attempt to add a custom rule to a target "
+ "that does not exist yet for target ",
+ target.c_str());
+ return;
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::AddUtilityCommand(const std::string& utilityName,
+ bool excludeFromAll,
+ const std::vector<std::string>& depends,
+ const char* workingDirectory,
+ const char* command,
+ const char* arg1,
+ const char* arg2,
+ const char* arg3,
+ const char* arg4)
+{
+ // Construct the command line for the custom command.
+ cmCustomCommandLine commandLine;
+ commandLine.push_back(command);
+ if(arg1)
+ {
+ commandLine.push_back(arg1);
+ }
+ if(arg2)
+ {
+ commandLine.push_back(arg2);
+ }
+ if(arg3)
+ {
+ commandLine.push_back(arg3);
+ }
+ if(arg4)
+ {
+ commandLine.push_back(arg4);
+ }
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+
+ // Call the real signature of this method.
+ this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
+ depends, commandLines);
+}
+
+//----------------------------------------------------------------------------
+cmTarget*
+cmMakefile::AddUtilityCommand(const std::string& utilityName,
+ bool excludeFromAll,
+ const char* workingDirectory,
+ const std::vector<std::string>& depends,
+ const cmCustomCommandLines& commandLines,
+ bool escapeOldStyle, const char* comment)
+{
+ // Create a target instance for this utility.
+ cmTarget* target = this->AddNewTarget(cmTarget::UTILITY, utilityName);
+ if (excludeFromAll)
+ {
+ target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
+ }
+ if(!comment)
+ {
+ // Use an empty comment to avoid generation of default comment.
+ comment = "";
+ }
+
+ // Store the custom command in the target.
+ if (!commandLines.empty() || !depends.empty())
+ {
+ std::string force = this->GetStartOutputDirectory();
+ force += cmake::GetCMakeFilesDirectory();
+ force += "/";
+ force += utilityName;
+ std::string no_main_dependency = "";
+ bool no_replace = false;
+ this->AddCustomCommandToOutput(force, depends,
+ no_main_dependency,
+ commandLines, comment,
+ workingDirectory, no_replace,
+ escapeOldStyle);
+ cmSourceFile* sf = target->AddSourceCMP0049(force);
+
+ // The output is not actually created so mark it symbolic.
+ if(sf)
+ {
+ sf->SetProperty("SYMBOLIC", "1");
+ }
+ else
+ {
+ cmSystemTools::Error("Could not get source file entry for ",
+ force.c_str());
+ }
+ }
+ return target;
+}
+
+void cmMakefile::AddDefineFlag(const char* flag)
+{
+ if (!flag)
+ {
+ return;
+ }
+
+ // Update the string used for the old DEFINITIONS property.
+ this->AddDefineFlag(flag, this->DefineFlagsOrig);
+
+ // If this is really a definition, update COMPILE_DEFINITIONS.
+ if(this->ParseDefineFlag(flag, false))
+ {
+ return;
+ }
+
+ // Add this flag that does not look like a definition.
+ this->AddDefineFlag(flag, this->DefineFlags);
+}
+
+void cmMakefile::AddDefineFlag(const char* flag, std::string& dflags)
+{
+ // remove any \n\r
+ std::string ret = flag;
+ std::string::size_type pos = 0;
+ while((pos = ret.find('\n', pos)) != std::string::npos)
+ {
+ ret[pos] = ' ';
+ pos++;
+ }
+ pos = 0;
+ while((pos = ret.find('\r', pos)) != std::string::npos)
+ {
+ ret[pos] = ' ';
+ pos++;
+ }
+
+ dflags += " ";
+ dflags += ret;
+}
+
+
+void cmMakefile::RemoveDefineFlag(const char* flag)
+{
+ // Check the length of the flag to remove.
+ std::string::size_type len = strlen(flag);
+ if(len < 1)
+ {
+ return;
+ }
+
+ // Update the string used for the old DEFINITIONS property.
+ this->RemoveDefineFlag(flag, len, this->DefineFlagsOrig);
+
+ // If this is really a definition, update COMPILE_DEFINITIONS.
+ if(this->ParseDefineFlag(flag, true))
+ {
+ return;
+ }
+
+ // Remove this flag that does not look like a definition.
+ this->RemoveDefineFlag(flag, len, this->DefineFlags);
+}
+
+void cmMakefile::RemoveDefineFlag(const char* flag,
+ std::string::size_type len,
+ std::string& dflags)
+{
+ // Remove all instances of the flag that are surrounded by
+ // whitespace or the beginning/end of the string.
+ for(std::string::size_type lpos = dflags.find(flag, 0);
+ lpos != std::string::npos; lpos = dflags.find(flag, lpos))
+ {
+ std::string::size_type rpos = lpos + len;
+ if((lpos <= 0 || isspace(dflags[lpos-1])) &&
+ (rpos >= dflags.size() || isspace(dflags[rpos])))
+ {
+ dflags.erase(lpos, len);
+ }
+ else
+ {
+ ++lpos;
+ }
+ }
+}
+
+void cmMakefile::AddCompileOption(const char* option)
+{
+ this->AppendProperty("COMPILE_OPTIONS", option);
+}
+
+bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
+{
+ // Create a regular expression to match valid definitions.
+ static cmsys::RegularExpression
+ valid("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=.*)?$");
+
+ // Make sure the definition matches.
+ if(!valid.find(def.c_str()))
+ {
+ return false;
+ }
+
+ // VS6 IDE does not support definition values with spaces in
+ // combination with '"', '$', or ';'.
+ if((this->LocalGenerator->GetGlobalGenerator()->GetName() ==
+ "Visual Studio 6") &&
+ (def.find(" ") != def.npos && def.find_first_of("\"$;") != def.npos))
+ {
+ return false;
+ }
+
+ // Definitions with non-trivial values require a policy check.
+ static cmsys::RegularExpression
+ trivial("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=[A-Za-z0-9_.]+)?$");
+ if(!trivial.find(def.c_str()))
+ {
+ // This definition has a non-trivial value.
+ switch(this->GetPolicyStatus(cmPolicies::CMP0005))
+ {
+ case cmPolicies::WARN:
+ this->IssueMessage(
+ cmake::AUTHOR_WARNING,
+ this->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0005)
+ );
+ case cmPolicies::OLD:
+ // OLD behavior is to not escape the value. We should not
+ // convert the definition to use the property.
+ return false;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ this->IssueMessage(
+ cmake::FATAL_ERROR,
+ this->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0005)
+ );
+ return false;
+ case cmPolicies::NEW:
+ // NEW behavior is to escape the value. Proceed to convert it
+ // to an entry in the property.
+ break;
+ }
+ }
+
+ // Get the definition part after the flag.
+ const char* define = def.c_str() + 2;
+
+ if(remove)
+ {
+ if(const char* cdefs = this->GetProperty("COMPILE_DEFINITIONS"))
+ {
+ // Expand the list.
+ std::vector<std::string> defs;
+ cmSystemTools::ExpandListArgument(cdefs, defs);
+
+ // Recompose the list without the definition.
+ std::string ndefs;
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator di = defs.begin();
+ di != defs.end(); ++di)
+ {
+ if(*di != define)
+ {
+ ndefs += sep;
+ sep = ";";
+ ndefs += *di;
+ }
+ }
+
+ // Store the new list.
+ this->SetProperty("COMPILE_DEFINITIONS", ndefs.c_str());
+ }
+ }
+ else
+ {
+ // Append the definition to the directory property.
+ this->AppendProperty("COMPILE_DEFINITIONS", define);
+ }
+
+ return true;
+}
+
+void cmMakefile::AddLinkLibrary(const std::string& lib,
+ cmTarget::LinkLibraryType llt)
+{
+ cmTarget::LibraryID tmp;
+ tmp.first = lib;
+ tmp.second = llt;
+ this->LinkLibraries.push_back(tmp);
+}
+
+void cmMakefile::AddLinkLibraryForTarget(const std::string& target,
+ const std::string& lib,
+ cmTarget::LinkLibraryType llt)
+{
+ cmTargets::iterator i = this->Targets.find(target);
+ if ( i != this->Targets.end())
+ {
+ cmTarget* tgt =
+ this->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(lib);
+ 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) ||
+ tgt->IsExecutableWithExports()))
+ {
+ cmOStringStream e;
+ e << "Target \"" << lib << "\" of type "
+ << cmTarget::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.";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ }
+ i->second.AddLinkLibrary( *this, target, lib, llt );
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "Attempt to add link library \""
+ << lib << "\" to target \""
+ << target << "\" which is not built in this directory.";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+}
+
+void cmMakefile::AddLinkDirectoryForTarget(const std::string& target,
+ const std::string& d)
+{
+ cmTargets::iterator i = this->Targets.find(target);
+ if ( i != this->Targets.end())
+ {
+ if(this->IsAlias(target))
+ {
+ cmOStringStream e;
+ e << "ALIAS target \"" << target << "\" "
+ << "may not be linked into another target.";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ i->second.AddLinkDirectory( d );
+ }
+ else
+ {
+ cmSystemTools::Error
+ ("Attempt to add link directories to non-existent target: ",
+ target.c_str(), " for directory ", d.c_str());
+ }
+}
+
+void cmMakefile::AddLinkLibrary(const std::string& lib)
+{
+ this->AddLinkLibrary(lib,cmTarget::GENERAL);
+}
+
+void cmMakefile::AddLinkDirectory(const std::string& dir)
+{
+ // Don't add a link directory that is already present. Yes, this
+ // linear search results in n^2 behavior, but n won't be getting
+ // much bigger than 20. We cannot use a set because of order
+ // dependency of the link search path.
+
+ if(dir.empty())
+ {
+ return;
+ }
+ std::string newdir = dir;
+ // remove trailing slashes
+ if(*dir.rbegin() == '/')
+ {
+ newdir = dir.substr(0, dir.size()-1);
+ }
+ if(std::find(this->LinkDirectories.begin(),
+ this->LinkDirectories.end(), newdir)
+ == this->LinkDirectories.end())
+ {
+ this->LinkDirectories.push_back(dir);
+ }
+}
+
+void cmMakefile::InitializeFromParent()
+{
+ cmMakefile *parent = this->LocalGenerator->GetParent()->GetMakefile();
+
+ // Initialize definitions with the closure of the parent scope.
+ this->Internal->VarStack.top() = parent->Internal->VarStack.top().Closure();
+
+ const std::vector<cmValueWithOrigin>& parentIncludes =
+ parent->GetIncludeDirectoriesEntries();
+ this->IncludeDirectoriesEntries.insert(this->IncludeDirectoriesEntries.end(),
+ parentIncludes.begin(),
+ parentIncludes.end());
+
+ const std::vector<cmValueWithOrigin>& parentOptions =
+ parent->GetCompileOptionsEntries();
+ this->CompileOptionsEntries.insert(this->CompileOptionsEntries.end(),
+ parentOptions.begin(),
+ parentOptions.end());
+
+ const std::vector<cmValueWithOrigin>& parentDefines =
+ parent->GetCompileDefinitionsEntries();
+ this->CompileDefinitionsEntries.insert(this->CompileDefinitionsEntries.end(),
+ parentDefines.begin(),
+ parentDefines.end());
+
+ this->SystemIncludeDirectories = parent->SystemIncludeDirectories;
+
+ // define flags
+ this->DefineFlags = parent->DefineFlags;
+ this->DefineFlagsOrig = parent->DefineFlagsOrig;
+
+ // Include transform property. There is no per-config version.
+ {
+ const char* prop = "IMPLICIT_DEPENDS_INCLUDE_TRANSFORM";
+ this->SetProperty(prop, parent->GetProperty(prop));
+ }
+
+ // compile definitions property and per-config versions
+ cmPolicies::PolicyStatus polSt = this->GetPolicyStatus(cmPolicies::CMP0043);
+ if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
+ {
+ this->SetProperty("COMPILE_DEFINITIONS",
+ parent->GetProperty("COMPILE_DEFINITIONS"));
+ std::vector<std::string> configs;
+ this->GetConfigurations(configs);
+ for(std::vector<std::string>::const_iterator ci = configs.begin();
+ ci != configs.end(); ++ci)
+ {
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += cmSystemTools::UpperCase(*ci);
+ const char* prop = parent->GetProperty(defPropName);
+ this->SetProperty(defPropName, prop);
+ }
+ }
+
+ // link libraries
+ this->LinkLibraries = parent->LinkLibraries;
+
+ // link directories
+ this->LinkDirectories = parent->LinkDirectories;
+
+ // the initial project name
+ this->ProjectName = parent->ProjectName;
+
+ // Copy include regular expressions.
+ this->IncludeFileRegularExpression = parent->IncludeFileRegularExpression;
+ this->ComplainFileRegularExpression = parent->ComplainFileRegularExpression;
+
+ // Imported targets.
+ this->ImportedTargets = parent->ImportedTargets;
+}
+
+void cmMakefile::ConfigureSubDirectory(cmLocalGenerator *lg2)
+{
+ // copy our variables from the child makefile
+ lg2->GetMakefile()->InitializeFromParent();
+ lg2->GetMakefile()->MakeStartDirectoriesCurrent();
+ if (this->GetCMakeInstance()->GetDebugOutput())
+ {
+ std::string msg=" Entering ";
+ msg += lg2->GetMakefile()->GetCurrentDirectory();
+ cmSystemTools::Message(msg.c_str());
+ }
+ // finally configure the subdir
+ lg2->Configure();
+ if (this->GetCMakeInstance()->GetDebugOutput())
+ {
+ std::string msg=" Returning to ";
+ msg += this->GetCurrentDirectory();
+ cmSystemTools::Message(msg.c_str());
+ }
+}
+
+void cmMakefile::AddSubDirectory(const std::string& sub,
+ bool excludeFromAll, bool preorder)
+{
+ // the source path must be made full if it isn't already
+ std::string srcPath = sub;
+ if (!cmSystemTools::FileIsFullPath(srcPath.c_str()))
+ {
+ srcPath = this->GetCurrentDirectory();
+ srcPath += "/";
+ srcPath += sub;
+ }
+
+ // binary path must be made full if it isn't already
+ std::string binPath = sub;
+ if (!cmSystemTools::FileIsFullPath(binPath.c_str()))
+ {
+ binPath = this->GetCurrentOutputDirectory();
+ binPath += "/";
+ binPath += sub;
+ }
+
+
+ this->AddSubDirectory(srcPath, binPath,
+ excludeFromAll, preorder, false);
+}
+
+
+void cmMakefile::AddSubDirectory(const std::string& srcPath,
+ const std::string& binPath,
+ bool excludeFromAll, bool preorder,
+ bool immediate)
+{
+ // Make sure the binary directory is unique.
+ if(!this->EnforceUniqueDir(srcPath, binPath))
+ {
+ return;
+ }
+
+ // create a new local generator and set its parent
+ cmLocalGenerator *lg2 =
+ this->LocalGenerator->GetGlobalGenerator()->CreateLocalGenerator();
+ lg2->SetParent(this->LocalGenerator);
+ this->LocalGenerator->GetGlobalGenerator()->AddLocalGenerator(lg2);
+
+ // set the subdirs start dirs
+ lg2->GetMakefile()->SetStartDirectory(srcPath);
+ lg2->GetMakefile()->SetStartOutputDirectory(binPath);
+ if(excludeFromAll)
+ {
+ lg2->GetMakefile()->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
+ }
+ lg2->GetMakefile()->SetPreOrder(preorder);
+
+ if (immediate)
+ {
+ this->ConfigureSubDirectory(lg2);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::AddIncludeDirectories(const std::vector<std::string> &incs,
+ bool before)
+{
+ if (incs.empty())
+ {
+ return;
+ }
+
+ std::string incString;
+ std::string sep;
+
+ for(std::vector<std::string>::const_iterator li = incs.begin();
+ li != incs.end(); ++li)
+ {
+ incString += sep + *li;
+ sep = ";";
+ }
+
+ std::vector<cmValueWithOrigin>::iterator position =
+ before ? this->IncludeDirectoriesEntries.begin()
+ : this->IncludeDirectoriesEntries.end();
+
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ cmValueWithOrigin entry(incString, lfbt);
+ this->IncludeDirectoriesEntries.insert(position, entry);
+
+ // Property on each target:
+ for (cmTargets::iterator l = this->Targets.begin();
+ l != this->Targets.end(); ++l)
+ {
+ cmTarget &t = l->second;
+ t.InsertInclude(entry, before);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefile::AddSystemIncludeDirectories(const std::set<std::string> &incs)
+{
+ for(std::set<std::string>::const_iterator li = incs.begin();
+ li != incs.end(); ++li)
+ {
+ this->SystemIncludeDirectories.insert(*li);
+ }
+
+ for (cmTargets::iterator l = this->Targets.begin();
+ l != this->Targets.end(); ++l)
+ {
+ cmTarget &t = l->second;
+ t.AddSystemIncludeDirectories(incs);
+ }
+}
+
+void cmMakefile::AddDefinition(const std::string& name, const char* value)
+{
+ if (!value )
+ {
+ return;
+ }
+
+ this->Internal->VarStack.top().Set(name, value);
+ if (this->Internal->VarUsageStack.size() &&
+ this->VariableInitialized(name))
+ {
+ this->CheckForUnused("changing definition", name);
+ this->Internal->VarUsageStack.top().erase(name);
+ }
+ this->Internal->VarInitStack.top().insert(name);
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmVariableWatch* vv = this->GetVariableWatch();
+ if ( vv )
+ {
+ vv->VariableAccessed(name,
+ cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
+ value,
+ this);
+ }
+#endif
+}
+
+
+void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
+ const char* doc,
+ cmCacheManager::CacheEntryType type,
+ bool force)
+{
+ bool haveVal = value ? true : false;
+ std::string val = haveVal ? value : "";
+ cmCacheManager::CacheIterator it =
+ this->GetCacheManager()->GetCacheIterator(name.c_str());
+ if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED) &&
+ it.Initialized())
+ {
+ // if this is not a force, then use the value from the cache
+ // if it is a force, then use the value being passed in
+ if(!force)
+ {
+ val = it.GetValue();
+ haveVal = true;
+ }
+ if ( type == cmCacheManager::PATH || type == cmCacheManager::FILEPATH )
+ {
+ std::vector<std::string>::size_type cc;
+ std::vector<std::string> files;
+ std::string nvalue = "";
+ cmSystemTools::ExpandListArgument(val, files);
+ for ( cc = 0; cc < files.size(); cc ++ )
+ {
+ if(!cmSystemTools::IsOff(files[cc].c_str()))
+ {
+ files[cc] = cmSystemTools::CollapseFullPath(files[cc].c_str());
+ }
+ if ( cc > 0 )
+ {
+ nvalue += ";";
+ }
+ nvalue += files[cc];
+ }
+
+ this->GetCacheManager()->AddCacheEntry(name, nvalue.c_str(), doc, type);
+ val = it.GetValue();
+ haveVal = true;
+ }
+
+ }
+ this->GetCacheManager()->AddCacheEntry(name, haveVal ? val.c_str() : 0, doc,
+ type);
+ // if there was a definition then remove it
+ this->Internal->VarStack.top().Set(name, 0);
+}
+
+
+void cmMakefile::AddDefinition(const std::string& name, bool value)
+{
+ this->Internal->VarStack.top().Set(name, value? "ON" : "OFF");
+ if (this->Internal->VarUsageStack.size() &&
+ this->VariableInitialized(name))
+ {
+ this->CheckForUnused("changing definition", name);
+ this->Internal->VarUsageStack.top().erase(name);
+ }
+ this->Internal->VarInitStack.top().insert(name);
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmVariableWatch* vv = this->GetVariableWatch();
+ if ( vv )
+ {
+ vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
+ value?"ON":"OFF", this);
+ }
+#endif
+}
+
+void cmMakefile::CheckForUnusedVariables() const
+{
+ if (!this->WarnUnused)
+ {
+ return;
+ }
+ const cmDefinitions& defs = this->Internal->VarStack.top();
+ const std::set<std::string>& locals = defs.LocalKeys();
+ std::set<std::string>::const_iterator it = locals.begin();
+ for (; it != locals.end(); ++it)
+ {
+ this->CheckForUnused("out of scope", *it);
+ }
+}
+
+void cmMakefile::MarkVariableAsUsed(const std::string& var)
+{
+ this->Internal->VarUsageStack.top().insert(var);
+}
+
+bool cmMakefile::VariableInitialized(const std::string& var) const
+{
+ if(this->Internal->VarInitStack.top().find(var) !=
+ this->Internal->VarInitStack.top().end())
+ {
+ return true;
+ }
+ return false;
+}
+
+bool cmMakefile::VariableUsed(const std::string& var) const
+{
+ if(this->Internal->VarUsageStack.top().find(var) !=
+ this->Internal->VarUsageStack.top().end())
+ {
+ return true;
+ }
+ return false;
+}
+
+void cmMakefile::CheckForUnused(const char* reason,
+ const std::string& name) const
+{
+ if (this->WarnUnused && !this->VariableUsed(name))
+ {
+ std::string path;
+ cmListFileBacktrace bt(this->GetLocalGenerator());
+ if (this->CallStack.size())
+ {
+ const cmListFileContext* file = this->CallStack.back().Context;
+ bt.push_back(*file);
+ path = file->FilePath.c_str();
+ }
+ else
+ {
+ path = this->GetStartDirectory();
+ path += "/CMakeLists.txt";
+ cmListFileContext lfc;
+ lfc.FilePath = path;
+ lfc.Line = 0;
+ bt.push_back(lfc);
+ }
+ if (this->CheckSystemVars ||
+ cmSystemTools::IsSubDirectory(path.c_str(),
+ this->GetHomeDirectory()) ||
+ (cmSystemTools::IsSubDirectory(path.c_str(),
+ this->GetHomeOutputDirectory()) &&
+ !cmSystemTools::IsSubDirectory(path.c_str(),
+ cmake::GetCMakeFilesDirectory())))
+ {
+ cmOStringStream msg;
+ msg << "unused variable (" << reason << ") \'" << name << "\'";
+ this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
+ msg.str(),
+ bt);
+ }
+ }
+}
+
+void cmMakefile::RemoveDefinition(const std::string& name)
+{
+ this->Internal->VarStack.top().Set(name, 0);
+ if (this->Internal->VarUsageStack.size() &&
+ this->VariableInitialized(name))
+ {
+ this->CheckForUnused("unsetting", name);
+ this->Internal->VarUsageStack.top().erase(name);
+ }
+ this->Internal->VarInitStack.top().insert(name);
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmVariableWatch* vv = this->GetVariableWatch();
+ if ( vv )
+ {
+ vv->VariableAccessed(name, cmVariableWatch::VARIABLE_REMOVED_ACCESS,
+ 0, this);
+ }
+#endif
+}
+
+void cmMakefile::RemoveCacheDefinition(const std::string& name)
+{
+ this->GetCacheManager()->RemoveCacheEntry(name);
+}
+
+void cmMakefile::SetProjectName(const char* p)
+{
+ this->ProjectName = p;
+}
+
+
+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:
+ return;
+ default:;
+ }
+ std::vector<std::string>::iterator j;
+ for(j = this->LinkDirectories.begin();
+ j != this->LinkDirectories.end(); ++j)
+ {
+ target.AddLinkDirectory(*j);
+ }
+ target.MergeLinkLibraries( *this, name, this->LinkLibraries );
+}
+
+
+void cmMakefile::AddAlias(const std::string& lname, cmTarget *tgt)
+{
+ this->AliasTargets[lname] = tgt;
+ this->LocalGenerator->GetGlobalGenerator()->AddAlias(lname, tgt);
+}
+
+cmTarget* cmMakefile::AddLibrary(const std::string& lname,
+ cmTarget::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))
+ {
+ this->IssueMessage(cmake::INTERNAL_ERROR,
+ "cmMakefile::AddLibrary given invalid target type.");
+ type = cmTarget::STATIC_LIBRARY;
+ }
+
+ cmTarget* target = this->AddNewTarget(type, lname);
+ // Clear its dependencies. Otherwise, dependencies might persist
+ // over changes in CMakeLists.txt, making the information stale and
+ // hence useless.
+ target->ClearDependencyInformation( *this, lname );
+ if(excludeFromAll)
+ {
+ target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
+ }
+ target->AddSources(srcs);
+ this->AddGlobalLinkInformation(lname, *target);
+ return target;
+}
+
+cmTarget* cmMakefile::AddExecutable(const char *exeName,
+ const std::vector<std::string> &srcs,
+ bool excludeFromAll)
+{
+ cmTarget* target = this->AddNewTarget(cmTarget::EXECUTABLE, exeName);
+ if(excludeFromAll)
+ {
+ target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
+ }
+ target->AddSources(srcs);
+ this->AddGlobalLinkInformation(exeName, *target);
+ return target;
+}
+
+//----------------------------------------------------------------------------
+cmTarget*
+cmMakefile::AddNewTarget(cmTarget::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->LocalGenerator->GetGlobalGenerator()->AddTarget(&it->second);
+ return &it->second;
+}
+
+cmSourceFile*
+cmMakefile::LinearGetSourceFileWithOutput(const std::string& name) const
+{
+ std::string out;
+
+ // look through all the source files that have custom commands
+ // and see if the custom command has the passed source file as an output
+ for(std::vector<cmSourceFile*>::const_iterator i =
+ this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
+ {
+ // does this source file have a custom command?
+ if ((*i)->GetCustomCommand())
+ {
+ // Does the output of the custom command match the source file name?
+ const std::vector<std::string>& outputs =
+ (*i)->GetCustomCommand()->GetOutputs();
+ for(std::vector<std::string>::const_iterator o = outputs.begin();
+ o != outputs.end(); ++o)
+ {
+ out = *o;
+ std::string::size_type pos = out.rfind(name);
+ // If the output matches exactly
+ if (pos != out.npos &&
+ pos == out.size() - name.size() &&
+ (pos ==0 || out[pos-1] == '/'))
+ {
+ return *i;
+ }
+ }
+ }
+ }
+
+ // otherwise return NULL
+ return 0;
+}
+
+cmSourceFile *cmMakefile::GetSourceFileWithOutput(
+ const std::string& name) const
+{
+ // If the queried path is not absolute we use the backward compatible
+ // linear-time search for an output with a matching suffix.
+ if(!cmSystemTools::FileIsFullPath(name.c_str()))
+ {
+ return this->LinearGetSourceFileWithOutput(name);
+ }
+ // Otherwise we use an efficient lookup map.
+ OutputToSourceMap::const_iterator o = this->OutputToSource.find(name);
+ if (o != this->OutputToSource.end())
+ {
+ return (*o).second;
+ }
+ return 0;
+}
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+cmSourceGroup*
+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
+ for (std::vector<cmSourceGroup>::const_iterator
+ sgIt = this->SourceGroups.begin();
+ sgIt != this->SourceGroups.end(); ++sgIt)
+ {
+ std::string sgName = sgIt->GetName();
+ if(sgName == name[0])
+ {
+ sg = const_cast<cmSourceGroup*>(&(*sgIt));
+ break;
+ }
+ }
+
+ if(sg != 0)
+ {
+ // iterate through its children to find match source group
+ for(unsigned int i=1; i<name.size(); ++i)
+ {
+ sg = sg->LookupChild(name[i].c_str());
+ if(sg == 0)
+ {
+ break;
+ }
+ }
+ }
+ return sg;
+}
+
+void cmMakefile::AddSourceGroup(const std::string& name,
+ const char* regex)
+{
+ std::vector<std::string> nameVector;
+ nameVector.push_back(name);
+ AddSourceGroup(nameVector, regex);
+}
+
+void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
+ const char* regex)
+{
+ cmSourceGroup* sg = 0;
+ std::vector<std::string> currentName;
+ int i = 0;
+ const int lastElement = static_cast<int>(name.size()-1);
+ for(i=lastElement; i>=0; --i)
+ {
+ currentName.assign(name.begin(), name.begin()+i+1);
+ sg = this->GetSourceGroup(currentName);
+ if(sg != 0)
+ {
+ break;
+ }
+ }
+
+ // i now contains the index of the last found component
+ if(i==lastElement)
+ {
+ // group already exists, replace its regular expression
+ if ( regex )
+ {
+ // We only want to set the regular expression. If there are already
+ // source files in the group, we don't want to remove them.
+ sg->SetGroupRegex(regex);
+ }
+ return;
+ }
+ else if(i==-1)
+ {
+ // group does not exist nor belong to any existing group
+ // add its first component
+ this->SourceGroups.push_back(cmSourceGroup(name[0].c_str(), regex));
+ sg = this->GetSourceGroup(currentName);
+ i = 0; // last component found
+ }
+
+ // build the whole source group path
+ const char* fullname = sg->GetFullName();
+ cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
+ if(strlen(fullname))
+ {
+ std::string guidName = "SG_Filter_";
+ guidName += fullname;
+ gg->CreateGUID(guidName);
+ }
+ for(++i; i<=lastElement; ++i)
+ {
+ sg->AddChild(cmSourceGroup(name[i].c_str(), 0, sg->GetFullName()));
+ sg = sg->LookupChild(name[i].c_str());
+ fullname = sg->GetFullName();
+ if(strlen(fullname))
+ {
+ std::string guidName = "SG_Filter_";
+ guidName += fullname;
+ gg->CreateGUID(guidName);
+ }
+ }
+
+ sg->SetGroupRegex(regex);
+}
+
+#endif
+
+void cmMakefile::AddExtraDirectory(const char* dir)
+{
+ this->AuxSourceDirectories.push_back(dir);
+}
+
+static bool mightExpandVariablesCMP0019(const char* s)
+{
+ return s && *s && strstr(s,"${") && strchr(s,'}');
+}
+
+void cmMakefile::ExpandVariablesCMP0019()
+{
+ // Drop this ancient compatibility behavior with a policy.
+ cmPolicies::PolicyStatus pol = this->GetPolicyStatus(cmPolicies::CMP0019);
+ if(pol != cmPolicies::OLD && pol != cmPolicies::WARN)
+ {
+ return;
+ }
+ cmOStringStream w;
+
+ const char *includeDirs = this->GetProperty("INCLUDE_DIRECTORIES");
+ if(mightExpandVariablesCMP0019(includeDirs))
+ {
+ std::string dirs = includeDirs;
+ this->ExpandVariablesInString(dirs, true, true);
+ if(pol == cmPolicies::WARN && dirs != includeDirs)
+ {
+ w << "Evaluated directory INCLUDE_DIRECTORIES\n"
+ << " " << includeDirs << "\n"
+ << "as\n"
+ << " " << dirs << "\n";
+ }
+ this->SetProperty("INCLUDE_DIRECTORIES", dirs.c_str());
+ }
+
+ // Also for each target's INCLUDE_DIRECTORIES property:
+ for (cmTargets::iterator l = this->Targets.begin();
+ l != this->Targets.end(); ++l)
+ {
+ cmTarget &t = l->second;
+ if (t.GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ continue;
+ }
+ includeDirs = t.GetProperty("INCLUDE_DIRECTORIES");
+ if(mightExpandVariablesCMP0019(includeDirs))
+ {
+ std::string dirs = includeDirs;
+ this->ExpandVariablesInString(dirs, true, true);
+ if(pol == cmPolicies::WARN && dirs != includeDirs)
+ {
+ w << "Evaluated target " << t.GetName() << " INCLUDE_DIRECTORIES\n"
+ << " " << includeDirs << "\n"
+ << "as\n"
+ << " " << dirs << "\n";
+ }
+ t.SetProperty("INCLUDE_DIRECTORIES", dirs.c_str());
+ }
+ }
+
+ for(std::vector<std::string>::iterator d = this->LinkDirectories.begin();
+ d != this->LinkDirectories.end(); ++d)
+ {
+ if(mightExpandVariablesCMP0019(d->c_str()))
+ {
+ std::string orig = *d;
+ this->ExpandVariablesInString(*d, true, true);
+ if(pol == cmPolicies::WARN && *d != orig)
+ {
+ w << "Evaluated link directory\n"
+ << " " << orig << "\n"
+ << "as\n"
+ << " " << *d << "\n";
+ }
+ }
+ }
+ for(cmTarget::LinkLibraryVectorType::iterator l =
+ this->LinkLibraries.begin();
+ l != this->LinkLibraries.end(); ++l)
+ {
+ if(mightExpandVariablesCMP0019(l->first.c_str()))
+ {
+ std::string orig = l->first;
+ this->ExpandVariablesInString(l->first, true, true);
+ if(pol == cmPolicies::WARN && l->first != orig)
+ {
+ w << "Evaluated link library\n"
+ << " " << orig << "\n"
+ << "as\n"
+ << " " << l->first << "\n";
+ }
+ }
+ }
+
+ if(!w.str().empty())
+ {
+ cmOStringStream m;
+ m << this->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0019)
+ << "\n"
+ << "The following variable evaluations were encountered:\n"
+ << w.str();
+ this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
+ }
+}
+
+bool cmMakefile::IsOn(const std::string& name) const
+{
+ const char* value = this->GetDefinition(name);
+ return cmSystemTools::IsOn(value);
+}
+
+bool cmMakefile::IsSet(const std::string& name) const
+{
+ const char* value = this->GetDefinition(name);
+ if ( !value )
+ {
+ return false;
+ }
+
+ if ( ! *value )
+ {
+ return false;
+ }
+
+ if ( cmSystemTools::IsNOTFOUND(value) )
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool cmMakefile::PlatformIs64Bit() const
+{
+ if(const char* sizeof_dptr = this->GetDefinition("CMAKE_SIZEOF_VOID_P"))
+ {
+ return atoi(sizeof_dptr) == 8;
+ }
+ return false;
+}
+
+const char* cmMakefile::GetSONameFlag(const std::string& language) const
+{
+ std::string name = "CMAKE_SHARED_LIBRARY_SONAME";
+ if(!language.empty())
+ {
+ name += "_";
+ name += language;
+ }
+ name += "_FLAG";
+ return GetDefinition(name);
+}
+
+bool cmMakefile::CanIWriteThisFile(const char* fileName) const
+{
+ if ( !this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES") )
+ {
+ return true;
+ }
+ // If we are doing an in-source build, then the test will always fail
+ if ( cmSystemTools::SameFile(this->GetHomeDirectory(),
+ this->GetHomeOutputDirectory()) )
+ {
+ if ( this->IsOn("CMAKE_DISABLE_IN_SOURCE_BUILD") )
+ {
+ return false;
+ }
+ return true;
+ }
+
+ // Check if this is a subdirectory of the source tree but not a
+ // subdirectory of the build tree
+ if ( cmSystemTools::IsSubDirectory(fileName,
+ this->GetHomeDirectory()) &&
+ !cmSystemTools::IsSubDirectory(fileName,
+ this->GetHomeOutputDirectory()) )
+ {
+ return false;
+ }
+ return true;
+}
+
+const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
+{
+ const char* ret = this->GetDefinition(name);
+ if(!ret)
+ {
+ cmSystemTools::Error("Error required internal CMake variable not "
+ "set, cmake may be not be built correctly.\n",
+ "Missing variable is:\n",
+ name.c_str());
+ return "";
+ }
+ return ret;
+}
+
+bool cmMakefile::IsDefinitionSet(const std::string& name) const
+{
+ const char* def = this->Internal->VarStack.top().Get(name);
+ this->Internal->VarUsageStack.top().insert(name);
+ if(!def)
+ {
+ def = this->GetCacheManager()->GetCacheValue(name);
+ }
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ if(cmVariableWatch* vv = this->GetVariableWatch())
+ {
+ if(!def)
+ {
+ vv->VariableAccessed
+ (name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS,
+ def, this);
+ }
+ }
+#endif
+ return def?true:false;
+}
+
+const char* cmMakefile::GetDefinition(const std::string& name) const
+{
+ if (this->WarnUnused)
+ {
+ this->Internal->VarUsageStack.top().insert(name);
+ }
+ const char* def = this->Internal->VarStack.top().Get(name);
+ if(!def)
+ {
+ def = this->GetCacheManager()->GetCacheValue(name);
+ }
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmVariableWatch* vv = this->GetVariableWatch();
+ if ( vv && !this->SuppressWatches )
+ {
+ if ( def )
+ {
+ vv->VariableAccessed(name, cmVariableWatch::VARIABLE_READ_ACCESS,
+ def, this);
+ }
+ else
+ {
+ vv->VariableAccessed(name,
+ cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS, def, this);
+ }
+ }
+#endif
+ return def;
+}
+
+const char* cmMakefile::GetSafeDefinition(const std::string& def) const
+{
+ const char* ret = this->GetDefinition(def);
+ if(!ret)
+ {
+ return "";
+ }
+ return ret;
+}
+
+std::vector<std::string> cmMakefile
+::GetDefinitions(int cacheonly /* = 0 */) const
+{
+ std::set<std::string> definitions;
+ if ( !cacheonly )
+ {
+ definitions = this->Internal->VarStack.top().ClosureKeys();
+ }
+ cmCacheManager::CacheIterator cit =
+ this->GetCacheManager()->GetCacheIterator();
+ for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
+ {
+ definitions.insert(cit.GetName());
+ }
+
+ std::vector<std::string> res;
+
+ std::set<std::string>::iterator fit;
+ for ( fit = definitions.begin(); fit != definitions.end(); fit ++ )
+ {
+ res.push_back(*fit);
+ }
+ return res;
+}
+
+
+const char *cmMakefile::ExpandVariablesInString(std::string& source) const
+{
+ return this->ExpandVariablesInString(source, false, false);
+}
+
+const char *cmMakefile::ExpandVariablesInString(std::string& source,
+ bool escapeQuotes,
+ bool noEscapes,
+ bool atOnly,
+ const char* filename,
+ long line,
+ bool removeEmpty,
+ bool replaceAt) const
+{
+ bool compareResults = false;
+ cmake::MessageType mtype = cmake::LOG;
+ std::string errorstr;
+ std::string original;
+
+ // Sanity check the @ONLY mode.
+ if(atOnly && (!noEscapes || !removeEmpty))
+ {
+ // This case should never be called. At-only is for
+ // configure-file/string which always does no escapes.
+ this->IssueMessage(cmake::INTERNAL_ERROR,
+ "ExpandVariablesInString @ONLY called "
+ "on something with escapes.");
+ return source.c_str();
+ }
+
+ // Variables used in the WARN case.
+ std::string newResult;
+ std::string newErrorstr;
+ cmake::MessageType newError = cmake::LOG;
+
+ switch(this->GetPolicyStatus(cmPolicies::CMP0053))
+ {
+ case cmPolicies::WARN:
+ {
+ // Save the original string for the warning.
+ original = source;
+ newResult = source;
+ compareResults = true;
+ // Suppress variable watches to avoid calling hooks twice. Suppress new
+ // dereferences since the OLD behavior is still what is actually used.
+ this->SuppressWatches = true;
+ newError =
+ ExpandVariablesInStringNew(newErrorstr, newResult, escapeQuotes,
+ noEscapes, atOnly, filename, line,
+ removeEmpty, replaceAt);
+ this->SuppressWatches = false;
+ }
+ case cmPolicies::OLD:
+ mtype = ExpandVariablesInStringOld(errorstr, source, escapeQuotes,
+ noEscapes, atOnly, filename,
+ line, removeEmpty, true);
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ // Messaging here would be *very* verbose.
+ case cmPolicies::NEW:
+ mtype = ExpandVariablesInStringNew(errorstr, source, escapeQuotes,
+ noEscapes, atOnly, filename,
+ line, removeEmpty, replaceAt);
+ break;
+ }
+
+ // If it's an error in either case, just report the error...
+ if(mtype != cmake::LOG)
+ {
+ if(mtype == cmake::FATAL_ERROR)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ }
+ this->IssueMessage(mtype, errorstr);
+ }
+ // ...otherwise, see if there's a difference that needs to be warned about.
+ else if(compareResults && (newResult != source || newError != mtype))
+ {
+ std::string msg =
+ this->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0053);
+ msg += "\n";
+
+ std::string msg_input = original;
+ cmSystemTools::ReplaceString(msg_input, "\n", "\n ");
+ msg += "For input:\n '";
+ msg += msg_input;
+ msg += "'\n";
+
+ std::string msg_old = source;
+ cmSystemTools::ReplaceString(msg_old, "\n", "\n ");
+ msg += "the old evaluation rules produce:\n '";
+ msg += msg_old;
+ msg += "'\n";
+
+ if(newError == mtype)
+ {
+ std::string msg_new = newResult;
+ cmSystemTools::ReplaceString(msg_new, "\n", "\n ");
+ msg += "but the new evaluation rules produce:\n '";
+ msg += msg_new;
+ msg += "'\n";
+ }
+ else
+ {
+ std::string msg_err = newErrorstr;
+ cmSystemTools::ReplaceString(msg_err, "\n", "\n ");
+ msg += "but the new evaluation rules produce an error:\n ";
+ msg += msg_err;
+ msg += "\n";
+ }
+
+ msg +=
+ "Using the old result for compatibility since the policy is not set.";
+
+ this->IssueMessage(cmake::AUTHOR_WARNING, msg);
+ }
+
+ return source.c_str();
+}
+
+cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
+ std::string& errorstr,
+ std::string& source,
+ bool escapeQuotes,
+ bool noEscapes,
+ bool atOnly,
+ const char* filename,
+ long line,
+ bool removeEmpty,
+ bool replaceAt) const
+{
+ // Fast path strings without any special characters.
+ if ( source.find_first_of("$@\\") == source.npos)
+ {
+ return cmake::LOG;
+ }
+
+ // Special-case the @ONLY mode.
+ if(atOnly)
+ {
+ // Store an original copy of the input.
+ std::string input = source;
+
+ // Start with empty output.
+ source = "";
+
+ // Look for one @VAR@ at a time.
+ const char* in = input.c_str();
+ while(this->cmAtVarRegex.find(in))
+ {
+ // Get the range of the string to replace.
+ const char* first = in + this->cmAtVarRegex.start();
+ const char* last = in + this->cmAtVarRegex.end();
+
+ // Store the unchanged part of the string now.
+ source.append(in, first-in);
+
+ // Lookup the definition of VAR.
+ std::string var(first+1, last-first-2);
+ if(const char* val = this->GetDefinition(var))
+ {
+ // Store the value in the output escaping as requested.
+ if(escapeQuotes)
+ {
+ source.append(cmSystemTools::EscapeQuotes(val));
+ }
+ else
+ {
+ source.append(val);
+ }
+ }
+
+ // Continue looking for @VAR@ further along the string.
+ in = last;
+ }
+
+ // Append the rest of the unchanged part of the string.
+ source.append(in);
+
+ return cmake::LOG;
+ }
+
+ // This method replaces ${VAR} and @VAR@ where VAR is looked up
+ // with GetDefinition(), if not found in the map, nothing is expanded.
+ // It also supports the $ENV{VAR} syntax where VAR is looked up in
+ // the current environment variables.
+
+ cmCommandArgumentParserHelper parser;
+ parser.SetMakefile(this);
+ parser.SetLineFile(line, filename);
+ parser.SetEscapeQuotes(escapeQuotes);
+ parser.SetNoEscapeMode(noEscapes);
+ parser.SetReplaceAtSyntax(replaceAt);
+ parser.SetRemoveEmpty(removeEmpty);
+ int res = parser.ParseString(source.c_str(), 0);
+ const char* emsg = parser.GetError();
+ cmake::MessageType mtype = cmake::LOG;
+ if ( res && !emsg[0] )
+ {
+ source = parser.GetResult();
+ }
+ else
+ {
+ // Construct the main error message.
+ cmOStringStream error;
+ error << "Syntax error in cmake code ";
+ if(filename && line > 0)
+ {
+ // This filename and line number may be more specific than the
+ // command context because one command invocation can have
+ // arguments on multiple lines.
+ error << "at\n"
+ << " " << filename << ":" << line << "\n";
+ }
+ error << "when parsing string\n"
+ << " " << source << "\n";
+ error << emsg;
+
+ // If the parser failed ("res" is false) then this is a real
+ // argument parsing error, so the policy applies. Otherwise the
+ // parser reported an error message without failing because the
+ // helper implementation is unhappy, which has always reported an
+ // error.
+ mtype = cmake::FATAL_ERROR;
+ if(!res)
+ {
+ // This is a real argument parsing error. Use policy CMP0010 to
+ // decide whether it is an error.
+ switch(this->GetPolicyStatus(cmPolicies::CMP0010))
+ {
+ case cmPolicies::WARN:
+ error << "\n"
+ << (this->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0010));
+ case cmPolicies::OLD:
+ // OLD behavior is to just warn and continue.
+ mtype = cmake::AUTHOR_WARNING;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ error << "\n"
+ << (this->GetPolicies()
+ ->GetRequiredPolicyError(cmPolicies::CMP0010));
+ case cmPolicies::NEW:
+ // NEW behavior is to report the error.
+ break;
+ }
+ }
+ errorstr = error.str();
+ }
+ return mtype;
+}
+
+typedef enum
+ {
+ NORMAL,
+ ENVIRONMENT,
+ CACHE
+ } t_domain;
+struct t_lookup
+ {
+ t_lookup(): domain(NORMAL), loc(0) {}
+ t_domain domain;
+ size_t loc;
+ };
+
+cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
+ std::string& errorstr,
+ std::string& source,
+ bool escapeQuotes,
+ bool noEscapes,
+ bool atOnly,
+ const char* filename,
+ long line,
+ bool removeEmpty,
+ bool replaceAt) const
+{
+ // This method replaces ${VAR} and @VAR@ where VAR is looked up
+ // with GetDefinition(), if not found in the map, nothing is expanded.
+ // It also supports the $ENV{VAR} syntax where VAR is looked up in
+ // the current environment variables.
+
+ const char* in = source.c_str();
+ const char* last = in;
+ std::string result;
+ result.reserve(source.size());
+ std::stack<t_lookup> openstack;
+ bool error = false;
+ bool done = false;
+ openstack.push(t_lookup());
+ cmake::MessageType mtype = cmake::LOG;
+
+ do
+ {
+ char inc = *in;
+ switch(inc)
+ {
+ case '}':
+ if(openstack.size() > 1)
+ {
+ t_lookup var = openstack.top();
+ openstack.pop();
+ result.append(last, in - last);
+ std::string const& lookup = result.substr(var.loc);
+ const char* value = NULL;
+ std::string varresult;
+ static const std::string lineVar = "CMAKE_CURRENT_LIST_LINE";
+ switch(var.domain)
+ {
+ case NORMAL:
+ if(filename && lookup == lineVar)
+ {
+ cmOStringStream ostr;
+ ostr << line;
+ varresult = ostr.str();
+ }
+ else
+ {
+ value = this->GetDefinition(lookup);
+ }
+ break;
+ case ENVIRONMENT:
+ value = cmSystemTools::GetEnv(lookup.c_str());
+ break;
+ case CACHE:
+ value = this->GetCacheManager()->GetCacheValue(lookup);
+ break;
+ }
+ // Get the string we're meant to append to.
+ if(value)
+ {
+ if(escapeQuotes)
+ {
+ varresult = cmSystemTools::EscapeQuotes(value);
+ }
+ else
+ {
+ varresult = value;
+ }
+ }
+ else if(!removeEmpty)
+ {
+ // check to see if we need to print a warning
+ // if strict mode is on and the variable has
+ // not been "cleared"/initialized with a set(foo ) call
+ if(this->GetCMakeInstance()->GetWarnUninitialized() &&
+ !this->VariableInitialized(lookup))
+ {
+ if (this->CheckSystemVars ||
+ cmSystemTools::IsSubDirectory(filename,
+ this->GetHomeDirectory()) ||
+ cmSystemTools::IsSubDirectory(filename,
+ this->GetHomeOutputDirectory()))
+ {
+ cmOStringStream msg;
+ cmListFileBacktrace bt(this->GetLocalGenerator());
+ cmListFileContext lfc;
+ lfc.FilePath = filename;
+ lfc.Line = line;
+ bt.push_back(lfc);
+ msg << "uninitialized variable \'" << lookup << "\'";
+ this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
+ msg.str().c_str(), bt);
+ }
+ }
+ }
+ result.replace(var.loc, result.size() - var.loc, varresult);
+ // Start looking from here on out.
+ last = in + 1;
+ }
+ break;
+ case '$':
+ if(!atOnly)
+ {
+ t_lookup lookup;
+ const char* next = in + 1;
+ const char* start = NULL;
+ char nextc = *next;
+ if(nextc == '{')
+ {
+ // Looking for a variable.
+ start = in + 2;
+ lookup.domain = NORMAL;
+ }
+ else if(nextc == '<')
+ {
+ }
+ else if(!nextc)
+ {
+ result.append(last, next - last);
+ last = next;
+ }
+ else if(cmHasLiteralPrefix(next, "ENV{"))
+ {
+ // Looking for an environment variable.
+ start = in + 5;
+ lookup.domain = ENVIRONMENT;
+ }
+ else if(cmHasLiteralPrefix(next, "CACHE{"))
+ {
+ // Looking for a cache variable.
+ start = in + 7;
+ lookup.domain = CACHE;
+ }
+ else
+ {
+ if(this->cmNamedCurly.find(next))
+ {
+ errorstr = "Syntax $"
+ + std::string(next, this->cmNamedCurly.end())
+ + "{} is not supported. Only ${}, $ENV{}, "
+ "and $CACHE{} are allowed.";
+ mtype = cmake::FATAL_ERROR;
+ error = true;
+ }
+ }
+ if(start)
+ {
+ result.append(last, in - last);
+ last = start;
+ in = start - 1;
+ lookup.loc = result.size();
+ openstack.push(lookup);
+ }
+ break;
+ }
+ case '\\':
+ if(!noEscapes)
+ {
+ const char* next = in + 1;
+ char nextc = *next;
+ if(nextc == 't')
+ {
+ result.append(last, in - last);
+ result.append("\t");
+ last = next + 1;
+ }
+ else if(nextc == 'n')
+ {
+ result.append(last, in - last);
+ result.append("\n");
+ last = next + 1;
+ }
+ else if(nextc == 'r')
+ {
+ result.append(last, in - last);
+ result.append("\r");
+ last = next + 1;
+ }
+ else if(nextc == ';' && openstack.size() == 1)
+ {
+ // Handled in ExpandListArgument; pass the backslash literally.
+ }
+ else if (isalnum(nextc) || nextc == '\0')
+ {
+ errorstr += "Invalid character escape '\\";
+ if (nextc)
+ {
+ errorstr += nextc;
+ errorstr += "'.";
+ }
+ else
+ {
+ errorstr += "' (at end of input).";
+ }
+ error = true;
+ }
+ else
+ {
+ // Take what we've found so far, skipping the escape character.
+ result.append(last, in - last);
+ // Start tracking from the next character.
+ last = in + 1;
+ }
+ // Skip the next character since it was escaped, but don't read past
+ // the end of the string.
+ if(*last)
+ {
+ ++in;
+ }
+ }
+ break;
+ case '\n':
+ // Onto the next line.
+ ++line;
+ break;
+ case '\0':
+ done = true;
+ break;
+ case '@':
+ if(replaceAt)
+ {
+ const char* nextAt = strchr(in + 1, '@');
+ if(nextAt && nextAt != in + 1 &&
+ nextAt == in + 1 + strspn(in + 1,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789/_.+-"))
+ {
+ std::string variable(in + 1, nextAt - in - 1);
+ std::string varresult = this->GetSafeDefinition(variable);
+ if(escapeQuotes)
+ {
+ varresult = cmSystemTools::EscapeQuotes(varresult);
+ }
+ // Skip over the variable.
+ result.append(last, in - last);
+ result.append(varresult);
+ in = nextAt;
+ last = in + 1;
+ break;
+ }
+ }
+ // Failed to find a valid @ expansion; treat it as literal.
+ /* FALLTHROUGH */
+ default:
+ {
+ if(openstack.size() > 1 &&
+ !(isalnum(inc) || inc == '_' ||
+ inc == '/' || inc == '.' ||
+ inc == '+' || inc == '-'))
+ {
+ errorstr += "Invalid character (\'";
+ errorstr += inc;
+ result.append(last, in - last);
+ errorstr += "\') in a variable name: "
+ "'" + result.substr(openstack.top().loc) + "'";
+ mtype = cmake::FATAL_ERROR;
+ error = true;
+ }
+ break;
+ }
+ }
+ // Look at the next character.
+ } while(!error && !done && *++in);
+
+ // Check for open variable references yet.
+ if(!error && openstack.size() != 1)
+ {
+ // There's an open variable reference waiting. Policy CMP0010 flags
+ // whether this is an error or not. The new parser now enforces
+ // CMP0010 as well.
+ errorstr += "There is an unterminated variable reference.";
+ error = true;
+ }
+
+ if(error)
+ {
+ cmOStringStream emsg;
+ emsg << "Syntax error in cmake code ";
+ if(filename)
+ {
+ // This filename and line number may be more specific than the
+ // command context because one command invocation can have
+ // arguments on multiple lines.
+ emsg << "at\n"
+ << " " << filename << ":" << line << "\n";
+ }
+ emsg << "when parsing string\n"
+ << " " << source << "\n";
+ emsg << errorstr;
+ mtype = cmake::FATAL_ERROR;
+ errorstr = emsg.str();
+ }
+ else
+ {
+ // Append the rest of the unchanged part of the string.
+ result.append(last);
+
+ source = result;
+ }
+
+ return mtype;
+}
+
+void cmMakefile::RemoveVariablesInString(std::string& source,
+ bool atOnly) const
+{
+ if(!atOnly)
+ {
+ cmsys::RegularExpression var("(\\${[A-Za-z_0-9]*})");
+ while (var.find(source))
+ {
+ source.erase(var.start(),var.end() - var.start());
+ }
+ }
+
+ if(!atOnly)
+ {
+ cmsys::RegularExpression varb("(\\$ENV{[A-Za-z_0-9]*})");
+ while (varb.find(source))
+ {
+ source.erase(varb.start(),varb.end() - varb.start());
+ }
+ }
+ cmsys::RegularExpression var2("(@[A-Za-z_0-9]*@)");
+ while (var2.find(source))
+ {
+ source.erase(var2.start(),var2.end() - var2.start());
+ }
+}
+
+/**
+ * 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,
+ bool single) const
+{
+ if(this->LocalGenerator->GetGlobalGenerator()->IsMultiConfig())
+ {
+ if(const char* configTypes =
+ this->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
+ {
+ cmSystemTools::ExpandListArgument(configTypes, configs);
+ }
+ return "";
+ }
+ else
+ {
+ const std::string& buildType = this->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ if(single && !buildType.empty())
+ {
+ configs.push_back(buildType);
+ }
+ return buildType;
+ }
+}
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+/**
+ * Find a source group whose regular expression matches the filename
+ * part of the given source name. Search backward through the list of
+ * source groups, and take the first matching group found. This way
+ * non-inherited SOURCE_GROUP commands will have precedence over
+ * inherited ones.
+ */
+cmSourceGroup*
+cmMakefile::FindSourceGroup(const char* source,
+ std::vector<cmSourceGroup> &groups) const
+{
+ // First search for a group that lists the file explicitly.
+ for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
+ sg != groups.rend(); ++sg)
+ {
+ cmSourceGroup *result = sg->MatchChildrenFiles(source);
+ if(result)
+ {
+ return result;
+ }
+ }
+
+ // Now search for a group whose regex matches the file.
+ for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
+ sg != groups.rend(); ++sg)
+ {
+ cmSourceGroup *result = sg->MatchChildrenRegex(source);
+ if(result)
+ {
+ return result;
+ }
+ }
+
+
+ // Shouldn't get here, but just in case, return the default group.
+ return &groups.front();
+}
+#endif
+
+bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff,
+ cmExecutionStatus &status)
+{
+ // if there are no blockers get out of here
+ if (this->FunctionBlockers.begin() == this->FunctionBlockers.end())
+ {
+ return false;
+ }
+
+ // loop over all function blockers to see if any block this command
+ // evaluate in reverse, this is critical for balanced IF statements etc
+ std::vector<cmFunctionBlocker*>::reverse_iterator pos;
+ for (pos = this->FunctionBlockers.rbegin();
+ pos != this->FunctionBlockers.rend(); ++pos)
+ {
+ if((*pos)->IsFunctionBlocked(lff, *this, status))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::PushFunctionBlockerBarrier()
+{
+ this->FunctionBlockerBarriers.push_back(this->FunctionBlockers.size());
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::PopFunctionBlockerBarrier(bool reportError)
+{
+ // Remove any extra entries pushed on the barrier.
+ FunctionBlockersType::size_type barrier =
+ this->FunctionBlockerBarriers.back();
+ while(this->FunctionBlockers.size() > barrier)
+ {
+ cmsys::auto_ptr<cmFunctionBlocker> fb(this->FunctionBlockers.back());
+ this->FunctionBlockers.pop_back();
+ if(reportError)
+ {
+ // Report the context in which the unclosed block was opened.
+ cmListFileContext const& lfc = fb->GetStartingContext();
+ cmOStringStream e;
+ e << "A logical block opening on the line\n"
+ << " " << lfc << "\n"
+ << "is not closed.";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ reportError = false;
+ }
+ }
+
+ // Remove the barrier.
+ this->FunctionBlockerBarriers.pop_back();
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::ExpandArguments(
+ std::vector<cmListFileArgument> const& inArgs,
+ std::vector<std::string>& outArgs) const
+{
+ std::vector<cmListFileArgument>::const_iterator i;
+ std::string value;
+ outArgs.reserve(inArgs.size());
+ for(i = inArgs.begin(); i != inArgs.end(); ++i)
+ {
+ // No expansion in a bracket argument.
+ if(i->Delim == cmListFileArgument::Bracket)
+ {
+ outArgs.push_back(i->Value);
+ continue;
+ }
+ // Expand the variables in the argument.
+ value = i->Value;
+ this->ExpandVariablesInString(value, false, false, false,
+ i->FilePath, i->Line,
+ false, false);
+
+ // If the argument is quoted, it should be one argument.
+ // Otherwise, it may be a list of arguments.
+ if(i->Delim == cmListFileArgument::Quoted)
+ {
+ outArgs.push_back(value);
+ }
+ else
+ {
+ cmSystemTools::ExpandListArgument(value, outArgs);
+ }
+ }
+ return !cmSystemTools::GetFatalErrorOccured();
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::ExpandArguments(
+ std::vector<cmListFileArgument> const& inArgs,
+ std::vector<cmExpandedCommandArgument>& outArgs) const
+{
+ std::vector<cmListFileArgument>::const_iterator i;
+ std::string value;
+ outArgs.reserve(inArgs.size());
+ for(i = inArgs.begin(); i != inArgs.end(); ++i)
+ {
+ // No expansion in a bracket argument.
+ if(i->Delim == cmListFileArgument::Bracket)
+ {
+ outArgs.push_back(cmExpandedCommandArgument(i->Value, true));
+ continue;
+ }
+ // Expand the variables in the argument.
+ value = i->Value;
+ this->ExpandVariablesInString(value, false, false, false,
+ i->FilePath, i->Line,
+ false, false);
+
+ // If the argument is quoted, it should be one argument.
+ // Otherwise, it may be a list of arguments.
+ if(i->Delim == cmListFileArgument::Quoted)
+ {
+ outArgs.push_back(cmExpandedCommandArgument(value, true));
+ }
+ else
+ {
+ std::vector<std::string> stringArgs;
+ cmSystemTools::ExpandListArgument(value, stringArgs);
+ for(size_t j = 0; j < stringArgs.size(); ++j)
+ {
+ outArgs.push_back(cmExpandedCommandArgument(stringArgs[j], false));
+ }
+ }
+ }
+ return !cmSystemTools::GetFatalErrorOccured();
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb)
+{
+ if(!this->CallStack.empty())
+ {
+ // Record the context in which the blocker is created.
+ fb->SetStartingContext(*(this->CallStack.back().Context));
+ }
+
+ this->FunctionBlockers.push_back(fb);
+}
+
+cmsys::auto_ptr<cmFunctionBlocker>
+cmMakefile::RemoveFunctionBlocker(cmFunctionBlocker* fb,
+ const cmListFileFunction& lff)
+{
+ // Find the function blocker stack barrier for the current scope.
+ // We only remove a blocker whose index is not less than the barrier.
+ FunctionBlockersType::size_type barrier = 0;
+ if(!this->FunctionBlockerBarriers.empty())
+ {
+ barrier = this->FunctionBlockerBarriers.back();
+ }
+
+ // Search for the function blocker whose scope this command ends.
+ for(FunctionBlockersType::size_type
+ i = this->FunctionBlockers.size(); i > barrier; --i)
+ {
+ std::vector<cmFunctionBlocker*>::iterator pos =
+ this->FunctionBlockers.begin() + (i - 1);
+ if (*pos == fb)
+ {
+ // Warn if the arguments do not match, but always remove.
+ if(!(*pos)->ShouldRemove(lff, *this))
+ {
+ cmListFileContext const& lfc = fb->GetStartingContext();
+ cmOStringStream e;
+ e << "A logical block opening on the line\n"
+ << " " << lfc << "\n"
+ << "closes on the line\n"
+ << " " << lff << "\n"
+ << "with mis-matching arguments.";
+ this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ }
+ cmFunctionBlocker* b = *pos;
+ this->FunctionBlockers.erase(pos);
+ return cmsys::auto_ptr<cmFunctionBlocker>(b);
+ }
+ }
+
+ return cmsys::auto_ptr<cmFunctionBlocker>();
+}
+
+//----------------------------------------------------------------------------
+cmMakefile::LexicalPushPop::LexicalPushPop(cmMakefile* mf):
+ Makefile(mf), ReportError(true)
+{
+ this->Makefile->PushFunctionBlockerBarrier();
+}
+
+//----------------------------------------------------------------------------
+cmMakefile::LexicalPushPop::~LexicalPushPop()
+{
+ this->Makefile->PopFunctionBlockerBarrier(this->ReportError);
+}
+
+void cmMakefile::SetHomeDirectory(const std::string& dir)
+{
+ this->cmHomeDirectory = dir;
+ cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory);
+ this->AddDefinition("CMAKE_SOURCE_DIR", this->GetHomeDirectory());
+ if ( !this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR") )
+ {
+ this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", this->GetHomeDirectory());
+ }
+}
+
+void cmMakefile::SetHomeOutputDirectory(const std::string& lib)
+{
+ this->HomeOutputDirectory = lib;
+ cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory);
+ this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory());
+ if ( !this->GetDefinition("CMAKE_CURRENT_BINARY_DIR") )
+ {
+ this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
+ this->GetHomeOutputDirectory());
+ }
+}
+
+void cmMakefile::SetScriptModeFile(const char* scriptfile)
+{
+ this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile);
+}
+
+void cmMakefile::SetArgcArgv(const std::vector<std::string>& args)
+{
+ cmOStringStream strStream;
+ strStream << args.size();
+ this->AddDefinition("CMAKE_ARGC", strStream.str().c_str());
+ //this->MarkVariableAsUsed("CMAKE_ARGC");
+
+ for (unsigned int t = 0; t < args.size(); ++t)
+ {
+ cmOStringStream tmpStream;
+ tmpStream << "CMAKE_ARGV" << t;
+ this->AddDefinition(tmpStream.str(), args[t].c_str());
+ //this->MarkVariableAsUsed(tmpStream.str().c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const
+{
+ cmSourceFileLocation sfl(this, sourceName);
+ for(std::vector<cmSourceFile*>::const_iterator
+ sfi = this->SourceFiles.begin();
+ sfi != this->SourceFiles.end(); ++sfi)
+ {
+ cmSourceFile* sf = *sfi;
+ if(sf->Matches(sfl))
+ {
+ return sf;
+ }
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName,
+ bool generated)
+{
+ cmSourceFile* sf = new cmSourceFile(this, sourceName);
+ if(generated)
+ {
+ sf->SetProperty("GENERATED", "1");
+ }
+ this->SourceFiles.push_back(sf);
+ return sf;
+}
+
+//----------------------------------------------------------------------------
+cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName,
+ bool generated)
+{
+ if(cmSourceFile* esf = this->GetSource(sourceName))
+ {
+ return esf;
+ }
+ else
+ {
+ return this->CreateSource(sourceName, generated);
+ }
+}
+
+void cmMakefile::EnableLanguage(std::vector<std::string> const & lang,
+ bool optional)
+{
+ this->AddDefinition("CMAKE_CFG_INTDIR",
+ this->LocalGenerator->GetGlobalGenerator()
+ ->GetCMakeCFGIntDir());
+ this->LocalGenerator->GetGlobalGenerator()->EnableLanguage(lang, this,
+ optional);
+}
+
+void cmMakefile::ExpandSourceListArguments(
+ std::vector<std::string> const& arguments,
+ std::vector<std::string>& newargs, unsigned int /* start */) const
+{
+ // now expand the args
+ unsigned int i;
+ for(i = 0; i < arguments.size(); ++i)
+ {
+ // List expansion will have been done already.
+ newargs.push_back(arguments[i]);
+ }
+}
+
+int cmMakefile::TryCompile(const std::string& srcdir,
+ const std::string& bindir,
+ const std::string& projectName,
+ const std::string& targetName,
+ bool fast,
+ const std::vector<std::string> *cmakeArgs,
+ std::string& output)
+{
+ this->Internal->IsSourceFileTryCompile = fast;
+ // does the binary directory exist ? If not create it...
+ if (!cmSystemTools::FileIsDirectory(bindir.c_str()))
+ {
+ cmSystemTools::MakeDirectory(bindir.c_str());
+ }
+
+ // change to the tests directory and run cmake
+ // use the cmake object instead of calling cmake
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ cmSystemTools::ChangeDirectory(bindir.c_str());
+
+ // make sure the same generator is used
+ // use this program as the cmake to be run, it should not
+ // be run that way but the cmake object requires a vailid path
+ std::string cmakeCommand = this->GetDefinition("CMAKE_COMMAND");
+ cmake cm;
+ cm.SetIsInTryCompile(true);
+ cmGlobalGenerator *gg = cm.CreateGlobalGenerator
+ (this->LocalGenerator->GetGlobalGenerator()->GetName());
+ if (!gg)
+ {
+ cmSystemTools::Error(
+ "Internal CMake error, TryCompile bad GlobalGenerator");
+ // return to the original directory
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ this->Internal->IsSourceFileTryCompile = false;
+ return 1;
+ }
+ cm.SetGlobalGenerator(gg);
+
+ // do a configure
+ cm.SetHomeDirectory(srcdir);
+ cm.SetHomeOutputDirectory(bindir);
+ cm.SetStartDirectory(srcdir);
+ cm.SetStartOutputDirectory(bindir);
+ cm.SetGeneratorPlatform(this->GetCMakeInstance()->GetGeneratorPlatform());
+ cm.SetGeneratorToolset(this->GetCMakeInstance()->GetGeneratorToolset());
+ cm.LoadCache();
+ if(!gg->IsMultiConfig())
+ {
+ if(const char* config =
+ this->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION"))
+ {
+ // Tell the single-configuration generator which one to use.
+ // Add this before the user-provided CMake arguments in case
+ // one of the arguments is -DCMAKE_BUILD_TYPE=...
+ cm.AddCacheEntry("CMAKE_BUILD_TYPE", config,
+ "Build configuration", cmCacheManager::STRING);
+ }
+ }
+ // if cmake args were provided then pass them in
+ if (cmakeArgs)
+ {
+ // FIXME: Workaround to ignore unused CLI variables in try-compile.
+ //
+ // Ideally we should use SetArgs to honor options like --warn-unused-vars.
+ // However, there is a subtle problem when certain arguments are passed to
+ // a macro wrapping around try_compile or try_run that does not escape
+ // semicolons in its parameters but just passes ${ARGV} or ${ARGN}. In
+ // this case a list argument like "-DVAR=a;b" gets split into multiple
+ // cmake arguments "-DVAR=a" and "b". Currently SetCacheArgs ignores
+ // argument "b" and uses just "-DVAR=a", leading to a subtle bug in that
+ // the try_compile or try_run does not get the proper value of VAR. If we
+ // call SetArgs here then it would treat "b" as the source directory and
+ // cause an error such as "The source directory .../CMakeFiles/CMakeTmp/b
+ // does not exist", thus breaking the try_compile or try_run completely.
+ //
+ // Strictly speaking the bug is in the wrapper macro because the CMake
+ // language has always flattened nested lists and the macro should escape
+ // the semicolons in its arguments before forwarding them. However, this
+ // bug is so subtle that projects typically work anyway, usually because
+ // the value VAR=a is sufficient for the try_compile or try_run to get the
+ // correct result. Calling SetArgs here would break such projects that
+ // previously built. Instead we work around the issue by never reporting
+ // unused arguments and ignoring options such as --warn-unused-vars.
+ cm.SetWarnUnusedCli(false);
+ //cm.SetArgs(*cmakeArgs, true);
+
+ cm.SetCacheArgs(*cmakeArgs);
+ }
+ // to save time we pass the EnableLanguage info directly
+ gg->EnableLanguagesFromGenerator
+ (this->LocalGenerator->GetGlobalGenerator(), this);
+ if(this->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"))
+ {
+ cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS",
+ "TRUE", "", cmCacheManager::INTERNAL);
+ }
+ else
+ {
+ cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS",
+ "FALSE", "", cmCacheManager::INTERNAL);
+ }
+ if (cm.Configure() != 0)
+ {
+ cmSystemTools::Error(
+ "Internal CMake error, TryCompile configure of cmake failed");
+ // return to the original directory
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ this->Internal->IsSourceFileTryCompile = false;
+ return 1;
+ }
+
+ if (cm.Generate() != 0)
+ {
+ cmSystemTools::Error(
+ "Internal CMake error, TryCompile generation of cmake failed");
+ // return to the original directory
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ this->Internal->IsSourceFileTryCompile = false;
+ return 1;
+ }
+
+ // finally call the generator to actually build the resulting project
+ int ret =
+ this->LocalGenerator->GetGlobalGenerator()->TryCompile(srcdir,bindir,
+ projectName,
+ targetName,
+ fast,
+ output,
+ this);
+
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+ this->Internal->IsSourceFileTryCompile = false;
+ return ret;
+}
+
+bool cmMakefile::GetIsSourceFileTryCompile() const
+{
+ return this->Internal->IsSourceFileTryCompile;
+}
+
+cmake *cmMakefile::GetCMakeInstance() const
+{
+ if ( this->LocalGenerator && this->LocalGenerator->GetGlobalGenerator() )
+ {
+ return this->LocalGenerator->GetGlobalGenerator()->GetCMakeInstance();
+ }
+ return 0;
+}
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+cmVariableWatch *cmMakefile::GetVariableWatch() const
+{
+ if ( this->GetCMakeInstance() &&
+ this->GetCMakeInstance()->GetVariableWatch() )
+ {
+ return this->GetCMakeInstance()->GetVariableWatch();
+ }
+ return 0;
+}
+#endif
+
+void cmMakefile::AddMacro(const char* name, const char* signature)
+{
+ if ( !name || !signature )
+ {
+ return;
+ }
+ this->MacrosMap[name] = signature;
+}
+
+void cmMakefile::GetListOfMacros(std::string& macros) const
+{
+ StringStringMap::const_iterator it;
+ macros = "";
+ int cc = 0;
+ for ( it = this->MacrosMap.begin(); it != this->MacrosMap.end(); ++it )
+ {
+ if ( cc > 0 )
+ {
+ macros += ";";
+ }
+ macros += it->first;
+ cc ++;
+ }
+}
+
+cmCacheManager *cmMakefile::GetCacheManager() const
+{
+ return this->GetCMakeInstance()->GetCacheManager();
+}
+
+void cmMakefile::DisplayStatus(const char* message, float s) const
+{
+ cmake* cm = this->GetLocalGenerator()->GetGlobalGenerator()
+ ->GetCMakeInstance();
+ if (cm->GetWorkingMode() == cmake::FIND_PACKAGE_MODE)
+ {
+ // don't output any STATUS message in FIND_PACKAGE_MODE, since they will
+ // directly be fed to the compiler, which will be confused.
+ return;
+ }
+ cm->UpdateProgress(message, s);
+}
+
+std::string cmMakefile::GetModulesFile(const char* filename) const
+{
+ std::string result;
+
+ // We search the module always in CMAKE_ROOT and in CMAKE_MODULE_PATH,
+ // and then decide based on the policy setting which one to return.
+ // See CMP0017 for more details.
+ // The specific problem was that KDE 4.5.0 installs a
+ // FindPackageHandleStandardArgs.cmake which doesn't have the new features
+ // of FPHSA.cmake introduced in CMake 2.8.3 yet, and by setting
+ // CMAKE_MODULE_PATH also e.g. FindZLIB.cmake from cmake included
+ // FPHSA.cmake from kdelibs and not from CMake, and tried to use the
+ // new features, which were not there in the version from kdelibs, and so
+ // failed ("
+ std::string moduleInCMakeRoot;
+ std::string moduleInCMakeModulePath;
+
+ // Always search in CMAKE_MODULE_PATH:
+ const char* cmakeModulePath = this->GetDefinition("CMAKE_MODULE_PATH");
+ if(cmakeModulePath)
+ {
+ std::vector<std::string> modulePath;
+ cmSystemTools::ExpandListArgument(cmakeModulePath, modulePath);
+
+ //Look through the possible module directories.
+ for(std::vector<std::string>::iterator i = modulePath.begin();
+ i != modulePath.end(); ++i)
+ {
+ std::string itempl = *i;
+ cmSystemTools::ConvertToUnixSlashes(itempl);
+ itempl += "/";
+ itempl += filename;
+ if(cmSystemTools::FileExists(itempl.c_str()))
+ {
+ moduleInCMakeModulePath = itempl;
+ break;
+ }
+ }
+ }
+
+ // Always search in the standard modules location.
+ const char* cmakeRoot = this->GetDefinition("CMAKE_ROOT");
+ if(cmakeRoot)
+ {
+ moduleInCMakeRoot = cmakeRoot;
+ moduleInCMakeRoot += "/Modules/";
+ moduleInCMakeRoot += filename;
+ cmSystemTools::ConvertToUnixSlashes(moduleInCMakeRoot);
+ if(!cmSystemTools::FileExists(moduleInCMakeRoot.c_str()))
+ {
+ moduleInCMakeRoot = "";
+ }
+ }
+
+ // Normally, prefer the files found in CMAKE_MODULE_PATH. Only when the file
+ // from which we are being called is located itself in CMAKE_ROOT, then
+ // prefer results from CMAKE_ROOT depending on the policy setting.
+ result = moduleInCMakeModulePath;
+ if (result.size() == 0)
+ {
+ result = moduleInCMakeRoot;
+ }
+
+ if ((moduleInCMakeModulePath.size()>0) && (moduleInCMakeRoot.size()>0))
+ {
+ const char* currentFile = this->GetDefinition("CMAKE_CURRENT_LIST_FILE");
+ std::string mods = cmakeRoot + std::string("/Modules/");
+ if (currentFile && strncmp(currentFile, mods.c_str(), mods.size()) == 0)
+ {
+ switch (this->GetPolicyStatus(cmPolicies::CMP0017))
+ {
+ case cmPolicies::WARN:
+ {
+ cmOStringStream e;
+ e << "File " << currentFile << " includes "
+ << moduleInCMakeModulePath
+ << " (found via CMAKE_MODULE_PATH) which shadows "
+ << moduleInCMakeRoot << ". This may cause errors later on .\n"
+ << this->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0017);
+
+ this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ // break; // fall through to OLD behaviour
+ }
+ case cmPolicies::OLD:
+ result = moduleInCMakeModulePath;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ result = moduleInCMakeRoot;
+ break;
+ }
+ }
+ }
+
+ return result;
+}
+
+void cmMakefile::ConfigureString(const std::string& input,
+ std::string& output, bool atOnly,
+ bool escapeQuotes) const
+{
+ // Split input to handle one line at a time.
+ std::string::const_iterator lineStart = input.begin();
+ while(lineStart != input.end())
+ {
+ // Find the end of this line.
+ std::string::const_iterator lineEnd = lineStart;
+ while(lineEnd != input.end() && *lineEnd != '\n')
+ {
+ ++lineEnd;
+ }
+
+ // Copy the line.
+ std::string line(lineStart, lineEnd);
+
+ // Skip the newline character.
+ bool haveNewline = (lineEnd != input.end());
+ if(haveNewline)
+ {
+ ++lineEnd;
+ }
+
+ // Replace #cmakedefine instances.
+ if(this->cmDefineRegex.find(line))
+ {
+ const char* def =
+ this->GetDefinition(this->cmDefineRegex.match(1));
+ if(!cmSystemTools::IsOff(def))
+ {
+ cmSystemTools::ReplaceString(line, "#cmakedefine", "#define");
+ output += line;
+ }
+ else
+ {
+ output += "/* #undef ";
+ output += this->cmDefineRegex.match(1);
+ output += " */";
+ }
+ }
+ else if(this->cmDefine01Regex.find(line))
+ {
+ const char* def =
+ this->GetDefinition(this->cmDefine01Regex.match(1));
+ cmSystemTools::ReplaceString(line, "#cmakedefine01", "#define");
+ output += line;
+ if(!cmSystemTools::IsOff(def))
+ {
+ output += " 1";
+ }
+ else
+ {
+ output += " 0";
+ }
+ }
+ else
+ {
+ output += line;
+ }
+
+ if(haveNewline)
+ {
+ output += "\n";
+ }
+
+ // Move to the next line.
+ lineStart = lineEnd;
+ }
+
+ // Perform variable replacements.
+ this->ExpandVariablesInString(output, escapeQuotes, true,
+ atOnly, 0, -1, true, true);
+}
+
+int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
+ bool copyonly, bool atOnly, bool escapeQuotes,
+ const cmNewLineStyle& newLine)
+{
+ int res = 1;
+ if ( !this->CanIWriteThisFile(outfile) )
+ {
+ cmSystemTools::Error("Attempt to write file: ",
+ outfile, " into a source directory.");
+ return 0;
+ }
+ if ( !cmSystemTools::FileExists(infile) )
+ {
+ cmSystemTools::Error("File ", infile, " does not exist.");
+ return 0;
+ }
+ std::string soutfile = outfile;
+ std::string sinfile = infile;
+ this->AddCMakeDependFile(sinfile);
+ cmSystemTools::ConvertToUnixSlashes(soutfile);
+
+ // Re-generate if non-temporary outputs are missing.
+ //when we finalize the configuration we will remove all
+ //output files that now don't exist.
+ this->AddCMakeOutputFile(soutfile);
+
+ mode_t perm = 0;
+ cmSystemTools::GetPermissions(sinfile.c_str(), perm);
+ std::string::size_type pos = soutfile.rfind('/');
+ if(pos != std::string::npos)
+ {
+ std::string path = soutfile.substr(0, pos);
+ cmSystemTools::MakeDirectory(path.c_str());
+ }
+
+ if(copyonly)
+ {
+ if ( !cmSystemTools::CopyFileIfDifferent(sinfile.c_str(),
+ soutfile.c_str()))
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ std::string newLineCharacters;
+ std::ios_base::openmode omode = std::ios_base::out | std::ios_base::trunc;
+ if (newLine.IsValid())
+ {
+ newLineCharacters = newLine.GetCharacters();
+ omode |= std::ios::binary;
+ }
+ else
+ {
+ newLineCharacters = "\n";
+ }
+ std::string tempOutputFile = soutfile;
+ tempOutputFile += ".tmp";
+ cmsys::ofstream fout(tempOutputFile.c_str(), omode);
+ if(!fout)
+ {
+ cmSystemTools::Error(
+ "Could not open file for write in copy operation ",
+ tempOutputFile.c_str());
+ cmSystemTools::ReportLastSystemError("");
+ return 0;
+ }
+ cmsys::ifstream fin(sinfile.c_str());
+ if(!fin)
+ {
+ cmSystemTools::Error("Could not open file for read in copy operation ",
+ sinfile.c_str());
+ return 0;
+ }
+
+ cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin);
+ if(bom != cmsys::FStream::BOM_None &&
+ bom != cmsys::FStream::BOM_UTF8)
+ {
+ cmOStringStream e;
+ e << "File starts with a Byte-Order-Mark that is not UTF-8:\n "
+ << sinfile;
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return 0;
+ }
+ // rewind to copy BOM to output file
+ fin.seekg(0);
+
+
+ // now copy input to output and expand variables in the
+ // input file at the same time
+ std::string inLine;
+ std::string outLine;
+ while( cmSystemTools::GetLineFromStream(fin, inLine) )
+ {
+ outLine = "";
+ this->ConfigureString(inLine, outLine, atOnly, escapeQuotes);
+ fout << outLine.c_str() << newLineCharacters;
+ }
+ // close the files before attempting to copy
+ fin.close();
+ fout.close();
+ if ( !cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
+ soutfile.c_str()) )
+ {
+ res = 0;
+ }
+ else
+ {
+ cmSystemTools::SetPermissions(soutfile.c_str(), perm);
+ }
+ cmSystemTools::RemoveFile(tempOutputFile.c_str());
+ }
+ return res;
+}
+
+void cmMakefile::SetProperty(const std::string& prop, const char* value)
+{
+ if ( prop == "LINK_DIRECTORIES" )
+ {
+ std::vector<std::string> varArgsExpanded;
+ if(value)
+ {
+ cmSystemTools::ExpandListArgument(value, varArgsExpanded);
+ }
+ this->SetLinkDirectories(varArgsExpanded);
+ return;
+ }
+ if (prop == "INCLUDE_DIRECTORIES")
+ {
+ this->IncludeDirectoriesEntries.clear();
+ if (!value)
+ {
+ return;
+ }
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ this->IncludeDirectoriesEntries.push_back(
+ cmValueWithOrigin(value, lfbt));
+ return;
+ }
+ if (prop == "COMPILE_OPTIONS")
+ {
+ this->CompileOptionsEntries.clear();
+ if (!value)
+ {
+ return;
+ }
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ this->CompileOptionsEntries.push_back(cmValueWithOrigin(value, lfbt));
+ return;
+ }
+ if (prop == "COMPILE_DEFINITIONS")
+ {
+ this->CompileDefinitionsEntries.clear();
+ if (!value)
+ {
+ return;
+ }
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ cmValueWithOrigin entry(value, lfbt);
+ this->CompileDefinitionsEntries.push_back(entry);
+ return;
+ }
+
+ if ( prop == "INCLUDE_REGULAR_EXPRESSION" )
+ {
+ this->SetIncludeRegularExpression(value);
+ return;
+ }
+
+ if ( prop == "ADDITIONAL_MAKE_CLEAN_FILES" )
+ {
+ // This property is not inherrited
+ if ( strcmp(this->GetCurrentDirectory(),
+ this->GetStartDirectory()) != 0 )
+ {
+ return;
+ }
+ }
+
+ this->Properties.SetProperty(prop,value,cmProperty::DIRECTORY);
+}
+
+void cmMakefile::AppendProperty(const std::string& prop,
+ const char* value,
+ bool asString)
+{
+ if (prop == "INCLUDE_DIRECTORIES")
+ {
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ this->IncludeDirectoriesEntries.push_back(
+ cmValueWithOrigin(value, lfbt));
+ return;
+ }
+ if (prop == "COMPILE_OPTIONS")
+ {
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ this->CompileOptionsEntries.push_back(
+ cmValueWithOrigin(value, lfbt));
+ return;
+ }
+ if (prop == "COMPILE_DEFINITIONS")
+ {
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ this->CompileDefinitionsEntries.push_back(
+ cmValueWithOrigin(value, lfbt));
+ return;
+ }
+ if ( prop == "LINK_DIRECTORIES" )
+ {
+ std::vector<std::string> varArgsExpanded;
+ cmSystemTools::ExpandListArgument(value, varArgsExpanded);
+ for(std::vector<std::string>::const_iterator vi = varArgsExpanded.begin();
+ vi != varArgsExpanded.end(); ++vi)
+ {
+ this->AddLinkDirectory(*vi);
+ }
+ return;
+ }
+
+ this->Properties.AppendProperty(prop,value,cmProperty::DIRECTORY,asString);
+}
+
+const char *cmMakefile::GetProperty(const std::string& prop) const
+{
+ return this->GetProperty(prop, cmProperty::DIRECTORY);
+}
+
+const char *cmMakefile::GetProperty(const std::string& prop,
+ cmProperty::ScopeType scope) const
+{
+ // watch for specific properties
+ static std::string output;
+ output = "";
+ if (prop == "PARENT_DIRECTORY")
+ {
+ if(cmLocalGenerator* plg = this->LocalGenerator->GetParent())
+ {
+ output = plg->GetMakefile()->GetStartDirectory();
+ }
+ return output.c_str();
+ }
+ else if (prop == "INCLUDE_REGULAR_EXPRESSION" )
+ {
+ output = this->GetIncludeRegularExpression();
+ return output.c_str();
+ }
+ else if (prop == "LISTFILE_STACK")
+ {
+ for (std::deque<std::string>::const_iterator
+ i = this->ListFileStack.begin();
+ i != this->ListFileStack.end(); ++i)
+ {
+ if (i != this->ListFileStack.begin())
+ {
+ output += ";";
+ }
+ output += *i;
+ }
+ return output.c_str();
+ }
+ else if (prop == "VARIABLES" || prop == "CACHE_VARIABLES")
+ {
+ int cacheonly = 0;
+ if ( prop == "CACHE_VARIABLES" )
+ {
+ cacheonly = 1;
+ }
+ std::vector<std::string> vars = this->GetDefinitions(cacheonly);
+ for (unsigned int cc = 0; cc < vars.size(); cc ++ )
+ {
+ if ( cc > 0 )
+ {
+ output += ";";
+ }
+ output += vars[cc];
+ }
+ return output.c_str();
+ }
+ else if (prop == "MACROS")
+ {
+ this->GetListOfMacros(output);
+ return output.c_str();
+ }
+ else if (prop == "DEFINITIONS")
+ {
+ output += this->DefineFlagsOrig;
+ return output.c_str();
+ }
+ else if (prop == "LINK_DIRECTORIES")
+ {
+ cmOStringStream str;
+ for (std::vector<std::string>::const_iterator
+ it = this->GetLinkDirectories().begin();
+ it != this->GetLinkDirectories().end();
+ ++ it )
+ {
+ if ( it != this->GetLinkDirectories().begin())
+ {
+ str << ";";
+ }
+ str << it->c_str();
+ }
+ output = str.str();
+ return output.c_str();
+ }
+ else if (prop == "INCLUDE_DIRECTORIES")
+ {
+ std::string sep;
+ for (std::vector<cmValueWithOrigin>::const_iterator
+ it = this->IncludeDirectoriesEntries.begin(),
+ end = this->IncludeDirectoriesEntries.end();
+ it != end; ++it)
+ {
+ output += sep;
+ output += it->Value;
+ sep = ";";
+ }
+ return output.c_str();
+ }
+ else if (prop == "COMPILE_OPTIONS")
+ {
+ std::string sep;
+ for (std::vector<cmValueWithOrigin>::const_iterator
+ it = this->CompileOptionsEntries.begin(),
+ end = this->CompileOptionsEntries.end();
+ it != end; ++it)
+ {
+ output += sep;
+ output += it->Value;
+ sep = ";";
+ }
+ return output.c_str();
+ }
+ else if (prop == "COMPILE_DEFINITIONS")
+ {
+ std::string sep;
+ for (std::vector<cmValueWithOrigin>::const_iterator
+ it = this->CompileDefinitionsEntries.begin(),
+ end = this->CompileDefinitionsEntries.end();
+ it != end; ++it)
+ {
+ output += sep;
+ output += it->Value;
+ sep = ";";
+ }
+ return output.c_str();
+ }
+
+ bool chain = false;
+ const char *retVal =
+ this->Properties.GetPropertyValue(prop, scope, chain);
+ if (chain)
+ {
+ if(this->LocalGenerator->GetParent())
+ {
+ return this->LocalGenerator->GetParent()->GetMakefile()->
+ GetProperty(prop, scope);
+ }
+ return this->GetCMakeInstance()->GetProperty(prop,scope);
+ }
+
+ return retVal;
+}
+
+bool cmMakefile::GetPropertyAsBool(const std::string& prop) const
+{
+ return cmSystemTools::IsOn(this->GetProperty(prop));
+}
+
+//----------------------------------------------------------------------------
+const char* cmMakefile::GetFeature(const std::string& feature,
+ const std::string& config)
+{
+ // TODO: Define accumulation policy for features (prepend, append, replace).
+ // Currently we always replace.
+ if(!config.empty())
+ {
+ std::string featureConfig = feature;
+ featureConfig += "_";
+ featureConfig += cmSystemTools::UpperCase(config);
+ if(const char* value = this->GetProperty(featureConfig))
+ {
+ return value;
+ }
+ }
+ if(const char* value = this->GetProperty(feature))
+ {
+ return value;
+ }
+ if(cmLocalGenerator* parent = this->LocalGenerator->GetParent())
+ {
+ return parent->GetMakefile()->GetFeature(feature, config);
+ }
+ return 0;
+}
+
+cmTarget* cmMakefile::FindTarget(const std::string& name,
+ bool excludeAliases) const
+{
+ if (!excludeAliases)
+ {
+ TargetMap::const_iterator i = this->AliasTargets.find(name);
+ if (i != this->AliasTargets.end())
+ {
+ return i->second;
+ }
+ }
+ cmTargets::iterator i = this->Targets.find( name );
+ if ( i != this->Targets.end() )
+ {
+ return &i->second;
+ }
+
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+cmTest* cmMakefile::CreateTest(const std::string& testName)
+{
+ cmTest* test = this->GetTest(testName);
+ if ( test )
+ {
+ return test;
+ }
+ test = new cmTest(this);
+ test->SetName(testName);
+ this->Tests[testName] = test;
+ return test;
+}
+
+//----------------------------------------------------------------------------
+cmTest* cmMakefile::GetTest(const std::string& testName) const
+{
+ std::map<std::string, cmTest*>::const_iterator
+ mi = this->Tests.find(testName);
+ if(mi != this->Tests.end())
+ {
+ return mi->second;
+ }
+ return 0;
+}
+
+void cmMakefile::AddCMakeDependFilesFromUser()
+{
+ std::vector<std::string> deps;
+ if(const char* deps_str = this->GetProperty("CMAKE_CONFIGURE_DEPENDS"))
+ {
+ cmSystemTools::ExpandListArgument(deps_str, deps);
+ }
+ for(std::vector<std::string>::iterator i = deps.begin();
+ i != deps.end(); ++i)
+ {
+ if(cmSystemTools::FileIsFullPath(i->c_str()))
+ {
+ this->AddCMakeDependFile(*i);
+ }
+ else
+ {
+ std::string f = this->GetCurrentDirectory();
+ f += "/";
+ f += *i;
+ this->AddCMakeDependFile(f);
+ }
+ }
+}
+
+std::string cmMakefile::GetListFileStack() const
+{
+ cmOStringStream tmp;
+ size_t depth = this->ListFileStack.size();
+ if (depth > 0)
+ {
+ std::deque<std::string>::const_iterator it = this->ListFileStack.end();
+ do
+ {
+ if (depth != this->ListFileStack.size())
+ {
+ tmp << "\n ";
+ }
+ --it;
+ tmp << "[";
+ tmp << depth;
+ tmp << "]\t";
+ tmp << *it;
+ depth--;
+ }
+ while (it != this->ListFileStack.begin());
+ }
+ return tmp.str();
+}
+
+
+void cmMakefile::PushScope()
+{
+ cmDefinitions* parent = &this->Internal->VarStack.top();
+ const std::set<std::string>& init = this->Internal->VarInitStack.top();
+ const std::set<std::string>& usage = this->Internal->VarUsageStack.top();
+ this->Internal->VarStack.push(cmDefinitions(parent));
+ this->Internal->VarInitStack.push(init);
+ this->Internal->VarUsageStack.push(usage);
+}
+
+void cmMakefile::PopScope()
+{
+ cmDefinitions* current = &this->Internal->VarStack.top();
+ std::set<std::string> init = this->Internal->VarInitStack.top();
+ std::set<std::string> usage = this->Internal->VarUsageStack.top();
+ const std::set<std::string>& locals = current->LocalKeys();
+ // Remove initialization and usage information for variables in the local
+ // scope.
+ std::set<std::string>::const_iterator it = locals.begin();
+ for (; it != locals.end(); ++it)
+ {
+ init.erase(*it);
+ if (!this->VariableUsed(*it))
+ {
+ this->CheckForUnused("out of scope", *it);
+ }
+ else
+ {
+ usage.erase(*it);
+ }
+ }
+ this->Internal->VarStack.pop();
+ this->Internal->VarInitStack.pop();
+ this->Internal->VarUsageStack.pop();
+ // Push initialization and usage up to the parent scope.
+ it = init.begin();
+ for (; it != init.end(); ++it)
+ {
+ this->Internal->VarInitStack.top().insert(*it);
+ }
+ it = usage.begin();
+ for (; it != usage.end(); ++it)
+ {
+ this->Internal->VarUsageStack.top().insert(*it);
+ }
+}
+
+void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
+{
+ if (var.empty())
+ {
+ return;
+ }
+
+ cmDefinitions& cur = this->Internal->VarStack.top();
+ if(cmDefinitions* up = cur.GetParent())
+ {
+ // First localize the definition in the current scope.
+ cur.Pull(var);
+
+ // Now update the definition in the parent scope.
+ up->Set(var, varDef);
+ }
+ else if(cmLocalGenerator* plg = this->LocalGenerator->GetParent())
+ {
+ // Update the definition in the parent directory top scope. This
+ // directory's scope was initialized by the closure of the parent
+ // scope, so we do not need to localize the definition first.
+ cmMakefile* parent = plg->GetMakefile();
+ if (varDef)
+ {
+ parent->AddDefinition(var, varDef);
+ }
+ else
+ {
+ parent->RemoveDefinition(var);
+ }
+ }
+ else
+ {
+ cmOStringStream m;
+ m << "Cannot set \"" << var << "\": current scope has no parent.";
+ this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
+ }
+}
+
+
+// define properties
+void cmMakefile::DefineProperties(cmake *cm)
+{
+ cm->DefineProperty
+ ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
+ "", "", true);
+ cm->DefineProperty
+ ("RULE_LAUNCH_LINK", cmProperty::DIRECTORY,
+ "", "", true);
+ cm->DefineProperty
+ ("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY,
+ "", "", true);
+}
+
+//----------------------------------------------------------------------------
+cmTarget*
+cmMakefile::AddImportedTarget(const std::string& name,
+ cmTarget::TargetType type,
+ bool global)
+{
+ // Create the target.
+ cmsys::auto_ptr<cmTarget> target(new cmTarget);
+ target->SetType(type, name);
+ target->MarkAsImported();
+ target->SetMakefile(this);
+
+ // Add to the set of available imported targets.
+ this->ImportedTargets[name] = target.get();
+ if(global)
+ {
+ this->LocalGenerator->GetGlobalGenerator()->AddTarget(target.get());
+ }
+
+ // Transfer ownership to this cmMakefile object.
+ this->ImportedTargetsOwned.push_back(target.get());
+ return target.release();
+}
+
+//----------------------------------------------------------------------------
+cmTarget* cmMakefile::FindTargetToUse(const std::string& name,
+ bool excludeAliases) const
+{
+ // Look for an imported target. These take priority because they
+ // are more local in scope and do not have to be globally unique.
+ TargetMap::const_iterator
+ imported = this->ImportedTargets.find(name);
+ if(imported != this->ImportedTargets.end())
+ {
+ return imported->second;
+ }
+
+ // Look for a target built in this directory.
+ if(cmTarget* t = this->FindTarget(name, excludeAliases))
+ {
+ return t;
+ }
+
+ // Look for a target built in this project.
+ return this->LocalGenerator->GetGlobalGenerator()->FindTarget(name,
+ excludeAliases);
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::IsAlias(const std::string& name) const
+{
+ if (this->AliasTargets.find(name) != this->AliasTargets.end())
+ return true;
+ return this->GetLocalGenerator()->GetGlobalGenerator()->IsAlias(
+ name);
+}
+
+//----------------------------------------------------------------------------
+cmGeneratorTarget*
+cmMakefile::FindGeneratorTargetToUse(const std::string& name) const
+{
+ if (cmTarget *t = this->FindTargetToUse(name))
+ {
+ return this->LocalGenerator->GetGlobalGenerator()->GetGeneratorTarget(t);
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
+ bool isCustom) const
+{
+ if(this->IsAlias(name))
+ {
+ cmOStringStream e;
+ e << "cannot create target \"" << name
+ << "\" because an alias with the same name already exists.";
+ msg = e.str();
+ return false;
+ }
+ if(cmTarget* existing = this->FindTargetToUse(name))
+ {
+ // The name given conflicts with an existing target. Produce an
+ // error in a compatible way.
+ if(existing->IsImported())
+ {
+ // Imported targets were not supported in previous versions.
+ // This is new code, so we can make it an error.
+ cmOStringStream e;
+ e << "cannot create target \"" << name
+ << "\" because an imported target with the same name already exists.";
+ msg = e.str();
+ return false;
+ }
+ else
+ {
+ // target names must be globally unique
+ switch (this->GetPolicyStatus(cmPolicies::CMP0002))
+ {
+ case cmPolicies::WARN:
+ this->IssueMessage(cmake::AUTHOR_WARNING, this->GetPolicies()->
+ GetPolicyWarning(cmPolicies::CMP0002));
+ case cmPolicies::OLD:
+ return true;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ this->IssueMessage(cmake::FATAL_ERROR,
+ this->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0002)
+ );
+ return true;
+ case cmPolicies::NEW:
+ break;
+ }
+
+ // The conflict is with a non-imported target.
+ // Allow this if the user has requested support.
+ cmake* cm =
+ this->LocalGenerator->GetGlobalGenerator()->GetCMakeInstance();
+ if(isCustom && existing->GetType() == cmTarget::UTILITY &&
+ this != existing->GetMakefile() &&
+ cm->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
+ {
+ return true;
+ }
+
+ // Produce an error that tells the user how to work around the
+ // problem.
+ cmOStringStream e;
+ e << "cannot create target \"" << name
+ << "\" because another target with the same name already exists. "
+ << "The existing target is ";
+ switch(existing->GetType())
+ {
+ case cmTarget::EXECUTABLE:
+ e << "an executable ";
+ break;
+ case cmTarget::STATIC_LIBRARY:
+ e << "a static library ";
+ break;
+ case cmTarget::SHARED_LIBRARY:
+ e << "a shared library ";
+ break;
+ case cmTarget::MODULE_LIBRARY:
+ e << "a module library ";
+ break;
+ case cmTarget::UTILITY:
+ e << "a custom target ";
+ break;
+ case cmTarget::INTERFACE_LIBRARY:
+ e << "an interface library ";
+ break;
+ default: break;
+ }
+ e << "created in source directory \""
+ << existing->GetMakefile()->GetCurrentDirectory() << "\". "
+ << "See documentation for policy CMP0002 for more details.";
+ msg = e.str();
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::EnforceUniqueDir(const std::string& srcPath,
+ const std::string& binPath) const
+{
+ // Make sure the binary directory is unique.
+ cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
+ if(gg->BinaryDirectoryIsNew(binPath))
+ {
+ return true;
+ }
+ cmOStringStream e;
+ switch (this->GetPolicyStatus(cmPolicies::CMP0013))
+ {
+ case cmPolicies::WARN:
+ // Print the warning.
+ e << this->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0013)
+ << "\n"
+ << "The binary directory\n"
+ << " " << binPath << "\n"
+ << "is already used to build a source directory. "
+ << "This command uses it to build source directory\n"
+ << " " << srcPath << "\n"
+ << "which can generate conflicting build files. "
+ << "CMake does not support this use case but it used "
+ << "to work accidentally and is being allowed for "
+ << "compatibility.";
+ this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ case cmPolicies::OLD:
+ // OLD behavior does not warn.
+ return true;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ e << this->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0013)
+ << "\n";
+ case cmPolicies::NEW:
+ // NEW behavior prints the error.
+ e << "The binary directory\n"
+ << " " << binPath << "\n"
+ << "is already used to build a source directory. "
+ << "It cannot be used to build source directory\n"
+ << " " << srcPath << "\n"
+ << "Specify a unique binary directory name.";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ break;
+ }
+
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::AddQtUiFileWithOptions(cmSourceFile *sf)
+{
+ this->QtUiFilesWithOptions.push_back(sf);
+}
+
+//----------------------------------------------------------------------------
+std::vector<cmSourceFile*> cmMakefile::GetQtUiFilesWithOptions() const
+{
+ return this->QtUiFilesWithOptions;
+}
+
+static std::string matchVariables[] = {
+ "CMAKE_MATCH_0",
+ "CMAKE_MATCH_1",
+ "CMAKE_MATCH_2",
+ "CMAKE_MATCH_3",
+ "CMAKE_MATCH_4",
+ "CMAKE_MATCH_5",
+ "CMAKE_MATCH_6",
+ "CMAKE_MATCH_7",
+ "CMAKE_MATCH_8",
+ "CMAKE_MATCH_9"
+};
+
+//----------------------------------------------------------------------------
+void cmMakefile::ClearMatches()
+{
+ for (unsigned int i=0; i<this->NumLastMatches; i++)
+ {
+ std::string const& var = matchVariables[i];
+ std::string const& s = this->GetSafeDefinition(var);
+ if(!s.empty())
+ {
+ this->AddDefinition(var, "");
+ this->MarkVariableAsUsed(var);
+ }
+ }
+ this->NumLastMatches = 0;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::StoreMatches(cmsys::RegularExpression& re)
+{
+ for (unsigned int i=0; i<10; i++)
+ {
+ std::string const& m = re.match(i);
+ if(!m.empty())
+ {
+ std::string const& var = matchVariables[i];
+ this->AddDefinition(var, m.c_str());
+ this->MarkVariableAsUsed(var);
+ this->NumLastMatches = i + 1;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+cmPolicies::PolicyStatus
+cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id) const
+{
+ // Get the current setting of the policy.
+ cmPolicies::PolicyStatus cur = this->GetPolicyStatusInternal(id);
+
+ // If the policy is required to be set to NEW but is not, ignore the
+ // current setting and tell the caller.
+ if(cur != cmPolicies::NEW)
+ {
+ if(cur == cmPolicies::REQUIRED_ALWAYS ||
+ cur == cmPolicies::REQUIRED_IF_USED)
+ {
+ return cur;
+ }
+ cmPolicies::PolicyStatus def = this->GetPolicies()->GetPolicyStatus(id);
+ if(def == cmPolicies::REQUIRED_ALWAYS ||
+ def == cmPolicies::REQUIRED_IF_USED)
+ {
+ return def;
+ }
+ }
+
+ // The current setting is okay.
+ return cur;
+}
+
+//----------------------------------------------------------------------------
+cmPolicies::PolicyStatus
+cmMakefile::GetPolicyStatusInternal(cmPolicies::PolicyID id) const
+{
+ // Is the policy set in our stack?
+ for(PolicyStackType::const_reverse_iterator psi = this->PolicyStack.rbegin();
+ psi != this->PolicyStack.rend(); ++psi)
+ {
+ PolicyStackEntry::const_iterator pse = psi->find(id);
+ if(pse != psi->end())
+ {
+ return pse->second;
+ }
+ }
+
+ // If we have a parent directory, recurse up to it.
+ if(this->LocalGenerator->GetParent())
+ {
+ cmMakefile* parent = this->LocalGenerator->GetParent()->GetMakefile();
+ return parent->GetPolicyStatusInternal(id);
+ }
+
+ // The policy is not set. Use the default for this CMake version.
+ return this->GetPolicies()->GetPolicyStatus(id);
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::PolicyOptionalWarningEnabled(std::string const& var)
+{
+ // Check for an explicit CMAKE_POLICY_WARNING_CMP<NNNN> setting.
+ if(!var.empty())
+ {
+ if(const char* val = this->GetDefinition(var))
+ {
+ return cmSystemTools::IsOn(val);
+ }
+ }
+ // Enable optional policy warnings with --debug-output or --trace.
+ cmake* cm = this->GetCMakeInstance();
+ return cm->GetDebugOutput() || cm->GetTrace();
+}
+
+bool cmMakefile::SetPolicy(const char *id,
+ cmPolicies::PolicyStatus status)
+{
+ cmPolicies::PolicyID pid;
+ if (!this->GetPolicies()->GetPolicyID(id, /* out */ pid))
+ {
+ cmOStringStream e;
+ e << "Policy \"" << id << "\" is not known to this version of CMake.";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+ return this->SetPolicy(pid,status);
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
+ cmPolicies::PolicyStatus status)
+{
+ // A REQUIRED_ALWAYS policy may be set only to NEW.
+ if(status != cmPolicies::NEW &&
+ this->GetPolicies()->GetPolicyStatus(id) ==
+ cmPolicies::REQUIRED_ALWAYS)
+ {
+ std::string msg =
+ this->GetPolicies()->GetRequiredAlwaysPolicyError(id);
+ this->IssueMessage(cmake::FATAL_ERROR, msg);
+ return false;
+ }
+
+ // Update the policy stack from the top to the top-most strong entry.
+ bool previous_was_weak = true;
+ for(PolicyStackType::reverse_iterator psi = this->PolicyStack.rbegin();
+ previous_was_weak && psi != this->PolicyStack.rend(); ++psi)
+ {
+ (*psi)[id] = status;
+ previous_was_weak = psi->Weak;
+ }
+
+ // Special hook for presenting compatibility variable as soon as
+ // the user requests it.
+ if(id == cmPolicies::CMP0001 &&
+ (status == cmPolicies::WARN || status == cmPolicies::OLD))
+ {
+ if(!(this->GetCacheManager()
+ ->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")))
+ {
+ // Set it to 2.4 because that is the last version where the
+ // variable had meaning.
+ this->AddCacheDefinition
+ ("CMAKE_BACKWARDS_COMPATIBILITY", "2.4",
+ "For backwards compatibility, what version of CMake "
+ "commands and "
+ "syntax should this version of CMake try to support.",
+ cmCacheManager::STRING);
+ }
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+cmMakefile::PolicyPushPop::PolicyPushPop(cmMakefile* m, bool weak,
+ cmPolicies::PolicyMap const& pm):
+ Makefile(m), ReportError(true)
+{
+ this->Makefile->PushPolicy(weak, pm);
+ this->Makefile->PushPolicyBarrier();
+}
+
+//----------------------------------------------------------------------------
+cmMakefile::PolicyPushPop::~PolicyPushPop()
+{
+ this->Makefile->PopPolicyBarrier(this->ReportError);
+ this->Makefile->PopPolicy();
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::PushPolicy(bool weak, cmPolicies::PolicyMap const& pm)
+{
+ // Allocate a new stack entry.
+ this->PolicyStack.push_back(PolicyStackEntry(pm, weak));
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::PopPolicy()
+{
+ if(this->PolicyStack.size() > this->PolicyBarriers.back())
+ {
+ this->PolicyStack.pop_back();
+ }
+ else
+ {
+ this->IssueMessage(cmake::FATAL_ERROR,
+ "cmake_policy POP without matching PUSH");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::PushPolicyBarrier()
+{
+ this->PolicyBarriers.push_back(this->PolicyStack.size());
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::PopPolicyBarrier(bool reportError)
+{
+ // Remove any extra entries pushed on the barrier.
+ PolicyStackType::size_type barrier = this->PolicyBarriers.back();
+ while(this->PolicyStack.size() > barrier)
+ {
+ if(reportError)
+ {
+ this->IssueMessage(cmake::FATAL_ERROR,
+ "cmake_policy PUSH without matching POP");
+ reportError = false;
+ }
+ this->PopPolicy();
+ }
+
+ // Remove the barrier.
+ this->PolicyBarriers.pop_back();
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::SetPolicyVersion(const char *version)
+{
+ return this->GetCMakeInstance()->GetPolicies()->
+ ApplyPolicyVersion(this,version);
+}
+
+//----------------------------------------------------------------------------
+cmPolicies *cmMakefile::GetPolicies() const
+{
+ if (!this->GetCMakeInstance())
+ {
+ return 0;
+ }
+ return this->GetCMakeInstance()->GetPolicies();
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::HasCMP0054AlreadyBeenReported(
+ cmListFileContext context) const
+{
+ cmCMP0054Id id(context);
+
+ bool alreadyReported =
+ this->CMP0054ReportedIds.find(id) != this->CMP0054ReportedIds.end();
+
+ if(!alreadyReported)
+ {
+ this->CMP0054ReportedIds.insert(id);
+ }
+
+ return alreadyReported;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm)
+{
+ /* Record the setting of every policy. */
+ typedef cmPolicies::PolicyID PolicyID;
+ for(PolicyID pid = cmPolicies::CMP0000;
+ pid != cmPolicies::CMPCOUNT; pid = PolicyID(pid+1))
+ {
+ pm[pid] = this->GetPolicyStatus(pid);
+ }
+}
+
+#define FEATURE_STRING(F) , #F
+static const char * const C_FEATURES[] = {
+ 0
+ FOR_EACH_C_FEATURE(FEATURE_STRING)
+};
+
+static const char * const CXX_FEATURES[] = {
+ 0
+ FOR_EACH_CXX_FEATURE(FEATURE_STRING)
+};
+#undef FEATURE_STRING
+
+static const char * const C_STANDARDS[] = {
+ "90"
+ , "99"
+ , "11"
+};
+static const char * const CXX_STANDARDS[] = {
+ "98"
+ , "11"
+ , "14"
+};
+
+//----------------------------------------------------------------------------
+bool cmMakefile::
+AddRequiredTargetFeature(cmTarget *target, const std::string& feature,
+ std::string *error) const
+{
+ if (cmGeneratorExpression::Find(feature) != std::string::npos)
+ {
+ target->AppendProperty("COMPILE_FEATURES", feature.c_str());
+ return true;
+ }
+
+ std::string lang;
+ if (!this->CompileFeatureKnown(target, feature, lang, error))
+ {
+ return false;
+ }
+
+ const char* features = this->CompileFeaturesAvailable(lang, error);
+ if (!features)
+ {
+ return false;
+ }
+
+ std::vector<std::string> availableFeatures;
+ cmSystemTools::ExpandListArgument(features, availableFeatures);
+ if (std::find(availableFeatures.begin(),
+ availableFeatures.end(),
+ feature) == availableFeatures.end())
+ {
+ cmOStringStream e;
+ e << "The compiler feature \"" << feature
+ << "\" is not known to " << lang << " compiler\n\""
+ << this->GetDefinition("CMAKE_" + lang + "_COMPILER_ID")
+ << "\"\nversion "
+ << this->GetDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << ".";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ target->AppendProperty("COMPILE_FEATURES", feature.c_str());
+
+ return lang == "C"
+ ? this->AddRequiredTargetCFeature(target, feature)
+ : this->AddRequiredTargetCxxFeature(target, feature);
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::
+CompileFeatureKnown(cmTarget const* target, const std::string& feature,
+ std::string& lang, std::string *error) const
+{
+ assert(cmGeneratorExpression::Find(feature) == std::string::npos);
+
+ bool isCFeature = std::find_if(cmArrayBegin(C_FEATURES) + 1,
+ cmArrayEnd(C_FEATURES), cmStrCmp(feature))
+ != cmArrayEnd(C_FEATURES);
+ if (isCFeature)
+ {
+ lang = "C";
+ return true;
+ }
+ bool isCxxFeature = std::find_if(cmArrayBegin(CXX_FEATURES) + 1,
+ cmArrayEnd(CXX_FEATURES), cmStrCmp(feature))
+ != cmArrayEnd(CXX_FEATURES);
+ if (isCxxFeature)
+ {
+ lang = "CXX";
+ return true;
+ }
+ cmOStringStream e;
+ if (error)
+ {
+ e << "specified";
+ }
+ else
+ {
+ e << "Specified";
+ }
+ e << " unknown feature \"" << feature << "\" for "
+ "target \"" << target->GetName() << "\".";
+ if (error)
+ {
+ *error = e.str();
+ }
+ else
+ {
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+const char* cmMakefile::
+CompileFeaturesAvailable(const std::string& lang, std::string *error) const
+{
+ const char* featuresKnown =
+ this->GetDefinition("CMAKE_" + lang + "_COMPILE_FEATURES");
+
+ if (!featuresKnown || !*featuresKnown)
+ {
+ cmOStringStream e;
+ if (error)
+ {
+ e << "no";
+ }
+ else
+ {
+ e << "No";
+ }
+ e << " known features for " << lang << " compiler\n\""
+ << this->GetDefinition("CMAKE_" + lang + "_COMPILER_ID")
+ << "\"\nversion "
+ << this->GetDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << ".";
+ if (error)
+ {
+ *error = e.str();
+ }
+ else
+ {
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ return 0;
+ }
+ return featuresKnown;
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::HaveFeatureAvailable(cmTarget const* target,
+ std::string const& lang,
+ const std::string& feature) const
+{
+ return lang == "C"
+ ? this->HaveCFeatureAvailable(target, feature)
+ : this->HaveCxxFeatureAvailable(target, feature);
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::
+HaveCFeatureAvailable(cmTarget const* target, const std::string& feature) const
+{
+ bool needC90 = false;
+ bool needC99 = false;
+ bool needC11 = false;
+
+ this->CheckNeededCLanguage(feature, needC90, needC99, needC11);
+
+ const char *existingCStandard = target->GetProperty("C_STANDARD");
+ if (!existingCStandard)
+ {
+ existingCStandard = this->GetDefinition("CMAKE_C_STANDARD_DEFAULT");
+ }
+
+ if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
+ cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS))
+ {
+ cmOStringStream e;
+ e << "The C_STANDARD property on target \"" << target->GetName()
+ << "\" contained an invalid value: \"" << existingCStandard << "\".";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ return false;
+ }
+
+ const char * const *existingCIt = existingCStandard
+ ? std::find_if(cmArrayBegin(C_STANDARDS),
+ cmArrayEnd(C_STANDARDS),
+ cmStrCmp(existingCStandard))
+ : cmArrayEnd(C_STANDARDS);
+
+ if (needC11 && existingCStandard && existingCIt <
+ std::find_if(cmArrayBegin(C_STANDARDS),
+ cmArrayEnd(C_STANDARDS),
+ cmStrCmp("11")))
+ {
+ return false;
+ }
+ else if(needC99 && existingCStandard && existingCIt <
+ std::find_if(cmArrayBegin(C_STANDARDS),
+ cmArrayEnd(C_STANDARDS),
+ cmStrCmp("99")))
+ {
+ return false;
+ }
+ else if(needC90 && existingCStandard && existingCIt <
+ std::find_if(cmArrayBegin(C_STANDARDS),
+ cmArrayEnd(C_STANDARDS),
+ cmStrCmp("90")))
+ {
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::IsLaterStandard(std::string const& lang,
+ std::string const& lhs,
+ std::string const& rhs)
+{
+ if (lang == "C")
+ {
+ const char * const *rhsIt = std::find_if(cmArrayBegin(C_STANDARDS),
+ cmArrayEnd(C_STANDARDS),
+ cmStrCmp(rhs));
+
+ return std::find_if(rhsIt, cmArrayEnd(C_STANDARDS),
+ cmStrCmp(lhs)) != cmArrayEnd(C_STANDARDS);
+ }
+ const char * const *rhsIt = std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp(rhs));
+
+ return std::find_if(rhsIt, cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp(lhs)) != cmArrayEnd(CXX_STANDARDS);
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::HaveCxxFeatureAvailable(cmTarget const* target,
+ const std::string& feature) const
+{
+ bool needCxx98 = false;
+ bool needCxx11 = false;
+ bool needCxx14 = false;
+ this->CheckNeededCxxLanguage(feature, needCxx98, needCxx11, needCxx14);
+
+ const char *existingCxxStandard = target->GetProperty("CXX_STANDARD");
+ if (!existingCxxStandard)
+ {
+ existingCxxStandard = this->GetDefinition("CMAKE_CXX_STANDARD_DEFAULT");
+ }
+
+ if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp(existingCxxStandard)) == cmArrayEnd(CXX_STANDARDS))
+ {
+ cmOStringStream e;
+ e << "The CXX_STANDARD property on target \"" << target->GetName()
+ << "\" contained an invalid value: \"" << existingCxxStandard << "\".";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ const char * const *existingCxxIt = existingCxxStandard
+ ? std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp(existingCxxStandard))
+ : cmArrayEnd(CXX_STANDARDS);
+
+ if (needCxx11 && existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp("11")))
+ {
+ return false;
+ }
+ else if(needCxx98 && existingCxxIt <
+ std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp("98")))
+ {
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::CheckNeededCxxLanguage(const std::string& feature,
+ bool& needCxx98,
+ bool& needCxx11,
+ bool& needCxx14) const
+{
+ if (const char *propCxx98 =
+ this->GetDefinition("CMAKE_CXX98_COMPILE_FEATURES"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propCxx98, props);
+ needCxx98 = std::find(props.begin(), props.end(), feature) != props.end();
+ }
+ if (const char *propCxx11 =
+ this->GetDefinition("CMAKE_CXX11_COMPILE_FEATURES"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propCxx11, props);
+ needCxx11 = std::find(props.begin(), props.end(), feature) != props.end();
+ }
+ if (const char *propCxx14 =
+ this->GetDefinition("CMAKE_CXX14_COMPILE_FEATURES"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propCxx14, props);
+ needCxx14 = std::find(props.begin(), props.end(), feature) != props.end();
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::
+AddRequiredTargetCxxFeature(cmTarget *target,
+ const std::string& feature) const
+{
+ bool needCxx98 = false;
+ bool needCxx11 = false;
+ bool needCxx14 = false;
+
+ this->CheckNeededCxxLanguage(feature, needCxx98, needCxx11, needCxx14);
+
+ const char *existingCxxStandard = target->GetProperty("CXX_STANDARD");
+ if (existingCxxStandard)
+ {
+ if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp(existingCxxStandard)) == cmArrayEnd(CXX_STANDARDS))
+ {
+ cmOStringStream e;
+ e << "The CXX_STANDARD property on target \"" << target->GetName()
+ << "\" contained an invalid value: \"" << existingCxxStandard << "\".";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+ }
+ const char * const *existingCxxIt = existingCxxStandard
+ ? std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp(existingCxxStandard))
+ : cmArrayEnd(CXX_STANDARDS);
+
+ bool setCxx98 = needCxx98 && !existingCxxStandard;
+ bool setCxx11 = needCxx11 && !existingCxxStandard;
+ bool setCxx14 = needCxx14 && !existingCxxStandard;
+
+ if (needCxx14 && existingCxxStandard && existingCxxIt <
+ std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp("14")))
+ {
+ setCxx14 = true;
+ }
+ else if (needCxx11 && existingCxxStandard && existingCxxIt <
+ std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp("11")))
+ {
+ setCxx11 = true;
+ }
+ else if(needCxx98 && existingCxxStandard && existingCxxIt <
+ std::find_if(cmArrayBegin(CXX_STANDARDS),
+ cmArrayEnd(CXX_STANDARDS),
+ cmStrCmp("98")))
+ {
+ setCxx98 = true;
+ }
+
+ if (setCxx14)
+ {
+ target->SetProperty("CXX_STANDARD", "14");
+ }
+ else if (setCxx11)
+ {
+ target->SetProperty("CXX_STANDARD", "11");
+ }
+ else if (setCxx98)
+ {
+ target->SetProperty("CXX_STANDARD", "98");
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::CheckNeededCLanguage(const std::string& feature,
+ bool& needC90,
+ bool& needC99,
+ bool& needC11) const
+{
+ if (const char *propC90 =
+ this->GetDefinition("CMAKE_C90_COMPILE_FEATURES"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propC90, props);
+ needC90 = std::find(props.begin(), props.end(), feature) != props.end();
+ }
+ if (const char *propC99 =
+ this->GetDefinition("CMAKE_C99_COMPILE_FEATURES"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propC99, props);
+ needC99 = std::find(props.begin(), props.end(), feature) != props.end();
+ }
+ if (const char *propC11 =
+ this->GetDefinition("CMAKE_C11_COMPILE_FEATURES"))
+ {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propC11, props);
+ needC11 = std::find(props.begin(), props.end(), feature) != props.end();
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefile::
+AddRequiredTargetCFeature(cmTarget *target, const std::string& feature) const
+{
+ bool needC90 = false;
+ bool needC99 = false;
+ bool needC11 = false;
+
+ this->CheckNeededCLanguage(feature, needC90, needC99, needC11);
+
+ const char *existingCStandard = target->GetProperty("C_STANDARD");
+ if (existingCStandard)
+ {
+ if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
+ cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS))
+ {
+ cmOStringStream e;
+ e << "The C_STANDARD property on target \"" << target->GetName()
+ << "\" contained an invalid value: \"" << existingCStandard << "\".";
+ this->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ return false;
+ }
+ }
+ const char * const *existingCIt = existingCStandard
+ ? std::find_if(cmArrayBegin(C_STANDARDS),
+ cmArrayEnd(C_STANDARDS),
+ cmStrCmp(existingCStandard))
+ : cmArrayEnd(C_STANDARDS);
+
+ bool setC90 = needC90 && !existingCStandard;
+ bool setC99 = needC99 && !existingCStandard;
+ bool setC11 = needC11 && !existingCStandard;
+
+ if (needC11 && existingCStandard && existingCIt <
+ std::find_if(cmArrayBegin(C_STANDARDS),
+ cmArrayEnd(C_STANDARDS),
+ cmStrCmp("11")))
+ {
+ setC11 = true;
+ }
+ else if(needC99 && existingCStandard && existingCIt <
+ std::find_if(cmArrayBegin(C_STANDARDS),
+ cmArrayEnd(C_STANDARDS),
+ cmStrCmp("99")))
+ {
+ setC99 = true;
+ }
+ else if(needC90 && existingCStandard && existingCIt <
+ std::find_if(cmArrayBegin(C_STANDARDS),
+ cmArrayEnd(C_STANDARDS),
+ cmStrCmp("90")))
+ {
+ setC90 = true;
+ }
+
+ if (setC11)
+ {
+ target->SetProperty("C_STANDARD", "11");
+ }
+ else if (setC99)
+ {
+ target->SetProperty("C_STANDARD", "99");
+ }
+ else if (setC90)
+ {
+ target->SetProperty("C_STANDARD", "90");
+ }
+ return true;
+}
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
new file mode 100644
index 0000000000..164290aa9d
--- /dev/null
+++ b/Source/cmMakefile.h
@@ -0,0 +1,1194 @@
+/*============================================================================
+ 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 cmMakefile_h
+#define cmMakefile_h
+
+#include "cmCacheManager.h"
+#include "cmExecutionStatus.h"
+#include "cmListFileCache.h"
+#include "cmPolicies.h"
+#include "cmPropertyMap.h"
+#include "cmSystemTools.h"
+#include "cmTarget.h"
+#include "cmNewLineStyle.h"
+#include "cmGeneratorTarget.h"
+#include "cmExpandedCommandArgument.h"
+#include "cmake.h"
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+#include "cmSourceGroup.h"
+#endif
+
+#include <cmsys/auto_ptr.hxx>
+#include <cmsys/RegularExpression.hxx>
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include <cmsys/hash_map.hxx>
+#endif
+
+class cmFunctionBlocker;
+class cmCommand;
+class cmInstallGenerator;
+class cmLocalGenerator;
+class cmMakeDepend;
+class cmSourceFile;
+class cmTest;
+class cmTestGenerator;
+class cmVariableWatch;
+class cmake;
+class cmMakefileCall;
+class cmCMakePolicyCommand;
+
+/** \class cmMakefile
+ * \brief Process the input CMakeLists.txt file.
+ *
+ * Process and store into memory the input CMakeLists.txt file.
+ * Each CMakeLists.txt file is parsed and the commands found there
+ * are added into the build process.
+ */
+class cmMakefile
+{
+ class Internals;
+ cmsys::auto_ptr<Internals> Internal;
+public:
+ /**
+ * Return the major and minor version of the cmake that
+ * was used to write the currently loaded cache, note
+ * this method will not work before the cache is loaded.
+ */
+ unsigned int GetCacheMajorVersion() const;
+ unsigned int GetCacheMinorVersion() const;
+
+ /* Check for unused variables in this scope */
+ void CheckForUnusedVariables() const;
+ /* Mark a variable as used */
+ void MarkVariableAsUsed(const std::string& var);
+ /* return true if a variable has been initialized */
+ bool VariableInitialized(const std::string& ) const;
+ /* return true if a variable has been used */
+ bool VariableUsed(const std::string& ) const;
+ /** Return whether compatibility features needed for a version of
+ the cache or lower should be enabled. */
+ bool NeedCacheCompatibility(int major, int minor) const;
+
+ /**
+ * Construct an empty makefile.
+ */
+ cmMakefile();
+ cmMakefile(const cmMakefile& mf);
+
+ /**
+ * Destructor.
+ */
+ ~cmMakefile();
+
+ /**
+ * Read and parse a CMakeLists.txt file.
+ */
+ bool ReadListFile(const char* listfile,
+ const char* external= 0,
+ std::string* fullPath= 0,
+ bool noPolicyScope = true);
+
+ /**
+ * Add a function blocker to this makefile
+ */
+ void AddFunctionBlocker(cmFunctionBlocker* fb);
+
+ /**
+ * Remove the function blocker whose scope ends with the given command.
+ * This returns ownership of the function blocker object.
+ */
+ cmsys::auto_ptr<cmFunctionBlocker>
+ RemoveFunctionBlocker(cmFunctionBlocker* fb, const cmListFileFunction& lff);
+
+ /** Push/pop a lexical (function blocker) barrier automatically. */
+ class LexicalPushPop
+ {
+ public:
+ LexicalPushPop(cmMakefile* mf);
+ ~LexicalPushPop();
+ void Quiet() { this->ReportError = false; }
+ private:
+ cmMakefile* Makefile;
+ bool ReportError;
+ };
+ friend class LexicalPushPop;
+
+ /**
+ * Try running cmake and building a file. This is used for dynalically
+ * loaded commands, not as part of the usual build process.
+ */
+ int TryCompile(const std::string& srcdir, const std::string& bindir,
+ const std::string& projectName, const std::string& targetName,
+ bool fast,
+ const std::vector<std::string> *cmakeArgs,
+ std::string& output);
+
+ bool GetIsSourceFileTryCompile() const;
+
+ /**
+ * Specify the makefile generator. This is platform/compiler
+ * dependent, although the interface is through a generic
+ * superclass.
+ */
+ void SetLocalGenerator(cmLocalGenerator*);
+
+ ///! Get the current makefile generator.
+ cmLocalGenerator* GetLocalGenerator() const
+ { return this->LocalGenerator;}
+
+ /**
+ * Help enforce global target name uniqueness.
+ */
+ bool EnforceUniqueName(std::string const& name, std::string& msg,
+ bool isCustom = false) const;
+
+ /**
+ * Perform FinalPass, Library dependency analysis etc before output of the
+ * makefile.
+ */
+ void ConfigureFinalPass();
+
+ /**
+ * run the final pass on all commands.
+ */
+ void FinalPass();
+
+ /**
+ * Print the object state to std::cout.
+ */
+ void Print() const;
+
+ /** Add a custom command to the build. */
+ void AddCustomCommandToTarget(const std::string& target,
+ const std::vector<std::string>& depends,
+ const cmCustomCommandLines& commandLines,
+ cmTarget::CustomCommandType type,
+ const char* comment, const char* workingDir,
+ bool escapeOldStyle = true) const;
+ cmSourceFile* AddCustomCommandToOutput(
+ const std::vector<std::string>& outputs,
+ const std::vector<std::string>& depends,
+ const std::string& main_dependency,
+ const cmCustomCommandLines& commandLines,
+ const char* comment, const char* workingDir,
+ bool replace = false,
+ bool escapeOldStyle = true);
+ cmSourceFile* AddCustomCommandToOutput(
+ const std::string& output,
+ const std::vector<std::string>& depends,
+ const std::string& main_dependency,
+ const cmCustomCommandLines& commandLines,
+ const char* comment, const char* workingDir,
+ bool replace = false,
+ bool escapeOldStyle = true);
+ void AddCustomCommandOldStyle(const std::string& target,
+ const std::vector<std::string>& outputs,
+ const std::vector<std::string>& depends,
+ const std::string& source,
+ const cmCustomCommandLines& commandLines,
+ const char* comment);
+
+ /**
+ * Add a define flag to the build.
+ */
+ void AddDefineFlag(const char* definition);
+ void RemoveDefineFlag(const char* definition);
+ void AddCompileOption(const char* option);
+
+ /** Create a new imported target with the name and type given. */
+ cmTarget* AddImportedTarget(const std::string& name,
+ cmTarget::TargetType type,
+ bool global);
+
+ cmTarget* AddNewTarget(cmTarget::TargetType type, const std::string& name);
+
+ /**
+ * Add an executable to the build.
+ */
+ cmTarget* AddExecutable(const char *exename,
+ const std::vector<std::string> &srcs,
+ bool excludeFromAll = false);
+
+ /**
+ * Add a utility to the build. A utiltity target is a command that
+ * is run every time the target is built.
+ */
+ void AddUtilityCommand(const std::string& utilityName, bool excludeFromAll,
+ const std::vector<std::string>& depends,
+ const char* workingDirectory,
+ const char* command,
+ const char* arg1=0,
+ const char* arg2=0,
+ const char* arg3=0,
+ const char* arg4=0);
+ cmTarget* AddUtilityCommand(const std::string& utilityName,
+ bool excludeFromAll,
+ const char* workingDirectory,
+ const std::vector<std::string>& depends,
+ const cmCustomCommandLines& commandLines,
+ bool escapeOldStyle = true,
+ const char* comment = 0);
+
+ /**
+ * Add a link library to the build.
+ */
+ void AddLinkLibrary(const std::string&);
+ void AddLinkLibrary(const std::string&, cmTarget::LinkLibraryType type);
+ void AddLinkLibraryForTarget(const std::string& tgt, const std::string&,
+ cmTarget::LinkLibraryType type);
+ void AddLinkDirectoryForTarget(const std::string& tgt, const std::string& d);
+
+ /**
+ * Add a link directory to the build.
+ */
+ void AddLinkDirectory(const std::string&);
+
+ const std::vector<std::string>& GetLinkDirectories() const
+ {
+ return this->LinkDirectories;
+ }
+ void SetLinkDirectories(const std::vector<std::string>& vec)
+ {
+ this->LinkDirectories = vec;
+ }
+
+ /**
+ * Add a subdirectory to the build.
+ */
+ void AddSubDirectory(const std::string&, bool excludeFromAll=false,
+ bool preorder = false);
+ void AddSubDirectory(const std::string& fullSrcDir,
+ const std::string& fullBinDir,
+ bool excludeFromAll, bool preorder,
+ bool immediate);
+
+ /**
+ * Configure a subdirectory
+ */
+ void ConfigureSubDirectory(cmLocalGenerator *);
+
+ /**
+ * Add an include directory to the build.
+ */
+ void AddIncludeDirectories(const std::vector<std::string> &incs,
+ bool before = false);
+
+ /**
+ * Add a variable definition to the build. This variable
+ * can be used in CMake to refer to lists, directories, etc.
+ */
+ void AddDefinition(const std::string& name, const char* value);
+ ///! Add a definition to this makefile and the global cmake cache.
+ void AddCacheDefinition(const std::string& name, const char* value,
+ const char* doc,
+ cmCacheManager::CacheEntryType type,
+ bool force = false);
+
+ /**
+ * Add bool variable definition to the build.
+ */
+ void AddDefinition(const std::string& name, bool);
+
+ /**
+ * Remove a variable definition from the build. This is not valid
+ * for cache entries, and will only affect the current makefile.
+ */
+ void RemoveDefinition(const std::string& name);
+ ///! Remove a definition from the cache.
+ void RemoveCacheDefinition(const std::string& name);
+
+ /**
+ * Specify the name of the project for this build.
+ */
+ void SetProjectName(const char*);
+
+ /**
+ * Get the name of the project for this build.
+ */
+ const char* GetProjectName() const
+ {
+ return this->ProjectName.c_str();
+ }
+
+ /** Get the configurations to be generated. */
+ std::string GetConfigurations(std::vector<std::string>& configs,
+ bool single = true) const;
+
+ /**
+ * Set the name of the library.
+ */
+ cmTarget* AddLibrary(const std::string& libname, cmTarget::TargetType type,
+ const std::vector<std::string> &srcs,
+ bool excludeFromAll = false);
+ void AddAlias(const std::string& libname, cmTarget *tgt);
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ /**
+ * Add a root source group for consideration when adding a new source.
+ */
+ void AddSourceGroup(const std::string& name, const char* regex=0);
+
+ /**
+ * Add a source group for consideration when adding a new source.
+ * name is tokenized.
+ */
+ void AddSourceGroup(const std::vector<std::string>& name,
+ const char* regex=0);
+
+#endif
+
+ //@{
+ /**
+ * Set, Push, Pop policy values for CMake.
+ */
+ bool SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
+ bool SetPolicy(const char *id, cmPolicies::PolicyStatus status);
+ cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
+ bool SetPolicyVersion(const char *version);
+ void RecordPolicies(cmPolicies::PolicyMap& pm);
+ //@}
+
+ /** Helper class to push and pop policies automatically. */
+ class PolicyPushPop
+ {
+ public:
+ PolicyPushPop(cmMakefile* m,
+ bool weak = false,
+ cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
+ ~PolicyPushPop();
+ void Quiet() { this->ReportError = false; }
+ private:
+ cmMakefile* Makefile;
+ bool ReportError;
+ };
+ friend class PolicyPushPop;
+
+ /**
+ * Get the Policies Instance
+ */
+ cmPolicies *GetPolicies() const;
+
+ struct cmCMP0054Id
+ {
+ cmCMP0054Id(cmListFileContext const& context):
+ Context(context)
+ {
+
+ }
+
+ bool operator< (cmCMP0054Id const& id) const
+ {
+ if(this->Context.FilePath != id.Context.FilePath)
+ return this->Context.FilePath < id.Context.FilePath;
+
+ return this->Context.Line < id.Context.Line;
+ }
+
+ cmListFileContext Context;
+ };
+
+ mutable std::set<cmCMP0054Id> CMP0054ReportedIds;
+
+ /**
+ * Determine if the given context, name pair has already been reported
+ * in context of CMP0054.
+ */
+ bool HasCMP0054AlreadyBeenReported(
+ cmListFileContext context) const;
+
+ /**
+ * Add an auxiliary directory to the build.
+ */
+ void AddExtraDirectory(const char* dir);
+
+
+ /**
+ * Add an auxiliary directory to the build.
+ */
+ void MakeStartDirectoriesCurrent()
+ {
+ this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
+ this->cmStartDirectory.c_str());
+ this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
+ this->StartOutputDirectory.c_str());
+ }
+
+ //@{
+ /**
+ * Set/Get the home directory (or output directory) in the project. The
+ * home directory is the top directory of the project. It is where
+ * CMakeSetup or configure was run. Remember that CMake processes
+ * CMakeLists files by recursing up the tree starting at the StartDirectory
+ * and going up until it reaches the HomeDirectory.
+ */
+ void SetHomeDirectory(const std::string& dir);
+ const char* GetHomeDirectory() const
+ {
+ return this->cmHomeDirectory.c_str();
+ }
+ void SetHomeOutputDirectory(const std::string& lib);
+ const char* GetHomeOutputDirectory() const
+ {
+ return this->HomeOutputDirectory.c_str();
+ }
+ //@}
+
+ /**
+ * Set CMAKE_SCRIPT_MODE_FILE variable when running a -P script.
+ */
+ void SetScriptModeFile(const char* scriptfile);
+
+ /**
+ * Set CMAKE_ARGC, CMAKE_ARGV0 ... variables.
+ */
+ void SetArgcArgv(const std::vector<std::string>& args);
+
+ //@{
+ /**
+ * Set/Get the start directory (or output directory). The start directory
+ * is the directory of the CMakeLists.txt file that started the current
+ * round of processing. Remember that CMake processes CMakeLists files by
+ * recursing up the tree starting at the StartDirectory and going up until
+ * it reaches the HomeDirectory.
+ */
+ void SetStartDirectory(const std::string& dir)
+ {
+ this->cmStartDirectory = dir;
+ cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
+ this->cmStartDirectory =
+ cmSystemTools::CollapseFullPath(this->cmStartDirectory.c_str());
+ this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
+ this->cmStartDirectory.c_str());
+ }
+ const char* GetStartDirectory() const
+ {
+ return this->cmStartDirectory.c_str();
+ }
+ void SetStartOutputDirectory(const std::string& lib)
+ {
+ this->StartOutputDirectory = lib;
+ cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
+ this->StartOutputDirectory =
+ cmSystemTools::CollapseFullPath(this->StartOutputDirectory.c_str());
+ cmSystemTools::MakeDirectory(this->StartOutputDirectory.c_str());
+ this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
+ this->StartOutputDirectory.c_str());
+ }
+ const char* GetStartOutputDirectory() const
+ {
+ return this->StartOutputDirectory.c_str();
+ }
+ //@}
+
+ const char* GetCurrentDirectory() const
+ {
+ return this->cmStartDirectory.c_str();
+ }
+ const char* GetCurrentOutputDirectory() const
+ {
+ return this->StartOutputDirectory.c_str();
+ }
+
+ /* Get the current CMakeLists.txt file that is being processed. This
+ * is just used in order to be able to 'branch' from one file to a second
+ * transparently */
+ const char* GetCurrentListFile() const
+ {
+ return this->cmCurrentListFile.c_str();
+ }
+
+ //@}
+
+ /**
+ * Set a regular expression that include files must match
+ * in order to be considered as part of the depend information.
+ */
+ void SetIncludeRegularExpression(const char* regex)
+ {
+ this->IncludeFileRegularExpression = regex;
+ }
+ const char* GetIncludeRegularExpression() const
+ {
+ return this->IncludeFileRegularExpression.c_str();
+ }
+
+ /**
+ * Set a regular expression that include files that are not found
+ * must match in order to be considered a problem.
+ */
+ void SetComplainRegularExpression(const std::string& regex)
+ {
+ this->ComplainFileRegularExpression = regex;
+ }
+ const char* GetComplainRegularExpression() const
+ {
+ return this->ComplainFileRegularExpression.c_str();
+ }
+
+ /**
+ * Get the list of targets
+ */
+ cmTargets &GetTargets() { return this->Targets; }
+ /**
+ * Get the list of targets, const version
+ */
+ const cmTargets &GetTargets() const { return this->Targets; }
+ const std::vector<cmTarget*> &GetOwnedImportedTargets() const
+ {
+ return this->ImportedTargetsOwned;
+ }
+
+ const cmGeneratorTargetsType &GetGeneratorTargets() const
+ {
+ return this->GeneratorTargets;
+ }
+
+ void SetGeneratorTargets(const cmGeneratorTargetsType &targets)
+ {
+ this->GeneratorTargets = targets;
+ }
+
+ cmTarget* FindTarget(const std::string& name,
+ bool excludeAliases = false) const;
+
+ /** Find a target to use in place of the given name. The target
+ returned may be imported or built within the project. */
+ cmTarget* FindTargetToUse(const std::string& name,
+ bool excludeAliases = false) const;
+ bool IsAlias(const std::string& name) const;
+ cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
+
+ /**
+ * Mark include directories as system directories.
+ */
+ void AddSystemIncludeDirectories(const std::set<std::string> &incs);
+
+ /** Expand out any arguements in the vector that have ; separated
+ * strings into multiple arguements. A new vector is created
+ * containing the expanded versions of all arguments in argsIn.
+ * This method differes from the one in cmSystemTools in that if
+ * the CmakeLists file is version 1.2 or earlier it will check for
+ * source lists being used without ${} around them
+ */
+ void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
+ std::vector<std::string>& argsOut,
+ unsigned int startArgumentIndex) const;
+
+ /** Get a cmSourceFile pointer for a given source name, if the name is
+ * not found, then a null pointer is returned.
+ */
+ cmSourceFile* GetSource(const std::string& sourceName) const;
+
+ /** Create the source file and return it. generated
+ * indicates if it is a generated file, this is used in determining
+ * how to create the source file instance e.g. name
+ */
+ cmSourceFile* CreateSource(const std::string& sourceName,
+ bool generated = false);
+
+ /** Get a cmSourceFile pointer for a given source name, if the name is
+ * not found, then create the source file and return it. generated
+ * indicates if it is a generated file, this is used in determining
+ * how to create the source file instance e.g. name
+ */
+ cmSourceFile* GetOrCreateSource(const std::string& sourceName,
+ bool generated = false);
+
+ /**
+ * Obtain a list of auxiliary source directories.
+ */
+ const std::vector<std::string>& GetAuxSourceDirectories() const
+ {return this->AuxSourceDirectories;}
+
+ //@{
+ /**
+ * 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
+ * cache is then queried.
+ */
+ const char* GetDefinition(const std::string&) const;
+ const char* GetSafeDefinition(const std::string&) const;
+ const char* GetRequiredDefinition(const std::string& name) const;
+ bool IsDefinitionSet(const std::string&) const;
+ /**
+ * Get the list of all variables in the current space. If argument
+ * cacheonly is specified and is greater than 0, then only cache
+ * variables will be listed.
+ */
+ std::vector<std::string> GetDefinitions(int cacheonly=0) const;
+
+ /**
+ * Test a boolean variable to see if it is true or false.
+ * If the variable is not found in this makefile instance, the
+ * cache is then queried.
+ * Returns false if no entry defined.
+ */
+ bool IsOn(const std::string& name) const;
+ bool IsSet(const std::string& name) const;
+
+ /** Return whether the target platform is 64-bit. */
+ bool PlatformIs64Bit() const;
+
+ /** Retrieve soname flag for the specified language if supported */
+ const char* GetSONameFlag(const std::string& language) const;
+
+ /**
+ * Get a list of preprocessor define flags.
+ */
+ const char* GetDefineFlags() const
+ {return this->DefineFlags.c_str();}
+
+ /**
+ * Make sure CMake can write this file
+ */
+ bool CanIWriteThisFile(const char* fileName) const;
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ /**
+ * Get the vector source groups.
+ */
+ const std::vector<cmSourceGroup>& GetSourceGroups() const
+ { return this->SourceGroups; }
+
+ /**
+ * Get the source group
+ */
+ cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name) const;
+#endif
+
+ /**
+ * Get the vector of list files on which this makefile depends
+ */
+ const std::vector<std::string>& GetListFiles() const
+ { return this->ListFiles; }
+ ///! When the file changes cmake will be re-run from the build system.
+ void AddCMakeDependFile(const std::string& file)
+ { this->ListFiles.push_back(file);}
+ void AddCMakeDependFilesFromUser();
+
+ std::string GetListFileStack() const;
+
+ /**
+ * Get the current context backtrace.
+ */
+ cmListFileBacktrace GetBacktrace() const;
+
+ /**
+ * Get the vector of files created by this makefile
+ */
+ const std::vector<std::string>& GetOutputFiles() const
+ { return this->OutputFiles; }
+ void AddCMakeOutputFile(const std::string& file)
+ { this->OutputFiles.push_back(file);}
+
+ /**
+ * Expand all defined variables in the string.
+ * Defined variables come from the this->Definitions map.
+ * They are expanded with ${var} where var is the
+ * entry in the this->Definitions map. Also \@var\@ is
+ * expanded to match autoconf style expansions.
+ */
+ const char *ExpandVariablesInString(std::string& source) const;
+ const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
+ bool noEscapes,
+ bool atOnly = false,
+ const char* filename = 0,
+ long line = -1,
+ bool removeEmpty = false,
+ bool replaceAt = false) const;
+
+ /**
+ * Remove any remaining variables in the string. Anything with ${var} or
+ * \@var\@ will be removed.
+ */
+ void RemoveVariablesInString(std::string& source,
+ bool atOnly = false) const;
+
+ /**
+ * Expand variables in the makefiles ivars such as link directories etc
+ */
+ void ExpandVariablesCMP0019();
+
+ /**
+ * Replace variables and #cmakedefine lines in the given string.
+ * See cmConfigureFileCommand for details.
+ */
+ void ConfigureString(const std::string& input, std::string& output,
+ bool atOnly, bool escapeQuotes) const;
+
+ /**
+ * Copy file but change lines acording to ConfigureString
+ */
+ int ConfigureFile(const char* infile, const char* outfile,
+ bool copyonly, bool atOnly, bool escapeQuotes,
+ const cmNewLineStyle& = cmNewLineStyle());
+
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ /**
+ * find what source group this source is in
+ */
+ cmSourceGroup* FindSourceGroup(const char* source,
+ std::vector<cmSourceGroup> &groups) const;
+#endif
+
+ /**
+ * Print a command's invocation
+ */
+ void PrintCommandTrace(const cmListFileFunction& lff) const;
+
+ /**
+ * Execute a single CMake command. Returns true if the command
+ * succeeded or false if it failed.
+ */
+ bool ExecuteCommand(const cmListFileFunction& lff,
+ cmExecutionStatus &status);
+
+ /** Check if a command exists. */
+ bool CommandExists(const char* name) const;
+
+ /**
+ * Add a command to this cmake instance
+ */
+ void AddCommand(cmCommand* );
+
+ ///! Enable support for named language, if nil then all languages are
+ ///enabled.
+ void EnableLanguage(std::vector<std::string>const& languages, bool optional);
+
+ /**
+ * Set/Get the name of the parent directories CMakeLists file
+ * given a current CMakeLists file name
+ */
+ cmCacheManager *GetCacheManager() const;
+
+ /**
+ * Get the variable watch. This is used to determine when certain variables
+ * are accessed.
+ */
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmVariableWatch* GetVariableWatch() const;
+#endif
+
+ ///! Display progress or status message.
+ void DisplayStatus(const char*, float) const;
+
+ /**
+ * Expand the given list file arguments into the full set after
+ * variable replacement and list expansion.
+ */
+ bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
+ std::vector<std::string>& outArgs) const;
+
+ bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
+ std::vector<cmExpandedCommandArgument>& outArgs) const;
+
+ /**
+ * Get the instance
+ */
+ cmake *GetCMakeInstance() const;
+
+ /**
+ * Get all the source files this makefile knows about
+ */
+ const std::vector<cmSourceFile*> &GetSourceFiles() const
+ {return this->SourceFiles;}
+ std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
+
+ /**
+ * Is there a source file that has the provided source file as an output?
+ * if so then return it
+ */
+ cmSourceFile *GetSourceFileWithOutput(const std::string& outName) const;
+
+ /**
+ * Add a macro to the list of macros. The arguments should be name of the
+ * macro and a documentation signature of it
+ */
+ void AddMacro(const char* name, const char* signature);
+
+ ///! Add a new cmTest to the list of tests for this makefile.
+ cmTest* CreateTest(const std::string& testName);
+
+ /** Get a cmTest pointer for a given test name, if the name is
+ * not found, then a null pointer is returned.
+ */
+ cmTest* GetTest(const std::string& testName) const;
+
+ /**
+ * Get a list of macros as a ; separated string
+ */
+ void GetListOfMacros(std::string& macros) const;
+
+ /**
+ * Return a location of a file in cmake or custom modules directory
+ */
+ std::string GetModulesFile(const char* name) const;
+
+ ///! Set/Get a property of this directory
+ void SetProperty(const std::string& prop, const char *value);
+ void AppendProperty(const std::string& prop, const char *value,
+ bool asString=false);
+ const char *GetProperty(const std::string& prop) const;
+ const char *GetProperty(const std::string& prop,
+ cmProperty::ScopeType scope) const;
+ bool GetPropertyAsBool(const std::string& prop) const;
+
+ const char* GetFeature(const std::string& feature,
+ const std::string& config);
+
+ // Get the properties
+ cmPropertyMap &GetProperties() { return this->Properties; }
+
+ ///! Initialize a makefile from its parent
+ void InitializeFromParent();
+
+ ///! Set/Get the preorder flag
+ void SetPreOrder(bool p) { this->PreOrder = p; }
+ bool GetPreOrder() const { return this->PreOrder; }
+
+ void AddInstallGenerator(cmInstallGenerator* g)
+ { if(g) this->InstallGenerators.push_back(g); }
+ std::vector<cmInstallGenerator*>& GetInstallGenerators()
+ { return this->InstallGenerators; }
+
+ void AddTestGenerator(cmTestGenerator* g)
+ { if(g) this->TestGenerators.push_back(g); }
+ const std::vector<cmTestGenerator*>& GetTestGenerators() const
+ { return this->TestGenerators; }
+
+ // Define the properties
+ static void DefineProperties(cmake *cm);
+
+ // push and pop variable scopes
+ void PushScope();
+ void PopScope();
+ void RaiseScope(const std::string& var, const char *value);
+
+ /** Helper class to push and pop scopes automatically. */
+ class ScopePushPop
+ {
+ public:
+ ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
+ ~ScopePushPop() { this->Makefile->PopScope(); }
+ private:
+ cmMakefile* Makefile;
+ };
+
+ void IssueMessage(cmake::MessageType t,
+ std::string const& text) const;
+
+ /** Set whether or not to report a CMP0000 violation. */
+ void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
+
+ const std::vector<cmValueWithOrigin>& GetIncludeDirectoriesEntries() const
+ {
+ return this->IncludeDirectoriesEntries;
+ }
+ const std::vector<cmValueWithOrigin>& GetCompileOptionsEntries() const
+ {
+ return this->CompileOptionsEntries;
+ }
+ const std::vector<cmValueWithOrigin>& GetCompileDefinitionsEntries() const
+ {
+ return this->CompileDefinitionsEntries;
+ }
+
+ bool IsGeneratingBuildSystem() const { return this->GeneratingBuildSystem; }
+ void SetGeneratingBuildSystem(){ this->GeneratingBuildSystem = true; }
+
+ void AddQtUiFileWithOptions(cmSourceFile *sf);
+ std::vector<cmSourceFile*> GetQtUiFilesWithOptions() const;
+
+ std::set<std::string> const & GetSystemIncludeDirectories() const
+ { return this->SystemIncludeDirectories; }
+
+ bool PolicyOptionalWarningEnabled(std::string const& var);
+
+ bool AddRequiredTargetFeature(cmTarget *target,
+ const std::string& feature,
+ std::string *error = 0) const;
+
+ bool CompileFeatureKnown(cmTarget const* target, const std::string& feature,
+ std::string& lang, std::string *error) const;
+
+ const char* CompileFeaturesAvailable(const std::string& lang,
+ std::string *error) const;
+
+ bool HaveFeatureAvailable(cmTarget const* target, std::string const& lang,
+ const std::string& feature) const;
+
+ bool IsLaterStandard(std::string const& lang,
+ std::string const& lhs,
+ std::string const& rhs);
+
+ void ClearMatches();
+ void StoreMatches(cmsys::RegularExpression& re);
+
+protected:
+ // add link libraries and directories to the target
+ void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
+
+ // Check for a an unused variable
+ void CheckForUnused(const char* reason, const std::string& name) const;
+
+ std::string Prefix;
+ std::vector<std::string> AuxSourceDirectories; //
+
+ std::string cmStartDirectory;
+ std::string StartOutputDirectory;
+ std::string cmHomeDirectory;
+ std::string HomeOutputDirectory;
+ std::string cmCurrentListFile;
+
+ std::string ProjectName; // project name
+
+ // libraries, classes, and executables
+ mutable cmTargets Targets;
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
+#else
+ typedef std::map<std::string, cmTarget*> TargetMap;
+#endif
+ TargetMap AliasTargets;
+ cmGeneratorTargetsType GeneratorTargets;
+ std::vector<cmSourceFile*> SourceFiles;
+
+ // Tests
+ std::map<std::string, cmTest*> Tests;
+
+ // The link-library paths. Order matters, use std::vector (not std::set).
+ std::vector<std::string> LinkDirectories;
+
+ // The set of include directories that are marked as system include
+ // directories.
+ std::set<std::string> SystemIncludeDirectories;
+
+ std::vector<std::string> ListFiles; // list of command files loaded
+ std::vector<std::string> OutputFiles; // list of command files loaded
+
+
+ cmTarget::LinkLibraryVectorType LinkLibraries;
+
+ std::vector<cmInstallGenerator*> InstallGenerators;
+ std::vector<cmTestGenerator*> TestGenerators;
+
+ std::string IncludeFileRegularExpression;
+ std::string ComplainFileRegularExpression;
+ std::vector<std::string> SourceFileExtensions;
+ std::vector<std::string> HeaderFileExtensions;
+ std::string DefineFlags;
+
+ std::vector<cmValueWithOrigin> IncludeDirectoriesEntries;
+ std::vector<cmValueWithOrigin> CompileOptionsEntries;
+ std::vector<cmValueWithOrigin> CompileDefinitionsEntries;
+
+ // Track the value of the computed DEFINITIONS property.
+ void AddDefineFlag(const char*, std::string&);
+ void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
+ std::string DefineFlagsOrig;
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ std::vector<cmSourceGroup> SourceGroups;
+#endif
+
+ std::vector<cmCommand*> FinalPassCommands;
+ cmLocalGenerator* LocalGenerator;
+ bool IsFunctionBlocked(const cmListFileFunction& lff,
+ cmExecutionStatus &status);
+
+private:
+ void Initialize();
+
+ bool ParseDefineFlag(std::string const& definition, bool remove);
+
+ bool EnforceUniqueDir(const std::string& srcPath,
+ const std::string& binPath) const;
+
+ friend class cmMakeDepend; // make depend needs direct access
+ // to the Sources array
+ void PrintStringVector(const char* s, const
+ std::vector<std::pair<std::string, bool> >& v) const;
+ void PrintStringVector(const char* s,
+ const std::vector<std::string>& v) const;
+
+ void AddDefaultDefinitions();
+ typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
+ FunctionBlockersType FunctionBlockers;
+ std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
+ void PushFunctionBlockerBarrier();
+ void PopFunctionBlockerBarrier(bool reportError = true);
+
+ typedef std::map<std::string, std::string> StringStringMap;
+ StringStringMap MacrosMap;
+
+ std::map<std::string, bool> SubDirectoryOrder;
+
+ mutable cmsys::RegularExpression cmDefineRegex;
+ mutable cmsys::RegularExpression cmDefine01Regex;
+ mutable cmsys::RegularExpression cmAtVarRegex;
+ mutable cmsys::RegularExpression cmNamedCurly;
+
+ cmPropertyMap Properties;
+
+ // should this makefile be processed before or after processing the parent
+ bool PreOrder;
+
+ // Unused variable flags
+ bool WarnUnused;
+ bool CheckSystemVars;
+
+ // stack of list files being read
+ std::deque<std::string> ListFileStack;
+
+ // stack of commands being invoked.
+ struct CallStackEntry
+ {
+ cmListFileContext const* Context;
+ cmExecutionStatus* Status;
+ };
+ typedef std::deque<CallStackEntry> CallStackType;
+ CallStackType CallStack;
+ friend class cmMakefileCall;
+
+ std::vector<cmTarget*> ImportedTargetsOwned;
+ TargetMap ImportedTargets;
+
+ // Internal policy stack management.
+ void PushPolicy(bool weak = false,
+ cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
+ void PopPolicy();
+ void PushPolicyBarrier();
+ void PopPolicyBarrier(bool reportError = true);
+ friend class cmCMakePolicyCommand;
+ class IncludeScope;
+ friend class IncludeScope;
+
+ // stack of policy settings
+ struct PolicyStackEntry: public cmPolicies::PolicyMap
+ {
+ typedef cmPolicies::PolicyMap derived;
+ PolicyStackEntry(bool w = false): derived(), Weak(w) {}
+ PolicyStackEntry(derived const& d, bool w = false): derived(d), Weak(w) {}
+ PolicyStackEntry(PolicyStackEntry const& r): derived(r), Weak(r.Weak) {}
+ bool Weak;
+ };
+ typedef std::vector<PolicyStackEntry> PolicyStackType;
+ PolicyStackType PolicyStack;
+ std::vector<PolicyStackType::size_type> PolicyBarriers;
+ cmPolicies::PolicyStatus
+ GetPolicyStatusInternal(cmPolicies::PolicyID id) const;
+
+ bool CheckCMP0000;
+
+ // Enforce rules about CMakeLists.txt files.
+ void EnforceDirectoryLevelRules() const;
+
+ // CMP0053 == old
+ cmake::MessageType ExpandVariablesInStringOld(
+ std::string& errorstr,
+ std::string& source,
+ bool escapeQuotes,
+ bool noEscapes,
+ bool atOnly,
+ const char* filename,
+ long line,
+ bool removeEmpty,
+ bool replaceAt) const;
+ // CMP0053 == new
+ cmake::MessageType ExpandVariablesInStringNew(
+ std::string& errorstr,
+ std::string& source,
+ bool escapeQuotes,
+ bool noEscapes,
+ bool atOnly,
+ const char* filename,
+ long line,
+ bool removeEmpty,
+ bool replaceAt) const;
+ bool GeneratingBuildSystem;
+ /**
+ * Old version of GetSourceFileWithOutput(const std::string&) kept for
+ * backward-compatibility. It implements a linear search and support
+ * relative file paths. It is used as a fall back by
+ * GetSourceFileWithOutput(const std::string&).
+ */
+ cmSourceFile *LinearGetSourceFileWithOutput(const std::string& cname) const;
+
+ // A map for fast output to input look up.
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
+#else
+ typedef std::map<std::string, cmSourceFile*> OutputToSourceMap;
+#endif
+ OutputToSourceMap OutputToSource;
+
+ void UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
+ cmSourceFile* source);
+ void UpdateOutputToSourceMap(std::string const& output,
+ cmSourceFile* source);
+
+ std::vector<cmSourceFile*> QtUiFilesWithOptions;
+
+ unsigned int NumLastMatches;
+
+ bool AddRequiredTargetCFeature(cmTarget *target,
+ const std::string& feature) const;
+
+ bool AddRequiredTargetCxxFeature(cmTarget *target,
+ const std::string& feature) const;
+
+ void CheckNeededCLanguage(const std::string& feature, bool& needC90,
+ bool& needC99, bool& needC11) const;
+ void CheckNeededCxxLanguage(const std::string& feature, bool& needCxx98,
+ bool& needCxx11, bool& needCxx14) const;
+
+ bool HaveCFeatureAvailable(cmTarget const* target,
+ const std::string& feature) const;
+ bool HaveCxxFeatureAvailable(cmTarget const* target,
+ const std::string& feature) const;
+
+ mutable bool SuppressWatches;
+};
+
+//----------------------------------------------------------------------------
+// Helper class to make sure the call stack is valid.
+class cmMakefileCall
+{
+public:
+ cmMakefileCall(cmMakefile* mf,
+ cmListFileContext const& lfc,
+ cmExecutionStatus& status): Makefile(mf)
+ {
+ cmMakefile::CallStackEntry entry = {&lfc, &status};
+ this->Makefile->CallStack.push_back(entry);
+ }
+ ~cmMakefileCall()
+ {
+ this->Makefile->CallStack.pop_back();
+ }
+private:
+ cmMakefile* Makefile;
+};
+
+#endif
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
new file mode 100644
index 0000000000..fc52cccf3b
--- /dev/null
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -0,0 +1,472 @@
+/*============================================================================
+ 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 "cmMakefileExecutableTargetGenerator.h"
+
+#include "cmGeneratedFileStream.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmTarget.h"
+#include "cmake.h"
+
+//----------------------------------------------------------------------------
+cmMakefileExecutableTargetGenerator
+::cmMakefileExecutableTargetGenerator(cmGeneratorTarget* target):
+ cmMakefileTargetGenerator(target->Target)
+{
+ this->CustomCommandDriver = OnDepends;
+ this->Target->GetExecutableNames(
+ this->TargetNameOut, this->TargetNameReal, this->TargetNameImport,
+ this->TargetNamePDB, this->ConfigName);
+
+ this->OSXBundleGenerator = new cmOSXBundleGenerator(target,
+ this->ConfigName);
+ this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
+}
+
+//----------------------------------------------------------------------------
+cmMakefileExecutableTargetGenerator
+::~cmMakefileExecutableTargetGenerator()
+{
+ delete this->OSXBundleGenerator;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileExecutableTargetGenerator::WriteRuleFiles()
+{
+ // create the build.make file and directory, put in the common blocks
+ this->CreateRuleFile();
+
+ // write rules used to help build object files
+ this->WriteCommonCodeRules();
+
+ // write the per-target per-language flags
+ this->WriteTargetLanguageFlags();
+
+ // write in rules for object files and custom commands
+ this->WriteTargetBuildRules();
+
+ // write the link rules
+ this->WriteExecutableRule(false);
+ if(this->Target->NeedRelinkBeforeInstall(this->ConfigName))
+ {
+ // Write rules to link an installable version of the target.
+ this->WriteExecutableRule(true);
+ }
+
+ // Write the requires target.
+ this->WriteTargetRequiresRules();
+
+ // Write clean target
+ this->WriteTargetCleanRules();
+
+ // Write the dependency generation rule. This must be done last so
+ // that multiple output pair information is available.
+ this->WriteTargetDependRules();
+
+ // close the streams
+ this->CloseFileStreams();
+}
+
+
+
+//----------------------------------------------------------------------------
+void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
+{
+ std::vector<std::string> commands;
+
+ // Build list of dependencies.
+ std::vector<std::string> depends;
+ this->AppendLinkDepends(depends);
+
+ // Get the name of the executable to generate.
+ std::string targetName;
+ std::string targetNameReal;
+ std::string targetNameImport;
+ std::string targetNamePDB;
+ this->Target->GetExecutableNames
+ (targetName, targetNameReal, targetNameImport, targetNamePDB,
+ this->ConfigName);
+
+ // Construct the full path version of the names.
+ std::string outpath = this->Target->GetDirectory(this->ConfigName);
+ if(this->Target->IsAppBundleOnApple())
+ {
+ this->OSXBundleGenerator->CreateAppBundle(targetName, outpath);
+ }
+ outpath += "/";
+ std::string outpathImp;
+ if(relink)
+ {
+ outpath = this->Makefile->GetStartOutputDirectory();
+ outpath += cmake::GetCMakeFilesDirectory();
+ outpath += "/CMakeRelink.dir";
+ cmSystemTools::MakeDirectory(outpath.c_str());
+ outpath += "/";
+ if(!targetNameImport.empty())
+ {
+ outpathImp = outpath;
+ }
+ }
+ else
+ {
+ cmSystemTools::MakeDirectory(outpath.c_str());
+ if(!targetNameImport.empty())
+ {
+ outpathImp = this->Target->GetDirectory(this->ConfigName, true);
+ cmSystemTools::MakeDirectory(outpathImp.c_str());
+ outpathImp += "/";
+ }
+ }
+
+ std::string compilePdbOutputPath =
+ this->Target->GetCompilePDBDirectory(this->ConfigName);
+ cmSystemTools::MakeDirectory(compilePdbOutputPath.c_str());
+
+ std::string pdbOutputPath = this->Target->GetPDBDirectory(this->ConfigName);
+ cmSystemTools::MakeDirectory(pdbOutputPath.c_str());
+ pdbOutputPath += "/";
+
+ std::string targetFullPath = outpath + targetName;
+ std::string targetFullPathReal = outpath + targetNameReal;
+ std::string targetFullPathPDB = pdbOutputPath + targetNamePDB;
+ std::string targetFullPathImport = outpathImp + targetNameImport;
+ std::string targetOutPathPDB =
+ this->Convert(targetFullPathPDB,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ // Convert to the output path to use in constructing commands.
+ std::string targetOutPath =
+ this->Convert(targetFullPath,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ std::string targetOutPathReal =
+ this->Convert(targetFullPathReal,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ std::string targetOutPathImport =
+ this->Convert(targetFullPathImport,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+
+ // Get the language to use for linking this executable.
+ std::string linkLanguage =
+ this->Target->GetLinkerLanguage(this->ConfigName);
+
+ // Make sure we have a link language.
+ if(linkLanguage.empty())
+ {
+ cmSystemTools::Error("Cannot determine link language for target \"",
+ this->Target->GetName().c_str(), "\".");
+ return;
+ }
+
+ if(!this->NoRuleMessages)
+ {
+ // Add the link message.
+ std::string buildEcho = "Linking ";
+ buildEcho += linkLanguage;
+ buildEcho += " executable ";
+ buildEcho += targetOutPath;
+ this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(),
+ cmLocalUnixMakefileGenerator3::EchoLink);
+ }
+
+ // Build a list of compiler flags and linker flags.
+ std::string flags;
+ std::string linkFlags;
+
+ // Add flags to create an executable.
+ this->LocalGenerator->
+ AddConfigVariableFlags(linkFlags, "CMAKE_EXE_LINKER_FLAGS",
+ this->ConfigName);
+
+
+ if(this->Target->GetPropertyAsBool("WIN32_EXECUTABLE"))
+ {
+ this->LocalGenerator->AppendFlags
+ (linkFlags, this->Makefile->GetDefinition("CMAKE_CREATE_WIN32_EXE"));
+ }
+ else
+ {
+ this->LocalGenerator->AppendFlags
+ (linkFlags, this->Makefile->GetDefinition("CMAKE_CREATE_CONSOLE_EXE"));
+ }
+
+ // Add symbol export flags if necessary.
+ if(this->Target->IsExecutableWithExports())
+ {
+ std::string export_flag_var = "CMAKE_EXE_EXPORTS_";
+ export_flag_var += linkLanguage;
+ export_flag_var += "_FLAG";
+ this->LocalGenerator->AppendFlags
+ (linkFlags, this->Makefile->GetDefinition(export_flag_var));
+ }
+
+ // Add language feature flags.
+ this->AddFeatureFlags(flags, linkLanguage);
+
+ this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
+ linkLanguage, this->ConfigName);
+
+ // Add target-specific linker flags.
+ this->LocalGenerator->AppendFlags
+ (linkFlags, this->Target->GetProperty("LINK_FLAGS"));
+ std::string linkFlagsConfig = "LINK_FLAGS_";
+ linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
+ this->LocalGenerator->AppendFlags
+ (linkFlags, this->Target->GetProperty(linkFlagsConfig));
+
+ this->AddModuleDefinitionFlag(linkFlags);
+
+ // Construct a list of files associated with this executable that
+ // may need to be cleaned.
+ std::vector<std::string> exeCleanFiles;
+ exeCleanFiles.push_back(this->Convert(targetFullPath,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+#ifdef _WIN32
+ // There may be a manifest file for this target. Add it to the
+ // clean set just in case.
+ exeCleanFiles.push_back(this->Convert((targetFullPath+".manifest").c_str(),
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+#endif
+ if(targetNameReal != targetName)
+ {
+ exeCleanFiles.push_back(this->Convert(targetFullPathReal,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ }
+ if(!targetNameImport.empty())
+ {
+ exeCleanFiles.push_back(this->Convert(targetFullPathImport,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ std::string implib;
+ if(this->Target->GetImplibGNUtoMS(targetFullPathImport, implib))
+ {
+ exeCleanFiles.push_back(this->Convert(implib,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ }
+ }
+
+ // List the PDB for cleaning only when the whole target is
+ // cleaned. We do not want to delete the .pdb file just before
+ // linking the target.
+ this->CleanFiles.push_back
+ (this->Convert(targetFullPathPDB,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+
+ // Add the pre-build and pre-link rules building but not when relinking.
+ if(!relink)
+ {
+ this->LocalGenerator
+ ->AppendCustomCommands(commands, this->Target->GetPreBuildCommands(),
+ this->Target);
+ this->LocalGenerator
+ ->AppendCustomCommands(commands, this->Target->GetPreLinkCommands(),
+ this->Target);
+ }
+
+ // Determine whether a link script will be used.
+ bool useLinkScript = this->GlobalGenerator->GetUseLinkScript();
+
+ // Construct the main link rule.
+ std::vector<std::string> real_link_commands;
+ std::string linkRuleVar = "CMAKE_";
+ linkRuleVar += linkLanguage;
+ linkRuleVar += "_LINK_EXECUTABLE";
+ std::string linkRule = this->GetLinkRule(linkRuleVar);
+ std::vector<std::string> commands1;
+ cmSystemTools::ExpandListArgument(linkRule, real_link_commands);
+ if(this->Target->IsExecutableWithExports())
+ {
+ // If a separate rule for creating an import library is specified
+ // add it now.
+ std::string implibRuleVar = "CMAKE_";
+ implibRuleVar += linkLanguage;
+ implibRuleVar += "_CREATE_IMPORT_LIBRARY";
+ if(const char* rule =
+ this->Makefile->GetDefinition(implibRuleVar))
+ {
+ cmSystemTools::ExpandListArgument(rule, real_link_commands);
+ }
+ }
+
+ // Select whether to use a response file for objects.
+ bool useResponseFileForObjects = false;
+ {
+ std::string responseVar = "CMAKE_";
+ responseVar += linkLanguage;
+ responseVar += "_USE_RESPONSE_FILE_FOR_OBJECTS";
+ if(this->Makefile->IsOn(responseVar))
+ {
+ useResponseFileForObjects = true;
+ }
+ }
+
+ // Select whether to use a response file for libraries.
+ bool useResponseFileForLibs = false;
+ {
+ std::string responseVar = "CMAKE_";
+ responseVar += linkLanguage;
+ responseVar += "_USE_RESPONSE_FILE_FOR_LIBRARIES";
+ if(this->Makefile->IsOn(responseVar))
+ {
+ useResponseFileForLibs = true;
+ }
+ }
+
+ // Expand the rule variables.
+ {
+ bool useWatcomQuote = this->Makefile->IsOn(linkRuleVar+"_USE_WATCOM_QUOTE");
+
+ // Set path conversion for link script shells.
+ this->LocalGenerator->SetLinkScriptShell(useLinkScript);
+
+ // Collect up flags to link in needed libraries.
+ std::string linkLibs;
+ this->CreateLinkLibs(linkLibs, relink, useResponseFileForLibs, depends,
+ useWatcomQuote);
+
+ // Construct object file lists that may be needed to expand the
+ // rule.
+ std::string buildObjs;
+ this->CreateObjectLists(useLinkScript, false,
+ useResponseFileForObjects, buildObjs, depends,
+ useWatcomQuote);
+
+ cmLocalGenerator::RuleVariables vars;
+ vars.RuleLauncher = "RULE_LAUNCH_LINK";
+ vars.CMTarget = this->Target;
+ vars.Language = linkLanguage.c_str();
+ vars.Objects = buildObjs.c_str();
+ std::string objectDir = this->Target->GetSupportDirectory();
+ objectDir = this->Convert(objectDir,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ vars.ObjectDir = objectDir.c_str();
+ cmLocalGenerator::OutputFormat output = (useWatcomQuote) ?
+ cmLocalGenerator::WATCOMQUOTE : cmLocalGenerator::SHELL;
+ std::string target = this->Convert(targetFullPathReal,
+ cmLocalGenerator::START_OUTPUT,
+ output);
+ vars.Target = target.c_str();
+ vars.TargetPDB = targetOutPathPDB.c_str();
+
+ // Setup the target version.
+ std::string targetVersionMajor;
+ std::string targetVersionMinor;
+ {
+ cmOStringStream majorStream;
+ cmOStringStream minorStream;
+ int major;
+ int minor;
+ this->Target->GetTargetVersion(major, minor);
+ majorStream << major;
+ minorStream << minor;
+ targetVersionMajor = majorStream.str();
+ targetVersionMinor = minorStream.str();
+ }
+ vars.TargetVersionMajor = targetVersionMajor.c_str();
+ vars.TargetVersionMinor = targetVersionMinor.c_str();
+
+ vars.LinkLibraries = linkLibs.c_str();
+ vars.Flags = flags.c_str();
+ vars.LinkFlags = linkFlags.c_str();
+ // Expand placeholders in the commands.
+ this->LocalGenerator->TargetImplib = targetOutPathImport;
+ for(std::vector<std::string>::iterator i = real_link_commands.begin();
+ i != real_link_commands.end(); ++i)
+ {
+ this->LocalGenerator->ExpandRuleVariables(*i, vars);
+ }
+ this->LocalGenerator->TargetImplib = "";
+
+ // Restore path conversion to normal shells.
+ this->LocalGenerator->SetLinkScriptShell(false);
+ }
+
+ // Optionally convert the build rule to use a script to avoid long
+ // command lines in the make shell.
+ if(useLinkScript)
+ {
+ // Use a link script.
+ const char* name = (relink? "relink.txt" : "link.txt");
+ this->CreateLinkScript(name, real_link_commands, commands1, depends);
+ }
+ else
+ {
+ // No link script. Just use the link rule directly.
+ commands1 = real_link_commands;
+ }
+ this->LocalGenerator->CreateCDCommand
+ (commands1,
+ this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+ commands.insert(commands.end(), commands1.begin(), commands1.end());
+ commands1.clear();
+
+ // Add a rule to create necessary symlinks for the library.
+ if(targetOutPath != targetOutPathReal)
+ {
+ std::string symlink = "$(CMAKE_COMMAND) -E cmake_symlink_executable ";
+ symlink += targetOutPathReal;
+ symlink += " ";
+ symlink += targetOutPath;
+ commands1.push_back(symlink);
+ this->LocalGenerator->CreateCDCommand(commands1,
+ this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+ commands.insert(commands.end(), commands1.begin(), commands1.end());
+ commands1.clear();
+ }
+
+ // Add the post-build rules when building but not when relinking.
+ if(!relink)
+ {
+ this->LocalGenerator->
+ AppendCustomCommands(commands, this->Target->GetPostBuildCommands(),
+ this->Target);
+ }
+
+ // Write the build rule.
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream,
+ 0,
+ targetFullPathReal,
+ depends, commands, false);
+
+ // The symlink name for the target should depend on the real target
+ // so if the target version changes it rebuilds and recreates the
+ // symlink.
+ if(targetFullPath != targetFullPathReal)
+ {
+ depends.clear();
+ commands.clear();
+ depends.push_back(targetFullPathReal);
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ targetFullPath,
+ depends, commands, false);
+ }
+
+ // Write the main driver rule to build everything in this target.
+ this->WriteTargetDriverRule(targetFullPath, relink);
+
+ // Clean all the possible executable names and symlinks.
+ this->CleanFiles.insert(this->CleanFiles.end(),
+ exeCleanFiles.begin(),
+ exeCleanFiles.end());
+}
diff --git a/Source/cmMakefileExecutableTargetGenerator.h b/Source/cmMakefileExecutableTargetGenerator.h
new file mode 100644
index 0000000000..940226b1a1
--- /dev/null
+++ b/Source/cmMakefileExecutableTargetGenerator.h
@@ -0,0 +1,31 @@
+/*============================================================================
+ 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 cmMakefileExecutableTargetGenerator_h
+#define cmMakefileExecutableTargetGenerator_h
+
+#include "cmMakefileTargetGenerator.h"
+
+class cmMakefileExecutableTargetGenerator: public cmMakefileTargetGenerator
+{
+public:
+ cmMakefileExecutableTargetGenerator(cmGeneratorTarget* target);
+ virtual ~cmMakefileExecutableTargetGenerator();
+
+ /* the main entry point for this class. Writes the Makefiles associated
+ with this target */
+ virtual void WriteRuleFiles();
+
+protected:
+ virtual void WriteExecutableRule(bool relink);
+};
+
+#endif
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
new file mode 100644
index 0000000000..80473f6131
--- /dev/null
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -0,0 +1,815 @@
+/*============================================================================
+ 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 "cmMakefileLibraryTargetGenerator.h"
+
+#include "cmGeneratedFileStream.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmTarget.h"
+#include "cmake.h"
+
+//----------------------------------------------------------------------------
+cmMakefileLibraryTargetGenerator
+::cmMakefileLibraryTargetGenerator(cmGeneratorTarget* target):
+ cmMakefileTargetGenerator(target->Target)
+{
+ this->CustomCommandDriver = OnDepends;
+ if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ this->Target->GetLibraryNames(
+ this->TargetNameOut, this->TargetNameSO, this->TargetNameReal,
+ this->TargetNameImport, this->TargetNamePDB, this->ConfigName);
+ }
+
+ this->OSXBundleGenerator = new cmOSXBundleGenerator(target,
+ this->ConfigName);
+ this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
+}
+
+//----------------------------------------------------------------------------
+cmMakefileLibraryTargetGenerator
+::~cmMakefileLibraryTargetGenerator()
+{
+ delete this->OSXBundleGenerator;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
+{
+ // create the build.make file and directory, put in the common blocks
+ this->CreateRuleFile();
+
+ // write rules used to help build object files
+ this->WriteCommonCodeRules();
+
+ // write the per-target per-language flags
+ this->WriteTargetLanguageFlags();
+
+ // write in rules for object files and custom commands
+ this->WriteTargetBuildRules();
+
+ // write the link rules
+ // Write the rule for this target type.
+ switch(this->Target->GetType())
+ {
+ case cmTarget::STATIC_LIBRARY:
+ this->WriteStaticLibraryRules();
+ break;
+ case cmTarget::SHARED_LIBRARY:
+ this->WriteSharedLibraryRules(false);
+ if(this->Target->NeedRelinkBeforeInstall(this->ConfigName))
+ {
+ // Write rules to link an installable version of the target.
+ this->WriteSharedLibraryRules(true);
+ }
+ break;
+ case cmTarget::MODULE_LIBRARY:
+ this->WriteModuleLibraryRules(false);
+ if(this->Target->NeedRelinkBeforeInstall(this->ConfigName))
+ {
+ // Write rules to link an installable version of the target.
+ this->WriteModuleLibraryRules(true);
+ }
+ break;
+ case cmTarget::OBJECT_LIBRARY:
+ this->WriteObjectLibraryRules();
+ break;
+ default:
+ // If language is not known, this is an error.
+ cmSystemTools::Error("Unknown Library Type");
+ break;
+ }
+
+ // Write the requires target.
+ this->WriteTargetRequiresRules();
+
+ // Write clean target
+ this->WriteTargetCleanRules();
+
+ // Write the dependency generation rule. This must be done last so
+ // that multiple output pair information is available.
+ this->WriteTargetDependRules();
+
+ // close the streams
+ this->CloseFileStreams();
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
+{
+ std::vector<std::string> commands;
+ std::vector<std::string> depends;
+
+ // Add post-build rules.
+ this->LocalGenerator->
+ AppendCustomCommands(commands, this->Target->GetPostBuildCommands(),
+ this->Target);
+
+ // Depend on the object files.
+ this->AppendObjectDepends(depends);
+
+ // Write the rule.
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ this->Target->GetName(),
+ depends, commands, true);
+
+ // Write the main driver rule to build everything in this target.
+ this->WriteTargetDriverRule(this->Target->GetName(), false);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
+{
+ std::string linkLanguage =
+ this->Target->GetLinkerLanguage(this->ConfigName);
+ std::string linkRuleVar = "CMAKE_";
+ linkRuleVar += linkLanguage;
+ linkRuleVar += "_CREATE_STATIC_LIBRARY";
+
+ if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION") &&
+ this->Makefile->GetDefinition(linkRuleVar+"_IPO"))
+ {
+ linkRuleVar += "_IPO";
+ }
+
+ std::string extraFlags;
+ this->LocalGenerator->GetStaticLibraryFlags(extraFlags,
+ cmSystemTools::UpperCase(this->ConfigName), this->Target);
+ this->WriteLibraryRules(linkRuleVar, extraFlags, false);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
+{
+ if(this->Target->IsFrameworkOnApple())
+ {
+ this->WriteFrameworkRules(relink);
+ return;
+ }
+ std::string linkLanguage =
+ this->Target->GetLinkerLanguage(this->ConfigName);
+ std::string linkRuleVar = "CMAKE_";
+ linkRuleVar += linkLanguage;
+ linkRuleVar += "_CREATE_SHARED_LIBRARY";
+
+ std::string extraFlags;
+ this->LocalGenerator->AppendFlags
+ (extraFlags, this->Target->GetProperty("LINK_FLAGS"));
+ std::string linkFlagsConfig = "LINK_FLAGS_";
+ linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
+ this->LocalGenerator->AppendFlags
+ (extraFlags, this->Target->GetProperty(linkFlagsConfig));
+
+ this->LocalGenerator->AddConfigVariableFlags
+ (extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->ConfigName);
+ this->AddModuleDefinitionFlag(extraFlags);
+
+ this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
+{
+ std::string linkLanguage =
+ this->Target->GetLinkerLanguage(this->ConfigName);
+ std::string linkRuleVar = "CMAKE_";
+ linkRuleVar += linkLanguage;
+ linkRuleVar += "_CREATE_SHARED_MODULE";
+
+ std::string extraFlags;
+ this->LocalGenerator->AppendFlags(extraFlags,
+ this->Target->GetProperty("LINK_FLAGS"));
+ std::string linkFlagsConfig = "LINK_FLAGS_";
+ linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
+ this->LocalGenerator->AppendFlags
+ (extraFlags, this->Target->GetProperty(linkFlagsConfig));
+ this->LocalGenerator->AddConfigVariableFlags
+ (extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->ConfigName);
+ this->AddModuleDefinitionFlag(extraFlags);
+
+ this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
+{
+ std::string linkLanguage =
+ this->Target->GetLinkerLanguage(this->ConfigName);
+ std::string linkRuleVar = "CMAKE_";
+ linkRuleVar += linkLanguage;
+ linkRuleVar += "_CREATE_MACOSX_FRAMEWORK";
+
+ std::string extraFlags;
+ this->LocalGenerator->AppendFlags(extraFlags,
+ this->Target->GetProperty("LINK_FLAGS"));
+ std::string linkFlagsConfig = "LINK_FLAGS_";
+ linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
+ this->LocalGenerator->AppendFlags
+ (extraFlags, this->Target->GetProperty(linkFlagsConfig));
+ this->LocalGenerator->AddConfigVariableFlags
+ (extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS", this->ConfigName);
+
+ this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileLibraryTargetGenerator::WriteLibraryRules
+(const std::string& linkRuleVar, const std::string& extraFlags, bool relink)
+{
+ // TODO: Merge the methods that call this method to avoid
+ // code duplication.
+ std::vector<std::string> commands;
+
+ // Build list of dependencies.
+ std::vector<std::string> depends;
+ this->AppendLinkDepends(depends);
+
+ // Get the language to use for linking this library.
+ std::string linkLanguage =
+ this->Target->GetLinkerLanguage(this->ConfigName);
+
+ // Make sure we have a link language.
+ if(linkLanguage.empty())
+ {
+ cmSystemTools::Error("Cannot determine link language for target \"",
+ this->Target->GetName().c_str(), "\".");
+ return;
+ }
+
+ // Create set of linking flags.
+ std::string linkFlags;
+ this->LocalGenerator->AppendFlags(linkFlags, extraFlags);
+
+ // Add OSX version flags, if any.
+ if(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
+ this->Target->GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ this->AppendOSXVerFlag(linkFlags, linkLanguage, "COMPATIBILITY", true);
+ this->AppendOSXVerFlag(linkFlags, linkLanguage, "CURRENT", false);
+ }
+
+ // Construct the name of the library.
+ std::string targetName;
+ std::string targetNameSO;
+ std::string targetNameReal;
+ std::string targetNameImport;
+ std::string targetNamePDB;
+ this->Target->GetLibraryNames(
+ targetName, targetNameSO, targetNameReal, targetNameImport, targetNamePDB,
+ this->ConfigName);
+
+ // Construct the full path version of the names.
+ std::string outpath;
+ std::string outpathImp;
+ if(this->Target->IsFrameworkOnApple())
+ {
+ outpath = this->Target->GetDirectory(this->ConfigName);
+ this->OSXBundleGenerator->CreateFramework(targetName, outpath);
+ outpath += "/";
+ }
+ else if(this->Target->IsCFBundleOnApple())
+ {
+ outpath = this->Target->GetDirectory(this->ConfigName);
+ this->OSXBundleGenerator->CreateCFBundle(targetName, outpath);
+ outpath += "/";
+ }
+ else if(relink)
+ {
+ outpath = this->Makefile->GetStartOutputDirectory();
+ outpath += cmake::GetCMakeFilesDirectory();
+ outpath += "/CMakeRelink.dir";
+ cmSystemTools::MakeDirectory(outpath.c_str());
+ outpath += "/";
+ if(!targetNameImport.empty())
+ {
+ outpathImp = outpath;
+ }
+ }
+ else
+ {
+ outpath = this->Target->GetDirectory(this->ConfigName);
+ cmSystemTools::MakeDirectory(outpath.c_str());
+ outpath += "/";
+ if(!targetNameImport.empty())
+ {
+ outpathImp = this->Target->GetDirectory(this->ConfigName, true);
+ cmSystemTools::MakeDirectory(outpathImp.c_str());
+ outpathImp += "/";
+ }
+ }
+
+ std::string compilePdbOutputPath =
+ this->Target->GetCompilePDBDirectory(this->ConfigName);
+ cmSystemTools::MakeDirectory(compilePdbOutputPath.c_str());
+
+ std::string pdbOutputPath = this->Target->GetPDBDirectory(this->ConfigName);
+ cmSystemTools::MakeDirectory(pdbOutputPath.c_str());
+ pdbOutputPath += "/";
+
+ std::string targetFullPath = outpath + targetName;
+ std::string targetFullPathPDB = pdbOutputPath + targetNamePDB;
+ std::string targetFullPathSO = outpath + targetNameSO;
+ std::string targetFullPathReal = outpath + targetNameReal;
+ std::string targetFullPathImport = outpathImp + targetNameImport;
+
+ // Construct the output path version of the names for use in command
+ // arguments.
+ std::string targetOutPathPDB =
+ this->Convert(targetFullPathPDB,cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ std::string targetOutPath =
+ this->Convert(targetFullPath,cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ std::string targetOutPathSO =
+ this->Convert(targetFullPathSO,cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ std::string targetOutPathReal =
+ this->Convert(targetFullPathReal,cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ std::string targetOutPathImport =
+ this->Convert(targetFullPathImport,cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+
+ if(!this->NoRuleMessages)
+ {
+ // Add the link message.
+ std::string buildEcho = "Linking ";
+ buildEcho += linkLanguage;
+ switch(this->Target->GetType())
+ {
+ case cmTarget::STATIC_LIBRARY:
+ buildEcho += " static library ";
+ break;
+ case cmTarget::SHARED_LIBRARY:
+ buildEcho += " shared library ";
+ break;
+ case cmTarget::MODULE_LIBRARY:
+ if (this->Target->IsCFBundleOnApple())
+ buildEcho += " CFBundle";
+ buildEcho += " shared module ";
+ break;
+ default:
+ buildEcho += " library ";
+ break;
+ }
+ buildEcho += targetOutPath.c_str();
+ this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(),
+ cmLocalUnixMakefileGenerator3::EchoLink);
+ }
+
+ const char* forbiddenFlagVar = 0;
+ switch(this->Target->GetType())
+ {
+ case cmTarget::SHARED_LIBRARY:
+ forbiddenFlagVar = "_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS";
+ break;
+ case cmTarget::MODULE_LIBRARY:
+ forbiddenFlagVar = "_CREATE_SHARED_MODULE_FORBIDDEN_FLAGS";
+ break;
+ default: break;
+ }
+
+ // Clean files associated with this library.
+ std::vector<std::string> libCleanFiles;
+ libCleanFiles.push_back(this->Convert(targetFullPath,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ if(targetNameReal != targetName)
+ {
+ libCleanFiles.push_back(this->Convert(targetFullPathReal,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ }
+ if(targetNameSO != targetName &&
+ targetNameSO != targetNameReal)
+ {
+ libCleanFiles.push_back(this->Convert(targetFullPathSO,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ }
+ if(!targetNameImport.empty())
+ {
+ libCleanFiles.push_back(this->Convert(targetFullPathImport,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ std::string implib;
+ if(this->Target->GetImplibGNUtoMS(targetFullPathImport, implib))
+ {
+ libCleanFiles.push_back(this->Convert(implib,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ }
+ }
+
+ // List the PDB for cleaning only when the whole target is
+ // cleaned. We do not want to delete the .pdb file just before
+ // linking the target.
+ this->CleanFiles.push_back
+ (this->Convert(targetFullPathPDB,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+
+#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)
+ {
+ libCleanFiles.push_back(
+ this->Convert((targetFullPath+".manifest").c_str(),
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ }
+#endif
+
+ 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)
+ {
+ this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles,
+ *this->Target, "target");
+ this->LocalGenerator->CreateCDCommand
+ (commands1,
+ this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+ commands.insert(commands.end(), commands1.begin(), commands1.end());
+ commands1.clear();
+ }
+
+ // Add the pre-build and pre-link rules building but not when relinking.
+ if(!relink)
+ {
+ this->LocalGenerator
+ ->AppendCustomCommands(commands, this->Target->GetPreBuildCommands(),
+ this->Target);
+ this->LocalGenerator
+ ->AppendCustomCommands(commands, this->Target->GetPreLinkCommands(),
+ this->Target);
+ }
+
+ // Determine whether a link script will be used.
+ bool useLinkScript = this->GlobalGenerator->GetUseLinkScript();
+
+ // Select whether to use a response file for objects.
+ bool useResponseFileForObjects = false;
+ {
+ std::string responseVar = "CMAKE_";
+ responseVar += linkLanguage;
+ responseVar += "_USE_RESPONSE_FILE_FOR_OBJECTS";
+ if(this->Makefile->IsOn(responseVar))
+ {
+ useResponseFileForObjects = true;
+ }
+ }
+
+ // Select whether to use a response file for libraries.
+ bool useResponseFileForLibs = false;
+ {
+ std::string responseVar = "CMAKE_";
+ responseVar += linkLanguage;
+ responseVar += "_USE_RESPONSE_FILE_FOR_LIBRARIES";
+ if(this->Makefile->IsOn(responseVar))
+ {
+ useResponseFileForLibs = true;
+ }
+ }
+
+ // For static libraries there might be archiving rules.
+ bool haveStaticLibraryRule = false;
+ std::vector<std::string> archiveCreateCommands;
+ 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)
+ {
+ haveStaticLibraryRule =
+ this->Makefile->GetDefinition(linkRuleVar)? true:false;
+ std::string arCreateVar = "CMAKE_";
+ arCreateVar += linkLanguage;
+ arCreateVar += "_ARCHIVE_CREATE";
+ if(const char* rule = this->Makefile->GetDefinition(arCreateVar))
+ {
+ cmSystemTools::ExpandListArgument(rule, archiveCreateCommands);
+ }
+ std::string arAppendVar = "CMAKE_";
+ arAppendVar += linkLanguage;
+ arAppendVar += "_ARCHIVE_APPEND";
+ if(const char* rule = this->Makefile->GetDefinition(arAppendVar))
+ {
+ cmSystemTools::ExpandListArgument(rule, archiveAppendCommands);
+ }
+ std::string arFinishVar = "CMAKE_";
+ arFinishVar += linkLanguage;
+ arFinishVar += "_ARCHIVE_FINISH";
+ if(const char* rule = this->Makefile->GetDefinition(arFinishVar))
+ {
+ cmSystemTools::ExpandListArgument(rule, archiveFinishCommands);
+ }
+ }
+
+ // Decide whether to use archiving rules.
+ bool useArchiveRules =
+ !haveStaticLibraryRule &&
+ !archiveCreateCommands.empty() && !archiveAppendCommands.empty();
+ if(useArchiveRules)
+ {
+ // Archiving rules are always run with a link script.
+ useLinkScript = true;
+
+ // Archiving rules never use a response file.
+ useResponseFileForObjects = false;
+
+ // Limit the length of individual object lists to less than the
+ // 32K command line length limit on Windows. We could make this a
+ // platform file variable but this should work everywhere.
+ archiveCommandLimit = 30000;
+ }
+
+ // Expand the rule variables.
+ std::vector<std::string> real_link_commands;
+ {
+ bool useWatcomQuote = this->Makefile->IsOn(linkRuleVar+"_USE_WATCOM_QUOTE");
+
+ // Set path conversion for link script shells.
+ this->LocalGenerator->SetLinkScriptShell(useLinkScript);
+
+ // Collect up flags to link in needed libraries.
+ std::string linkLibs;
+ if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
+ {
+ this->CreateLinkLibs(linkLibs, relink, useResponseFileForLibs, depends,
+ useWatcomQuote);
+ }
+
+ // Construct object file lists that may be needed to expand the
+ // rule.
+ std::string buildObjs;
+ this->CreateObjectLists(useLinkScript, useArchiveRules,
+ useResponseFileForObjects, buildObjs, depends,
+ useWatcomQuote);
+
+ cmLocalGenerator::RuleVariables vars;
+ vars.TargetPDB = targetOutPathPDB.c_str();
+
+ // Setup the target version.
+ std::string targetVersionMajor;
+ std::string targetVersionMinor;
+ {
+ cmOStringStream majorStream;
+ cmOStringStream minorStream;
+ int major;
+ int minor;
+ this->Target->GetTargetVersion(major, minor);
+ majorStream << major;
+ minorStream << minor;
+ targetVersionMajor = majorStream.str();
+ targetVersionMinor = minorStream.str();
+ }
+ vars.TargetVersionMajor = targetVersionMajor.c_str();
+ vars.TargetVersionMinor = targetVersionMinor.c_str();
+
+ vars.RuleLauncher = "RULE_LAUNCH_LINK";
+ vars.CMTarget = this->Target;
+ vars.Language = linkLanguage.c_str();
+ vars.Objects = buildObjs.c_str();
+ std::string objectDir = this->Target->GetSupportDirectory();
+ objectDir = this->Convert(objectDir,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ vars.ObjectDir = objectDir.c_str();
+ cmLocalGenerator::OutputFormat output = (useWatcomQuote) ?
+ cmLocalGenerator::WATCOMQUOTE : cmLocalGenerator::SHELL;
+ std::string target = this->Convert(targetFullPathReal,
+ cmLocalGenerator::START_OUTPUT,
+ output);
+ vars.Target = target.c_str();
+ vars.LinkLibraries = linkLibs.c_str();
+ vars.ObjectsQuoted = buildObjs.c_str();
+ if (this->Target->HasSOName(this->ConfigName))
+ {
+ vars.SONameFlag = this->Makefile->GetSONameFlag(linkLanguage);
+ vars.TargetSOName= targetNameSO.c_str();
+ }
+ vars.LinkFlags = linkFlags.c_str();
+
+ // Compute the directory portion of the install_name setting.
+ std::string install_name_dir;
+ if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
+ {
+ // Get the install_name directory for the build tree.
+ install_name_dir =
+ this->Target->GetInstallNameDirForBuildTree(this->ConfigName);
+
+ // Set the rule variable replacement value.
+ if(install_name_dir.empty())
+ {
+ vars.TargetInstallNameDir = "";
+ }
+ else
+ {
+ // Convert to a path for the native build tool.
+ install_name_dir =
+ this->LocalGenerator->Convert(install_name_dir,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL, false);
+ vars.TargetInstallNameDir = install_name_dir.c_str();
+ }
+ }
+
+ // Add language feature flags.
+ std::string langFlags;
+ this->AddFeatureFlags(langFlags, linkLanguage);
+
+ this->LocalGenerator->AddArchitectureFlags(langFlags, this->GeneratorTarget,
+ linkLanguage, this->ConfigName);
+
+ // remove any language flags that might not work with the
+ // particular os
+ if(forbiddenFlagVar)
+ {
+ this->RemoveForbiddenFlags(forbiddenFlagVar,
+ linkLanguage, langFlags);
+ }
+ vars.LanguageCompileFlags = langFlags.c_str();
+
+ // Construct the main link rule and expand placeholders.
+ this->LocalGenerator->TargetImplib = targetOutPathImport;
+ if(useArchiveRules)
+ {
+ // Construct the individual object list strings.
+ std::vector<std::string> object_strings;
+ this->WriteObjectsStrings(object_strings, archiveCommandLimit);
+
+ // Create the archive with the first set of objects.
+ std::vector<std::string>::iterator osi = object_strings.begin();
+ {
+ vars.Objects = osi->c_str();
+ for(std::vector<std::string>::const_iterator
+ i = archiveCreateCommands.begin();
+ i != archiveCreateCommands.end(); ++i)
+ {
+ std::string cmd = *i;
+ this->LocalGenerator->ExpandRuleVariables(cmd, vars);
+ real_link_commands.push_back(cmd);
+ }
+ }
+ // Append to the archive with the other object sets.
+ for(++osi; osi != object_strings.end(); ++osi)
+ {
+ vars.Objects = osi->c_str();
+ for(std::vector<std::string>::const_iterator
+ i = archiveAppendCommands.begin();
+ i != archiveAppendCommands.end(); ++i)
+ {
+ std::string cmd = *i;
+ this->LocalGenerator->ExpandRuleVariables(cmd, vars);
+ real_link_commands.push_back(cmd);
+ }
+ }
+ // Finish the archive.
+ vars.Objects = "";
+ for(std::vector<std::string>::const_iterator
+ i = archiveFinishCommands.begin();
+ i != archiveFinishCommands.end(); ++i)
+ {
+ std::string cmd = *i;
+ this->LocalGenerator->ExpandRuleVariables(cmd, vars);
+ real_link_commands.push_back(cmd);
+ }
+ }
+ else
+ {
+ // Get the set of commands.
+ std::string linkRule = this->GetLinkRule(linkRuleVar);
+ cmSystemTools::ExpandListArgument(linkRule, real_link_commands);
+
+ // Expand placeholders.
+ for(std::vector<std::string>::iterator i = real_link_commands.begin();
+ i != real_link_commands.end(); ++i)
+ {
+ this->LocalGenerator->ExpandRuleVariables(*i, vars);
+ }
+ }
+ this->LocalGenerator->TargetImplib = "";
+
+ // Restore path conversion to normal shells.
+ this->LocalGenerator->SetLinkScriptShell(false);
+ }
+
+ // Optionally convert the build rule to use a script to avoid long
+ // command lines in the make shell.
+ if(useLinkScript)
+ {
+ // Use a link script.
+ const char* name = (relink? "relink.txt" : "link.txt");
+ this->CreateLinkScript(name, real_link_commands, commands1, depends);
+ }
+ else
+ {
+ // No link script. Just use the link rule directly.
+ commands1 = real_link_commands;
+ }
+ this->LocalGenerator->CreateCDCommand
+ (commands1,
+ this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+ commands.insert(commands.end(), commands1.begin(), commands1.end());
+ commands1.clear();
+
+ // Add a rule to create necessary symlinks for the library.
+ // Frameworks are handled by cmOSXBundleGenerator.
+ if(targetOutPath != targetOutPathReal && !this->Target->IsFrameworkOnApple())
+ {
+ std::string symlink = "$(CMAKE_COMMAND) -E cmake_symlink_library ";
+ symlink += targetOutPathReal;
+ symlink += " ";
+ symlink += targetOutPathSO;
+ symlink += " ";
+ symlink += targetOutPath;
+ commands1.push_back(symlink);
+ this->LocalGenerator->CreateCDCommand(commands1,
+ this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+ commands.insert(commands.end(), commands1.begin(), commands1.end());
+ commands1.clear();
+ }
+ // Add the post-build rules when building but not when relinking.
+ if(!relink)
+ {
+ this->LocalGenerator->
+ AppendCustomCommands(commands, this->Target->GetPostBuildCommands(),
+ this->Target);
+ }
+
+ // Write the build rule.
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ targetFullPathReal,
+ depends, commands, false);
+
+ // Some targets have more than one output file. Create rules to
+ // drive the build if any extra outputs are missing.
+ std::vector<std::string> extraOutputs;
+ if(targetNameSO != targetNameReal)
+ {
+ this->GenerateExtraOutput(targetFullPathSO.c_str(),
+ targetFullPathReal.c_str());
+ }
+ if(targetName != targetNameSO &&
+ targetName != targetNameReal)
+ {
+ this->GenerateExtraOutput(targetFullPath.c_str(),
+ targetFullPathReal.c_str());
+ }
+
+ // Write the main driver rule to build everything in this target.
+ this->WriteTargetDriverRule(targetFullPath, relink);
+
+ // Clean all the possible library names and symlinks.
+ this->CleanFiles.insert(this->CleanFiles.end(),
+ libCleanFiles.begin(),libCleanFiles.end());
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileLibraryTargetGenerator
+::AppendOSXVerFlag(std::string& flags, const std::string& lang,
+ const char* name, bool so)
+{
+ // Lookup the flag to specify the version.
+ std::string fvar = "CMAKE_";
+ fvar += lang;
+ fvar += "_OSX_";
+ fvar += name;
+ fvar += "_VERSION_FLAG";
+ const char* flag = this->Makefile->GetDefinition(fvar);
+
+ // Skip if no such flag.
+ if(!flag)
+ {
+ return;
+ }
+
+ // Lookup the target version information.
+ int major;
+ int minor;
+ int patch;
+ this->Target->GetTargetVersion(so, major, minor, patch);
+ if(major > 0 || minor > 0 || patch > 0)
+ {
+ // Append the flag since a non-zero version is specified.
+ cmOStringStream vflag;
+ vflag << flag << major << "." << minor << "." << patch;
+ this->LocalGenerator->AppendFlags(flags, vflag.str());
+ }
+}
diff --git a/Source/cmMakefileLibraryTargetGenerator.h b/Source/cmMakefileLibraryTargetGenerator.h
new file mode 100644
index 0000000000..68980c3fff
--- /dev/null
+++ b/Source/cmMakefileLibraryTargetGenerator.h
@@ -0,0 +1,46 @@
+/*============================================================================
+ 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 cmMakefileLibraryTargetGenerator_h
+#define cmMakefileLibraryTargetGenerator_h
+
+#include "cmMakefileTargetGenerator.h"
+
+class cmMakefileLibraryTargetGenerator:
+ public cmMakefileTargetGenerator
+{
+public:
+ cmMakefileLibraryTargetGenerator(cmGeneratorTarget* target);
+ virtual ~cmMakefileLibraryTargetGenerator();
+
+ /* the main entry point for this class. Writes the Makefiles associated
+ with this target */
+ virtual void WriteRuleFiles();
+
+protected:
+ void WriteObjectLibraryRules();
+ void WriteStaticLibraryRules();
+ void WriteSharedLibraryRules(bool relink);
+ void WriteModuleLibraryRules(bool relink);
+ void WriteLibraryRules(const std::string& linkRule,
+ const std::string& extraFlags,
+ bool relink);
+ // MacOSX Framework support methods
+ void WriteFrameworkRules(bool relink);
+
+ // Store the computd framework version for OS X Frameworks.
+ std::string FrameworkVersion;
+
+ void AppendOSXVerFlag(std::string& flags, const std::string& lang,
+ const char* name, bool so);
+};
+
+#endif
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
new file mode 100644
index 0000000000..1f8f686783
--- /dev/null
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -0,0 +1,2131 @@
+/*============================================================================
+ 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 "cmMakefileTargetGenerator.h"
+
+#include "cmGeneratorTarget.h"
+#include "cmGeneratedFileStream.h"
+#include "cmGlobalGenerator.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmTarget.h"
+#include "cmake.h"
+#include "cmComputeLinkInformation.h"
+#include "cmCustomCommandGenerator.h"
+#include "cmGeneratorExpression.h"
+
+#include "cmMakefileExecutableTargetGenerator.h"
+#include "cmMakefileLibraryTargetGenerator.h"
+#include "cmMakefileUtilityTargetGenerator.h"
+
+#include <ctype.h>
+
+cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmTarget* target)
+ : OSXBundleGenerator(0)
+ , MacOSXContentGenerator(0)
+{
+ this->BuildFileStream = 0;
+ this->InfoFileStream = 0;
+ this->FlagFileStream = 0;
+ this->CustomCommandDriver = OnBuild;
+ this->FortranModuleDirectoryComputed = false;
+ this->Target = target;
+ this->Makefile = this->Target->GetMakefile();
+ this->LocalGenerator =
+ static_cast<cmLocalUnixMakefileGenerator3*>(
+ this->Makefile->GetLocalGenerator());
+ this->ConfigName = this->LocalGenerator->ConfigurationName.c_str();
+ this->GlobalGenerator =
+ static_cast<cmGlobalUnixMakefileGenerator3*>(
+ this->LocalGenerator->GetGlobalGenerator());
+ this->GeneratorTarget = this->GlobalGenerator->GetGeneratorTarget(target);
+ cmake* cm = this->GlobalGenerator->GetCMakeInstance();
+ this->NoRuleMessages = false;
+ if(const char* ruleStatus = cm->GetProperty("RULE_MESSAGES"))
+ {
+ this->NoRuleMessages = cmSystemTools::IsOff(ruleStatus);
+ }
+ MacOSXContentGenerator = new MacOSXContentGeneratorType(this);
+}
+
+cmMakefileTargetGenerator::~cmMakefileTargetGenerator()
+{
+ delete MacOSXContentGenerator;
+}
+
+cmMakefileTargetGenerator *
+cmMakefileTargetGenerator::New(cmGeneratorTarget *tgt)
+{
+ cmMakefileTargetGenerator *result = 0;
+
+ switch (tgt->GetType())
+ {
+ case cmTarget::EXECUTABLE:
+ result = new cmMakefileExecutableTargetGenerator(tgt);
+ break;
+ case cmTarget::STATIC_LIBRARY:
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ case cmTarget::OBJECT_LIBRARY:
+ result = new cmMakefileLibraryTargetGenerator(tgt);
+ break;
+ case cmTarget::UTILITY:
+ result = new cmMakefileUtilityTargetGenerator(tgt);
+ break;
+ default:
+ return result;
+ // break; /* unreachable */
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::CreateRuleFile()
+{
+ // Create a directory for this target.
+ this->TargetBuildDirectory =
+ this->LocalGenerator->GetTargetDirectory(*this->Target);
+ this->TargetBuildDirectoryFull =
+ this->LocalGenerator->ConvertToFullPath(this->TargetBuildDirectory);
+ cmSystemTools::MakeDirectory(this->TargetBuildDirectoryFull.c_str());
+
+ // Construct the rule file name.
+ this->BuildFileName = this->TargetBuildDirectory;
+ this->BuildFileName += "/build.make";
+ this->BuildFileNameFull = this->TargetBuildDirectoryFull;
+ this->BuildFileNameFull += "/build.make";
+
+ // Construct the rule file name.
+ this->ProgressFileNameFull = this->TargetBuildDirectoryFull;
+ this->ProgressFileNameFull += "/progress.make";
+
+ // reset the progress count
+ this->NumberOfProgressActions = 0;
+
+ // Open the rule file. This should be copy-if-different because the
+ // rules may depend on this file itself.
+ this->BuildFileStream =
+ new cmGeneratedFileStream(this->BuildFileNameFull.c_str());
+ this->BuildFileStream->SetCopyIfDifferent(true);
+ if(!this->BuildFileStream)
+ {
+ return;
+ }
+ this->LocalGenerator->WriteDisclaimer(*this->BuildFileStream);
+ this->LocalGenerator->WriteSpecialTargetsTop(*this->BuildFileStream);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::WriteTargetBuildRules()
+{
+ const std::string& config =
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+
+ // write the custom commands for this target
+ // Look for files registered for cleaning in this directory.
+ if(const char* additional_clean_files =
+ this->Makefile->GetProperty
+ ("ADDITIONAL_MAKE_CLEAN_FILES"))
+ {
+ cmGeneratorExpression ge;
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(additional_clean_files);
+
+ cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile, config,
+ false, this->Target, 0, 0),
+ this->CleanFiles);
+ }
+
+ // add custom commands to the clean rules?
+ const char* clean_no_custom =
+ this->Makefile->GetProperty("CLEAN_NO_CUSTOM");
+ bool clean = cmSystemTools::IsOff(clean_no_custom);
+
+ // First generate the object rule files. Save a list of all object
+ // files for this target.
+ std::vector<cmSourceFile const*> customCommands;
+ this->GeneratorTarget->GetCustomCommands(customCommands, config);
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = customCommands.begin();
+ si != customCommands.end(); ++si)
+ {
+ cmCustomCommandGenerator ccg(*(*si)->GetCustomCommand(),
+ this->ConfigName,
+ this->Makefile);
+ this->GenerateCustomRuleFile(ccg);
+ if (clean)
+ {
+ const std::vector<std::string>& outputs = ccg.GetOutputs();
+ for(std::vector<std::string>::const_iterator o = outputs.begin();
+ o != outputs.end(); ++o)
+ {
+ this->CleanFiles.push_back
+ (this->Convert(*o,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED));
+ }
+ }
+ }
+ std::vector<cmSourceFile const*> headerSources;
+ this->GeneratorTarget->GetHeaderSources(headerSources, config);
+ this->OSXBundleGenerator->GenerateMacOSXContentStatements(
+ headerSources,
+ this->MacOSXContentGenerator);
+ std::vector<cmSourceFile const*> extraSources;
+ this->GeneratorTarget->GetExtraSources(extraSources, config);
+ this->OSXBundleGenerator->GenerateMacOSXContentStatements(
+ extraSources,
+ this->MacOSXContentGenerator);
+ std::vector<cmSourceFile const*> externalObjects;
+ this->GeneratorTarget->GetExternalObjects(externalObjects, config);
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = externalObjects.begin();
+ si != externalObjects.end(); ++si)
+ {
+ this->ExternalObjects.push_back((*si)->GetFullPath());
+ }
+ std::vector<cmSourceFile const*> objectSources;
+ this->GeneratorTarget->GetObjectSources(objectSources, config);
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = objectSources.begin(); si != objectSources.end(); ++si)
+ {
+ // Generate this object file's rule file.
+ this->WriteObjectRuleFiles(**si);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::WriteCommonCodeRules()
+{
+ const char* root = (this->Makefile->IsOn("CMAKE_MAKE_INCLUDE_FROM_ROOT")?
+ "$(CMAKE_BINARY_DIR)/" : "");
+
+ // Include the dependencies for the target.
+ std::string dependFileNameFull = this->TargetBuildDirectoryFull;
+ dependFileNameFull += "/depend.make";
+ *this->BuildFileStream
+ << "# Include any dependencies generated for this target.\n"
+ << this->LocalGenerator->IncludeDirective << " " << root
+ << this->Convert(dependFileNameFull,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE)
+ << "\n\n";
+
+ if(!this->NoRuleMessages)
+ {
+ // Include the progress variables for the target.
+ *this->BuildFileStream
+ << "# Include the progress variables for this target.\n"
+ << this->LocalGenerator->IncludeDirective << " " << root
+ << this->Convert(this->ProgressFileNameFull,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE)
+ << "\n\n";
+ }
+
+ // make sure the depend file exists
+ if (!cmSystemTools::FileExists(dependFileNameFull.c_str()))
+ {
+ // Write an empty dependency file.
+ cmGeneratedFileStream depFileStream(dependFileNameFull.c_str());
+ depFileStream
+ << "# Empty dependencies file for " << this->Target->GetName() << ".\n"
+ << "# This may be replaced when dependencies are built." << std::endl;
+ }
+
+ // Open the flags file. This should be copy-if-different because the
+ // rules may depend on this file itself.
+ this->FlagFileNameFull = this->TargetBuildDirectoryFull;
+ this->FlagFileNameFull += "/flags.make";
+ this->FlagFileStream =
+ new cmGeneratedFileStream(this->FlagFileNameFull.c_str());
+ this->FlagFileStream->SetCopyIfDifferent(true);
+ if(!this->FlagFileStream)
+ {
+ return;
+ }
+ this->LocalGenerator->WriteDisclaimer(*this->FlagFileStream);
+
+ // Include the flags for the target.
+ *this->BuildFileStream
+ << "# Include the compile flags for this target's objects.\n"
+ << this->LocalGenerator->IncludeDirective << " " << root
+ << this->Convert(this->FlagFileNameFull,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE)
+ << "\n\n";
+}
+
+//----------------------------------------------------------------------------
+std::string cmMakefileTargetGenerator::GetFlags(const std::string &l)
+{
+ ByLanguageMap::iterator i = this->FlagsByLanguage.find(l);
+ if (i == this->FlagsByLanguage.end())
+ {
+ std::string flags;
+ const char *lang = l.c_str();
+
+ // Add language feature flags.
+ this->AddFeatureFlags(flags, lang);
+
+ this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
+ lang, this->ConfigName);
+
+ // Fortran-specific flags computed for this target.
+ if(l == "Fortran")
+ {
+ this->AddFortranFlags(flags);
+ }
+
+ this->LocalGenerator->AddCMP0018Flags(flags, this->Target,
+ lang, this->ConfigName);
+
+ this->LocalGenerator->AddVisibilityPresetFlags(flags, this->Target,
+ lang);
+
+ // Add include directory flags.
+ this->AddIncludeFlags(flags, lang);
+
+ // Append old-style preprocessor definition flags.
+ this->LocalGenerator->
+ AppendFlags(flags, this->Makefile->GetDefineFlags());
+
+ // Add include directory flags.
+ this->LocalGenerator->
+ AppendFlags(flags,this->GetFrameworkFlags(l));
+
+ // Add target-specific flags.
+ this->LocalGenerator->AddCompileOptions(flags, this->Target,
+ lang, this->ConfigName);
+
+ ByLanguageMap::value_type entry(l, flags);
+ i = this->FlagsByLanguage.insert(entry).first;
+ }
+ return i->second;
+}
+
+std::string cmMakefileTargetGenerator::GetDefines(const std::string &l)
+{
+ ByLanguageMap::iterator i = this->DefinesByLanguage.find(l);
+ if (i == this->DefinesByLanguage.end())
+ {
+ 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())
+ {
+ this->LocalGenerator->AppendDefines(defines, exportMacro);
+ }
+
+ // Add preprocessor definitions for this target and configuration.
+ this->LocalGenerator->AddCompileDefinitions(defines, this->Target,
+ this->LocalGenerator->ConfigurationName);
+
+ std::string definesString;
+ this->LocalGenerator->JoinDefines(defines, definesString, lang);
+
+ ByLanguageMap::value_type entry(l, definesString);
+ i = this->DefinesByLanguage.insert(entry).first;
+ }
+ return i->second;
+}
+
+void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
+{
+ // write language flags for target
+ std::set<std::string> languages;
+ this->Target->GetLanguages(languages,
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ // put the compiler in the rules.make file so that if it changes
+ // things rebuild
+ for(std::set<std::string>::const_iterator l = languages.begin();
+ l != languages.end(); ++l)
+ {
+ std::string compiler = "CMAKE_";
+ compiler += *l;
+ compiler += "_COMPILER";
+ *this->FlagFileStream << "# compile " << *l << " with " <<
+ this->Makefile->GetSafeDefinition(compiler) << "\n";
+ }
+
+ for(std::set<std::string>::const_iterator l = languages.begin();
+ l != languages.end(); ++l)
+ {
+ std::string flags = this->GetFlags(*l);
+ std::string defines = this->GetDefines(*l);
+ // Escape comment characters so they do not terminate assignment.
+ cmSystemTools::ReplaceString(flags, "#", "\\#");
+ cmSystemTools::ReplaceString(defines, "#", "\\#");
+ *this->FlagFileStream << *l << "_FLAGS = " << flags << "\n\n";
+ *this->FlagFileStream << *l << "_DEFINES = " << defines << "\n\n";
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()
+ (cmSourceFile const& source, const char* pkgloc)
+{
+ // Skip OS X content when not building a Framework or Bundle.
+ if(!this->Generator->GetTarget()->IsBundleOnApple())
+ {
+ return;
+ }
+
+ std::string macdir =
+ this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc);
+
+ // Get the input file location.
+ std::string input = source.GetFullPath();
+
+ // Get the output file location.
+ std::string output = macdir;
+ output += "/";
+ output += cmSystemTools::GetFilenameName(input);
+ this->Generator->CleanFiles.push_back(
+ this->Generator->Convert(output,
+ cmLocalGenerator::START_OUTPUT));
+ output = this->Generator->Convert(output,
+ cmLocalGenerator::HOME_OUTPUT);
+
+ // Create a rule to copy the content into the bundle.
+ std::vector<std::string> depends;
+ std::vector<std::string> commands;
+ depends.push_back(input);
+ std::string copyEcho = "Copying OS X content ";
+ copyEcho += output;
+ this->Generator->LocalGenerator->AppendEcho(
+ commands, copyEcho.c_str(),
+ cmLocalUnixMakefileGenerator3::EchoBuild);
+ std::string copyCommand = "$(CMAKE_COMMAND) -E copy ";
+ copyCommand += this->Generator->Convert(input,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ copyCommand += " ";
+ copyCommand += this->Generator->Convert(output,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ commands.push_back(copyCommand);
+ this->Generator->LocalGenerator->WriteMakeRule(
+ *this->Generator->BuildFileStream, 0,
+ output,
+ depends, commands, false);
+ this->Generator->ExtraFiles.insert(output);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator
+::WriteObjectRuleFiles(cmSourceFile const& source)
+{
+ // Identify the language of the source file.
+ const std::string& lang =
+ this->LocalGenerator->GetSourceFileLanguage(source);
+ if(lang.empty())
+ {
+ // don't know anything about this file so skip it
+ return;
+ }
+
+ // 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);
+ obj += "/";
+ obj += objectName;
+
+ // Avoid generating duplicate rules.
+ if(this->ObjectFiles.find(obj) == this->ObjectFiles.end())
+ {
+ this->ObjectFiles.insert(obj);
+ }
+ else
+ {
+ cmOStringStream err;
+ err << "Warning: Source file \""
+ << source.GetFullPath()
+ << "\" is listed multiple times for target \""
+ << this->Target->GetName()
+ << "\".";
+ cmSystemTools::Message(err.str().c_str(), "Warning");
+ return;
+ }
+
+ // Create the directory containing the object file. This may be a
+ // subdirectory under the target's directory.
+ std::string dir = cmSystemTools::GetFilenamePath(obj);
+ cmSystemTools::MakeDirectory
+ (this->LocalGenerator->ConvertToFullPath(dir).c_str());
+
+ // Save this in the target's list of object files.
+ this->Objects.push_back(obj);
+ this->CleanFiles.push_back(obj);
+
+ // TODO: Remove
+ //std::string relativeObj
+ //= this->LocalGenerator->GetHomeRelativeOutputPath();
+ //relativeObj += obj;
+
+ // we compute some depends when writing the depend.make that we will also
+ // use in the build.make, same with depMakeFile
+ std::vector<std::string> depends;
+ std::string depMakeFile;
+
+ // generate the build rule file
+ this->WriteObjectBuildFile(obj, lang, source, depends);
+
+ // The object file should be checked for dependency integrity.
+ std::string objFullPath = this->Makefile->GetCurrentOutputDirectory();
+ objFullPath += "/";
+ objFullPath += obj;
+ objFullPath =
+ this->Convert(objFullPath, cmLocalGenerator::FULL);
+ std::string srcFullPath =
+ this->Convert(source.GetFullPath(), cmLocalGenerator::FULL);
+ this->LocalGenerator->
+ AddImplicitDepends(*this->Target, lang,
+ objFullPath.c_str(),
+ srcFullPath.c_str());
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::AppendFortranFormatFlags(std::string& flags, cmSourceFile const& source)
+{
+ const char* srcfmt = source.GetProperty("Fortran_FORMAT");
+ cmLocalGenerator::FortranFormat format =
+ this->LocalGenerator->GetFortranFormat(srcfmt);
+ if(format == cmLocalGenerator::FortranFormatNone)
+ {
+ const char* tgtfmt = this->Target->GetProperty("Fortran_FORMAT");
+ format = this->LocalGenerator->GetFortranFormat(tgtfmt);
+ }
+ const char* var = 0;
+ switch (format)
+ {
+ case cmLocalGenerator::FortranFormatFixed:
+ var = "CMAKE_Fortran_FORMAT_FIXED_FLAG"; break;
+ case cmLocalGenerator::FortranFormatFree:
+ var = "CMAKE_Fortran_FORMAT_FREE_FLAG"; break;
+ default: break;
+ }
+ if(var)
+ {
+ this->LocalGenerator->AppendFlags(
+ flags, this->Makefile->GetDefinition(var));
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::WriteObjectBuildFile(std::string &obj,
+ const std::string& lang,
+ cmSourceFile const& source,
+ std::vector<std::string>& depends)
+{
+ this->LocalGenerator->AppendRuleDepend(depends,
+ this->FlagFileNameFull.c_str());
+ this->LocalGenerator->AppendRuleDepends(depends,
+ this->FlagFileDepends[lang]);
+
+ // generate the depend scanning rule
+ this->WriteObjectDependRules(source, depends);
+
+ std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
+ relativeObj += obj;
+ // Write the build rule.
+
+ // Build the set of compiler flags.
+ std::string flags;
+
+ // Add language-specific flags.
+ std::string langFlags = "$(";
+ langFlags += lang;
+ langFlags += "_FLAGS)";
+ this->LocalGenerator->AppendFlags(flags, langFlags);
+
+ std::string configUpper =
+ cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName);
+
+ // Add Fortran format flags.
+ if(lang == "Fortran")
+ {
+ this->AppendFortranFormatFlags(flags, source);
+ }
+
+ // Add flags from source file properties.
+ if (source.GetProperty("COMPILE_FLAGS"))
+ {
+ this->LocalGenerator->AppendFlags
+ (flags, source.GetProperty("COMPILE_FLAGS"));
+ *this->FlagFileStream << "# Custom flags: "
+ << relativeObj << "_FLAGS = "
+ << source.GetProperty("COMPILE_FLAGS")
+ << "\n"
+ << "\n";
+ }
+
+ // Add language-specific defines.
+ std::set<std::string> defines;
+
+ // Add source-sepcific preprocessor definitions.
+ if(const char* compile_defs = source.GetProperty("COMPILE_DEFINITIONS"))
+ {
+ this->LocalGenerator->AppendDefines(defines, compile_defs);
+ *this->FlagFileStream << "# Custom defines: "
+ << relativeObj << "_DEFINES = "
+ << compile_defs << "\n"
+ << "\n";
+ }
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += configUpper;
+ if(const char* config_compile_defs =
+ source.GetProperty(defPropName))
+ {
+ this->LocalGenerator->AppendDefines(defines, config_compile_defs);
+ *this->FlagFileStream
+ << "# Custom defines: "
+ << relativeObj << "_DEFINES_" << configUpper
+ << " = " << config_compile_defs << "\n"
+ << "\n";
+ }
+
+ // Get the output paths for source and object files.
+ std::string sourceFile = source.GetFullPath();
+ if(this->LocalGenerator->UseRelativePaths)
+ {
+ sourceFile = this->Convert(sourceFile,
+ cmLocalGenerator::START_OUTPUT);
+ }
+ sourceFile = this->Convert(sourceFile,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+
+ // Construct the build message.
+ std::vector<std::string> no_commands;
+ std::vector<std::string> commands;
+
+ // add in a progress call if needed
+ this->AppendProgress(commands);
+
+ if(!this->NoRuleMessages)
+ {
+ std::string buildEcho = "Building ";
+ buildEcho += lang;
+ buildEcho += " object ";
+ buildEcho += relativeObj;
+ this->LocalGenerator->AppendEcho
+ (commands, buildEcho.c_str(), cmLocalUnixMakefileGenerator3::EchoBuild);
+ }
+
+ std::string targetOutPathReal;
+ std::string targetOutPathPDB;
+ std::string targetOutPathCompilePDB;
+ {
+ 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)
+ {
+ targetFullPathReal =
+ this->Target->GetFullPath(this->ConfigName, false, true);
+ targetFullPathPDB = this->Target->GetPDBDirectory(this->ConfigName);
+ targetFullPathPDB += "/";
+ targetFullPathPDB += this->Target->GetPDBName(this->ConfigName);
+ }
+ if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
+ {
+ targetFullPathCompilePDB =
+ this->Target->GetCompilePDBPath(this->ConfigName);
+ if(targetFullPathCompilePDB.empty())
+ {
+ targetFullPathCompilePDB = this->Target->GetSupportDirectory() + "/";
+ }
+ }
+
+ targetOutPathReal = this->Convert(targetFullPathReal,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ targetOutPathPDB =
+ this->Convert(targetFullPathPDB,cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ targetOutPathCompilePDB =
+ this->Convert(targetFullPathCompilePDB,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ }
+ cmLocalGenerator::RuleVariables vars;
+ vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
+ vars.CMTarget = this->Target;
+ vars.Language = lang.c_str();
+ vars.Target = targetOutPathReal.c_str();
+ vars.TargetPDB = targetOutPathPDB.c_str();
+ vars.TargetCompilePDB = targetOutPathCompilePDB.c_str();
+ vars.Source = sourceFile.c_str();
+ std::string shellObj =
+ this->Convert(obj,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ vars.Object = shellObj.c_str();
+ std::string objectDir = this->Target->GetSupportDirectory();
+ objectDir = this->Convert(objectDir,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ vars.ObjectDir = objectDir.c_str();
+ std::string objectFileDir = cmSystemTools::GetFilenamePath(obj);
+ objectFileDir = this->Convert(objectFileDir,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ vars.ObjectFileDir = objectFileDir.c_str();
+ vars.Flags = flags.c_str();
+
+ std::string definesString = "$(";
+ definesString += lang;
+ definesString += "_DEFINES)";
+
+ this->LocalGenerator->JoinDefines(defines, definesString, lang);
+
+ vars.Defines = definesString.c_str();
+
+ bool lang_is_c_or_cxx = ((lang == "C") || (lang == "CXX"));
+
+ // Construct the compile rules.
+ {
+ std::string compileRuleVar = "CMAKE_";
+ compileRuleVar += lang;
+ compileRuleVar += "_COMPILE_OBJECT";
+ std::string compileRule =
+ this->Makefile->GetRequiredDefinition(compileRuleVar);
+ std::vector<std::string> compileCommands;
+ cmSystemTools::ExpandListArgument(compileRule, compileCommands);
+
+ if (this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS") &&
+ lang_is_c_or_cxx && compileCommands.size() == 1)
+ {
+ std::string compileCommand = compileCommands[0];
+ this->LocalGenerator->ExpandRuleVariables(compileCommand, vars);
+ std::string workingDirectory =
+ this->LocalGenerator->Convert(
+ this->Makefile->GetStartOutputDirectory(), cmLocalGenerator::FULL);
+ compileCommand.replace(compileCommand.find(langFlags),
+ langFlags.size(), this->GetFlags(lang));
+ std::string langDefines = std::string("$(") + lang + "_DEFINES)";
+ compileCommand.replace(compileCommand.find(langDefines),
+ langDefines.size(), this->GetDefines(lang));
+ this->GlobalGenerator->AddCXXCompileCommand(
+ source.GetFullPath(), workingDirectory, compileCommand);
+ }
+
+ // Expand placeholders in the commands.
+ for(std::vector<std::string>::iterator i = compileCommands.begin();
+ i != compileCommands.end(); ++i)
+ {
+ this->LocalGenerator->ExpandRuleVariables(*i, vars);
+ }
+
+ // Change the command working directory to the local build tree.
+ this->LocalGenerator->CreateCDCommand
+ (compileCommands,
+ this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+ commands.insert(commands.end(),
+ compileCommands.begin(), compileCommands.end());
+ }
+
+ // Write the rule.
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ relativeObj,
+ depends, commands, false);
+
+ // Check for extra outputs created by the compilation.
+ if(const char* extra_outputs_str =
+ source.GetProperty("OBJECT_OUTPUTS"))
+ {
+ std::vector<std::string> extra_outputs;
+ cmSystemTools::ExpandListArgument(extra_outputs_str, extra_outputs);
+ for(std::vector<std::string>::const_iterator eoi = extra_outputs.begin();
+ eoi != extra_outputs.end(); ++eoi)
+ {
+ // Register this as an extra output for the object file rule.
+ // This will cause the object file to be rebuilt if the extra
+ // output is missing.
+ this->GenerateExtraOutput(eoi->c_str(), relativeObj.c_str(), false);
+
+ // Register this as an extra file to clean.
+ this->CleanFiles.push_back(*eoi);
+ }
+ }
+
+ bool do_preprocess_rules = lang_is_c_or_cxx &&
+ this->LocalGenerator->GetCreatePreprocessedSourceRules();
+ bool do_assembly_rules = lang_is_c_or_cxx &&
+ this->LocalGenerator->GetCreateAssemblySourceRules();
+ if(do_preprocess_rules || do_assembly_rules)
+ {
+ std::vector<std::string> force_depends;
+ force_depends.push_back("cmake_force");
+ std::string::size_type dot_pos = relativeObj.rfind(".");
+ std::string relativeObjBase = relativeObj.substr(0, dot_pos);
+ dot_pos = obj.rfind(".");
+ std::string objBase = obj.substr(0, dot_pos);
+
+ if(do_preprocess_rules)
+ {
+ commands.clear();
+ std::string relativeObjI = relativeObjBase + ".i";
+ std::string objI = objBase + ".i";
+
+ std::string preprocessEcho = "Preprocessing ";
+ preprocessEcho += lang;
+ preprocessEcho += " source to ";
+ preprocessEcho += objI;
+ this->LocalGenerator->AppendEcho(
+ commands, preprocessEcho.c_str(),
+ cmLocalUnixMakefileGenerator3::EchoBuild
+ );
+
+ std::string preprocessRuleVar = "CMAKE_";
+ preprocessRuleVar += lang;
+ preprocessRuleVar += "_CREATE_PREPROCESSED_SOURCE";
+ if(const char* preprocessRule =
+ this->Makefile->GetDefinition(preprocessRuleVar))
+ {
+ std::vector<std::string> preprocessCommands;
+ cmSystemTools::ExpandListArgument(preprocessRule, preprocessCommands);
+
+ std::string shellObjI =
+ this->Convert(objI,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ vars.PreprocessedSource = shellObjI.c_str();
+
+ // Expand placeholders in the commands.
+ for(std::vector<std::string>::iterator i = preprocessCommands.begin();
+ i != preprocessCommands.end(); ++i)
+ {
+ this->LocalGenerator->ExpandRuleVariables(*i, vars);
+ }
+
+ this->LocalGenerator->CreateCDCommand
+ (preprocessCommands,
+ this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+ commands.insert(commands.end(),
+ preprocessCommands.begin(),
+ preprocessCommands.end());
+ }
+ else
+ {
+ std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
+ cmd += preprocessRuleVar;
+ commands.push_back(cmd);
+ }
+
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ relativeObjI,
+ force_depends, commands, false);
+ }
+
+ if(do_assembly_rules)
+ {
+ commands.clear();
+ std::string relativeObjS = relativeObjBase + ".s";
+ std::string objS = objBase + ".s";
+
+ std::string assemblyEcho = "Compiling ";
+ assemblyEcho += lang;
+ assemblyEcho += " source to assembly ";
+ assemblyEcho += objS;
+ this->LocalGenerator->AppendEcho(
+ commands, assemblyEcho.c_str(),
+ cmLocalUnixMakefileGenerator3::EchoBuild
+ );
+
+ std::string assemblyRuleVar = "CMAKE_";
+ assemblyRuleVar += lang;
+ assemblyRuleVar += "_CREATE_ASSEMBLY_SOURCE";
+ if(const char* assemblyRule =
+ this->Makefile->GetDefinition(assemblyRuleVar))
+ {
+ std::vector<std::string> assemblyCommands;
+ cmSystemTools::ExpandListArgument(assemblyRule, assemblyCommands);
+
+ std::string shellObjS =
+ this->Convert(objS,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ vars.AssemblySource = shellObjS.c_str();
+
+ // Expand placeholders in the commands.
+ for(std::vector<std::string>::iterator i = assemblyCommands.begin();
+ i != assemblyCommands.end(); ++i)
+ {
+ this->LocalGenerator->ExpandRuleVariables(*i, vars);
+ }
+
+ this->LocalGenerator->CreateCDCommand
+ (assemblyCommands,
+ this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+ commands.insert(commands.end(),
+ assemblyCommands.begin(),
+ assemblyCommands.end());
+ }
+ else
+ {
+ std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
+ cmd += assemblyRuleVar;
+ commands.push_back(cmd);
+ }
+
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ relativeObjS,
+ force_depends, commands, false);
+ }
+ }
+
+ // If the language needs provides-requires mode, create the
+ // corresponding targets.
+ std::string objectRequires = relativeObj;
+ objectRequires += ".requires";
+ std::vector<std::string> p_depends;
+ // always provide an empty requires target
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ objectRequires, p_depends,
+ no_commands, true);
+
+ // write a build rule to recursively build what this obj provides
+ std::string objectProvides = relativeObj;
+ objectProvides += ".provides";
+ std::string temp = relativeObj;
+ temp += ".provides.build";
+ std::vector<std::string> r_commands;
+ std::string tgtMakefileName =
+ this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+ tgtMakefileName += "/build.make";
+ r_commands.push_back
+ (this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(),
+ temp));
+
+ p_depends.clear();
+ p_depends.push_back(objectRequires);
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ objectProvides, p_depends,
+ r_commands, true);
+
+ // write the provides.build rule dependency on the obj file
+ p_depends.clear();
+ p_depends.push_back(relativeObj);
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ temp, p_depends, no_commands,
+ false);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::WriteTargetRequiresRules()
+{
+ std::vector<std::string> depends;
+ std::vector<std::string> no_commands;
+
+ // Construct the name of the dependency generation target.
+ std::string depTarget =
+ this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+ depTarget += "/requires";
+
+ // This target drives dependency generation for all object files.
+ std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
+ std::string objTarget;
+ for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
+ obj != this->Objects.end(); ++obj)
+ {
+ objTarget = relPath;
+ objTarget += *obj;
+ objTarget += ".requires";
+ depends.push_back(objTarget);
+ }
+
+ // Write the rule.
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ depTarget,
+ depends, no_commands, true);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::WriteTargetCleanRules()
+{
+ std::vector<std::string> depends;
+ std::vector<std::string> commands;
+
+ // Construct the clean target name.
+ std::string cleanTarget =
+ this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+ cleanTarget += "/clean";
+
+ // Construct the clean command.
+ this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
+ *this->Target);
+ this->LocalGenerator->CreateCDCommand
+ (commands,
+ this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::HOME_OUTPUT);
+
+ // Write the rule.
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ cleanTarget,
+ depends, commands, true);
+}
+
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::WriteTargetDependRules()
+{
+ // must write the targets depend info file
+ std::string dir = this->LocalGenerator->GetTargetDirectory(*this->Target);
+ this->InfoFileNameFull = dir;
+ this->InfoFileNameFull += "/DependInfo.cmake";
+ this->InfoFileNameFull =
+ this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull);
+ this->InfoFileStream =
+ new cmGeneratedFileStream(this->InfoFileNameFull.c_str());
+ this->InfoFileStream->SetCopyIfDifferent(true);
+ if(!*this->InfoFileStream)
+ {
+ return;
+ }
+ this->LocalGenerator->
+ WriteDependLanguageInfo(*this->InfoFileStream,*this->Target);
+
+ // Store multiple output pairs in the depend info file.
+ if(!this->MultipleOutputPairs.empty())
+ {
+ *this->InfoFileStream
+ << "\n"
+ << "# Pairs of files generated by the same build rule.\n"
+ << "set(CMAKE_MULTIPLE_OUTPUT_PAIRS\n";
+ for(MultipleOutputPairsType::const_iterator pi =
+ this->MultipleOutputPairs.begin();
+ pi != this->MultipleOutputPairs.end(); ++pi)
+ {
+ *this->InfoFileStream
+ << " " << this->LocalGenerator->EscapeForCMake(pi->first)
+ << " " << this->LocalGenerator->EscapeForCMake(pi->second)
+ << "\n";
+ }
+ *this->InfoFileStream << " )\n\n";
+ }
+
+ // Store list of targets linked directly or transitively.
+ {
+ *this->InfoFileStream
+ << "\n"
+ << "# Targets to which this target links.\n"
+ << "set(CMAKE_TARGET_LINKED_INFO_FILES\n";
+ std::set<cmTarget const*> emitted;
+ const char* cfg = this->LocalGenerator->ConfigurationName.c_str();
+ if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg))
+ {
+ cmComputeLinkInformation::ItemVector const& items = cli->GetItems();
+ for(cmComputeLinkInformation::ItemVector::const_iterator
+ i = items.begin(); i != items.end(); ++i)
+ {
+ cmTarget 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
+ && emitted.insert(linkee).second)
+ {
+ cmMakefile* mf = linkee->GetMakefile();
+ cmLocalGenerator* lg = mf->GetLocalGenerator();
+ std::string di = mf->GetStartOutputDirectory();
+ di += "/";
+ di += lg->GetTargetDirectory(*linkee);
+ di += "/DependInfo.cmake";
+ *this->InfoFileStream << " \"" << di << "\"\n";
+ }
+ }
+ }
+ *this->InfoFileStream
+ << " )\n";
+ }
+
+ // Check for a target-specific module output directory.
+ if(const char* mdir = this->GetFortranModuleDirectory())
+ {
+ *this->InfoFileStream
+ << "\n"
+ << "# Fortran module output directory.\n"
+ << "set(CMAKE_Fortran_TARGET_MODULE_DIR \"" << mdir << "\")\n";
+ }
+
+ // Target-specific include directories:
+ *this->InfoFileStream
+ << "\n"
+ << "# The include file search paths:\n";
+ *this->InfoFileStream
+ << "set(CMAKE_C_TARGET_INCLUDE_PATH\n";
+ std::vector<std::string> includes;
+
+ const std::string& config =
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ this->LocalGenerator->GetIncludeDirectories(includes,
+ this->GeneratorTarget,
+ "C", config);
+ for(std::vector<std::string>::iterator i = includes.begin();
+ i != includes.end(); ++i)
+ {
+ *this->InfoFileStream
+ << " \""
+ << this->LocalGenerator->Convert(*i,
+ cmLocalGenerator::HOME_OUTPUT)
+ << "\"\n";
+ }
+ *this->InfoFileStream
+ << " )\n";
+ *this->InfoFileStream
+ << "set(CMAKE_CXX_TARGET_INCLUDE_PATH "
+ << "${CMAKE_C_TARGET_INCLUDE_PATH})\n";
+ *this->InfoFileStream
+ << "set(CMAKE_Fortran_TARGET_INCLUDE_PATH "
+ << "${CMAKE_C_TARGET_INCLUDE_PATH})\n";
+ *this->InfoFileStream
+ << "set(CMAKE_ASM_TARGET_INCLUDE_PATH "
+ << "${CMAKE_C_TARGET_INCLUDE_PATH})\n";
+
+ // and now write the rule to use it
+ std::vector<std::string> depends;
+ std::vector<std::string> commands;
+
+ // Construct the name of the dependency generation target.
+ std::string depTarget =
+ this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+ depTarget += "/depend";
+
+ // Add a command to call CMake to scan dependencies. CMake will
+ // touch the corresponding depends file after scanning dependencies.
+ cmOStringStream depCmd;
+ // TODO: Account for source file properties and directory-level
+ // definitions when scanning for dependencies.
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ // This platform supports symlinks, so cmSystemTools will translate
+ // paths. Make sure PWD is set to the original name of the home
+ // output directory to help cmSystemTools to create the same
+ // translation table for the dependency scanning process.
+ depCmd << "cd "
+ << (this->LocalGenerator->Convert(
+ this->Makefile->GetHomeOutputDirectory(),
+ cmLocalGenerator::FULL, cmLocalGenerator::SHELL))
+ << " && ";
+#endif
+ // Generate a call this signature:
+ //
+ // cmake -E cmake_depends <generator>
+ // <home-src-dir> <start-src-dir>
+ // <home-out-dir> <start-out-dir>
+ // <dep-info> --color=$(COLOR)
+ //
+ // This gives the dependency scanner enough information to recreate
+ // the state of our local generator sufficiently for its needs.
+ depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
+ << this->GlobalGenerator->GetName() << "\" "
+ << this->Convert(this->Makefile->GetHomeDirectory(),
+ cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
+ << " "
+ << this->Convert(this->Makefile->GetStartDirectory(),
+ cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
+ << " "
+ << this->Convert(this->Makefile->GetHomeOutputDirectory(),
+ cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
+ << " "
+ << this->Convert(this->Makefile->GetStartOutputDirectory(),
+ cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
+ << " "
+ << this->Convert(this->InfoFileNameFull,
+ cmLocalGenerator::FULL, cmLocalGenerator::SHELL);
+ if(this->LocalGenerator->GetColorMakefile())
+ {
+ depCmd << " --color=$(COLOR)";
+ }
+ commands.push_back(depCmd.str());
+
+ // Make sure all custom command outputs in this target are built.
+ if(this->CustomCommandDriver == OnDepends)
+ {
+ this->DriveCustomCommands(depends);
+ }
+
+ // Write the rule.
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ depTarget,
+ depends, commands, true);
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::DriveCustomCommands(std::vector<std::string>& depends)
+{
+ // Depend on all custom command outputs.
+ std::vector<cmSourceFile*> sources;
+ this->Target->GetSourceFiles(sources,
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
+ source != sources.end(); ++source)
+ {
+ if(cmCustomCommand* cc = (*source)->GetCustomCommand())
+ {
+ cmCustomCommandGenerator ccg(*cc, this->ConfigName, this->Makefile);
+ const std::vector<std::string>& outputs = ccg.GetOutputs();
+ for(std::vector<std::string>::const_iterator o = outputs.begin();
+ o != outputs.end(); ++o)
+ {
+ depends.push_back(*o);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator
+::WriteObjectDependRules(cmSourceFile const& source,
+ std::vector<std::string>& depends)
+{
+ // Create the list of dependencies known at cmake time. These are
+ // shared between the object file and dependency scanning rule.
+ depends.push_back(source.GetFullPath());
+ if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
+ {
+ std::vector<std::string> deps;
+ cmSystemTools::ExpandListArgument(objectDeps, deps);
+ for(std::vector<std::string>::iterator i = deps.begin();
+ i != deps.end(); ++i)
+ {
+ depends.push_back(*i);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator
+::GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg)
+{
+ // Collect the commands.
+ std::vector<std::string> commands;
+ std::string comment = this->LocalGenerator->ConstructComment(ccg);
+ if(!comment.empty())
+ {
+ // add in a progress call if needed
+ this->AppendProgress(commands);
+ if(!this->NoRuleMessages)
+ {
+ this->LocalGenerator
+ ->AppendEcho(commands, comment.c_str(),
+ cmLocalUnixMakefileGenerator3::EchoGenerate);
+ }
+ }
+
+ // Now append the actual user-specified commands.
+ cmOStringStream content;
+ this->LocalGenerator->AppendCustomCommand(commands, ccg, this->Target, false,
+ cmLocalGenerator::HOME_OUTPUT,
+ &content);
+
+ // Collect the dependencies.
+ std::vector<std::string> depends;
+ this->LocalGenerator->AppendCustomDepend(depends, ccg);
+
+ // Check whether we need to bother checking for a symbolic output.
+ bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark();
+
+ // Write the rule.
+ const std::vector<std::string>& outputs = ccg.GetOutputs();
+ std::vector<std::string>::const_iterator o = outputs.begin();
+ {
+ bool symbolic = false;
+ if(need_symbolic)
+ {
+ if(cmSourceFile* sf = this->Makefile->GetSource(*o))
+ {
+ symbolic = sf->GetPropertyAsBool("SYMBOLIC");
+ }
+ }
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ *o, depends, commands,
+ symbolic);
+
+ // If the rule has changed make sure the output is rebuilt.
+ if(!symbolic)
+ {
+ this->GlobalGenerator->AddRuleHash(ccg.GetOutputs(), content.str());
+ }
+ }
+
+ // Write rules to drive building any outputs beyond the first.
+ const char* in = o->c_str();
+ for(++o; o != outputs.end(); ++o)
+ {
+ bool symbolic = false;
+ if(need_symbolic)
+ {
+ if(cmSourceFile* sf = this->Makefile->GetSource(*o))
+ {
+ symbolic = sf->GetPropertyAsBool("SYMBOLIC");
+ }
+ }
+ this->GenerateExtraOutput(o->c_str(), in, symbolic);
+ }
+
+ // Setup implicit dependency scanning.
+ for(cmCustomCommand::ImplicitDependsList::const_iterator
+ idi = ccg.GetCC().GetImplicitDepends().begin();
+ idi != ccg.GetCC().GetImplicitDepends().end(); ++idi)
+ {
+ std::string objFullPath =
+ this->Convert(outputs[0], cmLocalGenerator::FULL);
+ std::string srcFullPath =
+ this->Convert(idi->second, cmLocalGenerator::FULL);
+ this->LocalGenerator->
+ AddImplicitDepends(*this->Target, idi->first,
+ objFullPath.c_str(),
+ srcFullPath.c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::GenerateExtraOutput(const char* out, const char* in, bool symbolic)
+{
+ // Add a rule to build the primary output if the extra output needs
+ // to be created.
+ std::vector<std::string> commands;
+ std::vector<std::string> depends;
+ std::string emptyCommand = this->GlobalGenerator->GetEmptyRuleHackCommand();
+ if(!emptyCommand.empty())
+ {
+ commands.push_back(emptyCommand);
+ }
+ depends.push_back(in);
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ out, depends, commands,
+ symbolic);
+
+ // Register the extra output as paired with the first output so that
+ // the check-build-system step will remove the primary output if any
+ // extra outputs are missing. This forces the rule to regenerate
+ // all outputs.
+ this->AddMultipleOutputPair(out, in);
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator::AppendProgress(std::vector<std::string>& commands)
+{
+ this->NumberOfProgressActions++;
+ if(this->NoRuleMessages)
+ {
+ return;
+ }
+ std::string progressDir = this->Makefile->GetHomeOutputDirectory();
+ progressDir += cmake::GetCMakeFilesDirectory();
+ cmOStringStream progCmd;
+ progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
+ progCmd << this->LocalGenerator->Convert(progressDir,
+ cmLocalGenerator::FULL,
+ cmLocalGenerator::SHELL);
+ progCmd << " $(CMAKE_PROGRESS_" << this->NumberOfProgressActions << ")";
+ commands.push_back(progCmd.str());
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::WriteObjectsVariable(std::string& variableName,
+ std::string& variableNameExternal,
+ bool useWatcomQuote)
+{
+ // Write a make variable assignment that lists all objects for the
+ // target.
+ variableName =
+ this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
+ "_OBJECTS");
+ *this->BuildFileStream
+ << "# Object files for target " << this->Target->GetName() << "\n"
+ << variableName << " =";
+ std::string object;
+ const char* lineContinue =
+ this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
+ if(!lineContinue)
+ {
+ lineContinue = "\\";
+ }
+ for(std::vector<std::string>::const_iterator i = this->Objects.begin();
+ i != this->Objects.end(); ++i)
+ {
+ *this->BuildFileStream << " " << lineContinue << "\n";
+ *this->BuildFileStream <<
+ this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str(),
+ useWatcomQuote);
+ }
+ *this->BuildFileStream << "\n";
+
+ // Write a make variable assignment that lists all external objects
+ // for the target.
+ variableNameExternal =
+ this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
+ "_EXTERNAL_OBJECTS");
+ *this->BuildFileStream
+ << "\n"
+ << "# External object files for target "
+ << this->Target->GetName() << "\n"
+ << variableNameExternal << " =";
+ for(std::vector<std::string>::const_iterator i =
+ this->ExternalObjects.begin();
+ i != this->ExternalObjects.end(); ++i)
+ {
+ object = this->Convert(*i,cmLocalGenerator::START_OUTPUT);
+ *this->BuildFileStream
+ << " " << lineContinue << "\n"
+ << this->Makefile->GetSafeDefinition("CMAKE_OBJECT_NAME");
+ *this->BuildFileStream <<
+ this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str(),
+ useWatcomQuote);
+ }
+ *this->BuildFileStream << "\n" << "\n";
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::WriteObjectsString(std::string& buildObjs)
+{
+ std::vector<std::string> objStrings;
+ this->WriteObjectsStrings(objStrings);
+ buildObjs = objStrings[0];
+}
+
+//----------------------------------------------------------------------------
+class cmMakefileTargetGeneratorObjectStrings
+{
+public:
+ cmMakefileTargetGeneratorObjectStrings(std::vector<std::string>& strings,
+ cmLocalUnixMakefileGenerator3* lg,
+ std::string::size_type limit):
+ Strings(strings), LocalGenerator(lg), LengthLimit(limit)
+ {
+ this->Space = "";
+ }
+ void Feed(std::string const& obj)
+ {
+ // Construct the name of the next object.
+ this->NextObject =
+ this->LocalGenerator->Convert(obj,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::RESPONSE);
+
+ // Roll over to next string if the limit will be exceeded.
+ if(this->LengthLimit != std::string::npos &&
+ (this->CurrentString.length() + 1 + this->NextObject.length()
+ > this->LengthLimit))
+ {
+ this->Strings.push_back(this->CurrentString);
+ this->CurrentString = "";
+ this->Space = "";
+ }
+
+ // Separate from previous object.
+ this->CurrentString += this->Space;
+ this->Space = " ";
+
+ // Append this object.
+ this->CurrentString += this->NextObject;
+ }
+ void Done()
+ {
+ this->Strings.push_back(this->CurrentString);
+ }
+private:
+ std::vector<std::string>& Strings;
+ cmLocalUnixMakefileGenerator3* LocalGenerator;
+ std::string::size_type LengthLimit;
+ std::string CurrentString;
+ std::string NextObject;
+ const char* Space;
+};
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::WriteObjectsStrings(std::vector<std::string>& objStrings,
+ std::string::size_type limit)
+{
+ cmMakefileTargetGeneratorObjectStrings
+ helper(objStrings, this->LocalGenerator, limit);
+ for(std::vector<std::string>::const_iterator i = this->Objects.begin();
+ i != this->Objects.end(); ++i)
+ {
+ helper.Feed(*i);
+ }
+ for(std::vector<std::string>::const_iterator i =
+ this->ExternalObjects.begin();
+ i != this->ExternalObjects.end(); ++i)
+ {
+ helper.Feed(*i);
+ }
+ helper.Done();
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::WriteTargetDriverRule(
+ const std::string& main_output,
+ bool relink)
+{
+ // Compute the name of the driver target.
+ std::string dir =
+ this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+ std::string buildTargetRuleName = dir;
+ buildTargetRuleName += relink?"/preinstall":"/build";
+ buildTargetRuleName = this->Convert(buildTargetRuleName,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::UNCHANGED);
+
+ // Build the list of target outputs to drive.
+ std::vector<std::string> depends;
+ depends.push_back(main_output);
+
+ const char* comment = 0;
+ if(relink)
+ {
+ // Setup the comment for the preinstall driver.
+ comment = "Rule to relink during preinstall.";
+ }
+ else
+ {
+ // Setup the comment for the main build driver.
+ comment = "Rule to build all files generated by this target.";
+
+ // Make sure all custom command outputs in this target are built.
+ if(this->CustomCommandDriver == OnBuild)
+ {
+ this->DriveCustomCommands(depends);
+ }
+
+ // Make sure the extra files are built.
+ for(std::set<std::string>::const_iterator i = this->ExtraFiles.begin();
+ i != this->ExtraFiles.end(); ++i)
+ {
+ depends.push_back(*i);
+ }
+ }
+
+ // Write the driver rule.
+ std::vector<std::string> no_commands;
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
+ buildTargetRuleName,
+ depends, no_commands, true);
+}
+
+//----------------------------------------------------------------------------
+std::string cmMakefileTargetGenerator::GetFrameworkFlags(std::string const& l)
+{
+ if(!this->Makefile->IsOn("APPLE"))
+ {
+ return std::string();
+ }
+
+ std::string fwSearchFlagVar = "CMAKE_" + l + "_FRAMEWORK_SEARCH_FLAG";
+ const char* fwSearchFlag =
+ this->Makefile->GetDefinition(fwSearchFlagVar);
+ if(!(fwSearchFlag && *fwSearchFlag))
+ {
+ return std::string();
+ }
+
+ std::set<std::string> emitted;
+#ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */
+ emitted.insert("/System/Library/Frameworks");
+#endif
+ std::vector<std::string> includes;
+
+ const std::string& config =
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ this->LocalGenerator->GetIncludeDirectories(includes,
+ this->GeneratorTarget,
+ "C", config);
+ // check all include directories for frameworks as this
+ // will already have added a -F for the framework
+ for(std::vector<std::string>::iterator i = includes.begin();
+ i != includes.end(); ++i)
+ {
+ if(this->Target->NameResolvesToFramework(*i))
+ {
+ std::string frameworkDir = *i;
+ frameworkDir += "/../";
+ frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
+ emitted.insert(frameworkDir);
+ }
+ }
+
+ std::string flags;
+ const char* cfg = this->LocalGenerator->ConfigurationName.c_str();
+ if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg))
+ {
+ std::vector<std::string> const& frameworks = cli->GetFrameworkPaths();
+ for(std::vector<std::string>::const_iterator i = frameworks.begin();
+ i != frameworks.end(); ++i)
+ {
+ if(emitted.insert(*i).second)
+ {
+ flags += fwSearchFlag;
+ flags += this->Convert(*i,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL, true);
+ flags += " ";
+ }
+ }
+ }
+ return flags;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator
+::AppendTargetDepends(std::vector<std::string>& depends)
+{
+ // Static libraries never depend on anything for linking.
+ if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
+ {
+ return;
+ }
+
+ // Loop over all library dependencies.
+ const char* cfg = this->LocalGenerator->ConfigurationName.c_str();
+ if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg))
+ {
+ std::vector<std::string> const& libDeps = cli->GetDepends();
+ for(std::vector<std::string>::const_iterator j = libDeps.begin();
+ j != libDeps.end(); ++j)
+ {
+ depends.push_back(*j);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator
+::AppendObjectDepends(std::vector<std::string>& depends)
+{
+ // Add dependencies on the compiled object files.
+ std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
+ std::string objTarget;
+ for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
+ obj != this->Objects.end(); ++obj)
+ {
+ objTarget = relPath;
+ objTarget += *obj;
+ depends.push_back(objTarget);
+ }
+
+ // Add dependencies on the external object files.
+ for(std::vector<std::string>::const_iterator obj
+ = this->ExternalObjects.begin();
+ obj != this->ExternalObjects.end(); ++obj)
+ {
+ depends.push_back(*obj);
+ }
+
+ // Add a dependency on the rule file itself.
+ this->LocalGenerator->AppendRuleDepend(depends,
+ this->BuildFileNameFull.c_str());
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator
+::AppendLinkDepends(std::vector<std::string>& depends)
+{
+ this->AppendObjectDepends(depends);
+
+ // Add dependencies on targets that must be built first.
+ this->AppendTargetDepends(depends);
+
+ // Add a dependency on the link definitions file, if any.
+ std::string def = this->GeneratorTarget->GetModuleDefinitionFile(
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ if(!def.empty())
+ {
+ depends.push_back(def);
+ }
+
+ // Add user-specified dependencies.
+ if(const char* linkDepends =
+ this->Target->GetProperty("LINK_DEPENDS"))
+ {
+ cmSystemTools::ExpandListArgument(linkDepends, depends);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmMakefileTargetGenerator::GetLinkRule(
+ const std::string& linkRuleVar)
+{
+ std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
+ if(this->Target->HasImplibGNUtoMS())
+ {
+ std::string ruleVar = "CMAKE_";
+ ruleVar += this->Target->GetLinkerLanguage(this->ConfigName);
+ ruleVar += "_GNUtoMS_RULE";
+ if(const char* rule = this->Makefile->GetDefinition(ruleVar))
+ {
+ linkRule += rule;
+ }
+ }
+ return linkRule;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator
+::CloseFileStreams()
+{
+ delete this->BuildFileStream;
+ delete this->InfoFileStream;
+ delete this->FlagFileStream;
+}
+
+void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar,
+ const std::string& linkLang,
+ std::string& linkFlags)
+{
+ // check for language flags that are not allowed at link time, and
+ // remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
+ // which fails, there may be more]
+
+ std::string removeFlags = "CMAKE_";
+ removeFlags += linkLang;
+ removeFlags += flagVar;
+ std::string removeflags =
+ this->Makefile->GetSafeDefinition(removeFlags);
+ std::vector<std::string> removeList;
+ cmSystemTools::ExpandListArgument(removeflags, removeList);
+
+ for(std::vector<std::string>::iterator i = removeList.begin();
+ i != removeList.end(); ++i)
+ {
+ std::string tmp;
+ std::string::size_type lastPosition = 0;
+
+ for(;;)
+ {
+ std::string::size_type position = linkFlags.find(*i, lastPosition);
+
+ if(position == std::string::npos)
+ {
+ tmp += linkFlags.substr(lastPosition);
+ break;
+ }
+ else
+ {
+ std::string::size_type prefixLength = position - lastPosition;
+ tmp += linkFlags.substr(lastPosition, prefixLength);
+ lastPosition = position + i->length();
+
+ bool validFlagStart = position == 0 ||
+ isspace(linkFlags[position - 1]);
+
+ bool validFlagEnd = lastPosition == linkFlags.size() ||
+ isspace(linkFlags[lastPosition]);
+
+ if(!validFlagStart || !validFlagEnd)
+ {
+ tmp += *i;
+ }
+ }
+ }
+
+ linkFlags = tmp;
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::AddMultipleOutputPair(const char* depender, const char* dependee)
+{
+ MultipleOutputPairsType::value_type p(depender, dependee);
+ this->MultipleOutputPairs.insert(p);
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::CreateLinkScript(const char* name,
+ std::vector<std::string> const& link_commands,
+ std::vector<std::string>& makefile_commands,
+ std::vector<std::string>& makefile_depends)
+{
+ // Create the link script file.
+ std::string linkScriptName = this->TargetBuildDirectoryFull;
+ linkScriptName += "/";
+ linkScriptName += name;
+ cmGeneratedFileStream linkScriptStream(linkScriptName.c_str());
+ linkScriptStream.SetCopyIfDifferent(true);
+ for(std::vector<std::string>::const_iterator cmd = link_commands.begin();
+ cmd != link_commands.end(); ++cmd)
+ {
+ // Do not write out empty commands or commands beginning in the
+ // shell no-op ":".
+ if(!cmd->empty() && (*cmd)[0] != ':')
+ {
+ linkScriptStream << *cmd << "\n";
+ }
+ }
+
+ // Create the makefile command to invoke the link script.
+ std::string link_command = "$(CMAKE_COMMAND) -E cmake_link_script ";
+ link_command += this->Convert(linkScriptName,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ link_command += " --verbose=$(VERBOSE)";
+ makefile_commands.push_back(link_command);
+ makefile_depends.push_back(linkScriptName);
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmMakefileTargetGenerator
+::CreateResponseFile(const char* name, std::string const& options,
+ std::vector<std::string>& makefile_depends)
+{
+ // Create the response file.
+ std::string responseFileNameFull = this->TargetBuildDirectoryFull;
+ responseFileNameFull += "/";
+ responseFileNameFull += name;
+ cmGeneratedFileStream responseStream(responseFileNameFull.c_str());
+ responseStream.SetCopyIfDifferent(true);
+ responseStream << options << "\n";
+
+ // Add a dependency so the target will rebuild when the set of
+ // objects changes.
+ makefile_depends.push_back(responseFileNameFull);
+
+ // Construct the name to be used on the command line.
+ std::string responseFileName = this->TargetBuildDirectory;
+ responseFileName += "/";
+ responseFileName += name;
+ return responseFileName;
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::CreateLinkLibs(std::string& linkLibs, bool relink,
+ bool useResponseFile,
+ std::vector<std::string>& makefile_depends,
+ bool useWatcomQuote)
+{
+ std::string frameworkPath;
+ std::string linkPath;
+ this->LocalGenerator
+ ->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
+ *this->GeneratorTarget, relink,
+ useResponseFile,
+ useWatcomQuote);
+ linkLibs = frameworkPath + linkPath + linkLibs;
+
+ if(useResponseFile)
+ {
+ // Lookup the response file reference flag.
+ std::string responseFlagVar = "CMAKE_";
+ responseFlagVar += this->Target->GetLinkerLanguage(this->ConfigName);
+ responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
+ const char* responseFlag =
+ this->Makefile->GetDefinition(responseFlagVar);
+ if(!responseFlag)
+ {
+ responseFlag = "@";
+ }
+
+ // Create this response file.
+ std::string link_rsp =
+ this->CreateResponseFile("linklibs.rsp", linkLibs, makefile_depends);
+
+ // Reference the response file.
+ linkLibs = responseFlag;
+ linkLibs += this->Convert(link_rsp,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::CreateObjectLists(bool useLinkScript, bool useArchiveRules,
+ bool useResponseFile, std::string& buildObjs,
+ std::vector<std::string>& makefile_depends,
+ bool useWatcomQuote)
+{
+ std::string variableName;
+ std::string variableNameExternal;
+ this->WriteObjectsVariable(variableName, variableNameExternal,
+ useWatcomQuote);
+ if(useResponseFile)
+ {
+ // MSVC response files cannot exceed 128K.
+ std::string::size_type const responseFileLimit = 131000;
+
+ // Construct the individual object list strings.
+ std::vector<std::string> object_strings;
+ this->WriteObjectsStrings(object_strings, responseFileLimit);
+
+ // Lookup the response file reference flag.
+ std::string responseFlagVar = "CMAKE_";
+ responseFlagVar += this->Target->GetLinkerLanguage(this->ConfigName);
+ responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
+ const char* responseFlag =
+ this->Makefile->GetDefinition(responseFlagVar);
+ if(!responseFlag)
+ {
+ responseFlag = "@";
+ }
+
+ // Write a response file for each string.
+ const char* sep = "";
+ for(unsigned int i = 0; i < object_strings.size(); ++i)
+ {
+ // Number the response files.
+ char rsp[32];
+ sprintf(rsp, "objects%u.rsp", i+1);
+
+ // Create this response file.
+ std::string objects_rsp =
+ this->CreateResponseFile(rsp, object_strings[i], makefile_depends);
+
+ // Separate from previous response file references.
+ buildObjs += sep;
+ sep = " ";
+
+ // Reference the response file.
+ buildObjs += responseFlag;
+ buildObjs += this->Convert(objects_rsp,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ }
+ }
+ else if(useLinkScript)
+ {
+ if(!useArchiveRules)
+ {
+ this->WriteObjectsString(buildObjs);
+ }
+ }
+ else
+ {
+ buildObjs = "$(";
+ buildObjs += variableName;
+ buildObjs += ") $(";
+ buildObjs += variableNameExternal;
+ buildObjs += ")";
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
+ const std::string& lang)
+{
+ std::string responseVar = "CMAKE_";
+ responseVar += lang;
+ responseVar += "_USE_RESPONSE_FILE_FOR_INCLUDES";
+ bool useResponseFile = this->Makefile->IsOn(responseVar);
+
+
+ std::vector<std::string> includes;
+ const std::string& config =
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ this->LocalGenerator->GetIncludeDirectories(includes,
+ this->GeneratorTarget,
+ lang, config);
+
+ std::string includeFlags =
+ this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget,
+ lang, false, useResponseFile);
+ if(includeFlags.empty())
+ {
+ return;
+ }
+
+ if(useResponseFile)
+ {
+ std::string name = "includes_";
+ name += lang;
+ name += ".rsp";
+ std::string arg = "@" +
+ this->CreateResponseFile(name.c_str(), includeFlags,
+ this->FlagFileDepends[lang]);
+ this->LocalGenerator->AppendFlags(flags, arg);
+ }
+ else
+ {
+ this->LocalGenerator->AppendFlags(flags, includeFlags);
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmMakefileTargetGenerator::GetFortranModuleDirectory()
+{
+ // Compute the module directory.
+ if(!this->FortranModuleDirectoryComputed)
+ {
+ const char* target_mod_dir =
+ this->Target->GetProperty("Fortran_MODULE_DIRECTORY");
+ const char* moddir_flag =
+ this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
+ if(target_mod_dir && moddir_flag)
+ {
+ // Compute the full path to the module directory.
+ if(cmSystemTools::FileIsFullPath(target_mod_dir))
+ {
+ // Already a full path.
+ this->FortranModuleDirectory = target_mod_dir;
+ }
+ else
+ {
+ // Interpret relative to the current output directory.
+ this->FortranModuleDirectory =
+ this->Makefile->GetCurrentOutputDirectory();
+ this->FortranModuleDirectory += "/";
+ this->FortranModuleDirectory += target_mod_dir;
+ }
+
+ // Make sure the module output directory exists.
+ cmSystemTools::MakeDirectory(this->FortranModuleDirectory.c_str());
+ }
+ this->FortranModuleDirectoryComputed = true;
+ }
+
+ // Return the computed directory.
+ if(this->FortranModuleDirectory.empty())
+ {
+ return 0;
+ }
+ else
+ {
+ return this->FortranModuleDirectory.c_str();
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::AddFortranFlags(std::string& flags)
+{
+ // Enable module output if necessary.
+ if(const char* modout_flag =
+ this->Makefile->GetDefinition("CMAKE_Fortran_MODOUT_FLAG"))
+ {
+ this->LocalGenerator->AppendFlags(flags, modout_flag);
+ }
+
+ // Add a module output directory flag if necessary.
+ const char* mod_dir = this->GetFortranModuleDirectory();
+ if(!mod_dir)
+ {
+ mod_dir = this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_DEFAULT");
+ }
+ if(mod_dir)
+ {
+ const char* moddir_flag =
+ this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG");
+ std::string modflag = moddir_flag;
+ modflag += this->Convert(mod_dir,
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::SHELL);
+ this->LocalGenerator->AppendFlags(flags, modflag);
+ }
+
+ // If there is a separate module path flag then duplicate the
+ // include path with it. This compiler does not search the include
+ // path for modules.
+ if(const char* modpath_flag =
+ this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG"))
+ {
+ std::vector<std::string> includes;
+ const std::string& config =
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ this->LocalGenerator->GetIncludeDirectories(includes,
+ this->GeneratorTarget,
+ "C", config);
+ for(std::vector<std::string>::const_iterator idi = includes.begin();
+ idi != includes.end(); ++idi)
+ {
+ std::string flg = modpath_flag;
+ flg += this->Convert(*idi,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL);
+ this->LocalGenerator->AppendFlags(flags, flg);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
+{
+ std::string def = this->GeneratorTarget->GetModuleDefinitionFile(
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ if(def.empty())
+ {
+ return;
+ }
+
+ // TODO: Create a per-language flag variable.
+ const char* defFileFlag =
+ this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
+ if(!defFileFlag)
+ {
+ return;
+ }
+
+ // Append the flag and value. Use ConvertToLinkReference to help
+ // vs6's "cl -link" pass it to the linker.
+ std::string flag = defFileFlag;
+ flag += (this->LocalGenerator->ConvertToLinkReference(def));
+ this->LocalGenerator->AppendFlags(flags, flag);
+}
+
+//----------------------------------------------------------------------------
+const char* cmMakefileTargetGenerator::GetFeature(const std::string& feature)
+{
+ return this->Target->GetFeature(feature, this->ConfigName);
+}
+
+//----------------------------------------------------------------------------
+bool cmMakefileTargetGenerator::GetFeatureAsBool(const std::string& feature)
+{
+ return this->Target->GetFeatureAsBool(feature, this->ConfigName);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileTargetGenerator::AddFeatureFlags(
+ std::string& flags, const std::string& lang
+ )
+{
+ // Add language-specific flags.
+ this->LocalGenerator->AddLanguageFlags(flags, lang, this->ConfigName);
+
+ if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION"))
+ {
+ this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO");
+ }
+}
diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h
new file mode 100644
index 0000000000..9fac5746f4
--- /dev/null
+++ b/Source/cmMakefileTargetGenerator.h
@@ -0,0 +1,287 @@
+/*============================================================================
+ 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 cmMakefileTargetGenerator_h
+#define cmMakefileTargetGenerator_h
+
+#include "cmLocalUnixMakefileGenerator3.h"
+#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
+ * \brief Support Routines for writing makefiles
+ *
+ */
+class cmMakefileTargetGenerator
+{
+public:
+ // constructor to set the ivars
+ cmMakefileTargetGenerator(cmTarget* target);
+ virtual ~cmMakefileTargetGenerator();
+
+ // construct using this factory call
+ static cmMakefileTargetGenerator *New(cmGeneratorTarget *tgt);
+
+ /* the main entry point for this class. Writes the Makefiles associated
+ with this target */
+ virtual void WriteRuleFiles() = 0;
+
+ /* return the number of actions that have progress reporting on them */
+ virtual unsigned long GetNumberOfProgressActions() {
+ return this->NumberOfProgressActions;}
+ std::string GetProgressFileNameFull()
+ { return this->ProgressFileNameFull; }
+
+ cmTarget* GetTarget() { return this->Target;}
+
+protected:
+
+ // create the file and directory etc
+ void CreateRuleFile();
+
+ // outputs the rules for object files and custom commands used by
+ // this target
+ void WriteTargetBuildRules();
+
+ // write some common code at the top of build.make
+ void WriteCommonCodeRules();
+ void WriteTargetLanguageFlags();
+
+ // write the provide require rules for this target
+ void WriteTargetRequiresRules();
+
+ // write the clean rules for this target
+ void WriteTargetCleanRules();
+
+ // write the depend rules for this target
+ void WriteTargetDependRules();
+
+ // write rules for Mac OS X Application Bundle content.
+ struct MacOSXContentGeneratorType :
+ cmOSXBundleGenerator::MacOSXContentGeneratorType
+ {
+ MacOSXContentGeneratorType(cmMakefileTargetGenerator* gen) :
+ Generator(gen) {}
+
+ void operator()(cmSourceFile const& source, const char* pkgloc);
+
+ private:
+ cmMakefileTargetGenerator* Generator;
+ };
+ friend struct MacOSXContentGeneratorType;
+
+ // write the rules for an object
+ void WriteObjectRuleFiles(cmSourceFile const& source);
+
+ // write the build rule for an object
+ void WriteObjectBuildFile(std::string &obj,
+ const std::string& lang,
+ cmSourceFile const& source,
+ std::vector<std::string>& depends);
+
+ // write the depend.make file for an object
+ void WriteObjectDependRules(cmSourceFile const& source,
+ std::vector<std::string>& depends);
+
+ // write the build rule for a custom command
+ void GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg);
+
+ // write a rule to drive building of more than one output from
+ // another rule
+ void GenerateExtraOutput(const char* out, const char* in,
+ bool symbolic = false);
+
+ void AppendProgress(std::vector<std::string>& commands);
+
+ // write out the variable that lists the objects for this target
+ void WriteObjectsVariable(std::string& variableName,
+ std::string& variableNameExternal,
+ bool useWatcomQuote);
+ void WriteObjectsString(std::string& buildObjs);
+ void WriteObjectsStrings(std::vector<std::string>& objStrings,
+ std::string::size_type limit = std::string::npos);
+
+ // write the driver rule to build target outputs
+ void WriteTargetDriverRule(const std::string& main_output, bool relink);
+
+ void DriveCustomCommands(std::vector<std::string>& depends);
+
+ // Return the a string with -F flags on apple
+ std::string GetFrameworkFlags(std::string const& l);
+
+ void AppendFortranFormatFlags(std::string& flags,
+ cmSourceFile const& source);
+
+ // append intertarget dependencies
+ void AppendTargetDepends(std::vector<std::string>& depends);
+
+ // Append object file dependencies.
+ void AppendObjectDepends(std::vector<std::string>& depends);
+
+ // Append link rule dependencies (objects, etc.).
+ void AppendLinkDepends(std::vector<std::string>& depends);
+
+ // Lookup the link rule for this target.
+ std::string GetLinkRule(const std::string& linkRuleVar);
+
+ /** In order to support parallel builds for custom commands with
+ multiple outputs the outputs are given a serial order, and only
+ the first output actually has the build rule. Other outputs
+ just depend on the first one. The check-build-system step must
+ remove a dependee if the depender is missing to make sure both
+ are regenerated properly. This method is used by the local
+ makefile generators to register such pairs. */
+ void AddMultipleOutputPair(const char* depender, const char* dependee);
+
+ /** Create a script to hold link rules and a command to invoke the
+ script at build time. */
+ void CreateLinkScript(const char* name,
+ std::vector<std::string> const& link_commands,
+ std::vector<std::string>& makefile_commands,
+ std::vector<std::string>& makefile_depends);
+
+ /** Create a response file with the given set of options. Returns
+ the relative path from the target build working directory to the
+ response file name. */
+ std::string CreateResponseFile(const char* name,
+ std::string const& options,
+ std::vector<std::string>& makefile_depends);
+
+ /** Create list of flags for link libraries. */
+ void CreateLinkLibs(std::string& linkLibs, bool relink,
+ bool useResponseFile,
+ std::vector<std::string>& makefile_depends,
+ bool useWatcomQuote);
+
+ /** Create lists of object files for linking and cleaning. */
+ void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
+ bool useResponseFile, std::string& buildObjs,
+ std::vector<std::string>& makefile_depends,
+ bool useWatcomQuote);
+
+ void AddIncludeFlags(std::string& flags, const std::string& lang);
+
+ virtual void CloseFileStreams();
+ void RemoveForbiddenFlags(const char* flagVar, const std::string& linkLang,
+ std::string& linkFlags);
+ cmTarget *Target;
+ cmGeneratorTarget* GeneratorTarget;
+ cmLocalUnixMakefileGenerator3 *LocalGenerator;
+ cmGlobalUnixMakefileGenerator3 *GlobalGenerator;
+ cmMakefile *Makefile;
+ std::string ConfigName;
+
+ enum CustomCommandDriveType { OnBuild, OnDepends, OnUtility };
+ CustomCommandDriveType CustomCommandDriver;
+
+ // the full path to the build file
+ std::string BuildFileName;
+ std::string BuildFileNameFull;
+
+ // the full path to the progress file
+ std::string ProgressFileNameFull;
+ unsigned long NumberOfProgressActions;
+ bool NoRuleMessages;
+
+ // the path to the directory the build file is in
+ std::string TargetBuildDirectory;
+ std::string TargetBuildDirectoryFull;
+
+ // the stream for the build file
+ cmGeneratedFileStream *BuildFileStream;
+
+ // the stream for the flag file
+ std::string FlagFileNameFull;
+ cmGeneratedFileStream *FlagFileStream;
+ class StringList: public std::vector<std::string> {};
+ std::map<std::string, StringList> FlagFileDepends;
+
+ // the stream for the info file
+ std::string InfoFileNameFull;
+ cmGeneratedFileStream *InfoFileStream;
+
+ // files to clean
+ std::vector<std::string> CleanFiles;
+
+ // objects used by this target
+ std::vector<std::string> Objects;
+ std::vector<std::string> ExternalObjects;
+
+ // Set of object file names that will be built in this directory.
+ std::set<std::string> ObjectFiles;
+
+ // Set of extra output files to be driven by the build.
+ std::set<std::string> ExtraFiles;
+
+ typedef std::map<std::string, std::string> MultipleOutputPairsType;
+ MultipleOutputPairsType MultipleOutputPairs;
+
+ // Target name info.
+ std::string TargetNameOut;
+ std::string TargetNameSO;
+ std::string TargetNameReal;
+ std::string TargetNameImport;
+ std::string TargetNamePDB;
+
+ // Mac OS X content info.
+ std::set<std::string> MacContentFolders;
+ cmOSXBundleGenerator* OSXBundleGenerator;
+ MacOSXContentGeneratorType* MacOSXContentGenerator;
+
+ typedef std::map<std::string, std::string> ByLanguageMap;
+ std::string GetFlags(const std::string &l);
+ ByLanguageMap FlagsByLanguage;
+ std::string GetDefines(const std::string &l);
+ ByLanguageMap DefinesByLanguage;
+
+ // Target-wide Fortran module output directory.
+ bool FortranModuleDirectoryComputed;
+ std::string FortranModuleDirectory;
+ const char* GetFortranModuleDirectory();
+
+ // Compute target-specific Fortran language flags.
+ void AddFortranFlags(std::string& flags);
+
+ // Helper to add flag for windows .def file.
+ void AddModuleDefinitionFlag(std::string& flags);
+
+ // Add language feature flags.
+ void AddFeatureFlags(std::string& flags, const std::string& lang);
+
+ // Feature query methods.
+ const char* GetFeature(const std::string& feature);
+ bool GetFeatureAsBool(const std::string& feature);
+
+ //==================================================================
+ // Convenience routines that do nothing more than forward to
+ // implementaitons
+ std::string Convert(const std::string& source,
+ cmLocalGenerator::RelativeRoot relative,
+ cmLocalGenerator::OutputFormat output =
+ cmLocalGenerator::UNCHANGED,
+ bool optional = false)
+ {
+ return this->LocalGenerator->Convert(source, relative, output, optional);
+ }
+
+};
+
+#endif
diff --git a/Source/cmMakefileUtilityTargetGenerator.cxx b/Source/cmMakefileUtilityTargetGenerator.cxx
new file mode 100644
index 0000000000..617214fe47
--- /dev/null
+++ b/Source/cmMakefileUtilityTargetGenerator.cxx
@@ -0,0 +1,120 @@
+/*============================================================================
+ 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 "cmMakefileUtilityTargetGenerator.h"
+
+#include "cmGeneratedFileStream.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmTarget.h"
+
+//----------------------------------------------------------------------------
+cmMakefileUtilityTargetGenerator
+::cmMakefileUtilityTargetGenerator(cmGeneratorTarget* target):
+ cmMakefileTargetGenerator(target->Target)
+{
+ this->CustomCommandDriver = OnUtility;
+ this->OSXBundleGenerator = new cmOSXBundleGenerator(target,
+ this->ConfigName);
+ this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
+}
+
+//----------------------------------------------------------------------------
+cmMakefileUtilityTargetGenerator
+::~cmMakefileUtilityTargetGenerator()
+{
+ delete this->OSXBundleGenerator;
+}
+
+//----------------------------------------------------------------------------
+void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
+{
+ this->CreateRuleFile();
+
+ *this->BuildFileStream
+ << "# Utility rule file for " << this->Target->GetName() << ".\n\n";
+
+ if(!this->NoRuleMessages)
+ {
+ const char* root = (this->Makefile->IsOn("CMAKE_MAKE_INCLUDE_FROM_ROOT")?
+ "$(CMAKE_BINARY_DIR)/" : "");
+ // Include the progress variables for the target.
+ *this->BuildFileStream
+ << "# Include the progress variables for this target.\n"
+ << this->LocalGenerator->IncludeDirective << " " << root
+ << this->Convert(this->ProgressFileNameFull,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE)
+ << "\n\n";
+ }
+
+ // write the custom commands for this target
+ this->WriteTargetBuildRules();
+
+ // Collect the commands and dependencies.
+ std::vector<std::string> commands;
+ std::vector<std::string> depends;
+
+ // Utility targets store their rules in pre- and post-build commands.
+ this->LocalGenerator->AppendCustomDepends
+ (depends, this->Target->GetPreBuildCommands());
+
+ this->LocalGenerator->AppendCustomDepends
+ (depends, this->Target->GetPostBuildCommands());
+
+ this->LocalGenerator->AppendCustomCommands
+ (commands, this->Target->GetPreBuildCommands(), this->Target);
+
+ // Depend on all custom command outputs for sources
+ this->DriveCustomCommands(depends);
+
+ this->LocalGenerator->AppendCustomCommands
+ (commands, this->Target->GetPostBuildCommands(), this->Target);
+
+ // Add dependencies on targets that must be built first.
+ this->AppendTargetDepends(depends);
+
+ // Add a dependency on the rule file itself.
+ this->LocalGenerator->AppendRuleDepend(depends,
+ this->BuildFileNameFull.c_str());
+
+ // If the rule is empty add the special empty rule dependency needed
+ // by some make tools.
+ if(depends.empty() && commands.empty())
+ {
+ std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends();
+ if(!hack.empty())
+ {
+ depends.push_back(hack);
+ }
+ }
+
+ // Write the rule.
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+ this->Target->GetName(),
+ depends, commands, true);
+
+ // Write the main driver rule to build everything in this target.
+ this->WriteTargetDriverRule(this->Target->GetName(), false);
+
+ // Write clean target
+ this->WriteTargetCleanRules();
+
+ // Write the dependency generation rule. This must be done last so
+ // that multiple output pair information is available.
+ this->WriteTargetDependRules();
+
+ // close the streams
+ this->CloseFileStreams();
+}
+
diff --git a/Source/cmMakefileUtilityTargetGenerator.h b/Source/cmMakefileUtilityTargetGenerator.h
new file mode 100644
index 0000000000..8f99300521
--- /dev/null
+++ b/Source/cmMakefileUtilityTargetGenerator.h
@@ -0,0 +1,32 @@
+/*============================================================================
+ 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 cmMakefileUtilityTargetGenerator_h
+#define cmMakefileUtilityTargetGenerator_h
+
+#include "cmMakefileTargetGenerator.h"
+
+class cmMakefileUtilityTargetGenerator:
+ public cmMakefileTargetGenerator
+{
+public:
+ cmMakefileUtilityTargetGenerator(cmGeneratorTarget* target);
+ virtual ~cmMakefileUtilityTargetGenerator();
+
+ /* the main entry point for this class. Writes the Makefiles associated
+ with this target */
+ virtual void WriteRuleFiles();
+
+protected:
+
+};
+
+#endif
diff --git a/Source/cmMarkAsAdvancedCommand.cxx b/Source/cmMarkAsAdvancedCommand.cxx
new file mode 100644
index 0000000000..f6a2c26704
--- /dev/null
+++ b/Source/cmMarkAsAdvancedCommand.cxx
@@ -0,0 +1,62 @@
+/*============================================================================
+ 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 "cmMarkAsAdvancedCommand.h"
+
+// cmMarkAsAdvancedCommand
+bool cmMarkAsAdvancedCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ unsigned int i =0;
+ const char* value = "1";
+ bool overwrite = false;
+ if(args[0] == "CLEAR" || args[0] == "FORCE")
+ {
+ overwrite = true;
+ if(args[0] == "CLEAR")
+ {
+ value = "0";
+ }
+ i = 1;
+ }
+ for(; i < args.size(); ++i)
+ {
+ std::string variable = args[i];
+ cmCacheManager* manager = this->Makefile->GetCacheManager();
+ cmCacheManager::CacheIterator it =
+ manager->GetCacheIterator(variable.c_str());
+ if ( it.IsAtEnd() )
+ {
+ this->Makefile->GetCacheManager()
+ ->AddCacheEntry(variable, 0, 0,
+ cmCacheManager::UNINITIALIZED);
+ overwrite = true;
+ }
+ it.Find(variable);
+ if ( it.IsAtEnd() )
+ {
+ cmSystemTools::Error("This should never happen...");
+ return false;
+ }
+ if ( !it.PropertyExists("ADVANCED") || overwrite )
+ {
+ it.SetProperty("ADVANCED", value);
+ }
+ }
+ return true;
+}
+
diff --git a/Source/cmMarkAsAdvancedCommand.h b/Source/cmMarkAsAdvancedCommand.h
new file mode 100644
index 0000000000..38064a326a
--- /dev/null
+++ b/Source/cmMarkAsAdvancedCommand.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 cmMarkAsAdvancedCommand_h
+#define cmMarkAsAdvancedCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmMarkAsAdvancedCommand
+ * \brief mark_as_advanced command
+ *
+ * cmMarkAsAdvancedCommand implements the mark_as_advanced CMake command
+ */
+class cmMarkAsAdvancedCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmMarkAsAdvancedCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "mark_as_advanced";}
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ * mark_as_advanced() will have no effect in script mode, but this will
+ * make many of the modules usable in cmake/ctest scripts, (among them
+ * FindUnixMake.cmake used by the CTEST_BUILD command.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ cmTypeMacro(cmMarkAsAdvancedCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmMathCommand.cxx b/Source/cmMathCommand.cxx
new file mode 100644
index 0000000000..f1942c546e
--- /dev/null
+++ b/Source/cmMathCommand.cxx
@@ -0,0 +1,61 @@
+/*============================================================================
+ 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 "cmMathCommand.h"
+
+#include "cmExprParserHelper.h"
+
+//----------------------------------------------------------------------------
+bool cmMathCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if ( args.size() < 1 )
+ {
+ this->SetError("must be called with at least one argument.");
+ return false;
+ }
+ const std::string &subCommand = args[0];
+ if(subCommand == "EXPR")
+ {
+ return this->HandleExprCommand(args);
+ }
+ std::string e = "does not recognize sub-command "+subCommand;
+ this->SetError(e);
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args)
+{
+ if ( args.size() != 3 )
+ {
+ this->SetError("EXPR called with incorrect arguments.");
+ return false;
+ }
+
+ const std::string& outputVariable = args[1];
+ const std::string& expression = args[2];
+
+ cmExprParserHelper helper;
+ if ( !helper.ParseString(expression.c_str(), 0) )
+ {
+ std::string e = "cannot parse the expression: \""+expression+"\": ";
+ e += helper.GetError();
+ this->SetError(e);
+ return false;
+ }
+
+ char buffer[1024];
+ sprintf(buffer, "%d", helper.GetResult());
+
+ this->Makefile->AddDefinition(outputVariable, buffer);
+ return true;
+}
diff --git a/Source/cmMathCommand.h b/Source/cmMathCommand.h
new file mode 100644
index 0000000000..76dc102bd7
--- /dev/null
+++ b/Source/cmMathCommand.h
@@ -0,0 +1,54 @@
+/*============================================================================
+ 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 cmMathCommand_h
+#define cmMathCommand_h
+
+#include "cmCommand.h"
+
+/// Mathematical expressions: math(EXPR ...) command.
+class cmMathCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmMathCommand;
+ }
+
+ /**
+ * 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 "math";}
+
+ cmTypeMacro(cmMathCommand, cmCommand);
+protected:
+
+ bool HandleExprCommand(std::vector<std::string> const& args);
+};
+
+
+#endif
+
diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx
new file mode 100644
index 0000000000..88d6a771b3
--- /dev/null
+++ b/Source/cmMessageCommand.cxx
@@ -0,0 +1,99 @@
+/*============================================================================
+ 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 "cmMessageCommand.h"
+
+// cmLibraryCommand
+bool cmMessageCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ std::string message;
+ std::vector<std::string>::const_iterator i = args.begin();
+
+ cmake::MessageType type = cmake::MESSAGE;
+ bool status = false;
+ bool fatal = false;
+ if (*i == "SEND_ERROR")
+ {
+ type = cmake::FATAL_ERROR;
+ ++i;
+ }
+ else if (*i == "FATAL_ERROR")
+ {
+ fatal = true;
+ type = cmake::FATAL_ERROR;
+ ++i;
+ }
+ else if (*i == "WARNING")
+ {
+ type = cmake::WARNING;
+ ++i;
+ }
+ else if (*i == "AUTHOR_WARNING")
+ {
+ type = cmake::AUTHOR_WARNING;
+ ++i;
+ }
+ else if (*i == "STATUS")
+ {
+ status = true;
+ ++i;
+ }
+ else if (*i == "DEPRECATION")
+ {
+ if (this->Makefile->IsOn("CMAKE_ERROR_DEPRECATED"))
+ {
+ fatal = true;
+ type = cmake::DEPRECATION_ERROR;
+ }
+ else if (this->Makefile->IsOn("CMAKE_WARN_DEPRECATED"))
+ {
+ type = cmake::DEPRECATION_WARNING;
+ }
+ else
+ {
+ return true;
+ }
+ ++i;
+ }
+
+ for(;i != args.end(); ++i)
+ {
+ message += *i;
+ }
+
+ if (type != cmake::MESSAGE)
+ {
+ this->Makefile->IssueMessage(type, message);
+ }
+ else
+ {
+ if (status)
+ {
+ this->Makefile->DisplayStatus(message.c_str(), -1);
+ }
+ else
+ {
+ cmSystemTools::Message(message.c_str());
+ }
+ }
+ if(fatal)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ }
+ return true;
+}
+
diff --git a/Source/cmMessageCommand.h b/Source/cmMessageCommand.h
new file mode 100644
index 0000000000..c0ae2a3225
--- /dev/null
+++ b/Source/cmMessageCommand.h
@@ -0,0 +1,53 @@
+/*============================================================================
+ 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 cmMessageCommand_h
+#define cmMessageCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmMessageCommand
+ * \brief Displays a message to the user
+ *
+ */
+class cmMessageCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmMessageCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "message";}
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ cmTypeMacro(cmMessageCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmNewLineStyle.cxx b/Source/cmNewLineStyle.cxx
new file mode 100644
index 0000000000..08f0b5b092
--- /dev/null
+++ b/Source/cmNewLineStyle.cxx
@@ -0,0 +1,93 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 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 "cmNewLineStyle.h"
+
+
+
+cmNewLineStyle::cmNewLineStyle() : NewLineStyle(Invalid)
+{
+}
+
+
+bool cmNewLineStyle::IsValid() const
+{
+ return NewLineStyle != Invalid;
+}
+
+
+bool cmNewLineStyle::ReadFromArguments(const std::vector<std::string>& args,
+ std::string& errorString)
+{
+ NewLineStyle = Invalid;
+
+ for (size_t i = 0; i< args.size(); i++)
+ {
+ if (args[i] == "NEWLINE_STYLE")
+ {
+ size_t const styleIndex = i + 1;
+ if (args.size() > styleIndex)
+ {
+ const std::string eol = args[styleIndex];
+ if (eol == "LF" || eol == "UNIX")
+ {
+ NewLineStyle = LF;
+ return true;
+ }
+ else if (eol == "CRLF" || eol == "WIN32" || eol == "DOS")
+ {
+ NewLineStyle = CRLF;
+ return true;
+ }
+ else
+ {
+ errorString = "NEWLINE_STYLE sets an unknown style, only LF, "
+ "CRLF, UNIX, DOS, and WIN32 are supported";
+ return false;
+ }
+ }
+ else
+ {
+ errorString = "NEWLINE_STYLE must set a style: "
+ "LF, CRLF, UNIX, DOS, or WIN32";
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+
+const std::string cmNewLineStyle::GetCharacters() const
+{
+ switch (NewLineStyle)
+ {
+ case Invalid:
+ return "";
+ case LF:
+ return "\n";
+ case CRLF:
+ return "\r\n";
+ }
+ return "";
+}
+
+
+void cmNewLineStyle::SetStyle(Style style)
+{
+ NewLineStyle = style;
+}
+
+
+cmNewLineStyle::Style cmNewLineStyle::GetStyle() const
+{
+ return NewLineStyle;
+}
diff --git a/Source/cmNewLineStyle.h b/Source/cmNewLineStyle.h
new file mode 100644
index 0000000000..cae1106043
--- /dev/null
+++ b/Source/cmNewLineStyle.h
@@ -0,0 +1,46 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 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 cmNewLineStyle_h
+#define cmNewLineStyle_h
+
+#include "cmStandardIncludes.h"
+
+class cmNewLineStyle
+{
+public:
+
+ cmNewLineStyle();
+
+ enum Style
+ {
+ Invalid,
+ // LF = '\n', 0x0A, 10
+ // CR = '\r', 0x0D, 13
+ LF, // Unix
+ CRLF // Dos
+ };
+
+ void SetStyle(Style);
+ Style GetStyle() const;
+
+ bool IsValid() const;
+
+ bool ReadFromArguments(const std::vector<std::string>& args,
+ std::string &errorString);
+
+ const std::string GetCharacters() const;
+
+private:
+ Style NewLineStyle;
+};
+
+#endif
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
new file mode 100644
index 0000000000..e344df4f32
--- /dev/null
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -0,0 +1,693 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 "cmNinjaNormalTargetGenerator.h"
+#include "cmLocalNinjaGenerator.h"
+#include "cmGlobalNinjaGenerator.h"
+#include "cmSourceFile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmMakefile.h"
+#include "cmOSXBundleGenerator.h"
+#include "cmGeneratorTarget.h"
+#include "cmCustomCommandGenerator.h"
+
+#include <assert.h>
+#include <algorithm>
+
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
+
+cmNinjaNormalTargetGenerator::
+cmNinjaNormalTargetGenerator(cmGeneratorTarget* target)
+ : cmNinjaTargetGenerator(target->Target)
+ , TargetNameOut()
+ , TargetNameSO()
+ , TargetNameReal()
+ , TargetNameImport()
+ , TargetNamePDB()
+ , TargetLinkLanguage("")
+{
+ this->TargetLinkLanguage = target->Target
+ ->GetLinkerLanguage(this->GetConfigName());
+ if (target->GetType() == cmTarget::EXECUTABLE)
+ target->Target->GetExecutableNames(this->TargetNameOut,
+ this->TargetNameReal,
+ this->TargetNameImport,
+ this->TargetNamePDB,
+ GetLocalGenerator()->GetConfigName());
+ else
+ target->Target->GetLibraryNames(this->TargetNameOut,
+ this->TargetNameSO,
+ this->TargetNameReal,
+ this->TargetNameImport,
+ this->TargetNamePDB,
+ GetLocalGenerator()->GetConfigName());
+
+ if(target->GetType() != cmTarget::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()));
+ }
+
+ this->OSXBundleGenerator = new cmOSXBundleGenerator(target,
+ this->GetConfigName());
+ this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
+}
+
+cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator()
+{
+ delete this->OSXBundleGenerator;
+}
+
+void cmNinjaNormalTargetGenerator::Generate()
+{
+ if (this->TargetLinkLanguage.empty()) {
+ cmSystemTools::Error("CMake can not determine linker language for "
+ "target: ",
+ this->GetTarget()->GetName().c_str());
+ return;
+ }
+
+ // Write the rules for each language.
+ this->WriteLanguagesRules();
+
+ // Write the build statements
+ this->WriteObjectBuildStatements();
+
+ if(this->GetTarget()->GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ this->WriteObjectLibStatement();
+ }
+ else
+ {
+ this->WriteLinkRule(false); // write rule without rspfile support
+ this->WriteLinkRule(true); // write rule with rspfile support
+ this->WriteLinkStatement();
+ }
+}
+
+void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
+{
+#ifdef NINJA_GEN_VERBOSE_FILES
+ cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream());
+ this->GetRulesFileStream()
+ << "# Rules for each languages for "
+ << cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
+ << " target "
+ << this->GetTargetName()
+ << "\n\n";
+#endif
+
+ std::set<std::string> languages;
+ this->GetTarget()->GetLanguages(languages,
+ this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ for(std::set<std::string>::const_iterator l = languages.begin();
+ l != languages.end();
+ ++l)
+ this->WriteLanguageRules(*l);
+}
+
+const char *cmNinjaNormalTargetGenerator::GetVisibleTypeName() const
+{
+ switch (this->GetTarget()->GetType()) {
+ case cmTarget::STATIC_LIBRARY:
+ return "static library";
+ case cmTarget::SHARED_LIBRARY:
+ return "shared library";
+ case cmTarget::MODULE_LIBRARY:
+ if (this->GetTarget()->IsCFBundleOnApple())
+ return "CFBundle shared module";
+ else
+ return "shared module";
+ case cmTarget::EXECUTABLE:
+ return "executable";
+ default:
+ return 0;
+ }
+}
+
+std::string
+cmNinjaNormalTargetGenerator
+::LanguageLinkerRule() const
+{
+ return this->TargetLinkLanguage
+ + "_"
+ + cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
+ + "_LINKER";
+}
+
+void
+cmNinjaNormalTargetGenerator
+::WriteLinkRule(bool useResponseFile)
+{
+ cmTarget::TargetType targetType = this->GetTarget()->GetType();
+ std::string ruleName = this->LanguageLinkerRule();
+ if (useResponseFile)
+ ruleName += "_RSP_FILE";
+
+ // Select whether to use a response file for objects.
+ std::string rspfile;
+ std::string rspcontent;
+
+ if (!this->GetGlobalGenerator()->HasRule(ruleName)) {
+ cmLocalGenerator::RuleVariables vars;
+ vars.RuleLauncher = "RULE_LAUNCH_LINK";
+ vars.CMTarget = this->GetTarget();
+ vars.Language = this->TargetLinkLanguage.c_str();
+
+ std::string responseFlag;
+ if (!useResponseFile) {
+ vars.Objects = "$in";
+ vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES";
+ } else {
+ std::string cmakeVarLang = "CMAKE_";
+ cmakeVarLang += this->TargetLinkLanguage;
+
+ // build response file name
+ std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG";
+ const char * flag = GetMakefile()->GetDefinition(cmakeLinkVar);
+ if(flag) {
+ responseFlag = flag;
+ } else {
+ responseFlag = "@";
+ }
+ rspfile = "$RSP_FILE";
+ responseFlag += rspfile;
+
+ // build response file content
+ rspcontent = "$in_newline $LINK_PATH $LINK_LIBRARIES";
+ vars.Objects = responseFlag.c_str();
+ vars.LinkLibraries = "";
+ }
+
+ vars.ObjectDir = "$OBJECT_DIR";
+
+ // TODO:
+ // Makefile generator expands <TARGET> to the plain target name
+ // with suffix. $out expands to a relative path. This difference
+ // could make trouble when switching to Ninja generator. Maybe
+ // using TARGET_NAME and RuleVariables::TargetName is a fix.
+ vars.Target = "$out";
+
+ vars.SONameFlag = "$SONAME_FLAG";
+ vars.TargetSOName = "$SONAME";
+ vars.TargetInstallNameDir = "$INSTALLNAME_DIR";
+ vars.TargetPDB = "$TARGET_PDB";
+
+ // Setup the target version.
+ std::string targetVersionMajor;
+ std::string targetVersionMinor;
+ {
+ cmOStringStream majorStream;
+ cmOStringStream minorStream;
+ int major;
+ int minor;
+ this->GetTarget()->GetTargetVersion(major, minor);
+ majorStream << major;
+ minorStream << minor;
+ targetVersionMajor = majorStream.str();
+ targetVersionMinor = minorStream.str();
+ }
+ vars.TargetVersionMajor = targetVersionMajor.c_str();
+ vars.TargetVersionMinor = targetVersionMinor.c_str();
+
+ vars.Flags = "$FLAGS";
+ vars.LinkFlags = "$LINK_FLAGS";
+
+ std::string langFlags;
+ if (targetType != cmTarget::EXECUTABLE)
+ {
+ langFlags += "$LANGUAGE_COMPILE_FLAGS $ARCH_FLAGS";
+ vars.LanguageCompileFlags = langFlags.c_str();
+ }
+
+ // Rule for linking library/executable.
+ std::vector<std::string> linkCmds = this->ComputeLinkCmd();
+ for(std::vector<std::string>::iterator i = linkCmds.begin();
+ i != linkCmds.end();
+ ++i)
+ {
+ this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
+ }
+ linkCmds.insert(linkCmds.begin(), "$PRE_LINK");
+ linkCmds.push_back("$POST_BUILD");
+ std::string linkCmd =
+ this->GetLocalGenerator()->BuildCommandLine(linkCmds);
+
+ // Write the linker rule with response file if needed.
+ cmOStringStream comment;
+ comment << "Rule for linking " << this->TargetLinkLanguage << " "
+ << this->GetVisibleTypeName() << ".";
+ cmOStringStream description;
+ description << "Linking " << this->TargetLinkLanguage << " "
+ << this->GetVisibleTypeName() << " $out";
+ this->GetGlobalGenerator()->AddRule(ruleName,
+ linkCmd,
+ description.str(),
+ comment.str(),
+ /*depfile*/ "",
+ /*deptype*/ "",
+ rspfile,
+ rspcontent,
+ /*restat*/ false,
+ /*generator*/ false);
+ }
+
+ if (this->TargetNameOut != this->TargetNameReal &&
+ !this->GetTarget()->IsFrameworkOnApple()) {
+ std::string cmakeCommand =
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ this->GetMakefile()->GetRequiredDefinition("CMAKE_COMMAND"),
+ cmLocalGenerator::SHELL);
+ if (targetType == cmTarget::EXECUTABLE)
+ this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_EXECUTABLE",
+ cmakeCommand +
+ " -E cmake_symlink_executable"
+ " $in $out && $POST_BUILD",
+ "Creating executable symlink $out",
+ "Rule for creating "
+ "executable symlink.",
+ /*depfile*/ "",
+ /*deptype*/ "",
+ /*rspfile*/ "",
+ /*rspcontent*/ "",
+ /*restat*/ false,
+ /*generator*/ false);
+ else
+ this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_LIBRARY",
+ cmakeCommand +
+ " -E cmake_symlink_library"
+ " $in $SONAME $out && $POST_BUILD",
+ "Creating library symlink $out",
+ "Rule for creating "
+ "library symlink.",
+ /*depfile*/ "",
+ /*deptype*/ "",
+ /*rspfile*/ "",
+ /*rspcontent*/ "",
+ /*restat*/ false,
+ /*generator*/ false);
+ }
+}
+
+std::vector<std::string>
+cmNinjaNormalTargetGenerator
+::ComputeLinkCmd()
+{
+ std::vector<std::string> linkCmds;
+ cmMakefile* mf = this->GetMakefile();
+ {
+ std::string linkCmdVar = this->GetGeneratorTarget()
+ ->GetCreateRuleVariable(this->TargetLinkLanguage, this->GetConfigName());
+ const char *linkCmd = mf->GetDefinition(linkCmdVar);
+ if (linkCmd)
+ {
+ cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
+ return linkCmds;
+ }
+ }
+ switch (this->GetTarget()->GetType()) {
+ case cmTarget::STATIC_LIBRARY: {
+ // We have archive link commands set. First, delete the existing archive.
+ {
+ std::string cmakeCommand =
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ mf->GetRequiredDefinition("CMAKE_COMMAND"),
+ cmLocalGenerator::SHELL);
+ linkCmds.push_back(cmakeCommand + " -E remove $out");
+ }
+ // TODO: Use ARCHIVE_APPEND for archives over a certain size.
+ {
+ std::string linkCmdVar = "CMAKE_";
+ linkCmdVar += this->TargetLinkLanguage;
+ linkCmdVar += "_ARCHIVE_CREATE";
+ const char *linkCmd = mf->GetRequiredDefinition(linkCmdVar);
+ cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
+ }
+ {
+ std::string linkCmdVar = "CMAKE_";
+ linkCmdVar += this->TargetLinkLanguage;
+ linkCmdVar += "_ARCHIVE_FINISH";
+ const char *linkCmd = mf->GetRequiredDefinition(linkCmdVar);
+ cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
+ }
+ return linkCmds;
+ }
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ case cmTarget::EXECUTABLE:
+ break;
+ default:
+ assert(0 && "Unexpected target type");
+ }
+ return std::vector<std::string>();
+}
+
+
+static int calculateCommandLineLengthLimit(int linkRuleLength)
+{
+#ifdef _WIN32
+ return 8000 - linkRuleLength;
+#elif defined(__linux) || defined(__APPLE__) || defined(__HAIKU__)
+ // for instance ARG_MAX is 2096152 on Ubuntu or 262144 on Mac
+ return ((int)sysconf(_SC_ARG_MAX)) - linkRuleLength - 1000;
+#else
+ (void)linkRuleLength;
+ return -1;
+#endif
+}
+
+
+void cmNinjaNormalTargetGenerator::WriteLinkStatement()
+{
+ cmTarget& target = *this->GetTarget();
+ const std::string cfgName = this->GetConfigName();
+ std::string targetOutput = ConvertToNinjaPath(
+ target.GetFullPath(cfgName).c_str());
+ std::string targetOutputReal = ConvertToNinjaPath(
+ target.GetFullPath(cfgName,
+ /*implib=*/false,
+ /*realpath=*/true).c_str());
+ std::string targetOutputImplib = ConvertToNinjaPath(
+ target.GetFullPath(cfgName,
+ /*implib=*/true).c_str());
+
+ if (target.IsAppBundleOnApple())
+ {
+ // Create the app bundle
+ std::string outpath = target.GetDirectory(cfgName);
+ this->OSXBundleGenerator->CreateAppBundle(this->TargetNameOut, outpath);
+
+ // Calculate the output path
+ targetOutput = outpath;
+ targetOutput += "/";
+ targetOutput += this->TargetNameOut;
+ targetOutput = this->ConvertToNinjaPath(targetOutput.c_str());
+ targetOutputReal = outpath;
+ targetOutputReal += "/";
+ targetOutputReal += this->TargetNameReal;
+ targetOutputReal = this->ConvertToNinjaPath(targetOutputReal.c_str());
+ }
+ else if (target.IsFrameworkOnApple())
+ {
+ // Create the library framework.
+ this->OSXBundleGenerator->CreateFramework(this->TargetNameOut,
+ target.GetDirectory(cfgName));
+ }
+ else if(target.IsCFBundleOnApple())
+ {
+ // Create the core foundation bundle.
+ this->OSXBundleGenerator->CreateCFBundle(this->TargetNameOut,
+ target.GetDirectory(cfgName));
+ }
+
+ // Write comments.
+ cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
+ const cmTarget::TargetType targetType = target.GetType();
+ this->GetBuildFileStream()
+ << "# Link build statements for "
+ << cmTarget::GetTargetTypeName(targetType)
+ << " target "
+ << this->GetTargetName()
+ << "\n\n";
+
+ cmNinjaDeps emptyDeps;
+ cmNinjaVars vars;
+
+ // Compute the comment.
+ cmOStringStream comment;
+ comment <<
+ "Link the " << this->GetVisibleTypeName() << " " << targetOutputReal;
+
+ // Compute outputs.
+ cmNinjaDeps outputs;
+ outputs.push_back(targetOutputReal);
+
+ // Compute specific libraries to link with.
+ cmNinjaDeps explicitDeps = this->GetObjects();
+ cmNinjaDeps implicitDeps = this->ComputeLinkDeps();
+
+ cmMakefile* mf = this->GetMakefile();
+
+ std::string frameworkPath;
+ std::string linkPath;
+ cmGeneratorTarget& genTarget = *this->GetGeneratorTarget();
+
+ std::string createRule =
+ genTarget.GetCreateRuleVariable(this->TargetLinkLanguage,
+ this->GetConfigName());
+ bool useWatcomQuote = mf->IsOn(createRule+"_USE_WATCOM_QUOTE");
+ cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
+ localGen.GetTargetFlags(vars["LINK_LIBRARIES"],
+ vars["FLAGS"],
+ vars["LINK_FLAGS"],
+ frameworkPath,
+ linkPath,
+ &genTarget,
+ useWatcomQuote);
+
+ this->addPoolNinjaVariable("JOB_POOL_LINK", &target, vars);
+
+ this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]);
+ vars["LINK_FLAGS"] = cmGlobalNinjaGenerator
+ ::EncodeLiteral(vars["LINK_FLAGS"]);
+
+ vars["LINK_PATH"] = frameworkPath + linkPath;
+
+ // 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)
+ {
+ std::string t = vars["FLAGS"];
+ localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName);
+ vars["FLAGS"] = t;
+ }
+ else
+ {
+ std::string t = vars["ARCH_FLAGS"];
+ localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName);
+ vars["ARCH_FLAGS"] = t;
+ t = "";
+ localGen.AddLanguageFlags(t, TargetLinkLanguage, cfgName);
+ vars["LANGUAGE_COMPILE_FLAGS"] = t;
+ }
+
+ if (target.HasSOName(cfgName))
+ {
+ vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage);
+ vars["SONAME"] = this->TargetNameSO;
+ if (targetType == cmTarget::SHARED_LIBRARY)
+ {
+ std::string install_dir = target.GetInstallNameDirForBuildTree(cfgName);
+ if (!install_dir.empty())
+ {
+ vars["INSTALLNAME_DIR"] = localGen.Convert(install_dir,
+ cmLocalGenerator::NONE,
+ cmLocalGenerator::SHELL,
+ false);
+ }
+ }
+ }
+
+ if (!this->TargetNameImport.empty())
+ {
+ const std::string impLibPath = localGen.ConvertToOutputFormat(
+ targetOutputImplib,
+ cmLocalGenerator::SHELL);
+ vars["TARGET_IMPLIB"] = impLibPath;
+ EnsureParentDirectoryExists(impLibPath);
+ }
+
+ if (!this->SetMsvcTargetPdbVariable(vars))
+ {
+ // It is common to place debug symbols at a specific place,
+ // so we need a plain target name in the rule available.
+ std::string prefix;
+ std::string base;
+ std::string suffix;
+ target.GetFullNameComponents(prefix, base, suffix);
+ std::string dbg_suffix = ".dbg";
+ // TODO: Where to document?
+ if (mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX"))
+ {
+ dbg_suffix = mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX");
+ }
+ vars["TARGET_PDB"] = base + suffix + dbg_suffix;
+ }
+
+ if (mf->IsOn("CMAKE_COMPILER_IS_MINGW"))
+ {
+ const std::string objPath = GetTarget()->GetSupportDirectory();
+ vars["OBJECT_DIR"] = ConvertToNinjaPath(objPath.c_str());
+ EnsureDirectoryExists(objPath);
+ // ar.exe can't handle backslashes in rsp files (implicitly used by gcc)
+ std::string& linkLibraries = vars["LINK_LIBRARIES"];
+ std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/');
+ std::string& link_path = vars["LINK_PATH"];
+ std::replace(link_path.begin(), link_path.end(), '\\', '/');
+ }
+
+ const std::vector<cmCustomCommand> *cmdLists[3] = {
+ &target.GetPreBuildCommands(),
+ &target.GetPreLinkCommands(),
+ &target.GetPostBuildCommands()
+ };
+
+ std::vector<std::string> preLinkCmdLines, postBuildCmdLines;
+ std::vector<std::string> *cmdLineLists[3] = {
+ &preLinkCmdLines,
+ &preLinkCmdLines,
+ &postBuildCmdLines
+ };
+
+ for (unsigned i = 0; i != 3; ++i)
+ {
+ for (std::vector<cmCustomCommand>::const_iterator
+ ci = cmdLists[i]->begin();
+ ci != cmdLists[i]->end(); ++ci)
+ {
+ cmCustomCommandGenerator ccg(*ci, cfgName, mf);
+ localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
+ }
+ }
+
+ // If we have any PRE_LINK commands, we need to go back to HOME_OUTPUT for
+ // the link commands.
+ if (!preLinkCmdLines.empty())
+ {
+ const std::string homeOutDir = localGen.ConvertToOutputFormat(
+ mf->GetHomeOutputDirectory(),
+ cmLocalGenerator::SHELL);
+ preLinkCmdLines.push_back("cd " + homeOutDir);
+ }
+
+ vars["PRE_LINK"] = localGen.BuildCommandLine(preLinkCmdLines);
+ std::string postBuildCmdLine = localGen.BuildCommandLine(postBuildCmdLines);
+
+ cmNinjaVars symlinkVars;
+ if (targetOutput == targetOutputReal)
+ {
+ vars["POST_BUILD"] = postBuildCmdLine;
+ }
+ else
+ {
+ vars["POST_BUILD"] = ":";
+ symlinkVars["POST_BUILD"] = postBuildCmdLine;
+ }
+
+ cmGlobalNinjaGenerator& globalGen = *this->GetGlobalGenerator();
+
+ int commandLineLengthLimit = 1;
+ const char* forceRspFile = "CMAKE_NINJA_FORCE_RESPONSE_FILE";
+ if (!mf->IsDefinitionSet(forceRspFile) &&
+ cmSystemTools::GetEnv(forceRspFile) == 0)
+ {
+ commandLineLengthLimit = calculateCommandLineLengthLimit(
+ globalGen.GetRuleCmdLength(this->LanguageLinkerRule()));
+ }
+
+ const std::string rspfile =
+ std::string(cmake::GetCMakeFilesDirectoryPostSlash())
+ + target.GetName() + ".rsp";
+
+ // Gather order-only dependencies.
+ cmNinjaDeps orderOnlyDeps;
+ this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(),
+ orderOnlyDeps);
+
+ // Write the build statement for this target.
+ globalGen.WriteBuild(this->GetBuildFileStream(),
+ comment.str(),
+ this->LanguageLinkerRule(),
+ outputs,
+ explicitDeps,
+ implicitDeps,
+ orderOnlyDeps,
+ vars,
+ rspfile,
+ commandLineLengthLimit);
+
+ if (targetOutput != targetOutputReal && !target.IsFrameworkOnApple())
+ {
+ if (targetType == cmTarget::EXECUTABLE)
+ {
+ globalGen.WriteBuild(this->GetBuildFileStream(),
+ "Create executable symlink " + targetOutput,
+ "CMAKE_SYMLINK_EXECUTABLE",
+ cmNinjaDeps(1, targetOutput),
+ cmNinjaDeps(1, targetOutputReal),
+ emptyDeps,
+ emptyDeps,
+ symlinkVars);
+ }
+ else
+ {
+ cmNinjaDeps symlinks;
+ const std::string soName = this->GetTargetFilePath(this->TargetNameSO);
+ // If one link has to be created.
+ if (targetOutputReal == soName || targetOutput == soName)
+ {
+ symlinkVars["SONAME"] = soName;
+ }
+ else
+ {
+ symlinkVars["SONAME"] = "";
+ symlinks.push_back(soName);
+ }
+ symlinks.push_back(targetOutput);
+ globalGen.WriteBuild(this->GetBuildFileStream(),
+ "Create library symlink " + targetOutput,
+ "CMAKE_SYMLINK_LIBRARY",
+ symlinks,
+ cmNinjaDeps(1, targetOutputReal),
+ emptyDeps,
+ emptyDeps,
+ symlinkVars);
+ }
+ }
+
+ if (!this->TargetNameImport.empty())
+ {
+ // Since using multiple outputs would mess up the $out variable, use an
+ // alias for the import library.
+ globalGen.WritePhonyBuild(this->GetBuildFileStream(),
+ "Alias for import library.",
+ cmNinjaDeps(1, targetOutputImplib),
+ cmNinjaDeps(1, targetOutputReal));
+ }
+
+ // Add aliases for the file name and the target name.
+ globalGen.AddTargetAlias(this->TargetNameOut, &target);
+ globalGen.AddTargetAlias(this->GetTargetName(), &target);
+}
+
+//----------------------------------------------------------------------------
+void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
+{
+ // Write a phony output that depends on all object files.
+ cmNinjaDeps outputs;
+ this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs);
+ cmNinjaDeps depends = this->GetObjects();
+ this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
+ "Object library "
+ + this->GetTargetName(),
+ outputs,
+ depends);
+
+ // Add aliases for the target name.
+ this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
+ this->GetTarget());
+}
diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h
new file mode 100644
index 0000000000..556ed5e136
--- /dev/null
+++ b/Source/cmNinjaNormalTargetGenerator.h
@@ -0,0 +1,53 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 cmNinjaNormalTargetGenerator_h
+# define cmNinjaNormalTargetGenerator_h
+
+# include "cmNinjaTargetGenerator.h"
+# include "cmNinjaTypes.h"
+# include "cmStandardIncludes.h"
+
+# include <set>
+
+class cmSourceFile;
+class cmOSXBundleGenerator;
+class cmGeneratorTarget;
+
+class cmNinjaNormalTargetGenerator : public cmNinjaTargetGenerator
+{
+public:
+ cmNinjaNormalTargetGenerator(cmGeneratorTarget* target);
+ ~cmNinjaNormalTargetGenerator();
+
+ void Generate();
+
+private:
+ std::string LanguageLinkerRule() const;
+ const char* GetVisibleTypeName() const;
+ void WriteLanguagesRules();
+ void WriteLinkRule(bool useResponseFile);
+ void WriteLinkStatement();
+ void WriteObjectLibStatement();
+ std::vector<std::string> ComputeLinkCmd();
+
+private:
+ // Target name info.
+ std::string TargetNameOut;
+ std::string TargetNameSO;
+ std::string TargetNameReal;
+ std::string TargetNameImport;
+ std::string TargetNamePDB;
+ std::string TargetLinkLanguage;
+};
+
+#endif // ! cmNinjaNormalTargetGenerator_h
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
new file mode 100644
index 0000000000..816e6d827a
--- /dev/null
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -0,0 +1,805 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 "cmNinjaTargetGenerator.h"
+#include "cmGlobalNinjaGenerator.h"
+#include "cmLocalNinjaGenerator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmGeneratorTarget.h"
+#include "cmNinjaNormalTargetGenerator.h"
+#include "cmNinjaUtilityTargetGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmComputeLinkInformation.h"
+#include "cmSourceFile.h"
+#include "cmCustomCommandGenerator.h"
+
+#include <algorithm>
+
+cmNinjaTargetGenerator *
+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:
+ return new cmNinjaNormalTargetGenerator(target);
+
+ case cmTarget::UTILITY:
+ return new cmNinjaUtilityTargetGenerator(target);;
+
+ case cmTarget::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->GetStartDirectory(), mf->GetHomeDirectory()) == 0)
+ return new cmNinjaUtilityTargetGenerator(target);
+ // else fallthrough
+ }
+
+ default:
+ return 0;
+ }
+}
+
+cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmTarget* target)
+ :
+ MacOSXContentGenerator(0),
+ OSXBundleGenerator(0),
+ MacContentFolders(),
+ Target(target),
+ Makefile(target->GetMakefile()),
+ LocalGenerator(
+ static_cast<cmLocalNinjaGenerator*>(Makefile->GetLocalGenerator())),
+ Objects()
+{
+ this->GeneratorTarget =
+ this->GetGlobalGenerator()->GetGeneratorTarget(target);
+ MacOSXContentGenerator = new MacOSXContentGeneratorType(this);
+}
+
+cmNinjaTargetGenerator::~cmNinjaTargetGenerator()
+{
+ delete this->MacOSXContentGenerator;
+}
+
+cmGeneratedFileStream& cmNinjaTargetGenerator::GetBuildFileStream() const
+{
+ return *this->GetGlobalGenerator()->GetBuildFileStream();
+}
+
+cmGeneratedFileStream& cmNinjaTargetGenerator::GetRulesFileStream() const
+{
+ return *this->GetGlobalGenerator()->GetRulesFileStream();
+}
+
+cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const
+{
+ return this->LocalGenerator->GetGlobalNinjaGenerator();
+}
+
+std::string const& cmNinjaTargetGenerator::GetConfigName() const
+{
+ return this->LocalGenerator->GetConfigName();
+}
+
+// TODO: Picked up from cmMakefileTargetGenerator. Refactor it.
+const char* cmNinjaTargetGenerator::GetFeature(const std::string& feature)
+{
+ return this->Target->GetFeature(feature, this->GetConfigName());
+}
+
+// TODO: Picked up from cmMakefileTargetGenerator. Refactor it.
+bool cmNinjaTargetGenerator::GetFeatureAsBool(const std::string& feature)
+{
+ return this->Target->GetFeatureAsBool(feature, this->GetConfigName());
+}
+
+// TODO: Picked up from cmMakefileTargetGenerator. Refactor it.
+void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags,
+ const std::string& lang)
+{
+ // Add language-specific flags.
+ this->LocalGenerator->AddLanguageFlags(flags, lang, this->GetConfigName());
+
+ if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION"))
+ {
+ this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO");
+ }
+}
+
+std::string
+cmNinjaTargetGenerator::OrderDependsTargetForTarget()
+{
+ return "cmake_order_depends_target_" + this->GetTargetName();
+}
+
+// TODO: Most of the code is picked up from
+// void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink),
+// void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
+// Refactor it.
+std::string
+cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile const* source,
+ const std::string& language)
+{
+ // TODO: Fortran support.
+ // // Fortran-specific flags computed for this target.
+ // if(*l == "Fortran")
+ // {
+ // this->AddFortranFlags(flags);
+ // }
+
+ bool hasLangCached = this->LanguageFlags.count(language) != 0;
+ std::string& languageFlags = this->LanguageFlags[language];
+ if(!hasLangCached)
+ {
+ this->AddFeatureFlags(languageFlags, language);
+
+ this->GetLocalGenerator()->AddArchitectureFlags(languageFlags,
+ this->GeneratorTarget,
+ language,
+ this->GetConfigName());
+
+ // Add shared-library flags if needed.
+ this->LocalGenerator->AddCMP0018Flags(languageFlags, this->Target,
+ language,
+ this->GetConfigName());
+
+ this->LocalGenerator->AddVisibilityPresetFlags(languageFlags, this->Target,
+ language);
+
+ std::vector<std::string> includes;
+ this->LocalGenerator->GetIncludeDirectories(includes,
+ this->GeneratorTarget,
+ language,
+ this->GetConfigName());
+ // Add include directory flags.
+ std::string includeFlags =
+ this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget,
+ language,
+ language == "RC" ? true : false); // full include paths for RC
+ // needed by cmcldeps
+ if(cmGlobalNinjaGenerator::IsMinGW())
+ cmSystemTools::ReplaceString(includeFlags, "\\", "/");
+
+ this->LocalGenerator->AppendFlags(languageFlags, includeFlags);
+
+ // Append old-style preprocessor definition flags.
+ this->LocalGenerator->AppendFlags(languageFlags,
+ this->Makefile->GetDefineFlags());
+
+ // Add target-specific flags.
+ this->LocalGenerator->AddCompileOptions(languageFlags, this->Target,
+ language,
+ this->GetConfigName());
+ }
+
+ std::string flags = languageFlags;
+
+ // Add source file specific flags.
+ this->LocalGenerator->AppendFlags(flags,
+ source->GetProperty("COMPILE_FLAGS"));
+
+ // TODO: Handle Apple frameworks.
+
+ return flags;
+}
+
+
+bool cmNinjaTargetGenerator::needsDepFile(const std::string& lang)
+{
+ cmMakefile* mf = this->GetMakefile();
+
+ const bool usingMSVC = std::string("MSVC") ==
+ (mf->GetDefinition("CMAKE_C_COMPILER_ID") ?
+ mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") :
+ mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"));
+
+ return !usingMSVC || lang == "RC";
+}
+
+
+
+// TODO: Refactor with
+// void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
+std::string
+cmNinjaTargetGenerator::
+ComputeDefines(cmSourceFile const* source, const std::string& language)
+{
+ std::set<std::string> defines;
+
+ // Add the export symbol definition for shared library objects.
+ if(const char* exportMacro = this->Target->GetExportMacro())
+ {
+ this->LocalGenerator->AppendDefines(defines, exportMacro);
+ }
+
+ // Add preprocessor definitions for this target and configuration.
+ this->LocalGenerator->AddCompileDefinitions(defines, this->Target,
+ this->GetConfigName());
+ this->LocalGenerator->AppendDefines
+ (defines,
+ source->GetProperty("COMPILE_DEFINITIONS"));
+ {
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += cmSystemTools::UpperCase(this->GetConfigName());
+ this->LocalGenerator->AppendDefines
+ (defines,
+ source->GetProperty(defPropName));
+ }
+
+ std::string definesString;
+ this->LocalGenerator->JoinDefines(defines, definesString,
+ language);
+
+ return definesString;
+}
+
+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)
+ return cmNinjaDeps();
+
+ cmComputeLinkInformation* cli =
+ this->Target->GetLinkInformation(this->GetConfigName());
+ if(!cli)
+ return cmNinjaDeps();
+
+ const std::vector<std::string> &deps = cli->GetDepends();
+ cmNinjaDeps result(deps.size());
+ std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath());
+
+ // Add a dependency on the link definitions file, if any.
+ if(!this->ModuleDefinitionFile.empty())
+ {
+ result.push_back(this->ModuleDefinitionFile);
+ }
+
+ return result;
+}
+
+std::string
+cmNinjaTargetGenerator
+::GetSourceFilePath(cmSourceFile const* source) const
+{
+ return ConvertToNinjaPath(source->GetFullPath().c_str());
+}
+
+std::string
+cmNinjaTargetGenerator
+::GetObjectFilePath(cmSourceFile const* source) const
+{
+ std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
+ if(!path.empty())
+ path += "/";
+ std::string const& objectName = this->GeneratorTarget
+ ->GetObjectName(source);
+ path += this->LocalGenerator->GetTargetDirectory(*this->Target);
+ path += "/";
+ path += objectName;
+ return path;
+}
+
+std::string cmNinjaTargetGenerator::GetTargetOutputDir() const
+{
+ std::string dir = this->Target->GetDirectory(this->GetConfigName());
+ return ConvertToNinjaPath(dir.c_str());
+}
+
+std::string
+cmNinjaTargetGenerator
+::GetTargetFilePath(const std::string& name) const
+{
+ std::string path = this->GetTargetOutputDir();
+ if (path.empty() || path == ".")
+ return name;
+ path += "/";
+ path += name;
+ return path;
+}
+
+std::string cmNinjaTargetGenerator::GetTargetName() const
+{
+ return this->Target->GetName();
+}
+
+
+bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const
+{
+ cmMakefile* mf = this->GetMakefile();
+ if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") ||
+ mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID"))
+ {
+ 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)
+ {
+ pdbPath = this->Target->GetPDBDirectory(this->GetConfigName());
+ pdbPath += "/";
+ pdbPath += this->Target->GetPDBName(this->GetConfigName());
+ }
+ if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
+ {
+ compilePdbPath = this->Target->GetCompilePDBPath(this->GetConfigName());
+ if(compilePdbPath.empty())
+ {
+ compilePdbPath = this->Target->GetSupportDirectory() + "/";
+ }
+ }
+
+ vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
+ ConvertToNinjaPath(pdbPath.c_str()),
+ cmLocalGenerator::SHELL);
+ vars["TARGET_COMPILE_PDB"] =
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ ConvertToNinjaPath(compilePdbPath.c_str()),
+ cmLocalGenerator::SHELL);
+
+ EnsureParentDirectoryExists(pdbPath);
+ EnsureParentDirectoryExists(compilePdbPath);
+ return true;
+ }
+ return false;
+}
+
+void
+cmNinjaTargetGenerator
+::WriteLanguageRules(const std::string& language)
+{
+#ifdef NINJA_GEN_VERBOSE_FILES
+ this->GetRulesFileStream()
+ << "# Rules for language " << language << "\n\n";
+#endif
+ this->WriteCompileRule(language);
+}
+
+void
+cmNinjaTargetGenerator
+::WriteCompileRule(const std::string& lang)
+{
+ cmLocalGenerator::RuleVariables vars;
+ vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
+ vars.CMTarget = this->GetTarget();
+ vars.Language = lang.c_str();
+ vars.Source = "$in";
+ vars.Object = "$out";
+ vars.Defines = "$DEFINES";
+ vars.TargetPDB = "$TARGET_PDB";
+ vars.TargetCompilePDB = "$TARGET_COMPILE_PDB";
+ vars.ObjectDir = "$OBJECT_DIR";
+ vars.ObjectFileDir = "$OBJECT_FILE_DIR";
+
+ cmMakefile* mf = this->GetMakefile();
+
+ const std::string cId = mf->GetDefinition("CMAKE_C_COMPILER_ID")
+ ? mf->GetSafeDefinition("CMAKE_C_COMPILER_ID")
+ : mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID");
+ const std::string sId = mf->GetDefinition("CMAKE_C_SIMULATE_ID")
+ ? mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID")
+ : mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID");
+ const bool usingMSVC = (cId == "MSVC" || sId == "MSVC");
+
+ // Tell ninja dependency format so all deps can be loaded into a database
+ std::string deptype;
+ std::string depfile;
+ std::string cldeps;
+ std::string flags = "$FLAGS";
+ if (usingMSVC)
+ {
+ if (!mf->GetIsSourceFileTryCompile() && lang == "RC")
+ {
+ deptype = "gcc";
+ depfile = "$DEP_FILE";
+ const std::string cl = mf->GetDefinition("CMAKE_C_COMPILER") ?
+ mf->GetSafeDefinition("CMAKE_C_COMPILER") :
+ mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
+ cldeps = "\"";
+ cldeps += mf->GetSafeDefinition("CMAKE_CMCLDEPS_EXECUTABLE");
+ cldeps += "\" " + lang + " $in \"$DEP_FILE\" $out \"";
+ cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX");
+ cldeps += "\" \"" + cl + "\" ";
+ }
+ else
+ {
+ deptype = "msvc";
+ depfile = "";
+ flags += " /showIncludes";
+ }
+ }
+ else
+ {
+ deptype = "gcc";
+ const char* langdeptype = mf->GetDefinition("CMAKE_NINJA_DEPTYPE_" + lang);
+ if (langdeptype)
+ {
+ deptype = langdeptype;
+ }
+ depfile = "$DEP_FILE";
+ const std::string flagsName = "CMAKE_DEPFILE_FLAGS_" + lang;
+ std::string depfileFlags = mf->GetSafeDefinition(flagsName);
+ if (!depfileFlags.empty())
+ {
+ cmSystemTools::ReplaceString(depfileFlags, "<DEPFILE>", "$DEP_FILE");
+ cmSystemTools::ReplaceString(depfileFlags, "<OBJECT>", "$out");
+ cmSystemTools::ReplaceString(depfileFlags, "<CMAKE_C_COMPILER>",
+ mf->GetDefinition("CMAKE_C_COMPILER"));
+ flags += " " + depfileFlags;
+ }
+ }
+
+ vars.Flags = flags.c_str();
+ vars.DependencyFile = depfile.c_str();
+
+ // Rule for compiling object file.
+ const std::string cmdVar = std::string("CMAKE_") + lang + "_COMPILE_OBJECT";
+ std::string compileCmd = mf->GetRequiredDefinition(cmdVar);
+ std::vector<std::string> compileCmds;
+ cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
+
+ compileCmds.front().insert(0, cldeps);
+
+ for (std::vector<std::string>::iterator i = compileCmds.begin();
+ i != compileCmds.end(); ++i)
+ this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
+
+ std::string cmdLine =
+ this->GetLocalGenerator()->BuildCommandLine(compileCmds);
+
+
+ // Write the rule for compiling file of the given language.
+ cmOStringStream comment;
+ comment << "Rule for compiling " << lang << " files.";
+ cmOStringStream description;
+ description << "Building " << lang << " object $out";
+ this->GetGlobalGenerator()->AddRule(this->LanguageCompilerRule(lang),
+ cmdLine,
+ description.str(),
+ comment.str(),
+ depfile,
+ deptype,
+ /*rspfile*/ "",
+ /*rspcontent*/ "",
+ /*restat*/ false,
+ /*generator*/ false);
+}
+
+void
+cmNinjaTargetGenerator
+::WriteObjectBuildStatements()
+{
+ // Write comments.
+ cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
+ this->GetBuildFileStream()
+ << "# Object build statements for "
+ << cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
+ << " target "
+ << this->GetTargetName()
+ << "\n\n";
+
+ std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ std::vector<cmSourceFile const*> customCommands;
+ this->GeneratorTarget->GetCustomCommands(customCommands, config);
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = customCommands.begin();
+ si != customCommands.end(); ++si)
+ {
+ cmCustomCommand const* cc = (*si)->GetCustomCommand();
+ this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
+ // Record the custom commands for this target. The container is used
+ // in WriteObjectBuildStatement when called in a loop below.
+ this->CustomCommands.push_back(cc);
+ }
+ std::vector<cmSourceFile const*> headerSources;
+ this->GeneratorTarget->GetHeaderSources(headerSources, config);
+ this->OSXBundleGenerator->GenerateMacOSXContentStatements(
+ headerSources,
+ this->MacOSXContentGenerator);
+ std::vector<cmSourceFile const*> extraSources;
+ this->GeneratorTarget->GetExtraSources(extraSources, config);
+ this->OSXBundleGenerator->GenerateMacOSXContentStatements(
+ extraSources,
+ this->MacOSXContentGenerator);
+ std::vector<cmSourceFile const*> externalObjects;
+ this->GeneratorTarget->GetExternalObjects(externalObjects, config);
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = externalObjects.begin();
+ si != externalObjects.end(); ++si)
+ {
+ this->Objects.push_back(this->GetSourceFilePath(*si));
+ }
+
+ cmNinjaDeps orderOnlyDeps;
+ this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps);
+
+ // Add order-only dependencies on custom command outputs.
+ for(std::vector<cmCustomCommand const*>::const_iterator
+ cci = this->CustomCommands.begin();
+ cci != this->CustomCommands.end(); ++cci)
+ {
+ cmCustomCommand const* cc = *cci;
+ cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
+ this->GetMakefile());
+ const std::vector<std::string>& ccoutputs = ccg.GetOutputs();
+ std::transform(ccoutputs.begin(), ccoutputs.end(),
+ std::back_inserter(orderOnlyDeps), MapToNinjaPath());
+ }
+
+ if (!orderOnlyDeps.empty())
+ {
+ cmNinjaDeps orderOnlyTarget;
+ orderOnlyTarget.push_back(this->OrderDependsTargetForTarget());
+ this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
+ "Order-only phony target for "
+ + this->GetTargetName(),
+ orderOnlyTarget,
+ cmNinjaDeps(),
+ cmNinjaDeps(),
+ orderOnlyDeps);
+ }
+ std::vector<cmSourceFile const*> objectSources;
+ this->GeneratorTarget->GetObjectSources(objectSources, config);
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = objectSources.begin(); si != objectSources.end(); ++si)
+ {
+ this->WriteObjectBuildStatement(*si, !orderOnlyDeps.empty());
+ }
+ std::string def = this->GeneratorTarget->GetModuleDefinitionFile(config);
+ if(!def.empty())
+ {
+ this->ModuleDefinitionFile = this->ConvertToNinjaPath(def.c_str());
+ }
+
+ this->GetBuildFileStream() << "\n";
+}
+
+void
+cmNinjaTargetGenerator
+::WriteObjectBuildStatement(
+ cmSourceFile const* source, bool writeOrderDependsTargetForTarget)
+{
+ std::string comment;
+ const std::string language = source->GetLanguage();
+ std::string rule = this->LanguageCompilerRule(language);
+
+ cmNinjaDeps outputs;
+ std::string objectFileName = this->GetObjectFilePath(source);
+ outputs.push_back(objectFileName);
+ // Add this object to the list of object files.
+ this->Objects.push_back(objectFileName);
+
+ cmNinjaDeps explicitDeps;
+ std::string sourceFileName;
+ if (language == "RC")
+ sourceFileName = source->GetFullPath();
+ else
+ sourceFileName = this->GetSourceFilePath(source);
+ explicitDeps.push_back(sourceFileName);
+
+ cmNinjaDeps implicitDeps;
+ if(const char* objectDeps = source->GetProperty("OBJECT_DEPENDS")) {
+ std::vector<std::string> depList;
+ cmSystemTools::ExpandListArgument(objectDeps, depList);
+ std::transform(depList.begin(), depList.end(),
+ std::back_inserter(implicitDeps), MapToNinjaPath());
+ }
+
+ cmNinjaDeps orderOnlyDeps;
+ if (writeOrderDependsTargetForTarget)
+ {
+ orderOnlyDeps.push_back(this->OrderDependsTargetForTarget());
+ }
+
+ // If the source file is GENERATED and does not have a custom command
+ // (either attached to this source file or another one), assume that one of
+ // the target dependencies, OBJECT_DEPENDS or header file custom commands
+ // will rebuild the file.
+ if (source->GetPropertyAsBool("GENERATED") && !source->GetCustomCommand() &&
+ !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) {
+ this->GetGlobalGenerator()->AddAssumedSourceDependencies(sourceFileName,
+ orderOnlyDeps);
+ }
+
+ cmNinjaVars vars;
+ vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
+ vars["DEFINES"] = this->ComputeDefines(source, language);
+ if (needsDepFile(language)) {
+ vars["DEP_FILE"] =
+ cmGlobalNinjaGenerator::EncodeDepfileSpace(objectFileName + ".d");
+ }
+ EnsureParentDirectoryExists(objectFileName);
+
+ std::string objectDir = this->Target->GetSupportDirectory();
+ vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
+ ConvertToNinjaPath(objectDir.c_str()),
+ cmLocalGenerator::SHELL);
+ std::string objectFileDir = cmSystemTools::GetFilenamePath(objectFileName);
+ vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
+ ConvertToNinjaPath(objectFileDir.c_str()),
+ cmLocalGenerator::SHELL);
+
+ this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetTarget(), vars);
+
+ this->SetMsvcTargetPdbVariable(vars);
+
+ if(this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS"))
+ {
+ cmLocalGenerator::RuleVariables compileObjectVars;
+ std::string lang = language;
+ compileObjectVars.Language = lang.c_str();
+
+ std::string escapedSourceFileName = sourceFileName;
+
+ if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
+ {
+ escapedSourceFileName = cmSystemTools::CollapseFullPath(
+ escapedSourceFileName.c_str(),
+ this->GetGlobalGenerator()->GetCMakeInstance()->
+ GetHomeOutputDirectory());
+ }
+
+ escapedSourceFileName =
+ this->LocalGenerator->ConvertToOutputFormat(
+ escapedSourceFileName, cmLocalGenerator::SHELL);
+
+ compileObjectVars.Source = escapedSourceFileName.c_str();
+ compileObjectVars.Object = objectFileName.c_str();
+ compileObjectVars.ObjectDir = objectDir.c_str();
+ compileObjectVars.ObjectFileDir = objectFileDir.c_str();
+ compileObjectVars.Flags = vars["FLAGS"].c_str();
+ compileObjectVars.Defines = vars["DEFINES"].c_str();
+
+ // Rule for compiling object file.
+ std::string compileCmdVar = "CMAKE_";
+ compileCmdVar += language;
+ compileCmdVar += "_COMPILE_OBJECT";
+ std::string compileCmd =
+ this->GetMakefile()->GetRequiredDefinition(compileCmdVar);
+ std::vector<std::string> compileCmds;
+ cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
+
+ for (std::vector<std::string>::iterator i = compileCmds.begin();
+ i != compileCmds.end(); ++i)
+ this->GetLocalGenerator()->ExpandRuleVariables(*i, compileObjectVars);
+
+ std::string cmdLine =
+ this->GetLocalGenerator()->BuildCommandLine(compileCmds);
+
+ this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine,
+ sourceFileName);
+ }
+
+ this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(),
+ comment,
+ rule,
+ outputs,
+ explicitDeps,
+ implicitDeps,
+ orderOnlyDeps,
+ vars);
+
+ if(const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
+ std::vector<std::string> outputList;
+ cmSystemTools::ExpandListArgument(objectOutputs, outputList);
+ std::transform(outputList.begin(), outputList.end(), outputList.begin(),
+ MapToNinjaPath());
+ this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
+ "Additional output files.",
+ outputList,
+ outputs);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmNinjaTargetGenerator
+::AddModuleDefinitionFlag(std::string& flags)
+{
+ if(this->ModuleDefinitionFile.empty())
+ {
+ return;
+ }
+
+ // TODO: Create a per-language flag variable.
+ const char* defFileFlag =
+ this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
+ if(!defFileFlag)
+ {
+ return;
+ }
+
+ // Append the flag and value. Use ConvertToLinkReference to help
+ // vs6's "cl -link" pass it to the linker.
+ std::string flag = defFileFlag;
+ flag += (this->LocalGenerator->ConvertToLinkReference(
+ this->ModuleDefinitionFile));
+ this->LocalGenerator->AppendFlags(flags, flag);
+}
+
+void
+cmNinjaTargetGenerator
+::EnsureDirectoryExists(const std::string& path) const
+{
+ if (cmSystemTools::FileIsFullPath(path.c_str()))
+ {
+ cmSystemTools::MakeDirectory(path.c_str());
+ }
+ else
+ {
+ const std::string fullPath = std::string(this->GetGlobalGenerator()->
+ GetCMakeInstance()->GetHomeOutputDirectory())
+ + "/" + path;
+ cmSystemTools::MakeDirectory(fullPath.c_str());
+ }
+}
+
+void
+cmNinjaTargetGenerator
+::EnsureParentDirectoryExists(const std::string& path) const
+{
+ EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path.c_str()));
+}
+
+
+//----------------------------------------------------------------------------
+void
+cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
+ cmSourceFile const& source, const char* pkgloc)
+{
+ // Skip OS X content when not building a Framework or Bundle.
+ if(!this->Generator->GetTarget()->IsBundleOnApple())
+ {
+ return;
+ }
+
+ std::string macdir =
+ this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc);
+
+ // Get the input file location.
+ std::string input = source.GetFullPath();
+ input =
+ this->Generator->GetLocalGenerator()->ConvertToNinjaPath(input.c_str());
+
+ // Get the output file location.
+ std::string output = macdir;
+ output += "/";
+ output += cmSystemTools::GetFilenameName(input);
+ output =
+ this->Generator->GetLocalGenerator()->ConvertToNinjaPath(output.c_str());
+
+ // Write a build statement to copy the content into the bundle.
+ this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(input,
+ output);
+
+ // Add as a dependency of all target so that it gets called.
+ this->Generator->GetGlobalGenerator()->AddDependencyToAll(output);
+}
+
+void cmNinjaTargetGenerator::addPoolNinjaVariable(
+ const std::string& pool_property,
+ cmTarget* target,
+ cmNinjaVars& vars)
+{
+ const char* pool = target->GetProperty(pool_property);
+ if (pool)
+ {
+ vars["pool"] = pool;
+ }
+}
diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h
new file mode 100644
index 0000000000..40a15a3ac9
--- /dev/null
+++ b/Source/cmNinjaTargetGenerator.h
@@ -0,0 +1,170 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 cmNinjaTargetGenerator_h
+#define cmNinjaTargetGenerator_h
+
+#include "cmStandardIncludes.h"
+#include "cmNinjaTypes.h"
+#include "cmLocalNinjaGenerator.h"
+#include "cmOSXBundleGenerator.h"
+
+class cmTarget;
+class cmGlobalNinjaGenerator;
+class cmGeneratedFileStream;
+class cmGeneratorTarget;
+class cmMakefile;
+class cmSourceFile;
+class cmCustomCommand;
+
+class cmNinjaTargetGenerator
+{
+public:
+ /// Create a cmNinjaTargetGenerator according to the @a target's type.
+ static cmNinjaTargetGenerator* New(cmGeneratorTarget* target);
+
+ /// Build a NinjaTargetGenerator.
+ cmNinjaTargetGenerator(cmTarget* target);
+
+ /// Destructor.
+ virtual ~cmNinjaTargetGenerator();
+
+ virtual void Generate() = 0;
+
+ std::string GetTargetName() const;
+
+ bool needsDepFile(const std::string& lang);
+
+protected:
+
+ bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;
+
+ cmGeneratedFileStream& GetBuildFileStream() const;
+ cmGeneratedFileStream& GetRulesFileStream() const;
+
+ cmTarget* GetTarget() const
+ { return this->Target; }
+
+ cmGeneratorTarget* GetGeneratorTarget() const
+ { return this->GeneratorTarget; }
+
+ cmLocalNinjaGenerator* GetLocalGenerator() const
+ { return this->LocalGenerator; }
+
+ cmGlobalNinjaGenerator* GetGlobalGenerator() const;
+
+ cmMakefile* GetMakefile() const
+ { return this->Makefile; }
+
+ std::string const& GetConfigName() const;
+
+ std::string LanguageCompilerRule(const std::string& lang) const
+ { return lang + "_COMPILER"; }
+
+ const char* GetFeature(const std::string& feature);
+ bool GetFeatureAsBool(const std::string& feature);
+ void AddFeatureFlags(std::string& flags, const std::string& lang);
+
+ std::string OrderDependsTargetForTarget();
+
+ std::string ComputeOrderDependsForTarget();
+
+ /**
+ * Compute the flags for compilation of object files for a given @a language.
+ * @note Generally it is the value of the variable whose name is computed
+ * by LanguageFlagsVarName().
+ */
+ std::string ComputeFlagsForObject(cmSourceFile const* source,
+ const std::string& language);
+
+ std::string ComputeDefines(cmSourceFile const* source,
+ const std::string& language);
+
+ std::string ConvertToNinjaPath(const std::string& path) const {
+ return this->GetLocalGenerator()->ConvertToNinjaPath(path);
+ }
+ cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
+ return this->GetLocalGenerator()->MapToNinjaPath();
+ }
+
+ /// @return the list of link dependency for the given target @a target.
+ cmNinjaDeps ComputeLinkDeps() const;
+
+ /// @return the source file path for the given @a source.
+ std::string GetSourceFilePath(cmSourceFile const* source) const;
+
+ /// @return the object file path for the given @a source.
+ std::string GetObjectFilePath(cmSourceFile const* source) const;
+
+ /// @return the file path where the target named @a name is generated.
+ std::string GetTargetFilePath(const std::string& name) const;
+
+ /// @return the output path for the target.
+ virtual std::string GetTargetOutputDir() const;
+
+ void WriteLanguageRules(const std::string& language);
+ void WriteCompileRule(const std::string& language);
+ void WriteObjectBuildStatements();
+ void WriteObjectBuildStatement(cmSourceFile const* source,
+ bool writeOrderDependsTargetForTarget);
+ void WriteCustomCommandBuildStatement(cmCustomCommand *cc);
+
+ cmNinjaDeps GetObjects() const
+ { return this->Objects; }
+
+ // Helper to add flag for windows .def file.
+ void AddModuleDefinitionFlag(std::string& flags);
+
+ void EnsureDirectoryExists(const std::string& dir) const;
+ void EnsureParentDirectoryExists(const std::string& path) const;
+
+ // write rules for Mac OS X Application Bundle content.
+ struct MacOSXContentGeneratorType :
+ cmOSXBundleGenerator::MacOSXContentGeneratorType
+ {
+ MacOSXContentGeneratorType(cmNinjaTargetGenerator* g) :
+ Generator(g) {}
+
+ void operator()(cmSourceFile const& source, const char* pkgloc);
+
+ private:
+ cmNinjaTargetGenerator* Generator;
+ };
+ friend struct MacOSXContentGeneratorType;
+
+
+ MacOSXContentGeneratorType* MacOSXContentGenerator;
+ // Properly initialized by sub-classes.
+ cmOSXBundleGenerator* OSXBundleGenerator;
+ std::set<std::string> MacContentFolders;
+
+ void addPoolNinjaVariable(const std::string& pool_property,
+ cmTarget* target,
+ cmNinjaVars& vars);
+
+private:
+ cmTarget* Target;
+ cmGeneratorTarget* GeneratorTarget;
+ cmMakefile* Makefile;
+ cmLocalNinjaGenerator* LocalGenerator;
+ /// List of object files for this target.
+ cmNinjaDeps Objects;
+ std::vector<cmCustomCommand const*> CustomCommands;
+
+ typedef std::map<std::string, std::string> LanguageFlagMap;
+ LanguageFlagMap LanguageFlags;
+
+ // The windows module definition source file (.def), if any.
+ std::string ModuleDefinitionFile;
+};
+
+#endif // ! cmNinjaTargetGenerator_h
diff --git a/Source/cmNinjaTypes.h b/Source/cmNinjaTypes.h
new file mode 100644
index 0000000000..498f6b6398
--- /dev/null
+++ b/Source/cmNinjaTypes.h
@@ -0,0 +1,19 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 cmNinjaTypes_h
+# define cmNinjaTypes_h
+
+typedef std::vector<std::string> cmNinjaDeps;
+typedef std::map<std::string, std::string> cmNinjaVars;
+
+#endif // ! cmNinjaTypes_h
diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx
new file mode 100644
index 0000000000..f5d18dc88c
--- /dev/null
+++ b/Source/cmNinjaUtilityTargetGenerator.cxx
@@ -0,0 +1,125 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 "cmNinjaUtilityTargetGenerator.h"
+#include "cmCustomCommand.h"
+#include "cmGeneratedFileStream.h"
+#include "cmGlobalNinjaGenerator.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmTarget.h"
+#include "cmCustomCommandGenerator.h"
+
+cmNinjaUtilityTargetGenerator::cmNinjaUtilityTargetGenerator(
+ cmGeneratorTarget *target)
+ : cmNinjaTargetGenerator(target->Target) {}
+
+cmNinjaUtilityTargetGenerator::~cmNinjaUtilityTargetGenerator() {}
+
+void cmNinjaUtilityTargetGenerator::Generate()
+{
+ std::vector<std::string> commands;
+ cmNinjaDeps deps, outputs;
+
+ const std::vector<cmCustomCommand> *cmdLists[2] = {
+ &this->GetTarget()->GetPreBuildCommands(),
+ &this->GetTarget()->GetPostBuildCommands()
+ };
+
+ for (unsigned i = 0; i != 2; ++i) {
+ for (std::vector<cmCustomCommand>::const_iterator
+ ci = cmdLists[i]->begin(); ci != cmdLists[i]->end(); ++ci) {
+ cmCustomCommandGenerator ccg(*ci, this->GetConfigName(),
+ this->GetMakefile());
+ this->GetLocalGenerator()->AppendCustomCommandDeps(ccg, deps);
+ this->GetLocalGenerator()->AppendCustomCommandLines(ccg, commands);
+ }
+ }
+
+ std::vector<cmSourceFile*> sources;
+ std::string config = this->GetMakefile()
+ ->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ this->GetTarget()->GetSourceFiles(sources, config);
+ for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
+ source != sources.end(); ++source)
+ {
+ if(cmCustomCommand* cc = (*source)->GetCustomCommand())
+ {
+ cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
+ this->GetMakefile());
+ this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
+
+ // Depend on all custom command outputs.
+ const std::vector<std::string>& ccOutputs = ccg.GetOutputs();
+ std::transform(ccOutputs.begin(), ccOutputs.end(),
+ std::back_inserter(deps), MapToNinjaPath());
+ }
+ }
+
+ this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs);
+ this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(), deps);
+
+ if (commands.empty()) {
+ this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
+ "Utility command for "
+ + this->GetTargetName(),
+ outputs,
+ deps);
+ } else {
+ std::string command =
+ this->GetLocalGenerator()->BuildCommandLine(commands);
+ const char *echoStr = this->GetTarget()->GetProperty("EchoString");
+ std::string desc;
+ if (echoStr)
+ desc = echoStr;
+ else
+ desc = "Running utility command for " + this->GetTargetName();
+
+ // TODO: fix problematic global targets. For now, search and replace the
+ // makefile vars.
+ cmSystemTools::ReplaceString(
+ command,
+ "$(CMAKE_SOURCE_DIR)",
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ this->GetTarget()->GetMakefile()->GetHomeDirectory(),
+ cmLocalGenerator::SHELL).c_str());
+ cmSystemTools::ReplaceString(
+ command,
+ "$(CMAKE_BINARY_DIR)",
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ this->GetTarget()->GetMakefile()->GetHomeOutputDirectory(),
+ cmLocalGenerator::SHELL).c_str());
+ cmSystemTools::ReplaceString(command, "$(ARGS)", "");
+
+ if (command.find('$') != std::string::npos)
+ return;
+
+ std::string utilCommandName = cmake::GetCMakeFilesDirectoryPostSlash();
+ utilCommandName += this->GetTargetName() + ".util";
+
+ this->GetGlobalGenerator()->WriteCustomCommandBuild(
+ command,
+ desc,
+ "Utility command for " + this->GetTargetName(),
+ cmNinjaDeps(1, utilCommandName),
+ deps);
+
+ this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
+ "",
+ outputs,
+ cmNinjaDeps(1, utilCommandName)
+ );
+ }
+
+ this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
+ this->GetTarget());
+}
diff --git a/Source/cmNinjaUtilityTargetGenerator.h b/Source/cmNinjaUtilityTargetGenerator.h
new file mode 100644
index 0000000000..add0291a53
--- /dev/null
+++ b/Source/cmNinjaUtilityTargetGenerator.h
@@ -0,0 +1,30 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
+ Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 cmNinjaUtilityTargetGenerator_h
+# define cmNinjaUtilityTargetGenerator_h
+
+# include "cmNinjaTargetGenerator.h"
+# include "cmNinjaTypes.h"
+
+class cmSourceFile;
+
+class cmNinjaUtilityTargetGenerator : public cmNinjaTargetGenerator
+{
+public:
+ cmNinjaUtilityTargetGenerator(cmGeneratorTarget* target);
+ ~cmNinjaUtilityTargetGenerator();
+
+ void Generate();
+};
+
+#endif // ! cmNinjaUtilityTargetGenerator_h
diff --git a/Source/cmOSXBundleGenerator.cxx b/Source/cmOSXBundleGenerator.cxx
new file mode 100644
index 0000000000..786e6e2b69
--- /dev/null
+++ b/Source/cmOSXBundleGenerator.cxx
@@ -0,0 +1,234 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 "cmOSXBundleGenerator.h"
+#include "cmMakefile.h"
+#include "cmTarget.h"
+#include "cmLocalGenerator.h"
+
+#include <cassert>
+
+//----------------------------------------------------------------------------
+cmOSXBundleGenerator::
+cmOSXBundleGenerator(cmGeneratorTarget* target,
+ const std::string& configName)
+ : GT(target)
+ , Makefile(target->Target->GetMakefile())
+ , LocalGenerator(Makefile->GetLocalGenerator())
+ , ConfigName(configName)
+ , MacContentFolders(0)
+{
+ if (this->MustSkip())
+ return;
+
+}
+
+//----------------------------------------------------------------------------
+bool cmOSXBundleGenerator::MustSkip()
+{
+ return !this->GT->Target->HaveWellDefinedOutputFiles();
+}
+
+//----------------------------------------------------------------------------
+void cmOSXBundleGenerator::CreateAppBundle(const std::string& targetName,
+ std::string& outpath)
+{
+ if (this->MustSkip())
+ return;
+
+ // Compute bundle directory names.
+ std::string out = outpath;
+ out += "/";
+ out += this->GT->Target->GetAppBundleDirectory(this->ConfigName, false);
+ cmSystemTools::MakeDirectory(out.c_str());
+ this->Makefile->AddCMakeOutputFile(out);
+
+ std::string newoutpath = out;
+
+ // Configure the Info.plist file. Note that it needs the executable name
+ // to be set.
+ std::string plist = outpath;
+ plist += "/";
+ plist += this->GT->Target->GetAppBundleDirectory(this->ConfigName, true);
+ plist += "/Info.plist";
+ this->LocalGenerator->GenerateAppleInfoPList(this->GT->Target,
+ targetName,
+ plist.c_str());
+ this->Makefile->AddCMakeOutputFile(plist);
+ outpath = newoutpath;
+}
+
+//----------------------------------------------------------------------------
+void cmOSXBundleGenerator::CreateFramework(
+ const std::string& targetName, const std::string& outpath)
+{
+ if (this->MustSkip())
+ return;
+
+ assert(this->MacContentFolders);
+
+ // Compute the location of the top-level foo.framework directory.
+ std::string contentdir = outpath + "/" +
+ this->GT->Target->GetFrameworkDirectory(this->ConfigName, true);
+ contentdir += "/";
+
+ std::string newoutpath = outpath + "/" +
+ this->GT->Target->GetFrameworkDirectory(this->ConfigName, false);
+
+ std::string frameworkVersion = this->GT->Target->GetFrameworkVersion();
+
+ // Configure the Info.plist file into the Resources directory.
+ this->MacContentFolders->insert("Resources");
+ std::string plist = newoutpath;
+ plist += "/Resources/Info.plist";
+ std::string name = cmSystemTools::GetFilenameName(targetName);
+ this->LocalGenerator->GenerateFrameworkInfoPList(this->GT->Target,
+ name,
+ plist.c_str());
+
+ // TODO: Use the cmMakefileTargetGenerator::ExtraFiles vector to
+ // drive rules to create these files at build time.
+ std::string oldName;
+ std::string newName;
+
+
+ // Make foo.framework/Versions
+ std::string versions = contentdir;
+ versions += "Versions";
+ cmSystemTools::MakeDirectory(versions.c_str());
+
+ // Make foo.framework/Versions/version
+ cmSystemTools::MakeDirectory(newoutpath.c_str());
+
+ // Current -> version
+ oldName = frameworkVersion;
+ newName = versions;
+ newName += "/Current";
+ cmSystemTools::RemoveFile(newName.c_str());
+ cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
+ this->Makefile->AddCMakeOutputFile(newName);
+
+ // foo -> Versions/Current/foo
+ oldName = "Versions/Current/";
+ oldName += name;
+ newName = contentdir;
+ newName += name;
+ cmSystemTools::RemoveFile(newName.c_str());
+ cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
+ this->Makefile->AddCMakeOutputFile(newName);
+
+ // Resources -> Versions/Current/Resources
+ if(this->MacContentFolders->find("Resources") !=
+ this->MacContentFolders->end())
+ {
+ oldName = "Versions/Current/Resources";
+ newName = contentdir;
+ newName += "Resources";
+ cmSystemTools::RemoveFile(newName.c_str());
+ cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
+ this->Makefile->AddCMakeOutputFile(newName);
+ }
+
+ // Headers -> Versions/Current/Headers
+ if(this->MacContentFolders->find("Headers") !=
+ this->MacContentFolders->end())
+ {
+ oldName = "Versions/Current/Headers";
+ newName = contentdir;
+ newName += "Headers";
+ cmSystemTools::RemoveFile(newName.c_str());
+ cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
+ this->Makefile->AddCMakeOutputFile(newName);
+ }
+
+ // PrivateHeaders -> Versions/Current/PrivateHeaders
+ if(this->MacContentFolders->find("PrivateHeaders") !=
+ this->MacContentFolders->end())
+ {
+ oldName = "Versions/Current/PrivateHeaders";
+ newName = contentdir;
+ newName += "PrivateHeaders";
+ cmSystemTools::RemoveFile(newName.c_str());
+ cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
+ this->Makefile->AddCMakeOutputFile(newName);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName,
+ const std::string& root)
+{
+ if (this->MustSkip())
+ return;
+
+ // Compute bundle directory names.
+ std::string out = root;
+ out += "/";
+ out += this->GT->Target->GetCFBundleDirectory(this->ConfigName, false);
+ cmSystemTools::MakeDirectory(out.c_str());
+ this->Makefile->AddCMakeOutputFile(out);
+
+ // Configure the Info.plist file. Note that it needs the executable name
+ // to be set.
+ std::string plist = root + "/" +
+ this->GT->Target->GetCFBundleDirectory(this->ConfigName, true);
+ plist += "/Info.plist";
+ this->LocalGenerator->GenerateAppleInfoPList(this->GT->Target,
+ targetName,
+ plist.c_str());
+ this->Makefile->AddCMakeOutputFile(plist);
+}
+
+//----------------------------------------------------------------------------
+void
+cmOSXBundleGenerator::
+GenerateMacOSXContentStatements(
+ std::vector<cmSourceFile const*> const& sources,
+ MacOSXContentGeneratorType* generator)
+{
+ if (this->MustSkip())
+ return;
+
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = sources.begin(); si != sources.end(); ++si)
+ {
+ cmGeneratorTarget::SourceFileFlags tsFlags =
+ this->GT->GetTargetSourceFileFlags(*si);
+ if(tsFlags.Type != cmGeneratorTarget::SourceFileTypeNormal)
+ {
+ (*generator)(**si, tsFlags.MacFolder);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmOSXBundleGenerator::InitMacOSXContentDirectory(const char* pkgloc)
+{
+ // Construct the full path to the content subdirectory.
+
+ std::string macdir =
+ this->GT->Target->GetMacContentDirectory(this->ConfigName,
+ /*implib*/ false);
+ macdir += "/";
+ macdir += pkgloc;
+ cmSystemTools::MakeDirectory(macdir.c_str());
+
+ // Record use of this content location. Only the first level
+ // directory is needed.
+ {
+ std::string loc = pkgloc;
+ loc = loc.substr(0, loc.find('/'));
+ this->MacContentFolders->insert(loc);
+ }
+
+ return macdir;
+}
diff --git a/Source/cmOSXBundleGenerator.h b/Source/cmOSXBundleGenerator.h
new file mode 100644
index 0000000000..f945c15a8c
--- /dev/null
+++ b/Source/cmOSXBundleGenerator.h
@@ -0,0 +1,71 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 Nicolas Despres <nicolas.despres@gmail.com>
+
+ 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 cmOSXBundleGenerator_h
+#define cmOSXBundleGenerator_h
+
+#include "cmStandardIncludes.h"
+#include "cmSourceFile.h"
+
+#include <string>
+#include <set>
+
+class cmTarget;
+class cmMakefile;
+class cmLocalGenerator;
+class cmGeneratorTarget;
+
+class cmOSXBundleGenerator
+{
+public:
+ cmOSXBundleGenerator(cmGeneratorTarget* target,
+ const std::string& configName);
+
+ // create an app bundle at a given root, and return
+ // the directory within the bundle that contains the executable
+ void CreateAppBundle(const std::string& targetName, std::string& root);
+
+ // create a framework at a given root
+ void CreateFramework(const std::string& targetName,
+ const std::string& root);
+
+ // create a cf bundle at a given root
+ void CreateCFBundle(const std::string& targetName,
+ const std::string& root);
+
+ struct MacOSXContentGeneratorType
+ {
+ virtual ~MacOSXContentGeneratorType() {}
+ virtual void operator()(cmSourceFile const& source,
+ const char* pkgloc) = 0;
+ };
+
+ void GenerateMacOSXContentStatements(
+ std::vector<cmSourceFile const*> const& sources,
+ MacOSXContentGeneratorType* generator);
+ std::string InitMacOSXContentDirectory(const char* pkgloc);
+
+ void SetMacContentFolders(std::set<std::string>* macContentFolders)
+ { this->MacContentFolders = macContentFolders; }
+
+private:
+ bool MustSkip();
+
+private:
+ cmGeneratorTarget* GT;
+ cmMakefile* Makefile;
+ cmLocalGenerator* LocalGenerator;
+ std::string ConfigName;
+ std::set<std::string>* MacContentFolders;
+};
+
+
+#endif
diff --git a/Source/cmObject.h b/Source/cmObject.h
new file mode 100644
index 0000000000..ca6a54fd03
--- /dev/null
+++ b/Source/cmObject.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmObject_h
+#define cmObject_h
+
+#include "cmStandardIncludes.h"
+
+/** \class cmObject
+ * \brief Superclass for all commands and other classes in CMake.
+ *
+ * cmObject is the base class for all classes in CMake. It defines some
+ * methods such as GetNameOfClass, IsA, SafeDownCast.
+ */
+class cmObject
+{
+public:
+ /**
+ * Need virtual destructor to destroy real command type.
+ */
+ virtual ~cmObject() {}
+
+ /**
+ * The class name of the command.
+ */
+ virtual const char* GetNameOfClass() = 0;
+
+ /**
+ * Returns true if this class is the given class, or a subclass of it.
+ */
+ static bool IsTypeOf(const char *type)
+ { return !strcmp("cmObject", type); }
+
+ /**
+ * Returns true if this object is an instance of the given class or
+ * a subclass of it.
+ */
+ virtual bool IsA(const char *type)
+ { return cmObject::IsTypeOf(type); }
+};
+
+#endif
+
diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx
new file mode 100644
index 0000000000..e505440e8f
--- /dev/null
+++ b/Source/cmOptionCommand.cxx
@@ -0,0 +1,68 @@
+/*============================================================================
+ 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 "cmOptionCommand.h"
+
+// cmOptionCommand
+bool cmOptionCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ bool argError = false;
+ if(args.size() < 2)
+ {
+ argError = true;
+ }
+ // for VTK 4.0 we have to support the option command with more than 3
+ // arguments if CMAKE_MINIMUM_REQUIRED_VERSION is not defined, if
+ // CMAKE_MINIMUM_REQUIRED_VERSION is defined, then we can have stricter
+ // checking.
+ if(this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"))
+ {
+ if(args.size() > 3)
+ {
+ argError = true;
+ }
+ }
+ if(argError)
+ {
+ std::string m = "called with incorrect number of arguments: ";
+ for(size_t i =0; i < args.size(); ++i)
+ {
+ m += args[i];
+ m += " ";
+ }
+ this->SetError(m);
+ return false;
+ }
+
+ std::string initialValue = "Off";
+ // Now check and see if the value has been stored in the cache
+ // already, if so use that value and don't look for the program
+ cmCacheManager::CacheIterator it =
+ this->Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
+ if(!it.IsAtEnd())
+ {
+ if ( it.GetType() != cmCacheManager::UNINITIALIZED )
+ {
+ it.SetProperty("HELPSTRING", args[1].c_str());
+ return true;
+ }
+ initialValue = it.GetValue();
+ }
+ if(args.size() == 3)
+ {
+ initialValue = args[2];
+ }
+ bool init = cmSystemTools::IsOn(initialValue.c_str());
+ this->Makefile->AddCacheDefinition(args[0], init? "ON":"OFF",
+ args[1].c_str(), cmCacheManager::BOOL);
+ return true;
+}
diff --git a/Source/cmOptionCommand.h b/Source/cmOptionCommand.h
new file mode 100644
index 0000000000..12a6472273
--- /dev/null
+++ b/Source/cmOptionCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmOptionCommand_h
+#define cmOptionCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmOptionCommand
+ * \brief Provide an option to the user
+ *
+ * cmOptionCommand provides an option for the user to select
+ */
+class cmOptionCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmOptionCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "option";}
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ cmTypeMacro(cmOptionCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmOrderDirectories.cxx b/Source/cmOrderDirectories.cxx
new file mode 100644
index 0000000000..007364c1f4
--- /dev/null
+++ b/Source/cmOrderDirectories.cxx
@@ -0,0 +1,648 @@
+/*============================================================================
+ 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 "cmOrderDirectories.h"
+
+#include "cmGlobalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmake.h"
+
+#include <assert.h>
+
+#include <algorithm>
+
+/*
+Directory ordering computation.
+ - Useful to compute a safe runtime library path order
+ - Need runtime path for supporting INSTALL_RPATH_USE_LINK_PATH
+ - Need runtime path at link time to pickup transitive link dependencies
+ for shared libraries.
+*/
+
+//----------------------------------------------------------------------------
+class cmOrderDirectoriesConstraint
+{
+public:
+ cmOrderDirectoriesConstraint(cmOrderDirectories* od,
+ std::string const& file):
+ OD(od), GlobalGenerator(od->GlobalGenerator)
+ {
+ this->FullPath = file;
+
+ if(file.rfind(".framework") != std::string::npos)
+ {
+ static cmsys::RegularExpression
+ splitFramework("^(.*)/(.*).framework/(.*)$");
+ if(splitFramework.find(file) &&
+ (std::string::npos !=
+ splitFramework.match(3).find(splitFramework.match(2))))
+ {
+ this->Directory = splitFramework.match(1);
+ this->FileName =
+ std::string(file.begin() + this->Directory.size() + 1, file.end());
+ }
+ }
+
+ if(this->FileName.empty())
+ {
+ this->Directory = cmSystemTools::GetFilenamePath(file);
+ this->FileName = cmSystemTools::GetFilenameName(file);
+ }
+ }
+ virtual ~cmOrderDirectoriesConstraint() {}
+
+ void AddDirectory()
+ {
+ this->DirectoryIndex = this->OD->AddOriginalDirectory(this->Directory);
+ }
+
+ virtual void Report(std::ostream& e) = 0;
+
+ void FindConflicts(unsigned int index)
+ {
+ for(unsigned int i=0; i < this->OD->OriginalDirectories.size(); ++i)
+ {
+ // Check if this directory conflicts with the entry.
+ std::string const& dir = this->OD->OriginalDirectories[i];
+ if(dir != this->Directory &&
+ cmSystemTools::GetRealPath(dir) !=
+ cmSystemTools::GetRealPath(this->Directory) &&
+ this->FindConflict(dir))
+ {
+ // The library will be found in this directory but this is not
+ // the directory named for it. Add an entry to make sure the
+ // desired directory comes before this one.
+ cmOrderDirectories::ConflictPair p(this->DirectoryIndex, index);
+ this->OD->ConflictGraph[i].push_back(p);
+ }
+ }
+ }
+
+ void FindImplicitConflicts(cmOStringStream& w)
+ {
+ bool first = true;
+ for(unsigned int i=0; i < this->OD->OriginalDirectories.size(); ++i)
+ {
+ // Check if this directory conflicts with the entry.
+ std::string const& dir = this->OD->OriginalDirectories[i];
+ if(dir != this->Directory &&
+ cmSystemTools::GetRealPath(dir) !=
+ cmSystemTools::GetRealPath(this->Directory) &&
+ this->FindConflict(dir))
+ {
+ // The library will be found in this directory but it is
+ // supposed to be found in an implicit search directory.
+ if(first)
+ {
+ first = false;
+ w << " ";
+ this->Report(w);
+ w << " in " << this->Directory << " may be hidden by files in:\n";
+ }
+ w << " " << dir << "\n";
+ }
+ }
+ }
+protected:
+ virtual bool FindConflict(std::string const& dir) = 0;
+
+ bool FileMayConflict(std::string const& dir, std::string const& name);
+
+ cmOrderDirectories* OD;
+ cmGlobalGenerator* GlobalGenerator;
+
+ // The location in which the item is supposed to be found.
+ std::string FullPath;
+ std::string Directory;
+ std::string FileName;
+
+ // The index assigned to the directory.
+ int DirectoryIndex;
+};
+
+//----------------------------------------------------------------------------
+bool cmOrderDirectoriesConstraint::FileMayConflict(std::string const& dir,
+ std::string const& name)
+{
+ // Check if the file exists on disk.
+ std::string file = dir;
+ file += "/";
+ file += name;
+ if(cmSystemTools::FileExists(file.c_str(), true))
+ {
+ // The file conflicts only if it is not the same as the original
+ // file due to a symlink or hardlink.
+ return !cmSystemTools::SameFile(this->FullPath.c_str(), file.c_str());
+ }
+
+ // Check if the file will be built by cmake.
+ std::set<std::string> const& files =
+ (this->GlobalGenerator->GetDirectoryContent(dir, false));
+ std::set<std::string>::const_iterator fi = files.find(name);
+ return fi != files.end();
+}
+
+//----------------------------------------------------------------------------
+class cmOrderDirectoriesConstraintSOName: public cmOrderDirectoriesConstraint
+{
+public:
+ cmOrderDirectoriesConstraintSOName(cmOrderDirectories* od,
+ std::string const& file,
+ const char* soname):
+ cmOrderDirectoriesConstraint(od, file), SOName(soname? soname : "")
+ {
+ if(this->SOName.empty())
+ {
+ // Try to guess the soname.
+ std::string soguess;
+ if(cmSystemTools::GuessLibrarySOName(file, soguess))
+ {
+ this->SOName = soguess;
+ }
+ }
+ }
+
+ virtual void Report(std::ostream& e)
+ {
+ e << "runtime library [";
+ if(this->SOName.empty())
+ {
+ e << this->FileName;
+ }
+ else
+ {
+ e << this->SOName;
+ }
+ e << "]";
+ }
+
+ virtual bool FindConflict(std::string const& dir);
+private:
+ // The soname of the shared library if it is known.
+ std::string SOName;
+};
+
+//----------------------------------------------------------------------------
+bool cmOrderDirectoriesConstraintSOName::FindConflict(std::string const& dir)
+{
+ // Determine which type of check to do.
+ if(!this->SOName.empty())
+ {
+ // We have the library soname. Check if it will be found.
+ if(this->FileMayConflict(dir, this->SOName))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ // We do not have the soname. Look for files in the directory
+ // that may conflict.
+ std::set<std::string> const& files =
+ (this->GlobalGenerator
+ ->GetDirectoryContent(dir, true));
+
+ // Get the set of files that might conflict. Since we do not
+ // know the soname just look at all files that start with the
+ // file name. Usually the soname starts with the library name.
+ std::string base = this->FileName;
+ std::set<std::string>::const_iterator first = files.lower_bound(base);
+ ++base[base.size()-1];
+ std::set<std::string>::const_iterator last = files.upper_bound(base);
+ if(first != last)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+class cmOrderDirectoriesConstraintLibrary: public cmOrderDirectoriesConstraint
+{
+public:
+ cmOrderDirectoriesConstraintLibrary(cmOrderDirectories* od,
+ std::string const& file):
+ cmOrderDirectoriesConstraint(od, file)
+ {
+ }
+
+ virtual void Report(std::ostream& e)
+ {
+ e << "link library [" << this->FileName << "]";
+ }
+
+ virtual bool FindConflict(std::string const& dir);
+};
+
+//----------------------------------------------------------------------------
+bool cmOrderDirectoriesConstraintLibrary::FindConflict(std::string const& dir)
+{
+ // We have the library file name. Check if it will be found.
+ if(this->FileMayConflict(dir, this->FileName))
+ {
+ return true;
+ }
+
+ // Now check if the file exists with other extensions the linker
+ // might consider.
+ if(!this->OD->LinkExtensions.empty() &&
+ this->OD->RemoveLibraryExtension.find(this->FileName))
+ {
+ std::string lib = this->OD->RemoveLibraryExtension.match(1);
+ std::string ext = this->OD->RemoveLibraryExtension.match(2);
+ for(std::vector<std::string>::iterator
+ i = this->OD->LinkExtensions.begin();
+ i != this->OD->LinkExtensions.end(); ++i)
+ {
+ if(*i != ext)
+ {
+ std::string fname = lib;
+ fname += *i;
+ if(this->FileMayConflict(dir, fname))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+cmOrderDirectories::cmOrderDirectories(cmGlobalGenerator* gg,
+ cmTarget const* target,
+ const char* purpose)
+{
+ this->GlobalGenerator = gg;
+ this->Target = target;
+ this->Purpose = purpose;
+ this->Computed = false;
+}
+
+//----------------------------------------------------------------------------
+cmOrderDirectories::~cmOrderDirectories()
+{
+ for(std::vector<cmOrderDirectoriesConstraint*>::iterator
+ i = this->ConstraintEntries.begin();
+ i != this->ConstraintEntries.end(); ++i)
+ {
+ delete *i;
+ }
+ for(std::vector<cmOrderDirectoriesConstraint*>::iterator
+ i = this->ImplicitDirEntries.begin();
+ i != this->ImplicitDirEntries.end(); ++i)
+ {
+ delete *i;
+ }
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string> const& cmOrderDirectories::GetOrderedDirectories()
+{
+ if(!this->Computed)
+ {
+ this->Computed = true;
+ this->CollectOriginalDirectories();
+ this->FindConflicts();
+ this->OrderDirectories();
+ }
+ return this->OrderedDirectories;
+}
+
+//----------------------------------------------------------------------------
+void cmOrderDirectories::AddRuntimeLibrary(std::string const& fullPath,
+ const char* soname)
+{
+ // Add the runtime library at most once.
+ if(this->EmmittedConstraintSOName.insert(fullPath).second)
+ {
+ // Implicit link directories need special handling.
+ if(!this->ImplicitDirectories.empty())
+ {
+ std::string dir = cmSystemTools::GetFilenamePath(fullPath);
+
+ if(fullPath.rfind(".framework") != std::string::npos)
+ {
+ static cmsys::RegularExpression
+ splitFramework("^(.*)/(.*).framework/(.*)$");
+ if(splitFramework.find(fullPath) &&
+ (std::string::npos !=
+ splitFramework.match(3).find(splitFramework.match(2))))
+ {
+ dir = splitFramework.match(1);
+ }
+ }
+
+ if(this->ImplicitDirectories.find(dir) !=
+ this->ImplicitDirectories.end())
+ {
+ this->ImplicitDirEntries.push_back(
+ new cmOrderDirectoriesConstraintSOName(this, fullPath, soname));
+ return;
+ }
+ }
+
+ // Construct the runtime information entry for this library.
+ this->ConstraintEntries.push_back(
+ new cmOrderDirectoriesConstraintSOName(this, fullPath, soname));
+ }
+ else
+ {
+ // This can happen if the same library is linked multiple times.
+ // In that case the runtime information check need be done only
+ // once anyway. For shared libs we could add a check in AddItem
+ // to not repeat them.
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmOrderDirectories::AddLinkLibrary(std::string const& fullPath)
+{
+ // Link extension info is required for library constraints.
+ assert(!this->LinkExtensions.empty());
+
+ // Add the link library at most once.
+ if(this->EmmittedConstraintLibrary.insert(fullPath).second)
+ {
+ // Implicit link directories need special handling.
+ if(!this->ImplicitDirectories.empty())
+ {
+ std::string dir = cmSystemTools::GetFilenamePath(fullPath);
+ if(this->ImplicitDirectories.find(dir) !=
+ this->ImplicitDirectories.end())
+ {
+ this->ImplicitDirEntries.push_back(
+ new cmOrderDirectoriesConstraintLibrary(this, fullPath));
+ return;
+ }
+ }
+
+ // Construct the link library entry.
+ this->ConstraintEntries.push_back(
+ new cmOrderDirectoriesConstraintLibrary(this, fullPath));
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmOrderDirectories
+::AddUserDirectories(std::vector<std::string> const& extra)
+{
+ this->UserDirectories.insert(this->UserDirectories.end(),
+ extra.begin(), extra.end());
+}
+
+//----------------------------------------------------------------------------
+void
+cmOrderDirectories
+::AddLanguageDirectories(std::vector<std::string> const& dirs)
+{
+ this->LanguageDirectories.insert(this->LanguageDirectories.end(),
+ dirs.begin(), dirs.end());
+}
+
+//----------------------------------------------------------------------------
+void
+cmOrderDirectories
+::SetImplicitDirectories(std::set<std::string> const& implicitDirs)
+{
+ this->ImplicitDirectories = implicitDirs;
+}
+
+//----------------------------------------------------------------------------
+void
+cmOrderDirectories
+::SetLinkExtensionInfo(std::vector<std::string> const& linkExtensions,
+ std::string const& removeExtRegex)
+{
+ this->LinkExtensions = linkExtensions;
+ this->RemoveLibraryExtension.compile(removeExtRegex.c_str());
+}
+
+//----------------------------------------------------------------------------
+void cmOrderDirectories::CollectOriginalDirectories()
+{
+ // Add user directories specified for inclusion. These should be
+ // indexed first so their original order is preserved as much as
+ // possible subject to the constraints.
+ this->AddOriginalDirectories(this->UserDirectories);
+
+ // Add directories containing constraints.
+ for(unsigned int i=0; i < this->ConstraintEntries.size(); ++i)
+ {
+ this->ConstraintEntries[i]->AddDirectory();
+ }
+
+ // Add language runtime directories last.
+ this->AddOriginalDirectories(this->LanguageDirectories);
+}
+
+//----------------------------------------------------------------------------
+int cmOrderDirectories::AddOriginalDirectory(std::string const& dir)
+{
+ // Add the runtime directory with a unique index.
+ std::map<std::string, int>::iterator i =
+ this->DirectoryIndex.find(dir);
+ if(i == this->DirectoryIndex.end())
+ {
+ std::map<std::string, int>::value_type
+ entry(dir, static_cast<int>(this->OriginalDirectories.size()));
+ i = this->DirectoryIndex.insert(entry).first;
+ this->OriginalDirectories.push_back(dir);
+ }
+
+ return i->second;
+}
+
+//----------------------------------------------------------------------------
+void
+cmOrderDirectories
+::AddOriginalDirectories(std::vector<std::string> const& dirs)
+{
+ for(std::vector<std::string>::const_iterator di = dirs.begin();
+ di != dirs.end(); ++di)
+ {
+ // We never explicitly specify implicit link directories.
+ if(this->ImplicitDirectories.find(*di) !=
+ this->ImplicitDirectories.end())
+ {
+ continue;
+ }
+
+ // Skip the empty string.
+ if(di->empty())
+ {
+ continue;
+ }
+
+ // Add this directory.
+ this->AddOriginalDirectory(*di);
+ }
+}
+
+//----------------------------------------------------------------------------
+struct cmOrderDirectoriesCompare
+{
+ typedef std::pair<int, int> ConflictPair;
+
+ // The conflict pair is unique based on just the directory
+ // (first). The second element is only used for displaying
+ // information about why the entry is present.
+ bool operator()(ConflictPair const& l,
+ ConflictPair const& r)
+ {
+ return l.first == r.first;
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmOrderDirectories::FindConflicts()
+{
+ // Allocate the conflict graph.
+ this->ConflictGraph.resize(this->OriginalDirectories.size());
+ this->DirectoryVisited.resize(this->OriginalDirectories.size(), 0);
+
+ // Find directories conflicting with each entry.
+ for(unsigned int i=0; i < this->ConstraintEntries.size(); ++i)
+ {
+ this->ConstraintEntries[i]->FindConflicts(i);
+ }
+
+ // Clean up the conflict graph representation.
+ for(std::vector<ConflictList>::iterator
+ i = this->ConflictGraph.begin();
+ i != this->ConflictGraph.end(); ++i)
+ {
+ // Sort the outgoing edges for each graph node so that the
+ // original order will be preserved as much as possible.
+ std::sort(i->begin(), i->end());
+
+ // Make the edge list unique so cycle detection will be reliable.
+ ConflictList::iterator last =
+ std::unique(i->begin(), i->end(), cmOrderDirectoriesCompare());
+ i->erase(last, i->end());
+ }
+
+ // Check items in implicit link directories.
+ this->FindImplicitConflicts();
+}
+
+//----------------------------------------------------------------------------
+void cmOrderDirectories::FindImplicitConflicts()
+{
+ // Check for items in implicit link directories that have conflicts
+ // in the explicit directories.
+ cmOStringStream conflicts;
+ for(unsigned int i=0; i < this->ImplicitDirEntries.size(); ++i)
+ {
+ this->ImplicitDirEntries[i]->FindImplicitConflicts(conflicts);
+ }
+
+ // Skip warning if there were no conflicts.
+ std::string text = conflicts.str();
+ if(text.empty())
+ {
+ return;
+ }
+
+ // Warn about the conflicts.
+ cmOStringStream w;
+ w << "Cannot generate a safe " << this->Purpose
+ << " for target " << this->Target->GetName()
+ << " because files in some directories may conflict with "
+ << " libraries in implicit directories:\n"
+ << text
+ << "Some of these libraries may not be found correctly.";
+ this->GlobalGenerator->GetCMakeInstance()
+ ->IssueMessage(cmake::WARNING, w.str(), this->Target->GetBacktrace());
+}
+
+//----------------------------------------------------------------------------
+void cmOrderDirectories::OrderDirectories()
+{
+ // Allow a cycle to be diagnosed once.
+ this->CycleDiagnosed = false;
+ this->WalkId = 0;
+
+ // Iterate through the directories in the original order.
+ for(unsigned int i=0; i < this->OriginalDirectories.size(); ++i)
+ {
+ // Start a new DFS from this node.
+ ++this->WalkId;
+ this->VisitDirectory(i);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmOrderDirectories::VisitDirectory(unsigned int i)
+{
+ // Skip nodes already visited.
+ if(this->DirectoryVisited[i])
+ {
+ if(this->DirectoryVisited[i] == this->WalkId)
+ {
+ // We have reached a node previously visited on this DFS.
+ // There is a cycle.
+ this->DiagnoseCycle();
+ }
+ return;
+ }
+
+ // We are now visiting this node so mark it.
+ this->DirectoryVisited[i] = this->WalkId;
+
+ // Visit the neighbors of the node first.
+ ConflictList const& clist = this->ConflictGraph[i];
+ for(ConflictList::const_iterator j = clist.begin();
+ j != clist.end(); ++j)
+ {
+ this->VisitDirectory(j->first);
+ }
+
+ // Now that all directories required to come before this one have
+ // been emmitted, emit this directory.
+ this->OrderedDirectories.push_back(this->OriginalDirectories[i]);
+}
+
+//----------------------------------------------------------------------------
+void cmOrderDirectories::DiagnoseCycle()
+{
+ // Report the cycle at most once.
+ if(this->CycleDiagnosed)
+ {
+ return;
+ }
+ this->CycleDiagnosed = true;
+
+ // Construct the message.
+ cmOStringStream e;
+ e << "Cannot generate a safe " << this->Purpose
+ << " for target " << this->Target->GetName()
+ << " because there is a cycle in the constraint graph:\n";
+
+ // Display the conflict graph.
+ for(unsigned int i=0; i < this->ConflictGraph.size(); ++i)
+ {
+ ConflictList const& clist = this->ConflictGraph[i];
+ e << " dir " << i << " is [" << this->OriginalDirectories[i] << "]\n";
+ for(ConflictList::const_iterator j = clist.begin();
+ j != clist.end(); ++j)
+ {
+ e << " dir " << j->first << " must precede it due to ";
+ this->ConstraintEntries[j->second]->Report(e);
+ e << "\n";
+ }
+ }
+ e << "Some of these libraries may not be found correctly.";
+ this->GlobalGenerator->GetCMakeInstance()
+ ->IssueMessage(cmake::WARNING, e.str(), this->Target->GetBacktrace());
+}
diff --git a/Source/cmOrderDirectories.h b/Source/cmOrderDirectories.h
new file mode 100644
index 0000000000..07c85dd079
--- /dev/null
+++ b/Source/cmOrderDirectories.h
@@ -0,0 +1,88 @@
+/*============================================================================
+ 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 cmOrderDirectories_h
+#define cmOrderDirectories_h
+
+#include "cmStandardIncludes.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+class cmGlobalGenerator;
+class cmOrderDirectoriesConstraint;
+class cmOrderDirectoriesConstraintLibrary;
+class cmTarget;
+
+/** \class cmOrderDirectories
+ * \brief Compute a safe runtime path order for a set of shared libraries.
+ */
+class cmOrderDirectories
+{
+public:
+ cmOrderDirectories(cmGlobalGenerator* gg, cmTarget const* target,
+ const char* purpose);
+ ~cmOrderDirectories();
+ void AddRuntimeLibrary(std::string const& fullPath, const char* soname = 0);
+ void AddLinkLibrary(std::string const& fullPath);
+ void AddUserDirectories(std::vector<std::string> const& extra);
+ void AddLanguageDirectories(std::vector<std::string> const& dirs);
+ void SetImplicitDirectories(std::set<std::string> const& implicitDirs);
+ void SetLinkExtensionInfo(std::vector<std::string> const& linkExtensions,
+ std::string const& removeExtRegex);
+
+ std::vector<std::string> const& GetOrderedDirectories();
+private:
+ cmGlobalGenerator* GlobalGenerator;
+ cmTarget const* Target;
+ std::string Purpose;
+
+ bool Computed;
+
+ std::vector<std::string> OrderedDirectories;
+
+ std::vector<cmOrderDirectoriesConstraint*> ConstraintEntries;
+ std::vector<cmOrderDirectoriesConstraint*> ImplicitDirEntries;
+ std::vector<std::string> UserDirectories;
+ std::vector<std::string> LanguageDirectories;
+ cmsys::RegularExpression RemoveLibraryExtension;
+ std::vector<std::string> LinkExtensions;
+ std::set<std::string> ImplicitDirectories;
+ std::set<std::string> EmmittedConstraintSOName;
+ std::set<std::string> EmmittedConstraintLibrary;
+ std::vector<std::string> OriginalDirectories;
+ std::map<std::string, int> DirectoryIndex;
+ std::vector<int> DirectoryVisited;
+ void CollectOriginalDirectories();
+ int AddOriginalDirectory(std::string const& dir);
+ void AddOriginalDirectories(std::vector<std::string> const& dirs);
+ void FindConflicts();
+ void FindImplicitConflicts();
+ void OrderDirectories();
+ void VisitDirectory(unsigned int i);
+ void DiagnoseCycle();
+ bool CycleDiagnosed;
+ int WalkId;
+
+ // Adjacency-list representation of runtime path ordering graph.
+ // This maps from directory to those that must come *before* it.
+ // Each entry that must come before is a pair. The first element is
+ // the index of the directory that must come first. The second
+ // element is the index of the runtime library that added the
+ // constraint.
+ typedef std::pair<int, int> ConflictPair;
+ struct ConflictList: public std::vector<ConflictPair> {};
+ std::vector<ConflictList> ConflictGraph;
+
+ friend class cmOrderDirectoriesConstraint;
+ friend class cmOrderDirectoriesConstraintLibrary;
+};
+
+#endif
diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx
new file mode 100644
index 0000000000..5016493bd6
--- /dev/null
+++ b/Source/cmOutputRequiredFilesCommand.cxx
@@ -0,0 +1,244 @@
+/*============================================================================
+ 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 "cmOutputRequiredFilesCommand.h"
+#include "cmMakeDepend.h"
+#include <cmsys/FStream.hxx>
+
+class cmLBDepend : public cmMakeDepend
+{
+ /**
+ * Compute the depend information for this class.
+ */
+ virtual void DependWalk(cmDependInformation* info);
+};
+
+void cmLBDepend::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"))
+ {
+ // 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
+ {
+ 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))
+ {
+ 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());
+ /// add the cxx file if it exists
+ std::string cxxFile = includeFile;
+ std::string::size_type pos = cxxFile.rfind('.');
+ if(pos != std::string::npos)
+ {
+ 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();
+ 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 + ".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 + ".c";
+ 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()))
+ {
+ 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());
+ }
+ }
+ }
+ }
+}
+
+// cmOutputRequiredFilesCommand
+bool cmOutputRequiredFilesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(this->Disallowed(cmPolicies::CMP0032,
+ "The output_required_files command should not be called; see CMP0032."))
+ { return true; }
+ if(args.size() != 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // store the arg for final pass
+ this->File = args[0];
+ this->OutputFile = args[1];
+
+ // compute the list of files
+ cmLBDepend md;
+ md.SetMakefile(this->Makefile);
+ md.AddSearchPath(this->Makefile->GetStartDirectory());
+ // find the depends for a file
+ const cmDependInformation *info = md.FindDependencies(this->File.c_str());
+ if (info)
+ {
+ // write them out
+ FILE *fout = cmsys::SystemTools::Fopen(this->OutputFile.c_str(),"w");
+ if(!fout)
+ {
+ std::string err = "Can not open output file: ";
+ err += this->OutputFile;
+ this->SetError(err);
+ return false;
+ }
+ std::set<cmDependInformation const*> visited;
+ this->ListDependencies(info,fout, &visited);
+ fclose(fout);
+ }
+
+ return true;
+}
+
+void cmOutputRequiredFilesCommand::
+ListDependencies(cmDependInformation const *info,
+ FILE *fout,
+ std::set<cmDependInformation const*> *visited)
+{
+ // add info to the visited set
+ visited->insert(info);
+ // now recurse with info's dependencies
+ for(cmDependInformation::DependencySetType::const_iterator d =
+ info->DependencySet.begin();
+ d != info->DependencySet.end(); ++d)
+ {
+ if (visited->find(*d) == visited->end())
+ {
+ if(info->FullPath != "")
+ {
+ std::string tmp = (*d)->FullPath;
+ std::string::size_type pos = tmp.rfind('.');
+ if(pos != std::string::npos && (tmp.substr(pos) != ".h"))
+ {
+ tmp = tmp.substr(0, pos);
+ fprintf(fout,"%s\n",(*d)->FullPath.c_str());
+ }
+ }
+ this->ListDependencies(*d,fout,visited);
+ }
+ }
+}
+
diff --git a/Source/cmOutputRequiredFilesCommand.h b/Source/cmOutputRequiredFilesCommand.h
new file mode 100644
index 0000000000..95eba38ecf
--- /dev/null
+++ b/Source/cmOutputRequiredFilesCommand.h
@@ -0,0 +1,38 @@
+/*============================================================================
+ 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 cmOutputRequiredFilesCommand_h
+#define cmOutputRequiredFilesCommand_h
+
+#include "cmCommand.h"
+#include "cmMakeDepend.h"
+
+class cmOutputRequiredFilesCommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmOutputRequiredFilesCommand, cmCommand);
+ virtual cmCommand* Clone() { return new cmOutputRequiredFilesCommand; }
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+ virtual std::string GetName() const { return "output_required_files";}
+ virtual bool IsDiscouraged() const { return true; }
+
+ void ListDependencies(cmDependInformation const *info,
+ FILE *fout,
+ std::set<cmDependInformation const*> *visited);
+private:
+ std::string File;
+ std::string OutputFile;
+};
+
+
+
+#endif
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
new file mode 100644
index 0000000000..a420f5958e
--- /dev/null
+++ b/Source/cmPolicies.cxx
@@ -0,0 +1,676 @@
+#include "cmPolicies.h"
+#include "cmake.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmVersion.h"
+#include "cmVersionMacros.h"
+#include <map>
+#include <set>
+#include <queue>
+#include <assert.h>
+
+const char* cmPolicies::PolicyStatusNames[] = {
+ "OLD", "WARN", "NEW", "REQUIRED_IF_USED", "REQUIRED_ALWAYS"
+};
+
+class cmPolicy
+{
+public:
+ cmPolicy(cmPolicies::PolicyID iD,
+ const char *idString,
+ const char *shortDescription,
+ unsigned int majorVersionIntroduced,
+ unsigned int minorVersionIntroduced,
+ unsigned int patchVersionIntroduced,
+ cmPolicies::PolicyStatus status)
+ {
+ if (!idString || !shortDescription)
+ {
+ cmSystemTools::Error("Attempt to define a policy without "
+ "all parameters being specified!");
+ return;
+ }
+ this->ID = iD;
+ this->IDString = idString;
+ this->ShortDescription = shortDescription;
+ this->MajorVersionIntroduced = majorVersionIntroduced;
+ this->MinorVersionIntroduced = minorVersionIntroduced;
+ this->PatchVersionIntroduced = patchVersionIntroduced;
+ this->Status = status;
+ }
+
+ std::string GetVersionString()
+ {
+ cmOStringStream v;
+ v << this->MajorVersionIntroduced << "." << this->MinorVersionIntroduced;
+ if(this->PatchVersionIntroduced > 0)
+ {
+ v << "." << this->PatchVersionIntroduced;
+ }
+ return v.str();
+ }
+
+ bool IsPolicyNewerThan(unsigned int majorV,
+ unsigned int minorV,
+ unsigned int patchV)
+ {
+ if (majorV < this->MajorVersionIntroduced)
+ {
+ return true;
+ }
+ if (majorV > this->MajorVersionIntroduced)
+ {
+ return false;
+ }
+ if (minorV < this->MinorVersionIntroduced)
+ {
+ return true;
+ }
+ if (minorV > this->MinorVersionIntroduced)
+ {
+ return false;
+ }
+ return (patchV < this->PatchVersionIntroduced);
+ }
+
+ cmPolicies::PolicyID ID;
+ std::string IDString;
+ std::string ShortDescription;
+ unsigned int MajorVersionIntroduced;
+ unsigned int MinorVersionIntroduced;
+ unsigned int PatchVersionIntroduced;
+ cmPolicies::PolicyStatus Status;
+};
+
+cmPolicies::cmPolicies()
+{
+ // define all the policies
+ this->DefinePolicy(
+ CMP0000, "CMP0000",
+ "A minimum required CMake version must be specified.",
+ 2,6,0, cmPolicies::WARN
+ );
+
+ this->DefinePolicy(
+ CMP0001, "CMP0001",
+ "CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.",
+ 2,6,0, cmPolicies::WARN
+ );
+
+ this->DefinePolicy(
+ CMP0002, "CMP0002",
+ "Logical target names must be globally unique.",
+ 2,6,0, cmPolicies::WARN
+ );
+
+ this->DefinePolicy(
+ CMP0003, "CMP0003",
+ "Libraries linked via full path no longer produce linker search paths.",
+ 2,6,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0004, "CMP0004",
+ "Libraries linked may not have leading or trailing whitespace.",
+ 2,6,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0005, "CMP0005",
+ "Preprocessor definition values are now escaped automatically.",
+ 2,6,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0006, "CMP0006",
+ "Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.",
+ 2,6,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0007, "CMP0007",
+ "list command no longer ignores empty elements.",
+ 2,6,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0008, "CMP0008",
+ "Libraries linked by full-path must have a valid library file name.",
+ 2,6,1, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0009, "CMP0009",
+ "FILE GLOB_RECURSE calls should not follow symlinks by default.",
+ 2,6,2, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0010, "CMP0010",
+ "Bad variable reference syntax is an error.",
+ 2,6,3, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0011, "CMP0011",
+ "Included scripts do automatic cmake_policy PUSH and POP.",
+ 2,6,3, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0012, "CMP0012",
+ "if() recognizes numbers and boolean constants.",
+ 2,8,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0013, "CMP0013",
+ "Duplicate binary directories are not allowed.",
+ 2,8,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0014, "CMP0014",
+ "Input directories must have CMakeLists.txt.",
+ 2,8,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0015, "CMP0015",
+ "link_directories() treats paths relative to the source dir.",
+ 2,8,1, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0016, "CMP0016",
+ "target_link_libraries() reports error if its only argument "
+ "is not a target.",
+ 2,8,3, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0017, "CMP0017",
+ "Prefer files from the CMake module directory when including from there.",
+ 2,8,4, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0018, "CMP0018",
+ "Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.",
+ 2,8,9, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0019, "CMP0019",
+ "Do not re-expand variables in include and link information.",
+ 2,8,11, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0020, "CMP0020",
+ "Automatically link Qt executables to qtmain target on Windows.",
+ 2,8,11, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0021, "CMP0021",
+ "Fatal error on relative paths in INCLUDE_DIRECTORIES target property.",
+ 2,8,12, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0022, "CMP0022",
+ "INTERFACE_LINK_LIBRARIES defines the link interface.",
+ 2,8,12, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0023, "CMP0023",
+ "Plain and keyword target_link_libraries signatures cannot be mixed.",
+ 2,8,12, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0024, "CMP0024",
+ "Disallow include export result.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0025, "CMP0025",
+ "Compiler id for Apple Clang is now AppleClang.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0026, "CMP0026",
+ "Disallow use of the LOCATION target property.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0027, "CMP0027",
+ "Conditionally linked imported targets with missing include directories.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0028, "CMP0028",
+ "Double colon in target name means ALIAS or IMPORTED target.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0029, "CMP0029",
+ "The subdir_depends command should not be called.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0030, "CMP0030",
+ "The use_mangled_mesa command should not be called.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0031, "CMP0031",
+ "The load_command command should not be called.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0032, "CMP0032",
+ "The output_required_files command should not be called.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0033, "CMP0033",
+ "The export_library_dependencies command should not be called.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0034, "CMP0034",
+ "The utility_source command should not be called.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0035, "CMP0035",
+ "The variable_requires command should not be called.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0036, "CMP0036",
+ "The build_name command should not be called.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0037, "CMP0037",
+ "Target names should not be reserved and should match a validity pattern.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0038, "CMP0038",
+ "Targets may not link directly to themselves.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0039, "CMP0039",
+ "Utility targets may not have link dependencies.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0040, "CMP0040",
+ "The target in the TARGET signature of add_custom_command() must exist.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0041, "CMP0041",
+ "Error on relative include with generator expression.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0042, "CMP0042",
+ "MACOSX_RPATH is enabled by default.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0043, "CMP0043",
+ "Ignore COMPILE_DEFINITIONS_<Config> properties.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0044, "CMP0044",
+ "Case sensitive <LANG>_COMPILER_ID generator expressions.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0045, "CMP0045",
+ "Error on non-existent target in get_target_property.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0046, "CMP0046",
+ "Error on non-existent dependency in add_dependencies.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0047, "CMP0047",
+ "Use QCC compiler id for the qcc drivers on QNX.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0048, "CMP0048",
+ "project() command manages VERSION variables.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0049, "CMP0049",
+ "Do not expand variables in target source entries.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0050, "CMP0050",
+ "Disallow add_custom_command SOURCE signatures.",
+ 3,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0051, "CMP0051",
+ "List TARGET_OBJECTS in SOURCES target property.",
+ 3,1,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0052, "CMP0052",
+ "Reject source and build dirs in installed "
+ "INTERFACE_INCLUDE_DIRECTORIES.",
+ 3,1,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0053, "CMP0053",
+ "Simplify variable reference and escape sequence evaluation.",
+ 3,1,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0054, "CMP0054",
+ "Only interpret if() arguments as variables or keywords when unquoted.",
+ 3,1,0, cmPolicies::WARN);
+}
+
+cmPolicies::~cmPolicies()
+{
+ // free the policies
+ std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
+ = this->Policies.begin();
+ for (;i != this->Policies.end(); ++i)
+ {
+ delete i->second;
+ }
+}
+
+void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD,
+ const char *idString,
+ const char *shortDescription,
+ unsigned int majorVersionIntroduced,
+ unsigned int minorVersionIntroduced,
+ unsigned int patchVersionIntroduced,
+ cmPolicies::PolicyStatus status)
+{
+ // a policy must be unique and can only be defined once
+ if (this->Policies.find(iD) != this->Policies.end())
+ {
+ cmSystemTools::Error("Attempt to redefine a CMake policy for policy "
+ "ID ", this->GetPolicyIDString(iD).c_str());
+ return;
+ }
+
+ this->Policies[iD] = new cmPolicy(iD, idString,
+ shortDescription,
+ majorVersionIntroduced,
+ minorVersionIntroduced,
+ patchVersionIntroduced,
+ status);
+ this->PolicyStringMap[idString] = iD;
+}
+
+//----------------------------------------------------------------------------
+bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
+ const char *version)
+{
+ std::string ver = "2.4.0";
+
+ if (version && strlen(version) > 0)
+ {
+ ver = version;
+ }
+
+ unsigned int majorVer = 2;
+ unsigned int minorVer = 0;
+ unsigned int patchVer = 0;
+ unsigned int tweakVer = 0;
+
+ // parse the string
+ if(sscanf(ver.c_str(), "%u.%u.%u.%u",
+ &majorVer, &minorVer, &patchVer, &tweakVer) < 2)
+ {
+ cmOStringStream e;
+ e << "Invalid policy version value \"" << ver << "\". "
+ << "A numeric major.minor[.patch[.tweak]] must be given.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ // it is an error if the policy version is less than 2.4
+ if (majorVer < 2 || (majorVer == 2 && minorVer < 4))
+ {
+ mf->IssueMessage(cmake::FATAL_ERROR,
+ "Compatibility with CMake < 2.4 is not supported by CMake >= 3.0. "
+ "For compatibility with older versions please use any CMake 2.8.x "
+ "release or lower.");
+ return false;
+ }
+
+ // It is an error if the policy version is greater than the running
+ // CMake.
+ if (majorVer > cmVersion::GetMajorVersion() ||
+ (majorVer == cmVersion::GetMajorVersion() &&
+ minorVer > cmVersion::GetMinorVersion()) ||
+ (majorVer == cmVersion::GetMajorVersion() &&
+ minorVer == cmVersion::GetMinorVersion() &&
+ patchVer > cmVersion::GetPatchVersion()) ||
+ (majorVer == cmVersion::GetMajorVersion() &&
+ minorVer == cmVersion::GetMinorVersion() &&
+ patchVer == cmVersion::GetPatchVersion() &&
+ tweakVer > cmVersion::GetTweakVersion()))
+ {
+ cmOStringStream e;
+ e << "An attempt was made to set the policy version of CMake to \""
+ << version << "\" which is greater than this version of CMake. "
+ << "This is not allowed because the greater version may have new "
+ << "policies not known to this CMake. "
+ << "You may need a newer CMake version to build this project.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ // now loop over all the policies and set them as appropriate
+ std::vector<cmPolicies::PolicyID> ancientPolicies;
+ for(std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
+ = this->Policies.begin(); i != this->Policies.end(); ++i)
+ {
+ if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer))
+ {
+ if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
+ {
+ ancientPolicies.push_back(i->first);
+ }
+ else
+ {
+ cmPolicies::PolicyStatus status = cmPolicies::WARN;
+ if(!this->GetPolicyDefault(mf, i->second->IDString, &status) ||
+ !mf->SetPolicy(i->second->ID, status))
+ {
+ return false;
+ }
+ }
+ }
+ else
+ {
+ if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
+ {
+ return false;
+ }
+ }
+ }
+
+ // Make sure the project does not use any ancient policies.
+ if(!ancientPolicies.empty())
+ {
+ this->DiagnoseAncientPolicies(ancientPolicies,
+ majorVer, minorVer, patchVer, mf);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmPolicies::GetPolicyDefault(cmMakefile* mf, std::string const& policy,
+ cmPolicies::PolicyStatus* defaultSetting)
+{
+ std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy;
+ std::string defaultValue = mf->GetSafeDefinition(defaultVar);
+ if(defaultValue == "NEW")
+ {
+ *defaultSetting = cmPolicies::NEW;
+ }
+ else if(defaultValue == "OLD")
+ {
+ *defaultSetting = cmPolicies::OLD;
+ }
+ else if(defaultValue == "")
+ {
+ *defaultSetting = cmPolicies::WARN;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << defaultVar << " has value \"" << defaultValue
+ << "\" but must be \"OLD\", \"NEW\", or \"\" (empty).";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ return true;
+}
+
+bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
+{
+ if (!id || strlen(id) < 1)
+ {
+ return false;
+ }
+ std::map<std::string,cmPolicies::PolicyID>::iterator pos =
+ this->PolicyStringMap.find(id);
+ if (pos == this->PolicyStringMap.end())
+ {
+ return false;
+ }
+ pid = pos->second;
+ return true;
+}
+
+std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid)
+{
+ std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
+ this->Policies.find(pid);
+ if (pos == this->Policies.end())
+ {
+ return "";
+ }
+ return pos->second->IDString;
+}
+
+
+///! return a warning string for a given policy
+std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id)
+{
+ std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
+ this->Policies.find(id);
+ if (pos == this->Policies.end())
+ {
+ cmSystemTools::Error(
+ "Request for warning text for undefined policy!");
+ return "Request for warning text for undefined policy!";
+ }
+
+ cmOStringStream msg;
+ msg <<
+ "Policy " << pos->second->IDString << " is not set: "
+ "" << pos->second->ShortDescription << " "
+ "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
+ "policy details. "
+ "Use the cmake_policy command to set the policy "
+ "and suppress this warning.";
+ return msg.str();
+}
+
+
+///! return an error string for when a required policy is unspecified
+std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id)
+{
+ std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
+ this->Policies.find(id);
+ if (pos == this->Policies.end())
+ {
+ cmSystemTools::Error(
+ "Request for error text for undefined policy!");
+ return "Request for error text for undefined policy!";
+ }
+
+ cmOStringStream error;
+ error <<
+ "Policy " << pos->second->IDString << " is not set to NEW: "
+ "" << pos->second->ShortDescription << " "
+ "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
+ "policy details. "
+ "CMake now requires this policy to be set to NEW by the project. "
+ "The policy may be set explicitly using the code\n"
+ " cmake_policy(SET " << pos->second->IDString << " NEW)\n"
+ "or by upgrading all policies with the code\n"
+ " cmake_policy(VERSION " << pos->second->GetVersionString() <<
+ ") # or later\n"
+ "Run \"cmake --help-command cmake_policy\" for more information.";
+ return error.str();
+}
+
+///! Get the default status for a policy
+cmPolicies::PolicyStatus
+cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id)
+{
+ // if the policy is not know then what?
+ std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
+ this->Policies.find(id);
+ if (pos == this->Policies.end())
+ {
+ // TODO is this right?
+ return cmPolicies::WARN;
+ }
+
+ return pos->second->Status;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
+{
+ std::string pid = this->GetPolicyIDString(id);
+ cmOStringStream e;
+ e << "Policy " << pid << " may not be set to OLD behavior because this "
+ << "version of CMake no longer supports it. "
+ << "The policy was introduced in "
+ << "CMake version " << this->Policies[id]->GetVersionString()
+ << ", and use of NEW behavior is now required."
+ << "\n"
+ << "Please either update your CMakeLists.txt files to conform to "
+ << "the new behavior or use an older version of CMake that still "
+ << "supports the old behavior. "
+ << "Run cmake --help-policy " << pid << " for more information.";
+ return e.str();
+}
+
+//----------------------------------------------------------------------------
+void
+cmPolicies::DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
+ unsigned int majorVer,
+ unsigned int minorVer,
+ unsigned int patchVer,
+ cmMakefile* mf)
+{
+ cmOStringStream e;
+ e << "The project requests behavior compatible with CMake version \""
+ << majorVer << "." << minorVer << "." << patchVer
+ << "\", which requires the OLD behavior for some policies:\n";
+ for(std::vector<PolicyID>::const_iterator
+ i = ancient.begin(); i != ancient.end(); ++i)
+ {
+ cmPolicy const* policy = this->Policies[*i];
+ e << " " << policy->IDString << ": " << policy->ShortDescription << "\n";
+ }
+ e << "However, this version of CMake no longer supports the OLD "
+ << "behavior for these policies. "
+ << "Please either update your CMakeLists.txt files to conform to "
+ << "the new behavior or use an older version of CMake that still "
+ << "supports the old behavior.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
new file mode 100644
index 0000000000..7c73da82bd
--- /dev/null
+++ b/Source/cmPolicies.h
@@ -0,0 +1,168 @@
+/*============================================================================
+ 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 cmPolicies_h
+#define cmPolicies_h
+
+#include "cmCustomCommand.h"
+
+class cmake;
+class cmMakefile;
+class cmPolicy;
+
+/** \class cmPolicies
+ * \brief Handles changes in CMake behavior and policies
+ *
+ * See the cmake wiki section on
+ * <a href="http://www.cmake.org/Wiki/CMake/Policies">policies</a>
+ * for an overview of this class's purpose
+ */
+class cmPolicies
+{
+public:
+ cmPolicies();
+ ~cmPolicies();
+
+ /// Status of a policy
+ enum PolicyStatus {
+ OLD, ///< Use old behavior
+ WARN, ///< Use old behavior but issue a warning
+ NEW, ///< Use new behavior
+ /// Issue an error if user doesn't set policy status to NEW and hits the
+ /// check
+ REQUIRED_IF_USED,
+ REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW.
+ };
+ static const char* PolicyStatusNames[];
+
+ /// Policy identifiers
+ enum PolicyID
+ {
+ CMP0000, ///< Policy version specification
+ CMP0001, ///< Ignore old compatibility variable
+ CMP0002, ///< Target names must be unique
+ CMP0003, ///< Linking does not include extra -L paths
+ CMP0004, ///< Libraries linked may not have leading or trailing whitespace
+ CMP0005, ///< Definition value escaping
+ CMP0006, ///< BUNDLE install rules needed for MACOSX_BUNDLE targets
+ CMP0007, ///< list command handling of empty elements
+ CMP0008, ///< Full-path libraries must be a valid library file name
+ CMP0009, ///< GLOB_RECURSE should not follow symlinks by default
+ CMP0010, ///< Bad variable reference syntax is an error
+ CMP0011, ///< Strong policy scope for include and find_package
+ CMP0012, ///< Recognize numbers and boolean constants in if()
+ CMP0013, ///< Duplicate binary directories not allowed
+ CMP0014, ///< Input directories must have CMakeLists.txt
+ CMP0015, ///< link_directories() treats paths relative to source dir
+ /// target_link_libraries() fails if only argument is not a target
+ CMP0016,
+ CMP0017, ///< Prefer files in CMAKE_ROOT when including from CMAKE_ROOT
+ CMP0018, ///< Ignore language flags for shared libs, and adhere to
+ /// POSITION_INDEPENDENT_CODE property and *_COMPILE_OPTIONS_PI{E,C}
+ /// instead.
+ CMP0019, ///< No variable re-expansion in include and link info
+ CMP0020, ///< Automatically link Qt executables to qtmain target
+ CMP0021, ///< Fatal error on relative paths in INCLUDE_DIRECTORIES
+ /// target property
+ CMP0022, ///< INTERFACE_LINK_LIBRARIES defines the link interface
+ CMP0023, ///< Disallow mixing keyword and plain tll signatures
+ CMP0024, ///< Disallow including export() result.
+ CMP0025, ///< Compiler id for Apple Clang is now AppleClang
+ CMP0026, ///< Disallow use of the LOCATION target property.
+ CMP0027, ///< Conditionally linked imported targets with missing include
+ /// directories.
+ CMP0028, ///< Double colon in target name means ALIAS or IMPORTED target.
+ CMP0029, ///< Disallow command: subdir_depends
+ CMP0030, ///< Disallow command: use_mangled_mesa
+ CMP0031, ///< Disallow command: load_command
+ CMP0032, ///< Disallow command: output_required_files
+ CMP0033, ///< Disallow command: export_library_dependencies
+ CMP0034, ///< Disallow command: utility_source
+ CMP0035, ///< Disallow command: variable_requires
+ CMP0036, ///< Disallow command: build_name
+ CMP0037, ///< Target names should not be reserved and
+ /// should match a validity pattern.
+ CMP0038, ///< Targets may not link directly to themselves
+ CMP0039, ///< Utility targets may not have link dependencies
+ CMP0040, ///< The target in the TARGET signature of
+ /// add_custom_command() must exist.
+ CMP0041, ///< Error on relative include with generator expression
+ CMP0042, ///< Enable MACOSX_RPATH by default
+ CMP0043, ///< Ignore COMPILE_DEFINITIONS_<Config> properties
+ CMP0044, ///< Case sensitive <LANG>_COMPILER_ID generator expressions
+ CMP0045, ///< Error on non-existent target in get_target_property
+ CMP0046, ///< Error on non-existent dependency in add_dependencies
+ CMP0047, ///< Use QCC compiler id for the qcc drivers on QNX.
+ CMP0048, ///< project() command manages VERSION variables
+ CMP0049, ///< Do not expand variables in target source entries
+ CMP0050, ///< Disallow add_custom_command SOURCE signatures
+ CMP0051, ///< List TARGET_OBJECTS in SOURCES target property
+ CMP0052, ///< Reject source and build dirs in installed
+ /// INTERFACE_INCLUDE_DIRECTORIES
+
+ CMP0053, ///< Simplify variable reference and escape sequence evaluation
+ CMP0054, ///< Only interpret if() arguments as variables
+ /// or keywords when unquoted.
+
+ /** \brief Always the last entry.
+ *
+ * Useful mostly to avoid adding a comma the last policy when adding a new
+ * one.
+ */
+ CMPCOUNT
+ };
+
+ ///! convert a string policy ID into a number
+ bool GetPolicyID(const char *id, /* out */ cmPolicies::PolicyID &pid);
+ std::string GetPolicyIDString(cmPolicies::PolicyID pid);
+
+ ///! Get the default status for a policy
+ cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
+
+ ///! Define a Policy for CMake
+ void DefinePolicy(cmPolicies::PolicyID id,
+ const char *stringID,
+ const char *shortDescription,
+ unsigned int majorVersionIntroduced,
+ unsigned int minorVersionIntroduced,
+ unsigned int patchVersionIntroduced,
+ cmPolicies::PolicyStatus status);
+
+ ///! Set a policy level for this listfile
+ bool ApplyPolicyVersion(cmMakefile *mf, const char *version);
+
+ ///! return a warning string for a given policy
+ std::string GetPolicyWarning(cmPolicies::PolicyID id);
+
+ ///! return an error string for when a required policy is unspecified
+ std::string GetRequiredPolicyError(cmPolicies::PolicyID id);
+
+ ///! return an error string for when a required policy is unspecified
+ std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
+
+ /** Represent a set of policy values. */
+ typedef std::map<PolicyID, PolicyStatus> PolicyMap;
+
+ private:
+ // might have to make these internal for VS6 not sure yet
+ std::map<PolicyID,cmPolicy *> Policies;
+ std::map<std::string,PolicyID> PolicyStringMap;
+
+ void DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
+ unsigned int majorVer, unsigned int minorVer,
+ unsigned int patchVer, cmMakefile* mf);
+
+ bool GetPolicyDefault(cmMakefile* mf, std::string const& policy,
+ cmPolicies::PolicyStatus* defaultStatus);
+
+};
+
+#endif
diff --git a/Source/cmProcessTools.cxx b/Source/cmProcessTools.cxx
new file mode 100644
index 0000000000..d2f7bf3208
--- /dev/null
+++ b/Source/cmProcessTools.cxx
@@ -0,0 +1,90 @@
+/*============================================================================
+ 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 "cmProcessTools.h"
+
+#include <cmsys/Process.h>
+
+//----------------------------------------------------------------------------
+void cmProcessTools::RunProcess(struct cmsysProcess_s* cp,
+ OutputParser* out, OutputParser* err)
+{
+ cmsysProcess_Execute(cp);
+ char* data = 0;
+ int length = 0;
+ int p;
+ while((out||err) && (p=cmsysProcess_WaitForData(cp, &data, &length, 0), p))
+ {
+ if(out && p == cmsysProcess_Pipe_STDOUT)
+ {
+ if(!out->Process(data, length))
+ {
+ out = 0;
+ }
+ }
+ else if(err && p == cmsysProcess_Pipe_STDERR)
+ {
+ if(!err->Process(data, length))
+ {
+ err = 0;
+ }
+ }
+ }
+ cmsysProcess_WaitForExit(cp, 0);
+}
+
+
+//----------------------------------------------------------------------------
+cmProcessTools::LineParser::LineParser(char sep, bool ignoreCR):
+ Separator(sep), IgnoreCR(ignoreCR), Log(0), Prefix(0), LineEnd('\0')
+{
+}
+
+//----------------------------------------------------------------------------
+void cmProcessTools::LineParser::SetLog(std::ostream* log, const char* prefix)
+{
+ this->Log = log;
+ this->Prefix = prefix? prefix : "";
+}
+
+//----------------------------------------------------------------------------
+bool cmProcessTools::LineParser::ProcessChunk(const char* first, int length)
+{
+ const char* last = first + length;
+ for(const char* c = first; c != last; ++c)
+ {
+ if(*c == this->Separator || *c == '\0')
+ {
+ this->LineEnd = *c;
+
+ // Log this line.
+ if(this->Log && this->Prefix)
+ {
+ *this->Log << this->Prefix << this->Line << "\n";
+ }
+
+ // Hand this line to the subclass implementation.
+ if(!this->ProcessLine())
+ {
+ this->Line = "";
+ return false;
+ }
+
+ this->Line = "";
+ }
+ else if(*c != '\r' || !this->IgnoreCR)
+ {
+ // Append this character to the line under construction.
+ this->Line.append(1, *c);
+ }
+ }
+ return true;
+}
diff --git a/Source/cmProcessTools.h b/Source/cmProcessTools.h
new file mode 100644
index 0000000000..439726dd09
--- /dev/null
+++ b/Source/cmProcessTools.h
@@ -0,0 +1,82 @@
+/*============================================================================
+ 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 cmProcessTools_h
+#define cmProcessTools_h
+
+#include "cmStandardIncludes.h"
+
+/** \class cmProcessTools
+ * \brief Helper classes for process output parsing
+ *
+ */
+class cmProcessTools
+{
+public:
+ /** Abstract interface for process output parsers. */
+ class OutputParser
+ {
+ public:
+ /** Process the given output data from a tool. Processing may be
+ done incrementally. Returns true if the parser is interested
+ in any more data and false if it is done. */
+ bool Process(const char* data, int length)
+ { return this->ProcessChunk(data, length); }
+ bool Process(const char* data)
+ { return this->Process(data, static_cast<int>(strlen(data))); }
+
+ virtual ~OutputParser() {}
+ protected:
+ /** Implement in a subclass to process a chunk of data. It should
+ return true only if it is interested in more data. */
+ virtual bool ProcessChunk(const char* data, int length) = 0;
+ };
+
+ /** Process output parser that extracts one line at a time. */
+ class LineParser: public OutputParser
+ {
+ public:
+ /** Construct with line separation character and choose whether to
+ ignore carriage returns. */
+ LineParser(char sep = '\n', bool ignoreCR = true);
+
+ /** Configure logging of lines as they are extracted. */
+ void SetLog(std::ostream* log, const char* prefix);
+ protected:
+ char Separator;
+ bool IgnoreCR;
+ std::ostream* Log;
+ const char* Prefix;
+ char LineEnd;
+ std::string Line;
+ virtual bool ProcessChunk(const char* data, int length);
+
+ /** Implement in a subclass to process one line of input. It
+ should return true only if it is interested in more data. */
+ virtual bool ProcessLine() = 0;
+ };
+
+ /** Trivial line handler for simple logging. */
+ class OutputLogger: public LineParser
+ {
+ public:
+ OutputLogger(std::ostream& log, const char* prefix = 0)
+ { this->SetLog(&log, prefix); }
+ private:
+ virtual bool ProcessLine() { return true; }
+ };
+
+ /** Run a process and send output to given parsers. */
+ static void RunProcess(struct cmsysProcess_s* cp,
+ OutputParser* out, OutputParser* err = 0);
+};
+
+#endif
diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx
new file mode 100644
index 0000000000..12318c8afa
--- /dev/null
+++ b/Source/cmProjectCommand.cxx
@@ -0,0 +1,253 @@
+/*============================================================================
+ 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 "cmProjectCommand.h"
+
+// cmProjectCommand
+bool cmProjectCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("PROJECT called with incorrect number of arguments");
+ return false;
+ }
+ this->Makefile->SetProjectName(args[0].c_str());
+
+ std::string bindir = args[0];
+ bindir += "_BINARY_DIR";
+ std::string srcdir = args[0];
+ srcdir += "_SOURCE_DIR";
+
+ this->Makefile->AddCacheDefinition
+ (bindir,
+ this->Makefile->GetCurrentOutputDirectory(),
+ "Value Computed by CMake", cmCacheManager::STATIC);
+ this->Makefile->AddCacheDefinition
+ (srcdir,
+ this->Makefile->GetCurrentDirectory(),
+ "Value Computed by CMake", cmCacheManager::STATIC);
+
+ bindir = "PROJECT_BINARY_DIR";
+ srcdir = "PROJECT_SOURCE_DIR";
+
+ this->Makefile->AddDefinition(bindir,
+ this->Makefile->GetCurrentOutputDirectory());
+ this->Makefile->AddDefinition(srcdir,
+ this->Makefile->GetCurrentDirectory());
+
+ this->Makefile->AddDefinition("PROJECT_NAME", args[0].c_str());
+
+ // Set the CMAKE_PROJECT_NAME variable to be the highest-level
+ // project name in the tree. If there are two project commands
+ // in the same CMakeLists.txt file, and it is the top level
+ // CMakeLists.txt file, then go with the last one, so that
+ // CMAKE_PROJECT_NAME will match PROJECT_NAME, and cmake --build
+ // will work.
+ if(!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME")
+ || (this->Makefile->GetLocalGenerator()->GetParent() == 0) )
+ {
+ this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", args[0].c_str());
+ this->Makefile->AddCacheDefinition
+ ("CMAKE_PROJECT_NAME",
+ args[0].c_str(),
+ "Value Computed by CMake", cmCacheManager::STATIC);
+ }
+
+ bool haveVersion = false;
+ bool haveLanguages = false;
+ std::string version;
+ std::vector<std::string> languages;
+ enum Doing { DoingLanguages, DoingVersion };
+ Doing doing = DoingLanguages;
+ for(size_t i = 1; i < args.size(); ++i)
+ {
+ if(args[i] == "LANGUAGES")
+ {
+ if(haveLanguages)
+ {
+ this->Makefile->IssueMessage
+ (cmake::FATAL_ERROR, "LANGUAGES may be specified at most once.");
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+ haveLanguages = true;
+ doing = DoingLanguages;
+ }
+ else if (args[i] == "VERSION")
+ {
+ if(haveVersion)
+ {
+ this->Makefile->IssueMessage
+ (cmake::FATAL_ERROR, "VERSION may be specified at most once.");
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+ haveVersion = true;
+ doing = DoingVersion;
+ }
+ else if(doing == DoingVersion)
+ {
+ doing = DoingLanguages;
+ version = args[i];
+ }
+ else // doing == DoingLanguages
+ {
+ languages.push_back(args[i]);
+ }
+ }
+
+ if (haveVersion && !haveLanguages && !languages.empty())
+ {
+ this->Makefile->IssueMessage
+ (cmake::FATAL_ERROR,
+ "project with VERSION must use LANGUAGES before language names.");
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+ if (haveLanguages && languages.empty())
+ {
+ languages.push_back("NONE");
+ }
+
+ cmPolicies::PolicyStatus cmp0048 =
+ this->Makefile->GetPolicyStatus(cmPolicies::CMP0048);
+ if (haveVersion)
+ {
+ // Set project VERSION variables to given values
+ if (cmp0048 == cmPolicies::OLD ||
+ cmp0048 == cmPolicies::WARN)
+ {
+ this->Makefile->IssueMessage
+ (cmake::FATAL_ERROR,
+ "VERSION not allowed unless CMP0048 is set to NEW");
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+
+ cmsys::RegularExpression
+ vx("^([0-9]+(\\.[0-9]+(\\.[0-9]+(\\.[0-9]+)?)?)?)?$");
+ if(!vx.find(version))
+ {
+ std::string e = "VERSION \"" + version + "\" format invalid.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e);
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+
+ std::string vs;
+ const char* sep = "";
+ char vb[4][64];
+ unsigned int v[4] = {0,0,0,0};
+ int vc = sscanf(version.c_str(), "%u.%u.%u.%u",
+ &v[0], &v[1], &v[2], &v[3]);
+ for(int i=0; i < 4; ++i)
+ {
+ if(i < vc)
+ {
+ sprintf(vb[i], "%u", v[i]);
+ vs += sep;
+ vs += vb[i];
+ sep = ".";
+ }
+ else
+ {
+ vb[i][0] = 0;
+ }
+ }
+
+ std::string vv;
+ vv = args[0] + "_VERSION";
+ this->Makefile->AddDefinition("PROJECT_VERSION", vs.c_str());
+ this->Makefile->AddDefinition(vv, vs.c_str());
+ vv = args[0] + "_VERSION_MAJOR";
+ this->Makefile->AddDefinition("PROJECT_VERSION_MAJOR", vb[0]);
+ this->Makefile->AddDefinition(vv, vb[0]);
+ vv = args[0] + "_VERSION_MINOR";
+ this->Makefile->AddDefinition("PROJECT_VERSION_MINOR", vb[1]);
+ this->Makefile->AddDefinition(vv, vb[1]);
+ vv = args[0] + "_VERSION_PATCH";
+ this->Makefile->AddDefinition("PROJECT_VERSION_PATCH", vb[2]);
+ this->Makefile->AddDefinition(vv, vb[2]);
+ vv = args[0] + "_VERSION_TWEAK";
+ this->Makefile->AddDefinition("PROJECT_VERSION_TWEAK", vb[3]);
+ this->Makefile->AddDefinition(vv, vb[3]);
+ }
+ else if(cmp0048 != cmPolicies::OLD)
+ {
+ // Set project VERSION variables to empty
+ std::vector<std::string> vv;
+ vv.push_back("PROJECT_VERSION");
+ vv.push_back("PROJECT_VERSION_MAJOR");
+ vv.push_back("PROJECT_VERSION_MINOR");
+ vv.push_back("PROJECT_VERSION_PATCH");
+ vv.push_back("PROJECT_VERSION_TWEAK");
+ vv.push_back(args[0] + "_VERSION");
+ vv.push_back(args[0] + "_VERSION_MAJOR");
+ vv.push_back(args[0] + "_VERSION_MINOR");
+ vv.push_back(args[0] + "_VERSION_PATCH");
+ vv.push_back(args[0] + "_VERSION_TWEAK");
+ std::string vw;
+ for(std::vector<std::string>::iterator i = vv.begin();
+ i != vv.end(); ++i)
+ {
+ const char* v = this->Makefile->GetDefinition(*i);
+ if(v && *v)
+ {
+ if(cmp0048 == cmPolicies::WARN)
+ {
+ vw += "\n ";
+ vw += *i;
+ }
+ else
+ {
+ this->Makefile->AddDefinition(*i, "");
+ }
+ }
+ }
+ if(!vw.empty())
+ {
+ cmOStringStream w;
+ w << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0048))
+ << "\nThe following variable(s) would be set to empty:" << vw;
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }
+ }
+
+ if (languages.empty())
+ {
+ // if no language is specified do c and c++
+ languages.push_back("C");
+ languages.push_back("CXX");
+ }
+ this->Makefile->EnableLanguage(languages, false);
+ std::string extraInclude = "CMAKE_PROJECT_" + args[0] + "_INCLUDE";
+ const char* include = this->Makefile->GetDefinition(extraInclude);
+ if(include)
+ {
+ std::string fullFilePath;
+ bool readit =
+ this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
+ include);
+ if(!readit && !cmSystemTools::GetFatalErrorOccured())
+ {
+ std::string m =
+ "could not find file:\n"
+ " ";
+ m += include;
+ this->SetError(m);
+ return false;
+ }
+ }
+ return true;
+}
+
diff --git a/Source/cmProjectCommand.h b/Source/cmProjectCommand.h
new file mode 100644
index 0000000000..7aacb55374
--- /dev/null
+++ b/Source/cmProjectCommand.h
@@ -0,0 +1,53 @@
+/*============================================================================
+ 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 cmProjectCommand_h
+#define cmProjectCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmProjectCommand
+ * \brief Specify the name for this build project.
+ *
+ * cmProjectCommand is used to specify a name for this build project.
+ * It is defined once per set of CMakeList.txt files (including
+ * all subdirectories). Currently it just sets the name of the workspace
+ * file for Microsoft Visual C++
+ */
+class cmProjectCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmProjectCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "project";}
+
+ cmTypeMacro(cmProjectCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmProperty.cxx b/Source/cmProperty.cxx
new file mode 100644
index 0000000000..40976db159
--- /dev/null
+++ b/Source/cmProperty.cxx
@@ -0,0 +1,41 @@
+/*============================================================================
+ 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 "cmProperty.h"
+#include "cmSystemTools.h"
+
+void cmProperty::Set(const std::string& name, const char *value)
+{
+ this->Name = name;
+ this->Value = value;
+ this->ValueHasBeenSet = true;
+}
+
+void cmProperty::Append(const std::string& name, const char *value,
+ bool asString)
+{
+ this->Name = name;
+ if(!this->Value.empty() && *value && !asString)
+ {
+ this->Value += ";";
+ }
+ this->Value += value;
+ this->ValueHasBeenSet = true;
+}
+
+const char *cmProperty::GetValue() const
+{
+ if (this->ValueHasBeenSet)
+ {
+ return this->Value.c_str();
+ }
+ return 0;
+}
diff --git a/Source/cmProperty.h b/Source/cmProperty.h
new file mode 100644
index 0000000000..659c4c3243
--- /dev/null
+++ b/Source/cmProperty.h
@@ -0,0 +1,42 @@
+/*============================================================================
+ 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 cmProperty_h
+#define cmProperty_h
+
+#include "cmStandardIncludes.h"
+
+class cmProperty
+{
+public:
+ enum ScopeType { TARGET, SOURCE_FILE, DIRECTORY, GLOBAL, CACHE,
+ TEST, VARIABLE, CACHED_VARIABLE, INSTALL };
+
+ // set this property
+ void Set(const std::string& name, const char *value);
+
+ // append to this property
+ void Append(const std::string& name, const char *value,
+ bool asString = false);
+
+ // get the value
+ const char *GetValue() const;
+
+ // construct with the value not set
+ cmProperty() { this->ValueHasBeenSet = false; }
+
+protected:
+ std::string Name;
+ std::string Value;
+ bool ValueHasBeenSet;
+};
+
+#endif
diff --git a/Source/cmPropertyDefinition.cxx b/Source/cmPropertyDefinition.cxx
new file mode 100644
index 0000000000..1af967c944
--- /dev/null
+++ b/Source/cmPropertyDefinition.cxx
@@ -0,0 +1,33 @@
+/*============================================================================
+ 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 "cmPropertyDefinition.h"
+#include "cmSystemTools.h"
+
+void cmPropertyDefinition
+::DefineProperty(const std::string& name, cmProperty::ScopeType scope,
+ const char *shortDescription,
+ const char *fullDescription,
+ bool chain)
+{
+ this->Name = name;
+ this->Scope = scope;
+ this->Chained = chain;
+ if (shortDescription)
+ {
+ this->ShortDescription = shortDescription;
+ }
+ if (fullDescription)
+ {
+ this->FullDescription = fullDescription;
+ }
+}
+
diff --git a/Source/cmPropertyDefinition.h b/Source/cmPropertyDefinition.h
new file mode 100644
index 0000000000..098fadb75d
--- /dev/null
+++ b/Source/cmPropertyDefinition.h
@@ -0,0 +1,61 @@
+/*============================================================================
+ 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 cmPropertyDefinition_h
+#define cmPropertyDefinition_h
+
+#include "cmProperty.h"
+
+/** \class cmPropertyDefinition
+ * \brief Property meta-information
+ *
+ * This class contains the following meta-information about property:
+ * - Name;
+ * - Various documentation strings;
+ * - The scope of the property;
+ * - If the property is chained.
+ */
+class cmPropertyDefinition
+{
+public:
+ /// Define this property
+ void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
+ const char *ShortDescription,
+ const char *FullDescription,
+ bool chained);
+
+ /// Default constructor
+ cmPropertyDefinition() { this->Chained = false; }
+
+ /// Is the property chained?
+ bool IsChained() const { return this->Chained; }
+
+ /// Get the scope
+ cmProperty::ScopeType GetScope() const {
+ return this->Scope; }
+
+ /// Get the documentation (short version)
+ const std::string &GetShortDescription() const {
+ return this->ShortDescription; }
+
+ /// Get the documentation (full version)
+ const std::string &GetFullDescription() const {
+ return this->FullDescription; }
+
+protected:
+ std::string Name;
+ std::string ShortDescription;
+ std::string FullDescription;
+ cmProperty::ScopeType Scope;
+ bool Chained;
+};
+
+#endif
diff --git a/Source/cmPropertyDefinitionMap.cxx b/Source/cmPropertyDefinitionMap.cxx
new file mode 100644
index 0000000000..3875318f4a
--- /dev/null
+++ b/Source/cmPropertyDefinitionMap.cxx
@@ -0,0 +1,52 @@
+/*============================================================================
+ 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 "cmPropertyDefinitionMap.h"
+#include "cmSystemTools.h"
+#include "cmDocumentationSection.h"
+
+void cmPropertyDefinitionMap
+::DefineProperty(const std::string& name, cmProperty::ScopeType scope,
+ const char *ShortDescription,
+ const char *FullDescription,
+ bool chain)
+{
+ cmPropertyDefinitionMap::iterator it = this->find(name);
+ cmPropertyDefinition *prop;
+ if (it == this->end())
+ {
+ prop = &(*this)[name];
+ prop->DefineProperty(name,scope,ShortDescription, FullDescription,
+ chain);
+ }
+}
+
+bool cmPropertyDefinitionMap::IsPropertyDefined(const std::string& name)
+{
+ cmPropertyDefinitionMap::iterator it = this->find(name);
+ if (it == this->end())
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool cmPropertyDefinitionMap::IsPropertyChained(const std::string& name)
+{
+ cmPropertyDefinitionMap::iterator it = this->find(name);
+ if (it == this->end())
+ {
+ return false;
+ }
+
+ return it->second.IsChained();
+}
diff --git a/Source/cmPropertyDefinitionMap.h b/Source/cmPropertyDefinitionMap.h
new file mode 100644
index 0000000000..00c7328c6e
--- /dev/null
+++ b/Source/cmPropertyDefinitionMap.h
@@ -0,0 +1,37 @@
+/*============================================================================
+ 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 cmPropertyDefinitionMap_h
+#define cmPropertyDefinitionMap_h
+
+#include "cmPropertyDefinition.h"
+
+class cmDocumentationSection;
+
+class cmPropertyDefinitionMap :
+public std::map<std::string,cmPropertyDefinition>
+{
+public:
+ // define the property
+ void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
+ const char *ShortDescription,
+ const char *FullDescription,
+ bool chain);
+
+ // has a named property been defined
+ bool IsPropertyDefined(const std::string& name);
+
+ // is a named property set to chain
+ bool IsPropertyChained(const std::string& name);
+};
+
+#endif
+
diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx
new file mode 100644
index 0000000000..e335b3b558
--- /dev/null
+++ b/Source/cmPropertyMap.cxx
@@ -0,0 +1,82 @@
+/*============================================================================
+ 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 "cmPropertyMap.h"
+#include "cmSystemTools.h"
+#include "cmake.h"
+
+cmProperty *cmPropertyMap::GetOrCreateProperty(const std::string& name)
+{
+ cmPropertyMap::iterator it = this->find(name);
+ cmProperty *prop;
+ if (it == this->end())
+ {
+ prop = &(*this)[name];
+ }
+ else
+ {
+ prop = &(it->second);
+ }
+ return prop;
+}
+
+void cmPropertyMap::SetProperty(const std::string& name, const char *value,
+ cmProperty::ScopeType scope)
+{
+ if(!value)
+ {
+ this->erase(name);
+ return;
+ }
+ (void)scope;
+
+ cmProperty *prop = this->GetOrCreateProperty(name);
+ prop->Set(name,value);
+}
+
+void cmPropertyMap::AppendProperty(const std::string& name, const char* value,
+ cmProperty::ScopeType scope, bool asString)
+{
+ // Skip if nothing to append.
+ if(!value || !*value)
+ {
+ return;
+ }
+ (void)scope;
+
+ cmProperty *prop = this->GetOrCreateProperty(name);
+ prop->Append(name,value,asString);
+}
+
+const char *cmPropertyMap
+::GetPropertyValue(const std::string& name,
+ cmProperty::ScopeType scope,
+ bool &chain) const
+{
+ chain = false;
+ if (name.empty())
+ {
+ return 0;
+ }
+
+ cmPropertyMap::const_iterator it = this->find(name);
+ if (it == this->end())
+ {
+ // should we chain up?
+ if (this->CMakeInstance)
+ {
+ chain = this->CMakeInstance->IsPropertyChained(name,scope);
+ }
+ return 0;
+ }
+ return it->second.GetValue();
+}
+
diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h
new file mode 100644
index 0000000000..02d4235dad
--- /dev/null
+++ b/Source/cmPropertyMap.h
@@ -0,0 +1,43 @@
+/*============================================================================
+ 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 cmPropertyMap_h
+#define cmPropertyMap_h
+
+#include "cmProperty.h"
+
+class cmake;
+
+class cmPropertyMap : public std::map<std::string,cmProperty>
+{
+public:
+ cmProperty *GetOrCreateProperty(const std::string& name);
+
+ void SetProperty(const std::string& name, const char *value,
+ cmProperty::ScopeType scope);
+
+ void AppendProperty(const std::string& name, const char* value,
+ cmProperty::ScopeType scope, bool asString=false);
+
+ const char *GetPropertyValue(const std::string& name,
+ cmProperty::ScopeType scope,
+ bool &chain) const;
+
+ void SetCMakeInstance(cmake *cm) { this->CMakeInstance = cm; }
+
+ cmPropertyMap() { this->CMakeInstance = 0;}
+
+private:
+ cmake *CMakeInstance;
+};
+
+#endif
+
diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx
new file mode 100644
index 0000000000..a984260d62
--- /dev/null
+++ b/Source/cmQTWrapCPPCommand.cxx
@@ -0,0 +1,115 @@
+/*============================================================================
+ 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 "cmQTWrapCPPCommand.h"
+
+// cmQTWrapCPPCommand
+bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& argsIn,
+ cmExecutionStatus &)
+{
+ if(argsIn.size() < 3 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // This command supports source list inputs for compatibility.
+ std::vector<std::string> args;
+ this->Makefile->ExpandSourceListArguments(argsIn, args, 2);
+
+ // Get the moc executable to run in the custom command.
+ const char* moc_exe =
+ this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
+
+ // Get the variable holding the list of sources.
+ std::string const& sourceList = args[1];
+ std::string sourceListValue =
+ this->Makefile->GetSafeDefinition(sourceList);
+
+ // Create a rule for all sources listed.
+ for(std::vector<std::string>::iterator j = (args.begin() + 2);
+ j != args.end(); ++j)
+ {
+ cmSourceFile *curr = this->Makefile->GetSource(*j);
+ // if we should wrap the class
+ if(!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE")))
+ {
+ // Compute the name of the file to generate.
+ std::string srcName =
+ cmSystemTools::GetFilenameWithoutLastExtension(*j);
+ std::string newName = this->Makefile->GetCurrentOutputDirectory();
+ newName += "/moc_";
+ newName += srcName;
+ newName += ".cxx";
+ cmSourceFile* sf =
+ this->Makefile->GetOrCreateSource(newName, true);
+ if (curr)
+ {
+ sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT"));
+ }
+
+ // Compute the name of the header from which to generate the file.
+ std::string hname;
+ if(cmSystemTools::FileIsFullPath(j->c_str()))
+ {
+ hname = *j;
+ }
+ else
+ {
+ if(curr && curr->GetPropertyAsBool("GENERATED"))
+ {
+ hname = this->Makefile->GetCurrentOutputDirectory();
+ }
+ else
+ {
+ hname = this->Makefile->GetCurrentDirectory();
+ }
+ hname += "/";
+ hname += *j;
+ }
+
+ // Append the generated source file to the list.
+ if(!sourceListValue.empty())
+ {
+ sourceListValue += ";";
+ }
+ sourceListValue += newName;
+
+ // Create the custom command to generate the file.
+ cmCustomCommandLine commandLine;
+ commandLine.push_back(moc_exe);
+ commandLine.push_back("-o");
+ commandLine.push_back(newName);
+ commandLine.push_back(hname);
+
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(commandLine);
+
+ std::vector<std::string> depends;
+ depends.push_back(moc_exe);
+ depends.push_back(hname);
+
+ std::string no_main_dependency = "";
+ const char* no_working_dir = 0;
+ this->Makefile->AddCustomCommandToOutput(newName,
+ depends,
+ no_main_dependency,
+ commandLines,
+ "Qt Wrapped File",
+ no_working_dir);
+ }
+ }
+
+ // Store the final list of source files.
+ this->Makefile->AddDefinition(sourceList,
+ sourceListValue.c_str());
+ return true;
+}
diff --git a/Source/cmQTWrapCPPCommand.h b/Source/cmQTWrapCPPCommand.h
new file mode 100644
index 0000000000..85729ddc99
--- /dev/null
+++ b/Source/cmQTWrapCPPCommand.h
@@ -0,0 +1,53 @@
+/*============================================================================
+ 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 cmQTWrapCPPCommand_h
+#define cmQTWrapCPPCommand_h
+
+#include "cmCommand.h"
+
+#include "cmSourceFile.h"
+
+/** \class cmQTWrapCPPCommand
+ * \brief Create moc file rules for Qt classes
+ *
+ * cmQTWrapCPPCommand is used to create wrappers for Qt classes into
+ * normal C++
+ */
+class cmQTWrapCPPCommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmQTWrapCPPCommand, cmCommand);
+
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmQTWrapCPPCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "qt_wrap_cpp";}
+};
+
+
+
+#endif
diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx
new file mode 100644
index 0000000000..dce59efa16
--- /dev/null
+++ b/Source/cmQTWrapUICommand.cxx
@@ -0,0 +1,166 @@
+/*============================================================================
+ 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 "cmQTWrapUICommand.h"
+
+// cmQTWrapUICommand
+bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& argsIn,
+ cmExecutionStatus &)
+{
+ if(argsIn.size() < 4 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // This command supports source list inputs for compatibility.
+ std::vector<std::string> args;
+ this->Makefile->ExpandSourceListArguments(argsIn, args, 3);
+
+ // Get the uic and moc executables to run in the custom commands.
+ const char* uic_exe =
+ this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
+ const char* moc_exe =
+ this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
+
+ // Get the variable holding the list of sources.
+ std::string const& headerList = args[1];
+ std::string const& sourceList = args[2];
+ std::string headerListValue =
+ this->Makefile->GetSafeDefinition(headerList);
+ std::string sourceListValue =
+ this->Makefile->GetSafeDefinition(sourceList);
+
+ // Create rules for all sources listed.
+ for(std::vector<std::string>::iterator j = (args.begin() + 3);
+ j != args.end(); ++j)
+ {
+ cmSourceFile *curr = this->Makefile->GetSource(*j);
+ // if we should wrap the class
+ if(!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE")))
+ {
+ // Compute the name of the files to generate.
+ std::string srcName =
+ cmSystemTools::GetFilenameWithoutLastExtension(*j);
+ std::string hName = this->Makefile->GetCurrentOutputDirectory();
+ hName += "/";
+ hName += srcName;
+ hName += ".h";
+ std::string cxxName = this->Makefile->GetCurrentOutputDirectory();
+ cxxName += "/";
+ cxxName += srcName;
+ cxxName += ".cxx";
+ std::string mocName = this->Makefile->GetCurrentOutputDirectory();
+ mocName += "/moc_";
+ mocName += srcName;
+ mocName += ".cxx";
+
+ // Compute the name of the ui file from which to generate others.
+ std::string uiName;
+ if(cmSystemTools::FileIsFullPath(j->c_str()))
+ {
+ uiName = *j;
+ }
+ else
+ {
+ if(curr && curr->GetPropertyAsBool("GENERATED"))
+ {
+ uiName = this->Makefile->GetCurrentOutputDirectory();
+ }
+ else
+ {
+ uiName = this->Makefile->GetCurrentDirectory();
+ }
+ uiName += "/";
+ uiName += *j;
+ }
+
+ // create the list of headers
+ if(!headerListValue.empty())
+ {
+ headerListValue += ";";
+ }
+ headerListValue += hName;
+
+ // create the list of sources
+ if(!sourceListValue.empty())
+ {
+ sourceListValue += ";";
+ }
+ sourceListValue += cxxName;
+ sourceListValue += ";";
+ sourceListValue += mocName;
+
+ // set up .ui to .h and .cxx command
+ cmCustomCommandLine hCommand;
+ hCommand.push_back(uic_exe);
+ hCommand.push_back("-o");
+ hCommand.push_back(hName);
+ hCommand.push_back(uiName);
+ cmCustomCommandLines hCommandLines;
+ hCommandLines.push_back(hCommand);
+
+ cmCustomCommandLine cxxCommand;
+ cxxCommand.push_back(uic_exe);
+ cxxCommand.push_back("-impl");
+ cxxCommand.push_back(hName);
+ cxxCommand.push_back("-o");
+ cxxCommand.push_back(cxxName);
+ cxxCommand.push_back(uiName);
+ cmCustomCommandLines cxxCommandLines;
+ cxxCommandLines.push_back(cxxCommand);
+
+ cmCustomCommandLine mocCommand;
+ mocCommand.push_back(moc_exe);
+ mocCommand.push_back("-o");
+ mocCommand.push_back(mocName);
+ mocCommand.push_back(hName);
+ cmCustomCommandLines mocCommandLines;
+ mocCommandLines.push_back(mocCommand);
+
+ std::vector<std::string> depends;
+ depends.push_back(uiName);
+ std::string no_main_dependency = "";
+ const char* no_comment = 0;
+ const char* no_working_dir = 0;
+ this->Makefile->AddCustomCommandToOutput(hName,
+ depends,
+ no_main_dependency,
+ hCommandLines,
+ no_comment,
+ no_working_dir);
+
+ depends.push_back(hName);
+ this->Makefile->AddCustomCommandToOutput(cxxName,
+ depends,
+ no_main_dependency,
+ cxxCommandLines,
+ no_comment,
+ no_working_dir);
+
+ depends.clear();
+ depends.push_back(hName);
+ this->Makefile->AddCustomCommandToOutput(mocName,
+ depends,
+ no_main_dependency,
+ mocCommandLines,
+ no_comment,
+ no_working_dir);
+ }
+ }
+
+ // Store the final list of source files and headers.
+ this->Makefile->AddDefinition(sourceList,
+ sourceListValue.c_str());
+ this->Makefile->AddDefinition(headerList,
+ headerListValue.c_str());
+ return true;
+}
diff --git a/Source/cmQTWrapUICommand.h b/Source/cmQTWrapUICommand.h
new file mode 100644
index 0000000000..4aa9a614a9
--- /dev/null
+++ b/Source/cmQTWrapUICommand.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmQTWrapUICommand_h
+#define cmQTWrapUICommand_h
+
+#include "cmCommand.h"
+
+#include "cmSourceFile.h"
+
+/** \class cmQTWrapUICommand
+ * \brief Create .h and .cxx files rules for Qt user interfaces files
+ *
+ * cmQTWrapUICommand is used to create wrappers for Qt classes into normal C++
+ */
+class cmQTWrapUICommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmQTWrapUICommand, cmCommand);
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmQTWrapUICommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "qt_wrap_ui";}
+};
+
+
+
+#endif
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
new file mode 100644
index 0000000000..93ebde6c2a
--- /dev/null
+++ b/Source/cmQtAutoGenerators.cxx
@@ -0,0 +1,2164 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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 "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmSystemTools.h"
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# include "cmLocalVisualStudioGenerator.h"
+#endif
+
+#include <cmsys/Terminal.h>
+#include <cmsys/ios/sstream>
+#include <cmsys/FStream.hxx>
+#include <assert.h>
+
+#include <string.h>
+#if defined(__APPLE__)
+#include <unistd.h>
+#endif
+
+#include "cmQtAutoGenerators.h"
+
+
+static bool requiresMocing(const std::string& text, std::string &macroName)
+{
+ // this simple check is much much faster than the regexp
+ if (strstr(text.c_str(), "Q_OBJECT") == NULL
+ && strstr(text.c_str(), "Q_GADGET") == NULL)
+ {
+ return false;
+ }
+
+ cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]");
+ if (qObjectRegExp.find(text))
+ {
+ macroName = "Q_OBJECT";
+ return true;
+ }
+ cmsys::RegularExpression qGadgetRegExp("[\n][ \t]*Q_GADGET[^a-zA-Z0-9_]");
+ if (qGadgetRegExp.find(text))
+ {
+ macroName = "Q_GADGET";
+ return true;
+ }
+ return false;
+}
+
+
+static std::string findMatchingHeader(const std::string& absPath,
+ const std::string& mocSubDir,
+ const std::string& basename,
+ const std::vector<std::string>& headerExtensions)
+{
+ std::string header;
+ for(std::vector<std::string>::const_iterator ext = headerExtensions.begin();
+ ext != headerExtensions.end();
+ ++ext)
+ {
+ std::string sourceFilePath = absPath + basename + "." + (*ext);
+ if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
+ {
+ header = sourceFilePath;
+ break;
+ }
+ if (!mocSubDir.empty())
+ {
+ sourceFilePath = mocSubDir + basename + "." + (*ext);
+ if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
+ {
+ header = sourceFilePath;
+ break;
+ }
+ }
+ }
+
+ return header;
+}
+
+
+static std::string extractSubDir(const std::string& absPath,
+ const std::string& currentMoc)
+{
+ std::string subDir;
+ if (currentMoc.find_first_of('/') != std::string::npos)
+ {
+ subDir = absPath
+ + cmsys::SystemTools::GetFilenamePath(currentMoc) + '/';
+ }
+ return subDir;
+}
+
+
+static void copyTargetProperty(cmTarget* destinationTarget,
+ cmTarget* sourceTarget,
+ const std::string& propertyName)
+{
+ const char* propertyValue = sourceTarget->GetProperty(propertyName);
+ if (propertyValue)
+ {
+ destinationTarget->SetProperty(propertyName, propertyValue);
+ }
+}
+
+
+static std::string ReadAll(const std::string& filename)
+{
+ cmsys::ifstream file(filename.c_str());
+ cmsys_ios::stringstream stream;
+ stream << file.rdbuf();
+ file.close();
+ return stream.str();
+}
+
+cmQtAutoGenerators::cmQtAutoGenerators()
+:Verbose(cmsys::SystemTools::GetEnv("VERBOSE") != 0)
+,ColorOutput(true)
+,RunMocFailed(false)
+,RunUicFailed(false)
+,RunRccFailed(false)
+,GenerateAll(false)
+{
+
+ std::string colorEnv = "";
+ cmsys::SystemTools::GetEnv("COLOR", colorEnv);
+ if(!colorEnv.empty())
+ {
+ if(cmSystemTools::IsOn(colorEnv.c_str()))
+ {
+ this->ColorOutput = true;
+ }
+ else
+ {
+ this->ColorOutput = false;
+ }
+ }
+}
+
+static std::string getAutogenTargetName(cmTarget const* target)
+{
+ std::string autogenTargetName = target->GetName();
+ autogenTargetName += "_automoc";
+ return autogenTargetName;
+}
+
+static std::string getAutogenTargetDir(cmTarget const* target)
+{
+ cmMakefile* makefile = target->GetMakefile();
+ std::string targetDir = makefile->GetCurrentOutputDirectory();
+ targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
+ targetDir += "/";
+ targetDir += getAutogenTargetName(target);
+ targetDir += ".dir/";
+ return targetDir;
+}
+
+bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target)
+{
+ cmMakefile* makefile = target->GetMakefile();
+ // don't do anything if there is no Qt4 or Qt5Core (which contains moc):
+ std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
+ if (qtMajorVersion == "")
+ {
+ qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
+ }
+ if (qtMajorVersion != "4" && qtMajorVersion != "5")
+ {
+ return false;
+ }
+
+ if (target->GetPropertyAsBool("AUTOMOC"))
+ {
+ std::string automocTargetName = getAutogenTargetName(target);
+ std::string mocCppFile = makefile->GetCurrentOutputDirectory();
+ mocCppFile += "/";
+ mocCppFile += automocTargetName;
+ mocCppFile += ".cpp";
+ makefile->GetOrCreateSource(mocCppFile, true);
+ makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
+ mocCppFile.c_str(), false);
+
+ target->AddSource(mocCppFile);
+ }
+ // create a custom target for running generators at buildtime:
+ std::string autogenTargetName = getAutogenTargetName(target);
+
+ std::string targetDir = getAutogenTargetDir(target);
+
+ cmCustomCommandLine currentLine;
+ currentLine.push_back(makefile->GetSafeDefinition("CMAKE_COMMAND"));
+ currentLine.push_back("-E");
+ currentLine.push_back("cmake_autogen");
+ currentLine.push_back(targetDir);
+ currentLine.push_back("$<CONFIGURATION>");
+
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(currentLine);
+
+ std::string workingDirectory = cmSystemTools::CollapseFullPath(
+ "", makefile->GetCurrentOutputDirectory());
+
+ 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"))
+ {
+ toolNames.push_back("rcc");
+ }
+
+ 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();
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ bool usePRE_BUILD = false;
+ cmLocalGenerator* localGen = makefile->GetLocalGenerator();
+ cmGlobalGenerator* gg = localGen->GetGlobalGenerator();
+ if(gg->GetName().find("Visual Studio") != std::string::npos)
+ {
+ cmLocalVisualStudioGenerator* vslg =
+ static_cast<cmLocalVisualStudioGenerator*>(localGen);
+ // 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 = vslg->GetVersion() >= cmLocalVisualStudioGenerator::VS7;
+ if(usePRE_BUILD)
+ {
+ for (std::vector<std::string>::iterator it = depends.begin();
+ it != depends.end(); ++it)
+ {
+ if(!makefile->FindTargetToUse(it->c_str()))
+ {
+ usePRE_BUILD = false;
+ break;
+ }
+ }
+ }
+ }
+ if(usePRE_BUILD)
+ {
+ // 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;
+ cmCustomCommand cc(makefile, no_output, depends,
+ commandLines, autogenComment.c_str(),
+ workingDirectory.c_str());
+ cc.SetEscapeOldStyle(false);
+ cc.SetEscapeAllowMakeVars(true);
+ target->AddPreBuildCommand(cc);
+ }
+ else
+#endif
+ {
+ cmTarget* autogenTarget = makefile->AddUtilityCommand(
+ autogenTargetName, true,
+ workingDirectory.c_str(), depends,
+ commandLines, false, autogenComment.c_str());
+ // Set target folder
+ const char* autogenFolder = makefile->GetCMakeInstance()->GetProperty(
+ "AUTOMOC_TARGETS_FOLDER");
+ if (!autogenFolder)
+ {
+ autogenFolder = makefile->GetCMakeInstance()->GetProperty(
+ "AUTOGEN_TARGETS_FOLDER");
+ }
+ if (autogenFolder && *autogenFolder)
+ {
+ autogenTarget->SetProperty("FOLDER", autogenFolder);
+ }
+ else
+ {
+ // inherit FOLDER property from target (#13688)
+ copyTargetProperty(autogenTarget, target, "FOLDER");
+ }
+
+ target->AddUtility(autogenTargetName);
+ }
+
+ return true;
+}
+
+static void GetCompileDefinitionsAndDirectories(cmTarget const* target,
+ const std::string& config,
+ std::string &incs,
+ std::string &defs)
+{
+ cmMakefile* makefile = target->GetMakefile();
+ cmLocalGenerator* localGen = makefile->GetLocalGenerator();
+ std::vector<std::string> includeDirs;
+ cmGeneratorTarget *gtgt = target->GetMakefile()->GetLocalGenerator()
+ ->GetGlobalGenerator()
+ ->GetGeneratorTarget(target);
+ // 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);
+ const char* sep = "";
+ incs = "";
+ for(std::vector<std::string>::const_iterator incDirIt = includeDirs.begin();
+ incDirIt != includeDirs.end();
+ ++incDirIt)
+ {
+ incs += sep;
+ sep = ";";
+ incs += *incDirIt;
+ }
+
+ std::set<std::string> defines;
+ localGen->AddCompileDefinitions(defines, target, config);
+
+ sep = "";
+ for(std::set<std::string>::const_iterator defIt = defines.begin();
+ defIt != defines.end();
+ ++defIt)
+ {
+ defs += sep;
+ sep = ";";
+ defs += *defIt;
+ }
+}
+
+void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget 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 = getAutogenTargetName(target);
+
+ makefile->AddDefinition("_moc_target_name",
+ cmLocalGenerator::EscapeForCMake(autogenTargetName).c_str());
+ makefile->AddDefinition("_origin_target_name",
+ cmLocalGenerator::EscapeForCMake(target->GetName()).c_str());
+
+ std::string targetDir = getAutogenTargetDir(target);
+
+ const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
+ if (!qtVersion)
+ {
+ qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
+ }
+ if (const char *targetQtVersion =
+ target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", ""))
+ {
+ qtVersion = targetQtVersion;
+ }
+ if (qtVersion)
+ {
+ makefile->AddDefinition("_target_qt_version", qtVersion);
+ }
+
+ std::map<std::string, std::string> configIncludes;
+ std::map<std::string, std::string> configDefines;
+ std::map<std::string, std::string> configUicOptions;
+
+ if (target->GetPropertyAsBool("AUTOMOC")
+ || target->GetPropertyAsBool("AUTOUIC")
+ || target->GetPropertyAsBool("AUTORCC"))
+ {
+ this->SetupSourceFiles(target);
+ }
+ makefile->AddDefinition("_cpp_files",
+ cmLocalGenerator::EscapeForCMake(this->Sources).c_str());
+ if (target->GetPropertyAsBool("AUTOMOC"))
+ {
+ this->SetupAutoMocTarget(target, autogenTargetName,
+ configIncludes, configDefines);
+ }
+ if (target->GetPropertyAsBool("AUTOUIC"))
+ {
+ this->SetupAutoUicTarget(target, configUicOptions);
+ }
+ if (target->GetPropertyAsBool("AUTORCC"))
+ {
+ this->SetupAutoRccTarget(target);
+ }
+
+ const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT");
+ std::string inputFile = cmakeRoot;
+ inputFile += "/Modules/AutogenInfo.cmake.in";
+ std::string outputFile = targetDir;
+ outputFile += "/AutogenInfo.cmake";
+ makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(),
+ false, true, false);
+
+ if (!configDefines.empty()
+ || !configIncludes.empty()
+ || !configUicOptions.empty())
+ {
+ 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";
+ }
+ }
+ if (!configUicOptions.empty())
+ {
+ 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";
+ }
+ }
+ }
+}
+
+void cmQtAutoGenerators::SetupSourceFiles(cmTarget const* target)
+{
+ cmMakefile* makefile = target->GetMakefile();
+
+ const char* sepFiles = "";
+ const char* sepHeaders = "";
+
+ std::vector<cmSourceFile*> srcFiles;
+ target->GetConfigCommonSourceFiles(srcFiles);
+
+ const char *skipMocSep = "";
+ const char *skipUicSep = "";
+
+ std::vector<std::string> newRccFiles;
+
+ for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
+ fileIt != srcFiles.end();
+ ++fileIt)
+ {
+ cmSourceFile* sf = *fileIt;
+ std::string absFile = cmsys::SystemTools::GetRealPath(
+ sf->GetFullPath().c_str());
+ bool skipMoc = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"));
+ bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"));
+
+ if(cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC")))
+ {
+ this->SkipUic += skipUicSep;
+ this->SkipUic += absFile;
+ skipUicSep = ";";
+ }
+
+ 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 (skipMoc)
+ {
+ this->SkipMoc += skipMocSep;
+ this->SkipMoc += absFile;
+ skipMocSep = ";";
+ }
+ else
+ {
+ cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat(
+ ext.c_str());
+ if (fileType == cmSystemTools::CXX_FILE_FORMAT)
+ {
+ this->Sources += sepFiles;
+ this->Sources += absFile;
+ sepFiles = ";";
+ }
+ else if (fileType == cmSystemTools::HEADER_FILE_FORMAT)
+ {
+ this->Headers += sepHeaders;
+ this->Headers += absFile;
+ sepHeaders = ";";
+ }
+ }
+ }
+ }
+
+ for(std::vector<std::string>::const_iterator fileIt = newRccFiles.begin();
+ fileIt != newRccFiles.end();
+ ++fileIt)
+ {
+ const_cast<cmTarget*>(target)->AddSource(*fileIt);
+ }
+}
+
+void cmQtAutoGenerators::SetupAutoMocTarget(cmTarget const* target,
+ const std::string &autogenTargetName,
+ std::map<std::string, std::string> &configIncludes,
+ std::map<std::string, std::string> &configDefines)
+{
+ cmMakefile* makefile = target->GetMakefile();
+
+ const char* tmp = target->GetProperty("AUTOMOC_MOC_OPTIONS");
+ std::string _moc_options = (tmp!=0 ? tmp : "");
+ makefile->AddDefinition("_moc_options",
+ cmLocalGenerator::EscapeForCMake(_moc_options).c_str());
+ makefile->AddDefinition("_skip_moc",
+ cmLocalGenerator::EscapeForCMake(this->SkipMoc).c_str());
+ makefile->AddDefinition("_moc_headers",
+ cmLocalGenerator::EscapeForCMake(this->Headers).c_str());
+ bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE");
+ makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE");
+
+ 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);
+
+ makefile->AddDefinition("_moc_incs",
+ cmLocalGenerator::EscapeForCMake(_moc_incs).c_str());
+ makefile->AddDefinition("_moc_compile_defs",
+ cmLocalGenerator::EscapeForCMake(_moc_compile_defs).c_str());
+
+ for (std::vector<std::string>::const_iterator li = configs.begin();
+ li != configs.end(); ++li)
+ {
+ 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] =
+ cmLocalGenerator::EscapeForCMake(config_moc_incs);
+ if(_moc_incs.empty())
+ {
+ _moc_incs = config_moc_incs;
+ }
+ }
+ if (config_moc_compile_defs != _moc_compile_defs)
+ {
+ configDefines[*li] =
+ cmLocalGenerator::EscapeForCMake(config_moc_compile_defs);
+ if(_moc_compile_defs.empty())
+ {
+ _moc_compile_defs = config_moc_compile_defs;
+ }
+ }
+ }
+
+ const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+ if (strcmp(qtVersion, "5") == 0)
+ {
+ 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->GetLocation(""));
+ }
+ else if (strcmp(qtVersion, "4") == 0)
+ {
+ cmTarget *qt4Moc = makefile->FindTargetToUse("Qt4::moc");
+ if (!qt4Moc)
+ {
+ cmSystemTools::Error("Qt4::moc target not found ",
+ autogenTargetName.c_str());
+ return;
+ }
+ makefile->AddDefinition("_qt_moc_executable", qt4Moc->GetLocation(""));
+ }
+ else
+ {
+ cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and "
+ "Qt 5 ", autogenTargetName.c_str());
+ }
+}
+
+void cmQtAutoGenerators::MergeUicOptions(std::vector<std::string> &opts,
+ const std::vector<std::string> &fileOpts,
+ bool isQt5)
+{
+ static const char* valueOptions[] = {
+ "tr",
+ "translate",
+ "postfix",
+ "generator",
+ "include", // Since Qt 5.3
+ "g"
+ };
+ 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())
+ {
+ 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
+ {
+ extraOpts.push_back(*it);
+ }
+ }
+ opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
+}
+
+static void GetUicOpts(cmTarget const* target, const std::string& config,
+ std::string &optString)
+{
+ std::vector<std::string> opts;
+ target->GetAutoUicOptions(opts, config);
+
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator optIt = opts.begin();
+ optIt != opts.end();
+ ++optIt)
+ {
+ optString += sep;
+ sep = ";";
+ optString += *optIt;
+ }
+}
+
+void cmQtAutoGenerators::SetupAutoUicTarget(cmTarget const* target,
+ std::map<std::string, std::string> &configUicOptions)
+{
+ cmMakefile *makefile = target->GetMakefile();
+
+ std::set<std::string> skipped;
+ std::vector<std::string> skipVec;
+ cmSystemTools::ExpandListArgument(this->SkipUic, skipVec);
+
+ for (std::vector<std::string>::const_iterator li = skipVec.begin();
+ li != skipVec.end(); ++li)
+ {
+ skipped.insert(*li);
+ }
+
+ makefile->AddDefinition("_skip_uic",
+ cmLocalGenerator::EscapeForCMake(this->SkipUic).c_str());
+
+ std::vector<cmSourceFile*> uiFilesWithOptions
+ = makefile->GetQtUiFilesWithOptions();
+
+ const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+
+ std::string _uic_opts;
+ std::vector<std::string> configs;
+ const std::string& config = makefile->GetConfigurations(configs);
+ GetUicOpts(target, config, _uic_opts);
+
+ if (!_uic_opts.empty())
+ {
+ _uic_opts = cmLocalGenerator::EscapeForCMake(_uic_opts);
+ makefile->AddDefinition("_uic_target_options", _uic_opts.c_str());
+ }
+ for (std::vector<std::string>::const_iterator li = configs.begin();
+ li != configs.end(); ++li)
+ {
+ std::string config_uic_opts;
+ GetUicOpts(target, *li, config_uic_opts);
+ if (config_uic_opts != _uic_opts)
+ {
+ configUicOptions[*li] =
+ cmLocalGenerator::EscapeForCMake(config_uic_opts);
+ if(_uic_opts.empty())
+ {
+ _uic_opts = config_uic_opts;
+ }
+ }
+ }
+
+ std::string uiFileFiles;
+ std::string uiFileOptions;
+ const char* sep = "";
+
+ for(std::vector<cmSourceFile*>::const_iterator fileIt =
+ uiFilesWithOptions.begin();
+ fileIt != uiFilesWithOptions.end();
+ ++fileIt)
+ {
+ cmSourceFile* sf = *fileIt;
+ std::string absFile = cmsys::SystemTools::GetRealPath(
+ sf->GetFullPath().c_str());
+
+ 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 = ";";
+ }
+
+ makefile->AddDefinition("_qt_uic_options_files",
+ cmLocalGenerator::EscapeForCMake(uiFileFiles).c_str());
+ makefile->AddDefinition("_qt_uic_options_options",
+ cmLocalGenerator::EscapeForCMake(uiFileOptions).c_str());
+
+ std::string targetName = target->GetName();
+ if (strcmp(qtVersion, "5") == 0)
+ {
+ cmTarget *qt5Uic = makefile->FindTargetToUse("Qt5::uic");
+ if (!qt5Uic)
+ {
+ // Project does not use Qt5Widgets, but has AUTOUIC ON anyway
+ }
+ else
+ {
+ makefile->AddDefinition("_qt_uic_executable", qt5Uic->GetLocation(""));
+ }
+ }
+ else if (strcmp(qtVersion, "4") == 0)
+ {
+ cmTarget *qt4Uic = makefile->FindTargetToUse("Qt4::uic");
+ if (!qt4Uic)
+ {
+ cmSystemTools::Error("Qt4::uic target not found ",
+ targetName.c_str());
+ return;
+ }
+ makefile->AddDefinition("_qt_uic_executable", qt4Uic->GetLocation(""));
+ }
+ else
+ {
+ cmSystemTools::Error("The CMAKE_AUTOUIC feature supports only Qt 4 and "
+ "Qt 5 ", targetName.c_str());
+ }
+}
+
+void cmQtAutoGenerators::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())
+ {
+ 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
+ {
+ extraOpts.push_back(*it);
+ }
+ }
+ opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
+}
+
+void cmQtAutoGenerators::SetupAutoRccTarget(cmTarget const* target)
+{
+ std::string _rcc_files;
+ const char* sepRccFiles = "";
+ cmMakefile *makefile = target->GetMakefile();
+
+ std::vector<cmSourceFile*> srcFiles;
+ target->GetConfigCommonSourceFiles(srcFiles);
+
+ std::string rccFileFiles;
+ std::string rccFileOptions;
+ const char *sep = "";
+
+ const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+
+ std::vector<std::string> rccOptions;
+ if (const char* opts = target->GetProperty("AUTORCC_OPTIONS"))
+ {
+ cmSystemTools::ExpandListArgument(opts, rccOptions);
+ }
+
+ for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
+ fileIt != srcFiles.end();
+ ++fileIt)
+ {
+ cmSourceFile* sf = *fileIt;
+ std::string ext = sf->GetExtension();
+ if (ext == "qrc")
+ {
+ std::string absFile = cmsys::SystemTools::GetRealPath(
+ sf->GetFullPath().c_str());
+ 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);
+ this->MergeRccOptions(rccOptions, optsVec,
+ strcmp(qtVersion, "5") == 0);
+ }
+
+ if (!rccOptions.empty())
+ {
+ rccFileFiles += sep;
+ rccFileFiles += absFile;
+ rccFileOptions += sep;
+ }
+ const char *listSep = "";
+ for(std::vector<std::string>::const_iterator it = rccOptions.begin();
+ it != rccOptions.end();
+ ++it)
+ {
+ rccFileOptions += listSep;
+ rccFileOptions += *it;
+ listSep = "@list_sep@";
+ }
+ sep = ";";
+ }
+ }
+ }
+
+ makefile->AddDefinition("_rcc_files",
+ cmLocalGenerator::EscapeForCMake(_rcc_files).c_str());
+
+ makefile->AddDefinition("_qt_rcc_options_files",
+ cmLocalGenerator::EscapeForCMake(rccFileFiles).c_str());
+ makefile->AddDefinition("_qt_rcc_options_options",
+ cmLocalGenerator::EscapeForCMake(rccFileOptions).c_str());
+
+ std::string targetName = target->GetName();
+ if (strcmp(qtVersion, "5") == 0)
+ {
+ cmTarget *qt5Rcc = makefile->FindTargetToUse("Qt5::rcc");
+ if (!qt5Rcc)
+ {
+ cmSystemTools::Error("Qt5::rcc target not found ",
+ targetName.c_str());
+ return;
+ }
+ makefile->AddDefinition("_qt_rcc_executable", qt5Rcc->GetLocation(""));
+ }
+ else if (strcmp(qtVersion, "4") == 0)
+ {
+ cmTarget *qt4Rcc = makefile->FindTargetToUse("Qt4::rcc");
+ if (!qt4Rcc)
+ {
+ cmSystemTools::Error("Qt4::rcc target not found ",
+ targetName.c_str());
+ return;
+ }
+ makefile->AddDefinition("_qt_rcc_executable", qt4Rcc->GetLocation(""));
+ }
+ else
+ {
+ cmSystemTools::Error("The CMAKE_AUTORCC feature supports only Qt 4 and "
+ "Qt 5 ", targetName.c_str());
+ }
+}
+
+static cmGlobalGenerator* CreateGlobalGenerator(cmake* cm,
+ const std::string& targetDirectory)
+{
+ cmGlobalGenerator* gg = new cmGlobalGenerator();
+ gg->SetCMakeInstance(cm);
+
+ cmLocalGenerator* lg = gg->CreateLocalGenerator();
+ lg->GetMakefile()->SetHomeOutputDirectory(targetDirectory);
+ lg->GetMakefile()->SetStartOutputDirectory(targetDirectory);
+ lg->GetMakefile()->SetHomeDirectory(targetDirectory);
+ lg->GetMakefile()->SetStartDirectory(targetDirectory);
+ gg->SetCurrentLocalGenerator(lg);
+
+ return gg;
+}
+
+bool cmQtAutoGenerators::Run(const std::string& targetDirectory,
+ const std::string& config)
+{
+ bool success = true;
+ cmake cm;
+ cmGlobalGenerator* gg = CreateGlobalGenerator(&cm, targetDirectory);
+ cmMakefile* makefile = gg->GetCurrentLocalGenerator()->GetMakefile();
+
+ this->ReadAutogenInfoFile(makefile, targetDirectory, config);
+ this->ReadOldMocDefinitionsFile(makefile, targetDirectory);
+
+ this->Init();
+
+ if (this->QtMajorVersion == "4" || this->QtMajorVersion == "5")
+ {
+ success = this->RunAutogen(makefile);
+ }
+
+ this->WriteOldMocDefinitionsFile(targetDirectory);
+
+ delete gg->GetCurrentLocalGenerator();
+ delete gg;
+ gg = NULL;
+ makefile = NULL;
+ return success;
+}
+
+bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile,
+ const std::string& targetDirectory,
+ const std::string& config)
+{
+ std::string filename(
+ cmSystemTools::CollapseFullPath(targetDirectory.c_str()));
+ cmSystemTools::ConvertToUnixSlashes(filename);
+ filename += "/AutogenInfo.cmake";
+
+ if (!makefile->ReadListFile(0, filename.c_str()))
+ {
+ cmSystemTools::Error("Error processing file: ", filename.c_str());
+ return false;
+ }
+
+ this->QtMajorVersion = makefile->GetSafeDefinition("AM_QT_VERSION_MAJOR");
+ if (this->QtMajorVersion == "")
+ {
+ this->QtMajorVersion = makefile->GetSafeDefinition(
+ "AM_Qt5Core_VERSION_MAJOR");
+ }
+ this->Sources = makefile->GetSafeDefinition("AM_SOURCES");
+ this->RccSources = makefile->GetSafeDefinition("AM_RCC_SOURCES");
+ this->SkipMoc = makefile->GetSafeDefinition("AM_SKIP_MOC");
+ this->SkipUic = makefile->GetSafeDefinition("AM_SKIP_UIC");
+ this->Headers = makefile->GetSafeDefinition("AM_HEADERS");
+ this->IncludeProjectDirsBefore = makefile->IsOn(
+ "AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE");
+ this->Srcdir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR");
+ this->Builddir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR");
+ this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE");
+ this->UicExecutable = makefile->GetSafeDefinition("AM_QT_UIC_EXECUTABLE");
+ this->RccExecutable = makefile->GetSafeDefinition("AM_QT_RCC_EXECUTABLE");
+ {
+ std::string compileDefsPropOrig = "AM_MOC_COMPILE_DEFINITIONS";
+ std::string compileDefsProp = compileDefsPropOrig;
+ if(!config.empty())
+ {
+ compileDefsProp += "_";
+ compileDefsProp += config;
+ }
+ const char *compileDefs = makefile->GetDefinition(compileDefsProp);
+ this->MocCompileDefinitionsStr = compileDefs ? compileDefs
+ : makefile->GetSafeDefinition(compileDefsPropOrig);
+ }
+ {
+ std::string includesPropOrig = "AM_MOC_INCLUDES";
+ std::string includesProp = includesPropOrig;
+ if(!config.empty())
+ {
+ includesProp += "_";
+ includesProp += config;
+ }
+ const char *includes = makefile->GetDefinition(includesProp);
+ this->MocIncludesStr = includes ? includes
+ : makefile->GetSafeDefinition(includesPropOrig);
+ }
+ this->MocOptionsStr = makefile->GetSafeDefinition("AM_MOC_OPTIONS");
+ this->ProjectBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR");
+ this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR");
+ this->TargetName = makefile->GetSafeDefinition("AM_TARGET_NAME");
+ this->OriginTargetName
+ = makefile->GetSafeDefinition("AM_ORIGIN_TARGET_NAME");
+
+ {
+ const char *uicOptionsFiles
+ = makefile->GetSafeDefinition("AM_UIC_OPTIONS_FILES");
+ std::string uicOptionsPropOrig = "AM_UIC_TARGET_OPTIONS";
+ std::string uicOptionsProp = uicOptionsPropOrig;
+ if(!config.empty())
+ {
+ uicOptionsProp += "_";
+ uicOptionsProp += config;
+ }
+ const char *uicTargetOptions
+ = makefile->GetSafeDefinition(uicOptionsProp);
+ cmSystemTools::ExpandListArgument(
+ uicTargetOptions ? uicTargetOptions
+ : makefile->GetSafeDefinition(uicOptionsPropOrig),
+ this->UicTargetOptions);
+ const char *uicOptionsOptions
+ = makefile->GetSafeDefinition("AM_UIC_OPTIONS_OPTIONS");
+ std::vector<std::string> uicFilesVec;
+ cmSystemTools::ExpandListArgument(uicOptionsFiles, uicFilesVec);
+ std::vector<std::string> uicOptionsVec;
+ cmSystemTools::ExpandListArgument(uicOptionsOptions, uicOptionsVec);
+ if (uicFilesVec.size() != uicOptionsVec.size())
+ {
+ return false;
+ }
+ for (std::vector<std::string>::iterator fileIt = uicFilesVec.begin(),
+ optionIt = uicOptionsVec.begin();
+ fileIt != uicFilesVec.end();
+ ++fileIt, ++optionIt)
+ {
+ cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";");
+ this->UicOptions[*fileIt] = *optionIt;
+ }
+ }
+ {
+ const char *rccOptionsFiles
+ = makefile->GetSafeDefinition("AM_RCC_OPTIONS_FILES");
+ const char *rccOptionsOptions
+ = makefile->GetSafeDefinition("AM_RCC_OPTIONS_OPTIONS");
+ std::vector<std::string> rccFilesVec;
+ cmSystemTools::ExpandListArgument(rccOptionsFiles, rccFilesVec);
+ std::vector<std::string> rccOptionsVec;
+ cmSystemTools::ExpandListArgument(rccOptionsOptions, rccOptionsVec);
+ if (rccFilesVec.size() != rccOptionsVec.size())
+ {
+ return false;
+ }
+ for (std::vector<std::string>::iterator fileIt = rccFilesVec.begin(),
+ optionIt = rccOptionsVec.begin();
+ fileIt != rccFilesVec.end();
+ ++fileIt, ++optionIt)
+ {
+ cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";");
+ this->RccOptions[*fileIt] = *optionIt;
+ }
+ }
+ this->CurrentCompileSettingsStr = this->MakeCompileSettingsString(makefile);
+
+ this->RelaxedMode = makefile->IsOn("AM_RELAXED_MODE");
+
+ return true;
+}
+
+
+std::string cmQtAutoGenerators::MakeCompileSettingsString(cmMakefile* makefile)
+{
+ std::string s;
+ s += makefile->GetSafeDefinition("AM_MOC_COMPILE_DEFINITIONS");
+ s += " ~~~ ";
+ s += makefile->GetSafeDefinition("AM_MOC_INCLUDES");
+ s += " ~~~ ";
+ s += makefile->GetSafeDefinition("AM_MOC_OPTIONS");
+ s += " ~~~ ";
+ s += makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE") ? "TRUE"
+ : "FALSE";
+ s += " ~~~ ";
+
+ return s;
+}
+
+
+bool cmQtAutoGenerators::ReadOldMocDefinitionsFile(cmMakefile* makefile,
+ const std::string& targetDirectory)
+{
+ std::string filename(
+ cmSystemTools::CollapseFullPath(targetDirectory.c_str()));
+ cmSystemTools::ConvertToUnixSlashes(filename);
+ filename += "/AutomocOldMocDefinitions.cmake";
+
+ if (makefile->ReadListFile(0, filename.c_str()))
+ {
+ this->OldCompileSettingsStr =
+ makefile->GetSafeDefinition("AM_OLD_COMPILE_SETTINGS");
+ }
+ return true;
+}
+
+
+void
+cmQtAutoGenerators::WriteOldMocDefinitionsFile(
+ const std::string& targetDirectory)
+{
+ std::string filename(
+ cmSystemTools::CollapseFullPath(targetDirectory.c_str()));
+ cmSystemTools::ConvertToUnixSlashes(filename);
+ filename += "/AutomocOldMocDefinitions.cmake";
+
+ cmsys::ofstream outfile;
+ outfile.open(filename.c_str(),
+ std::ios::trunc);
+ outfile << "set(AM_OLD_COMPILE_SETTINGS "
+ << cmLocalGenerator::EscapeForCMake(
+ this->CurrentCompileSettingsStr) << ")\n";
+
+ outfile.close();
+}
+
+
+void cmQtAutoGenerators::Init()
+{
+ this->OutMocCppFilename = this->Builddir;
+ this->OutMocCppFilename += this->TargetName;
+ this->OutMocCppFilename += ".cpp";
+
+ std::vector<std::string> cdefList;
+ cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList);
+ for(std::vector<std::string>::const_iterator it = cdefList.begin();
+ it != cdefList.end();
+ ++it)
+ {
+ this->MocDefinitions.push_back("-D" + (*it));
+ }
+
+ cmSystemTools::ExpandListArgument(this->MocOptionsStr, this->MocOptions);
+
+ std::vector<std::string> incPaths;
+ cmSystemTools::ExpandListArgument(this->MocIncludesStr, incPaths);
+
+ std::set<std::string> frameworkPaths;
+ for(std::vector<std::string>::const_iterator it = incPaths.begin();
+ it != incPaths.end();
+ ++it)
+ {
+ const std::string &path = *it;
+ this->MocIncludes.push_back("-I" + path);
+ if (this->EndsWith(path, ".framework/Headers"))
+ {
+ // Go up twice to get to the framework root
+ std::vector<std::string> pathComponents;
+ cmsys::SystemTools::SplitPath(path.c_str(), pathComponents);
+ std::string frameworkPath =cmsys::SystemTools::JoinPath(
+ pathComponents.begin(), pathComponents.end() - 2);
+ frameworkPaths.insert(frameworkPath);
+ }
+ }
+
+ for (std::set<std::string>::const_iterator it = frameworkPaths.begin();
+ it != frameworkPaths.end(); ++it)
+ {
+ this->MocIncludes.push_back("-F");
+ this->MocIncludes.push_back(*it);
+ }
+
+
+ if (this->IncludeProjectDirsBefore)
+ {
+ const std::string &binDir = "-I" + this->ProjectBinaryDir;
+
+ const std::string srcDir = "-I" + this->ProjectSourceDir;
+
+ std::list<std::string> sortedMocIncludes;
+ std::list<std::string>::iterator it = this->MocIncludes.begin();
+ while (it != this->MocIncludes.end())
+ {
+ if (this->StartsWith(*it, binDir))
+ {
+ sortedMocIncludes.push_back(*it);
+ it = this->MocIncludes.erase(it);
+ }
+ else
+ {
+ ++it;
+ }
+ }
+ it = this->MocIncludes.begin();
+ while (it != this->MocIncludes.end())
+ {
+ if (this->StartsWith(*it, srcDir))
+ {
+ sortedMocIncludes.push_back(*it);
+ it = this->MocIncludes.erase(it);
+ }
+ else
+ {
+ ++it;
+ }
+ }
+ sortedMocIncludes.insert(sortedMocIncludes.end(),
+ this->MocIncludes.begin(), this->MocIncludes.end());
+ this->MocIncludes = sortedMocIncludes;
+ }
+
+}
+
+
+bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
+{
+ if (!cmsys::SystemTools::FileExists(this->OutMocCppFilename.c_str())
+ || (this->OldCompileSettingsStr != this->CurrentCompileSettingsStr))
+ {
+ this->GenerateAll = true;
+ }
+
+ // the program goes through all .cpp files to see which moc files are
+ // included. It is not really interesting how the moc file is named, but
+ // what file the moc is created from. Once a moc is included the same moc
+ // may not be included in the _automoc.cpp file anymore. OTOH if there's a
+ // header containing Q_OBJECT where no corresponding moc file is included
+ // anywhere a moc_<filename>.cpp file is created and included in
+ // the _automoc.cpp file.
+
+ // key = moc source filepath, value = moc output filepath
+ std::map<std::string, std::string> includedMocs;
+ // collect all headers which may need to be mocced
+ std::set<std::string> headerFiles;
+
+ std::vector<std::string> sourceFiles;
+ cmSystemTools::ExpandListArgument(this->Sources, sourceFiles);
+
+ const std::vector<std::string>& headerExtensions =
+ makefile->GetHeaderExtensions();
+
+ std::map<std::string, std::vector<std::string> > includedUis;
+ std::map<std::string, std::vector<std::string> > skippedUis;
+ std::vector<std::string> uicSkipped;
+ cmSystemTools::ExpandListArgument(this->SkipUic, uicSkipped);
+
+ for (std::vector<std::string>::const_iterator it = sourceFiles.begin();
+ it != sourceFiles.end();
+ ++it)
+ {
+ const bool skipUic = std::find(uicSkipped.begin(), uicSkipped.end(), *it)
+ != uicSkipped.end();
+ std::map<std::string, std::vector<std::string> >& uiFiles
+ = skipUic ? skippedUis : includedUis;
+ const std::string &absFilename = *it;
+ if (this->Verbose)
+ {
+ std::cout << "AUTOGEN: Checking " << absFilename << std::endl;
+ }
+ if (this->RelaxedMode)
+ {
+ this->ParseCppFile(absFilename, headerExtensions, includedMocs,
+ uiFiles);
+ }
+ else
+ {
+ this->StrictParseCppFile(absFilename, headerExtensions, includedMocs,
+ uiFiles);
+ }
+ this->SearchHeadersForCppFile(absFilename, headerExtensions, headerFiles);
+ }
+
+ {
+ std::vector<std::string> mocSkipped;
+ cmSystemTools::ExpandListArgument(this->SkipMoc, mocSkipped);
+ for (std::vector<std::string>::const_iterator it = mocSkipped.begin();
+ it != mocSkipped.end();
+ ++it)
+ {
+ if (std::find(uicSkipped.begin(), uicSkipped.end(), *it)
+ != uicSkipped.end())
+ {
+ const std::string &absFilename = *it;
+ if (this->Verbose)
+ {
+ std::cout << "AUTOGEN: Checking " << absFilename << std::endl;
+ }
+ this->ParseForUic(absFilename, includedUis);
+ }
+ }
+ }
+
+ std::vector<std::string> headerFilesVec;
+ cmSystemTools::ExpandListArgument(this->Headers, headerFilesVec);
+ for (std::vector<std::string>::const_iterator it = headerFilesVec.begin();
+ it != headerFilesVec.end();
+ ++it)
+ {
+ headerFiles.insert(*it);
+ }
+
+ // key = moc source filepath, value = moc output filename
+ std::map<std::string, std::string> notIncludedMocs;
+ this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs, includedUis);
+
+ // run moc on all the moc's that are #included in source files
+ for(std::map<std::string, std::string>::const_iterator
+ it = includedMocs.begin();
+ it != includedMocs.end();
+ ++it)
+ {
+ this->GenerateMoc(it->first, it->second);
+ }
+ for(std::map<std::string, std::vector<std::string> >::const_iterator
+ it = includedUis.begin();
+ it != includedUis.end();
+ ++it)
+ {
+ for (std::vector<std::string>::const_iterator nit = it->second.begin();
+ nit != it->second.end();
+ ++nit)
+ {
+ this->GenerateUi(it->first, *nit);
+ }
+ }
+
+ if(!this->RccExecutable.empty())
+ {
+ this->GenerateQrc();
+ }
+
+ cmsys_ios::stringstream outStream;
+ outStream << "/* This file is autogenerated, do not edit*/\n";
+
+ bool automocCppChanged = false;
+ if (notIncludedMocs.empty())
+ {
+ outStream << "enum some_compilers { need_more_than_nothing };\n";
+ }
+ else
+ {
+ // run moc on the remaining headers and include them in
+ // the _automoc.cpp file
+ for(std::map<std::string, std::string>::const_iterator
+ it = notIncludedMocs.begin();
+ it != notIncludedMocs.end();
+ ++it)
+ {
+ bool mocSuccess = this->GenerateMoc(it->first, it->second);
+ if (mocSuccess)
+ {
+ automocCppChanged = true;
+ }
+ outStream << "#include \"" << it->second << "\"\n";
+ }
+ }
+
+ if (this->RunMocFailed)
+ {
+ std::cerr << "moc failed..." << std::endl;
+ return false;
+ }
+
+ if (this->RunUicFailed)
+ {
+ std::cerr << "uic failed..." << std::endl;
+ return false;
+ }
+ if (this->RunRccFailed)
+ {
+ std::cerr << "rcc failed..." << std::endl;
+ return false;
+ }
+ outStream.flush();
+ std::string automocSource = outStream.str();
+ if (!automocCppChanged)
+ {
+ // compare contents of the _automoc.cpp file
+ const std::string oldContents = ReadAll(this->OutMocCppFilename);
+ if (oldContents == automocSource)
+ {
+ // nothing changed: don't touch the _automoc.cpp file
+ return true;
+ }
+ }
+
+ // source file that includes all remaining moc files (_automoc.cpp file)
+ cmsys::ofstream outfile;
+ outfile.open(this->OutMocCppFilename.c_str(),
+ std::ios::trunc);
+ outfile << automocSource;
+ outfile.close();
+
+ return true;
+}
+
+
+void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename,
+ const std::vector<std::string>& headerExtensions,
+ std::map<std::string, std::string>& includedMocs,
+ std::map<std::string, std::vector<std::string> > &includedUis)
+{
+ cmsys::RegularExpression mocIncludeRegExp(
+ "[\n][ \t]*#[ \t]*include[ \t]+"
+ "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]");
+
+ const std::string contentsString = ReadAll(absFilename);
+ if (contentsString.empty())
+ {
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n"
+ << std::endl;
+ return;
+ }
+ this->ParseForUic(absFilename, contentsString, includedUis);
+ if (this->MocExecutable.empty())
+ {
+ return;
+ }
+
+ const std::string absPath = cmsys::SystemTools::GetFilenamePath(
+ cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/';
+ const std::string scannedFileBasename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(absFilename);
+ std::string macroName;
+ const bool requiresMoc = requiresMocing(contentsString, macroName);
+ bool dotMocIncluded = false;
+ bool mocUnderscoreIncluded = false;
+ std::string ownMocUnderscoreFile;
+ std::string ownDotMocFile;
+ std::string ownMocHeaderFile;
+
+ std::string::size_type matchOffset = 0;
+ // first a simple string check for "moc" is *much* faster than the regexp,
+ // and if the string search already fails, we don't have to try the
+ // expensive regexp
+ if ((strstr(contentsString.c_str(), "moc") != NULL)
+ && (mocIncludeRegExp.find(contentsString)))
+ {
+ // for every moc include in the file
+ do
+ {
+ const std::string currentMoc = mocIncludeRegExp.match(1);
+ //std::cout << "found moc include: " << currentMoc << std::endl;
+
+ std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(currentMoc);
+ const bool moc_style = this->StartsWith(basename, "moc_");
+
+ // If the moc include is of the moc_foo.cpp style we expect
+ // the Q_OBJECT class declaration in a header file.
+ // If the moc include is of the foo.moc style we need to look for
+ // a Q_OBJECT macro in the current source file, if it contains the
+ // macro we generate the moc file from the source file.
+ // Q_OBJECT
+ if (moc_style)
+ {
+ // basename should be the part of the moc filename used for
+ // finding the correct header, so we need to remove the moc_ part
+ basename = basename.substr(4);
+ std::string mocSubDir = extractSubDir(absPath, currentMoc);
+ std::string headerToMoc = findMatchingHeader(
+ absPath, mocSubDir, basename, headerExtensions);
+
+ if (!headerToMoc.empty())
+ {
+ includedMocs[headerToMoc] = currentMoc;
+ if (basename == scannedFileBasename)
+ {
+ mocUnderscoreIncluded = true;
+ ownMocUnderscoreFile = currentMoc;
+ ownMocHeaderFile = headerToMoc;
+ }
+ }
+ else
+ {
+ std::cerr << "AUTOGEN: error: " << absFilename << ": The file "
+ << "includes the moc file \"" << currentMoc << "\", "
+ << "but could not find header \"" << basename
+ << '{' << this->Join(headerExtensions, ',') << "}\" ";
+ if (mocSubDir.empty())
+ {
+ std::cerr << "in " << absPath << "\n" << std::endl;
+ }
+ else
+ {
+ std::cerr << "neither in " << absPath
+ << " nor in " << mocSubDir << "\n" << std::endl;
+ }
+
+ ::exit(EXIT_FAILURE);
+ }
+ }
+ else
+ {
+ std::string fileToMoc = absFilename;
+ if ((basename != scannedFileBasename) || (requiresMoc==false))
+ {
+ std::string mocSubDir = extractSubDir(absPath, currentMoc);
+ std::string headerToMoc = findMatchingHeader(
+ absPath, mocSubDir, basename, headerExtensions);
+ if (!headerToMoc.empty())
+ {
+ // this is for KDE4 compatibility:
+ fileToMoc = headerToMoc;
+ if ((requiresMoc==false) &&(basename==scannedFileBasename))
+ {
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": The file "
+ "includes the moc file \"" << currentMoc <<
+ "\", but does not contain a " << macroName
+ << " macro. Running moc on "
+ << "\"" << headerToMoc << "\" ! Include \"moc_"
+ << basename << ".cpp\" for a compatiblity with "
+ "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n"
+ << std::endl;
+ }
+ else
+ {
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": The file "
+ "includes the moc file \"" << currentMoc <<
+ "\" instead of \"moc_" << basename << ".cpp\". "
+ "Running moc on "
+ << "\"" << headerToMoc << "\" ! Include \"moc_"
+ << basename << ".cpp\" for compatiblity with "
+ "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cerr <<"AUTOGEN: error: " << absFilename << ": The file "
+ "includes the moc file \"" << currentMoc <<
+ "\", which seems to be the moc file from a different "
+ "source file. CMake also could not find a matching "
+ "header.\n" << std::endl;
+ ::exit(EXIT_FAILURE);
+ }
+ }
+ else
+ {
+ dotMocIncluded = true;
+ ownDotMocFile = currentMoc;
+ }
+ includedMocs[fileToMoc] = currentMoc;
+ }
+ matchOffset += mocIncludeRegExp.end();
+ } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
+ }
+
+ // In this case, check whether the scanned file itself contains a Q_OBJECT.
+ // If this is the case, the moc_foo.cpp should probably be generated from
+ // foo.cpp instead of foo.h, because otherwise it won't build.
+ // But warn, since this is not how it is supposed to be used.
+ if ((dotMocIncluded == false) && (requiresMoc == true))
+ {
+ if (mocUnderscoreIncluded == true)
+ {
+ // this is for KDE4 compatibility:
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": The file "
+ << "contains a " << macroName << " macro, but does not "
+ "include "
+ << "\"" << scannedFileBasename << ".moc\", but instead "
+ "includes "
+ << "\"" << ownMocUnderscoreFile << "\". Running moc on "
+ << "\"" << absFilename << "\" ! Better include \""
+ << scannedFileBasename << ".moc\" for compatiblity with "
+ "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n"
+ << std::endl;
+ includedMocs[absFilename] = ownMocUnderscoreFile;
+ includedMocs.erase(ownMocHeaderFile);
+ }
+ else
+ {
+ // otherwise always error out since it will not compile:
+ std::cerr << "AUTOGEN: error: " << absFilename << ": The file "
+ << "contains a " << macroName << " macro, but does not "
+ "include "
+ << "\"" << scannedFileBasename << ".moc\" !\n"
+ << std::endl;
+ ::exit(EXIT_FAILURE);
+ }
+ }
+
+}
+
+
+void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename,
+ const std::vector<std::string>& headerExtensions,
+ std::map<std::string, std::string>& includedMocs,
+ std::map<std::string, std::vector<std::string> >& includedUis)
+{
+ cmsys::RegularExpression mocIncludeRegExp(
+ "[\n][ \t]*#[ \t]*include[ \t]+"
+ "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]");
+
+ const std::string contentsString = ReadAll(absFilename);
+ if (contentsString.empty())
+ {
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n"
+ << std::endl;
+ return;
+ }
+ this->ParseForUic(absFilename, contentsString, includedUis);
+ if (this->MocExecutable.empty())
+ {
+ return;
+ }
+
+ const std::string absPath = cmsys::SystemTools::GetFilenamePath(
+ cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/';
+ const std::string scannedFileBasename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(absFilename);
+
+ bool dotMocIncluded = false;
+
+ std::string::size_type matchOffset = 0;
+ // first a simple string check for "moc" is *much* faster than the regexp,
+ // and if the string search already fails, we don't have to try the
+ // expensive regexp
+ if ((strstr(contentsString.c_str(), "moc") != NULL)
+ && (mocIncludeRegExp.find(contentsString)))
+ {
+ // for every moc include in the file
+ do
+ {
+ const std::string currentMoc = mocIncludeRegExp.match(1);
+
+ std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(currentMoc);
+ const bool mocUnderscoreStyle = this->StartsWith(basename, "moc_");
+
+ // If the moc include is of the moc_foo.cpp style we expect
+ // the Q_OBJECT class declaration in a header file.
+ // If the moc include is of the foo.moc style we need to look for
+ // a Q_OBJECT macro in the current source file, if it contains the
+ // macro we generate the moc file from the source file.
+ if (mocUnderscoreStyle)
+ {
+ // basename should be the part of the moc filename used for
+ // finding the correct header, so we need to remove the moc_ part
+ basename = basename.substr(4);
+ std::string mocSubDir = extractSubDir(absPath, currentMoc);
+ std::string headerToMoc = findMatchingHeader(
+ absPath, mocSubDir, basename, headerExtensions);
+
+ if (!headerToMoc.empty())
+ {
+ includedMocs[headerToMoc] = currentMoc;
+ }
+ else
+ {
+ std::cerr << "AUTOGEN: error: " << absFilename << " The file "
+ << "includes the moc file \"" << currentMoc << "\", "
+ << "but could not find header \"" << basename
+ << '{' << this->Join(headerExtensions, ',') << "}\" ";
+ if (mocSubDir.empty())
+ {
+ std::cerr << "in " << absPath << "\n" << std::endl;
+ }
+ else
+ {
+ std::cerr << "neither in " << absPath
+ << " nor in " << mocSubDir << "\n" << std::endl;
+ }
+
+ ::exit(EXIT_FAILURE);
+ }
+ }
+ else
+ {
+ if (basename != scannedFileBasename)
+ {
+ std::cerr <<"AUTOGEN: error: " << absFilename << ": The file "
+ "includes the moc file \"" << currentMoc <<
+ "\", which seems to be the moc file from a different "
+ "source file. This is not supported. "
+ "Include \"" << scannedFileBasename << ".moc\" to run "
+ "moc on this source file.\n" << std::endl;
+ ::exit(EXIT_FAILURE);
+ }
+ dotMocIncluded = true;
+ includedMocs[absFilename] = currentMoc;
+ }
+ matchOffset += mocIncludeRegExp.end();
+ } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
+ }
+
+ // In this case, check whether the scanned file itself contains a Q_OBJECT.
+ // If this is the case, the moc_foo.cpp should probably be generated from
+ // foo.cpp instead of foo.h, because otherwise it won't build.
+ // But warn, since this is not how it is supposed to be used.
+ std::string macroName;
+ if ((dotMocIncluded == false) && (requiresMocing(contentsString,
+ macroName)))
+ {
+ // otherwise always error out since it will not compile:
+ std::cerr << "AUTOGEN: error: " << absFilename << ": The file "
+ << "contains a " << macroName << " macro, but does not include "
+ << "\"" << scannedFileBasename << ".moc\" !\n"
+ << std::endl;
+ ::exit(EXIT_FAILURE);
+ }
+
+}
+
+
+void cmQtAutoGenerators::ParseForUic(const std::string& absFilename,
+ std::map<std::string, std::vector<std::string> >& includedUis)
+{
+ if (this->UicExecutable.empty())
+ {
+ return;
+ }
+ const std::string contentsString = ReadAll(absFilename);
+ if (contentsString.empty())
+ {
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n"
+ << std::endl;
+ return;
+ }
+ this->ParseForUic(absFilename, contentsString, includedUis);
+}
+
+
+void cmQtAutoGenerators::ParseForUic(const std::string& absFilename,
+ const std::string& contentsString,
+ std::map<std::string, std::vector<std::string> >& includedUis)
+{
+ if (this->UicExecutable.empty())
+ {
+ return;
+ }
+ cmsys::RegularExpression uiIncludeRegExp(
+ "[\n][ \t]*#[ \t]*include[ \t]+"
+ "[\"<](([^ \">]+/)?ui_[^ \">/]+\\.h)[\">]");
+
+ std::string::size_type matchOffset = 0;
+
+ const std::string realName =
+ cmsys::SystemTools::GetRealPath(absFilename.c_str());
+
+ matchOffset = 0;
+ if ((strstr(contentsString.c_str(), "ui_") != NULL)
+ && (uiIncludeRegExp.find(contentsString)))
+ {
+ do
+ {
+ const std::string currentUi = uiIncludeRegExp.match(1);
+
+ std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(currentUi);
+
+ // basename should be the part of the ui filename used for
+ // finding the correct header, so we need to remove the ui_ part
+ basename = basename.substr(3);
+
+ includedUis[realName].push_back(basename);
+
+ matchOffset += uiIncludeRegExp.end();
+ } while(uiIncludeRegExp.find(contentsString.c_str() + matchOffset));
+ }
+}
+
+
+void
+cmQtAutoGenerators::SearchHeadersForCppFile(const std::string& absFilename,
+ const std::vector<std::string>& headerExtensions,
+ std::set<std::string>& absHeaders)
+{
+ // search for header files and private header files we may need to moc:
+ const std::string basename =
+ cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename);
+ const std::string absPath = cmsys::SystemTools::GetFilenamePath(
+ cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/';
+
+ for(std::vector<std::string>::const_iterator ext = headerExtensions.begin();
+ ext != headerExtensions.end();
+ ++ext)
+ {
+ const std::string headerName = absPath + basename + "." + (*ext);
+ if (cmsys::SystemTools::FileExists(headerName.c_str()))
+ {
+ absHeaders.insert(headerName);
+ break;
+ }
+ }
+ for(std::vector<std::string>::const_iterator ext = headerExtensions.begin();
+ ext != headerExtensions.end();
+ ++ext)
+ {
+ const std::string privateHeaderName = absPath+basename+"_p."+(*ext);
+ if (cmsys::SystemTools::FileExists(privateHeaderName.c_str()))
+ {
+ absHeaders.insert(privateHeaderName);
+ break;
+ }
+ }
+
+}
+
+
+void cmQtAutoGenerators::ParseHeaders(const std::set<std::string>& absHeaders,
+ const std::map<std::string, std::string>& includedMocs,
+ std::map<std::string, std::string>& notIncludedMocs,
+ std::map<std::string, std::vector<std::string> >& includedUis)
+{
+ for(std::set<std::string>::const_iterator hIt=absHeaders.begin();
+ hIt!=absHeaders.end();
+ ++hIt)
+ {
+ const std::string& headerName = *hIt;
+ const std::string contents = ReadAll(headerName);
+
+ if (!this->MocExecutable.empty()
+ && includedMocs.find(headerName) == includedMocs.end())
+ {
+ if (this->Verbose)
+ {
+ std::cout << "AUTOGEN: Checking " << headerName << std::endl;
+ }
+
+ const std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(headerName);
+
+ const std::string currentMoc = "moc_" + basename + ".cpp";
+ std::string macroName;
+ if (requiresMocing(contents, macroName))
+ {
+ //std::cout << "header contains Q_OBJECT macro";
+ notIncludedMocs[headerName] = currentMoc;
+ }
+ }
+ this->ParseForUic(headerName, contents, includedUis);
+ }
+}
+
+bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
+ const std::string& mocFileName)
+{
+ const std::string mocFilePath = this->Builddir + mocFileName;
+ int sourceNewerThanMoc = 0;
+ bool success = cmsys::SystemTools::FileTimeCompare(sourceFile.c_str(),
+ mocFilePath.c_str(),
+ &sourceNewerThanMoc);
+ if (this->GenerateAll || !success || sourceNewerThanMoc >= 0)
+ {
+ // make sure the directory for the resulting moc file exists
+ std::string mocDir = mocFilePath.substr(0, mocFilePath.rfind('/'));
+ if (!cmsys::SystemTools::FileExists(mocDir.c_str(), false))
+ {
+ cmsys::SystemTools::MakeDirectory(mocDir.c_str());
+ }
+
+ std::string msg = "Generating ";
+ msg += mocFileName;
+ cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue
+ |cmsysTerminal_Color_ForegroundBold,
+ msg.c_str(), true, this->ColorOutput);
+
+ std::vector<std::string> command;
+ command.push_back(this->MocExecutable);
+ for (std::list<std::string>::const_iterator it = this->MocIncludes.begin();
+ it != this->MocIncludes.end();
+ ++it)
+ {
+ command.push_back(*it);
+ }
+ for(std::list<std::string>::const_iterator it=this->MocDefinitions.begin();
+ it != this->MocDefinitions.end();
+ ++it)
+ {
+ command.push_back(*it);
+ }
+ for(std::vector<std::string>::const_iterator it=this->MocOptions.begin();
+ it != this->MocOptions.end();
+ ++it)
+ {
+ command.push_back(*it);
+ }
+#ifdef _WIN32
+ command.push_back("-DWIN32");
+#endif
+ command.push_back("-o");
+ command.push_back(mocFilePath);
+ command.push_back(sourceFile);
+
+ if (this->Verbose)
+ {
+ for(std::vector<std::string>::const_iterator cmdIt = command.begin();
+ cmdIt != command.end();
+ ++cmdIt)
+ {
+ std::cout << *cmdIt << " ";
+ }
+ std::cout << std::endl;
+ }
+
+ std::string output;
+ int retVal = 0;
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal);
+ if (!result || retVal)
+ {
+ std::cerr << "AUTOGEN: error: process for " << mocFilePath <<" failed:\n"
+ << output << std::endl;
+ this->RunMocFailed = true;
+ cmSystemTools::RemoveFile(mocFilePath.c_str());
+ }
+ return true;
+ }
+ return false;
+}
+
+bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
+ const std::string& uiFileName)
+{
+ if (!cmsys::SystemTools::FileExists(this->Builddir.c_str(), false))
+ {
+ cmsys::SystemTools::MakeDirectory(this->Builddir.c_str());
+ }
+
+ const std::string path = cmsys::SystemTools::GetFilenamePath(
+ realName.c_str()) + '/';
+
+ std::string ui_output_file = "ui_" + uiFileName + ".h";
+ std::string ui_input_file = path + uiFileName + ".ui";
+
+ int sourceNewerThanUi = 0;
+ bool success = cmsys::SystemTools::FileTimeCompare(ui_input_file.c_str(),
+ (this->Builddir + ui_output_file).c_str(),
+ &sourceNewerThanUi);
+ if (this->GenerateAll || !success || sourceNewerThanUi >= 0)
+ {
+ std::string msg = "Generating ";
+ msg += ui_output_file;
+ cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue
+ |cmsysTerminal_Color_ForegroundBold,
+ msg.c_str(), true, this->ColorOutput);
+
+ std::vector<std::string> command;
+ command.push_back(this->UicExecutable);
+
+ std::vector<std::string> opts = this->UicTargetOptions;
+ std::map<std::string, std::string>::const_iterator optionIt
+ = this->UicOptions.find(ui_input_file);
+ if (optionIt != this->UicOptions.end())
+ {
+ std::vector<std::string> fileOpts;
+ cmSystemTools::ExpandListArgument(optionIt->second, fileOpts);
+ this->MergeUicOptions(opts, fileOpts, this->QtMajorVersion == "5");
+ }
+ for(std::vector<std::string>::const_iterator optIt = opts.begin();
+ optIt != opts.end();
+ ++optIt)
+ {
+ command.push_back(*optIt);
+ }
+
+ command.push_back("-o");
+ command.push_back(this->Builddir + ui_output_file);
+ command.push_back(ui_input_file);
+
+ if (this->Verbose)
+ {
+ for(std::vector<std::string>::const_iterator cmdIt = command.begin();
+ cmdIt != command.end();
+ ++cmdIt)
+ {
+ std::cout << *cmdIt << " ";
+ }
+ std::cout << std::endl;
+ }
+ std::string output;
+ int retVal = 0;
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal);
+ if (!result || retVal)
+ {
+ std::cerr << "AUTOUIC: error: process for " << ui_output_file <<
+ " failed:\n" << output << std::endl;
+ this->RunUicFailed = true;
+ cmSystemTools::RemoveFile(ui_output_file.c_str());
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
+bool cmQtAutoGenerators::GenerateQrc()
+{
+ std::vector<std::string> sourceFiles;
+ cmSystemTools::ExpandListArgument(this->RccSources, sourceFiles);
+
+ for(std::vector<std::string>::const_iterator si = sourceFiles.begin();
+ si != sourceFiles.end(); ++si)
+ {
+ std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si);
+
+ if (ext != ".qrc")
+ {
+ continue;
+ }
+ std::vector<std::string> command;
+ command.push_back(this->RccExecutable);
+
+ std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(*si);
+
+ std::string rcc_output_file = this->Builddir
+ + "CMakeFiles/" + this->OriginTargetName
+ + ".dir/qrc_" + basename + ".cpp";
+
+ int sourceNewerThanQrc = 0;
+ bool success = cmsys::SystemTools::FileTimeCompare(si->c_str(),
+ rcc_output_file.c_str(),
+ &sourceNewerThanQrc);
+ if (this->GenerateAll || !success || sourceNewerThanQrc >= 0)
+ {
+ std::map<std::string, std::string>::const_iterator optionIt
+ = this->RccOptions.find(*si);
+ if (optionIt != this->RccOptions.end())
+ {
+ std::vector<std::string> opts;
+ cmSystemTools::ExpandListArgument(optionIt->second, opts);
+ for(std::vector<std::string>::const_iterator optIt = opts.begin();
+ optIt != opts.end();
+ ++optIt)
+ {
+ command.push_back(*optIt);
+ }
+ }
+
+ command.push_back("-name");
+ command.push_back(basename);
+ command.push_back("-o");
+ command.push_back(rcc_output_file);
+ command.push_back(*si);
+
+ if (this->Verbose)
+ {
+ for(std::vector<std::string>::const_iterator cmdIt = command.begin();
+ cmdIt != command.end();
+ ++cmdIt)
+ {
+ std::cout << *cmdIt << " ";
+ }
+ std::cout << std::endl;
+ }
+ std::string output;
+ int retVal = 0;
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal);
+ if (!result || retVal)
+ {
+ std::cerr << "AUTORCC: error: process for " << rcc_output_file <<
+ " failed:\n" << output << std::endl;
+ this->RunRccFailed = true;
+ cmSystemTools::RemoveFile(rcc_output_file.c_str());
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+std::string cmQtAutoGenerators::Join(const std::vector<std::string>& lst,
+ char separator)
+{
+ if (lst.empty())
+ {
+ return "";
+ }
+
+ std::string result;
+ for (std::vector<std::string>::const_iterator it = lst.begin();
+ it != lst.end();
+ ++it)
+ {
+ result += "." + (*it) + separator;
+ }
+ result.erase(result.end() - 1);
+ return result;
+}
+
+
+bool cmQtAutoGenerators::StartsWith(const std::string& str,
+ const std::string& with)
+{
+ return (str.substr(0, with.length()) == with);
+}
+
+
+bool cmQtAutoGenerators::EndsWith(const std::string& str,
+ const std::string& with)
+{
+ if (with.length() > (str.length()))
+ {
+ return false;
+ }
+ return (str.substr(str.length() - with.length(), with.length()) == with);
+}
diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h
new file mode 100644
index 0000000000..c298f5d283
--- /dev/null
+++ b/Source/cmQtAutoGenerators.h
@@ -0,0 +1,130 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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.
+============================================================================*/
+
+#ifndef cmQtAutoGenerators_h
+#define cmQtAutoGenerators_h
+
+class cmGlobalGenerator;
+class cmMakefile;
+
+class cmQtAutoGenerators
+{
+public:
+ cmQtAutoGenerators();
+ bool Run(const std::string& targetDirectory, const std::string& config);
+
+ bool InitializeAutogenTarget(cmTarget* target);
+ void SetupAutoGenerateTarget(cmTarget const* target);
+ void SetupSourceFiles(cmTarget const* target);
+
+private:
+ void SetupAutoMocTarget(cmTarget const* target,
+ const std::string &autogenTargetName,
+ std::map<std::string, std::string> &configIncludes,
+ std::map<std::string, std::string> &configDefines);
+ void SetupAutoUicTarget(cmTarget const* target,
+ std::map<std::string, std::string> &configUicOptions);
+ void SetupAutoRccTarget(cmTarget const* target);
+
+ bool ReadAutogenInfoFile(cmMakefile* makefile,
+ const std::string& targetDirectory,
+ const std::string& config);
+ bool ReadOldMocDefinitionsFile(cmMakefile* makefile,
+ const std::string& targetDirectory);
+ void WriteOldMocDefinitionsFile(const std::string& targetDirectory);
+
+ std::string MakeCompileSettingsString(cmMakefile* makefile);
+
+ bool RunAutogen(cmMakefile* makefile);
+ bool GenerateMoc(const std::string& sourceFile,
+ const std::string& mocFileName);
+ bool GenerateUi(const std::string& realName, const std::string& uiFileName);
+ bool GenerateQrc();
+ void ParseCppFile(const std::string& absFilename,
+ const std::vector<std::string>& headerExtensions,
+ std::map<std::string, std::string>& includedMocs,
+ std::map<std::string, std::vector<std::string> >& includedUis);
+ void StrictParseCppFile(const std::string& absFilename,
+ const std::vector<std::string>& headerExtensions,
+ std::map<std::string, std::string>& includedMocs,
+ std::map<std::string, std::vector<std::string> >& includedUis);
+ void SearchHeadersForCppFile(const std::string& absFilename,
+ const std::vector<std::string>& headerExtensions,
+ std::set<std::string>& absHeaders);
+
+ void ParseHeaders(const std::set<std::string>& absHeaders,
+ const std::map<std::string, std::string>& includedMocs,
+ std::map<std::string, std::string>& notIncludedMocs,
+ std::map<std::string, std::vector<std::string> >& includedUis);
+
+ void ParseForUic(const std::string& fileName,
+ const std::string& contentsString,
+ std::map<std::string, std::vector<std::string> >& includedUis);
+
+ void ParseForUic(const std::string& fileName,
+ std::map<std::string, std::vector<std::string> >& includedUis);
+
+ void Init();
+
+ std::string Join(const std::vector<std::string>& lst, char separator);
+ bool EndsWith(const std::string& str, const std::string& with);
+ bool StartsWith(const std::string& str, const std::string& with);
+
+ void MergeUicOptions(std::vector<std::string> &opts,
+ const std::vector<std::string> &fileOpts, bool isQt5);
+
+ void MergeRccOptions(std::vector<std::string> &opts,
+ const std::vector<std::string> &fileOpts, bool isQt5);
+
+ std::string QtMajorVersion;
+ std::string Sources;
+ std::string RccSources;
+ std::string SkipMoc;
+ std::string SkipUic;
+ std::string Headers;
+ bool IncludeProjectDirsBefore;
+ std::string Srcdir;
+ std::string Builddir;
+ std::string MocExecutable;
+ std::string UicExecutable;
+ std::string RccExecutable;
+ std::string MocCompileDefinitionsStr;
+ std::string MocIncludesStr;
+ std::string MocOptionsStr;
+ std::string ProjectBinaryDir;
+ std::string ProjectSourceDir;
+ std::string TargetName;
+ std::string OriginTargetName;
+
+ std::string CurrentCompileSettingsStr;
+ std::string OldCompileSettingsStr;
+
+ std::string OutMocCppFilename;
+ std::list<std::string> MocIncludes;
+ std::list<std::string> MocDefinitions;
+ std::vector<std::string> MocOptions;
+ std::vector<std::string> UicTargetOptions;
+ std::map<std::string, std::string> UicOptions;
+ std::map<std::string, std::string> RccOptions;
+
+ bool Verbose;
+ bool ColorOutput;
+ bool RunMocFailed;
+ bool RunUicFailed;
+ bool RunRccFailed;
+ bool GenerateAll;
+ bool RelaxedMode;
+
+};
+
+#endif
diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx
new file mode 100644
index 0000000000..cca995b120
--- /dev/null
+++ b/Source/cmRST.cxx
@@ -0,0 +1,511 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 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 "cmRST.h"
+
+#include "cmSystemTools.h"
+#include "cmVersion.h"
+#include <cmsys/FStream.hxx>
+#include <ctype.h>
+
+//----------------------------------------------------------------------------
+cmRST::cmRST(std::ostream& os, std::string const& docroot):
+ OS(os),
+ DocRoot(docroot),
+ IncludeDepth(0),
+ OutputLinePending(false),
+ LastLineEndedInColonColon(false),
+ Markup(MarkupNone),
+ Directive(DirectiveNone),
+ CMakeDirective("^.. (cmake:)?("
+ "command|variable"
+ ")::[ \t]+([^ \t\n]+)$"),
+ CMakeModuleDirective("^.. cmake-module::[ \t]+([^ \t\n]+)$"),
+ ParsedLiteralDirective("^.. parsed-literal::[ \t]*(.*)$"),
+ CodeBlockDirective("^.. code-block::[ \t]*(.*)$"),
+ ReplaceDirective("^.. (\\|[^|]+\\|) replace::[ \t]*(.*)$"),
+ IncludeDirective("^.. include::[ \t]+([^ \t\n]+)$"),
+ TocTreeDirective("^.. toctree::[ \t]*(.*)$"),
+ ProductionListDirective("^.. productionlist::[ \t]*(.*)$"),
+ NoteDirective("^.. note::[ \t]*(.*)$"),
+ ModuleRST("^#\\[(=*)\\[\\.rst:$"),
+ CMakeRole("(:cmake)?:("
+ "command|generator|variable|module|policy|"
+ "prop_cache|prop_dir|prop_gbl|prop_inst|prop_sf|"
+ "prop_test|prop_tgt|"
+ "manual"
+ "):`(<*([^`<]|[^` \t]<)*)([ \t]+<[^`]*>)?`"),
+ Substitution("(^|[^A-Za-z0-9_])"
+ "((\\|[^| \t\r\n]([^|\r\n]*[^| \t\r\n])?\\|)(__|_|))"
+ "([^A-Za-z0-9_]|$)")
+{
+ this->Replace["|release|"] = cmVersion::GetCMakeVersion();
+}
+
+//----------------------------------------------------------------------------
+bool cmRST::ProcessFile(std::string const& fname, bool isModule)
+{
+ cmsys::ifstream fin(fname.c_str());
+ if(fin)
+ {
+ this->DocDir = cmSystemTools::GetFilenamePath(fname);
+ if(isModule)
+ {
+ this->ProcessModule(fin);
+ }
+ else
+ {
+ this->ProcessRST(fin);
+ }
+ this->OutputLinePending = true;
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmRST::ProcessRST(std::istream& is)
+{
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(is, line))
+ {
+ this->ProcessLine(line);
+ }
+ this->Reset();
+}
+
+//----------------------------------------------------------------------------
+void cmRST::ProcessModule(std::istream& is)
+{
+ std::string line;
+ std::string rst;
+ while(cmSystemTools::GetLineFromStream(is, line))
+ {
+ if(!rst.empty() && rst != "#")
+ {
+ // Bracket mode: check for end bracket
+ std::string::size_type pos = line.find(rst);
+ if(pos == line.npos)
+ {
+ this->ProcessLine(line);
+ }
+ else
+ {
+ if(line[0] != '#')
+ {
+ this->ProcessLine(line.substr(0, pos));
+ }
+ rst = "";
+ this->Reset();
+ this->OutputLinePending = true;
+ }
+ }
+ else
+ {
+ // Line mode: check for .rst start (bracket or line)
+ if(rst == "#")
+ {
+ if(line == "#")
+ {
+ this->ProcessLine("");
+ continue;
+ }
+ else if(line.substr(0, 2) == "# ")
+ {
+ this->ProcessLine(line.substr(2, line.npos));
+ continue;
+ }
+ else
+ {
+ rst = "";
+ this->Reset();
+ this->OutputLinePending = true;
+ }
+ }
+ if(line == "#.rst:")
+ {
+ rst = "#";
+ }
+ else if(this->ModuleRST.find(line))
+ {
+ rst = "]" + this->ModuleRST.match(1) + "]";
+ }
+ }
+ }
+ if(rst == "#")
+ {
+ this->Reset();
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmRST::Reset()
+{
+ if(!this->MarkupLines.empty())
+ {
+ this->UnindentLines(this->MarkupLines);
+ }
+ switch(this->Directive)
+ {
+ case DirectiveNone: break;
+ case DirectiveParsedLiteral: this->ProcessDirectiveParsedLiteral(); break;
+ case DirectiveLiteralBlock: this->ProcessDirectiveLiteralBlock(); break;
+ case DirectiveCodeBlock: this->ProcessDirectiveCodeBlock(); break;
+ case DirectiveReplace: this->ProcessDirectiveReplace(); break;
+ case DirectiveTocTree: this->ProcessDirectiveTocTree(); break;
+ }
+ this->Markup = MarkupNone;
+ this->Directive = DirectiveNone;
+ this->MarkupLines.clear();
+}
+
+//----------------------------------------------------------------------------
+void cmRST::ProcessLine(std::string const& line)
+{
+ bool lastLineEndedInColonColon = this->LastLineEndedInColonColon;
+ this->LastLineEndedInColonColon = false;
+
+ // A line starting in .. is an explicit markup start.
+ if(line == ".." || (line.size() >= 3 && line[0] == '.' &&
+ line[1] == '.' && isspace(line[2])))
+ {
+ this->Reset();
+ this->Markup = (line.find_first_not_of(" \t", 2) == line.npos ?
+ MarkupEmpty : MarkupNormal);
+ if(this->CMakeDirective.find(line))
+ {
+ // Output cmake domain directives and their content normally.
+ this->NormalLine(line);
+ }
+ else if(this->CMakeModuleDirective.find(line))
+ {
+ // Process cmake-module directive: scan .cmake file comments.
+ std::string file = this->CMakeModuleDirective.match(1);
+ if(file.empty() || !this->ProcessInclude(file, IncludeModule))
+ {
+ this->NormalLine(line);
+ }
+ }
+ else if(this->ParsedLiteralDirective.find(line))
+ {
+ // Record the literal lines to output after whole block.
+ this->Directive = DirectiveParsedLiteral;
+ this->MarkupLines.push_back(this->ParsedLiteralDirective.match(1));
+ }
+ else if(this->CodeBlockDirective.find(line))
+ {
+ // Record the literal lines to output after whole block.
+ // Ignore the language spec and record the opening line as blank.
+ this->Directive = DirectiveCodeBlock;
+ this->MarkupLines.push_back("");
+ }
+ else if(this->ReplaceDirective.find(line))
+ {
+ // Record the replace directive content.
+ this->Directive = DirectiveReplace;
+ this->ReplaceName = this->ReplaceDirective.match(1);
+ this->MarkupLines.push_back(this->ReplaceDirective.match(2));
+ }
+ else if(this->IncludeDirective.find(line))
+ {
+ // Process the include directive or output the directive and its
+ // content normally if it fails.
+ std::string file = this->IncludeDirective.match(1);
+ if(file.empty() || !this->ProcessInclude(file, IncludeNormal))
+ {
+ this->NormalLine(line);
+ }
+ }
+ else if(this->TocTreeDirective.find(line))
+ {
+ // Record the toctree entries to process after whole block.
+ this->Directive = DirectiveTocTree;
+ this->MarkupLines.push_back(this->TocTreeDirective.match(1));
+ }
+ else if(this->ProductionListDirective.find(line))
+ {
+ // Output productionlist directives and their content normally.
+ this->NormalLine(line);
+ }
+ else if(this->NoteDirective.find(line))
+ {
+ // Output note directives and their content normally.
+ this->NormalLine(line);
+ }
+ }
+ // An explicit markup start followed nothing but whitespace and a
+ // blank line does not consume any indented text following.
+ else if(this->Markup == MarkupEmpty && line.empty())
+ {
+ this->NormalLine(line);
+ }
+ // Indented lines following an explicit markup start are explicit markup.
+ else if(this->Markup && (line.empty() || isspace(line[0])))
+ {
+ this->Markup = MarkupNormal;
+ // Record markup lines if the start line was recorded.
+ if(!this->MarkupLines.empty())
+ {
+ this->MarkupLines.push_back(line);
+ }
+ }
+ // A blank line following a paragraph ending in "::" starts a literal block.
+ else if(lastLineEndedInColonColon && line.empty())
+ {
+ // Record the literal lines to output after whole block.
+ this->Markup = MarkupNormal;
+ this->Directive = DirectiveLiteralBlock;
+ this->MarkupLines.push_back("");
+ this->OutputLine("", false);
+ }
+ // Print non-markup lines.
+ else
+ {
+ this->NormalLine(line);
+ this->LastLineEndedInColonColon = (line.size() >= 2
+ && line[line.size()-2] == ':' && line[line.size()-1] == ':');
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmRST::NormalLine(std::string const& line)
+{
+ this->Reset();
+ this->OutputLine(line, true);
+}
+
+//----------------------------------------------------------------------------
+void cmRST::OutputLine(std::string const& line_in, bool inlineMarkup)
+{
+ if(this->OutputLinePending)
+ {
+ this->OS << "\n";
+ this->OutputLinePending = false;
+ }
+ if(inlineMarkup)
+ {
+ std::string line = this->ReplaceSubstitutions(line_in);
+ std::string::size_type pos = 0;
+ while(this->CMakeRole.find(line.c_str()+pos))
+ {
+ this->OS << line.substr(pos, this->CMakeRole.start());
+ std::string text = this->CMakeRole.match(3);
+ // If a command reference has no explicit target and
+ // no explicit "(...)" then add "()" to the text.
+ if(this->CMakeRole.match(2) == "command" &&
+ this->CMakeRole.match(5).empty() &&
+ text.find_first_of("()") == text.npos)
+ {
+ text += "()";
+ }
+ this->OS << "``" << text << "``";
+ pos += this->CMakeRole.end();
+ }
+ this->OS << line.substr(pos) << "\n";
+ }
+ else
+ {
+ this->OS << line_in << "\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmRST::ReplaceSubstitutions(std::string const& line)
+{
+ std::string out;
+ std::string::size_type pos = 0;
+ while(this->Substitution.find(line.c_str()+pos))
+ {
+ std::string::size_type start = this->Substitution.start(2);
+ std::string::size_type end = this->Substitution.end(2);
+ std::string substitute = this->Substitution.match(3);
+ std::map<std::string, std::string>::iterator
+ replace = this->Replace.find(substitute);
+ if(replace != this->Replace.end())
+ {
+ std::pair<std::set<std::string>::iterator, bool> replaced =
+ this->Replaced.insert(substitute);
+ if(replaced.second)
+ {
+ substitute = this->ReplaceSubstitutions(replace->second);
+ this->Replaced.erase(replaced.first);
+ }
+ }
+ out += line.substr(pos, start);
+ out += substitute;
+ pos += end;
+ }
+ out += line.substr(pos);
+ return out;
+}
+
+//----------------------------------------------------------------------------
+void cmRST::OutputMarkupLines(bool inlineMarkup)
+{
+ for(std::vector<std::string>::iterator i = this->MarkupLines.begin();
+ i != this->MarkupLines.end(); ++i)
+ {
+ std::string line = *i;
+ if(!line.empty())
+ {
+ line = " " + line;
+ }
+ this->OutputLine(line, inlineMarkup);
+ }
+ this->OutputLinePending = true;
+}
+
+//----------------------------------------------------------------------------
+bool cmRST::ProcessInclude(std::string file, IncludeType type)
+{
+ bool found = false;
+ if(this->IncludeDepth < 10)
+ {
+ cmRST r(this->OS, this->DocRoot);
+ r.IncludeDepth = this->IncludeDepth + 1;
+ r.OutputLinePending = this->OutputLinePending;
+ if(type != IncludeTocTree)
+ {
+ r.Replace = this->Replace;
+ }
+ if(file[0] == '/')
+ {
+ file = this->DocRoot + file;
+ }
+ else
+ {
+ file = this->DocDir + "/" + file;
+ }
+ found = r.ProcessFile(file, type == IncludeModule);
+ if(type != IncludeTocTree)
+ {
+ this->Replace = r.Replace;
+ }
+ this->OutputLinePending = r.OutputLinePending;
+ }
+ return found;
+}
+
+//----------------------------------------------------------------------------
+void cmRST::ProcessDirectiveParsedLiteral()
+{
+ this->OutputMarkupLines(true);
+}
+
+//----------------------------------------------------------------------------
+void cmRST::ProcessDirectiveLiteralBlock()
+{
+ this->OutputMarkupLines(false);
+}
+
+//----------------------------------------------------------------------------
+void cmRST::ProcessDirectiveCodeBlock()
+{
+ this->OutputMarkupLines(false);
+}
+
+//----------------------------------------------------------------------------
+void cmRST::ProcessDirectiveReplace()
+{
+ // Record markup lines as replacement text.
+ std::string& replacement = this->Replace[this->ReplaceName];
+ const char* sep = "";
+ for(std::vector<std::string>::iterator i = this->MarkupLines.begin();
+ i != this->MarkupLines.end(); ++i)
+ {
+ replacement += sep;
+ replacement += *i;
+ sep = " ";
+ }
+ this->ReplaceName = "";
+}
+
+//----------------------------------------------------------------------------
+void cmRST::ProcessDirectiveTocTree()
+{
+ // Process documents referenced by toctree directive.
+ for(std::vector<std::string>::iterator i = this->MarkupLines.begin();
+ i != this->MarkupLines.end(); ++i)
+ {
+ if(!i->empty() && i->find_first_of(":") == i->npos)
+ {
+ this->ProcessInclude(*i + ".rst", IncludeTocTree);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmRST::UnindentLines(std::vector<std::string>& lines)
+{
+ // Remove the common indentation from the second and later lines.
+ std::string indentText;
+ std::string::size_type indentEnd = 0;
+ bool first = true;
+ for(size_t i = 1; i < lines.size(); ++i)
+ {
+ std::string const& line = lines[i];
+
+ // Do not consider empty lines.
+ if(line.empty())
+ {
+ continue;
+ }
+
+ // Record indentation on first non-empty line.
+ if(first)
+ {
+ first = false;
+ indentEnd = line.find_first_not_of(" \t");
+ indentText = line.substr(0, indentEnd);
+ continue;
+ }
+
+ // Truncate indentation to match that on this line.
+ if(line.size() < indentEnd)
+ {
+ indentEnd = line.size();
+ }
+ for(std::string::size_type j = 0; j != indentEnd; ++j)
+ {
+ if(line[j] != indentText[j])
+ {
+ indentEnd = j;
+ break;
+ }
+ }
+ }
+
+ // Update second and later lines.
+ for(size_t i = 1; i < lines.size(); ++i)
+ {
+ std::string& line = lines[i];
+ if(!line.empty())
+ {
+ line = line.substr(indentEnd);
+ }
+ }
+
+ // Drop leading blank lines.
+ size_t leadingEmpty = 0;
+ for(size_t i = 0; i < lines.size() && lines[i].empty(); ++i)
+ {
+ ++leadingEmpty;
+ }
+ lines.erase(lines.begin(), lines.begin()+leadingEmpty);
+
+ // Drop trailing blank lines.
+ size_t trailingEmpty = 0;
+ for(size_t i = lines.size(); i > 0 && lines[i-1].empty(); --i)
+ {
+ ++trailingEmpty;
+ }
+ lines.erase(lines.end()-trailingEmpty, lines.end());
+}
diff --git a/Source/cmRST.h b/Source/cmRST.h
new file mode 100644
index 0000000000..b9b2366421
--- /dev/null
+++ b/Source/cmRST.h
@@ -0,0 +1,100 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 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 _cmRST_h
+#define _cmRST_h
+
+#include "cmStandardIncludes.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+/** \class cmRST
+ * \brief Perform basic .rst processing for command-line help
+ *
+ * This class implements a subset of reStructuredText and Sphinx
+ * document processing. It is used to print command-line help.
+ *
+ * If you modify the capabilities of this class, be sure to update
+ * the Help/manual/cmake-developer.7.rst documentation and to update
+ * the Tests/CMakeLib/testRST.(rst|expect) test input and output.
+ */
+class cmRST
+{
+public:
+ cmRST(std::ostream& os, std::string const& docroot);
+ bool ProcessFile(std::string const& fname, bool isModule = false);
+private:
+ enum IncludeType
+ {
+ IncludeNormal,
+ IncludeModule,
+ IncludeTocTree
+ };
+ enum MarkupType
+ {
+ MarkupNone,
+ MarkupNormal,
+ MarkupEmpty
+ };
+ enum DirectiveType
+ {
+ DirectiveNone,
+ DirectiveParsedLiteral,
+ DirectiveLiteralBlock,
+ DirectiveCodeBlock,
+ DirectiveReplace,
+ DirectiveTocTree
+ };
+
+ void ProcessRST(std::istream& is);
+ void ProcessModule(std::istream& is);
+ void Reset();
+ void ProcessLine(std::string const& line);
+ void NormalLine(std::string const& line);
+ void OutputLine(std::string const& line, bool inlineMarkup);
+ std::string ReplaceSubstitutions(std::string const& line);
+ void OutputMarkupLines(bool inlineMarkup);
+ bool ProcessInclude(std::string file, IncludeType type);
+ void ProcessDirectiveParsedLiteral();
+ void ProcessDirectiveLiteralBlock();
+ void ProcessDirectiveCodeBlock();
+ void ProcessDirectiveReplace();
+ void ProcessDirectiveTocTree();
+ static void UnindentLines(std::vector<std::string>& lines);
+
+ std::ostream& OS;
+ std::string DocRoot;
+ int IncludeDepth;
+ bool OutputLinePending;
+ bool LastLineEndedInColonColon;
+ MarkupType Markup;
+ DirectiveType Directive;
+ cmsys::RegularExpression CMakeDirective;
+ cmsys::RegularExpression CMakeModuleDirective;
+ cmsys::RegularExpression ParsedLiteralDirective;
+ cmsys::RegularExpression CodeBlockDirective;
+ cmsys::RegularExpression ReplaceDirective;
+ cmsys::RegularExpression IncludeDirective;
+ cmsys::RegularExpression TocTreeDirective;
+ cmsys::RegularExpression ProductionListDirective;
+ cmsys::RegularExpression NoteDirective;
+ cmsys::RegularExpression ModuleRST;
+ cmsys::RegularExpression CMakeRole;
+ cmsys::RegularExpression Substitution;
+
+ std::vector<std::string> MarkupLines;
+ std::string DocDir;
+ std::map<std::string, std::string> Replace;
+ std::set<std::string> Replaced;
+ std::string ReplaceName;
+};
+
+#endif
diff --git a/Source/cmRemoveCommand.cxx b/Source/cmRemoveCommand.cxx
new file mode 100644
index 0000000000..bcb856438e
--- /dev/null
+++ b/Source/cmRemoveCommand.cxx
@@ -0,0 +1,76 @@
+/*============================================================================
+ 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 "cmRemoveCommand.h"
+
+// cmRemoveCommand
+bool cmRemoveCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ return true;
+ }
+
+ const char* variable = args[0].c_str(); // VAR is always first
+ // get the old value
+ const char* cacheValue
+ = this->Makefile->GetDefinition(variable);
+
+ // if there is no old value then return
+ if (!cacheValue)
+ {
+ return true;
+ }
+
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded);
+
+ // expand the args
+ // check for REMOVE(VAR v1 v2 ... vn)
+ std::vector<std::string> argsExpanded;
+ std::vector<std::string> temp;
+ for(unsigned int j = 1; j < args.size(); ++j)
+ {
+ temp.push_back(args[j]);
+ }
+ cmSystemTools::ExpandList(temp, argsExpanded);
+
+ // now create the new value
+ std::string value;
+ for(unsigned int j = 0; j < varArgsExpanded.size(); ++j)
+ {
+ int found = 0;
+ for(unsigned int k = 0; k < argsExpanded.size(); ++k)
+ {
+ if (varArgsExpanded[j] == argsExpanded[k])
+ {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ {
+ if (value.size())
+ {
+ value += ";";
+ }
+ value += varArgsExpanded[j];
+ }
+ }
+
+ // add the definition
+ this->Makefile->AddDefinition(variable, value.c_str());
+
+ return true;
+}
+
diff --git a/Source/cmRemoveCommand.h b/Source/cmRemoveCommand.h
new file mode 100644
index 0000000000..94161f8e31
--- /dev/null
+++ b/Source/cmRemoveCommand.h
@@ -0,0 +1,61 @@
+/*============================================================================
+ 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 cmRemoveCommand_h
+#define cmRemoveCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmRemoveCommand
+ * \brief remove command
+ *
+ * cmRemoveCommand implements the remove CMake command
+ */
+class cmRemoveCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmRemoveCommand;
+ }
+
+ /**
+ * 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 "remove";}
+
+ /** This command is kept for compatibility with older CMake versions. */
+ virtual bool IsDiscouraged() const
+ {
+ return true;
+ }
+
+ cmTypeMacro(cmRemoveCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmRemoveDefinitionsCommand.cxx b/Source/cmRemoveDefinitionsCommand.cxx
new file mode 100644
index 0000000000..b4be0f587e
--- /dev/null
+++ b/Source/cmRemoveDefinitionsCommand.cxx
@@ -0,0 +1,31 @@
+/*============================================================================
+ 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 "cmRemoveDefinitionsCommand.h"
+
+// cmRemoveDefinitionsCommand
+bool cmRemoveDefinitionsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ // it is OK to have no arguments
+ if(args.size() < 1 )
+ {
+ return true;
+ }
+
+ for(std::vector<std::string>::const_iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ this->Makefile->RemoveDefineFlag(i->c_str());
+ }
+ return true;
+}
+
diff --git a/Source/cmRemoveDefinitionsCommand.h b/Source/cmRemoveDefinitionsCommand.h
new file mode 100644
index 0000000000..cac94bef20
--- /dev/null
+++ b/Source/cmRemoveDefinitionsCommand.h
@@ -0,0 +1,52 @@
+/*============================================================================
+ 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 cmRemoveDefinitionsCommand_h
+#define cmRemoveDefinitionsCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmRemoveDefinitionsCommand
+ * \brief Specify a list of compiler defines
+ *
+ * cmRemoveDefinitionsCommand specifies a list of compiler defines.
+ * These defines will
+ * be removed from the compile command.
+ */
+class cmRemoveDefinitionsCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmRemoveDefinitionsCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "remove_definitions";}
+
+ cmTypeMacro(cmRemoveDefinitionsCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmReturnCommand.cxx b/Source/cmReturnCommand.cxx
new file mode 100644
index 0000000000..51cc83fcda
--- /dev/null
+++ b/Source/cmReturnCommand.cxx
@@ -0,0 +1,21 @@
+/*============================================================================
+ 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 "cmReturnCommand.h"
+
+// cmReturnCommand
+bool cmReturnCommand::InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &status)
+{
+ status.SetReturnInvoked(true);
+ return true;
+}
+
diff --git a/Source/cmReturnCommand.h b/Source/cmReturnCommand.h
new file mode 100644
index 0000000000..4ff81effa7
--- /dev/null
+++ b/Source/cmReturnCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmReturnCommand_h
+#define cmReturnCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmReturnCommand
+ * \brief Return from a directory or function
+ *
+ * cmReturnCommand returns from a directory or function
+ */
+class cmReturnCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmReturnCommand;
+ }
+
+ /**
+ * 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 "return";}
+
+ cmTypeMacro(cmReturnCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmScriptGenerator.cxx b/Source/cmScriptGenerator.cxx
new file mode 100644
index 0000000000..e44b2364a3
--- /dev/null
+++ b/Source/cmScriptGenerator.cxx
@@ -0,0 +1,238 @@
+/*============================================================================
+ 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 "cmScriptGenerator.h"
+
+#include "cmSystemTools.h"
+
+//----------------------------------------------------------------------------
+cmScriptGenerator
+::cmScriptGenerator(const std::string& config_var,
+ std::vector<std::string> const& configurations):
+ RuntimeConfigVariable(config_var),
+ Configurations(configurations),
+ ConfigurationName(""),
+ ConfigurationTypes(0),
+ ActionsPerConfig(false)
+{
+}
+
+//----------------------------------------------------------------------------
+cmScriptGenerator
+::~cmScriptGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+void
+cmScriptGenerator
+::Generate(std::ostream& os, const std::string& config,
+ std::vector<std::string> const& configurationTypes)
+{
+ this->ConfigurationName = config;
+ this->ConfigurationTypes = &configurationTypes;
+ this->GenerateScript(os);
+ this->ConfigurationName = "";
+ this->ConfigurationTypes = 0;
+}
+
+//----------------------------------------------------------------------------
+static void cmScriptGeneratorEncodeConfig(const std::string& config,
+ std::string& result)
+{
+ for(const char* c = config.c_str(); *c; ++c)
+ {
+ if(*c >= 'a' && *c <= 'z')
+ {
+ result += "[";
+ result += static_cast<char>(*c + 'A' - 'a');
+ result += *c;
+ result += "]";
+ }
+ else if(*c >= 'A' && *c <= 'Z')
+ {
+ result += "[";
+ result += *c;
+ result += static_cast<char>(*c + 'a' - 'A');
+ result += "]";
+ }
+ else
+ {
+ result += *c;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmScriptGenerator::CreateConfigTest(const std::string& config)
+{
+ std::string result = "\"${";
+ result += this->RuntimeConfigVariable;
+ result += "}\" MATCHES \"^(";
+ if(!config.empty())
+ {
+ cmScriptGeneratorEncodeConfig(config, result);
+ }
+ result += ")$\"";
+ return result;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmScriptGenerator::CreateConfigTest(std::vector<std::string> const& configs)
+{
+ std::string result = "\"${";
+ result += this->RuntimeConfigVariable;
+ result += "}\" MATCHES \"^(";
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator ci = configs.begin();
+ ci != configs.end(); ++ci)
+ {
+ result += sep;
+ sep = "|";
+ cmScriptGeneratorEncodeConfig(*ci, result);
+ }
+ result += ")$\"";
+ return result;
+}
+
+//----------------------------------------------------------------------------
+void cmScriptGenerator::GenerateScript(std::ostream& os)
+{
+ // Track indentation.
+ Indent indent;
+
+ // Generate the script possibly with per-configuration code.
+ this->GenerateScriptConfigs(os, indent);
+}
+
+//----------------------------------------------------------------------------
+void cmScriptGenerator::GenerateScriptConfigs(std::ostream& os,
+ Indent const& indent)
+{
+ if(this->ActionsPerConfig)
+ {
+ this->GenerateScriptActionsPerConfig(os, indent);
+ }
+ else
+ {
+ this->GenerateScriptActionsOnce(os, indent);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmScriptGenerator::GenerateScriptActions(std::ostream& os,
+ Indent const& indent)
+{
+ if(this->ActionsPerConfig)
+ {
+ // This is reached for single-configuration build generators in a
+ // per-config script generator.
+ this->GenerateScriptForConfig(os, this->ConfigurationName, indent);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmScriptGenerator::GenerateScriptForConfig(std::ostream&,
+ const std::string&,
+ Indent const&)
+{
+ // No actions for this generator.
+}
+
+//----------------------------------------------------------------------------
+bool cmScriptGenerator::GeneratesForConfig(const std::string& config)
+{
+ // If this is not a configuration-specific rule then we install.
+ if(this->Configurations.empty())
+ {
+ return true;
+ }
+
+ // This is a configuration-specific rule. Check if the config
+ // matches this rule.
+ std::string config_upper = cmSystemTools::UpperCase(config);
+ for(std::vector<std::string>::const_iterator i =
+ this->Configurations.begin();
+ i != this->Configurations.end(); ++i)
+ {
+ if(cmSystemTools::UpperCase(*i) == config_upper)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmScriptGenerator::GenerateScriptActionsOnce(std::ostream& os,
+ Indent const& indent)
+{
+ if(this->Configurations.empty())
+ {
+ // This rule is for all configurations.
+ this->GenerateScriptActions(os, indent);
+ }
+ else
+ {
+ // Generate a per-configuration block.
+ std::string config_test = this->CreateConfigTest(this->Configurations);
+ os << indent << "if(" << config_test << ")\n";
+ this->GenerateScriptActions(os, indent.Next());
+ os << indent << "endif(" << config_test << ")\n";
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmScriptGenerator::GenerateScriptActionsPerConfig(std::ostream& os,
+ Indent const& indent)
+{
+ if(this->ConfigurationTypes->empty())
+ {
+ // In a single-configuration generator there is only one action
+ // and it applies if the runtime-requested configuration is among
+ // the rule's allowed configurations. The configuration built in
+ // the tree does not matter for this decision but will be used to
+ // generate proper target file names into the code.
+ this->GenerateScriptActionsOnce(os, indent);
+ }
+ else
+ {
+ // In a multi-configuration generator we produce a separate rule
+ // in a block for each configuration that is built. We restrict
+ // the list of configurations to those to which this rule applies.
+ bool first = true;
+ for(std::vector<std::string>::const_iterator i =
+ this->ConfigurationTypes->begin();
+ i != this->ConfigurationTypes->end(); ++i)
+ {
+ const char* config = i->c_str();
+ if(this->GeneratesForConfig(config))
+ {
+ // Generate a per-configuration block.
+ std::string config_test = this->CreateConfigTest(config);
+ os << indent << (first? "if(" : "elseif(") << config_test << ")\n";
+ this->GenerateScriptForConfig(os, config, indent.Next());
+ first = false;
+ }
+ }
+ if(!first)
+ {
+ if(this->NeedsScriptNoConfig())
+ {
+ os << indent << "else()\n";
+ this->GenerateScriptNoConfig(os, indent.Next());
+ }
+ os << indent << "endif()\n";
+ }
+ }
+}
diff --git a/Source/cmScriptGenerator.h b/Source/cmScriptGenerator.h
new file mode 100644
index 0000000000..9ab04f17b0
--- /dev/null
+++ b/Source/cmScriptGenerator.h
@@ -0,0 +1,96 @@
+/*============================================================================
+ 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 cmScriptGenerator_h
+#define cmScriptGenerator_h
+
+#include "cmStandardIncludes.h"
+
+class cmScriptGeneratorIndent
+{
+public:
+ cmScriptGeneratorIndent(): Level(0) {}
+ cmScriptGeneratorIndent(int level): Level(level) {}
+ void Write(std::ostream& os) const
+ {
+ for(int i=0; i < this->Level; ++i)
+ {
+ os << " ";
+ }
+ }
+ cmScriptGeneratorIndent Next(int step = 2) const
+ {
+ return cmScriptGeneratorIndent(this->Level + step);
+ }
+private:
+ int Level;
+};
+inline std::ostream& operator<<(std::ostream& os,
+ cmScriptGeneratorIndent const& indent)
+{
+ indent.Write(os);
+ return os;
+}
+
+/** \class cmScriptGenerator
+ * \brief Support class for generating install and test scripts.
+ *
+ */
+class cmScriptGenerator
+{
+public:
+ cmScriptGenerator(const std::string& config_var,
+ std::vector<std::string> const& configurations);
+ virtual ~cmScriptGenerator();
+
+ void Generate(std::ostream& os, const std::string& config,
+ std::vector<std::string> const& configurationTypes);
+
+ const std::vector<std::string>& GetConfigurations() const
+ { return this->Configurations; }
+
+protected:
+ typedef cmScriptGeneratorIndent Indent;
+ virtual void GenerateScript(std::ostream& os);
+ virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
+ virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
+ virtual void GenerateScriptForConfig(std::ostream& os,
+ const std::string& config,
+ Indent const& indent);
+ virtual void GenerateScriptNoConfig(std::ostream&, Indent const&) {}
+ virtual bool NeedsScriptNoConfig() const { return false; }
+
+ // Test if this generator does something for a given configuration.
+ bool GeneratesForConfig(const std::string&);
+
+ std::string CreateConfigTest(const std::string& config);
+ std::string CreateConfigTest(std::vector<std::string> const& configs);
+ std::string CreateComponentTest(const char* component);
+
+ // Information shared by most generator types.
+ std::string RuntimeConfigVariable;
+ std::vector<std::string> const Configurations;
+
+ // Information used during generation.
+ std::string ConfigurationName;
+ std::vector<std::string> const* ConfigurationTypes;
+
+ // True if the subclass needs to generate an explicit rule for each
+ // configuration. False if the subclass only generates one rule for
+ // all enabled configurations.
+ bool ActionsPerConfig;
+
+private:
+ void GenerateScriptActionsOnce(std::ostream& os, Indent const& indent);
+ void GenerateScriptActionsPerConfig(std::ostream& os, Indent const& indent);
+};
+
+#endif
diff --git a/Source/cmSeparateArgumentsCommand.cxx b/Source/cmSeparateArgumentsCommand.cxx
new file mode 100644
index 0000000000..1ee3f29f54
--- /dev/null
+++ b/Source/cmSeparateArgumentsCommand.cxx
@@ -0,0 +1,109 @@
+/*============================================================================
+ 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 "cmSeparateArgumentsCommand.h"
+
+// cmSeparateArgumentsCommand
+bool cmSeparateArgumentsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.empty())
+ {
+ this->SetError("must be given at least one argument.");
+ return false;
+ }
+
+ std::string var;
+ std::string command;
+ enum Mode { ModeOld, ModeUnix, ModeWindows };
+ Mode mode = ModeOld;
+ enum Doing { DoingNone, DoingVariable, DoingMode, DoingCommand };
+ Doing doing = DoingVariable;
+ for(unsigned int i=0; i < args.size(); ++i)
+ {
+ if(doing == DoingVariable)
+ {
+ var = args[i];
+ doing = DoingMode;
+ }
+ else if(doing == DoingMode && args[i] == "UNIX_COMMAND")
+ {
+ mode = ModeUnix;
+ doing = DoingCommand;
+ }
+ else if(doing == DoingMode && args[i] == "WINDOWS_COMMAND")
+ {
+ mode = ModeWindows;
+ doing = DoingCommand;
+ }
+ else if(doing == DoingCommand)
+ {
+ command = args[i];
+ doing = DoingNone;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given unknown argument " << args[i];
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ if(mode == ModeOld)
+ {
+ // Original space-replacement version of command.
+ if(const char* def = this->Makefile->GetDefinition(var))
+ {
+ std::string value = def;
+ cmSystemTools::ReplaceString(value, " ", ";");
+ this->Makefile->AddDefinition(var, value.c_str());
+ }
+ }
+ else
+ {
+ // Parse the command line.
+ std::vector<std::string> vec;
+ if(mode == ModeUnix)
+ {
+ cmSystemTools::ParseUnixCommandLine(command.c_str(), vec);
+ }
+ else // if(mode == ModeWindows)
+ {
+ cmSystemTools::ParseWindowsCommandLine(command.c_str(), vec);
+ }
+
+ // Construct the result list value.
+ std::string value;
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator vi = vec.begin();
+ vi != vec.end(); ++vi)
+ {
+ // Separate from the previous argument.
+ value += sep;
+ sep = ";";
+
+ // Preserve semicolons.
+ for(std::string::const_iterator si = vi->begin();
+ si != vi->end(); ++si)
+ {
+ if(*si == ';')
+ {
+ value += '\\';
+ }
+ value += *si;
+ }
+ }
+ this->Makefile->AddDefinition(var, value.c_str());
+ }
+
+ return true;
+}
diff --git a/Source/cmSeparateArgumentsCommand.h b/Source/cmSeparateArgumentsCommand.h
new file mode 100644
index 0000000000..a527ae7b2b
--- /dev/null
+++ b/Source/cmSeparateArgumentsCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmSeparateArgumentsCommand_h
+#define cmSeparateArgumentsCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmSeparateArgumentsCommand
+ * \brief separate_arguments command
+ *
+ * cmSeparateArgumentsCommand implements the separate_arguments CMake command
+ */
+class cmSeparateArgumentsCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmSeparateArgumentsCommand;
+ }
+
+ /**
+ * 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 "separate_arguments";}
+
+ cmTypeMacro(cmSeparateArgumentsCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx
new file mode 100644
index 0000000000..0ca36eb0bb
--- /dev/null
+++ b/Source/cmSetCommand.cxx
@@ -0,0 +1,178 @@
+/*============================================================================
+ 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 "cmSetCommand.h"
+
+// cmSetCommand
+bool cmSetCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // watch for ENV signatures
+ const char* variable = args[0].c_str(); // VAR is always first
+ if (cmHasLiteralPrefix(variable, "ENV{") && strlen(variable) > 5)
+ {
+ // what is the variable name
+ char *varName = new char [strlen(variable)];
+ strncpy(varName,variable+4,strlen(variable)-5);
+ varName[strlen(variable)-5] = '\0';
+ std::string putEnvArg = varName;
+ putEnvArg += "=";
+
+ // what is the current value if any
+ const char *currValue = getenv(varName);
+ delete [] varName;
+
+ // will it be set to something, then set it
+ if (args.size() > 1 && args[1].size())
+ {
+ // but only if it is different from current value
+ if (!currValue || strcmp(currValue,args[1].c_str()))
+ {
+ putEnvArg += args[1];
+ cmSystemTools::PutEnv(putEnvArg.c_str());
+ }
+ return true;
+ }
+
+ // if it will be cleared, then clear it if it isn;t already clear
+ if (currValue)
+ {
+ cmSystemTools::PutEnv(putEnvArg.c_str());
+ }
+ return true;
+ }
+
+ // SET (VAR) // Removes the definition of VAR.
+ if (args.size() == 1)
+ {
+ this->Makefile->RemoveDefinition(args[0]);
+ return true;
+ }
+ // SET (VAR PARENT_SCOPE) // Removes the definition of VAR
+ // in the parent scope.
+ else if (args.size() == 2 && args[args.size()-1] == "PARENT_SCOPE")
+ {
+ this->Makefile->RaiseScope(variable, 0);
+ return true;
+ }
+
+ // here are the remaining options
+ // SET (VAR value )
+ // SET (VAR value PARENT_SCOPE)
+ // SET (VAR CACHE TYPE "doc String" [FORCE])
+ // SET (VAR value CACHE TYPE "doc string" [FORCE])
+ std::string value; // optional
+ bool cache = false; // optional
+ bool force = false; // optional
+ bool parentScope = false;
+ cmCacheManager::CacheEntryType type
+ = cmCacheManager::STRING; // required if cache
+ const char* docstring = 0; // required if cache
+
+ unsigned int ignoreLastArgs = 0;
+ // look for PARENT_SCOPE argument
+ if (args.size() > 1 && args[args.size()-1] == "PARENT_SCOPE")
+ {
+ parentScope = true;
+ ignoreLastArgs++;
+ }
+ else
+ {
+ // look for FORCE argument
+ if (args.size() > 4 && args[args.size()-1] == "FORCE")
+ {
+ force = true;
+ ignoreLastArgs++;
+ }
+
+ // check for cache signature
+ if (args.size() > 3 && args[args.size() - 3 - (force ? 1 : 0)] == "CACHE")
+ {
+ cache = true;
+ ignoreLastArgs+=3;
+ }
+ }
+
+ // collect any values into a single semi-colon separated value list
+ if(static_cast<unsigned short>(args.size()) >
+ static_cast<unsigned short>(1 + ignoreLastArgs))
+ {
+ value = args[1];
+ size_t endPos = args.size() - ignoreLastArgs;
+ for(size_t i = 2; i < endPos; ++i)
+ {
+ value += ";";
+ value += args[i];
+ }
+ }
+
+ if (parentScope)
+ {
+ this->Makefile->RaiseScope(variable, value.c_str());
+ return true;
+ }
+
+
+ // we should be nice and try to catch some simple screwups if the last or
+ // next to last args are CACHE then they screwed up. If they used FORCE
+ // without CACHE they screwed up
+ if ((args[args.size() - 1] == "CACHE") ||
+ (args.size() > 1 && args[args.size() - 2] == "CACHE") ||
+ (force && !cache))
+ {
+ this->SetError("given invalid arguments for CACHE mode.");
+ return false;
+ }
+
+ if(cache)
+ {
+ std::string::size_type cacheStart = args.size() - 3 - (force ? 1 : 0);
+ type = cmCacheManager::StringToType(args[cacheStart+1].c_str());
+ docstring = args[cacheStart+2].c_str();
+ }
+
+ // see if this is already in the cache
+ cmCacheManager::CacheIterator it =
+ this->Makefile->GetCacheManager()->GetCacheIterator(variable);
+ if(!it.IsAtEnd() && (it.GetType() != cmCacheManager::UNINITIALIZED))
+ {
+ // if the set is trying to CACHE the value but the value
+ // is already in the cache and the type is not internal
+ // then leave now without setting any definitions in the cache
+ // or the makefile
+ if(cache && type != cmCacheManager::INTERNAL && !force)
+ {
+ return true;
+ }
+ }
+
+ // if it is meant to be in the cache then define it in the cache
+ if(cache)
+ {
+ this->Makefile->AddCacheDefinition(variable,
+ value.c_str(),
+ docstring,
+ type, force);
+ }
+ else
+ {
+ // add the definition
+ this->Makefile->AddDefinition(variable, value.c_str());
+ }
+ return true;
+}
+
diff --git a/Source/cmSetCommand.h b/Source/cmSetCommand.h
new file mode 100644
index 0000000000..4adc2d9f0c
--- /dev/null
+++ b/Source/cmSetCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmSetCommand_h
+#define cmSetCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmSetCommand
+ * \brief Set a CMAKE variable
+ *
+ * cmSetCommand sets a variable to a value with expansion.
+ */
+class cmSetCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmSetCommand;
+ }
+
+ /**
+ * 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 "set";}
+
+ cmTypeMacro(cmSetCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmSetDirectoryPropertiesCommand.cxx b/Source/cmSetDirectoryPropertiesCommand.cxx
new file mode 100644
index 0000000000..3d4b7a9808
--- /dev/null
+++ b/Source/cmSetDirectoryPropertiesCommand.cxx
@@ -0,0 +1,70 @@
+/*============================================================================
+ 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 "cmSetDirectoryPropertiesCommand.h"
+
+#include "cmake.h"
+
+// cmSetDirectoryPropertiesCommand
+bool cmSetDirectoryPropertiesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::string errors;
+ bool ret =
+ cmSetDirectoryPropertiesCommand::RunCommand(this->Makefile,
+ args.begin() + 1,
+ args.end(), errors);
+ if (!ret)
+ {
+ this->SetError(errors);
+ }
+ return ret;
+}
+
+bool cmSetDirectoryPropertiesCommand
+::RunCommand(cmMakefile *mf,
+ std::vector<std::string>::const_iterator ait,
+ std::vector<std::string>::const_iterator aitend,
+ std::string &errors)
+{
+ for (; ait != aitend; ait += 2 )
+ {
+ if ( ait +1 == aitend)
+ {
+ errors = "Wrong number of arguments";
+ return false;
+ }
+ const std::string& prop = *ait;
+ const std::string& value = *(ait+1);
+ if ( prop == "VARIABLES" )
+ {
+ errors =
+ "Variables and cache variables should be set using SET command";
+ return false;
+ }
+ else if ( prop == "MACROS" )
+ {
+ errors =
+ "Commands and macros cannot be set using SET_CMAKE_PROPERTIES";
+ return false;
+ }
+ mf->SetProperty(prop, value.c_str());
+ }
+
+ return true;
+}
+
diff --git a/Source/cmSetDirectoryPropertiesCommand.h b/Source/cmSetDirectoryPropertiesCommand.h
new file mode 100644
index 0000000000..f444a1bb2c
--- /dev/null
+++ b/Source/cmSetDirectoryPropertiesCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmSetDirectoryPropertiesCommand_h
+#define cmSetDirectoryPropertiesCommand_h
+
+#include "cmCommand.h"
+
+class cmSetDirectoryPropertiesCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmSetDirectoryPropertiesCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input 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 "set_directory_properties";}
+
+ /**
+ * Static entry point for use by other commands
+ */
+ static bool RunCommand(cmMakefile *mf,
+ std::vector<std::string>::const_iterator ait,
+ std::vector<std::string>::const_iterator aitend,
+ std::string &errors);
+
+ cmTypeMacro(cmSetDirectoryPropertiesCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx
new file mode 100644
index 0000000000..c624d170ad
--- /dev/null
+++ b/Source/cmSetPropertyCommand.cxx
@@ -0,0 +1,547 @@
+/*============================================================================
+ 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 "cmSetPropertyCommand.h"
+#include "cmSetTargetPropertiesCommand.h"
+#include "cmSetTestsPropertiesCommand.h"
+#include "cmSetSourceFilesPropertiesCommand.h"
+
+#include "cmCacheManager.h"
+
+//----------------------------------------------------------------------------
+cmSetPropertyCommand::cmSetPropertyCommand()
+{
+ this->AppendMode = false;
+ this->AppendAsString = false;
+ this->Remove = true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // Get the scope on which to set the property.
+ std::vector<std::string>::const_iterator arg = args.begin();
+ cmProperty::ScopeType scope;
+ if(*arg == "GLOBAL")
+ {
+ scope = cmProperty::GLOBAL;
+ }
+ else if(*arg == "DIRECTORY")
+ {
+ scope = cmProperty::DIRECTORY;
+ }
+ else if(*arg == "TARGET")
+ {
+ scope = cmProperty::TARGET;
+ }
+ else if(*arg == "SOURCE")
+ {
+ scope = cmProperty::SOURCE_FILE;
+ }
+ else if(*arg == "TEST")
+ {
+ scope = cmProperty::TEST;
+ }
+ else if(*arg == "CACHE")
+ {
+ scope = cmProperty::CACHE;
+ }
+ else if(*arg == "INSTALL")
+ {
+ scope = cmProperty::INSTALL;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given invalid scope " << *arg << ". "
+ << "Valid scopes are GLOBAL, DIRECTORY, "
+ "TARGET, SOURCE, TEST, CACHE, INSTALL.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Parse the rest of the arguments up to the values.
+ enum Doing { DoingNone, DoingNames, DoingProperty, DoingValues };
+ Doing doing = DoingNames;
+ const char* sep = "";
+ for(++arg; arg != args.end(); ++arg)
+ {
+ if(*arg == "PROPERTY")
+ {
+ doing = DoingProperty;
+ }
+ else if(*arg == "APPEND")
+ {
+ doing = DoingNone;
+ this->AppendMode = true;
+ this->Remove = false;
+ this->AppendAsString = false;
+ }
+ else if(*arg == "APPEND_STRING")
+ {
+ doing = DoingNone;
+ this->AppendMode = true;
+ this->Remove = false;
+ this->AppendAsString = true;
+ }
+ else if(doing == DoingNames)
+ {
+ this->Names.insert(*arg);
+ }
+ else if(doing == DoingProperty)
+ {
+ this->PropertyName = *arg;
+ doing = DoingValues;
+ }
+ else if(doing == DoingValues)
+ {
+ this->PropertyValue += sep;
+ sep = ";";
+ this->PropertyValue += *arg;
+ this->Remove = false;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given invalid argument \"" << *arg << "\".";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+
+ // Make sure a property name was found.
+ if(this->PropertyName.empty())
+ {
+ this->SetError("not given a PROPERTY <name> argument.");
+ return false;
+ }
+
+ // Dispatch property setting.
+ switch(scope)
+ {
+ case cmProperty::GLOBAL: return this->HandleGlobalMode();
+ case cmProperty::DIRECTORY: return this->HandleDirectoryMode();
+ case cmProperty::TARGET: return this->HandleTargetMode();
+ case cmProperty::SOURCE_FILE: return this->HandleSourceMode();
+ case cmProperty::TEST: return this->HandleTestMode();
+ case cmProperty::CACHE: return this->HandleCacheMode();
+ case cmProperty::INSTALL: return this->HandleInstallMode();
+
+ case cmProperty::VARIABLE:
+ case cmProperty::CACHED_VARIABLE:
+ break; // should never happen
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleGlobalMode()
+{
+ if(!this->Names.empty())
+ {
+ this->SetError("given names for GLOBAL scope.");
+ return false;
+ }
+
+ // Set or append the property.
+ cmake* cm = this->Makefile->GetCMakeInstance();
+ const char* name = this->PropertyName.c_str();
+ const char *value = this->PropertyValue.c_str();
+ if (this->Remove)
+ {
+ value = 0;
+ }
+ if(this->AppendMode)
+ {
+ cm->AppendProperty(name, value ? value : "", this->AppendAsString);
+ }
+ else
+ {
+ cm->SetProperty(name, value);
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleDirectoryMode()
+{
+ if(this->Names.size() > 1)
+ {
+ this->SetError("allows at most one name for DIRECTORY scope.");
+ return false;
+ }
+
+ // Default to the current directory.
+ cmMakefile* mf = this->Makefile;
+
+ // Lookup the directory if given.
+ if(!this->Names.empty())
+ {
+ // Construct the directory name. Interpret relative paths with
+ // respect to the current directory.
+ std::string dir = *this->Names.begin();
+ if(!cmSystemTools::FileIsFullPath(dir.c_str()))
+ {
+ dir = this->Makefile->GetCurrentDirectory();
+ dir += "/";
+ dir += *this->Names.begin();
+ }
+
+ // The local generators are associated with collapsed paths.
+ dir = cmSystemTools::CollapseFullPath(dir.c_str());
+
+ // Lookup the generator.
+ if(cmLocalGenerator* lg =
+ (this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->FindLocalGenerator(dir)))
+ {
+ // Use the makefile for the directory found.
+ mf = lg->GetMakefile();
+ }
+ else
+ {
+ // Could not find the directory.
+ this->SetError
+ ("DIRECTORY scope provided but requested directory was not found. "
+ "This could be because the directory argument was invalid or, "
+ "it is valid but has not been processed yet.");
+ return false;
+ }
+ }
+
+ // Set or append the property.
+ const char* name = this->PropertyName.c_str();
+ const char *value = this->PropertyValue.c_str();
+ if (this->Remove)
+ {
+ value = 0;
+ }
+ if(this->AppendMode)
+ {
+ mf->AppendProperty(name, value ? value : "", this->AppendAsString);
+ }
+ else
+ {
+ mf->SetProperty(name, value);
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleTargetMode()
+{
+ for(std::set<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni)
+ {
+ if (this->Makefile->IsAlias(*ni))
+ {
+ this->SetError("can not be used on an ALIAS target.");
+ return false;
+ }
+ if(cmTarget* target = this->Makefile->FindTargetToUse(*ni))
+ {
+ // Handle the current target.
+ if(!this->HandleTarget(target))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "could not find TARGET " << *ni
+ << ". Perhaps it has not yet been created.";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleTarget(cmTarget* target)
+{
+ // Set or append the property.
+ const char* name = this->PropertyName.c_str();
+ const char *value = this->PropertyValue.c_str();
+ if (this->Remove)
+ {
+ value = 0;
+ }
+ if(this->AppendMode)
+ {
+ target->AppendProperty(name, value, this->AppendAsString);
+ }
+ else
+ {
+ target->SetProperty(name, value);
+ }
+
+ // Check the resulting value.
+ target->CheckProperty(name, this->Makefile);
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleSourceMode()
+{
+ for(std::set<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni)
+ {
+ // Get the source file.
+ if(cmSourceFile* sf = this->Makefile->GetOrCreateSource(*ni))
+ {
+ if(!this->HandleSource(sf))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given SOURCE name that could not be found or created: " << *ni;
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleSource(cmSourceFile* sf)
+{
+ // Set or append the property.
+ const char* name = this->PropertyName.c_str();
+ const char *value = this->PropertyValue.c_str();
+ if (this->Remove)
+ {
+ value = 0;
+ }
+
+ if(this->AppendMode)
+ {
+ sf->AppendProperty(name, value, this->AppendAsString);
+ }
+ else
+ {
+ sf->SetProperty(name, value);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleTestMode()
+{
+ // Look for tests with all names given.
+ std::set<std::string>::iterator next;
+ for(std::set<std::string>::iterator ni = this->Names.begin();
+ ni != this->Names.end(); ni = next)
+ {
+ next = ni;
+ ++next;
+ if(cmTest* test = this->Makefile->GetTest(*ni))
+ {
+ if(this->HandleTest(test))
+ {
+ this->Names.erase(ni);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ // Names that are still left were not found.
+ if(!this->Names.empty())
+ {
+ cmOStringStream e;
+ e << "given TEST names that do not exist:\n";
+ for(std::set<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni)
+ {
+ e << " " << *ni << "\n";
+ }
+ this->SetError(e.str());
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleTest(cmTest* test)
+{
+ // Set or append the property.
+ const char* name = this->PropertyName.c_str();
+ const char *value = this->PropertyValue.c_str();
+ if (this->Remove)
+ {
+ value = 0;
+ }
+ if(this->AppendMode)
+ {
+ test->AppendProperty(name, value, this->AppendAsString);
+ }
+ else
+ {
+ test->SetProperty(name, value);
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleCacheMode()
+{
+ if(this->PropertyName == "ADVANCED")
+ {
+ if(!this->Remove &&
+ !cmSystemTools::IsOn(this->PropertyValue.c_str()) &&
+ !cmSystemTools::IsOff(this->PropertyValue.c_str()))
+ {
+ cmOStringStream e;
+ e << "given non-boolean value \"" << this->PropertyValue
+ << "\" for CACHE property \"ADVANCED\". ";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else if(this->PropertyName == "TYPE")
+ {
+ if(!cmCacheManager::IsType(this->PropertyValue.c_str()))
+ {
+ cmOStringStream e;
+ e << "given invalid CACHE entry TYPE \"" << this->PropertyValue << "\"";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ else if(this->PropertyName != "HELPSTRING" &&
+ this->PropertyName != "STRINGS" &&
+ this->PropertyName != "VALUE")
+ {
+ cmOStringStream e;
+ e << "given invalid CACHE property " << this->PropertyName << ". "
+ << "Settable CACHE properties are: "
+ << "ADVANCED, HELPSTRING, STRINGS, TYPE, and VALUE.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ for(std::set<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni)
+ {
+ // Get the source file.
+ cmMakefile* mf = this->GetMakefile();
+ cmake* cm = mf->GetCMakeInstance();
+ cmCacheManager::CacheIterator it =
+ cm->GetCacheManager()->GetCacheIterator(ni->c_str());
+ if(!it.IsAtEnd())
+ {
+ if(!this->HandleCacheEntry(it))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "could not find CACHE variable " << *ni
+ << ". Perhaps it has not yet been created.";
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleCacheEntry(cmCacheManager::CacheIterator& it)
+{
+ // Set or append the property.
+ const char* name = this->PropertyName.c_str();
+ const char* value = this->PropertyValue.c_str();
+ if (this->Remove)
+ {
+ value = 0;
+ }
+ if(this->AppendMode)
+ {
+ it.AppendProperty(name, value, this->AppendAsString);
+ }
+ else
+ {
+ it.SetProperty(name, value);
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleInstallMode()
+{
+ cmake* cm = this->Makefile->GetCMakeInstance();
+
+ for(std::set<std::string>::const_iterator i = this->Names.begin();
+ i != this->Names.end(); ++i)
+ {
+ if(cmInstalledFile* file = cm->GetOrCreateInstalledFile(
+ this->Makefile, *i))
+ {
+ if(!this->HandleInstall(file))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "given INSTALL name that could not be found or created: " << *i;
+ this->SetError(e.str());
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSetPropertyCommand::HandleInstall(cmInstalledFile* file)
+{
+ // Set or append the property.
+ std::string const& name = this->PropertyName;
+
+ cmMakefile* mf = this->Makefile;
+
+ const char *value = this->PropertyValue.c_str();
+ if (this->Remove)
+ {
+ file->RemoveProperty(name);
+ }
+ else if(this->AppendMode)
+ {
+ file->AppendProperty(mf, name, value, this->AppendAsString);
+ }
+ else
+ {
+ file->SetProperty(mf, name, value);
+ }
+ return true;
+}
diff --git a/Source/cmSetPropertyCommand.h b/Source/cmSetPropertyCommand.h
new file mode 100644
index 0000000000..b06cb6857e
--- /dev/null
+++ b/Source/cmSetPropertyCommand.h
@@ -0,0 +1,71 @@
+/*============================================================================
+ 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 cmSetsPropertiesCommand_h
+#define cmSetsPropertiesCommand_h
+
+#include "cmCommand.h"
+
+class cmSetPropertyCommand : public cmCommand
+{
+public:
+ cmSetPropertyCommand();
+
+ virtual cmCommand* Clone()
+ {
+ return new cmSetPropertyCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "set_property";}
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ cmTypeMacro(cmSetPropertyCommand, cmCommand);
+
+private:
+ std::set<std::string> Names;
+ std::string PropertyName;
+ std::string PropertyValue;
+ bool Remove;
+ bool AppendMode;
+ bool AppendAsString;
+
+ // Implementation of each property type.
+ bool HandleGlobalMode();
+ bool HandleDirectoryMode();
+ bool HandleTargetMode();
+ bool HandleTarget(cmTarget* target);
+ bool HandleSourceMode();
+ bool HandleSource(cmSourceFile* sf);
+ bool HandleTestMode();
+ bool HandleTest(cmTest* test);
+ bool HandleCacheMode();
+ bool HandleCacheEntry(cmCacheManager::CacheIterator&);
+ bool HandleInstallMode();
+ bool HandleInstall(cmInstalledFile* file);
+};
+
+
+
+#endif
diff --git a/Source/cmSetSourceFilesPropertiesCommand.cxx b/Source/cmSetSourceFilesPropertiesCommand.cxx
new file mode 100644
index 0000000000..19c681944c
--- /dev/null
+++ b/Source/cmSetSourceFilesPropertiesCommand.cxx
@@ -0,0 +1,170 @@
+/*============================================================================
+ 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 "cmSetSourceFilesPropertiesCommand.h"
+
+#include "cmSourceFile.h"
+
+// cmSetSourceFilesPropertiesCommand
+bool cmSetSourceFilesPropertiesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // break the arguments into source file names and properties
+ int numFiles = 0;
+ std::vector<std::string>::const_iterator j;
+ j = args.begin();
+ // old style allows for specifier before PROPERTIES keyword
+ while (j != args.end() &&
+ *j != "ABSTRACT" &&
+ *j != "WRAP_EXCLUDE" &&
+ *j != "GENERATED" &&
+ *j != "COMPILE_FLAGS" &&
+ *j != "OBJECT_DEPENDS" &&
+ *j != "PROPERTIES")
+ {
+ numFiles++;
+ ++j;
+ }
+
+ // now call the worker function
+ std::string errors;
+ bool ret =
+ cmSetSourceFilesPropertiesCommand
+ ::RunCommand(this->Makefile,
+ args.begin(),
+ args.begin() + numFiles,
+ args.begin() + numFiles,
+ args.end(), errors);
+ if (!ret)
+ {
+ this->SetError(errors);
+ }
+ return ret;
+}
+
+bool cmSetSourceFilesPropertiesCommand
+::RunCommand(cmMakefile *mf,
+ std::vector<std::string>::const_iterator filebeg,
+ std::vector<std::string>::const_iterator fileend,
+ std::vector<std::string>::const_iterator propbeg,
+ std::vector<std::string>::const_iterator propend,
+ std::string &errors)
+{
+ std::vector<std::string> propertyPairs;
+ bool generated = false;
+ std::vector<std::string>::const_iterator j;
+ // build the property pairs
+ for(j= propbeg; j != propend;++j)
+ {
+ // old style allows for specifier before PROPERTIES keyword
+ if(*j == "ABSTRACT")
+ {
+ propertyPairs.push_back("ABSTRACT");
+ propertyPairs.push_back("1");
+ }
+ else if(*j == "WRAP_EXCLUDE")
+ {
+ propertyPairs.push_back("WRAP_EXCLUDE");
+ propertyPairs.push_back("1");
+ }
+ else if(*j == "GENERATED")
+ {
+ generated = true;
+ propertyPairs.push_back("GENERATED");
+ propertyPairs.push_back("1");
+ }
+ else if(*j == "COMPILE_FLAGS")
+ {
+ propertyPairs.push_back("COMPILE_FLAGS");
+ ++j;
+ if(j == propend)
+ {
+ errors = "called with incorrect number of arguments "
+ "COMPILE_FLAGS with no flags";
+ return false;
+ }
+ propertyPairs.push_back(*j);
+ }
+ else if(*j == "OBJECT_DEPENDS")
+ {
+ propertyPairs.push_back("OBJECT_DEPENDS");
+ ++j;
+ if(j == propend)
+ {
+ errors = "called with incorrect number of arguments "
+ "OBJECT_DEPENDS with no dependencies";
+ return false;
+ }
+ propertyPairs.push_back(*j);
+ }
+ else if(*j == "PROPERTIES")
+ {
+ // now loop through the rest of the arguments, new style
+ ++j;
+ while (j != propend)
+ {
+ propertyPairs.push_back(*j);
+ if(*j == "GENERATED")
+ {
+ ++j;
+ if(j != propend && cmSystemTools::IsOn(j->c_str()))
+ {
+ generated = true;
+ }
+ }
+ else
+ {
+ ++j;
+ }
+ if(j == propend)
+ {
+ errors = "called with incorrect number of arguments.";
+ return false;
+ }
+ propertyPairs.push_back(*j);
+ ++j;
+ }
+ // break out of the loop because j is already == end
+ break;
+ }
+ else
+ {
+ errors = "called with illegal arguments, maybe missing a "
+ "PROPERTIES specifier?";
+ return false;
+ }
+ }
+
+ // now loop over all the files
+ for(j= filebeg; j != fileend;++j)
+ {
+ // get the source file
+ cmSourceFile* sf =
+ mf->GetOrCreateSource(*j, generated);
+ if(sf)
+ {
+ // now loop through all the props and set them
+ unsigned int k;
+ for (k = 0; k < propertyPairs.size(); k = k + 2)
+ {
+ sf->SetProperty(propertyPairs[k],propertyPairs[k+1].c_str());
+ }
+ }
+ }
+ return true;
+}
+
diff --git a/Source/cmSetSourceFilesPropertiesCommand.h b/Source/cmSetSourceFilesPropertiesCommand.h
new file mode 100644
index 0000000000..5fa5a3ac73
--- /dev/null
+++ b/Source/cmSetSourceFilesPropertiesCommand.h
@@ -0,0 +1,49 @@
+/*============================================================================
+ 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 cmSetSourceFilesPropertiesCommand_h
+#define cmSetSourceFilesPropertiesCommand_h
+
+#include "cmCommand.h"
+
+class cmSetSourceFilesPropertiesCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmSetSourceFilesPropertiesCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "set_source_files_properties";}
+
+ cmTypeMacro(cmSetSourceFilesPropertiesCommand, cmCommand);
+
+ static bool RunCommand(cmMakefile *mf,
+ std::vector<std::string>::const_iterator filebeg,
+ std::vector<std::string>::const_iterator fileend,
+ std::vector<std::string>::const_iterator propbeg,
+ std::vector<std::string>::const_iterator propend,
+ std::string &errors);
+};
+
+
+
+#endif
diff --git a/Source/cmSetTargetPropertiesCommand.cxx b/Source/cmSetTargetPropertiesCommand.cxx
new file mode 100644
index 0000000000..bf3519c720
--- /dev/null
+++ b/Source/cmSetTargetPropertiesCommand.cxx
@@ -0,0 +1,115 @@
+/*============================================================================
+ 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 "cmSetTargetPropertiesCommand.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+
+// cmSetTargetPropertiesCommand
+bool cmSetTargetPropertiesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // first collect up the list of files
+ std::vector<std::string> propertyPairs;
+ bool doingFiles = true;
+ int numFiles = 0;
+ std::vector<std::string>::const_iterator j;
+ for(j= args.begin(); j != args.end();++j)
+ {
+ if(*j == "PROPERTIES")
+ {
+ doingFiles = false;
+ // now loop through the rest of the arguments, new style
+ ++j;
+ while (j != args.end())
+ {
+ propertyPairs.push_back(*j);
+ ++j;
+ if(j == args.end())
+ {
+ this->SetError("called with incorrect number of arguments.");
+ return false;
+ }
+ propertyPairs.push_back(*j);
+ ++j;
+ }
+ // break out of the loop because j is already == end
+ break;
+ }
+ else if (doingFiles)
+ {
+ numFiles++;
+ }
+ else
+ {
+ this->SetError("called with illegal arguments, maybe missing "
+ "a PROPERTIES specifier?");
+ return false;
+ }
+ }
+ if(propertyPairs.size() == 0)
+ {
+ this->SetError("called with illegal arguments, maybe missing "
+ "a PROPERTIES specifier?");
+ return false;
+ }
+
+ // now loop over all the targets
+ int i;
+ for(i = 0; i < numFiles; ++i)
+ {
+ if (this->Makefile->IsAlias(args[i]))
+ {
+ this->SetError("can not be used on an ALIAS target.");
+ return false;
+ }
+ bool ret = cmSetTargetPropertiesCommand::SetOneTarget
+ (args[i],propertyPairs,this->Makefile);
+ if (!ret)
+ {
+ std::string message = "Can not find target to add properties to: ";
+ message += args[i];
+ this->SetError(message);
+ return false;
+ }
+ }
+ return true;
+}
+
+bool cmSetTargetPropertiesCommand
+::SetOneTarget(const std::string& tname,
+ std::vector<std::string> &propertyPairs,
+ cmMakefile *mf)
+{
+ if(cmTarget* target = mf->FindTargetToUse(tname))
+ {
+ // now loop through all the props and set them
+ unsigned int k;
+ for (k = 0; k < propertyPairs.size(); k = k + 2)
+ {
+ target->SetProperty(propertyPairs[k],
+ propertyPairs[k+1].c_str());
+ target->CheckProperty(propertyPairs[k], mf);
+ }
+ }
+ // if file is not already in the makefile, then add it
+ else
+ {
+ return false;
+ }
+ return true;
+}
diff --git a/Source/cmSetTargetPropertiesCommand.h b/Source/cmSetTargetPropertiesCommand.h
new file mode 100644
index 0000000000..3981ef3d1e
--- /dev/null
+++ b/Source/cmSetTargetPropertiesCommand.h
@@ -0,0 +1,49 @@
+/*============================================================================
+ 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 cmSetTargetsPropertiesCommand_h
+#define cmSetTargetsPropertiesCommand_h
+
+#include "cmCommand.h"
+
+class cmSetTargetPropertiesCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmSetTargetPropertiesCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "set_target_properties";}
+
+ /**
+ * Used by this command and cmSetPropertiesCommand
+ */
+ static bool SetOneTarget(const std::string& tname,
+ std::vector<std::string> &propertyPairs,
+ cmMakefile *mf);
+
+ cmTypeMacro(cmSetTargetPropertiesCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmSetTestsPropertiesCommand.cxx b/Source/cmSetTestsPropertiesCommand.cxx
new file mode 100644
index 0000000000..b026ff3b1e
--- /dev/null
+++ b/Source/cmSetTestsPropertiesCommand.cxx
@@ -0,0 +1,117 @@
+/*============================================================================
+ 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 "cmSetTestsPropertiesCommand.h"
+
+#include "cmake.h"
+#include "cmTest.h"
+
+// cmSetTestsPropertiesCommand
+bool cmSetTestsPropertiesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // first collect up the list of files
+ std::vector<std::string> propertyPairs;
+ bool doingFiles = true;
+ int numFiles = 0;
+ std::vector<std::string>::const_iterator j;
+ for(j= args.begin(); j != args.end();++j)
+ {
+ if(*j == "PROPERTIES")
+ {
+ doingFiles = false;
+ // now loop through the rest of the arguments, new style
+ ++j;
+ while (j != args.end())
+ {
+ propertyPairs.push_back(*j);
+ ++j;
+ if(j == args.end())
+ {
+ this->SetError("called with incorrect number of arguments.");
+ return false;
+ }
+ propertyPairs.push_back(*j);
+ ++j;
+ }
+ // break out of the loop because j is already == end
+ break;
+ }
+ else if (doingFiles)
+ {
+ numFiles++;
+ }
+ else
+ {
+ this->SetError("called with illegal arguments, maybe "
+ "missing a PROPERTIES specifier?");
+ return false;
+ }
+ }
+ if(propertyPairs.size() == 0)
+ {
+ this->SetError("called with illegal arguments, maybe "
+ "missing a PROPERTIES specifier?");
+ return false;
+ }
+
+
+ // now loop over all the targets
+ int i;
+ for(i = 0; i < numFiles; ++i)
+ {
+ std::string errors;
+ bool ret =
+ cmSetTestsPropertiesCommand::SetOneTest(args[i],
+ propertyPairs,
+ this->Makefile, errors);
+ if (!ret)
+ {
+ this->SetError(errors);
+ return ret;
+ }
+ }
+
+ return true;
+}
+
+
+bool cmSetTestsPropertiesCommand
+::SetOneTest(const std::string& tname,
+ std::vector<std::string> &propertyPairs,
+ cmMakefile *mf, std::string &errors)
+{
+ if(cmTest* test = mf->GetTest(tname))
+ {
+ // now loop through all the props and set them
+ unsigned int k;
+ for (k = 0; k < propertyPairs.size(); k = k + 2)
+ {
+ test->SetProperty(propertyPairs[k],
+ propertyPairs[k+1].c_str());
+ }
+ }
+ else
+ {
+ errors = "Can not find test to add properties to: ";
+ errors += tname;
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/Source/cmSetTestsPropertiesCommand.h b/Source/cmSetTestsPropertiesCommand.h
new file mode 100644
index 0000000000..dabe9448d9
--- /dev/null
+++ b/Source/cmSetTestsPropertiesCommand.h
@@ -0,0 +1,47 @@
+/*============================================================================
+ 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 cmSetTestsPropertiesCommand_h
+#define cmSetTestsPropertiesCommand_h
+
+#include "cmCommand.h"
+
+class cmSetTestsPropertiesCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone()
+ {
+ return new cmSetTestsPropertiesCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the input file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "set_tests_properties";}
+
+ cmTypeMacro(cmSetTestsPropertiesCommand, cmCommand);
+
+ static bool SetOneTest(const std::string& tname,
+ std::vector<std::string> &propertyPairs,
+ cmMakefile *mf,
+ std::string &errors);
+};
+
+
+
+#endif
diff --git a/Source/cmSiteNameCommand.cxx b/Source/cmSiteNameCommand.cxx
new file mode 100644
index 0000000000..e61caabce2
--- /dev/null
+++ b/Source/cmSiteNameCommand.cxx
@@ -0,0 +1,95 @@
+/*============================================================================
+ 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 "cmSiteNameCommand.h"
+
+#include <cmsys/RegularExpression.hxx>
+
+// cmSiteNameCommand
+bool cmSiteNameCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() != 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ std::vector<std::string> paths;
+ paths.push_back("/usr/bsd");
+ paths.push_back("/usr/sbin");
+ paths.push_back("/usr/bin");
+ paths.push_back("/bin");
+ paths.push_back("/sbin");
+ paths.push_back("/usr/local/bin");
+
+ const char* cacheValue
+ = this->Makefile->GetDefinition(args[0]);
+ if(cacheValue)
+ {
+ return true;
+ }
+
+ const char *temp = this->Makefile->GetDefinition("HOSTNAME");
+ std::string hostname_cmd;
+ if(temp)
+ {
+ hostname_cmd = temp;
+ }
+ else
+ {
+ hostname_cmd = cmSystemTools::FindProgram("hostname", paths);
+ }
+
+ std::string siteName = "unknown";
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ std::string host;
+ if(cmSystemTools::ReadRegistryValue
+ ("HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\"
+ "Control\\ComputerName\\ComputerName;ComputerName", host))
+ {
+ siteName = host;
+ }
+#else
+ // try to find the hostname for this computer
+ if (!cmSystemTools::IsOff(hostname_cmd.c_str()))
+ {
+ std::string host;
+ cmSystemTools::RunSingleCommand(hostname_cmd.c_str(),
+ &host, 0, 0, cmSystemTools::OUTPUT_NONE);
+
+ // got the hostname
+ if (host.length())
+ {
+ // remove any white space from the host name
+ std::string hostRegExp = "[ \t\n\r]*([^\t\n\r ]*)[ \t\n\r]*";
+ cmsys::RegularExpression hostReg (hostRegExp.c_str());
+ if (hostReg.find(host.c_str()))
+ {
+ // strip whitespace
+ host = hostReg.match(1);
+ }
+
+ if(host.length())
+ {
+ siteName = host;
+ }
+ }
+ }
+#endif
+ this->Makefile->
+ AddCacheDefinition(args[0],
+ siteName.c_str(),
+ "Name of the computer/site where compile is being run",
+ cmCacheManager::STRING);
+
+ return true;
+}
+
diff --git a/Source/cmSiteNameCommand.h b/Source/cmSiteNameCommand.h
new file mode 100644
index 0000000000..ec63ef8607
--- /dev/null
+++ b/Source/cmSiteNameCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmSiteNameCommand_h
+#define cmSiteNameCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmSiteNameCommand
+ * \brief site_name command
+ *
+ * cmSiteNameCommand implements the site_name CMake command
+ */
+class cmSiteNameCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmSiteNameCommand;
+ }
+
+ /**
+ * 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 "site_name";}
+
+ cmTypeMacro(cmSiteNameCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx
new file mode 100644
index 0000000000..b833d3fd4b
--- /dev/null
+++ b/Source/cmSourceFile.cxx
@@ -0,0 +1,401 @@
+/*============================================================================
+ 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 "cmSourceFile.h"
+
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include "cmake.h"
+
+//----------------------------------------------------------------------------
+cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name):
+ Location(mf, name)
+{
+ this->CustomCommand = 0;
+ this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
+ this->FindFullPathFailed = false;
+ this->IsUiFile = ("ui" ==
+ cmSystemTools::GetFilenameLastExtension(this->Location.GetName()));
+}
+
+//----------------------------------------------------------------------------
+cmSourceFile::~cmSourceFile()
+{
+ this->SetCustomCommand(0);
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSourceFile::GetExtension() const
+{
+ return this->Extension;
+}
+
+const std::string cmSourceFile::propLANGUAGE = "LANGUAGE";
+
+//----------------------------------------------------------------------------
+void cmSourceFile::SetObjectLibrary(std::string const& objlib)
+{
+ this->ObjectLibrary = objlib;
+}
+
+//----------------------------------------------------------------------------
+std::string cmSourceFile::GetObjectLibrary() const
+{
+ return this->ObjectLibrary;
+}
+
+//----------------------------------------------------------------------------
+std::string cmSourceFile::GetLanguage()
+{
+ // If the language was set explicitly by the user then use it.
+ if(const char* lang = this->GetProperty(propLANGUAGE))
+ {
+ return lang;
+ }
+
+ // Perform computation needed to get the language if necessary.
+ if(this->FullPath.empty() && this->Language.empty())
+ {
+ // If a known extension is given or a known full path is given
+ // then trust that the current extension is sufficient to
+ // determine the language. This will fail only if the user
+ // specifies a full path to the source but leaves off the
+ // extension, which is kind of weird.
+ if(this->Location.ExtensionIsAmbiguous() &&
+ this->Location.DirectoryIsAmbiguous())
+ {
+ // Finalize the file location to get the extension and set the
+ // language.
+ this->GetFullPath();
+ }
+ else
+ {
+ // Use the known extension to get the language if possible.
+ std::string ext =
+ cmSystemTools::GetFilenameLastExtension(this->Location.GetName());
+ this->CheckLanguage(ext);
+ }
+ }
+
+ // Now try to determine the language.
+ return static_cast<cmSourceFile const*>(this)->GetLanguage();
+}
+
+//----------------------------------------------------------------------------
+std::string cmSourceFile::GetLanguage() const
+{
+ // If the language was set explicitly by the user then use it.
+ if(const char* lang = this->GetProperty(propLANGUAGE))
+ {
+ return lang;
+ }
+
+ // If the language was determined from the source file extension use it.
+ if(!this->Language.empty())
+ {
+ return this->Language;
+ }
+
+ // The language is not known.
+ return "";
+}
+
+//----------------------------------------------------------------------------
+cmSourceFileLocation const& cmSourceFile::GetLocation() const
+{
+ return this->Location;
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSourceFile::GetFullPath(std::string* error)
+{
+ if(this->FullPath.empty())
+ {
+ if(this->FindFullPath(error))
+ {
+ this->CheckExtension();
+ }
+ }
+ return this->FullPath;
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSourceFile::GetFullPath() const
+{
+ return this->FullPath;
+}
+
+//----------------------------------------------------------------------------
+bool cmSourceFile::FindFullPath(std::string* error)
+{
+ // If thie method has already failed once do not try again.
+ if(this->FindFullPathFailed)
+ {
+ return false;
+ }
+
+ // If the file is generated compute the location without checking on
+ // disk.
+ if(this->GetPropertyAsBool("GENERATED"))
+ {
+ // The file is either already a full path or is relative to the
+ // build directory for the target.
+ this->Location.DirectoryUseBinary();
+ this->FullPath = this->Location.GetDirectory();
+ this->FullPath += "/";
+ this->FullPath += this->Location.GetName();
+ return true;
+ }
+
+ // The file is not generated. It must exist on disk.
+ cmMakefile const* mf = this->Location.GetMakefile();
+ const char* tryDirs[3] = {0, 0, 0};
+ if(this->Location.DirectoryIsAmbiguous())
+ {
+ tryDirs[0] = mf->GetCurrentDirectory();
+ tryDirs[1] = mf->GetCurrentOutputDirectory();
+ }
+ else
+ {
+ tryDirs[0] = "";
+ }
+ const std::vector<std::string>& srcExts = mf->GetSourceExtensions();
+ const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions();
+ for(const char* const* di = tryDirs; *di; ++di)
+ {
+ std::string tryPath = this->Location.GetDirectory();
+ if(!tryPath.empty())
+ {
+ tryPath += "/";
+ }
+ tryPath += this->Location.GetName();
+ tryPath = cmSystemTools::CollapseFullPath(tryPath.c_str(), *di);
+ if(this->TryFullPath(tryPath, ""))
+ {
+ return true;
+ }
+ for(std::vector<std::string>::const_iterator ei = srcExts.begin();
+ ei != srcExts.end(); ++ei)
+ {
+ if(this->TryFullPath(tryPath, *ei))
+ {
+ return true;
+ }
+ }
+ for(std::vector<std::string>::const_iterator ei = hdrExts.begin();
+ ei != hdrExts.end(); ++ei)
+ {
+ if(this->TryFullPath(tryPath, *ei))
+ {
+ return true;
+ }
+ }
+ }
+
+ cmOStringStream e;
+ std::string missing = this->Location.GetDirectory();
+ if(!missing.empty())
+ {
+ missing += "/";
+ }
+ missing += this->Location.GetName();
+ e << "Cannot find source file:\n " << missing << "\nTried extensions";
+ for(std::vector<std::string>::const_iterator ext = srcExts.begin();
+ ext != srcExts.end(); ++ext)
+ {
+ e << " ." << *ext;
+ }
+ for(std::vector<std::string>::const_iterator ext = hdrExts.begin();
+ ext != hdrExts.end(); ++ext)
+ {
+ e << " ." << *ext;
+ }
+ if(error)
+ {
+ *error = e.str();
+ }
+ else
+ {
+ this->Location.GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ this->FindFullPathFailed = true;
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmSourceFile::TryFullPath(const std::string& path,
+ const std::string& ext)
+{
+ std::string tryPath = path;
+ if(!ext.empty())
+ {
+ tryPath += ".";
+ tryPath += ext;
+ }
+ if(cmSystemTools::FileExists(tryPath.c_str()))
+ {
+ this->FullPath = tryPath;
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmSourceFile::CheckExtension()
+{
+ // Compute the extension.
+ std::string realExt =
+ cmSystemTools::GetFilenameLastExtension(this->FullPath);
+ if(!realExt.empty())
+ {
+ // Store the extension without the leading '.'.
+ this->Extension = realExt.substr(1);
+ }
+
+ // Look for object files.
+ if(this->Extension == "obj" ||
+ this->Extension == "o" ||
+ this->Extension == "lo")
+ {
+ this->SetProperty("EXTERNAL_OBJECT", "1");
+ }
+
+ // Try to identify the source file language from the extension.
+ if(this->Language.empty())
+ {
+ this->CheckLanguage(this->Extension);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmSourceFile::CheckLanguage(std::string const& ext)
+{
+ // Try to identify the source file language from the extension.
+ cmMakefile const* mf = this->Location.GetMakefile();
+ cmGlobalGenerator* gg = mf->GetLocalGenerator()->GetGlobalGenerator();
+ std::string l = gg->GetLanguageFromExtension(ext.c_str());
+ if(!l.empty())
+ {
+ this->Language = l;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmSourceFile::Matches(cmSourceFileLocation const& loc)
+{
+ return this->Location.Matches(loc);
+}
+
+//----------------------------------------------------------------------------
+void cmSourceFile::SetProperty(const std::string& prop, const char* value)
+{
+ this->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE);
+
+ if (this->IsUiFile)
+ {
+ cmMakefile const* mf = this->Location.GetMakefile();
+ if (prop == "AUTOUIC_OPTIONS")
+ {
+ const_cast<cmMakefile*>(mf)->AddQtUiFileWithOptions(this);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmSourceFile::AppendProperty(const std::string& prop, const char* value,
+ bool asString)
+{
+ this->Properties.AppendProperty(prop, value, cmProperty::SOURCE_FILE,
+ asString);
+}
+
+//----------------------------------------------------------------------------
+const char* cmSourceFile::GetPropertyForUser(const std::string& prop)
+{
+ // This method is a consequence of design history and backwards
+ // compatibility. GetProperty is (and should be) a const method.
+ // Computed properties should not be stored back in the property map
+ // but instead reference information already known. If they need to
+ // cache information in a mutable ivar to provide the return string
+ // safely then so be it.
+ //
+ // The LOCATION property is particularly problematic. The CMake
+ // language has very loose restrictions on the names that will match
+ // a given source file (for historical reasons). Implementing
+ // lookups correctly with such loose naming requires the
+ // cmSourceFileLocation class to commit to a particular full path to
+ // the source file as late as possible. If the users requests the
+ // LOCATION property we must commit now.
+ if(prop == "LOCATION")
+ {
+ // Commit to a location.
+ this->GetFullPath();
+ }
+
+ // Perform the normal property lookup.
+ return this->GetProperty(prop);
+}
+
+//----------------------------------------------------------------------------
+const char* cmSourceFile::GetProperty(const std::string& prop) const
+{
+ // Check for computed properties.
+ if(prop == "LOCATION")
+ {
+ if(this->FullPath.empty())
+ {
+ return 0;
+ }
+ else
+ {
+ return this->FullPath.c_str();
+ }
+ }
+
+ bool chain = false;
+ const char *retVal =
+ this->Properties.GetPropertyValue(prop, cmProperty::SOURCE_FILE, chain);
+ if (chain)
+ {
+ cmMakefile const* mf = this->Location.GetMakefile();
+ return mf->GetProperty(prop,cmProperty::SOURCE_FILE);
+ }
+
+ return retVal;
+}
+
+//----------------------------------------------------------------------------
+bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const
+{
+ return cmSystemTools::IsOn(this->GetProperty(prop));
+}
+
+//----------------------------------------------------------------------------
+cmCustomCommand* cmSourceFile::GetCustomCommand()
+{
+ return this->CustomCommand;
+}
+
+//----------------------------------------------------------------------------
+cmCustomCommand const* cmSourceFile::GetCustomCommand() const
+{
+ return this->CustomCommand;
+}
+
+//----------------------------------------------------------------------------
+void cmSourceFile::SetCustomCommand(cmCustomCommand* cc)
+{
+ cmCustomCommand* old = this->CustomCommand;
+ this->CustomCommand = cc;
+ delete old;
+}
diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h
new file mode 100644
index 0000000000..f8982600fd
--- /dev/null
+++ b/Source/cmSourceFile.h
@@ -0,0 +1,127 @@
+/*============================================================================
+ 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 cmSourceFile_h
+#define cmSourceFile_h
+
+#include "cmSourceFileLocation.h"
+#include "cmCustomCommand.h"
+#include "cmPropertyMap.h"
+
+class cmake;
+
+/** \class cmSourceFile
+ * \brief Represent a class loaded from a makefile.
+ *
+ * cmSourceFile is represents a class loaded from
+ * a makefile.
+ */
+class cmSourceFile
+{
+public:
+ /**
+ * Construct with the makefile storing the source and the initial
+ * name referencing it.
+ */
+ cmSourceFile(cmMakefile* mf, const std::string& name);
+
+ ~cmSourceFile();
+
+ /**
+ * Get the list of the custom commands for this source file
+ */
+ cmCustomCommand* GetCustomCommand();
+ cmCustomCommand const* GetCustomCommand() const;
+ void SetCustomCommand(cmCustomCommand *cc);
+
+ ///! Set/Get a property of this source file
+ void SetProperty(const std::string& prop, const char *value);
+ void AppendProperty(const std::string& prop,
+ const char* value,bool asString=false);
+ const char *GetProperty(const std::string& prop) const;
+ bool GetPropertyAsBool(const std::string& prop) const;
+
+ /** Implement getting a property when called from a CMake language
+ command like get_property or get_source_file_property. */
+ const char* GetPropertyForUser(const std::string& prop);
+
+ /**
+ * The full path to the file. The non-const version of this method
+ * may attempt to locate the file on disk and finalize its location.
+ * The const version of this method may return an empty string if
+ * the non-const version has not yet been called (yes this is a
+ * horrible interface, but is necessary for backwards
+ * compatibility).
+ */
+ std::string const& GetFullPath(std::string* error = 0);
+ std::string const& GetFullPath() const;
+
+ /**
+ * Get the information currently known about the source file
+ * location without attempting to locate the file as GetFullPath
+ * would. See cmSourceFileLocation documentation.
+ */
+ cmSourceFileLocation const& GetLocation() const;
+
+ /**
+ * Get the file extension of this source file.
+ */
+ std::string const& GetExtension() const;
+
+ /**
+ * Get the language of the compiler to use for this source file.
+ */
+ std::string GetLanguage();
+ std::string GetLanguage() const;
+
+ /**
+ * Return the vector that holds the list of dependencies
+ */
+ const std::vector<std::string> &GetDepends() const {return this->Depends;}
+ void AddDepend(const std::string& d) { this->Depends.push_back(d); }
+
+ // Get the properties
+ cmPropertyMap &GetProperties() { return this->Properties; }
+
+ /**
+ * Check whether the given source file location could refer to this
+ * source.
+ */
+ bool Matches(cmSourceFileLocation const&);
+
+ void SetObjectLibrary(std::string const& objlib);
+ std::string GetObjectLibrary() const;
+
+private:
+ cmSourceFileLocation Location;
+ cmPropertyMap Properties;
+ cmCustomCommand* CustomCommand;
+ std::string Extension;
+ std::string Language;
+ std::string FullPath;
+ bool FindFullPathFailed;
+ std::string ObjectLibrary;
+ bool IsUiFile;
+
+ bool FindFullPath(std::string* error);
+ bool TryFullPath(const std::string& path, const std::string& ext);
+ void CheckExtension();
+ void CheckLanguage(std::string const& ext);
+
+ std::vector<std::string> Depends;
+
+ static const std::string propLANGUAGE;
+};
+
+// TODO: Factor out into platform information modules.
+#define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"
+
+#endif
diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx
new file mode 100644
index 0000000000..1c2454e697
--- /dev/null
+++ b/Source/cmSourceFileLocation.cxx
@@ -0,0 +1,312 @@
+/*============================================================================
+ 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 "cmSourceFileLocation.h"
+
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmSystemTools.h"
+
+#include "assert.h"
+
+//----------------------------------------------------------------------------
+cmSourceFileLocation::cmSourceFileLocation()
+ : Makefile(0), AmbiguousDirectory(true), AmbiguousExtension(true)
+{
+
+}
+
+//----------------------------------------------------------------------------
+cmSourceFileLocation::cmSourceFileLocation(const cmSourceFileLocation& loc)
+ : Makefile(loc.Makefile)
+{
+ this->AmbiguousDirectory = loc.AmbiguousDirectory;
+ this->AmbiguousExtension = loc.AmbiguousExtension;
+ this->Directory = loc.Directory;
+ this->Name = loc.Name;
+}
+
+//----------------------------------------------------------------------------
+cmSourceFileLocation&
+cmSourceFileLocation::operator=(const cmSourceFileLocation& loc)
+{
+ if(this == &loc)
+ {
+ return *this;
+ }
+ this->Makefile = loc.Makefile;
+ this->AmbiguousDirectory = loc.AmbiguousDirectory;
+ this->AmbiguousExtension = loc.AmbiguousExtension;
+ this->Directory = loc.Directory;
+ this->Name = loc.Name;
+ this->UpdateExtension(this->Name);
+ return *this;
+}
+
+//----------------------------------------------------------------------------
+cmSourceFileLocation
+::cmSourceFileLocation(cmMakefile const* mf, const std::string& name)
+ : Makefile(mf)
+{
+ this->AmbiguousDirectory = !cmSystemTools::FileIsFullPath(name.c_str());
+ this->AmbiguousExtension = true;
+ this->Directory = cmSystemTools::GetFilenamePath(name);
+ if (cmSystemTools::FileIsFullPath(this->Directory.c_str()))
+ {
+ this->Directory
+ = cmSystemTools::CollapseFullPath(this->Directory.c_str());
+ }
+ this->Name = cmSystemTools::GetFilenameName(name);
+ this->UpdateExtension(name);
+}
+
+//----------------------------------------------------------------------------
+void cmSourceFileLocation::Update(cmSourceFileLocation const& loc)
+{
+ if(this->AmbiguousDirectory && !loc.AmbiguousDirectory)
+ {
+ this->Directory = loc.Directory;
+ this->AmbiguousDirectory = false;
+ }
+ if(this->AmbiguousExtension && !loc.AmbiguousExtension)
+ {
+ this->Name = loc.Name;
+ this->AmbiguousExtension = false;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmSourceFileLocation::DirectoryUseSource()
+{
+ assert(this->Makefile);
+ if(this->AmbiguousDirectory)
+ {
+ this->Directory =
+ cmSystemTools::CollapseFullPath(
+ this->Directory.c_str(), this->Makefile->GetCurrentDirectory());
+ this->AmbiguousDirectory = false;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmSourceFileLocation::DirectoryUseBinary()
+{
+ assert(this->Makefile);
+ if(this->AmbiguousDirectory)
+ {
+ this->Directory =
+ cmSystemTools::CollapseFullPath(
+ this->Directory.c_str(), this->Makefile->GetCurrentOutputDirectory());
+ this->AmbiguousDirectory = false;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmSourceFileLocation::UpdateExtension(const std::string& name)
+{
+ assert(this->Makefile);
+ // Check the extension.
+ std::string ext = cmSystemTools::GetFilenameLastExtension(name);
+ if(!ext.empty()) { ext = ext.substr(1); }
+
+ // The global generator checks extensions of enabled languages.
+ cmGlobalGenerator* gg =
+ this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
+ cmMakefile const* mf = this->Makefile;
+ const std::vector<std::string>& srcExts = mf->GetSourceExtensions();
+ const std::vector<std::string>& hdrExts = mf->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())
+ {
+ // This is a known extension. Use the given filename with extension.
+ this->Name = cmSystemTools::GetFilenameName(name);
+ this->AmbiguousExtension = false;
+ }
+ else
+ {
+ // This is not a known extension. See if the file exists on disk as
+ // named.
+ std::string tryPath;
+ if(this->AmbiguousDirectory)
+ {
+ // Check the source tree only because a file in the build tree should
+ // be specified by full path at least once. We do not want this
+ // detection to depend on whether the project has already been built.
+ tryPath = this->Makefile->GetCurrentDirectory();
+ tryPath += "/";
+ }
+ if(!this->Directory.empty())
+ {
+ tryPath += this->Directory;
+ tryPath += "/";
+ }
+ tryPath += this->Name;
+ if(cmSystemTools::FileExists(tryPath.c_str(), true))
+ {
+ // We found a source file named by the user on disk. Trust it's
+ // extension.
+ this->Name = cmSystemTools::GetFilenameName(name);
+ this->AmbiguousExtension = false;
+
+ // If the directory was ambiguous, it isn't anymore.
+ if(this->AmbiguousDirectory)
+ {
+ this->DirectoryUseSource();
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool
+cmSourceFileLocation
+::MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const
+{
+ assert(this->Makefile);
+ // This location's extension is not ambiguous but loc's extension
+ // is. See if the names match as-is.
+ if(this->Name == loc.Name)
+ {
+ return true;
+ }
+
+ // Check if loc's name could possibly be extended to our name by
+ // adding an extension.
+ if(!(this->Name.size() > loc.Name.size() &&
+ this->Name[loc.Name.size()] == '.' &&
+ cmHasLiteralPrefixImpl(this->Name.c_str(),
+ loc.Name.c_str(), loc.Name.size())))
+ {
+ return false;
+ }
+
+ // Only a fixed set of extensions will be tried to match a file on
+ // 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();
+ if(std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end())
+ {
+ return true;
+ }
+ const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions();
+ if(std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end())
+ {
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
+{
+ assert(this->Makefile);
+ if(this->AmbiguousExtension == loc.AmbiguousExtension)
+ {
+ // Both extensions are similarly ambiguous. Since only the old fixed set
+ // of extensions will be tried, the names must match at this point to be
+ // the same file.
+ if(this->Name.size() != loc.Name.size() || this->Name != loc.Name)
+ {
+ return false;
+ }
+ }
+ else
+ {
+ const cmSourceFileLocation* loc1;
+ const cmSourceFileLocation* loc2;
+ if(this->AmbiguousExtension)
+ {
+ // Only "this" extension is ambiguous.
+ loc1 = &loc;
+ loc2 = this;
+ }
+ else
+ {
+ // Only "loc" extension is ambiguous.
+ loc1 = this;
+ loc2 = &loc;
+ }
+ if(!loc1->MatchesAmbiguousExtension(*loc2))
+ {
+ return false;
+ }
+ }
+
+ if(!this->AmbiguousDirectory && !loc.AmbiguousDirectory)
+ {
+ // Both sides have absolute directories.
+ if(this->Directory != loc.Directory)
+ {
+ return false;
+ }
+ }
+ else if(this->AmbiguousDirectory && loc.AmbiguousDirectory)
+ {
+ if (this->Makefile == loc.Makefile)
+ {
+ // Both sides have directories relative to the same location.
+ if(this->Directory != loc.Directory)
+ {
+ return false;
+ }
+ }
+ else
+ {
+ // Each side has a directory relative to a different location.
+ // This can occur when referencing a source file from a different
+ // directory. This is not yet allowed.
+ this->Makefile->IssueMessage(
+ cmake::INTERNAL_ERROR,
+ "Matches error: Each side has a directory relative to a different "
+ "location. This can occur when referencing a source file from a "
+ "different directory. This is not yet allowed."
+ );
+ return false;
+ }
+ }
+ else if(this->AmbiguousDirectory)
+ {
+ // Compare possible directory combinations.
+ std::string const& srcDir =
+ cmSystemTools::CollapseFullPath(
+ this->Directory.c_str(), this->Makefile->GetCurrentDirectory());
+ std::string const& binDir =
+ cmSystemTools::CollapseFullPath(
+ this->Directory.c_str(), this->Makefile->GetCurrentOutputDirectory());
+ if(srcDir != loc.Directory &&
+ binDir != loc.Directory)
+ {
+ return false;
+ }
+ }
+ else if(loc.AmbiguousDirectory)
+ {
+ // Compare possible directory combinations.
+ std::string const& srcDir =
+ cmSystemTools::CollapseFullPath(
+ loc.Directory.c_str(), loc.Makefile->GetCurrentDirectory());
+ std::string const& binDir =
+ cmSystemTools::CollapseFullPath(
+ loc.Directory.c_str(), loc.Makefile->GetCurrentOutputDirectory());
+ if(srcDir != this->Directory &&
+ binDir != this->Directory)
+ {
+ return false;
+ }
+ }
+
+ // File locations match.
+ this->Update(loc);
+ return true;
+}
diff --git a/Source/cmSourceFileLocation.h b/Source/cmSourceFileLocation.h
new file mode 100644
index 0000000000..af3651a29e
--- /dev/null
+++ b/Source/cmSourceFileLocation.h
@@ -0,0 +1,102 @@
+/*============================================================================
+ 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 cmSourceFileLocation_h
+#define cmSourceFileLocation_h
+
+#include "cmStandardIncludes.h"
+
+class cmMakefile;
+
+/** \class cmSourceFileLocation
+ * \brief cmSourceFileLocation tracks knowledge about a source file location
+ *
+ * Source files can be referenced by a variety of names. The
+ * directory and/or extension may be omitted leading to a certain
+ * level of ambiguity about the source file location. This class is
+ * used by cmSourceFile to keep track of what is known about the
+ * source file location. Each reference may add some information
+ * about the directory or extension of the file.
+ */
+class cmSourceFileLocation
+{
+public:
+ /**
+ * Construct for a source file created in a given cmMakefile
+ * instance with an initial name.
+ */
+ cmSourceFileLocation(cmMakefile const* mf, const std::string& name);
+ cmSourceFileLocation();
+ cmSourceFileLocation(const cmSourceFileLocation& loc);
+ cmSourceFileLocation& operator=(const cmSourceFileLocation& loc);
+
+ /**
+ * Return whether the givne source file location could refers to the
+ * same source file as this location given the level of ambiguity in
+ * each location.
+ */
+ bool Matches(cmSourceFileLocation const& loc);
+
+ /**
+ * Explicity state that the source file is located in the source tree.
+ */
+ void DirectoryUseSource();
+
+ /**
+ * Explicity state that the source file is located in the build tree.
+ */
+ void DirectoryUseBinary();
+
+ /**
+ * Return whether the directory containing the source is ambiguous.
+ */
+ bool DirectoryIsAmbiguous() const { return this->AmbiguousDirectory; }
+
+ /**
+ * Return whether the extension of the source name is ambiguous.
+ */
+ bool ExtensionIsAmbiguous() const { return this->AmbiguousExtension; }
+
+ /**
+ * Get the directory containing the file as best is currently known.
+ * If DirectoryIsAmbiguous() returns false this will be a full path.
+ * Otherwise it will be a relative path (possibly empty) that is
+ * either with respect to the source or build tree.
+ */
+ const std::string& GetDirectory() const { return this->Directory; }
+
+ /**
+ * Get the file name as best is currently known. If
+ * ExtensionIsAmbiguous() returns true this name may not be the
+ * final name (but could be). Otherwise the returned name is the
+ * final name.
+ */
+ const std::string& GetName() const { return this->Name; }
+
+ /**
+ * Get the cmMakefile instance for which the source file was created.
+ */
+ cmMakefile const* GetMakefile() const { return this->Makefile; }
+private:
+ cmMakefile const* Makefile;
+ bool AmbiguousDirectory;
+ bool AmbiguousExtension;
+ std::string Directory;
+ std::string Name;
+
+ bool MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const;
+
+ // Update the location with additional knowledge.
+ void Update(cmSourceFileLocation const& loc);
+ void UpdateExtension(const std::string& name);
+};
+
+#endif
diff --git a/Source/cmSourceGroup.cxx b/Source/cmSourceGroup.cxx
new file mode 100644
index 0000000000..8fed95e11f
--- /dev/null
+++ b/Source/cmSourceGroup.cxx
@@ -0,0 +1,205 @@
+/*============================================================================
+ 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 "cmSourceGroup.h"
+
+class cmSourceGroupInternals
+{
+public:
+ std::vector<cmSourceGroup> GroupChildren;
+};
+
+//----------------------------------------------------------------------------
+cmSourceGroup::cmSourceGroup(const char* name, const char* regex,
+ const char* parentName): Name(name)
+{
+ this->Internal = new cmSourceGroupInternals;
+ this->SetGroupRegex(regex);
+ if(parentName)
+ {
+ this->FullName = parentName;
+ this->FullName += "\\";
+ }
+ this->FullName += this->Name;
+}
+
+//----------------------------------------------------------------------------
+cmSourceGroup::~cmSourceGroup()
+{
+ delete this->Internal;
+}
+
+//----------------------------------------------------------------------------
+cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
+{
+ this->Name = r.Name;
+ this->FullName = r.FullName;
+ this->GroupRegex = r.GroupRegex;
+ this->GroupFiles = r.GroupFiles;
+ this->SourceFiles = r.SourceFiles;
+ this->Internal = new cmSourceGroupInternals(*r.Internal);
+}
+
+//----------------------------------------------------------------------------
+cmSourceGroup& cmSourceGroup::operator=(cmSourceGroup const& r)
+{
+ this->Name = r.Name;
+ this->GroupRegex = r.GroupRegex;
+ this->GroupFiles = r.GroupFiles;
+ this->SourceFiles = r.SourceFiles;
+ *(this->Internal) = *(r.Internal);
+ return *this;
+}
+
+//----------------------------------------------------------------------------
+void cmSourceGroup::SetGroupRegex(const char* regex)
+{
+ if(regex)
+ {
+ this->GroupRegex.compile(regex);
+ }
+ else
+ {
+ this->GroupRegex.compile("^$");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmSourceGroup::AddGroupFile(const std::string& name)
+{
+ this->GroupFiles.insert(name);
+}
+
+//----------------------------------------------------------------------------
+const char* cmSourceGroup::GetName() const
+{
+ return this->Name.c_str();
+}
+
+//----------------------------------------------------------------------------
+const char* cmSourceGroup::GetFullName() const
+{
+ return this->FullName.c_str();
+}
+
+//----------------------------------------------------------------------------
+bool cmSourceGroup::MatchesRegex(const char* name)
+{
+ return this->GroupRegex.find(name);
+}
+
+//----------------------------------------------------------------------------
+bool cmSourceGroup::MatchesFiles(const char* name)
+{
+ std::set<std::string>::const_iterator i = this->GroupFiles.find(name);
+ if(i != this->GroupFiles.end())
+ {
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmSourceGroup::AssignSource(const cmSourceFile* sf)
+{
+ this->SourceFiles.push_back(sf);
+}
+
+//----------------------------------------------------------------------------
+const std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles() const
+{
+ return this->SourceFiles;
+}
+
+//----------------------------------------------------------------------------
+void cmSourceGroup::AddChild(cmSourceGroup child)
+{
+ this->Internal->GroupChildren.push_back(child);
+}
+
+//----------------------------------------------------------------------------
+cmSourceGroup *cmSourceGroup::LookupChild(const char* name) const
+{
+ // initializing iterators
+ std::vector<cmSourceGroup>::const_iterator iter =
+ this->Internal->GroupChildren.begin();
+ const std::vector<cmSourceGroup>::const_iterator end =
+ this->Internal->GroupChildren.end();
+
+ // st
+ for(;iter!=end; ++iter)
+ {
+ std::string sgName = iter->GetName();
+
+ // look if descenened is the one were looking for
+ if(sgName == name)
+ {
+ return const_cast<cmSourceGroup*>(&(*iter)); // if it so return it
+ }
+ }
+
+ // if no child with this name was found return NULL
+ return NULL;
+}
+
+cmSourceGroup *cmSourceGroup::MatchChildrenFiles(const char *name)
+{
+ // initializing iterators
+ std::vector<cmSourceGroup>::iterator iter =
+ this->Internal->GroupChildren.begin();
+ std::vector<cmSourceGroup>::iterator end =
+ this->Internal->GroupChildren.end();
+
+ if(this->MatchesFiles(name))
+ {
+ return this;
+ }
+ for(;iter!=end;++iter)
+ {
+ cmSourceGroup *result = iter->MatchChildrenFiles(name);
+ if(result)
+ {
+ return result;
+ }
+ }
+ return 0;
+}
+
+
+cmSourceGroup *cmSourceGroup::MatchChildrenRegex(const char *name)
+{
+ // initializing iterators
+ std::vector<cmSourceGroup>::iterator iter =
+ this->Internal->GroupChildren.begin();
+ std::vector<cmSourceGroup>::iterator end =
+ this->Internal->GroupChildren.end();
+
+ for(;iter!=end; ++iter)
+ {
+ cmSourceGroup *result = iter->MatchChildrenRegex(name);
+ if(result)
+ {
+ return result;
+ }
+ }
+ if(this->MatchesRegex(name))
+ {
+ return this;
+ }
+
+ return 0;
+}
+
+std::vector<cmSourceGroup> const&
+cmSourceGroup::GetGroupChildren() const
+{
+ return this->Internal->GroupChildren;
+}
diff --git a/Source/cmSourceGroup.h b/Source/cmSourceGroup.h
new file mode 100644
index 0000000000..e8cf519d4f
--- /dev/null
+++ b/Source/cmSourceGroup.h
@@ -0,0 +1,132 @@
+/*============================================================================
+ 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 cmSourceGroup_h
+#define cmSourceGroup_h
+
+#include "cmStandardIncludes.h"
+#include <cmsys/RegularExpression.hxx>
+
+class cmSourceFile;
+
+class cmSourceGroupInternals;
+
+/** \class cmSourceGroup
+ * \brief Hold a group of sources as specified by a SOURCE_GROUP command.
+ *
+ * cmSourceGroup holds a regular expression and a list of files. When
+ * local generators are about to generate the rules for a target's
+ * files, the set of source groups is consulted to group files
+ * together. A file is placed into the last source group that lists
+ * the file by name. If no group lists the file, it is placed into
+ * the last group whose regex matches it.
+ */
+class cmSourceGroup
+{
+public:
+ cmSourceGroup(const char* name, const char* regex,
+ const char* parentName=0);
+ cmSourceGroup(cmSourceGroup const& r);
+ ~cmSourceGroup();
+ cmSourceGroup& operator=(cmSourceGroup const&);
+
+ /**
+ * Set the regular expression for this group.
+ */
+ void SetGroupRegex(const char* regex);
+
+ /**
+ * Add a file name to the explicit list of files for this group.
+ */
+ void AddGroupFile(const std::string& name);
+
+ /**
+ * Add child to this sourcegroup
+ */
+ void AddChild(cmSourceGroup child);
+
+ /**
+ * Looks up child and returns it
+ */
+ cmSourceGroup *LookupChild(const char *name) const;
+
+ /**
+ * Get the name of this group.
+ */
+ const char* GetName() const;
+
+ /**
+ * Get the full path name for group.
+ */
+ const char* GetFullName() const;
+
+ /**
+ * Check if the given name matches this group's regex.
+ */
+ bool MatchesRegex(const char* name);
+
+ /**
+ * Check if the given name matches this group's explicit file list.
+ */
+ bool MatchesFiles(const char* name);
+
+ /**
+ * Check if the given name matches this group's explicit file list
+ * in children.
+ */
+ cmSourceGroup *MatchChildrenFiles(const char *name);
+
+ /**
+ * Check if the given name matches this group's regex in children.
+ */
+ cmSourceGroup *MatchChildrenRegex(const char *name);
+
+ /**
+ * Assign the given source file to this group. Used only by
+ * generators.
+ */
+ void AssignSource(const cmSourceFile* sf);
+
+ /**
+ * Get the list of the source files that have been assigned to this
+ * source group.
+ */
+ const std::vector<const cmSourceFile*>& GetSourceFiles() const;
+
+ std::vector<cmSourceGroup> const& GetGroupChildren() const;
+private:
+ /**
+ * The name of the source group.
+ */
+ std::string Name;
+ // Full path to group
+ std::string FullName;
+
+ /**
+ * The regular expression matching the files in the group.
+ */
+ cmsys::RegularExpression GroupRegex;
+
+ /**
+ * Set of file names explicitly added to this group.
+ */
+ std::set<std::string> GroupFiles;
+
+ /**
+ * Vector of all source files that have been assigned to
+ * this group.
+ */
+ std::vector<const cmSourceFile*> SourceFiles;
+
+ cmSourceGroupInternals* Internal;
+};
+
+#endif
diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx
new file mode 100644
index 0000000000..edba5baf86
--- /dev/null
+++ b/Source/cmSourceGroupCommand.cxx
@@ -0,0 +1,102 @@
+/*============================================================================
+ 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 "cmSourceGroupCommand.h"
+
+// cmSourceGroupCommand
+bool cmSourceGroupCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::string delimiter = "\\";
+ if(this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"))
+ {
+ delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
+ }
+
+ std::vector<std::string> folders =
+ cmSystemTools::tokenize(args[0], delimiter);
+
+ cmSourceGroup* sg = 0;
+ sg = this->Makefile->GetSourceGroup(folders);
+ if(!sg)
+ {
+ this->Makefile->AddSourceGroup(folders);
+ sg = this->Makefile->GetSourceGroup(folders);
+ }
+
+ if(!sg)
+ {
+ this->SetError("Could not create or find source group");
+ return false;
+ }
+ // If only two arguments are given, the pre-1.8 version of the
+ // command is being invoked.
+ if(args.size() == 2 && args[1] != "FILES")
+ {
+ sg->SetGroupRegex(args[1].c_str());
+ return true;
+ }
+
+ // Process arguments.
+ bool doingFiles = false;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "REGULAR_EXPRESSION")
+ {
+ // Next argument must specify the regex.
+ if(i+1 < args.size())
+ {
+ ++i;
+ sg->SetGroupRegex(args[i].c_str());
+ }
+ else
+ {
+ this->SetError("REGULAR_EXPRESSION argument given without a regex.");
+ return false;
+ }
+ doingFiles = false;
+ }
+ else if(args[i] == "FILES")
+ {
+ // Next arguments will specify files.
+ doingFiles = true;
+ }
+ else if(doingFiles)
+ {
+ // Convert name to full path and add to the group's list.
+ std::string src = args[i];
+ if(!cmSystemTools::FileIsFullPath(src.c_str()))
+ {
+ src = this->Makefile->GetCurrentDirectory();
+ src += "/";
+ src += args[i];
+ }
+ src = cmSystemTools::CollapseFullPath(src.c_str());
+ sg->AddGroupFile(src);
+ }
+ else
+ {
+ cmOStringStream err;
+ err << "Unknown argument \"" << args[i] << "\". "
+ << "Perhaps the FILES keyword is missing.\n";
+ this->SetError(err.str());
+ return false;
+ }
+ }
+
+ return true;
+}
diff --git a/Source/cmSourceGroupCommand.h b/Source/cmSourceGroupCommand.h
new file mode 100644
index 0000000000..410411be90
--- /dev/null
+++ b/Source/cmSourceGroupCommand.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ 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 cmSourceGroupCommand_h
+#define cmSourceGroupCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmSourceGroupCommand
+ * \brief Adds a cmSourceGroup to the cmMakefile.
+ *
+ * cmSourceGroupCommand is used to define cmSourceGroups which split up
+ * source files in to named, organized groups in the generated makefiles.
+ */
+class cmSourceGroupCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmSourceGroupCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const {return "source_group";}
+
+ cmTypeMacro(cmSourceGroupCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmStandardIncludes.cxx b/Source/cmStandardIncludes.cxx
new file mode 100644
index 0000000000..a4bdb2e32c
--- /dev/null
+++ b/Source/cmStandardIncludes.cxx
@@ -0,0 +1,16 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2010 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 "cmStandardIncludes.h"
+#if !defined(CMAKE_NO_ANSI_STRING_STREAM)
+cmOStringStream::cmOStringStream() {}
+cmOStringStream::~cmOStringStream() {}
+#endif
diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h
new file mode 100644
index 0000000000..8baf7b3039
--- /dev/null
+++ b/Source/cmStandardIncludes.h
@@ -0,0 +1,469 @@
+/*============================================================================
+ 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 header files as a function of the build process, compiler,
+ * and operating system.
+ */
+#ifndef cmStandardIncludes_h
+#define cmStandardIncludes_h
+
+// include configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
+// CMAKE_NO_STD_NAMESPACE, and other macros.
+#include <cmConfigure.h>
+#include <cmsys/Configure.hxx>
+
+#ifdef _MSC_VER
+#pragma warning ( disable : 4786 )
+#pragma warning ( disable : 4503 )
+#pragma warning ( disable : 4512 ) /* operator=() could not be generated */
+#define CMAKE_NO_ANSI_FOR_SCOPE
+#endif
+
+#ifdef __BORLANDC__
+# pragma warn -8030 /* Temporary used for parameter */
+# pragma warn -8027 /* 'for' not inlined. */
+# pragma warn -8026 /* 'exception' not inlined. */
+# pragma warn -8004 /* value never used */
+#endif
+
+#ifdef __ICL
+#pragma warning ( disable : 985 )
+#pragma warning ( disable : 1572 ) /* floating-point equality test */
+#endif
+
+// Provide fixed-size integer types.
+#include <cmIML/INT.h>
+
+#include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
+
+// This is a hack to prevent warnings about these functions being
+// declared but not referenced.
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 3970 /* conversion from pointer to same-sized */
+# include <sys/termios.h>
+class cmStandardIncludesHack
+{
+public:
+ enum
+ {
+ Ref1 = sizeof(cfgetospeed(0)),
+ Ref2 = sizeof(cfgetispeed(0)),
+ Ref3 = sizeof(tcgetattr(0, 0)),
+ Ref4 = sizeof(tcsetattr(0, 0, 0)),
+ Ref5 = sizeof(cfsetospeed(0,0)),
+ Ref6 = sizeof(cfsetispeed(0,0))
+ };
+};
+#endif
+
+// Include stream compatibility layer from KWSys.
+// This is needed to work with large file support
+// on some platforms whose stream operators do not
+// support the large integer types.
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include <cmsys/IOStream.hxx>
+# undef GetCurrentDirectory // Borland <iosfwd> includes windows.h
+#endif
+
+// Avoid warnings in system headers.
+#if defined(_MSC_VER)
+# pragma warning (push,1)
+#endif
+#if defined(__BORLANDC__)
+# pragma warn -8008 /* condition is always false (RESET BELOW!) */
+# pragma warn -8066 /* unreachable code (RESET BELOW!) */
+#endif
+
+#ifndef CMAKE_NO_ANSI_STREAM_HEADERS
+# include <fstream>
+# include <iostream>
+# include <iomanip>
+#else
+# include <fstream.h>
+# include <iostream.h>
+# include <iomanip.h>
+#endif
+
+#if !defined(CMAKE_NO_ANSI_STRING_STREAM)
+# include <sstream>
+#elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
+# include <strstream>
+#else
+# include <strstream.h>
+#endif
+
+// we must have stl with the standard include style
+#include <vector>
+#include <string>
+#include <iterator>
+#include <algorithm>
+#include <functional>
+#include <map>
+#include <list>
+#include <set>
+#include <deque>
+
+#if defined(__BORLANDC__)
+# pragma warn .8008 /* condition is always false (disabled above) */
+# pragma warn .8066 /* unreachable code (disabled above) */
+#endif
+#if defined(_MSC_VER)
+# pragma warning(pop)
+#endif
+
+// include the "c" string header
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+// Borland C++ defines several of the stdlib.h and string.h symbols in
+// sub-headers search.h and mem.h. These sub-headers have using
+// declarations to pull functions from the std namespace to the global
+// namespace, but they are defined only if the header was not included
+// through the C++-style cstdlib or cstring header. These outer
+// headers are included by the streams library in C++-style and
+// include blockers are put in place that prevent including the
+// C-style versions from ever including the sub-headers. Therefore we
+// have to include the sub-headers here to get the using declarations.
+#if defined(__BORLANDC__)
+# include <mem.h> /* mem... functions from string.h */
+# include <search.h> /* search functions from stdlib.h */
+#endif
+
+
+#if !defined(_WIN32) && defined(__COMO__)
+// Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
+extern "C"
+{
+extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
+extern int pclose (FILE *__stream) __THROW;
+extern char *realpath (__const char *__restrict __name,
+ char *__restrict __resolved) __THROW;
+extern char *strdup (__const char *__s) __THROW;
+extern int putenv (char *__string) __THROW;
+}
+#endif
+
+// if std:: is not supported, then just #define it away
+#ifdef CMAKE_NO_STD_NAMESPACE
+#define std
+#endif
+
+// if the compiler does not support ansi for scoping of vars use a
+// #define hack
+#ifdef CMAKE_NO_ANSI_FOR_SCOPE
+#define for if(false) {} else for
+#endif
+
+// Provide std::ios_base on ancient GCC 2.9x
+#if defined(__GNUC__) && __GNUC__ < 3
+namespace std { typedef ios ios_base; }
+#endif
+
+// check for the 720 compiler on the SGI
+// which has some strange properties that I don't think are worth
+// checking for in a general way in configure
+#if defined(__sgi) && !defined(__GNUC__)
+# if (_COMPILER_VERSION >= 730)
+# define CM_SGI_CC_730
+# elif (_COMPILER_VERSION >= 720)
+# define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
+# endif
+#endif
+
+#ifdef __DECCXX_VER
+# if __DECCXX_VER <= 60390008
+# define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
+# endif
+#endif
+
+#if defined( _MSC_VER )
+typedef unsigned short mode_t;
+#endif
+
+
+#ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
+// some compilers have std:: but not for the stream library,
+// so we have to bring it into the std namespace by hand.
+namespace std {
+using ::ostream;
+using ::istream;
+using ::ios;
+using ::cout;
+using ::cerr;
+using ::cin;
+using ::ifstream;
+using ::ofstream;
+
+#if !defined(CMAKE_NO_ANSI_STRING_STREAM)
+ using ::ostringstream;
+ using ::istringstream;
+#else
+ using ::ostrstream;
+ using ::istrstream;
+#endif
+
+using ::endl;
+using ::ends;
+using ::flush;
+using ::dec;
+using ::hex;
+using ::setw;
+using ::setiosflags;
+using ::setfill;
+using ::setprecision;
+}
+// The string class is missing these operators so add them
+#if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
+# define cmsys_STL_STRING_NO_NEQ_CHAR
+inline bool operator!=(std::string const& a, const char* b)
+{ return !(a==std::string(b)); }
+#endif
+
+inline bool operator==(std::string const& a, const char* b)
+{ return (a==std::string(b)); }
+# endif // end CM_SGI_CC_720
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 1375 /* base class destructor not virtual */
+#endif
+
+// use this class to shrink the size of symbols in .o files
+// std::string is really basic_string<....lots of stuff....>
+// when combined with a map or set, the symbols can be > 2000 chars!
+#include <cmsys/String.hxx>
+//typedef cmsys::String std::string;
+
+// Define cmOStringStream and cmIStringStream wrappers to hide
+// differences between std::stringstream and the old strstream.
+#if !defined(CMAKE_NO_ANSI_STRING_STREAM)
+class cmOStringStream: public std::ostringstream
+{
+public:
+ cmOStringStream();
+ ~cmOStringStream();
+private:
+ cmOStringStream(const cmOStringStream&);
+ void operator=(const cmOStringStream&);
+};
+class cmIStringStream: public std::istringstream
+{
+public:
+ typedef std::istringstream Superclass;
+ cmIStringStream() {}
+ cmIStringStream(const std::string& s): Superclass(s) {}
+private:
+ cmIStringStream(const cmIStringStream&);
+ void operator=(const cmIStringStream&);
+};
+#else
+class cmOStrStreamCleanup
+{
+public:
+ cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
+ ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
+ static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
+protected:
+ std::ostrstream& OStrStream;
+};
+
+class cmOStringStream: public std::ostrstream
+{
+public:
+ typedef std::ostrstream Superclass;
+ cmOStringStream() {}
+ std::string str()
+ {
+ cmOStrStreamCleanup cleanup(*this);
+ cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
+ int pcount = this->pcount();
+ const char* ptr = this->Superclass::str();
+ return std::string(ptr?ptr:"", pcount);
+ }
+private:
+ cmOStringStream(const cmOStringStream&);
+ void operator=(const cmOStringStream&);
+};
+
+class cmIStringStream: private std::string, public std::istrstream
+{
+public:
+ typedef std::string StdString;
+ typedef std::istrstream IStrStream;
+ cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
+ cmIStringStream(const std::string& s):
+ StdString(s), IStrStream(StdString::c_str()) {}
+ std::string str() const { return *this; }
+ void str(const std::string& s)
+ {
+ // Very dangerous. If this throws, the object is hosed. When the
+ // destructor is later called, the program is hosed too.
+ this->~cmIStringStream();
+ new (this) cmIStringStream(s);
+ }
+private:
+ cmIStringStream(const cmIStringStream&);
+ void operator=(const cmIStringStream&);
+};
+#endif
+
+/* Poison this operator to avoid common mistakes. */
+extern void operator << (std::ostream&, const cmOStringStream&);
+
+/** Standard documentation entry for cmDocumentation's formatting. */
+struct cmDocumentationEntry
+{
+ std::string Name;
+ std::string Brief;
+ cmDocumentationEntry(){}
+ cmDocumentationEntry(const char *doc[2])
+ { if (doc[0]) this->Name = doc[0];
+ if (doc[1]) this->Brief = doc[1];}
+ cmDocumentationEntry(const char *n, const char *b)
+ { if (n) this->Name = n; if (b) this->Brief = b; }
+};
+
+/** Data structure to represent a single command line. */
+class cmCustomCommandLine: public std::vector<std::string>
+{
+public:
+ typedef std::vector<std::string> Superclass;
+ typedef Superclass::iterator iterator;
+ typedef Superclass::const_iterator const_iterator;
+};
+
+/** Data structure to represent a list of command lines. */
+class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
+{
+public:
+ typedef std::vector<cmCustomCommandLine> Superclass;
+ typedef Superclass::iterator iterator;
+ typedef Superclass::const_iterator const_iterator;
+};
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma reset woff 1375 /* base class destructor not virtual */
+#endif
+
+// All subclasses of cmCommand or cmCTestGenericHandler should
+// invoke this macro.
+#define cmTypeMacro(thisClass,superclass) \
+virtual const char* GetNameOfClass() { return #thisClass; } \
+typedef superclass Superclass; \
+static bool IsTypeOf(const char *type) \
+{ \
+ if ( !strcmp(#thisClass,type) ) \
+ { \
+ return true; \
+ } \
+ return Superclass::IsTypeOf(type); \
+} \
+virtual bool IsA(const char *type) \
+{ \
+ return thisClass::IsTypeOf(type); \
+} \
+static thisClass* SafeDownCast(cmObject *c) \
+{ \
+ if ( c && c->IsA(#thisClass) ) \
+ { \
+ return static_cast<thisClass *>(c); \
+ } \
+ return 0;\
+} \
+class cmTypeMacro_UseTrailingSemicolon
+
+inline bool cmHasLiteralPrefixImpl(const std::string &str1,
+ const char *str2,
+ size_t N)
+{
+ return strncmp(str1.c_str(), str2, N) == 0;
+}
+
+inline bool cmHasLiteralPrefixImpl(const char* str1,
+ const char *str2,
+ size_t N)
+{
+ return strncmp(str1, str2, N) == 0;
+}
+
+inline bool cmHasLiteralSuffixImpl(const std::string &str1,
+ const char *str2,
+ size_t N)
+{
+ size_t len = str1.size();
+ return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
+}
+
+inline bool cmHasLiteralSuffixImpl(const char* str1,
+ const char* str2,
+ size_t N)
+{
+ size_t len = strlen(str1);
+ return len >= N && strcmp(str1 + len - N, str2) == 0;
+}
+
+#if defined(_MSC_VER) && _MSC_VER < 1300 \
+ || defined(__GNUC__) && __GNUC__ < 3 \
+ || defined(__BORLANDC__)
+
+#define cmArrayBegin(a) a
+#define cmArraySize(a) (sizeof(a)/sizeof(*a))
+#define cmArrayEnd(a) a + cmArraySize(a)
+
+#define cmHasLiteralPrefix(STR1, STR2) \
+ cmHasLiteralPrefixImpl(STR1, "" STR2 "", sizeof(STR2) - 1)
+
+#define cmHasLiteralSuffix(STR1, STR2) \
+ cmHasLiteralSuffixImpl(STR1, "" STR2 "", sizeof(STR2) - 1)
+
+#else
+
+template<typename T, size_t N>
+const T* cmArrayBegin(const T (&a)[N]) { return a; }
+template<typename T, size_t N>
+const T* cmArrayEnd(const T (&a)[N]) { return a + N; }
+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])
+{
+ return cmHasLiteralPrefixImpl(str1, str2, N - 1);
+}
+
+template<typename T, size_t N>
+bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
+{
+ return cmHasLiteralSuffixImpl(str1, str2, N - 1);
+}
+
+#endif
+
+struct cmStrCmp {
+ cmStrCmp(const char *test) : m_test(test) {}
+ cmStrCmp(const std::string &test) : m_test(test) {}
+
+ bool operator()(const std::string& input) const
+ {
+ return m_test == input;
+ }
+
+ bool operator()(const char * input) const
+ {
+ return strcmp(input, m_test.c_str()) == 0;
+ }
+
+private:
+ const std::string m_test;
+};
+
+#endif
diff --git a/Source/cmStandardLexer.h b/Source/cmStandardLexer.h
new file mode 100644
index 0000000000..acd636c431
--- /dev/null
+++ b/Source/cmStandardLexer.h
@@ -0,0 +1,73 @@
+/*============================================================================
+ 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 cmStandardLexer_h
+#define cmStandardLexer_h
+
+/* Disable some warnings. */
+#if defined(_MSC_VER)
+# pragma warning ( disable : 4127 )
+# pragma warning ( disable : 4131 )
+# pragma warning ( disable : 4244 )
+# pragma warning ( disable : 4251 )
+# pragma warning ( disable : 4267 )
+# pragma warning ( disable : 4305 )
+# pragma warning ( disable : 4309 )
+# pragma warning ( disable : 4706 )
+# pragma warning ( disable : 4786 )
+#endif
+
+#if defined(__BORLANDC__)
+# pragma warn -8008 /* condition always returns true */
+# pragma warn -8066 /* unreachable code */
+#endif
+
+/* Borland system header defines these macros without first undef-ing them. */
+#if defined(__BORLANDC__) && __BORLANDC__ >= 0x580
+# undef INT8_MIN
+# undef INT16_MIN
+# undef INT32_MIN
+# undef INT8_MAX
+# undef INT16_MAX
+# undef INT32_MAX
+# undef UINT8_MAX
+# undef UINT16_MAX
+# undef UINT32_MAX
+# include <stdint.h>
+#endif
+
+/* Make sure SGI termios does not define ECHO differently. */
+#if defined(__sgi) && !defined(__GNUC__)
+# include <sys/termios.h>
+# undef ECHO
+#endif
+
+/* Define isatty on windows. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# include <io.h>
+# if defined( _MSC_VER )
+# define isatty _isatty
+# endif
+# define YY_NO_UNISTD_H 1
+#endif
+
+/* Make sure malloc and free are available on QNX. */
+#ifdef __QNX__
+# include <malloc.h>
+#endif
+
+/* Disable features we do not need. */
+#define YY_NEVER_INTERACTIVE 1
+#define YY_NO_INPUT 1
+#define YY_NO_UNPUT 1
+#define ECHO
+
+#endif
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
new file mode 100644
index 0000000000..90a8f8546a
--- /dev/null
+++ b/Source/cmStringCommand.cxx
@@ -0,0 +1,1099 @@
+/*============================================================================
+ 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 "cmStringCommand.h"
+#include "cmCryptoHash.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/SystemTools.hxx>
+
+#include <stdlib.h> // required for atoi
+#include <ctype.h>
+#include <time.h>
+
+#include <cmTimestamp.h>
+#include <cmUuid.h>
+
+//----------------------------------------------------------------------------
+bool cmStringCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("must be called with at least one argument.");
+ return false;
+ }
+
+ const std::string &subCommand = args[0];
+ if(subCommand == "REGEX")
+ {
+ return this->HandleRegexCommand(args);
+ }
+ else if(subCommand == "REPLACE")
+ {
+ return this->HandleReplaceCommand(args);
+ }
+ else if ( subCommand == "MD5" ||
+ subCommand == "SHA1" ||
+ subCommand == "SHA224" ||
+ subCommand == "SHA256" ||
+ subCommand == "SHA384" ||
+ subCommand == "SHA512" )
+ {
+ return this->HandleHashCommand(args);
+ }
+ else if(subCommand == "TOLOWER")
+ {
+ return this->HandleToUpperLowerCommand(args, false);
+ }
+ else if(subCommand == "TOUPPER")
+ {
+ return this->HandleToUpperLowerCommand(args, true);
+ }
+ else if(subCommand == "COMPARE")
+ {
+ return this->HandleCompareCommand(args);
+ }
+ else if(subCommand == "ASCII")
+ {
+ return this->HandleAsciiCommand(args);
+ }
+ else if(subCommand == "CONFIGURE")
+ {
+ return this->HandleConfigureCommand(args);
+ }
+ else if(subCommand == "LENGTH")
+ {
+ return this->HandleLengthCommand(args);
+ }
+ else if(subCommand == "CONCAT")
+ {
+ return this->HandleConcatCommand(args);
+ }
+ else if(subCommand == "SUBSTRING")
+ {
+ return this->HandleSubstringCommand(args);
+ }
+ else if(subCommand == "STRIP")
+ {
+ return this->HandleStripCommand(args);
+ }
+ else if(subCommand == "RANDOM")
+ {
+ return this->HandleRandomCommand(args);
+ }
+ else if(subCommand == "FIND")
+ {
+ return this->HandleFindCommand(args);
+ }
+ else if(subCommand == "TIMESTAMP")
+ {
+ return this->HandleTimestampCommand(args);
+ }
+ else if(subCommand == "MAKE_C_IDENTIFIER")
+ {
+ return this->HandleMakeCIdentifierCommand(args);
+ }
+ else if(subCommand == "GENEX_STRIP")
+ {
+ return this->HandleGenexStripCommand(args);
+ }
+ else if(subCommand == "UUID")
+ {
+ return this->HandleUuidCommand(args);
+ }
+
+ std::string e = "does not recognize sub-command "+subCommand;
+ this->SetError(e);
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleHashCommand(std::vector<std::string> const& args)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ if(args.size() != 3)
+ {
+ cmOStringStream e;
+ e << args[0] << " requires an output variable and an input string";
+ this->SetError(e.str());
+ return false;
+ }
+
+ cmsys::auto_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str()));
+ if(hash.get())
+ {
+ std::string out = hash->HashString(args[2]);
+ this->Makefile->AddDefinition(args[1], out.c_str());
+ return true;
+ }
+ return false;
+#else
+ cmOStringStream e;
+ e << args[0] << " not available during bootstrap";
+ this->SetError(e.str().c_str());
+ return false;
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleToUpperLowerCommand(
+ std::vector<std::string> const& args, bool toUpper)
+{
+ if ( args.size() < 3 )
+ {
+ this->SetError("no output variable specified");
+ return false;
+ }
+
+ std::string outvar = args[2];
+ std::string output;
+
+ if (toUpper)
+ {
+ output = cmSystemTools::UpperCase(args[1]);
+ }
+ else
+ {
+ output = cmSystemTools::LowerCase(args[1]);
+ }
+
+ // Store the output in the provided variable.
+ this->Makefile->AddDefinition(outvar, output.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleAsciiCommand(std::vector<std::string> const& args)
+{
+ if ( args.size() < 3 )
+ {
+ this->SetError("No output variable specified");
+ return false;
+ }
+ std::string::size_type cc;
+ std::string outvar = args[args.size()-1];
+ std::string output = "";
+ for ( cc = 1; cc < args.size()-1; cc ++ )
+ {
+ int ch = atoi(args[cc].c_str());
+ if ( ch > 0 && ch < 256 )
+ {
+ output += static_cast<char>(ch);
+ }
+ else
+ {
+ std::string error = "Character with code ";
+ error += args[cc];
+ error += " does not exist.";
+ this->SetError(error);
+ return false;
+ }
+ }
+ // Store the output in the provided variable.
+ this->Makefile->AddDefinition(outvar, output.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleConfigureCommand(
+ std::vector<std::string> const& args)
+{
+ if ( args.size() < 2 )
+ {
+ this->SetError("No input string specified.");
+ return false;
+ }
+ else if ( args.size() < 3 )
+ {
+ this->SetError("No output variable specified.");
+ return false;
+ }
+
+ // Parse options.
+ bool escapeQuotes = false;
+ bool atOnly = false;
+ for(unsigned int i = 3; i < args.size(); ++i)
+ {
+ if(args[i] == "@ONLY")
+ {
+ atOnly = true;
+ }
+ else if(args[i] == "ESCAPE_QUOTES")
+ {
+ escapeQuotes = true;
+ }
+ else
+ {
+ cmOStringStream err;
+ err << "Unrecognized argument \"" << args[i] << "\"";
+ this->SetError(err.str());
+ return false;
+ }
+ }
+
+ // Configure the string.
+ std::string output;
+ this->Makefile->ConfigureString(args[1], output, atOnly, escapeQuotes);
+
+ // Store the output in the provided variable.
+ this->Makefile->AddDefinition(args[2], output.c_str());
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleRegexCommand(std::vector<std::string> const& args)
+{
+ if(args.size() < 2)
+ {
+ this->SetError("sub-command REGEX requires a mode to be specified.");
+ return false;
+ }
+ std::string mode = args[1];
+ if(mode == "MATCH")
+ {
+ if(args.size() < 5)
+ {
+ this->SetError("sub-command REGEX, mode MATCH needs "
+ "at least 5 arguments total to command.");
+ return false;
+ }
+ return this->RegexMatch(args);
+ }
+ else if(mode == "MATCHALL")
+ {
+ if(args.size() < 5)
+ {
+ this->SetError("sub-command REGEX, mode MATCHALL needs "
+ "at least 5 arguments total to command.");
+ return false;
+ }
+ return this->RegexMatchAll(args);
+ }
+ else if(mode == "REPLACE")
+ {
+ if(args.size() < 6)
+ {
+ this->SetError("sub-command REGEX, mode REPLACE needs "
+ "at least 6 arguments total to command.");
+ return false;
+ }
+ return this->RegexReplace(args);
+ }
+
+ std::string e = "sub-command REGEX does not recognize mode "+mode;
+ this->SetError(e);
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
+{
+ //"STRING(REGEX MATCH <regular_expression> <output variable>
+ // <input> [<input>...])\n";
+ std::string regex = args[2];
+ std::string outvar = args[3];
+
+ // Concatenate all the last arguments together.
+ std::string input = args[4];
+ for(unsigned int i=5; i < args.size(); ++i)
+ {
+ input += args[i];
+ }
+
+ this->Makefile->ClearMatches();
+ // Compile the regular expression.
+ cmsys::RegularExpression re;
+ if(!re.compile(regex.c_str()))
+ {
+ std::string e =
+ "sub-command REGEX, mode MATCH failed to compile regex \""+regex+"\".";
+ this->SetError(e);
+ return false;
+ }
+
+ // Scan through the input for all matches.
+ std::string output;
+ if(re.find(input.c_str()))
+ {
+ this->Makefile->StoreMatches(re);
+ std::string::size_type l = re.start();
+ std::string::size_type r = re.end();
+ if(r-l == 0)
+ {
+ std::string e =
+ "sub-command REGEX, mode MATCH regex \""+regex+
+ "\" matched an empty string.";
+ this->SetError(e);
+ return false;
+ }
+ output = input.substr(l, r-l);
+ }
+
+ // Store the output in the provided variable.
+ this->Makefile->AddDefinition(outvar, output.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
+{
+ //"STRING(REGEX MATCHALL <regular_expression> <output variable> <input>
+ // [<input>...])\n";
+ std::string regex = args[2];
+ std::string outvar = args[3];
+
+ // Concatenate all the last arguments together.
+ std::string input = args[4];
+ for(unsigned int i=5; i < args.size(); ++i)
+ {
+ input += args[i];
+ }
+
+ this->Makefile->ClearMatches();
+ // Compile the regular expression.
+ cmsys::RegularExpression re;
+ if(!re.compile(regex.c_str()))
+ {
+ std::string e =
+ "sub-command REGEX, mode MATCHALL failed to compile regex \""+
+ regex+"\".";
+ this->SetError(e);
+ return false;
+ }
+
+ // Scan through the input for all matches.
+ std::string output;
+ const char* p = input.c_str();
+ while(re.find(p))
+ {
+ this->Makefile->StoreMatches(re);
+ std::string::size_type l = re.start();
+ std::string::size_type r = re.end();
+ if(r-l == 0)
+ {
+ std::string e = "sub-command REGEX, mode MATCHALL regex \""+
+ regex+"\" matched an empty string.";
+ this->SetError(e);
+ return false;
+ }
+ if(output.length() > 0)
+ {
+ output += ";";
+ }
+ output += std::string(p+l, r-l);
+ p += r;
+ }
+
+ // Store the output in the provided variable.
+ this->Makefile->AddDefinition(outvar, output.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
+{
+ //"STRING(REGEX REPLACE <regular_expression> <replace_expression>
+ // <output variable> <input> [<input>...])\n"
+ std::string regex = args[2];
+ std::string replace = args[3];
+ std::string outvar = args[4];
+
+ // Pull apart the replace expression to find the escaped [0-9] values.
+ std::vector<RegexReplacement> replacement;
+ std::string::size_type l = 0;
+ while(l < replace.length())
+ {
+ std::string::size_type r = replace.find("\\", l);
+ if(r == std::string::npos)
+ {
+ r = replace.length();
+ replacement.push_back(replace.substr(l, r-l));
+ }
+ else
+ {
+ if(r-l > 0)
+ {
+ replacement.push_back(replace.substr(l, r-l));
+ }
+ if(r == (replace.length()-1))
+ {
+ this->SetError("sub-command REGEX, mode REPLACE: "
+ "replace-expression ends in a backslash.");
+ return false;
+ }
+ if((replace[r+1] >= '0') && (replace[r+1] <= '9'))
+ {
+ replacement.push_back(replace[r+1]-'0');
+ }
+ else if(replace[r+1] == 'n')
+ {
+ replacement.push_back("\n");
+ }
+ else if(replace[r+1] == '\\')
+ {
+ replacement.push_back("\\");
+ }
+ else
+ {
+ std::string e = "sub-command REGEX, mode REPLACE: Unknown escape \"";
+ e += replace.substr(r, 2);
+ e += "\" in replace-expression.";
+ this->SetError(e);
+ return false;
+ }
+ r += 2;
+ }
+ l = r;
+ }
+
+ // Concatenate all the last arguments together.
+ std::string input = args[5];
+ for(unsigned int i=6; i < args.size(); ++i)
+ {
+ input += args[i];
+ }
+
+ this->Makefile->ClearMatches();
+ // Compile the regular expression.
+ cmsys::RegularExpression re;
+ if(!re.compile(regex.c_str()))
+ {
+ std::string e =
+ "sub-command REGEX, mode REPLACE failed to compile regex \""+
+ regex+"\".";
+ this->SetError(e);
+ return false;
+ }
+
+ // Scan through the input for all matches.
+ std::string output;
+ std::string::size_type base = 0;
+ while(re.find(input.c_str()+base))
+ {
+ this->Makefile->StoreMatches(re);
+ std::string::size_type l2 = re.start();
+ std::string::size_type r = re.end();
+
+ // Concatenate the part of the input that was not matched.
+ output += input.substr(base, l2);
+
+ // Make sure the match had some text.
+ if(r-l2 == 0)
+ {
+ std::string e = "sub-command REGEX, mode REPLACE regex \""+
+ regex+"\" matched an empty string.";
+ this->SetError(e);
+ return false;
+ }
+
+ // Concatenate the replacement for the match.
+ for(unsigned int i=0; i < replacement.size(); ++i)
+ {
+ if(replacement[i].number < 0)
+ {
+ // This is just a plain-text part of the replacement.
+ output += replacement[i].value;
+ }
+ else
+ {
+ // Replace with part of the match.
+ int n = replacement[i].number;
+ std::string::size_type start = re.start(n);
+ std::string::size_type end = re.end(n);
+ std::string::size_type len = input.length()-base;
+ if((start != std::string::npos) && (end != std::string::npos) &&
+ (start <= len) && (end <= len))
+ {
+ output += input.substr(base+start, end-start);
+ }
+ else
+ {
+ std::string e =
+ "sub-command REGEX, mode REPLACE: replace expression \""+
+ replace+"\" contains an out-of-range escape for regex \""+
+ regex+"\".";
+ this->SetError(e);
+ return false;
+ }
+ }
+ }
+
+ // Move past the match.
+ base += r;
+ }
+
+ // Concatenate the text after the last match.
+ output += input.substr(base, input.length()-base);
+
+ // Store the output in the provided variable.
+ this->Makefile->AddDefinition(outvar, output.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleFindCommand(std::vector<std::string> const&
+ args)
+{
+ // check if all required parameters were passed
+ if(args.size() < 4 || args.size() > 5)
+ {
+ this->SetError("sub-command FIND requires 3 or 4 parameters.");
+ return false;
+ }
+
+ // check if the reverse flag was set or not
+ bool reverseMode = false;
+ if(args.size() == 5 && args[4] == "REVERSE")
+ {
+ reverseMode = true;
+ }
+
+ // if we have 5 arguments the last one must be REVERSE
+ if(args.size() == 5 && args[4] != "REVERSE")
+ {
+ this->SetError("sub-command FIND: unknown last parameter");
+ return false;
+ }
+
+ // local parameter names.
+ const std::string& sstring = args[1];
+ const std::string& schar = args[2];
+ const std::string& outvar = args[3];
+
+ // ensure that the user cannot accidentally specify REVERSE as a variable
+ if(outvar == "REVERSE")
+ {
+ this->SetError("sub-command FIND does not allow to select REVERSE as "
+ "the output variable. "
+ "Maybe you missed the actual output variable?");
+ return false;
+ }
+
+ // try to find the character and return its position
+ size_t pos;
+ if(!reverseMode)
+ {
+ pos = sstring.find(schar);
+ }
+ else
+ {
+ pos = sstring.rfind(schar);
+ }
+ if(std::string::npos != pos)
+ {
+ cmOStringStream s;
+ s << pos;
+ this->Makefile->AddDefinition(outvar, s.str().c_str());
+ return true;
+ }
+
+ // the character was not found, but this is not really an error
+ this->Makefile->AddDefinition(outvar, "-1");
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleCompareCommand(std::vector<std::string> const&
+ args)
+{
+ if(args.size() < 2)
+ {
+ this->SetError("sub-command COMPARE requires a mode to be specified.");
+ return false;
+ }
+ std::string mode = args[1];
+ if((mode == "EQUAL") || (mode == "NOTEQUAL") ||
+ (mode == "LESS") || (mode == "GREATER"))
+ {
+ if(args.size() < 5)
+ {
+ std::string e = "sub-command COMPARE, mode ";
+ e += mode;
+ e += " needs at least 5 arguments total to command.";
+ this->SetError(e);
+ return false;
+ }
+
+ const std::string& left = args[2];
+ const std::string& right = args[3];
+ const std::string& outvar = args[4];
+ bool result;
+ if(mode == "LESS")
+ {
+ result = (left < right);
+ }
+ else if(mode == "GREATER")
+ {
+ result = (left > right);
+ }
+ else if(mode == "EQUAL")
+ {
+ result = (left == right);
+ }
+ else // if(mode == "NOTEQUAL")
+ {
+ result = !(left == right);
+ }
+ if(result)
+ {
+ this->Makefile->AddDefinition(outvar, "1");
+ }
+ else
+ {
+ this->Makefile->AddDefinition(outvar, "0");
+ }
+ return true;
+ }
+ std::string e = "sub-command COMPARE does not recognize mode "+mode;
+ this->SetError(e);
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleReplaceCommand(std::vector<std::string> const&
+ args)
+{
+ if(args.size() < 5)
+ {
+ this->SetError("sub-command REPLACE requires at least four arguments.");
+ return false;
+ }
+
+ const std::string& matchExpression = args[1];
+ const std::string& replaceExpression = args[2];
+ const std::string& variableName = args[3];
+
+ std::string input = args[4];
+ for(unsigned int i=5; i < args.size(); ++i)
+ {
+ input += args[i];
+ }
+
+ cmsys::SystemTools::ReplaceString(input, matchExpression.c_str(),
+ replaceExpression.c_str());
+
+ this->Makefile->AddDefinition(variableName, input.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleSubstringCommand(std::vector<std::string> const&
+ args)
+{
+ if(args.size() != 5)
+ {
+ this->SetError("sub-command SUBSTRING requires four arguments.");
+ return false;
+ }
+
+ const std::string& stringValue = args[1];
+ int begin = atoi(args[2].c_str());
+ int end = atoi(args[3].c_str());
+ const std::string& variableName = args[4];
+
+ size_t stringLength = stringValue.size();
+ int intStringLength = static_cast<int>(stringLength);
+ if ( begin < 0 || begin > intStringLength )
+ {
+ cmOStringStream ostr;
+ ostr << "begin index: " << begin << " is out of range 0 - "
+ << stringLength;
+ this->SetError(ostr.str());
+ return false;
+ }
+ int leftOverLength = intStringLength - begin;
+ if ( end < -1 || end > leftOverLength )
+ {
+ cmOStringStream ostr;
+ ostr << "end index: " << end << " is out of range -1 - "
+ << leftOverLength;
+ this->SetError(ostr.str());
+ return false;
+ }
+
+ this->Makefile->AddDefinition(variableName,
+ stringValue.substr(begin, end).c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand
+::HandleLengthCommand(std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+ {
+ this->SetError("sub-command LENGTH requires two arguments.");
+ return false;
+ }
+
+ const std::string& stringValue = args[1];
+ const std::string& variableName = args[2];
+
+ size_t length = stringValue.size();
+ char buffer[1024];
+ sprintf(buffer, "%d", static_cast<int>(length));
+
+ this->Makefile->AddDefinition(variableName, buffer);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand
+::HandleConcatCommand(std::vector<std::string> const& args)
+{
+ if(args.size() < 2)
+ {
+ this->SetError("sub-command CONCAT requires at least one argument.");
+ return false;
+ }
+
+ std::string const& variableName = args[1];
+ std::string value;
+ for(unsigned int i = 2; i < args.size(); ++i)
+ {
+ value += args[i];
+ }
+
+ this->Makefile->AddDefinition(variableName, value.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand
+::HandleMakeCIdentifierCommand(std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+ {
+ this->SetError("sub-command MAKE_C_IDENTIFIER requires two arguments.");
+ return false;
+ }
+
+ const std::string& input = args[1];
+ const std::string& variableName = args[2];
+
+ this->Makefile->AddDefinition(variableName,
+ cmSystemTools::MakeCidentifier(input.c_str()).c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand
+::HandleGenexStripCommand(std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+ {
+ this->SetError("sub-command GENEX_STRIP requires two arguments.");
+ return false;
+ }
+
+ const std::string& input = args[1];
+
+ std::string result = cmGeneratorExpression::Preprocess(input,
+ cmGeneratorExpression::StripAllGeneratorExpressions);
+
+ const std::string& variableName = args[2];
+
+ this->Makefile->AddDefinition(variableName, result.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand::HandleStripCommand(
+ std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+ {
+ this->SetError("sub-command STRIP requires two arguments.");
+ return false;
+ }
+
+ const std::string& stringValue = args[1];
+ const std::string& variableName = args[2];
+ size_t inStringLength = stringValue.size();
+ size_t startPos = inStringLength + 1;
+ size_t endPos = 0;
+ const char* ptr = stringValue.c_str();
+ size_t cc;
+ for ( cc = 0; cc < inStringLength; ++ cc )
+ {
+ if ( !isspace(*ptr) )
+ {
+ if ( startPos > inStringLength )
+ {
+ startPos = cc;
+ }
+ endPos = cc;
+ }
+ ++ ptr;
+ }
+
+ size_t outLength = 0;
+
+ // if the input string didn't contain any non-space characters, return
+ // an empty string
+ if (startPos > inStringLength)
+ {
+ outLength = 0;
+ startPos = 0;
+ }
+ else
+ {
+ outLength=endPos - startPos + 1;
+ }
+
+ this->Makefile->AddDefinition(variableName,
+ stringValue.substr(startPos, outLength).c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand
+::HandleRandomCommand(std::vector<std::string> const& args)
+{
+ if(args.size() < 2 || args.size() == 3 || args.size() == 5)
+ {
+ this->SetError("sub-command RANDOM requires at least one argument.");
+ return false;
+ }
+
+ static bool seeded = false;
+ bool force_seed = false;
+ unsigned int seed = 0;
+ int length = 5;
+ const char cmStringCommandDefaultAlphabet[] = "qwertyuiopasdfghjklzxcvbnm"
+ "QWERTYUIOPASDFGHJKLZXCVBNM"
+ "0123456789";
+ std::string alphabet;
+
+ if ( args.size() > 3 )
+ {
+ size_t i = 1;
+ size_t stopAt = args.size() - 2;
+
+ for ( ; i < stopAt; ++i )
+ {
+ if ( args[i] == "LENGTH" )
+ {
+ ++i;
+ length = atoi(args[i].c_str());
+ }
+ else if ( args[i] == "ALPHABET" )
+ {
+ ++i;
+ alphabet = args[i];
+ }
+ else if ( args[i] == "RANDOM_SEED" )
+ {
+ ++i;
+ seed = static_cast<unsigned int>(atoi(args[i].c_str()));
+ force_seed = true;
+ }
+ }
+ }
+ if ( !alphabet.size() )
+ {
+ alphabet = cmStringCommandDefaultAlphabet;
+ }
+
+ double sizeofAlphabet = static_cast<double>(alphabet.size());
+ if ( sizeofAlphabet < 1 )
+ {
+ this->SetError("sub-command RANDOM invoked with bad alphabet.");
+ return false;
+ }
+ if ( length < 1 )
+ {
+ this->SetError("sub-command RANDOM invoked with bad length.");
+ return false;
+ }
+ const std::string& variableName = args[args.size()-1];
+
+ std::vector<char> result;
+
+ if (!seeded || force_seed)
+ {
+ seeded = true;
+ srand(force_seed? seed : cmSystemTools::RandomSeed());
+ }
+
+ const char* alphaPtr = alphabet.c_str();
+ int cc;
+ for ( cc = 0; cc < length; cc ++ )
+ {
+ int idx=(int) (sizeofAlphabet* rand()/(RAND_MAX+1.0));
+ result.push_back(*(alphaPtr + idx));
+ }
+ result.push_back(0);
+
+ this->Makefile->AddDefinition(variableName, &*result.begin());
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand
+::HandleTimestampCommand(std::vector<std::string> const& args)
+{
+ if(args.size() < 2)
+ {
+ this->SetError("sub-command TIMESTAMP requires at least one argument.");
+ return false;
+ }
+ else if(args.size() > 4)
+ {
+ this->SetError("sub-command TIMESTAMP takes at most three arguments.");
+ return false;
+ }
+
+ unsigned int argsIndex = 1;
+
+ const std::string &outputVariable = args[argsIndex++];
+
+ std::string formatString;
+ if(args.size() > argsIndex && args[argsIndex] != "UTC")
+ {
+ formatString = args[argsIndex++];
+ }
+
+ bool utcFlag = false;
+ if(args.size() > argsIndex)
+ {
+ if(args[argsIndex] == "UTC")
+ {
+ utcFlag = true;
+ }
+ else
+ {
+ std::string e = " TIMESTAMP sub-command does not recognize option " +
+ args[argsIndex] + ".";
+ this->SetError(e);
+ return false;
+ }
+ }
+
+ cmTimestamp timestamp;
+ std::string result = timestamp.CurrentTime(formatString, utcFlag);
+ this->Makefile->AddDefinition(outputVariable, result.c_str());
+
+ return true;
+}
+
+bool cmStringCommand
+::HandleUuidCommand(std::vector<std::string> const& args)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ unsigned int argsIndex = 1;
+
+ if(args.size() < 2)
+ {
+ this->SetError("UUID sub-command requires an output variable.");
+ return false;
+ }
+
+ const std::string &outputVariable = args[argsIndex++];
+
+ std::string uuidNamespaceString;
+ std::string uuidName;
+ std::string uuidType;
+ bool uuidUpperCase = false;
+
+ while(args.size() > argsIndex)
+ {
+ if(args[argsIndex] == "NAMESPACE")
+ {
+ ++argsIndex;
+ if(argsIndex >= args.size())
+ {
+ this->SetError("UUID sub-command, NAMESPACE requires a value.");
+ return false;
+ }
+ uuidNamespaceString = args[argsIndex++];
+ }
+ else if(args[argsIndex] == "NAME")
+ {
+ ++argsIndex;
+ if(argsIndex >= args.size())
+ {
+ this->SetError("UUID sub-command, NAME requires a value.");
+ return false;
+ }
+ uuidName = args[argsIndex++];
+ }
+ else if(args[argsIndex] == "TYPE")
+ {
+ ++argsIndex;
+ if(argsIndex >= args.size())
+ {
+ this->SetError("UUID sub-command, TYPE requires a value.");
+ return false;
+ }
+ uuidType = args[argsIndex++];
+ }
+ else if(args[argsIndex] == "UPPER")
+ {
+ ++argsIndex;
+ uuidUpperCase = true;
+ }
+ else
+ {
+ std::string e = "UUID sub-command does not recognize option " +
+ args[argsIndex] + ".";
+ this->SetError(e);
+ return false;
+ }
+ }
+
+ std::string uuid;
+ cmUuid uuidGenerator;
+
+ std::vector<unsigned char> uuidNamespace;
+ if(!uuidGenerator.StringToBinary(uuidNamespaceString, uuidNamespace))
+ {
+ this->SetError("UUID sub-command, malformed NAMESPACE UUID.");
+ return false;
+ }
+
+ if(uuidType == "MD5")
+ {
+ uuid = uuidGenerator.FromMd5(uuidNamespace, uuidName);
+ }
+ else if(uuidType == "SHA1")
+ {
+ uuid = uuidGenerator.FromSha1(uuidNamespace, uuidName);
+ }
+ else
+ {
+ std::string e = "UUID sub-command, unknown TYPE '" + uuidType + "'.";
+ this->SetError(e);
+ return false;
+ }
+
+ if(uuid.empty())
+ {
+ this->SetError("UUID sub-command, generation failed.");
+ return false;
+ }
+
+ if(uuidUpperCase)
+ {
+ uuid = cmSystemTools::UpperCase(uuid);
+ }
+
+ this->Makefile->AddDefinition(outputVariable, uuid.c_str());
+ return true;
+#else
+ cmOStringStream e;
+ e << args[0] << " not available during bootstrap";
+ this->SetError(e.str().c_str());
+ return false;
+#endif
+}
diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h
new file mode 100644
index 0000000000..9c75095c1c
--- /dev/null
+++ b/Source/cmStringCommand.h
@@ -0,0 +1,92 @@
+/*============================================================================
+ 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 cmStringCommand_h
+#define cmStringCommand_h
+
+#include "cmCommand.h"
+
+class cmMakefile;
+namespace cmsys
+{
+ class RegularExpression;
+}
+
+/** \class cmStringCommand
+ * \brief Common string operations
+ *
+ */
+class cmStringCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmStringCommand;
+ }
+
+ /**
+ * 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 "string";}
+
+ cmTypeMacro(cmStringCommand, cmCommand);
+protected:
+ bool HandleConfigureCommand(std::vector<std::string> const& args);
+ bool HandleAsciiCommand(std::vector<std::string> const& args);
+ bool HandleRegexCommand(std::vector<std::string> const& args);
+ bool RegexMatch(std::vector<std::string> const& args);
+ bool RegexMatchAll(std::vector<std::string> const& args);
+ bool RegexReplace(std::vector<std::string> const& args);
+ bool HandleHashCommand(std::vector<std::string> const& args);
+ bool HandleToUpperLowerCommand(std::vector<std::string> const& args,
+ bool toUpper);
+ bool HandleCompareCommand(std::vector<std::string> const& args);
+ bool HandleReplaceCommand(std::vector<std::string> const& args);
+ bool HandleLengthCommand(std::vector<std::string> const& args);
+ bool HandleSubstringCommand(std::vector<std::string> const& args);
+ bool HandleConcatCommand(std::vector<std::string> const& args);
+ bool HandleStripCommand(std::vector<std::string> const& args);
+ bool HandleRandomCommand(std::vector<std::string> const& args);
+ bool HandleFindCommand(std::vector<std::string> const& args);
+ bool HandleTimestampCommand(std::vector<std::string> const& args);
+ bool HandleMakeCIdentifierCommand(std::vector<std::string> const& args);
+ bool HandleGenexStripCommand(std::vector<std::string> const& args);
+ bool HandleUuidCommand(std::vector<std::string> const& args);
+
+ class RegexReplacement
+ {
+ public:
+ RegexReplacement(const char* s): number(-1), value(s) {}
+ RegexReplacement(const std::string& s): number(-1), value(s) {}
+ RegexReplacement(int n): number(n), value() {}
+ RegexReplacement() {}
+ int number;
+ std::string value;
+ };
+};
+
+
+#endif
diff --git a/Source/cmSubdirCommand.cxx b/Source/cmSubdirCommand.cxx
new file mode 100644
index 0000000000..cdde91687b
--- /dev/null
+++ b/Source/cmSubdirCommand.cxx
@@ -0,0 +1,74 @@
+/*============================================================================
+ 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 "cmSubdirCommand.h"
+
+// cmSubdirCommand
+bool cmSubdirCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 1 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ bool res = true;
+ bool excludeFromAll = false;
+ bool preorder = false;
+
+ for(std::vector<std::string>::const_iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ if(*i == "EXCLUDE_FROM_ALL")
+ {
+ excludeFromAll = true;
+ continue;
+ }
+ if(*i == "PREORDER")
+ {
+ preorder = true;
+ continue;
+ }
+
+ // if they specified a relative path then compute the full
+ std::string srcPath =
+ std::string(this->Makefile->GetCurrentDirectory()) +
+ "/" + i->c_str();
+ if (cmSystemTools::FileIsDirectory(srcPath.c_str()))
+ {
+ std::string binPath =
+ std::string(this->Makefile->GetCurrentOutputDirectory()) +
+ "/" + i->c_str();
+ this->Makefile->AddSubDirectory(srcPath, binPath,
+ excludeFromAll, preorder, false);
+ }
+ // otherwise it is a full path
+ else if ( cmSystemTools::FileIsDirectory(i->c_str()) )
+ {
+ // we must compute the binPath from the srcPath, we just take the last
+ // element from the source path and use that
+ std::string binPath =
+ std::string(this->Makefile->GetCurrentOutputDirectory()) +
+ "/" + cmSystemTools::GetFilenameName(*i);
+ this->Makefile->AddSubDirectory(*i, binPath,
+ excludeFromAll, preorder, false);
+ }
+ else
+ {
+ std::string error = "Incorrect SUBDIRS command. Directory: ";
+ error += *i + " does not exist.";
+ this->SetError(error);
+ res = false;
+ }
+ }
+ return res;
+}
+
diff --git a/Source/cmSubdirCommand.h b/Source/cmSubdirCommand.h
new file mode 100644
index 0000000000..6addd8f852
--- /dev/null
+++ b/Source/cmSubdirCommand.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ 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 cmSubdirCommand_h
+#define cmSubdirCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmSubdirCommand
+ * \brief Specify a list of subdirectories to build.
+ *
+ * cmSubdirCommand specifies a list of subdirectories to process
+ * by CMake. For each subdirectory listed, CMake will descend
+ * into that subdirectory and process any CMakeLists.txt found.
+ */
+class cmSubdirCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmSubdirCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "subdirs";}
+
+ /** This command is kept for compatibility with older CMake versions. */
+ virtual bool IsDiscouraged() const
+ {
+ return true;
+ }
+
+ cmTypeMacro(cmSubdirCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmSubdirDependsCommand.cxx b/Source/cmSubdirDependsCommand.cxx
new file mode 100644
index 0000000000..938198300b
--- /dev/null
+++ b/Source/cmSubdirDependsCommand.cxx
@@ -0,0 +1,20 @@
+/*============================================================================
+ 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 "cmSubdirDependsCommand.h"
+
+bool cmSubdirDependsCommand::InitialPass(std::vector<std::string> const& ,
+ cmExecutionStatus &)
+{
+ this->Disallowed(cmPolicies::CMP0029,
+ "The subdir_depends command should not be called; see CMP0029.");
+ return true;
+}
diff --git a/Source/cmSubdirDependsCommand.h b/Source/cmSubdirDependsCommand.h
new file mode 100644
index 0000000000..75a5685949
--- /dev/null
+++ b/Source/cmSubdirDependsCommand.h
@@ -0,0 +1,28 @@
+/*============================================================================
+ 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 cmSubdirDependsCommand_h
+#define cmSubdirDependsCommand_h
+
+#include "cmCommand.h"
+
+class cmSubdirDependsCommand : public cmCommand
+{
+public:
+ virtual cmCommand* Clone() { return new cmSubdirDependsCommand; }
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+ virtual std::string GetName() const { return "subdir_depends";}
+ virtual bool IsDiscouraged() const { return true; }
+ cmTypeMacro(cmSubdirDependsCommand, cmCommand);
+};
+
+#endif
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
new file mode 100644
index 0000000000..fbb44160c6
--- /dev/null
+++ b/Source/cmSystemTools.cxx
@@ -0,0 +1,2923 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#if defined(_MSC_VER) && _MSC_VER < 1300
+# define _WIN32_WINNT 0x0400 /* for wincrypt.h */
+#endif
+#include "cmSystemTools.h"
+#include <ctype.h>
+#include <errno.h>
+#include <time.h>
+#include <string.h>
+#include <stdlib.h>
+#ifdef __QNX__
+# include <malloc.h> /* for malloc/free on QNX */
+#endif
+#include <cmsys/Glob.hxx>
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Directory.hxx>
+#include <cmsys/System.h>
+#include <cmsys/Encoding.hxx>
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include "cmArchiveWrite.h"
+# include <cm_libarchive.h>
+# include <cmsys/Terminal.h>
+#endif
+#include <cmsys/stl/algorithm>
+#include <cmsys/FStream.hxx>
+
+#if defined(_WIN32)
+# include <windows.h>
+# include <wincrypt.h>
+#else
+# include <sys/time.h>
+# include <sys/types.h>
+# include <unistd.h>
+# include <utime.h>
+# include <sys/wait.h>
+#endif
+
+#if defined(__APPLE__)
+# include <mach-o/dyld.h>
+#endif
+
+#include <sys/stat.h>
+
+#if defined(_WIN32) && \
+ (defined(_MSC_VER) || defined(__WATCOMC__) || \
+ defined(__BORLANDC__) || defined(__MINGW32__))
+# include <io.h>
+#endif
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include <fcntl.h>
+# include "cmCryptoHash.h"
+#endif
+
+#if defined(CMAKE_USE_ELF_PARSER)
+# include "cmELF.h"
+#endif
+
+class cmSystemToolsFileTime
+{
+public:
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ FILETIME timeCreation;
+ FILETIME timeLastAccess;
+ FILETIME timeLastWrite;
+#else
+ struct utimbuf timeBuf;
+#endif
+};
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 1375 /* base class destructor not virtual */
+#endif
+
+#if !defined(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
+// For GetEnvironmentVariables
+# if defined(_WIN32)
+extern __declspec( dllimport ) char** environ;
+# else
+extern char** environ;
+# endif
+#endif
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+static std::string
+cm_archive_entry_pathname(struct archive_entry *entry)
+{
+#if cmsys_STL_HAS_WSTRING
+ return cmsys::Encoding::ToNarrow(
+ archive_entry_pathname_w(entry)).c_str();
+#else
+ return archive_entry_pathname(entry);
+#endif
+}
+
+static int cm_archive_read_open_file(struct archive* a,
+ const char* file,
+ int block_size)
+{
+#if cmsys_STL_HAS_WSTRING
+ std::wstring wfile = cmsys::Encoding::ToWide(file);
+ return archive_read_open_filename_w(a, wfile.c_str(), block_size);
+#else
+ return archive_read_open_filename(a, file, block_size);
+#endif
+}
+#endif
+
+#ifdef _WIN32
+class cmSystemToolsWindowsHandle
+{
+public:
+ cmSystemToolsWindowsHandle(HANDLE h): handle_(h) {}
+ ~cmSystemToolsWindowsHandle()
+ {
+ if(this->handle_ != INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(this->handle_);
+ }
+ }
+ operator bool() const { return this->handle_ != INVALID_HANDLE_VALUE; }
+ bool operator !() const { return this->handle_ == INVALID_HANDLE_VALUE; }
+ operator HANDLE() const { return this->handle_; }
+private:
+ HANDLE handle_;
+};
+#elif defined(__APPLE__)
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#endif
+
+bool cmSystemTools::s_RunCommandHideConsole = false;
+bool cmSystemTools::s_DisableRunCommandOutput = false;
+bool cmSystemTools::s_ErrorOccured = false;
+bool cmSystemTools::s_FatalErrorOccured = false;
+bool cmSystemTools::s_DisableMessages = false;
+bool cmSystemTools::s_ForceUnixPaths = false;
+
+cmSystemTools::MessageCallback cmSystemTools::s_MessageCallback;
+cmSystemTools::OutputCallback cmSystemTools::s_StdoutCallback;
+cmSystemTools::OutputCallback cmSystemTools::s_StderrCallback;
+cmSystemTools::InterruptCallback cmSystemTools::s_InterruptCallback;
+void* cmSystemTools::s_MessageCallbackClientData;
+void* cmSystemTools::s_StdoutCallbackClientData;
+void* cmSystemTools::s_StderrCallbackClientData;
+void* cmSystemTools::s_InterruptCallbackClientData;
+
+// replace replace with with as many times as it shows up in source.
+// write the result into source.
+#if defined(_WIN32) && !defined(__CYGWIN__)
+void cmSystemTools::ExpandRegistryValues(std::string& source, KeyWOW64 view)
+{
+ // Regular expression to match anything inside [...] that begins in HKEY.
+ // Note that there is a special rule for regular expressions to match a
+ // close square-bracket inside a list delimited by square brackets.
+ // The "[^]]" part of this expression will match any character except
+ // a close square-bracket. The ']' character must be the first in the
+ // list of characters inside the [^...] block of the expression.
+ cmsys::RegularExpression regEntry("\\[(HKEY[^]]*)\\]");
+
+ // check for black line or comment
+ while (regEntry.find(source))
+ {
+ // the arguments are the second match
+ std::string key = regEntry.match(1);
+ std::string val;
+ if (ReadRegistryValue(key.c_str(), val, view))
+ {
+ std::string reg = "[";
+ reg += key + "]";
+ cmSystemTools::ReplaceString(source, reg.c_str(), val.c_str());
+ }
+ else
+ {
+ std::string reg = "[";
+ reg += key + "]";
+ cmSystemTools::ReplaceString(source, reg.c_str(), "/registry");
+ }
+ }
+}
+#else
+void cmSystemTools::ExpandRegistryValues(std::string& source, KeyWOW64)
+{
+ cmsys::RegularExpression regEntry("\\[(HKEY[^]]*)\\]");
+ while (regEntry.find(source))
+ {
+ // the arguments are the second match
+ std::string key = regEntry.match(1);
+ std::string val;
+ std::string reg = "[";
+ reg += key + "]";
+ cmSystemTools::ReplaceString(source, reg.c_str(), "/registry");
+ }
+
+}
+#endif
+
+std::string cmSystemTools::EscapeQuotes(const std::string& str)
+{
+ std::string result;
+ result.reserve(str.size());
+ for(const char* ch = str.c_str(); *ch != '\0'; ++ch)
+ {
+ if(*ch == '"')
+ {
+ result += '\\';
+ }
+ result += *ch;
+ }
+ return result;
+}
+
+std::string cmSystemTools::HelpFileName(std::string name)
+{
+ cmSystemTools::ReplaceString(name, "<", "");
+ cmSystemTools::ReplaceString(name, ">", "");
+ return name;
+}
+
+std::string cmSystemTools::TrimWhitespace(const std::string& s)
+{
+ std::string::const_iterator start = s.begin();
+ while(start != s.end() && *start <= ' ')
+ ++start;
+ if (start == s.end())
+ return "";
+
+ std::string::const_iterator stop = s.end()-1;
+ while(*stop <= ' ')
+ --stop;
+ return std::string(start, stop+1);
+}
+
+void cmSystemTools::Error(const char* m1, const char* m2,
+ const char* m3, const char* m4)
+{
+ std::string message = "CMake Error: ";
+ if(m1)
+ {
+ message += m1;
+ }
+ if(m2)
+ {
+ message += m2;
+ }
+ if(m3)
+ {
+ message += m3;
+ }
+ if(m4)
+ {
+ message += m4;
+ }
+ cmSystemTools::s_ErrorOccured = true;
+ cmSystemTools::Message(message.c_str(),"Error");
+}
+
+void cmSystemTools::SetInterruptCallback(InterruptCallback f, void* clientData)
+{
+ s_InterruptCallback = f;
+ s_InterruptCallbackClientData = clientData;
+}
+
+bool cmSystemTools::GetInterruptFlag()
+{
+ if(s_InterruptCallback)
+ {
+ return (*s_InterruptCallback)(s_InterruptCallbackClientData);
+ }
+ return false;
+}
+
+void cmSystemTools::SetMessageCallback(MessageCallback f, void* clientData)
+{
+ s_MessageCallback = f;
+ s_MessageCallbackClientData = clientData;
+}
+
+void cmSystemTools::SetStdoutCallback(OutputCallback f, void* clientData)
+{
+ s_StdoutCallback = f;
+ s_StdoutCallbackClientData = clientData;
+}
+
+void cmSystemTools::SetStderrCallback(OutputCallback f, void* clientData)
+{
+ s_StderrCallback = f;
+ s_StderrCallbackClientData = clientData;
+}
+
+void cmSystemTools::Stdout(const char* s)
+{
+ cmSystemTools::Stdout(s, strlen(s));
+}
+
+void cmSystemTools::Stderr(const char* s)
+{
+ cmSystemTools::Stderr(s, strlen(s));
+}
+
+void cmSystemTools::Stderr(const char* s, size_t length)
+{
+ if(s_StderrCallback)
+ {
+ (*s_StderrCallback)(s, length, s_StderrCallbackClientData);
+ }
+ else
+ {
+ std::cerr.write(s, length);
+ std::cerr.flush();
+ }
+}
+
+void cmSystemTools::Stdout(const char* s, size_t length)
+{
+ if(s_StdoutCallback)
+ {
+ (*s_StdoutCallback)(s, length, s_StdoutCallbackClientData);
+ }
+ else
+ {
+ std::cout.write(s, length);
+ std::cout.flush();
+ }
+}
+
+void cmSystemTools::Message(const char* m1, const char *title)
+{
+ if(s_DisableMessages)
+ {
+ return;
+ }
+ if(s_MessageCallback)
+ {
+ (*s_MessageCallback)(m1, title, s_DisableMessages,
+ s_MessageCallbackClientData);
+ return;
+ }
+ else
+ {
+ std::cerr << m1 << std::endl << std::flush;
+ }
+
+}
+
+
+void cmSystemTools::ReportLastSystemError(const char* msg)
+{
+ std::string m = msg;
+ m += ": System Error: ";
+ m += Superclass::GetLastSystemError();
+ cmSystemTools::Error(m.c_str());
+}
+
+bool cmSystemTools::IsInternallyOn(const char* val)
+{
+ if (!val)
+ {
+ return false;
+ }
+ std::basic_string<char> v = val;
+
+ for(std::basic_string<char>::iterator c = v.begin();
+ c != v.end(); c++)
+ {
+ *c = static_cast<char>(toupper(*c));
+ }
+ return (v == "I_ON" || v == "i_on");
+}
+
+bool cmSystemTools::IsOn(const char* val)
+{
+ if (!val)
+ {
+ return false;
+ }
+ size_t len = strlen(val);
+ if (len > 4)
+ {
+ return false;
+ }
+ std::basic_string<char> v(val, len);
+
+ static std::set<std::string> onValues;
+ if(onValues.empty())
+ {
+ onValues.insert("ON");
+ onValues.insert("1");
+ onValues.insert("YES");
+ onValues.insert("TRUE");
+ onValues.insert("Y");
+ }
+ for(std::basic_string<char>::iterator c = v.begin();
+ c != v.end(); c++)
+ {
+ *c = static_cast<char>(toupper(*c));
+ }
+ return (onValues.count(v) > 0);
+}
+
+bool cmSystemTools::IsNOTFOUND(const char* val)
+{
+ if(strcmp(val, "NOTFOUND") == 0)
+ {
+ return true;
+ }
+ return cmHasLiteralSuffix(val, "-NOTFOUND");
+}
+
+
+bool cmSystemTools::IsOff(const char* val)
+{
+ if (!val || !*val)
+ {
+ return true;
+ }
+ size_t len = strlen(val);
+ // Try and avoid toupper() for large strings.
+ if (len > 6)
+ {
+ return cmSystemTools::IsNOTFOUND(val);
+ }
+
+ static std::set<std::string> offValues;
+ if(offValues.empty())
+ {
+ offValues.insert("OFF");
+ offValues.insert("0");
+ offValues.insert("NO");
+ offValues.insert("FALSE");
+ offValues.insert("N");
+ offValues.insert("IGNORE");
+ }
+ // Try and avoid toupper().
+ std::basic_string<char> v(val, len);
+ for(std::basic_string<char>::iterator c = v.begin();
+ c != v.end(); c++)
+ {
+ *c = static_cast<char>(toupper(*c));
+ }
+ return (offValues.count(v) > 0);
+}
+
+//----------------------------------------------------------------------------
+void cmSystemTools::ParseWindowsCommandLine(const char* command,
+ std::vector<std::string>& args)
+{
+ // See the MSDN document "Parsing C Command-Line Arguments" at
+ // http://msdn2.microsoft.com/en-us/library/a1y7w461.aspx for rules
+ // of parsing the windows command line.
+
+ bool in_argument = false;
+ bool in_quotes = false;
+ int backslashes = 0;
+ std::string arg;
+ for(const char* c = command;*c; ++c)
+ {
+ if(*c == '\\')
+ {
+ ++backslashes;
+ in_argument = true;
+ }
+ else if(*c == '"')
+ {
+ int backslash_pairs = backslashes >> 1;
+ int backslash_escaped = backslashes & 1;
+ arg.append(backslash_pairs, '\\');
+ backslashes = 0;
+ if(backslash_escaped)
+ {
+ /* An odd number of backslashes precede this quote.
+ It is escaped. */
+ arg.append(1, '"');
+ }
+ else
+ {
+ /* An even number of backslashes precede this quote.
+ It is not escaped. */
+ in_quotes = !in_quotes;
+ }
+ in_argument = true;
+ }
+ else
+ {
+ arg.append(backslashes, '\\');
+ backslashes = 0;
+ if(((*c & 0x80) == 0 ) && isspace(*c))
+ {
+ if(in_quotes)
+ {
+ arg.append(1, *c);
+ }
+ else if(in_argument)
+ {
+ args.push_back(arg);
+ arg = "";
+ in_argument = false;
+ }
+ }
+ else
+ {
+ in_argument = true;
+ arg.append(1, *c);
+ }
+ }
+ }
+ arg.append(backslashes, '\\');
+ if(in_argument)
+ {
+ args.push_back(arg);
+ }
+}
+
+//----------------------------------------------------------------------------
+class cmSystemToolsArgV
+{
+ char** ArgV;
+public:
+ cmSystemToolsArgV(char** argv): ArgV(argv) {}
+ ~cmSystemToolsArgV()
+ {
+ for(char** arg = this->ArgV; arg && *arg; ++arg)
+ {
+ free(*arg);
+ }
+ free(this->ArgV);
+ }
+ void Store(std::vector<std::string>& args) const
+ {
+ for(char** arg = this->ArgV; arg && *arg; ++arg)
+ {
+ args.push_back(*arg);
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmSystemTools::ParseUnixCommandLine(const char* command,
+ std::vector<std::string>& args)
+{
+ // Invoke the underlying parser.
+ cmSystemToolsArgV argv = cmsysSystem_Parse_CommandForUnix(command, 0);
+ argv.Store(args);
+}
+
+std::string cmSystemTools::EscapeWindowsShellArgument(const char* arg,
+ int shell_flags)
+{
+ char local_buffer[1024];
+ char* buffer = local_buffer;
+ int size = cmsysSystem_Shell_GetArgumentSizeForWindows(arg, shell_flags);
+ if(size > 1024)
+ {
+ buffer = new char[size];
+ }
+ cmsysSystem_Shell_GetArgumentForWindows(arg, buffer, shell_flags);
+ std::string result(buffer);
+ if(buffer != local_buffer)
+ {
+ delete [] buffer;
+ }
+ return result;
+}
+
+std::vector<std::string> cmSystemTools::ParseArguments(const char* command)
+{
+ std::vector<std::string> args;
+ std::string arg;
+
+ bool win_path = false;
+
+ if ((command[0] != '/' && command[1] == ':' && command[2] == '\\') ||
+ (command[0] == '\"' && command[1] != '/' && command[2] == ':'
+ && command[3] == '\\') ||
+ (command[0] == '\'' && command[1] != '/' && command[2] == ':'
+ && command[3] == '\\') ||
+ (command[0] == '\\' && command[1] == '\\'))
+ {
+ win_path = true;
+ }
+ // Split the command into an argv array.
+ for(const char* c = command; *c;)
+ {
+ // Skip over whitespace.
+ while(*c == ' ' || *c == '\t')
+ {
+ ++c;
+ }
+ arg = "";
+ if(*c == '"')
+ {
+ // Parse a quoted argument.
+ ++c;
+ while(*c && *c != '"')
+ {
+ arg.append(1, *c);
+ ++c;
+ }
+ if(*c)
+ {
+ ++c;
+ }
+ args.push_back(arg);
+ }
+ else if(*c == '\'')
+ {
+ // Parse a quoted argument.
+ ++c;
+ while(*c && *c != '\'')
+ {
+ arg.append(1, *c);
+ ++c;
+ }
+ if(*c)
+ {
+ ++c;
+ }
+ args.push_back(arg);
+ }
+ else if(*c)
+ {
+ // Parse an unquoted argument.
+ while(*c && *c != ' ' && *c != '\t')
+ {
+ if(*c == '\\' && !win_path)
+ {
+ ++c;
+ if(*c)
+ {
+ arg.append(1, *c);
+ ++c;
+ }
+ }
+ else
+ {
+ arg.append(1, *c);
+ ++c;
+ }
+ }
+ args.push_back(arg);
+ }
+ }
+
+ return args;
+}
+
+
+bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
+ std::string* output ,
+ int* retVal , const char* dir ,
+ OutputOption outputflag ,
+ double timeout )
+{
+ std::vector<const char*> argv;
+ for(std::vector<std::string>::const_iterator a = command.begin();
+ a != command.end(); ++a)
+ {
+ argv.push_back(a->c_str());
+ }
+ argv.push_back(0);
+ if ( output )
+ {
+ *output = "";
+ }
+
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetWorkingDirectory(cp, dir);
+ if(cmSystemTools::GetRunCommandHideConsole())
+ {
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+ }
+
+ if (outputflag == OUTPUT_PASSTHROUGH)
+ {
+ cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
+ cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
+ }
+
+ cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_Execute(cp);
+
+ std::vector<char> tempOutput;
+ char* data;
+ int length;
+ int pipe;
+ if(outputflag != OUTPUT_PASSTHROUGH && (output || outputflag != OUTPUT_NONE))
+ {
+ while((pipe = cmsysProcess_WaitForData(cp, &data, &length, 0)) > 0)
+ {
+ if(output || 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)
+ {
+ if(data[i] == '\0')
+ {
+ data[i] = ' ';
+ }
+ }
+ }
+ if ( output )
+ {
+ tempOutput.insert(tempOutput.end(), data, data+length);
+ }
+ if(outputflag != OUTPUT_NONE)
+ {
+ if(outputflag == OUTPUT_MERGE)
+ {
+ cmSystemTools::Stdout(data, length);
+ }
+ else
+ {
+ if(pipe == cmsysProcess_Pipe_STDERR)
+ {
+ cmSystemTools::Stderr(data, length);
+ }
+ else if(pipe == cmsysProcess_Pipe_STDOUT)
+ {
+ cmSystemTools::Stdout(data, length);
+ }
+ }
+ }
+ }
+ }
+
+ cmsysProcess_WaitForExit(cp, 0);
+ if ( output && tempOutput.begin() != tempOutput.end())
+ {
+ output->append(&*tempOutput.begin(), tempOutput.size());
+ }
+
+ bool result = true;
+ if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
+ {
+ if ( retVal )
+ {
+ *retVal = cmsysProcess_GetExitValue(cp);
+ }
+ else
+ {
+ if ( cmsysProcess_GetExitValue(cp) != 0 )
+ {
+ result = false;
+ }
+ }
+ }
+ else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception)
+ {
+ const char* exception_str = cmsysProcess_GetExceptionString(cp);
+ if ( outputflag != OUTPUT_NONE )
+ {
+ std::cerr << exception_str << std::endl;
+ }
+ if ( output )
+ {
+ output->append(exception_str, strlen(exception_str));
+ }
+ result = false;
+ }
+ else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
+ {
+ const char* error_str = cmsysProcess_GetErrorString(cp);
+ if ( outputflag != OUTPUT_NONE )
+ {
+ std::cerr << error_str << std::endl;
+ }
+ if ( output )
+ {
+ output->append(error_str, strlen(error_str));
+ }
+ result = false;
+ }
+ else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired)
+ {
+ const char* error_str = "Process terminated due to timeout\n";
+ if ( outputflag != OUTPUT_NONE )
+ {
+ std::cerr << error_str << std::endl;
+ }
+ if ( output )
+ {
+ output->append(error_str, strlen(error_str));
+ }
+ result = false;
+ }
+
+ cmsysProcess_Delete(cp);
+ return result;
+}
+
+bool cmSystemTools::RunSingleCommand(
+ const char* command,
+ std::string* output,
+ int *retVal,
+ const char* dir,
+ OutputOption outputflag,
+ double timeout)
+{
+ if(s_DisableRunCommandOutput)
+ {
+ outputflag = OUTPUT_NONE;
+ }
+
+ std::vector<std::string> args = cmSystemTools::ParseArguments(command);
+
+ if(args.size() < 1)
+ {
+ return false;
+ }
+ return cmSystemTools::RunSingleCommand(args, output,retVal,
+ dir, outputflag, timeout);
+}
+
+std::string
+cmSystemTools::PrintSingleCommand(std::vector<std::string> const& command)
+{
+ std::string commandStr;
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator i = command.begin();
+ i != command.end(); ++i)
+ {
+ commandStr += sep;
+ commandStr += "\"";
+ commandStr += *i;
+ commandStr += "\"";
+ sep = " ";
+ }
+ return commandStr;
+}
+
+bool cmSystemTools::DoesFileExistWithExtensions(
+ const char* name,
+ const std::vector<std::string>& headerExts)
+{
+ std::string hname;
+
+ for( std::vector<std::string>::const_iterator ext = headerExts.begin();
+ ext != headerExts.end(); ++ext )
+ {
+ hname = name;
+ hname += ".";
+ hname += *ext;
+ if(cmSystemTools::FileExists(hname.c_str()))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+std::string cmSystemTools::FileExistsInParentDirectories(const char* fname,
+ const char* directory, const char* toplevel)
+{
+ std::string file = fname;
+ cmSystemTools::ConvertToUnixSlashes(file);
+ std::string dir = directory;
+ cmSystemTools::ConvertToUnixSlashes(dir);
+ std::string prevDir;
+ while(dir != prevDir)
+ {
+ std::string path = dir + "/" + file;
+ if ( cmSystemTools::FileExists(path.c_str()) )
+ {
+ return path;
+ }
+ if ( dir.size() < strlen(toplevel) )
+ {
+ break;
+ }
+ prevDir = dir;
+ dir = cmSystemTools::GetParentDirectory(dir.c_str());
+ }
+ return "";
+}
+
+bool cmSystemTools::cmCopyFile(const char* source, const char* destination)
+{
+ return Superclass::CopyFileAlways(source, destination);
+}
+
+bool cmSystemTools::CopyFileIfDifferent(const char* source,
+ const char* destination)
+{
+ return Superclass::CopyFileIfDifferent(source, destination);
+}
+
+//----------------------------------------------------------------------------
+#ifdef _WIN32
+cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsFileRetry()
+{
+ static WindowsFileRetry retry = {0,0};
+ if(!retry.Count)
+ {
+ unsigned int data[2] = {0,0};
+ HKEY const keys[2] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE};
+ wchar_t const* const values[2] = {L"FilesystemRetryCount",
+ L"FilesystemRetryDelay"};
+ for(int k=0; k < 2; ++k)
+ {
+ HKEY hKey;
+ if(RegOpenKeyExW(keys[k], L"Software\\Kitware\\CMake\\Config",
+ 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
+ {
+ for(int v=0; v < 2; ++v)
+ {
+ DWORD dwData, dwType, dwSize = 4;
+ if(!data[v] &&
+ RegQueryValueExW(hKey, values[v], 0, &dwType, (BYTE *)&dwData,
+ &dwSize) == ERROR_SUCCESS &&
+ dwType == REG_DWORD && dwSize == 4)
+ {
+ data[v] = static_cast<unsigned int>(dwData);
+ }
+ }
+ RegCloseKey(hKey);
+ }
+ }
+ retry.Count = data[0]? data[0] : 5;
+ retry.Delay = data[1]? data[1] : 500;
+ }
+ return retry;
+}
+#endif
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
+{
+#ifdef _WIN32
+# ifndef INVALID_FILE_ATTRIBUTES
+# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+# endif
+ /* Windows MoveFileEx may not replace read-only or in-use files. If it
+ fails then remove the read-only attribute from any existing destination.
+ Try multiple times since we may be racing against another process
+ creating/opening the destination file just before our MoveFileEx. */
+ WindowsFileRetry retry = cmSystemTools::GetWindowsFileRetry();
+ while(!MoveFileExW(cmsys::Encoding::ToWide(oldname).c_str(),
+ cmsys::Encoding::ToWide(newname).c_str(),
+ MOVEFILE_REPLACE_EXISTING) && --retry.Count)
+ {
+ DWORD last_error = GetLastError();
+ // Try again only if failure was due to access/sharing permissions.
+ if(last_error != ERROR_ACCESS_DENIED &&
+ last_error != ERROR_SHARING_VIOLATION)
+ {
+ return false;
+ }
+ DWORD attrs =
+ GetFileAttributesW(cmsys::Encoding::ToWide(newname).c_str());
+ if((attrs != INVALID_FILE_ATTRIBUTES) &&
+ (attrs & FILE_ATTRIBUTE_READONLY))
+ {
+ // Remove the read-only attribute from the destination file.
+ SetFileAttributesW(cmsys::Encoding::ToWide(newname).c_str(),
+ attrs & ~FILE_ATTRIBUTE_READONLY);
+ }
+ else
+ {
+ // The file may be temporarily in use so wait a bit.
+ cmSystemTools::Delay(retry.Delay);
+ }
+ }
+ return retry.Count > 0;
+#else
+ /* On UNIX we have an OS-provided call to do this atomically. */
+ return rename(oldname, newname) == 0;
+#endif
+}
+
+bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ cmCryptoHashMD5 md5;
+ std::string str = md5.HashFile(source);
+ strncpy(md5out, str.c_str(), 32);
+ return !str.empty();
+#else
+ (void)source;
+ (void)md5out;
+ cmSystemTools::Message("md5sum not supported in bootstrapping mode","Error");
+ return false;
+#endif
+}
+
+std::string cmSystemTools::ComputeStringMD5(const std::string& input)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ cmCryptoHashMD5 md5;
+ return md5.HashString(input);
+#else
+ (void)input;
+ cmSystemTools::Message("md5sum not supported in bootstrapping mode","Error");
+ return "";
+#endif
+}
+
+void cmSystemTools::Glob(const std::string& directory,
+ const std::string& regexp,
+ std::vector<std::string>& files)
+{
+ cmsys::Directory d;
+ cmsys::RegularExpression reg(regexp.c_str());
+
+ if (d.Load(directory.c_str()))
+ {
+ size_t numf;
+ unsigned int i;
+ numf = d.GetNumberOfFiles();
+ for (i = 0; i < numf; i++)
+ {
+ std::string fname = d.GetFile(i);
+ if (reg.find(fname))
+ {
+ files.push_back(fname);
+ }
+ }
+ }
+}
+
+
+void cmSystemTools::GlobDirs(const std::string& path,
+ std::vector<std::string>& files)
+{
+ std::string::size_type pos = path.find("/*");
+ if(pos == std::string::npos)
+ {
+ files.push_back(path);
+ return;
+ }
+ std::string startPath = path.substr(0, pos);
+ std::string finishPath = path.substr(pos+2);
+
+ cmsys::Directory d;
+ if (d.Load(startPath.c_str()))
+ {
+ for (unsigned int i = 0; i < d.GetNumberOfFiles(); ++i)
+ {
+ if((std::string(d.GetFile(i)) != ".")
+ && (std::string(d.GetFile(i)) != ".."))
+ {
+ std::string fname = startPath;
+ fname +="/";
+ fname += d.GetFile(i);
+ if(cmSystemTools::FileIsDirectory(fname.c_str()))
+ {
+ fname += finishPath;
+ cmSystemTools::GlobDirs(fname, files);
+ }
+ }
+ }
+ }
+}
+
+
+void cmSystemTools::ExpandList(std::vector<std::string> const& arguments,
+ std::vector<std::string>& newargs)
+{
+ std::vector<std::string>::const_iterator i;
+ for(i = arguments.begin();i != arguments.end(); ++i)
+ {
+ cmSystemTools::ExpandListArgument(*i, newargs);
+ }
+}
+
+void cmSystemTools::ExpandListArgument(const std::string& arg,
+ std::vector<std::string>& newargs,
+ bool emptyArgs)
+{
+ // If argument is empty, it is an empty list.
+ if(!emptyArgs && arg.empty())
+ {
+ return;
+ }
+ // if there are no ; in the name then just copy the current string
+ if(arg.find(';') == std::string::npos)
+ {
+ newargs.push_back(arg);
+ return;
+ }
+ std::string newArg;
+ const char *last = arg.c_str();
+ // Break the string at non-escaped semicolons not nested in [].
+ int squareNesting = 0;
+ for(const char* c = last; *c; ++c)
+ {
+ switch(*c)
+ {
+ case '\\':
+ {
+ // We only want to allow escaping of semicolons. Other
+ // escapes should not be processed here.
+ const char* next = c + 1;
+ if(*next == ';')
+ {
+ newArg.append(last, c - last);
+ // Skip over the escape character
+ last = c = next;
+ }
+ } break;
+ case '[':
+ {
+ ++squareNesting;
+ } break;
+ case ']':
+ {
+ --squareNesting;
+ } break;
+ case ';':
+ {
+ // Break the string here if we are not nested inside square
+ // brackets.
+ if(squareNesting == 0)
+ {
+ newArg.append(last, c - last);
+ // Skip over the semicolon
+ last = c + 1;
+ if ( !newArg.empty() || emptyArgs )
+ {
+ // Add the last argument if the string is not empty.
+ newargs.push_back(newArg);
+ newArg = "";
+ }
+ }
+ } break;
+ default:
+ {
+ // Just append this character.
+ } break;
+ }
+ }
+ newArg.append(last);
+ if ( !newArg.empty() || emptyArgs )
+ {
+ // Add the last argument if the string is not empty.
+ newargs.push_back(newArg);
+ }
+}
+
+bool cmSystemTools::SimpleGlob(const std::string& glob,
+ std::vector<std::string>& files,
+ int type /* = 0 */)
+{
+ files.clear();
+ if ( glob[glob.size()-1] != '*' )
+ {
+ return false;
+ }
+ std::string path = cmSystemTools::GetFilenamePath(glob);
+ std::string ppath = cmSystemTools::GetFilenameName(glob);
+ ppath = ppath.substr(0, ppath.size()-1);
+ if ( path.size() == 0 )
+ {
+ path = "/";
+ }
+
+ bool res = false;
+ cmsys::Directory d;
+ if (d.Load(path.c_str()))
+ {
+ for (unsigned int i = 0; i < d.GetNumberOfFiles(); ++i)
+ {
+ if((std::string(d.GetFile(i)) != ".")
+ && (std::string(d.GetFile(i)) != ".."))
+ {
+ std::string fname = path;
+ if ( path[path.size()-1] != '/' )
+ {
+ fname +="/";
+ }
+ fname += d.GetFile(i);
+ std::string sfname = d.GetFile(i);
+ if ( type > 0 && cmSystemTools::FileIsDirectory(fname.c_str()) )
+ {
+ continue;
+ }
+ if ( type < 0 && !cmSystemTools::FileIsDirectory(fname.c_str()) )
+ {
+ continue;
+ }
+ if ( sfname.size() >= ppath.size() &&
+ sfname.substr(0, ppath.size()) ==
+ ppath )
+ {
+ files.push_back(fname);
+ res = true;
+ }
+ }
+ }
+ }
+ return res;
+}
+
+cmSystemTools::FileFormat cmSystemTools::GetFileFormat(const char* cext)
+{
+ if ( ! cext || *cext == 0 )
+ {
+ return cmSystemTools::NO_FILE_FORMAT;
+ }
+ //std::string ext = cmSystemTools::LowerCase(cext);
+ std::string ext = cext;
+ if ( ext == "c" || ext == ".c" ||
+ ext == "m" || ext == ".m"
+ ) { return cmSystemTools::C_FILE_FORMAT; }
+ if (
+ ext == "C" || ext == ".C" ||
+ ext == "M" || ext == ".M" ||
+ ext == "c++" || ext == ".c++" ||
+ ext == "cc" || ext == ".cc" ||
+ ext == "cpp" || ext == ".cpp" ||
+ ext == "cxx" || ext == ".cxx" ||
+ ext == "mm" || ext == ".mm"
+ ) { return cmSystemTools::CXX_FILE_FORMAT; }
+ if (
+ ext == "f" || ext == ".f" ||
+ ext == "F" || ext == ".F" ||
+ ext == "f77" || ext == ".f77" ||
+ ext == "f90" || ext == ".f90" ||
+ ext == "for" || ext == ".for" ||
+ ext == "f95" || ext == ".f95"
+ ) { return cmSystemTools::FORTRAN_FILE_FORMAT; }
+ if ( ext == "java" || ext == ".java" )
+ { return cmSystemTools::JAVA_FILE_FORMAT; }
+ if (
+ ext == "H" || ext == ".H" ||
+ ext == "h" || ext == ".h" ||
+ ext == "h++" || ext == ".h++" ||
+ ext == "hm" || ext == ".hm" ||
+ ext == "hpp" || ext == ".hpp" ||
+ ext == "hxx" || ext == ".hxx" ||
+ ext == "in" || ext == ".in" ||
+ ext == "txx" || ext == ".txx"
+ ) { return cmSystemTools::HEADER_FILE_FORMAT; }
+ if ( ext == "rc" || ext == ".rc" )
+ { return cmSystemTools::RESOURCE_FILE_FORMAT; }
+ if ( ext == "def" || ext == ".def" )
+ { return cmSystemTools::DEFINITION_FILE_FORMAT; }
+ if ( ext == "lib" || ext == ".lib" ||
+ ext == "a" || ext == ".a")
+ { return cmSystemTools::STATIC_LIBRARY_FILE_FORMAT; }
+ if ( ext == "o" || ext == ".o" ||
+ ext == "obj" || ext == ".obj")
+ { return cmSystemTools::OBJECT_FILE_FORMAT; }
+#ifdef __APPLE__
+ if ( ext == "dylib" || ext == ".dylib" )
+ { return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT; }
+ if ( ext == "so" || ext == ".so" ||
+ ext == "bundle" || ext == ".bundle" )
+ { return cmSystemTools::MODULE_FILE_FORMAT; }
+#else // __APPLE__
+ if ( ext == "so" || ext == ".so" ||
+ ext == "sl" || ext == ".sl" ||
+ ext == "dll" || ext == ".dll" )
+ { return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT; }
+#endif // __APPLE__
+ return cmSystemTools::UNKNOWN_FILE_FORMAT;
+}
+
+bool cmSystemTools::Split(const char* s, std::vector<std::string>& l)
+{
+ std::vector<std::string> temp;
+ bool res = Superclass::Split(s, temp);
+ for(std::vector<std::string>::const_iterator i = temp.begin();
+ i != temp.end(); ++i)
+ {
+ l.push_back(*i);
+ }
+ return res;
+}
+
+std::string cmSystemTools::ConvertToOutputPath(const char* path)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if(s_ForceUnixPaths)
+ {
+ return cmSystemTools::ConvertToUnixOutputPath(path);
+ }
+ return cmSystemTools::ConvertToWindowsOutputPath(path);
+#else
+ return cmSystemTools::ConvertToUnixOutputPath(path);
+#endif
+}
+
+void cmSystemTools::ConvertToOutputSlashes(std::string& path)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if(!s_ForceUnixPaths)
+ {
+ // Convert to windows slashes.
+ std::string::size_type pos = 0;
+ while((pos = path.find('/', pos)) != std::string::npos)
+ {
+ path[pos++] = '\\';
+ }
+ }
+#else
+ static_cast<void>(path);
+#endif
+}
+
+std::string cmSystemTools::ConvertToRunCommandPath(const char* path)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ return cmSystemTools::ConvertToWindowsOutputPath(path);
+#else
+ return cmSystemTools::ConvertToUnixOutputPath(path);
+#endif
+}
+
+bool cmSystemTools::StringEndsWith(const char* str1, const char* str2)
+{
+ if ( !str1 || !str2 || strlen(str1) < strlen(str2) )
+ {
+ return 0;
+ }
+ return !strncmp(str1 + (strlen(str1)-strlen(str2)), str2, strlen(str2));
+}
+
+// compute the relative path from here to there
+std::string cmSystemTools::RelativePath(const char* local, const char* remote)
+{
+ if(!cmSystemTools::FileIsFullPath(local))
+ {
+ cmSystemTools::Error("RelativePath must be passed a full path to local: ",
+ local);
+ }
+ if(!cmSystemTools::FileIsFullPath(remote))
+ {
+ cmSystemTools::Error
+ ("RelativePath must be passed a full path to remote: ", remote);
+ }
+ return cmsys::SystemTools::RelativePath(local, remote);
+}
+
+std::string cmSystemTools::CollapseCombinedPath(std::string const& dir,
+ std::string const& file)
+{
+ if(dir.empty() || dir == ".")
+ {
+ return file;
+ }
+
+ std::vector<std::string> dirComponents;
+ std::vector<std::string> fileComponents;
+ cmSystemTools::SplitPath(dir.c_str(), dirComponents);
+ cmSystemTools::SplitPath(file.c_str(), fileComponents);
+
+ if(fileComponents.empty())
+ {
+ return dir;
+ }
+ if(fileComponents[0] != "")
+ {
+ // File is not a relative path.
+ return file;
+ }
+
+ std::vector<std::string>::iterator i = fileComponents.begin()+1;
+ while(i != fileComponents.end() && *i == ".." && dirComponents.size() > 1)
+ {
+ ++i; // Remove ".." file component.
+ dirComponents.pop_back(); // Remove last dir component.
+ }
+
+ dirComponents.insert(dirComponents.end(), i, fileComponents.end());
+ return cmSystemTools::JoinPath(dirComponents);
+}
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+//----------------------------------------------------------------------
+bool cmSystemTools::UnsetEnv(const char* value)
+{
+#if !defined(HAVE_UNSETENV)
+ std::string var = value;
+ var += "=";
+ return cmSystemTools::PutEnv(var.c_str());
+#else
+ unsetenv(value);
+ return true;
+#endif
+}
+
+//----------------------------------------------------------------------
+std::vector<std::string> cmSystemTools::GetEnvironmentVariables()
+{
+ std::vector<std::string> env;
+ int cc;
+ for ( cc = 0; environ[cc]; ++ cc )
+ {
+ env.push_back(environ[cc]);
+ }
+ return env;
+}
+
+//----------------------------------------------------------------------
+void cmSystemTools::AppendEnv(std::vector<std::string> const& env)
+{
+ for(std::vector<std::string>::const_iterator eit = env.begin();
+ eit != env.end(); ++eit)
+ {
+ cmSystemTools::PutEnv(eit->c_str());
+ }
+}
+
+//----------------------------------------------------------------------
+cmSystemTools::SaveRestoreEnvironment::SaveRestoreEnvironment()
+{
+ this->Env = cmSystemTools::GetEnvironmentVariables();
+}
+
+//----------------------------------------------------------------------
+cmSystemTools::SaveRestoreEnvironment::~SaveRestoreEnvironment()
+{
+ // First clear everything in the current environment:
+ std::vector<std::string> currentEnv = GetEnvironmentVariables();
+ for(std::vector<std::string>::const_iterator
+ eit = currentEnv.begin(); eit != currentEnv.end(); ++eit)
+ {
+ std::string var(*eit);
+
+ std::string::size_type pos = var.find("=");
+ if (pos != std::string::npos)
+ {
+ var = var.substr(0, pos);
+ }
+
+ cmSystemTools::UnsetEnv(var.c_str());
+ }
+
+ // Then put back each entry from the original environment:
+ cmSystemTools::AppendEnv(this->Env);
+}
+#endif
+
+void cmSystemTools::EnableVSConsoleOutput()
+{
+#ifdef _WIN32
+ // Visual Studio 8 2005 (devenv.exe or VCExpress.exe) will not
+ // display output to the console unless this environment variable is
+ // set. We need it to capture the output of these build tools.
+ // Note for future work that one could pass "/out \\.\pipe\NAME" to
+ // either of these executables where NAME is created with
+ // CreateNamedPipe. This would bypass the internal buffering of the
+ // output and allow it to be captured on the fly.
+ cmSystemTools::PutEnv("vsconsoleoutput=1");
+
+# ifdef CMAKE_BUILD_WITH_CMAKE
+ // VS sets an environment variable to tell MS tools like "cl" to report
+ // output through a backdoor pipe instead of stdout/stderr. Unset the
+ // environment variable to close this backdoor for any path of process
+ // invocations that passes through CMake so we can capture the output.
+ cmSystemTools::UnsetEnv("VS_UNICODE_OUTPUT");
+# endif
+#endif
+}
+
+bool cmSystemTools::IsPathToFramework(const char* path)
+{
+ if(cmSystemTools::FileIsFullPath(path))
+ {
+ std::string libname = path;
+ if(libname.find(".framework") == libname.size()+1-sizeof(".framework"))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool cmSystemTools::CreateTar(const char* outFileName,
+ const std::vector<std::string>& files,
+ bool gzip, bool bzip2, bool verbose)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ cmsys::ofstream fout(outFileName, std::ios::out | cmsys_ios_binary);
+ if(!fout)
+ {
+ std::string e = "Cannot open output file \"";
+ e += outFileName;
+ e += "\": ";
+ e += cmSystemTools::GetLastSystemError();
+ cmSystemTools::Error(e.c_str());
+ return false;
+ }
+ cmArchiveWrite a(fout, (gzip? cmArchiveWrite::CompressGZip :
+ (bzip2? cmArchiveWrite::CompressBZip2 :
+ cmArchiveWrite::CompressNone)),
+ cmArchiveWrite::TypeTAR);
+ a.SetVerbose(verbose);
+ for(std::vector<std::string>::const_iterator i = files.begin();
+ i != files.end(); ++i)
+ {
+ std::string path = *i;
+ if(cmSystemTools::FileIsFullPath(path.c_str()))
+ {
+ // Get the relative path to the file.
+ path = cmSystemTools::RelativePath(cwd.c_str(), path.c_str());
+ }
+ if(!a.Add(path))
+ {
+ break;
+ }
+ }
+ if(!a)
+ {
+ cmSystemTools::Error(a.GetError().c_str());
+ return false;
+ }
+ return true;
+#else
+ (void)outFileName;
+ (void)files;
+ (void)gzip;
+ (void)verbose;
+ return false;
+#endif
+}
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+namespace{
+#define BSDTAR_FILESIZE_PRINTF "%lu"
+#define BSDTAR_FILESIZE_TYPE unsigned long
+ void
+ list_item_verbose(FILE *out, struct archive_entry *entry)
+{
+ char tmp[100];
+ size_t w;
+ const char *p;
+ const char *fmt;
+ time_t tim;
+ static time_t now;
+ size_t u_width = 6;
+ size_t gs_width = 13;
+
+ /*
+ * We avoid collecting the entire list in memory at once by
+ * listing things as we see them. However, that also means we can't
+ * just pre-compute the field widths. Instead, we start with guesses
+ * and just widen them as necessary. These numbers are completely
+ * arbitrary.
+ */
+ if (!now)
+ {
+ time(&now);
+ }
+ fprintf(out, "%s %d ",
+ archive_entry_strmode(entry),
+ archive_entry_nlink(entry));
+
+ /* Use uname if it's present, else uid. */
+ p = archive_entry_uname(entry);
+ if ((p == NULL) || (*p == '\0'))
+ {
+ sprintf(tmp, "%lu ",
+ (unsigned long)archive_entry_uid(entry));
+ p = tmp;
+ }
+ w = strlen(p);
+ if (w > u_width)
+ {
+ u_width = w;
+ }
+ fprintf(out, "%-*s ", (int)u_width, p);
+ /* Use gname if it's present, else gid. */
+ p = archive_entry_gname(entry);
+ if (p != NULL && p[0] != '\0')
+ {
+ fprintf(out, "%s", p);
+ w = strlen(p);
+ }
+ else
+ {
+ sprintf(tmp, "%lu",
+ (unsigned long)archive_entry_gid(entry));
+ w = strlen(tmp);
+ fprintf(out, "%s", tmp);
+ }
+
+ /*
+ * Print device number or file size, right-aligned so as to make
+ * total width of group and devnum/filesize fields be gs_width.
+ * If gs_width is too small, grow it.
+ */
+ if (archive_entry_filetype(entry) == AE_IFCHR
+ || archive_entry_filetype(entry) == AE_IFBLK)
+ {
+ sprintf(tmp, "%lu,%lu",
+ (unsigned long)archive_entry_rdevmajor(entry),
+ (unsigned long)archive_entry_rdevminor(entry));
+ }
+ else
+ {
+ /*
+ * Note the use of platform-dependent macros to format
+ * the filesize here. We need the format string and the
+ * corresponding type for the cast.
+ */
+ sprintf(tmp, BSDTAR_FILESIZE_PRINTF,
+ (BSDTAR_FILESIZE_TYPE)archive_entry_size(entry));
+ }
+ if (w + strlen(tmp) >= gs_width)
+ {
+ gs_width = w+strlen(tmp)+1;
+ }
+ fprintf(out, "%*s", (int)(gs_width - w), tmp);
+
+ /* Format the time using 'ls -l' conventions. */
+ tim = archive_entry_mtime(entry);
+#define HALF_YEAR (time_t)365 * 86400 / 2
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Windows' strftime function does not support %e format. */
+#define DAY_FMT "%d"
+#else
+#define DAY_FMT "%e" /* Day number without leading zeros */
+#endif
+ if (tim < now - HALF_YEAR || tim > now + HALF_YEAR)
+ {
+ fmt = DAY_FMT " %b %Y";
+ }
+ else
+ {
+ fmt = DAY_FMT " %b %H:%M";
+ }
+ strftime(tmp, sizeof(tmp), fmt, localtime(&tim));
+ fprintf(out, " %s ", tmp);
+ fprintf(out, "%s", cm_archive_entry_pathname(entry).c_str());
+
+ /* Extra information for links. */
+ if (archive_entry_hardlink(entry)) /* Hard link */
+ {
+ fprintf(out, " link to %s",
+ archive_entry_hardlink(entry));
+ }
+ else if (archive_entry_symlink(entry)) /* Symbolic link */
+ {
+ fprintf(out, " -> %s", archive_entry_symlink(entry));
+ }
+}
+#ifdef __BORLANDC__
+# pragma warn -8066 /* unreachable code */
+#endif
+
+long copy_data(struct archive *ar, struct archive *aw)
+{
+ long r;
+ const void *buff;
+ size_t size;
+#if defined(ARCHIVE_VERSION_NUMBER) && ARCHIVE_VERSION_NUMBER >= 3000000
+ __LA_INT64_T offset;
+#else
+ off_t offset;
+#endif
+
+ for (;;)
+ {
+ r = archive_read_data_block(ar, &buff, &size, &offset);
+ if (r == ARCHIVE_EOF)
+ {
+ return (ARCHIVE_OK);
+ }
+ if (r != ARCHIVE_OK)
+ {
+ return (r);
+ }
+ r = archive_write_data_block(aw, buff, size, offset);
+ if (r != ARCHIVE_OK)
+ {
+ cmSystemTools::Message("archive_write_data_block()",
+ archive_error_string(aw));
+ return (r);
+ }
+ }
+#if !defined(__clang__) && !defined(__HP_aCC)
+ return r; /* this should not happen but it quiets some compilers */
+#endif
+}
+
+bool extract_tar(const char* outFileName, bool verbose,
+ bool extract)
+{
+ struct archive* a = archive_read_new();
+ struct archive *ext = archive_write_disk_new();
+ archive_read_support_compression_all(a);
+ archive_read_support_format_all(a);
+ struct archive_entry *entry;
+ int r = cm_archive_read_open_file(a, outFileName, 10240);
+ if(r)
+ {
+ cmSystemTools::Error("Problem with archive_read_open_file(): ",
+ archive_error_string(a));
+ archive_write_free(ext);
+ archive_read_close(a);
+ return false;
+ }
+ for (;;)
+ {
+ r = archive_read_next_header(a, &entry);
+ if (r == ARCHIVE_EOF)
+ {
+ break;
+ }
+ if (r != ARCHIVE_OK)
+ {
+ cmSystemTools::Error("Problem with archive_read_next_header(): ",
+ archive_error_string(a));
+ break;
+ }
+ if(verbose)
+ {
+ if(extract)
+ {
+ cmSystemTools::Stdout("x ");
+ cmSystemTools::Stdout(cm_archive_entry_pathname(entry).c_str());
+ }
+ else
+ {
+ list_item_verbose(stdout, entry);
+ }
+ cmSystemTools::Stdout("\n");
+ }
+ else if(!extract)
+ {
+ cmSystemTools::Stdout(cm_archive_entry_pathname(entry).c_str());
+ cmSystemTools::Stdout("\n");
+ }
+ if(extract)
+ {
+ r = archive_write_disk_set_options(ext, ARCHIVE_EXTRACT_TIME);
+ if (r != ARCHIVE_OK)
+ {
+ cmSystemTools::Error(
+ "Problem with archive_write_disk_set_options(): ",
+ archive_error_string(ext));
+ break;
+ }
+
+ r = archive_write_header(ext, entry);
+ if (r == ARCHIVE_OK)
+ {
+ copy_data(a, ext);
+ r = archive_write_finish_entry(ext);
+ if (r != ARCHIVE_OK)
+ {
+ cmSystemTools::Error("Problem with archive_write_finish_entry(): ",
+ archive_error_string(ext));
+ break;
+ }
+ }
+#ifdef _WIN32
+ else if(const char* linktext = archive_entry_symlink(entry))
+ {
+ std::cerr << "cmake -E tar: warning: skipping symbolic link \""
+ << cm_archive_entry_pathname(entry)
+ << "\" -> \""
+ << linktext << "\"." << std::endl;
+ }
+#endif
+ else
+ {
+ cmSystemTools::Error("Problem with archive_write_header(): ",
+ archive_error_string(ext));
+ cmSystemTools::Error("Current file: ",
+ cm_archive_entry_pathname(entry).c_str());
+ break;
+ }
+ }
+ }
+ archive_write_free(ext);
+ archive_read_close(a);
+ archive_read_finish(a);
+ return r == ARCHIVE_EOF || r == ARCHIVE_OK;
+}
+}
+#endif
+
+bool cmSystemTools::ExtractTar(const char* outFileName,
+ bool , bool verbose)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ return extract_tar(outFileName, verbose, true);
+#else
+ (void)outFileName;
+ (void)verbose;
+ return false;
+#endif
+}
+
+bool cmSystemTools::ListTar(const char* outFileName,
+ bool ,
+ bool verbose)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ return extract_tar(outFileName, verbose, false);
+#else
+ (void)outFileName;
+ (void)verbose;
+ return false;
+#endif
+}
+
+int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line,
+ double timeout,
+ std::vector<char>& out,
+ std::vector<char>& err)
+{
+ line = "";
+ std::vector<char>::iterator outiter = out.begin();
+ std::vector<char>::iterator erriter = err.begin();
+ while(1)
+ {
+ // Check for a newline in stdout.
+ for(;outiter != out.end(); ++outiter)
+ {
+ if((*outiter == '\r') && ((outiter+1) == out.end()))
+ {
+ break;
+ }
+ else if(*outiter == '\n' || *outiter == '\0')
+ {
+ std::vector<char>::size_type length = outiter-out.begin();
+ if(length > 1 && *(outiter-1) == '\r')
+ {
+ --length;
+ }
+ if(length > 0)
+ {
+ line.append(&out[0], length);
+ }
+ out.erase(out.begin(), outiter+1);
+ return cmsysProcess_Pipe_STDOUT;
+ }
+ }
+
+ // Check for a newline in stderr.
+ for(;erriter != err.end(); ++erriter)
+ {
+ if((*erriter == '\r') && ((erriter+1) == err.end()))
+ {
+ break;
+ }
+ else if(*erriter == '\n' || *erriter == '\0')
+ {
+ std::vector<char>::size_type length = erriter-err.begin();
+ if(length > 1 && *(erriter-1) == '\r')
+ {
+ --length;
+ }
+ if(length > 0)
+ {
+ line.append(&err[0], length);
+ }
+ err.erase(err.begin(), erriter+1);
+ return cmsysProcess_Pipe_STDERR;
+ }
+ }
+
+ // No newlines found. Wait for more data from the process.
+ int length;
+ char* data;
+ int pipe = cmsysProcess_WaitForData(process, &data, &length, &timeout);
+ if(pipe == cmsysProcess_Pipe_Timeout)
+ {
+ // Timeout has been exceeded.
+ return pipe;
+ }
+ else if(pipe == cmsysProcess_Pipe_STDOUT)
+ {
+ // Append to the stdout buffer.
+ std::vector<char>::size_type size = out.size();
+ out.insert(out.end(), data, data+length);
+ outiter = out.begin()+size;
+ }
+ else if(pipe == cmsysProcess_Pipe_STDERR)
+ {
+ // Append to the stderr buffer.
+ std::vector<char>::size_type size = err.size();
+ err.insert(err.end(), data, data+length);
+ erriter = err.begin()+size;
+ }
+ else if(pipe == cmsysProcess_Pipe_None)
+ {
+ // Both stdout and stderr pipes have broken. Return leftover data.
+ if(!out.empty())
+ {
+ line.append(&out[0], outiter-out.begin());
+ out.erase(out.begin(), out.end());
+ return cmsysProcess_Pipe_STDOUT;
+ }
+ else if(!err.empty())
+ {
+ line.append(&err[0], erriter-err.begin());
+ err.erase(err.begin(), err.end());
+ return cmsysProcess_Pipe_STDERR;
+ }
+ else
+ {
+ return cmsysProcess_Pipe_None;
+ }
+ }
+ }
+}
+
+void cmSystemTools::DoNotInheritStdPipes()
+{
+#ifdef _WIN32
+ // Check to see if we are attached to a console
+ // if so, then do not stop the inherited pipes
+ // or stdout and stderr will not show up in dos
+ // shell windows
+ CONSOLE_SCREEN_BUFFER_INFO hOutInfo;
+ HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
+ if(GetConsoleScreenBufferInfo(hOut, &hOutInfo))
+ {
+ return;
+ }
+ {
+ HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
+ DuplicateHandle(GetCurrentProcess(), out,
+ GetCurrentProcess(), &out, 0, FALSE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ SetStdHandle(STD_OUTPUT_HANDLE, out);
+ }
+ {
+ HANDLE out = GetStdHandle(STD_ERROR_HANDLE);
+ DuplicateHandle(GetCurrentProcess(), out,
+ GetCurrentProcess(), &out, 0, FALSE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ SetStdHandle(STD_ERROR_HANDLE, out);
+ }
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::CopyFileTime(const char* fromFile, const char* toFile)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ cmSystemToolsWindowsHandle hFrom =
+ CreateFileW(cmsys::Encoding::ToWide(fromFile).c_str(),
+ GENERIC_READ, FILE_SHARE_READ, 0,
+ OPEN_EXISTING, 0, 0);
+ cmSystemToolsWindowsHandle hTo =
+ CreateFileW(cmsys::Encoding::ToWide(toFile).c_str(),
+ GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
+ if(!hFrom || !hTo)
+ {
+ return false;
+ }
+ FILETIME timeCreation;
+ FILETIME timeLastAccess;
+ FILETIME timeLastWrite;
+ if(!GetFileTime(hFrom, &timeCreation, &timeLastAccess, &timeLastWrite))
+ {
+ return false;
+ }
+ if(!SetFileTime(hTo, &timeCreation, &timeLastAccess, &timeLastWrite))
+ {
+ return false;
+ }
+#else
+ struct stat fromStat;
+ if(stat(fromFile, &fromStat) < 0)
+ {
+ return false;
+ }
+
+ struct utimbuf buf;
+ buf.actime = fromStat.st_atime;
+ buf.modtime = fromStat.st_mtime;
+ if(utime(toFile, &buf) < 0)
+ {
+ return false;
+ }
+#endif
+ return true;
+}
+
+//----------------------------------------------------------------------------
+cmSystemToolsFileTime* cmSystemTools::FileTimeNew()
+{
+ return new cmSystemToolsFileTime;
+}
+
+//----------------------------------------------------------------------------
+void cmSystemTools::FileTimeDelete(cmSystemToolsFileTime* t)
+{
+ delete t;
+}
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::FileTimeGet(const char* fname, cmSystemToolsFileTime* t)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ cmSystemToolsWindowsHandle h =
+ CreateFileW(cmsys::Encoding::ToWide(fname).c_str(),
+ GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
+ if(!h)
+ {
+ return false;
+ }
+ if(!GetFileTime(h, &t->timeCreation, &t->timeLastAccess, &t->timeLastWrite))
+ {
+ return false;
+ }
+#else
+ struct stat st;
+ if(stat(fname, &st) < 0)
+ {
+ return false;
+ }
+ t->timeBuf.actime = st.st_atime;
+ t->timeBuf.modtime = st.st_mtime;
+#endif
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::FileTimeSet(const char* fname, cmSystemToolsFileTime* t)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ cmSystemToolsWindowsHandle h =
+ CreateFileW(cmsys::Encoding::ToWide(fname).c_str(),
+ GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
+ if(!h)
+ {
+ return false;
+ }
+ if(!SetFileTime(h, &t->timeCreation, &t->timeLastAccess, &t->timeLastWrite))
+ {
+ return false;
+ }
+#else
+ if(utime(fname, &t->timeBuf) < 0)
+ {
+ return false;
+ }
+#endif
+ return true;
+}
+
+//----------------------------------------------------------------------------
+#ifdef _WIN32
+# ifndef CRYPT_SILENT
+# define CRYPT_SILENT 0x40 /* Not defined by VS 6 version of header. */
+# endif
+static int WinCryptRandom(void* data, size_t size)
+{
+ int result = 0;
+ HCRYPTPROV hProvider = 0;
+ if(CryptAcquireContextW(&hProvider, 0, 0, PROV_RSA_FULL,
+ CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
+ {
+ result = CryptGenRandom(hProvider, (DWORD)size, (BYTE*)data)? 1:0;
+ CryptReleaseContext(hProvider, 0);
+ }
+ return result;
+}
+#endif
+
+//----------------------------------------------------------------------------
+unsigned int cmSystemTools::RandomSeed()
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ unsigned int seed = 0;
+
+ // Try using a real random source.
+ if(WinCryptRandom(&seed, sizeof(seed)))
+ {
+ return seed;
+ }
+
+ // Fall back to the time and pid.
+ FILETIME ft;
+ GetSystemTimeAsFileTime(&ft);
+ unsigned int t1 = static_cast<unsigned int>(ft.dwHighDateTime);
+ unsigned int t2 = static_cast<unsigned int>(ft.dwLowDateTime);
+ unsigned int pid = static_cast<unsigned int>(GetCurrentProcessId());
+ return t1 ^ t2 ^ pid;
+#else
+ union
+ {
+ unsigned int integer;
+ char bytes[sizeof(unsigned int)];
+ } seed;
+
+ // Try using a real random source.
+ cmsys::ifstream fin("/dev/urandom");
+ if(fin && fin.read(seed.bytes, sizeof(seed)) &&
+ fin.gcount() == sizeof(seed))
+ {
+ return seed.integer;
+ }
+
+ // Fall back to the time and pid.
+ struct timeval t;
+ gettimeofday(&t, 0);
+ unsigned int pid = static_cast<unsigned int>(getpid());
+ unsigned int tv_sec = static_cast<unsigned int>(t.tv_sec);
+ unsigned int tv_usec = static_cast<unsigned int>(t.tv_usec);
+ // Since tv_usec never fills more than 11 bits we shift it to fill
+ // in the slow-changing high-order bits of tv_sec.
+ return tv_sec ^ (tv_usec << 21) ^ pid;
+#endif
+}
+
+//----------------------------------------------------------------------------
+static std::string cmSystemToolsCMakeCommand;
+static std::string cmSystemToolsCTestCommand;
+static std::string cmSystemToolsCPackCommand;
+static std::string cmSystemToolsCMakeCursesCommand;
+static std::string cmSystemToolsCMakeGUICommand;
+static std::string cmSystemToolsCMakeRoot;
+void cmSystemTools::FindCMakeResources(const char* argv0)
+{
+ std::string exe_dir;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ (void)argv0; // ignore this on windows
+ wchar_t modulepath[_MAX_PATH];
+ ::GetModuleFileNameW(NULL, modulepath, sizeof(modulepath));
+ exe_dir =
+ cmSystemTools::GetFilenamePath(cmsys::Encoding::ToNarrow(modulepath));
+#elif defined(__APPLE__)
+ (void)argv0; // ignore this on OS X
+# define CM_EXE_PATH_LOCAL_SIZE 16384
+ char exe_path_local[CM_EXE_PATH_LOCAL_SIZE];
+# if defined(MAC_OS_X_VERSION_10_3) && !defined(MAC_OS_X_VERSION_10_4)
+ unsigned long exe_path_size = CM_EXE_PATH_LOCAL_SIZE;
+# else
+ uint32_t exe_path_size = CM_EXE_PATH_LOCAL_SIZE;
+# endif
+# undef CM_EXE_PATH_LOCAL_SIZE
+ char* exe_path = exe_path_local;
+ if(_NSGetExecutablePath(exe_path, &exe_path_size) < 0)
+ {
+ exe_path = (char*)malloc(exe_path_size);
+ _NSGetExecutablePath(exe_path, &exe_path_size);
+ }
+ exe_dir =
+ cmSystemTools::GetFilenamePath(
+ cmSystemTools::GetRealPath(exe_path));
+ if(exe_path != exe_path_local)
+ {
+ free(exe_path);
+ }
+ if(cmSystemTools::GetFilenameName(exe_dir) == "MacOS")
+ {
+ // The executable is inside an application bundle.
+ // Look for ../bin (install tree) and then fall back to
+ // ../../../bin (build tree).
+ exe_dir = cmSystemTools::GetFilenamePath(exe_dir);
+ if(cmSystemTools::FileExists((exe_dir+"/bin/cmake").c_str()))
+ {
+ exe_dir += "/bin";
+ }
+ else
+ {
+ exe_dir = cmSystemTools::GetFilenamePath(exe_dir);
+ exe_dir = cmSystemTools::GetFilenamePath(exe_dir);
+ }
+ }
+#else
+ std::string errorMsg;
+ std::string exe;
+ if(cmSystemTools::FindProgramPath(argv0, exe, errorMsg))
+ {
+ // remove symlinks
+ exe = cmSystemTools::GetRealPath(exe.c_str());
+ exe_dir =
+ cmSystemTools::GetFilenamePath(exe);
+ }
+ else
+ {
+ // ???
+ }
+#endif
+ cmSystemToolsCMakeCommand = exe_dir;
+ cmSystemToolsCMakeCommand += "/cmake";
+ cmSystemToolsCMakeCommand += cmSystemTools::GetExecutableExtension();
+#ifndef CMAKE_BUILD_WITH_CMAKE
+ // The bootstrap cmake does not provide the other tools,
+ // so use the directory where they are about to be built.
+ exe_dir = CMAKE_BOOTSTRAP_BINARY_DIR "/bin";
+#endif
+ cmSystemToolsCTestCommand = exe_dir;
+ cmSystemToolsCTestCommand += "/ctest";
+ cmSystemToolsCTestCommand += cmSystemTools::GetExecutableExtension();
+ cmSystemToolsCPackCommand = exe_dir;
+ cmSystemToolsCPackCommand += "/cpack";
+ cmSystemToolsCPackCommand += cmSystemTools::GetExecutableExtension();
+ cmSystemToolsCMakeGUICommand = exe_dir;
+ cmSystemToolsCMakeGUICommand += "/cmake-gui";
+ cmSystemToolsCMakeGUICommand += cmSystemTools::GetExecutableExtension();
+ if(!cmSystemTools::FileExists(cmSystemToolsCMakeGUICommand.c_str()))
+ {
+ cmSystemToolsCMakeGUICommand = "";
+ }
+ cmSystemToolsCMakeCursesCommand = exe_dir;
+ cmSystemToolsCMakeCursesCommand += "/ccmake";
+ cmSystemToolsCMakeCursesCommand += cmSystemTools::GetExecutableExtension();
+ if(!cmSystemTools::FileExists(cmSystemToolsCMakeCursesCommand.c_str()))
+ {
+ cmSystemToolsCMakeCursesCommand = "";
+ }
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ // Install tree has "<prefix>/bin/cmake" and "<prefix><CMAKE_DATA_DIR>".
+ std::string dir = cmSystemTools::GetFilenamePath(exe_dir);
+ cmSystemToolsCMakeRoot = dir + CMAKE_DATA_DIR;
+ if(!cmSystemTools::FileExists(
+ (cmSystemToolsCMakeRoot+"/Modules/CMake.cmake").c_str()))
+ {
+ // Build tree has "<build>/bin[/<config>]/cmake" and
+ // "<build>/CMakeFiles/CMakeSourceDir.txt".
+ std::string src_dir_txt = dir + "/CMakeFiles/CMakeSourceDir.txt";
+ cmsys::ifstream fin(src_dir_txt.c_str());
+ std::string src_dir;
+ if(fin && cmSystemTools::GetLineFromStream(fin, src_dir) &&
+ cmSystemTools::FileIsDirectory(src_dir.c_str()))
+ {
+ cmSystemToolsCMakeRoot = src_dir;
+ }
+ else
+ {
+ dir = cmSystemTools::GetFilenamePath(dir);
+ src_dir_txt = dir + "/CMakeFiles/CMakeSourceDir.txt";
+ cmsys::ifstream fin2(src_dir_txt.c_str());
+ if(fin2 && cmSystemTools::GetLineFromStream(fin2, src_dir) &&
+ cmSystemTools::FileIsDirectory(src_dir.c_str()))
+ {
+ cmSystemToolsCMakeRoot = src_dir;
+ }
+ }
+ }
+#else
+ // Bootstrap build knows its source.
+ cmSystemToolsCMakeRoot = CMAKE_BOOTSTRAP_SOURCE_DIR;
+#endif
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSystemTools::GetCMakeCommand()
+{
+ return cmSystemToolsCMakeCommand;
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSystemTools::GetCTestCommand()
+{
+ return cmSystemToolsCTestCommand;
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSystemTools::GetCPackCommand()
+{
+ return cmSystemToolsCPackCommand;
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSystemTools::GetCMakeCursesCommand()
+{
+ return cmSystemToolsCMakeCursesCommand;
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSystemTools::GetCMakeGUICommand()
+{
+ return cmSystemToolsCMakeGUICommand;
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSystemTools::GetCMakeRoot()
+{
+ return cmSystemToolsCMakeRoot;
+}
+
+//----------------------------------------------------------------------------
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+void cmSystemTools::MakefileColorEcho(int color, const char* message,
+ bool newline, bool enabled)
+{
+ // On some platforms (an MSYS prompt) cmsysTerminal may not be able
+ // to determine whether the stream is displayed on a tty. In this
+ // case it assumes no unless we tell it otherwise. Since we want
+ // color messages to be displayed for users we will assume yes.
+ // However, we can test for some situations when the answer is most
+ // likely no.
+ int assumeTTY = cmsysTerminal_Color_AssumeTTY;
+ if(cmSystemTools::GetEnv("DART_TEST_FROM_DART") ||
+ cmSystemTools::GetEnv("DASHBOARD_TEST_FROM_CTEST") ||
+ cmSystemTools::GetEnv("CTEST_INTERACTIVE_DEBUG_MODE"))
+ {
+ // Avoid printing color escapes during dashboard builds.
+ assumeTTY = 0;
+ }
+
+ if(enabled)
+ {
+ cmsysTerminal_cfprintf(color | assumeTTY, stdout, "%s%s",
+ message, newline? "\n" : "");
+ }
+ else
+ {
+ // Color is disabled. Print without color.
+ fprintf(stdout, "%s%s", message, newline? "\n" : "");
+ }
+}
+#endif
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::GuessLibrarySOName(std::string const& fullPath,
+ std::string& soname)
+{
+ // For ELF shared libraries use a real parser to get the correct
+ // soname.
+#if defined(CMAKE_USE_ELF_PARSER)
+ cmELF elf(fullPath.c_str());
+ if(elf)
+ {
+ return elf.GetSOName(soname);
+ }
+#endif
+
+ // If the file is not a symlink we have no guess for its soname.
+ if(!cmSystemTools::FileIsSymlink(fullPath.c_str()))
+ {
+ return false;
+ }
+ if(!cmSystemTools::ReadSymlink(fullPath.c_str(), soname))
+ {
+ return false;
+ }
+
+ // If the symlink has a path component we have no guess for the soname.
+ if(!cmSystemTools::GetFilenamePath(soname).empty())
+ {
+ return false;
+ }
+
+ // If the symlink points at an extended version of the same name
+ // assume it is the soname.
+ std::string name = cmSystemTools::GetFilenameName(fullPath);
+ if(soname.length() > name.length() &&
+ soname.substr(0, name.length()) == name)
+ {
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::GuessLibraryInstallName(std::string const& fullPath,
+ std::string& soname)
+{
+ std::vector<std::string> cmds;
+ cmds.push_back("otool");
+ cmds.push_back("-D");
+ cmds.push_back(fullPath);
+
+ std::string output;
+ if(!RunSingleCommand(cmds, &output, 0, 0, OUTPUT_NONE))
+ {
+ cmds.insert(cmds.begin(), "-r");
+ cmds.insert(cmds.begin(), "xcrun");
+ if(!RunSingleCommand(cmds, &output, 0, 0, OUTPUT_NONE))
+ {
+ return false;
+ }
+ }
+
+ std::vector<std::string> strs = cmSystemTools::tokenize(output, "\n");
+ // otool returns extra lines reporting multiple install names
+ // in case the binary is multi-arch and none of the architectures
+ // is native (e.g. i386;ppc on x86_64)
+ if(strs.size() >= 2)
+ {
+ soname = strs[1];
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+#if defined(CMAKE_USE_ELF_PARSER)
+std::string::size_type cmSystemToolsFindRPath(std::string const& have,
+ std::string const& want)
+{
+ // Search for the desired rpath.
+ std::string::size_type pos = have.find(want);
+
+ // If the path is not present we are done.
+ if(pos == std::string::npos)
+ {
+ return pos;
+ }
+
+ // Build a regex to match a properly separated path instance.
+ std::string regex_str = "(^|:)(";
+ for(std::string::const_iterator i = want.begin(); i != want.end(); ++i)
+ {
+ int ch = *i;
+ if(!(('a' <= ch && ch <= 'z') ||
+ ('A' <= ch && ch <= 'Z') ||
+ ('0' <= ch && ch <= '9')))
+ {
+ // Escape the non-alphanumeric character.
+ regex_str += "\\";
+ }
+ // Store the character.
+ regex_str.append(1, static_cast<char>(ch));
+ }
+ regex_str += ")(:|$)";
+
+ // Look for the separated path.
+ cmsys::RegularExpression regex(regex_str.c_str());
+ if(regex.find(have))
+ {
+ // Return the position of the path portion.
+ return regex.start(2);
+ }
+ else
+ {
+ // The desired rpath was not found.
+ return std::string::npos;
+ }
+}
+#endif
+
+#if defined(CMAKE_USE_ELF_PARSER)
+struct cmSystemToolsRPathInfo
+{
+ unsigned long Position;
+ unsigned long Size;
+ std::string Name;
+ std::string Value;
+};
+#endif
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::ChangeRPath(std::string const& file,
+ std::string const& oldRPath,
+ std::string const& newRPath,
+ std::string* emsg,
+ bool* changed)
+{
+#if defined(CMAKE_USE_ELF_PARSER)
+ if(changed)
+ {
+ *changed = false;
+ }
+ int rp_count = 0;
+ cmSystemToolsRPathInfo rp[2];
+ {
+ // Parse the ELF binary.
+ cmELF elf(file.c_str());
+
+ // Get the RPATH and RUNPATH entries from it.
+ int se_count = 0;
+ cmELF::StringEntry const* se[2] = {0, 0};
+ const char* se_name[2] = {0, 0};
+ if(cmELF::StringEntry const* se_rpath = elf.GetRPath())
+ {
+ se[se_count] = se_rpath;
+ se_name[se_count] = "RPATH";
+ ++se_count;
+ }
+ if(cmELF::StringEntry const* se_runpath = elf.GetRunPath())
+ {
+ se[se_count] = se_runpath;
+ se_name[se_count] = "RUNPATH";
+ ++se_count;
+ }
+ if(se_count == 0)
+ {
+ if(newRPath.empty())
+ {
+ // The new rpath is empty and there is no rpath anyway so it is
+ // okay.
+ return true;
+ }
+ else
+ {
+ if(emsg)
+ {
+ *emsg = "No valid ELF RPATH or RUNPATH entry exists in the file; ";
+ *emsg += elf.GetErrorMessage();
+ }
+ return false;
+ }
+ }
+
+ for(int i=0; i < se_count; ++i)
+ {
+ // If both RPATH and RUNPATH refer to the same string literal it
+ // needs to be changed only once.
+ if(rp_count && rp[0].Position == se[i]->Position)
+ {
+ continue;
+ }
+
+ // Make sure the current rpath contains the old rpath.
+ std::string::size_type pos =
+ cmSystemToolsFindRPath(se[i]->Value, oldRPath);
+ if(pos == std::string::npos)
+ {
+ // If it contains the new rpath instead then it is okay.
+ if(cmSystemToolsFindRPath(se[i]->Value, newRPath) != std::string::npos)
+ {
+ continue;
+ }
+ if(emsg)
+ {
+ cmOStringStream e;
+ e << "The current " << se_name[i] << " is:\n"
+ << " " << se[i]->Value << "\n"
+ << "which does not contain:\n"
+ << " " << oldRPath << "\n"
+ << "as was expected.";
+ *emsg = e.str();
+ }
+ return false;
+ }
+
+ // Store information about the entry in the file.
+ rp[rp_count].Position = se[i]->Position;
+ rp[rp_count].Size = se[i]->Size;
+ rp[rp_count].Name = se_name[i];
+
+ // 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 += newRPath;
+ rp[rp_count].Value += se[i]->Value.substr(pos+oldRPath.length(),
+ oldRPath.npos);
+
+ // 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)
+ {
+ if(emsg)
+ {
+ *emsg = "The replacement path is too long for the ";
+ *emsg += se_name[i];
+ *emsg += " entry.";
+ }
+ return false;
+ }
+
+ // This entry is ready for update.
+ ++rp_count;
+ }
+ }
+
+ // If no runtime path needs to be changed, we are done.
+ if(rp_count == 0)
+ {
+ return true;
+ }
+
+ {
+ // Open the file for update.
+ cmsys::ofstream f(file.c_str(),
+ std::ios::in | std::ios::out | std::ios::binary);
+ if(!f)
+ {
+ if(emsg)
+ {
+ *emsg = "Error opening file for update.";
+ }
+ return false;
+ }
+
+ // Store the new RPATH and RUNPATH strings.
+ for(int i=0; i < rp_count; ++i)
+ {
+ // Seek to the RPATH position.
+ if(!f.seekp(rp[i].Position))
+ {
+ if(emsg)
+ {
+ *emsg = "Error seeking to ";
+ *emsg += rp[i].Name;
+ *emsg += " position.";
+ }
+ return false;
+ }
+
+ // Write the new rpath. Follow it with enough null terminators to
+ // fill the string table entry.
+ f << rp[i].Value;
+ for(unsigned long j=rp[i].Value.length(); j < rp[i].Size; ++j)
+ {
+ f << '\0';
+ }
+
+ // Make sure it wrote correctly.
+ if(!f)
+ {
+ if(emsg)
+ {
+ *emsg = "Error writing the new ";
+ *emsg += rp[i].Name;
+ *emsg += " string to the file.";
+ }
+ return false;
+ }
+ }
+ }
+
+ // Everything was updated successfully.
+ if(changed)
+ {
+ *changed = true;
+ }
+ return true;
+#else
+ (void)file;
+ (void)oldRPath;
+ (void)newRPath;
+ (void)emsg;
+ (void)changed;
+ return false;
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op,
+ const char* lhss, const char* rhss)
+{
+ // Parse out up to 8 components.
+ unsigned int lhs[8] = {0,0,0,0,0,0,0,0};
+ unsigned int rhs[8] = {0,0,0,0,0,0,0,0};
+ sscanf(lhss, "%u.%u.%u.%u.%u.%u.%u.%u",
+ &lhs[0], &lhs[1], &lhs[2], &lhs[3],
+ &lhs[4], &lhs[5], &lhs[6], &lhs[7]);
+ sscanf(rhss, "%u.%u.%u.%u.%u.%u.%u.%u",
+ &rhs[0], &rhs[1], &rhs[2], &rhs[3],
+ &rhs[4], &rhs[5], &rhs[6], &rhs[7]);
+
+ // Do component-wise comparison.
+ for(unsigned int i=0; i < 8; ++i)
+ {
+ if(lhs[i] < rhs[i])
+ {
+ // lhs < rhs, so true if operation is LESS
+ return op == cmSystemTools::OP_LESS;
+ }
+ else if(lhs[i] > rhs[i])
+ {
+ // lhs > rhs, so true if operation is GREATER
+ return op == cmSystemTools::OP_GREATER;
+ }
+ }
+ // lhs == rhs, so true if operation is EQUAL
+ return op == cmSystemTools::OP_EQUAL;
+}
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
+ bool* removed)
+{
+#if defined(CMAKE_USE_ELF_PARSER)
+ if(removed)
+ {
+ *removed = false;
+ }
+ int zeroCount = 0;
+ unsigned long zeroPosition[2] = {0,0};
+ unsigned long zeroSize[2] = {0,0};
+ unsigned long bytesBegin = 0;
+ std::vector<char> bytes;
+ {
+ // Parse the ELF binary.
+ cmELF elf(file.c_str());
+
+ // Get the RPATH and RUNPATH entries from it and sort them by index
+ // in the dynamic section header.
+ int se_count = 0;
+ cmELF::StringEntry const* se[2] = {0, 0};
+ if(cmELF::StringEntry const* se_rpath = elf.GetRPath())
+ {
+ se[se_count++] = se_rpath;
+ }
+ if(cmELF::StringEntry const* se_runpath = elf.GetRunPath())
+ {
+ se[se_count++] = se_runpath;
+ }
+ if(se_count == 0)
+ {
+ // There is no RPATH or RUNPATH anyway.
+ return true;
+ }
+ if(se_count == 2 && se[1]->IndexInSection < se[0]->IndexInSection)
+ {
+ cmsys_stl::swap(se[0], se[1]);
+ }
+
+ // Get the size of the dynamic section header.
+ unsigned int count = elf.GetDynamicEntryCount();
+ if(count == 0)
+ {
+ // This should happen only for invalid ELF files where a DT_NULL
+ // appears before the end of the table.
+ if(emsg)
+ {
+ *emsg = "DYNAMIC section contains a DT_NULL before the end.";
+ }
+ return false;
+ }
+
+ // Save information about the string entries to be zeroed.
+ zeroCount = se_count;
+ for(int i=0; i < se_count; ++i)
+ {
+ zeroPosition[i] = se[i]->Position;
+ zeroSize[i] = se[i]->Size;
+ }
+
+ // Get the range of file positions corresponding to each entry and
+ // the rest of the table after them.
+ unsigned long entryBegin[3] = {0,0,0};
+ unsigned long entryEnd[2] = {0,0};
+ for(int i=0; i < se_count; ++i)
+ {
+ entryBegin[i] = elf.GetDynamicEntryPosition(se[i]->IndexInSection);
+ entryEnd[i] = elf.GetDynamicEntryPosition(se[i]->IndexInSection+1);
+ }
+ entryBegin[se_count] = elf.GetDynamicEntryPosition(count);
+
+ // The data are to be written over the old table entries starting at
+ // the first one being removed.
+ bytesBegin = entryBegin[0];
+ unsigned long bytesEnd = entryBegin[se_count];
+
+ // Allocate a buffer to hold the part of the file to be written.
+ // Initialize it with zeros.
+ bytes.resize(bytesEnd - bytesBegin, 0);
+
+ // Read the part of the DYNAMIC section header that will move.
+ // The remainder of the buffer will be left with zeros which
+ // represent a DT_NULL entry.
+ char* data = &bytes[0];
+ for(int i=0; i < se_count; ++i)
+ {
+ // Read data between the entries being removed.
+ unsigned long sz = entryBegin[i+1] - entryEnd[i];
+ if(sz > 0 && !elf.ReadBytes(entryEnd[i], sz, data))
+ {
+ if(emsg)
+ {
+ *emsg = "Failed to read DYNAMIC section header.";
+ }
+ return false;
+ }
+ data += sz;
+ }
+ }
+
+ // Open the file for update.
+ cmsys::ofstream f(file.c_str(),
+ std::ios::in | std::ios::out | std::ios::binary);
+ if(!f)
+ {
+ if(emsg)
+ {
+ *emsg = "Error opening file for update.";
+ }
+ return false;
+ }
+
+ // Write the new DYNAMIC table header.
+ if(!f.seekp(bytesBegin))
+ {
+ if(emsg)
+ {
+ *emsg = "Error seeking to DYNAMIC table header for RPATH.";
+ }
+ return false;
+ }
+ if(!f.write(&bytes[0], bytes.size()))
+ {
+ if(emsg)
+ {
+ *emsg = "Error replacing DYNAMIC table header.";
+ }
+ return false;
+ }
+
+ // Fill the RPATH and RUNPATH strings with zero bytes.
+ for(int i=0; i < zeroCount; ++i)
+ {
+ if(!f.seekp(zeroPosition[i]))
+ {
+ if(emsg)
+ {
+ *emsg = "Error seeking to RPATH position.";
+ }
+ return false;
+ }
+ for(unsigned long j=0; j < zeroSize[i]; ++j)
+ {
+ f << '\0';
+ }
+ if(!f)
+ {
+ if(emsg)
+ {
+ *emsg = "Error writing the empty rpath string to the file.";
+ }
+ return false;
+ }
+ }
+
+ // Everything was updated successfully.
+ if(removed)
+ {
+ *removed = true;
+ }
+ return true;
+#else
+ (void)file;
+ (void)emsg;
+ (void)removed;
+ return false;
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::CheckRPath(std::string const& file,
+ std::string const& newRPath)
+{
+#if defined(CMAKE_USE_ELF_PARSER)
+ // Parse the ELF binary.
+ cmELF elf(file.c_str());
+
+ // Get the RPATH or RUNPATH entry from it.
+ cmELF::StringEntry const* se = elf.GetRPath();
+ if(!se)
+ {
+ se = elf.GetRunPath();
+ }
+
+ // Make sure the current rpath contains the new rpath.
+ if(newRPath.empty())
+ {
+ if(!se)
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if(se &&
+ cmSystemToolsFindRPath(se->Value, newRPath) != std::string::npos)
+ {
+ return true;
+ }
+ }
+ return false;
+#else
+ (void)file;
+ (void)newRPath;
+ return false;
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::RepeatedRemoveDirectory(const char* dir)
+{
+ // Windows sometimes locks files temporarily so try a few times.
+ for(int i = 0; i < 10; ++i)
+ {
+ if(cmSystemTools::RemoveADirectory(dir))
+ {
+ return true;
+ }
+ cmSystemTools::Delay(100);
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string> cmSystemTools::tokenize(const std::string& str,
+ const std::string& sep)
+{
+ std::vector<std::string> tokens;
+ std::string::size_type tokend = 0;
+
+ do
+ {
+ std::string::size_type tokstart=str.find_first_not_of(sep, tokend);
+ if (tokstart==std::string::npos)
+ {
+ break; // no more tokens
+ }
+ tokend=str.find_first_of(sep,tokstart);
+ if (tokend==std::string::npos)
+ {
+ tokens.push_back(str.substr(tokstart));
+ }
+ else
+ {
+ tokens.push_back(str.substr(tokstart,tokend-tokstart));
+ }
+ } while (tokend!=std::string::npos);
+
+ if (tokens.empty())
+ {
+ tokens.push_back("");
+ }
+ return tokens;
+}
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
new file mode 100644
index 0000000000..4455dd1d8c
--- /dev/null
+++ b/Source/cmSystemTools.h
@@ -0,0 +1,486 @@
+/*============================================================================
+ 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 cmSystemTools_h
+#define cmSystemTools_h
+
+#include "cmStandardIncludes.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Process.h>
+
+class cmSystemToolsFileTime;
+
+/** \class cmSystemTools
+ * \brief A collection of useful functions for CMake.
+ *
+ * cmSystemTools is a class that provides helper functions
+ * for the CMake build system.
+ */
+class cmSystemTools: public cmsys::SystemTools
+{
+public:
+ typedef cmsys::SystemTools Superclass;
+
+ /** Expand out any arguments in the vector that have ; separated
+ * strings into multiple arguments. A new vector is created
+ * containing the expanded versions of all arguments in argsIn.
+ */
+ static void ExpandList(std::vector<std::string> const& argsIn,
+ std::vector<std::string>& argsOut);
+ static void ExpandListArgument(const std::string& arg,
+ std::vector<std::string>& argsOut,
+ bool emptyArgs=false);
+
+ /**
+ * Look for and replace registry values in a string
+ */
+ static void ExpandRegistryValues(std::string& source,
+ KeyWOW64 view = KeyWOW64_Default);
+
+ ///! Escape quotes in a string.
+ static std::string EscapeQuotes(const std::string& str);
+
+ /** Map help document name to file name. */
+ static std::string HelpFileName(std::string);
+
+ /**
+ * Returns a string that has whitespace removed from the start and the end.
+ */
+ static std::string TrimWhitespace(const std::string& s);
+
+ typedef void (*MessageCallback)(const char*, const char*, bool&, void*);
+ /**
+ * Set the function used by GUIs to display error messages
+ * Function gets passed: message as a const char*,
+ * title as a const char*, and a reference to bool that when
+ * set to false, will disable furthur messages (cancel).
+ */
+ static void SetMessageCallback(MessageCallback f, void* clientData=0);
+
+ /**
+ * Display an error message.
+ */
+ static void Error(const char* m, const char* m2=0,
+ const char* m3=0, const char* m4=0);
+
+ /**
+ * Display a message.
+ */
+ static void Message(const char* m, const char* title=0);
+
+ typedef void (*OutputCallback)(const char*, size_t length, void*);
+
+ ///! Send a string to stdout
+ static void Stdout(const char* s);
+ static void Stdout(const char* s, size_t length);
+ static void SetStdoutCallback(OutputCallback, void* clientData=0);
+
+ ///! Send a string to stderr
+ static void Stderr(const char* s);
+ static void Stderr(const char* s, size_t length);
+ static void SetStderrCallback(OutputCallback, void* clientData=0);
+
+
+ typedef bool (*InterruptCallback)(void*);
+ static void SetInterruptCallback(InterruptCallback f, void* clientData=0);
+ static bool GetInterruptFlag();
+
+ ///! Return true if there was an error at any point.
+ static bool GetErrorOccuredFlag()
+ {
+ return cmSystemTools::s_ErrorOccured ||
+ cmSystemTools::s_FatalErrorOccured ||
+ GetInterruptFlag();
+ }
+ ///! If this is set to true, cmake stops processing commands.
+ static void SetFatalErrorOccured()
+ {
+ cmSystemTools::s_FatalErrorOccured = true;
+ }
+ static void SetErrorOccured()
+ {
+ cmSystemTools::s_ErrorOccured = true;
+ }
+ ///! Return true if there was an error at any point.
+ static bool GetFatalErrorOccured()
+ {
+ return cmSystemTools::s_FatalErrorOccured || GetInterruptFlag();
+ }
+
+ ///! Set the error occured flag and fatal error back to false
+ static void ResetErrorOccuredFlag()
+ {
+ cmSystemTools::s_FatalErrorOccured = false;
+ cmSystemTools::s_ErrorOccured = false;
+ }
+
+ /**
+ * Does a string indicates that CMake/CPack/CTest internally
+ * forced this value. This is not the same as On, but this
+ * may be considered as "internally switched on".
+ */
+ static bool IsInternallyOn(const char* val);
+ /**
+ * does a string indicate a true or on value ? This is not the same
+ * as ifdef.
+ */
+ static bool IsOn(const char* val);
+
+ /**
+ * does a string indicate a false or off value ? Note that this is
+ * not the same as !IsOn(...) because there are a number of
+ * ambiguous values such as "/usr/local/bin" a path will result in
+ * IsON and IsOff both returning false. Note that the special path
+ * NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true.
+ */
+ static bool IsOff(const char* val);
+
+ ///! Return true if value is NOTFOUND or ends in -NOTFOUND.
+ static bool IsNOTFOUND(const char* value);
+ ///! Return true if the path is a framework
+ static bool IsPathToFramework(const char* value);
+
+ static bool DoesFileExistWithExtensions(
+ const char *name,
+ const std::vector<std::string>& sourceExts);
+
+ /**
+ * Check if the given file exists in one of the parent directory of the
+ * given file or directory and if it does, return the name of the file.
+ * Toplevel specifies the top-most directory to where it will look.
+ */
+ static std::string FileExistsInParentDirectories(const char* fname,
+ const char* directory, const char* toplevel);
+
+ static void Glob(const std::string& directory, const std::string& regexp,
+ std::vector<std::string>& files);
+ static void GlobDirs(const std::string& fullPath,
+ std::vector<std::string>& files);
+
+ /**
+ * Try to find a list of files that match the "simple" globbing
+ * expression. At this point in time the globbing expressions have
+ * to be in form: /directory/partial_file_name*. The * character has
+ * to be at the end of the string and it does not support ?
+ * []... The optional argument type specifies what kind of files you
+ * want to find. 0 means all files, -1 means directories, 1 means
+ * files only. This method returns true if search was succesfull.
+ */
+ static bool SimpleGlob(const std::string& glob,
+ std::vector<std::string>& files,
+ int type = 0);
+
+ ///! Copy a file.
+ static bool cmCopyFile(const char* source, const char* destination);
+ static bool CopyFileIfDifferent(const char* source,
+ const char* destination);
+
+ /** Rename a file or directory within a single disk volume (atomic
+ if possible). */
+ static bool RenameFile(const char* oldname, const char* newname);
+
+ ///! Compute the md5sum of a file
+ static bool ComputeFileMD5(const std::string& source, char* md5out);
+
+ /** Compute the md5sum of a string. */
+ static std::string ComputeStringMD5(const std::string& input);
+
+ /**
+ * Run a single executable command
+ *
+ * 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
+ * it was received. OUTPUT_PASSTHROUGH passes through the original handles.
+ *
+ * If timeout is specified, the command will be terminated after
+ * timeout expires. Timeout is specified in seconds.
+ *
+ * Argument retVal should be a pointer to the location where the
+ * exit code will be stored. If the retVal is not specified and
+ * the program exits with a code other than 0, then the this
+ * function will return false.
+ *
+ * If the command has spaces in the path the caller MUST call
+ * cmSystemTools::ConvertToRunCommandPath on the command before passing
+ * it into this function or it will not work. The command must be correctly
+ * escaped for this to with spaces.
+ */
+ enum OutputOption
+ {
+ OUTPUT_NONE = 0,
+ OUTPUT_MERGE,
+ OUTPUT_NORMAL,
+ OUTPUT_PASSTHROUGH
+ };
+ static bool RunSingleCommand(const char* command, std::string* output = 0,
+ int* retVal = 0, const char* dir = 0,
+ OutputOption outputflag = OUTPUT_MERGE,
+ double timeout = 0.0);
+ /**
+ * In this version of RunSingleCommand, command[0] should be
+ * the command to run, and each argument to the command should
+ * be in comand[1]...command[command.size()]
+ */
+ static bool RunSingleCommand(std::vector<std::string> const& command,
+ std::string* output = 0,
+ int* retVal = 0, const char* dir = 0,
+ OutputOption outputflag = OUTPUT_MERGE,
+ double timeout = 0.0);
+
+ static std::string PrintSingleCommand(std::vector<std::string> const&);
+
+ /**
+ * Parse arguments out of a single string command
+ */
+ static std::vector<std::string> ParseArguments(const char* command);
+
+ /** Parse arguments out of a windows command line string. */
+ static void ParseWindowsCommandLine(const char* command,
+ std::vector<std::string>& args);
+
+ /** Parse arguments out of a unix command line string. */
+ static void ParseUnixCommandLine(const char* command,
+ std::vector<std::string>& args);
+
+ /** Compute an escaped version of the given argument for use in a
+ windows shell. See kwsys/System.h.in for details. */
+ static std::string EscapeWindowsShellArgument(const char* arg,
+ int shell_flags);
+
+ static void EnableMessages() { s_DisableMessages = false; }
+ static void DisableMessages() { s_DisableMessages = true; }
+ static void DisableRunCommandOutput() {s_DisableRunCommandOutput = true; }
+ static void EnableRunCommandOutput() {s_DisableRunCommandOutput = false; }
+ static bool GetRunCommandOutput() { return s_DisableRunCommandOutput; }
+
+ /**
+ * Some constants for different file formats.
+ */
+ enum FileFormat {
+ NO_FILE_FORMAT = 0,
+ C_FILE_FORMAT,
+ CXX_FILE_FORMAT,
+ FORTRAN_FILE_FORMAT,
+ JAVA_FILE_FORMAT,
+ HEADER_FILE_FORMAT,
+ RESOURCE_FILE_FORMAT,
+ DEFINITION_FILE_FORMAT,
+ STATIC_LIBRARY_FILE_FORMAT,
+ SHARED_LIBRARY_FILE_FORMAT,
+ MODULE_FILE_FORMAT,
+ OBJECT_FILE_FORMAT,
+ UNKNOWN_FILE_FORMAT
+ };
+
+ enum CompareOp {
+ OP_LESS,
+ OP_GREATER,
+ OP_EQUAL
+ };
+
+ /**
+ * Compare versions
+ */
+ static bool VersionCompare(CompareOp op, const char* lhs, const char* rhs);
+
+ /**
+ * Determine the file type based on the extension
+ */
+ static FileFormat GetFileFormat(const char* ext);
+
+ /** Windows if this is true, the CreateProcess in RunCommand will
+ * not show new consol windows when running programs.
+ */
+ static void SetRunCommandHideConsole(bool v){s_RunCommandHideConsole = v;}
+ static bool GetRunCommandHideConsole(){ return s_RunCommandHideConsole;}
+ /** Call cmSystemTools::Error with the message m, plus the
+ * result of strerror(errno)
+ */
+ static void ReportLastSystemError(const char* m);
+
+ /** a general output handler for cmsysProcess */
+ static int WaitForLine(cmsysProcess* process, std::string& line,
+ double timeout,
+ std::vector<char>& out,
+ std::vector<char>& err);
+
+ /** Split a string on its newlines into multiple lines. Returns
+ false only if the last line stored had no newline. */
+ static bool Split(const char* s, std::vector<std::string>& l);
+ static void SetForceUnixPaths(bool v)
+ {
+ s_ForceUnixPaths = v;
+ }
+ static bool GetForceUnixPaths()
+ {
+ return s_ForceUnixPaths;
+ }
+
+ // ConvertToOutputPath use s_ForceUnixPaths
+ static std::string ConvertToOutputPath(const char* path);
+ static void ConvertToOutputSlashes(std::string& path);
+
+ // ConvertToRunCommandPath does not use s_ForceUnixPaths and should
+ // be used when RunCommand is called from cmake, because the
+ // running cmake needs paths to be in its format
+ static std::string ConvertToRunCommandPath(const char* path);
+ //! Check if the first string ends with the second one.
+ static bool StringEndsWith(const char* str1, const char* str2);
+
+ /** compute the relative path from local to remote. local must
+ be a directory. remote can be a file or a directory.
+ Both remote and local must be full paths. Basically, if
+ you are in directory local and you want to access the file in remote
+ what is the relative path to do that. For example:
+ /a/b/c/d to /a/b/c1/d1 -> ../../c1/d1
+ from /usr/src to /usr/src/test/blah/foo.cpp -> test/blah/foo.cpp
+ */
+ static std::string RelativePath(const char* local, const char* remote);
+
+ /** Joins two paths while collapsing x/../ parts
+ * For example CollapseCombinedPath("a/b/c", "../../d") results in "a/d"
+ */
+ static std::string CollapseCombinedPath(std::string const& dir,
+ std::string const& file);
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ /** Remove an environment variable */
+ static bool UnsetEnv(const char* value);
+
+ /** Get the list of all environment variables */
+ static std::vector<std::string> GetEnvironmentVariables();
+
+ /** Append multiple variables to the current environment. */
+ static void AppendEnv(std::vector<std::string> const& env);
+
+ /** Helper class to save and restore the environment.
+ Instantiate this class as an automatic variable on
+ the stack. Its constructor saves a copy of the current
+ environment and then its destructor restores the
+ original environment. */
+ class SaveRestoreEnvironment
+ {
+ public:
+ SaveRestoreEnvironment();
+ virtual ~SaveRestoreEnvironment();
+ private:
+ std::vector<std::string> Env;
+ };
+#endif
+
+ /** Setup the environment to enable VS 8 IDE output. */
+ static void EnableVSConsoleOutput();
+
+ /** Create tar */
+ static bool ListTar(const char* outFileName,
+ bool gzip, bool verbose);
+ static bool CreateTar(const char* outFileName,
+ const std::vector<std::string>& files, bool gzip,
+ bool bzip2, bool verbose);
+ static bool ExtractTar(const char* inFileName, bool gzip,
+ bool verbose);
+ // This should be called first thing in main
+ // it will keep child processes from inheriting the
+ // stdin and stdout of this process. This is important
+ // if you want to be able to kill child processes and
+ // not get stuck waiting for all the output on the pipes.
+ static void DoNotInheritStdPipes();
+
+ /** Copy the file create/access/modify times from the file named by
+ the first argument to that named by the second. */
+ static bool CopyFileTime(const char* fromFile, const char* toFile);
+
+ /** Save and restore file times. */
+ static cmSystemToolsFileTime* FileTimeNew();
+ static void FileTimeDelete(cmSystemToolsFileTime*);
+ static bool FileTimeGet(const char* fname, cmSystemToolsFileTime* t);
+ static bool FileTimeSet(const char* fname, cmSystemToolsFileTime* t);
+
+ /** Random seed generation. */
+ static unsigned int RandomSeed();
+
+ /** Find the directory containing CMake executables. */
+ static void FindCMakeResources(const char* argv0);
+
+ /** Get the CMake resource paths, after FindCMakeResources. */
+ static std::string const& GetCTestCommand();
+ static std::string const& GetCPackCommand();
+ static std::string const& GetCMakeCommand();
+ static std::string const& GetCMakeGUICommand();
+ static std::string const& GetCMakeCursesCommand();
+ static std::string const& GetCMakeRoot();
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ /** Echo a message in color using KWSys's Terminal cprintf. */
+ static void MakefileColorEcho(int color, const char* message,
+ bool newLine, bool enabled);
+#endif
+
+ /** Try to guess the soname of a shared library. */
+ static bool GuessLibrarySOName(std::string const& fullPath,
+ std::string& soname);
+
+ /** Try to guess the install name of a shared library. */
+ static bool GuessLibraryInstallName(std::string const& fullPath,
+ std::string& soname);
+
+ /** Try to set the RPATH in an ELF binary. */
+ static bool ChangeRPath(std::string const& file,
+ std::string const& oldRPath,
+ std::string const& newRPath,
+ std::string* emsg = 0,
+ bool* changed = 0);
+
+ /** Try to remove the RPATH from an ELF binary. */
+ static bool RemoveRPath(std::string const& file, std::string* emsg = 0,
+ bool* removed = 0);
+
+ /** Check whether the RPATH in an ELF binary contains the path
+ given. */
+ static bool CheckRPath(std::string const& file,
+ std::string const& newRPath);
+
+ /** Remove a directory; repeat a few times in case of locked files. */
+ static bool RepeatedRemoveDirectory(const char* dir);
+
+ /** Tokenize a string */
+ static std::vector<std::string> tokenize(const std::string& str,
+ const std::string& sep);
+
+#ifdef _WIN32
+ struct WindowsFileRetry
+ {
+ unsigned int Count;
+ unsigned int Delay;
+ };
+ static WindowsFileRetry GetWindowsFileRetry();
+#endif
+private:
+ static bool s_ForceUnixPaths;
+ static bool s_RunCommandHideConsole;
+ static bool s_ErrorOccured;
+ static bool s_FatalErrorOccured;
+ static bool s_DisableMessages;
+ static bool s_DisableRunCommandOutput;
+ static MessageCallback s_MessageCallback;
+ static OutputCallback s_StdoutCallback;
+ static OutputCallback s_StderrCallback;
+ static InterruptCallback s_InterruptCallback;
+ static void* s_MessageCallbackClientData;
+ static void* s_StdoutCallbackClientData;
+ static void* s_StderrCallbackClientData;
+ static void* s_InterruptCallbackClientData;
+};
+
+#endif
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
new file mode 100644
index 0000000000..b476a2776e
--- /dev/null
+++ b/Source/cmTarget.cxx
@@ -0,0 +1,6980 @@
+/*============================================================================
+ 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 "cmTarget.h"
+#include "cmake.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmComputeLinkInformation.h"
+#include "cmListFileCache.h"
+#include "cmGeneratorExpression.h"
+#include "cmGeneratorExpressionDAGChecker.h"
+#include <cmsys/RegularExpression.hxx>
+#include <map>
+#include <set>
+#include <stdlib.h> // required for atof
+#include <assert.h>
+#include <errno.h>
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+#include <cmsys/hash_set.hxx>
+#define UNORDERED_SET cmsys::hash_set
+#else
+#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;
+};
+
+//----------------------------------------------------------------------------
+struct cmTarget::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;
+};
+
+//----------------------------------------------------------------------------
+struct cmTarget::CompileInfo
+{
+ std::string CompilePdbDir;
+};
+
+//----------------------------------------------------------------------------
+class cmTargetInternals
+{
+public:
+ cmTargetInternals()
+ : Backtrace(NULL)
+ {
+ this->PolicyWarnedCMP0022 = false;
+ this->UtilityItemsDone = false;
+ }
+ cmTargetInternals(cmTargetInternals const&)
+ : Backtrace(NULL)
+ {
+ this->PolicyWarnedCMP0022 = false;
+ this->UtilityItemsDone = false;
+ }
+ ~cmTargetInternals();
+
+ // The backtrace when the target was created.
+ cmListFileBacktrace Backtrace;
+
+ // Cache link interface computation from each configuration.
+ struct OptionalLinkInterface: public cmTarget::LinkInterface
+ {
+ OptionalLinkInterface():
+ LibrariesDone(false), AllDone(false),
+ Exists(false), HadHeadSensitiveCondition(false),
+ ExplicitLibraries(0) {}
+ bool LibrariesDone;
+ bool AllDone;
+ bool Exists;
+ bool HadHeadSensitiveCondition;
+ const char* ExplicitLibraries;
+ };
+ void ComputeLinkInterface(cmTarget const* thisTarget,
+ const std::string& config,
+ OptionalLinkInterface& iface,
+ cmTarget const* head) const;
+ void ComputeLinkInterfaceLibraries(cmTarget const* thisTarget,
+ const std::string& config,
+ OptionalLinkInterface& iface,
+ cmTarget const* head,
+ bool usage_requirements_only);
+
+ struct HeadToLinkInterfaceMap:
+ public std::map<cmTarget const*, OptionalLinkInterface> {};
+ typedef std::map<std::string, HeadToLinkInterfaceMap>
+ LinkInterfaceMapType;
+ LinkInterfaceMapType LinkInterfaceMap;
+ LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap;
+ bool PolicyWarnedCMP0022;
+
+ typedef std::map<std::string, cmTarget::OutputInfo> OutputInfoMapType;
+ OutputInfoMapType OutputInfoMap;
+
+ typedef std::map<std::string, cmTarget::ImportInfo> ImportInfoMapType;
+ ImportInfoMapType ImportInfoMap;
+
+ typedef std::map<std::string, cmTarget::CompileInfo> CompileInfoMapType;
+ CompileInfoMapType CompileInfoMap;
+
+ // Cache link implementation computation from each configuration.
+ struct OptionalLinkImplementation: public cmTarget::LinkImplementation
+ {
+ OptionalLinkImplementation():
+ LibrariesDone(false), LanguagesDone(false),
+ HadHeadSensitiveCondition(false) {}
+ bool LibrariesDone;
+ bool LanguagesDone;
+ bool HadHeadSensitiveCondition;
+ };
+ void ComputeLinkImplementationLibraries(cmTarget const* thisTarget,
+ const std::string& config,
+ OptionalLinkImplementation& impl,
+ cmTarget const* head) const;
+ void ComputeLinkImplementationLanguages(cmTarget const* thisTarget,
+ const std::string& config,
+ OptionalLinkImplementation& impl
+ ) const;
+
+ struct HeadToLinkImplementationMap:
+ public std::map<cmTarget const*, OptionalLinkImplementation> {};
+ typedef std::map<std::string,
+ HeadToLinkImplementationMap> LinkImplMapType;
+ LinkImplMapType LinkImplMap;
+
+ typedef std::map<std::string, cmTarget::LinkClosure> LinkClosureMapType;
+ LinkClosureMapType LinkClosureMap;
+
+ struct LinkImplClosure: public std::vector<cmTarget const*>
+ {
+ LinkImplClosure(): Done(false) {}
+ bool Done;
+ };
+ std::map<std::string, LinkImplClosure> LinkImplClosureMap;
+
+ struct CompatibleInterfaces: public cmTarget::CompatibleInterfaces
+ {
+ CompatibleInterfaces(): Done(false) {}
+ bool Done;
+ };
+ std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
+
+ 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<TargetPropertyEntry*> IncludeDirectoriesEntries;
+ std::vector<TargetPropertyEntry*> CompileOptionsEntries;
+ std::vector<TargetPropertyEntry*> CompileFeaturesEntries;
+ std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
+ 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);
+};
+
+cmLinkImplItem cmTargetInternals::TargetPropertyEntry::NoLinkImplItem;
+
+//----------------------------------------------------------------------------
+static void deleteAndClear(
+ std::vector<cmTargetInternals::TargetPropertyEntry*> &entries)
+{
+ for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
+ it = entries.begin(),
+ end = entries.end();
+ it != end; ++it)
+ {
+ delete *it;
+ }
+ entries.clear();
+}
+
+//----------------------------------------------------------------------------
+cmTargetInternals::~cmTargetInternals()
+{
+}
+
+//----------------------------------------------------------------------------
+cmTarget::cmTarget()
+{
+#define INITIALIZE_TARGET_POLICY_MEMBER(POLICY) \
+ this->PolicyStatus ## POLICY = cmPolicies::WARN;
+
+ CM_FOR_EACH_TARGET_POLICY(INITIALIZE_TARGET_POLICY_MEMBER)
+
+#undef INITIALIZE_TARGET_POLICY_MEMBER
+
+ this->Makefile = 0;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ this->LinkLibrariesForVS6Analyzed = false;
+#endif
+ this->HaveInstallRule = false;
+ this->DLLPlatform = false;
+ this->IsAndroid = false;
+ this->IsApple = false;
+ this->IsImportedTarget = false;
+ this->BuildInterfaceIncludesAppended = false;
+ this->DebugIncludesDone = false;
+ this->DebugCompileOptionsDone = false;
+ this->DebugCompileFeaturesDone = false;
+ this->DebugCompileDefinitionsDone = false;
+ this->DebugSourcesDone = false;
+ this->LinkImplementationLanguageIsContextDependent = true;
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::DefineProperties(cmake *cm)
+{
+ cm->DefineProperty
+ ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
+ "", "", true);
+ cm->DefineProperty
+ ("RULE_LAUNCH_LINK", cmProperty::TARGET,
+ "", "", true);
+ cm->DefineProperty
+ ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
+ "", "", true);
+}
+
+void cmTarget::SetType(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)
+ {
+ this->RecordDependencies = true;
+ }
+ else
+ {
+ this->RecordDependencies = false;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::SetMakefile(cmMakefile* mf)
+{
+ // Set our makefile.
+ this->Makefile = mf;
+
+ // set the cmake instance of the properties
+ this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
+
+ // Check whether this is a DLL platform.
+ this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
+ this->Makefile->IsOn("CYGWIN") ||
+ this->Makefile->IsOn("MINGW"));
+
+ // Check whether we are targeting an Android platform.
+ this->IsAndroid =
+ 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)
+ {
+ this->SetPropertyDefault("ANDROID_API", 0);
+ this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
+ this->SetPropertyDefault("INSTALL_RPATH", "");
+ this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
+ this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
+ this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
+ this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
+ this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
+ this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
+ this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
+ this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", 0);
+ this->SetPropertyDefault("Fortran_FORMAT", 0);
+ this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
+ this->SetPropertyDefault("GNUtoMS", 0);
+ this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
+ this->SetPropertyDefault("AUTOMOC", 0);
+ this->SetPropertyDefault("AUTOUIC", 0);
+ this->SetPropertyDefault("AUTORCC", 0);
+ this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
+ this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
+ this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
+ this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
+ this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
+ this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
+ this->SetPropertyDefault("MACOSX_BUNDLE", 0);
+ this->SetPropertyDefault("MACOSX_RPATH", 0);
+ this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
+ this->SetPropertyDefault("C_STANDARD", 0);
+ this->SetPropertyDefault("C_STANDARD_REQUIRED", 0);
+ this->SetPropertyDefault("C_EXTENSIONS", 0);
+ this->SetPropertyDefault("CXX_STANDARD", 0);
+ this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0);
+ this->SetPropertyDefault("CXX_EXTENSIONS", 0);
+ }
+
+ // Collect the set of configuration types.
+ std::vector<std::string> configNames;
+ mf->GetConfigurations(configNames);
+
+ // Setup per-configuration property default values.
+ if (this->GetType() != UTILITY)
+ {
+ const char* configProps[] = {
+ "ARCHIVE_OUTPUT_DIRECTORY_",
+ "LIBRARY_OUTPUT_DIRECTORY_",
+ "RUNTIME_OUTPUT_DIRECTORY_",
+ "PDB_OUTPUT_DIRECTORY_",
+ "COMPILE_PDB_OUTPUT_DIRECTORY_",
+ "MAP_IMPORTED_CONFIG_",
+ 0};
+ for(std::vector<std::string>::iterator ci = configNames.begin();
+ ci != configNames.end(); ++ci)
+ {
+ std::string configUpper = cmSystemTools::UpperCase(*ci);
+ for(const char** p = configProps; *p; ++p)
+ {
+ if (this->TargetTypeValue == INTERFACE_LIBRARY
+ && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
+ {
+ continue;
+ }
+ std::string property = *p;
+ property += configUpper;
+ this->SetPropertyDefault(property, 0);
+ }
+
+ // Initialize per-configuration name postfix property from the
+ // variable only for non-executable targets. This preserves
+ // 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)
+ {
+ std::string property = cmSystemTools::UpperCase(*ci);
+ property += "_POSTFIX";
+ this->SetPropertyDefault(property, 0);
+ }
+ }
+ }
+
+ // Save the backtrace of target construction.
+ this->Internal->Backtrace = this->Makefile->GetBacktrace();
+
+ if (!this->IsImported())
+ {
+ // Initialize the INCLUDE_DIRECTORIES property based on the current value
+ // of the same directory property:
+ const std::vector<cmValueWithOrigin> parentIncludes =
+ this->Makefile->GetIncludeDirectoriesEntries();
+
+ for (std::vector<cmValueWithOrigin>::const_iterator it
+ = parentIncludes.begin(); it != parentIncludes.end(); ++it)
+ {
+ this->InsertInclude(*it);
+ }
+ const std::set<std::string> parentSystemIncludes =
+ this->Makefile->GetSystemIncludeDirectories();
+
+ for (std::set<std::string>::const_iterator it
+ = parentSystemIncludes.begin();
+ it != parentSystemIncludes.end(); ++it)
+ {
+ this->SystemIncludeDirectories.insert(*it);
+ }
+
+ const std::vector<cmValueWithOrigin> parentOptions =
+ this->Makefile->GetCompileOptionsEntries();
+
+ for (std::vector<cmValueWithOrigin>::const_iterator it
+ = parentOptions.begin(); it != parentOptions.end(); ++it)
+ {
+ this->InsertCompileOption(*it);
+ }
+ }
+
+ if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
+ {
+ this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
+ this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
+ this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
+ }
+
+ if(this->TargetTypeValue == cmTarget::EXECUTABLE)
+ {
+ this->SetPropertyDefault("ANDROID_GUI", 0);
+ }
+ if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
+ || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
+ {
+ this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
+ }
+ if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
+ {
+ this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
+ }
+
+ // Record current policies for later use.
+#define CAPTURE_TARGET_POLICY(POLICY) \
+ this->PolicyStatus ## POLICY = \
+ this->Makefile->GetPolicyStatus(cmPolicies::POLICY);
+
+ CM_FOR_EACH_TARGET_POLICY(CAPTURE_TARGET_POLICY)
+
+#undef CAPTURE_TARGET_POLICY
+
+ if (this->TargetTypeValue == INTERFACE_LIBRARY)
+ {
+ // This policy is checked in a few conditions. The properties relevant
+ // to the policy are always ignored for INTERFACE_LIBRARY targets,
+ // so ensure that the conditions don't lead to nonsense.
+ this->PolicyStatusCMP0022 = cmPolicies::NEW;
+ }
+
+ if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
+ {
+ this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
+ this->SetPropertyDefault("JOB_POOL_LINK", 0);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
+{
+ if(this->Utilities.insert(u).second && makefile)
+ {
+ UtilityBacktraces.insert(std::make_pair(u, makefile->GetBacktrace()));
+ }
+}
+
+//----------------------------------------------------------------------------
+cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
+ const std::string& u) const
+{
+ std::map<std::string, cmListFileBacktrace>::const_iterator i =
+ this->UtilityBacktraces.find(u);
+ if(i == this->UtilityBacktraces.end()) return 0;
+
+ return &i->second;
+}
+
+//----------------------------------------------------------------------------
+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->GetLocalGenerator()->GetGlobalGenerator()->IsForVS6())
+ {
+ this->AnalyzeLibDependenciesForVS6(*this->Makefile);
+ }
+#endif
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::ClearLinkMaps()
+{
+ this->LinkImplementationLanguageIsContextDependent = true;
+ this->Internal->LinkImplMap.clear();
+ this->Internal->LinkInterfaceMap.clear();
+ this->Internal->LinkInterfaceUsageRequirementsOnlyMap.clear();
+ this->Internal->LinkClosureMap.clear();
+ for (cmTargetLinkInformationMap::const_iterator it
+ = this->LinkInformation.begin();
+ it != this->LinkInformation.end(); ++it)
+ {
+ delete it->second;
+ }
+ this->LinkInformation.clear();
+}
+
+//----------------------------------------------------------------------------
+cmListFileBacktrace const& cmTarget::GetBacktrace() const
+{
+ return this->Internal->Backtrace;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetSupportDirectory() const
+{
+ std::string dir = this->Makefile->GetCurrentOutputDirectory();
+ dir += cmake::GetCMakeFilesDirectory();
+ dir += "/";
+ dir += this->Name;
+#if defined(__VMS)
+ dir += "_dir";
+#else
+ dir += ".dir";
+#endif
+ return dir;
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::IsExecutableWithExports() const
+{
+ return (this->GetType() == cmTarget::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->IsExecutableWithExports()));
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::IsFrameworkOnApple() const
+{
+ return (this->GetType() == cmTarget::SHARED_LIBRARY &&
+ this->Makefile->IsOn("APPLE") &&
+ this->GetPropertyAsBool("FRAMEWORK"));
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::IsAppBundleOnApple() const
+{
+ return (this->GetType() == cmTarget::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::IsBundleOnApple() const
+{
+ return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
+ this->IsCFBundleOnApple();
+}
+
+//----------------------------------------------------------------------------
+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)
+ {
+ 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;
+ src = sf->GetFullPath(&e);
+ if(src.empty())
+ {
+ if(!e.empty())
+ {
+ cmake* cm = mf->GetCMakeInstance();
+ cm->IssueMessage(cmake::FATAL_ERROR, e,
+ tgt->GetBacktrace());
+ }
+ return contextDependent;
+ }
+ }
+ 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->Makefile->GetGeneratorTargets().empty())
+ {
+ // 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->Makefile->IsGeneratingBuildSystem())
+ {
+ 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;
+ }
+
+ deleteAndClear(linkInterfaceSourcesEntries);
+}
+
+//----------------------------------------------------------------------------
+bool
+cmTarget::GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const
+{
+ std::vector<std::string> configs;
+ this->Makefile->GetConfigurations(configs);
+ if (configs.empty())
+ {
+ configs.push_back("");
+ }
+
+ std::vector<std::string>::const_iterator it = configs.begin();
+ const std::string& firstConfig = *it;
+ this->GetSourceFiles(files, firstConfig);
+
+ for ( ; it != configs.end(); ++it)
+ {
+ std::vector<cmSourceFile*> configFiles;
+ this->GetSourceFiles(configFiles, *it);
+ if (configFiles != files)
+ {
+ std::string firstConfigFiles;
+ const char* sep = "";
+ for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
+ fi != files.end(); ++fi)
+ {
+ firstConfigFiles += sep;
+ firstConfigFiles += (*fi)->GetFullPath();
+ sep = "\n ";
+ }
+
+ std::string thisConfigFiles;
+ sep = "";
+ for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
+ fi != configFiles.end(); ++fi)
+ {
+ thisConfigFiles += sep;
+ thisConfigFiles += (*fi)->GetFullPath();
+ sep = "\n ";
+ }
+ cmOStringStream e;
+ e << "Target \"" << this->Name << "\" has source files which vary by "
+ "configuration. This is not supported by the \""
+ << this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()->GetName()
+ << "\" generator.\n"
+ "Config \"" << firstConfig << "\":\n"
+ " " << firstConfigFiles << "\n"
+ "Config \"" << *it << "\":\n"
+ " " << thisConfigFiles << "\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+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;
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator i = srcs.begin();
+ i != srcs.end(); ++i)
+ {
+ std::string filename = *i;
+ srcFiles += sep;
+ srcFiles += filename;
+ sep = ";";
+ }
+ 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));
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::AddSources(std::vector<std::string> const& srcs)
+{
+ std::string srcFiles;
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator i = srcs.begin();
+ i != srcs.end(); ++i)
+ {
+ std::string filename = *i;
+ const char* src = filename.c_str();
+
+ if(!(src[0] == '$' && src[1] == '<'))
+ {
+ if(!filename.empty())
+ {
+ filename = this->ProcessSourceItemCMP0049(filename);
+ if(filename.empty())
+ {
+ return;
+ }
+ }
+ this->Makefile->GetOrCreateSource(filename);
+ }
+ srcFiles += sep;
+ srcFiles += filename;
+ sep = ";";
+ }
+ 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));
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
+{
+ std::string src = s;
+
+ // For backwards compatibility replace varibles in source names.
+ // This should eventually be removed.
+ this->Makefile->ExpandVariablesInString(src);
+ if (src != s)
+ {
+ cmOStringStream e;
+ bool noMessage = false;
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0049))
+ {
+ case cmPolicies::WARN:
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0049)) << "\n";
+ break;
+ case cmPolicies::OLD:
+ noMessage = true;
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW:
+ messageType = cmake::FATAL_ERROR;
+ }
+ if (!noMessage)
+ {
+ e << "Legacy variable expansion in source file \""
+ << s << "\" expanded to \"" << src << "\" in target \""
+ << this->GetName() << "\". This behavior will be removed in a "
+ "future version of CMake.";
+ this->Makefile->IssueMessage(messageType, e.str());
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return "";
+ }
+ }
+ }
+ return src;
+}
+
+//----------------------------------------------------------------------------
+cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
+{
+ std::string src = this->ProcessSourceItemCMP0049(s);
+ if(!s.empty() && src.empty())
+ {
+ return 0;
+ }
+ return this->AddSource(src);
+}
+
+//----------------------------------------------------------------------------
+struct CreateLocation
+{
+ cmMakefile const* Makefile;
+
+ CreateLocation(cmMakefile const* mf)
+ : Makefile(mf)
+ {
+
+ }
+
+ cmSourceFileLocation operator()(const std::string& filename)
+ {
+ return cmSourceFileLocation(this->Makefile, filename);
+ }
+};
+
+//----------------------------------------------------------------------------
+struct LocationMatcher
+{
+ const cmSourceFileLocation& Needle;
+
+ LocationMatcher(const cmSourceFileLocation& needle)
+ : Needle(needle)
+ {
+
+ }
+
+ bool operator()(cmSourceFileLocation &loc)
+ {
+ return loc.Matches(this->Needle);
+ }
+};
+
+
+//----------------------------------------------------------------------------
+struct TargetPropertyEntryFinder
+{
+private:
+ const cmSourceFileLocation& Needle;
+public:
+ TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
+ : Needle(needle)
+ {
+
+ }
+
+ bool operator()(cmTargetInternals::TargetPropertyEntry* entry)
+ {
+ std::vector<std::string> files;
+ cmSystemTools::ExpandListArgument(entry->ge->GetInput(), files);
+ std::vector<cmSourceFileLocation> locations(files.size());
+ std::transform(files.begin(), files.end(), locations.begin(),
+ CreateLocation(this->Needle.GetMakefile()));
+
+ return std::find_if(locations.begin(), locations.end(),
+ LocationMatcher(this->Needle)) != locations.end();
+ }
+};
+
+//----------------------------------------------------------------------------
+cmSourceFile* cmTarget::AddSource(const std::string& src)
+{
+ cmSourceFileLocation sfl(this->Makefile, src);
+ if (std::find_if(this->Internal->SourceEntries.begin(),
+ this->Internal->SourceEntries.end(),
+ 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));
+ }
+ if (cmGeneratorExpression::Find(src) != std::string::npos)
+ {
+ return 0;
+ }
+ return this->Makefile->GetOrCreateSource(src);
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::MergeLinkLibraries( cmMakefile& mf,
+ const std::string& selfname,
+ const LinkLibraryVectorType& libs )
+{
+ // Only add on libraries we haven't added on before.
+ // Assumption: the global link libraries could only grow, never shrink
+ LinkLibraryVectorType::const_iterator i = libs.begin();
+ i += this->PrevLinkedLibraries.size();
+ for( ; i != libs.end(); ++i )
+ {
+ // This is equivalent to the target_link_libraries plain signature.
+ this->AddLinkLibrary( mf, selfname, i->first, i->second );
+ this->AppendProperty("INTERFACE_LINK_LIBRARIES",
+ this->GetDebugGeneratorExpressions(i->first, i->second).c_str());
+ }
+ this->PrevLinkedLibraries = libs;
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::AddLinkDirectory(const std::string& d)
+{
+ // Make sure we don't add unnecessary search directories.
+ if(this->LinkDirectoriesEmmitted.insert(d).second)
+ {
+ this->LinkDirectories.push_back(d);
+ }
+}
+
+//----------------------------------------------------------------------------
+const std::vector<std::string>& cmTarget::GetLinkDirectories() const
+{
+ return this->LinkDirectories;
+}
+
+//----------------------------------------------------------------------------
+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> const& debugConfigs =
+ this->Makefile->GetCMakeInstance()->GetDebugConfigs();
+
+ // Check if any entry in the list matches this configuration.
+ std::string configUpper = cmSystemTools::UpperCase(config);
+ for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
+ i != debugConfigs.end(); ++i)
+ {
+ if(*i == configUpper)
+ {
+ return cmTarget::DEBUG;
+ }
+ }
+
+ // The current configuration is not a debug configuration.
+ return cmTarget::OPTIMIZED;
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::ClearDependencyInformation( cmMakefile& mf,
+ const std::string& target )
+{
+ // Clear the dependencies. The cache variable must exist iff we are
+ // recording dependency information for this target.
+ std::string depname = target;
+ depname += "_LIB_DEPENDS";
+ if (this->RecordDependencies)
+ {
+ mf.AddCacheDefinition(depname, "",
+ "Dependencies for target", cmCacheManager::STATIC);
+ }
+ else
+ {
+ if (mf.GetDefinition( depname ))
+ {
+ std::string message = "Target ";
+ message += target;
+ message += " has dependency information when it shouldn't.\n";
+ message += "Your cache is probably stale. Please remove the entry\n ";
+ message += depname;
+ message += "\nfrom the cache.";
+ cmSystemTools::Error( message.c_str() );
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::NameResolvesToFramework(const std::string& libname) const
+{
+ return this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
+ NameResolvesToFramework(libname);
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
+ cmTarget::LinkLibraryType llt) const
+{
+ if (llt == GENERAL)
+ {
+ return value;
+ }
+
+ // Get the list of configurations considered to be DEBUG.
+ std::vector<std::string> const& debugConfigs =
+ this->Makefile->GetCMakeInstance()->GetDebugConfigs();
+
+ std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
+
+ if (debugConfigs.size() > 1)
+ {
+ for(std::vector<std::string>::const_iterator
+ li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
+ {
+ configString += ",$<CONFIG:" + *li + ">";
+ }
+ configString = "$<OR:" + configString + ">";
+ }
+
+ if (llt == OPTIMIZED)
+ {
+ configString = "$<NOT:" + configString + ">";
+ }
+ return "$<" + configString + ":" + value + ">";
+}
+
+//----------------------------------------------------------------------------
+static std::string targetNameGenex(const std::string& lib)
+{
+ return "$<TARGET_NAME:" + lib + ">";
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
+{
+ bool ret = true;
+ if (!this->TLLCommands.empty())
+ {
+ if (this->TLLCommands.back().first != signature)
+ {
+ ret = false;
+ }
+ }
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ this->TLLCommands.push_back(std::make_pair(signature, lfbt));
+ return ret;
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetTllSignatureTraces(cmOStringStream &s,
+ TLLSignature sig) const
+{
+ std::vector<cmListFileBacktrace> sigs;
+ typedef std::vector<std::pair<TLLSignature, cmListFileBacktrace> > Container;
+ for(Container::const_iterator it = this->TLLCommands.begin();
+ it != this->TLLCommands.end(); ++it)
+ {
+ if (it->first == sig)
+ {
+ sigs.push_back(it->second);
+ }
+ }
+ if (!sigs.empty())
+ {
+ const char *sigString
+ = (sig == cmTarget::KeywordTLLSignature ? "keyword"
+ : "plain");
+ s << "The uses of the " << sigString << " signature are here:\n";
+ UNORDERED_SET<std::string> emitted;
+ for(std::vector<cmListFileBacktrace>::iterator it = sigs.begin();
+ it != sigs.end(); ++it)
+ {
+ it->MakeRelative();
+ cmListFileBacktrace::const_iterator i = it->begin();
+ if(i != it->end())
+ {
+ cmListFileContext const& lfc = *i;
+ cmOStringStream line;
+ line << " * " << (lfc.Line? "": " in ") << lfc << std::endl;
+ if (emitted.insert(line.str()).second)
+ {
+ s << line.str();
+ }
+ ++i;
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::AddLinkLibrary(cmMakefile& mf,
+ const std::string& target,
+ const std::string& lib,
+ LinkLibraryType llt)
+{
+ cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
+ {
+ const bool isNonImportedTarget = tgt && !tgt->IsImported();
+
+ const std::string libName = (isNonImportedTarget && llt != GENERAL)
+ ? 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)
+ || (target == lib ))
+ {
+ return;
+ }
+
+ cmTarget::LibraryID tmp;
+ tmp.first = lib;
+ tmp.second = llt;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ 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
+ // be a trailing ";". These library names are not canonical, in that
+ // they may be "-framework x", "-ly", "/path/libz.a", etc.
+ // We shouldn't remove duplicates here because external libraries
+ // may be purposefully duplicated to handle recursive dependencies,
+ // and we removing one instance will break the link line. Duplicates
+ // will be appropriately eliminated at emit time.
+ if(this->RecordDependencies)
+ {
+ std::string targetEntry = target;
+ targetEntry += "_LIB_DEPENDS";
+ std::string dependencies;
+ const char* old_val = mf.GetDefinition( targetEntry );
+ if( old_val )
+ {
+ dependencies += old_val;
+ }
+ switch (llt)
+ {
+ case cmTarget::GENERAL:
+ dependencies += "general";
+ break;
+ case cmTarget::DEBUG:
+ dependencies += "debug";
+ break;
+ case cmTarget::OPTIMIZED:
+ dependencies += "optimized";
+ break;
+ }
+ dependencies += ";";
+ dependencies += lib;
+ dependencies += ";";
+ mf.AddCacheDefinition( targetEntry, dependencies.c_str(),
+ "Dependencies for the target",
+ cmCacheManager::STATIC );
+ }
+
+}
+
+//----------------------------------------------------------------------------
+void
+cmTarget::AddSystemIncludeDirectories(const std::set<std::string> &incs)
+{
+ for(std::set<std::string>::const_iterator li = incs.begin();
+ li != incs.end(); ++li)
+ {
+ this->SystemIncludeDirectories.insert(*li);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmTarget::AddSystemIncludeDirectories(const std::vector<std::string> &incs)
+{
+ for(std::vector<std::string>::const_iterator li = incs.begin();
+ li != incs.end(); ++li)
+ {
+ this->SystemIncludeDirectories.insert(*li);
+ }
+}
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+//----------------------------------------------------------------------------
+void
+cmTarget::AnalyzeLibDependenciesForVS6( const cmMakefile& mf )
+{
+ // There are two key parts of the dependency analysis: (1)
+ // determining the libraries in the link line, and (2) constructing
+ // the dependency graph for those libraries.
+ //
+ // The latter is done using the cache entries that record the
+ // dependencies of each library.
+ //
+ // The former is a more thorny issue, since it is not clear how to
+ // determine if two libraries listed on the link line refer to the a
+ // single library or not. For example, consider the link "libraries"
+ // /usr/lib/libtiff.so -ltiff
+ // Is this one library or two? The solution implemented here is the
+ // simplest (and probably the only practical) one: two libraries are
+ // the same if their "link strings" are identical. Thus, the two
+ // libraries above are considered distinct. This also means that for
+ // dependency analysis to be effective, the CMake user must specify
+ // libraries build by his project without using any linker flags or
+ // file extensions. That is,
+ // LINK_LIBRARIES( One Two )
+ // instead of
+ // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
+ // The former is probably what most users would do, but it never
+ // hurts to document the assumptions. :-) Therefore, in the analysis
+ // code, the "canonical name" of a library is simply its name as
+ // given to a LINK_LIBRARIES command.
+ //
+ // Also, we will leave the original link line intact; we will just add any
+ // dependencies that were missing.
+ //
+ // There is a problem with recursive external libraries
+ // (i.e. libraries with no dependency information that are
+ // recursively dependent). We must make sure that the we emit one of
+ // the libraries twice to satisfy the recursion, but we shouldn't
+ // emit it more times than necessary. In particular, we must make
+ // sure that handling this improbable case doesn't cost us when
+ // dealing with the common case of non-recursive libraries. The
+ // solution is to assume that the recursion is satisfied at one node
+ // of the dependency tree. To illustrate, assume libA and libB are
+ // extrenal and mutually dependent. Suppose libX depends on
+ // libA, and libY on libA and libX. Then
+ // TARGET_LINK_LIBRARIES( Y X A B A )
+ // TARGET_LINK_LIBRARIES( X A B A )
+ // TARGET_LINK_LIBRARIES( Exec Y )
+ // would result in "-lY -lX -lA -lB -lA". This is the correct way to
+ // specify the dependencies, since the mutual dependency of A and B
+ // is resolved *every time libA is specified*.
+ //
+ // Something like
+ // TARGET_LINK_LIBRARIES( Y X A B A )
+ // TARGET_LINK_LIBRARIES( X A B )
+ // TARGET_LINK_LIBRARIES( Exec Y )
+ // would result in "-lY -lX -lA -lB", and the mutual dependency
+ // information is lost. This is because in some case (Y), the mutual
+ // dependency of A and B is listed, while in another other case (X),
+ // it is not. Depending on which line actually emits A, the mutual
+ // dependency may or may not be on the final link line. We can't
+ // handle this pathalogical case cleanly without emitting extra
+ // libraries for the normal cases. Besides, the dependency
+ // information for X is wrong anyway: if we build an executable
+ // depending on X alone, we would not have the mutual dependency on
+ // A and B resolved.
+ //
+ // IMPROVEMENTS:
+ // -- The current algorithm will not always pick the "optimal" link line
+ // when recursive dependencies are present. It will instead break the
+ // cycles at an aribtrary point. The majority of projects won't have
+ // cyclic dependencies, so this is probably not a big deal. Note that
+ // the link line is always correct, just not necessary optimal.
+
+ {
+ // Expand variables in link library names. This is for backwards
+ // compatibility with very early CMake versions and should
+ // eventually be removed. This code was moved here from the end of
+ // old source list processing code which was called just before this
+ // method.
+ for(LinkLibraryVectorType::iterator p = this->LinkLibrariesForVS6.begin();
+ p != this->LinkLibrariesForVS6.end(); ++p)
+ {
+ this->Makefile->ExpandVariablesInString(p->first, true, true);
+ }
+ }
+
+ // The dependency map.
+ DependencyMap dep_map;
+
+ // 1. Build the dependency graph
+ //
+ for(LinkLibraryVectorType::reverse_iterator lib
+ = this->LinkLibrariesForVS6.rbegin();
+ lib != this->LinkLibrariesForVS6.rend(); ++lib)
+ {
+ this->GatherDependenciesForVS6( mf, *lib, dep_map);
+ }
+
+ // 2. Remove any dependencies that are already satisfied in the original
+ // link line.
+ //
+ for(LinkLibraryVectorType::iterator lib = this->LinkLibrariesForVS6.begin();
+ lib != this->LinkLibrariesForVS6.end(); ++lib)
+ {
+ for( LinkLibraryVectorType::iterator lib2 = lib;
+ lib2 != this->LinkLibrariesForVS6.end(); ++lib2)
+ {
+ this->DeleteDependencyForVS6( dep_map, *lib, *lib2);
+ }
+ }
+
+
+ // 3. Create the new link line by simply emitting any dependencies that are
+ // missing. Start from the back and keep adding.
+ //
+ std::set<DependencyMap::key_type> done, visited;
+ std::vector<DependencyMap::key_type> newLinkLibrariesForVS6;
+ for(LinkLibraryVectorType::reverse_iterator lib =
+ this->LinkLibrariesForVS6.rbegin();
+ lib != this->LinkLibrariesForVS6.rend(); ++lib)
+ {
+ // skip zero size library entries, this may happen
+ // if a variable expands to nothing.
+ if (lib->first.size() != 0)
+ {
+ this->EmitForVS6( *lib, dep_map, done, visited, newLinkLibrariesForVS6 );
+ }
+ }
+
+ // 4. Add the new libraries to the link line.
+ //
+ for( std::vector<DependencyMap::key_type>::reverse_iterator k =
+ newLinkLibrariesForVS6.rbegin();
+ k != newLinkLibrariesForVS6.rend(); ++k )
+ {
+ // get the llt from the dep_map
+ this->LinkLibrariesForVS6.push_back( std::make_pair(k->first,k->second) );
+ }
+ this->LinkLibrariesForVS6Analyzed = true;
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::InsertDependencyForVS6( DependencyMap& depMap,
+ const LibraryID& lib,
+ const LibraryID& dep)
+{
+ depMap[lib].push_back(dep);
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::DeleteDependencyForVS6( DependencyMap& depMap,
+ const LibraryID& lib,
+ const LibraryID& dep)
+{
+ // Make sure there is an entry in the map for lib. If so, delete all
+ // dependencies to dep. There may be repeated entries because of
+ // external libraries that are specified multiple times.
+ DependencyMap::iterator map_itr = depMap.find( lib );
+ if( map_itr != depMap.end() )
+ {
+ DependencyList& depList = map_itr->second;
+ DependencyList::iterator itr;
+ while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
+ depList.end() )
+ {
+ depList.erase( itr );
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::EmitForVS6(const LibraryID lib,
+ const DependencyMap& dep_map,
+ std::set<LibraryID>& emitted,
+ std::set<LibraryID>& visited,
+ DependencyList& link_line )
+{
+ // It's already been emitted
+ if( emitted.find(lib) != emitted.end() )
+ {
+ return;
+ }
+
+ // Emit the dependencies only if this library node hasn't been
+ // visited before. If it has, then we have a cycle. The recursion
+ // that got us here should take care of everything.
+
+ if( visited.insert(lib).second )
+ {
+ if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
+ {
+ const DependencyList& dep_on = dep_map.find( lib )->second;
+ DependencyList::const_reverse_iterator i;
+
+ // To cater for recursive external libraries, we must emit
+ // duplicates on this link line *unless* they were emitted by
+ // some other node, in which case we assume that the recursion
+ // was resolved then. We making the simplifying assumption that
+ // any duplicates on a single link line are on purpose, and must
+ // be preserved.
+
+ // This variable will keep track of the libraries that were
+ // emitted directly from the current node, and not from a
+ // recursive call. This way, if we come across a library that
+ // has already been emitted, we repeat it iff it has been
+ // emitted here.
+ std::set<DependencyMap::key_type> emitted_here;
+ for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
+ {
+ if( emitted_here.find(*i) != emitted_here.end() )
+ {
+ // a repeat. Must emit.
+ emitted.insert(*i);
+ link_line.push_back( *i );
+ }
+ else
+ {
+ // Emit only if no-one else has
+ if( emitted.find(*i) == emitted.end() )
+ {
+ // emit dependencies
+ this->EmitForVS6( *i, dep_map, emitted, visited, link_line );
+ // emit self
+ emitted.insert(*i);
+ emitted_here.insert(*i);
+ link_line.push_back( *i );
+ }
+ }
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GatherDependenciesForVS6( const cmMakefile& mf,
+ const LibraryID& lib,
+ DependencyMap& dep_map)
+{
+ // If the library is already in the dependency map, then it has
+ // already been fully processed.
+ if( dep_map.find(lib) != dep_map.end() )
+ {
+ return;
+ }
+
+ const char* deps = mf.GetDefinition( lib.first+"_LIB_DEPENDS" );
+ if( deps && strcmp(deps,"") != 0 )
+ {
+ // Make sure this library is in the map, even if it has an empty
+ // set of dependencies. This distinguishes the case of explicitly
+ // no dependencies with that of unspecified dependencies.
+ dep_map[lib];
+
+ // Parse the dependency information, which is a set of
+ // type, library pairs separated by ";". There is always a trailing ";".
+ cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
+ std::string depline = deps;
+ std::string::size_type start = 0;
+ std::string::size_type end;
+ end = depline.find( ";", start );
+ while( end != std::string::npos )
+ {
+ std::string l = depline.substr( start, end-start );
+ if( l.size() != 0 )
+ {
+ if (l == "debug")
+ {
+ llt = cmTarget::DEBUG;
+ }
+ else if (l == "optimized")
+ {
+ llt = cmTarget::OPTIMIZED;
+ }
+ else if (l == "general")
+ {
+ llt = cmTarget::GENERAL;
+ }
+ else
+ {
+ LibraryID lib2(l,llt);
+ this->InsertDependencyForVS6( dep_map, lib, lib2);
+ this->GatherDependenciesForVS6( mf, lib2, dep_map);
+ llt = cmTarget::GENERAL;
+ }
+ }
+ start = end+1; // skip the ;
+ end = depline.find( ";", start );
+ }
+ // cannot depend on itself
+ this->DeleteDependencyForVS6( dep_map, lib, lib);
+ }
+}
+#endif
+
+//----------------------------------------------------------------------------
+static bool whiteListedInterfaceProperty(const std::string& prop)
+{
+ if(cmHasLiteralPrefix(prop, "INTERFACE_"))
+ {
+ return true;
+ }
+ static UNORDERED_SET<std::string> builtIns;
+ if (builtIns.empty())
+ {
+ builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
+ builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
+ builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
+ builtIns.insert("COMPATIBLE_INTERFACE_STRING");
+ builtIns.insert("EXPORT_NAME");
+ builtIns.insert("IMPORTED");
+ builtIns.insert("NAME");
+ builtIns.insert("TYPE");
+ }
+
+ if (builtIns.count(prop))
+ {
+ return true;
+ }
+
+ if (cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_"))
+ {
+ return true;
+ }
+
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::SetProperty(const std::string& prop, const char* value)
+{
+ if (this->GetType() == INTERFACE_LIBRARY
+ && !whiteListedInterfaceProperty(prop))
+ {
+ cmOStringStream e;
+ e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
+ "The property \"" << prop << "\" is not allowed.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ else if (prop == "NAME")
+ {
+ cmOStringStream e;
+ e << "NAME property is read-only\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ else if(prop == "INCLUDE_DIRECTORIES")
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmGeneratorExpression ge(&lfbt);
+ deleteAndClear(this->Internal->IncludeDirectoriesEntries);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+ this->Internal->IncludeDirectoriesEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(cge));
+ }
+ else if(prop == "COMPILE_OPTIONS")
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmGeneratorExpression ge(&lfbt);
+ deleteAndClear(this->Internal->CompileOptionsEntries);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+ this->Internal->CompileOptionsEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(cge));
+ }
+ else if(prop == "COMPILE_FEATURES")
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmGeneratorExpression ge(&lfbt);
+ deleteAndClear(this->Internal->CompileFeaturesEntries);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+ this->Internal->CompileFeaturesEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(cge));
+ }
+ else if(prop == "COMPILE_DEFINITIONS")
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmGeneratorExpression ge(&lfbt);
+ deleteAndClear(this->Internal->CompileDefinitionsEntries);
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+ this->Internal->CompileDefinitionsEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(cge));
+ }
+ else if(prop == "EXPORT_NAME" && this->IsImported())
+ {
+ cmOStringStream e;
+ e << "EXPORT_NAME property can't be set on imported targets (\""
+ << this->Name << "\")\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ else if (prop == "LINK_LIBRARIES")
+ {
+ this->Internal->LinkImplementationPropertyEntries.clear();
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmValueWithOrigin entry(value, lfbt);
+ this->Internal->LinkImplementationPropertyEntries.push_back(entry);
+ }
+ else if (prop == "SOURCES")
+ {
+ if(this->IsImported())
+ {
+ cmOStringStream e;
+ e << "SOURCES property can't be set on imported targets (\""
+ << this->Name << "\")\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ this->Internal->SourceFilesMap.clear();
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmGeneratorExpression ge(&lfbt);
+ this->Internal->SourceEntries.clear();
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+ this->Internal->SourceEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(cge));
+ }
+ else
+ {
+ this->Properties.SetProperty(prop, value, cmProperty::TARGET);
+ this->MaybeInvalidatePropertyCache(prop);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::AppendProperty(const std::string& prop, const char* value,
+ bool asString)
+{
+ if (this->GetType() == INTERFACE_LIBRARY
+ && !whiteListedInterfaceProperty(prop))
+ {
+ cmOStringStream e;
+ e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
+ "The property \"" << prop << "\" is not allowed.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ else if (prop == "NAME")
+ {
+ cmOStringStream e;
+ e << "NAME property is read-only\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ else if(prop == "INCLUDE_DIRECTORIES")
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmGeneratorExpression ge(&lfbt);
+ this->Internal->IncludeDirectoriesEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
+ }
+ else if(prop == "COMPILE_OPTIONS")
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmGeneratorExpression ge(&lfbt);
+ this->Internal->CompileOptionsEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
+ }
+ else if(prop == "COMPILE_FEATURES")
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmGeneratorExpression ge(&lfbt);
+ this->Internal->CompileFeaturesEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
+ }
+ else if(prop == "COMPILE_DEFINITIONS")
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmGeneratorExpression ge(&lfbt);
+ this->Internal->CompileDefinitionsEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
+ }
+ else if(prop == "EXPORT_NAME" && this->IsImported())
+ {
+ cmOStringStream e;
+ e << "EXPORT_NAME property can't be set on imported targets (\""
+ << this->Name << "\")\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ else if (prop == "LINK_LIBRARIES")
+ {
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmValueWithOrigin entry(value, lfbt);
+ this->Internal->LinkImplementationPropertyEntries.push_back(entry);
+ }
+ else if (prop == "SOURCES")
+ {
+ if(this->IsImported())
+ {
+ cmOStringStream e;
+ e << "SOURCES property can't be set on imported targets (\""
+ << this->Name << "\")\n";
+ 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));
+ }
+ else
+ {
+ this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
+ this->MaybeInvalidatePropertyCache(prop);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetExportName() const
+{
+ const char *exportName = this->GetProperty("EXPORT_NAME");
+
+ if (exportName && *exportName)
+ {
+ if (!cmGeneratorExpression::IsValidTargetName(exportName))
+ {
+ cmOStringStream 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 &&
+ !this->IsExecutableWithExports())
+ {
+ return;
+ }
+ if (this->BuildInterfaceIncludesAppended)
+ {
+ return;
+ }
+ this->BuildInterfaceIncludesAppended = true;
+
+ if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
+ {
+ const char *binDir = this->Makefile->GetStartOutputDirectory();
+ const char *srcDir = this->Makefile->GetStartDirectory();
+ const std::string dirs = std::string(binDir ? binDir : "")
+ + std::string(binDir ? ";" : "")
+ + std::string(srcDir ? srcDir : "");
+ if (!dirs.empty())
+ {
+ this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
+ ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::InsertInclude(const cmValueWithOrigin &entry,
+ bool before)
+{
+ cmGeneratorExpression ge(&entry.Backtrace);
+
+ std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
+ = before ? this->Internal->IncludeDirectoriesEntries.begin()
+ : this->Internal->IncludeDirectoriesEntries.end();
+
+ this->Internal->IncludeDirectoriesEntries.insert(position,
+ new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::InsertCompileOption(const cmValueWithOrigin &entry,
+ bool before)
+{
+ cmGeneratorExpression ge(&entry.Backtrace);
+
+ std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
+ = before ? this->Internal->CompileOptionsEntries.begin()
+ : this->Internal->CompileOptionsEntries.end();
+
+ this->Internal->CompileOptionsEntries.insert(position,
+ new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::InsertCompileDefinition(const cmValueWithOrigin &entry)
+{
+ cmGeneratorExpression ge(&entry.Backtrace);
+
+ this->Internal->CompileDefinitionsEntries.push_back(
+ new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
+}
+
+//----------------------------------------------------------------------------
+static void processIncludeDirectories(cmTarget const* tgt,
+ const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
+ std::vector<std::string> &includes,
+ UNORDERED_SET<std::string> &uniqueIncludes,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ const std::string& config, bool debugIncludes)
+{
+ cmMakefile *mf = tgt->GetMakefile();
+
+ 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;
+ bool const fromImported = item.Target && item.Target->IsImported();
+ bool const checkCMP0027 = item.FromGenex;
+ std::vector<std::string> entryIncludes;
+ cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
+ config,
+ false,
+ tgt,
+ dagChecker),
+ entryIncludes);
+
+ std::string usedIncludes;
+ for(std::vector<std::string>::iterator
+ li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
+ {
+ if (fromImported
+ && !cmSystemTools::FileExists(li->c_str()))
+ {
+ cmOStringStream e;
+ cmake::MessageType messageType = cmake::FATAL_ERROR;
+ if (checkCMP0027)
+ {
+ switch(tgt->GetPolicyStatusCMP0027())
+ {
+ case cmPolicies::WARN:
+ e << (mf->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0027)) << "\n";
+ case cmPolicies::OLD:
+ messageType = cmake::AUTHOR_WARNING;
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW:
+ break;
+ }
+ }
+ e << "Imported target \"" << targetName << "\" includes "
+ "non-existent path\n \"" << *li << "\"\nin its "
+ "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
+ "* The path was deleted, renamed, or moved to another "
+ "location.\n"
+ "* An install or uninstall procedure did not complete "
+ "successfully.\n"
+ "* The installation package was faulty and references files it "
+ "does not provide.\n";
+ tgt->GetMakefile()->IssueMessage(messageType, e.str());
+ return;
+ }
+
+ if (!cmSystemTools::FileIsFullPath(li->c_str()))
+ {
+ cmOStringStream e;
+ bool noMessage = false;
+ cmake::MessageType messageType = cmake::FATAL_ERROR;
+ if (!targetName.empty())
+ {
+ e << "Target \"" << targetName << "\" contains relative "
+ "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
+ " \"" << *li << "\"";
+ }
+ else
+ {
+ switch(tgt->GetPolicyStatusCMP0021())
+ {
+ case cmPolicies::WARN:
+ {
+ e << (mf->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0021)) << "\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;
+ }
+ e << "Found relative path while evaluating include directories of "
+ "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
+ }
+ if (!noMessage)
+ {
+ tgt->GetMakefile()->IssueMessage(messageType, e.str());
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return;
+ }
+ }
+ }
+
+ if (!cmSystemTools::IsOff(li->c_str()))
+ {
+ cmSystemTools::ConvertToUnixSlashes(*li);
+ }
+ std::string inc = *li;
+
+ if(uniqueIncludes.insert(inc).second)
+ {
+ includes.push_back(inc);
+ if (debugIncludes)
+ {
+ usedIncludes += " * " + inc + "\n";
+ }
+ }
+ }
+ if (!usedIncludes.empty())
+ {
+ mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
+ std::string("Used includes for target ")
+ + tgt->GetName() + ":\n"
+ + usedIncludes, (*it)->ge->GetBacktrace());
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string>
+cmTarget::GetIncludeDirectories(const std::string& config) const
+{
+ std::vector<std::string> includes;
+ UNORDERED_SET<std::string> uniqueIncludes;
+
+ cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
+ "INCLUDE_DIRECTORIES", 0, 0);
+
+ std::vector<std::string> debugProperties;
+ const char *debugProp =
+ this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
+ if (debugProp)
+ {
+ cmSystemTools::ExpandListArgument(debugProp, debugProperties);
+ }
+
+ bool debugIncludes = !this->DebugIncludesDone
+ && std::find(debugProperties.begin(),
+ debugProperties.end(),
+ "INCLUDE_DIRECTORIES")
+ != debugProperties.end();
+
+ if (this->Makefile->IsGeneratingBuildSystem())
+ {
+ this->DebugIncludesDone = true;
+ }
+
+ processIncludeDirectories(this,
+ this->Internal->IncludeDirectoriesEntries,
+ includes,
+ uniqueIncludes,
+ &dagChecker,
+ config,
+ debugIncludes);
+
+ std::vector<cmTargetInternals::TargetPropertyEntry*>
+ linkInterfaceIncludeDirectoriesEntries;
+ this->Internal->AddInterfaceEntries(
+ this, config, "INTERFACE_INCLUDE_DIRECTORIES",
+ linkInterfaceIncludeDirectoriesEntries);
+
+ if(this->Makefile->IsOn("APPLE"))
+ {
+ LinkImplementation const* impl = this->GetLinkImplementation(config);
+ for(std::vector<cmLinkImplItem>::const_iterator
+ it = impl->Libraries.begin();
+ it != impl->Libraries.end(); ++it)
+ {
+ std::string libDir = cmSystemTools::CollapseFullPath(it->c_str());
+
+ static cmsys::RegularExpression
+ frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
+ if(!frameworkCheck.find(libDir))
+ {
+ continue;
+ }
+
+ libDir = frameworkCheck.match(1);
+
+ cmGeneratorExpression ge;
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(libDir.c_str());
+ linkInterfaceIncludeDirectoriesEntries
+ .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
+ }
+ }
+
+ processIncludeDirectories(this,
+ linkInterfaceIncludeDirectoriesEntries,
+ includes,
+ uniqueIncludes,
+ &dagChecker,
+ config,
+ debugIncludes);
+
+ deleteAndClear(linkInterfaceIncludeDirectoriesEntries);
+
+ return includes;
+}
+
+//----------------------------------------------------------------------------
+static void processCompileOptionsInternal(cmTarget const* tgt,
+ const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
+ std::vector<std::string> &options,
+ UNORDERED_SET<std::string> &uniqueOptions,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ const std::string& config, bool debugOptions, const char *logName)
+{
+ cmMakefile *mf = tgt->GetMakefile();
+
+ for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
+ it = entries.begin(), end = entries.end(); it != end; ++it)
+ {
+ std::vector<std::string> entryOptions;
+ cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
+ config,
+ false,
+ tgt,
+ dagChecker),
+ entryOptions);
+ std::string usedOptions;
+ for(std::vector<std::string>::iterator
+ li = entryOptions.begin(); li != entryOptions.end(); ++li)
+ {
+ std::string const& opt = *li;
+
+ if(uniqueOptions.insert(opt).second)
+ {
+ options.push_back(opt);
+ if (debugOptions)
+ {
+ usedOptions += " * " + opt + "\n";
+ }
+ }
+ }
+ if (!usedOptions.empty())
+ {
+ mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
+ std::string("Used compile ") + logName
+ + std::string(" for target ")
+ + tgt->GetName() + ":\n"
+ + usedOptions, (*it)->ge->GetBacktrace());
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+static void processCompileOptions(cmTarget const* tgt,
+ const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
+ std::vector<std::string> &options,
+ UNORDERED_SET<std::string> &uniqueOptions,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ const std::string& config, bool debugOptions)
+{
+ processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
+ dagChecker, config, debugOptions, "options");
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetAutoUicOptions(std::vector<std::string> &result,
+ const std::string& config) const
+{
+ const char *prop
+ = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
+ config);
+ if (!prop)
+ {
+ return;
+ }
+ cmGeneratorExpression ge;
+
+ cmGeneratorExpressionDAGChecker dagChecker(
+ this->GetName(),
+ "AUTOUIC_OPTIONS", 0, 0);
+ cmSystemTools::ExpandListArgument(ge.Parse(prop)
+ ->Evaluate(this->Makefile,
+ config,
+ false,
+ this,
+ &dagChecker),
+ result);
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetCompileOptions(std::vector<std::string> &result,
+ const std::string& config) const
+{
+ UNORDERED_SET<std::string> uniqueOptions;
+
+ cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
+ "COMPILE_OPTIONS", 0, 0);
+
+ std::vector<std::string> debugProperties;
+ const char *debugProp =
+ this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
+ if (debugProp)
+ {
+ cmSystemTools::ExpandListArgument(debugProp, debugProperties);
+ }
+
+ bool debugOptions = !this->DebugCompileOptionsDone
+ && std::find(debugProperties.begin(),
+ debugProperties.end(),
+ "COMPILE_OPTIONS")
+ != debugProperties.end();
+
+ if (this->Makefile->IsGeneratingBuildSystem())
+ {
+ this->DebugCompileOptionsDone = true;
+ }
+
+ processCompileOptions(this,
+ this->Internal->CompileOptionsEntries,
+ result,
+ uniqueOptions,
+ &dagChecker,
+ config,
+ debugOptions);
+
+ std::vector<cmTargetInternals::TargetPropertyEntry*>
+ linkInterfaceCompileOptionsEntries;
+
+ this->Internal->AddInterfaceEntries(
+ this, config, "INTERFACE_COMPILE_OPTIONS",
+ linkInterfaceCompileOptionsEntries);
+
+ processCompileOptions(this,
+ linkInterfaceCompileOptionsEntries,
+ result,
+ uniqueOptions,
+ &dagChecker,
+ config,
+ debugOptions);
+
+ deleteAndClear(linkInterfaceCompileOptionsEntries);
+}
+
+//----------------------------------------------------------------------------
+static void processCompileDefinitions(cmTarget const* tgt,
+ const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
+ std::vector<std::string> &options,
+ UNORDERED_SET<std::string> &uniqueOptions,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ const std::string& config, bool debugOptions)
+{
+ processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
+ dagChecker, config, debugOptions,
+ "definitions");
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
+ const std::string& config) const
+{
+ UNORDERED_SET<std::string> uniqueOptions;
+
+ cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
+ "COMPILE_DEFINITIONS", 0, 0);
+
+ std::vector<std::string> debugProperties;
+ const char *debugProp =
+ this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
+ if (debugProp)
+ {
+ cmSystemTools::ExpandListArgument(debugProp, debugProperties);
+ }
+
+ bool debugDefines = !this->DebugCompileDefinitionsDone
+ && std::find(debugProperties.begin(),
+ debugProperties.end(),
+ "COMPILE_DEFINITIONS")
+ != debugProperties.end();
+
+ if (this->Makefile->IsGeneratingBuildSystem())
+ {
+ this->DebugCompileDefinitionsDone = true;
+ }
+
+ processCompileDefinitions(this,
+ this->Internal->CompileDefinitionsEntries,
+ list,
+ uniqueOptions,
+ &dagChecker,
+ config,
+ debugDefines);
+
+ std::vector<cmTargetInternals::TargetPropertyEntry*>
+ linkInterfaceCompileDefinitionsEntries;
+ this->Internal->AddInterfaceEntries(
+ this, config, "INTERFACE_COMPILE_DEFINITIONS",
+ linkInterfaceCompileDefinitionsEntries);
+ if (!config.empty())
+ {
+ std::string configPropName = "COMPILE_DEFINITIONS_"
+ + cmSystemTools::UpperCase(config);
+ const char *configProp = this->GetProperty(configPropName);
+ if (configProp)
+ {
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
+ {
+ case cmPolicies::WARN:
+ {
+ cmOStringStream e;
+ e << this->Makefile->GetCMakeInstance()->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0043);
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ e.str());
+ }
+ case cmPolicies::OLD:
+ {
+ cmGeneratorExpression ge;
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(configProp);
+ linkInterfaceCompileDefinitionsEntries
+ .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
+ }
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ break;
+ }
+ }
+ }
+
+ processCompileDefinitions(this,
+ linkInterfaceCompileDefinitionsEntries,
+ list,
+ uniqueOptions,
+ &dagChecker,
+ config,
+ debugDefines);
+
+ deleteAndClear(linkInterfaceCompileDefinitionsEntries);
+}
+
+//----------------------------------------------------------------------------
+static void processCompileFeatures(cmTarget const* tgt,
+ const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
+ std::vector<std::string> &options,
+ UNORDERED_SET<std::string> &uniqueOptions,
+ cmGeneratorExpressionDAGChecker *dagChecker,
+ const std::string& config, bool debugOptions)
+{
+ processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
+ dagChecker, config, debugOptions, "features");
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetCompileFeatures(std::vector<std::string> &result,
+ const std::string& config) const
+{
+ UNORDERED_SET<std::string> uniqueFeatures;
+
+ cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
+ "COMPILE_FEATURES",
+ 0, 0);
+
+ std::vector<std::string> debugProperties;
+ const char *debugProp =
+ this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
+ if (debugProp)
+ {
+ cmSystemTools::ExpandListArgument(debugProp, debugProperties);
+ }
+
+ bool debugFeatures = !this->DebugCompileFeaturesDone
+ && std::find(debugProperties.begin(),
+ debugProperties.end(),
+ "COMPILE_FEATURES")
+ != debugProperties.end();
+
+ if (this->Makefile->IsGeneratingBuildSystem())
+ {
+ this->DebugCompileFeaturesDone = true;
+ }
+
+ processCompileFeatures(this,
+ this->Internal->CompileFeaturesEntries,
+ result,
+ uniqueFeatures,
+ &dagChecker,
+ config,
+ debugFeatures);
+
+ std::vector<cmTargetInternals::TargetPropertyEntry*>
+ linkInterfaceCompileFeaturesEntries;
+ this->Internal->AddInterfaceEntries(
+ this, config, "INTERFACE_COMPILE_FEATURES",
+ linkInterfaceCompileFeaturesEntries);
+
+ processCompileFeatures(this,
+ linkInterfaceCompileFeaturesEntries,
+ result,
+ uniqueFeatures,
+ &dagChecker,
+ config,
+ debugFeatures);
+
+ deleteAndClear(linkInterfaceCompileFeaturesEntries);
+}
+
+//----------------------------------------------------------------------------
+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)
+{
+ // Look for link-type keywords in the value.
+ static cmsys::RegularExpression
+ keys("(^|;)(debug|optimized|general)(;|$)");
+ if(!keys.find(value))
+ {
+ return;
+ }
+
+ // Support imported and non-imported versions of the property.
+ const char* base = (imported?
+ "IMPORTED_LINK_INTERFACE_LIBRARIES" :
+ "LINK_INTERFACE_LIBRARIES");
+
+ // Report an error.
+ cmOStringStream e;
+ e << "Property " << prop << " may not contain link-type keyword \""
+ << keys.match(2) << "\". "
+ << "The " << base << " property has a per-configuration "
+ << "version called " << base << "_<CONFIG> which may be "
+ << "used to specify per-configuration rules.";
+ if(!imported)
+ {
+ e << " "
+ << "Alternatively, an IMPORTED library may be created, configured "
+ << "with a per-configuration location, and then named in the "
+ << "property value. "
+ << "See the add_library command's IMPORTED mode for details."
+ << "\n"
+ << "If you have a list of libraries that already contains the "
+ << "keyword, use the target_link_libraries command with its "
+ << "LINK_INTERFACE_LIBRARIES mode to set the property. "
+ << "The command automatically recognizes link-type keywords and sets "
+ << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
+ << "properties accordingly.";
+ }
+ context->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+//----------------------------------------------------------------------------
+static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
+ cmMakefile* context)
+{
+ // Look for link-type keywords in the value.
+ static cmsys::RegularExpression
+ keys("(^|;)(debug|optimized|general)(;|$)");
+ if(!keys.find(value))
+ {
+ return;
+ }
+
+ // Report an error.
+ cmOStringStream e;
+
+ e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
+ "keyword \"" << keys.match(2) << "\". The INTERFACE_LINK_LIBRARIES "
+ "property may contain configuration-sensitive generator-expressions "
+ "which may be used to specify per-configuration rules.";
+
+ context->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::CheckProperty(const std::string& prop,
+ cmMakefile* context) const
+{
+ // Certain properties need checking.
+ if(cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES"))
+ {
+ if(const char* value = this->GetProperty(prop))
+ {
+ cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
+ }
+ }
+ if(cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES"))
+ {
+ if(const char* value = this->GetProperty(prop))
+ {
+ cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
+ }
+ }
+ if(cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES"))
+ {
+ if(const char* value = this->GetProperty(prop))
+ {
+ cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::MarkAsImported()
+{
+ this->IsImportedTarget = true;
+}
+
+//----------------------------------------------------------------------------
+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
+{
+ // There is no output information for imported targets.
+ if(this->IsImported())
+ {
+ return 0;
+ }
+
+ // Only libraries and executables have well-defined output files.
+ if(!this->HaveWellDefinedOutputFiles())
+ {
+ 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;
+ }
+
+ // Lookup/compute/cache the output information for this configuration.
+ std::string config_upper;
+ if(!config.empty())
+ {
+ config_upper = cmSystemTools::UpperCase(config);
+ }
+ typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
+ OutputInfoMapType::const_iterator i =
+ this->Internal->OutputInfoMap.find(config_upper);
+ if(i == this->Internal->OutputInfoMap.end())
+ {
+ OutputInfo info;
+ this->ComputeOutputDir(config, false, info.OutDir);
+ this->ComputeOutputDir(config, true, info.ImpDir);
+ if(!this->ComputePDBOutputDir("PDB", config, info.PdbDir))
+ {
+ info.PdbDir = info.OutDir;
+ }
+ OutputInfoMapType::value_type entry(config_upper, info);
+ i = this->Internal->OutputInfoMap.insert(entry).first;
+ }
+ return &i->second;
+}
+
+//----------------------------------------------------------------------------
+cmTarget::CompileInfo const* cmTarget::GetCompileInfo(
+ const std::string& config) const
+{
+ // There is no compile information for imported targets.
+ if(this->IsImported())
+ {
+ return 0;
+ }
+
+ if(this->GetType() > cmTarget::OBJECT_LIBRARY)
+ {
+ std::string msg = "cmTarget::GetCompileInfo called for ";
+ msg += this->GetName();
+ msg += " which has type ";
+ msg += cmTarget::GetTargetTypeName(this->GetType());
+ this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
+ return 0;
+ }
+
+ // Lookup/compute/cache the compile information for this configuration.
+ std::string config_upper;
+ if(!config.empty())
+ {
+ config_upper = cmSystemTools::UpperCase(config);
+ }
+ typedef cmTargetInternals::CompileInfoMapType CompileInfoMapType;
+ CompileInfoMapType::const_iterator i =
+ this->Internal->CompileInfoMap.find(config_upper);
+ if(i == this->Internal->CompileInfoMap.end())
+ {
+ CompileInfo info;
+ this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
+ CompileInfoMapType::value_type entry(config_upper, info);
+ i = this->Internal->CompileInfoMap.insert(entry).first;
+ }
+ return &i->second;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetDirectory(const std::string& config,
+ bool implib) 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 "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetCompilePDBDirectory(const std::string& config) const
+{
+ if(CompileInfo const* info = this->GetCompileInfo(config))
+ {
+ return info->CompilePdbDir;
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+const char* cmTarget::GetLocation(const std::string& config) const
+{
+ static std::string location;
+ if (this->IsImported())
+ {
+ location = this->ImportedGetFullPath(config, false);
+ }
+ else
+ {
+ location = this->GetFullPath(config, false);
+ }
+ return location.c_str();
+}
+
+//----------------------------------------------------------------------------
+const char* cmTarget::GetLocationForBuild() const
+{
+ static std::string location;
+ if(this->IsImported())
+ {
+ location = this->ImportedGetFullPath("", false);
+ return location.c_str();
+ }
+
+ // Now handle the deprecated build-time configuration location.
+ location = this->GetDirectory();
+ const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
+ if(cfgid && strcmp(cfgid, ".") != 0)
+ {
+ location += "/";
+ location += cfgid;
+ }
+
+ if(this->IsAppBundleOnApple())
+ {
+ std::string macdir = this->BuildMacContentDirectory("", "", false);
+ if(!macdir.empty())
+ {
+ location += "/";
+ location += macdir;
+ }
+ }
+ location += "/";
+ location += this->GetFullName("", 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;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmTarget::GetFeature(const std::string& feature,
+ const std::string& config) const
+{
+ if(!config.empty())
+ {
+ std::string featureConfig = feature;
+ featureConfig += "_";
+ featureConfig += cmSystemTools::UpperCase(config);
+ if(const char* value = this->GetProperty(featureConfig))
+ {
+ return value;
+ }
+ }
+ if(const char* value = this->GetProperty(feature))
+ {
+ return value;
+ }
+ return this->Makefile->GetFeature(feature, config);
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::GetFeatureAsBool(const std::string& feature,
+ const std::string& config) const
+{
+ return cmSystemTools::IsOn(this->GetFeature(feature, config));
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
+{
+ if (this->IsImported())
+ {
+ return true;
+ }
+ cmOStringStream e;
+ const char *modal = 0;
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ switch (context->GetPolicyStatus(cmPolicies::CMP0026))
+ {
+ case cmPolicies::WARN:
+ e << (this->Makefile->GetPolicies()
+ ->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;
+}
+
+//----------------------------------------------------------------------------
+static void MakePropertyList(std::string& output,
+ std::vector<cmTargetInternals::TargetPropertyEntry*> const& values)
+{
+ output = "";
+ std::string sep;
+ for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
+ it = values.begin(), end = values.end();
+ it != end; ++it)
+ {
+ output += sep;
+ output += (*it)->ge->GetInput();
+ sep = ";";
+ }
+}
+
+//----------------------------------------------------------------------------
+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
+ && !whiteListedInterfaceProperty(prop))
+ {
+ cmOStringStream e;
+ e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
+ "The property \"" << prop << "\" is not allowed.";
+ context->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return 0;
+ }
+
+ // 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)
+ {
+ static const std::string propLOCATION = "LOCATION";
+ if(prop == propLOCATION)
+ {
+ if (!this->HandleLocationPropertyPolicy(context))
+ {
+ return 0;
+ }
+
+ // Set the LOCATION property of the target.
+ //
+ // For an imported target this is the location of an arbitrary
+ // available configuration.
+ //
+ // For a non-imported target this is deprecated because it
+ // cannot take into account the per-configuration name of the
+ // target because the configuration type may not be known at
+ // CMake time.
+ this->Properties.SetProperty(propLOCATION, this->GetLocationForBuild(),
+ cmProperty::TARGET);
+ }
+
+ // Support "LOCATION_<CONFIG>".
+ else if(cmHasLiteralPrefix(prop, "LOCATION_"))
+ {
+ if (!this->HandleLocationPropertyPolicy(context))
+ {
+ return 0;
+ }
+ const char* configName = prop.c_str() + 9;
+ this->Properties.SetProperty(prop,
+ this->GetLocation(configName),
+ cmProperty::TARGET);
+ }
+ // Support "<CONFIG>_LOCATION".
+ else if(cmHasLiteralSuffix(prop, "_LOCATION"))
+ {
+ std::string configName(prop.c_str(), prop.size() - 9);
+ if(configName != "IMPORTED")
+ {
+ if (!this->HandleLocationPropertyPolicy(context))
+ {
+ return 0;
+ }
+ this->Properties.SetProperty(prop,
+ this->GetLocation(configName),
+ cmProperty::TARGET);
+ }
+ }
+ }
+ static UNORDERED_SET<std::string> specialProps;
+#define MAKE_STATIC_PROP(PROP) \
+ static const std::string prop##PROP = #PROP
+ MAKE_STATIC_PROP(LINK_LIBRARIES);
+ MAKE_STATIC_PROP(TYPE);
+ MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
+ MAKE_STATIC_PROP(COMPILE_FEATURES);
+ MAKE_STATIC_PROP(COMPILE_OPTIONS);
+ MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
+ MAKE_STATIC_PROP(IMPORTED);
+ MAKE_STATIC_PROP(NAME);
+ MAKE_STATIC_PROP(SOURCES);
+#undef MAKE_STATIC_PROP
+ if(specialProps.empty())
+ {
+ specialProps.insert(propLINK_LIBRARIES);
+ specialProps.insert(propTYPE);
+ specialProps.insert(propINCLUDE_DIRECTORIES);
+ specialProps.insert(propCOMPILE_FEATURES);
+ specialProps.insert(propCOMPILE_OPTIONS);
+ specialProps.insert(propCOMPILE_DEFINITIONS);
+ specialProps.insert(propIMPORTED);
+ specialProps.insert(propNAME);
+ specialProps.insert(propSOURCES);
+ }
+ if(specialProps.count(prop))
+ {
+ if(prop == propLINK_LIBRARIES)
+ {
+ if (this->Internal->LinkImplementationPropertyEntries.empty())
+ {
+ return 0;
+ }
+
+ 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 = ";";
+ }
+ return output.c_str();
+ }
+ // the type property returns what type the target is
+ else if (prop == propTYPE)
+ {
+ return cmTarget::GetTargetTypeName(this->GetType());
+ }
+ else if(prop == propINCLUDE_DIRECTORIES)
+ {
+ if (this->Internal->IncludeDirectoriesEntries.empty())
+ {
+ return 0;
+ }
+
+ static std::string output;
+ MakePropertyList(output, this->Internal->IncludeDirectoriesEntries);
+ return output.c_str();
+ }
+ else if(prop == propCOMPILE_FEATURES)
+ {
+ if (this->Internal->CompileFeaturesEntries.empty())
+ {
+ return 0;
+ }
+
+ static std::string output;
+ MakePropertyList(output, this->Internal->CompileFeaturesEntries);
+ return output.c_str();
+ }
+ else if(prop == propCOMPILE_OPTIONS)
+ {
+ if (this->Internal->CompileOptionsEntries.empty())
+ {
+ return 0;
+ }
+
+ static std::string output;
+ MakePropertyList(output, this->Internal->CompileOptionsEntries);
+ return output.c_str();
+ }
+ else if(prop == propCOMPILE_DEFINITIONS)
+ {
+ if (this->Internal->CompileDefinitionsEntries.empty())
+ {
+ return 0;
+ }
+
+ static std::string output;
+ MakePropertyList(output, this->Internal->CompileDefinitionsEntries);
+ return output.c_str();
+ }
+ else if (prop == propIMPORTED)
+ {
+ return this->IsImported()?"TRUE":"FALSE";
+ }
+ else if (prop == propNAME)
+ {
+ return this->GetName().c_str();
+ }
+ else if(prop == propSOURCES)
+ {
+ if (this->Internal->SourceEntries.empty())
+ {
+ return 0;
+ }
+
+ cmOStringStream ss;
+ const char* sep = "";
+ 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)
+ {
+ ss << sep;
+ sep = ";";
+ ss << *li;
+ continue;
+ }
+
+ bool addContent = false;
+ bool noMessage = true;
+ cmOStringStream e;
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ switch(context->GetPolicyStatus(cmPolicies::CMP0051))
+ {
+ case cmPolicies::WARN:
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0051)) << "\n";
+ noMessage = false;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW:
+ addContent = true;
+ }
+ if (!noMessage)
+ {
+ e << "Target \"" << this->Name << "\" contains "
+ "$<TARGET_OBJECTS> generator expression in its sources list. "
+ "This content was not previously part of the SOURCES property "
+ "when that property was read at configure time. Code reading "
+ "that property needs to be adapted to ignore the generator "
+ "expression using the string(GENEX_STRIP) command.";
+ context->IssueMessage(messageType, e.str());
+ }
+ if (addContent)
+ {
+ ss << sep;
+ sep = ";";
+ ss << *li;
+ }
+ }
+ else if (cmGeneratorExpression::Find(*li) == std::string::npos)
+ {
+ ss << sep;
+ sep = ";";
+ ss << *li;
+ }
+ else
+ {
+ cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
+ // Construct what is known about this source file location.
+ cmSourceFileLocation const& location = sf->GetLocation();
+ std::string sname = location.GetDirectory();
+ if(!sname.empty())
+ {
+ sname += "/";
+ }
+ sname += location.GetName();
+
+ ss << sep;
+ sep = ";";
+ // Append this list entry.
+ ss << sname;
+ }
+ }
+ }
+ this->Properties.SetProperty("SOURCES", ss.str().c_str(),
+ cmProperty::TARGET);
+ }
+ }
+
+ bool chain = false;
+ const char *retVal =
+ this->Properties.GetPropertyValue(prop, cmProperty::TARGET, chain);
+ if (chain)
+ {
+ return this->Makefile->GetProperty(prop, cmProperty::TARGET);
+ }
+ return retVal;
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::GetPropertyAsBool(const std::string& prop) const
+{
+ return cmSystemTools::IsOn(this->GetProperty(prop));
+}
+
+//----------------------------------------------------------------------------
+class cmTargetCollectLinkLanguages
+{
+public:
+ cmTargetCollectLinkLanguages(cmTarget const* target,
+ const std::string& config,
+ UNORDERED_SET<std::string>& languages,
+ cmTarget const* head):
+ Config(config), Languages(languages), HeadTarget(head),
+ Makefile(target->GetMakefile()), Target(target)
+ { this->Visited.insert(target); }
+
+ void Visit(cmLinkItem const& item)
+ {
+ if(!item.Target)
+ {
+ if(item.find("::") != std::string::npos)
+ {
+ bool noMessage = false;
+ cmake::MessageType messageType = cmake::FATAL_ERROR;
+ cmOStringStream e;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
+ {
+ case cmPolicies::WARN:
+ {
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0028)) << "\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->Target->GetName()
+ << "\" links to target \"" << item
+ << "\" 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->GetBacktrace());
+ }
+ }
+ return;
+ }
+ if(!this->Visited.insert(item.Target).second)
+ {
+ return;
+ }
+
+ cmTarget::LinkInterface const* iface =
+ item.Target->GetLinkInterface(this->Config, this->HeadTarget);
+ if(!iface) { return; }
+
+ for(std::vector<std::string>::const_iterator
+ li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
+ {
+ this->Languages.insert(*li);
+ }
+
+ for(std::vector<cmLinkItem>::const_iterator
+ li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
+ {
+ this->Visit(*li);
+ }
+ }
+private:
+ std::string Config;
+ UNORDERED_SET<std::string>& Languages;
+ cmTarget const* HeadTarget;
+ cmMakefile* Makefile;
+ const cmTarget* Target;
+ std::set<cmTarget const*> Visited;
+};
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetLinkerLanguage(const std::string& config) const
+{
+ return this->GetLinkClosure(config)->LinkerLanguage;
+}
+
+//----------------------------------------------------------------------------
+cmTarget::LinkClosure const*
+cmTarget::GetLinkClosure(const std::string& config) const
+{
+ std::string key(cmSystemTools::UpperCase(config));
+ cmTargetInternals::LinkClosureMapType::iterator
+ i = this->Internal->LinkClosureMap.find(key);
+ if(i == this->Internal->LinkClosureMap.end())
+ {
+ LinkClosure lc;
+ this->ComputeLinkClosure(config, lc);
+ cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
+ i = this->Internal->LinkClosureMap.insert(entry).first;
+ }
+ return &i->second;
+}
+
+//----------------------------------------------------------------------------
+class cmTargetSelectLinker
+{
+ int Preference;
+ cmTarget const* Target;
+ cmMakefile* Makefile;
+ cmGlobalGenerator* GG;
+ UNORDERED_SET<std::string> Preferred;
+public:
+ cmTargetSelectLinker(cmTarget const* target): Preference(0), Target(target)
+ {
+ this->Makefile = this->Target->GetMakefile();
+ this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
+ }
+ void Consider(const std::string& lang)
+ {
+ int preference = this->GG->GetLinkerPreference(lang);
+ if(preference > this->Preference)
+ {
+ this->Preference = preference;
+ this->Preferred.clear();
+ }
+ if(preference == this->Preference)
+ {
+ this->Preferred.insert(lang);
+ }
+ }
+ std::string Choose()
+ {
+ if(this->Preferred.empty())
+ {
+ return "";
+ }
+ else if(this->Preferred.size() > 1)
+ {
+ cmOStringStream e;
+ e << "Target " << this->Target->GetName()
+ << " contains multiple languages with the highest linker preference"
+ << " (" << this->Preference << "):\n";
+ for(UNORDERED_SET<std::string>::const_iterator
+ li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
+ {
+ e << " " << *li << "\n";
+ }
+ e << "Set the LINKER_LANGUAGE property for this target.";
+ cmake* cm = this->Makefile->GetCMakeInstance();
+ cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->Target->GetBacktrace());
+ }
+ return *this->Preferred.begin();
+ }
+};
+
+//----------------------------------------------------------------------------
+void cmTarget::ComputeLinkClosure(const std::string& config,
+ LinkClosure& lc) const
+{
+ // Get languages built in this target.
+ UNORDERED_SET<std::string> languages;
+ LinkImplementation const* impl = this->GetLinkImplementation(config);
+ for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
+ li != impl->Languages.end(); ++li)
+ {
+ languages.insert(*li);
+ }
+
+ // Add interface languages from linked targets.
+ cmTargetCollectLinkLanguages cll(this, config, languages, this);
+ for(std::vector<cmLinkImplItem>::const_iterator
+ li = impl->Libraries.begin();
+ li != impl->Libraries.end(); ++li)
+ {
+ cll.Visit(*li);
+ }
+
+ // Store the transitive closure of languages.
+ for(UNORDERED_SET<std::string>::const_iterator li = languages.begin();
+ li != languages.end(); ++li)
+ {
+ lc.Languages.push_back(*li);
+ }
+
+ // Choose the language whose linker should be used.
+ if(this->GetProperty("HAS_CXX"))
+ {
+ lc.LinkerLanguage = "CXX";
+ }
+ else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
+ {
+ lc.LinkerLanguage = linkerLang;
+ }
+ else
+ {
+ // Find the language with the highest preference value.
+ cmTargetSelectLinker tsl(this);
+
+ // First select from the languages compiled directly in this target.
+ for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
+ li != impl->Languages.end(); ++li)
+ {
+ tsl.Consider(*li);
+ }
+
+ // Now consider languages that propagate from linked targets.
+ for(UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
+ sit != languages.end(); ++sit)
+ {
+ std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
+ if(this->Makefile->IsOn(propagates))
+ {
+ tsl.Consider(*sit);
+ }
+ }
+
+ lc.LinkerLanguage = tsl.Choose();
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::ExpandLinkItems(std::string const& prop,
+ std::string const& value,
+ std::string const& config,
+ cmTarget const* headTarget,
+ bool usage_requirements_only,
+ std::vector<cmLinkItem>& items,
+ bool& hadHeadSensitiveCondition) const
+{
+ cmGeneratorExpression ge;
+ cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
+ // The $<LINK_ONLY> expression may be in a link interface to specify private
+ // link dependencies that are otherwise excluded from usage requirements.
+ if(usage_requirements_only)
+ {
+ dagChecker.SetTransitivePropertiesOnly();
+ }
+ std::vector<std::string> libs;
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+ cmSystemTools::ExpandListArgument(cge->Evaluate(
+ this->Makefile,
+ config,
+ false,
+ headTarget,
+ this, &dagChecker), libs);
+ this->LookupLinkItems(libs, items);
+ hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::LookupLinkItems(std::vector<std::string> const& names,
+ std::vector<cmLinkItem>& items) const
+{
+ for(std::vector<std::string>::const_iterator i = names.begin();
+ i != names.end(); ++i)
+ {
+ std::string name = this->CheckCMP0004(*i);
+ if(name == this->GetName() || name.empty())
+ {
+ continue;
+ }
+ items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmTarget::GetSuffixVariableInternal(bool implib) const
+{
+ switch(this->GetType())
+ {
+ case cmTarget::STATIC_LIBRARY:
+ return "CMAKE_STATIC_LIBRARY_SUFFIX";
+ case cmTarget::SHARED_LIBRARY:
+ return (implib
+ ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
+ : "CMAKE_SHARED_LIBRARY_SUFFIX");
+ case cmTarget::MODULE_LIBRARY:
+ return (implib
+ ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
+ : "CMAKE_SHARED_MODULE_SUFFIX");
+ case cmTarget::EXECUTABLE:
+ return (implib
+ ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
+ // Android GUI application packages store the native
+ // binary as a shared library.
+ : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
+ "CMAKE_SHARED_LIBRARY_SUFFIX" : "CMAKE_EXECUTABLE_SUFFIX"));
+ default:
+ break;
+ }
+ return "";
+}
+
+
+//----------------------------------------------------------------------------
+const char* cmTarget::GetPrefixVariableInternal(bool implib) const
+{
+ switch(this->GetType())
+ {
+ case cmTarget::STATIC_LIBRARY:
+ return "CMAKE_STATIC_LIBRARY_PREFIX";
+ case cmTarget::SHARED_LIBRARY:
+ return (implib
+ ? "CMAKE_IMPORT_LIBRARY_PREFIX"
+ : "CMAKE_SHARED_LIBRARY_PREFIX");
+ case cmTarget::MODULE_LIBRARY:
+ return (implib
+ ? "CMAKE_IMPORT_LIBRARY_PREFIX"
+ : "CMAKE_SHARED_MODULE_PREFIX");
+ case cmTarget::EXECUTABLE:
+ return (implib
+ ? "CMAKE_IMPORT_LIBRARY_PREFIX"
+ // Android GUI application packages store the native
+ // binary as a shared library.
+ : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
+ "CMAKE_SHARED_LIBRARY_PREFIX" : ""));
+ default:
+ break;
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetPDBName(const std::string& config) const
+{
+ std::string prefix;
+ std::string base;
+ std::string suffix;
+ this->GetFullNameInternal(config, false, prefix, base, suffix);
+
+ std::vector<std::string> props;
+ std::string configUpper = cmSystemTools::UpperCase(config);
+ if(!configUpper.empty())
+ {
+ // PDB_NAME_<CONFIG>
+ props.push_back("PDB_NAME_" + configUpper);
+ }
+
+ // PDB_NAME
+ props.push_back("PDB_NAME");
+
+ for(std::vector<std::string>::const_iterator i = props.begin();
+ i != props.end(); ++i)
+ {
+ if(const char* outName = this->GetProperty(*i))
+ {
+ base = outName;
+ break;
+ }
+ }
+ return prefix+base+".pdb";
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetCompilePDBName(const std::string& config) const
+{
+ std::string prefix;
+ std::string base;
+ std::string suffix;
+ this->GetFullNameInternal(config, false, prefix, base, suffix);
+
+ // Check for a per-configuration output directory target property.
+ std::string configUpper = cmSystemTools::UpperCase(config);
+ std::string configProp = "COMPILE_PDB_NAME_";
+ configProp += configUpper;
+ const char* config_name = this->GetProperty(configProp);
+ if(config_name && *config_name)
+ {
+ return prefix + config_name + ".pdb";
+ }
+
+ const char* name = this->GetProperty("COMPILE_PDB_NAME");
+ if(name && *name)
+ {
+ return prefix + name + ".pdb";
+ }
+
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetCompilePDBPath(const std::string& config) const
+{
+ std::string dir = this->GetCompilePDBDirectory(config);
+ std::string name = this->GetCompilePDBName(config);
+ if(dir.empty() && !name.empty())
+ {
+ dir = this->GetPDBDirectory(config);
+ }
+ if(!dir.empty())
+ {
+ dir += "/";
+ }
+ return dir + name;
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::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 ||
+ this->GetType() == cmTarget::MODULE_LIBRARY) &&
+ !this->GetPropertyAsBool("NO_SONAME") &&
+ this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetSOName(const std::string& config) const
+{
+ if(this->IsImported())
+ {
+ // Lookup the imported soname.
+ if(cmTarget::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;
+ std::string realName;
+ std::string impName;
+ std::string pdbName;
+ this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
+ return soName;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
+{
+ bool install_name_is_rpath = false;
+ bool macosx_rpath = false;
+
+ if(!this->IsImportedTarget)
+ {
+ 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();
+ }
+ }
+ else
+ {
+ // Lookup the imported soname.
+ if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
+ {
+ if(!info->NoSOName && !info->SOName.empty())
+ {
+ if(info->SOName.find("@rpath/") == 0)
+ {
+ install_name_is_rpath = true;
+ }
+ }
+ else
+ {
+ std::string install_name;
+ cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
+ if(install_name.find("@rpath") != std::string::npos)
+ {
+ install_name_is_rpath = true;
+ }
+ }
+ }
+ }
+
+ if(!install_name_is_rpath && !macosx_rpath)
+ {
+ return false;
+ }
+
+ if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
+ {
+ cmOStringStream 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->GetLocalGenerator()->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;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::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->IsImported())
+ {
+ std::string msg = "NormalGetRealName called on imported target: ";
+ msg += this->GetName();
+ this->GetMakefile()->
+ IssueMessage(cmake::INTERNAL_ERROR,
+ msg);
+ }
+
+ if(this->GetType() == cmTarget::EXECUTABLE)
+ {
+ // Compute the real name that will be built.
+ std::string name;
+ std::string realName;
+ std::string impName;
+ std::string pdbName;
+ this->GetExecutableNames(name, realName, impName, pdbName, config);
+ return realName;
+ }
+ else
+ {
+ // Compute the real name that will be built.
+ std::string name;
+ std::string soName;
+ std::string realName;
+ std::string impName;
+ std::string pdbName;
+ this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
+ return realName;
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetFullName(const std::string& config,
+ bool implib) const
+{
+ if(this->IsImported())
+ {
+ return this->GetFullNameImported(config, implib);
+ }
+ else
+ {
+ return this->GetFullNameInternal(config, implib);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmTarget::GetFullNameImported(const std::string& config, bool implib) const
+{
+ return cmSystemTools::GetFilenameName(
+ this->ImportedGetFullPath(config, implib));
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
+ std::string& suffix,
+ const std::string& config,
+ bool implib) const
+{
+ this->GetFullNameInternal(config, implib, prefix, base, suffix);
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetFullPath(const std::string& config, bool implib,
+ bool realname) const
+{
+ if(this->IsImported())
+ {
+ return this->ImportedGetFullPath(config, implib);
+ }
+ else
+ {
+ return this->NormalGetFullPath(config, implib, realname);
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::NormalGetFullPath(const std::string& config,
+ bool implib, bool realname) const
+{
+ std::string fpath = this->GetDirectory(config, implib);
+ fpath += "/";
+ if(this->IsAppBundleOnApple())
+ {
+ fpath = this->BuildMacContentDirectory(fpath, config, false);
+ fpath += "/";
+ }
+
+ // Add the full name of the target.
+ if(implib)
+ {
+ fpath += this->GetFullName(config, true);
+ }
+ else if(realname)
+ {
+ fpath += this->NormalGetRealName(config);
+ }
+ else
+ {
+ fpath += this->GetFullName(config, false);
+ }
+ return fpath;
+}
+
+//----------------------------------------------------------------------------
+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();
+ result += "-NOTFOUND";
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmTarget::GetFullNameInternal(const std::string& config, bool implib) const
+{
+ std::string prefix;
+ std::string base;
+ std::string suffix;
+ this->GetFullNameInternal(config, implib, prefix, base, suffix);
+ return prefix+base+suffix;
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetFullNameInternal(const std::string& config,
+ bool implib,
+ std::string& outPrefix,
+ std::string& outBase,
+ 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)
+ {
+ outPrefix = "";
+ outBase = this->GetName();
+ outSuffix = "";
+ return;
+ }
+
+ // Return an empty name for the import library if this platform
+ // does not support import libraries.
+ if(implib &&
+ !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
+ {
+ outPrefix = "";
+ outBase = "";
+ outSuffix = "";
+ return;
+ }
+
+ // 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)
+ {
+ implib = false;
+ }
+
+ // Compute the full name for main target types.
+ const char* targetPrefix = (implib
+ ? this->GetProperty("IMPORT_PREFIX")
+ : this->GetProperty("PREFIX"));
+ const char* targetSuffix = (implib
+ ? this->GetProperty("IMPORT_SUFFIX")
+ : this->GetProperty("SUFFIX"));
+ const char* configPostfix = 0;
+ if(!config.empty())
+ {
+ std::string configProp = cmSystemTools::UpperCase(config);
+ configProp += "_POSTFIX";
+ configPostfix = this->GetProperty(configProp);
+ // Mac application bundles and frameworks have no postfix.
+ if(configPostfix &&
+ (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
+ {
+ configPostfix = 0;
+ }
+ }
+ const char* prefixVar = this->GetPrefixVariableInternal(implib);
+ const char* suffixVar = this->GetSuffixVariableInternal(implib);
+
+ // Check for language-specific default prefix and suffix.
+ std::string ll = this->GetLinkerLanguage(config);
+ if(!ll.empty())
+ {
+ if(!targetSuffix && suffixVar && *suffixVar)
+ {
+ std::string langSuff = suffixVar + std::string("_") + ll;
+ targetSuffix = this->Makefile->GetDefinition(langSuff);
+ }
+ if(!targetPrefix && prefixVar && *prefixVar)
+ {
+ std::string langPrefix = prefixVar + std::string("_") + ll;
+ targetPrefix = this->Makefile->GetDefinition(langPrefix);
+ }
+ }
+
+ // if there is no prefix on the target use the cmake definition
+ if(!targetPrefix && prefixVar)
+ {
+ targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
+ }
+ // if there is no suffix on the target use the cmake definition
+ if(!targetSuffix && suffixVar)
+ {
+ targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
+ }
+
+ // frameworks have directory prefix but no suffix
+ std::string fw_prefix;
+ if(this->IsFrameworkOnApple())
+ {
+ fw_prefix = this->GetOutputName(config, false);
+ fw_prefix += ".framework/";
+ targetPrefix = fw_prefix.c_str();
+ targetSuffix = 0;
+ }
+
+ if(this->IsCFBundleOnApple())
+ {
+ fw_prefix = this->GetOutputName(config, false);
+ fw_prefix += ".";
+ const char *ext = this->GetProperty("BUNDLE_EXTENSION");
+ if (!ext)
+ {
+ ext = "bundle";
+ }
+ fw_prefix += ext;
+ fw_prefix += "/Contents/MacOS/";
+ targetPrefix = fw_prefix.c_str();
+ targetSuffix = 0;
+ }
+
+ // Begin the final name with the prefix.
+ outPrefix = targetPrefix?targetPrefix:"";
+
+ // Append the target name or property-specified name.
+ outBase += this->GetOutputName(config, implib);
+
+ // Append the per-configuration postfix.
+ outBase += configPostfix?configPostfix:"";
+
+ // Name shared libraries with their version number on some platforms.
+ if(const char* soversion = this->GetProperty("SOVERSION"))
+ {
+ if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
+ this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
+ {
+ outBase += "-";
+ outBase += soversion;
+ }
+ }
+
+ // Append the suffix.
+ outSuffix = targetSuffix?targetSuffix:"";
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetLibraryNames(std::string& name,
+ std::string& soName,
+ std::string& realName,
+ std::string& impName,
+ std::string& pdbName,
+ 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->IsImported())
+ {
+ std::string msg = "GetLibraryNames called on imported target: ";
+ msg += this->GetName();
+ this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
+ msg);
+ return;
+ }
+
+ assert(this->GetType() != INTERFACE_LIBRARY);
+
+ // Check for library version properties.
+ const char* version = this->GetProperty("VERSION");
+ const char* soversion = this->GetProperty("SOVERSION");
+ if(!this->HasSOName(config) ||
+ this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
+ this->IsFrameworkOnApple())
+ {
+ // Versioning is supported only for shared libraries and modules,
+ // and then only when the platform supports an soname flag.
+ version = 0;
+ soversion = 0;
+ }
+ if(version && !soversion)
+ {
+ // The soversion must be set if the library version is set. Use
+ // the library version as the soversion.
+ soversion = version;
+ }
+ if(!version && soversion)
+ {
+ // Use the soversion as the library version.
+ version = soversion;
+ }
+
+ // Get the components of the library name.
+ std::string prefix;
+ std::string base;
+ std::string suffix;
+ this->GetFullNameInternal(config, false, prefix, base, suffix);
+
+ // The library name.
+ name = prefix+base+suffix;
+
+ if(this->IsFrameworkOnApple())
+ {
+ realName = prefix;
+ realName += "Versions/";
+ realName += this->GetFrameworkVersion();
+ realName += "/";
+ realName += base;
+ soName = realName;
+ }
+ else
+ {
+ // The library's soname.
+ this->ComputeVersionedName(soName, prefix, base, suffix,
+ name, soversion);
+ // The library's real name on disk.
+ this->ComputeVersionedName(realName, prefix, base, suffix,
+ name, version);
+ }
+
+ // The import library name.
+ if(this->GetType() == cmTarget::SHARED_LIBRARY ||
+ this->GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ impName = this->GetFullNameInternal(config, true);
+ }
+ else
+ {
+ impName = "";
+ }
+
+ // The program database file name.
+ pdbName = this->GetPDBName(config);
+}
+
+//----------------------------------------------------------------------------
+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();
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetExecutableNames(std::string& name,
+ std::string& realName,
+ std::string& impName,
+ std::string& pdbName,
+ 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->IsImported())
+ {
+ std::string msg =
+ "GetExecutableNames called on imported target: ";
+ msg += this->GetName();
+ this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
+ }
+
+ // This versioning is supported only for executables and then only
+ // when the platform supports symbolic links.
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ const char* version = 0;
+#else
+ // Check for executable version properties.
+ const char* version = this->GetProperty("VERSION");
+ if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
+ {
+ version = 0;
+ }
+#endif
+
+ // Get the components of the executable name.
+ std::string prefix;
+ std::string base;
+ std::string suffix;
+ this->GetFullNameInternal(config, false, prefix, base, suffix);
+
+ // The executable name.
+ name = prefix+base+suffix;
+
+ // The executable's real name on disk.
+#if defined(__CYGWIN__)
+ realName = prefix+base;
+#else
+ realName = name;
+#endif
+ if(version)
+ {
+ realName += "-";
+ realName += version;
+ }
+#if defined(__CYGWIN__)
+ realName += suffix;
+#endif
+
+ // The import library name.
+ impName = this->GetFullNameInternal(config, true);
+
+ // The program database file name.
+ pdbName = this->GetPDBName(config);
+}
+
+//----------------------------------------------------------------------------
+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)
+{
+ // Compute the name of the variable holding the default value.
+ std::string var = "CMAKE_";
+ var += property;
+
+ if(const char* value = this->Makefile->GetDefinition(var))
+ {
+ this->SetProperty(property, value);
+ }
+ else if(default_value)
+ {
+ this->SetProperty(property, default_value);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const
+{
+ if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
+ {
+ return false;
+ }
+ if(LinkImplementationLibraries const* impl =
+ this->GetLinkImplementationLibraries(config))
+ {
+ return !impl->Libraries.empty();
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::HaveInstallTreeRPATH() const
+{
+ const char* install_rpath = this->GetProperty("INSTALL_RPATH");
+ return (install_rpath && *install_rpath) &&
+ !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::NeedRelinkBeforeInstall(const std::string& config) const
+{
+ // Only executables and shared libraries can have an rpath and may
+ // need relinking.
+ if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
+ this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
+ this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
+ {
+ return false;
+ }
+
+ // If there is no install location this target will not be installed
+ // and therefore does not need relinking.
+ if(!this->GetHaveInstallRule())
+ {
+ return false;
+ }
+
+ // If skipping all rpaths completely then no relinking is needed.
+ if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
+ {
+ return false;
+ }
+
+ // If building with the install-tree rpath no relinking is needed.
+ if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
+ {
+ return false;
+ }
+
+ // If chrpath is going to be used no relinking is needed.
+ if(this->IsChrpathUsed(config))
+ {
+ return false;
+ }
+
+ // Check for rpath support on this platform.
+ std::string ll = this->GetLinkerLanguage(config);
+ if(!ll.empty())
+ {
+ std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
+ flagVar += ll;
+ flagVar += "_FLAG";
+ if(!this->Makefile->IsSet(flagVar))
+ {
+ // There is no rpath support on this platform so nothing needs
+ // relinking.
+ return false;
+ }
+ }
+ else
+ {
+ // No linker language is known. This error will be reported by
+ // other code.
+ return false;
+ }
+
+ // If either a build or install tree rpath is set then the rpath
+ // will likely change between the build tree and install tree and
+ // this target must be relinked.
+ return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetInstallNameDirForBuildTree(
+ const std::string& config) const
+{
+ // If building directly for installation then the build tree install_name
+ // is the same as the install tree.
+ if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
+ {
+ return GetInstallNameDirForInstallTree();
+ }
+
+ // Use the build tree directory for the target.
+ if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
+ !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
+ !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
+ {
+ std::string dir;
+ bool macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
+ if(macosx_rpath)
+ {
+ dir = "@rpath";
+ }
+ else
+ {
+ dir = this->GetDirectory(config);
+ }
+ dir += "/";
+ return dir;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetInstallNameDirForInstallTree() const
+{
+ if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ std::string dir;
+ const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
+
+ if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
+ !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
+ {
+ if(install_name_dir && *install_name_dir)
+ {
+ dir = install_name_dir;
+ dir += "/";
+ }
+ }
+ if(!install_name_dir)
+ {
+ if(this->MacOSXRpathInstallNameDirDefault())
+ {
+ dir = "@rpath/";
+ }
+ }
+ return dir;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+//----------------------------------------------------------------------------
+const char* cmTarget::GetOutputTargetType(bool implib) const
+{
+ switch(this->GetType())
+ {
+ 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;
+ }
+ 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();
+ }
+
+ // 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.
+ out = config_outdir;
+
+ // Skip per-configuration subdirectory.
+ conf = "";
+ }
+ else if(const char* outdir = this->GetProperty(propertyName))
+ {
+ // Use the user-specified output directory.
+ out = outdir;
+ }
+ 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.c_str(), this->Makefile->GetStartOutputDirectory()));
+
+ // The generator may add the configuration's subdirectory.
+ if(!conf.empty())
+ {
+ const char *platforms = this->Makefile->GetDefinition(
+ "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
+ std::string suffix =
+ usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
+ this->Makefile->GetLocalGenerator()->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.c_str(), this->Makefile->GetStartOutputDirectory()));
+
+ // The generator may add the configuration's subdirectory.
+ if(!conf.empty())
+ {
+ this->Makefile->GetLocalGenerator()->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::GetOutputName(const std::string& config,
+ bool implib) const
+{
+ std::vector<std::string> props;
+ std::string type = this->GetOutputTargetType(implib);
+ std::string configUpper = cmSystemTools::UpperCase(config);
+ if(!type.empty() && !configUpper.empty())
+ {
+ // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
+ props.push_back(type + "_OUTPUT_NAME_" + configUpper);
+ }
+ if(!type.empty())
+ {
+ // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
+ props.push_back(type + "_OUTPUT_NAME");
+ }
+ if(!configUpper.empty())
+ {
+ // OUTPUT_NAME_<CONFIG>
+ props.push_back("OUTPUT_NAME_" + configUpper);
+ // <CONFIG>_OUTPUT_NAME
+ props.push_back(configUpper + "_OUTPUT_NAME");
+ }
+ // OUTPUT_NAME
+ props.push_back("OUTPUT_NAME");
+
+ for(std::vector<std::string>::const_iterator i = props.begin();
+ i != props.end(); ++i)
+ {
+ if(const char* outName = this->GetProperty(*i))
+ {
+ return outName;
+ }
+ }
+ return this->GetName();
+}
+
+//----------------------------------------------------------------------------
+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.c_str());
+ }
+ return this->ExportMacro.c_str();
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
+{
+ return this->LinkImplicitNullProperties.find(p)
+ != this->LinkImplicitNullProperties.end();
+}
+
+//----------------------------------------------------------------------------
+template<typename PropertyType>
+PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop,
+ PropertyType *);
+
+//----------------------------------------------------------------------------
+template<>
+bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop,
+ bool *)
+{
+ return tgt->GetPropertyAsBool(prop);
+}
+
+//----------------------------------------------------------------------------
+template<>
+const char *getTypedProperty<const char *>(cmTarget const* tgt,
+ const std::string& prop,
+ const char **)
+{
+ return tgt->GetProperty(prop);
+}
+
+enum CompatibleType
+{
+ BoolType,
+ StringType,
+ NumberMinType,
+ NumberMaxType
+};
+
+//----------------------------------------------------------------------------
+template<typename PropertyType>
+std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
+ PropertyType rhs,
+ CompatibleType t);
+
+//----------------------------------------------------------------------------
+template<>
+std::pair<bool, bool> consistentProperty(bool lhs, bool rhs, CompatibleType)
+{
+ return std::make_pair(lhs == rhs, lhs);
+}
+
+//----------------------------------------------------------------------------
+std::pair<bool, const char*> consistentStringProperty(const char *lhs,
+ const char *rhs)
+{
+ const bool b = strcmp(lhs, rhs) == 0;
+ return std::make_pair(b, b ? lhs : 0);
+}
+
+#if defined(_MSC_VER) && _MSC_VER <= 1200
+template<typename T> const T&
+cmMaximum(const T& l, const T& r) {return l > r ? l : r;}
+template<typename T> const T&
+cmMinimum(const T& l, const T& r) {return l < r ? l : r;}
+#else
+#define cmMinimum std::min
+#define cmMaximum std::max
+#endif
+
+//----------------------------------------------------------------------------
+std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
+ const char *rhs,
+ CompatibleType t)
+{
+ char *pEnd;
+
+#if defined(_MSC_VER)
+ static const char* const null_ptr = 0;
+#else
+# define null_ptr 0
+#endif
+
+ long lnum = strtol(lhs, &pEnd, 0);
+ if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
+ {
+ return std::pair<bool, const char*>(false, null_ptr);
+ }
+
+ long rnum = strtol(rhs, &pEnd, 0);
+ if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
+ {
+ return std::pair<bool, const char*>(false, null_ptr);
+ }
+
+#if !defined(_MSC_VER)
+#undef null_ptr
+#endif
+
+ if (t == NumberMaxType)
+ {
+ return std::make_pair(true, cmMaximum(lnum, rnum) == lnum ? lhs : rhs);
+ }
+ else
+ {
+ return std::make_pair(true, cmMinimum(lnum, rnum) == lnum ? lhs : rhs);
+ }
+}
+
+//----------------------------------------------------------------------------
+template<>
+std::pair<bool, const char*> consistentProperty(const char *lhs,
+ const char *rhs,
+ CompatibleType t)
+{
+ if (!lhs && !rhs)
+ {
+ return std::make_pair(true, lhs);
+ }
+ if (!lhs)
+ {
+ return std::make_pair(true, rhs);
+ }
+ if (!rhs)
+ {
+ return std::make_pair(true, lhs);
+ }
+
+#if defined(_MSC_VER)
+ static const char* const null_ptr = 0;
+#else
+# define null_ptr 0
+#endif
+
+ switch(t)
+ {
+ case BoolType:
+ assert(!"consistentProperty for strings called with BoolType");
+ return std::pair<bool, const char*>(false, null_ptr);
+ case StringType:
+ return consistentStringProperty(lhs, rhs);
+ case NumberMinType:
+ case NumberMaxType:
+ return consistentNumberProperty(lhs, rhs, t);
+ }
+ assert(!"Unreachable!");
+ return std::pair<bool, const char*>(false, null_ptr);
+
+#if !defined(_MSC_VER)
+#undef null_ptr
+#endif
+
+}
+
+template<typename PropertyType>
+PropertyType impliedValue(PropertyType);
+template<>
+bool impliedValue<bool>(bool)
+{
+ return false;
+}
+template<>
+const char* impliedValue<const char*>(const char*)
+{
+ return "";
+}
+
+
+template<typename PropertyType>
+std::string valueAsString(PropertyType);
+template<>
+std::string valueAsString<bool>(bool value)
+{
+ return value ? "TRUE" : "FALSE";
+}
+template<>
+std::string valueAsString<const char*>(const char* value)
+{
+ return value ? value : "(unset)";
+}
+
+//----------------------------------------------------------------------------
+void
+cmTarget::ReportPropertyOrigin(const std::string &p,
+ const std::string &result,
+ const std::string &report,
+ const std::string &compatibilityType) const
+{
+ std::vector<std::string> debugProperties;
+ const char *debugProp =
+ this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
+ if (debugProp)
+ {
+ cmSystemTools::ExpandListArgument(debugProp, debugProperties);
+ }
+
+ bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
+ && std::find(debugProperties.begin(),
+ debugProperties.end(),
+ p)
+ != debugProperties.end();
+
+ if (this->Makefile->IsGeneratingBuildSystem())
+ {
+ this->DebugCompatiblePropertiesDone[p] = true;
+ }
+ if (!debugOrigin)
+ {
+ return;
+ }
+
+ std::string areport = compatibilityType;
+ areport += std::string(" of property \"") + p + "\" for target \"";
+ areport += std::string(this->GetName());
+ areport += "\" (result: \"";
+ areport += result;
+ areport += "\"):\n" + report;
+
+ this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
+}
+
+//----------------------------------------------------------------------------
+std::string compatibilityType(CompatibleType t)
+{
+ switch(t)
+ {
+ case BoolType:
+ return "Boolean compatibility";
+ case StringType:
+ return "String compatibility";
+ case NumberMaxType:
+ return "Numeric maximum compatibility";
+ case NumberMinType:
+ return "Numeric minimum compatibility";
+ }
+ assert(!"Unreachable!");
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string compatibilityAgree(CompatibleType t, bool dominant)
+{
+ switch(t)
+ {
+ case BoolType:
+ case StringType:
+ return dominant ? "(Disagree)\n" : "(Agree)\n";
+ case NumberMaxType:
+ case NumberMinType:
+ return dominant ? "(Dominant)\n" : "(Ignored)\n";
+ }
+ assert(!"Unreachable!");
+ return "";
+}
+
+//----------------------------------------------------------------------------
+template<typename PropertyType>
+PropertyType checkInterfacePropertyCompatibility(cmTarget const* tgt,
+ const std::string &p,
+ const std::string& config,
+ const char *defaultValue,
+ CompatibleType t,
+ PropertyType *)
+{
+ PropertyType propContent = getTypedProperty<PropertyType>(tgt, p,
+ 0);
+ const bool explicitlySet = tgt->GetProperties()
+ .find(p)
+ != tgt->GetProperties().end();
+ const bool impliedByUse =
+ tgt->IsNullImpliedByLinkLibraries(p);
+ assert((impliedByUse ^ explicitlySet)
+ || (!impliedByUse && !explicitlySet));
+
+ std::vector<cmTarget const*> const& deps =
+ tgt->GetLinkImplementationClosure(config);
+
+ if(deps.empty())
+ {
+ return propContent;
+ }
+ bool propInitialized = explicitlySet;
+
+ std::string report = " * Target \"";
+ report += tgt->GetName();
+ if (explicitlySet)
+ {
+ report += "\" has property content \"";
+ report += valueAsString<PropertyType>(propContent);
+ report += "\"\n";
+ }
+ else if (impliedByUse)
+ {
+ report += "\" property is implied by use.\n";
+ }
+ else
+ {
+ report += "\" property not set.\n";
+ }
+
+ std::string interfaceProperty = "INTERFACE_" + p;
+ for(std::vector<cmTarget const*>::const_iterator li =
+ deps.begin();
+ li != deps.end(); ++li)
+ {
+ // An error should be reported if one dependency
+ // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
+ // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
+ // target itself has a POSITION_INDEPENDENT_CODE which disagrees
+ // with a dependency.
+
+ cmTarget const* theTarget = *li;
+
+ const bool ifaceIsSet = theTarget->GetProperties()
+ .find(interfaceProperty)
+ != theTarget->GetProperties().end();
+ PropertyType ifacePropContent =
+ getTypedProperty<PropertyType>(theTarget,
+ interfaceProperty, 0);
+
+ std::string reportEntry;
+ if (ifaceIsSet)
+ {
+ reportEntry += " * Target \"";
+ reportEntry += theTarget->GetName();
+ reportEntry += "\" property value \"";
+ reportEntry += valueAsString<PropertyType>(ifacePropContent);
+ reportEntry += "\" ";
+ }
+
+ if (explicitlySet)
+ {
+ if (ifaceIsSet)
+ {
+ std::pair<bool, PropertyType> consistent =
+ consistentProperty(propContent,
+ ifacePropContent, t);
+ report += reportEntry;
+ report += compatibilityAgree(t, propContent != consistent.second);
+ if (!consistent.first)
+ {
+ cmOStringStream e;
+ e << "Property " << p << " on target \""
+ << tgt->GetName() << "\" does\nnot match the "
+ "INTERFACE_" << p << " property requirement\nof "
+ "dependency \"" << theTarget->GetName() << "\".\n";
+ cmSystemTools::Error(e.str().c_str());
+ break;
+ }
+ else
+ {
+ propContent = consistent.second;
+ continue;
+ }
+ }
+ else
+ {
+ // Explicitly set on target and not set in iface. Can't disagree.
+ continue;
+ }
+ }
+ else if (impliedByUse)
+ {
+ propContent = impliedValue<PropertyType>(propContent);
+
+ if (ifaceIsSet)
+ {
+ std::pair<bool, PropertyType> consistent =
+ consistentProperty(propContent,
+ ifacePropContent, t);
+ report += reportEntry;
+ report += compatibilityAgree(t, propContent != consistent.second);
+ if (!consistent.first)
+ {
+ cmOStringStream e;
+ e << "Property " << p << " on target \""
+ << tgt->GetName() << "\" is\nimplied to be " << defaultValue
+ << " because it was used to determine the link libraries\n"
+ "already. The INTERFACE_" << p << " property on\ndependency \""
+ << theTarget->GetName() << "\" is in conflict.\n";
+ cmSystemTools::Error(e.str().c_str());
+ break;
+ }
+ else
+ {
+ propContent = consistent.second;
+ continue;
+ }
+ }
+ else
+ {
+ // Implicitly set on target and not set in iface. Can't disagree.
+ continue;
+ }
+ }
+ else
+ {
+ if (ifaceIsSet)
+ {
+ if (propInitialized)
+ {
+ std::pair<bool, PropertyType> consistent =
+ consistentProperty(propContent,
+ ifacePropContent, t);
+ report += reportEntry;
+ report += compatibilityAgree(t, propContent != consistent.second);
+ if (!consistent.first)
+ {
+ cmOStringStream e;
+ e << "The INTERFACE_" << p << " property of \""
+ << theTarget->GetName() << "\" does\nnot agree with the value "
+ "of " << p << " already determined\nfor \""
+ << tgt->GetName() << "\".\n";
+ cmSystemTools::Error(e.str().c_str());
+ break;
+ }
+ else
+ {
+ propContent = consistent.second;
+ continue;
+ }
+ }
+ else
+ {
+ report += reportEntry + "(Interface set)\n";
+ propContent = ifacePropContent;
+ propInitialized = true;
+ }
+ }
+ else
+ {
+ // Not set. Nothing to agree on.
+ continue;
+ }
+ }
+ }
+
+ tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
+ report, compatibilityType(t));
+ return propContent;
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
+ const std::string& config) const
+{
+ return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
+ BoolType, 0);
+}
+
+//----------------------------------------------------------------------------
+const char * cmTarget::GetLinkInterfaceDependentStringProperty(
+ const std::string &p,
+ const std::string& config) const
+{
+ return checkInterfacePropertyCompatibility<const char *>(this,
+ p,
+ config,
+ "empty",
+ StringType, 0);
+}
+
+//----------------------------------------------------------------------------
+const char * cmTarget::GetLinkInterfaceDependentNumberMinProperty(
+ const std::string &p,
+ const std::string& config) const
+{
+ return checkInterfacePropertyCompatibility<const char *>(this,
+ p,
+ config,
+ "empty",
+ NumberMinType, 0);
+}
+
+//----------------------------------------------------------------------------
+const char * cmTarget::GetLinkInterfaceDependentNumberMaxProperty(
+ const std::string &p,
+ const std::string& config) const
+{
+ return checkInterfacePropertyCompatibility<const char *>(this,
+ p,
+ config,
+ "empty",
+ NumberMaxType, 0);
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
+ const std::string& config) const
+{
+ if (this->TargetTypeValue == OBJECT_LIBRARY
+ || this->TargetTypeValue == INTERFACE_LIBRARY)
+ {
+ return false;
+ }
+ return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
+ const std::string& config) const
+{
+ if (this->TargetTypeValue == OBJECT_LIBRARY
+ || this->TargetTypeValue == INTERFACE_LIBRARY)
+ {
+ return false;
+ }
+ return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
+ const std::string& config) const
+{
+ if (this->TargetTypeValue == OBJECT_LIBRARY
+ || this->TargetTypeValue == INTERFACE_LIBRARY)
+ {
+ return false;
+ }
+ return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
+ const std::string& config) const
+{
+ if (this->TargetTypeValue == OBJECT_LIBRARY
+ || this->TargetTypeValue == INTERFACE_LIBRARY)
+ {
+ return false;
+ }
+ return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
+}
+
+//----------------------------------------------------------------------------
+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.c_str());
+ if(objLib)
+ {
+ objlibs.push_back(objLib);
+ }
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::GetLanguages(std::set<std::string>& languages,
+ const std::string& config) const
+{
+ std::vector<cmSourceFile*> sourceFiles;
+ this->GetSourceFiles(sourceFiles, config);
+ for(std::vector<cmSourceFile*>::const_iterator
+ i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
+ {
+ const std::string& lang = (*i)->GetLanguage();
+ if(!lang.empty())
+ {
+ languages.insert(lang);
+ }
+ }
+
+ std::vector<cmTarget*> objectLibraries;
+ std::vector<cmSourceFile const*> externalObjects;
+ if (this->Makefile->GetGeneratorTargets().empty())
+ {
+ this->GetObjectLibrariesCMP0026(objectLibraries);
+ }
+ else
+ {
+ cmGeneratorTarget* gt = this->Makefile->GetLocalGenerator()
+ ->GetGlobalGenerator()
+ ->GetGeneratorTarget(this);
+ gt->GetExternalObjects(externalObjects, config);
+ for(std::vector<cmSourceFile const*>::const_iterator
+ i = externalObjects.begin(); i != externalObjects.end(); ++i)
+ {
+ std::string objLib = (*i)->GetObjectLibrary();
+ if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
+ {
+ objectLibraries.push_back(tgt);
+ }
+ }
+ }
+ for(std::vector<cmTarget*>::const_iterator
+ i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
+ {
+ (*i)->GetLanguages(languages, config);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::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))
+ {
+ return false;
+ }
+
+ // If the target will not be installed we do not need to change its
+ // rpath.
+ if(!this->GetHaveInstallRule())
+ {
+ return false;
+ }
+
+ // Skip chrpath if skipping rpath altogether.
+ if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
+ {
+ return false;
+ }
+
+ // Skip chrpath if it does not need to be changed at install time.
+ if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
+ {
+ return false;
+ }
+
+ // Allow the user to disable builtin chrpath explicitly.
+ if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
+ {
+ return false;
+ }
+
+ if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ return true;
+ }
+
+#if defined(CMAKE_USE_ELF_PARSER)
+ // Enable if the rpath flag uses a separator and the target uses ELF
+ // binaries.
+ std::string ll = this->GetLinkerLanguage(config);
+ if(!ll.empty())
+ {
+ std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
+ sepVar += ll;
+ sepVar += "_FLAG_SEP";
+ const char* sep = this->Makefile->GetDefinition(sepVar);
+ if(sep && *sep)
+ {
+ // TODO: Add ELF check to ABI detection and get rid of
+ // CMAKE_EXECUTABLE_FORMAT.
+ if(const char* fmt =
+ this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
+ {
+ return strcmp(fmt, "ELF") == 0;
+ }
+ }
+ }
+#endif
+ static_cast<void>(config);
+ return false;
+}
+
+//----------------------------------------------------------------------------
+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)
+ {
+ std::string impProp = "IMPORTED_IMPLIB_";
+ impProp += mcUpper;
+ *imp = this->GetProperty(impProp);
+ }
+
+ // If it was found, use it for all properties below.
+ if(*loc || *imp)
+ {
+ suffix = "_";
+ suffix += mcUpper;
+ }
+ }
+
+ // If we needed to find one of the mapped configurations but did not
+ // then the target is not found. The project does not want any
+ // other configuration.
+ if(!mappedConfigs.empty() && !*loc && !*imp)
+ {
+ return false;
+ }
+
+ // If we have not yet found it then there are no mapped
+ // configurations. Look for an exact-match.
+ if(!*loc && !*imp)
+ {
+ std::string locProp = "IMPORTED_LOCATION";
+ locProp += suffix;
+ *loc = this->GetProperty(locProp);
+ if(allowImp)
+ {
+ std::string impProp = "IMPORTED_IMPLIB";
+ impProp += suffix;
+ *imp = this->GetProperty(impProp);
+ }
+ }
+
+ // If we have not yet found it then there are no mapped
+ // configurations and no exact match.
+ if(!*loc && !*imp)
+ {
+ // The suffix computed above is not useful.
+ suffix = "";
+
+ // Look for a configuration-less location. This may be set by
+ // manually-written code.
+ *loc = this->GetProperty("IMPORTED_LOCATION");
+ if(allowImp)
+ {
+ *imp = this->GetProperty("IMPORTED_IMPLIB");
+ }
+ }
+
+ // If we have not yet found it then the project is willing to try
+ // any available configuration.
+ if(!*loc && !*imp)
+ {
+ std::vector<std::string> availableConfigs;
+ if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
+ {
+ cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
+ }
+ for(std::vector<std::string>::const_iterator
+ aci = availableConfigs.begin();
+ !*loc && !*imp && aci != availableConfigs.end(); ++aci)
+ {
+ suffix = "_";
+ suffix += cmSystemTools::UpperCase(*aci);
+ std::string locProp = "IMPORTED_LOCATION";
+ locProp += suffix;
+ *loc = this->GetProperty(locProp);
+ if(allowImp)
+ {
+ std::string impProp = "IMPORTED_IMPLIB";
+ impProp += suffix;
+ *imp = this->GetProperty(impProp);
+ }
+ }
+ }
+ // If we have not yet found it then the target is not available.
+ if(!*loc && !*imp)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+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);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+cmTarget::LinkInterface const* cmTarget::GetLinkInterface(
+ const std::string& config,
+ cmTarget const* head) const
+{
+ // Imported targets have their own link interface.
+ if(this->IsImported())
+ {
+ return this->GetImportLinkInterface(config, head, false);
+ }
+
+ // Link interfaces are not supported for executables that do not
+ // export symbols.
+ if(this->GetType() == cmTarget::EXECUTABLE &&
+ !this->IsExecutableWithExports())
+ {
+ return 0;
+ }
+
+ // Lookup any existing link interface for this configuration.
+ std::string CONFIG = cmSystemTools::UpperCase(config);
+ cmTargetInternals::HeadToLinkInterfaceMap& hm =
+ this->Internal->LinkInterfaceMap[CONFIG];
+
+ // If the link interface 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;
+ }
+
+ cmTargetInternals::OptionalLinkInterface& iface = hm[head];
+ if(!iface.LibrariesDone)
+ {
+ iface.LibrariesDone = true;
+ this->Internal->ComputeLinkInterfaceLibraries(
+ this, config, iface, head, false);
+ }
+ if(!iface.AllDone)
+ {
+ iface.AllDone = true;
+ if(iface.Exists)
+ {
+ this->Internal->ComputeLinkInterface(this, config, iface, head);
+ }
+ }
+
+ return iface.Exists? &iface : 0;
+}
+
+//----------------------------------------------------------------------------
+cmTarget::LinkInterfaceLibraries const*
+cmTarget::GetLinkInterfaceLibraries(const std::string& config,
+ cmTarget const* head,
+ bool usage_requirements_only) const
+{
+ // Imported targets have their own link interface.
+ if(this->IsImported())
+ {
+ return this->GetImportLinkInterface(config, head, usage_requirements_only);
+ }
+
+ // Link interfaces are not supported for executables that do not
+ // export symbols.
+ if(this->GetType() == cmTarget::EXECUTABLE &&
+ !this->IsExecutableWithExports())
+ {
+ return 0;
+ }
+
+ // Lookup any existing link interface for this configuration.
+ std::string CONFIG = cmSystemTools::UpperCase(config);
+ cmTargetInternals::HeadToLinkInterfaceMap& hm =
+ (usage_requirements_only ?
+ this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
+ this->Internal->LinkInterfaceMap[CONFIG]);
+
+ // If the link interface 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;
+ }
+
+ cmTargetInternals::OptionalLinkInterface& iface = hm[head];
+ if(!iface.LibrariesDone)
+ {
+ iface.LibrariesDone = true;
+ this->Internal->ComputeLinkInterfaceLibraries(
+ this, config, iface, head, usage_requirements_only);
+ }
+
+ return iface.Exists? &iface : 0;
+}
+
+//----------------------------------------------------------------------------
+cmTarget::LinkInterface const*
+cmTarget::GetImportLinkInterface(const std::string& config,
+ cmTarget const* headTarget,
+ bool usage_requirements_only) const
+{
+ cmTarget::ImportInfo const* info = this->GetImportInfo(config);
+ if(!info)
+ {
+ return 0;
+ }
+
+ std::string CONFIG = cmSystemTools::UpperCase(config);
+ cmTargetInternals::HeadToLinkInterfaceMap& hm =
+ (usage_requirements_only ?
+ this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
+ this->Internal->LinkInterfaceMap[CONFIG]);
+
+ // If the link interface 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;
+ }
+
+ cmTargetInternals::OptionalLinkInterface& iface = hm[headTarget];
+ if(!iface.AllDone)
+ {
+ iface.AllDone = true;
+ iface.Multiplicity = info->Multiplicity;
+ cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
+ this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
+ headTarget, usage_requirements_only,
+ iface.Libraries,
+ iface.HadHeadSensitiveCondition);
+ std::vector<std::string> deps;
+ cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
+ this->LookupLinkItems(deps, iface.SharedDeps);
+ }
+
+ return &iface;
+}
+
+//----------------------------------------------------------------------------
+void processILibs(const std::string& config,
+ cmTarget const* headTarget,
+ cmLinkItem const& item,
+ std::vector<cmTarget const*>& tgts,
+ std::set<cmTarget const*>& emitted)
+{
+ if (item.Target && emitted.insert(item.Target).second)
+ {
+ tgts.push_back(item.Target);
+ if(cmTarget::LinkInterfaceLibraries const* iface =
+ item.Target->GetLinkInterfaceLibraries(config, headTarget, true))
+ {
+ for(std::vector<cmLinkItem>::const_iterator
+ it = iface->Libraries.begin();
+ it != iface->Libraries.end(); ++it)
+ {
+ processILibs(config, headTarget, *it, tgts, emitted);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+std::vector<cmTarget const*> const&
+cmTarget::GetLinkImplementationClosure(const std::string& config) const
+{
+ cmTargetInternals::LinkImplClosure& tgts =
+ this->Internal->LinkImplClosureMap[config];
+ if(!tgts.Done)
+ {
+ tgts.Done = true;
+ std::set<cmTarget const*> emitted;
+
+ cmTarget::LinkImplementationLibraries const* impl
+ = this->GetLinkImplementationLibraries(config);
+
+ for(std::vector<cmLinkImplItem>::const_iterator
+ it = impl->Libraries.begin();
+ it != impl->Libraries.end(); ++it)
+ {
+ processILibs(config, this, *it, tgts , emitted);
+ }
+ }
+ return tgts;
+}
+
+//----------------------------------------------------------------------------
+cmTarget::CompatibleInterfaces const&
+cmTarget::GetCompatibleInterfaces(std::string const& config) const
+{
+ cmTargetInternals::CompatibleInterfaces& compat =
+ this->Internal->CompatibleInterfacesMap[config];
+ if(!compat.Done)
+ {
+ compat.Done = true;
+ compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
+ compat.PropsString.insert("AUTOUIC_OPTIONS");
+ std::vector<cmTarget const*> const& deps =
+ this->GetLinkImplementationClosure(config);
+ for(std::vector<cmTarget 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)) \
+ { \
+ std::vector<std::string> props; \
+ cmSystemTools::ExpandListArgument(prop, props); \
+ std::copy(props.begin(), props.end(), \
+ std::inserter(compat.Props##x, compat.Props##x.begin())); \
+ }
+ CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
+ CM_READ_COMPATIBLE_INTERFACE(STRING, String)
+ CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
+ CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
+#undef CM_READ_COMPATIBLE_INTERFACE
+ }
+ }
+ return compat;
+}
+
+//----------------------------------------------------------------------------
+void
+cmTargetInternals::ComputeLinkInterfaceLibraries(
+ cmTarget const* thisTarget,
+ const std::string& config,
+ OptionalLinkInterface& iface,
+ cmTarget const* headTarget,
+ bool usage_requirements_only)
+{
+ // 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(thisTarget->PolicyStatusCMP0022 != cmPolicies::OLD &&
+ thisTarget->PolicyStatusCMP0022 != cmPolicies::WARN)
+ {
+ // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
+ linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
+ explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
+ }
+ else if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY ||
+ thisTarget->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 = thisTarget->GetProperty(linkIfaceProp);
+
+ // If not set, try the generic property.
+ if(!explicitLibraries)
+ {
+ linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
+ explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
+ }
+ }
+
+ if(explicitLibraries &&
+ thisTarget->PolicyStatusCMP0022 == 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 =
+ thisTarget->GetProperty("INTERFACE_LINK_LIBRARIES");
+ if (newExplicitLibraries
+ && strcmp(newExplicitLibraries, explicitLibraries) != 0)
+ {
+ cmOStringStream w;
+ w <<
+ (thisTarget->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
+ "Target \"" << thisTarget->GetName() << "\" has an "
+ "INTERFACE_LINK_LIBRARIES property which differs from its " <<
+ linkIfaceProp << " properties."
+ "\n"
+ "INTERFACE_LINK_LIBRARIES:\n"
+ " " << newExplicitLibraries << "\n" <<
+ linkIfaceProp << ":\n"
+ " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
+ thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->PolicyWarnedCMP0022 = true;
+ }
+ }
+
+ // There is no implicit link interface for executables or modules
+ // so if none was explicitly set then there is no link interface.
+ if(!explicitLibraries &&
+ (thisTarget->GetType() == cmTarget::EXECUTABLE ||
+ (thisTarget->GetType() == cmTarget::MODULE_LIBRARY)))
+ {
+ return;
+ }
+ iface.Exists = true;
+ iface.ExplicitLibraries = explicitLibraries;
+
+ if(explicitLibraries)
+ {
+ // The interface libraries have been explicitly set.
+ thisTarget->ExpandLinkItems(linkIfaceProp, explicitLibraries, config,
+ headTarget, usage_requirements_only,
+ iface.Libraries,
+ iface.HadHeadSensitiveCondition);
+ }
+ else if (thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN
+ || thisTarget->PolicyStatusCMP0022 == 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
+ // to the link implementation.
+ {
+ // The link implementation is the default link interface.
+ cmTarget::LinkImplementationLibraries const* impl =
+ thisTarget->GetLinkImplementationLibrariesInternal(config, headTarget);
+ std::copy(impl->Libraries.begin(), impl->Libraries.end(),
+ std::back_inserter(iface.Libraries));
+ if(thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN &&
+ !this->PolicyWarnedCMP0022 && !usage_requirements_only)
+ {
+ // Compare the link implementation fallback link interface to the
+ // preferred new link interface property and warn if different.
+ std::vector<cmLinkItem> ifaceLibs;
+ static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
+ if(const char* newExplicitLibraries = thisTarget->GetProperty(newProp))
+ {
+ bool hadHeadSensitiveConditionDummy = false;
+ thisTarget->ExpandLinkItems(newProp, newExplicitLibraries, config,
+ headTarget, usage_requirements_only,
+ ifaceLibs, hadHeadSensitiveConditionDummy);
+ }
+ if (ifaceLibs != iface.Libraries)
+ {
+ std::string oldLibraries;
+ std::string newLibraries;
+ const char *sep = "";
+ for(std::vector<cmLinkImplItem>::const_iterator it
+ = impl->Libraries.begin(); it != impl->Libraries.end(); ++it)
+ {
+ oldLibraries += sep;
+ oldLibraries += *it;
+ sep = ";";
+ }
+ sep = "";
+ for(std::vector<cmLinkItem>::const_iterator it
+ = ifaceLibs.begin(); it != ifaceLibs.end(); ++it)
+ {
+ newLibraries += sep;
+ newLibraries += *it;
+ sep = ";";
+ }
+ if(oldLibraries.empty())
+ { oldLibraries = "(empty)"; }
+ if(newLibraries.empty())
+ { newLibraries = "(empty)"; }
+
+ cmOStringStream w;
+ w <<
+ (thisTarget->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
+ "Target \"" << thisTarget->GetName() << "\" has an "
+ "INTERFACE_LINK_LIBRARIES property. "
+ "This should be preferred as the source of the link interface "
+ "for this library but because CMP0022 is not set CMake is "
+ "ignoring the property and using the link implementation "
+ "as the link interface instead."
+ "\n"
+ "INTERFACE_LINK_LIBRARIES:\n"
+ " " << newLibraries << "\n"
+ "Link implementation:\n"
+ " " << oldLibraries << "\n";
+ thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->PolicyWarnedCMP0022 = true;
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
+ const std::string& config,
+ OptionalLinkInterface& iface,
+ cmTarget const* headTarget) const
+{
+ if(iface.ExplicitLibraries)
+ {
+ if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY
+ || thisTarget->GetType() == cmTarget::STATIC_LIBRARY
+ || thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ // Shared libraries may have runtime implementation dependencies
+ // on other shared libraries that are not in the interface.
+ UNORDERED_SET<std::string> emitted;
+ for(std::vector<cmLinkItem>::const_iterator
+ li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
+ {
+ emitted.insert(*li);
+ }
+ if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ cmTarget::LinkImplementation const* impl =
+ thisTarget->GetLinkImplementation(config);
+ for(std::vector<cmLinkImplItem>::const_iterator
+ li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
+ {
+ if(emitted.insert(*li).second)
+ {
+ if(li->Target)
+ {
+ // This is a runtime dependency on another shared library.
+ if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
+ {
+ iface.SharedDeps.push_back(*li);
+ }
+ }
+ else
+ {
+ // TODO: Recognize shared library file names. Perhaps this
+ // should be moved to cmComputeLinkInformation, but that creates
+ // a chicken-and-egg problem since this list is needed for its
+ // construction.
+ }
+ }
+ }
+ }
+ }
+ }
+ else if (thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN
+ || thisTarget->PolicyStatusCMP0022 == cmPolicies::OLD)
+ {
+ // The link implementation is the default link interface.
+ cmTarget::LinkImplementationLibraries const*
+ impl = thisTarget->GetLinkImplementationLibrariesInternal(config,
+ headTarget);
+ iface.ImplementationIsInterface = true;
+ iface.WrongConfigLibraries = impl->WrongConfigLibraries;
+ }
+
+ if(thisTarget->LinkLanguagePropagatesToDependents())
+ {
+ // Targets using this archive need its language runtime libraries.
+ if(cmTarget::LinkImplementation const* impl =
+ thisTarget->GetLinkImplementation(config))
+ {
+ iface.Languages = impl->Languages;
+ }
+ }
+
+ if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY)
+ {
+ // Construct the property name suffix for this configuration.
+ std::string suffix = "_";
+ if(!config.empty())
+ {
+ suffix += cmSystemTools::UpperCase(config);
+ }
+ else
+ {
+ suffix += "NOCONFIG";
+ }
+
+ // How many repetitions are needed if this library has cyclic
+ // dependencies?
+ std::string propName = "LINK_INTERFACE_MULTIPLICITY";
+ propName += suffix;
+ if(const char* config_reps = thisTarget->GetProperty(propName))
+ {
+ sscanf(config_reps, "%u", &iface.Multiplicity);
+ }
+ else if(const char* reps =
+ thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
+ {
+ sscanf(reps, "%u", &iface.Multiplicity);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTargetInternals::AddInterfaceEntries(
+ cmTarget const* thisTarget, std::string const& config,
+ std::string const& prop, std::vector<TargetPropertyEntry*>& entries)
+{
+ if(cmTarget::LinkImplementationLibraries 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));
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+cmTarget::LinkImplementation const*
+cmTarget::GetLinkImplementation(const std::string& config) const
+{
+ // There is no link implementation for imported targets.
+ if(this->IsImported())
+ {
+ return 0;
+ }
+
+ // Populate the link implementation for this configuration.
+ std::string CONFIG = cmSystemTools::UpperCase(config);
+ cmTargetInternals::OptionalLinkImplementation&
+ impl = this->Internal->LinkImplMap[CONFIG][this];
+ if(!impl.LibrariesDone)
+ {
+ impl.LibrariesDone = true;
+ this->Internal
+ ->ComputeLinkImplementationLibraries(this, config, impl, this);
+ }
+ if(!impl.LanguagesDone)
+ {
+ impl.LanguagesDone = true;
+ this->Internal->ComputeLinkImplementationLanguages(this, config, impl);
+ }
+ return &impl;
+}
+
+//----------------------------------------------------------------------------
+cmTarget::LinkImplementationLibraries const*
+cmTarget::GetLinkImplementationLibraries(const std::string& config) const
+{
+ return this->GetLinkImplementationLibrariesInternal(config, this);
+}
+
+//----------------------------------------------------------------------------
+cmTarget::LinkImplementationLibraries 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;
+ }
+
+ cmTargetInternals::OptionalLinkImplementation& impl = hm[head];
+ if(!impl.LibrariesDone)
+ {
+ impl.LibrariesDone = true;
+ this->Internal
+ ->ComputeLinkImplementationLibraries(this, config, impl, head);
+ }
+ return &impl;
+}
+
+//----------------------------------------------------------------------------
+void
+cmTargetInternals::ComputeLinkImplementationLibraries(
+ cmTarget const* thisTarget,
+ const std::string& config,
+ OptionalLinkImplementation& impl,
+ cmTarget const* head) const
+{
+ // Collect libraries directly linked in this configuration.
+ for (std::vector<cmValueWithOrigin>::const_iterator
+ le = this->LinkImplementationPropertyEntries.begin(),
+ end = this->LinkImplementationPropertyEntries.end();
+ le != end; ++le)
+ {
+ std::vector<std::string> llibs;
+ cmGeneratorExpressionDAGChecker dagChecker(
+ thisTarget->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(thisTarget->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 = thisTarget->CheckCMP0004(*li);
+ if(name == thisTarget->GetName() || name.empty())
+ {
+ if(name == thisTarget->GetName())
+ {
+ bool noMessage = false;
+ cmake::MessageType messageType = cmake::FATAL_ERROR;
+ cmOStringStream e;
+ switch(thisTarget->GetPolicyStatusCMP0038())
+ {
+ case cmPolicies::WARN:
+ {
+ e << (thisTarget->Makefile->GetPolicies()
+ ->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 \"" << thisTarget->GetName() << "\" links to itself.";
+ thisTarget->Makefile->GetCMakeInstance()->IssueMessage(
+ messageType, e.str(), thisTarget->GetBacktrace());
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return;
+ }
+ }
+ }
+ continue;
+ }
+
+ // The entry is meant for this configuration.
+ impl.Libraries.push_back(
+ cmLinkImplItem(name, thisTarget->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 (!thisTarget->GetProperty(*it))
+ {
+ thisTarget->LinkImplicitNullProperties.insert(*it);
+ }
+ }
+ cge->GetMaxLanguageStandard(thisTarget, thisTarget->MaxLanguageStandards);
+ }
+
+ cmTarget::LinkLibraryType linkType = thisTarget->ComputeLinkType(config);
+ cmTarget::LinkLibraryVectorType const& oldllibs =
+ thisTarget->GetOriginalLinkLibraries();
+ for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
+ li != oldllibs.end(); ++li)
+ {
+ if(li->second != cmTarget::GENERAL && li->second != linkType)
+ {
+ std::string name = thisTarget->CheckCMP0004(li->first);
+ if(name == thisTarget->GetName() || name.empty())
+ {
+ continue;
+ }
+ // Support OLD behavior for CMP0003.
+ impl.WrongConfigLibraries.push_back(
+ cmLinkItem(name, thisTarget->FindTargetToLink(name)));
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmTargetInternals::ComputeLinkImplementationLanguages(
+ cmTarget const* thisTarget,
+ const std::string& config,
+ OptionalLinkImplementation& impl) const
+{
+ // This target needs runtime libraries for its source languages.
+ std::set<std::string> languages;
+ // Get languages used in our source files.
+ thisTarget->GetLanguages(languages, config);
+ // Copy the set of langauges to the link implementation.
+ for(std::set<std::string>::iterator li = languages.begin();
+ li != languages.end(); ++li)
+ {
+ impl.Languages.push_back(*li);
+ }
+}
+
+//----------------------------------------------------------------------------
+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)
+ {
+ cmOStringStream 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->PolicyStatusCMP0004)
+ {
+ case cmPolicies::WARN:
+ {
+ cmOStringStream w;
+ w << (this->Makefile->GetPolicies()
+ ->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:
+ {
+ cmOStringStream 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:
+ {
+ cmOStringStream e;
+ e << (this->Makefile->GetPolicies()
+ ->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;
+}
+
+template<typename PropertyType>
+PropertyType getLinkInterfaceDependentProperty(cmTarget const* tgt,
+ const std::string& prop,
+ const std::string& config,
+ CompatibleType,
+ PropertyType *);
+
+template<>
+bool getLinkInterfaceDependentProperty(cmTarget const* tgt,
+ const std::string& prop,
+ const std::string& config,
+ CompatibleType, bool *)
+{
+ return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
+}
+
+template<>
+const char * getLinkInterfaceDependentProperty(cmTarget const* tgt,
+ const std::string& prop,
+ const std::string& config,
+ CompatibleType t,
+ const char **)
+{
+ switch(t)
+ {
+ case BoolType:
+ assert(!"String compatibility check function called for boolean");
+ return 0;
+ case StringType:
+ return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
+ case NumberMinType:
+ return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
+ case NumberMaxType:
+ return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
+ }
+ assert(!"Unreachable!");
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+template<typename PropertyType>
+void checkPropertyConsistency(cmTarget const* depender,
+ cmTarget const* dependee,
+ const std::string& propName,
+ std::set<std::string> &emitted,
+ const std::string& config,
+ CompatibleType t,
+ PropertyType *)
+{
+ const char *prop = dependee->GetProperty(propName);
+ if (!prop)
+ {
+ return;
+ }
+
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(prop, props);
+ std::string pdir =
+ dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
+ pdir += "/Help/prop_tgt/";
+
+ for(std::vector<std::string>::iterator pi = props.begin();
+ pi != props.end(); ++pi)
+ {
+ std::string pname = cmSystemTools::HelpFileName(*pi);
+ std::string pfile = pdir + pname + ".rst";
+ if(cmSystemTools::FileExists(pfile.c_str(), true))
+ {
+ cmOStringStream e;
+ e << "Target \"" << dependee->GetName() << "\" has property \""
+ << *pi << "\" listed in its " << propName << " property. "
+ "This is not allowed. Only user-defined properties may appear "
+ "listed in the " << propName << " property.";
+ depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
+ if(emitted.insert(*pi).second)
+ {
+ getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
+ t, 0);
+ if (cmSystemTools::GetErrorOccuredFlag())
+ {
+ return;
+ }
+ }
+ }
+}
+
+static std::string intersect(const std::set<std::string> &s1,
+ const std::set<std::string> &s2)
+{
+ std::set<std::string> intersect;
+ std::set_intersection(s1.begin(),s1.end(),
+ s2.begin(),s2.end(),
+ std::inserter(intersect,intersect.begin()));
+ if (!intersect.empty())
+ {
+ return *intersect.begin();
+ }
+ return "";
+}
+static std::string intersect(const std::set<std::string> &s1,
+ const std::set<std::string> &s2,
+ const std::set<std::string> &s3)
+{
+ std::string result;
+ result = intersect(s1, s2);
+ if (!result.empty())
+ return result;
+ result = intersect(s1, s3);
+ if (!result.empty())
+ return result;
+ return intersect(s2, s3);
+}
+static std::string intersect(const std::set<std::string> &s1,
+ const std::set<std::string> &s2,
+ const std::set<std::string> &s3,
+ const std::set<std::string> &s4)
+{
+ std::string result;
+ result = intersect(s1, s2);
+ if (!result.empty())
+ return result;
+ result = intersect(s1, s3);
+ if (!result.empty())
+ return result;
+ result = intersect(s1, s4);
+ if (!result.empty())
+ return result;
+ return intersect(s2, s3, s4);
+}
+
+//----------------------------------------------------------------------------
+void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
+ const std::string& config) const
+{
+ const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
+
+ std::set<std::string> emittedBools;
+ static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
+ std::set<std::string> emittedStrings;
+ static std::string strString = "COMPATIBLE_INTERFACE_STRING";
+ std::set<std::string> emittedMinNumbers;
+ static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
+ std::set<std::string> emittedMaxNumbers;
+ static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
+
+ for(cmComputeLinkInformation::ItemVector::const_iterator li =
+ deps.begin();
+ li != deps.end(); ++li)
+ {
+ if (!li->Target)
+ {
+ continue;
+ }
+
+ checkPropertyConsistency<bool>(this, li->Target,
+ strBool,
+ emittedBools, config, BoolType, 0);
+ if (cmSystemTools::GetErrorOccuredFlag())
+ {
+ return;
+ }
+ checkPropertyConsistency<const char *>(this, li->Target,
+ strString,
+ emittedStrings, config,
+ StringType, 0);
+ if (cmSystemTools::GetErrorOccuredFlag())
+ {
+ return;
+ }
+ checkPropertyConsistency<const char *>(this, li->Target,
+ strNumMin,
+ emittedMinNumbers, config,
+ NumberMinType, 0);
+ if (cmSystemTools::GetErrorOccuredFlag())
+ {
+ return;
+ }
+ checkPropertyConsistency<const char *>(this, li->Target,
+ strNumMax,
+ emittedMaxNumbers, config,
+ NumberMaxType, 0);
+ if (cmSystemTools::GetErrorOccuredFlag())
+ {
+ return;
+ }
+ }
+
+ std::string prop = intersect(emittedBools,
+ emittedStrings,
+ emittedMinNumbers,
+ emittedMaxNumbers);
+
+ if (!prop.empty())
+ {
+ // Use a std::set to keep the error message sorted.
+ std::set<std::string> props;
+ std::set<std::string>::const_iterator i = emittedBools.find(prop);
+ if (i != emittedBools.end())
+ {
+ props.insert(strBool);
+ }
+ i = emittedStrings.find(prop);
+ if (i != emittedStrings.end())
+ {
+ props.insert(strString);
+ }
+ i = emittedMinNumbers.find(prop);
+ if (i != emittedMinNumbers.end())
+ {
+ props.insert(strNumMin);
+ }
+ i = emittedMaxNumbers.find(prop);
+ if (i != emittedMaxNumbers.end())
+ {
+ props.insert(strNumMax);
+ }
+
+ std::string propsString = *props.begin();
+ props.erase(props.begin());
+ while (props.size() > 1)
+ {
+ propsString += ", " + *props.begin();
+ props.erase(props.begin());
+ }
+ if (props.size() == 1)
+ {
+ propsString += " and the " + *props.begin();
+ }
+ cmOStringStream e;
+ e << "Property \"" << prop << "\" appears in both the "
+ << propsString <<
+ " property in the dependencies of target \"" << this->GetName() <<
+ "\". This is not allowed. A property may only require compatibility "
+ "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
+ "string interpretation, but not a mixture.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+}
+
+//----------------------------------------------------------------------------
+cmComputeLinkInformation*
+cmTarget::GetLinkInformation(const std::string& config) const
+{
+ // Lookup any existing information for this configuration.
+ std::string key(cmSystemTools::UpperCase(config));
+ cmTargetLinkInformationMap::iterator
+ i = this->LinkInformation.find(key);
+ if(i == this->LinkInformation.end())
+ {
+ // Compute information for this configuration.
+ cmComputeLinkInformation* info =
+ new cmComputeLinkInformation(this, config);
+ if(!info || !info->Compute())
+ {
+ delete info;
+ info = 0;
+ }
+
+ // Store the information for this configuration.
+ cmTargetLinkInformationMap::value_type entry(key, info);
+ i = this->LinkInformation.insert(entry).first;
+
+ if (info)
+ {
+ this->CheckPropertyCompatibility(info, config);
+ }
+ }
+ return i->second;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetFrameworkDirectory(const std::string& config,
+ bool rootDir) const
+{
+ std::string fpath;
+ fpath += this->GetOutputName(config, false);
+ fpath += ".framework";
+ if(!rootDir)
+ {
+ fpath += "/Versions/";
+ fpath += this->GetFrameworkVersion();
+ }
+ return fpath;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetCFBundleDirectory(const std::string& config,
+ bool contentOnly) const
+{
+ std::string fpath;
+ fpath += this->GetOutputName(config, false);
+ fpath += ".";
+ const char *ext = this->GetProperty("BUNDLE_EXTENSION");
+ if (!ext)
+ {
+ ext = "bundle";
+ }
+ fpath += ext;
+ fpath += "/Contents";
+ if(!contentOnly)
+ fpath += "/MacOS";
+ return fpath;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetAppBundleDirectory(const std::string& config,
+ bool contentOnly) const
+{
+ std::string fpath = this->GetFullName(config, false);
+ fpath += ".app/Contents";
+ if(!contentOnly)
+ fpath += "/MacOS";
+ return fpath;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::BuildMacContentDirectory(const std::string& base,
+ const std::string& config,
+ bool contentOnly) const
+{
+ std::string fpath = base;
+ if(this->IsAppBundleOnApple())
+ {
+ fpath += this->GetAppBundleDirectory(config, contentOnly);
+ }
+ if(this->IsFrameworkOnApple())
+ {
+ fpath += this->GetFrameworkDirectory(config, contentOnly);
+ }
+ if(this->IsCFBundleOnApple())
+ {
+ fpath += this->GetCFBundleDirectory(config, contentOnly);
+ }
+ return fpath;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetMacContentDirectory(const std::string& config,
+ bool implib) const
+{
+ // Start with the output directory for the target.
+ std::string fpath = this->GetDirectory(config, implib);
+ fpath += "/";
+ bool contentOnly = true;
+ if(this->IsFrameworkOnApple())
+ {
+ // additional files with a framework go into the version specific
+ // directory
+ contentOnly = false;
+ }
+ fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
+ return fpath;
+}
+
+//----------------------------------------------------------------------------
+cmTargetLinkInformationMap
+::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
+{
+ // Ideally cmTarget instances should never be copied. However until
+ // we can make a sweep to remove that, this copy constructor avoids
+ // allowing the resources (LinkInformation) from getting copied. In
+ // the worst case this will lead to extra cmComputeLinkInformation
+ // instances. We also enforce in debug mode that the map be emptied
+ // when copied.
+ static_cast<void>(r);
+ assert(r.empty());
+}
+
+//----------------------------------------------------------------------------
+cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
+{
+ for(derived::iterator i = this->begin(); i != this->end(); ++i)
+ {
+ delete i->second;
+ }
+}
+
+//----------------------------------------------------------------------------
+cmTargetInternalPointer::cmTargetInternalPointer()
+{
+ this->Pointer = new cmTargetInternals;
+}
+
+//----------------------------------------------------------------------------
+cmTargetInternalPointer
+::cmTargetInternalPointer(cmTargetInternalPointer const& r)
+{
+ // Ideally cmTarget instances should never be copied. However until
+ // we can make a sweep to remove that, this copy constructor avoids
+ // allowing the resources (Internals) to be copied.
+ this->Pointer = new cmTargetInternals(*r.Pointer);
+}
+
+//----------------------------------------------------------------------------
+cmTargetInternalPointer::~cmTargetInternalPointer()
+{
+ deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
+ deleteAndClear(this->Pointer->CompileOptionsEntries);
+ deleteAndClear(this->Pointer->CompileFeaturesEntries);
+ deleteAndClear(this->Pointer->CompileDefinitionsEntries);
+ deleteAndClear(this->Pointer->SourceEntries);
+ delete this->Pointer;
+}
+
+//----------------------------------------------------------------------------
+cmTargetInternalPointer&
+cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
+{
+ if(this == &r) { return *this; } // avoid warning on HP about self check
+ // Ideally cmTarget instances should never be copied. However until
+ // we can make a sweep to remove that, this copy constructor avoids
+ // allowing the resources (Internals) to be copied.
+ cmTargetInternals* oldPointer = this->Pointer;
+ this->Pointer = new cmTargetInternals(*r.Pointer);
+ delete oldPointer;
+ return *this;
+}
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
new file mode 100644
index 0000000000..a3ecca0601
--- /dev/null
+++ b/Source/cmTarget.h
@@ -0,0 +1,856 @@
+/*============================================================================
+ 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 cmTarget_h
+#define cmTarget_h
+
+#include "cmCustomCommand.h"
+#include "cmPropertyMap.h"
+#include "cmPolicies.h"
+#include "cmListFileCache.h"
+
+#include <cmsys/auto_ptr.hxx>
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+#include <cmsys/hash_map.hxx>
+#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)
+
+class cmake;
+class cmMakefile;
+class cmSourceFile;
+class cmGlobalGenerator;
+class cmComputeLinkInformation;
+class cmListFileBacktrace;
+class cmTarget;
+class cmGeneratorTarget;
+class cmTargetTraceDependencies;
+
+// Basic information about each link item.
+class cmLinkItem: public std::string
+{
+ typedef std::string std_string;
+public:
+ cmLinkItem(): std_string(), Target(0) {}
+ cmLinkItem(const std_string& n,
+ cmTarget const* t): std_string(n), Target(t) {}
+ cmLinkItem(cmLinkItem const& r): std_string(r), Target(r.Target) {}
+ cmTarget const* Target;
+};
+class cmLinkImplItem: public cmLinkItem
+{
+public:
+ cmLinkImplItem(): cmLinkItem(), Backtrace(0), FromGenex(false) {}
+ cmLinkImplItem(std::string const& n,
+ cmTarget const* t,
+ cmListFileBacktrace const& bt,
+ bool fromGenex):
+ cmLinkItem(n, t), Backtrace(bt), FromGenex(fromGenex) {}
+ cmLinkImplItem(cmLinkImplItem const& r):
+ cmLinkItem(r), Backtrace(r.Backtrace), FromGenex(r.FromGenex) {}
+ cmListFileBacktrace Backtrace;
+ bool FromGenex;
+};
+
+struct cmTargetLinkInformationMap:
+ public std::map<std::string, cmComputeLinkInformation*>
+{
+ typedef std::map<std::string, cmComputeLinkInformation*> derived;
+ cmTargetLinkInformationMap() {}
+ cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r);
+ ~cmTargetLinkInformationMap();
+};
+
+class cmTargetInternals;
+class cmTargetInternalPointer
+{
+public:
+ cmTargetInternalPointer();
+ cmTargetInternalPointer(cmTargetInternalPointer const& r);
+ ~cmTargetInternalPointer();
+ cmTargetInternalPointer& operator=(cmTargetInternalPointer const& r);
+ cmTargetInternals* operator->() const { return this->Pointer; }
+ cmTargetInternals* Get() const { return this->Pointer; }
+private:
+ cmTargetInternals* Pointer;
+};
+
+/** \class cmTarget
+ * \brief Represent a library or executable target loaded from a makefile.
+ *
+ * cmTarget represents a target loaded from
+ * a makefile.
+ */
+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
+ {
+ return this->TargetTypeValue;
+ }
+
+ /**
+ * Set the target type
+ */
+ void SetType(TargetType f, const std::string& name);
+
+ void MarkAsImported();
+
+ ///! 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);
+ cmMakefile *GetMakefile() const { return this->Makefile;}
+
+#define DECLARE_TARGET_POLICY(POLICY) \
+ cmPolicies::PolicyStatus GetPolicyStatus ## POLICY () const \
+ { return this->PolicyStatus ## POLICY; }
+
+ CM_FOR_EACH_TARGET_POLICY(DECLARE_TARGET_POLICY)
+
+#undef DECLARE_TARGET_POLICY
+
+ /**
+ * Get the list of the custom commands for this target
+ */
+ std::vector<cmCustomCommand> const &GetPreBuildCommands() const
+ {return this->PreBuildCommands;}
+ std::vector<cmCustomCommand> const &GetPreLinkCommands() const
+ {return this->PreLinkCommands;}
+ std::vector<cmCustomCommand> const &GetPostBuildCommands() const
+ {return this->PostBuildCommands;}
+ void AddPreBuildCommand(cmCustomCommand const &cmd)
+ {this->PreBuildCommands.push_back(cmd);}
+ void AddPreLinkCommand(cmCustomCommand const &cmd)
+ {this->PreLinkCommands.push_back(cmd);}
+ void AddPostBuildCommand(cmCustomCommand const &cmd)
+ {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;
+ bool GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const;
+
+ /**
+ * Add sources to the target.
+ */
+ void AddSources(std::vector<std::string> const& srcs);
+ void AddTracedSources(std::vector<std::string> const& srcs);
+ 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::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);
+ enum TLLSignature {
+ KeywordTLLSignature,
+ PlainTLLSignature
+ };
+ bool PushTLLCommandTrace(TLLSignature signature);
+ void GetTllSignatureTraces(cmOStringStream &s, TLLSignature sig) const;
+
+ void MergeLinkLibraries( cmMakefile& mf, const std::string& selfname,
+ const LinkLibraryVectorType& libs );
+
+ const std::vector<std::string>& GetLinkDirectories() const;
+
+ void AddLinkDirectory(const std::string& d);
+
+ /**
+ * Set the path where this target should be installed. This is relative to
+ * INSTALL_PREFIX
+ */
+ std::string GetInstallPath() const {return this->InstallPath;}
+ void SetInstallPath(const char *name) {this->InstallPath = name;}
+
+ /**
+ * Set the path where this target (if it has a runtime part) should be
+ * installed. This is relative to INSTALL_PREFIX
+ */
+ std::string GetRuntimeInstallPath() const {return this->RuntimeInstallPath;}
+ void SetRuntimeInstallPath(const char *name) {
+ this->RuntimeInstallPath = name; }
+
+ /**
+ * Get/Set whether there is an install rule for this target.
+ */
+ bool GetHaveInstallRule() const { return this->HaveInstallRule; }
+ void SetHaveInstallRule(bool h) { this->HaveInstallRule = h; }
+
+ /** Add a utility on which this project depends. A utility is an executable
+ * name as would be specified to the ADD_EXECUTABLE or UTILITY_SOURCE
+ * commands. It is not a full path nor does it have an extension.
+ */
+ 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,
+ bool asString=false);
+ const char *GetProperty(const std::string& prop) const;
+ const char *GetProperty(const std::string& prop, cmMakefile* context) const;
+ bool GetPropertyAsBool(const std::string& prop) const;
+ void CheckProperty(const std::string& prop, cmMakefile* context) const;
+
+ const char* GetFeature(const std::string& feature,
+ const std::string& config) const;
+ bool GetFeatureAsBool(const std::string& feature,
+ const std::string& config) const;
+
+ bool IsImported() const {return this->IsImportedTarget;}
+
+ void GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const;
+
+ /** The link interface specifies transitive library dependencies and
+ other information needed by targets that link to this target. */
+ struct LinkInterfaceLibraries
+ {
+ // Libraries listed in the interface.
+ std::vector<cmLinkItem> Libraries;
+ };
+ struct LinkInterface: public LinkInterfaceLibraries
+ {
+ // Languages whose runtime libraries must be linked.
+ std::vector<std::string> Languages;
+
+ // Shared library dependencies needed for linking on some platforms.
+ std::vector<cmLinkItem> SharedDeps;
+
+ // Number of repetitions of a strongly connected component of two
+ // or more static libraries.
+ int Multiplicity;
+
+ // Libraries listed for other configurations.
+ // Needed only for OLD behavior of CMP0003.
+ std::vector<cmLinkItem> WrongConfigLibraries;
+
+ bool ImplementationIsInterface;
+
+ LinkInterface(): Multiplicity(0), ImplementationIsInterface(false) {}
+ };
+
+ /** Get the link interface for the given configuration. Returns 0
+ if the target cannot be linked. */
+ LinkInterface const* GetLinkInterface(const std::string& config,
+ cmTarget const* headTarget) const;
+ LinkInterfaceLibraries const*
+ GetLinkInterfaceLibraries(const std::string& config,
+ cmTarget const* headTarget,
+ bool usage_requirements_only) const;
+
+ std::vector<cmTarget const*> const&
+ GetLinkImplementationClosure(const std::string& config) const;
+
+ struct CompatibleInterfaces
+ {
+ std::set<std::string> PropsBool;
+ std::set<std::string> PropsString;
+ std::set<std::string> PropsNumberMax;
+ std::set<std::string> PropsNumberMin;
+ };
+ CompatibleInterfaces const&
+ GetCompatibleInterfaces(std::string const& config) const;
+
+ /** The link implementation specifies the direct library
+ dependencies needed by the object files of the target. */
+ struct LinkImplementationLibraries
+ {
+ // Libraries linked directly in this configuration.
+ std::vector<cmLinkImplItem> Libraries;
+
+ // Libraries linked directly in other configurations.
+ // Needed only for OLD behavior of CMP0003.
+ std::vector<cmLinkItem> WrongConfigLibraries;
+ };
+ struct LinkImplementation: public LinkImplementationLibraries
+ {
+ // Languages whose runtime libraries must be linked.
+ std::vector<std::string> Languages;
+ };
+ LinkImplementation const*
+ GetLinkImplementation(const std::string& config) const;
+
+ LinkImplementationLibraries const*
+ GetLinkImplementationLibraries(const std::string& config) const;
+
+ /** Link information from the transitive closure of the link
+ implementation and the interfaces of its dependencies. */
+ struct LinkClosure
+ {
+ // The preferred linker language.
+ std::string LinkerLanguage;
+
+ // Languages whose runtime libraries must be linked.
+ std::vector<std::string> Languages;
+ };
+ LinkClosure const* GetLinkClosure(const std::string& 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;
+
+ /** 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
+ compiler pdb output directory is given. */
+ std::string GetCompilePDBDirectory(const std::string& config = "") const;
+
+ /** Get the location of the target in the build tree for the given
+ configuration. */
+ const char* GetLocation(const std::string& config) const;
+
+ /** 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. */
+ const char* GetLocationForBuild() 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;
+
+ ///! Return the preferred linker language for this target
+ std::string GetLinkerLanguage(const std::string& config = "") const;
+
+ /** Get the full name of the target according to the settings in its
+ makefile. */
+ std::string GetFullName(const std::string& config="",
+ bool implib = false) const;
+ void GetFullNameComponents(std::string& prefix,
+ std::string& base, std::string& suffix,
+ const std::string& config="",
+ bool implib = false) const;
+
+ /** Get the name of the pdb file for the target. */
+ std::string GetPDBName(const std::string& config) const;
+
+ /** Get the name of the compiler pdb file for the target. */
+ std::string GetCompilePDBName(const std::string& config="") const;
+
+ /** Get the path for the MSVC /Fd option for this target. */
+ std::string GetCompilePDBPath(const std::string& config="") const;
+
+ /** Whether this library has soname enabled and platform supports it. */
+ bool HasSOName(const std::string& config) const;
+
+ /** Get the soname of the target. Allowed only for a shared library. */
+ std::string GetSOName(const std::string& config) 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;
+
+ /** Get the full path to the target according to the settings in its
+ makefile and the configuration type. */
+ std::string GetFullPath(const std::string& config="", bool implib = false,
+ bool realname = false) const;
+
+ /** Get the names of the library needed to generate a build rule
+ that takes into account shared library version numbers. This
+ should be called only on a library target. */
+ void GetLibraryNames(std::string& name, std::string& soName,
+ std::string& realName, std::string& impName,
+ std::string& pdbName, const std::string& config) const;
+
+ /** Get the names of the executable needed to generate a build rule
+ that takes into account executable version numbers. This should
+ be called only on an executable target. */
+ void GetExecutableNames(std::string& name, std::string& realName,
+ std::string& impName,
+ std::string& pdbName,
+ 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;
+
+ /**
+ * Compute whether this target must be relinked before installing.
+ */
+ bool NeedRelinkBeforeInstall(const std::string& config) const;
+
+ bool HaveBuildTreeRPATH(const std::string& config) const;
+ bool HaveInstallTreeRPATH() const;
+
+ /** Return true if builtin chrpath will work for this target */
+ bool IsChrpathUsed(const std::string& config) const;
+
+ /** Return the install name directory for the target in the
+ * build tree. For example: "\@rpath/", "\@loader_path/",
+ * or "/full/path/to/library". */
+ std::string GetInstallNameDirForBuildTree(const std::string& config) const;
+
+ /** Return the install name directory for the target in the
+ * install tree. For example: "\@rpath/" or "\@loader_path/". */
+ std::string GetInstallNameDirForInstallTree() const;
+
+ cmComputeLinkInformation*
+ GetLinkInformation(const std::string& config) const;
+
+ // Get the properties
+ cmPropertyMap &GetProperties() const { return this->Properties; }
+
+ bool GetMappedConfig(std::string const& desired_config,
+ const char** loc,
+ const char** imp,
+ std::string& suffix) const;
+
+ // Define the properties
+ static void DefineProperties(cmake *cm);
+
+ /** Get the macro to define when building sources in this target.
+ If no macro should be defined null is returned. */
+ const char* GetExportMacro() const;
+
+ void GetCompileDefinitions(std::vector<std::string> &result,
+ const std::string& config) 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
+ // information to forward these property changes to the targets
+ // until we have per-target object file properties.
+ void GetLanguages(std::set<std::string>& languages,
+ std::string const& config) 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 an executable Bundle on Apple. */
+ bool IsAppBundleOnApple() const;
+
+ /** Return whether this target is an executable Bundle, a framework
+ or CFBundle on Apple. */
+ bool IsBundleOnApple() 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 the mac content directory for this target. */
+ std::string GetMacContentDirectory(const std::string& config,
+ bool implib) const;
+
+ /** @return whether this target have a well defined output file name. */
+ bool HaveWellDefinedOutputFiles() const;
+
+ /** @return the Mac framework directory without the base. */
+ std::string GetFrameworkDirectory(const std::string& config,
+ bool rootDir) const;
+
+ /** @return the Mac CFBundle directory without the base */
+ std::string GetCFBundleDirectory(const std::string& config,
+ bool contentOnly) const;
+
+ /** @return the Mac App directory without the base */
+ std::string GetAppBundleDirectory(const std::string& config,
+ bool contentOnly) const;
+
+ std::vector<std::string> GetIncludeDirectories(
+ const std::string& config) const;
+ void InsertInclude(const cmValueWithOrigin &entry,
+ bool before = false);
+ void InsertCompileOption(const cmValueWithOrigin &entry,
+ bool before = false);
+ void InsertCompileDefinition(const cmValueWithOrigin &entry);
+
+ void AppendBuildInterfaceIncludes();
+
+ void GetCompileOptions(std::vector<std::string> &result,
+ const std::string& config) const;
+ void GetAutoUicOptions(std::vector<std::string> &result,
+ const std::string& config) const;
+ void GetCompileFeatures(std::vector<std::string> &features,
+ const std::string& config) const;
+
+ bool IsNullImpliedByLinkLibraries(const std::string &p) const;
+ bool IsLinkInterfaceDependentBoolProperty(const std::string &p,
+ const std::string& config) const;
+ bool IsLinkInterfaceDependentStringProperty(const std::string &p,
+ const std::string& config) const;
+ bool IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
+ const std::string& config) const;
+ bool IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
+ const std::string& config) const;
+
+ bool GetLinkInterfaceDependentBoolProperty(const std::string &p,
+ const std::string& config) const;
+
+ const char *GetLinkInterfaceDependentStringProperty(const std::string &p,
+ const std::string& config) const;
+ const char *GetLinkInterfaceDependentNumberMinProperty(const std::string &p,
+ const std::string& config) const;
+ const char *GetLinkInterfaceDependentNumberMaxProperty(const std::string &p,
+ const std::string& config) const;
+
+ std::string GetDebugGeneratorExpressions(const std::string &value,
+ cmTarget::LinkLibraryType llt) const;
+
+ void AddSystemIncludeDirectories(const std::set<std::string> &incs);
+ void AddSystemIncludeDirectories(const std::vector<std::string> &incs);
+ std::set<std::string> const & GetSystemIncludeDirectories() const
+ { return this->SystemIncludeDirectories; }
+
+ bool LinkLanguagePropagatesToDependents() const
+ { return this->TargetTypeValue == STATIC_LIBRARY; }
+
+ void ReportPropertyOrigin(const std::string &p,
+ const std::string &result,
+ const std::string &report,
+ const std::string &compatibilityType) const;
+
+ std::map<std::string, std::string> const&
+ GetMaxLanguageStandards() const
+ {
+ return this->MaxLanguageStandards;
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ const LinkLibraryVectorType &GetLinkLibrariesForVS6() const {
+ return this->LinkLibrariesForVS6;}
+#endif
+
+private:
+ bool HandleLocationPropertyPolicy(cmMakefile* context) const;
+
+ // The set of include directories that are marked as system include
+ // directories.
+ std::set<std::string> SystemIncludeDirectories;
+
+ std::vector<std::pair<TLLSignature, cmListFileBacktrace> > TLLCommands;
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /**
+ * A list of direct dependencies. Use in conjunction with DependencyMap.
+ */
+ typedef std::vector< LibraryID > DependencyList;
+
+ /**
+ * This map holds the dependency graph. map[x] returns a set of
+ * direct dependencies of x. Note that the direct depenencies are
+ * ordered. This is necessary to handle direct dependencies that
+ * themselves have no dependency information.
+ */
+ typedef std::map< LibraryID, DependencyList > DependencyMap;
+
+ /**
+ * Inserts \a dep at the end of the dependency list of \a lib.
+ */
+ void InsertDependencyForVS6( DependencyMap& depMap,
+ const LibraryID& lib,
+ const LibraryID& dep);
+
+ /*
+ * Deletes \a dep from the dependency list of \a lib.
+ */
+ void DeleteDependencyForVS6( DependencyMap& depMap,
+ const LibraryID& lib,
+ const LibraryID& dep);
+
+ /**
+ * Emits the library \a lib and all its dependencies into link_line.
+ * \a emitted keeps track of the libraries that have been emitted to
+ * avoid duplicates--it is more efficient than searching
+ * link_line. \a visited is used detect cycles. Note that \a
+ * link_line is in reverse order, in that the dependencies of a
+ * library are listed before the library itself.
+ */
+ void EmitForVS6( const LibraryID lib,
+ const DependencyMap& dep_map,
+ std::set<LibraryID>& emitted,
+ std::set<LibraryID>& visited,
+ DependencyList& link_line);
+
+ /**
+ * Finds the dependencies for \a lib and inserts them into \a
+ * dep_map.
+ */
+ void GatherDependenciesForVS6( const cmMakefile& mf,
+ const LibraryID& lib,
+ DependencyMap& dep_map);
+
+ void AnalyzeLibDependenciesForVS6( const cmMakefile& mf );
+#endif
+
+ const char* GetSuffixVariableInternal(bool implib) const;
+ const char* GetPrefixVariableInternal(bool implib) const;
+ std::string GetFullNameInternal(const std::string& config,
+ bool implib) const;
+ void GetFullNameInternal(const std::string& config, bool implib,
+ std::string& outPrefix, std::string& outBase,
+ std::string& outSuffix) const;
+
+ // Use a makefile variable to set a default for the given property.
+ // If the variable is not defined use the given default instead.
+ 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;
+
+ // Get the target base name.
+ std::string GetOutputName(const std::string& config, bool implib) const;
+
+ std::string GetFullNameImported(const std::string& config,
+ bool implib) const;
+
+ std::string ImportedGetFullPath(const std::string& config,
+ bool implib) const;
+ std::string NormalGetFullPath(const std::string& config, bool implib,
+ bool realname) const;
+
+ /** Get the real name of the target. Allowed only for non-imported
+ targets. When a library or executable file is versioned this is
+ the full versioned name. If the target is not versioned this is
+ the same as GetFullName. */
+ std::string NormalGetRealName(const std::string& config) const;
+
+ /** Append to @a base the mac content directory and return it. */
+ std::string BuildMacContentDirectory(const std::string& base,
+ const std::string& config,
+ bool contentOnly) const;
+
+ void GetSourceFiles(std::vector<std::string> &files,
+ const std::string& config) const;
+private:
+ std::string Name;
+ std::vector<cmCustomCommand> PreBuildCommands;
+ std::vector<cmCustomCommand> PreLinkCommands;
+ std::vector<cmCustomCommand> PostBuildCommands;
+ TargetType TargetTypeValue;
+ LinkLibraryVectorType PrevLinkedLibraries;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ LinkLibraryVectorType LinkLibrariesForVS6;
+ bool LinkLibrariesForVS6Analyzed;
+#endif
+ std::vector<std::string> LinkDirectories;
+ std::set<std::string> LinkDirectoriesEmmitted;
+ bool HaveInstallRule;
+ std::string InstallPath;
+ std::string RuntimeInstallPath;
+ mutable std::string ExportMacro;
+ std::set<std::string> Utilities;
+ std::map<std::string, cmListFileBacktrace> UtilityBacktraces;
+ bool RecordDependencies;
+ mutable cmPropertyMap Properties;
+ LinkLibraryVectorType OriginalLinkLibraries;
+ bool DLLPlatform;
+ bool IsAndroid;
+ bool IsApple;
+ bool IsImportedTarget;
+ mutable bool DebugIncludesDone;
+ mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
+ mutable bool DebugCompileOptionsDone;
+ mutable bool DebugCompileDefinitionsDone;
+ mutable bool DebugSourcesDone;
+ mutable bool DebugCompileFeaturesDone;
+ mutable std::set<std::string> LinkImplicitNullProperties;
+ mutable std::map<std::string, std::string> MaxLanguageStandards;
+ bool BuildInterfaceIncludesAppended;
+
+ // 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 const* GetImportInfo(const std::string& config) const;
+ void ComputeImportInfo(std::string const& desired_config,
+ ImportInfo& info) const;
+
+ // Cache target compile paths for each configuration.
+ struct CompileInfo;
+ CompileInfo const* GetCompileInfo(const std::string& config) const;
+
+ mutable cmTargetLinkInformationMap LinkInformation;
+ void CheckPropertyCompatibility(cmComputeLinkInformation *info,
+ const std::string& config) const;
+
+ LinkInterface const*
+ GetImportLinkInterface(const std::string& config, cmTarget const* head,
+ bool usage_requirements_only) const;
+
+ LinkImplementationLibraries const*
+ GetLinkImplementationLibrariesInternal(const std::string& config,
+ cmTarget const* head) const;
+ void ComputeLinkClosure(const std::string& config, LinkClosure& lc) const;
+
+ void ExpandLinkItems(std::string const& prop, std::string const& value,
+ std::string const& config, cmTarget const* 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;
+
+ std::string ProcessSourceItemCMP0049(const std::string& s);
+
+ void ClearLinkMaps();
+
+ void MaybeInvalidatePropertyCache(const std::string& prop);
+
+ void ProcessSourceExpression(std::string const& expr);
+
+ // The cmMakefile instance that owns this target. This should
+ // always be set.
+ cmMakefile* Makefile;
+
+ // Policy status recorded when target was created.
+#define TARGET_POLICY_MEMBER(POLICY) \
+ cmPolicies::PolicyStatus PolicyStatus ## POLICY;
+
+ CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_MEMBER)
+
+#undef TARGET_POLICY_MEMBER
+
+ // Internal representation details.
+ friend class cmTargetInternals;
+ friend class cmGeneratorTarget;
+ friend class cmTargetTraceDependencies;
+ cmTargetInternalPointer Internal;
+
+ 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;
+
+ mutable bool LinkImplementationLanguageIsContextDependent;
+};
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+typedef cmsys::hash_map<std::string,cmTarget> cmTargets;
+#else
+typedef std::map<std::string,cmTarget> cmTargets;
+#endif
+
+class cmTargetSet: public std::set<std::string> {};
+class cmTargetManifest: public std::map<std::string, cmTargetSet> {};
+
+#endif
diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx
new file mode 100644
index 0000000000..66d8ad34a3
--- /dev/null
+++ b/Source/cmTargetCompileDefinitionsCommand.cxx
@@ -0,0 +1,67 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmTargetCompileDefinitionsCommand.h"
+
+bool cmTargetCompileDefinitionsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ return this->HandleArguments(args, "COMPILE_DEFINITIONS");
+}
+
+void cmTargetCompileDefinitionsCommand
+::HandleImportedTarget(const std::string &tgt)
+{
+ cmOStringStream e;
+ e << "Cannot specify compile definitions for imported target \""
+ << tgt << "\".";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+void cmTargetCompileDefinitionsCommand
+::HandleMissingTarget(const std::string &name)
+{
+ cmOStringStream e;
+ e << "Cannot specify compile definitions for target \"" << name << "\" "
+ "which is not built by this project.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+//----------------------------------------------------------------------------
+std::string cmTargetCompileDefinitionsCommand
+::Join(const std::vector<std::string> &content)
+{
+ std::string defs;
+ std::string sep;
+ for(std::vector<std::string>::const_iterator it = content.begin();
+ it != content.end(); ++it)
+ {
+ if (cmHasLiteralPrefix(it->c_str(), "-D"))
+ {
+ defs += sep + it->substr(2);
+ }
+ else
+ {
+ defs += sep + *it;
+ }
+ sep = ";";
+ }
+ return defs;
+}
+
+//----------------------------------------------------------------------------
+bool cmTargetCompileDefinitionsCommand
+::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
+ bool, bool)
+{
+ tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
+ return true;
+}
diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h
new file mode 100644
index 0000000000..b548c70a0e
--- /dev/null
+++ b/Source/cmTargetCompileDefinitionsCommand.h
@@ -0,0 +1,53 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmTargetCompileDefinitionsCommand_h
+#define cmTargetCompileDefinitionsCommand_h
+
+#include "cmTargetPropCommandBase.h"
+
+class cmTargetCompileDefinitionsCommand : public cmTargetPropCommandBase
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmTargetCompileDefinitionsCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "target_compile_definitions";}
+
+ cmTypeMacro(cmTargetCompileDefinitionsCommand, cmTargetPropCommandBase);
+
+private:
+ virtual void HandleImportedTarget(const std::string &tgt);
+ virtual void HandleMissingTarget(const std::string &name);
+
+ virtual bool HandleDirectContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system);
+ virtual std::string Join(const std::vector<std::string> &content);
+};
+
+#endif
diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx
new file mode 100644
index 0000000000..10daad4648
--- /dev/null
+++ b/Source/cmTargetCompileFeaturesCommand.cxx
@@ -0,0 +1,70 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmTargetCompileFeaturesCommand.h"
+
+bool cmTargetCompileFeaturesCommand::InitialPass(
+ std::vector<std::string> const& args,
+ cmExecutionStatus &)
+{
+ return this->HandleArguments(args, "COMPILE_FEATURES", NO_FLAGS);
+}
+
+void cmTargetCompileFeaturesCommand
+::HandleImportedTarget(const std::string &tgt)
+{
+ cmOStringStream e;
+ e << "Cannot specify compile features for imported target \""
+ << tgt << "\".";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+void cmTargetCompileFeaturesCommand
+::HandleMissingTarget(const std::string &name)
+{
+ cmOStringStream e;
+ e << "Cannot specify compile features for target \"" << name << "\" "
+ "which is not built by this project.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+//----------------------------------------------------------------------------
+std::string cmTargetCompileFeaturesCommand
+::Join(const std::vector<std::string> &content)
+{
+ std::string defs;
+ std::string sep;
+ for(std::vector<std::string>::const_iterator it = content.begin();
+ it != content.end(); ++it)
+ {
+ defs += sep + *it;
+ sep = ";";
+ }
+ return defs;
+}
+
+//----------------------------------------------------------------------------
+bool cmTargetCompileFeaturesCommand
+::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
+ bool, bool)
+{
+ for(std::vector<std::string>::const_iterator it = content.begin();
+ it != content.end(); ++it)
+ {
+ std::string error;
+ if(!this->Makefile->AddRequiredTargetFeature(tgt, *it, &error))
+ {
+ this->SetError(error);
+ return false;
+ }
+ }
+ return true;
+}
diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h
new file mode 100644
index 0000000000..fa7ae8d073
--- /dev/null
+++ b/Source/cmTargetCompileFeaturesCommand.h
@@ -0,0 +1,41 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmTargetCompileFeaturesCommand_h
+#define cmTargetCompileFeaturesCommand_h
+
+#include "cmTargetPropCommandBase.h"
+
+class cmTargetCompileFeaturesCommand : public cmTargetPropCommandBase
+{
+ virtual cmCommand* Clone()
+ {
+ return new cmTargetCompileFeaturesCommand;
+ }
+
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ virtual std::string GetName() const { return "target_compile_features";}
+
+ cmTypeMacro(cmTargetCompileFeaturesCommand, cmTargetPropCommandBase);
+
+private:
+ virtual void HandleImportedTarget(const std::string &tgt);
+ virtual void HandleMissingTarget(const std::string &name);
+
+ virtual bool HandleDirectContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system);
+ virtual std::string Join(const std::vector<std::string> &content);
+};
+
+#endif
diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx
new file mode 100644
index 0000000000..3fb76a6ddd
--- /dev/null
+++ b/Source/cmTargetCompileOptionsCommand.cxx
@@ -0,0 +1,62 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmTargetCompileOptionsCommand.h"
+
+bool cmTargetCompileOptionsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ return this->HandleArguments(args, "COMPILE_OPTIONS", PROCESS_BEFORE);
+}
+
+void cmTargetCompileOptionsCommand
+::HandleImportedTarget(const std::string &tgt)
+{
+ cmOStringStream e;
+ e << "Cannot specify compile options for imported target \""
+ << tgt << "\".";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+void cmTargetCompileOptionsCommand
+::HandleMissingTarget(const std::string &name)
+{
+ cmOStringStream e;
+ e << "Cannot specify compile options for target \"" << name << "\" "
+ "which is not built by this project.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+//----------------------------------------------------------------------------
+std::string cmTargetCompileOptionsCommand
+::Join(const std::vector<std::string> &content)
+{
+ std::string defs;
+ std::string sep;
+ for(std::vector<std::string>::const_iterator it = content.begin();
+ it != content.end(); ++it)
+ {
+ defs += sep + *it;
+ sep = ";";
+ }
+ return defs;
+}
+
+//----------------------------------------------------------------------------
+bool cmTargetCompileOptionsCommand
+::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
+ bool, bool)
+{
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmValueWithOrigin entry(this->Join(content), lfbt);
+ tgt->InsertCompileOption(entry);
+ return true;
+}
diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h
new file mode 100644
index 0000000000..d43534d4a3
--- /dev/null
+++ b/Source/cmTargetCompileOptionsCommand.h
@@ -0,0 +1,53 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmTargetCompileOptionsCommand_h
+#define cmTargetCompileOptionsCommand_h
+
+#include "cmTargetPropCommandBase.h"
+
+class cmTargetCompileOptionsCommand : public cmTargetPropCommandBase
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmTargetCompileOptionsCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "target_compile_options";}
+
+ cmTypeMacro(cmTargetCompileOptionsCommand, cmTargetPropCommandBase);
+
+private:
+ virtual void HandleImportedTarget(const std::string &tgt);
+ virtual void HandleMissingTarget(const std::string &name);
+
+ virtual bool HandleDirectContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system);
+ virtual std::string Join(const std::vector<std::string> &content);
+};
+
+#endif
diff --git a/Source/cmTargetDepend.h b/Source/cmTargetDepend.h
new file mode 100644
index 0000000000..1feb07203e
--- /dev/null
+++ b/Source/cmTargetDepend.h
@@ -0,0 +1,48 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2010 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 cmTargetDepend_h
+#define cmTargetDepend_h
+
+#include "cmStandardIncludes.h"
+
+class cmTarget;
+
+/** One edge in the global target dependency graph.
+ It may be marked as a 'link' or 'util' edge or both. */
+class cmTargetDepend
+{
+ cmTarget const* Target;
+
+ // The set order depends only on the Target, so we use
+ // mutable members to acheive a map with set syntax.
+ mutable bool Link;
+ mutable bool Util;
+public:
+ cmTargetDepend(cmTarget const* t): Target(t), Link(false), Util(false) {}
+ operator cmTarget const*() const { return this->Target; }
+ cmTarget const* operator->() const { return this->Target; }
+ cmTarget const& operator*() const { return *this->Target; }
+ friend bool operator < (cmTargetDepend const& l, cmTargetDepend const& r)
+ { return l.Target < r.Target; }
+ void SetType(bool strong) const
+ {
+ if(strong) { this->Util = true; }
+ else { this->Link = true; }
+ }
+ bool IsLink() const { return this->Link; }
+ bool IsUtil() const { return this->Util; }
+};
+
+/** Unordered set of (direct) dependencies of a target. */
+class cmTargetDependSet: public std::set<cmTargetDepend> {};
+
+#endif
diff --git a/Source/cmTargetExport.h b/Source/cmTargetExport.h
new file mode 100644
index 0000000000..76658887d4
--- /dev/null
+++ b/Source/cmTargetExport.h
@@ -0,0 +1,42 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 cmTargetExport_h
+#define cmTargetExport_h
+
+#include "cmStandardIncludes.h"
+
+class cmTarget;
+class cmInstallTargetGenerator;
+class cmInstallFilesGenerator;
+
+/** \brief A member of an ExportSet
+ *
+ * This struct holds pointers to target and all relevant generators.
+ */
+class cmTargetExport
+{
+public:
+ cmTarget* Target; ///< The target
+
+ ///@name Generators
+ ///@{
+ cmInstallTargetGenerator* ArchiveGenerator;
+ cmInstallTargetGenerator* RuntimeGenerator;
+ cmInstallTargetGenerator* LibraryGenerator;
+ cmInstallTargetGenerator* FrameworkGenerator;
+ cmInstallTargetGenerator* BundleGenerator;
+ cmInstallFilesGenerator* HeaderGenerator;
+ std::string InterfaceIncludeDirectories;
+ ///@}
+};
+
+#endif
diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx
new file mode 100644
index 0000000000..e9f0e047ff
--- /dev/null
+++ b/Source/cmTargetIncludeDirectoriesCommand.cxx
@@ -0,0 +1,106 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmTargetIncludeDirectoriesCommand.h"
+
+#include "cmGeneratorExpression.h"
+
+//----------------------------------------------------------------------------
+bool cmTargetIncludeDirectoriesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ return this->HandleArguments(args, "INCLUDE_DIRECTORIES",
+ ArgumentFlags(PROCESS_BEFORE | PROCESS_SYSTEM));
+}
+
+//----------------------------------------------------------------------------
+void cmTargetIncludeDirectoriesCommand
+::HandleImportedTarget(const std::string &tgt)
+{
+ cmOStringStream e;
+ e << "Cannot specify include directories for imported target \""
+ << tgt << "\".";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+//----------------------------------------------------------------------------
+void cmTargetIncludeDirectoriesCommand
+::HandleMissingTarget(const std::string &name)
+{
+ cmOStringStream e;
+ e << "Cannot specify include directories for target \"" << name << "\" "
+ "which is not built by this project.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+//----------------------------------------------------------------------------
+std::string cmTargetIncludeDirectoriesCommand
+::Join(const std::vector<std::string> &content)
+{
+ std::string dirs;
+ std::string sep;
+ std::string prefix = this->Makefile->GetStartDirectory() + std::string("/");
+ for(std::vector<std::string>::const_iterator it = content.begin();
+ it != content.end(); ++it)
+ {
+ if (cmSystemTools::FileIsFullPath(it->c_str())
+ || cmGeneratorExpression::Find(*it) == 0)
+ {
+ dirs += sep + *it;
+ }
+ else
+ {
+ dirs += sep + prefix + *it;
+ }
+ sep = ";";
+ }
+ return dirs;
+}
+
+//----------------------------------------------------------------------------
+bool cmTargetIncludeDirectoriesCommand
+::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
+ bool prepend, bool system)
+{
+ cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+ cmValueWithOrigin entry(this->Join(content), lfbt);
+ tgt->InsertInclude(entry, prepend);
+ if (system)
+ {
+ tgt->AddSystemIncludeDirectories(content);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmTargetIncludeDirectoriesCommand
+::HandleInterfaceContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system)
+{
+ cmTargetPropCommandBase::HandleInterfaceContent(tgt, content,
+ prepend, system);
+
+ if (system)
+ {
+ std::string joined;
+ std::string sep;
+ for(std::vector<std::string>::const_iterator it = content.begin();
+ it != content.end(); ++it)
+ {
+ joined += sep;
+ sep = ";";
+ joined += *it;
+ }
+ tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES",
+ joined.c_str());
+ }
+}
diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h
new file mode 100644
index 0000000000..2a7814e78b
--- /dev/null
+++ b/Source/cmTargetIncludeDirectoriesCommand.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmTargetIncludeDirectoriesCommand_h
+#define cmTargetIncludeDirectoriesCommand_h
+
+#include "cmTargetPropCommandBase.h"
+
+//----------------------------------------------------------------------------
+class cmTargetIncludeDirectoriesCommand : public cmTargetPropCommandBase
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmTargetIncludeDirectoriesCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "target_include_directories";}
+
+ cmTypeMacro(cmTargetIncludeDirectoriesCommand, cmTargetPropCommandBase);
+
+private:
+ virtual void HandleImportedTarget(const std::string &tgt);
+ virtual void HandleMissingTarget(const std::string &name);
+
+ virtual bool HandleDirectContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system);
+ virtual void HandleInterfaceContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system);
+
+ virtual std::string Join(const std::vector<std::string> &content);
+};
+
+#endif
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
new file mode 100644
index 0000000000..56e1338175
--- /dev/null
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -0,0 +1,505 @@
+/*============================================================================
+ 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 "cmTargetLinkLibrariesCommand.h"
+
+#include "cmGeneratorExpression.h"
+
+const char* cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[3] =
+{
+ "general",
+ "debug",
+ "optimized"
+};
+
+// cmTargetLinkLibrariesCommand
+bool cmTargetLinkLibrariesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ // must have one argument
+ if(args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ if (this->Makefile->IsAlias(args[0]))
+ {
+ this->SetError("can not be used on an ALIAS target.");
+ return false;
+ }
+ // Lookup the target for which libraries are specified.
+ this->Target =
+ this->Makefile->GetCMakeInstance()
+ ->GetGlobalGenerator()->FindTarget(args[0]);
+ if(!this->Target)
+ {
+ cmake::MessageType t = cmake::FATAL_ERROR; // fail by default
+ cmOStringStream e;
+ e << "Cannot specify link libraries for target \"" << args[0] << "\" "
+ << "which is not built by this project.";
+ // The bad target is the only argument. Check how policy CMP0016 is set,
+ // and accept, warn or fail respectively:
+ if (args.size() < 2)
+ {
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0016))
+ {
+ case cmPolicies::WARN:
+ t = cmake::AUTHOR_WARNING;
+ // Print the warning.
+ e << "\n"
+ << "CMake does not support this but it used to work accidentally "
+ << "and is being allowed for compatibility."
+ << "\n" << this->Makefile->GetPolicies()->
+ GetPolicyWarning(cmPolicies::CMP0016);
+ break;
+ case cmPolicies::OLD: // OLD behavior does not warn.
+ t = cmake::MESSAGE;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ e << "\n" << this->Makefile->GetPolicies()->
+ GetRequiredPolicyError(cmPolicies::CMP0016);
+ break;
+ case cmPolicies::NEW: // NEW behavior prints the error.
+ break;
+ }
+ }
+
+ // now actually print the message
+ switch(t)
+ {
+ case cmake::AUTHOR_WARNING:
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ break;
+ case cmake::FATAL_ERROR:
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ cmSystemTools::SetFatalErrorOccured();
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
+
+ if(this->Target->GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ cmOStringStream e;
+ e << "Object library target \"" << args[0] << "\" "
+ << "may not link to anything.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+
+ if (this->Target->GetType() == cmTarget::UTILITY)
+ {
+ cmOStringStream e;
+ const char *modal = 0;
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0039))
+ {
+ case cmPolicies::WARN:
+ e << this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0039) << "\n";
+ modal = "should";
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW:
+ modal = "must";
+ messageType = cmake::FATAL_ERROR;
+ }
+ if (modal)
+ {
+ e <<
+ "Utility target \"" << this->Target->GetName() << "\" " << modal
+ << " not be used as the target of a target_link_libraries call.";
+ this->Makefile->IssueMessage(messageType, e.str());
+ if(messageType == cmake::FATAL_ERROR)
+ {
+ return false;
+ }
+ }
+ }
+
+ // but we might not have any libs after variable expansion
+ if(args.size() < 2)
+ {
+ return true;
+ }
+
+ // Keep track of link configuration specifiers.
+ cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
+ bool haveLLT = false;
+
+ // Start with primary linking and switch to link interface
+ // specification if the keyword is encountered as the first argument.
+ this->CurrentProcessingState = ProcessingLinkLibraries;
+
+ // add libraries, note that there is an optional prefix
+ // of debug and optimized that can be used
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "LINK_INTERFACE_LIBRARIES")
+ {
+ this->CurrentProcessingState = ProcessingPlainLinkInterface;
+ if(i != 1)
+ {
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ "The LINK_INTERFACE_LIBRARIES option must appear as the second "
+ "argument, just after the target name."
+ );
+ return true;
+ }
+ }
+ else if(args[i] == "INTERFACE")
+ {
+ if(i != 1
+ && this->CurrentProcessingState != ProcessingKeywordPrivateInterface
+ && this->CurrentProcessingState != ProcessingKeywordPublicInterface
+ && this->CurrentProcessingState != ProcessingKeywordLinkInterface)
+ {
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ "The INTERFACE option must appear as the second "
+ "argument, just after the target name."
+ );
+ return true;
+ }
+ this->CurrentProcessingState = ProcessingKeywordLinkInterface;
+ }
+ else if(args[i] == "LINK_PUBLIC")
+ {
+ if(i != 1
+ && this->CurrentProcessingState != ProcessingPlainPrivateInterface
+ && this->CurrentProcessingState != ProcessingPlainPublicInterface)
+ {
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ "The LINK_PUBLIC or LINK_PRIVATE option must appear as the second "
+ "argument, just after the target name."
+ );
+ return true;
+ }
+ this->CurrentProcessingState = ProcessingPlainPublicInterface;
+ }
+ else if(args[i] == "PUBLIC")
+ {
+ if(i != 1
+ && this->CurrentProcessingState != ProcessingKeywordPrivateInterface
+ && this->CurrentProcessingState != ProcessingKeywordPublicInterface
+ && this->CurrentProcessingState != ProcessingKeywordLinkInterface)
+ {
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ "The PUBLIC or PRIVATE option must appear as the second "
+ "argument, just after the target name."
+ );
+ return true;
+ }
+ this->CurrentProcessingState = ProcessingKeywordPublicInterface;
+ }
+ else if(args[i] == "LINK_PRIVATE")
+ {
+ if(i != 1
+ && this->CurrentProcessingState != ProcessingPlainPublicInterface
+ && this->CurrentProcessingState != ProcessingPlainPrivateInterface)
+ {
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ "The LINK_PUBLIC or LINK_PRIVATE option must appear as the second "
+ "argument, just after the target name."
+ );
+ return true;
+ }
+ this->CurrentProcessingState = ProcessingPlainPrivateInterface;
+ }
+ else if(args[i] == "PRIVATE")
+ {
+ if(i != 1
+ && this->CurrentProcessingState != ProcessingKeywordPrivateInterface
+ && this->CurrentProcessingState != ProcessingKeywordPublicInterface
+ && this->CurrentProcessingState != ProcessingKeywordLinkInterface)
+ {
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ "The PUBLIC or PRIVATE option must appear as the second "
+ "argument, just after the target name."
+ );
+ return true;
+ }
+ this->CurrentProcessingState = ProcessingKeywordPrivateInterface;
+ }
+ else if(args[i] == "debug")
+ {
+ if(haveLLT)
+ {
+ this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::DEBUG);
+ }
+ llt = cmTarget::DEBUG;
+ haveLLT = true;
+ }
+ else if(args[i] == "optimized")
+ {
+ if(haveLLT)
+ {
+ this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::OPTIMIZED);
+ }
+ llt = cmTarget::OPTIMIZED;
+ haveLLT = true;
+ }
+ else if(args[i] == "general")
+ {
+ if(haveLLT)
+ {
+ this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::GENERAL);
+ }
+ llt = cmTarget::GENERAL;
+ haveLLT = true;
+ }
+ else if(haveLLT)
+ {
+ // The link type was specified by the previous argument.
+ haveLLT = false;
+ if (!this->HandleLibrary(args[i], llt))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ // Lookup old-style cache entry if type is unspecified. So if you
+ // do a target_link_libraries(foo optimized bar) it will stay optimized
+ // and not use the lookup. As there maybe the case where someone has
+ // 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;
+ std::string linkType = args[0];
+ linkType += "_LINK_TYPE";
+ const char* linkTypeString =
+ this->Makefile->GetDefinition( linkType );
+ if(linkTypeString)
+ {
+ if(strcmp(linkTypeString, "debug") == 0)
+ {
+ llt = cmTarget::DEBUG;
+ }
+ if(strcmp(linkTypeString, "optimized") == 0)
+ {
+ llt = cmTarget::OPTIMIZED;
+ }
+ }
+ if (!this->HandleLibrary(args[i], llt))
+ {
+ return false;
+ }
+ }
+ }
+
+ // Make sure the last argument was not a library type specifier.
+ if(haveLLT)
+ {
+ cmOStringStream e;
+ e << "The \"" << this->LinkLibraryTypeNames[llt]
+ << "\" argument must be followed by a library.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ cmSystemTools::SetFatalErrorOccured();
+ }
+
+ const cmPolicies::PolicyStatus policy22Status
+ = this->Target->GetPolicyStatusCMP0022();
+
+ // If any of the LINK_ options were given, make sure the
+ // LINK_INTERFACE_LIBRARIES target property exists.
+ // Use of any of the new keywords implies awareness of
+ // this property. And if no libraries are named, it should
+ // result in an empty link interface.
+ if((policy22Status == cmPolicies::OLD ||
+ policy22Status == cmPolicies::WARN) &&
+ this->CurrentProcessingState != ProcessingLinkLibraries &&
+ !this->Target->GetProperty("LINK_INTERFACE_LIBRARIES"))
+ {
+ this->Target->SetProperty("LINK_INTERFACE_LIBRARIES", "");
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void
+cmTargetLinkLibrariesCommand
+::LinkLibraryTypeSpecifierWarning(int left, int right)
+{
+ cmOStringStream w;
+ w << "Link library type specifier \""
+ << this->LinkLibraryTypeNames[left] << "\" is followed by specifier \""
+ << this->LinkLibraryTypeNames[right] << "\" instead of a library name. "
+ << "The first specifier will be ignored.";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+}
+
+//----------------------------------------------------------------------------
+bool
+cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
+ cmTarget::LinkLibraryType llt)
+{
+ if(this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
+ && this->CurrentProcessingState != ProcessingKeywordLinkInterface)
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "INTERFACE library can only be used with the INTERFACE keyword of "
+ "target_link_libraries");
+ return false;
+ }
+
+ cmTarget::TLLSignature sig =
+ (this->CurrentProcessingState == ProcessingPlainPrivateInterface
+ || this->CurrentProcessingState == ProcessingPlainPublicInterface
+ || this->CurrentProcessingState == ProcessingKeywordPrivateInterface
+ || this->CurrentProcessingState == ProcessingKeywordPublicInterface
+ || this->CurrentProcessingState == ProcessingKeywordLinkInterface)
+ ? cmTarget::KeywordTLLSignature : cmTarget::PlainTLLSignature;
+ if (!this->Target->PushTLLCommandTrace(sig))
+ {
+ cmOStringStream e;
+ const char *modal = 0;
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0023))
+ {
+ case cmPolicies::WARN:
+ e << this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0023) << "\n";
+ modal = "should";
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW:
+ modal = "must";
+ messageType = cmake::FATAL_ERROR;
+ }
+
+ if(modal)
+ {
+ // If the sig is a keyword form and there is a conflict, the existing
+ // form must be the plain form.
+ const char *existingSig
+ = (sig == cmTarget::KeywordTLLSignature ? "plain"
+ : "keyword");
+ e <<
+ "The " << existingSig << " signature for target_link_libraries "
+ "has already been used with the target \""
+ << this->Target->GetName() << "\". All uses of "
+ "target_link_libraries with a target " << modal << " be either "
+ "all-keyword or all-plain.\n";
+ this->Target->GetTllSignatureTraces(e,
+ sig == cmTarget::KeywordTLLSignature
+ ? cmTarget::PlainTLLSignature
+ : cmTarget::KeywordTLLSignature);
+ this->Makefile->IssueMessage(messageType, e.str());
+ if(messageType == cmake::FATAL_ERROR)
+ {
+ return false;
+ }
+ }
+ }
+
+ // Handle normal case first.
+ if(this->CurrentProcessingState != ProcessingKeywordLinkInterface
+ && this->CurrentProcessingState != ProcessingPlainLinkInterface)
+ {
+ this->Makefile
+ ->AddLinkLibraryForTarget(this->Target->GetName(), lib, llt);
+ if(this->CurrentProcessingState == ProcessingLinkLibraries)
+ {
+ this->Target->AppendProperty("INTERFACE_LINK_LIBRARIES",
+ this->Target->GetDebugGeneratorExpressions(lib, llt).c_str());
+ return true;
+ }
+ else if(this->CurrentProcessingState != ProcessingKeywordPublicInterface
+ && this->CurrentProcessingState != ProcessingPlainPublicInterface)
+ {
+ if (this->Target->GetType() == cmTarget::STATIC_LIBRARY)
+ {
+ std::string configLib = this->Target
+ ->GetDebugGeneratorExpressions(lib, llt);
+ if (cmGeneratorExpression::IsValidTargetName(lib)
+ || cmGeneratorExpression::Find(lib) != std::string::npos)
+ {
+ configLib = "$<LINK_ONLY:" + configLib + ">";
+ }
+ this->Target->AppendProperty("INTERFACE_LINK_LIBRARIES",
+ configLib.c_str());
+ }
+ // Not a 'public' or 'interface' library. Do not add to interface
+ // property.
+ return true;
+ }
+ }
+
+ this->Target->AppendProperty("INTERFACE_LINK_LIBRARIES",
+ this->Target->GetDebugGeneratorExpressions(lib, llt).c_str());
+
+ const cmPolicies::PolicyStatus policy22Status
+ = this->Target->GetPolicyStatusCMP0022();
+
+ if (policy22Status != cmPolicies::OLD
+ && policy22Status != cmPolicies::WARN)
+ {
+ return true;
+ }
+
+ if (this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+ {
+ return true;
+ }
+
+ // Get the list of configurations considered to be DEBUG.
+ std::vector<std::string> const& debugConfigs =
+ this->Makefile->GetCMakeInstance()->GetDebugConfigs();
+ std::string prop;
+
+ // Include this library in the link interface for the target.
+ if(llt == cmTarget::DEBUG || llt == cmTarget::GENERAL)
+ {
+ // Put in the DEBUG configuration interfaces.
+ for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
+ i != debugConfigs.end(); ++i)
+ {
+ prop = "LINK_INTERFACE_LIBRARIES_";
+ prop += *i;
+ this->Target->AppendProperty(prop, lib.c_str());
+ }
+ }
+ if(llt == cmTarget::OPTIMIZED || llt == cmTarget::GENERAL)
+ {
+ // Put in the non-DEBUG configuration interfaces.
+ this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES", lib.c_str());
+
+ // Make sure the DEBUG configuration interfaces exist so that the
+ // general one will not be used as a fall-back.
+ for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
+ i != debugConfigs.end(); ++i)
+ {
+ prop = "LINK_INTERFACE_LIBRARIES_";
+ prop += *i;
+ if(!this->Target->GetProperty(prop))
+ {
+ this->Target->SetProperty(prop, "");
+ }
+ }
+ }
+ return true;
+}
diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h
new file mode 100644
index 0000000000..47dd8bd6cb
--- /dev/null
+++ b/Source/cmTargetLinkLibrariesCommand.h
@@ -0,0 +1,70 @@
+/*============================================================================
+ 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 cmTargetLinkLibrariesCommand_h
+#define cmTargetLinkLibrariesCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmTargetLinkLibrariesCommand
+ * \brief Specify a list of libraries to link into executables.
+ *
+ * cmTargetLinkLibrariesCommand is used to specify a list of libraries to link
+ * into executable(s) or shared objects. The names of the libraries
+ * should be those defined by the LIBRARY(library) command(s).
+ */
+class cmTargetLinkLibrariesCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmTargetLinkLibrariesCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "target_link_libraries";}
+
+ cmTypeMacro(cmTargetLinkLibrariesCommand, cmCommand);
+private:
+ void LinkLibraryTypeSpecifierWarning(int left, int right);
+ static const char* LinkLibraryTypeNames[3];
+
+ cmTarget* Target;
+ enum ProcessingState {
+ ProcessingLinkLibraries,
+ ProcessingPlainLinkInterface,
+ ProcessingKeywordLinkInterface,
+ ProcessingPlainPublicInterface,
+ ProcessingKeywordPublicInterface,
+ ProcessingPlainPrivateInterface,
+ ProcessingKeywordPrivateInterface
+ };
+
+ ProcessingState CurrentProcessingState;
+
+ bool HandleLibrary(const std::string& lib, cmTarget::LinkLibraryType llt);
+};
+
+
+
+#endif
diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx
new file mode 100644
index 0000000000..4696de4348
--- /dev/null
+++ b/Source/cmTargetPropCommandBase.cxx
@@ -0,0 +1,181 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmTargetPropCommandBase.h"
+
+#include "cmGlobalGenerator.h"
+
+//----------------------------------------------------------------------------
+bool cmTargetPropCommandBase
+::HandleArguments(std::vector<std::string> const& args,
+ const std::string& prop,
+ ArgumentFlags flags)
+{
+ if(args.size() < 2)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // Lookup the target for which libraries are specified.
+ if (this->Makefile->IsAlias(args[0]))
+ {
+ this->SetError("can not be used on an ALIAS target.");
+ return false;
+ }
+ this->Target =
+ this->Makefile->GetCMakeInstance()
+ ->GetGlobalGenerator()->FindTarget(args[0]);
+ if(!this->Target)
+ {
+ this->Target = this->Makefile->FindTargetToUse(args[0]);
+ }
+ if(!this->Target)
+ {
+ 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))
+ {
+ this->SetError("called with non-compilable target type");
+ return false;
+ }
+
+ bool system = false;
+ unsigned int argIndex = 1;
+
+ if ((flags & PROCESS_SYSTEM) && args[argIndex] == "SYSTEM")
+ {
+ if (args.size() < 3)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ system = true;
+ ++argIndex;
+ }
+
+ bool prepend = false;
+ if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE")
+ {
+ if (args.size() < 3)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ prepend = true;
+ ++argIndex;
+ }
+
+ this->Property = prop;
+
+ while (argIndex < args.size())
+ {
+ if (!this->ProcessContentArgs(args, argIndex, prepend, system))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmTargetPropCommandBase
+::ProcessContentArgs(std::vector<std::string> const& args,
+ unsigned int &argIndex, bool prepend, bool system)
+{
+ const std::string scope = args[argIndex];
+
+ if(scope != "PUBLIC"
+ && scope != "PRIVATE"
+ && scope != "INTERFACE" )
+ {
+ this->SetError("called with invalid arguments");
+ return false;
+ }
+
+ if(this->Target->IsImported())
+ {
+ this->HandleImportedTarget(args[0]);
+ return false;
+ }
+
+ if (this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
+ && scope != "INTERFACE")
+ {
+ this->SetError("may only be set INTERFACE properties on INTERFACE "
+ "targets");
+ return false;
+ }
+
+ ++argIndex;
+
+ std::vector<std::string> content;
+
+ for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
+ {
+ if(args[i] == "PUBLIC"
+ || args[i] == "PRIVATE"
+ || args[i] == "INTERFACE" )
+ {
+ return this->PopulateTargetProperies(scope, content, prepend, system);
+ }
+ content.push_back(args[i]);
+ }
+ return this->PopulateTargetProperies(scope, content, prepend, system);
+}
+
+//----------------------------------------------------------------------------
+bool cmTargetPropCommandBase
+::PopulateTargetProperies(const std::string &scope,
+ const std::vector<std::string> &content,
+ bool prepend, bool system)
+{
+ if (scope == "PRIVATE" || scope == "PUBLIC")
+ {
+ if (!this->HandleDirectContent(this->Target, content, prepend, system))
+ {
+ return false;
+ }
+ }
+ if (scope == "INTERFACE" || scope == "PUBLIC")
+ {
+ this->HandleInterfaceContent(this->Target, content, prepend, system);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmTargetPropCommandBase::HandleInterfaceContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool)
+{
+ if (prepend)
+ {
+ const std::string propName = std::string("INTERFACE_") + this->Property;
+ const char *propValue = tgt->GetProperty(propName);
+ const std::string totalContent = this->Join(content) + (propValue
+ ? std::string(";") + propValue
+ : std::string());
+ tgt->SetProperty(propName, totalContent.c_str());
+ }
+ else
+ {
+ tgt->AppendProperty("INTERFACE_" + this->Property,
+ this->Join(content).c_str());
+ }
+}
diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h
new file mode 100644
index 0000000000..d42b588c97
--- /dev/null
+++ b/Source/cmTargetPropCommandBase.h
@@ -0,0 +1,60 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2013 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmTargetPropCommandBase_h
+#define cmTargetPropCommandBase_h
+
+#include "cmCommand.h"
+
+class cmTarget;
+
+//----------------------------------------------------------------------------
+class cmTargetPropCommandBase : public cmCommand
+{
+public:
+
+ enum ArgumentFlags {
+ NO_FLAGS = 0,
+ PROCESS_BEFORE = 1,
+ PROCESS_SYSTEM = 2
+ };
+
+ bool HandleArguments(std::vector<std::string> const& args,
+ const std::string& prop,
+ ArgumentFlags flags = NO_FLAGS);
+
+ cmTypeMacro(cmTargetPropCommandBase, cmCommand);
+protected:
+ std::string Property;
+ cmTarget *Target;
+
+ virtual void HandleInterfaceContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system);
+private:
+ virtual void HandleImportedTarget(const std::string &tgt) = 0;
+ virtual void HandleMissingTarget(const std::string &name) = 0;
+
+ virtual bool HandleDirectContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system) = 0;
+
+ virtual std::string Join(const std::vector<std::string> &content) = 0;
+
+ bool ProcessContentArgs(std::vector<std::string> const& args,
+ unsigned int &argIndex, bool prepend, bool system);
+ bool PopulateTargetProperies(const std::string &scope,
+ const std::vector<std::string> &content,
+ bool prepend, bool system);
+};
+
+#endif
diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx
new file mode 100644
index 0000000000..ce3b11e835
--- /dev/null
+++ b/Source/cmTargetSourcesCommand.cxx
@@ -0,0 +1,65 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 Stephen Kelly <steveire@gmail.com>
+
+ 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 "cmTargetSourcesCommand.h"
+
+#include "cmGeneratorExpression.h"
+
+//----------------------------------------------------------------------------
+bool cmTargetSourcesCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ return this->HandleArguments(args, "SOURCES");
+}
+
+//----------------------------------------------------------------------------
+void cmTargetSourcesCommand
+::HandleImportedTarget(const std::string &tgt)
+{
+ cmOStringStream e;
+ e << "Cannot specify sources for imported target \""
+ << tgt << "\".";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+//----------------------------------------------------------------------------
+void cmTargetSourcesCommand
+::HandleMissingTarget(const std::string &name)
+{
+ cmOStringStream e;
+ e << "Cannot specify sources for target \"" << name << "\" "
+ "which is not built by this project.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+}
+
+//----------------------------------------------------------------------------
+std::string cmTargetSourcesCommand
+::Join(const std::vector<std::string> &content)
+{
+ std::string srcs;
+ std::string sep;
+ for(std::vector<std::string>::const_iterator it = content.begin();
+ it != content.end(); ++it)
+ {
+ srcs += sep + *it;
+ sep = ";";
+ }
+ return srcs;
+}
+
+//----------------------------------------------------------------------------
+bool cmTargetSourcesCommand
+::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
+ bool, bool)
+{
+ tgt->AppendProperty("SOURCES", this->Join(content).c_str());
+ return true;
+}
diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h
new file mode 100644
index 0000000000..a170e3637a
--- /dev/null
+++ b/Source/cmTargetSourcesCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 Stephen Kelly <steveire@gmail.com>
+
+ 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 cmTargetSourcesCommand_h
+#define cmTargetSourcesCommand_h
+
+#include "cmTargetPropCommandBase.h"
+
+//----------------------------------------------------------------------------
+class cmTargetSourcesCommand : public cmTargetPropCommandBase
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmTargetSourcesCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "target_sources";}
+
+ cmTypeMacro(cmTargetSourcesCommand, cmTargetPropCommandBase);
+
+private:
+ virtual void HandleImportedTarget(const std::string &tgt);
+ virtual void HandleMissingTarget(const std::string &name);
+
+ virtual bool HandleDirectContent(cmTarget *tgt,
+ const std::vector<std::string> &content,
+ bool prepend, bool system);
+
+ virtual std::string Join(const std::vector<std::string> &content);
+};
+
+#endif
diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx
new file mode 100644
index 0000000000..ff5d4119e3
--- /dev/null
+++ b/Source/cmTest.cxx
@@ -0,0 +1,80 @@
+/*============================================================================
+ 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 "cmTest.h"
+#include "cmSystemTools.h"
+
+#include "cmake.h"
+#include "cmMakefile.h"
+
+//----------------------------------------------------------------------------
+cmTest::cmTest(cmMakefile* mf)
+ : Backtrace(mf->GetBacktrace())
+{
+ this->Makefile = mf;
+ this->OldStyle = true;
+ this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
+}
+
+//----------------------------------------------------------------------------
+cmTest::~cmTest()
+{
+}
+
+//----------------------------------------------------------------------------
+cmListFileBacktrace const& cmTest::GetBacktrace() const
+{
+ return this->Backtrace;
+}
+
+//----------------------------------------------------------------------------
+void cmTest::SetName(const std::string& name)
+{
+ this->Name = name;
+}
+
+//----------------------------------------------------------------------------
+void cmTest::SetCommand(std::vector<std::string> const& command)
+{
+ this->Command = command;
+}
+
+//----------------------------------------------------------------------------
+const char *cmTest::GetProperty(const std::string& prop) const
+{
+ bool chain = false;
+ const char *retVal =
+ this->Properties.GetPropertyValue(prop, cmProperty::TEST, chain);
+ if (chain)
+ {
+ return this->Makefile->GetProperty(prop,cmProperty::TEST);
+ }
+ return retVal;
+}
+
+//----------------------------------------------------------------------------
+bool cmTest::GetPropertyAsBool(const std::string& prop) const
+{
+ return cmSystemTools::IsOn(this->GetProperty(prop));
+}
+
+//----------------------------------------------------------------------------
+void cmTest::SetProperty(const std::string& prop, const char* value)
+{
+ this->Properties.SetProperty(prop, value, cmProperty::TEST);
+}
+
+//----------------------------------------------------------------------------
+void cmTest::AppendProperty(const std::string& prop,
+ const char* value, bool asString)
+{
+ this->Properties.AppendProperty(prop, value, cmProperty::TEST, asString);
+}
diff --git a/Source/cmTest.h b/Source/cmTest.h
new file mode 100644
index 0000000000..c6e7e42e89
--- /dev/null
+++ b/Source/cmTest.h
@@ -0,0 +1,78 @@
+/*============================================================================
+ 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 cmTest_h
+#define cmTest_h
+
+#include "cmCustomCommand.h"
+#include "cmPropertyMap.h"
+#include "cmListFileCache.h"
+class cmMakefile;
+
+/** \class cmTest
+ * \brief Represent a test
+ *
+ * cmTest is representation of a test.
+ */
+class cmTest
+{
+public:
+ /**
+ */
+ cmTest(cmMakefile* mf);
+ ~cmTest();
+
+ ///! Set the test name
+ void SetName(const std::string& name);
+ std::string GetName() const { return this->Name; }
+
+ void SetCommand(std::vector<std::string> const& command);
+ std::vector<std::string> const& GetCommand() const
+ {
+ return this->Command;
+ }
+
+ /**
+ * Print the structure to std::cout.
+ */
+ void Print() const;
+
+ ///! Set/Get a property of this source file
+ void SetProperty(const std::string& prop, const char *value);
+ void AppendProperty(const std::string& prop,
+ const char* value,bool asString=false);
+ const char *GetProperty(const std::string& prop) const;
+ bool GetPropertyAsBool(const std::string& prop) const;
+ cmPropertyMap &GetProperties() { return this->Properties; }
+
+ /** Get the cmMakefile instance that owns this test. */
+ cmMakefile *GetMakefile() { return this->Makefile;}
+
+ /** Get the backtrace of the command that created this test. */
+ cmListFileBacktrace const& GetBacktrace() const;
+
+ /** Get/Set whether this is an old-style test. */
+ bool GetOldStyle() const { return this->OldStyle; }
+ void SetOldStyle(bool b) { this->OldStyle = b; }
+
+private:
+ cmPropertyMap Properties;
+ std::string Name;
+ std::vector<std::string> Command;
+
+ bool OldStyle;
+
+ cmMakefile* Makefile;
+ cmListFileBacktrace Backtrace;
+};
+
+#endif
+
diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx
new file mode 100644
index 0000000000..f87a5353f0
--- /dev/null
+++ b/Source/cmTestGenerator.cxx
@@ -0,0 +1,196 @@
+/*============================================================================
+ 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 "cmTestGenerator.h"
+
+#include "cmGeneratorExpression.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include "cmTarget.h"
+#include "cmTest.h"
+
+//----------------------------------------------------------------------------
+cmTestGenerator
+::cmTestGenerator(cmTest* test,
+ std::vector<std::string> const& configurations):
+ cmScriptGenerator("CTEST_CONFIGURATION_TYPE", configurations),
+ Test(test)
+{
+ this->ActionsPerConfig = !test->GetOldStyle();
+ this->TestGenerated = false;
+}
+
+//----------------------------------------------------------------------------
+cmTestGenerator
+::~cmTestGenerator()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmTestGenerator::GenerateScriptConfigs(std::ostream& os,
+ Indent const& indent)
+{
+ // Create the tests.
+ this->cmScriptGenerator::GenerateScriptConfigs(os, indent);
+}
+
+//----------------------------------------------------------------------------
+void cmTestGenerator::GenerateScriptActions(std::ostream& os,
+ Indent const& indent)
+{
+ if(this->ActionsPerConfig)
+ {
+ // This is the per-config generation in a single-configuration
+ // build generator case. The superclass will call our per-config
+ // method.
+ this->cmScriptGenerator::GenerateScriptActions(os, indent);
+ }
+ else
+ {
+ // This is an old-style test, so there is only one config.
+ //assert(this->Test->GetOldStyle());
+ this->GenerateOldStyle(os, indent);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
+ const std::string& config,
+ Indent const& indent)
+{
+ this->TestGenerated = true;
+
+ // Set up generator expression evaluation context.
+ cmGeneratorExpression ge(&this->Test->GetBacktrace());
+
+ // Start the test command.
+ os << indent << "add_test(" << this->Test->GetName() << " ";
+
+ // Get the test command line to be executed.
+ std::vector<std::string> const& command = this->Test->GetCommand();
+
+ // Check whether the command executable is a target whose name is to
+ // be translated.
+ std::string exe = command[0];
+ cmMakefile* mf = this->Test->GetMakefile();
+ cmTarget* target = mf->FindTargetToUse(exe);
+ if(target && target->GetType() == cmTarget::EXECUTABLE)
+ {
+ // Use the target file on disk.
+ exe = target->GetFullPath(config);
+ }
+ else
+ {
+ // Use the command name given.
+ exe = ge.Parse(exe.c_str())->Evaluate(mf, config);
+ cmSystemTools::ConvertToUnixSlashes(exe);
+ }
+
+ // Generate the command line with full escapes.
+ cmLocalGenerator* lg = mf->GetLocalGenerator();
+ os << lg->EscapeForCMake(exe);
+ for(std::vector<std::string>::const_iterator ci = command.begin()+1;
+ ci != command.end(); ++ci)
+ {
+ os << " " << lg->EscapeForCMake(ge.Parse(*ci)->Evaluate(mf, config));
+ }
+
+ // Finish the test command.
+ os << ")\n";
+
+ // Output properties for the test.
+ cmPropertyMap& pm = this->Test->GetProperties();
+ if(!pm.empty())
+ {
+ os << indent << "set_tests_properties(" << this->Test->GetName()
+ << " PROPERTIES ";
+ for(cmPropertyMap::const_iterator i = pm.begin();
+ i != pm.end(); ++i)
+ {
+ os << " " << i->first
+ << " " << lg->EscapeForCMake(
+ ge.Parse(i->second.GetValue())->Evaluate(mf, config));
+ }
+ os << ")" << std::endl;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmTestGenerator::GenerateScriptNoConfig(std::ostream& os,
+ Indent const& indent)
+{
+ os << indent << "add_test(" << this->Test->GetName() << " NOT_AVAILABLE)\n";
+}
+
+//----------------------------------------------------------------------------
+bool cmTestGenerator::NeedsScriptNoConfig() const
+{
+ return (this->TestGenerated && // test generated for at least one config
+ this->ActionsPerConfig && // test is config-aware
+ this->Configurations.empty() && // test runs in all configs
+ !this->ConfigurationTypes->empty()); // config-dependent command
+}
+
+//----------------------------------------------------------------------------
+void cmTestGenerator::GenerateOldStyle(std::ostream& fout,
+ Indent const& indent)
+{
+ this->TestGenerated = true;
+
+ // Get the test command line to be executed.
+ std::vector<std::string> const& command = this->Test->GetCommand();
+
+ std::string exe = command[0];
+ cmSystemTools::ConvertToUnixSlashes(exe);
+ fout << indent;
+ fout << "add_test(";
+ fout << this->Test->GetName() << " \"" << exe << "\"";
+
+ for(std::vector<std::string>::const_iterator argit = command.begin()+1;
+ argit != command.end(); ++argit)
+ {
+ // Just double-quote all arguments so they are re-parsed
+ // correctly by the test system.
+ fout << " \"";
+ for(std::string::const_iterator c = argit->begin();
+ c != argit->end(); ++c)
+ {
+ // Escape quotes within arguments. We should escape
+ // backslashes too but we cannot because it makes the result
+ // inconsistent with previous behavior of this command.
+ if((*c == '"'))
+ {
+ fout << '\\';
+ }
+ fout << *c;
+ }
+ fout << "\"";
+ }
+ fout << ")" << std::endl;
+
+ // Output properties for the test.
+ cmMakefile* mf = this->Test->GetMakefile();
+ cmLocalGenerator* lg = mf->GetLocalGenerator();
+ cmPropertyMap& pm = this->Test->GetProperties();
+ if(!pm.empty())
+ {
+ fout << indent << "set_tests_properties(" << this->Test->GetName()
+ << " PROPERTIES ";
+ for(cmPropertyMap::const_iterator i = pm.begin();
+ i != pm.end(); ++i)
+ {
+ fout << " " << i->first
+ << " " << lg->EscapeForCMake(i->second.GetValue());
+ }
+ fout << ")" << std::endl;
+ }
+}
diff --git a/Source/cmTestGenerator.h b/Source/cmTestGenerator.h
new file mode 100644
index 0000000000..5446553cf4
--- /dev/null
+++ b/Source/cmTestGenerator.h
@@ -0,0 +1,45 @@
+/*============================================================================
+ 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 cmTestGenerator_h
+#define cmTestGenerator_h
+
+#include "cmScriptGenerator.h"
+
+class cmTest;
+
+/** \class cmTestGenerator
+ * \brief Support class for generating install scripts.
+ *
+ */
+class cmTestGenerator: public cmScriptGenerator
+{
+public:
+ cmTestGenerator(cmTest* test,
+ std::vector<std::string> const&
+ configurations = std::vector<std::string>());
+ virtual ~cmTestGenerator();
+
+protected:
+ virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
+ virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
+ virtual void GenerateScriptForConfig(std::ostream& os,
+ const std::string& config,
+ Indent const& indent);
+ virtual void GenerateScriptNoConfig(std::ostream& os, Indent const& indent);
+ virtual bool NeedsScriptNoConfig() const;
+ void GenerateOldStyle(std::ostream& os, Indent const& indent);
+
+ cmTest* Test;
+ bool TestGenerated;
+};
+
+#endif
diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx
new file mode 100644
index 0000000000..6fd6ab7b47
--- /dev/null
+++ b/Source/cmTimestamp.cxx
@@ -0,0 +1,132 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 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 "cmTimestamp.h"
+
+#include <cstring>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+//----------------------------------------------------------------------------
+std::string cmTimestamp::CurrentTime(
+ const std::string& formatString, bool utcFlag)
+{
+ time_t currentTimeT = time(0);
+ if(currentTimeT == time_t(-1))
+ {
+ return std::string();
+ }
+
+ return CreateTimestampFromTimeT(currentTimeT, formatString, utcFlag);
+}
+
+//----------------------------------------------------------------------------
+std::string cmTimestamp::FileModificationTime(const char* path,
+ const std::string& formatString, bool utcFlag)
+{
+ if(!cmsys::SystemTools::FileExists(path))
+ {
+ return std::string();
+ }
+
+ time_t mtime = cmsys::SystemTools::ModifiedTime(path);
+ return CreateTimestampFromTimeT(mtime, formatString, utcFlag);
+}
+
+//----------------------------------------------------------------------------
+std::string cmTimestamp::CreateTimestampFromTimeT(time_t timeT,
+ std::string formatString, bool utcFlag)
+{
+ if(formatString.empty())
+ {
+ formatString = "%Y-%m-%dT%H:%M:%S";
+ if(utcFlag)
+ {
+ formatString += "Z";
+ }
+ }
+
+ struct tm timeStruct;
+ memset(&timeStruct, 0, sizeof(timeStruct));
+
+ struct tm* ptr = (struct tm*) 0;
+ if(utcFlag)
+ {
+ ptr = gmtime(&timeT);
+ }
+ else
+ {
+ ptr = localtime(&timeT);
+ }
+
+ if(ptr == 0)
+ {
+ return std::string();
+ }
+
+ timeStruct = *ptr;
+
+ std::string result;
+ for(std::string::size_type i = 0; i < formatString.size(); ++i)
+ {
+ char c1 = formatString[i];
+ char c2 = (i+1 < formatString.size()) ?
+ formatString[i+1] : static_cast<char>(0);
+
+ if(c1 == '%' && c2 != 0)
+ {
+ result += AddTimestampComponent(c2, timeStruct);
+ ++i;
+ }
+ else
+ {
+ result += c1;
+ }
+ }
+
+ return result;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTimestamp::AddTimestampComponent(
+ char flag, struct tm& timeStruct)
+{
+ std::string formatString = "%";
+ formatString += flag;
+
+ switch(flag)
+ {
+ case 'd':
+ case 'H':
+ case 'I':
+ case 'j':
+ case 'm':
+ case 'M':
+ case 'S':
+ case 'U':
+ case 'w':
+ case 'y':
+ case 'Y':
+ break;
+ default:
+ {
+ return formatString;
+ }
+ }
+
+ char buffer[16];
+
+ size_t size = strftime(buffer, sizeof(buffer),
+ formatString.c_str(), &timeStruct);
+
+ return std::string(buffer, size);
+}
diff --git a/Source/cmTimestamp.h b/Source/cmTimestamp.h
new file mode 100644
index 0000000000..24c186983a
--- /dev/null
+++ b/Source/cmTimestamp.h
@@ -0,0 +1,40 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2012 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 cmTimestamp_h
+#define cmTimestamp_h
+
+#include <string>
+#include <time.h>
+
+/** \class cmTimestamp
+ * \brief Utility class to generate sting representation of a timestamp
+ *
+ */
+class cmTimestamp
+{
+public:
+ cmTimestamp() {}
+
+ std::string CurrentTime(const std::string& formatString, bool utcFlag);
+
+ std::string FileModificationTime(const char* path,
+ const std::string& formatString, bool utcFlag);
+
+private:
+ std::string CreateTimestampFromTimeT(time_t timeT,
+ std::string formatString, bool utcFlag);
+
+ std::string AddTimestampComponent(char flag, struct tm& timeStruct);
+};
+
+
+#endif
diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx
new file mode 100644
index 0000000000..12ce015d2c
--- /dev/null
+++ b/Source/cmTryCompileCommand.cxx
@@ -0,0 +1,42 @@
+/*============================================================================
+ 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 "cmTryCompileCommand.h"
+
+// cmTryCompileCommand
+bool cmTryCompileCommand
+::InitialPass(std::vector<std::string> const& argv, cmExecutionStatus &)
+{
+ if(argv.size() < 3)
+ {
+ return false;
+ }
+
+ if(this->Makefile->GetCMakeInstance()->GetWorkingMode() ==
+ cmake::FIND_PACKAGE_MODE)
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "The TRY_COMPILE() command is not supported in --find-package mode.");
+ return false;
+ }
+
+ this->TryCompileCode(argv);
+
+ // if They specified clean then we clean up what we can
+ if (this->SrcFileSignature)
+ {
+ if(!this->Makefile->GetCMakeInstance()->GetDebugTryCompile())
+ {
+ this->CleanupFiles(this->BinaryDirectory.c_str());
+ }
+ }
+ return true;
+}
diff --git a/Source/cmTryCompileCommand.h b/Source/cmTryCompileCommand.h
new file mode 100644
index 0000000000..a09c47ff38
--- /dev/null
+++ b/Source/cmTryCompileCommand.h
@@ -0,0 +1,50 @@
+/*============================================================================
+ 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 cmTryCompileCommand_h
+#define cmTryCompileCommand_h
+
+#include "cmCoreTryCompile.h"
+
+/** \class cmTryCompileCommand
+ * \brief Specifies where to install some files
+ *
+ * cmTryCompileCommand is used to test if soucre code can be compiled
+ */
+class cmTryCompileCommand : public cmCoreTryCompile
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmTryCompileCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "try_compile";}
+
+ cmTypeMacro(cmTryCompileCommand, cmCoreTryCompile);
+
+};
+
+
+#endif
diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx
new file mode 100644
index 0000000000..cc6e139ca3
--- /dev/null
+++ b/Source/cmTryRunCommand.cxx
@@ -0,0 +1,388 @@
+/*============================================================================
+ 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 "cmTryRunCommand.h"
+#include "cmCacheManager.h"
+#include "cmTryCompileCommand.h"
+#include <cmsys/FStream.hxx>
+
+// cmTryRunCommand
+bool cmTryRunCommand
+::InitialPass(std::vector<std::string> const& argv, cmExecutionStatus &)
+{
+ if(argv.size() < 4)
+ {
+ return false;
+ }
+
+ if(this->Makefile->GetCMakeInstance()->GetWorkingMode() ==
+ cmake::FIND_PACKAGE_MODE)
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "The TRY_RUN() command is not supported in --find-package mode.");
+ return false;
+ }
+
+ // build an arg list for TryCompile and extract the runArgs,
+ std::vector<std::string> tryCompile;
+
+ this->CompileResultVariable = "";
+ this->RunResultVariable = "";
+ this->OutputVariable = "";
+ this->RunOutputVariable = "";
+ this->CompileOutputVariable = "";
+
+ std::string runArgs;
+ unsigned int i;
+ for (i = 1; i < argv.size(); ++i)
+ {
+ if (argv[i] == "ARGS")
+ {
+ ++i;
+ while (i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" &&
+ argv[i] != "CMAKE_FLAGS")
+ {
+ runArgs += " ";
+ runArgs += argv[i];
+ ++i;
+ }
+ if (i < argv.size())
+ {
+ tryCompile.push_back(argv[i]);
+ }
+ }
+ else
+ {
+ if (argv[i] == "OUTPUT_VARIABLE")
+ {
+ if ( argv.size() <= (i+1) )
+ {
+ cmSystemTools::Error(
+ "OUTPUT_VARIABLE specified but there is no variable");
+ return false;
+ }
+ i++;
+ this->OutputVariable = argv[i];
+ }
+ else if (argv[i] == "RUN_OUTPUT_VARIABLE")
+ {
+ if (argv.size() <= (i + 1))
+ {
+ cmSystemTools::Error(
+ "RUN_OUTPUT_VARIABLE specified but there is no variable");
+ return false;
+ }
+ i++;
+ this->RunOutputVariable = argv[i];
+ }
+ else if (argv[i] == "COMPILE_OUTPUT_VARIABLE")
+ {
+ if (argv.size() <= (i + 1))
+ {
+ cmSystemTools::Error(
+ "COMPILE_OUTPUT_VARIABLE specified but there is no variable");
+ return false;
+ }
+ i++;
+ this->CompileOutputVariable = argv[i];
+ }
+ else
+ {
+ tryCompile.push_back(argv[i]);
+ }
+ }
+ }
+
+ // although they could be used together, don't allow it, because
+ // using OUTPUT_VARIABLE makes crosscompiling harder
+ if (this->OutputVariable.size()
+ && ((this->RunOutputVariable.size())
+ || (this->CompileOutputVariable.size())))
+ {
+ cmSystemTools::Error(
+ "You cannot use OUTPUT_VARIABLE together with COMPILE_OUTPUT_VARIABLE "
+ "or RUN_OUTPUT_VARIABLE. Please use only COMPILE_OUTPUT_VARIABLE and/or "
+ "RUN_OUTPUT_VARIABLE.");
+ return false;
+ }
+
+ bool captureRunOutput = false;
+ if (this->OutputVariable.size())
+ {
+ captureRunOutput = true;
+ tryCompile.push_back("OUTPUT_VARIABLE");
+ tryCompile.push_back(this->OutputVariable);
+ }
+ if (this->CompileOutputVariable.size())
+ {
+ tryCompile.push_back("OUTPUT_VARIABLE");
+ tryCompile.push_back(this->CompileOutputVariable);
+ }
+ if (this->RunOutputVariable.size())
+ {
+ captureRunOutput = true;
+ }
+
+ this->RunResultVariable = argv[0];
+ this->CompileResultVariable = argv[1];
+
+ // do the try compile
+ int res = this->TryCompileCode(tryCompile);
+
+ // now try running the command if it compiled
+ if (!res)
+ {
+ if (this->OutputFile.size() == 0)
+ {
+ cmSystemTools::Error(this->FindErrorMessage.c_str());
+ }
+ else
+ {
+ // "run" it and capture the output
+ std::string runOutputContents;
+ if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING"))
+ {
+ this->DoNotRunExecutable(runArgs,
+ argv[3],
+ captureRunOutput ? &runOutputContents : 0);
+ }
+ else
+ {
+ this->RunExecutable(runArgs, &runOutputContents);
+ }
+
+ // now put the output into the variables
+ if(this->RunOutputVariable.size())
+ {
+ this->Makefile->AddDefinition(this->RunOutputVariable,
+ runOutputContents.c_str());
+ }
+
+ if(this->OutputVariable.size())
+ {
+ // if the TryCompileCore saved output in this outputVariable then
+ // prepend that output to this output
+ const char* compileOutput
+ = this->Makefile->GetDefinition(this->OutputVariable);
+ if (compileOutput)
+ {
+ runOutputContents = std::string(compileOutput) + runOutputContents;
+ }
+ this->Makefile->AddDefinition(this->OutputVariable,
+ runOutputContents.c_str());
+ }
+ }
+ }
+
+ // if we created a directory etc, then cleanup after ourselves
+ if(!this->Makefile->GetCMakeInstance()->GetDebugTryCompile())
+ {
+ this->CleanupFiles(this->BinaryDirectory.c_str());
+ }
+ return true;
+}
+
+void cmTryRunCommand::RunExecutable(const std::string& runArgs,
+ std::string* out)
+{
+ int retVal = -1;
+ std::string finalCommand = cmSystemTools::ConvertToRunCommandPath(
+ this->OutputFile.c_str());
+ if (runArgs.size())
+ {
+ finalCommand += runArgs;
+ }
+ int timeout = 0;
+ bool worked = cmSystemTools::RunSingleCommand(finalCommand.c_str(),
+ out, &retVal,
+ 0, cmSystemTools::OUTPUT_NONE, timeout);
+ // set the run var
+ char retChar[1000];
+ if (worked)
+ {
+ sprintf(retChar, "%i", retVal);
+ }
+ else
+ {
+ strcpy(retChar, "FAILED_TO_RUN");
+ }
+ this->Makefile->AddCacheDefinition(this->RunResultVariable, retChar,
+ "Result of TRY_RUN",
+ cmCacheManager::INTERNAL);
+}
+
+/* This is only used when cross compiling. Instead of running the
+ executable, two cache variables are created which will hold the results
+ the executable would have produced.
+*/
+void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
+ const std::string& srcFile,
+ std::string* out
+ )
+{
+ // copy the executable out of the CMakeFiles/ directory, so it is not
+ // removed at the end of TRY_RUN and the user can run it manually
+ // on the target platform.
+ std::string copyDest = this->Makefile->GetHomeOutputDirectory();
+ copyDest += cmake::GetCMakeFilesDirectory();
+ copyDest += "/";
+ copyDest += cmSystemTools::GetFilenameWithoutExtension(
+ this->OutputFile);
+ copyDest += "-";
+ copyDest += this->RunResultVariable;
+ copyDest += cmSystemTools::GetFilenameExtension(this->OutputFile);
+ cmSystemTools::CopyFileAlways(this->OutputFile.c_str(), copyDest.c_str());
+
+ std::string resultFileName = this->Makefile->GetHomeOutputDirectory();
+ resultFileName += "/TryRunResults.cmake";
+
+ std::string detailsString = "For details see ";
+ detailsString += resultFileName;
+
+ std::string internalRunOutputName=this->RunResultVariable+"__TRYRUN_OUTPUT";
+ bool error = false;
+
+ if (this->Makefile->GetDefinition(this->RunResultVariable) == 0)
+ {
+ // if the variables doesn't exist, create it with a helpful error text
+ // and mark it as advanced
+ std::string comment;
+ comment += "Run result of TRY_RUN(), indicates whether the executable "
+ "would have been able to run on its target platform.\n";
+ comment += detailsString;
+ this->Makefile->AddCacheDefinition(this->RunResultVariable,
+ "PLEASE_FILL_OUT-FAILED_TO_RUN",
+ comment.c_str(),
+ cmCacheManager::STRING);
+
+ cmCacheManager::CacheIterator it = this->Makefile->GetCacheManager()->
+ GetCacheIterator(this->RunResultVariable.c_str());
+ if ( !it.IsAtEnd() )
+ {
+ it.SetProperty("ADVANCED", "1");
+ }
+
+ error = true;
+ }
+
+ // is the output from the executable used ?
+ if (out!=0)
+ {
+ if (this->Makefile->GetDefinition(internalRunOutputName) == 0)
+ {
+ // if the variables doesn't exist, create it with a helpful error text
+ // and mark it as advanced
+ std::string comment;
+ comment+="Output of TRY_RUN(), contains the text, which the executable "
+ "would have printed on stdout and stderr on its target platform.\n";
+ comment += detailsString;
+
+ this->Makefile->AddCacheDefinition(internalRunOutputName,
+ "PLEASE_FILL_OUT-NOTFOUND",
+ comment.c_str(),
+ cmCacheManager::STRING);
+ cmCacheManager::CacheIterator it = this->Makefile->GetCacheManager()->
+ GetCacheIterator(internalRunOutputName.c_str());
+ if ( !it.IsAtEnd() )
+ {
+ it.SetProperty("ADVANCED", "1");
+ }
+
+ error = true;
+ }
+ }
+
+ if (error)
+ {
+ static bool firstTryRun = true;
+ cmsys::ofstream file(resultFileName.c_str(),
+ firstTryRun ? std::ios::out : std::ios::app);
+ if ( file )
+ {
+ if (firstTryRun)
+ {
+ file << "# This file was generated by CMake because it detected "
+ "TRY_RUN() commands\n"
+ "# in crosscompiling mode. It will be overwritten by the next "
+ "CMake run.\n"
+ "# Copy it to a safe location, set the variables to "
+ "appropriate values\n"
+ "# and use it then to preset the CMake cache (using -C).\n\n";
+ }
+
+ std::string comment ="\n";
+ comment += this->RunResultVariable;
+ comment += "\n indicates whether the executable would have been able "
+ "to run on its\n"
+ " target platform. If so, set ";
+ comment += this->RunResultVariable;
+ comment += " to\n"
+ " the exit code (in many cases 0 for success), otherwise "
+ "enter \"FAILED_TO_RUN\".\n";
+ if (out!=0)
+ {
+ comment += internalRunOutputName;
+ comment += "\n contains the text the executable "
+ "would have printed on stdout and stderr.\n"
+ " If the executable would not have been able to run, set ";
+ comment += internalRunOutputName;
+ comment += " empty.\n"
+ " Otherwise check if the output is evaluated by the "
+ "calling CMake code. If so,\n"
+ " check what the source file would have printed when "
+ "called with the given arguments.\n";
+ }
+ comment += "The ";
+ comment += this->CompileResultVariable;
+ comment += " variable holds the build result for this TRY_RUN().\n\n"
+ "Source file : ";
+ comment += srcFile + "\n";
+ comment += "Executable : ";
+ comment += copyDest + "\n";
+ comment += "Run arguments : ";
+ comment += runArgs;
+ comment += "\n";
+ comment += " Called from: " + this->Makefile->GetListFileStack();
+ cmsys::SystemTools::ReplaceString(comment, "\n", "\n# ");
+ file << comment << "\n\n";
+
+ file << "set( " << this->RunResultVariable << " \n \""
+ << this->Makefile->GetDefinition(this->RunResultVariable)
+ << "\"\n CACHE STRING \"Result from TRY_RUN\" FORCE)\n\n";
+
+ if (out!=0)
+ {
+ file << "set( " << internalRunOutputName << " \n \""
+ << this->Makefile->GetDefinition(internalRunOutputName)
+ << "\"\n CACHE STRING \"Output from TRY_RUN\" FORCE)\n\n";
+ }
+ file.close();
+ }
+ firstTryRun = false;
+
+ std::string errorMessage = "TRY_RUN() invoked in cross-compiling mode, "
+ "please set the following cache variables "
+ "appropriately:\n";
+ errorMessage += " " + this->RunResultVariable + " (advanced)\n";
+ if (out!=0)
+ {
+ errorMessage += " " + internalRunOutputName + " (advanced)\n";
+ }
+ errorMessage += detailsString;
+ cmSystemTools::Error(errorMessage.c_str());
+ return;
+ }
+
+ if (out!=0)
+ {
+ (*out) = this->Makefile->GetDefinition(internalRunOutputName);
+ }
+}
diff --git a/Source/cmTryRunCommand.h b/Source/cmTryRunCommand.h
new file mode 100644
index 0000000000..9b97b16a22
--- /dev/null
+++ b/Source/cmTryRunCommand.h
@@ -0,0 +1,61 @@
+/*============================================================================
+ 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 cmTryRunCommand_h
+#define cmTryRunCommand_h
+
+#include "cmCoreTryCompile.h"
+
+/** \class cmTryRunCommand
+ * \brief Specifies where to install some files
+ *
+ * cmTryRunCommand is used to test if soucre code can be compiled
+ */
+class cmTryRunCommand : public cmCoreTryCompile
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmTryRunCommand;
+ }
+
+ /**
+ * 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);
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "try_run";}
+
+ cmTypeMacro(cmTryRunCommand, cmCoreTryCompile);
+private:
+ void RunExecutable(const std::string& runArgs,
+ std::string* runOutputContents);
+ void DoNotRunExecutable(const std::string& runArgs,
+ const std::string& srcFile,
+ std::string* runOutputContents);
+
+ std::string CompileResultVariable;
+ std::string RunResultVariable;
+ std::string OutputVariable;
+ std::string RunOutputVariable;
+ std::string CompileOutputVariable;
+};
+
+
+#endif
diff --git a/Source/cmUnsetCommand.cxx b/Source/cmUnsetCommand.cxx
new file mode 100644
index 0000000000..053cdfc7d8
--- /dev/null
+++ b/Source/cmUnsetCommand.cxx
@@ -0,0 +1,65 @@
+/*============================================================================
+ 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 "cmUnsetCommand.h"
+
+// cmUnsetCommand
+bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &)
+{
+ if(args.size() < 1 || args.size() > 2)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ const char* variable = args[0].c_str();
+
+ // unset(ENV{VAR})
+ if (cmHasLiteralPrefix(variable, "ENV{") && strlen(variable) > 5)
+ {
+ // what is the variable name
+ char *envVarName = new char [strlen(variable)];
+ strncpy(envVarName,variable+4,strlen(variable)-5);
+ envVarName[strlen(variable)-5] = '\0';
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmSystemTools::UnsetEnv(envVarName);
+#endif
+ delete[] envVarName;
+ return true;
+ }
+ // unset(VAR)
+ else if (args.size() == 1)
+ {
+ this->Makefile->RemoveDefinition(variable);
+ return true;
+ }
+ // unset(VAR CACHE)
+ else if ((args.size() == 2) && (args[1] == "CACHE"))
+ {
+ this->Makefile->RemoveCacheDefinition(variable);
+ return true;
+ }
+ // unset(VAR PARENT_SCOPE)
+ else if ((args.size() == 2) && (args[1] == "PARENT_SCOPE"))
+ {
+ this->Makefile->RaiseScope(variable, 0);
+ return true;
+ }
+ // ERROR: second argument isn't CACHE or PARENT_SCOPE
+ else
+ {
+ this->SetError("called with an invalid second argument");
+ return false;
+ }
+}
+
diff --git a/Source/cmUnsetCommand.h b/Source/cmUnsetCommand.h
new file mode 100644
index 0000000000..62c2bd39be
--- /dev/null
+++ b/Source/cmUnsetCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ 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 cmUnsetCommand_h
+#define cmUnsetCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmUnsetCommand
+ * \brief Unset a CMAKE variable
+ *
+ * cmUnsetCommand unsets or removes a variable.
+ */
+class cmUnsetCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmUnsetCommand;
+ }
+
+ /**
+ * 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 "unset";}
+
+ cmTypeMacro(cmUnsetCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmUseMangledMesaCommand.cxx b/Source/cmUseMangledMesaCommand.cxx
new file mode 100644
index 0000000000..8d26f863a5
--- /dev/null
+++ b/Source/cmUseMangledMesaCommand.cxx
@@ -0,0 +1,134 @@
+/*============================================================================
+ 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 "cmUseMangledMesaCommand.h"
+#include "cmSystemTools.h"
+
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/FStream.hxx>
+
+bool cmUseMangledMesaCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(this->Disallowed(cmPolicies::CMP0030,
+ "The use_mangled_mesa command should not be called; see CMP0030."))
+ { return true; }
+ // expected two arguments:
+ // arguement one: the full path to gl_mangle.h
+ // arguement two : directory for output of edited headers
+ if(args.size() != 2)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ const char* inputDir = args[0].c_str();
+ std::string glh = inputDir;
+ glh += "/";
+ glh += "gl.h";
+ if(!cmSystemTools::FileExists(glh.c_str()))
+ {
+ std::string e = "Bad path to Mesa, could not find: ";
+ e += glh;
+ e += " ";
+ this->SetError(e);
+ return false;
+ }
+ const char* destDir = args[1].c_str();
+ std::vector<std::string> files;
+ cmSystemTools::Glob(inputDir, "\\.h$", files);
+ if(files.size() == 0)
+ {
+ cmSystemTools::Error("Could not open Mesa Directory ", inputDir);
+ return false;
+ }
+ cmSystemTools::MakeDirectory(destDir);
+ for(std::vector<std::string>::iterator i = files.begin();
+ i != files.end(); ++i)
+ {
+ std::string path = inputDir;
+ path += "/";
+ path += *i;
+ this->CopyAndFullPathMesaHeader(path.c_str(), destDir);
+ }
+
+ return true;
+}
+
+void
+cmUseMangledMesaCommand::
+CopyAndFullPathMesaHeader(const char* source,
+ const char* outdir)
+{
+ std::string dir, file;
+ cmSystemTools::SplitProgramPath(source, dir, file);
+ std::string outFile = outdir;
+ outFile += "/";
+ outFile += file;
+ std::string tempOutputFile = outFile;
+ tempOutputFile += ".tmp";
+ cmsys::ofstream fout(tempOutputFile.c_str());
+ if(!fout)
+ {
+ cmSystemTools::Error("Could not open file for write in copy operation: ",
+ tempOutputFile.c_str(), outdir);
+ cmSystemTools::ReportLastSystemError("");
+ return;
+ }
+ cmsys::ifstream fin(source);
+ if(!fin)
+ {
+ cmSystemTools::Error("Could not open file for read in copy operation",
+ source);
+ return;
+ }
+ // now copy input to output and expand variables in the
+ // input file at the same time
+ std::string inLine;
+ // regular expression for any #include line
+ cmsys::RegularExpression includeLine(
+ "^[ \t]*#[ \t]*include[ \t]*[<\"]([^\">]+)[\">]");
+ // regular expression for gl/ or GL/ in a file (match(1) of above)
+ cmsys::RegularExpression glDirLine("(gl|GL)(/|\\\\)([^<\"]+)");
+ // regular expression for gl GL or xmesa in a file (match(1) of above)
+ cmsys::RegularExpression glLine("(gl|GL|xmesa)");
+ while(cmSystemTools::GetLineFromStream(fin,inLine))
+ {
+ if(includeLine.find(inLine.c_str()))
+ {
+ std::string includeFile = includeLine.match(1);
+ if(glDirLine.find(includeFile.c_str()))
+ {
+ std::string gfile = glDirLine.match(3);
+ fout << "#include \"" << outdir << "/" << gfile << "\"\n";
+ }
+ else if(glLine.find(includeFile.c_str()))
+ {
+ fout << "#include \"" << outdir << "/" <<
+ includeLine.match(1) << "\"\n";
+ }
+ else
+ {
+ fout << inLine << "\n";
+ }
+ }
+ else
+ {
+ fout << inLine << "\n";
+ }
+ }
+ // close the files before attempting to copy
+ fin.close();
+ fout.close();
+ cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
+ outFile.c_str());
+ cmSystemTools::RemoveFile(tempOutputFile.c_str());
+}
+
diff --git a/Source/cmUseMangledMesaCommand.h b/Source/cmUseMangledMesaCommand.h
new file mode 100644
index 0000000000..da927c72b3
--- /dev/null
+++ b/Source/cmUseMangledMesaCommand.h
@@ -0,0 +1,32 @@
+/*============================================================================
+ 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 cmUseMangledMesaCommand_h
+#define cmUseMangledMesaCommand_h
+
+#include "cmCommand.h"
+
+class cmUseMangledMesaCommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmUseMangledMesaCommand, cmCommand);
+ virtual cmCommand* Clone() { return new cmUseMangledMesaCommand; }
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+ virtual std::string GetName() const { return "use_mangled_mesa";}
+ virtual bool IsScriptable() const { return true; }
+ virtual bool IsDiscouraged() const { return true; }
+protected:
+ void CopyAndFullPathMesaHeader(const char* source,
+ const char* outdir);
+};
+
+#endif
diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx
new file mode 100644
index 0000000000..ba6b4acfaa
--- /dev/null
+++ b/Source/cmUtilitySourceCommand.cxx
@@ -0,0 +1,130 @@
+/*============================================================================
+ 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 "cmUtilitySourceCommand.h"
+
+// cmUtilitySourceCommand
+bool cmUtilitySourceCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(this->Disallowed(cmPolicies::CMP0034,
+ "The utility_source command should not be called; see CMP0034."))
+ { return true; }
+ if(args.size() < 3)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::vector<std::string>::const_iterator arg = args.begin();
+
+ // The first argument is the cache entry name.
+ std::string cacheEntry = *arg++;
+ const char* cacheValue =
+ this->Makefile->GetDefinition(cacheEntry);
+ // If it exists already and appears up to date then we are done. If
+ // the string contains "(IntDir)" but that is not the
+ // CMAKE_CFG_INTDIR setting then the value is out of date.
+ const char* intDir =
+ this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
+
+ bool haveCacheValue = false;
+ if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING"))
+ {
+ haveCacheValue = (cacheValue != 0);
+ if (!haveCacheValue)
+ {
+ std::string msg = "UTILITY_SOURCE is used in cross compiling mode for ";
+ msg += cacheEntry;
+ msg += ". If your intention is to run this executable, you need to "
+ "preload the cache with the full path to a version of that "
+ "program, which runs on this build machine.";
+ cmSystemTools::Message(msg.c_str() ,"Warning");
+ }
+ }
+ else
+ {
+ haveCacheValue = (cacheValue &&
+ (strstr(cacheValue, "(IntDir)") == 0 ||
+ (intDir && strcmp(intDir, "$(IntDir)") == 0)) &&
+ (this->Makefile->GetCacheMajorVersion() != 0 &&
+ this->Makefile->GetCacheMinorVersion() != 0 ));
+ }
+
+ if(haveCacheValue)
+ {
+ return true;
+ }
+
+ // The second argument is the utility's executable name, which will be
+ // needed later.
+ std::string utilityName = *arg++;
+
+ // The third argument specifies the relative directory of the source
+ // of the utility.
+ std::string relativeSource = *arg++;
+ std::string utilitySource = this->Makefile->GetCurrentDirectory();
+ utilitySource = utilitySource+"/"+relativeSource;
+
+ // If the directory doesn't exist, the source has not been included.
+ if(!cmSystemTools::FileExists(utilitySource.c_str()))
+ { return true; }
+
+ // Make sure all the files exist in the source directory.
+ while(arg != args.end())
+ {
+ std::string file = utilitySource+"/"+*arg++;
+ if(!cmSystemTools::FileExists(file.c_str()))
+ { return true; }
+ }
+
+ // The source exists.
+ std::string cmakeCFGout =
+ this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
+ std::string utilityDirectory = this->Makefile->GetCurrentOutputDirectory();
+ std::string exePath;
+ if (this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
+ {
+ exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
+ }
+ if(exePath.size())
+ {
+ utilityDirectory = exePath;
+ }
+ else
+ {
+ utilityDirectory += "/"+relativeSource;
+ }
+
+ // Construct the cache entry for the executable's location.
+ std::string utilityExecutable =
+ utilityDirectory+"/"+cmakeCFGout+"/"
+ +utilityName+this->Makefile->GetDefinition("CMAKE_EXECUTABLE_SUFFIX");
+
+ // make sure we remove any /./ in the name
+ cmSystemTools::ReplaceString(utilityExecutable, "/./", "/");
+
+ // Enter the value into the cache.
+ this->Makefile->AddCacheDefinition(cacheEntry,
+ utilityExecutable.c_str(),
+ "Path to an internal program.",
+ cmCacheManager::FILEPATH);
+ // add a value into the cache that maps from the
+ // full path to the name of the project
+ cmSystemTools::ConvertToUnixSlashes(utilityExecutable);
+ this->Makefile->AddCacheDefinition(utilityExecutable,
+ utilityName.c_str(),
+ "Executable to project name.",
+ cmCacheManager::INTERNAL);
+
+ return true;
+}
+
diff --git a/Source/cmUtilitySourceCommand.h b/Source/cmUtilitySourceCommand.h
new file mode 100644
index 0000000000..23afdbe0d8
--- /dev/null
+++ b/Source/cmUtilitySourceCommand.h
@@ -0,0 +1,28 @@
+/*============================================================================
+ 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 cmUtilitySourceCommand_h
+#define cmUtilitySourceCommand_h
+
+#include "cmCommand.h"
+
+class cmUtilitySourceCommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmUtilitySourceCommand, cmCommand);
+ virtual cmCommand* Clone() { return new cmUtilitySourceCommand; }
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+ virtual std::string GetName() const { return "utility_source";}
+ virtual bool IsDiscouraged() const { return true; }
+};
+
+#endif
diff --git a/Source/cmUuid.cxx b/Source/cmUuid.cxx
new file mode 100644
index 0000000000..8b5b7aef0d
--- /dev/null
+++ b/Source/cmUuid.cxx
@@ -0,0 +1,214 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 "cmUuid.h"
+
+#include <string.h>
+
+#include <cmsys/MD5.h>
+#include "cm_sha2.h"
+
+cmUuid::cmUuid()
+{
+ Groups.push_back(4);
+ Groups.push_back(2);
+ Groups.push_back(2);
+ Groups.push_back(2);
+ Groups.push_back(6);
+}
+
+std::string cmUuid::FromMd5(std::vector<unsigned char> const& uuidNamespace,
+ std::string const& name) const
+{
+ std::vector<unsigned char> hashInput;
+ this->CreateHashInput(uuidNamespace, name, hashInput);
+
+ cmsysMD5_s *md5 = cmsysMD5_New();
+ cmsysMD5_Initialize(md5);
+ cmsysMD5_Append(md5, &hashInput[0], int(hashInput.size()));
+
+ unsigned char digest[16] = {0};
+ cmsysMD5_Finalize(md5, digest);
+
+ cmsysMD5_Delete(md5);
+
+ return this->FromDigest(digest, 3);
+}
+
+std::string cmUuid::FromSha1(std::vector<unsigned char> const& uuidNamespace,
+ std::string const& name) const
+{
+ std::vector<unsigned char> hashInput;
+ this->CreateHashInput(uuidNamespace, name, hashInput);
+
+ SHA_CTX *sha = new SHA_CTX;
+ SHA1_Init(sha);
+ SHA1_Update(sha, &hashInput[0], hashInput.size());
+
+ unsigned char digest[SHA1_DIGEST_LENGTH] = {0};
+ SHA1_Final(digest, sha);
+
+ delete sha;
+
+ return this->FromDigest(digest, 5);
+}
+
+void cmUuid::CreateHashInput(std::vector<unsigned char> const& uuidNamespace,
+ std::string const& name, std::vector<unsigned char> &output) const
+{
+ output = uuidNamespace;
+
+ if(name.size())
+ {
+ output.resize(output.size() + name.size());
+
+ memcpy(&output[0] + uuidNamespace.size(),
+ name.c_str(), name.size());
+ }
+}
+
+std::string cmUuid::FromDigest(
+ const unsigned char* digest, unsigned char version) const
+{
+ typedef unsigned char byte_t;
+
+ byte_t uuid[16] = {0};
+ memcpy(uuid, digest, 16);
+
+ uuid[6] &= 0xF;
+ uuid[6] |= byte_t(version << 4);
+
+ uuid[8] &= 0x3F;
+ uuid[8] |= 0x80;
+
+ return this->BinaryToString(uuid);
+}
+
+bool cmUuid::StringToBinary(std::string const& input,
+ std::vector<unsigned char> &output) const
+{
+ output.clear();
+ output.reserve(16);
+
+ if(input.length() != 36)
+ {
+ return false;
+ }
+ size_t index = 0;
+ for(size_t i = 0; i < this->Groups.size(); ++i)
+ {
+ if(i != 0 && input[index++] != '-')
+ {
+ return false;
+ }
+ size_t digits = this->Groups[i] * 2;
+ if(!StringToBinaryImpl(input.substr(index, digits), output))
+ {
+ return false;
+ }
+
+ index += digits;
+ }
+
+ return true;
+}
+
+std::string cmUuid::BinaryToString(const unsigned char* input) const
+{
+ std::string output;
+
+ size_t inputIndex = 0;
+ for(size_t i = 0; i < this->Groups.size(); ++i)
+ {
+ if(i != 0)
+ {
+ output += '-';
+ }
+
+ size_t bytes = this->Groups[i];
+ for(size_t j = 0; j < bytes; ++j)
+ {
+ unsigned char byte = input[inputIndex++];
+ output += this->ByteToHex(byte);
+ }
+ }
+
+ return output;
+}
+
+std::string cmUuid::ByteToHex(unsigned char byte) const
+{
+ std::string result;
+ for(int i = 0; i < 2; ++i)
+ {
+ unsigned char rest = byte % 16;
+ byte /= 16;
+
+ char c = (rest < 0xA) ?
+ char('0' + rest) :
+ char('a' + (rest - 0xA));
+
+ result = c + result;
+ }
+
+ return result;
+}
+
+bool cmUuid::StringToBinaryImpl(std::string const& input,
+ std::vector<unsigned char> &output) const
+{
+ if(input.size()%2)
+ {
+ return false;
+ }
+
+ for(size_t i = 0; i < input.size(); i +=2)
+ {
+ char c1 = 0;
+ if(!IntFromHexDigit(input[i], c1))
+ {
+ return false;
+ }
+
+ char c2 = 0;
+ if(!IntFromHexDigit(input[i + 1], c2))
+ {
+ return false;
+ }
+
+ output.push_back(char(c1 << 4 | c2));
+ }
+
+ return true;
+}
+
+bool cmUuid::IntFromHexDigit(char input, char& output) const
+{
+ if(input >= '0' && input <= '9')
+ {
+ output = char(input - '0');
+ return true;
+ }
+ else if(input >= 'a' && input <= 'f')
+ {
+ output = char(input - 'a' + 0xA);
+ return true;
+ }
+ else if(input >= 'A' && input <= 'F')
+ {
+ output = char(input - 'A' + 0xA);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
diff --git a/Source/cmUuid.h b/Source/cmUuid.h
new file mode 100644
index 0000000000..0dda357588
--- /dev/null
+++ b/Source/cmUuid.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 cmUuid_h
+#define cmUuid_h
+
+#include "cmStandardIncludes.h"
+
+/** \class cmUuid
+ * \brief Utility class to generate UUIDs as defined by RFC4122
+ *
+ */
+class cmUuid
+{
+public:
+ cmUuid();
+
+ std::string FromMd5(std::vector<unsigned char> const& uuidNamespace,
+ std::string const& name) const;
+
+ std::string FromSha1(std::vector<unsigned char> const& uuidNamespace,
+ std::string const& name) const;
+
+ bool StringToBinary(std::string const& input,
+ std::vector<unsigned char> &output) const;
+
+private:
+ std::string ByteToHex(unsigned char byte) const;
+
+ void CreateHashInput(std::vector<unsigned char> const& uuidNamespace,
+ std::string const& name, std::vector<unsigned char> &output) const;
+
+ std::string FromDigest(const unsigned char* digest,
+ unsigned char version) const;
+
+ bool StringToBinaryImpl(std::string const& input,
+ std::vector<unsigned char> &output) const;
+
+ std::string BinaryToString(const unsigned char* input) const;
+
+ bool IntFromHexDigit(char input, char& output) const;
+
+ std::vector<int> Groups;
+};
+
+
+#endif
diff --git a/Source/cmVS10CLFlagTable.h b/Source/cmVS10CLFlagTable.h
new file mode 100644
index 0000000000..a7b1b3651a
--- /dev/null
+++ b/Source/cmVS10CLFlagTable.h
@@ -0,0 +1,270 @@
+static cmVS7FlagTable cmVS10CLFlagTable[] =
+{
+
+ //Enum Properties
+ {"DebugInformationFormat", "Z7",
+ "C7 compatible", "OldStyle", 0},
+ {"DebugInformationFormat", "Zi",
+ "Program Database", "ProgramDatabase", 0},
+ {"DebugInformationFormat", "ZI",
+ "Program Database for Edit And Continue", "EditAndContinue", 0},
+
+ {"WarningLevel", "W0",
+ "Turn Off All Warnings", "TurnOffAllWarnings", 0},
+ {"WarningLevel", "W1",
+ "Level1", "Level1", 0},
+ {"WarningLevel", "W2",
+ "Level2", "Level2", 0},
+ {"WarningLevel", "W3",
+ "Level3", "Level3", 0},
+ {"WarningLevel", "W4",
+ "Level4", "Level4", 0},
+ {"WarningLevel", "Wall",
+ "EnableAllWarnings", "EnableAllWarnings", 0},
+
+ {"Optimization", "Od",
+ "Disabled", "Disabled", 0},
+ {"Optimization", "O1",
+ "Minimize Size", "MinSpace", 0},
+ {"Optimization", "O2",
+ "Maximize Speed", "MaxSpeed", 0},
+ {"Optimization", "Ox",
+ "Full Optimization", "Full", 0},
+
+ {"InlineFunctionExpansion", "",
+ "Default", "Default", 0},
+ {"InlineFunctionExpansion", "Ob0",
+ "Disabled", "Disabled", 0},
+ {"InlineFunctionExpansion", "Ob1",
+ "Only __inline", "OnlyExplicitInline", 0},
+ {"InlineFunctionExpansion", "Ob2",
+ "Any Suitable", "AnySuitable", 0},
+
+ {"FavorSizeOrSpeed", "Os",
+ "Favor small code", "Size", 0},
+ {"FavorSizeOrSpeed", "Ot",
+ "Favor fast code", "Speed", 0},
+ {"FavorSizeOrSpeed", "",
+ "Neither", "Neither", 0},
+
+ {"ExceptionHandling", "EHa",
+ "Yes with SEH Exceptions", "Async", 0},
+ {"ExceptionHandling", "EHsc",
+ "Yes", "Sync", 0},
+ {"ExceptionHandling", "EHs",
+ "Yes with Extern C functions", "SyncCThrow", 0},
+ {"ExceptionHandling", "",
+ "No", "false", 0},
+
+ {"BasicRuntimeChecks", "RTCs",
+ "Stack Frames", "StackFrameRuntimeCheck", 0},
+ {"BasicRuntimeChecks", "RTCu",
+ "Uninitialized variables", "UninitializedLocalUsageCheck", 0},
+ {"BasicRuntimeChecks", "RTC1",
+ "Both (/RTC1, equiv. to /RTCsu)", "EnableFastChecks", 0},
+ {"BasicRuntimeChecks", "",
+ "Default", "Default", 0},
+
+ {"RuntimeLibrary", "MT",
+ "Multi-threaded", "MultiThreaded", 0},
+ {"RuntimeLibrary", "MTd",
+ "Multi-threaded Debug", "MultiThreadedDebug", 0},
+ {"RuntimeLibrary", "MD",
+ "Multi-threaded DLL", "MultiThreadedDLL", 0},
+ {"RuntimeLibrary", "MDd",
+ "Multi-threaded Debug DLL", "MultiThreadedDebugDLL", 0},
+
+ {"StructMemberAlignment", "Zp1",
+ "1 Byte", "1Byte", 0},
+ {"StructMemberAlignment", "Zp2",
+ "2 Bytes", "2Bytes", 0},
+ {"StructMemberAlignment", "Zp4",
+ "4 Byte", "4Bytes", 0},
+ {"StructMemberAlignment", "Zp8",
+ "8 Bytes", "8Bytes", 0},
+ {"StructMemberAlignment", "Zp16",
+ "16 Bytes", "16Bytes", 0},
+ {"StructMemberAlignment", "",
+ "Default", "Default", 0},
+
+ {"EnableEnhancedInstructionSet", "arch:SSE",
+ "Streaming SIMD Extensions (/arch:SSE)", "StreamingSIMDExtensions", 0},
+ {"EnableEnhancedInstructionSet", "arch:SSE2",
+ "Streaming SIMD Extensions 2 (/arch:SSE2)", "StreamingSIMDExtensions2", 0},
+ {"EnableEnhancedInstructionSet", "",
+ "Not Set", "NotSet", 0},
+
+ {"FloatingPointModel", "fp:precise",
+ "Precise", "Precise", 0},
+ {"FloatingPointModel", "fp:strict",
+ "Strict", "Strict", 0},
+ {"FloatingPointModel", "fp:fast",
+ "Fast", "Fast", 0},
+
+ {"PrecompiledHeader", "Yc",
+ "Create", "Create",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeader", "Yu",
+ "Use", "Use",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeader", "",
+ "Not Using Precompiled Headers", "NotUsing", 0},
+
+ {"AssemblerOutput", "",
+ "No Listing", "NoListing", 0},
+ {"AssemblerOutput", "FA",
+ "Assembly-Only Listing", "AssemblyCode", 0},
+ {"AssemblerOutput", "FAc",
+ "Assembly With Machine Code", "AssemblyAndMachineCode", 0},
+ {"AssemblerOutput", "FAs",
+ "Assembly With Source Code", "AssemblyAndSourceCode", 0},
+ {"AssemblerOutput", "FAcs",
+ "Assembly, Machine Code and Source", "All", 0},
+
+ {"CallingConvention", "Gd",
+ "__cdecl", "Cdecl", 0},
+ {"CallingConvention", "Gr",
+ "__fastcall", "FastCall", 0},
+ {"CallingConvention", "Gz",
+ "__stdcall", "StdCall", 0},
+
+ {"CompileAs", "",
+ "Default", "Default", 0},
+ {"CompileAs", "TC",
+ "Compile as C Code", "CompileAsC", 0},
+ {"CompileAs", "TP",
+ "Compile as C++ Code", "CompileAsCpp", 0},
+
+ {"ErrorReporting", "errorReport:none",
+ "Do Not Send Report", "None", 0},
+ {"ErrorReporting", "errorReport:prompt",
+ "Prompt Immediately", "Prompt", 0},
+ {"ErrorReporting", "errorReport:queue",
+ "Queue For Next Login", "Queue", 0},
+ {"ErrorReporting", "errorReport:send",
+ "Send Automatically", "Send", 0},
+
+ {"CompileAsManaged", "",
+ "No Common Language RunTime Support", "false", 0},
+ {"CompileAsManaged", "clr",
+ "Common Language RunTime Support", "true", 0},
+ {"CompileAsManaged", "clr:pure",
+ "Pure MSIL Common Language RunTime Support", "Pure", 0},
+ {"CompileAsManaged", "clr:safe",
+ "Safe MSIL Common Language RunTime Support", "Safe", 0},
+ {"CompileAsManaged", "clr:oldSyntax",
+ "Common Language RunTime Support, Old Syntax", "OldSyntax", 0},
+
+
+ //Bool Properties
+ {"SuppressStartupBanner", "nologo-", "", "false", 0},
+ {"SuppressStartupBanner", "nologo", "", "true", 0},
+ {"TreatWarningAsError", "WX-", "", "false", 0},
+ {"TreatWarningAsError", "WX", "", "true", 0},
+ {"IntrinsicFunctions", "Oi", "", "true", 0},
+ {"OmitFramePointers", "Oy-", "", "false", 0},
+ {"OmitFramePointers", "Oy", "", "true", 0},
+ {"EnableFiberSafeOptimizations", "GT", "", "true", 0},
+ {"WholeProgramOptimization", "GL", "", "true", 0},
+ {"UndefineAllPreprocessorDefinitions", "u", "", "true", 0},
+ {"IgnoreStandardIncludePath", "X", "", "true", 0},
+ {"PreprocessToFile", "P", "", "true", 0},
+ {"PreprocessSuppressLineNumbers", "EP", "", "true", 0},
+ {"PreprocessKeepComments", "C", "", "true", 0},
+ {"StringPooling", "GF-", "", "false", 0},
+ {"StringPooling", "GF", "", "true", 0},
+ {"MinimalRebuild", "Gm-", "", "false", 0},
+ {"MinimalRebuild", "Gm", "", "true", 0},
+ {"SmallerTypeCheck", "RTCc", "", "true", 0},
+ {"BufferSecurityCheck", "GS-", "", "false", 0},
+ {"BufferSecurityCheck", "GS", "", "true", 0},
+ {"FunctionLevelLinking", "Gy-", "", "false", 0},
+ {"FunctionLevelLinking", "Gy", "", "true", 0},
+ {"FloatingPointExceptions", "fp:except-", "", "false", 0},
+ {"FloatingPointExceptions", "fp:except", "", "true", 0},
+ {"CreateHotpatchableImage", "hotpatch", "", "true", 0},
+ {"DisableLanguageExtensions", "Za", "", "true", 0},
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t-", "", "false", 0},
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t", "", "true", 0},
+ {"ForceConformanceInForLoopScope", "Zc:forScope-", "", "false", 0},
+ {"ForceConformanceInForLoopScope", "Zc:forScope", "", "true", 0},
+ {"RuntimeTypeInfo", "GR-", "", "false", 0},
+ {"RuntimeTypeInfo", "GR", "", "true", 0},
+ {"OpenMPSupport", "openmp-", "", "false", 0},
+ {"OpenMPSupport", "openmp", "", "true", 0},
+ {"ExpandAttributedSource", "Fx", "", "true", 0},
+ {"ShowIncludes", "showIncludes", "", "true", 0},
+ {"EnablePREfast", "analyze-", "", "false", 0},
+ {"EnablePREfast", "analyze", "", "true", 0},
+ {"UseFullPaths", "FC", "", "true", 0},
+ {"OmitDefaultLibName", "Zl", "", "true", 0},
+ {"UseUnicodeForAssemblerListing", "FAu", "", "true", 0},
+
+ //Bool Properties With Argument
+ {"MultiProcessorCompilation", "MP", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"ProcessorNumber", "MP", "Multi-processor Compilation", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"GenerateXMLDocumentationFiles", "doc", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"XMLDocumentationFileName", "doc", "Generate XML Documentation Files", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"BrowseInformation", "FR", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"BrowseInformationFile", "FR", "Enable Browse Information", "",
+ cmVS7FlagTable::UserValueRequired},
+
+ //String List Properties
+ {"AdditionalIncludeDirectories", "I",
+ "Additional Include Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AdditionalUsingDirectories", "AI",
+ "Resolve #using References",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"PreprocessorDefinitions", "D ",
+ "Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"UndefinePreprocessorDefinitions", "U",
+ "Undefine Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"DisableSpecificWarnings", "wd",
+ "Disable Specific Warnings",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForcedIncludeFiles", "FI",
+ "Forced Include File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForcedUsingFiles", "FU",
+ "Forced #using File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"TreatSpecificWarningsAsErrors", "we",
+ "Treat Specific Warnings As Errors",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {"PreprocessOutputPath", "Fi",
+ "Preprocess Output Path",
+ "", cmVS7FlagTable::UserValue},
+ {"PrecompiledHeaderFile", "Yc",
+ "Precompiled Header Name",
+ "", cmVS7FlagTable::UserValueRequired},
+ {"PrecompiledHeaderFile", "Yu",
+ "Precompiled Header Name",
+ "", cmVS7FlagTable::UserValueRequired},
+ {"PrecompiledHeaderOutputFile", "Fp",
+ "Precompiled Header Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"AssemblerListingLocation", "Fa",
+ "ASM List Location",
+ "", cmVS7FlagTable::UserValue},
+ {"ObjectFileName", "Fo",
+ "Object File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"ProgramDataBaseFileName", "Fd",
+ "Program Database File Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [XMLDocumentationFileName] - no command line Switch.
+ // Skip [BrowseInformationFile] - no command line Switch.
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS10LibFlagTable.h b/Source/cmVS10LibFlagTable.h
new file mode 100644
index 0000000000..79aeeff71c
--- /dev/null
+++ b/Source/cmVS10LibFlagTable.h
@@ -0,0 +1,102 @@
+static cmVS7FlagTable cmVS10LibFlagTable[] =
+{
+
+ //Enum Properties
+ {"ErrorReporting", "ERRORREPORT:PROMPT",
+ "PromptImmediately", "PromptImmediately", 0},
+ {"ErrorReporting", "ERRORREPORT:QUEUE",
+ "Queue For Next Login", "QueueForNextLogin", 0},
+ {"ErrorReporting", "ERRORREPORT:SEND",
+ "Send Error Report", "SendErrorReport", 0},
+ {"ErrorReporting", "ERRORREPORT:NONE",
+ "No Error Report", "NoErrorReport", 0},
+
+ {"TargetMachine", "MACHINE:ARM",
+ "MachineARM", "MachineARM", 0},
+ {"TargetMachine", "MACHINE:EBC",
+ "MachineEBC", "MachineEBC", 0},
+ {"TargetMachine", "MACHINE:IA64",
+ "MachineIA64", "MachineIA64", 0},
+ {"TargetMachine", "MACHINE:MIPS",
+ "MachineMIPS", "MachineMIPS", 0},
+ {"TargetMachine", "MACHINE:MIPS16",
+ "MachineMIPS16", "MachineMIPS16", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU",
+ "MachineMIPSFPU", "MachineMIPSFPU", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU16",
+ "MachineMIPSFPU16", "MachineMIPSFPU16", 0},
+ {"TargetMachine", "MACHINE:SH4",
+ "MachineSH4", "MachineSH4", 0},
+ {"TargetMachine", "MACHINE:THUMB",
+ "MachineTHUMB", "MachineTHUMB", 0},
+ {"TargetMachine", "MACHINE:X64",
+ "MachineX64", "MachineX64", 0},
+ {"TargetMachine", "MACHINE:X86",
+ "MachineX86", "MachineX86", 0},
+
+ {"SubSystem", "SUBSYSTEM:CONSOLE",
+ "Console", "Console", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWS",
+ "Windows", "Windows", 0},
+ {"SubSystem", "SUBSYSTEM:NATIVE",
+ "Native", "Native", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_APPLICATION",
+ "EFI Application", "EFI Application", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER",
+ "EFI Boot Service Driver", "EFI Boot Service Driver", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_ROM",
+ "EFI ROM", "EFI ROM", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_RUNTIME_DRIVER",
+ "EFI Runtime", "EFI Runtime", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWSCE",
+ "WindowsCE", "WindowsCE", 0},
+ {"SubSystem", "SUBSYSTEM:POSIX",
+ "POSIX", "POSIX", 0},
+
+
+ //Bool Properties
+ {"SuppressStartupBanner", "NOLOGO", "", "true", 0},
+ {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "", "true", 0},
+ {"TreatLibWarningAsErrors", "WX:NO", "", "false", 0},
+ {"TreatLibWarningAsErrors", "WX", "", "true", 0},
+ {"Verbose", "VERBOSE", "", "true", 0},
+ {"LinkTimeCodeGeneration", "LTCG", "", "true", 0},
+
+ //Bool Properties With Argument
+
+ //String List Properties
+ // Skip [AdditionalDependencies] - no command line Switch.
+ {"AdditionalLibraryDirectories", "LIBPATH:",
+ "Additional Library Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"IgnoreSpecificDefaultLibraries", "NODEFAULTLIB:",
+ "Ignore Specific Default Libraries",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ExportNamedFunctions", "EXPORT:",
+ "Export Named Functions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"RemoveObjects", "REMOVE:",
+ "Remove Objects",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ {"OutputFile", "OUT:",
+ "Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"ModuleDefinitionFile", "DEF:",
+ "Module Definition File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"ForceSymbolReferences", "INCLUDE:",
+ "Force Symbol References",
+ "", cmVS7FlagTable::UserValue},
+ {"DisplayLibrary", "LIST:",
+ "Display Library to standard output",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [MinimumRequiredVersion] - no command line Switch.
+ {"Name", "NAME:",
+ "Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS10LinkFlagTable.h b/Source/cmVS10LinkFlagTable.h
new file mode 100644
index 0000000000..f6b758d05f
--- /dev/null
+++ b/Source/cmVS10LinkFlagTable.h
@@ -0,0 +1,302 @@
+static cmVS7FlagTable cmVS10LinkFlagTable[] =
+{
+
+ //Enum Properties
+ {"ShowProgress", "",
+ "Not Set", "NotSet", 0},
+ {"ShowProgress", "VERBOSE",
+ "Display all progress messages", "LinkVerbose", 0},
+ {"ShowProgress", "VERBOSE:Lib",
+ "For Libraries Searched", "LinkVerboseLib", 0},
+ {"ShowProgress", "VERBOSE:ICF",
+ "About COMDAT folding during optimized linking", "LinkVerboseICF", 0},
+ {"ShowProgress", "VERBOSE:REF",
+ "About data removed during optimized linking", "LinkVerboseREF", 0},
+ {"ShowProgress", "VERBOSE:SAFESEH",
+ "About Modules incompatible with SEH", "LinkVerboseSAFESEH", 0},
+ {"ShowProgress", "VERBOSE:CLR",
+ "About linker activity related to managed code", "LinkVerboseCLR", 0},
+
+ {"ForceFileOutput", "FORCE",
+ "Enabled", "Enabled", 0},
+ {"ForceFileOutput", "FORCE:MULTIPLE",
+ "Multiply Defined Symbol Only", "MultiplyDefinedSymbolOnly", 0},
+ {"ForceFileOutput", "FORCE:UNRESOLVED",
+ "Undefined Symbol Only", "UndefinedSymbolOnly", 0},
+
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN",
+ "Enabled", "Enabled", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:5",
+ "X86 Image Only", "X86Image", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:6",
+ "X64 Image Only", "X64Image", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:16",
+ "Itanium Image Only", "ItaniumImage", 0},
+
+ {"UACExecutionLevel", "level='asInvoker'",
+ "asInvoker", "AsInvoker", 0},
+ {"UACExecutionLevel", "level='highestAvailable'",
+ "highestAvailable", "HighestAvailable", 0},
+ {"UACExecutionLevel", "level='requireAdministrator'",
+ "requireAdministrator", "RequireAdministrator", 0},
+
+ {"SubSystem", "",
+ "Not Set", "NotSet", 0},
+ {"SubSystem", "SUBSYSTEM:CONSOLE",
+ "Console", "Console", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWS",
+ "Windows", "Windows", 0},
+ {"SubSystem", "SUBSYSTEM:NATIVE",
+ "Native", "Native", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_APPLICATION",
+ "EFI Application", "EFI Application", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER",
+ "EFI Boot Service Driver", "EFI Boot Service Driver", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_ROM",
+ "EFI ROM", "EFI ROM", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_RUNTIME_DRIVER",
+ "EFI Runtime", "EFI Runtime", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWSCE",
+ "WindowsCE", "WindowsCE", 0},
+ {"SubSystem", "SUBSYSTEM:POSIX",
+ "POSIX", "POSIX", 0},
+
+ {"Driver", "",
+ "Not Set", "NotSet", 0},
+ {"Driver", "Driver",
+ "Driver", "Driver", 0},
+ {"Driver", "DRIVER:UPONLY",
+ "UP Only", "UpOnly", 0},
+ {"Driver", "DRIVER:WDM",
+ "WDM", "WDM", 0},
+
+ {"LinkTimeCodeGeneration", "",
+ "Default", "Default", 0},
+ {"LinkTimeCodeGeneration", "LTCG",
+ "Use Link Time Code Generation", "UseLinkTimeCodeGeneration", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGInstrument",
+ "Profile Guided Optimization - Instrument", "PGInstrument", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGOptimize",
+ "Profile Guided Optimization - Optimization", "PGOptimization", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGUpdate",
+ "Profile Guided Optimization - Update", "PGUpdate", 0},
+
+ {"TargetMachine", "",
+ "Not Set", "NotSet", 0},
+ {"TargetMachine", "MACHINE:ARM",
+ "MachineARM", "MachineARM", 0},
+ {"TargetMachine", "MACHINE:EBC",
+ "MachineEBC", "MachineEBC", 0},
+ {"TargetMachine", "MACHINE:IA64",
+ "MachineIA64", "MachineIA64", 0},
+ {"TargetMachine", "MACHINE:MIPS",
+ "MachineMIPS", "MachineMIPS", 0},
+ {"TargetMachine", "MACHINE:MIPS16",
+ "MachineMIPS16", "MachineMIPS16", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU",
+ "MachineMIPSFPU", "MachineMIPSFPU", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU16",
+ "MachineMIPSFPU16", "MachineMIPSFPU16", 0},
+ {"TargetMachine", "MACHINE:SH4",
+ "MachineSH4", "MachineSH4", 0},
+ {"TargetMachine", "MACHINE:THUMB",
+ "MachineTHUMB", "MachineTHUMB", 0},
+ {"TargetMachine", "MACHINE:X64",
+ "MachineX64", "MachineX64", 0},
+ {"TargetMachine", "MACHINE:X86",
+ "MachineX86", "MachineX86", 0},
+
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:MTA",
+ "MTA threading attribute", "MTAThreadingAttribute", 0},
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:STA",
+ "STA threading attribute", "STAThreadingAttribute", 0},
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:NONE",
+ "Default threading attribute", "DefaultThreadingAttribute", 0},
+
+ {"CLRImageType", "CLRIMAGETYPE:IJW",
+ "Force IJW image", "ForceIJWImage", 0},
+ {"CLRImageType", "CLRIMAGETYPE:PURE",
+ "Force Pure IL Image", "ForcePureILImage", 0},
+ {"CLRImageType", "CLRIMAGETYPE:SAFE",
+ "Force Safe IL Image", "ForceSafeILImage", 0},
+ {"CLRImageType", "",
+ "Default image type", "Default", 0},
+
+ {"LinkErrorReporting", "ERRORREPORT:PROMPT",
+ "PromptImmediately", "PromptImmediately", 0},
+ {"LinkErrorReporting", "ERRORREPORT:QUEUE",
+ "Queue For Next Login", "QueueForNextLogin", 0},
+ {"LinkErrorReporting", "ERRORREPORT:SEND",
+ "Send Error Report", "SendErrorReport", 0},
+ {"LinkErrorReporting", "ERRORREPORT:NONE",
+ "No Error Report", "NoErrorReport", 0},
+
+ {"CLRSupportLastError", "CLRSupportLastError",
+ "Enabled", "Enabled", 0},
+ {"CLRSupportLastError", "CLRSupportLastError:NO",
+ "Disabled", "Disabled", 0},
+ {"CLRSupportLastError", "CLRSupportLastError:SYSTEMDLL",
+ "System Dlls Only", "SystemDlls", 0},
+
+
+ //Bool Properties
+ {"LinkIncremental", "INCREMENTAL:NO", "", "false", 0},
+ {"LinkIncremental", "INCREMENTAL", "", "true", 0},
+ {"SuppressStartupBanner", "NOLOGO", "", "true", 0},
+ {"LinkStatus", "LTCG:NOSTATUS", "", "false", 0},
+ {"LinkStatus", "LTCG:STATUS", "", "true", 0},
+ {"PreventDllBinding", "ALLOWBIND:NO", "", "false", 0},
+ {"PreventDllBinding", "ALLOWBIND", "", "true", 0},
+ {"TreatLinkerWarningAsErrors", "WX:NO", "", "false", 0},
+ {"TreatLinkerWarningAsErrors", "WX", "", "true", 0},
+ {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "", "true", 0},
+ {"GenerateManifest", "MANIFEST:NO", "", "false", 0},
+ {"GenerateManifest", "MANIFEST", "", "true", 0},
+ {"AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0},
+ {"UACUIAccess", "uiAccess='false'", "", "false", 0},
+ {"UACUIAccess", "uiAccess='true'", "", "true", 0},
+ {"GenerateDebugInformation", "DEBUG", "", "true", 0},
+ {"MapExports", "MAPINFO:EXPORTS", "", "true", 0},
+ {"AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0},
+ {"AssemblyDebug", "ASSEMBLYDEBUG", "", "true", 0},
+ {"LargeAddressAware", "LARGEADDRESSAWARE:NO", "", "false", 0},
+ {"LargeAddressAware", "LARGEADDRESSAWARE", "", "true", 0},
+ {"TerminalServerAware", "TSAWARE:NO", "", "false", 0},
+ {"TerminalServerAware", "TSAWARE", "", "true", 0},
+ {"SwapRunFromCD", "SWAPRUN:CD", "", "true", 0},
+ {"SwapRunFromNET", "SWAPRUN:NET", "", "true", 0},
+ {"OptimizeReferences", "OPT:NOREF", "", "false", 0},
+ {"OptimizeReferences", "OPT:REF", "", "true", 0},
+ {"EnableCOMDATFolding", "OPT:NOICF", "", "false", 0},
+ {"EnableCOMDATFolding", "OPT:ICF", "", "true", 0},
+ {"IgnoreEmbeddedIDL", "IGNOREIDL", "", "true", 0},
+ {"NoEntryPoint", "NOENTRY", "", "true", 0},
+ {"SetChecksum", "RELEASE", "", "true", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE:NO", "", "false", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE", "", "true", 0},
+ {"FixedBaseAddress", "FIXED:NO", "", "false", 0},
+ {"FixedBaseAddress", "FIXED", "", "true", 0},
+ {"DataExecutionPrevention", "NXCOMPAT:NO", "", "false", 0},
+ {"DataExecutionPrevention", "NXCOMPAT", "", "true", 0},
+ {"TurnOffAssemblyGeneration", "NOASSEMBLY", "", "true", 0},
+ {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
+ {"SupportNobindOfDelayLoadedDLL", "DELAY:NOBIND", "", "true", 0},
+ {"Profile", "PROFILE", "", "true", 0},
+ {"LinkDelaySign", "DELAYSIGN:NO", "", "false", 0},
+ {"LinkDelaySign", "DELAYSIGN", "", "true", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
+ {"ImageHasSafeExceptionHandlers", "SAFESEH:NO", "", "false", 0},
+ {"ImageHasSafeExceptionHandlers", "SAFESEH", "", "true", 0},
+ {"LinkDLL", "DLL", "", "true", 0},
+
+ //Bool Properties With Argument
+ {"EnableUAC", "MANIFESTUAC:NO", "", "false", 0},
+ {"EnableUAC", "MANIFESTUAC:", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"UACUIAccess", "MANIFESTUAC:", "Enable User Account Control (UAC)", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"GenerateMapFile", "MAP", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"MapFileName", "MAP:", "Generate Map File", "",
+ cmVS7FlagTable::UserValueRequired},
+
+ //String List Properties
+ {"AdditionalLibraryDirectories", "LIBPATH:",
+ "Additional Library Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ // Skip [AdditionalDependencies] - no command line Switch.
+ {"IgnoreSpecificDefaultLibraries", "NODEFAULTLIB:",
+ "Ignore Specific Default Libraries",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AddModuleNamesToAssembly", "ASSEMBLYMODULE:",
+ "Add Module to Assembly",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"EmbedManagedResourceFile", "ASSEMBLYRESOURCE:",
+ "Embed Managed Resource File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForceSymbolReferences", "INCLUDE:",
+ "Force Symbol References",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"DelayLoadDLLs", "DELAYLOAD:",
+ "Delay Loaded Dlls",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AssemblyLinkResource", "ASSEMBLYLINKRESOURCE:",
+ "Assembly Link Resource",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AdditionalManifestDependencies", "MANIFESTDEPENDENCY:",
+ "Additional Manifest Dependencies",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ {"OutputFile", "OUT:",
+ "Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"Version", "VERSION:",
+ "Version",
+ "", cmVS7FlagTable::UserValue},
+ {"SpecifySectionAttributes", "SECTION:",
+ "Specify Section Attributes",
+ "", cmVS7FlagTable::UserValue},
+ {"MSDOSStubFileName", "STUB:",
+ "MS-DOS Stub File Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {"ModuleDefinitionFile", "DEF:",
+ "Module Definition File",
+ "", cmVS7FlagTable::UserValue},
+ {"ManifestFile", "ManifestFile:",
+ "Manifest File",
+ "", cmVS7FlagTable::UserValue},
+ {"ProgramDatabaseFile", "PDB:",
+ "Generate Program Database File",
+ "", cmVS7FlagTable::UserValue},
+ {"StripPrivateSymbols", "PDBSTRIPPED:",
+ "Strip Private Symbols",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [MapFileName] - no command line Switch.
+ // Skip [MinimumRequiredVersion] - no command line Switch.
+ {"HeapReserveSize", "HEAP:",
+ "Heap Reserve Size",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [HeapCommitSize] - no command line Switch.
+ {"StackReserveSize", "STACK:",
+ "Stack Reserve Size",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [StackCommitSize] - no command line Switch.
+ {"FunctionOrder", "ORDER:@",
+ "Function Order",
+ "", cmVS7FlagTable::UserValue},
+ {"ProfileGuidedDatabase", "PGD:",
+ "Profile Guided Database",
+ "", cmVS7FlagTable::UserValue},
+ {"MidlCommandFile", "MIDL:@",
+ "MIDL Commands",
+ "", cmVS7FlagTable::UserValue},
+ {"MergedIDLBaseFileName", "IDLOUT:",
+ "Merged IDL Base File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"TypeLibraryFile", "TLBOUT:",
+ "Type Library",
+ "", cmVS7FlagTable::UserValue},
+ {"EntryPointSymbol", "ENTRY:",
+ "Entry Point",
+ "", cmVS7FlagTable::UserValue},
+ {"BaseAddress", "BASE:",
+ "Base Address",
+ "", cmVS7FlagTable::UserValue},
+ {"ImportLibrary", "IMPLIB:",
+ "Import Library",
+ "", cmVS7FlagTable::UserValue},
+ {"MergeSections", "MERGE:",
+ "Merge Sections",
+ "", cmVS7FlagTable::UserValue},
+ {"LinkKeyFile", "KEYFILE:",
+ "Key File",
+ "", cmVS7FlagTable::UserValue},
+ {"KeyContainer", "KEYCONTAINER:",
+ "Key Container",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS10MASMFlagTable.h b/Source/cmVS10MASMFlagTable.h
new file mode 100644
index 0000000000..8fb6f3328a
--- /dev/null
+++ b/Source/cmVS10MASMFlagTable.h
@@ -0,0 +1,96 @@
+static cmVS7FlagTable cmVS10MASMFlagTable[] =
+{
+
+ //Enum Properties
+ {"PreserveIdentifierCase", "",
+ "Default", "0", 0},
+ {"PreserveIdentifierCase", "/Cp",
+ "Preserves Identifier Case (/Cp)", "1", 0},
+ {"PreserveIdentifierCase", "/Cu",
+ "Maps all identifiers to upper case. (/Cu)", "2", 0},
+ {"PreserveIdentifierCase", "/Cx",
+ "Preserves case in public and extern symbols. (/Cx)", "3", 0},
+
+ {"WarningLevel", "/W0",
+ "Warning Level 0 (/W0)", "0", 0},
+ {"WarningLevel", "/W1",
+ "Warning Level 1 (/W1)", "1", 0},
+ {"WarningLevel", "/W2",
+ "Warning Level 2 (/W2)", "2", 0},
+ {"WarningLevel", "/W3",
+ "Warning Level 3 (/W3)", "3", 0},
+
+ {"PackAlignmentBoundary", "",
+ "Default", "0", 0},
+ {"PackAlignmentBoundary", "/Zp1",
+ "One Byte Boundary (/Zp1)", "1", 0},
+ {"PackAlignmentBoundary", "/Zp2",
+ "Two Byte Boundary (/Zp2)", "2", 0},
+ {"PackAlignmentBoundary", "/Zp4",
+ "Four Byte Boundary (/Zp4)", "3", 0},
+ {"PackAlignmentBoundary", "/Zp8",
+ "Eight Byte Boundary (/Zp8)", "4", 0},
+ {"PackAlignmentBoundary", "/Zp16",
+ "Sixteen Byte Boundary (/Zp16)", "5", 0},
+
+ {"CallingConvention", "",
+ "Default", "0", 0},
+ {"CallingConvention", "/Gd",
+ "Use C-style Calling Convention (/Gd)", "1", 0},
+ {"CallingConvention", "/Gz",
+ "Use stdcall Calling Convention (/Gz)", "2", 0},
+ {"CallingConvention", "/Gc",
+ "Use Pascal Calling Convention (/Gc)", "3", 0},
+
+ {"ErrorReporting", "/errorReport:prompt",
+ "Prompt to send report immediately (/errorReport:prompt)", "0", 0},
+ {"ErrorReporting", "/errorReport:queue",
+ "Prompt to send report at the next logon (/errorReport:queue)", "1", 0},
+ {"ErrorReporting", "/errorReport:send",
+ "Automatically send report (/errorReport:send)", "2", 0},
+ {"ErrorReporting", "/errorReport:none",
+ "Do not send report (/errorReport:none)", "3", 0},
+
+
+ //Bool Properties
+ {"NoLogo", "/nologo", "", "true", 0},
+ {"GeneratePreprocessedSourceListing", "/EP", "", "true", 0},
+ {"ListAllAvailableInformation", "/Sa", "", "true", 0},
+ {"UseSafeExceptionHandlers", "/safeseh", "", "true", 0},
+ {"AddFirstPassListing", "/Sf", "", "true", 0},
+ {"EnableAssemblyGeneratedCodeListing", "/Sg", "", "true", 0},
+ {"DisableSymbolTable", "/Sn", "", "true", 0},
+ {"EnableFalseConditionalsInListing", "/Sx", "", "true", 0},
+ {"TreatWarningsAsErrors", "/WX", "", "true", 0},
+ {"MakeAllSymbolsPublic", "/Zf", "", "true", 0},
+ {"GenerateDebugInformation", "/Zi", "", "true", 0},
+ {"EnableMASM51Compatibility", "/Zm", "", "true", 0},
+ {"PerformSyntaxCheckOnly", "/Zs", "", "true", 0},
+
+ //Bool Properties With Argument
+
+ //String List Properties
+ {"PreprocessorDefinitions", "/D",
+ "Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"IncludePaths", "/I",
+ "Include Paths",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"BrowseFile", "/FR",
+ "Generate Browse Information File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ // Skip [AdditionalDependencies] - no command line Switch.
+
+ //String Properties
+ // Skip [Inputs] - no command line Switch.
+ {"ObjectFileName", "/Fo",
+ "Object File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"AssembledCodeListingFile", "/Fl",
+ "Assembled Code Listing File",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [CommandLineTemplate] - no command line Switch.
+ // Skip [ExecutionDescription] - no command line Switch.
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS10RCFlagTable.h b/Source/cmVS10RCFlagTable.h
new file mode 100644
index 0000000000..90499861be
--- /dev/null
+++ b/Source/cmVS10RCFlagTable.h
@@ -0,0 +1,7 @@
+static cmVS7FlagTable cmVS10RCFlagTable[] =
+{
+ //Bool Properties
+ {"NullTerminateStrings", "n", "", "true", 0},
+
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS11CLFlagTable.h b/Source/cmVS11CLFlagTable.h
new file mode 100644
index 0000000000..a61ab16096
--- /dev/null
+++ b/Source/cmVS11CLFlagTable.h
@@ -0,0 +1,288 @@
+static cmVS7FlagTable cmVS11CLFlagTable[] =
+{
+
+ //Enum Properties
+ {"DebugInformationFormat", "",
+ "None", "None", 0},
+ {"DebugInformationFormat", "Z7",
+ "C7 compatible", "OldStyle", 0},
+ {"DebugInformationFormat", "Zi",
+ "Program Database", "ProgramDatabase", 0},
+ {"DebugInformationFormat", "ZI",
+ "Program Database for Edit And Continue", "EditAndContinue", 0},
+
+ {"WarningLevel", "W0",
+ "Turn Off All Warnings", "TurnOffAllWarnings", 0},
+ {"WarningLevel", "W1",
+ "Level1", "Level1", 0},
+ {"WarningLevel", "W2",
+ "Level2", "Level2", 0},
+ {"WarningLevel", "W3",
+ "Level3", "Level3", 0},
+ {"WarningLevel", "W4",
+ "Level4", "Level4", 0},
+ {"WarningLevel", "Wall",
+ "EnableAllWarnings", "EnableAllWarnings", 0},
+
+ {"Optimization", "Od",
+ "Disabled", "Disabled", 0},
+ {"Optimization", "O1",
+ "Minimize Size", "MinSpace", 0},
+ {"Optimization", "O2",
+ "Maximize Speed", "MaxSpeed", 0},
+ {"Optimization", "Ox",
+ "Full Optimization", "Full", 0},
+
+ {"InlineFunctionExpansion", "",
+ "Default", "Default", 0},
+ {"InlineFunctionExpansion", "Ob0",
+ "Disabled", "Disabled", 0},
+ {"InlineFunctionExpansion", "Ob1",
+ "Only __inline", "OnlyExplicitInline", 0},
+ {"InlineFunctionExpansion", "Ob2",
+ "Any Suitable", "AnySuitable", 0},
+
+ {"FavorSizeOrSpeed", "Os",
+ "Favor small code", "Size", 0},
+ {"FavorSizeOrSpeed", "Ot",
+ "Favor fast code", "Speed", 0},
+ {"FavorSizeOrSpeed", "",
+ "Neither", "Neither", 0},
+
+ {"ExceptionHandling", "EHa",
+ "Yes with SEH Exceptions", "Async", 0},
+ {"ExceptionHandling", "EHsc",
+ "Yes", "Sync", 0},
+ {"ExceptionHandling", "EHs",
+ "Yes with Extern C functions", "SyncCThrow", 0},
+ {"ExceptionHandling", "",
+ "No", "false", 0},
+
+ {"BasicRuntimeChecks", "RTCs",
+ "Stack Frames", "StackFrameRuntimeCheck", 0},
+ {"BasicRuntimeChecks", "RTCu",
+ "Uninitialized variables", "UninitializedLocalUsageCheck", 0},
+ {"BasicRuntimeChecks", "RTC1",
+ "Both (/RTC1, equiv. to /RTCsu)", "EnableFastChecks", 0},
+ {"BasicRuntimeChecks", "",
+ "Default", "Default", 0},
+
+ {"RuntimeLibrary", "MT",
+ "Multi-threaded", "MultiThreaded", 0},
+ {"RuntimeLibrary", "MTd",
+ "Multi-threaded Debug", "MultiThreadedDebug", 0},
+ {"RuntimeLibrary", "MD",
+ "Multi-threaded DLL", "MultiThreadedDLL", 0},
+ {"RuntimeLibrary", "MDd",
+ "Multi-threaded Debug DLL", "MultiThreadedDebugDLL", 0},
+
+ {"StructMemberAlignment", "Zp1",
+ "1 Byte", "1Byte", 0},
+ {"StructMemberAlignment", "Zp2",
+ "2 Bytes", "2Bytes", 0},
+ {"StructMemberAlignment", "Zp4",
+ "4 Byte", "4Bytes", 0},
+ {"StructMemberAlignment", "Zp8",
+ "8 Bytes", "8Bytes", 0},
+ {"StructMemberAlignment", "Zp16",
+ "16 Bytes", "16Bytes", 0},
+ {"StructMemberAlignment", "",
+ "Default", "Default", 0},
+
+ {"EnableEnhancedInstructionSet", "arch:SSE",
+ "Streaming SIMD Extensions", "StreamingSIMDExtensions", 0},
+ {"EnableEnhancedInstructionSet", "arch:SSE2",
+ "Streaming SIMD Extensions 2", "StreamingSIMDExtensions2", 0},
+ {"EnableEnhancedInstructionSet", "arch:AVX",
+ "Advanced Vector Extensions", "AdvancedVectorExtensions", 0},
+ {"EnableEnhancedInstructionSet", "arch:IA32",
+ "No Enhanced Instructions", "NoExtensions", 0},
+ {"EnableEnhancedInstructionSet", "",
+ "Not Set", "NotSet", 0},
+
+ {"FloatingPointModel", "fp:precise",
+ "Precise", "Precise", 0},
+ {"FloatingPointModel", "fp:strict",
+ "Strict", "Strict", 0},
+ {"FloatingPointModel", "fp:fast",
+ "Fast", "Fast", 0},
+
+ {"PrecompiledHeader", "Yc",
+ "Create", "Create",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeader", "Yu",
+ "Use", "Use",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeader", "",
+ "Not Using Precompiled Headers", "NotUsing", 0},
+
+ {"AssemblerOutput", "",
+ "No Listing", "NoListing", 0},
+ {"AssemblerOutput", "FA",
+ "Assembly-Only Listing", "AssemblyCode", 0},
+ {"AssemblerOutput", "FAc",
+ "Assembly With Machine Code", "AssemblyAndMachineCode", 0},
+ {"AssemblerOutput", "FAs",
+ "Assembly With Source Code", "AssemblyAndSourceCode", 0},
+ {"AssemblerOutput", "FAcs",
+ "Assembly, Machine Code and Source", "All", 0},
+
+ {"CallingConvention", "Gd",
+ "__cdecl", "Cdecl", 0},
+ {"CallingConvention", "Gr",
+ "__fastcall", "FastCall", 0},
+ {"CallingConvention", "Gz",
+ "__stdcall", "StdCall", 0},
+
+ {"CompileAs", "",
+ "Default", "Default", 0},
+ {"CompileAs", "TC",
+ "Compile as C Code", "CompileAsC", 0},
+ {"CompileAs", "TP",
+ "Compile as C++ Code", "CompileAsCpp", 0},
+
+ {"ErrorReporting", "errorReport:none",
+ "Do Not Send Report", "None", 0},
+ {"ErrorReporting", "errorReport:prompt",
+ "Prompt Immediately", "Prompt", 0},
+ {"ErrorReporting", "errorReport:queue",
+ "Queue For Next Login", "Queue", 0},
+ {"ErrorReporting", "errorReport:send",
+ "Send Automatically", "Send", 0},
+
+ {"CompileAsManaged", "",
+ "No Common Language RunTime Support", "false", 0},
+ {"CompileAsManaged", "clr",
+ "Common Language RunTime Support", "true", 0},
+ {"CompileAsManaged", "clr:pure",
+ "Pure MSIL Common Language RunTime Support", "Pure", 0},
+ {"CompileAsManaged", "clr:safe",
+ "Safe MSIL Common Language RunTime Support", "Safe", 0},
+ {"CompileAsManaged", "clr:oldSyntax",
+ "Common Language RunTime Support, Old Syntax", "OldSyntax", 0},
+
+
+ //Bool Properties
+ {"CompileAsWinRT", "ZW", "", "true", 0},
+ {"WinRTNoStdLib", "ZW:nostdlib", "", "true", 0},
+ {"SuppressStartupBanner", "nologo-", "", "false", 0},
+ {"SuppressStartupBanner", "nologo", "", "true", 0},
+ {"TreatWarningAsError", "WX-", "", "false", 0},
+ {"TreatWarningAsError", "WX", "", "true", 0},
+ {"SDLCheck", "sdl-", "", "false", 0},
+ {"SDLCheck", "sdl", "", "true", 0},
+ {"IntrinsicFunctions", "Oi", "", "true", 0},
+ {"OmitFramePointers", "Oy-", "", "false", 0},
+ {"OmitFramePointers", "Oy", "", "true", 0},
+ {"EnableFiberSafeOptimizations", "GT", "", "true", 0},
+ {"WholeProgramOptimization", "GL", "", "true", 0},
+ {"UndefineAllPreprocessorDefinitions", "u", "", "true", 0},
+ {"IgnoreStandardIncludePath", "X", "", "true", 0},
+ {"PreprocessToFile", "P", "", "true", 0},
+ {"PreprocessSuppressLineNumbers", "EP", "", "true", 0},
+ {"PreprocessKeepComments", "C", "", "true", 0},
+ {"StringPooling", "GF-", "", "false", 0},
+ {"StringPooling", "GF", "", "true", 0},
+ {"MinimalRebuild", "Gm-", "", "false", 0},
+ {"MinimalRebuild", "Gm", "", "true", 0},
+ {"SmallerTypeCheck", "RTCc", "", "true", 0},
+ {"BufferSecurityCheck", "GS-", "", "false", 0},
+ {"BufferSecurityCheck", "GS", "", "true", 0},
+ {"FunctionLevelLinking", "Gy-", "", "false", 0},
+ {"FunctionLevelLinking", "Gy", "", "true", 0},
+ {"EnableParallelCodeGeneration", "Qpar-", "", "false", 0},
+ {"EnableParallelCodeGeneration", "Qpar", "", "true", 0},
+ {"FloatingPointExceptions", "fp:except-", "", "false", 0},
+ {"FloatingPointExceptions", "fp:except", "", "true", 0},
+ {"CreateHotpatchableImage", "hotpatch", "", "true", 0},
+ {"DisableLanguageExtensions", "Za", "", "true", 0},
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t-", "", "false", 0},
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t", "", "true", 0},
+ {"ForceConformanceInForLoopScope", "Zc:forScope-", "", "false", 0},
+ {"ForceConformanceInForLoopScope", "Zc:forScope", "", "true", 0},
+ {"RuntimeTypeInfo", "GR-", "", "false", 0},
+ {"RuntimeTypeInfo", "GR", "", "true", 0},
+ {"OpenMPSupport", "openmp-", "", "false", 0},
+ {"OpenMPSupport", "openmp", "", "true", 0},
+ {"ExpandAttributedSource", "Fx", "", "true", 0},
+ {"UseUnicodeForAssemblerListing", "FAu", "", "true", 0},
+ {"ShowIncludes", "showIncludes", "", "true", 0},
+ {"EnablePREfast", "analyze-", "", "false", 0},
+ {"EnablePREfast", "analyze", "", "true", 0},
+ {"UseFullPaths", "FC", "", "true", 0},
+ {"OmitDefaultLibName", "Zl", "", "true", 0},
+
+ //Bool Properties With Argument
+ {"MultiProcessorCompilation", "MP", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"ProcessorNumber", "MP", "Multi-processor Compilation", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"GenerateXMLDocumentationFiles", "doc", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"XMLDocumentationFileName", "doc", "Generate XML Documentation Files", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"BrowseInformation", "FR", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"BrowseInformationFile", "FR", "Enable Browse Information", "",
+ cmVS7FlagTable::UserValueRequired},
+
+ //String List Properties
+ {"AdditionalIncludeDirectories", "I",
+ "Additional Include Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AdditionalUsingDirectories", "AI",
+ "Additional #using Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"PreprocessorDefinitions", "D ",
+ "Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"UndefinePreprocessorDefinitions", "U",
+ "Undefine Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"DisableSpecificWarnings", "wd",
+ "Disable Specific Warnings",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForcedIncludeFiles", "FI",
+ "Forced Include File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForcedUsingFiles", "FU",
+ "Forced #using File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"PREfastLog", "analyze:log",
+ "Code Analysis Log",
+ "", cmVS7FlagTable::UserFollowing},
+ {"PREfastAdditionalPlugins", "analyze:plugin",
+ "Additional Code Analysis Native plugins",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"TreatSpecificWarningsAsErrors", "we",
+ "Treat Specific Warnings As Errors",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {"PreprocessOutputPath", "Fi",
+ "Preprocess Output Path",
+ "", cmVS7FlagTable::UserValue},
+ {"PrecompiledHeaderFile", "Yc",
+ "Precompiled Header Name",
+ "", cmVS7FlagTable::UserValueRequired},
+ {"PrecompiledHeaderFile", "Yu",
+ "Precompiled Header Name",
+ "", cmVS7FlagTable::UserValueRequired},
+ {"PrecompiledHeaderOutputFile", "Fp",
+ "Precompiled Header Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"AssemblerListingLocation", "Fa",
+ "ASM List Location",
+ "", cmVS7FlagTable::UserValue},
+ {"ObjectFileName", "Fo",
+ "Object File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"ProgramDataBaseFileName", "Fd",
+ "Program Database File Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [XMLDocumentationFileName] - no command line Switch.
+ // Skip [BrowseInformationFile] - no command line Switch.
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS11LibFlagTable.h b/Source/cmVS11LibFlagTable.h
new file mode 100644
index 0000000000..942944241f
--- /dev/null
+++ b/Source/cmVS11LibFlagTable.h
@@ -0,0 +1,102 @@
+static cmVS7FlagTable cmVS11LibFlagTable[] =
+{
+
+ //Enum Properties
+ {"ErrorReporting", "ERRORREPORT:PROMPT",
+ "PromptImmediately", "PromptImmediately", 0},
+ {"ErrorReporting", "ERRORREPORT:QUEUE",
+ "Queue For Next Login", "QueueForNextLogin", 0},
+ {"ErrorReporting", "ERRORREPORT:SEND",
+ "Send Error Report", "SendErrorReport", 0},
+ {"ErrorReporting", "ERRORREPORT:NONE",
+ "No Error Report", "NoErrorReport", 0},
+
+ {"TargetMachine", "MACHINE:ARM",
+ "MachineARM", "MachineARM", 0},
+ {"TargetMachine", "MACHINE:EBC",
+ "MachineEBC", "MachineEBC", 0},
+ {"TargetMachine", "MACHINE:IA64",
+ "MachineIA64", "MachineIA64", 0},
+ {"TargetMachine", "MACHINE:MIPS",
+ "MachineMIPS", "MachineMIPS", 0},
+ {"TargetMachine", "MACHINE:MIPS16",
+ "MachineMIPS16", "MachineMIPS16", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU",
+ "MachineMIPSFPU", "MachineMIPSFPU", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU16",
+ "MachineMIPSFPU16", "MachineMIPSFPU16", 0},
+ {"TargetMachine", "MACHINE:SH4",
+ "MachineSH4", "MachineSH4", 0},
+ {"TargetMachine", "MACHINE:THUMB",
+ "MachineTHUMB", "MachineTHUMB", 0},
+ {"TargetMachine", "MACHINE:X64",
+ "MachineX64", "MachineX64", 0},
+ {"TargetMachine", "MACHINE:X86",
+ "MachineX86", "MachineX86", 0},
+
+ {"SubSystem", "SUBSYSTEM:CONSOLE",
+ "Console", "Console", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWS",
+ "Windows", "Windows", 0},
+ {"SubSystem", "SUBSYSTEM:NATIVE",
+ "Native", "Native", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_APPLICATION",
+ "EFI Application", "EFI Application", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER",
+ "EFI Boot Service Driver", "EFI Boot Service Driver", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_ROM",
+ "EFI ROM", "EFI ROM", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_RUNTIME_DRIVER",
+ "EFI Runtime", "EFI Runtime", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWSCE",
+ "WindowsCE", "WindowsCE", 0},
+ {"SubSystem", "SUBSYSTEM:POSIX",
+ "POSIX", "POSIX", 0},
+
+
+ //Bool Properties
+ {"SuppressStartupBanner", "NOLOGO", "", "true", 0},
+ {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "", "true", 0},
+ {"TreatLibWarningAsErrors", "WX:NO", "", "false", 0},
+ {"TreatLibWarningAsErrors", "WX", "", "true", 0},
+ {"Verbose", "VERBOSE", "", "true", 0},
+ {"LinkTimeCodeGeneration", "LTCG", "", "true", 0},
+
+ //Bool Properties With Argument
+
+ //String List Properties
+ // Skip [AdditionalDependencies] - no command line Switch.
+ {"AdditionalLibraryDirectories", "LIBPATH:",
+ "Additional Library Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"IgnoreSpecificDefaultLibraries", "NODEFAULTLIB:",
+ "Ignore Specific Default Libraries",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ExportNamedFunctions", "EXPORT:",
+ "Export Named Functions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"RemoveObjects", "REMOVE:",
+ "Remove Objects",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ {"OutputFile", "OUT:",
+ "Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"ModuleDefinitionFile", "DEF:",
+ "Module Definition File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"ForceSymbolReferences", "INCLUDE:",
+ "Force Symbol References",
+ "", cmVS7FlagTable::UserValue},
+ {"DisplayLibrary", "LIST:",
+ "Display Library to standard output",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [MinimumRequiredVersion] - no command line Switch.
+ {"Name", "NAME:",
+ "Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [AdditionalOptions] - no command line Switch.
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS11LinkFlagTable.h b/Source/cmVS11LinkFlagTable.h
new file mode 100644
index 0000000000..0f641e40e0
--- /dev/null
+++ b/Source/cmVS11LinkFlagTable.h
@@ -0,0 +1,340 @@
+static cmVS7FlagTable cmVS11LinkFlagTable[] =
+{
+
+ //Enum Properties
+ {"ShowProgress", "",
+ "Not Set", "NotSet", 0},
+ {"ShowProgress", "VERBOSE",
+ "Display all progress messages", "LinkVerbose", 0},
+ {"ShowProgress", "VERBOSE:Lib",
+ "For Libraries Searched", "LinkVerboseLib", 0},
+ {"ShowProgress", "VERBOSE:ICF",
+ "About COMDAT folding during optimized linking", "LinkVerboseICF", 0},
+ {"ShowProgress", "VERBOSE:REF",
+ "About data removed during optimized linking", "LinkVerboseREF", 0},
+ {"ShowProgress", "VERBOSE:SAFESEH",
+ "About Modules incompatible with SEH", "LinkVerboseSAFESEH", 0},
+ {"ShowProgress", "VERBOSE:CLR",
+ "About linker activity related to managed code", "LinkVerboseCLR", 0},
+
+ {"ForceFileOutput", "FORCE",
+ "Enabled", "Enabled", 0},
+ {"ForceFileOutput", "FORCE:MULTIPLE",
+ "Multiply Defined Symbol Only", "MultiplyDefinedSymbolOnly", 0},
+ {"ForceFileOutput", "FORCE:UNRESOLVED",
+ "Undefined Symbol Only", "UndefinedSymbolOnly", 0},
+
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN",
+ "Enabled", "Enabled", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:5",
+ "X86 Image Only", "X86Image", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:6",
+ "X64 Image Only", "X64Image", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:16",
+ "Itanium Image Only", "ItaniumImage", 0},
+
+ {"UACExecutionLevel", "level='asInvoker'",
+ "asInvoker", "AsInvoker", 0},
+ {"UACExecutionLevel", "level='highestAvailable'",
+ "highestAvailable", "HighestAvailable", 0},
+ {"UACExecutionLevel", "level='requireAdministrator'",
+ "requireAdministrator", "RequireAdministrator", 0},
+
+ {"SubSystem", "",
+ "Not Set", "NotSet", 0},
+ {"SubSystem", "SUBSYSTEM:CONSOLE",
+ "Console", "Console", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWS",
+ "Windows", "Windows", 0},
+ {"SubSystem", "SUBSYSTEM:NATIVE",
+ "Native", "Native", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_APPLICATION",
+ "EFI Application", "EFI Application", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER",
+ "EFI Boot Service Driver", "EFI Boot Service Driver", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_ROM",
+ "EFI ROM", "EFI ROM", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_RUNTIME_DRIVER",
+ "EFI Runtime", "EFI Runtime", 0},
+ {"SubSystem", "SUBSYSTEM:POSIX",
+ "POSIX", "POSIX", 0},
+
+ {"Driver", "",
+ "Not Set", "NotSet", 0},
+ {"Driver", "Driver",
+ "Driver", "Driver", 0},
+ {"Driver", "DRIVER:UPONLY",
+ "UP Only", "UpOnly", 0},
+ {"Driver", "DRIVER:WDM",
+ "WDM", "WDM", 0},
+
+ {"LinkTimeCodeGeneration", "",
+ "Default", "Default", 0},
+ {"LinkTimeCodeGeneration", "LTCG",
+ "Use Link Time Code Generation", "UseLinkTimeCodeGeneration", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGInstrument",
+ "Profile Guided Optimization - Instrument", "PGInstrument", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGOptimize",
+ "Profile Guided Optimization - Optimization", "PGOptimization", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGUpdate",
+ "Profile Guided Optimization - Update", "PGUpdate", 0},
+
+ {"GenerateWindowsMetadata", "WINMD",
+ "Yes", "true", 0},
+ {"GenerateWindowsMetadata", "WINMD:NO",
+ "No", "false", 0},
+
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA1",
+ "SHA1", "SHA1", 0},
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA256",
+ "SHA256", "SHA256", 0},
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA384",
+ "SHA384", "SHA384", 0},
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA512",
+ "SHA512", "SHA512", 0},
+
+ {"TargetMachine", "",
+ "Not Set", "NotSet", 0},
+ {"TargetMachine", "MACHINE:ARM",
+ "MachineARM", "MachineARM", 0},
+ {"TargetMachine", "MACHINE:EBC",
+ "MachineEBC", "MachineEBC", 0},
+ {"TargetMachine", "MACHINE:IA64",
+ "MachineIA64", "MachineIA64", 0},
+ {"TargetMachine", "MACHINE:MIPS",
+ "MachineMIPS", "MachineMIPS", 0},
+ {"TargetMachine", "MACHINE:MIPS16",
+ "MachineMIPS16", "MachineMIPS16", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU",
+ "MachineMIPSFPU", "MachineMIPSFPU", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU16",
+ "MachineMIPSFPU16", "MachineMIPSFPU16", 0},
+ {"TargetMachine", "MACHINE:SH4",
+ "MachineSH4", "MachineSH4", 0},
+ {"TargetMachine", "MACHINE:THUMB",
+ "MachineTHUMB", "MachineTHUMB", 0},
+ {"TargetMachine", "MACHINE:X64",
+ "MachineX64", "MachineX64", 0},
+ {"TargetMachine", "MACHINE:X86",
+ "MachineX86", "MachineX86", 0},
+
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:MTA",
+ "MTA threading attribute", "MTAThreadingAttribute", 0},
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:STA",
+ "STA threading attribute", "STAThreadingAttribute", 0},
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:NONE",
+ "Default threading attribute", "DefaultThreadingAttribute", 0},
+
+ {"CLRImageType", "CLRIMAGETYPE:IJW",
+ "Force IJW image", "ForceIJWImage", 0},
+ {"CLRImageType", "CLRIMAGETYPE:PURE",
+ "Force Pure IL Image", "ForcePureILImage", 0},
+ {"CLRImageType", "CLRIMAGETYPE:SAFE",
+ "Force Safe IL Image", "ForceSafeILImage", 0},
+ {"CLRImageType", "",
+ "Default image type", "Default", 0},
+
+ {"SignHash", "CLRSIGNHASH:SHA1",
+ "SHA1", "SHA1", 0},
+ {"SignHash", "CLRSIGNHASH:SHA256",
+ "SHA256", "SHA256", 0},
+ {"SignHash", "CLRSIGNHASH:SHA384",
+ "SHA384", "SHA384", 0},
+ {"SignHash", "CLRSIGNHASH:SHA512",
+ "SHA512", "SHA512", 0},
+
+ {"LinkErrorReporting", "ERRORREPORT:PROMPT",
+ "PromptImmediately", "PromptImmediately", 0},
+ {"LinkErrorReporting", "ERRORREPORT:QUEUE",
+ "Queue For Next Login", "QueueForNextLogin", 0},
+ {"LinkErrorReporting", "ERRORREPORT:SEND",
+ "Send Error Report", "SendErrorReport", 0},
+ {"LinkErrorReporting", "ERRORREPORT:NONE",
+ "No Error Report", "NoErrorReport", 0},
+
+ {"CLRSupportLastError", "CLRSupportLastError",
+ "Enabled", "Enabled", 0},
+ {"CLRSupportLastError", "CLRSupportLastError:NO",
+ "Disabled", "Disabled", 0},
+ {"CLRSupportLastError", "CLRSupportLastError:SYSTEMDLL",
+ "System Dlls Only", "SystemDlls", 0},
+
+
+ //Bool Properties
+ {"LinkIncremental", "INCREMENTAL:NO", "", "false", 0},
+ {"LinkIncremental", "INCREMENTAL", "", "true", 0},
+ {"SuppressStartupBanner", "NOLOGO", "", "true", 0},
+ {"LinkStatus", "LTCG:NOSTATUS", "", "false", 0},
+ {"LinkStatus", "LTCG:STATUS", "", "true", 0},
+ {"PreventDllBinding", "ALLOWBIND:NO", "", "false", 0},
+ {"PreventDllBinding", "ALLOWBIND", "", "true", 0},
+ {"TreatLinkerWarningAsErrors", "WX:NO", "", "false", 0},
+ {"TreatLinkerWarningAsErrors", "WX", "", "true", 0},
+ {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "", "true", 0},
+ {"GenerateManifest", "MANIFEST:NO", "", "false", 0},
+ {"GenerateManifest", "MANIFEST", "", "true", 0},
+ {"AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0},
+ {"UACUIAccess", "uiAccess='false'", "", "false", 0},
+ {"UACUIAccess", "uiAccess='true'", "", "true", 0},
+ {"ManifestEmbed", "manifest:embed", "", "true", 0},
+ {"GenerateDebugInformation", "DEBUG", "", "true", 0},
+ {"MapExports", "MAPINFO:EXPORTS", "", "true", 0},
+ {"AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0},
+ {"AssemblyDebug", "ASSEMBLYDEBUG", "", "true", 0},
+ {"LargeAddressAware", "LARGEADDRESSAWARE:NO", "", "false", 0},
+ {"LargeAddressAware", "LARGEADDRESSAWARE", "", "true", 0},
+ {"TerminalServerAware", "TSAWARE:NO", "", "false", 0},
+ {"TerminalServerAware", "TSAWARE", "", "true", 0},
+ {"SwapRunFromCD", "SWAPRUN:CD", "", "true", 0},
+ {"SwapRunFromNET", "SWAPRUN:NET", "", "true", 0},
+ {"OptimizeReferences", "OPT:NOREF", "", "false", 0},
+ {"OptimizeReferences", "OPT:REF", "", "true", 0},
+ {"EnableCOMDATFolding", "OPT:NOICF", "", "false", 0},
+ {"EnableCOMDATFolding", "OPT:ICF", "", "true", 0},
+ {"IgnoreEmbeddedIDL", "IGNOREIDL", "", "true", 0},
+ {"AppContainer", "APPCONTAINER", "", "true", 0},
+ {"WindowsMetadataLinkDelaySign", "WINMDDELAYSIGN:NO", "", "false", 0},
+ {"WindowsMetadataLinkDelaySign", "WINMDDELAYSIGN", "", "true", 0},
+ {"NoEntryPoint", "NOENTRY", "", "true", 0},
+ {"SetChecksum", "RELEASE", "", "true", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE:NO", "", "false", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE", "", "true", 0},
+ {"FixedBaseAddress", "FIXED:NO", "", "false", 0},
+ {"FixedBaseAddress", "FIXED", "", "true", 0},
+ {"DataExecutionPrevention", "NXCOMPAT:NO", "", "false", 0},
+ {"DataExecutionPrevention", "NXCOMPAT", "", "true", 0},
+ {"TurnOffAssemblyGeneration", "NOASSEMBLY", "", "true", 0},
+ {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
+ {"SupportNobindOfDelayLoadedDLL", "DELAY:NOBIND", "", "true", 0},
+ {"Profile", "PROFILE", "", "true", 0},
+ {"LinkDelaySign", "DELAYSIGN:NO", "", "false", 0},
+ {"LinkDelaySign", "DELAYSIGN", "", "true", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
+ {"DetectOneDefinitionRule", "ODR", "", "true", 0},
+ {"ImageHasSafeExceptionHandlers", "SAFESEH:NO", "", "false", 0},
+ {"ImageHasSafeExceptionHandlers", "SAFESEH", "", "true", 0},
+ {"LinkDLL", "DLL", "", "true", 0},
+
+ //Bool Properties With Argument
+ {"EnableUAC", "MANIFESTUAC:NO", "", "false", 0},
+ {"EnableUAC", "MANIFESTUAC:", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"UACUIAccess", "MANIFESTUAC:", "Enable User Account Control (UAC)", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"GenerateMapFile", "MAP", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"MapFileName", "MAP:", "Generate Map File", "",
+ cmVS7FlagTable::UserValueRequired},
+
+ //String List Properties
+ {"AdditionalLibraryDirectories", "LIBPATH:",
+ "Additional Library Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ // Skip [AdditionalDependencies] - no command line Switch.
+ {"IgnoreSpecificDefaultLibraries", "NODEFAULTLIB:",
+ "Ignore Specific Default Libraries",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AddModuleNamesToAssembly", "ASSEMBLYMODULE:",
+ "Add Module to Assembly",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"EmbedManagedResourceFile", "ASSEMBLYRESOURCE:",
+ "Embed Managed Resource File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForceSymbolReferences", "INCLUDE:",
+ "Force Symbol References",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"DelayLoadDLLs", "DELAYLOAD:",
+ "Delay Loaded Dlls",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AssemblyLinkResource", "ASSEMBLYLINKRESOURCE:",
+ "Assembly Link Resource",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AdditionalManifestDependencies", "MANIFESTDEPENDENCY:",
+ "Additional Manifest Dependencies",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ManifestInput", "manifestinput:",
+ "Manifest Input",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ {"OutputFile", "OUT:",
+ "Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"Version", "VERSION:",
+ "Version",
+ "", cmVS7FlagTable::UserValue},
+ {"SpecifySectionAttributes", "SECTION:",
+ "Specify Section Attributes",
+ "", cmVS7FlagTable::UserValue},
+ {"MSDOSStubFileName", "STUB:",
+ "MS-DOS Stub File Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {"ModuleDefinitionFile", "DEF:",
+ "Module Definition File",
+ "", cmVS7FlagTable::UserValue},
+ {"ManifestFile", "ManifestFile:",
+ "Manifest File",
+ "", cmVS7FlagTable::UserValue},
+ {"ProgramDatabaseFile", "PDB:",
+ "Generate Program Database File",
+ "", cmVS7FlagTable::UserValue},
+ {"StripPrivateSymbols", "PDBSTRIPPED:",
+ "Strip Private Symbols",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [MapFileName] - no command line Switch.
+ // Skip [MinimumRequiredVersion] - no command line Switch.
+ {"HeapReserveSize", "HEAP:",
+ "Heap Reserve Size",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [HeapCommitSize] - no command line Switch.
+ {"StackReserveSize", "STACK:",
+ "Stack Reserve Size",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [StackCommitSize] - no command line Switch.
+ {"FunctionOrder", "ORDER:@",
+ "Function Order",
+ "", cmVS7FlagTable::UserValue},
+ {"ProfileGuidedDatabase", "PGD:",
+ "Profile Guided Database",
+ "", cmVS7FlagTable::UserValue},
+ {"MidlCommandFile", "MIDL:@",
+ "MIDL Commands",
+ "", cmVS7FlagTable::UserValue},
+ {"MergedIDLBaseFileName", "IDLOUT:",
+ "Merged IDL Base File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"TypeLibraryFile", "TLBOUT:",
+ "Type Library",
+ "", cmVS7FlagTable::UserValue},
+ {"WindowsMetadataFile", "WINMDFILE:",
+ "Windows Metadata File",
+ "", cmVS7FlagTable::UserValue},
+ {"WindowsMetadataLinkKeyFile", "WINMDKEYFILE:",
+ "Windows Metadata Key File",
+ "", cmVS7FlagTable::UserValue},
+ {"WindowsMetadataKeyContainer", "WINMDKEYCONTAINER:",
+ "Windows Metadata Key Container",
+ "", cmVS7FlagTable::UserValue},
+ {"EntryPointSymbol", "ENTRY:",
+ "Entry Point",
+ "", cmVS7FlagTable::UserValue},
+ {"BaseAddress", "BASE:",
+ "Base Address",
+ "", cmVS7FlagTable::UserValue},
+ {"ImportLibrary", "IMPLIB:",
+ "Import Library",
+ "", cmVS7FlagTable::UserValue},
+ {"MergeSections", "MERGE:",
+ "Merge Sections",
+ "", cmVS7FlagTable::UserValue},
+ {"LinkKeyFile", "KEYFILE:",
+ "Key File",
+ "", cmVS7FlagTable::UserValue},
+ {"KeyContainer", "KEYCONTAINER:",
+ "Key Container",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS11MASMFlagTable.h b/Source/cmVS11MASMFlagTable.h
new file mode 100644
index 0000000000..2ff95adc1a
--- /dev/null
+++ b/Source/cmVS11MASMFlagTable.h
@@ -0,0 +1,96 @@
+static cmVS7FlagTable cmVS11MASMFlagTable[] =
+{
+
+ //Enum Properties
+ {"PreserveIdentifierCase", "",
+ "Default", "0", 0},
+ {"PreserveIdentifierCase", "/Cp",
+ "Preserves Identifier Case (/Cp)", "1", 0},
+ {"PreserveIdentifierCase", "/Cu",
+ "Maps all identifiers to upper case. (/Cu)", "2", 0},
+ {"PreserveIdentifierCase", "/Cx",
+ "Preserves case in public and extern symbols. (/Cx)", "3", 0},
+
+ {"WarningLevel", "/W0",
+ "Warning Level 0 (/W0)", "0", 0},
+ {"WarningLevel", "/W1",
+ "Warning Level 1 (/W1)", "1", 0},
+ {"WarningLevel", "/W2",
+ "Warning Level 2 (/W2)", "2", 0},
+ {"WarningLevel", "/W3",
+ "Warning Level 3 (/W3)", "3", 0},
+
+ {"PackAlignmentBoundary", "",
+ "Default", "0", 0},
+ {"PackAlignmentBoundary", "/Zp1",
+ "One Byte Boundary (/Zp1)", "1", 0},
+ {"PackAlignmentBoundary", "/Zp2",
+ "Two Byte Boundary (/Zp2)", "2", 0},
+ {"PackAlignmentBoundary", "/Zp4",
+ "Four Byte Boundary (/Zp4)", "3", 0},
+ {"PackAlignmentBoundary", "/Zp8",
+ "Eight Byte Boundary (/Zp8)", "4", 0},
+ {"PackAlignmentBoundary", "/Zp16",
+ "Sixteen Byte Boundary (/Zp16)", "5", 0},
+
+ {"CallingConvention", "",
+ "Default", "0", 0},
+ {"CallingConvention", "/Gd",
+ "Use C-style Calling Convention (/Gd)", "1", 0},
+ {"CallingConvention", "/Gz",
+ "Use stdcall Calling Convention (/Gz)", "2", 0},
+ {"CallingConvention", "/Gc",
+ "Use Pascal Calling Convention (/Gc)", "3", 0},
+
+ {"ErrorReporting", "/errorReport:prompt",
+ "Prompt to send report immediately (/errorReport:prompt)", "0", 0},
+ {"ErrorReporting", "/errorReport:queue",
+ "Prompt to send report at the next logon (/errorReport:queue)", "1", 0},
+ {"ErrorReporting", "/errorReport:send",
+ "Automatically send report (/errorReport:send)", "2", 0},
+ {"ErrorReporting", "/errorReport:none",
+ "Do not send report (/errorReport:none)", "3", 0},
+
+
+ //Bool Properties
+ {"NoLogo", "/nologo", "", "true", 0},
+ {"GeneratePreprocessedSourceListing", "/EP", "", "true", 0},
+ {"ListAllAvailableInformation", "/Sa", "", "true", 0},
+ {"UseSafeExceptionHandlers", "/safeseh", "", "true", 0},
+ {"AddFirstPassListing", "/Sf", "", "true", 0},
+ {"EnableAssemblyGeneratedCodeListing", "/Sg", "", "true", 0},
+ {"DisableSymbolTable", "/Sn", "", "true", 0},
+ {"EnableFalseConditionalsInListing", "/Sx", "", "true", 0},
+ {"TreatWarningsAsErrors", "/WX", "", "true", 0},
+ {"MakeAllSymbolsPublic", "/Zf", "", "true", 0},
+ {"GenerateDebugInformation", "/Zi", "", "true", 0},
+ {"EnableMASM51Compatibility", "/Zm", "", "true", 0},
+ {"PerformSyntaxCheckOnly", "/Zs", "", "true", 0},
+
+ //Bool Properties With Argument
+
+ //String List Properties
+ {"PreprocessorDefinitions", "/D",
+ "Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"IncludePaths", "/I",
+ "Include Paths",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"BrowseFile", "/FR",
+ "Generate Browse Information File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ // Skip [AdditionalDependencies] - no command line Switch.
+
+ //String Properties
+ // Skip [Inputs] - no command line Switch.
+ {"ObjectFileName", "/Fo",
+ "Object File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"AssembledCodeListingFile", "/Fl",
+ "Assembled Code Listing File",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [CommandLineTemplate] - no command line Switch.
+ // Skip [ExecutionDescription] - no command line Switch.
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS11RCFlagTable.h b/Source/cmVS11RCFlagTable.h
new file mode 100644
index 0000000000..a7d2de1e3d
--- /dev/null
+++ b/Source/cmVS11RCFlagTable.h
@@ -0,0 +1,7 @@
+static cmVS7FlagTable cmVS11RCFlagTable[] =
+{
+ //Bool Properties
+ {"NullTerminateStrings", "n", "", "true", 0},
+
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS12CLFlagTable.h b/Source/cmVS12CLFlagTable.h
new file mode 100644
index 0000000000..0a7916f1b6
--- /dev/null
+++ b/Source/cmVS12CLFlagTable.h
@@ -0,0 +1,294 @@
+static cmVS7FlagTable cmVS12CLFlagTable[] =
+{
+
+ //Enum Properties
+ {"DebugInformationFormat", "",
+ "None", "None", 0},
+ {"DebugInformationFormat", "Z7",
+ "C7 compatible", "OldStyle", 0},
+ {"DebugInformationFormat", "Zi",
+ "Program Database", "ProgramDatabase", 0},
+ {"DebugInformationFormat", "ZI",
+ "Program Database for Edit And Continue", "EditAndContinue", 0},
+
+ {"WarningLevel", "W0",
+ "Turn Off All Warnings", "TurnOffAllWarnings", 0},
+ {"WarningLevel", "W1",
+ "Level1", "Level1", 0},
+ {"WarningLevel", "W2",
+ "Level2", "Level2", 0},
+ {"WarningLevel", "W3",
+ "Level3", "Level3", 0},
+ {"WarningLevel", "W4",
+ "Level4", "Level4", 0},
+ {"WarningLevel", "Wall",
+ "EnableAllWarnings", "EnableAllWarnings", 0},
+
+ {"Optimization", "",
+ "Custom", "Custom", 0},
+ {"Optimization", "Od",
+ "Disabled", "Disabled", 0},
+ {"Optimization", "O1",
+ "Minimize Size", "MinSpace", 0},
+ {"Optimization", "O2",
+ "Maximize Speed", "MaxSpeed", 0},
+ {"Optimization", "Ox",
+ "Full Optimization", "Full", 0},
+
+ {"InlineFunctionExpansion", "",
+ "Default", "Default", 0},
+ {"InlineFunctionExpansion", "Ob0",
+ "Disabled", "Disabled", 0},
+ {"InlineFunctionExpansion", "Ob1",
+ "Only __inline", "OnlyExplicitInline", 0},
+ {"InlineFunctionExpansion", "Ob2",
+ "Any Suitable", "AnySuitable", 0},
+
+ {"FavorSizeOrSpeed", "Os",
+ "Favor small code", "Size", 0},
+ {"FavorSizeOrSpeed", "Ot",
+ "Favor fast code", "Speed", 0},
+ {"FavorSizeOrSpeed", "",
+ "Neither", "Neither", 0},
+
+ {"ExceptionHandling", "EHa",
+ "Yes with SEH Exceptions", "Async", 0},
+ {"ExceptionHandling", "EHsc",
+ "Yes", "Sync", 0},
+ {"ExceptionHandling", "EHs",
+ "Yes with Extern C functions", "SyncCThrow", 0},
+ {"ExceptionHandling", "",
+ "No", "false", 0},
+
+ {"BasicRuntimeChecks", "RTCs",
+ "Stack Frames", "StackFrameRuntimeCheck", 0},
+ {"BasicRuntimeChecks", "RTCu",
+ "Uninitialized variables", "UninitializedLocalUsageCheck", 0},
+ {"BasicRuntimeChecks", "RTC1",
+ "Both (/RTC1, equiv. to /RTCsu)", "EnableFastChecks", 0},
+ {"BasicRuntimeChecks", "",
+ "Default", "Default", 0},
+
+ {"RuntimeLibrary", "MT",
+ "Multi-threaded", "MultiThreaded", 0},
+ {"RuntimeLibrary", "MTd",
+ "Multi-threaded Debug", "MultiThreadedDebug", 0},
+ {"RuntimeLibrary", "MD",
+ "Multi-threaded DLL", "MultiThreadedDLL", 0},
+ {"RuntimeLibrary", "MDd",
+ "Multi-threaded Debug DLL", "MultiThreadedDebugDLL", 0},
+
+ {"StructMemberAlignment", "Zp1",
+ "1 Byte", "1Byte", 0},
+ {"StructMemberAlignment", "Zp2",
+ "2 Bytes", "2Bytes", 0},
+ {"StructMemberAlignment", "Zp4",
+ "4 Byte", "4Bytes", 0},
+ {"StructMemberAlignment", "Zp8",
+ "8 Bytes", "8Bytes", 0},
+ {"StructMemberAlignment", "Zp16",
+ "16 Bytes", "16Bytes", 0},
+ {"StructMemberAlignment", "",
+ "Default", "Default", 0},
+
+ {"BufferSecurityCheck", "GS-",
+ "Disable Security Check", "false", 0},
+ {"BufferSecurityCheck", "GS",
+ "Enable Security Check", "true", 0},
+
+ {"EnableEnhancedInstructionSet", "arch:SSE",
+ "Streaming SIMD Extensions", "StreamingSIMDExtensions", 0},
+ {"EnableEnhancedInstructionSet", "arch:SSE2",
+ "Streaming SIMD Extensions 2", "StreamingSIMDExtensions2", 0},
+ {"EnableEnhancedInstructionSet", "arch:AVX",
+ "Advanced Vector Extensions", "AdvancedVectorExtensions", 0},
+ {"EnableEnhancedInstructionSet", "arch:IA32",
+ "No Enhanced Instructions", "NoExtensions", 0},
+ {"EnableEnhancedInstructionSet", "",
+ "Not Set", "NotSet", 0},
+
+ {"FloatingPointModel", "fp:precise",
+ "Precise", "Precise", 0},
+ {"FloatingPointModel", "fp:strict",
+ "Strict", "Strict", 0},
+ {"FloatingPointModel", "fp:fast",
+ "Fast", "Fast", 0},
+
+ {"PrecompiledHeader", "Yc",
+ "Create", "Create",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeader", "Yu",
+ "Use", "Use",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeader", "",
+ "Not Using Precompiled Headers", "NotUsing", 0},
+
+ {"AssemblerOutput", "",
+ "No Listing", "NoListing", 0},
+ {"AssemblerOutput", "FA",
+ "Assembly-Only Listing", "AssemblyCode", 0},
+ {"AssemblerOutput", "FAc",
+ "Assembly With Machine Code", "AssemblyAndMachineCode", 0},
+ {"AssemblerOutput", "FAs",
+ "Assembly With Source Code", "AssemblyAndSourceCode", 0},
+ {"AssemblerOutput", "FAcs",
+ "Assembly, Machine Code and Source", "All", 0},
+
+ {"CallingConvention", "Gd",
+ "__cdecl", "Cdecl", 0},
+ {"CallingConvention", "Gr",
+ "__fastcall", "FastCall", 0},
+ {"CallingConvention", "Gz",
+ "__stdcall", "StdCall", 0},
+ {"CallingConvention", "Gv",
+ "__vectorcall", "VectorCall", 0},
+
+ {"CompileAs", "",
+ "Default", "Default", 0},
+ {"CompileAs", "TC",
+ "Compile as C Code", "CompileAsC", 0},
+ {"CompileAs", "TP",
+ "Compile as C++ Code", "CompileAsCpp", 0},
+
+ {"ErrorReporting", "errorReport:none",
+ "Do Not Send Report", "None", 0},
+ {"ErrorReporting", "errorReport:prompt",
+ "Prompt Immediately", "Prompt", 0},
+ {"ErrorReporting", "errorReport:queue",
+ "Queue For Next Login", "Queue", 0},
+ {"ErrorReporting", "errorReport:send",
+ "Send Automatically", "Send", 0},
+
+ {"CompileAsManaged", "",
+ "No Common Language RunTime Support", "false", 0},
+ {"CompileAsManaged", "clr",
+ "Common Language RunTime Support", "true", 0},
+ {"CompileAsManaged", "clr:pure",
+ "Pure MSIL Common Language RunTime Support", "Pure", 0},
+ {"CompileAsManaged", "clr:safe",
+ "Safe MSIL Common Language RunTime Support", "Safe", 0},
+ {"CompileAsManaged", "clr:oldSyntax",
+ "Common Language RunTime Support, Old Syntax", "OldSyntax", 0},
+
+
+ //Bool Properties
+ {"CompileAsWinRT", "ZW", "", "true", 0},
+ {"WinRTNoStdLib", "ZW:nostdlib", "", "true", 0},
+ {"SuppressStartupBanner", "nologo", "", "true", 0},
+ {"TreatWarningAsError", "WX-", "", "false", 0},
+ {"TreatWarningAsError", "WX", "", "true", 0},
+ {"SDLCheck", "sdl-", "", "false", 0},
+ {"SDLCheck", "sdl", "", "true", 0},
+ {"IntrinsicFunctions", "Oi", "", "true", 0},
+ {"OmitFramePointers", "Oy-", "", "false", 0},
+ {"OmitFramePointers", "Oy", "", "true", 0},
+ {"EnableFiberSafeOptimizations", "GT", "", "true", 0},
+ {"WholeProgramOptimization", "GL", "", "true", 0},
+ {"UndefineAllPreprocessorDefinitions", "u", "", "true", 0},
+ {"IgnoreStandardIncludePath", "X", "", "true", 0},
+ {"PreprocessToFile", "P", "", "true", 0},
+ {"PreprocessSuppressLineNumbers", "EP", "", "true", 0},
+ {"PreprocessKeepComments", "C", "", "true", 0},
+ {"StringPooling", "GF-", "", "false", 0},
+ {"StringPooling", "GF", "", "true", 0},
+ {"MinimalRebuild", "Gm-", "", "false", 0},
+ {"MinimalRebuild", "Gm", "", "true", 0},
+ {"SmallerTypeCheck", "RTCc", "", "true", 0},
+ {"FunctionLevelLinking", "Gy-", "", "false", 0},
+ {"FunctionLevelLinking", "Gy", "", "true", 0},
+ {"EnableParallelCodeGeneration", "Qpar-", "", "false", 0},
+ {"EnableParallelCodeGeneration", "Qpar", "", "true", 0},
+ {"FloatingPointExceptions", "fp:except-", "", "false", 0},
+ {"FloatingPointExceptions", "fp:except", "", "true", 0},
+ {"CreateHotpatchableImage", "hotpatch", "", "true", 0},
+ {"DisableLanguageExtensions", "Za", "", "true", 0},
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t-", "", "false", 0},
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t", "", "true", 0},
+ {"ForceConformanceInForLoopScope", "Zc:forScope-", "", "false", 0},
+ {"ForceConformanceInForLoopScope", "Zc:forScope", "", "true", 0},
+ {"RuntimeTypeInfo", "GR-", "", "false", 0},
+ {"RuntimeTypeInfo", "GR", "", "true", 0},
+ {"OpenMPSupport", "openmp-", "", "false", 0},
+ {"OpenMPSupport", "openmp", "", "true", 0},
+ {"ExpandAttributedSource", "Fx", "", "true", 0},
+ {"UseUnicodeForAssemblerListing", "FAu", "", "true", 0},
+ {"ShowIncludes", "showIncludes", "", "true", 0},
+ {"EnablePREfast", "analyze-", "", "false", 0},
+ {"EnablePREfast", "analyze", "", "true", 0},
+ {"UseFullPaths", "FC", "", "true", 0},
+ {"OmitDefaultLibName", "Zl", "", "true", 0},
+
+ //Bool Properties With Argument
+ {"MultiProcessorCompilation", "MP", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"ProcessorNumber", "MP", "Multi-processor Compilation", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"GenerateXMLDocumentationFiles", "doc", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"XMLDocumentationFileName", "doc", "Generate XML Documentation Files", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"BrowseInformation", "FR", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"BrowseInformationFile", "FR", "Enable Browse Information", "",
+ cmVS7FlagTable::UserValueRequired},
+
+ //String List Properties
+ {"AdditionalIncludeDirectories", "I",
+ "Additional Include Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AdditionalUsingDirectories", "AI",
+ "Additional #using Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"PreprocessorDefinitions", "D ",
+ "Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"UndefinePreprocessorDefinitions", "U",
+ "Undefine Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"DisableSpecificWarnings", "wd",
+ "Disable Specific Warnings",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForcedIncludeFiles", "FI",
+ "Forced Include File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForcedUsingFiles", "FU",
+ "Forced #using File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"PREfastLog", "analyze:log",
+ "Code Analysis Log",
+ "", cmVS7FlagTable::UserFollowing},
+ {"PREfastAdditionalPlugins", "analyze:plugin",
+ "Additional Code Analysis Native plugins",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"TreatSpecificWarningsAsErrors", "we",
+ "Treat Specific Warnings As Errors",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {"PreprocessOutputPath", "Fi",
+ "Preprocess Output Path",
+ "", cmVS7FlagTable::UserValue},
+ {"PrecompiledHeaderFile", "Yc",
+ "Precompiled Header Name",
+ "", cmVS7FlagTable::UserValueRequired},
+ {"PrecompiledHeaderFile", "Yu",
+ "Precompiled Header Name",
+ "", cmVS7FlagTable::UserValueRequired},
+ {"PrecompiledHeaderOutputFile", "Fp",
+ "Precompiled Header Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"AssemblerListingLocation", "Fa",
+ "ASM List Location",
+ "", cmVS7FlagTable::UserValue},
+ {"ObjectFileName", "Fo",
+ "Object File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"ProgramDataBaseFileName", "Fd",
+ "Program Database File Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [XMLDocumentationFileName] - no command line Switch.
+ // Skip [BrowseInformationFile] - no command line Switch.
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS12LibFlagTable.h b/Source/cmVS12LibFlagTable.h
new file mode 100644
index 0000000000..10bb8057f5
--- /dev/null
+++ b/Source/cmVS12LibFlagTable.h
@@ -0,0 +1,102 @@
+static cmVS7FlagTable cmVS12LibFlagTable[] =
+{
+
+ //Enum Properties
+ {"ErrorReporting", "ERRORREPORT:PROMPT",
+ "PromptImmediately", "PromptImmediately", 0},
+ {"ErrorReporting", "ERRORREPORT:QUEUE",
+ "Queue For Next Login", "QueueForNextLogin", 0},
+ {"ErrorReporting", "ERRORREPORT:SEND",
+ "Send Error Report", "SendErrorReport", 0},
+ {"ErrorReporting", "ERRORREPORT:NONE",
+ "No Error Report", "NoErrorReport", 0},
+
+ {"TargetMachine", "MACHINE:ARM",
+ "MachineARM", "MachineARM", 0},
+ {"TargetMachine", "MACHINE:EBC",
+ "MachineEBC", "MachineEBC", 0},
+ {"TargetMachine", "MACHINE:IA64",
+ "MachineIA64", "MachineIA64", 0},
+ {"TargetMachine", "MACHINE:MIPS",
+ "MachineMIPS", "MachineMIPS", 0},
+ {"TargetMachine", "MACHINE:MIPS16",
+ "MachineMIPS16", "MachineMIPS16", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU",
+ "MachineMIPSFPU", "MachineMIPSFPU", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU16",
+ "MachineMIPSFPU16", "MachineMIPSFPU16", 0},
+ {"TargetMachine", "MACHINE:SH4",
+ "MachineSH4", "MachineSH4", 0},
+ {"TargetMachine", "MACHINE:THUMB",
+ "MachineTHUMB", "MachineTHUMB", 0},
+ {"TargetMachine", "MACHINE:X64",
+ "MachineX64", "MachineX64", 0},
+ {"TargetMachine", "MACHINE:X86",
+ "MachineX86", "MachineX86", 0},
+
+ {"SubSystem", "SUBSYSTEM:CONSOLE",
+ "Console", "Console", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWS",
+ "Windows", "Windows", 0},
+ {"SubSystem", "SUBSYSTEM:NATIVE",
+ "Native", "Native", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_APPLICATION",
+ "EFI Application", "EFI Application", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER",
+ "EFI Boot Service Driver", "EFI Boot Service Driver", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_ROM",
+ "EFI ROM", "EFI ROM", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_RUNTIME_DRIVER",
+ "EFI Runtime", "EFI Runtime", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWSCE",
+ "WindowsCE", "WindowsCE", 0},
+ {"SubSystem", "SUBSYSTEM:POSIX",
+ "POSIX", "POSIX", 0},
+
+
+ //Bool Properties
+ {"SuppressStartupBanner", "NOLOGO", "", "true", 0},
+ {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "", "true", 0},
+ {"TreatLibWarningAsErrors", "WX:NO", "", "false", 0},
+ {"TreatLibWarningAsErrors", "WX", "", "true", 0},
+ {"Verbose", "VERBOSE", "", "true", 0},
+ {"LinkTimeCodeGeneration", "LTCG", "", "true", 0},
+
+ //Bool Properties With Argument
+
+ //String List Properties
+ // Skip [AdditionalDependencies] - no command line Switch.
+ {"AdditionalLibraryDirectories", "LIBPATH:",
+ "Additional Library Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"IgnoreSpecificDefaultLibraries", "NODEFAULTLIB:",
+ "Ignore Specific Default Libraries",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ExportNamedFunctions", "EXPORT:",
+ "Export Named Functions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"RemoveObjects", "REMOVE:",
+ "Remove Objects",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ {"OutputFile", "OUT:",
+ "Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"ModuleDefinitionFile", "DEF:",
+ "Module Definition File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"ForceSymbolReferences", "INCLUDE:",
+ "Force Symbol References",
+ "", cmVS7FlagTable::UserValue},
+ {"DisplayLibrary", "LIST:",
+ "Display Library to standard output",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [MinimumRequiredVersion] - no command line Switch.
+ {"Name", "NAME:",
+ "Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [AdditionalOptions] - no command line Switch.
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS12LinkFlagTable.h b/Source/cmVS12LinkFlagTable.h
new file mode 100644
index 0000000000..e5a570e7c0
--- /dev/null
+++ b/Source/cmVS12LinkFlagTable.h
@@ -0,0 +1,340 @@
+static cmVS7FlagTable cmVS12LinkFlagTable[] =
+{
+
+ //Enum Properties
+ {"ShowProgress", "",
+ "Not Set", "NotSet", 0},
+ {"ShowProgress", "VERBOSE",
+ "Display all progress messages", "LinkVerbose", 0},
+ {"ShowProgress", "VERBOSE:Lib",
+ "For Libraries Searched", "LinkVerboseLib", 0},
+ {"ShowProgress", "VERBOSE:ICF",
+ "About COMDAT folding during optimized linking", "LinkVerboseICF", 0},
+ {"ShowProgress", "VERBOSE:REF",
+ "About data removed during optimized linking", "LinkVerboseREF", 0},
+ {"ShowProgress", "VERBOSE:SAFESEH",
+ "About Modules incompatible with SEH", "LinkVerboseSAFESEH", 0},
+ {"ShowProgress", "VERBOSE:CLR",
+ "About linker activity related to managed code", "LinkVerboseCLR", 0},
+
+ {"ForceFileOutput", "FORCE",
+ "Enabled", "Enabled", 0},
+ {"ForceFileOutput", "FORCE:MULTIPLE",
+ "Multiply Defined Symbol Only", "MultiplyDefinedSymbolOnly", 0},
+ {"ForceFileOutput", "FORCE:UNRESOLVED",
+ "Undefined Symbol Only", "UndefinedSymbolOnly", 0},
+
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN",
+ "Enabled", "Enabled", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:5",
+ "X86 Image Only", "X86Image", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:6",
+ "X64 Image Only", "X64Image", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:16",
+ "Itanium Image Only", "ItaniumImage", 0},
+
+ {"UACExecutionLevel", "level='asInvoker'",
+ "asInvoker", "AsInvoker", 0},
+ {"UACExecutionLevel", "level='highestAvailable'",
+ "highestAvailable", "HighestAvailable", 0},
+ {"UACExecutionLevel", "level='requireAdministrator'",
+ "requireAdministrator", "RequireAdministrator", 0},
+
+ {"SubSystem", "",
+ "Not Set", "NotSet", 0},
+ {"SubSystem", "SUBSYSTEM:CONSOLE",
+ "Console", "Console", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWS",
+ "Windows", "Windows", 0},
+ {"SubSystem", "SUBSYSTEM:NATIVE",
+ "Native", "Native", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_APPLICATION",
+ "EFI Application", "EFI Application", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER",
+ "EFI Boot Service Driver", "EFI Boot Service Driver", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_ROM",
+ "EFI ROM", "EFI ROM", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_RUNTIME_DRIVER",
+ "EFI Runtime", "EFI Runtime", 0},
+ {"SubSystem", "SUBSYSTEM:POSIX",
+ "POSIX", "POSIX", 0},
+
+ {"Driver", "",
+ "Not Set", "NotSet", 0},
+ {"Driver", "Driver",
+ "Driver", "Driver", 0},
+ {"Driver", "DRIVER:UPONLY",
+ "UP Only", "UpOnly", 0},
+ {"Driver", "DRIVER:WDM",
+ "WDM", "WDM", 0},
+
+ {"LinkTimeCodeGeneration", "",
+ "Default", "Default", 0},
+ {"LinkTimeCodeGeneration", "LTCG",
+ "Use Link Time Code Generation", "UseLinkTimeCodeGeneration", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGInstrument",
+ "Profile Guided Optimization - Instrument", "PGInstrument", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGOptimize",
+ "Profile Guided Optimization - Optimization", "PGOptimization", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGUpdate",
+ "Profile Guided Optimization - Update", "PGUpdate", 0},
+
+ {"GenerateWindowsMetadata", "WINMD",
+ "Yes", "true", 0},
+ {"GenerateWindowsMetadata", "WINMD:NO",
+ "No", "false", 0},
+
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA1",
+ "SHA1", "SHA1", 0},
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA256",
+ "SHA256", "SHA256", 0},
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA384",
+ "SHA384", "SHA384", 0},
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA512",
+ "SHA512", "SHA512", 0},
+
+ {"TargetMachine", "",
+ "Not Set", "NotSet", 0},
+ {"TargetMachine", "MACHINE:ARM",
+ "MachineARM", "MachineARM", 0},
+ {"TargetMachine", "MACHINE:EBC",
+ "MachineEBC", "MachineEBC", 0},
+ {"TargetMachine", "MACHINE:IA64",
+ "MachineIA64", "MachineIA64", 0},
+ {"TargetMachine", "MACHINE:MIPS",
+ "MachineMIPS", "MachineMIPS", 0},
+ {"TargetMachine", "MACHINE:MIPS16",
+ "MachineMIPS16", "MachineMIPS16", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU",
+ "MachineMIPSFPU", "MachineMIPSFPU", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU16",
+ "MachineMIPSFPU16", "MachineMIPSFPU16", 0},
+ {"TargetMachine", "MACHINE:SH4",
+ "MachineSH4", "MachineSH4", 0},
+ {"TargetMachine", "MACHINE:THUMB",
+ "MachineTHUMB", "MachineTHUMB", 0},
+ {"TargetMachine", "MACHINE:X64",
+ "MachineX64", "MachineX64", 0},
+ {"TargetMachine", "MACHINE:X86",
+ "MachineX86", "MachineX86", 0},
+
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:MTA",
+ "MTA threading attribute", "MTAThreadingAttribute", 0},
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:STA",
+ "STA threading attribute", "STAThreadingAttribute", 0},
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:NONE",
+ "Default threading attribute", "DefaultThreadingAttribute", 0},
+
+ {"CLRImageType", "CLRIMAGETYPE:IJW",
+ "Force IJW image", "ForceIJWImage", 0},
+ {"CLRImageType", "CLRIMAGETYPE:PURE",
+ "Force Pure IL Image", "ForcePureILImage", 0},
+ {"CLRImageType", "CLRIMAGETYPE:SAFE",
+ "Force Safe IL Image", "ForceSafeILImage", 0},
+ {"CLRImageType", "",
+ "Default image type", "Default", 0},
+
+ {"SignHash", "CLRSIGNHASH:SHA1",
+ "SHA1", "SHA1", 0},
+ {"SignHash", "CLRSIGNHASH:SHA256",
+ "SHA256", "SHA256", 0},
+ {"SignHash", "CLRSIGNHASH:SHA384",
+ "SHA384", "SHA384", 0},
+ {"SignHash", "CLRSIGNHASH:SHA512",
+ "SHA512", "SHA512", 0},
+
+ {"LinkErrorReporting", "ERRORREPORT:PROMPT",
+ "PromptImmediately", "PromptImmediately", 0},
+ {"LinkErrorReporting", "ERRORREPORT:QUEUE",
+ "Queue For Next Login", "QueueForNextLogin", 0},
+ {"LinkErrorReporting", "ERRORREPORT:SEND",
+ "Send Error Report", "SendErrorReport", 0},
+ {"LinkErrorReporting", "ERRORREPORT:NONE",
+ "No Error Report", "NoErrorReport", 0},
+
+ {"CLRSupportLastError", "CLRSupportLastError",
+ "Enabled", "Enabled", 0},
+ {"CLRSupportLastError", "CLRSupportLastError:NO",
+ "Disabled", "Disabled", 0},
+ {"CLRSupportLastError", "CLRSupportLastError:SYSTEMDLL",
+ "System Dlls Only", "SystemDlls", 0},
+
+
+ //Bool Properties
+ {"LinkIncremental", "INCREMENTAL:NO", "", "false", 0},
+ {"LinkIncremental", "INCREMENTAL", "", "true", 0},
+ {"SuppressStartupBanner", "NOLOGO", "", "true", 0},
+ {"LinkStatus", "LTCG:NOSTATUS", "", "false", 0},
+ {"LinkStatus", "LTCG:STATUS", "", "true", 0},
+ {"PreventDllBinding", "ALLOWBIND:NO", "", "false", 0},
+ {"PreventDllBinding", "ALLOWBIND", "", "true", 0},
+ {"TreatLinkerWarningAsErrors", "WX:NO", "", "false", 0},
+ {"TreatLinkerWarningAsErrors", "WX", "", "true", 0},
+ {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "", "true", 0},
+ {"GenerateManifest", "MANIFEST:NO", "", "false", 0},
+ {"GenerateManifest", "MANIFEST", "", "true", 0},
+ {"AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0},
+ {"UACUIAccess", "uiAccess='false'", "", "false", 0},
+ {"UACUIAccess", "uiAccess='true'", "", "true", 0},
+ {"ManifestEmbed", "manifest:embed", "", "true", 0},
+ {"GenerateDebugInformation", "DEBUG", "", "true", 0},
+ {"MapExports", "MAPINFO:EXPORTS", "", "true", 0},
+ {"AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0},
+ {"AssemblyDebug", "ASSEMBLYDEBUG", "", "true", 0},
+ {"LargeAddressAware", "LARGEADDRESSAWARE:NO", "", "false", 0},
+ {"LargeAddressAware", "LARGEADDRESSAWARE", "", "true", 0},
+ {"TerminalServerAware", "TSAWARE:NO", "", "false", 0},
+ {"TerminalServerAware", "TSAWARE", "", "true", 0},
+ {"SwapRunFromCD", "SWAPRUN:CD", "", "true", 0},
+ {"SwapRunFromNET", "SWAPRUN:NET", "", "true", 0},
+ {"OptimizeReferences", "OPT:NOREF", "", "false", 0},
+ {"OptimizeReferences", "OPT:REF", "", "true", 0},
+ {"EnableCOMDATFolding", "OPT:NOICF", "", "false", 0},
+ {"EnableCOMDATFolding", "OPT:ICF", "", "true", 0},
+ {"IgnoreEmbeddedIDL", "IGNOREIDL", "", "true", 0},
+ {"AppContainer", "APPCONTAINER", "", "true", 0},
+ {"WindowsMetadataLinkDelaySign", "WINMDDELAYSIGN:NO", "", "false", 0},
+ {"WindowsMetadataLinkDelaySign", "WINMDDELAYSIGN", "", "true", 0},
+ {"NoEntryPoint", "NOENTRY", "", "true", 0},
+ {"SetChecksum", "RELEASE", "", "true", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE:NO", "", "false", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE", "", "true", 0},
+ {"FixedBaseAddress", "FIXED:NO", "", "false", 0},
+ {"FixedBaseAddress", "FIXED", "", "true", 0},
+ {"DataExecutionPrevention", "NXCOMPAT:NO", "", "false", 0},
+ {"DataExecutionPrevention", "NXCOMPAT", "", "true", 0},
+ {"TurnOffAssemblyGeneration", "NOASSEMBLY", "", "true", 0},
+ {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
+ {"SupportNobindOfDelayLoadedDLL", "DELAY:NOBIND", "", "true", 0},
+ {"Profile", "PROFILE", "", "true", 0},
+ {"LinkDelaySign", "DELAYSIGN:NO", "", "false", 0},
+ {"LinkDelaySign", "DELAYSIGN", "", "true", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
+ {"DetectOneDefinitionRule", "ODR", "", "true", 0},
+ {"ImageHasSafeExceptionHandlers", "SAFESEH:NO", "", "false", 0},
+ {"ImageHasSafeExceptionHandlers", "SAFESEH", "", "true", 0},
+ {"LinkDLL", "DLL", "", "true", 0},
+
+ //Bool Properties With Argument
+ {"EnableUAC", "MANIFESTUAC:NO", "", "false", 0},
+ {"EnableUAC", "MANIFESTUAC:", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"UACUIAccess", "MANIFESTUAC:", "Enable User Account Control (UAC)", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"GenerateMapFile", "MAP", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"MapFileName", "MAP:", "Generate Map File", "",
+ cmVS7FlagTable::UserValueRequired},
+
+ //String List Properties
+ {"AdditionalLibraryDirectories", "LIBPATH:",
+ "Additional Library Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ // Skip [AdditionalDependencies] - no command line Switch.
+ {"IgnoreSpecificDefaultLibraries", "NODEFAULTLIB:",
+ "Ignore Specific Default Libraries",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AddModuleNamesToAssembly", "ASSEMBLYMODULE:",
+ "Add Module to Assembly",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"EmbedManagedResourceFile", "ASSEMBLYRESOURCE:",
+ "Embed Managed Resource File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForceSymbolReferences", "INCLUDE:",
+ "Force Symbol References",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"DelayLoadDLLs", "DELAYLOAD:",
+ "Delay Loaded Dlls",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AssemblyLinkResource", "ASSEMBLYLINKRESOURCE:",
+ "Assembly Link Resource",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AdditionalManifestDependencies", "MANIFESTDEPENDENCY:",
+ "Additional Manifest Dependencies",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ManifestInput", "manifestinput:",
+ "Manifest Input",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ {"OutputFile", "OUT:",
+ "Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"Version", "VERSION:",
+ "Version",
+ "", cmVS7FlagTable::UserValue},
+ {"SpecifySectionAttributes", "SECTION:",
+ "Specify Section Attributes",
+ "", cmVS7FlagTable::UserValue},
+ {"MSDOSStubFileName", "STUB:",
+ "MS-DOS Stub File Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {"ModuleDefinitionFile", "DEF:",
+ "Module Definition File",
+ "", cmVS7FlagTable::UserValue},
+ {"ManifestFile", "ManifestFile:",
+ "Manifest File",
+ "", cmVS7FlagTable::UserValue},
+ {"ProgramDatabaseFile", "PDB:",
+ "Generate Program Database File",
+ "", cmVS7FlagTable::UserValue},
+ {"StripPrivateSymbols", "PDBSTRIPPED:",
+ "Strip Private Symbols",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [MapFileName] - no command line Switch.
+ // Skip [MinimumRequiredVersion] - no command line Switch.
+ {"HeapReserveSize", "HEAP:",
+ "Heap Reserve Size",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [HeapCommitSize] - no command line Switch.
+ {"StackReserveSize", "STACK:",
+ "Stack Reserve Size",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [StackCommitSize] - no command line Switch.
+ {"FunctionOrder", "ORDER:@",
+ "Function Order",
+ "", cmVS7FlagTable::UserValue},
+ {"ProfileGuidedDatabase", "PGD:",
+ "Profile Guided Database",
+ "", cmVS7FlagTable::UserValue},
+ {"MidlCommandFile", "MIDL:@",
+ "MIDL Commands",
+ "", cmVS7FlagTable::UserValue},
+ {"MergedIDLBaseFileName", "IDLOUT:",
+ "Merged IDL Base File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"TypeLibraryFile", "TLBOUT:",
+ "Type Library",
+ "", cmVS7FlagTable::UserValue},
+ {"WindowsMetadataFile", "WINMDFILE:",
+ "Windows Metadata File",
+ "", cmVS7FlagTable::UserValue},
+ {"WindowsMetadataLinkKeyFile", "WINMDKEYFILE:",
+ "Windows Metadata Key File",
+ "", cmVS7FlagTable::UserValue},
+ {"WindowsMetadataKeyContainer", "WINMDKEYCONTAINER:",
+ "Windows Metadata Key Container",
+ "", cmVS7FlagTable::UserValue},
+ {"EntryPointSymbol", "ENTRY:",
+ "Entry Point",
+ "", cmVS7FlagTable::UserValue},
+ {"BaseAddress", "BASE:",
+ "Base Address",
+ "", cmVS7FlagTable::UserValue},
+ {"ImportLibrary", "IMPLIB:",
+ "Import Library",
+ "", cmVS7FlagTable::UserValue},
+ {"MergeSections", "MERGE:",
+ "Merge Sections",
+ "", cmVS7FlagTable::UserValue},
+ {"LinkKeyFile", "KEYFILE:",
+ "Key File",
+ "", cmVS7FlagTable::UserValue},
+ {"KeyContainer", "KEYCONTAINER:",
+ "Key Container",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS12MASMFlagTable.h b/Source/cmVS12MASMFlagTable.h
new file mode 100644
index 0000000000..74d529c064
--- /dev/null
+++ b/Source/cmVS12MASMFlagTable.h
@@ -0,0 +1,96 @@
+static cmVS7FlagTable cmVS12MASMFlagTable[] =
+{
+
+ //Enum Properties
+ {"PreserveIdentifierCase", "",
+ "Default", "0", 0},
+ {"PreserveIdentifierCase", "/Cp",
+ "Preserves Identifier Case (/Cp)", "1", 0},
+ {"PreserveIdentifierCase", "/Cu",
+ "Maps all identifiers to upper case. (/Cu)", "2", 0},
+ {"PreserveIdentifierCase", "/Cx",
+ "Preserves case in public and extern symbols. (/Cx)", "3", 0},
+
+ {"WarningLevel", "/W0",
+ "Warning Level 0 (/W0)", "0", 0},
+ {"WarningLevel", "/W1",
+ "Warning Level 1 (/W1)", "1", 0},
+ {"WarningLevel", "/W2",
+ "Warning Level 2 (/W2)", "2", 0},
+ {"WarningLevel", "/W3",
+ "Warning Level 3 (/W3)", "3", 0},
+
+ {"PackAlignmentBoundary", "",
+ "Default", "0", 0},
+ {"PackAlignmentBoundary", "/Zp1",
+ "One Byte Boundary (/Zp1)", "1", 0},
+ {"PackAlignmentBoundary", "/Zp2",
+ "Two Byte Boundary (/Zp2)", "2", 0},
+ {"PackAlignmentBoundary", "/Zp4",
+ "Four Byte Boundary (/Zp4)", "3", 0},
+ {"PackAlignmentBoundary", "/Zp8",
+ "Eight Byte Boundary (/Zp8)", "4", 0},
+ {"PackAlignmentBoundary", "/Zp16",
+ "Sixteen Byte Boundary (/Zp16)", "5", 0},
+
+ {"CallingConvention", "",
+ "Default", "0", 0},
+ {"CallingConvention", "/Gd",
+ "Use C-style Calling Convention (/Gd)", "1", 0},
+ {"CallingConvention", "/Gz",
+ "Use stdcall Calling Convention (/Gz)", "2", 0},
+ {"CallingConvention", "/Gc",
+ "Use Pascal Calling Convention (/Gc)", "3", 0},
+
+ {"ErrorReporting", "/errorReport:prompt",
+ "Prompt to send report immediately (/errorReport:prompt)", "0", 0},
+ {"ErrorReporting", "/errorReport:queue",
+ "Prompt to send report at the next logon (/errorReport:queue)", "1", 0},
+ {"ErrorReporting", "/errorReport:send",
+ "Automatically send report (/errorReport:send)", "2", 0},
+ {"ErrorReporting", "/errorReport:none",
+ "Do not send report (/errorReport:none)", "3", 0},
+
+
+ //Bool Properties
+ {"NoLogo", "/nologo", "", "true", 0},
+ {"GeneratePreprocessedSourceListing", "/EP", "", "true", 0},
+ {"ListAllAvailableInformation", "/Sa", "", "true", 0},
+ {"UseSafeExceptionHandlers", "/safeseh", "", "true", 0},
+ {"AddFirstPassListing", "/Sf", "", "true", 0},
+ {"EnableAssemblyGeneratedCodeListing", "/Sg", "", "true", 0},
+ {"DisableSymbolTable", "/Sn", "", "true", 0},
+ {"EnableFalseConditionalsInListing", "/Sx", "", "true", 0},
+ {"TreatWarningsAsErrors", "/WX", "", "true", 0},
+ {"MakeAllSymbolsPublic", "/Zf", "", "true", 0},
+ {"GenerateDebugInformation", "/Zi", "", "true", 0},
+ {"EnableMASM51Compatibility", "/Zm", "", "true", 0},
+ {"PerformSyntaxCheckOnly", "/Zs", "", "true", 0},
+
+ //Bool Properties With Argument
+
+ //String List Properties
+ {"PreprocessorDefinitions", "/D",
+ "Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"IncludePaths", "/I",
+ "Include Paths",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"BrowseFile", "/FR",
+ "Generate Browse Information File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ // Skip [AdditionalDependencies] - no command line Switch.
+
+ //String Properties
+ // Skip [Inputs] - no command line Switch.
+ {"ObjectFileName", "/Fo",
+ "Object File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"AssembledCodeListingFile", "/Fl",
+ "Assembled Code Listing File",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [CommandLineTemplate] - no command line Switch.
+ // Skip [ExecutionDescription] - no command line Switch.
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS12RCFlagTable.h b/Source/cmVS12RCFlagTable.h
new file mode 100644
index 0000000000..1551c66f92
--- /dev/null
+++ b/Source/cmVS12RCFlagTable.h
@@ -0,0 +1,7 @@
+static cmVS7FlagTable cmVS12RCFlagTable[] =
+{
+ //Bool Properties
+ {"NullTerminateStrings", "n", "", "true", 0},
+
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS14CLFlagTable.h b/Source/cmVS14CLFlagTable.h
new file mode 100644
index 0000000000..422f47b435
--- /dev/null
+++ b/Source/cmVS14CLFlagTable.h
@@ -0,0 +1,296 @@
+static cmVS7FlagTable cmVS14CLFlagTable[] =
+{
+
+ //Enum Properties
+ {"DebugInformationFormat", "",
+ "None", "None", 0},
+ {"DebugInformationFormat", "Z7",
+ "C7 compatible", "OldStyle", 0},
+ {"DebugInformationFormat", "Zi",
+ "Program Database", "ProgramDatabase", 0},
+ {"DebugInformationFormat", "ZI",
+ "Program Database for Edit And Continue", "EditAndContinue", 0},
+
+ {"WarningLevel", "W0",
+ "Turn Off All Warnings", "TurnOffAllWarnings", 0},
+ {"WarningLevel", "W1",
+ "Level1", "Level1", 0},
+ {"WarningLevel", "W2",
+ "Level2", "Level2", 0},
+ {"WarningLevel", "W3",
+ "Level3", "Level3", 0},
+ {"WarningLevel", "W4",
+ "Level4", "Level4", 0},
+ {"WarningLevel", "Wall",
+ "EnableAllWarnings", "EnableAllWarnings", 0},
+
+ {"Optimization", "",
+ "Custom", "Custom", 0},
+ {"Optimization", "Od",
+ "Disabled", "Disabled", 0},
+ {"Optimization", "O1",
+ "Minimize Size", "MinSpace", 0},
+ {"Optimization", "O2",
+ "Maximize Speed", "MaxSpeed", 0},
+ {"Optimization", "Ox",
+ "Full Optimization", "Full", 0},
+
+ {"InlineFunctionExpansion", "",
+ "Default", "Default", 0},
+ {"InlineFunctionExpansion", "Ob0",
+ "Disabled", "Disabled", 0},
+ {"InlineFunctionExpansion", "Ob1",
+ "Only __inline", "OnlyExplicitInline", 0},
+ {"InlineFunctionExpansion", "Ob2",
+ "Any Suitable", "AnySuitable", 0},
+
+ {"FavorSizeOrSpeed", "Os",
+ "Favor small code", "Size", 0},
+ {"FavorSizeOrSpeed", "Ot",
+ "Favor fast code", "Speed", 0},
+ {"FavorSizeOrSpeed", "",
+ "Neither", "Neither", 0},
+
+ {"ExceptionHandling", "EHa",
+ "Yes with SEH Exceptions", "Async", 0},
+ {"ExceptionHandling", "EHsc",
+ "Yes", "Sync", 0},
+ {"ExceptionHandling", "EHs",
+ "Yes with Extern C functions", "SyncCThrow", 0},
+ {"ExceptionHandling", "",
+ "No", "false", 0},
+
+ {"BasicRuntimeChecks", "RTCs",
+ "Stack Frames", "StackFrameRuntimeCheck", 0},
+ {"BasicRuntimeChecks", "RTCu",
+ "Uninitialized variables", "UninitializedLocalUsageCheck", 0},
+ {"BasicRuntimeChecks", "RTC1",
+ "Both (/RTC1, equiv. to /RTCsu)", "EnableFastChecks", 0},
+ {"BasicRuntimeChecks", "",
+ "Default", "Default", 0},
+
+ {"RuntimeLibrary", "MT",
+ "Multi-threaded", "MultiThreaded", 0},
+ {"RuntimeLibrary", "MTd",
+ "Multi-threaded Debug", "MultiThreadedDebug", 0},
+ {"RuntimeLibrary", "MD",
+ "Multi-threaded DLL", "MultiThreadedDLL", 0},
+ {"RuntimeLibrary", "MDd",
+ "Multi-threaded Debug DLL", "MultiThreadedDebugDLL", 0},
+
+ {"StructMemberAlignment", "Zp1",
+ "1 Byte", "1Byte", 0},
+ {"StructMemberAlignment", "Zp2",
+ "2 Bytes", "2Bytes", 0},
+ {"StructMemberAlignment", "Zp4",
+ "4 Byte", "4Bytes", 0},
+ {"StructMemberAlignment", "Zp8",
+ "8 Bytes", "8Bytes", 0},
+ {"StructMemberAlignment", "Zp16",
+ "16 Bytes", "16Bytes", 0},
+ {"StructMemberAlignment", "",
+ "Default", "Default", 0},
+
+ {"BufferSecurityCheck", "GS-",
+ "Disable Security Check", "false", 0},
+ {"BufferSecurityCheck", "GS",
+ "Enable Security Check", "true", 0},
+
+ {"EnableEnhancedInstructionSet", "arch:SSE",
+ "Streaming SIMD Extensions", "StreamingSIMDExtensions", 0},
+ {"EnableEnhancedInstructionSet", "arch:SSE2",
+ "Streaming SIMD Extensions 2", "StreamingSIMDExtensions2", 0},
+ {"EnableEnhancedInstructionSet", "arch:AVX",
+ "Advanced Vector Extensions", "AdvancedVectorExtensions", 0},
+ {"EnableEnhancedInstructionSet", "arch:AVX2",
+ "Advanced Vector Extensions 2", "AdvancedVectorExtensions2", 0},
+ {"EnableEnhancedInstructionSet", "arch:IA32",
+ "No Enhanced Instructions", "NoExtensions", 0},
+ {"EnableEnhancedInstructionSet", "",
+ "Not Set", "NotSet", 0},
+
+ {"FloatingPointModel", "fp:precise",
+ "Precise", "Precise", 0},
+ {"FloatingPointModel", "fp:strict",
+ "Strict", "Strict", 0},
+ {"FloatingPointModel", "fp:fast",
+ "Fast", "Fast", 0},
+
+ {"PrecompiledHeader", "Yc",
+ "Create", "Create",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeader", "Yu",
+ "Use", "Use",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"PrecompiledHeader", "",
+ "Not Using Precompiled Headers", "NotUsing", 0},
+
+ {"AssemblerOutput", "",
+ "No Listing", "NoListing", 0},
+ {"AssemblerOutput", "FA",
+ "Assembly-Only Listing", "AssemblyCode", 0},
+ {"AssemblerOutput", "FAc",
+ "Assembly With Machine Code", "AssemblyAndMachineCode", 0},
+ {"AssemblerOutput", "FAs",
+ "Assembly With Source Code", "AssemblyAndSourceCode", 0},
+ {"AssemblerOutput", "FAcs",
+ "Assembly, Machine Code and Source", "All", 0},
+
+ {"CallingConvention", "Gd",
+ "__cdecl", "Cdecl", 0},
+ {"CallingConvention", "Gr",
+ "__fastcall", "FastCall", 0},
+ {"CallingConvention", "Gz",
+ "__stdcall", "StdCall", 0},
+ {"CallingConvention", "Gv",
+ "__vectorcall", "VectorCall", 0},
+
+ {"CompileAs", "",
+ "Default", "Default", 0},
+ {"CompileAs", "TC",
+ "Compile as C Code", "CompileAsC", 0},
+ {"CompileAs", "TP",
+ "Compile as C++ Code", "CompileAsCpp", 0},
+
+ {"ErrorReporting", "errorReport:none",
+ "Do Not Send Report", "None", 0},
+ {"ErrorReporting", "errorReport:prompt",
+ "Prompt Immediately", "Prompt", 0},
+ {"ErrorReporting", "errorReport:queue",
+ "Queue For Next Login", "Queue", 0},
+ {"ErrorReporting", "errorReport:send",
+ "Send Automatically", "Send", 0},
+
+ {"CompileAsManaged", "",
+ "No Common Language RunTime Support", "false", 0},
+ {"CompileAsManaged", "clr",
+ "Common Language RunTime Support", "true", 0},
+ {"CompileAsManaged", "clr:pure",
+ "Pure MSIL Common Language RunTime Support", "Pure", 0},
+ {"CompileAsManaged", "clr:safe",
+ "Safe MSIL Common Language RunTime Support", "Safe", 0},
+ {"CompileAsManaged", "clr:oldSyntax",
+ "Common Language RunTime Support, Old Syntax", "OldSyntax", 0},
+
+
+ //Bool Properties
+ {"CompileAsWinRT", "ZW", "", "true", 0},
+ {"WinRTNoStdLib", "ZW:nostdlib", "", "true", 0},
+ {"SuppressStartupBanner", "nologo", "", "true", 0},
+ {"TreatWarningAsError", "WX-", "", "false", 0},
+ {"TreatWarningAsError", "WX", "", "true", 0},
+ {"SDLCheck", "sdl-", "", "false", 0},
+ {"SDLCheck", "sdl", "", "true", 0},
+ {"IntrinsicFunctions", "Oi", "", "true", 0},
+ {"OmitFramePointers", "Oy-", "", "false", 0},
+ {"OmitFramePointers", "Oy", "", "true", 0},
+ {"EnableFiberSafeOptimizations", "GT", "", "true", 0},
+ {"WholeProgramOptimization", "GL", "", "true", 0},
+ {"UndefineAllPreprocessorDefinitions", "u", "", "true", 0},
+ {"IgnoreStandardIncludePath", "X", "", "true", 0},
+ {"PreprocessToFile", "P", "", "true", 0},
+ {"PreprocessSuppressLineNumbers", "EP", "", "true", 0},
+ {"PreprocessKeepComments", "C", "", "true", 0},
+ {"StringPooling", "GF-", "", "false", 0},
+ {"StringPooling", "GF", "", "true", 0},
+ {"MinimalRebuild", "Gm-", "", "false", 0},
+ {"MinimalRebuild", "Gm", "", "true", 0},
+ {"SmallerTypeCheck", "RTCc", "", "true", 0},
+ {"FunctionLevelLinking", "Gy-", "", "false", 0},
+ {"FunctionLevelLinking", "Gy", "", "true", 0},
+ {"EnableParallelCodeGeneration", "Qpar-", "", "false", 0},
+ {"EnableParallelCodeGeneration", "Qpar", "", "true", 0},
+ {"FloatingPointExceptions", "fp:except-", "", "false", 0},
+ {"FloatingPointExceptions", "fp:except", "", "true", 0},
+ {"CreateHotpatchableImage", "hotpatch", "", "true", 0},
+ {"DisableLanguageExtensions", "Za", "", "true", 0},
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t-", "", "false", 0},
+ {"TreatWChar_tAsBuiltInType", "Zc:wchar_t", "", "true", 0},
+ {"ForceConformanceInForLoopScope", "Zc:forScope-", "", "false", 0},
+ {"ForceConformanceInForLoopScope", "Zc:forScope", "", "true", 0},
+ {"RuntimeTypeInfo", "GR-", "", "false", 0},
+ {"RuntimeTypeInfo", "GR", "", "true", 0},
+ {"OpenMPSupport", "openmp-", "", "false", 0},
+ {"OpenMPSupport", "openmp", "", "true", 0},
+ {"ExpandAttributedSource", "Fx", "", "true", 0},
+ {"UseUnicodeForAssemblerListing", "FAu", "", "true", 0},
+ {"ShowIncludes", "showIncludes", "", "true", 0},
+ {"EnablePREfast", "analyze-", "", "false", 0},
+ {"EnablePREfast", "analyze", "", "true", 0},
+ {"UseFullPaths", "FC", "", "true", 0},
+ {"OmitDefaultLibName", "Zl", "", "true", 0},
+
+ //Bool Properties With Argument
+ {"MultiProcessorCompilation", "MP", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"ProcessorNumber", "MP", "Multi-processor Compilation", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"GenerateXMLDocumentationFiles", "doc", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"XMLDocumentationFileName", "doc", "Generate XML Documentation Files", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"BrowseInformation", "FR", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"BrowseInformationFile", "FR", "Enable Browse Information", "",
+ cmVS7FlagTable::UserValueRequired},
+
+ //String List Properties
+ {"AdditionalIncludeDirectories", "I",
+ "Additional Include Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AdditionalUsingDirectories", "AI",
+ "Additional #using Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"PreprocessorDefinitions", "D ",
+ "Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"UndefinePreprocessorDefinitions", "U",
+ "Undefine Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"DisableSpecificWarnings", "wd",
+ "Disable Specific Warnings",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForcedIncludeFiles", "FI",
+ "Forced Include File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForcedUsingFiles", "FU",
+ "Forced #using File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"PREfastLog", "analyze:log",
+ "Code Analysis Log",
+ "", cmVS7FlagTable::UserFollowing},
+ {"PREfastAdditionalPlugins", "analyze:plugin",
+ "Additional Code Analysis Native plugins",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"TreatSpecificWarningsAsErrors", "we",
+ "Treat Specific Warnings As Errors",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {"PreprocessOutputPath", "Fi",
+ "Preprocess Output Path",
+ "", cmVS7FlagTable::UserValue},
+ {"PrecompiledHeaderFile", "Yc",
+ "Precompiled Header Name",
+ "", cmVS7FlagTable::UserValueRequired},
+ {"PrecompiledHeaderFile", "Yu",
+ "Precompiled Header Name",
+ "", cmVS7FlagTable::UserValueRequired},
+ {"PrecompiledHeaderOutputFile", "Fp",
+ "Precompiled Header Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"AssemblerListingLocation", "Fa",
+ "ASM List Location",
+ "", cmVS7FlagTable::UserValue},
+ {"ObjectFileName", "Fo",
+ "Object File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"ProgramDataBaseFileName", "Fd",
+ "Program Database File Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [XMLDocumentationFileName] - no command line Switch.
+ // Skip [BrowseInformationFile] - no command line Switch.
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS14LibFlagTable.h b/Source/cmVS14LibFlagTable.h
new file mode 100644
index 0000000000..a33f273bb8
--- /dev/null
+++ b/Source/cmVS14LibFlagTable.h
@@ -0,0 +1,102 @@
+static cmVS7FlagTable cmVS14LibFlagTable[] =
+{
+
+ //Enum Properties
+ {"ErrorReporting", "ERRORREPORT:PROMPT",
+ "PromptImmediately", "PromptImmediately", 0},
+ {"ErrorReporting", "ERRORREPORT:QUEUE",
+ "Queue For Next Login", "QueueForNextLogin", 0},
+ {"ErrorReporting", "ERRORREPORT:SEND",
+ "Send Error Report", "SendErrorReport", 0},
+ {"ErrorReporting", "ERRORREPORT:NONE",
+ "No Error Report", "NoErrorReport", 0},
+
+ {"TargetMachine", "MACHINE:ARM",
+ "MachineARM", "MachineARM", 0},
+ {"TargetMachine", "MACHINE:EBC",
+ "MachineEBC", "MachineEBC", 0},
+ {"TargetMachine", "MACHINE:IA64",
+ "MachineIA64", "MachineIA64", 0},
+ {"TargetMachine", "MACHINE:MIPS",
+ "MachineMIPS", "MachineMIPS", 0},
+ {"TargetMachine", "MACHINE:MIPS16",
+ "MachineMIPS16", "MachineMIPS16", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU",
+ "MachineMIPSFPU", "MachineMIPSFPU", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU16",
+ "MachineMIPSFPU16", "MachineMIPSFPU16", 0},
+ {"TargetMachine", "MACHINE:SH4",
+ "MachineSH4", "MachineSH4", 0},
+ {"TargetMachine", "MACHINE:THUMB",
+ "MachineTHUMB", "MachineTHUMB", 0},
+ {"TargetMachine", "MACHINE:X64",
+ "MachineX64", "MachineX64", 0},
+ {"TargetMachine", "MACHINE:X86",
+ "MachineX86", "MachineX86", 0},
+
+ {"SubSystem", "SUBSYSTEM:CONSOLE",
+ "Console", "Console", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWS",
+ "Windows", "Windows", 0},
+ {"SubSystem", "SUBSYSTEM:NATIVE",
+ "Native", "Native", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_APPLICATION",
+ "EFI Application", "EFI Application", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER",
+ "EFI Boot Service Driver", "EFI Boot Service Driver", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_ROM",
+ "EFI ROM", "EFI ROM", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_RUNTIME_DRIVER",
+ "EFI Runtime", "EFI Runtime", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWSCE",
+ "WindowsCE", "WindowsCE", 0},
+ {"SubSystem", "SUBSYSTEM:POSIX",
+ "POSIX", "POSIX", 0},
+
+
+ //Bool Properties
+ {"SuppressStartupBanner", "NOLOGO", "", "true", 0},
+ {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "", "true", 0},
+ {"TreatLibWarningAsErrors", "WX:NO", "", "false", 0},
+ {"TreatLibWarningAsErrors", "WX", "", "true", 0},
+ {"Verbose", "VERBOSE", "", "true", 0},
+ {"LinkTimeCodeGeneration", "LTCG", "", "true", 0},
+
+ //Bool Properties With Argument
+
+ //String List Properties
+ // Skip [AdditionalDependencies] - no command line Switch.
+ {"AdditionalLibraryDirectories", "LIBPATH:",
+ "Additional Library Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"IgnoreSpecificDefaultLibraries", "NODEFAULTLIB:",
+ "Ignore Specific Default Libraries",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ExportNamedFunctions", "EXPORT:",
+ "Export Named Functions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"RemoveObjects", "REMOVE:",
+ "Remove Objects",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ {"OutputFile", "OUT:",
+ "Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"ModuleDefinitionFile", "DEF:",
+ "Module Definition File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"ForceSymbolReferences", "INCLUDE:",
+ "Force Symbol References",
+ "", cmVS7FlagTable::UserValue},
+ {"DisplayLibrary", "LIST:",
+ "Display Library to standard output",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [MinimumRequiredVersion] - no command line Switch.
+ {"Name", "NAME:",
+ "Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [AdditionalOptions] - no command line Switch.
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS14LinkFlagTable.h b/Source/cmVS14LinkFlagTable.h
new file mode 100644
index 0000000000..6d81d125f3
--- /dev/null
+++ b/Source/cmVS14LinkFlagTable.h
@@ -0,0 +1,340 @@
+static cmVS7FlagTable cmVS14LinkFlagTable[] =
+{
+
+ //Enum Properties
+ {"ShowProgress", "",
+ "Not Set", "NotSet", 0},
+ {"ShowProgress", "VERBOSE",
+ "Display all progress messages", "LinkVerbose", 0},
+ {"ShowProgress", "VERBOSE:Lib",
+ "For Libraries Searched", "LinkVerboseLib", 0},
+ {"ShowProgress", "VERBOSE:ICF",
+ "About COMDAT folding during optimized linking", "LinkVerboseICF", 0},
+ {"ShowProgress", "VERBOSE:REF",
+ "About data removed during optimized linking", "LinkVerboseREF", 0},
+ {"ShowProgress", "VERBOSE:SAFESEH",
+ "About Modules incompatible with SEH", "LinkVerboseSAFESEH", 0},
+ {"ShowProgress", "VERBOSE:CLR",
+ "About linker activity related to managed code", "LinkVerboseCLR", 0},
+
+ {"ForceFileOutput", "FORCE",
+ "Enabled", "Enabled", 0},
+ {"ForceFileOutput", "FORCE:MULTIPLE",
+ "Multiply Defined Symbol Only", "MultiplyDefinedSymbolOnly", 0},
+ {"ForceFileOutput", "FORCE:UNRESOLVED",
+ "Undefined Symbol Only", "UndefinedSymbolOnly", 0},
+
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN",
+ "Enabled", "Enabled", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:5",
+ "X86 Image Only", "X86Image", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:6",
+ "X64 Image Only", "X64Image", 0},
+ {"CreateHotPatchableImage", "FUNCTIONPADMIN:16",
+ "Itanium Image Only", "ItaniumImage", 0},
+
+ {"UACExecutionLevel", "level='asInvoker'",
+ "asInvoker", "AsInvoker", 0},
+ {"UACExecutionLevel", "level='highestAvailable'",
+ "highestAvailable", "HighestAvailable", 0},
+ {"UACExecutionLevel", "level='requireAdministrator'",
+ "requireAdministrator", "RequireAdministrator", 0},
+
+ {"SubSystem", "",
+ "Not Set", "NotSet", 0},
+ {"SubSystem", "SUBSYSTEM:CONSOLE",
+ "Console", "Console", 0},
+ {"SubSystem", "SUBSYSTEM:WINDOWS",
+ "Windows", "Windows", 0},
+ {"SubSystem", "SUBSYSTEM:NATIVE",
+ "Native", "Native", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_APPLICATION",
+ "EFI Application", "EFI Application", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER",
+ "EFI Boot Service Driver", "EFI Boot Service Driver", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_ROM",
+ "EFI ROM", "EFI ROM", 0},
+ {"SubSystem", "SUBSYSTEM:EFI_RUNTIME_DRIVER",
+ "EFI Runtime", "EFI Runtime", 0},
+ {"SubSystem", "SUBSYSTEM:POSIX",
+ "POSIX", "POSIX", 0},
+
+ {"Driver", "",
+ "Not Set", "NotSet", 0},
+ {"Driver", "Driver",
+ "Driver", "Driver", 0},
+ {"Driver", "DRIVER:UPONLY",
+ "UP Only", "UpOnly", 0},
+ {"Driver", "DRIVER:WDM",
+ "WDM", "WDM", 0},
+
+ {"LinkTimeCodeGeneration", "",
+ "Default", "Default", 0},
+ {"LinkTimeCodeGeneration", "LTCG",
+ "Use Link Time Code Generation", "UseLinkTimeCodeGeneration", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGInstrument",
+ "Profile Guided Optimization - Instrument", "PGInstrument", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGOptimize",
+ "Profile Guided Optimization - Optimization", "PGOptimization", 0},
+ {"LinkTimeCodeGeneration", "LTCG:PGUpdate",
+ "Profile Guided Optimization - Update", "PGUpdate", 0},
+
+ {"GenerateWindowsMetadata", "WINMD",
+ "Yes", "true", 0},
+ {"GenerateWindowsMetadata", "WINMD:NO",
+ "No", "false", 0},
+
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA1",
+ "SHA1", "SHA1", 0},
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA256",
+ "SHA256", "SHA256", 0},
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA384",
+ "SHA384", "SHA384", 0},
+ {"WindowsMetadataSignHash", "WINMDSIGNHASH:SHA512",
+ "SHA512", "SHA512", 0},
+
+ {"TargetMachine", "",
+ "Not Set", "NotSet", 0},
+ {"TargetMachine", "MACHINE:ARM",
+ "MachineARM", "MachineARM", 0},
+ {"TargetMachine", "MACHINE:EBC",
+ "MachineEBC", "MachineEBC", 0},
+ {"TargetMachine", "MACHINE:IA64",
+ "MachineIA64", "MachineIA64", 0},
+ {"TargetMachine", "MACHINE:MIPS",
+ "MachineMIPS", "MachineMIPS", 0},
+ {"TargetMachine", "MACHINE:MIPS16",
+ "MachineMIPS16", "MachineMIPS16", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU",
+ "MachineMIPSFPU", "MachineMIPSFPU", 0},
+ {"TargetMachine", "MACHINE:MIPSFPU16",
+ "MachineMIPSFPU16", "MachineMIPSFPU16", 0},
+ {"TargetMachine", "MACHINE:SH4",
+ "MachineSH4", "MachineSH4", 0},
+ {"TargetMachine", "MACHINE:THUMB",
+ "MachineTHUMB", "MachineTHUMB", 0},
+ {"TargetMachine", "MACHINE:X64",
+ "MachineX64", "MachineX64", 0},
+ {"TargetMachine", "MACHINE:X86",
+ "MachineX86", "MachineX86", 0},
+
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:MTA",
+ "MTA threading attribute", "MTAThreadingAttribute", 0},
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:STA",
+ "STA threading attribute", "STAThreadingAttribute", 0},
+ {"CLRThreadAttribute", "CLRTHREADATTRIBUTE:NONE",
+ "Default threading attribute", "DefaultThreadingAttribute", 0},
+
+ {"CLRImageType", "CLRIMAGETYPE:IJW",
+ "Force IJW image", "ForceIJWImage", 0},
+ {"CLRImageType", "CLRIMAGETYPE:PURE",
+ "Force Pure IL Image", "ForcePureILImage", 0},
+ {"CLRImageType", "CLRIMAGETYPE:SAFE",
+ "Force Safe IL Image", "ForceSafeILImage", 0},
+ {"CLRImageType", "",
+ "Default image type", "Default", 0},
+
+ {"SignHash", "CLRSIGNHASH:SHA1",
+ "SHA1", "SHA1", 0},
+ {"SignHash", "CLRSIGNHASH:SHA256",
+ "SHA256", "SHA256", 0},
+ {"SignHash", "CLRSIGNHASH:SHA384",
+ "SHA384", "SHA384", 0},
+ {"SignHash", "CLRSIGNHASH:SHA512",
+ "SHA512", "SHA512", 0},
+
+ {"LinkErrorReporting", "ERRORREPORT:PROMPT",
+ "PromptImmediately", "PromptImmediately", 0},
+ {"LinkErrorReporting", "ERRORREPORT:QUEUE",
+ "Queue For Next Login", "QueueForNextLogin", 0},
+ {"LinkErrorReporting", "ERRORREPORT:SEND",
+ "Send Error Report", "SendErrorReport", 0},
+ {"LinkErrorReporting", "ERRORREPORT:NONE",
+ "No Error Report", "NoErrorReport", 0},
+
+ {"CLRSupportLastError", "CLRSupportLastError",
+ "Enabled", "Enabled", 0},
+ {"CLRSupportLastError", "CLRSupportLastError:NO",
+ "Disabled", "Disabled", 0},
+ {"CLRSupportLastError", "CLRSupportLastError:SYSTEMDLL",
+ "System Dlls Only", "SystemDlls", 0},
+
+
+ //Bool Properties
+ {"LinkIncremental", "INCREMENTAL:NO", "", "false", 0},
+ {"LinkIncremental", "INCREMENTAL", "", "true", 0},
+ {"SuppressStartupBanner", "NOLOGO", "", "true", 0},
+ {"LinkStatus", "LTCG:NOSTATUS", "", "false", 0},
+ {"LinkStatus", "LTCG:STATUS", "", "true", 0},
+ {"PreventDllBinding", "ALLOWBIND:NO", "", "false", 0},
+ {"PreventDllBinding", "ALLOWBIND", "", "true", 0},
+ {"TreatLinkerWarningAsErrors", "WX:NO", "", "false", 0},
+ {"TreatLinkerWarningAsErrors", "WX", "", "true", 0},
+ {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "", "true", 0},
+ {"GenerateManifest", "MANIFEST:NO", "", "false", 0},
+ {"GenerateManifest", "MANIFEST", "", "true", 0},
+ {"AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0},
+ {"UACUIAccess", "uiAccess='false'", "", "false", 0},
+ {"UACUIAccess", "uiAccess='true'", "", "true", 0},
+ {"ManifestEmbed", "manifest:embed", "", "true", 0},
+ {"GenerateDebugInformation", "DEBUG", "", "true", 0},
+ {"MapExports", "MAPINFO:EXPORTS", "", "true", 0},
+ {"AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0},
+ {"AssemblyDebug", "ASSEMBLYDEBUG", "", "true", 0},
+ {"LargeAddressAware", "LARGEADDRESSAWARE:NO", "", "false", 0},
+ {"LargeAddressAware", "LARGEADDRESSAWARE", "", "true", 0},
+ {"TerminalServerAware", "TSAWARE:NO", "", "false", 0},
+ {"TerminalServerAware", "TSAWARE", "", "true", 0},
+ {"SwapRunFromCD", "SWAPRUN:CD", "", "true", 0},
+ {"SwapRunFromNET", "SWAPRUN:NET", "", "true", 0},
+ {"OptimizeReferences", "OPT:NOREF", "", "false", 0},
+ {"OptimizeReferences", "OPT:REF", "", "true", 0},
+ {"EnableCOMDATFolding", "OPT:NOICF", "", "false", 0},
+ {"EnableCOMDATFolding", "OPT:ICF", "", "true", 0},
+ {"IgnoreEmbeddedIDL", "IGNOREIDL", "", "true", 0},
+ {"AppContainer", "APPCONTAINER", "", "true", 0},
+ {"WindowsMetadataLinkDelaySign", "WINMDDELAYSIGN:NO", "", "false", 0},
+ {"WindowsMetadataLinkDelaySign", "WINMDDELAYSIGN", "", "true", 0},
+ {"NoEntryPoint", "NOENTRY", "", "true", 0},
+ {"SetChecksum", "RELEASE", "", "true", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE:NO", "", "false", 0},
+ {"RandomizedBaseAddress", "DYNAMICBASE", "", "true", 0},
+ {"FixedBaseAddress", "FIXED:NO", "", "false", 0},
+ {"FixedBaseAddress", "FIXED", "", "true", 0},
+ {"DataExecutionPrevention", "NXCOMPAT:NO", "", "false", 0},
+ {"DataExecutionPrevention", "NXCOMPAT", "", "true", 0},
+ {"TurnOffAssemblyGeneration", "NOASSEMBLY", "", "true", 0},
+ {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
+ {"SupportNobindOfDelayLoadedDLL", "DELAY:NOBIND", "", "true", 0},
+ {"Profile", "PROFILE", "", "true", 0},
+ {"LinkDelaySign", "DELAYSIGN:NO", "", "false", 0},
+ {"LinkDelaySign", "DELAYSIGN", "", "true", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
+ {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
+ {"DetectOneDefinitionRule", "ODR", "", "true", 0},
+ {"ImageHasSafeExceptionHandlers", "SAFESEH:NO", "", "false", 0},
+ {"ImageHasSafeExceptionHandlers", "SAFESEH", "", "true", 0},
+ {"LinkDLL", "DLL", "", "true", 0},
+
+ //Bool Properties With Argument
+ {"EnableUAC", "MANIFESTUAC:NO", "", "false", 0},
+ {"EnableUAC", "MANIFESTUAC:", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"UACUIAccess", "MANIFESTUAC:", "Enable User Account Control (UAC)", "",
+ cmVS7FlagTable::UserValueRequired},
+ {"GenerateMapFile", "MAP", "", "true",
+ cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
+ {"MapFileName", "MAP:", "Generate Map File", "",
+ cmVS7FlagTable::UserValueRequired},
+
+ //String List Properties
+ {"AdditionalLibraryDirectories", "LIBPATH:",
+ "Additional Library Directories",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ // Skip [AdditionalDependencies] - no command line Switch.
+ {"IgnoreSpecificDefaultLibraries", "NODEFAULTLIB:",
+ "Ignore Specific Default Libraries",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AddModuleNamesToAssembly", "ASSEMBLYMODULE:",
+ "Add Module to Assembly",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"EmbedManagedResourceFile", "ASSEMBLYRESOURCE:",
+ "Embed Managed Resource File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ForceSymbolReferences", "INCLUDE:",
+ "Force Symbol References",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"DelayLoadDLLs", "DELAYLOAD:",
+ "Delay Loaded Dlls",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AssemblyLinkResource", "ASSEMBLYLINKRESOURCE:",
+ "Assembly Link Resource",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"AdditionalManifestDependencies", "MANIFESTDEPENDENCY:",
+ "Additional Manifest Dependencies",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"ManifestInput", "manifestinput:",
+ "Manifest Input",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+
+ //String Properties
+ {"OutputFile", "OUT:",
+ "Output File",
+ "", cmVS7FlagTable::UserValue},
+ {"Version", "VERSION:",
+ "Version",
+ "", cmVS7FlagTable::UserValue},
+ {"SpecifySectionAttributes", "SECTION:",
+ "Specify Section Attributes",
+ "", cmVS7FlagTable::UserValue},
+ {"MSDOSStubFileName", "STUB:",
+ "MS-DOS Stub File Name",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [TrackerLogDirectory] - no command line Switch.
+ {"ModuleDefinitionFile", "DEF:",
+ "Module Definition File",
+ "", cmVS7FlagTable::UserValue},
+ {"ManifestFile", "ManifestFile:",
+ "Manifest File",
+ "", cmVS7FlagTable::UserValue},
+ {"ProgramDatabaseFile", "PDB:",
+ "Generate Program Database File",
+ "", cmVS7FlagTable::UserValue},
+ {"StripPrivateSymbols", "PDBSTRIPPED:",
+ "Strip Private Symbols",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [MapFileName] - no command line Switch.
+ // Skip [MinimumRequiredVersion] - no command line Switch.
+ {"HeapReserveSize", "HEAP:",
+ "Heap Reserve Size",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [HeapCommitSize] - no command line Switch.
+ {"StackReserveSize", "STACK:",
+ "Stack Reserve Size",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [StackCommitSize] - no command line Switch.
+ {"FunctionOrder", "ORDER:@",
+ "Function Order",
+ "", cmVS7FlagTable::UserValue},
+ {"ProfileGuidedDatabase", "PGD:",
+ "Profile Guided Database",
+ "", cmVS7FlagTable::UserValue},
+ {"MidlCommandFile", "MIDL:@",
+ "MIDL Commands",
+ "", cmVS7FlagTable::UserValue},
+ {"MergedIDLBaseFileName", "IDLOUT:",
+ "Merged IDL Base File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"TypeLibraryFile", "TLBOUT:",
+ "Type Library",
+ "", cmVS7FlagTable::UserValue},
+ {"WindowsMetadataFile", "WINMDFILE:",
+ "Windows Metadata File",
+ "", cmVS7FlagTable::UserValue},
+ {"WindowsMetadataLinkKeyFile", "WINMDKEYFILE:",
+ "Windows Metadata Key File",
+ "", cmVS7FlagTable::UserValue},
+ {"WindowsMetadataKeyContainer", "WINMDKEYCONTAINER:",
+ "Windows Metadata Key Container",
+ "", cmVS7FlagTable::UserValue},
+ {"EntryPointSymbol", "ENTRY:",
+ "Entry Point",
+ "", cmVS7FlagTable::UserValue},
+ {"BaseAddress", "BASE:",
+ "Base Address",
+ "", cmVS7FlagTable::UserValue},
+ {"ImportLibrary", "IMPLIB:",
+ "Import Library",
+ "", cmVS7FlagTable::UserValue},
+ {"MergeSections", "MERGE:",
+ "Merge Sections",
+ "", cmVS7FlagTable::UserValue},
+ {"LinkKeyFile", "KEYFILE:",
+ "Key File",
+ "", cmVS7FlagTable::UserValue},
+ {"KeyContainer", "KEYCONTAINER:",
+ "Key Container",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS14MASMFlagTable.h b/Source/cmVS14MASMFlagTable.h
new file mode 100644
index 0000000000..dce846f92d
--- /dev/null
+++ b/Source/cmVS14MASMFlagTable.h
@@ -0,0 +1,96 @@
+static cmVS7FlagTable cmVS14MASMFlagTable[] =
+{
+
+ //Enum Properties
+ {"PreserveIdentifierCase", "",
+ "Default", "0", 0},
+ {"PreserveIdentifierCase", "/Cp",
+ "Preserves Identifier Case (/Cp)", "1", 0},
+ {"PreserveIdentifierCase", "/Cu",
+ "Maps all identifiers to upper case. (/Cu)", "2", 0},
+ {"PreserveIdentifierCase", "/Cx",
+ "Preserves case in public and extern symbols. (/Cx)", "3", 0},
+
+ {"WarningLevel", "/W0",
+ "Warning Level 0 (/W0)", "0", 0},
+ {"WarningLevel", "/W1",
+ "Warning Level 1 (/W1)", "1", 0},
+ {"WarningLevel", "/W2",
+ "Warning Level 2 (/W2)", "2", 0},
+ {"WarningLevel", "/W3",
+ "Warning Level 3 (/W3)", "3", 0},
+
+ {"PackAlignmentBoundary", "",
+ "Default", "0", 0},
+ {"PackAlignmentBoundary", "/Zp1",
+ "One Byte Boundary (/Zp1)", "1", 0},
+ {"PackAlignmentBoundary", "/Zp2",
+ "Two Byte Boundary (/Zp2)", "2", 0},
+ {"PackAlignmentBoundary", "/Zp4",
+ "Four Byte Boundary (/Zp4)", "3", 0},
+ {"PackAlignmentBoundary", "/Zp8",
+ "Eight Byte Boundary (/Zp8)", "4", 0},
+ {"PackAlignmentBoundary", "/Zp16",
+ "Sixteen Byte Boundary (/Zp16)", "5", 0},
+
+ {"CallingConvention", "",
+ "Default", "0", 0},
+ {"CallingConvention", "/Gd",
+ "Use C-style Calling Convention (/Gd)", "1", 0},
+ {"CallingConvention", "/Gz",
+ "Use stdcall Calling Convention (/Gz)", "2", 0},
+ {"CallingConvention", "/Gc",
+ "Use Pascal Calling Convention (/Gc)", "3", 0},
+
+ {"ErrorReporting", "/errorReport:prompt",
+ "Prompt to send report immediately (/errorReport:prompt)", "0", 0},
+ {"ErrorReporting", "/errorReport:queue",
+ "Prompt to send report at the next logon (/errorReport:queue)", "1", 0},
+ {"ErrorReporting", "/errorReport:send",
+ "Automatically send report (/errorReport:send)", "2", 0},
+ {"ErrorReporting", "/errorReport:none",
+ "Do not send report (/errorReport:none)", "3", 0},
+
+
+ //Bool Properties
+ {"NoLogo", "/nologo", "", "true", 0},
+ {"GeneratePreprocessedSourceListing", "/EP", "", "true", 0},
+ {"ListAllAvailableInformation", "/Sa", "", "true", 0},
+ {"UseSafeExceptionHandlers", "/safeseh", "", "true", 0},
+ {"AddFirstPassListing", "/Sf", "", "true", 0},
+ {"EnableAssemblyGeneratedCodeListing", "/Sg", "", "true", 0},
+ {"DisableSymbolTable", "/Sn", "", "true", 0},
+ {"EnableFalseConditionalsInListing", "/Sx", "", "true", 0},
+ {"TreatWarningsAsErrors", "/WX", "", "true", 0},
+ {"MakeAllSymbolsPublic", "/Zf", "", "true", 0},
+ {"GenerateDebugInformation", "/Zi", "", "true", 0},
+ {"EnableMASM51Compatibility", "/Zm", "", "true", 0},
+ {"PerformSyntaxCheckOnly", "/Zs", "", "true", 0},
+
+ //Bool Properties With Argument
+
+ //String List Properties
+ {"PreprocessorDefinitions", "/D",
+ "Preprocessor Definitions",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"IncludePaths", "/I",
+ "Include Paths",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ {"BrowseFile", "/FR",
+ "Generate Browse Information File",
+ "", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
+ // Skip [AdditionalDependencies] - no command line Switch.
+
+ //String Properties
+ // Skip [Inputs] - no command line Switch.
+ {"ObjectFileName", "/Fo",
+ "Object File Name",
+ "", cmVS7FlagTable::UserValue},
+ {"AssembledCodeListingFile", "/Fl",
+ "Assembled Code Listing File",
+ "", cmVS7FlagTable::UserValue},
+ // Skip [CommandLineTemplate] - no command line Switch.
+ // Skip [ExecutionDescription] - no command line Switch.
+ // Skip [AdditionalOptions] - no command line Switch.
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVS14RCFlagTable.h b/Source/cmVS14RCFlagTable.h
new file mode 100644
index 0000000000..ebd8d656e9
--- /dev/null
+++ b/Source/cmVS14RCFlagTable.h
@@ -0,0 +1,7 @@
+static cmVS7FlagTable cmVS14RCFlagTable[] =
+{
+ //Bool Properties
+ {"NullTerminateStrings", "n", "", "true", 0},
+
+ {0,0,0,0,0}
+};
diff --git a/Source/cmVariableRequiresCommand.cxx b/Source/cmVariableRequiresCommand.cxx
new file mode 100644
index 0000000000..80c128654c
--- /dev/null
+++ b/Source/cmVariableRequiresCommand.cxx
@@ -0,0 +1,79 @@
+/*============================================================================
+ 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 "cmVariableRequiresCommand.h"
+#include "cmCacheManager.h"
+
+// cmLibraryCommand
+bool cmVariableRequiresCommand
+::InitialPass(std::vector<std::string>const& args, cmExecutionStatus &)
+{
+ if(this->Disallowed(cmPolicies::CMP0035,
+ "The variable_requires command should not be called; see CMP0035."))
+ { return true; }
+ if(args.size() < 3 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::string testVariable = args[0];
+ if(!this->Makefile->IsOn(testVariable))
+ {
+ return true;
+ }
+ std::string resultVariable = args[1];
+ bool requirementsMet = true;
+ std::string notSet;
+ bool hasAdvanced = false;
+ for(unsigned int i = 2; i < args.size(); ++i)
+ {
+ if(!this->Makefile->IsOn(args[i]))
+ {
+ requirementsMet = false;
+ notSet += args[i];
+ notSet += "\n";
+ cmCacheManager::CacheIterator it =
+ this->Makefile->GetCacheManager()->GetCacheIterator(args[i].c_str());
+ if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED"))
+ {
+ hasAdvanced = true;
+ }
+ }
+ }
+ const char* reqVar = this->Makefile->GetDefinition(resultVariable);
+ // if reqVar is unset, then set it to requirementsMet
+ // if reqVar is set to true, but requirementsMet is false , then
+ // set reqVar to false.
+ if(!reqVar || (!requirementsMet && this->Makefile->IsOn(reqVar)))
+ {
+ this->Makefile->AddDefinition(resultVariable, requirementsMet);
+ }
+
+ if(!requirementsMet)
+ {
+ std::string message = "Variable assertion failed:\n";
+ message += testVariable +
+ " Requires that the following unset variables are set:\n";
+ message += notSet;
+ message += "\nPlease set them, or set ";
+ message += testVariable + " to false, and re-configure.\n";
+ if(hasAdvanced)
+ {
+ message +=
+ "One or more of the required variables is advanced."
+ " To set the variable, you must turn on advanced mode in cmake.";
+ }
+ cmSystemTools::Error(message.c_str());
+ }
+
+ return true;
+}
diff --git a/Source/cmVariableRequiresCommand.h b/Source/cmVariableRequiresCommand.h
new file mode 100644
index 0000000000..7e68de11db
--- /dev/null
+++ b/Source/cmVariableRequiresCommand.h
@@ -0,0 +1,29 @@
+/*============================================================================
+ 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 cmVariableRequiresCommand_h
+#define cmVariableRequiresCommand_h
+
+#include "cmCommand.h"
+
+class cmVariableRequiresCommand : public cmCommand
+{
+public:
+ cmTypeMacro(cmVariableRequiresCommand, cmCommand);
+ virtual cmCommand* Clone() { return new cmVariableRequiresCommand; }
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+ virtual std::string GetName() const { return "variable_requires";}
+ virtual bool IsDiscouraged() const { return true; }
+};
+
+
+#endif
diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx
new file mode 100644
index 0000000000..cb6cb12965
--- /dev/null
+++ b/Source/cmVariableWatch.cxx
@@ -0,0 +1,119 @@
+/*============================================================================
+ 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 "cmVariableWatch.h"
+
+static const char* const cmVariableWatchAccessStrings[] =
+{
+ "READ_ACCESS",
+ "UNKNOWN_READ_ACCESS",
+ "UNKNOWN_DEFINED_ACCESS",
+ "MODIFIED_ACCESS",
+ "REMOVED_ACCESS",
+ "NO_ACCESS"
+};
+
+const char* cmVariableWatch::GetAccessAsString(int access_type)
+{
+ if ( access_type < 0 || access_type >= cmVariableWatch::NO_ACCESS )
+ {
+ return "NO_ACCESS";
+ }
+ return cmVariableWatchAccessStrings[access_type];
+}
+
+cmVariableWatch::cmVariableWatch()
+{
+}
+
+cmVariableWatch::~cmVariableWatch()
+{
+ cmVariableWatch::StringToVectorOfPairs::iterator svp_it;
+
+ for ( svp_it = this->WatchMap.begin();
+ svp_it != this->WatchMap.end(); ++svp_it )
+ {
+ cmVariableWatch::VectorOfPairs::iterator p_it;
+
+ for ( p_it = svp_it->second.begin();
+ p_it != svp_it->second.end(); ++p_it )
+ {
+ delete *p_it;
+ }
+ }
+}
+
+bool cmVariableWatch::AddWatch(const std::string& variable,
+ WatchMethod method, void* client_data /*=0*/,
+ DeleteData delete_data /*=0*/)
+{
+ cmVariableWatch::Pair* p = new cmVariableWatch::Pair;
+ p->Method = method;
+ p->ClientData = client_data;
+ p->DeleteDataCall = delete_data;
+ cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
+ cmVariableWatch::VectorOfPairs::size_type cc;
+ for ( cc = 0; cc < vp->size(); cc ++ )
+ {
+ cmVariableWatch::Pair* pair = (*vp)[cc];
+ if ( pair->Method == method &&
+ client_data && client_data == pair->ClientData)
+ {
+ // Callback already exists
+ return false;
+ }
+ }
+ vp->push_back(p);
+ return true;
+}
+
+void cmVariableWatch::RemoveWatch(const std::string& variable,
+ WatchMethod method,
+ void* client_data /*=0*/)
+{
+ if ( !this->WatchMap.count(variable) )
+ {
+ return;
+ }
+ cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
+ cmVariableWatch::VectorOfPairs::iterator it;
+ for ( it = vp->begin(); it != vp->end(); ++it )
+ {
+ if ( (*it)->Method == method &&
+ // If client_data is NULL, we want to disconnect all watches against
+ // the given method; otherwise match ClientData as well.
+ (!client_data || (client_data == (*it)->ClientData)))
+ {
+ delete *it;
+ vp->erase(it);
+ return;
+ }
+ }
+}
+
+void cmVariableWatch::VariableAccessed(const std::string& variable,
+ int access_type,
+ const char* newValue,
+ const cmMakefile* mf) const
+{
+ cmVariableWatch::StringToVectorOfPairs::const_iterator mit =
+ this->WatchMap.find(variable);
+ if ( mit != this->WatchMap.end() )
+ {
+ const cmVariableWatch::VectorOfPairs* vp = &mit->second;
+ cmVariableWatch::VectorOfPairs::const_iterator it;
+ for ( it = vp->begin(); it != vp->end(); it ++ )
+ {
+ (*it)->Method(variable, access_type, (*it)->ClientData,
+ newValue, mf);
+ }
+ }
+}
diff --git a/Source/cmVariableWatch.h b/Source/cmVariableWatch.h
new file mode 100644
index 0000000000..0ca4a5580e
--- /dev/null
+++ b/Source/cmVariableWatch.h
@@ -0,0 +1,89 @@
+/*============================================================================
+ 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 cmVariableWatch_h
+#define cmVariableWatch_h
+
+#include "cmStandardIncludes.h"
+
+class cmMakefile;
+
+/** \class cmVariableWatch
+ * \brief Helper class for watching of variable accesses.
+ *
+ * Calls function when variable is accessed
+ */
+class cmVariableWatch
+{
+public:
+ typedef void (*WatchMethod)(const std::string& variable, int access_type,
+ void* client_data, const char* newValue, const cmMakefile* mf);
+ typedef void (*DeleteData)(void* client_data);
+
+ cmVariableWatch();
+ ~cmVariableWatch();
+
+ /**
+ * Add watch to the variable
+ */
+ bool AddWatch(const std::string& variable, WatchMethod method,
+ void* client_data=0, DeleteData delete_data=0);
+ void RemoveWatch(const std::string& variable, WatchMethod method,
+ void* client_data=0);
+
+ /**
+ * This method is called when variable is accessed
+ */
+ void VariableAccessed(const std::string& variable, int access_type,
+ const char* newValue, const cmMakefile* mf) const;
+
+ /**
+ * Different access types.
+ */
+ enum
+ {
+ VARIABLE_READ_ACCESS = 0,
+ UNKNOWN_VARIABLE_READ_ACCESS,
+ UNKNOWN_VARIABLE_DEFINED_ACCESS,
+ VARIABLE_MODIFIED_ACCESS,
+ VARIABLE_REMOVED_ACCESS,
+ NO_ACCESS
+ };
+
+ /**
+ * Return the access as string
+ */
+ static const char* GetAccessAsString(int access_type);
+
+protected:
+ struct Pair
+ {
+ WatchMethod Method;
+ void* ClientData;
+ DeleteData DeleteDataCall;
+ Pair() : Method(0), ClientData(0), DeleteDataCall(0) {}
+ ~Pair()
+ {
+ if (this->DeleteDataCall && this->ClientData)
+ {
+ this->DeleteDataCall(this->ClientData);
+ }
+ }
+ };
+
+ typedef std::vector< Pair* > VectorOfPairs;
+ typedef std::map<std::string, VectorOfPairs > StringToVectorOfPairs;
+
+ StringToVectorOfPairs WatchMap;
+};
+
+
+#endif
diff --git a/Source/cmVariableWatchCommand.cxx b/Source/cmVariableWatchCommand.cxx
new file mode 100644
index 0000000000..debe24340f
--- /dev/null
+++ b/Source/cmVariableWatchCommand.cxx
@@ -0,0 +1,159 @@
+/*============================================================================
+ 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 "cmVariableWatchCommand.h"
+
+#include "cmVariableWatch.h"
+
+//----------------------------------------------------------------------------
+struct cmVariableWatchCallbackData
+{
+ bool InCallback;
+ std::string Command;
+};
+
+//----------------------------------------------------------------------------
+static void cmVariableWatchCommandVariableAccessed(
+ const std::string& variable, int access_type, void* client_data,
+ const char* newValue, const cmMakefile* mf)
+{
+ cmVariableWatchCallbackData* data
+ = static_cast<cmVariableWatchCallbackData*>(client_data);
+
+ if ( data->InCallback )
+ {
+ return;
+ }
+ data->InCallback = true;
+
+ cmListFileFunction newLFF;
+ cmListFileArgument arg;
+ bool processed = false;
+ const char* accessString = cmVariableWatch::GetAccessAsString(access_type);
+ const char* currentListFile = mf->GetDefinition("CMAKE_CURRENT_LIST_FILE");
+
+ /// Ultra bad!!
+ cmMakefile* makefile = const_cast<cmMakefile*>(mf);
+
+ std::string stack = makefile->GetProperty("LISTFILE_STACK");
+ if ( !data->Command.empty() )
+ {
+ newLFF.Arguments.clear();
+ newLFF.Arguments.push_back(
+ cmListFileArgument(variable, cmListFileArgument::Quoted,
+ "unknown", 9999));
+ newLFF.Arguments.push_back(
+ cmListFileArgument(accessString, cmListFileArgument::Quoted,
+ "unknown", 9999));
+ newLFF.Arguments.push_back(
+ cmListFileArgument(newValue?newValue:"", cmListFileArgument::Quoted,
+ "unknown", 9999));
+ newLFF.Arguments.push_back(
+ cmListFileArgument(currentListFile, cmListFileArgument::Quoted,
+ "unknown", 9999));
+ newLFF.Arguments.push_back(
+ cmListFileArgument(stack, cmListFileArgument::Quoted,
+ "unknown", 9999));
+ newLFF.Name = data->Command;
+ newLFF.FilePath = "Some weird path";
+ newLFF.Line = 9999;
+ cmExecutionStatus status;
+ if(!makefile->ExecuteCommand(newLFF,status))
+ {
+ arg.FilePath = "Unknown";
+ arg.Line = 0;
+ cmOStringStream error;
+ error << "Error in cmake code at\n"
+ << arg.FilePath << ":" << arg.Line << ":\n"
+ << "A command failed during the invocation of callback \""
+ << data->Command << "\".";
+ cmSystemTools::Error(error.str().c_str());
+ data->InCallback = false;
+ return;
+ }
+ processed = true;
+ }
+ if ( !processed )
+ {
+ cmOStringStream msg;
+ msg << "Variable \"" << variable << "\" was accessed using "
+ << accessString << " with value \"" << (newValue?newValue:"") << "\".";
+ makefile->IssueMessage(cmake::LOG, msg.str());
+ }
+
+ data->InCallback = false;
+}
+
+//----------------------------------------------------------------------------
+static void deleteVariableWatchCallbackData(void* client_data)
+{
+ cmVariableWatchCallbackData* data
+ = static_cast<cmVariableWatchCallbackData*>(client_data);
+ delete data;
+}
+
+//----------------------------------------------------------------------------
+cmVariableWatchCommand::cmVariableWatchCommand()
+{
+}
+
+//----------------------------------------------------------------------------
+cmVariableWatchCommand::~cmVariableWatchCommand()
+{
+ std::set<std::string>::const_iterator it;
+ for ( it = this->WatchedVariables.begin();
+ it != this->WatchedVariables.end();
+ ++it )
+ {
+ this->Makefile->GetCMakeInstance()->GetVariableWatch()->RemoveWatch(
+ *it, cmVariableWatchCommandVariableAccessed);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmVariableWatchCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if ( args.size() < 1 )
+ {
+ this->SetError("must be called with at least one argument.");
+ return false;
+ }
+ std::string variable = args[0];
+ std::string command;
+ if ( args.size() > 1 )
+ {
+ command = args[1];
+ }
+ if ( variable == "CMAKE_CURRENT_LIST_FILE" )
+ {
+ cmOStringStream ostr;
+ ostr << "cannot be set on the variable: " << variable;
+ this->SetError(ostr.str());
+ return false;
+ }
+
+ cmVariableWatchCallbackData* data = new cmVariableWatchCallbackData;
+
+ data->InCallback = false;
+ data->Command = command;
+
+ this->WatchedVariables.insert(variable);
+ if ( !this->Makefile->GetCMakeInstance()->GetVariableWatch()->AddWatch(
+ variable, cmVariableWatchCommandVariableAccessed,
+ data, deleteVariableWatchCallbackData) )
+ {
+ deleteVariableWatchCallbackData(data);
+ return false;
+ }
+
+ return true;
+}
diff --git a/Source/cmVariableWatchCommand.h b/Source/cmVariableWatchCommand.h
new file mode 100644
index 0000000000..c1ee9b14eb
--- /dev/null
+++ b/Source/cmVariableWatchCommand.h
@@ -0,0 +1,68 @@
+/*============================================================================
+ 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 cmVariableWatchCommand_h
+#define cmVariableWatchCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmVariableWatchCommand
+ * \brief Watch when the variable changes and invoke command
+ *
+ */
+class cmVariableWatchCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmVariableWatchCommand;
+ }
+
+ //! Default constructor
+ cmVariableWatchCommand();
+
+ //! Destructor.
+ ~cmVariableWatchCommand();
+
+ /**
+ * 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; }
+
+ /** This command does not really have a final pass but it needs to
+ stay alive since it owns variable watch callback information. */
+ virtual bool HasFinalPass() const { return true; }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "variable_watch";}
+
+ cmTypeMacro(cmVariableWatchCommand, cmCommand);
+
+protected:
+ std::set<std::string> WatchedVariables;
+};
+
+
+#endif
+
+
diff --git a/Source/cmVersion.cxx b/Source/cmVersion.cxx
new file mode 100644
index 0000000000..9cb0cd6a7f
--- /dev/null
+++ b/Source/cmVersion.cxx
@@ -0,0 +1,24 @@
+/*============================================================================
+ 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 "cmVersion.h"
+
+#include "cmVersionMacros.h"
+
+unsigned int cmVersion::GetMajorVersion() { return CMake_VERSION_MAJOR; }
+unsigned int cmVersion::GetMinorVersion() { return CMake_VERSION_MINOR; }
+unsigned int cmVersion::GetPatchVersion() { return CMake_VERSION_PATCH; }
+unsigned int cmVersion::GetTweakVersion() { return 0; }
+
+const char* cmVersion::GetCMakeVersion()
+{
+ return CMake_VERSION;
+}
diff --git a/Source/cmVersion.h b/Source/cmVersion.h
new file mode 100644
index 0000000000..0ab639051e
--- /dev/null
+++ b/Source/cmVersion.h
@@ -0,0 +1,44 @@
+/*============================================================================
+ 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 cmVersion_h
+#define cmVersion_h
+
+#include "cmStandardIncludes.h"
+
+/** \class cmVersion
+ * \brief Helper class for providing CMake and CTest version information.
+ *
+ * Finds all version related information.
+ */
+class cmVersion
+{
+public:
+ /**
+ * Return major and minor version numbers for cmake.
+ */
+ static unsigned int GetMajorVersion();
+ static unsigned int GetMinorVersion();
+ static unsigned int GetPatchVersion();
+ static unsigned int GetTweakVersion();
+ static const char* GetCMakeVersion();
+};
+
+/* 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(major, minor, patch) \
+ ((((major) * 1000u) * CMake_VERSION_ENCODE__BASE) + \
+ (((minor) % 1000u) * CMake_VERSION_ENCODE__BASE) + \
+ (((patch) % CMake_VERSION_ENCODE__BASE)))
+
+#endif
+
diff --git a/Source/cmVersionConfig.h.in b/Source/cmVersionConfig.h.in
new file mode 100644
index 0000000000..16aeabe9e5
--- /dev/null
+++ b/Source/cmVersionConfig.h.in
@@ -0,0 +1,15 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#define CMake_VERSION_MAJOR @CMake_VERSION_MAJOR@
+#define CMake_VERSION_MINOR @CMake_VERSION_MINOR@
+#define CMake_VERSION_PATCH @CMake_VERSION_PATCH@
+#define CMake_VERSION "@CMake_VERSION@"
diff --git a/Source/cmVersionMacros.h b/Source/cmVersionMacros.h
new file mode 100644
index 0000000000..cf7f678a78
--- /dev/null
+++ b/Source/cmVersionMacros.h
@@ -0,0 +1,22 @@
+/*============================================================================
+ 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 cmVersionMacros_h
+#define cmVersionMacros_h
+
+#include "cmVersionConfig.h"
+
+#define CMake_VERSION_PATCH_IS_RELEASE(patch) ((patch) < 20000000)
+#if CMake_VERSION_PATCH_IS_RELEASE(CMake_VERSION_PATCH)
+# define CMake_VERSION_IS_RELEASE 1
+#endif
+
+#endif
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
new file mode 100644
index 0000000000..26fc317bc6
--- /dev/null
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -0,0 +1,3126 @@
+/*============================================================================
+ 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 "cmVisualStudio10TargetGenerator.h"
+#include "cmGlobalVisualStudio10Generator.h"
+#include "cmGeneratorTarget.h"
+#include "cmTarget.h"
+#include "cmComputeLinkInformation.h"
+#include "cmGeneratedFileStream.h"
+#include "cmMakefile.h"
+#include "cmSourceFile.h"
+#include "cmVisualStudioGeneratorOptions.h"
+#include "cmLocalVisualStudio7Generator.h"
+#include "cmCustomCommandGenerator.h"
+#include "cmVS10CLFlagTable.h"
+#include "cmVS10RCFlagTable.h"
+#include "cmVS10LinkFlagTable.h"
+#include "cmVS10LibFlagTable.h"
+#include "cmVS10MASMFlagTable.h"
+#include "cmVS11CLFlagTable.h"
+#include "cmVS11RCFlagTable.h"
+#include "cmVS11LinkFlagTable.h"
+#include "cmVS11LibFlagTable.h"
+#include "cmVS11MASMFlagTable.h"
+#include "cmVS12CLFlagTable.h"
+#include "cmVS12RCFlagTable.h"
+#include "cmVS12LinkFlagTable.h"
+#include "cmVS12LibFlagTable.h"
+#include "cmVS12MASMFlagTable.h"
+#include "cmVS14CLFlagTable.h"
+#include "cmVS14RCFlagTable.h"
+#include "cmVS14LinkFlagTable.h"
+#include "cmVS14LibFlagTable.h"
+#include "cmVS14MASMFlagTable.h"
+
+#include <cmsys/auto_ptr.hxx>
+
+cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetClFlagTable() const
+{
+ if(this->MSTools)
+ {
+ cmLocalVisualStudioGenerator::VSVersion
+ v = this->LocalGenerator->GetVersion();
+ if(v >= cmLocalVisualStudioGenerator::VS14)
+ { return cmVS14CLFlagTable; }
+ else if(v >= cmLocalVisualStudioGenerator::VS12)
+ { return cmVS12CLFlagTable; }
+ else if(v == cmLocalVisualStudioGenerator::VS11)
+ { return cmVS11CLFlagTable; }
+ else
+ { return cmVS10CLFlagTable; }
+ }
+ return 0;
+}
+
+cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetRcFlagTable() const
+{
+ if(this->MSTools)
+ {
+ cmLocalVisualStudioGenerator::VSVersion
+ v = this->LocalGenerator->GetVersion();
+ if(v >= cmLocalVisualStudioGenerator::VS14)
+ { return cmVS14RCFlagTable; }
+ else if(v >= cmLocalVisualStudioGenerator::VS12)
+ { return cmVS12RCFlagTable; }
+ else if(v == cmLocalVisualStudioGenerator::VS11)
+ { return cmVS11RCFlagTable; }
+ else
+ { return cmVS10RCFlagTable; }
+ }
+ return 0;
+}
+
+cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLibFlagTable() const
+{
+ if(this->MSTools)
+ {
+ cmLocalVisualStudioGenerator::VSVersion
+ v = this->LocalGenerator->GetVersion();
+ if(v >= cmLocalVisualStudioGenerator::VS14)
+ { return cmVS14LibFlagTable; }
+ else if(v >= cmLocalVisualStudioGenerator::VS12)
+ { return cmVS12LibFlagTable; }
+ else if(v == cmLocalVisualStudioGenerator::VS11)
+ { return cmVS11LibFlagTable; }
+ else
+ { return cmVS10LibFlagTable; }
+ }
+ return 0;
+}
+
+cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLinkFlagTable() const
+{
+ if(this->MSTools)
+ {
+ cmLocalVisualStudioGenerator::VSVersion
+ v = this->LocalGenerator->GetVersion();
+ if(v >= cmLocalVisualStudioGenerator::VS14)
+ { return cmVS14LinkFlagTable; }
+ else if(v >= cmLocalVisualStudioGenerator::VS12)
+ { return cmVS12LinkFlagTable; }
+ else if(v == cmLocalVisualStudioGenerator::VS11)
+ { return cmVS11LinkFlagTable; }
+ else
+ { return cmVS10LinkFlagTable; }
+ }
+ return 0;
+}
+
+cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetMasmFlagTable() const
+{
+ if(this->MSTools)
+ {
+ cmLocalVisualStudioGenerator::VSVersion
+ v = this->LocalGenerator->GetVersion();
+ if(v >= cmLocalVisualStudioGenerator::VS14)
+ { return cmVS14MASMFlagTable; }
+ else if(v >= cmLocalVisualStudioGenerator::VS12)
+ { return cmVS12MASMFlagTable; }
+ else if(v == cmLocalVisualStudioGenerator::VS11)
+ { return cmVS11MASMFlagTable; }
+ else
+ { return cmVS10MASMFlagTable; }
+ }
+ return 0;
+}
+
+static std::string cmVS10EscapeXML(std::string arg)
+{
+ cmSystemTools::ReplaceString(arg, "&", "&amp;");
+ cmSystemTools::ReplaceString(arg, "<", "&lt;");
+ cmSystemTools::ReplaceString(arg, ">", "&gt;");
+ return arg;
+}
+
+static std::string cmVS10EscapeComment(std::string comment)
+{
+ // MSBuild takes the CDATA of a <Message></Message> element and just
+ // does "echo $CDATA" with no escapes. We must encode the string.
+ // http://technet.microsoft.com/en-us/library/cc772462%28WS.10%29.aspx
+ std::string echoable;
+ for(std::string::iterator c = comment.begin(); c != comment.end(); ++c)
+ {
+ switch (*c)
+ {
+ case '\r': break;
+ case '\n': echoable += '\t'; break;
+ case '"': /* no break */
+ case '|': /* no break */
+ case '&': /* no break */
+ case '<': /* no break */
+ case '>': /* no break */
+ case '^': echoable += '^'; /* no break */
+ default: echoable += *c; break;
+ }
+ }
+ return echoable;
+}
+
+cmVisualStudio10TargetGenerator::
+cmVisualStudio10TargetGenerator(cmTarget* target,
+ cmGlobalVisualStudio10Generator* gg)
+{
+ this->GlobalGenerator = gg;
+ this->Target = target;
+ this->GeneratorTarget = gg->GetGeneratorTarget(target);
+ this->Makefile = target->GetMakefile();
+ this->LocalGenerator =
+ (cmLocalVisualStudio7Generator*)
+ this->Makefile->GetLocalGenerator();
+ this->Name = this->Target->GetName();
+ this->GlobalGenerator->CreateGUID(this->Name.c_str());
+ this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
+ this->Platform = gg->GetPlatformName();
+ this->NsightTegra = gg->IsNsightTegra();
+ for(int i =
+ sscanf(gg->GetNsightTegraVersion().c_str(), "%u.%u.%u.%u",
+ &this->NsightTegraVersion[0], &this->NsightTegraVersion[1],
+ &this->NsightTegraVersion[2], &this->NsightTegraVersion[3]);
+ i < 4; ++i)
+ {
+ this->NsightTegraVersion[i] = 0;
+ }
+ this->MSTools = !this->NsightTegra;
+ this->TargetCompileAsWinRT = false;
+ this->BuildFileStream = 0;
+ this->IsMissingFiles = false;
+ this->DefaultArtifactDir =
+ this->Makefile->GetStartOutputDirectory() + std::string("/") +
+ this->LocalGenerator->GetTargetDirectory(*this->Target);
+}
+
+cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
+{
+ for(OptionsMap::iterator i = this->ClOptions.begin();
+ i != this->ClOptions.end(); ++i)
+ {
+ delete i->second;
+ }
+ for(OptionsMap::iterator i = this->LinkOptions.begin();
+ i != this->LinkOptions.end(); ++i)
+ {
+ delete i->second;
+ }
+ if(!this->BuildFileStream)
+ {
+ return;
+ }
+ if (this->BuildFileStream->Close())
+ {
+ this->GlobalGenerator
+ ->FileReplacedDuringGenerate(this->PathToVcxproj);
+ }
+ delete this->BuildFileStream;
+}
+
+void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
+ const char* tag,
+ const std::string& config,
+ int indentLevel,
+ const char* attribute,
+ const char* end,
+ std::ostream* stream)
+
+{
+ if(!stream)
+ {
+ stream = this->BuildFileStream;
+ }
+ stream->fill(' ');
+ stream->width(indentLevel*2 );
+ (*stream ) << "";
+ (*stream ) << "<" << tag
+ << " Condition=\"'$(Configuration)|$(Platform)'=='";
+ (*stream ) << config << "|" << this->Platform << "'\"";
+ if(attribute)
+ {
+ (*stream ) << attribute;
+ }
+ // close the tag
+ (*stream ) << ">";
+ if(end)
+ {
+ (*stream ) << end;
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteString(const char* line,
+ int indentLevel)
+{
+ this->BuildFileStream->fill(' ');
+ this->BuildFileStream->width(indentLevel*2 );
+ // write an empty string to get the fill level indent to print
+ (*this->BuildFileStream ) << "";
+ (*this->BuildFileStream ) << line;
+}
+
+#define VS10_USER_PROPS "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props"
+
+void cmVisualStudio10TargetGenerator::Generate()
+{
+ // do not generate external ms projects
+ if(this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
+ || this->Target->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",
+ ".vcxproj");
+ if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
+ {
+ if(!this->ComputeClOptions())
+ {
+ return;
+ }
+ if(!this->ComputeRcOptions())
+ {
+ return;
+ }
+ if(!this->ComputeMasmOptions())
+ {
+ return;
+ }
+ if(!this->ComputeLinkOptions())
+ {
+ return;
+ }
+ }
+ cmMakefile* mf = this->Target->GetMakefile();
+ std::string path = mf->GetStartOutputDirectory();
+ path += "/";
+ path += this->Name;
+ path += ".vcxproj";
+ this->BuildFileStream =
+ new cmGeneratedFileStream(path.c_str());
+ this->PathToVcxproj = path;
+ this->BuildFileStream->SetCopyIfDifferent(true);
+
+ // Write the encoding header into the file
+ char magic[] = {0xEF,0xBB, 0xBF};
+ this->BuildFileStream->write(magic, 3);
+
+ //get the tools version to use
+ const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
+ std::string project_defaults=
+ "<?xml version=\"1.0\" encoding=\"" +
+ this->GlobalGenerator->Encoding() + "\"?>\n";
+ project_defaults.append("<Project DefaultTargets=\"Build\" ToolsVersion=\"");
+ project_defaults.append(toolsVer +"\" ");
+ project_defaults.append(
+ "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
+ this->WriteString(project_defaults.c_str(),0);
+
+ if(this->NsightTegra)
+ {
+ this->WriteString("<PropertyGroup Label=\"NsightTegraProject\">\n", 1);
+ if(this->NsightTegraVersion[0] >= 2)
+ {
+ // Nsight Tegra 2.0 uses project revision 8.
+ this->WriteString("<NsightTegraProjectRevisionNumber>"
+ "8"
+ "</NsightTegraProjectRevisionNumber>\n", 2);
+ // Tell newer versions to upgrade silently when loading.
+ this->WriteString("<NsightTegraUpgradeOnceWithoutPrompt>"
+ "true"
+ "</NsightTegraUpgradeOnceWithoutPrompt>\n", 2);
+ }
+ else
+ {
+ // Require Nsight Tegra 1.6 for JCompile support.
+ this->WriteString("<NsightTegraProjectRevisionNumber>"
+ "7"
+ "</NsightTegraProjectRevisionNumber>\n", 2);
+ }
+ this->WriteString("</PropertyGroup>\n", 1);
+ }
+
+ this->WriteProjectConfigurations();
+ this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
+ this->WriteString("<ProjectGUID>", 2);
+ (*this->BuildFileStream) << "{" << this->GUID << "}</ProjectGUID>\n";
+
+ if(this->MSTools && this->Target->GetType() <= cmTarget::GLOBAL_TARGET)
+ {
+ this->WriteApplicationTypeSettings();
+ this->VerifyNecessaryFiles();
+ }
+
+ const char* vsProjectTypes =
+ this->Target->GetProperty("VS_GLOBAL_PROJECT_TYPES");
+ if(vsProjectTypes)
+ {
+ this->WriteString("<ProjectTypes>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectTypes) <<
+ "</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");
+
+ if( vsProjectName && vsLocalPath && vsProvider )
+ {
+ this->WriteString("<SccProjectName>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectName) <<
+ "</SccProjectName>\n";
+ this->WriteString("<SccLocalPath>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(vsLocalPath) <<
+ "</SccLocalPath>\n";
+ this->WriteString("<SccProvider>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(vsProvider) <<
+ "</SccProvider>\n";
+
+ const char* vsAuxPath = this->Target->GetProperty("VS_SCC_AUXPATH");
+ if( vsAuxPath )
+ {
+ this->WriteString("<SccAuxPath>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(vsAuxPath) <<
+ "</SccAuxPath>\n";
+ }
+ }
+
+ if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
+ {
+ this->WriteString("<WinMDAssembly>true</WinMDAssembly>\n", 2);
+ }
+
+ const char* vsGlobalKeyword =
+ this->Target->GetProperty("VS_GLOBAL_KEYWORD");
+ if(!vsGlobalKeyword)
+ {
+ this->WriteString("<Keyword>Win32Proj</Keyword>\n", 2);
+ }
+ else
+ {
+ this->WriteString("<Keyword>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalKeyword) <<
+ "</Keyword>\n";
+ }
+
+ const char* vsGlobalRootNamespace =
+ this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
+ if(vsGlobalRootNamespace)
+ {
+ this->WriteString("<RootNamespace>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalRootNamespace) <<
+ "</RootNamespace>\n";
+ }
+
+ this->WriteString("<Platform>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
+ << "</Platform>\n";
+ const char* projLabel = this->Target->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(
+ "VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
+ {
+ this->WriteString("<TargetFrameworkVersion>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(targetFrameworkVersion)
+ << "</TargetFrameworkVersion>\n";
+ }
+ this->WriteString("</PropertyGroup>\n", 1);
+ this->WriteString("<Import Project="
+ "\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n",
+ 1);
+ this->WriteProjectConfigurationValues();
+ this->WriteString(
+ "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n", 1);
+ this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1);
+ if (this->GlobalGenerator->IsMasmEnabled())
+ {
+ this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
+ "BuildCustomizations\\masm.props\" />\n", 2);
+ }
+ this->WriteString("</ImportGroup>\n", 1);
+ this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1);
+ this->WriteString("<Import Project=\"" VS10_USER_PROPS "\""
+ " Condition=\"exists('" VS10_USER_PROPS "')\""
+ " Label=\"LocalAppDataPlatform\" />\n", 2);
+ this->WriteString("</ImportGroup>\n", 1);
+ this->WriteString("<PropertyGroup Label=\"UserMacros\" />\n", 1);
+ this->WriteWinRTPackageCertificateKeyFile();
+ this->WritePathAndIncrementalLinkOptions();
+ this->WriteItemDefinitionGroups();
+ this->WriteCustomCommands();
+ this->WriteAllSources();
+ this->WriteDotNetReferences();
+ this->WriteEmbeddedResourceGroup();
+ this->WriteWinRTReferences();
+ this->WriteProjectReferences();
+ this->WriteString(
+ "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\""
+ " />\n", 1);
+ this->WriteTargetSpecificReferences();
+ this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
+ if (this->GlobalGenerator->IsMasmEnabled())
+ {
+ this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
+ "BuildCustomizations\\masm.targets\" />\n", 2);
+ }
+ this->WriteString("</ImportGroup>\n", 1);
+ this->WriteString("</Project>", 0);
+ // The groups are stored in a separate file for VS 10
+ this->WriteGroups();
+}
+
+void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
+{
+ std::vector<std::string> references;
+ if(const char* vsDotNetReferences =
+ this->Target->GetProperty("VS_DOTNET_REFERENCES"))
+ {
+ cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
+ }
+ if(!references.empty())
+ {
+ this->WriteString("<ItemGroup>\n", 1);
+ for(std::vector<std::string>::iterator ri = references.begin();
+ ri != references.end(); ++ri)
+ {
+ this->WriteString("<Reference Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
+ this->WriteString("<CopyLocalSatelliteAssemblies>true"
+ "</CopyLocalSatelliteAssemblies>\n", 3);
+ this->WriteString("<ReferenceOutputAssembly>true"
+ "</ReferenceOutputAssembly>\n", 3);
+ this->WriteString("</Reference>\n", 2);
+ }
+ this->WriteString("</ItemGroup>\n", 1);
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
+{
+ std::vector<cmSourceFile const*> resxObjs;
+ this->GeneratorTarget->GetResxSources(resxObjs, "");
+ if(!resxObjs.empty())
+ {
+ this->WriteString("<ItemGroup>\n", 1);
+ for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
+ oi != resxObjs.end(); ++oi)
+ {
+ std::string obj = (*oi)->GetFullPath();
+ this->WriteString("<EmbeddedResource Include=\"", 2);
+ this->ConvertToWindowsSlash(obj);
+ (*this->BuildFileStream ) << obj << "\">\n";
+
+ this->WriteString("<DependentUpon>", 3);
+ std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
+ (*this->BuildFileStream ) << hFileName;
+ this->WriteString("</DependentUpon>\n", 3);
+
+ std::vector<std::string> const * configs =
+ this->GlobalGenerator->GetConfigurations();
+ for(std::vector<std::string>::const_iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ this->WritePlatformConfigTag("LogicalName", i->c_str(), 3);
+ if(this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE"))
+ {
+ (*this->BuildFileStream ) << "$(RootNamespace).";
+ }
+ (*this->BuildFileStream ) << "%(Filename)";
+ (*this->BuildFileStream ) << ".resources";
+ (*this->BuildFileStream ) << "</LogicalName>\n";
+ }
+
+ this->WriteString("</EmbeddedResource>\n", 2);
+ }
+ this->WriteString("</ItemGroup>\n", 1);
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences()
+{
+ if(this->MSTools)
+ {
+ if(this->GlobalGenerator->TargetsWindowsPhone() &&
+ this->GlobalGenerator->GetSystemVersion() == "8.0")
+ {
+ this->WriteString(
+ "<Import Project=\""
+ "$(MSBuildExtensionsPath)\\Microsoft\\WindowsPhone\\v"
+ "$(TargetPlatformVersion)\\Microsoft.Cpp.WindowsPhone."
+ "$(TargetPlatformVersion).targets\" />\n", 1);
+ }
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
+{
+ std::vector<std::string> references;
+ if(const char* vsWinRTReferences =
+ this->Target->GetProperty("VS_WINRT_REFERENCES"))
+ {
+ cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
+ }
+
+ if(this->GlobalGenerator->TargetsWindowsPhone() &&
+ this->GlobalGenerator->GetSystemVersion() == "8.0" &&
+ references.empty())
+ {
+ references.push_back("platform.winmd");
+ }
+ if(!references.empty())
+ {
+ this->WriteString("<ItemGroup>\n", 1);
+ for(std::vector<std::string>::iterator ri = references.begin();
+ ri != references.end(); ++ri)
+ {
+ this->WriteString("<Reference Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
+ this->WriteString("<IsWinMDFile>true</IsWinMDFile>\n", 3);
+ this->WriteString("</Reference>\n", 2);
+ }
+ this->WriteString("</ItemGroup>\n", 1);
+ }
+}
+
+// ConfigurationType Application, Utility StaticLibrary DynamicLibrary
+
+void cmVisualStudio10TargetGenerator::WriteProjectConfigurations()
+{
+ this->WriteString("<ItemGroup Label=\"ProjectConfigurations\">\n", 1);
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+ for(std::vector<std::string>::iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ this->WriteString("<ProjectConfiguration Include=\"", 2);
+ (*this->BuildFileStream ) << *i << "|" << this->Platform << "\">\n";
+ this->WriteString("<Configuration>", 3);
+ (*this->BuildFileStream ) << *i << "</Configuration>\n";
+ this->WriteString("<Platform>", 3);
+ (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
+ << "</Platform>\n";
+ this->WriteString("</ProjectConfiguration>\n", 2);
+ }
+ this->WriteString("</ItemGroup>\n", 1);
+}
+
+void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
+{
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+ for(std::vector<std::string>::iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ this->WritePlatformConfigTag("PropertyGroup",
+ i->c_str(),
+ 1, " Label=\"Configuration\"", "\n");
+ std::string configType = "<ConfigurationType>";
+ switch(this->Target->GetType())
+ {
+ case cmTarget::SHARED_LIBRARY:
+ case cmTarget::MODULE_LIBRARY:
+ configType += "DynamicLibrary";
+ break;
+ case cmTarget::OBJECT_LIBRARY:
+ case cmTarget::STATIC_LIBRARY:
+ configType += "StaticLibrary";
+ break;
+ case cmTarget::EXECUTABLE:
+ if(this->NsightTegra &&
+ !this->Target->GetPropertyAsBool("ANDROID_GUI"))
+ {
+ // Android executables are .so too.
+ configType += "DynamicLibrary";
+ }
+ else
+ {
+ configType += "Application";
+ }
+ break;
+ case cmTarget::UTILITY:
+ case cmTarget::GLOBAL_TARGET:
+ if(this->NsightTegra)
+ {
+ // Tegra-Android platform does not understand "Utility".
+ configType += "StaticLibrary";
+ }
+ else
+ {
+ configType += "Utility";
+ }
+ break;
+ case cmTarget::UNKNOWN_LIBRARY:
+ case cmTarget::INTERFACE_LIBRARY:
+ break;
+ }
+ configType += "</ConfigurationType>\n";
+ this->WriteString(configType.c_str(), 2);
+
+ if(this->MSTools)
+ {
+ this->WriteMSToolConfigurationValues(*i);
+ }
+ else if(this->NsightTegra)
+ {
+ this->WriteNsightTegraConfigurationValues(*i);
+ }
+
+ this->WriteString("</PropertyGroup>\n", 1);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudio10TargetGenerator
+::WriteMSToolConfigurationValues(std::string const& config)
+{
+ cmGlobalVisualStudio10Generator* gg =
+ static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
+ const char* mfcFlag =
+ this->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")
+ {
+ useOfMfcValue = "Dynamic";
+ }
+ std::string mfcLine = "<UseOfMfc>";
+ mfcLine += useOfMfcValue + "</UseOfMfc>\n";
+ this->WriteString(mfcLine.c_str(), 2);
+
+ if((this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
+ this->ClOptions[config]->UsingUnicode()) ||
+ this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
+ this->GlobalGenerator->TargetsWindowsPhone() ||
+ this->GlobalGenerator->TargetsWindowsStore() ||
+ this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
+ {
+ this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
+ }
+ else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
+ this->ClOptions[config]->UsingSBCS())
+ {
+ this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
+ }
+ else
+ {
+ this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
+ }
+ if(const char* toolset = gg->GetPlatformToolset())
+ {
+ std::string pts = "<PlatformToolset>";
+ pts += toolset;
+ pts += "</PlatformToolset>\n";
+ this->WriteString(pts.c_str(), 2);
+ }
+ if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
+ this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
+ {
+ this->WriteString("<WindowsAppContainer>true"
+ "</WindowsAppContainer>\n", 2);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudio10TargetGenerator
+::WriteNsightTegraConfigurationValues(std::string const&)
+{
+ cmGlobalVisualStudio10Generator* gg =
+ static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
+ const char* toolset = gg->GetPlatformToolset();
+ std::string ntv = "<NdkToolchainVersion>";
+ ntv += toolset? toolset : "Default";
+ ntv += "</NdkToolchainVersion>\n";
+ this->WriteString(ntv.c_str(), 2);
+ if(const char* api = this->Target->GetProperty("ANDROID_API"))
+ {
+ this->WriteString("<AndroidTargetAPI>", 2);
+ (*this->BuildFileStream ) <<
+ "android-" << cmVS10EscapeXML(api) << "</AndroidTargetAPI>\n";
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteCustomCommands()
+{
+ this->SourcesVisited.clear();
+ std::vector<cmSourceFile const*> customCommands;
+ this->GeneratorTarget->GetCustomCommands(customCommands, "");
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = customCommands.begin();
+ si != customCommands.end(); ++si)
+ {
+ this->WriteCustomCommand(*si);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudio10TargetGenerator
+::WriteCustomCommand(cmSourceFile const* sf)
+{
+ if(this->SourcesVisited.insert(sf).second)
+ {
+ if(std::vector<cmSourceFile*> const* depends =
+ this->GeneratorTarget->GetSourceDepends(sf))
+ {
+ for(std::vector<cmSourceFile*>::const_iterator di = depends->begin();
+ di != depends->end(); ++di)
+ {
+ this->WriteCustomCommand(*di);
+ }
+ }
+ if(cmCustomCommand const* command = sf->GetCustomCommand())
+ {
+ this->WriteString("<ItemGroup>\n", 1);
+ this->WriteCustomRule(sf, *command);
+ this->WriteString("</ItemGroup>\n", 1);
+ }
+ }
+}
+
+void
+cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
+ cmCustomCommand const &
+ command)
+{
+ std::string sourcePath = source->GetFullPath();
+ // VS 10 will always rebuild a custom command attached to a .rule
+ // file that doesn't exist so create the file explicitly.
+ if (source->GetPropertyAsBool("__CMAKE_RULE"))
+ {
+ if(!cmSystemTools::FileExists(sourcePath.c_str()))
+ {
+ // Make sure the path exists for the file
+ std::string path = cmSystemTools::GetFilenamePath(sourcePath);
+ cmSystemTools::MakeDirectory(path.c_str());
+ cmsys::ofstream fout(sourcePath.c_str());
+ if(fout)
+ {
+ fout << "# generated from CMake\n";
+ fout.flush();
+ fout.close();
+ }
+ else
+ {
+ std::string error = "Could not create file: [";
+ error += sourcePath;
+ error += "] ";
+ cmSystemTools::Error
+ (error.c_str(), cmSystemTools::GetLastSystemError().c_str());
+ }
+ }
+ }
+ cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+
+ this->WriteSource("CustomBuild", source, ">\n");
+
+ for(std::vector<std::string>::iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ cmCustomCommandGenerator ccg(command, *i, this->Makefile);
+ std::string comment = lg->ConstructComment(ccg);
+ comment = cmVS10EscapeComment(comment);
+ std::string script =
+ cmVS10EscapeXML(lg->ConstructScript(ccg));
+ this->WritePlatformConfigTag("Message",i->c_str(), 3);
+ (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
+ this->WritePlatformConfigTag("Command", i->c_str(), 3);
+ (*this->BuildFileStream ) << script << "</Command>\n";
+ this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3);
+
+ (*this->BuildFileStream ) << cmVS10EscapeXML(source->GetFullPath());
+ for(std::vector<std::string>::const_iterator d =
+ ccg.GetDepends().begin();
+ d != ccg.GetDepends().end();
+ ++d)
+ {
+ std::string dep;
+ if(this->LocalGenerator->GetRealDependency(d->c_str(), i->c_str(), dep))
+ {
+ this->ConvertToWindowsSlash(dep);
+ (*this->BuildFileStream ) << ";" << cmVS10EscapeXML(dep);
+ }
+ }
+ (*this->BuildFileStream ) << ";%(AdditionalInputs)</AdditionalInputs>\n";
+ this->WritePlatformConfigTag("Outputs", i->c_str(), 3);
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator o =
+ ccg.GetOutputs().begin();
+ o != ccg.GetOutputs().end();
+ ++o)
+ {
+ std::string out = *o;
+ this->ConvertToWindowsSlash(out);
+ (*this->BuildFileStream ) << sep << cmVS10EscapeXML(out);
+ sep = ";";
+ }
+ (*this->BuildFileStream ) << "</Outputs>\n";
+ if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
+ {
+ // VS >= 11 let us turn off linking of custom command outputs.
+ this->WritePlatformConfigTag("LinkObjects", i->c_str(), 3);
+ (*this->BuildFileStream ) << "false</LinkObjects>\n";
+ }
+ }
+ this->WriteString("</CustomBuild>\n", 2);
+}
+
+std::string
+cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path,
+ bool forceRelative)
+{
+ return forceRelative
+ ? cmSystemTools::RelativePath(
+ this->Makefile->GetCurrentOutputDirectory(), path.c_str())
+ : this->LocalGenerator->Convert(path.c_str(),
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED,
+ /* optional = */ true);
+}
+
+void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s)
+{
+ // first convert all of the slashes
+ std::string::size_type pos = 0;
+ while((pos = s.find('/', pos)) != std::string::npos)
+ {
+ s[pos] = '\\';
+ pos++;
+ }
+}
+void cmVisualStudio10TargetGenerator::WriteGroups()
+{
+ // collect up group information
+ std::vector<cmSourceGroup> sourceGroups =
+ this->Makefile->GetSourceGroups();
+ std::vector<cmSourceFile*> classes;
+ if (!this->Target->GetConfigCommonSourceFiles(classes))
+ {
+ return;
+ }
+
+ std::set<cmSourceGroup*> groupsUsed;
+ for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
+ s != classes.end(); s++)
+ {
+ cmSourceFile* sf = *s;
+ std::string const& source = sf->GetFullPath();
+ cmSourceGroup* sourceGroup =
+ this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
+ groupsUsed.insert(sourceGroup);
+ }
+
+ this->AddMissingSourceGroups(groupsUsed, sourceGroups);
+
+ // Write out group file
+ std::string path = this->Makefile->GetStartOutputDirectory();
+ path += "/";
+ path += this->Name;
+ path += ".vcxproj.filters";
+ cmGeneratedFileStream fout(path.c_str());
+ fout.SetCopyIfDifferent(true);
+ char magic[] = {0xEF,0xBB, 0xBF};
+ fout.write(magic, 3);
+ cmGeneratedFileStream* save = this->BuildFileStream;
+ this->BuildFileStream = & fout;
+
+ //get the tools version to use
+ const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
+ std::string project_defaults=
+ "<?xml version=\"1.0\" encoding=\"" +
+ this->GlobalGenerator->Encoding() + "\"?>\n";
+ project_defaults.append("<Project ToolsVersion=\"");
+ project_defaults.append(toolsVer +"\" ");
+ project_defaults.append(
+ "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
+ this->WriteString(project_defaults.c_str(),0);
+
+ for(ToolSourceMap::const_iterator ti = this->Tools.begin();
+ ti != this->Tools.end(); ++ti)
+ {
+ this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups);
+ }
+
+ // Added files are images and the manifest.
+ if (!this->AddedFiles.empty())
+ {
+ this->WriteString("<ItemGroup>\n", 1);
+ for(std::vector<std::string>::const_iterator
+ oi = this->AddedFiles.begin(); oi != this->AddedFiles.end(); ++oi)
+ {
+ std::string fileName = cmSystemTools::LowerCase(
+ cmSystemTools::GetFilenameName(*oi));
+ if (fileName == "wmappmanifest.xml")
+ {
+ this->WriteString("<XML Include=\"", 2);
+ (*this->BuildFileStream) << *oi << "\">\n";
+ this->WriteString("<Filter>Resource Files</Filter>\n", 3);
+ this->WriteString("</XML>\n", 2);
+ }
+ else if(cmSystemTools::GetFilenameExtension(fileName) ==
+ ".appxmanifest")
+ {
+ this->WriteString("<AppxManifest Include=\"", 2);
+ (*this->BuildFileStream) << *oi << "\">\n";
+ this->WriteString("<Filter>Resource Files</Filter>\n", 3);
+ this->WriteString("</AppxManifest>\n", 2);
+ }
+ else if(cmSystemTools::GetFilenameExtension(fileName) ==
+ ".pfx")
+ {
+ this->WriteString("<None Include=\"", 2);
+ (*this->BuildFileStream) << *oi << "\">\n";
+ this->WriteString("<Filter>Resource Files</Filter>\n", 3);
+ this->WriteString("</None>\n", 2);
+ }
+ else
+ {
+ this->WriteString("<Image Include=\"", 2);
+ (*this->BuildFileStream) << *oi << "\">\n";
+ this->WriteString("<Filter>Resource Files</Filter>\n", 3);
+ this->WriteString("</Image>\n", 2);
+ }
+ }
+ this->WriteString("</ItemGroup>\n", 1);
+ }
+
+ std::vector<cmSourceFile const*> resxObjs;
+ this->GeneratorTarget->GetResxSources(resxObjs, "");
+ if(!resxObjs.empty())
+ {
+ this->WriteString("<ItemGroup>\n", 1);
+ for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
+ oi != resxObjs.end(); ++oi)
+ {
+ std::string obj = (*oi)->GetFullPath();
+ this->WriteString("<EmbeddedResource Include=\"", 2);
+ this->ConvertToWindowsSlash(obj);
+ (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
+ this->WriteString("<Filter>Resource Files</Filter>\n", 3);
+ this->WriteString("</EmbeddedResource>\n", 2);
+ }
+ this->WriteString("</ItemGroup>\n", 1);
+ }
+
+ // Add object library contents as external objects.
+ std::vector<std::string> objs;
+ this->GeneratorTarget->UseObjectLibraries(objs, "");
+ if(!objs.empty())
+ {
+ this->WriteString("<ItemGroup>\n", 1);
+ for(std::vector<std::string>::const_iterator
+ oi = objs.begin(); oi != objs.end(); ++oi)
+ {
+ std::string obj = *oi;
+ this->WriteString("<Object Include=\"", 2);
+ this->ConvertToWindowsSlash(obj);
+ (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
+ this->WriteString("<Filter>Object Libraries</Filter>\n", 3);
+ this->WriteString("</Object>\n", 2);
+ }
+ this->WriteString("</ItemGroup>\n", 1);
+ }
+
+ this->WriteString("<ItemGroup>\n", 1);
+ for(std::set<cmSourceGroup*>::iterator g = groupsUsed.begin();
+ g != groupsUsed.end(); ++g)
+ {
+ cmSourceGroup* sg = *g;
+ const char* name = sg->GetFullName();
+ if(strlen(name) != 0)
+ {
+ this->WriteString("<Filter Include=\"", 2);
+ (*this->BuildFileStream) << name << "\">\n";
+ std::string guidName = "SG_Filter_";
+ guidName += name;
+ this->GlobalGenerator->CreateGUID(guidName.c_str());
+ this->WriteString("<UniqueIdentifier>", 3);
+ std::string guid
+ = this->GlobalGenerator->GetGUID(guidName.c_str());
+ (*this->BuildFileStream)
+ << "{"
+ << guid << "}"
+ << "</UniqueIdentifier>\n";
+ this->WriteString("</Filter>\n", 2);
+ }
+ }
+ if(!objs.empty())
+ {
+ this->WriteString("<Filter Include=\"Object Libraries\">\n", 2);
+ std::string guidName = "SG_Filter_Object Libraries";
+ this->GlobalGenerator->CreateGUID(guidName.c_str());
+ this->WriteString("<UniqueIdentifier>", 3);
+ std::string guid =
+ this->GlobalGenerator->GetGUID(guidName.c_str());
+ (*this->BuildFileStream) << "{" << guid << "}"
+ << "</UniqueIdentifier>\n";
+ this->WriteString("</Filter>\n", 2);
+ }
+
+ if(!resxObjs.empty() || !this->AddedFiles.empty())
+ {
+ this->WriteString("<Filter Include=\"Resource Files\">\n", 2);
+ std::string guidName = "SG_Filter_Resource Files";
+ this->GlobalGenerator->CreateGUID(guidName.c_str());
+ this->WriteString("<UniqueIdentifier>", 3);
+ std::string guid =
+ this->GlobalGenerator->GetGUID(guidName.c_str());
+ (*this->BuildFileStream) << "{" << guid << "}"
+ << "</UniqueIdentifier>\n";
+ this->WriteString("<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;", 3);
+ (*this->BuildFileStream) << "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;";
+ (*this->BuildFileStream) << "mfcribbon-ms</Extensions>\n";
+ this->WriteString("</Filter>\n", 2);
+ }
+
+ this->WriteString("</ItemGroup>\n", 1);
+ this->WriteString("</Project>\n", 0);
+ // restore stream pointer
+ this->BuildFileStream = save;
+
+ if (fout.Close())
+ {
+ this->GlobalGenerator->FileReplacedDuringGenerate(path);
+ }
+}
+
+// Add to groupsUsed empty source groups that have non-empty children.
+void
+cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
+ std::set<cmSourceGroup*>& groupsUsed,
+ const std::vector<cmSourceGroup>& allGroups
+ )
+{
+ for(std::vector<cmSourceGroup>::const_iterator current = allGroups.begin();
+ current != allGroups.end(); ++current)
+ {
+ std::vector<cmSourceGroup> const& children = current->GetGroupChildren();
+ if(children.empty())
+ {
+ continue; // the group is really empty
+ }
+
+ this->AddMissingSourceGroups(groupsUsed, children);
+
+ cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(&(*current));
+ if(groupsUsed.find(current_ptr) != groupsUsed.end())
+ {
+ continue; // group has already been added to set
+ }
+
+ // check if it least one of the group's descendants is not empty
+ // (at least one child must already have been added)
+ std::vector<cmSourceGroup>::const_iterator child_it = children.begin();
+ while(child_it != children.end())
+ {
+ cmSourceGroup* child_ptr = const_cast<cmSourceGroup*>(&(*child_it));
+ if(groupsUsed.find(child_ptr) != groupsUsed.end())
+ {
+ break; // found a child that was already added => add current group too
+ }
+ child_it++;
+ }
+
+ if(child_it == children.end())
+ {
+ continue; // no descendants have source files => ignore this group
+ }
+
+ groupsUsed.insert(current_ptr);
+ }
+}
+
+void
+cmVisualStudio10TargetGenerator::
+WriteGroupSources(const char* name,
+ ToolSources const& sources,
+ std::vector<cmSourceGroup>& sourceGroups)
+{
+ this->WriteString("<ItemGroup>\n", 1);
+ for(ToolSources::const_iterator s = sources.begin();
+ s != sources.end(); ++s)
+ {
+ cmSourceFile const* sf = s->SourceFile;
+ std::string const& source = sf->GetFullPath();
+ cmSourceGroup* sourceGroup =
+ this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
+ const char* filter = sourceGroup->GetFullName();
+ this->WriteString("<", 2);
+ std::string path = this->ConvertPath(source, s->RelativePath);
+ this->ConvertToWindowsSlash(path);
+ (*this->BuildFileStream) << name << " Include=\""
+ << cmVS10EscapeXML(path);
+ if(strlen(filter))
+ {
+ (*this->BuildFileStream) << "\">\n";
+ this->WriteString("<Filter>", 3);
+ (*this->BuildFileStream) << filter << "</Filter>\n";
+ this->WriteString("</", 2);
+ (*this->BuildFileStream) << name << ">\n";
+ }
+ else
+ {
+ (*this->BuildFileStream) << "\" />\n";
+ }
+ }
+ this->WriteString("</ItemGroup>\n", 1);
+}
+
+void cmVisualStudio10TargetGenerator::WriteHeaderSource(cmSourceFile const* sf)
+{
+ if(this->IsResxHeader(sf->GetFullPath()))
+ {
+ this->WriteSource("ClInclude", sf, ">\n");
+ this->WriteString("<FileType>CppForm</FileType>\n", 3);
+ this->WriteString("</ClInclude>\n", 2);
+ }
+ else
+ {
+ this->WriteSource("ClInclude", sf);
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
+{
+ bool toolHasSettings = false;
+ std::string tool = "None";
+ std::string shaderType;
+ std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
+ if(ext == "hlsl")
+ {
+ tool = "FXCompile";
+ // Figure out the type of shader compiler to use.
+ if(const char* st = sf->GetProperty("VS_SHADER_TYPE"))
+ {
+ shaderType = st;
+ toolHasSettings = true;
+ }
+ }
+ else if(ext == "jpg" ||
+ ext == "png")
+ {
+ tool = "Image";
+ }
+ else if(ext == "xml")
+ {
+ tool = "XML";
+ }
+ if(this->NsightTegra)
+ {
+ // Nsight Tegra needs specific file types to check up-to-dateness.
+ std::string name =
+ cmSystemTools::LowerCase(sf->GetLocation().GetName());
+ if(name == "androidmanifest.xml" ||
+ name == "build.xml" ||
+ name == "proguard.cfg" ||
+ name == "proguard-project.txt" ||
+ ext == "properties")
+ {
+ tool = "AndroidBuild";
+ }
+ else if(ext == "java")
+ {
+ tool = "JCompile";
+ }
+ else if(ext == "asm" || ext == "s")
+ {
+ tool = "ClCompile";
+ }
+ }
+
+ std::string deployContent;
+ if(this->GlobalGenerator->TargetsWindowsPhone() ||
+ this->GlobalGenerator->TargetsWindowsStore())
+ {
+ const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
+ if(content && *content)
+ {
+ toolHasSettings = true;
+ deployContent = content;
+ }
+ }
+
+ if(toolHasSettings)
+ {
+ this->WriteSource(tool, sf, ">\n");
+
+ if(!deployContent.empty())
+ {
+ std::vector<std::string> const* configs =
+ this->GlobalGenerator->GetConfigurations();
+ cmGeneratorExpression ge;
+ cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(deployContent);
+ for(size_t i = 0; i != configs->size(); ++i)
+ {
+ if(0 == strcmp(cge->Evaluate(this->Makefile, (*configs)[i]), "1"))
+ {
+ this->WriteString("<DeploymentContent Condition=\""
+ "'$(Configuration)|$(Platform)'=='", 3);
+ (*this->BuildFileStream) << (*configs)[i] << "|"
+ << this->Platform << "'\">true";
+ this->WriteString("</DeploymentContent>\n", 0);
+ }
+ else
+ {
+ this->WriteString("<ExcludedFromBuild Condition=\""
+ "'$(Configuration)|$(Platform)'=='", 3);
+ (*this->BuildFileStream) << (*configs)[i] << "|"
+ << this->Platform << "'\">true";
+ this->WriteString("</ExcludedFromBuild>\n", 0);
+ }
+ }
+ }
+ if(!shaderType.empty())
+ {
+ this->WriteString("<ShaderType>", 3);
+ (*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
+ << "</ShaderType>\n";
+ }
+
+ this->WriteString("</", 2);
+ (*this->BuildFileStream) << tool << ">\n";
+ }
+ else
+ {
+ this->WriteSource(tool, sf);
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteSource(
+ std::string const& tool, cmSourceFile const* sf, const char* end)
+{
+ // Visual Studio tools append relative paths to the current dir, as in:
+ //
+ // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
+ //
+ // and fail if this exceeds the maximum allowed path length. Our path
+ // conversion uses full paths when possible to allow deeper trees.
+ bool forceRelative = false;
+ std::string sourceFile = this->ConvertPath(sf->GetFullPath(), false);
+ if(this->LocalGenerator->GetVersion() == cmLocalVisualStudioGenerator::VS10
+ && cmSystemTools::FileIsFullPath(sourceFile.c_str()))
+ {
+ // Normal path conversion resulted in a full path. VS 10 (but not 11)
+ // refuses to show the property page in the IDE for a source file with a
+ // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
+ // relative path but to allow deeper build trees CMake 2.8.[5678] used a
+ // full path except for custom commands. Custom commands do not work
+ // without a relative path, but they do not seem to be involved in tools
+ // with the above behavior. For other sources we now use a relative path
+ // when the combined path will not be too long so property pages appear.
+ std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
+ size_t const maxLen = 250;
+ if(sf->GetCustomCommand() ||
+ ((strlen(this->Makefile->GetCurrentOutputDirectory()) + 1 +
+ sourceRel.length()) <= maxLen))
+ {
+ forceRelative = true;
+ sourceFile = sourceRel;
+ }
+ else
+ {
+ this->GlobalGenerator->PathTooLong(this->Target, sf, sourceRel);
+ }
+ }
+ this->ConvertToWindowsSlash(sourceFile);
+ this->WriteString("<", 2);
+ (*this->BuildFileStream ) << tool << " Include=\""
+ << cmVS10EscapeXML(sourceFile) << "\""
+ << (end? end : " />\n");
+
+ ToolSource toolSource = {sf, forceRelative};
+ this->Tools[tool].push_back(toolSource);
+}
+
+void cmVisualStudio10TargetGenerator::WriteSources(
+ std::string const& tool, std::vector<cmSourceFile const*> const& sources)
+{
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = sources.begin(); si != sources.end(); ++si)
+ {
+ this->WriteSource(tool, *si);
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteAllSources()
+{
+ if(this->Target->GetType() > cmTarget::UTILITY)
+ {
+ return;
+ }
+ this->WriteString("<ItemGroup>\n", 1);
+
+ std::vector<cmSourceFile const*> headerSources;
+ this->GeneratorTarget->GetHeaderSources(headerSources, "");
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = headerSources.begin(); si != headerSources.end(); ++si)
+ {
+ this->WriteHeaderSource(*si);
+ }
+ std::vector<cmSourceFile const*> idlSources;
+ this->GeneratorTarget->GetIDLSources(idlSources, "");
+ this->WriteSources("Midl", idlSources);
+
+ std::vector<cmSourceFile const*> objectSources;
+ this->GeneratorTarget->GetObjectSources(objectSources, "");
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = objectSources.begin();
+ si != objectSources.end(); ++si)
+ {
+ const std::string& lang = (*si)->GetLanguage();
+ std::string tool;
+ if (lang == "C"|| lang == "CXX")
+ {
+ tool = "ClCompile";
+ }
+ else if (lang == "ASM_MASM" &&
+ this->GlobalGenerator->IsMasmEnabled())
+ {
+ tool = "MASM";
+ }
+ else if (lang == "RC")
+ {
+ tool = "ResourceCompile";
+ }
+
+ if (!tool.empty())
+ {
+ this->WriteSource(tool, *si, " ");
+ if (this->OutputSourceSpecificFlags(*si))
+ {
+ this->WriteString("</", 2);
+ (*this->BuildFileStream ) << tool << ">\n";
+ }
+ else
+ {
+ (*this->BuildFileStream ) << " />\n";
+ }
+ }
+ else
+ {
+ this->WriteSource("None", *si);
+ }
+ }
+
+ std::vector<cmSourceFile const*> manifestSources;
+ this->GeneratorTarget->GetAppManifest(manifestSources, "");
+ this->WriteSources("AppxManifest", manifestSources);
+
+ std::vector<cmSourceFile const*> certificateSources;
+ this->GeneratorTarget->GetCertificates(certificateSources, "");
+ this->WriteSources("None", certificateSources);
+
+ std::vector<cmSourceFile const*> externalObjects;
+ this->GeneratorTarget->GetExternalObjects(externalObjects, "");
+ for(std::vector<cmSourceFile const*>::iterator
+ si = externalObjects.begin();
+ si != externalObjects.end(); )
+ {
+ if (!(*si)->GetObjectLibrary().empty())
+ {
+ si = externalObjects.erase(si);
+ }
+ else
+ {
+ ++si;
+ }
+ }
+ if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
+ {
+ // For VS >= 11 we use LinkObjects to avoid linking custom command
+ // outputs. Use Object for all external objects, generated or not.
+ this->WriteSources("Object", externalObjects);
+ }
+ else
+ {
+ // If an object file is generated in this target, then vs10 will use
+ // it in the build, and we have to list it as None instead of Object.
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = externalObjects.begin();
+ si != externalObjects.end(); ++si)
+ {
+ std::vector<cmSourceFile*> const* d =
+ this->GeneratorTarget->GetSourceDepends(*si);
+ this->WriteSource((d && !d->empty())? "None":"Object", *si);
+ }
+ }
+
+ std::vector<cmSourceFile const*> extraSources;
+ this->GeneratorTarget->GetExtraSources(extraSources, "");
+ for(std::vector<cmSourceFile const*>::const_iterator
+ si = extraSources.begin(); si != extraSources.end(); ++si)
+ {
+ this->WriteExtraSource(*si);
+ }
+
+ // Add object library contents as external objects.
+ std::vector<std::string> objs;
+ this->GeneratorTarget->UseObjectLibraries(objs, "");
+ for(std::vector<std::string>::const_iterator
+ oi = objs.begin(); oi != objs.end(); ++oi)
+ {
+ std::string obj = *oi;
+ this->WriteString("<Object Include=\"", 2);
+ this->ConvertToWindowsSlash(obj);
+ (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\" />\n";
+ }
+
+ if (this->IsMissingFiles)
+ {
+ this->WriteMissingFiles();
+ }
+
+ this->WriteString("</ItemGroup>\n", 1);
+}
+
+bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
+ cmSourceFile const* source)
+{
+ cmSourceFile const& sf = *source;
+
+ std::string objectName;
+ if(this->GeneratorTarget->HasExplicitObjectName(&sf))
+ {
+ objectName = this->GeneratorTarget->GetObjectName(&sf);
+ }
+ std::string flags;
+ std::string defines;
+ if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
+ {
+ flags += cflags;
+ }
+ if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
+ {
+ defines += cdefs;
+ }
+ std::string lang =
+ this->GlobalGenerator->GetLanguageFromExtension
+ (sf.GetExtension().c_str());
+ std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
+ const std::string& linkLanguage = this->Target->GetLinkerLanguage();
+ bool needForceLang = false;
+ // source file does not match its extension language
+ if(lang != sourceLang)
+ {
+ needForceLang = true;
+ lang = sourceLang;
+ }
+ // if the source file does not match the linker language
+ // then force c or c++
+ const char* compileAs = 0;
+ if(needForceLang || (linkLanguage != lang))
+ {
+ if(lang == "CXX")
+ {
+ // force a C++ file type
+ compileAs = "CompileAsCpp";
+ }
+ else if(lang == "C")
+ {
+ // force to c
+ compileAs = "CompileAsC";
+ }
+ }
+ bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
+ bool hasFlags = false;
+ // for the first time we need a new line if there is something
+ // produced here.
+ const char* firstString = ">\n";
+ if(objectName.size())
+ {
+ (*this->BuildFileStream ) << firstString;
+ firstString = "";
+ hasFlags = true;
+ this->WriteString("<ObjectFileName>", 3);
+ (*this->BuildFileStream )
+ << "$(IntDir)/" << objectName << "</ObjectFileName>\n";
+ }
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+ for( std::vector<std::string>::iterator config = configs->begin();
+ config != configs->end(); ++config)
+ {
+ std::string configUpper = cmSystemTools::UpperCase(*config);
+ std::string configDefines = defines;
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += configUpper;
+ if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
+ {
+ if(configDefines.size())
+ {
+ configDefines += ";";
+ }
+ configDefines += ccdefs;
+ }
+ // if we have flags or defines for this config then
+ // use them
+ if(!flags.empty() || !configDefines.empty() || compileAs || noWinRT)
+ {
+ (*this->BuildFileStream ) << firstString;
+ firstString = ""; // only do firstString once
+ hasFlags = true;
+ cmVisualStudioGeneratorOptions
+ clOptions(this->LocalGenerator,
+ cmVisualStudioGeneratorOptions::Compiler,
+ this->GetClFlagTable(), 0, this);
+ if(compileAs)
+ {
+ clOptions.AddFlag("CompileAs", compileAs);
+ }
+ if(noWinRT)
+ {
+ clOptions.AddFlag("CompileAsWinRT", "false");
+ }
+ clOptions.Parse(flags.c_str());
+ if(clOptions.HasFlag("AdditionalIncludeDirectories"))
+ {
+ clOptions.AppendFlag("AdditionalIncludeDirectories",
+ "%(AdditionalIncludeDirectories)");
+ }
+ clOptions.AddDefines(configDefines.c_str());
+ clOptions.SetConfiguration((*config).c_str());
+ clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
+ clOptions.OutputFlagMap(*this->BuildFileStream, " ");
+ clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream,
+ " ", "\n", lang);
+ }
+ }
+ return hasFlags;
+}
+
+
+void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
+{
+ cmTarget::TargetType ttype = this->Target->GetType();
+ if(ttype > cmTarget::GLOBAL_TARGET)
+ {
+ return;
+ }
+
+ this->WriteString("<PropertyGroup>\n", 2);
+ this->WriteString("<_ProjectFileVersion>10.0.20506.1"
+ "</_ProjectFileVersion>\n", 3);
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+ for(std::vector<std::string>::iterator config = configs->begin();
+ config != configs->end(); ++config)
+ {
+ if(ttype >= cmTarget::UTILITY)
+ {
+ this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
+ *this->BuildFileStream
+ << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
+ << "</IntDir>\n";
+ }
+ else
+ {
+ std::string intermediateDir = this->LocalGenerator->
+ GetTargetDirectory(*this->Target);
+ intermediateDir += "/";
+ intermediateDir += *config;
+ intermediateDir += "/";
+ std::string outDir;
+ std::string targetNameFull;
+ if(ttype == cmTarget::OBJECT_LIBRARY)
+ {
+ outDir = intermediateDir;
+ targetNameFull = this->Target->GetName();
+ targetNameFull += ".lib";
+ }
+ else
+ {
+ outDir = this->Target->GetDirectory(config->c_str()) + "/";
+ targetNameFull = this->Target->GetFullName(config->c_str());
+ }
+ this->ConvertToWindowsSlash(intermediateDir);
+ this->ConvertToWindowsSlash(outDir);
+
+ this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
+ *this->BuildFileStream << cmVS10EscapeXML(outDir)
+ << "</OutDir>\n";
+
+ this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
+ *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
+ << "</IntDir>\n";
+
+ std::string name =
+ cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
+ this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
+ *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
+
+ std::string ext =
+ cmSystemTools::GetFilenameLastExtension(targetNameFull);
+ if(ext.empty())
+ {
+ // An empty TargetExt causes a default extension to be used.
+ // A single "." appears to be treated as an empty extension.
+ ext = ".";
+ }
+ this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
+ *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
+
+ this->OutputLinkIncremental(*config);
+ }
+ }
+ this->WriteString("</PropertyGroup>\n", 2);
+}
+
+
+
+void
+cmVisualStudio10TargetGenerator::
+OutputLinkIncremental(std::string const& configName)
+{
+ if(!this->MSTools)
+ {
+ return;
+ }
+ // 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)
+ {
+ return;
+ }
+ Options& linkOptions = *(this->LinkOptions[configName]);
+
+ const char* incremental = linkOptions.GetFlag("LinkIncremental");
+ this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
+ *this->BuildFileStream << (incremental?incremental:"true")
+ << "</LinkIncremental>\n";
+ linkOptions.RemoveFlag("LinkIncremental");
+
+ const char* manifest = linkOptions.GetFlag("GenerateManifest");
+ this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
+ *this->BuildFileStream << (manifest?manifest:"true")
+ << "</GenerateManifest>\n";
+ linkOptions.RemoveFlag("GenerateManifest");
+
+ // Some link options belong here. Use them now and remove them so that
+ // WriteLinkOptions does not use them.
+ const char* flags[] = {
+ "LinkDelaySign",
+ "LinkKeyFile",
+ 0};
+ for(const char** f = flags; *f; ++f)
+ {
+ const char* flag = *f;
+ if(const char* value = linkOptions.GetFlag(flag))
+ {
+ this->WritePlatformConfigTag(flag, configName.c_str(), 3);
+ *this->BuildFileStream << value << "</" << flag << ">\n";
+ linkOptions.RemoveFlag(flag);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudio10TargetGenerator::ComputeClOptions()
+{
+ std::vector<std::string> const* configs =
+ this->GlobalGenerator->GetConfigurations();
+ for(std::vector<std::string>::const_iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ if(!this->ComputeClOptions(*i))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudio10TargetGenerator::ComputeClOptions(
+ std::string const& configName)
+{
+ // much of this was copied from here:
+ // copied from cmLocalVisualStudio7Generator.cxx 805
+ // TODO: Integrate code below with cmLocalVisualStudio7Generator.
+
+ cmsys::auto_ptr<Options> pOptions(
+ new Options(this->LocalGenerator, Options::Compiler,
+ this->GetClFlagTable()));
+ Options& clOptions = *pOptions;
+
+ std::string flags;
+ const std::string& linkLanguage =
+ this->Target->GetLinkerLanguage(configName.c_str());
+ if(linkLanguage.empty())
+ {
+ cmSystemTools::Error
+ ("CMake can not determine linker language for target: ",
+ this->Name.c_str());
+ return false;
+ }
+ if(linkLanguage == "C" || linkLanguage == "CXX"
+ || linkLanguage == "Fortran")
+ {
+ std::string baseFlagVar = "CMAKE_";
+ baseFlagVar += linkLanguage;
+ baseFlagVar += "_FLAGS";
+ flags = this->
+ Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
+ std::string flagVar = baseFlagVar + std::string("_") +
+ cmSystemTools::UpperCase(configName);
+ flags += " ";
+ flags += this->
+ Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
+ }
+ // set the correct language
+ if(linkLanguage == "C")
+ {
+ clOptions.AddFlag("CompileAs", "CompileAsC");
+ }
+ if(linkLanguage == "CXX")
+ {
+ clOptions.AddFlag("CompileAs", "CompileAsCpp");
+ }
+ this->LocalGenerator->AddCompileOptions(flags, this->Target,
+ linkLanguage, configName.c_str());
+
+ // Get preprocessor definitions for this directory.
+ std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
+ if(this->MSTools)
+ {
+ clOptions.FixExceptionHandlingDefault();
+ clOptions.AddFlag("PrecompiledHeader", "NotUsing");
+ std::string asmLocation = configName + "/";
+ clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
+ }
+ clOptions.Parse(flags.c_str());
+ clOptions.Parse(defineFlags.c_str());
+ std::vector<std::string> targetDefines;
+ this->Target->GetCompileDefinitions(targetDefines, configName.c_str());
+ clOptions.AddDefines(targetDefines);
+ if(this->MSTools)
+ {
+ clOptions.SetVerboseMakefile(
+ this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
+ }
+
+ // Add a definition for the configuration name.
+ std::string configDefine = "CMAKE_INTDIR=\"";
+ configDefine += configName;
+ configDefine += "\"";
+ clOptions.AddDefine(configDefine);
+ if(const char* exportMacro = this->Target->GetExportMacro())
+ {
+ clOptions.AddDefine(exportMacro);
+ }
+
+ if (this->MSTools)
+ {
+ // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
+ if (this->Target->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 )
+ {
+ clOptions.AddDefine("_WINRT_DLL");
+ }
+ }
+ else if (this->GlobalGenerator->TargetsWindowsStore() ||
+ this->GlobalGenerator->TargetsWindowsPhone())
+ {
+ if (!clOptions.IsWinRt())
+ {
+ clOptions.AddFlag("CompileAsWinRT", "false");
+ }
+ }
+ if(const char* winRT = clOptions.GetFlag("CompileAsWinRT"))
+ {
+ if(cmSystemTools::IsOn(winRT))
+ {
+ this->TargetCompileAsWinRT = true;
+ }
+ }
+ }
+
+ this->ClOptions[configName] = pOptions.release();
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudio10TargetGenerator::WriteClOptions(
+ std::string const& configName,
+ std::vector<std::string> const& includes)
+{
+ Options& clOptions = *(this->ClOptions[configName]);
+ this->WriteString("<ClCompile>\n", 2);
+ clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
+ clOptions.AppendFlag("AdditionalIncludeDirectories", includes);
+ clOptions.AppendFlag("AdditionalIncludeDirectories",
+ "%(AdditionalIncludeDirectories)");
+ clOptions.OutputFlagMap(*this->BuildFileStream, " ");
+ clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
+ "\n", "CXX");
+
+ if(this->MSTools)
+ {
+ this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
+
+ // If not in debug mode, write the DebugInformationFormat field
+ // without value so PDBs don't get generated uselessly.
+ if(!clOptions.IsDebug())
+ {
+ this->WriteString("<DebugInformationFormat>"
+ "</DebugInformationFormat>\n", 3);
+ }
+
+ // Specify the compiler program database file if configured.
+ std::string pdb = this->Target->GetCompilePDBPath(configName.c_str());
+ if(!pdb.empty())
+ {
+ this->ConvertToWindowsSlash(pdb);
+ this->WriteString("<ProgramDataBaseFileName>", 3);
+ *this->BuildFileStream << cmVS10EscapeXML(pdb)
+ << "</ProgramDataBaseFileName>\n";
+ }
+ }
+
+ this->WriteString("</ClCompile>\n", 2);
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
+{
+ std::vector<std::string> const* configs =
+ this->GlobalGenerator->GetConfigurations();
+ for(std::vector<std::string>::const_iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ if(!this->ComputeRcOptions(*i))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
+ std::string const& configName)
+{
+ cmsys::auto_ptr<Options> pOptions(
+ new Options(this->LocalGenerator, Options::ResourceCompiler,
+ this->GetRcFlagTable()));
+ Options& rcOptions = *pOptions;
+
+ std::string CONFIG = cmSystemTools::UpperCase(configName);
+ std::string rcConfigFlagsVar = std::string("CMAKE_RC_FLAGS_") + CONFIG;
+ std::string flags =
+ std::string(this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS")) +
+ std::string(" ") +
+ std::string(this->Makefile->GetSafeDefinition(rcConfigFlagsVar));
+
+ rcOptions.Parse(flags.c_str());
+ this->RcOptions[configName] = pOptions.release();
+ return true;
+}
+
+void cmVisualStudio10TargetGenerator::
+WriteRCOptions(std::string const& configName,
+ std::vector<std::string> const & includes)
+{
+ if(!this->MSTools)
+ {
+ return;
+ }
+ this->WriteString("<ResourceCompile>\n", 2);
+
+ // Preprocessor definitions and includes are shared with clOptions.
+ Options& clOptions = *(this->ClOptions[configName]);
+ clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
+ "\n", "RC");
+
+ Options& rcOptions = *(this->RcOptions[configName]);
+ rcOptions.AppendFlag("AdditionalIncludeDirectories", includes);
+ rcOptions.AppendFlag("AdditionalIncludeDirectories",
+ "%(AdditionalIncludeDirectories)");
+ rcOptions.OutputFlagMap(*this->BuildFileStream, " ");
+ rcOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
+
+ this->WriteString("</ResourceCompile>\n", 2);
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
+{
+ if(!this->GlobalGenerator->IsMasmEnabled())
+ {
+ return true;
+ }
+ std::vector<std::string> const* configs =
+ this->GlobalGenerator->GetConfigurations();
+ for(std::vector<std::string>::const_iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ if(!this->ComputeMasmOptions(*i))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
+ std::string const& configName)
+{
+ cmsys::auto_ptr<Options> pOptions(
+ new Options(this->LocalGenerator, Options::MasmCompiler,
+ this->GetMasmFlagTable()));
+ Options& masmOptions = *pOptions;
+
+ std::string CONFIG = cmSystemTools::UpperCase(configName);
+ std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG;
+ std::string flags =
+ std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS")) +
+ std::string(" ") +
+ std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
+
+ masmOptions.Parse(flags.c_str());
+ this->MasmOptions[configName] = pOptions.release();
+ return true;
+}
+
+void cmVisualStudio10TargetGenerator::
+WriteMasmOptions(std::string const& configName,
+ std::vector<std::string> const& includes)
+{
+ if(!this->MSTools || !this->GlobalGenerator->IsMasmEnabled())
+ {
+ return;
+ }
+ this->WriteString("<MASM>\n", 2);
+
+ // Preprocessor definitions and includes are shared with clOptions.
+ Options& clOptions = *(this->ClOptions[configName]);
+ clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
+ "\n", "ASM_MASM");
+
+ Options& masmOptions = *(this->MasmOptions[configName]);
+ masmOptions.AppendFlag("IncludePaths", includes);
+ masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
+ masmOptions.OutputFlagMap(*this->BuildFileStream, " ");
+ masmOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
+
+ this->WriteString("</MASM>\n", 2);
+}
+
+
+void
+cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
+{
+ if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
+ {
+ return;
+ }
+ std::string libflags;
+ this->LocalGenerator->GetStaticLibraryFlags(libflags,
+ cmSystemTools::UpperCase(config), this->Target);
+ if(!libflags.empty())
+ {
+ this->WriteString("<Lib>\n", 2);
+ cmVisualStudioGeneratorOptions
+ libOptions(this->LocalGenerator,
+ cmVisualStudioGeneratorOptions::Linker,
+ this->GetLibFlagTable(), 0, this);
+ libOptions.Parse(libflags.c_str());
+ libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
+ libOptions.OutputFlagMap(*this->BuildFileStream, " ");
+ this->WriteString("</Lib>\n", 2);
+ }
+
+ // We cannot generate metadata for static libraries. WindowsPhone
+ // and WindowsStore tools look at GenerateWindowsMetadata in the
+ // Link tool options even for static libraries.
+ if(this->GlobalGenerator->TargetsWindowsPhone() ||
+ this->GlobalGenerator->TargetsWindowsStore())
+ {
+ this->WriteString("<Link>\n", 2);
+ this->WriteString("<GenerateWindowsMetadata>false"
+ "</GenerateWindowsMetadata>\n", 3);
+ this->WriteString("</Link>\n", 2);
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
+ std::string const&)
+{
+ // Look through the sources for AndroidManifest.xml and use
+ // its location as the root source directory.
+ std::string rootDir = this->Makefile->GetCurrentDirectory();
+ {
+ std::vector<cmSourceFile const*> extraSources;
+ this->GeneratorTarget->GetExtraSources(extraSources, "");
+ for(std::vector<cmSourceFile const*>::const_iterator si =
+ extraSources.begin(); si != extraSources.end(); ++si)
+ {
+ if("androidmanifest.xml" == cmSystemTools::LowerCase(
+ (*si)->GetLocation().GetName()))
+ {
+ rootDir = (*si)->GetLocation().GetDirectory();
+ break;
+ }
+ }
+ }
+
+ // Tell MSBuild to launch Ant.
+ {
+ std::string antBuildPath = rootDir;
+ this->WriteString("<AntBuild>\n", 2);
+ this->WriteString("<AntBuildPath>", 3);
+ this->ConvertToWindowsSlash(antBuildPath);
+ (*this->BuildFileStream) <<
+ cmVS10EscapeXML(antBuildPath) << "</AntBuildPath>\n";
+ }
+
+ {
+ std::string manifest_xml = rootDir + "/AndroidManifest.xml";
+ this->ConvertToWindowsSlash(manifest_xml);
+ this->WriteString("<AndroidManifestLocation>", 3);
+ (*this->BuildFileStream) <<
+ cmVS10EscapeXML(manifest_xml) << "</AndroidManifestLocation>\n";
+ }
+
+ this->WriteString("</AntBuild>\n", 2);
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
+{
+ if(this->Target->GetType() == cmTarget::EXECUTABLE ||
+ this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
+ this->Target->GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ std::vector<std::string> const* configs =
+ this->GlobalGenerator->GetConfigurations();
+ for(std::vector<std::string>::const_iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ if(!this->ComputeLinkOptions(*i))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
+{
+ cmsys::auto_ptr<Options> pOptions(
+ new Options(this->LocalGenerator, Options::Linker,
+ this->GetLinkFlagTable(), 0, this));
+ Options& linkOptions = *pOptions;
+
+ const std::string& linkLanguage =
+ this->Target->GetLinkerLanguage(config.c_str());
+ if(linkLanguage.empty())
+ {
+ cmSystemTools::Error
+ ("CMake can not determine linker language for target: ",
+ this->Name.c_str());
+ return false;
+ }
+
+ std::string CONFIG = cmSystemTools::UpperCase(config);
+
+ const char* linkType = "SHARED";
+ if(this->Target->GetType() == cmTarget::MODULE_LIBRARY)
+ {
+ linkType = "MODULE";
+ }
+ if(this->Target->GetType() == cmTarget::EXECUTABLE)
+ {
+ linkType = "EXE";
+ }
+ std::string flags;
+ std::string linkFlagVarBase = "CMAKE_";
+ linkFlagVarBase += linkType;
+ linkFlagVarBase += "_LINKER_FLAGS";
+ flags += " ";
+ flags += this->
+ Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
+ std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
+ flags += " ";
+ flags += this->
+ Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
+ const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
+ if(targetLinkFlags)
+ {
+ flags += " ";
+ flags += targetLinkFlags;
+ }
+ std::string flagsProp = "LINK_FLAGS_";
+ flagsProp += CONFIG;
+ if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
+ {
+ flags += " ";
+ flags += flagsConfig;
+ }
+ std::string standardLibsVar = "CMAKE_";
+ standardLibsVar += linkLanguage;
+ standardLibsVar += "_STANDARD_LIBRARIES";
+ std::string
+ libs = this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
+ // Remove trailing spaces from libs
+ std::string::size_type pos = libs.size()-1;
+ if(libs.size() != 0)
+ {
+ while(libs[pos] == ' ')
+ {
+ pos--;
+ }
+ }
+ if(pos != libs.size()-1)
+ {
+ libs = libs.substr(0, pos+1);
+ }
+ // Replace spaces in libs with ;
+ cmSystemTools::ReplaceString(libs, " ", ";");
+ std::vector<std::string> libVec;
+ cmSystemTools::ExpandListArgument(libs, libVec);
+
+ cmComputeLinkInformation* pcli =
+ this->Target->GetLinkInformation(config.c_str());
+ if(!pcli)
+ {
+ cmSystemTools::Error
+ ("CMake can not compute cmComputeLinkInformation for target: ",
+ this->Name.c_str());
+ return false;
+ }
+ // add the libraries for the target to libs string
+ cmComputeLinkInformation& cli = *pcli;
+ this->AddLibraries(cli, libVec);
+ linkOptions.AddFlag("AdditionalDependencies", libVec);
+
+ std::vector<std::string> const& ldirs = cli.GetDirectories();
+ std::vector<std::string> linkDirs;
+ for(std::vector<std::string>::const_iterator d = ldirs.begin();
+ d != ldirs.end(); ++d)
+ {
+ // first just full path
+ linkDirs.push_back(*d);
+ // next path with configuration type Debug, Release, etc
+ linkDirs.push_back(*d + "/$(Configuration)");
+ }
+ linkDirs.push_back("%(AdditionalLibraryDirectories)");
+ linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
+
+ std::string targetName;
+ std::string targetNameSO;
+ std::string targetNameFull;
+ std::string targetNameImport;
+ std::string targetNamePDB;
+ if(this->Target->GetType() == cmTarget::EXECUTABLE)
+ {
+ this->Target->GetExecutableNames(targetName, targetNameFull,
+ targetNameImport, targetNamePDB,
+ config.c_str());
+ }
+ else
+ {
+ this->Target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
+ targetNameImport, targetNamePDB,
+ config.c_str());
+ }
+
+ if(this->MSTools)
+ {
+ linkOptions.AddFlag("Version", "");
+
+ if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
+ {
+ if (this->GlobalGenerator->TargetsWindowsCE())
+ {
+ linkOptions.AddFlag("SubSystem", "WindowsCE");
+ if (this->Target->GetType() == cmTarget::EXECUTABLE)
+ {
+ linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
+ }
+ }
+ else
+ {
+ linkOptions.AddFlag("SubSystem", "Windows");
+ }
+ }
+ else
+ {
+ if (this->GlobalGenerator->TargetsWindowsCE())
+ {
+ linkOptions.AddFlag("SubSystem", "WindowsCE");
+ if (this->Target->GetType() == cmTarget::EXECUTABLE)
+ {
+ linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
+ }
+ }
+ else
+ {
+ linkOptions.AddFlag("SubSystem", "Console");
+ };
+ }
+
+ if(const char* stackVal =
+ this->Makefile->GetDefinition("CMAKE_"+linkLanguage+"_STACK_SIZE"))
+ {
+ linkOptions.AddFlag("StackReserveSize", stackVal);
+ }
+
+ if(linkOptions.IsDebug() || flags.find("/debug") != flags.npos)
+ {
+ linkOptions.AddFlag("GenerateDebugInformation", "true");
+ }
+ else
+ {
+ linkOptions.AddFlag("GenerateDebugInformation", "false");
+ }
+ std::string pdb = this->Target->GetPDBDirectory(config.c_str());
+ pdb += "/";
+ pdb += targetNamePDB;
+ std::string imLib = this->Target->GetDirectory(config.c_str(), true);
+ imLib += "/";
+ imLib += targetNameImport;
+
+ linkOptions.AddFlag("ImportLibrary", imLib.c_str());
+ linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
+
+ // A Windows Runtime component uses internal .NET metadata,
+ // so does not have an import library.
+ if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
+ {
+ linkOptions.AddFlag("GenerateWindowsMetadata", "true");
+ }
+ else if (this->GlobalGenerator->TargetsWindowsPhone() ||
+ this->GlobalGenerator->TargetsWindowsStore())
+ {
+ // WindowsPhone and WindowsStore components are in an app container
+ // and produce WindowsMetadata. If we are not producing a WINRT
+ // component, then do not generate the metadata here.
+ linkOptions.AddFlag("GenerateWindowsMetadata", "false");
+ }
+
+ if (this->GlobalGenerator->TargetsWindowsPhone() &&
+ this->GlobalGenerator->GetSystemVersion() == "8.0")
+ {
+ // WindowsPhone 8.0 does not have ole32.
+ linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
+ }
+ }
+ else if(this->NsightTegra)
+ {
+ linkOptions.AddFlag("SoName", targetNameSO.c_str());
+ }
+
+ linkOptions.Parse(flags.c_str());
+
+ if(this->MSTools)
+ {
+ std::string def = this->GeneratorTarget->GetModuleDefinitionFile("");
+ if(!def.empty())
+ {
+ linkOptions.AddFlag("ModuleDefinitionFile", def.c_str());
+ }
+ linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
+ "%(IgnoreSpecificDefaultLibraries)");
+ }
+
+ this->LinkOptions[config] = pOptions.release();
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void
+cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
+{
+ if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
+ || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
+ {
+ return;
+ }
+ Options& linkOptions = *(this->LinkOptions[config]);
+ this->WriteString("<Link>\n", 2);
+
+ linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
+ linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
+
+ this->WriteString("</Link>\n", 2);
+ if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target))
+ {
+ this->WriteString("<ProjectReference>\n", 2);
+ this->WriteString(
+ " <LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 2);
+ this->WriteString("</ProjectReference>\n", 2);
+ }
+}
+
+void cmVisualStudio10TargetGenerator::AddLibraries(
+ cmComputeLinkInformation& cli,
+ std::vector<std::string>& libVec)
+{
+ typedef cmComputeLinkInformation::ItemVector ItemVector;
+ ItemVector libs = cli.GetItems();
+ for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
+ {
+ if(l->IsPath)
+ {
+ std::string path = this->LocalGenerator->
+ Convert(l->Value.c_str(),
+ cmLocalGenerator::START_OUTPUT,
+ cmLocalGenerator::UNCHANGED);
+ this->ConvertToWindowsSlash(path);
+ libVec.push_back(path);
+ }
+ else if (!l->Target
+ || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+ {
+ libVec.push_back(l->Value);
+ }
+ }
+}
+
+
+void cmVisualStudio10TargetGenerator::
+WriteMidlOptions(std::string const& /*config*/,
+ std::vector<std::string> const & includes)
+{
+ if(!this->MSTools)
+ {
+ return;
+ }
+
+ // This processes *any* of the .idl files specified in the project's file
+ // list (and passed as the item metadata %(Filename) expressing the rule
+ // input filename) into output files at the per-config *build* dir
+ // ($(IntDir)) each.
+ //
+ // IOW, this MIDL section is intended to provide a fully generic syntax
+ // content suitable for most cases (read: if you get errors, then it's quite
+ // probable that the error is on your side of the .idl setup).
+ //
+ // Also, note that the marked-as-generated _i.c file in the Visual Studio
+ // generator case needs to be referred to as $(IntDir)\foo_i.c at the
+ // project's file list, otherwise the compiler-side processing won't pick it
+ // up (for non-directory form, it ends up looking in project binary dir
+ // only). Perhaps there's something to be done to make this more automatic
+ // on the CMake side?
+ this->WriteString("<Midl>\n", 2);
+ this->WriteString("<AdditionalIncludeDirectories>", 3);
+ for(std::vector<std::string>::const_iterator i = includes.begin();
+ i != includes.end(); ++i)
+ {
+ *this->BuildFileStream << cmVS10EscapeXML(*i) << ";";
+ }
+ this->WriteString("%(AdditionalIncludeDirectories)"
+ "</AdditionalIncludeDirectories>\n", 0);
+ this->WriteString("<OutputDirectory>$(IntDir)</OutputDirectory>\n", 3);
+ this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
+ this->WriteString(
+ "<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
+ this->WriteString(
+ "<InterfaceIdentifierFileName>"
+ "%(Filename)_i.c</InterfaceIdentifierFileName>\n", 3);
+ this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n",3);
+ this->WriteString("</Midl>\n", 2);
+}
+
+
+void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
+{
+ std::vector<std::string> *configs =
+ static_cast<cmGlobalVisualStudio7Generator *>
+ (this->GlobalGenerator)->GetConfigurations();
+ for(std::vector<std::string>::iterator i = configs->begin();
+ i != configs->end(); ++i)
+ {
+ std::vector<std::string> includes;
+ this->LocalGenerator->GetIncludeDirectories(includes,
+ this->GeneratorTarget,
+ "C", i->c_str());
+ for(std::vector<std::string>::iterator ii = includes.begin();
+ ii != includes.end(); ++ii)
+ {
+ this->ConvertToWindowsSlash(*ii);
+ }
+ this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
+ *this->BuildFileStream << "\n";
+ // output cl compile flags <ClCompile></ClCompile>
+ if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
+ {
+ this->WriteClOptions(*i, includes);
+ // output rc compile flags <ResourceCompile></ResourceCompile>
+ this->WriteRCOptions(*i, includes);
+ this->WriteMasmOptions(*i, includes);
+ }
+ // output midl flags <Midl></Midl>
+ this->WriteMidlOptions(*i, includes);
+ // write events
+ this->WriteEvents(*i);
+ // output link flags <Link></Link>
+ this->WriteLinkOptions(*i);
+ // output lib flags <Lib></Lib>
+ this->WriteLibOptions(*i);
+ if(this->NsightTegra &&
+ this->Target->GetType() == cmTarget::EXECUTABLE &&
+ this->Target->GetPropertyAsBool("ANDROID_GUI"))
+ {
+ this->WriteAntBuildOptions(*i);
+ }
+ this->WriteString("</ItemDefinitionGroup>\n", 1);
+ }
+}
+
+void
+cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
+{
+ this->WriteEvent("PreLinkEvent",
+ this->Target->GetPreLinkCommands(), configName);
+ this->WriteEvent("PreBuildEvent",
+ this->Target->GetPreBuildCommands(), configName);
+ this->WriteEvent("PostBuildEvent",
+ this->Target->GetPostBuildCommands(), configName);
+}
+
+void cmVisualStudio10TargetGenerator::WriteEvent(
+ const char* name,
+ std::vector<cmCustomCommand> const& commands,
+ std::string const& configName)
+{
+ if(commands.size() == 0)
+ {
+ return;
+ }
+ this->WriteString("<", 2);
+ (*this->BuildFileStream ) << name << ">\n";
+ cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
+ std::string script;
+ const char* pre = "";
+ std::string comment;
+ for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
+ i != commands.end(); ++i)
+ {
+ cmCustomCommandGenerator ccg(*i, configName, this->Makefile);
+ comment += pre;
+ comment += lg->ConstructComment(ccg);
+ script += pre;
+ pre = "\n";
+ script += cmVS10EscapeXML(lg->ConstructScript(ccg));
+ }
+ comment = cmVS10EscapeComment(comment);
+ this->WriteString("<Message>",3);
+ (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
+ this->WriteString("<Command>", 3);
+ (*this->BuildFileStream ) << script;
+ (*this->BuildFileStream ) << "</Command>" << "\n";
+ this->WriteString("</", 2);
+ (*this->BuildFileStream ) << name << ">\n";
+}
+
+
+void cmVisualStudio10TargetGenerator::WriteProjectReferences()
+{
+ cmGlobalGenerator::TargetDependSet const& unordered
+ = this->GlobalGenerator->GetTargetDirectDepends(*this->Target);
+ typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
+ OrderedTargetDependSet;
+ OrderedTargetDependSet depends(unordered);
+ this->WriteString("<ItemGroup>\n", 1);
+ for( OrderedTargetDependSet::const_iterator i = depends.begin();
+ i != depends.end(); ++i)
+ {
+ cmTarget const* dt = *i;
+ if(dt->GetType() == cmTarget::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))
+ {
+ continue;
+ }
+ this->WriteString("<ProjectReference Include=\"", 2);
+ cmMakefile* mf = dt->GetMakefile();
+ std::string name = dt->GetName();
+ std::string path;
+ const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
+ if(p)
+ {
+ path = p;
+ }
+ else
+ {
+ path = mf->GetStartOutputDirectory();
+ path += "/";
+ path += dt->GetName();
+ path += ".vcxproj";
+ }
+ (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
+ this->WriteString("<Project>", 3);
+ (*this->BuildFileStream)
+ << this->GlobalGenerator->GetGUID(name.c_str())
+ << "</Project>\n";
+ this->WriteString("</ProjectReference>\n", 2);
+ }
+ this->WriteString("</ItemGroup>\n", 1);
+}
+
+void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
+{
+ if((this->GlobalGenerator->TargetsWindowsStore() ||
+ this->GlobalGenerator->TargetsWindowsPhone())
+ && (cmTarget::EXECUTABLE == this->Target->GetType()))
+ {
+ std::string pfxFile;
+ std::vector<cmSourceFile const*> certificates;
+ this->GeneratorTarget->GetCertificates(certificates, "");
+ for(std::vector<cmSourceFile const*>::const_iterator si =
+ certificates.begin(); si != certificates.end(); ++si)
+ {
+ pfxFile = this->ConvertPath((*si)->GetFullPath(), false);
+ this->ConvertToWindowsSlash(pfxFile);
+ break;
+ }
+
+ if(this->IsMissingFiles &&
+ !(this->GlobalGenerator->TargetsWindowsPhone() &&
+ this->GlobalGenerator->GetSystemVersion() == "8.0"))
+ {
+ // Move the manifest to a project directory to avoid clashes
+ std::string artifactDir =
+ this->LocalGenerator->GetTargetDirectory(*this->Target);
+ this->ConvertToWindowsSlash(artifactDir);
+ this->WriteString("<PropertyGroup>\n", 1);
+ this->WriteString("<AppxPackageArtifactsDir>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir) <<
+ "\\</AppxPackageArtifactsDir>\n";
+ this->WriteString("<ProjectPriFullPath>"
+ "$(TargetDir)resources.pri</ProjectPriFullPath>", 2);
+
+ // If we are missing files and we don't have a certificate and
+ // aren't targeting WP8.0, add a default certificate
+ if(pfxFile.empty())
+ {
+ std::string templateFolder = cmSystemTools::GetCMakeRoot() +
+ "/Templates/Windows";
+ pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
+ cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
+ pfxFile, false);
+ this->ConvertToWindowsSlash(pfxFile);
+ this->AddedFiles.push_back(pfxFile);
+ }
+
+ this->WriteString("<", 2);
+ (*this->BuildFileStream) << "PackageCertificateKeyFile>"
+ << pfxFile << "</PackageCertificateKeyFile>\n";
+ this->WriteString("</PropertyGroup>\n", 1);
+ }
+ else if(!pfxFile.empty())
+ {
+ this->WriteString("<PropertyGroup>\n", 1);
+ this->WriteString("<", 2);
+ (*this->BuildFileStream) << "PackageCertificateKeyFile>"
+ << pfxFile << "</PackageCertificateKeyFile>\n";
+ this->WriteString("</PropertyGroup>\n", 1);
+ }
+ }
+}
+
+bool cmVisualStudio10TargetGenerator::
+ IsResxHeader(const std::string& headerFile)
+{
+ std::set<std::string> expectedResxHeaders;
+ this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
+
+ std::set<std::string>::const_iterator it =
+ expectedResxHeaders.find(headerFile);
+ return it != expectedResxHeaders.end();
+}
+
+void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
+{
+ bool isAppContainer = false;
+ bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
+ bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
+ std::string const& v = this->GlobalGenerator->GetSystemVersion();
+ if(isWindowsPhone || isWindowsStore)
+ {
+ this->WriteString("<ApplicationType>", 2);
+ (*this->BuildFileStream) << (isWindowsPhone ?
+ "Windows Phone" : "Windows Store")
+ << "</ApplicationType>\n";
+ this->WriteString("<ApplicationTypeRevision>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(v)
+ << "</ApplicationTypeRevision>\n";
+ if(v == "8.1")
+ {
+ // Visual Studio 12.0 is necessary for building 8.1 apps
+ this->WriteString("<MinimumVisualStudioVersion>12.0"
+ "</MinimumVisualStudioVersion>\n", 2);
+
+ if (this->Target->GetType() < cmTarget::UTILITY)
+ {
+ isAppContainer = true;
+ }
+ }
+ else if (v == "8.0")
+ {
+ // Visual Studio 11.0 is necessary for building 8.0 apps
+ this->WriteString("<MinimumVisualStudioVersion>11.0"
+ "</MinimumVisualStudioVersion>\n", 2);
+
+ if (isWindowsStore && this->Target->GetType() < cmTarget::UTILITY)
+ {
+ isAppContainer = true;
+ }
+ else if (isWindowsPhone &&
+ this->Target->GetType() == cmTarget::EXECUTABLE)
+ {
+ this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
+ this->WriteString("<XapFilename>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(this->Name.c_str()) <<
+ "_$(Configuration)_$(Platform).xap</XapFilename>\n";
+ }
+ }
+ }
+ if(isAppContainer)
+ {
+ this->WriteString("<AppContainerApplication>true"
+ "</AppContainerApplication>", 2);
+ }
+ else if (this->Platform == "ARM")
+ {
+ this->WriteString("<WindowsSDKDesktopARMSupport>true"
+ "</WindowsSDKDesktopARMSupport>", 2);
+ }
+}
+
+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)
+ {
+ std::vector<cmSourceFile const*> manifestSources;
+ this->GeneratorTarget->GetAppManifest(manifestSources, "");
+ {
+ std::string const& v = this->GlobalGenerator->GetSystemVersion();
+ if(this->GlobalGenerator->TargetsWindowsPhone())
+ {
+ if (v == "8.0")
+ {
+ // Look through the sources for WMAppManifest.xml
+ std::vector<cmSourceFile const*> extraSources;
+ this->GeneratorTarget->GetExtraSources(extraSources, "");
+ bool foundManifest = false;
+ for(std::vector<cmSourceFile const*>::const_iterator si =
+ extraSources.begin(); si != extraSources.end(); ++si)
+ {
+ // Need to do a lowercase comparison on the filename
+ if("wmappmanifest.xml" == cmSystemTools::LowerCase(
+ (*si)->GetLocation().GetName()))
+ {
+ foundManifest = true;
+ break;
+ }
+ }
+ if (!foundManifest)
+ {
+ this->IsMissingFiles = true;
+ }
+ }
+ else if (v == "8.1")
+ {
+ if(manifestSources.empty())
+ {
+ this->IsMissingFiles = true;
+ }
+ }
+ }
+ else if (this->GlobalGenerator->TargetsWindowsStore())
+ {
+ if (manifestSources.empty())
+ {
+ if (v == "8.0")
+ {
+ this->IsMissingFiles = true;
+ }
+ else if (v == "8.1")
+ {
+ this->IsMissingFiles = true;
+ }
+ }
+ }
+ }
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteMissingFiles()
+{
+ std::string const& v = this->GlobalGenerator->GetSystemVersion();
+ if(this->GlobalGenerator->TargetsWindowsPhone())
+ {
+ if (v == "8.0")
+ {
+ this->WriteMissingFilesWP80();
+ }
+ else if (v == "8.1")
+ {
+ this->WriteMissingFilesWP81();
+ }
+ }
+ else if (this->GlobalGenerator->TargetsWindowsStore())
+ {
+ if (v == "8.0")
+ {
+ this->WriteMissingFilesWS80();
+ }
+ else if (v == "8.1")
+ {
+ this->WriteMissingFilesWS81();
+ }
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
+{
+ std::string templateFolder = cmSystemTools::GetCMakeRoot() +
+ "/Templates/Windows";
+
+ // 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->GetStartOutputDirectory() +
+ std::string("/WMAppManifest.xml");
+ std::string artifactDir =
+ this->LocalGenerator->GetTargetDirectory(*this->Target);
+ this->ConvertToWindowsSlash(artifactDir);
+ std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
+ std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
+
+ cmGeneratedFileStream fout(manifestFile.c_str());
+ fout.SetCopyIfDifferent(true);
+
+ fout <<
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<Deployment"
+ " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
+ " AppPlatformVersion=\"8.0\">\n"
+ "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
+ "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
+ " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
+ " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
+ " Description=\"Default CMake App\" Publisher=\"CMake\""
+ " PublisherID=\"{" << this->GUID << "}\">\n"
+ "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
+ << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
+ "\t\t<Capabilities/>\n"
+ "\t\t<Tasks>\n"
+ "\t\t\t<DefaultTask Name=\"_default\""
+ " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
+ "\t\t</Tasks>\n"
+ "\t\t<Tokens>\n"
+ "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
+ " TaskName=\"_default\">\n"
+ "\t\t\t\t<TemplateFlip>\n"
+ "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
+ << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
+ "\t\t\t\t\t<Count>0</Count>\n"
+ "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
+ << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
+ "\t\t\t\t</TemplateFlip>\n"
+ "\t\t\t</PrimaryToken>\n"
+ "\t\t</Tokens>\n"
+ "\t\t<ScreenResolutions>\n"
+ "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
+ "\t\t</ScreenResolutions>\n"
+ "\t</App>\n"
+ "</Deployment>\n";
+
+ std::string sourceFile = this->ConvertPath(manifestFile, false);
+ this->ConvertToWindowsSlash(sourceFile);
+ this->WriteString("<Xml Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
+ this->WriteString("<SubType>Designer</SubType>\n", 3);
+ this->WriteString("</Xml>\n", 2);
+ this->AddedFiles.push_back(sourceFile);
+
+ std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
+ cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
+ smallLogo, false);
+ this->ConvertToWindowsSlash(smallLogo);
+ this->WriteString("<Image Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
+ this->AddedFiles.push_back(smallLogo);
+
+ std::string logo = this->DefaultArtifactDir + "/Logo.png";
+ cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
+ logo, false);
+ this->ConvertToWindowsSlash(logo);
+ this->WriteString("<Image Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
+ this->AddedFiles.push_back(logo);
+
+ std::string applicationIcon =
+ this->DefaultArtifactDir + "/ApplicationIcon.png";
+ cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
+ applicationIcon, false);
+ this->ConvertToWindowsSlash(applicationIcon);
+ this->WriteString("<Image Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(applicationIcon) << "\" />\n";
+ this->AddedFiles.push_back(applicationIcon);
+}
+
+void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
+{
+ std::string manifestFile =
+ this->DefaultArtifactDir + "/package.appxManifest";
+ std::string artifactDir =
+ this->LocalGenerator->GetTargetDirectory(*this->Target);
+ this->ConvertToWindowsSlash(artifactDir);
+ std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
+ std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
+
+ cmGeneratedFileStream fout(manifestFile.c_str());
+ fout.SetCopyIfDifferent(true);
+
+ fout <<
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
+ " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
+ " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
+ "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
+ " Version=\"1.0.0.0\" />\n"
+ "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
+ " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
+ "\t<Properties>\n"
+ "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
+ "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
+ "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
+ "\t</Properties>\n"
+ "\t<Prerequisites>\n"
+ "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
+ "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
+ "\t</Prerequisites>\n"
+ "\t<Resources>\n"
+ "\t\t<Resource Language=\"x-generate\" />\n"
+ "\t</Resources>\n"
+ "\t<Applications>\n"
+ "\t\t<Application Id=\"App\""
+ " Executable=\"" << targetNameXML << ".exe\""
+ " EntryPoint=\"" << targetNameXML << ".App\">\n"
+ "\t\t\t<m2:VisualElements\n"
+ "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
+ "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
+ "\t\t\t\tBackgroundColor=\"#336699\"\n"
+ "\t\t\t\tForegroundText=\"light\"\n"
+ "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
+ "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
+ "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
+ "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
+ "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
+ "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
+ "\t\t\t\t</m2:DefaultTile>\n"
+ "\t\t\t\t<m2:SplashScreen"
+ " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
+ "\t\t\t</m2:VisualElements>\n"
+ "\t\t</Application>\n"
+ "\t</Applications>\n"
+ "</Package>\n";
+
+ this->WriteCommonMissingFiles(manifestFile);
+}
+
+void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
+{
+ std::string manifestFile =
+ this->DefaultArtifactDir + "/package.appxManifest";
+ std::string artifactDir =
+ this->LocalGenerator->GetTargetDirectory(*this->Target);
+ this->ConvertToWindowsSlash(artifactDir);
+ std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
+ std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
+
+ cmGeneratedFileStream fout(manifestFile.c_str());
+ fout.SetCopyIfDifferent(true);
+
+ fout <<
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
+ "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
+ " Version=\"1.0.0.0\" />\n"
+ "\t<Properties>\n"
+ "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
+ "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
+ "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
+ "\t</Properties>\n"
+ "\t<Prerequisites>\n"
+ "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
+ "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
+ "\t</Prerequisites>\n"
+ "\t<Resources>\n"
+ "\t\t<Resource Language=\"x-generate\" />\n"
+ "\t</Resources>\n"
+ "\t<Applications>\n"
+ "\t\t<Application Id=\"App\""
+ " Executable=\"" << targetNameXML << ".exe\""
+ " EntryPoint=\"" << targetNameXML << ".App\">\n"
+ "\t\t\t<VisualElements"
+ " DisplayName=\"" << targetNameXML << "\""
+ " Description=\"" << targetNameXML << "\""
+ " BackgroundColor=\"#336699\" ForegroundText=\"light\""
+ " Logo=\"" << artifactDirXML << "\\Logo.png\""
+ " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
+ "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
+ " ShortName=\"" << targetNameXML << "\" />\n"
+ "\t\t\t\t<SplashScreen"
+ " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
+ "\t\t\t</VisualElements>\n"
+ "\t\t</Application>\n"
+ "\t</Applications>\n"
+ "</Package>\n";
+
+ this->WriteCommonMissingFiles(manifestFile);
+}
+
+void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
+{
+ std::string manifestFile =
+ this->DefaultArtifactDir + "/package.appxManifest";
+ std::string artifactDir =
+ this->LocalGenerator->GetTargetDirectory(*this->Target);
+ this->ConvertToWindowsSlash(artifactDir);
+ std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
+ std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
+
+ cmGeneratedFileStream fout(manifestFile.c_str());
+ fout.SetCopyIfDifferent(true);
+
+ fout <<
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
+ " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
+ "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
+ " Version=\"1.0.0.0\" />\n"
+ "\t<Properties>\n"
+ "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
+ "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
+ "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
+ "\t</Properties>\n"
+ "\t<Prerequisites>\n"
+ "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
+ "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
+ "\t</Prerequisites>\n"
+ "\t<Resources>\n"
+ "\t\t<Resource Language=\"x-generate\" />\n"
+ "\t</Resources>\n"
+ "\t<Applications>\n"
+ "\t\t<Application Id=\"App\""
+ " Executable=\"" << targetNameXML << ".exe\""
+ " EntryPoint=\"" << targetNameXML << ".App\">\n"
+ "\t\t\t<m2:VisualElements\n"
+ "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
+ "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
+ "\t\t\t\tBackgroundColor=\"#336699\"\n"
+ "\t\t\t\tForegroundText=\"light\"\n"
+ "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
+ "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
+ "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
+ "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
+ "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
+ "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
+ "\t\t\t\t</m2:DefaultTile>\n"
+ "\t\t\t\t<m2:SplashScreen"
+ " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
+ "\t\t\t</m2:VisualElements>\n"
+ "\t\t</Application>\n"
+ "\t</Applications>\n"
+ "</Package>\n";
+
+ this->WriteCommonMissingFiles(manifestFile);
+}
+
+void
+cmVisualStudio10TargetGenerator
+::WriteCommonMissingFiles(const std::string& manifestFile)
+{
+ std::string templateFolder = cmSystemTools::GetCMakeRoot() +
+ "/Templates/Windows";
+
+ std::string sourceFile = this->ConvertPath(manifestFile, false);
+ this->ConvertToWindowsSlash(sourceFile);
+ this->WriteString("<AppxManifest Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
+ this->WriteString("<SubType>Designer</SubType>\n", 3);
+ this->WriteString("</AppxManifest>\n", 2);
+ this->AddedFiles.push_back(sourceFile);
+
+ std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
+ cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
+ smallLogo, false);
+ this->ConvertToWindowsSlash(smallLogo);
+ this->WriteString("<Image Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
+ this->AddedFiles.push_back(smallLogo);
+
+ std::string logo = this->DefaultArtifactDir + "/Logo.png";
+ cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
+ logo, false);
+ this->ConvertToWindowsSlash(logo);
+ this->WriteString("<Image Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
+ this->AddedFiles.push_back(logo);
+
+ std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
+ cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png",
+ storeLogo, false);
+ this->ConvertToWindowsSlash(storeLogo);
+ this->WriteString("<Image Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(storeLogo) << "\" />\n";
+ this->AddedFiles.push_back(storeLogo);
+
+ std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
+ cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png",
+ splashScreen, false);
+ this->ConvertToWindowsSlash(splashScreen);
+ this->WriteString("<Image Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(splashScreen) << "\" />\n";
+ this->AddedFiles.push_back(splashScreen);
+
+ // This file has already been added to the build so don't copy it
+ std::string keyFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
+ this->ConvertToWindowsSlash(keyFile);
+ this->WriteString("<None Include=\"", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n";
+}
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
new file mode 100644
index 0000000000..a02dfa8450
--- /dev/null
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -0,0 +1,159 @@
+/*============================================================================
+ 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 cmVisualStudioTargetGenerator_h
+#define cmVisualStudioTargetGenerator_h
+#include "cmStandardIncludes.h"
+
+class cmTarget;
+class cmMakefile;
+class cmGeneratorTarget;
+class cmGeneratedFileStream;
+class cmGlobalVisualStudio10Generator;
+class cmSourceFile;
+class cmCustomCommand;
+class cmLocalVisualStudio7Generator;
+class cmComputeLinkInformation;
+class cmVisualStudioGeneratorOptions;
+struct cmIDEFlagTable;
+#include "cmSourceGroup.h"
+
+class cmVisualStudio10TargetGenerator
+{
+public:
+ cmVisualStudio10TargetGenerator(cmTarget* target,
+ cmGlobalVisualStudio10Generator* gg);
+ ~cmVisualStudio10TargetGenerator();
+ void Generate();
+ // used by cmVisualStudioGeneratorOptions
+ void WritePlatformConfigTag(
+ const char* tag,
+ const std::string& config,
+ int indentLevel,
+ const char* attribute = 0,
+ const char* end = 0,
+ std::ostream* strm = 0
+ );
+
+private:
+ struct ToolSource
+ {
+ cmSourceFile const* SourceFile;
+ bool RelativePath;
+ };
+ struct ToolSources: public std::vector<ToolSource> {};
+
+ std::string ConvertPath(std::string const& path, bool forceRelative);
+ void ConvertToWindowsSlash(std::string& s);
+ void WriteString(const char* line, int indentLevel);
+ void WriteProjectConfigurations();
+ void WriteProjectConfigurationValues();
+ void WriteMSToolConfigurationValues(std::string const& config);
+ void WriteHeaderSource(cmSourceFile const* sf);
+ void WriteExtraSource(cmSourceFile const* sf);
+ void WriteNsightTegraConfigurationValues(std::string const& config);
+ void WriteSource(std::string const& tool, cmSourceFile const* sf,
+ const char* end = 0);
+ void WriteSources(std::string const& tool,
+ std::vector<cmSourceFile const*> const&);
+ void WriteAllSources();
+ void WriteDotNetReferences();
+ void WriteEmbeddedResourceGroup();
+ void WriteWinRTReferences();
+ void WriteWinRTPackageCertificateKeyFile();
+ void WritePathAndIncrementalLinkOptions();
+ void WriteItemDefinitionGroups();
+ void VerifyNecessaryFiles();
+ void WriteMissingFiles();
+ void WriteMissingFilesWP80();
+ void WriteMissingFilesWP81();
+ void WriteMissingFilesWS80();
+ void WriteMissingFilesWS81();
+ void WriteCommonMissingFiles(const std::string& manifestFile);
+ void WriteTargetSpecificReferences();
+
+ bool ComputeClOptions();
+ bool ComputeClOptions(std::string const& configName);
+ void WriteClOptions(std::string const& config,
+ std::vector<std::string> const & includes);
+ bool ComputeRcOptions();
+ bool ComputeRcOptions(std::string const& config);
+ void WriteRCOptions(std::string const& config,
+ std::vector<std::string> const & includes);
+ bool ComputeMasmOptions();
+ bool ComputeMasmOptions(std::string const& config);
+ void WriteMasmOptions(std::string const& config,
+ std::vector<std::string> const& includes);
+ bool ComputeLinkOptions();
+ bool ComputeLinkOptions(std::string const& config);
+ void WriteLinkOptions(std::string const& config);
+ void WriteMidlOptions(std::string const& config,
+ std::vector<std::string> const & includes);
+ void WriteAntBuildOptions(std::string const& config);
+ void OutputLinkIncremental(std::string const& configName);
+ void WriteCustomRule(cmSourceFile const* source,
+ cmCustomCommand const & command);
+ void WriteCustomCommands();
+ void WriteCustomCommand(cmSourceFile const* sf);
+ void WriteGroups();
+ void WriteProjectReferences();
+ void WriteApplicationTypeSettings();
+ bool OutputSourceSpecificFlags(cmSourceFile const* source);
+ void AddLibraries(cmComputeLinkInformation& cli,
+ std::vector<std::string>& libVec);
+ void WriteLibOptions(std::string const& config);
+ void WriteEvents(std::string const& configName);
+ void WriteEvent(const char* name,
+ std::vector<cmCustomCommand> const& commands,
+ std::string const& configName);
+ void WriteGroupSources(const char* name, ToolSources const& sources,
+ std::vector<cmSourceGroup>& );
+ void AddMissingSourceGroups(std::set<cmSourceGroup*>& groupsUsed,
+ const std::vector<cmSourceGroup>& allGroups);
+ bool IsResxHeader(const std::string& headerFile);
+
+ cmIDEFlagTable const* GetClFlagTable() const;
+ cmIDEFlagTable const* GetRcFlagTable() const;
+ cmIDEFlagTable const* GetLibFlagTable() const;
+ cmIDEFlagTable const* GetLinkFlagTable() const;
+ cmIDEFlagTable const* GetMasmFlagTable() const;
+
+private:
+ typedef cmVisualStudioGeneratorOptions Options;
+ typedef std::map<std::string, Options*> OptionsMap;
+ OptionsMap ClOptions;
+ OptionsMap RcOptions;
+ OptionsMap MasmOptions;
+ OptionsMap LinkOptions;
+ std::string PathToVcxproj;
+ cmTarget* Target;
+ cmGeneratorTarget* GeneratorTarget;
+ cmMakefile* Makefile;
+ std::string Platform;
+ std::string GUID;
+ std::string Name;
+ bool MSTools;
+ bool NsightTegra;
+ int NsightTegraVersion[4];
+ bool TargetCompileAsWinRT;
+ cmGlobalVisualStudio10Generator* GlobalGenerator;
+ cmGeneratedFileStream* BuildFileStream;
+ cmLocalVisualStudio7Generator* LocalGenerator;
+ std::set<cmSourceFile const*> SourcesVisited;
+ bool IsMissingFiles;
+ std::vector<std::string> AddedFiles;
+ std::string DefaultArtifactDir;
+
+ typedef std::map<std::string, ToolSources> ToolSourceMap;
+ ToolSourceMap Tools;
+};
+
+#endif
diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx
new file mode 100644
index 0000000000..cdc8879a48
--- /dev/null
+++ b/Source/cmVisualStudioGeneratorOptions.cxx
@@ -0,0 +1,388 @@
+#include "cmVisualStudioGeneratorOptions.h"
+#include "cmSystemTools.h"
+#include <cmsys/System.h>
+#include "cmVisualStudio10TargetGenerator.h"
+
+static
+std::string cmVisualStudio10GeneratorOptionsEscapeForXML(std::string ret)
+{
+ cmSystemTools::ReplaceString(ret, ";", "%3B");
+ cmSystemTools::ReplaceString(ret, "&", "&amp;");
+ cmSystemTools::ReplaceString(ret, "<", "&lt;");
+ cmSystemTools::ReplaceString(ret, ">", "&gt;");
+ return ret;
+}
+
+static
+std::string cmVisualStudioGeneratorOptionsEscapeForXML(std::string ret)
+{
+ cmSystemTools::ReplaceString(ret, "&", "&amp;");
+ cmSystemTools::ReplaceString(ret, "\"", "&quot;");
+ cmSystemTools::ReplaceString(ret, "<", "&lt;");
+ cmSystemTools::ReplaceString(ret, ">", "&gt;");
+ cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
+ return ret;
+}
+
+//----------------------------------------------------------------------------
+cmVisualStudioGeneratorOptions
+::cmVisualStudioGeneratorOptions(cmLocalVisualStudioGenerator* lg,
+ Tool tool,
+ cmVS7FlagTable const* table,
+ cmVS7FlagTable const* extraTable,
+ cmVisualStudio10TargetGenerator* g):
+ cmIDEOptions(),
+ LocalGenerator(lg), Version(lg->GetVersion()), CurrentTool(tool),
+ TargetGenerator(g)
+{
+ // Store the given flag tables.
+ cmIDEFlagTable const** ft = this->FlagTable;
+ if(table) { *ft++ = table; }
+ if(extraTable) { *ft++ = extraTable; }
+
+ // Preprocessor definitions are not allowed for linker tools.
+ this->AllowDefine = (tool != Linker);
+
+ // Slash options are allowed for VS.
+ this->AllowSlash = true;
+
+ this->FortranRuntimeDebug = false;
+ this->FortranRuntimeDLL = false;
+ this->FortranRuntimeMT = false;
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudioGeneratorOptions::FixExceptionHandlingDefault()
+{
+ // Exception handling is on by default because the platform file has
+ // "/EHsc" in the flags. Normally, that will override this
+ // initialization to off, but the user has the option of removing
+ // the flag to disable exception handling. When the user does
+ // remove the flag we need to override the IDE default of on.
+ switch (this->Version)
+ {
+ case cmLocalVisualStudioGenerator::VS7:
+ case cmLocalVisualStudioGenerator::VS71:
+ this->FlagMap["ExceptionHandling"] = "FALSE";
+ break;
+ case cmLocalVisualStudioGenerator::VS10:
+ case cmLocalVisualStudioGenerator::VS11:
+ case cmLocalVisualStudioGenerator::VS12:
+ case cmLocalVisualStudioGenerator::VS14:
+ // by default VS puts <ExceptionHandling></ExceptionHandling> empty
+ // for a project, to make our projects look the same put a new line
+ // and space over for the closing </ExceptionHandling> as the default
+ // value
+ this->FlagMap["ExceptionHandling"] = "\n ";
+ break;
+ default:
+ this->FlagMap["ExceptionHandling"] = "0";
+ break;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudioGeneratorOptions::SetVerboseMakefile(bool verbose)
+{
+ // If verbose makefiles have been requested and the /nologo option
+ // was not given explicitly in the flags we want to add an attribute
+ // to the generated project to disable logo suppression. Otherwise
+ // the GUI default is to enable suppression.
+ //
+ // On Visual Studio 10 (and later!), the value of this attribute should be
+ // an empty string, instead of "FALSE", in order to avoid a warning:
+ // "cl ... warning D9035: option 'nologo-' has been deprecated"
+ //
+ if(verbose &&
+ this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
+ {
+ this->FlagMap["SuppressStartupBanner"] =
+ this->Version < cmLocalVisualStudioGenerator::VS10 ? "FALSE" : "";
+ }
+}
+
+bool cmVisualStudioGeneratorOptions::IsDebug() const
+{
+ return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end();
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioGeneratorOptions::IsWinRt() const
+{
+ return this->FlagMap.find("CompileAsWinRT") != this->FlagMap.end();
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioGeneratorOptions::UsingUnicode() const
+{
+ // Look for the a _UNICODE definition.
+ for(std::vector<std::string>::const_iterator di = this->Defines.begin();
+ di != this->Defines.end(); ++di)
+ {
+ if(*di == "_UNICODE")
+ {
+ return true;
+ }
+ }
+ return false;
+}
+//----------------------------------------------------------------------------
+bool cmVisualStudioGeneratorOptions::UsingSBCS() const
+{
+ // Look for the a _SBCS definition.
+ for(std::vector<std::string>::const_iterator di = this->Defines.begin();
+ di != this->Defines.end(); ++di)
+ {
+ if(*di == "_SBCS")
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudioGeneratorOptions::Parse(const char* flags)
+{
+ // Parse the input string as a windows command line since the string
+ // is intended for writing directly into the build files.
+ std::vector<std::string> args;
+ cmSystemTools::ParseWindowsCommandLine(flags, args);
+
+ // Process flags that need to be represented specially in the IDE
+ // project file.
+ for(std::vector<std::string>::iterator ai = args.begin();
+ ai != args.end(); ++ai)
+ {
+ this->HandleFlag(ai->c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudioGeneratorOptions::ParseFinish()
+{
+ if(this->CurrentTool == FortranCompiler)
+ {
+ // "RuntimeLibrary" attribute values:
+ // "rtMultiThreaded", "0", /threads /libs:static
+ // "rtMultiThreadedDLL", "2", /threads /libs:dll
+ // "rtMultiThreadedDebug", "1", /threads /dbglibs /libs:static
+ // "rtMultiThreadedDebugDLL", "3", /threads /dbglibs /libs:dll
+ // These seem unimplemented by the IDE:
+ // "rtSingleThreaded", "4", /libs:static
+ // "rtSingleThreadedDLL", "10", /libs:dll
+ // "rtSingleThreadedDebug", "5", /dbglibs /libs:static
+ // "rtSingleThreadedDebugDLL", "11", /dbglibs /libs:dll
+ std::string rl = "rtMultiThreaded";
+ rl += this->FortranRuntimeDebug? "Debug" : "";
+ rl += this->FortranRuntimeDLL? "DLL" : "";
+ this->FlagMap["RuntimeLibrary"] = rl;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag)
+{
+ // Look for Intel Fortran flags that do not map well in the flag table.
+ if(this->CurrentTool == FortranCompiler)
+ {
+ if(strcmp(flag, "/dbglibs") == 0)
+ {
+ this->FortranRuntimeDebug = true;
+ return;
+ }
+ if(strcmp(flag, "/threads") == 0)
+ {
+ this->FortranRuntimeMT = true;
+ return;
+ }
+ if(strcmp(flag, "/libs:dll") == 0)
+ {
+ this->FortranRuntimeDLL = true;
+ return;
+ }
+ if(strcmp(flag, "/libs:static") == 0)
+ {
+ this->FortranRuntimeDLL = false;
+ return;
+ }
+ }
+
+ // This option is not known. Store it in the output flags.
+ this->FlagString += " ";
+ this->FlagString +=
+ cmSystemTools::EscapeWindowsShellArgument(
+ flag,
+ cmsysSystem_Shell_Flag_AllowMakeVariables |
+ cmsysSystem_Shell_Flag_VSIDE);
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudioGeneratorOptions::SetConfiguration(const char* config)
+{
+ this->Configuration = config;
+}
+
+//----------------------------------------------------------------------------
+void
+cmVisualStudioGeneratorOptions
+::OutputPreprocessorDefinitions(std::ostream& fout,
+ const char* prefix,
+ const char* suffix,
+ const std::string& lang)
+{
+ if(this->Defines.empty())
+ {
+ return;
+ }
+ if(this->Version >= cmLocalVisualStudioGenerator::VS10)
+ {
+ // if there are configuration specific flags, then
+ // use the configuration specific tag for PreprocessorDefinitions
+ if(this->Configuration.size())
+ {
+ fout << prefix;
+ this->TargetGenerator->WritePlatformConfigTag(
+ "PreprocessorDefinitions",
+ this->Configuration.c_str(),
+ 0,
+ 0, 0, &fout);
+ }
+ else
+ {
+ fout << prefix << "<PreprocessorDefinitions>";
+ }
+ }
+ else
+ {
+ fout << prefix << "PreprocessorDefinitions=\"";
+ }
+ const char* sep = "";
+ for(std::vector<std::string>::const_iterator di = this->Defines.begin();
+ di != this->Defines.end(); ++di)
+ {
+ // Escape the definition for the compiler.
+ std::string define;
+ if(this->Version < cmLocalVisualStudioGenerator::VS10)
+ {
+ define =
+ this->LocalGenerator->EscapeForShell(di->c_str(), true);
+ }
+ else
+ {
+ define = *di;
+ }
+ // Escape this flag for the IDE.
+ if(this->Version >= cmLocalVisualStudioGenerator::VS10)
+ {
+ define = cmVisualStudio10GeneratorOptionsEscapeForXML(define);
+
+ if(lang == "RC")
+ {
+ cmSystemTools::ReplaceString(define, "\"", "\\\"");
+ }
+ }
+ else
+ {
+ define = cmVisualStudioGeneratorOptionsEscapeForXML(define);
+ }
+ // Store the flag in the project file.
+ fout << sep << define;
+ sep = ";";
+ }
+ if(this->Version >= cmLocalVisualStudioGenerator::VS10)
+ {
+ fout << ";%(PreprocessorDefinitions)</PreprocessorDefinitions>" << suffix;
+ }
+ else
+ {
+ fout << "\"" << suffix;
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmVisualStudioGeneratorOptions
+::OutputFlagMap(std::ostream& fout, const char* indent)
+{
+ if(this->Version >= cmLocalVisualStudioGenerator::VS10)
+ {
+ for(std::map<std::string, FlagValue>::iterator m = this->FlagMap.begin();
+ m != this->FlagMap.end(); ++m)
+ {
+ fout << indent;
+ if(this->Configuration.size())
+ {
+ this->TargetGenerator->WritePlatformConfigTag(
+ m->first.c_str(),
+ this->Configuration.c_str(),
+ 0,
+ 0, 0, &fout);
+ }
+ else
+ {
+ fout << "<" << m->first << ">";
+ }
+ const char* sep = "";
+ for(std::vector<std::string>::iterator i = m->second.begin();
+ i != m->second.end(); ++i)
+ {
+ fout << sep << cmVisualStudio10GeneratorOptionsEscapeForXML(*i);
+ sep = ";";
+ }
+ fout << "</" << m->first << ">\n";
+ }
+ }
+ else
+ {
+ for(std::map<std::string, FlagValue>::iterator m = this->FlagMap.begin();
+ m != this->FlagMap.end(); ++m)
+ {
+ fout << indent << m->first << "=\"";
+ const char* sep = "";
+ for(std::vector<std::string>::iterator i = m->second.begin();
+ i != m->second.end(); ++i)
+ {
+ fout << sep << cmVisualStudioGeneratorOptionsEscapeForXML(*i);
+ sep = ";";
+ }
+ fout << "\"\n";
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmVisualStudioGeneratorOptions
+::OutputAdditionalOptions(std::ostream& fout,
+ const char* prefix,
+ const char* suffix)
+{
+ if(!this->FlagString.empty())
+ {
+ if(this->Version >= cmLocalVisualStudioGenerator::VS10)
+ {
+ fout << prefix;
+ if(this->Configuration.size())
+ {
+ this->TargetGenerator->WritePlatformConfigTag(
+ "AdditionalOptions",
+ this->Configuration.c_str(),
+ 0,
+ 0, 0, &fout);
+ }
+ else
+ {
+ fout << "<AdditionalOptions>";
+ }
+ fout << cmVisualStudio10GeneratorOptionsEscapeForXML(this->FlagString)
+ << " %(AdditionalOptions)</AdditionalOptions>\n";
+ }
+ else
+ {
+ fout << prefix << "AdditionalOptions=\"";
+ fout << cmVisualStudioGeneratorOptionsEscapeForXML(this->FlagString);
+ fout << "\"" << suffix;
+ }
+ }
+}
diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h
new file mode 100644
index 0000000000..9951033bd8
--- /dev/null
+++ b/Source/cmVisualStudioGeneratorOptions.h
@@ -0,0 +1,82 @@
+/*============================================================================
+ 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 cmVisualStudioGeneratorOptions_h
+#define cmVisualStudioGeneratorOptions_h
+
+#include "cmLocalVisualStudioGenerator.h"
+
+#include "cmIDEOptions.h"
+typedef cmIDEFlagTable cmVS7FlagTable;
+
+class cmVisualStudio10TargetGenerator;
+
+//----------------------------------------------------------------------------
+class cmVisualStudioGeneratorOptions: public cmIDEOptions
+{
+public:
+ // Construct an options table for a given tool.
+ enum Tool
+ {
+ Compiler,
+ ResourceCompiler,
+ MasmCompiler,
+ Linker,
+ FortranCompiler
+ };
+ cmVisualStudioGeneratorOptions(cmLocalVisualStudioGenerator* lg,
+ Tool tool,
+ cmVS7FlagTable const* table,
+ cmVS7FlagTable const* extraTable = 0,
+ cmVisualStudio10TargetGenerator* g = 0);
+
+ // Store options from command line flags.
+ void Parse(const char* flags);
+ void ParseFinish();
+
+ // Fix the ExceptionHandling option to default to off.
+ void FixExceptionHandlingDefault();
+
+ // Store options for verbose builds.
+ void SetVerboseMakefile(bool verbose);
+
+ // Check for specific options.
+ bool UsingUnicode() const;
+ bool UsingSBCS() const;
+
+ bool IsDebug() const;
+ bool IsWinRt() const;
+ // Write options to output.
+ void OutputPreprocessorDefinitions(std::ostream& fout,
+ const char* prefix,
+ const char* suffix,
+ const std::string& lang);
+ void OutputFlagMap(std::ostream& fout, const char* indent);
+ void OutputAdditionalOptions(std::ostream& fout,
+ const char* prefix,
+ const char* suffix);
+ void SetConfiguration(const char* config);
+private:
+ cmLocalVisualStudioGenerator* LocalGenerator;
+ cmLocalVisualStudioGenerator::VSVersion Version;
+
+ std::string Configuration;
+ Tool CurrentTool;
+ cmVisualStudio10TargetGenerator* TargetGenerator;
+
+ bool FortranRuntimeDebug;
+ bool FortranRuntimeDLL;
+ bool FortranRuntimeMT;
+
+ virtual void StoreUnknownFlag(const char* flag);
+};
+
+#endif
diff --git a/Source/cmVisualStudioSlnData.cxx b/Source/cmVisualStudioSlnData.cxx
new file mode 100644
index 0000000000..82b4ee84f3
--- /dev/null
+++ b/Source/cmVisualStudioSlnData.cxx
@@ -0,0 +1,62 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 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 "cmVisualStudioSlnData.h"
+
+//----------------------------------------------------------------------------
+const cmSlnProjectEntry*
+cmSlnData::GetProjectByGUID(const std::string& projectGUID) const
+{
+ ProjectStorage::const_iterator it(ProjectsByGUID.find(projectGUID));
+ if (it != ProjectsByGUID.end())
+ return &it->second;
+ else
+ return NULL;
+}
+
+//----------------------------------------------------------------------------
+const cmSlnProjectEntry*
+cmSlnData::GetProjectByName(const std::string& projectName) const
+{
+ ProjectStringIndex::const_iterator it(ProjectNameIndex.find(projectName));
+ if (it != ProjectNameIndex.end())
+ return &it->second->second;
+ else
+ return NULL;
+}
+
+//----------------------------------------------------------------------------
+std::vector<cmSlnProjectEntry> cmSlnData::GetProjects() const
+{
+ ProjectStringIndex::const_iterator it(this->ProjectNameIndex.begin()),
+ itEnd(this->ProjectNameIndex.end());
+ std::vector<cmSlnProjectEntry> result;
+ for (; it != itEnd; ++it)
+ result.push_back(it->second->second);
+ return result;
+}
+
+//----------------------------------------------------------------------------
+cmSlnProjectEntry* cmSlnData::AddProject(
+ const std::string& projectGUID,
+ const std::string& projectName,
+ const std::string& projectRelativePath)
+{
+ ProjectStorage::iterator it(ProjectsByGUID.find(projectGUID));
+ if (it != ProjectsByGUID.end())
+ return NULL;
+ it = ProjectsByGUID.insert(
+ ProjectStorage::value_type(
+ projectGUID,
+ cmSlnProjectEntry(projectGUID, projectName, projectRelativePath))).first;
+ ProjectNameIndex[projectName] = it;
+ return &it->second;
+}
diff --git a/Source/cmVisualStudioSlnData.h b/Source/cmVisualStudioSlnData.h
new file mode 100644
index 0000000000..ec128cf11c
--- /dev/null
+++ b/Source/cmVisualStudioSlnData.h
@@ -0,0 +1,58 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 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 cmVisualStudioSlnData_h
+#define cmVisualStudioSlnData_h
+
+#include "cmStandardIncludes.h"
+
+class cmSlnProjectEntry
+{
+public:
+ cmSlnProjectEntry() {}
+ cmSlnProjectEntry(const std::string& guid,
+ const std::string& name,
+ const std::string& relativePath)
+ : Guid(guid), Name(name), RelativePath(relativePath)
+ {}
+
+ std::string GetGUID() const { return Guid; }
+ std::string GetName() const { return Name; }
+ std::string GetRelativePath() const { return RelativePath; }
+
+private:
+ std::string Guid, Name, RelativePath;
+};
+
+
+class cmSlnData
+{
+public:
+ const cmSlnProjectEntry*
+ GetProjectByGUID(const std::string& projectGUID) const;
+
+ const cmSlnProjectEntry*
+ GetProjectByName(const std::string& projectName) const;
+
+ std::vector<cmSlnProjectEntry> GetProjects() const;
+
+ cmSlnProjectEntry* AddProject(const std::string& projectGUID,
+ const std::string& projectName,
+ const std::string& projectRelativePath);
+
+private:
+ typedef std::map<std::string, cmSlnProjectEntry> ProjectStorage;
+ ProjectStorage ProjectsByGUID;
+ typedef std::map<std::string, ProjectStorage::iterator> ProjectStringIndex;
+ ProjectStringIndex ProjectNameIndex;
+};
+
+#endif
diff --git a/Source/cmVisualStudioSlnParser.cxx b/Source/cmVisualStudioSlnParser.cxx
new file mode 100644
index 0000000000..d182a75d5f
--- /dev/null
+++ b/Source/cmVisualStudioSlnParser.cxx
@@ -0,0 +1,713 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 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 "cmVisualStudioSlnParser.h"
+
+#include "cmSystemTools.h"
+#include "cmVisualStudioSlnData.h"
+#include <cmsys/FStream.hxx>
+
+#include <cassert>
+#include <stack>
+
+//----------------------------------------------------------------------------
+namespace
+{
+ enum LineFormat
+ {
+ LineMultiValueTag,
+ LineSingleValueTag,
+ LineKeyValuePair,
+ LineVerbatim
+ };
+}
+
+//----------------------------------------------------------------------------
+class cmVisualStudioSlnParser::ParsedLine
+{
+public:
+ bool IsComment() const;
+ bool IsKeyValuePair() const;
+
+ const std::string& GetTag() const { return this->Tag; }
+ const std::string& GetArg() const { return this->Arg.first; }
+ std::string GetArgVerbatim() const;
+ size_t GetValueCount() const { return this->Values.size(); }
+ const std::string& GetValue(size_t idxValue) const;
+ std::string GetValueVerbatim(size_t idxValue) const;
+
+ void SetTag(const std::string& tag) { this->Tag = tag; }
+ void SetArg(const std::string& arg) { this->Arg = StringData(arg, false); }
+ void SetQuotedArg(const std::string& arg)
+ { this->Arg = StringData(arg, true); }
+ void AddValue(const std::string& value)
+ { this->Values.push_back(StringData(value, false)); }
+ void AddQuotedValue(const std::string& value)
+ { this->Values.push_back(StringData(value, true)); }
+
+ void CopyVerbatim(const std::string& line) { this->Tag = line; }
+
+private:
+ typedef std::pair<std::string, bool> StringData;
+ std::string Tag;
+ StringData Arg;
+ std::vector<StringData> Values;
+ static const std::string BadString;
+ static const std::string Quote;
+};
+
+//----------------------------------------------------------------------------
+const std::string cmVisualStudioSlnParser::ParsedLine::BadString;
+const std::string cmVisualStudioSlnParser::ParsedLine::Quote("\"");
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParsedLine::IsComment() const
+{
+ assert(!this->Tag.empty());
+ return (this->Tag[0]== '#');
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParsedLine::IsKeyValuePair() const
+{
+ assert(!this->Tag.empty());
+ return this->Arg.first.empty() && this->Values.size() == 1;
+}
+
+//----------------------------------------------------------------------------
+std::string cmVisualStudioSlnParser::ParsedLine::GetArgVerbatim() const
+{
+ if (this->Arg.second)
+ return Quote + this->Arg.first + Quote;
+ else
+ return this->Arg.first;
+}
+
+//----------------------------------------------------------------------------
+const std::string&
+cmVisualStudioSlnParser::ParsedLine::GetValue(size_t idxValue) const
+{
+ if (idxValue < this->Values.size())
+ return this->Values[idxValue].first;
+ else
+ return BadString;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmVisualStudioSlnParser::ParsedLine::GetValueVerbatim(size_t idxValue) const
+{
+ if (idxValue < this->Values.size())
+ {
+ const StringData& data = this->Values[idxValue];
+ if (data.second)
+ return Quote + data.first + Quote;
+ else
+ return data.first;
+ }
+ else
+ return BadString;
+}
+
+//----------------------------------------------------------------------------
+class cmVisualStudioSlnParser::State
+{
+public:
+ explicit State(DataGroupSet requestedData);
+
+ size_t GetCurrentLine() const { return this->CurrentLine; }
+ bool ReadLine(std::istream& input, std::string& line);
+
+ LineFormat NextLineFormat() const;
+
+ bool Process(const cmVisualStudioSlnParser::ParsedLine& line,
+ cmSlnData& output,
+ cmVisualStudioSlnParser::ResultData& result);
+
+ bool Finished(cmVisualStudioSlnParser::ResultData& result);
+
+private:
+ enum FileState
+ {
+ FileStateStart,
+ FileStateTopLevel,
+ FileStateProject,
+ FileStateProjectDependencies,
+ FileStateGlobal,
+ FileStateSolutionConfigurations,
+ FileStateProjectConfigurations,
+ FileStateSolutionFilters,
+ FileStateGlobalSection,
+ FileStateIgnore
+ };
+ std::stack<FileState> Stack;
+ std::string EndIgnoreTag;
+ DataGroupSet RequestedData;
+ size_t CurrentLine;
+
+ void IgnoreUntilTag(const std::string& endTag);
+};
+
+//----------------------------------------------------------------------------
+cmVisualStudioSlnParser::State::State(DataGroupSet requestedData) :
+ RequestedData(requestedData),
+ CurrentLine(0)
+{
+ if (this->RequestedData.test(DataGroupProjectDependenciesBit))
+ this->RequestedData.set(DataGroupProjectsBit);
+ this->Stack.push(FileStateStart);
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::State::ReadLine(std::istream& input,
+ std::string& line)
+{
+ ++this->CurrentLine;
+ return !std::getline(input, line).fail();
+}
+
+//----------------------------------------------------------------------------
+LineFormat cmVisualStudioSlnParser::State::NextLineFormat() const
+{
+ switch (this->Stack.top())
+ {
+ case FileStateStart: return LineVerbatim;
+ case FileStateTopLevel: return LineMultiValueTag;
+ case FileStateProject: return LineSingleValueTag;
+ case FileStateProjectDependencies: return LineKeyValuePair;
+ case FileStateGlobal: return LineSingleValueTag;
+ case FileStateSolutionConfigurations: return LineKeyValuePair;
+ case FileStateProjectConfigurations: return LineKeyValuePair;
+ case FileStateSolutionFilters: return LineKeyValuePair;
+ case FileStateGlobalSection: return LineKeyValuePair;
+ case FileStateIgnore: return LineVerbatim;
+ default:
+ assert(false);
+ return LineVerbatim;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::State::Process(
+ const cmVisualStudioSlnParser::ParsedLine& line,
+ cmSlnData& output, cmVisualStudioSlnParser::ResultData& result)
+{
+ assert(!line.IsComment());
+ switch (this->Stack.top())
+ {
+ case FileStateStart:
+ if (!cmSystemTools::StringStartsWith(
+ line.GetTag().c_str(), "Microsoft Visual Studio Solution File"))
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ this->Stack.pop();
+ this->Stack.push(FileStateTopLevel);
+ break;
+ case FileStateTopLevel:
+ if (line.GetTag().compare("Project") == 0)
+ {
+ if (line.GetValueCount() != 3)
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ if (this->RequestedData.test(DataGroupProjectsBit))
+ {
+ if (!output.AddProject(line.GetValue(2),
+ line.GetValue(0),
+ line.GetValue(1)))
+ {
+ result.SetError(ResultErrorInputData, this->GetCurrentLine());
+ return false;
+ }
+ this->Stack.push(FileStateProject);
+ }
+ else
+ this->IgnoreUntilTag("EndProject");
+ }
+ else if (line.GetTag().compare("Global") == 0)
+ this->Stack.push(FileStateGlobal);
+ else
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ break;
+ case FileStateProject:
+ if (line.GetTag().compare("EndProject") == 0)
+ this->Stack.pop();
+ else if (line.GetTag().compare("ProjectSection") == 0)
+ {
+ if (line.GetArg().compare("ProjectDependencies") == 0 &&
+ line.GetValue(0).compare("postProject") == 0)
+ {
+ if (this->RequestedData.test(DataGroupProjectDependenciesBit))
+ this->Stack.push(FileStateProjectDependencies);
+ else
+ this->IgnoreUntilTag("EndProjectSection");
+ }
+ else
+ this->IgnoreUntilTag("EndProjectSection");
+ }
+ else
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ break;
+ case FileStateProjectDependencies:
+ if (line.GetTag().compare("EndProjectSection") == 0)
+ this->Stack.pop();
+ else if (line.IsKeyValuePair())
+ // implement dependency storing here, once needed
+ ;
+ else
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ break;
+ case FileStateGlobal:
+ if (line.GetTag().compare("EndGlobal") == 0)
+ this->Stack.pop();
+ else if (line.GetTag().compare("GlobalSection") == 0)
+ {
+ if (line.GetArg().compare("SolutionConfigurationPlatforms") == 0 &&
+ line.GetValue(0).compare("preSolution") == 0)
+ {
+ if (this->RequestedData.test(DataGroupSolutionConfigurationsBit))
+ this->Stack.push(FileStateSolutionConfigurations);
+ else
+ this->IgnoreUntilTag("EndGlobalSection");
+ }
+ else if (line.GetArg().compare("ProjectConfigurationPlatforms") == 0 &&
+ line.GetValue(0).compare("postSolution") == 0)
+ {
+ if (this->RequestedData.test(DataGroupProjectConfigurationsBit))
+ this->Stack.push(FileStateProjectConfigurations);
+ else
+ this->IgnoreUntilTag("EndGlobalSection");
+ }
+ else if (line.GetArg().compare("NestedProjects") == 0 &&
+ line.GetValue(0).compare("preSolution") == 0)
+ {
+ if (this->RequestedData.test(DataGroupSolutionFiltersBit))
+ this->Stack.push(FileStateSolutionFilters);
+ else
+ this->IgnoreUntilTag("EndGlobalSection");
+ }
+ else if (this->RequestedData.test(DataGroupGenericGlobalSectionsBit))
+ this->Stack.push(FileStateGlobalSection);
+ else
+ this->IgnoreUntilTag("EndGlobalSection");
+ }
+ else
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ break;
+ case FileStateSolutionConfigurations:
+ if (line.GetTag().compare("EndGlobalSection") == 0)
+ this->Stack.pop();
+ else if (line.IsKeyValuePair())
+ // implement configuration storing here, once needed
+ ;
+ else
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ break;
+ case FileStateProjectConfigurations:
+ if (line.GetTag().compare("EndGlobalSection") == 0)
+ this->Stack.pop();
+ else if (line.IsKeyValuePair())
+ // implement configuration storing here, once needed
+ ;
+ else
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ break;
+ case FileStateSolutionFilters:
+ if (line.GetTag().compare("EndGlobalSection") == 0)
+ this->Stack.pop();
+ else if (line.IsKeyValuePair())
+ // implement filter storing here, once needed
+ ;
+ else
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ break;
+ case FileStateGlobalSection:
+ if (line.GetTag().compare("EndGlobalSection") == 0)
+ this->Stack.pop();
+ else if (line.IsKeyValuePair())
+ // implement section storing here, once needed
+ ;
+ else
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ break;
+ case FileStateIgnore:
+ if (line.GetTag() == this->EndIgnoreTag)
+ {
+ this->Stack.pop();
+ this->EndIgnoreTag = "";
+ }
+ break;
+ default:
+ result.SetError(ResultErrorBadInternalState, this->GetCurrentLine());
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::State::Finished(
+ cmVisualStudioSlnParser::ResultData& result)
+{
+ if (this->Stack.top() != FileStateTopLevel)
+ {
+ result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
+ return false;
+ }
+ result.Result = ResultOK;
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudioSlnParser::State::IgnoreUntilTag(const std::string& endTag)
+{
+ this->Stack.push(FileStateIgnore);
+ this->EndIgnoreTag = endTag;
+}
+
+//----------------------------------------------------------------------------
+cmVisualStudioSlnParser::ResultData::ResultData()
+ : Result(ResultOK)
+ , ResultLine(0)
+{}
+
+//----------------------------------------------------------------------------
+void cmVisualStudioSlnParser::ResultData::Clear()
+{
+ *this = ResultData();
+}
+
+//----------------------------------------------------------------------------
+void cmVisualStudioSlnParser::ResultData::SetError(ParseResult error,
+ size_t line)
+{
+ this->Result = error;
+ this->ResultLine = line;
+}
+
+//----------------------------------------------------------------------------
+const cmVisualStudioSlnParser::DataGroupSet
+cmVisualStudioSlnParser::DataGroupProjects(
+ 1 << cmVisualStudioSlnParser::DataGroupProjectsBit);
+
+const cmVisualStudioSlnParser::DataGroupSet
+cmVisualStudioSlnParser::DataGroupProjectDependencies(
+ 1 << cmVisualStudioSlnParser::DataGroupProjectDependenciesBit);
+
+const cmVisualStudioSlnParser::DataGroupSet
+cmVisualStudioSlnParser::DataGroupSolutionConfigurations(
+ 1 << cmVisualStudioSlnParser::DataGroupSolutionConfigurationsBit);
+
+const cmVisualStudioSlnParser::DataGroupSet
+cmVisualStudioSlnParser::DataGroupProjectConfigurations(
+ 1 << cmVisualStudioSlnParser::DataGroupProjectConfigurationsBit);
+
+const cmVisualStudioSlnParser::DataGroupSet
+cmVisualStudioSlnParser::DataGroupSolutionFilters(
+ 1 << cmVisualStudioSlnParser::DataGroupSolutionFiltersBit);
+
+const cmVisualStudioSlnParser::DataGroupSet
+cmVisualStudioSlnParser::DataGroupGenericGlobalSections(
+ 1 << cmVisualStudioSlnParser::DataGroupGenericGlobalSectionsBit);
+
+const cmVisualStudioSlnParser::DataGroupSet
+cmVisualStudioSlnParser::DataGroupAll(~0);
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::Parse(std::istream& input,
+ cmSlnData& output,
+ DataGroupSet dataGroups)
+{
+ this->LastResult.Clear();
+ if (!this->IsDataGroupSetSupported(dataGroups))
+ {
+ this->LastResult.SetError(ResultErrorUnsupportedDataGroup, 0);
+ return false;
+ }
+ State state(dataGroups);
+ return this->ParseImpl(input, output, state);
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParseFile(const std::string& file,
+ cmSlnData& output,
+ DataGroupSet dataGroups)
+{
+ this->LastResult.Clear();
+ if (!this->IsDataGroupSetSupported(dataGroups))
+ {
+ this->LastResult.SetError(ResultErrorUnsupportedDataGroup, 0);
+ return false;
+ }
+ cmsys::ifstream f(file.c_str());
+ if (!f)
+ {
+ this->LastResult.SetError(ResultErrorOpeningInput, 0);
+ return false;
+ }
+ State state(dataGroups);
+ return this->ParseImpl(f, output, state);
+}
+
+//----------------------------------------------------------------------------
+cmVisualStudioSlnParser::ParseResult
+cmVisualStudioSlnParser::GetParseResult() const
+{
+ return this->LastResult.Result;
+}
+
+//----------------------------------------------------------------------------
+size_t cmVisualStudioSlnParser::GetParseResultLine() const
+{
+ return this->LastResult.ResultLine;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::GetParseHadBOM() const
+{
+ return this->LastResult.HadBOM;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmVisualStudioSlnParser::IsDataGroupSetSupported(DataGroupSet dataGroups) const
+{
+ return (dataGroups & DataGroupProjects) == dataGroups;
+ //only supporting DataGroupProjects for now
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParseImpl(std::istream& input,
+ cmSlnData& output,
+ State& state)
+{
+ std::string line;
+ // Does the .sln start with a Byte Order Mark?
+ if (!this->ParseBOM(input, line, state))
+ return false;
+ do
+ {
+ line = cmSystemTools::TrimWhitespace(line);
+ if (line.empty())
+ continue;
+ ParsedLine parsedLine;
+ switch (state.NextLineFormat())
+ {
+ case LineMultiValueTag:
+ if (!this->ParseMultiValueTag(line, parsedLine, state))
+ return false;
+ break;
+ case LineSingleValueTag:
+ if (!this->ParseSingleValueTag(line, parsedLine, state))
+ return false;
+ break;
+ case LineKeyValuePair:
+ if (!this->ParseKeyValuePair(line, parsedLine, state))
+ return false;
+ break;
+ case LineVerbatim:
+ parsedLine.CopyVerbatim(line);
+ break;
+ }
+ if (parsedLine.IsComment())
+ continue;
+ if (!state.Process(parsedLine, output, this->LastResult))
+ return false;
+ }
+ while (state.ReadLine(input, line));
+ return state.Finished(this->LastResult);
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParseBOM(std::istream& input,
+ std::string& line,
+ State& state)
+{
+ char bom[4];
+ if (!input.get(bom, 4))
+ {
+ this->LastResult.SetError(ResultErrorReadingInput, 1);
+ return false;
+ }
+ this->LastResult.HadBOM =
+ (bom[0] == char(0xEF) && bom[1] == char(0xBB) && bom[2] == char(0xBF));
+ if (!state.ReadLine(input, line))
+ {
+ this->LastResult.SetError(ResultErrorReadingInput, 1);
+ return false;
+ }
+ if (!this->LastResult.HadBOM)
+ line = bom + line; // it wasn't a BOM, prepend it to first line
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParseMultiValueTag(const std::string& line,
+ ParsedLine& parsedLine,
+ State& state)
+{
+ size_t idxEqualSign = line.find('=');
+ const std::string& fullTag = line.substr(0, idxEqualSign);
+ if (!this->ParseTag(fullTag, parsedLine, state))
+ return false;
+ if (idxEqualSign != line.npos)
+ {
+ size_t idxFieldStart = idxEqualSign + 1;
+ if (idxFieldStart < line.size())
+ {
+ size_t idxParsing = idxFieldStart;
+ bool inQuotes = false;
+ for (;;)
+ {
+ idxParsing = line.find_first_of(",\"", idxParsing);
+ bool fieldOver = false;
+ if (idxParsing == line.npos)
+ {
+ fieldOver = true;
+ if (inQuotes)
+ {
+ this->LastResult.SetError(ResultErrorInputStructure,
+ state.GetCurrentLine());
+ return false;
+ }
+ }
+ else if (line[idxParsing] == ',' && !inQuotes)
+ fieldOver = true;
+ else if (line[idxParsing] == '"')
+ inQuotes = !inQuotes;
+ if (fieldOver)
+ {
+ if (!this->ParseValue(line.substr(idxFieldStart,
+ idxParsing - idxFieldStart),
+ parsedLine))
+ return false;
+ if (idxParsing == line.npos)
+ break; //end of last field
+ idxFieldStart = idxParsing + 1;
+ }
+ ++idxParsing;
+ }
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParseSingleValueTag(const std::string& line,
+ ParsedLine& parsedLine,
+ State& state)
+{
+ size_t idxEqualSign = line.find('=');
+ const std::string& fullTag = line.substr(0, idxEqualSign);
+ if (!this->ParseTag(fullTag, parsedLine, state))
+ return false;
+ if (idxEqualSign != line.npos)
+ {
+ if (!this->ParseValue(line.substr(idxEqualSign + 1), parsedLine))
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParseKeyValuePair(const std::string& line,
+ ParsedLine& parsedLine,
+ State& /*state*/)
+{
+ size_t idxEqualSign = line.find('=');
+ if (idxEqualSign == line.npos)
+ {
+ parsedLine.CopyVerbatim(line);
+ return true;
+ }
+ const std::string& key = line.substr(0, idxEqualSign);
+ parsedLine.SetTag(cmSystemTools::TrimWhitespace(key));
+ const std::string& value = line.substr(idxEqualSign + 1);
+ parsedLine.AddValue(cmSystemTools::TrimWhitespace(value));
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParseTag(const std::string& fullTag,
+ ParsedLine& parsedLine,
+ State& state)
+{
+ size_t idxLeftParen = fullTag.find('(');
+ if (idxLeftParen == fullTag.npos)
+ {
+ parsedLine.SetTag(cmSystemTools::TrimWhitespace(fullTag));
+ return true;
+ }
+ parsedLine.SetTag(
+ cmSystemTools::TrimWhitespace(fullTag.substr(0, idxLeftParen)));
+ size_t idxRightParen = fullTag.rfind(')');
+ if (idxRightParen == fullTag.npos)
+ {
+ this->LastResult.SetError(ResultErrorInputStructure,
+ state.GetCurrentLine());
+ return false;
+ }
+ const std::string& arg = cmSystemTools::TrimWhitespace(
+ fullTag.substr(idxLeftParen + 1, idxRightParen - idxLeftParen - 1));
+ if (arg[0] == '"')
+ {
+ if (arg[arg.size() - 1] != '"')
+ {
+ this->LastResult.SetError(ResultErrorInputStructure,
+ state.GetCurrentLine());
+ return false;
+ }
+ parsedLine.SetQuotedArg(arg.substr(1, arg.size() - 2));
+ }
+ else
+ parsedLine.SetArg(arg);
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmVisualStudioSlnParser::ParseValue(const std::string& value,
+ ParsedLine& parsedLine)
+{
+ const std::string& trimmed = cmSystemTools::TrimWhitespace(value);
+ if (trimmed.empty())
+ parsedLine.AddValue(trimmed);
+ else if (trimmed[0] == '"' && trimmed[trimmed.size() - 1] == '"')
+ parsedLine.AddQuotedValue(trimmed.substr(1, trimmed.size() - 2));
+ else
+ parsedLine.AddValue(trimmed);
+ return true;
+}
diff --git a/Source/cmVisualStudioSlnParser.h b/Source/cmVisualStudioSlnParser.h
new file mode 100644
index 0000000000..bee70cc13d
--- /dev/null
+++ b/Source/cmVisualStudioSlnParser.h
@@ -0,0 +1,118 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 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 cmVisualStudioSlnParser_h
+#define cmVisualStudioSlnParser_h
+
+#include "cmStandardIncludes.h"
+
+#include <bitset>
+
+
+class cmSlnData;
+
+
+class cmVisualStudioSlnParser
+{
+public:
+ enum ParseResult
+ {
+ ResultOK = 0,
+
+ ResultInternalError = -1,
+ ResultExternalError = 1,
+
+ ResultErrorOpeningInput = ResultExternalError,
+ ResultErrorReadingInput,
+ ResultErrorInputStructure,
+ ResultErrorInputData,
+
+ ResultErrorBadInternalState = ResultInternalError,
+ ResultErrorUnsupportedDataGroup = ResultInternalError - 1
+ };
+
+ enum DataGroup
+ {
+ DataGroupProjectsBit,
+ DataGroupProjectDependenciesBit,
+ DataGroupSolutionConfigurationsBit,
+ DataGroupProjectConfigurationsBit,
+ DataGroupSolutionFiltersBit,
+ DataGroupGenericGlobalSectionsBit,
+ DataGroupCount
+ };
+
+ typedef std::bitset<DataGroupCount> DataGroupSet;
+
+ static const DataGroupSet DataGroupProjects;
+ static const DataGroupSet DataGroupProjectDependencies;
+ static const DataGroupSet DataGroupSolutionConfigurations;
+ static const DataGroupSet DataGroupProjectConfigurations;
+ static const DataGroupSet DataGroupSolutionFilters;
+ static const DataGroupSet DataGroupGenericGlobalSections;
+ static const DataGroupSet DataGroupAll;
+
+ bool Parse(std::istream& input,
+ cmSlnData& output,
+ DataGroupSet dataGroups = DataGroupAll);
+
+ bool ParseFile(const std::string& file,
+ cmSlnData& output,
+ DataGroupSet dataGroups = DataGroupAll);
+
+ ParseResult GetParseResult() const;
+
+ size_t GetParseResultLine() const;
+
+ bool GetParseHadBOM() const;
+
+protected:
+ class State;
+ friend class State;
+ class ParsedLine;
+
+ struct ResultData
+ {
+ ParseResult Result;
+ size_t ResultLine;
+ bool HadBOM;
+
+ ResultData();
+ void Clear();
+ void SetError(ParseResult error, size_t line);
+ } LastResult;
+
+ bool IsDataGroupSetSupported(DataGroupSet dataGroups) const;
+
+ bool ParseImpl(std::istream& input, cmSlnData& output, State& state);
+
+ bool ParseBOM(std::istream& input, std::string& line, State& state);
+
+ bool ParseMultiValueTag(const std::string& line,
+ ParsedLine& parsedLine,
+ State& state);
+
+ bool ParseSingleValueTag(const std::string& line,
+ ParsedLine& parsedLine,
+ State& state);
+
+ bool ParseKeyValuePair(const std::string& line,
+ ParsedLine& parsedLine,
+ State& state);
+
+ bool ParseTag(const std::string& fullTag,
+ ParsedLine& parsedLine,
+ State& state);
+
+ bool ParseValue(const std::string& value, ParsedLine& parsedLine);
+};
+
+#endif
diff --git a/Source/cmVisualStudioWCEPlatformParser.cxx b/Source/cmVisualStudioWCEPlatformParser.cxx
new file mode 100644
index 0000000000..ca226fb50c
--- /dev/null
+++ b/Source/cmVisualStudioWCEPlatformParser.cxx
@@ -0,0 +1,179 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 "cmVisualStudioWCEPlatformParser.h"
+#include "cmGlobalVisualStudioGenerator.h"
+#include "cmXMLParser.h"
+
+int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version)
+{
+ const std::string registryBase =
+ cmGlobalVisualStudioGenerator::GetRegistryBase(version);
+ const std::string vckey = registryBase + "\\Setup\\VC;ProductDir";
+ const std::string vskey = registryBase + "\\Setup\\VS;ProductDir";
+
+ if(!cmSystemTools::ReadRegistryValue(vckey.c_str(),
+ this->VcInstallDir,
+ cmSystemTools::KeyWOW64_32) ||
+ !cmSystemTools::ReadRegistryValue(vskey.c_str(),
+ this->VsInstallDir,
+ cmSystemTools::KeyWOW64_32))
+ {
+ return 0;
+ }
+ cmSystemTools::ConvertToUnixSlashes(this->VcInstallDir);
+ cmSystemTools::ConvertToUnixSlashes(this->VsInstallDir);
+ this->VcInstallDir.append("/");
+ this->VsInstallDir.append("/");
+
+ const std::string configFilename =
+ this->VcInstallDir + "vcpackages/WCE.VCPlatform.config";
+
+ return this->ParseFile(configFilename.c_str());
+}
+
+std::string cmVisualStudioWCEPlatformParser::GetOSVersion() const
+{
+ if (this->OSMinorVersion.empty())
+ {
+ return OSMajorVersion;
+ }
+
+ return OSMajorVersion + "." + OSMinorVersion;
+}
+
+const char* cmVisualStudioWCEPlatformParser::GetArchitectureFamily() const
+{
+ std::map<std::string, std::string>::const_iterator it =
+ this->Macros.find("ARCHFAM");
+ if (it != this->Macros.end())
+ {
+ return it->second.c_str();
+ }
+
+ return 0;
+}
+
+void cmVisualStudioWCEPlatformParser::StartElement(const std::string& name,
+ const char** attributes)
+{
+ if(this->FoundRequiredName)
+ {
+ return;
+ }
+
+ this->CharacterData = "";
+
+ if(name == "PlatformData")
+ {
+ this->PlatformName = "";
+ this->OSMajorVersion = "";
+ this->OSMinorVersion = "";
+ this->Macros.clear();
+ }
+
+ if(name == "Macro")
+ {
+ std::string macroName;
+ std::string macroValue;
+
+ for(const char** attr = attributes; *attr; attr += 2)
+ {
+ if(strcmp(attr[0], "Name") == 0)
+ {
+ macroName = attr[1];
+ }
+ else if(strcmp(attr[0], "Value") == 0)
+ {
+ macroValue = attr[1];
+ }
+ }
+
+ if(!macroName.empty())
+ {
+ this->Macros[macroName] = macroValue;
+ }
+ }
+ else if(name == "Directories")
+ {
+ for(const char** attr = attributes; *attr; attr += 2)
+ {
+ if(strcmp(attr[0], "Include") == 0)
+ {
+ this->Include = attr[1];
+ }
+ else if(strcmp(attr[0], "Library") == 0)
+ {
+ this->Library = attr[1];
+ }
+ else if(strcmp(attr[0], "Path") == 0)
+ {
+ this->Path = attr[1];
+ }
+ }
+ }
+}
+
+void cmVisualStudioWCEPlatformParser::EndElement(const std::string& name)
+{
+ if(!this->RequiredName)
+ {
+ if(name == "PlatformName")
+ {
+ this->AvailablePlatforms.push_back(this->CharacterData);
+ }
+ return;
+ }
+
+ if(this->FoundRequiredName)
+ {
+ return;
+ }
+
+ if(name == "PlatformName")
+ {
+ this->PlatformName = this->CharacterData;
+ }
+ else if(name == "OSMajorVersion")
+ {
+ this->OSMajorVersion = this->CharacterData;
+ }
+ else if(name == "OSMinorVersion")
+ {
+ this->OSMinorVersion = this->CharacterData;
+ }
+ else if(name == "Platform")
+ {
+ if(this->PlatformName == this->RequiredName)
+ {
+ this->FoundRequiredName = true;
+ }
+ }
+}
+
+void cmVisualStudioWCEPlatformParser::CharacterDataHandler(const char* data,
+ int length)
+{
+ this->CharacterData.append(data, length);
+}
+
+std::string cmVisualStudioWCEPlatformParser::FixPaths(
+ const std::string& paths) const
+{
+ std::string ret = paths;
+ cmSystemTools::ReplaceString(ret, "$(PATH)", "%PATH%");
+ cmSystemTools::ReplaceString(ret, "$(VCInstallDir)", VcInstallDir.c_str());
+ cmSystemTools::ReplaceString(ret, "$(VSInstallDir)", VsInstallDir.c_str());
+ cmSystemTools::ReplaceString(ret, "\\", "/");
+ cmSystemTools::ReplaceString(ret, "//", "/");
+ cmSystemTools::ReplaceString(ret, "/", "\\");
+ return ret;
+}
diff --git a/Source/cmVisualStudioWCEPlatformParser.h b/Source/cmVisualStudioWCEPlatformParser.h
new file mode 100644
index 0000000000..042df01422
--- /dev/null
+++ b/Source/cmVisualStudioWCEPlatformParser.h
@@ -0,0 +1,68 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 cmVisualStudioWCEPlatformParser_h
+#define cmVisualStudioWCEPlatformParser_h
+#include "cmStandardIncludes.h"
+
+#include "cmXMLParser.h"
+
+// This class is used to parse XML with configuration
+// of installed SDKs in system
+class cmVisualStudioWCEPlatformParser : public cmXMLParser
+{
+public:
+ cmVisualStudioWCEPlatformParser(const char* name = NULL)
+ : RequiredName(name)
+ , FoundRequiredName(false)
+ {
+ }
+
+ int ParseVersion(const char* version);
+
+ bool Found() const {return this->FoundRequiredName;}
+ const char* GetArchitectureFamily() const;
+ std::string GetOSVersion() const;
+ std::string GetIncludeDirectories() const {
+ return this->FixPaths(this->Include); }
+ std::string GetLibraryDirectories() const {
+ return this->FixPaths(this->Library); }
+ std::string GetPathDirectories() const {
+ return this->FixPaths(this->Path); }
+ const std::vector<std::string>& GetAvailablePlatforms() const {
+ return this->AvailablePlatforms; }
+
+protected:
+ virtual void StartElement(const std::string& name, const char** attributes);
+ void EndElement(const std::string& name);
+ void CharacterDataHandler(const char* data, int length);
+
+private:
+ std::string FixPaths(const std::string& paths) const;
+
+ std::string CharacterData;
+
+ std::string Include;
+ std::string Library;
+ std::string Path;
+ std::string PlatformName;
+ std::string OSMajorVersion;
+ std::string OSMinorVersion;
+ std::map<std::string, std::string> Macros;
+ std::vector<std::string> AvailablePlatforms;
+
+ const char* RequiredName;
+ bool FoundRequiredName;
+ std::string VcInstallDir;
+ std::string VsInstallDir;
+};
+
+#endif
diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx
new file mode 100644
index 0000000000..851c4cb20e
--- /dev/null
+++ b/Source/cmWhileCommand.cxx
@@ -0,0 +1,143 @@
+/*============================================================================
+ 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 "cmWhileCommand.h"
+#include "cmConditionEvaluator.h"
+
+bool cmWhileFunctionBlocker::
+IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
+ cmExecutionStatus &inStatus)
+{
+ // at end of for each execute recorded commands
+ if (!cmSystemTools::Strucmp(lff.Name.c_str(),"while"))
+ {
+ // record the number of while commands past this one
+ this->Depth++;
+ }
+ else if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endwhile"))
+ {
+ // if this is the endwhile for this while loop then execute
+ if (!this->Depth)
+ {
+ // Remove the function blocker for this scope or bail.
+ cmsys::auto_ptr<cmFunctionBlocker>
+ fb(mf.RemoveFunctionBlocker(this, lff));
+ if(!fb.get()) { return false; }
+
+ std::string errorString;
+
+ std::vector<cmExpandedCommandArgument> expandedArguments;
+ mf.ExpandArguments(this->Args, expandedArguments);
+ cmake::MessageType messageType;
+
+ cmConditionEvaluator conditionEvaluator(mf);
+
+ bool isTrue = conditionEvaluator.IsTrue(
+ expandedArguments, errorString, messageType);
+
+ while (isTrue)
+ {
+ if (errorString.size())
+ {
+ std::string err = "had incorrect arguments: ";
+ unsigned int i;
+ for(i =0; i < this->Args.size(); ++i)
+ {
+ err += (this->Args[i].Delim?"\"":"");
+ err += this->Args[i].Value;
+ err += (this->Args[i].Delim?"\"":"");
+ err += " ";
+ }
+ err += "(";
+ err += errorString;
+ err += ").";
+ mf.IssueMessage(messageType, err);
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+ }
+
+ // Invoke all the functions that were collected in the block.
+ for(unsigned int c = 0; c < this->Functions.size(); ++c)
+ {
+ cmExecutionStatus status;
+ mf.ExecuteCommand(this->Functions[c],status);
+ if (status.GetReturnInvoked())
+ {
+ inStatus.SetReturnInvoked(true);
+ return true;
+ }
+ if (status.GetBreakInvoked())
+ {
+ return true;
+ }
+ if(cmSystemTools::GetFatalErrorOccured() )
+ {
+ return true;
+ }
+ }
+ expandedArguments.clear();
+ mf.ExpandArguments(this->Args, expandedArguments);
+ isTrue = conditionEvaluator.IsTrue(
+ expandedArguments, errorString, messageType);
+ }
+ return true;
+ }
+ else
+ {
+ // decrement for each nested while that ends
+ this->Depth--;
+ }
+ }
+
+ // record the command
+ this->Functions.push_back(lff);
+
+ // always return true
+ return true;
+}
+
+bool cmWhileFunctionBlocker::
+ShouldRemove(const cmListFileFunction& lff, cmMakefile& )
+{
+ if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endwhile"))
+ {
+ // if the endwhile has arguments, then make sure
+ // they match the arguments of the matching while
+ if (lff.Arguments.size() == 0 ||
+ lff.Arguments == this->Args)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool cmWhileCommand
+::InvokeInitialPass(const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus &)
+{
+ if(args.size() < 1)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ // create a function blocker
+ cmWhileFunctionBlocker *f = new cmWhileFunctionBlocker();
+ f->Args = args;
+ this->Makefile->AddFunctionBlocker(f);
+
+ return true;
+}
+
diff --git a/Source/cmWhileCommand.h b/Source/cmWhileCommand.h
new file mode 100644
index 0000000000..9fafffc09b
--- /dev/null
+++ b/Source/cmWhileCommand.h
@@ -0,0 +1,75 @@
+/*============================================================================
+ 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 cmWhileCommand_h
+#define cmWhileCommand_h
+
+#include "cmCommand.h"
+#include "cmFunctionBlocker.h"
+#include "cmListFileCache.h"
+
+class cmWhileFunctionBlocker : public cmFunctionBlocker
+{
+public:
+ cmWhileFunctionBlocker() {this->Depth=0;}
+ virtual ~cmWhileFunctionBlocker() {}
+ virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
+ cmMakefile &mf,
+ cmExecutionStatus &);
+ virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf);
+
+ std::vector<cmListFileArgument> Args;
+ std::vector<cmListFileFunction> Functions;
+private:
+ int Depth;
+};
+
+/// \brief Starts a while loop
+class cmWhileCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmWhileCommand;
+ }
+
+ /**
+ * This overrides the default InvokeInitialPass implementation.
+ * It records the arguments before expansion.
+ */
+ virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus &);
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &) { return false; }
+
+ /**
+ * 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 "while";}
+
+ cmTypeMacro(cmWhileCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmWriteFileCommand.cxx b/Source/cmWriteFileCommand.cxx
new file mode 100644
index 0000000000..af955ecf86
--- /dev/null
+++ b/Source/cmWriteFileCommand.cxx
@@ -0,0 +1,94 @@
+/*============================================================================
+ 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 "cmWriteFileCommand.h"
+#include <cmsys/FStream.hxx>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+// cmLibraryCommand
+bool cmWriteFileCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+ std::string message;
+ std::vector<std::string>::const_iterator i = args.begin();
+
+ std::string fileName = *i;
+ bool overwrite = true;
+ i++;
+
+ for(;i != args.end(); ++i)
+ {
+ if ( *i == "APPEND" )
+ {
+ overwrite = false;
+ }
+ else
+ {
+ message += *i;
+ }
+ }
+
+ if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) )
+ {
+ std::string e = "attempted to write a file: " + fileName
+ + " into a source directory.";
+ this->SetError(e);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+
+ std::string dir = cmSystemTools::GetFilenamePath(fileName);
+ cmSystemTools::MakeDirectory(dir.c_str());
+
+ mode_t mode = 0;
+
+ // Set permissions to writable
+ if ( cmSystemTools::GetPermissions(fileName.c_str(), mode) )
+ {
+ cmSystemTools::SetPermissions(fileName.c_str(),
+#if defined( _MSC_VER ) || defined( __MINGW32__ )
+ mode | S_IWRITE
+#elif defined( __BORLANDC__ )
+ mode | S_IWUSR
+#else
+ mode | S_IWUSR | S_IWGRP
+#endif
+ );
+ }
+ // If GetPermissions fails, pretend like it is ok. File open will fail if
+ // the file is not writable
+ cmsys::ofstream file(fileName.c_str(),
+ overwrite?std::ios::out : std::ios::app);
+ if ( !file )
+ {
+ std::string error = "Internal CMake error when trying to open file: ";
+ error += fileName.c_str();
+ error += " for writing.";
+ this->SetError(error);
+ return false;
+ }
+ file << message << std::endl;
+ file.close();
+ if(mode)
+ {
+ cmSystemTools::SetPermissions(fileName.c_str(), mode);
+ }
+
+ return true;
+}
+
diff --git a/Source/cmWriteFileCommand.h b/Source/cmWriteFileCommand.h
new file mode 100644
index 0000000000..0d06878c03
--- /dev/null
+++ b/Source/cmWriteFileCommand.h
@@ -0,0 +1,59 @@
+/*============================================================================
+ 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 cmWriteFileCommand_h
+#define cmWriteFileCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmWriteFileCommand
+ * \brief Writes a message to a file
+ *
+ */
+class cmWriteFileCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmWriteFileCommand;
+ }
+
+ /**
+ * 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 "write_file";}
+
+ /** This command is kept for compatibility with older CMake versions. */
+ virtual bool IsDiscouraged() const
+ {
+ return true;
+ }
+
+ cmTypeMacro(cmWriteFileCommand, cmCommand);
+};
+
+
+#endif
diff --git a/Source/cmXCode21Object.cxx b/Source/cmXCode21Object.cxx
new file mode 100644
index 0000000000..855e1ad2ff
--- /dev/null
+++ b/Source/cmXCode21Object.cxx
@@ -0,0 +1,105 @@
+/*============================================================================
+ 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 "cmXCode21Object.h"
+#include "cmSystemTools.h"
+
+//----------------------------------------------------------------------------
+cmXCode21Object::cmXCode21Object(PBXType ptype, Type type)
+ :cmXCodeObject(ptype, type)
+{
+ this->Version = 21;
+}
+
+//----------------------------------------------------------------------------
+void cmXCode21Object::PrintComment(std::ostream& out)
+{
+ if(this->Comment.size() == 0)
+ {
+ cmXCodeObject* n = this->GetObject("name");
+ if(n)
+ {
+ this->Comment = n->GetString();
+ cmSystemTools::ReplaceString(this->Comment, "\"", "");
+ }
+ }
+ out << "/* ";
+ out << this->Comment;
+ out << " */";
+}
+
+//----------------------------------------------------------------------------
+void cmXCode21Object::PrintList(std::vector<cmXCodeObject*> const& v,
+ std::ostream& out, PBXType t)
+{
+ bool hasOne = false;
+ for(std::vector<cmXCodeObject*>::const_iterator i = v.begin();
+ i != v.end(); ++i)
+ {
+ cmXCodeObject* obj = *i;
+ if(obj->GetType() == OBJECT && obj->GetIsA() == t)
+ {
+ hasOne = true;
+ break;
+ }
+ }
+ if(!hasOne)
+ {
+ return;
+ }
+ out << "\n/* Begin " << PBXTypeNames[t] << " section */\n";
+ for(std::vector<cmXCodeObject*>::const_iterator i = v.begin();
+ i != v.end(); ++i)
+ {
+ cmXCodeObject* obj = *i;
+ if(obj->GetType() == OBJECT && obj->GetIsA() == t)
+ {
+ obj->Print(out);
+ }
+ }
+ out << "/* End " << PBXTypeNames[t] << " section */\n";
+}
+
+//----------------------------------------------------------------------------
+void cmXCode21Object::PrintList(std::vector<cmXCodeObject*> const& v,
+ std::ostream& out)
+{
+ cmXCodeObject::Indent(1, out);
+ out << "objects = {\n";
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXAggregateTarget);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXBuildFile);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXBuildStyle);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXContainerItemProxy);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXFileReference);
+ cmXCode21Object::PrintList(v, out,
+ cmXCode21Object::PBXFrameworksBuildPhase);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXGroup);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXHeadersBuildPhase);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXNativeTarget);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXProject);
+ cmXCode21Object::PrintList(v, out,
+ cmXCode21Object::PBXShellScriptBuildPhase);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXResourcesBuildPhase);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXSourcesBuildPhase);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXCopyFilesBuildPhase);
+ cmXCode21Object::PrintList(v, out,
+ cmXCode21Object::PBXApplicationReference);
+ cmXCode21Object::PrintList(v, out,
+ cmXCode21Object::PBXExecutableFileReference);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXLibraryReference);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXToolTarget);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXLibraryTarget);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXTargetDependency);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::XCBuildConfiguration);
+ cmXCode21Object::PrintList(v, out, cmXCode21Object::XCConfigurationList);
+ cmXCodeObject::Indent(1, out);
+ out << "};\n";
+}
diff --git a/Source/cmXCode21Object.h b/Source/cmXCode21Object.h
new file mode 100644
index 0000000000..cc3ab047b0
--- /dev/null
+++ b/Source/cmXCode21Object.h
@@ -0,0 +1,28 @@
+/*============================================================================
+ 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 cmXCode21Object_h
+#define cmXCode21Object_h
+
+#include "cmXCodeObject.h"
+
+class cmXCode21Object : public cmXCodeObject
+{
+public:
+ cmXCode21Object(PBXType ptype, Type type);
+ virtual void PrintComment(std::ostream&);
+ static void PrintList(std::vector<cmXCodeObject*> const&,
+ std::ostream& out,
+ PBXType t);
+ static void PrintList(std::vector<cmXCodeObject*> const&,
+ std::ostream& out);
+};
+#endif
diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx
new file mode 100644
index 0000000000..3302a8de41
--- /dev/null
+++ b/Source/cmXCodeObject.cxx
@@ -0,0 +1,272 @@
+/*============================================================================
+ 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 "cmXCodeObject.h"
+#include "cmSystemTools.h"
+
+#include <CoreFoundation/CoreFoundation.h> // CFUUIDCreate
+
+//----------------------------------------------------------------------------
+const char* cmXCodeObject::PBXTypeNames[] = {
+ "PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
+ "PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
+ "PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
+ "PBXTargetDependency", "PBXShellScriptBuildPhase",
+ "PBXResourcesBuildPhase", "PBXApplicationReference",
+ "PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
+ "PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
+ "XCConfigurationList",
+ "PBXCopyFilesBuildPhase",
+ "None"
+ };
+
+//----------------------------------------------------------------------------
+cmXCodeObject::~cmXCodeObject()
+{
+ this->Version = 15;
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
+{
+ this->Version = 15;
+ this->Target = 0;
+ this->Object =0;
+
+ this->IsA = ptype;
+
+ if(type == OBJECT)
+ {
+ // Set the Id of an Xcode object to a unique string for each instance.
+ // However the Xcode user file references certain Ids: for those cases,
+ // override the generated Id using SetId().
+ //
+ char cUuid[40] = {0};
+ CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
+ CFStringRef s = CFUUIDCreateString(kCFAllocatorDefault, uuid);
+ CFStringGetCString(s, cUuid, sizeof(cUuid), kCFStringEncodingUTF8);
+ this->Id = cUuid;
+ CFRelease(s);
+ CFRelease(uuid);
+ }
+ else
+ {
+ this->Id =
+ "Temporary cmake object, should not be referred to in Xcode file";
+ }
+
+ cmSystemTools::ReplaceString(this->Id, "-", "");
+ if(this->Id.size() > 24)
+ {
+ this->Id = this->Id.substr(0, 24);
+ }
+
+ this->TypeValue = type;
+ if(this->TypeValue == OBJECT)
+ {
+ this->AddAttribute("isa", 0);
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmXCodeObject::Indent(int level, std::ostream& out)
+{
+ while(level)
+ {
+ out << " ";
+ level--;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmXCodeObject::Print(std::ostream& out)
+{
+ std::string separator = "\n";
+ int indentFactor = 1;
+ if(this->Version > 15
+ && (this->IsA == PBXFileReference || this->IsA == PBXBuildFile))
+ {
+ separator = " ";
+ indentFactor = 0;
+ }
+ cmXCodeObject::Indent(2*indentFactor, out);
+ out << this->Id << " ";
+ if(!(this->IsA == PBXGroup && this->Comment.size() == 0))
+ {
+ this->PrintComment(out);
+ }
+ out << " = {";
+ if(separator == "\n")
+ {
+ out << separator;
+ }
+ std::map<std::string, cmXCodeObject*>::iterator i;
+ cmXCodeObject::Indent(3*indentFactor, out);
+ out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator;
+ for(i = this->ObjectAttributes.begin();
+ i != this->ObjectAttributes.end(); ++i)
+ {
+ cmXCodeObject* object = i->second;
+ if(i->first != "isa")
+ {
+ cmXCodeObject::Indent(3*indentFactor, out);
+ }
+ else
+ {
+ continue;
+ }
+ if(object->TypeValue == OBJECT_LIST)
+ {
+ out << i->first << " = (" << separator;
+ for(unsigned int k = 0; k < i->second->List.size(); k++)
+ {
+ cmXCodeObject::Indent(4*indentFactor, out);
+ out << i->second->List[k]->Id << " ";
+ i->second->List[k]->PrintComment(out);
+ out << "," << separator;
+ }
+ cmXCodeObject::Indent(3*indentFactor, out);
+ out << ");" << separator;
+ }
+ else if(object->TypeValue == ATTRIBUTE_GROUP)
+ {
+ std::map<std::string, cmXCodeObject*>::iterator j;
+ out << i->first << " = {" << separator;
+ for(j = object->ObjectAttributes.begin(); j !=
+ object->ObjectAttributes.end(); ++j)
+ {
+ cmXCodeObject::Indent(4 *indentFactor, out);
+
+ if(j->second->TypeValue == STRING)
+ {
+ cmXCodeObject::PrintString(out,j->first);
+ out << " = ";
+ j->second->PrintString(out);
+ out << ";";
+ }
+ else if(j->second->TypeValue == OBJECT_LIST)
+ {
+ cmXCodeObject::PrintString(out,j->first);
+ out << " = (";
+ for(unsigned int k = 0; k < j->second->List.size(); k++)
+ {
+ if(j->second->List[k]->TypeValue == STRING)
+ {
+ j->second->List[k]->PrintString(out);
+ out << ", ";
+ }
+ else
+ {
+ out << "List_" << k << "_TypeValue_IS_NOT_STRING, ";
+ }
+ }
+ out << ");";
+ }
+ else
+ {
+ cmXCodeObject::PrintString(out,j->first);
+ out << " = error_unexpected_TypeValue_" <<
+ j->second->TypeValue << ";";
+ }
+
+ out << separator;
+ }
+ cmXCodeObject::Indent(3 *indentFactor, out);
+ out << "};" << separator;
+ }
+ else if(object->TypeValue == OBJECT_REF)
+ {
+ cmXCodeObject::PrintString(out,i->first);
+ out << " = " << object->Object->Id;
+ if(object->Object->HasComment() && i->first != "remoteGlobalIDString")
+ {
+ out << " ";
+ object->Object->PrintComment(out);
+ }
+ out << ";" << separator;
+ }
+ else if(object->TypeValue == STRING)
+ {
+ cmXCodeObject::PrintString(out,i->first);
+ out << " = ";
+ object->PrintString(out);
+ out << ";" << separator;
+ }
+ else
+ {
+ out << "what is this?? " << i->first << "\n";
+ }
+ }
+ cmXCodeObject::Indent(2*indentFactor, out);
+ out << "};\n";
+}
+
+//----------------------------------------------------------------------------
+void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
+ std::ostream& out)
+{
+ cmXCodeObject::Indent(1, out);
+ out << "objects = {\n";
+ for(unsigned int i = 0; i < objs.size(); ++i)
+ {
+ if(objs[i]->TypeValue == OBJECT)
+ {
+ objs[i]->Print(out);
+ }
+ }
+ cmXCodeObject::Indent(1, out);
+ out << "};\n";
+}
+
+//----------------------------------------------------------------------------
+void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
+{
+ this->ObjectAttributes = copy->ObjectAttributes;
+ this->List = copy->List;
+ this->String = copy->String;
+ this->Object = copy->Object;
+}
+
+//----------------------------------------------------------------------------
+void cmXCodeObject::PrintString(std::ostream& os,std::string String)
+{
+ // The string needs to be quoted if it contains any characters
+ // considered special by the Xcode project file parser.
+ bool needQuote =
+ (String.empty() ||
+ String.find_first_of(" <>.+-=@$[],") != String.npos);
+ const char* quote = needQuote? "\"" : "";
+
+ // Print the string, quoted and escaped as necessary.
+ os << quote;
+ for(std::string::const_iterator i = String.begin();
+ i != String.end(); ++i)
+ {
+ if(*i == '"')
+ {
+ // Escape double-quotes.
+ os << '\\';
+ }
+ os << *i;
+ }
+ os << quote;
+}
+
+void cmXCodeObject::PrintString(std::ostream& os) const
+{
+ cmXCodeObject::PrintString(os,this->String);
+}
+
+//----------------------------------------------------------------------------
+void cmXCodeObject::SetString(const std::string& s)
+{
+ this->String = s;
+}
diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h
new file mode 100644
index 0000000000..ed2940a0cc
--- /dev/null
+++ b/Source/cmXCodeObject.h
@@ -0,0 +1,162 @@
+/*============================================================================
+ 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 cmXCodeObject_h
+#define cmXCodeObject_h
+
+#include "cmStandardIncludes.h"
+class cmTarget;
+
+class cmXCodeObject
+{
+public:
+ enum Type { OBJECT_LIST, STRING, ATTRIBUTE_GROUP, OBJECT_REF, OBJECT };
+ enum PBXType { PBXGroup, PBXBuildStyle, PBXProject, PBXHeadersBuildPhase,
+ PBXSourcesBuildPhase, PBXFrameworksBuildPhase,
+ PBXNativeTarget, PBXFileReference, PBXBuildFile,
+ PBXContainerItemProxy, PBXTargetDependency,
+ PBXShellScriptBuildPhase, PBXResourcesBuildPhase,
+ PBXApplicationReference, PBXExecutableFileReference,
+ PBXLibraryReference, PBXToolTarget, PBXLibraryTarget,
+ PBXAggregateTarget,XCBuildConfiguration,XCConfigurationList,
+ PBXCopyFilesBuildPhase,
+ None
+ };
+ class StringVec: public std::vector<std::string> {};
+ static const char* PBXTypeNames[];
+ virtual ~cmXCodeObject();
+ cmXCodeObject(PBXType ptype, Type type);
+ Type GetType() { return this->TypeValue;}
+ PBXType GetIsA() { return this->IsA;}
+
+ void SetString(const std::string& s);
+ const std::string& GetString()
+ {
+ return this->String;
+ }
+
+ void AddAttribute(const std::string& name, cmXCodeObject* value)
+ {
+ this->ObjectAttributes[name] = value;
+ }
+
+ void SetObject(cmXCodeObject* value)
+ {
+ this->Object = value;
+ }
+ cmXCodeObject* GetObject()
+ {
+ return this->Object;
+ }
+ void AddObject(cmXCodeObject* value)
+ {
+ this->List.push_back(value);
+ }
+ bool HasObject(cmXCodeObject* o)
+ {
+ return !(std::find(this->List.begin(), this->List.end(), o)
+ == this->List.end());
+ }
+ void AddUniqueObject(cmXCodeObject* value)
+ {
+ if(std::find(this->List.begin(), this->List.end(), value)
+ == this->List.end())
+ {
+ this->List.push_back(value);
+ }
+ }
+ static void Indent(int level, std::ostream& out);
+ void Print(std::ostream& out);
+ virtual void PrintComment(std::ostream&) {};
+
+ static void PrintList(std::vector<cmXCodeObject*> const&,
+ std::ostream& out);
+ const std::string& GetId()
+ {
+ return this->Id;
+ }
+ void SetId(const std::string& id)
+ {
+ this->Id = id;
+ }
+ cmTarget* GetTarget()
+ {
+ return this->Target;
+ }
+ void SetTarget(cmTarget* t)
+ {
+ this->Target = t;
+ }
+ const std::string& GetComment() {return this->Comment;}
+ bool HasComment() { return (!this->Comment.empty());}
+ cmXCodeObject* GetObject(const char* name)
+ {
+ if(this->ObjectAttributes.count(name))
+ {
+ return this->ObjectAttributes[name];
+ }
+ return 0;
+ }
+ // serach the attribute list for an object of the specified type
+ cmXCodeObject* GetObject(cmXCodeObject::PBXType t)
+ {
+ for(std::vector<cmXCodeObject*>::iterator i = this->List.begin();
+ i != this->List.end(); ++i)
+ {
+ cmXCodeObject* o = *i;
+ if(o->IsA == t)
+ {
+ return o;
+ }
+ }
+ return 0;
+ }
+
+ void CopyAttributes(cmXCodeObject* );
+
+ void AddDependLibrary(const std::string& configName,
+ const std::string& l)
+ {
+ this->DependLibraries[configName].push_back(l);
+ }
+ std::map<std::string, StringVec> const& GetDependLibraries()
+ {
+ return this->DependLibraries;
+ }
+ void AddDependTarget(const std::string& configName,
+ const std::string& tName)
+ {
+ this->DependTargets[configName].push_back(tName);
+ }
+ std::map<std::string, StringVec> const& GetDependTargets()
+ {
+ return this->DependTargets;
+ }
+ std::vector<cmXCodeObject*> const& GetObjectList() { return this->List;}
+ void SetComment(const std::string& c) { this->Comment = c;}
+ static void PrintString(std::ostream& os,std::string String);
+protected:
+ void PrintString(std::ostream& os) const;
+
+ cmTarget* Target;
+ Type TypeValue;
+ std::string Id;
+ PBXType IsA;
+ int Version;
+ std::string Comment;
+ std::string String;
+ cmXCodeObject* Object;
+ std::vector<cmXCodeObject*> List;
+ std::map<std::string, StringVec> DependLibraries;
+ std::map<std::string, StringVec> DependTargets;
+ std::map<std::string, cmXCodeObject*> ObjectAttributes;
+};
+#endif
diff --git a/Source/cmXMLParser.cxx b/Source/cmXMLParser.cxx
new file mode 100644
index 0000000000..391b874d1a
--- /dev/null
+++ b/Source/cmXMLParser.cxx
@@ -0,0 +1,247 @@
+/*============================================================================
+ 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 "cmXMLParser.h"
+#include <cmsys/FStream.hxx>
+
+#include <cm_expat.h>
+#include <ctype.h>
+
+//----------------------------------------------------------------------------
+cmXMLParser::cmXMLParser()
+{
+ this->Parser = 0;
+ this->ParseError = 0;
+ this->ReportCallback = 0;
+ this->ReportCallbackData = 0;
+}
+
+//----------------------------------------------------------------------------
+cmXMLParser::~cmXMLParser()
+{
+ if ( this->Parser )
+ {
+ this->CleanupParser();
+ }
+}
+
+//----------------------------------------------------------------------------
+int cmXMLParser::Parse(const char* string)
+{
+ return (int)this->InitializeParser() &&
+ this->ParseChunk(string, strlen(string)) &&
+ this->CleanupParser();
+}
+
+int cmXMLParser::ParseFile(const char* file)
+{
+ if ( !file )
+ {
+ return 0;
+ }
+
+ cmsys::ifstream ifs(file);
+ if ( !ifs )
+ {
+ return 0;
+ }
+
+ cmOStringStream str;
+ str << ifs.rdbuf();
+ return this->Parse(str.str().c_str());
+}
+
+//----------------------------------------------------------------------------
+int cmXMLParser::InitializeParser()
+{
+ if ( this->Parser )
+ {
+ std::cerr << "Parser already initialized" << std::endl;
+ this->ParseError = 1;
+ return 0;
+ }
+
+ // Create the expat XML parser.
+ this->Parser = XML_ParserCreate(0);
+ XML_SetElementHandler(static_cast<XML_Parser>(this->Parser),
+ &cmXMLParserStartElement,
+ &cmXMLParserEndElement);
+ XML_SetCharacterDataHandler(static_cast<XML_Parser>(this->Parser),
+ &cmXMLParserCharacterDataHandler);
+ XML_SetUserData(static_cast<XML_Parser>(this->Parser), this);
+ this->ParseError = 0;
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+int cmXMLParser::ParseChunk(const char* inputString,
+ std::string::size_type length)
+{
+ if ( !this->Parser )
+ {
+ std::cerr << "Parser not initialized" << std::endl;
+ this->ParseError = 1;
+ return 0;
+ }
+ int res;
+ res = this->ParseBuffer(inputString, length);
+ if ( res == 0 )
+ {
+ this->ParseError = 1;
+ }
+ return res;
+}
+
+//----------------------------------------------------------------------------
+int cmXMLParser::CleanupParser()
+{
+ if ( !this->Parser )
+ {
+ std::cerr << "Parser not initialized" << std::endl;
+ this->ParseError = 1;
+ return 0;
+ }
+ int result = !this->ParseError;
+ if(result)
+ {
+ // Tell the expat XML parser about the end-of-input.
+ if(!XML_Parse(static_cast<XML_Parser>(this->Parser), "", 0, 1))
+ {
+ this->ReportXmlParseError();
+ result = 0;
+ }
+ }
+
+ // Clean up the parser.
+ XML_ParserFree(static_cast<XML_Parser>(this->Parser));
+ this->Parser = 0;
+
+ return result;
+}
+
+//----------------------------------------------------------------------------
+int cmXMLParser::ParseBuffer(const char* buffer, std::string::size_type count)
+{
+ // Pass the buffer to the expat XML parser.
+ if(!XML_Parse(static_cast<XML_Parser>(this->Parser), buffer,
+ static_cast<int>(count), 0))
+ {
+ this->ReportXmlParseError();
+ return 0;
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+int cmXMLParser::ParseBuffer(const char* buffer)
+{
+ return this->ParseBuffer(buffer, static_cast<int>(strlen(buffer)));
+}
+
+//----------------------------------------------------------------------------
+int cmXMLParser::ParsingComplete()
+{
+ // Default behavior is to parse to end of stream.
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+void cmXMLParser::StartElement(const std::string& name,
+ const char ** /*atts*/)
+{
+ std::cout << "Start element: " << name << std::endl;
+}
+
+//----------------------------------------------------------------------------
+void cmXMLParser::EndElement(const std::string& name)
+{
+ std::cout << "End element: " << name << std::endl;
+}
+
+//----------------------------------------------------------------------------
+void cmXMLParser::CharacterDataHandler(const char* /*inData*/,
+ int /*inLength*/)
+{
+}
+
+//----------------------------------------------------------------------------
+int cmXMLParser::IsSpace(char c)
+{
+ return isspace(c);
+}
+
+//----------------------------------------------------------------------------
+const char* cmXMLParser::FindAttribute(const char** atts,
+ const char* attribute)
+{
+ if(atts && attribute)
+ {
+ for(const char** a = atts; *a && *(a+1); a += 2)
+ {
+ if(strcmp(*a, attribute) == 0)
+ {
+ return *(a+1);
+ }
+ }
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+void cmXMLParserStartElement(void* parser, const char *name,
+ const char **atts)
+{
+ // Begin element handler that is registered with the XML_Parser.
+ // This just casts the user data to a cmXMLParser and calls
+ // StartElement.
+ static_cast<cmXMLParser*>(parser)->StartElement(name, atts);
+}
+
+//----------------------------------------------------------------------------
+void cmXMLParserEndElement(void* parser, const char *name)
+{
+ // End element handler that is registered with the XML_Parser. This
+ // just casts the user data to a cmXMLParser and calls EndElement.
+ static_cast<cmXMLParser*>(parser)->EndElement(name);
+}
+
+//----------------------------------------------------------------------------
+void cmXMLParserCharacterDataHandler(void* parser, const char* data,
+ int length)
+{
+ // Character data handler that is registered with the XML_Parser.
+ // This just casts the user data to a cmXMLParser and calls
+ // CharacterDataHandler.
+ static_cast<cmXMLParser*>(parser)->CharacterDataHandler(data, length);
+}
+
+//----------------------------------------------------------------------------
+void cmXMLParser::ReportXmlParseError()
+{
+ XML_Parser parser = static_cast<XML_Parser>(this->Parser);
+ this->ReportError(XML_GetCurrentLineNumber(parser),
+ XML_GetCurrentColumnNumber(parser),
+ XML_ErrorString(XML_GetErrorCode(parser)));
+}
+
+//----------------------------------------------------------------------------
+void cmXMLParser::ReportError(int line, int, const char* msg)
+{
+ if(this->ReportCallback)
+ {
+ this->ReportCallback(line, msg, this->ReportCallbackData);
+ }
+ else
+ {
+ std::cerr << "Error parsing XML in stream at line "
+ << line << ": " << msg << std::endl;
+ }
+}
diff --git a/Source/cmXMLParser.h b/Source/cmXMLParser.h
new file mode 100644
index 0000000000..e72da66b33
--- /dev/null
+++ b/Source/cmXMLParser.h
@@ -0,0 +1,119 @@
+/*============================================================================
+ 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 cmXMLParser_h
+#define cmXMLParser_h
+
+#include "cmStandardIncludes.h"
+
+extern "C"
+{
+ void cmXMLParserStartElement(void*, const char*, const char**);
+ void cmXMLParserEndElement(void*, const char*);
+ void cmXMLParserCharacterDataHandler(void*, const char*, int);
+}
+
+/** \class cmXMLParser
+ * \brief Helper class for performing XML parsing
+ *
+ * Superclass for all XML parsers.
+ */
+class cmXMLParser
+{
+public:
+ cmXMLParser();
+ virtual ~cmXMLParser();
+
+ //! Parse given XML string
+ virtual int Parse(const char* string);
+
+ //! Parse given XML file
+ virtual int ParseFile(const char* file);
+
+ /**
+ * When parsing fragments of XML or streaming XML, use the following
+ * three methods. InitializeParser method initialize parser but does
+ * not perform any actual parsing. ParseChunk parses framgent of
+ * XML. This has to match to what was already parsed. CleanupParser
+ * finishes parsing. If there were errors, CleanupParser will report
+ * them.
+ */
+ virtual int InitializeParser();
+ virtual int ParseChunk(const char* inputString,
+ std::string::size_type length);
+ virtual int CleanupParser();
+ typedef void (*ReportFunction)(int, const char*, void*);
+ void SetErrorCallback(ReportFunction f, void* d)
+ {
+ this->ReportCallback = f;
+ this->ReportCallbackData = d;
+ }
+protected:
+ //! This variable is true if there was a parse error while parsing in
+ //chunks.
+ int ParseError;
+ ReportFunction ReportCallback;
+ void* ReportCallbackData;
+
+ //1 Expat parser structure. Exists only during call to Parse().
+ void* Parser;
+
+ /**
+ * Called before each block of input is read from the stream to check if
+ * parsing is complete. Can be replaced by subclasses to change the
+ * terminating condition for parsing. Parsing always stops when the end of
+ * file is reached in the stream.
+ */
+
+ virtual int ParsingComplete();
+
+ /**
+ * Called when a new element is opened in the XML source. Should be
+ * replaced by subclasses to handle each element. name = Name of new
+ * element. atts = Null-terminated array of attribute name/value pairs.
+ * Even indices are attribute names, and odd indices are values.
+ */
+ virtual void StartElement(const std::string& name, const char** atts);
+
+ //! Called at the end of an element in the XML source opened when
+ //StartElement was called.
+ virtual void EndElement(const std::string& name);
+
+ //! Called when there is character data to handle.
+ virtual void CharacterDataHandler(const char* data, int length);
+
+ //! Called by Parse to report an XML syntax error.
+ virtual void ReportXmlParseError();
+
+ /** Called by ReportXmlParseError with basic error info. */
+ virtual void ReportError(int line, int column, const char* msg);
+
+ //! Utility for convenience of subclasses. Wraps isspace C library
+ // routine.
+ static int IsSpace(char c);
+
+ //! Send the given buffer to the XML parser.
+ virtual int ParseBuffer(const char* buffer,
+ std::string::size_type length);
+
+ //! Send the given c-style string to the XML parser.
+ int ParseBuffer(const char* buffer);
+
+ /** Helps subclasses search for attributes on elements. */
+ static const char* FindAttribute(const char** atts, const char* attribute);
+
+ //! Callbacks for the expat
+ friend void cmXMLParserStartElement(void*, const char*, const char**);
+ friend void cmXMLParserEndElement(void*, const char*);
+ friend void cmXMLParserCharacterDataHandler(void*, const char*, int);
+};
+
+#endif
diff --git a/Source/cmXMLSafe.cxx b/Source/cmXMLSafe.cxx
new file mode 100644
index 0000000000..72fdc3466b
--- /dev/null
+++ b/Source/cmXMLSafe.cxx
@@ -0,0 +1,102 @@
+/*============================================================================
+ 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 "cmXMLSafe.h"
+
+#include "cm_utf8.h"
+
+#include <cmsys/ios/iostream>
+#include <cmsys/ios/sstream>
+
+#include <string.h>
+#include <stdio.h>
+
+//----------------------------------------------------------------------------
+cmXMLSafe::cmXMLSafe(const char* s):
+ Data(s),
+ Size(static_cast<unsigned long>(strlen(s))),
+ DoQuotes(true)
+{
+}
+
+//----------------------------------------------------------------------------
+cmXMLSafe::cmXMLSafe(cmsys_stl::string const& s):
+ Data(s.c_str()),
+ Size(static_cast<unsigned long>(s.length())),
+ DoQuotes(true)
+{
+}
+
+//----------------------------------------------------------------------------
+cmXMLSafe& cmXMLSafe::Quotes(bool b)
+{
+ this->DoQuotes = b;
+ return *this;
+}
+
+//----------------------------------------------------------------------------
+cmsys_stl::string cmXMLSafe::str()
+{
+ cmsys_ios::ostringstream ss;
+ ss << *this;
+ return ss.str();
+}
+
+//----------------------------------------------------------------------------
+cmsys_ios::ostream& operator<<(cmsys_ios::ostream& os, cmXMLSafe const& self)
+{
+ char const* first = self.Data;
+ char const* last = self.Data + self.Size;
+ while(first != last)
+ {
+ unsigned int ch;
+ if(const char* next = cm_utf8_decode_character(first, last, &ch))
+ {
+ // http://www.w3.org/TR/REC-xml/#NT-Char
+ if((ch >= 0x20 && ch <= 0xD7FF) ||
+ (ch >= 0xE000 && ch <= 0xFFFD) ||
+ (ch >= 0x10000 && ch <= 0x10FFFF) ||
+ ch == 0x9 || ch == 0xA || ch == 0xD)
+ {
+ switch(ch)
+ {
+ // Escape XML control characters.
+ case '&': os << "&amp;"; break;
+ case '<': os << "&lt;"; break;
+ case '>': os << "&gt;"; break;
+ case '"': os << (self.DoQuotes? "&quot;" : "\""); break;
+ case '\'': os << (self.DoQuotes? "&apos;" : "'"); break;
+ case '\r': break; // Ignore CR
+ // Print the UTF-8 character.
+ default: os.write(first, next-first); break;
+ }
+ }
+ else
+ {
+ // Use a human-readable hex value for this invalid character.
+ char buf[16];
+ sprintf(buf, "%X", ch);
+ os << "[NON-XML-CHAR-0x" << buf << "]";
+ }
+
+ first = next;
+ }
+ else
+ {
+ ch = static_cast<unsigned char>(*first++);
+ // Use a human-readable hex value for this invalid byte.
+ char buf[16];
+ sprintf(buf, "%X", ch);
+ os << "[NON-UTF-8-BYTE-0x" << buf << "]";
+ }
+ }
+ return os;
+}
diff --git a/Source/cmXMLSafe.h b/Source/cmXMLSafe.h
new file mode 100644
index 0000000000..cba9f390d9
--- /dev/null
+++ b/Source/cmXMLSafe.h
@@ -0,0 +1,44 @@
+/*============================================================================
+ 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 cmXMLSafe_h
+#define cmXMLSafe_h
+
+#include <cmsys/stl/string>
+#include <cmsys/ios/iosfwd>
+
+/** \class cmXMLSafe
+ * \brief Write strings to XML with proper escapes
+ */
+class cmXMLSafe
+{
+public:
+ /** Construct with the data to be written. This assumes the data
+ will exist for the duration of this object's life. */
+ cmXMLSafe(const char* s);
+ cmXMLSafe(cmsys_stl::string const& s);
+
+ /** Specify whether to escape quotes too. This is needed when
+ writing the content of an attribute value. By default quotes
+ are escaped. */
+ cmXMLSafe& Quotes(bool b = true);
+
+ /** Get the escaped data as a string. */
+ cmsys_stl::string str();
+private:
+ char const* Data;
+ unsigned long Size;
+ bool DoQuotes;
+ friend cmsys_ios::ostream& operator<<(cmsys_ios::ostream&,
+ cmXMLSafe const&);
+};
+
+#endif
diff --git a/Source/cm_sha2.c b/Source/cm_sha2.c
new file mode 100644
index 0000000000..24de2b2940
--- /dev/null
+++ b/Source/cm_sha2.c
@@ -0,0 +1,1617 @@
+/*
+ * FILE: sha2.c
+ * AUTHOR: Aaron D. Gifford
+ * http://www.aarongifford.com/computers/sha.html
+ *
+ * Copyright (c) 2000-2003, Aaron D. Gifford
+ * 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.
+ * 3. Neither the name of the copyright holder nor the names of contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(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 OR CONTRIBUTOR(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.
+ *
+ * $Id: sha2.c,v 1.4 2004/01/07 22:58:18 adg Exp $
+ */
+
+#include <string.h> /* memcpy()/memset() or bcopy()/bzero() */
+#include <assert.h> /* assert() */
+#include "cm_sha2.h" /* "sha2.h" -> "cm_sha2.h" renamed for CMake */
+
+/*
+ * ASSERT NOTE:
+ * Some sanity checking code is included using assert(). On my FreeBSD
+ * system, this additional code can be removed by compiling with NDEBUG
+ * defined. Check your own systems manpage on assert() to see how to
+ * compile WITHOUT the sanity checking code on your system.
+ *
+ * UNROLLED TRANSFORM LOOP NOTE:
+ * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
+ * loop version for the hash transform rounds (defined using macros
+ * later in this file). Either define on the command line, for example:
+ *
+ * cc -DSHA2_UNROLL_TRANSFORM -o sha2 sha2.c sha2prog.c
+ *
+ * or define below:
+ *
+ * #define SHA2_UNROLL_TRANSFORM
+ *
+ */
+
+
+/*** SHA-224/256/384/512 Machine Architecture Definitions *************/
+/*
+ * BYTE_ORDER NOTE:
+ *
+ * Please make sure that your system defines BYTE_ORDER. If your
+ * architecture is little-endian, make sure it also defines
+ * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
+ * equivilent.
+ *
+ * If your system does not define the above, then you can do so by
+ * hand like this:
+ *
+ * #define LITTLE_ENDIAN 1234
+ * #define BIG_ENDIAN 4321
+ *
+ * And for little-endian machines, add:
+ *
+ * #define BYTE_ORDER LITTLE_ENDIAN
+ *
+ * Or for big-endian machines:
+ *
+ * #define BYTE_ORDER BIG_ENDIAN
+ *
+ * The FreeBSD machine this was written on defines BYTE_ORDER
+ * appropriately by including <sys/types.h> (which in turn includes
+ * <machine/endian.h> where the appropriate definitions are actually
+ * made).
+ */
+#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
+/* CMake modification: use byte order from cmIML. */
+# include "cmIML/ABI.h"
+# 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
+#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)
+#if defined(__BORLANDC__)
+# pragma warn -8004 /* variable assigned value that is never used */
+#endif
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+
+/*** ENDIAN REVERSAL MACROS *******************************************/
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define REVERSE32(w,x) { \
+ sha_word32 tmp = (w); \
+ tmp = (tmp >> 16) | (tmp << 16); \
+ (x) = ((tmp & SHA_UINT32_C(0xff00ff00)) >> 8) | \
+ ((tmp & SHA_UINT32_C(0x00ff00ff)) << 8); \
+}
+#define REVERSE64(w,x) { \
+ sha_word64 tmp = (w); \
+ tmp = (tmp >> 32) | (tmp << 32); \
+ tmp = ((tmp & SHA_UINT64_C(0xff00ff00ff00ff00)) >> 8) | \
+ ((tmp & SHA_UINT64_C(0x00ff00ff00ff00ff)) << 8); \
+ (x) = ((tmp & SHA_UINT64_C(0xffff0000ffff0000)) >> 16) | \
+ ((tmp & SHA_UINT64_C(0x0000ffff0000ffff)) << 16); \
+}
+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+
+/*
+ * Macro for incrementally adding the unsigned 64-bit integer n to the
+ * unsigned 128-bit integer (represented using a two-element array of
+ * 64-bit words):
+ */
+#define ADDINC128(w,n) { \
+ (w)[0] += (sha_word64)(n); \
+ if ((w)[0] < (n)) { \
+ (w)[1]++; \
+ } \
+}
+
+/*
+ * Macros for copying blocks of memory and for zeroing out ranges
+ * of memory. Using these macros makes it easy to switch from
+ * using memset()/memcpy() and using bzero()/bcopy().
+ *
+ * Please define either SHA2_USE_MEMSET_MEMCPY or define
+ * SHA2_USE_BZERO_BCOPY depending on which function set you
+ * choose to use:
+ */
+#if !defined(SHA2_USE_MEMSET_MEMCPY) && !defined(SHA2_USE_BZERO_BCOPY)
+/* Default to memset()/memcpy() if no option is specified */
+#define SHA2_USE_MEMSET_MEMCPY 1
+#endif
+#if defined(SHA2_USE_MEMSET_MEMCPY) && defined(SHA2_USE_BZERO_BCOPY)
+/* Abort with an error if BOTH options are defined */
+#error Define either SHA2_USE_MEMSET_MEMCPY or SHA2_USE_BZERO_BCOPY, not both!
+#endif
+
+#ifdef SHA2_USE_MEMSET_MEMCPY
+#define MEMSET_BZERO(p,l) memset((p), 0, (l))
+#define MEMCPY_BCOPY(d,s,l) memcpy((d), (s), (l))
+#endif
+#ifdef SHA2_USE_BZERO_BCOPY
+#define MEMSET_BZERO(p,l) bzero((p), (l))
+#define MEMCPY_BCOPY(d,s,l) bcopy((s), (d), (l))
+#endif
+
+
+/*** THE SIX LOGICAL FUNCTIONS ****************************************/
+/*
+ * Bit shifting and rotation (used by the six SHA-XYZ logical functions:
+ *
+ * NOTE: In the original SHA-256/384/512 document, the shift-right
+ * function was named R and the rotate-right function was called S.
+ * (See: http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf on the
+ * web.)
+ *
+ * The newer NIST FIPS 180-2 document uses a much clearer naming
+ * scheme, SHR for shift-right, ROTR for rotate-right, and ROTL for
+ * rotate-left. (See:
+ * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+ * on the web.)
+ *
+ * WARNING: These macros must be used cautiously, since they reference
+ * supplied parameters sometimes more than once, and thus could have
+ * unexpected side-effects if used without taking this into account.
+ */
+/* Shift-right (used in SHA-256, SHA-384, and SHA-512): */
+#define SHR(b,x) ((x) >> (b))
+/* 32-bit Rotate-right (used in SHA-256): */
+#define ROTR32(b,x) (((x) >> (b)) | ((x) << (32 - (b))))
+/* 64-bit Rotate-right (used in SHA-384 and SHA-512): */
+#define ROTR64(b,x) (((x) >> (b)) | ((x) << (64 - (b))))
+/* 32-bit Rotate-left (used in SHA-1): */
+#define ROTL32(b,x) (((x) << (b)) | ((x) >> (32 - (b))))
+
+/* Two logical functions used in SHA-1, SHA-254, SHA-256, SHA-384, and SHA-512: */
+#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
+#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+
+/* Function used in SHA-1: */
+#define Parity(x,y,z) ((x) ^ (y) ^ (z))
+
+/* Four logical functions used in SHA-256: */
+#define Sigma0_256(x) (ROTR32(2, (x)) ^ ROTR32(13, (x)) ^ ROTR32(22, (x)))
+#define Sigma1_256(x) (ROTR32(6, (x)) ^ ROTR32(11, (x)) ^ ROTR32(25, (x)))
+#define sigma0_256(x) (ROTR32(7, (x)) ^ ROTR32(18, (x)) ^ SHR( 3 , (x)))
+#define sigma1_256(x) (ROTR32(17, (x)) ^ ROTR32(19, (x)) ^ SHR( 10, (x)))
+
+/* Four of six logical functions used in SHA-384 and SHA-512: */
+#define Sigma0_512(x) (ROTR64(28, (x)) ^ ROTR64(34, (x)) ^ ROTR64(39, (x)))
+#define Sigma1_512(x) (ROTR64(14, (x)) ^ ROTR64(18, (x)) ^ ROTR64(41, (x)))
+#define sigma0_512(x) (ROTR64( 1, (x)) ^ ROTR64( 8, (x)) ^ SHR( 7, (x)))
+#define sigma1_512(x) (ROTR64(19, (x)) ^ ROTR64(61, (x)) ^ SHR( 6, (x)))
+
+/*** INTERNAL FUNCTION PROTOTYPES *************************************/
+
+/* SHA-224 and SHA-256: */
+void SHA256_Internal_Init(SHA_CTX*, const sha_word32*);
+void SHA256_Internal_Last(SHA_CTX*);
+void SHA256_Internal_Transform(SHA_CTX*, const sha_word32*);
+
+/* SHA-384 and SHA-512: */
+void SHA512_Internal_Init(SHA_CTX*, const sha_word64*);
+void SHA512_Internal_Last(SHA_CTX*);
+void SHA512_Internal_Transform(SHA_CTX*, const sha_word64*);
+
+
+/*** SHA2 INITIAL HASH VALUES AND CONSTANTS ***************************/
+
+/* Hash constant words K for SHA-1: */
+#define K1_0_TO_19 SHA_UINT32_C(0x5a827999)
+#define K1_20_TO_39 SHA_UINT32_C(0x6ed9eba1)
+#define K1_40_TO_59 SHA_UINT32_C(0x8f1bbcdc)
+#define K1_60_TO_79 SHA_UINT32_C(0xca62c1d6)
+
+/* Initial hash value H for SHA-1: */
+static const sha_word32 sha1_initial_hash_value[5] = {
+ SHA_UINT32_C(0x67452301),
+ SHA_UINT32_C(0xefcdab89),
+ SHA_UINT32_C(0x98badcfe),
+ SHA_UINT32_C(0x10325476),
+ SHA_UINT32_C(0xc3d2e1f0)
+};
+
+/* Hash constant words K for SHA-224 and SHA-256: */
+static const sha_word32 K256[64] = {
+ SHA_UINT32_C(0x428a2f98), SHA_UINT32_C(0x71374491),
+ SHA_UINT32_C(0xb5c0fbcf), SHA_UINT32_C(0xe9b5dba5),
+ SHA_UINT32_C(0x3956c25b), SHA_UINT32_C(0x59f111f1),
+ SHA_UINT32_C(0x923f82a4), SHA_UINT32_C(0xab1c5ed5),
+ SHA_UINT32_C(0xd807aa98), SHA_UINT32_C(0x12835b01),
+ SHA_UINT32_C(0x243185be), SHA_UINT32_C(0x550c7dc3),
+ SHA_UINT32_C(0x72be5d74), SHA_UINT32_C(0x80deb1fe),
+ SHA_UINT32_C(0x9bdc06a7), SHA_UINT32_C(0xc19bf174),
+ SHA_UINT32_C(0xe49b69c1), SHA_UINT32_C(0xefbe4786),
+ SHA_UINT32_C(0x0fc19dc6), SHA_UINT32_C(0x240ca1cc),
+ SHA_UINT32_C(0x2de92c6f), SHA_UINT32_C(0x4a7484aa),
+ SHA_UINT32_C(0x5cb0a9dc), SHA_UINT32_C(0x76f988da),
+ SHA_UINT32_C(0x983e5152), SHA_UINT32_C(0xa831c66d),
+ SHA_UINT32_C(0xb00327c8), SHA_UINT32_C(0xbf597fc7),
+ SHA_UINT32_C(0xc6e00bf3), SHA_UINT32_C(0xd5a79147),
+ SHA_UINT32_C(0x06ca6351), SHA_UINT32_C(0x14292967),
+ SHA_UINT32_C(0x27b70a85), SHA_UINT32_C(0x2e1b2138),
+ SHA_UINT32_C(0x4d2c6dfc), SHA_UINT32_C(0x53380d13),
+ SHA_UINT32_C(0x650a7354), SHA_UINT32_C(0x766a0abb),
+ SHA_UINT32_C(0x81c2c92e), SHA_UINT32_C(0x92722c85),
+ SHA_UINT32_C(0xa2bfe8a1), SHA_UINT32_C(0xa81a664b),
+ SHA_UINT32_C(0xc24b8b70), SHA_UINT32_C(0xc76c51a3),
+ SHA_UINT32_C(0xd192e819), SHA_UINT32_C(0xd6990624),
+ SHA_UINT32_C(0xf40e3585), SHA_UINT32_C(0x106aa070),
+ SHA_UINT32_C(0x19a4c116), SHA_UINT32_C(0x1e376c08),
+ SHA_UINT32_C(0x2748774c), SHA_UINT32_C(0x34b0bcb5),
+ SHA_UINT32_C(0x391c0cb3), SHA_UINT32_C(0x4ed8aa4a),
+ SHA_UINT32_C(0x5b9cca4f), SHA_UINT32_C(0x682e6ff3),
+ SHA_UINT32_C(0x748f82ee), SHA_UINT32_C(0x78a5636f),
+ SHA_UINT32_C(0x84c87814), SHA_UINT32_C(0x8cc70208),
+ SHA_UINT32_C(0x90befffa), SHA_UINT32_C(0xa4506ceb),
+ SHA_UINT32_C(0xbef9a3f7), SHA_UINT32_C(0xc67178f2)
+};
+
+/* Initial hash value H for SHA-224: */
+static const sha_word32 sha224_initial_hash_value[8] = {
+ SHA_UINT32_C(0xc1059ed8),
+ SHA_UINT32_C(0x367cd507),
+ SHA_UINT32_C(0x3070dd17),
+ SHA_UINT32_C(0xf70e5939),
+ SHA_UINT32_C(0xffc00b31),
+ SHA_UINT32_C(0x68581511),
+ SHA_UINT32_C(0x64f98fa7),
+ SHA_UINT32_C(0xbefa4fa4)
+};
+
+/* Initial hash value H for SHA-256: */
+static const sha_word32 sha256_initial_hash_value[8] = {
+ SHA_UINT32_C(0x6a09e667),
+ SHA_UINT32_C(0xbb67ae85),
+ SHA_UINT32_C(0x3c6ef372),
+ SHA_UINT32_C(0xa54ff53a),
+ SHA_UINT32_C(0x510e527f),
+ SHA_UINT32_C(0x9b05688c),
+ SHA_UINT32_C(0x1f83d9ab),
+ SHA_UINT32_C(0x5be0cd19)
+};
+
+/* Hash constant words K for SHA-384 and SHA-512: */
+static const sha_word64 K512[80] = {
+ SHA_UINT64_C(0x428a2f98d728ae22), SHA_UINT64_C(0x7137449123ef65cd),
+ SHA_UINT64_C(0xb5c0fbcfec4d3b2f), SHA_UINT64_C(0xe9b5dba58189dbbc),
+ SHA_UINT64_C(0x3956c25bf348b538), SHA_UINT64_C(0x59f111f1b605d019),
+ SHA_UINT64_C(0x923f82a4af194f9b), SHA_UINT64_C(0xab1c5ed5da6d8118),
+ SHA_UINT64_C(0xd807aa98a3030242), SHA_UINT64_C(0x12835b0145706fbe),
+ SHA_UINT64_C(0x243185be4ee4b28c), SHA_UINT64_C(0x550c7dc3d5ffb4e2),
+ SHA_UINT64_C(0x72be5d74f27b896f), SHA_UINT64_C(0x80deb1fe3b1696b1),
+ SHA_UINT64_C(0x9bdc06a725c71235), SHA_UINT64_C(0xc19bf174cf692694),
+ SHA_UINT64_C(0xe49b69c19ef14ad2), SHA_UINT64_C(0xefbe4786384f25e3),
+ SHA_UINT64_C(0x0fc19dc68b8cd5b5), SHA_UINT64_C(0x240ca1cc77ac9c65),
+ SHA_UINT64_C(0x2de92c6f592b0275), SHA_UINT64_C(0x4a7484aa6ea6e483),
+ SHA_UINT64_C(0x5cb0a9dcbd41fbd4), SHA_UINT64_C(0x76f988da831153b5),
+ SHA_UINT64_C(0x983e5152ee66dfab), SHA_UINT64_C(0xa831c66d2db43210),
+ SHA_UINT64_C(0xb00327c898fb213f), SHA_UINT64_C(0xbf597fc7beef0ee4),
+ SHA_UINT64_C(0xc6e00bf33da88fc2), SHA_UINT64_C(0xd5a79147930aa725),
+ SHA_UINT64_C(0x06ca6351e003826f), SHA_UINT64_C(0x142929670a0e6e70),
+ SHA_UINT64_C(0x27b70a8546d22ffc), SHA_UINT64_C(0x2e1b21385c26c926),
+ SHA_UINT64_C(0x4d2c6dfc5ac42aed), SHA_UINT64_C(0x53380d139d95b3df),
+ SHA_UINT64_C(0x650a73548baf63de), SHA_UINT64_C(0x766a0abb3c77b2a8),
+ SHA_UINT64_C(0x81c2c92e47edaee6), SHA_UINT64_C(0x92722c851482353b),
+ SHA_UINT64_C(0xa2bfe8a14cf10364), SHA_UINT64_C(0xa81a664bbc423001),
+ SHA_UINT64_C(0xc24b8b70d0f89791), SHA_UINT64_C(0xc76c51a30654be30),
+ SHA_UINT64_C(0xd192e819d6ef5218), SHA_UINT64_C(0xd69906245565a910),
+ SHA_UINT64_C(0xf40e35855771202a), SHA_UINT64_C(0x106aa07032bbd1b8),
+ SHA_UINT64_C(0x19a4c116b8d2d0c8), SHA_UINT64_C(0x1e376c085141ab53),
+ SHA_UINT64_C(0x2748774cdf8eeb99), SHA_UINT64_C(0x34b0bcb5e19b48a8),
+ SHA_UINT64_C(0x391c0cb3c5c95a63), SHA_UINT64_C(0x4ed8aa4ae3418acb),
+ SHA_UINT64_C(0x5b9cca4f7763e373), SHA_UINT64_C(0x682e6ff3d6b2b8a3),
+ SHA_UINT64_C(0x748f82ee5defb2fc), SHA_UINT64_C(0x78a5636f43172f60),
+ SHA_UINT64_C(0x84c87814a1f0ab72), SHA_UINT64_C(0x8cc702081a6439ec),
+ SHA_UINT64_C(0x90befffa23631e28), SHA_UINT64_C(0xa4506cebde82bde9),
+ SHA_UINT64_C(0xbef9a3f7b2c67915), SHA_UINT64_C(0xc67178f2e372532b),
+ SHA_UINT64_C(0xca273eceea26619c), SHA_UINT64_C(0xd186b8c721c0c207),
+ SHA_UINT64_C(0xeada7dd6cde0eb1e), SHA_UINT64_C(0xf57d4f7fee6ed178),
+ SHA_UINT64_C(0x06f067aa72176fba), SHA_UINT64_C(0x0a637dc5a2c898a6),
+ SHA_UINT64_C(0x113f9804bef90dae), SHA_UINT64_C(0x1b710b35131c471b),
+ SHA_UINT64_C(0x28db77f523047d84), SHA_UINT64_C(0x32caab7b40c72493),
+ SHA_UINT64_C(0x3c9ebe0a15c9bebc), SHA_UINT64_C(0x431d67c49c100d4c),
+ SHA_UINT64_C(0x4cc5d4becb3e42b6), SHA_UINT64_C(0x597f299cfc657e2a),
+ SHA_UINT64_C(0x5fcb6fab3ad6faec), SHA_UINT64_C(0x6c44198c4a475817)
+};
+
+/* Initial hash value H for SHA-384 */
+static const sha_word64 sha384_initial_hash_value[8] = {
+ SHA_UINT64_C(0xcbbb9d5dc1059ed8),
+ SHA_UINT64_C(0x629a292a367cd507),
+ SHA_UINT64_C(0x9159015a3070dd17),
+ SHA_UINT64_C(0x152fecd8f70e5939),
+ SHA_UINT64_C(0x67332667ffc00b31),
+ SHA_UINT64_C(0x8eb44a8768581511),
+ SHA_UINT64_C(0xdb0c2e0d64f98fa7),
+ SHA_UINT64_C(0x47b5481dbefa4fa4)
+};
+
+/* Initial hash value H for SHA-512 */
+static const sha_word64 sha512_initial_hash_value[8] = {
+ SHA_UINT64_C(0x6a09e667f3bcc908),
+ SHA_UINT64_C(0xbb67ae8584caa73b),
+ SHA_UINT64_C(0x3c6ef372fe94f82b),
+ SHA_UINT64_C(0xa54ff53a5f1d36f1),
+ SHA_UINT64_C(0x510e527fade682d1),
+ SHA_UINT64_C(0x9b05688c2b3e6c1f),
+ SHA_UINT64_C(0x1f83d9abfb41bd6b),
+ SHA_UINT64_C(0x5be0cd19137e2179)
+};
+
+/*
+ * Constant used by SHA224/256/384/512_End() functions for converting the
+ * digest to a readable hexadecimal character string:
+ */
+static const char *sha_hex_digits = "0123456789abcdef";
+
+
+/*** SHA-1: ***********************************************************/
+void SHA1_Init(SHA_CTX* context) {
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ MEMCPY_BCOPY(context->s1.state, sha1_initial_hash_value, sizeof(sha_word32) * 5);
+ MEMSET_BZERO(context->s1.buffer, 64);
+ context->s1.bitcount = 0;
+}
+
+#ifdef SHA2_UNROLL_TRANSFORM
+
+/* Unrolled SHA-1 round macros: */
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+
+#define ROUND1_0_TO_15(a,b,c,d,e) \
+ REVERSE32(*data++, W1[j]); \
+ (e) = ROTL32(5, (a)) + Ch((b), (c), (d)) + (e) + \
+ K1_0_TO_19 + W1[j]; \
+ (b) = ROTL32(30, (b)); \
+ j++;
+
+#else /* BYTE_ORDER == LITTLE_ENDIAN */
+
+#define ROUND1_0_TO_15(a,b,c,d,e) \
+ (e) = ROTL32(5, (a)) + Ch((b), (c), (d)) + (e) + \
+ K1_0_TO_19 + ( W1[j] = *data++ ); \
+ (b) = ROTL32(30, (b)); \
+ j++;
+
+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+
+#define ROUND1_16_TO_19(a,b,c,d,e) \
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f]; \
+ (e) = ROTL32(5, a) + Ch(b,c,d) + e + K1_0_TO_19 + ( W1[j&0x0f] = ROTL32(1, T1) ); \
+ (b) = ROTL32(30, b); \
+ j++;
+
+#define ROUND1_20_TO_39(a,b,c,d,e) \
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f]; \
+ (e) = ROTL32(5, a) + Parity(b,c,d) + e + K1_20_TO_39 + ( W1[j&0x0f] = ROTL32(1, T1) ); \
+ (b) = ROTL32(30, b); \
+ j++;
+
+#define ROUND1_40_TO_59(a,b,c,d,e) \
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f]; \
+ (e) = ROTL32(5, a) + Maj(b,c,d) + e + K1_40_TO_59 + ( W1[j&0x0f] = ROTL32(1, T1) ); \
+ (b) = ROTL32(30, b); \
+ j++;
+
+#define ROUND1_60_TO_79(a,b,c,d,e) \
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f]; \
+ (e) = ROTL32(5, a) + Parity(b,c,d) + e + K1_60_TO_79 + ( W1[j&0x0f] = ROTL32(1, T1) ); \
+ (b) = ROTL32(30, b); \
+ j++;
+
+void SHA1_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
+ sha_word32 a, b, c, d, e;
+ sha_word32 T1, *W1;
+ int j;
+
+ W1 = (sha_word32*)context->s1.buffer;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->s1.state[0];
+ b = context->s1.state[1];
+ c = context->s1.state[2];
+ d = context->s1.state[3];
+ e = context->s1.state[4];
+
+ j = 0;
+
+ /* Rounds 0 to 15 unrolled: */
+ ROUND1_0_TO_15(a,b,c,d,e);
+ ROUND1_0_TO_15(e,a,b,c,d);
+ ROUND1_0_TO_15(d,e,a,b,c);
+ ROUND1_0_TO_15(c,d,e,a,b);
+ ROUND1_0_TO_15(b,c,d,e,a);
+ ROUND1_0_TO_15(a,b,c,d,e);
+ ROUND1_0_TO_15(e,a,b,c,d);
+ ROUND1_0_TO_15(d,e,a,b,c);
+ ROUND1_0_TO_15(c,d,e,a,b);
+ ROUND1_0_TO_15(b,c,d,e,a);
+ ROUND1_0_TO_15(a,b,c,d,e);
+ ROUND1_0_TO_15(e,a,b,c,d);
+ ROUND1_0_TO_15(d,e,a,b,c);
+ ROUND1_0_TO_15(c,d,e,a,b);
+ ROUND1_0_TO_15(b,c,d,e,a);
+ ROUND1_0_TO_15(a,b,c,d,e);
+
+ /* Rounds 16 to 19 unrolled: */
+ ROUND1_16_TO_19(e,a,b,c,d);
+ ROUND1_16_TO_19(d,e,a,b,c);
+ ROUND1_16_TO_19(c,d,e,a,b);
+ ROUND1_16_TO_19(b,c,d,e,a);
+
+ /* Rounds 20 to 39 unrolled: */
+ ROUND1_20_TO_39(a,b,c,d,e);
+ ROUND1_20_TO_39(e,a,b,c,d);
+ ROUND1_20_TO_39(d,e,a,b,c);
+ ROUND1_20_TO_39(c,d,e,a,b);
+ ROUND1_20_TO_39(b,c,d,e,a);
+ ROUND1_20_TO_39(a,b,c,d,e);
+ ROUND1_20_TO_39(e,a,b,c,d);
+ ROUND1_20_TO_39(d,e,a,b,c);
+ ROUND1_20_TO_39(c,d,e,a,b);
+ ROUND1_20_TO_39(b,c,d,e,a);
+ ROUND1_20_TO_39(a,b,c,d,e);
+ ROUND1_20_TO_39(e,a,b,c,d);
+ ROUND1_20_TO_39(d,e,a,b,c);
+ ROUND1_20_TO_39(c,d,e,a,b);
+ ROUND1_20_TO_39(b,c,d,e,a);
+ ROUND1_20_TO_39(a,b,c,d,e);
+ ROUND1_20_TO_39(e,a,b,c,d);
+ ROUND1_20_TO_39(d,e,a,b,c);
+ ROUND1_20_TO_39(c,d,e,a,b);
+ ROUND1_20_TO_39(b,c,d,e,a);
+
+ /* Rounds 40 to 59 unrolled: */
+ ROUND1_40_TO_59(a,b,c,d,e);
+ ROUND1_40_TO_59(e,a,b,c,d);
+ ROUND1_40_TO_59(d,e,a,b,c);
+ ROUND1_40_TO_59(c,d,e,a,b);
+ ROUND1_40_TO_59(b,c,d,e,a);
+ ROUND1_40_TO_59(a,b,c,d,e);
+ ROUND1_40_TO_59(e,a,b,c,d);
+ ROUND1_40_TO_59(d,e,a,b,c);
+ ROUND1_40_TO_59(c,d,e,a,b);
+ ROUND1_40_TO_59(b,c,d,e,a);
+ ROUND1_40_TO_59(a,b,c,d,e);
+ ROUND1_40_TO_59(e,a,b,c,d);
+ ROUND1_40_TO_59(d,e,a,b,c);
+ ROUND1_40_TO_59(c,d,e,a,b);
+ ROUND1_40_TO_59(b,c,d,e,a);
+ ROUND1_40_TO_59(a,b,c,d,e);
+ ROUND1_40_TO_59(e,a,b,c,d);
+ ROUND1_40_TO_59(d,e,a,b,c);
+ ROUND1_40_TO_59(c,d,e,a,b);
+ ROUND1_40_TO_59(b,c,d,e,a);
+
+ /* Rounds 60 to 79 unrolled: */
+ ROUND1_60_TO_79(a,b,c,d,e);
+ ROUND1_60_TO_79(e,a,b,c,d);
+ ROUND1_60_TO_79(d,e,a,b,c);
+ ROUND1_60_TO_79(c,d,e,a,b);
+ ROUND1_60_TO_79(b,c,d,e,a);
+ ROUND1_60_TO_79(a,b,c,d,e);
+ ROUND1_60_TO_79(e,a,b,c,d);
+ ROUND1_60_TO_79(d,e,a,b,c);
+ ROUND1_60_TO_79(c,d,e,a,b);
+ ROUND1_60_TO_79(b,c,d,e,a);
+ ROUND1_60_TO_79(a,b,c,d,e);
+ ROUND1_60_TO_79(e,a,b,c,d);
+ ROUND1_60_TO_79(d,e,a,b,c);
+ ROUND1_60_TO_79(c,d,e,a,b);
+ ROUND1_60_TO_79(b,c,d,e,a);
+ ROUND1_60_TO_79(a,b,c,d,e);
+ ROUND1_60_TO_79(e,a,b,c,d);
+ ROUND1_60_TO_79(d,e,a,b,c);
+ ROUND1_60_TO_79(c,d,e,a,b);
+ ROUND1_60_TO_79(b,c,d,e,a);
+
+ /* Compute the current intermediate hash value */
+ context->s1.state[0] += a;
+ context->s1.state[1] += b;
+ context->s1.state[2] += c;
+ context->s1.state[3] += d;
+ context->s1.state[4] += e;
+
+ /* Clean up */
+ a = b = c = d = e = T1 = 0;
+}
+
+#else /* SHA2_UNROLL_TRANSFORM */
+
+void SHA1_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
+ sha_word32 a, b, c, d, e;
+ sha_word32 T1, *W1;
+ int j;
+
+ W1 = (sha_word32*)context->s1.buffer;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->s1.state[0];
+ b = context->s1.state[1];
+ c = context->s1.state[2];
+ d = context->s1.state[3];
+ e = context->s1.state[4];
+ j = 0;
+ do {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ T1 = data[j];
+ /* Copy data while converting to host byte order */
+ REVERSE32(*data++, W1[j]);
+ T1 = ROTL32(5, a) + Ch(b, c, d) + e + K1_0_TO_19 + W1[j];
+#else /* BYTE_ORDER == LITTLE_ENDIAN */
+ T1 = ROTL32(5, a) + Ch(b, c, d) + e + K1_0_TO_19 + (W1[j] = *data++);
+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 16);
+
+ do {
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
+ T1 = ROTL32(5, a) + Ch(b,c,d) + e + K1_0_TO_19 + (W1[j&0x0f] = ROTL32(1, T1));
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 20);
+
+ do {
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
+ T1 = ROTL32(5, a) + Parity(b,c,d) + e + K1_20_TO_39 + (W1[j&0x0f] = ROTL32(1, T1));
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 40);
+
+ do {
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
+ T1 = ROTL32(5, a) + Maj(b,c,d) + e + K1_40_TO_59 + (W1[j&0x0f] = ROTL32(1, T1));
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 60);
+
+ do {
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
+ T1 = ROTL32(5, a) + Parity(b,c,d) + e + K1_60_TO_79 + (W1[j&0x0f] = ROTL32(1, T1));
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 80);
+
+
+ /* Compute the current intermediate hash value */
+ context->s1.state[0] += a;
+ context->s1.state[1] += b;
+ context->s1.state[2] += c;
+ context->s1.state[3] += d;
+ context->s1.state[4] += e;
+
+ /* Clean up */
+ a = b = c = d = e = T1 = 0;
+}
+
+#endif /* SHA2_UNROLL_TRANSFORM */
+
+void SHA1_Update(SHA_CTX* context, const sha_byte *data, size_t len) {
+ unsigned int freespace, usedspace;
+ if (len == 0) {
+ /* Calling with no data is valid - we do nothing */
+ return;
+ }
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0 && data != (sha_byte*)0);
+
+ usedspace = (unsigned int)((context->s1.bitcount >> 3) % 64);
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = 64 - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ MEMCPY_BCOPY(&context->s1.buffer[usedspace], data, freespace);
+ context->s1.bitcount += freespace << 3;
+ len -= freespace;
+ data += freespace;
+ SHA1_Internal_Transform(context, (sha_word32*)context->s1.buffer);
+ } else {
+ /* The buffer is not yet full */
+ MEMCPY_BCOPY(&context->s1.buffer[usedspace], data, len);
+ context->s1.bitcount += len << 3;
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+ while (len >= 64) {
+ /* Process as many complete blocks as we can */
+ SHA1_Internal_Transform(context, (sha_word32*)data);
+ context->s1.bitcount += 512;
+ len -= 64;
+ data += 64;
+ }
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ MEMCPY_BCOPY(context->s1.buffer, data, len);
+ context->s1.bitcount += len << 3;
+ }
+ /* Clean up: */
+ usedspace = freespace = 0;
+}
+
+void SHA1_Final(sha_byte digest[], SHA_CTX* context) {
+ sha_word32 *d = (sha_word32*)digest;
+ unsigned int usedspace;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ if (digest == (sha_byte*)0) {
+ /*
+ * No digest buffer, so we can do nothing
+ * except clean up and go home
+ */
+ MEMSET_BZERO(context, sizeof(*context));
+ return;
+ }
+
+ usedspace = (unsigned int)((context->s1.bitcount >> 3) % 64);
+ if (usedspace == 0) {
+ /* Set-up for the last transform: */
+ MEMSET_BZERO(context->s1.buffer, 56);
+
+ /* Begin padding with a 1 bit: */
+ *context->s1.buffer = 0x80;
+ } else {
+ /* Begin padding with a 1 bit: */
+ context->s1.buffer[usedspace++] = 0x80;
+
+ if (usedspace <= 56) {
+ /* Set-up for the last transform: */
+ MEMSET_BZERO(&context->s1.buffer[usedspace], 56 - usedspace);
+ } else {
+ if (usedspace < 64) {
+ MEMSET_BZERO(&context->s1.buffer[usedspace], 64 - usedspace);
+ }
+ /* Do second-to-last transform: */
+ SHA1_Internal_Transform(context, (sha_word32*)context->s1.buffer);
+
+ /* And set-up for the last transform: */
+ MEMSET_BZERO(context->s1.buffer, 56);
+ }
+ /* Clean up: */
+ usedspace = 0;
+ }
+ /* Set the bit count: */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert FROM host byte order */
+ REVERSE64(context->s1.bitcount,context->s1.bitcount);
+#endif
+ MEMCPY_BCOPY(&context->s1.buffer[56], &context->s1.bitcount,
+ sizeof(sha_word64));
+
+ /* Final transform: */
+ SHA1_Internal_Transform(context, (sha_word32*)context->s1.buffer);
+
+ /* Save the hash data for output: */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ {
+ /* Convert TO host byte order */
+ int j;
+ for (j = 0; j < (SHA1_DIGEST_LENGTH >> 2); j++) {
+ REVERSE32(context->s1.state[j],context->s1.state[j]);
+ *d++ = context->s1.state[j];
+ }
+ }
+#else
+ MEMCPY_BCOPY(d, context->s1.state, SHA1_DIGEST_LENGTH);
+#endif
+
+ /* Clean up: */
+ MEMSET_BZERO(context, sizeof(*context));
+}
+
+char *SHA1_End(SHA_CTX* context, char buffer[]) {
+ sha_byte digest[SHA1_DIGEST_LENGTH], *d = digest;
+ int i;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ if (buffer != (char*)0) {
+ SHA1_Final(digest, context);
+
+ for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+ *buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha_hex_digits[*d & 0x0f];
+ d++;
+ }
+ *buffer = (char)0;
+ } else {
+ MEMSET_BZERO(context, sizeof(*context));
+ }
+ MEMSET_BZERO(digest, SHA1_DIGEST_LENGTH);
+ return buffer;
+}
+
+char* SHA1_Data(const sha_byte* data, size_t len, char digest[SHA1_DIGEST_STRING_LENGTH]) {
+ SHA_CTX context;
+
+ SHA1_Init(&context);
+ SHA1_Update(&context, data, len);
+ return SHA1_End(&context, digest);
+}
+
+
+/*** SHA-256: *********************************************************/
+void SHA256_Internal_Init(SHA_CTX* context, const sha_word32* ihv) {
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ MEMCPY_BCOPY(context->s256.state, ihv, sizeof(sha_word32) * 8);
+ MEMSET_BZERO(context->s256.buffer, 64);
+ context->s256.bitcount = 0;
+}
+
+void SHA256_Init(SHA_CTX* context) {
+ SHA256_Internal_Init(context, sha256_initial_hash_value);
+}
+
+#ifdef SHA2_UNROLL_TRANSFORM
+
+/* Unrolled SHA-256 round macros: */
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+
+#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \
+ REVERSE32(*data++, W256[j]); \
+ T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
+ K256[j] + W256[j]; \
+ (d) += T1; \
+ (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
+ j++
+
+
+#else /* BYTE_ORDER == LITTLE_ENDIAN */
+
+#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \
+ T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
+ K256[j] + (W256[j] = *data++); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
+ j++
+
+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+
+#define ROUND256(a,b,c,d,e,f,g,h) \
+ s0 = W256[(j+1)&0x0f]; \
+ s0 = sigma0_256(s0); \
+ s1 = W256[(j+14)&0x0f]; \
+ s1 = sigma1_256(s1); \
+ T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + K256[j] + \
+ (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
+ j++
+
+void SHA256_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
+ sha_word32 a, b, c, d, e, f, g, h, s0, s1;
+ sha_word32 T1, *W256;
+ int j;
+
+ W256 = (sha_word32*)context->s256.buffer;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->s256.state[0];
+ b = context->s256.state[1];
+ c = context->s256.state[2];
+ d = context->s256.state[3];
+ e = context->s256.state[4];
+ f = context->s256.state[5];
+ g = context->s256.state[6];
+ h = context->s256.state[7];
+
+ j = 0;
+ do {
+ /* Rounds 0 to 15 (unrolled): */
+ ROUND256_0_TO_15(a,b,c,d,e,f,g,h);
+ ROUND256_0_TO_15(h,a,b,c,d,e,f,g);
+ ROUND256_0_TO_15(g,h,a,b,c,d,e,f);
+ ROUND256_0_TO_15(f,g,h,a,b,c,d,e);
+ ROUND256_0_TO_15(e,f,g,h,a,b,c,d);
+ ROUND256_0_TO_15(d,e,f,g,h,a,b,c);
+ ROUND256_0_TO_15(c,d,e,f,g,h,a,b);
+ ROUND256_0_TO_15(b,c,d,e,f,g,h,a);
+ } while (j < 16);
+
+ /* Now for the remaining rounds to 64: */
+ do {
+ ROUND256(a,b,c,d,e,f,g,h);
+ ROUND256(h,a,b,c,d,e,f,g);
+ ROUND256(g,h,a,b,c,d,e,f);
+ ROUND256(f,g,h,a,b,c,d,e);
+ ROUND256(e,f,g,h,a,b,c,d);
+ ROUND256(d,e,f,g,h,a,b,c);
+ ROUND256(c,d,e,f,g,h,a,b);
+ ROUND256(b,c,d,e,f,g,h,a);
+ } while (j < 64);
+
+ /* Compute the current intermediate hash value */
+ context->s256.state[0] += a;
+ context->s256.state[1] += b;
+ context->s256.state[2] += c;
+ context->s256.state[3] += d;
+ context->s256.state[4] += e;
+ context->s256.state[5] += f;
+ context->s256.state[6] += g;
+ context->s256.state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = 0;
+}
+
+#else /* SHA2_UNROLL_TRANSFORM */
+
+void SHA256_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
+ sha_word32 a, b, c, d, e, f, g, h, s0, s1;
+ sha_word32 T1, T2, *W256;
+ int j;
+
+ W256 = (sha_word32*)context->s256.buffer;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->s256.state[0];
+ b = context->s256.state[1];
+ c = context->s256.state[2];
+ d = context->s256.state[3];
+ e = context->s256.state[4];
+ f = context->s256.state[5];
+ g = context->s256.state[6];
+ h = context->s256.state[7];
+
+ j = 0;
+ do {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Copy data while converting to host byte order */
+ REVERSE32(*data++,W256[j]);
+ /* Apply the SHA-256 compression function to update a..h */
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j];
+#else /* BYTE_ORDER == LITTLE_ENDIAN */
+ /* Apply the SHA-256 compression function to update a..h with copy */
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + (W256[j] = *data++);
+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+ T2 = Sigma0_256(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 16);
+
+ do {
+ /* Part of the message block expansion: */
+ s0 = W256[(j+1)&0x0f];
+ s0 = sigma0_256(s0);
+ s1 = W256[(j+14)&0x0f];
+ s1 = sigma1_256(s1);
+
+ /* Apply the SHA-256 compression function to update a..h */
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] +
+ (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0);
+ T2 = Sigma0_256(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 64);
+
+ /* Compute the current intermediate hash value */
+ context->s256.state[0] += a;
+ context->s256.state[1] += b;
+ context->s256.state[2] += c;
+ context->s256.state[3] += d;
+ context->s256.state[4] += e;
+ context->s256.state[5] += f;
+ context->s256.state[6] += g;
+ context->s256.state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = T2 = 0;
+}
+
+#endif /* SHA2_UNROLL_TRANSFORM */
+
+void SHA256_Update(SHA_CTX* context, const sha_byte *data, size_t len) {
+ unsigned int freespace, usedspace;
+
+ if (len == 0) {
+ /* Calling with no data is valid - we do nothing */
+ return;
+ }
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0 && data != (sha_byte*)0);
+
+ usedspace = (unsigned int)((context->s256.bitcount >> 3) % 64);
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = 64 - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ MEMCPY_BCOPY(&context->s256.buffer[usedspace], data, freespace);
+ context->s256.bitcount += freespace << 3;
+ len -= freespace;
+ data += freespace;
+ SHA256_Internal_Transform(context, (sha_word32*)context->s256.buffer);
+ } else {
+ /* The buffer is not yet full */
+ MEMCPY_BCOPY(&context->s256.buffer[usedspace], data, len);
+ context->s256.bitcount += len << 3;
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+ while (len >= 64) {
+ /* Process as many complete blocks as we can */
+ SHA256_Internal_Transform(context, (sha_word32*)data);
+ context->s256.bitcount += 512;
+ len -= 64;
+ data += 64;
+ }
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ MEMCPY_BCOPY(context->s256.buffer, data, len);
+ context->s256.bitcount += len << 3;
+ }
+ /* Clean up: */
+ usedspace = freespace = 0;
+}
+
+void SHA256_Internal_Last(SHA_CTX* context) {
+ unsigned int usedspace;
+
+ usedspace = (unsigned int)((context->s256.bitcount >> 3) % 64);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert FROM host byte order */
+ REVERSE64(context->s256.bitcount,context->s256.bitcount);
+#endif
+ if (usedspace > 0) {
+ /* Begin padding with a 1 bit: */
+ context->s256.buffer[usedspace++] = 0x80;
+
+ if (usedspace <= 56) {
+ /* Set-up for the last transform: */
+ MEMSET_BZERO(&context->s256.buffer[usedspace], 56 - usedspace);
+ } else {
+ if (usedspace < 64) {
+ MEMSET_BZERO(&context->s256.buffer[usedspace], 64 - usedspace);
+ }
+ /* Do second-to-last transform: */
+ SHA256_Internal_Transform(context, (sha_word32*)context->s256.buffer);
+
+ /* And set-up for the last transform: */
+ MEMSET_BZERO(context->s256.buffer, 56);
+ }
+ /* Clean up: */
+ usedspace = 0;
+ } else {
+ /* Set-up for the last transform: */
+ MEMSET_BZERO(context->s256.buffer, 56);
+
+ /* Begin padding with a 1 bit: */
+ *context->s256.buffer = 0x80;
+ }
+ /* Set the bit count: */
+ MEMCPY_BCOPY(&context->s256.buffer[56], &context->s256.bitcount,
+ sizeof(sha_word64));
+
+ /* Final transform: */
+ SHA256_Internal_Transform(context, (sha_word32*)context->s256.buffer);
+}
+
+void SHA256_Final(sha_byte digest[], SHA_CTX* context) {
+ sha_word32 *d = (sha_word32*)digest;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha_byte*)0) {
+ SHA256_Internal_Last(context);
+
+ /* Save the hash data for output: */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ {
+ /* Convert TO host byte order */
+ int j;
+ for (j = 0; j < (SHA256_DIGEST_LENGTH >> 2); j++) {
+ REVERSE32(context->s256.state[j],context->s256.state[j]);
+ *d++ = context->s256.state[j];
+ }
+ }
+#else
+ MEMCPY_BCOPY(d, context->s256.state, SHA256_DIGEST_LENGTH);
+#endif
+ }
+
+ /* Clean up state data: */
+ MEMSET_BZERO(context, sizeof(*context));
+}
+
+char *SHA256_End(SHA_CTX* context, char buffer[]) {
+ sha_byte digest[SHA256_DIGEST_LENGTH], *d = digest;
+ int i;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ if (buffer != (char*)0) {
+ SHA256_Final(digest, context);
+
+ for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
+ *buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha_hex_digits[*d & 0x0f];
+ d++;
+ }
+ *buffer = (char)0;
+ } else {
+ MEMSET_BZERO(context, sizeof(*context));
+ }
+ MEMSET_BZERO(digest, SHA256_DIGEST_LENGTH);
+ return buffer;
+}
+
+char* SHA256_Data(const sha_byte* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH]) {
+ SHA_CTX context;
+
+ SHA256_Init(&context);
+ SHA256_Update(&context, data, len);
+ return SHA256_End(&context, digest);
+}
+
+
+/*** SHA-224: *********************************************************/
+void SHA224_Init(SHA_CTX* context) {
+ SHA256_Internal_Init(context, sha224_initial_hash_value);
+}
+
+void SHA224_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
+ SHA256_Internal_Transform(context, data);
+}
+
+void SHA224_Update(SHA_CTX* context, const sha_byte *data, size_t len) {
+ SHA256_Update(context, data, len);
+}
+
+void SHA224_Final(sha_byte digest[], SHA_CTX* context) {
+ sha_word32 *d = (sha_word32*)digest;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha_byte*)0) {
+ SHA256_Internal_Last(context);
+
+ /* Save the hash data for output: */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ {
+ /* Convert TO host byte order */
+ int j;
+ for (j = 0; j < (SHA224_DIGEST_LENGTH >> 2); j++) {
+ REVERSE32(context->s256.state[j],context->s256.state[j]);
+ *d++ = context->s256.state[j];
+ }
+ }
+#else
+ MEMCPY_BCOPY(d, context->s256.state, SHA224_DIGEST_LENGTH);
+#endif
+ }
+
+ /* Clean up state data: */
+ MEMSET_BZERO(context, sizeof(*context));
+}
+
+char *SHA224_End(SHA_CTX* context, char buffer[]) {
+ sha_byte digest[SHA224_DIGEST_LENGTH], *d = digest;
+ int i;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ if (buffer != (char*)0) {
+ SHA224_Final(digest, context);
+
+ for (i = 0; i < SHA224_DIGEST_LENGTH; i++) {
+ *buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha_hex_digits[*d & 0x0f];
+ d++;
+ }
+ *buffer = (char)0;
+ } else {
+ MEMSET_BZERO(context, sizeof(*context));
+ }
+ MEMSET_BZERO(digest, SHA224_DIGEST_LENGTH);
+ return buffer;
+}
+
+char* SHA224_Data(const sha_byte* data, size_t len, char digest[SHA224_DIGEST_STRING_LENGTH]) {
+ SHA_CTX context;
+
+ SHA224_Init(&context);
+ SHA224_Update(&context, data, len);
+ return SHA224_End(&context, digest);
+}
+
+
+/*** SHA-512: *********************************************************/
+void SHA512_Internal_Init(SHA_CTX* context, const sha_word64* ihv) {
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ MEMCPY_BCOPY(context->s512.state, ihv, sizeof(sha_word64) * 8);
+ MEMSET_BZERO(context->s512.buffer, 128);
+ context->s512.bitcount[0] = context->s512.bitcount[1] = 0;
+}
+
+void SHA512_Init(SHA_CTX* context) {
+ SHA512_Internal_Init(context, sha512_initial_hash_value);
+}
+
+#ifdef SHA2_UNROLL_TRANSFORM
+
+/* Unrolled SHA-512 round macros: */
+#if BYTE_ORDER == LITTLE_ENDIAN
+
+#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) \
+ REVERSE64(*data++, W512[j]); \
+ T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
+ K512[j] + W512[j]; \
+ (d) += T1, \
+ (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)), \
+ j++
+
+
+#else /* BYTE_ORDER == LITTLE_ENDIAN */
+
+#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) \
+ T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
+ K512[j] + (W512[j] = *data++); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
+ j++
+
+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+
+#define ROUND512(a,b,c,d,e,f,g,h) \
+ s0 = W512[(j+1)&0x0f]; \
+ s0 = sigma0_512(s0); \
+ s1 = W512[(j+14)&0x0f]; \
+ s1 = sigma1_512(s1); \
+ T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + K512[j] + \
+ (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
+ j++
+
+void SHA512_Internal_Transform(SHA_CTX* context, const sha_word64* data) {
+ sha_word64 a, b, c, d, e, f, g, h, s0, s1;
+ sha_word64 T1, *W512 = (sha_word64*)context->s512.buffer;
+ int j;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->s512.state[0];
+ b = context->s512.state[1];
+ c = context->s512.state[2];
+ d = context->s512.state[3];
+ e = context->s512.state[4];
+ f = context->s512.state[5];
+ g = context->s512.state[6];
+ h = context->s512.state[7];
+
+ j = 0;
+ do {
+ ROUND512_0_TO_15(a,b,c,d,e,f,g,h);
+ ROUND512_0_TO_15(h,a,b,c,d,e,f,g);
+ ROUND512_0_TO_15(g,h,a,b,c,d,e,f);
+ ROUND512_0_TO_15(f,g,h,a,b,c,d,e);
+ ROUND512_0_TO_15(e,f,g,h,a,b,c,d);
+ ROUND512_0_TO_15(d,e,f,g,h,a,b,c);
+ ROUND512_0_TO_15(c,d,e,f,g,h,a,b);
+ ROUND512_0_TO_15(b,c,d,e,f,g,h,a);
+ } while (j < 16);
+
+ /* Now for the remaining rounds up to 79: */
+ do {
+ ROUND512(a,b,c,d,e,f,g,h);
+ ROUND512(h,a,b,c,d,e,f,g);
+ ROUND512(g,h,a,b,c,d,e,f);
+ ROUND512(f,g,h,a,b,c,d,e);
+ ROUND512(e,f,g,h,a,b,c,d);
+ ROUND512(d,e,f,g,h,a,b,c);
+ ROUND512(c,d,e,f,g,h,a,b);
+ ROUND512(b,c,d,e,f,g,h,a);
+ } while (j < 80);
+
+ /* Compute the current intermediate hash value */
+ context->s512.state[0] += a;
+ context->s512.state[1] += b;
+ context->s512.state[2] += c;
+ context->s512.state[3] += d;
+ context->s512.state[4] += e;
+ context->s512.state[5] += f;
+ context->s512.state[6] += g;
+ context->s512.state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = 0;
+}
+
+#else /* SHA2_UNROLL_TRANSFORM */
+
+void SHA512_Internal_Transform(SHA_CTX* context, const sha_word64* data) {
+ sha_word64 a, b, c, d, e, f, g, h, s0, s1;
+ sha_word64 T1, T2, *W512 = (sha_word64*)context->s512.buffer;
+ int j;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->s512.state[0];
+ b = context->s512.state[1];
+ c = context->s512.state[2];
+ d = context->s512.state[3];
+ e = context->s512.state[4];
+ f = context->s512.state[5];
+ g = context->s512.state[6];
+ h = context->s512.state[7];
+
+ j = 0;
+ do {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ REVERSE64(*data++, W512[j]);
+ /* Apply the SHA-512 compression function to update a..h */
+ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j];
+#else /* BYTE_ORDER == LITTLE_ENDIAN */
+ /* Apply the SHA-512 compression function to update a..h with copy */
+ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j] = *data++);
+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+ T2 = Sigma0_512(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 16);
+
+ do {
+ /* Part of the message block expansion: */
+ s0 = W512[(j+1)&0x0f];
+ s0 = sigma0_512(s0);
+ s1 = W512[(j+14)&0x0f];
+ s1 = sigma1_512(s1);
+
+ /* Apply the SHA-512 compression function to update a..h */
+ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] +
+ (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0);
+ T2 = Sigma0_512(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 80);
+
+ /* Compute the current intermediate hash value */
+ context->s512.state[0] += a;
+ context->s512.state[1] += b;
+ context->s512.state[2] += c;
+ context->s512.state[3] += d;
+ context->s512.state[4] += e;
+ context->s512.state[5] += f;
+ context->s512.state[6] += g;
+ context->s512.state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = T2 = 0;
+}
+
+#endif /* SHA2_UNROLL_TRANSFORM */
+
+void SHA512_Update(SHA_CTX* context, const sha_byte *data, size_t len) {
+ unsigned int freespace, usedspace;
+
+ if (len == 0) {
+ /* Calling with no data is valid - we do nothing */
+ return;
+ }
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0 && data != (sha_byte*)0);
+
+ usedspace = (unsigned int)((context->s512.bitcount[0] >> 3) % 128);
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = 128 - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ MEMCPY_BCOPY(&context->s512.buffer[usedspace], data, freespace);
+ ADDINC128(context->s512.bitcount, freespace << 3);
+ len -= freespace;
+ data += freespace;
+ SHA512_Internal_Transform(context, (sha_word64*)context->s512.buffer);
+ } else {
+ /* The buffer is not yet full */
+ MEMCPY_BCOPY(&context->s512.buffer[usedspace], data, len);
+ ADDINC128(context->s512.bitcount, len << 3);
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+ while (len >= 128) {
+ /* Process as many complete blocks as we can */
+ SHA512_Internal_Transform(context, (sha_word64*)data);
+ ADDINC128(context->s512.bitcount, 1024);
+ len -= 128;
+ data += 128;
+ }
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ MEMCPY_BCOPY(context->s512.buffer, data, len);
+ ADDINC128(context->s512.bitcount, len << 3);
+ }
+ /* Clean up: */
+ usedspace = freespace = 0;
+}
+
+void SHA512_Internal_Last(SHA_CTX* context) {
+ unsigned int usedspace;
+
+ usedspace = (unsigned int)((context->s512.bitcount[0] >> 3) % 128);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert FROM host byte order */
+ REVERSE64(context->s512.bitcount[0],context->s512.bitcount[0]);
+ REVERSE64(context->s512.bitcount[1],context->s512.bitcount[1]);
+#endif
+ if (usedspace > 0) {
+ /* Begin padding with a 1 bit: */
+ context->s512.buffer[usedspace++] = 0x80;
+
+ if (usedspace <= 112) {
+ /* Set-up for the last transform: */
+ MEMSET_BZERO(&context->s512.buffer[usedspace], 112 - usedspace);
+ } else {
+ if (usedspace < 128) {
+ MEMSET_BZERO(&context->s512.buffer[usedspace], 128 - usedspace);
+ }
+ /* Do second-to-last transform: */
+ SHA512_Internal_Transform(context, (sha_word64*)context->s512.buffer);
+
+ /* And set-up for the last transform: */
+ MEMSET_BZERO(context->s512.buffer, 112);
+ }
+ /* Clean up: */
+ usedspace = 0;
+ } else {
+ /* Prepare for final transform: */
+ MEMSET_BZERO(context->s512.buffer, 112);
+
+ /* Begin padding with a 1 bit: */
+ *context->s512.buffer = 0x80;
+ }
+ /* Store the length of input data (in bits): */
+ MEMCPY_BCOPY(&context->s512.buffer[112], &context->s512.bitcount[1],
+ sizeof(sha_word64));
+ MEMCPY_BCOPY(&context->s512.buffer[120], &context->s512.bitcount[0],
+ sizeof(sha_word64));
+
+ /* Final transform: */
+ SHA512_Internal_Transform(context, (sha_word64*)context->s512.buffer);
+}
+
+void SHA512_Final(sha_byte digest[], SHA_CTX* context) {
+ sha_word64 *d = (sha_word64*)digest;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha_byte*)0) {
+ SHA512_Internal_Last(context);
+
+ /* Save the hash data for output: */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ {
+ /* Convert TO host byte order */
+ int j;
+ for (j = 0; j < (SHA512_DIGEST_LENGTH >> 3); j++) {
+ REVERSE64(context->s512.state[j],context->s512.state[j]);
+ *d++ = context->s512.state[j];
+ }
+ }
+#else
+ MEMCPY_BCOPY(d, context->s512.state, SHA512_DIGEST_LENGTH);
+#endif
+ }
+
+ /* Zero out state data */
+ MEMSET_BZERO(context, sizeof(*context));
+}
+
+char *SHA512_End(SHA_CTX* context, char buffer[]) {
+ sha_byte digest[SHA512_DIGEST_LENGTH], *d = digest;
+ int i;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ if (buffer != (char*)0) {
+ SHA512_Final(digest, context);
+
+ for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
+ *buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha_hex_digits[*d & 0x0f];
+ d++;
+ }
+ *buffer = (char)0;
+ } else {
+ MEMSET_BZERO(context, sizeof(*context));
+ }
+ MEMSET_BZERO(digest, SHA512_DIGEST_LENGTH);
+ return buffer;
+}
+
+char* SHA512_Data(const sha_byte* data, size_t len, char digest[SHA512_DIGEST_STRING_LENGTH]) {
+ SHA_CTX context;
+
+ SHA512_Init(&context);
+ SHA512_Update(&context, data, len);
+ return SHA512_End(&context, digest);
+}
+
+
+/*** SHA-384: *********************************************************/
+void SHA384_Init(SHA_CTX* context) {
+ SHA512_Internal_Init(context, sha384_initial_hash_value);
+}
+
+void SHA384_Update(SHA_CTX* context, const sha_byte* data, size_t len) {
+ SHA512_Update(context, data, len);
+}
+
+void SHA384_Final(sha_byte digest[], SHA_CTX* context) {
+ sha_word64 *d = (sha_word64*)digest;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha_byte*)0) {
+ SHA512_Internal_Last(context);
+
+ /* Save the hash data for output: */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ {
+ /* Convert TO host byte order */
+ int j;
+ for (j = 0; j < (SHA384_DIGEST_LENGTH >> 3); j++) {
+ REVERSE64(context->s512.state[j],context->s512.state[j]);
+ *d++ = context->s512.state[j];
+ }
+ }
+#else
+ MEMCPY_BCOPY(d, context->s512.state, SHA384_DIGEST_LENGTH);
+#endif
+ }
+
+ /* Zero out state data */
+ MEMSET_BZERO(context, sizeof(*context));
+}
+
+char *SHA384_End(SHA_CTX* context, char buffer[]) {
+ sha_byte digest[SHA384_DIGEST_LENGTH], *d = digest;
+ int i;
+
+ /* Sanity check: */
+ assert(context != (SHA_CTX*)0);
+
+ if (buffer != (char*)0) {
+ SHA384_Final(digest, context);
+
+ for (i = 0; i < SHA384_DIGEST_LENGTH; i++) {
+ *buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha_hex_digits[*d & 0x0f];
+ d++;
+ }
+ *buffer = (char)0;
+ } else {
+ MEMSET_BZERO(context, sizeof(*context));
+ }
+ MEMSET_BZERO(digest, SHA384_DIGEST_LENGTH);
+ return buffer;
+}
+
+char* SHA384_Data(const sha_byte* data, size_t len, char digest[SHA384_DIGEST_STRING_LENGTH]) {
+ SHA_CTX context;
+
+ SHA384_Init(&context);
+ SHA384_Update(&context, data, len);
+ return SHA384_End(&context, digest);
+}
diff --git a/Source/cm_sha2.h b/Source/cm_sha2.h
new file mode 100644
index 0000000000..71395f06b8
--- /dev/null
+++ b/Source/cm_sha2.h
@@ -0,0 +1,140 @@
+/*
+ * FILE: sha2.h
+ * AUTHOR: Aaron D. Gifford
+ * http://www.aarongifford.com/computers/sha.html
+ *
+ * Copyright (c) 2000-2003, Aaron D. Gifford
+ * 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.
+ * 3. Neither the name of the copyright holder nor the names of contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(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 OR CONTRIBUTOR(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.
+ *
+ * $Id: sha2.h,v 1.4 2004/01/07 19:06:18 adg Exp $
+ */
+
+#ifndef __SHA2_H__
+#define __SHA2_H__
+
+#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;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ * Import u_intXX_t size_t type definitions from system headers. You
+ * may need to change this, or define these things yourself in this
+ * file.
+ */
+#include <sys/types.h>
+
+/*** SHA-224/256/384/512 Various Length Definitions *******************/
+
+/* Digest lengths for SHA-1/224/256/384/512 */
+#define SHA1_DIGEST_LENGTH 20
+#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
+#define SHA224_DIGEST_LENGTH 28
+#define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1)
+#define SHA256_DIGEST_LENGTH 32
+#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
+#define SHA384_DIGEST_LENGTH 48
+#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
+#define SHA512_DIGEST_LENGTH 64
+#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
+
+
+/*** SHA-224/256/384/512 Context Structures ***************************/
+
+typedef union _SHA_CTX {
+ /* SHA-1 uses this part of the union: */
+ struct {
+ cm_sha2_uint32_t state[5];
+ cm_sha2_uint64_t bitcount;
+ cm_sha2_uint8_t buffer[64];
+ } s1;
+
+ /* SHA-224 and SHA-256 use this part of the union: */
+ struct {
+ cm_sha2_uint32_t state[8];
+ cm_sha2_uint64_t bitcount;
+ cm_sha2_uint8_t buffer[64];
+ } s256;
+
+ /* SHA-384 and SHA-512 use this part of the union: */
+ struct {
+ cm_sha2_uint64_t state[8];
+ cm_sha2_uint64_t bitcount[2];
+ cm_sha2_uint8_t buffer[128];
+ } s512;
+} SHA_CTX;
+
+/*** SHA-256/384/512 Function Prototypes ******************************/
+
+void SHA1_Init(SHA_CTX*);
+void SHA1_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA1_Final(cm_sha2_uint8_t[SHA1_DIGEST_LENGTH], SHA_CTX*);
+char* SHA1_End(SHA_CTX*, char[SHA1_DIGEST_STRING_LENGTH]);
+char* SHA1_Data(const cm_sha2_uint8_t*, size_t,
+ char[SHA1_DIGEST_STRING_LENGTH]);
+
+void SHA224_Init(SHA_CTX*);
+void SHA224_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA224_Final(cm_sha2_uint8_t[SHA224_DIGEST_LENGTH], SHA_CTX*);
+char* SHA224_End(SHA_CTX*, char[SHA224_DIGEST_STRING_LENGTH]);
+char* SHA224_Data(const cm_sha2_uint8_t*, size_t,
+ char[SHA224_DIGEST_STRING_LENGTH]);
+
+void SHA256_Init(SHA_CTX*);
+void SHA256_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA256_Final(cm_sha2_uint8_t[SHA256_DIGEST_LENGTH], SHA_CTX*);
+char* SHA256_End(SHA_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
+char* SHA256_Data(const cm_sha2_uint8_t*, size_t,
+ char[SHA256_DIGEST_STRING_LENGTH]);
+
+void SHA384_Init(SHA_CTX*);
+void SHA384_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA384_Final(cm_sha2_uint8_t[SHA384_DIGEST_LENGTH], SHA_CTX*);
+char* SHA384_End(SHA_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
+char* SHA384_Data(const cm_sha2_uint8_t*, size_t,
+ char[SHA384_DIGEST_STRING_LENGTH]);
+
+void SHA512_Init(SHA_CTX*);
+void SHA512_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA512_Final(cm_sha2_uint8_t[SHA512_DIGEST_LENGTH], SHA_CTX*);
+char* SHA512_End(SHA_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
+char* SHA512_Data(const cm_sha2_uint8_t*, size_t,
+ char[SHA512_DIGEST_STRING_LENGTH]);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __SHA2_H__ */
diff --git a/Source/cm_sha2_mangle.h b/Source/cm_sha2_mangle.h
new file mode 100644
index 0000000000..e73d131413
--- /dev/null
+++ b/Source/cm_sha2_mangle.h
@@ -0,0 +1,51 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2011 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 cm_sha2_mangle_h
+#define cm_sha2_mangle_h
+
+/* Mangle sha2 symbol names to avoid possible conflict with
+ implementations in other libraries to which CMake links. */
+#define SHA1_Data cmSHA1_Data
+#define SHA1_End cmSHA1_End
+#define SHA1_Final cmSHA1_Final
+#define SHA1_Init cmSHA1_Init
+#define SHA1_Internal_Transform cmSHA1_Internal_Transform
+#define SHA1_Update cmSHA1_Update
+#define SHA224_Data cmSHA224_Data
+#define SHA224_End cmSHA224_End
+#define SHA224_Final cmSHA224_Final
+#define SHA224_Init cmSHA224_Init
+#define SHA224_Internal_Transform cmSHA224_Internal_Transform
+#define SHA224_Update cmSHA224_Update
+#define SHA256_Data cmSHA256_Data
+#define SHA256_End cmSHA256_End
+#define SHA256_Final cmSHA256_Final
+#define SHA256_Init cmSHA256_Init
+#define SHA256_Internal_Init cmSHA256_Internal_Init
+#define SHA256_Internal_Last cmSHA256_Internal_Last
+#define SHA256_Internal_Transform cmSHA256_Internal_Transform
+#define SHA256_Update cmSHA256_Update
+#define SHA384_Data cmSHA384_Data
+#define SHA384_End cmSHA384_End
+#define SHA384_Final cmSHA384_Final
+#define SHA384_Init cmSHA384_Init
+#define SHA384_Update cmSHA384_Update
+#define SHA512_Data cmSHA512_Data
+#define SHA512_End cmSHA512_End
+#define SHA512_Final cmSHA512_Final
+#define SHA512_Init cmSHA512_Init
+#define SHA512_Internal_Init cmSHA512_Internal_Init
+#define SHA512_Internal_Last cmSHA512_Internal_Last
+#define SHA512_Internal_Transform cmSHA512_Internal_Transform
+#define SHA512_Update cmSHA512_Update
+
+#endif
diff --git a/Source/cm_utf8.c b/Source/cm_utf8.c
new file mode 100644
index 0000000000..c9bf259acc
--- /dev/null
+++ b/Source/cm_utf8.c
@@ -0,0 +1,84 @@
+/*============================================================================
+ 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 "cm_utf8.h"
+
+/*
+ RFC 3629
+ 07-bit: 0xxxxxxx
+ 11-bit: 110xxxxx 10xxxxxx
+ 16-bit: 1110xxxx 10xxxxxx 10xxxxxx
+ 21-bit: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+
+ Pre-RFC Compatibility
+ 26-bit: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ 31-bit: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+*/
+
+/* Number of leading ones before a zero in the byte. */
+static unsigned char const cm_utf8_ones[256] = {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,7,8
+};
+
+/* Mask away control bits from bytes with n leading ones. */
+static unsigned char const cm_utf8_mask[7] = {
+ 0xEF, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01
+};
+
+/* Minimum allowed value when first byte has n leading ones. */
+static unsigned int const cm_utf8_min[7] = {
+ 0, 0, 1u<<7, 1u<<11, 1u<<16, 1u<<21, 1u<<26 /*, 1u<<31 */
+};
+
+/*--------------------------------------------------------------------------*/
+const char* cm_utf8_decode_character(const char* first, const char* last,
+ unsigned int* pc)
+{
+ /* Count leading ones in the first byte. */
+ unsigned char c = (unsigned char)*first++;
+ unsigned char const ones = cm_utf8_ones[c];
+ switch(ones)
+ {
+ case 0: *pc = c; return first; /* One-byte character. */
+ case 1: case 7: case 8: return 0; /* Invalid leading byte. */
+ default: break;
+ }
+
+ /* Extract bits from this multi-byte character. */
+ {
+ unsigned int uc = c & cm_utf8_mask[ones];
+ int left;
+ for(left = ones-1; left && first != last; --left)
+ {
+ c = (unsigned char)*first++;
+ if(cm_utf8_ones[c] != 1)
+ {
+ return 0;
+ }
+ uc = (uc << 6) | (c & cm_utf8_mask[1]);
+ }
+
+ if(left > 0 || uc < cm_utf8_min[ones])
+ {
+ return 0;
+ }
+
+ *pc = uc;
+ return first;
+ }
+}
diff --git a/Source/cm_utf8.h b/Source/cm_utf8.h
new file mode 100644
index 0000000000..06e2868d54
--- /dev/null
+++ b/Source/cm_utf8.h
@@ -0,0 +1,29 @@
+/*============================================================================
+ 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 cm_utf8_h
+#define cm_utf8_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Decode one UTF-8 character from the input byte range. On success,
+ stores the unicode character number in *pc and returns the first
+ position not extracted. On failure, returns 0. */
+const char* cm_utf8_decode_character(const char* first, const char* last,
+ unsigned int* pc);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
new file mode 100644
index 0000000000..09d270d595
--- /dev/null
+++ b/Source/cmake.cxx
@@ -0,0 +1,2857 @@
+/*============================================================================
+ 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 "cmake.h"
+#include "cmCacheManager.h"
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmExternalMakefileProjectGenerator.h"
+#include "cmCommands.h"
+#include "cmCommand.h"
+#include "cmFileTimeComparison.h"
+#include "cmSourceFile.h"
+#include "cmTest.h"
+#include "cmDocumentationFormatter.h"
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include "cmGraphVizWriter.h"
+# include "cmVariableWatch.h"
+# include <cmsys/SystemInformation.hxx>
+#endif
+
+#include <cmsys/Glob.hxx>
+#include <cmsys/RegularExpression.hxx>
+#include <cmsys/FStream.hxx>
+
+// only build kdevelop generator on non-windows platforms
+// when not bootstrapping cmake
+#if !defined(_WIN32)
+# if defined(CMAKE_BUILD_WITH_CMAKE)
+# define CMAKE_USE_KDEVELOP
+# endif
+#endif
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# define CMAKE_USE_ECLIPSE
+#endif
+
+#if defined(__MINGW32__) && !defined(CMAKE_BUILD_WITH_CMAKE)
+# define CMAKE_BOOT_MINGW
+#endif
+
+// include the generator
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# if !defined(CMAKE_BOOT_MINGW)
+# include "cmGlobalVisualStudio6Generator.h"
+# include "cmGlobalVisualStudio7Generator.h"
+# include "cmGlobalVisualStudio71Generator.h"
+# include "cmGlobalVisualStudio8Generator.h"
+# include "cmGlobalVisualStudio9Generator.h"
+# include "cmGlobalVisualStudio10Generator.h"
+# include "cmGlobalVisualStudio11Generator.h"
+# include "cmGlobalVisualStudio12Generator.h"
+# include "cmGlobalVisualStudio14Generator.h"
+# include "cmGlobalBorlandMakefileGenerator.h"
+# include "cmGlobalNMakeMakefileGenerator.h"
+# include "cmGlobalJOMMakefileGenerator.h"
+# define CMAKE_HAVE_VS_GENERATORS
+# endif
+# include "cmGlobalMSYSMakefileGenerator.h"
+# include "cmGlobalMinGWMakefileGenerator.h"
+#else
+#endif
+#if defined(CMAKE_USE_WMAKE)
+# include "cmGlobalWatcomWMakeGenerator.h"
+#endif
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmGlobalNinjaGenerator.h"
+#include "cmExtraCodeLiteGenerator.h"
+
+#if !defined(CMAKE_BOOT_MINGW)
+# include "cmExtraCodeBlocksGenerator.h"
+#endif
+#include "cmExtraSublimeTextGenerator.h"
+#include "cmExtraKateGenerator.h"
+
+#ifdef CMAKE_USE_KDEVELOP
+# include "cmGlobalKdevelopGenerator.h"
+#endif
+
+#ifdef CMAKE_USE_ECLIPSE
+# include "cmExtraEclipseCDT4Generator.h"
+#endif
+
+#include <stdlib.h> // required for atoi
+
+#if defined( __APPLE__ )
+# if defined(CMAKE_BUILD_WITH_CMAKE)
+# include "cmGlobalXCodeGenerator.h"
+# define CMAKE_USE_XCODE 1
+# endif
+# include <sys/types.h>
+# include <sys/time.h>
+# include <sys/resource.h>
+#endif
+
+#include <sys/stat.h> // struct stat
+
+static bool cmakeCheckStampFile(const char* stampName);
+static bool cmakeCheckStampList(const char* stampName);
+
+void cmWarnUnusedCliWarning(const std::string& variable,
+ int, void* ctx, const char*, const cmMakefile*)
+{
+ cmake* cm = reinterpret_cast<cmake*>(ctx);
+ cm->MarkCliAsUsed(variable);
+}
+
+cmake::cmake()
+{
+ this->Trace = false;
+ this->WarnUninitialized = false;
+ 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->Policies = new cmPolicies();
+ this->InitializeProperties();
+
+#ifdef __APPLE__
+ struct rlimit rlp;
+ if(!getrlimit(RLIMIT_STACK, &rlp))
+ {
+ if(rlp.rlim_cur != rlp.rlim_max)
+ {
+ rlp.rlim_cur = rlp.rlim_max;
+ setrlimit(RLIMIT_STACK, &rlp);
+ }
+ }
+#endif
+
+ this->Verbose = false;
+ this->InTryCompile = false;
+ this->CacheManager = new cmCacheManager(this);
+ this->GlobalGenerator = 0;
+ this->ProgressCallback = 0;
+ this->ProgressCallbackClientData = 0;
+ this->CurrentWorkingMode = NORMAL_MODE;
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ this->VariableWatch = new cmVariableWatch;
+#endif
+
+ this->AddDefaultGenerators();
+ this->AddDefaultExtraGenerators();
+ this->AddDefaultCommands();
+
+ // Make sure we can capture the build tool output.
+ cmSystemTools::EnableVSConsoleOutput();
+}
+
+cmake::~cmake()
+{
+ delete this->CacheManager;
+ delete this->Policies;
+ if (this->GlobalGenerator)
+ {
+ delete this->GlobalGenerator;
+ this->GlobalGenerator = 0;
+ }
+ for(RegisteredCommandsMap::iterator j = this->Commands.begin();
+ j != this->Commands.end(); ++j)
+ {
+ delete (*j).second;
+ }
+ for(RegisteredGeneratorsVector::iterator j = this->Generators.begin();
+ j != this->Generators.end(); ++j)
+ {
+ delete *j;
+ }
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ delete this->VariableWatch;
+#endif
+ delete this->FileComparison;
+}
+
+void cmake::InitializeProperties()
+{
+ this->Properties.clear();
+ this->Properties.SetCMakeInstance(this);
+ this->AccessedProperties.clear();
+ this->PropertyDefinitions.clear();
+
+ // initialize properties
+ cmTarget::DefineProperties(this);
+ cmMakefile::DefineProperties(this);
+}
+
+void cmake::CleanupCommandsAndMacros()
+{
+ this->InitializeProperties();
+ std::vector<cmCommand*> commands;
+ for(RegisteredCommandsMap::iterator j = this->Commands.begin();
+ j != this->Commands.end(); ++j)
+ {
+ if ( !j->second->IsA("cmMacroHelperCommand") &&
+ !j->second->IsA("cmFunctionHelperCommand"))
+ {
+ commands.push_back(j->second);
+ }
+ else
+ {
+ delete j->second;
+ }
+ }
+ this->Commands.erase(this->Commands.begin(), this->Commands.end());
+ std::vector<cmCommand*>::iterator it;
+ for ( it = commands.begin(); it != commands.end();
+ ++ it )
+ {
+ this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
+ }
+}
+
+bool cmake::CommandExists(const std::string& name) const
+{
+ std::string sName = cmSystemTools::LowerCase(name);
+ return (this->Commands.find(sName) != this->Commands.end());
+}
+
+cmCommand *cmake::GetCommand(const std::string& name)
+{
+ cmCommand* rm = 0;
+ std::string sName = cmSystemTools::LowerCase(name);
+ RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
+ if (pos != this->Commands.end())
+ {
+ rm = (*pos).second;
+ }
+ return rm;
+}
+
+void cmake::RenameCommand(const std::string& oldName,
+ const std::string& newName)
+{
+ // if the command already exists, free the old one
+ std::string sOldName = cmSystemTools::LowerCase(oldName);
+ std::string sNewName = cmSystemTools::LowerCase(newName);
+ RegisteredCommandsMap::iterator pos = this->Commands.find(sOldName);
+ if ( pos == this->Commands.end() )
+ {
+ return;
+ }
+ cmCommand* cmd = pos->second;
+
+ pos = this->Commands.find(sNewName);
+ if (pos != this->Commands.end())
+ {
+ delete pos->second;
+ this->Commands.erase(pos);
+ }
+ this->Commands.insert(RegisteredCommandsMap::value_type(sNewName, cmd));
+ pos = this->Commands.find(sOldName);
+ this->Commands.erase(pos);
+}
+
+void cmake::RemoveCommand(const std::string& name)
+{
+ std::string sName = cmSystemTools::LowerCase(name);
+ RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
+ if ( pos != this->Commands.end() )
+ {
+ delete pos->second;
+ this->Commands.erase(pos);
+ }
+}
+
+void cmake::AddCommand(cmCommand* wg)
+{
+ std::string name = cmSystemTools::LowerCase(wg->GetName());
+ // if the command already exists, free the old one
+ RegisteredCommandsMap::iterator pos = this->Commands.find(name);
+ if (pos != this->Commands.end())
+ {
+ delete pos->second;
+ this->Commands.erase(pos);
+ }
+ this->Commands.insert( RegisteredCommandsMap::value_type(name, wg));
+}
+
+
+void cmake::RemoveUnscriptableCommands()
+{
+ std::vector<std::string> unscriptableCommands;
+ cmake::RegisteredCommandsMap* commands = this->GetCommands();
+ for (cmake::RegisteredCommandsMap::const_iterator pos = commands->begin();
+ pos != commands->end();
+ ++pos)
+ {
+ if (!pos->second->IsScriptable())
+ {
+ unscriptableCommands.push_back(pos->first);
+ }
+ }
+
+ for(std::vector<std::string>::const_iterator it=unscriptableCommands.begin();
+ it != unscriptableCommands.end();
+ ++it)
+ {
+ this->RemoveCommand(*it);
+ }
+}
+
+// Parse the args
+bool cmake::SetCacheArgs(const std::vector<std::string>& args)
+{
+ bool findPackageMode = false;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ std::string arg = args[i];
+ if(arg.find("-D",0) == 0)
+ {
+ std::string entry = arg.substr(2);
+ if(entry.size() == 0)
+ {
+ ++i;
+ if(i < args.size())
+ {
+ entry = args[i];
+ }
+ else
+ {
+ cmSystemTools::Error("-D must be followed with VAR=VALUE.");
+ return false;
+ }
+ }
+ std::string var, value;
+ cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
+ if(cmCacheManager::ParseEntry(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
+ // after we call AddCacheEntry.
+ bool haveValue = false;
+ std::string cachedValue;
+ if(this->WarnUnusedCli)
+ {
+ if(const char *v = this->CacheManager->GetCacheValue(var))
+ {
+ haveValue = true;
+ cachedValue = v;
+ }
+ }
+
+ this->CacheManager->AddCacheEntry(var, value.c_str(),
+ "No help, variable specified on the command line.", type);
+
+ if(this->WarnUnusedCli)
+ {
+ if (!haveValue ||
+ cachedValue != this->CacheManager->GetCacheValue(var))
+ {
+ this->WatchUnusedCli(var);
+ }
+ }
+ }
+ else
+ {
+ std::cerr << "Parse error in command line argument: " << arg << "\n"
+ << "Should be: VAR:type=value\n";
+ cmSystemTools::Error("No cmake script provided.");
+ return false;
+ }
+ }
+ else if(arg.find("-Wno-dev",0) == 0)
+ {
+ this->SuppressDevWarnings = true;
+ this->DoSuppressDevWarnings = true;
+ }
+ else if(arg.find("-Wdev",0) == 0)
+ {
+ this->SuppressDevWarnings = false;
+ this->DoSuppressDevWarnings = true;
+ }
+ else if(arg.find("-U",0) == 0)
+ {
+ std::string entryPattern = arg.substr(2);
+ if(entryPattern.size() == 0)
+ {
+ ++i;
+ if(i < args.size())
+ {
+ entryPattern = args[i];
+ }
+ else
+ {
+ cmSystemTools::Error("-U must be followed with VAR.");
+ return false;
+ }
+ }
+ cmsys::RegularExpression regex(
+ cmsys::Glob::PatternToRegex(entryPattern, true, true).c_str());
+ //go through all cache entries and collect the vars which will be removed
+ std::vector<std::string> entriesToDelete;
+ cmCacheManager::CacheIterator it =
+ this->CacheManager->GetCacheIterator();
+ for ( it.Begin(); !it.IsAtEnd(); it.Next() )
+ {
+ cmCacheManager::CacheEntryType t = it.GetType();
+ if(t != cmCacheManager::STATIC)
+ {
+ std::string entryName = it.GetName();
+ if (regex.find(entryName.c_str()))
+ {
+ entriesToDelete.push_back(entryName);
+ }
+ }
+ }
+
+ // now remove them from the cache
+ for(std::vector<std::string>::const_iterator currentEntry =
+ entriesToDelete.begin();
+ currentEntry != entriesToDelete.end();
+ ++currentEntry)
+ {
+ this->CacheManager->RemoveCacheEntry(*currentEntry);
+ }
+ }
+ else if(arg.find("-C",0) == 0)
+ {
+ std::string path = arg.substr(2);
+ if ( path.size() == 0 )
+ {
+ ++i;
+ if(i < args.size())
+ {
+ path = args[i];
+ }
+ else
+ {
+ cmSystemTools::Error("-C must be followed by a file name.");
+ return false;
+ }
+ }
+ std::cerr << "loading initial cache file " << path << "\n";
+ this->ReadListFile(args, path.c_str());
+ }
+ else if(arg.find("-P",0) == 0)
+ {
+ i++;
+ if(i >= args.size())
+ {
+ cmSystemTools::Error("-P must be followed by a file name.");
+ return false;
+ }
+ std::string path = args[i];
+ if ( path.size() == 0 )
+ {
+ cmSystemTools::Error("No cmake script provided.");
+ return false;
+ }
+ this->ReadListFile(args, path.c_str());
+ }
+ else if (arg.find("--find-package",0) == 0)
+ {
+ findPackageMode = true;
+ }
+ }
+
+ if (findPackageMode)
+ {
+ return this->FindPackage(args);
+ }
+
+ return true;
+}
+
+void cmake::ReadListFile(const std::vector<std::string>& args,
+ const char *path)
+{
+ // if a generator was not yet created, temporarily create one
+ cmGlobalGenerator *gg = this->GetGlobalGenerator();
+ bool created = false;
+
+ // if a generator was not specified use a generic one
+ if (!gg)
+ {
+ gg = new cmGlobalGenerator;
+ gg->SetCMakeInstance(this);
+ created = true;
+ }
+
+ // read in the list file to fill the cache
+ if(path)
+ {
+ cmsys::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
+ lg->GetMakefile()->SetHomeOutputDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ lg->GetMakefile()->SetStartOutputDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ lg->GetMakefile()->SetHomeDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ lg->GetMakefile()->SetStartDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ if (this->GetWorkingMode() != NORMAL_MODE)
+ {
+ std::string file(cmSystemTools::CollapseFullPath(path));
+ cmSystemTools::ConvertToUnixSlashes(file);
+ lg->GetMakefile()->SetScriptModeFile(file.c_str());
+
+ lg->GetMakefile()->SetArgcArgv(args);
+ }
+ if (!lg->GetMakefile()->ReadListFile(0, path))
+ {
+ cmSystemTools::Error("Error processing file: ", path);
+ }
+ }
+
+ // free generic one if generated
+ if (created)
+ {
+ delete gg;
+ }
+}
+
+
+bool cmake::FindPackage(const std::vector<std::string>& args)
+{
+ // if a generator was not yet created, temporarily create one
+ cmGlobalGenerator *gg = new cmGlobalGenerator;
+ gg->SetCMakeInstance(this);
+ this->SetGlobalGenerator(gg);
+
+ // read in the list file to fill the cache
+ cmsys::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
+ cmMakefile* mf = lg->GetMakefile();
+ mf->SetHomeOutputDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ mf->SetStartOutputDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ mf->SetHomeDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ mf->SetStartDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+
+ mf->SetArgcArgv(args);
+
+ std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake");
+ mf->ReadListFile(0, systemFile.c_str());
+
+ std::string language = mf->GetSafeDefinition("LANGUAGE");
+ std::string mode = mf->GetSafeDefinition("MODE");
+ std::string packageName = mf->GetSafeDefinition("NAME");
+ bool packageFound = mf->IsOn("PACKAGE_FOUND");
+ bool quiet = mf->IsOn("PACKAGE_QUIET");
+
+ if (!packageFound)
+ {
+ if (!quiet)
+ {
+ printf("%s not found.\n", packageName.c_str());
+ }
+ }
+ else if (mode == "EXIST")
+ {
+ if (!quiet)
+ {
+ printf("%s found.\n", packageName.c_str());
+ }
+ }
+ else if (mode == "COMPILE")
+ {
+ std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS");
+ std::vector<std::string> includeDirs;
+ cmSystemTools::ExpandListArgument(includes, includeDirs);
+
+ std::string includeFlags = lg->GetIncludeFlags(includeDirs, 0,
+ language, false);
+
+ std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS");
+ printf("%s %s\n", includeFlags.c_str(), definitions.c_str());
+ }
+ else if (mode == "LINK")
+ {
+ const char* targetName = "dummy";
+ std::vector<std::string> srcs;
+ cmTarget* tgt = mf->AddExecutable(targetName, srcs, true);
+ tgt->SetProperty("LINKER_LANGUAGE", language.c_str());
+
+ std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES");
+ std::vector<std::string> libList;
+ cmSystemTools::ExpandListArgument(libs, libList);
+ for(std::vector<std::string>::const_iterator libIt=libList.begin();
+ libIt != libList.end();
+ ++libIt)
+ {
+ mf->AddLinkLibraryForTarget(targetName, *libIt,
+ cmTarget::GENERAL);
+ }
+
+
+ std::string linkLibs;
+ std::string frameworkPath;
+ std::string linkPath;
+ std::string flags;
+ std::string linkFlags;
+ gg->CreateGeneratorTargets(mf);
+ cmGeneratorTarget *gtgt = gg->GetGeneratorTarget(tgt);
+ lg->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags,
+ gtgt, false);
+ linkLibs = frameworkPath + linkPath + linkLibs;
+
+ printf("%s\n", linkLibs.c_str() );
+
+/* if ( use_win32 )
+ {
+ tgt->SetProperty("WIN32_EXECUTABLE", "ON");
+ }
+ if ( use_macbundle)
+ {
+ tgt->SetProperty("MACOSX_BUNDLE", "ON");
+ }*/
+ }
+
+ // free generic one if generated
+// this->SetGlobalGenerator(0); // setting 0-pointer is not possible
+// delete gg; // this crashes inside the cmake instance
+
+ return packageFound;
+}
+
+
+// Parse the args
+void cmake::SetArgs(const std::vector<std::string>& args,
+ bool directoriesSetBefore)
+{
+ bool directoriesSet = directoriesSetBefore;
+ bool haveToolset = false;
+ bool havePlatform = false;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ std::string arg = args[i];
+ if(arg.find("-H",0) == 0)
+ {
+ directoriesSet = true;
+ std::string path = arg.substr(2);
+ path = cmSystemTools::CollapseFullPath(path.c_str());
+ cmSystemTools::ConvertToUnixSlashes(path);
+ this->SetHomeDirectory(path);
+ }
+ else if(arg.find("-S",0) == 0)
+ {
+ // There is no local generate anymore. Ignore -S option.
+ }
+ else if(arg.find("-O",0) == 0)
+ {
+ // There is no local generate anymore. Ignore -O option.
+ }
+ else if(arg.find("-B",0) == 0)
+ {
+ directoriesSet = true;
+ std::string path = arg.substr(2);
+ path = cmSystemTools::CollapseFullPath(path.c_str());
+ cmSystemTools::ConvertToUnixSlashes(path);
+ this->SetHomeOutputDirectory(path);
+ }
+ else if((i < args.size()-2) && (arg.find("--check-build-system",0) == 0))
+ {
+ this->CheckBuildSystemArgument = args[++i];
+ this->ClearBuildSystem = (atoi(args[++i].c_str()) > 0);
+ }
+ else if((i < args.size()-1) && (arg.find("--check-stamp-file",0) == 0))
+ {
+ this->CheckStampFile = args[++i];
+ }
+ else if((i < args.size()-1) && (arg.find("--check-stamp-list",0) == 0))
+ {
+ this->CheckStampList = args[++i];
+ }
+#if defined(CMAKE_HAVE_VS_GENERATORS)
+ else if((i < args.size()-1) && (arg.find("--vs-solution-file",0) == 0))
+ {
+ this->VSSolutionFile = args[++i];
+ }
+#endif
+ else if(arg.find("-V",0) == 0)
+ {
+ this->Verbose = true;
+ }
+ else if(arg.find("-D",0) == 0)
+ {
+ // skip for now
+ }
+ else if(arg.find("-U",0) == 0)
+ {
+ // skip for now
+ }
+ else if(arg.find("-C",0) == 0)
+ {
+ // skip for now
+ }
+ else if(arg.find("-P",0) == 0)
+ {
+ // skip for now
+ i++;
+ }
+ else if(arg.find("--find-package",0) == 0)
+ {
+ // skip for now
+ i++;
+ }
+ else if(arg.find("-Wno-dev",0) == 0)
+ {
+ // skip for now
+ }
+ else if(arg.find("-Wdev",0) == 0)
+ {
+ // skip for now
+ }
+ else if(arg.find("--graphviz=",0) == 0)
+ {
+ std::string path = arg.substr(strlen("--graphviz="));
+ path = cmSystemTools::CollapseFullPath(path.c_str());
+ cmSystemTools::ConvertToUnixSlashes(path);
+ this->GraphVizFile = path;
+ if ( this->GraphVizFile.empty() )
+ {
+ cmSystemTools::Error("No file specified for --graphviz");
+ }
+ }
+ else if(arg.find("--debug-trycompile",0) == 0)
+ {
+ std::cout << "debug trycompile on\n";
+ this->DebugTryCompileOn();
+ }
+ else if(arg.find("--debug-output",0) == 0)
+ {
+ std::cout << "Running with debug output on.\n";
+ this->SetDebugOutputOn(true);
+ }
+ else if(arg.find("--trace",0) == 0)
+ {
+ std::cout << "Running with trace output on.\n";
+ this->SetTrace(true);
+ }
+ else if(arg.find("--warn-uninitialized",0) == 0)
+ {
+ std::cout << "Warn about uninitialized values.\n";
+ this->SetWarnUninitialized(true);
+ }
+ else if(arg.find("--warn-unused-vars",0) == 0)
+ {
+ std::cout << "Finding unused variables.\n";
+ this->SetWarnUnused(true);
+ }
+ else if(arg.find("--no-warn-unused-cli",0) == 0)
+ {
+ std::cout << "Not searching for unused variables given on the " <<
+ "command line.\n";
+ this->SetWarnUnusedCli(false);
+ }
+ else if(arg.find("--check-system-vars",0) == 0)
+ {
+ std::cout << "Also check system files when warning about unused and " <<
+ "uninitialized variables.\n";
+ this->SetCheckSystemVars(true);
+ }
+ else if(arg.find("-A",0) == 0)
+ {
+ std::string value = arg.substr(2);
+ if(value.size() == 0)
+ {
+ ++i;
+ if(i >= args.size())
+ {
+ cmSystemTools::Error("No platform specified for -A");
+ return;
+ }
+ value = args[i];
+ }
+ if(havePlatform)
+ {
+ cmSystemTools::Error("Multiple -A options not allowed");
+ return;
+ }
+ this->GeneratorPlatform = value;
+ havePlatform = true;
+ }
+ else if(arg.find("-T",0) == 0)
+ {
+ std::string value = arg.substr(2);
+ if(value.size() == 0)
+ {
+ ++i;
+ if(i >= args.size())
+ {
+ cmSystemTools::Error("No toolset specified for -T");
+ return;
+ }
+ value = args[i];
+ }
+ if(haveToolset)
+ {
+ cmSystemTools::Error("Multiple -T options not allowed");
+ return;
+ }
+ this->GeneratorToolset = value;
+ haveToolset = true;
+ }
+ else if(arg.find("-G",0) == 0)
+ {
+ std::string value = arg.substr(2);
+ if(value.size() == 0)
+ {
+ ++i;
+ if(i >= args.size())
+ {
+ cmSystemTools::Error("No generator specified for -G");
+ return;
+ }
+ value = args[i];
+ }
+ cmGlobalGenerator* gen =
+ this->CreateGlobalGenerator(value);
+ if(!gen)
+ {
+ cmSystemTools::Error("Could not create named generator ",
+ value.c_str());
+ }
+ else
+ {
+ this->SetGlobalGenerator(gen);
+ }
+ }
+ // no option assume it is the path to the source
+ else
+ {
+ directoriesSet = true;
+ this->SetDirectoriesFromFile(arg.c_str());
+ }
+ }
+ if(!directoriesSet)
+ {
+ this->SetHomeOutputDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ this->SetStartOutputDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ this->SetHomeDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ this->SetStartDirectory
+ (cmSystemTools::GetCurrentWorkingDirectory());
+ }
+
+ this->SetStartDirectory(this->GetHomeDirectory());
+ this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
+}
+
+//----------------------------------------------------------------------------
+void cmake::SetDirectoriesFromFile(const char* arg)
+{
+ // Check if the argument refers to a CMakeCache.txt or
+ // CMakeLists.txt file.
+ std::string listPath;
+ std::string cachePath;
+ bool argIsFile = false;
+ if(cmSystemTools::FileIsDirectory(arg))
+ {
+ std::string path = cmSystemTools::CollapseFullPath(arg);
+ cmSystemTools::ConvertToUnixSlashes(path);
+ std::string cacheFile = path;
+ cacheFile += "/CMakeCache.txt";
+ std::string listFile = path;
+ listFile += "/CMakeLists.txt";
+ if(cmSystemTools::FileExists(cacheFile.c_str()))
+ {
+ cachePath = path;
+ }
+ if(cmSystemTools::FileExists(listFile.c_str()))
+ {
+ listPath = path;
+ }
+ }
+ else if(cmSystemTools::FileExists(arg))
+ {
+ argIsFile = true;
+ std::string fullPath = cmSystemTools::CollapseFullPath(arg);
+ std::string name = cmSystemTools::GetFilenameName(fullPath);
+ name = cmSystemTools::LowerCase(name);
+ if(name == "cmakecache.txt")
+ {
+ cachePath = cmSystemTools::GetFilenamePath(fullPath);
+ }
+ else if(name == "cmakelists.txt")
+ {
+ listPath = cmSystemTools::GetFilenamePath(fullPath);
+ }
+ }
+ else
+ {
+ // Specified file or directory does not exist. Try to set things
+ // up to produce a meaningful error message.
+ std::string fullPath = cmSystemTools::CollapseFullPath(arg);
+ std::string name = cmSystemTools::GetFilenameName(fullPath);
+ name = cmSystemTools::LowerCase(name);
+ if(name == "cmakecache.txt" || name == "cmakelists.txt")
+ {
+ argIsFile = true;
+ listPath = cmSystemTools::GetFilenamePath(fullPath);
+ }
+ else
+ {
+ listPath = fullPath;
+ }
+ }
+
+ // If there is a CMakeCache.txt file, use its settings.
+ if(cachePath.length() > 0)
+ {
+ cmCacheManager* cachem = this->GetCacheManager();
+ cmCacheManager::CacheIterator it = cachem->NewIterator();
+ if(cachem->LoadCache(cachePath) &&
+ it.Find("CMAKE_HOME_DIRECTORY"))
+ {
+ this->SetHomeOutputDirectory(cachePath);
+ this->SetStartOutputDirectory(cachePath);
+ this->SetHomeDirectory(it.GetValue());
+ this->SetStartDirectory(it.GetValue());
+ return;
+ }
+ }
+
+ // If there is a CMakeLists.txt file, use it as the source tree.
+ if(listPath.length() > 0)
+ {
+ this->SetHomeDirectory(listPath);
+ this->SetStartDirectory(listPath);
+
+ if(argIsFile)
+ {
+ // Source CMakeLists.txt file given. It was probably dropped
+ // onto the executable in a GUI. Default to an in-source build.
+ this->SetHomeOutputDirectory(listPath);
+ this->SetStartOutputDirectory(listPath);
+ }
+ else
+ {
+ // Source directory given on command line. Use current working
+ // directory as build tree.
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ this->SetHomeOutputDirectory(cwd);
+ this->SetStartOutputDirectory(cwd);
+ }
+ return;
+ }
+
+ // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
+ // argument. Assume it is the path to the source tree, and use the
+ // current working directory as the build tree.
+ std::string full = cmSystemTools::CollapseFullPath(arg);
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ this->SetHomeDirectory(full);
+ this->SetStartDirectory(full);
+ this->SetHomeOutputDirectory(cwd);
+ this->SetStartOutputDirectory(cwd);
+}
+
+// at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
+// cache
+int cmake::AddCMakePaths()
+{
+ // Save the value in the cache
+ this->CacheManager->AddCacheEntry
+ ("CMAKE_COMMAND", cmSystemTools::GetCMakeCommand().c_str(),
+ "Path to CMake executable.", cmCacheManager::INTERNAL);
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ this->CacheManager->AddCacheEntry
+ ("CMAKE_CTEST_COMMAND", cmSystemTools::GetCTestCommand().c_str(),
+ "Path to ctest program executable.", cmCacheManager::INTERNAL);
+ this->CacheManager->AddCacheEntry
+ ("CMAKE_CPACK_COMMAND", cmSystemTools::GetCPackCommand().c_str(),
+ "Path to cpack program executable.", cmCacheManager::INTERNAL);
+#endif
+ if(!cmSystemTools::FileExists(
+ (cmSystemTools::GetCMakeRoot()+"/Modules/CMake.cmake").c_str()))
+ {
+ // couldn't find modules
+ cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
+ "CMake has most likely not been installed correctly.\n"
+ "Modules directory not found in\n",
+ cmSystemTools::GetCMakeRoot().c_str());
+ return 0;
+ }
+ this->CacheManager->AddCacheEntry
+ ("CMAKE_ROOT", cmSystemTools::GetCMakeRoot().c_str(),
+ "Path to CMake installation.", cmCacheManager::INTERNAL);
+
+ return 1;
+}
+
+void cmake::AddExtraGenerator(const std::string& name,
+ CreateExtraGeneratorFunctionType newFunction)
+{
+ cmExternalMakefileProjectGenerator* extraGenerator = newFunction();
+ const std::vector<std::string>& supportedGlobalGenerators =
+ extraGenerator->GetSupportedGlobalGenerators();
+
+ for(std::vector<std::string>::const_iterator
+ it = supportedGlobalGenerators.begin();
+ it != supportedGlobalGenerators.end();
+ ++it )
+ {
+ std::string fullName = cmExternalMakefileProjectGenerator::
+ CreateFullGeneratorName(*it, name);
+ this->ExtraGenerators[fullName] = newFunction;
+ }
+ delete extraGenerator;
+}
+
+void cmake::AddDefaultExtraGenerators()
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ // e.g. kdevelop4 ?
+#endif
+
+ this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(),
+ &cmExtraCodeBlocksGenerator::New);
+ this->AddExtraGenerator(cmExtraCodeLiteGenerator::GetActualName(),
+ &cmExtraCodeLiteGenerator::New);
+ this->AddExtraGenerator(cmExtraSublimeTextGenerator::GetActualName(),
+ &cmExtraSublimeTextGenerator::New);
+ this->AddExtraGenerator(cmExtraKateGenerator::GetActualName(),
+ &cmExtraKateGenerator::New);
+
+#ifdef CMAKE_USE_ECLIPSE
+ this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(),
+ &cmExtraEclipseCDT4Generator::New);
+#endif
+
+#ifdef CMAKE_USE_KDEVELOP
+ this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(),
+ &cmGlobalKdevelopGenerator::New);
+ // for kdevelop also add the generator with just the name of the
+ // extra generator, since it was this way since cmake 2.2
+ this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()]
+ = &cmGlobalKdevelopGenerator::New;
+#endif
+
+#endif
+}
+
+
+//----------------------------------------------------------------------------
+void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
+{
+ for(RegisteredGeneratorsVector::const_iterator i = this->Generators.begin();
+ i != this->Generators.end(); ++i)
+ {
+ (*i)->GetGenerators(names);
+ }
+ for(RegisteredExtraGeneratorsMap::const_iterator
+ i = this->ExtraGenerators.begin();
+ i != this->ExtraGenerators.end(); ++i)
+ {
+ names.push_back(i->first);
+ }
+}
+
+cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname)
+{
+ cmExternalMakefileProjectGenerator* extraGenerator = 0;
+ std::string name = gname;
+ RegisteredExtraGeneratorsMap::const_iterator extraGenIt =
+ this->ExtraGenerators.find(name);
+ if (extraGenIt != this->ExtraGenerators.end())
+ {
+ extraGenerator = (extraGenIt->second)();
+ name = extraGenerator->GetGlobalGeneratorName(name);
+ }
+
+ cmGlobalGenerator* generator = 0;
+ for (RegisteredGeneratorsVector::const_iterator i =
+ this->Generators.begin(); i != this->Generators.end(); ++i)
+ {
+ generator = (*i)->CreateGlobalGenerator(name);
+ if (generator)
+ {
+ break;
+ }
+ }
+
+ if (generator)
+ {
+ generator->SetCMakeInstance(this);
+ generator->SetExternalMakefileProjectGenerator(extraGenerator);
+ }
+ else
+ {
+ delete extraGenerator;
+ }
+
+ return generator;
+}
+
+void cmake::SetHomeDirectory(const std::string& dir)
+{
+ this->cmHomeDirectory = dir;
+ cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory);
+}
+
+void cmake::SetHomeOutputDirectory(const std::string& lib)
+{
+ this->HomeOutputDirectory = lib;
+ cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory);
+}
+
+void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
+{
+ if(!gg)
+ {
+ cmSystemTools::Error("Error SetGlobalGenerator called with null");
+ return;
+ }
+ // delete the old generator
+ if (this->GlobalGenerator)
+ {
+ delete this->GlobalGenerator;
+ // restore the original environment variables CXX and CC
+ // Restore CC
+ std::string env = "CC=";
+ if(this->CCEnvironment.size())
+ {
+ env += this->CCEnvironment;
+ }
+ cmSystemTools::PutEnv(env.c_str());
+ env = "CXX=";
+ if(this->CXXEnvironment.size())
+ {
+ env += this->CXXEnvironment;
+ }
+ cmSystemTools::PutEnv(env.c_str());
+ }
+
+ // set the new
+ this->GlobalGenerator = gg;
+
+ // set the global flag for unix style paths on cmSystemTools as soon as
+ // the generator is set. This allows gmake to be used on windows.
+ cmSystemTools::SetForceUnixPaths
+ (this->GlobalGenerator->GetForceUnixPaths());
+
+ // Save the environment variables CXX and CC
+ const char* cxx = getenv("CXX");
+ const char* cc = getenv("CC");
+ if(cxx)
+ {
+ this->CXXEnvironment = cxx;
+ }
+ else
+ {
+ this->CXXEnvironment = "";
+ }
+ if(cc)
+ {
+ this->CCEnvironment = cc;
+ }
+ else
+ {
+ this->CCEnvironment = "";
+ }
+ // set the cmake instance just to be sure
+ gg->SetCMakeInstance(this);
+}
+
+int cmake::DoPreConfigureChecks()
+{
+ // Make sure the Start directory contains a CMakeLists.txt file.
+ std::string srcList = this->GetHomeDirectory();
+ srcList += "/CMakeLists.txt";
+ if(!cmSystemTools::FileExists(srcList.c_str()))
+ {
+ cmOStringStream err;
+ if(cmSystemTools::FileIsDirectory(this->GetHomeDirectory()))
+ {
+ err << "The source directory \"" << this->GetHomeDirectory()
+ << "\" does not appear to contain CMakeLists.txt.\n";
+ }
+ else if(cmSystemTools::FileExists(this->GetHomeDirectory()))
+ {
+ err << "The source directory \"" << this->GetHomeDirectory()
+ << "\" is a file, not a directory.\n";
+ }
+ else
+ {
+ err << "The source directory \"" << this->GetHomeDirectory()
+ << "\" does not exist.\n";
+ }
+ err << "Specify --help for usage, or press the help button on the CMake "
+ "GUI.";
+ cmSystemTools::Error(err.str().c_str());
+ return -2;
+ }
+
+ // do a sanity check on some values
+ if(this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
+ {
+ std::string cacheStart =
+ this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY");
+ cacheStart += "/CMakeLists.txt";
+ std::string currentStart = this->GetHomeDirectory();
+ currentStart += "/CMakeLists.txt";
+ if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
+ {
+ std::string message = "The source \"";
+ message += currentStart;
+ message += "\" does not match the source \"";
+ message += cacheStart;
+ message += "\" used to generate cache. ";
+ message += "Re-run cmake with a different source directory.";
+ cmSystemTools::Error(message.c_str());
+ return -2;
+ }
+ }
+ else
+ {
+ return 0;
+ }
+ return 1;
+}
+struct SaveCacheEntry
+{
+ std::string key;
+ std::string value;
+ std::string help;
+ cmCacheManager::CacheEntryType type;
+};
+
+int cmake::HandleDeleteCacheVariables(const std::string& var)
+{
+ std::vector<std::string> argsSplit;
+ cmSystemTools::ExpandListArgument(std::string(var), argsSplit, true);
+ // erase the property to avoid infinite recursion
+ this->SetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", "");
+ if(this->GetIsInTryCompile())
+ {
+ return 0;
+ }
+ cmCacheManager::CacheIterator ci = this->CacheManager->NewIterator();
+ std::vector<SaveCacheEntry> saved;
+ cmOStringStream warning;
+ warning
+ << "You have changed variables that require your cache to be deleted.\n"
+ << "Configure will be re-run and you may have to reset some variables.\n"
+ << "The following variables have changed:\n";
+ for(std::vector<std::string>::iterator i = argsSplit.begin();
+ i != argsSplit.end(); ++i)
+ {
+ SaveCacheEntry save;
+ save.key = *i;
+ warning << *i << "= ";
+ i++;
+ save.value = *i;
+ warning << *i << "\n";
+ if(ci.Find(save.key))
+ {
+ save.type = ci.GetType();
+ if(const char* help = ci.GetProperty("HELPSTRING"))
+ {
+ save.help = help;
+ }
+ }
+ saved.push_back(save);
+ }
+
+ // remove the cache
+ this->CacheManager->DeleteCache(this->GetStartOutputDirectory());
+ // load the empty cache
+ this->LoadCache();
+ // restore the changed compilers
+ for(std::vector<SaveCacheEntry>::iterator i = saved.begin();
+ i != saved.end(); ++i)
+ {
+ this->AddCacheEntry(i->key, i->value.c_str(),
+ i->help.c_str(), i->type);
+ }
+ cmSystemTools::Message(warning.str().c_str());
+ // avoid reconfigure if there were errors
+ if(!cmSystemTools::GetErrorOccuredFlag())
+ {
+ // re-run configure
+ return this->Configure();
+ }
+ return 0;
+}
+
+int cmake::Configure()
+{
+ if(this->DoSuppressDevWarnings)
+ {
+ if(this->SuppressDevWarnings)
+ {
+ this->CacheManager->
+ AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
+ "Suppress Warnings that are meant for"
+ " the author of the CMakeLists.txt files.",
+ cmCacheManager::INTERNAL);
+ }
+ else
+ {
+ this->CacheManager->
+ AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
+ "Suppress Warnings that are meant for"
+ " the author of the CMakeLists.txt files.",
+ cmCacheManager::INTERNAL);
+ }
+ }
+ int ret = this->ActualConfigure();
+ const char* delCacheVars =
+ this->GetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
+ if(delCacheVars && delCacheVars[0] != 0)
+ {
+ return this->HandleDeleteCacheVariables(delCacheVars);
+ }
+ return ret;
+
+}
+
+int cmake::ActualConfigure()
+{
+ // Construct right now our path conversion table before it's too late:
+ this->UpdateConversionPathTable();
+ this->CleanupCommandsAndMacros();
+
+ int res = 0;
+ if ( this->GetWorkingMode() == NORMAL_MODE )
+ {
+ res = this->DoPreConfigureChecks();
+ }
+ if ( res < 0 )
+ {
+ return -2;
+ }
+ if ( !res )
+ {
+ this->CacheManager->AddCacheEntry
+ ("CMAKE_HOME_DIRECTORY",
+ this->GetHomeDirectory(),
+ "Start directory with the top level CMakeLists.txt file for this "
+ "project",
+ cmCacheManager::INTERNAL);
+ }
+
+ // no generator specified on the command line
+ if(!this->GlobalGenerator)
+ {
+ const char* genName =
+ this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
+ const char* extraGenName =
+ this->CacheManager->GetCacheValue("CMAKE_EXTRA_GENERATOR");
+ if(genName)
+ {
+ std::string fullName = cmExternalMakefileProjectGenerator::
+ CreateFullGeneratorName(genName,
+ extraGenName ? extraGenName : "");
+ this->GlobalGenerator = this->CreateGlobalGenerator(fullName);
+ }
+ if(this->GlobalGenerator)
+ {
+ // set the global flag for unix style paths on cmSystemTools as
+ // soon as the generator is set. This allows gmake to be used
+ // on windows.
+ cmSystemTools::SetForceUnixPaths
+ (this->GlobalGenerator->GetForceUnixPaths());
+ }
+ else
+ {
+#if defined(__BORLANDC__) && defined(_WIN32)
+ this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator);
+#elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
+ std::string installedCompiler;
+ // Try to find the newest VS installed on the computer and
+ // use that as a default if -G is not specified
+ const std::string vsregBase =
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\";
+ std::vector<std::string> vsVerions;
+ vsVerions.push_back("VisualStudio\\");
+ vsVerions.push_back("VCExpress\\");
+ vsVerions.push_back("WDExpress\\");
+ struct VSRegistryEntryName
+ {
+ const char* MSVersion;
+ const char* GeneratorName;
+ };
+ VSRegistryEntryName version[] = {
+ {"6.0", "Visual Studio 6"},
+ {"7.0", "Visual Studio 7"},
+ {"7.1", "Visual Studio 7 .NET 2003"},
+ {"8.0", "Visual Studio 8 2005"},
+ {"9.0", "Visual Studio 9 2008"},
+ {"10.0", "Visual Studio 10 2010"},
+ {"11.0", "Visual Studio 11 2012"},
+ {"12.0", "Visual Studio 12 2013"},
+ {"14.0", "Visual Studio 14"},
+ {0, 0}};
+ for(int i=0; version[i].MSVersion != 0; i++)
+ {
+ for(size_t b=0; b < vsVerions.size(); b++)
+ {
+ std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion;
+ reg += ";InstallDir]";
+ cmSystemTools::ExpandRegistryValues(reg,
+ cmSystemTools::KeyWOW64_32);
+ if (!(reg == "/registry"))
+ {
+ installedCompiler = version[i].GeneratorName;
+ break;
+ }
+ }
+ }
+ cmGlobalGenerator* gen
+ = this->CreateGlobalGenerator(installedCompiler.c_str());
+ if(!gen)
+ {
+ gen = new cmGlobalNMakeMakefileGenerator;
+ }
+ this->SetGlobalGenerator(gen);
+ std::cout << "-- Building for: " << gen->GetName() << "\n";
+#else
+ this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3);
+#endif
+ }
+ if(!this->GlobalGenerator)
+ {
+ cmSystemTools::Error("Could not create generator");
+ return -1;
+ }
+ }
+
+ const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
+ if(genName)
+ {
+ if(!this->GlobalGenerator->MatchesGeneratorName(genName))
+ {
+ std::string message = "Error: generator : ";
+ message += this->GlobalGenerator->GetName();
+ message += "\nDoes not match the generator used previously: ";
+ message += genName;
+ message +=
+ "\nEither remove the CMakeCache.txt file and CMakeFiles "
+ "directory or choose a different binary directory.";
+ cmSystemTools::Error(message.c_str());
+ return -2;
+ }
+ }
+ if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR"))
+ {
+ this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
+ this->GlobalGenerator->GetName().c_str(),
+ "Name of generator.",
+ cmCacheManager::INTERNAL);
+ this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
+ this->GlobalGenerator->GetExtraGeneratorName().c_str(),
+ "Name of external makefile project generator.",
+ cmCacheManager::INTERNAL);
+ }
+
+ if(const char* platformName =
+ this->CacheManager->GetCacheValue("CMAKE_GENERATOR_PLATFORM"))
+ {
+ if(this->GeneratorPlatform.empty())
+ {
+ this->GeneratorPlatform = platformName;
+ }
+ else if(this->GeneratorPlatform != platformName)
+ {
+ std::string message = "Error: generator platform: ";
+ message += this->GeneratorPlatform;
+ message += "\nDoes not match the platform used previously: ";
+ message += platformName;
+ message +=
+ "\nEither remove the CMakeCache.txt file and CMakeFiles "
+ "directory or choose a different binary directory.";
+ cmSystemTools::Error(message.c_str());
+ return -2;
+ }
+ }
+ else
+ {
+ this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_PLATFORM",
+ this->GeneratorPlatform.c_str(),
+ "Name of generator platform.",
+ cmCacheManager::INTERNAL);
+ }
+
+ if(const char* tsName =
+ this->CacheManager->GetCacheValue("CMAKE_GENERATOR_TOOLSET"))
+ {
+ if(this->GeneratorToolset.empty())
+ {
+ this->GeneratorToolset = tsName;
+ }
+ else if(this->GeneratorToolset != tsName)
+ {
+ std::string message = "Error: generator toolset: ";
+ message += this->GeneratorToolset;
+ message += "\nDoes not match the toolset used previously: ";
+ message += tsName;
+ message +=
+ "\nEither remove the CMakeCache.txt file and CMakeFiles "
+ "directory or choose a different binary directory.";
+ cmSystemTools::Error(message.c_str());
+ return -2;
+ }
+ }
+ else
+ {
+ this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_TOOLSET",
+ this->GeneratorToolset.c_str(),
+ "Name of generator toolset.",
+ cmCacheManager::INTERNAL);
+ }
+
+ // reset any system configuration information, except for when we are
+ // InTryCompile. With TryCompile the system info is taken from the parent's
+ // info to save time
+ if (!this->InTryCompile)
+ {
+ this->GlobalGenerator->ClearEnabledLanguages();
+ }
+
+ // Truncate log files
+ if (!this->InTryCompile)
+ {
+ this->TruncateOutputLog("CMakeOutput.log");
+ this->TruncateOutputLog("CMakeError.log");
+ }
+
+ // actually do the configure
+ this->GlobalGenerator->Configure();
+ // Before saving the cache
+ // if the project did not define one of the entries below, add them now
+ // so users can edit the values in the cache:
+
+ // We used to always present LIBRARY_OUTPUT_PATH and
+ // EXECUTABLE_OUTPUT_PATH. They are now documented as old-style and
+ // should no longer be used. Therefore we present them only if the
+ // project requires compatibility with CMake 2.4. We detect this
+ // here by looking for the old CMAKE_BACKWARDS_COMPATIBILITY
+ // variable created when CMP0001 is not set to NEW.
+ if(this->GetCacheManager()->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
+ {
+ if(!this->CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
+ {
+ this->CacheManager->AddCacheEntry
+ ("LIBRARY_OUTPUT_PATH", "",
+ "Single output directory for building all libraries.",
+ cmCacheManager::PATH);
+ }
+ if(!this->CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
+ {
+ this->CacheManager->AddCacheEntry
+ ("EXECUTABLE_OUTPUT_PATH", "",
+ "Single output directory for building all executables.",
+ cmCacheManager::PATH);
+ }
+ }
+ if(!this->CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS"))
+ {
+ this->CacheManager->AddCacheEntry
+ ("CMAKE_USE_RELATIVE_PATHS", "OFF",
+ "If true, cmake will use relative paths in makefiles and projects.",
+ cmCacheManager::BOOL);
+ cmCacheManager::CacheIterator it =
+ this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS");
+ if ( !it.PropertyExists("ADVANCED") )
+ {
+ it.SetProperty("ADVANCED", "1");
+ }
+ }
+
+ if(cmSystemTools::GetFatalErrorOccured() &&
+ (!this->CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
+ cmSystemTools::IsOff(this->CacheManager->
+ GetCacheValue("CMAKE_MAKE_PROGRAM"))))
+ {
+ // We must have a bad generator selection. Wipe the cache entry so the
+ // user can select another.
+ this->CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
+ this->CacheManager->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR");
+ }
+
+ cmMakefile* mf=this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
+ if (mf->IsOn("CTEST_USE_LAUNCHERS")
+ && !this->GetProperty("RULE_LAUNCH_COMPILE", cmProperty::GLOBAL))
+ {
+ cmSystemTools::Error("CTEST_USE_LAUNCHERS is enabled, but the "
+ "RULE_LAUNCH_COMPILE global property is not defined.\n"
+ "Did you forget to include(CTest) in the toplevel "
+ "CMakeLists.txt ?");
+ }
+
+ // only save the cache if there were no fatal errors
+ if ( this->GetWorkingMode() == NORMAL_MODE )
+ {
+ this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
+ }
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ return -1;
+ }
+ return 0;
+}
+
+void cmake::PreLoadCMakeFiles()
+{
+ std::vector<std::string> args;
+ std::string pre_load = this->GetHomeDirectory();
+ if ( pre_load.size() > 0 )
+ {
+ pre_load += "/PreLoad.cmake";
+ if ( cmSystemTools::FileExists(pre_load.c_str()) )
+ {
+ this->ReadListFile(args, pre_load.c_str());
+ }
+ }
+ pre_load = this->GetHomeOutputDirectory();
+ if ( pre_load.size() > 0 )
+ {
+ pre_load += "/PreLoad.cmake";
+ if ( cmSystemTools::FileExists(pre_load.c_str()) )
+ {
+ this->ReadListFile(args, pre_load.c_str());
+ }
+ }
+}
+
+// handle a command line invocation
+int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
+{
+ // Process the arguments
+ this->SetArgs(args);
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ return -1;
+ }
+
+ // If we are given a stamp list file check if it is really out of date.
+ if(!this->CheckStampList.empty() &&
+ cmakeCheckStampList(this->CheckStampList.c_str()))
+ {
+ return 0;
+ }
+
+ // If we are given a stamp file check if it is really out of date.
+ if(!this->CheckStampFile.empty() &&
+ cmakeCheckStampFile(this->CheckStampFile.c_str()))
+ {
+ return 0;
+ }
+
+ if ( this->GetWorkingMode() == NORMAL_MODE )
+ {
+ // load the cache
+ if(this->LoadCache() < 0)
+ {
+ cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
+ return -1;
+ }
+ }
+ else
+ {
+ this->AddCMakePaths();
+ }
+ // Add any cache args
+ if ( !this->SetCacheArgs(args) )
+ {
+ cmSystemTools::Error("Problem processing arguments. Aborting.\n");
+ return -1;
+ }
+
+ // In script mode we terminate after running the script.
+ if(this->GetWorkingMode() != NORMAL_MODE)
+ {
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ // If MAKEFLAGS are given in the environment, remove the environment
+ // variable. This will prevent try-compile from succeeding when it
+ // should fail (if "-i" is an option). We cannot simply test
+ // whether "-i" is given and remove it because some make programs
+ // encode the MAKEFLAGS variable in a strange way.
+ if(getenv("MAKEFLAGS"))
+ {
+ cmSystemTools::PutEnv("MAKEFLAGS=");
+ }
+
+ this->PreLoadCMakeFiles();
+
+ if ( noconfigure )
+ {
+ return 0;
+ }
+
+ // now run the global generate
+ // Check the state of the build system to see if we need to regenerate.
+ if(!this->CheckBuildSystem())
+ {
+ return 0;
+ }
+
+ // If we are doing global generate, we better set start and start
+ // output directory to the root of the project.
+ std::string oldstartdir = this->GetStartDirectory();
+ std::string oldstartoutputdir = this->GetStartOutputDirectory();
+ this->SetStartDirectory(this->GetHomeDirectory());
+ this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
+ int ret = this->Configure();
+ if (ret || this->GetWorkingMode() != NORMAL_MODE)
+ {
+#if defined(CMAKE_HAVE_VS_GENERATORS)
+ if(!this->VSSolutionFile.empty() && this->GlobalGenerator)
+ {
+ // CMake is running to regenerate a Visual Studio build tree
+ // during a build from the VS IDE. The build files cannot be
+ // regenerated, so we should stop the build.
+ cmSystemTools::Message(
+ "CMake Configure step failed. "
+ "Build files cannot be regenerated correctly. "
+ "Attempting to stop IDE build.");
+ cmGlobalVisualStudioGenerator* gg =
+ static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
+ gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
+ this->VSSolutionFile.c_str());
+ }
+#endif
+ return ret;
+ }
+ ret = this->Generate();
+ std::string message = "Build files have been written to: ";
+ message += this->GetHomeOutputDirectory();
+ this->UpdateProgress(message.c_str(), -1);
+ if(ret)
+ {
+ return ret;
+ }
+ this->SetStartDirectory(oldstartdir);
+ this->SetStartOutputDirectory(oldstartoutputdir);
+
+ return ret;
+}
+
+int cmake::Generate()
+{
+ if(!this->GlobalGenerator)
+ {
+ return -1;
+ }
+ this->GlobalGenerator->DoGenerate();
+ if ( !this->GraphVizFile.empty() )
+ {
+ std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
+ this->GenerateGraphViz(this->GraphVizFile.c_str());
+ }
+ if(this->WarnUnusedCli)
+ {
+ this->RunCheckForUnusedVariables();
+ }
+ if(cmSystemTools::GetErrorOccuredFlag())
+ {
+ return -1;
+ }
+ // Save the cache again after a successful Generate so that any internal
+ // variables created during Generate are saved. (Specifically target GUIDs
+ // for the Visual Studio and Xcode generators.)
+ if ( this->GetWorkingMode() == NORMAL_MODE )
+ {
+ this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
+ }
+ return 0;
+}
+
+void cmake::AddCacheEntry(const std::string& key, const char* value,
+ const char* helpString,
+ int type)
+{
+ this->CacheManager->AddCacheEntry(key, value,
+ helpString,
+ cmCacheManager::CacheEntryType(type));
+}
+
+const char* cmake::GetCacheDefinition(const std::string& name) const
+{
+ return this->CacheManager->GetCacheValue(name);
+}
+
+void cmake::AddDefaultCommands()
+{
+ std::list<cmCommand*> commands;
+ GetBootstrapCommands1(commands);
+ GetBootstrapCommands2(commands);
+ GetPredefinedCommands(commands);
+ for(std::list<cmCommand*>::iterator i = commands.begin();
+ i != commands.end(); ++i)
+ {
+ this->AddCommand(*i);
+ }
+}
+
+void cmake::AddDefaultGenerators()
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# if !defined(CMAKE_BOOT_MINGW)
+ this->Generators.push_back(
+ cmGlobalVisualStudio6Generator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalVisualStudio7Generator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalVisualStudio10Generator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalVisualStudio11Generator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalVisualStudio12Generator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalVisualStudio14Generator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalVisualStudio71Generator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalVisualStudio8Generator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalVisualStudio9Generator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalBorlandMakefileGenerator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalNMakeMakefileGenerator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalJOMMakefileGenerator::NewFactory());
+# endif
+ this->Generators.push_back(
+ cmGlobalMSYSMakefileGenerator::NewFactory());
+ this->Generators.push_back(
+ cmGlobalMinGWMakefileGenerator::NewFactory());
+#endif
+ this->Generators.push_back(
+ cmGlobalUnixMakefileGenerator3::NewFactory());
+ this->Generators.push_back(
+ cmGlobalNinjaGenerator::NewFactory());
+#if defined(CMAKE_USE_WMAKE)
+ this->Generators.push_back(
+ cmGlobalWatcomWMakeGenerator::NewFactory());
+#endif
+#ifdef CMAKE_USE_XCODE
+ this->Generators.push_back(
+ cmGlobalXCodeGenerator::NewFactory());
+#endif
+}
+
+int cmake::LoadCache()
+{
+ // could we not read the cache
+ if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory()))
+ {
+ // if it does exist, but isn't readable then warn the user
+ std::string cacheFile = this->GetHomeOutputDirectory();
+ cacheFile += "/CMakeCache.txt";
+ if(cmSystemTools::FileExists(cacheFile.c_str()))
+ {
+ cmSystemTools::Error(
+ "There is a CMakeCache.txt file for the current binary tree but "
+ "cmake does not have permission to read it. Please check the "
+ "permissions of the directory you are trying to run CMake on.");
+ return -1;
+ }
+ }
+
+ // setup CMAKE_ROOT and CMAKE_COMMAND
+ if(!this->AddCMakePaths())
+ {
+ return -3;
+ }
+ return 0;
+}
+
+void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
+{
+ this->ProgressCallback = f;
+ this->ProgressCallbackClientData = cd;
+}
+
+void cmake::UpdateProgress(const char *msg, float prog)
+{
+ if(this->ProgressCallback && !this->InTryCompile)
+ {
+ (*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
+ return;
+ }
+}
+
+void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
+{
+ for(RegisteredGeneratorsVector::const_iterator i =
+ this->Generators.begin(); i != this->Generators.end(); ++i)
+ {
+ cmDocumentationEntry e;
+ (*i)->GetDocumentation(e);
+ v.push_back(e);
+ }
+ for(RegisteredExtraGeneratorsMap::const_iterator i =
+ this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
+ {
+ cmDocumentationEntry e;
+ cmExternalMakefileProjectGenerator* generator = (i->second)();
+ generator->GetDocumentation(e, i->first);
+ e.Name = i->first;
+ delete generator;
+ v.push_back(e);
+ }
+}
+
+void cmake::UpdateConversionPathTable()
+{
+ // Update the path conversion table with any specified file:
+ const char* tablepath =
+ this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE");
+
+ if(tablepath)
+ {
+ cmsys::ifstream table( tablepath );
+ if(!table)
+ {
+ cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath,
+ ". CMake can not open file.");
+ cmSystemTools::ReportLastSystemError("CMake can not open file.");
+ }
+ else
+ {
+ std::string a, b;
+ while(!table.eof())
+ {
+ // two entries per line
+ table >> a; table >> b;
+ cmSystemTools::AddTranslationPath( a.c_str(), b.c_str());
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+int cmake::CheckBuildSystem()
+{
+ // We do not need to rerun CMake. Check dependency integrity. Use
+ // the make system's VERBOSE environment variable to enable verbose
+ // output. This can be skipped by setting CMAKE_NO_VERBOSE (which is set
+ // by the Eclipse and KDevelop generators).
+ bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
+ && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
+
+ // This method will check the integrity of the build system if the
+ // option was given on the command line. It reads the given file to
+ // determine whether CMake should rerun.
+
+ // If no file is provided for the check, we have to rerun.
+ if(this->CheckBuildSystemArgument.size() == 0)
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Re-run cmake no build system arguments\n";
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ return 1;
+ }
+
+ // If the file provided does not exist, we have to rerun.
+ if(!cmSystemTools::FileExists(this->CheckBuildSystemArgument.c_str()))
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Re-run cmake missing file: "
+ << this->CheckBuildSystemArgument << "\n";
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ return 1;
+ }
+
+ // Read the rerun check file and use it to decide whether to do the
+ // global generate.
+ cmake cm;
+ cmGlobalGenerator gg;
+ gg.SetCMakeInstance(&cm);
+ cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
+ cmMakefile* mf = lg->GetMakefile();
+ if(!mf->ReadListFile(0, this->CheckBuildSystemArgument.c_str()) ||
+ cmSystemTools::GetErrorOccuredFlag())
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Re-run cmake error reading : "
+ << this->CheckBuildSystemArgument << "\n";
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ // There was an error reading the file. Just rerun.
+ return 1;
+ }
+
+ if(this->ClearBuildSystem)
+ {
+ // Get the generator used for this build system.
+ const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
+ if(!genName || genName[0] == '\0')
+ {
+ genName = "Unix Makefiles";
+ }
+
+ // Create the generator and use it to clear the dependencies.
+ cmsys::auto_ptr<cmGlobalGenerator>
+ ggd(this->CreateGlobalGenerator(genName));
+ if(ggd.get())
+ {
+ cmsys::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
+ lgd->ClearDependencies(mf, verbose);
+ }
+ }
+
+ // If any byproduct of makefile generation is missing we must re-run.
+ std::vector<std::string> products;
+ if(const char* productStr = mf->GetDefinition("CMAKE_MAKEFILE_PRODUCTS"))
+ {
+ cmSystemTools::ExpandListArgument(productStr, products);
+ }
+ for(std::vector<std::string>::const_iterator pi = products.begin();
+ pi != products.end(); ++pi)
+ {
+ if(!(cmSystemTools::FileExists(pi->c_str()) ||
+ cmSystemTools::FileIsSymlink(pi->c_str())))
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Re-run cmake, missing byproduct: " << *pi << "\n";
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ return 1;
+ }
+ }
+
+ // Get the set of dependencies and outputs.
+ std::vector<std::string> depends;
+ std::vector<std::string> outputs;
+ const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS");
+ const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
+ if(dependsStr && outputsStr)
+ {
+ cmSystemTools::ExpandListArgument(dependsStr, depends);
+ cmSystemTools::ExpandListArgument(outputsStr, outputs);
+ }
+ if(depends.empty() || outputs.empty())
+ {
+ // Not enough information was provided to do the test. Just rerun.
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
+ "or CMAKE_MAKEFILE_OUTPUTS :\n";
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ return 1;
+ }
+
+ // Find the newest dependency.
+ std::vector<std::string>::iterator dep = depends.begin();
+ std::string dep_newest = *dep++;
+ for(;dep != depends.end(); ++dep)
+ {
+ int result = 0;
+ if(this->FileComparison->FileTimeCompare(dep_newest.c_str(),
+ dep->c_str(), &result))
+ {
+ if(result < 0)
+ {
+ dep_newest = *dep;
+ }
+ }
+ else
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Re-run cmake: build system dependency is missing\n";
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ return 1;
+ }
+ }
+
+ // Find the oldest output.
+ std::vector<std::string>::iterator out = outputs.begin();
+ std::string out_oldest = *out++;
+ for(;out != outputs.end(); ++out)
+ {
+ int result = 0;
+ if(this->FileComparison->FileTimeCompare(out_oldest.c_str(),
+ out->c_str(), &result))
+ {
+ if(result > 0)
+ {
+ out_oldest = *out;
+ }
+ }
+ else
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Re-run cmake: build system output is missing\n";
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ return 1;
+ }
+ }
+
+ // If any output is older than any dependency then rerun.
+ {
+ int result = 0;
+ if(!this->FileComparison->FileTimeCompare(out_oldest.c_str(),
+ dep_newest.c_str(),
+ &result) ||
+ result < 0)
+ {
+ if(verbose)
+ {
+ cmOStringStream msg;
+ msg << "Re-run cmake file: " << out_oldest
+ << " older than: " << dep_newest << "\n";
+ cmSystemTools::Stdout(msg.str().c_str());
+ }
+ return 1;
+ }
+ }
+
+ // No need to rerun.
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+void cmake::TruncateOutputLog(const char* fname)
+{
+ std::string fullPath = this->GetHomeOutputDirectory();
+ fullPath += "/";
+ fullPath += fname;
+ struct stat st;
+ if ( ::stat(fullPath.c_str(), &st) )
+ {
+ return;
+ }
+ if ( !this->CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") )
+ {
+ cmSystemTools::RemoveFile(fullPath.c_str());
+ return;
+ }
+ off_t fsize = st.st_size;
+ const off_t maxFileSize = 50 * 1024;
+ if ( fsize < maxFileSize )
+ {
+ //TODO: truncate file
+ return;
+ }
+}
+
+inline std::string removeQuotes(const std::string& s)
+{
+ if(s[0] == '\"' && s[s.size()-1] == '\"')
+ {
+ return s.substr(1, s.size()-2);
+ }
+ return s;
+}
+
+void cmake::MarkCliAsUsed(const std::string& variable)
+{
+ this->UsedCliVariables[variable] = true;
+}
+
+void cmake::GenerateGraphViz(const char* fileName) const
+{
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmsys::auto_ptr<cmGraphVizWriter> gvWriter(
+ new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators()));
+
+ std::string settingsFile = this->GetHomeOutputDirectory();
+ settingsFile += "/CMakeGraphVizOptions.cmake";
+ std::string fallbackSettingsFile = this->GetHomeDirectory();
+ fallbackSettingsFile += "/CMakeGraphVizOptions.cmake";
+
+ gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str());
+
+ gvWriter->WritePerTargetFiles(fileName);
+ gvWriter->WriteTargetDependersFiles(fileName);
+ gvWriter->WriteGlobalFile(fileName);
+
+#endif
+}
+
+void cmake::DefineProperty(const std::string& name,
+ cmProperty::ScopeType scope,
+ const char *ShortDescription,
+ const char *FullDescription,
+ bool chained)
+{
+ this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription,
+ FullDescription,
+ chained);
+}
+
+cmPropertyDefinition *cmake
+::GetPropertyDefinition(const std::string& name,
+ cmProperty::ScopeType scope)
+{
+ if (this->IsPropertyDefined(name,scope))
+ {
+ return &(this->PropertyDefinitions[scope][name]);
+ }
+ return 0;
+}
+
+bool cmake::IsPropertyDefined(const std::string& name,
+ cmProperty::ScopeType scope)
+{
+ return this->PropertyDefinitions[scope].IsPropertyDefined(name);
+}
+
+bool cmake::IsPropertyChained(const std::string& name,
+ cmProperty::ScopeType scope)
+{
+ return this->PropertyDefinitions[scope].IsPropertyChained(name);
+}
+
+void cmake::SetProperty(const std::string& prop, const char* value)
+{
+ // Special hook to invalidate cached value.
+ if(prop == "DEBUG_CONFIGURATIONS")
+ {
+ this->DebugConfigs.clear();
+ }
+
+ this->Properties.SetProperty(prop, value, cmProperty::GLOBAL);
+}
+
+void cmake::AppendProperty(const std::string& prop,
+ const char* value, bool asString)
+{
+ // Special hook to invalidate cached value.
+ if(prop == "DEBUG_CONFIGURATIONS")
+ {
+ this->DebugConfigs.clear();
+ }
+
+ this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL, asString);
+}
+
+const char *cmake::GetProperty(const std::string& prop)
+{
+ return this->GetProperty(prop, cmProperty::GLOBAL);
+}
+
+const char *cmake::GetProperty(const std::string& prop,
+ cmProperty::ScopeType scope)
+{
+ bool chain = false;
+
+ // watch for special properties
+ std::string output = "";
+ if ( prop == "CACHE_VARIABLES" )
+ {
+ cmCacheManager::CacheIterator cit =
+ this->GetCacheManager()->GetCacheIterator();
+ for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
+ {
+ if ( output.size() )
+ {
+ output += ";";
+ }
+ output += cit.GetName();
+ }
+ this->SetProperty("CACHE_VARIABLES", output.c_str());
+ }
+ else if ( prop == "COMMANDS" )
+ {
+ cmake::RegisteredCommandsMap::iterator cmds
+ = this->GetCommands()->begin();
+ for (unsigned int cc=0 ; cmds != this->GetCommands()->end(); ++ cmds )
+ {
+ if ( cc > 0 )
+ {
+ output += ";";
+ }
+ output += cmds->first.c_str();
+ cc++;
+ }
+ this->SetProperty("COMMANDS",output.c_str());
+ }
+ else if ( prop == "IN_TRY_COMPILE" )
+ {
+ this->SetProperty("IN_TRY_COMPILE",
+ this->GetIsInTryCompile()? "1":"0");
+ }
+ else if ( prop == "ENABLED_LANGUAGES" )
+ {
+ std::string lang;
+ if(this->GlobalGenerator)
+ {
+ std::vector<std::string> enLangs;
+ this->GlobalGenerator->GetEnabledLanguages(enLangs);
+ const char* sep = "";
+ for(std::vector<std::string>::iterator i = enLangs.begin();
+ i != enLangs.end(); ++i)
+ {
+ lang += sep;
+ sep = ";";
+ lang += *i;
+ }
+ }
+ this->SetProperty("ENABLED_LANGUAGES", lang.c_str());
+ }
+#define STRING_LIST_ELEMENT(F) ";" #F
+ if (prop == "CMAKE_C_KNOWN_FEATURES")
+ {
+ return FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT) + 1;
+ }
+ if (prop == "CMAKE_CXX_KNOWN_FEATURES")
+ {
+ return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
+ }
+#undef STRING_LIST_ELEMENT
+ return this->Properties.GetPropertyValue(prop, scope, chain);
+}
+
+bool cmake::GetPropertyAsBool(const std::string& prop)
+{
+ return cmSystemTools::IsOn(this->GetProperty(prop));
+}
+
+cmInstalledFile *cmake::GetOrCreateInstalledFile(
+ cmMakefile* mf, const std::string& name)
+{
+ std::map<std::string, cmInstalledFile>::iterator i =
+ this->InstalledFiles.find(name);
+
+ if(i != this->InstalledFiles.end())
+ {
+ cmInstalledFile &file = i->second;
+ return &file;
+ }
+ else
+ {
+ cmInstalledFile &file = this->InstalledFiles[name];
+ file.SetName(mf, name);
+ return &file;
+ }
+}
+
+cmInstalledFile const* cmake::GetInstalledFile(const std::string& name) const
+{
+ std::map<std::string, cmInstalledFile>::const_iterator i =
+ this->InstalledFiles.find(name);
+
+ if(i != this->InstalledFiles.end())
+ {
+ cmInstalledFile const& file = i->second;
+ return &file;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+int cmake::GetSystemInformation(std::vector<std::string>& args)
+{
+ // so create the directory
+ std::string resultFile;
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ std::string destPath = cwd + "/__cmake_systeminformation";
+ cmSystemTools::RemoveADirectory(destPath.c_str());
+ if (!cmSystemTools::MakeDirectory(destPath.c_str()))
+ {
+ std::cerr << "Error: --system-information must be run from a "
+ "writable directory!\n";
+ return 1;
+ }
+
+ // process the arguments
+ bool writeToStdout = true;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ std::string arg = args[i];
+ if(arg.find("-V",0) == 0)
+ {
+ this->Verbose = true;
+ }
+ else if(arg.find("-G",0) == 0)
+ {
+ std::string value = arg.substr(2);
+ if(value.size() == 0)
+ {
+ ++i;
+ if(i >= args.size())
+ {
+ cmSystemTools::Error("No generator specified for -G");
+ return -1;
+ }
+ value = args[i];
+ }
+ cmGlobalGenerator* gen =
+ this->CreateGlobalGenerator(value);
+ if(!gen)
+ {
+ cmSystemTools::Error("Could not create named generator ",
+ value.c_str());
+ }
+ else
+ {
+ this->SetGlobalGenerator(gen);
+ }
+ }
+ // no option assume it is the output file
+ else
+ {
+ if (!cmSystemTools::FileIsFullPath(arg.c_str()))
+ {
+ resultFile = cwd;
+ resultFile += "/";
+ }
+ resultFile += arg;
+ writeToStdout = false;
+ }
+ }
+
+
+ // we have to find the module directory, so we can copy the files
+ this->AddCMakePaths();
+ std::string modulesPath =
+ this->CacheManager->GetCacheValue("CMAKE_ROOT");
+ modulesPath += "/Modules";
+ std::string inFile = modulesPath;
+ inFile += "/SystemInformation.cmake";
+ std::string outFile = destPath;
+ outFile += "/CMakeLists.txt";
+
+ // Copy file
+ if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
+ {
+ std::cerr << "Error copying file \"" << inFile
+ << "\" to \"" << outFile << "\".\n";
+ return 1;
+ }
+
+ // do we write to a file or to stdout?
+ if (resultFile.size() == 0)
+ {
+ resultFile = cwd;
+ resultFile += "/__cmake_systeminformation/results.txt";
+ }
+
+ // now run cmake on the CMakeLists file
+ cmSystemTools::ChangeDirectory(destPath.c_str());
+ std::vector<std::string> args2;
+ args2.push_back(args[0]);
+ args2.push_back(destPath);
+ std::string resultArg = "-DRESULT_FILE=";
+ resultArg += resultFile;
+ args2.push_back(resultArg);
+ int res = this->Run(args2, false);
+
+ if (res != 0)
+ {
+ std::cerr << "Error: --system-information failed on internal CMake!\n";
+ return res;
+ }
+
+ // change back to the original directory
+ cmSystemTools::ChangeDirectory(cwd.c_str());
+
+ // echo results to stdout if needed
+ if (writeToStdout)
+ {
+ FILE* fin = cmsys::SystemTools::Fopen(resultFile.c_str(), "r");
+ if(fin)
+ {
+ const int bufferSize = 4096;
+ char buffer[bufferSize];
+ size_t n;
+ while((n = fread(buffer, 1, bufferSize, fin)) > 0)
+ {
+ for(char* c = buffer; c < buffer+n; ++c)
+ {
+ putc(*c, stdout);
+ }
+ fflush(stdout);
+ }
+ fclose(fin);
+ }
+ }
+
+ // clean up the directory
+ cmSystemTools::RemoveADirectory(destPath.c_str());
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+static bool cmakeCheckStampFile(const char* stampName)
+{
+ // The stamp file does not exist. Use the stamp dependencies to
+ // determine whether it is really out of date. This works in
+ // conjunction with cmLocalVisualStudio7Generator to avoid
+ // repeatedly re-running CMake when the user rebuilds the entire
+ // solution.
+ std::string stampDepends = stampName;
+ stampDepends += ".depend";
+#if defined(_WIN32) || defined(__CYGWIN__)
+ cmsys::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
+#else
+ cmsys::ifstream fin(stampDepends.c_str(), std::ios::in);
+#endif
+ if(!fin)
+ {
+ // The stamp dependencies file cannot be read. Just assume the
+ // build system is really out of date.
+ std::cout << "CMake is re-running because " << stampName
+ << " dependency file is missing.\n";
+ return false;
+ }
+
+ // Compare the stamp dependencies against the dependency file itself.
+ cmFileTimeComparison ftc;
+ std::string dep;
+ while(cmSystemTools::GetLineFromStream(fin, dep))
+ {
+ int result;
+ if(dep.length() >= 1 && dep[0] != '#' &&
+ (!ftc.FileTimeCompare(stampDepends.c_str(), dep.c_str(), &result)
+ || result < 0))
+ {
+ // The stamp depends file is older than this dependency. The
+ // build system is really out of date.
+ std::cout << "CMake is re-running because " << stampName
+ << " is out-of-date.\n";
+ std::cout << " the file '" << dep << "'\n";
+ std::cout << " is newer than '" << stampDepends << "'\n";
+ std::cout << " result='" << result << "'\n";
+ return false;
+ }
+ }
+
+ // The build system is up to date. The stamp file has been removed
+ // by the VS IDE due to a "rebuild" request. Restore it atomically.
+ cmOStringStream stampTempStream;
+ stampTempStream << stampName << ".tmp" << cmSystemTools::RandomSeed();
+ std::string stampTempString = stampTempStream.str();
+ const char* stampTemp = stampTempString.c_str();
+ {
+ // TODO: Teach cmGeneratedFileStream to use a random temp file (with
+ // multiple tries in unlikely case of conflict) and use that here.
+ cmsys::ofstream stamp(stampTemp);
+ stamp << "# CMake generation timestamp file for this directory.\n";
+ }
+ if(cmSystemTools::RenameFile(stampTemp, stampName))
+ {
+ // Notify the user why CMake is not re-running. It is safe to
+ // just print to stdout here because this code is only reachable
+ // through an undocumented flag used by the VS generator.
+ std::cout << "CMake does not need to re-run because "
+ << stampName << " is up-to-date.\n";
+ return true;
+ }
+ else
+ {
+ cmSystemTools::RemoveFile(stampTemp);
+ cmSystemTools::Error("Cannot restore timestamp ", stampName);
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+static bool cmakeCheckStampList(const char* stampList)
+{
+ // If the stamp list does not exist CMake must rerun to generate it.
+ if(!cmSystemTools::FileExists(stampList))
+ {
+ std::cout << "CMake is re-running because generate.stamp.list "
+ << "is missing.\n";
+ return false;
+ }
+ cmsys::ifstream fin(stampList);
+ if(!fin)
+ {
+ std::cout << "CMake is re-running because generate.stamp.list "
+ << "could not be read.\n";
+ return false;
+ }
+
+ // Check each stamp.
+ std::string stampName;
+ while(cmSystemTools::GetLineFromStream(fin, stampName))
+ {
+ if(!cmakeCheckStampFile(stampName.c_str()))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
+ cmListFileBacktrace const& bt)
+{
+ cmListFileBacktrace backtrace = bt;
+ backtrace.MakeRelative();
+
+ cmOStringStream msg;
+ bool isError = false;
+ // Construct the message header.
+ if(t == cmake::FATAL_ERROR)
+ {
+ isError = true;
+ msg << "CMake Error";
+ }
+ else if(t == cmake::INTERNAL_ERROR)
+ {
+ isError = true;
+ msg << "CMake Internal Error (please report a bug)";
+ }
+ else if(t == cmake::LOG)
+ {
+ msg << "CMake Debug Log";
+ }
+ else if(t == cmake::DEPRECATION_ERROR)
+ {
+ msg << "CMake Deprecation Error";
+ isError = true;
+ }
+ else if (t == cmake::DEPRECATION_WARNING)
+ {
+ msg << "CMake Deprecation Warning";
+ }
+ else
+ {
+ msg << "CMake Warning";
+ if(t == cmake::AUTHOR_WARNING)
+ {
+ // Allow suppression of these warnings.
+ cmCacheManager::CacheIterator it = this->CacheManager
+ ->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
+ if(!it.IsAtEnd() && it.GetValueAsBool())
+ {
+ return;
+ }
+ msg << " (dev)";
+ }
+ }
+
+ // Add the immediate context.
+ cmListFileBacktrace::const_iterator i = backtrace.begin();
+ if(i != backtrace.end())
+ {
+ cmListFileContext const& lfc = *i;
+ msg << (lfc.Line? " at ": " in ") << lfc;
+ ++i;
+ }
+
+ // Add the message text.
+ {
+ msg << ":\n";
+ cmDocumentationFormatter formatter;
+ formatter.SetIndent(" ");
+ formatter.PrintFormatted(msg, text.c_str());
+ }
+
+ // Add the rest of the context.
+ if(i != backtrace.end())
+ {
+ msg << "Call Stack (most recent call first):\n";
+ while(i != backtrace.end())
+ {
+ cmListFileContext const& lfc = *i;
+ msg << " " << lfc << "\n";
+ ++i;
+ }
+ }
+
+ // Add a note about warning suppression.
+ if(t == cmake::AUTHOR_WARNING)
+ {
+ msg <<
+ "This warning is for project developers. Use -Wno-dev to suppress it.";
+ }
+
+ // Add a terminating blank line.
+ msg << "\n";
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ // Add a C++ stack trace to internal errors.
+ if(t == cmake::INTERNAL_ERROR)
+ {
+ std::string stack = cmsys::SystemInformation::GetProgramStack(0,0);
+ if(!stack.empty())
+ {
+ if(cmHasLiteralPrefix(stack, "WARNING:"))
+ {
+ stack = "Note:" + stack.substr(8);
+ }
+ msg << stack << "\n";
+ }
+ }
+#endif
+
+ // Output the message.
+ if(isError)
+ {
+ cmSystemTools::SetErrorOccured();
+ cmSystemTools::Message(msg.str().c_str(), "Error");
+ }
+ else
+ {
+ cmSystemTools::Message(msg.str().c_str(), "Warning");
+ }
+}
+
+//----------------------------------------------------------------------------
+std::vector<std::string> const& cmake::GetDebugConfigs()
+{
+ // Compute on-demand.
+ if(this->DebugConfigs.empty())
+ {
+ if(const char* config_list = this->GetProperty("DEBUG_CONFIGURATIONS"))
+ {
+ // Expand the specified list and convert to upper-case.
+ cmSystemTools::ExpandListArgument(config_list, this->DebugConfigs);
+ for(std::vector<std::string>::iterator i = this->DebugConfigs.begin();
+ i != this->DebugConfigs.end(); ++i)
+ {
+ *i = cmSystemTools::UpperCase(*i);
+ }
+ }
+ // If no configurations were specified, use a default list.
+ if(this->DebugConfigs.empty())
+ {
+ this->DebugConfigs.push_back("DEBUG");
+ }
+ }
+ return this->DebugConfigs;
+}
+
+
+int cmake::Build(const std::string& dir,
+ const std::string& target,
+ const std::string& config,
+ const std::vector<std::string>& nativeOptions,
+ bool clean)
+{
+ if(!cmSystemTools::FileIsDirectory(dir.c_str()))
+ {
+ std::cerr << "Error: " << dir << " is not a directory\n";
+ return 1;
+ }
+ std::string cachePath = dir;
+ cmSystemTools::ConvertToUnixSlashes(cachePath);
+ cmCacheManager* cachem = this->GetCacheManager();
+ cmCacheManager::CacheIterator it = cachem->NewIterator();
+ if(!cachem->LoadCache(cachePath))
+ {
+ std::cerr << "Error: could not load cache\n";
+ return 1;
+ }
+ if(!it.Find("CMAKE_GENERATOR"))
+ {
+ std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
+ return 1;
+ }
+ cmsys::auto_ptr<cmGlobalGenerator> gen(
+ this->CreateGlobalGenerator(it.GetValue()));
+ if(!gen.get())
+ {
+ std::cerr << "Error: could create CMAKE_GENERATOR \""
+ << it.GetValue() << "\"\n";
+ return 1;
+ }
+ std::string output;
+ std::string projName;
+ if(!it.Find("CMAKE_PROJECT_NAME"))
+ {
+ std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
+ return 1;
+ }
+ projName = it.GetValue();
+ return gen->Build("", dir,
+ projName, target,
+ output,
+ "",
+ config, clean, false, 0,
+ cmSystemTools::OUTPUT_PASSTHROUGH,
+ nativeOptions);
+}
+
+void cmake::WatchUnusedCli(const std::string& var)
+{
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
+ if(this->UsedCliVariables.find(var) == this->UsedCliVariables.end())
+ {
+ this->UsedCliVariables[var] = false;
+ }
+#endif
+}
+
+void cmake::UnwatchUnusedCli(const std::string& var)
+{
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning);
+ this->UsedCliVariables.erase(var);
+#endif
+}
+
+void cmake::RunCheckForUnusedVariables()
+{
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ bool haveUnused = false;
+ cmOStringStream msg;
+ msg << "Manually-specified variables were not used by the project:";
+ for(std::map<std::string, bool>::const_iterator
+ it = this->UsedCliVariables.begin();
+ it != this->UsedCliVariables.end(); ++it)
+ {
+ if(!it->second)
+ {
+ haveUnused = true;
+ msg << "\n " << it->first;
+ }
+ }
+ if(haveUnused)
+ {
+ this->IssueMessage(cmake::WARNING, msg.str());
+ }
+#endif
+}
diff --git a/Source/cmake.h b/Source/cmake.h
new file mode 100644
index 0000000000..60ffcd4de8
--- /dev/null
+++ b/Source/cmake.h
@@ -0,0 +1,548 @@
+/*============================================================================
+ 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 cmake_h
+#define cmake_h
+
+#include "cmListFileCache.h"
+#include "cmSystemTools.h"
+#include "cmPropertyDefinitionMap.h"
+#include "cmPropertyMap.h"
+#include "cmInstalledFile.h"
+
+class cmGlobalGeneratorFactory;
+class cmGlobalGenerator;
+class cmLocalGenerator;
+class cmCacheManager;
+class cmMakefile;
+class cmCommand;
+class cmVariableWatch;
+class cmFileTimeComparison;
+class cmExternalMakefileProjectGenerator;
+class cmDocumentationSection;
+class cmPolicies;
+class cmTarget;
+class cmGeneratedFileStream;
+
+/** \brief Represents a cmake invocation.
+ *
+ * This class represents a cmake invocation. It is the top level class when
+ * running cmake. Most cmake based GUIs should primarily create an instance
+ * of this class and communicate with it.
+ *
+ * The basic process for a GUI is as follows:
+ *
+ * -# Create a cmake instance
+ * -# Set the Home & Start directories, generator, and cmake command. this
+ * can be done using the Set methods or by using SetArgs and passing in
+ * command line arguments.
+ * -# Load the cache by calling LoadCache (duh)
+ * -# if you are using command line arguments with -D or -C flags then
+ * call SetCacheArgs (or if for some other reason you want to modify the
+ * cache), do it now.
+ * -# Finally call Configure
+ * -# Let the user change values and go back to step 5
+ * -# call Generate
+
+ * If your GUI allows the user to change the start & home directories then
+ * you must at a minimum redo steps 2 through 7.
+ */
+
+class cmake
+{
+ public:
+ enum MessageType
+ { AUTHOR_WARNING,
+ FATAL_ERROR,
+ INTERNAL_ERROR,
+ MESSAGE,
+ WARNING,
+ LOG,
+ DEPRECATION_ERROR,
+ DEPRECATION_WARNING
+ };
+
+
+ /** \brief Describes the working modes of cmake */
+ enum WorkingMode
+ {
+ NORMAL_MODE, ///< Cmake runs to create project files
+ /** \brief Script mode (started by using -P).
+ *
+ * In script mode there is no generator and no cache. Also,
+ * languages are not enabled, so add_executable and things do
+ * nothing.
+ */
+ SCRIPT_MODE,
+ /** \brief A pkg-config like mode
+ *
+ * In this mode cmake just searches for a package and prints the results to
+ * stdout. This is similar to SCRIPT_MODE, but commands like add_library()
+ * work too, since they may be used e.g. in exported target files. Started
+ * via --find-package.
+ */
+ FIND_PACKAGE_MODE
+ };
+ typedef std::map<std::string, cmCommand*> RegisteredCommandsMap;
+ typedef std::map<std::string, cmInstalledFile> InstalledFilesMap;
+
+ /// Default constructor
+ cmake();
+ /// Destructor
+ ~cmake();
+
+ static const char *GetCMakeFilesDirectory() {return "/CMakeFiles";}
+ static const char *GetCMakeFilesDirectoryPostSlash() {
+ return "CMakeFiles/";}
+
+ //@{
+ /**
+ * Set/Get the home directory (or output directory) in the project. The
+ * home directory is the top directory of the project. It is the
+ * path-to-source cmake was run with. Remember that CMake processes
+ * CMakeLists files by recursing up the tree starting at the StartDirectory
+ * and going up until it reaches the HomeDirectory.
+ */
+ void SetHomeDirectory(const std::string& dir);
+ const char* GetHomeDirectory() const
+ {
+ return this->cmHomeDirectory.c_str();
+ }
+ void SetHomeOutputDirectory(const std::string& lib);
+ const char* GetHomeOutputDirectory() const
+ {
+ return this->HomeOutputDirectory.c_str();
+ }
+ //@}
+
+ //@{
+ /**
+ * Set/Get the start directory (or output directory). The start directory
+ * is the directory of the CMakeLists.txt file that started the current
+ * round of processing. Remember that CMake processes CMakeLists files by
+ * recursing up the tree starting at the StartDirectory and going up until
+ * it reaches the HomeDirectory.
+ */
+ void SetStartDirectory(const std::string& dir)
+ {
+ this->cmStartDirectory = dir;
+ cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
+ }
+ const char* GetStartDirectory() const
+ {
+ return this->cmStartDirectory.c_str();
+ }
+ void SetStartOutputDirectory(const std::string& lib)
+ {
+ this->StartOutputDirectory = lib;
+ cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
+ }
+ const char* GetStartOutputDirectory() const
+ {
+ return this->StartOutputDirectory.c_str();
+ }
+ //@}
+
+ /**
+ * Handle a command line invocation of cmake.
+ */
+ int Run(const std::vector<std::string>&args)
+ { return this->Run(args, false); }
+ int Run(const std::vector<std::string>&args, bool noconfigure);
+
+ /**
+ * Run the global generator Generate step.
+ */
+ int Generate();
+
+ /**
+ * Configure the cmMakefiles. This routine will create a GlobalGenerator if
+ * one has not already been set. It will then Call Configure on the
+ * GlobalGenerator. This in turn will read in an process all the CMakeList
+ * files for the tree. It will not produce any actual Makefiles, or
+ * workspaces. Generate does that. */
+ int Configure();
+ int ActualConfigure();
+
+ int LoadCache();
+ void PreLoadCMakeFiles();
+
+ ///! Create a GlobalGenerator
+ cmGlobalGenerator* CreateGlobalGenerator(const std::string& name);
+
+ ///! Return the global generator assigned to this instance of cmake
+ cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }
+ ///! Return the global generator assigned to this instance of cmake, const
+ const cmGlobalGenerator* GetGlobalGenerator() const
+ { return this->GlobalGenerator; }
+
+ ///! Return the global generator assigned to this instance of cmake
+ void SetGlobalGenerator(cmGlobalGenerator *);
+
+ ///! Get the names of the current registered generators
+ void GetRegisteredGenerators(std::vector<std::string>& names);
+
+ ///! Set the name of the selected generator-specific platform.
+ void SetGeneratorPlatform(std::string const& ts)
+ { this->GeneratorPlatform = ts; }
+
+ ///! Get the name of the selected generator-specific platform.
+ std::string const& GetGeneratorPlatform() const
+ { return this->GeneratorPlatform; }
+
+ ///! Set the name of the selected generator-specific toolset.
+ void SetGeneratorToolset(std::string const& ts)
+ { this->GeneratorToolset = ts; }
+
+ ///! Get the name of the selected generator-specific toolset.
+ std::string const& GetGeneratorToolset() const
+ { return this->GeneratorToolset; }
+
+ ///! get the cmCachemManager used by this invocation of cmake
+ cmCacheManager *GetCacheManager() { return this->CacheManager; }
+
+ /**
+ * Given a variable name, return its value (as a string).
+ */
+ const char* GetCacheDefinition(const std::string&) const;
+ ///! Add an entry into the cache
+ void AddCacheEntry(const std::string& key, const char* value,
+ const char* helpString,
+ int type);
+
+ /**
+ * Get the system information and write it to the file specified
+ */
+ int GetSystemInformation(std::vector<std::string>&);
+
+ /**
+ * Add a command to this cmake instance
+ */
+ void AddCommand(cmCommand* );
+ void RenameCommand(const std::string& oldName, const std::string& newName);
+ void RemoveCommand(const std::string& name);
+ void RemoveUnscriptableCommands();
+
+ /**
+ * Get a command by its name
+ */
+ cmCommand *GetCommand(const std::string& name);
+
+ /** Get list of all commands */
+ RegisteredCommandsMap* GetCommands() { return &this->Commands; }
+
+ /** Check if a command exists. */
+ bool CommandExists(const std::string& name) const;
+
+ ///! Parse command line arguments
+ void SetArgs(const std::vector<std::string>&,
+ bool directoriesSetBefore = false);
+
+ ///! Is this cmake running as a result of a TRY_COMPILE command
+ bool GetIsInTryCompile() { return this->InTryCompile; }
+
+ ///! Is this cmake running as a result of a TRY_COMPILE command
+ void SetIsInTryCompile(bool i) { this->InTryCompile = i; }
+
+ ///! Parse command line arguments that might set cache values
+ bool SetCacheArgs(const std::vector<std::string>&);
+
+ typedef void (*ProgressCallbackType)
+ (const char*msg, float progress, void *);
+ /**
+ * Set the function used by GUIs to receive progress updates
+ * Function gets passed: message as a const char*, a progress
+ * amount ranging from 0 to 1.0 and client data. The progress
+ * number provided may be negative in cases where a message is
+ * to be displayed without any progress percentage.
+ */
+ void SetProgressCallback(ProgressCallbackType f, void* clientData=0);
+
+ ///! this is called by generators to update the progress
+ void UpdateProgress(const char *msg, float prog);
+
+ ///! get the cmake policies instance
+ cmPolicies *GetPolicies() {return this->Policies;}
+
+ ///! Get the variable watch object
+ cmVariableWatch* GetVariableWatch() { return this->VariableWatch; }
+
+ void GetGeneratorDocumentation(std::vector<cmDocumentationEntry>&);
+
+ ///! 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,bool asString=false);
+ const char *GetProperty(const std::string& prop);
+ const char *GetProperty(const std::string& prop,
+ cmProperty::ScopeType scope);
+ bool GetPropertyAsBool(const std::string& prop);
+
+ // Get the properties
+ cmPropertyMap &GetProperties() { return this->Properties; }
+
+ ///! Get or create an cmInstalledFile instance and return a pointer to it
+ cmInstalledFile *GetOrCreateInstalledFile(
+ cmMakefile* mf, const std::string& name);
+
+ cmInstalledFile const* GetInstalledFile(const std::string& name) const;
+
+ InstalledFilesMap const& GetInstalledFiles() const
+ { return this->InstalledFiles; }
+
+ ///! Do all the checks before running configure
+ int DoPreConfigureChecks();
+
+ void SetWorkingMode(WorkingMode mode) { this->CurrentWorkingMode = mode; }
+ WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; }
+
+ ///! Debug the try compile stuff by not deleting the files
+ bool GetDebugTryCompile(){return this->DebugTryCompile;}
+ void DebugTryCompileOn(){this->DebugTryCompile = true;}
+
+ /**
+ * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
+ */
+ int AddCMakePaths();
+
+ /**
+ * Get the file comparison class
+ */
+ cmFileTimeComparison* GetFileComparison() { return this->FileComparison; }
+
+ // Do we want debug output during the cmake run.
+ bool GetDebugOutput() { return this->DebugOutput; }
+ void SetDebugOutputOn(bool b) { this->DebugOutput = b;}
+
+ // Do we want trace output during the cmake run.
+ bool GetTrace() { return this->Trace;}
+ void SetTrace(bool b) { this->Trace = b;}
+ bool GetWarnUninitialized() { return this->WarnUninitialized;}
+ void SetWarnUninitialized(bool b) { this->WarnUninitialized = b;}
+ bool GetWarnUnused() { return this->WarnUnused;}
+ void SetWarnUnused(bool b) { this->WarnUnused = b;}
+ bool GetWarnUnusedCli() { return this->WarnUnusedCli;}
+ void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b;}
+ bool GetCheckSystemVars() { return this->CheckSystemVars;}
+ void SetCheckSystemVars(bool b) { this->CheckSystemVars = b;}
+
+ void MarkCliAsUsed(const std::string& variable);
+
+ // Define a property
+ void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
+ const char *ShortDescription,
+ const char *FullDescription,
+ bool chain = false);
+
+ // get property definition
+ cmPropertyDefinition *GetPropertyDefinition
+ (const std::string& name, cmProperty::ScopeType scope);
+
+ // Is a property defined?
+ bool IsPropertyDefined(const std::string& name, cmProperty::ScopeType scope);
+ bool IsPropertyChained(const std::string& name, cmProperty::ScopeType scope);
+
+ /** Get the list of configurations (in upper case) considered to be
+ debugging configurations.*/
+ std::vector<std::string> const& GetDebugConfigs();
+
+ void SetCMakeEditCommand(std::string const& s)
+ { this->CMakeEditCommand = s; }
+ std::string const& GetCMakeEditCommand() const
+ { return this->CMakeEditCommand; }
+
+ void SetSuppressDevWarnings(bool v)
+ {
+ this->SuppressDevWarnings = v;
+ this->DoSuppressDevWarnings = true;
+ }
+
+ /** Display a message to the user. */
+ void IssueMessage(cmake::MessageType t, std::string const& text,
+ cmListFileBacktrace const& backtrace = cmListFileBacktrace(NULL));
+ ///! run the --build option
+ int Build(const std::string& dir,
+ const std::string& target,
+ const std::string& config,
+ const std::vector<std::string>& nativeOptions,
+ bool clean);
+
+ void UnwatchUnusedCli(const std::string& var);
+ void WatchUnusedCli(const std::string& var);
+protected:
+ void RunCheckForUnusedVariables();
+ void InitializeProperties();
+ int HandleDeleteCacheVariables(const std::string& var);
+ cmPropertyMap Properties;
+ std::set<std::pair<std::string,cmProperty::ScopeType> > AccessedProperties;
+
+ std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>
+ PropertyDefinitions;
+
+ typedef
+ cmExternalMakefileProjectGenerator* (*CreateExtraGeneratorFunctionType)();
+ typedef std::map<std::string,
+ CreateExtraGeneratorFunctionType> RegisteredExtraGeneratorsMap;
+ typedef std::vector<cmGlobalGeneratorFactory*> RegisteredGeneratorsVector;
+ RegisteredCommandsMap Commands;
+ RegisteredGeneratorsVector Generators;
+ RegisteredExtraGeneratorsMap ExtraGenerators;
+ void AddDefaultCommands();
+ void AddDefaultGenerators();
+ void AddDefaultExtraGenerators();
+ void AddExtraGenerator(const std::string& name,
+ CreateExtraGeneratorFunctionType newFunction);
+
+ cmPolicies *Policies;
+ cmGlobalGenerator *GlobalGenerator;
+ cmCacheManager *CacheManager;
+ std::string cmHomeDirectory;
+ std::string HomeOutputDirectory;
+ std::string cmStartDirectory;
+ std::string StartOutputDirectory;
+ bool SuppressDevWarnings;
+ bool DoSuppressDevWarnings;
+ std::string GeneratorPlatform;
+ std::string GeneratorToolset;
+
+ ///! read in a cmake list file to initialize the cache
+ void ReadListFile(const std::vector<std::string>& args, const char *path);
+ bool FindPackage(const std::vector<std::string>& args);
+
+ ///! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
+ /// If it is set, truncate it to 50kb
+ void TruncateOutputLog(const char* fname);
+
+ /**
+ * Method called to check build system integrity at build time.
+ * Returns 1 if CMake should rerun and 0 otherwise.
+ */
+ int CheckBuildSystem();
+
+ void SetDirectoriesFromFile(const char* arg);
+
+ //! Make sure all commands are what they say they are and there is no
+ /// macros.
+ void CleanupCommandsAndMacros();
+
+ void GenerateGraphViz(const char* fileName) const;
+
+ cmVariableWatch* VariableWatch;
+
+private:
+ cmake(const cmake&); // Not implemented.
+ void operator=(const cmake&); // Not implemented.
+ ProgressCallbackType ProgressCallback;
+ void* ProgressCallbackClientData;
+ bool Verbose;
+ bool InTryCompile;
+ WorkingMode CurrentWorkingMode;
+ bool DebugOutput;
+ bool Trace;
+ bool WarnUninitialized;
+ bool WarnUnused;
+ bool WarnUnusedCli;
+ bool CheckSystemVars;
+ std::map<std::string, bool> UsedCliVariables;
+ std::string CMakeEditCommand;
+ std::string CXXEnvironment;
+ std::string CCEnvironment;
+ std::string CheckBuildSystemArgument;
+ std::string CheckStampFile;
+ std::string CheckStampList;
+ std::string VSSolutionFile;
+ bool ClearBuildSystem;
+ bool DebugTryCompile;
+ cmFileTimeComparison* FileComparison;
+ std::string GraphVizFile;
+ std::vector<std::string> DebugConfigs;
+ InstalledFilesMap InstalledFiles;
+
+ void UpdateConversionPathTable();
+};
+
+#define CMAKE_STANDARD_OPTIONS_TABLE \
+ {"-C <initial-cache>", "Pre-load a script to populate the cache."}, \
+ {"-D <var>:<type>=<value>", "Create a cmake cache entry."}, \
+ {"-U <globbing_expr>", "Remove matching entries from CMake cache."}, \
+ {"-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."}, \
+ {"-Wno-dev", "Suppress developer warnings."},\
+ {"-Wdev", "Enable developer warnings."}
+
+#define FOR_EACH_C_FEATURE(F) \
+ F(c_function_prototypes) \
+ F(c_restrict) \
+ F(c_static_assert) \
+ F(c_variadic_macros)
+
+#define FOR_EACH_CXX_FEATURE(F) \
+ F(cxx_aggregate_default_initializers) \
+ F(cxx_alias_templates) \
+ F(cxx_alignas) \
+ F(cxx_alignof) \
+ F(cxx_attributes) \
+ F(cxx_attribute_deprecated) \
+ F(cxx_auto_type) \
+ F(cxx_binary_literals) \
+ F(cxx_constexpr) \
+ F(cxx_contextual_conversions) \
+ F(cxx_decltype) \
+ F(cxx_decltype_auto) \
+ F(cxx_decltype_incomplete_return_types) \
+ F(cxx_default_function_template_args) \
+ F(cxx_defaulted_functions) \
+ F(cxx_defaulted_move_initializers) \
+ F(cxx_delegating_constructors) \
+ F(cxx_deleted_functions) \
+ F(cxx_digit_separators) \
+ F(cxx_enum_forward_declarations) \
+ F(cxx_explicit_conversions) \
+ F(cxx_extended_friend_declarations) \
+ F(cxx_extern_templates) \
+ F(cxx_final) \
+ F(cxx_func_identifier) \
+ F(cxx_generalized_initializers) \
+ F(cxx_generic_lambdas) \
+ F(cxx_inheriting_constructors) \
+ F(cxx_inline_namespaces) \
+ F(cxx_lambdas) \
+ F(cxx_lambda_init_captures) \
+ F(cxx_local_type_template_args) \
+ F(cxx_long_long_type) \
+ F(cxx_noexcept) \
+ F(cxx_nonstatic_member_init) \
+ F(cxx_nullptr) \
+ F(cxx_override) \
+ F(cxx_range_for) \
+ F(cxx_raw_string_literals) \
+ F(cxx_reference_qualified_functions) \
+ F(cxx_relaxed_constexpr) \
+ F(cxx_return_type_deduction) \
+ F(cxx_right_angle_brackets) \
+ F(cxx_rvalue_references) \
+ F(cxx_sizeof_member) \
+ F(cxx_static_assert) \
+ F(cxx_strong_enums) \
+ F(cxx_template_template_parameters) \
+ F(cxx_thread_local) \
+ F(cxx_trailing_return_types) \
+ F(cxx_unicode_literals) \
+ F(cxx_uniform_initialization) \
+ F(cxx_unrestricted_unions) \
+ F(cxx_user_literals) \
+ F(cxx_variable_templates) \
+ F(cxx_variadic_macros) \
+ F(cxx_variadic_templates)
+
+#endif
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
new file mode 100644
index 0000000000..61b175e133
--- /dev/null
+++ b/Source/cmakemain.cxx
@@ -0,0 +1,463 @@
+/*============================================================================
+ 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 these first, otherwise there will be problems on Windows
+// with GetCurrentDirectory() being redefined
+#ifdef CMAKE_BUILD_WITH_CMAKE
+#include "cmDynamicLoader.h"
+#include "cmDocumentation.h"
+#endif
+
+#include "cmake.h"
+#include "cmcmd.h"
+#include "cmCacheManager.h"
+#include "cmListFileCache.h"
+#include "cmSourceFile.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include <cmsys/Encoding.hxx>
+#include <locale.h>
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+//----------------------------------------------------------------------------
+static const char * cmDocumentationName[][2] =
+{
+ {0,
+ " cmake - Cross-Platform Makefile Generator."},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationUsage[][2] =
+{
+ {0,
+ " cmake [options] <path-to-source>\n"
+ " cmake [options] <path-to-existing-build>"},
+ {0,
+ "Specify a source directory to (re-)generate a build system for "
+ "it in the current working directory. Specify an existing build "
+ "directory to re-generate its build system."},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationUsageNote[][2] =
+{
+ {0,
+ "Run 'cmake --help' for more information."},
+ {0,0}
+};
+
+#define CMAKE_BUILD_OPTIONS \
+ " <dir> = Project binary directory to be built.\n" \
+ " --target <tgt> = Build <tgt> instead of default targets.\n" \
+ " --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \
+ " --clean-first = Build target 'clean' first, then build.\n" \
+ " (To clean only, use --target 'clean'.)\n" \
+ " --use-stderr = Ignored. Behavior is default in CMake >= 3.0.\n" \
+ " -- = Pass remaining options to the native tool.\n"
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationOptions[][2] =
+{
+ CMAKE_STANDARD_OPTIONS_TABLE,
+ {"-E", "CMake command mode."},
+ {"-L[A][H]", "List non-advanced cached variables."},
+ {"--build <dir>", "Build a CMake-generated project binary tree."},
+ {"-N", "View mode only."},
+ {"-P <file>", "Process script mode."},
+ {"--find-package", "Run in pkg-config like mode."},
+ {"--graphviz=[file]", "Generate graphviz of dependencies, see "
+ "CMakeGraphVizOptions.cmake for more."},
+ {"--system-information [file]", "Dump information about this system."},
+ {"--debug-trycompile", "Do not delete the try_compile build tree. Only "
+ "useful on one try_compile at a time."},
+ {"--debug-output", "Put cmake in a debug mode."},
+ {"--trace", "Put cmake in trace mode."},
+ {"--warn-uninitialized", "Warn about uninitialized values."},
+ {"--warn-unused-vars", "Warn about unused variables."},
+ {"--no-warn-unused-cli", "Don't warn about command line options."},
+ {"--check-system-vars", "Find problems with variable usage in system "
+ "files."},
+ {0,0}
+};
+
+#endif
+
+static int do_command(int ac, char const* const* av)
+{
+ std::vector<std::string> args;
+ args.push_back(av[0]);
+ for(int i = 2; i < ac; ++i)
+ {
+ args.push_back(av[i]);
+ }
+ return cmcmd::ExecuteCMakeCommand(args);
+}
+
+int do_cmake(int ac, char const* const* av);
+static int do_build(int ac, char const* const* av);
+
+static cmMakefile* cmakemainGetMakefile(void *clientdata)
+{
+ cmake* cm = (cmake *)clientdata;
+ if(cm && cm->GetDebugOutput())
+ {
+ cmGlobalGenerator* gg=cm->GetGlobalGenerator();
+ if (gg)
+ {
+ cmLocalGenerator* lg=gg->GetCurrentLocalGenerator();
+ if (lg)
+ {
+ cmMakefile* mf = lg->GetMakefile();
+ return mf;
+ }
+ }
+ }
+ return 0;
+}
+
+static std::string cmakemainGetStack(void *clientdata)
+{
+ std::string msg;
+ cmMakefile* mf=cmakemainGetMakefile(clientdata);
+ if (mf)
+ {
+ msg = mf->GetListFileStack();
+ if (!msg.empty())
+ {
+ msg = "\n Called from: " + msg;
+ }
+ }
+
+ return msg;
+}
+
+static void cmakemainMessageCallback(const char* m, const char*, bool&,
+ void *clientdata)
+{
+ std::cerr << m << cmakemainGetStack(clientdata) << std::endl << std::flush;
+}
+
+static void cmakemainProgressCallback(const char *m, float prog,
+ void* clientdata)
+{
+ cmMakefile* mf = cmakemainGetMakefile(clientdata);
+ std::string dir;
+ if ((mf) && (strstr(m, "Configuring")==m) && (prog<0))
+ {
+ dir = " ";
+ dir += mf->GetCurrentDirectory();
+ }
+ else if ((mf) && (strstr(m, "Generating")==m))
+ {
+ dir = " ";
+ dir += mf->GetCurrentOutputDirectory();
+ }
+
+ if ((prog < 0) || (!dir.empty()))
+ {
+ std::cout << "-- " << m << dir << cmakemainGetStack(clientdata)<<std::endl;
+ }
+
+ std::cout.flush();
+}
+
+
+int main(int ac, char const* const* av)
+{
+ setlocale(LC_CTYPE, "");
+ cmsys::Encoding::CommandLineArguments args =
+ cmsys::Encoding::CommandLineArguments::Main(ac, av);
+ ac = args.argc();
+ av = args.argv();
+
+ cmSystemTools::EnableMSVCDebugHook();
+ cmSystemTools::FindCMakeResources(av[0]);
+ if(ac > 1)
+ {
+ if(strcmp(av[1], "--build") == 0)
+ {
+ return do_build(ac, av);
+ }
+ else if(strcmp(av[1], "-E") == 0)
+ {
+ return do_command(ac, av);
+ }
+ }
+ int ret = do_cmake(ac, av);
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmDynamicLoader::FlushCache();
+#endif
+ return ret;
+}
+
+int do_cmake(int ac, char const* const* av)
+{
+ if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
+ {
+ std::cerr << "Current working directory cannot be established."
+ << std::endl;
+ return 1;
+ }
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmDocumentation doc;
+ doc.addCMakeStandardDocSections();
+ if(doc.CheckOptions(ac, av))
+ {
+ // Construct and print requested documentation.
+ cmake hcm;
+ hcm.AddCMakePaths();
+
+ // the command line args are processed here so that you can do
+ // -DCMAKE_MODULE_PATH=/some/path and have this value accessible here
+ std::vector<std::string> args;
+ for(int i =0; i < ac; ++i)
+ {
+ args.push_back(av[i]);
+ }
+ hcm.SetCacheArgs(args);
+
+ std::vector<cmDocumentationEntry> generators;
+
+ hcm.GetGeneratorDocumentation(generators);
+
+ doc.SetName("cmake");
+ doc.SetSection("Name",cmDocumentationName);
+ doc.SetSection("Usage",cmDocumentationUsage);
+ if ( ac == 1 )
+ {
+ doc.AppendSection("Usage",cmDocumentationUsageNote);
+ }
+ doc.AppendSection("Generators",generators);
+ doc.PrependSection("Options",cmDocumentationOptions);
+
+ return doc.PrintRequestedDocumentation(std::cout)? 0:1;
+ }
+#else
+ if ( ac == 1 )
+ {
+ std::cout <<
+ "Bootstrap CMake should not be used outside CMake build process."
+ << std::endl;
+ return 0;
+ }
+#endif
+
+ bool sysinfo = false;
+ bool list_cached = false;
+ bool list_all_cached = false;
+ bool list_help = false;
+ bool view_only = false;
+ cmake::WorkingMode workingMode = cmake::NORMAL_MODE;
+ std::vector<std::string> args;
+ for(int i =0; i < ac; ++i)
+ {
+ if(strcmp(av[i], "-i") == 0)
+ {
+ std::cerr <<
+ "The \"cmake -i\" wizard mode is no longer supported.\n"
+ "Use the -D option to set cache values on the command line.\n"
+ "Use cmake-gui or ccmake for an interactive dialog.\n";
+ return 1;
+ }
+ else if(strcmp(av[i], "--system-information") == 0)
+ {
+ sysinfo = true;
+ }
+ else if (strcmp(av[i], "-N") == 0)
+ {
+ view_only = true;
+ }
+ else if (strcmp(av[i], "-L") == 0)
+ {
+ list_cached = true;
+ }
+ else if (strcmp(av[i], "-LA") == 0)
+ {
+ list_all_cached = true;
+ }
+ else if (strcmp(av[i], "-LH") == 0)
+ {
+ list_cached = true;
+ list_help = true;
+ }
+ else if (strcmp(av[i], "-LAH") == 0)
+ {
+ list_all_cached = true;
+ list_help = true;
+ }
+ else if (cmHasLiteralPrefix(av[i], "-P"))
+ {
+ if ( i == ac -1 )
+ {
+ cmSystemTools::Error("No script specified for argument -P");
+ }
+ else
+ {
+ workingMode = cmake::SCRIPT_MODE;
+ args.push_back(av[i]);
+ i++;
+ args.push_back(av[i]);
+ }
+ }
+ else if (cmHasLiteralPrefix(av[i], "--find-package"))
+ {
+ workingMode = cmake::FIND_PACKAGE_MODE;
+ args.push_back(av[i]);
+ }
+ else
+ {
+ args.push_back(av[i]);
+ }
+ }
+ if (sysinfo)
+ {
+ cmake cm;
+ int ret = cm.GetSystemInformation(args);
+ return ret;
+ }
+ cmake cm;
+ cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void *)&cm);
+ cm.SetProgressCallback(cmakemainProgressCallback, (void *)&cm);
+ cm.SetWorkingMode(workingMode);
+
+ int res = cm.Run(args, view_only);
+ if ( list_cached || list_all_cached )
+ {
+ cmCacheManager::CacheIterator it =
+ cm.GetCacheManager()->GetCacheIterator();
+ std::cout << "-- Cache values" << std::endl;
+ for ( it.Begin(); !it.IsAtEnd(); it.Next() )
+ {
+ cmCacheManager::CacheEntryType t = it.GetType();
+ if ( t != cmCacheManager::INTERNAL && t != cmCacheManager::STATIC &&
+ t != cmCacheManager::UNINITIALIZED )
+ {
+ bool advanced = it.PropertyExists("ADVANCED");
+ if ( list_all_cached || !advanced)
+ {
+ if ( list_help )
+ {
+ std::cout << "// " << it.GetProperty("HELPSTRING") << std::endl;
+ }
+ std::cout << it.GetName() << ":" <<
+ cmCacheManager::TypeToString(it.GetType())
+ << "=" << it.GetValue() << std::endl;
+ if ( list_help )
+ {
+ std::cout << std::endl;
+ }
+ }
+ }
+ }
+ }
+
+ // Always return a non-negative value. Windows tools do not always
+ // interpret negative return values as errors.
+ if(res != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+static int do_build(int ac, char const* const* av)
+{
+#ifndef CMAKE_BUILD_WITH_CMAKE
+ std::cerr << "This cmake does not support --build\n";
+ return -1;
+#else
+ std::string target;
+ std::string config = "Debug";
+ std::string dir;
+ std::vector<std::string> nativeOptions;
+ bool clean = false;
+
+ enum Doing { DoingNone, DoingDir, DoingTarget, DoingConfig, DoingNative};
+ Doing doing = DoingDir;
+ for(int i=2; i < ac; ++i)
+ {
+ if(doing == DoingNative)
+ {
+ nativeOptions.push_back(av[i]);
+ }
+ else if(strcmp(av[i], "--target") == 0)
+ {
+ doing = DoingTarget;
+ }
+ else if(strcmp(av[i], "--config") == 0)
+ {
+ doing = DoingConfig;
+ }
+ else if(strcmp(av[i], "--clean-first") == 0)
+ {
+ clean = true;
+ doing = DoingNone;
+ }
+ else if(strcmp(av[i], "--use-stderr") == 0)
+ {
+ /* tolerate legacy option */
+ }
+ else if(strcmp(av[i], "--") == 0)
+ {
+ doing = DoingNative;
+ }
+ else
+ {
+ switch (doing)
+ {
+ case DoingDir:
+ dir = av[i];
+ doing = DoingNone;
+ break;
+ case DoingTarget:
+ target = av[i];
+ doing = DoingNone;
+ break;
+ case DoingConfig:
+ config = av[i];
+ doing = DoingNone;
+ break;
+ default:
+ std::cerr << "Unknown argument " << av[i] << std::endl;
+ dir = "";
+ break;
+ }
+ }
+ }
+ if(dir.empty())
+ {
+ std::cerr <<
+ "Usage: cmake --build <dir> [options] [-- [native-options]]\n"
+ "Options:\n"
+ CMAKE_BUILD_OPTIONS
+ ;
+ return 1;
+ }
+
+ // Hack for vs6 that passes ".\Debug" as "$(IntDir)" value:
+ //
+ if (cmSystemTools::StringStartsWith(config.c_str(), ".\\"))
+ {
+ config = config.substr(2);
+ }
+
+ cmake cm;
+ return cm.Build(dir, target, config, nativeOptions, clean);
+#endif
+}
diff --git a/Source/cmakexbuild.cxx b/Source/cmakexbuild.cxx
new file mode 100644
index 0000000000..9aaeeaa4d7
--- /dev/null
+++ b/Source/cmakexbuild.cxx
@@ -0,0 +1,92 @@
+/*============================================================================
+ 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 <cmsys/Process.h>
+#include "cmStandardIncludes.h"
+#include "cmSystemTools.h"
+
+// This is a wrapper program for xcodebuild
+// it calls xcodebuild, and does two things
+// it removes much of the output, all the setenv
+// stuff. Also, it checks for the text file busy
+// error, and re-runs xcodebuild until that error does
+// not show up.
+
+int RunXCode(std::vector<const char*>& argv, bool& hitbug)
+{
+ hitbug = false;
+ cmsysProcess* cp = cmsysProcess_New();
+ cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetTimeout(cp, 0);
+ cmsysProcess_Execute(cp);
+ std::vector<char> out;
+ std::vector<char> err;
+ std::string line;
+ int pipe = cmSystemTools::WaitForLine(cp, line, 100.0, out, err);
+ while(pipe != cmsysProcess_Pipe_None)
+ {
+ if(line.find("/bin/sh: bad interpreter: Text file busy")
+ != line.npos)
+ {
+ hitbug = true;
+ std::cerr << "Hit xcodebuild bug : " << line << "\n";
+ }
+ // if the bug is hit, no more output should be generated
+ // because it may contain bogus errors
+ // also remove all output with setenv in it to tone down
+ // the verbosity of xcodebuild
+ if(!hitbug && (line.find("setenv") == line.npos))
+ {
+ if(pipe == cmsysProcess_Pipe_STDERR)
+ {
+ std::cerr << line << "\n";
+ }
+ else if(pipe == cmsysProcess_Pipe_STDOUT)
+ {
+ std::cout << line << "\n";
+ }
+ }
+ pipe = cmSystemTools::WaitForLine(cp, line, 100, out, err);
+ }
+ cmsysProcess_WaitForExit(cp, 0);
+ if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
+ {
+ return cmsysProcess_GetExitValue(cp);
+ }
+ if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
+ {
+ return -1;
+ }
+ return -1;
+}
+
+int main(int ac, char*av[])
+{
+ std::vector<const char*> argv;
+ argv.push_back("xcodebuild");
+ for(int i =1; i < ac; i++)
+ {
+ argv.push_back(av[i]);
+ }
+ argv.push_back(0);
+ bool hitbug = true;
+ int ret = 0;
+ while(hitbug)
+ {
+ ret = RunXCode(argv, hitbug);
+ }
+ if(ret < 0)
+ {
+ return 255;
+ }
+ return ret;
+}
+
diff --git a/Source/cmcldeps.cxx b/Source/cmcldeps.cxx
new file mode 100644
index 0000000000..55fc6338a8
--- /dev/null
+++ b/Source/cmcldeps.cxx
@@ -0,0 +1,307 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+
+// Wrapper around cl that adds /showIncludes to command line, and uses that to
+// generate .d files that match the style from gcc -MD.
+//
+// /showIncludes is equivalent to -MD, not -MMD, that is, system headers are
+// included.
+
+
+#include <windows.h>
+#include <sstream>
+#include <cmSystemTools.h>
+#include <cmsys/Encoding.hxx>
+
+// We don't want any wildcard expansion.
+// See http://msdn.microsoft.com/en-us/library/zay8tzh6(v=vs.85).aspx
+void _setargv() {}
+
+static void Fatal(const char* msg, ...) {
+ va_list ap;
+ fprintf(stderr, "ninja: FATAL: ");
+ va_start(ap, msg);
+ vfprintf(stderr, msg, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+ // On Windows, some tools may inject extra threads.
+ // exit() may block on locks held by those threads, so forcibly exit.
+ fflush(stderr);
+ fflush(stdout);
+ ExitProcess(1);
+}
+
+static void usage(const char* msg) {
+ Fatal("%s\n\nusage:\n "
+ "cmcldeps "
+ "<language C, CXX or RC> "
+ "<source file path> "
+ "<output path for *.d file> "
+ "<output path for *.obj file> "
+ "<prefix of /showIncludes> "
+ "<path to cl.exe> "
+ "<path to tool (cl or rc)> "
+ "<rest of command ...>\n", msg);
+}
+
+static std::string trimLeadingSpace(const std::string& cmdline) {
+ int i = 0;
+ for (; cmdline[i] == ' '; ++i)
+ ;
+ return cmdline.substr(i);
+}
+
+static void replaceAll(std::string& str, const std::string& search,
+ const std::string& repl) {
+ std::string::size_type pos = 0;
+ while ((pos = str.find(search, pos)) != std::string::npos) {
+ str.replace(pos, search.size(), repl);
+ pos += repl.size();
+ }
+}
+
+bool startsWith(const std::string& str, const std::string& what) {
+ return str.compare(0, what.size(), what) == 0;
+}
+
+// Strips one argument from the cmdline and returns it. "surrounding quotes"
+// are removed from the argument if there were any.
+static std::string getArg(std::string& cmdline) {
+ std::string ret;
+ bool in_quoted = false;
+ unsigned int i = 0;
+
+ cmdline = trimLeadingSpace(cmdline);
+
+ for (;; ++i) {
+ if (i >= cmdline.size())
+ usage("Couldn't parse arguments.");
+ if (!in_quoted && cmdline[i] == ' ')
+ break; // "a b" "x y"
+ if (cmdline[i] == '"')
+ in_quoted = !in_quoted;
+ }
+
+ ret = cmdline.substr(0, i);
+ if (ret[0] == '"' && ret[i - 1] == '"')
+ ret = ret.substr(1, ret.size() - 2);
+ cmdline = cmdline.substr(i);
+ return ret;
+}
+
+static void parseCommandLine(LPWSTR wincmdline,
+ std::string& lang,
+ std::string& srcfile,
+ std::string& dfile,
+ std::string& objfile,
+ std::string& prefix,
+ std::string& clpath,
+ std::string& binpath,
+ std::string& rest) {
+ std::string cmdline = cmsys::Encoding::ToNarrow(wincmdline);
+ /* self */ getArg(cmdline);
+ lang = getArg(cmdline);
+ srcfile = getArg(cmdline);
+ dfile = getArg(cmdline);
+ objfile = getArg(cmdline);
+ prefix = getArg(cmdline);
+ clpath = getArg(cmdline);
+ binpath = getArg(cmdline);
+ rest = trimLeadingSpace(cmdline);
+}
+
+// Not all backslashes need to be escaped in a depfile, but it's easier that
+// way. See the re2c grammar in ninja's source code for more info.
+static void escapePath(std::string &path) {
+ replaceAll(path, "\\", "\\\\");
+ replaceAll(path, " ", "\\ ");
+}
+
+static void outputDepFile(const std::string& dfile, const std::string& objfile,
+ std::vector<std::string>& incs) {
+
+ if (dfile.empty())
+ return;
+
+ // strip duplicates
+ std::sort(incs.begin(), incs.end());
+ incs.erase(std::unique(incs.begin(), incs.end()), incs.end());
+
+ FILE* out = cmsys::SystemTools::Fopen(dfile.c_str(), "wb");
+
+ // FIXME should this be fatal or not? delete obj? delete d?
+ if (!out)
+ return;
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ replaceAll(cwd, "/", "\\");
+ cwd += "\\";
+
+ std::string tmp = objfile;
+ escapePath(tmp);
+ fprintf(out, "%s: \\\n", tmp.c_str());
+
+ std::vector<std::string>::iterator it = incs.begin();
+ for (; it != incs.end(); ++it) {
+ tmp = *it;
+ // The paths need to match the ones used to identify build artifacts in the
+ // build.ninja file. Therefore we need to canonicalize the path to use
+ // backward slashes and relativize the path to the build directory.
+ replaceAll(tmp, "/", "\\");
+ if (startsWith(tmp, cwd))
+ tmp = tmp.substr(cwd.size());
+ escapePath(tmp);
+ fprintf(out, "%s \\\n", tmp.c_str());
+ }
+
+ fprintf(out, "\n");
+ fclose(out);
+}
+
+
+bool contains(const std::string& str, const std::string& what) {
+ return str.find(what) != std::string::npos;
+}
+
+std::string replace(const std::string& str, const std::string& what,
+ const std::string& replacement) {
+ size_t pos = str.find(what);
+ if (pos == std::string::npos)
+ return str;
+ std::string replaced = str;
+ return replaced.replace(pos, what.size(), replacement);
+}
+
+
+
+static int process( const std::string& srcfilename,
+ const std::string& dfile,
+ const std::string& objfile,
+ const std::string& prefix,
+ const std::string& cmd,
+ const std::string& dir = "",
+ bool quiet = false)
+{
+ std::string output;
+ // break up command line into a vector
+ std::vector<std::string> args;
+ cmSystemTools::ParseWindowsCommandLine(cmd.c_str(), args);
+ // convert to correct vector type for RunSingleCommand
+ std::vector<std::string> command;
+ for(std::vector<std::string>::iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ command.push_back(i->c_str());
+ }
+ // run the command
+ int exit_code = 0;
+ bool run = cmSystemTools::RunSingleCommand(command, &output, &exit_code,
+ dir.c_str(), cmSystemTools::OUTPUT_NONE);
+
+ // process the include directives and output everything else
+ std::stringstream ss(output);
+ std::string line;
+ std::vector<std::string> includes;
+ bool isFirstLine = true; // cl prints always first the source filename
+ while (std::getline(ss, line)) {
+ if (startsWith(line, prefix)) {
+ std::string inc = trimLeadingSpace(line.substr(prefix.size()).c_str());
+ if (inc[inc.size() - 1] == '\r') // blech, stupid \r\n
+ inc = inc.substr(0, inc.size() - 1);
+ includes.push_back(inc);
+ } else {
+ if (!isFirstLine || !startsWith(line, srcfilename)) {
+ if (!quiet || exit_code != 0) {
+ fprintf(stdout, "%s\n", line.c_str());
+ }
+ } else {
+ isFirstLine = false;
+ }
+ }
+ }
+
+ // don't update .d until/unless we succeed compilation
+ if (run && exit_code == 0)
+ outputDepFile(dfile, objfile, includes);
+
+ return exit_code;
+}
+
+
+int main() {
+
+ // Use the Win32 API instead of argc/argv so we can avoid interpreting the
+ // rest of command line after the .d and .obj. Custom parsing seemed
+ // preferable to the ugliness you get into in trying to re-escape quotes for
+ // subprocesses, so by avoiding argc/argv, the subprocess is called with
+ // the same command line verbatim.
+
+ std::string lang, srcfile, dfile, objfile, prefix, cl, binpath, rest;
+ parseCommandLine(GetCommandLineW(), lang, srcfile, dfile, objfile,
+ prefix, cl, binpath, rest);
+
+ // needed to suppress filename output of msvc tools
+ std::string srcfilename;
+ {
+ std::string::size_type pos = srcfile.rfind("\\");
+ if (pos == std::string::npos) {
+ srcfilename = srcfile;
+ } else {
+ srcfilename = srcfile.substr(pos + 1);
+ }
+ }
+
+ std::string nol = " /nologo ";
+ std::string show = " /showIncludes ";
+ if (lang == "C" || lang == "CXX") {
+ return process(srcfilename, dfile, objfile, prefix,
+ binpath + nol + show + rest);
+ } else if (lang == "RC") {
+ // "misuse" cl.exe to get headers from .rc files
+
+ std::string clrest = rest;
+ // rc: /fo x.dir\x.rc.res -> cl: /out:x.dir\x.rc.res.dep.obj
+ clrest = replace(clrest, "/fo", "/out:");
+ clrest = replace(clrest, objfile, objfile + ".dep.obj ");
+
+ // rc: src\x\x.rc -> cl: /Tc src\x\x.rc
+ if (srcfile.find(" ") != std::string::npos)
+ srcfile = "\"" + srcfile + "\"";
+ clrest = replace(clrest, srcfile, "/Tc " + srcfile);
+
+ cl = "\"" + cl + "\" /P /DRC_INVOKED ";
+
+ // call cl in object dir so the .i is generated there
+ std::string objdir;
+ {
+ std::string::size_type pos = objfile.rfind("\\");
+ if (pos != std::string::npos) {
+ objdir = objfile.substr(0, pos);
+ }
+ }
+
+ // extract dependencies with cl.exe
+ int exit_code = process(srcfilename, dfile, objfile,
+ prefix, cl + nol + show + clrest, objdir, true);
+
+ if (exit_code != 0)
+ return exit_code;
+
+ // compile rc file with rc.exe
+ return process(srcfilename, "" , objfile, prefix, binpath + " " + rest);
+ }
+
+ usage("Invalid language specified.");
+ return 1;
+}
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
new file mode 100644
index 0000000000..a0c67e00ae
--- /dev/null
+++ b/Source/cmcmd.cxx
@@ -0,0 +1,1447 @@
+/*============================================================================
+ 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 "cmcmd.h"
+#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmQtAutoGenerators.h"
+#include "cmVersion.h"
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
+# include <cmsys/Terminal.h>
+#endif
+
+#include <cmsys/Directory.hxx>
+#include <cmsys/Process.h>
+#include <cmsys/FStream.hxx>
+
+#if defined(CMAKE_HAVE_VS_GENERATORS)
+#include "cmCallVisualStudioMacro.h"
+#include "cmVisualStudioWCEPlatformParser.h"
+#endif
+
+#include <time.h>
+
+#include <stdlib.h> // required for atoi
+
+void CMakeCommandUsage(const char* program)
+{
+ cmOStringStream errorStream;
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ errorStream
+ << "cmake version " << cmVersion::GetCMakeVersion() << "\n";
+#else
+ errorStream
+ << "cmake bootstrap\n";
+#endif
+ // If you add new commands, change here,
+ // and in cmakemain.cxx in the options table
+ errorStream
+ << "Usage: " << program << " -E [command] [arguments ...]\n"
+ << "Available commands: \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 "
+ "changed\n"
+ << " 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 "
+ "it\n"
+ << " remove_directory dir - remove a directory and its contents\n"
+ << " rename oldname newname - rename a file or directory "
+ "(on one volume)\n"
+ << " tar [cxt][vfz][cvfj] 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"
+ << " touch file - touch a file.\n"
+ << " touch_nocreate file - touch a file but do not create it.\n"
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ << "Available on Windows only:\n"
+ << " delete_regv key - delete registry value\n"
+ << " env_vs8_wince sdkname - displays a batch file which sets the "
+ "environment for the provided Windows CE SDK installed in VS2005\n"
+ << " env_vs9_wince sdkname - displays a batch file which sets the "
+ "environment for the provided Windows CE SDK installed in VS2008\n"
+ << " write_regv key value - write registry value\n"
+#else
+ << "Available on UNIX only:\n"
+ << " create_symlink old new - create a symbolic link new -> old\n"
+#endif
+ ;
+
+ cmSystemTools::Error(errorStream.str().c_str());
+}
+
+int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
+{
+ // IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx
+ if (args.size() > 1)
+ {
+ // Copy file
+ if (args[1] == "copy" && args.size() == 4)
+ {
+ if(!cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str()))
+ {
+ std::cerr << "Error copying file \"" << args[2]
+ << "\" to \"" << args[3] << "\".\n";
+ return 1;
+ }
+ return 0;
+ }
+
+ // Copy file if different.
+ if (args[1] == "copy_if_different" && args.size() == 4)
+ {
+ if(!cmSystemTools::CopyFileIfDifferent(args[2].c_str(),
+ args[3].c_str()))
+ {
+ std::cerr << "Error copying file (if different) from \""
+ << args[2] << "\" to \"" << args[3]
+ << "\".\n";
+ return 1;
+ }
+ return 0;
+ }
+
+ // Copy directory content
+ if (args[1] == "copy_directory" && args.size() == 4)
+ {
+ if(!cmSystemTools::CopyADirectory(args[2].c_str(), args[3].c_str()))
+ {
+ std::cerr << "Error copying directory from \""
+ << args[2] << "\" to \"" << args[3]
+ << "\".\n";
+ return 1;
+ }
+ return 0;
+ }
+
+ // Rename a file or directory
+ if (args[1] == "rename" && args.size() == 4)
+ {
+ if(!cmSystemTools::RenameFile(args[2].c_str(), args[3].c_str()))
+ {
+ std::string e = cmSystemTools::GetLastSystemError();
+ std::cerr << "Error renaming from \""
+ << args[2] << "\" to \"" << args[3]
+ << "\": " << e << "\n";
+ return 1;
+ }
+ return 0;
+ }
+
+ // Compare files
+ if (args[1] == "compare_files" && args.size() == 4)
+ {
+ if(cmSystemTools::FilesDiffer(args[2].c_str(), args[3].c_str()))
+ {
+ std::cerr << "Files \""
+ << args[2] << "\" to \"" << args[3]
+ << "\" are different.\n";
+ return 1;
+ }
+ return 0;
+ }
+
+ // Echo string
+ else if (args[1] == "echo" )
+ {
+ unsigned int cc;
+ const char* space = "";
+ for ( cc = 2; cc < args.size(); cc ++ )
+ {
+ std::cout << space << args[cc];
+ space = " ";
+ }
+ std::cout << std::endl;
+ return 0;
+ }
+
+ // Echo string no new line
+ else if (args[1] == "echo_append" )
+ {
+ unsigned int cc;
+ const char* space = "";
+ for ( cc = 2; cc < args.size(); cc ++ )
+ {
+ std::cout << space << args[cc];
+ space = " ";
+ }
+ return 0;
+ }
+
+ else if (args[1] == "env" )
+ {
+ std::vector<std::string>::const_iterator ai = args.begin() + 2;
+ std::vector<std::string>::const_iterator ae = args.end();
+ for(; ai != ae; ++ai)
+ {
+ std::string const& a = *ai;
+ if(cmHasLiteralPrefix(a, "--unset="))
+ {
+ // Unset environment variable.
+ cmSystemTools::UnPutEnv(a.c_str() + 8);
+ }
+ else if(!a.empty() && a[0] == '-')
+ {
+ // Environment variable and command names cannot start in '-',
+ // so this must be an unknown option.
+ std::cerr << "cmake -E env: unknown option '" << a << "'"
+ << std::endl;
+ return 1;
+ }
+ else if(a.find("=") != a.npos)
+ {
+ // Set environment variable.
+ cmSystemTools::PutEnv(a.c_str());
+ }
+ else
+ {
+ // This is the beginning of the command.
+ break;
+ }
+ }
+
+ if(ai == ae)
+ {
+ std::cerr << "cmake -E env: no command given" << std::endl;
+ return 1;
+ }
+
+ // Execute command from remaining arguments.
+ std::vector<std::string> cmd(ai, ae);
+ int retval;
+ if(cmSystemTools::RunSingleCommand(
+ cmd, 0, &retval, NULL, cmSystemTools::OUTPUT_PASSTHROUGH))
+ {
+ return retval;
+ }
+ return 1;
+ }
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ // Command to create a symbolic link. Fails on platforms not
+ // supporting them.
+ else if (args[1] == "environment" )
+ {
+ std::vector<std::string> env = cmSystemTools::GetEnvironmentVariables();
+ std::vector<std::string>::iterator it;
+ for ( it = env.begin(); it != env.end(); ++ it )
+ {
+ std::cout << *it << std::endl;
+ }
+ return 0;
+ }
+#endif
+
+ else if (args[1] == "make_directory" && args.size() == 3)
+ {
+ if(!cmSystemTools::MakeDirectory(args[2].c_str()))
+ {
+ std::cerr << "Error making directory \"" << args[2]
+ << "\".\n";
+ return 1;
+ }
+ return 0;
+ }
+
+ else if (args[1] == "remove_directory" && args.size() == 3)
+ {
+ if(cmSystemTools::FileIsDirectory(args[2].c_str()) &&
+ !cmSystemTools::RemoveADirectory(args[2].c_str()))
+ {
+ std::cerr << "Error removing directory \"" << args[2]
+ << "\".\n";
+ return 1;
+ }
+ return 0;
+ }
+
+ // Remove file
+ else if (args[1] == "remove" && args.size() > 2)
+ {
+ bool force = false;
+ for (std::string::size_type cc = 2; cc < args.size(); cc ++)
+ {
+ if(args[cc] == "\\-f" || args[cc] == "-f")
+ {
+ force = true;
+ }
+ else
+ {
+ // Complain if the file could not be removed, still exists,
+ // and the -f option was not given.
+ if(!cmSystemTools::RemoveFile(args[cc].c_str()) && !force &&
+ cmSystemTools::FileExists(args[cc].c_str()))
+ {
+ return 1;
+ }
+ }
+ }
+ return 0;
+ }
+ // Touch file
+ else if (args[1] == "touch" && args.size() > 2)
+ {
+ for (std::string::size_type cc = 2; cc < args.size(); cc ++)
+ {
+ // Complain if the file could not be removed, still exists,
+ // and the -f option was not given.
+ if(!cmSystemTools::Touch(args[cc].c_str(), true))
+ {
+ return 1;
+ }
+ }
+ return 0;
+ }
+ // Touch file
+ else if (args[1] == "touch_nocreate" && args.size() > 2)
+ {
+ for (std::string::size_type cc = 2; cc < args.size(); cc ++)
+ {
+ // Complain if the file could not be removed, still exists,
+ // and the -f option was not given.
+ if(!cmSystemTools::Touch(args[cc].c_str(), false))
+ {
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ // Sleep command
+ else if (args[1] == "sleep" && args.size() > 2)
+ {
+ double total = 0;
+ for(size_t i = 2; i < args.size(); ++i)
+ {
+ double num = 0.0;
+ char unit;
+ char extra;
+ int n = sscanf(args[i].c_str(), "%lg%c%c", &num, &unit, &extra);
+ if((n == 1 || (n == 2 && unit == 's')) && num >= 0)
+ {
+ total += num;
+ }
+ else
+ {
+ std::cerr << "Unknown sleep time format \"" << args[i] << "\".\n";
+ return 1;
+ }
+ }
+ if(total > 0)
+ {
+ cmSystemTools::Delay(static_cast<unsigned int>(total*1000));
+ }
+ return 0;
+ }
+
+ // Clock command
+ else if (args[1] == "time" && args.size() > 2)
+ {
+ std::string command = args[2];
+ for (std::string::size_type cc = 3; cc < args.size(); cc ++)
+ {
+ command += " ";
+ command += args[cc];
+ }
+
+ clock_t clock_start, clock_finish;
+ time_t time_start, time_finish;
+
+ time(&time_start);
+ clock_start = clock();
+ int ret =0;
+ cmSystemTools::RunSingleCommand(command.c_str(), 0, &ret);
+
+ clock_finish = clock();
+ time(&time_finish);
+
+ double clocks_per_sec = static_cast<double>(CLOCKS_PER_SEC);
+ std::cout << "Elapsed time: "
+ << static_cast<long>(time_finish - time_start) << " s. (time)"
+ << ", "
+ << static_cast<double>(clock_finish - clock_start) / clocks_per_sec
+ << " s. (clock)"
+ << "\n";
+ return ret;
+ }
+ // Command to calculate the md5sum of a file
+ else if (args[1] == "md5sum" && args.size() >= 3)
+ {
+ char md5out[32];
+ int retval = 0;
+ for (std::string::size_type cc = 2; cc < args.size(); cc ++)
+ {
+ const char *filename = args[cc].c_str();
+ // Cannot compute md5sum of a directory
+ if(cmSystemTools::FileIsDirectory(filename))
+ {
+ std::cerr << "Error: " << filename << " is a directory" << std::endl;
+ retval++;
+ }
+ else if(!cmSystemTools::ComputeFileMD5(filename, md5out))
+ {
+ // To mimic md5sum behavior in a shell:
+ std::cerr << filename << ": No such file or directory" << std::endl;
+ retval++;
+ }
+ else
+ {
+ std::cout << std::string(md5out,32) << " " << filename << std::endl;
+ }
+ }
+ return retval;
+ }
+
+ // Command to change directory and run a program.
+ else if (args[1] == "chdir" && args.size() >= 4)
+ {
+ std::string directory = args[2];
+ if(!cmSystemTools::FileExists(directory.c_str()))
+ {
+ cmSystemTools::Error("Directory does not exist for chdir command: ",
+ args[2].c_str());
+ return 1;
+ }
+
+ std::string command = "\"";
+ command += args[3];
+ command += "\"";
+ for (std::string::size_type cc = 4; cc < args.size(); cc ++)
+ {
+ command += " \"";
+ command += args[cc];
+ command += "\"";
+ }
+ int retval = 0;
+ int timeout = 0;
+ if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
+ directory.c_str(), cmSystemTools::OUTPUT_NORMAL, timeout) )
+ {
+ return retval;
+ }
+
+ return 1;
+ }
+
+ // Command to start progress for a build
+ else if (args[1] == "cmake_progress_start" && args.size() == 4)
+ {
+ // basically remove the directory
+ std::string dirName = args[2];
+ dirName += "/Progress";
+ cmSystemTools::RemoveADirectory(dirName.c_str());
+
+ // is the last argument a filename that exists?
+ FILE *countFile = cmsys::SystemTools::Fopen(args[3].c_str(),"r");
+ int count;
+ if (countFile)
+ {
+ if (1!=fscanf(countFile,"%i",&count))
+ {
+ cmSystemTools::Message("Could not read from count file.");
+ }
+ fclose(countFile);
+ }
+ else
+ {
+ count = atoi(args[3].c_str());
+ }
+ if (count)
+ {
+ cmSystemTools::MakeDirectory(dirName.c_str());
+ // write the count into the directory
+ std::string fName = dirName;
+ fName += "/count.txt";
+ FILE *progFile = cmsys::SystemTools::Fopen(fName.c_str(),"w");
+ if (progFile)
+ {
+ fprintf(progFile,"%i\n",count);
+ fclose(progFile);
+ }
+ }
+ return 0;
+ }
+
+ // Command to report progress for a build
+ else if (args[1] == "cmake_progress_report" && args.size() >= 3)
+ {
+ std::string dirName = args[2];
+ dirName += "/Progress";
+ std::string fName;
+ FILE *progFile;
+
+ // read the count
+ fName = dirName;
+ fName += "/count.txt";
+ progFile = cmsys::SystemTools::Fopen(fName.c_str(),"r");
+ int count = 0;
+ if (!progFile)
+ {
+ return 0;
+ }
+ else
+ {
+ if (1!=fscanf(progFile,"%i",&count))
+ {
+ cmSystemTools::Message("Could not read from progress file.");
+ }
+ fclose(progFile);
+ }
+ unsigned int i;
+ for (i = 3; i < args.size(); ++i)
+ {
+ fName = dirName;
+ fName += "/";
+ fName += args[i];
+ progFile = cmsys::SystemTools::Fopen(fName.c_str(),"w");
+ if (progFile)
+ {
+ fprintf(progFile,"empty");
+ fclose(progFile);
+ }
+ }
+ int fileNum = static_cast<int>
+ (cmsys::Directory::GetNumberOfFilesInDirectory(dirName.c_str()));
+ if (count > 0)
+ {
+ // print the progress
+ fprintf(stdout,"[%3i%%] ",((fileNum-3)*100)/count);
+ }
+ return 0;
+ }
+
+ // Command to create a symbolic link. Fails on platforms not
+ // supporting them.
+ else if (args[1] == "create_symlink" && args.size() == 4)
+ {
+ const char* destinationFileName = args[3].c_str();
+ if((cmSystemTools::FileExists(destinationFileName) ||
+ cmSystemTools::FileIsSymlink(destinationFileName)) &&
+ !cmSystemTools::RemoveFile(destinationFileName))
+ {
+ std::string emsg = cmSystemTools::GetLastSystemError();
+ std::cerr <<
+ "failed to create symbolic link '" << destinationFileName <<
+ "' because existing path cannot be removed: " << emsg << "\n";
+ return 1;
+ }
+ if(!cmSystemTools::CreateSymlink(args[2].c_str(), args[3].c_str()))
+ {
+ std::string emsg = cmSystemTools::GetLastSystemError();
+ std::cerr <<
+ "failed to create symbolic link '" << destinationFileName <<
+ "': " << emsg << "\n";
+ return 1;
+ }
+ return 0;
+ }
+
+ // Internal CMake shared library support.
+ else if (args[1] == "cmake_symlink_library" && args.size() == 5)
+ {
+ return cmcmd::SymlinkLibrary(args);
+ }
+ // Internal CMake versioned executable support.
+ else if (args[1] == "cmake_symlink_executable" && args.size() == 4)
+ {
+ return cmcmd::SymlinkExecutable(args);
+ }
+
+#if defined(CMAKE_HAVE_VS_GENERATORS)
+ // Internal CMake support for calling Visual Studio macros.
+ else if (args[1] == "cmake_call_visual_studio_macro" && args.size() >= 4)
+ {
+ // args[2] = full path to .sln file or "ALL"
+ // args[3] = name of Visual Studio macro to call
+ // args[4..args.size()-1] = [optional] args for Visual Studio macro
+
+ std::string macroArgs;
+
+ if (args.size() > 4)
+ {
+ macroArgs = args[4];
+
+ for (size_t i = 5; i < args.size(); ++i)
+ {
+ macroArgs += " ";
+ macroArgs += args[i];
+ }
+ }
+
+ return cmCallVisualStudioMacro::CallMacro(args[2], args[3],
+ macroArgs, true);
+ }
+#endif
+
+ // Internal CMake dependency scanning support.
+ else if (args[1] == "cmake_depends" && args.size() >= 6)
+ {
+ // Use the make system's VERBOSE environment variable to enable
+ // verbose output. This can be skipped by also setting CMAKE_NO_VERBOSE
+ // (which is set by the Eclipse and KDevelop generators).
+ bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
+ && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
+
+ // Create a cmake object instance to process dependencies.
+ cmake cm;
+ std::string gen;
+ std::string homeDir;
+ std::string startDir;
+ std::string homeOutDir;
+ std::string startOutDir;
+ std::string depInfo;
+ bool color = false;
+ if(args.size() >= 8)
+ {
+ // Full signature:
+ //
+ // -E cmake_depends <generator>
+ // <home-src-dir> <start-src-dir>
+ // <home-out-dir> <start-out-dir>
+ // <dep-info> [--color=$(COLOR)]
+ //
+ // All paths are provided.
+ gen = args[2];
+ homeDir = args[3];
+ startDir = args[4];
+ homeOutDir = args[5];
+ startOutDir = args[6];
+ depInfo = args[7];
+ if(args.size() >= 9 &&
+ args[8].length() >= 8 &&
+ args[8].substr(0, 8) == "--color=")
+ {
+ // Enable or disable color based on the switch value.
+ color = (args[8].size() == 8 ||
+ cmSystemTools::IsOn(args[8].substr(8).c_str()));
+ }
+ }
+ else
+ {
+ // Support older signature for existing makefiles:
+ //
+ // -E cmake_depends <generator>
+ // <home-out-dir> <start-out-dir>
+ // <dep-info>
+ //
+ // Just pretend the source directories are the same as the
+ // binary directories so at least scanning will work.
+ gen = args[2];
+ homeDir = args[3];
+ startDir = args[4];
+ homeOutDir = args[3];
+ startOutDir = args[3];
+ depInfo = args[5];
+ }
+
+ // Create a local generator configured for the directory in
+ // which dependencies will be scanned.
+ homeDir = cmSystemTools::CollapseFullPath(homeDir.c_str());
+ startDir = cmSystemTools::CollapseFullPath(startDir.c_str());
+ homeOutDir = cmSystemTools::CollapseFullPath(homeOutDir.c_str());
+ startOutDir = cmSystemTools::CollapseFullPath(startOutDir.c_str());
+ cm.SetHomeDirectory(homeDir);
+ cm.SetStartDirectory(startDir);
+ cm.SetHomeOutputDirectory(homeOutDir);
+ cm.SetStartOutputDirectory(startOutDir);
+ if(cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen))
+ {
+ cm.SetGlobalGenerator(ggd);
+ cmsys::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
+ lgd->GetMakefile()->SetStartDirectory(startDir);
+ lgd->GetMakefile()->SetStartOutputDirectory(startOutDir);
+ lgd->GetMakefile()->MakeStartDirectoriesCurrent();
+
+ // Actually scan dependencies.
+ return lgd->UpdateDependencies(depInfo.c_str(),
+ verbose, color)? 0 : 2;
+ }
+ return 1;
+ }
+
+ // Internal CMake link script support.
+ else if (args[1] == "cmake_link_script" && args.size() >= 3)
+ {
+ return cmcmd::ExecuteLinkScript(args);
+ }
+
+ // Internal CMake unimplemented feature notification.
+ else if (args[1] == "cmake_unimplemented_variable")
+ {
+ std::cerr << "Feature not implemented for this platform.";
+ if(args.size() == 3)
+ {
+ std::cerr << " Variable " << args[2] << " is not set.";
+ }
+ std::cerr << std::endl;
+ return 1;
+ }
+ else if (args[1] == "vs_link_exe")
+ {
+ return cmcmd::VisualStudioLink(args, 1);
+ }
+ else if (args[1] == "vs_link_dll")
+ {
+ return cmcmd::VisualStudioLink(args, 2);
+ }
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ // Internal CMake color makefile support.
+ else if (args[1] == "cmake_echo_color")
+ {
+ return cmcmd::ExecuteEchoColor(args);
+ }
+ else if (args[1] == "cmake_autogen" && args.size() >= 4)
+ {
+ cmQtAutoGenerators autogen;
+ std::string const& config = args[3];
+ bool autogenSuccess = autogen.Run(args[2], config);
+ return autogenSuccess ? 0 : 1;
+ }
+#endif
+
+ // Tar files
+ else if (args[1] == "tar" && args.size() > 3)
+ {
+ std::string flags = args[2];
+ std::string outFile = args[3];
+ std::vector<std::string> files;
+ for (std::string::size_type cc = 4; cc < args.size(); cc ++)
+ {
+ files.push_back(args[cc]);
+ }
+ bool gzip = false;
+ bool bzip2 = false;
+ bool verbose = false;
+ if ( flags.find_first_of('j') != flags.npos )
+ {
+ bzip2 = true;
+ }
+ if ( flags.find_first_of('z') != flags.npos )
+ {
+ gzip = true;
+ }
+ if ( flags.find_first_of('v') != flags.npos )
+ {
+ verbose = true;
+ }
+
+ if ( flags.find_first_of('t') != flags.npos )
+ {
+ if ( !cmSystemTools::ListTar(outFile.c_str(), gzip, verbose) )
+ {
+ cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
+ return 1;
+ }
+ }
+ else if ( flags.find_first_of('c') != flags.npos )
+ {
+ if ( !cmSystemTools::CreateTar(
+ outFile.c_str(), files, gzip, bzip2, verbose) )
+ {
+ cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
+ return 1;
+ }
+ }
+ else if ( flags.find_first_of('x') != flags.npos )
+ {
+ if ( !cmSystemTools::ExtractTar(
+ outFile.c_str(), gzip, verbose) )
+ {
+ cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
+ return 1;
+ }
+#ifdef WIN32
+ // OK, on windows 7 after we untar some files,
+ // sometimes we can not rename the directory after
+ // the untar is done. This breaks the external project
+ // untar and rename code. So, by default we will wait
+ // 1/10th of a second after the untar. If CMAKE_UNTAR_DELAY
+ // is set in the env, its value will be used instead of 100.
+ int delay = 100;
+ const char* delayVar = cmSystemTools::GetEnv("CMAKE_UNTAR_DELAY");
+ if(delayVar)
+ {
+ delay = atoi(delayVar);
+ }
+ if(delay)
+ {
+ cmSystemTools::Delay(delay);
+ }
+#endif
+ }
+ return 0;
+ }
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ // Internal CMake Fortran module support.
+ else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4)
+ {
+ return cmDependsFortran::CopyModule(args)? 0 : 1;
+ }
+#endif
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ // Write registry value
+ else if (args[1] == "write_regv" && args.size() > 3)
+ {
+ return cmSystemTools::WriteRegistryValue(args[2].c_str(),
+ args[3].c_str()) ? 0 : 1;
+ }
+
+ // Delete registry value
+ else if (args[1] == "delete_regv" && args.size() > 2)
+ {
+ return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
+ }
+ // Remove file
+ else if (args[1] == "comspec" && args.size() > 2)
+ {
+ std::cerr << "Win9x helper \"cmake -E comspec\" no longer supported\n";
+ return 1;
+ }
+ else if (args[1] == "env_vs8_wince" && args.size() == 3)
+ {
+ return cmcmd::WindowsCEEnvironment("8.0", args[2]);
+ }
+ else if (args[1] == "env_vs9_wince" && args.size() == 3)
+ {
+ return cmcmd::WindowsCEEnvironment("9.0", args[2]);
+ }
+#endif
+ }
+
+ ::CMakeCommandUsage(args[0].c_str());
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+int cmcmd::SymlinkLibrary(std::vector<std::string>& args)
+{
+ int result = 0;
+ std::string realName = args[2];
+ std::string soName = args[3];
+ std::string name = args[4];
+ if(soName != realName)
+ {
+ if(!cmcmd::SymlinkInternal(realName, soName))
+ {
+ cmSystemTools::ReportLastSystemError("cmake_symlink_library");
+ result = 1;
+ }
+ }
+ if(name != soName)
+ {
+ if(!cmcmd::SymlinkInternal(soName, name))
+ {
+ cmSystemTools::ReportLastSystemError("cmake_symlink_library");
+ result = 1;
+ }
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+int cmcmd::SymlinkExecutable(std::vector<std::string>& args)
+{
+ int result = 0;
+ std::string realName = args[2];
+ std::string name = args[3];
+ if(name != realName)
+ {
+ if(!cmcmd::SymlinkInternal(realName, name))
+ {
+ cmSystemTools::ReportLastSystemError("cmake_symlink_executable");
+ result = 1;
+ }
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+bool cmcmd::SymlinkInternal(std::string const& file, std::string const& link)
+{
+ if(cmSystemTools::FileExists(link.c_str()) ||
+ cmSystemTools::FileIsSymlink(link.c_str()))
+ {
+ cmSystemTools::RemoveFile(link.c_str());
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ return cmSystemTools::CopyFileAlways(file.c_str(), link.c_str());
+#else
+ std::string linktext = cmSystemTools::GetFilenameName(file);
+ return cmSystemTools::CreateSymlink(linktext.c_str(), link.c_str());
+#endif
+}
+
+//----------------------------------------------------------------------------
+#ifdef CMAKE_BUILD_WITH_CMAKE
+int cmcmd::ExecuteEchoColor(std::vector<std::string>& args)
+{
+ // The arguments are
+ // argv[0] == <cmake-executable>
+ // argv[1] == cmake_echo_color
+
+ bool enabled = true;
+ int color = cmsysTerminal_Color_Normal;
+ bool newline = true;
+ for(unsigned int i=2; i < args.size(); ++i)
+ {
+ if(args[i].find("--switch=") == 0)
+ {
+ // Enable or disable color based on the switch value.
+ std::string value = args[i].substr(9);
+ if(!value.empty())
+ {
+ if(cmSystemTools::IsOn(value.c_str()))
+ {
+ enabled = true;
+ }
+ else
+ {
+ enabled = false;
+ }
+ }
+ }
+ else if(args[i] == "--normal")
+ {
+ color = cmsysTerminal_Color_Normal;
+ }
+ else if(args[i] == "--black")
+ {
+ color = cmsysTerminal_Color_ForegroundBlack;
+ }
+ else if(args[i] == "--red")
+ {
+ color = cmsysTerminal_Color_ForegroundRed;
+ }
+ else if(args[i] == "--green")
+ {
+ color = cmsysTerminal_Color_ForegroundGreen;
+ }
+ else if(args[i] == "--yellow")
+ {
+ color = cmsysTerminal_Color_ForegroundYellow;
+ }
+ else if(args[i] == "--blue")
+ {
+ color = cmsysTerminal_Color_ForegroundBlue;
+ }
+ else if(args[i] == "--magenta")
+ {
+ color = cmsysTerminal_Color_ForegroundMagenta;
+ }
+ else if(args[i] == "--cyan")
+ {
+ color = cmsysTerminal_Color_ForegroundCyan;
+ }
+ else if(args[i] == "--white")
+ {
+ color = cmsysTerminal_Color_ForegroundWhite;
+ }
+ else if(args[i] == "--bold")
+ {
+ color |= cmsysTerminal_Color_ForegroundBold;
+ }
+ else if(args[i] == "--no-newline")
+ {
+ newline = false;
+ }
+ else if(args[i] == "--newline")
+ {
+ newline = true;
+ }
+ else
+ {
+ // Color is enabled. Print with the current color.
+ cmSystemTools::MakefileColorEcho(color, args[i].c_str(),
+ newline, enabled);
+ }
+ }
+
+ return 0;
+}
+#else
+int cmcmd::ExecuteEchoColor(std::vector<std::string>&)
+{
+ return 1;
+}
+#endif
+
+//----------------------------------------------------------------------------
+int cmcmd::ExecuteLinkScript(std::vector<std::string>& args)
+{
+ // The arguments are
+ // argv[0] == <cmake-executable>
+ // argv[1] == cmake_link_script
+ // argv[2] == <link-script-name>
+ // argv[3] == --verbose=?
+ bool verbose = false;
+ if(args.size() >= 4)
+ {
+ if(args[3].find("--verbose=") == 0)
+ {
+ if(!cmSystemTools::IsOff(args[3].substr(10).c_str()))
+ {
+ verbose = true;
+ }
+ }
+ }
+
+ // Allocate a process instance.
+ cmsysProcess* cp = cmsysProcess_New();
+ if(!cp)
+ {
+ std::cerr << "Error allocating process instance in link script."
+ << std::endl;
+ return 1;
+ }
+
+ // Children should share stdout and stderr with this process.
+ cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
+ cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
+
+ // Run the command lines verbatim.
+ cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
+
+ // Read command lines from the script.
+ cmsys::ifstream fin(args[2].c_str());
+ if(!fin)
+ {
+ std::cerr << "Error opening link script \""
+ << args[2] << "\"" << std::endl;
+ return 1;
+ }
+
+ // Run one command at a time.
+ std::string command;
+ int result = 0;
+ while(result == 0 && cmSystemTools::GetLineFromStream(fin, command))
+ {
+ // Skip empty command lines.
+ if(command.find_first_not_of(" \t") == command.npos)
+ {
+ continue;
+ }
+
+ // Setup this command line.
+ const char* cmd[2] = {command.c_str(), 0};
+ cmsysProcess_SetCommand(cp, cmd);
+
+ // Report the command if verbose output is enabled.
+ if(verbose)
+ {
+ std::cout << command << std::endl;
+ }
+
+ // Run the command and wait for it to exit.
+ cmsysProcess_Execute(cp);
+ cmsysProcess_WaitForExit(cp, 0);
+
+ // Report failure if any.
+ switch(cmsysProcess_GetState(cp))
+ {
+ case cmsysProcess_State_Exited:
+ {
+ int value = cmsysProcess_GetExitValue(cp);
+ if(value != 0)
+ {
+ result = value;
+ }
+ }
+ break;
+ case cmsysProcess_State_Exception:
+ std::cerr << "Error running link command: "
+ << cmsysProcess_GetExceptionString(cp) << std::endl;
+ result = 1;
+ break;
+ case cmsysProcess_State_Error:
+ std::cerr << "Error running link command: "
+ << cmsysProcess_GetErrorString(cp) << std::endl;
+ result = 2;
+ break;
+ default:
+ break;
+ };
+ }
+
+ // Free the process instance.
+ cmsysProcess_Delete(cp);
+
+ // Return the final resulting return value.
+ return result;
+}
+
+//----------------------------------------------------------------------------
+int cmcmd::WindowsCEEnvironment(const char* version, const std::string& name)
+{
+#if defined(CMAKE_HAVE_VS_GENERATORS)
+ cmVisualStudioWCEPlatformParser parser(name.c_str());
+ parser.ParseVersion(version);
+ if (parser.Found())
+ {
+ std::cout << "@echo off" << std::endl;
+ std::cout << "echo Environment Selection: " << name << std::endl;
+ std::cout << "set PATH=" << parser.GetPathDirectories() << std::endl;
+ std::cout << "set INCLUDE=" << parser.GetIncludeDirectories() <<std::endl;
+ std::cout << "set LIB=" << parser.GetLibraryDirectories() <<std::endl;
+ return 0;
+ }
+#else
+ (void)version;
+#endif
+
+ std::cerr << "Could not find " << name;
+ return -1;
+}
+
+// For visual studio 2005 and newer manifest files need to be embedded into
+// exe and dll's. This code does that in such a way that incremental linking
+// still works.
+int cmcmd::VisualStudioLink(std::vector<std::string>& args, int type)
+{
+ if(args.size() < 2)
+ {
+ return -1;
+ }
+ bool verbose = false;
+ if(cmSystemTools::GetEnv("VERBOSE"))
+ {
+ verbose = true;
+ }
+ std::vector<std::string> expandedArgs;
+ for(std::vector<std::string>::iterator i = args.begin();
+ i != args.end(); ++i)
+ {
+ // check for nmake temporary files
+ if((*i)[0] == '@' && i->find("@CMakeFiles") != 0 )
+ {
+ cmsys::ifstream fin(i->substr(1).c_str());
+ std::string line;
+ while(cmSystemTools::GetLineFromStream(fin,
+ line))
+ {
+ cmSystemTools::ParseWindowsCommandLine(line.c_str(), expandedArgs);
+ }
+ }
+ else
+ {
+ expandedArgs.push_back(*i);
+ }
+ }
+ bool hasIncremental = false;
+ bool hasManifest = true;
+ for(std::vector<std::string>::iterator i = expandedArgs.begin();
+ i != expandedArgs.end(); ++i)
+ {
+ if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL:YES") == 0)
+ {
+ hasIncremental = true;
+ }
+ if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL") == 0)
+ {
+ hasIncremental = true;
+ }
+ if(cmSystemTools::Strucmp(i->c_str(), "/MANIFEST:NO") == 0)
+ {
+ hasManifest = false;
+ }
+ }
+ if(hasIncremental && hasManifest)
+ {
+ if(verbose)
+ {
+ std::cout << "Visual Studio Incremental Link with embedded manifests\n";
+ }
+ return cmcmd::VisualStudioLinkIncremental(expandedArgs, type, verbose);
+ }
+ if(verbose)
+ {
+ if(!hasIncremental)
+ {
+ std::cout << "Visual Studio Non-Incremental Link\n";
+ }
+ else
+ {
+ std::cout << "Visual Studio Incremental Link without manifests\n";
+ }
+ }
+ return cmcmd::VisualStudioLinkNonIncremental(expandedArgs,
+ type, hasManifest, verbose);
+}
+
+int cmcmd::ParseVisualStudioLinkCommand(std::vector<std::string>& args,
+ std::vector<std::string>& command,
+ std::string& targetName)
+{
+ std::vector<std::string>::iterator i = args.begin();
+ i++; // skip -E
+ i++; // skip vs_link_dll or vs_link_exe
+ command.push_back(*i);
+ i++; // move past link command
+ for(; i != args.end(); ++i)
+ {
+ command.push_back(*i);
+ if(i->find("/Fe") == 0)
+ {
+ targetName = i->substr(3);
+ }
+ if(i->find("/out:") == 0)
+ {
+ targetName = i->substr(5);
+ }
+ }
+ if(targetName.size() == 0 || command.size() == 0)
+ {
+ return -1;
+ }
+ return 0;
+}
+
+bool cmcmd::RunCommand(const char* comment,
+ std::vector<std::string>& command,
+ bool verbose,
+ int* retCodeOut)
+{
+ if(verbose)
+ {
+ std::cout << comment << ":\n";
+ for(std::vector<std::string>::iterator i = command.begin();
+ i != command.end(); ++i)
+ {
+ std::cout << *i << " ";
+ }
+ std::cout << "\n";
+ }
+ std::string output;
+ int retCode =0;
+ // use rc command to create .res file
+ cmSystemTools::RunSingleCommand(command,
+ &output,
+ &retCode, 0, cmSystemTools::OUTPUT_NONE);
+ // always print the output of the command, unless
+ // it is the dumb rc command banner, but if the command
+ // returned an error code then print the output anyway as
+ // the banner may be mixed with some other important information.
+ if(output.find("Resource Compiler Version") == output.npos
+ || retCode !=0)
+ {
+ std::cout << output;
+ }
+ // if retCodeOut is requested then always return true
+ // and set the retCodeOut to retCode
+ if(retCodeOut)
+ {
+ *retCodeOut = retCode;
+ return true;
+ }
+ if(retCode != 0)
+ {
+ std::cout << comment << " failed. with " << retCode << "\n";
+ }
+ return retCode == 0;
+}
+
+int cmcmd::VisualStudioLinkIncremental(std::vector<std::string>& args,
+ int type, bool verbose)
+{
+ // This follows the steps listed here:
+ // http://blogs.msdn.com/zakramer/archive/2006/05/22/603558.aspx
+
+ // 1. Compiler compiles the application and generates the *.obj files.
+ // 2. An empty manifest file is generated if this is a clean build and if
+ // not the previous one is reused.
+ // 3. The resource compiler (rc.exe) compiles the *.manifest file to a
+ // *.res file.
+ // 4. Linker generates the binary (EXE or DLL) with the /incremental
+ // switch and embeds the dummy manifest file. The linker also generates
+ // the real manifest file based on the binaries that your binary depends
+ // on.
+ // 5. The manifest tool (mt.exe) is then used to generate the final
+ // manifest.
+
+ // If the final manifest is changed, then 6 and 7 are run, if not
+ // they are skipped, and it is done.
+
+ // 6. The resource compiler is invoked one more time.
+ // 7. Finally, the Linker does another incremental link, but since the
+ // only thing that has changed is the *.res file that contains the
+ // manifest it is a short link.
+ std::vector<std::string> linkCommand;
+ std::string targetName;
+ if(cmcmd::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
+ {
+ return -1;
+ }
+ std::string manifestArg = "/MANIFESTFILE:";
+ std::vector<std::string> rcCommand;
+ rcCommand.push_back(cmSystemTools::FindProgram("rc.exe"));
+ std::vector<std::string> mtCommand;
+ mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
+ std::string tempManifest;
+ tempManifest = targetName;
+ tempManifest += ".intermediate.manifest";
+ std::string resourceInputFile = targetName;
+ resourceInputFile += ".resource.txt";
+ if(verbose)
+ {
+ std::cout << "Create " << resourceInputFile << "\n";
+ }
+ // Create input file for rc command
+ cmsys::ofstream fout(resourceInputFile.c_str());
+ if(!fout)
+ {
+ return -1;
+ }
+ std::string manifestFile = targetName;
+ manifestFile += ".embed.manifest";
+ std::string fullPath= cmSystemTools::CollapseFullPath(manifestFile.c_str());
+ fout << type << " /* CREATEPROCESS_MANIFEST_RESOURCE_ID "
+ "*/ 24 /* RT_MANIFEST */ " << "\"" << fullPath << "\"";
+ fout.close();
+ manifestArg += tempManifest;
+ // add the manifest arg to the linkCommand
+ linkCommand.push_back("/MANIFEST");
+ linkCommand.push_back(manifestArg);
+ // if manifestFile is not yet created, create an
+ // empty one
+ if(!cmSystemTools::FileExists(manifestFile.c_str()))
+ {
+ if(verbose)
+ {
+ std::cout << "Create empty: " << manifestFile << "\n";
+ }
+ cmsys::ofstream foutTmp(manifestFile.c_str());
+ }
+ std::string resourceFile = manifestFile;
+ resourceFile += ".res";
+ // add the resource file to the end of the link command
+ linkCommand.push_back(resourceFile);
+ std::string outputOpt = "/fo";
+ outputOpt += resourceFile;
+ rcCommand.push_back(outputOpt);
+ rcCommand.push_back(resourceInputFile);
+ // Run rc command to create resource
+ if(!cmcmd::RunCommand("RC Pass 1", rcCommand, verbose))
+ {
+ return -1;
+ }
+ // Now run the link command to link and create manifest
+ if(!cmcmd::RunCommand("LINK Pass 1", linkCommand, verbose))
+ {
+ return -1;
+ }
+ // create mt command
+ std::string outArg("/out:");
+ outArg+= manifestFile;
+ mtCommand.push_back("/nologo");
+ mtCommand.push_back(outArg);
+ mtCommand.push_back("/notify_update");
+ mtCommand.push_back("/manifest");
+ mtCommand.push_back(tempManifest);
+ // now run mt.exe to create the final manifest file
+ int mtRet =0;
+ cmcmd::RunCommand("MT", mtCommand, verbose, &mtRet);
+ // if mt returns 0, then the manifest was not changed and
+ // we do not need to do another link step
+ if(mtRet == 0)
+ {
+ return 0;
+ }
+ // check for magic mt return value if mt returns the magic number
+ // 1090650113 then it means that it updated the manifest file and we need
+ // to do the final link. If mt has any value other than 0 or 1090650113
+ // then there was some problem with the command itself and there was an
+ // error so return the error code back out of cmake so make can report it.
+ // (when hosted on a posix system the value is 187)
+ if(mtRet != 1090650113 && mtRet != 187)
+ {
+ return mtRet;
+ }
+ // update the resource file with the new manifest from the mt command.
+ if(!cmcmd::RunCommand("RC Pass 2", rcCommand, verbose))
+ {
+ return -1;
+ }
+ // Run the final incremental link that will put the new manifest resource
+ // into the file incrementally.
+ if(!cmcmd::RunCommand("FINAL LINK", linkCommand, verbose))
+ {
+ return -1;
+ }
+ return 0;
+}
+
+int cmcmd::VisualStudioLinkNonIncremental(std::vector<std::string>& args,
+ int type,
+ bool hasManifest,
+ bool verbose)
+{
+ std::vector<std::string> linkCommand;
+ std::string targetName;
+ if(cmcmd::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
+ {
+ return -1;
+ }
+ // Run the link command as given
+ if (hasManifest)
+ {
+ linkCommand.push_back("/MANIFEST");
+ }
+ if(!cmcmd::RunCommand("LINK", linkCommand, verbose))
+ {
+ return -1;
+ }
+ if(!hasManifest)
+ {
+ return 0;
+ }
+ std::vector<std::string> mtCommand;
+ mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
+ mtCommand.push_back("/nologo");
+ mtCommand.push_back("/manifest");
+ std::string manifestFile = targetName;
+ manifestFile += ".manifest";
+ mtCommand.push_back(manifestFile);
+ std::string outresource = "/outputresource:";
+ outresource += targetName;
+ outresource += ";#";
+ if(type == 1)
+ {
+ outresource += "1";
+ }
+ else if(type == 2)
+ {
+ outresource += "2";
+ }
+ mtCommand.push_back(outresource);
+ // Now use the mt tool to embed the manifest into the exe or dll
+ if(!cmcmd::RunCommand("MT", mtCommand, verbose))
+ {
+ return -1;
+ }
+ return 0;
+}
diff --git a/Source/cmcmd.h b/Source/cmcmd.h
new file mode 100644
index 0000000000..2bfbae7ccb
--- /dev/null
+++ b/Source/cmcmd.h
@@ -0,0 +1,54 @@
+/*============================================================================
+ 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 cmcmd_h
+#define cmcmd_h
+
+#include "cmStandardIncludes.h"
+
+class cmcmd
+{
+public:
+
+ /**
+ * Execute commands during the build process. Supports options such
+ * as echo, remove file etc.
+ */
+ static int ExecuteCMakeCommand(std::vector<std::string>&);
+protected:
+
+ static int SymlinkLibrary(std::vector<std::string>& args);
+ static int SymlinkExecutable(std::vector<std::string>& args);
+ static bool SymlinkInternal(std::string const& file,
+ std::string const& link);
+ static int ExecuteEchoColor(std::vector<std::string>& args);
+ static int ExecuteLinkScript(std::vector<std::string>& args);
+ static int WindowsCEEnvironment(const char* version,
+ const std::string& name);
+ static int VisualStudioLink(std::vector<std::string>& args, int type);
+ static int VisualStudioLinkIncremental(std::vector<std::string>& args,
+ int type,
+ bool verbose);
+ static int VisualStudioLinkNonIncremental(std::vector<std::string>& args,
+ int type,
+ bool hasManifest,
+ bool verbose);
+ static int ParseVisualStudioLinkCommand(std::vector<std::string>& args,
+ std::vector<std::string>& command,
+ std::string& targetName);
+ static bool RunCommand(const char* comment,
+ std::vector<std::string>& command,
+ bool verbose,
+ int* retCodeOut = 0);
+};
+
+#endif
diff --git a/Source/cmparseMSBuildXML.py b/Source/cmparseMSBuildXML.py
new file mode 100755
index 0000000000..056a0db0f0
--- /dev/null
+++ b/Source/cmparseMSBuildXML.py
@@ -0,0 +1,338 @@
+# This python script parses the spec files from MSBuild to create
+# mappings from compiler options to IDE XML specifications. For
+# more information see here:
+
+# http://blogs.msdn.com/vcblog/archive/2008/12/16/msbuild-task.aspx
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/1033/cl.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/1033/lib.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/1033/link.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V110/1033/cl.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V110/1033/lib.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V110/1033/link.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/v120/1033/cl.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/v120/1033/lib.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/v120/1033/link.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V140/1033/cl.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V140/1033/lib.xml"
+# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V140/1033/link.xml"
+#
+# BoolProperty <Name>true|false</Name>
+# simple example:
+# <BoolProperty ReverseSwitch="Oy-" Name="OmitFramePointers"
+# Category="Optimization" Switch="Oy">
+# <BoolProperty.DisplayName> <BoolProperty.Description>
+# <CLCompile>
+# <OmitFramePointers>true</OmitFramePointers>
+# </ClCompile>
+#
+# argument means it might be this: /MP3
+# example with argument:
+# <BoolProperty Name="MultiProcessorCompilation" Category="General" Switch="MP">
+# <BoolProperty.DisplayName>
+# <sys:String>Multi-processor Compilation</sys:String>
+# </BoolProperty.DisplayName>
+# <BoolProperty.Description>
+# <sys:String>Multi-processor Compilation</sys:String>
+# </BoolProperty.Description>
+# <Argument Property="ProcessorNumber" IsRequired="false" />
+# </BoolProperty>
+# <CLCompile>
+# <MultiProcessorCompilation>true</MultiProcessorCompilation>
+# <ProcessorNumber>4</ProcessorNumber>
+# </ClCompile>
+# IntProperty
+# not used AFIT
+# <IntProperty Name="ProcessorNumber" Category="General" Visible="false">
+
+
+# per config options example
+# <EnableFiberSafeOptimizations Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</EnableFiberSafeOptimizations>
+#
+# EnumProperty
+# <EnumProperty Name="Optimization" Category="Optimization">
+# <EnumProperty.DisplayName>
+# <sys:String>Optimization</sys:String>
+# </EnumProperty.DisplayName>
+# <EnumProperty.Description>
+# <sys:String>Select option for code optimization; choose Custom to use specific optimization options. (/Od, /O1, /O2, /Ox)</sys:String>
+# </EnumProperty.Description>
+# <EnumValue Name="MaxSpeed" Switch="O2">
+# <EnumValue.DisplayName>
+# <sys:String>Maximize Speed</sys:String>
+# </EnumValue.DisplayName>
+# <EnumValue.Description>
+# <sys:String>Equivalent to /Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy</sys:String>
+# </EnumValue.Description>
+# </EnumValue>
+# <EnumValue Name="MinSpace" Switch="O1">
+# <EnumValue.DisplayName>
+# <sys:String>Minimize Size</sys:String>
+# </EnumValue.DisplayName>
+# <EnumValue.Description>
+# <sys:String>Equivalent to /Og /Os /Oy /Ob2 /Gs /GF /Gy</sys:String>
+# </EnumValue.Description>
+# </EnumValue>
+# example for O2 would be this:
+# <Optimization>MaxSpeed</Optimization>
+# example for O1 would be this:
+# <Optimization>MinSpace</Optimization>
+#
+# StringListProperty
+# <StringListProperty Name="PreprocessorDefinitions" Category="Preprocessor" Switch="D ">
+# <StringListProperty.DisplayName>
+# <sys:String>Preprocessor Definitions</sys:String>
+# </StringListProperty.DisplayName>
+# <StringListProperty.Description>
+# <sys:String>Defines a preprocessing symbols for your source file.</sys:String>
+# </StringListProperty.Description>
+# </StringListProperty>
+
+# <StringListProperty Subtype="folder" Name="AdditionalIncludeDirectories" Category="General" Switch="I">
+# <StringListProperty.DisplayName>
+# <sys:String>Additional Include Directories</sys:String>
+# </StringListProperty.DisplayName>
+# <StringListProperty.Description>
+# <sys:String>Specifies one or more directories to add to the include path; separate with semi-colons if more than one. (/I[path])</sys:String>
+# </StringListProperty.Description>
+# </StringListProperty>
+# StringProperty
+
+# Example add bill include:
+
+# <AdditionalIncludeDirectories>..\..\..\..\..\..\bill;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+
+
+import sys
+from xml.dom.minidom import parse, parseString
+
+def getText(node):
+ nodelist = node.childNodes
+ rc = ""
+ for child in nodelist:
+ if child.nodeType == child.TEXT_NODE:
+ rc = rc + child.data
+ return rc
+
+def print_tree(document, spaces=""):
+ for i in range(len(document.childNodes)):
+ if document.childNodes[i].nodeType == document.childNodes[i].ELEMENT_NODE:
+ print spaces+str(document.childNodes[i].nodeName )
+ print_tree(document.childNodes[i],spaces+"----")
+ pass
+
+###########################################################################################
+#Data structure that stores a property of MSBuild
+class Property:
+ #type = type of MSBuild property (ex. if the property is EnumProperty type should be "Enum")
+ #attributeNames = a list of any attributes that this property could have (ex. if this was a EnumProperty it should be ["Name","Category"])
+ #document = the dom file that's root node is the Property node (ex. if you were parsing a BoolProperty the root node should be something like <BoolProperty Name="RegisterOutput" Category="General" IncludeInCommandLine="false">
+ def __init__(self,type,attributeNames,document=None):
+ self.suffix_type = "Property"
+ self.prefix_type = type
+ self.attributeNames = attributeNames
+ self.attributes = {}
+ self.DisplayName = ""
+ self.Description = ""
+ self.argumentProperty = ""
+ self.argumentIsRequired = ""
+ self.values = []
+ if document is not None:
+ self.populate(document)
+ pass
+
+ #document = the dom file that's root node is the Property node (ex. if you were parsing a BoolProperty the root node should be something like <BoolProperty Name="RegisterOutput" Category="General" IncludeInCommandLine="false">
+ #spaces = do not use
+ def populate(self,document, spaces = ""):
+ if document.nodeName == self.prefix_type+self.suffix_type:
+ for i in self.attributeNames:
+ self.attributes[i] = document.getAttribute(i)
+ for i in range(len(document.childNodes)):
+ child = document.childNodes[i]
+ if child.nodeType == child.ELEMENT_NODE:
+ if child.nodeName == self.prefix_type+self.suffix_type+".DisplayName":
+ self.DisplayName = getText(child.childNodes[1])
+ if child.nodeName == self.prefix_type+self.suffix_type+".Description":
+ self.Description = getText(child.childNodes[1])
+ if child.nodeName == "Argument":
+ self.argumentProperty = child.getAttribute("Property")
+ self.argumentIsRequired = child.getAttribute("IsRequired")
+ if child.nodeName == self.prefix_type+"Value":
+ va = Property(self.prefix_type,["Name","DisplayName","Switch"])
+ va.suffix_type = "Value"
+ va.populate(child)
+ self.values.append(va)
+ self.populate(child,spaces+"----")
+ pass
+
+ #toString function
+ def __str__(self):
+ toReturn = self.prefix_type+self.suffix_type+":"
+ for i in self.attributeNames:
+ toReturn += "\n "+i+": "+self.attributes[i]
+ if self.argumentProperty != "":
+ toReturn += "\n Argument:\n Property: "+self.argumentProperty+"\n IsRequired: "+self.argumentIsRequired
+ for i in self.values:
+ toReturn+="\n "+str(i).replace("\n","\n ")
+ return toReturn
+###########################################################################################
+
+###########################################################################################
+#Class that populates itself from an MSBuild file and outputs it in CMake
+#format
+
+class MSBuildToCMake:
+ #document = the entire MSBuild xml file
+ def __init__(self,document=None):
+ self.enumProperties = []
+ self.stringProperties = []
+ self.stringListProperties = []
+ self.boolProperties = []
+ self.intProperties = []
+ if document!=None :
+ self.populate(document)
+ pass
+
+ #document = the entire MSBuild xml file
+ #spaces = don't use
+ #To add a new property (if they exist) copy and paste this code and fill in appropriate places
+ #
+ #if child.nodeName == "<Name>Property":
+ # self.<Name>Properties.append(Property("<Name>",[<List of attributes>],child))
+ #
+ #Replace <Name> with the name of the new property (ex. if property is StringProperty replace <Name> with String)
+ #Replace <List of attributes> with a list of attributes in your property's root node
+ #in the __init__ function add the line self.<Name>Properties = []
+ #
+ #That is all that is required to add new properties
+ #
+ def populate(self,document, spaces=""):
+ for i in range(len(document.childNodes)):
+ child = document.childNodes[i]
+ if child.nodeType == child.ELEMENT_NODE:
+ if child.nodeName == "EnumProperty":
+ self.enumProperties.append(Property("Enum",["Name","Category"],child))
+ if child.nodeName == "StringProperty":
+ self.stringProperties.append(Property("String",["Name","Subtype","Separator","Category","Visible","IncludeInCommandLine","Switch","DisplayName","ReadOnly"],child))
+ if child.nodeName == "StringListProperty":
+ self.stringListProperties.append(Property("StringList",["Name","Category","Switch","DisplayName","Subtype"],child))
+ if child.nodeName == "BoolProperty":
+ self.boolProperties.append(Property("Bool",["ReverseSwitch","Name","Category","Switch","DisplayName","SwitchPrefix","IncludeInCommandLine"],child))
+ if child.nodeName == "IntProperty":
+ self.intProperties.append(Property("Int",["Name","Category","Visible"],child))
+ self.populate(child,spaces+"----")
+ pass
+
+ #outputs information that CMake needs to know about MSBuild xml files
+ def toCMake(self):
+ toReturn = "static cmVS7FlagTable cmVS10CxxTable[] =\n{\n"
+ toReturn += "\n //Enum Properties\n"
+ lastProp = {}
+ for i in self.enumProperties:
+ if i.attributes["Name"] == "CompileAsManaged":
+ #write these out after the rest of the enumProperties
+ lastProp = i
+ continue
+ for j in i.values:
+ #hardcore Brad King's manual fixes for cmVS10CLFlagTable.h
+ if i.attributes["Name"] == "PrecompiledHeader" and j.attributes["Switch"] != "":
+ toReturn+=" {\""+i.attributes["Name"]+"\", \""+j.attributes["Switch"]+"\",\n \""+j.attributes["DisplayName"]+"\", \""+j.attributes["Name"]+"\",\n cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},\n"
+ else:
+ #default (normal, non-hardcoded) case
+ toReturn+=" {\""+i.attributes["Name"]+"\", \""+j.attributes["Switch"]+"\",\n \""+j.attributes["DisplayName"]+"\", \""+j.attributes["Name"]+"\", 0},\n"
+ toReturn += "\n"
+
+ if lastProp != {}:
+ for j in lastProp.values:
+ toReturn+=" {\""+lastProp.attributes["Name"]+"\", \""+j.attributes["Switch"]+"\",\n \""+j.attributes["DisplayName"]+"\", \""+j.attributes["Name"]+"\", 0},\n"
+ toReturn += "\n"
+
+ toReturn += "\n //Bool Properties\n"
+ for i in self.boolProperties:
+ if i.argumentProperty == "":
+ if i.attributes["ReverseSwitch"] != "":
+ toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["ReverseSwitch"]+"\", \"\", \"false\", 0},\n"
+ if i.attributes["Switch"] != "":
+ toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["Switch"]+"\", \"\", \"true\", 0},\n"
+
+ toReturn += "\n //Bool Properties With Argument\n"
+ for i in self.boolProperties:
+ if i.argumentProperty != "":
+ if i.attributes["ReverseSwitch"] != "":
+ toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["ReverseSwitch"]+"\", \"\", \"false\",\n cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},\n"
+ toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["ReverseSwitch"]+"\", \""+i.attributes["DisplayName"]+"\", \"\",\n cmVS7FlagTable::UserValueRequired},\n"
+ if i.attributes["Switch"] != "":
+ toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["Switch"]+"\", \"\", \"true\",\n cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},\n"
+ toReturn += " {\""+i.argumentProperty+"\", \""+i.attributes["Switch"]+"\", \""+i.attributes["DisplayName"]+"\", \"\",\n cmVS7FlagTable::UserValueRequired},\n"
+
+ toReturn += "\n //String List Properties\n"
+ for i in self.stringListProperties:
+ if i.attributes["Switch"] == "":
+ toReturn += " // Skip [" + i.attributes["Name"] + "] - no command line Switch.\n";
+ else:
+ toReturn +=" {\""+i.attributes["Name"]+"\", \""+i.attributes["Switch"]+"\",\n \""+i.attributes["DisplayName"]+"\",\n \"\", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},\n"
+
+ toReturn += "\n //String Properties\n"
+ for i in self.stringProperties:
+ if i.attributes["Switch"] == "":
+ if i.attributes["Name"] == "PrecompiledHeaderFile":
+ #more hardcoding
+ toReturn += " {\"PrecompiledHeaderFile\", \"Yc\",\n"
+ toReturn += " \"Precompiled Header Name\",\n"
+ toReturn += " \"\", cmVS7FlagTable::UserValueRequired},\n"
+ toReturn += " {\"PrecompiledHeaderFile\", \"Yu\",\n"
+ toReturn += " \"Precompiled Header Name\",\n"
+ toReturn += " \"\", cmVS7FlagTable::UserValueRequired},\n"
+ else:
+ toReturn += " // Skip [" + i.attributes["Name"] + "] - no command line Switch.\n";
+ else:
+ toReturn +=" {\""+i.attributes["Name"]+"\", \""+i.attributes["Switch"]+i.attributes["Separator"]+"\",\n \""+i.attributes["DisplayName"]+"\",\n \"\", cmVS7FlagTable::UserValue},\n"
+
+ toReturn += " {0,0,0,0,0}\n};"
+ return toReturn
+ pass
+
+ #toString function
+ def __str__(self):
+ toReturn = ""
+ allList = [self.enumProperties,self.stringProperties,self.stringListProperties,self.boolProperties,self.intProperties]
+ for p in allList:
+ for i in p:
+ toReturn += "==================================================\n"+str(i).replace("\n","\n ")+"\n==================================================\n"
+
+ return toReturn
+###########################################################################################
+
+###########################################################################################
+# main function
+def main(argv):
+ xml_file = None
+ help = """
+ Please specify an input xml file with -x
+
+ Exiting...
+ Have a nice day :)"""
+ for i in range(0,len(argv)):
+ if argv[i] == "-x":
+ xml_file = argv[i+1]
+ if argv[i] == "-h":
+ print help
+ sys.exit(0)
+ pass
+ if xml_file == None:
+ print help
+ sys.exit(1)
+
+ f = open(xml_file,"r")
+ xml_str = f.read()
+ xml_dom = parseString(xml_str)
+
+ convertor = MSBuildToCMake(xml_dom)
+ print convertor.toCMake()
+
+ xml_dom.unlink()
+###########################################################################################
+# main entry point
+if __name__ == "__main__":
+ main(sys.argv)
+
+sys.exit(0)
diff --git a/Source/ctest.cxx b/Source/ctest.cxx
new file mode 100644
index 0000000000..fb97af6063
--- /dev/null
+++ b/Source/ctest.cxx
@@ -0,0 +1,197 @@
+/*============================================================================
+ 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 "cmCTest.h"
+#include "cmSystemTools.h"
+
+// Need these for documentation support.
+#include "cmake.h"
+#include "cmDocumentation.h"
+
+#include "CTest/cmCTestScriptHandler.h"
+#include "CTest/cmCTestLaunch.h"
+#include "cmsys/Encoding.hxx"
+#include <locale.h>
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationName[][2] =
+{
+ {0,
+ " ctest - Testing driver provided by CMake."},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+static const char * cmDocumentationUsage[][2] =
+{
+ {0,
+ " ctest [options]"},
+ {0,0}
+};
+
+//----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+static const char * cmDocumentationOptions[][2] =
+{
+ {"-C <cfg>, --build-config <cfg>", "Choose configuration to test."},
+ {"-V,--verbose", "Enable verbose output from tests."},
+ {"-VV,--extra-verbose", "Enable more verbose output from tests."},
+ {"--debug", "Displaying more verbose internals of CTest."},
+ {"--output-on-failure", "Output anything outputted by the test program "
+ "if the test should fail."},
+ {"-F", "Enable failover."},
+ {"-j <jobs>, --parallel <jobs>", "Run the tests in parallel using the "
+ "given number of jobs."},
+ {"-Q,--quiet", "Make ctest quiet."},
+ {"-O <file>, --output-log <file>", "Output to log file"},
+ {"-N,--show-only", "Disable actual execution of tests."},
+ {"-L <regex>, --label-regex <regex>", "Run tests with labels matching "
+ "regular expression."},
+ {"-R <regex>, --tests-regex <regex>", "Run tests matching regular "
+ "expression."},
+ {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular "
+ "expression."},
+ {"-LE <regex>, --label-exclude <regex>", "Exclude tests with labels "
+ "matching regular expression."},
+ {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test"},
+ {"-D <var>:<type>=<value>", "Define a variable for script mode"},
+ {"-M <model>, --test-model <model>", "Sets the model for a dashboard"},
+ {"-T <action>, --test-action <action>", "Sets the dashboard action to "
+ "perform"},
+ {"--track <track>", "Specify the track to submit dashboard to"},
+ {"-S <script>, --script <script>", "Execute a dashboard for a "
+ "configuration"},
+ {"-SP <script>, --script-new-process <script>", "Execute a dashboard for a "
+ "configuration"},
+ {"-A <file>, --add-notes <file>", "Add a notes file with submission"},
+ {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
+ "Run a specific number of tests by number."},
+ {"-U, --union", "Take the Union of -I and -R"},
+ {"--rerun-failed", "Run only the tests that failed previously"},
+ {"--max-width <width>", "Set the max width for a test name to output"},
+ {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1."},
+ {"--no-label-summary", "Disable timing summary information for labels."},
+ {"--build-and-test", "Configure, build and run a test."},
+ {"--build-target", "Specify a specific target to build."},
+ {"--build-nocmake", "Run the build without running cmake first."},
+ {"--build-run-dir", "Specify directory to run programs from."},
+ {"--build-two-config", "Run CMake twice"},
+ {"--build-exe-dir", "Specify the directory for the executable."},
+ {"--build-generator", "Specify the generator to use."},
+ {"--build-generator-platform", "Specify the generator-specific platform."},
+ {"--build-generator-toolset", "Specify the generator-specific toolset."},
+ {"--build-project", "Specify the name of the project to build."},
+ {"--build-makeprogram", "Specify the make program to use."},
+ {"--build-noclean", "Skip the make clean step."},
+ {"--build-config-sample",
+ "A sample executable to use to determine the configuration"},
+ {"--build-options", "Add extra options to the build step."},
+
+ {"--test-command", "The test to run with the --build-and-test option."},
+ {"--test-timeout", "The time limit in seconds, internal use only."},
+ {"--tomorrow-tag", "Nightly or experimental starts with next day tag."},
+ {"--ctest-config", "The configuration file used to initialize CTest state "
+ "when submitting dashboards."},
+ {"--overwrite", "Overwrite CTest configuration option."},
+ {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard."},
+ {"--force-new-ctest-process", "Run child CTest instances as new processes"},
+ {"--schedule-random", "Use a random order for scheduling tests"},
+ {"--submit-index", "Submit individual dashboard tests with specific index"},
+ {"--timeout <seconds>", "Set a global timeout on all tests."},
+ {"--stop-time <time>",
+ "Set a time at which all tests should stop running."},
+ {"--http1.0", "Submit using HTTP 1.0."},
+ {"--no-compress-output", "Do not compress test output when submitting."},
+ {"--print-labels", "Print all available test labels."},
+ {0,0}
+};
+
+// this is a test driver program for cmCTest.
+int main (int argc, char const* const* argv)
+{
+ setlocale(LC_CTYPE, "");
+
+ cmsys::Encoding::CommandLineArguments encoding_args =
+ cmsys::Encoding::CommandLineArguments::Main(argc, argv);
+ argc = encoding_args.argc();
+ argv = encoding_args.argv();
+
+ cmSystemTools::DoNotInheritStdPipes();
+ cmSystemTools::EnableMSVCDebugHook();
+ cmSystemTools::FindCMakeResources(argv[0]);
+
+ // Dispatch 'ctest --launch' mode directly.
+ if(argc >= 2 && strcmp(argv[1], "--launch") == 0)
+ {
+ return cmCTestLaunch::Main(argc, argv);
+ }
+
+ cmCTest inst;
+
+ if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
+ {
+ cmCTestLog(&inst, ERROR_MESSAGE,
+ "Current working directory cannot be established." << std::endl);
+ return 1;
+ }
+
+ // If there is a testing input file, check for documentation options
+ // only if there are actually arguments. We want running without
+ // arguments to run tests.
+ if(argc > 1 || !(cmSystemTools::FileExists("CTestTestfile.cmake") ||
+ cmSystemTools::FileExists("DartTestfile.txt")))
+ {
+ if(argc == 1)
+ {
+ cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
+ << std::endl
+ << "No test configuration file found!" << std::endl
+ << "*********************************" << std::endl);
+ }
+ cmDocumentation doc;
+ doc.addCTestStandardDocSections();
+ if(doc.CheckOptions(argc, argv))
+ {
+ cmake hcm;
+ hcm.AddCMakePaths();
+
+ // Construct and print requested documentation.
+ cmCTestScriptHandler* ch =
+ static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
+ ch->CreateCMake();
+
+ doc.SetShowGenerators(false);
+ doc.SetName("ctest");
+ doc.SetSection("Name",cmDocumentationName);
+ doc.SetSection("Usage",cmDocumentationUsage);
+ doc.PrependSection("Options",cmDocumentationOptions);
+#ifdef cout
+# undef cout
+#endif
+ return doc.PrintRequestedDocumentation(std::cout)? 0:1;
+#define cout no_cout_use_cmCTestLog
+ }
+ }
+
+ // copy the args to a vector
+ std::vector<std::string> args;
+ for(int i =0; i < argc; ++i)
+ {
+ args.push_back(argv[i]);
+ }
+ // run ctest
+ std::string output;
+ int res = inst.Run(args,&output);
+ cmCTestLog(&inst, OUTPUT, output);
+
+ return res;
+}
+
diff --git a/Source/kwsys/Base64.c b/Source/kwsys/Base64.c
new file mode 100644
index 0000000000..d07bdd01b6
--- /dev/null
+++ b/Source/kwsys/Base64.c
@@ -0,0 +1,279 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Base64.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "Base64.h.in"
+#endif
+
+/*--------------------------------------------------------------------------*/
+static const unsigned char kwsysBase64EncodeTable[65] =
+"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+"abcdefghijklmnopqrstuvwxyz"
+"0123456789+/";
+
+/*--------------------------------------------------------------------------*/
+static const unsigned char kwsysBase64DecodeTable[256] =
+{
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0x3E,0xFF,0xFF,0xFF,0x3F,
+ 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,
+ 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,
+ 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06,
+ 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
+ 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
+ 0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,
+ 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
+ 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,
+ 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF,
+ /*------------------------------------*/
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
+};
+
+/*--------------------------------------------------------------------------*/
+static unsigned char kwsysBase64EncodeChar(int c)
+{
+ return kwsysBase64EncodeTable[(unsigned char)c];
+}
+
+/*--------------------------------------------------------------------------*/
+static unsigned char kwsysBase64DecodeChar(unsigned char c)
+{
+ return kwsysBase64DecodeTable[c];
+}
+
+/*--------------------------------------------------------------------------*/
+/* Encode 3 bytes into a 4 byte string. */
+void kwsysBase64_Encode3(const unsigned char *src, unsigned char *dest)
+{
+ dest[0] = kwsysBase64EncodeChar((src[0] >> 2) & 0x3F);
+ dest[1] = kwsysBase64EncodeChar(((src[0] << 4) & 0x30)|((src[1] >> 4) & 0x0F));
+ dest[2] = kwsysBase64EncodeChar(((src[1] << 2) & 0x3C)|((src[2] >> 6) & 0x03));
+ dest[3] = kwsysBase64EncodeChar(src[2] & 0x3F);
+}
+
+/*--------------------------------------------------------------------------*/
+/* Encode 2 bytes into a 4 byte string. */
+void kwsysBase64_Encode2(const unsigned char *src, unsigned char *dest)
+{
+ dest[0] = kwsysBase64EncodeChar((src[0] >> 2) & 0x3F);
+ dest[1] = kwsysBase64EncodeChar(((src[0] << 4) & 0x30)|((src[1] >> 4) & 0x0F));
+ dest[2] = kwsysBase64EncodeChar(((src[1] << 2) & 0x3C));
+ dest[3] = '=';
+}
+
+/*--------------------------------------------------------------------------*/
+/* Encode 1 bytes into a 4 byte string. */
+void kwsysBase64_Encode1(const unsigned char *src, unsigned char *dest)
+{
+ dest[0] = kwsysBase64EncodeChar((src[0] >> 2) & 0x3F);
+ dest[1] = kwsysBase64EncodeChar(((src[0] << 4) & 0x30));
+ dest[2] = '=';
+ dest[3] = '=';
+}
+
+/*--------------------------------------------------------------------------*/
+/* Encode 'length' bytes from the input buffer and store the
+ encoded stream into the output buffer. Return the length of the encoded
+ buffer (output). Note that the output buffer must be allocated by the caller
+ (length * 1.5 should be a safe estimate). If 'mark_end' is true than an
+ extra set of 4 bytes is added to the end of the stream if the input is a
+ multiple of 3 bytes. These bytes are invalid chars and therefore they will
+ stop the decoder thus enabling the caller to decode a stream without
+ actually knowing how much data to expect (if the input is not a multiple of
+ 3 bytes then the extra padding needed to complete the encode 4 bytes will
+ stop the decoding anyway). */
+unsigned long kwsysBase64_Encode(const unsigned char *input,
+ unsigned long length,
+ unsigned char *output,
+ int mark_end)
+{
+ const unsigned char *ptr = input;
+ const unsigned char *end = input + length;
+ unsigned char *optr = output;
+
+ /* Encode complete triplet */
+
+ while ((end - ptr) >= 3)
+ {
+ kwsysBase64_Encode3(ptr, optr);
+ ptr += 3;
+ optr += 4;
+ }
+
+ /* Encodes a 2-byte ending into 3 bytes and 1 pad byte and writes. */
+
+ if (end - ptr == 2)
+ {
+ kwsysBase64_Encode2(ptr, optr);
+ optr += 4;
+ }
+
+ /* Encodes a 1-byte ending into 2 bytes and 2 pad bytes */
+
+ else if (end - ptr == 1)
+ {
+ kwsysBase64_Encode1(ptr, optr);
+ optr += 4;
+ }
+
+ /* Do we need to mark the end */
+
+ else if (mark_end)
+ {
+ optr[0] = optr[1] = optr[2] = optr[3] = '=';
+ optr += 4;
+ }
+
+ return (unsigned long)(optr - output);
+}
+
+/*--------------------------------------------------------------------------*/
+/* Decode 4 bytes into a 3 byte string. */
+int kwsysBase64_Decode3(const unsigned char *src, unsigned char *dest)
+{
+ unsigned char d0, d1, d2, d3;
+
+ d0 = kwsysBase64DecodeChar(src[0]);
+ d1 = kwsysBase64DecodeChar(src[1]);
+ d2 = kwsysBase64DecodeChar(src[2]);
+ d3 = kwsysBase64DecodeChar(src[3]);
+
+ /* Make sure all characters were valid */
+
+ if (d0 == 0xFF || d1 == 0xFF || d2 == 0xFF || d3 == 0xFF)
+ {
+ return 0;
+ }
+
+ /* Decode the 3 bytes */
+
+ dest[0] = (unsigned char)(((d0 << 2) & 0xFC) | ((d1 >> 4) & 0x03));
+ dest[1] = (unsigned char)(((d1 << 4) & 0xF0) | ((d2 >> 2) & 0x0F));
+ dest[2] = (unsigned char)(((d2 << 6) & 0xC0) | ((d3 >> 0) & 0x3F));
+
+ /* Return the number of bytes actually decoded */
+
+ if (src[2] == '=')
+ {
+ return 1;
+ }
+ if (src[3] == '=')
+ {
+ return 2;
+ }
+ return 3;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Decode bytes from the input buffer and store the decoded stream
+ into the output buffer until 'length' bytes have been decoded. Return the
+ real length of the decoded stream (which should be equal to 'length'). Note
+ that the output buffer must be allocated by the caller. If
+ 'max_input_length' is not null, then it specifies the number of encoded
+ bytes that should be at most read from the input buffer. In that case the
+ 'length' parameter is ignored. This enables the caller to decode a stream
+ without actually knowing how much decoded data to expect (of course, the
+ buffer must be large enough). */
+unsigned long kwsysBase64_Decode(const unsigned char *input,
+ unsigned long length,
+ unsigned char *output,
+ unsigned long max_input_length)
+{
+ const unsigned char *ptr = input;
+ unsigned char *optr = output;
+
+ /* Decode complete triplet */
+
+ if (max_input_length)
+ {
+ const unsigned char *end = input + max_input_length;
+ while (ptr < end)
+ {
+ int len = kwsysBase64_Decode3(ptr, optr);
+ optr += len;
+ if(len < 3)
+ {
+ return (unsigned long)(optr - output);
+ }
+ ptr += 4;
+ }
+ }
+ else
+ {
+ unsigned char *oend = output + length;
+ while ((oend - optr) >= 3)
+ {
+ int len = kwsysBase64_Decode3(ptr, optr);
+ optr += len;
+ if(len < 3)
+ {
+ return (unsigned long)(optr - output);
+ }
+ ptr += 4;
+ }
+
+ /* Decode the last triplet */
+
+ if (oend - optr == 2)
+ {
+ unsigned char temp[3];
+ int len = kwsysBase64_Decode3(ptr, temp);
+ if(len >= 2)
+ {
+ optr[0] = temp[0];
+ optr[1] = temp[1];
+ optr += 2;
+ }
+ else if(len > 0)
+ {
+ optr[0] = temp[0];
+ optr += 1;
+ }
+ }
+ else if (oend - optr == 1)
+ {
+ unsigned char temp[3];
+ int len = kwsysBase64_Decode3(ptr, temp);
+ if(len > 0)
+ {
+ optr[0] = temp[0];
+ optr += 1;
+ }
+ }
+ }
+
+ return (unsigned long)(optr - output);
+}
diff --git a/Source/kwsys/Base64.h.in b/Source/kwsys/Base64.h.in
new file mode 100644
index 0000000000..3468007687
--- /dev/null
+++ b/Source/kwsys/Base64.h.in
@@ -0,0 +1,120 @@
+/*============================================================================
+ 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@_Base64_h
+#define @KWSYS_NAMESPACE@_Base64_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@_EXPORT
+#endif
+#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsysBase64 kwsys_ns(Base64)
+# define kwsysBase64_Decode kwsys_ns(Base64_Decode)
+# define kwsysBase64_Decode3 kwsys_ns(Base64_Decode3)
+# define kwsysBase64_Encode kwsys_ns(Base64_Encode)
+# define kwsysBase64_Encode1 kwsys_ns(Base64_Encode1)
+# define kwsysBase64_Encode2 kwsys_ns(Base64_Encode2)
+# define kwsysBase64_Encode3 kwsys_ns(Base64_Encode3)
+#endif
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/**
+ * Encode 3 bytes into a 4 byte string.
+ */
+kwsysEXPORT void kwsysBase64_Encode3(const unsigned char *src,
+ unsigned char *dest);
+
+/**
+ * Encode 2 bytes into a 4 byte string.
+ */
+kwsysEXPORT void kwsysBase64_Encode2(const unsigned char *src,
+ unsigned char *dest);
+
+/**
+ * Encode 1 bytes into a 4 byte string.
+ */
+kwsysEXPORT void kwsysBase64_Encode1(const unsigned char *src,
+ unsigned char *dest);
+
+/**
+ * Encode 'length' bytes from the input buffer and store the encoded
+ * stream into the output buffer. Return the length of the encoded
+ * buffer (output). Note that the output buffer must be allocated by
+ * the caller (length * 1.5 should be a safe estimate). If 'mark_end'
+ * is true than an extra set of 4 bytes is added to the end of the
+ * stream if the input is a multiple of 3 bytes. These bytes are
+ * invalid chars and therefore they will stop the decoder thus
+ * enabling the caller to decode a stream without actually knowing how
+ * much data to expect (if the input is not a multiple of 3 bytes then
+ * the extra padding needed to complete the encode 4 bytes will stop
+ * the decoding anyway).
+ */
+kwsysEXPORT unsigned long kwsysBase64_Encode(const unsigned char *input,
+ unsigned long length,
+ unsigned char *output,
+ int mark_end);
+
+/**
+ * Decode 4 bytes into a 3 byte string. Returns the number of bytes
+ * actually decoded.
+ */
+kwsysEXPORT int kwsysBase64_Decode3(const unsigned char *src,
+ unsigned char *dest);
+
+/**
+ * Decode bytes from the input buffer and store the decoded stream
+ * into the output buffer until 'length' bytes have been decoded.
+ * Return the real length of the decoded stream (which should be equal
+ * to 'length'). Note that the output buffer must be allocated by the
+ * caller. If 'max_input_length' is not null, then it specifies the
+ * number of encoded bytes that should be at most read from the input
+ * buffer. In that case the 'length' parameter is ignored. This
+ * enables the caller to decode a stream without actually knowing how
+ * much decoded data to expect (of course, the buffer must be large
+ * enough).
+ */
+kwsysEXPORT unsigned long kwsysBase64_Decode(const unsigned char *input,
+ unsigned long length,
+ unsigned char *output,
+ unsigned long max_input_length);
+
+#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 !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsysBase64
+# undef kwsysBase64_Decode
+# undef kwsysBase64_Decode3
+# undef kwsysBase64_Encode
+# undef kwsysBase64_Encode1
+# undef kwsysBase64_Encode2
+# undef kwsysBase64_Encode3
+# endif
+#endif
+
+#endif
diff --git a/Source/kwsys/CMakeEmptyInputFile.in b/Source/kwsys/CMakeEmptyInputFile.in
new file mode 100644
index 0000000000..40b7ea245e
--- /dev/null
+++ b/Source/kwsys/CMakeEmptyInputFile.in
@@ -0,0 +1 @@
+@CMAKE_EMPTY_INPUT_FILE_CONTENT@
diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt
new file mode 100644
index 0000000000..8ca43608cf
--- /dev/null
+++ b/Source/kwsys/CMakeLists.txt
@@ -0,0 +1,1267 @@
+#=============================================================================
+# KWSys - Kitware System Library
+# Copyright 2000-2011 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.
+#=============================================================================
+
+# The Kitware System Library is intended to be included in other
+# projects. It is completely configurable in that the library's
+# namespace can be configured and the components that are included can
+# be selected invididually.
+
+# Typical usage is to import the kwsys directory tree into a
+# subdirectory under a parent project and enable the classes that will
+# be used. All classes are disabled by default. The CMake listfile
+# above this one configures the library as follows:
+#
+# SET(KWSYS_NAMESPACE foosys)
+# SET(KWSYS_USE_Directory 1) # Enable Directory class.
+# SUBDIRS(kwsys)
+#
+# Optional settings are as follows:
+#
+# KWSYS_HEADER_ROOT = The directory into which to generate the kwsys headers.
+# A directory called "${KWSYS_NAMESPACE}" will be
+# created under this root directory to hold the files.
+#
+# Example:
+#
+# SET(KWSYS_HEADER_ROOT ${PROJECT_BINARY_DIR})
+# INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
+#
+# KWSYS_IOS_FORCE_OLD = Force use of old non-ANSI C++ streams even if
+# new streams are available. This may be used
+# by projects that cannot configure their
+# streams library.
+# Example:
+#
+# SET(KWSYS_IOS_FORCE_OLD 1)
+#
+#
+# Optional settings to setup install rules are as follows:
+#
+# KWSYS_INSTALL_BIN_DIR = The installation target directories into
+# KWSYS_INSTALL_LIB_DIR which the libraries and headers from
+# KWSYS_INSTALL_INCLUDE_DIR kwsys should be installed by a "make install".
+# The values should be specified relative to
+# the installation prefix and NOT start with '/'.
+# KWSYS_INSTALL_DOC_DIR = The installation target directory for documentation
+# such as copyright information.
+#
+# KWSYS_INSTALL_COMPONENT_NAME_RUNTIME = Name of runtime and development
+# KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT installation components.
+# If not given the install rules
+# will not be in any component.
+#
+# KWSYS_INSTALL_EXPORT_NAME = The EXPORT option value for install(TARGETS) calls.
+#
+# Example:
+#
+# SET(KWSYS_INSTALL_BIN_DIR bin)
+# SET(KWSYS_INSTALL_LIB_DIR lib)
+# SET(KWSYS_INSTALL_INCLUDE_DIR include)
+# SET(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME Runtime)
+# SET(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT Development)
+
+# Once configured, kwsys should be used as follows from C or C++ code:
+#
+# #include <foosys/Directory.hxx>
+# ...
+# foosys::Directory directory;
+#
+
+# NOTE: This library is intended for internal use by Kitware-driven
+# projects. In order to keep it simple no attempt will be made to
+# maintain backward compatibility when changes are made to KWSys.
+# When an incompatible change is made Kitware's projects that use
+# KWSys will be fixed, but no notification will necessarily be sent to
+# any outside mailing list and no documentation of the change will be
+# written.
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR)
+IF(POLICY CMP0025)
+ CMAKE_POLICY(SET CMP0025 NEW)
+ENDIF()
+
+#-----------------------------------------------------------------------------
+# If a namespace is not specified, use "kwsys" and enable testing.
+# This should be the case only when kwsys is not included inside
+# another project and is being tested.
+IF(NOT KWSYS_NAMESPACE)
+ SET(KWSYS_NAMESPACE "kwsys")
+ SET(KWSYS_STANDALONE 1)
+ENDIF(NOT KWSYS_NAMESPACE)
+
+#-----------------------------------------------------------------------------
+# The project name is that of the specified namespace.
+PROJECT(${KWSYS_NAMESPACE})
+
+# Tell CMake how to follow dependencies of sources in this directory.
+SET_PROPERTY(DIRECTORY
+ PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
+ "KWSYS_HEADER(%)=<${KWSYS_NAMESPACE}/%>"
+ )
+
+# Select library components.
+IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
+ SET(KWSYS_ENABLE_C 1)
+ # Enable all components.
+ SET(KWSYS_USE_Base64 1)
+ SET(KWSYS_USE_Directory 1)
+ SET(KWSYS_USE_DynamicLoader 1)
+ SET(KWSYS_USE_Encoding 1)
+ SET(KWSYS_USE_Glob 1)
+ SET(KWSYS_USE_MD5 1)
+ SET(KWSYS_USE_Process 1)
+ SET(KWSYS_USE_RegularExpression 1)
+ 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(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
+
+# Enforce component dependencies.
+IF(KWSYS_USE_SystemTools)
+ SET(KWSYS_USE_Directory 1)
+ SET(KWSYS_USE_FStream 1)
+ SET(KWSYS_USE_Encoding 1)
+ENDIF(KWSYS_USE_SystemTools)
+IF(KWSYS_USE_Glob)
+ SET(KWSYS_USE_Directory 1)
+ SET(KWSYS_USE_SystemTools 1)
+ SET(KWSYS_USE_RegularExpression 1)
+ SET(KWSYS_USE_FStream 1)
+ SET(KWSYS_USE_Encoding 1)
+ENDIF(KWSYS_USE_Glob)
+IF(KWSYS_USE_Process)
+ SET(KWSYS_USE_System 1)
+ SET(KWSYS_USE_Encoding 1)
+ENDIF(KWSYS_USE_Process)
+IF(KWSYS_USE_SystemInformation)
+ SET(KWSYS_USE_Process 1)
+ENDIF(KWSYS_USE_SystemInformation)
+IF(KWSYS_USE_System)
+ SET(KWSYS_USE_Encoding 1)
+ENDIF(KWSYS_USE_System)
+IF(KWSYS_USE_Directory)
+ SET(KWSYS_USE_Encoding 1)
+ENDIF(KWSYS_USE_Directory)
+IF(KWSYS_USE_FStream)
+ SET(KWSYS_USE_Encoding 1)
+ENDIF(KWSYS_USE_FStream)
+
+# Setup the large file support default.
+IF(KWSYS_LFS_DISABLE)
+ SET(KWSYS_LFS_REQUESTED 0)
+ELSE(KWSYS_LFS_DISABLE)
+ SET(KWSYS_LFS_REQUESTED 1)
+ENDIF(KWSYS_LFS_DISABLE)
+
+# Specify default 8 bit encoding for Windows
+IF(NOT KWSYS_ENCODING_DEFAULT_CODEPAGE)
+ SET(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_ACP)
+ENDIF(NOT KWSYS_ENCODING_DEFAULT_CODEPAGE)
+
+# Enable testing if building standalone.
+IF(KWSYS_STANDALONE)
+ INCLUDE(Dart)
+ MARK_AS_ADVANCED(BUILD_TESTING DART_ROOT TCL_TCLSH)
+ IF(BUILD_TESTING)
+ ENABLE_TESTING()
+ ENDIF(BUILD_TESTING)
+ENDIF(KWSYS_STANDALONE)
+
+# Include helper macros.
+INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/kwsysPlatformTests.cmake)
+INCLUDE(CheckTypeSize)
+
+# Do full dependency headers.
+INCLUDE_REGULAR_EXPRESSION("^.*$")
+
+# Use new KWSYS_INSTALL_*_DIR variable names to control installation.
+# Take defaults from the old names. Note that there was no old name
+# for the bin dir, so we take the old lib dir name so DLLs will be
+# installed in a compatible way for old code.
+IF(NOT KWSYS_INSTALL_INCLUDE_DIR)
+ STRING(REGEX REPLACE "^/" "" KWSYS_INSTALL_INCLUDE_DIR
+ "${KWSYS_HEADER_INSTALL_DIR}")
+ENDIF(NOT KWSYS_INSTALL_INCLUDE_DIR)
+IF(NOT KWSYS_INSTALL_LIB_DIR)
+ STRING(REGEX REPLACE "^/" "" KWSYS_INSTALL_LIB_DIR
+ "${KWSYS_LIBRARY_INSTALL_DIR}")
+ENDIF(NOT KWSYS_INSTALL_LIB_DIR)
+IF(NOT KWSYS_INSTALL_BIN_DIR)
+ STRING(REGEX REPLACE "^/" "" KWSYS_INSTALL_BIN_DIR
+ "${KWSYS_LIBRARY_INSTALL_DIR}")
+ENDIF(NOT KWSYS_INSTALL_BIN_DIR)
+
+# Setup header install rules.
+SET(KWSYS_INSTALL_INCLUDE_OPTIONS)
+IF(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT)
+ SET(KWSYS_INSTALL_INCLUDE_OPTIONS ${KWSYS_INSTALL_INCLUDE_OPTIONS}
+ COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT}
+ )
+ENDIF(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT)
+
+# Setup library install rules.
+SET(KWSYS_INSTALL_LIBRARY_RULE)
+IF(KWSYS_INSTALL_LIB_DIR)
+ IF(KWSYS_INSTALL_EXPORT_NAME)
+ LIST(APPEND KWSYS_INSTALL_LIBRARY_RULE EXPORT ${KWSYS_INSTALL_EXPORT_NAME})
+ ENDIF()
+ # Install the shared library to the lib directory.
+ SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
+ LIBRARY DESTINATION ${KWSYS_INSTALL_LIB_DIR}
+ )
+ # Assign the shared library to the runtime component.
+ IF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
+ SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
+ COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_RUNTIME}
+ )
+ ENDIF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
+
+ # Install the archive to the lib directory.
+ SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
+ ARCHIVE DESTINATION ${KWSYS_INSTALL_LIB_DIR}
+ )
+ # Assign the archive to the development component.
+ IF(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT)
+ SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
+ COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT}
+ )
+ ENDIF(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT)
+ENDIF(KWSYS_INSTALL_LIB_DIR)
+IF(KWSYS_INSTALL_BIN_DIR)
+ # Install the runtime library to the bin directory.
+ SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
+ RUNTIME DESTINATION ${KWSYS_INSTALL_BIN_DIR}
+ )
+ # Assign the runtime library to the runtime component.
+ IF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
+ SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
+ COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_RUNTIME}
+ )
+ ENDIF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
+ENDIF(KWSYS_INSTALL_BIN_DIR)
+
+# Do not support old KWSYS_*a_INSTALL_DIR variable names.
+SET(KWSYS_HEADER_INSTALL_DIR)
+SET(KWSYS_LIBRARY_INSTALL_DIR)
+
+# Generated source files will need this header.
+STRING(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}"
+ KWSYS_IN_SOURCE_BUILD)
+IF(NOT KWSYS_IN_SOURCE_BUILD)
+ CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsysPrivate.h
+ ${PROJECT_BINARY_DIR}/kwsysPrivate.h COPY_ONLY IMMEDIATE)
+ENDIF(NOT KWSYS_IN_SOURCE_BUILD)
+
+# Select plugin module file name convention.
+IF(NOT KWSYS_DynamicLoader_PREFIX)
+ SET(KWSYS_DynamicLoader_PREFIX ${CMAKE_SHARED_MODULE_PREFIX})
+ENDIF()
+IF(NOT KWSYS_DynamicLoader_SUFFIX)
+ SET(KWSYS_DynamicLoader_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX})
+ENDIF()
+
+#-----------------------------------------------------------------------------
+# We require ANSI support from the C compiler. Add any needed flags.
+IF(CMAKE_ANSI_CFLAGS)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
+ENDIF(CMAKE_ANSI_CFLAGS)
+
+#-----------------------------------------------------------------------------
+# Adjust compiler flags for some platforms.
+IF(NOT CMAKE_COMPILER_IS_GNUCXX)
+ IF(CMAKE_SYSTEM MATCHES "OSF1-V.*")
+ STRING(REGEX MATCH "-timplicit_local"
+ KWSYS_CXX_FLAGS_HAVE_IMPLICIT_LOCAL "${CMAKE_CXX_FLAGS}")
+ STRING(REGEX MATCH "-no_implicit_include"
+ KWSYS_CXX_FLAGS_HAVE_NO_IMPLICIT_INCLUDE "${CMAKE_CXX_FLAGS}")
+ IF(NOT KWSYS_CXX_FLAGS_HAVE_IMPLICIT_LOCAL)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local")
+ ENDIF(NOT KWSYS_CXX_FLAGS_HAVE_IMPLICIT_LOCAL)
+ IF(NOT KWSYS_CXX_FLAGS_HAVE_NO_IMPLICIT_INCLUDE)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no_implicit_include")
+ ENDIF(NOT KWSYS_CXX_FLAGS_HAVE_NO_IMPLICIT_INCLUDE)
+ ENDIF(CMAKE_SYSTEM MATCHES "OSF1-V.*")
+ IF(CMAKE_SYSTEM MATCHES "HP-UX")
+ SET(KWSYS_PLATFORM_CXX_TEST_EXTRA_FLAGS "+p")
+ IF(CMAKE_CXX_COMPILER_ID MATCHES "HP")
+ # it is known that version 3.85 fails and 6.25 works without these flags
+ IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4)
+ # use new C++ library and improved template support
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA +hpxstd98")
+ ENDIF()
+ ENDIF()
+ ENDIF(CMAKE_SYSTEM MATCHES "HP-UX")
+ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX)
+
+#-----------------------------------------------------------------------------
+# Configure Large File Support.
+KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_CSTDIO
+ "Checking whether header cstdio is available" DIRECT)
+SET(KWSYS_LFS_AVAILABLE 0)
+IF(KWSYS_LFS_REQUESTED)
+ # Large File Support is requested.
+ SET(KWSYS_LFS_REQUESTED 1)
+
+ # Check for large file support.
+ SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
+ -DKWSYS_CXX_HAS_CSTDIO=${KWSYS_CXX_HAS_CSTDIO})
+ KWSYS_PLATFORM_CXX_TEST_RUN(KWSYS_LFS_WORKS
+ "Checking for Large File Support" DIRECT)
+ SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
+
+ IF(KWSYS_LFS_WORKS)
+ SET(KWSYS_LFS_AVAILABLE 1)
+ ENDIF(KWSYS_LFS_WORKS)
+ELSE(KWSYS_LFS_REQUESTED)
+ # Large File Support is not requested.
+ SET(KWSYS_LFS_REQUESTED 0)
+ENDIF(KWSYS_LFS_REQUESTED)
+
+#-----------------------------------------------------------------------------
+# Configure the standard library header wrappers based on compiler's
+# capabilities and parent project's request. Enforce 0/1 as only
+# possible values for configuration into Configure.hxx.
+
+KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAVE_STD
+ "Checking whether STL classes are in std namespace" DIRECT)
+
+IF(KWSYS_IOS_FORCE_OLD)
+ SET(KWSYS_IOS_USE_ANSI 0)
+ELSE(KWSYS_IOS_FORCE_OLD)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_ANSI
+ "Checking whether ANSI stream headers are available" DIRECT)
+ENDIF(KWSYS_IOS_FORCE_OLD)
+
+IF(KWSYS_IOS_USE_ANSI)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAVE_STD
+ "Checking whether ANSI streams are in std namespace" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_SSTREAM
+ "Checking whether ANSI string stream is available" DIRECT)
+ELSE(KWSYS_IOS_USE_ANSI)
+ SET(KWSYS_IOS_HAVE_STD 0)
+ SET(KWSYS_IOS_USE_SSTREAM 0)
+ENDIF(KWSYS_IOS_USE_ANSI)
+
+IF(KWSYS_IOS_USE_SSTREAM)
+ SET(KWSYS_IOS_USE_STRSTREAM_H 0)
+ SET(KWSYS_IOS_USE_STRSTREA_H 0)
+ELSE(KWSYS_IOS_USE_SSTREAM)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_STRSTREAM_H
+ "Checking whether strstream.h is available" DIRECT)
+ IF(KWSYS_IOS_USE_STRSTREAM_H)
+ SET(KWSYS_IOS_USE_STRSTREA_H 0)
+ ELSE(KWSYS_IOS_USE_STRSTREAM_H)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_STRSTREA_H
+ "Checking whether strstrea.h is available" DIRECT)
+ ENDIF(KWSYS_IOS_USE_STRSTREAM_H)
+ENDIF(KWSYS_IOS_USE_SSTREAM)
+
+KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_CSTDDEF
+ "Checking whether header cstddef is available" DIRECT)
+
+SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
+ -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD})
+KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_NEQ_CHAR
+ "Checking whether stl string has operator!= for char*" DIRECT)
+KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ITERATOR_TRAITS
+ "Checking whether stl has iterator_traits" DIRECT)
+IF(KWSYS_STL_HAS_ITERATOR_TRAITS)
+ SET(KWSYS_STL_HAS_ITERATOR_CATEGORY 0)
+ SET(KWSYS_STL_HAS___ITERATOR_CATEGORY 0)
+ELSE(KWSYS_STL_HAS_ITERATOR_TRAITS)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ITERATOR_CATEGORY
+ "Checking whether stl has old iterator_category" DIRECT)
+ IF(KWSYS_STL_HAS_ITERATOR_CATEGORY)
+ SET(KWSYS_STL_HAS___ITERATOR_CATEGORY 0)
+ ELSE(KWSYS_STL_HAS_ITERATOR_CATEGORY)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS___ITERATOR_CATEGORY
+ "Checking whether stl has internal __iterator_category" DIRECT)
+ ENDIF(KWSYS_STL_HAS_ITERATOR_CATEGORY)
+ENDIF(KWSYS_STL_HAS_ITERATOR_TRAITS)
+KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_TEMPLATE
+ "Checking whether stl has standard template allocator" DIRECT)
+IF(KWSYS_STL_HAS_ALLOCATOR_TEMPLATE)
+ SET(KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE 0)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_REBIND
+ "Checking for rebind member of stl allocator" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
+ "Checking for non-standard argument to stl allocator<>::max_size" DIRECT)
+ELSE(KWSYS_STL_HAS_ALLOCATOR_TEMPLATE)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
+ "Checking whether stl has old non-template allocator" DIRECT)
+ SET(KWSYS_STL_HAS_ALLOCATOR_REBIND 0)
+ SET(KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT 0)
+ENDIF(KWSYS_STL_HAS_ALLOCATOR_TEMPLATE)
+KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_OBJECTS
+ "Checking whether stl containers support allocator objects." DIRECT)
+IF(KWSYS_IOS_USE_ANSI AND NOT WATCOM)
+ # ANSI streams always have string operators.
+ SET(KWSYS_STL_STRING_HAVE_OSTREAM 1)
+ SET(KWSYS_STL_STRING_HAVE_ISTREAM 1)
+ELSE(KWSYS_IOS_USE_ANSI AND NOT WATCOM)
+ # There may not be string operators for old streams.
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_OSTREAM
+ "Checking whether stl string has ostream operator<<" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_ISTREAM
+ "Checking whether stl string has istream operator>>" DIRECT)
+ENDIF(KWSYS_IOS_USE_ANSI AND NOT WATCOM)
+SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
+ -DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI}
+ -DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD})
+KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAVE_BINARY
+ "Checking whether ios has binary openmode" DIRECT)
+SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
+
+KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
+ "Checking whether \"<>\" is needed for template friends" INVERT)
+KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_MEMBER_TEMPLATES
+ "Checking for member template support" DIRECT)
+KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_FULL_SPECIALIZATION
+ "Checking for standard template specialization syntax" DIRECT)
+KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
+ "Checking whether argument dependent lookup is supported" DIRECT)
+
+IF(UNIX)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_STAT_HAS_ST_MTIM
+ "Checking whether struct stat has st_mtim member" DIRECT)
+ENDIF(UNIX)
+
+# 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)
+KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS___INT64
+ "Checking whether C++ compiler has '__int64'" DIRECT)
+IF(KWSYS_CXX_HAS___INT64)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_AND___INT64
+ "Checking whether long and __int64 are the same type" DIRECT)
+ IF(KWSYS_CXX_HAS_LONG_LONG)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_LONG_AND___INT64
+ "Checking whether long long and __int64 are the same type" DIRECT)
+ ENDIF()
+ENDIF()
+
+# Enable the "long long" type if it is available. It is standard in
+# C99 and C++03 but not in earlier standards.
+IF(KWSYS_CXX_HAS_LONG_LONG)
+ SET(KWSYS_USE_LONG_LONG 1)
+ELSE()
+ SET(KWSYS_USE_LONG_LONG 0)
+ENDIF()
+
+# Enable the "__int64" type if it is available and unique. It is not
+# standard.
+SET(KWSYS_USE___INT64 0)
+IF(KWSYS_CXX_HAS___INT64)
+ IF(NOT KWSYS_CXX_SAME_LONG_AND___INT64)
+ IF(NOT KWSYS_CXX_SAME_LONG_LONG_AND___INT64)
+ SET(KWSYS_USE___INT64 1)
+ ENDIF()
+ 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(KWSYS_USE___INT64)
+ SET(KWSYS_CAN_CONVERT_UI64_TO_DOUBLE 1)
+ ENDIF(KWSYS_USE___INT64)
+
+ # Check signedness of "char" type.
+ KWSYS_PLATFORM_CXX_TEST_RUN(KWSYS_CHAR_IS_SIGNED
+ "Checking whether char is signed" DIRECT)
+ENDIF(KWSYS_USE_FundamentalType)
+
+IF(KWSYS_USE_Encoding)
+ # Look for type size helper macros.
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_WSTRING
+ "Checking whether wstring is available" DIRECT)
+ENDIF(KWSYS_USE_Encoding)
+
+IF(KWSYS_USE_IOStream)
+ # Determine whether iostreams support long long.
+ SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
+ -DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI}
+ -DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD})
+ IF(KWSYS_CXX_HAS_LONG_LONG)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM_LONG_LONG
+ "Checking if istream supports long long" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM_LONG_LONG
+ "Checking if ostream supports long long" DIRECT)
+ ELSE()
+ SET(KWSYS_IOS_HAS_ISTREAM_LONG_LONG 0)
+ SET(KWSYS_IOS_HAS_OSTREAM_LONG_LONG 0)
+ ENDIF()
+ IF(KWSYS_CXX_HAS___INT64)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM___INT64
+ "Checking if istream supports __int64" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM___INT64
+ "Checking if ostream supports __int64" DIRECT)
+ ELSE()
+ SET(KWSYS_IOS_HAS_ISTREAM___INT64 0)
+ SET(KWSYS_IOS_HAS_OSTREAM___INT64 0)
+ ENDIF()
+ SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
+ENDIF(KWSYS_USE_IOStream)
+
+IF(KWSYS_NAMESPACE MATCHES "^kwsys$")
+ SET(KWSYS_NAME_IS_KWSYS 1)
+ELSE(KWSYS_NAMESPACE MATCHES "^kwsys$")
+ SET(KWSYS_NAME_IS_KWSYS 0)
+ENDIF(KWSYS_NAMESPACE MATCHES "^kwsys$")
+
+# Choose default shared/static build if not specified.
+IF(KWSYS_BUILD_SHARED MATCHES "^KWSYS_BUILD_SHARED$")
+ SET(KWSYS_BUILD_SHARED ${BUILD_SHARED_LIBS})
+ENDIF(KWSYS_BUILD_SHARED MATCHES "^KWSYS_BUILD_SHARED$")
+
+IF(KWSYS_BUILD_SHARED)
+ SET(KWSYS_BUILD_SHARED 1)
+ SET(KWSYS_LIBRARY_TYPE SHARED)
+ELSE(KWSYS_BUILD_SHARED)
+ SET(KWSYS_BUILD_SHARED 0)
+ SET(KWSYS_LIBRARY_TYPE STATIC)
+ENDIF(KWSYS_BUILD_SHARED)
+
+#-----------------------------------------------------------------------------
+# Configure some implementation details.
+
+KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_PTRDIFF_T
+ "Checking whether C compiler has ptrdiff_t in stddef.h" DIRECT)
+KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_SSIZE_T
+ "Checking whether C compiler has ssize_t in unistd.h" DIRECT)
+SET_SOURCE_FILES_PROPERTIES(ProcessUNIX.c System.c PROPERTIES
+ COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T}"
+ )
+
+IF(KWSYS_USE_SystemTools)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_SETENV
+ "Checking whether CXX compiler has setenv" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UNSETENV
+ "Checking whether CXX compiler has unsetenv" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H
+ "Checking whether CXX compiler has environ in stdlib.h" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UTIMES
+ "Checking whether CXX compiler has utimes" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UTIMENSAT
+ "Checking whether CXX compiler has utimensat" 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}
+ )
+ENDIF()
+
+IF(KWSYS_USE_SystemInformation)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P})
+ IF(NOT CYGWIN)
+ INCLUDE(CheckIncludeFiles)
+ CHECK_INCLUDE_FILES("sys/types.h;ifaddrs.h" KWSYS_SYS_HAS_IFADDRS_H)
+ IF(KWSYS_SYS_HAS_IFADDRS_H)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYS_HAS_IFADDRS_H=1)
+ ENDIF()
+ ENDIF()
+ IF(WIN32)
+ INCLUDE(CheckSymbolExists)
+ SET(CMAKE_REQUIRED_LIBRARIES Psapi)
+ CHECK_SYMBOL_EXISTS(GetProcessMemoryInfo "windows.h;psapi.h" KWSYS_SYS_HAS_PSAPI)
+ UNSET(CMAKE_REQUIRED_LIBRARIES)
+ IF(KWSYS_SYS_HAS_PSAPI)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYS_HAS_PSAPI=1)
+ IF(MSVC70 OR MSVC71)
+ # Suppress LNK4089: all references to 'PSAPI.DLL' discarded by /OPT:REF
+ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /IGNORE:4089")
+ ENDIF()
+ ENDIF()
+ ENDIF()
+ IF(CMAKE_SYSTEM MATCHES "HP-UX")
+ CHECK_INCLUDE_FILES("sys/mpctl.h" KWSYS_SYS_HAS_MPCTL_H)
+ IF(KWSYS_SYS_HAS_MPCTL_H)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYS_HAS_MPCTL_H=1)
+ ENDIF()
+ ENDIF()
+ IF(CMAKE_SYSTEM MATCHES "BSD")
+ CHECK_INCLUDE_FILES("machine/cpu.h" KWSYS_SYS_HAS_MACHINE_CPU_H)
+ IF(KWSYS_SYS_HAS_MACHINE_CPU_H)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYS_HAS_MACHINE_CPU_H=1)
+ ENDIF()
+ ENDIF()
+ IF(KWSYS_LFS_AVAILABLE AND NOT KWSYS_LFS_DISABLE)
+ SET(KWSYS_PLATFORM_CXX_TEST_DEFINES -DKWSYS_HAS_LFS=1)
+ ENDIF()
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_RLIMIT64
+ "Checking whether CXX compiler has rlimit64" DIRECT)
+ SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
+ IF(KWSYS_CXX_HAS_RLIMIT64)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_CXX_HAS_RLIMIT64=1)
+ ENDIF()
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOL
+ "Checking whether CXX compiler has atol" DIRECT)
+ IF(KWSYS_CXX_HAS_ATOL)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOL=1)
+ ENDIF()
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOLL
+ "Checking whether CXX compiler has atoll" DIRECT)
+ IF(KWSYS_CXX_HAS_ATOLL)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOLL=1)
+ ENDIF()
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS__ATOI64
+ "Checking whether CXX compiler has _atoi64" DIRECT)
+ IF(KWSYS_CXX_HAS__ATOI64)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1)
+ ENDIF()
+ IF(UNIX)
+ INCLUDE(CheckIncludeFileCXX)
+ # check for simple stack trace
+ # usually it's in libc but on FreeBSD
+ # it's in libexecinfo
+ FIND_LIBRARY(EXECINFO_LIB "execinfo")
+ MARK_AS_ADVANCED(EXECINFO_LIB)
+ IF (NOT EXECINFO_LIB)
+ SET(EXECINFO_LIB "")
+ ENDIF()
+ CHECK_INCLUDE_FILE_CXX("execinfo.h" KWSYS_CXX_HAS_EXECINFOH)
+ IF (KWSYS_CXX_HAS_EXECINFOH)
+ # we have the backtrace header check if it
+ # can be used with this compiler
+ SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES ${EXECINFO_LIB})
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BACKTRACE
+ "Checking whether backtrace works with this C++ compiler" DIRECT)
+ SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES)
+ IF (KWSYS_CXX_HAS_BACKTRACE)
+ # backtrace is supported by this system and compiler.
+ # now check for the more advanced capabilities.
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE=1)
+ # check for symbol lookup using dladdr
+ CHECK_INCLUDE_FILE_CXX("dlfcn.h" KWSYS_CXX_HAS_DLFCNH)
+ IF (KWSYS_CXX_HAS_DLFCNH)
+ # we have symbol lookup libraries and headers
+ # check if they can be used with this compiler
+ SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES ${CMAKE_DL_LIBS})
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_DLADDR
+ "Checking whether dladdr works with this C++ compiler" DIRECT)
+ SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES)
+ IF (KWSYS_CXX_HAS_DLADDR)
+ # symbol lookup is supported by this system
+ # and compiler.
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP=1)
+ ENDIF()
+ ENDIF()
+ # c++ demangling support
+ # check for cxxabi headers
+ CHECK_INCLUDE_FILE_CXX("cxxabi.h" KWSYS_CXX_HAS_CXXABIH)
+ IF (KWSYS_CXX_HAS_CXXABIH)
+ # check if cxxabi can be used with this
+ # system and compiler.
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_CXXABI
+ "Checking whether cxxabi works with this C++ compiler" DIRECT)
+ IF (KWSYS_CXX_HAS_CXXABI)
+ # c++ demangle using cxxabi is supported with
+ # this system and compiler
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE=1)
+ ENDIF()
+ ENDIF()
+ # basic backtrace works better with release build
+ # don't bother with advanced features for release
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS_DEBUG KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD=1)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS_RELWITHDEBINFO KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD=1)
+ ENDIF()
+ ENDIF()
+ ENDIF()
+ IF(BORLAND)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM
+ "Checking whether Borland CXX compiler supports assembler instructions" DIRECT)
+ IF(KWSYS_CXX_HAS_BORLAND_ASM)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM=1)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM_CPUID
+ "Checking whether Borland CXX compiler supports CPUID assembler instruction" DIRECT)
+ IF(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM_CPUID=1)
+ ENDIF()
+ ENDIF()
+ ENDIF()
+ IF(KWSYS_USE___INT64)
+ SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_USE___INT64=1)
+ ENDIF()
+ IF(KWSYS_USE_LONG_LONG)
+ SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_USE_LONG_LONG=1)
+ ENDIF()
+ IF(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
+ SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM_LONG_LONG=1)
+ ENDIF()
+ IF(KWSYS_IOS_HAS_OSTREAM___INT64)
+ SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM___INT64=1)
+ ENDIF()
+ IF(KWSYS_BUILD_SHARED)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_BUILD_SHARED=1)
+ ENDIF()
+ENDIF()
+
+#-----------------------------------------------------------------------------
+# Choose a directory for the generated headers.
+IF(NOT KWSYS_HEADER_ROOT)
+ SET(KWSYS_HEADER_ROOT "${PROJECT_BINARY_DIR}")
+ENDIF(NOT KWSYS_HEADER_ROOT)
+SET(KWSYS_HEADER_DIR "${KWSYS_HEADER_ROOT}/${KWSYS_NAMESPACE}")
+INCLUDE_DIRECTORIES(${KWSYS_HEADER_ROOT})
+
+#-----------------------------------------------------------------------------
+IF(KWSYS_INSTALL_DOC_DIR)
+ # Assign the license to the runtime component since it must be
+ # distributed with binary forms of this software.
+ IF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
+ SET(KWSYS_INSTALL_LICENSE_OPTIONS ${KWSYS_INSTALL_LICENSE_OPTIONS}
+ COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_RUNTIME}
+ )
+ ENDIF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
+
+ # Install the license under the documentation directory.
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt
+ DESTINATION ${KWSYS_INSTALL_DOC_DIR}/${KWSYS_NAMESPACE}
+ ${KWSYS_INSTALL_LICENSE_OPTIONS})
+ENDIF(KWSYS_INSTALL_DOC_DIR)
+
+#-----------------------------------------------------------------------------
+# Create STL header wrappers to block warnings in the STL headers and
+# give standard names by which they may be included.
+SET(KWSYS_STL_HEADER_EXTRA_string 1)
+FOREACH(header
+ algorithm
+ deque
+ exception
+ functional
+ iterator
+ list
+ map
+ memory
+ new
+ numeric
+ queue
+ set
+ stack
+ stdexcept
+ string
+ utility
+ vector
+ )
+ # Configure the header wrapper.
+ SET(KWSYS_STL_HEADER "${header}")
+ IF(KWSYS_STL_HEADER_EXTRA_${header})
+ SET(KWSYS_STL_HEADER_EXTRA
+ "#define ${KWSYS_NAMESPACE}_stl_${header}_including_hxx\n# include <${KWSYS_NAMESPACE}/stl/${header}.hxx>\n#undef ${KWSYS_NAMESPACE}_stl_${header}_including_hxx\n")
+ CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_stl_${header}.hxx.in
+ ${KWSYS_HEADER_DIR}/stl/${header}.hxx
+ @ONLY IMMEDIATE)
+ IF(KWSYS_INSTALL_INCLUDE_DIR)
+ INSTALL(FILES ${KWSYS_HEADER_DIR}/stl/${header}.hxx
+ DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}/stl
+ ${KWSYS_INSTALL_INCLUDE_OPTIONS})
+ ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
+ ELSE(KWSYS_STL_HEADER_EXTRA_${header})
+ SET(KWSYS_STL_HEADER_EXTRA "")
+ ENDIF(KWSYS_STL_HEADER_EXTRA_${header})
+ CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_stl.hxx.in
+ ${KWSYS_HEADER_DIR}/stl/${header}
+ @ONLY IMMEDIATE)
+
+ # Create an install target for the header wrapper.
+ IF(KWSYS_INSTALL_INCLUDE_DIR)
+ INSTALL(FILES ${KWSYS_HEADER_DIR}/stl/${header}
+ DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}/stl
+ ${KWSYS_INSTALL_INCLUDE_OPTIONS})
+ ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
+ENDFOREACH(header)
+
+# Provide cstddef header.
+CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_cstddef.hxx.in
+ ${KWSYS_HEADER_DIR}/cstddef
+ @ONLY IMMEDIATE)
+IF(KWSYS_INSTALL_INCLUDE_DIR)
+ INSTALL(FILES ${KWSYS_HEADER_DIR}/cstddef
+ DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}
+ ${KWSYS_INSTALL_INCLUDE_OPTIONS})
+ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
+
+#-----------------------------------------------------------------------------
+# Create streams header wrappers to give standard names by which they
+# may be included.
+FOREACH(header iostream fstream sstream iosfwd)
+ # Configure the header wrapper.
+ CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_ios_${header}.h.in
+ ${KWSYS_HEADER_DIR}/ios/${header}
+ @ONLY IMMEDIATE)
+
+ # Create an install target for the header wrapper.
+ IF(KWSYS_INSTALL_INCLUDE_DIR)
+ INSTALL(FILES ${KWSYS_HEADER_DIR}/ios/${header}
+ DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}/ios
+ ${KWSYS_INSTALL_INCLUDE_OPTIONS})
+ ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
+ENDFOREACH(header)
+
+#-----------------------------------------------------------------------------
+# Build a list of classes and headers we need to implement the
+# selected components. Initialize with required components.
+SET(KWSYS_CLASSES)
+SET(KWSYS_H_FILES Configure SharedForward)
+SET(KWSYS_HXX_FILES Configure String
+ hashtable hash_fun hash_map hash_set
+ auto_ptr
+ )
+
+# Add selected C++ classes.
+SET(cppclasses
+ Directory DynamicLoader Encoding Glob RegularExpression SystemTools
+ CommandLineArguments IOStream FStream SystemInformation
+ )
+FOREACH(cpp ${cppclasses})
+ IF(KWSYS_USE_${cpp})
+ # Use the corresponding class.
+ SET(KWSYS_CLASSES ${KWSYS_CLASSES} ${cpp})
+
+ # Load component-specific CMake code.
+ IF(EXISTS ${PROJECT_SOURCE_DIR}/kwsys${cpp}.cmake)
+ INCLUDE(${PROJECT_SOURCE_DIR}/kwsys${cpp}.cmake)
+ ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/kwsys${cpp}.cmake)
+ ENDIF(KWSYS_USE_${cpp})
+ENDFOREACH(cpp)
+
+# Add selected C components.
+FOREACH(c
+ Process Base64 Encoding FundamentalType MD5 Terminal System String CPU
+ )
+ IF(KWSYS_USE_${c})
+ # Use the corresponding header file.
+ SET(KWSYS_H_FILES ${KWSYS_H_FILES} ${c})
+
+ # Load component-specific CMake code.
+ IF(EXISTS ${PROJECT_SOURCE_DIR}/kwsys${c}.cmake)
+ INCLUDE(${PROJECT_SOURCE_DIR}/kwsys${c}.cmake)
+ ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/kwsys${c}.cmake)
+ ENDIF(KWSYS_USE_${c})
+ENDFOREACH(c)
+
+#-----------------------------------------------------------------------------
+# Build a list of sources for the library based on components that are
+# included.
+SET(KWSYS_C_SRCS)
+SET(KWSYS_CXX_SRCS)
+
+# Add the proper sources for this platform's Process implementation.
+IF(KWSYS_USE_Process)
+ IF(NOT UNIX)
+ # Use the Windows implementation.
+ SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ProcessWin32.c)
+ ELSE(NOT UNIX)
+ # Use the UNIX implementation.
+ SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ProcessUNIX.c)
+ ENDIF(NOT UNIX)
+ENDIF(KWSYS_USE_Process)
+
+# Add selected C sources.
+FOREACH(c Base64 Encoding MD5 Terminal System String)
+ IF(KWSYS_USE_${c})
+ IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}C.c)
+ LIST(APPEND KWSYS_C_SRCS ${c}C.c)
+ ELSE()
+ LIST(APPEND KWSYS_C_SRCS ${c}.c)
+ ENDIF()
+ ENDIF(KWSYS_USE_${c})
+ENDFOREACH(c)
+
+# Configure headers of C++ classes and construct the list of sources.
+FOREACH(c ${KWSYS_CLASSES})
+ # Add this source to the list of source files for the library.
+ IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}CXX.cxx)
+ LIST(APPEND KWSYS_CXX_SRCS ${c}CXX.cxx)
+ ELSEIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}.cxx)
+ LIST(APPEND KWSYS_CXX_SRCS ${c}.cxx)
+ ENDIF()
+
+ # Configure the header for this class.
+ CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${c}.hxx.in ${KWSYS_HEADER_DIR}/${c}.hxx
+ @ONLY IMMEDIATE)
+ SET(KWSYS_CXX_SRCS ${KWSYS_CXX_SRCS} ${KWSYS_HEADER_DIR}/${c}.hxx)
+
+ # Create an install target for the header.
+ IF(KWSYS_INSTALL_INCLUDE_DIR)
+ INSTALL(FILES ${KWSYS_HEADER_DIR}/${c}.hxx
+ DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}
+ ${KWSYS_INSTALL_INCLUDE_OPTIONS})
+ ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
+ENDFOREACH(c)
+
+# Configure C headers.
+FOREACH(h ${KWSYS_H_FILES})
+ # Configure the header into the given directory.
+ CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.h.in ${KWSYS_HEADER_DIR}/${h}.h
+ @ONLY IMMEDIATE)
+ SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ${KWSYS_HEADER_DIR}/${h}.h)
+
+ # Create an install target for the header.
+ IF(KWSYS_INSTALL_INCLUDE_DIR)
+ INSTALL(FILES ${KWSYS_HEADER_DIR}/${h}.h
+ DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}
+ ${KWSYS_INSTALL_INCLUDE_OPTIONS})
+ ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
+ENDFOREACH(h)
+
+# Configure other C++ headers.
+FOREACH(h ${KWSYS_HXX_FILES})
+ # Configure the header into the given directory.
+ CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.hxx.in ${KWSYS_HEADER_DIR}/${h}.hxx
+ @ONLY IMMEDIATE)
+ SET(KWSYS_CXX_SRCS ${KWSYS_CXX_SRCS} ${KWSYS_HEADER_DIR}/${h}.hxx)
+
+ # Create an install target for the header.
+ IF(KWSYS_INSTALL_INCLUDE_DIR)
+ INSTALL(FILES ${KWSYS_HEADER_DIR}/${h}.hxx
+ DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}
+ ${KWSYS_INSTALL_INCLUDE_OPTIONS})
+ ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
+ENDFOREACH(h)
+
+#-----------------------------------------------------------------------------
+# Add the library with the configured name and list of sources.
+IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
+ ADD_LIBRARY(${KWSYS_NAMESPACE} ${KWSYS_LIBRARY_TYPE}
+ ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS})
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY LABELS ${KWSYS_LABELS_LIB})
+ IF(KWSYS_USE_DynamicLoader)
+ IF(UNIX)
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS})
+ ENDIF(UNIX)
+ ENDIF(KWSYS_USE_DynamicLoader)
+
+ IF(KWSYS_USE_SystemInformation)
+ IF(WIN32)
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32)
+ IF(KWSYS_SYS_HAS_PSAPI)
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} Psapi)
+ ENDIF()
+ ELSEIF(UNIX)
+ IF (EXECINFO_LIB AND KWSYS_CXX_HAS_BACKTRACE)
+ # backtrace on FreeBSD is not in libc
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${EXECINFO_LIB})
+ ENDIF()
+ IF (KWSYS_CXX_HAS_DLADDR)
+ # for symbol lookup using dladdr
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS})
+ ENDIF()
+ ENDIF()
+ ENDIF()
+
+ # Apply user-defined target properties to the library.
+ IF(KWSYS_PROPERTIES_CXX)
+ SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE} PROPERTIES
+ ${KWSYS_PROPERTIES_CXX}
+ )
+ ENDIF(KWSYS_PROPERTIES_CXX)
+
+ # Create an install target for the library.
+ IF(KWSYS_INSTALL_LIBRARY_RULE)
+ INSTALL(TARGETS ${KWSYS_NAMESPACE} ${KWSYS_INSTALL_LIBRARY_RULE})
+ ENDIF(KWSYS_INSTALL_LIBRARY_RULE)
+ENDIF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
+
+# Add a C-only library if requested.
+IF(KWSYS_ENABLE_C AND KWSYS_C_SRCS)
+ ADD_LIBRARY(${KWSYS_NAMESPACE}_c ${KWSYS_LIBRARY_TYPE} ${KWSYS_C_SRCS})
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}_c PROPERTY LABELS ${KWSYS_LABELS_LIB})
+
+ # Apply user-defined target properties to the library.
+ IF(KWSYS_PROPERTIES_C)
+ SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE} PROPERTIES
+ ${KWSYS_PROPERTIES_C}
+ )
+ ENDIF(KWSYS_PROPERTIES_C)
+
+ # Create an install target for the library.
+ IF(KWSYS_INSTALL_LIBRARY_RULE)
+ INSTALL(TARGETS ${KWSYS_NAMESPACE}_c ${KWSYS_INSTALL_LIBRARY_RULE})
+ ENDIF(KWSYS_INSTALL_LIBRARY_RULE)
+ENDIF(KWSYS_ENABLE_C AND KWSYS_C_SRCS)
+
+# For building kwsys itself, we use a macro defined on the command
+# line to configure the namespace in the C and C++ source files.
+ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}")
+
+# Disable deprecation warnings for standard C functions.
+IF(MSVC OR (WIN32 AND "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$"))
+ ADD_DEFINITIONS(
+ -D_CRT_NONSTDC_NO_DEPRECATE
+ -D_CRT_SECURE_NO_DEPRECATE
+ -D_CRT_SECURE_NO_WARNINGS
+ -D_SCL_SECURE_NO_DEPRECATE
+ )
+ENDIF()
+
+IF(WIN32)
+ # Help enforce the use of wide Windows apis.
+ ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
+ENDIF()
+
+IF(KWSYS_USE_String)
+ # Activate code in "String.c". See the comment in the source.
+ SET_SOURCE_FILES_PROPERTIES(String.c PROPERTIES
+ COMPILE_FLAGS "-DKWSYS_STRING_C")
+ENDIF(KWSYS_USE_String)
+
+IF(KWSYS_USE_Encoding)
+ # Set default 8 bit encoding in "EndcodingC.c".
+ SET_PROPERTY(SOURCE EncodingC.c APPEND PROPERTY COMPILE_DEFINITIONS
+ KWSYS_ENCODING_DEFAULT_CODEPAGE=${KWSYS_ENCODING_DEFAULT_CODEPAGE})
+ENDIF(KWSYS_USE_Encoding)
+
+#-----------------------------------------------------------------------------
+# Setup testing if not being built as part of another project.
+IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
+ IF(BUILD_TESTING)
+ # Compute the location of executables.
+ SET(EXEC_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+ IF(EXECUTABLE_OUTPUT_PATH)
+ SET(EXEC_DIR "${EXECUTABLE_OUTPUT_PATH}")
+ ENDIF(EXECUTABLE_OUTPUT_PATH)
+
+ # C tests
+ SET(KWSYS_C_TESTS
+ testEncode
+ testTerminal
+ )
+ IF(KWSYS_STANDALONE)
+ SET(KWSYS_C_TESTS ${KWSYS_C_TESTS} testFail)
+ ENDIF()
+ CREATE_TEST_SOURCELIST(
+ KWSYS_C_TEST_SRCS ${KWSYS_NAMESPACE}TestsC.c
+ ${KWSYS_C_TESTS}
+ )
+ ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestsC ${KWSYS_C_TEST_SRCS})
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsC PROPERTY LABELS ${KWSYS_LABELS_EXE})
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsC ${KWSYS_NAMESPACE}_c)
+ FOREACH(test ${KWSYS_C_TESTS})
+ ADD_TEST(kwsys.${test} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsC ${test} ${KWSYS_TEST_ARGS_${test}})
+ SET_PROPERTY(TEST kwsys.${test} PROPERTY LABELS ${KWSYS_LABELS_TEST})
+ ENDFOREACH(test)
+
+ # C++ tests
+ IF(NOT WATCOM)
+ SET(KWSYS_CXX_TESTS
+ testAutoPtr
+ testHashSTL
+ )
+ ENDIF(NOT WATCOM)
+ SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
+ testIOS
+ testSystemTools
+ testCommandLineArguments
+ testCommandLineArguments1
+ )
+ IF(KWSYS_STL_HAS_WSTRING)
+ SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
+ testEncoding
+ )
+ ENDIF(KWSYS_STL_HAS_WSTRING)
+ IF(KWSYS_USE_FStream)
+ SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
+ testFStream
+ )
+ ENDIF(KWSYS_USE_FStream)
+ IF(KWSYS_USE_SystemInformation)
+ SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testSystemInformation)
+ ENDIF(KWSYS_USE_SystemInformation)
+ IF(KWSYS_USE_DynamicLoader)
+ SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testDynamicLoader)
+ # If kwsys contains the DynamicLoader, need extra library
+ ADD_LIBRARY(${KWSYS_NAMESPACE}TestDynload MODULE testDynload.c)
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestDynload PROPERTY LABELS ${KWSYS_LABELS_LIB})
+ ADD_DEPENDENCIES(${KWSYS_NAMESPACE}TestDynload ${KWSYS_NAMESPACE})
+ ENDIF(KWSYS_USE_DynamicLoader)
+ CREATE_TEST_SOURCELIST(
+ KWSYS_CXX_TEST_SRCS ${KWSYS_NAMESPACE}TestsCxx.cxx
+ ${KWSYS_CXX_TESTS}
+ )
+ ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_CXX_TEST_SRCS})
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY LABELS ${KWSYS_LABELS_EXE})
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_NAMESPACE})
+
+ SET(TEST_SYSTEMTOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+ SET(TEST_SYSTEMTOOLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+ CONFIGURE_FILE(
+ ${PROJECT_SOURCE_DIR}/testSystemTools.h.in
+ ${PROJECT_BINARY_DIR}/testSystemTools.h)
+ INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
+
+ IF(CTEST_TEST_KWSYS)
+ CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/ExtraTest.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/ExtraTest.cmake")
+ SET_DIRECTORY_PROPERTIES(PROPERTIES TEST_INCLUDE_FILE "${CMAKE_CURRENT_BINARY_DIR}/ExtraTest.cmake")
+ ENDIF(CTEST_TEST_KWSYS)
+
+ SET(KWSYS_TEST_ARGS_testCommandLineArguments
+ --another-bool-variable
+ --long3=opt
+ --set-bool-arg1
+ -SSS ken brad bill andy
+ --some-bool-variable=true
+ --some-double-variable12.5
+ --some-int-variable 14
+ "--some-string-variable=test string with space"
+ --some-multi-argument 5 1 8 3 7 1 3 9 7 1
+ -N 12.5 -SS=andy -N 1.31 -N 22
+ -SS=bill -BBtrue -SS=brad
+ -BBtrue
+ -BBfalse
+ -SS=ken
+ -A
+ -C=test
+ --long2 hello
+ )
+ SET(KWSYS_TEST_ARGS_testCommandLineArguments1
+ --ignored
+ -n 24
+ --second-ignored
+ "-m=test value"
+ third-ignored
+ -p
+ some junk at the end
+ )
+ FOREACH(test ${KWSYS_CXX_TESTS})
+ ADD_TEST(kwsys.${test} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsCxx ${test} ${KWSYS_TEST_ARGS_${test}})
+ SET_PROPERTY(TEST kwsys.${test} PROPERTY LABELS ${KWSYS_LABELS_TEST})
+ ENDFOREACH(test)
+
+ # Process tests.
+ ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestProcess testProcess.c)
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestProcess PROPERTY LABELS ${KWSYS_LABELS_EXE})
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestProcess ${KWSYS_NAMESPACE}_c)
+ IF(NOT CYGWIN)
+ SET(KWSYS_TEST_PROCESS_7 7)
+ ENDIF(NOT CYGWIN)
+ FOREACH(n 1 2 3 4 5 6 ${KWSYS_TEST_PROCESS_7})
+ ADD_TEST(kwsys.testProcess-${n} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestProcess ${n})
+ SET_PROPERTY(TEST kwsys.testProcess-${n} PROPERTY LABELS ${KWSYS_LABELS_TEST})
+ SET_TESTS_PROPERTIES(kwsys.testProcess-${n} PROPERTIES TIMEOUT 120)
+ ENDFOREACH(n)
+
+ # Some Apple compilers produce bad optimizations in this source.
+ IF(APPLE AND "${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU|LLVM)$")
+ SET_SOURCE_FILES_PROPERTIES(testProcess.c PROPERTIES COMPILE_FLAGS -O0)
+ ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "XL")
+ # Tell IBM XL not to warn about our test infinite loop
+ SET_PROPERTY(SOURCE testProcess.c PROPERTY COMPILE_FLAGS -qsuppress=1500-010)
+ ENDIF()
+
+ # Test SharedForward
+ CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/testSharedForward.c.in
+ ${PROJECT_BINARY_DIR}/testSharedForward.c @ONLY IMMEDIATE)
+ ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestSharedForward
+ ${PROJECT_BINARY_DIR}/testSharedForward.c)
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestSharedForward PROPERTY LABELS ${KWSYS_LABELS_EXE})
+ ADD_DEPENDENCIES(${KWSYS_NAMESPACE}TestSharedForward ${KWSYS_NAMESPACE}_c)
+ ADD_TEST(kwsys.testSharedForward ${EXEC_DIR}/${KWSYS_NAMESPACE}TestSharedForward 1)
+ SET_PROPERTY(TEST kwsys.testSharedForward PROPERTY LABELS ${KWSYS_LABELS_TEST})
+
+ # Configure some test properties.
+ IF(KWSYS_STANDALONE)
+ # We expect test to fail
+ SET_TESTS_PROPERTIES(kwsys.testFail PROPERTIES WILL_FAIL ON)
+ GET_TEST_PROPERTY(kwsys.testFail WILL_FAIL wfv)
+ SET_TESTS_PROPERTIES(kwsys.testFail PROPERTIES MEASUREMENT "Some Key=Some Value")
+ MESSAGE(STATUS "GET_TEST_PROPERTY returned: ${wfv}")
+ ENDIF()
+
+ # Suppress known consistent failures on buggy systems.
+ IF(KWSYS_TEST_BOGUS_FAILURES)
+ SET_TESTS_PROPERTIES(${KWSYS_TEST_BOGUS_FAILURES} PROPERTIES WILL_FAIL ON)
+ ENDIF()
+
+ ENDIF(BUILD_TESTING)
+ENDIF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
diff --git a/Source/kwsys/CPU.h.in b/Source/kwsys/CPU.h.in
new file mode 100644
index 0000000000..626914b547
--- /dev/null
+++ b/Source/kwsys/CPU.h.in
@@ -0,0 +1,129 @@
+/*============================================================================
+ 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@_CPU_h
+#define @KWSYS_NAMESPACE@_CPU_h
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+
+/* Identify possible endian cases. The macro
+ @KWSYS_NAMESPACE@_CPU_ENDIAN_ID will be defined to one of these, or
+ 0 if unknown. */
+#define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG 4321
+#define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE 1234
+
+/* Apple always defines one of these. */
+#if defined(__LITTLE_ENDIAN__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+#elif defined(__BIG_ENDIAN__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* Alpha */
+#elif defined(__alpha) || defined(__alpha__) || defined(_M_ALPHA)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+
+/* Arm */
+#elif defined(__arm__)
+# if !defined(__ARMEB__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+# else
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+# endif
+
+/* Intel x86 */
+#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+#elif defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+#elif defined(__MWERKS__) && defined(__INTEL__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+
+/* Intel x86-64 */
+#elif defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+#elif defined(__amd64) || defined(__amd64__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+
+/* Intel Architecture-64 (Itanium) */
+#elif defined(__ia64) || defined(__ia64__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+#elif defined(_IA64) || defined(__IA64__) || defined(_M_IA64)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+
+/* PowerPC */
+#elif defined(__powerpc) || defined(__powerpc__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+#elif defined(__ppc) || defined(__ppc__) || defined(__POWERPC__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* SPARC */
+#elif defined(__sparc) || defined(__sparc__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* HP/PA RISC */
+#elif defined(__hppa) || defined(__hppa__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* Motorola 68k */
+#elif defined(__m68k__) || defined(M68000)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* MIPS */
+#elif defined(__mips) || defined(__mips__) || defined(__MIPS__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* OpenRISC 1000 */
+#elif defined(__or1k__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* RS/6000 */
+#elif defined(__THW_RS600) || defined(_IBMR2) || defined(_POWER)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+#elif defined(_ARCH_PWR) || defined(_ARCH_PWR2)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* System/370 */
+#elif defined(__370__) || defined(__THW_370__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* System/390 */
+#elif defined(__s390__) || defined(__s390x__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* z/Architecture */
+#elif defined(__SYSC_ZARCH__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
+/* Aarch64 */
+#elif defined(__aarch64__)
+# if !defined(__AARCH64EB__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+# else
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+# endif
+
+/* Unknown CPU */
+#else
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID 0
+# if !defined(@KWSYS_NAMESPACE@_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@_CPU_ENDIAN_ID
+# define KWSYS_CPU_ENDIAN_ID_BIG @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+# define KWSYS_CPU_ENDIAN_ID_LITTLE @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_LITTLE
+#endif
+
+#endif
diff --git a/Source/kwsys/CTestConfig.cmake b/Source/kwsys/CTestConfig.cmake
new file mode 100644
index 0000000000..d977b472a1
--- /dev/null
+++ b/Source/kwsys/CTestConfig.cmake
@@ -0,0 +1,17 @@
+#=============================================================================
+# KWSys - Kitware System Library
+# Copyright 2000-2012 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.
+#=============================================================================
+set(CTEST_PROJECT_NAME "KWSys")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Source/kwsys/CommandLineArguments.cxx b/Source/kwsys/CommandLineArguments.cxx
new file mode 100644
index 0000000000..9fa9802132
--- /dev/null
+++ b/Source/kwsys/CommandLineArguments.cxx
@@ -0,0 +1,859 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(CommandLineArguments.hxx)
+
+#include KWSYS_HEADER(Configure.hxx)
+#include KWSYS_HEADER(String.hxx)
+
+#include KWSYS_HEADER(stl/vector)
+#include KWSYS_HEADER(stl/map)
+#include KWSYS_HEADER(stl/set)
+#include KWSYS_HEADER(ios/sstream)
+#include KWSYS_HEADER(ios/iostream)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "CommandLineArguments.hxx.in"
+# include "Configure.hxx.in"
+# include "kwsys_stl.hxx.in"
+# include "kwsys_ios_sstream.h.in"
+# include "kwsys_ios_iostream.h.in"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef _MSC_VER
+# pragma warning (disable: 4786)
+#endif
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 1375 /* base class destructor not virtual */
+#endif
+
+#if 0
+# define CommandLineArguments_DEBUG(x) \
+ kwsys_ios::cout << __LINE__ << " CLA: " << x << kwsys_ios::endl
+#else
+# define CommandLineArguments_DEBUG(x)
+#endif
+
+namespace KWSYS_NAMESPACE
+{
+
+//----------------------------------------------------------------------------
+//============================================================================
+struct CommandLineArgumentsCallbackStructure
+{
+ const char* Argument;
+ int ArgumentType;
+ CommandLineArguments::CallbackType Callback;
+ void* CallData;
+ void* Variable;
+ int VariableType;
+ const char* Help;
+};
+
+class CommandLineArgumentsVectorOfStrings :
+ public kwsys_stl::vector<kwsys::String> {};
+class CommandLineArgumentsSetOfStrings :
+ public kwsys_stl::set<kwsys::String> {};
+class CommandLineArgumentsMapOfStrucs :
+ public kwsys_stl::map<kwsys::String,
+ CommandLineArgumentsCallbackStructure> {};
+
+class CommandLineArgumentsInternal
+{
+public:
+ CommandLineArgumentsInternal()
+ {
+ this->UnknownArgumentCallback = 0;
+ this->ClientData = 0;
+ this->LastArgument = 0;
+ }
+
+ typedef CommandLineArgumentsVectorOfStrings VectorOfStrings;
+ typedef CommandLineArgumentsMapOfStrucs CallbacksMap;
+ typedef kwsys::String String;
+ typedef CommandLineArgumentsSetOfStrings SetOfStrings;
+
+ VectorOfStrings Argv;
+ String Argv0;
+ CallbacksMap Callbacks;
+
+ CommandLineArguments::ErrorCallbackType UnknownArgumentCallback;
+ void* ClientData;
+
+ VectorOfStrings::size_type LastArgument;
+
+ VectorOfStrings UnusedArguments;
+};
+//============================================================================
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+CommandLineArguments::CommandLineArguments()
+{
+ this->Internals = new CommandLineArguments::Internal;
+ this->Help = "";
+ this->LineLength = 80;
+ this->StoreUnusedArgumentsFlag = false;
+}
+
+//----------------------------------------------------------------------------
+CommandLineArguments::~CommandLineArguments()
+{
+ delete this->Internals;
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::Initialize(int argc, const char* const argv[])
+{
+ int cc;
+
+ this->Initialize();
+ this->Internals->Argv0 = argv[0];
+ for ( cc = 1; cc < argc; cc ++ )
+ {
+ this->ProcessArgument(argv[cc]);
+ }
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::Initialize(int argc, char* argv[])
+{
+ this->Initialize(argc, static_cast<const char* const*>(argv));
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::Initialize()
+{
+ this->Internals->Argv.clear();
+ this->Internals->LastArgument = 0;
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::ProcessArgument(const char* arg)
+{
+ this->Internals->Argv.push_back(arg);
+}
+
+//----------------------------------------------------------------------------
+bool CommandLineArguments::GetMatchedArguments(
+ kwsys_stl::vector<kwsys_stl::string>* matches,
+ const kwsys_stl::string& arg)
+{
+ matches->clear();
+ CommandLineArguments::Internal::CallbacksMap::iterator it;
+
+ // Does the argument match to any we know about?
+ for ( it = this->Internals->Callbacks.begin();
+ it != this->Internals->Callbacks.end();
+ it ++ )
+ {
+ const CommandLineArguments::Internal::String& parg = it->first;
+ CommandLineArgumentsCallbackStructure *cs = &it->second;
+ if (cs->ArgumentType == CommandLineArguments::NO_ARGUMENT ||
+ cs->ArgumentType == CommandLineArguments::SPACE_ARGUMENT)
+ {
+ if ( arg == parg )
+ {
+ matches->push_back(parg);
+ }
+ }
+ else if ( arg.find( parg ) == 0 )
+ {
+ matches->push_back(parg);
+ }
+ }
+ return !matches->empty();
+}
+
+//----------------------------------------------------------------------------
+int CommandLineArguments::Parse()
+{
+ kwsys_stl::vector<kwsys_stl::string>::size_type cc;
+ kwsys_stl::vector<kwsys_stl::string> matches;
+ if ( this->StoreUnusedArgumentsFlag )
+ {
+ this->Internals->UnusedArguments.clear();
+ }
+ for ( cc = 0; cc < this->Internals->Argv.size(); cc ++ )
+ {
+ const kwsys_stl::string& arg = this->Internals->Argv[cc];
+ CommandLineArguments_DEBUG("Process argument: " << arg);
+ this->Internals->LastArgument = cc;
+ if ( this->GetMatchedArguments(&matches, arg) )
+ {
+ // Ok, we found one or more arguments that match what user specified.
+ // Let's find the longest one.
+ CommandLineArguments::Internal::VectorOfStrings::size_type kk;
+ CommandLineArguments::Internal::VectorOfStrings::size_type maxidx = 0;
+ CommandLineArguments::Internal::String::size_type maxlen = 0;
+ for ( kk = 0; kk < matches.size(); kk ++ )
+ {
+ if ( matches[kk].size() > maxlen )
+ {
+ maxlen = matches[kk].size();
+ maxidx = kk;
+ }
+ }
+ // So, the longest one is probably the right one. Now see if it has any
+ // additional value
+ CommandLineArgumentsCallbackStructure *cs
+ = &this->Internals->Callbacks[matches[maxidx]];
+ const kwsys_stl::string& sarg = matches[maxidx];
+ if ( cs->Argument != sarg )
+ {
+ abort();
+ }
+ switch ( cs->ArgumentType )
+ {
+ case NO_ARGUMENT:
+ // No value
+ if ( !this->PopulateVariable(cs, 0) )
+ {
+ return 0;
+ }
+ break;
+ case SPACE_ARGUMENT:
+ if ( cc == this->Internals->Argv.size()-1 )
+ {
+ this->Internals->LastArgument --;
+ return 0;
+ }
+ CommandLineArguments_DEBUG("This is a space argument: " << arg
+ << " value: " << this->Internals->Argv[cc+1]);
+ // Value is the next argument
+ if ( !this->PopulateVariable(cs, this->Internals->Argv[cc+1].c_str()) )
+ {
+ return 0;
+ }
+ cc ++;
+ break;
+ case EQUAL_ARGUMENT:
+ if ( arg.size() == sarg.size() || arg.at(sarg.size()) != '=' )
+ {
+ this->Internals->LastArgument --;
+ return 0;
+ }
+ // Value is everythng followed the '=' sign
+ if ( !this->PopulateVariable(cs, arg.c_str() + sarg.size() + 1) )
+ {
+ return 0;
+ }
+ break;
+ case CONCAT_ARGUMENT:
+ // Value is whatever follows the argument
+ if ( !this->PopulateVariable(cs, arg.c_str() + sarg.size()) )
+ {
+ return 0;
+ }
+ break;
+ case MULTI_ARGUMENT:
+ // Suck in all the rest of the arguments
+ CommandLineArguments_DEBUG("This is a multi argument: " << arg);
+ for (cc++; cc < this->Internals->Argv.size(); ++ cc )
+ {
+ const kwsys_stl::string& marg = this->Internals->Argv[cc];
+ CommandLineArguments_DEBUG(" check multi argument value: " << marg);
+ if ( this->GetMatchedArguments(&matches, marg) )
+ {
+ CommandLineArguments_DEBUG("End of multi argument " << arg << " with value: " << marg);
+ break;
+ }
+ CommandLineArguments_DEBUG(" populate multi argument value: " << marg);
+ if ( !this->PopulateVariable(cs, marg.c_str()) )
+ {
+ return 0;
+ }
+ }
+ if ( cc != this->Internals->Argv.size() )
+ {
+ CommandLineArguments_DEBUG("Again End of multi argument " << arg);
+ cc--;
+ continue;
+ }
+ break;
+ default:
+ kwsys_ios::cerr << "Got unknown argument type: \"" << cs->ArgumentType << "\"" << kwsys_ios::endl;
+ this->Internals->LastArgument --;
+ return 0;
+ }
+ }
+ else
+ {
+ // Handle unknown arguments
+ if ( this->Internals->UnknownArgumentCallback )
+ {
+ if ( !this->Internals->UnknownArgumentCallback(arg.c_str(),
+ this->Internals->ClientData) )
+ {
+ this->Internals->LastArgument --;
+ return 0;
+ }
+ return 1;
+ }
+ else if ( this->StoreUnusedArgumentsFlag )
+ {
+ CommandLineArguments_DEBUG("Store unused argument " << arg);
+ this->Internals->UnusedArguments.push_back(arg);
+ }
+ else
+ {
+ kwsys_ios::cerr << "Got unknown argument: \"" << arg << "\"" << kwsys_ios::endl;
+ this->Internals->LastArgument --;
+ return 0;
+ }
+ }
+ }
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::GetRemainingArguments(int* argc, char*** argv)
+{
+ CommandLineArguments::Internal::VectorOfStrings::size_type size
+ = this->Internals->Argv.size() - this->Internals->LastArgument + 1;
+ CommandLineArguments::Internal::VectorOfStrings::size_type cc;
+
+ // Copy Argv0 as the first argument
+ char** args = new char*[ size ];
+ args[0] = new char[ this->Internals->Argv0.size() + 1 ];
+ strcpy(args[0], this->Internals->Argv0.c_str());
+ int cnt = 1;
+
+ // Copy everything after the LastArgument, since that was not parsed.
+ for ( cc = this->Internals->LastArgument+1;
+ cc < this->Internals->Argv.size(); cc ++ )
+ {
+ args[cnt] = new char[ this->Internals->Argv[cc].size() + 1];
+ strcpy(args[cnt], this->Internals->Argv[cc].c_str());
+ cnt ++;
+ }
+ *argc = cnt;
+ *argv = args;
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::GetUnusedArguments(int* argc, char*** argv)
+{
+ CommandLineArguments::Internal::VectorOfStrings::size_type size
+ = this->Internals->UnusedArguments.size() + 1;
+ CommandLineArguments::Internal::VectorOfStrings::size_type cc;
+
+ // Copy Argv0 as the first argument
+ char** args = new char*[ size ];
+ args[0] = new char[ this->Internals->Argv0.size() + 1 ];
+ strcpy(args[0], this->Internals->Argv0.c_str());
+ int cnt = 1;
+
+ // Copy everything after the LastArgument, since that was not parsed.
+ for ( cc = 0;
+ cc < this->Internals->UnusedArguments.size(); cc ++ )
+ {
+ kwsys::String &str = this->Internals->UnusedArguments[cc];
+ args[cnt] = new char[ str.size() + 1];
+ strcpy(args[cnt], str.c_str());
+ cnt ++;
+ }
+ *argc = cnt;
+ *argv = args;
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::DeleteRemainingArguments(int argc, char*** argv)
+{
+ int cc;
+ for ( cc = 0; cc < argc; ++ cc )
+ {
+ delete [] (*argv)[cc];
+ }
+ delete [] *argv;
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::AddCallback(const char* argument, ArgumentTypeEnum type,
+ CallbackType callback, void* call_data, const char* help)
+{
+ CommandLineArgumentsCallbackStructure s;
+ s.Argument = argument;
+ s.ArgumentType = type;
+ s.Callback = callback;
+ s.CallData = call_data;
+ s.VariableType = CommandLineArguments::NO_VARIABLE_TYPE;
+ s.Variable = 0;
+ s.Help = help;
+
+ this->Internals->Callbacks[argument] = s;
+ this->GenerateHelp();
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::AddArgument(const char* argument, ArgumentTypeEnum type,
+ VariableTypeEnum vtype, void* variable, const char* help)
+{
+ CommandLineArgumentsCallbackStructure s;
+ s.Argument = argument;
+ s.ArgumentType = type;
+ s.Callback = 0;
+ s.CallData = 0;
+ s.VariableType = vtype;
+ s.Variable = variable;
+ s.Help = help;
+
+ this->Internals->Callbacks[argument] = s;
+ this->GenerateHelp();
+}
+
+//----------------------------------------------------------------------------
+#define CommandLineArgumentsAddArgumentMacro(type, ctype) \
+ void CommandLineArguments::AddArgument(const char* argument, ArgumentTypeEnum type, \
+ ctype* variable, const char* help) \
+ { \
+ this->AddArgument(argument, type, CommandLineArguments::type##_TYPE, variable, help); \
+ }
+
+CommandLineArgumentsAddArgumentMacro(BOOL, bool)
+CommandLineArgumentsAddArgumentMacro(INT, int)
+CommandLineArgumentsAddArgumentMacro(DOUBLE, double)
+CommandLineArgumentsAddArgumentMacro(STRING, char*)
+CommandLineArgumentsAddArgumentMacro(STL_STRING, kwsys_stl::string)
+
+CommandLineArgumentsAddArgumentMacro(VECTOR_BOOL, kwsys_stl::vector<bool>)
+CommandLineArgumentsAddArgumentMacro(VECTOR_INT, kwsys_stl::vector<int>)
+CommandLineArgumentsAddArgumentMacro(VECTOR_DOUBLE, kwsys_stl::vector<double>)
+CommandLineArgumentsAddArgumentMacro(VECTOR_STRING, kwsys_stl::vector<char*>)
+CommandLineArgumentsAddArgumentMacro(VECTOR_STL_STRING, kwsys_stl::vector<kwsys_stl::string>)
+
+//----------------------------------------------------------------------------
+#define CommandLineArgumentsAddBooleanArgumentMacro(type, ctype) \
+ void CommandLineArguments::AddBooleanArgument(const char* argument, \
+ ctype* variable, const char* help) \
+ { \
+ this->AddArgument(argument, CommandLineArguments::NO_ARGUMENT, \
+ CommandLineArguments::type##_TYPE, variable, help); \
+ }
+
+CommandLineArgumentsAddBooleanArgumentMacro(BOOL, bool)
+CommandLineArgumentsAddBooleanArgumentMacro(INT, int)
+CommandLineArgumentsAddBooleanArgumentMacro(DOUBLE, double)
+CommandLineArgumentsAddBooleanArgumentMacro(STRING, char*)
+CommandLineArgumentsAddBooleanArgumentMacro(STL_STRING, kwsys_stl::string)
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::SetClientData(void* client_data)
+{
+ this->Internals->ClientData = client_data;
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::SetUnknownArgumentCallback(
+ CommandLineArguments::ErrorCallbackType callback)
+{
+ this->Internals->UnknownArgumentCallback = callback;
+}
+
+//----------------------------------------------------------------------------
+const char* CommandLineArguments::GetHelp(const char* arg)
+{
+ CommandLineArguments::Internal::CallbacksMap::iterator it
+ = this->Internals->Callbacks.find(arg);
+ if ( it == this->Internals->Callbacks.end() )
+ {
+ return 0;
+ }
+
+ // Since several arguments may point to the same argument, find the one this
+ // one point to if this one is pointing to another argument.
+ CommandLineArgumentsCallbackStructure *cs = &(it->second);
+ for(;;)
+ {
+ CommandLineArguments::Internal::CallbacksMap::iterator hit
+ = this->Internals->Callbacks.find(cs->Help);
+ if ( hit == this->Internals->Callbacks.end() )
+ {
+ break;
+ }
+ cs = &(hit->second);
+ }
+ return cs->Help;
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::SetLineLength(unsigned int ll)
+{
+ if ( ll < 9 || ll > 1000 )
+ {
+ return;
+ }
+ this->LineLength = ll;
+ this->GenerateHelp();
+}
+
+//----------------------------------------------------------------------------
+const char* CommandLineArguments::GetArgv0()
+{
+ return this->Internals->Argv0.c_str();
+}
+
+//----------------------------------------------------------------------------
+unsigned int CommandLineArguments::GetLastArgument()
+{
+ return static_cast<unsigned int>(this->Internals->LastArgument + 1);
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::GenerateHelp()
+{
+ kwsys_ios::ostringstream str;
+
+ // Collapse all arguments into the map of vectors of all arguments that do
+ // the same thing.
+ CommandLineArguments::Internal::CallbacksMap::iterator it;
+ typedef kwsys_stl::map<CommandLineArguments::Internal::String,
+ CommandLineArguments::Internal::SetOfStrings > MapArgs;
+ MapArgs mp;
+ MapArgs::iterator mpit, smpit;
+ for ( it = this->Internals->Callbacks.begin();
+ it != this->Internals->Callbacks.end();
+ it ++ )
+ {
+ CommandLineArgumentsCallbackStructure *cs = &(it->second);
+ mpit = mp.find(cs->Help);
+ if ( mpit != mp.end() )
+ {
+ mpit->second.insert(it->first);
+ mp[it->first].insert(it->first);
+ }
+ else
+ {
+ mp[it->first].insert(it->first);
+ }
+ }
+ for ( it = this->Internals->Callbacks.begin();
+ it != this->Internals->Callbacks.end();
+ it ++ )
+ {
+ CommandLineArgumentsCallbackStructure *cs = &(it->second);
+ mpit = mp.find(cs->Help);
+ if ( mpit != mp.end() )
+ {
+ mpit->second.insert(it->first);
+ smpit = mp.find(it->first);
+ CommandLineArguments::Internal::SetOfStrings::iterator sit;
+ for ( sit = smpit->second.begin(); sit != smpit->second.end(); sit++ )
+ {
+ mpit->second.insert(*sit);
+ }
+ mp.erase(smpit);
+ }
+ else
+ {
+ mp[it->first].insert(it->first);
+ }
+ }
+
+ // Find the length of the longest string
+ CommandLineArguments::Internal::String::size_type maxlen = 0;
+ for ( mpit = mp.begin();
+ mpit != mp.end();
+ mpit ++ )
+ {
+ CommandLineArguments::Internal::SetOfStrings::iterator sit;
+ for ( sit = mpit->second.begin(); sit != mpit->second.end(); sit++ )
+ {
+ CommandLineArguments::Internal::String::size_type clen = sit->size();
+ switch ( this->Internals->Callbacks[*sit].ArgumentType )
+ {
+ case CommandLineArguments::NO_ARGUMENT: clen += 0; break;
+ case CommandLineArguments::CONCAT_ARGUMENT: clen += 3; break;
+ case CommandLineArguments::SPACE_ARGUMENT: clen += 4; break;
+ case CommandLineArguments::EQUAL_ARGUMENT: clen += 4; break;
+ }
+ if ( clen > maxlen )
+ {
+ maxlen = clen;
+ }
+ }
+ }
+
+ // Create format for that string
+ char format[80];
+ sprintf(format, " %%-%us ", static_cast<unsigned int>(maxlen));
+
+ maxlen += 4; // For the space before and after the option
+
+ // Print help for each option
+ for ( mpit = mp.begin();
+ mpit != mp.end();
+ mpit ++ )
+ {
+ CommandLineArguments::Internal::SetOfStrings::iterator sit;
+ for ( sit = mpit->second.begin(); sit != mpit->second.end(); sit++ )
+ {
+ str << kwsys_ios::endl;
+ char argument[100];
+ sprintf(argument, "%s", sit->c_str());
+ switch ( this->Internals->Callbacks[*sit].ArgumentType )
+ {
+ case CommandLineArguments::NO_ARGUMENT: break;
+ case CommandLineArguments::CONCAT_ARGUMENT: strcat(argument, "opt"); break;
+ case CommandLineArguments::SPACE_ARGUMENT: strcat(argument, " opt"); break;
+ case CommandLineArguments::EQUAL_ARGUMENT: strcat(argument, "=opt"); break;
+ case CommandLineArguments::MULTI_ARGUMENT: strcat(argument, " opt opt ..."); break;
+ }
+ char buffer[80];
+ sprintf(buffer, format, argument);
+ str << buffer;
+ }
+ const char* ptr = this->Internals->Callbacks[mpit->first].Help;
+ size_t len = strlen(ptr);
+ int cnt = 0;
+ while ( len > 0)
+ {
+ // If argument with help is longer than line length, split it on previous
+ // space (or tab) and continue on the next line
+ CommandLineArguments::Internal::String::size_type cc;
+ for ( cc = 0; ptr[cc]; cc ++ )
+ {
+ if ( *ptr == ' ' || *ptr == '\t' )
+ {
+ ptr ++;
+ len --;
+ }
+ }
+ if ( cnt > 0 )
+ {
+ for ( cc = 0; cc < maxlen; cc ++ )
+ {
+ str << " ";
+ }
+ }
+ CommandLineArguments::Internal::String::size_type skip = len;
+ if ( skip > this->LineLength - maxlen )
+ {
+ skip = this->LineLength - maxlen;
+ for ( cc = skip-1; cc > 0; cc -- )
+ {
+ if ( ptr[cc] == ' ' || ptr[cc] == '\t' )
+ {
+ break;
+ }
+ }
+ if ( cc != 0 )
+ {
+ skip = cc;
+ }
+ }
+ str.write(ptr, static_cast<kwsys_ios::streamsize>(skip));
+ str << kwsys_ios::endl;
+ ptr += skip;
+ len -= skip;
+ cnt ++;
+ }
+ }
+ /*
+ // This can help debugging help string
+ str << endl;
+ unsigned int cc;
+ for ( cc = 0; cc < this->LineLength; cc ++ )
+ {
+ str << cc % 10;
+ }
+ str << endl;
+ */
+ this->Help = str.str();
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ bool* variable, const kwsys_stl::string& value)
+{
+ if ( value == "1" || value == "ON" || value == "on" || value == "On" ||
+ value == "TRUE" || value == "true" || value == "True" ||
+ value == "yes" || value == "Yes" || value == "YES" )
+ {
+ *variable = true;
+ }
+ else
+ {
+ *variable = false;
+ }
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ int* variable, const kwsys_stl::string& value)
+{
+ char* res = 0;
+ *variable = static_cast<int>(strtol(value.c_str(), &res, 10));
+ //if ( res && *res )
+ // {
+ // Can handle non-int
+ // }
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ double* variable, const kwsys_stl::string& value)
+{
+ char* res = 0;
+ *variable = strtod(value.c_str(), &res);
+ //if ( res && *res )
+ // {
+ // Can handle non-double
+ // }
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ char** variable, const kwsys_stl::string& value)
+{
+ if ( *variable )
+ {
+ delete [] *variable;
+ *variable = 0;
+ }
+ *variable = new char[ value.size() + 1 ];
+ strcpy(*variable, value.c_str());
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ kwsys_stl::string* variable, const kwsys_stl::string& value)
+{
+ *variable = value;
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ kwsys_stl::vector<bool>* variable, const kwsys_stl::string& value)
+{
+ bool val = false;
+ if ( value == "1" || value == "ON" || value == "on" || value == "On" ||
+ value == "TRUE" || value == "true" || value == "True" ||
+ value == "yes" || value == "Yes" || value == "YES" )
+ {
+ val = true;
+ }
+ variable->push_back(val);
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ kwsys_stl::vector<int>* variable, const kwsys_stl::string& value)
+{
+ char* res = 0;
+ variable->push_back(static_cast<int>(strtol(value.c_str(), &res, 10)));
+ //if ( res && *res )
+ // {
+ // Can handle non-int
+ // }
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ kwsys_stl::vector<double>* variable, const kwsys_stl::string& value)
+{
+ char* res = 0;
+ variable->push_back(strtod(value.c_str(), &res));
+ //if ( res && *res )
+ // {
+ // Can handle non-int
+ // }
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ kwsys_stl::vector<char*>* variable, const kwsys_stl::string& value)
+{
+ char* var = new char[ value.size() + 1 ];
+ strcpy(var, value.c_str());
+ variable->push_back(var);
+}
+
+//----------------------------------------------------------------------------
+void CommandLineArguments::PopulateVariable(
+ kwsys_stl::vector<kwsys_stl::string>* variable,
+ const kwsys_stl::string& value)
+{
+ variable->push_back(value);
+}
+
+//----------------------------------------------------------------------------
+bool CommandLineArguments::PopulateVariable(CommandLineArgumentsCallbackStructure* cs,
+ const char* value)
+{
+ // Call the callback
+ if ( cs->Callback )
+ {
+ if ( !cs->Callback(cs->Argument, value, cs->CallData) )
+ {
+ this->Internals->LastArgument --;
+ return 0;
+ }
+ }
+ CommandLineArguments_DEBUG("Set argument: " << cs->Argument << " to " << value);
+ if ( cs->Variable )
+ {
+ kwsys_stl::string var = "1";
+ if ( value )
+ {
+ var = value;
+ }
+ switch ( cs->VariableType )
+ {
+ case CommandLineArguments::INT_TYPE:
+ this->PopulateVariable(static_cast<int*>(cs->Variable), var);
+ break;
+ case CommandLineArguments::DOUBLE_TYPE:
+ this->PopulateVariable(static_cast<double*>(cs->Variable), var);
+ break;
+ case CommandLineArguments::STRING_TYPE:
+ this->PopulateVariable(static_cast<char**>(cs->Variable), var);
+ break;
+ case CommandLineArguments::STL_STRING_TYPE:
+ this->PopulateVariable(static_cast<kwsys_stl::string*>(cs->Variable), var);
+ break;
+ case CommandLineArguments::BOOL_TYPE:
+ this->PopulateVariable(static_cast<bool*>(cs->Variable), var);
+ break;
+ case CommandLineArguments::VECTOR_BOOL_TYPE:
+ this->PopulateVariable(static_cast<kwsys_stl::vector<bool>*>(cs->Variable), var);
+ break;
+ case CommandLineArguments::VECTOR_INT_TYPE:
+ this->PopulateVariable(static_cast<kwsys_stl::vector<int>*>(cs->Variable), var);
+ break;
+ case CommandLineArguments::VECTOR_DOUBLE_TYPE:
+ this->PopulateVariable(static_cast<kwsys_stl::vector<double>*>(cs->Variable), var);
+ break;
+ case CommandLineArguments::VECTOR_STRING_TYPE:
+ this->PopulateVariable(static_cast<kwsys_stl::vector<char*>*>(cs->Variable), var);
+ break;
+ case CommandLineArguments::VECTOR_STL_STRING_TYPE:
+ this->PopulateVariable(static_cast<kwsys_stl::vector<kwsys_stl::string>*>(cs->Variable), var);
+ break;
+ default:
+ kwsys_ios::cerr << "Got unknown variable type: \"" << cs->VariableType << "\"" << kwsys_ios::endl;
+ this->Internals->LastArgument --;
+ return 0;
+ }
+ }
+ return 1;
+}
+
+
+} // namespace KWSYS_NAMESPACE
diff --git a/Source/kwsys/CommandLineArguments.hxx.in b/Source/kwsys/CommandLineArguments.hxx.in
new file mode 100644
index 0000000000..cbf6ee3938
--- /dev/null
+++ b/Source/kwsys/CommandLineArguments.hxx.in
@@ -0,0 +1,286 @@
+/*============================================================================
+ 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@_CommandLineArguments_hxx
+#define @KWSYS_NAMESPACE@_CommandLineArguments_hxx
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+#include <@KWSYS_NAMESPACE@/stl/string>
+#include <@KWSYS_NAMESPACE@/stl/vector>
+
+/* Define this macro temporarily to keep the code readable. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys_stl @KWSYS_NAMESPACE@_stl
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+
+class CommandLineArgumentsInternal;
+struct CommandLineArgumentsCallbackStructure;
+
+/** \class CommandLineArguments
+ * \brief Command line arguments processing code.
+ *
+ * Find specified arguments with optional options and execute specified methods
+ * or set given variables.
+ *
+ * The two interfaces it knows are callback based and variable based. For
+ * callback based, you have to register callback for particular argument using
+ * AddCallback method. When that argument is passed, the callback will be
+ * called with argument, value, and call data. For boolean (NO_ARGUMENT)
+ * arguments, the value is "1". If the callback returns 0 the argument parsing
+ * will stop with an error.
+ *
+ * For the variable interface you associate variable with each argument. When
+ * the argument is specified, the variable is set to the specified value casted
+ * to the appropriate type. For boolean (NO_ARGUMENT), the value is "1".
+ *
+ * Both interfaces can be used at the same time.
+ *
+ * Possible argument types are:
+ * NO_ARGUMENT - The argument takes no value : --A
+ * CONCAT_ARGUMENT - The argument takes value after no space : --Aval
+ * SPACE_ARGUMENT - The argument takes value after space : --A val
+ * EQUAL_ARGUMENT - The argument takes value after equal : --A=val
+ * MULTI_ARGUMENT - The argument takes values after space : --A val1 val2 val3 ...
+ *
+ * Example use:
+ *
+ * kwsys::CommandLineArguments arg;
+ * arg.Initialize(argc, argv);
+ * typedef kwsys::CommandLineArguments argT;
+ * arg.AddArgument("--something", argT::EQUAL_ARGUMENT, &some_variable,
+ * "This is help string for --something");
+ * if ( !arg.Parse() )
+ * {
+ * kwsys_ios::cerr << "Problem parsing arguments" << kwsys_ios::endl;
+ * res = 1;
+ * }
+ *
+ */
+
+class @KWSYS_NAMESPACE@_EXPORT CommandLineArguments
+{
+public:
+ CommandLineArguments();
+ ~CommandLineArguments();
+
+ /**
+ * Various argument types.
+ */
+ enum ArgumentTypeEnum {
+ NO_ARGUMENT,
+ CONCAT_ARGUMENT,
+ SPACE_ARGUMENT,
+ EQUAL_ARGUMENT,
+ MULTI_ARGUMENT
+ };
+
+ /**
+ * Various variable types. When using the variable interface, this specifies
+ * what type the variable is.
+ */
+ enum VariableTypeEnum {
+ NO_VARIABLE_TYPE = 0, // The variable is not specified
+ INT_TYPE, // The variable is integer (int)
+ BOOL_TYPE, // The variable is boolean (bool)
+ DOUBLE_TYPE, // The variable is float (double)
+ STRING_TYPE, // The variable is string (char*)
+ STL_STRING_TYPE, // The variable is string (char*)
+ VECTOR_INT_TYPE, // The variable is integer (int)
+ VECTOR_BOOL_TYPE, // The variable is boolean (bool)
+ VECTOR_DOUBLE_TYPE, // The variable is float (double)
+ VECTOR_STRING_TYPE, // The variable is string (char*)
+ VECTOR_STL_STRING_TYPE, // The variable is string (char*)
+ LAST_VARIABLE_TYPE
+ };
+
+ /**
+ * Prototypes for callbacks for callback interface.
+ */
+ typedef int(*CallbackType)(const char* argument, const char* value,
+ void* call_data);
+ typedef int(*ErrorCallbackType)(const char* argument, void* client_data);
+
+ /**
+ * Initialize internal data structures. This should be called before parsing.
+ */
+ void Initialize(int argc, const char* const argv[]);
+ void Initialize(int argc, char* argv[]);
+
+ /**
+ * Initialize internal data structure and pass arguments one by one. This is
+ * convenience method for use from scripting languages where argc and argv
+ * are not available.
+ */
+ void Initialize();
+ void ProcessArgument(const char* arg);
+
+ /**
+ * This method will parse arguments and call appropriate methods.
+ */
+ int Parse();
+
+ /**
+ * This method will add a callback for a specific argument. The arguments to
+ * it are argument, argument type, callback method, and call data. The
+ * argument help specifies the help string used with this option. The
+ * callback and call_data can be skipped.
+ */
+ void AddCallback(const char* argument, ArgumentTypeEnum type,
+ CallbackType callback, void* call_data, const char* help);
+
+ /**
+ * Add handler for argument which is going to set the variable to the
+ * specified value. If the argument is specified, the option is casted to the
+ * appropriate type.
+ */
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ bool* variable, const char* help);
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ int* variable, const char* help);
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ double* variable, const char* help);
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ char** variable, const char* help);
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ kwsys_stl::string* variable, const char* help);
+
+ /**
+ * Add handler for argument which is going to set the variable to the
+ * specified value. If the argument is specified, the option is casted to the
+ * appropriate type. This will handle the multi argument values.
+ */
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ kwsys_stl::vector<bool>* variable, const char* help);
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ kwsys_stl::vector<int>* variable, const char* help);
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ kwsys_stl::vector<double>* variable, const char* help);
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ kwsys_stl::vector<char*>* variable, const char* help);
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ kwsys_stl::vector<kwsys_stl::string>* variable, const char* help);
+
+ /**
+ * Add handler for boolean argument. The argument does not take any option
+ * and if it is specified, the value of the variable is true/1, otherwise it
+ * is false/0.
+ */
+ void AddBooleanArgument(const char* argument,
+ bool* variable, const char* help);
+ void AddBooleanArgument(const char* argument,
+ int* variable, const char* help);
+ void AddBooleanArgument(const char* argument,
+ double* variable, const char* help);
+ void AddBooleanArgument(const char* argument,
+ char** variable, const char* help);
+ void AddBooleanArgument(const char* argument,
+ kwsys_stl::string* variable, const char* help);
+
+ /**
+ * Set the callbacks for error handling.
+ */
+ void SetClientData(void* client_data);
+ void SetUnknownArgumentCallback(ErrorCallbackType callback);
+
+ /**
+ * Get remaining arguments. It allocates space for argv, so you have to call
+ * delete[] on it.
+ */
+ void GetRemainingArguments(int* argc, char*** argv);
+ void DeleteRemainingArguments(int argc, char*** argv);
+
+ /**
+ * If StoreUnusedArguments is set to true, then all unknown arguments will be
+ * stored and the user can access the modified argc, argv without known
+ * arguments.
+ */
+ void StoreUnusedArguments(bool val) { this->StoreUnusedArgumentsFlag = val; }
+ void GetUnusedArguments(int* argc, char*** argv);
+
+ /**
+ * Return string containing help. If the argument is specified, only return
+ * help for that argument.
+ */
+ const char* GetHelp() { return this->Help.c_str(); }
+ const char* GetHelp(const char* arg);
+
+ /**
+ * Get / Set the help line length. This length is used when generating the
+ * help page. Default length is 80.
+ */
+ void SetLineLength(unsigned int);
+ unsigned int GetLineLength();
+
+ /**
+ * Get the executable name (argv0). This is only available when using
+ * Initialize with argc/argv.
+ */
+ const char* GetArgv0();
+
+ /**
+ * Get index of the last argument parsed. This is the last argument that was
+ * parsed ok in the original argc/argv list.
+ */
+ unsigned int GetLastArgument();
+
+protected:
+ void GenerateHelp();
+
+ //! This is internal method that registers variable with argument
+ void AddArgument(const char* argument, ArgumentTypeEnum type,
+ VariableTypeEnum vtype, void* variable, const char* help);
+
+ bool GetMatchedArguments(kwsys_stl::vector<kwsys_stl::string>* matches,
+ const kwsys_stl::string& arg);
+
+ //! Populate individual variables
+ bool PopulateVariable(CommandLineArgumentsCallbackStructure* cs,
+ const char* value);
+
+ //! Populate individual variables of type ...
+ void PopulateVariable(bool* variable, const kwsys_stl::string& value);
+ void PopulateVariable(int* variable, const kwsys_stl::string& value);
+ void PopulateVariable(double* variable, const kwsys_stl::string& value);
+ void PopulateVariable(char** variable, const kwsys_stl::string& value);
+ void PopulateVariable(kwsys_stl::string* variable, const kwsys_stl::string& value);
+ void PopulateVariable(kwsys_stl::vector<bool>* variable, const kwsys_stl::string& value);
+ void PopulateVariable(kwsys_stl::vector<int>* variable, const kwsys_stl::string& value);
+ void PopulateVariable(kwsys_stl::vector<double>* variable, const kwsys_stl::string& value);
+ void PopulateVariable(kwsys_stl::vector<char*>* variable, const kwsys_stl::string& value);
+ void PopulateVariable(kwsys_stl::vector<kwsys_stl::string>* variable, const kwsys_stl::string& value);
+
+ typedef CommandLineArgumentsInternal Internal;
+ Internal* Internals;
+ kwsys_stl::string Help;
+
+ unsigned int LineLength;
+
+ bool StoreUnusedArgumentsFlag;
+};
+
+} // namespace @KWSYS_NAMESPACE@
+
+/* Undefine temporary macro. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsys_stl
+#endif
+
+#endif
+
+
+
+
+
diff --git a/Source/kwsys/Configure.h.in b/Source/kwsys/Configure.h.in
new file mode 100644
index 0000000000..70cf8442be
--- /dev/null
+++ b/Source/kwsys/Configure.h.in
@@ -0,0 +1,131 @@
+/*============================================================================
+ 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@_Configure_h
+#define @KWSYS_NAMESPACE@_Configure_h
+
+/* If we are building a kwsys .c or .cxx file, let it use the kwsys
+ namespace. When not building a kwsys source file these macros are
+ temporarily defined inside the headers that use them. */
+#if defined(KWSYS_NAMESPACE)
+# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
+# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
+#endif
+
+/* Disable some warnings inside kwsys source files. */
+#if defined(KWSYS_NAMESPACE)
+# if defined(__BORLANDC__)
+# pragma warn -8027 /* function not inlined. */
+# endif
+# if defined(__INTEL_COMPILER)
+# pragma warning (disable: 1572) /* floating-point equality test */
+# endif
+# if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 3970 /* pointer to int conversion */
+# pragma set woff 3968 /* 64 bit conversion */
+# endif
+#endif
+
+/* Whether kwsys namespace is "kwsys". */
+#define @KWSYS_NAMESPACE@_NAME_IS_KWSYS @KWSYS_NAME_IS_KWSYS@
+
+/* Whether Large File Support is requested. */
+#define @KWSYS_NAMESPACE@_LFS_REQUESTED @KWSYS_LFS_REQUESTED@
+
+/* Whether Large File Support is available. */
+#if @KWSYS_NAMESPACE@_LFS_REQUESTED
+# define @KWSYS_NAMESPACE@_LFS_AVAILABLE @KWSYS_LFS_AVAILABLE@
+#endif
+
+/* Setup Large File Support if requested. */
+#if @KWSYS_NAMESPACE@_LFS_REQUESTED
+ /* Since LFS is requested this header must be included before system
+ headers whether or not LFS is available. */
+# if 0 && (defined(_SYS_TYPES_H) || defined(_SYS_TYPES_INCLUDED))
+# error "@KWSYS_NAMESPACE@/Configure.h must be included before sys/types.h"
+# endif
+ /* Enable the large file API if it is available. */
+# if @KWSYS_NAMESPACE@_LFS_AVAILABLE && \
+ !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINES)
+# if !defined(_LARGEFILE_SOURCE) && \
+ !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGEFILE_SOURCE)
+# define _LARGEFILE_SOURCE
+# endif
+# if !defined(_LARGEFILE64_SOURCE) && \
+ !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGEFILE64_SOURCE)
+# define _LARGEFILE64_SOURCE
+# endif
+# if !defined(_LARGE_FILES) && \
+ !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGE_FILES)
+# define _LARGE_FILES
+# endif
+# if !defined(_FILE_OFFSET_BITS) && \
+ !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_FILE_OFFSET_BITS)
+# define _FILE_OFFSET_BITS 64
+# endif
+# if 0 && (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS < 64)
+# error "_FILE_OFFSET_BITS must be defined to at least 64"
+# endif
+# endif
+#endif
+
+/* Setup the export macro. */
+#if @KWSYS_BUILD_SHARED@
+# if defined(_WIN32) || defined(__CYGWIN__)
+# if defined(@KWSYS_NAMESPACE@_EXPORTS)
+# define @KWSYS_NAMESPACE@_EXPORT __declspec(dllexport)
+# else
+# define @KWSYS_NAMESPACE@_EXPORT __declspec(dllimport)
+# endif
+# elif __GNUC__ >= 4
+# define @KWSYS_NAMESPACE@_EXPORT __attribute__ ((visibility("default")))
+# else
+# define @KWSYS_NAMESPACE@_EXPORT
+# endif
+#else
+# define @KWSYS_NAMESPACE@_EXPORT
+#endif
+
+/* Enable warnings that are off by default but are useful. */
+#if !defined(@KWSYS_NAMESPACE@_NO_WARNING_ENABLE)
+# if defined(_MSC_VER)
+# pragma warning ( default : 4263 ) /* no override, call convention differs */
+# endif
+#endif
+
+/* Disable warnings that are on by default but occur in valid code. */
+#if !defined(@KWSYS_NAMESPACE@_NO_WARNING_DISABLE)
+# if defined(_MSC_VER)
+# pragma warning (disable: 4097) /* typedef is synonym for class */
+# pragma warning (disable: 4127) /* conditional expression is constant */
+# pragma warning (disable: 4244) /* possible loss in conversion */
+# pragma warning (disable: 4251) /* missing DLL-interface */
+# pragma warning (disable: 4305) /* truncation from type1 to type2 */
+# pragma warning (disable: 4309) /* truncation of constant value */
+# pragma warning (disable: 4514) /* unreferenced inline function */
+# pragma warning (disable: 4706) /* assignment in conditional expression */
+# pragma warning (disable: 4710) /* function not inlined */
+# pragma warning (disable: 4786) /* identifier truncated in debug info */
+# endif
+#endif
+
+/* MSVC 6.0 in release mode will warn about code it produces with its
+ optimizer. Disable the warnings specifically for this
+ configuration. Real warnings will be revealed by a debug build or
+ by other compilers. */
+#if !defined(@KWSYS_NAMESPACE@_NO_WARNING_DISABLE_BOGUS)
+# if defined(_MSC_VER) && (_MSC_VER < 1300) && defined(NDEBUG)
+# pragma warning ( disable : 4701 ) /* Variable may be used uninitialized. */
+# pragma warning ( disable : 4702 ) /* Unreachable code. */
+# endif
+#endif
+
+#endif
diff --git a/Source/kwsys/Configure.hxx.in b/Source/kwsys/Configure.hxx.in
new file mode 100644
index 0000000000..8f5ace23ba
--- /dev/null
+++ b/Source/kwsys/Configure.hxx.in
@@ -0,0 +1,179 @@
+/*============================================================================
+ 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@_Configure_hxx
+#define @KWSYS_NAMESPACE@_Configure_hxx
+
+/* Include C configuration. */
+#include <@KWSYS_NAMESPACE@/Configure.h>
+
+/* Whether ANSI C++ stream headers are to be used. */
+#define @KWSYS_NAMESPACE@_IOS_USE_ANSI @KWSYS_IOS_USE_ANSI@
+
+/* Whether ANSI C++ streams are in std namespace. */
+#define @KWSYS_NAMESPACE@_IOS_HAVE_STD @KWSYS_IOS_HAVE_STD@
+
+/* Whether ANSI C++ <sstream> header is to be used. */
+#define @KWSYS_NAMESPACE@_IOS_USE_SSTREAM @KWSYS_IOS_USE_SSTREAM@
+
+/* Whether old C++ <strstream.h> header is to be used. */
+#define @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H @KWSYS_IOS_USE_STRSTREAM_H@
+
+/* Whether old C++ <strstrea.h> header is to be used. */
+#define @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H @KWSYS_IOS_USE_STRSTREA_H@
+
+/* Whether C++ streams support the ios::binary openmode. */
+#define @KWSYS_NAMESPACE@_IOS_HAVE_BINARY @KWSYS_IOS_HAVE_BINARY@
+
+/* Whether STL is in std namespace. */
+#define @KWSYS_NAMESPACE@_STL_HAVE_STD @KWSYS_STL_HAVE_STD@
+
+/* Whether wstring is available. */
+#define @KWSYS_NAMESPACE@_STL_HAS_WSTRING @KWSYS_STL_HAS_WSTRING@
+
+/* Whether the STL string has operator<< for ostream. */
+#define @KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM @KWSYS_STL_STRING_HAVE_OSTREAM@
+
+/* Whether the STL string has operator>> for istream. */
+#define @KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM @KWSYS_STL_STRING_HAVE_ISTREAM@
+
+/* Whether the STL string has operator!= for char*. */
+#define @KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR @KWSYS_STL_STRING_HAVE_NEQ_CHAR@
+
+/* Define the stl namespace macro. */
+#if @KWSYS_NAMESPACE@_STL_HAVE_STD
+# define @KWSYS_NAMESPACE@_stl std
+#else
+# define @KWSYS_NAMESPACE@_stl
+#endif
+
+/* Define the ios namespace macro. */
+#if @KWSYS_NAMESPACE@_IOS_HAVE_STD
+# define @KWSYS_NAMESPACE@_ios_namespace std
+#else
+# define @KWSYS_NAMESPACE@_ios_namespace
+#endif
+#if @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
+# define @KWSYS_NAMESPACE@_ios @KWSYS_NAMESPACE@_ios_namespace
+#else
+# define @KWSYS_NAMESPACE@_ios @KWSYS_NAMESPACE@_ios
+#endif
+
+/* Define the ios::binary openmode macro. */
+#if @KWSYS_NAMESPACE@_IOS_HAVE_BINARY
+# define @KWSYS_NAMESPACE@_ios_binary @KWSYS_NAMESPACE@_ios::ios::binary
+#else
+# define @KWSYS_NAMESPACE@_ios_binary 0
+#endif
+
+/* Whether the cstddef header is available. */
+#define @KWSYS_NAMESPACE@_CXX_HAS_CSTDDEF @KWSYS_CXX_HAS_CSTDDEF@
+
+/* Whether the compiler supports null template arguments. */
+#define @KWSYS_NAMESPACE@_CXX_HAS_NULL_TEMPLATE_ARGS @KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS@
+
+/* Define the null template arguments macro. */
+#if @KWSYS_NAMESPACE@_CXX_HAS_NULL_TEMPLATE_ARGS
+# define @KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS <>
+#else
+# define @KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS
+#endif
+
+/* Whether the compiler supports member templates. */
+#define @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES @KWSYS_CXX_HAS_MEMBER_TEMPLATES@
+
+/* Whether the compiler supports argument dependent lookup. */
+#define @KWSYS_NAMESPACE@_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP @KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP@
+
+/* Whether the compiler supports standard full specialization syntax. */
+#define @KWSYS_NAMESPACE@_CXX_HAS_FULL_SPECIALIZATION @KWSYS_CXX_HAS_FULL_SPECIALIZATION@
+
+/* Define the specialization definition macro. */
+#if @KWSYS_NAMESPACE@_CXX_HAS_FULL_SPECIALIZATION
+# define @KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION template <>
+#else
+# define @KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+#endif
+
+/* Define typename keyword macro for use in declarations. */
+#if defined(_MSC_VER) && _MSC_VER < 1300
+# define @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME
+#else
+# define @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME typename
+#endif
+
+/* Whether the stl has iterator_traits. */
+#define @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_TRAITS @KWSYS_STL_HAS_ITERATOR_TRAITS@
+
+/* Whether the stl has iterator_category. */
+#define @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_CATEGORY @KWSYS_STL_HAS_ITERATOR_CATEGORY@
+
+/* Whether the stl has __iterator_category. */
+#define @KWSYS_NAMESPACE@_STL_HAS___ITERATOR_CATEGORY @KWSYS_STL_HAS___ITERATOR_CATEGORY@
+
+/* Whether the stl allocator is the standard template. */
+#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_TEMPLATE @KWSYS_STL_HAS_ALLOCATOR_TEMPLATE@
+
+/* Whether the stl allocator is not a template. */
+#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE @KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE@
+
+/* Whether the stl allocator has rebind. */
+#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND @KWSYS_STL_HAS_ALLOCATOR_REBIND@
+
+/* Whether the stl allocator has a size argument for max_size. */
+#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT @KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT@
+
+/* Whether the stl containers support allocator objects. */
+#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_OBJECTS @KWSYS_STL_HAS_ALLOCATOR_OBJECTS@
+
+/* Whether struct stat has the st_mtim member for high resolution times. */
+#define @KWSYS_NAMESPACE@_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)
+# if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys_stl @KWSYS_NAMESPACE@_stl
+# define kwsys_ios @KWSYS_NAMESPACE@_ios
+# define kwsys @KWSYS_NAMESPACE@
+# define kwsys_ios_binary @KWSYS_NAMESPACE@_ios_binary
+# endif
+# define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define KWSYS_STL_HAVE_STD @KWSYS_NAMESPACE@_STL_HAVE_STD
+# define KWSYS_IOS_HAVE_STD @KWSYS_NAMESPACE@_IOS_HAVE_STD
+# define KWSYS_IOS_USE_ANSI @KWSYS_NAMESPACE@_IOS_USE_ANSI
+# define KWSYS_IOS_USE_SSTREAM @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
+# define KWSYS_IOS_USE_STRSTREAM_H @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H
+# define KWSYS_IOS_USE_STRSTREA_H @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H
+# define KWSYS_IOS_HAVE_BINARY @KWSYS_NAMESPACE@_IOS_HAVE_BINARY
+# define KWSYS_STAT_HAS_ST_MTIM @KWSYS_NAMESPACE@_STAT_HAS_ST_MTIM
+# define KWSYS_CXX_HAS_CSTDDEF @KWSYS_NAMESPACE@_CXX_HAS_CSTDDEF
+# define KWSYS_STL_STRING_HAVE_OSTREAM @KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM
+# define KWSYS_STL_STRING_HAVE_ISTREAM @KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM
+# define KWSYS_STL_STRING_HAVE_NEQ_CHAR @KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR
+# define KWSYS_CXX_NULL_TEMPLATE_ARGS @KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS
+# define KWSYS_CXX_HAS_MEMBER_TEMPLATES @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+# define KWSYS_CXX_HAS_FULL_SPECIALIZATION @KWSYS_NAMESPACE@_CXX_HAS_FULL_SPECIALIZATION
+# define KWSYS_CXX_DEFINE_SPECIALIZATION @KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+# define KWSYS_CXX_DECL_TYPENAME @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME
+# define KWSYS_STL_HAS_ALLOCATOR_REBIND @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND
+# define KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
+# define KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP @KWSYS_NAMESPACE@_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
+# define KWSYS_STL_HAS_ITERATOR_TRAITS @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_TRAITS
+# define KWSYS_STL_HAS_ITERATOR_CATEGORY @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_CATEGORY
+# define KWSYS_STL_HAS___ITERATOR_CATEGORY @KWSYS_NAMESPACE@_STL_HAS___ITERATOR_CATEGORY
+# define KWSYS_STL_HAS_ALLOCATOR_TEMPLATE @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_TEMPLATE
+# define KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
+# define KWSYS_STL_HAS_ALLOCATOR_OBJECTS @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_OBJECTS
+# define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING
+#endif
+
+#endif
diff --git a/Source/kwsys/Copyright.txt b/Source/kwsys/Copyright.txt
new file mode 100644
index 0000000000..1549a7d5f5
--- /dev/null
+++ b/Source/kwsys/Copyright.txt
@@ -0,0 +1,31 @@
+KWSys - Kitware System Library
+Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+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 names of Kitware, Inc., the Insight Software Consortium,
+ nor the names of their 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.
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx
new file mode 100644
index 0000000000..741bcba271
--- /dev/null
+++ b/Source/kwsys/Directory.cxx
@@ -0,0 +1,253 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Directory.hxx)
+
+#include KWSYS_HEADER(Configure.hxx)
+
+#include KWSYS_HEADER(Encoding.hxx)
+
+#include KWSYS_HEADER(stl/string)
+#include KWSYS_HEADER(stl/vector)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "Directory.hxx.in"
+# include "Configure.hxx.in"
+# include "Encoding.hxx.in"
+# include "kwsys_stl.hxx.in"
+# include "kwsys_stl_string.hxx.in"
+# include "kwsys_stl_vector.hxx.in"
+#endif
+
+namespace KWSYS_NAMESPACE
+{
+
+//----------------------------------------------------------------------------
+class DirectoryInternals
+{
+public:
+ // Array of Files
+ kwsys_stl::vector<kwsys_stl::string> Files;
+
+ // Path to Open'ed directory
+ kwsys_stl::string Path;
+};
+
+//----------------------------------------------------------------------------
+Directory::Directory()
+{
+ this->Internal = new DirectoryInternals;
+}
+
+//----------------------------------------------------------------------------
+Directory::~Directory()
+{
+ delete this->Internal;
+}
+
+//----------------------------------------------------------------------------
+unsigned long Directory::GetNumberOfFiles() const
+{
+ return static_cast<unsigned long>(this->Internal->Files.size());
+}
+
+//----------------------------------------------------------------------------
+const char* Directory::GetFile(unsigned long dindex) const
+{
+ if ( dindex >= this->Internal->Files.size() )
+ {
+ return 0;
+ }
+ return this->Internal->Files[dindex].c_str();
+}
+
+//----------------------------------------------------------------------------
+const char* Directory::GetPath() const
+{
+ return this->Internal->Path.c_str();
+}
+
+//----------------------------------------------------------------------------
+void Directory::Clear()
+{
+ this->Internal->Path.resize(0);
+ this->Internal->Files.clear();
+}
+
+} // namespace KWSYS_NAMESPACE
+
+// First microsoft compilers
+
+#if defined(_MSC_VER) || defined(__WATCOMC__)
+#include <windows.h>
+#include <io.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+namespace KWSYS_NAMESPACE
+{
+
+bool Directory::Load(const kwsys_stl::string& name)
+{
+ this->Clear();
+#if _MSC_VER < 1300
+ long srchHandle;
+#else
+ intptr_t srchHandle;
+#endif
+ char* buf;
+ size_t n = name.size();
+ if ( *name.rbegin() == '/' || *name.rbegin() == '\\' )
+ {
+ buf = new char[n + 1 + 1];
+ sprintf(buf, "%s*", name.c_str());
+ }
+ else
+ {
+ // Make sure the slashes in the wildcard suffix are consistent with the
+ // rest of the path
+ buf = new char[n + 2 + 1];
+ if ( name.find('\\') != name.npos )
+ {
+ sprintf(buf, "%s\\*", name.c_str());
+ }
+ else
+ {
+ sprintf(buf, "%s/*", name.c_str());
+ }
+ }
+ struct _wfinddata_t data; // data of current file
+
+ // Now put them into the file array
+ srchHandle = _wfindfirst((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
+ delete [] buf;
+
+ if ( srchHandle == -1 )
+ {
+ return 0;
+ }
+
+ // Loop through names
+ do
+ {
+ this->Internal->Files.push_back(Encoding::ToNarrow(data.name));
+ }
+ while ( _wfindnext(srchHandle, &data) != -1 );
+ this->Internal->Path = name;
+ return _findclose(srchHandle) != -1;
+}
+
+unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name)
+{
+#if _MSC_VER < 1300
+ long srchHandle;
+#else
+ intptr_t srchHandle;
+#endif
+ char* buf;
+ size_t n = name.size();
+ if ( *name.rbegin() == '/' )
+ {
+ buf = new char[n + 1 + 1];
+ sprintf(buf, "%s*", name.c_str());
+ }
+ else
+ {
+ buf = new char[n + 2 + 1];
+ sprintf(buf, "%s/*", name.c_str());
+ }
+ struct _wfinddata_t data; // data of current file
+
+ // Now put them into the file array
+ srchHandle = _wfindfirst((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
+ delete [] buf;
+
+ if ( srchHandle == -1 )
+ {
+ return 0;
+ }
+
+ // Loop through names
+ unsigned long count = 0;
+ do
+ {
+ count++;
+ }
+ while ( _wfindnext(srchHandle, &data) != -1 );
+ _findclose(srchHandle);
+ return count;
+}
+
+} // namespace KWSYS_NAMESPACE
+
+#else
+
+// Now the POSIX style directory access
+
+#include <sys/types.h>
+#include <dirent.h>
+
+/* There is a problem with the Portland compiler, large file
+support and glibc/Linux system headers:
+http://www.pgroup.com/userforum/viewtopic.php?
+p=1992&sid=f16167f51964f1a68fe5041b8eb213b6
+*/
+#if defined(__PGI) && defined(__USE_FILE_OFFSET64)
+# define dirent dirent64
+#endif
+
+namespace KWSYS_NAMESPACE
+{
+
+bool Directory::Load(const kwsys_stl::string& name)
+{
+ this->Clear();
+
+ DIR* dir = opendir(name.c_str());
+
+ if (!dir)
+ {
+ return 0;
+ }
+
+ for (dirent* d = readdir(dir); d; d = readdir(dir) )
+ {
+ this->Internal->Files.push_back(d->d_name);
+ }
+ this->Internal->Path = name;
+ closedir(dir);
+ return 1;
+}
+
+unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name)
+{
+ DIR* dir = opendir(name.c_str());
+
+ unsigned long count = 0;
+ for (dirent* d = readdir(dir); d; d = readdir(dir) )
+ {
+ count++;
+ }
+ closedir(dir);
+ return count;
+}
+
+} // namespace KWSYS_NAMESPACE
+
+#endif
diff --git a/Source/kwsys/Directory.hxx.in b/Source/kwsys/Directory.hxx.in
new file mode 100644
index 0000000000..0acb1913f4
--- /dev/null
+++ b/Source/kwsys/Directory.hxx.in
@@ -0,0 +1,93 @@
+/*============================================================================
+ 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@_Directory_hxx
+#define @KWSYS_NAMESPACE@_Directory_hxx
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+#include <@KWSYS_NAMESPACE@/stl/string>
+
+/* Define these macros temporarily to keep the code readable. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys_stl @KWSYS_NAMESPACE@_stl
+# define kwsys_ios @KWSYS_NAMESPACE@_ios
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+
+class DirectoryInternals;
+
+/** \class Directory
+ * \brief Portable directory/filename traversal.
+ *
+ * Directory provides a portable way of finding the names of the files
+ * in a system directory.
+ *
+ * Directory currently works with Windows and Unix operating systems.
+ */
+class @KWSYS_NAMESPACE@_EXPORT Directory
+{
+public:
+ Directory();
+ ~Directory();
+
+ /**
+ * Load the specified directory and load the names of the files
+ * in that directory. 0 is returned if the directory can not be
+ * opened, 1 if it is opened.
+ */
+ bool Load(const kwsys_stl::string&);
+
+ /**
+ * Return the number of files in the current directory.
+ */
+ unsigned long GetNumberOfFiles() const;
+
+ /**
+ * Return the number of files in the specified directory.
+ * A higher performance static method.
+ */
+ static unsigned long GetNumberOfFilesInDirectory(const kwsys_stl::string&);
+
+ /**
+ * Return the file at the given index, the indexing is 0 based
+ */
+ const char* GetFile(unsigned long) const;
+
+ /**
+ * Return the path to Open'ed directory
+ */
+ const char* GetPath() const;
+
+ /**
+ * Clear the internal structure. Used internally at beginning of Load(...)
+ * to clear the cache.
+ */
+ void Clear();
+
+private:
+ // Private implementation details.
+ DirectoryInternals* Internal;
+
+ Directory(const Directory&); // Not implemented.
+ void operator=(const Directory&); // Not implemented.
+}; // End Class: Directory
+
+} // namespace @KWSYS_NAMESPACE@
+
+/* Undefine temporary macros. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsys_stl
+# undef kwsys_ios
+#endif
+
+#endif
diff --git a/Source/kwsys/DynamicLoader.cxx b/Source/kwsys/DynamicLoader.cxx
new file mode 100644
index 0000000000..44cf6af7e8
--- /dev/null
+++ b/Source/kwsys/DynamicLoader.cxx
@@ -0,0 +1,527 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(DynamicLoader.hxx)
+
+#include KWSYS_HEADER(Configure.hxx)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "DynamicLoader.hxx.in"
+# include "Configure.hxx.in"
+#endif
+
+// This file is actually 3 different implementations.
+// 1. HP machines which uses shl_load
+// 2. Mac OS X 10.2.x and earlier which uses NSLinkModule
+// 3. Windows which uses LoadLibrary
+// 4. Most unix systems (including Mac OS X 10.3 and later) which use dlopen
+// (default) Each part of the ifdef contains a complete implementation for
+// the static methods of DynamicLoader.
+
+// ---------------------------------------------------------------
+// 1. Implementation for HPUX machines
+#ifdef __hpux
+#include <errno.h>
+#include <dl.h>
+#define DYNAMICLOADER_DEFINED 1
+
+namespace KWSYS_NAMESPACE
+{
+
+//----------------------------------------------------------------------------
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname )
+{
+ return shl_load(libname, BIND_DEFERRED | DYNAMIC_PATH, 0L);
+}
+
+//----------------------------------------------------------------------------
+int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
+{
+ return !shl_unload(lib);
+}
+
+//----------------------------------------------------------------------------
+DynamicLoader::SymbolPointer
+DynamicLoader::GetSymbolAddress(DynamicLoader::LibraryHandle lib, const char* sym)
+{
+ void* addr;
+ int status;
+
+ /* TYPE_PROCEDURE Look for a function or procedure. (This used to be default)
+ * TYPE_DATA Look for a symbol in the data segment (for example, variables).
+ * TYPE_UNDEFINED Look for any symbol.
+ */
+ status = shl_findsym (&lib, sym, TYPE_UNDEFINED, &addr);
+ void* result = (status < 0) ? (void*)0 : addr;
+
+ // Hack to cast pointer-to-data to pointer-to-function.
+ return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
+}
+
+const char* DynamicLoader::LastError()
+{
+ // TODO: Need implementation with errno/strerror
+ /* If successful, shl_findsym returns an integer (int) value zero. If
+ * shl_findsym cannot find sym, it returns -1 and sets errno to zero.
+ * If any other errors occur, shl_findsym returns -1 and sets errno to one
+ * of these values (defined in <errno.h>):
+ * ENOEXEC
+ * A format error was detected in the specified library.
+ * ENOSYM
+ * A symbol on which sym depends could not be found.
+ * EINVAL
+ * The specified handle is invalid.
+ */
+
+ if( errno == ENOEXEC
+ || errno == ENOSYM
+ || errno == EINVAL )
+ {
+ return strerror(errno);
+ }
+ // else
+ return 0;
+}
+
+} // namespace KWSYS_NAMESPACE
+
+#endif //__hpux
+
+
+// ---------------------------------------------------------------
+// 2. Implementation for Mac OS X 10.2.x and earlier
+#ifdef __APPLE__
+#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
+#include <string.h> // for strlen
+#include <mach-o/dyld.h>
+#define DYNAMICLOADER_DEFINED 1
+
+namespace KWSYS_NAMESPACE
+{
+
+//----------------------------------------------------------------------------
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname )
+{
+ NSObjectFileImageReturnCode rc;
+ NSObjectFileImage image = 0;
+
+ rc = NSCreateObjectFileImageFromFile(libname, &image);
+ // rc == NSObjectFileImageInappropriateFile when trying to load a dylib file
+ if( rc != NSObjectFileImageSuccess )
+ {
+ return 0;
+ }
+ NSModule handle = NSLinkModule(image, libname,
+ NSLINKMODULE_OPTION_BINDNOW|NSLINKMODULE_OPTION_RETURN_ON_ERROR);
+ NSDestroyObjectFileImage(image);
+ return handle;
+}
+
+//----------------------------------------------------------------------------
+int DynamicLoader::CloseLibrary( DynamicLoader::LibraryHandle lib)
+{
+ // NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED
+ // With this option the memory for the module is not deallocated
+ // allowing pointers into the module to still be valid.
+ // You should use this option instead if your code experience some problems
+ // reported against Panther 10.3.9 (fixed in Tiger 10.4.2 and up)
+ bool success = NSUnLinkModule(lib, NSUNLINKMODULE_OPTION_NONE);
+ return success;
+}
+
+//----------------------------------------------------------------------------
+DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
+ DynamicLoader::LibraryHandle lib, const char* sym)
+{
+ void *result=0;
+ // Need to prepend symbols with '_' on Apple-gcc compilers
+ size_t len = strlen(sym);
+ char *rsym = new char[len + 1 + 1];
+ strcpy(rsym, "_");
+ strcat(rsym+1, sym);
+
+ NSSymbol symbol = NSLookupSymbolInModule(lib, rsym);
+ if(symbol)
+ {
+ result = NSAddressOfSymbol(symbol);
+ }
+
+ delete[] rsym;
+ // Hack to cast pointer-to-data to pointer-to-function.
+ return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
+}
+
+//----------------------------------------------------------------------------
+const char* DynamicLoader::LastError()
+{
+ return 0;
+}
+
+} // namespace KWSYS_NAMESPACE
+
+#endif // MAC_OS_X_VERSION_MAX_ALLOWED < 1030
+#endif // __APPLE__
+
+// ---------------------------------------------------------------
+// 3. Implementation for Windows win32 code but not cygwin
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <windows.h>
+#define DYNAMICLOADER_DEFINED 1
+
+namespace KWSYS_NAMESPACE
+{
+
+//----------------------------------------------------------------------------
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname)
+{
+ DynamicLoader::LibraryHandle lh;
+ int length = MultiByteToWideChar(CP_UTF8, 0, libname, -1, NULL, 0);
+ wchar_t* wchars = new wchar_t[length+1];
+ wchars[0] = '\0';
+ MultiByteToWideChar(CP_UTF8, 0, libname, -1, wchars, length);
+ lh = LoadLibraryW(wchars);
+ delete [] wchars;
+ return lh;
+}
+
+//----------------------------------------------------------------------------
+int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
+{
+ return (int)FreeLibrary(lib);
+}
+
+//----------------------------------------------------------------------------
+DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
+ DynamicLoader::LibraryHandle lib, const char* sym)
+{
+ // TODO: The calling convention affects the name of the symbol. We
+ // should have a tool to help get the symbol with the desired
+ // calling convention. Currently we assume cdecl.
+ //
+ // Borland:
+ // __cdecl = "_func" (default)
+ // __fastcall = "@_func"
+ // __stdcall = "func"
+ //
+ // Watcom:
+ // __cdecl = "_func"
+ // __fastcall = "@_func@X"
+ // __stdcall = "_func@X"
+ // __watcall = "func_" (default)
+ //
+ // MSVC:
+ // __cdecl = "func" (default)
+ // __fastcall = "@_func@X"
+ // __stdcall = "_func@X"
+ //
+ // Note that the "@X" part of the name above is the total size (in
+ // bytes) of the arguments on the stack.
+ void *result;
+#if defined(__BORLANDC__) || defined(__WATCOMC__)
+ // Need to prepend symbols with '_'
+ size_t len = strlen(sym);
+ char *rsym = new char[len + 1 + 1];
+ strcpy(rsym, "_");
+ strcat(rsym, sym);
+#else
+ const char *rsym = sym;
+#endif
+ result = (void*)GetProcAddress(lib, rsym);
+#if defined(__BORLANDC__) || defined(__WATCOMC__)
+ delete[] rsym;
+#endif
+ // Hack to cast pointer-to-data to pointer-to-function.
+#ifdef __WATCOMC__
+ return *(DynamicLoader::SymbolPointer*)(&result);
+#else
+ return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
+#endif
+}
+
+//----------------------------------------------------------------------------
+const char* DynamicLoader::LastError()
+{
+ LPVOID lpMsgBuf=NULL;
+
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR) &lpMsgBuf,
+ 0,
+ NULL
+ );
+
+ if(!lpMsgBuf)
+ {
+ return NULL;
+ }
+
+ static char* str = 0;
+ delete [] str;
+ str = strcpy(new char[strlen((char*)lpMsgBuf)+1], (char*)lpMsgBuf);
+ // Free the buffer.
+ LocalFree( lpMsgBuf );
+ return str;
+}
+
+} // namespace KWSYS_NAMESPACE
+
+#endif //_WIN32
+
+// ---------------------------------------------------------------
+// 4. Implementation for BeOS
+#if defined __BEOS__
+
+#include <string.h> // for strerror()
+
+#include <be/kernel/image.h>
+#include <be/support/Errors.h>
+
+#define DYNAMICLOADER_DEFINED 1
+
+namespace KWSYS_NAMESPACE
+{
+
+static image_id last_dynamic_err = B_OK;
+
+//----------------------------------------------------------------------------
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname )
+{
+ // image_id's are integers, errors are negative. Add one just in case we
+ // get a valid image_id of zero (is that even possible?).
+ image_id rc = load_add_on(libname);
+ if (rc < 0)
+ {
+ last_dynamic_err = rc;
+ return 0;
+ }
+
+ return rc+1;
+}
+
+//----------------------------------------------------------------------------
+int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
+{
+ if (!lib)
+ {
+ last_dynamic_err = B_BAD_VALUE;
+ return 0;
+ }
+ else
+ {
+ // The function dlclose() returns 0 on success, and non-zero on error.
+ status_t rc = unload_add_on(lib-1);
+ if (rc != B_OK)
+ {
+ last_dynamic_err = rc;
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
+ DynamicLoader::LibraryHandle lib, const char* sym)
+{
+ // Hack to cast pointer-to-data to pointer-to-function.
+ union
+ {
+ void* pvoid;
+ DynamicLoader::SymbolPointer psym;
+ } result;
+
+ result.psym = NULL;
+
+ if (!lib)
+ {
+ last_dynamic_err = B_BAD_VALUE;
+ }
+ else
+ {
+ // !!! FIXME: BeOS can do function-only lookups...does this ever
+ // !!! FIXME: actually _want_ a data symbol lookup, or was this union
+ // !!! FIXME: a leftover of dlsym()? (s/ANY/TEXT for functions only).
+ status_t rc = get_image_symbol(lib-1,sym,B_SYMBOL_TYPE_ANY,&result.pvoid);
+ if (rc != B_OK)
+ {
+ last_dynamic_err = rc;
+ result.psym = NULL;
+ }
+ }
+ return result.psym;
+}
+
+//----------------------------------------------------------------------------
+const char* DynamicLoader::LastError()
+{
+ const char *retval = strerror(last_dynamic_err);
+ last_dynamic_err = B_OK;
+ return retval;
+}
+
+} // namespace KWSYS_NAMESPACE
+#endif
+
+// ---------------------------------------------------------------
+// 5. Implementation for systems without dynamic libs
+// __gnu_blrts__ is IBM BlueGene/L
+// __LIBCATAMOUNT__ is defined on Catamount on Cray compute nodes
+#if defined(__gnu_blrts__) || defined(__LIBCATAMOUNT__) || defined(__CRAYXT_COMPUTE_LINUX_TARGET)
+#include <string.h> // for strerror()
+#define DYNAMICLOADER_DEFINED 1
+
+namespace KWSYS_NAMESPACE
+{
+
+//----------------------------------------------------------------------------
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname )
+{
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
+{
+ if (!lib)
+ {
+ return 0;
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
+ DynamicLoader::LibraryHandle lib, const char* sym)
+{
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+const char* DynamicLoader::LastError()
+ {
+ return "General error";
+ }
+
+} // namespace KWSYS_NAMESPACE
+#endif
+
+#ifdef __MINT__
+#define DYNAMICLOADER_DEFINED 1
+#define _GNU_SOURCE /* for program_invocation_name */
+#include <string.h>
+#include <malloc.h>
+#include <errno.h>
+#include <dld.h>
+
+namespace KWSYS_NAMESPACE
+{
+
+//----------------------------------------------------------------------------
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname )
+{
+ char *name = (char *)calloc(1, strlen(libname) + 1);
+ dld_init(program_invocation_name);
+ strncpy(name, libname, strlen(libname));
+ dld_link(libname);
+ return (void *)name;
+}
+
+//----------------------------------------------------------------------------
+int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
+{
+ dld_unlink_by_file((char *)lib, 0);
+ free(lib);
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
+ DynamicLoader::LibraryHandle lib, const char* sym)
+{
+ // Hack to cast pointer-to-data to pointer-to-function.
+ union
+ {
+ void* pvoid;
+ DynamicLoader::SymbolPointer psym;
+ } result;
+ result.pvoid = dld_get_symbol(sym);
+ return result.psym;
+}
+
+//----------------------------------------------------------------------------
+const char* DynamicLoader::LastError()
+{
+ return dld_strerror(dld_errno);
+}
+
+} // namespace KWSYS_NAMESPACE
+#endif
+
+// ---------------------------------------------------------------
+// 6. Implementation for default UNIX machines.
+// if nothing has been defined then use this
+#ifndef DYNAMICLOADER_DEFINED
+#define DYNAMICLOADER_DEFINED 1
+// Setup for most unix machines
+#include <dlfcn.h>
+
+namespace KWSYS_NAMESPACE
+{
+
+//----------------------------------------------------------------------------
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname )
+{
+ return dlopen(libname, RTLD_LAZY);
+}
+
+//----------------------------------------------------------------------------
+int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
+{
+ if (lib)
+ {
+ // The function dlclose() returns 0 on success, and non-zero on error.
+ return !dlclose(lib);
+ }
+ // else
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
+ DynamicLoader::LibraryHandle lib, const char* sym)
+{
+ // Hack to cast pointer-to-data to pointer-to-function.
+ union
+ {
+ void* pvoid;
+ DynamicLoader::SymbolPointer psym;
+ } result;
+ result.pvoid = dlsym(lib, sym);
+ return result.psym;
+}
+
+//----------------------------------------------------------------------------
+const char* DynamicLoader::LastError()
+{
+ return dlerror();
+}
+
+} // namespace KWSYS_NAMESPACE
+
+#endif
diff --git a/Source/kwsys/DynamicLoader.hxx.in b/Source/kwsys/DynamicLoader.hxx.in
new file mode 100644
index 0000000000..64468ecd37
--- /dev/null
+++ b/Source/kwsys/DynamicLoader.hxx.in
@@ -0,0 +1,101 @@
+/*============================================================================
+ 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@_DynamicLoader_hxx
+#define @KWSYS_NAMESPACE@_DynamicLoader_hxx
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+
+#if defined(__hpux)
+ #include <dl.h>
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ #include <windows.h>
+#elif defined(__APPLE__)
+ #include <AvailabilityMacros.h>
+ #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
+ #include <mach-o/dyld.h>
+ #endif
+#elif defined(__BEOS__)
+ #include <be/kernel/image.h>
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+/** \class DynamicLoader
+ * \brief Portable loading of dynamic libraries or dll's.
+ *
+ * DynamicLoader provides a portable interface to loading dynamic
+ * libraries or dll's into a process.
+ *
+ * Directory currently works with Windows, Apple, HP-UX and Unix (POSIX)
+ * operating systems
+ *
+ * \warning dlopen on *nix system works the following way:
+ * If filename contains a slash ("/"), then it is interpreted as a (relative
+ * or absolute) pathname. Otherwise, the dynamic linker searches for the
+ * library as follows : see ld.so(8) for further details):
+ * Whereas this distinction does not exist on Win32. Therefore ideally you
+ * should be doing full path to garantee to have a consistent way of dealing
+ * with dynamic loading of shared library.
+ *
+ * \warning the Cygwin implementation do not use the Win32 HMODULE. Put extra
+ * condition so that we can include the correct declaration (POSIX)
+ */
+
+class @KWSYS_NAMESPACE@_EXPORT DynamicLoader
+{
+public:
+// Ugly stuff for library handles
+// They are different on several different OS's
+#if defined(__hpux)
+ typedef shl_t LibraryHandle;
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ typedef HMODULE LibraryHandle;
+#elif defined(__APPLE__)
+ #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
+ typedef NSModule LibraryHandle;
+ #else
+ typedef void* LibraryHandle;
+ #endif
+#elif defined(__BEOS__)
+ typedef image_id LibraryHandle;
+#else // POSIX
+ typedef void* LibraryHandle;
+#endif
+
+ // Return type from DynamicLoader::GetSymbolAddress.
+ typedef void (*SymbolPointer)();
+
+ /** Load a dynamic library into the current process.
+ * The returned LibraryHandle can be used to access the symbols in the
+ * library. */
+ static LibraryHandle OpenLibrary(const char*);
+
+ /** Attempt to detach a dynamic library from the
+ * process. A value of true is returned if it is sucessful. */
+ static int CloseLibrary(LibraryHandle);
+
+ /** Find the address of the symbol in the given library. */
+ static SymbolPointer GetSymbolAddress(LibraryHandle, const char*);
+
+ /** Return the default module prefix for the current platform. */
+ static const char* LibPrefix() { return "@KWSYS_DynamicLoader_PREFIX@"; }
+
+ /** Return the default module suffix for the current platform. */
+ static const char* LibExtension() { return "@KWSYS_DynamicLoader_SUFFIX@"; }
+
+ /** Return the last error produced from a calls made on this class. */
+ static const char* LastError();
+}; // End Class: DynamicLoader
+
+} // namespace @KWSYS_NAMESPACE@
+
+#endif
diff --git a/Source/kwsys/Encoding.h.in b/Source/kwsys/Encoding.h.in
new file mode 100644
index 0000000000..591c5a8986
--- /dev/null
+++ b/Source/kwsys/Encoding.h.in
@@ -0,0 +1,79 @@
+/*============================================================================
+ 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@_Encoding_h
+#define @KWSYS_NAMESPACE@_Encoding_h
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+#include <wchar.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@_EXPORT
+#endif
+#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsysEncoding kwsys_ns(Encoding)
+# define kwsysEncoding_mbstowcs kwsys_ns(Encoding_mbstowcs)
+# define kwsysEncoding_DupToWide kwsys_ns(Encoding_DupToWide)
+# define kwsysEncoding_wcstombs kwsys_ns(Encoding_wcstombs)
+# define kwsysEncoding_DupToNarrow kwsys_ns(Encoding_DupToNarrow)
+#endif
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+
+/* Convert a narrow string to a wide string.
+ On Windows, UTF-8 is assumed, and on other platforms,
+ the current locale is assumed.
+ */
+kwsysEXPORT size_t kwsysEncoding_mbstowcs(wchar_t* dest, const char* src, size_t n);
+
+/* Convert a narrow string to a wide string.
+ This can return NULL if the conversion fails. */
+kwsysEXPORT wchar_t* kwsysEncoding_DupToWide(const char* src);
+
+
+/* Convert a wide string to a narrow string.
+ On Windows, UTF-8 is assumed, and on other platforms,
+ the current locale is assumed. */
+kwsysEXPORT size_t kwsysEncoding_wcstombs(char* dest, const wchar_t* src, size_t n);
+
+/* Convert a wide string to a narrow string.
+ This can return NULL if the conversion fails. */
+kwsysEXPORT char* kwsysEncoding_DupToNarrow(const wchar_t* str);
+
+
+#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@_NAME_IS_KWSYS
+# undef kwsysEncoding
+# undef kwsysEncoding_mbstowcs
+# undef kwsysEncoding_DupToWide
+# undef kwsysEncoding_wcstombs
+# undef kwsysEncoding_DupToNarrow
+# endif
+#endif
+
+#endif
diff --git a/Source/kwsys/Encoding.hxx.in b/Source/kwsys/Encoding.hxx.in
new file mode 100644
index 0000000000..aba4175545
--- /dev/null
+++ b/Source/kwsys/Encoding.hxx.in
@@ -0,0 +1,87 @@
+/*============================================================================
+ 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@_Encoding_hxx
+#define @KWSYS_NAMESPACE@_Encoding_hxx
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+#include <@KWSYS_NAMESPACE@/stl/string>
+#include <@KWSYS_NAMESPACE@/stl/vector>
+
+/* Define these macros temporarily to keep the code readable. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys_stl @KWSYS_NAMESPACE@_stl
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+class @KWSYS_NAMESPACE@_EXPORT Encoding
+{
+public:
+
+ // Container class for argc/argv.
+ class CommandLineArguments
+ {
+ public:
+ // On Windows, get the program command line arguments
+ // in this Encoding module's 8 bit encoding.
+ // On other platforms the given argc/argv is used, and
+ // to be consistent, should be the argc/argv from main().
+ static CommandLineArguments Main(int argc, char const* const* argv);
+
+ // Construct CommandLineArguments with the given
+ // argc/argv. It is assumed that the string is already
+ // in the encoding used by this module.
+ CommandLineArguments(int argc, char const* const* argv);
+
+ // Construct CommandLineArguments with the given
+ // argc and wide argv. This is useful if wmain() is used.
+ CommandLineArguments(int argc, wchar_t const* const* argv);
+ ~CommandLineArguments();
+ CommandLineArguments(const CommandLineArguments&);
+ CommandLineArguments& operator=(const CommandLineArguments&);
+
+ int argc() const;
+ char const* const* argv() const;
+
+ protected:
+ std::vector<char*> argv_;
+ };
+
+ /**
+ * Convert between char and wchar_t
+ */
+
+#if @KWSYS_NAMESPACE@_STL_HAS_WSTRING
+
+ // Convert a narrow string to a wide string.
+ // On Windows, UTF-8 is assumed, and on other platforms,
+ // the current locale is assumed.
+ static kwsys_stl::wstring ToWide(const kwsys_stl::string& str);
+ static kwsys_stl::wstring ToWide(const char* str);
+
+ // Convert a wide string to a narrow string.
+ // On Windows, UTF-8 is assumed, and on other platforms,
+ // the current locale is assumed.
+ static kwsys_stl::string ToNarrow(const kwsys_stl::wstring& str);
+ static kwsys_stl::string ToNarrow(const wchar_t* str);
+
+#endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING
+
+}; // class Encoding
+} // namespace @KWSYS_NAMESPACE@
+
+/* Undefine temporary macros. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsys_stl
+#endif
+
+#endif
diff --git a/Source/kwsys/EncodingC.c b/Source/kwsys/EncodingC.c
new file mode 100644
index 0000000000..cda78e2896
--- /dev/null
+++ b/Source/kwsys/EncodingC.c
@@ -0,0 +1,79 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Encoding.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "Encoding.h.in"
+#endif
+
+#include <stdlib.h>
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+size_t kwsysEncoding_mbstowcs(wchar_t* dest, const char* str, size_t n)
+{
+ if(str == 0)
+ {
+ return (size_t)-1;
+ }
+#ifdef _WIN32
+ return MultiByteToWideChar(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0,
+ str, -1, dest, (int)n) - 1;
+#else
+ return mbstowcs(dest, str, n);
+#endif
+}
+
+wchar_t* kwsysEncoding_DupToWide(const char* str)
+{
+ wchar_t* ret = NULL;
+ size_t length = kwsysEncoding_mbstowcs(NULL, str, 0) + 1;
+ if(length > 0)
+ {
+ ret = malloc((length)*sizeof(wchar_t));
+ ret[0] = 0;
+ kwsysEncoding_mbstowcs(ret, str, length);
+ }
+ return ret;
+}
+
+size_t kwsysEncoding_wcstombs(char* dest, const wchar_t* str, size_t n)
+{
+ if(str == 0)
+ {
+ return (size_t)-1;
+ }
+#ifdef _WIN32
+ return WideCharToMultiByte(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, str, -1,
+ dest, (int)n, NULL, NULL) - 1;
+#else
+ return wcstombs(dest, str, n);
+#endif
+}
+
+char* kwsysEncoding_DupToNarrow(const wchar_t* str)
+{
+ char* ret = NULL;
+ size_t length = kwsysEncoding_wcstombs(0, str, 0) + 1;
+ if(length > 0)
+ {
+ ret = malloc(length);
+ ret[0] = 0;
+ kwsysEncoding_wcstombs(ret, str, length);
+ }
+ return ret;
+}
diff --git a/Source/kwsys/EncodingCXX.cxx b/Source/kwsys/EncodingCXX.cxx
new file mode 100644
index 0000000000..251a56ddc9
--- /dev/null
+++ b/Source/kwsys/EncodingCXX.cxx
@@ -0,0 +1,184 @@
+/*============================================================================
+ 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.
+============================================================================*/
+
+#ifdef __osf__
+# define _OSF_SOURCE
+# define _POSIX_C_SOURCE 199506L
+# define _XOPEN_SOURCE_EXTENDED
+#endif
+
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Encoding.hxx)
+#include KWSYS_HEADER(Encoding.h)
+#include KWSYS_HEADER(stl/vector)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "Encoding.hxx.in"
+# include "Encoding.h.in"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef _MSC_VER
+# pragma warning (disable: 4786)
+#endif
+
+// Windows API.
+#if defined(_WIN32)
+# include <windows.h>
+#endif
+
+namespace KWSYS_NAMESPACE
+{
+
+Encoding::CommandLineArguments
+Encoding::CommandLineArguments::Main(int argc, char const* const* argv)
+{
+#ifdef _WIN32
+ (void) argc;
+ (void) argv;
+
+ int ac;
+ LPWSTR* w_av = CommandLineToArgvW(GetCommandLineW(), &ac);
+
+ std::vector<std::string> av1(ac);
+ std::vector<char const*> av2(ac);
+ for(int i=0; i<ac; i++)
+ {
+ av1[i] = ToNarrow(w_av[i]);
+ av2[i] = av1[i].c_str();
+ }
+ LocalFree(w_av);
+ return CommandLineArguments(ac, &av2[0]);
+#else
+ return CommandLineArguments(argc, argv);
+#endif
+}
+
+Encoding::CommandLineArguments::CommandLineArguments(int ac,
+ char const* const* av)
+{
+ this->argv_.resize(ac+1);
+ for(int i=0; i<ac; i++)
+ {
+ this->argv_[i] = strdup(av[i]);
+ }
+ this->argv_[ac] = 0;
+}
+
+Encoding::CommandLineArguments::CommandLineArguments(int ac,
+ wchar_t const* const* av)
+{
+ this->argv_.resize(ac+1);
+ for(int i=0; i<ac; i++)
+ {
+ this->argv_[i] = kwsysEncoding_DupToNarrow(av[i]);
+ }
+ this->argv_[ac] = 0;
+}
+
+Encoding::CommandLineArguments::~CommandLineArguments()
+{
+ for(size_t i=0; i<this->argv_.size(); i++)
+ {
+ free(argv_[i]);
+ }
+}
+
+Encoding::CommandLineArguments::
+ CommandLineArguments(const CommandLineArguments& other)
+{
+ this->argv_.resize(other.argv_.size());
+ for(size_t i=0; i<this->argv_.size(); i++)
+ {
+ this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : 0;
+ }
+}
+
+Encoding::CommandLineArguments&
+Encoding::CommandLineArguments::operator=(const CommandLineArguments& other)
+{
+ if(this != &other)
+ {
+ size_t i;
+ for(i=0; i<this->argv_.size(); i++)
+ {
+ free(this->argv_[i]);
+ }
+
+ this->argv_.resize(other.argv_.size());
+ for(i=0; i<this->argv_.size(); i++)
+ {
+ this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : 0;
+ }
+ }
+
+ return *this;
+}
+
+int Encoding::CommandLineArguments::argc() const
+{
+ return static_cast<int>(this->argv_.size() - 1);
+}
+
+char const* const* Encoding::CommandLineArguments::argv() const
+{
+ return &this->argv_[0];
+}
+
+#if KWSYS_STL_HAS_WSTRING
+
+kwsys_stl::wstring Encoding::ToWide(const kwsys_stl::string& str)
+{
+ return ToWide(str.c_str());
+}
+
+kwsys_stl::string Encoding::ToNarrow(const kwsys_stl::wstring& str)
+{
+ return ToNarrow(str.c_str());
+}
+
+kwsys_stl::wstring Encoding::ToWide(const char* cstr)
+{
+ kwsys_stl::wstring wstr;
+ size_t length = kwsysEncoding_mbstowcs(0, cstr, 0) + 1;
+ if(length > 0)
+ {
+ kwsys_stl::vector<wchar_t> wchars(length);
+ if(kwsysEncoding_mbstowcs(&wchars[0], cstr, length) > 0)
+ {
+ wstr = &wchars[0];
+ }
+ }
+ return wstr;
+}
+
+kwsys_stl::string Encoding::ToNarrow(const wchar_t* wcstr)
+{
+ kwsys_stl::string str;
+ size_t length = kwsysEncoding_wcstombs(0, wcstr, 0) + 1;
+ if(length > 0)
+ {
+ std::vector<char> chars(length);
+ if(kwsysEncoding_wcstombs(&chars[0], wcstr, length) > 0)
+ {
+ str = &chars[0];
+ }
+ }
+ return str;
+}
+#endif // KWSYS_STL_HAS_WSTRING
+
+} // namespace KWSYS_NAMESPACE
diff --git a/Source/kwsys/ExtraTest.cmake.in b/Source/kwsys/ExtraTest.cmake.in
new file mode 100644
index 0000000000..e8c0a1cdb1
--- /dev/null
+++ b/Source/kwsys/ExtraTest.cmake.in
@@ -0,0 +1 @@
+MESSAGE("*** This message is generated by message inside a file that is included in DartTestfile.txt ***")
diff --git a/Source/kwsys/FStream.cxx b/Source/kwsys/FStream.cxx
new file mode 100644
index 0000000000..018652c84e
--- /dev/null
+++ b/Source/kwsys/FStream.cxx
@@ -0,0 +1,76 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(FStream.hxx)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "FStream.hxx.in"
+#endif
+
+namespace KWSYS_NAMESPACE
+{
+namespace FStream
+{
+
+BOM ReadBOM(std::istream& in)
+{
+ if(!in.good())
+ {
+ return BOM_None;
+ }
+ unsigned long orig = in.tellg();
+ unsigned char bom[4];
+ in.read(reinterpret_cast<char*>(bom), 2);
+ if(!in.good())
+ {
+ in.seekg(orig);
+ return BOM_None;
+ }
+ if(bom[0] == 0xEF && bom[1] == 0xBB)
+ {
+ in.read(reinterpret_cast<char*>(bom+2), 1);
+ if(in.good() && bom[2] == 0xBF)
+ {
+ return BOM_UTF8;
+ }
+ }
+ else if(bom[0] == 0xFE && bom[1] == 0xFF)
+ {
+ return BOM_UTF16BE;
+ }
+ else if(bom[0] == 0x00 && bom[1] == 0x00)
+ {
+ in.read(reinterpret_cast<char*>(bom+2), 2);
+ if(in.good() && bom[2] == 0xFE && bom[3] == 0xFF)
+ {
+ return BOM_UTF32BE;
+ }
+ }
+ else if(bom[0] == 0xFF && bom[1] == 0xFE)
+ {
+ unsigned long p = in.tellg();
+ in.read(reinterpret_cast<char*>(bom+2), 2);
+ if(in.good() && bom[2] == 0x00 && bom[3] == 0x00)
+ {
+ return BOM_UTF32LE;
+ }
+ in.seekg(p);
+ return BOM_UTF16LE;
+ }
+ in.seekg(orig);
+ return BOM_None;
+}
+
+} // FStream namespace
+} //KWSYS_NAMESPACE
diff --git a/Source/kwsys/FStream.hxx.in b/Source/kwsys/FStream.hxx.in
new file mode 100644
index 0000000000..45425ffd6d
--- /dev/null
+++ b/Source/kwsys/FStream.hxx.in
@@ -0,0 +1,188 @@
+/*============================================================================
+ 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@_FStream_hxx
+#define @KWSYS_NAMESPACE@_FStream_hxx
+
+#include <@KWSYS_NAMESPACE@/ios/fstream>
+#include <@KWSYS_NAMESPACE@/Encoding.hxx>
+
+namespace @KWSYS_NAMESPACE@
+{
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+ template<typename CharType,typename Traits>
+ class basic_filebuf : public std::basic_filebuf<CharType,Traits>
+ {
+ public:
+ typedef std::basic_filebuf<CharType,Traits> my_base_type;
+ basic_filebuf *open(char const *s,std::ios_base::openmode mode)
+ {
+ return static_cast<basic_filebuf*>(
+ my_base_type::open(Encoding::ToWide(s).c_str(), mode)
+ );
+ }
+ };
+
+ template<typename CharType,typename Traits = std::char_traits<CharType> >
+ class basic_ifstream : public std::basic_istream<CharType,Traits>
+ {
+ public:
+ typedef basic_filebuf<CharType,Traits> internal_buffer_type;
+ typedef std::basic_istream<CharType,Traits> internal_stream_type;
+
+ basic_ifstream() : internal_stream_type(new internal_buffer_type())
+ {
+ buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
+ }
+ explicit basic_ifstream(char const *file_name,
+ std::ios_base::openmode mode = std::ios_base::in)
+ : internal_stream_type(new internal_buffer_type())
+ {
+ buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
+ open(file_name,mode);
+ }
+ void open(char const *file_name,std::ios_base::openmode mode = std::ios_base::in)
+ {
+ if(!buf_->open(file_name,mode | std::ios_base::in))
+ {
+ this->setstate(std::ios_base::failbit);
+ }
+ else
+ {
+ this->clear();
+ }
+ }
+ bool is_open()
+ {
+ return buf_->is_open();
+ }
+ bool is_open() const
+ {
+ return buf_->is_open();
+ }
+ void close()
+ {
+ if(!buf_->close())
+ {
+ this->setstate(std::ios_base::failbit);
+ }
+ else
+ {
+ this->clear();
+ }
+ }
+
+ internal_buffer_type *rdbuf() const
+ {
+ return buf_;
+ }
+
+ ~basic_ifstream()
+ {
+ buf_->close();
+ delete buf_;
+ }
+
+ private:
+ internal_buffer_type* buf_;
+};
+
+template<typename CharType,typename Traits = std::char_traits<CharType> >
+class basic_ofstream : public std::basic_ostream<CharType,Traits>
+{
+ public:
+ typedef basic_filebuf<CharType,Traits> internal_buffer_type;
+ typedef std::basic_ostream<CharType,Traits> internal_stream_type;
+
+ basic_ofstream() : internal_stream_type(new internal_buffer_type())
+ {
+ buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
+ }
+ explicit basic_ofstream(char const *file_name,std::ios_base::openmode mode = std::ios_base::out) :
+ internal_stream_type(new internal_buffer_type())
+ {
+ buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
+ open(file_name,mode);
+ }
+ void open(char const *file_name,std::ios_base::openmode mode = std::ios_base::out)
+ {
+ if(!buf_->open(file_name,mode | std::ios_base::out))
+ {
+ this->setstate(std::ios_base::failbit);
+ }
+ else
+ {
+ this->clear();
+ }
+ }
+ bool is_open()
+ {
+ return buf_->is_open();
+ }
+ bool is_open() const
+ {
+ return buf_->is_open();
+ }
+ void close()
+ {
+ if(!buf_->close())
+ {
+ this->setstate(std::ios_base::failbit);
+ }
+ else
+ {
+ this->clear();
+ }
+ }
+
+ internal_buffer_type *rdbuf() const
+ {
+ return buf_.get();
+ }
+ ~basic_ofstream()
+ {
+ buf_->close();
+ delete buf_;
+ }
+
+ private:
+ internal_buffer_type* buf_;
+};
+
+ typedef basic_ifstream<char> ifstream;
+ typedef basic_ofstream<char> ofstream;
+
+#else
+ using @KWSYS_NAMESPACE@_ios_namespace::ofstream;
+ using @KWSYS_NAMESPACE@_ios_namespace::ifstream;
+#endif
+
+ namespace FStream
+ {
+ enum BOM
+ {
+ BOM_None,
+ BOM_UTF8,
+ BOM_UTF16BE,
+ BOM_UTF16LE,
+ BOM_UTF32BE,
+ BOM_UTF32LE
+ };
+
+ // Read a BOM, if one exists.
+ // If a BOM exists, the stream is advanced to after the BOM.
+ // This function requires a seekable stream (but not a relative
+ // seekable stream).
+ BOM ReadBOM(std::istream& in);
+ }
+}
+
+#endif
diff --git a/Source/kwsys/FundamentalType.h.in b/Source/kwsys/FundamentalType.h.in
new file mode 100644
index 0000000000..ff200633af
--- /dev/null
+++ b/Source/kwsys/FundamentalType.h.in
@@ -0,0 +1,146 @@
+/*============================================================================
+ 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@_FundamentalType_h
+#define @KWSYS_NAMESPACE@_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@_EXPORT
+#endif
+
+#if !@KWSYS_NAMESPACE@_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. */
+@KWSYS_C_CODE_SIZEOF_CHAR@
+@KWSYS_C_CODE_SIZEOF_SHORT@
+@KWSYS_C_CODE_SIZEOF_INT@
+@KWSYS_C_CODE_SIZEOF_LONG@
+@KWSYS_C_CODE_SIZEOF_LONG_LONG@
+@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@_USE_LONG_LONG @KWSYS_USE_LONG_LONG@
+#define @KWSYS_NAMESPACE@_USE___INT64 @KWSYS_USE___INT64@
+
+/* Whether type "char" is signed (it may be signed or unsigned). */
+#define @KWSYS_NAMESPACE@_CHAR_IS_SIGNED @KWSYS_CHAR_IS_SIGNED@
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/* Select an 8-bit integer type. */
+#if @KWSYS_NAMESPACE@_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@_SIZEOF_SHORT == 2
+typedef short kwsysFundamentalType_Int16;
+typedef unsigned short kwsysFundamentalType_UInt16;
+#elif @KWSYS_NAMESPACE@_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@_SIZEOF_INT == 4
+typedef int kwsysFundamentalType_Int32;
+typedef unsigned int kwsysFundamentalType_UInt32;
+#elif @KWSYS_NAMESPACE@_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@_SIZEOF_LONG == 8
+typedef signed long kwsysFundamentalType_Int64;
+typedef unsigned long kwsysFundamentalType_UInt64;
+/* Whether UInt64 can be converted to double. */
+# define @KWSYS_NAMESPACE@_CAN_CONVERT_UI64_TO_DOUBLE 1
+#elif @KWSYS_NAMESPACE@_USE_LONG_LONG && @KWSYS_NAMESPACE@_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@_CAN_CONVERT_UI64_TO_DOUBLE 1
+#elif @KWSYS_NAMESPACE@_USE___INT64 && @KWSYS_NAMESPACE@_SIZEOF___INT64 == 8
+typedef signed __int64 kwsysFundamentalType_Int64;
+typedef unsigned __int64 kwsysFundamentalType_UInt64;
+/* Whether UInt64 can be converted to double. */
+# define @KWSYS_NAMESPACE@_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@_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@_SIZEOF_CHAR
+# define KWSYS_SIZEOF_SHORT @KWSYS_NAMESPACE@_SIZEOF_SHORT
+# define KWSYS_SIZEOF_INT @KWSYS_NAMESPACE@_SIZEOF_INT
+# define KWSYS_SIZEOF_LONG @KWSYS_NAMESPACE@_SIZEOF_LONG
+# define KWSYS_SIZEOF_LONG_LONG @KWSYS_NAMESPACE@_SIZEOF_LONG_LONG
+# define KWSYS_SIZEOF___INT64 @KWSYS_NAMESPACE@_SIZEOF___INT64
+# define KWSYS_USE_LONG_LONG @KWSYS_NAMESPACE@_USE_LONG_LONG
+# define KWSYS_USE___INT64 @KWSYS_NAMESPACE@_USE___INT64
+# define KWSYS_CHAR_IS_SIGNED @KWSYS_NAMESPACE@_CHAR_IS_SIGNED
+# define KWSYS_CAN_CONVERT_UI64_TO_DOUBLE @KWSYS_NAMESPACE@_CAN_CONVERT_UI64_TO_DOUBLE
+#endif
+
+#endif
diff --git a/Source/kwsys/Glob.cxx b/Source/kwsys/Glob.cxx
new file mode 100644
index 0000000000..0916d2e6f2
--- /dev/null
+++ b/Source/kwsys/Glob.cxx
@@ -0,0 +1,513 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Glob.hxx)
+
+#include KWSYS_HEADER(Configure.hxx)
+
+#include KWSYS_HEADER(RegularExpression.hxx)
+#include KWSYS_HEADER(SystemTools.hxx)
+#include KWSYS_HEADER(Directory.hxx)
+#include KWSYS_HEADER(stl/string)
+#include KWSYS_HEADER(stl/vector)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "Glob.hxx.in"
+# include "Directory.hxx.in"
+# include "Configure.hxx.in"
+# include "RegularExpression.hxx.in"
+# include "SystemTools.hxx.in"
+# include "kwsys_stl.hxx.in"
+# include "kwsys_stl_string.hxx.in"
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+namespace KWSYS_NAMESPACE
+{
+#if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
+// On Windows and apple, no difference between lower and upper case
+# define KWSYS_GLOB_CASE_INDEPENDENT
+#endif
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+// Handle network paths
+# define KWSYS_GLOB_SUPPORT_NETWORK_PATHS
+#endif
+
+//----------------------------------------------------------------------------
+class GlobInternals
+{
+public:
+ kwsys_stl::vector<kwsys_stl::string> Files;
+ kwsys_stl::vector<kwsys::RegularExpression> Expressions;
+};
+
+//----------------------------------------------------------------------------
+Glob::Glob()
+{
+ this->Internals = new GlobInternals;
+ this->Recurse = false;
+ this->Relative = "";
+
+ this->RecurseThroughSymlinks = true;
+ // RecurseThroughSymlinks is true by default for backwards compatibility,
+ // not because it's a good idea...
+ this->FollowedSymlinkCount = 0;
+}
+
+//----------------------------------------------------------------------------
+Glob::~Glob()
+{
+ delete this->Internals;
+}
+
+//----------------------------------------------------------------------------
+kwsys_stl::vector<kwsys_stl::string>& Glob::GetFiles()
+{
+ return this->Internals->Files;
+}
+
+//----------------------------------------------------------------------------
+kwsys_stl::string Glob::PatternToRegex(const kwsys_stl::string& pattern,
+ bool require_whole_string,
+ bool preserve_case)
+{
+ // Incrementally build the regular expression from the pattern.
+ kwsys_stl::string regex = require_whole_string? "^" : "";
+ kwsys_stl::string::const_iterator pattern_first = pattern.begin();
+ kwsys_stl::string::const_iterator pattern_last = pattern.end();
+ for(kwsys_stl::string::const_iterator i = pattern_first;
+ i != pattern_last; ++i)
+ {
+ int c = *i;
+ if(c == '*')
+ {
+ // A '*' (not between brackets) matches any string.
+ // We modify this to not match slashes since the orignal glob
+ // pattern documentation was meant for matching file name
+ // components separated by slashes.
+ regex += "[^/]*";
+ }
+ else if(c == '?')
+ {
+ // A '?' (not between brackets) matches any single character.
+ // We modify this to not match slashes since the orignal glob
+ // pattern documentation was meant for matching file name
+ // components separated by slashes.
+ regex += "[^/]";
+ }
+ else if(c == '[')
+ {
+ // Parse out the bracket expression. It begins just after the
+ // opening character.
+ kwsys_stl::string::const_iterator bracket_first = i+1;
+ kwsys_stl::string::const_iterator bracket_last = bracket_first;
+
+ // The first character may be complementation '!' or '^'.
+ if(bracket_last != pattern_last &&
+ (*bracket_last == '!' || *bracket_last == '^'))
+ {
+ ++bracket_last;
+ }
+
+ // If the next character is a ']' it is included in the brackets
+ // because the bracket string may not be empty.
+ if(bracket_last != pattern_last && *bracket_last == ']')
+ {
+ ++bracket_last;
+ }
+
+ // Search for the closing ']'.
+ while(bracket_last != pattern_last && *bracket_last != ']')
+ {
+ ++bracket_last;
+ }
+
+ // Check whether we have a complete bracket string.
+ if(bracket_last == pattern_last)
+ {
+ // The bracket string did not end, so it was opened simply by
+ // a '[' that is supposed to be matched literally.
+ regex += "\\[";
+ }
+ else
+ {
+ // Convert the bracket string to its regex equivalent.
+ kwsys_stl::string::const_iterator k = bracket_first;
+
+ // Open the regex block.
+ regex += "[";
+
+ // A regex range complement uses '^' instead of '!'.
+ if(k != bracket_last && *k == '!')
+ {
+ regex += "^";
+ ++k;
+ }
+
+ // Convert the remaining characters.
+ for(; k != bracket_last; ++k)
+ {
+ // Backslashes must be escaped.
+ if(*k == '\\')
+ {
+ regex += "\\";
+ }
+
+ // Store this character.
+ regex += *k;
+ }
+
+ // Close the regex block.
+ regex += "]";
+
+ // Jump to the end of the bracket string.
+ i = bracket_last;
+ }
+ }
+ else
+ {
+ // A single character matches itself.
+ int ch = c;
+ if(!(('a' <= ch && ch <= 'z') ||
+ ('A' <= ch && ch <= 'Z') ||
+ ('0' <= ch && ch <= '9')))
+ {
+ // Escape the non-alphanumeric character.
+ regex += "\\";
+ }
+#if defined(KWSYS_GLOB_CASE_INDEPENDENT)
+ else
+ {
+ // On case-insensitive systems file names are converted to lower
+ // case before matching.
+ if(!preserve_case)
+ {
+ ch = tolower(ch);
+ }
+ }
+#endif
+ (void)preserve_case;
+ // Store the character.
+ regex.append(1, static_cast<char>(ch));
+ }
+ }
+
+ if(require_whole_string)
+ {
+ regex += "$";
+ }
+ return regex;
+}
+
+//----------------------------------------------------------------------------
+void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
+ const kwsys_stl::string& dir)
+{
+ kwsys::Directory d;
+ if ( !d.Load(dir) )
+ {
+ return;
+ }
+ unsigned long cc;
+ kwsys_stl::string fullname;
+ kwsys_stl::string realname;
+ kwsys_stl::string fname;
+ for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
+ {
+ fname = d.GetFile(cc);
+ if ( fname == "." || fname == ".." )
+ {
+ continue;
+ }
+
+ if ( start == 0 )
+ {
+ realname = dir + fname;
+ }
+ else
+ {
+ realname = dir + "/" + fname;
+ }
+
+#if defined( KWSYS_GLOB_CASE_INDEPENDENT )
+ // On Windows and apple, no difference between lower and upper case
+ fname = kwsys::SystemTools::LowerCase(fname);
+#endif
+
+ if ( start == 0 )
+ {
+ fullname = dir + fname;
+ }
+ else
+ {
+ fullname = dir + "/" + fname;
+ }
+
+ bool isDir = kwsys::SystemTools::FileIsDirectory(realname);
+ bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname);
+
+ if ( isDir && (!isSymLink || this->RecurseThroughSymlinks) )
+ {
+ if (isSymLink)
+ {
+ ++this->FollowedSymlinkCount;
+ }
+ this->RecurseDirectory(start+1, realname);
+ }
+ else
+ {
+ if ( !this->Internals->Expressions.empty() &&
+ this->Internals->Expressions.rbegin()->find(fname) )
+ {
+ this->AddFile(this->Internals->Files, realname);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
+ const kwsys_stl::string& dir)
+{
+ //kwsys_ios::cout << "ProcessDirectory: " << dir << kwsys_ios::endl;
+ bool last = ( start == this->Internals->Expressions.size()-1 );
+ if ( last && this->Recurse )
+ {
+ this->RecurseDirectory(start, dir);
+ return;
+ }
+
+ if ( start >= this->Internals->Expressions.size() )
+ {
+ return;
+ }
+
+ kwsys::Directory d;
+ if ( !d.Load(dir) )
+ {
+ return;
+ }
+ unsigned long cc;
+ kwsys_stl::string fullname;
+ kwsys_stl::string realname;
+ kwsys_stl::string fname;
+ for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
+ {
+ fname = d.GetFile(cc);
+ if ( fname == "." || fname == ".." )
+ {
+ continue;
+ }
+
+ if ( start == 0 )
+ {
+ realname = dir + fname;
+ }
+ else
+ {
+ realname = dir + "/" + fname;
+ }
+
+#if defined(KWSYS_GLOB_CASE_INDEPENDENT)
+ // On case-insensitive file systems convert to lower case for matching.
+ fname = kwsys::SystemTools::LowerCase(fname);
+#endif
+
+ if ( start == 0 )
+ {
+ fullname = dir + fname;
+ }
+ else
+ {
+ fullname = dir + "/" + fname;
+ }
+
+ //kwsys_ios::cout << "Look at file: " << fname << kwsys_ios::endl;
+ //kwsys_ios::cout << "Match: "
+ // << this->Internals->TextExpressions[start].c_str() << kwsys_ios::endl;
+ //kwsys_ios::cout << "Full name: " << fullname << kwsys_ios::endl;
+
+ if ( !last &&
+ !kwsys::SystemTools::FileIsDirectory(realname) )
+ {
+ continue;
+ }
+
+ if ( this->Internals->Expressions[start].find(fname) )
+ {
+ if ( last )
+ {
+ this->AddFile(this->Internals->Files, realname);
+ }
+ else
+ {
+ this->ProcessDirectory(start+1, realname + "/");
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+bool Glob::FindFiles(const kwsys_stl::string& inexpr)
+{
+ kwsys_stl::string cexpr;
+ kwsys_stl::string::size_type cc;
+ kwsys_stl::string expr = inexpr;
+
+ this->Internals->Expressions.clear();
+ this->Internals->Files.clear();
+
+ if ( !kwsys::SystemTools::FileIsFullPath(expr) )
+ {
+ expr = kwsys::SystemTools::GetCurrentWorkingDirectory();
+ expr += "/" + inexpr;
+ }
+ kwsys_stl::string fexpr = expr;
+
+ kwsys_stl::string::size_type skip = 0;
+ kwsys_stl::string::size_type last_slash = 0;
+ for ( cc = 0; cc < expr.size(); cc ++ )
+ {
+ if ( cc > 0 && expr[cc] == '/' && expr[cc-1] != '\\' )
+ {
+ last_slash = cc;
+ }
+ if ( cc > 0 &&
+ (expr[cc] == '[' || expr[cc] == '?' || expr[cc] == '*') &&
+ expr[cc-1] != '\\' )
+ {
+ break;
+ }
+ }
+ if ( last_slash > 0 )
+ {
+ //kwsys_ios::cout << "I can skip: " << fexpr.substr(0, last_slash)
+ // << kwsys_ios::endl;
+ skip = last_slash;
+ }
+ if ( skip == 0 )
+ {
+#if defined( KWSYS_GLOB_SUPPORT_NETWORK_PATHS )
+ // Handle network paths
+ if ( expr[0] == '/' && expr[1] == '/' )
+ {
+ int cnt = 0;
+ for ( cc = 2; cc < expr.size(); cc ++ )
+ {
+ if ( expr[cc] == '/' )
+ {
+ cnt ++;
+ if ( cnt == 2 )
+ {
+ break;
+ }
+ }
+ }
+ skip = int(cc + 1);
+ }
+ else
+#endif
+ // Handle drive letters on Windows
+ if ( expr[1] == ':' && expr[0] != '/' )
+ {
+ skip = 2;
+ }
+ }
+
+ if ( skip > 0 )
+ {
+ expr = expr.substr(skip);
+ }
+
+ cexpr = "";
+ for ( cc = 0; cc < expr.size(); cc ++ )
+ {
+ int ch = expr[cc];
+ if ( ch == '/' )
+ {
+ if ( !cexpr.empty() )
+ {
+ this->AddExpression(cexpr);
+ }
+ cexpr = "";
+ }
+ else
+ {
+ cexpr.append(1, static_cast<char>(ch));
+ }
+ }
+ if ( !cexpr.empty() )
+ {
+ this->AddExpression(cexpr);
+ }
+
+ // Handle network paths
+ if ( skip > 0 )
+ {
+ this->ProcessDirectory(0, fexpr.substr(0, skip) + "/");
+ }
+ else
+ {
+ this->ProcessDirectory(0, "/");
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+void Glob::AddExpression(const kwsys_stl::string& expr)
+{
+ this->Internals->Expressions.push_back(
+ kwsys::RegularExpression(
+ this->PatternToRegex(expr)));
+}
+
+//----------------------------------------------------------------------------
+void Glob::SetRelative(const char* dir)
+{
+ if ( !dir )
+ {
+ this->Relative = "";
+ return;
+ }
+ this->Relative = dir;
+}
+
+//----------------------------------------------------------------------------
+const char* Glob::GetRelative()
+{
+ if ( this->Relative.empty() )
+ {
+ return 0;
+ }
+ return this->Relative.c_str();
+}
+
+//----------------------------------------------------------------------------
+void Glob::AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const kwsys_stl::string& file)
+{
+ if ( !this->Relative.empty() )
+ {
+ files.push_back(kwsys::SystemTools::RelativePath(this->Relative.c_str(), file.c_str()));
+ }
+ else
+ {
+ files.push_back(file);
+ }
+}
+
+} // namespace KWSYS_NAMESPACE
+
diff --git a/Source/kwsys/Glob.hxx.in b/Source/kwsys/Glob.hxx.in
new file mode 100644
index 0000000000..d8b8491dc4
--- /dev/null
+++ b/Source/kwsys/Glob.hxx.in
@@ -0,0 +1,117 @@
+/*============================================================================
+ 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@_Glob_hxx
+#define @KWSYS_NAMESPACE@_Glob_hxx
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+#include <@KWSYS_NAMESPACE@/stl/string>
+#include <@KWSYS_NAMESPACE@/stl/vector>
+
+/* Define this macro temporarily to keep the code readable. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys_stl @KWSYS_NAMESPACE@_stl
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+
+class GlobInternals;
+
+/** \class Glob
+ * \brief Portable globbing searches.
+ *
+ * Globbing expressions are much simpler than regular
+ * expressions. This class will search for files using
+ * globbing expressions.
+ *
+ * Finds all files that match a given globbing expression.
+ */
+class @KWSYS_NAMESPACE@_EXPORT Glob
+{
+public:
+ Glob();
+ ~Glob();
+
+ //! Find all files that match the pattern.
+ bool FindFiles(const kwsys_stl::string& inexpr);
+
+ //! Return the list of files that matched.
+ kwsys_stl::vector<kwsys_stl::string>& GetFiles();
+
+ //! Set recurse to true to match subdirectories.
+ void RecurseOn() { this->SetRecurse(true); }
+ void RecurseOff() { this->SetRecurse(false); }
+ void SetRecurse(bool i) { this->Recurse = i; }
+ bool GetRecurse() { return this->Recurse; }
+
+ //! Set recurse through symlinks to true if recursion should traverse the
+ // linked-to directories
+ void RecurseThroughSymlinksOn() { this->SetRecurseThroughSymlinks(true); }
+ void RecurseThroughSymlinksOff() { this->SetRecurseThroughSymlinks(false); }
+ void SetRecurseThroughSymlinks(bool i) { this->RecurseThroughSymlinks = i; }
+ bool GetRecurseThroughSymlinks() { return this->RecurseThroughSymlinks; }
+
+ //! Get the number of symlinks followed through recursion
+ unsigned int GetFollowedSymlinkCount() { return this->FollowedSymlinkCount; }
+
+ //! Set relative to true to only show relative path to files.
+ void SetRelative(const char* dir);
+ const char* GetRelative();
+
+ /** Convert the given globbing pattern to a regular expression.
+ There is no way to quote meta-characters. The
+ require_whole_string argument specifies whether the regex is
+ automatically surrounded by "^" and "$" to match the whole
+ string. This is on by default because patterns always match
+ whole strings, but may be disabled to support concatenating
+ expressions more easily (regex1|regex2|etc). */
+ static kwsys_stl::string PatternToRegex(const kwsys_stl::string& pattern,
+ bool require_whole_string = true,
+ bool preserve_case = false);
+
+protected:
+ //! Process directory
+ void ProcessDirectory(kwsys_stl::string::size_type start,
+ const kwsys_stl::string& dir);
+
+ //! Process last directory, but only when recurse flags is on. That is
+ // effectively like saying: /path/to/file/**/file
+ void RecurseDirectory(kwsys_stl::string::size_type start,
+ const kwsys_stl::string& dir);
+
+ //! Add regular expression
+ void AddExpression(const kwsys_stl::string& expr);
+
+ //! Add a file to the list
+ void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const kwsys_stl::string& file);
+
+ GlobInternals* Internals;
+ bool Recurse;
+ kwsys_stl::string Relative;
+ bool RecurseThroughSymlinks;
+ unsigned int FollowedSymlinkCount;
+
+private:
+ Glob(const Glob&); // Not implemented.
+ void operator=(const Glob&); // Not implemented.
+};
+
+} // namespace @KWSYS_NAMESPACE@
+
+/* Undefine temporary macro. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsys_stl
+#endif
+
+#endif
diff --git a/Source/kwsys/IOStream.cxx b/Source/kwsys/IOStream.cxx
new file mode 100644
index 0000000000..a31f8c846a
--- /dev/null
+++ b/Source/kwsys/IOStream.cxx
@@ -0,0 +1,282 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Configure.hxx)
+
+// Configure the implementation for the current streams library.
+#if !KWSYS_IOS_USE_ANSI
+# define ios_base ios
+# if defined(__HP_aCC)
+# define protected public
+# include <iostream.h> // Hack access to some private stream methods.
+# undef protected
+# endif
+#endif
+
+// Include the streams library.
+#include KWSYS_HEADER(ios/iostream)
+#include KWSYS_HEADER(IOStream.hxx)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "Configure.hxx.in"
+# include "kwsys_ios_iostream.hxx.in"
+# include "IOStream.hxx.in"
+#endif
+
+// Implement the rest of this file only if it is needed.
+#if KWSYS_IOS_NEED_OPERATORS_LL
+
+# include <stdio.h> // sscanf, sprintf
+# include <string.h> // memchr
+
+# if defined(_MAX_INT_DIG)
+# define KWSYS_IOS_INT64_MAX_DIG _MAX_INT_DIG
+# else
+# define KWSYS_IOS_INT64_MAX_DIG 32
+# endif
+
+namespace KWSYS_NAMESPACE
+{
+
+// Scan an input stream for an integer value.
+static int IOStreamScanStream(kwsys_ios::istream& is, char* buffer)
+{
+ // Prepare to write to buffer.
+ char* out = buffer;
+ char* end = buffer + KWSYS_IOS_INT64_MAX_DIG - 1;
+
+ // Look for leading sign.
+ if(is.peek() == '+') { *out++ = '+'; is.ignore(); }
+ else if(is.peek() == '-') { *out++ = '-'; is.ignore(); }
+
+ // Determine the base. If not specified in the stream, try to
+ // detect it from the input. A leading 0x means hex, and a leading
+ // 0 alone means octal.
+ int base = 0;
+ int flags = is.flags() & kwsys_ios::ios_base::basefield;
+ if(flags == kwsys_ios::ios_base::oct) { base = 8; }
+ else if(flags == kwsys_ios::ios_base::dec) { base = 10; }
+ else if(flags == kwsys_ios::ios_base::hex) { base = 16; }
+ bool foundDigit = false;
+ bool foundNonZero = false;
+ if(is.peek() == '0')
+ {
+ foundDigit = true;
+ is.ignore();
+ if((is.peek() == 'x' || is.peek() == 'X') && (base == 0 || base == 16))
+ {
+ base = 16;
+ foundDigit = false;
+ is.ignore();
+ }
+ else if (base == 0)
+ {
+ base = 8;
+ }
+ }
+
+ // Determine the range of digits allowed for this number.
+ const char* digits = "0123456789abcdefABCDEF";
+ int maxDigitIndex = 10;
+ if(base == 8)
+ {
+ maxDigitIndex = 8;
+ }
+ else if(base == 16)
+ {
+ maxDigitIndex = 10+6+6;
+ }
+
+ // Scan until an invalid digit is found.
+ for(;is.peek() != EOF; is.ignore())
+ {
+ if(memchr(digits, *out = (char)is.peek(), maxDigitIndex) != 0)
+ {
+ if((foundNonZero || *out != '0') && out < end)
+ {
+ ++out;
+ foundNonZero = true;
+ }
+ foundDigit = true;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ // Correct the buffer contents for degenerate cases.
+ if(foundDigit && !foundNonZero)
+ {
+ *out++ = '0';
+ }
+ else if (!foundDigit)
+ {
+ out = buffer;
+ }
+
+ // Terminate the string in the buffer.
+ *out = '\0';
+
+ return base;
+}
+
+// Read an integer value from an input stream.
+template <class T>
+kwsys_ios::istream&
+IOStreamScanTemplate(kwsys_ios::istream& is, T& value, char type)
+{
+ int state = kwsys_ios::ios_base::goodbit;
+
+ // Skip leading whitespace.
+# if KWSYS_IOS_USE_ANSI
+ kwsys_ios::istream::sentry okay(is);
+# else
+ is.eatwhite();
+ kwsys_ios::istream& okay = is;
+# endif
+
+ if(okay)
+ {
+# if KWSYS_IOS_USE_ANSI
+ try {
+# endif
+ // Copy the string to a buffer and construct the format string.
+ char buffer[KWSYS_IOS_INT64_MAX_DIG];
+# if defined(_MSC_VER)
+ char format[] = "%I64_";
+ const int typeIndex = 4;
+# else
+ char format[] = "%ll_";
+ const int typeIndex = 3;
+# endif
+ switch(IOStreamScanStream(is, buffer))
+ {
+ case 8: format[typeIndex] = 'o'; break;
+ case 0: // Default to decimal if not told otherwise.
+ case 10: format[typeIndex] = type; break;
+ case 16: format[typeIndex] = 'x'; break;
+ };
+
+ // Use sscanf to parse the number from the buffer.
+ T result;
+ int success = (sscanf(buffer, format, &result) == 1)?1:0;
+
+ // Set flags for resulting state.
+ if(is.peek() == EOF) { state |= kwsys_ios::ios_base::eofbit; }
+ if(!success) { state |= kwsys_ios::ios_base::failbit; }
+ else { value = result; }
+# if KWSYS_IOS_USE_ANSI
+ } catch(...) { state |= kwsys_ios::ios_base::badbit; }
+# endif
+ }
+
+# if KWSYS_IOS_USE_ANSI
+ is.setstate(kwsys_ios::ios_base::iostate(state));
+# else
+ is.clear(state);
+# endif
+ return is;
+}
+
+// Print an integer value to an output stream.
+template <class T>
+kwsys_ios::ostream&
+IOStreamPrintTemplate(kwsys_ios::ostream& os, T value, char type)
+{
+# if KWSYS_IOS_USE_ANSI
+ kwsys_ios::ostream::sentry okay(os);
+# else
+ kwsys_ios::ostream& okay = os;
+# endif
+ if(okay)
+ {
+# if KWSYS_IOS_USE_ANSI
+ try {
+# endif
+ // Construct the format string.
+ char format[8];
+ char* f = format;
+ *f++ = '%';
+ if(os.flags() & kwsys_ios::ios_base::showpos) { *f++ = '+'; }
+ if(os.flags() & kwsys_ios::ios_base::showbase) { *f++ = '#'; }
+# if defined(_MSC_VER)
+ *f++ = 'I'; *f++ = '6'; *f++ = '4';
+# else
+ *f++ = 'l'; *f++ = 'l';
+# endif
+ long bflags = os.flags() & kwsys_ios::ios_base::basefield;
+ if(bflags == kwsys_ios::ios_base::oct) { *f++ = 'o'; }
+ else if(bflags != kwsys_ios::ios_base::hex) { *f++ = type; }
+ else if(os.flags() & kwsys_ios::ios_base::uppercase) { *f++ = 'X'; }
+ else { *f++ = 'x'; }
+ *f = '\0';
+
+ // Use sprintf to print to a buffer and then write the
+ // buffer to the stream.
+ char buffer[2*KWSYS_IOS_INT64_MAX_DIG];
+ sprintf(buffer, format, value);
+ os << buffer;
+# if KWSYS_IOS_USE_ANSI
+ } catch(...) { os.clear(os.rdstate() | kwsys_ios::ios_base::badbit); }
+# endif
+ }
+ return os;
+}
+
+# if !KWSYS_IOS_HAS_ISTREAM_LONG_LONG
+// Implement input stream operator for IOStreamSLL.
+kwsys_ios::istream& IOStreamScan(kwsys_ios::istream& is, IOStreamSLL& value)
+{
+ return IOStreamScanTemplate(is, value, 'd');
+}
+
+// Implement input stream operator for IOStreamULL.
+kwsys_ios::istream& IOStreamScan(kwsys_ios::istream& is, IOStreamULL& value)
+{
+ return IOStreamScanTemplate(is, value, 'u');
+}
+# endif
+
+# if !KWSYS_IOS_HAS_OSTREAM_LONG_LONG
+// Implement output stream operator for IOStreamSLL.
+kwsys_ios::ostream& IOStreamPrint(kwsys_ios::ostream& os, IOStreamSLL value)
+{
+ return IOStreamPrintTemplate(os, value, 'd');
+}
+
+// Implement output stream operator for IOStreamULL.
+kwsys_ios::ostream& IOStreamPrint(kwsys_ios::ostream& os, IOStreamULL value)
+{
+ return IOStreamPrintTemplate(os, value, 'u');
+}
+# endif
+
+} // namespace KWSYS_NAMESPACE
+
+#else
+
+namespace KWSYS_NAMESPACE
+{
+
+// Create one public symbol in this object file to avoid warnings from
+// archivers.
+void IOStreamSymbolToAvoidWarning();
+void IOStreamSymbolToAvoidWarning()
+{
+}
+
+} // namespace KWSYS_NAMESPACE
+
+#endif // KWSYS_IOS_NEED_OPERATORS_LL
diff --git a/Source/kwsys/IOStream.hxx.in b/Source/kwsys/IOStream.hxx.in
new file mode 100644
index 0000000000..2eeedf2ffe
--- /dev/null
+++ b/Source/kwsys/IOStream.hxx.in
@@ -0,0 +1,142 @@
+/*============================================================================
+ 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@_IOStream_hxx
+#define @KWSYS_NAMESPACE@_IOStream_hxx
+
+#include <@KWSYS_NAMESPACE@/ios/iosfwd>
+
+/* Define these macros temporarily to keep the code readable. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
+# define kwsys_ios @KWSYS_NAMESPACE@_ios
+#endif
+
+/* Whether istream supports long long. */
+#define @KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG @KWSYS_IOS_HAS_ISTREAM_LONG_LONG@
+
+/* Whether ostream supports long long. */
+#define @KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG @KWSYS_IOS_HAS_OSTREAM_LONG_LONG@
+
+/* Determine whether we need to define the streaming operators for
+ long long or __int64. */
+#if @KWSYS_USE_LONG_LONG@
+# if !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG || \
+ !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG
+# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 1
+ namespace @KWSYS_NAMESPACE@
+ {
+ typedef long long IOStreamSLL;
+ typedef unsigned long long IOStreamULL;
+ }
+# endif
+#elif defined(_MSC_VER) && _MSC_VER < 1300
+# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 1
+ namespace @KWSYS_NAMESPACE@
+ {
+ typedef __int64 IOStreamSLL;
+ typedef unsigned __int64 IOStreamULL;
+ }
+#endif
+#if !defined(@KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL)
+# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 0
+#endif
+
+#if @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL
+# if !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG
+
+/* Input stream operator implementation functions. */
+namespace @KWSYS_NAMESPACE@
+{
+kwsysEXPORT kwsys_ios::istream& IOStreamScan(kwsys_ios::istream&,
+ IOStreamSLL&);
+kwsysEXPORT kwsys_ios::istream& IOStreamScan(kwsys_ios::istream&,
+ IOStreamULL&);
+}
+
+/* Provide input stream operator for long long. */
+# if !defined(@KWSYS_NAMESPACE@_IOS_NO_ISTREAM_LONG_LONG) && \
+ !defined(KWSYS_IOS_ISTREAM_LONG_LONG_DEFINED)
+# define KWSYS_IOS_ISTREAM_LONG_LONG_DEFINED
+# define @KWSYS_NAMESPACE@_IOS_ISTREAM_LONG_LONG_DEFINED
+inline kwsys_ios::istream&
+operator>>(kwsys_ios::istream& is, @KWSYS_NAMESPACE@::IOStreamSLL& value)
+{
+ return @KWSYS_NAMESPACE@::IOStreamScan(is, value);
+}
+# endif
+
+/* Provide input stream operator for unsigned long long. */
+# if !defined(@KWSYS_NAMESPACE@_IOS_NO_ISTREAM_UNSIGNED_LONG_LONG) && \
+ !defined(KWSYS_IOS_ISTREAM_UNSIGNED_LONG_LONG_DEFINED)
+# define KWSYS_IOS_ISTREAM_UNSIGNED_LONG_LONG_DEFINED
+# define @KWSYS_NAMESPACE@_IOS_ISTREAM_UNSIGNED_LONG_LONG_DEFINED
+inline kwsys_ios::istream&
+operator>>(kwsys_ios::istream& is, @KWSYS_NAMESPACE@::IOStreamULL& value)
+{
+ return @KWSYS_NAMESPACE@::IOStreamScan(is, value);
+}
+# endif
+# endif /* !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG */
+
+# if !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG
+
+/* Output stream operator implementation functions. */
+namespace @KWSYS_NAMESPACE@
+{
+kwsysEXPORT kwsys_ios::ostream& IOStreamPrint(kwsys_ios::ostream&,
+ IOStreamSLL);
+kwsysEXPORT kwsys_ios::ostream& IOStreamPrint(kwsys_ios::ostream&,
+ IOStreamULL);
+}
+
+/* Provide output stream operator for long long. */
+# if !defined(@KWSYS_NAMESPACE@_IOS_NO_OSTREAM_LONG_LONG) && \
+ !defined(KWSYS_IOS_OSTREAM_LONG_LONG_DEFINED)
+# define KWSYS_IOS_OSTREAM_LONG_LONG_DEFINED
+# define @KWSYS_NAMESPACE@_IOS_OSTREAM_LONG_LONG_DEFINED
+inline kwsys_ios::ostream&
+operator<<(kwsys_ios::ostream& os, @KWSYS_NAMESPACE@::IOStreamSLL value)
+{
+ return @KWSYS_NAMESPACE@::IOStreamPrint(os, value);
+}
+# endif
+
+/* Provide output stream operator for unsigned long long. */
+# if !defined(@KWSYS_NAMESPACE@_IOS_NO_OSTREAM_UNSIGNED_LONG_LONG) && \
+ !defined(KWSYS_IOS_OSTREAM_UNSIGNED_LONG_LONG_DEFINED)
+# define KWSYS_IOS_OSTREAM_UNSIGNED_LONG_LONG_DEFINED
+# define @KWSYS_NAMESPACE@_IOS_OSTREAM_UNSIGNED_LONG_LONG_DEFINED
+inline kwsys_ios::ostream&
+operator<<(kwsys_ios::ostream& os, @KWSYS_NAMESPACE@::IOStreamULL value)
+{
+ return @KWSYS_NAMESPACE@::IOStreamPrint(os, value);
+}
+# endif
+# endif /* !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG */
+#endif /* @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL */
+
+/* Undefine temporary macros. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsysEXPORT
+# undef kwsys_ios
+#endif
+
+/* If building a C++ file in kwsys itself, give the source file
+ access to the macros without a configured namespace. */
+#if defined(KWSYS_NAMESPACE)
+# define KWSYS_IOS_HAS_ISTREAM_LONG_LONG @KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG
+# define KWSYS_IOS_HAS_OSTREAM_LONG_LONG @KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG
+# define KWSYS_IOS_NEED_OPERATORS_LL @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL
+#endif
+
+#endif
+
diff --git a/Source/kwsys/MD5.c b/Source/kwsys/MD5.c
new file mode 100644
index 0000000000..a1470572d7
--- /dev/null
+++ b/Source/kwsys/MD5.c
@@ -0,0 +1,523 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(MD5.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "MD5.h.in"
+#endif
+
+#include <stddef.h> /* size_t */
+#include <stdlib.h> /* malloc, free */
+#include <string.h> /* memcpy, strlen */
+
+/*--------------------------------------------------------------------------*/
+
+/* This MD5 implementation has been taken from a third party. Slight
+ modifications to the arrangement of the code have been made to put
+ it in a single source file instead of a separate header and
+ implementation file. */
+
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+
+/*
+ Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ L. Peter Deutsch
+ ghost@aladdin.com
+
+ */
+/*
+ Independent implementation of MD5 (RFC 1321).
+
+ This code implements the MD5 Algorithm defined in RFC 1321, whose
+ text is available at
+ http://www.ietf.org/rfc/rfc1321.txt
+ The code is derived from the text of the RFC, including the test suite
+ (section A.5) but excluding the rest of Appendix A. It does not include
+ any code or documentation that is identified in the RFC as being
+ copyrighted.
+
+ The original and principal author of md5.c is L. Peter Deutsch
+ <ghost@aladdin.com>. Other authors are noted in the change history
+ that follows (in reverse chronological order):
+
+ 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
+ either statically or dynamically; added missing #include <string.h>
+ in library.
+ 2002-03-11 lpd Corrected argument list for main(), and added int return
+ type, in test program and T value program.
+ 2002-02-21 lpd Added missing #include <stdio.h> in test program.
+ 2000-07-03 lpd Patched to eliminate warnings about "constant is
+ unsigned in ANSI C, signed in traditional"; made test program
+ self-checking.
+ 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
+ 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
+ 1999-05-03 lpd Original version.
+ */
+
+/*
+ * This package supports both compile-time and run-time determination of CPU
+ * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
+ * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
+ * defined as non-zero, the code will be compiled to run only on big-endian
+ * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
+ * run on either big- or little-endian CPUs, but will run slightly less
+ * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
+ */
+
+typedef unsigned char md5_byte_t; /* 8-bit byte */
+typedef unsigned int md5_word_t; /* 32-bit word */
+
+/* Define the state of the MD5 Algorithm. */
+typedef struct md5_state_s {
+ md5_word_t count[2]; /* message length in bits, lsw first */
+ md5_word_t abcd[4]; /* digest buffer */
+ md5_byte_t buf[64]; /* accumulate block */
+} md5_state_t;
+
+#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
+#ifdef ARCH_IS_BIG_ENDIAN
+# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
+#else
+# define BYTE_ORDER 0
+#endif
+
+#define T_MASK ((md5_word_t)~0)
+#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
+#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
+#define T3 0x242070db
+#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
+#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
+#define T6 0x4787c62a
+#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
+#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
+#define T9 0x698098d8
+#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
+#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
+#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
+#define T13 0x6b901122
+#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
+#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
+#define T16 0x49b40821
+#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
+#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
+#define T19 0x265e5a51
+#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
+#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
+#define T22 0x02441453
+#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
+#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
+#define T25 0x21e1cde6
+#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
+#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
+#define T28 0x455a14ed
+#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
+#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
+#define T31 0x676f02d9
+#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
+#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
+#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
+#define T35 0x6d9d6122
+#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
+#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
+#define T38 0x4bdecfa9
+#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
+#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
+#define T41 0x289b7ec6
+#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
+#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
+#define T44 0x04881d05
+#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
+#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
+#define T47 0x1fa27cf8
+#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
+#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
+#define T50 0x432aff97
+#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
+#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
+#define T53 0x655b59c3
+#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
+#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
+#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
+#define T57 0x6fa87e4f
+#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
+#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
+#define T60 0x4e0811a1
+#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
+#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
+#define T63 0x2ad7d2bb
+#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
+
+
+static void
+md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
+{
+ md5_word_t
+ a = pms->abcd[0], b = pms->abcd[1],
+ c = pms->abcd[2], d = pms->abcd[3];
+ md5_word_t t;
+#if BYTE_ORDER > 0
+ /* Define storage only for big-endian CPUs. */
+ md5_word_t X[16];
+#else
+ /* Define storage for little-endian or both types of CPUs. */
+ md5_word_t xbuf[16];
+ const md5_word_t *X;
+#endif
+
+ {
+#if BYTE_ORDER == 0
+ /*
+ * Determine dynamically whether this is a big-endian or
+ * little-endian machine, since we can use a more efficient
+ * algorithm on the latter.
+ */
+ static const int w = 1;
+
+ if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
+#endif
+#if BYTE_ORDER <= 0 /* little-endian */
+ {
+ /*
+ * On little-endian machines, we can process properly aligned
+ * data without copying it.
+ */
+ if (!((data - (const md5_byte_t *)0) & 3)) {
+ /* data are properly aligned */
+ X = (const md5_word_t *)data;
+ } else {
+ /* not aligned */
+ memcpy(xbuf, data, 64);
+ X = xbuf;
+ }
+ }
+#endif
+#if BYTE_ORDER == 0
+ else /* dynamic big-endian */
+#endif
+#if BYTE_ORDER >= 0 /* big-endian */
+ {
+ /*
+ * On big-endian machines, we must arrange the bytes in the
+ * right order.
+ */
+ const md5_byte_t *xp = data;
+ int i;
+
+# if BYTE_ORDER == 0
+ X = xbuf; /* (dynamic only) */
+# else
+# define xbuf X /* (static only) */
+# endif
+ for (i = 0; i < 16; ++i, xp += 4)
+ xbuf[i] = (md5_word_t)(xp[0] + (xp[1] << 8) +
+ (xp[2] << 16) + (xp[3] << 24));
+ }
+#endif
+ }
+
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
+
+ /* Round 1. */
+ /* Let [abcd k s i] denote the operation
+ a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
+#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + F(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 0, 7, T1);
+ SET(d, a, b, c, 1, 12, T2);
+ SET(c, d, a, b, 2, 17, T3);
+ SET(b, c, d, a, 3, 22, T4);
+ SET(a, b, c, d, 4, 7, T5);
+ SET(d, a, b, c, 5, 12, T6);
+ SET(c, d, a, b, 6, 17, T7);
+ SET(b, c, d, a, 7, 22, T8);
+ SET(a, b, c, d, 8, 7, T9);
+ SET(d, a, b, c, 9, 12, T10);
+ SET(c, d, a, b, 10, 17, T11);
+ SET(b, c, d, a, 11, 22, T12);
+ SET(a, b, c, d, 12, 7, T13);
+ SET(d, a, b, c, 13, 12, T14);
+ SET(c, d, a, b, 14, 17, T15);
+ SET(b, c, d, a, 15, 22, T16);
+#undef SET
+
+ /* Round 2. */
+ /* Let [abcd k s i] denote the operation
+ a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
+#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + G(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 1, 5, T17);
+ SET(d, a, b, c, 6, 9, T18);
+ SET(c, d, a, b, 11, 14, T19);
+ SET(b, c, d, a, 0, 20, T20);
+ SET(a, b, c, d, 5, 5, T21);
+ SET(d, a, b, c, 10, 9, T22);
+ SET(c, d, a, b, 15, 14, T23);
+ SET(b, c, d, a, 4, 20, T24);
+ SET(a, b, c, d, 9, 5, T25);
+ SET(d, a, b, c, 14, 9, T26);
+ SET(c, d, a, b, 3, 14, T27);
+ SET(b, c, d, a, 8, 20, T28);
+ SET(a, b, c, d, 13, 5, T29);
+ SET(d, a, b, c, 2, 9, T30);
+ SET(c, d, a, b, 7, 14, T31);
+ SET(b, c, d, a, 12, 20, T32);
+#undef SET
+
+ /* Round 3. */
+ /* Let [abcd k s t] denote the operation
+ a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + H(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 5, 4, T33);
+ SET(d, a, b, c, 8, 11, T34);
+ SET(c, d, a, b, 11, 16, T35);
+ SET(b, c, d, a, 14, 23, T36);
+ SET(a, b, c, d, 1, 4, T37);
+ SET(d, a, b, c, 4, 11, T38);
+ SET(c, d, a, b, 7, 16, T39);
+ SET(b, c, d, a, 10, 23, T40);
+ SET(a, b, c, d, 13, 4, T41);
+ SET(d, a, b, c, 0, 11, T42);
+ SET(c, d, a, b, 3, 16, T43);
+ SET(b, c, d, a, 6, 23, T44);
+ SET(a, b, c, d, 9, 4, T45);
+ SET(d, a, b, c, 12, 11, T46);
+ SET(c, d, a, b, 15, 16, T47);
+ SET(b, c, d, a, 2, 23, T48);
+#undef SET
+
+ /* Round 4. */
+ /* Let [abcd k s t] denote the operation
+ a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
+#define I(x, y, z) ((y) ^ ((x) | ~(z)))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + I(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 0, 6, T49);
+ SET(d, a, b, c, 7, 10, T50);
+ SET(c, d, a, b, 14, 15, T51);
+ SET(b, c, d, a, 5, 21, T52);
+ SET(a, b, c, d, 12, 6, T53);
+ SET(d, a, b, c, 3, 10, T54);
+ SET(c, d, a, b, 10, 15, T55);
+ SET(b, c, d, a, 1, 21, T56);
+ SET(a, b, c, d, 8, 6, T57);
+ SET(d, a, b, c, 15, 10, T58);
+ SET(c, d, a, b, 6, 15, T59);
+ SET(b, c, d, a, 13, 21, T60);
+ SET(a, b, c, d, 4, 6, T61);
+ SET(d, a, b, c, 11, 10, T62);
+ SET(c, d, a, b, 2, 15, T63);
+ SET(b, c, d, a, 9, 21, T64);
+#undef SET
+
+ /* Then perform the following additions. (That is increment each
+ of the four registers by the value it had before this block
+ was started.) */
+ pms->abcd[0] += a;
+ pms->abcd[1] += b;
+ pms->abcd[2] += c;
+ pms->abcd[3] += d;
+}
+
+/* Initialize the algorithm. */
+static void md5_init(md5_state_t *pms)
+{
+ pms->count[0] = pms->count[1] = 0;
+ pms->abcd[0] = 0x67452301;
+ pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
+ pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
+ pms->abcd[3] = 0x10325476;
+}
+
+/* Append a string to the message. */
+static void md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes)
+{
+ const md5_byte_t *p = data;
+ size_t left = nbytes;
+ size_t offset = (pms->count[0] >> 3) & 63;
+ md5_word_t nbits = (md5_word_t)(nbytes << 3);
+
+ if (nbytes <= 0)
+ return;
+
+ /* Update the message length. */
+ pms->count[1] += (md5_word_t)(nbytes >> 29);
+ pms->count[0] += nbits;
+ if (pms->count[0] < nbits)
+ pms->count[1]++;
+
+ /* Process an initial partial block. */
+ if (offset) {
+ size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
+
+ memcpy(pms->buf + offset, p, copy);
+ if (offset + copy < 64)
+ return;
+ p += copy;
+ left -= copy;
+ md5_process(pms, pms->buf);
+ }
+
+ /* Process full blocks. */
+ for (; left >= 64; p += 64, left -= 64)
+ md5_process(pms, p);
+
+ /* Process a final partial block. */
+ if (left)
+ memcpy(pms->buf, p, left);
+}
+
+/* Finish the message and return the digest. */
+static void md5_finish(md5_state_t *pms, md5_byte_t digest[16])
+{
+ static const md5_byte_t pad[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ md5_byte_t data[8];
+ int i;
+
+ /* Save the length before padding. */
+ for (i = 0; i < 8; ++i)
+ data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
+ /* Pad to 56 bytes mod 64. */
+ md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
+ /* Append the length. */
+ md5_append(pms, data, 8);
+ for (i = 0; i < 16; ++i)
+ digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
+}
+
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* Wrap up the MD5 state in our opaque structure. */
+struct kwsysMD5_s
+{
+ md5_state_t md5_state;
+};
+
+/*--------------------------------------------------------------------------*/
+kwsysMD5* kwsysMD5_New(void)
+{
+ /* Allocate a process control structure. */
+ kwsysMD5* md5 = (kwsysMD5*)malloc(sizeof(kwsysMD5));
+ if(!md5)
+ {
+ return 0;
+ }
+ return md5;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysMD5_Delete(kwsysMD5* md5)
+{
+ /* Make sure we have an instance. */
+ if(!md5)
+ {
+ return;
+ }
+
+ /* Free memory. */
+ free(md5);
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysMD5_Initialize(kwsysMD5* md5)
+{
+ md5_init(&md5->md5_state);
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysMD5_Append(kwsysMD5* md5, unsigned char const* data, int length)
+{
+ size_t dlen;
+ if(length < 0)
+ {
+ dlen = strlen((char const*)data);
+ }
+ else
+ {
+ dlen = (size_t)length;
+ }
+ md5_append(&md5->md5_state, (md5_byte_t const*)data, dlen);
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysMD5_Finalize(kwsysMD5* md5, unsigned char digest[16])
+{
+ md5_finish(&md5->md5_state, (md5_byte_t*)digest);
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysMD5_FinalizeHex(kwsysMD5* md5, char buffer[32])
+{
+ unsigned char digest[16];
+ kwsysMD5_Finalize(md5, digest);
+ kwsysMD5_DigestToHex(digest, buffer);
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysMD5_DigestToHex(unsigned char const digest[16], char buffer[32])
+{
+ /* Map from 4-bit index to hexadecimal representation. */
+ static char const hex[16] =
+ {'0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+
+ /* Map each 4-bit block separately. */
+ char* out = buffer;
+ int i;
+ for(i=0; i < 16; ++i)
+ {
+ *out++ = hex[digest[i] >> 4];
+ *out++ = hex[digest[i] & 0xF];
+ }
+}
diff --git a/Source/kwsys/MD5.h.in b/Source/kwsys/MD5.h.in
new file mode 100644
index 0000000000..33344317db
--- /dev/null
+++ b/Source/kwsys/MD5.h.in
@@ -0,0 +1,107 @@
+/*============================================================================
+ 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@_MD5_h
+#define @KWSYS_NAMESPACE@_MD5_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@_EXPORT
+#endif
+#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsysMD5 kwsys_ns(MD5)
+# define kwsysMD5_s kwsys_ns(MD5_s)
+# define kwsysMD5_New kwsys_ns(MD5_New)
+# define kwsysMD5_Delete kwsys_ns(MD5_Delete)
+# define kwsysMD5_Initialize kwsys_ns(MD5_Initialize)
+# define kwsysMD5_Append kwsys_ns(MD5_Append)
+# define kwsysMD5_Finalize kwsys_ns(MD5_Finalize)
+# define kwsysMD5_FinalizeHex kwsys_ns(MD5_FinalizeHex)
+# define kwsysMD5_DigestToHex kwsys_ns(MD5_DigestToHex)
+#endif
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/**
+ * MD5 state data structure.
+ */
+typedef struct kwsysMD5_s kwsysMD5;
+
+/**
+ * Create a new MD5 instance. The returned instance is not initialized.
+ */
+kwsysEXPORT kwsysMD5* kwsysMD5_New(void);
+
+/**
+ * Delete an old MD5 instance.
+ */
+kwsysEXPORT void kwsysMD5_Delete(kwsysMD5* md5);
+
+/**
+ * Initialize a new MD5 digest.
+ */
+kwsysEXPORT void kwsysMD5_Initialize(kwsysMD5* md5);
+
+/**
+ * Append data to an MD5 digest. If the given length is negative,
+ * data will be read up to but not including a terminating null.
+ */
+kwsysEXPORT void kwsysMD5_Append(kwsysMD5* md5, unsigned char const* data,
+ int length);
+
+/**
+ * Finalize a MD5 digest and get the 16-byte hash value.
+ */
+kwsysEXPORT void kwsysMD5_Finalize(kwsysMD5* md5, unsigned char digest[16]);
+
+/**
+ * Finalize a MD5 digest and get the 32-bit hexadecimal representation.
+ */
+kwsysEXPORT void kwsysMD5_FinalizeHex(kwsysMD5* md5, char buffer[32]);
+
+/**
+ * Convert a MD5 digest 16-byte value to a 32-byte hexadecimal representation.
+ */
+kwsysEXPORT void kwsysMD5_DigestToHex(unsigned char const digest[16],
+ char buffer[32]);
+
+#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 !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsysMD5
+# undef kwsysMD5_s
+# undef kwsysMD5_New
+# undef kwsysMD5_Delete
+# undef kwsysMD5_Initialize
+# undef kwsysMD5_Append
+# undef kwsysMD5_Finalize
+# undef kwsysMD5_FinalizeHex
+# undef kwsysMD5_DigestToHex
+# endif
+#endif
+
+#endif
diff --git a/Source/kwsys/Process.h.in b/Source/kwsys/Process.h.in
new file mode 100644
index 0000000000..c5995eac1d
--- /dev/null
+++ b/Source/kwsys/Process.h.in
@@ -0,0 +1,428 @@
+/*============================================================================
+ 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@_Process_h
+#define @KWSYS_NAMESPACE@_Process_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@_EXPORT
+#endif
+#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsysProcess kwsys_ns(Process)
+# define kwsysProcess_s kwsys_ns(Process_s)
+# define kwsysProcess_New kwsys_ns(Process_New)
+# define kwsysProcess_Delete kwsys_ns(Process_Delete)
+# define kwsysProcess_SetCommand kwsys_ns(Process_SetCommand)
+# define kwsysProcess_AddCommand kwsys_ns(Process_AddCommand)
+# define kwsysProcess_SetTimeout kwsys_ns(Process_SetTimeout)
+# define kwsysProcess_SetWorkingDirectory kwsys_ns(Process_SetWorkingDirectory)
+# define kwsysProcess_SetPipeFile kwsys_ns(Process_SetPipeFile)
+# define kwsysProcess_SetPipeNative kwsys_ns(Process_SetPipeNative)
+# define kwsysProcess_SetPipeShared kwsys_ns(Process_SetPipeShared)
+# define kwsysProcess_Option_Detach kwsys_ns(Process_Option_Detach)
+# define kwsysProcess_Option_HideWindow kwsys_ns(Process_Option_HideWindow)
+# define kwsysProcess_Option_Verbatim kwsys_ns(Process_Option_Verbatim)
+# define kwsysProcess_GetOption kwsys_ns(Process_GetOption)
+# define kwsysProcess_SetOption kwsys_ns(Process_SetOption)
+# define kwsysProcess_Option_e kwsys_ns(Process_Option_e)
+# define kwsysProcess_State_Starting kwsys_ns(Process_State_Starting)
+# define kwsysProcess_State_Error kwsys_ns(Process_State_Error)
+# define kwsysProcess_State_Exception kwsys_ns(Process_State_Exception)
+# define kwsysProcess_State_Executing kwsys_ns(Process_State_Executing)
+# define kwsysProcess_State_Exited kwsys_ns(Process_State_Exited)
+# define kwsysProcess_State_Expired kwsys_ns(Process_State_Expired)
+# define kwsysProcess_State_Killed kwsys_ns(Process_State_Killed)
+# define kwsysProcess_State_Disowned kwsys_ns(Process_State_Disowned)
+# define kwsysProcess_GetState kwsys_ns(Process_GetState)
+# define kwsysProcess_State_e kwsys_ns(Process_State_e)
+# define kwsysProcess_Exception_None kwsys_ns(Process_Exception_None)
+# define kwsysProcess_Exception_Fault kwsys_ns(Process_Exception_Fault)
+# define kwsysProcess_Exception_Illegal kwsys_ns(Process_Exception_Illegal)
+# define kwsysProcess_Exception_Interrupt kwsys_ns(Process_Exception_Interrupt)
+# define kwsysProcess_Exception_Numerical kwsys_ns(Process_Exception_Numerical)
+# define kwsysProcess_Exception_Other kwsys_ns(Process_Exception_Other)
+# define kwsysProcess_GetExitException kwsys_ns(Process_GetExitException)
+# define kwsysProcess_Exception_e kwsys_ns(Process_Exception_e)
+# define kwsysProcess_GetExitCode kwsys_ns(Process_GetExitCode)
+# define kwsysProcess_GetExitValue kwsys_ns(Process_GetExitValue)
+# define kwsysProcess_GetErrorString kwsys_ns(Process_GetErrorString)
+# define kwsysProcess_GetExceptionString kwsys_ns(Process_GetExceptionString)
+# define kwsysProcess_Execute kwsys_ns(Process_Execute)
+# define kwsysProcess_Disown kwsys_ns(Process_Disown)
+# define kwsysProcess_WaitForData kwsys_ns(Process_WaitForData)
+# define kwsysProcess_Pipes_e kwsys_ns(Process_Pipes_e)
+# define kwsysProcess_Pipe_None kwsys_ns(Process_Pipe_None)
+# define kwsysProcess_Pipe_STDIN kwsys_ns(Process_Pipe_STDIN)
+# define kwsysProcess_Pipe_STDOUT kwsys_ns(Process_Pipe_STDOUT)
+# define kwsysProcess_Pipe_STDERR kwsys_ns(Process_Pipe_STDERR)
+# define kwsysProcess_Pipe_Timeout kwsys_ns(Process_Pipe_Timeout)
+# define kwsysProcess_Pipe_Handle kwsys_ns(Process_Pipe_Handle)
+# define kwsysProcess_WaitForExit kwsys_ns(Process_WaitForExit)
+# define kwsysProcess_Kill kwsys_ns(Process_Kill)
+#endif
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/**
+ * Process control data structure.
+ */
+typedef struct kwsysProcess_s kwsysProcess;
+
+/* Platform-specific pipe handle type. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+typedef void* kwsysProcess_Pipe_Handle;
+#else
+typedef int kwsysProcess_Pipe_Handle;
+#endif
+
+/**
+ * Create a new Process instance.
+ */
+kwsysEXPORT kwsysProcess* kwsysProcess_New(void);
+
+/**
+ * Delete an existing Process instance. If the instance is currently
+ * executing a process, this blocks until the process terminates.
+ */
+kwsysEXPORT void kwsysProcess_Delete(kwsysProcess* cp);
+
+/**
+ * Set the command line to be executed. Argument is an array of
+ * pointers to the command and each argument. The array must end with
+ * a NULL pointer. Any previous command lines are removed. Returns
+ * 1 for success and 0 otherwise.
+ */
+kwsysEXPORT int kwsysProcess_SetCommand(kwsysProcess* cp,
+ char const* const* command);
+
+/**
+ * Add a command line to be executed. Argument is an array of
+ * pointers to the command and each argument. The array must end with
+ * a NULL pointer. If this is not the first command added, its
+ * standard input will be connected to the standard output of the
+ * previous command. Returns 1 for success and 0 otherwise.
+ */
+kwsysEXPORT int kwsysProcess_AddCommand(kwsysProcess* cp,
+ char const* const* command);
+
+/**
+ * Set the timeout in seconds for the child process. The timeout
+ * period begins when the child is executed. If the child has not
+ * terminated when the timeout expires, it will be killed. A
+ * non-positive (<= 0) value will disable the timeout.
+ */
+kwsysEXPORT void kwsysProcess_SetTimeout(kwsysProcess* cp, double timeout);
+
+/**
+ * Set the working directory for the child process. The working
+ * directory can be absolute or relative to the current directory.
+ * Returns 1 for success and 0 for failure.
+ */
+kwsysEXPORT int kwsysProcess_SetWorkingDirectory(kwsysProcess* cp,
+ const char* dir);
+
+/**
+ * Set the name of a file to be attached to the given pipe. Returns 1
+ * for success and 0 for failure.
+ */
+kwsysEXPORT int kwsysProcess_SetPipeFile(kwsysProcess* cp, int pipe,
+ const char* file);
+
+/**
+ * Set whether the given pipe in the child is shared with the parent
+ * process. The default is no for Pipe_STDOUT and Pipe_STDERR and yes
+ * for Pipe_STDIN.
+ */
+kwsysEXPORT void kwsysProcess_SetPipeShared(kwsysProcess* cp, int pipe,
+ int shared);
+
+/**
+ * Specify a platform-specific native pipe for use as one of the child
+ * interface pipes. The native pipe is specified by an array of two
+ * descriptors or handles. The first entry in the array (index 0)
+ * should be the read end of the pipe. The second entry in the array
+ * (index 1) should be the write end of the pipe. If a null pointer
+ * is given the option will be disabled.
+ *
+ * For Pipe_STDIN the native pipe is connected to the first child in
+ * the pipeline as its stdin. After the children are created the
+ * write end of the pipe will be closed in the child process and the
+ * read end will be closed in the parent process.
+ *
+ * For Pipe_STDOUT and Pipe_STDERR the pipe is connected to the last
+ * child as its stdout or stderr. After the children are created the
+ * write end of the pipe will be closed in the parent process and the
+ * read end will be closed in the child process.
+ */
+kwsysEXPORT void kwsysProcess_SetPipeNative(kwsysProcess* cp, int pipe,
+ kwsysProcess_Pipe_Handle p[2]);
+
+/**
+ * Get/Set a possibly platform-specific option. Possible options are:
+ *
+ * kwsysProcess_Option_Detach = Whether to detach the process.
+ * 0 = No (default)
+ * 1 = Yes
+ *
+ * kwsysProcess_Option_HideWindow = Whether to hide window on Windows.
+ * 0 = No (default)
+ * 1 = Yes
+ *
+ * kwsysProcess_Option_Verbatim = Whether SetCommand and AddCommand
+ * should treat the first argument
+ * as a verbatim command line
+ * and ignore the rest of the arguments.
+ * 0 = No (default)
+ * 1 = Yes
+ */
+kwsysEXPORT int kwsysProcess_GetOption(kwsysProcess* cp, int optionId);
+kwsysEXPORT void kwsysProcess_SetOption(kwsysProcess* cp, int optionId,
+ int value);
+enum kwsysProcess_Option_e
+{
+ kwsysProcess_Option_HideWindow,
+ kwsysProcess_Option_Detach,
+ kwsysProcess_Option_Verbatim
+};
+
+/**
+ * Get the current state of the Process instance. Possible states are:
+ *
+ * kwsysProcess_State_Starting = Execute has not yet been called.
+ * kwsysProcess_State_Error = Error administrating the child process.
+ * kwsysProcess_State_Exception = Child process exited abnormally.
+ * kwsysProcess_State_Executing = Child process is currently running.
+ * kwsysProcess_State_Exited = Child process exited normally.
+ * kwsysProcess_State_Expired = Child process's timeout expired.
+ * kwsysProcess_State_Killed = Child process terminated by Kill method.
+ * kwsysProcess_State_Disowned = Child is no longer managed by this object.
+ */
+kwsysEXPORT int kwsysProcess_GetState(kwsysProcess* cp);
+enum kwsysProcess_State_e
+{
+ kwsysProcess_State_Starting,
+ kwsysProcess_State_Error,
+ kwsysProcess_State_Exception,
+ kwsysProcess_State_Executing,
+ kwsysProcess_State_Exited,
+ kwsysProcess_State_Expired,
+ kwsysProcess_State_Killed,
+ kwsysProcess_State_Disowned
+};
+
+/**
+ * When GetState returns "Exception", this method returns a
+ * platform-independent description of the exceptional behavior that
+ * caused the child to terminate abnormally. Possible exceptions are:
+ *
+ * kwsysProcess_Exception_None = No exceptional behavior occurred.
+ * kwsysProcess_Exception_Fault = Child crashed with a memory fault.
+ * kwsysProcess_Exception_Illegal = Child crashed with an illegal instruction.
+ * kwsysProcess_Exception_Interrupt = Child was interrupted by user (Cntl-C/Break).
+ * kwsysProcess_Exception_Numerical = Child crashed with a numerical exception.
+ * kwsysProcess_Exception_Other = Child terminated for another reason.
+ */
+kwsysEXPORT int kwsysProcess_GetExitException(kwsysProcess* cp);
+enum kwsysProcess_Exception_e
+{
+ kwsysProcess_Exception_None,
+ kwsysProcess_Exception_Fault,
+ kwsysProcess_Exception_Illegal,
+ kwsysProcess_Exception_Interrupt,
+ kwsysProcess_Exception_Numerical,
+ kwsysProcess_Exception_Other
+};
+
+/**
+ * When GetState returns "Exited" or "Exception", this method returns
+ * the platform-specific raw exit code of the process. UNIX platforms
+ * should use WIFEXITED/WEXITSTATUS and WIFSIGNALED/WTERMSIG to access
+ * this value. Windows users should compare the value to the various
+ * EXCEPTION_* values.
+ *
+ * If GetState returns "Exited", use GetExitValue to get the
+ * platform-independent child return value.
+ */
+kwsysEXPORT int kwsysProcess_GetExitCode(kwsysProcess* cp);
+
+/**
+ * When GetState returns "Exited", this method returns the child's
+ * platform-independent exit code (such as the value returned by the
+ * child's main).
+ */
+kwsysEXPORT int kwsysProcess_GetExitValue(kwsysProcess* cp);
+
+/**
+ * When GetState returns "Error", this method returns a string
+ * describing the problem. Otherwise, it returns NULL.
+ */
+kwsysEXPORT const char* kwsysProcess_GetErrorString(kwsysProcess* cp);
+
+/**
+ * When GetState returns "Exception", this method returns a string
+ * describing the problem. Otherwise, it returns NULL.
+ */
+kwsysEXPORT const char* kwsysProcess_GetExceptionString(kwsysProcess* cp);
+
+/**
+ * Start executing the child process.
+ */
+kwsysEXPORT void kwsysProcess_Execute(kwsysProcess* cp);
+
+/**
+ * Stop management of a detached child process. This closes any pipes
+ * being read. If the child was not created with the
+ * kwsysProcess_Option_Detach option, this method does nothing. This
+ * is because disowning a non-detached process will cause the child
+ * exit signal to be left unhandled until this process exits.
+ */
+kwsysEXPORT void kwsysProcess_Disown(kwsysProcess* cp);
+
+/**
+ * Block until data are available on a pipe, a timeout expires, or the
+ * child process terminates. Arguments are as follows:
+ *
+ * data = If data are read, the pointer to which this points is
+ * set to point to the data.
+ * length = If data are read, the integer to which this points is
+ * set to the length of the data read.
+ * timeout = Specifies the maximum time this call may block. Upon
+ * return after reading data, the time elapsed is subtracted
+ * from the timeout value. If this timeout expires, the
+ * value is set to 0. A NULL pointer passed for this argument
+ * indicates no timeout for the call. A negative or zero
+ * value passed for this argument may be used for polling
+ * and will always return immediately.
+ *
+ * Return value will be one of:
+ *
+ * Pipe_None = No more data will be available from the child process,
+ * ( == 0) or no process has been executed. WaitForExit should
+ * be called to wait for the process to terminate.
+ * Pipe_STDOUT = Data have been read from the child's stdout pipe.
+ * Pipe_STDERR = Data have been read from the child's stderr pipe.
+ * Pipe_Timeout = No data available within timeout specified for the
+ * call. Time elapsed has been subtracted from timeout
+ * argument.
+ */
+kwsysEXPORT int kwsysProcess_WaitForData(kwsysProcess* cp, char** data,
+ int* length, double* timeout);
+enum kwsysProcess_Pipes_e
+{
+ kwsysProcess_Pipe_None,
+ kwsysProcess_Pipe_STDIN,
+ kwsysProcess_Pipe_STDOUT,
+ kwsysProcess_Pipe_STDERR,
+ kwsysProcess_Pipe_Timeout=255
+};
+
+/**
+ * Block until the child process terminates or the given timeout
+ * expires. If no process is running, returns immediatly. The
+ * argument is:
+ *
+ * timeout = Specifies the maximum time this call may block. Upon
+ * returning due to child termination, the elapsed time
+ * is subtracted from the given value. A NULL pointer
+ * passed for this argument indicates no timeout for the
+ * call.
+ *
+ * Return value will be one of:
+ *
+ * 0 = Child did not terminate within timeout specified for
+ * the call. Time elapsed has been subtracted from timeout
+ * argument.
+ * 1 = Child has terminated or was not running.
+ */
+kwsysEXPORT int kwsysProcess_WaitForExit(kwsysProcess* cp, double* timeout);
+
+/**
+ * Forcefully terminate the child process that is currently running.
+ * The caller should call WaitForExit after this returns to wait for
+ * the child to terminate.
+ */
+kwsysEXPORT void kwsysProcess_Kill(kwsysProcess* cp);
+
+#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 !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsysProcess
+# undef kwsysProcess_s
+# undef kwsysProcess_New
+# undef kwsysProcess_Delete
+# undef kwsysProcess_SetCommand
+# undef kwsysProcess_AddCommand
+# undef kwsysProcess_SetTimeout
+# undef kwsysProcess_SetWorkingDirectory
+# undef kwsysProcess_SetPipeFile
+# undef kwsysProcess_SetPipeNative
+# undef kwsysProcess_SetPipeShared
+# undef kwsysProcess_Option_Detach
+# undef kwsysProcess_Option_HideWindow
+# undef kwsysProcess_Option_Verbatim
+# undef kwsysProcess_GetOption
+# undef kwsysProcess_SetOption
+# undef kwsysProcess_Option_e
+# undef kwsysProcess_State_Starting
+# undef kwsysProcess_State_Error
+# undef kwsysProcess_State_Exception
+# undef kwsysProcess_State_Executing
+# undef kwsysProcess_State_Exited
+# undef kwsysProcess_State_Expired
+# undef kwsysProcess_State_Killed
+# undef kwsysProcess_State_Disowned
+# undef kwsysProcess_GetState
+# undef kwsysProcess_State_e
+# undef kwsysProcess_Exception_None
+# undef kwsysProcess_Exception_Fault
+# undef kwsysProcess_Exception_Illegal
+# undef kwsysProcess_Exception_Interrupt
+# undef kwsysProcess_Exception_Numerical
+# undef kwsysProcess_Exception_Other
+# undef kwsysProcess_GetExitException
+# undef kwsysProcess_Exception_e
+# undef kwsysProcess_GetExitCode
+# undef kwsysProcess_GetExitValue
+# undef kwsysProcess_GetErrorString
+# undef kwsysProcess_GetExceptionString
+# undef kwsysProcess_Execute
+# undef kwsysProcess_Disown
+# undef kwsysProcess_WaitForData
+# undef kwsysProcess_Pipes_e
+# undef kwsysProcess_Pipe_None
+# undef kwsysProcess_Pipe_STDIN
+# undef kwsysProcess_Pipe_STDOUT
+# undef kwsysProcess_Pipe_STDERR
+# undef kwsysProcess_Pipe_Timeout
+# undef kwsysProcess_Pipe_Handle
+# undef kwsysProcess_WaitForExit
+# undef kwsysProcess_Kill
+# endif
+#endif
+
+#endif
diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c
new file mode 100644
index 0000000000..ca9d424289
--- /dev/null
+++ b/Source/kwsys/ProcessUNIX.c
@@ -0,0 +1,2765 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Process.h)
+#include KWSYS_HEADER(System.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "Process.h.in"
+# include "System.h.in"
+#endif
+
+/*
+
+Implementation for UNIX
+
+On UNIX, a child process is forked to exec the program. Three output
+pipes are read by the parent process using a select call to block
+until data are ready. Two of the pipes are stdout and stderr for the
+child. The third is a special pipe populated by a signal handler to
+indicate that a child has terminated. This is used in conjunction
+with the timeout on the select call to implement a timeout for program
+even when it closes stdout and stderr and at the same time avoiding
+races.
+
+*/
+
+
+/*
+
+TODO:
+
+We cannot create the pipeline of processes in suspended states. How
+do we cleanup processes already started when one fails to load? Right
+now we are just killing them, which is probably not the right thing to
+do.
+
+*/
+
+#if defined(__CYGWIN__)
+/* Increase the file descriptor limit for select() before including
+ related system headers. (Default: 64) */
+# define FD_SETSIZE 16384
+#endif
+
+#include <stddef.h> /* ptrdiff_t */
+#include <stdio.h> /* snprintf */
+#include <stdlib.h> /* malloc, free */
+#include <string.h> /* strdup, strerror, memset */
+#include <sys/time.h> /* struct timeval */
+#include <sys/types.h> /* pid_t, fd_set */
+#include <sys/wait.h> /* waitpid */
+#include <sys/stat.h> /* open mode */
+#include <unistd.h> /* pipe, close, fork, execvp, select, _exit */
+#include <fcntl.h> /* fcntl */
+#include <errno.h> /* errno */
+#include <time.h> /* gettimeofday */
+#include <signal.h> /* sigaction */
+#include <dirent.h> /* DIR, dirent */
+#include <ctype.h> /* isspace */
+#include <assert.h> /* assert */
+
+#if defined(__VMS)
+# define KWSYSPE_VMS_NONBLOCK , O_NONBLOCK
+#else
+# define KWSYSPE_VMS_NONBLOCK
+#endif
+
+#if defined(KWSYS_C_HAS_PTRDIFF_T) && KWSYS_C_HAS_PTRDIFF_T
+typedef ptrdiff_t kwsysProcess_ptrdiff_t;
+#else
+typedef int kwsysProcess_ptrdiff_t;
+#endif
+
+#if defined(KWSYS_C_HAS_SSIZE_T) && KWSYS_C_HAS_SSIZE_T
+typedef ssize_t kwsysProcess_ssize_t;
+#else
+typedef int kwsysProcess_ssize_t;
+#endif
+
+#if defined(__BEOS__) && !defined(__ZETA__)
+/* BeOS 5 doesn't have usleep(), but it has snooze(), which is identical. */
+# include <be/kernel/OS.h>
+static inline void kwsysProcess_usleep(unsigned int msec)
+{
+ snooze(msec);
+}
+#else
+# define kwsysProcess_usleep usleep
+#endif
+
+/*
+ * BeOS's select() works like WinSock: it's for networking only, and
+ * doesn't work with Unix file handles...socket and file handles are
+ * different namespaces (the same descriptor means different things in
+ * each context!)
+ *
+ * So on Unix-like systems where select() is flakey, we'll set the
+ * pipes' file handles to be non-blocking and just poll them directly
+ * without select().
+ */
+#if !defined(__BEOS__) && !defined(__VMS) && !defined(__MINT__)
+# define KWSYSPE_USE_SELECT 1
+#endif
+
+/* Some platforms do not have siginfo on their signal handlers. */
+#if defined(SA_SIGINFO) && !defined(__BEOS__)
+# define KWSYSPE_USE_SIGINFO 1
+#endif
+
+/* The number of pipes for the child's output. The standard stdout
+ and stderr pipes are the first two. One more pipe is used to
+ detect when the child process has terminated. The third pipe is
+ not given to the child process, so it cannot close it until it
+ terminates. */
+#define KWSYSPE_PIPE_COUNT 3
+#define KWSYSPE_PIPE_STDOUT 0
+#define KWSYSPE_PIPE_STDERR 1
+#define KWSYSPE_PIPE_SIGNAL 2
+
+/* The maximum amount to read from a pipe at a time. */
+#define KWSYSPE_PIPE_BUFFER_SIZE 1024
+
+/* Keep track of times using a signed representation. Switch to the
+ native (possibly unsigned) representation only when calling native
+ functions. */
+typedef struct timeval kwsysProcessTimeNative;
+typedef struct kwsysProcessTime_s kwsysProcessTime;
+struct kwsysProcessTime_s
+{
+ long tv_sec;
+ long tv_usec;
+};
+
+typedef struct kwsysProcessCreateInformation_s
+{
+ int StdIn;
+ int StdOut;
+ int StdErr;
+ int ErrorPipe[2];
+} kwsysProcessCreateInformation;
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcessInitialize(kwsysProcess* cp);
+static void kwsysProcessCleanup(kwsysProcess* cp, int error);
+static void kwsysProcessCleanupDescriptor(int* pfd);
+static void kwsysProcessClosePipes(kwsysProcess* cp);
+static int kwsysProcessSetNonBlocking(int fd);
+static int kwsysProcessCreate(kwsysProcess* cp, int prIndex,
+ kwsysProcessCreateInformation* si, int* readEnd);
+static void kwsysProcessDestroy(kwsysProcess* cp);
+static int kwsysProcessSetupOutputPipeFile(int* p, const char* name);
+static int kwsysProcessSetupOutputPipeNative(int* p, int des[2]);
+static int kwsysProcessGetTimeoutTime(kwsysProcess* cp, double* userTimeout,
+ kwsysProcessTime* timeoutTime);
+static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime,
+ double* userTimeout,
+ kwsysProcessTimeNative* timeoutLength,
+ int zeroIsExpired);
+static kwsysProcessTime kwsysProcessTimeGetCurrent(void);
+static double kwsysProcessTimeToDouble(kwsysProcessTime t);
+static kwsysProcessTime kwsysProcessTimeFromDouble(double d);
+static int kwsysProcessTimeLess(kwsysProcessTime in1, kwsysProcessTime in2);
+static kwsysProcessTime kwsysProcessTimeAdd(kwsysProcessTime in1, kwsysProcessTime in2);
+static kwsysProcessTime kwsysProcessTimeSubtract(kwsysProcessTime in1, kwsysProcessTime in2);
+static void kwsysProcessSetExitException(kwsysProcess* cp, int sig);
+static void kwsysProcessChildErrorExit(int errorPipe);
+static void kwsysProcessRestoreDefaultSignalHandlers(void);
+static pid_t kwsysProcessFork(kwsysProcess* cp,
+ kwsysProcessCreateInformation* si);
+static void kwsysProcessKill(pid_t process_id);
+#if defined(__VMS)
+static int kwsysProcessSetVMSFeature(const char* name, int value);
+#endif
+static int kwsysProcessesAdd(kwsysProcess* cp);
+static void kwsysProcessesRemove(kwsysProcess* cp);
+#if KWSYSPE_USE_SIGINFO
+static void kwsysProcessesSignalHandler(int signum, siginfo_t* info,
+ void* ucontext);
+#else
+static void kwsysProcessesSignalHandler(int signum);
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* Structure containing data used to implement the child's execution. */
+struct kwsysProcess_s
+{
+ /* The command lines to execute. */
+ char*** Commands;
+ int NumberOfCommands;
+
+ /* Descriptors for the read ends of the child's output pipes and
+ the signal pipe. */
+ int PipeReadEnds[KWSYSPE_PIPE_COUNT];
+
+ /* Write descriptor for child termination signal pipe. */
+ int SignalPipe;
+
+ /* Buffer for pipe data. */
+ char PipeBuffer[KWSYSPE_PIPE_BUFFER_SIZE];
+
+ /* Process IDs returned by the calls to fork. */
+ pid_t* ForkPIDs;
+
+ /* Flag for whether the children were terminated by a faild select. */
+ int SelectError;
+
+ /* The timeout length. */
+ double Timeout;
+
+ /* The working directory for the process. */
+ char* WorkingDirectory;
+
+ /* Whether to create the child as a detached process. */
+ int OptionDetach;
+
+ /* Whether the child was created as a detached process. */
+ int Detached;
+
+ /* Whether to treat command lines as verbatim. */
+ int Verbatim;
+
+ /* Time at which the child started. Negative for no timeout. */
+ kwsysProcessTime StartTime;
+
+ /* Time at which the child will timeout. Negative for no timeout. */
+ kwsysProcessTime TimeoutTime;
+
+ /* Flag for whether the timeout expired. */
+ int TimeoutExpired;
+
+ /* The number of pipes left open during execution. */
+ int PipesLeft;
+
+#if KWSYSPE_USE_SELECT
+ /* File descriptor set for call to select. */
+ fd_set PipeSet;
+#endif
+
+ /* The number of children still executing. */
+ int CommandsLeft;
+
+ /* The current status of the child process. */
+ int State;
+
+ /* The exceptional behavior that terminated the child process, if
+ * any. */
+ int ExitException;
+
+ /* The exit code of the child process. */
+ int ExitCode;
+
+ /* The exit value of the child process, if any. */
+ int ExitValue;
+
+ /* Whether the process was killed. */
+ int Killed;
+
+ /* Buffer for error message in case of failure. */
+ char ErrorMessage[KWSYSPE_PIPE_BUFFER_SIZE+1];
+
+ /* Description for the ExitException. */
+ char ExitExceptionString[KWSYSPE_PIPE_BUFFER_SIZE+1];
+
+ /* The exit codes of each child process in the pipeline. */
+ int* CommandExitCodes;
+
+ /* Name of files to which stdin and stdout pipes are attached. */
+ char* PipeFileSTDIN;
+ char* PipeFileSTDOUT;
+ char* PipeFileSTDERR;
+
+ /* Whether each pipe is shared with the parent process. */
+ int PipeSharedSTDIN;
+ int PipeSharedSTDOUT;
+ int PipeSharedSTDERR;
+
+ /* Native pipes provided by the user. */
+ int PipeNativeSTDIN[2];
+ int PipeNativeSTDOUT[2];
+ int PipeNativeSTDERR[2];
+
+ /* The real working directory of this process. */
+ int RealWorkingDirectoryLength;
+ char* RealWorkingDirectory;
+};
+
+/*--------------------------------------------------------------------------*/
+kwsysProcess* kwsysProcess_New(void)
+{
+ /* Allocate a process control structure. */
+ kwsysProcess* cp = (kwsysProcess*)malloc(sizeof(kwsysProcess));
+ if(!cp)
+ {
+ return 0;
+ }
+ memset(cp, 0, sizeof(kwsysProcess));
+
+ /* Share stdin with the parent process by default. */
+ cp->PipeSharedSTDIN = 1;
+
+ /* No native pipes by default. */
+ cp->PipeNativeSTDIN[0] = -1;
+ cp->PipeNativeSTDIN[1] = -1;
+ cp->PipeNativeSTDOUT[0] = -1;
+ cp->PipeNativeSTDOUT[1] = -1;
+ cp->PipeNativeSTDERR[0] = -1;
+ cp->PipeNativeSTDERR[1] = -1;
+
+ /* Set initial status. */
+ cp->State = kwsysProcess_State_Starting;
+
+ return cp;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_Delete(kwsysProcess* cp)
+{
+ /* Make sure we have an instance. */
+ if(!cp)
+ {
+ return;
+ }
+
+ /* If the process is executing, wait for it to finish. */
+ if(cp->State == kwsysProcess_State_Executing)
+ {
+ if(cp->Detached)
+ {
+ kwsysProcess_Disown(cp);
+ }
+ else
+ {
+ kwsysProcess_WaitForExit(cp, 0);
+ }
+ }
+
+ /* Free memory. */
+ kwsysProcess_SetCommand(cp, 0);
+ kwsysProcess_SetWorkingDirectory(cp, 0);
+ kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDIN, 0);
+ kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDOUT, 0);
+ kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDERR, 0);
+ if(cp->CommandExitCodes)
+ {
+ free(cp->CommandExitCodes);
+ }
+ free(cp);
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_SetCommand(kwsysProcess* cp, char const* const* command)
+{
+ int i;
+ if(!cp)
+ {
+ return 0;
+ }
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ char** c = cp->Commands[i];
+ while(*c)
+ {
+ free(*c++);
+ }
+ free(cp->Commands[i]);
+ }
+ cp->NumberOfCommands = 0;
+ if(cp->Commands)
+ {
+ free(cp->Commands);
+ cp->Commands = 0;
+ }
+ if(command)
+ {
+ return kwsysProcess_AddCommand(cp, command);
+ }
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command)
+{
+ int newNumberOfCommands;
+ char*** newCommands;
+
+ /* Make sure we have a command to add. */
+ if(!cp || !command || !*command)
+ {
+ return 0;
+ }
+
+ /* Allocate a new array for command pointers. */
+ newNumberOfCommands = cp->NumberOfCommands + 1;
+ if(!(newCommands =
+ (char***)malloc(sizeof(char**) *(size_t)(newNumberOfCommands))))
+ {
+ /* Out of memory. */
+ return 0;
+ }
+
+ /* Copy any existing commands into the new array. */
+ {
+ int i;
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ newCommands[i] = cp->Commands[i];
+ }
+ }
+
+ /* Add the new command. */
+ if(cp->Verbatim)
+ {
+ /* In order to run the given command line verbatim we need to
+ parse it. */
+ newCommands[cp->NumberOfCommands] =
+ kwsysSystem_Parse_CommandForUnix(*command, 0);
+ if(!newCommands[cp->NumberOfCommands] ||
+ !newCommands[cp->NumberOfCommands][0])
+ {
+ /* Out of memory or no command parsed. */
+ free(newCommands);
+ return 0;
+ }
+ }
+ else
+ {
+ /* Copy each argument string individually. */
+ char const* const* c = command;
+ kwsysProcess_ptrdiff_t n = 0;
+ kwsysProcess_ptrdiff_t i = 0;
+ while(*c++);
+ n = c - command - 1;
+ newCommands[cp->NumberOfCommands] =
+ (char**)malloc((size_t)(n+1)*sizeof(char*));
+ if(!newCommands[cp->NumberOfCommands])
+ {
+ /* Out of memory. */
+ free(newCommands);
+ return 0;
+ }
+ for(i=0; i < n; ++i)
+ {
+ assert(command[i]); /* Quiet Clang scan-build. */
+ newCommands[cp->NumberOfCommands][i] = strdup(command[i]);
+ if(!newCommands[cp->NumberOfCommands][i])
+ {
+ break;
+ }
+ }
+ if(i < n)
+ {
+ /* Out of memory. */
+ for(;i > 0; --i)
+ {
+ free(newCommands[cp->NumberOfCommands][i-1]);
+ }
+ free(newCommands);
+ return 0;
+ }
+ newCommands[cp->NumberOfCommands][n] = 0;
+ }
+
+ /* Successfully allocated new command array. Free the old array. */
+ free(cp->Commands);
+ cp->Commands = newCommands;
+ cp->NumberOfCommands = newNumberOfCommands;
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetTimeout(kwsysProcess* cp, double timeout)
+{
+ if(!cp)
+ {
+ return;
+ }
+ cp->Timeout = timeout;
+ if(cp->Timeout < 0)
+ {
+ cp->Timeout = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir)
+{
+ if(!cp)
+ {
+ return 0;
+ }
+ if(cp->WorkingDirectory == dir)
+ {
+ return 1;
+ }
+ if(cp->WorkingDirectory && dir && strcmp(cp->WorkingDirectory, dir) == 0)
+ {
+ return 1;
+ }
+ if(cp->WorkingDirectory)
+ {
+ free(cp->WorkingDirectory);
+ cp->WorkingDirectory = 0;
+ }
+ if(dir)
+ {
+ cp->WorkingDirectory = (char*)malloc(strlen(dir) + 1);
+ if(!cp->WorkingDirectory)
+ {
+ return 0;
+ }
+ strcpy(cp->WorkingDirectory, dir);
+ }
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_SetPipeFile(kwsysProcess* cp, int prPipe, const char* file)
+{
+ char** pfile;
+ if(!cp)
+ {
+ return 0;
+ }
+ switch(prPipe)
+ {
+ case kwsysProcess_Pipe_STDIN: pfile = &cp->PipeFileSTDIN; break;
+ case kwsysProcess_Pipe_STDOUT: pfile = &cp->PipeFileSTDOUT; break;
+ case kwsysProcess_Pipe_STDERR: pfile = &cp->PipeFileSTDERR; break;
+ default: return 0;
+ }
+ if(*pfile)
+ {
+ free(*pfile);
+ *pfile = 0;
+ }
+ if(file)
+ {
+ *pfile = malloc(strlen(file)+1);
+ if(!*pfile)
+ {
+ return 0;
+ }
+ strcpy(*pfile, file);
+ }
+
+ /* If we are redirecting the pipe, do not share it or use a native
+ pipe. */
+ if(*pfile)
+ {
+ kwsysProcess_SetPipeNative(cp, prPipe, 0);
+ kwsysProcess_SetPipeShared(cp, prPipe, 0);
+ }
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetPipeShared(kwsysProcess* cp, int prPipe, int shared)
+{
+ if(!cp)
+ {
+ return;
+ }
+
+ switch(prPipe)
+ {
+ case kwsysProcess_Pipe_STDIN: cp->PipeSharedSTDIN = shared?1:0; break;
+ case kwsysProcess_Pipe_STDOUT: cp->PipeSharedSTDOUT = shared?1:0; break;
+ case kwsysProcess_Pipe_STDERR: cp->PipeSharedSTDERR = shared?1:0; break;
+ default: return;
+ }
+
+ /* If we are sharing the pipe, do not redirect it to a file or use a
+ native pipe. */
+ if(shared)
+ {
+ kwsysProcess_SetPipeFile(cp, prPipe, 0);
+ kwsysProcess_SetPipeNative(cp, prPipe, 0);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetPipeNative(kwsysProcess* cp, int prPipe, int p[2])
+{
+ int* pPipeNative = 0;
+
+ if(!cp)
+ {
+ return;
+ }
+
+ switch(prPipe)
+ {
+ case kwsysProcess_Pipe_STDIN: pPipeNative = cp->PipeNativeSTDIN; break;
+ case kwsysProcess_Pipe_STDOUT: pPipeNative = cp->PipeNativeSTDOUT; break;
+ case kwsysProcess_Pipe_STDERR: pPipeNative = cp->PipeNativeSTDERR; break;
+ default: return;
+ }
+
+ /* Copy the native pipe descriptors provided. */
+ if(p)
+ {
+ pPipeNative[0] = p[0];
+ pPipeNative[1] = p[1];
+ }
+ else
+ {
+ pPipeNative[0] = -1;
+ pPipeNative[1] = -1;
+ }
+
+ /* If we are using a native pipe, do not share it or redirect it to
+ a file. */
+ if(p)
+ {
+ kwsysProcess_SetPipeFile(cp, prPipe, 0);
+ kwsysProcess_SetPipeShared(cp, prPipe, 0);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetOption(kwsysProcess* cp, int optionId)
+{
+ if(!cp)
+ {
+ return 0;
+ }
+
+ switch(optionId)
+ {
+ case kwsysProcess_Option_Detach: return cp->OptionDetach;
+ case kwsysProcess_Option_Verbatim: return cp->Verbatim;
+ default: return 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetOption(kwsysProcess* cp, int optionId, int value)
+{
+ if(!cp)
+ {
+ return;
+ }
+
+ switch(optionId)
+ {
+ case kwsysProcess_Option_Detach: cp->OptionDetach = value; break;
+ case kwsysProcess_Option_Verbatim: cp->Verbatim = value; break;
+ default: break;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetState(kwsysProcess* cp)
+{
+ return cp? cp->State : kwsysProcess_State_Error;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetExitException(kwsysProcess* cp)
+{
+ return cp? cp->ExitException : kwsysProcess_Exception_Other;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetExitCode(kwsysProcess* cp)
+{
+ return cp? cp->ExitCode : 0;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetExitValue(kwsysProcess* cp)
+{
+ return cp? cp->ExitValue : -1;
+}
+
+/*--------------------------------------------------------------------------*/
+const char* kwsysProcess_GetErrorString(kwsysProcess* cp)
+{
+ if(!cp)
+ {
+ return "Process management structure could not be allocated";
+ }
+ else if(cp->State == kwsysProcess_State_Error)
+ {
+ return cp->ErrorMessage;
+ }
+ return "Success";
+}
+
+/*--------------------------------------------------------------------------*/
+const char* kwsysProcess_GetExceptionString(kwsysProcess* cp)
+{
+ if(!cp)
+ {
+ return "GetExceptionString called with NULL process management structure";
+ }
+ else if(cp->State == kwsysProcess_State_Exception)
+ {
+ return cp->ExitExceptionString;
+ }
+ return "No exception";
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_Execute(kwsysProcess* cp)
+{
+ int i;
+ kwsysProcessCreateInformation si = {-1, -1, -1, {-1, -1}};
+
+ /* Do not execute a second copy simultaneously. */
+ if(!cp || cp->State == kwsysProcess_State_Executing)
+ {
+ return;
+ }
+
+ /* Make sure we have something to run. */
+ if(cp->NumberOfCommands < 1)
+ {
+ strcpy(cp->ErrorMessage, "No command");
+ cp->State = kwsysProcess_State_Error;
+ return;
+ }
+
+ /* Initialize the control structure for a new process. */
+ if(!kwsysProcessInitialize(cp))
+ {
+ strcpy(cp->ErrorMessage, "Out of memory");
+ cp->State = kwsysProcess_State_Error;
+ return;
+ }
+
+#if defined(__VMS)
+ /* Make sure pipes behave like streams on VMS. */
+ if(!kwsysProcessSetVMSFeature("DECC$STREAM_PIPE", 1))
+ {
+ kwsysProcessCleanup(cp, 1);
+ return;
+ }
+#endif
+
+ /* Save the real working directory of this process and change to
+ the working directory for the child processes. This is needed
+ to make pipe file paths evaluate correctly. */
+ if(cp->WorkingDirectory)
+ {
+ int r;
+ if(!getcwd(cp->RealWorkingDirectory,
+ (size_t)(cp->RealWorkingDirectoryLength)))
+ {
+ kwsysProcessCleanup(cp, 1);
+ return;
+ }
+
+ /* Some platforms specify that the chdir call may be
+ interrupted. Repeat the call until it finishes. */
+ while(((r = chdir(cp->WorkingDirectory)) < 0) && (errno == EINTR));
+ if(r < 0)
+ {
+ kwsysProcessCleanup(cp, 1);
+ return;
+ }
+ }
+
+ /* If not running a detached child, add this object to the global
+ set of process objects that wish to be notified when a child
+ exits. */
+ if(!cp->OptionDetach)
+ {
+ if(!kwsysProcessesAdd(cp))
+ {
+ kwsysProcessCleanup(cp, 1);
+ return;
+ }
+ }
+
+ /* Setup the stderr pipe to be shared by all processes. */
+ {
+ /* Create the pipe. */
+ int p[2];
+ if(pipe(p KWSYSPE_VMS_NONBLOCK) < 0)
+ {
+ kwsysProcessCleanup(cp, 1);
+ return;
+ }
+
+ /* Store the pipe. */
+ cp->PipeReadEnds[KWSYSPE_PIPE_STDERR] = p[0];
+ si.StdErr = p[1];
+
+ /* Set close-on-exec flag on the pipe's ends. */
+ if((fcntl(p[0], F_SETFD, FD_CLOEXEC) < 0) ||
+ (fcntl(p[1], F_SETFD, FD_CLOEXEC) < 0))
+ {
+ kwsysProcessCleanup(cp, 1);
+ kwsysProcessCleanupDescriptor(&si.StdErr);
+ return;
+ }
+
+ /* Set to non-blocking in case select lies, or for the polling
+ implementation. */
+ if(!kwsysProcessSetNonBlocking(p[0]))
+ {
+ kwsysProcessCleanup(cp, 1);
+ kwsysProcessCleanupDescriptor(&si.StdErr);
+ return;
+ }
+ }
+
+ /* Replace the stderr pipe with a file if requested. In this case
+ the select call will report that stderr is closed immediately. */
+ if(cp->PipeFileSTDERR)
+ {
+ if(!kwsysProcessSetupOutputPipeFile(&si.StdErr, cp->PipeFileSTDERR))
+ {
+ kwsysProcessCleanup(cp, 1);
+ kwsysProcessCleanupDescriptor(&si.StdErr);
+ return;
+ }
+ }
+
+ /* Replace the stderr pipe with the parent's if requested. In this
+ case the select call will report that stderr is closed
+ immediately. */
+ if(cp->PipeSharedSTDERR)
+ {
+ kwsysProcessCleanupDescriptor(&si.StdErr);
+ si.StdErr = 2;
+ }
+
+ /* Replace the stderr pipe with the native pipe provided if any. In
+ this case the select call will report that stderr is closed
+ immediately. */
+ if(cp->PipeNativeSTDERR[1] >= 0)
+ {
+ if(!kwsysProcessSetupOutputPipeNative(&si.StdErr, cp->PipeNativeSTDERR))
+ {
+ kwsysProcessCleanup(cp, 1);
+ kwsysProcessCleanupDescriptor(&si.StdErr);
+ return;
+ }
+ }
+
+ /* The timeout period starts now. */
+ cp->StartTime = kwsysProcessTimeGetCurrent();
+ cp->TimeoutTime.tv_sec = -1;
+ cp->TimeoutTime.tv_usec = -1;
+
+ /* Create the pipeline of processes. */
+ {
+ int readEnd = -1;
+ int failed = 0;
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ if(!kwsysProcessCreate(cp, i, &si, &readEnd))
+ {
+ failed = 1;
+ }
+
+ /* Set the output pipe of the last process to be non-blocking in
+ case select lies, or for the polling implementation. */
+ if(i == (cp->NumberOfCommands-1) && !kwsysProcessSetNonBlocking(readEnd))
+ {
+ failed = 1;
+ }
+
+ if(failed)
+ {
+ kwsysProcessCleanup(cp, 1);
+
+ /* Release resources that may have been allocated for this
+ process before an error occurred. */
+ kwsysProcessCleanupDescriptor(&readEnd);
+ if(si.StdIn != 0)
+ {
+ kwsysProcessCleanupDescriptor(&si.StdIn);
+ }
+ if(si.StdOut != 1)
+ {
+ kwsysProcessCleanupDescriptor(&si.StdOut);
+ }
+ if(si.StdErr != 2)
+ {
+ kwsysProcessCleanupDescriptor(&si.StdErr);
+ }
+ kwsysProcessCleanupDescriptor(&si.ErrorPipe[0]);
+ kwsysProcessCleanupDescriptor(&si.ErrorPipe[1]);
+ return;
+ }
+ }
+ /* Save a handle to the output pipe for the last process. */
+ cp->PipeReadEnds[KWSYSPE_PIPE_STDOUT] = readEnd;
+ }
+
+ /* The parent process does not need the output pipe write ends. */
+ if(si.StdErr != 2)
+ {
+ kwsysProcessCleanupDescriptor(&si.StdErr);
+ }
+
+ /* Restore the working directory. */
+ if(cp->RealWorkingDirectory)
+ {
+ /* Some platforms specify that the chdir call may be
+ interrupted. Repeat the call until it finishes. */
+ while((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR));
+ free(cp->RealWorkingDirectory);
+ cp->RealWorkingDirectory = 0;
+ }
+
+ /* All the pipes are now open. */
+ cp->PipesLeft = KWSYSPE_PIPE_COUNT;
+
+ /* The process has now started. */
+ cp->State = kwsysProcess_State_Executing;
+ cp->Detached = cp->OptionDetach;
+}
+
+/*--------------------------------------------------------------------------*/
+kwsysEXPORT void kwsysProcess_Disown(kwsysProcess* cp)
+{
+ /* Make sure a detached child process is running. */
+ if(!cp || !cp->Detached || cp->State != kwsysProcess_State_Executing ||
+ cp->TimeoutExpired || cp->Killed)
+ {
+ return;
+ }
+
+ /* Close all the pipes safely. */
+ kwsysProcessClosePipes(cp);
+
+ /* We will not wait for exit, so cleanup now. */
+ kwsysProcessCleanup(cp, 0);
+
+ /* The process has been disowned. */
+ cp->State = kwsysProcess_State_Disowned;
+}
+
+/*--------------------------------------------------------------------------*/
+typedef struct kwsysProcessWaitData_s
+{
+ int Expired;
+ int PipeId;
+ int User;
+ double* UserTimeout;
+ kwsysProcessTime TimeoutTime;
+} kwsysProcessWaitData;
+static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length,
+ kwsysProcessWaitData* wd);
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
+ double* userTimeout)
+{
+ kwsysProcessTime userStartTime = {0, 0};
+ kwsysProcessWaitData wd =
+ {
+ 0,
+ kwsysProcess_Pipe_None,
+ 0,
+ 0,
+ {0, 0}
+ };
+ wd.UserTimeout = userTimeout;
+ /* Make sure we are executing a process. */
+ if(!cp || cp->State != kwsysProcess_State_Executing || cp->Killed ||
+ cp->TimeoutExpired)
+ {
+ return kwsysProcess_Pipe_None;
+ }
+
+ /* Record the time at which user timeout period starts. */
+ if(userTimeout)
+ {
+ userStartTime = kwsysProcessTimeGetCurrent();
+ }
+
+ /* Calculate the time at which a timeout will expire, and whether it
+ is the user or process timeout. */
+ wd.User = kwsysProcessGetTimeoutTime(cp, userTimeout,
+ &wd.TimeoutTime);
+
+ /* Data can only be available when pipes are open. If the process
+ is not running, cp->PipesLeft will be 0. */
+ while(cp->PipesLeft > 0 &&
+ !kwsysProcessWaitForPipe(cp, data, length, &wd)) {}
+
+ /* Update the user timeout. */
+ if(userTimeout)
+ {
+ kwsysProcessTime userEndTime = kwsysProcessTimeGetCurrent();
+ kwsysProcessTime difference = kwsysProcessTimeSubtract(userEndTime,
+ userStartTime);
+ double d = kwsysProcessTimeToDouble(difference);
+ *userTimeout -= d;
+ if(*userTimeout < 0)
+ {
+ *userTimeout = 0;
+ }
+ }
+
+ /* Check what happened. */
+ if(wd.PipeId)
+ {
+ /* Data are ready on a pipe. */
+ return wd.PipeId;
+ }
+ else if(wd.Expired)
+ {
+ /* A timeout has expired. */
+ if(wd.User)
+ {
+ /* The user timeout has expired. It has no time left. */
+ return kwsysProcess_Pipe_Timeout;
+ }
+ else
+ {
+ /* The process timeout has expired. Kill the children now. */
+ kwsysProcess_Kill(cp);
+ cp->Killed = 0;
+ cp->TimeoutExpired = 1;
+ return kwsysProcess_Pipe_None;
+ }
+ }
+ else
+ {
+ /* No pipes are left open. */
+ return kwsysProcess_Pipe_None;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length,
+ kwsysProcessWaitData* wd)
+{
+ int i;
+ kwsysProcessTimeNative timeoutLength;
+
+#if KWSYSPE_USE_SELECT
+ int numReady = 0;
+ int max = -1;
+ kwsysProcessTimeNative* timeout = 0;
+
+ /* Check for any open pipes with data reported ready by the last
+ call to select. According to "man select_tut" we must deal
+ with all descriptors reported by a call to select before
+ passing them to another select call. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ if(cp->PipeReadEnds[i] >= 0 &&
+ FD_ISSET(cp->PipeReadEnds[i], &cp->PipeSet))
+ {
+ kwsysProcess_ssize_t n;
+
+ /* We are handling this pipe now. Remove it from the set. */
+ FD_CLR(cp->PipeReadEnds[i], &cp->PipeSet);
+
+ /* The pipe is ready to read without blocking. Keep trying to
+ read until the operation is not interrupted. */
+ while(((n = read(cp->PipeReadEnds[i], cp->PipeBuffer,
+ KWSYSPE_PIPE_BUFFER_SIZE)) < 0) && (errno == EINTR));
+ if(n > 0)
+ {
+ /* We have data on this pipe. */
+ if(i == KWSYSPE_PIPE_SIGNAL)
+ {
+ /* A child process has terminated. */
+ kwsysProcessDestroy(cp);
+ }
+ else if(data && length)
+ {
+ /* Report this data. */
+ *data = cp->PipeBuffer;
+ *length = (int)(n);
+ switch(i)
+ {
+ case KWSYSPE_PIPE_STDOUT:
+ wd->PipeId = kwsysProcess_Pipe_STDOUT; break;
+ case KWSYSPE_PIPE_STDERR:
+ wd->PipeId = kwsysProcess_Pipe_STDERR; break;
+ };
+ return 1;
+ }
+ }
+ else if(n < 0 && errno == EAGAIN)
+ {
+ /* No data are really ready. The select call lied. See the
+ "man select" page on Linux for cases when this occurs. */
+ }
+ else
+ {
+ /* We are done reading from this pipe. */
+ kwsysProcessCleanupDescriptor(&cp->PipeReadEnds[i]);
+ --cp->PipesLeft;
+ }
+ }
+ }
+
+ /* If we have data, break early. */
+ if(wd->PipeId)
+ {
+ return 1;
+ }
+
+ /* Make sure the set is empty (it should always be empty here
+ anyway). */
+ FD_ZERO(&cp->PipeSet);
+
+ /* Setup a timeout if required. */
+ if(wd->TimeoutTime.tv_sec < 0)
+ {
+ timeout = 0;
+ }
+ else
+ {
+ timeout = &timeoutLength;
+ }
+ if(kwsysProcessGetTimeoutLeft(&wd->TimeoutTime,
+ wd->User?wd->UserTimeout:0,
+ &timeoutLength, 0))
+ {
+ /* Timeout has already expired. */
+ wd->Expired = 1;
+ return 1;
+ }
+
+ /* Add the pipe reading ends that are still open. */
+ max = -1;
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ if(cp->PipeReadEnds[i] >= 0)
+ {
+ FD_SET(cp->PipeReadEnds[i], &cp->PipeSet);
+ if(cp->PipeReadEnds[i] > max)
+ {
+ max = cp->PipeReadEnds[i];
+ }
+ }
+ }
+
+ /* Make sure we have a non-empty set. */
+ if(max < 0)
+ {
+ /* All pipes have closed. Child has terminated. */
+ return 1;
+ }
+
+ /* Run select to block until data are available. Repeat call
+ until it is not interrupted. */
+ while(((numReady = select(max+1, &cp->PipeSet, 0, 0, timeout)) < 0) &&
+ (errno == EINTR));
+
+ /* Check result of select. */
+ if(numReady == 0)
+ {
+ /* Select's timeout expired. */
+ wd->Expired = 1;
+ return 1;
+ }
+ else if(numReady < 0)
+ {
+ /* Select returned an error. Leave the error description in the
+ pipe buffer. */
+ strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
+
+ /* Kill the children now. */
+ kwsysProcess_Kill(cp);
+ cp->Killed = 0;
+ cp->SelectError = 1;
+ }
+
+ return 0;
+#else
+ /* Poll pipes for data since we do not have select. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ if(cp->PipeReadEnds[i] >= 0)
+ {
+ const int fd = cp->PipeReadEnds[i];
+ int n = read(fd, cp->PipeBuffer, KWSYSPE_PIPE_BUFFER_SIZE);
+ if(n > 0)
+ {
+ /* We have data on this pipe. */
+ if(i == KWSYSPE_PIPE_SIGNAL)
+ {
+ /* A child process has terminated. */
+ kwsysProcessDestroy(cp);
+ }
+ else if(data && length)
+ {
+ /* Report this data. */
+ *data = cp->PipeBuffer;
+ *length = n;
+ switch(i)
+ {
+ case KWSYSPE_PIPE_STDOUT:
+ wd->PipeId = kwsysProcess_Pipe_STDOUT; break;
+ case KWSYSPE_PIPE_STDERR:
+ wd->PipeId = kwsysProcess_Pipe_STDERR; break;
+ };
+ }
+ return 1;
+ }
+ else if (n == 0) /* EOF */
+ {
+ /* We are done reading from this pipe. */
+#if defined(__VMS)
+ if(!cp->CommandsLeft)
+#endif
+ {
+ kwsysProcessCleanupDescriptor(&cp->PipeReadEnds[i]);
+ --cp->PipesLeft;
+ }
+ }
+ else if (n < 0) /* error */
+ {
+#if defined(__VMS)
+ if(!cp->CommandsLeft)
+ {
+ kwsysProcessCleanupDescriptor(&cp->PipeReadEnds[i]);
+ --cp->PipesLeft;
+ }
+ else
+#endif
+ if((errno != EINTR) && (errno != EAGAIN))
+ {
+ strncpy(cp->ErrorMessage,strerror(errno),
+ KWSYSPE_PIPE_BUFFER_SIZE);
+ /* Kill the children now. */
+ kwsysProcess_Kill(cp);
+ cp->Killed = 0;
+ cp->SelectError = 1;
+ return 1;
+ }
+ }
+ }
+ }
+
+ /* If we have data, break early. */
+ if(wd->PipeId)
+ {
+ return 1;
+ }
+
+ if(kwsysProcessGetTimeoutLeft(&wd->TimeoutTime, wd->User?wd->UserTimeout:0,
+ &timeoutLength, 1))
+ {
+ /* Timeout has already expired. */
+ wd->Expired = 1;
+ return 1;
+ }
+
+ /* Sleep a little, try again. */
+ {
+ unsigned int msec = ((timeoutLength.tv_sec * 1000) +
+ (timeoutLength.tv_usec / 1000));
+ if (msec > 100000)
+ {
+ msec = 100000; /* do not sleep more than 100 milliseconds at a time */
+ }
+ kwsysProcess_usleep(msec);
+ }
+ return 0;
+#endif
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_WaitForExit(kwsysProcess* cp, double* userTimeout)
+{
+ int status = 0;
+ int prPipe = 0;
+
+ /* Make sure we are executing a process. */
+ if(!cp || cp->State != kwsysProcess_State_Executing)
+ {
+ return 1;
+ }
+
+ /* Wait for all the pipes to close. Ignore all data. */
+ while((prPipe = kwsysProcess_WaitForData(cp, 0, 0, userTimeout)) > 0)
+ {
+ if(prPipe == kwsysProcess_Pipe_Timeout)
+ {
+ return 0;
+ }
+ }
+
+ /* Check if there was an error in one of the waitpid calls. */
+ if(cp->State == kwsysProcess_State_Error)
+ {
+ /* The error message is already in its buffer. Tell
+ kwsysProcessCleanup to not create it. */
+ kwsysProcessCleanup(cp, 0);
+ return 1;
+ }
+
+ /* Check whether the child reported an error invoking the process. */
+ if(cp->SelectError)
+ {
+ /* The error message is already in its buffer. Tell
+ kwsysProcessCleanup to not create it. */
+ kwsysProcessCleanup(cp, 0);
+ cp->State = kwsysProcess_State_Error;
+ return 1;
+ }
+
+ /* Use the status of the last process in the pipeline. */
+ status = cp->CommandExitCodes[cp->NumberOfCommands-1];
+
+ /* Determine the outcome. */
+ if(cp->Killed)
+ {
+ /* We killed the child. */
+ cp->State = kwsysProcess_State_Killed;
+ }
+ else if(cp->TimeoutExpired)
+ {
+ /* The timeout expired. */
+ cp->State = kwsysProcess_State_Expired;
+ }
+ else if(WIFEXITED(status))
+ {
+ /* The child exited normally. */
+ cp->State = kwsysProcess_State_Exited;
+ cp->ExitException = kwsysProcess_Exception_None;
+ cp->ExitCode = status;
+ cp->ExitValue = (int)WEXITSTATUS(status);
+ }
+ else if(WIFSIGNALED(status))
+ {
+ /* The child received an unhandled signal. */
+ cp->State = kwsysProcess_State_Exception;
+ cp->ExitCode = status;
+ kwsysProcessSetExitException(cp, (int)WTERMSIG(status));
+ }
+ else
+ {
+ /* Error getting the child return code. */
+ strcpy(cp->ErrorMessage, "Error getting child return code.");
+ cp->State = kwsysProcess_State_Error;
+ }
+
+ /* Normal cleanup. */
+ kwsysProcessCleanup(cp, 0);
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_Kill(kwsysProcess* cp)
+{
+ int i;
+
+ /* Make sure we are executing a process. */
+ if(!cp || cp->State != kwsysProcess_State_Executing)
+ {
+ return;
+ }
+
+ /* First close the child exit report pipe write end to avoid causing a
+ SIGPIPE when the child terminates and our signal handler tries to
+ report it after we have already closed the read end. */
+ kwsysProcessCleanupDescriptor(&cp->SignalPipe);
+
+#if !defined(__APPLE__)
+ /* Close all the pipe read ends. Do this before killing the
+ children because Cygwin has problems killing processes that are
+ blocking to wait for writing to their output pipes. */
+ kwsysProcessClosePipes(cp);
+#endif
+
+ /* Kill the children. */
+ cp->Killed = 1;
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ int status;
+ if(cp->ForkPIDs[i])
+ {
+ /* Kill the child. */
+ kwsysProcessKill(cp->ForkPIDs[i]);
+
+ /* Reap the child. Keep trying until the call is not
+ interrupted. */
+ while((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && (errno == EINTR));
+ }
+ }
+
+#if defined(__APPLE__)
+ /* Close all the pipe read ends. Do this after killing the
+ children because OS X has problems closing pipe read ends whose
+ pipes are full and still have an open write end. */
+ kwsysProcessClosePipes(cp);
+#endif
+
+ cp->CommandsLeft = 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Initialize a process control structure for kwsysProcess_Execute. */
+static int kwsysProcessInitialize(kwsysProcess* cp)
+{
+ int i;
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ cp->PipeReadEnds[i] = -1;
+ }
+ cp->SignalPipe = -1;
+ cp->SelectError = 0;
+ cp->StartTime.tv_sec = -1;
+ cp->StartTime.tv_usec = -1;
+ cp->TimeoutTime.tv_sec = -1;
+ cp->TimeoutTime.tv_usec = -1;
+ cp->TimeoutExpired = 0;
+ cp->PipesLeft = 0;
+ cp->CommandsLeft = 0;
+#if KWSYSPE_USE_SELECT
+ FD_ZERO(&cp->PipeSet);
+#endif
+ cp->State = kwsysProcess_State_Starting;
+ cp->Killed = 0;
+ cp->ExitException = kwsysProcess_Exception_None;
+ cp->ExitCode = 1;
+ cp->ExitValue = 1;
+ cp->ErrorMessage[0] = 0;
+ strcpy(cp->ExitExceptionString, "No exception");
+
+ if(cp->ForkPIDs)
+ {
+ free(cp->ForkPIDs);
+ }
+ cp->ForkPIDs = (pid_t*)malloc(sizeof(pid_t)*(size_t)(cp->NumberOfCommands));
+ if(!cp->ForkPIDs)
+ {
+ return 0;
+ }
+ memset(cp->ForkPIDs, 0, sizeof(pid_t)*(size_t)(cp->NumberOfCommands));
+
+ if(cp->CommandExitCodes)
+ {
+ free(cp->CommandExitCodes);
+ }
+ cp->CommandExitCodes = (int*)malloc(sizeof(int)*
+ (size_t)(cp->NumberOfCommands));
+ if(!cp->CommandExitCodes)
+ {
+ return 0;
+ }
+ memset(cp->CommandExitCodes, 0, sizeof(int)*(size_t)(cp->NumberOfCommands));
+
+ /* Allocate memory to save the real working directory. */
+ if ( cp->WorkingDirectory )
+ {
+#if defined(MAXPATHLEN)
+ cp->RealWorkingDirectoryLength = MAXPATHLEN;
+#elif defined(PATH_MAX)
+ cp->RealWorkingDirectoryLength = PATH_MAX;
+#else
+ cp->RealWorkingDirectoryLength = 4096;
+#endif
+ cp->RealWorkingDirectory =
+ malloc((size_t)(cp->RealWorkingDirectoryLength));
+ if(!cp->RealWorkingDirectory)
+ {
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Free all resources used by the given kwsysProcess instance that were
+ allocated by kwsysProcess_Execute. */
+static void kwsysProcessCleanup(kwsysProcess* cp, int error)
+{
+ int i;
+
+ if(error)
+ {
+ /* We are cleaning up due to an error. Report the error message
+ if one has not been provided already. */
+ if(cp->ErrorMessage[0] == 0)
+ {
+ strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
+ }
+
+ /* Set the error state. */
+ cp->State = kwsysProcess_State_Error;
+
+ /* Kill any children already started. */
+ if(cp->ForkPIDs)
+ {
+ int status;
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ if(cp->ForkPIDs[i])
+ {
+ /* Kill the child. */
+ kwsysProcessKill(cp->ForkPIDs[i]);
+
+ /* Reap the child. Keep trying until the call is not
+ interrupted. */
+ while((waitpid(cp->ForkPIDs[i], &status, 0) < 0) &&
+ (errno == EINTR));
+ }
+ }
+ }
+
+ /* Restore the working directory. */
+ if(cp->RealWorkingDirectory)
+ {
+ while((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR));
+ }
+ }
+
+ /* If not creating a detached child, remove this object from the
+ global set of process objects that wish to be notified when a
+ child exits. */
+ if(!cp->OptionDetach)
+ {
+ kwsysProcessesRemove(cp);
+ }
+
+ /* Free memory. */
+ if(cp->ForkPIDs)
+ {
+ free(cp->ForkPIDs);
+ cp->ForkPIDs = 0;
+ }
+ if(cp->RealWorkingDirectory)
+ {
+ free(cp->RealWorkingDirectory);
+ cp->RealWorkingDirectory = 0;
+ }
+
+ /* Close pipe handles. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ kwsysProcessCleanupDescriptor(&cp->PipeReadEnds[i]);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+/* Close the given file descriptor if it is open. Reset its value to -1. */
+static void kwsysProcessCleanupDescriptor(int* pfd)
+{
+ if(pfd && *pfd >= 0)
+ {
+ /* Keep trying to close until it is not interrupted by a
+ * signal. */
+ while((close(*pfd) < 0) && (errno == EINTR));
+ *pfd = -1;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessClosePipes(kwsysProcess* cp)
+{
+ int i;
+
+ /* Close any pipes that are still open. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ if(cp->PipeReadEnds[i] >= 0)
+ {
+#if KWSYSPE_USE_SELECT
+ /* If the pipe was reported by the last call to select, we must
+ read from it. This is needed to satisfy the suggestions from
+ "man select_tut" and is not needed for the polling
+ implementation. Ignore the data. */
+ if(FD_ISSET(cp->PipeReadEnds[i], &cp->PipeSet))
+ {
+ /* We are handling this pipe now. Remove it from the set. */
+ FD_CLR(cp->PipeReadEnds[i], &cp->PipeSet);
+
+ /* The pipe is ready to read without blocking. Keep trying to
+ read until the operation is not interrupted. */
+ while((read(cp->PipeReadEnds[i], cp->PipeBuffer,
+ KWSYSPE_PIPE_BUFFER_SIZE) < 0) && (errno == EINTR));
+ }
+#endif
+
+ /* We are done reading from this pipe. */
+ kwsysProcessCleanupDescriptor(&cp->PipeReadEnds[i]);
+ --cp->PipesLeft;
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcessSetNonBlocking(int fd)
+{
+ int flags = fcntl(fd, F_GETFL);
+ if(flags >= 0)
+ {
+ flags = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+ }
+ return flags >= 0;
+}
+
+/*--------------------------------------------------------------------------*/
+#if defined(__VMS)
+int decc$set_child_standard_streams(int fd1, int fd2, int fd3);
+#endif
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcessCreate(kwsysProcess* cp, int prIndex,
+ kwsysProcessCreateInformation* si, int* readEnd)
+{
+ /* Setup the process's stdin. */
+ if(prIndex > 0)
+ {
+ si->StdIn = *readEnd;
+ *readEnd = 0;
+ }
+ else if(cp->PipeFileSTDIN)
+ {
+ /* Open a file for the child's stdin to read. */
+ si->StdIn = open(cp->PipeFileSTDIN, O_RDONLY);
+ if(si->StdIn < 0)
+ {
+ return 0;
+ }
+
+ /* Set close-on-exec flag on the pipe's end. */
+ if(fcntl(si->StdIn, F_SETFD, FD_CLOEXEC) < 0)
+ {
+ return 0;
+ }
+ }
+ else if(cp->PipeSharedSTDIN)
+ {
+ si->StdIn = 0;
+ }
+ else if(cp->PipeNativeSTDIN[0] >= 0)
+ {
+ si->StdIn = cp->PipeNativeSTDIN[0];
+
+ /* Set close-on-exec flag on the pipe's ends. The read end will
+ be dup2-ed into the stdin descriptor after the fork but before
+ the exec. */
+ if((fcntl(cp->PipeNativeSTDIN[0], F_SETFD, FD_CLOEXEC) < 0) ||
+ (fcntl(cp->PipeNativeSTDIN[1], F_SETFD, FD_CLOEXEC) < 0))
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ si->StdIn = -1;
+ }
+
+ /* Setup the process's stdout. */
+ {
+ /* Create the pipe. */
+ int p[2];
+ if(pipe(p KWSYSPE_VMS_NONBLOCK) < 0)
+ {
+ return 0;
+ }
+ *readEnd = p[0];
+ si->StdOut = p[1];
+
+ /* Set close-on-exec flag on the pipe's ends. */
+ if((fcntl(p[0], F_SETFD, FD_CLOEXEC) < 0) ||
+ (fcntl(p[1], F_SETFD, FD_CLOEXEC) < 0))
+ {
+ return 0;
+ }
+ }
+
+ /* Replace the stdout pipe with a file if requested. In this case
+ the select call will report that stdout is closed immediately. */
+ if(prIndex == cp->NumberOfCommands-1 && cp->PipeFileSTDOUT)
+ {
+ if(!kwsysProcessSetupOutputPipeFile(&si->StdOut, cp->PipeFileSTDOUT))
+ {
+ return 0;
+ }
+ }
+
+ /* Replace the stdout pipe with the parent's if requested. In this
+ case the select call will report that stderr is closed
+ immediately. */
+ if(prIndex == cp->NumberOfCommands-1 && cp->PipeSharedSTDOUT)
+ {
+ kwsysProcessCleanupDescriptor(&si->StdOut);
+ si->StdOut = 1;
+ }
+
+ /* Replace the stdout pipe with the native pipe provided if any. In
+ this case the select call will report that stdout is closed
+ immediately. */
+ if(prIndex == cp->NumberOfCommands-1 && cp->PipeNativeSTDOUT[1] >= 0)
+ {
+ if(!kwsysProcessSetupOutputPipeNative(&si->StdOut, cp->PipeNativeSTDOUT))
+ {
+ return 0;
+ }
+ }
+
+ /* Create the error reporting pipe. */
+ if(pipe(si->ErrorPipe) < 0)
+ {
+ return 0;
+ }
+
+ /* Set close-on-exec flag on the error pipe's write end. */
+ if(fcntl(si->ErrorPipe[1], F_SETFD, FD_CLOEXEC) < 0)
+ {
+ return 0;
+ }
+
+ /* Fork off a child process. */
+#if defined(__VMS)
+ /* VMS needs vfork and execvp to be in the same function because
+ they use setjmp/longjmp to run the child startup code in the
+ parent! TODO: OptionDetach. */
+ cp->ForkPIDs[prIndex] = vfork();
+#else
+ cp->ForkPIDs[prIndex] = kwsysProcessFork(cp, si);
+#endif
+ if(cp->ForkPIDs[prIndex] < 0)
+ {
+ return 0;
+ }
+
+ if(cp->ForkPIDs[prIndex] == 0)
+ {
+#if defined(__VMS)
+ /* Specify standard pipes for child process. */
+ decc$set_child_standard_streams(si->StdIn, si->StdOut, si->StdErr);
+#else
+ /* Close the read end of the error reporting pipe. */
+ close(si->ErrorPipe[0]);
+
+ /* Setup the stdin, stdout, and stderr pipes. */
+ if(si->StdIn > 0)
+ {
+ dup2(si->StdIn, 0);
+ }
+ else if(si->StdIn < 0)
+ {
+ close(0);
+ }
+ if(si->StdOut != 1)
+ {
+ dup2(si->StdOut, 1);
+ }
+ if(si->StdErr != 2)
+ {
+ dup2(si->StdErr, 2);
+ }
+
+ /* Clear the close-on-exec flag for stdin, stdout, and stderr.
+ All other pipe handles will be closed when exec succeeds. */
+ fcntl(0, F_SETFD, 0);
+ fcntl(1, F_SETFD, 0);
+ fcntl(2, F_SETFD, 0);
+
+ /* Restore all default signal handlers. */
+ kwsysProcessRestoreDefaultSignalHandlers();
+#endif
+
+ /* Execute the real process. If successful, this does not return. */
+ execvp(cp->Commands[prIndex][0], cp->Commands[prIndex]);
+ /* TODO: What does VMS do if the child fails to start? */
+
+ /* Failure. Report error to parent and terminate. */
+ kwsysProcessChildErrorExit(si->ErrorPipe[1]);
+ }
+
+#if defined(__VMS)
+ /* Restore the standard pipes of this process. */
+ decc$set_child_standard_streams(0, 1, 2);
+#endif
+
+ /* A child has been created. */
+ ++cp->CommandsLeft;
+
+ /* We are done with the error reporting pipe write end. */
+ kwsysProcessCleanupDescriptor(&si->ErrorPipe[1]);
+
+ /* Block until the child's exec call succeeds and closes the error
+ pipe or writes data to the pipe to report an error. */
+ {
+ kwsysProcess_ssize_t total = 0;
+ kwsysProcess_ssize_t n = 1;
+ /* Read the entire error message up to the length of our buffer. */
+ while(total < KWSYSPE_PIPE_BUFFER_SIZE && n > 0)
+ {
+ /* Keep trying to read until the operation is not interrupted. */
+ while(((n = read(si->ErrorPipe[0], cp->ErrorMessage+total,
+ (size_t)(KWSYSPE_PIPE_BUFFER_SIZE-total))) < 0) &&
+ (errno == EINTR));
+ if(n > 0)
+ {
+ total += n;
+ }
+ }
+
+ /* We are done with the error reporting pipe read end. */
+ kwsysProcessCleanupDescriptor(&si->ErrorPipe[0]);
+
+ if(total > 0)
+ {
+ /* The child failed to execute the process. */
+ return 0;
+ }
+ }
+
+ /* Successfully created this child process. */
+ if(prIndex > 0 || si->StdIn > 0)
+ {
+ /* The parent process does not need the input pipe read end. */
+ kwsysProcessCleanupDescriptor(&si->StdIn);
+ }
+
+ /* The parent process does not need the output pipe write ends. */
+ if(si->StdOut != 1)
+ {
+ kwsysProcessCleanupDescriptor(&si->StdOut);
+ }
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessDestroy(kwsysProcess* cp)
+{
+ /* A child process has terminated. Reap it if it is one handled by
+ this object. */
+ int i;
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ if(cp->ForkPIDs[i])
+ {
+ int result;
+ while(((result = waitpid(cp->ForkPIDs[i],
+ &cp->CommandExitCodes[i], WNOHANG)) < 0) &&
+ (errno == EINTR));
+ if(result > 0)
+ {
+ /* This child has termianted. */
+ cp->ForkPIDs[i] = 0;
+ if(--cp->CommandsLeft == 0)
+ {
+ /* All children have terminated. Close the signal pipe
+ write end so that no more notifications are sent to this
+ object. */
+ kwsysProcessCleanupDescriptor(&cp->SignalPipe);
+
+ /* TODO: Once the children have terminated, switch
+ WaitForData to use a non-blocking read to get the
+ rest of the data from the pipe. This is needed when
+ grandchildren keep the output pipes open. */
+ }
+ }
+ else if(result < 0 && cp->State != kwsysProcess_State_Error)
+ {
+ /* Unexpected error. Report the first time this happens. */
+ strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
+ cp->State = kwsysProcess_State_Error;
+ }
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcessSetupOutputPipeFile(int* p, const char* name)
+{
+ int fout;
+ if(!name)
+ {
+ return 1;
+ }
+
+ /* Close the existing descriptor. */
+ kwsysProcessCleanupDescriptor(p);
+
+ /* Open a file for the pipe to write. */
+ if((fout = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
+ {
+ return 0;
+ }
+
+ /* Set close-on-exec flag on the pipe's end. */
+ if(fcntl(fout, F_SETFD, FD_CLOEXEC) < 0)
+ {
+ return 0;
+ }
+
+ /* Assign the replacement descriptor. */
+ *p = fout;
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcessSetupOutputPipeNative(int* p, int des[2])
+{
+ /* Close the existing descriptor. */
+ kwsysProcessCleanupDescriptor(p);
+
+ /* Set close-on-exec flag on the pipe's ends. The proper end will
+ be dup2-ed into the standard descriptor number after fork but
+ before exec. */
+ if((fcntl(des[0], F_SETFD, FD_CLOEXEC) < 0) ||
+ (fcntl(des[1], F_SETFD, FD_CLOEXEC) < 0))
+ {
+ return 0;
+ }
+
+ /* Assign the replacement descriptor. */
+ *p = des[1];
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Get the time at which either the process or user timeout will
+ expire. Returns 1 if the user timeout is first, and 0 otherwise. */
+static int kwsysProcessGetTimeoutTime(kwsysProcess* cp, double* userTimeout,
+ kwsysProcessTime* timeoutTime)
+{
+ /* The first time this is called, we need to calculate the time at
+ which the child will timeout. */
+ if(cp->Timeout > 0 && cp->TimeoutTime.tv_sec < 0)
+ {
+ kwsysProcessTime length = kwsysProcessTimeFromDouble(cp->Timeout);
+ cp->TimeoutTime = kwsysProcessTimeAdd(cp->StartTime, length);
+ }
+
+ /* Start with process timeout. */
+ *timeoutTime = cp->TimeoutTime;
+
+ /* Check if the user timeout is earlier. */
+ if(userTimeout)
+ {
+ kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent();
+ kwsysProcessTime userTimeoutLength = kwsysProcessTimeFromDouble(*userTimeout);
+ kwsysProcessTime userTimeoutTime = kwsysProcessTimeAdd(currentTime,
+ userTimeoutLength);
+ if(timeoutTime->tv_sec < 0 ||
+ kwsysProcessTimeLess(userTimeoutTime, *timeoutTime))
+ {
+ *timeoutTime = userTimeoutTime;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Get the length of time before the given timeout time arrives.
+ Returns 1 if the time has already arrived, and 0 otherwise. */
+static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime,
+ double* userTimeout,
+ kwsysProcessTimeNative* timeoutLength,
+ int zeroIsExpired)
+{
+ if(timeoutTime->tv_sec < 0)
+ {
+ /* No timeout time has been requested. */
+ return 0;
+ }
+ else
+ {
+ /* Calculate the remaining time. */
+ kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent();
+ kwsysProcessTime timeLeft = kwsysProcessTimeSubtract(*timeoutTime,
+ currentTime);
+ if(timeLeft.tv_sec < 0 && userTimeout && *userTimeout <= 0)
+ {
+ /* Caller has explicitly requested a zero timeout. */
+ timeLeft.tv_sec = 0;
+ timeLeft.tv_usec = 0;
+ }
+
+ if(timeLeft.tv_sec < 0 ||
+ (timeLeft.tv_sec == 0 && timeLeft.tv_usec == 0 && zeroIsExpired))
+ {
+ /* Timeout has already expired. */
+ return 1;
+ }
+ else
+ {
+ /* There is some time left. */
+ timeoutLength->tv_sec = timeLeft.tv_sec;
+ timeoutLength->tv_usec = timeLeft.tv_usec;
+ return 0;
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static kwsysProcessTime kwsysProcessTimeGetCurrent(void)
+{
+ kwsysProcessTime current;
+ kwsysProcessTimeNative current_native;
+ gettimeofday(&current_native, 0);
+ current.tv_sec = (long)current_native.tv_sec;
+ current.tv_usec = (long)current_native.tv_usec;
+ return current;
+}
+
+/*--------------------------------------------------------------------------*/
+static double kwsysProcessTimeToDouble(kwsysProcessTime t)
+{
+ return (double)t.tv_sec + (double)(t.tv_usec)*0.000001;
+}
+
+/*--------------------------------------------------------------------------*/
+static kwsysProcessTime kwsysProcessTimeFromDouble(double d)
+{
+ kwsysProcessTime t;
+ t.tv_sec = (long)d;
+ t.tv_usec = (long)((d-(double)(t.tv_sec))*1000000);
+ return t;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcessTimeLess(kwsysProcessTime in1, kwsysProcessTime in2)
+{
+ return ((in1.tv_sec < in2.tv_sec) ||
+ ((in1.tv_sec == in2.tv_sec) && (in1.tv_usec < in2.tv_usec)));
+}
+
+/*--------------------------------------------------------------------------*/
+static kwsysProcessTime kwsysProcessTimeAdd(kwsysProcessTime in1, kwsysProcessTime in2)
+{
+ 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)
+ {
+ out.tv_usec -= 1000000;
+ out.tv_sec += 1;
+ }
+ return out;
+}
+
+/*--------------------------------------------------------------------------*/
+static kwsysProcessTime kwsysProcessTimeSubtract(kwsysProcessTime in1, kwsysProcessTime in2)
+{
+ kwsysProcessTime out;
+ out.tv_sec = in1.tv_sec - in2.tv_sec;
+ out.tv_usec = in1.tv_usec - in2.tv_usec;
+ if(out.tv_usec < 0)
+ {
+ out.tv_usec += 1000000;
+ out.tv_sec -= 1;
+ }
+ return out;
+}
+
+/*--------------------------------------------------------------------------*/
+#define KWSYSPE_CASE(type, str) \
+ cp->ExitException = kwsysProcess_Exception_##type; \
+ strcpy(cp->ExitExceptionString, str)
+static void kwsysProcessSetExitException(kwsysProcess* cp, int sig)
+{
+ switch (sig)
+ {
+#ifdef SIGSEGV
+ case SIGSEGV: KWSYSPE_CASE(Fault, "Segmentation fault"); break;
+#endif
+#ifdef SIGBUS
+# if !defined(SIGSEGV) || SIGBUS != SIGSEGV
+ case SIGBUS: KWSYSPE_CASE(Fault, "Bus error"); break;
+# endif
+#endif
+#ifdef SIGFPE
+ case SIGFPE: KWSYSPE_CASE(Numerical, "Floating-point exception"); break;
+#endif
+#ifdef SIGILL
+ case SIGILL: KWSYSPE_CASE(Illegal, "Illegal instruction"); break;
+#endif
+#ifdef SIGINT
+ case SIGINT: KWSYSPE_CASE(Interrupt, "User interrupt"); break;
+#endif
+#ifdef SIGABRT
+ case SIGABRT: KWSYSPE_CASE(Other, "Child aborted"); break;
+#endif
+#ifdef SIGKILL
+ case SIGKILL: KWSYSPE_CASE(Other, "Child killed"); break;
+#endif
+#ifdef SIGTERM
+ case SIGTERM: KWSYSPE_CASE(Other, "Child terminated"); break;
+#endif
+#ifdef SIGHUP
+ case SIGHUP: KWSYSPE_CASE(Other, "SIGHUP"); break;
+#endif
+#ifdef SIGQUIT
+ case SIGQUIT: KWSYSPE_CASE(Other, "SIGQUIT"); break;
+#endif
+#ifdef SIGTRAP
+ case SIGTRAP: KWSYSPE_CASE(Other, "SIGTRAP"); break;
+#endif
+#ifdef SIGIOT
+# if !defined(SIGABRT) || SIGIOT != SIGABRT
+ case SIGIOT: KWSYSPE_CASE(Other, "SIGIOT"); break;
+# endif
+#endif
+#ifdef SIGUSR1
+ case SIGUSR1: KWSYSPE_CASE(Other, "SIGUSR1"); break;
+#endif
+#ifdef SIGUSR2
+ case SIGUSR2: KWSYSPE_CASE(Other, "SIGUSR2"); break;
+#endif
+#ifdef SIGPIPE
+ case SIGPIPE: KWSYSPE_CASE(Other, "SIGPIPE"); break;
+#endif
+#ifdef SIGALRM
+ case SIGALRM: KWSYSPE_CASE(Other, "SIGALRM"); break;
+#endif
+#ifdef SIGSTKFLT
+ case SIGSTKFLT: KWSYSPE_CASE(Other, "SIGSTKFLT"); break;
+#endif
+#ifdef SIGCHLD
+ case SIGCHLD: KWSYSPE_CASE(Other, "SIGCHLD"); break;
+#elif defined(SIGCLD)
+ case SIGCLD: KWSYSPE_CASE(Other, "SIGCLD"); break;
+#endif
+#ifdef SIGCONT
+ case SIGCONT: KWSYSPE_CASE(Other, "SIGCONT"); break;
+#endif
+#ifdef SIGSTOP
+ case SIGSTOP: KWSYSPE_CASE(Other, "SIGSTOP"); break;
+#endif
+#ifdef SIGTSTP
+ case SIGTSTP: KWSYSPE_CASE(Other, "SIGTSTP"); break;
+#endif
+#ifdef SIGTTIN
+ case SIGTTIN: KWSYSPE_CASE(Other, "SIGTTIN"); break;
+#endif
+#ifdef SIGTTOU
+ case SIGTTOU: KWSYSPE_CASE(Other, "SIGTTOU"); break;
+#endif
+#ifdef SIGURG
+ case SIGURG: KWSYSPE_CASE(Other, "SIGURG"); break;
+#endif
+#ifdef SIGXCPU
+ case SIGXCPU: KWSYSPE_CASE(Other, "SIGXCPU"); break;
+#endif
+#ifdef SIGXFSZ
+ case SIGXFSZ: KWSYSPE_CASE(Other, "SIGXFSZ"); break;
+#endif
+#ifdef SIGVTALRM
+ case SIGVTALRM: KWSYSPE_CASE(Other, "SIGVTALRM"); break;
+#endif
+#ifdef SIGPROF
+ case SIGPROF: KWSYSPE_CASE(Other, "SIGPROF"); break;
+#endif
+#ifdef SIGWINCH
+ case SIGWINCH: KWSYSPE_CASE(Other, "SIGWINCH"); break;
+#endif
+#ifdef SIGPOLL
+ case SIGPOLL: KWSYSPE_CASE(Other, "SIGPOLL"); break;
+#endif
+#ifdef SIGIO
+# if !defined(SIGPOLL) || SIGIO != SIGPOLL
+ case SIGIO: KWSYSPE_CASE(Other, "SIGIO"); break;
+# endif
+#endif
+#ifdef SIGPWR
+ case SIGPWR: KWSYSPE_CASE(Other, "SIGPWR"); break;
+#endif
+#ifdef SIGSYS
+ case SIGSYS: KWSYSPE_CASE(Other, "SIGSYS"); break;
+#endif
+#ifdef SIGUNUSED
+# if !defined(SIGSYS) || SIGUNUSED != SIGSYS
+ case SIGUNUSED: KWSYSPE_CASE(Other, "SIGUNUSED"); break;
+# endif
+#endif
+ default:
+ cp->ExitException = kwsysProcess_Exception_Other;
+ sprintf(cp->ExitExceptionString, "Signal %d", sig);
+ break;
+ }
+}
+#undef KWSYSPE_CASE
+
+/*--------------------------------------------------------------------------*/
+/* When the child process encounters an error before its program is
+ invoked, this is called to report the error to the parent and
+ exit. */
+static void kwsysProcessChildErrorExit(int errorPipe)
+{
+ /* Construct the error message. */
+ char buffer[KWSYSPE_PIPE_BUFFER_SIZE];
+ kwsysProcess_ssize_t result;
+ strncpy(buffer, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
+
+ /* Report the error to the parent through the special pipe. */
+ result=write(errorPipe, buffer, strlen(buffer));
+ (void)result;
+
+ /* Terminate without cleanup. */
+ _exit(1);
+}
+
+/*--------------------------------------------------------------------------*/
+/* Restores all signal handlers to their default values. */
+static void kwsysProcessRestoreDefaultSignalHandlers(void)
+{
+ struct sigaction act;
+ memset(&act, 0, sizeof(struct sigaction));
+ act.sa_handler = SIG_DFL;
+#ifdef SIGHUP
+ sigaction(SIGHUP, &act, 0);
+#endif
+#ifdef SIGINT
+ sigaction(SIGINT, &act, 0);
+#endif
+#ifdef SIGQUIT
+ sigaction(SIGQUIT, &act, 0);
+#endif
+#ifdef SIGILL
+ sigaction(SIGILL, &act, 0);
+#endif
+#ifdef SIGTRAP
+ sigaction(SIGTRAP, &act, 0);
+#endif
+#ifdef SIGABRT
+ sigaction(SIGABRT, &act, 0);
+#endif
+#ifdef SIGIOT
+ sigaction(SIGIOT, &act, 0);
+#endif
+#ifdef SIGBUS
+ sigaction(SIGBUS, &act, 0);
+#endif
+#ifdef SIGFPE
+ sigaction(SIGFPE, &act, 0);
+#endif
+#ifdef SIGUSR1
+ sigaction(SIGUSR1, &act, 0);
+#endif
+#ifdef SIGSEGV
+ sigaction(SIGSEGV, &act, 0);
+#endif
+#ifdef SIGUSR2
+ sigaction(SIGUSR2, &act, 0);
+#endif
+#ifdef SIGPIPE
+ sigaction(SIGPIPE, &act, 0);
+#endif
+#ifdef SIGALRM
+ sigaction(SIGALRM, &act, 0);
+#endif
+#ifdef SIGTERM
+ sigaction(SIGTERM, &act, 0);
+#endif
+#ifdef SIGSTKFLT
+ sigaction(SIGSTKFLT, &act, 0);
+#endif
+#ifdef SIGCLD
+ sigaction(SIGCLD, &act, 0);
+#endif
+#ifdef SIGCHLD
+ sigaction(SIGCHLD, &act, 0);
+#endif
+#ifdef SIGCONT
+ sigaction(SIGCONT, &act, 0);
+#endif
+#ifdef SIGTSTP
+ sigaction(SIGTSTP, &act, 0);
+#endif
+#ifdef SIGTTIN
+ sigaction(SIGTTIN, &act, 0);
+#endif
+#ifdef SIGTTOU
+ sigaction(SIGTTOU, &act, 0);
+#endif
+#ifdef SIGURG
+ sigaction(SIGURG, &act, 0);
+#endif
+#ifdef SIGXCPU
+ sigaction(SIGXCPU, &act, 0);
+#endif
+#ifdef SIGXFSZ
+ sigaction(SIGXFSZ, &act, 0);
+#endif
+#ifdef SIGVTALRM
+ sigaction(SIGVTALRM, &act, 0);
+#endif
+#ifdef SIGPROF
+ sigaction(SIGPROF, &act, 0);
+#endif
+#ifdef SIGWINCH
+ sigaction(SIGWINCH, &act, 0);
+#endif
+#ifdef SIGPOLL
+ sigaction(SIGPOLL, &act, 0);
+#endif
+#ifdef SIGIO
+ sigaction(SIGIO, &act, 0);
+#endif
+#ifdef SIGPWR
+ sigaction(SIGPWR, &act, 0);
+#endif
+#ifdef SIGSYS
+ sigaction(SIGSYS, &act, 0);
+#endif
+#ifdef SIGUNUSED
+ sigaction(SIGUNUSED, &act, 0);
+#endif
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessExit(void)
+{
+ _exit(0);
+}
+
+/*--------------------------------------------------------------------------*/
+#if !defined(__VMS)
+static pid_t kwsysProcessFork(kwsysProcess* cp,
+ kwsysProcessCreateInformation* si)
+{
+ /* Create a detached process if requested. */
+ if(cp->OptionDetach)
+ {
+ /* Create an intermediate process. */
+ pid_t middle_pid = fork();
+ if(middle_pid < 0)
+ {
+ /* Fork failed. Return as if we were not detaching. */
+ return middle_pid;
+ }
+ else if(middle_pid == 0)
+ {
+ /* This is the intermediate process. Create the real child. */
+ pid_t child_pid = fork();
+ if(child_pid == 0)
+ {
+ /* This is the real child process. There is nothing to do here. */
+ return 0;
+ }
+ else
+ {
+ /* Use the error pipe to report the pid to the real parent. */
+ while((write(si->ErrorPipe[1], &child_pid, sizeof(child_pid)) < 0) &&
+ (errno == EINTR));
+
+ /* Exit without cleanup. The parent holds all resources. */
+ kwsysProcessExit();
+ return 0; /* Never reached, but avoids SunCC warning. */
+ }
+ }
+ else
+ {
+ /* This is the original parent process. The intermediate
+ process will use the error pipe to report the pid of the
+ detached child. */
+ pid_t child_pid;
+ int status;
+ while((read(si->ErrorPipe[0], &child_pid, sizeof(child_pid)) < 0) &&
+ (errno == EINTR));
+
+ /* Wait for the intermediate process to exit and clean it up. */
+ while((waitpid(middle_pid, &status, 0) < 0) && (errno == EINTR));
+ return child_pid;
+ }
+ }
+ else
+ {
+ /* Not creating a detached process. Use normal fork. */
+ return fork();
+ }
+}
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* We try to obtain process information by invoking the ps command.
+ Here we define the command to call on each platform and the
+ corresponding parsing format string. The parsing format should
+ have two integers to store: the pid and then the ppid. */
+#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) \
+ || defined(__OpenBSD__) || defined(__GLIBC__) || defined(__GNU__)
+# define KWSYSPE_PS_COMMAND "ps axo pid,ppid"
+# define KWSYSPE_PS_FORMAT "%d %d\n"
+#elif defined(__sun) && (defined(__SVR4) || defined(__svr4__)) /* Solaris */
+# define KWSYSPE_PS_COMMAND "ps -e -o pid,ppid"
+# define KWSYSPE_PS_FORMAT "%d %d\n"
+#elif defined(__hpux) || defined(__sun__) || defined(__sgi) || defined(_AIX) \
+ || defined(__sparc)
+# define KWSYSPE_PS_COMMAND "ps -ef"
+# define KWSYSPE_PS_FORMAT "%*s %d %d %*[^\n]\n"
+#elif defined(__QNX__)
+# define KWSYSPE_PS_COMMAND "ps -Af"
+# define KWSYSPE_PS_FORMAT "%*d %d %d %*[^\n]\n"
+#elif defined(__CYGWIN__)
+# define KWSYSPE_PS_COMMAND "ps aux"
+# define KWSYSPE_PS_FORMAT "%d %d %*[^\n]\n"
+#endif
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessKill(pid_t process_id)
+{
+#if defined(__linux__) || defined(__CYGWIN__)
+ DIR* procdir;
+#endif
+
+ /* Suspend the process to be sure it will not create more children. */
+ kill(process_id, SIGSTOP);
+
+#if defined(__CYGWIN__)
+ /* Some Cygwin versions seem to need help here. Give up our time slice
+ so that the child can process SIGSTOP before we send SIGKILL. */
+ usleep(1);
+#endif
+
+ /* Kill all children if we can find them. */
+#if defined(__linux__) || defined(__CYGWIN__)
+ /* First try using the /proc filesystem. */
+ if((procdir = opendir("/proc")) != NULL)
+ {
+#if defined(MAXPATHLEN)
+ char fname[MAXPATHLEN];
+#elif defined(PATH_MAX)
+ char fname[PATH_MAX];
+#else
+ char fname[4096];
+#endif
+ char buffer[KWSYSPE_PIPE_BUFFER_SIZE+1];
+ struct dirent* d;
+
+ /* Each process has a directory in /proc whose name is the pid.
+ Within this directory is a file called stat that has the
+ following format:
+
+ pid (command line) status ppid ...
+
+ We want to get the ppid for all processes. Those that have
+ process_id as their parent should be recursively killed. */
+ for(d = readdir(procdir); d; d = readdir(procdir))
+ {
+ int pid;
+ if(sscanf(d->d_name, "%d", &pid) == 1 && pid != 0)
+ {
+ struct stat finfo;
+ sprintf(fname, "/proc/%d/stat", pid);
+ if(stat(fname, &finfo) == 0)
+ {
+ FILE* f = fopen(fname, "r");
+ if(f)
+ {
+ size_t nread = fread(buffer, 1, KWSYSPE_PIPE_BUFFER_SIZE, f);
+ fclose(f);
+ buffer[nread] = '\0';
+ if(nread > 0)
+ {
+ const char* rparen = strrchr(buffer, ')');
+ int ppid;
+ if(rparen && (sscanf(rparen+1, "%*s %d", &ppid) == 1))
+ {
+ if(ppid == process_id)
+ {
+ /* Recursively kill this child and its children. */
+ kwsysProcessKill(pid);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ closedir(procdir);
+ }
+ else
+#endif
+ {
+#if defined(KWSYSPE_PS_COMMAND)
+ /* Try running "ps" to get the process information. */
+ FILE* ps = popen(KWSYSPE_PS_COMMAND, "r");
+
+ /* Make sure the process started and provided a valid header. */
+ if(ps && fscanf(ps, "%*[^\n]\n") != EOF)
+ {
+ /* Look for processes whose parent is the process being killed. */
+ int pid, ppid;
+ while(fscanf(ps, KWSYSPE_PS_FORMAT, &pid, &ppid) == 2)
+ {
+ if(ppid == process_id)
+ {
+ /* Recursively kill this child and its children. */
+ kwsysProcessKill(pid);
+ }
+ }
+ }
+
+ /* We are done with the ps process. */
+ if(ps)
+ {
+ pclose(ps);
+ }
+#endif
+ }
+
+ /* Kill the process. */
+ kill(process_id, SIGKILL);
+
+#if defined(__APPLE__)
+ /* On OS X 10.3 the above SIGSTOP occasionally prevents the SIGKILL
+ from working. Just in case, we resume the child and kill it
+ again. There is a small race condition in this obscure case. If
+ the child manages to fork again between these two signals, we
+ will not catch its children. */
+ kill(process_id, SIGCONT);
+ kill(process_id, SIGKILL);
+#endif
+}
+
+/*--------------------------------------------------------------------------*/
+#if defined(__VMS)
+int decc$feature_get_index(const char* name);
+int decc$feature_set_value(int index, int mode, int value);
+static int kwsysProcessSetVMSFeature(const char* name, int value)
+{
+ int i;
+ errno = 0;
+ i = decc$feature_get_index(name);
+ return i >= 0 && (decc$feature_set_value(i, 1, value) >= 0 || errno == 0);
+}
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* Global set of executing processes for use by the signal handler.
+ This global instance will be zero-initialized by the compiler. */
+typedef struct kwsysProcessInstances_s
+{
+ int Count;
+ int Size;
+ kwsysProcess** Processes;
+} kwsysProcessInstances;
+static kwsysProcessInstances kwsysProcesses;
+
+/* The old SIGCHLD handler. */
+static struct sigaction kwsysProcessesOldSigChldAction;
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessesUpdate(kwsysProcessInstances* newProcesses)
+{
+ /* Block SIGCHLD while we update the set of pipes to check.
+ TODO: sigprocmask is undefined for threaded apps. See
+ pthread_sigmask. */
+ sigset_t newset;
+ sigset_t oldset;
+ sigemptyset(&newset);
+ sigaddset(&newset, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &newset, &oldset);
+
+ /* Store the new set in that seen by the signal handler. */
+ kwsysProcesses = *newProcesses;
+
+ /* Restore the signal mask to the previous setting. */
+ sigprocmask(SIG_SETMASK, &oldset, 0);
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcessesAdd(kwsysProcess* cp)
+{
+ /* Create a pipe through which the signal handler can notify the
+ given process object that a child has exited. */
+ {
+ /* Create the pipe. */
+ int p[2];
+ if(pipe(p KWSYSPE_VMS_NONBLOCK) < 0)
+ {
+ return 0;
+ }
+
+ /* Store the pipes now to be sure they are cleaned up later. */
+ cp->PipeReadEnds[KWSYSPE_PIPE_SIGNAL] = p[0];
+ cp->SignalPipe = p[1];
+
+ /* Switch the pipe to non-blocking mode so that reading a byte can
+ be an atomic test-and-set. */
+ if(!kwsysProcessSetNonBlocking(p[0]) ||
+ !kwsysProcessSetNonBlocking(p[1]))
+ {
+ return 0;
+ }
+
+ /* The children do not need this pipe. Set close-on-exec flag on
+ the pipe's ends. */
+ if((fcntl(p[0], F_SETFD, FD_CLOEXEC) < 0) ||
+ (fcntl(p[1], F_SETFD, FD_CLOEXEC) < 0))
+ {
+ return 0;
+ }
+ }
+
+ /* Attempt to add the given signal pipe to the signal handler set. */
+ {
+
+ /* Make sure there is enough space for the new signal pipe. */
+ kwsysProcessInstances oldProcesses = kwsysProcesses;
+ kwsysProcessInstances newProcesses = oldProcesses;
+ if(oldProcesses.Count == oldProcesses.Size)
+ {
+ /* Start with enough space for a small number of process instances
+ and double the size each time more is needed. */
+ newProcesses.Size = oldProcesses.Size? oldProcesses.Size*2 : 4;
+
+ /* Try allocating the new block of memory. */
+ if((newProcesses.Processes = ((kwsysProcess**)
+ malloc((size_t)(newProcesses.Size)*
+ sizeof(kwsysProcess*)))))
+ {
+ /* Copy the old pipe set to the new memory. */
+ if(oldProcesses.Count > 0)
+ {
+ memcpy(newProcesses.Processes, oldProcesses.Processes,
+ ((size_t)(oldProcesses.Count) * sizeof(kwsysProcess*)));
+ }
+ }
+ else
+ {
+ /* Failed to allocate memory for the new signal pipe set. */
+ return 0;
+ }
+ }
+
+ /* Append the new signal pipe to the set. */
+ newProcesses.Processes[newProcesses.Count++] = cp;
+
+ /* Store the new set in that seen by the signal handler. */
+ kwsysProcessesUpdate(&newProcesses);
+
+ /* Free the original pipes if new ones were allocated. */
+ if(newProcesses.Processes != oldProcesses.Processes)
+ {
+ free(oldProcesses.Processes);
+ }
+
+ /* If this is the first process, enable the signal handler. */
+ if(newProcesses.Count == 1)
+ {
+ /* Install our handler for SIGCHLD. Repeat call until it is not
+ interrupted. */
+ struct sigaction newSigChldAction;
+ memset(&newSigChldAction, 0, sizeof(struct sigaction));
+#if KWSYSPE_USE_SIGINFO
+ newSigChldAction.sa_sigaction = kwsysProcessesSignalHandler;
+ newSigChldAction.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
+# ifdef SA_RESTART
+ newSigChldAction.sa_flags |= SA_RESTART;
+# endif
+#else
+ newSigChldAction.sa_handler = kwsysProcessesSignalHandler;
+ newSigChldAction.sa_flags = SA_NOCLDSTOP;
+#endif
+ while((sigaction(SIGCHLD, &newSigChldAction,
+ &kwsysProcessesOldSigChldAction) < 0) &&
+ (errno == EINTR));
+ }
+ }
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessesRemove(kwsysProcess* cp)
+{
+ /* Attempt to remove the given signal pipe from the signal handler set. */
+ {
+ /* Find the given process in the set. */
+ kwsysProcessInstances newProcesses = kwsysProcesses;
+ int i;
+ for(i=0; i < newProcesses.Count; ++i)
+ {
+ if(newProcesses.Processes[i] == cp)
+ {
+ break;
+ }
+ }
+ if(i < newProcesses.Count)
+ {
+ /* Remove the process from the set. */
+ --newProcesses.Count;
+ for(; i < newProcesses.Count; ++i)
+ {
+ newProcesses.Processes[i] = newProcesses.Processes[i+1];
+ }
+
+ /* If this was the last process, disable the signal handler. */
+ if(newProcesses.Count == 0)
+ {
+ /* Restore the SIGCHLD handler. Repeat call until it is not
+ interrupted. */
+ while((sigaction(SIGCHLD, &kwsysProcessesOldSigChldAction, 0) < 0) &&
+ (errno == EINTR));
+
+ /* Free the table of process pointers since it is now empty.
+ This is safe because the signal handler has been removed. */
+ newProcesses.Size = 0;
+ free(newProcesses.Processes);
+ newProcesses.Processes = 0;
+ }
+
+ /* Store the new set in that seen by the signal handler. */
+ kwsysProcessesUpdate(&newProcesses);
+ }
+ }
+
+ /* Close the pipe through which the signal handler may have notified
+ the given process object that a child has exited. */
+ kwsysProcessCleanupDescriptor(&cp->SignalPipe);
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessesSignalHandler(int signum
+#if KWSYSPE_USE_SIGINFO
+ , siginfo_t* info, void* ucontext
+#endif
+ )
+{
+ (void)signum;
+#if KWSYSPE_USE_SIGINFO
+ (void)info;
+ (void)ucontext;
+#endif
+
+ /* Signal all process objects that a child has terminated. */
+ {
+ int i;
+ for(i=0; i < kwsysProcesses.Count; ++i)
+ {
+ /* Set the pipe in a signalled state. */
+ char buf = 1;
+ kwsysProcess* cp = kwsysProcesses.Processes[i];
+ kwsysProcess_ssize_t status=
+ read(cp->PipeReadEnds[KWSYSPE_PIPE_SIGNAL], &buf, 1);
+ (void)status;
+ status=write(cp->SignalPipe, &buf, 1);
+ (void)status;
+ }
+ }
+
+#if !KWSYSPE_USE_SIGINFO
+ /* Re-Install our handler for SIGCHLD. Repeat call until it is not
+ interrupted. */
+ {
+ struct sigaction newSigChldAction;
+ memset(&newSigChldAction, 0, sizeof(struct sigaction));
+ newSigChldAction.sa_handler = kwsysProcessesSignalHandler;
+ newSigChldAction.sa_flags = SA_NOCLDSTOP;
+ while((sigaction(SIGCHLD, &newSigChldAction,
+ &kwsysProcessesOldSigChldAction) < 0) &&
+ (errno == EINTR));
+ }
+#endif
+}
diff --git a/Source/kwsys/ProcessWin32.c b/Source/kwsys/ProcessWin32.c
new file mode 100644
index 0000000000..ef71f26da6
--- /dev/null
+++ b/Source/kwsys/ProcessWin32.c
@@ -0,0 +1,2736 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Process.h)
+#include KWSYS_HEADER(System.h)
+#include KWSYS_HEADER(Encoding.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "Process.h.in"
+# include "System.h.in"
+# include "Encoding_c.h.in"
+#endif
+
+/*
+
+Implementation for Windows
+
+On windows, a thread is created to wait for data on each pipe. The
+threads are synchronized with the main thread to simulate the use of
+a UNIX-style select system call.
+
+*/
+
+#ifdef _MSC_VER
+#pragma warning (push, 1)
+#endif
+#include <windows.h> /* Windows API */
+#if defined(_MSC_VER) && _MSC_VER >= 1800
+# define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+#endif
+#include <string.h> /* strlen, strdup */
+#include <stdio.h> /* sprintf */
+#include <io.h> /* _unlink */
+#ifdef __WATCOMC__
+#define _unlink unlink
+#endif
+
+#ifndef _MAX_FNAME
+#define _MAX_FNAME 4096
+#endif
+#ifndef _MAX_PATH
+#define _MAX_PATH 4096
+#endif
+
+#ifdef _MSC_VER
+#pragma warning (pop)
+#pragma warning (disable: 4514)
+#pragma warning (disable: 4706)
+#endif
+
+#if defined(__BORLANDC__)
+# pragma warn -8004 /* assigned a value that is never used */
+# pragma warn -8060 /* Assignment inside if() condition. */
+#endif
+
+/* There are pipes for the process pipeline's stdout and stderr. */
+#define KWSYSPE_PIPE_COUNT 2
+#define KWSYSPE_PIPE_STDOUT 0
+#define KWSYSPE_PIPE_STDERR 1
+
+/* The maximum amount to read from a pipe at a time. */
+#define KWSYSPE_PIPE_BUFFER_SIZE 1024
+
+/* Debug output macro. */
+#if 0
+# define KWSYSPE_DEBUG(x) \
+( \
+ (void*)cp == (void*)0x00226DE0? \
+ ( \
+ fprintf(stderr, "%d/%p/%d ", (int)GetCurrentProcessId(), cp, __LINE__), \
+ fprintf x, \
+ fflush(stderr), \
+ 1 \
+ ) : (1) \
+)
+#else
+# define KWSYSPE_DEBUG(x) (void)1
+#endif
+
+typedef LARGE_INTEGER kwsysProcessTime;
+
+typedef struct kwsysProcessCreateInformation_s
+{
+ /* Windows child startup control data. */
+ STARTUPINFOW StartupInfo;
+} kwsysProcessCreateInformation;
+
+
+/*--------------------------------------------------------------------------*/
+typedef struct kwsysProcessPipeData_s kwsysProcessPipeData;
+static DWORD WINAPI kwsysProcessPipeThreadRead(LPVOID ptd);
+static void kwsysProcessPipeThreadReadPipe(kwsysProcess* cp,
+ kwsysProcessPipeData* td);
+static DWORD WINAPI kwsysProcessPipeThreadWake(LPVOID ptd);
+static void kwsysProcessPipeThreadWakePipe(kwsysProcess* cp,
+ kwsysProcessPipeData* td);
+static int kwsysProcessInitialize(kwsysProcess* cp);
+static int kwsysProcessCreate(kwsysProcess* cp, int index,
+ kwsysProcessCreateInformation* si,
+ PHANDLE readEnd);
+static void kwsysProcessDestroy(kwsysProcess* cp, int event);
+static int kwsysProcessSetupOutputPipeFile(PHANDLE handle, const char* name);
+static int kwsysProcessSetupSharedPipe(DWORD nStdHandle, PHANDLE handle);
+static int kwsysProcessSetupPipeNative(PHANDLE handle, HANDLE p[2],
+ int isWrite);
+static void kwsysProcessCleanupHandle(PHANDLE h);
+static void kwsysProcessCleanupHandleSafe(PHANDLE h, DWORD nStdHandle);
+static void kwsysProcessCleanup(kwsysProcess* cp, int error);
+static void kwsysProcessCleanErrorMessage(kwsysProcess* cp);
+static int kwsysProcessComputeCommandLength(kwsysProcess* cp,
+ char const* const* command);
+static void kwsysProcessComputeCommandLine(kwsysProcess* cp,
+ char const* const* command,
+ char* cmd);
+static int kwsysProcessGetTimeoutTime(kwsysProcess* cp, double* userTimeout,
+ kwsysProcessTime* timeoutTime);
+static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime,
+ double* userTimeout,
+ kwsysProcessTime* timeoutLength);
+static kwsysProcessTime kwsysProcessTimeGetCurrent(void);
+static DWORD kwsysProcessTimeToDWORD(kwsysProcessTime t);
+static double kwsysProcessTimeToDouble(kwsysProcessTime t);
+static kwsysProcessTime kwsysProcessTimeFromDouble(double d);
+static int kwsysProcessTimeLess(kwsysProcessTime in1, kwsysProcessTime in2);
+static kwsysProcessTime kwsysProcessTimeAdd(kwsysProcessTime in1, kwsysProcessTime in2);
+static kwsysProcessTime kwsysProcessTimeSubtract(kwsysProcessTime in1, kwsysProcessTime in2);
+static void kwsysProcessSetExitException(kwsysProcess* cp, int code);
+static void kwsysProcessKillTree(int pid);
+static void kwsysProcessDisablePipeThreads(kwsysProcess* cp);
+
+/*--------------------------------------------------------------------------*/
+/* A structure containing synchronization data for each thread. */
+typedef struct kwsysProcessPipeSync_s kwsysProcessPipeSync;
+struct kwsysProcessPipeSync_s
+{
+ /* Handle to the thread. */
+ HANDLE Thread;
+
+ /* Semaphore indicating to the thread that a process has started. */
+ HANDLE Ready;
+
+ /* Semaphore indicating to the thread that it should begin work. */
+ HANDLE Go;
+
+ /* Semaphore indicating thread has reset for another process. */
+ HANDLE Reset;
+};
+
+/*--------------------------------------------------------------------------*/
+/* A structure containing data for each pipe's threads. */
+struct kwsysProcessPipeData_s
+{
+ /* ------------- Data managed per instance of kwsysProcess ------------- */
+
+ /* Synchronization data for reading thread. */
+ kwsysProcessPipeSync Reader;
+
+ /* Synchronization data for waking thread. */
+ kwsysProcessPipeSync Waker;
+
+ /* Index of this pipe. */
+ int Index;
+
+ /* The kwsysProcess instance owning this pipe. */
+ kwsysProcess* Process;
+
+ /* ------------- Data managed per call to Execute ------------- */
+
+ /* Buffer for data read in this pipe's thread. */
+ char DataBuffer[KWSYSPE_PIPE_BUFFER_SIZE];
+
+ /* The length of the data stored in the buffer. */
+ DWORD DataLength;
+
+ /* Whether the pipe has been closed. */
+ int Closed;
+
+ /* Handle for the read end of this pipe. */
+ HANDLE Read;
+
+ /* Handle for the write end of this pipe. */
+ HANDLE Write;
+};
+
+/*--------------------------------------------------------------------------*/
+/* Structure containing data used to implement the child's execution. */
+struct kwsysProcess_s
+{
+ /* ------------- Data managed per instance of kwsysProcess ------------- */
+
+ /* The status of the process structure. */
+ int State;
+
+ /* The command lines to execute. */
+ wchar_t** Commands;
+ int NumberOfCommands;
+
+ /* The exit code of each command. */
+ DWORD* CommandExitCodes;
+
+ /* The working directory for the child process. */
+ wchar_t* WorkingDirectory;
+
+ /* Whether to create the child as a detached process. */
+ int OptionDetach;
+
+ /* Whether the child was created as a detached process. */
+ int Detached;
+
+ /* Whether to hide the child process's window. */
+ int HideWindow;
+
+ /* Whether to treat command lines as verbatim. */
+ int Verbatim;
+
+ /* Mutex to protect the shared index used by threads to report data. */
+ HANDLE SharedIndexMutex;
+
+ /* Semaphore used by threads to signal data ready. */
+ HANDLE Full;
+
+ /* Whether we are currently deleting this kwsysProcess instance. */
+ int Deleting;
+
+ /* Data specific to each pipe and its thread. */
+ kwsysProcessPipeData Pipe[KWSYSPE_PIPE_COUNT];
+
+ /* Name of files to which stdin and stdout pipes are attached. */
+ char* PipeFileSTDIN;
+ char* PipeFileSTDOUT;
+ char* PipeFileSTDERR;
+
+ /* Whether each pipe is shared with the parent process. */
+ int PipeSharedSTDIN;
+ int PipeSharedSTDOUT;
+ int PipeSharedSTDERR;
+
+ /* Native pipes provided by the user. */
+ HANDLE PipeNativeSTDIN[2];
+ HANDLE PipeNativeSTDOUT[2];
+ HANDLE PipeNativeSTDERR[2];
+
+ /* ------------- Data managed per call to Execute ------------- */
+
+ /* The exceptional behavior that terminated the process, if any. */
+ int ExitException;
+
+ /* The process exit code. */
+ DWORD ExitCode;
+
+ /* The process return code, if any. */
+ int ExitValue;
+
+ /* Index of last pipe to report data, if any. */
+ int CurrentIndex;
+
+ /* Index shared by threads to report data. */
+ int SharedIndex;
+
+ /* The timeout length. */
+ double Timeout;
+
+ /* Time at which the child started. */
+ kwsysProcessTime StartTime;
+
+ /* Time at which the child will timeout. Negative for no timeout. */
+ kwsysProcessTime TimeoutTime;
+
+ /* Flag for whether the process was killed. */
+ int Killed;
+
+ /* Flag for whether the timeout expired. */
+ int TimeoutExpired;
+
+ /* Flag for whether the process has terminated. */
+ int Terminated;
+
+ /* The number of pipes still open during execution and while waiting
+ for pipes to close after process termination. */
+ int PipesLeft;
+
+ /* Buffer for error messages. */
+ char ErrorMessage[KWSYSPE_PIPE_BUFFER_SIZE+1];
+
+ /* Description for the ExitException. */
+ char ExitExceptionString[KWSYSPE_PIPE_BUFFER_SIZE+1];
+
+ /* Windows process information data. */
+ PROCESS_INFORMATION* ProcessInformation;
+
+ /* Data and process termination events for which to wait. */
+ PHANDLE ProcessEvents;
+ int ProcessEventsLength;
+
+ /* Real working directory of our own process. */
+ DWORD RealWorkingDirectoryLength;
+ wchar_t* RealWorkingDirectory;
+};
+
+/*--------------------------------------------------------------------------*/
+kwsysProcess* kwsysProcess_New(void)
+{
+ int i;
+
+ /* Process control structure. */
+ kwsysProcess* cp;
+
+ /* Windows version number data. */
+ OSVERSIONINFO osv;
+
+ /* Allocate a process control structure. */
+ cp = (kwsysProcess*)malloc(sizeof(kwsysProcess));
+ if(!cp)
+ {
+ /* Could not allocate memory for the control structure. */
+ return 0;
+ }
+ ZeroMemory(cp, sizeof(*cp));
+
+ /* Share stdin with the parent process by default. */
+ cp->PipeSharedSTDIN = 1;
+
+ /* Set initial status. */
+ cp->State = kwsysProcess_State_Starting;
+
+ /* Choose a method of running the child based on version of
+ windows. */
+ ZeroMemory(&osv, sizeof(osv));
+ osv.dwOSVersionInfoSize = sizeof(osv);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (push)
+# pragma warning (disable:4996)
+#endif
+ GetVersionEx(&osv);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (pop)
+#endif
+ if(osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
+ {
+ /* Win9x no longer supported. */
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* Initially no thread owns the mutex. Initialize semaphore to 1. */
+ if(!(cp->SharedIndexMutex = CreateSemaphore(0, 1, 1, 0)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* Initially no data are available. Initialize semaphore to 0. */
+ if(!(cp->Full = CreateSemaphore(0, 0, 1, 0)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* Create the thread to read each pipe. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ DWORD dummy=0;
+
+ /* Assign the thread its index. */
+ cp->Pipe[i].Index = i;
+
+ /* Give the thread a pointer back to the kwsysProcess instance. */
+ cp->Pipe[i].Process = cp;
+
+ /* No process is yet running. Initialize semaphore to 0. */
+ if(!(cp->Pipe[i].Reader.Ready = CreateSemaphore(0, 0, 1, 0)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* The pipe is not yet reset. Initialize semaphore to 0. */
+ if(!(cp->Pipe[i].Reader.Reset = CreateSemaphore(0, 0, 1, 0)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* The thread's buffer is initially empty. Initialize semaphore to 1. */
+ if(!(cp->Pipe[i].Reader.Go = CreateSemaphore(0, 1, 1, 0)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* Create the reading thread. It will block immediately. The
+ thread will not make deeply nested calls, so we need only a
+ small stack. */
+ if(!(cp->Pipe[i].Reader.Thread = CreateThread(0, 1024,
+ kwsysProcessPipeThreadRead,
+ &cp->Pipe[i], 0, &dummy)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* No process is yet running. Initialize semaphore to 0. */
+ if(!(cp->Pipe[i].Waker.Ready = CreateSemaphore(0, 0, 1, 0)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* The pipe is not yet reset. Initialize semaphore to 0. */
+ if(!(cp->Pipe[i].Waker.Reset = CreateSemaphore(0, 0, 1, 0)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* The waker should not wake immediately. Initialize semaphore to 0. */
+ if(!(cp->Pipe[i].Waker.Go = CreateSemaphore(0, 0, 1, 0)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+
+ /* Create the waking thread. It will block immediately. The
+ thread will not make deeply nested calls, so we need only a
+ small stack. */
+ if(!(cp->Pipe[i].Waker.Thread = CreateThread(0, 1024,
+ kwsysProcessPipeThreadWake,
+ &cp->Pipe[i], 0, &dummy)))
+ {
+ kwsysProcess_Delete(cp);
+ return 0;
+ }
+ }
+
+ return cp;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_Delete(kwsysProcess* cp)
+{
+ int i;
+
+ /* Make sure we have an instance. */
+ if(!cp)
+ {
+ return;
+ }
+
+ /* If the process is executing, wait for it to finish. */
+ if(cp->State == kwsysProcess_State_Executing)
+ {
+ if(cp->Detached)
+ {
+ kwsysProcess_Disown(cp);
+ }
+ else
+ {
+ kwsysProcess_WaitForExit(cp, 0);
+ }
+ }
+
+ /* We are deleting the kwsysProcess instance. */
+ cp->Deleting = 1;
+
+ /* Terminate each of the threads. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ /* Terminate this reading thread. */
+ if(cp->Pipe[i].Reader.Thread)
+ {
+ /* Signal the thread we are ready for it. It will terminate
+ immediately since Deleting is set. */
+ ReleaseSemaphore(cp->Pipe[i].Reader.Ready, 1, 0);
+
+ /* Wait for the thread to exit. */
+ WaitForSingleObject(cp->Pipe[i].Reader.Thread, INFINITE);
+
+ /* Close the handle to the thread. */
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Reader.Thread);
+ }
+
+ /* Terminate this waking thread. */
+ if(cp->Pipe[i].Waker.Thread)
+ {
+ /* Signal the thread we are ready for it. It will terminate
+ immediately since Deleting is set. */
+ ReleaseSemaphore(cp->Pipe[i].Waker.Ready, 1, 0);
+
+ /* Wait for the thread to exit. */
+ WaitForSingleObject(cp->Pipe[i].Waker.Thread, INFINITE);
+
+ /* Close the handle to the thread. */
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Waker.Thread);
+ }
+
+ /* Cleanup the pipe's semaphores. */
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Reader.Ready);
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Reader.Go);
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Reader.Reset);
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Waker.Ready);
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Waker.Go);
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Waker.Reset);
+ }
+
+ /* Close the shared semaphores. */
+ kwsysProcessCleanupHandle(&cp->SharedIndexMutex);
+ kwsysProcessCleanupHandle(&cp->Full);
+
+ /* Free memory. */
+ kwsysProcess_SetCommand(cp, 0);
+ kwsysProcess_SetWorkingDirectory(cp, 0);
+ kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDIN, 0);
+ kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDOUT, 0);
+ kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDERR, 0);
+ if(cp->CommandExitCodes)
+ {
+ free(cp->CommandExitCodes);
+ }
+ free(cp);
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_SetCommand(kwsysProcess* cp, char const* const* command)
+{
+ int i;
+ if(!cp)
+ {
+ return 0;
+ }
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ free(cp->Commands[i]);
+ }
+ cp->NumberOfCommands = 0;
+ if(cp->Commands)
+ {
+ free(cp->Commands);
+ cp->Commands = 0;
+ }
+ if(command)
+ {
+ return kwsysProcess_AddCommand(cp, command);
+ }
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command)
+{
+ int newNumberOfCommands;
+ wchar_t** newCommands;
+
+ /* Make sure we have a command to add. */
+ if(!cp || !command || !*command)
+ {
+ return 0;
+ }
+
+
+ /* Allocate a new array for command pointers. */
+ newNumberOfCommands = cp->NumberOfCommands + 1;
+ if(!(newCommands = (wchar_t**)malloc(sizeof(wchar_t*) * newNumberOfCommands)))
+ {
+ /* Out of memory. */
+ return 0;
+ }
+
+ /* Copy any existing commands into the new array. */
+ {
+ int i;
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ newCommands[i] = cp->Commands[i];
+ }
+ }
+
+ /* We need to construct a single string representing the command
+ and its arguments. We will surround each argument containing
+ spaces with double-quotes. Inside a double-quoted argument, we
+ need to escape double-quotes and all backslashes before them.
+ We also need to escape backslashes at the end of an argument
+ because they come before the closing double-quote for the
+ argument. */
+ {
+ /* First determine the length of the final string. */
+ int length = kwsysProcessComputeCommandLength(cp, command);
+
+ /* Allocate enough space for the command. We do not need an extra
+ byte for the terminating null because we allocated a space for
+ the first argument that we will not use. */
+ char* new_cmd = malloc(length);
+ if(!new_cmd)
+ {
+ /* Out of memory. */
+ free(newCommands);
+ return 0;
+ }
+
+ /* Construct the command line in the allocated buffer. */
+ kwsysProcessComputeCommandLine(cp, command,
+ new_cmd);
+
+ newCommands[cp->NumberOfCommands] = kwsysEncoding_DupToWide(new_cmd);
+ free(new_cmd);
+ }
+
+
+ /* Save the new array of commands. */
+ free(cp->Commands);
+ cp->Commands = newCommands;
+ cp->NumberOfCommands = newNumberOfCommands;
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetTimeout(kwsysProcess* cp, double timeout)
+{
+ if(!cp)
+ {
+ return;
+ }
+ cp->Timeout = timeout;
+ if(cp->Timeout < 0)
+ {
+ cp->Timeout = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir)
+{
+ if(!cp)
+ {
+ return 0;
+ }
+ if(cp->WorkingDirectory)
+ {
+ free(cp->WorkingDirectory);
+ cp->WorkingDirectory = 0;
+ }
+ if(dir && dir[0])
+ {
+ wchar_t* wdir = kwsysEncoding_DupToWide(dir);
+ /* We must convert the working directory to a full path. */
+ DWORD length = GetFullPathNameW(wdir, 0, 0, 0);
+ if(length > 0)
+ {
+ wchar_t* work_dir = malloc(length*sizeof(wchar_t));
+ if(!work_dir)
+ {
+ free(wdir);
+ return 0;
+ }
+ if(!GetFullPathNameW(wdir, length, work_dir, 0))
+ {
+ free(work_dir);
+ free(wdir);
+ return 0;
+ }
+ cp->WorkingDirectory = work_dir;
+ }
+ free(wdir);
+ }
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_SetPipeFile(kwsysProcess* cp, int pipe, const char* file)
+{
+ char** pfile;
+ if(!cp)
+ {
+ return 0;
+ }
+ switch(pipe)
+ {
+ case kwsysProcess_Pipe_STDIN: pfile = &cp->PipeFileSTDIN; break;
+ case kwsysProcess_Pipe_STDOUT: pfile = &cp->PipeFileSTDOUT; break;
+ case kwsysProcess_Pipe_STDERR: pfile = &cp->PipeFileSTDERR; break;
+ default: return 0;
+ }
+ if(*pfile)
+ {
+ free(*pfile);
+ *pfile = 0;
+ }
+ if(file)
+ {
+ *pfile = (char*)malloc(strlen(file)+1);
+ if(!*pfile)
+ {
+ return 0;
+ }
+ strcpy(*pfile, file);
+ }
+
+ /* If we are redirecting the pipe, do not share it or use a native
+ pipe. */
+ if(*pfile)
+ {
+ kwsysProcess_SetPipeNative(cp, pipe, 0);
+ kwsysProcess_SetPipeShared(cp, pipe, 0);
+ }
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetPipeShared(kwsysProcess* cp, int pipe, int shared)
+{
+ if(!cp)
+ {
+ return;
+ }
+
+ switch(pipe)
+ {
+ case kwsysProcess_Pipe_STDIN: cp->PipeSharedSTDIN = shared?1:0; break;
+ case kwsysProcess_Pipe_STDOUT: cp->PipeSharedSTDOUT = shared?1:0; break;
+ case kwsysProcess_Pipe_STDERR: cp->PipeSharedSTDERR = shared?1:0; break;
+ default: return;
+ }
+
+ /* If we are sharing the pipe, do not redirect it to a file or use a
+ native pipe. */
+ if(shared)
+ {
+ kwsysProcess_SetPipeFile(cp, pipe, 0);
+ kwsysProcess_SetPipeNative(cp, pipe, 0);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetPipeNative(kwsysProcess* cp, int pipe, HANDLE p[2])
+{
+ HANDLE* pPipeNative = 0;
+
+ if(!cp)
+ {
+ return;
+ }
+
+ switch(pipe)
+ {
+ case kwsysProcess_Pipe_STDIN: pPipeNative = cp->PipeNativeSTDIN; break;
+ case kwsysProcess_Pipe_STDOUT: pPipeNative = cp->PipeNativeSTDOUT; break;
+ case kwsysProcess_Pipe_STDERR: pPipeNative = cp->PipeNativeSTDERR; break;
+ default: return;
+ }
+
+ /* Copy the native pipe handles provided. */
+ if(p)
+ {
+ pPipeNative[0] = p[0];
+ pPipeNative[1] = p[1];
+ }
+ else
+ {
+ pPipeNative[0] = 0;
+ pPipeNative[1] = 0;
+ }
+
+ /* If we are using a native pipe, do not share it or redirect it to
+ a file. */
+ if(p)
+ {
+ kwsysProcess_SetPipeFile(cp, pipe, 0);
+ kwsysProcess_SetPipeShared(cp, pipe, 0);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetOption(kwsysProcess* cp, int optionId)
+{
+ if(!cp)
+ {
+ return 0;
+ }
+
+ switch(optionId)
+ {
+ case kwsysProcess_Option_Detach: return cp->OptionDetach;
+ case kwsysProcess_Option_HideWindow: return cp->HideWindow;
+ case kwsysProcess_Option_Verbatim: return cp->Verbatim;
+ default: return 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetOption(kwsysProcess* cp, int optionId, int value)
+{
+ if(!cp)
+ {
+ return;
+ }
+
+ switch(optionId)
+ {
+ case kwsysProcess_Option_Detach: cp->OptionDetach = value; break;
+ case kwsysProcess_Option_HideWindow: cp->HideWindow = value; break;
+ case kwsysProcess_Option_Verbatim: cp->Verbatim = value; break;
+ default: break;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetState(kwsysProcess* cp)
+{
+ return cp? cp->State : kwsysProcess_State_Error;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetExitException(kwsysProcess* cp)
+{
+ return cp? cp->ExitException : kwsysProcess_Exception_Other;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetExitValue(kwsysProcess* cp)
+{
+ return cp? cp->ExitValue : -1;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_GetExitCode(kwsysProcess* cp)
+{
+ return cp? cp->ExitCode : 0;
+}
+
+/*--------------------------------------------------------------------------*/
+const char* kwsysProcess_GetErrorString(kwsysProcess* cp)
+{
+ if(!cp)
+ {
+ return "Process management structure could not be allocated";
+ }
+ else if(cp->State == kwsysProcess_State_Error)
+ {
+ return cp->ErrorMessage;
+ }
+ return "Success";
+}
+
+/*--------------------------------------------------------------------------*/
+const char* kwsysProcess_GetExceptionString(kwsysProcess* cp)
+{
+ if(!cp)
+ {
+ return "GetExceptionString called with NULL process management structure";
+ }
+ else if(cp->State == kwsysProcess_State_Exception)
+ {
+ return cp->ExitExceptionString;
+ }
+ return "No exception";
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_Execute(kwsysProcess* cp)
+{
+ int i;
+
+ /* Child startup control data. */
+ kwsysProcessCreateInformation si;
+
+ /* Do not execute a second time. */
+ if(!cp || cp->State == kwsysProcess_State_Executing)
+ {
+ return;
+ }
+
+ /* Make sure we have something to run. */
+ if(cp->NumberOfCommands < 1)
+ {
+ strcpy(cp->ErrorMessage, "No command");
+ cp->State = kwsysProcess_State_Error;
+ return;
+ }
+
+ /* Initialize the control structure for a new process. */
+ if(!kwsysProcessInitialize(cp))
+ {
+ strcpy(cp->ErrorMessage, "Out of memory");
+ cp->State = kwsysProcess_State_Error;
+ return;
+ }
+
+ /* Save the real working directory of this process and change to
+ the working directory for the child processes. This is needed
+ to make pipe file paths evaluate correctly. */
+ if(cp->WorkingDirectory)
+ {
+ if(!GetCurrentDirectoryW(cp->RealWorkingDirectoryLength,
+ cp->RealWorkingDirectory))
+ {
+ kwsysProcessCleanup(cp, 1);
+ return;
+ }
+ SetCurrentDirectoryW(cp->WorkingDirectory);
+ }
+
+ /* Initialize startup info data. */
+ ZeroMemory(&si, sizeof(si));
+ si.StartupInfo.cb = sizeof(si.StartupInfo);
+
+ /* Decide whether a child window should be shown. */
+ si.StartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
+ si.StartupInfo.wShowWindow =
+ (unsigned short)(cp->HideWindow?SW_HIDE:SW_SHOWDEFAULT);
+
+ /* Connect the child's output pipes to the threads. */
+ si.StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
+
+ /* Create stderr pipe to be shared by all processes in the pipeline.
+ Neither end is directly inherited. */
+ if(!CreatePipe(&cp->Pipe[KWSYSPE_PIPE_STDERR].Read,
+ &cp->Pipe[KWSYSPE_PIPE_STDERR].Write, 0, 0))
+ {
+ kwsysProcessCleanup(cp, 1);
+ return;
+ }
+
+ /* Create an inherited duplicate of the write end, but do not
+ close the non-inherited version. We need to keep it open
+ to use in waking up the pipe threads. */
+ if(!DuplicateHandle(GetCurrentProcess(), cp->Pipe[KWSYSPE_PIPE_STDERR].Write,
+ GetCurrentProcess(), &si.StartupInfo.hStdError,
+ 0, TRUE, DUPLICATE_SAME_ACCESS))
+ {
+ kwsysProcessCleanup(cp, 1);
+ kwsysProcessCleanupHandle(&si.StartupInfo.hStdError);
+ return;
+ }
+
+ /* Replace the stderr pipe with a file if requested. In this case
+ the pipe thread will still run but never report data. */
+ if(cp->PipeFileSTDERR)
+ {
+ if(!kwsysProcessSetupOutputPipeFile(&si.StartupInfo.hStdError,
+ cp->PipeFileSTDERR))
+ {
+ kwsysProcessCleanup(cp, 1);
+ kwsysProcessCleanupHandle(&si.StartupInfo.hStdError);
+ return;
+ }
+ }
+
+ /* Replace the stderr pipe with the parent process's if requested.
+ In this case the pipe thread will still run but never report
+ data. */
+ if(cp->PipeSharedSTDERR)
+ {
+ if(!kwsysProcessSetupSharedPipe(STD_ERROR_HANDLE,
+ &si.StartupInfo.hStdError))
+ {
+ kwsysProcessCleanup(cp, 1);
+ kwsysProcessCleanupHandleSafe(&si.StartupInfo.hStdError,
+ STD_ERROR_HANDLE);
+ return;
+ }
+ }
+
+ /* Replace the stderr pipe with the native pipe provided if any. In
+ this case the pipe thread will still run but never report
+ data. */
+ if(cp->PipeNativeSTDERR[1])
+ {
+ if(!kwsysProcessSetupPipeNative(&si.StartupInfo.hStdError,
+ cp->PipeNativeSTDERR, 1))
+ {
+ kwsysProcessCleanup(cp, 1);
+ kwsysProcessCleanupHandleSafe(&si.StartupInfo.hStdError,
+ STD_ERROR_HANDLE);
+ return;
+ }
+ }
+
+ /* Create the pipeline of processes. */
+ {
+ HANDLE readEnd = 0;
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ if(kwsysProcessCreate(cp, i, &si, &readEnd))
+ {
+ cp->ProcessEvents[i+1] = cp->ProcessInformation[i].hProcess;
+ }
+ else
+ {
+ kwsysProcessCleanup(cp, 1);
+
+ /* Release resources that may have been allocated for this
+ process before an error occurred. */
+ kwsysProcessCleanupHandle(&readEnd);
+ kwsysProcessCleanupHandleSafe(&si.StartupInfo.hStdInput,
+ STD_INPUT_HANDLE);
+ kwsysProcessCleanupHandleSafe(&si.StartupInfo.hStdOutput,
+ STD_OUTPUT_HANDLE);
+ kwsysProcessCleanupHandleSafe(&si.StartupInfo.hStdError,
+ STD_ERROR_HANDLE);
+ return;
+ }
+ }
+
+ /* Save a handle to the output pipe for the last process. */
+ cp->Pipe[KWSYSPE_PIPE_STDOUT].Read = readEnd;
+ }
+
+ /* Close the inherited handles to the stderr pipe shared by all
+ processes in the pipeline. The stdout and stdin pipes are not
+ shared among all children and are therefore closed by
+ kwsysProcessCreate after each child is created. */
+ kwsysProcessCleanupHandleSafe(&si.StartupInfo.hStdError, STD_ERROR_HANDLE);
+
+ /* Restore the working directory. */
+ if(cp->RealWorkingDirectory)
+ {
+ SetCurrentDirectoryW(cp->RealWorkingDirectory);
+ free(cp->RealWorkingDirectory);
+ cp->RealWorkingDirectory = 0;
+ }
+
+ /* The timeout period starts now. */
+ cp->StartTime = kwsysProcessTimeGetCurrent();
+ cp->TimeoutTime = kwsysProcessTimeFromDouble(-1);
+
+ /* All processes in the pipeline have been started in suspended
+ mode. Resume them all now. */
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ ResumeThread(cp->ProcessInformation[i].hThread);
+ }
+
+ /* ---- It is no longer safe to call kwsysProcessCleanup. ----- */
+ /* Tell the pipe threads that a process has started. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ ReleaseSemaphore(cp->Pipe[i].Reader.Ready, 1, 0);
+ ReleaseSemaphore(cp->Pipe[i].Waker.Ready, 1, 0);
+ }
+
+ /* We don't care about the children's main threads. */
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ kwsysProcessCleanupHandle(&cp->ProcessInformation[i].hThread);
+ }
+
+ /* No pipe has reported data. */
+ cp->CurrentIndex = KWSYSPE_PIPE_COUNT;
+ cp->PipesLeft = KWSYSPE_PIPE_COUNT;
+
+ /* The process has now started. */
+ cp->State = kwsysProcess_State_Executing;
+ cp->Detached = cp->OptionDetach;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_Disown(kwsysProcess* cp)
+{
+ int i;
+
+ /* Make sure we are executing a detached process. */
+ if(!cp || !cp->Detached || cp->State != kwsysProcess_State_Executing ||
+ cp->TimeoutExpired || cp->Killed || cp->Terminated)
+ {
+ return;
+ }
+
+ /* Disable the reading threads. */
+ kwsysProcessDisablePipeThreads(cp);
+
+ /* Wait for all pipe threads to reset. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ WaitForSingleObject(cp->Pipe[i].Reader.Reset, INFINITE);
+ WaitForSingleObject(cp->Pipe[i].Waker.Reset, INFINITE);
+ }
+
+ /* We will not wait for exit, so cleanup now. */
+ kwsysProcessCleanup(cp, 0);
+
+ /* The process has been disowned. */
+ cp->State = kwsysProcess_State_Disowned;
+}
+
+/*--------------------------------------------------------------------------*/
+
+int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
+ double* userTimeout)
+{
+ kwsysProcessTime userStartTime;
+ kwsysProcessTime timeoutLength;
+ kwsysProcessTime timeoutTime;
+ DWORD timeout;
+ int user;
+ int done = 0;
+ int expired = 0;
+ int pipeId = kwsysProcess_Pipe_None;
+ DWORD w;
+
+ /* Make sure we are executing a process. */
+ if(!cp || cp->State != kwsysProcess_State_Executing || cp->Killed ||
+ cp->TimeoutExpired)
+ {
+ return kwsysProcess_Pipe_None;
+ }
+
+ /* Record the time at which user timeout period starts. */
+ userStartTime = kwsysProcessTimeGetCurrent();
+
+ /* Calculate the time at which a timeout will expire, and whether it
+ is the user or process timeout. */
+ user = kwsysProcessGetTimeoutTime(cp, userTimeout, &timeoutTime);
+
+ /* Loop until we have a reason to return. */
+ while(!done && cp->PipesLeft > 0)
+ {
+ /* If we previously got data from a thread, let it know we are
+ done with the data. */
+ if(cp->CurrentIndex < KWSYSPE_PIPE_COUNT)
+ {
+ KWSYSPE_DEBUG((stderr, "releasing reader %d\n", cp->CurrentIndex));
+ ReleaseSemaphore(cp->Pipe[cp->CurrentIndex].Reader.Go, 1, 0);
+ cp->CurrentIndex = KWSYSPE_PIPE_COUNT;
+ }
+
+ /* Setup a timeout if required. */
+ if(kwsysProcessGetTimeoutLeft(&timeoutTime, user?userTimeout:0,
+ &timeoutLength))
+ {
+ /* Timeout has already expired. */
+ expired = 1;
+ break;
+ }
+ if(timeoutTime.QuadPart < 0)
+ {
+ timeout = INFINITE;
+ }
+ else
+ {
+ timeout = kwsysProcessTimeToDWORD(timeoutLength);
+ }
+
+ /* Wait for a pipe's thread to signal or a process to terminate. */
+ w = WaitForMultipleObjects(cp->ProcessEventsLength, cp->ProcessEvents,
+ 0, timeout);
+ if(w == WAIT_TIMEOUT)
+ {
+ /* Timeout has expired. */
+ expired = 1;
+ done = 1;
+ }
+ else if(w == WAIT_OBJECT_0)
+ {
+ /* Save the index of the reporting thread and release the mutex.
+ The thread will block until we signal its Empty mutex. */
+ cp->CurrentIndex = cp->SharedIndex;
+ ReleaseSemaphore(cp->SharedIndexMutex, 1, 0);
+
+ /* Data are available or a pipe closed. */
+ if(cp->Pipe[cp->CurrentIndex].Closed)
+ {
+ /* The pipe closed at the write end. Close the read end and
+ inform the wakeup thread it is done with this process. */
+ kwsysProcessCleanupHandle(&cp->Pipe[cp->CurrentIndex].Read);
+ ReleaseSemaphore(cp->Pipe[cp->CurrentIndex].Waker.Go, 1, 0);
+ KWSYSPE_DEBUG((stderr, "wakeup %d\n", cp->CurrentIndex));
+ --cp->PipesLeft;
+ }
+ else if(data && length)
+ {
+ /* Report this data. */
+ *data = cp->Pipe[cp->CurrentIndex].DataBuffer;
+ *length = cp->Pipe[cp->CurrentIndex].DataLength;
+ switch(cp->CurrentIndex)
+ {
+ case KWSYSPE_PIPE_STDOUT:
+ pipeId = kwsysProcess_Pipe_STDOUT; break;
+ case KWSYSPE_PIPE_STDERR:
+ pipeId = kwsysProcess_Pipe_STDERR; break;
+ }
+ done = 1;
+ }
+ }
+ else
+ {
+ /* A process has terminated. */
+ kwsysProcessDestroy(cp, w-WAIT_OBJECT_0);
+ }
+ }
+
+ /* Update the user timeout. */
+ if(userTimeout)
+ {
+ kwsysProcessTime userEndTime = kwsysProcessTimeGetCurrent();
+ kwsysProcessTime difference = kwsysProcessTimeSubtract(userEndTime,
+ userStartTime);
+ double d = kwsysProcessTimeToDouble(difference);
+ *userTimeout -= d;
+ if(*userTimeout < 0)
+ {
+ *userTimeout = 0;
+ }
+ }
+
+ /* Check what happened. */
+ if(pipeId)
+ {
+ /* Data are ready on a pipe. */
+ return pipeId;
+ }
+ else if(expired)
+ {
+ /* A timeout has expired. */
+ if(user)
+ {
+ /* The user timeout has expired. It has no time left. */
+ return kwsysProcess_Pipe_Timeout;
+ }
+ else
+ {
+ /* The process timeout has expired. Kill the child now. */
+ KWSYSPE_DEBUG((stderr, "killing child because timeout expired\n"));
+ kwsysProcess_Kill(cp);
+ cp->TimeoutExpired = 1;
+ cp->Killed = 0;
+ return kwsysProcess_Pipe_None;
+ }
+ }
+ else
+ {
+ /* The children have terminated and no more data are available. */
+ return kwsysProcess_Pipe_None;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcess_WaitForExit(kwsysProcess* cp, double* userTimeout)
+{
+ int i;
+ int pipe;
+
+ /* Make sure we are executing a process. */
+ if(!cp || cp->State != kwsysProcess_State_Executing)
+ {
+ return 1;
+ }
+
+ /* Wait for the process to terminate. Ignore all data. */
+ while((pipe = kwsysProcess_WaitForData(cp, 0, 0, userTimeout)) > 0)
+ {
+ if(pipe == kwsysProcess_Pipe_Timeout)
+ {
+ /* The user timeout has expired. */
+ return 0;
+ }
+ }
+
+ KWSYSPE_DEBUG((stderr, "no more data\n"));
+
+ /* When the last pipe closes in WaitForData, the loop terminates
+ without releasing the pipe's thread. Release it now. */
+ if(cp->CurrentIndex < KWSYSPE_PIPE_COUNT)
+ {
+ KWSYSPE_DEBUG((stderr, "releasing reader %d\n", cp->CurrentIndex));
+ ReleaseSemaphore(cp->Pipe[cp->CurrentIndex].Reader.Go, 1, 0);
+ cp->CurrentIndex = KWSYSPE_PIPE_COUNT;
+ }
+
+ /* Wait for all pipe threads to reset. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ KWSYSPE_DEBUG((stderr, "waiting reader reset %d\n", i));
+ WaitForSingleObject(cp->Pipe[i].Reader.Reset, INFINITE);
+ KWSYSPE_DEBUG((stderr, "waiting waker reset %d\n", i));
+ WaitForSingleObject(cp->Pipe[i].Waker.Reset, INFINITE);
+ }
+
+ /* ---- It is now safe again to call kwsysProcessCleanup. ----- */
+ /* Close all the pipes. */
+ kwsysProcessCleanup(cp, 0);
+
+ /* Determine the outcome. */
+ if(cp->Killed)
+ {
+ /* We killed the child. */
+ cp->State = kwsysProcess_State_Killed;
+ }
+ else if(cp->TimeoutExpired)
+ {
+ /* The timeout expired. */
+ cp->State = kwsysProcess_State_Expired;
+ }
+ else
+ {
+ /* The children exited. Report the outcome of the last process. */
+ cp->ExitCode = cp->CommandExitCodes[cp->NumberOfCommands-1];
+ if((cp->ExitCode & 0xF0000000) == 0xC0000000)
+ {
+ /* Child terminated due to exceptional behavior. */
+ cp->State = kwsysProcess_State_Exception;
+ cp->ExitValue = 1;
+ kwsysProcessSetExitException(cp, cp->ExitCode);
+ }
+ else
+ {
+ /* Child exited without exception. */
+ cp->State = kwsysProcess_State_Exited;
+ cp->ExitException = kwsysProcess_Exception_None;
+ cp->ExitValue = cp->ExitCode;
+ }
+ }
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_Kill(kwsysProcess* cp)
+{
+ int i;
+ /* Make sure we are executing a process. */
+ if(!cp || cp->State != kwsysProcess_State_Executing || cp->TimeoutExpired ||
+ cp->Killed)
+ {
+ KWSYSPE_DEBUG((stderr, "kill: child not executing\n"));
+ return;
+ }
+
+ /* Disable the reading threads. */
+ KWSYSPE_DEBUG((stderr, "kill: disabling pipe threads\n"));
+ kwsysProcessDisablePipeThreads(cp);
+
+ /* Skip actually killing the child if it has already terminated. */
+ if(cp->Terminated)
+ {
+ KWSYSPE_DEBUG((stderr, "kill: child already terminated\n"));
+ return;
+ }
+
+ /* Kill the children. */
+ cp->Killed = 1;
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ kwsysProcessKillTree(cp->ProcessInformation[i].dwProcessId);
+ // close the handle if we kill it
+ kwsysProcessCleanupHandle(&cp->ProcessInformation[i].hThread);
+ kwsysProcessCleanupHandle(&cp->ProcessInformation[i].hProcess);
+ }
+
+ /* We are killing the children and ignoring all data. Do not wait
+ for them to exit. */
+}
+
+/*--------------------------------------------------------------------------*/
+
+/*
+ Function executed for each pipe's thread. Argument is a pointer to
+ the kwsysProcessPipeData instance for this thread.
+*/
+DWORD WINAPI kwsysProcessPipeThreadRead(LPVOID ptd)
+{
+ kwsysProcessPipeData* td = (kwsysProcessPipeData*)ptd;
+ kwsysProcess* cp = td->Process;
+
+ /* Wait for a process to be ready. */
+ while((WaitForSingleObject(td->Reader.Ready, INFINITE), !cp->Deleting))
+ {
+ /* Read output from the process for this thread's pipe. */
+ kwsysProcessPipeThreadReadPipe(cp, td);
+
+ /* Signal the main thread we have reset for a new process. */
+ ReleaseSemaphore(td->Reader.Reset, 1, 0);
+ }
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+
+/*
+ Function called in each pipe's thread to handle data for one
+ execution of a subprocess.
+*/
+void kwsysProcessPipeThreadReadPipe(kwsysProcess* cp, kwsysProcessPipeData* td)
+{
+ /* Wait for space in the thread's buffer. */
+ while((KWSYSPE_DEBUG((stderr, "wait for read %d\n", td->Index)),
+ WaitForSingleObject(td->Reader.Go, INFINITE), !td->Closed))
+ {
+ KWSYSPE_DEBUG((stderr, "reading %d\n", td->Index));
+
+ /* Read data from the pipe. This may block until data are available. */
+ if(!ReadFile(td->Read, td->DataBuffer, KWSYSPE_PIPE_BUFFER_SIZE,
+ &td->DataLength, 0))
+ {
+ if(GetLastError() != ERROR_BROKEN_PIPE)
+ {
+ /* UNEXPECTED failure to read the pipe. */
+ }
+
+ /* The pipe closed. There are no more data to read. */
+ td->Closed = 1;
+ KWSYSPE_DEBUG((stderr, "read closed %d\n", td->Index));
+ }
+
+ KWSYSPE_DEBUG((stderr, "read %d\n", td->Index));
+
+ /* Wait for our turn to be handled by the main thread. */
+ WaitForSingleObject(cp->SharedIndexMutex, INFINITE);
+
+ KWSYSPE_DEBUG((stderr, "reporting read %d\n", td->Index));
+
+ /* Tell the main thread we have something to report. */
+ cp->SharedIndex = td->Index;
+ ReleaseSemaphore(cp->Full, 1, 0);
+ }
+
+ /* We were signalled to exit with our buffer empty. Reset the
+ mutex for a new process. */
+ KWSYSPE_DEBUG((stderr, "self releasing reader %d\n", td->Index));
+ ReleaseSemaphore(td->Reader.Go, 1, 0);
+}
+
+/*--------------------------------------------------------------------------*/
+
+/*
+ Function executed for each pipe's thread. Argument is a pointer to
+ the kwsysProcessPipeData instance for this thread.
+*/
+DWORD WINAPI kwsysProcessPipeThreadWake(LPVOID ptd)
+{
+ kwsysProcessPipeData* td = (kwsysProcessPipeData*)ptd;
+ kwsysProcess* cp = td->Process;
+
+ /* Wait for a process to be ready. */
+ while((WaitForSingleObject(td->Waker.Ready, INFINITE), !cp->Deleting))
+ {
+ /* Wait for a possible wakeup. */
+ kwsysProcessPipeThreadWakePipe(cp, td);
+
+ /* Signal the main thread we have reset for a new process. */
+ ReleaseSemaphore(td->Waker.Reset, 1, 0);
+ }
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+
+/*
+ Function called in each pipe's thread to handle reading thread
+ wakeup for one execution of a subprocess.
+*/
+void kwsysProcessPipeThreadWakePipe(kwsysProcess* cp, kwsysProcessPipeData* td)
+{
+ (void)cp;
+
+ /* Wait for a possible wake command. */
+ KWSYSPE_DEBUG((stderr, "wait for wake %d\n", td->Index));
+ WaitForSingleObject(td->Waker.Go, INFINITE);
+ KWSYSPE_DEBUG((stderr, "waking %d\n", td->Index));
+
+ /* If the pipe is not closed, we need to wake up the reading thread. */
+ if(!td->Closed)
+ {
+ DWORD dummy;
+ KWSYSPE_DEBUG((stderr, "waker %d writing byte\n", td->Index));
+ WriteFile(td->Write, "", 1, &dummy, 0);
+ KWSYSPE_DEBUG((stderr, "waker %d wrote byte\n", td->Index));
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+/* Initialize a process control structure for kwsysProcess_Execute. */
+int kwsysProcessInitialize(kwsysProcess* cp)
+{
+ /* Reset internal status flags. */
+ cp->TimeoutExpired = 0;
+ cp->Terminated = 0;
+ cp->Killed = 0;
+ cp->ExitException = kwsysProcess_Exception_None;
+ cp->ExitCode = 1;
+ cp->ExitValue = 1;
+
+ /* Reset error data. */
+ cp->ErrorMessage[0] = 0;
+ strcpy(cp->ExitExceptionString, "No exception");
+
+ /* Allocate process information for each process. */
+ cp->ProcessInformation =
+ (PROCESS_INFORMATION*)malloc(sizeof(PROCESS_INFORMATION) *
+ cp->NumberOfCommands);
+ if(!cp->ProcessInformation)
+ {
+ return 0;
+ }
+ ZeroMemory(cp->ProcessInformation,
+ sizeof(PROCESS_INFORMATION) * cp->NumberOfCommands);
+ if(cp->CommandExitCodes)
+ {
+ free(cp->CommandExitCodes);
+ }
+ cp->CommandExitCodes = (DWORD*)malloc(sizeof(DWORD)*cp->NumberOfCommands);
+ if(!cp->CommandExitCodes)
+ {
+ return 0;
+ }
+ ZeroMemory(cp->CommandExitCodes, sizeof(DWORD)*cp->NumberOfCommands);
+
+ /* Allocate event wait array. The first event is cp->Full, the rest
+ are the process termination events. */
+ cp->ProcessEvents = (PHANDLE)malloc(sizeof(HANDLE)*(cp->NumberOfCommands+1));
+ if(!cp->ProcessEvents)
+ {
+ return 0;
+ }
+ ZeroMemory(cp->ProcessEvents, sizeof(HANDLE) * (cp->NumberOfCommands+1));
+ cp->ProcessEvents[0] = cp->Full;
+ cp->ProcessEventsLength = cp->NumberOfCommands+1;
+
+ /* Allocate space to save the real working directory of this process. */
+ if(cp->WorkingDirectory)
+ {
+ cp->RealWorkingDirectoryLength = GetCurrentDirectoryW(0, 0);
+ if(cp->RealWorkingDirectoryLength > 0)
+ {
+ cp->RealWorkingDirectory = malloc(cp->RealWorkingDirectoryLength * sizeof(wchar_t));
+ if(!cp->RealWorkingDirectory)
+ {
+ return 0;
+ }
+ }
+ }
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcessCreate(kwsysProcess* cp, int index,
+ kwsysProcessCreateInformation* si,
+ PHANDLE readEnd)
+{
+ /* Setup the process's stdin. */
+ if(*readEnd)
+ {
+ /* Create an inherited duplicate of the read end from the output
+ pipe of the previous process. This also closes the
+ non-inherited version. */
+ if(!DuplicateHandle(GetCurrentProcess(), *readEnd,
+ GetCurrentProcess(), readEnd,
+ 0, TRUE, (DUPLICATE_CLOSE_SOURCE |
+ DUPLICATE_SAME_ACCESS)))
+ {
+ return 0;
+ }
+ si->StartupInfo.hStdInput = *readEnd;
+
+ /* This function is done with this handle. */
+ *readEnd = 0;
+ }
+ else if(cp->PipeFileSTDIN)
+ {
+ /* Create a handle to read a file for stdin. */
+ wchar_t* wstdin = kwsysEncoding_DupToWide(cp->PipeFileSTDIN);
+ HANDLE fin = CreateFileW(wstdin, GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ 0, OPEN_EXISTING, 0, 0);
+ free(wstdin);
+ if(fin == INVALID_HANDLE_VALUE)
+ {
+ return 0;
+ }
+ /* Create an inherited duplicate of the handle. This also closes
+ the non-inherited version. */
+ if(!DuplicateHandle(GetCurrentProcess(), fin,
+ GetCurrentProcess(), &fin,
+ 0, TRUE, (DUPLICATE_CLOSE_SOURCE |
+ DUPLICATE_SAME_ACCESS)))
+ {
+ return 0;
+ }
+ si->StartupInfo.hStdInput = fin;
+ }
+ else if(cp->PipeSharedSTDIN)
+ {
+ /* Share this process's stdin with the child. */
+ if(!kwsysProcessSetupSharedPipe(STD_INPUT_HANDLE,
+ &si->StartupInfo.hStdInput))
+ {
+ return 0;
+ }
+ }
+ else if(cp->PipeNativeSTDIN[0])
+ {
+ /* Use the provided native pipe. */
+ if(!kwsysProcessSetupPipeNative(&si->StartupInfo.hStdInput,
+ cp->PipeNativeSTDIN, 0))
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ /* Explicitly give the child no stdin. */
+ si->StartupInfo.hStdInput = INVALID_HANDLE_VALUE;
+ }
+
+ /* Setup the process's stdout. */
+ {
+ DWORD maybeClose = DUPLICATE_CLOSE_SOURCE;
+ HANDLE writeEnd;
+
+ /* Create the output pipe for this process. Neither end is directly
+ inherited. */
+ if(!CreatePipe(readEnd, &writeEnd, 0, 0))
+ {
+ return 0;
+ }
+
+ /* Create an inherited duplicate of the write end. Close the
+ non-inherited version unless this is the last process. Save the
+ non-inherited write end of the last process. */
+ if(index == cp->NumberOfCommands-1)
+ {
+ cp->Pipe[KWSYSPE_PIPE_STDOUT].Write = writeEnd;
+ maybeClose = 0;
+ }
+ if(!DuplicateHandle(GetCurrentProcess(), writeEnd,
+ GetCurrentProcess(), &writeEnd,
+ 0, TRUE, (maybeClose | DUPLICATE_SAME_ACCESS)))
+ {
+ return 0;
+ }
+ si->StartupInfo.hStdOutput = writeEnd;
+ }
+
+ /* Replace the stdout pipe with a file if requested. In this case
+ the pipe thread will still run but never report data. */
+ if(index == cp->NumberOfCommands-1 && cp->PipeFileSTDOUT)
+ {
+ if(!kwsysProcessSetupOutputPipeFile(&si->StartupInfo.hStdOutput,
+ cp->PipeFileSTDOUT))
+ {
+ return 0;
+ }
+ }
+
+ /* Replace the stdout pipe of the last child with the parent
+ process's if requested. In this case the pipe thread will still
+ run but never report data. */
+ if(index == cp->NumberOfCommands-1 && cp->PipeSharedSTDOUT)
+ {
+ if(!kwsysProcessSetupSharedPipe(STD_OUTPUT_HANDLE,
+ &si->StartupInfo.hStdOutput))
+ {
+ return 0;
+ }
+ }
+
+ /* Replace the stdout pipe with the native pipe provided if any. In
+ this case the pipe thread will still run but never report
+ data. */
+ if(index == cp->NumberOfCommands-1 && cp->PipeNativeSTDOUT[1])
+ {
+ if(!kwsysProcessSetupPipeNative(&si->StartupInfo.hStdOutput,
+ cp->PipeNativeSTDOUT, 1))
+ {
+ return 0;
+ }
+ }
+
+ /* Create the child in a suspended state so we can wait until all
+ children have been created before running any one. */
+ if(!CreateProcessW(0, cp->Commands[index], 0, 0, TRUE, CREATE_SUSPENDED, 0,
+ 0, &si->StartupInfo, &cp->ProcessInformation[index]))
+ {
+ return 0;
+ }
+
+ /* Successfully created this child process. Close the current
+ process's copies of the inherited stdout and stdin handles. The
+ stderr handle is shared among all children and is closed by
+ kwsysProcess_Execute after all children have been created. */
+ kwsysProcessCleanupHandleSafe(&si->StartupInfo.hStdInput,
+ STD_INPUT_HANDLE);
+ kwsysProcessCleanupHandleSafe(&si->StartupInfo.hStdOutput,
+ STD_OUTPUT_HANDLE);
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcessDestroy(kwsysProcess* cp, int event)
+{
+ int i;
+ int index;
+
+ /* Find the process index for the termination event. */
+ for(index=0; index < cp->NumberOfCommands; ++index)
+ {
+ if(cp->ProcessInformation[index].hProcess == cp->ProcessEvents[event])
+ {
+ break;
+ }
+ }
+
+ /* Check the exit code of the process. */
+ GetExitCodeProcess(cp->ProcessInformation[index].hProcess,
+ &cp->CommandExitCodes[index]);
+
+ /* Close the process handle for the terminated process. */
+ kwsysProcessCleanupHandle(&cp->ProcessInformation[index].hProcess);
+
+ /* Remove the process from the available events. */
+ cp->ProcessEventsLength -= 1;
+ for(i=event; i < cp->ProcessEventsLength; ++i)
+ {
+ cp->ProcessEvents[i] = cp->ProcessEvents[i+1];
+ }
+
+ /* Check if all processes have terminated. */
+ if(cp->ProcessEventsLength == 1)
+ {
+ cp->Terminated = 1;
+
+ /* Close our copies of the pipe write handles so the pipe threads
+ can detect end-of-data. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ /* TODO: If the child created its own child (our grandchild)
+ which inherited a copy of the pipe write-end then the pipe
+ may not close and we will still need the waker write pipe.
+ However we still want to be able to detect end-of-data in the
+ normal case. The reader thread will have to switch to using
+ PeekNamedPipe to read the last bit of data from the pipe
+ without blocking. This is equivalent to using a non-blocking
+ read on posix. */
+ KWSYSPE_DEBUG((stderr, "closing wakeup write %d\n", i));
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Write);
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcessSetupOutputPipeFile(PHANDLE phandle, const char* name)
+{
+ HANDLE fout;
+ wchar_t* wname;
+ if(!name)
+ {
+ return 1;
+ }
+
+ /* Close the existing inherited handle. */
+ kwsysProcessCleanupHandle(phandle);
+
+ /* Create a handle to write a file for the pipe. */
+ wname = kwsysEncoding_DupToWide(name);
+ fout = CreateFileW(wname, GENERIC_WRITE, FILE_SHARE_READ, 0,
+ CREATE_ALWAYS, 0, 0);
+ free(wname);
+ if(fout == INVALID_HANDLE_VALUE)
+ {
+ return 0;
+ }
+
+ /* Create an inherited duplicate of the handle. This also closes
+ the non-inherited version. */
+ if(!DuplicateHandle(GetCurrentProcess(), fout,
+ GetCurrentProcess(), &fout,
+ 0, TRUE, (DUPLICATE_CLOSE_SOURCE |
+ DUPLICATE_SAME_ACCESS)))
+ {
+ return 0;
+ }
+
+ /* Assign the replacement handle. */
+ *phandle = fout;
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcessSetupSharedPipe(DWORD nStdHandle, PHANDLE handle)
+{
+ /* Check whether the handle to be shared is already inherited. */
+ DWORD flags;
+ int inherited = 0;
+ if(GetHandleInformation(GetStdHandle(nStdHandle), &flags) &&
+ (flags & HANDLE_FLAG_INHERIT))
+ {
+ inherited = 1;
+ }
+
+ /* Cleanup the previous handle. */
+ kwsysProcessCleanupHandle(handle);
+
+ /* If the standard handle is not inherited then duplicate it to
+ create an inherited copy. Do not close the original handle when
+ duplicating! */
+ if(inherited)
+ {
+ *handle = GetStdHandle(nStdHandle);
+ return 1;
+ }
+ else if(DuplicateHandle(GetCurrentProcess(), GetStdHandle(nStdHandle),
+ GetCurrentProcess(), handle,
+ 0, TRUE, DUPLICATE_SAME_ACCESS))
+ {
+ return 1;
+ }
+ else
+ {
+ /* The given standard handle is not valid for this process. Some
+ child processes may break if they do not have a valid standard
+ pipe, so give the child an empty pipe. For the stdin pipe we
+ want to close the write end and give the read end to the child.
+ For stdout and stderr we want to close the read end and give
+ the write end to the child. */
+ int child_end = (nStdHandle == STD_INPUT_HANDLE)? 0:1;
+ int parent_end = (nStdHandle == STD_INPUT_HANDLE)? 1:0;
+ HANDLE emptyPipe[2];
+ if(!CreatePipe(&emptyPipe[0], &emptyPipe[1], 0, 0))
+ {
+ return 0;
+ }
+
+ /* Close the non-inherited end so the pipe will be broken
+ immediately. */
+ CloseHandle(emptyPipe[parent_end]);
+
+ /* Create an inherited duplicate of the handle. This also
+ closes the non-inherited version. */
+ if(!DuplicateHandle(GetCurrentProcess(), emptyPipe[child_end],
+ GetCurrentProcess(), &emptyPipe[child_end],
+ 0, TRUE, (DUPLICATE_CLOSE_SOURCE |
+ DUPLICATE_SAME_ACCESS)))
+ {
+ return 0;
+ }
+
+ /* Give the inherited handle to the child. */
+ *handle = emptyPipe[child_end];
+ return 1;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcessSetupPipeNative(PHANDLE handle, HANDLE p[2], int isWrite)
+{
+ /* Close the existing inherited handle. */
+ kwsysProcessCleanupHandle(handle);
+
+ /* Create an inherited duplicate of the handle. This also closes
+ the non-inherited version. */
+ if(!DuplicateHandle(GetCurrentProcess(), p[isWrite? 1:0],
+ GetCurrentProcess(), handle,
+ 0, TRUE, (DUPLICATE_CLOSE_SOURCE |
+ DUPLICATE_SAME_ACCESS)))
+ {
+ return 0;
+ }
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+
+/* Close the given handle if it is open. Reset its value to 0. */
+void kwsysProcessCleanupHandle(PHANDLE h)
+{
+ if(h && *h)
+ {
+ CloseHandle(*h);
+ *h = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+
+/* Close the given handle if it is open and not a standard handle.
+ Reset its value to 0. */
+void kwsysProcessCleanupHandleSafe(PHANDLE h, DWORD nStdHandle)
+{
+ if(h && *h && (*h != GetStdHandle(nStdHandle)))
+ {
+ CloseHandle(*h);
+ *h = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+
+/* Close all handles created by kwsysProcess_Execute. */
+void kwsysProcessCleanup(kwsysProcess* cp, int error)
+{
+ int i;
+ /* If this is an error case, report the error. */
+ if(error)
+ {
+ /* Construct an error message if one has not been provided already. */
+ if(cp->ErrorMessage[0] == 0)
+ {
+ /* Format the error message. */
+ DWORD original = GetLastError();
+ wchar_t err_msg[KWSYSPE_PIPE_BUFFER_SIZE];
+ DWORD length = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS, 0, original,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ err_msg, KWSYSPE_PIPE_BUFFER_SIZE, 0);
+ WideCharToMultiByte(CP_UTF8, 0, err_msg, -1, cp->ErrorMessage,
+ KWSYSPE_PIPE_BUFFER_SIZE, NULL, NULL);
+ if(length < 1)
+ {
+ /* FormatMessage failed. Use a default message. */
+ _snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE,
+ "Process execution failed with error 0x%X. "
+ "FormatMessage failed with error 0x%X",
+ original, GetLastError());
+ }
+ }
+
+ /* Remove trailing period and newline, if any. */
+ kwsysProcessCleanErrorMessage(cp);
+
+ /* Set the error state. */
+ cp->State = kwsysProcess_State_Error;
+
+ /* Cleanup any processes already started in a suspended state. */
+ if(cp->ProcessInformation)
+ {
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ if(cp->ProcessInformation[i].hProcess)
+ {
+ TerminateProcess(cp->ProcessInformation[i].hProcess, 255);
+ WaitForSingleObject(cp->ProcessInformation[i].hProcess, INFINITE);
+ }
+ }
+ for(i=0; i < cp->NumberOfCommands; ++i)
+ {
+ kwsysProcessCleanupHandle(&cp->ProcessInformation[i].hThread);
+ kwsysProcessCleanupHandle(&cp->ProcessInformation[i].hProcess);
+ }
+ }
+
+ /* Restore the working directory. */
+ if(cp->RealWorkingDirectory)
+ {
+ SetCurrentDirectoryW(cp->RealWorkingDirectory);
+ }
+ }
+
+ /* Free memory. */
+ if(cp->ProcessInformation)
+ {
+ free(cp->ProcessInformation);
+ cp->ProcessInformation = 0;
+ }
+ if(cp->ProcessEvents)
+ {
+ free(cp->ProcessEvents);
+ cp->ProcessEvents = 0;
+ }
+ if(cp->RealWorkingDirectory)
+ {
+ free(cp->RealWorkingDirectory);
+ cp->RealWorkingDirectory = 0;
+ }
+
+ /* Close each pipe. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Write);
+ kwsysProcessCleanupHandle(&cp->Pipe[i].Read);
+ cp->Pipe[i].Closed = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcessCleanErrorMessage(kwsysProcess* cp)
+{
+ /* Remove trailing period and newline, if any. */
+ size_t length = strlen(cp->ErrorMessage);
+ if(cp->ErrorMessage[length-1] == '\n')
+ {
+ cp->ErrorMessage[length-1] = 0;
+ --length;
+ if(length > 0 && cp->ErrorMessage[length-1] == '\r')
+ {
+ cp->ErrorMessage[length-1] = 0;
+ --length;
+ }
+ }
+ if(length > 0 && cp->ErrorMessage[length-1] == '.')
+ {
+ cp->ErrorMessage[length-1] = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcessComputeCommandLength(kwsysProcess* cp,
+ char const* const* command)
+{
+ int length = 0;
+ if(cp->Verbatim)
+ {
+ /* Treat the first argument as a verbatim command line. Use its
+ length directly and add space for the null-terminator. */
+ length = (int)strlen(*command)+1;
+ }
+ else
+ {
+ /* Compute the length of the command line when it is converted to
+ a single string. Space for the null-terminator is allocated by
+ the whitespace character allocated for the first argument that
+ will not be used. */
+ char const* const* arg;
+ for(arg = command; *arg; ++arg)
+ {
+ /* Add the length of this argument. It already includes room
+ for a separating space or terminating null. */
+ length += kwsysSystem_Shell_GetArgumentSizeForWindows(*arg, 0);
+ }
+ }
+
+ return length;
+}
+
+/*--------------------------------------------------------------------------*/
+void kwsysProcessComputeCommandLine(kwsysProcess* cp,
+ char const* const* command,
+ char* cmd)
+{
+ if(cp->Verbatim)
+ {
+ /* Copy the verbatim command line into the buffer. */
+ strcpy(cmd, *command);
+ }
+ else
+ {
+ /* Construct the command line in the allocated buffer. */
+ char const* const* arg;
+ for(arg = command; *arg; ++arg)
+ {
+ /* Add the separating space if this is not the first argument. */
+ if(arg != command)
+ {
+ *cmd++ = ' ';
+ }
+
+ /* Add the current argument. */
+ cmd = kwsysSystem_Shell_GetArgumentForWindows(*arg, cmd, 0);
+ }
+
+ /* Add the terminating null character to the command line. */
+ *cmd = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+/* Get the time at which either the process or user timeout will
+ expire. Returns 1 if the user timeout is first, and 0 otherwise. */
+int kwsysProcessGetTimeoutTime(kwsysProcess* cp, double* userTimeout,
+ kwsysProcessTime* timeoutTime)
+{
+ /* The first time this is called, we need to calculate the time at
+ which the child will timeout. */
+ if(cp->Timeout && cp->TimeoutTime.QuadPart < 0)
+ {
+ kwsysProcessTime length = kwsysProcessTimeFromDouble(cp->Timeout);
+ cp->TimeoutTime = kwsysProcessTimeAdd(cp->StartTime, length);
+ }
+
+ /* Start with process timeout. */
+ *timeoutTime = cp->TimeoutTime;
+
+ /* Check if the user timeout is earlier. */
+ if(userTimeout)
+ {
+ kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent();
+ kwsysProcessTime userTimeoutLength = kwsysProcessTimeFromDouble(*userTimeout);
+ kwsysProcessTime userTimeoutTime = kwsysProcessTimeAdd(currentTime,
+ userTimeoutLength);
+ if(timeoutTime->QuadPart < 0 ||
+ kwsysProcessTimeLess(userTimeoutTime, *timeoutTime))
+ {
+ *timeoutTime = userTimeoutTime;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Get the length of time before the given timeout time arrives.
+ Returns 1 if the time has already arrived, and 0 otherwise. */
+int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime,
+ double* userTimeout,
+ kwsysProcessTime* timeoutLength)
+{
+ if(timeoutTime->QuadPart < 0)
+ {
+ /* No timeout time has been requested. */
+ return 0;
+ }
+ else
+ {
+ /* Calculate the remaining time. */
+ kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent();
+ *timeoutLength = kwsysProcessTimeSubtract(*timeoutTime, currentTime);
+
+ if(timeoutLength->QuadPart < 0 && userTimeout && *userTimeout <= 0)
+ {
+ /* Caller has explicitly requested a zero timeout. */
+ timeoutLength->QuadPart = 0;
+ }
+
+ if(timeoutLength->QuadPart < 0)
+ {
+ /* Timeout has already expired. */
+ return 1;
+ }
+ else
+ {
+ /* There is some time left. */
+ return 0;
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+kwsysProcessTime kwsysProcessTimeGetCurrent()
+{
+ kwsysProcessTime current;
+ FILETIME ft;
+ GetSystemTimeAsFileTime(&ft);
+ current.LowPart = ft.dwLowDateTime;
+ current.HighPart = ft.dwHighDateTime;
+ return current;
+}
+
+/*--------------------------------------------------------------------------*/
+DWORD kwsysProcessTimeToDWORD(kwsysProcessTime t)
+{
+ return (DWORD)(t.QuadPart * 0.0001);
+}
+
+/*--------------------------------------------------------------------------*/
+double kwsysProcessTimeToDouble(kwsysProcessTime t)
+{
+ return t.QuadPart * 0.0000001;
+}
+
+/*--------------------------------------------------------------------------*/
+kwsysProcessTime kwsysProcessTimeFromDouble(double d)
+{
+ kwsysProcessTime t;
+ t.QuadPart = (LONGLONG)(d*10000000);
+ return t;
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysProcessTimeLess(kwsysProcessTime in1, kwsysProcessTime in2)
+{
+ return in1.QuadPart < in2.QuadPart;
+}
+
+/*--------------------------------------------------------------------------*/
+kwsysProcessTime kwsysProcessTimeAdd(kwsysProcessTime in1, kwsysProcessTime in2)
+{
+ kwsysProcessTime out;
+ out.QuadPart = in1.QuadPart + in2.QuadPart;
+ return out;
+}
+
+/*--------------------------------------------------------------------------*/
+kwsysProcessTime kwsysProcessTimeSubtract(kwsysProcessTime in1, kwsysProcessTime in2)
+{
+ kwsysProcessTime out;
+ out.QuadPart = in1.QuadPart - in2.QuadPart;
+ return out;
+}
+
+/*--------------------------------------------------------------------------*/
+#define KWSYSPE_CASE(type, str) \
+ cp->ExitException = kwsysProcess_Exception_##type; \
+ strcpy(cp->ExitExceptionString, str)
+static void kwsysProcessSetExitException(kwsysProcess* cp, int code)
+{
+ switch (code)
+ {
+ case STATUS_CONTROL_C_EXIT:
+ KWSYSPE_CASE(Interrupt, "User interrupt"); break;
+
+ case STATUS_FLOAT_DENORMAL_OPERAND:
+ KWSYSPE_CASE(Numerical, "Floating-point exception (denormal operand)"); break;
+ case STATUS_FLOAT_DIVIDE_BY_ZERO:
+ KWSYSPE_CASE(Numerical, "Divide-by-zero"); break;
+ case STATUS_FLOAT_INEXACT_RESULT:
+ KWSYSPE_CASE(Numerical, "Floating-point exception (inexact result)"); break;
+ case STATUS_FLOAT_INVALID_OPERATION:
+ KWSYSPE_CASE(Numerical, "Invalid floating-point operation"); break;
+ case STATUS_FLOAT_OVERFLOW:
+ KWSYSPE_CASE(Numerical, "Floating-point overflow"); break;
+ case STATUS_FLOAT_STACK_CHECK:
+ KWSYSPE_CASE(Numerical, "Floating-point stack check failed"); break;
+ case STATUS_FLOAT_UNDERFLOW:
+ KWSYSPE_CASE(Numerical, "Floating-point underflow"); break;
+#ifdef STATUS_FLOAT_MULTIPLE_FAULTS
+ case STATUS_FLOAT_MULTIPLE_FAULTS:
+ KWSYSPE_CASE(Numerical, "Floating-point exception (multiple faults)"); break;
+#endif
+#ifdef STATUS_FLOAT_MULTIPLE_TRAPS
+ case STATUS_FLOAT_MULTIPLE_TRAPS:
+ KWSYSPE_CASE(Numerical, "Floating-point exception (multiple traps)"); break;
+#endif
+ case STATUS_INTEGER_DIVIDE_BY_ZERO:
+ KWSYSPE_CASE(Numerical, "Integer divide-by-zero"); break;
+ case STATUS_INTEGER_OVERFLOW:
+ KWSYSPE_CASE(Numerical, "Integer overflow"); break;
+
+ case STATUS_DATATYPE_MISALIGNMENT:
+ KWSYSPE_CASE(Fault, "Datatype misalignment"); break;
+ case STATUS_ACCESS_VIOLATION:
+ KWSYSPE_CASE(Fault, "Access violation"); break;
+ case STATUS_IN_PAGE_ERROR:
+ KWSYSPE_CASE(Fault, "In-page error"); break;
+ case STATUS_INVALID_HANDLE:
+ KWSYSPE_CASE(Fault, "Invalid hanlde"); break;
+ case STATUS_NONCONTINUABLE_EXCEPTION:
+ KWSYSPE_CASE(Fault, "Noncontinuable exception"); break;
+ case STATUS_INVALID_DISPOSITION:
+ KWSYSPE_CASE(Fault, "Invalid disposition"); break;
+ case STATUS_ARRAY_BOUNDS_EXCEEDED:
+ KWSYSPE_CASE(Fault, "Array bounds exceeded"); break;
+ case STATUS_STACK_OVERFLOW:
+ KWSYSPE_CASE(Fault, "Stack overflow"); break;
+
+ case STATUS_ILLEGAL_INSTRUCTION:
+ KWSYSPE_CASE(Illegal, "Illegal instruction"); break;
+ case STATUS_PRIVILEGED_INSTRUCTION:
+ KWSYSPE_CASE(Illegal, "Privileged instruction"); break;
+
+ case STATUS_NO_MEMORY:
+ default:
+ cp->ExitException = kwsysProcess_Exception_Other;
+ _snprintf(cp->ExitExceptionString, KWSYSPE_PIPE_BUFFER_SIZE, "Exit code 0x%x\n", code);
+ break;
+ }
+}
+#undef KWSYSPE_CASE
+
+typedef struct kwsysProcess_List_s kwsysProcess_List;
+static kwsysProcess_List* kwsysProcess_List_New(void);
+static void kwsysProcess_List_Delete(kwsysProcess_List* self);
+static int kwsysProcess_List_Update(kwsysProcess_List* self);
+static int kwsysProcess_List_NextProcess(kwsysProcess_List* self);
+static int kwsysProcess_List_GetCurrentProcessId(kwsysProcess_List* self);
+static int kwsysProcess_List_GetCurrentParentId(kwsysProcess_List* self);
+
+/*--------------------------------------------------------------------------*/
+/* Windows NT 4 API definitions. */
+#define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
+typedef LONG NTSTATUS;
+typedef LONG KPRIORITY;
+typedef struct _UNICODE_STRING UNICODE_STRING;
+struct _UNICODE_STRING
+{
+ USHORT Length;
+ USHORT MaximumLength;
+ PWSTR Buffer;
+};
+
+/* The process information structure. Declare only enough to get
+ process identifiers. The rest may be ignored because we use the
+ NextEntryDelta to move through an array of instances. */
+typedef struct _SYSTEM_PROCESS_INFORMATION SYSTEM_PROCESS_INFORMATION;
+typedef SYSTEM_PROCESS_INFORMATION* PSYSTEM_PROCESS_INFORMATION;
+struct _SYSTEM_PROCESS_INFORMATION
+{
+ ULONG NextEntryDelta;
+ ULONG ThreadCount;
+ ULONG Reserved1[6];
+ LARGE_INTEGER CreateTime;
+ LARGE_INTEGER UserTime;
+ LARGE_INTEGER KernelTime;
+ UNICODE_STRING ProcessName;
+ KPRIORITY BasePriority;
+ ULONG ProcessId;
+ ULONG InheritedFromProcessId;
+};
+
+/*--------------------------------------------------------------------------*/
+/* Toolhelp32 API definitions. */
+#define TH32CS_SNAPPROCESS 0x00000002
+#if defined(_WIN64)
+typedef unsigned __int64 ProcessULONG_PTR;
+#else
+typedef unsigned long ProcessULONG_PTR;
+#endif
+typedef struct tagPROCESSENTRY32 PROCESSENTRY32;
+typedef PROCESSENTRY32* LPPROCESSENTRY32;
+struct tagPROCESSENTRY32
+{
+ DWORD dwSize;
+ DWORD cntUsage;
+ DWORD th32ProcessID;
+ ProcessULONG_PTR th32DefaultHeapID;
+ DWORD th32ModuleID;
+ DWORD cntThreads;
+ DWORD th32ParentProcessID;
+ LONG pcPriClassBase;
+ DWORD dwFlags;
+ char szExeFile[MAX_PATH];
+};
+
+/*--------------------------------------------------------------------------*/
+/* Windows API function types. */
+typedef HANDLE (WINAPI* CreateToolhelp32SnapshotType)(DWORD, DWORD);
+typedef BOOL (WINAPI* Process32FirstType)(HANDLE, LPPROCESSENTRY32);
+typedef BOOL (WINAPI* Process32NextType)(HANDLE, LPPROCESSENTRY32);
+typedef NTSTATUS (WINAPI* ZwQuerySystemInformationType)(ULONG, PVOID,
+ ULONG, PULONG);
+
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__New_NT4(kwsysProcess_List* self);
+static int kwsysProcess_List__New_Snapshot(kwsysProcess_List* self);
+static void kwsysProcess_List__Delete_NT4(kwsysProcess_List* self);
+static void kwsysProcess_List__Delete_Snapshot(kwsysProcess_List* self);
+static int kwsysProcess_List__Update_NT4(kwsysProcess_List* self);
+static int kwsysProcess_List__Update_Snapshot(kwsysProcess_List* self);
+static int kwsysProcess_List__Next_NT4(kwsysProcess_List* self);
+static int kwsysProcess_List__Next_Snapshot(kwsysProcess_List* self);
+static int kwsysProcess_List__GetProcessId_NT4(kwsysProcess_List* self);
+static int kwsysProcess_List__GetProcessId_Snapshot(kwsysProcess_List* self);
+static int kwsysProcess_List__GetParentId_NT4(kwsysProcess_List* self);
+static int kwsysProcess_List__GetParentId_Snapshot(kwsysProcess_List* self);
+
+struct kwsysProcess_List_s
+{
+ /* Implementation switches at runtime based on version of Windows. */
+ int NT4;
+
+ /* Implementation functions and data for NT 4. */
+ ZwQuerySystemInformationType P_ZwQuerySystemInformation;
+ char* Buffer;
+ int BufferSize;
+ PSYSTEM_PROCESS_INFORMATION CurrentInfo;
+
+ /* Implementation functions and data for other Windows versions. */
+ CreateToolhelp32SnapshotType P_CreateToolhelp32Snapshot;
+ Process32FirstType P_Process32First;
+ Process32NextType P_Process32Next;
+ HANDLE Snapshot;
+ PROCESSENTRY32 CurrentEntry;
+};
+
+/*--------------------------------------------------------------------------*/
+static kwsysProcess_List* kwsysProcess_List_New(void)
+{
+ OSVERSIONINFO osv;
+ kwsysProcess_List* self;
+
+ /* Allocate and initialize the list object. */
+ if(!(self = (kwsysProcess_List*)malloc(sizeof(kwsysProcess_List))))
+ {
+ return 0;
+ }
+ memset(self, 0, sizeof(*self));
+
+ /* Select an implementation. */
+ ZeroMemory(&osv, sizeof(osv));
+ osv.dwOSVersionInfoSize = sizeof(osv);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (push)
+# pragma warning (disable:4996)
+#endif
+ GetVersionEx(&osv);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (pop)
+#endif
+ self->NT4 = (osv.dwPlatformId == VER_PLATFORM_WIN32_NT &&
+ osv.dwMajorVersion < 5)? 1:0;
+
+ /* Initialize the selected implementation. */
+ if(!(self->NT4?
+ kwsysProcess_List__New_NT4(self) :
+ kwsysProcess_List__New_Snapshot(self)))
+ {
+ kwsysProcess_List_Delete(self);
+ return 0;
+ }
+
+ /* Update to the current set of processes. */
+ if(!kwsysProcess_List_Update(self))
+ {
+ kwsysProcess_List_Delete(self);
+ return 0;
+ }
+ return self;
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcess_List_Delete(kwsysProcess_List* self)
+{
+ if(self)
+ {
+ if(self->NT4)
+ {
+ kwsysProcess_List__Delete_NT4(self);
+ }
+ else
+ {
+ kwsysProcess_List__Delete_Snapshot(self);
+ }
+ free(self);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List_Update(kwsysProcess_List* self)
+{
+ return self? (self->NT4?
+ kwsysProcess_List__Update_NT4(self) :
+ kwsysProcess_List__Update_Snapshot(self)) : 0;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List_GetCurrentProcessId(kwsysProcess_List* self)
+{
+ return self? (self->NT4?
+ kwsysProcess_List__GetProcessId_NT4(self) :
+ kwsysProcess_List__GetProcessId_Snapshot(self)) : -1;
+
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List_GetCurrentParentId(kwsysProcess_List* self)
+{
+ return self? (self->NT4?
+ kwsysProcess_List__GetParentId_NT4(self) :
+ kwsysProcess_List__GetParentId_Snapshot(self)) : -1;
+
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List_NextProcess(kwsysProcess_List* self)
+{
+ return (self? (self->NT4?
+ kwsysProcess_List__Next_NT4(self) :
+ kwsysProcess_List__Next_Snapshot(self)) : 0);
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__New_NT4(kwsysProcess_List* self)
+{
+ /* Get a handle to the NT runtime module that should already be
+ loaded in this program. This does not actually increment the
+ reference count to the module so we do not need to close the
+ handle. */
+ HMODULE hNT = GetModuleHandleW(L"ntdll.dll");
+ if(hNT)
+ {
+ /* Get pointers to the needed API functions. */
+ self->P_ZwQuerySystemInformation =
+ ((ZwQuerySystemInformationType)
+ GetProcAddress(hNT, "ZwQuerySystemInformation"));
+ }
+ if(!self->P_ZwQuerySystemInformation)
+ {
+ return 0;
+ }
+
+ /* Allocate an initial process information buffer. */
+ self->BufferSize = 32768;
+ self->Buffer = (char*)malloc(self->BufferSize);
+ return self->Buffer? 1:0;
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcess_List__Delete_NT4(kwsysProcess_List* self)
+{
+ /* Free the process information buffer. */
+ if(self->Buffer)
+ {
+ free(self->Buffer);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__Update_NT4(kwsysProcess_List* self)
+{
+ self->CurrentInfo = 0;
+ for(;;)
+ {
+ /* Query number 5 is for system process list. */
+ NTSTATUS status =
+ self->P_ZwQuerySystemInformation(5, self->Buffer, self->BufferSize, 0);
+ if(status == STATUS_INFO_LENGTH_MISMATCH)
+ {
+ /* The query requires a bigger buffer. */
+ int newBufferSize = self->BufferSize * 2;
+ char* newBuffer = (char*)malloc(newBufferSize);
+ if(newBuffer)
+ {
+ free(self->Buffer);
+ self->Buffer = newBuffer;
+ self->BufferSize = newBufferSize;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else if(status >= 0)
+ {
+ /* The query succeeded. Initialize traversal of the process list. */
+ self->CurrentInfo = (PSYSTEM_PROCESS_INFORMATION)self->Buffer;
+ return 1;
+ }
+ else
+ {
+ /* The query failed. */
+ return 0;
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__Next_NT4(kwsysProcess_List* self)
+{
+ if(self->CurrentInfo)
+ {
+ if(self->CurrentInfo->NextEntryDelta > 0)
+ {
+ self->CurrentInfo = ((PSYSTEM_PROCESS_INFORMATION)
+ ((char*)self->CurrentInfo +
+ self->CurrentInfo->NextEntryDelta));
+ return 1;
+ }
+ self->CurrentInfo = 0;
+ }
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__GetProcessId_NT4(kwsysProcess_List* self)
+{
+ return self->CurrentInfo? self->CurrentInfo->ProcessId : -1;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__GetParentId_NT4(kwsysProcess_List* self)
+{
+ return self->CurrentInfo? self->CurrentInfo->InheritedFromProcessId : -1;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__New_Snapshot(kwsysProcess_List* self)
+{
+ /* Get a handle to the Windows runtime module that should already be
+ loaded in this program. This does not actually increment the
+ reference count to the module so we do not need to close the
+ handle. */
+ HMODULE hKernel = GetModuleHandleW(L"kernel32.dll");
+ if(hKernel)
+ {
+ self->P_CreateToolhelp32Snapshot =
+ ((CreateToolhelp32SnapshotType)
+ GetProcAddress(hKernel, "CreateToolhelp32Snapshot"));
+ self->P_Process32First =
+ ((Process32FirstType)
+ GetProcAddress(hKernel, "Process32First"));
+ self->P_Process32Next =
+ ((Process32NextType)
+ GetProcAddress(hKernel, "Process32Next"));
+ }
+ return (self->P_CreateToolhelp32Snapshot &&
+ self->P_Process32First &&
+ self->P_Process32Next)? 1:0;
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcess_List__Delete_Snapshot(kwsysProcess_List* self)
+{
+ if(self->Snapshot)
+ {
+ CloseHandle(self->Snapshot);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__Update_Snapshot(kwsysProcess_List* self)
+{
+ if(self->Snapshot)
+ {
+ CloseHandle(self->Snapshot);
+ }
+ if(!(self->Snapshot =
+ self->P_CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)))
+ {
+ return 0;
+ }
+ ZeroMemory(&self->CurrentEntry, sizeof(self->CurrentEntry));
+ self->CurrentEntry.dwSize = sizeof(self->CurrentEntry);
+ if(!self->P_Process32First(self->Snapshot, &self->CurrentEntry))
+ {
+ CloseHandle(self->Snapshot);
+ self->Snapshot = 0;
+ return 0;
+ }
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__Next_Snapshot(kwsysProcess_List* self)
+{
+ if(self->Snapshot)
+ {
+ if(self->P_Process32Next(self->Snapshot, &self->CurrentEntry))
+ {
+ return 1;
+ }
+ CloseHandle(self->Snapshot);
+ self->Snapshot = 0;
+ }
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__GetProcessId_Snapshot(kwsysProcess_List* self)
+{
+ return self->Snapshot? self->CurrentEntry.th32ProcessID : -1;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysProcess_List__GetParentId_Snapshot(kwsysProcess_List* self)
+{
+ return self->Snapshot? self->CurrentEntry.th32ParentProcessID : -1;
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessKill(DWORD pid)
+{
+ HANDLE h = OpenProcess(PROCESS_TERMINATE, 0, pid);
+ if(h)
+ {
+ TerminateProcess(h, 255);
+ WaitForSingleObject(h, INFINITE);
+ CloseHandle(h);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessKillTree(int pid)
+{
+ kwsysProcess_List* plist = kwsysProcess_List_New();
+ kwsysProcessKill(pid);
+ if(plist)
+ {
+ do
+ {
+ if(kwsysProcess_List_GetCurrentParentId(plist) == pid)
+ {
+ int ppid = kwsysProcess_List_GetCurrentProcessId(plist);
+ kwsysProcessKillTree(ppid);
+ }
+ } while(kwsysProcess_List_NextProcess(plist));
+ kwsysProcess_List_Delete(plist);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+static void kwsysProcessDisablePipeThreads(kwsysProcess* cp)
+{
+ int i;
+
+ /* If data were just reported data, release the pipe's thread. */
+ if(cp->CurrentIndex < KWSYSPE_PIPE_COUNT)
+ {
+ KWSYSPE_DEBUG((stderr, "releasing reader %d\n", cp->CurrentIndex));
+ ReleaseSemaphore(cp->Pipe[cp->CurrentIndex].Reader.Go, 1, 0);
+ cp->CurrentIndex = KWSYSPE_PIPE_COUNT;
+ }
+
+ /* Wakeup all reading threads that are not on closed pipes. */
+ for(i=0; i < KWSYSPE_PIPE_COUNT; ++i)
+ {
+ /* The wakeup threads will write one byte to the pipe write ends.
+ If there are no data in the pipe then this is enough to wakeup
+ the reading threads. If there are already data in the pipe
+ this may block. We cannot use PeekNamedPipe to check whether
+ there are data because an outside process might still be
+ writing data if we are disowning it. Also, PeekNamedPipe will
+ block if checking a pipe on which the reading thread is
+ currently calling ReadPipe. Therefore we need a separate
+ thread to call WriteFile. If it blocks, that is okay because
+ it will unblock when we close the read end and break the pipe
+ below. */
+ if(cp->Pipe[i].Read)
+ {
+ KWSYSPE_DEBUG((stderr, "releasing waker %d\n", i));
+ ReleaseSemaphore(cp->Pipe[i].Waker.Go, 1, 0);
+ }
+ }
+
+ /* Tell pipe threads to reset until we run another process. */
+ while(cp->PipesLeft > 0)
+ {
+ /* The waking threads will cause all reading threads to report.
+ Wait for the next one and save its index. */
+ KWSYSPE_DEBUG((stderr, "waiting for reader\n"));
+ WaitForSingleObject(cp->Full, INFINITE);
+ cp->CurrentIndex = cp->SharedIndex;
+ ReleaseSemaphore(cp->SharedIndexMutex, 1, 0);
+ KWSYSPE_DEBUG((stderr, "got reader %d\n", cp->CurrentIndex));
+
+ /* We are done reading this pipe. Close its read handle. */
+ cp->Pipe[cp->CurrentIndex].Closed = 1;
+ kwsysProcessCleanupHandle(&cp->Pipe[cp->CurrentIndex].Read);
+ --cp->PipesLeft;
+
+ /* Tell the reading thread we are done with the data. It will
+ reset immediately because the pipe is closed. */
+ ReleaseSemaphore(cp->Pipe[cp->CurrentIndex].Reader.Go, 1, 0);
+ }
+}
diff --git a/Source/kwsys/README.txt b/Source/kwsys/README.txt
new file mode 100644
index 0000000000..ba03f8ddee
--- /dev/null
+++ b/Source/kwsys/README.txt
@@ -0,0 +1,10 @@
+KWSys provides a platform-independent API to many common system
+features that are implemented differently on every platform. This
+library is intended to be shared among many projects, so it has a
+configurable namespace. Each project should configure KWSys to use a
+namespace unique to itself. See comments in CMakeLists.txt for
+details.
+
+You are probably reading this file in the source tree of a surrounding
+project. In that case, see "../README.kwsys" for details of using
+KWSys in your project.
diff --git a/Source/kwsys/RegularExpression.cxx b/Source/kwsys/RegularExpression.cxx
new file mode 100644
index 0000000000..598e7cae5f
--- /dev/null
+++ b/Source/kwsys/RegularExpression.cxx
@@ -0,0 +1,1244 @@
+/*============================================================================
+ 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.
+============================================================================*/
+//
+// Copyright (C) 1991 Texas Instruments Incorporated.
+//
+// Permission is granted to any individual or institution to use, copy, modify
+// and distribute this software, provided that this complete copyright and
+// permission notice is maintained, intact, in all copies and supporting
+// documentation.
+//
+// Texas Instruments Incorporated provides this software "as is" without
+// express or implied warranty.
+//
+//
+// Created: MNF 06/13/89 Initial Design and Implementation
+// Updated: LGO 08/09/89 Inherit from Generic
+// Updated: MBN 09/07/89 Added conditional exception handling
+// Updated: MBN 12/15/89 Sprinkled "const" qualifiers all over the place!
+// Updated: DLS 03/22/91 New lite version
+//
+
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(RegularExpression.hxx)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "RegularExpression.hxx.in"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+namespace KWSYS_NAMESPACE
+{
+
+// RegularExpression -- Copies the given regular expression.
+RegularExpression::RegularExpression (const RegularExpression& rxp) {
+ if ( !rxp.program )
+ {
+ this->program = 0;
+ return;
+ }
+ int ind;
+ this->progsize = rxp.progsize; // Copy regular expression size
+ this->program = new char[this->progsize]; // Allocate storage
+ for(ind=this->progsize; ind-- != 0;) // Copy regular expresion
+ this->program[ind] = rxp.program[ind];
+ this->startp[0] = rxp.startp[0]; // Copy pointers into last
+ this->endp[0] = rxp.endp[0]; // Successful "find" operation
+ this->regmust = rxp.regmust; // Copy field
+ if (rxp.regmust != 0) {
+ char* dum = rxp.program;
+ ind = 0;
+ while (dum != rxp.regmust) {
+ ++dum;
+ ++ind;
+ }
+ this->regmust = this->program + ind;
+ }
+ this->regstart = rxp.regstart; // Copy starting index
+ this->reganch = rxp.reganch; // Copy remaining private data
+ this->regmlen = rxp.regmlen; // Copy remaining private data
+}
+
+// operator= -- Copies the given regular expression.
+RegularExpression& RegularExpression::operator= (const RegularExpression& rxp)
+{
+ if(this == &rxp)
+ {
+ return *this;
+ }
+ if ( !rxp.program )
+ {
+ this->program = 0;
+ return *this;
+ }
+ int ind;
+ this->progsize = rxp.progsize; // Copy regular expression size
+ delete [] this->program;
+ this->program = new char[this->progsize]; // Allocate storage
+ for(ind=this->progsize; ind-- != 0;) // Copy regular expresion
+ this->program[ind] = rxp.program[ind];
+ this->startp[0] = rxp.startp[0]; // Copy pointers into last
+ this->endp[0] = rxp.endp[0]; // Successful "find" operation
+ this->regmust = rxp.regmust; // Copy field
+ if (rxp.regmust != 0) {
+ char* dum = rxp.program;
+ ind = 0;
+ while (dum != rxp.regmust) {
+ ++dum;
+ ++ind;
+ }
+ this->regmust = this->program + ind;
+ }
+ this->regstart = rxp.regstart; // Copy starting index
+ this->reganch = rxp.reganch; // Copy remaining private data
+ this->regmlen = rxp.regmlen; // Copy remaining private data
+
+ return *this;
+}
+
+// operator== -- Returns true if two regular expressions have the same
+// compiled program for pattern matching.
+bool RegularExpression::operator== (const RegularExpression& rxp) const {
+ if (this != &rxp) { // Same address?
+ int ind = this->progsize; // Get regular expression size
+ if (ind != rxp.progsize) // If different size regexp
+ return false; // Return failure
+ while(ind-- != 0) // Else while still characters
+ if(this->program[ind] != rxp.program[ind]) // If regexp are different
+ return false; // Return failure
+ }
+ return true; // Else same, return success
+}
+
+
+// deep_equal -- Returns true if have the same compiled regular expressions
+// and the same start and end pointers.
+
+bool RegularExpression::deep_equal (const RegularExpression& rxp) const {
+ int ind = this->progsize; // Get regular expression size
+ if (ind != rxp.progsize) // If different size regexp
+ return false; // Return failure
+ while(ind-- != 0) // Else while still characters
+ if(this->program[ind] != rxp.program[ind]) // If regexp are different
+ return false; // Return failure
+ return (this->startp[0] == rxp.startp[0] && // Else if same start/end ptrs,
+ this->endp[0] == rxp.endp[0]); // Return true
+}
+
+// The remaining code in this file is derived from the regular expression code
+// whose copyright statement appears below. It has been changed to work
+// with the class concepts of C++ and COOL.
+
+/*
+ * compile and find
+ *
+ * Copyright (c) 1986 by University of Toronto.
+ * Written by Henry Spencer. Not derived from licensed software.
+ *
+ * Permission is granted to anyone to use this software for any
+ * purpose on any computer system, and to redistribute it freely,
+ * subject to the following restrictions:
+ *
+ * 1. The author is not responsible for the consequences of use of
+ * this software, no matter how awful, even if they arise
+ * from defects in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either
+ * by explicit claim or by omission.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not
+ * be misrepresented as being the original software.
+ *
+ * Beware that some of this code is subtly aware of the way operator
+ * precedence is structured in regular expressions. Serious changes in
+ * regular-expression syntax might require a total rethink.
+ */
+
+/*
+ * The "internal use only" fields in regexp.h are present to pass info from
+ * compile to execute that permits the execute phase to run lots faster on
+ * simple cases. They are:
+ *
+ * regstart char that must begin a match; '\0' if none obvious
+ * reganch is the match anchored (at beginning-of-line only)?
+ * regmust string (pointer into program) that match must include, or NULL
+ * regmlen length of regmust string
+ *
+ * Regstart and reganch permit very fast decisions on suitable starting points
+ * for a match, cutting down the work a lot. Regmust permits fast rejection
+ * of lines that cannot possibly match. The regmust tests are costly enough
+ * that compile() supplies a regmust only if the r.e. contains something
+ * potentially expensive (at present, the only such thing detected is * or +
+ * at the start of the r.e., which can involve a lot of backup). Regmlen is
+ * supplied because the test in find() needs it and compile() is computing
+ * it anyway.
+ */
+
+/*
+ * Structure for regexp "program". This is essentially a linear encoding
+ * of a nondeterministic finite-state machine (aka syntax charts or
+ * "railroad normal form" in parsing technology). Each node is an opcode
+ * plus a "next" pointer, possibly plus an operand. "Next" pointers of
+ * all nodes except BRANCH implement concatenation; a "next" pointer with
+ * a BRANCH on both ends of it is connecting two alternatives. (Here we
+ * have one of the subtle syntax dependencies: an individual BRANCH (as
+ * opposed to a collection of them) is never concatenated with anything
+ * because of operator precedence.) The operand of some types of node is
+ * a literal string; for others, it is a node leading into a sub-FSM. In
+ * particular, the operand of a BRANCH node is the first node of the branch.
+ * (NB this is *not* a tree structure: the tail of the branch connects
+ * to the thing following the set of BRANCHes.) The opcodes are:
+ */
+
+// definition number opnd? meaning
+#define END 0 // no End of program.
+#define BOL 1 // no Match "" at beginning of line.
+#define EOL 2 // no Match "" at end of line.
+#define ANY 3 // no Match any one character.
+#define ANYOF 4 // str Match any character in this string.
+#define ANYBUT 5 // str Match any character not in this
+ // string.
+#define BRANCH 6 // node Match this alternative, or the
+ // next...
+#define BACK 7 // no Match "", "next" ptr points backward.
+#define EXACTLY 8 // str Match this string.
+#define NOTHING 9 // no Match empty string.
+#define STAR 10 // node Match this (simple) thing 0 or more
+ // times.
+#define PLUS 11 // node Match this (simple) thing 1 or more
+ // times.
+#define OPEN 20 // no Mark this point in input as start of
+ // #n.
+// OPEN+1 is number 1, etc.
+#define CLOSE 30 // no Analogous to OPEN.
+
+/*
+ * Opcode notes:
+ *
+ * BRANCH The set of branches constituting a single choice are hooked
+ * together with their "next" pointers, since precedence prevents
+ * anything being concatenated to any individual branch. The
+ * "next" pointer of the last BRANCH in a choice points to the
+ * thing following the whole choice. This is also where the
+ * final "next" pointer of each individual branch points; each
+ * branch starts with the operand node of a BRANCH node.
+ *
+ * BACK Normal "next" pointers all implicitly point forward; BACK
+ * exists to make loop structures possible.
+ *
+ * STAR,PLUS '?', and complex '*' and '+', are implemented as circular
+ * BRANCH structures using BACK. Simple cases (one character
+ * per match) are implemented with STAR and PLUS for speed
+ * and to minimize recursive plunges.
+ *
+ * OPEN,CLOSE ...are numbered at compile time.
+ */
+
+/*
+ * A node is one char of opcode followed by two chars of "next" pointer.
+ * "Next" pointers are stored as two 8-bit pieces, high order first. The
+ * value is a positive offset from the opcode of the node containing it.
+ * An operand, if any, simply follows the node. (Note that much of the
+ * code generation knows about this implicit relationship.)
+ *
+ * Using two bytes for the "next" pointer is vast overkill for most things,
+ * but allows patterns to get big without disasters.
+ */
+
+#define OP(p) (*(p))
+#define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
+#define OPERAND(p) ((p) + 3)
+
+const unsigned char MAGIC = 0234;
+/*
+ * Utility definitions.
+ */
+
+#define UCHARAT(p) (reinterpret_cast<const unsigned char*>(p))[0]
+
+
+#define FAIL(m) { regerror(m); return(0); }
+#define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?')
+#define META "^$.[()|?+*\\"
+
+
+/*
+ * Flags to be passed up and down.
+ */
+#define HASWIDTH 01 // Known never to match null string.
+#define SIMPLE 02 // Simple enough to be STAR/PLUS operand.
+#define SPSTART 04 // Starts with * or +.
+#define WORST 0 // Worst case.
+
+
+
+/////////////////////////////////////////////////////////////////////////
+//
+// COMPILE AND ASSOCIATED FUNCTIONS
+//
+/////////////////////////////////////////////////////////////////////////
+
+
+/*
+ * Global work variables for compile().
+ */
+static const char* regparse; // Input-scan pointer.
+static int regnpar; // () count.
+static char regdummy;
+static char* regcode; // Code-emit pointer; &regdummy = don't.
+static long regsize; // Code size.
+
+/*
+ * Forward declarations for compile()'s friends.
+ */
+// #ifndef static
+// #define static static
+// #endif
+static char* reg (int, int*);
+static char* regbranch (int*);
+static char* regpiece (int*);
+static char* regatom (int*);
+static char* regnode (char);
+static const char* regnext (const char*);
+static char* regnext (char*);
+static void regc (char);
+static void reginsert (char, char*);
+static void regtail (char*, const char*);
+static void regoptail (char*, const char*);
+
+#ifdef STRCSPN
+static int strcspn ();
+#endif
+
+
+
+/*
+ * We can't allocate space until we know how big the compiled form will be,
+ * but we can't compile it (and thus know how big it is) until we've got a
+ * place to put the code. So we cheat: we compile it twice, once with code
+ * generation turned off and size counting turned on, and once "for real".
+ * This also means that we don't allocate space until we are sure that the
+ * thing really will compile successfully, and we never have to move the
+ * code and thus invalidate pointers into it. (Note that it has to be in
+ * one piece because free() must be able to free it all.)
+ *
+ * Beware that the optimization-preparation code in here knows about some
+ * of the structure of the compiled regexp.
+ */
+
+
+// compile -- compile a regular expression into internal code
+// for later pattern matching.
+
+bool RegularExpression::compile (const char* exp) {
+ const char* scan;
+ const char* longest;
+ size_t len;
+ int flags;
+
+ if (exp == 0) {
+ //RAISE Error, SYM(RegularExpression), SYM(No_Expr),
+ printf ("RegularExpression::compile(): No expression supplied.\n");
+ return false;
+ }
+
+ // First pass: determine size, legality.
+ regparse = exp;
+ regnpar = 1;
+ regsize = 0L;
+ regcode = &regdummy;
+ regc(static_cast<char>(MAGIC));
+ if(!reg(0, &flags))
+ {
+ printf ("RegularExpression::compile(): Error in compile.\n");
+ return false;
+ }
+ this->startp[0] = this->endp[0] = this->searchstring = 0;
+
+ // Small enough for pointer-storage convention?
+ if (regsize >= 32767L) { // Probably could be 65535L.
+ //RAISE Error, SYM(RegularExpression), SYM(Expr_Too_Big),
+ printf ("RegularExpression::compile(): Expression too big.\n");
+ return false;
+ }
+
+ // Allocate space.
+//#ifndef WIN32
+ if (this->program != 0) delete [] this->program;
+//#endif
+ this->program = new char[regsize];
+ this->progsize = static_cast<int>(regsize);
+
+ if (this->program == 0) {
+ //RAISE Error, SYM(RegularExpression), SYM(Out_Of_Memory),
+ printf ("RegularExpression::compile(): Out of memory.\n");
+ return false;
+ }
+
+ // Second pass: emit code.
+ regparse = exp;
+ regnpar = 1;
+ regcode = this->program;
+ regc(static_cast<char>(MAGIC));
+ reg(0, &flags);
+
+ // Dig out information for optimizations.
+ this->regstart = '\0'; // Worst-case defaults.
+ this->reganch = 0;
+ this->regmust = 0;
+ this->regmlen = 0;
+ scan = this->program + 1; // First BRANCH.
+ if (OP(regnext(scan)) == END) { // Only one top-level choice.
+ scan = OPERAND(scan);
+
+ // Starting-point info.
+ if (OP(scan) == EXACTLY)
+ this->regstart = *OPERAND(scan);
+ else if (OP(scan) == BOL)
+ this->reganch++;
+
+ //
+ // If there's something expensive in the r.e., find the longest
+ // literal string that must appear and make it the regmust. Resolve
+ // ties in favor of later strings, since the regstart check works
+ // with the beginning of the r.e. and avoiding duplication
+ // strengthens checking. Not a strong reason, but sufficient in the
+ // absence of others.
+ //
+ if (flags & SPSTART) {
+ longest = 0;
+ len = 0;
+ for (; scan != 0; scan = regnext(scan))
+ if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
+ longest = OPERAND(scan);
+ len = strlen(OPERAND(scan));
+ }
+ this->regmust = longest;
+ this->regmlen = len;
+ }
+ }
+ return true;
+}
+
+
+/*
+ - reg - regular expression, i.e. main body or parenthesized thing
+ *
+ * Caller must absorb opening parenthesis.
+ *
+ * Combining parenthesis handling with the base level of regular expression
+ * is a trifle forced, but the need to tie the tails of the branches to what
+ * follows makes it hard to avoid.
+ */
+static char* reg (int paren, int *flagp) {
+ char* ret;
+ char* br;
+ char* ender;
+ int parno =0;
+ int flags;
+
+ *flagp = HASWIDTH; // Tentatively.
+
+ // Make an OPEN node, if parenthesized.
+ if (paren) {
+ if (regnpar >= RegularExpression::NSUBEXP) {
+ //RAISE Error, SYM(RegularExpression), SYM(Too_Many_Parens),
+ printf ("RegularExpression::compile(): Too many parentheses.\n");
+ return 0;
+ }
+ parno = regnpar;
+ regnpar++;
+ ret = regnode(static_cast<char>(OPEN + parno));
+ }
+ else
+ ret = 0;
+
+ // Pick up the branches, linking them together.
+ br = regbranch(&flags);
+ if (br == 0)
+ return (0);
+ if (ret != 0)
+ regtail(ret, br); // OPEN -> first.
+ else
+ ret = br;
+ if (!(flags & HASWIDTH))
+ *flagp &= ~HASWIDTH;
+ *flagp |= flags & SPSTART;
+ while (*regparse == '|') {
+ regparse++;
+ br = regbranch(&flags);
+ if (br == 0)
+ return (0);
+ regtail(ret, br); // BRANCH -> BRANCH.
+ if (!(flags & HASWIDTH))
+ *flagp &= ~HASWIDTH;
+ *flagp |= flags & SPSTART;
+ }
+
+ // Make a closing node, and hook it on the end.
+ ender = regnode(static_cast<char>((paren) ? CLOSE + parno : END));
+ regtail(ret, ender);
+
+ // Hook the tails of the branches to the closing node.
+ for (br = ret; br != 0; br = regnext(br))
+ regoptail(br, ender);
+
+ // Check for proper termination.
+ if (paren && *regparse++ != ')') {
+ //RAISE Error, SYM(RegularExpression), SYM(Unmatched_Parens),
+ printf ("RegularExpression::compile(): Unmatched parentheses.\n");
+ return 0;
+ }
+ else if (!paren && *regparse != '\0') {
+ if (*regparse == ')') {
+ //RAISE Error, SYM(RegularExpression), SYM(Unmatched_Parens),
+ printf ("RegularExpression::compile(): Unmatched parentheses.\n");
+ return 0;
+ }
+ else {
+ //RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
+ printf ("RegularExpression::compile(): Internal error.\n");
+ return 0;
+ }
+ // NOTREACHED
+ }
+ return (ret);
+}
+
+
+/*
+ - regbranch - one alternative of an | operator
+ *
+ * Implements the concatenation operator.
+ */
+static char* regbranch (int *flagp) {
+ char* ret;
+ char* chain;
+ char* latest;
+ int flags;
+
+ *flagp = WORST; // Tentatively.
+
+ ret = regnode(BRANCH);
+ chain = 0;
+ while (*regparse != '\0' && *regparse != '|' && *regparse != ')') {
+ latest = regpiece(&flags);
+ if (latest == 0)
+ return (0);
+ *flagp |= flags & HASWIDTH;
+ if (chain == 0) // First piece.
+ *flagp |= flags & SPSTART;
+ else
+ regtail(chain, latest);
+ chain = latest;
+ }
+ if (chain == 0) // Loop ran zero times.
+ regnode(NOTHING);
+
+ return (ret);
+}
+
+
+/*
+ - regpiece - something followed by possible [*+?]
+ *
+ * Note that the branching code sequences used for ? and the general cases
+ * of * and + are somewhat optimized: they use the same NOTHING node as
+ * both the endmarker for their branch list and the body of the last branch.
+ * It might seem that this node could be dispensed with entirely, but the
+ * endmarker role is not redundant.
+ */
+static char* regpiece (int *flagp) {
+ char* ret;
+ char op;
+ char* next;
+ int flags;
+
+ ret = regatom(&flags);
+ if (ret == 0)
+ return (0);
+
+ op = *regparse;
+ if (!ISMULT(op)) {
+ *flagp = flags;
+ return (ret);
+ }
+
+ if (!(flags & HASWIDTH) && op != '?') {
+ //RAISE Error, SYM(RegularExpression), SYM(Empty_Operand),
+ printf ("RegularExpression::compile() : *+ operand could be empty.\n");
+ return 0;
+ }
+ *flagp = (op != '+') ? (WORST | SPSTART) : (WORST | HASWIDTH);
+
+ if (op == '*' && (flags & SIMPLE))
+ reginsert(STAR, ret);
+ else if (op == '*') {
+ // Emit x* as (x&|), where & means "self".
+ reginsert(BRANCH, ret); // Either x
+ regoptail(ret, regnode(BACK)); // and loop
+ regoptail(ret, ret); // back
+ regtail(ret, regnode(BRANCH)); // or
+ regtail(ret, regnode(NOTHING)); // null.
+ }
+ else if (op == '+' && (flags & SIMPLE))
+ reginsert(PLUS, ret);
+ else if (op == '+') {
+ // Emit x+ as x(&|), where & means "self".
+ next = regnode(BRANCH); // Either
+ regtail(ret, next);
+ regtail(regnode(BACK), ret); // loop back
+ regtail(next, regnode(BRANCH)); // or
+ regtail(ret, regnode(NOTHING)); // null.
+ }
+ else if (op == '?') {
+ // Emit x? as (x|)
+ reginsert(BRANCH, ret); // Either x
+ regtail(ret, regnode(BRANCH)); // or
+ next = regnode(NOTHING);// null.
+ regtail(ret, next);
+ regoptail(ret, next);
+ }
+ regparse++;
+ if (ISMULT(*regparse)) {
+ //RAISE Error, SYM(RegularExpression), SYM(Nested_Operand),
+ printf ("RegularExpression::compile(): Nested *?+.\n");
+ return 0;
+ }
+ return (ret);
+}
+
+
+/*
+ - regatom - the lowest level
+ *
+ * Optimization: gobbles an entire sequence of ordinary characters so that
+ * it can turn them into a single node, which is smaller to store and
+ * faster to run. Backslashed characters are exceptions, each becoming a
+ * separate node; the code is simpler that way and it's not worth fixing.
+ */
+static char* regatom (int *flagp) {
+ char* ret;
+ int flags;
+
+ *flagp = WORST; // Tentatively.
+
+ switch (*regparse++) {
+ case '^':
+ ret = regnode(BOL);
+ break;
+ case '$':
+ ret = regnode(EOL);
+ break;
+ case '.':
+ ret = regnode(ANY);
+ *flagp |= HASWIDTH | SIMPLE;
+ break;
+ case '[':{
+ int rxpclass;
+ int rxpclassend;
+
+ if (*regparse == '^') { // Complement of range.
+ ret = regnode(ANYBUT);
+ regparse++;
+ }
+ else
+ ret = regnode(ANYOF);
+ if (*regparse == ']' || *regparse == '-')
+ regc(*regparse++);
+ while (*regparse != '\0' && *regparse != ']') {
+ if (*regparse == '-') {
+ regparse++;
+ if (*regparse == ']' || *regparse == '\0')
+ regc('-');
+ else {
+ rxpclass = UCHARAT(regparse - 2) + 1;
+ rxpclassend = UCHARAT(regparse);
+ if (rxpclass > rxpclassend + 1) {
+ //RAISE Error, SYM(RegularExpression), SYM(Invalid_Range),
+ printf ("RegularExpression::compile(): Invalid range in [].\n");
+ return 0;
+ }
+ for (; rxpclass <= rxpclassend; rxpclass++)
+ regc(static_cast<char>(rxpclass));
+ regparse++;
+ }
+ }
+ else
+ regc(*regparse++);
+ }
+ regc('\0');
+ if (*regparse != ']') {
+ //RAISE Error, SYM(RegularExpression), SYM(Unmatched_Bracket),
+ printf ("RegularExpression::compile(): Unmatched [].\n");
+ return 0;
+ }
+ regparse++;
+ *flagp |= HASWIDTH | SIMPLE;
+ }
+ break;
+ case '(':
+ ret = reg(1, &flags);
+ if (ret == 0)
+ return (0);
+ *flagp |= flags & (HASWIDTH | SPSTART);
+ break;
+ case '\0':
+ case '|':
+ case ')':
+ //RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
+ printf ("RegularExpression::compile(): Internal error.\n"); // Never here
+ return 0;
+ case '?':
+ case '+':
+ case '*':
+ //RAISE Error, SYM(RegularExpression), SYM(No_Operand),
+ printf ("RegularExpression::compile(): ?+* follows nothing.\n");
+ return 0;
+ case '\\':
+ if (*regparse == '\0') {
+ //RAISE Error, SYM(RegularExpression), SYM(Trailing_Backslash),
+ printf ("RegularExpression::compile(): Trailing backslash.\n");
+ return 0;
+ }
+ ret = regnode(EXACTLY);
+ regc(*regparse++);
+ regc('\0');
+ *flagp |= HASWIDTH | SIMPLE;
+ break;
+ default:{
+ int len;
+ char ender;
+
+ regparse--;
+ len = int(strcspn(regparse, META));
+ if (len <= 0) {
+ //RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
+ printf ("RegularExpression::compile(): Internal error.\n");
+ return 0;
+ }
+ ender = *(regparse + len);
+ if (len > 1 && ISMULT(ender))
+ len--; // Back off clear of ?+* operand.
+ *flagp |= HASWIDTH;
+ if (len == 1)
+ *flagp |= SIMPLE;
+ ret = regnode(EXACTLY);
+ while (len > 0) {
+ regc(*regparse++);
+ len--;
+ }
+ regc('\0');
+ }
+ break;
+ }
+ return (ret);
+}
+
+
+/*
+ - regnode - emit a node
+ Location.
+ */
+static char* regnode (char op) {
+ char* ret;
+ char* ptr;
+
+ ret = regcode;
+ if (ret == &regdummy) {
+ regsize += 3;
+ return (ret);
+ }
+
+ ptr = ret;
+ *ptr++ = op;
+ *ptr++ = '\0'; // Null "next" pointer.
+ *ptr++ = '\0';
+ regcode = ptr;
+
+ return (ret);
+}
+
+
+/*
+ - regc - emit (if appropriate) a byte of code
+ */
+static void regc (char b) {
+ if (regcode != &regdummy)
+ *regcode++ = b;
+ else
+ regsize++;
+}
+
+
+/*
+ - reginsert - insert an operator in front of already-emitted operand
+ *
+ * Means relocating the operand.
+ */
+static void reginsert (char op, char* opnd) {
+ char* src;
+ char* dst;
+ char* place;
+
+ if (regcode == &regdummy) {
+ regsize += 3;
+ return;
+ }
+
+ src = regcode;
+ regcode += 3;
+ dst = regcode;
+ while (src > opnd)
+ *--dst = *--src;
+
+ place = opnd; // Op node, where operand used to be.
+ *place++ = op;
+ *place++ = '\0';
+ *place = '\0';
+}
+
+
+/*
+ - regtail - set the next-pointer at the end of a node chain
+ */
+static void regtail (char* p, const char* val) {
+ char* scan;
+ char* temp;
+ int offset;
+
+ if (p == &regdummy)
+ return;
+
+ // Find last node.
+ scan = p;
+ for (;;) {
+ temp = regnext(scan);
+ if (temp == 0)
+ break;
+ scan = temp;
+ }
+
+ if (OP(scan) == BACK)
+ offset = int(scan - val);
+ else
+ offset = int(val - scan);
+ *(scan + 1) = static_cast<char>((offset >> 8) & 0377);
+ *(scan + 2) = static_cast<char>(offset & 0377);
+}
+
+
+/*
+ - regoptail - regtail on operand of first argument; nop if operandless
+ */
+static void regoptail (char* p, const char* val) {
+ // "Operandless" and "op != BRANCH" are synonymous in practice.
+ if (p == 0 || p == &regdummy || OP(p) != BRANCH)
+ return;
+ regtail(OPERAND(p), val);
+}
+
+
+
+////////////////////////////////////////////////////////////////////////
+//
+// find and friends
+//
+////////////////////////////////////////////////////////////////////////
+
+
+/*
+ * Global work variables for find().
+ */
+static const char* reginput; // String-input pointer.
+static const char* regbol; // Beginning of input, for ^ check.
+static const char* *regstartp; // Pointer to startp array.
+static const char* *regendp; // Ditto for endp.
+
+/*
+ * Forwards.
+ */
+static int regtry (const char*, const char* *,
+ const char* *, const char*);
+static int regmatch (const char*);
+static int regrepeat (const char*);
+
+#ifdef DEBUG
+int regnarrate = 0;
+void regdump ();
+static char* regprop ();
+#endif
+
+// find -- Matches the regular expression to the given string.
+// Returns true if found, and sets start and end indexes accordingly.
+
+bool RegularExpression::find (const char* string) {
+ const char* s;
+
+ this->searchstring = string;
+
+ if (!this->program)
+ {
+ return false;
+ }
+
+ // Check validity of program.
+ if (UCHARAT(this->program) != MAGIC) {
+ //RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
+ printf ("RegularExpression::find(): Compiled regular expression corrupted.\n");
+ return 0;
+ }
+
+ // If there is a "must appear" string, look for it.
+ if (this->regmust != 0) {
+ s = string;
+ while ((s = strchr(s, this->regmust[0])) != 0) {
+ if (strncmp(s, this->regmust, this->regmlen) == 0)
+ break; // Found it.
+ s++;
+ }
+ if (s == 0) // Not present.
+ return (0);
+ }
+
+ // Mark beginning of line for ^ .
+ regbol = string;
+
+ // Simplest case: anchored match need be tried only once.
+ if (this->reganch)
+ return (regtry(string, this->startp, this->endp, this->program) != 0);
+
+ // Messy cases: unanchored match.
+ s = string;
+ if (this->regstart != '\0')
+ // We know what char it must start with.
+ while ((s = strchr(s, this->regstart)) != 0) {
+ if (regtry(s, this->startp, this->endp, this->program))
+ return (1);
+ s++;
+
+ }
+ else
+ // We don't -- general case.
+ do {
+ if (regtry(s, this->startp, this->endp, this->program))
+ return (1);
+ } while (*s++ != '\0');
+
+ // Failure.
+ return (0);
+}
+
+
+/*
+ - regtry - try match at specific point
+ 0 failure, 1 success
+ */
+static int regtry (const char* string, const char* *start,
+ const char* *end, const char* prog) {
+ int i;
+ const char* *sp1;
+ const char* *ep;
+
+ reginput = string;
+ regstartp = start;
+ regendp = end;
+
+ sp1 = start;
+ ep = end;
+ for (i = RegularExpression::NSUBEXP; i > 0; i--) {
+ *sp1++ = 0;
+ *ep++ = 0;
+ }
+ if (regmatch(prog + 1)) {
+ start[0] = string;
+ end[0] = reginput;
+ return (1);
+ }
+ else
+ return (0);
+}
+
+
+/*
+ - regmatch - main matching routine
+ *
+ * Conceptually the strategy is simple: check to see whether the current
+ * node matches, call self recursively to see whether the rest matches,
+ * and then act accordingly. In practice we make some effort to avoid
+ * recursion, in particular by going through "ordinary" nodes (that don't
+ * need to know whether the rest of the match failed) by a loop instead of
+ * by recursion.
+ * 0 failure, 1 success
+ */
+static int regmatch (const char* prog) {
+ const char* scan; // Current node.
+ const char* next; // Next node.
+
+ scan = prog;
+
+ while (scan != 0) {
+
+ next = regnext(scan);
+
+ switch (OP(scan)) {
+ case BOL:
+ if (reginput != regbol)
+ return (0);
+ break;
+ case EOL:
+ if (*reginput != '\0')
+ return (0);
+ break;
+ case ANY:
+ if (*reginput == '\0')
+ return (0);
+ reginput++;
+ break;
+ case EXACTLY:{
+ size_t len;
+ const char* opnd;
+
+ opnd = OPERAND(scan);
+ // Inline the first character, for speed.
+ if (*opnd != *reginput)
+ return (0);
+ len = strlen(opnd);
+ if (len > 1 && strncmp(opnd, reginput, len) != 0)
+ return (0);
+ reginput += len;
+ }
+ break;
+ case ANYOF:
+ if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == 0)
+ return (0);
+ reginput++;
+ break;
+ case ANYBUT:
+ if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != 0)
+ return (0);
+ reginput++;
+ break;
+ case NOTHING:
+ break;
+ case BACK:
+ break;
+ case OPEN + 1:
+ case OPEN + 2:
+ case OPEN + 3:
+ case OPEN + 4:
+ case OPEN + 5:
+ case OPEN + 6:
+ case OPEN + 7:
+ case OPEN + 8:
+ case OPEN + 9:{
+ int no;
+ const char* save;
+
+ no = OP(scan) - OPEN;
+ save = reginput;
+
+ if (regmatch(next)) {
+
+ //
+ // Don't set startp if some later invocation of the
+ // same parentheses already has.
+ //
+ if (regstartp[no] == 0)
+ regstartp[no] = save;
+ return (1);
+ }
+ else
+ return (0);
+ }
+// break;
+ case CLOSE + 1:
+ case CLOSE + 2:
+ case CLOSE + 3:
+ case CLOSE + 4:
+ case CLOSE + 5:
+ case CLOSE + 6:
+ case CLOSE + 7:
+ case CLOSE + 8:
+ case CLOSE + 9:{
+ int no;
+ const char* save;
+
+ no = OP(scan) - CLOSE;
+ save = reginput;
+
+ if (regmatch(next)) {
+
+ //
+ // Don't set endp if some later invocation of the
+ // same parentheses already has.
+ //
+ if (regendp[no] == 0)
+ regendp[no] = save;
+ return (1);
+ }
+ else
+ return (0);
+ }
+// break;
+ case BRANCH:{
+
+ const char* save;
+
+ if (OP(next) != BRANCH) // No choice.
+ next = OPERAND(scan); // Avoid recursion.
+ else {
+ do {
+ save = reginput;
+ if (regmatch(OPERAND(scan)))
+ return (1);
+ reginput = save;
+ scan = regnext(scan);
+ } while (scan != 0 && OP(scan) == BRANCH);
+ return (0);
+ // NOTREACHED
+ }
+ }
+ break;
+ case STAR:
+ case PLUS:{
+ char nextch;
+ int no;
+ const char* save;
+ int min_no;
+
+ //
+ // Lookahead to avoid useless match attempts when we know
+ // what character comes next.
+ //
+ nextch = '\0';
+ if (OP(next) == EXACTLY)
+ nextch = *OPERAND(next);
+ min_no = (OP(scan) == STAR) ? 0 : 1;
+ save = reginput;
+ no = regrepeat(OPERAND(scan));
+ while (no >= min_no) {
+ // If it could work, try it.
+ if (nextch == '\0' || *reginput == nextch)
+ if (regmatch(next))
+ return (1);
+ // Couldn't or didn't -- back up.
+ no--;
+ reginput = save + no;
+ }
+ return (0);
+ }
+// break;
+ case END:
+ return (1); // Success!
+
+ default:
+ //RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
+ printf ("RegularExpression::find(): Internal error -- memory corrupted.\n");
+ return 0;
+ }
+ scan = next;
+ }
+
+ //
+ // We get here only if there's trouble -- normally "case END" is the
+ // terminating point.
+ //
+ //RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
+ printf ("RegularExpression::find(): Internal error -- corrupted pointers.\n");
+ return (0);
+}
+
+
+/*
+ - regrepeat - repeatedly match something simple, report how many
+ */
+static int regrepeat (const char* p) {
+ int count = 0;
+ const char* scan;
+ const char* opnd;
+
+ scan = reginput;
+ opnd = OPERAND(p);
+ switch (OP(p)) {
+ case ANY:
+ count = int(strlen(scan));
+ scan += count;
+ break;
+ case EXACTLY:
+ while (*opnd == *scan) {
+ count++;
+ scan++;
+ }
+ break;
+ case ANYOF:
+ while (*scan != '\0' && strchr(opnd, *scan) != 0) {
+ count++;
+ scan++;
+ }
+ break;
+ case ANYBUT:
+ while (*scan != '\0' && strchr(opnd, *scan) == 0) {
+ count++;
+ scan++;
+ }
+ break;
+ default: // Oh dear. Called inappropriately.
+ //RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
+ printf ("cm RegularExpression::find(): Internal error.\n");
+ return 0;
+ }
+ reginput = scan;
+ return (count);
+}
+
+
+/*
+ - regnext - dig the "next" pointer out of a node
+ */
+static const char* regnext (const char* p) {
+ int offset;
+
+ if (p == &regdummy)
+ return (0);
+
+ offset = NEXT(p);
+ if (offset == 0)
+ return (0);
+
+ if (OP(p) == BACK)
+ return (p - offset);
+ else
+ return (p + offset);
+}
+
+static char* regnext (char* p) {
+ int offset;
+
+ if (p == &regdummy)
+ return (0);
+
+ offset = NEXT(p);
+ if (offset == 0)
+ return (0);
+
+ if (OP(p) == BACK)
+ return (p - offset);
+ else
+ return (p + offset);
+}
+
+} // namespace KWSYS_NAMESPACE
diff --git a/Source/kwsys/RegularExpression.hxx.in b/Source/kwsys/RegularExpression.hxx.in
new file mode 100644
index 0000000000..502fbe2708
--- /dev/null
+++ b/Source/kwsys/RegularExpression.hxx.in
@@ -0,0 +1,453 @@
+/*============================================================================
+ 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.
+============================================================================*/
+// Original Copyright notice:
+// Copyright (C) 1991 Texas Instruments Incorporated.
+//
+// Permission is granted to any individual or institution to use, copy, modify,
+// and distribute this software, provided that this complete copyright and
+// permission notice is maintained, intact, in all copies and supporting
+// documentation.
+//
+// Texas Instruments Incorporated provides this software "as is" without
+// express or implied warranty.
+//
+// Created: MNF 06/13/89 Initial Design and Implementation
+// Updated: LGO 08/09/89 Inherit from Generic
+// Updated: MBN 09/07/89 Added conditional exception handling
+// Updated: MBN 12/15/89 Sprinkled "const" qualifiers all over the place!
+// Updated: DLS 03/22/91 New lite version
+//
+
+#ifndef @KWSYS_NAMESPACE@_RegularExpression_hxx
+#define @KWSYS_NAMESPACE@_RegularExpression_hxx
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+#include <@KWSYS_NAMESPACE@/stl/string>
+
+/* Define this macro temporarily to keep the code readable. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys_stl @KWSYS_NAMESPACE@_stl
+#endif
+
+/* Disable useless Borland warnings. KWSys tries not to force things
+ on its includers, but there is no choice here. */
+#if defined(__BORLANDC__)
+# pragma warn -8027 /* function not inlined. */
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+
+/** \class RegularExpression
+ * \brief Implements pattern matching with regular expressions.
+ *
+ * This is the header file for the regular expression class. An object of
+ * this class contains a regular expression, in a special "compiled" format.
+ * This compiled format consists of several slots all kept as the objects
+ * private data. The RegularExpression class provides a convenient way to
+ * represent regular expressions. It makes it easy to search for the same
+ * regular expression in many different strings without having to compile a
+ * string to regular expression format more than necessary.
+ *
+ * This class implements pattern matching via regular expressions.
+ * A regular expression allows a programmer to specify complex
+ * patterns that can be searched for and matched against the
+ * character string of a string object. In its simplest form, a
+ * regular expression is a sequence of characters used to
+ * search for exact character matches. However, many times the
+ * exact sequence to be found is not known, or only a match at
+ * the beginning or end of a string is desired. The RegularExpression regu-
+ * lar expression class implements regular expression pattern
+ * matching as is found and implemented in many UNIX commands
+ * and utilities.
+ *
+ * Example: The perl code
+ *
+ * $filename =~ m"([a-z]+)\.cc";
+ * print $1;
+ *
+ * Is written as follows in C++
+ *
+ * RegularExpression re("([a-z]+)\\.cc");
+ * re.find(filename);
+ * cerr << re.match(1);
+ *
+ *
+ * The regular expression class provides a convenient mechanism
+ * for specifying and manipulating regular expressions. The
+ * regular expression object allows specification of such pat-
+ * terns by using the following regular expression metacharac-
+ * ters:
+ *
+ * ^ Matches at beginning of a line
+ *
+ * $ Matches at end of a line
+ *
+ * . Matches any single character
+ *
+ * [ ] Matches any character(s) inside the brackets
+ *
+ * [^ ] Matches any character(s) not inside the brackets
+ *
+ * - Matches any character in range on either side of a dash
+ *
+ * * Matches preceding pattern zero or more times
+ *
+ * + Matches preceding pattern one or more times
+ *
+ * ? Matches preceding pattern zero or once only
+ *
+ * () Saves a matched expression and uses it in a later match
+ *
+ * Note that more than one of these metacharacters can be used
+ * in a single regular expression in order to create complex
+ * search patterns. For example, the pattern [^ab1-9] says to
+ * match any character sequence that does not begin with the
+ * characters "ab" followed by numbers in the series one
+ * through nine.
+ *
+ * There are three constructors for RegularExpression. One just creates an
+ * empty RegularExpression object. Another creates a RegularExpression
+ * object and initializes it with a regular expression that is given in the
+ * form of a char*. The third takes a reference to a RegularExpression
+ * object as an argument and creates an object initialized with the
+ * information from the given RegularExpression object.
+ *
+ * The find member function finds the first occurence of the regualr
+ * expression of that object in the string given to find as an argument. Find
+ * returns a boolean, and if true, mutates the private data appropriately.
+ * Find sets pointers to the beginning and end of the thing last found, they
+ * are pointers into the actual string that was searched. The start and end
+ * member functions return indicies into the searched string that correspond
+ * to the beginning and end pointers respectively. The compile member
+ * function takes a char* and puts the compiled version of the char* argument
+ * into the object's private data fields. The == and != operators only check
+ * the to see if the compiled regular expression is the same, and the
+ * deep_equal functions also checks to see if the start and end pointers are
+ * the same. The is_valid function returns false if program is set to NULL,
+ * (i.e. there is no valid compiled exression). The set_invalid function sets
+ * the program to NULL (Warning: this deletes the compiled expression). The
+ * following examples may help clarify regular expression usage:
+ *
+ * * The regular expression "^hello" matches a "hello" only at the
+ * beginning of a line. It would match "hello there" but not "hi,
+ * hello there".
+ *
+ * * The regular expression "long$" matches a "long" only at the end
+ * of a line. It would match "so long\0", but not "long ago".
+ *
+ * * The regular expression "t..t..g" will match anything that has a
+ * "t" then any two characters, another "t", any two characters and
+ * then a "g". It will match "testing", or "test again" but would
+ * not match "toasting"
+ *
+ * * The regular expression "[1-9ab]" matches any number one through
+ * nine, and the characters "a" and "b". It would match "hello 1"
+ * or "begin", but would not match "no-match".
+ *
+ * * The regular expression "[^1-9ab]" matches any character that is
+ * not a number one through nine, or an "a" or "b". It would NOT
+ * match "hello 1" or "begin", but would match "no-match".
+ *
+ * * The regular expression "br* " matches something that begins with
+ * a "b", is followed by zero or more "r"s, and ends in a space. It
+ * would match "brrrrr ", and "b ", but would not match "brrh ".
+ *
+ * * The regular expression "br+ " matches something that begins with
+ * a "b", is followed by one or more "r"s, and ends in a space. It
+ * would match "brrrrr ", and "br ", but would not match "b " or
+ * "brrh ".
+ *
+ * * The regular expression "br? " matches something that begins with
+ * a "b", is followed by zero or one "r"s, and ends in a space. It
+ * would match "br ", and "b ", but would not match "brrrr " or
+ * "brrh ".
+ *
+ * * The regular expression "(..p)b" matches something ending with pb
+ * and beginning with whatever the two characters before the first p
+ * encounterd in the line were. It would find "repb" in "rep drepa
+ * qrepb". The regular expression "(..p)a" would find "repa qrepb"
+ * in "rep drepa qrepb"
+ *
+ * * The regular expression "d(..p)" matches something ending with p,
+ * beginning with d, and having two characters in between that are
+ * the same as the two characters before the first p encounterd in
+ * the line. It would match "drepa qrepb" in "rep drepa qrepb".
+ *
+ */
+class @KWSYS_NAMESPACE@_EXPORT RegularExpression
+{
+public:
+ /**
+ * Instantiate RegularExpression with program=NULL.
+ */
+ inline RegularExpression ();
+
+ /**
+ * Instantiate RegularExpression with compiled char*.
+ */
+ inline RegularExpression (char const*);
+
+ /**
+ * Instantiate RegularExpression as a copy of another regular expression.
+ */
+ RegularExpression (RegularExpression const&);
+
+ /**
+ * Instantiate RegularExpression with compiled string.
+ */
+ inline RegularExpression (kwsys_stl::string const&);
+
+ /**
+ * Destructor.
+ */
+ inline ~RegularExpression();
+
+ /**
+ * Compile a regular expression into internal code
+ * for later pattern matching.
+ */
+ bool compile (char const*);
+
+ /**
+ * Compile a regular expression into internal code
+ * for later pattern matching.
+ */
+ inline bool compile (kwsys_stl::string const&);
+
+ /**
+ * Matches the regular expression to the given string.
+ * Returns true if found, and sets start and end indexes accordingly.
+ */
+ bool find (char const*);
+
+ /**
+ * Matches the regular expression to the given std string.
+ * Returns true if found, and sets start and end indexes accordingly.
+ */
+ inline bool find (kwsys_stl::string const&);
+
+ /**
+ * Index to start of first find.
+ */
+ inline kwsys_stl::string::size_type start() const;
+
+ /**
+ * Index to end of first find.
+ */
+ inline kwsys_stl::string::size_type end() const;
+
+ /**
+ * Copy the given regular expression.
+ */
+ RegularExpression& operator= (const RegularExpression& rxp);
+
+ /**
+ * Returns true if two regular expressions have the same
+ * compiled program for pattern matching.
+ */
+ bool operator== (RegularExpression const&) const;
+
+ /**
+ * Returns true if two regular expressions have different
+ * compiled program for pattern matching.
+ */
+ inline bool operator!= (RegularExpression const&) const;
+
+ /**
+ * Returns true if have the same compiled regular expressions
+ * and the same start and end pointers.
+ */
+ bool deep_equal (RegularExpression const&) const;
+
+ /**
+ * True if the compiled regexp is valid.
+ */
+ inline bool is_valid() const;
+
+ /**
+ * Marks the regular expression as invalid.
+ */
+ inline void set_invalid();
+
+ /**
+ * Destructor.
+ */
+ // awf added
+ kwsys_stl::string::size_type start(int n) const;
+ kwsys_stl::string::size_type end(int n) const;
+ kwsys_stl::string match(int n) const;
+
+ enum { NSUBEXP = 10 };
+private:
+ const char* startp[NSUBEXP];
+ const char* endp[NSUBEXP];
+ char regstart; // Internal use only
+ char reganch; // Internal use only
+ const char* regmust; // Internal use only
+ kwsys_stl::string::size_type regmlen; // Internal use only
+ char* program;
+ int progsize;
+ const char* searchstring;
+};
+
+/**
+ * Create an empty regular expression.
+ */
+inline RegularExpression::RegularExpression ()
+{
+ this->program = 0;
+}
+
+/**
+ * Creates a regular expression from string s, and
+ * compiles s.
+ */
+inline RegularExpression::RegularExpression (const char* s)
+{
+ this->program = 0;
+ if ( s )
+ {
+ this->compile(s);
+ }
+}
+
+/**
+ * Creates a regular expression from string s, and
+ * compiles s.
+ */
+inline RegularExpression::RegularExpression (const kwsys_stl::string& s)
+{
+ this->program = 0;
+ this->compile(s);
+}
+
+/**
+ * Destroys and frees space allocated for the regular expression.
+ */
+inline RegularExpression::~RegularExpression ()
+{
+//#ifndef WIN32
+ delete [] this->program;
+//#endif
+}
+
+/**
+ * Compile a regular expression into internal code
+ * for later pattern matching.
+ */
+inline bool RegularExpression::compile (kwsys_stl::string const& s)
+{
+ return this->compile(s.c_str());
+}
+
+/**
+ * Matches the regular expression to the given std string.
+ * Returns true if found, and sets start and end indexes accordingly.
+ */
+inline bool RegularExpression::find (kwsys_stl::string const& s)
+{
+ return this->find(s.c_str());
+}
+
+/**
+ * Set the start position for the regular expression.
+ */
+inline kwsys_stl::string::size_type RegularExpression::start () const
+{
+ return static_cast<kwsys_stl::string::size_type>(
+ this->startp[0] - searchstring);
+}
+
+
+/**
+ * Returns the start/end index of the last item found.
+ */
+inline kwsys_stl::string::size_type RegularExpression::end () const
+{
+ return static_cast<kwsys_stl::string::size_type>(
+ this->endp[0] - searchstring);
+}
+
+/**
+ * Returns true if two regular expressions have different
+ * compiled program for pattern matching.
+ */
+inline bool RegularExpression::operator!= (const RegularExpression& r) const
+{
+ return(!(*this == r));
+}
+
+/**
+ * Returns true if a valid regular expression is compiled
+ * and ready for pattern matching.
+ */
+inline bool RegularExpression::is_valid () const
+{
+ return (this->program != 0);
+}
+
+
+inline void RegularExpression::set_invalid ()
+{
+//#ifndef WIN32
+ delete [] this->program;
+//#endif
+ this->program = 0;
+}
+
+/**
+ * Return start index of nth submatch. start(0) is the start of the full match.
+ */
+inline kwsys_stl::string::size_type RegularExpression::start(int n) const
+{
+ return static_cast<kwsys_stl::string::size_type>(
+ this->startp[n] - searchstring);
+}
+
+
+/**
+ * Return end index of nth submatch. end(0) is the end of the full match.
+ */
+inline kwsys_stl::string::size_type RegularExpression::end(int n) const
+{
+ return static_cast<kwsys_stl::string::size_type>(
+ this->endp[n] - searchstring);
+}
+
+/**
+ * Return nth submatch as a string.
+ */
+inline kwsys_stl::string RegularExpression::match(int n) const
+{
+ if (this->startp[n]==0)
+ {
+ return kwsys_stl::string("");
+ }
+ else
+ {
+ return kwsys_stl::string(this->startp[n],
+ static_cast<kwsys_stl::string::size_type>(
+ this->endp[n] - this->startp[n]));
+ }
+}
+
+} // namespace @KWSYS_NAMESPACE@
+
+/* Undefine temporary macro. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsys_stl
+#endif
+
+#endif
diff --git a/Source/kwsys/SharedForward.h.in b/Source/kwsys/SharedForward.h.in
new file mode 100644
index 0000000000..7ff29b40ad
--- /dev/null
+++ b/Source/kwsys/SharedForward.h.in
@@ -0,0 +1,922 @@
+/*============================================================================
+ 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@_SharedForward_h
+#define @KWSYS_NAMESPACE@_SharedForward_h
+
+/*
+ This header is used to create a forwarding executable sets up the
+ shared library search path and replaces itself with a real
+ executable. This is useful when creating installations on UNIX with
+ shared libraries that will run from any install directory. Typical
+ usage:
+
+ #if defined(CMAKE_INTDIR)
+ # define CONFIG_DIR_PRE CMAKE_INTDIR "/"
+ # define CONFIG_DIR_POST "/" CMAKE_INTDIR
+ #else
+ # define CONFIG_DIR_PRE ""
+ # define CONFIG_DIR_POST ""
+ #endif
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD "/path/to/foo-build/bin"
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD "." CONFIG_DIR_POST
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL "../lib/foo-1.2"
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD CONFIG_DIR_PRE "foo-real"
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL "../lib/foo-1.2/foo-real"
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND "--command"
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT "--print"
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD "--ldd"
+ #if defined(CMAKE_INTDIR)
+ # define @KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME CMAKE_INTDIR
+ #endif
+ #include <@KWSYS_NAMESPACE@/SharedForward.h>
+ int main(int argc, char** argv)
+ {
+ return @KWSYS_NAMESPACE@_shared_forward_to_real(argc, argv);
+ }
+
+ Specify search and executable paths relative to the forwarding
+ executable location or as full paths. Include no trailing slash.
+ In the case of a multi-configuration build, when CMAKE_INTDIR is
+ defined, the DIR_BUILD setting should point at the directory above
+ the executable (the one containing the per-configuration
+ subdirectory specified by CMAKE_INTDIR). Then PATH_BUILD entries
+ and EXE_BUILD should be specified relative to this location and use
+ CMAKE_INTDIR as necessary. In the above example imagine appending
+ the PATH_BUILD or EXE_BUILD setting to the DIR_BUILD setting. The
+ result should form a valid path with per-configuration subdirectory.
+
+ Additional paths may be specified in the PATH_BUILD and PATH_INSTALL
+ variables by using comma-separated strings. For example:
+
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD \
+ "." CONFIG_DIR_POST, "/path/to/bar-build" CONFIG_DIR_POST
+ #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL \
+ "../lib/foo-1.2", "../lib/bar-4.5"
+
+ See the comments below for specific explanations of each macro.
+*/
+
+/*--------------------------------------------------------------------------*/
+
+/* Full path to the directory in which this executable is built. Do
+ not include a trailing slash. */
+#if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD)
+# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD"
+#endif
+#if !defined(KWSYS_SHARED_FORWARD_DIR_BUILD)
+# define KWSYS_SHARED_FORWARD_DIR_BUILD @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD
+#endif
+
+/* Library search path for build tree. */
+#if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD)
+# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD"
+#endif
+#if !defined(KWSYS_SHARED_FORWARD_PATH_BUILD)
+# define KWSYS_SHARED_FORWARD_PATH_BUILD @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD
+#endif
+
+/* Library search path for install tree. */
+#if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL)
+# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL"
+#endif
+#if !defined(KWSYS_SHARED_FORWARD_PATH_INSTALL)
+# define KWSYS_SHARED_FORWARD_PATH_INSTALL @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL
+#endif
+
+/* The real executable to which to forward in the build tree. */
+#if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD)
+# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD"
+#endif
+#if !defined(KWSYS_SHARED_FORWARD_EXE_BUILD)
+# define KWSYS_SHARED_FORWARD_EXE_BUILD @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD
+#endif
+
+/* The real executable to which to forward in the install tree. */
+#if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL)
+# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL"
+#endif
+#if !defined(KWSYS_SHARED_FORWARD_EXE_INSTALL)
+# define KWSYS_SHARED_FORWARD_EXE_INSTALL @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL
+#endif
+
+/* The configuration name with which this executable was built (Debug/Release). */
+#if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME)
+# define KWSYS_SHARED_FORWARD_CONFIG_NAME @KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME
+#else
+# undef KWSYS_SHARED_FORWARD_CONFIG_NAME
+#endif
+
+/* Create command line option to replace executable. */
+#if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND)
+# if !defined(KWSYS_SHARED_FORWARD_OPTION_COMMAND)
+# define KWSYS_SHARED_FORWARD_OPTION_COMMAND @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND
+# endif
+#else
+# undef KWSYS_SHARED_FORWARD_OPTION_COMMAND
+#endif
+
+/* Create command line option to print environment setting and exit. */
+#if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT)
+# if !defined(KWSYS_SHARED_FORWARD_OPTION_PRINT)
+# define KWSYS_SHARED_FORWARD_OPTION_PRINT @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT
+# endif
+#else
+# undef KWSYS_SHARED_FORWARD_OPTION_PRINT
+#endif
+
+/* Create command line option to run ldd or equivalent. */
+#if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD)
+# if !defined(KWSYS_SHARED_FORWARD_OPTION_LDD)
+# define KWSYS_SHARED_FORWARD_OPTION_LDD @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD
+# endif
+#else
+# undef KWSYS_SHARED_FORWARD_OPTION_LDD
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* Include needed system headers. */
+
+#include <stddef.h> /* size_t */
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# include <io.h>
+# include <windows.h>
+# include <process.h>
+# define KWSYS_SHARED_FORWARD_ESCAPE_ARGV /* re-escape argv for execvp */
+#else
+# include <unistd.h>
+# include <sys/stat.h>
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* Configuration for this platform. */
+
+/* The path separator for this platform. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# define KWSYS_SHARED_FORWARD_PATH_SEP ';'
+# define KWSYS_SHARED_FORWARD_PATH_SLASH '\\'
+#else
+# define KWSYS_SHARED_FORWARD_PATH_SEP ':'
+# define KWSYS_SHARED_FORWARD_PATH_SLASH '/'
+#endif
+static const char kwsys_shared_forward_path_sep[2] = {KWSYS_SHARED_FORWARD_PATH_SEP, 0};
+static const char kwsys_shared_forward_path_slash[2] = {KWSYS_SHARED_FORWARD_PATH_SLASH, 0};
+
+/* The maximum length of a file name. */
+#if defined(PATH_MAX)
+# define KWSYS_SHARED_FORWARD_MAXPATH PATH_MAX
+#elif defined(MAXPATHLEN)
+# define KWSYS_SHARED_FORWARD_MAXPATH MAXPATHLEN
+#else
+# define KWSYS_SHARED_FORWARD_MAXPATH 16384
+#endif
+
+/* Select the environment variable holding the shared library runtime
+ search path for this platform and build configuration. Also select
+ ldd command equivalent. */
+
+/* Linux */
+#if defined(__linux)
+# define KWSYS_SHARED_FORWARD_LDD "ldd"
+# define KWSYS_SHARED_FORWARD_LDD_N 1
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
+
+/* FreeBSD */
+#elif defined(__FreeBSD__)
+# define KWSYS_SHARED_FORWARD_LDD "ldd"
+# define KWSYS_SHARED_FORWARD_LDD_N 1
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
+
+/* OpenBSD */
+#elif defined(__OpenBSD__)
+# define KWSYS_SHARED_FORWARD_LDD "ldd"
+# define KWSYS_SHARED_FORWARD_LDD_N 1
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
+
+/* OSX */
+#elif defined(__APPLE__)
+# define KWSYS_SHARED_FORWARD_LDD "otool", "-L"
+# define KWSYS_SHARED_FORWARD_LDD_N 2
+# define KWSYS_SHARED_FORWARD_LDPATH "DYLD_LIBRARY_PATH"
+
+/* AIX */
+#elif defined(_AIX)
+# define KWSYS_SHARED_FORWARD_LDD "dump", "-H"
+# define KWSYS_SHARED_FORWARD_LDD_N 2
+# define KWSYS_SHARED_FORWARD_LDPATH "LIBPATH"
+
+/* SUN */
+#elif defined(__sun)
+# define KWSYS_SHARED_FORWARD_LDD "ldd"
+# define KWSYS_SHARED_FORWARD_LDD_N 1
+# include <sys/isa_defs.h>
+# if defined(_ILP32)
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
+# elif defined(_LP64)
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH_64"
+# endif
+
+/* HP-UX */
+#elif defined(__hpux)
+# define KWSYS_SHARED_FORWARD_LDD "chatr"
+# define KWSYS_SHARED_FORWARD_LDD_N 1
+# if defined(__LP64__)
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
+# else
+# define KWSYS_SHARED_FORWARD_LDPATH "SHLIB_PATH"
+# endif
+
+/* SGI MIPS */
+#elif defined(__sgi) && defined(_MIPS_SIM)
+# define KWSYS_SHARED_FORWARD_LDD "ldd"
+# define KWSYS_SHARED_FORWARD_LDD_N 1
+# if _MIPS_SIM == _ABIO32
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
+# elif _MIPS_SIM == _ABIN32
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARYN32_PATH"
+# elif _MIPS_SIM == _ABI64
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY64_PATH"
+# endif
+
+/* Cygwin */
+#elif defined(__CYGWIN__)
+# define KWSYS_SHARED_FORWARD_LDD "cygcheck" /* TODO: cygwin 1.7 has ldd */
+# define KWSYS_SHARED_FORWARD_LDD_N 1
+# define KWSYS_SHARED_FORWARD_LDPATH "PATH"
+
+/* Windows */
+#elif defined(_WIN32)
+# define KWSYS_SHARED_FORWARD_LDPATH "PATH"
+
+/* Guess on this unknown system. */
+#else
+# define KWSYS_SHARED_FORWARD_LDD "ldd"
+# define KWSYS_SHARED_FORWARD_LDD_N 1
+# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
+#endif
+
+#ifdef KWSYS_SHARED_FORWARD_ESCAPE_ARGV
+/*--------------------------------------------------------------------------*/
+typedef struct kwsys_sf_arg_info_s
+{
+ const char* arg;
+ int size;
+ int quote;
+} kwsys_sf_arg_info;
+
+/*--------------------------------------------------------------------------*/
+static kwsys_sf_arg_info kwsys_sf_get_arg_info(const char* in)
+{
+ /* Initialize information. */
+ kwsys_sf_arg_info info;
+
+ /* String iterator. */
+ const char* c;
+
+ /* Keep track of how many backslashes have been encountered in a row. */
+ int windows_backslashes = 0;
+
+ /* Start with the length of the original argument, plus one for
+ either a terminating null or a separating space. */
+ info.arg = in;
+ info.size = (int)strlen(in) + 1;
+ info.quote = 0;
+
+ /* Scan the string for characters that require escaping or quoting. */
+ for(c=in; *c; ++c)
+ {
+ /* Check whether this character needs quotes. */
+ if(strchr(" \t?'#&<>|^", *c))
+ {
+ info.quote = 1;
+ }
+
+ /* On Windows only backslashes and double-quotes need escaping. */
+ if(*c == '\\')
+ {
+ /* Found a backslash. It may need to be escaped later. */
+ ++windows_backslashes;
+ }
+ else if(*c == '"')
+ {
+ /* Found a double-quote. We need to escape it and all
+ immediately preceding backslashes. */
+ info.size += windows_backslashes + 1;
+ windows_backslashes = 0;
+ }
+ else
+ {
+ /* Found another character. This eliminates the possibility
+ that any immediately preceding backslashes will be
+ escaped. */
+ windows_backslashes = 0;
+ }
+ }
+
+ /* Check whether the argument needs surrounding quotes. */
+ if(info.quote)
+ {
+ /* Surrounding quotes are needed. Allocate space for them. */
+ info.size += 2;
+
+ /* We must escape all ending backslashes when quoting on windows. */
+ info.size += windows_backslashes;
+ }
+
+ return info;
+}
+
+/*--------------------------------------------------------------------------*/
+static char* kwsys_sf_get_arg(kwsys_sf_arg_info info, char* out)
+{
+ /* String iterator. */
+ const char* c;
+
+ /* Keep track of how many backslashes have been encountered in a row. */
+ int windows_backslashes = 0;
+
+ /* Whether the argument must be quoted. */
+ if(info.quote)
+ {
+ /* Add the opening quote for this argument. */
+ *out++ = '"';
+ }
+
+ /* Scan the string for characters that require escaping or quoting. */
+ for(c=info.arg; *c; ++c)
+ {
+ /* On Windows only backslashes and double-quotes need escaping. */
+ if(*c == '\\')
+ {
+ /* Found a backslash. It may need to be escaped later. */
+ ++windows_backslashes;
+ }
+ else if(*c == '"')
+ {
+ /* Found a double-quote. Escape all immediately preceding
+ backslashes. */
+ while(windows_backslashes > 0)
+ {
+ --windows_backslashes;
+ *out++ = '\\';
+ }
+
+ /* Add the backslash to escape the double-quote. */
+ *out++ = '\\';
+ }
+ else
+ {
+ /* We encountered a normal character. This eliminates any
+ escaping needed for preceding backslashes. */
+ windows_backslashes = 0;
+ }
+
+ /* Store this character. */
+ *out++ = *c;
+ }
+
+ if(info.quote)
+ {
+ /* Add enough backslashes to escape any trailing ones. */
+ while(windows_backslashes > 0)
+ {
+ --windows_backslashes;
+ *out++ = '\\';
+ }
+
+ /* Add the closing quote for this argument. */
+ *out++ = '"';
+ }
+
+ /* Store a terminating null without incrementing. */
+ *out = 0;
+
+ return out;
+}
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* Function to convert a logical or relative path to a physical full path. */
+static int kwsys_shared_forward_realpath(const char* in_path, char* out_path)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Implementation for Windows. */
+ DWORD n = GetFullPathNameA(in_path, KWSYS_SHARED_FORWARD_MAXPATH,
+ out_path, 0);
+ return n > 0 && n <= KWSYS_SHARED_FORWARD_MAXPATH;
+#else
+ /* Implementation for UNIX. */
+ return realpath(in_path, out_path) != 0;
+#endif
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsys_shared_forward_samepath(const char* file1, const char* file2)
+{
+#if defined(_WIN32)
+ int result = 0;
+ HANDLE h1 = CreateFileA(file1, GENERIC_READ, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ HANDLE h2 = CreateFileA(file2, GENERIC_READ, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ if(h1 != INVALID_HANDLE_VALUE && h2 != INVALID_HANDLE_VALUE)
+ {
+ BY_HANDLE_FILE_INFORMATION fi1;
+ BY_HANDLE_FILE_INFORMATION fi2;
+ GetFileInformationByHandle(h1, &fi1);
+ GetFileInformationByHandle(h2, &fi2);
+ result = (fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber &&
+ fi1.nFileIndexHigh == fi2.nFileIndexHigh &&
+ fi1.nFileIndexLow == fi2.nFileIndexLow);
+ }
+ CloseHandle(h1);
+ CloseHandle(h2);
+ return result;
+#else
+ struct stat fs1, fs2;
+ return (stat(file1, &fs1) == 0 && stat(file2, &fs2) == 0 &&
+ memcmp(&fs2.st_dev, &fs1.st_dev, sizeof(fs1.st_dev)) == 0 &&
+ memcmp(&fs2.st_ino, &fs1.st_ino, sizeof(fs1.st_ino)) == 0 &&
+ fs2.st_size == fs1.st_size);
+#endif
+}
+
+/*--------------------------------------------------------------------------*/
+/* Function to report a system error message. */
+static void kwsys_shared_forward_strerror(char* message)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Implementation for Windows. */
+ DWORD original = GetLastError();
+ DWORD length = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS, 0, original,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ message, KWSYS_SHARED_FORWARD_MAXPATH, 0);
+ if(length < 1 || length > KWSYS_SHARED_FORWARD_MAXPATH)
+ {
+ /* FormatMessage failed. Use a default message. */
+ _snprintf(message, KWSYS_SHARED_FORWARD_MAXPATH,
+ "Error 0x%X (FormatMessage failed with error 0x%X)",
+ original, GetLastError());
+ }
+#else
+ /* Implementation for UNIX. */
+ strcpy(message, strerror(errno));
+#endif
+}
+
+/*--------------------------------------------------------------------------*/
+/* Functions to execute a child process. */
+static void kwsys_shared_forward_execvp(const char* cmd,
+ char const* const* argv)
+{
+#ifdef KWSYS_SHARED_FORWARD_ESCAPE_ARGV
+ /* Count the number of arguments. */
+ int argc = 0;
+ {
+ char const* const* argvc;
+ for(argvc = argv; *argvc; ++argvc,++argc) {}
+ }
+
+ /* Create the escaped arguments. */
+ {
+ char** nargv = (char**)malloc((argc+1) * sizeof(char*));
+ int i;
+ for(i=0; i < argc; ++i)
+ {
+ kwsys_sf_arg_info info = kwsys_sf_get_arg_info(argv[i]);
+ nargv[i] = (char*)malloc(info.size);
+ kwsys_sf_get_arg(info, nargv[i]);
+ }
+ nargv[argc] = 0;
+
+ /* Replace the command line to be used. */
+ argv = (char const* const*)nargv;
+ }
+#endif
+
+ /* Invoke the child process. */
+#if defined(_MSC_VER)
+ _execvp(cmd, argv);
+#elif defined(__MINGW32__) && !defined(__MINGW64__)
+ execvp(cmd, argv);
+#else
+ execvp(cmd, (char* const*)argv);
+#endif
+}
+
+/*--------------------------------------------------------------------------*/
+/* Function to get the directory containing the given file or directory. */
+static void kwsys_shared_forward_dirname(const char* begin, char* result)
+{
+ /* Find the location of the last slash. */
+ int last_slash_index = -1;
+ const char* end = begin + strlen(begin);
+ for(;begin <= end && last_slash_index < 0; --end)
+ {
+ if(*end == '/' || *end == '\\')
+ {
+ last_slash_index = (int)(end-begin);
+ }
+ }
+
+ /* Handle each case of the index of the last slash. */
+ if(last_slash_index < 0)
+ {
+ /* No slashes. */
+ strcpy(result, ".");
+ }
+ else if(last_slash_index == 0)
+ {
+ /* Only one leading slash. */
+ strcpy(result, kwsys_shared_forward_path_slash);
+ }
+#if defined(_WIN32)
+ else if(last_slash_index == 2 && begin[1] == ':')
+ {
+ /* Only one leading drive letter and slash. */
+ strncpy(result, begin, (size_t)last_slash_index);
+ result[last_slash_index] = KWSYS_SHARED_FORWARD_PATH_SLASH;
+ result[last_slash_index+1] = 0;
+ }
+#endif
+ else
+ {
+ /* A non-leading slash. */
+ strncpy(result, begin, (size_t)last_slash_index);
+ result[last_slash_index] = 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+/* Function to check if a file exists and is executable. */
+static int kwsys_shared_forward_is_executable(const char* f)
+{
+#if defined(_MSC_VER)
+# define KWSYS_SHARED_FORWARD_ACCESS _access
+#else
+# define KWSYS_SHARED_FORWARD_ACCESS access
+#endif
+#if defined(X_OK)
+# define KWSYS_SHARED_FORWARD_ACCESS_OK X_OK
+#else
+# define KWSYS_SHARED_FORWARD_ACCESS_OK 04
+#endif
+ if(KWSYS_SHARED_FORWARD_ACCESS(f, KWSYS_SHARED_FORWARD_ACCESS_OK) == 0)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+/* Function to locate the executable currently running. */
+static int kwsys_shared_forward_self_path(const char* argv0, char* result)
+{
+ /* Check whether argv0 has a slash. */
+ int has_slash = 0;
+ const char* p = argv0;
+ for(;*p && !has_slash; ++p)
+ {
+ if(*p == '/' || *p == '\\')
+ {
+ has_slash = 1;
+ }
+ }
+
+ if(has_slash)
+ {
+ /* There is a slash. Use the dirname of the given location. */
+ kwsys_shared_forward_dirname(argv0, result);
+ return 1;
+ }
+ else
+ {
+ /* There is no slash. Search the PATH for the executable. */
+ const char* path = getenv("PATH");
+ const char* begin = path;
+ const char* end = begin + (begin?strlen(begin):0);
+ const char* first = begin;
+ while(first != end)
+ {
+ /* Store the end of this path entry. */
+ const char* last;
+
+ /* Skip all path separators. */
+ for(;*first && *first == KWSYS_SHARED_FORWARD_PATH_SEP; ++first);
+
+ /* Find the next separator. */
+ for(last = first;*last && *last != KWSYS_SHARED_FORWARD_PATH_SEP; ++last);
+
+ /* If we got a non-empty directory, look for the executable there. */
+ if(first < last)
+ {
+ /* Determine the length without trailing slash. */
+ size_t length = (size_t)(last-first);
+ if(*(last-1) == '/' || *(last-1) == '\\')
+ {
+ --length;
+ }
+
+ /* Construct the name of the executable in this location. */
+ strncpy(result, first, length);
+ result[length] = KWSYS_SHARED_FORWARD_PATH_SLASH;
+ strcpy(result+(length)+1, argv0);
+
+ /* Check if it exists and is executable. */
+ if(kwsys_shared_forward_is_executable(result))
+ {
+ /* Found it. */
+ result[length] = 0;
+ return 1;
+ }
+ }
+
+ /* Move to the next directory in the path. */
+ first = last;
+ }
+ }
+
+ /* We could not find the executable. */
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Function to convert a specified path to a full path. If it is not
+ already full, it is taken relative to the self path. */
+static int kwsys_shared_forward_fullpath(const char* self_path,
+ const char* in_path,
+ char* result,
+ const char* desc)
+{
+ /* Check the specified path type. */
+ if(in_path[0] == '/')
+ {
+ /* Already a full path. */
+ strcpy(result, in_path);
+ }
+#if defined(_WIN32)
+ else if(in_path[0] && in_path[1] == ':')
+ {
+ /* Already a full path. */
+ strcpy(result, in_path);
+ }
+#endif
+ else
+ {
+ /* Relative to self path. */
+ char temp_path[KWSYS_SHARED_FORWARD_MAXPATH];
+ strcpy(temp_path, self_path);
+ strcat(temp_path, kwsys_shared_forward_path_slash);
+ strcat(temp_path, in_path);
+ if(!kwsys_shared_forward_realpath(temp_path, result))
+ {
+ if(desc)
+ {
+ char msgbuf[KWSYS_SHARED_FORWARD_MAXPATH];
+ kwsys_shared_forward_strerror(msgbuf);
+ fprintf(stderr, "Error converting %s \"%s\" to real path: %s\n",
+ desc, temp_path, msgbuf);
+ }
+ return 0;
+ }
+ }
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Function to compute the library search path and executable name
+ based on the self path. */
+static int kwsys_shared_forward_get_settings(const char* self_path,
+ char* ldpath, char* exe)
+{
+ /* Possible search paths. */
+ static const char* search_path_build[] = {KWSYS_SHARED_FORWARD_PATH_BUILD, 0};
+ static const char* search_path_install[] = {KWSYS_SHARED_FORWARD_PATH_INSTALL, 0};
+
+ /* Chosen paths. */
+ const char** search_path;
+ const char* exe_path;
+
+ /* Get the real name of the build and self paths. */
+#if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
+ char build_path[] = KWSYS_SHARED_FORWARD_DIR_BUILD "/" KWSYS_SHARED_FORWARD_CONFIG_NAME;
+ char self_path_logical[KWSYS_SHARED_FORWARD_MAXPATH];
+#else
+ char build_path[] = KWSYS_SHARED_FORWARD_DIR_BUILD;
+ const char* self_path_logical = self_path;
+#endif
+ char build_path_real[KWSYS_SHARED_FORWARD_MAXPATH];
+ char self_path_real[KWSYS_SHARED_FORWARD_MAXPATH];
+ if(!kwsys_shared_forward_realpath(self_path, self_path_real))
+ {
+ char msgbuf[KWSYS_SHARED_FORWARD_MAXPATH];
+ kwsys_shared_forward_strerror(msgbuf);
+ fprintf(stderr, "Error converting self path \"%s\" to real path: %s\n",
+ self_path, msgbuf);
+ return 0;
+ }
+
+ /* Check whether we are running in the build tree or an install tree. */
+ if(kwsys_shared_forward_realpath(build_path, build_path_real) &&
+ kwsys_shared_forward_samepath(self_path_real, build_path_real))
+ {
+ /* Running in build tree. Use the build path and exe. */
+ search_path = search_path_build;
+#if defined(_WIN32)
+ exe_path = KWSYS_SHARED_FORWARD_EXE_BUILD ".exe";
+#else
+ exe_path = KWSYS_SHARED_FORWARD_EXE_BUILD;
+#endif
+
+#if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
+ /* Remove the configuration directory from self_path. */
+ kwsys_shared_forward_dirname(self_path, self_path_logical);
+#endif
+ }
+ else
+ {
+ /* Running in install tree. Use the install path and exe. */
+ search_path = search_path_install;
+#if defined(_WIN32)
+ exe_path = KWSYS_SHARED_FORWARD_EXE_INSTALL ".exe";
+#else
+ exe_path = KWSYS_SHARED_FORWARD_EXE_INSTALL;
+#endif
+
+#if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
+ /* Use the original self path directory. */
+ strcpy(self_path_logical, self_path);
+#endif
+ }
+
+ /* Construct the runtime search path. */
+ {
+ const char** dir;
+ for(dir = search_path; *dir; ++dir)
+ {
+ /* Add separator between path components. */
+ if(dir != search_path)
+ {
+ strcat(ldpath, kwsys_shared_forward_path_sep);
+ }
+
+ /* Add this path component. */
+ if(!kwsys_shared_forward_fullpath(self_path_logical, *dir,
+ ldpath+strlen(ldpath),
+ "runtime path entry"))
+ {
+ return 0;
+ }
+ }
+ }
+
+ /* Construct the executable location. */
+ if(!kwsys_shared_forward_fullpath(self_path_logical, exe_path, exe,
+ "executable file"))
+ {
+ return 0;
+ }
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Function to print why execution of a command line failed. */
+static void kwsys_shared_forward_print_failure(char const* const* argv)
+{
+ char msg[KWSYS_SHARED_FORWARD_MAXPATH];
+ char const* const* arg = argv;
+ kwsys_shared_forward_strerror(msg);
+ fprintf(stderr, "Error running");
+ for(; *arg; ++arg)
+ {
+ fprintf(stderr, " \"%s\"", *arg);
+ }
+ fprintf(stderr, ": %s\n", msg);
+}
+
+/* Static storage space to store the updated environment variable. */
+static char kwsys_shared_forward_ldpath[KWSYS_SHARED_FORWARD_MAXPATH*16] = KWSYS_SHARED_FORWARD_LDPATH "=";
+
+/*--------------------------------------------------------------------------*/
+/* Main driver function to be called from main. */
+static int @KWSYS_NAMESPACE@_shared_forward_to_real(int argc, char** argv_in)
+{
+ char const** argv = (char const**)argv_in;
+ /* Get the directory containing this executable. */
+ char self_path[KWSYS_SHARED_FORWARD_MAXPATH];
+ if(kwsys_shared_forward_self_path(argv[0], self_path))
+ {
+ /* Found this executable. Use it to get the library directory. */
+ char exe[KWSYS_SHARED_FORWARD_MAXPATH];
+ if(kwsys_shared_forward_get_settings(self_path,
+ kwsys_shared_forward_ldpath, exe))
+ {
+ /* Append the old runtime search path. */
+ const char* old_ldpath = getenv(KWSYS_SHARED_FORWARD_LDPATH);
+ if(old_ldpath)
+ {
+ strcat(kwsys_shared_forward_ldpath, kwsys_shared_forward_path_sep);
+ strcat(kwsys_shared_forward_ldpath, old_ldpath);
+ }
+
+ /* Store the environment variable. */
+ putenv(kwsys_shared_forward_ldpath);
+
+#if defined(KWSYS_SHARED_FORWARD_OPTION_COMMAND)
+ /* Look for the command line replacement option. */
+ if(argc > 1 && strcmp(argv[1], KWSYS_SHARED_FORWARD_OPTION_COMMAND) == 0)
+ {
+ if(argc > 2)
+ {
+ /* Use the command line given. */
+ strcpy(exe, argv[2]);
+ argv += 2;
+ argc -= 2;
+ }
+ else
+ {
+ /* The option was not given an executable. */
+ fprintf(stderr, "Option " KWSYS_SHARED_FORWARD_OPTION_COMMAND
+ " must be followed by a command line.\n");
+ return 1;
+ }
+ }
+#endif
+
+#if defined(KWSYS_SHARED_FORWARD_OPTION_PRINT)
+ /* Look for the print command line option. */
+ if(argc > 1 && strcmp(argv[1], KWSYS_SHARED_FORWARD_OPTION_PRINT) == 0)
+ {
+ fprintf(stdout, "%s\n", kwsys_shared_forward_ldpath);
+ fprintf(stdout, "%s\n", exe);
+ return 0;
+ }
+#endif
+
+#if defined(KWSYS_SHARED_FORWARD_OPTION_LDD)
+ /* Look for the ldd command line option. */
+ if(argc > 1 && strcmp(argv[1], KWSYS_SHARED_FORWARD_OPTION_LDD) == 0)
+ {
+# if defined(KWSYS_SHARED_FORWARD_LDD)
+ /* Use the named ldd-like executable and arguments. */
+ char const* ldd_argv[] = {KWSYS_SHARED_FORWARD_LDD, 0, 0};
+ ldd_argv[KWSYS_SHARED_FORWARD_LDD_N] = exe;
+ kwsys_shared_forward_execvp(ldd_argv[0], ldd_argv);
+
+ /* Report why execution failed. */
+ kwsys_shared_forward_print_failure(ldd_argv);
+ return 1;
+# else
+ /* We have no ldd-like executable available on this platform. */
+ fprintf(stderr, "No ldd-like tool is known to this executable.\n");
+ return 1;
+# endif
+ }
+#endif
+
+ /* Replace this process with the real executable. */
+ argv[0] = exe;
+ kwsys_shared_forward_execvp(argv[0], argv);
+
+ /* Report why execution failed. */
+ kwsys_shared_forward_print_failure(argv);
+ }
+ else
+ {
+ /* Could not convert self path to the library directory. */
+ }
+ }
+ else
+ {
+ /* Could not find this executable. */
+ fprintf(stderr, "Error locating executable \"%s\".\n", argv[0]);
+ }
+
+ /* Avoid unused argument warning. */
+ (void)argc;
+
+ /* Exit with failure. */
+ return 1;
+}
+
+#else
+# error "@KWSYS_NAMESPACE@/SharedForward.h should be included only once."
+#endif
diff --git a/Source/kwsys/String.c b/Source/kwsys/String.c
new file mode 100644
index 0000000000..ed4a6c52a8
--- /dev/null
+++ b/Source/kwsys/String.c
@@ -0,0 +1,115 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#ifdef KWSYS_STRING_C
+/*
+All code in this source file is conditionally compiled to work-around
+template definition auto-search on VMS. Other source files in this
+directory that use the stl string cause the compiler to load this
+source to try to get the definition of the string template. This
+condition blocks the compiler from seeing the symbols defined here.
+*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(String.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "String.h.in"
+#endif
+
+/* Select an implementation for strcasecmp. */
+#if defined(_MSC_VER)
+# define KWSYS_STRING_USE_STRICMP
+# include <string.h>
+#elif defined(__GNUC__)
+# define KWSYS_STRING_USE_STRCASECMP
+# include <strings.h>
+#else
+/* Table to convert upper case letters to lower case and leave all
+ other characters alone. */
+static char kwsysString_strcasecmp_tolower[] =
+{
+ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
+ '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
+ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
+ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
+ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
+ '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
+ '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
+ '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
+ '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+ '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
+ '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+ '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
+ '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
+ '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
+ '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
+ '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
+ '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
+ '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
+ '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
+ '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
+ '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
+ '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
+ '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
+ '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
+ '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
+ '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
+ '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
+ '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377'
+};
+#endif
+
+/*--------------------------------------------------------------------------*/
+int kwsysString_strcasecmp(const char* lhs, const char* rhs)
+{
+#if defined(KWSYS_STRING_USE_STRICMP)
+ return _stricmp(lhs, rhs);
+#elif defined(KWSYS_STRING_USE_STRCASECMP)
+ return strcasecmp(lhs, rhs);
+#else
+ const char* const lower = kwsysString_strcasecmp_tolower;
+ unsigned char const* us1 = (unsigned char const*)lhs;
+ unsigned char const* us2 = (unsigned char const*)rhs;
+ int result;
+ while((result = lower[*us1] - lower[*us2++], result == 0) && *us1++)
+ {
+ }
+ return result;
+#endif
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysString_strncasecmp(const char* lhs, const char* rhs, size_t n)
+{
+#if defined(KWSYS_STRING_USE_STRICMP)
+ return _strnicmp(lhs, rhs, n);
+#elif defined(KWSYS_STRING_USE_STRCASECMP)
+ return strncasecmp(lhs, rhs, n);
+#else
+ const char* const lower = kwsysString_strcasecmp_tolower;
+ unsigned char const* us1 = (unsigned char const*)lhs;
+ unsigned char const* us2 = (unsigned char const*)rhs;
+ int result = 0;
+ while(n && (result = lower[*us1] - lower[*us2++], result == 0) && *us1++)
+ {
+ --n;
+ }
+ return result;
+#endif
+}
+
+#endif /* KWSYS_STRING_C */
diff --git a/Source/kwsys/String.h.in b/Source/kwsys/String.h.in
new file mode 100644
index 0000000000..f5bab6e1a6
--- /dev/null
+++ b/Source/kwsys/String.h.in
@@ -0,0 +1,67 @@
+/*============================================================================
+ 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@_String_h
+#define @KWSYS_NAMESPACE@_String_h
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+
+#include <stddef.h> /* size_t */
+
+/* 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@_EXPORT
+#endif
+#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsysString_strcasecmp kwsys_ns(String_strcasecmp)
+# define kwsysString_strncasecmp kwsys_ns(String_strncasecmp)
+#endif
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/**
+ * Compare two strings ignoring the case of the characters. The
+ * integer returned is negative, zero, or positive if the first string
+ * is found to be less than, equal to, or greater than the second
+ * string, respectively.
+ */
+kwsysEXPORT int kwsysString_strcasecmp(const char* lhs, const char* rhs);
+
+/**
+ * Identical to String_strcasecmp except that only the first n
+ * characters are considered.
+ */
+kwsysEXPORT int kwsysString_strncasecmp(const char* lhs, const char* rhs,
+ size_t n);
+
+#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 !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsysString_strcasecmp
+# undef kwsysString_strncasecmp
+# endif
+#endif
+
+#endif
diff --git a/Source/kwsys/String.hxx.in b/Source/kwsys/String.hxx.in
new file mode 100644
index 0000000000..4386c9eb72
--- /dev/null
+++ b/Source/kwsys/String.hxx.in
@@ -0,0 +1,65 @@
+/*============================================================================
+ 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@_String_hxx
+#define @KWSYS_NAMESPACE@_String_hxx
+
+#include <@KWSYS_NAMESPACE@/stl/string>
+
+namespace @KWSYS_NAMESPACE@
+{
+
+/** \class String
+ * \brief Short-name version of the STL basic_string class template.
+ *
+ * The standard library "string" type is actually a typedef for
+ * "basic_string<..long argument list..>". This string class is
+ * simply a subclass of this type with the same interface so that the
+ * name is shorter in debugging symbols and error messages.
+ */
+class String: public @KWSYS_NAMESPACE@_stl::string
+{
+ /** The original string type. */
+ typedef @KWSYS_NAMESPACE@_stl::string stl_string;
+
+public:
+
+ /** String member types. */
+ typedef stl_string::value_type value_type;
+ typedef stl_string::pointer pointer;
+ typedef stl_string::reference reference;
+ typedef stl_string::const_reference const_reference;
+ typedef stl_string::size_type size_type;
+ typedef stl_string::difference_type difference_type;
+ typedef stl_string::iterator iterator;
+ typedef stl_string::const_iterator const_iterator;
+ typedef stl_string::reverse_iterator reverse_iterator;
+ typedef stl_string::const_reverse_iterator const_reverse_iterator;
+
+ /** String constructors. */
+ String(): stl_string() {}
+ String(const value_type* s): stl_string(s) {}
+ String(const value_type* s, size_type n): stl_string(s, n) {}
+ String(const stl_string& s, size_type pos=0, size_type n=npos):
+ stl_string(s, pos, n) {}
+}; // End Class: String
+
+#if defined(__WATCOMC__)
+inline bool operator<(String const& l, String const& r)
+ {
+ return (static_cast<@KWSYS_NAMESPACE@_stl::string const&>(l) <
+ static_cast<@KWSYS_NAMESPACE@_stl::string const&>(r));
+ }
+#endif
+
+} // namespace @KWSYS_NAMESPACE@
+
+#endif
diff --git a/Source/kwsys/System.c b/Source/kwsys/System.c
new file mode 100644
index 0000000000..1ee26fac58
--- /dev/null
+++ b/Source/kwsys/System.c
@@ -0,0 +1,882 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(System.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "System.h.in"
+#endif
+
+#include <stddef.h> /* ptrdiff_t */
+#include <stdlib.h> /* malloc, free */
+#include <string.h> /* strlen */
+#include <ctype.h> /* isalpha */
+
+#include <stdio.h>
+
+#if defined(KWSYS_C_HAS_PTRDIFF_T) && KWSYS_C_HAS_PTRDIFF_T
+typedef ptrdiff_t kwsysSystem_ptrdiff_t;
+#else
+typedef int kwsysSystem_ptrdiff_t;
+#endif
+
+/*
+
+Notes:
+
+Make variable replacements open a can of worms. Sometimes they should
+be quoted and sometimes not. Sometimes their replacement values are
+already quoted.
+
+VS variables cause problems. In order to pass the referenced value
+with spaces the reference must be quoted. If the variable value ends
+in a backslash then it will escape the ending quote! In order to make
+the ending backslash appear we need this:
+
+ "$(InputDir)\"
+
+However if there is not a trailing backslash then this will put a
+quote in the value so we need:
+
+ "$(InputDir)"
+
+Make variable references are platform specific so we should probably
+just NOT quote them and let the listfile author deal with it.
+
+*/
+
+/*
+TODO: For windows echo:
+
+To display a pipe (|) or redirection character (< or >) when using the
+echo command, use a caret character immediately before the pipe or
+redirection character (for example, ^>, ^<, or ^| ). If you need to
+use the caret character itself (^), use two in a row (^^).
+*/
+
+/*--------------------------------------------------------------------------*/
+static int kwsysSystem_Shell__CharIsWhitespace(char c)
+{
+ return ((c == ' ') || (c == '\t'));
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysSystem_Shell__CharNeedsQuotesOnUnix(char c)
+{
+ return ((c == '\'') || (c == '`') || (c == ';') || (c == '#') ||
+ (c == '&') || (c == '$') || (c == '(') || (c == ')') ||
+ (c == '~') || (c == '<') || (c == '>') || (c == '|') ||
+ (c == '*') || (c == '^') || (c == '\\'));
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysSystem_Shell__CharNeedsQuotesOnWindows(char c)
+{
+ return ((c == '\'') || (c == '#') || (c == '&') ||
+ (c == '<') || (c == '>') || (c == '|') || (c == '^'));
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysSystem_Shell__CharNeedsQuotes(char c, int isUnix, int flags)
+{
+ /* On Windows the built-in command shell echo never needs quotes. */
+ if(!isUnix && (flags & kwsysSystem_Shell_Flag_EchoWindows))
+ {
+ return 0;
+ }
+
+ /* On all platforms quotes are needed to preserve whitespace. */
+ if(kwsysSystem_Shell__CharIsWhitespace(c))
+ {
+ return 1;
+ }
+
+ if(isUnix)
+ {
+ /* On UNIX several special characters need quotes to preserve them. */
+ if(kwsysSystem_Shell__CharNeedsQuotesOnUnix(c))
+ {
+ return 1;
+ }
+ }
+ else
+ {
+ /* On Windows several special characters need quotes to preserve them. */
+ if(kwsysSystem_Shell__CharNeedsQuotesOnWindows(c))
+ {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysSystem_Shell__CharIsMakeVariableName(char c)
+{
+ return c && (c == '_' || isalpha(((int)c)));
+}
+
+/*--------------------------------------------------------------------------*/
+static const char* kwsysSystem_Shell__SkipMakeVariables(const char* c)
+{
+ while(*c == '$' && *(c+1) == '(')
+ {
+ const char* skip = c+2;
+ while(kwsysSystem_Shell__CharIsMakeVariableName(*skip))
+ {
+ ++skip;
+ }
+ if(*skip == ')')
+ {
+ c = skip+1;
+ }
+ else
+ {
+ break;
+ }
+ }
+ return c;
+}
+
+/*
+Allowing make variable replacements opens a can of worms. Sometimes
+they should be quoted and sometimes not. Sometimes their replacement
+values are already quoted or contain escapes.
+
+Some Visual Studio variables cause problems. In order to pass the
+referenced value with spaces the reference must be quoted. If the
+variable value ends in a backslash then it will escape the ending
+quote! In order to make the ending backslash appear we need this:
+
+ "$(InputDir)\"
+
+However if there is not a trailing backslash then this will put a
+quote in the value so we need:
+
+ "$(InputDir)"
+
+This macro decides whether we quote an argument just because it
+contains a make variable reference. This should be replaced with a
+flag later when we understand applications of this better.
+*/
+#define KWSYS_SYSTEM_SHELL_QUOTE_MAKE_VARIABLES 0
+
+/*--------------------------------------------------------------------------*/
+static int kwsysSystem_Shell__ArgumentNeedsQuotes(const char* in, int isUnix,
+ int flags)
+{
+ /* The empty string needs quotes. */
+ if(!*in)
+ {
+ return 1;
+ }
+
+ /* Scan the string for characters that require quoting. */
+ {
+ const char* c;
+ for(c=in; *c; ++c)
+ {
+ /* Look for $(MAKEVAR) syntax if requested. */
+ if(flags & kwsysSystem_Shell_Flag_AllowMakeVariables)
+ {
+#if KWSYS_SYSTEM_SHELL_QUOTE_MAKE_VARIABLES
+ const char* skip = kwsysSystem_Shell__SkipMakeVariables(c);
+ if(skip != c)
+ {
+ /* We need to quote make variable references to preserve the
+ string with contents substituted in its place. */
+ return 1;
+ }
+#else
+ /* Skip over the make variable references if any are present. */
+ c = kwsysSystem_Shell__SkipMakeVariables(c);
+
+ /* Stop if we have reached the end of the string. */
+ if(!*c)
+ {
+ break;
+ }
+#endif
+ }
+
+ /* Check whether this character needs quotes. */
+ if(kwsysSystem_Shell__CharNeedsQuotes(*c, isUnix, flags))
+ {
+ return 1;
+ }
+ }
+ }
+
+ /* On Windows some single character arguments need quotes. */
+ if(!isUnix && *in && !*(in+1))
+ {
+ char c = *in;
+ if((c == '?') || (c == '&') || (c == '^') || (c == '|') || (c == '#'))
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysSystem_Shell__GetArgumentSize(const char* in,
+ int isUnix, int flags)
+{
+ /* Start with the length of the original argument, plus one for
+ either a terminating null or a separating space. */
+ int size = (int)strlen(in) + 1;
+
+ /* String iterator. */
+ const char* c;
+
+ /* Keep track of how many backslashes have been encountered in a row. */
+ int windows_backslashes = 0;
+
+ /* Scan the string for characters that require escaping or quoting. */
+ for(c=in; *c; ++c)
+ {
+ /* Look for $(MAKEVAR) syntax if requested. */
+ if(flags & kwsysSystem_Shell_Flag_AllowMakeVariables)
+ {
+ /* Skip over the make variable references if any are present. */
+ c = kwsysSystem_Shell__SkipMakeVariables(c);
+
+ /* Stop if we have reached the end of the string. */
+ if(!*c)
+ {
+ break;
+ }
+ }
+
+ /* Check whether this character needs escaping for the shell. */
+ if(isUnix)
+ {
+ /* On Unix a few special characters need escaping even inside a
+ quoted argument. */
+ if(*c == '\\' || *c == '"' || *c == '`' || *c == '$')
+ {
+ /* This character needs a backslash to escape it. */
+ ++size;
+ }
+ }
+ else if(flags & kwsysSystem_Shell_Flag_EchoWindows)
+ {
+ /* On Windows the built-in command shell echo never needs escaping. */
+ }
+ else
+ {
+ /* On Windows only backslashes and double-quotes need escaping. */
+ if(*c == '\\')
+ {
+ /* Found a backslash. It may need to be escaped later. */
+ ++windows_backslashes;
+ }
+ else if(*c == '"')
+ {
+ /* Found a double-quote. We need to escape it and all
+ immediately preceding backslashes. */
+ size += windows_backslashes + 1;
+ windows_backslashes = 0;
+ }
+ else
+ {
+ /* Found another character. This eliminates the possibility
+ that any immediately preceding backslashes will be
+ escaped. */
+ windows_backslashes = 0;
+ }
+ }
+
+ /* Check whether this character needs escaping for a make tool. */
+ if(*c == '$')
+ {
+ if(flags & kwsysSystem_Shell_Flag_Make)
+ {
+ /* In Makefiles a dollar is written $$ so we need one extra
+ character. */
+ ++size;
+ }
+ else if(flags & kwsysSystem_Shell_Flag_VSIDE)
+ {
+ /* In a VS IDE a dollar is written "$" so we need two extra
+ characters. */
+ size += 2;
+ }
+ }
+ else if(*c == '#')
+ {
+ if((flags & kwsysSystem_Shell_Flag_Make) &&
+ (flags & kwsysSystem_Shell_Flag_WatcomWMake))
+ {
+ /* In Watcom WMake makefiles a pound is written $# so we need
+ one extra character. */
+ ++size;
+ }
+ }
+ else if(*c == '%')
+ {
+ if((flags & kwsysSystem_Shell_Flag_VSIDE) ||
+ ((flags & kwsysSystem_Shell_Flag_Make) &&
+ ((flags & kwsysSystem_Shell_Flag_MinGWMake) ||
+ (flags & kwsysSystem_Shell_Flag_NMake))))
+ {
+ /* In the VS IDE, NMake, or MinGW make a percent is written %%
+ so we need one extra characters. */
+ size += 1;
+ }
+ }
+ else if(*c == ';')
+ {
+ if(flags & kwsysSystem_Shell_Flag_VSIDE)
+ {
+ /* In a VS IDE a semicolon is written ";" so we need two extra
+ characters. */
+ size += 2;
+ }
+ }
+ }
+
+ /* Check whether the argument needs surrounding quotes. */
+ if(kwsysSystem_Shell__ArgumentNeedsQuotes(in, isUnix, flags))
+ {
+ /* Surrounding quotes are needed. Allocate space for them. */
+ if((flags & kwsysSystem_Shell_Flag_WatcomQuote) && (isUnix))
+ {
+ size += 2;
+ }
+ size += 2;
+
+ /* We must escape all ending backslashes when quoting on windows. */
+ size += windows_backslashes;
+ }
+
+ return size;
+}
+
+/*--------------------------------------------------------------------------*/
+static char* kwsysSystem_Shell__GetArgument(const char* in, char* out,
+ int isUnix, int flags)
+{
+ /* String iterator. */
+ const char* c;
+
+ /* Keep track of how many backslashes have been encountered in a row. */
+ int windows_backslashes = 0;
+
+ /* Whether the argument must be quoted. */
+ int needQuotes = kwsysSystem_Shell__ArgumentNeedsQuotes(in, isUnix, flags);
+ if(needQuotes)
+ {
+ /* Add the opening quote for this argument. */
+ if(flags & kwsysSystem_Shell_Flag_WatcomQuote)
+ {
+ if(isUnix)
+ {
+ *out++ = '"';
+ }
+ *out++ = '\'';
+ }
+ else
+ {
+ *out++ = '"';
+ }
+ }
+
+ /* Scan the string for characters that require escaping or quoting. */
+ for(c=in; *c; ++c)
+ {
+ /* Look for $(MAKEVAR) syntax if requested. */
+ if(flags & kwsysSystem_Shell_Flag_AllowMakeVariables)
+ {
+ const char* skip = kwsysSystem_Shell__SkipMakeVariables(c);
+ if(skip != c)
+ {
+ /* Copy to the end of the make variable references. */
+ while(c != skip)
+ {
+ *out++ = *c++;
+ }
+
+ /* The make variable reference eliminates any escaping needed
+ for preceding backslashes. */
+ windows_backslashes = 0;
+
+ /* Stop if we have reached the end of the string. */
+ if(!*c)
+ {
+ break;
+ }
+ }
+ }
+
+ /* Check whether this character needs escaping for the shell. */
+ if(isUnix)
+ {
+ /* On Unix a few special characters need escaping even inside a
+ quoted argument. */
+ if(*c == '\\' || *c == '"' || *c == '`' || *c == '$')
+ {
+ /* This character needs a backslash to escape it. */
+ *out++ = '\\';
+ }
+ }
+ else if(flags & kwsysSystem_Shell_Flag_EchoWindows)
+ {
+ /* On Windows the built-in command shell echo never needs escaping. */
+ }
+ else
+ {
+ /* On Windows only backslashes and double-quotes need escaping. */
+ if(*c == '\\')
+ {
+ /* Found a backslash. It may need to be escaped later. */
+ ++windows_backslashes;
+ }
+ else if(*c == '"')
+ {
+ /* Found a double-quote. Escape all immediately preceding
+ backslashes. */
+ while(windows_backslashes > 0)
+ {
+ --windows_backslashes;
+ *out++ = '\\';
+ }
+
+ /* Add the backslash to escape the double-quote. */
+ *out++ = '\\';
+ }
+ else
+ {
+ /* We encountered a normal character. This eliminates any
+ escaping needed for preceding backslashes. */
+ windows_backslashes = 0;
+ }
+ }
+
+ /* Check whether this character needs escaping for a make tool. */
+ if(*c == '$')
+ {
+ if(flags & kwsysSystem_Shell_Flag_Make)
+ {
+ /* In Makefiles a dollar is written $$. The make tool will
+ replace it with just $ before passing it to the shell. */
+ *out++ = '$';
+ *out++ = '$';
+ }
+ else if(flags & kwsysSystem_Shell_Flag_VSIDE)
+ {
+ /* In a VS IDE a dollar is written "$". If this is written in
+ an un-quoted argument it starts a quoted segment, inserts
+ the $ and ends the segment. If it is written in a quoted
+ argument it ends quoting, inserts the $ and restarts
+ quoting. Either way the $ is isolated from surrounding
+ text to avoid looking like a variable reference. */
+ *out++ = '"';
+ *out++ = '$';
+ *out++ = '"';
+ }
+ else
+ {
+ /* Otherwise a dollar is written just $. */
+ *out++ = '$';
+ }
+ }
+ else if(*c == '#')
+ {
+ if((flags & kwsysSystem_Shell_Flag_Make) &&
+ (flags & kwsysSystem_Shell_Flag_WatcomWMake))
+ {
+ /* In Watcom WMake makefiles a pound is written $#. The make
+ tool will replace it with just # before passing it to the
+ shell. */
+ *out++ = '$';
+ *out++ = '#';
+ }
+ else
+ {
+ /* Otherwise a pound is written just #. */
+ *out++ = '#';
+ }
+ }
+ else if(*c == '%')
+ {
+ if((flags & kwsysSystem_Shell_Flag_VSIDE) ||
+ ((flags & kwsysSystem_Shell_Flag_Make) &&
+ ((flags & kwsysSystem_Shell_Flag_MinGWMake) ||
+ (flags & kwsysSystem_Shell_Flag_NMake))))
+ {
+ /* In the VS IDE, NMake, or MinGW make a percent is written %%. */
+ *out++ = '%';
+ *out++ = '%';
+ }
+ else
+ {
+ /* Otherwise a percent is written just %. */
+ *out++ = '%';
+ }
+ }
+ else if(*c == ';')
+ {
+ if(flags & kwsysSystem_Shell_Flag_VSIDE)
+ {
+ /* In a VS IDE a semicolon is written ";". If this is written
+ in an un-quoted argument it starts a quoted segment,
+ inserts the ; and ends the segment. If it is written in a
+ quoted argument it ends quoting, inserts the ; and restarts
+ quoting. Either way the ; is isolated. */
+ *out++ = '"';
+ *out++ = ';';
+ *out++ = '"';
+ }
+ else
+ {
+ /* Otherwise a semicolon is written just ;. */
+ *out++ = ';';
+ }
+ }
+ else
+ {
+ /* Store this character. */
+ *out++ = *c;
+ }
+ }
+
+ if(needQuotes)
+ {
+ /* Add enough backslashes to escape any trailing ones. */
+ while(windows_backslashes > 0)
+ {
+ --windows_backslashes;
+ *out++ = '\\';
+ }
+
+ /* Add the closing quote for this argument. */
+ if(flags & kwsysSystem_Shell_Flag_WatcomQuote)
+ {
+ *out++ = '\'';
+ if(isUnix)
+ {
+ *out++ = '"';
+ }
+ }
+ else
+ {
+ *out++ = '"';
+ }
+ }
+
+ /* Store a terminating null without incrementing. */
+ *out = 0;
+
+ return out;
+}
+
+/*--------------------------------------------------------------------------*/
+char* kwsysSystem_Shell_GetArgumentForWindows(const char* in,
+ char* out,
+ int flags)
+{
+ return kwsysSystem_Shell__GetArgument(in, out, 0, flags);
+}
+
+/*--------------------------------------------------------------------------*/
+char* kwsysSystem_Shell_GetArgumentForUnix(const char* in,
+ char* out,
+ int flags)
+{
+ return kwsysSystem_Shell__GetArgument(in, out, 1, flags);
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysSystem_Shell_GetArgumentSizeForWindows(const char* in, int flags)
+{
+ return kwsysSystem_Shell__GetArgumentSize(in, 0, flags);
+}
+
+/*--------------------------------------------------------------------------*/
+int kwsysSystem_Shell_GetArgumentSizeForUnix(const char* in, int flags)
+{
+ return kwsysSystem_Shell__GetArgumentSize(in, 1, flags);
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysSystem__AppendByte(char* local,
+ char** begin, char** end,
+ int* size, char c)
+{
+ /* Allocate space for the character. */
+ if((*end - *begin) >= *size)
+ {
+ kwsysSystem_ptrdiff_t length = *end - *begin;
+ char* newBuffer = (char*)malloc((size_t)(*size*2));
+ if(!newBuffer)
+ {
+ return 0;
+ }
+ memcpy(newBuffer, *begin, (size_t)(length)*sizeof(char));
+ if(*begin != local)
+ {
+ free(*begin);
+ }
+ *begin = newBuffer;
+ *end = *begin + length;
+ *size *= 2;
+ }
+
+ /* Store the character. */
+ *(*end)++ = c;
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+static int kwsysSystem__AppendArgument(char** local,
+ char*** begin, char*** end,
+ int* size,
+ char* arg_local,
+ char** arg_begin, char** arg_end,
+ int* arg_size)
+{
+ /* Append a null-terminator to the argument string. */
+ if(!kwsysSystem__AppendByte(arg_local, arg_begin, arg_end, arg_size, '\0'))
+ {
+ return 0;
+ }
+
+ /* Allocate space for the argument pointer. */
+ if((*end - *begin) >= *size)
+ {
+ kwsysSystem_ptrdiff_t length = *end - *begin;
+ char** newPointers = (char**)malloc((size_t)(*size)*2*sizeof(char*));
+ if(!newPointers)
+ {
+ return 0;
+ }
+ memcpy(newPointers, *begin, (size_t)(length)*sizeof(char*));
+ if(*begin != local)
+ {
+ free(*begin);
+ }
+ *begin = newPointers;
+ *end = *begin + length;
+ *size *= 2;
+ }
+
+ /* Allocate space for the argument string. */
+ **end = (char*)malloc((size_t)(*arg_end - *arg_begin));
+ if(!**end)
+ {
+ return 0;
+ }
+
+ /* Store the argument in the command array. */
+ memcpy(**end, *arg_begin,(size_t)(*arg_end - *arg_begin));
+ ++(*end);
+
+ /* Reset the argument to be empty. */
+ *arg_end = *arg_begin;
+
+ return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+#define KWSYSPE_LOCAL_BYTE_COUNT 1024
+#define KWSYSPE_LOCAL_ARGS_COUNT 32
+static char** kwsysSystem__ParseUnixCommand(const char* command, int flags)
+{
+ /* Create a buffer for argument pointers during parsing. */
+ char* local_pointers[KWSYSPE_LOCAL_ARGS_COUNT];
+ int pointers_size = KWSYSPE_LOCAL_ARGS_COUNT;
+ char** pointer_begin = local_pointers;
+ char** pointer_end = pointer_begin;
+
+ /* Create a buffer for argument strings during parsing. */
+ char local_buffer[KWSYSPE_LOCAL_BYTE_COUNT];
+ int buffer_size = KWSYSPE_LOCAL_BYTE_COUNT;
+ char* buffer_begin = local_buffer;
+ char* buffer_end = buffer_begin;
+
+ /* Parse the command string. Try to behave like a UNIX shell. */
+ char** newCommand = 0;
+ const char* c = command;
+ int in_argument = 0;
+ int in_escape = 0;
+ int in_single = 0;
+ int in_double = 0;
+ int failed = 0;
+ for(;*c; ++c)
+ {
+ if(in_escape)
+ {
+ /* This character is escaped so do no special handling. */
+ if(!in_argument)
+ {
+ in_argument = 1;
+ }
+ if(!kwsysSystem__AppendByte(local_buffer, &buffer_begin,
+ &buffer_end, &buffer_size, *c))
+ {
+ failed = 1;
+ break;
+ }
+ in_escape = 0;
+ }
+ else if(*c == '\\')
+ {
+ /* The next character should be escaped. */
+ in_escape = 1;
+ }
+ else if(*c == '\'' && !in_double)
+ {
+ /* Enter or exit single-quote state. */
+ if(in_single)
+ {
+ in_single = 0;
+ }
+ else
+ {
+ in_single = 1;
+ if(!in_argument)
+ {
+ in_argument = 1;
+ }
+ }
+ }
+ else if(*c == '"' && !in_single)
+ {
+ /* Enter or exit double-quote state. */
+ if(in_double)
+ {
+ in_double = 0;
+ }
+ else
+ {
+ in_double = 1;
+ if(!in_argument)
+ {
+ in_argument = 1;
+ }
+ }
+ }
+ else if(isspace((unsigned char) *c))
+ {
+ if(in_argument)
+ {
+ if(in_single || in_double)
+ {
+ /* This space belongs to a quoted argument. */
+ if(!kwsysSystem__AppendByte(local_buffer, &buffer_begin,
+ &buffer_end, &buffer_size, *c))
+ {
+ failed = 1;
+ break;
+ }
+ }
+ else
+ {
+ /* This argument has been terminated by whitespace. */
+ if(!kwsysSystem__AppendArgument(local_pointers, &pointer_begin,
+ &pointer_end, &pointers_size,
+ local_buffer, &buffer_begin,
+ &buffer_end, &buffer_size))
+ {
+ failed = 1;
+ break;
+ }
+ in_argument = 0;
+ }
+ }
+ }
+ else
+ {
+ /* This character belong to an argument. */
+ if(!in_argument)
+ {
+ in_argument = 1;
+ }
+ if(!kwsysSystem__AppendByte(local_buffer, &buffer_begin,
+ &buffer_end, &buffer_size, *c))
+ {
+ failed = 1;
+ break;
+ }
+ }
+ }
+
+ /* Finish the last argument. */
+ if(in_argument)
+ {
+ if(!kwsysSystem__AppendArgument(local_pointers, &pointer_begin,
+ &pointer_end, &pointers_size,
+ local_buffer, &buffer_begin,
+ &buffer_end, &buffer_size))
+ {
+ failed = 1;
+ }
+ }
+
+ /* If we still have memory allocate space for the new command
+ buffer. */
+ if(!failed)
+ {
+ kwsysSystem_ptrdiff_t n = pointer_end - pointer_begin;
+ newCommand = (char**)malloc((size_t)(n+1)*sizeof(char*));
+ }
+
+ if(newCommand)
+ {
+ /* Copy the arguments into the new command buffer. */
+ kwsysSystem_ptrdiff_t n = pointer_end - pointer_begin;
+ memcpy(newCommand, pointer_begin, sizeof(char*)*(size_t)(n));
+ newCommand[n] = 0;
+ }
+ else
+ {
+ /* Free arguments already allocated. */
+ while(pointer_end != pointer_begin)
+ {
+ free(*(--pointer_end));
+ }
+ }
+
+ /* Free temporary buffers. */
+ if(pointer_begin != local_pointers)
+ {
+ free(pointer_begin);
+ }
+ if(buffer_begin != local_buffer)
+ {
+ free(buffer_begin);
+ }
+
+ /* The flags argument is currently unused. */
+ (void)flags;
+
+ /* Return the final command buffer. */
+ return newCommand;
+}
+
+/*--------------------------------------------------------------------------*/
+char** kwsysSystem_Parse_CommandForUnix(const char* command, int flags)
+{
+ /* Validate the flags. */
+ if(flags != 0)
+ {
+ return 0;
+ }
+
+ /* Forward to our internal implementation. */
+ return kwsysSystem__ParseUnixCommand(command, flags);
+}
diff --git a/Source/kwsys/System.h.in b/Source/kwsys/System.h.in
new file mode 100644
index 0000000000..f21bf0dcaa
--- /dev/null
+++ b/Source/kwsys/System.h.in
@@ -0,0 +1,167 @@
+/*============================================================================
+ 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@_System_h
+#define @KWSYS_NAMESPACE@_System_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@_EXPORT
+#endif
+#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsysSystem_Parse_CommandForUnix kwsys_ns(System_Parse_CommandForUnix)
+# define kwsysSystem_Shell_GetArgumentForWindows kwsys_ns(System_Shell_GetArgumentForWindows)
+# define kwsysSystem_Shell_GetArgumentForUnix kwsys_ns(System_Shell_GetArgumentForUnix)
+# define kwsysSystem_Shell_GetArgumentSizeForWindows kwsys_ns(System_Shell_GetArgumentSizeForWindows)
+# define kwsysSystem_Shell_GetArgumentSizeForUnix kwsys_ns(System_Shell_GetArgumentSizeForUnix)
+# define kwsysSystem_Shell_Flag_e kwsys_ns(System_Shell_Flag_e)
+# define kwsysSystem_Shell_Flag_Make kwsys_ns(System_Shell_Flag_Make)
+# define kwsysSystem_Shell_Flag_VSIDE kwsys_ns(System_Shell_Flag_VSIDE)
+# define kwsysSystem_Shell_Flag_EchoWindows kwsys_ns(System_Shell_Flag_EchoWindows)
+# define kwsysSystem_Shell_Flag_WatcomWMake kwsys_ns(System_Shell_Flag_WatcomWMake)
+# define kwsysSystem_Shell_Flag_MinGWMake kwsys_ns(System_Shell_Flag_MinGWMake)
+# define kwsysSystem_Shell_Flag_NMake kwsys_ns(System_Shell_Flag_NMake)
+# define kwsysSystem_Shell_Flag_AllowMakeVariables kwsys_ns(System_Shell_Flag_AllowMakeVariables)
+# define kwsysSystem_Shell_Flag_WatcomQuote kwsys_ns(System_Shell_Flag_WatcomQuote)
+#endif
+
+#ifdef __VMS
+#define @KWSYS_NAMESPACE@System_Shell_GetArgumentForUnix \
+ @KWSYS_NAMESPACE@System_Shell_UnixGA
+#define @KWSYS_NAMESPACE@System_Shell_GetArgumentSizeForUnix \
+ @KWSYS_NAMESPACE@System_Shell_UnixGAS
+#define @KWSYS_NAMESPACE@System_Shell_GetArgumentForWindows \
+ @KWSYS_NAMESPACE@System_Shell_WindowsGA
+#endif
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/**
+ * Transform the given command line argument for use in a Windows or
+ * Unix shell. Returns a pointer to the end of the command line
+ * argument in the provided output buffer. Flags may be passed to
+ * modify the generated quoting and escape sequences to work under
+ * alternative environments.
+ */
+kwsysEXPORT char* kwsysSystem_Shell_GetArgumentForWindows(const char* in,
+ char* out,
+ int flags);
+kwsysEXPORT char* kwsysSystem_Shell_GetArgumentForUnix(const char* in,
+ char* out,
+ int flags);
+
+/**
+ * Compute the size of the buffer required to store the output from
+ * kwsysSystem_Shell_GetArgumentForWindows or
+ * kwsysSystem_Shell_GetArgumentForUnix. The flags passed must be
+ * identical between the two calls.
+ */
+kwsysEXPORT int kwsysSystem_Shell_GetArgumentSizeForWindows(const char* in,
+ int flags);
+kwsysEXPORT int kwsysSystem_Shell_GetArgumentSizeForUnix(const char* in,
+ int flags);
+
+/**
+ * Flags to pass to kwsysSystem_Shell_GetArgumentForWindows or
+ * kwsysSystem_Shell_GetArgumentForUnix. These modify the generated
+ * quoting and escape sequences to work under alternative
+ * environments.
+ */
+enum kwsysSystem_Shell_Flag_e
+{
+ /** The target shell is in a makefile. */
+ kwsysSystem_Shell_Flag_Make = (1<<0),
+
+ /** The target shell is in a VS project file. Do not use with
+ Shell_Flag_Make. */
+ kwsysSystem_Shell_Flag_VSIDE = (1<<1),
+
+ /** In a windows shell the argument is being passed to "echo". */
+ kwsysSystem_Shell_Flag_EchoWindows = (1<<2),
+
+ /** The target shell is in a Watcom WMake makefile. */
+ kwsysSystem_Shell_Flag_WatcomWMake = (1<<3),
+
+ /** The target shell is in a MinGW Make makefile. */
+ kwsysSystem_Shell_Flag_MinGWMake = (1<<4),
+
+ /** The target shell is in a NMake makefile. */
+ kwsysSystem_Shell_Flag_NMake = (1<<5),
+
+ /** Make variable reference syntax $(MAKEVAR) should not be escaped
+ to allow a build tool to replace it. Replacement values
+ containing spaces, quotes, backslashes, or other
+ non-alphanumeric characters that have significance to some makes
+ or shells produce undefined behavior. */
+ kwsysSystem_Shell_Flag_AllowMakeVariables = (1<<6),
+
+ /** The target shell quoting uses extra single Quotes for Watcom tools. */
+ kwsysSystem_Shell_Flag_WatcomQuote = (1<<7)
+};
+
+/**
+ * Parse a unix-style command line string into separate arguments.
+ *
+ * On success, returns a pointer to an array of pointers to individual
+ * argument strings. Each string is null-terminated and the last
+ * entry in the array is a NULL pointer (just like argv). It is the
+ * caller's responsibility to free() the strings and the array of
+ * pointers to them.
+ *
+ * On failure, returns NULL. Failure occurs only on invalid flags or
+ * when memory cannot be allocated; never due to content of the input
+ * string. Missing close-quotes are treated as if the necessary
+ * closing quote appears.
+ *
+ * By default single- and double-quoted arguments are supported, and
+ * any character may be escaped by a backslash. The flags argument is
+ * reserved for future use, and must be zero (or the call will fail).
+ */
+kwsysEXPORT char** kwsysSystem_Parse_CommandForUnix(const char* command,
+ int flags);
+
+#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@_NAME_IS_KWSYS
+# undef kwsysSystem_Parse_CommandForUnix
+# undef kwsysSystem_Shell_GetArgumentForWindows
+# undef kwsysSystem_Shell_GetArgumentForUnix
+# undef kwsysSystem_Shell_GetArgumentSizeForWindows
+# undef kwsysSystem_Shell_GetArgumentSizeForUnix
+# undef kwsysSystem_Shell_Flag_e
+# undef kwsysSystem_Shell_Flag_Make
+# undef kwsysSystem_Shell_Flag_VSIDE
+# undef kwsysSystem_Shell_Flag_EchoWindows
+# undef kwsysSystem_Shell_Flag_WatcomWMake
+# undef kwsysSystem_Shell_Flag_MinGWMake
+# undef kwsysSystem_Shell_Flag_NMake
+# undef kwsysSystem_Shell_Flag_AllowMakeVariables
+# undef kwsysSystem_Shell_Flag_WatcomQuote
+# endif
+#endif
+
+#endif
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
new file mode 100644
index 0000000000..84b5f39f30
--- /dev/null
+++ b/Source/kwsys/SystemInformation.cxx
@@ -0,0 +1,5374 @@
+/*============================================================================
+ 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.
+============================================================================*/
+
+#if defined(_WIN32)
+# define NOMINMAX // use our min,max
+# if !defined(_WIN32_WINNT) && !(defined(_MSC_VER) && _MSC_VER < 1300)
+# define _WIN32_WINNT 0x0501
+# endif
+# include <winsock.h> // WSADATA, include before sys/types.h
+#endif
+
+#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+
+// TODO:
+// We need an alternative implementation for many functions in this file
+// when USE_ASM_INSTRUCTIONS gets defined as 0.
+//
+// Consider using these on Win32/Win64 for some of them:
+//
+// IsProcessorFeaturePresent
+// http://msdn.microsoft.com/en-us/library/ms724482(VS.85).aspx
+//
+// GetProcessMemoryInfo
+// http://msdn.microsoft.com/en-us/library/ms683219(VS.85).aspx
+
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(stl/string)
+#include KWSYS_HEADER(stl/vector)
+#include KWSYS_HEADER(ios/iosfwd)
+#include KWSYS_HEADER(SystemInformation.hxx)
+#include KWSYS_HEADER(Process.h)
+#include KWSYS_HEADER(ios/iostream)
+#include KWSYS_HEADER(ios/sstream)
+#include KWSYS_HEADER(ios/fstream)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "SystemInformation.hxx.in"
+# include "Process.h.in"
+# include "Configure.hxx.in"
+# include "kwsys_stl.hxx.in"
+# include "kwsys_stl_vector.in"
+# include "kwsys_stl_iosfwd.in"
+# include "kwsys_ios_sstream.h.in"
+# include "kwsys_ios_iostream.h.in"
+# include "kwsys_ios_fstream.h.in"
+#endif
+
+#if defined(_WIN32)
+# include <windows.h>
+# if defined(_MSC_VER) && _MSC_VER >= 1800
+# define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# endif
+# include <errno.h>
+# if defined(KWSYS_SYS_HAS_PSAPI)
+# include <psapi.h>
+# endif
+# if !defined(siginfo_t)
+typedef int siginfo_t;
+# endif
+#else
+# include <sys/types.h>
+# include <sys/time.h>
+# include <sys/utsname.h> // int uname(struct utsname *buf);
+# include <sys/resource.h> // getrlimit
+# include <unistd.h>
+# include <signal.h>
+# include <fcntl.h>
+# include <errno.h> // extern int errno;
+#endif
+
+#ifdef __FreeBSD__
+# include <sys/sysctl.h>
+# include <fenv.h>
+# include <sys/socket.h>
+# include <netdb.h>
+# include <netinet/in.h>
+# if defined(KWSYS_SYS_HAS_IFADDRS_H)
+# include <ifaddrs.h>
+# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
+# endif
+#endif
+
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+# include <sys/param.h>
+# include <sys/sysctl.h>
+#endif
+
+#if defined(KWSYS_SYS_HAS_MACHINE_CPU_H)
+# include <machine/cpu.h>
+#endif
+
+#if defined(__DragonFly__)
+# include <sys/sysctl.h>
+#endif
+
+#ifdef __APPLE__
+# include <sys/sysctl.h>
+# include <mach/vm_statistics.h>
+# include <mach/host_info.h>
+# include <mach/mach.h>
+# include <mach/mach_types.h>
+# include <fenv.h>
+# include <sys/socket.h>
+# include <netdb.h>
+# include <netinet/in.h>
+# if defined(KWSYS_SYS_HAS_IFADDRS_H)
+# include <ifaddrs.h>
+# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
+# endif
+# if !(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 >= 1050)
+# undef KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE
+# endif
+#endif
+
+#ifdef __linux
+# include <fenv.h>
+# include <sys/socket.h>
+# include <netdb.h>
+# include <netinet/in.h>
+# if defined(KWSYS_SYS_HAS_IFADDRS_H)
+# include <ifaddrs.h>
+# if !defined(__LSB_VERSION__) /* LSB has no getifaddrs */
+# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
+# endif
+# endif
+# if defined(KWSYS_CXX_HAS_RLIMIT64)
+typedef struct rlimit64 ResourceLimitType;
+# define GetResourceLimit getrlimit64
+# else
+typedef struct rlimit ResourceLimitType;
+# define GetResourceLimit getrlimit
+# endif
+#elif defined( __hpux )
+# include <sys/param.h>
+# include <sys/pstat.h>
+# if defined(KWSYS_SYS_HAS_MPCTL_H)
+# include <sys/mpctl.h>
+# endif
+#endif
+
+#ifdef __HAIKU__
+# include <OS.h>
+#endif
+
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+# include <execinfo.h>
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
+# include <cxxabi.h>
+# endif
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+# include <dlfcn.h>
+# endif
+#else
+# undef KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE
+# undef KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP
+#endif
+
+#include <memory.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h> // int isdigit(int c);
+
+#if defined(KWSYS_USE_LONG_LONG)
+# if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
+# define iostreamLongLong(x) (x)
+# else
+# define iostreamLongLong(x) ((long)x)
+# endif
+#elif defined(KWSYS_USE___INT64)
+# if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
+# define iostreamLongLong(x) (x)
+# else
+# define iostreamLongLong(x) ((long)x)
+# endif
+#else
+# error "No Long Long"
+#endif
+
+#if defined(KWSYS_CXX_HAS_ATOLL)
+# define atoLongLong atoll
+#else
+# if defined(KWSYS_CXX_HAS__ATOI64)
+# define atoLongLong _atoi64
+# elif defined(KWSYS_CXX_HAS_ATOL)
+# define atoLongLong atol
+# else
+# define atoLongLong atoi
+# endif
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(_WIN64)
+#define USE_ASM_INSTRUCTIONS 1
+#else
+#define USE_ASM_INSTRUCTIONS 0
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+#include <intrin.h>
+#define USE_CPUID_INTRINSICS 1
+#else
+#define USE_CPUID_INTRINSICS 0
+#endif
+
+#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
+# define USE_CPUID 1
+#else
+# define USE_CPUID 0
+#endif
+
+#if USE_CPUID
+
+#define CPUID_AWARE_COMPILER
+
+/**
+ * call CPUID instruction
+ *
+ * Will return false if the instruction failed.
+ */
+static bool call_cpuid(int select, int result[4])
+{
+#if USE_CPUID_INTRINSICS
+ __cpuid(result, select);
+ return true;
+#else
+ int tmp[4];
+#if defined(_MSC_VER)
+ // Use SEH to determine CPUID presence
+ __try {
+ _asm {
+#ifdef CPUID_AWARE_COMPILER
+ ; we must push/pop the registers <<CPUID>> writes to, as the
+ ; optimiser does not know about <<CPUID>>, and so does not expect
+ ; these registers to change.
+ push eax
+ push ebx
+ push ecx
+ push edx
+#endif
+ ; <<CPUID>>
+ mov eax, select
+#ifdef CPUID_AWARE_COMPILER
+ cpuid
+#else
+ _asm _emit 0x0f
+ _asm _emit 0xa2
+#endif
+ mov tmp[0 * TYPE int], eax
+ mov tmp[1 * TYPE int], ebx
+ mov tmp[2 * TYPE int], ecx
+ mov tmp[3 * TYPE int], edx
+
+#ifdef CPUID_AWARE_COMPILER
+ pop edx
+ pop ecx
+ pop ebx
+ pop eax
+#endif
+ }
+ }
+ __except(1)
+ {
+ return false;
+ }
+
+ memcpy(result, tmp, sizeof(tmp));
+#elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
+ unsigned int a, b, c, d;
+ __asm {
+ mov EAX, select;
+ cpuid
+ mov a, EAX;
+ mov b, EBX;
+ mov c, ECX;
+ mov d, EDX;
+ }
+
+ result[0] = a;
+ result[1] = b;
+ result[2] = c;
+ result[3] = d;
+#endif
+
+ // The cpuid instruction succeeded.
+ return true;
+#endif
+}
+#endif
+
+
+namespace KWSYS_NAMESPACE
+{
+template<typename T>
+T min(T a, T b){ return a<b ? a : b; }
+
+extern "C" { typedef void (*SigAction)(int,siginfo_t*,void*); }
+
+// Define SystemInformationImplementation class
+typedef void (*DELAY_FUNC)(unsigned int uiMS);
+
+class SystemInformationImplementation
+{
+public:
+ typedef SystemInformation::LongLong LongLong;
+ SystemInformationImplementation ();
+ ~SystemInformationImplementation ();
+
+ const char * GetVendorString();
+ const char * GetVendorID();
+ kwsys_stl::string GetTypeID();
+ kwsys_stl::string GetFamilyID();
+ kwsys_stl::string GetModelID();
+ kwsys_stl::string GetModelName();
+ kwsys_stl::string GetSteppingCode();
+ const char * GetExtendedProcessorName();
+ const char * GetProcessorSerialNumber();
+ int GetProcessorCacheSize();
+ unsigned int GetLogicalProcessorsPerPhysical();
+ float GetProcessorClockFrequency();
+ int GetProcessorAPICID();
+ int GetProcessorCacheXSize(long int);
+ bool DoesCPUSupportFeature(long int);
+
+ const char * GetOSName();
+ const char * GetHostname();
+ int GetFullyQualifiedDomainName(kwsys_stl::string &fqdn);
+ const char * GetOSRelease();
+ const char * GetOSVersion();
+ const char * GetOSPlatform();
+
+ bool Is64Bits();
+
+ unsigned int GetNumberOfLogicalCPU(); // per physical cpu
+ unsigned int GetNumberOfPhysicalCPU();
+
+ bool DoesCPUSupportCPUID();
+
+ // Retrieve memory information in megabyte.
+ size_t GetTotalVirtualMemory();
+ size_t GetAvailableVirtualMemory();
+ size_t GetTotalPhysicalMemory();
+ size_t GetAvailablePhysicalMemory();
+
+ LongLong GetProcessId();
+
+ // Retrieve memory information in kib
+ LongLong GetHostMemoryTotal();
+ LongLong GetHostMemoryAvailable(const char *envVarName);
+ LongLong GetHostMemoryUsed();
+
+ LongLong GetProcMemoryAvailable(
+ const char *hostLimitEnvVarName,
+ const char *procLimitEnvVarName);
+ LongLong GetProcMemoryUsed();
+
+ // enable/disable stack trace signal handler.
+ static
+ void SetStackTraceOnError(int enable);
+
+ // get current stack
+ static
+ kwsys_stl::string GetProgramStack(int firstFrame, int wholePath);
+
+ /** Run the different checks */
+ void RunCPUCheck();
+ void RunOSCheck();
+ void RunMemoryCheck();
+
+public:
+ typedef struct tagID
+ {
+ int Type;
+ int Family;
+ int Model;
+ int Revision;
+ int ExtendedFamily;
+ int ExtendedModel;
+ kwsys_stl::string ProcessorName;
+ kwsys_stl::string Vendor;
+ kwsys_stl::string SerialNumber;
+ kwsys_stl::string ModelName;
+ } ID;
+
+ typedef struct tagCPUPowerManagement
+ {
+ bool HasVoltageID;
+ bool HasFrequencyID;
+ bool HasTempSenseDiode;
+ } CPUPowerManagement;
+
+ typedef struct tagCPUExtendedFeatures
+ {
+ bool Has3DNow;
+ bool Has3DNowPlus;
+ bool SupportsMP;
+ bool HasMMXPlus;
+ bool HasSSEMMX;
+ bool SupportsHyperthreading;
+ unsigned int LogicalProcessorsPerPhysical;
+ int APIC_ID;
+ CPUPowerManagement PowerManagement;
+ } CPUExtendedFeatures;
+
+ typedef struct CPUtagFeatures
+ {
+ bool HasFPU;
+ bool HasTSC;
+ bool HasMMX;
+ bool HasSSE;
+ bool HasSSEFP;
+ bool HasSSE2;
+ bool HasIA64;
+ bool HasAPIC;
+ bool HasCMOV;
+ bool HasMTRR;
+ bool HasACPI;
+ bool HasSerial;
+ bool HasThermal;
+ int CPUSpeed;
+ int L1CacheSize;
+ int L2CacheSize;
+ int L3CacheSize;
+ CPUExtendedFeatures ExtendedFeatures;
+ } CPUFeatures;
+
+ enum Manufacturer
+ {
+ AMD, Intel, NSC, UMC, Cyrix, NexGen, IDT, Rise, Transmeta, Sun, IBM,
+ Motorola, HP, UnknownManufacturer
+ };
+
+protected:
+ // Functions.
+ bool RetrieveCPUFeatures();
+ bool RetrieveCPUIdentity();
+ bool RetrieveCPUCacheDetails();
+ bool RetrieveClassicalCPUCacheDetails();
+ bool RetrieveCPUClockSpeed();
+ bool RetrieveClassicalCPUClockSpeed();
+ bool RetrieveCPUExtendedLevelSupport(int);
+ bool RetrieveExtendedCPUFeatures();
+ bool RetrieveProcessorSerialNumber();
+ bool RetrieveCPUPowerManagement();
+ bool RetrieveClassicalCPUIdentity();
+ bool RetrieveExtendedCPUIdentity();
+
+ Manufacturer ChipManufacturer;
+ CPUFeatures Features;
+ ID ChipID;
+ float CPUSpeedInMHz;
+ unsigned int NumberOfLogicalCPU;
+ unsigned int NumberOfPhysicalCPU;
+
+ int CPUCount();
+ unsigned char LogicalCPUPerPhysicalCPU();
+ unsigned char GetAPICId();
+ bool IsHyperThreadingSupported();
+ static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int);
+
+ // For Linux and Cygwin, /proc/cpuinfo formats are slightly different
+ bool RetreiveInformationFromCpuInfoFile();
+ kwsys_stl::string ExtractValueFromCpuInfoFile(kwsys_stl::string buffer,
+ const char* word, size_t init=0);
+
+ bool QueryLinuxMemory();
+ bool QueryCygwinMemory();
+
+ static void Delay (unsigned int);
+ static void DelayOverhead (unsigned int);
+
+ void FindManufacturer(const kwsys_stl::string &family = "");
+
+ // For Mac
+ bool ParseSysCtl();
+ int CallSwVers(const char *arg, kwsys_stl::string &ver);
+ void TrimNewline(kwsys_stl::string&);
+ kwsys_stl::string ExtractValueFromSysCtl(const char* word);
+ kwsys_stl::string SysCtlBuffer;
+
+ // For Solaris
+ bool QuerySolarisMemory();
+ bool QuerySolarisProcessor();
+ kwsys_stl::string ParseValueFromKStat(const char* arguments);
+ kwsys_stl::string RunProcess(kwsys_stl::vector<const char*> args);
+
+ //For Haiku OS
+ bool QueryHaikuInfo();
+
+ //For QNX
+ bool QueryQNXMemory();
+ bool QueryQNXProcessor();
+
+ //For OpenBSD, FreeBSD, NetBSD, DragonFly
+ bool QueryBSDMemory();
+ bool QueryBSDProcessor();
+
+ //For HP-UX
+ bool QueryHPUXMemory();
+ bool QueryHPUXProcessor();
+
+ //For Microsoft Windows
+ bool QueryWindowsMemory();
+
+ //For AIX
+ bool QueryAIXMemory();
+
+ bool QueryProcessorBySysconf();
+ bool QueryProcessor();
+
+ // Evaluate the memory information.
+ bool QueryMemoryBySysconf();
+ bool QueryMemory();
+ size_t TotalVirtualMemory;
+ size_t AvailableVirtualMemory;
+ size_t TotalPhysicalMemory;
+ size_t AvailablePhysicalMemory;
+
+ size_t CurrentPositionInFile;
+
+ // Operating System information
+ bool QueryOSInformation();
+ kwsys_stl::string OSName;
+ kwsys_stl::string Hostname;
+ kwsys_stl::string OSRelease;
+ kwsys_stl::string OSVersion;
+ kwsys_stl::string OSPlatform;
+};
+
+
+SystemInformation::SystemInformation()
+{
+ this->Implementation = new SystemInformationImplementation;
+}
+
+SystemInformation::~SystemInformation()
+{
+ delete this->Implementation;
+}
+
+const char * SystemInformation::GetVendorString()
+{
+ return this->Implementation->GetVendorString();
+}
+
+const char * SystemInformation::GetVendorID()
+{
+ return this->Implementation->GetVendorID();
+}
+
+kwsys_stl::string SystemInformation::GetTypeID()
+{
+ return this->Implementation->GetTypeID();
+}
+
+kwsys_stl::string SystemInformation::GetFamilyID()
+{
+ return this->Implementation->GetFamilyID();
+}
+
+kwsys_stl::string SystemInformation::GetModelID()
+{
+ return this->Implementation->GetModelID();
+}
+
+kwsys_stl::string SystemInformation::GetModelName()
+{
+ return this->Implementation->GetModelName();
+}
+
+kwsys_stl::string SystemInformation::GetSteppingCode()
+{
+ return this->Implementation->GetSteppingCode();
+}
+
+const char * SystemInformation::GetExtendedProcessorName()
+{
+ return this->Implementation->GetExtendedProcessorName();
+}
+
+const char * SystemInformation::GetProcessorSerialNumber()
+{
+ return this->Implementation->GetProcessorSerialNumber();
+}
+
+int SystemInformation::GetProcessorCacheSize()
+{
+ return this->Implementation->GetProcessorCacheSize();
+}
+
+unsigned int SystemInformation::GetLogicalProcessorsPerPhysical()
+{
+ return this->Implementation->GetLogicalProcessorsPerPhysical();
+}
+
+float SystemInformation::GetProcessorClockFrequency()
+{
+ return this->Implementation->GetProcessorClockFrequency();
+}
+
+int SystemInformation::GetProcessorAPICID()
+{
+ return this->Implementation->GetProcessorAPICID();
+}
+
+int SystemInformation::GetProcessorCacheXSize(long int l)
+{
+ return this->Implementation->GetProcessorCacheXSize(l);
+}
+
+bool SystemInformation::DoesCPUSupportFeature(long int i)
+{
+ return this->Implementation->DoesCPUSupportFeature(i);
+}
+
+kwsys_stl::string SystemInformation::GetCPUDescription()
+{
+ kwsys_ios::ostringstream oss;
+ oss
+ << this->GetNumberOfPhysicalCPU()
+ << " core ";
+ if (this->GetModelName().empty())
+ {
+ oss
+ << this->GetProcessorClockFrequency()
+ << " MHz "
+ << this->GetVendorString()
+ << " "
+ << this->GetExtendedProcessorName();
+ }
+ else
+ {
+ oss << this->GetModelName();
+ }
+
+ // remove extra spaces
+ kwsys_stl::string tmp=oss.str();
+ size_t pos;
+ while( (pos=tmp.find(" "))!=kwsys_stl::string::npos)
+ {
+ tmp.replace(pos,2," ");
+ }
+
+ return tmp;
+}
+
+const char * SystemInformation::GetOSName()
+{
+ return this->Implementation->GetOSName();
+}
+
+const char * SystemInformation::GetHostname()
+{
+ return this->Implementation->GetHostname();
+}
+
+kwsys_stl::string SystemInformation::GetFullyQualifiedDomainName()
+{
+ kwsys_stl::string fqdn;
+ this->Implementation->GetFullyQualifiedDomainName(fqdn);
+ return fqdn;
+}
+
+const char * SystemInformation::GetOSRelease()
+{
+ return this->Implementation->GetOSRelease();
+}
+
+const char * SystemInformation::GetOSVersion()
+{
+ return this->Implementation->GetOSVersion();
+}
+
+const char * SystemInformation::GetOSPlatform()
+{
+ return this->Implementation->GetOSPlatform();
+}
+
+int SystemInformation::GetOSIsWindows()
+{
+#if defined(_WIN32)
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+int SystemInformation::GetOSIsLinux()
+{
+#if defined(__linux)
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+int SystemInformation::GetOSIsApple()
+{
+#if defined(__APPLE__)
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+kwsys_stl::string SystemInformation::GetOSDescription()
+{
+ kwsys_ios::ostringstream oss;
+ oss
+ << this->GetOSName()
+ << " "
+ << this->GetOSRelease()
+ << " "
+ << this->GetOSVersion();
+
+ return oss.str();
+}
+
+bool SystemInformation::Is64Bits()
+{
+ return this->Implementation->Is64Bits();
+}
+
+unsigned int SystemInformation::GetNumberOfLogicalCPU() // per physical cpu
+{
+ return this->Implementation->GetNumberOfLogicalCPU();
+}
+
+unsigned int SystemInformation::GetNumberOfPhysicalCPU()
+{
+ return this->Implementation->GetNumberOfPhysicalCPU();
+}
+
+bool SystemInformation::DoesCPUSupportCPUID()
+{
+ return this->Implementation->DoesCPUSupportCPUID();
+}
+
+// Retrieve memory information in megabyte.
+size_t SystemInformation::GetTotalVirtualMemory()
+{
+ return this->Implementation->GetTotalVirtualMemory();
+}
+
+size_t SystemInformation::GetAvailableVirtualMemory()
+{
+ return this->Implementation->GetAvailableVirtualMemory();
+}
+
+size_t SystemInformation::GetTotalPhysicalMemory()
+{
+ return this->Implementation->GetTotalPhysicalMemory();
+}
+
+size_t SystemInformation::GetAvailablePhysicalMemory()
+{
+ return this->Implementation->GetAvailablePhysicalMemory();
+}
+
+kwsys_stl::string SystemInformation::GetMemoryDescription(
+ const char *hostLimitEnvVarName,
+ const char *procLimitEnvVarName)
+{
+ kwsys_ios::ostringstream oss;
+ oss
+ << "Host Total: "
+ << iostreamLongLong(this->GetHostMemoryTotal())
+ << " KiB, Host Available: "
+ << iostreamLongLong(this->GetHostMemoryAvailable(hostLimitEnvVarName))
+ << " KiB, Process Available: "
+ << iostreamLongLong(
+ this->GetProcMemoryAvailable(hostLimitEnvVarName,procLimitEnvVarName))
+ << " KiB";
+ return oss.str();
+}
+
+// host memory info in units of KiB.
+SystemInformation::LongLong SystemInformation::GetHostMemoryTotal()
+{
+ return this->Implementation->GetHostMemoryTotal();
+}
+
+SystemInformation::LongLong
+SystemInformation::GetHostMemoryAvailable(const char *hostLimitEnvVarName)
+{
+ return this->Implementation->GetHostMemoryAvailable(hostLimitEnvVarName);
+}
+
+SystemInformation::LongLong SystemInformation::GetHostMemoryUsed()
+{
+ return this->Implementation->GetHostMemoryUsed();
+}
+
+// process memory info in units of KiB.
+SystemInformation::LongLong
+SystemInformation::GetProcMemoryAvailable(
+ const char *hostLimitEnvVarName,
+ const char *procLimitEnvVarName)
+{
+ return this->Implementation->GetProcMemoryAvailable(
+ hostLimitEnvVarName,
+ procLimitEnvVarName);
+}
+
+SystemInformation::LongLong SystemInformation::GetProcMemoryUsed()
+{
+ return this->Implementation->GetProcMemoryUsed();
+}
+
+SystemInformation::LongLong SystemInformation::GetProcessId()
+{
+ return this->Implementation->GetProcessId();
+}
+
+void SystemInformation::SetStackTraceOnError(int enable)
+{
+ SystemInformationImplementation::SetStackTraceOnError(enable);
+}
+
+kwsys_stl::string SystemInformation::GetProgramStack(int firstFrame, int wholePath)
+{
+ return SystemInformationImplementation::GetProgramStack(firstFrame, wholePath);
+}
+
+/** Run the different checks */
+void SystemInformation::RunCPUCheck()
+{
+ this->Implementation->RunCPUCheck();
+}
+
+void SystemInformation::RunOSCheck()
+{
+ this->Implementation->RunOSCheck();
+}
+
+void SystemInformation::RunMemoryCheck()
+{
+ this->Implementation->RunMemoryCheck();
+}
+
+
+// --------------------------------------------------------------
+// SystemInformationImplementation starts here
+
+#define STORE_TLBCACHE_INFO(x,y) x = (x < y) ? y : x
+#define TLBCACHE_INFO_UNITS (15)
+#define CLASSICAL_CPU_FREQ_LOOP 10000000
+#define RDTSC_INSTRUCTION _asm _emit 0x0f _asm _emit 0x31
+
+#define MMX_FEATURE 0x00000001
+#define MMX_PLUS_FEATURE 0x00000002
+#define SSE_FEATURE 0x00000004
+#define SSE2_FEATURE 0x00000008
+#define AMD_3DNOW_FEATURE 0x00000010
+#define AMD_3DNOW_PLUS_FEATURE 0x00000020
+#define IA64_FEATURE 0x00000040
+#define MP_CAPABLE 0x00000080
+#define HYPERTHREAD_FEATURE 0x00000100
+#define SERIALNUMBER_FEATURE 0x00000200
+#define APIC_FEATURE 0x00000400
+#define SSE_FP_FEATURE 0x00000800
+#define SSE_MMX_FEATURE 0x00001000
+#define CMOV_FEATURE 0x00002000
+#define MTRR_FEATURE 0x00004000
+#define L1CACHE_FEATURE 0x00008000
+#define L2CACHE_FEATURE 0x00010000
+#define L3CACHE_FEATURE 0x00020000
+#define ACPI_FEATURE 0x00040000
+#define THERMALMONITOR_FEATURE 0x00080000
+#define TEMPSENSEDIODE_FEATURE 0x00100000
+#define FREQUENCYID_FEATURE 0x00200000
+#define VOLTAGEID_FREQUENCY 0x00400000
+
+// Status Flag
+#define HT_NOT_CAPABLE 0
+#define HT_ENABLED 1
+#define HT_DISABLED 2
+#define HT_SUPPORTED_NOT_ENABLED 3
+#define HT_CANNOT_DETECT 4
+
+// EDX[28] Bit 28 is set if HT is supported
+#define HT_BIT 0x10000000
+
+// EAX[11:8] Bit 8-11 contains family processor ID.
+#define FAMILY_ID 0x0F00
+#define PENTIUM4_ID 0x0F00
+// EAX[23:20] Bit 20-23 contains extended family processor ID
+#define EXT_FAMILY_ID 0x0F00000
+// EBX[23:16] Bit 16-23 in ebx contains the number of logical
+#define NUM_LOGICAL_BITS 0x00FF0000
+// processors per physical processor when execute cpuid with
+// eax set to 1
+// EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique
+#define INITIAL_APIC_ID_BITS 0xFF000000
+// initial APIC ID for the processor this code is running on.
+// Default value = 0xff if HT is not supported
+
+// Hide implementation details in an anonymous namespace.
+namespace {
+// *****************************************************************************
+#if defined(__linux) || defined(__APPLE__)
+int LoadLines(
+ FILE *file,
+ kwsys_stl::vector<kwsys_stl::string> &lines)
+{
+ // Load each line in the given file into a the vector.
+ int nRead=0;
+ const int bufSize=1024;
+ char buf[bufSize]={'\0'};
+ while (!feof(file) && !ferror(file))
+ {
+ errno=0;
+ if (fgets(buf,bufSize,file) == 0)
+ {
+ if (ferror(file) && (errno==EINTR))
+ {
+ clearerr(file);
+ }
+ continue;
+ }
+ char *pBuf=buf;
+ while(*pBuf)
+ {
+ if (*pBuf=='\n') *pBuf='\0';
+ pBuf+=1;
+ }
+ lines.push_back(buf);
+ ++nRead;
+ }
+ if (ferror(file))
+ {
+ return 0;
+ }
+ return nRead;
+}
+
+# if defined(__linux)
+// *****************************************************************************
+int LoadLines(
+ const char *fileName,
+ kwsys_stl::vector<kwsys_stl::string> &lines)
+{
+ FILE *file=fopen(fileName,"r");
+ if (file==0)
+ {
+ return 0;
+ }
+ int nRead=LoadLines(file,lines);
+ fclose(file);
+ return nRead;
+}
+# endif
+
+// ****************************************************************************
+template<typename T>
+int NameValue(
+ kwsys_stl::vector<kwsys_stl::string> &lines,
+ kwsys_stl::string name, T &value)
+{
+ size_t nLines=lines.size();
+ for (size_t i=0; i<nLines; ++i)
+ {
+ size_t at=lines[i].find(name);
+ if (at==kwsys_stl::string::npos)
+ {
+ continue;
+ }
+ kwsys_ios::istringstream is(lines[i].substr(at+name.size()));
+ is >> value;
+ return 0;
+ }
+ return -1;
+}
+#endif
+
+#if defined(__linux)
+// ****************************************************************************
+template<typename T>
+int GetFieldsFromFile(
+ const char *fileName,
+ const char **fieldNames,
+ T *values)
+{
+ kwsys_stl::vector<kwsys_stl::string> fields;
+ if (!LoadLines(fileName,fields))
+ {
+ return -1;
+ }
+ int i=0;
+ while (fieldNames[i]!=NULL)
+ {
+ int ierr=NameValue(fields,fieldNames[i],values[i]);
+ if (ierr)
+ {
+ return -(i+2);
+ }
+ i+=1;
+ }
+ return 0;
+}
+
+// ****************************************************************************
+template<typename T>
+int GetFieldFromFile(
+ const char *fileName,
+ const char *fieldName,
+ T &value)
+{
+ const char *fieldNames[2]={fieldName,NULL};
+ T values[1]={T(0)};
+ int ierr=GetFieldsFromFile(fileName,fieldNames,values);
+ if (ierr)
+ {
+ return ierr;
+ }
+ value=values[0];
+ return 0;
+}
+#endif
+
+// ****************************************************************************
+#if defined(__APPLE__)
+template<typename T>
+int GetFieldsFromCommand(
+ const char *command,
+ const char **fieldNames,
+ T *values)
+{
+ FILE *file=popen(command,"r");
+ if (file==0)
+ {
+ return -1;
+ }
+ kwsys_stl::vector<kwsys_stl::string> fields;
+ int nl=LoadLines(file,fields);
+ pclose(file);
+ if (nl==0)
+ {
+ return -1;
+ }
+ int i=0;
+ while (fieldNames[i]!=NULL)
+ {
+ int ierr=NameValue(fields,fieldNames[i],values[i]);
+ if (ierr)
+ {
+ return -(i+2);
+ }
+ i+=1;
+ }
+ return 0;
+}
+#endif
+
+// ****************************************************************************
+#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
+void StacktraceSignalHandler(
+ int sigNo,
+ siginfo_t *sigInfo,
+ void * /*sigContext*/)
+{
+#if defined(__linux) || defined(__APPLE__)
+ kwsys_ios::ostringstream oss;
+ oss
+ << kwsys_ios::endl
+ << "=========================================================" << kwsys_ios::endl
+ << "Process id " << getpid() << " ";
+ switch (sigNo)
+ {
+ case SIGINT:
+ oss << "Caught SIGINT";
+ break;
+
+ case SIGTERM:
+ oss << "Caught SIGTERM";
+ break;
+
+ case SIGABRT:
+ oss << "Caught SIGABRT";
+ break;
+
+ case SIGFPE:
+ oss
+ << "Caught SIGFPE at "
+ << (sigInfo->si_addr==0?"0x":"")
+ << sigInfo->si_addr
+ << " ";
+ switch (sigInfo->si_code)
+ {
+# if defined(FPE_INTDIV)
+ case FPE_INTDIV:
+ oss << "integer division by zero";
+ break;
+# endif
+
+# if defined(FPE_INTOVF)
+ case FPE_INTOVF:
+ oss << "integer overflow";
+ break;
+# endif
+
+ case FPE_FLTDIV:
+ oss << "floating point divide by zero";
+ break;
+
+ case FPE_FLTOVF:
+ oss << "floating point overflow";
+ break;
+
+ case FPE_FLTUND:
+ oss << "floating point underflow";
+ break;
+
+ case FPE_FLTRES:
+ oss << "floating point inexact result";
+ break;
+
+ case FPE_FLTINV:
+ oss << "floating point invalid operation";
+ break;
+
+#if defined(FPE_FLTSUB)
+ case FPE_FLTSUB:
+ oss << "floating point subscript out of range";
+ break;
+#endif
+
+ default:
+ oss << "code " << sigInfo->si_code;
+ break;
+ }
+ break;
+
+ case SIGSEGV:
+ oss
+ << "Caught SIGSEGV at "
+ << (sigInfo->si_addr==0?"0x":"")
+ << sigInfo->si_addr
+ << " ";
+ switch (sigInfo->si_code)
+ {
+ case SEGV_MAPERR:
+ oss << "address not mapped to object";
+ break;
+
+ case SEGV_ACCERR:
+ oss << "invalid permission for mapped object";
+ break;
+
+ default:
+ oss << "code " << sigInfo->si_code;
+ break;
+ }
+ break;
+
+ case SIGBUS:
+ oss
+ << "Caught SIGBUS at "
+ << (sigInfo->si_addr==0?"0x":"")
+ << sigInfo->si_addr
+ << " ";
+ switch (sigInfo->si_code)
+ {
+ case BUS_ADRALN:
+ oss << "invalid address alignment";
+ break;
+
+# if defined(BUS_ADRERR)
+ case BUS_ADRERR:
+ oss << "nonexistent physical address";
+ break;
+# endif
+
+# if defined(BUS_OBJERR)
+ case BUS_OBJERR:
+ oss << "object-specific hardware error";
+ break;
+# endif
+
+# if defined(BUS_MCEERR_AR)
+ case BUS_MCEERR_AR:
+ oss << "Hardware memory error consumed on a machine check; action required.";
+ break;
+# endif
+
+# if defined(BUS_MCEERR_AO)
+ case BUS_MCEERR_AO:
+ oss << "Hardware memory error detected in process but not consumed; action optional.";
+ break;
+# endif
+
+ default:
+ oss << "code " << sigInfo->si_code;
+ break;
+ }
+ break;
+
+ case SIGILL:
+ oss
+ << "Caught SIGILL at "
+ << (sigInfo->si_addr==0?"0x":"")
+ << sigInfo->si_addr
+ << " ";
+ switch (sigInfo->si_code)
+ {
+ case ILL_ILLOPC:
+ oss << "illegal opcode";
+ break;
+
+# if defined(ILL_ILLOPN)
+ case ILL_ILLOPN:
+ oss << "illegal operand";
+ break;
+# endif
+
+# if defined(ILL_ILLADR)
+ case ILL_ILLADR:
+ oss << "illegal addressing mode.";
+ break;
+# endif
+
+ case ILL_ILLTRP:
+ oss << "illegal trap";
+
+ case ILL_PRVOPC:
+ oss << "privileged opcode";
+ break;
+
+# if defined(ILL_PRVREG)
+ case ILL_PRVREG:
+ oss << "privileged register";
+ break;
+# endif
+
+# if defined(ILL_COPROC)
+ case ILL_COPROC:
+ oss << "co-processor error";
+ break;
+# endif
+
+# if defined(ILL_BADSTK)
+ case ILL_BADSTK:
+ oss << "internal stack error";
+ break;
+# endif
+
+ default:
+ oss << "code " << sigInfo->si_code;
+ break;
+ }
+ break;
+
+ default:
+ oss << "Caught " << sigNo << " code " << sigInfo->si_code;
+ break;
+ }
+ oss
+ << kwsys_ios::endl
+ << "Program Stack:" << kwsys_ios::endl
+ << SystemInformationImplementation::GetProgramStack(2,0)
+ << "=========================================================" << kwsys_ios::endl;
+ kwsys_ios::cerr << oss.str() << kwsys_ios::endl;
+
+ // restore the previously registered handlers
+ // and abort
+ SystemInformationImplementation::SetStackTraceOnError(0);
+ abort();
+#else
+ // avoid warning C4100
+ (void)sigNo;
+ (void)sigInfo;
+#endif
+}
+#endif
+
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+#define safes(_arg)((_arg)?(_arg):"???")
+
+// Description:
+// A container for symbol properties. Each instance
+// must be Initialized.
+class SymbolProperties
+{
+public:
+ SymbolProperties();
+
+ // Description:
+ // The SymbolProperties instance must be initialized by
+ // passing a stack address.
+ void Initialize(void *address);
+
+ // Description:
+ // Get the symbol's stack address.
+ void *GetAddress() const { return this->Address; }
+
+ // Description:
+ // If not set paths will be removed. eg, from a binary
+ // or source file.
+ void SetReportPath(int rp){ this->ReportPath=rp; }
+
+ // Description:
+ // Set/Get the name of the binary file that the symbol
+ // is found in.
+ void SetBinary(const char *binary)
+ { this->Binary=safes(binary); }
+
+ kwsys_stl::string GetBinary() const;
+
+ // Description:
+ // Set the name of the function that the symbol is found in.
+ // If c++ demangling is supported it will be demangled.
+ void SetFunction(const char *function)
+ { this->Function=this->Demangle(function); }
+
+ kwsys_stl::string GetFunction() const
+ { return this->Function; }
+
+ // Description:
+ // Set/Get the name of the source file where the symbol
+ // is defined.
+ void SetSourceFile(const char *sourcefile)
+ { this->SourceFile=safes(sourcefile); }
+
+ kwsys_stl::string GetSourceFile() const
+ { return this->GetFileName(this->SourceFile); }
+
+ // Description:
+ // Set/Get the line number where the symbol is defined
+ void SetLineNumber(long linenumber){ this->LineNumber=linenumber; }
+ long GetLineNumber() const { return this->LineNumber; }
+
+ // Description:
+ // Set the address where the biinary image is mapped
+ // into memory.
+ void SetBinaryBaseAddress(void *address)
+ { this->BinaryBaseAddress=address; }
+
+private:
+ void *GetRealAddress() const
+ { return (void*)((char*)this->Address-(char*)this->BinaryBaseAddress); }
+
+ kwsys_stl::string GetFileName(const kwsys_stl::string &path) const;
+ kwsys_stl::string Demangle(const char *symbol) const;
+
+private:
+ kwsys_stl::string Binary;
+ void *BinaryBaseAddress;
+ void *Address;
+ kwsys_stl::string SourceFile;
+ kwsys_stl::string Function;
+ long LineNumber;
+ int ReportPath;
+};
+
+// --------------------------------------------------------------------------
+kwsys_ios::ostream &operator<<(
+ kwsys_ios::ostream &os,
+ const SymbolProperties &sp)
+{
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+ os
+ << kwsys_ios::hex << sp.GetAddress() << " : "
+ << sp.GetFunction()
+ << " [(" << sp.GetBinary() << ") "
+ << sp.GetSourceFile() << ":"
+ << kwsys_ios::dec << sp.GetLineNumber() << "]";
+#elif defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+ void *addr = sp.GetAddress();
+ char **syminfo = backtrace_symbols(&addr,1);
+ os << safes(syminfo[0]);
+ free(syminfo);
+#else
+ (void)os;
+ (void)sp;
+#endif
+ return os;
+}
+
+// --------------------------------------------------------------------------
+SymbolProperties::SymbolProperties()
+{
+ // not using an initializer list
+ // to avoid some PGI compiler warnings
+ this->SetBinary("???");
+ this->SetBinaryBaseAddress(NULL);
+ this->Address = NULL;
+ this->SetSourceFile("???");
+ this->SetFunction("???");
+ this->SetLineNumber(-1);
+ this->SetReportPath(0);
+ // avoid PGI compiler warnings
+ this->GetRealAddress();
+ this->GetFunction();
+ this->GetSourceFile();
+ this->GetLineNumber();
+}
+
+// --------------------------------------------------------------------------
+kwsys_stl::string SymbolProperties::GetFileName(const kwsys_stl::string &path) const
+{
+ kwsys_stl::string file(path);
+ if (!this->ReportPath)
+ {
+ size_t at = file.rfind("/");
+ if (at!=kwsys_stl::string::npos)
+ {
+ file = file.substr(at+1,kwsys_stl::string::npos);
+ }
+ }
+ return file;
+}
+
+// --------------------------------------------------------------------------
+kwsys_stl::string SymbolProperties::GetBinary() const
+{
+// only linux has proc fs
+#if defined(__linux__)
+ if (this->Binary=="/proc/self/exe")
+ {
+ kwsys_stl::string binary;
+ char buf[1024]={'\0'};
+ ssize_t ll=0;
+ if ((ll=readlink("/proc/self/exe",buf,1024))>0)
+ {
+ buf[ll]='\0';
+ binary=buf;
+ }
+ else
+ {
+ binary="/proc/self/exe";
+ }
+ return this->GetFileName(binary);
+ }
+#endif
+ return this->GetFileName(this->Binary);
+}
+
+// --------------------------------------------------------------------------
+kwsys_stl::string SymbolProperties::Demangle(const char *symbol) const
+{
+ kwsys_stl::string result = safes(symbol);
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
+ int status = 0;
+ size_t bufferLen = 1024;
+ char *buffer = (char*)malloc(1024);
+ char *demangledSymbol =
+ abi::__cxa_demangle(symbol, buffer, &bufferLen, &status);
+ if (!status)
+ {
+ result = demangledSymbol;
+ }
+ free(buffer);
+#else
+ (void)symbol;
+#endif
+ return result;
+}
+
+// --------------------------------------------------------------------------
+void SymbolProperties::Initialize(void *address)
+{
+ this->Address = address;
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+ // first fallback option can demangle c++ functions
+ Dl_info info;
+ int ierr=dladdr(this->Address,&info);
+ if (ierr && info.dli_sname && info.dli_saddr)
+ {
+ this->SetBinary(info.dli_fname);
+ this->SetFunction(info.dli_sname);
+ }
+#else
+ // second fallback use builtin backtrace_symbols
+ // to decode the bactrace.
+#endif
+}
+#endif // don't define this class if we're not using it
+
+} // anonymous namespace
+
+
+SystemInformationImplementation::SystemInformationImplementation()
+{
+ this->TotalVirtualMemory = 0;
+ this->AvailableVirtualMemory = 0;
+ this->TotalPhysicalMemory = 0;
+ this->AvailablePhysicalMemory = 0;
+ this->CurrentPositionInFile = 0;
+ this->ChipManufacturer = UnknownManufacturer;
+ memset(&this->Features, 0, sizeof(CPUFeatures));
+ this->ChipID.Type = 0;
+ this->ChipID.Family = 0;
+ this->ChipID.Model = 0;
+ this->ChipID.Revision = 0;
+ this->ChipID.ExtendedFamily = 0;
+ this->ChipID.ExtendedModel = 0;
+ this->CPUSpeedInMHz = 0;
+ this->NumberOfLogicalCPU = 0;
+ this->NumberOfPhysicalCPU = 0;
+ this->OSName = "";
+ this->Hostname = "";
+ this->OSRelease = "";
+ this->OSVersion = "";
+ this->OSPlatform = "";
+}
+
+SystemInformationImplementation::~SystemInformationImplementation()
+{
+}
+
+void SystemInformationImplementation::RunCPUCheck()
+{
+#ifdef WIN32
+ // Check to see if this processor supports CPUID.
+ bool supportsCPUID = DoesCPUSupportCPUID();
+
+ if (supportsCPUID)
+ {
+ // Retrieve the CPU details.
+ RetrieveCPUIdentity();
+ this->FindManufacturer();
+ RetrieveCPUFeatures();
+ }
+
+ // These two may be called without support for the CPUID instruction.
+ // (But if the instruction is there, they should be called *after*
+ // the above call to RetrieveCPUIdentity... that's why the two if
+ // blocks exist with the same "if (supportsCPUID)" logic...
+ //
+ if (!RetrieveCPUClockSpeed())
+ {
+ RetrieveClassicalCPUClockSpeed();
+ }
+
+ if (supportsCPUID)
+ {
+ // Retrieve cache information.
+ if (!RetrieveCPUCacheDetails())
+ {
+ RetrieveClassicalCPUCacheDetails();
+ }
+
+ // Retrieve the extended CPU details.
+ if (!RetrieveExtendedCPUIdentity())
+ {
+ RetrieveClassicalCPUIdentity();
+ }
+
+ RetrieveExtendedCPUFeatures();
+ RetrieveCPUPowerManagement();
+
+ // Now attempt to retrieve the serial number (if possible).
+ RetrieveProcessorSerialNumber();
+ }
+
+ this->CPUCount();
+
+#elif defined(__APPLE__)
+ this->ParseSysCtl();
+#elif defined (__SVR4) && defined (__sun)
+ this->QuerySolarisProcessor();
+#elif defined(__HAIKU__)
+ this->QueryHaikuInfo();
+#elif defined(__QNX__)
+ this->QueryQNXProcessor();
+#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
+ this->QueryBSDProcessor();
+#elif defined(__hpux)
+ this->QueryHPUXProcessor();
+#elif defined(__linux) || defined(__CYGWIN__)
+ this->RetreiveInformationFromCpuInfoFile();
+#else
+ this->QueryProcessor();
+#endif
+}
+
+void SystemInformationImplementation::RunOSCheck()
+{
+ this->QueryOSInformation();
+}
+
+void SystemInformationImplementation::RunMemoryCheck()
+{
+#if defined(__APPLE__)
+ this->ParseSysCtl();
+#elif defined (__SVR4) && defined (__sun)
+ this->QuerySolarisMemory();
+#elif defined(__HAIKU__)
+ this->QueryHaikuInfo();
+#elif defined(__QNX__)
+ this->QueryQNXMemory();
+#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
+ this->QueryBSDMemory();
+#elif defined(__CYGWIN__)
+ this->QueryCygwinMemory();
+#elif defined(_WIN32)
+ this->QueryWindowsMemory();
+#elif defined(__hpux)
+ this->QueryHPUXMemory();
+#elif defined(__linux)
+ this->QueryLinuxMemory();
+#elif defined(_AIX)
+ this->QueryAIXMemory();
+#else
+ this->QueryMemory();
+#endif
+}
+
+/** Get the vendor string */
+const char * SystemInformationImplementation::GetVendorString()
+{
+ return this->ChipID.Vendor.c_str();
+}
+
+/** Get the OS Name */
+const char * SystemInformationImplementation::GetOSName()
+{
+ return this->OSName.c_str();
+}
+
+/** Get the hostname */
+const char* SystemInformationImplementation::GetHostname()
+{
+ if (this->Hostname.empty())
+ {
+ this->Hostname="localhost";
+#if defined(_WIN32)
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ char name[255];
+ wVersionRequested = MAKEWORD(2,0);
+ if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
+ {
+ gethostname(name,sizeof(name));
+ WSACleanup( );
+ }
+ this->Hostname = name;
+#else
+ struct utsname unameInfo;
+ int errorFlag = uname(&unameInfo);
+ if(errorFlag == 0)
+ {
+ this->Hostname = unameInfo.nodename;
+ }
+#endif
+ }
+ return this->Hostname.c_str();
+}
+
+/** Get the FQDN */
+int SystemInformationImplementation::GetFullyQualifiedDomainName(
+ kwsys_stl::string &fqdn)
+{
+ // in the event of absolute failure return localhost.
+ fqdn="localhost";
+
+#if defined(_WIN32)
+ int ierr;
+ // TODO - a more robust implementation for windows, see comments
+ // in unix implementation.
+ WSADATA wsaData;
+ WORD ver=MAKEWORD(2,0);
+ ierr=WSAStartup(ver,&wsaData);
+ if (ierr)
+ {
+ return -1;
+ }
+
+ char base[256]={'\0'};
+ ierr=gethostname(base,256);
+ if (ierr)
+ {
+ WSACleanup();
+ return -2;
+ }
+ fqdn=base;
+
+ HOSTENT *hent=gethostbyname(base);
+ if (hent)
+ {
+ fqdn=hent->h_name;
+ }
+
+ WSACleanup();
+ return 0;
+
+#elif defined(KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN)
+ // gethostname typical returns an alias for loopback interface
+ // we want the fully qualified domain name. Because there are
+ // any number of interfaces on this system we look for the
+ // first of these that contains the name returned by gethostname
+ // and is longer. failing that we return gethostname and indicate
+ // with a failure code. Return of a failure code is not necessarilly
+ // an indication of an error. for instance gethostname may return
+ // the fully qualified domain name, or there may not be one if the
+ // system lives on a private network such as in the case of a cluster
+ // node.
+
+ int ierr=0;
+ char base[NI_MAXHOST];
+ ierr=gethostname(base,NI_MAXHOST);
+ if (ierr)
+ {
+ return -1;
+ }
+ size_t baseSize=strlen(base);
+ fqdn=base;
+
+ struct ifaddrs *ifas;
+ struct ifaddrs *ifa;
+ ierr=getifaddrs(&ifas);
+ if (ierr)
+ {
+ return -2;
+ }
+
+ for (ifa=ifas; ifa!=NULL; ifa=ifa->ifa_next)
+ {
+ int fam = ifa->ifa_addr? ifa->ifa_addr->sa_family : -1;
+ if ((fam==AF_INET) || (fam==AF_INET6))
+ {
+ char host[NI_MAXHOST]={'\0'};
+
+ const size_t addrlen
+ = (fam==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6));
+
+ ierr=getnameinfo(
+ ifa->ifa_addr,
+ static_cast<socklen_t>(addrlen),
+ host,
+ NI_MAXHOST,
+ NULL,
+ 0,
+ NI_NAMEREQD);
+ if (ierr)
+ {
+ // don't report the failure now since we may succeed on another
+ // interface. If all attempts fail then return the failure code.
+ ierr=-3;
+ continue;
+ }
+
+ kwsys_stl::string candidate=host;
+ if ((candidate.find(base)!=kwsys_stl::string::npos) && baseSize<candidate.size())
+ {
+ // success, stop now.
+ ierr=0;
+ fqdn=candidate;
+ break;
+ }
+ }
+ }
+ freeifaddrs(ifas);
+
+ return ierr;
+#else
+ /* TODO: Implement on more platforms. */
+ fqdn=this->GetHostname();
+ return -1;
+#endif
+}
+
+/** Get the OS release */
+const char* SystemInformationImplementation::GetOSRelease()
+{
+ return this->OSRelease.c_str();
+}
+
+/** Get the OS version */
+const char* SystemInformationImplementation::GetOSVersion()
+{
+ return this->OSVersion.c_str();
+}
+
+/** Get the OS platform */
+const char* SystemInformationImplementation::GetOSPlatform()
+{
+ return this->OSPlatform.c_str();
+}
+
+/** Get the vendor ID */
+const char * SystemInformationImplementation::GetVendorID()
+{
+ // Return the vendor ID.
+ switch (this->ChipManufacturer)
+ {
+ case Intel:
+ return "Intel Corporation";
+ case AMD:
+ return "Advanced Micro Devices";
+ case NSC:
+ return "National Semiconductor";
+ case Cyrix:
+ return "Cyrix Corp., VIA Inc.";
+ case NexGen:
+ return "NexGen Inc., Advanced Micro Devices";
+ case IDT:
+ return "IDT\\Centaur, Via Inc.";
+ case UMC:
+ return "United Microelectronics Corp.";
+ case Rise:
+ return "Rise";
+ case Transmeta:
+ return "Transmeta";
+ case Sun:
+ return "Sun Microelectronics";
+ case IBM:
+ return "IBM";
+ case Motorola:
+ return "Motorola";
+ case HP:
+ return "Hewlett-Packard";
+ default:
+ return "Unknown Manufacturer";
+ }
+}
+
+/** Return the type ID of the CPU */
+kwsys_stl::string SystemInformationImplementation::GetTypeID()
+{
+ kwsys_ios::ostringstream str;
+ str << this->ChipID.Type;
+ return str.str();
+}
+
+/** Return the family of the CPU present */
+kwsys_stl::string SystemInformationImplementation::GetFamilyID()
+{
+ kwsys_ios::ostringstream str;
+ str << this->ChipID.Family;
+ return str.str();
+}
+
+// Return the model of CPU present */
+kwsys_stl::string SystemInformationImplementation::GetModelID()
+{
+ kwsys_ios::ostringstream str;
+ str << this->ChipID.Model;
+ return str.str();
+}
+
+// Return the model name of CPU present */
+kwsys_stl::string SystemInformationImplementation::GetModelName()
+{
+ return this->ChipID.ModelName;
+}
+
+/** Return the stepping code of the CPU present. */
+kwsys_stl::string SystemInformationImplementation::GetSteppingCode()
+{
+ kwsys_ios::ostringstream str;
+ str << this->ChipID.Revision;
+ return str.str();
+}
+
+/** Return the stepping code of the CPU present. */
+const char * SystemInformationImplementation::GetExtendedProcessorName()
+{
+ return this->ChipID.ProcessorName.c_str();
+}
+
+/** Return the serial number of the processor
+ * in hexadecimal: xxxx-xxxx-xxxx-xxxx-xxxx-xxxx. */
+const char * SystemInformationImplementation::GetProcessorSerialNumber()
+{
+ return this->ChipID.SerialNumber.c_str();
+}
+
+/** Return the logical processors per physical */
+unsigned int SystemInformationImplementation::GetLogicalProcessorsPerPhysical()
+{
+ return this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical;
+}
+
+/** Return the processor clock frequency. */
+float SystemInformationImplementation::GetProcessorClockFrequency()
+{
+ return this->CPUSpeedInMHz;
+}
+
+/** Return the APIC ID. */
+int SystemInformationImplementation::GetProcessorAPICID()
+{
+ return this->Features.ExtendedFeatures.APIC_ID;
+}
+
+/** Return the L1 cache size. */
+int SystemInformationImplementation::GetProcessorCacheSize()
+{
+ return this->Features.L1CacheSize;
+}
+
+/** Return the chosen cache size. */
+int SystemInformationImplementation::GetProcessorCacheXSize(long int dwCacheID)
+{
+ switch (dwCacheID)
+ {
+ case L1CACHE_FEATURE:
+ return this->Features.L1CacheSize;
+ case L2CACHE_FEATURE:
+ return this->Features.L2CacheSize;
+ case L3CACHE_FEATURE:
+ return this->Features.L3CacheSize;
+ }
+ return -1;
+}
+
+
+bool SystemInformationImplementation::DoesCPUSupportFeature(long int dwFeature)
+{
+ bool bHasFeature = false;
+
+ // Check for MMX instructions.
+ if (((dwFeature & MMX_FEATURE) != 0) && this->Features.HasMMX) bHasFeature = true;
+
+ // Check for MMX+ instructions.
+ if (((dwFeature & MMX_PLUS_FEATURE) != 0) && this->Features.ExtendedFeatures.HasMMXPlus) bHasFeature = true;
+
+ // Check for SSE FP instructions.
+ if (((dwFeature & SSE_FEATURE) != 0) && this->Features.HasSSE) bHasFeature = true;
+
+ // Check for SSE FP instructions.
+ if (((dwFeature & SSE_FP_FEATURE) != 0) && this->Features.HasSSEFP) bHasFeature = true;
+
+ // Check for SSE MMX instructions.
+ if (((dwFeature & SSE_MMX_FEATURE) != 0) && this->Features.ExtendedFeatures.HasSSEMMX) bHasFeature = true;
+
+ // Check for SSE2 instructions.
+ if (((dwFeature & SSE2_FEATURE) != 0) && this->Features.HasSSE2) bHasFeature = true;
+
+ // Check for 3DNow! instructions.
+ if (((dwFeature & AMD_3DNOW_FEATURE) != 0) && this->Features.ExtendedFeatures.Has3DNow) bHasFeature = true;
+
+ // Check for 3DNow+ instructions.
+ if (((dwFeature & AMD_3DNOW_PLUS_FEATURE) != 0) && this->Features.ExtendedFeatures.Has3DNowPlus) bHasFeature = true;
+
+ // Check for IA64 instructions.
+ if (((dwFeature & IA64_FEATURE) != 0) && this->Features.HasIA64) bHasFeature = true;
+
+ // Check for MP capable.
+ if (((dwFeature & MP_CAPABLE) != 0) && this->Features.ExtendedFeatures.SupportsMP) bHasFeature = true;
+
+ // Check for a serial number for the processor.
+ if (((dwFeature & SERIALNUMBER_FEATURE) != 0) && this->Features.HasSerial) bHasFeature = true;
+
+ // Check for a local APIC in the processor.
+ if (((dwFeature & APIC_FEATURE) != 0) && this->Features.HasAPIC) bHasFeature = true;
+
+ // Check for CMOV instructions.
+ if (((dwFeature & CMOV_FEATURE) != 0) && this->Features.HasCMOV) bHasFeature = true;
+
+ // Check for MTRR instructions.
+ if (((dwFeature & MTRR_FEATURE) != 0) && this->Features.HasMTRR) bHasFeature = true;
+
+ // Check for L1 cache size.
+ if (((dwFeature & L1CACHE_FEATURE) != 0) && (this->Features.L1CacheSize != -1)) bHasFeature = true;
+
+ // Check for L2 cache size.
+ if (((dwFeature & L2CACHE_FEATURE) != 0) && (this->Features.L2CacheSize != -1)) bHasFeature = true;
+
+ // Check for L3 cache size.
+ if (((dwFeature & L3CACHE_FEATURE) != 0) && (this->Features.L3CacheSize != -1)) bHasFeature = true;
+
+ // Check for ACPI capability.
+ if (((dwFeature & ACPI_FEATURE) != 0) && this->Features.HasACPI) bHasFeature = true;
+
+ // Check for thermal monitor support.
+ if (((dwFeature & THERMALMONITOR_FEATURE) != 0) && this->Features.HasThermal) bHasFeature = true;
+
+ // Check for temperature sensing diode support.
+ if (((dwFeature & TEMPSENSEDIODE_FEATURE) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode) bHasFeature = true;
+
+ // Check for frequency ID support.
+ if (((dwFeature & FREQUENCYID_FEATURE) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID) bHasFeature = true;
+
+ // Check for voltage ID support.
+ if (((dwFeature & VOLTAGEID_FREQUENCY) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasVoltageID) bHasFeature = true;
+
+ return bHasFeature;
+}
+
+
+void SystemInformationImplementation::Delay(unsigned int uiMS)
+{
+#ifdef WIN32
+ LARGE_INTEGER Frequency, StartCounter, EndCounter;
+ __int64 x;
+
+ // Get the frequency of the high performance counter.
+ if (!QueryPerformanceFrequency (&Frequency)) return;
+ x = Frequency.QuadPart / 1000 * uiMS;
+
+ // Get the starting position of the counter.
+ QueryPerformanceCounter (&StartCounter);
+
+ do {
+ // Get the ending position of the counter.
+ QueryPerformanceCounter (&EndCounter);
+ } while (EndCounter.QuadPart - StartCounter.QuadPart < x);
+#endif
+ (void)uiMS;
+}
+
+
+bool SystemInformationImplementation::DoesCPUSupportCPUID()
+{
+#if USE_CPUID
+ int dummy[4] = { 0, 0, 0, 0 };
+
+#if USE_ASM_INSTRUCTIONS
+ return call_cpuid(0, dummy);
+#else
+ call_cpuid(0, dummy);
+ return dummy[0] || dummy[1] || dummy[2] || dummy[3];
+#endif
+#else
+ // Assume no cpuid instruction.
+ return false;
+#endif
+}
+
+
+bool SystemInformationImplementation::RetrieveCPUFeatures()
+{
+#if USE_CPUID
+ int cpuinfo[4] = { 0, 0, 0, 0 };
+
+ if (!call_cpuid(1, cpuinfo))
+ {
+ return false;
+ }
+
+ // Retrieve the features of CPU present.
+ this->Features.HasFPU = ((cpuinfo[3] & 0x00000001) != 0); // FPU Present --> Bit 0
+ this->Features.HasTSC = ((cpuinfo[3] & 0x00000010) != 0); // TSC Present --> Bit 4
+ this->Features.HasAPIC = ((cpuinfo[3] & 0x00000200) != 0); // APIC Present --> Bit 9
+ this->Features.HasMTRR = ((cpuinfo[3] & 0x00001000) != 0); // MTRR Present --> Bit 12
+ this->Features.HasCMOV = ((cpuinfo[3] & 0x00008000) != 0); // CMOV Present --> Bit 15
+ this->Features.HasSerial = ((cpuinfo[3] & 0x00040000) != 0); // Serial Present --> Bit 18
+ this->Features.HasACPI = ((cpuinfo[3] & 0x00400000) != 0); // ACPI Capable --> Bit 22
+ this->Features.HasMMX = ((cpuinfo[3] & 0x00800000) != 0); // MMX Present --> Bit 23
+ this->Features.HasSSE = ((cpuinfo[3] & 0x02000000) != 0); // SSE Present --> Bit 25
+ this->Features.HasSSE2 = ((cpuinfo[3] & 0x04000000) != 0); // SSE2 Present --> Bit 26
+ this->Features.HasThermal = ((cpuinfo[3] & 0x20000000) != 0); // Thermal Monitor Present --> Bit 29
+ this->Features.HasIA64 = ((cpuinfo[3] & 0x40000000) != 0); // IA64 Present --> Bit 30
+
+#if USE_ASM_INSTRUCTIONS
+ // Retrieve extended SSE capabilities if SSE is available.
+ if (this->Features.HasSSE) {
+
+ // Attempt to __try some SSE FP instructions.
+ __try
+ {
+ // Perform: orps xmm0, xmm0
+ _asm
+ {
+ _emit 0x0f
+ _emit 0x56
+ _emit 0xc0
+ }
+
+ // SSE FP capable processor.
+ this->Features.HasSSEFP = true;
+ }
+ __except(1)
+ {
+ // bad instruction - processor or OS cannot handle SSE FP.
+ this->Features.HasSSEFP = false;
+ }
+ }
+ else
+ {
+ // Set the advanced SSE capabilities to not available.
+ this->Features.HasSSEFP = false;
+ }
+#else
+ this->Features.HasSSEFP = false;
+#endif
+
+ // Retrieve Intel specific extended features.
+ if (this->ChipManufacturer == Intel)
+ {
+ this->Features.ExtendedFeatures.SupportsHyperthreading = ((cpuinfo[3] & 0x10000000) != 0); // Intel specific: Hyperthreading --> Bit 28
+ this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = (this->Features.ExtendedFeatures.SupportsHyperthreading) ? ((cpuinfo[1] & 0x00FF0000) >> 16) : 1;
+
+ if ((this->Features.ExtendedFeatures.SupportsHyperthreading) && (this->Features.HasAPIC))
+ {
+ // Retrieve APIC information if there is one present.
+ this->Features.ExtendedFeatures.APIC_ID = ((cpuinfo[1] & 0xFF000000) >> 24);
+ }
+ }
+
+ return true;
+
+#else
+ return false;
+#endif
+}
+
+
+/** Find the manufacturer given the vendor id */
+void SystemInformationImplementation::FindManufacturer(const kwsys_stl::string& family)
+{
+ if (this->ChipID.Vendor == "GenuineIntel") this->ChipManufacturer = Intel; // Intel Corp.
+ else if (this->ChipID.Vendor == "UMC UMC UMC ") this->ChipManufacturer = UMC; // United Microelectronics Corp.
+ else if (this->ChipID.Vendor == "AuthenticAMD") this->ChipManufacturer = AMD; // Advanced Micro Devices
+ else if (this->ChipID.Vendor == "AMD ISBETTER") this->ChipManufacturer = AMD; // Advanced Micro Devices (1994)
+ else if (this->ChipID.Vendor == "CyrixInstead") this->ChipManufacturer = Cyrix; // Cyrix Corp., VIA Inc.
+ else if (this->ChipID.Vendor == "NexGenDriven") this->ChipManufacturer = NexGen; // NexGen Inc. (now AMD)
+ else if (this->ChipID.Vendor == "CentaurHauls") this->ChipManufacturer = IDT; // IDT/Centaur (now VIA)
+ else if (this->ChipID.Vendor == "RiseRiseRise") this->ChipManufacturer = Rise; // Rise
+ else if (this->ChipID.Vendor == "GenuineTMx86") this->ChipManufacturer = Transmeta; // Transmeta
+ else if (this->ChipID.Vendor == "TransmetaCPU") this->ChipManufacturer = Transmeta; // Transmeta
+ else if (this->ChipID.Vendor == "Geode By NSC") this->ChipManufacturer = NSC; // National Semiconductor
+ else if (this->ChipID.Vendor == "Sun") this->ChipManufacturer = Sun; // Sun Microelectronics
+ else if (this->ChipID.Vendor == "IBM") this->ChipManufacturer = IBM; // IBM Microelectronics
+ else if (this->ChipID.Vendor == "Hewlett-Packard") this->ChipManufacturer = HP; // Hewlett-Packard
+ else if (this->ChipID.Vendor == "Motorola") this->ChipManufacturer = Motorola; // Motorola Microelectronics
+ else if (family.substr(0, 7) == "PA-RISC") this->ChipManufacturer = HP; // Hewlett-Packard
+ else this->ChipManufacturer = UnknownManufacturer; // Unknown manufacturer
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveCPUIdentity()
+{
+#if USE_CPUID
+ int localCPUVendor[4];
+ int localCPUSignature[4];
+
+ if (!call_cpuid(0, localCPUVendor))
+ {
+ return false;
+ }
+ if (!call_cpuid(1, localCPUSignature))
+ {
+ return false;
+ }
+
+ // Process the returned information.
+ // ; eax = 0 --> eax: maximum value of CPUID instruction.
+ // ; ebx: part 1 of 3; CPU signature.
+ // ; edx: part 2 of 3; CPU signature.
+ // ; ecx: part 3 of 3; CPU signature.
+ char vbuf[13];
+ memcpy (&(vbuf[0]), &(localCPUVendor[1]), sizeof (int));
+ memcpy (&(vbuf[4]), &(localCPUVendor[3]), sizeof (int));
+ memcpy (&(vbuf[8]), &(localCPUVendor[2]), sizeof (int));
+ vbuf[12] = '\0';
+ this->ChipID.Vendor = vbuf;
+
+ // Retrieve the family of CPU present.
+ // ; eax = 1 --> eax: CPU ID - bits 31..16 - unused, bits 15..12 - type, bits 11..8 - family, bits 7..4 - model, bits 3..0 - mask revision
+ // ; ebx: 31..24 - default APIC ID, 23..16 - logical processor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID
+ // ; edx: CPU feature flags
+ this->ChipID.ExtendedFamily = ((localCPUSignature[0] & 0x0FF00000) >> 20); // Bits 27..20 Used
+ this->ChipID.ExtendedModel = ((localCPUSignature[0] & 0x000F0000) >> 16); // Bits 19..16 Used
+ this->ChipID.Type = ((localCPUSignature[0] & 0x0000F000) >> 12); // Bits 15..12 Used
+ this->ChipID.Family = ((localCPUSignature[0] & 0x00000F00) >> 8); // Bits 11..8 Used
+ this->ChipID.Model = ((localCPUSignature[0] & 0x000000F0) >> 4); // Bits 7..4 Used
+ this->ChipID.Revision = ((localCPUSignature[0] & 0x0000000F) >> 0); // Bits 3..0 Used
+
+ return true;
+
+#else
+ return false;
+#endif
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveCPUCacheDetails()
+{
+#if USE_CPUID
+ int L1Cache[4] = { 0, 0, 0, 0 };
+ int L2Cache[4] = { 0, 0, 0, 0 };
+
+ // Check to see if what we are about to do is supported...
+ if (RetrieveCPUExtendedLevelSupport (0x80000005))
+ {
+ if (!call_cpuid(0x80000005, L1Cache))
+ {
+ return false;
+ }
+ // Save the L1 data cache size (in KB) from ecx: bits 31..24 as well as data cache size from edx: bits 31..24.
+ this->Features.L1CacheSize = ((L1Cache[2] & 0xFF000000) >> 24);
+ this->Features.L1CacheSize += ((L1Cache[3] & 0xFF000000) >> 24);
+ }
+ else
+ {
+ // Store -1 to indicate the cache could not be queried.
+ this->Features.L1CacheSize = -1;
+ }
+
+ // Check to see if what we are about to do is supported...
+ if (RetrieveCPUExtendedLevelSupport (0x80000006))
+ {
+ if (!call_cpuid(0x80000006, L2Cache))
+ {
+ return false;
+ }
+ // Save the L2 unified cache size (in KB) from ecx: bits 31..16.
+ this->Features.L2CacheSize = ((L2Cache[2] & 0xFFFF0000) >> 16);
+ }
+ else
+ {
+ // Store -1 to indicate the cache could not be queried.
+ this->Features.L2CacheSize = -1;
+ }
+
+ // Define L3 as being not present as we cannot test for it.
+ this->Features.L3CacheSize = -1;
+
+#endif
+
+ // Return failure if we cannot detect either cache with this method.
+ return ((this->Features.L1CacheSize == -1) && (this->Features.L2CacheSize == -1)) ? false : true;
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveClassicalCPUCacheDetails()
+{
+#if USE_CPUID
+ int TLBCode = -1, TLBData = -1, L1Code = -1, L1Data = -1, L1Trace = -1, L2Unified = -1, L3Unified = -1;
+ int TLBCacheData[4] = { 0, 0, 0, 0 };
+ int TLBPassCounter = 0;
+ int TLBCacheUnit = 0;
+
+
+ do {
+ if (!call_cpuid(2, TLBCacheData))
+ {
+ return false;
+ }
+
+ int bob = ((TLBCacheData[0] & 0x00FF0000) >> 16);
+ (void)bob;
+ // Process the returned TLB and cache information.
+ for (int nCounter = 0; nCounter < TLBCACHE_INFO_UNITS; nCounter ++)
+ {
+ // First of all - decide which unit we are dealing with.
+ switch (nCounter)
+ {
+ // eax: bits 8..15 : bits 16..23 : bits 24..31
+ case 0: TLBCacheUnit = ((TLBCacheData[0] & 0x0000FF00) >> 8); break;
+ case 1: TLBCacheUnit = ((TLBCacheData[0] & 0x00FF0000) >> 16); break;
+ case 2: TLBCacheUnit = ((TLBCacheData[0] & 0xFF000000) >> 24); break;
+
+ // ebx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
+ case 3: TLBCacheUnit = ((TLBCacheData[1] & 0x000000FF) >> 0); break;
+ case 4: TLBCacheUnit = ((TLBCacheData[1] & 0x0000FF00) >> 8); break;
+ case 5: TLBCacheUnit = ((TLBCacheData[1] & 0x00FF0000) >> 16); break;
+ case 6: TLBCacheUnit = ((TLBCacheData[1] & 0xFF000000) >> 24); break;
+
+ // ecx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
+ case 7: TLBCacheUnit = ((TLBCacheData[2] & 0x000000FF) >> 0); break;
+ case 8: TLBCacheUnit = ((TLBCacheData[2] & 0x0000FF00) >> 8); break;
+ case 9: TLBCacheUnit = ((TLBCacheData[2] & 0x00FF0000) >> 16); break;
+ case 10: TLBCacheUnit = ((TLBCacheData[2] & 0xFF000000) >> 24); break;
+
+ // edx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
+ case 11: TLBCacheUnit = ((TLBCacheData[3] & 0x000000FF) >> 0); break;
+ case 12: TLBCacheUnit = ((TLBCacheData[3] & 0x0000FF00) >> 8); break;
+ case 13: TLBCacheUnit = ((TLBCacheData[3] & 0x00FF0000) >> 16); break;
+ case 14: TLBCacheUnit = ((TLBCacheData[3] & 0xFF000000) >> 24); break;
+
+ // Default case - an error has occured.
+ default: return false;
+ }
+
+ // Now process the resulting unit to see what it means....
+ switch (TLBCacheUnit)
+ {
+ case 0x00: break;
+ case 0x01: STORE_TLBCACHE_INFO (TLBCode, 4); break;
+ case 0x02: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
+ case 0x03: STORE_TLBCACHE_INFO (TLBData, 4); break;
+ case 0x04: STORE_TLBCACHE_INFO (TLBData, 4096); break;
+ case 0x06: STORE_TLBCACHE_INFO (L1Code, 8); break;
+ case 0x08: STORE_TLBCACHE_INFO (L1Code, 16); break;
+ case 0x0a: STORE_TLBCACHE_INFO (L1Data, 8); break;
+ case 0x0c: STORE_TLBCACHE_INFO (L1Data, 16); break;
+ case 0x10: STORE_TLBCACHE_INFO (L1Data, 16); break; // <-- FIXME: IA-64 Only
+ case 0x15: STORE_TLBCACHE_INFO (L1Code, 16); break; // <-- FIXME: IA-64 Only
+ case 0x1a: STORE_TLBCACHE_INFO (L2Unified, 96); break; // <-- FIXME: IA-64 Only
+ case 0x22: STORE_TLBCACHE_INFO (L3Unified, 512); break;
+ case 0x23: STORE_TLBCACHE_INFO (L3Unified, 1024); break;
+ case 0x25: STORE_TLBCACHE_INFO (L3Unified, 2048); break;
+ case 0x29: STORE_TLBCACHE_INFO (L3Unified, 4096); break;
+ case 0x39: STORE_TLBCACHE_INFO (L2Unified, 128); break;
+ case 0x3c: STORE_TLBCACHE_INFO (L2Unified, 256); break;
+ case 0x40: STORE_TLBCACHE_INFO (L2Unified, 0); break; // <-- FIXME: No integrated L2 cache (P6 core) or L3 cache (P4 core).
+ case 0x41: STORE_TLBCACHE_INFO (L2Unified, 128); break;
+ case 0x42: STORE_TLBCACHE_INFO (L2Unified, 256); break;
+ case 0x43: STORE_TLBCACHE_INFO (L2Unified, 512); break;
+ case 0x44: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
+ case 0x45: STORE_TLBCACHE_INFO (L2Unified, 2048); break;
+ case 0x50: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
+ case 0x51: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
+ case 0x52: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
+ case 0x5b: STORE_TLBCACHE_INFO (TLBData, 4096); break;
+ case 0x5c: STORE_TLBCACHE_INFO (TLBData, 4096); break;
+ case 0x5d: STORE_TLBCACHE_INFO (TLBData, 4096); break;
+ case 0x66: STORE_TLBCACHE_INFO (L1Data, 8); break;
+ case 0x67: STORE_TLBCACHE_INFO (L1Data, 16); break;
+ case 0x68: STORE_TLBCACHE_INFO (L1Data, 32); break;
+ case 0x70: STORE_TLBCACHE_INFO (L1Trace, 12); break;
+ case 0x71: STORE_TLBCACHE_INFO (L1Trace, 16); break;
+ case 0x72: STORE_TLBCACHE_INFO (L1Trace, 32); break;
+ case 0x77: STORE_TLBCACHE_INFO (L1Code, 16); break; // <-- FIXME: IA-64 Only
+ case 0x79: STORE_TLBCACHE_INFO (L2Unified, 128); break;
+ case 0x7a: STORE_TLBCACHE_INFO (L2Unified, 256); break;
+ case 0x7b: STORE_TLBCACHE_INFO (L2Unified, 512); break;
+ case 0x7c: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
+ case 0x7e: STORE_TLBCACHE_INFO (L2Unified, 256); break;
+ case 0x81: STORE_TLBCACHE_INFO (L2Unified, 128); break;
+ case 0x82: STORE_TLBCACHE_INFO (L2Unified, 256); break;
+ case 0x83: STORE_TLBCACHE_INFO (L2Unified, 512); break;
+ case 0x84: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
+ case 0x85: STORE_TLBCACHE_INFO (L2Unified, 2048); break;
+ case 0x88: STORE_TLBCACHE_INFO (L3Unified, 2048); break; // <-- FIXME: IA-64 Only
+ case 0x89: STORE_TLBCACHE_INFO (L3Unified, 4096); break; // <-- FIXME: IA-64 Only
+ case 0x8a: STORE_TLBCACHE_INFO (L3Unified, 8192); break; // <-- FIXME: IA-64 Only
+ case 0x8d: STORE_TLBCACHE_INFO (L3Unified, 3096); break; // <-- FIXME: IA-64 Only
+ case 0x90: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
+ case 0x96: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
+ case 0x9b: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
+
+ // Default case - an error has occured.
+ default: return false;
+ }
+ }
+
+ // Increment the TLB pass counter.
+ TLBPassCounter ++;
+ } while ((TLBCacheData[0] & 0x000000FF) > TLBPassCounter);
+
+ // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
+ if ((L1Code == -1) && (L1Data == -1) && (L1Trace == -1))
+ {
+ this->Features.L1CacheSize = -1;
+ }
+ else if ((L1Code == -1) && (L1Data == -1) && (L1Trace != -1))
+ {
+ this->Features.L1CacheSize = L1Trace;
+ }
+ else if ((L1Code != -1) && (L1Data == -1))
+ {
+ this->Features.L1CacheSize = L1Code;
+ }
+ else if ((L1Code == -1) && (L1Data != -1))
+ {
+ this->Features.L1CacheSize = L1Data;
+ }
+ else if ((L1Code != -1) && (L1Data != -1))
+ {
+ this->Features.L1CacheSize = L1Code + L1Data;
+ }
+ else
+ {
+ this->Features.L1CacheSize = -1;
+ }
+
+ // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
+ if (L2Unified == -1)
+ {
+ this->Features.L2CacheSize = -1;
+ }
+ else
+ {
+ this->Features.L2CacheSize = L2Unified;
+ }
+
+ // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
+ if (L3Unified == -1)
+ {
+ this->Features.L3CacheSize = -1;
+ }
+ else
+ {
+ this->Features.L3CacheSize = L3Unified;
+ }
+
+ return true;
+
+#else
+ return false;
+#endif
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveCPUClockSpeed()
+{
+ bool retrieved = false;
+
+#if defined(_WIN32)
+ unsigned int uiRepetitions = 1;
+ unsigned int uiMSecPerRepetition = 50;
+ __int64 i64Total = 0;
+ __int64 i64Overhead = 0;
+
+ // Check if the TSC implementation works at all
+ if (this->Features.HasTSC &&
+ GetCyclesDifference(SystemInformationImplementation::Delay,
+ uiMSecPerRepetition) > 0)
+ {
+ for (unsigned int nCounter = 0; nCounter < uiRepetitions; nCounter ++)
+ {
+ i64Total += GetCyclesDifference (SystemInformationImplementation::Delay,
+ uiMSecPerRepetition);
+ i64Overhead +=
+ GetCyclesDifference (SystemInformationImplementation::DelayOverhead,
+ uiMSecPerRepetition);
+ }
+
+ // Calculate the MHz speed.
+ i64Total -= i64Overhead;
+ i64Total /= uiRepetitions;
+ i64Total /= uiMSecPerRepetition;
+ i64Total /= 1000;
+
+ // Save the CPU speed.
+ this->CPUSpeedInMHz = (float) i64Total;
+
+ retrieved = true;
+ }
+
+ // If RDTSC is not supported, we fallback to trying to read this value
+ // from the registry:
+ if (!retrieved)
+ {
+ HKEY hKey = NULL;
+ LONG err = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+ L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0,
+ KEY_READ, &hKey);
+
+ if (ERROR_SUCCESS == err)
+ {
+ DWORD dwType = 0;
+ DWORD data = 0;
+ DWORD dwSize = sizeof(DWORD);
+
+ err = RegQueryValueExW(hKey, L"~MHz", 0,
+ &dwType, (LPBYTE) &data, &dwSize);
+
+ if (ERROR_SUCCESS == err)
+ {
+ this->CPUSpeedInMHz = (float) data;
+ retrieved = true;
+ }
+
+ RegCloseKey(hKey);
+ hKey = NULL;
+ }
+ }
+#endif
+
+ return retrieved;
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveClassicalCPUClockSpeed()
+{
+#if USE_ASM_INSTRUCTIONS
+ LARGE_INTEGER liStart, liEnd, liCountsPerSecond;
+ double dFrequency, dDifference;
+
+ // Attempt to get a starting tick count.
+ QueryPerformanceCounter (&liStart);
+
+ __try
+ {
+ _asm
+ {
+ mov eax, 0x80000000
+ mov ebx, CLASSICAL_CPU_FREQ_LOOP
+ Timer_Loop:
+ bsf ecx,eax
+ dec ebx
+ jnz Timer_Loop
+ }
+ }
+ __except(1)
+ {
+ return false;
+ }
+
+ // Attempt to get a starting tick count.
+ QueryPerformanceCounter (&liEnd);
+
+ // Get the difference... NB: This is in seconds....
+ QueryPerformanceFrequency (&liCountsPerSecond);
+ dDifference = (((double) liEnd.QuadPart - (double) liStart.QuadPart) / (double) liCountsPerSecond.QuadPart);
+
+ // Calculate the clock speed.
+ if (this->ChipID.Family == 3)
+ {
+ // 80386 processors.... Loop time is 115 cycles!
+ dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 115) / dDifference) / 1000000);
+ }
+ else if (this->ChipID.Family == 4)
+ {
+ // 80486 processors.... Loop time is 47 cycles!
+ dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 47) / dDifference) / 1000000);
+ }
+ else if (this->ChipID.Family == 5)
+ {
+ // Pentium processors.... Loop time is 43 cycles!
+ dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 43) / dDifference) / 1000000);
+ }
+
+ // Save the clock speed.
+ this->Features.CPUSpeed = (int) dFrequency;
+
+ return true;
+
+#else
+ return false;
+#endif
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveCPUExtendedLevelSupport(int CPULevelToCheck)
+{
+ int cpuinfo[4] = { 0, 0, 0, 0 };
+
+ // The extended CPUID is supported by various vendors starting with the following CPU models:
+ //
+ // Manufacturer & Chip Name | Family Model Revision
+ //
+ // AMD K6, K6-2 | 5 6 x
+ // Cyrix GXm, Cyrix III "Joshua" | 5 4 x
+ // IDT C6-2 | 5 8 x
+ // VIA Cyrix III | 6 5 x
+ // Transmeta Crusoe | 5 x x
+ // Intel Pentium 4 | f x x
+ //
+
+ // We check to see if a supported processor is present...
+ if (this->ChipManufacturer == AMD)
+ {
+ if (this->ChipID.Family < 5) return false;
+ if ((this->ChipID.Family == 5) && (this->ChipID.Model < 6)) return false;
+ }
+ else if (this->ChipManufacturer == Cyrix)
+ {
+ if (this->ChipID.Family < 5) return false;
+ if ((this->ChipID.Family == 5) && (this->ChipID.Model < 4)) return false;
+ if ((this->ChipID.Family == 6) && (this->ChipID.Model < 5)) return false;
+ }
+ else if (this->ChipManufacturer == IDT)
+ {
+ if (this->ChipID.Family < 5) return false;
+ if ((this->ChipID.Family == 5) && (this->ChipID.Model < 8)) return false;
+ }
+ else if (this->ChipManufacturer == Transmeta)
+ {
+ if (this->ChipID.Family < 5) return false;
+ }
+ else if (this->ChipManufacturer == Intel)
+ {
+ if (this->ChipID.Family < 0xf)
+ {
+ return false;
+ }
+ }
+
+#if USE_CPUID
+ if (!call_cpuid(0x80000000, cpuinfo))
+ {
+ return false;
+ }
+#endif
+
+ // Now we have to check the level wanted vs level returned...
+ int nLevelWanted = (CPULevelToCheck & 0x7FFFFFFF);
+ int nLevelReturn = (cpuinfo[0] & 0x7FFFFFFF);
+
+ // Check to see if the level provided is supported...
+ if (nLevelWanted > nLevelReturn)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveExtendedCPUFeatures()
+{
+
+ // Check that we are not using an Intel processor as it does not support this.
+ if (this->ChipManufacturer == Intel)
+ {
+ return false;
+ }
+
+ // Check to see if what we are about to do is supported...
+ if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000001)))
+ {
+ return false;
+ }
+
+#if USE_CPUID
+ int localCPUExtendedFeatures[4] = { 0, 0, 0, 0 };
+
+ if (!call_cpuid(0x80000001, localCPUExtendedFeatures))
+ {
+ return false;
+ }
+
+ // Retrieve the extended features of CPU present.
+ this->Features.ExtendedFeatures.Has3DNow = ((localCPUExtendedFeatures[3] & 0x80000000) != 0); // 3DNow Present --> Bit 31.
+ this->Features.ExtendedFeatures.Has3DNowPlus = ((localCPUExtendedFeatures[3] & 0x40000000) != 0); // 3DNow+ Present -- > Bit 30.
+ this->Features.ExtendedFeatures.HasSSEMMX = ((localCPUExtendedFeatures[3] & 0x00400000) != 0); // SSE MMX Present --> Bit 22.
+ this->Features.ExtendedFeatures.SupportsMP = ((localCPUExtendedFeatures[3] & 0x00080000) != 0); // MP Capable -- > Bit 19.
+
+ // Retrieve AMD specific extended features.
+ if (this->ChipManufacturer == AMD)
+ {
+ this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures[3] & 0x00400000) != 0); // AMD specific: MMX-SSE --> Bit 22
+ }
+
+ // Retrieve Cyrix specific extended features.
+ if (this->ChipManufacturer == Cyrix)
+ {
+ this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures[3] & 0x01000000) != 0); // Cyrix specific: Extended MMX --> Bit 24
+ }
+
+ return true;
+
+#else
+ return false;
+#endif
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveProcessorSerialNumber()
+{
+ // Check to see if the processor supports the processor serial number.
+ if (!this->Features.HasSerial)
+ {
+ return false;
+ }
+
+#if USE_CPUID
+ int SerialNumber[4];
+
+ if (!call_cpuid(3, SerialNumber))
+ {
+ return false;
+ }
+
+ // Process the returned information.
+ // ; eax = 3 --> ebx: top 32 bits are the processor signature bits --> NB: Transmeta only ?!?
+ // ; ecx: middle 32 bits are the processor signature bits
+ // ; edx: bottom 32 bits are the processor signature bits
+ char sn[128];
+ sprintf (sn, "%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x",
+ ((SerialNumber[1] & 0xff000000) >> 24),
+ ((SerialNumber[1] & 0x00ff0000) >> 16),
+ ((SerialNumber[1] & 0x0000ff00) >> 8),
+ ((SerialNumber[1] & 0x000000ff) >> 0),
+ ((SerialNumber[2] & 0xff000000) >> 24),
+ ((SerialNumber[2] & 0x00ff0000) >> 16),
+ ((SerialNumber[2] & 0x0000ff00) >> 8),
+ ((SerialNumber[2] & 0x000000ff) >> 0),
+ ((SerialNumber[3] & 0xff000000) >> 24),
+ ((SerialNumber[3] & 0x00ff0000) >> 16),
+ ((SerialNumber[3] & 0x0000ff00) >> 8),
+ ((SerialNumber[3] & 0x000000ff) >> 0));
+ this->ChipID.SerialNumber = sn;
+ return true;
+
+#else
+ return false;
+#endif
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveCPUPowerManagement()
+{
+ // Check to see if what we are about to do is supported...
+ if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000007)))
+ {
+ this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID = false;
+ this->Features.ExtendedFeatures.PowerManagement.HasVoltageID = false;
+ this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode = false;
+ return false;
+ }
+
+#if USE_CPUID
+ int localCPUPowerManagement[4] = { 0, 0, 0, 0 };
+
+ if (!call_cpuid(0x80000007, localCPUPowerManagement))
+ {
+ return false;
+ }
+
+ // Check for the power management capabilities of the CPU.
+ this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode = ((localCPUPowerManagement[3] & 0x00000001) != 0);
+ this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID = ((localCPUPowerManagement[3] & 0x00000002) != 0);
+ this->Features.ExtendedFeatures.PowerManagement.HasVoltageID = ((localCPUPowerManagement[3] & 0x00000004) != 0);
+
+ return true;
+
+#else
+ return false;
+#endif
+}
+
+#if USE_CPUID
+// Used only in USE_CPUID implementation below.
+static void SystemInformationStripLeadingSpace(kwsys_stl::string& str)
+{
+ // Because some manufacturers have leading white space - we have to post-process the name.
+ kwsys_stl::string::size_type pos = str.find_first_not_of(" ");
+ if(pos != kwsys_stl::string::npos)
+ {
+ str = str.substr(pos);
+ }
+}
+#endif
+
+/** */
+bool SystemInformationImplementation::RetrieveExtendedCPUIdentity()
+{
+ // Check to see if what we are about to do is supported...
+ if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000002)))
+ return false;
+ if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000003)))
+ return false;
+ if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000004)))
+ return false;
+
+#if USE_CPUID
+ int CPUExtendedIdentity[12];
+
+ if (!call_cpuid(0x80000002, CPUExtendedIdentity))
+ {
+ return false;
+ }
+ if (!call_cpuid(0x80000003, CPUExtendedIdentity + 4))
+ {
+ return false;
+ }
+ if (!call_cpuid(0x80000004, CPUExtendedIdentity + 8))
+ {
+ return false;
+ }
+
+ // Process the returned information.
+ char nbuf[49];
+ memcpy (&(nbuf[0]), &(CPUExtendedIdentity[0]), sizeof (int));
+ memcpy (&(nbuf[4]), &(CPUExtendedIdentity[1]), sizeof (int));
+ memcpy (&(nbuf[8]), &(CPUExtendedIdentity[2]), sizeof (int));
+ memcpy (&(nbuf[12]), &(CPUExtendedIdentity[3]), sizeof (int));
+ memcpy (&(nbuf[16]), &(CPUExtendedIdentity[4]), sizeof (int));
+ memcpy (&(nbuf[20]), &(CPUExtendedIdentity[5]), sizeof (int));
+ memcpy (&(nbuf[24]), &(CPUExtendedIdentity[6]), sizeof (int));
+ memcpy (&(nbuf[28]), &(CPUExtendedIdentity[7]), sizeof (int));
+ memcpy (&(nbuf[32]), &(CPUExtendedIdentity[8]), sizeof (int));
+ memcpy (&(nbuf[36]), &(CPUExtendedIdentity[9]), sizeof (int));
+ memcpy (&(nbuf[40]), &(CPUExtendedIdentity[10]), sizeof (int));
+ memcpy (&(nbuf[44]), &(CPUExtendedIdentity[11]), sizeof (int));
+ nbuf[48] = '\0';
+ this->ChipID.ProcessorName = nbuf;
+ this->ChipID.ModelName = nbuf;
+
+ // Because some manufacturers have leading white space - we have to post-process the name.
+ SystemInformationStripLeadingSpace(this->ChipID.ProcessorName);
+ return true;
+#else
+ return false;
+#endif
+}
+
+
+/** */
+bool SystemInformationImplementation::RetrieveClassicalCPUIdentity()
+{
+ // Start by decided which manufacturer we are using....
+ switch (this->ChipManufacturer)
+ {
+ case Intel:
+ // Check the family / model / revision to determine the CPU ID.
+ switch (this->ChipID.Family) {
+ case 3:
+ this->ChipID.ProcessorName = "Newer i80386 family";
+ break;
+ case 4:
+ switch (this->ChipID.Model) {
+ case 0: this->ChipID.ProcessorName = "i80486DX-25/33"; break;
+ case 1: this->ChipID.ProcessorName = "i80486DX-50"; break;
+ case 2: this->ChipID.ProcessorName = "i80486SX"; break;
+ case 3: this->ChipID.ProcessorName = "i80486DX2"; break;
+ case 4: this->ChipID.ProcessorName = "i80486SL"; break;
+ case 5: this->ChipID.ProcessorName = "i80486SX2"; break;
+ case 7: this->ChipID.ProcessorName = "i80486DX2 WriteBack"; break;
+ case 8: this->ChipID.ProcessorName = "i80486DX4"; break;
+ case 9: this->ChipID.ProcessorName = "i80486DX4 WriteBack"; break;
+ default: this->ChipID.ProcessorName = "Unknown 80486 family"; return false;
+ }
+ break;
+ case 5:
+ switch (this->ChipID.Model)
+ {
+ case 0: this->ChipID.ProcessorName = "P5 A-Step"; break;
+ case 1: this->ChipID.ProcessorName = "P5"; break;
+ case 2: this->ChipID.ProcessorName = "P54C"; break;
+ case 3: this->ChipID.ProcessorName = "P24T OverDrive"; break;
+ case 4: this->ChipID.ProcessorName = "P55C"; break;
+ case 7: this->ChipID.ProcessorName = "P54C"; break;
+ case 8: this->ChipID.ProcessorName = "P55C (0.25micron)"; break;
+ default: this->ChipID.ProcessorName = "Unknown Pentium family"; return false;
+ }
+ break;
+ case 6:
+ switch (this->ChipID.Model)
+ {
+ case 0: this->ChipID.ProcessorName = "P6 A-Step"; break;
+ case 1: this->ChipID.ProcessorName = "P6"; break;
+ case 3: this->ChipID.ProcessorName = "Pentium II (0.28 micron)"; break;
+ case 5: this->ChipID.ProcessorName = "Pentium II (0.25 micron)"; break;
+ case 6: this->ChipID.ProcessorName = "Pentium II With On-Die L2 Cache"; break;
+ case 7: this->ChipID.ProcessorName = "Pentium III (0.25 micron)"; break;
+ case 8: this->ChipID.ProcessorName = "Pentium III (0.18 micron) With 256 KB On-Die L2 Cache "; break;
+ case 0xa: this->ChipID.ProcessorName = "Pentium III (0.18 micron) With 1 Or 2 MB On-Die L2 Cache "; break;
+ case 0xb: this->ChipID.ProcessorName = "Pentium III (0.13 micron) With 256 Or 512 KB On-Die L2 Cache "; break;
+ case 23: this->ChipID.ProcessorName = "Intel(R) Core(TM)2 Duo CPU T9500 @ 2.60GHz"; break;
+ default: this->ChipID.ProcessorName = "Unknown P6 family"; return false;
+ }
+ break;
+ case 7:
+ this->ChipID.ProcessorName = "Intel Merced (IA-64)";
+ break;
+ case 0xf:
+ // Check the extended family bits...
+ switch (this->ChipID.ExtendedFamily)
+ {
+ case 0:
+ switch (this->ChipID.Model)
+ {
+ case 0: this->ChipID.ProcessorName = "Pentium IV (0.18 micron)"; break;
+ case 1: this->ChipID.ProcessorName = "Pentium IV (0.18 micron)"; break;
+ case 2: this->ChipID.ProcessorName = "Pentium IV (0.13 micron)"; break;
+ default: this->ChipID.ProcessorName = "Unknown Pentium 4 family"; return false;
+ }
+ break;
+ case 1:
+ this->ChipID.ProcessorName = "Intel McKinley (IA-64)";
+ break;
+ default:
+ this->ChipID.ProcessorName = "Pentium";
+ }
+ break;
+ default:
+ this->ChipID.ProcessorName = "Unknown Intel family";
+ return false;
+ }
+ break;
+
+ case AMD:
+ // Check the family / model / revision to determine the CPU ID.
+ switch (this->ChipID.Family)
+ {
+ case 4:
+ switch (this->ChipID.Model)
+ {
+ case 3: this->ChipID.ProcessorName = "80486DX2"; break;
+ case 7: this->ChipID.ProcessorName = "80486DX2 WriteBack"; break;
+ case 8: this->ChipID.ProcessorName = "80486DX4"; break;
+ case 9: this->ChipID.ProcessorName = "80486DX4 WriteBack"; break;
+ case 0xe: this->ChipID.ProcessorName = "5x86"; break;
+ case 0xf: this->ChipID.ProcessorName = "5x86WB"; break;
+ default: this->ChipID.ProcessorName = "Unknown 80486 family"; return false;
+ }
+ break;
+ case 5:
+ switch (this->ChipID.Model)
+ {
+ case 0: this->ChipID.ProcessorName = "SSA5 (PR75, PR90 = PR100)"; break;
+ case 1: this->ChipID.ProcessorName = "5k86 (PR120 = PR133)"; break;
+ case 2: this->ChipID.ProcessorName = "5k86 (PR166)"; break;
+ case 3: this->ChipID.ProcessorName = "5k86 (PR200)"; break;
+ case 6: this->ChipID.ProcessorName = "K6 (0.30 micron)"; break;
+ case 7: this->ChipID.ProcessorName = "K6 (0.25 micron)"; break;
+ case 8: this->ChipID.ProcessorName = "K6-2"; break;
+ case 9: this->ChipID.ProcessorName = "K6-III"; break;
+ case 0xd: this->ChipID.ProcessorName = "K6-2+ or K6-III+ (0.18 micron)"; break;
+ default: this->ChipID.ProcessorName = "Unknown 80586 family"; return false;
+ }
+ break;
+ case 6:
+ switch (this->ChipID.Model)
+ {
+ case 1: this->ChipID.ProcessorName = "Athlon- (0.25 micron)"; break;
+ case 2: this->ChipID.ProcessorName = "Athlon- (0.18 micron)"; break;
+ case 3: this->ChipID.ProcessorName = "Duron- (SF core)"; break;
+ case 4: this->ChipID.ProcessorName = "Athlon- (Thunderbird core)"; break;
+ case 6: this->ChipID.ProcessorName = "Athlon- (Palomino core)"; break;
+ case 7: this->ChipID.ProcessorName = "Duron- (Morgan core)"; break;
+ case 8:
+ if (this->Features.ExtendedFeatures.SupportsMP)
+ this->ChipID.ProcessorName = "Athlon - MP (Thoroughbred core)";
+ else this->ChipID.ProcessorName = "Athlon - XP (Thoroughbred core)";
+ break;
+ default: this->ChipID.ProcessorName = "Unknown K7 family"; return false;
+ }
+ break;
+ default:
+ this->ChipID.ProcessorName = "Unknown AMD family";
+ return false;
+ }
+ break;
+
+ case Transmeta:
+ switch (this->ChipID.Family)
+ {
+ case 5:
+ switch (this->ChipID.Model)
+ {
+ case 4: this->ChipID.ProcessorName = "Crusoe TM3x00 and TM5x00"; break;
+ default: this->ChipID.ProcessorName = "Unknown Crusoe family"; return false;
+ }
+ break;
+ default:
+ this->ChipID.ProcessorName = "Unknown Transmeta family";
+ return false;
+ }
+ break;
+
+ case Rise:
+ switch (this->ChipID.Family)
+ {
+ case 5:
+ switch (this->ChipID.Model)
+ {
+ case 0: this->ChipID.ProcessorName = "mP6 (0.25 micron)"; break;
+ case 2: this->ChipID.ProcessorName = "mP6 (0.18 micron)"; break;
+ default: this->ChipID.ProcessorName = "Unknown Rise family"; return false;
+ }
+ break;
+ default:
+ this->ChipID.ProcessorName = "Unknown Rise family";
+ return false;
+ }
+ break;
+
+ case UMC:
+ switch (this->ChipID.Family)
+ {
+ case 4:
+ switch (this->ChipID.Model)
+ {
+ case 1: this->ChipID.ProcessorName = "U5D"; break;
+ case 2: this->ChipID.ProcessorName = "U5S"; break;
+ default: this->ChipID.ProcessorName = "Unknown UMC family"; return false;
+ }
+ break;
+ default:
+ this->ChipID.ProcessorName = "Unknown UMC family";
+ return false;
+ }
+ break;
+
+ case IDT:
+ switch (this->ChipID.Family)
+ {
+ case 5:
+ switch (this->ChipID.Model)
+ {
+ case 4: this->ChipID.ProcessorName = "C6"; break;
+ case 8: this->ChipID.ProcessorName = "C2"; break;
+ case 9: this->ChipID.ProcessorName = "C3"; break;
+ default: this->ChipID.ProcessorName = "Unknown IDT\\Centaur family"; return false;
+ }
+ break;
+ case 6:
+ switch (this->ChipID.Model)
+ {
+ case 6: this->ChipID.ProcessorName = "VIA Cyrix III - Samuel"; break;
+ default: this->ChipID.ProcessorName = "Unknown IDT\\Centaur family"; return false;
+ }
+ break;
+ default:
+ this->ChipID.ProcessorName = "Unknown IDT\\Centaur family";
+ return false;
+ }
+ break;
+
+ case Cyrix:
+ switch (this->ChipID.Family)
+ {
+ case 4:
+ switch (this->ChipID.Model)
+ {
+ case 4: this->ChipID.ProcessorName = "MediaGX GX = GXm"; break;
+ case 9: this->ChipID.ProcessorName = "5x86"; break;
+ default: this->ChipID.ProcessorName = "Unknown Cx5x86 family"; return false;
+ }
+ break;
+ case 5:
+ switch (this->ChipID.Model)
+ {
+ case 2: this->ChipID.ProcessorName = "Cx6x86"; break;
+ case 4: this->ChipID.ProcessorName = "MediaGX GXm"; break;
+ default: this->ChipID.ProcessorName = "Unknown Cx6x86 family"; return false;
+ }
+ break;
+ case 6:
+ switch (this->ChipID.Model)
+ {
+ case 0: this->ChipID.ProcessorName = "6x86MX"; break;
+ case 5: this->ChipID.ProcessorName = "Cyrix M2 Core"; break;
+ case 6: this->ChipID.ProcessorName = "WinChip C5A Core"; break;
+ case 7: this->ChipID.ProcessorName = "WinChip C5B\\C5C Core"; break;
+ case 8: this->ChipID.ProcessorName = "WinChip C5C-T Core"; break;
+ default: this->ChipID.ProcessorName = "Unknown 6x86MX\\Cyrix III family"; return false;
+ }
+ break;
+ default:
+ this->ChipID.ProcessorName = "Unknown Cyrix family";
+ return false;
+ }
+ break;
+
+ case NexGen:
+ switch (this->ChipID.Family)
+ {
+ case 5:
+ switch (this->ChipID.Model)
+ {
+ case 0: this->ChipID.ProcessorName = "Nx586 or Nx586FPU"; break;
+ default: this->ChipID.ProcessorName = "Unknown NexGen family"; return false;
+ }
+ break;
+ default:
+ this->ChipID.ProcessorName = "Unknown NexGen family";
+ return false;
+ }
+ break;
+
+ case NSC:
+ this->ChipID.ProcessorName = "Cx486SLC \\ DLC \\ Cx486S A-Step";
+ break;
+ default:
+ this->ChipID.ProcessorName = "Unknown family"; // We cannot identify the processor.
+ return false;
+ }
+
+ return true;
+}
+
+
+/** Extract a value from the CPUInfo file */
+kwsys_stl::string SystemInformationImplementation::ExtractValueFromCpuInfoFile(kwsys_stl::string buffer,const char* word,size_t init)
+{
+ size_t pos = buffer.find(word,init);
+ if(pos != buffer.npos)
+ {
+ this->CurrentPositionInFile = pos;
+ pos = buffer.find(":",pos);
+ size_t pos2 = buffer.find("\n",pos);
+ if(pos!=buffer.npos && pos2!=buffer.npos)
+ {
+ // It may happen that the beginning matches, but this is still not the requested key.
+ // An example is looking for "cpu" when "cpu family" comes first. So we check that
+ // we have only spaces from here to pos, otherwise we search again.
+ for(size_t i=this->CurrentPositionInFile+strlen(word); i < pos; ++i)
+ {
+ if(buffer[i] != ' ' && buffer[i] != '\t')
+ {
+ return this->ExtractValueFromCpuInfoFile(buffer, word, pos2);
+ }
+ }
+ return buffer.substr(pos+2,pos2-pos-2);
+ }
+ }
+ this->CurrentPositionInFile = buffer.npos;
+ return "";
+}
+
+/** Query for the cpu status */
+bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
+{
+ this->NumberOfLogicalCPU = 0;
+ this->NumberOfPhysicalCPU = 0;
+ kwsys_stl::string buffer;
+
+ FILE *fd = fopen("/proc/cpuinfo", "r" );
+ if ( !fd )
+ {
+ kwsys_ios::cout << "Problem opening /proc/cpuinfo" << kwsys_ios::endl;
+ return false;
+ }
+
+ size_t fileSize = 0;
+ while(!feof(fd))
+ {
+ buffer += static_cast<char>(fgetc(fd));
+ fileSize++;
+ }
+ fclose( fd );
+ buffer.resize(fileSize-2);
+ // Number of logical CPUs (combination of multiple processors, multi-core
+ // and hyperthreading)
+ size_t pos = buffer.find("processor\t");
+ while(pos != buffer.npos)
+ {
+ this->NumberOfLogicalCPU++;
+ pos = buffer.find("processor\t",pos+1);
+ }
+
+#ifdef __linux
+ // Find the largest physical id.
+ int maxId = -1;
+ kwsys_stl::string idc =
+ this->ExtractValueFromCpuInfoFile(buffer,"physical id");
+ while(this->CurrentPositionInFile != buffer.npos)
+ {
+ int id = atoi(idc.c_str());
+ if(id > maxId)
+ {
+ maxId=id;
+ }
+ idc = this->ExtractValueFromCpuInfoFile(buffer,"physical id",
+ this->CurrentPositionInFile+1);
+ }
+ // Physical ids returned by Linux don't distinguish cores.
+ // We want to record the total number of cores in this->NumberOfPhysicalCPU
+ // (checking only the first proc)
+ kwsys_stl::string cores =
+ this->ExtractValueFromCpuInfoFile(buffer,"cpu cores");
+ int numberOfCoresPerCPU=atoi(cores.c_str());
+ if (maxId > 0)
+ {
+ this->NumberOfPhysicalCPU=static_cast<unsigned int>(
+ numberOfCoresPerCPU*(maxId+1));
+ }
+ else
+ {
+ // Linux Sparc: get cpu count
+ this->NumberOfPhysicalCPU=
+ atoi(this->ExtractValueFromCpuInfoFile(buffer,"ncpus active").c_str());
+ }
+
+#else // __CYGWIN__
+ // does not have "physical id" entries, neither "cpu cores"
+ // this has to be fixed for hyper-threading.
+ kwsys_stl::string cpucount =
+ this->ExtractValueFromCpuInfoFile(buffer,"cpu count");
+ this->NumberOfPhysicalCPU=
+ this->NumberOfLogicalCPU = atoi(cpucount.c_str());
+#endif
+ // gotta have one, and if this is 0 then we get a / by 0n
+ // better to have a bad answer than a crash
+ if(this->NumberOfPhysicalCPU <= 0)
+ {
+ this->NumberOfPhysicalCPU = 1;
+ }
+ // LogicalProcessorsPerPhysical>1 => hyperthreading.
+ this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical=
+ this->NumberOfLogicalCPU/this->NumberOfPhysicalCPU;
+
+ // CPU speed (checking only the first processor)
+ kwsys_stl::string CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"cpu MHz");
+ if(!CPUSpeed.empty())
+ {
+ this->CPUSpeedInMHz = static_cast<float>(atof(CPUSpeed.c_str()));
+ }
+#ifdef __linux
+ else
+ {
+ // Linux Sparc: CPU speed is in Hz and encoded in hexadecimal
+ CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"Cpu0ClkTck");
+ this->CPUSpeedInMHz = static_cast<float>(
+ strtoull(CPUSpeed.c_str(),0,16))/1000000.0f;
+ }
+#endif
+
+ // Chip family
+ kwsys_stl::string familyStr =
+ this->ExtractValueFromCpuInfoFile(buffer,"cpu family");
+ if(familyStr.empty())
+ {
+ familyStr = this->ExtractValueFromCpuInfoFile(buffer,"CPU architecture");
+ }
+ this->ChipID.Family = atoi(familyStr.c_str());
+
+ // Chip Vendor
+ this->ChipID.Vendor = this->ExtractValueFromCpuInfoFile(buffer,"vendor_id");
+ this->FindManufacturer(familyStr);
+
+ // second try for setting family
+ if (this->ChipID.Family == 0 && this->ChipManufacturer == HP)
+ {
+ if (familyStr == "PA-RISC 1.1a")
+ this->ChipID.Family = 0x11a;
+ else if (familyStr == "PA-RISC 2.0")
+ this->ChipID.Family = 0x200;
+ // If you really get CMake to work on a machine not belonging to
+ // any of those families I owe you a dinner if you get it to
+ // contribute nightly builds regularly.
+ }
+
+ // Chip Model
+ this->ChipID.Model = atoi(this->ExtractValueFromCpuInfoFile(buffer,"model").c_str());
+ if(!this->RetrieveClassicalCPUIdentity())
+ {
+ // Some platforms (e.g. PA-RISC) tell us their CPU name here.
+ // Note: x86 does not.
+ kwsys_stl::string cpuname = this->ExtractValueFromCpuInfoFile(buffer,"cpu");
+ if(!cpuname.empty())
+ {
+ this->ChipID.ProcessorName = cpuname;
+ }
+ }
+
+ // Chip revision
+ kwsys_stl::string cpurev = this->ExtractValueFromCpuInfoFile(buffer,"stepping");
+ if(cpurev.empty())
+ {
+ cpurev = this->ExtractValueFromCpuInfoFile(buffer,"CPU revision");
+ }
+ this->ChipID.Revision = atoi(cpurev.c_str());
+
+ // Chip Model Name
+ this->ChipID.ModelName = this->ExtractValueFromCpuInfoFile(buffer,"model name").c_str();
+
+ // L1 Cache size
+ // Different architectures may show different names for the caches.
+ // Sum up everything we find.
+ kwsys_stl::vector<const char*> cachename;
+ cachename.clear();
+
+ cachename.push_back("cache size"); // e.g. x86
+ cachename.push_back("I-cache"); // e.g. PA-RISC
+ cachename.push_back("D-cache"); // e.g. PA-RISC
+
+ this->Features.L1CacheSize = 0;
+ for (size_t index = 0; index < cachename.size(); index ++)
+ {
+ kwsys_stl::string cacheSize = this->ExtractValueFromCpuInfoFile(buffer,cachename[index]);
+ if (!cacheSize.empty())
+ {
+ pos = cacheSize.find(" KB");
+ if(pos!=cacheSize.npos)
+ {
+ cacheSize = cacheSize.substr(0,pos);
+ }
+ this->Features.L1CacheSize += atoi(cacheSize.c_str());
+ }
+ }
+
+ // processor feature flags (probably x86 specific)
+ kwsys_stl::string cpuflags = this->ExtractValueFromCpuInfoFile(buffer,"flags");
+ if(!cpurev.empty())
+ {
+ // now we can match every flags as space + flag + space
+ cpuflags = " " + cpuflags + " ";
+ if ((cpuflags.find(" fpu ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasFPU = true;
+ }
+ if ((cpuflags.find(" tsc ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasTSC = true;
+ }
+ if ((cpuflags.find(" mmx ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasMMX = true;
+ }
+ if ((cpuflags.find(" sse ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasSSE = true;
+ }
+ if ((cpuflags.find(" sse2 ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasSSE2 = true;
+ }
+ if ((cpuflags.find(" apic ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasAPIC = true;
+ }
+ if ((cpuflags.find(" cmov ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasCMOV = true;
+ }
+ if ((cpuflags.find(" mtrr ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasMTRR = true;
+ }
+ if ((cpuflags.find(" acpi ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasACPI = true;
+ }
+ if ((cpuflags.find(" 3dnow ")!=kwsys_stl::string::npos))
+ {
+ this->Features.ExtendedFeatures.Has3DNow = true;
+ }
+ }
+
+ return true;
+}
+
+bool SystemInformationImplementation::QueryProcessorBySysconf()
+{
+#if defined(_SC_NPROC_ONLN) && !defined(_SC_NPROCESSORS_ONLN)
+// IRIX names this slightly different
+# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
+#endif
+
+#ifdef _SC_NPROCESSORS_ONLN
+ long c = sysconf(_SC_NPROCESSORS_ONLN);
+ if (c <= 0)
+ {
+ return false;
+ }
+
+ this->NumberOfPhysicalCPU = static_cast<unsigned int>(c);
+ this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryProcessor()
+{
+ return this->QueryProcessorBySysconf();
+}
+
+/**
+Get total system RAM in units of KiB.
+*/
+SystemInformation::LongLong
+SystemInformationImplementation::GetHostMemoryTotal()
+{
+#if defined(_WIN32)
+# if defined(_MSC_VER) && _MSC_VER < 1300
+ MEMORYSTATUS stat;
+ stat.dwLength = sizeof(stat);
+ GlobalMemoryStatus(&stat);
+ return stat.dwTotalPhys/1024;
+# else
+ MEMORYSTATUSEX statex;
+ statex.dwLength=sizeof(statex);
+ GlobalMemoryStatusEx(&statex);
+ return statex.ullTotalPhys/1024;
+# endif
+#elif defined(__linux)
+ SystemInformation::LongLong memTotal=0;
+ int ierr=GetFieldFromFile("/proc/meminfo","MemTotal:",memTotal);
+ if (ierr)
+ {
+ return -1;
+ }
+ return memTotal;
+#elif defined(__APPLE__)
+ uint64_t mem;
+ size_t len = sizeof(mem);
+ int ierr=sysctlbyname("hw.memsize", &mem, &len, NULL, 0);
+ if (ierr)
+ {
+ return -1;
+ }
+ return mem/1024;
+#else
+ return 0;
+#endif
+}
+
+/**
+Get total system RAM in units of KiB. This may differ from the
+host total if a host-wide resource limit is applied.
+*/
+SystemInformation::LongLong
+SystemInformationImplementation::GetHostMemoryAvailable(const char *hostLimitEnvVarName)
+{
+ SystemInformation::LongLong memTotal=this->GetHostMemoryTotal();
+
+ // the following mechanism is provided for systems that
+ // apply resource limits across groups of processes.
+ // this is of use on certain SMP systems (eg. SGI UV)
+ // where the host has a large amount of ram but a given user's
+ // access to it is severly restricted. The system will
+ // apply a limit across a set of processes. Units are in KiB.
+ if (hostLimitEnvVarName)
+ {
+ const char *hostLimitEnvVarValue=getenv(hostLimitEnvVarName);
+ if (hostLimitEnvVarValue)
+ {
+ SystemInformation::LongLong hostLimit=atoLongLong(hostLimitEnvVarValue);
+ if (hostLimit>0)
+ {
+ memTotal=min(hostLimit,memTotal);
+ }
+ }
+ }
+
+ return memTotal;
+}
+
+/**
+Get total system RAM in units of KiB. This may differ from the
+host total if a per-process resource limit is applied.
+*/
+SystemInformation::LongLong
+SystemInformationImplementation::GetProcMemoryAvailable(
+ const char *hostLimitEnvVarName,
+ const char *procLimitEnvVarName)
+{
+ SystemInformation::LongLong memAvail
+ = this->GetHostMemoryAvailable(hostLimitEnvVarName);
+
+ // the following mechanism is provide for systems where rlimits
+ // are not employed. Units are in KiB.
+ if (procLimitEnvVarName)
+ {
+ const char *procLimitEnvVarValue=getenv(procLimitEnvVarName);
+ if (procLimitEnvVarValue)
+ {
+ SystemInformation::LongLong procLimit=atoLongLong(procLimitEnvVarValue);
+ if (procLimit>0)
+ {
+ memAvail=min(procLimit,memAvail);
+ }
+ }
+ }
+
+#if defined(__linux)
+ int ierr;
+ ResourceLimitType rlim;
+ ierr=GetResourceLimit(RLIMIT_DATA,&rlim);
+ if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY))
+ {
+ memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail);
+ }
+
+ ierr=GetResourceLimit(RLIMIT_AS,&rlim);
+ if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY))
+ {
+ memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail);
+ }
+#elif defined(__APPLE__)
+ struct rlimit rlim;
+ int ierr;
+ ierr=getrlimit(RLIMIT_DATA,&rlim);
+ if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY))
+ {
+ memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail);
+ }
+
+ ierr=getrlimit(RLIMIT_RSS,&rlim);
+ if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY))
+ {
+ memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail);
+ }
+#endif
+
+ return memAvail;
+}
+
+/**
+Get RAM used by all processes in the host, in units of KiB.
+*/
+SystemInformation::LongLong
+SystemInformationImplementation::GetHostMemoryUsed()
+{
+#if defined(_WIN32)
+# if defined(_MSC_VER) && _MSC_VER < 1300
+ MEMORYSTATUS stat;
+ stat.dwLength = sizeof(stat);
+ GlobalMemoryStatus(&stat);
+ return (stat.dwTotalPhys - stat.dwAvailPhys)/1024;
+# else
+ MEMORYSTATUSEX statex;
+ statex.dwLength=sizeof(statex);
+ GlobalMemoryStatusEx(&statex);
+ return (statex.ullTotalPhys - statex.ullAvailPhys)/1024;
+# endif
+#elif defined(__linux)
+ const char *names[3]={"MemTotal:","MemFree:",NULL};
+ SystemInformation::LongLong values[2]={SystemInformation::LongLong(0)};
+ int ierr=GetFieldsFromFile("/proc/meminfo",names,values);
+ if (ierr)
+ {
+ return ierr;
+ }
+ SystemInformation::LongLong &memTotal=values[0];
+ SystemInformation::LongLong &memFree=values[1];
+ return memTotal - memFree;
+#elif defined(__APPLE__)
+ SystemInformation::LongLong psz=getpagesize();
+ if (psz<1)
+ {
+ return -1;
+ }
+ const char *names[4]={"Pages active:","Pages inactive:","Pages wired down:",NULL};
+ SystemInformation::LongLong values[3]={SystemInformation::LongLong(0)};
+ int ierr=GetFieldsFromCommand("vm_stat", names, values);
+ if (ierr)
+ {
+ return -1;
+ }
+ SystemInformation::LongLong &vmActive=values[0];
+ SystemInformation::LongLong &vmInactive=values[1];
+ SystemInformation::LongLong &vmWired=values[2];
+ return ((vmActive+vmInactive+vmWired)*psz)/1024;
+#else
+ return 0;
+#endif
+}
+
+/**
+Get system RAM used by the process associated with the given
+process id in units of KiB.
+*/
+SystemInformation::LongLong
+SystemInformationImplementation::GetProcMemoryUsed()
+{
+#if defined(_WIN32) && defined(KWSYS_SYS_HAS_PSAPI)
+ long pid=GetCurrentProcessId();
+ HANDLE hProc;
+ hProc=OpenProcess(
+ PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,
+ false,
+ pid);
+ if (hProc==0)
+ {
+ return -1;
+ }
+ PROCESS_MEMORY_COUNTERS pmc;
+ int ok=GetProcessMemoryInfo(hProc,&pmc,sizeof(pmc));
+ CloseHandle(hProc);
+ if (!ok)
+ {
+ return -2;
+ }
+ return pmc.WorkingSetSize/1024;
+#elif defined(__linux)
+ SystemInformation::LongLong memUsed=0;
+ int ierr=GetFieldFromFile("/proc/self/status","VmRSS:",memUsed);
+ if (ierr)
+ {
+ return -1;
+ }
+ return memUsed;
+#elif defined(__APPLE__)
+ SystemInformation::LongLong memUsed=0;
+ pid_t pid=getpid();
+ kwsys_ios::ostringstream oss;
+ oss << "ps -o rss= -p " << pid;
+ FILE *file=popen(oss.str().c_str(),"r");
+ if (file==0)
+ {
+ return -1;
+ }
+ oss.str("");
+ while (!feof(file) && !ferror(file))
+ {
+ char buf[256]={'\0'};
+ errno=0;
+ size_t nRead=fread(buf,1,256,file);
+ if (ferror(file) && (errno==EINTR))
+ {
+ clearerr(file);
+ }
+ if (nRead) oss << buf;
+ }
+ int ierr=ferror(file);
+ pclose(file);
+ if (ierr)
+ {
+ return -2;
+ }
+ kwsys_ios::istringstream iss(oss.str());
+ iss >> memUsed;
+ return memUsed;
+#else
+ return 0;
+#endif
+}
+
+/**
+Get the process id of the running process.
+*/
+SystemInformation::LongLong
+SystemInformationImplementation::GetProcessId()
+{
+#if defined(_WIN32)
+ return GetCurrentProcessId();
+#elif defined(__linux) || defined(__APPLE__)
+ return getpid();
+#else
+ return -1;
+#endif
+}
+
+/**
+return current program stack in a string
+demangle cxx symbols if possible.
+*/
+kwsys_stl::string SystemInformationImplementation::GetProgramStack(
+ int firstFrame,
+ int wholePath)
+{
+ kwsys_stl::string programStack = ""
+#if !defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+ "WARNING: The stack could not be examined "
+ "because backtrace is not supported.\n"
+#elif !defined(KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD)
+ "WARNING: The stack trace will not use advanced "
+ "capabilities because this is a release build.\n"
+#else
+# if !defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+ "WARNING: Function names will not be demangled because "
+ "dladdr is not available.\n"
+# endif
+# if !defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
+ "WARNING: Function names will not be demangled "
+ "because cxxabi is not available.\n"
+# endif
+#endif
+ ;
+
+ kwsys_ios::ostringstream oss;
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+ void *stackSymbols[256];
+ int nFrames=backtrace(stackSymbols,256);
+ for (int i=firstFrame; i<nFrames; ++i)
+ {
+ SymbolProperties symProps;
+ symProps.SetReportPath(wholePath);
+ symProps.Initialize(stackSymbols[i]);
+ oss << symProps << kwsys_ios::endl;
+ }
+#else
+ (void)firstFrame;
+ (void)wholePath;
+#endif
+ programStack += oss.str();
+
+ return programStack;
+}
+
+
+/**
+when set print stack trace in response to common signals.
+*/
+void SystemInformationImplementation::SetStackTraceOnError(int enable)
+{
+#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
+ static int saOrigValid=0;
+ static struct sigaction saABRTOrig;
+ static struct sigaction saSEGVOrig;
+ static struct sigaction saTERMOrig;
+ static struct sigaction saINTOrig;
+ static struct sigaction saILLOrig;
+ static struct sigaction saBUSOrig;
+ static struct sigaction saFPEOrig;
+
+
+ if (enable && !saOrigValid)
+ {
+ // save the current actions
+ sigaction(SIGABRT,0,&saABRTOrig);
+ sigaction(SIGSEGV,0,&saSEGVOrig);
+ sigaction(SIGTERM,0,&saTERMOrig);
+ sigaction(SIGINT,0,&saINTOrig);
+ sigaction(SIGILL,0,&saILLOrig);
+ sigaction(SIGBUS,0,&saBUSOrig);
+ sigaction(SIGFPE,0,&saFPEOrig);
+
+ // enable read, disable write
+ saOrigValid=1;
+
+ // install ours
+ struct sigaction sa;
+ sa.sa_sigaction=(SigAction)StacktraceSignalHandler;
+ sa.sa_flags=SA_SIGINFO|SA_RESETHAND;
+# ifdef SA_RESTART
+ sa.sa_flags|=SA_RESTART;
+# endif
+ sigemptyset(&sa.sa_mask);
+
+ sigaction(SIGABRT,&sa,0);
+ sigaction(SIGSEGV,&sa,0);
+ sigaction(SIGTERM,&sa,0);
+ sigaction(SIGINT,&sa,0);
+ sigaction(SIGILL,&sa,0);
+ sigaction(SIGBUS,&sa,0);
+ sigaction(SIGFPE,&sa,0);
+ }
+ else
+ if (!enable && saOrigValid)
+ {
+ // restore previous actions
+ sigaction(SIGABRT,&saABRTOrig,0);
+ sigaction(SIGSEGV,&saSEGVOrig,0);
+ sigaction(SIGTERM,&saTERMOrig,0);
+ sigaction(SIGINT,&saINTOrig,0);
+ sigaction(SIGILL,&saILLOrig,0);
+ sigaction(SIGBUS,&saBUSOrig,0);
+ sigaction(SIGFPE,&saFPEOrig,0);
+
+ // enable write, disable read
+ saOrigValid=0;
+ }
+#else
+ // avoid warning C4100
+ (void)enable;
+#endif
+}
+
+bool SystemInformationImplementation::QueryWindowsMemory()
+{
+#if defined(_WIN32)
+# if defined(_MSC_VER) && _MSC_VER < 1300
+ MEMORYSTATUS ms;
+ unsigned long tv, tp, av, ap;
+ ms.dwLength = sizeof(ms);
+ GlobalMemoryStatus(&ms);
+# define MEM_VAL(value) dw##value
+# else
+ MEMORYSTATUSEX ms;
+ DWORDLONG tv, tp, av, ap;
+ ms.dwLength = sizeof(ms);
+ if (0 == GlobalMemoryStatusEx(&ms))
+ {
+ return 0;
+ }
+# define MEM_VAL(value) ull##value
+# endif
+ tv = ms.MEM_VAL(TotalVirtual);
+ tp = ms.MEM_VAL(TotalPhys);
+ av = ms.MEM_VAL(AvailVirtual);
+ ap = ms.MEM_VAL(AvailPhys);
+ this->TotalVirtualMemory = tv>>10>>10;
+ this->TotalPhysicalMemory = tp>>10>>10;
+ this->AvailableVirtualMemory = av>>10>>10;
+ this->AvailablePhysicalMemory = ap>>10>>10;
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryLinuxMemory()
+{
+#if defined(__linux)
+ unsigned long tv=0;
+ unsigned long tp=0;
+ unsigned long av=0;
+ unsigned long ap=0;
+
+ char buffer[1024]; // for reading lines
+
+ int linuxMajor = 0;
+ int linuxMinor = 0;
+
+ // Find the Linux kernel version first
+ struct utsname unameInfo;
+ int errorFlag = uname(&unameInfo);
+ if( errorFlag!=0 )
+ {
+ kwsys_ios::cout << "Problem calling uname(): " << strerror(errno) << kwsys_ios::endl;
+ return false;
+ }
+
+ if( strlen(unameInfo.release)>=3 )
+ {
+ // release looks like "2.6.3-15mdk-i686-up-4GB"
+ char majorChar=unameInfo.release[0];
+ char minorChar=unameInfo.release[2];
+
+ if( isdigit(majorChar) )
+ {
+ linuxMajor=majorChar-'0';
+ }
+
+ if( isdigit(minorChar) )
+ {
+ linuxMinor=minorChar-'0';
+ }
+ }
+
+ FILE *fd = fopen("/proc/meminfo", "r" );
+ if ( !fd )
+ {
+ kwsys_ios::cout << "Problem opening /proc/meminfo" << kwsys_ios::endl;
+ return false;
+ }
+
+ if( linuxMajor>=3 || ( (linuxMajor>=2) && (linuxMinor>=6) ) )
+ {
+ // new /proc/meminfo format since kernel 2.6.x
+ // Rigorously, this test should check from the developping version 2.5.x
+ // that introduced the new format...
+
+ enum { mMemTotal, mMemFree, mBuffers, mCached, mSwapTotal, mSwapFree };
+ const char* format[6] =
+ { "MemTotal:%lu kB", "MemFree:%lu kB", "Buffers:%lu kB",
+ "Cached:%lu kB", "SwapTotal:%lu kB", "SwapFree:%lu kB" };
+ bool have[6] = { false, false, false, false, false, false };
+ unsigned long value[6];
+ int count = 0;
+ while(fgets(buffer, static_cast<int>(sizeof(buffer)), fd))
+ {
+ for(int i=0; i < 6; ++i)
+ {
+ if(!have[i] && sscanf(buffer, format[i], &value[i]) == 1)
+ {
+ have[i] = true;
+ ++count;
+ }
+ }
+ }
+ if(count == 6)
+ {
+ this->TotalPhysicalMemory = value[mMemTotal] / 1024;
+ this->AvailablePhysicalMemory =
+ (value[mMemFree] + value[mBuffers] + value[mCached]) / 1024;
+ this->TotalVirtualMemory = value[mSwapTotal] / 1024;
+ this->AvailableVirtualMemory = value[mSwapFree] / 1024;
+ }
+ else
+ {
+ kwsys_ios::cout << "Problem parsing /proc/meminfo" << kwsys_ios::endl;
+ fclose(fd);
+ return false;
+ }
+ }
+ else
+ {
+ // /proc/meminfo format for kernel older than 2.6.x
+
+ unsigned long temp;
+ unsigned long cachedMem;
+ unsigned long buffersMem;
+ // Skip "total: used:..."
+ char *r=fgets(buffer, static_cast<int>(sizeof(buffer)), fd);
+ int status=0;
+ if(r==buffer)
+ {
+ status+=fscanf(fd, "Mem: %lu %lu %lu %lu %lu %lu\n",
+ &tp, &temp, &ap, &temp, &buffersMem, &cachedMem);
+ }
+ if(status==6)
+ {
+ status+=fscanf(fd, "Swap: %lu %lu %lu\n", &tv, &temp, &av);
+ }
+ if(status==9)
+ {
+ this->TotalVirtualMemory = tv>>10>>10;
+ this->TotalPhysicalMemory = tp>>10>>10;
+ this->AvailableVirtualMemory = av>>10>>10;
+ this->AvailablePhysicalMemory = (ap+buffersMem+cachedMem)>>10>>10;
+ }
+ else
+ {
+ kwsys_ios::cout << "Problem parsing /proc/meminfo" << kwsys_ios::endl;
+ fclose(fd);
+ return false;
+ }
+ }
+ fclose( fd );
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryCygwinMemory()
+{
+#ifdef __CYGWIN__
+ // _SC_PAGE_SIZE does return the mmap() granularity on Cygwin,
+ // see http://cygwin.com/ml/cygwin/2006-06/msg00350.html
+ // Therefore just use 4096 as the page size of Windows.
+ long m = sysconf(_SC_PHYS_PAGES);
+ if (m < 0)
+ {
+ return false;
+ }
+ this->TotalPhysicalMemory = m >> 8;
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryAIXMemory()
+{
+#if defined(_AIX)
+ long c = sysconf(_SC_AIX_REALMEM);
+ if (c <= 0)
+ {
+ return false;
+ }
+
+ this->TotalPhysicalMemory = c / 1024;
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryMemoryBySysconf()
+{
+#if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
+ // Assume the mmap() granularity as returned by _SC_PAGESIZE is also
+ // the system page size. The only known system where this isn't true
+ // is Cygwin.
+ long p = sysconf(_SC_PHYS_PAGES);
+ long m = sysconf(_SC_PAGESIZE);
+
+ if (p < 0 || m < 0)
+ {
+ return false;
+ }
+
+ // assume pagesize is a power of 2 and smaller 1 MiB
+ size_t pagediv = (1024 * 1024 / m);
+
+ this->TotalPhysicalMemory = p;
+ this->TotalPhysicalMemory /= pagediv;
+
+#if defined(_SC_AVPHYS_PAGES)
+ p = sysconf(_SC_AVPHYS_PAGES);
+ if (p < 0)
+ {
+ return false;
+ }
+
+ this->AvailablePhysicalMemory = p;
+ this->AvailablePhysicalMemory /= pagediv;
+#endif
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+/** Query for the memory status */
+bool SystemInformationImplementation::QueryMemory()
+{
+ return this->QueryMemoryBySysconf();
+}
+
+/** */
+size_t SystemInformationImplementation::GetTotalVirtualMemory()
+{
+ return this->TotalVirtualMemory;
+}
+
+/** */
+size_t SystemInformationImplementation::GetAvailableVirtualMemory()
+{
+ return this->AvailableVirtualMemory;
+}
+
+size_t SystemInformationImplementation::GetTotalPhysicalMemory()
+{
+ return this->TotalPhysicalMemory;
+}
+
+/** */
+size_t SystemInformationImplementation::GetAvailablePhysicalMemory()
+{
+ return this->AvailablePhysicalMemory;
+}
+
+/** Get Cycle differences */
+SystemInformation::LongLong
+SystemInformationImplementation::GetCyclesDifference (DELAY_FUNC DelayFunction,
+ unsigned int uiParameter)
+{
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+ unsigned __int64 stamp1, stamp2;
+
+ stamp1 = __rdtsc();
+ DelayFunction(uiParameter);
+ stamp2 = __rdtsc();
+
+ return stamp2 - stamp1;
+#elif USE_ASM_INSTRUCTIONS
+
+ unsigned int edx1, eax1;
+ unsigned int edx2, eax2;
+
+ // Calculate the frequency of the CPU instructions.
+ __try {
+ _asm {
+ push uiParameter ; push parameter param
+ mov ebx, DelayFunction ; store func in ebx
+
+ RDTSC_INSTRUCTION
+
+ mov esi, eax ; esi = eax
+ mov edi, edx ; edi = edx
+
+ call ebx ; call the delay functions
+
+ RDTSC_INSTRUCTION
+
+ pop ebx
+
+ mov edx2, edx ; edx2 = edx
+ mov eax2, eax ; eax2 = eax
+
+ mov edx1, edi ; edx2 = edi
+ mov eax1, esi ; eax2 = esi
+ }
+ }
+ __except(1)
+ {
+ return -1;
+ }
+
+ return ((((__int64) edx2 << 32) + eax2) - (((__int64) edx1 << 32) + eax1));
+
+#else
+ (void)DelayFunction;
+ (void)uiParameter;
+ return -1;
+#endif
+}
+
+
+/** Compute the delay overhead */
+void SystemInformationImplementation::DelayOverhead(unsigned int uiMS)
+{
+#if defined(_WIN32)
+ LARGE_INTEGER Frequency, StartCounter, EndCounter;
+ __int64 x;
+
+ // Get the frequency of the high performance counter.
+ if(!QueryPerformanceFrequency (&Frequency))
+ {
+ return;
+ }
+ x = Frequency.QuadPart / 1000 * uiMS;
+
+ // Get the starting position of the counter.
+ QueryPerformanceCounter (&StartCounter);
+
+ do {
+ // Get the ending position of the counter.
+ QueryPerformanceCounter (&EndCounter);
+ } while (EndCounter.QuadPart - StartCounter.QuadPart == x);
+#endif
+ (void)uiMS;
+}
+
+/** Return the number of logical CPU per physical CPUs Works only for windows */
+unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void)
+{
+#ifdef __APPLE__
+ size_t len = 4;
+ int cores_per_package = 0;
+ int err = sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, &len, NULL, 0);
+ if (err != 0)
+ {
+ return 1; // That name was not found, default to 1
+ }
+ return static_cast<unsigned char>(cores_per_package);
+#else
+ int Regs[4] = { 0, 0, 0, 0 };
+#if USE_CPUID
+ if (!this->IsHyperThreadingSupported())
+ {
+ return static_cast<unsigned char>(1); // HT not supported
+ }
+ call_cpuid(1, Regs);
+#endif
+ return static_cast<unsigned char> ((Regs[1] & NUM_LOGICAL_BITS) >> 16);
+#endif
+}
+
+
+/** Works only for windows */
+bool SystemInformationImplementation::IsHyperThreadingSupported()
+{
+ if (this->Features.ExtendedFeatures.SupportsHyperthreading)
+ {
+ return true;
+ }
+
+#if USE_CPUID
+ int Regs[4] = { 0, 0, 0, 0 },
+ VendorId[4] = { 0, 0, 0, 0 };
+ // Get vendor id string
+ if (!call_cpuid(0, VendorId))
+ {
+ return false;
+ }
+ // eax contains family processor type
+ // edx has info about the availability of hyper-Threading
+ if (!call_cpuid(1, Regs))
+ {
+ return false;
+ }
+
+ if (((Regs[0] & FAMILY_ID) == PENTIUM4_ID) || (Regs[0] & EXT_FAMILY_ID))
+ {
+ if (VendorId[1] == 0x756e6547) // 'uneG'
+ {
+ if (VendorId[3] == 0x49656e69) // 'Ieni'
+ {
+ if (VendorId[2] == 0x6c65746e) // 'letn'
+ {
+ // Genuine Intel with hyper-Threading technology
+ this->Features.ExtendedFeatures.SupportsHyperthreading = ((Regs[3] & HT_BIT) != 0);
+ return this->Features.ExtendedFeatures.SupportsHyperthreading;
+ }
+ }
+ }
+ }
+#endif
+
+ return 0; // Not genuine Intel processor
+}
+
+
+/** Return the APIC Id. Works only for windows. */
+unsigned char SystemInformationImplementation::GetAPICId()
+{
+ int Regs[4] = { 0, 0, 0, 0 };
+
+#if USE_CPUID
+ if (!this->IsHyperThreadingSupported())
+ {
+ return static_cast<unsigned char>(-1); // HT not supported
+ } // Logical processor = 1
+ call_cpuid(1, Regs);
+#endif
+
+ return static_cast<unsigned char>((Regs[1] & INITIAL_APIC_ID_BITS) >> 24);
+}
+
+
+/** Count the number of CPUs. Works only on windows. */
+int SystemInformationImplementation::CPUCount()
+{
+#if defined(_WIN32)
+ unsigned char StatusFlag = 0;
+ SYSTEM_INFO info;
+
+ this->NumberOfPhysicalCPU = 0;
+ this->NumberOfLogicalCPU = 0;
+ info.dwNumberOfProcessors = 0;
+ GetSystemInfo (&info);
+
+ // Number of physical processors in a non-Intel system
+ // or in a 32-bit Intel system with Hyper-Threading technology disabled
+ this->NumberOfPhysicalCPU = (unsigned char) info.dwNumberOfProcessors;
+
+ if (this->IsHyperThreadingSupported())
+ {
+ unsigned char HT_Enabled = 0;
+ this->NumberOfLogicalCPU = this->LogicalCPUPerPhysicalCPU();
+ if (this->NumberOfLogicalCPU >= 1) // >1 Doesn't mean HT is enabled in the BIOS
+ {
+ HANDLE hCurrentProcessHandle;
+#ifndef _WIN64
+# define DWORD_PTR DWORD
+#endif
+ DWORD_PTR dwProcessAffinity;
+ DWORD_PTR dwSystemAffinity;
+ DWORD dwAffinityMask;
+
+ // Calculate the appropriate shifts and mask based on the
+ // number of logical processors.
+ unsigned int i = 1;
+ unsigned char PHY_ID_MASK = 0xFF;
+ //unsigned char PHY_ID_SHIFT = 0;
+
+ while (i < this->NumberOfLogicalCPU)
+ {
+ i *= 2;
+ PHY_ID_MASK <<= 1;
+ // PHY_ID_SHIFT++;
+ }
+
+ hCurrentProcessHandle = GetCurrentProcess();
+ GetProcessAffinityMask(hCurrentProcessHandle, &dwProcessAffinity,
+ &dwSystemAffinity);
+
+ // Check if available process affinity mask is equal to the
+ // available system affinity mask
+ if (dwProcessAffinity != dwSystemAffinity)
+ {
+ StatusFlag = HT_CANNOT_DETECT;
+ this->NumberOfPhysicalCPU = (unsigned char)-1;
+ return StatusFlag;
+ }
+
+ dwAffinityMask = 1;
+ while (dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity)
+ {
+ // Check if this CPU is available
+ if (dwAffinityMask & dwProcessAffinity)
+ {
+ if (SetProcessAffinityMask(hCurrentProcessHandle,
+ dwAffinityMask))
+ {
+ unsigned char APIC_ID, LOG_ID;
+ Sleep(0); // Give OS time to switch CPU
+
+ APIC_ID = GetAPICId();
+ LOG_ID = APIC_ID & ~PHY_ID_MASK;
+
+ if (LOG_ID != 0)
+ {
+ HT_Enabled = 1;
+ }
+ }
+ }
+ dwAffinityMask = dwAffinityMask << 1;
+ }
+ // Reset the processor affinity
+ SetProcessAffinityMask(hCurrentProcessHandle, dwProcessAffinity);
+
+ if (this->NumberOfLogicalCPU == 1) // Normal P4 : HT is disabled in hardware
+ {
+ StatusFlag = HT_DISABLED;
+ }
+ else
+ {
+ if (HT_Enabled)
+ {
+ // Total physical processors in a Hyper-Threading enabled system.
+ this->NumberOfPhysicalCPU /= (this->NumberOfLogicalCPU);
+ StatusFlag = HT_ENABLED;
+ }
+ else
+ {
+ StatusFlag = HT_SUPPORTED_NOT_ENABLED;
+ }
+ }
+ }
+ }
+ else
+ {
+ // Processors do not have Hyper-Threading technology
+ StatusFlag = HT_NOT_CAPABLE;
+ this->NumberOfLogicalCPU = 1;
+ }
+ return StatusFlag;
+#else
+ return 0;
+#endif
+}
+
+
+/** Return the number of logical CPUs on the system */
+unsigned int SystemInformationImplementation::GetNumberOfLogicalCPU()
+{
+ return this->NumberOfLogicalCPU;
+}
+
+
+/** Return the number of physical CPUs on the system */
+unsigned int SystemInformationImplementation::GetNumberOfPhysicalCPU()
+{
+ return this->NumberOfPhysicalCPU;
+}
+
+
+/** For Mac use sysctlbyname calls to find system info */
+bool SystemInformationImplementation::ParseSysCtl()
+{
+#if defined(__APPLE__)
+ char retBuf[128];
+ int err = 0;
+ uint64_t value = 0;
+ size_t len = sizeof(value);
+ sysctlbyname("hw.memsize", &value, &len, NULL, 0);
+ this->TotalPhysicalMemory = static_cast< size_t >( value/1048576 );
+
+ // Parse values for Mac
+ this->AvailablePhysicalMemory = 0;
+ vm_statistics_data_t vmstat;
+ mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
+ if ( host_statistics(mach_host_self(), HOST_VM_INFO,
+ (host_info_t) &vmstat, &count) == KERN_SUCCESS )
+ {
+ len = sizeof(value);
+ err = sysctlbyname("hw.pagesize", &value, &len, NULL, 0);
+ int64_t available_memory = vmstat.free_count * value;
+ this->AvailablePhysicalMemory = static_cast< size_t >( available_memory / 1048576 );
+ }
+
+#ifdef VM_SWAPUSAGE
+ // Virtual memory.
+ int mib[2] = { CTL_VM, VM_SWAPUSAGE };
+ size_t miblen = sizeof(mib) / sizeof(mib[0]);
+ struct xsw_usage swap;
+ len = sizeof(swap);
+ err = sysctl(mib, miblen, &swap, &len, NULL, 0);
+ if (err == 0)
+ {
+ this->AvailableVirtualMemory = static_cast< size_t >( swap.xsu_avail/1048576 );
+ this->TotalVirtualMemory = static_cast< size_t >( swap.xsu_total/1048576 );
+ }
+#else
+ this->AvailableVirtualMemory = 0;
+ this->TotalVirtualMemory = 0;
+#endif
+
+// CPU Info
+ len = sizeof(this->NumberOfPhysicalCPU);
+ sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len, NULL, 0);
+ len = sizeof(this->NumberOfLogicalCPU);
+ sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, NULL, 0);
+ this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical =
+ this->LogicalCPUPerPhysicalCPU();
+
+ len = sizeof(value);
+ sysctlbyname("hw.cpufrequency", &value, &len, NULL, 0);
+ this->CPUSpeedInMHz = static_cast< float >( value )/ 1000000;
+
+
+ // Chip family
+ len = sizeof(this->ChipID.Family);
+ //Seems only the intel chips will have this name so if this fails it is
+ //probably a PPC machine
+ err = sysctlbyname("machdep.cpu.family",
+ &this->ChipID.Family, &len, NULL, 0);
+ if (err != 0) // Go back to names we know but are less descriptive
+ {
+ this->ChipID.Family = 0;
+ ::memset(retBuf, 0, 128);
+ len = 32;
+ err = sysctlbyname("hw.machine", &retBuf, &len, NULL, 0);
+ kwsys_stl::string machineBuf(retBuf);
+ if (machineBuf.find_first_of("Power") != kwsys_stl::string::npos)
+ {
+ this->ChipID.Vendor = "IBM";
+ len = sizeof(this->ChipID.Family);
+ err = sysctlbyname("hw.cputype", &this->ChipID.Family, &len, NULL, 0);
+ len = sizeof(this->ChipID.Model);
+ err = sysctlbyname("hw.cpusubtype", &this->ChipID.Model, &len, NULL, 0);
+ this->FindManufacturer();
+ }
+ }
+ else // Should be an Intel Chip.
+ {
+ len = sizeof(this->ChipID.Family);
+ err =
+ sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len, NULL, 0);
+
+ ::memset(retBuf, 0, 128);
+ len = 128;
+ err = sysctlbyname("machdep.cpu.vendor", retBuf, &len, NULL, 0);
+ // Chip Vendor
+ this->ChipID.Vendor = retBuf;
+ this->FindManufacturer();
+
+ // Chip Model
+ len = sizeof(value);
+ err = sysctlbyname("machdep.cpu.model", &value, &len, NULL, 0);
+ this->ChipID.Model = static_cast< int >( value );
+
+ // Chip Stepping
+ len = sizeof(value);
+ value = 0;
+ err = sysctlbyname("machdep.cpu.stepping", &value, &len, NULL, 0);
+ if (!err)
+ {
+ this->ChipID.Revision = static_cast< int >( value );
+ }
+
+ // feature string
+ char *buf = 0;
+ size_t allocSize = 128;
+
+ err = 0;
+ len = 0;
+
+ // sysctlbyname() will return with err==0 && len==0 if the buffer is too small
+ while (err == 0 && len == 0)
+ {
+ delete[] buf;
+ allocSize *= 2;
+ buf = new char[allocSize];
+ if (!buf)
+ {
+ break;
+ }
+ buf[0] = ' ';
+ len = allocSize - 2; // keep space for leading and trailing space
+ err = sysctlbyname("machdep.cpu.features", buf + 1, &len, NULL, 0);
+ }
+ if (!err && buf && len)
+ {
+ // now we can match every flags as space + flag + space
+ buf[len + 1] = ' ';
+ kwsys_stl::string cpuflags(buf, len + 2);
+
+ if ((cpuflags.find(" FPU ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasFPU = true;
+ }
+ if ((cpuflags.find(" TSC ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasTSC = true;
+ }
+ if ((cpuflags.find(" MMX ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasMMX = true;
+ }
+ if ((cpuflags.find(" SSE ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasSSE = true;
+ }
+ if ((cpuflags.find(" SSE2 ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasSSE2 = true;
+ }
+ if ((cpuflags.find(" APIC ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasAPIC = true;
+ }
+ if ((cpuflags.find(" CMOV ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasCMOV = true;
+ }
+ if ((cpuflags.find(" MTRR ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasMTRR = true;
+ }
+ if ((cpuflags.find(" ACPI ")!=kwsys_stl::string::npos))
+ {
+ this->Features.HasACPI = true;
+ }
+ }
+ delete[] buf;
+ }
+
+ // brand string
+ ::memset(retBuf, 0, sizeof(retBuf));
+ len = sizeof(retBuf);
+ err = sysctlbyname("machdep.cpu.brand_string", retBuf, &len, NULL, 0);
+ if (!err)
+ {
+ this->ChipID.ProcessorName = retBuf;
+ this->ChipID.ModelName = retBuf;
+ }
+
+ // Cache size
+ len = sizeof(value);
+ err = sysctlbyname("hw.l1icachesize", &value, &len, NULL, 0);
+ this->Features.L1CacheSize = static_cast< int >( value );
+ len = sizeof(value);
+ err = sysctlbyname("hw.l2cachesize", &value, &len, NULL, 0);
+ this->Features.L2CacheSize = static_cast< int >( value );
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+
+/** Extract a value from sysctl command */
+kwsys_stl::string SystemInformationImplementation::ExtractValueFromSysCtl(const char* word)
+{
+ size_t pos = this->SysCtlBuffer.find(word);
+ if(pos != this->SysCtlBuffer.npos)
+ {
+ pos = this->SysCtlBuffer.find(": ",pos);
+ size_t pos2 = this->SysCtlBuffer.find("\n",pos);
+ if(pos!=this->SysCtlBuffer.npos && pos2!=this->SysCtlBuffer.npos)
+ {
+ return this->SysCtlBuffer.substr(pos+2,pos2-pos-2);
+ }
+ }
+ return "";
+}
+
+
+/** Run a given process */
+kwsys_stl::string SystemInformationImplementation::RunProcess(kwsys_stl::vector<const char*> args)
+{
+ kwsys_stl::string buffer = "";
+
+ // Run the application
+ kwsysProcess* gp = kwsysProcess_New();
+ kwsysProcess_SetCommand(gp, &*args.begin());
+ kwsysProcess_SetOption(gp,kwsysProcess_Option_HideWindow,1);
+
+ kwsysProcess_Execute(gp);
+
+ char* data = NULL;
+ int length;
+ double timeout = 255;
+ int pipe; // pipe id as returned by kwsysProcess_WaitForData()
+
+ while( ( pipe = kwsysProcess_WaitForData(gp,&data,&length,&timeout),
+ (pipe == kwsysProcess_Pipe_STDOUT || pipe == kwsysProcess_Pipe_STDERR) ) ) // wait for 1s
+ {
+ buffer.append(data, length);
+ }
+ kwsysProcess_WaitForExit(gp, 0);
+
+ int result = 0;
+ switch(kwsysProcess_GetState(gp))
+ {
+ case kwsysProcess_State_Exited:
+ {
+ result = kwsysProcess_GetExitValue(gp);
+ } break;
+ case kwsysProcess_State_Error:
+ {
+ kwsys_ios::cerr << "Error: Could not run " << args[0] << ":\n";
+ kwsys_ios::cerr << kwsysProcess_GetErrorString(gp) << "\n";
+ } break;
+ case kwsysProcess_State_Exception:
+ {
+ kwsys_ios::cerr << "Error: " << args[0]
+ << " terminated with an exception: "
+ << kwsysProcess_GetExceptionString(gp) << "\n";
+ } break;
+ case kwsysProcess_State_Starting:
+ case kwsysProcess_State_Executing:
+ case kwsysProcess_State_Expired:
+ case kwsysProcess_State_Killed:
+ {
+ // Should not get here.
+ kwsys_ios::cerr << "Unexpected ending state after running " << args[0]
+ << kwsys_ios::endl;
+ } break;
+ }
+ kwsysProcess_Delete(gp);
+ if(result)
+ {
+ kwsys_ios::cerr << "Error " << args[0] << " returned :" << result << "\n";
+ }
+ return buffer;
+}
+
+
+kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const char* arguments)
+{
+ kwsys_stl::vector<const char*> args;
+ args.clear();
+ args.push_back("kstat");
+ args.push_back("-p");
+
+ kwsys_stl::string command = arguments;
+ size_t start = command.npos;
+ size_t pos = command.find(' ',0);
+ while(pos!=command.npos)
+ {
+ bool inQuotes = false;
+ // Check if we are between quotes
+ size_t b0 = command.find('"',0);
+ size_t b1 = command.find('"',b0+1);
+ while(b0 != command.npos && b1 != command.npos && b1>b0)
+ {
+ if(pos>b0 && pos<b1)
+ {
+ inQuotes = true;
+ break;
+ }
+ b0 = command.find('"',b1+1);
+ b1 = command.find('"',b0+1);
+ }
+
+ if(!inQuotes)
+ {
+ kwsys_stl::string arg = command.substr(start+1,pos-start-1);
+
+ // Remove the quotes if any
+ size_t quotes = arg.find('"');
+ while(quotes != arg.npos)
+ {
+ arg.erase(quotes,1);
+ quotes = arg.find('"');
+ }
+ args.push_back(arg.c_str());
+ start = pos;
+ }
+ pos = command.find(' ',pos+1);
+ }
+ kwsys_stl::string lastArg = command.substr(start+1,command.size()-start-1);
+ args.push_back(lastArg.c_str());
+
+ args.push_back(0);
+
+ kwsys_stl::string buffer = this->RunProcess(args);
+
+ kwsys_stl::string value = "";
+ for(size_t i=buffer.size()-1;i>0;i--)
+ {
+ if(buffer[i] == ' ' || buffer[i] == '\t')
+ {
+ break;
+ }
+ if(buffer[i] != '\n' && buffer[i] != '\r')
+ {
+ kwsys_stl::string val = value;
+ value = buffer[i];
+ value += val;
+ }
+ }
+ return value;
+}
+
+/** Querying for system information from Solaris */
+bool SystemInformationImplementation::QuerySolarisMemory()
+{
+#if defined (__SVR4) && defined (__sun)
+ // Solaris allows querying this value by sysconf, but if this is
+ // a 32 bit process on a 64 bit host the returned memory will be
+ // limited to 4GiB. So if this is a 32 bit process or if the sysconf
+ // method fails use the kstat interface.
+#if SIZEOF_VOID_P == 8
+ if (this->QueryMemoryBySysconf())
+ {
+ return true;
+ }
+#endif
+
+ char* tail;
+ unsigned long totalMemory =
+ strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail,0);
+ this->TotalPhysicalMemory = totalMemory/128;
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QuerySolarisProcessor()
+{
+ if (!this->QueryProcessorBySysconf())
+ {
+ return false;
+ }
+
+ // Parse values
+ this->CPUSpeedInMHz = static_cast<float>(atoi(this->ParseValueFromKStat("-s clock_MHz").c_str()));
+
+ // Chip family
+ this->ChipID.Family = 0;
+
+ // Chip Model
+ this->ChipID.ProcessorName = this->ParseValueFromKStat("-s cpu_type");
+ this->ChipID.Model = 0;
+
+ // Chip Vendor
+ if (this->ChipID.ProcessorName != "i386")
+ {
+ this->ChipID.Vendor = "Sun";
+ this->FindManufacturer();
+ }
+
+ return true;
+}
+
+
+/** Querying for system information from Haiku OS */
+bool SystemInformationImplementation::QueryHaikuInfo()
+{
+#if defined(__HAIKU__)
+
+ // CPU count
+ system_info info;
+ get_system_info(&info);
+ this->NumberOfPhysicalCPU = info.cpu_count;
+
+ // CPU speed
+ uint32 topologyNodeCount = 0;
+ cpu_topology_node_info* topology = 0;
+ get_cpu_topology_info(0, &topologyNodeCount);
+ if (topologyNodeCount != 0)
+ topology = new cpu_topology_node_info[topologyNodeCount];
+ get_cpu_topology_info(topology, &topologyNodeCount);
+
+ for (uint32 i = 0; i < topologyNodeCount; i++) {
+ if (topology[i].type == B_TOPOLOGY_CORE) {
+ this->CPUSpeedInMHz = topology[i].data.core.default_frequency /
+ 1000000.0f;
+ break;
+ }
+ }
+
+ delete[] topology;
+
+ // Physical Memory
+ this->TotalPhysicalMemory = (info.max_pages * B_PAGE_SIZE) / (1024 * 1024) ;
+ this->AvailablePhysicalMemory = this->TotalPhysicalMemory -
+ ((info.used_pages * B_PAGE_SIZE) / (1024 * 1024));
+
+
+ // NOTE: get_system_info_etc is currently a private call so just set to 0
+ // until it becomes public
+ this->TotalVirtualMemory = 0;
+ this->AvailableVirtualMemory = 0;
+
+ // Retrieve cpuid_info union for cpu 0
+ cpuid_info cpu_info;
+ get_cpuid(&cpu_info, 0, 0);
+
+ // Chip Vendor
+ // Use a temporary buffer so that we can add NULL termination to the string
+ char vbuf[13];
+ strncpy(vbuf, cpu_info.eax_0.vendor_id, 12);
+ vbuf[12] = '\0';
+ this->ChipID.Vendor = vbuf;
+
+ this->FindManufacturer();
+
+ // Retrieve cpuid_info union for cpu 0 this time using a register value of 1
+ get_cpuid(&cpu_info, 1, 0);
+
+ this->NumberOfLogicalCPU = cpu_info.eax_1.logical_cpus;
+
+ // Chip type
+ this->ChipID.Type = cpu_info.eax_1.type;
+
+ // Chip family
+ this->ChipID.Family = cpu_info.eax_1.family;
+
+ // Chip Model
+ this->ChipID.Model = cpu_info.eax_1.model;
+
+ // Chip Revision
+ this->ChipID.Revision = cpu_info.eax_1.stepping;
+
+ // Chip Extended Family
+ this->ChipID.ExtendedFamily = cpu_info.eax_1.extended_family;
+
+ // Chip Extended Model
+ this->ChipID.ExtendedModel = cpu_info.eax_1.extended_model;
+
+ // Get ChipID.ProcessorName from other information already gathered
+ this->RetrieveClassicalCPUIdentity();
+
+ // Cache size
+ this->Features.L1CacheSize = 0;
+ this->Features.L2CacheSize = 0;
+
+ return true;
+
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryQNXMemory()
+{
+#if defined(__QNX__)
+ kwsys_stl::string buffer;
+ kwsys_stl::vector<const char*> args;
+ args.clear();
+
+ args.push_back("showmem");
+ args.push_back("-S");
+ args.push_back(0);
+ buffer = this->RunProcess(args);
+ args.clear();
+
+ size_t pos = buffer.find("System RAM:");
+ if (pos == buffer.npos)
+ return false;
+ pos = buffer.find(":", pos);
+ size_t pos2 = buffer.find("M (", pos);
+ if (pos2 == buffer.npos)
+ return false;
+
+ pos++;
+ while (buffer[pos] == ' ')
+ pos++;
+
+ this->TotalPhysicalMemory = atoi(buffer.substr(pos, pos2 - pos).c_str());
+ return true;
+#endif
+ return false;
+}
+
+bool SystemInformationImplementation::QueryBSDMemory()
+{
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
+ int ctrl[2] = { CTL_HW, HW_PHYSMEM };
+#if defined(HW_PHYSMEM64)
+ int64_t k;
+ ctrl[1] = HW_PHYSMEM64;
+#else
+ int k;
+#endif
+ size_t sz = sizeof(k);
+
+ if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
+ {
+ return false;
+ }
+
+ this->TotalPhysicalMemory = k>>10>>10;
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryQNXProcessor()
+{
+#if defined(__QNX__)
+ // the output on my QNX 6.4.1 looks like this:
+ // Processor1: 686 Pentium II Stepping 3 2175MHz FPU
+ kwsys_stl::string buffer;
+ kwsys_stl::vector<const char*> args;
+ args.clear();
+
+ args.push_back("pidin");
+ args.push_back("info");
+ args.push_back(0);
+ buffer = this->RunProcess(args);
+ args.clear();
+
+ size_t pos = buffer.find("Processor1:");
+ if (pos == buffer.npos)
+ return false;
+
+ size_t pos2 = buffer.find("MHz", pos);
+ if (pos2 == buffer.npos)
+ return false;
+
+ size_t pos3 = pos2;
+ while (buffer[pos3] != ' ')
+ --pos3;
+
+ this->CPUSpeedInMHz = atoi(buffer.substr(pos3 + 1, pos2 - pos3 - 1).c_str());
+
+ pos2 = buffer.find(" Stepping", pos);
+ if (pos2 != buffer.npos)
+ {
+ pos2 = buffer.find(" ", pos2 + 1);
+ if (pos2 != buffer.npos && pos2 < pos3)
+ {
+ this->ChipID.Revision = atoi(buffer.substr(pos2 + 1, pos3 - pos2).c_str());
+ }
+ }
+
+ this->NumberOfPhysicalCPU = 0;
+ do
+ {
+ pos = buffer.find("\nProcessor", pos + 1);
+ ++this->NumberOfPhysicalCPU;
+ } while (pos != buffer.npos);
+ this->NumberOfLogicalCPU = 1;
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryBSDProcessor()
+{
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
+ int k;
+ size_t sz = sizeof(k);
+ int ctrl[2] = { CTL_HW, HW_NCPU };
+
+ if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
+ {
+ return false;
+ }
+
+ this->NumberOfPhysicalCPU = k;
+ this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
+
+#if defined(HW_CPUSPEED)
+ ctrl[1] = HW_CPUSPEED;
+
+ if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
+ {
+ return false;
+ }
+
+ this->CPUSpeedInMHz = (float) k;
+#endif
+
+#if defined(CPU_SSE)
+ ctrl[0] = CTL_MACHDEP;
+ ctrl[1] = CPU_SSE;
+
+ if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
+ {
+ return false;
+ }
+
+ this->Features.HasSSE = (k > 0);
+#endif
+
+#if defined(CPU_SSE2)
+ ctrl[0] = CTL_MACHDEP;
+ ctrl[1] = CPU_SSE2;
+
+ if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
+ {
+ return false;
+ }
+
+ this->Features.HasSSE2 = (k > 0);
+#endif
+
+#if defined(CPU_CPUVENDOR)
+ ctrl[0] = CTL_MACHDEP;
+ ctrl[1] = CPU_CPUVENDOR;
+ char vbuf[25];
+ ::memset(vbuf, 0, sizeof(vbuf));
+ sz = sizeof(vbuf) - 1;
+ if (sysctl(ctrl, 2, vbuf, &sz, NULL, 0) != 0)
+ {
+ return false;
+ }
+
+ this->ChipID.Vendor = vbuf;
+ this->FindManufacturer();
+#endif
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryHPUXMemory()
+{
+#if defined(__hpux)
+ unsigned long tv=0;
+ unsigned long tp=0;
+ unsigned long av=0;
+ unsigned long ap=0;
+ struct pst_static pst;
+ struct pst_dynamic pdy;
+
+ unsigned long ps = 0;
+ if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1)
+ {
+ return false;
+ }
+
+ ps = pst.page_size;
+ tp = pst.physical_memory *ps;
+ tv = (pst.physical_memory + pst.pst_maxmem) * ps;
+ if (pstat_getdynamic(&pdy, sizeof(pdy), (size_t) 1, 0) == -1)
+ {
+ return false;
+ }
+
+ ap = tp - pdy.psd_rm * ps;
+ av = tv - pdy.psd_vm;
+ this->TotalVirtualMemory = tv>>10>>10;
+ this->TotalPhysicalMemory = tp>>10>>10;
+ this->AvailableVirtualMemory = av>>10>>10;
+ this->AvailablePhysicalMemory = ap>>10>>10;
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QueryHPUXProcessor()
+{
+#if defined(__hpux)
+# if defined(KWSYS_SYS_HAS_MPCTL_H)
+ int c = mpctl(MPC_GETNUMSPUS_SYS, 0, 0);
+ if (c <= 0)
+ {
+ return false;
+ }
+
+ this->NumberOfPhysicalCPU = c;
+ this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
+
+ long t = sysconf(_SC_CPU_VERSION);
+
+ if (t == -1)
+ {
+ return false;
+ }
+
+ switch (t)
+ {
+ case CPU_PA_RISC1_0:
+ this->ChipID.Vendor = "Hewlett-Packard";
+ this->ChipID.Family = 0x100;
+ break;
+ case CPU_PA_RISC1_1:
+ this->ChipID.Vendor = "Hewlett-Packard";
+ this->ChipID.Family = 0x110;
+ break;
+ case CPU_PA_RISC2_0:
+ this->ChipID.Vendor = "Hewlett-Packard";
+ this->ChipID.Family = 0x200;
+ break;
+# if defined(CPU_HP_INTEL_EM_1_0) || defined(CPU_IA64_ARCHREV_0)
+# ifdef CPU_HP_INTEL_EM_1_0
+ case CPU_HP_INTEL_EM_1_0:
+# endif
+# ifdef CPU_IA64_ARCHREV_0
+ case CPU_IA64_ARCHREV_0:
+# endif
+ this->ChipID.Vendor = "GenuineIntel";
+ this->Features.HasIA64 = true;
+ break;
+# endif
+ default:
+ return false;
+ }
+
+ this->FindManufacturer();
+
+ return true;
+# else
+ return false;
+# endif
+#else
+ return false;
+#endif
+}
+
+/** Query the operating system information */
+bool SystemInformationImplementation::QueryOSInformation()
+{
+#if defined(_WIN32)
+
+ this->OSName = "Windows";
+
+ OSVERSIONINFOEXW osvi;
+ BOOL bIsWindows64Bit;
+ BOOL bOsVersionInfoEx;
+ char operatingSystem[256];
+
+ // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
+ ZeroMemory (&osvi, sizeof (OSVERSIONINFOEXW));
+ osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXW);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (push)
+# pragma warning (disable:4996)
+#endif
+ bOsVersionInfoEx = GetVersionExW ((OSVERSIONINFOW*)&osvi);
+ if (!bOsVersionInfoEx)
+ {
+ osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOW);
+ if (!GetVersionExW((OSVERSIONINFOW*)&osvi))
+ {
+ return false;
+ }
+ }
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (pop)
+#endif
+
+ switch (osvi.dwPlatformId)
+ {
+ case VER_PLATFORM_WIN32_NT:
+ // Test for the product.
+ if (osvi.dwMajorVersion <= 4)
+ {
+ this->OSRelease = "NT";
+ }
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
+ {
+ this->OSRelease = "2000";
+ }
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
+ {
+ this->OSRelease = "XP";
+ }
+ // XP Professional x64
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
+ {
+ this->OSRelease = "XP";
+ }
+#ifdef VER_NT_WORKSTATION
+ // Test for product type.
+ if (bOsVersionInfoEx)
+ {
+ if (osvi.wProductType == VER_NT_WORKSTATION)
+ {
+ if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)
+ {
+ this->OSRelease = "Vista";
+ }
+ if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1)
+ {
+ this->OSRelease = "7";
+ }
+// VER_SUITE_PERSONAL may not be defined
+#ifdef VER_SUITE_PERSONAL
+ else
+ {
+ if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
+ {
+ this->OSRelease += " Personal";
+ }
+ else
+ {
+ this->OSRelease += " Professional";
+ }
+ }
+#endif
+ }
+ else if (osvi.wProductType == VER_NT_SERVER)
+ {
+ // Check for .NET Server instead of Windows XP.
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
+ {
+ this->OSRelease = ".NET";
+ }
+
+ // Continue with the type detection.
+ if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
+ {
+ this->OSRelease += " DataCenter Server";
+ }
+ else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
+ {
+ this->OSRelease += " Advanced Server";
+ }
+ else
+ {
+ this->OSRelease += " Server";
+ }
+ }
+
+ sprintf (operatingSystem, "%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
+ this->OSVersion = operatingSystem;
+ }
+ else
+#endif // VER_NT_WORKSTATION
+ {
+ HKEY hKey;
+ wchar_t szProductType[80];
+ DWORD dwBufLen;
+
+ // Query the registry to retrieve information.
+ RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey);
+ RegQueryValueExW(hKey, L"ProductType", NULL, NULL, (LPBYTE) szProductType, &dwBufLen);
+ RegCloseKey (hKey);
+
+ if (lstrcmpiW(L"WINNT", szProductType) == 0)
+ {
+ this->OSRelease += " Professional";
+ }
+ if (lstrcmpiW(L"LANMANNT", szProductType) == 0)
+ {
+ // Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
+ {
+ this->OSRelease += " Standard Server";
+ }
+ else
+ {
+ this->OSRelease += " Server";
+ }
+ }
+ if (lstrcmpiW(L"SERVERNT", szProductType) == 0)
+ {
+ // Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
+ {
+ this->OSRelease += " Enterprise Server";
+ }
+ else
+ {
+ this->OSRelease += " Advanced Server";
+ }
+ }
+ }
+
+ // Display version, service pack (if any), and build number.
+ if (osvi.dwMajorVersion <= 4)
+ {
+ // NB: NT 4.0 and earlier.
+ sprintf (operatingSystem, "version %ld.%ld %s (Build %ld)",
+ osvi.dwMajorVersion,
+ osvi.dwMinorVersion,
+ osvi.szCSDVersion,
+ osvi.dwBuildNumber & 0xFFFF);
+ this->OSVersion = operatingSystem;
+ }
+ else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
+ {
+ // Windows XP and .NET server.
+ typedef BOOL (CALLBACK* LPFNPROC) (HANDLE, BOOL *);
+ HINSTANCE hKernelDLL;
+ LPFNPROC DLLProc;
+
+ // Load the Kernel32 DLL.
+ hKernelDLL = LoadLibraryW(L"kernel32");
+ if (hKernelDLL != NULL) {
+ // Only XP and .NET Server support IsWOW64Process so... Load dynamically!
+ DLLProc = (LPFNPROC) GetProcAddress (hKernelDLL, "IsWow64Process");
+
+ // If the function address is valid, call the function.
+ if (DLLProc != NULL) (DLLProc) (GetCurrentProcess (), &bIsWindows64Bit);
+ else bIsWindows64Bit = false;
+
+ // Free the DLL module.
+ FreeLibrary (hKernelDLL);
+ }
+ }
+ else
+ {
+ // Windows 2000 and everything else.
+ sprintf (operatingSystem,"%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
+ this->OSVersion = operatingSystem;
+ }
+ break;
+
+ case VER_PLATFORM_WIN32_WINDOWS:
+ // Test for the product.
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
+ {
+ this->OSRelease = "95";
+ if(osvi.szCSDVersion[1] == 'C')
+ {
+ this->OSRelease += "OSR 2.5";
+ }
+ else if(osvi.szCSDVersion[1] == 'B')
+ {
+ this->OSRelease += "OSR 2";
+ }
+ }
+
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
+ {
+ this->OSRelease = "98";
+ if (osvi.szCSDVersion[1] == 'A' )
+ {
+ this->OSRelease += "SE";
+ }
+ }
+
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
+ {
+ this->OSRelease = "Me";
+ }
+ break;
+
+ case VER_PLATFORM_WIN32s:
+ this->OSRelease = "Win32s";
+ break;
+
+ default:
+ this->OSRelease = "Unknown";
+ break;
+ }
+
+ // Get the hostname
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ char name[255];
+ wVersionRequested = MAKEWORD(2,0);
+
+ if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
+ {
+ gethostname(name,sizeof(name));
+ WSACleanup( );
+ }
+ this->Hostname = name;
+
+ const char* arch = getenv("PROCESSOR_ARCHITECTURE");
+ if(arch)
+ {
+ this->OSPlatform = arch;
+ }
+
+#else
+
+ struct utsname unameInfo;
+ int errorFlag = uname(&unameInfo);
+ if(errorFlag == 0)
+ {
+ this->OSName = unameInfo.sysname;
+ this->Hostname = unameInfo.nodename;
+ this->OSRelease = unameInfo.release;
+ this->OSVersion = unameInfo.version;
+ this->OSPlatform = unameInfo.machine;
+ }
+
+#ifdef __APPLE__
+ this->OSName="Unknown Apple OS";
+ this->OSRelease="Unknown product version";
+ this->OSVersion="Unknown build version";
+
+ this->CallSwVers("-productName",this->OSName);
+ this->CallSwVers("-productVersion",this->OSRelease);
+ this->CallSwVers("-buildVersion",this->OSVersion);
+#endif
+
+#endif
+
+ return true;
+}
+
+int SystemInformationImplementation::CallSwVers(
+ const char *arg,
+ kwsys_stl::string &ver)
+{
+#ifdef __APPLE__
+ kwsys_stl::vector<const char*> args;
+ args.push_back("sw_vers");
+ args.push_back(arg);
+ args.push_back(0);
+ ver = this->RunProcess(args);
+ this->TrimNewline(ver);
+#else
+ // avoid C4100
+ (void)arg;
+ (void)ver;
+#endif
+ return 0;
+}
+
+void SystemInformationImplementation::TrimNewline(kwsys_stl::string& output)
+{
+ // remove \r
+ kwsys_stl::string::size_type pos=0;
+ while((pos = output.find("\r", pos)) != kwsys_stl::string::npos)
+ {
+ output.erase(pos);
+ }
+
+ // remove \n
+ pos = 0;
+ while((pos = output.find("\n", pos)) != kwsys_stl::string::npos)
+ {
+ output.erase(pos);
+ }
+}
+
+
+/** Return true if the machine is 64 bits */
+bool SystemInformationImplementation::Is64Bits()
+{
+ return (sizeof(void*) == 8);
+}
+
+
+} // namespace @KWSYS_NAMESPACE@
diff --git a/Source/kwsys/SystemInformation.hxx.in b/Source/kwsys/SystemInformation.hxx.in
new file mode 100644
index 0000000000..a9fd05defe
--- /dev/null
+++ b/Source/kwsys/SystemInformation.hxx.in
@@ -0,0 +1,159 @@
+/*============================================================================
+ 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@_SystemInformation_h
+#define @KWSYS_NAMESPACE@_SystemInformation_h
+
+
+/* Define these macros temporarily to keep the code readable. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys_stl @KWSYS_NAMESPACE@_stl
+# define kwsys_ios @KWSYS_NAMESPACE@_ios
+#endif
+#include <@KWSYS_NAMESPACE@/stl/string>
+#include <stddef.h> /* size_t */
+
+namespace @KWSYS_NAMESPACE@
+{
+
+// forward declare the implementation class
+class SystemInformationImplementation;
+
+class @KWSYS_NAMESPACE@_EXPORT SystemInformation
+{
+#if @KWSYS_USE_LONG_LONG@
+ typedef long long LongLong;
+#elif @KWSYS_USE___INT64@
+ typedef __int64 LongLong;
+#else
+# error "No Long Long"
+#endif
+ friend class SystemInformationImplementation;
+ SystemInformationImplementation* Implementation;
+public:
+
+ SystemInformation ();
+ ~SystemInformation ();
+
+ const char * GetVendorString();
+ const char * GetVendorID();
+ kwsys_stl::string GetTypeID();
+ kwsys_stl::string GetFamilyID();
+ kwsys_stl::string GetModelID();
+ kwsys_stl::string GetModelName();
+ kwsys_stl::string GetSteppingCode();
+ const char * GetExtendedProcessorName();
+ const char * GetProcessorSerialNumber();
+ int GetProcessorCacheSize();
+ unsigned int GetLogicalProcessorsPerPhysical();
+ float GetProcessorClockFrequency();
+ int GetProcessorAPICID();
+ int GetProcessorCacheXSize(long int);
+ bool DoesCPUSupportFeature(long int);
+
+ // returns an informative general description of the cpu
+ // on this system.
+ kwsys_stl::string GetCPUDescription();
+
+ const char * GetHostname();
+ kwsys_stl::string GetFullyQualifiedDomainName();
+
+ const char * GetOSName();
+ const char * GetOSRelease();
+ const char * GetOSVersion();
+ const char * GetOSPlatform();
+
+ int GetOSIsWindows();
+ int GetOSIsLinux();
+ int GetOSIsApple();
+
+ // returns an informative general description of the os
+ // on this system.
+ kwsys_stl::string GetOSDescription();
+
+ bool Is64Bits();
+
+ unsigned int GetNumberOfLogicalCPU(); // per physical cpu
+ unsigned int GetNumberOfPhysicalCPU();
+
+ bool DoesCPUSupportCPUID();
+
+ // Retrieve id of the current running process
+ LongLong GetProcessId();
+
+ // Retrieve memory information in megabyte.
+ size_t GetTotalVirtualMemory();
+ size_t GetAvailableVirtualMemory();
+ size_t GetTotalPhysicalMemory();
+ size_t GetAvailablePhysicalMemory();
+
+ // returns an informative general description if the installed and
+ // available ram on this system. See the GetHostMmeoryTotal, and
+ // Get{Host,Proc}MemoryAvailable methods for more information.
+ kwsys_stl::string GetMemoryDescription(
+ const char *hostLimitEnvVarName=NULL,
+ const char *procLimitEnvVarName=NULL);
+
+ // Retrieve amount of physical memory installed on the system in KiB
+ // units.
+ LongLong GetHostMemoryTotal();
+
+ // Get total system RAM in units of KiB available colectivley to all
+ // processes in a process group. An example of a process group
+ // are the processes comprising an mpi program which is running in
+ // parallel. The amount of memory reported may differ from the host
+ // total if a host wide resource limit is applied. Such reource limits
+ // are reported to us via an applicaiton specified environment variable.
+ LongLong GetHostMemoryAvailable(const char *hostLimitEnvVarName=NULL);
+
+ // Get total system RAM in units of KiB available to this process.
+ // This may differ from the host available if a per-process resource
+ // limit is applied. per-process memory limits are applied on unix
+ // system via rlimit API. Resource limits that are not imposed via
+ // rlimit API may be reported to us via an application specified
+ // environment variable.
+ LongLong GetProcMemoryAvailable(
+ const char *hostLimitEnvVarName=NULL,
+ const char *procLimitEnvVarName=NULL);
+
+ // Get the system RAM used by all processes on the host, in units of KiB.
+ LongLong GetHostMemoryUsed();
+
+ // Get system RAM used by this process id in units of KiB.
+ LongLong GetProcMemoryUsed();
+
+ // enable/disable stack trace signal handler. In order to
+ // produce an informative stack trace the application should
+ // be dynamically linked and compiled with debug symbols.
+ static
+ void SetStackTraceOnError(int enable);
+
+ // format and return the current program stack in a string. In
+ // order to produce an informative stack trace the application
+ // should be dynamically linked and compiled with debug symbols.
+ static
+ kwsys_stl::string GetProgramStack(int firstFrame, int wholePath);
+
+ /** Run the different checks */
+ void RunCPUCheck();
+ void RunOSCheck();
+ void RunMemoryCheck();
+};
+
+} // namespace @KWSYS_NAMESPACE@
+
+/* Undefine temporary macros. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsys_stl
+# undef kwsys_ios
+#endif
+
+#endif
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
new file mode 100644
index 0000000000..b1221e3a8f
--- /dev/null
+++ b/Source/kwsys/SystemTools.cxx
@@ -0,0 +1,5110 @@
+/*============================================================================
+ 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.
+============================================================================*/
+
+#ifdef __osf__
+# define _OSF_SOURCE
+# define _POSIX_C_SOURCE 199506L
+# define _XOPEN_SOURCE_EXTENDED
+#endif
+
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(RegularExpression.hxx)
+#include KWSYS_HEADER(SystemTools.hxx)
+#include KWSYS_HEADER(Directory.hxx)
+#include KWSYS_HEADER(FStream.hxx)
+#include KWSYS_HEADER(Encoding.hxx)
+
+#include KWSYS_HEADER(ios/iostream)
+#include KWSYS_HEADER(ios/fstream)
+#include KWSYS_HEADER(ios/sstream)
+
+#include KWSYS_HEADER(stl/set)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "SystemTools.hxx.in"
+# include "Directory.hxx.in"
+# include "FStream.hxx.in"
+# include "Encoding.hxx.in"
+# include "kwsys_ios_iostream.h.in"
+# include "kwsys_ios_fstream.h.in"
+# include "kwsys_ios_sstream.h.in"
+#endif
+
+#ifdef _MSC_VER
+# pragma warning (disable: 4786)
+#endif
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 1375 /* base class destructor not virtual */
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+#ifdef __QNX__
+# include <malloc.h> /* for malloc/free on QNX */
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <time.h>
+
+// support for realpath call
+#ifndef _WIN32
+#include <sys/time.h>
+#include <utime.h>
+#include <limits.h>
+#include <sys/wait.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <pwd.h>
+#ifndef __VMS
+#include <sys/param.h>
+#include <termios.h>
+#endif
+#include <signal.h> /* sigprocmask */
+#endif
+
+// Windows API.
+#if defined(_WIN32)
+# include <windows.h>
+# ifndef INVALID_FILE_ATTRIBUTES
+# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+# endif
+# if defined(_MSC_VER) && _MSC_VER >= 1800
+# define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# endif
+#elif defined (__CYGWIN__)
+# include <windows.h>
+# undef _WIN32
+#endif
+
+#if !KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H
+extern char **environ;
+#endif
+
+#ifdef __CYGWIN__
+# include <sys/cygwin.h>
+#endif
+
+// getpwnam doesn't exist on Windows and Cray Xt3/Catamount
+// same for TIOCGWINSZ
+#if defined(_WIN32) || defined (__LIBCATAMOUNT__)
+# undef HAVE_GETPWNAM
+# undef HAVE_TTY_INFO
+#else
+# define HAVE_GETPWNAM 1
+# define HAVE_TTY_INFO 1
+#endif
+
+#define VTK_URL_PROTOCOL_REGEX "([a-zA-Z0-9]*)://(.*)"
+#define VTK_URL_REGEX "([a-zA-Z0-9]*)://(([A-Za-z0-9]+)(:([^:@]+))?@)?([^:@/]+)(:([0-9]+))?/(.+)?"
+
+#ifdef _MSC_VER
+#include <sys/utime.h>
+#else
+#include <utime.h>
+#endif
+
+
+// This is a hack to prevent warnings about these functions being
+// declared but not referenced.
+#if defined(__sgi) && !defined(__GNUC__)
+# include <sys/termios.h>
+namespace KWSYS_NAMESPACE
+{
+class SystemToolsHack
+{
+public:
+ enum
+ {
+ Ref1 = sizeof(cfgetospeed(0)),
+ Ref2 = sizeof(cfgetispeed(0)),
+ Ref3 = sizeof(tcgetattr(0, 0)),
+ Ref4 = sizeof(tcsetattr(0, 0, 0)),
+ Ref5 = sizeof(cfsetospeed(0,0)),
+ Ref6 = sizeof(cfsetispeed(0,0))
+ };
+};
+}
+#endif
+
+#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) ||defined(__BORLANDC__) || defined(__MINGW32__))
+#include <io.h>
+#include <direct.h>
+#define _unlink unlink
+#endif
+
+/* The maximum length of a file name. */
+#if defined(PATH_MAX)
+# define KWSYS_SYSTEMTOOLS_MAXPATH PATH_MAX
+#elif defined(MAXPATHLEN)
+# define KWSYS_SYSTEMTOOLS_MAXPATH MAXPATHLEN
+#else
+# define KWSYS_SYSTEMTOOLS_MAXPATH 16384
+#endif
+#if defined(__WATCOMC__)
+#include <direct.h>
+#define _mkdir mkdir
+#define _rmdir rmdir
+#define _getcwd getcwd
+#define _chdir chdir
+#endif
+
+#if defined(__BEOS__) && !defined(__ZETA__)
+#include <be/kernel/OS.h>
+#include <be/storage/Path.h>
+
+// BeOS 5 doesn't have usleep(), but it has snooze(), which is identical.
+static inline void usleep(unsigned int msec)
+{
+ ::snooze(msec);
+}
+
+// BeOS 5 also doesn't have realpath(), but its C++ API offers something close.
+static inline char *realpath(const char *path, char *resolved_path)
+{
+ const size_t maxlen = KWSYS_SYSTEMTOOLS_MAXPATH;
+ snprintf(resolved_path, maxlen, "%s", path);
+ BPath normalized(resolved_path, NULL, true);
+ const char *resolved = normalized.Path();
+ if (resolved != NULL) // NULL == No such file.
+ {
+ if (snprintf(resolved_path, maxlen, "%s", resolved) < maxlen)
+ {
+ return resolved_path;
+ }
+ }
+ return NULL; // something went wrong.
+}
+#endif
+
+#ifdef _WIN32
+static time_t windows_filetime_to_posix_time(const FILETIME& ft)
+{
+ LARGE_INTEGER date;
+ date.HighPart = ft.dwHighDateTime;
+ date.LowPart = ft.dwLowDateTime;
+
+ // removes the diff between 1970 and 1601
+ date.QuadPart -= ((LONGLONG)(369 * 365 + 89) * 24 * 3600 * 10000000);
+
+ // converts back from 100-nanoseconds to seconds
+ return date.QuadPart / 10000000;
+}
+#endif
+
+#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__))
+
+#include <wctype.h>
+
+inline int Mkdir(const kwsys_stl::string& dir)
+{
+ return _wmkdir(
+ KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str());
+}
+inline int Rmdir(const kwsys_stl::string& dir)
+{
+ return _wrmdir(
+ KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str());
+}
+inline const char* Getcwd(char* buf, unsigned int len)
+{
+ std::vector<wchar_t> w_buf(len);
+ if(const wchar_t* ret = _wgetcwd(&w_buf[0], len))
+ {
+ // make sure the drive letter is capital
+ if(wcslen(&w_buf[0]) > 1 && w_buf[1] == L':')
+ {
+ w_buf[0] = towupper(w_buf[0]);
+ }
+ std::string tmp = KWSYS_NAMESPACE::Encoding::ToNarrow(&w_buf[0]);
+ strcpy(buf, tmp.c_str());
+ return buf;
+ }
+ return 0;
+}
+inline int Chdir(const kwsys_stl::string& dir)
+{
+ #if defined(__BORLANDC__)
+ return chdir(dir.c_str());
+ #else
+ return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str());
+ #endif
+}
+inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path)
+{
+ kwsys_stl::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path);
+ wchar_t *ptemp;
+ wchar_t fullpath[MAX_PATH];
+ if( GetFullPathNameW(tmp.c_str(), sizeof(fullpath)/sizeof(fullpath[0]),
+ fullpath, &ptemp) )
+ {
+ resolved_path = KWSYS_NAMESPACE::Encoding::ToNarrow(fullpath);
+ KWSYS_NAMESPACE::SystemTools::ConvertToUnixSlashes(resolved_path);
+ }
+ else
+ {
+ resolved_path = path;
+ }
+}
+#else
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+inline int Mkdir(const kwsys_stl::string& dir)
+{
+ return mkdir(dir.c_str(), 00777);
+}
+inline int Rmdir(const kwsys_stl::string& dir)
+{
+ return rmdir(dir.c_str());
+}
+inline const char* Getcwd(char* buf, unsigned int len)
+{
+ return getcwd(buf, len);
+}
+
+inline int Chdir(const kwsys_stl::string& dir)
+{
+ return chdir(dir.c_str());
+}
+inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path)
+{
+ char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH];
+
+ char *ret = realpath(path.c_str(), resolved_name);
+ if(ret)
+ {
+ resolved_path = ret;
+ }
+ else
+ {
+ // if path resolution fails, return what was passed in
+ resolved_path = path;
+ }
+}
+#endif
+
+#if !defined(_WIN32) && defined(__COMO__)
+// Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
+extern "C"
+{
+extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
+extern int pclose (FILE *__stream) __THROW;
+extern char *realpath (__const char *__restrict __name,
+ char *__restrict __resolved) __THROW;
+extern char *strdup (__const char *__s) __THROW;
+extern int putenv (char *__string) __THROW;
+}
+#endif
+
+namespace KWSYS_NAMESPACE
+{
+
+double SystemTools::GetTime(void)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ FILETIME ft;
+ GetSystemTimeAsFileTime(&ft);
+ return (429.4967296*ft.dwHighDateTime
+ + 0.0000001*ft.dwLowDateTime
+ - 11644473600.0);
+#else
+ struct timeval t;
+ gettimeofday(&t, 0);
+ return 1.0*double(t.tv_sec) + 0.000001*double(t.tv_usec);
+#endif
+}
+
+class SystemToolsTranslationMap :
+ public kwsys_stl::map<kwsys_stl::string,kwsys_stl::string>
+{
+};
+
+// adds the elements of the env variable path to the arg passed in
+void SystemTools::GetPath(kwsys_stl::vector<kwsys_stl::string>& path, const char* env)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ const char pathSep = ';';
+#else
+ const char pathSep = ':';
+#endif
+ if(!env)
+ {
+ env = "PATH";
+ }
+ const char* cpathEnv = SystemTools::GetEnv(env);
+ if ( !cpathEnv )
+ {
+ return;
+ }
+
+ kwsys_stl::string pathEnv = cpathEnv;
+
+ // A hack to make the below algorithm work.
+ if(!pathEnv.empty() && *pathEnv.rbegin() != pathSep)
+ {
+ pathEnv += pathSep;
+ }
+ kwsys_stl::string::size_type start =0;
+ bool done = false;
+ while(!done)
+ {
+ kwsys_stl::string::size_type endpos = pathEnv.find(pathSep, start);
+ if(endpos != kwsys_stl::string::npos)
+ {
+ path.push_back(pathEnv.substr(start, endpos-start));
+ start = endpos+1;
+ }
+ else
+ {
+ done = true;
+ }
+ }
+ for(kwsys_stl::vector<kwsys_stl::string>::iterator i = path.begin();
+ i != path.end(); ++i)
+ {
+ SystemTools::ConvertToUnixSlashes(*i);
+ }
+}
+
+const char* SystemTools::GetEnv(const char* key)
+{
+ return getenv(key);
+}
+
+bool SystemTools::GetEnv(const char* key, kwsys_stl::string& result)
+{
+ const char* v = getenv(key);
+ if(v)
+ {
+ result = v;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
+
+#if defined(__CYGWIN__) || defined(__GLIBC__)
+# define KWSYS_PUTENV_NAME /* putenv("A") removes A. */
+#elif defined(_WIN32)
+# define KWSYS_PUTENV_EMPTY /* putenv("A=") removes A. */
+#endif
+
+#if KWSYS_CXX_HAS_UNSETENV
+/* unsetenv("A") removes A from the environment.
+ On older platforms it returns void instead of int. */
+static int kwsysUnPutEnv(const char* env)
+{
+ if(const char* eq = strchr(env, '='))
+ {
+ std::string name(env, eq-env);
+ unsetenv(name.c_str());
+ }
+ else
+ {
+ unsetenv(env);
+ }
+ return 0;
+}
+
+#elif defined(KWSYS_PUTENV_EMPTY) || defined(KWSYS_PUTENV_NAME)
+/* putenv("A=") or putenv("A") removes A from the environment. */
+static int kwsysUnPutEnv(const char* env)
+{
+ int err = 0;
+ const char* eq = strchr(env, '=');
+ size_t const len = eq? (size_t)(eq-env) : strlen(env);
+# ifdef KWSYS_PUTENV_EMPTY
+ size_t const sz = len + 2;
+# else
+ size_t const sz = len + 1;
+# endif
+ char local_buf[256];
+ char* buf = sz > sizeof(local_buf) ? (char*)malloc(sz) : local_buf;
+ if(!buf)
+ {
+ return -1;
+ }
+ strncpy(buf, env, len);
+# ifdef KWSYS_PUTENV_EMPTY
+ buf[len] = '=';
+ buf[len+1] = 0;
+ if(putenv(buf) < 0)
+ {
+ err = errno;
+ }
+# else
+ buf[len] = 0;
+ if(putenv(buf) < 0 && errno != EINVAL)
+ {
+ err = errno;
+ }
+# endif
+ if(buf != local_buf)
+ {
+ free(buf);
+ }
+ if(err)
+ {
+ errno = err;
+ return -1;
+ }
+ return 0;
+}
+
+#else
+/* Manipulate the "environ" global directly. */
+static int kwsysUnPutEnv(const char* env)
+{
+ const char* eq = strchr(env, '=');
+ size_t const len = eq? (size_t)(eq-env) : strlen(env);
+ int in = 0;
+ int out = 0;
+ while(environ[in])
+ {
+ if(strlen(environ[in]) > len &&
+ environ[in][len] == '=' &&
+ strncmp(env, environ[in], len) == 0)
+ {
+ ++in;
+ }
+ else
+ {
+ environ[out++] = environ[in++];
+ }
+ }
+ while(out < in)
+ {
+ environ[out++] = 0;
+ }
+ return 0;
+}
+#endif
+
+//----------------------------------------------------------------------------
+
+#if KWSYS_CXX_HAS_SETENV
+
+/* setenv("A", "B", 1) will set A=B in the environment and makes its
+ own copies of the strings. */
+bool SystemTools::PutEnv(const char* env)
+{
+ if(const char* eq = strchr(env, '='))
+ {
+ std::string name(env, eq-env);
+ return setenv(name.c_str(), eq+1, 1) == 0;
+ }
+ else
+ {
+ return kwsysUnPutEnv(env) == 0;
+ }
+}
+
+bool SystemTools::UnPutEnv(const char* env)
+{
+ return kwsysUnPutEnv(env) == 0;
+}
+
+#else
+
+/* putenv("A=B") will set A=B in the environment. Most putenv implementations
+ put their argument directly in the environment. They never free the memory
+ on program exit. Keep an active set of pointers to memory we allocate and
+ pass to putenv, one per environment key. At program exit remove any
+ environment values that may still reference memory we allocated. Then free
+ the memory. This will not affect any environment values we never set. */
+
+# ifdef __INTEL_COMPILER
+# pragma warning disable 444 /* base has non-virtual destructor */
+# endif
+
+/* Order by environment key only (VAR from VAR=VALUE). */
+struct kwsysEnvCompare
+{
+ bool operator() (const char* l, const char* r) const
+ {
+ const char* leq = strchr(l, '=');
+ const char* req = strchr(r, '=');
+ size_t llen = leq? (leq-l) : strlen(l);
+ size_t rlen = req? (req-r) : strlen(r);
+ if(llen == rlen)
+ {
+ return strncmp(l,r,llen) < 0;
+ }
+ else
+ {
+ return strcmp(l,r) < 0;
+ }
+ }
+};
+
+class kwsysEnv: public kwsys_stl::set<const char*, kwsysEnvCompare>
+{
+ class Free
+ {
+ const char* Env;
+ public:
+ Free(const char* env): Env(env) {}
+ ~Free() { free(const_cast<char*>(this->Env)); }
+ };
+public:
+ typedef kwsys_stl::set<const char*, kwsysEnvCompare> derived;
+ ~kwsysEnv()
+ {
+ for(derived::iterator i = this->begin(); i != this->end(); ++i)
+ {
+ kwsysUnPutEnv(*i);
+ free(const_cast<char*>(*i));
+ }
+ }
+ const char* Release(const char* env)
+ {
+ const char* old = 0;
+ derived::iterator i = this->find(env);
+ if(i != this->end())
+ {
+ old = *i;
+ this->erase(i);
+ }
+ return old;
+ }
+ bool Put(const char* env)
+ {
+ Free oldEnv(this->Release(env));
+ static_cast<void>(oldEnv);
+ char* newEnv = strdup(env);
+ this->insert(newEnv);
+ return putenv(newEnv) == 0;
+ }
+ bool UnPut(const char* env)
+ {
+ Free oldEnv(this->Release(env));
+ static_cast<void>(oldEnv);
+ return kwsysUnPutEnv(env) == 0;
+ }
+};
+
+static kwsysEnv kwsysEnvInstance;
+
+bool SystemTools::PutEnv(const char* env)
+{
+ return kwsysEnvInstance.Put(env);
+}
+
+bool SystemTools::UnPutEnv(const char* env)
+{
+ return kwsysEnvInstance.UnPut(env);
+}
+
+#endif
+
+//----------------------------------------------------------------------------
+
+const char* SystemTools::GetExecutableExtension()
+{
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(__VMS)
+ return ".exe";
+#else
+ return "";
+#endif
+}
+
+FILE* SystemTools::Fopen(const kwsys_stl::string& file, const char* mode)
+{
+#ifdef _WIN32
+ return _wfopen(SystemTools::ConvertToWindowsExtendedPath(file).c_str(),
+ Encoding::ToWide(mode).c_str());
+#else
+ return fopen(file.c_str(), mode);
+#endif
+}
+
+bool SystemTools::MakeDirectory(const char* path)
+{
+ if(!path)
+ {
+ return false;
+ }
+ return SystemTools::MakeDirectory(kwsys_stl::string(path));
+}
+
+bool SystemTools::MakeDirectory(const kwsys_stl::string& path)
+{
+ if(SystemTools::FileExists(path))
+ {
+ return SystemTools::FileIsDirectory(path);
+ }
+ if(path.empty())
+ {
+ return false;
+ }
+ kwsys_stl::string dir = path;
+ SystemTools::ConvertToUnixSlashes(dir);
+
+ kwsys_stl::string::size_type pos = 0;
+ kwsys_stl::string topdir;
+ while((pos = dir.find('/', pos)) != kwsys_stl::string::npos)
+ {
+ topdir = dir.substr(0, pos);
+ Mkdir(topdir);
+ pos++;
+ }
+ topdir = dir;
+ if(Mkdir(topdir) != 0)
+ {
+ // There is a bug in the Borland Run time library which makes MKDIR
+ // return EACCES when it should return EEXISTS
+ // if it is some other error besides directory exists
+ // then return false
+ if( (errno != EEXIST)
+#ifdef __BORLANDC__
+ && (errno != EACCES)
+#endif
+ )
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+// replace replace with with as many times as it shows up in source.
+// write the result into source.
+void SystemTools::ReplaceString(kwsys_stl::string& source,
+ const char* replace,
+ const char* with)
+{
+ const char *src = source.c_str();
+ char *searchPos = const_cast<char *>(strstr(src,replace));
+
+ // get out quick if string is not found
+ if (!searchPos)
+ {
+ return;
+ }
+
+ // perform replacements until done
+ size_t replaceSize = strlen(replace);
+ // do while hangs if replaceSize is 0
+ if(replaceSize == 0)
+ {
+ return;
+ }
+ char *orig = strdup(src);
+ char *currentPos = orig;
+ searchPos = searchPos - src + orig;
+
+ // initialize the result
+ source.erase(source.begin(),source.end());
+ do
+ {
+ *searchPos = '\0';
+ source += currentPos;
+ currentPos = searchPos + replaceSize;
+ // replace
+ source += with;
+ searchPos = strstr(currentPos,replace);
+ }
+ while (searchPos);
+
+ // copy any trailing text
+ source += currentPos;
+ free(orig);
+}
+
+#if defined(KEY_WOW64_32KEY) && defined(KEY_WOW64_64KEY)
+# define KWSYS_ST_KEY_WOW64_32KEY KEY_WOW64_32KEY
+# define KWSYS_ST_KEY_WOW64_64KEY KEY_WOW64_64KEY
+#else
+# define KWSYS_ST_KEY_WOW64_32KEY 0x0200
+# define KWSYS_ST_KEY_WOW64_64KEY 0x0100
+#endif
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+static bool SystemToolsParseRegistryKey(const char* key,
+ HKEY& primaryKey,
+ kwsys_stl::string& second,
+ kwsys_stl::string& valuename)
+{
+ kwsys_stl::string primary = key;
+
+ size_t start = primary.find("\\");
+ if (start == kwsys_stl::string::npos)
+ {
+ return false;
+ }
+
+ size_t valuenamepos = primary.find(";");
+ if (valuenamepos != kwsys_stl::string::npos)
+ {
+ valuename = primary.substr(valuenamepos+1);
+ }
+
+ second = primary.substr(start+1, valuenamepos-start-1);
+ primary = primary.substr(0, start);
+
+ if (primary == "HKEY_CURRENT_USER")
+ {
+ primaryKey = HKEY_CURRENT_USER;
+ }
+ if (primary == "HKEY_CURRENT_CONFIG")
+ {
+ primaryKey = HKEY_CURRENT_CONFIG;
+ }
+ if (primary == "HKEY_CLASSES_ROOT")
+ {
+ primaryKey = HKEY_CLASSES_ROOT;
+ }
+ if (primary == "HKEY_LOCAL_MACHINE")
+ {
+ primaryKey = HKEY_LOCAL_MACHINE;
+ }
+ if (primary == "HKEY_USERS")
+ {
+ primaryKey = HKEY_USERS;
+ }
+
+ return true;
+}
+
+static DWORD SystemToolsMakeRegistryMode(DWORD mode,
+ SystemTools::KeyWOW64 view)
+{
+ // only add the modes when on a system that supports Wow64.
+ static FARPROC wow64p = GetProcAddress(GetModuleHandleW(L"kernel32"),
+ "IsWow64Process");
+ if(wow64p == NULL)
+ {
+ return mode;
+ }
+
+ if(view == SystemTools::KeyWOW64_32)
+ {
+ return mode | KWSYS_ST_KEY_WOW64_32KEY;
+ }
+ else if(view == SystemTools::KeyWOW64_64)
+ {
+ return mode | KWSYS_ST_KEY_WOW64_64KEY;
+ }
+ return mode;
+}
+#endif
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+bool
+SystemTools::GetRegistrySubKeys(const char *key,
+ kwsys_stl::vector<kwsys_stl::string>& subkeys,
+ KeyWOW64 view)
+{
+ HKEY primaryKey = HKEY_CURRENT_USER;
+ kwsys_stl::string second;
+ kwsys_stl::string valuename;
+ if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename))
+ {
+ return false;
+ }
+
+ HKEY hKey;
+ if(RegOpenKeyExW(primaryKey,
+ Encoding::ToWide(second).c_str(),
+ 0,
+ SystemToolsMakeRegistryMode(KEY_READ, view),
+ &hKey) != ERROR_SUCCESS)
+ {
+ return false;
+ }
+ else
+ {
+ wchar_t name[1024];
+ DWORD dwNameSize = sizeof(name)/sizeof(name[0]);
+
+ DWORD i = 0;
+ while (RegEnumKeyW(hKey, i, name, dwNameSize) == ERROR_SUCCESS)
+ {
+ subkeys.push_back(Encoding::ToNarrow(name));
+ ++i;
+ }
+
+ RegCloseKey(hKey);
+ }
+
+ return true;
+}
+#else
+bool SystemTools::GetRegistrySubKeys(const char *,
+ kwsys_stl::vector<kwsys_stl::string>&,
+ KeyWOW64)
+{
+ return false;
+}
+#endif
+
+// Read a registry value.
+// Example :
+// HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath
+// => will return the data of the "default" value of the key
+// HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root
+// => will return the data of the "Root" value of the key
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+bool SystemTools::ReadRegistryValue(const char *key, kwsys_stl::string &value,
+ KeyWOW64 view)
+{
+ bool valueset = false;
+ HKEY primaryKey = HKEY_CURRENT_USER;
+ kwsys_stl::string second;
+ kwsys_stl::string valuename;
+ if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename))
+ {
+ return false;
+ }
+
+ HKEY hKey;
+ if(RegOpenKeyExW(primaryKey,
+ Encoding::ToWide(second).c_str(),
+ 0,
+ SystemToolsMakeRegistryMode(KEY_READ, view),
+ &hKey) != ERROR_SUCCESS)
+ {
+ return false;
+ }
+ else
+ {
+ DWORD dwType, dwSize;
+ dwSize = 1023;
+ wchar_t data[1024];
+ if(RegQueryValueExW(hKey,
+ Encoding::ToWide(valuename).c_str(),
+ NULL,
+ &dwType,
+ (BYTE *)data,
+ &dwSize) == ERROR_SUCCESS)
+ {
+ if (dwType == REG_SZ)
+ {
+ value = Encoding::ToNarrow(data);
+ valueset = true;
+ }
+ else if (dwType == REG_EXPAND_SZ)
+ {
+ wchar_t expanded[1024];
+ DWORD dwExpandedSize = sizeof(expanded)/sizeof(expanded[0]);
+ if(ExpandEnvironmentStringsW(data, expanded,
+ dwExpandedSize))
+ {
+ value = Encoding::ToNarrow(expanded);
+ valueset = true;
+ }
+ }
+ }
+
+ RegCloseKey(hKey);
+ }
+
+ return valueset;
+}
+#else
+bool SystemTools::ReadRegistryValue(const char *, kwsys_stl::string &,
+ KeyWOW64)
+{
+ return false;
+}
+#endif
+
+
+// Write a registry value.
+// Example :
+// HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath
+// => will set the data of the "default" value of the key
+// HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root
+// => will set the data of the "Root" value of the key
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+bool SystemTools::WriteRegistryValue(const char *key, const char *value,
+ KeyWOW64 view)
+{
+ HKEY primaryKey = HKEY_CURRENT_USER;
+ kwsys_stl::string second;
+ kwsys_stl::string valuename;
+ if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename))
+ {
+ return false;
+ }
+
+ HKEY hKey;
+ DWORD dwDummy;
+ wchar_t lpClass[] = L"";
+ if(RegCreateKeyExW(primaryKey,
+ Encoding::ToWide(second).c_str(),
+ 0,
+ lpClass,
+ REG_OPTION_NON_VOLATILE,
+ SystemToolsMakeRegistryMode(KEY_WRITE, view),
+ NULL,
+ &hKey,
+ &dwDummy) != ERROR_SUCCESS)
+ {
+ return false;
+ }
+
+ std::wstring wvalue = Encoding::ToWide(value);
+ if(RegSetValueExW(hKey,
+ Encoding::ToWide(valuename).c_str(),
+ 0,
+ REG_SZ,
+ (CONST BYTE *)wvalue.c_str(),
+ (DWORD)(sizeof(wchar_t) * (wvalue.size() + 1))) == ERROR_SUCCESS)
+ {
+ return true;
+ }
+ return false;
+}
+#else
+bool SystemTools::WriteRegistryValue(const char *, const char *, KeyWOW64)
+{
+ return false;
+}
+#endif
+
+// Delete a registry value.
+// Example :
+// HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath
+// => will delete the data of the "default" value of the key
+// HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root
+// => will delete the data of the "Root" value of the key
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+bool SystemTools::DeleteRegistryValue(const char *key, KeyWOW64 view)
+{
+ HKEY primaryKey = HKEY_CURRENT_USER;
+ kwsys_stl::string second;
+ kwsys_stl::string valuename;
+ if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename))
+ {
+ return false;
+ }
+
+ HKEY hKey;
+ if(RegOpenKeyExW(primaryKey,
+ Encoding::ToWide(second).c_str(),
+ 0,
+ SystemToolsMakeRegistryMode(KEY_WRITE, view),
+ &hKey) != ERROR_SUCCESS)
+ {
+ return false;
+ }
+ else
+ {
+ if(RegDeleteValue(hKey,
+ (LPTSTR)valuename.c_str()) == ERROR_SUCCESS)
+ {
+ RegCloseKey(hKey);
+ return true;
+ }
+ }
+ return false;
+}
+#else
+bool SystemTools::DeleteRegistryValue(const char *, KeyWOW64)
+{
+ return false;
+}
+#endif
+
+bool SystemTools::SameFile(const kwsys_stl::string& file1, const kwsys_stl::string& file2)
+{
+#ifdef _WIN32
+ HANDLE hFile1, hFile2;
+
+ hFile1 = CreateFileW( Encoding::ToWide(file1).c_str(),
+ GENERIC_READ,
+ FILE_SHARE_READ ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS,
+ NULL
+ );
+ hFile2 = CreateFileW( Encoding::ToWide(file2).c_str(),
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS,
+ NULL
+ );
+ if( hFile1 == INVALID_HANDLE_VALUE || hFile2 == INVALID_HANDLE_VALUE)
+ {
+ if(hFile1 != INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(hFile1);
+ }
+ if(hFile2 != INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(hFile2);
+ }
+ return false;
+ }
+
+ BY_HANDLE_FILE_INFORMATION fiBuf1;
+ BY_HANDLE_FILE_INFORMATION fiBuf2;
+ GetFileInformationByHandle( hFile1, &fiBuf1 );
+ GetFileInformationByHandle( hFile2, &fiBuf2 );
+ CloseHandle(hFile1);
+ CloseHandle(hFile2);
+ return (fiBuf1.dwVolumeSerialNumber == fiBuf2.dwVolumeSerialNumber &&
+ fiBuf1.nFileIndexHigh == fiBuf2.nFileIndexHigh &&
+ fiBuf1.nFileIndexLow == fiBuf2.nFileIndexLow);
+#else
+ struct stat fileStat1, fileStat2;
+ if (stat(file1.c_str(), &fileStat1) == 0 && stat(file2.c_str(), &fileStat2) == 0)
+ {
+ // see if the files are the same file
+ // check the device inode and size
+ if(memcmp(&fileStat2.st_dev, &fileStat1.st_dev, sizeof(fileStat1.st_dev)) == 0 &&
+ memcmp(&fileStat2.st_ino, &fileStat1.st_ino, sizeof(fileStat1.st_ino)) == 0 &&
+ fileStat2.st_size == fileStat1.st_size
+ )
+ {
+ return true;
+ }
+ }
+ return false;
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool SystemTools::FileExists(const char* filename)
+{
+ if(!filename)
+ {
+ return false;
+ }
+ return SystemTools::FileExists(kwsys_stl::string(filename));
+}
+
+//----------------------------------------------------------------------------
+bool SystemTools::FileExists(const kwsys_stl::string& filename)
+{
+ if(filename.empty())
+ {
+ return false;
+ }
+#if defined(__CYGWIN__)
+ // Convert filename to native windows path if possible.
+ char winpath[MAX_PATH];
+ if(SystemTools::PathCygwinToWin32(filename.c_str(), winpath))
+ {
+ return (GetFileAttributesA(winpath) != INVALID_FILE_ATTRIBUTES);
+ }
+ return access(filename.c_str(), R_OK) == 0;
+#elif defined(_WIN32)
+ return (GetFileAttributesW(
+ SystemTools::ConvertToWindowsExtendedPath(filename).c_str())
+ != INVALID_FILE_ATTRIBUTES);
+#else
+ return access(filename.c_str(), R_OK) == 0;
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool SystemTools::FileExists(const char* filename, bool isFile)
+{
+ if(SystemTools::FileExists(filename))
+ {
+ // If isFile is set return not FileIsDirectory,
+ // so this will only be true if it is a file
+ return !isFile || !SystemTools::FileIsDirectory(filename);
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool SystemTools::FileExists(const kwsys_stl::string& filename, bool isFile)
+{
+ if(SystemTools::FileExists(filename))
+ {
+ // If isFile is set return not FileIsDirectory,
+ // so this will only be true if it is a file
+ return !isFile || !SystemTools::FileIsDirectory(filename);
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+#ifdef __CYGWIN__
+bool SystemTools::PathCygwinToWin32(const char *path, char *win32_path)
+{
+ SystemToolsTranslationMap::iterator i =
+ SystemTools::Cyg2Win32Map->find(path);
+
+ if (i != SystemTools::Cyg2Win32Map->end())
+ {
+ strncpy(win32_path, i->second.c_str(), MAX_PATH);
+ }
+ else
+ {
+ if(cygwin_conv_path(CCP_POSIX_TO_WIN_A, path, win32_path, MAX_PATH) != 0)
+ {
+ win32_path[0] = 0;
+ }
+ SystemToolsTranslationMap::value_type entry(path, win32_path);
+ SystemTools::Cyg2Win32Map->insert(entry);
+ }
+ return win32_path[0] != 0;
+}
+#endif
+
+bool SystemTools::Touch(const kwsys_stl::string& filename, bool create)
+{
+ if(create && !SystemTools::FileExists(filename))
+ {
+ FILE* file = Fopen(filename, "a+b");
+ if(file)
+ {
+ fclose(file);
+ return true;
+ }
+ return false;
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ HANDLE h = CreateFileW(
+ SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
+ FILE_WRITE_ATTRIBUTES,
+ FILE_SHARE_WRITE, 0, OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS, 0);
+ if(!h)
+ {
+ return false;
+ }
+ FILETIME mtime;
+ GetSystemTimeAsFileTime(&mtime);
+ if(!SetFileTime(h, 0, 0, &mtime))
+ {
+ CloseHandle(h);
+ return false;
+ }
+ CloseHandle(h);
+#elif KWSYS_CXX_HAS_UTIMENSAT
+ struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}};
+ if(utimensat(AT_FDCWD, filename.c_str(), times, 0) < 0)
+ {
+ return false;
+ }
+#else
+ struct stat st;
+ if(stat(filename.c_str(), &st) < 0)
+ {
+ return false;
+ }
+ 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 */
+# else
+ {st.st_atime, 0},
+# endif
+ mtime
+ };
+ if(utimes(filename.c_str(), times) < 0)
+ {
+ return false;
+ }
+# else
+ struct utimbuf times = {st.st_atime, mtime.tv_sec};
+ if(utime(filename.c_str(), &times) < 0)
+ {
+ return false;
+ }
+# endif
+#endif
+ return true;
+}
+
+bool SystemTools::FileTimeCompare(const kwsys_stl::string& f1,
+ const kwsys_stl::string& f2,
+ int* result)
+{
+ // Default to same time.
+ *result = 0;
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ // POSIX version. Use stat function to get file modification time.
+ struct stat s1;
+ if(stat(f1.c_str(), &s1) != 0)
+ {
+ return false;
+ }
+ struct stat s2;
+ if(stat(f2.c_str(), &s2) != 0)
+ {
+ return false;
+ }
+# if KWSYS_STAT_HAS_ST_MTIM
+ // Compare using nanosecond resolution.
+ if(s1.st_mtim.tv_sec < s2.st_mtim.tv_sec)
+ {
+ *result = -1;
+ }
+ else if(s1.st_mtim.tv_sec > s2.st_mtim.tv_sec)
+ {
+ *result = 1;
+ }
+ else if(s1.st_mtim.tv_nsec < s2.st_mtim.tv_nsec)
+ {
+ *result = -1;
+ }
+ else if(s1.st_mtim.tv_nsec > s2.st_mtim.tv_nsec)
+ {
+ *result = 1;
+ }
+# else
+ // Compare using 1 second resolution.
+ if(s1.st_mtime < s2.st_mtime)
+ {
+ *result = -1;
+ }
+ else if(s1.st_mtime > s2.st_mtime)
+ {
+ *result = 1;
+ }
+# endif
+#else
+ // Windows version. Get the modification time from extended file attributes.
+ WIN32_FILE_ATTRIBUTE_DATA f1d;
+ WIN32_FILE_ATTRIBUTE_DATA f2d;
+ if(!GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(f1).c_str(),
+ GetFileExInfoStandard, &f1d))
+ {
+ return false;
+ }
+ if(!GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(f2).c_str(),
+ GetFileExInfoStandard, &f2d))
+ {
+ return false;
+ }
+
+ // Compare the file times using resolution provided by system call.
+ *result = (int)CompareFileTime(&f1d.ftLastWriteTime, &f2d.ftLastWriteTime);
+#endif
+ return true;
+}
+
+
+// Return a capitalized string (i.e the first letter is uppercased, all other
+// are lowercased)
+kwsys_stl::string SystemTools::Capitalized(const kwsys_stl::string& s)
+{
+ kwsys_stl::string n;
+ if(s.empty())
+ {
+ return n;
+ }
+ n.resize(s.size());
+ n[0] = static_cast<kwsys_stl::string::value_type>(toupper(s[0]));
+ for (size_t i = 1; i < s.size(); i++)
+ {
+ n[i] = static_cast<kwsys_stl::string::value_type>(tolower(s[i]));
+ }
+ return n;
+}
+
+// Return capitalized words
+kwsys_stl::string SystemTools::CapitalizedWords(const kwsys_stl::string& s)
+{
+ kwsys_stl::string n(s);
+ for (size_t i = 0; i < s.size(); i++)
+ {
+#if defined(_MSC_VER) && defined (_MT) && defined (_DEBUG)
+ // MS has an assert that will fail if s[i] < 0; setting
+ // LC_CTYPE using setlocale() does *not* help. Painful.
+ if ((int)s[i] >= 0 && isalpha(s[i]) &&
+ (i == 0 || ((int)s[i - 1] >= 0 && isspace(s[i - 1]))))
+#else
+ if (isalpha(s[i]) && (i == 0 || isspace(s[i - 1])))
+#endif
+ {
+ n[i] = static_cast<kwsys_stl::string::value_type>(toupper(s[i]));
+ }
+ }
+ return n;
+}
+
+// Return uncapitalized words
+kwsys_stl::string SystemTools::UnCapitalizedWords(const kwsys_stl::string& s)
+{
+ kwsys_stl::string n(s);
+ for (size_t i = 0; i < s.size(); i++)
+ {
+#if defined(_MSC_VER) && defined (_MT) && defined (_DEBUG)
+ // MS has an assert that will fail if s[i] < 0; setting
+ // LC_CTYPE using setlocale() does *not* help. Painful.
+ if ((int)s[i] >= 0 && isalpha(s[i]) &&
+ (i == 0 || ((int)s[i - 1] >= 0 && isspace(s[i - 1]))))
+#else
+ if (isalpha(s[i]) && (i == 0 || isspace(s[i - 1])))
+#endif
+ {
+ n[i] = static_cast<kwsys_stl::string::value_type>(tolower(s[i]));
+ }
+ }
+ return n;
+}
+
+// only works for words with at least two letters
+kwsys_stl::string SystemTools::AddSpaceBetweenCapitalizedWords(
+ const kwsys_stl::string& s)
+{
+ kwsys_stl::string n;
+ if (!s.empty())
+ {
+ n.reserve(s.size());
+ n += s[0];
+ for (size_t i = 1; i < s.size(); i++)
+ {
+ if (isupper(s[i]) && !isspace(s[i - 1]) && !isupper(s[i - 1]))
+ {
+ n += ' ';
+ }
+ n += s[i];
+ }
+ }
+ return n;
+}
+
+char* SystemTools::AppendStrings(const char* str1, const char* str2)
+{
+ if (!str1)
+ {
+ return SystemTools::DuplicateString(str2);
+ }
+ if (!str2)
+ {
+ return SystemTools::DuplicateString(str1);
+ }
+ size_t len1 = strlen(str1);
+ char *newstr = new char[len1 + strlen(str2) + 1];
+ if (!newstr)
+ {
+ return 0;
+ }
+ strcpy(newstr, str1);
+ strcat(newstr + len1, str2);
+ return newstr;
+}
+
+char* SystemTools::AppendStrings(
+ const char* str1, const char* str2, const char* str3)
+{
+ if (!str1)
+ {
+ return SystemTools::AppendStrings(str2, str3);
+ }
+ if (!str2)
+ {
+ return SystemTools::AppendStrings(str1, str3);
+ }
+ if (!str3)
+ {
+ return SystemTools::AppendStrings(str1, str2);
+ }
+
+ size_t len1 = strlen(str1), len2 = strlen(str2);
+ char *newstr = new char[len1 + len2 + strlen(str3) + 1];
+ if (!newstr)
+ {
+ return 0;
+ }
+ strcpy(newstr, str1);
+ strcat(newstr + len1, str2);
+ strcat(newstr + len1 + len2, str3);
+ return newstr;
+}
+
+// Return a lower case string
+kwsys_stl::string SystemTools::LowerCase(const kwsys_stl::string& s)
+{
+ kwsys_stl::string n;
+ n.resize(s.size());
+ for (size_t i = 0; i < s.size(); i++)
+ {
+ n[i] = static_cast<kwsys_stl::string::value_type>(tolower(s[i]));
+ }
+ return n;
+}
+
+// Return a lower case string
+kwsys_stl::string SystemTools::UpperCase(const kwsys_stl::string& s)
+{
+ kwsys_stl::string n;
+ n.resize(s.size());
+ for (size_t i = 0; i < s.size(); i++)
+ {
+ n[i] = static_cast<kwsys_stl::string::value_type>(toupper(s[i]));
+ }
+ return n;
+}
+
+// Count char in string
+size_t SystemTools::CountChar(const char* str, char c)
+{
+ size_t count = 0;
+
+ if (str)
+ {
+ while (*str)
+ {
+ if (*str == c)
+ {
+ ++count;
+ }
+ ++str;
+ }
+ }
+ return count;
+}
+
+// Remove chars in string
+char* SystemTools::RemoveChars(const char* str, const char *toremove)
+{
+ if (!str)
+ {
+ return NULL;
+ }
+ char *clean_str = new char [strlen(str) + 1];
+ char *ptr = clean_str;
+ while (*str)
+ {
+ const char *str2 = toremove;
+ while (*str2 && *str != *str2)
+ {
+ ++str2;
+ }
+ if (!*str2)
+ {
+ *ptr++ = *str;
+ }
+ ++str;
+ }
+ *ptr = '\0';
+ return clean_str;
+}
+
+// Remove chars in string
+char* SystemTools::RemoveCharsButUpperHex(const char* str)
+{
+ if (!str)
+ {
+ return 0;
+ }
+ char *clean_str = new char [strlen(str) + 1];
+ char *ptr = clean_str;
+ while (*str)
+ {
+ if ((*str >= '0' && *str <= '9') || (*str >= 'A' && *str <= 'F'))
+ {
+ *ptr++ = *str;
+ }
+ ++str;
+ }
+ *ptr = '\0';
+ return clean_str;
+}
+
+// Replace chars in string
+char* SystemTools::ReplaceChars(char* str, const char *toreplace, char replacement)
+{
+ if (str)
+ {
+ char *ptr = str;
+ while (*ptr)
+ {
+ const char *ptr2 = toreplace;
+ while (*ptr2)
+ {
+ if (*ptr == *ptr2)
+ {
+ *ptr = replacement;
+ }
+ ++ptr2;
+ }
+ ++ptr;
+ }
+ }
+ return str;
+}
+
+// Returns if string starts with another string
+bool SystemTools::StringStartsWith(const char* str1, const char* str2)
+{
+ if (!str1 || !str2)
+ {
+ return false;
+ }
+ size_t len1 = strlen(str1), len2 = strlen(str2);
+ return len1 >= len2 && !strncmp(str1, str2, len2) ? true : false;
+}
+
+// Returns if string starts with another string
+bool SystemTools::StringStartsWith(const kwsys_stl::string& str1, const char* str2)
+{
+ if (!str2)
+ {
+ return false;
+ }
+ size_t len1 = str1.size(), len2 = strlen(str2);
+ return len1 >= len2 && !strncmp(str1.c_str(), str2, len2) ? true : false;
+}
+
+// Returns if string ends with another string
+bool SystemTools::StringEndsWith(const char* str1, const char* str2)
+{
+ if (!str1 || !str2)
+ {
+ return false;
+ }
+ size_t len1 = strlen(str1), len2 = strlen(str2);
+ return len1 >= len2 && !strncmp(str1 + (len1 - len2), str2, len2) ? true : false;
+}
+
+// Returns if string ends with another string
+bool SystemTools::StringEndsWith(const kwsys_stl::string& str1, const char* str2)
+{
+ if (!str2)
+ {
+ return false;
+ }
+ size_t len1 = str1.size(), len2 = strlen(str2);
+ return len1 >= len2 && !strncmp(str1.c_str() + (len1 - len2), str2, len2) ? true : false;
+}
+
+// Returns a pointer to the last occurence of str2 in str1
+const char* SystemTools::FindLastString(const char* str1, const char* str2)
+{
+ if (!str1 || !str2)
+ {
+ return NULL;
+ }
+
+ size_t len1 = strlen(str1), len2 = strlen(str2);
+ if (len1 >= len2)
+ {
+ const char *ptr = str1 + len1 - len2;
+ do
+ {
+ if (!strncmp(ptr, str2, len2))
+ {
+ return ptr;
+ }
+ } while (ptr-- != str1);
+ }
+
+ return NULL;
+}
+
+// Duplicate string
+char* SystemTools::DuplicateString(const char* str)
+{
+ if (str)
+ {
+ char *newstr = new char [strlen(str) + 1];
+ return strcpy(newstr, str);
+ }
+ return NULL;
+}
+
+// Return a cropped string
+kwsys_stl::string SystemTools::CropString(const kwsys_stl::string& s,
+ size_t max_len)
+{
+ if (!s.size() || max_len == 0 || max_len >= s.size())
+ {
+ return s;
+ }
+
+ kwsys_stl::string n;
+ n.reserve(max_len);
+
+ size_t middle = max_len / 2;
+
+ n += s.substr(0, middle);
+ n += s.substr(s.size() - (max_len - middle), kwsys_stl::string::npos);
+
+ if (max_len > 2)
+ {
+ n[middle] = '.';
+ if (max_len > 3)
+ {
+ n[middle - 1] = '.';
+ if (max_len > 4)
+ {
+ n[middle + 1] = '.';
+ }
+ }
+ }
+
+ return n;
+}
+
+//----------------------------------------------------------------------------
+kwsys_stl::vector<kwsys::String> SystemTools::SplitString(const kwsys_stl::string& p, char sep, bool isPath)
+{
+ kwsys_stl::string path = p;
+ kwsys_stl::vector<kwsys::String> paths;
+ if(path.empty())
+ {
+ return paths;
+ }
+ if(isPath && path[0] == '/')
+ {
+ path.erase(path.begin());
+ paths.push_back("/");
+ }
+ kwsys_stl::string::size_type pos1 = 0;
+ kwsys_stl::string::size_type pos2 = path.find(sep, pos1+1);
+ while(pos2 != kwsys_stl::string::npos)
+ {
+ paths.push_back(path.substr(pos1, pos2-pos1));
+ pos1 = pos2+1;
+ pos2 = path.find(sep, pos1+1);
+ }
+ paths.push_back(path.substr(pos1, pos2-pos1));
+
+ return paths;
+}
+
+//----------------------------------------------------------------------------
+int SystemTools::EstimateFormatLength(const char *format, va_list ap)
+{
+ if (!format)
+ {
+ return 0;
+ }
+
+ // Quick-hack attempt at estimating the length of the string.
+ // Should never under-estimate.
+
+ // Start with the length of the format string itself.
+
+ size_t length = strlen(format);
+
+ // Increase the length for every argument in the format.
+
+ const char* cur = format;
+ while(*cur)
+ {
+ if(*cur++ == '%')
+ {
+ // Skip "%%" since it doesn't correspond to a va_arg.
+ if(*cur != '%')
+ {
+ while(!int(isalpha(*cur)))
+ {
+ ++cur;
+ }
+ switch (*cur)
+ {
+ case 's':
+ {
+ // Check the length of the string.
+ char* s = va_arg(ap, char*);
+ if(s)
+ {
+ length += strlen(s);
+ }
+ } break;
+ case 'e':
+ case 'f':
+ case 'g':
+ {
+ // Assume the argument contributes no more than 64 characters.
+ length += 64;
+
+ // Eat the argument.
+ static_cast<void>(va_arg(ap, double));
+ } break;
+ default:
+ {
+ // Assume the argument contributes no more than 64 characters.
+ length += 64;
+
+ // Eat the argument.
+ static_cast<void>(va_arg(ap, int));
+ } break;
+ }
+ }
+
+ // Move past the characters just tested.
+ ++cur;
+ }
+ }
+
+ return static_cast<int>(length);
+}
+
+kwsys_stl::string SystemTools::EscapeChars(
+ const char *str,
+ const char *chars_to_escape,
+ char escape_char)
+{
+ kwsys_stl::string n;
+ if (str)
+ {
+ if (!chars_to_escape || !*chars_to_escape)
+ {
+ n.append(str);
+ }
+ else
+ {
+ n.reserve(strlen(str));
+ while (*str)
+ {
+ const char *ptr = chars_to_escape;
+ while (*ptr)
+ {
+ if (*str == *ptr)
+ {
+ n += escape_char;
+ break;
+ }
+ ++ptr;
+ }
+ n += *str;
+ ++str;
+ }
+ }
+ }
+ return n;
+}
+
+#ifdef __VMS
+static void ConvertVMSToUnix(kwsys_stl::string& path)
+{
+ kwsys_stl::string::size_type rootEnd = path.find(":[");
+ kwsys_stl::string::size_type pathEnd = path.find("]");
+ if(rootEnd != path.npos)
+ {
+ kwsys_stl::string root = path.substr(0, rootEnd);
+ kwsys_stl::string pathPart = path.substr(rootEnd+2, pathEnd - rootEnd-2);
+ const char* pathCString = pathPart.c_str();
+ const char* pos0 = pathCString;
+ for (kwsys_stl::string::size_type pos = 0; *pos0; ++ pos )
+ {
+ if ( *pos0 == '.' )
+ {
+ pathPart[pos] = '/';
+ }
+ pos0 ++;
+ }
+ path = "/"+ root + "/" + pathPart;
+ }
+}
+#endif
+
+// convert windows slashes to unix slashes
+void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path)
+{
+ const char* pathCString = path.c_str();
+ bool hasDoubleSlash = false;
+#ifdef __VMS
+ ConvertVMSToUnix(path);
+#else
+ const char* pos0 = pathCString;
+ const char* pos1 = pathCString+1;
+ for (kwsys_stl::string::size_type pos = 0; *pos0; ++ pos )
+ {
+ // make sure we don't convert an escaped space to a unix slash
+ if ( *pos0 == '\\' && *pos1 != ' ' )
+ {
+ path[pos] = '/';
+ }
+
+ // Also, reuse the loop to check for slash followed by another slash
+ if (*pos1 == '/' && *(pos1+1) == '/' && !hasDoubleSlash)
+ {
+#ifdef _WIN32
+ // However, on windows if the first characters are both slashes,
+ // then keep them that way, so that network paths can be handled.
+ if ( pos > 0)
+ {
+ hasDoubleSlash = true;
+ }
+#else
+ hasDoubleSlash = true;
+#endif
+ }
+
+ pos0 ++;
+ pos1 ++;
+ }
+
+ if ( hasDoubleSlash )
+ {
+ SystemTools::ReplaceString(path, "//", "/");
+ }
+#endif
+ // remove any trailing slash
+ if(!path.empty())
+ {
+ // if there is a tilda ~ then replace it with HOME
+ pathCString = path.c_str();
+ if(pathCString[0] == '~' && (pathCString[1] == '/' || pathCString[1] == '\0'))
+ {
+ const char* homeEnv = SystemTools::GetEnv("HOME");
+ if (homeEnv)
+ {
+ path.replace(0,1,homeEnv);
+ }
+ }
+#ifdef HAVE_GETPWNAM
+ else if(pathCString[0] == '~')
+ {
+ kwsys_stl::string::size_type idx = path.find_first_of("/\0");
+ kwsys_stl::string user = path.substr(1, idx-1);
+ passwd* pw = getpwnam(user.c_str());
+ if(pw)
+ {
+ path.replace(0, idx, pw->pw_dir);
+ }
+ }
+#endif
+ // remove trailing slash if the path is more than
+ // a single /
+ pathCString = path.c_str();
+ size_t size = path.size();
+ if(size > 1 && *path.rbegin() == '/')
+ {
+ // if it is c:/ then do not remove the trailing slash
+ if(!((size == 3 && pathCString[1] == ':')))
+ {
+ path.resize(size - 1);
+ }
+ }
+ }
+}
+
+#ifdef _WIN32
+// Convert local paths to UNC style paths
+kwsys_stl::wstring
+SystemTools::ConvertToWindowsExtendedPath(const kwsys_stl::string &source)
+{
+ kwsys_stl::wstring wsource = Encoding::ToWide(source);
+
+ // Resolve any relative paths
+ DWORD wfull_len;
+
+ /* The +3 is a workaround for a bug in some versions of GetFullPathNameW that
+ * won't return a large enough buffer size if the input is too small */
+ wfull_len = GetFullPathNameW(wsource.c_str(), 0, NULL, NULL) + 3;
+ kwsys_stl::vector<wchar_t> wfull(wfull_len);
+ GetFullPathNameW(wsource.c_str(), wfull_len, &wfull[0], NULL);
+
+ /* This should get the correct size without any extra padding from the
+ * previous size workaround. */
+ wfull_len = static_cast<DWORD>(wcslen(&wfull[0]));
+
+ if(wfull_len >= 2 && isalpha(wfull[0]) && wfull[1] == L':')
+ { /* C:\Foo\bar\FooBar.txt */
+ return L"\\\\?\\" + kwsys_stl::wstring(&wfull[0]);
+ }
+ else if(wfull_len >= 2 && wfull[0] == L'\\' && wfull[1] == L'\\')
+ { /* Starts with \\ */
+ if(wfull_len >= 4 && wfull[2] == L'?' && wfull[3] == L'\\')
+ { /* Starts with \\?\ */
+ if(wfull_len >= 8 && wfull[4] == L'U' && wfull[5] == L'N' &&
+ wfull[6] == L'C' && wfull[7] == L'\\')
+ { /* \\?\UNC\Foo\bar\FooBar.txt */
+ return kwsys_stl::wstring(&wfull[0]);
+ }
+ else if(wfull_len >= 6 && isalpha(wfull[4]) && wfull[5] == L':')
+ { /* \\?\C:\Foo\bar\FooBar.txt */
+ return kwsys_stl::wstring(&wfull[0]);
+ }
+ else if(wfull_len >= 5)
+ { /* \\?\Foo\bar\FooBar.txt */
+ return L"\\\\?\\UNC\\" + kwsys_stl::wstring(&wfull[4]);
+ }
+ }
+ else if(wfull_len >= 4 && wfull[2] == L'.' && wfull[3] == L'\\')
+ { /* Starts with \\.\ a device name */
+ if(wfull_len >= 6 && isalpha(wfull[4]) && wfull[5] == L':')
+ { /* \\.\C:\Foo\bar\FooBar.txt */
+ return L"\\\\?\\" + kwsys_stl::wstring(&wfull[4]);
+ }
+ else if(wfull_len >= 5)
+ { /* \\.\Foo\bar\ Device name is left unchanged */
+ return kwsys_stl::wstring(&wfull[0]);
+ }
+ }
+ else if(wfull_len >= 3)
+ { /* \\Foo\bar\FooBar.txt */
+ return L"\\\\?\\UNC\\" + kwsys_stl::wstring(&wfull[2]);
+ }
+ }
+
+ // If this case has been reached, then the path is invalid. Leave it
+ // unchanged
+ return Encoding::ToWide(source);
+}
+#endif
+
+// change // to /, and escape any spaces in the path
+kwsys_stl::string SystemTools::ConvertToUnixOutputPath(const kwsys_stl::string& path)
+{
+ kwsys_stl::string ret = path;
+
+ // remove // except at the beginning might be a cygwin drive
+ kwsys_stl::string::size_type pos=1;
+ while((pos = ret.find("//", pos)) != kwsys_stl::string::npos)
+ {
+ ret.erase(pos, 1);
+ }
+ // escape spaces and () in the path
+ if(ret.find_first_of(" ") != kwsys_stl::string::npos)
+ {
+ kwsys_stl::string result = "";
+ char lastch = 1;
+ for(const char* ch = ret.c_str(); *ch != '\0'; ++ch)
+ {
+ // if it is already escaped then don't try to escape it again
+ if((*ch == ' ') && lastch != '\\')
+ {
+ result += '\\';
+ }
+ result += *ch;
+ lastch = *ch;
+ }
+ ret = result;
+ }
+ return ret;
+}
+
+kwsys_stl::string SystemTools::ConvertToOutputPath(const kwsys_stl::string& path)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ return SystemTools::ConvertToWindowsOutputPath(path);
+#else
+ return SystemTools::ConvertToUnixOutputPath(path);
+#endif
+}
+
+// remove double slashes not at the start
+kwsys_stl::string SystemTools::ConvertToWindowsOutputPath(const kwsys_stl::string& path)
+{
+ kwsys_stl::string ret;
+ // make it big enough for all of path and double quotes
+ ret.reserve(path.size()+3);
+ // put path into the string
+ ret = path;
+ kwsys_stl::string::size_type pos = 0;
+ // first convert all of the slashes
+ while((pos = ret.find('/', pos)) != kwsys_stl::string::npos)
+ {
+ ret[pos] = '\\';
+ pos++;
+ }
+ // check for really small paths
+ if(ret.size() < 2)
+ {
+ return ret;
+ }
+ // now clean up a bit and remove double slashes
+ // Only if it is not the first position in the path which is a network
+ // path on windows
+ pos = 1; // start at position 1
+ if(ret[0] == '\"')
+ {
+ pos = 2; // if the string is already quoted then start at 2
+ if(ret.size() < 3)
+ {
+ return ret;
+ }
+ }
+ while((pos = ret.find("\\\\", pos)) != kwsys_stl::string::npos)
+ {
+ ret.erase(pos, 1);
+ }
+ // now double quote the path if it has spaces in it
+ // and is not already double quoted
+ if(ret.find(' ') != kwsys_stl::string::npos
+ && ret[0] != '\"')
+ {
+ ret.insert(static_cast<kwsys_stl::string::size_type>(0),
+ static_cast<kwsys_stl::string::size_type>(1), '\"');
+ ret.append(1, '\"');
+ }
+ return ret;
+}
+
+bool SystemTools::CopyFileIfDifferent(const kwsys_stl::string& source,
+ const kwsys_stl::string& destination)
+{
+ // special check for a destination that is a directory
+ // FilesDiffer does not handle file to directory compare
+ if(SystemTools::FileIsDirectory(destination))
+ {
+ kwsys_stl::string new_destination = destination;
+ SystemTools::ConvertToUnixSlashes(new_destination);
+ new_destination += '/';
+ kwsys_stl::string source_name = source;
+ new_destination += SystemTools::GetFilenameName(source_name);
+ if(SystemTools::FilesDiffer(source, new_destination))
+ {
+ return SystemTools::CopyFileAlways(source, destination);
+ }
+ else
+ {
+ // the files are the same so the copy is done return
+ // true
+ return true;
+ }
+ }
+ // source and destination are files so do a copy if they
+ // are different
+ if(SystemTools::FilesDiffer(source, destination))
+ {
+ return SystemTools::CopyFileAlways(source, destination);
+ }
+ // at this point the files must be the same so return true
+ return true;
+}
+
+#define KWSYS_ST_BUFFER 4096
+
+bool SystemTools::FilesDiffer(const kwsys_stl::string& source,
+ const kwsys_stl::string& destination)
+{
+
+#if defined(_WIN32)
+ WIN32_FILE_ATTRIBUTE_DATA statSource;
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(source).c_str(),
+ GetFileExInfoStandard,
+ &statSource) == 0)
+ {
+ return true;
+ }
+
+ WIN32_FILE_ATTRIBUTE_DATA statDestination;
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(destination).c_str(),
+ GetFileExInfoStandard,
+ &statDestination) == 0)
+ {
+ return true;
+ }
+
+ if(statSource.nFileSizeHigh != statDestination.nFileSizeHigh ||
+ statSource.nFileSizeLow != statDestination.nFileSizeLow)
+ {
+ return true;
+ }
+
+ if(statSource.nFileSizeHigh == 0 && statSource.nFileSizeLow == 0)
+ {
+ return false;
+ }
+ off_t nleft = ((__int64)statSource.nFileSizeHigh << 32) +
+ statSource.nFileSizeLow;
+
+#else
+
+ struct stat statSource;
+ if (stat(source.c_str(), &statSource) != 0)
+ {
+ return true;
+ }
+
+ struct stat statDestination;
+ if (stat(destination.c_str(), &statDestination) != 0)
+ {
+ return true;
+ }
+
+ if(statSource.st_size != statDestination.st_size)
+ {
+ return true;
+ }
+
+ if(statSource.st_size == 0)
+ {
+ return false;
+ }
+ off_t nleft = statSource.st_size;
+#endif
+
+#if defined(_WIN32)
+ kwsys::ifstream finSource(source.c_str(),
+ (kwsys_ios::ios::binary |
+ kwsys_ios::ios::in));
+ kwsys::ifstream finDestination(destination.c_str(),
+ (kwsys_ios::ios::binary |
+ kwsys_ios::ios::in));
+#else
+ kwsys::ifstream finSource(source.c_str());
+ kwsys::ifstream finDestination(destination.c_str());
+#endif
+ if(!finSource || !finDestination)
+ {
+ return true;
+ }
+
+ // Compare the files a block at a time.
+ char source_buf[KWSYS_ST_BUFFER];
+ char dest_buf[KWSYS_ST_BUFFER];
+ while(nleft > 0)
+ {
+ // Read a block from each file.
+ kwsys_ios::streamsize nnext = (nleft > KWSYS_ST_BUFFER)? KWSYS_ST_BUFFER : static_cast<kwsys_ios::streamsize>(nleft);
+ finSource.read(source_buf, nnext);
+ finDestination.read(dest_buf, nnext);
+
+ // If either failed to read assume they are different.
+ if(static_cast<kwsys_ios::streamsize>(finSource.gcount()) != nnext ||
+ static_cast<kwsys_ios::streamsize>(finDestination.gcount()) != nnext)
+ {
+ return true;
+ }
+
+ // If this block differs the file differs.
+ if(memcmp(static_cast<const void*>(source_buf),
+ static_cast<const void*>(dest_buf),
+ static_cast<size_t>(nnext)) != 0)
+ {
+ return true;
+ }
+
+ // Update the byte count remaining.
+ nleft -= nnext;
+ }
+
+ // No differences found.
+ return false;
+}
+
+
+//----------------------------------------------------------------------------
+/**
+ * Copy a file named by "source" to the file named by "destination".
+ */
+bool SystemTools::CopyFileAlways(const kwsys_stl::string& source, const kwsys_stl::string& destination)
+{
+ // If files are the same do not copy
+ if ( SystemTools::SameFile(source, destination) )
+ {
+ return true;
+ }
+ mode_t perm = 0;
+ bool perms = SystemTools::GetPermissions(source, perm);
+
+ const int bufferSize = 4096;
+ char buffer[bufferSize];
+
+ // If destination is a directory, try to create a file with the same
+ // name as the source in that directory.
+
+ kwsys_stl::string real_destination = destination;
+ kwsys_stl::string destination_dir;
+ if(SystemTools::FileExists(destination) &&
+ SystemTools::FileIsDirectory(destination))
+ {
+ destination_dir = real_destination;
+ SystemTools::ConvertToUnixSlashes(real_destination);
+ real_destination += '/';
+ kwsys_stl::string source_name = source;
+ real_destination += SystemTools::GetFilenameName(source_name);
+ }
+ else
+ {
+ destination_dir = SystemTools::GetFilenamePath(destination);
+ }
+
+ // Create destination directory
+
+ SystemTools::MakeDirectory(destination_dir);
+
+ // Open files
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+ kwsys::ifstream fin(source.c_str(),
+ kwsys_ios::ios::binary | kwsys_ios::ios::in);
+#else
+ kwsys::ifstream fin(source.c_str());
+#endif
+ if(!fin)
+ {
+ return false;
+ }
+
+ // try and remove the destination file so that read only destination files
+ // can be written to.
+ // If the remove fails continue so that files in read only directories
+ // that do not allow file removal can be modified.
+ SystemTools::RemoveFile(real_destination);
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+ kwsys::ofstream fout(real_destination.c_str(),
+ kwsys_ios::ios::binary | kwsys_ios::ios::out | kwsys_ios::ios::trunc);
+#else
+ kwsys::ofstream fout(real_destination.c_str(),
+ kwsys_ios::ios::out | kwsys_ios::ios::trunc);
+#endif
+ if(!fout)
+ {
+ return false;
+ }
+
+ // This copy loop is very sensitive on certain platforms with
+ // slightly broken stream libraries (like HPUX). Normally, it is
+ // incorrect to not check the error condition on the fin.read()
+ // before using the data, but the fin.gcount() will be zero if an
+ // error occurred. Therefore, the loop should be safe everywhere.
+ while(fin)
+ {
+ fin.read(buffer, bufferSize);
+ if(fin.gcount())
+ {
+ fout.write(buffer, fin.gcount());
+ }
+ }
+
+ // Make sure the operating system has finished writing the file
+ // before closing it. This will ensure the file is finished before
+ // the check below.
+ fout.flush();
+
+ fin.close();
+ fout.close();
+
+ if(!fout)
+ {
+ return false;
+ }
+ if ( perms )
+ {
+ if ( !SystemTools::SetPermissions(real_destination, perm) )
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool SystemTools::CopyAFile(const kwsys_stl::string& source, const kwsys_stl::string& destination,
+ bool always)
+{
+ if(always)
+ {
+ return SystemTools::CopyFileAlways(source, destination);
+ }
+ else
+ {
+ return SystemTools::CopyFileIfDifferent(source, destination);
+ }
+}
+
+/**
+ * Copy a directory content from "source" directory to the directory named by
+ * "destination".
+ */
+bool SystemTools::CopyADirectory(const kwsys_stl::string& source, const kwsys_stl::string& destination,
+ bool always)
+{
+ Directory dir;
+#ifdef _WIN32
+ dir.Load(Encoding::ToNarrow(
+ SystemTools::ConvertToWindowsExtendedPath(source)));
+#else
+ dir.Load(source);
+#endif
+ size_t fileNum;
+ if ( !SystemTools::MakeDirectory(destination) )
+ {
+ return false;
+ }
+ for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum)
+ {
+ if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") &&
+ strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".."))
+ {
+ kwsys_stl::string fullPath = source;
+ fullPath += "/";
+ fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
+ if(SystemTools::FileIsDirectory(fullPath))
+ {
+ kwsys_stl::string fullDestPath = destination;
+ fullDestPath += "/";
+ fullDestPath += dir.GetFile(static_cast<unsigned long>(fileNum));
+ if (!SystemTools::CopyADirectory(fullPath,
+ fullDestPath,
+ always))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if(!SystemTools::CopyAFile(fullPath, destination, always))
+ {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
+
+// return size of file; also returns zero if no file exists
+unsigned long SystemTools::FileLength(const char* filename)
+{
+ unsigned long length = 0;
+#ifdef _WIN32
+ WIN32_FILE_ATTRIBUTE_DATA fs;
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
+ GetFileExInfoStandard, &fs) != 0)
+ {
+ /* To support the full 64-bit file size, use fs.nFileSizeHigh
+ * and fs.nFileSizeLow to construct the 64 bit size
+
+ length = ((__int64)fs.nFileSizeHigh << 32) + fs.nFileSizeLow;
+ */
+ length = static_cast<unsigned long>(fs.nFileSizeLow);
+ }
+#else
+ struct stat fs;
+ if (stat(filename, &fs) == 0)
+ {
+ length = static_cast<unsigned long>(fs.st_size);
+ }
+#endif
+ return length;
+}
+
+int SystemTools::Strucmp(const char *s1, const char *s2)
+{
+ // lifted from Graphvis http://www.graphviz.org
+ while ((*s1 != '\0')
+ && (tolower(*s1) == tolower(*s2)))
+ {
+ s1++;
+ s2++;
+ }
+
+ return tolower(*s1) - tolower(*s2);
+}
+
+// return file's modified time
+long int SystemTools::ModifiedTime(const kwsys_stl::string& filename)
+{
+ long int mt = 0;
+#ifdef _WIN32
+ WIN32_FILE_ATTRIBUTE_DATA fs;
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
+ GetFileExInfoStandard,
+ &fs) != 0)
+ {
+ mt = windows_filetime_to_posix_time(fs.ftLastWriteTime);
+ }
+#else
+ struct stat fs;
+ if (stat(filename.c_str(), &fs) == 0)
+ {
+ mt = static_cast<long int>(fs.st_mtime);
+ }
+#endif
+ return mt;
+}
+
+// return file's creation time
+long int SystemTools::CreationTime(const kwsys_stl::string& filename)
+{
+ long int ct = 0;
+#ifdef _WIN32
+ WIN32_FILE_ATTRIBUTE_DATA fs;
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
+ GetFileExInfoStandard,
+ &fs) != 0)
+ {
+ ct = windows_filetime_to_posix_time(fs.ftCreationTime);
+ }
+#else
+ struct stat fs;
+ if (stat(filename.c_str(), &fs) == 0)
+ {
+ ct = fs.st_ctime >= 0 ? static_cast<long int>(fs.st_ctime) : 0;
+ }
+#endif
+ return ct;
+}
+
+bool SystemTools::ConvertDateMacroString(const char *str, time_t *tmt)
+{
+ if (!str || !tmt || strlen(str) > 11)
+ {
+ return false;
+ }
+
+ struct tm tmt2;
+
+ // __DATE__
+ // The compilation date of the current source file. The date is a string
+ // literal of the form Mmm dd yyyy. The month name Mmm is the same as for
+ // dates generated by the library function asctime declared in TIME.H.
+
+ // index: 012345678901
+ // format: Mmm dd yyyy
+ // example: Dec 19 2003
+
+ static char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+
+ char buffer[12];
+ strcpy(buffer, str);
+
+ buffer[3] = 0;
+ char *ptr = strstr(month_names, buffer);
+ if (!ptr)
+ {
+ return false;
+ }
+
+ int month = static_cast<int>((ptr - month_names) / 3);
+ int day = atoi(buffer + 4);
+ int year = atoi(buffer + 7);
+
+ tmt2.tm_isdst = -1;
+ tmt2.tm_hour = 0;
+ tmt2.tm_min = 0;
+ tmt2.tm_sec = 0;
+ tmt2.tm_wday = 0;
+ tmt2.tm_yday = 0;
+ tmt2.tm_mday = day;
+ tmt2.tm_mon = month;
+ tmt2.tm_year = year - 1900;
+
+ *tmt = mktime(&tmt2);
+ return true;
+}
+
+bool SystemTools::ConvertTimeStampMacroString(const char *str, time_t *tmt)
+{
+ if (!str || !tmt || strlen(str) > 26)
+ {
+ return false;
+ }
+
+ struct tm tmt2;
+
+ // __TIMESTAMP__
+ // The date and time of the last modification of the current source file,
+ // expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy,
+ /// where Ddd is the abbreviated day of the week and Date is an integer
+ // from 1 to 31.
+
+ // index: 0123456789
+ // 0123456789
+ // 0123456789
+ // format: Ddd Mmm Date hh:mm:ss yyyy
+ // example: Fri Dec 19 14:34:58 2003
+
+ static char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+
+ char buffer[27];
+ strcpy(buffer, str);
+
+ buffer[7] = 0;
+ char *ptr = strstr(month_names, buffer + 4);
+ if (!ptr)
+ {
+ return false;
+ }
+
+ int month = static_cast<int>((ptr - month_names) / 3);
+ int day = atoi(buffer + 8);
+ int hour = atoi(buffer + 11);
+ int min = atoi(buffer + 14);
+ int sec = atoi(buffer + 17);
+ int year = atoi(buffer + 20);
+
+ tmt2.tm_isdst = -1;
+ tmt2.tm_hour = hour;
+ tmt2.tm_min = min;
+ tmt2.tm_sec = sec;
+ tmt2.tm_wday = 0;
+ tmt2.tm_yday = 0;
+ tmt2.tm_mday = day;
+ tmt2.tm_mon = month;
+ tmt2.tm_year = year - 1900;
+
+ *tmt = mktime(&tmt2);
+ return true;
+}
+
+kwsys_stl::string SystemTools::GetLastSystemError()
+{
+ int e = errno;
+ return strerror(e);
+}
+
+bool SystemTools::RemoveFile(const kwsys_stl::string& source)
+{
+#ifdef _WIN32
+ mode_t mode;
+ if ( !SystemTools::GetPermissions(source, mode) )
+ {
+ return false;
+ }
+ /* Win32 unlink is stupid --- it fails if the file is read-only */
+ SystemTools::SetPermissions(source, S_IWRITE);
+#endif
+#ifdef _WIN32
+ bool res =
+ _wunlink(SystemTools::ConvertToWindowsExtendedPath(source).c_str()) == 0;
+#else
+ bool res = unlink(source.c_str()) != 0 ? false : true;
+#endif
+#ifdef _WIN32
+ if ( !res )
+ {
+ SystemTools::SetPermissions(source, mode);
+ }
+#endif
+ return res;
+}
+
+bool SystemTools::RemoveADirectory(const kwsys_stl::string& source)
+{
+ // Add write permission to the directory so we can modify its
+ // content to remove files and directories from it.
+ mode_t mode;
+ if(SystemTools::GetPermissions(source, mode))
+ {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ mode |= S_IWRITE;
+#else
+ mode |= S_IWUSR;
+#endif
+ SystemTools::SetPermissions(source, mode);
+ }
+
+ Directory dir;
+#ifdef _WIN32
+ dir.Load(Encoding::ToNarrow(
+ SystemTools::ConvertToWindowsExtendedPath(source)));
+#else
+ dir.Load(source);
+#endif
+ size_t fileNum;
+ for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum)
+ {
+ if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") &&
+ strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".."))
+ {
+ kwsys_stl::string fullPath = source;
+ fullPath += "/";
+ fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
+ if(SystemTools::FileIsDirectory(fullPath) &&
+ !SystemTools::FileIsSymlink(fullPath))
+ {
+ if (!SystemTools::RemoveADirectory(fullPath))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if(!SystemTools::RemoveFile(fullPath))
+ {
+ return false;
+ }
+ }
+ }
+ }
+
+ return (Rmdir(source) == 0);
+}
+
+/**
+ */
+size_t SystemTools::GetMaximumFilePathLength()
+{
+ return KWSYS_SYSTEMTOOLS_MAXPATH;
+}
+
+/**
+ * Find the file the given name. Searches the given path and then
+ * the system search path. Returns the full path to the file if it is
+ * found. Otherwise, the empty string is returned.
+ */
+kwsys_stl::string SystemTools
+::FindName(const char* name,
+ const kwsys_stl::vector<kwsys_stl::string>& userPaths,
+ bool no_system_path)
+{
+ // Add the system search path to our path first
+ kwsys_stl::vector<kwsys_stl::string> path;
+ if (!no_system_path)
+ {
+ SystemTools::GetPath(path, "CMAKE_FILE_PATH");
+ SystemTools::GetPath(path);
+ }
+ // now add the additional paths
+ {
+ for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = userPaths.begin();
+ i != userPaths.end(); ++i)
+ {
+ path.push_back(*i);
+ }
+ }
+ // Add a trailing slash to all paths to aid the search process.
+ {
+ for(kwsys_stl::vector<kwsys_stl::string>::iterator i = path.begin();
+ i != path.end(); ++i)
+ {
+ kwsys_stl::string& p = *i;
+ if(p.empty() || *p.rbegin() != '/')
+ {
+ p += "/";
+ }
+ }
+ }
+ // now look for the file
+ kwsys_stl::string tryPath;
+ for(kwsys_stl::vector<kwsys_stl::string>::const_iterator p = path.begin();
+ p != path.end(); ++p)
+ {
+ tryPath = *p;
+ tryPath += name;
+ if(SystemTools::FileExists(tryPath))
+ {
+ return tryPath;
+ }
+ }
+ // Couldn't find the file.
+ return "";
+}
+
+/**
+ * Find the file the given name. Searches the given path and then
+ * the system search path. Returns the full path to the file if it is
+ * found. Otherwise, the empty string is returned.
+ */
+kwsys_stl::string SystemTools
+::FindFile(const char* name,
+ const kwsys_stl::vector<kwsys_stl::string>& userPaths,
+ bool no_system_path)
+{
+ kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path);
+ if(!tryPath.empty() && !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ // Couldn't find the file.
+ return "";
+}
+
+/**
+ * Find the directory the given name. Searches the given path and then
+ * the system search path. Returns the full path to the directory if it is
+ * found. Otherwise, the empty string is returned.
+ */
+kwsys_stl::string SystemTools
+::FindDirectory(const char* name,
+ const kwsys_stl::vector<kwsys_stl::string>& userPaths,
+ bool no_system_path)
+{
+ kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path);
+ if(!tryPath.empty() && SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ // Couldn't find the file.
+ return "";
+}
+
+/**
+ * Find the executable with the given name. Searches the given path and then
+ * the system search path. Returns the full path to the executable if it is
+ * found. Otherwise, the empty string is returned.
+ */
+kwsys_stl::string SystemTools::FindProgram(
+ const char* nameIn,
+ const kwsys_stl::vector<kwsys_stl::string>& userPaths,
+ bool no_system_path)
+{
+ if(!nameIn || !*nameIn)
+ {
+ return "";
+ }
+ return SystemTools::FindProgram(kwsys_stl::string(nameIn), userPaths, no_system_path);
+}
+
+kwsys_stl::string SystemTools::FindProgram(
+ const kwsys_stl::string& name,
+ const kwsys_stl::vector<kwsys_stl::string>& userPaths,
+ bool no_system_path)
+{
+ kwsys_stl::vector<kwsys_stl::string> extensions;
+#if defined (_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
+ bool hasExtension = false;
+ // 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)
+ {
+ extensions.push_back(".com");
+ extensions.push_back(".exe");
+ }
+#endif
+ kwsys_stl::string tryPath;
+
+ // first try with extensions if the os supports them
+ for(kwsys_stl::vector<kwsys_stl::string>::iterator i =
+ extensions.begin(); i != extensions.end(); ++i)
+ {
+ tryPath = name;
+ tryPath += *i;
+ if(SystemTools::FileExists(tryPath) &&
+ !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ }
+ // now try just the name
+ tryPath = name;
+ if(SystemTools::FileExists(tryPath) &&
+ !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ // now construct the path
+ kwsys_stl::vector<kwsys_stl::string> path;
+ // Add the system search path to our path.
+ if (!no_system_path)
+ {
+ SystemTools::GetPath(path);
+ }
+ // now add the additional paths
+ {
+ for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i =
+ userPaths.begin(); i != userPaths.end(); ++i)
+ {
+ path.push_back(*i);
+ }
+ }
+ // Add a trailing slash to all paths to aid the search process.
+ {
+ for(kwsys_stl::vector<kwsys_stl::string>::iterator i = path.begin();
+ i != path.end(); ++i)
+ {
+ kwsys_stl::string& p = *i;
+ if(p.empty() || *p.rbegin() != '/')
+ {
+ p += "/";
+ }
+ }
+ }
+ // Try each path
+ for(kwsys_stl::vector<kwsys_stl::string>::iterator p = path.begin();
+ p != path.end(); ++p)
+ {
+#ifdef _WIN32
+ // Remove double quotes from the path on windows
+ SystemTools::ReplaceString(*p, "\"", "");
+#endif
+ // first try with extensions
+ for(kwsys_stl::vector<kwsys_stl::string>::iterator ext
+ = extensions.begin(); ext != extensions.end(); ++ext)
+ {
+ tryPath = *p;
+ tryPath += name;
+ tryPath += *ext;
+ if(SystemTools::FileExists(tryPath) &&
+ !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ }
+ // now try it without them
+ tryPath = *p;
+ tryPath += name;
+ if(SystemTools::FileExists(tryPath) &&
+ !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ }
+ // Couldn't find the program.
+ return "";
+}
+
+kwsys_stl::string SystemTools::FindProgram(
+ const kwsys_stl::vector<kwsys_stl::string>& names,
+ const kwsys_stl::vector<kwsys_stl::string>& path,
+ bool noSystemPath)
+{
+ for(kwsys_stl::vector<kwsys_stl::string>::const_iterator it = names.begin();
+ it != names.end() ; ++it)
+ {
+ // Try to find the program.
+ kwsys_stl::string result = SystemTools::FindProgram(*it,
+ path,
+ noSystemPath);
+ if ( !result.empty() )
+ {
+ return result;
+ }
+ }
+ return "";
+}
+
+/**
+ * Find the library with the given name. Searches the given path and then
+ * the system search path. Returns the full path to the library if it is
+ * found. Otherwise, the empty string is returned.
+ */
+kwsys_stl::string SystemTools
+::FindLibrary(const kwsys_stl::string& name,
+ const kwsys_stl::vector<kwsys_stl::string>& userPaths)
+{
+ // See if the executable exists as written.
+ if(SystemTools::FileExists(name) &&
+ !SystemTools::FileIsDirectory(name))
+ {
+ return SystemTools::CollapseFullPath(name);
+ }
+
+ // Add the system search path to our path.
+ kwsys_stl::vector<kwsys_stl::string> path;
+ SystemTools::GetPath(path);
+ // now add the additional paths
+ {
+ for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = userPaths.begin();
+ i != userPaths.end(); ++i)
+ {
+ path.push_back(*i);
+ }
+ }
+ // Add a trailing slash to all paths to aid the search process.
+ {
+ for(kwsys_stl::vector<kwsys_stl::string>::iterator i = path.begin();
+ i != path.end(); ++i)
+ {
+ kwsys_stl::string& p = *i;
+ if(p.empty() || *p.rbegin() != '/')
+ {
+ p += "/";
+ }
+ }
+ }
+ kwsys_stl::string tryPath;
+ for(kwsys_stl::vector<kwsys_stl::string>::const_iterator p = path.begin();
+ p != path.end(); ++p)
+ {
+#if defined(__APPLE__)
+ tryPath = *p;
+ tryPath += name;
+ tryPath += ".framework";
+ if(SystemTools::FileExists(tryPath)
+ && SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+#endif
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
+ tryPath = *p;
+ tryPath += name;
+ tryPath += ".lib";
+ if(SystemTools::FileExists(tryPath)
+ && !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+#else
+ tryPath = *p;
+ tryPath += "lib";
+ tryPath += name;
+ tryPath += ".so";
+ if(SystemTools::FileExists(tryPath)
+ && !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ tryPath = *p;
+ tryPath += "lib";
+ tryPath += name;
+ tryPath += ".a";
+ if(SystemTools::FileExists(tryPath)
+ && !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ tryPath = *p;
+ tryPath += "lib";
+ tryPath += name;
+ tryPath += ".sl";
+ if(SystemTools::FileExists(tryPath)
+ && !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ tryPath = *p;
+ tryPath += "lib";
+ tryPath += name;
+ tryPath += ".dylib";
+ if(SystemTools::FileExists(tryPath)
+ && !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+ tryPath = *p;
+ tryPath += "lib";
+ tryPath += name;
+ tryPath += ".dll";
+ if(SystemTools::FileExists(tryPath)
+ && !SystemTools::FileIsDirectory(tryPath))
+ {
+ return SystemTools::CollapseFullPath(tryPath);
+ }
+#endif
+ }
+
+ // Couldn't find the library.
+ return "";
+}
+
+kwsys_stl::string SystemTools::GetRealPath(const kwsys_stl::string& path)
+{
+ kwsys_stl::string ret;
+ Realpath(path, ret);
+ return ret;
+}
+
+bool SystemTools::FileIsDirectory(const kwsys_stl::string& inName)
+{
+ if (inName.empty())
+ {
+ return false;
+ }
+ size_t length = inName.size();
+ const char* name = inName.c_str();
+
+ // Remove any trailing slash from the name except in a root component.
+ char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH];
+ std::string string_buffer;
+ size_t last = length-1;
+ if(last > 0 && (name[last] == '/' || name[last] == '\\')
+ && strcmp(name, "/") != 0 && name[last-1] != ':')
+ {
+ if (last < sizeof(local_buffer))
+ {
+ memcpy(local_buffer, name, last);
+ local_buffer[last] = '\0';
+ name = local_buffer;
+ }
+ else
+ {
+ string_buffer.append(name, last);
+ name = string_buffer.c_str();
+ }
+ }
+
+ // Now check the file node type.
+#if defined( _WIN32 )
+ DWORD attr = GetFileAttributesW(
+ SystemTools::ConvertToWindowsExtendedPath(name).c_str());
+ if (attr != INVALID_FILE_ATTRIBUTES)
+ {
+ return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
+#else
+ struct stat fs;
+ if(stat(name, &fs) == 0)
+ {
+ return S_ISDIR(fs.st_mode);
+#endif
+ }
+ else
+ {
+ return false;
+ }
+}
+
+bool SystemTools::FileIsSymlink(const kwsys_stl::string& name)
+{
+#if defined( _WIN32 )
+ (void)name;
+ return false;
+#else
+ struct stat fs;
+ if(lstat(name.c_str(), &fs) == 0)
+ {
+ return S_ISLNK(fs.st_mode);
+ }
+ else
+ {
+ return false;
+ }
+#endif
+}
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+bool SystemTools::CreateSymlink(const char*, const char*)
+{
+ return false;
+}
+#else
+bool SystemTools::CreateSymlink(const char* origName, const char* newName)
+{
+ return symlink(origName, newName) >= 0;
+}
+#endif
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+bool SystemTools::ReadSymlink(const char*, kwsys_stl::string&)
+{
+ return false;
+}
+#else
+bool SystemTools::ReadSymlink(const char* newName,
+ kwsys_stl::string& origName)
+{
+ char buf[KWSYS_SYSTEMTOOLS_MAXPATH+1];
+ int count =
+ static_cast<int>(readlink(newName, buf, KWSYS_SYSTEMTOOLS_MAXPATH));
+ if(count >= 0)
+ {
+ // Add null-terminator.
+ buf[count] = 0;
+ origName = buf;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+#endif
+
+int SystemTools::ChangeDirectory(const kwsys_stl::string& dir)
+{
+ return Chdir(dir);
+}
+
+kwsys_stl::string SystemTools::GetCurrentWorkingDirectory(bool collapse)
+{
+ char buf[2048];
+ const char* cwd = Getcwd(buf, 2048);
+ kwsys_stl::string path;
+ if ( cwd )
+ {
+ path = cwd;
+ }
+ if(collapse)
+ {
+ return SystemTools::CollapseFullPath(path);
+ }
+ return path;
+}
+
+kwsys_stl::string SystemTools::GetProgramPath(const char* in_name)
+{
+ kwsys_stl::string dir, file;
+ SystemTools::SplitProgramPath(in_name, dir, file);
+ return dir;
+}
+
+bool SystemTools::SplitProgramPath(const char* in_name,
+ kwsys_stl::string& dir,
+ kwsys_stl::string& file,
+ bool)
+{
+ dir = in_name;
+ file = "";
+ SystemTools::ConvertToUnixSlashes(dir);
+
+ if(!SystemTools::FileIsDirectory(dir))
+ {
+ kwsys_stl::string::size_type slashPos = dir.rfind("/");
+ if(slashPos != kwsys_stl::string::npos)
+ {
+ file = dir.substr(slashPos+1);
+ dir = dir.substr(0, slashPos);
+ }
+ else
+ {
+ file = dir;
+ dir = "";
+ }
+ }
+ if(!(dir.empty()) && !SystemTools::FileIsDirectory(dir))
+ {
+ kwsys_stl::string oldDir = in_name;
+ SystemTools::ConvertToUnixSlashes(oldDir);
+ dir = in_name;
+ return false;
+ }
+ return true;
+}
+
+bool SystemTools::FindProgramPath(const char* argv0,
+ kwsys_stl::string& pathOut,
+ kwsys_stl::string& errorMsg,
+ const char* exeName,
+ const char* buildDir,
+ const char* installPrefix )
+{
+ kwsys_stl::vector<kwsys_stl::string> failures;
+ kwsys_stl::string self = argv0 ? argv0 : "";
+ failures.push_back(self);
+ SystemTools::ConvertToUnixSlashes(self);
+ self = SystemTools::FindProgram(self);
+ if(!SystemTools::FileExists(self))
+ {
+ if(buildDir)
+ {
+ kwsys_stl::string intdir = ".";
+#ifdef CMAKE_INTDIR
+ intdir = CMAKE_INTDIR;
+#endif
+ self = buildDir;
+ self += "/bin/";
+ self += intdir;
+ self += "/";
+ self += exeName;
+ self += SystemTools::GetExecutableExtension();
+ }
+ }
+ if(installPrefix)
+ {
+ if(!SystemTools::FileExists(self))
+ {
+ failures.push_back(self);
+ self = installPrefix;
+ self += "/bin/";
+ self += exeName;
+ }
+ }
+ if(!SystemTools::FileExists(self))
+ {
+ failures.push_back(self);
+ kwsys_ios::ostringstream msg;
+ msg << "Can not find the command line program ";
+ if (exeName)
+ {
+ msg << exeName;
+ }
+ msg << "\n";
+ if (argv0)
+ {
+ msg << " argv[0] = \"" << argv0 << "\"\n";
+ }
+ msg << " Attempted paths:\n";
+ kwsys_stl::vector<kwsys_stl::string>::iterator i;
+ for(i=failures.begin(); i != failures.end(); ++i)
+ {
+ msg << " \"" << *i << "\"\n";
+ }
+ errorMsg = msg.str();
+ return false;
+ }
+ pathOut = self;
+ return true;
+}
+
+
+kwsys_stl::string SystemTools::CollapseFullPath(const kwsys_stl::string& in_relative)
+{
+ return SystemTools::CollapseFullPath(in_relative, 0);
+}
+
+void SystemTools::AddTranslationPath(const kwsys_stl::string& a, const kwsys_stl::string& b)
+{
+ kwsys_stl::string path_a = a;
+ kwsys_stl::string path_b = b;
+ SystemTools::ConvertToUnixSlashes(path_a);
+ SystemTools::ConvertToUnixSlashes(path_b);
+ // First check this is a directory path, since we don't want the table to
+ // grow too fat
+ if( SystemTools::FileIsDirectory( path_a ) )
+ {
+ // Make sure the path is a full path and does not contain no '..'
+ // Ken--the following code is incorrect. .. can be in a valid path
+ // for example /home/martink/MyHubba...Hubba/Src
+ if( SystemTools::FileIsFullPath(path_b) && path_b.find("..")
+ == kwsys_stl::string::npos )
+ {
+ // Before inserting make sure path ends with '/'
+ if(!path_a.empty() && *path_a.rbegin() != '/')
+ {
+ path_a += '/';
+ }
+ if(!path_b.empty() && *path_b.rbegin() != '/')
+ {
+ path_b += '/';
+ }
+ if( !(path_a == path_b) )
+ {
+ SystemTools::TranslationMap->insert(
+ SystemToolsTranslationMap::value_type(path_a, path_b));
+ }
+ }
+ }
+}
+
+void SystemTools::AddKeepPath(const kwsys_stl::string& dir)
+{
+ kwsys_stl::string cdir;
+ Realpath(SystemTools::CollapseFullPath(dir).c_str(), cdir);
+ SystemTools::AddTranslationPath(cdir, dir);
+}
+
+void SystemTools::CheckTranslationPath(kwsys_stl::string & path)
+{
+ // Do not translate paths that are too short to have meaningful
+ // translations.
+ if(path.size() < 2)
+ {
+ return;
+ }
+
+ // Always add a trailing slash before translation. It does not
+ // matter if this adds an extra slash, but we do not want to
+ // translate part of a directory (like the foo part of foo-dir).
+ path += "/";
+
+ // In case a file was specified we still have to go through this:
+ // Now convert any path found in the table back to the one desired:
+ kwsys_stl::map<kwsys_stl::string,kwsys_stl::string>::const_iterator it;
+ for(it = SystemTools::TranslationMap->begin();
+ it != SystemTools::TranslationMap->end();
+ ++it )
+ {
+ // We need to check of the path is a substring of the other path
+ if(path.find( it->first ) == 0)
+ {
+ path = path.replace( 0, it->first.size(), it->second);
+ }
+ }
+
+ // Remove the trailing slash we added before.
+ path.erase(path.end()-1, path.end());
+}
+
+static void
+SystemToolsAppendComponents(
+ kwsys_stl::vector<kwsys_stl::string>& out_components,
+ kwsys_stl::vector<kwsys_stl::string>::const_iterator first,
+ kwsys_stl::vector<kwsys_stl::string>::const_iterator last)
+{
+ static const kwsys_stl::string up = "..";
+ static const kwsys_stl::string cur = ".";
+ for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = first;
+ i != last; ++i)
+ {
+ if(*i == up)
+ {
+ if(out_components.size() > 1)
+ {
+ out_components.resize(out_components.size()-1);
+ }
+ }
+ else if(!i->empty() && *i != cur)
+ {
+ out_components.push_back(*i);
+ }
+ }
+}
+
+kwsys_stl::string SystemTools::CollapseFullPath(const kwsys_stl::string& in_path,
+ const char* in_base)
+{
+ // Collect the output path components.
+ kwsys_stl::vector<kwsys_stl::string> out_components;
+
+ // Split the input path components.
+ kwsys_stl::vector<kwsys_stl::string> path_components;
+ SystemTools::SplitPath(in_path, path_components);
+
+ // If the input path is relative, start with a base path.
+ if(path_components[0].length() == 0)
+ {
+ kwsys_stl::vector<kwsys_stl::string> base_components;
+ if(in_base)
+ {
+ // Use the given base path.
+ SystemTools::SplitPath(in_base, base_components);
+ }
+ else
+ {
+ // Use the current working directory as a base path.
+ char buf[2048];
+ if(const char* cwd = Getcwd(buf, 2048))
+ {
+ SystemTools::SplitPath(cwd, base_components);
+ }
+ else
+ {
+ base_components.push_back("");
+ }
+ }
+
+ // Append base path components to the output path.
+ out_components.push_back(base_components[0]);
+ SystemToolsAppendComponents(out_components,
+ base_components.begin()+1,
+ base_components.end());
+ }
+
+ // Append input path components to the output path.
+ SystemToolsAppendComponents(out_components,
+ path_components.begin(),
+ path_components.end());
+
+ // Transform the path back to a string.
+ kwsys_stl::string newPath = SystemTools::JoinPath(out_components);
+
+ // Update the translation table with this potentially new path. I am not
+ // sure why this line is here, it seems really questionable, but yet I
+ // would put good money that if I remove it something will break, basically
+ // from what I can see it created a mapping from the collapsed path, to be
+ // replaced by the input path, which almost completely does the opposite of
+ // this function, the only thing preventing this from happening a lot is
+ // that if the in_path has a .. in it, then it is not added to the
+ // translation table. So for most calls this either does nothing due to the
+ // .. or it adds a translation between identical paths as nothing was
+ // collapsed, so I am going to try to comment it out, and see what hits the
+ // fan, hopefully quickly.
+ // Commented out line below:
+ //SystemTools::AddTranslationPath(newPath, in_path);
+
+ SystemTools::CheckTranslationPath(newPath);
+#ifdef _WIN32
+ newPath = SystemTools::GetActualCaseForPath(newPath.c_str());
+ SystemTools::ConvertToUnixSlashes(newPath);
+#endif
+ // Return the reconstructed path.
+ return newPath;
+}
+
+// compute the relative path from here to there
+kwsys_stl::string SystemTools::RelativePath(const kwsys_stl::string& local, const kwsys_stl::string& remote)
+{
+ if(!SystemTools::FileIsFullPath(local))
+ {
+ return "";
+ }
+ if(!SystemTools::FileIsFullPath(remote))
+ {
+ return "";
+ }
+
+ kwsys_stl::string l = SystemTools::CollapseFullPath(local);
+ kwsys_stl::string r = SystemTools::CollapseFullPath(remote);
+
+ // split up both paths into arrays of strings using / as a separator
+ kwsys_stl::vector<kwsys::String> localSplit = SystemTools::SplitString(l, '/', true);
+ kwsys_stl::vector<kwsys::String> remoteSplit = SystemTools::SplitString(r, '/', true);
+ kwsys_stl::vector<kwsys::String> commonPath; // store shared parts of path in this array
+ kwsys_stl::vector<kwsys::String> finalPath; // store the final relative path here
+ // count up how many matching directory names there are from the start
+ unsigned int sameCount = 0;
+ while(
+ ((sameCount <= (localSplit.size()-1)) && (sameCount <= (remoteSplit.size()-1)))
+ &&
+// for windows and apple do a case insensitive string compare
+#if defined(_WIN32) || defined(__APPLE__)
+ SystemTools::Strucmp(localSplit[sameCount].c_str(),
+ remoteSplit[sameCount].c_str()) == 0
+#else
+ localSplit[sameCount] == remoteSplit[sameCount]
+#endif
+ )
+ {
+ // put the common parts of the path into the commonPath array
+ commonPath.push_back(localSplit[sameCount]);
+ // erase the common parts of the path from the original path arrays
+ localSplit[sameCount] = "";
+ remoteSplit[sameCount] = "";
+ sameCount++;
+ }
+
+ // If there is nothing in common at all then just return the full
+ // path. This is the case only on windows when the paths have
+ // different drive letters. On unix two full paths always at least
+ // have the root "/" in common so we will return a relative path
+ // that passes through the root directory.
+ if(sameCount == 0)
+ {
+ return remote;
+ }
+
+ // for each entry that is not common in the local path
+ // add a ../ to the finalpath array, this gets us out of the local
+ // path into the remote dir
+ for(unsigned int i = 0; i < localSplit.size(); ++i)
+ {
+ if(!localSplit[i].empty())
+ {
+ finalPath.push_back("../");
+ }
+ }
+ // for each entry that is not common in the remote path add it
+ // to the final path.
+ for(kwsys_stl::vector<String>::iterator vit = remoteSplit.begin();
+ vit != remoteSplit.end(); ++vit)
+ {
+ if(!vit->empty())
+ {
+ finalPath.push_back(*vit);
+ }
+ }
+ kwsys_stl::string relativePath; // result string
+ // now turn the array of directories into a unix path by puttint /
+ // between each entry that does not already have one
+ for(kwsys_stl::vector<String>::iterator vit1 = finalPath.begin();
+ vit1 != finalPath.end(); ++vit1)
+ {
+ if(!relativePath.empty() && *relativePath.rbegin() != '/')
+ {
+ relativePath += "/";
+ }
+ relativePath += *vit1;
+ }
+ return relativePath;
+}
+
+#ifdef _WIN32
+static int GetCasePathName(const kwsys_stl::string & pathIn,
+ kwsys_stl::string & casePath)
+{
+ kwsys_stl::vector<kwsys_stl::string> path_components;
+ SystemTools::SplitPath(pathIn, path_components);
+ if(path_components[0].empty()) // First component always exists.
+ {
+ // Relative paths cannot be converted.
+ casePath = "";
+ return 0;
+ }
+
+ // Start with root component.
+ kwsys_stl::vector<kwsys_stl::string>::size_type idx = 0;
+ casePath = path_components[idx++];
+ const char* sep = "";
+
+ // If network path, fill casePath with server/share so FindFirstFile
+ // will work after that. Maybe someday call other APIs to get
+ // actual case of servers and shares.
+ if(path_components.size() > 2 && path_components[0] == "//")
+ {
+ casePath += path_components[idx++];
+ casePath += "/";
+ casePath += path_components[idx++];
+ sep = "/";
+ }
+
+ for(; idx < path_components.size(); idx++)
+ {
+ casePath += sep;
+ sep = "/";
+ kwsys_stl::string test_str = casePath;
+ test_str += path_components[idx];
+
+ // If path component contains wildcards, we skip matching
+ // because these filenames are not allowed on windows,
+ // and we do not want to match a different file.
+ if(path_components[idx].find('*') != kwsys_stl::string::npos ||
+ path_components[idx].find('?') != kwsys_stl::string::npos)
+ {
+ casePath = "";
+ return 0;
+ }
+
+ WIN32_FIND_DATAW findData;
+ HANDLE hFind = ::FindFirstFileW(Encoding::ToWide(test_str).c_str(),
+ &findData);
+ if (INVALID_HANDLE_VALUE != hFind)
+ {
+ casePath += Encoding::ToNarrow(findData.cFileName);
+ ::FindClose(hFind);
+ }
+ else
+ {
+ casePath = "";
+ return 0;
+ }
+ }
+ return (int)casePath.size();
+}
+#endif
+
+
+//----------------------------------------------------------------------------
+kwsys_stl::string SystemTools::GetActualCaseForPath(const char* p)
+{
+#ifndef _WIN32
+ return p;
+#else
+ kwsys_stl::string casePath = p;
+ // make sure drive letter is always upper case
+ if(casePath.size() > 1 && casePath[1] == ':')
+ {
+ casePath[0] = toupper(casePath[0]);
+ }
+
+ // Check to see if actual case has already been called
+ // for this path, and the result is stored in the LongPathMap
+ SystemToolsTranslationMap::iterator i =
+ SystemTools::LongPathMap->find(casePath);
+ if(i != SystemTools::LongPathMap->end())
+ {
+ return i->second;
+ }
+ int len = GetCasePathName(p, casePath);
+ if(len == 0 || len > MAX_PATH+1)
+ {
+ return p;
+ }
+ (*SystemTools::LongPathMap)[p] = casePath;
+ return casePath;
+#endif
+}
+
+//----------------------------------------------------------------------------
+const char* SystemTools::SplitPathRootComponent(const std::string& p,
+ kwsys_stl::string* root)
+{
+ // Identify the root component.
+ const char* c = p.c_str();
+ if((c[0] == '/' && c[1] == '/') || (c[0] == '\\' && c[1] == '\\'))
+ {
+ // Network path.
+ if(root)
+ {
+ *root = "//";
+ }
+ c += 2;
+ }
+ else if(c[0] == '/' || c[0] == '\\')
+ {
+ // Unix path (or Windows path w/out drive letter).
+ if(root)
+ {
+ *root = "/";
+ }
+ c += 1;
+ }
+ else if(c[0] && c[1] == ':' && (c[2] == '/' || c[2] == '\\'))
+ {
+ // Windows path.
+ if(root)
+ {
+ (*root) = "_:/";
+ (*root)[0] = c[0];
+ }
+ c += 3;
+ }
+ else if(c[0] && c[1] == ':')
+ {
+ // Path relative to a windows drive working directory.
+ if(root)
+ {
+ (*root) = "_:";
+ (*root)[0] = c[0];
+ }
+ c += 2;
+ }
+ else if(c[0] == '~')
+ {
+ // Home directory. The returned root should always have a
+ // trailing slash so that appending components as
+ // c[0]c[1]/c[2]/... works. The remaining path returned should
+ // skip the first slash if it exists:
+ //
+ // "~" : root = "~/" , return ""
+ // "~/ : root = "~/" , return ""
+ // "~/x : root = "~/" , return "x"
+ // "~u" : root = "~u/", return ""
+ // "~u/" : root = "~u/", return ""
+ // "~u/x" : root = "~u/", return "x"
+ size_t n = 1;
+ while(c[n] && c[n] != '/')
+ {
+ ++n;
+ }
+ if(root)
+ {
+ root->assign(c, n);
+ *root += '/';
+ }
+ if(c[n] == '/')
+ {
+ ++n;
+ }
+ c += n;
+ }
+ else
+ {
+ // Relative path.
+ if(root)
+ {
+ *root = "";
+ }
+ }
+
+ // Return the remaining path.
+ return c;
+}
+
+//----------------------------------------------------------------------------
+void SystemTools::SplitPath(const std::string& p,
+ kwsys_stl::vector<kwsys_stl::string>& components,
+ bool expand_home_dir)
+{
+ const char* c;
+ components.clear();
+
+ // Identify the root component.
+ {
+ kwsys_stl::string root;
+ c = SystemTools::SplitPathRootComponent(p, &root);
+
+ // Expand home directory references if requested.
+ if(expand_home_dir && !root.empty() && root[0] == '~')
+ {
+ kwsys_stl::string homedir;
+ root = root.substr(0, root.size()-1);
+ if(root.size() == 1)
+ {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if(const char* userp = getenv("USERPROFILE"))
+ {
+ homedir = userp;
+ }
+ else
+#endif
+ if(const char* h = getenv("HOME"))
+ {
+ homedir = h;
+ }
+ }
+#ifdef HAVE_GETPWNAM
+ else if(passwd* pw = getpwnam(root.c_str()+1))
+ {
+ if(pw->pw_dir)
+ {
+ homedir = pw->pw_dir;
+ }
+ }
+#endif
+ if(!homedir.empty() && (*homedir.rbegin() == '/' ||
+ *homedir.rbegin() == '\\'))
+ {
+ homedir.resize(homedir.size() - 1);
+ }
+ SystemTools::SplitPath(homedir, components);
+ }
+ else
+ {
+ components.push_back(root);
+ }
+ }
+
+ // Parse the remaining components.
+ const char* first = c;
+ const char* last = first;
+ for(;*last; ++last)
+ {
+ if(*last == '/' || *last == '\\')
+ {
+ // End of a component. Save it.
+ components.push_back(kwsys_stl::string(first, last));
+ first = last+1;
+ }
+ }
+
+ // Save the last component unless there were no components.
+ if(last != c)
+ {
+ components.push_back(kwsys_stl::string(first, last));
+ }
+}
+
+//----------------------------------------------------------------------------
+kwsys_stl::string
+SystemTools::JoinPath(const kwsys_stl::vector<kwsys_stl::string>& components)
+{
+ return SystemTools::JoinPath(components.begin(), components.end());
+}
+
+//----------------------------------------------------------------------------
+kwsys_stl::string
+SystemTools
+::JoinPath(kwsys_stl::vector<kwsys_stl::string>::const_iterator first,
+ kwsys_stl::vector<kwsys_stl::string>::const_iterator last)
+{
+ // Construct result in a single string.
+ kwsys_stl::string result;
+ size_t len = 0;
+ kwsys_stl::vector<kwsys_stl::string>::const_iterator i;
+ for(i = first; i != last; ++i)
+ {
+ len += 1 + i->size();
+ }
+ result.reserve(len);
+
+ // The first two components do not add a slash.
+ if(first != last)
+ {
+ result.append(*first++);
+ }
+ if(first != last)
+ {
+ result.append(*first++);
+ }
+
+ // All remaining components are always separated with a slash.
+ while(first != last)
+ {
+ result.append("/");
+ result.append((*first++));
+ }
+
+ // Return the concatenated result.
+ return result;
+}
+
+//----------------------------------------------------------------------------
+bool SystemTools::ComparePath(const kwsys_stl::string& c1, const kwsys_stl::string& c2)
+{
+#if defined(_WIN32) || defined(__APPLE__)
+# ifdef _MSC_VER
+ return _stricmp(c1.c_str(), c2.c_str()) == 0;
+# elif defined(__APPLE__) || defined(__GNUC__)
+ return strcasecmp(c1.c_str(), c2.c_str()) == 0;
+#else
+ return SystemTools::Strucmp(c1.c_str(), c2.c_str()) == 0;
+# endif
+#else
+ return c1 == c2;
+#endif
+}
+
+//----------------------------------------------------------------------------
+bool SystemTools::Split(const kwsys_stl::string& str, kwsys_stl::vector<kwsys_stl::string>& lines, char separator)
+{
+ kwsys_stl::string data(str);
+ kwsys_stl::string::size_type lpos = 0;
+ while(lpos < data.length())
+ {
+ kwsys_stl::string::size_type rpos = data.find_first_of(separator, lpos);
+ if(rpos == kwsys_stl::string::npos)
+ {
+ // Line ends at end of string without a newline.
+ lines.push_back(data.substr(lpos));
+ return false;
+ }
+ else
+ {
+ // Line ends in a "\n", remove the character.
+ lines.push_back(data.substr(lpos, rpos-lpos));
+ }
+ lpos = rpos+1;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool SystemTools::Split(const kwsys_stl::string& str, kwsys_stl::vector<kwsys_stl::string>& lines)
+{
+ kwsys_stl::string data(str);
+ kwsys_stl::string::size_type lpos = 0;
+ while(lpos < data.length())
+ {
+ kwsys_stl::string::size_type rpos = data.find_first_of("\n", lpos);
+ if(rpos == kwsys_stl::string::npos)
+ {
+ // Line ends at end of string without a newline.
+ lines.push_back(data.substr(lpos));
+ return false;
+ }
+ if((rpos > lpos) && (data[rpos-1] == '\r'))
+ {
+ // Line ends in a "\r\n" pair, remove both characters.
+ lines.push_back(data.substr(lpos, (rpos-1)-lpos));
+ }
+ else
+ {
+ // Line ends in a "\n", remove the character.
+ lines.push_back(data.substr(lpos, rpos-lpos));
+ }
+ lpos = rpos+1;
+ }
+ return true;
+}
+
+/**
+ * Return path of a full filename (no trailing slashes).
+ * Warning: returned path is converted to Unix slashes format.
+ */
+kwsys_stl::string SystemTools::GetFilenamePath(const kwsys_stl::string& filename)
+{
+ kwsys_stl::string fn = filename;
+ SystemTools::ConvertToUnixSlashes(fn);
+
+ kwsys_stl::string::size_type slash_pos = fn.rfind("/");
+ if(slash_pos != kwsys_stl::string::npos)
+ {
+ kwsys_stl::string ret = fn.substr(0, slash_pos);
+ if(ret.size() == 2 && ret[1] == ':')
+ {
+ return ret + '/';
+ }
+ if(ret.empty())
+ {
+ return "/";
+ }
+ return ret;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+
+/**
+ * Return file name of a full filename (i.e. file name without path).
+ */
+kwsys_stl::string SystemTools::GetFilenameName(const kwsys_stl::string& filename)
+{
+#if defined(_WIN32)
+ kwsys_stl::string::size_type slash_pos = filename.find_last_of("/\\");
+#else
+ kwsys_stl::string::size_type slash_pos = filename.rfind('/');
+#endif
+ if(slash_pos != kwsys_stl::string::npos)
+ {
+ return filename.substr(slash_pos + 1);
+ }
+ else
+ {
+ return filename;
+ }
+}
+
+
+/**
+ * Return file extension of a full filename (dot included).
+ * Warning: this is the longest extension (for example: .tar.gz)
+ */
+kwsys_stl::string SystemTools::GetFilenameExtension(const kwsys_stl::string& filename)
+{
+ kwsys_stl::string name = SystemTools::GetFilenameName(filename);
+ kwsys_stl::string::size_type dot_pos = name.find(".");
+ if(dot_pos != kwsys_stl::string::npos)
+ {
+ return name.substr(dot_pos);
+ }
+ else
+ {
+ return "";
+ }
+}
+
+/**
+ * Return file extension of a full filename (dot included).
+ * Warning: this is the shortest extension (for example: .gz of .tar.gz)
+ */
+kwsys_stl::string SystemTools::GetFilenameLastExtension(const kwsys_stl::string& filename)
+{
+ kwsys_stl::string name = SystemTools::GetFilenameName(filename);
+ kwsys_stl::string::size_type dot_pos = name.rfind(".");
+ if(dot_pos != kwsys_stl::string::npos)
+ {
+ return name.substr(dot_pos);
+ }
+ else
+ {
+ return "";
+ }
+}
+
+/**
+ * Return file name without extension of a full filename (i.e. without path).
+ * Warning: it considers the longest extension (for example: .tar.gz)
+ */
+kwsys_stl::string SystemTools::GetFilenameWithoutExtension(const kwsys_stl::string& filename)
+{
+ kwsys_stl::string name = SystemTools::GetFilenameName(filename);
+ kwsys_stl::string::size_type dot_pos = name.find(".");
+ if(dot_pos != kwsys_stl::string::npos)
+ {
+ return name.substr(0, dot_pos);
+ }
+ else
+ {
+ return name;
+ }
+}
+
+
+/**
+ * Return file name without extension of a full filename (i.e. without path).
+ * Warning: it considers the last extension (for example: removes .gz
+ * from .tar.gz)
+ */
+kwsys_stl::string
+SystemTools::GetFilenameWithoutLastExtension(const kwsys_stl::string& filename)
+{
+ kwsys_stl::string name = SystemTools::GetFilenameName(filename);
+ kwsys_stl::string::size_type dot_pos = name.rfind(".");
+ if(dot_pos != kwsys_stl::string::npos)
+ {
+ return name.substr(0, dot_pos);
+ }
+ else
+ {
+ return name;
+ }
+}
+
+bool SystemTools::FileHasSignature(const char *filename,
+ const char *signature,
+ long offset)
+{
+ if (!filename || !signature)
+ {
+ return false;
+ }
+
+ FILE *fp = Fopen(filename, "rb");
+ if (!fp)
+ {
+ return false;
+ }
+
+ fseek(fp, offset, SEEK_SET);
+
+ bool res = false;
+ size_t signature_len = strlen(signature);
+ char *buffer = new char [signature_len];
+
+ if (fread(buffer, 1, signature_len, fp) == signature_len)
+ {
+ res = (!strncmp(buffer, signature, signature_len) ? true : false);
+ }
+
+ delete [] buffer;
+
+ fclose(fp);
+ return res;
+}
+
+SystemTools::FileTypeEnum
+SystemTools::DetectFileType(const char *filename,
+ unsigned long length,
+ double percent_bin)
+{
+ if (!filename || percent_bin < 0)
+ {
+ return SystemTools::FileTypeUnknown;
+ }
+
+ FILE *fp = Fopen(filename, "rb");
+ if (!fp)
+ {
+ return SystemTools::FileTypeUnknown;
+ }
+
+ // Allocate buffer and read bytes
+
+ unsigned char *buffer = new unsigned char [length];
+ size_t read_length = fread(buffer, 1, length, fp);
+ fclose(fp);
+ if (read_length == 0)
+ {
+ return SystemTools::FileTypeUnknown;
+ }
+
+ // Loop over contents and count
+
+ size_t text_count = 0;
+
+ const unsigned char *ptr = buffer;
+ const unsigned char *buffer_end = buffer + read_length;
+
+ while (ptr != buffer_end)
+ {
+ if ((*ptr >= 0x20 && *ptr <= 0x7F) ||
+ *ptr == '\n' ||
+ *ptr == '\r' ||
+ *ptr == '\t')
+ {
+ text_count++;
+ }
+ ptr++;
+ }
+
+ delete [] buffer;
+
+ double current_percent_bin =
+ (static_cast<double>(read_length - text_count) /
+ static_cast<double>(read_length));
+
+ if (current_percent_bin >= percent_bin)
+ {
+ return SystemTools::FileTypeBinary;
+ }
+
+ return SystemTools::FileTypeText;
+}
+
+bool SystemTools::LocateFileInDir(const char *filename,
+ const char *dir,
+ kwsys_stl::string& filename_found,
+ int try_filename_dirs)
+{
+ if (!filename || !dir)
+ {
+ return false;
+ }
+
+ // Get the basename of 'filename'
+
+ kwsys_stl::string filename_base = SystemTools::GetFilenameName(filename);
+
+ // Check if 'dir' is really a directory
+ // If win32 and matches something like C:, accept it as a dir
+
+ kwsys_stl::string real_dir;
+ if (!SystemTools::FileIsDirectory(dir))
+ {
+#if defined( _WIN32 )
+ size_t dir_len = strlen(dir);
+ if (dir_len < 2 || dir[dir_len - 1] != ':')
+ {
+#endif
+ real_dir = SystemTools::GetFilenamePath(dir);
+ dir = real_dir.c_str();
+#if defined( _WIN32 )
+ }
+#endif
+ }
+
+ // Try to find the file in 'dir'
+
+ bool res = false;
+ if (!filename_base.empty() && dir)
+ {
+ size_t dir_len = strlen(dir);
+ int need_slash =
+ (dir_len && dir[dir_len - 1] != '/' && dir[dir_len - 1] != '\\');
+
+ kwsys_stl::string temp = dir;
+ if (need_slash)
+ {
+ temp += "/";
+ }
+ temp += filename_base;
+
+ if (SystemTools::FileExists(temp))
+ {
+ res = true;
+ filename_found = temp;
+ }
+
+ // If not found, we can try harder by appending part of the file to
+ // to the directory to look inside.
+ // Example: if we were looking for /foo/bar/yo.txt in /d1/d2, then
+ // try to find yo.txt in /d1/d2/bar, then /d1/d2/foo/bar, etc.
+
+ else if (try_filename_dirs)
+ {
+ kwsys_stl::string filename_dir(filename);
+ kwsys_stl::string filename_dir_base;
+ kwsys_stl::string filename_dir_bases;
+ do
+ {
+ filename_dir = SystemTools::GetFilenamePath(filename_dir);
+ filename_dir_base = SystemTools::GetFilenameName(filename_dir);
+#if defined( _WIN32 )
+ if (filename_dir_base.empty() ||
+ *filename_dir_base.rbegin() == ':')
+#else
+ if (filename_dir_base.empty())
+#endif
+ {
+ break;
+ }
+
+ filename_dir_bases = filename_dir_base + "/" + filename_dir_bases;
+
+ temp = dir;
+ if (need_slash)
+ {
+ temp += "/";
+ }
+ temp += filename_dir_bases;
+
+ res = SystemTools::LocateFileInDir(
+ filename_base.c_str(), temp.c_str(), filename_found, 0);
+
+ } while (!res && !filename_dir_base.empty());
+ }
+ }
+
+ return res;
+}
+
+bool SystemTools::FileIsFullPath(const kwsys_stl::string& in_name)
+{
+ return SystemTools::FileIsFullPath(in_name.c_str(), in_name.size());
+}
+
+bool SystemTools::FileIsFullPath(const char* in_name)
+{
+ return SystemTools::FileIsFullPath(in_name, in_name[0] ? (in_name[1] ? 2 : 1) : 0);
+}
+
+bool SystemTools::FileIsFullPath(const char* in_name, size_t len)
+{
+#if defined(_WIN32) || defined(__CYGWIN__)
+ // On Windows, the name must be at least two characters long.
+ if(len < 2)
+ {
+ return false;
+ }
+ if(in_name[1] == ':')
+ {
+ return true;
+ }
+ if(in_name[0] == '\\')
+ {
+ return true;
+ }
+#else
+ // On UNIX, the name must be at least one character long.
+ if(len < 1)
+ {
+ return false;
+ }
+#endif
+#if !defined(_WIN32)
+ if(in_name[0] == '~')
+ {
+ return true;
+ }
+#endif
+ // On UNIX, the name must begin in a '/'.
+ // On Windows, if the name begins in a '/', then it is a full
+ // network path.
+ if(in_name[0] == '/')
+ {
+ return true;
+ }
+ return false;
+}
+
+bool SystemTools::GetShortPath(const kwsys_stl::string& path, kwsys_stl::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;
+
+ // 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());
+ }
+
+ kwsys_stl::wstring wtempPath = Encoding::ToWide(tempPath);
+ kwsys_stl::vector<wchar_t> buffer(wtempPath.size()+1);
+ buffer[0] = 0;
+ ret = GetShortPathNameW(wtempPath.c_str(),
+ &buffer[0], static_cast<DWORD>(wtempPath.size()));
+
+ if(buffer[0] == 0 || ret > wtempPath.size())
+ {
+ delete [] tempPath;
+ return false;
+ }
+ else
+ {
+ shortPath = Encoding::ToNarrow(&buffer[0]);
+ delete [] tempPath;
+ return true;
+ }
+#else
+ shortPath = path;
+ return true;
+#endif
+}
+
+void SystemTools::SplitProgramFromArgs(const char* path,
+ kwsys_stl::string& program, kwsys_stl::string& args)
+{
+ // see if this is a full path to a program
+ // if so then set program to path and args to nothing
+ if(SystemTools::FileExists(path))
+ {
+ program = path;
+ args = "";
+ return;
+ }
+ // Try to find the program in the path, note the program
+ // may have spaces in its name so we have to look for it
+ kwsys_stl::vector<kwsys_stl::string> e;
+ kwsys_stl::string findProg = SystemTools::FindProgram(path, e);
+ if(!findProg.empty())
+ {
+ program = findProg;
+ args = "";
+ return;
+ }
+
+ // Now try and peel off space separated chunks from the end of the string
+ // so the largest path possible is found allowing for spaces in the path
+ kwsys_stl::string dir = path;
+ kwsys_stl::string::size_type spacePos = dir.rfind(' ');
+ while(spacePos != kwsys_stl::string::npos)
+ {
+ kwsys_stl::string tryProg = dir.substr(0, spacePos);
+ // See if the file exists
+ if(SystemTools::FileExists(tryProg))
+ {
+ program = tryProg;
+ // remove trailing spaces from program
+ kwsys_stl::string::size_type pos = program.size()-1;
+ while(program[pos] == ' ')
+ {
+ program.erase(pos);
+ pos--;
+ }
+ args = dir.substr(spacePos, dir.size()-spacePos);
+ return;
+ }
+ // Now try and find the program in the path
+ findProg = SystemTools::FindProgram(tryProg, e);
+ if(!findProg.empty())
+ {
+ program = findProg;
+ // remove trailing spaces from program
+ kwsys_stl::string::size_type pos = program.size()-1;
+ while(program[pos] == ' ')
+ {
+ program.erase(pos);
+ pos--;
+ }
+ args = dir.substr(spacePos, dir.size()-spacePos);
+ return;
+ }
+ // move past the space for the next search
+ spacePos--;
+ spacePos = dir.rfind(' ', spacePos);
+ }
+
+ program = "";
+ args = "";
+}
+
+kwsys_stl::string SystemTools::GetCurrentDateTime(const char* format)
+{
+ char buf[1024];
+ time_t t;
+ time(&t);
+ strftime(buf, sizeof(buf), format, localtime(&t));
+ return kwsys_stl::string(buf);
+}
+
+kwsys_stl::string SystemTools::MakeCidentifier(const char* s)
+{
+ kwsys_stl::string str(s);
+ if (str.find_first_of("0123456789") == 0)
+ {
+ str = "_" + str;
+ }
+
+ kwsys_stl::string permited_chars("_"
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789");
+ kwsys_stl::string::size_type pos = 0;
+ while ((pos = str.find_first_not_of(permited_chars, pos)) != kwsys_stl::string::npos)
+ {
+ str[pos] = '_';
+ }
+ return str;
+}
+
+// Due to a buggy stream library on the HP and another on Mac OS X, we
+// need this very carefully written version of getline. Returns true
+// if any data were read before the end-of-file was reached.
+bool SystemTools::GetLineFromStream(kwsys_ios::istream& is,
+ kwsys_stl::string& line,
+ bool* has_newline /* = 0 */,
+ long sizeLimit /* = -1 */)
+{
+ const int bufferSize = 1024;
+ char buffer[bufferSize];
+ bool haveData = false;
+ bool haveNewline = false;
+
+ // Start with an empty line.
+ line = "";
+
+ long leftToRead = sizeLimit;
+
+ // Early short circuit return if stream is no good. Just return
+ // false and the empty line. (Probably means caller tried to
+ // create a file stream with a non-existent file name...)
+ //
+ if(!is)
+ {
+ if(has_newline)
+ {
+ *has_newline = false;
+ }
+ return false;
+ }
+
+ // If no characters are read from the stream, the end of file has
+ // been reached. Clear the fail bit just before reading.
+ while(!haveNewline &&
+ leftToRead != 0 &&
+ (is.clear(is.rdstate() & ~kwsys_ios::ios::failbit),
+ is.getline(buffer, bufferSize), is.gcount() > 0))
+ {
+ // We have read at least one byte.
+ haveData = true;
+
+ // If newline character was read the gcount includes the character
+ // but the buffer does not: the end of line has been reached.
+ size_t length = strlen(buffer);
+ if(length < static_cast<size_t>(is.gcount()))
+ {
+ haveNewline = true;
+ }
+
+ // Avoid storing a carriage return character.
+ if(length > 0 && buffer[length-1] == '\r')
+ {
+ buffer[length-1] = 0;
+ }
+
+ // if we read too much then truncate the buffer
+ if (leftToRead > 0)
+ {
+ if (static_cast<long>(length) > leftToRead)
+ {
+ buffer[leftToRead-1] = 0;
+ leftToRead = 0;
+ }
+ else
+ {
+ leftToRead -= static_cast<long>(length);
+ }
+ }
+
+ // Append the data read to the line.
+ line.append(buffer);
+ }
+
+ // Return the results.
+ if(has_newline)
+ {
+ *has_newline = haveNewline;
+ }
+ return haveData;
+}
+
+int SystemTools::GetTerminalWidth()
+{
+ int width = -1;
+#ifdef HAVE_TTY_INFO
+ struct winsize ws;
+ char *columns; /* Unix98 environment variable */
+ if(ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col>0 && ws.ws_row>0)
+ {
+ width = ws.ws_col;
+ }
+ if(!isatty(STDOUT_FILENO))
+ {
+ width = -1;
+ }
+ columns = getenv("COLUMNS");
+ if(columns && *columns)
+ {
+ long t;
+ char *endptr;
+ t = strtol(columns, &endptr, 0);
+ if(endptr && !*endptr && (t>0) && (t<1000))
+ {
+ width = static_cast<int>(t);
+ }
+ }
+ if ( width < 9 )
+ {
+ width = -1;
+ }
+#endif
+ return width;
+}
+
+bool SystemTools::GetPermissions(const char* file, mode_t& mode)
+{
+ if ( !file )
+ {
+ return false;
+ }
+ return SystemTools::GetPermissions(kwsys_stl::string(file), mode);
+}
+
+bool SystemTools::GetPermissions(const kwsys_stl::string& file, mode_t& mode)
+{
+#if defined(_WIN32)
+ DWORD attr = GetFileAttributesW(
+ SystemTools::ConvertToWindowsExtendedPath(file).c_str());
+ if(attr == INVALID_FILE_ATTRIBUTES)
+ {
+ return false;
+ }
+ if((attr & FILE_ATTRIBUTE_READONLY) != 0)
+ {
+ mode = (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6));
+ }
+ else
+ {
+ mode = (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6)) |
+ (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6));
+ }
+ if((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+ {
+ mode |= S_IFDIR | (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6));
+ }
+ else
+ {
+ mode |= S_IFREG;
+ }
+ size_t dotPos = file.rfind('.');
+ const char* ext = dotPos == file.npos ? 0 : (file.c_str() + dotPos);
+ if(ext && (Strucmp(ext, ".exe") == 0 ||
+ Strucmp(ext, ".com") == 0 ||
+ Strucmp(ext, ".cmd") == 0 ||
+ Strucmp(ext, ".bat") == 0))
+ {
+ mode |= (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6));
+ }
+#else
+ struct stat st;
+ if ( stat(file.c_str(), &st) < 0 )
+ {
+ return false;
+ }
+ mode = st.st_mode;
+#endif
+ return true;
+}
+
+bool SystemTools::SetPermissions(const char* file, mode_t mode)
+{
+ if ( !file )
+ {
+ return false;
+ }
+ return SystemTools::SetPermissions(kwsys_stl::string(file), mode);
+}
+
+bool SystemTools::SetPermissions(const kwsys_stl::string& file, mode_t mode)
+{
+ if ( !SystemTools::FileExists(file) )
+ {
+ return false;
+ }
+#ifdef _WIN32
+ if ( _wchmod(SystemTools::ConvertToWindowsExtendedPath(file).c_str(),
+ mode) < 0 )
+#else
+ if ( chmod(file.c_str(), mode) < 0 )
+#endif
+ {
+ return false;
+ }
+
+ return true;
+}
+
+kwsys_stl::string SystemTools::GetParentDirectory(const kwsys_stl::string& fileOrDir)
+{
+ return SystemTools::GetFilenamePath(fileOrDir);
+}
+
+bool SystemTools::IsSubDirectory(const kwsys_stl::string& cSubdir, const kwsys_stl::string& cDir)
+{
+ if(cDir.empty())
+ {
+ return false;
+ }
+ kwsys_stl::string subdir = cSubdir;
+ kwsys_stl::string dir = cDir;
+ SystemTools::ConvertToUnixSlashes(subdir);
+ SystemTools::ConvertToUnixSlashes(dir);
+ if(subdir.size() > dir.size() && subdir[dir.size()] == '/')
+ {
+ std::string s = subdir.substr(0, dir.size());
+ return SystemTools::ComparePath(s, dir);
+ }
+ return false;
+}
+
+void SystemTools::Delay(unsigned int msec)
+{
+#ifdef _WIN32
+ Sleep(msec);
+#else
+ // The sleep function gives 1 second resolution and the usleep
+ // function gives 1e-6 second resolution but on some platforms has a
+ // maximum sleep time of 1 second. This could be re-implemented to
+ // use select with masked signals or pselect to mask signals
+ // atomically. If select is given empty sets and zero as the max
+ // file descriptor but a non-zero timeout it can be used to block
+ // for a precise amount of time.
+ if(msec >= 1000)
+ {
+ sleep(msec / 1000);
+ usleep((msec % 1000) * 1000);
+ }
+ else
+ {
+ usleep(msec * 1000);
+ }
+#endif
+}
+
+kwsys_stl::string SystemTools::GetOperatingSystemNameAndVersion()
+{
+ kwsys_stl::string res;
+
+#ifdef _WIN32
+ char buffer[256];
+
+ OSVERSIONINFOEXA osvi;
+ BOOL bOsVersionInfoEx;
+
+ // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
+ // If that fails, try using the OSVERSIONINFO structure.
+
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXA));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
+
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (push)
+# pragma warning (disable:4996)
+#endif
+ bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi);
+ if (!bOsVersionInfoEx)
+ {
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ if (!GetVersionEx((OSVERSIONINFO *)&osvi))
+ {
+ return 0;
+ }
+ }
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (pop)
+#endif
+
+ switch (osvi.dwPlatformId)
+ {
+ // Test for the Windows NT product family.
+
+ case VER_PLATFORM_WIN32_NT:
+
+ // Test for the specific product family.
+
+ if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)
+ {
+#if (_MSC_VER >= 1300)
+ if (osvi.wProductType == VER_NT_WORKSTATION)
+ {
+ res += "Microsoft Windows Vista";
+ }
+ else
+ {
+ res += "Microsoft Windows Server 2008 family";
+ }
+#else
+ res += "Microsoft Windows Vista or Windows Server 2008";
+#endif
+ }
+
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
+ {
+ res += "Microsoft Windows Server 2003 family";
+ }
+
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
+ {
+ res += "Microsoft Windows XP";
+ }
+
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
+ {
+ res += "Microsoft Windows 2000";
+ }
+
+ if (osvi.dwMajorVersion <= 4)
+ {
+ res += "Microsoft Windows NT";
+ }
+
+ // Test for specific product on Windows NT 4.0 SP6 and later.
+
+ if (bOsVersionInfoEx)
+ {
+ // Test for the workstation type.
+
+#if (_MSC_VER >= 1300)
+ if (osvi.wProductType == VER_NT_WORKSTATION)
+ {
+ if (osvi.dwMajorVersion == 4)
+ {
+ res += " Workstation 4.0";
+ }
+ else if (osvi.dwMajorVersion == 5)
+ {
+ if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
+ {
+ res += " Home Edition";
+ }
+ else
+ {
+ res += " Professional";
+ }
+ }
+ }
+
+ // Test for the server type.
+
+ else if (osvi.wProductType == VER_NT_SERVER)
+ {
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
+ {
+ if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
+ {
+ res += " Datacenter Edition";
+ }
+ else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
+ {
+ res += " Enterprise Edition";
+ }
+ else if (osvi.wSuiteMask == VER_SUITE_BLADE)
+ {
+ res += " Web Edition";
+ }
+ else
+ {
+ res += " Standard Edition";
+ }
+ }
+
+ else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
+ {
+ if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
+ {
+ res += " Datacenter Server";
+ }
+ else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
+ {
+ res += " Advanced Server";
+ }
+ else
+ {
+ res += " Server";
+ }
+ }
+
+ else if (osvi.dwMajorVersion <= 4) // Windows NT 4.0
+ {
+ if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
+ {
+ res += " Server 4.0, Enterprise Edition";
+ }
+ else
+ {
+ res += " Server 4.0";
+ }
+ }
+ }
+#endif // Visual Studio 7 and up
+ }
+
+ // Test for specific product on Windows NT 4.0 SP5 and earlier
+
+ else
+ {
+ HKEY hKey;
+ #define BUFSIZE 80
+ wchar_t szProductType[BUFSIZE];
+ DWORD dwBufLen=BUFSIZE;
+ LONG lRet;
+
+ lRet = RegOpenKeyExW(
+ HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
+ 0, KEY_QUERY_VALUE, &hKey);
+ if (lRet != ERROR_SUCCESS)
+ {
+ return 0;
+ }
+
+ lRet = RegQueryValueExW(hKey, L"ProductType", NULL, NULL,
+ (LPBYTE) szProductType, &dwBufLen);
+
+ if ((lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE))
+ {
+ return 0;
+ }
+
+ RegCloseKey(hKey);
+
+ if (lstrcmpiW(L"WINNT", szProductType) == 0)
+ {
+ res += " Workstation";
+ }
+ if (lstrcmpiW(L"LANMANNT", szProductType) == 0)
+ {
+ res += " Server";
+ }
+ if (lstrcmpiW(L"SERVERNT", szProductType) == 0)
+ {
+ res += " Advanced Server";
+ }
+
+ res += " ";
+ sprintf(buffer, "%ld", osvi.dwMajorVersion);
+ res += buffer;
+ res += ".";
+ sprintf(buffer, "%ld", osvi.dwMinorVersion);
+ res += buffer;
+ }
+
+ // Display service pack (if any) and build number.
+
+ if (osvi.dwMajorVersion == 4 &&
+ lstrcmpiA(osvi.szCSDVersion, "Service Pack 6") == 0)
+ {
+ HKEY hKey;
+ LONG lRet;
+
+ // Test for SP6 versus SP6a.
+
+ lRet = RegOpenKeyExW(
+ HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
+ 0, KEY_QUERY_VALUE, &hKey);
+
+ if (lRet == ERROR_SUCCESS)
+ {
+ res += " Service Pack 6a (Build ";
+ sprintf(buffer, "%ld", osvi.dwBuildNumber & 0xFFFF);
+ res += buffer;
+ res += ")";
+ }
+ else // Windows NT 4.0 prior to SP6a
+ {
+ res += " ";
+ res += osvi.szCSDVersion;
+ res += " (Build ";
+ sprintf(buffer, "%ld", osvi.dwBuildNumber & 0xFFFF);
+ res += buffer;
+ res += ")";
+ }
+
+ RegCloseKey(hKey);
+ }
+ else // Windows NT 3.51 and earlier or Windows 2000 and later
+ {
+ res += " ";
+ res += osvi.szCSDVersion;
+ res += " (Build ";
+ sprintf(buffer, "%ld", osvi.dwBuildNumber & 0xFFFF);
+ res += buffer;
+ res += ")";
+ }
+
+ break;
+
+ // Test for the Windows 95 product family.
+
+ case VER_PLATFORM_WIN32_WINDOWS:
+
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
+ {
+ res += "Microsoft Windows 95";
+ if (osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B')
+ {
+ res += " OSR2";
+ }
+ }
+
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
+ {
+ res += "Microsoft Windows 98";
+ if (osvi.szCSDVersion[1] == 'A')
+ {
+ res += " SE";
+ }
+ }
+
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
+ {
+ res += "Microsoft Windows Millennium Edition";
+ }
+ break;
+
+ case VER_PLATFORM_WIN32s:
+
+ res += "Microsoft Win32s";
+ break;
+ }
+#endif
+
+ return res;
+}
+
+// ----------------------------------------------------------------------
+bool SystemTools::ParseURLProtocol( const kwsys_stl::string& URL,
+ kwsys_stl::string& protocol,
+ kwsys_stl::string& dataglom )
+{
+ // match 0 entire url
+ // match 1 protocol
+ // match 2 dataglom following protocol://
+ kwsys::RegularExpression urlRe( VTK_URL_PROTOCOL_REGEX );
+
+ if ( ! urlRe.find( URL ) ) return false;
+
+ protocol = urlRe.match( 1 );
+ dataglom = urlRe.match( 2 );
+
+ return true;
+}
+
+// ----------------------------------------------------------------------
+bool SystemTools::ParseURL( const kwsys_stl::string& URL,
+ kwsys_stl::string& protocol,
+ kwsys_stl::string& username,
+ kwsys_stl::string& password,
+ kwsys_stl::string& hostname,
+ kwsys_stl::string& dataport,
+ kwsys_stl::string& database )
+{
+ kwsys::RegularExpression urlRe( VTK_URL_REGEX );
+ if ( ! urlRe.find( URL ) ) return false;
+
+ // match 0 URL
+ // match 1 protocol
+ // match 2 mangled user
+ // match 3 username
+ // match 4 mangled password
+ // match 5 password
+ // match 6 hostname
+ // match 7 mangled port
+ // match 8 dataport
+ // match 9 database name
+
+ protocol = urlRe.match( 1 );
+ username = urlRe.match( 3 );
+ password = urlRe.match( 5 );
+ hostname = urlRe.match( 6 );
+ dataport = urlRe.match( 8 );
+ database = urlRe.match( 9 );
+
+ return true;
+}
+
+// ----------------------------------------------------------------------
+// These must NOT be initialized. Default initialization to zero is
+// necessary.
+static unsigned int SystemToolsManagerCount;
+SystemToolsTranslationMap *SystemTools::TranslationMap;
+SystemToolsTranslationMap *SystemTools::LongPathMap;
+#ifdef __CYGWIN__
+SystemToolsTranslationMap *SystemTools::Cyg2Win32Map;
+#endif
+
+// SystemToolsManager manages the SystemTools singleton.
+// SystemToolsManager should be included in any translation unit
+// that will use SystemTools or that implements the singleton
+// pattern. It makes sure that the SystemTools singleton is created
+// before and destroyed after all other singletons in CMake.
+
+SystemToolsManager::SystemToolsManager()
+{
+ if(++SystemToolsManagerCount == 1)
+ {
+ SystemTools::ClassInitialize();
+ }
+}
+
+SystemToolsManager::~SystemToolsManager()
+{
+ if(--SystemToolsManagerCount == 0)
+ {
+ SystemTools::ClassFinalize();
+ }
+}
+
+#if defined(__VMS)
+// On VMS we configure the run time C library to be more UNIX like.
+// http://h71000.www7.hp.com/doc/732final/5763/5763pro_004.html
+extern "C" int decc$feature_get_index(char *name);
+extern "C" int decc$feature_set_value(int index, int mode, int value);
+static int SetVMSFeature(char* name, int value)
+{
+ int i;
+ errno = 0;
+ i = decc$feature_get_index(name);
+ return i >= 0 && (decc$feature_set_value(i, 1, value) >= 0 || errno == 0);
+}
+#endif
+
+void SystemTools::ClassInitialize()
+{
+#ifdef __VMS
+ SetVMSFeature("DECC$FILENAME_UNIX_ONLY", 1);
+#endif
+ // Allocate the translation map first.
+ SystemTools::TranslationMap = new SystemToolsTranslationMap;
+ SystemTools::LongPathMap = new SystemToolsTranslationMap;
+#ifdef __CYGWIN__
+ SystemTools::Cyg2Win32Map = new SystemToolsTranslationMap;
+#endif
+
+ // Add some special translation paths for unix. These are not added
+ // for windows because drive letters need to be maintained. Also,
+ // there are not sym-links and mount points on windows anyway.
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ // The tmp path is frequently a logical path so always keep it:
+ SystemTools::AddKeepPath("/tmp/");
+
+ // If the current working directory is a logical path then keep the
+ // logical name.
+ if(const char* pwd = getenv("PWD"))
+ {
+ char buf[2048];
+ if(const char* cwd = Getcwd(buf, 2048))
+ {
+ // The current working directory may be a logical path. Find
+ // the shortest logical path that still produces the correct
+ // physical path.
+ kwsys_stl::string cwd_changed;
+ kwsys_stl::string pwd_changed;
+
+ // Test progressively shorter logical-to-physical mappings.
+ kwsys_stl::string pwd_str = pwd;
+ kwsys_stl::string cwd_str = cwd;
+ kwsys_stl::string pwd_path;
+ Realpath(pwd, pwd_path);
+ while(cwd_str == pwd_path && cwd_str != pwd_str)
+ {
+ // The current pair of paths is a working logical mapping.
+ cwd_changed = cwd_str;
+ pwd_changed = pwd_str;
+
+ // Strip off one directory level and see if the logical
+ // mapping still works.
+ pwd_str = SystemTools::GetFilenamePath(pwd_str);
+ cwd_str = SystemTools::GetFilenamePath(cwd_str);
+ Realpath(pwd_str.c_str(), pwd_path);
+ }
+
+ // Add the translation to keep the logical path name.
+ if(!cwd_changed.empty() && !pwd_changed.empty())
+ {
+ SystemTools::AddTranslationPath(cwd_changed,
+ pwd_changed);
+ }
+ }
+ }
+#endif
+}
+
+void SystemTools::ClassFinalize()
+{
+ delete SystemTools::TranslationMap;
+ delete SystemTools::LongPathMap;
+#ifdef __CYGWIN__
+ delete SystemTools::Cyg2Win32Map;
+#endif
+}
+
+
+} // namespace KWSYS_NAMESPACE
+
+#if defined(_MSC_VER) && defined(_DEBUG)
+# include <crtdbg.h>
+# include <stdio.h>
+# include <stdlib.h>
+namespace KWSYS_NAMESPACE
+{
+
+static int SystemToolsDebugReport(int, char* message, int*)
+{
+ fprintf(stderr, "%s", message);
+ fflush(stderr);
+ return 1; // no further reporting required
+}
+
+void SystemTools::EnableMSVCDebugHook()
+{
+ if (getenv("DART_TEST_FROM_DART") ||
+ getenv("DASHBOARD_TEST_FROM_CTEST"))
+ {
+ _CrtSetReportHook(SystemToolsDebugReport);
+ }
+}
+
+} // namespace KWSYS_NAMESPACE
+#else
+namespace KWSYS_NAMESPACE
+{
+void SystemTools::EnableMSVCDebugHook() {}
+} // namespace KWSYS_NAMESPACE
+#endif
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
new file mode 100644
index 0000000000..e88bc8f3c3
--- /dev/null
+++ b/Source/kwsys/SystemTools.hxx.in
@@ -0,0 +1,944 @@
+/*============================================================================
+ 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@_SystemTools_hxx
+#define @KWSYS_NAMESPACE@_SystemTools_hxx
+
+#include <@KWSYS_NAMESPACE@/ios/iosfwd>
+#include <@KWSYS_NAMESPACE@/stl/string>
+#include <@KWSYS_NAMESPACE@/stl/vector>
+#include <@KWSYS_NAMESPACE@/stl/map>
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+#include <@KWSYS_NAMESPACE@/String.hxx>
+
+#include <sys/types.h>
+
+// Required for va_list
+#include <stdarg.h>
+// Required for FILE*
+#include <stdio.h>
+#if @KWSYS_NAMESPACE@_STL_HAVE_STD && !defined(va_list)
+// Some compilers move va_list into the std namespace and there is no way to
+// tell that this has been done. Playing with things being included before or
+// after stdarg.h does not solve things because we do not have control over
+// what the user does. This hack solves this problem by moving va_list to our
+// own namespace that is local for kwsys.
+namespace std {} // Required for platforms that do not have std namespace
+namespace @KWSYS_NAMESPACE@_VA_LIST
+{
+ using namespace std;
+ typedef va_list hack_va_list;
+}
+namespace @KWSYS_NAMESPACE@
+{
+ typedef @KWSYS_NAMESPACE@_VA_LIST::hack_va_list va_list;
+}
+#endif // va_list
+
+/* Define these macros temporarily to keep the code readable. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys_stl @KWSYS_NAMESPACE@_stl
+# define kwsys_ios @KWSYS_NAMESPACE@_ios
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+
+class SystemToolsTranslationMap;
+/** \class SystemToolsManager
+ * \brief Use to make sure SystemTools is initialized before it is used
+ * and is the last static object destroyed
+ */
+class @KWSYS_NAMESPACE@_EXPORT SystemToolsManager
+{
+public:
+ SystemToolsManager();
+ ~SystemToolsManager();
+};
+
+// This instance will show up in any translation unit that uses
+// SystemTools. It will make sure SystemTools is initialized
+// before it is used and is the last static object destroyed.
+static SystemToolsManager SystemToolsManagerInstance;
+
+/** \class SystemTools
+ * \brief A collection of useful platform-independent system functions.
+ */
+class @KWSYS_NAMESPACE@_EXPORT SystemTools
+{
+public:
+
+ /** -----------------------------------------------------------------
+ * String Manipulation Routines
+ * -----------------------------------------------------------------
+ */
+
+ /**
+ * Replace symbols in str that are not valid in C identifiers as
+ * defined by the 1999 standard, ie. anything except [A-Za-z0-9_].
+ * They are replaced with `_' and if the first character is a digit
+ * then an underscore is prepended. Note that this can produce
+ * identifiers that the standard reserves (_[A-Z].* and __.*).
+ */
+ static kwsys_stl::string MakeCidentifier(const char* s);
+
+ static kwsys_stl::string MakeCindentifier(const char* s)
+ {
+ return MakeCidentifier(s);
+ }
+
+ /**
+ * Replace replace all occurences of the string in the source string.
+ */
+ static void ReplaceString(kwsys_stl::string& source,
+ const char* replace,
+ const char* with);
+
+ /**
+ * Return a capitalized string (i.e the first letter is uppercased,
+ * all other are lowercased).
+ */
+ static kwsys_stl::string Capitalized(const kwsys_stl::string&);
+
+ /**
+ * Return a 'capitalized words' string (i.e the first letter of each word
+ * is uppercased all other are left untouched though).
+ */
+ static kwsys_stl::string CapitalizedWords(const kwsys_stl::string&);
+
+ /**
+ * Return a 'uncapitalized words' string (i.e the first letter of each word
+ * is lowercased all other are left untouched though).
+ */
+ static kwsys_stl::string UnCapitalizedWords(const kwsys_stl::string&);
+
+ /**
+ * Return a lower case string
+ */
+ static kwsys_stl::string LowerCase(const kwsys_stl::string&);
+
+ /**
+ * Return a lower case string
+ */
+ static kwsys_stl::string UpperCase(const kwsys_stl::string&);
+
+ /**
+ * Count char in string
+ */
+ static size_t CountChar(const char* str, char c);
+
+ /**
+ * Remove some characters from a string.
+ * Return a pointer to the new resulting string (allocated with 'new')
+ */
+ static char* RemoveChars(const char* str, const char *toremove);
+
+ /**
+ * Remove remove all but 0->9, A->F characters from a string.
+ * Return a pointer to the new resulting string (allocated with 'new')
+ */
+ static char* RemoveCharsButUpperHex(const char* str);
+
+ /**
+ * Replace some characters by another character in a string (in-place)
+ * Return a pointer to string
+ */
+ static char* ReplaceChars(char* str, const char *toreplace,char replacement);
+
+ /**
+ * Returns true if str1 starts (respectively ends) with str2
+ */
+ static bool StringStartsWith(const char* str1, const char* str2);
+ static bool StringStartsWith(const kwsys_stl::string& str1, const char* str2);
+ static bool StringEndsWith(const char* str1, const char* str2);
+ static bool StringEndsWith(const kwsys_stl::string& str1, const char* str2);
+
+ /**
+ * Returns a pointer to the last occurence of str2 in str1
+ */
+ static const char* FindLastString(const char* str1, const char* str2);
+
+ /**
+ * Make a duplicate of the string similar to the strdup C function
+ * but use new to create the 'new' string, so one can use
+ * 'delete' to remove it. Returns 0 if the input is empty.
+ */
+ static char* DuplicateString(const char* str);
+
+ /**
+ * Return the string cropped to a given length by removing chars in the
+ * center of the string and replacing them with an ellipsis (...)
+ */
+ static kwsys_stl::string CropString(const kwsys_stl::string&,size_t max_len);
+
+ /** split a path by separator into an array of strings, default is /.
+ If isPath is true then the string is treated like a path and if
+ s starts with a / then the first element of the returned array will
+ be /, so /foo/bar will be [/, foo, bar]
+ */
+ static kwsys_stl::vector<String> SplitString(const kwsys_stl::string& s, char separator = '/',
+ bool isPath = false);
+ /**
+ * Perform a case-independent string comparison
+ */
+ static int Strucmp(const char *s1, const char *s2);
+
+ /**
+ * Convert a string in __DATE__ or __TIMESTAMP__ format into a time_t.
+ * Return false on error, true on success
+ */
+ static bool ConvertDateMacroString(const char *str, time_t *tmt);
+ static bool ConvertTimeStampMacroString(const char *str, time_t *tmt);
+
+ /**
+ * Split a string on its newlines into multiple lines
+ * Return false only if the last line stored had no newline
+ */
+ static bool Split(const kwsys_stl::string& s, kwsys_stl::vector<kwsys_stl::string>& l);
+ static bool Split(const kwsys_stl::string& s, kwsys_stl::vector<kwsys_stl::string>& l, char separator);
+
+ /**
+ * Return string with space added between capitalized words
+ * (i.e. EatMyShorts becomes Eat My Shorts )
+ * (note that IEatShorts becomes IEat Shorts)
+ */
+ static kwsys_stl::string AddSpaceBetweenCapitalizedWords(
+ const kwsys_stl::string&);
+
+ /**
+ * Append two or more strings and produce new one.
+ * Programmer must 'delete []' the resulting string, which was allocated
+ * with 'new'.
+ * Return 0 if inputs are empty or there was an error
+ */
+ static char* AppendStrings(
+ const char* str1, const char* str2);
+ static char* AppendStrings(
+ const char* str1, const char* str2, const char* str3);
+
+ /**
+ * Estimate the length of the string that will be produced
+ * from printing the given format string and arguments. The
+ * returned length will always be at least as large as the string
+ * that will result from printing.
+ * WARNING: since va_arg is called to iterate of the argument list,
+ * you will not be able to use this 'ap' anymore from the beginning.
+ * It's up to you to call va_end though.
+ */
+ static int EstimateFormatLength(const char *format, va_list ap);
+
+ /**
+ * Escape specific characters in 'str'.
+ */
+ static kwsys_stl::string EscapeChars(
+ const char *str, const char *chars_to_escape, char escape_char = '\\');
+
+ /** -----------------------------------------------------------------
+ * Filename Manipulation Routines
+ * -----------------------------------------------------------------
+ */
+
+ /**
+ * Replace Windows file system slashes with Unix-style slashes.
+ */
+ static void ConvertToUnixSlashes(kwsys_stl::string& path);
+
+#ifdef _WIN32
+ /**
+ * Convert the path to an extended length path to avoid MAX_PATH length
+ * limitations on Windows. If the input is a local path the result will be
+ * prefixed with \\?\; if the input is instead a network path, the result
+ * will be prefixed with \\?\UNC\. All output will also be converted to
+ * absolute paths with Windows-style backslashes.
+ **/
+ static kwsys_stl::wstring ConvertToWindowsExtendedPath(const kwsys_stl::string&);
+#endif
+
+ /**
+ * For windows this calls ConvertToWindowsOutputPath and for unix
+ * it calls ConvertToUnixOutputPath
+ */
+ static kwsys_stl::string ConvertToOutputPath(const kwsys_stl::string&);
+
+ /**
+ * Convert the path to a string that can be used in a unix makefile.
+ * double slashes are removed, and spaces are escaped.
+ */
+ static kwsys_stl::string ConvertToUnixOutputPath(const kwsys_stl::string&);
+
+ /**
+ * Convert the path to string that can be used in a windows project or
+ * makefile. Double slashes are removed if they are not at the start of
+ * the string, the slashes are converted to windows style backslashes, and
+ * if there are spaces in the string it is double quoted.
+ */
+ static kwsys_stl::string ConvertToWindowsOutputPath(const kwsys_stl::string&);
+
+ /**
+ * Return true if a file exists in the current directory.
+ * If isFile = true, then make sure the file is a file and
+ * not a directory. If isFile = false, then return true
+ * if it is a file or a directory.
+ */
+ static bool FileExists(const char* filename, bool isFile);
+ static bool FileExists(const kwsys_stl::string& filename, bool isFile);
+ static bool FileExists(const char* filename);
+ static bool FileExists(const kwsys_stl::string& filename);
+
+ /**
+ * Converts Cygwin path to Win32 path. Uses dictionary container for
+ * caching and calls to cygwin_conv_to_win32_path from Cygwin dll
+ * for actual translation. Returns true on success, else false.
+ */
+#ifdef __CYGWIN__
+ static bool PathCygwinToWin32(const char *path, char *win32_path);
+#endif
+
+ /**
+ * Return file length
+ */
+ static unsigned long FileLength(const char *filename);
+
+ /**
+ Change the modification time or create a file
+ */
+ static bool Touch(const kwsys_stl::string& filename, bool create);
+
+ /**
+ * Compare file modification times.
+ * Return true for successful comparison and false for error.
+ * When true is returned, result has -1, 0, +1 for
+ * f1 older, same, or newer than f2.
+ */
+ static bool FileTimeCompare(const kwsys_stl::string& f1,
+ const kwsys_stl::string& f2,
+ int* result);
+
+ /**
+ * Get the file extension (including ".") needed for an executable
+ * on the current platform ("" for unix, ".exe" for Windows).
+ */
+ static const char* GetExecutableExtension();
+
+ /**
+ * Given a path that exists on a windows machine, return the
+ * actuall case of the path as it was created. If the file
+ * does not exist path is returned unchanged. This does nothing
+ * on unix but return path.
+ */
+ static kwsys_stl::string GetActualCaseForPath(const char* path);
+
+ /**
+ * Given the path to a program executable, get the directory part of
+ * the path with the file stripped off. If there is no directory
+ * part, the empty string is returned.
+ */
+ static kwsys_stl::string GetProgramPath(const char*);
+ static bool SplitProgramPath(const char* in_name,
+ kwsys_stl::string& dir,
+ kwsys_stl::string& file,
+ bool errorReport = true);
+
+ /**
+ * Given argv[0] for a unix program find the full path to a running
+ * executable. argv0 can be null for windows WinMain programs
+ * in this case GetModuleFileName will be used to find the path
+ * to the running executable. If argv0 is not a full path,
+ * then this will try to find the full path. If the path is not
+ * found false is returned, if found true is returned. An error
+ * message of the attempted paths is stored in errorMsg.
+ * exeName is the name of the executable.
+ * buildDir is a possibly null path to the build directory.
+ * installPrefix is a possibly null pointer to the install directory.
+ */
+ static bool FindProgramPath(const char* argv0,
+ kwsys_stl::string& pathOut,
+ kwsys_stl::string& errorMsg,
+ const char* exeName = 0,
+ const char* buildDir = 0,
+ const char* installPrefix = 0);
+
+ /**
+ * Given a path to a file or directory, convert it to a full path.
+ * This collapses away relative paths relative to the cwd argument
+ * (which defaults to the current working directory). The full path
+ * is returned.
+ */
+ static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative);
+ static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative,
+ const char* in_base);
+
+ /**
+ * Get the real path for a given path, removing all symlinks. In
+ * the event of an error (non-existent path, permissions issue,
+ * etc.) the original path is returned.
+ */
+ static kwsys_stl::string GetRealPath(const kwsys_stl::string& path);
+
+ /**
+ * Split a path name into its root component and the rest of the
+ * path. The root component is one of the following:
+ * "/" = UNIX full path
+ * "c:/" = Windows full path (can be any drive letter)
+ * "c:" = Windows drive-letter relative path (can be any drive letter)
+ * "//" = Network path
+ * "~/" = Home path for current user
+ * "~u/" = Home path for user 'u'
+ * "" = Relative path
+ *
+ * A pointer to the rest of the path after the root component is
+ * returned. The root component is stored in the "root" string if
+ * given.
+ */
+ static const char* SplitPathRootComponent(const std::string& p,
+ kwsys_stl::string* root=0);
+
+ /**
+ * Split a path name into its basic components. The first component
+ * always exists and is the root returned by SplitPathRootComponent.
+ * The remaining components form the path. If there is a trailing
+ * slash then the last component is the empty string. The
+ * components can be recombined as "c[0]c[1]/c[2]/.../c[n]" to
+ * produce the original path. Home directory references are
+ * automatically expanded if expand_home_dir is true and this
+ * platform supports them.
+ */
+ static void SplitPath(const std::string& p,
+ kwsys_stl::vector<kwsys_stl::string>& components,
+ bool expand_home_dir = true);
+
+ /**
+ * Join components of a path name into a single string. See
+ * SplitPath for the format of the components.
+ */
+ static kwsys_stl::string JoinPath(
+ const kwsys_stl::vector<kwsys_stl::string>& components);
+ static kwsys_stl::string JoinPath(
+ kwsys_stl::vector<kwsys_stl::string>::const_iterator first,
+ kwsys_stl::vector<kwsys_stl::string>::const_iterator last);
+
+ /**
+ * Compare a path or components of a path.
+ */
+ static bool ComparePath(const kwsys_stl::string& c1, const kwsys_stl::string& c2);
+
+
+ /**
+ * Return path of a full filename (no trailing slashes)
+ */
+ static kwsys_stl::string GetFilenamePath(const kwsys_stl::string&);
+
+ /**
+ * Return file name of a full filename (i.e. file name without path)
+ */
+ static kwsys_stl::string GetFilenameName(const kwsys_stl::string&);
+
+ /**
+ * Split a program from its arguments and handle spaces in the paths
+ */
+ static void SplitProgramFromArgs(
+ const char* path,
+ kwsys_stl::string& program, kwsys_stl::string& args);
+
+ /**
+ * Return longest file extension of a full filename (dot included)
+ */
+ static kwsys_stl::string GetFilenameExtension(const kwsys_stl::string&);
+
+ /**
+ * Return shortest file extension of a full filename (dot included)
+ */
+ static kwsys_stl::string GetFilenameLastExtension(
+ const kwsys_stl::string& filename);
+
+ /**
+ * Return file name without extension of a full filename
+ */
+ static kwsys_stl::string GetFilenameWithoutExtension(
+ const kwsys_stl::string&);
+
+ /**
+ * Return file name without its last (shortest) extension
+ */
+ static kwsys_stl::string GetFilenameWithoutLastExtension(
+ const kwsys_stl::string&);
+
+ /**
+ * Return whether the path represents a full path (not relative)
+ */
+ static bool FileIsFullPath(const kwsys_stl::string&);
+ static bool FileIsFullPath(const char*);
+
+ /**
+ * For windows return the short path for the given path,
+ * Unix just a pass through
+ */
+ static bool GetShortPath(const kwsys_stl::string& path, kwsys_stl::string& result);
+
+ /**
+ * Read line from file. Make sure to get everything. Due to a buggy stream
+ * library on the HP and another on Mac OS X, we need this very carefully
+ * written version of getline. Returns true if any data were read before the
+ * end-of-file was reached. If the has_newline argument is specified, it will
+ * be true when the line read had a newline character.
+ */
+ static bool GetLineFromStream(kwsys_ios::istream& istr,
+ kwsys_stl::string& line,
+ bool* has_newline=0,
+ long sizeLimit=-1);
+
+ /**
+ * Get the parent directory of the directory or file
+ */
+ static kwsys_stl::string GetParentDirectory(const kwsys_stl::string& fileOrDir);
+
+ /**
+ * Check if the given file or directory is in subdirectory of dir
+ */
+ static bool IsSubDirectory(const kwsys_stl::string& fileOrDir, const kwsys_stl::string& dir);
+
+ /** -----------------------------------------------------------------
+ * File Manipulation Routines
+ * -----------------------------------------------------------------
+ */
+
+ /**
+ * Open a file considering unicode.
+ */
+ static FILE* Fopen(const kwsys_stl::string& file, const char* mode);
+
+ /**
+ * Make a new directory if it is not there. This function
+ * can make a full path even if none of the directories existed
+ * prior to calling this function.
+ */
+ static bool MakeDirectory(const char* path);
+ static bool MakeDirectory(const kwsys_stl::string& path);
+
+ /**
+ * Copy the source file to the destination file only
+ * if the two files differ.
+ */
+ static bool CopyFileIfDifferent(const kwsys_stl::string& source,
+ const kwsys_stl::string& destination);
+
+ /**
+ * Compare the contents of two files. Return true if different
+ */
+ static bool FilesDiffer(const kwsys_stl::string& source, const kwsys_stl::string& destination);
+
+ /**
+ * Return true if the two files are the same file
+ */
+ static bool SameFile(const kwsys_stl::string& file1, const kwsys_stl::string& file2);
+
+ /**
+ * Copy a file.
+ */
+ static bool CopyFileAlways(const kwsys_stl::string& source, const kwsys_stl::string& destination);
+
+ /**
+ * Copy a file. If the "always" argument is true the file is always
+ * copied. If it is false, the file is copied only if it is new or
+ * has changed.
+ */
+ static bool CopyAFile(const kwsys_stl::string& source, const kwsys_stl::string& destination,
+ bool always = true);
+
+ /**
+ * Copy content directory to another directory with all files and
+ * subdirectories. If the "always" argument is true all files are
+ * always copied. If it is false, only files that have changed or
+ * are new are copied.
+ */
+ static bool CopyADirectory(const kwsys_stl::string& source, const kwsys_stl::string& destination,
+ bool always = true);
+
+ /**
+ * Remove a file
+ */
+ static bool RemoveFile(const kwsys_stl::string& source);
+
+ /**
+ * Remove a directory
+ */
+ static bool RemoveADirectory(const kwsys_stl::string& source);
+
+ /**
+ * Get the maximum full file path length
+ */
+ static size_t GetMaximumFilePathLength();
+
+ /**
+ * Find a file in the system PATH, with optional extra paths
+ */
+ static kwsys_stl::string FindFile(
+ const char* name,
+ const kwsys_stl::vector<kwsys_stl::string>& path =
+ kwsys_stl::vector<kwsys_stl::string>(),
+ bool no_system_path = false);
+
+ /**
+ * Find a directory in the system PATH, with optional extra paths
+ */
+ static kwsys_stl::string FindDirectory(
+ const char* name,
+ const kwsys_stl::vector<kwsys_stl::string>& path =
+ kwsys_stl::vector<kwsys_stl::string>(),
+ bool no_system_path = false);
+
+ /**
+ * Find an executable in the system PATH, with optional extra paths
+ */
+ static kwsys_stl::string FindProgram(
+ const char* name,
+ const kwsys_stl::vector<kwsys_stl::string>& path =
+ kwsys_stl::vector<kwsys_stl::string>(),
+ bool no_system_path = false);
+ static kwsys_stl::string FindProgram(
+ const kwsys_stl::string& name,
+ const kwsys_stl::vector<kwsys_stl::string>& path =
+ kwsys_stl::vector<kwsys_stl::string>(),
+ bool no_system_path = false);
+ static kwsys_stl::string FindProgram(
+ const kwsys_stl::vector<kwsys_stl::string>& names,
+ const kwsys_stl::vector<kwsys_stl::string>& path =
+ kwsys_stl::vector<kwsys_stl::string>(),
+ bool no_system_path = false);
+
+ /**
+ * Find a library in the system PATH, with optional extra paths
+ */
+ static kwsys_stl::string FindLibrary(
+ const kwsys_stl::string& name,
+ const kwsys_stl::vector<kwsys_stl::string>& path);
+
+ /**
+ * Return true if the file is a directory
+ */
+ static bool FileIsDirectory(const kwsys_stl::string& name);
+
+ /**
+ * Return true if the file is a symlink
+ */
+ static bool FileIsSymlink(const kwsys_stl::string& name);
+
+ /**
+ * Return true if the file has a given signature (first set of bytes)
+ */
+ static bool FileHasSignature(
+ const char* filename, const char *signature, long offset = 0);
+
+ /**
+ * Attempt to detect and return the type of a file.
+ * Up to 'length' bytes are read from the file, if more than 'percent_bin' %
+ * of the bytes are non-textual elements, the file is considered binary,
+ * otherwise textual. Textual elements are bytes in the ASCII [0x20, 0x7E]
+ * range, but also \\n, \\r, \\t.
+ * The algorithm is simplistic, and should probably check for usual file
+ * extensions, 'magic' signature, unicode, etc.
+ */
+ enum FileTypeEnum
+ {
+ FileTypeUnknown,
+ FileTypeBinary,
+ FileTypeText
+ };
+ static SystemTools::FileTypeEnum DetectFileType(
+ const char* filename,
+ unsigned long length = 256,
+ double percent_bin = 0.05);
+
+ /**
+ * Create a symbolic link if the platform supports it. Returns whether
+ * creation succeded.
+ */
+ static bool CreateSymlink(const char* origName, const char* newName);
+
+ /**
+ * Read the contents of a symbolic link. Returns whether reading
+ * succeded.
+ */
+ static bool ReadSymlink(const char* newName, kwsys_stl::string& origName);
+
+ /**
+ * Try to locate the file 'filename' in the directory 'dir'.
+ * If 'filename' is a fully qualified filename, the basename of the file is
+ * used to check for its existence in 'dir'.
+ * If 'dir' is not a directory, GetFilenamePath() is called on 'dir' to
+ * get its directory first (thus, you can pass a filename as 'dir', as
+ * a convenience).
+ * 'filename_found' is assigned the fully qualified name/path of the file
+ * if it is found (not touched otherwise).
+ * If 'try_filename_dirs' is true, try to find the file using the
+ * components of its path, i.e. if we are looking for c:/foo/bar/bill.txt,
+ * first look for bill.txt in 'dir', then in 'dir'/bar, then in 'dir'/foo/bar
+ * etc.
+ * Return true if the file was found, false otherwise.
+ */
+ static bool LocateFileInDir(const char *filename,
+ const char *dir,
+ kwsys_stl::string& filename_found,
+ int try_filename_dirs = 0);
+
+ /** compute the relative path from local to remote. local must
+ be a directory. remote can be a file or a directory.
+ Both remote and local must be full paths. Basically, if
+ you are in directory local and you want to access the file in remote
+ what is the relative path to do that. For example:
+ /a/b/c/d to /a/b/c1/d1 -> ../../c1/d1
+ from /usr/src to /usr/src/test/blah/foo.cpp -> test/blah/foo.cpp
+ */
+ static kwsys_stl::string RelativePath(const kwsys_stl::string& local, const kwsys_stl::string& remote);
+
+ /**
+ * Return file's modified time
+ */
+ static long int ModifiedTime(const kwsys_stl::string& filename);
+
+ /**
+ * Return file's creation time (Win32: works only for NTFS, not FAT)
+ */
+ static long int CreationTime(const kwsys_stl::string& filename);
+
+ #if defined( _MSC_VER )
+ typedef unsigned short mode_t;
+ #endif
+
+ /**
+ * Get and set permissions of the file.
+ */
+ static bool GetPermissions(const char* file, mode_t& mode);
+ static bool GetPermissions(const kwsys_stl::string& file, mode_t& mode);
+ static bool SetPermissions(const char* file, mode_t mode);
+ static bool SetPermissions(const kwsys_stl::string& file, mode_t mode);
+
+ /** -----------------------------------------------------------------
+ * Time Manipulation Routines
+ * -----------------------------------------------------------------
+ */
+
+ /** Get current time in seconds since Posix Epoch (Jan 1, 1970). */
+ static double GetTime();
+
+ /**
+ * Get current date/time
+ */
+ static kwsys_stl::string GetCurrentDateTime(const char* format);
+
+ /** -----------------------------------------------------------------
+ * Registry Manipulation Routines
+ * -----------------------------------------------------------------
+ */
+
+ /**
+ * Specify access to the 32-bit or 64-bit application view of
+ * registry values. The default is to match the currently running
+ * binary type.
+ */
+ enum KeyWOW64 { KeyWOW64_Default, KeyWOW64_32, KeyWOW64_64 };
+
+ /**
+ * Get a list of subkeys.
+ */
+ static bool GetRegistrySubKeys(const char *key,
+ kwsys_stl::vector<kwsys_stl::string>& subkeys,
+ KeyWOW64 view = KeyWOW64_Default);
+
+ /**
+ * Read a registry value
+ */
+ static bool ReadRegistryValue(const char *key, kwsys_stl::string &value,
+ KeyWOW64 view = KeyWOW64_Default);
+
+ /**
+ * Write a registry value
+ */
+ static bool WriteRegistryValue(const char *key, const char *value,
+ KeyWOW64 view = KeyWOW64_Default);
+
+ /**
+ * Delete a registry value
+ */
+ static bool DeleteRegistryValue(const char *key,
+ KeyWOW64 view = KeyWOW64_Default);
+
+ /** -----------------------------------------------------------------
+ * Environment Manipulation Routines
+ * -----------------------------------------------------------------
+ */
+
+ /**
+ * Add the paths from the environment variable PATH to the
+ * string vector passed in. If env is set then the value
+ * of env will be used instead of PATH.
+ */
+ static void GetPath(kwsys_stl::vector<kwsys_stl::string>& path,
+ const char* env=0);
+
+ /**
+ * Read an environment variable
+ */
+ static const char* GetEnv(const char* key);
+ static bool GetEnv(const char* key, kwsys_stl::string& result);
+
+ /** Put a string into the environment
+ of the form var=value */
+ static bool PutEnv(const char* env);
+
+ /** Remove a string from the environment.
+ Input is of the form "var" or "var=value" (value is ignored). */
+ static bool UnPutEnv(const char* env);
+
+ /**
+ * Get current working directory CWD
+ */
+ static kwsys_stl::string GetCurrentWorkingDirectory(bool collapse =true);
+
+ /**
+ * Change directory to the directory specified
+ */
+ static int ChangeDirectory(const kwsys_stl::string& dir);
+
+ /**
+ * Get the result of strerror(errno)
+ */
+ static kwsys_stl::string GetLastSystemError();
+
+ /**
+ * When building DEBUG with MSVC, this enables a hook that prevents
+ * error dialogs from popping up if the program is being run from
+ * DART.
+ */
+ static void EnableMSVCDebugHook();
+
+ /**
+ * Get the width of the terminal window. The code may or may not work, so
+ * make sure you have some resonable defaults prepared if the code returns
+ * some bogus size.
+ */
+ static int GetTerminalWidth();
+
+ /**
+ * Add an entry in the path translation table.
+ */
+ static void AddTranslationPath(const kwsys_stl::string& dir, const kwsys_stl::string& refdir);
+
+ /**
+ * If dir is different after CollapseFullPath is called,
+ * Then insert it into the path translation table
+ */
+ static void AddKeepPath(const kwsys_stl::string& dir);
+
+ /**
+ * Update path by going through the Path Translation table;
+ */
+ static void CheckTranslationPath(kwsys_stl::string & path);
+
+ /**
+ * Delay the execution for a specified amount of time specified
+ * in miliseconds
+ */
+ static void Delay(unsigned int msec);
+
+ /**
+ * Get the operating system name and version
+ * This is implemented for Win32 only for the moment
+ */
+ static kwsys_stl::string GetOperatingSystemNameAndVersion();
+
+ /** -----------------------------------------------------------------
+ * URL Manipulation Routines
+ * -----------------------------------------------------------------
+ */
+
+ /**
+ * Parse a character string :
+ * protocol://dataglom
+ * and fill protocol as appropriate.
+ * Return false if the URL does not have the required form, true otherwise.
+ */
+ static bool ParseURLProtocol( const kwsys_stl::string& URL,
+ kwsys_stl::string& protocol,
+ kwsys_stl::string& dataglom );
+
+ /**
+ * Parse a string (a URL without protocol prefix) with the form:
+ * protocol://[[username[':'password]'@']hostname[':'dataport]]'/'[datapath]
+ * and fill protocol, username, password, hostname, dataport, and datapath
+ * when values are found.
+ * Return true if the string matches the format; false otherwise.
+ */
+ static bool ParseURL( const kwsys_stl::string& URL,
+ kwsys_stl::string& protocol,
+ kwsys_stl::string& username,
+ kwsys_stl::string& password,
+ kwsys_stl::string& hostname,
+ kwsys_stl::string& dataport,
+ kwsys_stl::string& datapath );
+
+private:
+ /**
+ * Allocate the stl map that serve as the Path Translation table.
+ */
+ static void ClassInitialize();
+
+ /**
+ * Deallocate the stl map that serve as the Path Translation table.
+ */
+ static void ClassFinalize();
+
+ /**
+ * This method prevents warning on SGI
+ */
+ SystemToolsManager* GetSystemToolsManager()
+ {
+ return &SystemToolsManagerInstance;
+ }
+
+ /**
+ * Actual implementation of FileIsFullPath.
+ */
+ static bool FileIsFullPath(const char*, size_t);
+
+ /**
+ * Find a filename (file or directory) in the system PATH, with
+ * optional extra paths.
+ */
+ static kwsys_stl::string FindName(
+ const char* name,
+ const kwsys_stl::vector<kwsys_stl::string>& path =
+ kwsys_stl::vector<kwsys_stl::string>(),
+ bool no_system_path = false);
+
+
+ /**
+ * Path translation table from dir to refdir
+ * Each time 'dir' will be found it will be replace by 'refdir'
+ */
+ static SystemToolsTranslationMap *TranslationMap;
+ static SystemToolsTranslationMap *LongPathMap;
+#ifdef __CYGWIN__
+ static SystemToolsTranslationMap *Cyg2Win32Map;
+#endif
+ friend class SystemToolsManager;
+};
+
+} // namespace @KWSYS_NAMESPACE@
+
+/* Undefine temporary macros. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsys_stl
+# undef kwsys_ios
+#endif
+
+#endif
diff --git a/Source/kwsys/Terminal.c b/Source/kwsys/Terminal.c
new file mode 100644
index 0000000000..e13003fb85
--- /dev/null
+++ b/Source/kwsys/Terminal.c
@@ -0,0 +1,433 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Terminal.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "Terminal.h.in"
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* Configure support for this platform. */
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define KWSYS_TERMINAL_SUPPORT_CONSOLE
+#endif
+#if !defined(_WIN32)
+# define KWSYS_TERMINAL_ISATTY_WORKS
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* Include needed system APIs. */
+
+#include <stdlib.h> /* getenv */
+#include <string.h> /* strcmp */
+#include <stdarg.h> /* va_list */
+
+#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
+# include <windows.h> /* SetConsoleTextAttribute */
+# include <io.h> /* _get_osfhandle */
+#endif
+
+#if defined(KWSYS_TERMINAL_ISATTY_WORKS)
+# include <unistd.h> /* isatty */
+#else
+# include <sys/stat.h> /* fstat */
+#endif
+
+/*--------------------------------------------------------------------------*/
+static int kwsysTerminalStreamIsVT100(FILE* stream, int default_vt100,
+ int default_tty);
+static void kwsysTerminalSetVT100Color(FILE* stream, int color);
+#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
+static HANDLE kwsysTerminalGetStreamHandle(FILE* stream);
+static void kwsysTerminalSetConsoleColor(HANDLE hOut,
+ CONSOLE_SCREEN_BUFFER_INFO* hOutInfo,
+ FILE* stream,
+ int color);
+#endif
+
+/*--------------------------------------------------------------------------*/
+void kwsysTerminal_cfprintf(int color, FILE* stream, const char* format, ...)
+{
+ /* Setup the stream with the given color if possible. */
+ int pipeIsConsole = 0;
+ int pipeIsVT100 = 0;
+ int default_vt100 = color & kwsysTerminal_Color_AssumeVT100;
+ int default_tty = color & kwsysTerminal_Color_AssumeTTY;
+#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
+ CONSOLE_SCREEN_BUFFER_INFO hOutInfo;
+ HANDLE hOut = kwsysTerminalGetStreamHandle(stream);
+ if(GetConsoleScreenBufferInfo(hOut, &hOutInfo))
+ {
+ pipeIsConsole = 1;
+ kwsysTerminalSetConsoleColor(hOut, &hOutInfo, stream, color);
+ }
+#endif
+ if(!pipeIsConsole && kwsysTerminalStreamIsVT100(stream,
+ default_vt100, default_tty))
+ {
+ pipeIsVT100 = 1;
+ kwsysTerminalSetVT100Color(stream, color);
+ }
+
+ /* Format the text into the stream. */
+ {
+ va_list var_args;
+ va_start(var_args, format);
+ vfprintf(stream, format, var_args);
+ va_end(var_args);
+ }
+
+ /* Restore the normal color state for the stream. */
+#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
+ if(pipeIsConsole)
+ {
+ kwsysTerminalSetConsoleColor(hOut, &hOutInfo, stream,
+ kwsysTerminal_Color_Normal);
+ }
+#endif
+ if(pipeIsVT100)
+ {
+ kwsysTerminalSetVT100Color(stream, kwsysTerminal_Color_Normal);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+/* Detect cases when a stream is definitely not interactive. */
+#if !defined(KWSYS_TERMINAL_ISATTY_WORKS)
+static int kwsysTerminalStreamIsNotInteractive(FILE* stream)
+{
+ /* The given stream is definitely not interactive if it is a regular
+ file. */
+ struct stat stream_stat;
+ if(fstat(fileno(stream), &stream_stat) == 0)
+ {
+ if(stream_stat.st_mode & S_IFREG)
+ {
+ return 1;
+ }
+ }
+ return 0;
+}
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* List of terminal names known to support VT100 color escape sequences. */
+static const char* kwsysTerminalVT100Names[] =
+{
+ "Eterm",
+ "ansi",
+ "color-xterm",
+ "con132x25",
+ "con132x30",
+ "con132x43",
+ "con132x60",
+ "con80x25",
+ "con80x28",
+ "con80x30",
+ "con80x43",
+ "con80x50",
+ "con80x60",
+ "cons25",
+ "console",
+ "cygwin",
+ "dtterm",
+ "eterm-color",
+ "gnome",
+ "gnome-256color",
+ "konsole",
+ "konsole-256color",
+ "kterm",
+ "linux",
+ "msys",
+ "linux-c",
+ "mach-color",
+ "mlterm",
+ "putty",
+ "putty-256color",
+ "rxvt",
+ "rxvt-256color",
+ "rxvt-cygwin",
+ "rxvt-cygwin-native",
+ "rxvt-unicode",
+ "rxvt-unicode-256color",
+ "screen",
+ "screen-256color",
+ "screen-256color-bce",
+ "screen-bce",
+ "screen-w",
+ "screen.linux",
+ "vt100",
+ "xterm",
+ "xterm-16color",
+ "xterm-256color",
+ "xterm-88color",
+ "xterm-color",
+ "xterm-debian",
+ 0
+};
+
+/*--------------------------------------------------------------------------*/
+/* Detect whether a stream is displayed in a VT100-compatible terminal. */
+static int kwsysTerminalStreamIsVT100(FILE* stream, int default_vt100,
+ int default_tty)
+{
+ /* 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)
+ {
+ const char** t = 0;
+ const char* term = getenv("TERM");
+ if(term)
+ {
+ for(t = kwsysTerminalVT100Names; *t && strcmp(term, *t) != 0; ++t) {}
+ }
+ if(!(t && *t))
+ {
+ return 0;
+ }
+ }
+
+#if defined(KWSYS_TERMINAL_ISATTY_WORKS)
+ /* Make sure the stream is a tty. */
+ (void)default_tty;
+ return isatty(fileno(stream))? 1:0;
+#else
+ /* Check for cases in which the stream is definitely not a tty. */
+ if(kwsysTerminalStreamIsNotInteractive(stream))
+ {
+ return 0;
+ }
+
+ /* Use the provided default for whether this is a tty. */
+ return default_tty;
+#endif
+}
+
+/*--------------------------------------------------------------------------*/
+/* VT100 escape sequence strings. */
+#define KWSYS_TERMINAL_VT100_NORMAL "\33[0m"
+#define KWSYS_TERMINAL_VT100_BOLD "\33[1m"
+#define KWSYS_TERMINAL_VT100_UNDERLINE "\33[4m"
+#define KWSYS_TERMINAL_VT100_BLINK "\33[5m"
+#define KWSYS_TERMINAL_VT100_INVERSE "\33[7m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_BLACK "\33[30m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_RED "\33[31m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_GREEN "\33[32m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_YELLOW "\33[33m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_BLUE "\33[34m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_MAGENTA "\33[35m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_CYAN "\33[36m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_WHITE "\33[37m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_BLACK "\33[40m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_RED "\33[41m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_GREEN "\33[42m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_YELLOW "\33[43m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_BLUE "\33[44m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_MAGENTA "\33[45m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_CYAN "\33[46m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_WHITE "\33[47m"
+
+/*--------------------------------------------------------------------------*/
+/* Write VT100 escape sequences to the stream for the given color. */
+static void kwsysTerminalSetVT100Color(FILE* stream, int color)
+{
+ if(color == kwsysTerminal_Color_Normal)
+ {
+ fprintf(stream, KWSYS_TERMINAL_VT100_NORMAL);
+ return;
+ }
+
+ switch(color & kwsysTerminal_Color_ForegroundMask)
+ {
+ case kwsysTerminal_Color_Normal:
+ fprintf(stream, KWSYS_TERMINAL_VT100_NORMAL);
+ break;
+ case kwsysTerminal_Color_ForegroundBlack:
+ fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_BLACK);
+ break;
+ case kwsysTerminal_Color_ForegroundRed:
+ fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_RED);
+ break;
+ case kwsysTerminal_Color_ForegroundGreen:
+ fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_GREEN);
+ break;
+ case kwsysTerminal_Color_ForegroundYellow:
+ fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_YELLOW);
+ break;
+ case kwsysTerminal_Color_ForegroundBlue:
+ fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_BLUE);
+ break;
+ case kwsysTerminal_Color_ForegroundMagenta:
+ fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_MAGENTA);
+ break;
+ case kwsysTerminal_Color_ForegroundCyan:
+ fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_CYAN);
+ break;
+ case kwsysTerminal_Color_ForegroundWhite:
+ fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_WHITE);
+ break;
+ }
+ switch(color & kwsysTerminal_Color_BackgroundMask)
+ {
+ case kwsysTerminal_Color_BackgroundBlack:
+ fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_BLACK);
+ break;
+ case kwsysTerminal_Color_BackgroundRed:
+ fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_RED);
+ break;
+ case kwsysTerminal_Color_BackgroundGreen:
+ fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_GREEN);
+ break;
+ case kwsysTerminal_Color_BackgroundYellow:
+ fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_YELLOW);
+ break;
+ case kwsysTerminal_Color_BackgroundBlue:
+ fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_BLUE);
+ break;
+ case kwsysTerminal_Color_BackgroundMagenta:
+ fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_MAGENTA);
+ break;
+ case kwsysTerminal_Color_BackgroundCyan:
+ fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_CYAN);
+ break;
+ case kwsysTerminal_Color_BackgroundWhite:
+ fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_WHITE);
+ break;
+ }
+ if(color & kwsysTerminal_Color_ForegroundBold)
+ {
+ fprintf(stream, KWSYS_TERMINAL_VT100_BOLD);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
+
+# define KWSYS_TERMINAL_MASK_FOREGROUND \
+ (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
+# define KWSYS_TERMINAL_MASK_BACKGROUND \
+ (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
+
+/* Get the Windows handle for a FILE stream. */
+static HANDLE kwsysTerminalGetStreamHandle(FILE* stream)
+{
+ /* Get the C-library file descriptor from the stream. */
+ int fd = fileno(stream);
+
+# if defined(__CYGWIN__)
+ /* Cygwin seems to have an extra pipe level. If the file descriptor
+ corresponds to stdout or stderr then obtain the matching windows
+ handle directly. */
+ if(fd == fileno(stdout))
+ {
+ return GetStdHandle(STD_OUTPUT_HANDLE);
+ }
+ else if(fd == fileno(stderr))
+ {
+ return GetStdHandle(STD_ERROR_HANDLE);
+ }
+# endif
+
+ /* Get the underlying Windows handle for the descriptor. */
+ return (HANDLE)_get_osfhandle(fd);
+}
+
+/* Set color attributes in a Windows console. */
+static void kwsysTerminalSetConsoleColor(HANDLE hOut,
+ CONSOLE_SCREEN_BUFFER_INFO* hOutInfo,
+ FILE* stream,
+ int color)
+{
+ WORD attributes = 0;
+ switch(color & kwsysTerminal_Color_ForegroundMask)
+ {
+ case kwsysTerminal_Color_Normal:
+ attributes |= hOutInfo->wAttributes & KWSYS_TERMINAL_MASK_FOREGROUND;
+ break;
+ case kwsysTerminal_Color_ForegroundBlack:
+ attributes |= 0;
+ break;
+ case kwsysTerminal_Color_ForegroundRed:
+ attributes |= FOREGROUND_RED;
+ break;
+ case kwsysTerminal_Color_ForegroundGreen:
+ attributes |= FOREGROUND_GREEN;
+ break;
+ case kwsysTerminal_Color_ForegroundYellow:
+ attributes |= FOREGROUND_RED | FOREGROUND_GREEN;
+ break;
+ case kwsysTerminal_Color_ForegroundBlue:
+ attributes |= FOREGROUND_BLUE;
+ break;
+ case kwsysTerminal_Color_ForegroundMagenta:
+ attributes |= FOREGROUND_RED | FOREGROUND_BLUE;
+ break;
+ case kwsysTerminal_Color_ForegroundCyan:
+ attributes |= FOREGROUND_BLUE | FOREGROUND_GREEN;
+ break;
+ case kwsysTerminal_Color_ForegroundWhite:
+ attributes |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
+ break;
+ }
+ switch(color & kwsysTerminal_Color_BackgroundMask)
+ {
+ case kwsysTerminal_Color_Normal:
+ attributes |= hOutInfo->wAttributes & KWSYS_TERMINAL_MASK_BACKGROUND;
+ break;
+ case kwsysTerminal_Color_BackgroundBlack:
+ attributes |= 0;
+ break;
+ case kwsysTerminal_Color_BackgroundRed:
+ attributes |= BACKGROUND_RED;
+ break;
+ case kwsysTerminal_Color_BackgroundGreen:
+ attributes |= BACKGROUND_GREEN;
+ break;
+ case kwsysTerminal_Color_BackgroundYellow:
+ attributes |= BACKGROUND_RED | BACKGROUND_GREEN;
+ break;
+ case kwsysTerminal_Color_BackgroundBlue:
+ attributes |= BACKGROUND_BLUE;
+ break;
+ case kwsysTerminal_Color_BackgroundMagenta:
+ attributes |= BACKGROUND_RED | BACKGROUND_BLUE;
+ break;
+ case kwsysTerminal_Color_BackgroundCyan:
+ attributes |= BACKGROUND_BLUE | BACKGROUND_GREEN;
+ break;
+ case kwsysTerminal_Color_BackgroundWhite:
+ attributes |= BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
+ break;
+ }
+ if(color & kwsysTerminal_Color_ForegroundBold)
+ {
+ attributes |= FOREGROUND_INTENSITY;
+ }
+ if(color & kwsysTerminal_Color_BackgroundBold)
+ {
+ attributes |= BACKGROUND_INTENSITY;
+ }
+ fflush(stream);
+ SetConsoleTextAttribute(hOut, attributes);
+}
+#endif
diff --git a/Source/kwsys/Terminal.h.in b/Source/kwsys/Terminal.h.in
new file mode 100644
index 0000000000..108cba0174
--- /dev/null
+++ b/Source/kwsys/Terminal.h.in
@@ -0,0 +1,159 @@
+/*============================================================================
+ 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@_Terminal_h
+#define @KWSYS_NAMESPACE@_Terminal_h
+
+#include <@KWSYS_NAMESPACE@/Configure.h>
+
+#include <stdio.h> /* For file stream type FILE. */
+
+/* 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@_EXPORT
+#endif
+#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsysTerminal_cfprintf kwsys_ns(Terminal_cfprintf)
+# define kwsysTerminal_Color_e kwsys_ns(Terminal_Color_e)
+# define kwsysTerminal_Color_Normal kwsys_ns(Terminal_Color_Normal)
+# define kwsysTerminal_Color_ForegroundBlack kwsys_ns(Terminal_Color_ForegroundBlack)
+# define kwsysTerminal_Color_ForegroundRed kwsys_ns(Terminal_Color_ForegroundRed)
+# define kwsysTerminal_Color_ForegroundGreen kwsys_ns(Terminal_Color_ForegroundGreen)
+# define kwsysTerminal_Color_ForegroundYellow kwsys_ns(Terminal_Color_ForegroundYellow)
+# define kwsysTerminal_Color_ForegroundBlue kwsys_ns(Terminal_Color_ForegroundBlue)
+# define kwsysTerminal_Color_ForegroundMagenta kwsys_ns(Terminal_Color_ForegroundMagenta)
+# define kwsysTerminal_Color_ForegroundCyan kwsys_ns(Terminal_Color_ForegroundCyan)
+# define kwsysTerminal_Color_ForegroundWhite kwsys_ns(Terminal_Color_ForegroundWhite)
+# define kwsysTerminal_Color_ForegroundMask kwsys_ns(Terminal_Color_ForegroundMask)
+# define kwsysTerminal_Color_BackgroundBlack kwsys_ns(Terminal_Color_BackgroundBlack)
+# define kwsysTerminal_Color_BackgroundRed kwsys_ns(Terminal_Color_BackgroundRed)
+# define kwsysTerminal_Color_BackgroundGreen kwsys_ns(Terminal_Color_BackgroundGreen)
+# define kwsysTerminal_Color_BackgroundYellow kwsys_ns(Terminal_Color_BackgroundYellow)
+# define kwsysTerminal_Color_BackgroundBlue kwsys_ns(Terminal_Color_BackgroundBlue)
+# define kwsysTerminal_Color_BackgroundMagenta kwsys_ns(Terminal_Color_BackgroundMagenta)
+# define kwsysTerminal_Color_BackgroundCyan kwsys_ns(Terminal_Color_BackgroundCyan)
+# define kwsysTerminal_Color_BackgroundWhite kwsys_ns(Terminal_Color_BackgroundWhite)
+# define kwsysTerminal_Color_BackgroundMask kwsys_ns(Terminal_Color_BackgroundMask)
+# define kwsysTerminal_Color_ForegroundBold kwsys_ns(Terminal_Color_ForegroundBold)
+# define kwsysTerminal_Color_BackgroundBold kwsys_ns(Terminal_Color_BackgroundBold)
+# define kwsysTerminal_Color_AssumeTTY kwsys_ns(Terminal_Color_AssumeTTY)
+# define kwsysTerminal_Color_AssumeVT100 kwsys_ns(Terminal_Color_AssumeVT100)
+# define kwsysTerminal_Color_AttributeMask kwsys_ns(Terminal_Color_AttributeMask)
+#endif
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/**
+ * Write colored and formatted text to a stream. Color is used only
+ * for streams supporting it. The color specification is constructed
+ * by bitwise-OR-ing enumeration values. At most one foreground and
+ * one background value may be given.
+ *
+ * Whether the a stream supports color is usually automatically
+ * detected, but with two exceptions:
+ *
+ * - When the stream is displayed in a terminal supporting VT100
+ * color but using an intermediate pipe for communication the
+ * detection of a tty fails. (This typically occurs for a shell
+ * running in an rxvt terminal in MSYS.) If the caller knows this
+ * to be the case, the attribute Color_AssumeTTY may be included in
+ * the color specification.
+ *
+ * - When the stream is displayed in a terminal whose TERM
+ * environment variable is not set or is set to a value that is not
+ * known to support VT100 colors. If the caller knows this to be
+ * the case, the attribute Color_AssumeVT100 may be included in the
+ * color specification.
+ */
+kwsysEXPORT void kwsysTerminal_cfprintf(int color, FILE* stream,
+ const char* format, ...);
+enum kwsysTerminal_Color_e
+{
+ /* Normal Text */
+ kwsysTerminal_Color_Normal = 0,
+
+ /* Foreground Color */
+ kwsysTerminal_Color_ForegroundBlack = 0x1,
+ kwsysTerminal_Color_ForegroundRed = 0x2,
+ kwsysTerminal_Color_ForegroundGreen = 0x3,
+ kwsysTerminal_Color_ForegroundYellow = 0x4,
+ kwsysTerminal_Color_ForegroundBlue = 0x5,
+ kwsysTerminal_Color_ForegroundMagenta = 0x6,
+ kwsysTerminal_Color_ForegroundCyan = 0x7,
+ kwsysTerminal_Color_ForegroundWhite = 0x8,
+ kwsysTerminal_Color_ForegroundMask = 0xF,
+
+ /* Background Color */
+ kwsysTerminal_Color_BackgroundBlack = 0x10,
+ kwsysTerminal_Color_BackgroundRed = 0x20,
+ kwsysTerminal_Color_BackgroundGreen = 0x30,
+ kwsysTerminal_Color_BackgroundYellow = 0x40,
+ kwsysTerminal_Color_BackgroundBlue = 0x50,
+ kwsysTerminal_Color_BackgroundMagenta = 0x60,
+ kwsysTerminal_Color_BackgroundCyan = 0x70,
+ kwsysTerminal_Color_BackgroundWhite = 0x80,
+ kwsysTerminal_Color_BackgroundMask = 0xF0,
+
+ /* Attributes */
+ kwsysTerminal_Color_ForegroundBold = 0x100,
+ kwsysTerminal_Color_BackgroundBold = 0x200,
+ kwsysTerminal_Color_AssumeTTY = 0x400,
+ kwsysTerminal_Color_AssumeVT100 = 0x800,
+ kwsysTerminal_Color_AttributeMask = 0xF00
+};
+
+#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 !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsysTerminal_cfprintf
+# undef kwsysTerminal_Color_e
+# undef kwsysTerminal_Color_Normal
+# undef kwsysTerminal_Color_ForegroundBlack
+# undef kwsysTerminal_Color_ForegroundRed
+# undef kwsysTerminal_Color_ForegroundGreen
+# undef kwsysTerminal_Color_ForegroundYellow
+# undef kwsysTerminal_Color_ForegroundBlue
+# undef kwsysTerminal_Color_ForegroundMagenta
+# undef kwsysTerminal_Color_ForegroundCyan
+# undef kwsysTerminal_Color_ForegroundWhite
+# undef kwsysTerminal_Color_ForegroundMask
+# undef kwsysTerminal_Color_BackgroundBlack
+# undef kwsysTerminal_Color_BackgroundRed
+# undef kwsysTerminal_Color_BackgroundGreen
+# undef kwsysTerminal_Color_BackgroundYellow
+# undef kwsysTerminal_Color_BackgroundBlue
+# undef kwsysTerminal_Color_BackgroundMagenta
+# undef kwsysTerminal_Color_BackgroundCyan
+# undef kwsysTerminal_Color_BackgroundWhite
+# undef kwsysTerminal_Color_BackgroundMask
+# undef kwsysTerminal_Color_ForegroundBold
+# undef kwsysTerminal_Color_BackgroundBold
+# undef kwsysTerminal_Color_AssumeTTY
+# undef kwsysTerminal_Color_AssumeVT100
+# undef kwsysTerminal_Color_AttributeMask
+# endif
+#endif
+
+#endif
diff --git a/Source/kwsys/auto_ptr.hxx.in b/Source/kwsys/auto_ptr.hxx.in
new file mode 100644
index 0000000000..ad9654cb4c
--- /dev/null
+++ b/Source/kwsys/auto_ptr.hxx.in
@@ -0,0 +1,219 @@
+/*============================================================================
+ 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@_auto_ptr_hxx
+#define @KWSYS_NAMESPACE@_auto_ptr_hxx
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+// The HP compiler and VS6 cannot handle the conversions necessary to use
+// auto_ptr_ref to pass an auto_ptr returned from one function
+// directly to another function as in use_auto_ptr(get_auto_ptr()).
+// We instead use const_cast to achieve the syntax on those platforms.
+// We do not use const_cast on other platforms to maintain the C++
+// standard design and guarantee that if an auto_ptr is bound
+// to a reference-to-const then ownership will be maintained.
+#if defined(__HP_aCC) || (defined(_MSC_VER) && _MSC_VER <= 1200)
+# define @KWSYS_NAMESPACE@_AUTO_PTR_REF 0
+# define @KWSYS_NAMESPACE@_AUTO_PTR_CONST const
+# define @KWSYS_NAMESPACE@_AUTO_PTR_CAST(a) cast(a)
+#else
+# define @KWSYS_NAMESPACE@_AUTO_PTR_REF 1
+# define @KWSYS_NAMESPACE@_AUTO_PTR_CONST
+# define @KWSYS_NAMESPACE@_AUTO_PTR_CAST(a) a
+#endif
+
+// In C++11, clang will warn about using dynamic exception specifications
+// as they are deprecated. But as this class is trying to faithfully
+// mimic std::auto_ptr, we want to keep the 'throw()' decorations below.
+// So we suppress the warning.
+#if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wdeprecated")
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated"
+# endif
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+
+template <class X> class auto_ptr;
+
+#if @KWSYS_NAMESPACE@_AUTO_PTR_REF
+namespace detail
+{
+// The auto_ptr_ref template is supposed to be a private member of
+// auto_ptr but Borland 5.8 cannot handle it. Instead put it in
+// a private namespace.
+template <class Y> struct auto_ptr_ref
+{
+ Y* p_;
+
+ // The extra constructor argument prevents implicit conversion to
+ // auto_ptr_ref from auto_ptr through the constructor. Normally
+ // this should be done with the explicit keyword but Borland 5.x
+ // generates code in the conversion operator to call itself
+ // infinately.
+ auto_ptr_ref(Y* p, int): p_(p) {}
+};
+}
+#endif
+
+/** C++98 Standard Section 20.4.5 - Template class auto_ptr. */
+template <class X>
+class auto_ptr
+{
+#if !@KWSYS_NAMESPACE@_AUTO_PTR_REF
+ template <typename Y>
+ static inline auto_ptr<Y>& cast(auto_ptr<Y> const& a)
+ { return const_cast<auto_ptr<Y>&>(a); }
+#endif
+
+ /** The pointer to the object held. */
+ X* x_;
+
+public:
+ /** The type of object held by the auto_ptr. */
+ typedef X element_type;
+
+ /** Construct from an auto_ptr holding a compatible object. This
+ transfers ownership to the newly constructed auto_ptr. */
+ template <class Y>
+ auto_ptr(auto_ptr<Y> @KWSYS_NAMESPACE@_AUTO_PTR_CONST& a) throw():
+ x_(@KWSYS_NAMESPACE@_AUTO_PTR_CAST(a).release())
+ {
+ }
+
+ /** Assign from an auto_ptr holding a compatible object. This
+ transfers ownership to the left-hand-side of the assignment. */
+ template <class Y>
+ auto_ptr& operator=(auto_ptr<Y> @KWSYS_NAMESPACE@_AUTO_PTR_CONST& a) throw()
+ {
+ this->reset(@KWSYS_NAMESPACE@_AUTO_PTR_CAST(a).release());
+ return *this;
+ }
+
+ /**
+ * Explicitly construct from a raw pointer. This is typically
+ * called with the result of operator new. For example:
+ *
+ * auto_ptr<X> ptr(new X());
+ */
+ explicit auto_ptr(X* p=0) throw(): x_(p)
+ {
+ }
+
+ /** Construct from another auto_ptr holding an object of the same
+ type. This transfers ownership to the newly constructed
+ auto_ptr. */
+ auto_ptr(auto_ptr @KWSYS_NAMESPACE@_AUTO_PTR_CONST& a) throw():
+ x_(@KWSYS_NAMESPACE@_AUTO_PTR_CAST(a).release())
+ {
+ }
+
+ /** Assign from another auto_ptr holding an object of the same type.
+ This transfers ownership to the newly constructed auto_ptr. */
+ auto_ptr& operator=(auto_ptr @KWSYS_NAMESPACE@_AUTO_PTR_CONST& a) throw()
+ {
+ this->reset(@KWSYS_NAMESPACE@_AUTO_PTR_CAST(a).release());
+ return *this;
+ }
+
+ /** Destruct and delete the object held. */
+ ~auto_ptr() throw()
+ {
+ // Assume object destructor is nothrow.
+ delete this->x_;
+ }
+
+ /** Dereference and return a reference to the object held. */
+ X& operator*() const throw()
+ {
+ return *this->x_;
+ }
+
+ /** Return a pointer to the object held. */
+ X* operator->() const throw()
+ {
+ return this->x_;
+ }
+
+ /** Return a pointer to the object held. */
+ X* get() const throw()
+ {
+ return this->x_;
+ }
+
+ /** Return a pointer to the object held and reset to hold no object.
+ This transfers ownership to the caller. */
+ X* release() throw()
+ {
+ X* x = this->x_;
+ this->x_ = 0;
+ return x;
+ }
+
+ /** Assume ownership of the given object. The object previously
+ held is deleted. */
+ void reset(X* p=0) throw()
+ {
+ if(this->x_ != p)
+ {
+ // Assume object destructor is nothrow.
+ delete this->x_;
+ this->x_ = p;
+ }
+ }
+
+ /** Convert to an auto_ptr holding an object of a compatible type.
+ This transfers ownership to the returned auto_ptr. */
+ template <class Y> operator auto_ptr<Y>() throw()
+ {
+ return auto_ptr<Y>(this->release());
+ }
+
+#if @KWSYS_NAMESPACE@_AUTO_PTR_REF
+ /** Construct from an auto_ptr_ref. This is used when the
+ constructor argument is a call to a function returning an
+ auto_ptr. */
+ auto_ptr(detail::auto_ptr_ref<X> r) throw(): x_(r.p_)
+ {
+ }
+
+ /** Assign from an auto_ptr_ref. This is used when a function
+ returning an auto_ptr is passed on the right-hand-side of an
+ assignment. */
+ auto_ptr& operator=(detail::auto_ptr_ref<X> r) throw()
+ {
+ this->reset(r.p_);
+ return *this;
+ }
+
+ /** Convert to an auto_ptr_ref. This is used when a function
+ returning an auto_ptr is the argument to the constructor of
+ another auto_ptr. */
+ template <class Y> operator detail::auto_ptr_ref<Y>() throw()
+ {
+ return detail::auto_ptr_ref<Y>(this->release(), 1);
+ }
+#endif
+};
+
+} // namespace @KWSYS_NAMESPACE@
+
+// Undo warning suppression.
+#if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wdeprecated")
+# pragma clang diagnostic pop
+# endif
+#endif
+
+#endif
diff --git a/Source/kwsys/hash_fun.hxx.in b/Source/kwsys/hash_fun.hxx.in
new file mode 100644
index 0000000000..6f787ddc56
--- /dev/null
+++ b/Source/kwsys/hash_fun.hxx.in
@@ -0,0 +1,149 @@
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+#ifndef @KWSYS_NAMESPACE@_hash_fun_hxx
+#define @KWSYS_NAMESPACE@_hash_fun_hxx
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+#include <@KWSYS_NAMESPACE@/cstddef> // size_t
+#include <@KWSYS_NAMESPACE@/stl/string> // string
+
+namespace @KWSYS_NAMESPACE@
+{
+
+template <class _Key> struct hash { };
+
+inline size_t _stl_hash_string(const char* __s)
+{
+ unsigned long __h = 0;
+ for ( ; *__s; ++__s)
+ __h = 5*__h + *__s;
+
+ return size_t(__h);
+}
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<char*> {
+ size_t operator()(const char* __s) const { return _stl_hash_string(__s); }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<const char*> {
+ size_t operator()(const char* __s) const { return _stl_hash_string(__s); }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+ struct hash<@KWSYS_NAMESPACE@_stl::string> {
+ size_t operator()(const @KWSYS_NAMESPACE@_stl::string & __s) const { return _stl_hash_string(__s.c_str()); }
+};
+
+#if !defined(__BORLANDC__)
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+ struct hash<const @KWSYS_NAMESPACE@_stl::string> {
+ size_t operator()(const @KWSYS_NAMESPACE@_stl::string & __s) const { return _stl_hash_string(__s.c_str()); }
+};
+#endif
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<char> {
+ size_t operator()(char __x) const { return __x; }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<unsigned char> {
+ size_t operator()(unsigned char __x) const { return __x; }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<signed char> {
+ size_t operator()(unsigned char __x) const { return __x; }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<short> {
+ size_t operator()(short __x) const { return __x; }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<unsigned short> {
+ size_t operator()(unsigned short __x) const { return __x; }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<int> {
+ size_t operator()(int __x) const { return __x; }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<unsigned int> {
+ size_t operator()(unsigned int __x) const { return __x; }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<long> {
+ size_t operator()(long __x) const { return __x; }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<unsigned long> {
+ size_t operator()(unsigned long __x) const { return __x; }
+};
+
+// use long long or __int64
+#if @KWSYS_USE_LONG_LONG@
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<long long> {
+ size_t operator()(long long __x) const { return __x; }
+};
+
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<unsigned long long> {
+ size_t operator()(unsigned long long __x) const { return __x; }
+};
+#elif @KWSYS_USE___INT64@
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<__int64> {
+ size_t operator()(__int64 __x) const { return __x; }
+};
+@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
+struct hash<unsigned __int64> {
+ size_t operator()(unsigned __int64 __x) const { return __x; }
+};
+#endif // use long long or __int64
+
+} // namespace @KWSYS_NAMESPACE@
+
+#endif
diff --git a/Source/kwsys/hash_map.hxx.in b/Source/kwsys/hash_map.hxx.in
new file mode 100644
index 0000000000..6d4379d8e7
--- /dev/null
+++ b/Source/kwsys/hash_map.hxx.in
@@ -0,0 +1,461 @@
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+#ifndef @KWSYS_NAMESPACE@_hash_map_hxx
+#define @KWSYS_NAMESPACE@_hash_map_hxx
+
+#include <@KWSYS_NAMESPACE@/hashtable.hxx>
+#include <@KWSYS_NAMESPACE@/hash_fun.hxx>
+#include <@KWSYS_NAMESPACE@/stl/functional> // equal_to
+
+#if defined(_MSC_VER)
+# pragma warning (push)
+# pragma warning (disable:4284)
+# pragma warning (disable:4786)
+#endif
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+# pragma set woff 1174
+# pragma set woff 1375
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+
+// select1st is an extension: it is not part of the standard.
+template <class T1, class T2>
+struct hash_select1st:
+ public @KWSYS_NAMESPACE@_stl::unary_function<@KWSYS_NAMESPACE@_stl::pair<T1, T2>, T1>
+{
+ const T1& operator()(const @KWSYS_NAMESPACE@_stl::pair<T1, T2>& __x) const
+ { return __x.first; }
+};
+
+// Forward declaration of equality operator; needed for friend declaration.
+
+template <class _Key, class _Tp,
+ class _HashFcn = hash<_Key>,
+ class _EqualKey = @KWSYS_NAMESPACE@_stl::equal_to<_Key>,
+ class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
+class hash_map;
+
+template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
+bool operator==(const hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>&,
+ const hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>&);
+
+template <class _Key, class _Tp, class _HashFcn, class _EqualKey,
+ class _Alloc>
+class hash_map
+{
+private:
+ typedef hashtable<@KWSYS_NAMESPACE@_stl::pair<const _Key,_Tp>,_Key,_HashFcn,
+ hash_select1st<const _Key,_Tp>,_EqualKey,_Alloc> _Ht;
+ _Ht _M_ht;
+
+public:
+ typedef typename _Ht::key_type key_type;
+ typedef _Tp data_type;
+ typedef _Tp mapped_type;
+ typedef typename _Ht::value_type value_type;
+ typedef typename _Ht::hasher hasher;
+ typedef typename _Ht::key_equal key_equal;
+
+ typedef typename _Ht::size_type size_type;
+ typedef typename _Ht::difference_type difference_type;
+ typedef typename _Ht::pointer pointer;
+ typedef typename _Ht::const_pointer const_pointer;
+ typedef typename _Ht::reference reference;
+ typedef typename _Ht::const_reference const_reference;
+
+ typedef typename _Ht::iterator iterator;
+ typedef typename _Ht::const_iterator const_iterator;
+
+ typedef typename _Ht::allocator_type allocator_type;
+
+ hasher hash_funct() const { return _M_ht.hash_funct(); }
+ key_equal key_eq() const { return _M_ht.key_eq(); }
+ allocator_type get_allocator() const { return _M_ht.get_allocator(); }
+
+public:
+ hash_map() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
+ explicit hash_map(size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
+ hash_map(size_type __n, const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
+ hash_map(size_type __n, const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a) {}
+
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ hash_map(_InputIterator __f, _InputIterator __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ template <class _InputIterator>
+ hash_map(_InputIterator __f, _InputIterator __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ template <class _InputIterator>
+ hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ template <class _InputIterator>
+ hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_unique(__f, __l); }
+
+#else
+ hash_map(const value_type* __f, const value_type* __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_map(const value_type* __f, const value_type* __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_map(const value_type* __f, const value_type* __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_map(const value_type* __f, const value_type* __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_unique(__f, __l); }
+
+ hash_map(const_iterator __f, const_iterator __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_map(const_iterator __f, const_iterator __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_map(const_iterator __f, const_iterator __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_map(const_iterator __f, const_iterator __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_unique(__f, __l); }
+#endif
+
+public:
+ size_type size() const { return _M_ht.size(); }
+ size_type max_size() const { return _M_ht.max_size(); }
+ bool empty() const { return _M_ht.empty(); }
+ void swap(hash_map& __hs) { _M_ht.swap(__hs._M_ht); }
+
+ friend bool operator==@KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS(const hash_map&,
+ const hash_map&);
+
+ iterator begin() { return _M_ht.begin(); }
+ iterator end() { return _M_ht.end(); }
+ const_iterator begin() const { return _M_ht.begin(); }
+ const_iterator end() const { return _M_ht.end(); }
+
+public:
+ @KWSYS_NAMESPACE@_stl::pair<iterator,bool> insert(const value_type& __obj)
+ { return _M_ht.insert_unique(__obj); }
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void insert(_InputIterator __f, _InputIterator __l)
+ { _M_ht.insert_unique(__f,__l); }
+#else
+ void insert(const value_type* __f, const value_type* __l) {
+ _M_ht.insert_unique(__f,__l);
+ }
+ void insert(const_iterator __f, const_iterator __l)
+ { _M_ht.insert_unique(__f, __l); }
+#endif
+ @KWSYS_NAMESPACE@_stl::pair<iterator,bool> insert_noresize(const value_type& __obj)
+ { return _M_ht.insert_unique_noresize(__obj); }
+
+ iterator find(const key_type& __key) { return _M_ht.find(__key); }
+ const_iterator find(const key_type& __key) const
+ { return _M_ht.find(__key); }
+
+ _Tp& operator[](const key_type& __key) {
+ return _M_ht.find_or_insert(value_type(__key, _Tp())).second;
+ }
+
+ size_type count(const key_type& __key) const { return _M_ht.count(__key); }
+
+ @KWSYS_NAMESPACE@_stl::pair<iterator, iterator> equal_range(const key_type& __key)
+ { return _M_ht.equal_range(__key); }
+ @KWSYS_NAMESPACE@_stl::pair<const_iterator, const_iterator>
+ equal_range(const key_type& __key) const
+ { return _M_ht.equal_range(__key); }
+
+ size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
+ void erase(iterator __it) { _M_ht.erase(__it); }
+ void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
+ void clear() { _M_ht.clear(); }
+
+ void resize(size_type __hint) { _M_ht.resize(__hint); }
+ size_type bucket_count() const { return _M_ht.bucket_count(); }
+ size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
+ size_type elems_in_bucket(size_type __n) const
+ { return _M_ht.elems_in_bucket(__n); }
+};
+
+template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
+bool
+operator==(const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
+ const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
+{
+ return __hm1._M_ht == __hm2._M_ht;
+}
+
+template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
+inline bool
+operator!=(const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
+ const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2) {
+ return !(__hm1 == __hm2);
+}
+
+template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
+inline void
+swap(hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
+ hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
+{
+ __hm1.swap(__hm2);
+}
+
+// Forward declaration of equality operator; needed for friend declaration.
+
+template <class _Key, class _Tp,
+ class _HashFcn = hash<_Key>,
+ class _EqualKey = @KWSYS_NAMESPACE@_stl::equal_to<_Key>,
+ class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
+class hash_multimap;
+
+template <class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
+bool
+operator==(const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm1,
+ const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm2);
+
+template <class _Key, class _Tp, class _HashFcn, class _EqualKey,
+ class _Alloc>
+class hash_multimap
+{
+private:
+ typedef hashtable<@KWSYS_NAMESPACE@_stl::pair<const _Key, _Tp>, _Key, _HashFcn,
+ hash_select1st<const _Key, _Tp>, _EqualKey, _Alloc>
+ _Ht;
+ _Ht _M_ht;
+
+public:
+ typedef typename _Ht::key_type key_type;
+ typedef _Tp data_type;
+ typedef _Tp mapped_type;
+ typedef typename _Ht::value_type value_type;
+ typedef typename _Ht::hasher hasher;
+ typedef typename _Ht::key_equal key_equal;
+
+ typedef typename _Ht::size_type size_type;
+ typedef typename _Ht::difference_type difference_type;
+ typedef typename _Ht::pointer pointer;
+ typedef typename _Ht::const_pointer const_pointer;
+ typedef typename _Ht::reference reference;
+ typedef typename _Ht::const_reference const_reference;
+
+ typedef typename _Ht::iterator iterator;
+ typedef typename _Ht::const_iterator const_iterator;
+
+ typedef typename _Ht::allocator_type allocator_type;
+
+ hasher hash_funct() const { return _M_ht.hash_funct(); }
+ key_equal key_eq() const { return _M_ht.key_eq(); }
+ allocator_type get_allocator() const { return _M_ht.get_allocator(); }
+
+public:
+ hash_multimap() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
+ explicit hash_multimap(size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
+ hash_multimap(size_type __n, const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
+ hash_multimap(size_type __n, const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a) {}
+
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ hash_multimap(_InputIterator __f, _InputIterator __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ template <class _InputIterator>
+ hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ template <class _InputIterator>
+ hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ template <class _InputIterator>
+ hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_equal(__f, __l); }
+
+#else
+ hash_multimap(const value_type* __f, const value_type* __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multimap(const value_type* __f, const value_type* __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_equal(__f, __l); }
+
+ hash_multimap(const_iterator __f, const_iterator __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multimap(const_iterator __f, const_iterator __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_equal(__f, __l); }
+#endif
+
+public:
+ size_type size() const { return _M_ht.size(); }
+ size_type max_size() const { return _M_ht.max_size(); }
+ bool empty() const { return _M_ht.empty(); }
+ void swap(hash_multimap& __hs) { _M_ht.swap(__hs._M_ht); }
+
+ friend bool operator==@KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS(const hash_multimap&,
+ const hash_multimap&);
+
+ iterator begin() { return _M_ht.begin(); }
+ iterator end() { return _M_ht.end(); }
+ const_iterator begin() const { return _M_ht.begin(); }
+ const_iterator end() const { return _M_ht.end(); }
+
+public:
+ iterator insert(const value_type& __obj)
+ { return _M_ht.insert_equal(__obj); }
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void insert(_InputIterator __f, _InputIterator __l)
+ { _M_ht.insert_equal(__f,__l); }
+#else
+ void insert(const value_type* __f, const value_type* __l) {
+ _M_ht.insert_equal(__f,__l);
+ }
+ void insert(const_iterator __f, const_iterator __l)
+ { _M_ht.insert_equal(__f, __l); }
+#endif
+ iterator insert_noresize(const value_type& __obj)
+ { return _M_ht.insert_equal_noresize(__obj); }
+
+ iterator find(const key_type& __key) { return _M_ht.find(__key); }
+ const_iterator find(const key_type& __key) const
+ { return _M_ht.find(__key); }
+
+ size_type count(const key_type& __key) const { return _M_ht.count(__key); }
+
+ @KWSYS_NAMESPACE@_stl::pair<iterator, iterator> equal_range(const key_type& __key)
+ { return _M_ht.equal_range(__key); }
+ @KWSYS_NAMESPACE@_stl::pair<const_iterator, const_iterator>
+ equal_range(const key_type& __key) const
+ { return _M_ht.equal_range(__key); }
+
+ size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
+ void erase(iterator __it) { _M_ht.erase(__it); }
+ void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
+ void clear() { _M_ht.clear(); }
+
+public:
+ void resize(size_type __hint) { _M_ht.resize(__hint); }
+ size_type bucket_count() const { return _M_ht.bucket_count(); }
+ size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
+ size_type elems_in_bucket(size_type __n) const
+ { return _M_ht.elems_in_bucket(__n); }
+};
+
+template <class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
+bool
+operator==(const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm1,
+ const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm2)
+{
+ return __hm1._M_ht == __hm2._M_ht;
+}
+
+template <class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
+inline bool
+operator!=(const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm1,
+ const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm2) {
+ return !(__hm1 == __hm2);
+}
+
+template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
+inline void
+swap(hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
+ hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
+{
+ __hm1.swap(__hm2);
+}
+
+} // namespace @KWSYS_NAMESPACE@
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+# pragma reset woff 1174
+# pragma reset woff 1375
+#endif
+
+#if defined(_MSC_VER)
+# pragma warning (pop)
+#endif
+
+#endif
diff --git a/Source/kwsys/hash_set.hxx.in b/Source/kwsys/hash_set.hxx.in
new file mode 100644
index 0000000000..5ee01a5943
--- /dev/null
+++ b/Source/kwsys/hash_set.hxx.in
@@ -0,0 +1,445 @@
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+#ifndef @KWSYS_NAMESPACE@_hash_set_hxx
+#define @KWSYS_NAMESPACE@_hash_set_hxx
+
+#include <@KWSYS_NAMESPACE@/hashtable.hxx>
+#include <@KWSYS_NAMESPACE@/hash_fun.hxx>
+#include <@KWSYS_NAMESPACE@/stl/functional> // equal_to
+
+#if defined(_MSC_VER)
+# pragma warning (push)
+# pragma warning (disable:4284)
+# pragma warning (disable:4786)
+#endif
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+# pragma set woff 1174
+# pragma set woff 1375
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+
+// identity is an extension: it is not part of the standard.
+template <class _Tp>
+struct _Identity : public @KWSYS_NAMESPACE@_stl::unary_function<_Tp,_Tp>
+{
+ const _Tp& operator()(const _Tp& __x) const { return __x; }
+};
+
+// Forward declaration of equality operator; needed for friend declaration.
+
+template <class _Value,
+ class _HashFcn = hash<_Value>,
+ class _EqualKey = @KWSYS_NAMESPACE@_stl::equal_to<_Value>,
+ class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
+class hash_set;
+
+template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
+bool
+operator==(const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs1,
+ const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs2);
+
+template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
+class hash_set
+{
+private:
+ typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
+ _EqualKey, _Alloc> _Ht;
+ _Ht _M_ht;
+
+public:
+ typedef typename _Ht::key_type key_type;
+ typedef typename _Ht::value_type value_type;
+ typedef typename _Ht::hasher hasher;
+ typedef typename _Ht::key_equal key_equal;
+
+ typedef typename _Ht::size_type size_type;
+ typedef typename _Ht::difference_type difference_type;
+ typedef typename _Ht::const_pointer pointer;
+ typedef typename _Ht::const_pointer const_pointer;
+ typedef typename _Ht::const_reference reference;
+ typedef typename _Ht::const_reference const_reference;
+
+ typedef typename _Ht::const_iterator iterator;
+ typedef typename _Ht::const_iterator const_iterator;
+
+ typedef typename _Ht::allocator_type allocator_type;
+
+ hasher hash_funct() const { return _M_ht.hash_funct(); }
+ key_equal key_eq() const { return _M_ht.key_eq(); }
+ allocator_type get_allocator() const { return _M_ht.get_allocator(); }
+
+public:
+ hash_set()
+ : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
+ explicit hash_set(size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
+ hash_set(size_type __n, const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
+ hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a) {}
+
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ hash_set(_InputIterator __f, _InputIterator __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ template <class _InputIterator>
+ hash_set(_InputIterator __f, _InputIterator __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ template <class _InputIterator>
+ hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ template <class _InputIterator>
+ hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_unique(__f, __l); }
+#else
+
+ hash_set(const value_type* __f, const value_type* __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_set(const value_type* __f, const value_type* __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_set(const value_type* __f, const value_type* __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_set(const value_type* __f, const value_type* __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_unique(__f, __l); }
+
+ hash_set(const_iterator __f, const_iterator __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_set(const_iterator __f, const_iterator __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_set(const_iterator __f, const_iterator __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_unique(__f, __l); }
+ hash_set(const_iterator __f, const_iterator __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_unique(__f, __l); }
+#endif
+
+public:
+ size_type size() const { return _M_ht.size(); }
+ size_type max_size() const { return _M_ht.max_size(); }
+ bool empty() const { return _M_ht.empty(); }
+ void swap(hash_set& __hs) { _M_ht.swap(__hs._M_ht); }
+
+ friend bool operator==@KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS(const hash_set&,
+ const hash_set&);
+
+ iterator begin() const { return _M_ht.begin(); }
+ iterator end() const { return _M_ht.end(); }
+
+public:
+ @KWSYS_NAMESPACE@_stl::pair<iterator, bool> insert(const value_type& __obj)
+ {
+ typedef typename _Ht::iterator _Ht_iterator;
+ @KWSYS_NAMESPACE@_stl::pair<_Ht_iterator, bool> __p = _M_ht.insert_unique(__obj);
+ return @KWSYS_NAMESPACE@_stl::pair<iterator,bool>(__p.first, __p.second);
+ }
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void insert(_InputIterator __f, _InputIterator __l)
+ { _M_ht.insert_unique(__f,__l); }
+#else
+ void insert(const value_type* __f, const value_type* __l) {
+ _M_ht.insert_unique(__f,__l);
+ }
+ void insert(const_iterator __f, const_iterator __l)
+ {_M_ht.insert_unique(__f, __l); }
+#endif
+ @KWSYS_NAMESPACE@_stl::pair<iterator, bool> insert_noresize(const value_type& __obj)
+ {
+ typedef typename _Ht::iterator _Ht_iterator;
+ @KWSYS_NAMESPACE@_stl::pair<_Ht_iterator, bool> __p =
+ _M_ht.insert_unique_noresize(__obj);
+ return @KWSYS_NAMESPACE@_stl::pair<iterator, bool>(__p.first, __p.second);
+ }
+
+ iterator find(const key_type& __key) const { return _M_ht.find(__key); }
+
+ size_type count(const key_type& __key) const { return _M_ht.count(__key); }
+
+ @KWSYS_NAMESPACE@_stl::pair<iterator, iterator> equal_range(const key_type& __key) const
+ { return _M_ht.equal_range(__key); }
+
+ size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
+ void erase(iterator __it) { _M_ht.erase(__it); }
+ void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
+ void clear() { _M_ht.clear(); }
+
+public:
+ void resize(size_type __hint) { _M_ht.resize(__hint); }
+ size_type bucket_count() const { return _M_ht.bucket_count(); }
+ size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
+ size_type elems_in_bucket(size_type __n) const
+ { return _M_ht.elems_in_bucket(__n); }
+};
+
+template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
+bool
+operator==(const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs1,
+ const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs2)
+{
+ return __hs1._M_ht == __hs2._M_ht;
+}
+
+template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
+inline bool
+operator!=(const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs1,
+ const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs2) {
+ return !(__hs1 == __hs2);
+}
+
+template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
+inline void
+swap(hash_set<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
+ hash_set<_Val,_HashFcn,_EqualKey,_Alloc>& __hs2)
+{
+ __hs1.swap(__hs2);
+}
+
+template <class _Value,
+ class _HashFcn = hash<_Value>,
+ class _EqualKey = @KWSYS_NAMESPACE@_stl::equal_to<_Value>,
+ class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
+class hash_multiset;
+
+template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
+bool
+operator==(const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
+ const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs2);
+
+
+template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
+class hash_multiset
+{
+private:
+ typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
+ _EqualKey, _Alloc> _Ht;
+ _Ht _M_ht;
+
+public:
+ typedef typename _Ht::key_type key_type;
+ typedef typename _Ht::value_type value_type;
+ typedef typename _Ht::hasher hasher;
+ typedef typename _Ht::key_equal key_equal;
+
+ typedef typename _Ht::size_type size_type;
+ typedef typename _Ht::difference_type difference_type;
+ typedef typename _Ht::const_pointer pointer;
+ typedef typename _Ht::const_pointer const_pointer;
+ typedef typename _Ht::const_reference reference;
+ typedef typename _Ht::const_reference const_reference;
+
+ typedef typename _Ht::const_iterator iterator;
+ typedef typename _Ht::const_iterator const_iterator;
+
+ typedef typename _Ht::allocator_type allocator_type;
+
+ hasher hash_funct() const { return _M_ht.hash_funct(); }
+ key_equal key_eq() const { return _M_ht.key_eq(); }
+ allocator_type get_allocator() const { return _M_ht.get_allocator(); }
+
+public:
+ hash_multiset()
+ : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
+ explicit hash_multiset(size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
+ hash_multiset(size_type __n, const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
+ hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a) {}
+
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ hash_multiset(_InputIterator __f, _InputIterator __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ template <class _InputIterator>
+ hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ template <class _InputIterator>
+ hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ template <class _InputIterator>
+ hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_equal(__f, __l); }
+#else
+
+ hash_multiset(const value_type* __f, const value_type* __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multiset(const value_type* __f, const value_type* __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multiset(const value_type* __f, const value_type* __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multiset(const value_type* __f, const value_type* __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_equal(__f, __l); }
+
+ hash_multiset(const_iterator __f, const_iterator __l)
+ : _M_ht(100, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multiset(const_iterator __f, const_iterator __l, size_type __n)
+ : _M_ht(__n, hasher(), key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multiset(const_iterator __f, const_iterator __l, size_type __n,
+ const hasher& __hf)
+ : _M_ht(__n, __hf, key_equal(), allocator_type())
+ { _M_ht.insert_equal(__f, __l); }
+ hash_multiset(const_iterator __f, const_iterator __l, size_type __n,
+ const hasher& __hf, const key_equal& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_ht(__n, __hf, __eql, __a)
+ { _M_ht.insert_equal(__f, __l); }
+#endif
+
+public:
+ size_type size() const { return _M_ht.size(); }
+ size_type max_size() const { return _M_ht.max_size(); }
+ bool empty() const { return _M_ht.empty(); }
+ void swap(hash_multiset& hs) { _M_ht.swap(hs._M_ht); }
+
+ friend bool operator==@KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS(const hash_multiset&,
+ const hash_multiset&);
+
+ iterator begin() const { return _M_ht.begin(); }
+ iterator end() const { return _M_ht.end(); }
+
+public:
+ iterator insert(const value_type& __obj)
+ { return _M_ht.insert_equal(__obj); }
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void insert(_InputIterator __f, _InputIterator __l)
+ { _M_ht.insert_equal(__f,__l); }
+#else
+ void insert(const value_type* __f, const value_type* __l) {
+ _M_ht.insert_equal(__f,__l);
+ }
+ void insert(const_iterator __f, const_iterator __l)
+ { _M_ht.insert_equal(__f, __l); }
+#endif
+ iterator insert_noresize(const value_type& __obj)
+ { return _M_ht.insert_equal_noresize(__obj); }
+
+ iterator find(const key_type& __key) const { return _M_ht.find(__key); }
+
+ size_type count(const key_type& __key) const { return _M_ht.count(__key); }
+
+ @KWSYS_NAMESPACE@_stl::pair<iterator, iterator> equal_range(const key_type& __key) const
+ { return _M_ht.equal_range(__key); }
+
+ size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
+ void erase(iterator __it) { _M_ht.erase(__it); }
+ void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
+ void clear() { _M_ht.clear(); }
+
+public:
+ void resize(size_type __hint) { _M_ht.resize(__hint); }
+ size_type bucket_count() const { return _M_ht.bucket_count(); }
+ size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
+ size_type elems_in_bucket(size_type __n) const
+ { return _M_ht.elems_in_bucket(__n); }
+};
+
+template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
+bool
+operator==(const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
+ const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs2)
+{
+ return __hs1._M_ht == __hs2._M_ht;
+}
+
+template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
+inline bool
+operator!=(const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
+ const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs2) {
+ return !(__hs1 == __hs2);
+}
+
+template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
+inline void
+swap(hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
+ hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs2) {
+ __hs1.swap(__hs2);
+}
+
+} // namespace @KWSYS_NAMESPACE@
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+# pragma reset woff 1174
+# pragma reset woff 1375
+#endif
+
+#if defined(_MSC_VER)
+# pragma warning (pop)
+#endif
+
+#endif
diff --git a/Source/kwsys/hashtable.hxx.in b/Source/kwsys/hashtable.hxx.in
new file mode 100644
index 0000000000..307f6bc1f9
--- /dev/null
+++ b/Source/kwsys/hashtable.hxx.in
@@ -0,0 +1,1296 @@
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+#ifdef __BORLANDC__
+# pragma warn -8027 /* 'for' not inlined. */
+# pragma warn -8026 /* 'exception' not inlined. */
+#endif
+
+#ifndef @KWSYS_NAMESPACE@_hashtable_hxx
+#define @KWSYS_NAMESPACE@_hashtable_hxx
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+#include <@KWSYS_NAMESPACE@/cstddef> // size_t
+#include <@KWSYS_NAMESPACE@/stl/algorithm> // lower_bound
+#include <@KWSYS_NAMESPACE@/stl/functional> // unary_function
+#include <@KWSYS_NAMESPACE@/stl/iterator> // iterator_traits
+#include <@KWSYS_NAMESPACE@/stl/memory> // allocator
+#include <@KWSYS_NAMESPACE@/stl/utility> // pair
+#include <@KWSYS_NAMESPACE@/stl/vector> // vector
+
+#if defined(_MSC_VER)
+# pragma warning (push)
+# pragma warning (disable:4284)
+# pragma warning (disable:4786)
+# pragma warning (disable:4512) /* no assignment operator for class */
+#endif
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 3970 /* pointer to int conversion */ 3321 3968
+#endif
+
+// In C++11, clang will warn about using dynamic exception specifications
+// as they are deprecated. But as this class is trying to faithfully
+// mimic unordered_set and unordered_map, we want to keep the 'throw()'
+// decorations below. So we suppress the warning.
+#if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wdeprecated")
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated"
+# endif
+#endif
+
+#if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_TEMPLATE
+# define @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(T) @KWSYS_NAMESPACE@_stl::allocator< T >
+#elif @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
+# define @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(T) @KWSYS_NAMESPACE@_stl::allocator
+#else
+# define @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(T) @KWSYS_NAMESPACE@_stl::alloc
+#endif
+
+#if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_OBJECTS
+# define @KWSYS_NAMESPACE@_HASH_BUCKETS_INIT(__a) _M_buckets(__a)
+# define @KWSYS_NAMESPACE@_HASH_BUCKETS_GET_ALLOCATOR(__b) , __b.get_allocator()
+#else
+# define @KWSYS_NAMESPACE@_HASH_BUCKETS_INIT(__a) _M_buckets()
+# define @KWSYS_NAMESPACE@_HASH_BUCKETS_GET_ALLOCATOR(__b)
+#endif
+
+namespace @KWSYS_NAMESPACE@
+{
+
+//----------------------------------------------------------------------------
+// Define an allocator adaptor for platforms that do not provide an
+// allocator with the rebind member.
+#if !@KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND
+
+// Utility functions to convert item counts.
+inline size_t hash_sizeof(void*) { return sizeof(char); }
+inline size_t hash_sizeof(const void*) { return sizeof(char); }
+template <class TPtr> inline size_t hash_sizeof(TPtr p)
+{
+ static_cast<void>(p);
+ return sizeof(*p);
+}
+template <class POut, class PIn, class TSize>
+inline TSize hash_allocator_n(POut out, PIn in, TSize n)
+{
+ return n*(hash_sizeof(out)/hash_sizeof(in) +
+ (hash_sizeof(out)%hash_sizeof(in)>0));
+}
+
+// Define an allocation method to use the native allocator with
+// the proper signature. The following signatures of the allocate
+// method are used on various STL implementations:
+// pointer allocate(size_type, const void* hint)
+// pointer allocate(size_type)
+// static pointer allocate(size_type, const void* hint)
+// static pointer allocate(size_type)
+// Where pointer might be a real type or void*.
+// This set of overloads decodes the signature for a particular STL.
+// The extra three int/long arguments will favor certain signatures
+// over others in the case that multiple are present to avoid
+// ambiguity errors.
+template <class TAlloc, class PIn, class TSize, class THint, class POut>
+inline void hash_allocate(TAlloc* a, PIn (TAlloc::*allocate)(TSize, THint),
+ TSize n_out, const void* hint, POut& out,
+ int, int, int)
+{
+ TSize n_in = hash_allocator_n(POut(), PIn(), n_out);
+ void* vout = (a->*allocate)(n_in, const_cast<THint>(hint));
+ out = static_cast<POut>(vout);
+}
+
+template <class TAlloc, class PIn, class TSize, class POut>
+inline void hash_allocate(TAlloc* a, PIn (TAlloc::*allocate)(TSize),
+ TSize n_out, const void*, POut& out,
+ int, int, long)
+{
+ TSize n_in = hash_allocator_n(POut(), PIn(), n_out);
+ void* vout = (a->*allocate)(n_in);
+ out = static_cast<POut>(vout);
+}
+
+template <class PIn, class TSize, class THint, class POut>
+inline void hash_allocate(void*, PIn (*allocate)(TSize, THint),
+ TSize n_out, const void* hint, POut& out,
+ int, long, long)
+{
+ TSize n_in = hash_allocator_n(POut(), PIn(), n_out);
+ void* vout = allocate(n_in, const_cast<THint>(hint));
+ out = static_cast<POut>(vout);
+}
+
+template <class PIn, class TSize, class POut>
+inline void hash_allocate(void*, PIn (*allocate)(TSize),
+ TSize n_out, const void*, POut& out,
+ long, long, long)
+{
+ TSize n_in = hash_allocator_n(POut(), PIn(), n_out);
+ void* vout = allocate(n_in);
+ out = static_cast<POut>(vout);
+}
+
+// Define a deallocation method to use the native allocator with
+// the proper signature. The following signatures of the deallocate
+// method are used on various STL implementations:
+// void deallocate(pointer, size_type)
+// void deallocate(pointer)
+// static void deallocate(pointer, size_type)
+// static void deallocate(pointer)
+// Where pointer might be a real type or void*.
+// This set of overloads decodes the signature for a particular STL.
+// The extra three int/long arguments will favor certain signatures
+// over others in the case that multiple are present to avoid
+// ambiguity errors.
+template <class TAlloc, class PIn, class TSize, class PInReal, class POut>
+inline void hash_deallocate(TAlloc* a, void (TAlloc::*deallocate)(PIn, TSize),
+ PInReal, POut p, TSize n_out, int, int, int)
+{
+ TSize n_in = hash_allocator_n(POut(), PInReal(), n_out);
+ void* vout = p;
+ (a->*deallocate)(static_cast<PIn>(vout), n_in);
+}
+
+template <class TAlloc, class PIn, class TSize, class PInReal, class POut>
+inline void hash_deallocate(TAlloc* a, void (TAlloc::*deallocate)(PIn),
+ PInReal, POut p, TSize, int, int, long)
+{
+ void* vout = p;
+ (a->*deallocate)(static_cast<PIn>(vout));
+}
+
+template <class PIn, class TSize, class PInReal, class POut>
+inline void hash_deallocate(void*, void (*deallocate)(PIn, TSize),
+ PInReal, POut p, TSize n_out, int, long, long)
+{
+ TSize n_in = hash_allocator_n(POut(), PInReal(), n_out);
+ void* vout = p;
+ deallocate(static_cast<PIn>(vout), n_in);
+}
+
+template <class PIn, class TSize, class PInReal, class POut>
+inline void hash_deallocate(void*, void (*deallocate)(PIn),
+ PInReal, POut p, TSize, long, long, long)
+{
+ void* vout = p;
+ deallocate(static_cast<PIn>(vout));
+}
+
+// Use the same four overloads as hash_allocate to decode the type
+// really used for allocation. This is passed as PInReal to the
+// deallocate functions so that hash_allocator_n has the proper size.
+template <class TAlloc, class PIn, class TSize, class THint>
+inline PIn hash_allocate_type(PIn (TAlloc::*)(TSize, THint),
+ int, int, int) { return 0; }
+template <class TAlloc, class PIn, class TSize>
+inline PIn hash_allocate_type(PIn (TAlloc::*)(TSize),
+ int, int, long) { return 0; }
+template <class PIn, class TSize, class THint>
+inline PIn hash_allocate_type(PIn (*)(TSize, THint),
+ int, long, long) { return 0; }
+template <class PIn, class TSize>
+inline PIn hash_allocate_type(PIn (*)(TSize),
+ long, long, long) { return 0; }
+
+// Define the comparison operators in terms of a base type to avoid
+// needing templated versions.
+class hash_allocator_base {};
+inline bool operator==(const hash_allocator_base&,
+ const hash_allocator_base&) throw() { return true; }
+inline bool operator!=(const hash_allocator_base&,
+ const hash_allocator_base&) throw() { return false; }
+
+// Define the allocator template.
+template <class T, class Alloc>
+class hash_allocator: public hash_allocator_base
+{
+private:
+ // Store the real allocator privately.
+ typedef Alloc alloc_type;
+ alloc_type alloc_;
+
+public:
+ // Standard allocator interface.
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef T& reference;
+ typedef const T& const_reference;
+ typedef T value_type;
+
+ hash_allocator() throw(): alloc_() {}
+ hash_allocator(const hash_allocator_base&) throw() : alloc_() {}
+ hash_allocator(const hash_allocator& a) throw() : alloc_(a.alloc_) {}
+ hash_allocator(const alloc_type& a) throw() : alloc_(a) {}
+ ~hash_allocator() throw() {}
+# if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
+ template <class U>
+ struct rebind { typedef hash_allocator<U, alloc_type> other; };
+# endif
+ pointer address(reference x) const { return &x; }
+ const_pointer address(const_reference x) const { return &x; }
+ typedef void* void_pointer;
+ typedef const void* const_void_pointer;
+ pointer allocate(size_type n=1, const_void_pointer hint = 0)
+ {
+ if(n)
+ {
+ pointer p;
+ hash_allocate(&alloc_, &alloc_type::allocate, n, hint, p, 1, 1, 1);
+ return p;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ void deallocate(pointer p, size_type n=1)
+ {
+ if(n)
+ {
+ hash_deallocate(&alloc_, &alloc_type::deallocate,
+ hash_allocate_type(&alloc_type::allocate, 1, 1, 1),
+ p, n, 1, 1, 1);
+ }
+ }
+#if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
+ size_type max_size(size_type s) const throw()
+ {
+ return alloc_.max_size(s);
+ }
+#else
+ size_type max_size() const throw()
+ {
+ size_type n = alloc_.max_size() / sizeof(value_type);
+ return n>0? n:1;
+ }
+#endif
+ void construct(pointer p, const value_type& val) { new (p) value_type(val); }
+ void destroy(pointer p) { (void)p; p->~value_type(); }
+};
+#endif
+
+template <class _Val>
+struct _Hashtable_node
+{
+ _Hashtable_node* _M_next;
+ _Val _M_val;
+ void public_method_to_quiet_warning_about_all_methods_private();
+private:
+ void operator=(_Hashtable_node<_Val> const&); // poison node assignment
+};
+
+template <class _Val, class _Key, class _HashFcn,
+ class _ExtractKey, class _EqualKey,
+ class _Alloc = @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(char) >
+class hashtable;
+
+template <class _Val, class _Key, class _HashFcn,
+ class _ExtractKey, class _EqualKey, class _Alloc>
+struct _Hashtable_iterator;
+
+template <class _Val, class _Key, class _HashFcn,
+ class _ExtractKey, class _EqualKey, class _Alloc>
+struct _Hashtable_const_iterator;
+
+template <class _Val, class _Key, class _HashFcn,
+ class _ExtractKey, class _EqualKey, class _Alloc>
+struct _Hashtable_iterator {
+ typedef hashtable<_Val,_Key,_HashFcn,_ExtractKey,_EqualKey,_Alloc>
+ _Hashtable;
+ typedef _Hashtable_iterator<_Val, _Key, _HashFcn,
+ _ExtractKey, _EqualKey, _Alloc>
+ iterator;
+ typedef _Hashtable_const_iterator<_Val, _Key, _HashFcn,
+ _ExtractKey, _EqualKey, _Alloc>
+ const_iterator;
+ typedef _Hashtable_node<_Val> _Node;
+
+ typedef @KWSYS_NAMESPACE@_stl::forward_iterator_tag iterator_category;
+ typedef _Val value_type;
+ typedef ptrdiff_t difference_type;
+ typedef size_t size_type;
+ typedef _Val& reference;
+ typedef _Val* pointer;
+
+ _Node* _M_cur;
+ _Hashtable* _M_ht;
+
+ _Hashtable_iterator(_Node* __n, _Hashtable* __tab)
+ : _M_cur(__n), _M_ht(__tab) {}
+ _Hashtable_iterator() {}
+ reference operator*() const { return _M_cur->_M_val; }
+ pointer operator->() const { return &(operator*()); }
+ iterator& operator++();
+ iterator operator++(int);
+ bool operator==(const iterator& __it) const
+ { return _M_cur == __it._M_cur; }
+ bool operator!=(const iterator& __it) const
+ { return _M_cur != __it._M_cur; }
+};
+
+
+template <class _Val, class _Key, class _HashFcn,
+ class _ExtractKey, class _EqualKey, class _Alloc>
+struct _Hashtable_const_iterator {
+ typedef hashtable<_Val,_Key,_HashFcn,_ExtractKey,_EqualKey,_Alloc>
+ _Hashtable;
+ typedef _Hashtable_iterator<_Val,_Key,_HashFcn,
+ _ExtractKey,_EqualKey,_Alloc>
+ iterator;
+ typedef _Hashtable_const_iterator<_Val, _Key, _HashFcn,
+ _ExtractKey, _EqualKey, _Alloc>
+ const_iterator;
+ typedef _Hashtable_node<_Val> _Node;
+
+ typedef @KWSYS_NAMESPACE@_stl::forward_iterator_tag iterator_category;
+ typedef _Val value_type;
+ typedef ptrdiff_t difference_type;
+ typedef size_t size_type;
+ typedef const _Val& reference;
+ typedef const _Val* pointer;
+
+ const _Node* _M_cur;
+ const _Hashtable* _M_ht;
+
+ _Hashtable_const_iterator(const _Node* __n, const _Hashtable* __tab)
+ : _M_cur(__n), _M_ht(__tab) {}
+ _Hashtable_const_iterator() {}
+ _Hashtable_const_iterator(const iterator& __it)
+ : _M_cur(__it._M_cur), _M_ht(__it._M_ht) {}
+ reference operator*() const { return _M_cur->_M_val; }
+ pointer operator->() const { return &(operator*()); }
+ const_iterator& operator++();
+ const_iterator operator++(int);
+ bool operator==(const const_iterator& __it) const
+ { return _M_cur == __it._M_cur; }
+ bool operator!=(const const_iterator& __it) const
+ { return _M_cur != __it._M_cur; }
+};
+
+// Note: assumes long is at least 32 bits.
+enum { _stl_num_primes = 31 };
+
+// create a function with a static local to that function that returns
+// the static
+static inline const unsigned long* get_stl_prime_list() {
+
+static const unsigned long _stl_prime_list[_stl_num_primes] =
+{
+ 5ul, 11ul, 23ul,
+ 53ul, 97ul, 193ul, 389ul, 769ul,
+ 1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
+ 49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
+ 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
+ 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
+ 1610612741ul, 3221225473ul, 4294967291ul
+};
+
+return &_stl_prime_list[0]; }
+
+inline size_t _stl_next_prime(size_t __n)
+{
+ const unsigned long* __first = get_stl_prime_list();
+ const unsigned long* __last = get_stl_prime_list() + (int)_stl_num_primes;
+ const unsigned long* pos = @KWSYS_NAMESPACE@_stl::lower_bound(__first, __last, __n);
+ return pos == __last ? *(__last - 1) : *pos;
+}
+
+// Forward declaration of operator==.
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+class hashtable;
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+bool operator==(const hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>& __ht1,
+ const hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>& __ht2);
+
+// Hashtables handle allocators a bit differently than other containers
+// do. If we're using standard-conforming allocators, then a hashtable
+// unconditionally has a member variable to hold its allocator, even if
+// it so happens that all instances of the allocator type are identical.
+// This is because, for hashtables, this extra storage is negligible.
+// Additionally, a base class wouldn't serve any other purposes; it
+// wouldn't, for example, simplify the exception-handling code.
+
+template <class _Val, class _Key, class _HashFcn,
+ class _ExtractKey, class _EqualKey, class _Alloc>
+class hashtable {
+public:
+ typedef _Key key_type;
+ typedef _Val value_type;
+ typedef _HashFcn hasher;
+ typedef _EqualKey key_equal;
+
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+
+ hasher hash_funct() const { return _M_hash; }
+ key_equal key_eq() const { return _M_equals; }
+
+private:
+ typedef _Hashtable_node<_Val> _Node;
+
+#if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND
+public:
+ typedef typename _Alloc::template rebind<_Val>::other allocator_type;
+ allocator_type get_allocator() const { return _M_node_allocator; }
+private:
+ typedef typename _Alloc::template rebind<_Node>::other _M_node_allocator_type;
+ typedef typename _Alloc::template rebind<_Node*>::other _M_node_ptr_allocator_type;
+ typedef @KWSYS_NAMESPACE@_stl::vector<_Node*,_M_node_ptr_allocator_type> _M_buckets_type;
+#else
+public:
+ typedef hash_allocator<_Val, _Alloc> allocator_type;
+ allocator_type get_allocator() const { return allocator_type(); }
+private:
+ typedef hash_allocator<_Node, _Alloc> _M_node_allocator_type;
+# if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_OBJECTS
+ typedef hash_allocator<_Node*, _Alloc> _M_node_ptr_allocator_type;
+# else
+ typedef _Alloc _M_node_ptr_allocator_type;
+# endif
+ typedef @KWSYS_NAMESPACE@_stl::vector<_Node*,_M_node_ptr_allocator_type> _M_buckets_type;
+#endif
+
+private:
+ _M_node_allocator_type _M_node_allocator;
+ hasher _M_hash;
+ key_equal _M_equals;
+ _ExtractKey _M_get_key;
+ _M_buckets_type _M_buckets;
+ size_type _M_num_elements;
+
+ _Node* _M_get_node() { return _M_node_allocator.allocate(1); }
+ void _M_put_node(_Node* __p) { _M_node_allocator.deallocate(__p, 1); }
+
+public:
+ typedef _Hashtable_iterator<_Val,_Key,_HashFcn,_ExtractKey,_EqualKey,_Alloc>
+ iterator;
+ typedef _Hashtable_const_iterator<_Val,_Key,_HashFcn,_ExtractKey,_EqualKey,
+ _Alloc>
+ const_iterator;
+
+ friend struct
+ _Hashtable_iterator<_Val,_Key,_HashFcn,_ExtractKey,_EqualKey,_Alloc>;
+ friend struct
+ _Hashtable_const_iterator<_Val,_Key,_HashFcn,_ExtractKey,_EqualKey,_Alloc>;
+
+public:
+ hashtable(size_type __n,
+ const _HashFcn& __hf,
+ const _EqualKey& __eql,
+ const _ExtractKey& __ext,
+ const allocator_type& __a = allocator_type())
+ : _M_node_allocator(__a),
+ _M_hash(__hf),
+ _M_equals(__eql),
+ _M_get_key(__ext),
+ @KWSYS_NAMESPACE@_HASH_BUCKETS_INIT(__a),
+ _M_num_elements(0)
+ {
+ _M_initialize_buckets(__n);
+ }
+
+ hashtable(size_type __n,
+ const _HashFcn& __hf,
+ const _EqualKey& __eql,
+ const allocator_type& __a = allocator_type())
+ : _M_node_allocator(__a),
+ _M_hash(__hf),
+ _M_equals(__eql),
+ _M_get_key(_ExtractKey()),
+ @KWSYS_NAMESPACE@_HASH_BUCKETS_INIT(__a),
+ _M_num_elements(0)
+ {
+ _M_initialize_buckets(__n);
+ }
+
+ hashtable(const hashtable& __ht)
+ : _M_node_allocator(__ht.get_allocator()),
+ _M_hash(__ht._M_hash),
+ _M_equals(__ht._M_equals),
+ _M_get_key(__ht._M_get_key),
+ @KWSYS_NAMESPACE@_HASH_BUCKETS_INIT(__ht.get_allocator()),
+ _M_num_elements(0)
+ {
+ _M_copy_from(__ht);
+ }
+
+ hashtable& operator= (const hashtable& __ht)
+ {
+ if (&__ht != this) {
+ clear();
+ _M_hash = __ht._M_hash;
+ _M_equals = __ht._M_equals;
+ _M_get_key = __ht._M_get_key;
+ _M_copy_from(__ht);
+ }
+ return *this;
+ }
+
+ ~hashtable() { clear(); }
+
+ size_type size() const { return _M_num_elements; }
+ size_type max_size() const { return size_type(-1); }
+ bool empty() const { return size() == 0; }
+
+ void swap(hashtable& __ht)
+ {
+ @KWSYS_NAMESPACE@_stl::swap(_M_hash, __ht._M_hash);
+ @KWSYS_NAMESPACE@_stl::swap(_M_equals, __ht._M_equals);
+ @KWSYS_NAMESPACE@_stl::swap(_M_get_key, __ht._M_get_key);
+ _M_buckets.swap(__ht._M_buckets);
+ @KWSYS_NAMESPACE@_stl::swap(_M_num_elements, __ht._M_num_elements);
+ }
+
+ iterator begin()
+ {
+ for (size_type __n = 0; __n < _M_buckets.size(); ++__n)
+ if (_M_buckets[__n])
+ return iterator(_M_buckets[__n], this);
+ return end();
+ }
+
+ iterator end() { return iterator(0, this); }
+
+ const_iterator begin() const
+ {
+ for (size_type __n = 0; __n < _M_buckets.size(); ++__n)
+ if (_M_buckets[__n])
+ return const_iterator(_M_buckets[__n], this);
+ return end();
+ }
+
+ const_iterator end() const { return const_iterator(0, this); }
+
+ friend bool operator==@KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS(const hashtable&,
+ const hashtable&);
+
+public:
+
+ size_type bucket_count() const { return _M_buckets.size(); }
+
+ size_type max_bucket_count() const
+ { return get_stl_prime_list()[(int)_stl_num_primes - 1]; }
+
+ size_type elems_in_bucket(size_type __bucket) const
+ {
+ size_type __result = 0;
+ for (_Node* __cur = _M_buckets[__bucket]; __cur; __cur = __cur->_M_next)
+ __result += 1;
+ return __result;
+ }
+
+ @KWSYS_NAMESPACE@_stl::pair<iterator, bool> insert_unique(const value_type& __obj)
+ {
+ resize(_M_num_elements + 1);
+ return insert_unique_noresize(__obj);
+ }
+
+ iterator insert_equal(const value_type& __obj)
+ {
+ resize(_M_num_elements + 1);
+ return insert_equal_noresize(__obj);
+ }
+
+ @KWSYS_NAMESPACE@_stl::pair<iterator, bool> insert_unique_noresize(const value_type& __obj);
+ iterator insert_equal_noresize(const value_type& __obj);
+
+#if @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_TRAITS
+# define @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(T,I) \
+ typename @KWSYS_NAMESPACE@_stl::iterator_traits< T >::iterator_category()
+#elif @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_CATEGORY
+# define @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(T,I) \
+ @KWSYS_NAMESPACE@_stl::iterator_category( I )
+#elif @KWSYS_NAMESPACE@_STL_HAS___ITERATOR_CATEGORY
+# define @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(T,I) \
+ @KWSYS_NAMESPACE@_stl::__iterator_category( I )
+#endif
+
+#if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES && defined(@KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY)
+ template <class _InputIterator>
+ void insert_unique(_InputIterator __f, _InputIterator __l)
+ {
+ insert_unique(__f, __l,
+ @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(_InputIterator, __f));
+ }
+
+ template <class _InputIterator>
+ void insert_equal(_InputIterator __f, _InputIterator __l)
+ {
+ insert_equal(__f, __l,
+ @KWSYS_NAMESPACE@_HASH_ITERATOR_CATEGORY(_InputIterator, __f));
+ }
+
+ template <class _InputIterator>
+ void insert_unique(_InputIterator __f, _InputIterator __l,
+ @KWSYS_NAMESPACE@_stl::input_iterator_tag)
+ {
+ for ( ; __f != __l; ++__f)
+ insert_unique(*__f);
+ }
+
+ template <class _InputIterator>
+ void insert_equal(_InputIterator __f, _InputIterator __l,
+ @KWSYS_NAMESPACE@_stl::input_iterator_tag)
+ {
+ for ( ; __f != __l; ++__f)
+ insert_equal(*__f);
+ }
+
+ template <class _ForwardIterator>
+ void insert_unique(_ForwardIterator __f, _ForwardIterator __l,
+ @KWSYS_NAMESPACE@_stl::forward_iterator_tag)
+ {
+ size_type __n = 0;
+ @KWSYS_NAMESPACE@_stl::distance(__f, __l, __n);
+ resize(_M_num_elements + __n);
+ for ( ; __n > 0; --__n, ++__f)
+ insert_unique_noresize(*__f);
+ }
+
+ template <class _ForwardIterator>
+ void insert_equal(_ForwardIterator __f, _ForwardIterator __l,
+ @KWSYS_NAMESPACE@_stl::forward_iterator_tag)
+ {
+ size_type __n = 0;
+ @KWSYS_NAMESPACE@_stl::distance(__f, __l, __n);
+ resize(_M_num_elements + __n);
+ for ( ; __n > 0; --__n, ++__f)
+ insert_equal_noresize(*__f);
+ }
+
+#else
+ void insert_unique(const value_type* __f, const value_type* __l)
+ {
+ size_type __n = __l - __f;
+ resize(_M_num_elements + __n);
+ for ( ; __n > 0; --__n, ++__f)
+ insert_unique_noresize(*__f);
+ }
+
+ void insert_equal(const value_type* __f, const value_type* __l)
+ {
+ size_type __n = __l - __f;
+ resize(_M_num_elements + __n);
+ for ( ; __n > 0; --__n, ++__f)
+ insert_equal_noresize(*__f);
+ }
+
+ void insert_unique(const_iterator __f, const_iterator __l)
+ {
+ size_type __n = 0;
+ @KWSYS_NAMESPACE@_stl::distance(__f, __l, __n);
+ resize(_M_num_elements + __n);
+ for ( ; __n > 0; --__n, ++__f)
+ insert_unique_noresize(*__f);
+ }
+
+ void insert_equal(const_iterator __f, const_iterator __l)
+ {
+ size_type __n = 0;
+ @KWSYS_NAMESPACE@_stl::distance(__f, __l, __n);
+ resize(_M_num_elements + __n);
+ for ( ; __n > 0; --__n, ++__f)
+ insert_equal_noresize(*__f);
+ }
+#endif
+
+ reference find_or_insert(const value_type& __obj);
+
+ iterator find(const key_type& __key)
+ {
+ size_type __n = _M_bkt_num_key(__key);
+ _Node* __first;
+ for ( __first = _M_buckets[__n];
+ __first && !_M_equals(_M_get_key(__first->_M_val), __key);
+ __first = __first->_M_next)
+ {}
+ return iterator(__first, this);
+ }
+
+ const_iterator find(const key_type& __key) const
+ {
+ size_type __n = _M_bkt_num_key(__key);
+ const _Node* __first;
+ for ( __first = _M_buckets[__n];
+ __first && !_M_equals(_M_get_key(__first->_M_val), __key);
+ __first = __first->_M_next)
+ {}
+ return const_iterator(__first, this);
+ }
+
+ size_type count(const key_type& __key) const
+ {
+ const size_type __n = _M_bkt_num_key(__key);
+ size_type __result = 0;
+
+ for (const _Node* __cur = _M_buckets[__n]; __cur; __cur = __cur->_M_next)
+ if (_M_equals(_M_get_key(__cur->_M_val), __key))
+ ++__result;
+ return __result;
+ }
+
+ @KWSYS_NAMESPACE@_stl::pair<iterator, iterator>
+ equal_range(const key_type& __key);
+
+ @KWSYS_NAMESPACE@_stl::pair<const_iterator, const_iterator>
+ equal_range(const key_type& __key) const;
+
+ size_type erase(const key_type& __key);
+ void erase(const iterator& __it);
+ void erase(iterator __first, iterator __last);
+
+ void erase(const const_iterator& __it);
+ void erase(const_iterator __first, const_iterator __last);
+
+ void resize(size_type __num_elements_hint);
+ void clear();
+
+private:
+ size_type _M_next_size(size_type __n) const
+ { return _stl_next_prime(__n); }
+
+ void _M_initialize_buckets(size_type __n)
+ {
+ const size_type __n_buckets = _M_next_size(__n);
+ _M_buckets.reserve(__n_buckets);
+ _M_buckets.insert(_M_buckets.end(), __n_buckets, (_Node*) 0);
+ _M_num_elements = 0;
+ }
+
+ size_type _M_bkt_num_key(const key_type& __key) const
+ {
+ return _M_bkt_num_key(__key, _M_buckets.size());
+ }
+
+ size_type _M_bkt_num(const value_type& __obj) const
+ {
+ return _M_bkt_num_key(_M_get_key(__obj));
+ }
+
+ size_type _M_bkt_num_key(const key_type& __key, size_t __n) const
+ {
+ return _M_hash(__key) % __n;
+ }
+
+ size_type _M_bkt_num(const value_type& __obj, size_t __n) const
+ {
+ return _M_bkt_num_key(_M_get_key(__obj), __n);
+ }
+
+ void construct(_Val* p, const _Val& v)
+ {
+ new (p) _Val(v);
+ }
+ void destroy(_Val* p)
+ {
+ (void)p;
+ p->~_Val();
+ }
+
+ _Node* _M_new_node(const value_type& __obj)
+ {
+ _Node* __n = _M_get_node();
+ __n->_M_next = 0;
+ try {
+ construct(&__n->_M_val, __obj);
+ return __n;
+ }
+ catch(...) {_M_put_node(__n); throw;}
+ }
+
+ void _M_delete_node(_Node* __n)
+ {
+ destroy(&__n->_M_val);
+ _M_put_node(__n);
+ }
+
+ void _M_erase_bucket(const size_type __n, _Node* __first, _Node* __last);
+ void _M_erase_bucket(const size_type __n, _Node* __last);
+
+ void _M_copy_from(const hashtable& __ht);
+
+};
+
+template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
+ class _All>
+_Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>&
+_Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>::operator++()
+{
+ const _Node* __old = _M_cur;
+ _M_cur = _M_cur->_M_next;
+ if (!_M_cur) {
+ size_type __bucket = _M_ht->_M_bkt_num(__old->_M_val);
+ while (!_M_cur && ++__bucket < _M_ht->_M_buckets.size())
+ _M_cur = _M_ht->_M_buckets[__bucket];
+ }
+ return *this;
+}
+
+template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
+ class _All>
+inline _Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>
+_Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>::operator++(int)
+{
+ iterator __tmp = *this;
+ ++*this;
+ return __tmp;
+}
+
+template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
+ class _All>
+_Hashtable_const_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>&
+_Hashtable_const_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>::operator++()
+{
+ const _Node* __old = _M_cur;
+ _M_cur = _M_cur->_M_next;
+ if (!_M_cur) {
+ size_type __bucket = _M_ht->_M_bkt_num(__old->_M_val);
+ while (!_M_cur && ++__bucket < _M_ht->_M_buckets.size())
+ _M_cur = _M_ht->_M_buckets[__bucket];
+ }
+ return *this;
+}
+
+template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
+ class _All>
+inline _Hashtable_const_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>
+_Hashtable_const_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>::operator++(int)
+{
+ const_iterator __tmp = *this;
+ ++*this;
+ return __tmp;
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+bool operator==(const hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>& __ht1,
+ const hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>& __ht2)
+{
+ typedef typename hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::_Node _Node;
+ if (__ht1._M_buckets.size() != __ht2._M_buckets.size())
+ return false;
+ for (int __n = 0; __n < __ht1._M_buckets.size(); ++__n) {
+ _Node* __cur1 = __ht1._M_buckets[__n];
+ _Node* __cur2 = __ht2._M_buckets[__n];
+ for ( ; __cur1 && __cur2 && __cur1->_M_val == __cur2->_M_val;
+ __cur1 = __cur1->_M_next, __cur2 = __cur2->_M_next)
+ {}
+ if (__cur1 || __cur2)
+ return false;
+ }
+ return true;
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+inline bool operator!=(const hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>& __ht1,
+ const hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>& __ht2) {
+ return !(__ht1 == __ht2);
+}
+
+template <class _Val, class _Key, class _HF, class _Extract, class _EqKey,
+ class _All>
+inline void swap(hashtable<_Val, _Key, _HF, _Extract, _EqKey, _All>& __ht1,
+ hashtable<_Val, _Key, _HF, _Extract, _EqKey, _All>& __ht2) {
+ __ht1.swap(__ht2);
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+@KWSYS_NAMESPACE@_stl::pair<@KWSYS_NAMESPACE@_CXX_DECL_TYPENAME hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::iterator, bool>
+hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>
+ ::insert_unique_noresize(const value_type& __obj)
+{
+ const size_type __n = _M_bkt_num(__obj);
+ _Node* __first = _M_buckets[__n];
+
+ for (_Node* __cur = __first; __cur; __cur = __cur->_M_next)
+ if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj)))
+ return @KWSYS_NAMESPACE@_stl::pair<iterator, bool>(iterator(__cur, this), false);
+
+ _Node* __tmp = _M_new_node(__obj);
+ __tmp->_M_next = __first;
+ _M_buckets[__n] = __tmp;
+ ++_M_num_elements;
+ return @KWSYS_NAMESPACE@_stl::pair<iterator, bool>(iterator(__tmp, this), true);
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+typename hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::iterator
+hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>
+ ::insert_equal_noresize(const value_type& __obj)
+{
+ const size_type __n = _M_bkt_num(__obj);
+ _Node* __first = _M_buckets[__n];
+
+ for (_Node* __cur = __first; __cur; __cur = __cur->_M_next)
+ if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj))) {
+ _Node* __tmp = _M_new_node(__obj);
+ __tmp->_M_next = __cur->_M_next;
+ __cur->_M_next = __tmp;
+ ++_M_num_elements;
+ return iterator(__tmp, this);
+ }
+
+ _Node* __tmp = _M_new_node(__obj);
+ __tmp->_M_next = __first;
+ _M_buckets[__n] = __tmp;
+ ++_M_num_elements;
+ return iterator(__tmp, this);
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+typename hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::reference
+hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::find_or_insert(const value_type& __obj)
+{
+ resize(_M_num_elements + 1);
+
+ size_type __n = _M_bkt_num(__obj);
+ _Node* __first = _M_buckets[__n];
+
+ for (_Node* __cur = __first; __cur; __cur = __cur->_M_next)
+ if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj)))
+ return __cur->_M_val;
+
+ _Node* __tmp = _M_new_node(__obj);
+ __tmp->_M_next = __first;
+ _M_buckets[__n] = __tmp;
+ ++_M_num_elements;
+ return __tmp->_M_val;
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+@KWSYS_NAMESPACE@_stl::pair<@KWSYS_NAMESPACE@_CXX_DECL_TYPENAME hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::iterator,
+ @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::iterator>
+hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::equal_range(const key_type& __key)
+{
+ typedef @KWSYS_NAMESPACE@_stl::pair<iterator, iterator> _Pii;
+ const size_type __n = _M_bkt_num_key(__key);
+
+ for (_Node* __first = _M_buckets[__n]; __first; __first = __first->_M_next)
+ if (_M_equals(_M_get_key(__first->_M_val), __key)) {
+ for (_Node* __cur = __first->_M_next; __cur; __cur = __cur->_M_next)
+ if (!_M_equals(_M_get_key(__cur->_M_val), __key))
+ return _Pii(iterator(__first, this), iterator(__cur, this));
+ for (size_type __m = __n + 1; __m < _M_buckets.size(); ++__m)
+ if (_M_buckets[__m])
+ return _Pii(iterator(__first, this),
+ iterator(_M_buckets[__m], this));
+ return _Pii(iterator(__first, this), end());
+ }
+ return _Pii(end(), end());
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+@KWSYS_NAMESPACE@_stl::pair<@KWSYS_NAMESPACE@_CXX_DECL_TYPENAME hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::const_iterator,
+ @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::const_iterator>
+hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>
+ ::equal_range(const key_type& __key) const
+{
+ typedef @KWSYS_NAMESPACE@_stl::pair<const_iterator, const_iterator> _Pii;
+ const size_type __n = _M_bkt_num_key(__key);
+
+ for (const _Node* __first = _M_buckets[__n] ;
+ __first;
+ __first = __first->_M_next) {
+ if (_M_equals(_M_get_key(__first->_M_val), __key)) {
+ for (const _Node* __cur = __first->_M_next;
+ __cur;
+ __cur = __cur->_M_next)
+ if (!_M_equals(_M_get_key(__cur->_M_val), __key))
+ return _Pii(const_iterator(__first, this),
+ const_iterator(__cur, this));
+ for (size_type __m = __n + 1; __m < _M_buckets.size(); ++__m)
+ if (_M_buckets[__m])
+ return _Pii(const_iterator(__first, this),
+ const_iterator(_M_buckets[__m], this));
+ return _Pii(const_iterator(__first, this), end());
+ }
+ }
+ return _Pii(end(), end());
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+typename hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::size_type
+hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::erase(const key_type& __key)
+{
+ const size_type __n = _M_bkt_num_key(__key);
+ _Node* __first = _M_buckets[__n];
+ size_type __erased = 0;
+
+ if (__first) {
+ _Node* __cur = __first;
+ _Node* __next = __cur->_M_next;
+ while (__next) {
+ if (_M_equals(_M_get_key(__next->_M_val), __key)) {
+ __cur->_M_next = __next->_M_next;
+ _M_delete_node(__next);
+ __next = __cur->_M_next;
+ ++__erased;
+ --_M_num_elements;
+ }
+ else {
+ __cur = __next;
+ __next = __cur->_M_next;
+ }
+ }
+ if (_M_equals(_M_get_key(__first->_M_val), __key)) {
+ _M_buckets[__n] = __first->_M_next;
+ _M_delete_node(__first);
+ ++__erased;
+ --_M_num_elements;
+ }
+ }
+ return __erased;
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+void hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::erase(const iterator& __it)
+{
+ _Node* __p = __it._M_cur;
+ if (__p) {
+ const size_type __n = _M_bkt_num(__p->_M_val);
+ _Node* __cur = _M_buckets[__n];
+
+ if (__cur == __p) {
+ _M_buckets[__n] = __cur->_M_next;
+ _M_delete_node(__cur);
+ --_M_num_elements;
+ }
+ else {
+ _Node* __next = __cur->_M_next;
+ while (__next) {
+ if (__next == __p) {
+ __cur->_M_next = __next->_M_next;
+ _M_delete_node(__next);
+ --_M_num_elements;
+ break;
+ }
+ else {
+ __cur = __next;
+ __next = __cur->_M_next;
+ }
+ }
+ }
+ }
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+void hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>
+ ::erase(iterator __first, iterator __last)
+{
+ size_type __f_bucket = __first._M_cur ?
+ _M_bkt_num(__first._M_cur->_M_val) : _M_buckets.size();
+ size_type __l_bucket = __last._M_cur ?
+ _M_bkt_num(__last._M_cur->_M_val) : _M_buckets.size();
+
+ if (__first._M_cur == __last._M_cur)
+ return;
+ else if (__f_bucket == __l_bucket)
+ _M_erase_bucket(__f_bucket, __first._M_cur, __last._M_cur);
+ else {
+ _M_erase_bucket(__f_bucket, __first._M_cur, 0);
+ for (size_type __n = __f_bucket + 1; __n < __l_bucket; ++__n)
+ _M_erase_bucket(__n, 0);
+ if (__l_bucket != _M_buckets.size())
+ _M_erase_bucket(__l_bucket, __last._M_cur);
+ }
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+inline void
+hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::erase(const_iterator __first,
+ const_iterator __last)
+{
+ erase(iterator(const_cast<_Node*>(__first._M_cur),
+ const_cast<hashtable*>(__first._M_ht)),
+ iterator(const_cast<_Node*>(__last._M_cur),
+ const_cast<hashtable*>(__last._M_ht)));
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+inline void
+hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::erase(const const_iterator& __it)
+{
+ erase(iterator(const_cast<_Node*>(__it._M_cur),
+ const_cast<hashtable*>(__it._M_ht)));
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+void hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>
+ ::resize(size_type __num_elements_hint)
+{
+ const size_type __old_n = _M_buckets.size();
+ if (__num_elements_hint > __old_n) {
+ const size_type __n = _M_next_size(__num_elements_hint);
+ if (__n > __old_n) {
+ _M_buckets_type __tmp(
+ __n, (_Node*)(0)
+ @KWSYS_NAMESPACE@_HASH_BUCKETS_GET_ALLOCATOR(_M_buckets));
+ try {
+ for (size_type __bucket = 0; __bucket < __old_n; ++__bucket) {
+ _Node* __first = _M_buckets[__bucket];
+ while (__first) {
+ size_type __new_bucket = _M_bkt_num(__first->_M_val, __n);
+ _M_buckets[__bucket] = __first->_M_next;
+ __first->_M_next = __tmp[__new_bucket];
+ __tmp[__new_bucket] = __first;
+ __first = _M_buckets[__bucket];
+ }
+ }
+ _M_buckets.swap(__tmp);
+ }
+ catch(...) {
+ for (size_type __bucket = 0; __bucket < __tmp.size(); ++__bucket) {
+ while (__tmp[__bucket]) {
+ _Node* __next = __tmp[__bucket]->_M_next;
+ _M_delete_node(__tmp[__bucket]);
+ __tmp[__bucket] = __next;
+ }
+ }
+ throw;
+ }
+ }
+ }
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+void hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>
+ ::_M_erase_bucket(const size_type __n, _Node* __first, _Node* __last)
+{
+ _Node* __cur = _M_buckets[__n];
+ if (__cur == __first)
+ _M_erase_bucket(__n, __last);
+ else {
+ _Node* __next;
+ for (__next = __cur->_M_next;
+ __next != __first;
+ __cur = __next, __next = __cur->_M_next)
+ ;
+ while (__next != __last) {
+ __cur->_M_next = __next->_M_next;
+ _M_delete_node(__next);
+ __next = __cur->_M_next;
+ --_M_num_elements;
+ }
+ }
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+void hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>
+ ::_M_erase_bucket(const size_type __n, _Node* __last)
+{
+ _Node* __cur = _M_buckets[__n];
+ while (__cur != __last) {
+ _Node* __next = __cur->_M_next;
+ _M_delete_node(__cur);
+ __cur = __next;
+ _M_buckets[__n] = __cur;
+ --_M_num_elements;
+ }
+}
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+void hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>::clear()
+{
+ for (size_type __i = 0; __i < _M_buckets.size(); ++__i) {
+ _Node* __cur = _M_buckets[__i];
+ while (__cur != 0) {
+ _Node* __next = __cur->_M_next;
+ _M_delete_node(__cur);
+ __cur = __next;
+ }
+ _M_buckets[__i] = 0;
+ }
+ _M_num_elements = 0;
+}
+
+
+template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
+void hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>
+ ::_M_copy_from(const hashtable& __ht)
+{
+ _M_buckets.clear();
+ _M_buckets.reserve(__ht._M_buckets.size());
+ _M_buckets.insert(_M_buckets.end(), __ht._M_buckets.size(), (_Node*) 0);
+ try {
+ for (size_type __i = 0; __i < __ht._M_buckets.size(); ++__i) {
+ const _Node* __cur = __ht._M_buckets[__i];
+ if (__cur) {
+ _Node* __copy = _M_new_node(__cur->_M_val);
+ _M_buckets[__i] = __copy;
+
+ for (_Node* __next = __cur->_M_next;
+ __next;
+ __cur = __next, __next = __cur->_M_next) {
+ __copy->_M_next = _M_new_node(__next->_M_val);
+ __copy = __copy->_M_next;
+ }
+ }
+ }
+ _M_num_elements = __ht._M_num_elements;
+ }
+ catch(...) {clear(); throw;}
+}
+
+} // namespace @KWSYS_NAMESPACE@
+
+// Normally the comparison operators should be found in the @KWSYS_NAMESPACE@
+// namespace by argument dependent lookup. For compilers that do not
+// support it we must bring them into the global namespace now.
+#if !@KWSYS_NAMESPACE@_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
+using @KWSYS_NAMESPACE@::operator==;
+using @KWSYS_NAMESPACE@::operator!=;
+#endif
+
+// Undo warning suppression.
+#if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wdeprecated")
+# pragma clang diagnostic pop
+# endif
+#endif
+
+#if defined(_MSC_VER)
+# pragma warning (pop)
+#endif
+
+#endif
diff --git a/Source/kwsys/kwsysHeaderDump.pl b/Source/kwsys/kwsysHeaderDump.pl
new file mode 100755
index 0000000000..0dc4a52046
--- /dev/null
+++ b/Source/kwsys/kwsysHeaderDump.pl
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+#=============================================================================
+# 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.
+#=============================================================================
+
+if ( $#ARGV+1 < 2 )
+{
+ print "Usage: ./kwsysHeaderDump.pl <name> <header>\n";
+ exit(1);
+}
+
+$name = $ARGV[0];
+$max = 0;
+open(INFILE, $ARGV[1]);
+while (chomp ($line = <INFILE>))
+{
+ if (($line !~ /^\#/) &&
+ ($line =~ s/.*kwsys${name}_([A-Za-z0-9_]*).*/\1/) &&
+ ($i{$line}++ < 1))
+ {
+ push(@lines, "$line");
+ if (length($line) > $max)
+ {
+ $max = length($line);
+ }
+ }
+}
+close(INFILE);
+
+$width = $max + 13;
+print sprintf("#define %-${width}s kwsys_ns(${name})\n", "kwsys${name}");
+foreach $l (@lines)
+{
+ print sprintf("#define %-${width}s kwsys_ns(${name}_$l)\n",
+ "kwsys${name}_$l");
+}
+print "\n";
+print sprintf("# undef kwsys${name}\n");
+foreach $l (@lines)
+{
+ print sprintf("# undef kwsys${name}_$l\n");
+}
diff --git a/Source/kwsys/kwsysPlatformTests.cmake b/Source/kwsys/kwsysPlatformTests.cmake
new file mode 100644
index 0000000000..16bc9699f7
--- /dev/null
+++ b/Source/kwsys/kwsysPlatformTests.cmake
@@ -0,0 +1,219 @@
+#=============================================================================
+# 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.
+#=============================================================================
+SET(KWSYS_PLATFORM_TEST_FILE_C kwsysPlatformTestsC.c)
+SET(KWSYS_PLATFORM_TEST_FILE_CXX kwsysPlatformTestsCXX.cxx)
+
+MACRO(KWSYS_PLATFORM_TEST lang var description invert)
+ IF(NOT DEFINED ${var}_COMPILED)
+ MESSAGE(STATUS "${description}")
+ TRY_COMPILE(${var}_COMPILED
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}}
+ COMPILE_DEFINITIONS -DTEST_${var} ${KWSYS_PLATFORM_TEST_DEFINES} ${KWSYS_PLATFORM_TEST_EXTRA_FLAGS}
+ CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=${KWSYS_PLATFORM_TEST_LINK_LIBRARIES}"
+ OUTPUT_VARIABLE OUTPUT)
+ IF(${var}_COMPILED)
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "${description} compiled with the following output:\n${OUTPUT}\n\n")
+ ELSE(${var}_COMPILED)
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "${description} failed to compile with the following output:\n${OUTPUT}\n\n")
+ ENDIF(${var}_COMPILED)
+ IF(${invert} MATCHES INVERT)
+ IF(${var}_COMPILED)
+ MESSAGE(STATUS "${description} - no")
+ ELSE(${var}_COMPILED)
+ MESSAGE(STATUS "${description} - yes")
+ ENDIF(${var}_COMPILED)
+ ELSE(${invert} MATCHES INVERT)
+ IF(${var}_COMPILED)
+ MESSAGE(STATUS "${description} - yes")
+ ELSE(${var}_COMPILED)
+ MESSAGE(STATUS "${description} - no")
+ ENDIF(${var}_COMPILED)
+ ENDIF(${invert} MATCHES INVERT)
+ ENDIF()
+ IF(${invert} MATCHES INVERT)
+ IF(${var}_COMPILED)
+ SET(${var} 0)
+ ELSE(${var}_COMPILED)
+ SET(${var} 1)
+ ENDIF(${var}_COMPILED)
+ ELSE(${invert} MATCHES INVERT)
+ IF(${var}_COMPILED)
+ SET(${var} 1)
+ ELSE(${var}_COMPILED)
+ SET(${var} 0)
+ ENDIF(${var}_COMPILED)
+ ENDIF(${invert} MATCHES INVERT)
+ENDMACRO(KWSYS_PLATFORM_TEST)
+
+MACRO(KWSYS_PLATFORM_TEST_RUN lang var description invert)
+ IF(NOT DEFINED ${var})
+ MESSAGE(STATUS "${description}")
+ TRY_RUN(${var} ${var}_COMPILED
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}}
+ COMPILE_DEFINITIONS -DTEST_${var} ${KWSYS_PLATFORM_TEST_DEFINES} ${KWSYS_PLATFORM_TEST_EXTRA_FLAGS}
+ OUTPUT_VARIABLE OUTPUT)
+
+ # Note that ${var} will be a 0 return value on success.
+ IF(${var}_COMPILED)
+ IF(${var})
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "${description} compiled but failed to run with the following output:\n${OUTPUT}\n\n")
+ ELSE(${var})
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "${description} compiled and ran with the following output:\n${OUTPUT}\n\n")
+ ENDIF(${var})
+ ELSE(${var}_COMPILED)
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "${description} failed to compile with the following output:\n${OUTPUT}\n\n")
+ SET(${var} -1 CACHE INTERNAL "${description} failed to compile.")
+ ENDIF(${var}_COMPILED)
+
+ IF(${invert} MATCHES INVERT)
+ IF(${var}_COMPILED)
+ IF(${var})
+ MESSAGE(STATUS "${description} - yes")
+ ELSE(${var})
+ MESSAGE(STATUS "${description} - no")
+ ENDIF(${var})
+ ELSE(${var}_COMPILED)
+ MESSAGE(STATUS "${description} - failed to compile")
+ ENDIF(${var}_COMPILED)
+ ELSE(${invert} MATCHES INVERT)
+ IF(${var}_COMPILED)
+ IF(${var})
+ MESSAGE(STATUS "${description} - no")
+ ELSE(${var})
+ MESSAGE(STATUS "${description} - yes")
+ ENDIF(${var})
+ ELSE(${var}_COMPILED)
+ MESSAGE(STATUS "${description} - failed to compile")
+ ENDIF(${var}_COMPILED)
+ ENDIF(${invert} MATCHES INVERT)
+ ENDIF()
+
+ IF(${invert} MATCHES INVERT)
+ IF(${var}_COMPILED)
+ IF(${var})
+ SET(${var} 1)
+ ELSE(${var})
+ SET(${var} 0)
+ ENDIF(${var})
+ ELSE(${var}_COMPILED)
+ SET(${var} 1)
+ ENDIF(${var}_COMPILED)
+ ELSE(${invert} MATCHES INVERT)
+ IF(${var}_COMPILED)
+ IF(${var})
+ SET(${var} 0)
+ ELSE(${var})
+ SET(${var} 1)
+ ENDIF(${var})
+ ELSE(${var}_COMPILED)
+ SET(${var} 0)
+ ENDIF(${var}_COMPILED)
+ ENDIF(${invert} MATCHES INVERT)
+ENDMACRO(KWSYS_PLATFORM_TEST_RUN)
+
+MACRO(KWSYS_PLATFORM_C_TEST var description invert)
+ SET(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_C_TEST_DEFINES})
+ SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_C_TEST_EXTRA_FLAGS})
+ KWSYS_PLATFORM_TEST(C "${var}" "${description}" "${invert}")
+ SET(KWSYS_PLATFORM_TEST_DEFINES)
+ SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS)
+ENDMACRO(KWSYS_PLATFORM_C_TEST)
+
+MACRO(KWSYS_PLATFORM_C_TEST_RUN var description invert)
+ SET(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_C_TEST_DEFINES})
+ SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_C_TEST_EXTRA_FLAGS})
+ KWSYS_PLATFORM_TEST_RUN(C "${var}" "${description}" "${invert}")
+ SET(KWSYS_PLATFORM_TEST_DEFINES)
+ SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS)
+ENDMACRO(KWSYS_PLATFORM_C_TEST_RUN)
+
+MACRO(KWSYS_PLATFORM_CXX_TEST var description invert)
+ SET(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_CXX_TEST_DEFINES})
+ SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_CXX_TEST_EXTRA_FLAGS})
+ SET(KWSYS_PLATFORM_TEST_LINK_LIBRARIES ${KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES})
+ KWSYS_PLATFORM_TEST(CXX "${var}" "${description}" "${invert}")
+ SET(KWSYS_PLATFORM_TEST_DEFINES)
+ SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS)
+ SET(KWSYS_PLATFORM_TEST_LINK_LIBRARIES)
+ENDMACRO(KWSYS_PLATFORM_CXX_TEST)
+
+MACRO(KWSYS_PLATFORM_CXX_TEST_RUN var description invert)
+ SET(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_CXX_TEST_DEFINES})
+ SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_CXX_TEST_EXTRA_FLAGS})
+ KWSYS_PLATFORM_TEST_RUN(CXX "${var}" "${description}" "${invert}")
+ SET(KWSYS_PLATFORM_TEST_DEFINES)
+ SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS)
+ENDMACRO(KWSYS_PLATFORM_CXX_TEST_RUN)
+
+#-----------------------------------------------------------------------------
+# KWSYS_PLATFORM_INFO_TEST(lang var description)
+#
+# Compile test named by ${var} and store INFO strings extracted from binary.
+MACRO(KWSYS_PLATFORM_INFO_TEST lang var description)
+ # We can implement this macro on CMake 2.6 and above.
+ IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.6)
+ SET(${var} "")
+ ELSE()
+ # Choose a location for the result binary.
+ SET(KWSYS_PLATFORM_INFO_FILE
+ ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${var}.bin)
+
+ # Compile the test binary.
+ IF(NOT EXISTS ${KWSYS_PLATFORM_INFO_FILE})
+ MESSAGE(STATUS "${description}")
+ TRY_COMPILE(${var}_COMPILED
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}}
+ COMPILE_DEFINITIONS -DTEST_${var}
+ ${KWSYS_PLATFORM_${lang}_TEST_DEFINES}
+ ${KWSYS_PLATFORM_${lang}_TEST_EXTRA_FLAGS}
+ OUTPUT_VARIABLE OUTPUT
+ COPY_FILE ${KWSYS_PLATFORM_INFO_FILE}
+ )
+ IF(${var}_COMPILED)
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "${description} compiled with the following output:\n${OUTPUT}\n\n")
+ ELSE()
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "${description} failed to compile with the following output:\n${OUTPUT}\n\n")
+ ENDIF()
+ IF(${var}_COMPILED)
+ MESSAGE(STATUS "${description} - compiled")
+ ELSE()
+ MESSAGE(STATUS "${description} - failed")
+ ENDIF()
+ ENDIF()
+
+ # Parse info strings out of the compiled binary.
+ IF(${var}_COMPILED)
+ FILE(STRINGS ${KWSYS_PLATFORM_INFO_FILE} ${var} REGEX "INFO:[A-Za-z0-9]+\\[[^]]*\\]")
+ ELSE()
+ SET(${var} "")
+ ENDIF()
+
+ SET(KWSYS_PLATFORM_INFO_FILE)
+ ENDIF()
+ENDMACRO()
diff --git a/Source/kwsys/kwsysPlatformTestsC.c b/Source/kwsys/kwsysPlatformTestsC.c
new file mode 100644
index 0000000000..e602964bb7
--- /dev/null
+++ b/Source/kwsys/kwsysPlatformTestsC.c
@@ -0,0 +1,100 @@
+/*============================================================================
+ 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.
+============================================================================*/
+/*
+ Macros to define main() in a cross-platform way.
+
+ Usage:
+
+ int KWSYS_PLATFORM_TEST_C_MAIN()
+ {
+ return 0;
+ }
+
+ int KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv)
+ {
+ (void)argc; (void)argv;
+ return 0;
+ }
+*/
+#if defined(__CLASSIC_C__)
+# define KWSYS_PLATFORM_TEST_C_MAIN() \
+ main()
+# define KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv) \
+ main(argc,argv) int argc; char* argv[];
+#else
+# define KWSYS_PLATFORM_TEST_C_MAIN() \
+ main(void)
+# define KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv) \
+ main(int argc, char* argv[])
+#endif
+
+/*--------------------------------------------------------------------------*/
+#ifdef TEST_KWSYS_C_HAS_PTRDIFF_T
+#include <stddef.h>
+int f(ptrdiff_t n) { return n > 0; }
+int KWSYS_PLATFORM_TEST_C_MAIN()
+{
+ char* p = 0;
+ ptrdiff_t d = p - p;
+ (void)d;
+ return f(p - p);
+}
+#endif
+
+/*--------------------------------------------------------------------------*/
+#ifdef TEST_KWSYS_C_HAS_SSIZE_T
+#include <unistd.h>
+int f(ssize_t n) { return (int)n; }
+int KWSYS_PLATFORM_TEST_C_MAIN()
+{
+ ssize_t n = 0;
+ return f(n);
+}
+#endif
+
+/*--------------------------------------------------------------------------*/
+#ifdef TEST_KWSYS_C_TYPE_MACROS
+char* info_macros =
+#if defined(__SIZEOF_SHORT__)
+"INFO:macro[__SIZEOF_SHORT__]\n"
+#endif
+#if defined(__SIZEOF_INT__)
+"INFO:macro[__SIZEOF_INT__]\n"
+#endif
+#if defined(__SIZEOF_LONG__)
+"INFO:macro[__SIZEOF_LONG__]\n"
+#endif
+#if defined(__SIZEOF_LONG_LONG__)
+"INFO:macro[__SIZEOF_LONG_LONG__]\n"
+#endif
+#if defined(__SHORT_MAX__)
+"INFO:macro[__SHORT_MAX__]\n"
+#endif
+#if defined(__INT_MAX__)
+"INFO:macro[__INT_MAX__]\n"
+#endif
+#if defined(__LONG_MAX__)
+"INFO:macro[__LONG_MAX__]\n"
+#endif
+#if defined(__LONG_LONG_MAX__)
+"INFO:macro[__LONG_LONG_MAX__]\n"
+#endif
+ "";
+
+int KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv)
+{
+ int require = 0;
+ require += info_macros[argc];
+ (void)argv;
+ return require;
+}
+#endif
diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx
new file mode 100644
index 0000000000..3f947f3460
--- /dev/null
+++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx
@@ -0,0 +1,682 @@
+/*============================================================================
+ 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.
+============================================================================*/
+// Setup for tests that use result of stl namespace test.
+#if defined(KWSYS_STL_HAVE_STD)
+# if KWSYS_STL_HAVE_STD
+# define kwsys_stl std
+# else
+# define kwsys_stl
+# endif
+#endif
+
+// Setup for tests that use iostreams.
+#if defined(KWSYS_IOS_USE_ANSI) && defined(KWSYS_IOS_HAVE_STD)
+# if defined(_MSC_VER)
+# pragma warning (push,1)
+# endif
+# if KWSYS_IOS_USE_ANSI
+# include <iostream>
+# else
+# include <iostream.h>
+# endif
+# if defined(_MSC_VER)
+# pragma warning (pop)
+# endif
+# if KWSYS_IOS_HAVE_STD
+# define kwsys_ios std
+# else
+# define kwsys_ios
+# endif
+#endif
+
+#ifdef TEST_KWSYS_STL_HAVE_STD
+#include <list>
+void f(std ::list<int>*) {}
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_IOS_USE_ANSI
+#include <iosfwd>
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_IOS_HAVE_STD
+#include <iosfwd>
+void f(std ::ostream*) {}
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_IOS_USE_SSTREAM
+#include <sstream>
+#if defined(__GNUC__) && __GNUC__ == 2 && __GNUC_MINOR__ == 96
+# error "GCC 2.96 stringstream is buggy"
+#endif
+int main()
+{
+ std ::ostringstream ostr;
+ ostr << "hello";
+ if(ostr.str().size() == 5)
+ {
+ return 0;
+ }
+ return -1;
+}
+#endif
+
+#ifdef TEST_KWSYS_IOS_USE_STRSTREAM_H
+#include <strstream.h>
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_IOS_USE_STRSTREA_H
+#include <strstrea.h>
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_STRING_HAVE_OSTREAM
+# include <iostream.h>
+# include <string>
+void f(ostream& os, const kwsys_stl::string& s) { os << s; }
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_STRING_HAVE_ISTREAM
+# include <iostream.h>
+# include <string>
+void f(istream& is, kwsys_stl::string& s) { is >> s; }
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_STRING_HAVE_NEQ_CHAR
+# include <string>
+bool f(const kwsys_stl::string& s) { return s != ""; }
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_CSTDIO
+#include <cstdio>
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_CSTDDEF
+#include <cstddef>
+void f(size_t) {}
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_LONG_LONG
+long long f(long long n) { return n; }
+int main()
+{
+ long long n = 0;
+ return static_cast<int>(f(n));
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS___INT64
+__int64 f(__int64 n) { return n; }
+int main()
+{
+ __int64 n = 0;
+ return static_cast<int>(f(n));
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
+template <class T> class A;
+template <class T> int f(A<T>&);
+template <class T> class A
+{
+public:
+ // "friend int f<>(A<T>&)" would conform
+ friend int f(A<T>&);
+private:
+ int x;
+};
+
+template <class T> int f(A<T>& a) { return a.x = 0; }
+template int f(A<int>&);
+
+int main()
+{
+ A<int> a;
+ return f(a);
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_MEMBER_TEMPLATES
+template <class U>
+class A
+{
+public:
+ U u;
+ A(): u(0) {}
+ template <class V> V m(V* p) { return *p = u; }
+};
+
+int main()
+{
+ A<short> a;
+ int s = 1;
+ return a.m(&s);
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_FULL_SPECIALIZATION
+template <class T> struct A {};
+template <> struct A<int*>
+{
+ static int f() { return 0; }
+};
+int main() { return A<int*>::f(); }
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
+namespace N
+{
+ class A {};
+ int f(A*) { return 0; }
+}
+void f(void*);
+int main()
+{
+ N::A* a = 0;
+ return f(a);
+}
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_ITERATOR_TRAITS
+#include <iterator>
+#include <list>
+void f(kwsys_stl::iterator_traits<kwsys_stl::list<int>::iterator>::iterator_category const&) {}
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_ITERATOR_CATEGORY
+#include <iterator>
+#include <list>
+void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::iterator_category(x); }
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS___ITERATOR_CATEGORY
+#include <iterator>
+#include <list>
+void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::__iterator_category(x); }
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_TEMPLATE
+#include <memory>
+template <class Alloc>
+void f(const Alloc&)
+{
+ typedef typename Alloc::size_type alloc_size_type;
+}
+int main()
+{
+ f(kwsys_stl::allocator<char>());
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
+#include <memory>
+void f(kwsys_stl::allocator::size_type const&) {}
+int main() { return 0; }
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_REBIND
+#include <memory>
+template <class T, class Alloc>
+void f(const T&, const Alloc&)
+{
+ typedef typename Alloc::template rebind<T>::other alloc_type;
+}
+int main()
+{
+ f(0, kwsys_stl::allocator<char>());
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
+#include <memory>
+void f(kwsys_stl::allocator<char> const& a)
+{
+ a.max_size(sizeof(int));
+}
+int main()
+{
+ f(kwsys_stl::allocator<char>());
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_OBJECTS
+#include <vector>
+void f(kwsys_stl::vector<int> const& v1)
+{
+ kwsys_stl::vector<int>(1, 1, v1.get_allocator());
+}
+int main()
+{
+ f(kwsys_stl::vector<int>());
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_STAT_HAS_ST_MTIM
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+int main()
+{
+ struct stat stat1;
+ (void)stat1.st_mtim.tv_sec;
+ (void)stat1.st_mtim.tv_nsec;
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
+void function(long**) {}
+int main()
+{
+ __int64** p = 0;
+ function(p);
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
+void function(long long**) {}
+int main()
+{
+ __int64** p = 0;
+ function(p);
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_CAN_CONVERT_UI64_TO_DOUBLE
+void function(double& l, unsigned __int64 const& r)
+{
+ l = static_cast<double>(r);
+}
+
+int main()
+{
+ double tTo = 0.0;
+ unsigned __int64 tFrom = 0;
+ function(tTo, tFrom);
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_IOS_HAVE_BINARY
+int test_binary(int, ...)
+{
+ return 0;
+}
+int main()
+{
+ return test_binary(1, kwsys_ios::ios::binary);
+}
+#endif
+
+#ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG
+int test_istream(kwsys_ios::istream& is, long long& x)
+{
+ return (is >> x)? 1:0;
+}
+int main()
+{
+ long long x = 0;
+ return test_istream(kwsys_ios::cin, x);
+}
+#endif
+
+#ifdef TEST_KWSYS_IOS_HAS_OSTREAM_LONG_LONG
+int test_ostream(kwsys_ios::ostream& os, long long x)
+{
+ return (os << x)? 1:0;
+}
+int main()
+{
+ long long x = 0;
+ return test_ostream(kwsys_ios::cout, x);
+}
+#endif
+
+#ifdef TEST_KWSYS_IOS_HAS_ISTREAM___INT64
+int test_istream(kwsys_ios::istream& is, __int64& x)
+{
+ return (is >> x)? 1:0;
+}
+int main()
+{
+ __int64 x = 0;
+ return test_istream(kwsys_ios::cin, x);
+}
+#endif
+
+#ifdef TEST_KWSYS_IOS_HAS_OSTREAM___INT64
+int test_ostream(kwsys_ios::ostream& os, __int64 x)
+{
+ return (os << x)? 1:0;
+}
+int main()
+{
+ __int64 x = 0;
+ return test_ostream(kwsys_ios::cout, x);
+}
+#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
+#define _LARGEFILE64_SOURCE
+#define _LARGE_FILES
+#define _FILE_OFFSET_BITS 64
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#if KWSYS_CXX_HAS_CSTDIO
+# include <cstdio>
+#endif
+#include <stdio.h>
+
+int main(int, char **argv)
+{
+ /* check that off_t can hold 2^63 - 1 and perform basic operations... */
+#define OFF_T_64 (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+ if (OFF_T_64 % 2147483647 != 1)
+ return 1;
+
+ // stat breaks on SCO OpenServer
+ struct stat buf;
+ stat( argv[0], &buf );
+ if (!S_ISREG(buf.st_mode))
+ return 2;
+
+ FILE *file = fopen( argv[0], "r" );
+ off_t offset = ftello( file );
+ fseek( file, offset, SEEK_CUR );
+ fclose( file );
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_SETENV
+#include <stdlib.h>
+int main()
+{
+ return setenv("A", "B", 1);
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_UNSETENV
+#include <stdlib.h>
+int main()
+{
+ unsetenv("A");
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H
+#include <stdlib.h>
+int main()
+{
+ char* e = environ[0];
+ return e? 0:1;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_RLIMIT64
+# if defined(KWSYS_HAS_LFS)
+# define _LARGEFILE_SOURCE
+# define _LARGEFILE64_SOURCE
+# define _LARGE_FILES
+# define _FILE_OFFSET_BITS 64
+# endif
+# include <sys/resource.h>
+int main()
+{
+ struct rlimit64 rlim;
+ return getrlimit64(0,&rlim);
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_ATOLL
+#include <stdlib.h>
+int main()
+{
+ const char *str="1024";
+ return static_cast<int>(atoll(str));
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_ATOL
+#include <stdlib.h>
+int main()
+{
+ const char *str="1024";
+ return static_cast<int>(atol(str));
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS__ATOI64
+#include <stdlib.h>
+int main()
+{
+ const char *str="1024";
+ return static_cast<int>(_atoi64(str));
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_UTIMES
+#include <sys/time.h>
+int main()
+{
+ struct timeval* current_time = 0;
+ return utimes("/example", current_time);
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_UTIMENSAT
+#include <fcntl.h>
+#include <sys/stat.h>
+int main()
+{
+ struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}};
+ return utimensat(AT_FDCWD, "/example", times, AT_SYMLINK_NOFOLLOW);
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_BACKTRACE
+#if defined(__PATHSCALE__) || defined(__PATHCC__) \
+ || (defined(__LSB_VERSION__) && (__LSB_VERSION__ < 41))
+backtrace doesnt work with this compiler or os
+#endif
+#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+#include <execinfo.h>
+int main()
+{
+ void *stackSymbols[256];
+ backtrace(stackSymbols,256);
+ backtrace_symbols(&stackSymbols[0],1);
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_DLADDR
+#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+#include <dlfcn.h>
+int main()
+{
+ Dl_info info;
+ int ierr=dladdr((void*)main,&info);
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_CXXABI
+#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+#include <cxxabi.h>
+int main()
+{
+ int status = 0;
+ size_t bufferLen = 512;
+ char buffer[512] = {'\0'};
+ const char *function="_ZN5kwsys17SystemInformation15GetProgramStackEii";
+ char *demangledFunction =
+ abi::__cxa_demangle(function, buffer, &bufferLen, &status);
+ return status;
+}
+#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()
+{
+ int a = 1;
+ __asm {
+ xor EBX, EBX;
+ mov a, EBX;
+ }
+
+ return a;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM_CPUID
+int main()
+{
+ int a = 0;
+ __asm {
+ xor EAX, EAX;
+ cpuid;
+ mov a, EAX;
+ }
+
+ return a;
+}
+#endif
+
+#ifdef TEST_KWSYS_STL_HAS_WSTRING
+#include <string>
+void f(std ::wstring*) {}
+int main() { return 0; }
+#endif
diff --git a/Source/kwsys/kwsysPrivate.h b/Source/kwsys/kwsysPrivate.h
new file mode 100644
index 0000000000..3a26c26fbd
--- /dev/null
+++ b/Source/kwsys/kwsysPrivate.h
@@ -0,0 +1,41 @@
+/*============================================================================
+ 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
+# error "Do not include kwsysPrivate.h outside of kwsys c and cxx files."
+#endif
+
+#ifndef _kwsysPrivate_h
+#define _kwsysPrivate_h
+
+/*
+ Define KWSYS_HEADER macro to help the c and cxx files include kwsys
+ headers from the configured namespace directory. The macro can be
+ used like this:
+
+ #include KWSYS_HEADER(Directory.hxx)
+ #include KWSYS_HEADER(std/vector)
+*/
+#define KWSYS_HEADER(x) KWSYS_HEADER0(KWSYS_NAMESPACE/x)
+#define KWSYS_HEADER0(x) KWSYS_HEADER1(x)
+#define KWSYS_HEADER1(x) <x>
+
+/*
+ Define KWSYS_NAMESPACE_STRING to be a string constant containing the
+ name configured for this instance of the kwsys library.
+*/
+#define KWSYS_NAMESPACE_STRING KWSYS_NAMESPACE_STRING0(KWSYS_NAMESPACE)
+#define KWSYS_NAMESPACE_STRING0(x) KWSYS_NAMESPACE_STRING1(x)
+#define KWSYS_NAMESPACE_STRING1(x) #x
+
+#else
+# error "kwsysPrivate.h included multiple times."
+#endif
diff --git a/Source/kwsys/kwsys_cstddef.hxx.in b/Source/kwsys/kwsys_cstddef.hxx.in
new file mode 100644
index 0000000000..925c030846
--- /dev/null
+++ b/Source/kwsys/kwsys_cstddef.hxx.in
@@ -0,0 +1,35 @@
+/*============================================================================
+ 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@_cstddef
+#define @KWSYS_NAMESPACE@_cstddef
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+/* Avoid warnings in MSVC standard headers. */
+#ifdef _MSC_VER
+# pragma warning (push, 1)
+# pragma warning (disable: 4702)
+# pragma warning (disable: 4786)
+#endif
+
+/* Include the real header. */
+#if @KWSYS_NAMESPACE@_CXX_HAS_CSTDDEF
+# include <cstddef>
+#else
+# include <stddef.h>
+#endif
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
diff --git a/Source/kwsys/kwsys_ios_fstream.h.in b/Source/kwsys/kwsys_ios_fstream.h.in
new file mode 100644
index 0000000000..4b1a8cfcc4
--- /dev/null
+++ b/Source/kwsys/kwsys_ios_fstream.h.in
@@ -0,0 +1,46 @@
+/*============================================================================
+ 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@_ios_fstream
+#define @KWSYS_NAMESPACE@_ios_fstream
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+#ifdef _MSC_VER
+# pragma warning (push, 1)
+# pragma warning (disable: 4702)
+# pragma warning (disable: 4995) /* Old streams are deprecated. */
+#endif
+
+#if @KWSYS_NAMESPACE@_IOS_USE_ANSI
+# include <fstream>
+#else
+# include <fstream.h>
+#endif
+
+#if !@KWSYS_NAMESPACE@_IOS_USE_SSTREAM
+namespace @KWSYS_NAMESPACE@_ios
+{
+ using @KWSYS_NAMESPACE@_ios_namespace::ostream;
+ using @KWSYS_NAMESPACE@_ios_namespace::istream;
+ using @KWSYS_NAMESPACE@_ios_namespace::ofstream;
+ using @KWSYS_NAMESPACE@_ios_namespace::ifstream;
+ using @KWSYS_NAMESPACE@_ios_namespace::ios;
+ using @KWSYS_NAMESPACE@_ios_namespace::endl;
+ using @KWSYS_NAMESPACE@_ios_namespace::flush;
+}
+#endif
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
diff --git a/Source/kwsys/kwsys_ios_iosfwd.h.in b/Source/kwsys/kwsys_ios_iosfwd.h.in
new file mode 100644
index 0000000000..f4fafebc25
--- /dev/null
+++ b/Source/kwsys/kwsys_ios_iosfwd.h.in
@@ -0,0 +1,49 @@
+/*============================================================================
+ 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@_ios_iosfwd
+#define @KWSYS_NAMESPACE@_ios_iosfwd
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+#ifdef _MSC_VER
+#pragma warning (push, 1)
+#pragma warning (disable: 4702)
+#endif
+
+#if @KWSYS_NAMESPACE@_IOS_USE_ANSI
+# include <iosfwd>
+#else
+class fstream;
+class ifstream;
+class ios;
+class istream;
+class ofstream;
+class ostream;
+#endif
+
+#if !@KWSYS_NAMESPACE@_IOS_USE_SSTREAM
+namespace @KWSYS_NAMESPACE@_ios
+{
+ using @KWSYS_NAMESPACE@_ios_namespace::fstream;
+ using @KWSYS_NAMESPACE@_ios_namespace::ifstream;
+ using @KWSYS_NAMESPACE@_ios_namespace::ios;
+ using @KWSYS_NAMESPACE@_ios_namespace::istream;
+ using @KWSYS_NAMESPACE@_ios_namespace::ofstream;
+ using @KWSYS_NAMESPACE@_ios_namespace::ostream;
+}
+#endif
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+#endif
diff --git a/Source/kwsys/kwsys_ios_iostream.h.in b/Source/kwsys/kwsys_ios_iostream.h.in
new file mode 100644
index 0000000000..43fc4d5790
--- /dev/null
+++ b/Source/kwsys/kwsys_ios_iostream.h.in
@@ -0,0 +1,99 @@
+/*============================================================================
+ 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@_ios_iostream
+#define @KWSYS_NAMESPACE@_ios_iostream
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+#ifdef _MSC_VER
+# pragma warning (push, 1)
+# pragma warning (disable: 4702)
+# pragma warning (disable: 4995) /* Old streams are deprecated. */
+#endif
+
+#if @KWSYS_NAMESPACE@_IOS_USE_ANSI
+# include <iostream>
+#else
+# include <iostream.h>
+#endif
+
+// The HP implementation of iostream defines cin, cout, cerr, and clog
+// as macros in order to do thread-private streams.
+// See /opt/aCC/include/iostream/iostream.h for details.
+// This block redefines the macros in a safe way that is also compatible
+// with the HP definitions and the using declarations below.
+
+#if !@KWSYS_NAMESPACE@_IOS_USE_SSTREAM
+# if defined(__HP_aCC) && (defined(HP_THREAD_SAFE) || defined(_THREAD_SAFE))
+# if defined(cin) && !defined(@KWSYS_NAMESPACE@_IOS_HP_HACK_CIN)
+# define @KWSYS_NAMESPACE@_IOS_HP_HACK_CIN
+# undef cin
+# define cin __tcin.ref()
+# endif
+# if defined(cout) && !defined(@KWSYS_NAMESPACE@_IOS_HP_HACK_COUT)
+# define @KWSYS_NAMESPACE@_IOS_HP_HACK_COUT
+# undef cout
+# define cout __tcout.ref()
+# endif
+# if defined(cerr) && !defined(@KWSYS_NAMESPACE@_IOS_HP_HACK_CERR)
+# define @KWSYS_NAMESPACE@_IOS_HP_HACK_CERR
+# undef cerr
+# define cerr __tcerr.ref()
+# endif
+# if defined(clog) && !defined(@KWSYS_NAMESPACE@_IOS_HP_HACK_CLOG)
+# define @KWSYS_NAMESPACE@_IOS_HP_HACK_CLOG
+# undef clog
+# define clog __tclog.ref()
+# endif
+# endif
+#endif
+
+// If using our own sstream emulation code, put the standard
+// streams in the same namespace.
+#if !@KWSYS_NAMESPACE@_IOS_USE_SSTREAM
+namespace @KWSYS_NAMESPACE@_ios
+{
+ typedef int streamsize;
+ typedef int streamoff;
+ using @KWSYS_NAMESPACE@_ios_namespace::ostream;
+ using @KWSYS_NAMESPACE@_ios_namespace::istream;
+ using @KWSYS_NAMESPACE@_ios_namespace::ios;
+ using @KWSYS_NAMESPACE@_ios_namespace::endl;
+ using @KWSYS_NAMESPACE@_ios_namespace::flush;
+# if defined(@KWSYS_NAMESPACE@_IOS_HP_HACK_CIN)
+ using @KWSYS_NAMESPACE@_ios_namespace::__tcin;
+# else
+ using @KWSYS_NAMESPACE@_ios_namespace::cin;
+# endif
+# if defined(@KWSYS_NAMESPACE@_IOS_HP_HACK_COUT)
+ using @KWSYS_NAMESPACE@_ios_namespace::__tcout;
+# else
+ using @KWSYS_NAMESPACE@_ios_namespace::cout;
+# endif
+# if defined(@KWSYS_NAMESPACE@_IOS_HP_HACK_CERR)
+ using @KWSYS_NAMESPACE@_ios_namespace::__tcerr;
+# else
+ using @KWSYS_NAMESPACE@_ios_namespace::cerr;
+# endif
+# if defined(@KWSYS_NAMESPACE@_IOS_HP_HACK_CLOG)
+ using @KWSYS_NAMESPACE@_ios_namespace::__tclog;
+# else
+ using @KWSYS_NAMESPACE@_ios_namespace::clog;
+# endif
+}
+#endif
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
diff --git a/Source/kwsys/kwsys_ios_sstream.h.in b/Source/kwsys/kwsys_ios_sstream.h.in
new file mode 100644
index 0000000000..29d250c7a6
--- /dev/null
+++ b/Source/kwsys/kwsys_ios_sstream.h.in
@@ -0,0 +1,199 @@
+/*============================================================================
+ 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@_ios_sstream
+#define @KWSYS_NAMESPACE@_ios_sstream
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+/* Define this macro temporarily to keep the code readable. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys_stl @KWSYS_NAMESPACE@_stl
+#endif
+
+#if @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
+# ifdef _MSC_VER
+# pragma warning (push, 1)
+# pragma warning (disable: 4702)
+# endif
+# include <sstream>
+# ifdef _MSC_VER
+# pragma warning(pop)
+# endif
+#else
+# ifdef _MSC_VER
+# pragma warning (push, 1)
+# pragma warning (disable: 4702)
+# pragma warning (disable: 4995) /* Old streams are deprecated. */
+# endif
+# if @KWSYS_NAMESPACE@_IOS_USE_ANSI
+# include <strstream>
+# elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H
+# include <strstream.h>
+# elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H
+# include <strstrea.h>
+# endif
+# if @KWSYS_NAMESPACE@_IOS_USE_ANSI
+# include <new> // Need placement operator new.
+# else
+# include <new.h> // Need placement operator new.
+# endif
+# ifdef _MSC_VER
+# pragma warning(pop)
+# endif
+
+// Only have old std strstream classes. Wrap them to look like new
+// ostringstream and istringstream classes.
+
+# include <@KWSYS_NAMESPACE@/stl/string>
+
+namespace @KWSYS_NAMESPACE@_ios
+{
+using @KWSYS_NAMESPACE@_ios_namespace::streambuf;
+using @KWSYS_NAMESPACE@_ios_namespace::ostream;
+using @KWSYS_NAMESPACE@_ios_namespace::istream;
+using @KWSYS_NAMESPACE@_ios_namespace::strstream;
+using @KWSYS_NAMESPACE@_ios_namespace::istrstream;
+using @KWSYS_NAMESPACE@_ios_namespace::ostrstream;
+using @KWSYS_NAMESPACE@_ios_namespace::ios;
+using @KWSYS_NAMESPACE@_ios_namespace::endl;
+using @KWSYS_NAMESPACE@_ios_namespace::ends;
+using @KWSYS_NAMESPACE@_ios_namespace::flush;
+
+class stringstream_cleanup
+{
+public:
+ stringstream_cleanup(strstream& str): m_StrStream(str) {}
+ ~stringstream_cleanup() { m_StrStream.rdbuf()->freeze(0); }
+ static void IgnoreUnusedVariable(const stringstream_cleanup&) {}
+protected:
+ strstream& m_StrStream;
+private:
+ void operator=(stringstream_cleanup const&);
+};
+
+class stringstream: public strstream
+{
+public:
+ typedef strstream Superclass;
+ stringstream() {}
+ stringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
+ kwsys_stl::string str()
+ {
+ stringstream_cleanup cleanup(*this);
+ stringstream_cleanup::IgnoreUnusedVariable(cleanup);
+// Visual Studio 6 has a strstream::pcount, but this is not rdbuf()->pcount()
+#if (@KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H) && defined(_MSC_VER) && (_MSC_VER == 1200)
+ int count = this->pcount();
+#elif defined(__WATCOMC__)
+ int count = this->rdbuf()->out_waiting();
+#else
+ int count = this->rdbuf()->pcount();
+#endif
+ const char* ptr = this->Superclass::str();
+ return kwsys_stl::string(ptr?ptr:"", count);
+ }
+ void str(const kwsys_stl::string& s)
+ {
+ this->~stringstream();
+ new (this) stringstream(s);
+ }
+private:
+ stringstream(const stringstream&);
+ void operator=(const stringstream&);
+};
+
+class ostringstream_cleanup
+{
+public:
+ ostringstream_cleanup(ostrstream& ostr): m_OStrStream(ostr) {}
+ ~ostringstream_cleanup() { m_OStrStream.rdbuf()->freeze(0); }
+ static void IgnoreUnusedVariable(const ostringstream_cleanup&) {}
+protected:
+ ostrstream& m_OStrStream;
+private:
+ void operator=(ostringstream_cleanup const&);
+};
+
+class ostringstream: public ostrstream
+{
+public:
+ typedef ostrstream Superclass;
+ ostringstream() {}
+ ostringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
+ kwsys_stl::string str()
+ {
+ ostringstream_cleanup cleanup(*this);
+ ostringstream_cleanup::IgnoreUnusedVariable(cleanup);
+ int count = this->pcount();
+ const char* ptr = this->Superclass::str();
+ return kwsys_stl::string(ptr?ptr:"", count);
+ }
+ void str(const kwsys_stl::string& s)
+ {
+ this->~ostringstream();
+ new (this) ostringstream(s);
+ }
+private:
+ ostringstream(const ostringstream&);
+ void operator=(const ostringstream&);
+};
+
+#if defined(_MSC_VER)
+# pragma warning (push)
+# pragma warning (disable: 4097) /* typedef-name used as synonym for class */
+#endif
+#if defined(__WATCOMC__)
+// W728: class modifiers for 'A' conflict with class modifiers for 'B'
+# pragma warning 728 10
+#endif
+
+class istringstream: private kwsys_stl::string, public istrstream
+{
+public:
+ typedef kwsys_stl::string StdString;
+ typedef istrstream IStrStream;
+ istringstream(): StdString(),
+ IStrStream(const_cast<char*>(StdString::c_str())) {}
+ istringstream(const kwsys_stl::string& s):
+ StdString(s), IStrStream(const_cast<char*>(StdString::c_str())) {}
+ kwsys_stl::string str() const { return *this; }
+ void str(const kwsys_stl::string& s)
+ {
+ this->~istringstream();
+ new (this) istringstream(s);
+ }
+ void clear(int flags)
+ {
+ this->IStrStream::clear(flags);
+ }
+private:
+ istringstream(const istringstream&);
+ void operator=(const istringstream&);
+};
+
+#if defined(__WATCOMC__)
+# pragma warning 728 9
+#endif
+#if defined(_MSC_VER)
+# pragma warning (pop)
+#endif
+
+} // namespace @KWSYS_NAMESPACE@_ios
+
+#endif
+
+/* Undefine temporary macro. */
+#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsys_stl
+#endif
+
+#endif
diff --git a/Source/kwsys/kwsys_stl.hxx.in b/Source/kwsys/kwsys_stl.hxx.in
new file mode 100644
index 0000000000..610e6d4711
--- /dev/null
+++ b/Source/kwsys/kwsys_stl.hxx.in
@@ -0,0 +1,49 @@
+/*============================================================================
+ 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@_stl_@KWSYS_STL_HEADER@
+#define @KWSYS_NAMESPACE@_stl_@KWSYS_STL_HEADER@
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+/* Avoid warnings in MSVC standard headers. */
+#ifdef _MSC_VER
+# pragma warning (push, 1)
+# pragma warning (disable: 4702)
+# pragma warning (disable: 4786)
+#endif
+
+/* The HP standard library defines the functor "times" instead of
+ "multiplies" as specified by C++98 20.3.2 for backward
+ compatibility with earlier specifications. Defining this macro
+ fixes this behavior. The name "times" also conflicts with the
+ function declared in sys/times.h on that platform, so we must do
+ this as a work-around anyway. */
+#if defined(__HP_aCC) && !defined(__HPACC_USING_MULTIPLIES_IN_FUNCTIONAL)
+# define __HPACC_USING_MULTIPLIES_IN_FUNCTIONAL
+# define @KWSYS_NAMESPACE@_DEFINED___HPACC_USING_MULTIPLIES_IN_FUNCTIONAL
+#endif
+
+/* Include the real header. */
+#include <@KWSYS_STL_HEADER@>
+
+/* Cleanup. */
+#if defined(@KWSYS_NAMESPACE@_DEFINED___HPACC_USING_MULTIPLIES_IN_FUNCTIONAL)
+# undef @KWSYS_NAMESPACE@_DEFINED___HPACC_USING_MULTIPLIES_IN_FUNCTIONAL
+# undef __HPACC_USING_MULTIPLIES_IN_FUNCTIONAL
+#endif
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+@KWSYS_STL_HEADER_EXTRA@
+#endif
diff --git a/Source/kwsys/kwsys_stl_string.hxx.in b/Source/kwsys/kwsys_stl_string.hxx.in
new file mode 100644
index 0000000000..cd312cb8e3
--- /dev/null
+++ b/Source/kwsys/kwsys_stl_string.hxx.in
@@ -0,0 +1,123 @@
+/*============================================================================
+ 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.
+============================================================================*/
+
+// This header is extra code for <@KWSYS_NAMESPACE@/stl/string>.
+#if !defined(@KWSYS_NAMESPACE@_stl_string_including_hxx)
+# error "The header <@KWSYS_NAMESPACE@/stl/string.hxx> may be included only by <@KWSYS_NAMESPACE@/stl/string>."
+#endif
+
+// Provide the istream operator for the stl string if it is not
+// provided by the system or another copy of kwsys. Allow user code
+// to block this definition by defining the macro
+// @KWSYS_NAMESPACE@_STL_STRING_NO_ISTREAM
+// to avoid conflicts with other libraries. User code can test for
+// this definition by checking the macro
+// @KWSYS_NAMESPACE@_STL_STRING_ISTREAM_DEFINED
+#if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM && !defined(@KWSYS_NAMESPACE@_STL_STRING_NO_ISTREAM) && !defined(KWSYS_STL_STRING_ISTREAM_DEFINED)
+# define KWSYS_STL_STRING_ISTREAM_DEFINED
+# define @KWSYS_NAMESPACE@_STL_STRING_ISTREAM_DEFINED
+# include <ctype.h> // isspace
+# include <@KWSYS_NAMESPACE@/ios/iostream>
+# if defined(__WATCOMC__)
+namespace @KWSYS_NAMESPACE@
+{
+struct ios_istream_hack: public kwsys_ios::istream
+{ void eatwhite() { this->@KWSYS_NAMESPACE@_ios::istream::eatwhite(); } };
+}
+# endif
+inline @KWSYS_NAMESPACE@_ios::istream&
+operator>>(@KWSYS_NAMESPACE@_ios::istream& is,
+ @KWSYS_NAMESPACE@_stl::string& s)
+{
+ // Keep track of the resulting state.
+ int state = @KWSYS_NAMESPACE@_ios::ios::goodbit;
+
+ // Save the width setting and set it back to zero.
+ size_t n = static_cast<size_t>(is.width(0));
+
+ // Clear any old contents of the output string.
+ s.erase();
+
+ // Skip leading whitespace.
+#if defined(__WATCOMC__)
+ static_cast<@KWSYS_NAMESPACE@::ios_istream_hack&>(is).eatwhite();
+#else
+ is.eatwhite();
+#endif
+ @KWSYS_NAMESPACE@_ios::istream& okay = is;
+
+ if(okay)
+ {
+ // Select a maximum possible length.
+ if(n == 0 || n >= s.max_size())
+ {
+ n = s.max_size();
+ }
+
+ // Read until a space is found or the maximum length is reached.
+ bool success = false;
+ for(int c = is.peek(); (--n > 0 && c != EOF && !isspace(c)); c = is.peek())
+ {
+ s += static_cast<char>(c);
+ success = true;
+ is.ignore();
+ }
+
+ // Set flags for resulting state.
+ if(is.peek() == EOF) { state |= @KWSYS_NAMESPACE@_ios::ios::eofbit; }
+ if(!success) { state |= @KWSYS_NAMESPACE@_ios::ios::failbit; }
+ }
+
+ // Set the final result state.
+ is.clear(state);
+ return is;
+}
+#endif
+
+// Provide the ostream operator for the stl string if it is not
+// provided by the system or another copy of kwsys. Allow user code
+// to block this definition by defining the macro
+// @KWSYS_NAMESPACE@_STL_STRING_NO_OSTREAM
+// to avoid conflicts with other libraries. User code can test for
+// this definition by checking the macro
+// @KWSYS_NAMESPACE@_STL_STRING_OSTREAM_DEFINED
+#if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM && !defined(@KWSYS_NAMESPACE@_STL_STRING_NO_OSTREAM) && !defined(KWSYS_STL_STRING_OSTREAM_DEFINED)
+# define KWSYS_STL_STRING_OSTREAM_DEFINED
+# define @KWSYS_NAMESPACE@_STL_STRING_OSTREAM_DEFINED
+# include <@KWSYS_NAMESPACE@/ios/iostream>
+inline @KWSYS_NAMESPACE@_ios::ostream&
+operator<<(@KWSYS_NAMESPACE@_ios::ostream& os,
+ @KWSYS_NAMESPACE@_stl::string const& s)
+{
+ return os << s.c_str();
+}
+#endif
+
+// Provide the operator!= for the stl string and char* if it is not
+// provided by the system or another copy of kwsys. Allow user code
+// to block this definition by defining the macro
+// @KWSYS_NAMESPACE@_STL_STRING_NO_NEQ_CHAR
+// to avoid conflicts with other libraries. User code can test for
+// this definition by checking the macro
+// @KWSYS_NAMESPACE@_STL_STRING_NEQ_CHAR_DEFINED
+#if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR && !defined(@KWSYS_NAMESPACE@_STL_STRING_NO_NEQ_CHAR) && !defined(KWSYS_STL_STRING_NEQ_CHAR_DEFINED)
+# define KWSYS_STL_STRING_NEQ_CHAR_DEFINED
+# define @KWSYS_NAMESPACE@_STL_STRING_NEQ_CHAR_DEFINED
+inline bool operator!=(@KWSYS_NAMESPACE@_stl::string const& s, const char* c)
+{
+ return !(s == c);
+}
+inline bool operator!=(const char* c, @KWSYS_NAMESPACE@_stl::string const& s)
+{
+ return !(s == c);
+}
+#endif
diff --git a/Source/kwsys/testAutoPtr.cxx b/Source/kwsys/testAutoPtr.cxx
new file mode 100644
index 0000000000..ed75ff4475
--- /dev/null
+++ b/Source/kwsys/testAutoPtr.cxx
@@ -0,0 +1,166 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#ifdef __BORLANDC__
+# pragma warn -8027 /* 'for' not inlined. */
+# pragma warn -8026 /* exception not inlined. */
+#endif
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(auto_ptr.hxx)
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "auto_ptr.hxx.in"
+#endif
+
+#include <stdio.h>
+
+#define ASSERT(x,y) if (!(x)) { printf("FAIL: " y "\n"); status = 1; }
+
+int instances = 0; // don't declare as static
+
+struct A
+{
+ A() { ++instances; }
+ ~A() { --instances; }
+ A* self() {return this; }
+};
+struct B: public A {};
+
+static int function_call(kwsys::auto_ptr<A> a)
+{
+ return a.get()? 1:0;
+}
+
+static A* get_A(A& a) { return &a; }
+
+static kwsys::auto_ptr<A> generate_auto_ptr_A()
+{
+ return kwsys::auto_ptr<A>(new A);
+}
+
+static kwsys::auto_ptr<B> generate_auto_ptr_B()
+{
+ return kwsys::auto_ptr<B>(new B);
+}
+
+int testAutoPtr(int, char*[])
+{
+ int status = 0;
+
+ // Keep everything in a subscope so we can detect leaks.
+ {
+ kwsys::auto_ptr<A> pa0;
+ kwsys::auto_ptr<A> pa1(new A());
+ kwsys::auto_ptr<B> pb1(new B());
+ kwsys::auto_ptr<B> pb2(new B());
+ kwsys::auto_ptr<A> pa2(new B());
+
+ A* ptr = get_A(*pa1);
+ ASSERT(ptr == pa1.get(),
+ "auto_ptr does not return correct object when dereferenced");
+ ptr = pa1->self();
+ ASSERT(ptr == pa1.get(),
+ "auto_ptr does not return correct pointer from operator->");
+
+ A* before = pa0.get();
+ pa0.reset(new A());
+ ASSERT(pa0.get() && pa0.get() != before,
+ "auto_ptr empty after reset(new A())");
+
+ before = pa0.get();
+ pa0.reset(new B());
+ ASSERT(pa0.get() && pa0.get() != before,
+ "auto_ptr empty after reset(new B())");
+
+ delete pa0.release();
+ ASSERT(!pa0.get(), "auto_ptr holds an object after release()");
+
+ kwsys::auto_ptr<A> pa3(pb1);
+ ASSERT(!pb1.get(),
+ "auto_ptr full after being used to construct another");
+ ASSERT(pa3.get(),
+ "auto_ptr empty after construction from another");
+
+ {
+ kwsys::auto_ptr<A> pa;
+ pa = pa3;
+ ASSERT(!pa3.get(),
+ "auto_ptr full after assignment to another");
+ ASSERT(pa.get(),
+ "auto_ptr empty after assignment from another");
+ }
+
+ {
+ kwsys::auto_ptr<A> pa;
+ pa = pb2;
+ ASSERT(!pb2.get(),
+ "auto_ptr full after assignment to compatible");
+ ASSERT(pa.get(),
+ "auto_ptr empty after assignment from compatible");
+ }
+
+ {
+ int receive = function_call(pa2);
+ ASSERT(receive,
+ "auto_ptr did not receive ownership in called function");
+ ASSERT(!pa2.get(),
+ "auto_ptr did not release ownership to called function");
+ }
+
+ {
+ int received = function_call(generate_auto_ptr_A());
+ ASSERT(received,
+ "auto_ptr in called function did not take ownership "
+ "from factory function");
+ }
+
+#if 0
+ // Is this allowed by the standard?
+ {
+ int received = function_call(generate_auto_ptr_B());
+ ASSERT(received,
+ "auto_ptr in called function did not take ownership "
+ "from factory function with conversion");
+ }
+#endif
+
+ {
+ kwsys::auto_ptr<A> pa(generate_auto_ptr_A());
+ ASSERT(pa.get(),
+ "auto_ptr empty after construction from factory function");
+ }
+
+ {
+ kwsys::auto_ptr<A> pa;
+ pa = generate_auto_ptr_A();
+ ASSERT(pa.get(),
+ "auto_ptr empty after assignment from factory function");
+ }
+
+ {
+ kwsys::auto_ptr<A> pa(generate_auto_ptr_B());
+ ASSERT(pa.get(),
+ "auto_ptr empty after construction from compatible factory function");
+ }
+
+ {
+ kwsys::auto_ptr<A> pa;
+ pa = generate_auto_ptr_B();
+ ASSERT(pa.get(),
+ "auto_ptr empty after assignment from compatible factory function");
+ }
+ }
+
+ ASSERT(instances == 0, "auto_ptr leaked an object");
+
+ return status;
+}
diff --git a/Source/kwsys/testCommandLineArguments.cxx b/Source/kwsys/testCommandLineArguments.cxx
new file mode 100644
index 0000000000..6a03c0f768
--- /dev/null
+++ b/Source/kwsys/testCommandLineArguments.cxx
@@ -0,0 +1,187 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(CommandLineArguments.hxx)
+#include KWSYS_HEADER(ios/iostream)
+#include KWSYS_HEADER(stl/vector)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "CommandLineArguments.hxx.in"
+# include "kwsys_ios_iostream.h.in"
+#endif
+
+#include <stddef.h> /* size_t */
+#include <string.h> /* strcmp */
+
+static void* random_ptr = reinterpret_cast<void*>(0x123);
+
+static int argument(const char* arg, const char* value, void* call_data)
+{
+ kwsys_ios::cout << "Got argument: \"" << arg << "\" value: \"" << (value?value:"(null)") << "\"" << kwsys_ios::endl;
+ if ( call_data != random_ptr )
+ {
+ kwsys_ios::cerr << "Problem processing call_data" << kwsys_ios::endl;
+ return 0;
+ }
+ return 1;
+}
+
+static int unknown_argument(const char* argument, void* call_data)
+{
+ kwsys_ios::cout << "Got unknown argument: \"" << argument << "\"" << kwsys_ios::endl;
+ if ( call_data != random_ptr )
+ {
+ kwsys_ios::cerr << "Problem processing call_data" << kwsys_ios::endl;
+ return 0;
+ }
+ return 1;
+}
+
+static bool CompareTwoItemsOnList(bool i1, bool i2) { return i1 == i2; }
+static bool CompareTwoItemsOnList(int i1, int i2) { return i1 == i2; }
+static bool CompareTwoItemsOnList(double i1, double i2) { return i1 == i2; }
+static bool CompareTwoItemsOnList(const char* i1,
+ const char* i2) { return strcmp(i1, i2) == 0; }
+static bool CompareTwoItemsOnList(const kwsys_stl::string& i1,
+ const kwsys_stl::string& i2) { return i1 == i2; }
+
+int testCommandLineArguments(int argc, char* argv[])
+{
+ // Example run: ./testCommandLineArguments --some-int-variable 4
+ // --another-bool-variable --some-bool-variable=yes
+ // --some-stl-string-variable=foobar --set-bool-arg1 --set-bool-arg2
+ // --some-string-variable=hello
+
+ int res = 0;
+ kwsys::CommandLineArguments arg;
+ arg.Initialize(argc, argv);
+
+ // For error handling
+ arg.SetClientData(random_ptr);
+ arg.SetUnknownArgumentCallback(unknown_argument);
+
+ int some_int_variable = 10;
+ double some_double_variable = 10.10;
+ char* some_string_variable = 0;
+ kwsys_stl::string some_stl_string_variable = "";
+ bool some_bool_variable = false;
+ bool some_bool_variable1 = false;
+ bool bool_arg1 = false;
+ int bool_arg2 = 0;
+
+ kwsys_stl::vector<int> numbers_argument;
+ int valid_numbers[] = { 5, 1, 8, 3, 7, 1, 3, 9, 7, 1 };
+
+ kwsys_stl::vector<double> doubles_argument;
+ double valid_doubles[] = { 12.5, 1.31, 22 };
+
+ kwsys_stl::vector<bool> bools_argument;
+ bool valid_bools[] = { true, true, false };
+
+ kwsys_stl::vector<char*> strings_argument;
+ const char* valid_strings[] = { "andy", "bill", "brad", "ken" };
+
+ kwsys_stl::vector<kwsys_stl::string> stl_strings_argument;
+ kwsys_stl::string valid_stl_strings[] = { "ken", "brad", "bill", "andy" };
+
+ typedef kwsys::CommandLineArguments argT;
+
+ arg.AddArgument("--some-int-variable", argT::SPACE_ARGUMENT, &some_int_variable, "Set some random int variable");
+ arg.AddArgument("--some-double-variable", argT::CONCAT_ARGUMENT, &some_double_variable, "Set some random double variable");
+ arg.AddArgument("--some-string-variable", argT::EQUAL_ARGUMENT, &some_string_variable, "Set some random string variable");
+ arg.AddArgument("--some-stl-string-variable", argT::EQUAL_ARGUMENT, &some_stl_string_variable, "Set some random stl string variable");
+ arg.AddArgument("--some-bool-variable", argT::EQUAL_ARGUMENT, &some_bool_variable, "Set some random bool variable");
+ arg.AddArgument("--another-bool-variable", argT::NO_ARGUMENT, &some_bool_variable1, "Set some random bool variable 1");
+ arg.AddBooleanArgument("--set-bool-arg1", &bool_arg1, "Test AddBooleanArgument 1");
+ arg.AddBooleanArgument("--set-bool-arg2", &bool_arg2, "Test AddBooleanArgument 2");
+ arg.AddArgument("--some-multi-argument", argT::MULTI_ARGUMENT, &numbers_argument, "Some multiple values variable");
+ arg.AddArgument("-N", argT::SPACE_ARGUMENT, &doubles_argument, "Some explicit multiple values variable");
+ arg.AddArgument("-BB", argT::CONCAT_ARGUMENT, &bools_argument, "Some explicit multiple values variable");
+ arg.AddArgument("-SS", argT::EQUAL_ARGUMENT, &strings_argument, "Some explicit multiple values variable");
+ arg.AddArgument("-SSS", argT::MULTI_ARGUMENT, &stl_strings_argument, "Some explicit multiple values variable");
+
+ arg.AddCallback("-A", argT::NO_ARGUMENT, argument, random_ptr, "Some option -A. This option has a multiline comment. It should demonstrate how the code splits lines.");
+ arg.AddCallback("-B", argT::SPACE_ARGUMENT, argument, random_ptr, "Option -B takes argument with space");
+ arg.AddCallback("-C", argT::EQUAL_ARGUMENT, argument, random_ptr, "Option -C takes argument after =");
+ arg.AddCallback("-D", argT::CONCAT_ARGUMENT, argument, random_ptr, "This option takes concatinated argument");
+ arg.AddCallback("--long1", argT::NO_ARGUMENT, argument, random_ptr, "-A");
+ arg.AddCallback("--long2", argT::SPACE_ARGUMENT, argument, random_ptr, "-B");
+ arg.AddCallback("--long3", argT::EQUAL_ARGUMENT, argument, random_ptr, "Same as -C but a bit different");
+ arg.AddCallback("--long4", argT::CONCAT_ARGUMENT, argument, random_ptr, "-C");
+
+ if ( !arg.Parse() )
+ {
+ kwsys_ios::cerr << "Problem parsing arguments" << kwsys_ios::endl;
+ res = 1;
+ }
+ kwsys_ios::cout << "Help: " << arg.GetHelp() << kwsys_ios::endl;
+
+ kwsys_ios::cout << "Some int variable was set to: " << some_int_variable << kwsys_ios::endl;
+ kwsys_ios::cout << "Some double variable was set to: " << some_double_variable << kwsys_ios::endl;
+ if ( some_string_variable && strcmp(some_string_variable, "test string with space") == 0)
+ {
+ kwsys_ios::cout << "Some string variable was set to: " << some_string_variable << kwsys_ios::endl;
+ delete [] some_string_variable;
+ }
+ else
+ {
+ kwsys_ios::cerr << "Problem setting string variable" << kwsys_ios::endl;
+ res = 1;
+ }
+ size_t cc;
+#define CompareTwoLists(list1, list_valid, lsize) \
+ if ( list1.size() != lsize ) \
+ { \
+ kwsys_ios::cerr << "Problem setting " #list1 ". Size is: " << list1.size() \
+ << " should be: " << lsize << kwsys_ios::endl; \
+ res = 1; \
+ } \
+ else \
+ { \
+ kwsys_ios::cout << #list1 " argument set:"; \
+ for ( cc =0; cc < lsize; ++ cc ) \
+ { \
+ kwsys_ios::cout << " " << list1[cc]; \
+ if ( !CompareTwoItemsOnList(list1[cc], list_valid[cc]) ) \
+ { \
+ kwsys_ios::cerr << "Problem setting " #list1 ". Value of " \
+ << cc << " is: [" << list1[cc] << "] <> [" \
+ << list_valid[cc] << "]" << kwsys_ios::endl; \
+ res = 1; \
+ break; \
+ } \
+ } \
+ kwsys_ios::cout << kwsys_ios::endl; \
+ }
+
+ CompareTwoLists(numbers_argument, valid_numbers, 10);
+ CompareTwoLists(doubles_argument, valid_doubles, 3);
+ CompareTwoLists(bools_argument, valid_bools, 3);
+ CompareTwoLists(strings_argument, valid_strings, 4);
+ CompareTwoLists(stl_strings_argument, valid_stl_strings, 4);
+
+ kwsys_ios::cout << "Some STL String variable was set to: " << some_stl_string_variable << kwsys_ios::endl;
+ kwsys_ios::cout << "Some bool variable was set to: " << some_bool_variable << kwsys_ios::endl;
+ kwsys_ios::cout << "Some bool variable was set to: " << some_bool_variable1 << kwsys_ios::endl;
+ kwsys_ios::cout << "bool_arg1 variable was set to: " << bool_arg1 << kwsys_ios::endl;
+ kwsys_ios::cout << "bool_arg2 variable was set to: " << bool_arg2 << kwsys_ios::endl;
+ kwsys_ios::cout << kwsys_ios::endl;
+
+ for ( cc = 0; cc < strings_argument.size(); ++ cc )
+ {
+ delete [] strings_argument[cc];
+ strings_argument[cc] = 0;
+ }
+ return res;
+}
diff --git a/Source/kwsys/testCommandLineArguments1.cxx b/Source/kwsys/testCommandLineArguments1.cxx
new file mode 100644
index 0000000000..b65c37f85c
--- /dev/null
+++ b/Source/kwsys/testCommandLineArguments1.cxx
@@ -0,0 +1,108 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(CommandLineArguments.hxx)
+#include KWSYS_HEADER(ios/iostream)
+#include KWSYS_HEADER(stl/vector)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "CommandLineArguments.hxx.in"
+# include "kwsys_ios_iostream.h.in"
+#endif
+
+#include <assert.h> /* assert */
+#include <string.h> /* strcmp */
+
+int testCommandLineArguments1(int argc, char* argv[])
+{
+ kwsys::CommandLineArguments arg;
+ arg.Initialize(argc, argv);
+
+ int n = 0;
+ char* m = 0;
+ kwsys_stl::string p;
+ int res = 0;
+
+ typedef kwsys::CommandLineArguments argT;
+ arg.AddArgument("-n", argT::SPACE_ARGUMENT, &n, "Argument N");
+ arg.AddArgument("-m", argT::EQUAL_ARGUMENT, &m, "Argument M");
+ arg.AddBooleanArgument("-p", &p, "Argument P");
+
+ arg.StoreUnusedArguments(true);
+
+ if ( !arg.Parse() )
+ {
+ kwsys_ios::cerr << "Problem parsing arguments" << kwsys_ios::endl;
+ res = 1;
+ }
+ if ( n != 24 )
+ {
+ kwsys_ios::cout << "Problem setting N. Value of N: " << n << kwsys_ios::endl;
+ res = 1;
+ }
+ if ( !m || strcmp(m, "test value") != 0 )
+ {
+ kwsys_ios::cout << "Problem setting M. Value of M: " << m << kwsys_ios::endl;
+ res = 1;
+ }
+ if ( p != "1" )
+ {
+ kwsys_ios::cout << "Problem setting P. Value of P: " << p << kwsys_ios::endl;
+ res = 1;
+ }
+ kwsys_ios::cout << "Value of N: " << n << kwsys_ios::endl;
+ kwsys_ios::cout << "Value of M: " << m << kwsys_ios::endl;
+ kwsys_ios::cout << "Value of P: " << p << kwsys_ios::endl;
+ if ( m )
+ {
+ delete [] m;
+ }
+
+ char** newArgv = 0;
+ int newArgc = 0;
+ arg.GetUnusedArguments(&newArgc, &newArgv);
+ int cc;
+ const char* valid_unused_args[9] = {
+ 0, "--ignored", "--second-ignored", "third-ignored",
+ "some", "junk", "at", "the", "end"
+ };
+ if ( newArgc != 9 )
+ {
+ kwsys_ios::cerr << "Bad number of unused arguments: " << newArgc << kwsys_ios::endl;
+ res = 1;
+ }
+ for ( cc = 0; cc < newArgc; ++ cc )
+ {
+ assert(newArgv[cc]); /* Quiet Clang scan-build. */
+ kwsys_ios::cout << "Unused argument[" << cc << "] = [" << newArgv[cc] << "]"
+ << kwsys_ios::endl;
+ if ( cc >= 9 )
+ {
+ kwsys_ios::cerr << "Too many unused arguments: " << cc << kwsys_ios::endl;
+ res = 1;
+ }
+ else if ( valid_unused_args[cc] &&
+ strcmp(valid_unused_args[cc], newArgv[cc]) != 0 )
+ {
+ kwsys_ios::cerr << "Bad unused argument [" << cc << "] \""
+ << newArgv[cc] << "\" should be: \"" << valid_unused_args[cc] << "\""
+ << kwsys_ios::endl;
+ res = 1;
+ }
+ }
+ arg.DeleteRemainingArguments(newArgc, &newArgv);
+
+ return res;
+}
+
diff --git a/Source/kwsys/testDynamicLoader.cxx b/Source/kwsys/testDynamicLoader.cxx
new file mode 100644
index 0000000000..58adb844b7
--- /dev/null
+++ b/Source/kwsys/testDynamicLoader.cxx
@@ -0,0 +1,129 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+
+#include KWSYS_HEADER(DynamicLoader.hxx)
+#include KWSYS_HEADER(ios/iostream)
+#include KWSYS_HEADER(stl/string)
+
+#if defined(__BEOS__) || defined(__HAIKU__)
+#include <be/kernel/OS.h> /* disable_debugger() API. */
+#endif
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "DynamicLoader.hxx.in"
+# include "kwsys_ios_iostream.h.in"
+# include "kwsys_stl_string.hxx.in"
+#endif
+
+// Include with <> instead of "" to avoid getting any in-source copy
+// left on disk.
+#include <testSystemTools.h>
+
+static kwsys_stl::string GetLibName(const char* lname)
+{
+ // Construct proper name of lib
+ kwsys_stl::string slname;
+ slname = EXECUTABLE_OUTPUT_PATH;
+#ifdef CMAKE_INTDIR
+ slname += "/";
+ slname += CMAKE_INTDIR;
+#endif
+ slname += "/";
+ slname += kwsys::DynamicLoader::LibPrefix();
+ slname += lname;
+ slname += kwsys::DynamicLoader::LibExtension();
+
+ return slname;
+}
+
+/* libname = Library name (proper prefix, proper extension)
+ * System = symbol to lookup in libname
+ * r1: should OpenLibrary succeed ?
+ * r2: should GetSymbolAddress succeed ?
+ * r3: should CloseLibrary succeed ?
+ */
+int TestDynamicLoader(const char* libname, const char* symbol, int r1, int r2, int r3)
+{
+ kwsys_ios::cerr << "Testing: " << libname << kwsys_ios::endl;
+ kwsys::DynamicLoader::LibraryHandle l
+ = kwsys::DynamicLoader::OpenLibrary(libname);
+ // If result is incompatible with expectation just fails (xor):
+ if( (r1 && !l) || (!r1 && l) )
+ {
+ kwsys_ios::cerr
+ << kwsys::DynamicLoader::LastError() << kwsys_ios::endl;
+ return 1;
+ }
+ kwsys::DynamicLoader::SymbolPointer f
+ = kwsys::DynamicLoader::GetSymbolAddress(l, symbol);
+ if( (r2 && !f) || (!r2 && f) )
+ {
+ kwsys_ios::cerr
+ << kwsys::DynamicLoader::LastError() << kwsys_ios::endl;
+ return 1;
+ }
+#ifndef __APPLE__
+ int s = kwsys::DynamicLoader::CloseLibrary(l);
+ if( (r3 && !s) || (!r3 && s) )
+ {
+ kwsys_ios::cerr
+ << kwsys::DynamicLoader::LastError() << kwsys_ios::endl;
+ return 1;
+ }
+#else
+ (void)r3;
+#endif
+ return 0;
+}
+
+int testDynamicLoader(int argc, char *argv[])
+{
+#if defined(_WIN32)
+ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
+#elif defined(__BEOS__) || defined(__HAIKU__)
+ disable_debugger(1);
+#endif
+ int res = 0;
+ if( argc == 3 )
+ {
+ // User specify a libname and symbol to check.
+ res = TestDynamicLoader(argv[1], argv[2],1,1,1);
+ return res;
+ }
+
+// dlopen() on Syllable before 11/22/2007 doesn't return 0 on error
+#ifndef __SYLLABLE__
+ // Make sure that inexistent lib is giving correct result
+ res += TestDynamicLoader("azerty_", "foo_bar",0,0,0);
+ // Make sure that random binary file cannot be assimilated as dylib
+ res += TestDynamicLoader(TEST_SYSTEMTOOLS_SOURCE_DIR "/testSystemTools.bin", "wp",0,0,0);
+#endif
+
+#ifdef __linux__
+ // This one is actually fun to test, since dlopen is by default loaded...wonder why :)
+ res += TestDynamicLoader("foobar.lib", "dlopen",0,1,0);
+ res += TestDynamicLoader("libdl.so", "dlopen",1,1,1);
+ res += TestDynamicLoader("libdl.so", "TestDynamicLoader",1,0,1);
+#endif
+ // Now try on the generated library
+ kwsys_stl::string libname = GetLibName(KWSYS_NAMESPACE_STRING "TestDynload");
+ res += TestDynamicLoader(libname.c_str(), "dummy",1,0,1);
+ res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderSymbolPointer",1,1,1);
+ res += TestDynamicLoader(libname.c_str(), "_TestDynamicLoaderSymbolPointer",1,0,1);
+ res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderData",1,1,1);
+ res += TestDynamicLoader(libname.c_str(), "_TestDynamicLoaderData",1,0,1);
+
+ return res;
+}
diff --git a/Source/kwsys/testDynload.c b/Source/kwsys/testDynload.c
new file mode 100644
index 0000000000..ba60becbd0
--- /dev/null
+++ b/Source/kwsys/testDynload.c
@@ -0,0 +1,22 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#ifdef _WIN32
+#define DL_EXPORT __declspec( dllexport )
+#else
+#define DL_EXPORT
+#endif
+
+DL_EXPORT int TestDynamicLoaderData = 0;
+
+DL_EXPORT void TestDynamicLoaderSymbolPointer()
+{
+}
diff --git a/Source/kwsys/testEncode.c b/Source/kwsys/testEncode.c
new file mode 100644
index 0000000000..26d483b6f9
--- /dev/null
+++ b/Source/kwsys/testEncode.c
@@ -0,0 +1,76 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(MD5.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "MD5.h.in"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+static const unsigned char testMD5input1[] =
+" A quick brown fox jumps over the lazy dog.\n"
+" This is sample text for MD5 sum input.\n";
+static const char testMD5output1[] = "8f146af46ed4f267921bb937d4d3500c";
+
+static const int testMD5input2len = 28;
+static const unsigned char testMD5input2[] = "the cow jumped over the moon";
+static const char testMD5output2[] = "a2ad137b746138fae4e5adca9c85d3ae";
+
+static int testMD5_1(kwsysMD5* md5)
+{
+ char md5out[33];
+ kwsysMD5_Initialize(md5);
+ kwsysMD5_Append(md5, testMD5input1, -1);
+ kwsysMD5_FinalizeHex(md5, md5out);
+ md5out[32] = 0;
+ printf("md5sum 1: expected [%s]\n"
+ " got [%s]\n",
+ testMD5output1, md5out);
+ return (strcmp(md5out, testMD5output1) != 0)? 1:0;
+}
+
+static int testMD5_2(kwsysMD5* md5)
+{
+ unsigned char digest[16];
+ char md5out[33];
+ kwsysMD5_Initialize(md5);
+ kwsysMD5_Append(md5, testMD5input2, testMD5input2len);
+ kwsysMD5_Finalize(md5, digest);
+ kwsysMD5_DigestToHex(digest, md5out);
+ md5out[32] = 0;
+ printf("md5sum 2: expected [%s]\n"
+ " got [%s]\n",
+ testMD5output2, md5out);
+ return (strcmp(md5out, testMD5output2) != 0)? 1:0;
+}
+
+int testEncode(int argc, char* argv[])
+{
+ int result = 0;
+ (void)argc;
+ (void)argv;
+
+ /* Test MD5 digest. */
+ {
+ kwsysMD5* md5 = kwsysMD5_New();
+ result |= testMD5_1(md5);
+ result |= testMD5_2(md5);
+ kwsysMD5_Delete(md5);
+ }
+
+ return result;
+}
diff --git a/Source/kwsys/testEncoding.cxx b/Source/kwsys/testEncoding.cxx
new file mode 100644
index 0000000000..094588c1e3
--- /dev/null
+++ b/Source/kwsys/testEncoding.cxx
@@ -0,0 +1,199 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+
+#if defined(_MSC_VER)
+# pragma warning (disable:4786)
+#endif
+
+#include KWSYS_HEADER(Encoding.hxx)
+#include KWSYS_HEADER(Encoding.h)
+#include KWSYS_HEADER(ios/iostream)
+
+#include <locale.h>
+#include <string.h>
+#include <stdlib.h>
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "Encoding.hxx.in"
+# include "Encoding.h.in"
+# include "kwsys_ios_iostream.h.in"
+#endif
+
+//----------------------------------------------------------------------------
+static const unsigned char helloWorldStrings[][32] =
+{
+ // English
+ {'H','e','l','l','o',' ','W','o','r','l','d',0},
+ // Japanese
+ {0xE3, 0x81, 0x93, 0xE3, 0x82, 0x93, 0xE3, 0x81, 0xAB, 0xE3,
+ 0x81, 0xA1, 0xE3, 0x81, 0xAF, 0xE4, 0xB8, 0x96, 0xE7, 0x95,
+ 0x8C, 0},
+ // Arabic
+ {0xD9, 0x85, 0xD8, 0xB1, 0xD8, 0xAD, 0xD8, 0xA8, 0xD8, 0xA7,
+ 0x20, 0xD8, 0xA7, 0xD9, 0x84, 0xD8, 0xB9, 0xD8, 0xA7, 0xD9,
+ 0x84, 0xD9, 0x85, 0},
+ // Yiddish
+ {0xD7, 0x94, 0xD7, 0xA2, 0xD7, 0x9C, 0xD7, 0x90, 0x20, 0xD7,
+ 0x95, 0xD7, 0x95, 0xD7, 0xA2, 0xD7, 0x9C, 0xD7, 0x98, 0},
+ // Russian
+ {0xD0, 0xBF, 0xD1, 0x80, 0xD0, 0xB8, 0xD0, 0xB2, 0xD0, 0xB5,
+ 0xD1, 0x82, 0x20, 0xD0, 0xBC, 0xD0, 0xB8, 0xD1, 0x80, 0},
+ // Latin
+ {0x4D, 0x75, 0x6E, 0x64, 0x75, 0x73, 0x20, 0x73, 0x61, 0x6C,
+ 0x76, 0x65, 0},
+ // Swahili
+ {0x68, 0x75, 0x6A, 0x61, 0x6D, 0x62, 0x6F, 0x20, 0x44, 0x75,
+ 0x6E, 0x69, 0x61, 0},
+ // Icelandic
+ {0x48, 0x61, 0x6C, 0x6C, 0xC3, 0xB3, 0x20, 0x68, 0x65, 0x69,
+ 0x6D, 0x75, 0x72, 0},
+ {0}
+};
+
+//----------------------------------------------------------------------------
+static int testHelloWorldEncoding()
+{
+ int ret = 0;
+ for(int i=0; helloWorldStrings[i][0] != 0; i++)
+ {
+ std::string str = reinterpret_cast<const char*>(helloWorldStrings[i]);
+ std::cout << str << std::endl;
+ std::wstring wstr = kwsys::Encoding::ToWide(str);
+ std::string str2 = kwsys::Encoding::ToNarrow(wstr);
+ wchar_t* c_wstr = kwsysEncoding_DupToWide(str.c_str());
+ char* c_str2 = kwsysEncoding_DupToNarrow(c_wstr);
+ if(!wstr.empty() && (str != str2 || strcmp(c_str2, str.c_str())))
+ {
+ std::cout << "converted string was different: " << str2 << std::endl;
+ std::cout << "converted string was different: " << c_str2 << std::endl;
+ ret++;
+ }
+ free(c_wstr);
+ free(c_str2);
+ }
+ return ret;
+}
+
+static int testRobustEncoding()
+{
+ // test that the conversion functions handle invalid
+ // unicode correctly/gracefully
+
+ int ret = 0;
+ char cstr[] = {(char)-1, 0};
+ // this conversion could fail
+ std::wstring wstr = kwsys::Encoding::ToWide(cstr);
+
+ wstr = kwsys::Encoding::ToWide(NULL);
+ if(wstr != L"")
+ {
+ const wchar_t* wcstr = wstr.c_str();
+ std::cout << "ToWide(NULL) returned";
+ for(size_t i=0; i<wstr.size(); i++)
+ {
+ std::cout << " " << std::hex << (int)wcstr[i];
+ }
+ std::cout << std::endl;
+ ret++;
+ }
+ wstr = kwsys::Encoding::ToWide("");
+ if(wstr != L"")
+ {
+ const wchar_t* wcstr = wstr.c_str();
+ std::cout << "ToWide(\"\") returned";
+ for(size_t i=0; i<wstr.size(); i++)
+ {
+ std::cout << " " << std::hex << (int)wcstr[i];
+ }
+ std::cout << std::endl;
+ ret++;
+ }
+
+#ifdef WIN32
+ // 16 bit wchar_t - we make an invalid surrogate pair
+ wchar_t cwstr[] = {0xD801, 0xDA00, 0};
+ // this conversion could fail
+ std::string win_str = kwsys::Encoding::ToNarrow(cwstr);
+#endif
+
+ std::string str = kwsys::Encoding::ToNarrow(NULL);
+ if(str != "")
+ {
+ std::cout << "ToNarrow(NULL) returned " << str << std::endl;
+ ret++;
+ }
+
+ str = kwsys::Encoding::ToNarrow(L"");
+ if(wstr != L"")
+ {
+ std::cout << "ToNarrow(\"\") returned " << str << std::endl;
+ ret++;
+ }
+
+ return ret;
+}
+
+static int testCommandLineArguments()
+{
+ int status = 0;
+
+ char const* argv[2] = {
+ "./app.exe",
+ (char const*)helloWorldStrings[1]
+ };
+
+ kwsys::Encoding::CommandLineArguments args(2, argv);
+ kwsys::Encoding::CommandLineArguments arg2 =
+ kwsys::Encoding::CommandLineArguments(args);
+
+ char const* const* u8_argv = args.argv();
+ for(int i=0; i<args.argc(); i++)
+ {
+ char const* u8_arg = u8_argv[i];
+ if(strcmp(argv[i], u8_arg) != 0)
+ {
+ std::cout << "argv[" << i << "] " << argv[i] << " != "
+ << u8_arg << std::endl;
+ status++;
+ }
+ }
+
+ kwsys::Encoding::CommandLineArguments args3 =
+ kwsys::Encoding::CommandLineArguments::Main(2, argv);
+
+ return status;
+}
+
+//----------------------------------------------------------------------------
+int testEncoding(int, char*[])
+{
+ const char* loc = setlocale(LC_ALL, "");
+ if(loc)
+ {
+ std::cout << "Locale: " << loc << std::endl;
+ }
+ else
+ {
+ std::cout << "Locale: None" << std::endl;
+ }
+
+ int ret = 0;
+
+ ret |= testHelloWorldEncoding();
+ ret |= testRobustEncoding();
+ ret |= testCommandLineArguments();
+
+ return ret;
+}
diff --git a/Source/kwsys/testFStream.cxx b/Source/kwsys/testFStream.cxx
new file mode 100644
index 0000000000..9abfd4caa7
--- /dev/null
+++ b/Source/kwsys/testFStream.cxx
@@ -0,0 +1,190 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+
+#if defined(_MSC_VER)
+# pragma warning (disable:4786)
+#endif
+
+#include KWSYS_HEADER(FStream.hxx)
+#include KWSYS_HEADER(ios/iostream)
+#include <string.h>
+#ifdef __BORLANDC__
+# include <mem.h> /* memcmp */
+#endif
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "FStream.hxx.in"
+# include "kwsys_ios_iostream.h.in"
+#endif
+
+
+//----------------------------------------------------------------------------
+static int testNoFile()
+{
+ kwsys::ifstream in_file("NoSuchFile.txt");
+ if(in_file)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+static kwsys::FStream::BOM expected_bom[5] =
+{
+ kwsys::FStream::BOM_UTF8,
+ kwsys::FStream::BOM_UTF16LE,
+ kwsys::FStream::BOM_UTF16BE,
+ kwsys::FStream::BOM_UTF32LE,
+ kwsys::FStream::BOM_UTF32BE
+};
+
+static unsigned char expected_bom_data[5][5] =
+{
+ {3, 0xEF, 0xBB, 0xBF},
+ {2, 0xFF, 0xFE},
+ {2, 0xFE, 0xFF},
+ {4, 0xFF, 0xFE, 0x00, 0x00},
+ {4, 0x00, 0x00, 0xFE, 0xFF},
+};
+
+static unsigned char file_data[5][45] =
+{
+ {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},
+ {22, 0x00, 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x20,
+ 0x00, 0x57, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6C, 0x00, 0x64},
+ {44, 0x48, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00,
+ 0x6C, 0x00, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
+ 0x57, 0x00, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00,
+ 0x6C, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00},
+ {44, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x6C,
+ 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x20,
+ 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x72,
+ 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x64},
+};
+
+//----------------------------------------------------------------------------
+static int testBOM()
+{
+ // test various encodings in binary mode
+ for(int i=0; i<5; i++)
+ {
+ {
+ kwsys::ofstream out("bom.txt", kwsys::ofstream::binary);
+ out.write(reinterpret_cast<const char*>(expected_bom_data[i]+1),
+ *expected_bom_data[i]);
+ out.write(reinterpret_cast<const char*>(file_data[i]+1),
+ file_data[i][0]);
+ }
+
+ kwsys::ifstream in("bom.txt", kwsys::ofstream::binary);
+ kwsys::FStream::BOM bom = kwsys::FStream::ReadBOM(in);
+ if(bom != expected_bom[i])
+ {
+ kwsys_ios::cout << "Unexpected BOM " << i << std::endl;
+ return 1;
+ }
+ char data[45];
+ in.read(data, file_data[i][0]);
+ if(!in.good())
+ {
+ kwsys_ios::cout << "Unable to read data " << i << std::endl;
+ return 1;
+ }
+
+ if(memcmp(data, file_data[i]+1, file_data[i][0]) != 0)
+ {
+ kwsys_ios::cout << "Incorrect read data " << i << std::endl;
+ return 1;
+ }
+
+ }
+
+ // 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)
+ {
+ kwsys_ios::cout << "Unexpected BOM for none case" << std::endl;
+ return 1;
+ }
+ char data[45];
+ in.read(data, file_data[0][0]);
+ if(!in.good())
+ {
+ kwsys_ios::cout << "Unable to read data for none case" << std::endl;
+ return 1;
+ }
+
+ if(memcmp(data, file_data[0]+1, file_data[0][0]) != 0)
+ {
+ kwsys_ios::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)
+ {
+ kwsys_ios::cout << "Unexpected BOM for utf-8 case" << std::endl;
+ return 1;
+ }
+ char data[45];
+ in.read(data, file_data[0][0]);
+ if(!in.good())
+ {
+ kwsys_ios::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)
+ {
+ kwsys_ios::cout << "Incorrect read data for utf-8 case" << std::endl;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+
+//----------------------------------------------------------------------------
+int testFStream(int, char*[])
+{
+ int ret = 0;
+
+ ret |= testNoFile();
+ ret |= testBOM();
+
+ return ret;
+}
diff --git a/Source/kwsys/testFail.c b/Source/kwsys/testFail.c
new file mode 100644
index 0000000000..7e062c1751
--- /dev/null
+++ b/Source/kwsys/testFail.c
@@ -0,0 +1,35 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int testFail(int argc, char* argv[])
+{
+ char* env = getenv("DASHBOARD_TEST_FROM_CTEST");
+ int oldCtest = 0;
+ if(env)
+ {
+ if(strcmp(env, "1") == 0)
+ {
+ oldCtest = 1;
+ }
+ printf("DASHBOARD_TEST_FROM_CTEST = %s\n", env);
+ }
+ printf("%s: This test intentionally fails\n", argv[0]);
+ if(oldCtest)
+ {
+ printf("The version of ctest is not able to handle intentionally failing tests, so pass.\n");
+ return 0;
+ }
+ return argc;
+}
diff --git a/Source/kwsys/testHashSTL.cxx b/Source/kwsys/testHashSTL.cxx
new file mode 100644
index 0000000000..b861a5b32f
--- /dev/null
+++ b/Source/kwsys/testHashSTL.cxx
@@ -0,0 +1,75 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(hash_map.hxx)
+#include KWSYS_HEADER(hash_set.hxx)
+#include KWSYS_HEADER(ios/iostream)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "hash_map.hxx.in"
+# include "hash_set.hxx.in"
+# include "hashtable.hxx.in"
+# include "kwsys_ios_iostream.h.in"
+#endif
+
+#if defined(_MSC_VER)
+# pragma warning (disable:4786)
+#endif
+
+#if defined(__sgi) && !defined(__GNUC__)
+# pragma set woff 1468 /* inline function cannot be explicitly instantiated */
+#endif
+
+template class kwsys::hash_map<const char*, int>;
+template class kwsys::hash_set<int>;
+
+bool test_hash_map()
+{
+ typedef kwsys::hash_map<const char*, int> mtype;
+ mtype m;
+ const char* keys[] = {"hello", "world"};
+ m[keys[0]] = 1;
+ m.insert(mtype::value_type(keys[1], 2));
+ int sum = 0;
+ for(mtype::iterator mi = m.begin(); mi != m.end(); ++mi)
+ {
+ kwsys_ios::cout << "Found entry [" << mi->first << "," << mi->second << "]"
+ << kwsys_ios::endl;
+ sum += mi->second;
+ }
+ return sum == 3;
+}
+
+bool test_hash_set()
+{
+ typedef kwsys::hash_set<int> stype;
+ stype s;
+ s.insert(1);
+ s.insert(2);
+ int sum = 0;
+ for(stype::iterator si = s.begin(); si != s.end(); ++si)
+ {
+ kwsys_ios::cout << "Found entry [" << *si << "]" << kwsys_ios::endl;
+ sum += *si;
+ }
+ return sum == 3;
+}
+
+int testHashSTL(int, char*[])
+{
+ bool result = true;
+ result = test_hash_map() && result;
+ result = test_hash_set() && result;
+ return result? 0:1;
+}
diff --git a/Source/kwsys/testIOS.cxx b/Source/kwsys/testIOS.cxx
new file mode 100644
index 0000000000..f0c7f1a7bc
--- /dev/null
+++ b/Source/kwsys/testIOS.cxx
@@ -0,0 +1,167 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(stl/vector)
+#include KWSYS_HEADER(ios/sstream)
+#include KWSYS_HEADER(ios/fstream)
+#include KWSYS_HEADER(ios/iostream)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "kwsys_stl_string.hxx.in"
+# include "kwsys_stl_vector.h.in"
+# include "kwsys_ios_sstream.h.in"
+# include "kwsys_ios_fstream.h.in"
+# include "kwsys_ios_iostream.h.in"
+#endif
+
+#include <string.h> /* strlen */
+
+int testIOS(int, char*[])
+{
+ kwsys_ios::ostringstream ostr;
+ const char hello[] = "hello";
+ ostr << hello;
+ if(ostr.str() != hello)
+ {
+ kwsys_ios::cerr << "failed to write hello to ostr" << kwsys_ios::endl;
+ return 1;
+ }
+ const char world[] = "world";
+ kwsys_ios::ostringstream ostr2;
+ ostr2.write( hello, strlen(hello) ); /* I could do sizeof */
+ ostr2.put( '\0' );
+ ostr2.write( world, strlen(world) );
+ if(ostr2.str().size() != strlen(hello) + 1 + strlen(world) )
+ {
+ kwsys_ios::cerr << "failed to write hello to ostr2" << kwsys_ios::endl;
+ return 1;
+ }
+ static const unsigned char array[] = { 0xff,0x4f,0xff,0x51,0x00,0x29,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x01,0x01,0xff,0x52,0x00,0x0c,0x00,0x00,0x00,0x01,0x00,0x05,0x04,0x04,0x00,0x01,0xff,0x5c,0x00,0x13,0x40,0x40,0x48,0x48,0x50,0x48,0x48,0x50,0x48,0x48,0x50,0x48,0x48,0x50,0x48,0x48,0x50,0xff,0x64,0x00,0x2c,0x00,0x00,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x62,0x79,0x20,0x49,0x54,0x4b,0x2f,0x47,0x44,0x43,0x4d,0x2f,0x4f,0x70,0x65,0x6e,0x4a,0x50,0x45,0x47,0x20,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x31,0x2e,0x30,0xff,0x90,0x00,0x0a,0x00,0x00,0x00,0x00,0x06,0x2c,0x00,0x01,0xff,0x93,0xcf,0xb0,0x18,0x08,0x7f,0xc6,0x99,0xbf,0xff,0xc0,0xf8,0xc1,0xc1,0xf3,0x05,0x81,0xf2,0x83,0x0a,0xa5,0xff,0x10,0x90,0xbf,0x2f,0xff,0x04,0xa8,0x7f,0xc0,0xf8,0xc4,0xc1,0xf3,0x09,0x81,0xf3,0x0c,0x19,0x34 };
+ const size_t narray = sizeof(array); // 180
+ kwsys_ios::stringstream strstr;
+ strstr.write( (char*)array, narray );
+ //strstr.seekp( narray / 2 ); // set position of put pointer in mid string
+ if(strstr.str().size() != narray )
+ {
+ kwsys_ios::cerr << "failed to write array to strstr" << kwsys_ios::endl;
+ return 1;
+ }
+
+ kwsys_ios::istringstream istr(" 10 20 str ");
+ kwsys_stl::string s;
+ int x;
+ if(istr >> x)
+ {
+ if(x != 10)
+ {
+ kwsys_ios::cerr << "x != 10" << kwsys_ios::endl;
+ return 1;
+ }
+ }
+ else
+ {
+ kwsys_ios::cerr << "Failed to read 10 from istr" << kwsys_ios::endl;
+ return 1;
+ }
+ if(istr >> x)
+ {
+ if(x != 20)
+ {
+ kwsys_ios::cerr << "x != 20" << kwsys_ios::endl;
+ return 1;
+ }
+ }
+ else
+ {
+ kwsys_ios::cerr << "Failed to read 20 from istr" << kwsys_ios::endl;
+ return 1;
+ }
+ if(istr >> s)
+ {
+ if(s != "str")
+ {
+ kwsys_ios::cerr << "s != \"str\"" << kwsys_ios::endl;
+ return 1;
+ }
+ }
+ else
+ {
+ kwsys_ios::cerr << "Failed to read str from istr" << kwsys_ios::endl;
+ return 1;
+ }
+ if(istr >> s)
+ {
+ kwsys_ios::cerr << "Able to read past end of stream" << kwsys_ios::endl;
+ return 1;
+ }
+ else
+ {
+ // Clear the failure.
+ istr.clear(istr.rdstate() & ~kwsys_ios::ios::eofbit);
+ istr.clear(istr.rdstate() & ~kwsys_ios::ios::failbit);
+ }
+ istr.str("30");
+ if(istr >> x)
+ {
+ if(x != 30)
+ {
+ kwsys_ios::cerr << "x != 30" << kwsys_ios::endl;
+ return 1;
+ }
+ }
+ else
+ {
+ kwsys_ios::cerr << "Failed to read 30 from istr" << kwsys_ios::endl;
+ return 1;
+ }
+
+ kwsys_ios::stringstream sstr;
+ sstr << "40 str2";
+ if(sstr >> x)
+ {
+ if(x != 40)
+ {
+ kwsys_ios::cerr << "x != 40" << kwsys_ios::endl;
+ return 1;
+ }
+ }
+ else
+ {
+ kwsys_ios::cerr << "Failed to read 40 from sstr" << kwsys_ios::endl;
+ return 1;
+ }
+ if(sstr >> s)
+ {
+ if(s != "str2")
+ {
+ kwsys_ios::cerr << "s != \"str2\"" << kwsys_ios::endl;
+ return 1;
+ }
+ }
+ else
+ {
+ kwsys_ios::cerr << "Failed to read str2 from sstr" << kwsys_ios::endl;
+ return 1;
+ }
+
+ // Just try to compile this.
+ if(x == 12345)
+ {
+ kwsys_ios::ifstream fin("/does_not_exist",
+ kwsys_ios::ios::in | kwsys_ios_binary);
+ }
+
+ kwsys_ios::cout << "IOS tests passed" << kwsys_ios::endl;
+ return 0;
+}
diff --git a/Source/kwsys/testProcess.c b/Source/kwsys/testProcess.c
new file mode 100644
index 0000000000..47c3fb0d05
--- /dev/null
+++ b/Source/kwsys/testProcess.c
@@ -0,0 +1,548 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Process.h)
+#include KWSYS_HEADER(Encoding.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "Process.h.in"
+# include "Encoding.h.in"
+#endif
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(_WIN32)
+# include <windows.h>
+#else
+# include <unistd.h>
+#endif
+
+#if defined(__BORLANDC__)
+# pragma warn -8060 /* possibly incorrect assignment */
+#endif
+
+#if defined(__BEOS__) && !defined(__ZETA__)
+/* BeOS 5 doesn't have usleep(), but it has snooze(), which is identical. */
+# include <be/kernel/OS.h>
+static inline void testProcess_usleep(unsigned int msec)
+{
+ snooze(msec);
+}
+#else
+# define testProcess_usleep usleep
+#endif
+
+int runChild(const char* cmd[], int state, int exception, int value,
+ int share, int output, int delay, double timeout, int poll,
+ int repeat, int disown);
+
+static int test1(int argc, const char* argv[])
+{
+ (void)argc; (void)argv;
+ fprintf(stdout, "Output on stdout from test returning 0.\n");
+ fprintf(stderr, "Output on stderr from test returning 0.\n");
+ return 0;
+}
+
+static int test2(int argc, const char* argv[])
+{
+ (void)argc; (void)argv;
+ fprintf(stdout, "Output on stdout from test returning 123.\n");
+ fprintf(stderr, "Output on stderr from test returning 123.\n");
+ return 123;
+}
+
+static int test3(int argc, const char* argv[])
+{
+ (void)argc; (void)argv;
+ fprintf(stdout, "Output before sleep on stdout from timeout test.\n");
+ fprintf(stderr, "Output before sleep on stderr from timeout test.\n");
+ fflush(stdout);
+ fflush(stderr);
+#if defined(_WIN32)
+ Sleep(15000);
+#else
+ sleep(15);
+#endif
+ fprintf(stdout, "Output after sleep on stdout from timeout test.\n");
+ fprintf(stderr, "Output after sleep on stderr from timeout test.\n");
+ return 0;
+}
+
+static int test4(int argc, const char* argv[])
+{
+ /* Prepare a pointer to an invalid address. Don't use null, because
+ dereferencing null is undefined behaviour and compilers are free to
+ do whatever they want. ex: Clang will warn at compile time, or even
+ optimize away the write. We hope to 'outsmart' them by using
+ 'volatile' and a slightly larger address, based on a runtime value. */
+ volatile int* invalidAddress = 0;
+ invalidAddress += argc?1:2;
+
+#if defined(_WIN32)
+ /* Avoid error diagnostic popups since we are crashing on purpose. */
+ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
+#elif defined(__BEOS__) || defined(__HAIKU__)
+ /* Avoid error diagnostic popups since we are crashing on purpose. */
+ disable_debugger(1);
+#endif
+ (void)argc; (void)argv;
+ fprintf(stdout, "Output before crash on stdout from crash test.\n");
+ fprintf(stderr, "Output before crash on stderr from crash test.\n");
+ fflush(stdout);
+ fflush(stderr);
+ assert(invalidAddress); /* Quiet Clang scan-build. */
+ /* Provoke deliberate crash by writing to the invalid address. */
+ *invalidAddress = 0;
+ fprintf(stdout, "Output after crash on stdout from crash test.\n");
+ fprintf(stderr, "Output after crash on stderr from crash test.\n");
+ return 0;
+}
+
+static int test5(int argc, const char* argv[])
+{
+ int r;
+ const char* cmd[4];
+ (void)argc;
+ cmd[0] = argv[0];
+ cmd[1] = "run";
+ cmd[2] = "4";
+ cmd[3] = 0;
+ fprintf(stdout, "Output on stdout before recursive test.\n");
+ fprintf(stderr, "Output on stderr before recursive test.\n");
+ fflush(stdout);
+ fflush(stderr);
+ r = runChild(cmd, kwsysProcess_State_Exception,
+ kwsysProcess_Exception_Fault, 1, 1, 1, 0, 15, 0, 1, 0);
+ fprintf(stdout, "Output on stdout after recursive test.\n");
+ fprintf(stderr, "Output on stderr after recursive test.\n");
+ fflush(stdout);
+ fflush(stderr);
+ return r;
+}
+
+#define TEST6_SIZE (4096*2)
+static void test6(int argc, const char* argv[])
+{
+ int i;
+ char runaway[TEST6_SIZE+1];
+ (void)argc; (void)argv;
+ for(i=0;i < TEST6_SIZE;++i)
+ {
+ runaway[i] = '.';
+ }
+ runaway[TEST6_SIZE] = '\n';
+
+ /* Generate huge amounts of output to test killing. */
+ for(;;)
+ {
+ fwrite(runaway, 1, TEST6_SIZE+1, stdout);
+ fflush(stdout);
+ }
+}
+
+/* Define MINPOLL to be one more than the number of times output is
+ written. Define MAXPOLL to be the largest number of times a loop
+ delaying 1/10th of a second should ever have to poll. */
+#define MINPOLL 5
+#define MAXPOLL 20
+static int test7(int argc, const char* argv[])
+{
+ (void)argc; (void)argv;
+ fprintf(stdout, "Output on stdout before sleep.\n");
+ fprintf(stderr, "Output on stderr before sleep.\n");
+ fflush(stdout);
+ fflush(stderr);
+ /* Sleep for 1 second. */
+#if defined(_WIN32)
+ Sleep(1000);
+#else
+ sleep(1);
+#endif
+ fprintf(stdout, "Output on stdout after sleep.\n");
+ fprintf(stderr, "Output on stderr after sleep.\n");
+ fflush(stdout);
+ fflush(stderr);
+ return 0;
+}
+
+static int test8(int argc, const char* argv[])
+{
+ /* Create a disowned grandchild to test handling of processes
+ that exit before their children. */
+ int r;
+ const char* cmd[4];
+ (void)argc;
+ cmd[0] = argv[0];
+ cmd[1] = "run";
+ cmd[2] = "108";
+ cmd[3] = 0;
+ fprintf(stdout, "Output on stdout before grandchild test.\n");
+ fprintf(stderr, "Output on stderr before grandchild test.\n");
+ fflush(stdout);
+ fflush(stderr);
+ r = runChild(cmd, kwsysProcess_State_Disowned, kwsysProcess_Exception_None,
+ 1, 1, 1, 0, 10, 0, 1, 1);
+ fprintf(stdout, "Output on stdout after grandchild test.\n");
+ fprintf(stderr, "Output on stderr after grandchild test.\n");
+ fflush(stdout);
+ fflush(stderr);
+ return r;
+}
+
+static int test8_grandchild(int argc, const char* argv[])
+{
+ (void)argc; (void)argv;
+ fprintf(stdout, "Output on stdout from grandchild before sleep.\n");
+ fprintf(stderr, "Output on stderr from grandchild before sleep.\n");
+ fflush(stdout);
+ fflush(stderr);
+ /* TODO: Instead of closing pipes here leave them open to make sure
+ the grandparent can stop listening when the parent exits. This
+ part of the test cannot be enabled until the feature is
+ implemented. */
+ fclose(stdout);
+ fclose(stderr);
+#if defined(_WIN32)
+ Sleep(15000);
+#else
+ sleep(15);
+#endif
+ return 0;
+}
+
+static int runChild2(kwsysProcess* kp,
+ const char* cmd[], int state, int exception, int value,
+ int share, int output, int delay, double timeout,
+ int poll, int disown)
+{
+ int result = 0;
+ char* data = 0;
+ int length = 0;
+ double userTimeout = 0;
+ double* pUserTimeout = 0;
+ kwsysProcess_SetCommand(kp, cmd);
+ if(timeout >= 0)
+ {
+ kwsysProcess_SetTimeout(kp, timeout);
+ }
+ if(share)
+ {
+ kwsysProcess_SetPipeShared(kp, kwsysProcess_Pipe_STDOUT, 1);
+ kwsysProcess_SetPipeShared(kp, kwsysProcess_Pipe_STDERR, 1);
+ }
+ if(disown)
+ {
+ kwsysProcess_SetOption(kp, kwsysProcess_Option_Detach, 1);
+ }
+ kwsysProcess_Execute(kp);
+
+ if(poll)
+ {
+ pUserTimeout = &userTimeout;
+ }
+
+ if(!share && !disown)
+ {
+ int p;
+ while((p = kwsysProcess_WaitForData(kp, &data, &length, pUserTimeout)))
+ {
+ if(output)
+ {
+ if(poll && p == kwsysProcess_Pipe_Timeout)
+ {
+ fprintf(stdout, "WaitForData timeout reached.\n");
+ fflush(stdout);
+
+ /* Count the number of times we polled without getting data.
+ If it is excessive then kill the child and fail. */
+ if(++poll >= MAXPOLL)
+ {
+ fprintf(stdout, "Poll count reached limit %d.\n",
+ MAXPOLL);
+ kwsysProcess_Kill(kp);
+ }
+ }
+ else
+ {
+ fwrite(data, 1, (size_t) length, stdout);
+ fflush(stdout);
+ }
+ }
+ if(poll)
+ {
+ /* Delay to avoid busy loop during polling. */
+#if defined(_WIN32)
+ Sleep(100);
+#else
+ testProcess_usleep(100000);
+#endif
+ }
+ if(delay)
+ {
+ /* Purposely sleeping only on Win32 to let pipe fill up. */
+#if defined(_WIN32)
+ Sleep(100);
+#endif
+ }
+ }
+ }
+
+ if(disown)
+ {
+ kwsysProcess_Disown(kp);
+ }
+ else
+ {
+ kwsysProcess_WaitForExit(kp, 0);
+ }
+
+ switch (kwsysProcess_GetState(kp))
+ {
+ case kwsysProcess_State_Starting:
+ printf("No process has been executed.\n"); break;
+ case kwsysProcess_State_Executing:
+ printf("The process is still executing.\n"); break;
+ case kwsysProcess_State_Expired:
+ printf("Child was killed when timeout expired.\n"); break;
+ case kwsysProcess_State_Exited:
+ printf("Child exited with value = %d\n",
+ kwsysProcess_GetExitValue(kp));
+ result = ((exception != kwsysProcess_GetExitException(kp)) ||
+ (value != kwsysProcess_GetExitValue(kp))); break;
+ case kwsysProcess_State_Killed:
+ printf("Child was killed by parent.\n"); break;
+ case kwsysProcess_State_Exception:
+ printf("Child terminated abnormally: %s\n",
+ kwsysProcess_GetExceptionString(kp));
+ result = ((exception != kwsysProcess_GetExitException(kp)) ||
+ (value != kwsysProcess_GetExitValue(kp))); break;
+ case kwsysProcess_State_Disowned:
+ printf("Child was disowned.\n"); break;
+ case kwsysProcess_State_Error:
+ printf("Error in administrating child process: [%s]\n",
+ kwsysProcess_GetErrorString(kp)); break;
+ };
+
+ if(result)
+ {
+ if(exception != kwsysProcess_GetExitException(kp))
+ {
+ fprintf(stderr, "Mismatch in exit exception. "
+ "Should have been %d, was %d.\n",
+ exception, kwsysProcess_GetExitException(kp));
+ }
+ if(value != kwsysProcess_GetExitValue(kp))
+ {
+ fprintf(stderr, "Mismatch in exit value. "
+ "Should have been %d, was %d.\n",
+ value, kwsysProcess_GetExitValue(kp));
+ }
+ }
+
+ if(kwsysProcess_GetState(kp) != state)
+ {
+ fprintf(stderr, "Mismatch in state. "
+ "Should have been %d, was %d.\n",
+ state, kwsysProcess_GetState(kp));
+ result = 1;
+ }
+
+ /* We should have polled more times than there were data if polling
+ was enabled. */
+ if(poll && poll < MINPOLL)
+ {
+ fprintf(stderr, "Poll count is %d, which is less than %d.\n",
+ poll, MINPOLL);
+ result = 1;
+ }
+
+ return result;
+}
+
+int runChild(const char* cmd[], int state, int exception, int value,
+ int share, int output, int delay, double timeout,
+ int poll, int repeat, int disown)
+{
+ int result = 1;
+ kwsysProcess* kp = kwsysProcess_New();
+ if(!kp)
+ {
+ fprintf(stderr, "kwsysProcess_New returned NULL!\n");
+ return 1;
+ }
+ while(repeat-- > 0)
+ {
+ result = runChild2(kp, cmd, state, exception, value, share,
+ output, delay, timeout, poll, disown);
+ }
+ kwsysProcess_Delete(kp);
+ return result;
+}
+
+int main(int argc, const char* argv[])
+{
+ int n = 0;
+
+#ifdef _WIN32
+ int i;
+ char new_args[10][_MAX_PATH];
+ LPWSTR* w_av = CommandLineToArgvW(GetCommandLineW(), &argc);
+ for(i=0; i<argc; i++)
+ {
+ kwsysEncoding_wcstombs(new_args[i], w_av[i], _MAX_PATH);
+ argv[i] = new_args[i];
+ }
+ LocalFree(w_av);
+#endif
+
+#if 0
+ {
+ HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
+ DuplicateHandle(GetCurrentProcess(), out,
+ GetCurrentProcess(), &out, 0, FALSE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ SetStdHandle(STD_OUTPUT_HANDLE, out);
+ }
+ {
+ HANDLE out = GetStdHandle(STD_ERROR_HANDLE);
+ DuplicateHandle(GetCurrentProcess(), out,
+ GetCurrentProcess(), &out, 0, FALSE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ SetStdHandle(STD_ERROR_HANDLE, out);
+ }
+#endif
+ if(argc == 2)
+ {
+ n = atoi(argv[1]);
+ }
+ else if(argc == 3 && strcmp(argv[1], "run") == 0)
+ {
+ n = atoi(argv[2]);
+ }
+ /* Check arguments. */
+ if(((n >= 1 && n <= 8) || n == 108) && argc == 3)
+ {
+ /* This is the child process for a requested test number. */
+ switch (n)
+ {
+ case 1: return test1(argc, argv);
+ case 2: return test2(argc, argv);
+ case 3: return test3(argc, argv);
+ case 4: return test4(argc, argv);
+ case 5: return test5(argc, argv);
+ case 6: test6(argc, argv); return 0;
+ case 7: return test7(argc, argv);
+ case 8: return test8(argc, argv);
+ case 108: return test8_grandchild(argc, argv);
+ }
+ fprintf(stderr, "Invalid test number %d.\n", n);
+ return 1;
+ }
+ else if(n >= 1 && n <= 8)
+ {
+ /* This is the parent process for a requested test number. */
+ int states[8] =
+ {
+ kwsysProcess_State_Exited,
+ kwsysProcess_State_Exited,
+ kwsysProcess_State_Expired,
+ kwsysProcess_State_Exception,
+ kwsysProcess_State_Exited,
+ kwsysProcess_State_Expired,
+ kwsysProcess_State_Exited,
+ kwsysProcess_State_Exited
+ };
+ int exceptions[8] =
+ {
+ kwsysProcess_Exception_None,
+ kwsysProcess_Exception_None,
+ kwsysProcess_Exception_None,
+ kwsysProcess_Exception_Fault,
+ kwsysProcess_Exception_None,
+ kwsysProcess_Exception_None,
+ kwsysProcess_Exception_None,
+ kwsysProcess_Exception_None
+ };
+ int values[8] = {0, 123, 1, 1, 0, 0, 0, 0};
+ int outputs[8] = {1, 1, 1, 1, 1, 0, 1, 1};
+ int delays[8] = {0, 0, 0, 0, 0, 1, 0, 0};
+ double timeouts[8] = {10, 10, 10, 30, 30, 10, -1, 10};
+ int polls[8] = {0, 0, 0, 0, 0, 0, 1, 0};
+ int repeat[8] = {2, 1, 1, 1, 1, 1, 1, 1};
+ int r;
+ const char* cmd[4];
+#ifdef _WIN32
+ char* argv0 = 0;
+ if(n == 0 && (argv0 = strdup(argv[0])))
+ {
+ /* Try converting to forward slashes to see if it works. */
+ char* c;
+ for(c=argv0; *c; ++c)
+ {
+ if(*c == '\\')
+ {
+ *c = '/';
+ }
+ }
+ cmd[0] = argv0;
+ }
+ else
+ {
+ cmd[0] = argv[0];
+ }
+#else
+ cmd[0] = argv[0];
+#endif
+ cmd[1] = "run";
+ cmd[2] = argv[1];
+ cmd[3] = 0;
+ fprintf(stdout, "Output on stdout before test %d.\n", n);
+ fprintf(stderr, "Output on stderr before test %d.\n", n);
+ fflush(stdout);
+ fflush(stderr);
+ r = runChild(cmd, states[n-1], exceptions[n-1], values[n-1], 0,
+ outputs[n-1], delays[n-1], timeouts[n-1],
+ polls[n-1], repeat[n-1], 0);
+ fprintf(stdout, "Output on stdout after test %d.\n", n);
+ fprintf(stderr, "Output on stderr after test %d.\n", n);
+ fflush(stdout);
+ fflush(stderr);
+#if defined(_WIN32)
+ if(argv0) { free(argv0); }
+#endif
+ return r;
+ }
+ else if(argc > 2 && strcmp(argv[1], "0") == 0)
+ {
+ /* This is the special debugging test to run a given command
+ line. */
+ const char** cmd = argv+2;
+ int state = kwsysProcess_State_Exited;
+ int exception = kwsysProcess_Exception_None;
+ int value = 0;
+ double timeout = 0;
+ int r = runChild(cmd, state, exception, value, 0, 1, 0, timeout, 0, 1, 0);
+ return r;
+ }
+ else
+ {
+ /* Improper usage. */
+ fprintf(stdout, "Usage: %s <test number>\n", argv[0]);
+ return 1;
+ }
+}
diff --git a/Source/kwsys/testSharedForward.c.in b/Source/kwsys/testSharedForward.c.in
new file mode 100644
index 0000000000..ee753efa33
--- /dev/null
+++ b/Source/kwsys/testSharedForward.c.in
@@ -0,0 +1,36 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#if defined(CMAKE_INTDIR)
+# define CONFIG_DIR_PRE CMAKE_INTDIR "/"
+# define CONFIG_DIR_POST "/" CMAKE_INTDIR
+#else
+# define CONFIG_DIR_PRE ""
+# define CONFIG_DIR_POST ""
+#endif
+#define @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD "@EXEC_DIR@"
+#define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD "." CONFIG_DIR_POST
+#define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL 0
+#define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD \
+ CONFIG_DIR_PRE "@KWSYS_NAMESPACE@TestProcess"
+#define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL \
+ "@KWSYS_NAMESPACE@TestProcess"
+#define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND "--command"
+#define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT "--print"
+#define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD "--ldd"
+#if defined(CMAKE_INTDIR)
+# define @KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME CMAKE_INTDIR
+#endif
+#include <@KWSYS_NAMESPACE@/SharedForward.h>
+int main(int argc, char** argv)
+{
+ return @KWSYS_NAMESPACE@_shared_forward_to_real(argc, argv);
+}
diff --git a/Source/kwsys/testSystemInformation.cxx b/Source/kwsys/testSystemInformation.cxx
new file mode 100644
index 0000000000..53d51ac405
--- /dev/null
+++ b/Source/kwsys/testSystemInformation.cxx
@@ -0,0 +1,118 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(SystemInformation.hxx)
+#include KWSYS_HEADER(ios/iostream)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "SystemInformation.hxx.in"
+# include "kwsys_ios_iostream.h.in"
+#endif
+
+#if defined(KWSYS_USE_LONG_LONG)
+# if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
+# define iostreamLongLong(x) (x)
+# else
+# define iostreamLongLong(x) ((long)x)
+# endif
+#elif defined(KWSYS_USE___INT64)
+# if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
+# define iostreamLongLong(x) (x)
+# else
+# define iostreamLongLong(x) ((long)x)
+# endif
+#else
+# error "No Long Long"
+#endif
+
+#define printMethod(info, m) kwsys_ios::cout << #m << ": " \
+<< info.m() << "\n"
+
+#define printMethod2(info, m, unit) kwsys_ios::cout << #m << ": " \
+<< info.m() << " " << unit << "\n"
+
+#define printMethod3(info, m, unit) kwsys_ios::cout << #m << ": " \
+<< iostreamLongLong(info.m) << " " << unit << "\n"
+
+int testSystemInformation(int, char*[])
+{
+ kwsys_ios::cout << "CTEST_FULL_OUTPUT\n"; // avoid truncation
+
+ kwsys::SystemInformation info;
+ info.RunCPUCheck();
+ info.RunOSCheck();
+ info.RunMemoryCheck();
+ printMethod(info, GetOSName);
+ printMethod(info, GetOSIsLinux);
+ printMethod(info, GetOSIsApple);
+ printMethod(info, GetOSIsWindows);
+ printMethod(info, GetHostname);
+ printMethod(info, GetFullyQualifiedDomainName);
+ printMethod(info, GetOSRelease);
+ printMethod(info, GetOSVersion);
+ printMethod(info, GetOSPlatform);
+ printMethod(info, GetVendorString);
+ printMethod(info, GetVendorID);
+ printMethod(info, GetTypeID);
+ printMethod(info, GetFamilyID);
+ printMethod(info, GetModelID);
+ printMethod(info, GetExtendedProcessorName);
+ printMethod(info, GetSteppingCode);
+ printMethod(info, GetProcessorSerialNumber);
+ printMethod2(info, GetProcessorCacheSize, "KB");
+ printMethod(info, GetLogicalProcessorsPerPhysical);
+ printMethod2(info, GetProcessorClockFrequency, "MHz");
+ printMethod(info, Is64Bits);
+ printMethod(info, GetNumberOfLogicalCPU);
+ printMethod(info, GetNumberOfPhysicalCPU);
+ printMethod(info, DoesCPUSupportCPUID);
+ printMethod(info, GetProcessorAPICID);
+ printMethod2(info, GetTotalVirtualMemory, "MB");
+ printMethod2(info, GetAvailableVirtualMemory, "MB");
+ printMethod2(info, GetTotalPhysicalMemory, "MB");
+ printMethod2(info, GetAvailablePhysicalMemory, "MB");
+ printMethod3(info, GetHostMemoryTotal(), "KiB");
+ printMethod3(info, GetHostMemoryAvailable("KWSHL"), "KiB");
+ printMethod3(info, GetProcMemoryAvailable("KWSHL","KWSPL"), "KiB");
+ printMethod3(info, GetHostMemoryUsed(), "KiB");
+ printMethod3(info, GetProcMemoryUsed(), "KiB");
+
+ for (long int i = 0; i <= 31; i++)
+ {
+ if (info.DoesCPUSupportFeature(static_cast<long int>(1) << i))
+ {
+ kwsys_ios::cout << "CPU feature " << i << "\n";
+ }
+ }
+
+ /* test stack trace
+ */
+ kwsys_ios::cout
+ << "Program Stack:" << kwsys_ios::endl
+ << kwsys::SystemInformation::GetProgramStack(0,0) << kwsys_ios::endl
+ << kwsys_ios::endl;
+
+ /* test segv handler
+ info.SetStackTraceOnError(1);
+ double *d = (double*)100;
+ *d=0;
+ */
+
+ /* test abort handler
+ info.SetStackTraceOnError(1);
+ abort();
+ */
+
+ return 0;
+}
diff --git a/Source/kwsys/testSystemTools.bin b/Source/kwsys/testSystemTools.bin
new file mode 100644
index 0000000000..961a4043b9
--- /dev/null
+++ b/Source/kwsys/testSystemTools.bin
Binary files differ
diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
new file mode 100644
index 0000000000..b41532b114
--- /dev/null
+++ b/Source/kwsys/testSystemTools.cxx
@@ -0,0 +1,650 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+
+#if defined(_MSC_VER)
+# pragma warning (disable:4786)
+#endif
+
+#include KWSYS_HEADER(SystemTools.hxx)
+#include KWSYS_HEADER(ios/iostream)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "SystemTools.hxx.in"
+# include "kwsys_ios_iostream.h.in"
+#endif
+
+// Include with <> instead of "" to avoid getting any in-source copy
+// left on disk.
+#include <testSystemTools.h>
+
+#include <string.h> /* strcmp */
+
+//----------------------------------------------------------------------------
+static const char* toUnixPaths[][2] =
+{
+ { "/usr/local/bin/passwd", "/usr/local/bin/passwd" },
+ { "/usr/lo cal/bin/pa sswd", "/usr/lo cal/bin/pa sswd" },
+ { "/usr/lo\\ cal/bin/pa\\ sswd", "/usr/lo\\ cal/bin/pa\\ sswd" },
+ { "c:/usr/local/bin/passwd", "c:/usr/local/bin/passwd" },
+ { "c:/usr/lo cal/bin/pa sswd", "c:/usr/lo cal/bin/pa sswd" },
+ { "c:/usr/lo\\ cal/bin/pa\\ sswd", "c:/usr/lo\\ cal/bin/pa\\ sswd" },
+ { "\\usr\\local\\bin\\passwd", "/usr/local/bin/passwd" },
+ { "\\usr\\lo cal\\bin\\pa sswd", "/usr/lo cal/bin/pa sswd" },
+ { "\\usr\\lo\\ cal\\bin\\pa\\ sswd", "/usr/lo\\ cal/bin/pa\\ sswd" },
+ { "c:\\usr\\local\\bin\\passwd", "c:/usr/local/bin/passwd" },
+ { "c:\\usr\\lo cal\\bin\\pa sswd", "c:/usr/lo cal/bin/pa sswd" },
+ { "c:\\usr\\lo\\ cal\\bin\\pa\\ sswd", "c:/usr/lo\\ cal/bin/pa\\ sswd" },
+ { "\\\\usr\\local\\bin\\passwd", "//usr/local/bin/passwd" },
+ { "\\\\usr\\lo cal\\bin\\pa sswd", "//usr/lo cal/bin/pa sswd" },
+ { "\\\\usr\\lo\\ cal\\bin\\pa\\ sswd", "//usr/lo\\ cal/bin/pa\\ sswd" },
+ {0, 0}
+};
+
+static bool CheckConvertToUnixSlashes(kwsys_stl::string input,
+ kwsys_stl::string output)
+{
+ kwsys_stl::string result = input;
+ kwsys::SystemTools::ConvertToUnixSlashes(result);
+ if ( result != output )
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToUnixSlashes - input: " << input
+ << " output: " << result << " expected: " << output
+ << kwsys_ios::endl;
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+static const char* checkEscapeChars[][4] =
+{
+ { "1 foo 2 bar 2", "12", "\\", "\\1 foo \\2 bar \\2"},
+ { " {} ", "{}", "#", " #{#} "},
+ {0, 0, 0, 0}
+};
+
+static bool CheckEscapeChars(kwsys_stl::string input,
+ const char *chars_to_escape,
+ char escape_char,
+ kwsys_stl::string output)
+{
+ kwsys_stl::string result = kwsys::SystemTools::EscapeChars(
+ input.c_str(), chars_to_escape, escape_char);
+ if (result != output)
+ {
+ kwsys_ios::cerr
+ << "Problem with CheckEscapeChars - input: " << input
+ << " output: " << result << " expected: " << output
+ << kwsys_ios::endl;
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+static bool CheckFileOperations()
+{
+ bool res = true;
+ const kwsys_stl::string testBinFile(TEST_SYSTEMTOOLS_SOURCE_DIR
+ "/testSystemTools.bin");
+ const kwsys_stl::string testTxtFile(TEST_SYSTEMTOOLS_SOURCE_DIR
+ "/testSystemTools.cxx");
+ const kwsys_stl::string testNewDir(TEST_SYSTEMTOOLS_BINARY_DIR
+ "/testSystemToolsNewDir");
+ const kwsys_stl::string testNewFile(testNewDir + "/testNewFile.txt");
+
+ if (kwsys::SystemTools::DetectFileType(testBinFile.c_str()) !=
+ kwsys::SystemTools::FileTypeBinary)
+ {
+ kwsys_ios::cerr
+ << "Problem with DetectFileType - failed to detect type of: "
+ << testBinFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::DetectFileType(testTxtFile.c_str()) !=
+ kwsys::SystemTools::FileTypeText)
+ {
+ kwsys_ios::cerr
+ << "Problem with DetectFileType - failed to detect type of: "
+ << testTxtFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::FileLength(testBinFile.c_str()) != 766)
+ {
+ kwsys_ios::cerr
+ << "Problem with FileLength - incorrect length for: "
+ << testBinFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::MakeDirectory(testNewDir))
+ {
+ kwsys_ios::cerr
+ << "Problem with MakeDirectory for: "
+ << testNewDir << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::Touch(testNewFile.c_str(), true))
+ {
+ kwsys_ios::cerr
+ << "Problem with Touch for: "
+ << testNewFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::RemoveFile(testNewFile))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveFile: "
+ << testNewFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ kwsys::SystemTools::Touch(testNewFile.c_str(), true);
+ if (!kwsys::SystemTools::RemoveADirectory(testNewDir))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveADirectory for: "
+ << testNewDir << kwsys_ios::endl;
+ res = false;
+ }
+
+#ifdef KWSYS_TEST_SYSTEMTOOLS_LONG_PATHS
+ // Perform the same file and directory creation and deletion tests but
+ // with paths > 256 characters in length.
+
+ const kwsys_stl::string testNewLongDir(
+ TEST_SYSTEMTOOLS_BINARY_DIR "/"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "01234567890123");
+ const kwsys_stl::string testNewLongFile(testNewLongDir + "/"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "0123456789.txt");
+
+ if (!kwsys::SystemTools::MakeDirectory(testNewLongDir))
+ {
+ kwsys_ios::cerr
+ << "Problem with MakeDirectory for: "
+ << testNewLongDir << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::Touch(testNewLongFile.c_str(), true))
+ {
+ kwsys_ios::cerr
+ << "Problem with Touch for: "
+ << testNewLongFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::RemoveFile(testNewLongFile))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveFile: "
+ << testNewLongFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ kwsys::SystemTools::Touch(testNewLongFile.c_str(), true);
+ if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveADirectory for: "
+ << testNewLongDir << kwsys_ios::endl;
+ res = false;
+ }
+#endif
+
+ return res;
+}
+
+//----------------------------------------------------------------------------
+static bool CheckStringOperations()
+{
+ bool res = true;
+
+ kwsys_stl::string test = "mary had a little lamb.";
+ if (kwsys::SystemTools::CapitalizedWords(test) != "Mary Had A Little Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with CapitalizedWords "
+ << '"' << test << '"' << kwsys_ios::endl;
+ res = false;
+ }
+
+ test = "Mary Had A Little Lamb.";
+ if (kwsys::SystemTools::UnCapitalizedWords(test) !=
+ "mary had a little lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with UnCapitalizedWords "
+ << '"' << test << '"' << kwsys_ios::endl;
+ res = false;
+ }
+
+ test = "MaryHadTheLittleLamb.";
+ if (kwsys::SystemTools::AddSpaceBetweenCapitalizedWords(test) !=
+ "Mary Had The Little Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with AddSpaceBetweenCapitalizedWords "
+ << '"' << test << '"' << kwsys_ios::endl;
+ res = false;
+ }
+
+ char * cres =
+ kwsys::SystemTools::AppendStrings("Mary Had A"," Little Lamb.");
+ if (strcmp(cres,"Mary Had A Little Lamb."))
+ {
+ kwsys_ios::cerr
+ << "Problem with AppendStrings "
+ << "\"Mary Had A\" \" Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ cres =
+ kwsys::SystemTools::AppendStrings("Mary Had"," A ","Little Lamb.");
+ if (strcmp(cres,"Mary Had A Little Lamb."))
+ {
+ kwsys_ios::cerr
+ << "Problem with AppendStrings "
+ << "\"Mary Had\" \" A \" \"Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ if (kwsys::SystemTools::CountChar("Mary Had A Little Lamb.",'a') != 3)
+ {
+ kwsys_ios::cerr
+ << "Problem with CountChar "
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+
+ cres =
+ kwsys::SystemTools::RemoveChars("Mary Had A Little Lamb.","aeiou");
+ if (strcmp(cres,"Mry Hd A Lttl Lmb."))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveChars "
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ cres =
+ kwsys::SystemTools::RemoveCharsButUpperHex("Mary Had A Little Lamb.");
+ if (strcmp(cres,"A"))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveCharsButUpperHex "
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ char *cres2 = new char [strlen("Mary Had A Little Lamb.")+1];
+ strcpy(cres2,"Mary Had A Little Lamb.");
+ kwsys::SystemTools::ReplaceChars(cres2,"aeiou",'X');
+ if (strcmp(cres2,"MXry HXd A LXttlX LXmb."))
+ {
+ kwsys_ios::cerr
+ << "Problem with ReplaceChars "
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres2;
+
+ if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.",
+ "Mary "))
+ {
+ kwsys_ios::cerr
+ << "Problem with StringStartsWith "
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::StringEndsWith("Mary Had A Little Lamb.",
+ " Lamb."))
+ {
+ kwsys_ios::cerr
+ << "Problem with StringEndsWith "
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+
+ cres = kwsys::SystemTools::DuplicateString("Mary Had A Little Lamb.");
+ if (strcmp(cres,"Mary Had A Little Lamb."))
+ {
+ kwsys_ios::cerr
+ << "Problem with DuplicateString "
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ test = "Mary Had A Little Lamb.";
+ if (kwsys::SystemTools::CropString(test,13) !=
+ "Mary ...Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with CropString "
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+
+ kwsys_stl::vector<kwsys_stl::string> lines;
+ kwsys::SystemTools::Split("Mary Had A Little Lamb.",lines,' ');
+ if (lines[0] != "Mary" || lines[1] != "Had" ||
+ lines[2] != "A" || lines[3] != "Little" || lines[4] != "Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with Split "
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+
+#ifdef _WIN32
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath
+ ("L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
+ L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath
+ ("L:/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
+ L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"L:/Local Mojo/Hex Power Pack/Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath
+ ("\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
+ L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath
+ ("//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
+ L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("//") !=
+ L"//")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"//\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\") !=
+ L"\\\\.\\")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\.\\\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X") !=
+ L"\\\\.\\X")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\.\\X\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:") !=
+ L"\\\\?\\X:")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\.\\X:\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:\\") !=
+ L"\\\\?\\X:\\")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\.\\X:\\\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("NUL") !=
+ L"\\\\.\\NUL")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"NUL\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+#endif
+
+ if (kwsys::SystemTools::ConvertToWindowsOutputPath
+ ("L://Local Mojo/Hex Power Pack/Iffy Voodoo") !=
+ "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsOutputPath "
+ << "\"L://Local Mojo/Hex Power Pack/Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsOutputPath
+ ("//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
+ "\"\\\\grayson\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsOutputPath "
+ << "\"//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToUnixOutputPath
+ ("//Local Mojo/Hex Power Pack/Iffy Voodoo") !=
+ "//Local\\ Mojo/Hex\\ Power\\ Pack/Iffy\\ Voodoo")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToUnixOutputPath "
+ << "\"//Local Mojo/Hex Power Pack/Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ return res;
+}
+
+//----------------------------------------------------------------------------
+
+static bool CheckPutEnv(const char* env, const char* name, const char* value)
+{
+ if(!kwsys::SystemTools::PutEnv(env))
+ {
+ kwsys_ios::cerr << "PutEnv(\"" << env
+ << "\") failed!" << kwsys_ios::endl;
+ return false;
+ }
+ const char* v = kwsys::SystemTools::GetEnv(name);
+ v = v? v : "(null)";
+ if(strcmp(v, value) != 0)
+ {
+ kwsys_ios::cerr << "GetEnv(\"" << name << "\") returned \""
+ << v << "\", not \"" << value << "\"!" << kwsys_ios::endl;
+ return false;
+ }
+ return true;
+}
+
+static bool CheckUnPutEnv(const char* env, const char* name)
+{
+ if(!kwsys::SystemTools::UnPutEnv(env))
+ {
+ kwsys_ios::cerr << "UnPutEnv(\"" << env << "\") failed!"
+ << kwsys_ios::endl;
+ return false;
+ }
+ if(const char* v = kwsys::SystemTools::GetEnv(name))
+ {
+ kwsys_ios::cerr << "GetEnv(\"" << name << "\") returned \""
+ << v << "\", not (null)!" << kwsys_ios::endl;
+ return false;
+ }
+ return true;
+}
+
+static bool CheckEnvironmentOperations()
+{
+ bool res = true;
+ res &= CheckPutEnv("A=B", "A", "B");
+ res &= CheckPutEnv("B=C", "B", "C");
+ res &= CheckPutEnv("C=D", "C", "D");
+ res &= CheckPutEnv("D=E", "D", "E");
+ res &= CheckUnPutEnv("A", "A");
+ res &= CheckUnPutEnv("B=", "B");
+ res &= CheckUnPutEnv("C=D", "C");
+ /* Leave "D=E" in environment so a memory checker can test for leaks. */
+ return res;
+}
+
+
+static bool CheckRelativePath(
+ const kwsys_stl::string& local,
+ const kwsys_stl::string& remote,
+ const kwsys_stl::string& expected)
+{
+ kwsys_stl::string result = kwsys::SystemTools::RelativePath(local, remote);
+ if(expected != result)
+ {
+ kwsys_ios::cerr << "RelativePath(" << local << ", " << remote
+ << ") yielded " << result << " instead of " << expected << kwsys_ios::endl;
+ return false;
+ }
+ return true;
+}
+
+static bool CheckRelativePaths()
+{
+ bool res = true;
+ res &= CheckRelativePath("/usr/share", "/bin/bash", "../../bin/bash");
+ res &= CheckRelativePath("/usr/./share/", "/bin/bash", "../../bin/bash");
+ res &= CheckRelativePath("/usr//share/", "/bin/bash", "../../bin/bash");
+ res &= CheckRelativePath("/usr/share/../bin/", "/bin/bash", "../../bin/bash");
+ res &= CheckRelativePath("/usr/share", "/usr/share//bin", "bin");
+ return res;
+}
+
+static bool CheckCollapsePath(
+ const kwsys_stl::string& path,
+ const kwsys_stl::string& expected)
+{
+ kwsys_stl::string result = kwsys::SystemTools::CollapseFullPath(path);
+ if(expected != result)
+ {
+ kwsys_ios::cerr << "CollapseFullPath(" << path
+ << ") yielded " << result << " instead of " << expected << kwsys_ios::endl;
+ return false;
+ }
+ return true;
+}
+
+static bool CheckCollapsePath()
+{
+ bool res = true;
+ res &= CheckCollapsePath("/usr/share/*", "/usr/share/*");
+ res &= CheckCollapsePath("C:/Windows/*", "C:/Windows/*");
+ return res;
+}
+
+//----------------------------------------------------------------------------
+int testSystemTools(int, char*[])
+{
+ bool res = true;
+
+ int cc;
+ for ( cc = 0; toUnixPaths[cc][0]; cc ++ )
+ {
+ res &= CheckConvertToUnixSlashes(toUnixPaths[cc][0], toUnixPaths[cc][1]);
+ }
+
+ // Special check for ~
+ kwsys_stl::string output;
+ if(kwsys::SystemTools::GetEnv("HOME", output))
+ {
+ output += "/foo bar/lala";
+ res &= CheckConvertToUnixSlashes("~/foo bar/lala", output);
+ }
+
+ for (cc = 0; checkEscapeChars[cc][0]; cc ++ )
+ {
+ res &= CheckEscapeChars(checkEscapeChars[cc][0], checkEscapeChars[cc][1],
+ *checkEscapeChars[cc][2], checkEscapeChars[cc][3]);
+ }
+
+ res &= CheckFileOperations();
+
+ res &= CheckStringOperations();
+
+ res &= CheckEnvironmentOperations();
+
+ res &= CheckRelativePaths();
+
+ res &= CheckCollapsePath();
+
+ return res ? 0 : 1;
+}
diff --git a/Source/kwsys/testSystemTools.h.in b/Source/kwsys/testSystemTools.h.in
new file mode 100644
index 0000000000..66f0f72571
--- /dev/null
+++ b/Source/kwsys/testSystemTools.h.in
@@ -0,0 +1,21 @@
+/*============================================================================
+ 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@_testSystemtools_h
+#define @KWSYS_NAMESPACE@_testSystemtools_h
+
+#define EXECUTABLE_OUTPUT_PATH "@CMAKE_CURRENT_BINARY_DIR@"
+
+#define TEST_SYSTEMTOOLS_SOURCE_DIR "@TEST_SYSTEMTOOLS_SOURCE_DIR@"
+#define TEST_SYSTEMTOOLS_BINARY_DIR "@TEST_SYSTEMTOOLS_BINARY_DIR@"
+#cmakedefine KWSYS_TEST_SYSTEMTOOLS_LONG_PATHS
+
+#endif
diff --git a/Source/kwsys/testTerminal.c b/Source/kwsys/testTerminal.c
new file mode 100644
index 0000000000..0d2d7a77b3
--- /dev/null
+++ b/Source/kwsys/testTerminal.c
@@ -0,0 +1,31 @@
+/*============================================================================
+ 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.
+============================================================================*/
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Terminal.h)
+
+/* Work-around CMake dependency scanning limitation. This must
+ duplicate the above list of headers. */
+#if 0
+# include "Terminal.h.in"
+#endif
+
+int testTerminal(int argc, char* argv[])
+{
+ (void)argc;
+ (void)argv;
+ kwsysTerminal_cfprintf(kwsysTerminal_Color_ForegroundYellow |
+ kwsysTerminal_Color_BackgroundBlue |
+ kwsysTerminal_Color_AssumeTTY,
+ stdout, "Hello %s!", "World");
+ fprintf(stdout, "\n");
+ return 0;
+}
diff --git a/Templates/AppleInfo.plist b/Templates/AppleInfo.plist
new file mode 100644
index 0000000000..1f68ccf923
--- /dev/null
+++ b/Templates/AppleInfo.plist
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${APPLE_GUI_EXECUTABLE}</string>
+ <key>CFBundleGetInfoString</key>
+ <string>${APPLE_GUI_INFO_STRING}</string>
+ <key>CFBundleIconFile</key>
+ <string>${APPLE_GUI_ICON}</string>
+ <key>CFBundleIdentifier</key>
+ <string>${APPLE_GUI_IDENTIFIER}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleLongVersionString</key>
+ <string>${APPLE_GUI_LONG_VERSION_STRING}</string>
+ <key>CFBundleName</key>
+ <string>${APPLE_GUI_BUNDLE_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${APPLE_GUI_SHORT_VERSION_STRING}</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>${APPLE_GUI_BUNDLE_VERSION}</string>
+ <key>CSResourcesFileMapped</key>
+ <true/>
+ <key>LSRequiresCarbon</key>
+ <true/>
+ <key>NSHumanReadableCopyright</key>
+ <string>${APPLE_GUI_COPYRIGHT}</string>
+</dict>
+</plist>
diff --git a/Templates/CMakeVSMacros1.vsmacros b/Templates/CMakeVSMacros1.vsmacros
new file mode 100644
index 0000000000..60487d91c9
--- /dev/null
+++ b/Templates/CMakeVSMacros1.vsmacros
Binary files differ
diff --git a/Templates/CMakeVSMacros2.vsmacros b/Templates/CMakeVSMacros2.vsmacros
new file mode 100644
index 0000000000..5ba27991a8
--- /dev/null
+++ b/Templates/CMakeVSMacros2.vsmacros
Binary files differ
diff --git a/Templates/CMakeVisualStudio6Configurations.cmake b/Templates/CMakeVisualStudio6Configurations.cmake
new file mode 100644
index 0000000000..6355969ab0
--- /dev/null
+++ b/Templates/CMakeVisualStudio6Configurations.cmake
@@ -0,0 +1,3 @@
+# When the dll templates are changed, this list should be
+# updated with the list of possible configurations.
+set(CMAKE_CONFIGURATION_TYPES Debug Release MinSizeRel RelWithDebInfo)
diff --git a/Templates/CPack.GenericDescription.txt b/Templates/CPack.GenericDescription.txt
new file mode 100644
index 0000000000..9ca1802ad8
--- /dev/null
+++ b/Templates/CPack.GenericDescription.txt
@@ -0,0 +1,5 @@
+DESCRIPTION
+===========
+
+This is an installer created using CPack (http://www.cmake.org). No additional installation instructions provided.
+
diff --git a/Templates/CPack.GenericLicense.txt b/Templates/CPack.GenericLicense.txt
new file mode 100644
index 0000000000..c211bb3702
--- /dev/null
+++ b/Templates/CPack.GenericLicense.txt
@@ -0,0 +1,5 @@
+LICENSE
+=======
+
+This is an installer created using CPack (http://www.cmake.org). No license provided.
+
diff --git a/Templates/CPack.GenericWelcome.txt b/Templates/CPack.GenericWelcome.txt
new file mode 100644
index 0000000000..5330087b1e
--- /dev/null
+++ b/Templates/CPack.GenericWelcome.txt
@@ -0,0 +1 @@
+Welcome to installation. This program will guide you through the installation of this software.
diff --git a/Templates/CPackConfig.cmake.in b/Templates/CPackConfig.cmake.in
new file mode 100644
index 0000000000..c00ea2a059
--- /dev/null
+++ b/Templates/CPackConfig.cmake.in
@@ -0,0 +1,20 @@
+# This file will be configured to contain variables for CPack. These variables
+# should be set in the CMake list file of the project before CPack module is
+# included. The list of available CPACK_xxx variables and their associated
+# documentation may be obtained using
+# cpack --help-variable-list
+#
+# Some variables are common to all generators (e.g. CPACK_PACKAGE_NAME)
+# and some are specific to a generator
+# (e.g. CPACK_NSIS_EXTRA_INSTALL_COMMANDS). The generator specific variables
+# usually begin with CPACK_<GENNAME>_xxxx.
+
+@_CPACK_OTHER_VARIABLES_@
+
+if(NOT CPACK_PROPERTIES_FILE)
+ set(CPACK_PROPERTIES_FILE "@CMAKE_BINARY_DIR@/CPackProperties.cmake")
+endif()
+
+if(EXISTS ${CPACK_PROPERTIES_FILE})
+ include(${CPACK_PROPERTIES_FILE})
+endif()
diff --git a/Templates/CTestScript.cmake.in b/Templates/CTestScript.cmake.in
new file mode 100644
index 0000000000..5fb3529e4a
--- /dev/null
+++ b/Templates/CTestScript.cmake.in
@@ -0,0 +1,33 @@
+cmake_minimum_required(VERSION 2.4)
+
+# This is a template for the CTest script for this system
+
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "@BUILDNAME@")
+
+# ---
+set(CTEST_SOURCE_DIRECTORY "@CMAKE_SOURCE_DIR@")
+set(CTEST_BINARY_DIRECTORY "@CMAKE_BINARY_DIR@")
+set(CTEST_UPDATE_COMMAND "@UPDATE_COMMAND@")
+set(CTEST_UPDATE_OPTIONS "@UPDATE_OPTIONS@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_BUILD_CONFIGURATION "Release")
+#set(CTEST_MEMORYCHECK_COMMAND "@MEMORYCHECK_COMMAND@")
+#set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE "@MEMORYCHECK_SUPPRESSIONS_FILE@")
+#set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "@MEMORYCHECK_COMMAND_OPTIONS@")
+#set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+set(CTEST_DROP_METHOD "@DROP_METHOD@")
+
+CTEST_START(Experimental TRACK Weekly)
+CTEST_UPDATE(SOURCE "${CTEST_SOURCE_DIRECTORY}")
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}")
+CTEST_READ_CUSTOM_FILES("${CTEST_BINARY_DIRECTORY}")
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}")
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}")
+#CTEST_MEMCHECK(BUILD "${CTEST_BINARY_DIRECTORY}")
+#CTEST_COVERAGE(BUILD "${CTEST_BINARY_DIRECTORY}")
+CTEST_SUBMIT()
diff --git a/Templates/DLLFooter.dsptemplate b/Templates/DLLFooter.dsptemplate
new file mode 100644
index 0000000000..0d0682a7b4
--- /dev/null
+++ b/Templates/DLLFooter.dsptemplate
@@ -0,0 +1,4 @@
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Templates/DLLHeader.dsptemplate b/Templates/DLLHeader.dsptemplate
new file mode 100644
index 0000000000..d9bccaf561
--- /dev/null
+++ b/Templates/DLLHeader.dsptemplate
@@ -0,0 +1,192 @@
+# Microsoft Developer Studio Project File - Name="OUTPUT_LIBNAME" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=OUTPUT_LIBNAME - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak" CFG="OUTPUT_LIBNAME - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "OUTPUT_LIBNAME - Win32 MinSizeRel" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "OUTPUT_LIBNAME - Win32 RelWithDebInfo" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# ITK DSP Header file
+# This file is read by the build system of itk, and is used as the top part of
+# a microsoft project dsp header file
+# IF this is in a dsp file, then it is not the header, but has
+# already been used, so do not edit here...
+
+# variables to REPLACE
+#
+# BUILD_INCLUDES == include path
+# EXTRA_DEFINES == compiler defines
+# OUTPUT_DIRECTORY == override in output directory
+# OUTPUT_LIBNAME == name of output library
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Release"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_RELEASE"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "_WINDOWS" /D "_USRDLL" OUTPUT_LIBNAME_EXPORTS /FD /c
+# ADD CPP /nologo /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /FD /c
+# ADD CPP BUILD_INCLUDES_RELEASE EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_RELEASE
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_RELEASE /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_RELEASE
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /dll /machine:I386
+# ADD LINK32 /nologo /dll TARGET_VERSION_FLAG /machine:I386 /out:"OUTPUT_DIRECTORY_RELEASE/OUTPUT_NAME_RELEASE" TARGET_IMPLIB_FLAG_RELEASE
+CM_MULTILINE_OPTIONS_RELEASE
+
+CMAKE_CUSTOM_RULE_CODE_RELEASE
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Debug"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "OUTPUT_DIRECTORY_DEBUG"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" OUTPUT_LIBNAME_EXPORTS /FD /c
+# ADD CPP /nologo /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /FD /c
+# ADD CPP BUILD_INCLUDES_DEBUG EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_DEBUG
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC BUILD_INCLUDES_DEBUG /l 0x409 /d "_DEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_DEBUG
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 /nologo /dll TARGET_VERSION_FLAG /debug /machine:I386 /out:"OUTPUT_DIRECTORY_DEBUG/OUTPUT_NAME_DEBUG" /pdbtype:sept TARGET_IMPLIB_FLAG_DEBUG
+CM_MULTILINE_OPTIONS_DEBUG
+
+CMAKE_CUSTOM_RULE_CODE_DEBUG
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 MinSizeRel"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "MinSizeRel"
+# PROP BASE Intermediate_Dir "MinSizeRel"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_MINSIZEREL"
+# PROP Intermediate_Dir "MinSizeRel"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /FD /c OUTPUT_LIBNAME_EXPORTS
+# SUBTRACT BASE CPP /YX
+# ADD CPP /nologo /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /FD /c
+# ADD CPP BUILD_INCLUDES_MINSIZEREL EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_MINSIZEREL
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_MINSIZEREL /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_MINSIZEREL
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /dll /machine:I386
+# ADD LINK32 /nologo /dll TARGET_VERSION_FLAG /machine:I386 /out:"OUTPUT_DIRECTORY_MINSIZEREL/OUTPUT_NAME_MINSIZEREL" TARGET_IMPLIB_FLAG_MINSIZEREL
+CM_MULTILINE_OPTIONS_MINSIZEREL
+
+CMAKE_CUSTOM_RULE_CODE_MINSIZEREL
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "RelWithDebInfo"
+# PROP BASE Intermediate_Dir "RelWithDebInfo"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_RELWITHDEBINFO"
+# PROP Intermediate_Dir "RelWithDebInfo"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "_WINDOWS" /D "_USRDLL" OUTPUT_LIBNAME_EXPORTS /FD /c
+# ADD CPP /nologo /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /FD /c
+# ADD CPP BUILD_INCLUDES_RELWITHDEBINFO EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_RELWITHDEBINFO
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_RELWITHDEBINFO /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_RELWITHDEBINFO
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /dll /machine:I386 /pdbtype:sept
+# ADD LINK32 /nologo /dll TARGET_VERSION_FLAG /debug /machine:I386 /pdbtype:sept /out:"OUTPUT_DIRECTORY_RELWITHDEBINFO/OUTPUT_NAME_RELWITHDEBINFO" TARGET_IMPLIB_FLAG_RELWITHDEBINFO
+CM_MULTILINE_OPTIONS_RELWITHDEBINFO
+
+CMAKE_CUSTOM_RULE_CODE_RELWITHDEBINFO
+
+!ENDIF
+
+# Begin Target
+
+# Name "OUTPUT_LIBNAME - Win32 Release"
+# Name "OUTPUT_LIBNAME - Win32 Debug"
+# Name "OUTPUT_LIBNAME - Win32 MinSizeRel"
+# Name "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
diff --git a/Templates/EXEFooter.dsptemplate b/Templates/EXEFooter.dsptemplate
new file mode 100644
index 0000000000..0d0682a7b4
--- /dev/null
+++ b/Templates/EXEFooter.dsptemplate
@@ -0,0 +1,4 @@
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Templates/EXEHeader.dsptemplate b/Templates/EXEHeader.dsptemplate
new file mode 100644
index 0000000000..3a6d2feb11
--- /dev/null
+++ b/Templates/EXEHeader.dsptemplate
@@ -0,0 +1,183 @@
+# Microsoft Developer Studio Project File - Name="pcbuilder" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# CM DSP Header file
+# This file is read by the build system of cm, and is used as the top part of
+# a microsoft project dsp header file
+# IF this is in a dsp file, then it is not the header, but has
+# already been used, so do not edit here...
+
+# variables to REPLACE
+#
+# BUILD_INCLUDES == include path
+# OUTPUT_DIRECTORY == override in output directory
+# EXTRA_DEFINES == compiler defines
+# OUTPUT_LIBNAME == name of output library
+# CM_LIBRARIES == libraries linked in
+# TARGTYPE "Win32 (x86) Application" 0x0103
+
+CFG=OUTPUT_LIBNAME - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak" CFG="OUTPUT_LIBNAME - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "OUTPUT_LIBNAME - Win32 MinSizeRel" (based on "Win32 (x86) Application")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "OUTPUT_LIBNAME - Win32 RelWithDebInfo" (based on "Win32 (x86) Application")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Release"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_RELEASE"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /FD /c
+# ADD CPP /nologo /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /FD /c
+# ADD CPP BUILD_INCLUDES_RELEASE EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_RELEASE
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_RELEASE /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_RELEASE
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:console /machine:I386 /IGNORE:4089
+# ADD LINK32 /nologo /subsystem:console /machine:I386 /IGNORE:4089 TARGET_VERSION_FLAG
+# ADD LINK32 /out:"OUTPUT_DIRECTORY_RELEASE\OUTPUT_NAME_RELEASE" TARGET_IMPLIB_FLAG_RELEASE
+CM_MULTILINE_OPTIONS_RELEASE
+
+CMAKE_CUSTOM_RULE_CODE_RELEASE
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Debug"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "OUTPUT_DIRECTORY_DEBUG"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /FD /GZ /c
+# ADD CPP /nologo /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /FD /GZ /c
+# ADD CPP BUILD_INCLUDES_DEBUG EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_DEBUG
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC BUILD_INCLUDES_DEBUG /l 0x409 /d "_DEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_DEBUG
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /IGNORE:4089
+# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /IGNORE:4089 TARGET_VERSION_FLAG
+# ADD LINK32 /out:"OUTPUT_DIRECTORY_DEBUG\OUTPUT_NAME_DEBUG" TARGET_IMPLIB_FLAG_DEBUG
+CM_MULTILINE_OPTIONS_DEBUG
+
+CMAKE_CUSTOM_RULE_CODE_DEBUG
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 MinSizeRel"
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "MinSizeRel"
+# PROP BASE Intermediate_Dir "MinSizeRel"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_MINSIZEREL"
+# PROP Intermediate_Dir "MinSizeRel"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /FD /c
+# ADD CPP /nologo /D "WIN32" BUILD_INCLUDES_MINSIZEREL EXTRA_DEFINES /D "NDEBUG" /D "_CONSOLE" /FD /c
+# ADD CPP BUILD_INCLUDES_MINSIZEREL EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_MINSIZEREL
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_MINSIZEREL /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_MINSIZEREL
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:console /machine:I386 /IGNORE:4089
+# ADD LINK32 /nologo /subsystem:console /machine:I386 /IGNORE:4089 TARGET_VERSION_FLAG
+# ADD LINK32 /out:"OUTPUT_DIRECTORY_MINSIZEREL\OUTPUT_NAME_MINSIZEREL" TARGET_IMPLIB_FLAG_MINSIZEREL
+CM_MULTILINE_OPTIONS_MINSIZEREL
+
+CMAKE_CUSTOM_RULE_CODE_MINSIZEREL
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "RelWithDebInfo"
+# PROP BASE Intermediate_Dir "RelWithDebInfo"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_RELWITHDEBINFO"
+# PROP Intermediate_Dir "RelWithDebInfo"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /FD /c
+# ADD CPP /nologo /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /FD /c
+# ADD CPP BUILD_INCLUDES_RELWITHDEBINFO EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_RELWITHDEBINFO
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_RELWITHDEBINFO /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_RELWITHDEBINFO
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:console /debug /machine:I386 /IGNORE:4089
+# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /IGNORE:4089 TARGET_VERSION_FLAG
+# ADD LINK32 /out:"OUTPUT_DIRECTORY_RELWITHDEBINFO\OUTPUT_NAME_RELWITHDEBINFO" TARGET_IMPLIB_FLAG_RELWITHDEBINFO
+CM_MULTILINE_OPTIONS_RELWITHDEBINFO
+
+CMAKE_CUSTOM_RULE_CODE_RELWITHDEBINFO
+
+!ENDIF
+
+# Begin Target
+
+# Name "OUTPUT_LIBNAME - Win32 Release"
+# Name "OUTPUT_LIBNAME - Win32 Debug"
+# Name "OUTPUT_LIBNAME - Win32 MinSizeRel"
+# Name "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
diff --git a/Templates/EXEWinHeader.dsptemplate b/Templates/EXEWinHeader.dsptemplate
new file mode 100644
index 0000000000..350e3ea009
--- /dev/null
+++ b/Templates/EXEWinHeader.dsptemplate
@@ -0,0 +1,187 @@
+# Microsoft Developer Studio Project File - Name="pcbuilder" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# CM DSP Header file
+# This file is read by the build system of cm, and is used as the top part of
+# a microsoft project dsp header file
+# IF this is in a dsp file, then it is not the header, but has
+# already been used, so do not edit here...
+
+# variables to REPLACE
+#
+# BUILD_INCLUDES == include path
+# OUTPUT_DIRECTORY == override in output directory
+# EXTRA_DEFINES == compiler defines
+# OUTPUT_LIBNAME == name of output library
+# CM_LIBRARIES == libraries linked in
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=OUTPUT_LIBNAME - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak" CFG="OUTPUT_LIBNAME - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "OUTPUT_LIBNAME - Win32 MinSizeRel" (based on "Win32 (x86) Application")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "OUTPUT_LIBNAME - Win32 RelWithDebInfo" (based on "Win32 (x86) Application")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Release"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_RELEASE"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP BUILD_INCLUDES_RELEASE EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_RELEASE
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_RELEASE /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_RELEASE
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 /IGNORE:4089
+# ADD LINK32 /nologo /subsystem:windows /machine:I386 /IGNORE:4089 TARGET_VERSION_FLAG
+# ADD LINK32 /out:"OUTPUT_DIRECTORY_RELEASE\OUTPUT_NAME_RELEASE" TARGET_IMPLIB_FLAG_RELEASE
+CM_MULTILINE_OPTIONS_RELEASE
+
+CMAKE_CUSTOM_RULE_CODE_RELEASE
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Debug"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "OUTPUT_DIRECTORY_DEBUG"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /GZ /c
+# ADD CPP BUILD_INCLUDES_DEBUG EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_DEBUG
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC BUILD_INCLUDES_DEBUG /l 0x409 /d "_DEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_DEBUG
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept /IGNORE:4089
+# ADD LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept /IGNORE:4089 TARGET_VERSION_FLAG
+# ADD LINK32 /out:"OUTPUT_DIRECTORY_DEBUG\OUTPUT_NAME_DEBUG" TARGET_IMPLIB_FLAG_DEBUG
+CM_MULTILINE_OPTIONS_DEBUG
+
+CMAKE_CUSTOM_RULE_CODE_DEBUG
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 MinSizeRel"
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "MinSizeRel"
+# PROP BASE Intermediate_Dir "MinSizeRel"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_MINSIZEREL"
+# PROP Intermediate_Dir "MinSizeRel"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP BUILD_INCLUDES_MINSIZEREL EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_MINSIZEREL
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_MINSIZEREL /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_MINSIZEREL
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 /pdbtype:sept /IGNORE:4089
+# ADD LINK32 /nologo /subsystem:windows /machine:I386 /pdbtype:sept /IGNORE:4089 TARGET_VERSION_FLAG
+# ADD LINK32 /out:"OUTPUT_DIRECTORY_MINSIZEREL\OUTPUT_NAME_MINSIZEREL" TARGET_IMPLIB_FLAG_MINSIZEREL
+CM_MULTILINE_OPTIONS_MINSIZEREL
+
+CMAKE_CUSTOM_RULE_CODE_MINSIZEREL
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "RelWithDebInfo"
+# PROP BASE Intermediate_Dir "RelWithDebInfo"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_RELWITHDEBINFO"
+# PROP Intermediate_Dir "RelWithDebInfo"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP BUILD_INCLUDES_RELWITHDEBINFO EXTRA_DEFINES OUTPUT_LIBNAME_EXPORTS
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_RELWITHDEBINFO
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_RELWITHDEBINFO /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_RELWITHDEBINFO
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 /IGNORE:4089
+# ADD LINK32 /nologo /subsystem:windows /debug /machine:I386 /IGNORE:4089 TARGET_VERSION_FLAG
+# ADD LINK32 /out:"OUTPUT_DIRECTORY_RELWITHDEBINFO\OUTPUT_NAME_RELWITHDEBINFO" TARGET_IMPLIB_FLAG_RELWITHDEBINFO
+CM_MULTILINE_OPTIONS_RELWITHDEBINFO
+
+CMAKE_CUSTOM_RULE_CODE_RELWITHDEBINFO
+
+!ENDIF
+
+# Begin Target
+
+# Name "OUTPUT_LIBNAME - Win32 Release"
+# Name "OUTPUT_LIBNAME - Win32 Debug"
+# Name "OUTPUT_LIBNAME - Win32 MinSizeRel"
+# Name "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
diff --git a/Templates/TestDriver.cxx.in b/Templates/TestDriver.cxx.in
new file mode 100644
index 0000000000..ffa69995b8
--- /dev/null
+++ b/Templates/TestDriver.cxx.in
@@ -0,0 +1,165 @@
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#if defined(_MSC_VER)
+# pragma warning(disable:4996) /* deprecation */
+#endif
+
+@CMAKE_TESTDRIVER_EXTRA_INCLUDES@
+
+
+/* Forward declare test functions. */
+@CMAKE_FORWARD_DECLARE_TESTS@
+
+/* Create map. */
+
+typedef int (*MainFuncPointer)(int , char*[]);
+typedef struct
+{
+ const char* name;
+ MainFuncPointer func;
+} functionMapEntry;
+
+static functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
+ @CMAKE_FUNCTION_TABLE_ENTIRES@
+ {0,0}
+};
+
+/* Allocate and create a lowercased copy of string
+ (note that it has to be free'd manually) */
+
+static char* lowercase(const char *string)
+{
+ char *new_string, *p;
+
+#ifdef __cplusplus
+ new_string = static_cast<char *>(malloc(sizeof(char) *
+ static_cast<size_t>(strlen(string) + 1)));
+#else
+ new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
+#endif
+
+ if (!new_string)
+ {
+ return 0;
+ }
+ strcpy(new_string, string);
+ p = new_string;
+ while (*p != 0)
+ {
+#ifdef __cplusplus
+ *p = static_cast<char>(tolower(*p));
+#else
+ *p = (char)(tolower(*p));
+#endif
+
+ ++p;
+ }
+ return new_string;
+}
+
+int main(int ac, char *av[])
+{
+ int i, NumTests, testNum = 0, partial_match;
+ char *arg, *test_name;
+ int count;
+ int testToRun = -1;
+
+ @CMAKE_TESTDRIVER_ARGVC_FUNCTION@
+
+ for(count =0; cmakeGeneratedFunctionMapEntries[count].name != 0; count++)
+ {
+ }
+ NumTests = count;
+ /* If no test name was given */
+ /* process command line with user function. */
+ if (ac < 2)
+ {
+ /* Ask for a test. */
+ printf("Available tests:\n");
+ for (i =0; i < NumTests; ++i)
+ {
+ printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
+ }
+ printf("To run a test, enter the test number: ");
+ fflush(stdout);
+ if( scanf("%d", &testNum) != 1 )
+ {
+ printf("Couldn't parse that input as a number\n");
+ return -1;
+ }
+ if (testNum >= NumTests)
+ {
+ printf("%3d is an invalid test number.\n", testNum);
+ return -1;
+ }
+ testToRun = testNum;
+ ac--;
+ av++;
+ }
+ partial_match = 0;
+ arg = 0;
+ /* If partial match is requested. */
+ if(testToRun == -1 && ac > 1)
+ {
+ partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
+ }
+ if (partial_match && ac < 3)
+ {
+ printf("-R needs an additional parameter.\n");
+ return -1;
+ }
+ if(testToRun == -1)
+ {
+ arg = lowercase(av[1 + partial_match]);
+ }
+ for (i =0; i < NumTests && testToRun == -1; ++i)
+ {
+ test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
+ if (partial_match && strstr(test_name, arg) != NULL)
+ {
+ testToRun = i;
+ ac -=2;
+ av += 2;
+ }
+ else if (!partial_match && strcmp(test_name, arg) == 0)
+ {
+ testToRun = i;
+ ac--;
+ av++;
+ }
+ free(test_name);
+ }
+ if(arg)
+ {
+ free(arg);
+ }
+ if(testToRun != -1)
+ {
+ int result;
+@CMAKE_TESTDRIVER_BEFORE_TESTMAIN@
+ if (testToRun < 0 || testToRun >= NumTests)
+ {
+ printf(
+ "testToRun was modified by TestDriver code to an invalid value: %3d.\n",
+ testNum);
+ return -1;
+ }
+ result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
+@CMAKE_TESTDRIVER_AFTER_TESTMAIN@
+ return result;
+ }
+
+
+ /* Nothing was run, display the test names. */
+ printf("Available tests:\n");
+ for (i =0; i < NumTests; ++i)
+ {
+ printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
+ }
+ printf("Failed: %s is an invalid test name.\n", av[1]);
+
+ return -1;
+}
diff --git a/Templates/UtilityFooter.dsptemplate b/Templates/UtilityFooter.dsptemplate
new file mode 100644
index 0000000000..941fb446af
--- /dev/null
+++ b/Templates/UtilityFooter.dsptemplate
@@ -0,0 +1,2 @@
+# End Target
+# End Project
diff --git a/Templates/UtilityHeader.dsptemplate b/Templates/UtilityHeader.dsptemplate
new file mode 100644
index 0000000000..509f597f17
--- /dev/null
+++ b/Templates/UtilityHeader.dsptemplate
@@ -0,0 +1,95 @@
+# Microsoft Developer Studio Project File - Name="OUTPUT_LIBNAME" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Generic Project" 0x010a
+
+CFG=OUTPUT_LIBNAME - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak" CFG="OUTPUT_LIBNAME - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "OUTPUT_LIBNAME - Win32 MinSizeRel" (based on "Win32 (x86) Generic Project")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Release" (based on "Win32 (x86) Generic Project")
+!MESSAGE "OUTPUT_LIBNAME - Win32 RelWithDebInfo" (based on "Win32 (x86) Generic Project")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Debug" (based on "Win32 (x86) Generic Project")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+MTL=midl.exe
+
+!IF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+
+CMAKE_CUSTOM_RULE_CODE_RELEASE
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+
+CMAKE_CUSTOM_RULE_CODE_DEBUG
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 MinSizeRel"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "MinSizeRel"
+# PROP BASE Intermediate_Dir "MinSizeRel"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Intermediate_Dir "MinSizeRel"
+# PROP Target_Dir ""
+
+CMAKE_CUSTOM_RULE_CODE_MINSIZEREL
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "RelWithDebInfo"
+# PROP BASE Intermediate_Dir "RelWithDebInfo"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Intermediate_Dir "RelWithDebInfo"
+# PROP Target_Dir ""
+
+CMAKE_CUSTOM_RULE_CODE_RELWITHDEBINFO
+
+!ENDIF
+
+# Begin Target
+
+# Name "OUTPUT_LIBNAME - Win32 Release"
+# Name "OUTPUT_LIBNAME - Win32 Debug"
+# Name "OUTPUT_LIBNAME - Win32 MinSizeRel"
+# Name "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
diff --git a/Templates/Windows/ApplicationIcon.png b/Templates/Windows/ApplicationIcon.png
new file mode 100644
index 0000000000..7d95d4e081
--- /dev/null
+++ b/Templates/Windows/ApplicationIcon.png
Binary files differ
diff --git a/Templates/Windows/Logo.png b/Templates/Windows/Logo.png
new file mode 100644
index 0000000000..e26771cb33
--- /dev/null
+++ b/Templates/Windows/Logo.png
Binary files differ
diff --git a/Templates/Windows/SmallLogo.png b/Templates/Windows/SmallLogo.png
new file mode 100644
index 0000000000..1eb0d9d528
--- /dev/null
+++ b/Templates/Windows/SmallLogo.png
Binary files differ
diff --git a/Templates/Windows/SplashScreen.png b/Templates/Windows/SplashScreen.png
new file mode 100644
index 0000000000..c951e031bd
--- /dev/null
+++ b/Templates/Windows/SplashScreen.png
Binary files differ
diff --git a/Templates/Windows/StoreLogo.png b/Templates/Windows/StoreLogo.png
new file mode 100644
index 0000000000..dcb672712c
--- /dev/null
+++ b/Templates/Windows/StoreLogo.png
Binary files differ
diff --git a/Templates/Windows/Windows_TemporaryKey.pfx b/Templates/Windows/Windows_TemporaryKey.pfx
new file mode 100644
index 0000000000..1cad9993d6
--- /dev/null
+++ b/Templates/Windows/Windows_TemporaryKey.pfx
Binary files differ
diff --git a/Templates/cygwin-package.sh.in b/Templates/cygwin-package.sh.in
new file mode 100755
index 0000000000..69b6c0f6fc
--- /dev/null
+++ b/Templates/cygwin-package.sh.in
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+# this is a sample shell script used for building a cmake
+# based project for a cygwin setup package.
+
+# get the current directory
+TOP_DIR=`cd \`echo "$0" | sed -n '/\//{s/\/[^\/]*$//;p;}'\`;pwd`
+
+# create build directory
+mkdirs()
+{
+ (
+ mkdir -p "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build"
+ )
+}
+
+# cd into
+# untar source tree and apply patch
+prep()
+{
+ (
+ cd "$TOP_DIR" &&
+ tar xvfj @CPACK_PACKAGE_FILE_NAME@.tar.bz2
+ patch -p0 < "@CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@.patch" &&
+ mkdirs
+ )
+}
+
+# configure the build tree in .build directory
+# of the source tree
+conf()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ cmake ..
+ )
+}
+
+# build the package in the .build directory
+build()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ make &&
+ make test
+ )
+}
+
+# clean the build tree
+clean()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ make clean
+ )
+}
+
+# create the package
+pkg()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ cpack &&
+ mv @CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@.tar.bz2 "$TOP_DIR"
+ )
+}
+
+# create the source package
+spkg()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ cpack --config CPackSourceConfig.cmake &&
+ mv @CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@-src.tar.bz2 "$TOP_DIR"
+ )
+}
+
+# clean up
+finish()
+{
+ (
+ rm -rf "@CPACK_PACKAGE_FILE_NAME@"
+ )
+}
+
+case $1 in
+ prep) prep ; STATUS=$? ;;
+ mkdirs) mkdirs ; STATUS=$? ;;
+ conf) conf ; STATUS=$? ;;
+ build) build ; STATUS=$? ;;
+ clean) clean ; STATUS=$? ;;
+ package) pkg ; STATUS=$? ;;
+ pkg) pkg ; STATUS=$? ;;
+ src-package) spkg ; STATUS=$? ;;
+ spkg) spkg ; STATUS=$? ;;
+ finish) finish ; STATUS=$? ;;
+ all) (
+ prep && conf && build && pkg && spkg && finish ;
+ STATUS=$?
+ ) ;;
+ *) echo "Error: bad argument (all or one of these: prep mkdirs conf build clean package pkg src-package spkg finish)" ; exit 1 ;;
+esac
+exit ${STATUS}
diff --git a/Templates/staticLibFooter.dsptemplate b/Templates/staticLibFooter.dsptemplate
new file mode 100644
index 0000000000..0d0682a7b4
--- /dev/null
+++ b/Templates/staticLibFooter.dsptemplate
@@ -0,0 +1,4 @@
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Templates/staticLibHeader.dsptemplate b/Templates/staticLibHeader.dsptemplate
new file mode 100644
index 0000000000..a8892e1246
--- /dev/null
+++ b/Templates/staticLibHeader.dsptemplate
@@ -0,0 +1,173 @@
+# Microsoft Developer Studio Project File - Name="OUTPUT_LIBNAME" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# CMAKE DSP Header file
+# This file is read by the CMAKE, and is used as the top part of
+# a microsoft project dsp header file
+# IF this is in a dsp file, then it is not the header, but has
+# already been used, so do not edit in that case.
+
+# variables to REPLACE
+#
+# BUILD_INCLUDES == include path
+# EXTRA_DEFINES == compiler defines
+# OUTPUT_DIRECTORY == override in output directory
+# OUTPUT_LIBNAME == name of output library
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=OUTPUT_LIBNAME - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "OUTPUT_LIBNAME.mak" CFG="OUTPUT_LIBNAME - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "OUTPUT_LIBNAME - Win32 MinSizeRel" (based on "Win32 (x86) Static Library")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "OUTPUT_LIBNAME - Win32 RelWithDebInfo" (based on "Win32 (x86) Static Library")
+!MESSAGE "OUTPUT_LIBNAME - Win32 Debug" (based on "Win32 (x86) Static Library")
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Release"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_RELEASE"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "NDEBUG" /D "_LIB" /FD /c
+# ADD CPP /nologo /D "NDEBUG" /D "WIN32" /D "_LIB" /FD /c
+# ADD CPP BUILD_INCLUDES_RELEASE EXTRA_DEFINES
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_RELEASE
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_RELEASE /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_RELEASE
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_RELEASE/OUTPUT_NAME_RELEASE" CM_STATIC_LIB_ARGS_RELEASE
+
+CMAKE_CUSTOM_RULE_CODE_RELEASE
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Debug"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "OUTPUT_DIRECTORY_DEBUG"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "_DEBUG" /D "_LIB" /FD /c
+# ADD CPP /nologo /D "_DEBUG" /D "WIN32" /D "_LIB" /FD /GZ /c
+# ADD CPP BUILD_INCLUDES_DEBUG EXTRA_DEFINES
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_DEBUG
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC BUILD_INCLUDES_DEBUG /l 0x409 /d "_DEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_DEBUG
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_DEBUG/OUTPUT_NAME_DEBUG" CM_STATIC_LIB_ARGS_DEBUG
+
+CMAKE_CUSTOM_RULE_CODE_DEBUG
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 MinSizeRel"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "MinSizeRel"
+# PROP BASE Intermediate_Dir "MinSizeRel"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_MINSIZEREL"
+# PROP Intermediate_Dir "MinSizeRel"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_ATL_DLL" /FD /c
+# ADD CPP /nologo /D "NDEBUG" /D "_ATL_DLL" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /FD /c
+# ADD CPP BUILD_INCLUDES_MINSIZEREL EXTRA_DEFINES
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_MINSIZEREL
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_MINSIZEREL /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_MINSIZEREL
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_MINSIZEREL/OUTPUT_NAME_MINSIZEREL" CM_STATIC_LIB_ARGS_MINSIZEREL
+
+CMAKE_CUSTOM_RULE_CODE_MINSIZEREL
+
+!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
+
+# PROP BASE Use_MFC CMAKE_MFC_FLAG
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "RelWithDebInfo"
+# PROP BASE Intermediate_Dir "RelWithDebInfo"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC CMAKE_MFC_FLAG
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "OUTPUT_DIRECTORY_RELWITHDEBINFO"
+# PROP Intermediate_Dir "RelWithDebInfo"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /D "WIN32" /D "NDEBUG" /D "_LIB" /FD /c
+# ADD CPP /nologo /D "NDEBUG" /D "WIN32" /D "_LIB" /FD /c
+# ADD CPP BUILD_INCLUDES_RELWITHDEBINFO EXTRA_DEFINES
+# ADD CPP CMAKE_CXX_FLAGS
+# ADD CPP CMAKE_CXX_FLAGS_RELWITHDEBINFO
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC BUILD_INCLUDES_RELWITHDEBINFO /l 0x409 /d "NDEBUG"
+# ADD RSC COMPILE_DEFINITIONS
+# ADD RSC COMPILE_DEFINITIONS_RELWITHDEBINFO
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_RELWITHDEBINFO/OUTPUT_NAME_RELWITHDEBINFO" CM_STATIC_LIB_ARGS_RELWITHDEBINFO
+
+CMAKE_CUSTOM_RULE_CODE_RELWITHDEBINFO
+
+!ENDIF
+
+# Begin Target
+
+# Name "OUTPUT_LIBNAME - Win32 Release"
+# Name "OUTPUT_LIBNAME - Win32 Debug"
+# Name "OUTPUT_LIBNAME - Win32 MinSizeRel"
+# Name "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
+
diff --git a/Tests/.NoDartCoverage b/Tests/.NoDartCoverage
new file mode 100644
index 0000000000..3c99729386
--- /dev/null
+++ b/Tests/.NoDartCoverage
@@ -0,0 +1 @@
+# do not do coverage in this directory
diff --git a/Tests/AliasTarget/CMakeLists.txt b/Tests/AliasTarget/CMakeLists.txt
new file mode 100644
index 0000000000..c50b4e6a84
--- /dev/null
+++ b/Tests/AliasTarget/CMakeLists.txt
@@ -0,0 +1,80 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(AliasTarget)
+
+set(CMAKE_CXX_STANDARD 98)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+ CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
+
+add_library(foo SHARED empty.cpp)
+add_library(PREFIX::Foo ALIAS foo)
+add_library(Another::Alias ALIAS foo)
+
+add_library(objects OBJECT object.cpp)
+add_library(Alias::Objects ALIAS objects)
+
+target_compile_definitions(foo PUBLIC FOO_DEFINE)
+
+add_library(bar SHARED empty.cpp)
+target_compile_definitions(bar PUBLIC BAR_DEFINE)
+
+target_link_libraries(foo LINK_PUBLIC $<$<STREQUAL:$<TARGET_PROPERTY:PREFIX::Foo,ALIASED_TARGET>,foo>:bar>)
+
+add_executable(AliasTarget commandgenerator.cpp $<TARGET_OBJECTS:Alias::Objects>)
+add_executable(PREFIX::AliasTarget ALIAS AliasTarget)
+add_executable(Generator::Command ALIAS AliasTarget)
+
+add_custom_command(OUTPUT commandoutput.h COMMAND Generator::Command)
+
+add_library(bat SHARED bat.cpp "${CMAKE_CURRENT_BINARY_DIR}/commandoutput.h")
+target_link_libraries(bat PREFIX::Foo)
+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_dependencies(bat usealias)
+
+if (NOT TARGET Another::Alias)
+ message(SEND_ERROR "Another::Alias is not considered a target.")
+endif()
+
+get_target_property(_alt PREFIX::Foo ALIASED_TARGET)
+if (NOT ${_alt} STREQUAL foo)
+ message(SEND_ERROR "ALIASED_TARGET is not foo: ${_alt}")
+endif()
+
+get_property(_alt2 TARGET PREFIX::Foo PROPERTY ALIASED_TARGET)
+if (NOT ${_alt2} STREQUAL foo)
+ message(SEND_ERROR "ALIASED_TARGET is not foo.")
+endif()
+
+add_library(iface INTERFACE)
+add_library(Alias::Iface ALIAS iface)
+
+get_target_property(_notAlias1 foo ALIASED_TARGET)
+if (NOT DEFINED _notAlias1)
+ message(SEND_ERROR "_notAlias1 is not defined")
+endif()
+if (_notAlias1)
+ message(SEND_ERROR "_notAlias1 is defined, but foo is not an ALIAS")
+endif()
+if (NOT _notAlias1 STREQUAL _notAlias1-NOTFOUND)
+ message(SEND_ERROR "_notAlias1 not defined to a -NOTFOUND variant")
+endif()
+
+get_property(_notAlias2 TARGET foo PROPERTY ALIASED_TARGET)
+if (NOT DEFINED _notAlias2)
+ message(SEND_ERROR "_notAlias2 is not defined")
+endif()
+if (_notAlias2)
+ message(SEND_ERROR "_notAlias2 is defined, but foo is not an ALIAS")
+endif()
+if (NOT _notAlias2 STREQUAL _notAlias2-NOTFOUND)
+ message(SEND_ERROR "_notAlias2 not defined to a -NOTFOUND variant")
+endif()
diff --git a/Tests/AliasTarget/bat.cpp b/Tests/AliasTarget/bat.cpp
new file mode 100644
index 0000000000..1063c2175d
--- /dev/null
+++ b/Tests/AliasTarget/bat.cpp
@@ -0,0 +1,28 @@
+
+#ifndef FOO_DEFINE
+#error Expected FOO_DEFINE
+#endif
+
+#ifndef BAR_DEFINE
+#error Expected Bar_DEFINE
+#endif
+
+#include "commandoutput.h"
+
+#ifndef COMMANDOUTPUT_DEFINE
+#error Expected COMMANDOUTPUT_DEFINE
+#endif
+
+#include "targetoutput.h"
+
+#ifndef TARGETOUTPUT_DEFINE
+#error Expected TARGETOUTPUT_DEFINE
+#endif
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int bar()
+{
+ return 0;
+}
diff --git a/Tests/AliasTarget/commandgenerator.cpp b/Tests/AliasTarget/commandgenerator.cpp
new file mode 100644
index 0000000000..23560a4bae
--- /dev/null
+++ b/Tests/AliasTarget/commandgenerator.cpp
@@ -0,0 +1,15 @@
+
+#include <fstream>
+
+#include "object.h"
+
+int main(int argc, char **argv)
+{
+ std::fstream fout;
+ fout.open("commandoutput.h", std::ios::out);
+ if (!fout)
+ return 1;
+ fout << "#define COMMANDOUTPUT_DEFINE\n";
+ fout.close();
+ return object();
+}
diff --git a/Tests/AliasTarget/empty.cpp b/Tests/AliasTarget/empty.cpp
new file mode 100644
index 0000000000..b19427ad08
--- /dev/null
+++ b/Tests/AliasTarget/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/AliasTarget/object.cpp b/Tests/AliasTarget/object.cpp
new file mode 100644
index 0000000000..df09c20c98
--- /dev/null
+++ b/Tests/AliasTarget/object.cpp
@@ -0,0 +1,5 @@
+
+int object(void)
+{
+ return 0;
+}
diff --git a/Tests/AliasTarget/object.h b/Tests/AliasTarget/object.h
new file mode 100644
index 0000000000..e935f14746
--- /dev/null
+++ b/Tests/AliasTarget/object.h
@@ -0,0 +1,4 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int object(void);
diff --git a/Tests/AliasTarget/targetgenerator.cpp b/Tests/AliasTarget/targetgenerator.cpp
new file mode 100644
index 0000000000..3362414e03
--- /dev/null
+++ b/Tests/AliasTarget/targetgenerator.cpp
@@ -0,0 +1,13 @@
+
+#include <fstream>
+
+int main(int argc, char **argv)
+{
+ std::fstream fout;
+ fout.open("targetoutput.h", std::ios::out);
+ if (!fout)
+ return 1;
+ fout << "#define TARGETOUTPUT_DEFINE\n";
+ fout.close();
+ return 0;
+}
diff --git a/Tests/Architecture/CMakeLists.txt b/Tests/Architecture/CMakeLists.txt
new file mode 100644
index 0000000000..ea5fc0b506
--- /dev/null
+++ b/Tests/Architecture/CMakeLists.txt
@@ -0,0 +1,59 @@
+cmake_minimum_required(VERSION 2.8)
+project(Architecture C)
+
+function(test_for_xcode4 result_var)
+ set(${result_var} 0 PARENT_SCOPE)
+ if(APPLE)
+ execute_process(COMMAND xcodebuild -version
+ OUTPUT_VARIABLE ov RESULT_VARIABLE rv
+ )
+ if("${rv}" STREQUAL "0" AND ov MATCHES "^Xcode ([0-9]+)\\.")
+ if(NOT CMAKE_MATCH_1 VERSION_LESS 4)
+ set(${result_var} 1 PARENT_SCOPE)
+ endif()
+ endif()
+ endif()
+endfunction()
+
+test_for_xcode4(is_xcode4)
+
+set(arch0 i386)
+set(arch1 ppc)
+
+if(is_xcode4)
+ # Xcode 4, use modern architectures as defaults
+ # Arch 'ppc' no longer works: tools no longer available starting with Xcode 4
+ set(arch0 i386)
+ set(arch1 x86_64)
+endif()
+
+add_library(foo foo.c)
+if(CMAKE_OSX_ARCHITECTURES)
+ get_property(archs TARGET foo PROPERTY OSX_ARCHITECTURES)
+ if(NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "${archs}")
+ message(FATAL_ERROR
+ "OSX_ARCHITECTURES property not initialized by CMAKE_OSX_ARCHITECTURES.\n"
+ "Expected [${CMAKE_OSX_ARCHITECTURES}], got [${archs}]."
+ )
+ endif()
+ list(LENGTH archs archs_len)
+ if(archs_len GREATER 1)
+ list(GET archs 0 arch0)
+ list(GET archs 1 arch1)
+ endif()
+endif()
+
+message("is_xcode4='${is_xcode4}'")
+message("archs='${archs}'")
+message("arch0='${arch0}'")
+message("arch1='${arch1}'")
+
+set_property(TARGET foo PROPERTY OSX_ARCHITECTURES ${arch0})
+set_property(TARGET foo PROPERTY OSX_ARCHITECTURES_DEBUG ${arch1})
+
+add_executable(bar bar.c)
+target_link_libraries(bar foo)
+
+set_property(TARGET bar PROPERTY OUTPUT_NAME Architecture)
+set_property(TARGET bar PROPERTY OSX_ARCHITECTURES ${arch1})
+set_property(TARGET bar PROPERTY OSX_ARCHITECTURES_DEBUG ${arch0})
diff --git a/Tests/Architecture/bar.c b/Tests/Architecture/bar.c
new file mode 100644
index 0000000000..923c89c9a6
--- /dev/null
+++ b/Tests/Architecture/bar.c
@@ -0,0 +1,2 @@
+extern int foo(void);
+int main() { return foo(); }
diff --git a/Tests/Architecture/foo.c b/Tests/Architecture/foo.c
new file mode 100644
index 0000000000..e35694ba00
--- /dev/null
+++ b/Tests/Architecture/foo.c
@@ -0,0 +1 @@
+int foo(void) { return 0; }
diff --git a/Tests/ArgumentExpansion/CMakeLists.txt b/Tests/ArgumentExpansion/CMakeLists.txt
new file mode 100644
index 0000000000..1735400673
--- /dev/null
+++ b/Tests/ArgumentExpansion/CMakeLists.txt
@@ -0,0 +1,60 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(ArgumentExpansion)
+
+function (argument_tester expected expected_len)
+ list(LENGTH ARGN argn_len)
+ list(LENGTH ${expected} expected_received_len)
+
+ if (NOT ${expected_received_len} EQUAL ${expected_len})
+ message(STATUS "Unexpected: Expanding expected values isn't working")
+ endif ()
+
+ if (${argn_len} EQUAL ${expected_len})
+ set(i 0)
+ while (i LESS ${argn_len})
+ list(GET ARGN ${i} argn_value)
+ list(GET ${expected} ${i} expected_value)
+
+ if (NOT "${argn_value}" STREQUAL "${expected_value}")
+ message(STATUS "Unexpected: Argument ${i} doesn't match")
+ message(STATUS " Expected: ${expected_value}")
+ message(STATUS " Received: ${argn_value}")
+ endif ()
+
+ math(EXPR i "${i} + 1")
+ endwhile ()
+ else ()
+ message(STATUS "Unexpected: Lengths of arguments don't match")
+ message(STATUS " Expected: ${expected_len}")
+ message(STATUS " Received: ${argn_len}")
+ endif ()
+endfunction ()
+
+set(empty_test)
+message(STATUS "Test: Empty arguments")
+argument_tester(empty_test 0 ${empty_test})
+
+set(single_arg_test
+ "single arg")
+message(STATUS "Test: Single argument")
+argument_tester(single_arg_test 1 ${single_arg_test})
+
+set(multiple_arg_test
+ "first arg"
+ "second arg")
+message(STATUS "Test: Multiple arguments")
+argument_tester(multiple_arg_test 2 ${multiple_arg_test})
+
+set(nested_list_arg_test
+ "${multiple_arg_test}"
+ "first arg"
+ "second arg")
+message(STATUS "Test: Nested list argument flattens")
+argument_tester(nested_list_arg_test 4 ${nested_list_arg_test})
+
+set(semicolon_arg_test
+ "pre\;post")
+set(semicolon_arg_test_flat "pre;post")
+message(STATUS "Test: Semicolon argument flattens")
+argument_tester(semicolon_arg_test_flat 2 ${semicolon_arg_test})
diff --git a/Tests/Assembler/CMakeLists.txt b/Tests/Assembler/CMakeLists.txt
new file mode 100644
index 0000000000..fdc5c00210
--- /dev/null
+++ b/Tests/Assembler/CMakeLists.txt
@@ -0,0 +1,40 @@
+cmake_minimum_required (VERSION 2.6)
+project(Assembler C)
+message("CTEST_FULL_OUTPUT ")
+set(CMAKE_VERBOSE_MAKEFILE 1)
+
+set(SRCS)
+
+# (at least) the following toolchains can process assembler files directly
+# and also generate assembler files from C:
+if("${CMAKE_GENERATOR}" MATCHES "Makefile|Xcode" AND
+ NOT CMAKE_OSX_ARCHITECTURES)
+ if(("${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU|Clang|AppleClang|HP|SunPro|XL)$") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel" AND UNIX))
+ set(C_FLAGS "${CMAKE_C_FLAGS}")
+ separate_arguments(C_FLAGS)
+ if(CMAKE_OSX_SYSROOT AND CMAKE_C_SYSROOT_FLAG AND NOT ";${C_FLAGS};" MATCHES ";${CMAKE_C_SYSROOT_FLAG};")
+ list(APPEND C_FLAGS ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT})
+ endif()
+ # Clang on OS X, and perhaps other compilers, do not support -g
+ # for both generating and assembling, so drop it from generating.
+ list(REMOVE_ITEM C_FLAGS -g)
+ set(SRCS main.s)
+ add_custom_command(
+ OUTPUT main.s
+ COMMAND ${CMAKE_C_COMPILER} ${C_FLAGS} -S ${CMAKE_CURRENT_SOURCE_DIR}/main.c -o main.s
+ DEPENDS main.c
+ VERBATIM
+ )
+ endif()
+endif()
+
+
+if(SRCS)
+ set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}")
+ enable_language(ASM OPTIONAL)
+else()
+ message(STATUS "No assembler enabled, using C")
+ set(SRCS main.c)
+endif()
+
+add_executable(HelloAsm ${SRCS})
diff --git a/Tests/Assembler/main-linux-x86-gas.s b/Tests/Assembler/main-linux-x86-gas.s
new file mode 100644
index 0000000000..da8e845912
--- /dev/null
+++ b/Tests/Assembler/main-linux-x86-gas.s
@@ -0,0 +1,28 @@
+ .section .rodata
+ .align 4
+.LC0:
+ .string "hello assembler world, %d arguments given\n"
+ .text
+.globl main
+ .type main, @function
+main:
+ leal 4(%esp), %ecx
+ andl $-16, %esp
+ pushl -4(%ecx)
+ pushl %ebp
+ movl %esp, %ebp
+ pushl %ecx
+ subl $20, %esp
+ movl (%ecx), %eax
+ movl %eax, 4(%esp)
+ movl $.LC0, (%esp)
+ call printf
+ movl $0, %eax
+ addl $20, %esp
+ popl %ecx
+ popl %ebp
+ leal -4(%ecx), %esp
+ ret
+ .size main, .-main
+ .ident "GCC: (GNU) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)"
+ .section .note.GNU-stack,"",@progbits
diff --git a/Tests/Assembler/main.c b/Tests/Assembler/main.c
new file mode 100644
index 0000000000..95de0b5d1e
--- /dev/null
+++ b/Tests/Assembler/main.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+#ifdef __CLASSIC_C__
+int main(){
+ int argc;
+ char*argv[];
+#else
+int main(int argc, char*argv[]){
+#endif
+ printf("hello assembler world, %d arguments given\n", argc);
+ return 0;
+}
diff --git a/Tests/BootstrapTest.cmake b/Tests/BootstrapTest.cmake
new file mode 100644
index 0000000000..9c9fe09ac9
--- /dev/null
+++ b/Tests/BootstrapTest.cmake
@@ -0,0 +1,10 @@
+file(MAKE_DIRECTORY "${bin_dir}")
+message(STATUS "running bootstrap: ${bootstrap}")
+execute_process(
+ COMMAND ${bootstrap}
+ WORKING_DIRECTORY "${bin_dir}"
+ RESULT_VARIABLE result
+ )
+if(result)
+ message(FATAL_ERROR "bootstrap failed: ${result}")
+endif()
diff --git a/Tests/BuildDepends/CMakeLists.txt b/Tests/BuildDepends/CMakeLists.txt
new file mode 100644
index 0000000000..8df331e490
--- /dev/null
+++ b/Tests/BuildDepends/CMakeLists.txt
@@ -0,0 +1,325 @@
+# this test creates a static library and an executable
+# the source to the library is then changed
+# and the build is done on the executable and if things
+# are working the executable should relink with the new
+# value. The subdir Project contains the CMakelists.txt
+# and source files for the test project.
+cmake_minimum_required (VERSION 2.6)
+project(BuildDepends)
+
+# This entire test takes place during the initial
+# configure step. It should not run again when the
+# project is built.
+set(CMAKE_SUPPRESS_REGENERATION 1)
+
+# Xcode needs some help with the fancy dependencies in this test.
+if(XCODE AND XCODE_VERSION VERSION_LESS 5)
+ set(HELP_XCODE 1)
+endif()
+function(help_xcode_depends)
+ if(HELP_XCODE)
+ file(GLOB_RECURSE MACRO_OBJS
+ ${BuildDepends_BINARY_DIR}/Project/zot_macro_*.o*
+ )
+ if(MACRO_OBJS)
+ message("Helping Xcode by removing objects [${MACRO_OBJS}]")
+ file(REMOVE ${MACRO_OBJS})
+ endif()
+ endif()
+endfunction()
+
+if("${CMAKE_GENERATOR}" MATCHES "Ninja")
+ set(HELP_NINJA 1) # TODO Why is this needed?
+endif()
+
+# The Intel compiler causes the MSVC linker to crash during
+# incremental linking, so avoid the /INCREMENTAL:YES flag.
+if(WIN32 AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
+ set(_cmake_options "-DCMAKE_EXE_LINKER_FLAGS=")
+endif()
+
+if("${CMAKE_GENERATOR}" MATCHES "Make")
+ set(TEST_LINK_DEPENDS ${BuildDepends_BINARY_DIR}/Project/linkdep.txt)
+ file(WRITE ${TEST_LINK_DEPENDS} "1")
+endif()
+list(APPEND _cmake_options "-DTEST_LINK_DEPENDS=${TEST_LINK_DEPENDS}")
+
+list(APPEND _cmake_options "-DCMAKE_FORCE_DEPFILES=1")
+
+file(MAKE_DIRECTORY ${BuildDepends_BINARY_DIR}/Project)
+message("Creating Project/foo.cxx")
+write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
+ "const char* foo() { return \"foo\";}" )
+
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in
+ "static const char* zot = \"zot\";\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/dir/header.txt
+ "#define HEADER_STRING \"ninja\"\n" )
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_custom.hxx.in
+ "static const char* zot_custom = \"zot_custom\";\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
+ "static const char* zot_macro_dir = \"zot_macro_dir\";\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
+ "static const char* zot_macro_tgt = \"zot_macro_tgt\";\n")
+
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_lib.h
+ "#define link_depends_no_shared_lib_value 1\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_exe.h
+ "#define link_depends_no_shared_exe_value 0\n")
+set(link_depends_no_shared_check_txt ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_check.txt)
+
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/external.in "external original\n")
+
+help_xcode_depends()
+
+message("Building project first time")
+try_compile(RESULT
+ ${BuildDepends_BINARY_DIR}/Project
+ ${BuildDepends_SOURCE_DIR}/Project
+ testRebuild
+ CMAKE_FLAGS ${_cmake_options}
+ OUTPUT_VARIABLE OUTPUT)
+if(HELP_XCODE)
+ try_compile(RESULT
+ ${BuildDepends_BINARY_DIR}/Project
+ ${BuildDepends_SOURCE_DIR}/Project
+ testRebuild
+ OUTPUT_VARIABLE OUTPUT)
+ try_compile(RESULT
+ ${BuildDepends_BINARY_DIR}/Project
+ ${BuildDepends_SOURCE_DIR}/Project
+ testRebuild
+ OUTPUT_VARIABLE OUTPUT)
+endif()
+
+message("Output from first build:\n${OUTPUT}")
+if(NOT RESULT)
+ message(SEND_ERROR "Could not build test project (1)!")
+endif()
+
+# find and save the ninjadep executable
+set(ninjadep ${BuildDepends_BINARY_DIR}/Project/ninjadep${CMAKE_EXECUTABLE_SUFFIX})
+if(EXISTS
+ "${BuildDepends_BINARY_DIR}/Project/Debug/ninjadep${CMAKE_EXECUTABLE_SUFFIX}" )
+ message("found debug")
+ set(ninjadep
+ "${BuildDepends_BINARY_DIR}/Project/Debug/ninjadep${CMAKE_EXECUTABLE_SUFFIX}")
+endif()
+message("Running ${ninjadep} ")
+execute_process(COMMAND ${ninjadep} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
+string(REGEX REPLACE "[\r\n]" " " out "${out}")
+message("Run result: ${runResult} Output: \"${out}\"")
+
+if("${out}" STREQUAL "HEADER_STRING: ninja ")
+ message("Worked!")
+else()
+ message(SEND_ERROR "Project did not rebuild properly. Output[${out}]\n"
+ " expected [HEADER_STRING: ninja]")
+endif()
+
+set(bar ${BuildDepends_BINARY_DIR}/Project/bar${CMAKE_EXECUTABLE_SUFFIX})
+if(EXISTS
+ "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
+ message("found debug")
+ set(bar
+ "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
+endif()
+set(zot ${BuildDepends_BINARY_DIR}/Project/zot${CMAKE_EXECUTABLE_SUFFIX})
+if(EXISTS
+ "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
+ message("found debug")
+ set(zot
+ "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
+endif()
+
+message("Running ${bar} ")
+execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
+string(REGEX REPLACE "[\r\n]" " " out "${out}")
+message("Run result: ${runResult} Output: \"${out}\"")
+
+if("${out}" STREQUAL "foo ")
+ message("Worked!")
+else()
+ message(SEND_ERROR "Project did not initially build properly: ${out}")
+endif()
+
+message("Running ${zot} ")
+execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
+string(REGEX REPLACE "[\r\n]" " " out "${out}")
+message("Run result: ${runResult} Output: \"${out}\"")
+
+set(VALUE_UNCHANGED "[zot] [zot_custom] [zot_macro_dir] [zot_macro_tgt] ")
+if("${out}" STREQUAL "${VALUE_UNCHANGED}")
+ message("Worked!")
+else()
+ message(SEND_ERROR "Project did not initially build properly: ${out}")
+endif()
+
+if(EXISTS "${link_depends_no_shared_check_txt}")
+ file(STRINGS "${link_depends_no_shared_check_txt}" link_depends_no_shared_check LIMIT_COUNT 1)
+ if("${link_depends_no_shared_check}" STREQUAL "1")
+ message(STATUS "link_depends_no_shared_exe is newer than link_depends_no_shared_lib as expected.")
+ else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "link_depends_no_shared_exe is older than link_depends_no_shared_lib.")
+ endif()
+else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.")
+endif()
+
+if(EXISTS ${BuildDepends_BINARY_DIR}/Project/external.out)
+ file(STRINGS ${BuildDepends_BINARY_DIR}/Project/external.out external_out)
+ if("${external_out}" STREQUAL "external original")
+ message(STATUS "external.out contains '${external_out}'")
+ else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "external.out contains '${external_out}'")
+ endif()
+else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "external.out is missing")
+endif()
+
+message("Waiting 3 seconds...")
+execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 3)
+
+message("Modifying Project/foo.cxx")
+write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
+ "const char* foo() { return \"foo changed\";}" )
+file(WRITE "${BuildDepends_BINARY_DIR}/Project/dir/header.txt"
+ "#define HEADER_STRING \"ninja changed\"\n" )
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in
+ "static const char* zot = \"zot changed\";\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_custom.hxx.in
+ "static const char* zot_custom = \"zot_custom changed\";\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
+ "static const char* zot_macro_dir = \"zot_macro_dir changed\";\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
+ "static const char* zot_macro_tgt = \"zot_macro_tgt changed\";\n")
+
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_lib.h
+ "#define link_depends_no_shared_lib_value 0\n")
+
+if(TEST_LINK_DEPENDS)
+ file(WRITE ${TEST_LINK_DEPENDS} "2")
+endif()
+
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/external.in "external changed\n")
+
+help_xcode_depends()
+
+message("Building project second time")
+try_compile(RESULT
+ ${BuildDepends_BINARY_DIR}/Project
+ ${BuildDepends_SOURCE_DIR}/Project
+ testRebuild
+ CMAKE_FLAGS ${_cmake_options}
+ OUTPUT_VARIABLE OUTPUT)
+
+# Xcode is in serious need of help here
+if(HELP_XCODE OR HELP_NINJA)
+ try_compile(RESULT
+ ${BuildDepends_BINARY_DIR}/Project
+ ${BuildDepends_SOURCE_DIR}/Project
+ testRebuild
+ OUTPUT_VARIABLE OUTPUT)
+ try_compile(RESULT
+ ${BuildDepends_BINARY_DIR}/Project
+ ${BuildDepends_SOURCE_DIR}/Project
+ testRebuild
+ OUTPUT_VARIABLE OUTPUT)
+endif()
+
+message("Output from second build:\n${OUTPUT}")
+if(NOT RESULT)
+ message(SEND_ERROR "Could not build test project (2)!")
+endif()
+if(EXISTS
+ "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
+ message("found debug")
+endif()
+if(EXISTS
+ "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
+ message("found debug")
+endif()
+
+message("Running ${ninjadep} ")
+execute_process(COMMAND ${ninjadep} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
+string(REGEX REPLACE "[\r\n]" " " out "${out}")
+message("Run result: ${runResult} Output: \"${out}\"")
+
+if("${out}" STREQUAL "HEADER_STRING: ninja changed ")
+ message("Worked!")
+elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
+ # Tolerate failure because VS 6 does not seem to recompile ninjadep.cpp
+ # when the "dir/header.h" it includes changes.
+else()
+ message(SEND_ERROR "Project did not rebuild properly. Output[${out}]\n"
+ " expected [HEADER_STRING: ninja changed]")
+endif()
+
+message("Running ${bar} ")
+execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
+string(REGEX REPLACE "[\r\n]" " " out "${out}")
+message("Run result: ${runResult} Output: \"${out}\"")
+
+if("${out}" STREQUAL "foo changed ")
+ message("Worked!")
+else()
+ message(SEND_ERROR "Project did not rebuild properly!")
+endif()
+
+message("Running ${zot} ")
+execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
+string(REGEX REPLACE "[\r\n]" " " out "${out}")
+message("Run result: ${runResult} Output: \"${out}\"")
+
+set(VALUE_CHANGED
+ "[zot changed] [zot_custom changed] [zot_macro_dir changed] [zot_macro_tgt changed] "
+ )
+if("${out}" STREQUAL "${VALUE_CHANGED}")
+ message("Worked!")
+else()
+ message(SEND_ERROR "Project did not rebuild properly!")
+endif()
+
+if(TEST_LINK_DEPENDS)
+ set(linkdep ${BuildDepends_BINARY_DIR}/Project/linkdep${CMAKE_EXECUTABLE_SUFFIX})
+ if(${linkdep} IS_NEWER_THAN ${TEST_LINK_DEPENDS})
+ message("LINK_DEPENDS worked")
+ else()
+ message(SEND_ERROR "LINK_DEPENDS failed. Executable
+ ${linkdep}
+is not newer than dependency
+ ${TEST_LINK_DEPENDS}
+")
+ endif()
+endif()
+
+if(EXISTS "${link_depends_no_shared_check_txt}")
+ file(STRINGS "${link_depends_no_shared_check_txt}" link_depends_no_shared_check LIMIT_COUNT 1)
+ if("${link_depends_no_shared_check}" STREQUAL "0")
+ message(STATUS "link_depends_no_shared_exe is older than link_depends_no_shared_lib as expected.")
+ elseif(XCODE AND NOT XCODE_VERSION VERSION_LESS 5)
+ message(STATUS "Known limitation: link_depends_no_shared_exe is newer than link_depends_no_shared_lib but we cannot stop Xcode ${XCODE_VERSION} from enforcing this dependency.")
+ else()
+ message(SEND_ERROR "Project did not rebuild properly: link_depends_no_shared_exe is newer than link_depends_no_shared_lib.")
+ endif()
+else()
+ message(SEND_ERROR "Project did not rebuild properly. "
+ "Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.")
+endif()
+
+if(EXISTS ${BuildDepends_BINARY_DIR}/Project/external.out)
+ file(STRINGS ${BuildDepends_BINARY_DIR}/Project/external.out external_out)
+ if("${external_out}" STREQUAL "external changed")
+ message(STATUS "external.out contains '${external_out}'")
+ else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "external.out contains '${external_out}'")
+ endif()
+else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "external.out is missing")
+endif()
diff --git a/Tests/BuildDepends/Project/CMakeLists.txt b/Tests/BuildDepends/Project/CMakeLists.txt
new file mode 100644
index 0000000000..9ee4a43aac
--- /dev/null
+++ b/Tests/BuildDepends/Project/CMakeLists.txt
@@ -0,0 +1,153 @@
+cmake_minimum_required(VERSION 2.6)
+project(testRebuild)
+
+function(test_for_xcode4 result_var)
+ set(${result_var} 0 PARENT_SCOPE)
+ if(APPLE)
+ execute_process(COMMAND xcodebuild -version
+ OUTPUT_VARIABLE ov RESULT_VARIABLE rv
+ )
+ if("${rv}" STREQUAL "0" AND ov MATCHES "^Xcode ([0-9]+)\\.")
+ if(NOT CMAKE_MATCH_1 VERSION_LESS 4)
+ set(${result_var} 1 PARENT_SCOPE)
+ endif()
+ endif()
+ endif()
+endfunction()
+
+if(APPLE)
+ # only use multi-arch if the sysroot exists on this machine
+ # Ninja needs -M which could not be used with multiple -arch flags
+ if(EXISTS "${CMAKE_OSX_SYSROOT}" AND NOT "${CMAKE_GENERATOR}" MATCHES "Ninja")
+ set(CMAKE_OSX_ARCHITECTURES "ppc;i386")
+ test_for_xcode4(is_xcode4)
+ if(is_xcode4)
+ # Xcode 4, use modern architectures as defaults
+ # Arch 'ppc' no longer works: tools no longer available starting with Xcode 4
+ set(CMAKE_OSX_ARCHITECTURES i386 x86_64)
+ endif()
+ endif()
+endif()
+
+add_library(foo STATIC ${testRebuild_BINARY_DIR}/foo.cxx)
+set_target_properties(foo PROPERTIES OUTPUT_NAME "foolib")
+# Add a generated header that regenerates when the generator is
+# rebuilt.
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/regen.h
+ COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/regen.h regen
+ DEPENDS generator # adds file-level dependency to re-run rule
+ )
+
+# Add a generated header that does NOT regenerate when the generator
+# is rebuilt.
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
+ COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/noregen.h noregen
+ )
+
+# Test that the generator rebuilds when the static library source file
+# changes. This should cause regen.h to be recreated also.
+add_executable(generator generator.cxx)
+target_link_libraries(generator foo)
+set_target_properties(generator PROPERTIES OUTPUT_NAME "gen")
+
+# Build an executable to drive the build and rebuild.
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+add_executable(bar bar.cxx
+ ${CMAKE_CURRENT_BINARY_DIR}/regen.h
+ ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
+ )
+
+#-----------------------------------------------------------------------------
+if("${CMAKE_GENERATOR}" MATCHES "Make")
+ # Test the IMPLICIT_DEPENDS feature.
+ set(ZOT_DEPENDS IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep.cxx)
+ set(ZOT_CUSTOM_DEP
+ IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep_custom.cxx
+ CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep_custom2.cxx )
+else()
+ # No IMPLICIT_DEPENDS...just depend directly.
+ set(ZOT_DEPENDS DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in)
+ set(ZOT_CUSTOM_DEP DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in)
+endif()
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in
+ ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
+ ${ZOT_DEPENDS}
+ )
+
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in
+ ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
+ ${ZOT_CUSTOM_DEP}
+ )
+add_custom_target(zot_custom ALL DEPENDS
+ ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx)
+
+add_executable(zot zot.cxx ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
+ zot_macro_dir.cxx zot_macro_tgt.cxx)
+add_dependencies(zot zot_custom)
+
+# Test the #include line macro transformation rule support.
+set_property(
+ TARGET zot
+ PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_TGT(%)=<zot_%_tgt.hxx>"
+ )
+
+set_property(
+ DIRECTORY
+ PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_DIR(%)=<zot_%_dir.hxx>"
+ )
+
+if(TEST_LINK_DEPENDS)
+ add_executable(linkdep linkdep.cxx)
+ set_property(TARGET linkdep PROPERTY LINK_DEPENDS ${TEST_LINK_DEPENDS})
+endif()
+
+add_library(link_depends_no_shared_lib SHARED link_depends_no_shared_lib.c
+ ${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_lib.h)
+add_executable(link_depends_no_shared_exe link_depends_no_shared_exe.c
+ ${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_exe.h)
+target_link_libraries(link_depends_no_shared_exe link_depends_no_shared_lib)
+set_property(TARGET link_depends_no_shared_exe PROPERTY LINK_DEPENDS_NO_SHARED 1)
+add_custom_target(link_depends_no_shared_check ALL
+ COMMAND ${CMAKE_COMMAND}
+ -Dlib=$<TARGET_FILE:link_depends_no_shared_lib>
+ -Dexe=$<TARGET_FILE:link_depends_no_shared_exe>
+ -Dout=${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_check.txt
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/link_depends_no_shared_check.cmake
+ )
+add_dependencies(link_depends_no_shared_check link_depends_no_shared_exe)
+
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dir/header.h
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/dir/header.txt
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${CMAKE_CURRENT_BINARY_DIR}/dir/header.txt
+ ${CMAKE_CURRENT_BINARY_DIR}/dir/header.h
+ )
+
+set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/dir/header.h
+ PROPERTIES GENERATED 1)
+
+add_custom_target(header_tgt DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/dir/header.h)
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+add_executable(ninjadep ninjadep.cpp)
+add_dependencies(ninjadep header_tgt)
+
+include(ExternalProject)
+ExternalProject_Add(ExternalBuild
+ SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/External
+ BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/External
+ STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/External/Stamp
+ BUILD_ALWAYS 1
+ CMAKE_ARGS
+ -Dexternal_in=${CMAKE_CURRENT_BINARY_DIR}/external.in
+ -Dexternal_out=${CMAKE_CURRENT_BINARY_DIR}/external.out
+ INSTALL_COMMAND ""
+ )
diff --git a/Tests/BuildDepends/Project/External/CMakeLists.txt b/Tests/BuildDepends/Project/External/CMakeLists.txt
new file mode 100644
index 0000000000..c6015b6510
--- /dev/null
+++ b/Tests/BuildDepends/Project/External/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.0)
+project(BuildDependsExternal NONE)
+if(NOT DEFINED external_in)
+ message(FATAL_ERROR "Define external_in")
+endif()
+if(NOT DEFINED external_out)
+ message(FATAL_ERROR "Define external_out")
+endif()
+add_custom_command(
+ OUTPUT ${external_out}
+ COMMAND ${CMAKE_COMMAND} -E copy ${external_in} ${external_out}
+ DEPENDS ${external_in}
+ )
+add_custom_target(drive ALL DEPENDS ${external_out})
diff --git a/Tests/BuildDepends/Project/bar.cxx b/Tests/BuildDepends/Project/bar.cxx
new file mode 100644
index 0000000000..dadf93d6b9
--- /dev/null
+++ b/Tests/BuildDepends/Project/bar.cxx
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <string.h>
+#include <regen.h>
+#include <noregen.h>
+
+int main(int argc, char** argv)
+{
+ /* Make sure the noregen header was not regenerated. */
+ if(strcmp("foo", noregen_string) != 0)
+ {
+ printf("FAILED: noregen.h was regenerated!\n");
+ return 1;
+ }
+
+ /* Print out the string that should have been regenerated. */
+ printf("%s\n", regen_string);
+ fflush(stdout);
+ return 0;
+}
diff --git a/Tests/BuildDepends/Project/dep.cxx b/Tests/BuildDepends/Project/dep.cxx
new file mode 100644
index 0000000000..6cfebe37ca
--- /dev/null
+++ b/Tests/BuildDepends/Project/dep.cxx
@@ -0,0 +1 @@
+#include <zot.hxx.in>
diff --git a/Tests/BuildDepends/Project/dep_custom.cxx b/Tests/BuildDepends/Project/dep_custom.cxx
new file mode 100644
index 0000000000..b6ac54847b
--- /dev/null
+++ b/Tests/BuildDepends/Project/dep_custom.cxx
@@ -0,0 +1 @@
+#include <zot_custom.hxx.in>
diff --git a/Tests/BuildDepends/Project/dep_custom2.cxx b/Tests/BuildDepends/Project/dep_custom2.cxx
new file mode 100644
index 0000000000..ac9dee120f
--- /dev/null
+++ b/Tests/BuildDepends/Project/dep_custom2.cxx
@@ -0,0 +1,2 @@
+#include <zot_custom.hxx.in>
+// some comment
diff --git a/Tests/BuildDepends/Project/generator.cxx b/Tests/BuildDepends/Project/generator.cxx
new file mode 100644
index 0000000000..92a122de86
--- /dev/null
+++ b/Tests/BuildDepends/Project/generator.cxx
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+extern const char* foo();
+
+int main(int argc, const char* argv[])
+{
+ if(argc < 3)
+ {
+ fprintf(stderr, "Must specify output file and symbol prefix!");
+ return 1;
+ }
+ if(FILE* fout = fopen(argv[1], "w"))
+ {
+ fprintf(fout, "static const char* %s_string = \"%s\";\n", argv[2],
+ foo());
+ fclose(fout);
+ }
+ else
+ {
+ fprintf(stderr, "Could not open output file \"%s\"", argv[1]);
+ return 1;
+ }
+ return 0;
+}
diff --git a/Tests/BuildDepends/Project/link_depends_no_shared_check.cmake b/Tests/BuildDepends/Project/link_depends_no_shared_check.cmake
new file mode 100644
index 0000000000..3a611370f5
--- /dev/null
+++ b/Tests/BuildDepends/Project/link_depends_no_shared_check.cmake
@@ -0,0 +1,7 @@
+if(NOT EXISTS "${lib}" OR NOT EXISTS "${exe}")
+ file(REMOVE "${out}")
+elseif("${exe}" IS_NEWER_THAN "${lib}")
+ file(WRITE "${out}" "1\n")
+else()
+ file(WRITE "${out}" "0\n")
+endif()
diff --git a/Tests/BuildDepends/Project/link_depends_no_shared_exe.c b/Tests/BuildDepends/Project/link_depends_no_shared_exe.c
new file mode 100644
index 0000000000..e9113a21d9
--- /dev/null
+++ b/Tests/BuildDepends/Project/link_depends_no_shared_exe.c
@@ -0,0 +1,9 @@
+#include "link_depends_no_shared_exe.h"
+#ifdef _WIN32
+__declspec(dllimport)
+#endif
+int link_depends_no_shared_lib(void);
+int main()
+{
+ return link_depends_no_shared_lib() + link_depends_no_shared_exe_value;
+}
diff --git a/Tests/BuildDepends/Project/link_depends_no_shared_lib.c b/Tests/BuildDepends/Project/link_depends_no_shared_lib.c
new file mode 100644
index 0000000000..d2262894b9
--- /dev/null
+++ b/Tests/BuildDepends/Project/link_depends_no_shared_lib.c
@@ -0,0 +1,8 @@
+#include "link_depends_no_shared_lib.h"
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int link_depends_no_shared_lib(void)
+{
+ return link_depends_no_shared_lib_value;
+}
diff --git a/Tests/BuildDepends/Project/linkdep.cxx b/Tests/BuildDepends/Project/linkdep.cxx
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/BuildDepends/Project/linkdep.cxx
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/BuildDepends/Project/ninjadep.cpp b/Tests/BuildDepends/Project/ninjadep.cpp
new file mode 100644
index 0000000000..8d61336137
--- /dev/null
+++ b/Tests/BuildDepends/Project/ninjadep.cpp
@@ -0,0 +1,6 @@
+#include <stdio.h>
+#include "dir/header.h"
+
+int main() {
+ printf("HEADER_STRING: %s\n", HEADER_STRING);
+}
diff --git a/Tests/BuildDepends/Project/zot.cxx b/Tests/BuildDepends/Project/zot.cxx
new file mode 100644
index 0000000000..775fd3b438
--- /dev/null
+++ b/Tests/BuildDepends/Project/zot.cxx
@@ -0,0 +1,14 @@
+#include <zot.hxx>
+#include <zot_custom.hxx>
+#include <stdio.h>
+
+const char* zot_macro_dir_f();
+const char* zot_macro_tgt_f();
+
+int main()
+{
+ printf("[%s] [%s] [%s] [%s]\n", zot, zot_custom,
+ zot_macro_dir_f(), zot_macro_tgt_f());
+ fflush(stdout);
+ return 0;
+}
diff --git a/Tests/BuildDepends/Project/zot_macro_dir.cxx b/Tests/BuildDepends/Project/zot_macro_dir.cxx
new file mode 100644
index 0000000000..733a4b37f3
--- /dev/null
+++ b/Tests/BuildDepends/Project/zot_macro_dir.cxx
@@ -0,0 +1,7 @@
+#define ZOT_DIR(x) <zot_##x##_dir.hxx>
+#include ZOT_DIR(macro)
+
+const char* zot_macro_dir_f()
+{
+ return zot_macro_dir;
+}
diff --git a/Tests/BuildDepends/Project/zot_macro_tgt.cxx b/Tests/BuildDepends/Project/zot_macro_tgt.cxx
new file mode 100644
index 0000000000..182ee16fd0
--- /dev/null
+++ b/Tests/BuildDepends/Project/zot_macro_tgt.cxx
@@ -0,0 +1,7 @@
+#define ZOT_TGT(x) <zot_##x##_tgt.hxx>
+#include ZOT_TGT(macro)
+
+const char* zot_macro_tgt_f()
+{
+ return zot_macro_tgt;
+}
diff --git a/Tests/BundleGeneratorTest/BundleIcon.icns b/Tests/BundleGeneratorTest/BundleIcon.icns
new file mode 100644
index 0000000000..8808dd62db
--- /dev/null
+++ b/Tests/BundleGeneratorTest/BundleIcon.icns
Binary files differ
diff --git a/Tests/BundleGeneratorTest/CMakeLists.txt b/Tests/BundleGeneratorTest/CMakeLists.txt
new file mode 100644
index 0000000000..037df09c12
--- /dev/null
+++ b/Tests/BundleGeneratorTest/CMakeLists.txt
@@ -0,0 +1,33 @@
+project(BundleGeneratorTest)
+
+cmake_minimum_required(VERSION 2.7)
+
+# Build a shared library and install it in lib/
+add_library(Library SHARED Library.cxx)
+install(TARGETS Library DESTINATION lib)
+
+# Build an executable and install it in bin/
+add_executable(Executable Executable.cxx)
+target_link_libraries(Executable Library)
+install(TARGETS Executable DESTINATION bin)
+
+# Use the bundle-generator for packaging ...
+set(CPACK_GENERATOR "Bundle")
+set(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/BundleIcon.icns")
+set(CPACK_BUNDLE_NAME "BundleGeneratorTest")
+set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist")
+set(CPACK_BUNDLE_STARTUP_COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/StartupCommand")
+set(CPACK_PACKAGE_DESCRIPTION "Project for testing OSX bundle generation")
+
+# The custom volume icon is a copy of the normal Mac OSX volume icon, but
+# on a white background. This is to differentiate it from the normal one
+# so that you can verify that the custom icon is being used by doing a
+# visual inspection of the mounted volume... This was added when fixing
+# issue #7523...
+#
+set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/CustomVolumeIcon.icns")
+
+set(CPACK_PACKAGE_NAME "BundleGeneratorTest")
+set(CPACK_PACKAGE_VERSION "0.1")
+
+include(CPack)
diff --git a/Tests/BundleGeneratorTest/CustomVolumeIcon.icns b/Tests/BundleGeneratorTest/CustomVolumeIcon.icns
new file mode 100644
index 0000000000..3862a51917
--- /dev/null
+++ b/Tests/BundleGeneratorTest/CustomVolumeIcon.icns
Binary files differ
diff --git a/Tests/BundleGeneratorTest/Executable.cxx b/Tests/BundleGeneratorTest/Executable.cxx
new file mode 100644
index 0000000000..8107f783a8
--- /dev/null
+++ b/Tests/BundleGeneratorTest/Executable.cxx
@@ -0,0 +1,8 @@
+extern void print_message(const char* const Message);
+
+int main(int argc, char* argv[])
+{
+ print_message("Howdy, World!\n");
+ return 0;
+}
+
diff --git a/Tests/BundleGeneratorTest/Info.plist b/Tests/BundleGeneratorTest/Info.plist
new file mode 100644
index 0000000000..e5a7d0047a
--- /dev/null
+++ b/Tests/BundleGeneratorTest/Info.plist
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+ <key>CFBundleExecutable</key>
+ <string>BundleGeneratorTest</string>
+ <key>CFBundleIconFile</key>
+ <string>BundleGeneratorTest.icns</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ </dict>
+</plist>
diff --git a/Tests/BundleGeneratorTest/Library.cxx b/Tests/BundleGeneratorTest/Library.cxx
new file mode 100644
index 0000000000..1403c68246
--- /dev/null
+++ b/Tests/BundleGeneratorTest/Library.cxx
@@ -0,0 +1,7 @@
+#include <iostream>
+
+void print_message(const char* const Message)
+{
+ std::cout << Message;
+}
+
diff --git a/Tests/BundleGeneratorTest/StartupCommand b/Tests/BundleGeneratorTest/StartupCommand
new file mode 100755
index 0000000000..5bc5ad2370
--- /dev/null
+++ b/Tests/BundleGeneratorTest/StartupCommand
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+BUNDLE="`echo "$0" | sed -e 's/\/Contents\/MacOS\/.*//'`"
+RESOURCES="$BUNDLE/Contents/Resources"
+
+echo "BUNDLE: $BUNDLE"
+echo "RESOURCES: $RESOURCES"
+
+export DYLD_LIBRARY_PATH=$RESOURCES/lib
+
+exec "$RESOURCES/bin/Executable"
+
diff --git a/Tests/BundleTest/BundleLib.cxx b/Tests/BundleTest/BundleLib.cxx
new file mode 100644
index 0000000000..37bc178d63
--- /dev/null
+++ b/Tests/BundleTest/BundleLib.cxx
@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+
+int fileExists(char* filename)
+{
+#ifndef R_OK
+# define R_OK 04
+#endif
+ if ( access(filename, R_OK) != 0 )
+ {
+ printf("Cannot find file: %s\n", filename);
+ return 0;
+ }
+ return 1;
+}
+
+int findBundleFile(char* exec, const char* file)
+{
+ int res;
+ char* nexec = strdup(exec);
+ char* fpath = (char*)malloc(strlen(exec) + 100);
+ int cc;
+ int cnt = 0;
+ printf("Process executable name: %s\n", exec);
+
+ // Remove the executable name and directory name
+ for ( cc = strlen(nexec)-1; cc > 0; cc -- )
+ {
+ if ( nexec[cc] == '/' )
+ {
+ nexec[cc] = 0;
+ if ( cnt == 1 )
+ {
+ break;
+ }
+ cnt ++;
+ }
+ }
+ printf("Process executable path: %s\n", nexec);
+ sprintf(fpath, "%s/%s", nexec, file);
+ printf("Check for file: %s\n", fpath);
+ res = fileExists(fpath);
+ free(nexec);
+ free(fpath);
+ return res;
+}
+
+int foo(char *exec)
+{
+ // Call a CoreFoundation function...
+ //
+ CFBundleRef br = CFBundleGetMainBundle();
+ (void) br;
+
+ int res1 = findBundleFile(exec, "Resources/randomResourceFile.plist");
+ int res2 = findBundleFile(exec, "MacOS/SomeRandomFile.txt");
+ int res3 = findBundleFile(exec, "MacOS/README.rst");
+ if ( !res1 ||
+ !res2 ||
+ !res3 )
+ {
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/Tests/BundleTest/BundleSubDir/CMakeLists.txt b/Tests/BundleTest/BundleSubDir/CMakeLists.txt
new file mode 100644
index 0000000000..43c366a09d
--- /dev/null
+++ b/Tests/BundleTest/BundleSubDir/CMakeLists.txt
@@ -0,0 +1,36 @@
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ COMMAND /bin/cp
+ ARGS "${BundleTest_SOURCE_DIR}/randomResourceFile.plist.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist")
+
+set_source_files_properties(
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ PROPERTIES
+ MACOSX_PACKAGE_LOCATION Resources
+ )
+
+set_source_files_properties(
+ "${BundleTest_SOURCE_DIR}/SomeRandomFile.txt"
+ "${BundleTest_SOURCE_DIR}/../../README.rst"
+ PROPERTIES
+ MACOSX_PACKAGE_LOCATION MacOS
+ )
+
+add_executable(SecondBundle
+ MACOSX_BUNDLE
+ "${BundleTest_SOURCE_DIR}/BundleTest.cxx"
+ "${BundleTest_SOURCE_DIR}/SomeRandomFile.txt"
+ "${BundleTest_SOURCE_DIR}/../../README.rst"
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ )
+target_link_libraries(SecondBundle BundleTestLib)
+
+# Test bundle installation.
+install(TARGETS SecondBundle DESTINATION Applications)
+
+# Test whether bundles respect the output name. Since the library is
+# installed into a location that uses this output name this will fail if the
+# bundle does not respect the name. Also the executable will not be found by
+# the test driver if this does not work.
+set_target_properties(SecondBundle PROPERTIES OUTPUT_NAME SecondBundleExe)
diff --git a/Tests/BundleTest/BundleTest.cxx b/Tests/BundleTest/BundleTest.cxx
new file mode 100644
index 0000000000..a66d601d38
--- /dev/null
+++ b/Tests/BundleTest/BundleTest.cxx
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+
+extern int foo(char* exec);
+
+int main(int argc, char* argv[])
+{
+ printf("Started with: %d arguments\n", argc);
+
+ // Call a CoreFoundation function... but pull in the link dependency on "-framework
+ // CoreFoundation" via CMake's dependency chaining mechanism. This code exists to
+ // verify that the chaining mechanism works with "-framework blah" style
+ // link dependencies.
+ //
+ CFBundleRef br = CFBundleGetMainBundle();
+ (void) br;
+
+ return foo(argv[0]);
+}
diff --git a/Tests/BundleTest/CMakeLists.txt b/Tests/BundleTest/CMakeLists.txt
new file mode 100644
index 0000000000..853da35383
--- /dev/null
+++ b/Tests/BundleTest/CMakeLists.txt
@@ -0,0 +1,104 @@
+cmake_minimum_required (VERSION 2.6)
+project(BundleTest)
+set(MACOSX_BUNDLE_INFO_STRING "bundle_info_string")
+set(CMAKE_MacOSX_Content_COMPILE_OBJECT "\"${CMAKE_COMMAND}\" -E copy_if_different <SOURCE> <OBJECT>")
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ COMMAND /bin/cp
+ ARGS "${CMAKE_CURRENT_SOURCE_DIR}/randomResourceFile.plist.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist")
+
+set_source_files_properties(
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ PROPERTIES
+ MACOSX_PACKAGE_LOCATION Resources
+ )
+
+set_source_files_properties(
+ SomeRandomFile.txt
+ "${BundleTest_SOURCE_DIR}/../../README.rst"
+ PROPERTIES
+ MACOSX_PACKAGE_LOCATION MacOS
+ )
+
+set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/foobar")
+
+# Test building a bundle linking to a shared library where the
+# shared library links to CoreFoundation, but the executable does not
+# explicitly link to CoreFoundation, but the executable does *depend*
+# on CoreFoundation. There should be a link failure for the executable
+# if CMake's dependency chaining for libraries with "-framework
+# blah" style dependencies gets broken...
+#
+add_library(BundleTestLib SHARED BundleLib.cxx)
+target_link_libraries(BundleTestLib "-framework CoreFoundation")
+
+add_executable(BundleTest
+ MACOSX_BUNDLE
+ BundleTest.cxx
+ SomeRandomFile.txt
+ "${BundleTest_SOURCE_DIR}/../../README.rst"
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ )
+target_link_libraries(BundleTest BundleTestLib)
+#
+# DO NOT: target_link_libraries(BundleTest "-framework CoreFoundation")
+# (see above comments about CoreFoundation)
+#
+
+# Test bundle installation.
+#install(TARGETS BundleTestLib DESTINATION Applications/BundleTestExe.app/Contents/Plugins)
+install(TARGETS BundleTestLib DESTINATION Applications/SecondBundleExe.app/Contents/Plugins)
+install(TARGETS BundleTest DESTINATION Applications)
+
+# Test whether bundles respect the output name. Since the library is
+# installed into a location that uses this output name this will fail if the
+# bundle does not respect the name. Also the executable will not be found by
+# the test driver if this does not work.
+set_target_properties(BundleTest PROPERTIES OUTPUT_NAME BundleTestExe)
+
+# Test executable versioning if it is supported.
+if(NOT XCODE)
+ set_target_properties(BundleTest PROPERTIES VERSION 1)
+endif()
+
+# Make sure the executable can find its installed library.
+set_target_properties(BundleTestLib PROPERTIES
+ INSTALL_NAME_DIR "@executable_path/../Plugins")
+
+include(CPack)
+
+# test the framework find stuff
+if(EXISTS /usr/lib/libtcl.dylib
+ AND EXISTS /System/Library/Frameworks/Tcl.framework)
+ set(TCL NOTFOUND)
+ find_library(TCL tcl)
+ message("frame: ${TCL}")
+ if(NOT "${TCL}" MATCHES .framework)
+ message(FATAL_ERROR "Could not find tcl framework, found ${TCL}")
+ endif()
+ set(TCL NOTFOUND)
+ set(CMAKE_FIND_FRAMEWORK LAST)
+ find_library(TCL tcl)
+ if("${TCL}" MATCHES .framework)
+ message(FATAL_ERROR "Found framework and should have found dylib ${TCL}")
+ endif()
+ set(TCL NOTFOUND)
+ set(CMAKE_FIND_FRAMEWORK NEVER)
+ find_library(TCL tcl)
+ if("${TCL}" MATCHES .framework)
+ message(FATAL_ERROR "Found framework and should have found dylib ${TCL}")
+ endif()
+ message("not frame: ${TCL}")
+ set(TCL NOTFOUND)
+ set(CMAKE_FIND_FRAMEWORK FIRST)
+ find_library(TCL tcl)
+ if(NOT "${TCL}" MATCHES .framework)
+ message(FATAL_ERROR "Could not find tcl framework, found ${TCL}")
+ endif()
+ message("frame: ${TCL}")
+endif(EXISTS /usr/lib/libtcl.dylib
+ AND EXISTS /System/Library/Frameworks/Tcl.framework)
+
+subdirs(BundleSubDir)
diff --git a/Tests/BundleTest/SomeRandomFile.txt b/Tests/BundleTest/SomeRandomFile.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/BundleTest/SomeRandomFile.txt
diff --git a/Tests/BundleTest/randomResourceFile.plist.in b/Tests/BundleTest/randomResourceFile.plist.in
new file mode 100644
index 0000000000..cfe3222b68
--- /dev/null
+++ b/Tests/BundleTest/randomResourceFile.plist.in
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Package</key>
+ <string>CMake</string>
+</dict>
+</plist>
+
diff --git a/Tests/BundleUtilities/CMakeLists.txt b/Tests/BundleUtilities/CMakeLists.txt
new file mode 100644
index 0000000000..69ef535051
--- /dev/null
+++ b/Tests/BundleUtilities/CMakeLists.txt
@@ -0,0 +1,127 @@
+cmake_minimum_required(VERSION 2.8)
+project(BundleUtilities)
+
+###### the various types of dependencies we can have
+
+# a shared library
+add_library(shared SHARED shared.cpp shared.h)
+
+# another shared library
+add_library(shared2 SHARED shared2.cpp shared2.h)
+
+
+# a framework library
+add_library(framework SHARED framework.cpp framework.h)
+set_target_properties(framework PROPERTIES FRAMEWORK 1)
+
+# make sure rpaths are not helping BundleUtilities or the executables
+set_target_properties(shared shared2 framework PROPERTIES
+ SKIP_BUILD_RPATH 1)
+
+
+###### test a Bundle application using dependencies
+
+# a loadable module (depends on shared2)
+# testbundleutils1 will load this at runtime
+add_library(module1 MODULE module.cpp module.h)
+set_target_properties(module1 PROPERTIES PREFIX "")
+target_link_libraries(module1 shared2)
+
+# a bundle application
+add_executable(testbundleutils1 MACOSX_BUNDLE testbundleutils1.cpp)
+target_link_libraries(testbundleutils1 shared framework ${CMAKE_DL_LIBS})
+
+set_target_properties(testbundleutils1 module1 PROPERTIES
+ INSTALL_RPATH "${CMAKE_CURRENT_BINARY_DIR}/testdir1"
+ BUILD_WITH_INSTALL_RPATH 1)
+
+# add custom target to install and test the app
+add_custom_target(testbundleutils1_test ALL
+ COMMAND ${CMAKE_COMMAND}
+ "-DINPUT=$<TARGET_FILE:testbundleutils1>"
+ "-DMODULE=$<TARGET_FILE:module1>"
+ "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
+ "-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir1"
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake"
+ DEPENDS testbundleutils1 module1
+ )
+
+add_dependencies(testbundleutils1_test testbundleutils1)
+
+
+
+###### test a non-Bundle application using dependencies
+
+# a loadable module (depends on shared2)
+# testbundleutils2 will load this at runtime
+add_library(module2 MODULE module.cpp module.h)
+set_target_properties(module2 PROPERTIES PREFIX "")
+target_link_libraries(module2 shared2)
+
+# a non-bundle application
+add_executable(testbundleutils2 testbundleutils2.cpp)
+target_link_libraries(testbundleutils2 shared framework ${CMAKE_DL_LIBS})
+
+set_target_properties(testbundleutils2 module2 PROPERTIES
+ INSTALL_RPATH "${CMAKE_CURRENT_BINARY_DIR}/testdir2"
+ BUILD_WITH_INSTALL_RPATH 1)
+
+# add custom target to install and test the app
+add_custom_target(testbundleutils2_test ALL
+ COMMAND ${CMAKE_COMMAND}
+ "-DINPUT=$<TARGET_FILE:testbundleutils2>"
+ "-DMODULE=$<TARGET_FILE:module2>"
+ "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
+ "-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir2"
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake"
+ DEPENDS testbundleutils1 module2
+ )
+add_dependencies(testbundleutils2_test testbundleutils2)
+
+
+if(APPLE AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS 9.0)
+###### Test a Bundle application using dependencies
+###### and @rpaths on Mac OS X 10.5 or greater
+
+ # a shared library
+ add_library(shared-3 SHARED shared.cpp shared.h)
+
+ # another shared library
+ add_library(shared2-3 SHARED shared2.cpp shared2.h)
+
+ # a framework library
+ add_library(framework-3 SHARED framework.cpp framework.h)
+ set_target_properties(framework-3 PROPERTIES FRAMEWORK 1)
+
+ # build dependencies with @rpath install name
+ set_target_properties(shared-3 shared2-3 framework-3 PROPERTIES
+ INSTALL_NAME_DIR "@rpath"
+ BUILD_WITH_INSTALL_RPATH 1)
+
+ # a loadable module (depends on shared2)
+ # testbundleutils1 will load this at runtime
+ add_library(module3 MODULE module.cpp module.h)
+ set_target_properties(module3 PROPERTIES PREFIX "" LINK_FLAGS "-Wl,-rpath,@loader_path/")
+ target_link_libraries(module3 shared2-3)
+
+ # a non-bundle application
+ add_executable(testbundleutils3 testbundleutils3.cpp)
+ target_link_libraries(testbundleutils3 shared-3 framework-3 ${CMAKE_DL_LIBS})
+
+ set_target_properties(testbundleutils3 module3 PROPERTIES
+ LINK_FLAGS "-Wl,-rpath,@loader_path/"
+ BUILD_WITH_INSTALL_RPATH 1)
+
+ # add custom target to install and test the app
+ add_custom_target(testbundleutils3_test ALL
+ COMMAND ${CMAKE_COMMAND}
+ "-DINPUT=$<TARGET_FILE:testbundleutils3>"
+ "-DMODULE=$<TARGET_FILE:module3>"
+ "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
+ "-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir3"
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake"
+ DEPENDS testbundleutils3 module3
+ )
+
+ add_dependencies(testbundleutils3_test testbundleutils3)
+endif()
diff --git a/Tests/BundleUtilities/bundleutils.cmake b/Tests/BundleUtilities/bundleutils.cmake
new file mode 100644
index 0000000000..cc89347ade
--- /dev/null
+++ b/Tests/BundleUtilities/bundleutils.cmake
@@ -0,0 +1,45 @@
+
+# clean passed in arguments
+get_filename_component(INPUT ${INPUT} ABSOLUTE)
+get_filename_component(INPUTDIR ${INPUTDIR} ABSOLUTE)
+
+message("INPUT = ${INPUT}")
+message("MODULE = ${MODULE}")
+message("INPUTDIR = ${INPUTDIR}")
+message("OUTPUTDIR = ${OUTPUTDIR}")
+
+# compute location to install/test things
+file(RELATIVE_PATH relative_exe "${INPUTDIR}" "${INPUT}")
+set(OUTPUT "${OUTPUTDIR}/${relative_exe}")
+message("OUTPUT = ${OUTPUT}")
+get_filename_component(EXE_DIR "${OUTPUT}" PATH)
+get_filename_component(MODULE_NAME "${MODULE}" NAME)
+set(OUTPUT_MODULE "${EXE_DIR}/${MODULE_NAME}")
+message("OUTPUTMODULE = ${OUTPUT_MODULE}")
+
+# clean output dir
+file(REMOVE_RECURSE "${OUTPUTDIR}")
+# copy the app and plugin to installation/testing directory
+configure_file("${INPUT}" "${OUTPUT}" COPYONLY)
+configure_file("${MODULE}" "${OUTPUT_MODULE}" COPYONLY)
+
+# have BundleUtilities grab all dependencies and
+# check that the app runs
+
+# for this test we'll override location to put all dependencies
+# (in the same dir as the app)
+# this shouldn't be necessary except for the non-bundle case on Mac
+function(gp_item_default_embedded_path_override item path)
+ set(path "@executable_path" PARENT_SCOPE)
+endfunction()
+
+include(BundleUtilities)
+fixup_bundle("${OUTPUT}" "${OUTPUT_MODULE}" "${INPUTDIR}")
+
+# make sure we can run the app
+message("Executing ${OUTPUT} in ${EXE_DIR}")
+execute_process(COMMAND "${OUTPUT}" RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE out WORKING_DIRECTORY "${EXE_DIR}")
+
+if(NOT result STREQUAL "0")
+ message(FATAL_ERROR " failed to execute test program\n${out}")
+endif()
diff --git a/Tests/BundleUtilities/framework.cpp b/Tests/BundleUtilities/framework.cpp
new file mode 100644
index 0000000000..abda195edb
--- /dev/null
+++ b/Tests/BundleUtilities/framework.cpp
@@ -0,0 +1,8 @@
+
+#include "framework.h"
+#include "stdio.h"
+
+void framework()
+{
+ printf("framework\n");
+}
diff --git a/Tests/BundleUtilities/framework.h b/Tests/BundleUtilities/framework.h
new file mode 100644
index 0000000000..bdd10f05d6
--- /dev/null
+++ b/Tests/BundleUtilities/framework.h
@@ -0,0 +1,17 @@
+
+#ifndef framework_h
+#define framework_h
+
+#ifdef WIN32
+# ifdef framework_EXPORTS
+# define FRAMEWORK_EXPORT __declspec(dllexport)
+# else
+# define FRAMEWORK_EXPORT __declspec(dllimport)
+# endif
+#else
+# define FRAMEWORK_EXPORT
+#endif
+
+void FRAMEWORK_EXPORT framework();
+
+#endif
diff --git a/Tests/BundleUtilities/module.cpp b/Tests/BundleUtilities/module.cpp
new file mode 100644
index 0000000000..ee1b542fb3
--- /dev/null
+++ b/Tests/BundleUtilities/module.cpp
@@ -0,0 +1,10 @@
+
+#include "module.h"
+#include "stdio.h"
+#include "shared2.h"
+
+void module()
+{
+ printf("module\n");
+ shared2();
+}
diff --git a/Tests/BundleUtilities/module.h b/Tests/BundleUtilities/module.h
new file mode 100644
index 0000000000..0659bc742d
--- /dev/null
+++ b/Tests/BundleUtilities/module.h
@@ -0,0 +1,7 @@
+
+#ifndef module_h
+#define module_h
+
+void module();
+
+#endif
diff --git a/Tests/BundleUtilities/shared.cpp b/Tests/BundleUtilities/shared.cpp
new file mode 100644
index 0000000000..e5e7dc5aeb
--- /dev/null
+++ b/Tests/BundleUtilities/shared.cpp
@@ -0,0 +1,8 @@
+
+#include "shared.h"
+#include "stdio.h"
+
+void shared()
+{
+ printf("shared\n");
+}
diff --git a/Tests/BundleUtilities/shared.h b/Tests/BundleUtilities/shared.h
new file mode 100644
index 0000000000..3588fb88ed
--- /dev/null
+++ b/Tests/BundleUtilities/shared.h
@@ -0,0 +1,17 @@
+
+#ifndef shared_h
+#define shared_h
+
+#ifdef WIN32
+# ifdef shared_EXPORTS
+# define SHARED_EXPORT __declspec(dllexport)
+# else
+# define SHARED_EXPORT __declspec(dllimport)
+# endif
+#else
+# define SHARED_EXPORT
+#endif
+
+void SHARED_EXPORT shared();
+
+#endif
diff --git a/Tests/BundleUtilities/shared2.cpp b/Tests/BundleUtilities/shared2.cpp
new file mode 100644
index 0000000000..84af5d0617
--- /dev/null
+++ b/Tests/BundleUtilities/shared2.cpp
@@ -0,0 +1,8 @@
+
+#include "shared2.h"
+#include "stdio.h"
+
+void shared2()
+{
+ printf("shared2\n");
+}
diff --git a/Tests/BundleUtilities/shared2.h b/Tests/BundleUtilities/shared2.h
new file mode 100644
index 0000000000..d53546cb00
--- /dev/null
+++ b/Tests/BundleUtilities/shared2.h
@@ -0,0 +1,17 @@
+
+#ifndef shared2_h
+#define shared2_h
+
+#ifdef WIN32
+# ifdef shared2_EXPORTS
+# define SHARED2_EXPORT __declspec(dllexport)
+# else
+# define SHARED2_EXPORT __declspec(dllimport)
+# endif
+#else
+# define SHARED2_EXPORT
+#endif
+
+void SHARED2_EXPORT shared2();
+
+#endif
diff --git a/Tests/BundleUtilities/testbundleutils1.cpp b/Tests/BundleUtilities/testbundleutils1.cpp
new file mode 100644
index 0000000000..23d3cbd2e7
--- /dev/null
+++ b/Tests/BundleUtilities/testbundleutils1.cpp
@@ -0,0 +1,33 @@
+
+#include "framework.h"
+#include "shared.h"
+#include "stdio.h"
+
+#if defined(WIN32)
+#include <windows.h>
+#else
+#include "dlfcn.h"
+#endif
+
+int main(int, char**)
+{
+ framework();
+ shared();
+
+#if defined(WIN32)
+ HANDLE lib = LoadLibraryA("module1.dll");
+ if(!lib)
+ {
+ printf("Failed to open module1\n");
+ }
+#else
+ void* lib = dlopen("module1.so", RTLD_LAZY);
+ if(!lib)
+ {
+ printf("Failed to open module1\n%s\n", dlerror());
+ }
+#endif
+
+
+ return lib == 0 ? 1 : 0;
+}
diff --git a/Tests/BundleUtilities/testbundleutils2.cpp b/Tests/BundleUtilities/testbundleutils2.cpp
new file mode 100644
index 0000000000..319be8984d
--- /dev/null
+++ b/Tests/BundleUtilities/testbundleutils2.cpp
@@ -0,0 +1,33 @@
+
+#include "framework.h"
+#include "shared.h"
+#include "stdio.h"
+
+#if defined(WIN32)
+#include <windows.h>
+#else
+#include "dlfcn.h"
+#endif
+
+int main(int, char**)
+{
+ framework();
+ shared();
+
+#if defined(WIN32)
+ HANDLE lib = LoadLibraryA("module2.dll");
+ if(!lib)
+ {
+ printf("Failed to open module2\n");
+ }
+#else
+ void* lib = dlopen("module2.so", RTLD_LAZY);
+ if(!lib)
+ {
+ printf("Failed to open module2\n%s\n", dlerror());
+ }
+#endif
+
+
+ return lib == 0 ? 1 : 0;
+}
diff --git a/Tests/BundleUtilities/testbundleutils3.cpp b/Tests/BundleUtilities/testbundleutils3.cpp
new file mode 100644
index 0000000000..9df13e9883
--- /dev/null
+++ b/Tests/BundleUtilities/testbundleutils3.cpp
@@ -0,0 +1,33 @@
+
+#include "framework.h"
+#include "shared.h"
+#include "stdio.h"
+
+#if defined(WIN32)
+#include <windows.h>
+#else
+#include "dlfcn.h"
+#endif
+
+int main(int, char**)
+{
+ framework();
+ shared();
+
+#if defined(WIN32)
+ HANDLE lib = LoadLibraryA("module3.dll");
+ if(!lib)
+ {
+ printf("Failed to open module3\n");
+ }
+#else
+ void* lib = dlopen("module3.so", RTLD_LAZY);
+ if(!lib)
+ {
+ printf("Failed to open module3\n%s\n", dlerror());
+ }
+#endif
+
+
+ return lib == 0 ? 1 : 0;
+}
diff --git a/Tests/CFBundleTest/CMakeLists.txt b/Tests/CFBundleTest/CMakeLists.txt
new file mode 100644
index 0000000000..5cda527d85
--- /dev/null
+++ b/Tests/CFBundleTest/CMakeLists.txt
@@ -0,0 +1,64 @@
+#this is adapted from FireBreath (http://www.firebreath.org)
+
+cmake_minimum_required(VERSION 2.8)
+
+project(CFBundleTest)
+
+include(PluginConfig.cmake)
+
+message ("Creating Mac Browser Plugin project ${PROJECT_NAME}")
+set(SOURCES
+ np_macmain.cpp
+ Localized.r
+ ${CMAKE_CURRENT_BINARY_DIR}/Info.plist
+ ${CMAKE_CURRENT_BINARY_DIR}/InfoPlist.strings
+ ${CMAKE_CURRENT_BINARY_DIR}/Localized.rsrc
+)
+
+add_library( ${PROJECT_NAME} MODULE
+ ${SOURCES}
+ )
+
+set (RCFILES ${CMAKE_CURRENT_SOURCE_DIR}/Localized.r)
+
+configure_file(Info.plist.in ${CMAKE_CURRENT_BINARY_DIR}/Info.plist)
+configure_file(InfoPlist.strings.in ${CMAKE_CURRENT_BINARY_DIR}/InfoPlist.strings)
+
+# Compile the resource file
+find_program(RC_COMPILER Rez NO_DEFAULT_PATHS PATHS /Developer/Tools)
+if(NOT RC_COMPILER)
+ message(FATAL_ERROR "could not find Rez to build resources from .r file...")
+endif()
+
+set(sysroot)
+if(CMAKE_OSX_SYSROOT)
+ set(sysroot -isysroot ${CMAKE_OSX_SYSROOT})
+endif()
+
+execute_process(COMMAND
+ ${RC_COMPILER} ${sysroot} ${RCFILES} -useDF
+ -o ${CMAKE_CURRENT_BINARY_DIR}/Localized.rsrc
+ )
+
+set_source_files_properties(
+ ${CMAKE_CURRENT_BINARY_DIR}/Localized.rsrc
+ PROPERTIES GENERATED 1
+ )
+# note that for some reason, the makefile and xcode generators use a different
+# property to indicate where the Info.plist file is :-/ For that reason, we
+# specify it twice so it will work both places
+set_target_properties(CFBundleTest PROPERTIES
+ BUNDLE 1
+ BUNDLE_EXTENSION plugin
+ XCODE_ATTRIBUTE_WRAPPER_EXTENSION plugin #sets the extension to .plugin
+ XCODE_ATTRIBUTE_MACH_O_TYPE mh_bundle
+ XCODE_ATTRIBUTE_INFOPLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/Info.plist
+ MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist
+ LINK_FLAGS "-Wl,-exported_symbols_list,\"${CMAKE_CURRENT_SOURCE_DIR}/ExportList_plugin.txt\"")
+
+set_source_files_properties(
+ ${CMAKE_CURRENT_BINARY_DIR}/InfoPlist.strings
+ ${CMAKE_CURRENT_BINARY_DIR}/Localized.rsrc
+ PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/English.lproj")
+
+export(TARGETS CFBundleTest FILE ${CMAKE_CURRENT_BINARY_DIR}/exp.cmake)
diff --git a/Tests/CFBundleTest/ExportList_plugin.txt b/Tests/CFBundleTest/ExportList_plugin.txt
new file mode 100644
index 0000000000..31d6f640d1
--- /dev/null
+++ b/Tests/CFBundleTest/ExportList_plugin.txt
@@ -0,0 +1,3 @@
+_NP_GetEntryPoints
+_NP_Initialize
+_NP_Shutdown
diff --git a/Tests/CFBundleTest/Info.plist.in b/Tests/CFBundleTest/Info.plist.in
new file mode 100644
index 0000000000..638002f347
--- /dev/null
+++ b/Tests/CFBundleTest/Info.plist.in
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${PLUGIN_NAME}</string>
+ <key>CFBundleGetInfoString</key>
+ <string>${PLUGIN_NAME} ${FBSTRING_PLUGIN_VERSION}, ${FBSTRING_LegalCopyright}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.${ACTIVEX_PROGID}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BRPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${PLUGIN_NAME} ${FBSTRING_PLUGIN_VERSION}</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>${FBSTRING_PLUGIN_VERSION}</string>
+ <key>CFPlugInDynamicRegisterFunction</key>
+ <string></string>
+ <key>CFPlugInDynamicRegistration</key>
+ <string>NO</string>
+ <key>CFPlugInFactories</key>
+ <dict>
+ <key>00000000-0000-0000-0000-000000000000</key>
+ <string>MyFactoryFunction</string>
+ </dict>
+ <key>CFPlugInTypes</key>
+ <dict>
+ <key>00000000-0000-0000-0000-000000000000</key>
+ <array>
+ <string>00000000-0000-0000-0000-000000000000</string>
+ </array>
+ </dict>
+ <key>CFPlugInUnloadFunction</key>
+ <string></string>
+ <key>WebPluginName</key>
+ <string>${FBSTRING_ProductName}</string>
+ <key>WebPluginDescription</key>
+ <string>${FBSTRING_FileDescription}</string>
+ <key>WebPluginMIMETypes</key>
+ <dict>
+ <key>${FBSTRING_MIMEType}</key>
+ <dict>
+ <key>WebPluginTypeDescription</key>
+ <string>${FBSTRING_FileDescription}</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
diff --git a/Tests/CFBundleTest/InfoPlist.strings.in b/Tests/CFBundleTest/InfoPlist.strings.in
new file mode 100644
index 0000000000..790ead05d1
--- /dev/null
+++ b/Tests/CFBundleTest/InfoPlist.strings.in
@@ -0,0 +1,4 @@
+/* Localized versions of Info.plist keys */
+
+CFBundleName = "${PLUGIN_NAME}.plugin";
+NSHumanReadableCopyright = "${FBSTRING_LegalCopyright}";
diff --git a/Tests/CFBundleTest/Localized.r b/Tests/CFBundleTest/Localized.r
new file mode 100644
index 0000000000..e988e262cd
--- /dev/null
+++ b/Tests/CFBundleTest/Localized.r
@@ -0,0 +1,18 @@
+#include <CoreServices/CoreServices.r>
+
+resource 'STR#' (126)
+{ {
+ "${FBSTRING_LegalCopyright}",
+ "${FBSTRING_ProductName}"
+} };
+
+resource 'STR#' (127)
+{ {
+ "${FBSTRING_FileDescription}"
+} };
+
+resource 'STR#' (128)
+{ {
+ "${FBSTRING_MIMEType}",
+ "${FBSTRING_FileExtents}"
+} };
diff --git a/Tests/CFBundleTest/Localized.rsrc b/Tests/CFBundleTest/Localized.rsrc
new file mode 100644
index 0000000000..cbf35235b3
--- /dev/null
+++ b/Tests/CFBundleTest/Localized.rsrc
Binary files differ
diff --git a/Tests/CFBundleTest/PluginConfig.cmake b/Tests/CFBundleTest/PluginConfig.cmake
new file mode 100644
index 0000000000..763ddcc1c9
--- /dev/null
+++ b/Tests/CFBundleTest/PluginConfig.cmake
@@ -0,0 +1,21 @@
+#/**********************************************************\
+# Auto-Generated Plugin Configuration file
+# for CFTestPlugin
+#\**********************************************************/
+
+set(PLUGIN_NAME "CFTestPlugin")
+set(PLUGIN_PREFIX "CFTP")
+set(COMPANY_NAME "FBDevTeam")
+
+set(MOZILLA_PLUGINID "@firebreath.googlecode.com/CFTestPlugin")
+
+# strings
+set(FBSTRING_CompanyName "Firebreath Dev Team")
+set(FBSTRING_FileDescription "CFBundle Test Plugin - Plugin for testing cmake patch to improve FireBreath project generation")
+set(FBSTRING_PLUGIN_VERSION "1.0.0")
+set(FBSTRING_LegalCopyright "Copyright 2010 Firebreath Dev Team")
+set(FBSTRING_PluginFileName "np${PLUGIN_NAME}.dll")
+set(FBSTRING_ProductName "CFTestPlugin")
+set(FBSTRING_FileExtents "")
+set(FBSTRING_PluginName "CFTestPlugin")
+set(FBSTRING_MIMEType "application/x-fbtestplugin")
diff --git a/Tests/CFBundleTest/README.txt b/Tests/CFBundleTest/README.txt
new file mode 100644
index 0000000000..86c146333a
--- /dev/null
+++ b/Tests/CFBundleTest/README.txt
@@ -0,0 +1,16 @@
+
+CFBundle test project. The generated .plugin/ bundle from either makefiles or Xcode should look like this:
+
+./Contents
+./Contents/Info.plist
+./Contents/MacOS
+./Contents/MacOS/CFBundleTest
+./Contents/Resources
+./Contents/Resources/English.lproj
+./Contents/Resources/English.lproj/InfoPlist.strings
+./Contents/Resources/English.lproj/Localized.rsrc
+
+file Contents/MacOS/CFBundleTest should return something like:
+Contents/MacOS/CFBundleTest: Mach-O 64-bit bundle x86_64
+
+It is okay if it is a 32 bit binary; if it is not Mach-O, or is spelled differently, it is not okay.
diff --git a/Tests/CFBundleTest/VerifyResult.cmake b/Tests/CFBundleTest/VerifyResult.cmake
new file mode 100644
index 0000000000..e622900524
--- /dev/null
+++ b/Tests/CFBundleTest/VerifyResult.cmake
@@ -0,0 +1,32 @@
+if(NOT DEFINED CTEST_CONFIGURATION_TYPE)
+ message(FATAL_ERROR "expected variable CTEST_CONFIGURATION_TYPE not defined")
+endif()
+
+if(NOT DEFINED dir)
+ message(FATAL_ERROR "expected variable dir not defined")
+endif()
+
+if(NOT DEFINED gen)
+ message(FATAL_ERROR "expected variable gen not defined")
+endif()
+
+message(STATUS "CTEST_CONFIGURATION_TYPE='${CTEST_CONFIGURATION_TYPE}'")
+message(STATUS "dir='${dir}'")
+message(STATUS "gen='${gen}'")
+
+if(gen MATCHES "Make" OR
+ "${CTEST_CONFIGURATION_TYPE}" STREQUAL "" OR
+ "${CTEST_CONFIGURATION_TYPE}" STREQUAL "." OR
+ "${CTEST_CONFIGURATION_TYPE}" STREQUAL "NoConfig")
+ set(expected_filename "${dir}/CFBundleTest.plugin/Contents/MacOS/CFBundleTest")
+else()
+ set(expected_filename "${dir}/${CTEST_CONFIGURATION_TYPE}/CFBundleTest.plugin/Contents/MacOS/CFBundleTest")
+endif()
+
+if(NOT EXISTS "${expected_filename}")
+ message(FATAL_ERROR "test fails: expected output file does not exist [${expected_filename}]")
+endif()
+
+file(COPY "${expected_filename}"
+ DESTINATION "${dir}/LatestBuildResult"
+ )
diff --git a/Tests/CFBundleTest/np_macmain.cpp b/Tests/CFBundleTest/np_macmain.cpp
new file mode 100644
index 0000000000..78004d002c
--- /dev/null
+++ b/Tests/CFBundleTest/np_macmain.cpp
@@ -0,0 +1,49 @@
+/***********************************************************\
+ Written by: Richard Bateman (taxilian)
+
+ Based on the default np_macmain.cpp from FireBreath
+ http://firebreath.googlecode.com
+
+ This file has been stripped to prevent it from accidently
+ doing anything useful.
+\***********************************************************/
+
+
+#include <stdio.h>
+
+typedef void (*NPP_ShutdownProcPtr)(void);
+typedef short NPError;
+
+#pragma GCC visibility push(default)
+
+struct NPNetscapeFuncs;
+struct NPPluginFuncs;
+
+extern "C" {
+ NPError NP_Initialize(NPNetscapeFuncs *browserFuncs);
+ NPError NP_GetEntryPoints(NPPluginFuncs *pluginFuncs);
+ NPError NP_Shutdown(void);
+}
+
+#pragma GCC visibility pop
+
+void initPluginModule()
+{
+}
+
+NPError NP_GetEntryPoints(NPPluginFuncs* pFuncs)
+{
+ printf("NP_GetEntryPoints()\n");
+ return 0;
+}
+
+NPError NP_Initialize(NPNetscapeFuncs* pFuncs)
+{
+ printf("NP_Initialize()\n");
+ return 0;
+}
+
+NPError NP_Shutdown()
+{
+ return 0;
+}
diff --git a/Tests/CMakeBuildTest.cmake.in b/Tests/CMakeBuildTest.cmake.in
new file mode 100644
index 0000000000..71bcb183e4
--- /dev/null
+++ b/Tests/CMakeBuildTest.cmake.in
@@ -0,0 +1,61 @@
+# create the binary directory
+make_directory("@CMAKE_BUILD_TEST_BINARY_DIR@")
+
+# remove the CMakeCache.txt file from the source dir
+# if there is one, so that in-source cmake tests
+# still pass
+message("Remove: @CMAKE_BUILD_TEST_SOURCE_DIR@/CMakeCache.txt")
+file(REMOVE "@CMAKE_BUILD_TEST_SOURCE_DIR@/CMakeCache.txt")
+
+# run cmake in the binary directory
+message("running: ${CMAKE_COMMAND}")
+execute_process(COMMAND "${CMAKE_COMMAND}"
+ "@CMAKE_BUILD_TEST_SOURCE_DIR@"
+ "-G@CMAKE_GENERATOR@"
+ -A "@CMAKE_GENERATOR_PLATFORM@"
+ -T "@CMAKE_GENERATOR_TOOLSET@"
+ WORKING_DIRECTORY "@CMAKE_BUILD_TEST_BINARY_DIR@"
+ RESULT_VARIABLE RESULT)
+if(RESULT)
+ message(FATAL_ERROR "Error running cmake command")
+endif()
+
+# Now use the --build option to build the project
+message("running: ${CMAKE_COMMAND} --build")
+execute_process(COMMAND "${CMAKE_COMMAND}"
+ --build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug
+ RESULT_VARIABLE RESULT)
+if(RESULT)
+ message(FATAL_ERROR "Error running cmake --build")
+endif()
+
+# check for configuration types
+set(CMAKE_CONFIGURATION_TYPES @CMAKE_CONFIGURATION_TYPES@)
+# run the executable out of the Debug directory if there
+# are configuration types
+if(CMAKE_CONFIGURATION_TYPES)
+ set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/Debug/@CMAKE_BUILD_TEST_EXE@")
+else()
+ set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/@CMAKE_BUILD_TEST_EXE@")
+endif()
+# run the test results
+message("running [${RUN_TEST}]")
+execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
+if(RESULT)
+ message(FATAL_ERROR "Error running test @CMAKE_BUILD_TEST_EXE@")
+endif()
+
+# build it again with clean and only @CMAKE_BUILD_TEST_EXE@ target
+execute_process(COMMAND "${CMAKE_COMMAND}"
+ --build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug
+ --clean-first --target @CMAKE_BUILD_TEST_EXE@
+ RESULT_VARIABLE RESULT)
+if(RESULT)
+ message(FATAL_ERROR "Error running cmake --build")
+endif()
+
+# run it again after clean
+execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
+if(RESULT)
+ message(FATAL_ERROR "Error running test @CMAKE_BUILD_TEST_EXE@ after clean ")
+endif()
diff --git a/Tests/CMakeCommands/add_compile_options/CMakeLists.txt b/Tests/CMakeCommands/add_compile_options/CMakeLists.txt
new file mode 100644
index 0000000000..995b32c284
--- /dev/null
+++ b/Tests/CMakeCommands/add_compile_options/CMakeLists.txt
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(add_compile_options)
+
+add_compile_options(-DTEST_OPTION)
+
+add_executable(add_compile_options main.cpp)
+
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ target_compile_definitions(add_compile_options
+ PRIVATE
+ "DO_GNU_TESTS"
+ )
+endif()
+
+add_compile_options(-rtti)
+add_library(imp UNKNOWN IMPORTED)
+get_target_property(_res imp COMPILE_OPTIONS)
+if (_res)
+ message(SEND_ERROR "add_compile_options populated the COMPILE_OPTIONS target property")
+endif()
diff --git a/Tests/CMakeCommands/add_compile_options/main.cpp b/Tests/CMakeCommands/add_compile_options/main.cpp
new file mode 100644
index 0000000000..2bb20ac758
--- /dev/null
+++ b/Tests/CMakeCommands/add_compile_options/main.cpp
@@ -0,0 +1,11 @@
+
+#ifdef DO_GNU_TESTS
+# ifndef TEST_OPTION
+# error Expected TEST_OPTION
+# endif
+#endif
+
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt
new file mode 100644
index 0000000000..14d40aa543
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt
@@ -0,0 +1,34 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(target_compile_definitions)
+
+add_executable(target_compile_definitions
+ "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
+)
+target_compile_definitions(target_compile_definitions
+ PRIVATE MY_PRIVATE_DEFINE
+ PUBLIC MY_PUBLIC_DEFINE
+ INTERFACE MY_INTERFACE_DEFINE
+)
+
+add_executable(consumer
+ "${CMAKE_CURRENT_SOURCE_DIR}/consumer.cpp"
+)
+
+target_compile_definitions(consumer
+ PRIVATE $<TARGET_PROPERTY:target_compile_definitions,INTERFACE_COMPILE_DEFINITIONS>
+ -DDASH_D_DEFINE
+)
+
+# Test no items
+target_compile_definitions(consumer
+ PRIVATE
+)
+
+add_definitions(-DSOME_DEF)
+add_library(imp UNKNOWN IMPORTED)
+get_target_property(_res imp COMPILE_DEFINITIONS)
+if (_res)
+ message(SEND_ERROR "add_definitions populated the COMPILE_DEFINITIONS target property")
+endif()
diff --git a/Tests/CMakeCommands/target_compile_definitions/consumer.cpp b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp
new file mode 100644
index 0000000000..a391114162
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp
@@ -0,0 +1,18 @@
+
+#ifdef MY_PRIVATE_DEFINE
+#error Unexpected MY_PRIVATE_DEFINE
+#endif
+
+#ifndef MY_PUBLIC_DEFINE
+#error Expected MY_PUBLIC_DEFINE
+#endif
+
+#ifndef MY_INTERFACE_DEFINE
+#error Expected MY_INTERFACE_DEFINE
+#endif
+
+#ifndef DASH_D_DEFINE
+#error Expected DASH_D_DEFINE
+#endif
+
+int main() { return 0; }
diff --git a/Tests/CMakeCommands/target_compile_definitions/main.cpp b/Tests/CMakeCommands/target_compile_definitions/main.cpp
new file mode 100644
index 0000000000..addb33cf91
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_definitions/main.cpp
@@ -0,0 +1,14 @@
+
+#ifndef MY_PRIVATE_DEFINE
+#error Expected MY_PRIVATE_DEFINE
+#endif
+
+#ifndef MY_PUBLIC_DEFINE
+#error Expected MY_PUBLIC_DEFINE
+#endif
+
+#ifdef MY_INTERFACE_DEFINE
+#error Unexpected MY_INTERFACE_DEFINE
+#endif
+
+int main() { return 0; }
diff --git a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
new file mode 100644
index 0000000000..9b35f2713f
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
@@ -0,0 +1,45 @@
+cmake_minimum_required(VERSION 3.0)
+project(target_compile_features)
+
+if (NOT CMAKE_CXX_COMPILE_FEATURES AND NOT CMAKE_C_COMPILE_FEATURES)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_dummy.cpp"
+ "int main(int,char**) { return 0; }\n"
+ )
+ add_executable(target_compile_features "${CMAKE_CURRENT_BINARY_DIR}/test_dummy.cpp")
+ return()
+endif()
+
+set(CMAKE_VERBOSE_MAKEFILE ON)
+
+if (CMAKE_C_COMPILE_FEATURES)
+ add_executable(target_compile_features main.c)
+ target_compile_features(target_compile_features
+ PRIVATE c_restrict
+ )
+
+ add_library(lib_restrict lib_restrict.c)
+ target_compile_features(lib_restrict
+ PUBLIC c_restrict
+ )
+
+ add_executable(restrict_user restrict_user.c)
+ target_link_libraries(restrict_user lib_restrict)
+endif()
+
+if (CMAKE_CXX_COMPILE_FEATURES)
+ if (CMAKE_C_COMPILE_FEATURES)
+ set(target_suffix _cxx)
+ endif()
+ add_executable(target_compile_features${target_suffix} main.cpp)
+ target_compile_features(target_compile_features${target_suffix}
+ PRIVATE cxx_auto_type
+ )
+
+ add_library(lib_auto_type lib_auto_type.cpp)
+ target_compile_features(lib_auto_type
+ PUBLIC cxx_auto_type
+ )
+
+ add_executable(lib_user lib_user.cpp)
+ target_link_libraries(lib_user lib_auto_type)
+endif()
diff --git a/Tests/CMakeCommands/target_compile_features/dummy.cpp b/Tests/CMakeCommands/target_compile_features/dummy.cpp
new file mode 100644
index 0000000000..341aaafa0a
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/dummy.cpp
@@ -0,0 +1,5 @@
+
+int main(int, char **)
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/lib_auto_type.cpp b/Tests/CMakeCommands/target_compile_features/lib_auto_type.cpp
new file mode 100644
index 0000000000..71b22150d8
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_auto_type.cpp
@@ -0,0 +1,6 @@
+
+int getAutoTypeImpl()
+{
+ auto i = 0;
+ return i;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/lib_auto_type.h b/Tests/CMakeCommands/target_compile_features/lib_auto_type.h
new file mode 100644
index 0000000000..c825b10c3b
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_auto_type.h
@@ -0,0 +1,8 @@
+
+int getAutoTypeImpl();
+
+int getAutoType()
+{
+ auto i = getAutoTypeImpl();
+ return i;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/lib_restrict.c b/Tests/CMakeCommands/target_compile_features/lib_restrict.c
new file mode 100644
index 0000000000..049c1b0084
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_restrict.c
@@ -0,0 +1,9 @@
+
+#include "lib_restrict.h"
+
+int foo(int * restrict a, int * restrict b)
+{
+ (void)a;
+ (void)b;
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/lib_restrict.h b/Tests/CMakeCommands/target_compile_features/lib_restrict.h
new file mode 100644
index 0000000000..eca22be10c
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_restrict.h
@@ -0,0 +1,7 @@
+
+#ifndef LIB_RESTRICT_H
+#define LIB_RESTRICT_H
+
+int foo(int * restrict a, int * restrict b);
+
+#endif
diff --git a/Tests/CMakeCommands/target_compile_features/lib_user.cpp b/Tests/CMakeCommands/target_compile_features/lib_user.cpp
new file mode 100644
index 0000000000..976068a0b7
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_user.cpp
@@ -0,0 +1,7 @@
+
+#include "lib_auto_type.h"
+
+int main(int argc, char **argv)
+{
+ return getAutoType();
+}
diff --git a/Tests/CMakeCommands/target_compile_features/main.c b/Tests/CMakeCommands/target_compile_features/main.c
new file mode 100644
index 0000000000..831c5eb275
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/main.c
@@ -0,0 +1,12 @@
+
+int foo(int * restrict a, int * restrict b)
+{
+ (void)a;
+ (void)b;
+ return 0;
+}
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/main.cpp b/Tests/CMakeCommands/target_compile_features/main.cpp
new file mode 100644
index 0000000000..fe29b04adc
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/main.cpp
@@ -0,0 +1,6 @@
+
+int main(int, char **)
+{
+ auto i = 0;
+ return i;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/restrict_user.c b/Tests/CMakeCommands/target_compile_features/restrict_user.c
new file mode 100644
index 0000000000..d47b847b43
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/restrict_user.c
@@ -0,0 +1,14 @@
+
+#include "lib_restrict.h"
+
+int bar(int * restrict a, int * restrict b)
+{
+ (void)a;
+ (void)b;
+ return foo(a, b);
+}
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_compile_options/CMakeLists.txt b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt
new file mode 100644
index 0000000000..1d04639272
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt
@@ -0,0 +1,40 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(target_compile_options)
+
+add_executable(target_compile_options
+ "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
+)
+target_compile_options(target_compile_options
+ PRIVATE $<$<CXX_COMPILER_ID:GNU>:-DMY_PRIVATE_DEFINE>
+ PUBLIC $<$<CXX_COMPILER_ID:GNU>:-DMY_PUBLIC_DEFINE>
+ INTERFACE $<$<CXX_COMPILER_ID:GNU>:-DMY_INTERFACE_DEFINE>
+)
+
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ target_compile_definitions(target_compile_options
+ PRIVATE
+ "DO_GNU_TESTS"
+ )
+endif()
+
+add_executable(consumer
+ "${CMAKE_CURRENT_SOURCE_DIR}/consumer.cpp"
+)
+
+target_compile_options(consumer
+ PRIVATE $<$<CXX_COMPILER_ID:GNU>:$<TARGET_PROPERTY:target_compile_options,INTERFACE_COMPILE_OPTIONS>>
+)
+
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ target_compile_definitions(consumer
+ PRIVATE
+ "DO_GNU_TESTS"
+ )
+endif()
+
+# Test no items
+target_compile_options(consumer
+ PRIVATE
+)
diff --git a/Tests/CMakeCommands/target_compile_options/consumer.cpp b/Tests/CMakeCommands/target_compile_options/consumer.cpp
new file mode 100644
index 0000000000..12996065bc
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_options/consumer.cpp
@@ -0,0 +1,18 @@
+
+#ifdef DO_GNU_TESTS
+
+# ifdef MY_PRIVATE_DEFINE
+# error Unexpected MY_PRIVATE_DEFINE
+# endif
+
+# ifndef MY_PUBLIC_DEFINE
+# error Expected MY_PUBLIC_DEFINE
+# endif
+
+# ifndef MY_INTERFACE_DEFINE
+# error Expected MY_INTERFACE_DEFINE
+# endif
+
+#endif
+
+int main() { return 0; }
diff --git a/Tests/CMakeCommands/target_compile_options/main.cpp b/Tests/CMakeCommands/target_compile_options/main.cpp
new file mode 100644
index 0000000000..961c06dd70
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_options/main.cpp
@@ -0,0 +1,18 @@
+
+#ifdef DO_GNU_TESTS
+
+# ifndef MY_PRIVATE_DEFINE
+# error Expected MY_PRIVATE_DEFINE
+# endif
+
+# ifndef MY_PUBLIC_DEFINE
+# error Expected MY_PUBLIC_DEFINE
+# endif
+
+# ifdef MY_INTERFACE_DEFINE
+# error Unexpected MY_INTERFACE_DEFINE
+# endif
+
+#endif
+
+int main() { return 0; }
diff --git a/Tests/CMakeCommands/target_include_directories/CMakeLists.txt b/Tests/CMakeCommands/target_include_directories/CMakeLists.txt
new file mode 100644
index 0000000000..661bbaab63
--- /dev/null
+++ b/Tests/CMakeCommands/target_include_directories/CMakeLists.txt
@@ -0,0 +1,71 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(target_include_directories)
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/privateinclude")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/privateinclude/privateinclude.h" "#define PRIVATEINCLUDE_DEFINE\n")
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/publicinclude")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/publicinclude/publicinclude.h" "#define PUBLICINCLUDE_DEFINE\n")
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/interfaceinclude")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/interfaceinclude/interfaceinclude.h" "#define INTERFACEINCLUDE_DEFINE\n")
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/poison")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/poison/common.h" "#error Should not be included\n")
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/cure")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cure/common.h" "#define CURE_DEFINE\n")
+
+add_executable(target_include_directories
+ "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
+)
+target_include_directories(target_include_directories
+ PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/privateinclude"
+ PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/publicinclude"
+ INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/interfaceinclude"
+)
+
+target_include_directories(target_include_directories
+ PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/poison"
+)
+target_include_directories(target_include_directories
+ BEFORE PUBLIC "$<$<STREQUAL:$<TARGET_PROPERTY:target_include_directories,TYPE>,EXECUTABLE>:${CMAKE_CURRENT_BINARY_DIR}/cure>"
+)
+
+# Has no effect because the target type is not SHARED_LIBRARY:
+target_include_directories(target_include_directories
+ BEFORE PUBLIC "$<$<STREQUAL:$<TARGET_PROPERTY:target_include_directories,TYPE>,SHARED_LIBRARY>:${CMAKE_CURRENT_BINARY_DIR}/poison>"
+)
+
+add_executable(consumer
+ "${CMAKE_CURRENT_SOURCE_DIR}/consumer.cpp"
+)
+
+target_include_directories(consumer
+ PRIVATE
+ $<TARGET_PROPERTY:target_include_directories,INTERFACE_INCLUDE_DIRECTORIES>
+ relative_dir
+ relative_dir/$<TARGET_PROPERTY:NAME>
+)
+
+# Test no items
+target_include_directories(consumer
+ PRIVATE
+)
+target_include_directories(consumer
+ BEFORE PRIVATE
+)
+target_include_directories(consumer
+ SYSTEM BEFORE PRIVATE
+)
+target_include_directories(consumer
+ SYSTEM PRIVATE
+)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+add_library(imp UNKNOWN IMPORTED)
+get_target_property(_res imp INCLUDE_DIRECTORIES)
+if (_res)
+ message(SEND_ERROR "include_directories populated the INCLUDE_DIRECTORIES target property")
+endif()
diff --git a/Tests/CMakeCommands/target_include_directories/consumer.cpp b/Tests/CMakeCommands/target_include_directories/consumer.cpp
new file mode 100644
index 0000000000..7e3443ec3a
--- /dev/null
+++ b/Tests/CMakeCommands/target_include_directories/consumer.cpp
@@ -0,0 +1,32 @@
+
+#include "common.h"
+#include "publicinclude.h"
+#include "interfaceinclude.h"
+#include "relative_dir.h"
+#include "consumer.h"
+
+#ifdef PRIVATEINCLUDE_DEFINE
+#error Unexpected PRIVATEINCLUDE_DEFINE
+#endif
+
+#ifndef PUBLICINCLUDE_DEFINE
+#error Expected PUBLICINCLUDE_DEFINE
+#endif
+
+#ifndef INTERFACEINCLUDE_DEFINE
+#error Expected INTERFACEINCLUDE_DEFINE
+#endif
+
+#ifndef CURE_DEFINE
+#error Expected CURE_DEFINE
+#endif
+
+#ifndef RELATIVE_DIR_DEFINE
+#error Expected RELATIVE_DIR_DEFINE
+#endif
+
+#ifndef CONSUMER_DEFINE
+#error Expected CONSUMER_DEFINE
+#endif
+
+int main() { return 0; }
diff --git a/Tests/CMakeCommands/target_include_directories/main.cpp b/Tests/CMakeCommands/target_include_directories/main.cpp
new file mode 100644
index 0000000000..8434b97d8e
--- /dev/null
+++ b/Tests/CMakeCommands/target_include_directories/main.cpp
@@ -0,0 +1,22 @@
+
+#include "common.h"
+#include "privateinclude.h"
+#include "publicinclude.h"
+
+#ifndef PRIVATEINCLUDE_DEFINE
+#error Expected PRIVATEINCLUDE_DEFINE
+#endif
+
+#ifndef PUBLICINCLUDE_DEFINE
+#error Expected PUBLICINCLUDE_DEFINE
+#endif
+
+#ifdef INTERFACEINCLUDE_DEFINE
+#error Unexpected INTERFACEINCLUDE_DEFINE
+#endif
+
+#ifndef CURE_DEFINE
+#error Expected CURE_DEFINE
+#endif
+
+int main() { return 0; }
diff --git a/Tests/CMakeCommands/target_include_directories/relative_dir/consumer/consumer.h b/Tests/CMakeCommands/target_include_directories/relative_dir/consumer/consumer.h
new file mode 100644
index 0000000000..b91537369e
--- /dev/null
+++ b/Tests/CMakeCommands/target_include_directories/relative_dir/consumer/consumer.h
@@ -0,0 +1,2 @@
+
+#define CONSUMER_DEFINE
diff --git a/Tests/CMakeCommands/target_include_directories/relative_dir/relative_dir.h b/Tests/CMakeCommands/target_include_directories/relative_dir/relative_dir.h
new file mode 100644
index 0000000000..7017b61a89
--- /dev/null
+++ b/Tests/CMakeCommands/target_include_directories/relative_dir/relative_dir.h
@@ -0,0 +1,2 @@
+
+#define RELATIVE_DIR_DEFINE
diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
new file mode 100644
index 0000000000..e11f980dfa
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
@@ -0,0 +1,132 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(target_link_libraries)
+
+file(WRITE
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
+ "int main() { return 0; }
+"
+)
+
+add_executable(
+ target_link_libraries
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
+)
+
+macro(ASSERT_PROPERTY _target _property _value)
+ get_target_property(_out ${_target} ${_property})
+ if (NOT _out)
+ set(_out "")
+ endif()
+ if (NOT "${_out}" STREQUAL "${_value}")
+ message(SEND_ERROR "Target ${_target} does not have property ${_property} with value ${_value}. Actual value: ${_out}")
+ endif()
+endmacro()
+
+include(GenerateExportHeader)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_library(depA SHARED depA.cpp)
+generate_export_header(depA)
+
+add_library(depB SHARED depB.cpp)
+generate_export_header(depB)
+
+target_link_libraries(depB LINK_PRIVATE depA LINK_PRIVATE depA)
+
+add_library(libgenex SHARED libgenex.cpp)
+generate_export_header(libgenex)
+
+set_property(TARGET depB APPEND PROPERTY
+ LINK_LIBRARIES $<1:libgenex>
+)
+
+add_library(depC SHARED depC.cpp)
+generate_export_header(depC)
+
+target_link_libraries(depC LINK_PUBLIC depA LINK_PUBLIC depA)
+
+assert_property(depA LINK_INTERFACE_LIBRARIES "")
+assert_property(depB LINK_INTERFACE_LIBRARIES "")
+assert_property(depC LINK_INTERFACE_LIBRARIES "depA;depA")
+
+add_executable(targetA targetA.cpp)
+
+target_link_libraries(targetA LINK_INTERFACE_LIBRARIES depA depB)
+
+assert_property(targetA LINK_INTERFACE_LIBRARIES "depA;depB")
+
+set_target_properties(targetA PROPERTIES LINK_INTERFACE_LIBRARIES "")
+
+assert_property(targetA LINK_INTERFACE_LIBRARIES "")
+
+add_subdirectory(subdir)
+target_link_libraries(targetA subdirlib)
+
+target_link_libraries(targetA depB depC)
+
+assert_property(targetA LINK_INTERFACE_LIBRARIES "")
+
+# Exclude depIfaceOnly from ALL so that it will only be built if something
+# depends on it. As it is in the link interface of depB, targetA
+# will depend on it. That dependency is what is being tested here.
+add_library(depIfaceOnly SHARED EXCLUDE_FROM_ALL depIfaceOnly.cpp)
+generate_export_header(depIfaceOnly)
+set_property(TARGET depB APPEND PROPERTY LINK_INTERFACE_LIBRARIES depIfaceOnly)
+
+add_library(depD SHARED depD.cpp)
+generate_export_header(depD)
+set_property(TARGET depD APPEND PROPERTY
+ LINK_INTERFACE_LIBRARIES
+ $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:depA>
+)
+
+add_executable(targetB targetB.cpp)
+target_link_libraries(targetB depD)
+
+macro(create_header _name)
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_name}")
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_name}/${_name}.h" "//${_name}.h\n")
+endmacro()
+
+create_header(foo)
+create_header(bar)
+
+add_library(depG SHARED depG.cpp)
+generate_export_header(depG)
+target_include_directories(depG INTERFACE
+ "${CMAKE_CURRENT_BINARY_DIR}/foo"
+ "${CMAKE_CURRENT_BINARY_DIR}/bar"
+)
+target_compile_definitions(depG INTERFACE
+ TEST_DEF
+)
+
+
+add_executable(targetC targetC.cpp)
+if(NOT BORLAND AND NOT WATCOM)
+ # Linking to a target containing a + should be non-fatal, though it does
+ # not work at all on Borland or watcom
+ add_library(wrapc++ empty.cpp)
+ target_link_libraries(targetC wrapc++)
+endif()
+# The TARGET_PROPERTY expression is duplicated below to test that there is no
+# shortcutting of the evaluation by returning an empty string.
+set(_exe_test $<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>)
+target_link_libraries(targetC $<$<AND:${_exe_test},${_exe_test}>:depG>)
+
+add_library(libConsumer empty.cpp)
+# This line causes $<$<CONFIG:Debug>:depA> to be used when
+# determining the include directories for libConsumer based on the
+# interface properties of its LINK_LIBRARIES. Because the above expression
+# evaluates to the empty string in non-Debug cases, ensure that that causes
+# no problems.
+target_link_libraries(libConsumer debug depA)
+
+add_subdirectory(cmp0022)
+
+add_executable(newsignature1 newsignature1.cpp)
+target_link_libraries(newsignature1 PRIVATE depC INTERFACE depD PUBLIC depB PRIVATE subdirlib INTERFACE INTERFACE PUBLIC)
+
+assert_property(newsignature1 INTERFACE_LINK_LIBRARIES "depD;depB")
+assert_property(newsignature1 LINK_LIBRARIES "depC;depB;subdirlib")
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/cmp0022/CMakeLists.txt
new file mode 100644
index 0000000000..818b8c99c1
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/CMakeLists.txt
@@ -0,0 +1,37 @@
+
+include(GenerateExportHeader)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+cmake_policy(SET CMP0022 NEW)
+add_library(cmp0022lib SHARED cmp0022lib.cpp)
+generate_export_header(cmp0022lib)
+add_library(cmp0022ifacelib SHARED cmp0022ifacelib.cpp)
+generate_export_header(cmp0022ifacelib)
+target_link_libraries(cmp0022lib LINK_PUBLIC cmp0022ifacelib)
+
+assert_property(cmp0022lib LINK_INTERFACE_LIBRARIES "")
+assert_property(cmp0022ifacelib LINK_INTERFACE_LIBRARIES "")
+assert_property(cmp0022lib INTERFACE_LINK_LIBRARIES "cmp0022ifacelib")
+assert_property(cmp0022ifacelib INTERFACE_LINK_LIBRARIES "")
+
+add_executable(cmp0022exe cmp0022exe.cpp)
+target_link_libraries(cmp0022exe cmp0022lib)
+
+add_library(staticlib1 STATIC staticlib1.cpp)
+generate_export_header(staticlib1)
+add_library(staticlib2 STATIC staticlib2.cpp)
+generate_export_header(staticlib2)
+target_link_libraries(staticlib1 LINK_PUBLIC staticlib2)
+if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ target_link_libraries(staticlib1 LINK_PRIVATE "-Wl,-v")
+endif()
+
+add_executable(staticlib_exe staticlib_exe.cpp)
+target_link_libraries(staticlib_exe staticlib1)
+
+add_library(onlyplainlib1 SHARED onlyplainlib1.cpp)
+add_library(onlyplainlib2 SHARED onlyplainlib2.cpp)
+target_link_libraries(onlyplainlib2 onlyplainlib1)
+
+add_executable(onlyplainlib_user onlyplainlib_user.cpp)
+target_link_libraries(onlyplainlib_user onlyplainlib2)
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022exe.cpp b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022exe.cpp
new file mode 100644
index 0000000000..008bb74b55
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022exe.cpp
@@ -0,0 +1,7 @@
+
+#include "cmp0022lib.h"
+
+int main(void)
+{
+ return cmp0022().Value;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022ifacelib.cpp b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022ifacelib.cpp
new file mode 100644
index 0000000000..b285be0223
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022ifacelib.cpp
@@ -0,0 +1,9 @@
+
+#include "cmp0022ifacelib.h"
+
+CMP0022Iface cmp0022iface()
+{
+ CMP0022Iface iface;
+ iface.Value = 0;
+ return iface;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022ifacelib.h b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022ifacelib.h
new file mode 100644
index 0000000000..616dbf6441
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022ifacelib.h
@@ -0,0 +1,9 @@
+
+#include "cmp0022ifacelib_export.h"
+
+struct CMP0022Iface
+{
+ int Value;
+};
+
+CMP0022Iface CMP0022IFACELIB_EXPORT cmp0022iface();
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022lib.cpp b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022lib.cpp
new file mode 100644
index 0000000000..381d463ff7
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022lib.cpp
@@ -0,0 +1,7 @@
+
+#include "cmp0022lib.h"
+
+CMP0022Iface cmp0022()
+{
+ return cmp0022iface();
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022lib.h b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022lib.h
new file mode 100644
index 0000000000..3235b9bf19
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/cmp0022lib.h
@@ -0,0 +1,6 @@
+
+#include "cmp0022lib_export.h"
+
+#include "cmp0022ifacelib.h"
+
+CMP0022Iface CMP0022LIB_EXPORT cmp0022();
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib1.cpp b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib1.cpp
new file mode 100644
index 0000000000..41dc3ce18d
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib1.cpp
@@ -0,0 +1,13 @@
+
+#include "onlyplainlib1.h"
+
+OnlyPlainLib1::OnlyPlainLib1()
+ : result(0)
+{
+
+}
+
+int OnlyPlainLib1::GetResult()
+{
+ return result;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib1.h b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib1.h
new file mode 100644
index 0000000000..c0373ceb3b
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib1.h
@@ -0,0 +1,14 @@
+
+struct
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+OnlyPlainLib1
+{
+ OnlyPlainLib1();
+
+ int GetResult();
+
+private:
+ int result;
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib2.cpp b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib2.cpp
new file mode 100644
index 0000000000..2865ae91a6
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib2.cpp
@@ -0,0 +1,8 @@
+
+#include "onlyplainlib2.h"
+
+OnlyPlainLib1 onlyPlainLib2()
+{
+ OnlyPlainLib1 opl1;
+ return opl1;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib2.h b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib2.h
new file mode 100644
index 0000000000..74b18a00ef
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib2.h
@@ -0,0 +1,7 @@
+
+#include "onlyplainlib1.h"
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+OnlyPlainLib1 onlyPlainLib2();
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib_user.cpp b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib_user.cpp
new file mode 100644
index 0000000000..0fb7b0a67b
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/onlyplainlib_user.cpp
@@ -0,0 +1,7 @@
+
+#include "onlyplainlib2.h"
+
+int main(int argc, char **argv)
+{
+ return onlyPlainLib2().GetResult();
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib1.cpp b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib1.cpp
new file mode 100644
index 0000000000..a253c46f61
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib1.cpp
@@ -0,0 +1,2 @@
+
+int staticlib1() { return 0; }
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib1.h b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib1.h
new file mode 100644
index 0000000000..4bbf23ffdf
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib1.h
@@ -0,0 +1,4 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int staticlib1();
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib2.cpp b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib2.cpp
new file mode 100644
index 0000000000..4e38063b51
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib2.cpp
@@ -0,0 +1,2 @@
+
+int staticlib2() { return 0; }
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib2.h b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib2.h
new file mode 100644
index 0000000000..a4e07b6c13
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib2.h
@@ -0,0 +1,4 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int staticlib2();
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib_exe.cpp b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib_exe.cpp
new file mode 100644
index 0000000000..97adc40dbc
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/staticlib_exe.cpp
@@ -0,0 +1,8 @@
+
+#include "staticlib1.h"
+#include "staticlib2.h"
+
+int main()
+{
+ return staticlib1() + staticlib2();
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depA.cpp b/Tests/CMakeCommands/target_link_libraries/depA.cpp
new file mode 100644
index 0000000000..c2e8e7b9a1
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depA.cpp
@@ -0,0 +1,7 @@
+
+#include "depA.h"
+
+int DepA::foo()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depA.h b/Tests/CMakeCommands/target_link_libraries/depA.h
new file mode 100644
index 0000000000..7a859488b2
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depA.h
@@ -0,0 +1,7 @@
+
+#include "depa_export.h"
+
+struct DEPA_EXPORT DepA
+{
+ int foo();
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/depB.cpp b/Tests/CMakeCommands/target_link_libraries/depB.cpp
new file mode 100644
index 0000000000..4f46552d7c
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depB.cpp
@@ -0,0 +1,15 @@
+
+#include "depB.h"
+
+#include "depA.h"
+
+#include "libgenex.h"
+
+int DepB::foo()
+{
+ DepA a;
+
+ LibGenex lg;
+
+ return a.foo() + lg.foo();
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depB.h b/Tests/CMakeCommands/target_link_libraries/depB.h
new file mode 100644
index 0000000000..e617813ba2
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depB.h
@@ -0,0 +1,7 @@
+
+#include "depb_export.h"
+
+struct DEPB_EXPORT DepB
+{
+ int foo();
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/depC.cpp b/Tests/CMakeCommands/target_link_libraries/depC.cpp
new file mode 100644
index 0000000000..60bed592ff
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depC.cpp
@@ -0,0 +1,13 @@
+
+#include "depC.h"
+
+int DepC::foo()
+{
+ return 0;
+}
+
+DepA DepC::getA()
+{
+ DepA a;
+ return a;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depC.h b/Tests/CMakeCommands/target_link_libraries/depC.h
new file mode 100644
index 0000000000..4d65c9eb35
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depC.h
@@ -0,0 +1,12 @@
+
+#include "depc_export.h"
+
+#include "depA.h"
+
+struct DEPC_EXPORT DepC
+{
+ int foo();
+
+ DepA getA();
+
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/depD.cpp b/Tests/CMakeCommands/target_link_libraries/depD.cpp
new file mode 100644
index 0000000000..b02c76cf32
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depD.cpp
@@ -0,0 +1,13 @@
+
+#include "depD.h"
+
+int DepD::foo()
+{
+ return 0;
+}
+
+DepA DepD::getA()
+{
+ DepA a;
+ return a;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depD.h b/Tests/CMakeCommands/target_link_libraries/depD.h
new file mode 100644
index 0000000000..d24ff5f7ca
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depD.h
@@ -0,0 +1,11 @@
+
+#include "depd_export.h"
+
+#include "depA.h"
+
+struct DEPD_EXPORT DepD
+{
+ int foo();
+
+ DepA getA();
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/depG.cpp b/Tests/CMakeCommands/target_link_libraries/depG.cpp
new file mode 100644
index 0000000000..65b9655c56
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depG.cpp
@@ -0,0 +1,7 @@
+
+#include "depG.h"
+
+int DepG::foo()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depG.h b/Tests/CMakeCommands/target_link_libraries/depG.h
new file mode 100644
index 0000000000..1a36589141
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depG.h
@@ -0,0 +1,7 @@
+
+#include "depg_export.h"
+
+struct DEPG_EXPORT DepG
+{
+ int foo();
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.cpp b/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.cpp
new file mode 100644
index 0000000000..3b90af008f
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.cpp
@@ -0,0 +1,7 @@
+
+#include "depIfaceOnly.h"
+
+int DepIfaceOnly::foo()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.h b/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.h
new file mode 100644
index 0000000000..dddf6a5e46
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.h
@@ -0,0 +1,7 @@
+
+#include "depifaceonly_export.h"
+
+struct DEPIFACEONLY_EXPORT DepIfaceOnly
+{
+ int foo();
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/empty.cpp b/Tests/CMakeCommands/target_link_libraries/empty.cpp
new file mode 100644
index 0000000000..ab32cf6c8a
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/empty.cpp
@@ -0,0 +1 @@
+// No content
diff --git a/Tests/CMakeCommands/target_link_libraries/libgenex.cpp b/Tests/CMakeCommands/target_link_libraries/libgenex.cpp
new file mode 100644
index 0000000000..c925c08212
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/libgenex.cpp
@@ -0,0 +1,7 @@
+
+#include "libgenex.h"
+
+int LibGenex::foo()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/libgenex.h b/Tests/CMakeCommands/target_link_libraries/libgenex.h
new file mode 100644
index 0000000000..733f9b6df2
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/libgenex.h
@@ -0,0 +1,12 @@
+
+#include "libgenex_export.h"
+
+#ifndef LIBGENEX_H
+#define LIBGENEX_H
+
+struct LIBGENEX_EXPORT LibGenex
+{
+ int foo();
+};
+
+#endif
diff --git a/Tests/CMakeCommands/target_link_libraries/newsignature1.cpp b/Tests/CMakeCommands/target_link_libraries/newsignature1.cpp
new file mode 100644
index 0000000000..d1321a15fe
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/newsignature1.cpp
@@ -0,0 +1,19 @@
+
+#include "depB.h"
+#include "depC.h"
+#include "depIfaceOnly.h"
+
+#include "subdirlib.h"
+
+int main(int, char **)
+{
+ DepA a;
+ DepB b;
+ DepC c;
+
+ DepIfaceOnly iface_only;
+
+ SubDirLibObject sd;
+
+ return a.foo() + b.foo() + c.foo() + iface_only.foo() + sd.foo();
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt
new file mode 100644
index 0000000000..9d7fa6cb83
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+
+add_library(subdirlib SHARED subdirlib.cpp)
+generate_export_header(subdirlib)
diff --git a/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp
new file mode 100644
index 0000000000..cd2f1a23a9
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp
@@ -0,0 +1,7 @@
+
+#include "subdirlib.h"
+
+int SubDirLibObject::foo() const
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h
new file mode 100644
index 0000000000..e386f87b20
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h
@@ -0,0 +1,12 @@
+
+#ifndef SUBDIRLIB_H
+#define SUBDIRLIB_H
+
+#include "subdirlib_export.h"
+
+struct SUBDIRLIB_EXPORT SubDirLibObject
+{
+ int foo() const;
+};
+
+#endif
diff --git a/Tests/CMakeCommands/target_link_libraries/targetA.cpp b/Tests/CMakeCommands/target_link_libraries/targetA.cpp
new file mode 100644
index 0000000000..d1321a15fe
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/targetA.cpp
@@ -0,0 +1,19 @@
+
+#include "depB.h"
+#include "depC.h"
+#include "depIfaceOnly.h"
+
+#include "subdirlib.h"
+
+int main(int, char **)
+{
+ DepA a;
+ DepB b;
+ DepC c;
+
+ DepIfaceOnly iface_only;
+
+ SubDirLibObject sd;
+
+ return a.foo() + b.foo() + c.foo() + iface_only.foo() + sd.foo();
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/targetB.cpp b/Tests/CMakeCommands/target_link_libraries/targetB.cpp
new file mode 100644
index 0000000000..0913a57b06
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/targetB.cpp
@@ -0,0 +1,10 @@
+
+#include "depD.h"
+
+int main(int, char **)
+{
+ DepD d;
+ DepA a = d.getA();
+
+ return d.foo() + a.foo();
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/targetC.cpp b/Tests/CMakeCommands/target_link_libraries/targetC.cpp
new file mode 100644
index 0000000000..a4ef6369d0
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/targetC.cpp
@@ -0,0 +1,16 @@
+
+#include "depG.h"
+
+#include "foo.h"
+#include "bar.h"
+
+#ifndef TEST_DEF
+#error Expected TEST_DEF definition
+#endif
+
+int main(int, char **)
+{
+ DepG g;
+
+ return g.foo();
+}
diff --git a/Tests/CMakeCopyright.cmake b/Tests/CMakeCopyright.cmake
new file mode 100644
index 0000000000..a7201e97d1
--- /dev/null
+++ b/Tests/CMakeCopyright.cmake
@@ -0,0 +1,22 @@
+if(CMAKE_VERSION MATCHES "\\.(20[0-9][0-9])[0-9][0-9][0-9][0-9](-|$)")
+ set(version_year "${CMAKE_MATCH_1}")
+ set(copyright_line_regex "^Copyright 2000-(20[0-9][0-9]) Kitware")
+ file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/../Copyright.txt" copyright_line
+ LIMIT_COUNT 1 REGEX "${copyright_line_regex}")
+ if(copyright_line MATCHES "${copyright_line_regex}")
+ set(copyright_year "${CMAKE_MATCH_1}")
+ if(copyright_year LESS version_year)
+ message(FATAL_ERROR "Copyright.txt contains\n"
+ " ${copyright_line}\n"
+ "but the current version year is ${version_year}.")
+ else()
+ message(STATUS "PASSED: Copyright.txt contains\n"
+ " ${copyright_line}\n"
+ "and the current version year is ${version_year}.")
+ endif()
+ else()
+ message(FATAL_ERROR "Copyright.txt has no Copyright line of expected format!")
+ endif()
+else()
+ message(STATUS "SKIPPED: CMAKE_VERSION does not know the year: ${CMAKE_VERSION}")
+endif()
diff --git a/Tests/CMakeInstall.cmake b/Tests/CMakeInstall.cmake
new file mode 100644
index 0000000000..fda8c54b33
--- /dev/null
+++ b/Tests/CMakeInstall.cmake
@@ -0,0 +1,37 @@
+# Define option CMake_TEST_INSTALL, and enable by default for dashboards.
+set(_default 0)
+if(DEFINED ENV{DASHBOARD_TEST_FROM_CTEST})
+ set(_default 1)
+endif()
+option(CMake_TEST_INSTALL "Test CMake Installation" ${_default})
+mark_as_advanced(CMake_TEST_INSTALL)
+
+if(CMake_TEST_INSTALL)
+ # Do not build during the test.
+ set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY 1)
+
+ # Install to a test directory.
+ set(CMake_TEST_INSTALL_PREFIX ${CMake_BINARY_DIR}/Tests/CMakeInstall)
+ set(CMAKE_INSTALL_PREFIX "${CMake_TEST_INSTALL_PREFIX}")
+
+ if(CMAKE_CONFIGURATION_TYPES)
+ # There are multiple configurations. Make sure the tested
+ # configuration is the one that is installed.
+ set(CMake_TEST_INSTALL_CONFIG --config $<CONFIGURATION>)
+ else()
+ set(CMake_TEST_INSTALL_CONFIG)
+ endif()
+
+ # Add a test to install CMake through the build system install target.
+ add_test(NAME CMake.Install
+ COMMAND cmake --build . --target install ${CMake_TEST_INSTALL_CONFIG}
+ )
+
+ # Avoid running this test simultaneously with other tests:
+ set_tests_properties(CMake.Install PROPERTIES RUN_SERIAL ON)
+
+ # TODO: Make all other tests depend on this one, and then drive them
+ # with the installed CTest.
+else()
+ set(CMake_TEST_INSTALL_PREFIX)
+endif()
diff --git a/Tests/CMakeLib/CMakeLists.txt b/Tests/CMakeLib/CMakeLists.txt
new file mode 100644
index 0000000000..8c99f64184
--- /dev/null
+++ b/Tests/CMakeLib/CMakeLists.txt
@@ -0,0 +1,50 @@
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMake_BINARY_DIR}/Source
+ ${CMake_SOURCE_DIR}/Source
+ )
+
+set(CMakeLib_TESTS
+ testGeneratedFileStream
+ testRST
+ testSystemTools
+ testUTF8
+ testXMLParser
+ testXMLSafe
+ )
+
+set(testRST_ARGS ${CMAKE_CURRENT_SOURCE_DIR})
+
+if(WIN32)
+ list(APPEND CMakeLib_TESTS
+ testVisualStudioSlnParser
+ )
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testVisualStudioSlnParser.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/testVisualStudioSlnParser.h @ONLY)
+endif()
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testXMLParser.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/testXMLParser.h @ONLY)
+
+create_test_sourcelist(CMakeLib_TEST_SRCS CMakeLibTests.cxx ${CMakeLib_TESTS})
+add_executable(CMakeLibTests ${CMakeLib_TEST_SRCS})
+target_link_libraries(CMakeLibTests CMakeLib)
+
+# 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 CMakeLibTests
+ PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CFG_INTDIR}"
+ )
+endif()
+
+foreach(test ${CMakeLib_TESTS})
+ add_test(CMakeLib.${test} CMakeLibTests ${test} ${${test}_ARGS})
+endforeach()
+
+if(TEST_CompileCommandOutput)
+ add_executable(runcompilecommands run_compile_commands.cxx)
+ target_link_libraries(runcompilecommands CMakeLib)
+endif()
diff --git a/Tests/CMakeLib/run_compile_commands.cxx b/Tests/CMakeLib/run_compile_commands.cxx
new file mode 100644
index 0000000000..279bcd587b
--- /dev/null
+++ b/Tests/CMakeLib/run_compile_commands.cxx
@@ -0,0 +1,141 @@
+#include "cmSystemTools.h"
+
+class CompileCommandParser {
+public:
+ class CommandType: public std::map<std::string, std::string>
+ {
+ public:
+ std::string const& at(std::string const& k) const
+ {
+ const_iterator i = this->find(k);
+ if(i != this->end()) { return i->second; }
+ static std::string emptyString;
+ return emptyString;
+ }
+ };
+ typedef std::vector<CommandType> TranslationUnitsType;
+
+ CompileCommandParser(std::ifstream *input)
+ {
+ this->Input = input;
+ }
+
+ void Parse()
+ {
+ NextNonWhitespace();
+ ParseTranslationUnits();
+ }
+
+ const TranslationUnitsType& GetTranslationUnits()
+ {
+ return this->TranslationUnits;
+ }
+
+private:
+ void ParseTranslationUnits()
+ {
+ this->TranslationUnits = TranslationUnitsType();
+ ExpectOrDie('[', "at start of compile command file\n");
+ do
+ {
+ ParseTranslationUnit();
+ this->TranslationUnits.push_back(this->Command);
+ } while(Expect(','));
+ ExpectOrDie(']', "at end of array");
+ }
+
+ void ParseTranslationUnit()
+ {
+ this->Command = CommandType();
+ if(!Expect('{')) return;
+ if(Expect('}')) return;
+ do
+ {
+ ParseString();
+ std::string name = this->String;
+ ExpectOrDie(':', "between name and value");
+ ParseString();
+ std::string value = this->String;
+ this->Command[name] = value;
+ } while(Expect(','));
+ ExpectOrDie('}', "at end of object");
+ }
+
+ void ParseString()
+ {
+ this->String = "";
+ if(!Expect('"')) return;
+ while (!Expect('"'))
+ {
+ Expect('\\');
+ this->String.append(1,C);
+ Next();
+ }
+ }
+
+ bool Expect(char c)
+ {
+ if(this->C == c)
+ {
+ NextNonWhitespace();
+ return true;
+ }
+ return false;
+ }
+
+ void ExpectOrDie(char c, const std::string & message)
+ {
+ if (!Expect(c))
+ ErrorExit(std::string("'") + c + "' expected " + message + ".");
+ }
+
+ void NextNonWhitespace()
+ {
+ do { Next(); } while (IsWhitespace());
+ }
+
+ void Next()
+ {
+ this->C = char(Input->get());
+ if (this->Input->bad()) ErrorExit("Unexpected end of file.");
+ }
+
+ void ErrorExit(const std::string &message) {
+ std::cout << "ERROR: " << message;
+ exit(1);
+ }
+
+ bool IsWhitespace()
+ {
+ return (this->C == ' ' || this->C == '\t' ||
+ this->C == '\n' || this->C == '\r');
+ }
+
+ char C;
+ TranslationUnitsType TranslationUnits;
+ CommandType Command;
+ std::string String;
+ std::ifstream *Input;
+};
+
+int main ()
+{
+ std::ifstream file("compile_commands.json");
+ CompileCommandParser parser(&file);
+ parser.Parse();
+ for(CompileCommandParser::TranslationUnitsType::const_iterator
+ it = parser.GetTranslationUnits().begin(),
+ end = parser.GetTranslationUnits().end(); it != end; ++it)
+ {
+ std::vector<std::string> command;
+ cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), command);
+ if (!cmSystemTools::RunSingleCommand(
+ command, 0, 0, it->at("directory").c_str()))
+ {
+ std::cout << "ERROR: Failed to run command \""
+ << command[0] << "\"" << std::endl;
+ exit(1);
+ }
+ }
+ return 0;
+}
diff --git a/Tests/CMakeLib/testGeneratedFileStream.cxx b/Tests/CMakeLib/testGeneratedFileStream.cxx
new file mode 100644
index 0000000000..f8ca4af944
--- /dev/null
+++ b/Tests/CMakeLib/testGeneratedFileStream.cxx
@@ -0,0 +1,100 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2011 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 "cmGeneratedFileStream.h"
+#include "cmSystemTools.h"
+
+#define cmFailed(m1, m2) \
+ std::cout << "FAILED: " << m1 << m2 << "\n"; failed=1
+
+int testGeneratedFileStream(int, char*[])
+{
+ int failed = 0;
+ cmGeneratedFileStream gm;
+ std::string file1 = "generatedFile1";
+ std::string file2 = "generatedFile2";
+ std::string file3 = "generatedFile3";
+ std::string file4 = "generatedFile4";
+ std::string file1tmp = file1 + ".tmp";
+ std::string file2tmp = file2 + ".tmp";
+ std::string file3tmp = file3 + ".tmp";
+ std::string file4tmp = file4 + ".tmp";
+ gm.Open(file1.c_str());
+ gm << "This is generated file 1";
+ gm.Close();
+ gm.Open(file2.c_str());
+ gm << "This is generated file 2";
+ gm.Close();
+ gm.Open(file3.c_str());
+ gm << "This is generated file 3";
+ gm.Close();
+ gm.Open(file4.c_str());
+ gm << "This is generated file 4";
+ gm.Close();
+ if ( cmSystemTools::FileExists(file1.c_str()) )
+ {
+ if ( cmSystemTools::FileExists(file2.c_str()) )
+ {
+ if ( cmSystemTools::FileExists(file3.c_str()) )
+ {
+ if ( cmSystemTools::FileExists(file4.c_str()) )
+ {
+ if ( cmSystemTools::FileExists(file1tmp.c_str()) )
+ {
+ cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file1tmp.c_str());
+ }
+ else if ( cmSystemTools::FileExists(file2tmp.c_str()) )
+ {
+ cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file2tmp.c_str());
+ }
+ else if ( cmSystemTools::FileExists(file3tmp.c_str()) )
+ {
+ cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file3tmp.c_str());
+ }
+ else if ( cmSystemTools::FileExists(file4tmp.c_str()) )
+ {
+ cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file4tmp.c_str());
+ }
+ else
+ {
+ std::cout << "cmGeneratedFileStream works\n";
+ }
+ }
+ else
+ {
+ cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file4.c_str());
+ }
+ }
+ else
+ {
+ cmFailed("Something wrong with cmGeneratedFileStream. Found file: ", file3.c_str());
+ }
+ }
+ else
+ {
+ cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file2.c_str());
+ }
+ }
+ else
+ {
+ cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file1.c_str());
+ }
+ cmSystemTools::RemoveFile(file1.c_str());
+ cmSystemTools::RemoveFile(file2.c_str());
+ cmSystemTools::RemoveFile(file3.c_str());
+ cmSystemTools::RemoveFile(file4.c_str());
+ cmSystemTools::RemoveFile(file1tmp.c_str());
+ cmSystemTools::RemoveFile(file2tmp.c_str());
+ cmSystemTools::RemoveFile(file3tmp.c_str());
+ cmSystemTools::RemoveFile(file4tmp.c_str());
+
+ return failed;
+}
diff --git a/Tests/CMakeLib/testRST.cxx b/Tests/CMakeLib/testRST.cxx
new file mode 100644
index 0000000000..37cb3faab0
--- /dev/null
+++ b/Tests/CMakeLib/testRST.cxx
@@ -0,0 +1,101 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 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 "cmRST.h"
+
+#include "cmSystemTools.h"
+
+void reportLine(std::ostream& os, bool ret, std::string line, bool eol)
+{
+ if(ret)
+ {
+ os << "\"" << line << "\" (" << (eol?"with EOL":"without EOL") << ")";
+ }
+ else
+ {
+ os << "EOF";
+ }
+}
+
+int testRST(int argc, char* argv[])
+{
+ if(argc != 2)
+ {
+ std::cerr << "Usage: testRST <dir>" << std::endl;
+ return 1;
+ }
+ std::string dir = argv[1];
+ if(dir.empty())
+ {
+ dir = ".";
+ }
+ std::string a_name = "testRST.actual";
+ std::string e_name = dir + "/testRST.expect";
+
+ // Process the test RST file.
+ {
+ std::string fname = dir + "/testRST.rst";
+ std::ofstream fout(a_name.c_str());
+ if(!fout)
+ {
+ std::cerr << "Could not open output " << a_name << std::endl;
+ return 1;
+ }
+
+ cmRST r(fout, dir);
+ if(!r.ProcessFile(fname))
+ {
+ std::cerr << "Could not open input " << fname << std::endl;
+ return 1;
+ }
+ }
+
+ // Compare expected and actual outputs.
+ std::ifstream e_fin(e_name.c_str());
+ std::ifstream a_fin(a_name.c_str());
+ if(!e_fin)
+ {
+ std::cerr << "Could not open input " << e_name << std::endl;
+ return 1;
+ }
+ if(!a_fin)
+ {
+ std::cerr << "Could not open input " << a_name << std::endl;
+ return 1;
+ }
+ int lineno = 0;
+ bool e_ret;
+ bool a_ret;
+ do
+ {
+ std::string e_line;
+ std::string a_line;
+ bool e_eol;
+ bool a_eol;
+ e_ret = cmSystemTools::GetLineFromStream(e_fin, e_line, &e_eol);
+ a_ret = cmSystemTools::GetLineFromStream(a_fin, a_line, &a_eol);
+ ++lineno;
+ if(e_ret != a_ret || e_line != a_line || e_eol != a_eol)
+ {
+ a_fin.seekg(0, std::ios::beg);
+ std::cerr << "Actual output does not match that expected on line "
+ << lineno << "." << std::endl << "Expected ";
+ reportLine(std::cerr, e_ret, e_line, e_eol);
+ std::cerr << " but got ";
+ reportLine(std::cerr, a_ret, a_line, a_eol);
+ std::cerr << "." << std::endl
+ << "Actual output:" << std::endl
+ << a_fin.rdbuf();
+ return 1;
+ }
+ } while(e_ret && a_ret);
+ return 0;
+}
diff --git a/Tests/CMakeLib/testRST.expect b/Tests/CMakeLib/testRST.expect
new file mode 100644
index 0000000000..fa436cb914
--- /dev/null
+++ b/Tests/CMakeLib/testRST.expect
@@ -0,0 +1,92 @@
+title_text
+----------
+
+Command ``some_cmd()`` explicit cmake domain.
+Command ``some_cmd()`` without target.
+Command ``some_cmd`` with target.
+Command ``some_cmd_<cmd>()`` placeholder without target.
+Command ``some_cmd_<cmd>`` placholder with target.
+Command ``some_cmd()`` with parens.
+Command ``some_cmd(SUB)`` with subcommand.
+Command ``some_cmd(SUB)`` with subcommand and target.
+Command ``some_cmd (SUB)`` with space and subcommand and target.
+Command ``some command`` with space and target.
+Variable ``some variable`` space and target.
+Variable ``<PLACEHOLDER>_VARIABLE`` with leading placeholder.
+Variable ``VARIABLE_<PLACEHOLDER>`` with trailing placeholder.
+Variable ``<PLACEHOLDER>_VARIABLE`` with leading placeholder and target.
+Variable ``VARIABLE_<PLACEHOLDER>`` with trailing placeholder and target.
+Generator ``Some Generator`` with space.
+
+First TOC entry.
+
+|not replaced|
+Second TOC entry.
+
+CMake Module Content
+
+More CMake Module Content
+
+Bracket Comment Content
+
+[
+Bracket Comment Content
+]
+
+.. cmake:command:: some_cmd
+
+ Command some_cmd description.
+
+.. command:: other_cmd
+
+ Command other_cmd description.
+
+.. cmake:variable:: some_var
+
+ Variable some_var description.
+
+.. variable:: other_var
+
+ Variable other_var description.
+
+ Parsed-literal included without directive.
+ Common Indentation Removed
+ # replaced in parsed literal
+
+ # Sample CMake code block
+ if(condition)
+ message(indented)
+ endif()
+ # |not replaced in literal|
+
+A literal block starts after a line consisting of two colons
+
+::
+
+ Literal block.
+ Common Indentation Removed
+ # |not replaced in literal|
+
+or after a paragraph ending in two colons::
+
+ Literal block.
+ Common Indentation Removed
+ # |not replaced in literal|
+
+but not after a line ending in two colons::
+in the middle of a paragraph.
+
+.. productionlist::
+ grammar: `production`
+ production: "content rendered"
+
+.. note::
+ Notes are called out.
+
+substituted text with multiple lines becomes one line
+
+End of first include.
+
+Cross-include substitution text with ``some_cmd()`` reference.
+
+End of second include.
diff --git a/Tests/CMakeLib/testRST.rst b/Tests/CMakeLib/testRST.rst
new file mode 100644
index 0000000000..54952dd9f0
--- /dev/null
+++ b/Tests/CMakeLib/testRST.rst
@@ -0,0 +1,99 @@
+.. index::
+ single: directive ignored
+
+title_text
+----------
+
+.. comment ignored
+..
+ comment ignored
+
+Command :cmake:command:`some_cmd` explicit cmake domain.
+Command :command:`some_cmd` without target.
+Command :command:`some_cmd <some_cmd>` with target.
+Command :command:`some_cmd_<cmd>` placeholder without target.
+Command :command:`some_cmd_<cmd> <some_cmd>` placholder with target.
+Command :command:`some_cmd()` with parens.
+Command :command:`some_cmd(SUB)` with subcommand.
+Command :command:`some_cmd(SUB) <some_cmd>` with subcommand and target.
+Command :command:`some_cmd (SUB) <some_cmd>` with space and subcommand and target.
+Command :command:`some command <some_cmd>` with space and target.
+Variable :variable:`some variable <some_var>` space and target.
+Variable :variable:`<PLACEHOLDER>_VARIABLE` with leading placeholder.
+Variable :variable:`VARIABLE_<PLACEHOLDER>` with trailing placeholder.
+Variable :variable:`<PLACEHOLDER>_VARIABLE <target>` with leading placeholder and target.
+Variable :variable:`VARIABLE_<PLACEHOLDER> <target>` with trailing placeholder and target.
+Generator :generator:`Some Generator` with space.
+
+.. |not replaced| replace:: not replaced through toctree
+.. |not replaced in literal| replace:: replaced in parsed literal
+
+.. toctree::
+ :maxdepth: 2
+
+ testRSTtoc1
+ /testRSTtoc2
+
+.. cmake-module:: testRSTmod.cmake
+
+.. cmake:command:: some_cmd
+
+ Command some_cmd description.
+
+.. command:: other_cmd
+
+ Command other_cmd description.
+
+.. cmake:variable:: some_var
+
+ Variable some_var description.
+
+.. variable:: other_var
+
+ Variable other_var description.
+
+.. parsed-literal::
+
+ Parsed-literal included without directive.
+ Common Indentation Removed
+ # |not replaced in literal|
+
+.. code-block:: cmake
+
+ # Sample CMake code block
+ if(condition)
+ message(indented)
+ endif()
+ # |not replaced in literal|
+
+A literal block starts after a line consisting of two colons
+
+::
+
+ Literal block.
+ Common Indentation Removed
+ # |not replaced in literal|
+
+or after a paragraph ending in two colons::
+
+ Literal block.
+ Common Indentation Removed
+ # |not replaced in literal|
+
+but not after a line ending in two colons::
+in the middle of a paragraph.
+
+.. productionlist::
+ grammar: `production`
+ production: "content rendered"
+
+.. note::
+ Notes are called out.
+
+.. |substitution| replace::
+ |nested substitution|
+ with multiple lines becomes one line
+.. |nested substitution| replace:: substituted text
+
+.. include:: testRSTinclude1.rst
+.. include:: /testRSTinclude2.rst
diff --git a/Tests/CMakeLib/testRSTinclude1.rst b/Tests/CMakeLib/testRSTinclude1.rst
new file mode 100644
index 0000000000..91d394e3a1
--- /dev/null
+++ b/Tests/CMakeLib/testRSTinclude1.rst
@@ -0,0 +1,6 @@
+|substitution|
+
+.. |cross-include substitution| replace:: Cross-include substitution text
+ with :command:`some_cmd` reference.
+
+End of first include.
diff --git a/Tests/CMakeLib/testRSTinclude2.rst b/Tests/CMakeLib/testRSTinclude2.rst
new file mode 100644
index 0000000000..f2d619c4fc
--- /dev/null
+++ b/Tests/CMakeLib/testRSTinclude2.rst
@@ -0,0 +1,3 @@
+|cross-include substitution|
+
+End of second include.
diff --git a/Tests/CMakeLib/testRSTmod.cmake b/Tests/CMakeLib/testRSTmod.cmake
new file mode 100644
index 0000000000..8b807a605d
--- /dev/null
+++ b/Tests/CMakeLib/testRSTmod.cmake
@@ -0,0 +1,11 @@
+#.rst:
+# CMake Module Content
+#.rst:
+# More CMake Module Content
+#[[.rst:
+Bracket Comment Content
+# not part of content]] # not part of content
+#[=[.rst:
+[
+Bracket Comment Content
+]]=] # not part of content
diff --git a/Tests/CMakeLib/testRSTtoc1.rst b/Tests/CMakeLib/testRSTtoc1.rst
new file mode 100644
index 0000000000..fa7806edef
--- /dev/null
+++ b/Tests/CMakeLib/testRSTtoc1.rst
@@ -0,0 +1,2 @@
+.. |not replaced| replace:: not replaced across toctree
+First TOC entry.
diff --git a/Tests/CMakeLib/testRSTtoc2.rst b/Tests/CMakeLib/testRSTtoc2.rst
new file mode 100644
index 0000000000..9fd2fcb196
--- /dev/null
+++ b/Tests/CMakeLib/testRSTtoc2.rst
@@ -0,0 +1,2 @@
+|not replaced|
+Second TOC entry.
diff --git a/Tests/CMakeLib/testSystemTools.cxx b/Tests/CMakeLib/testSystemTools.cxx
new file mode 100644
index 0000000000..9309ae3322
--- /dev/null
+++ b/Tests/CMakeLib/testSystemTools.cxx
@@ -0,0 +1,33 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2011 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 "cmSystemTools.h"
+
+#define cmPassed(m) std::cout << "Passed: " << m << "\n"
+#define cmFailed(m) std::cout << "FAILED: " << m << "\n"; failed=1
+
+int testSystemTools(int, char*[])
+{
+ int failed = 0;
+ // ----------------------------------------------------------------------
+ // Test cmSystemTools::UpperCase
+ std::string str = "abc";
+ std::string strupper = "ABC";
+ if(cmSystemTools::UpperCase(str) == strupper)
+ {
+ cmPassed("cmSystemTools::UpperCase is working");
+ }
+ else
+ {
+ cmFailed("cmSystemTools::UpperCase is working");
+ }
+ return failed;
+}
diff --git a/Tests/CMakeLib/testUTF8.cxx b/Tests/CMakeLib/testUTF8.cxx
new file mode 100644
index 0000000000..4ab96cf01e
--- /dev/null
+++ b/Tests/CMakeLib/testUTF8.cxx
@@ -0,0 +1,125 @@
+/*============================================================================
+ 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 <cm_utf8.h>
+
+#include <string.h>
+#include <stdio.h>
+
+typedef char test_utf8_char[5];
+
+static void test_utf8_char_print(test_utf8_char const c)
+{
+ unsigned char const* d = reinterpret_cast<unsigned char const*>(c);
+ printf("[0x%02X,0x%02X,0x%02X,0x%02X]",
+ (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+}
+
+struct test_utf8_entry
+{
+ int n;
+ test_utf8_char str;
+ unsigned int chr;
+};
+
+static test_utf8_entry const good_entry[] = {
+ {1, "\x20\x00\x00\x00", 0x0020}, /* Space. */
+ {2, "\xC2\xA9\x00\x00", 0x00A9}, /* Copyright. */
+ {3, "\xE2\x80\x98\x00", 0x2018}, /* Open-single-quote. */
+ {3, "\xE2\x80\x99\x00", 0x2019}, /* Close-single-quote. */
+ {4, "\xF0\xA3\x8E\xB4", 0x233B4}, /* Example from RFC 3629. */
+ {0, {0,0,0,0,0}, 0}
+};
+
+static test_utf8_char const bad_chars[] = {
+ "\x80\x00\x00\x00",
+ "\xC0\x00\x00\x00",
+ "\xE0\x00\x00\x00",
+ "\xE0\x80\x80\x00",
+ "\xF0\x80\x80\x80",
+ {0,0,0,0,0}
+};
+
+static void report_good(bool passed, test_utf8_char const c)
+{
+ printf("%s: decoding good ", passed?"pass":"FAIL");
+ test_utf8_char_print(c);
+ printf(" (%s) ", c);
+}
+
+static void report_bad(bool passed, test_utf8_char const c)
+{
+ printf("%s: decoding bad ", passed?"pass":"FAIL");
+ test_utf8_char_print(c);
+ printf(" ");
+}
+
+static bool decode_good(test_utf8_entry const entry)
+{
+ unsigned int uc;
+ if(const char* e = cm_utf8_decode_character(entry.str, entry.str+4, &uc))
+ {
+ int used = static_cast<int>(e-entry.str);
+ if(uc != entry.chr)
+ {
+ report_good(false, entry.str);
+ printf("expected 0x%04X, got 0x%04X\n", entry.chr, uc);
+ return false;
+ }
+ if(used != entry.n)
+ {
+ report_good(false, entry.str);
+ printf("had %d bytes, used %d\n", entry.n, used);
+ return false;
+ }
+ report_good(true, entry.str);
+ printf("got 0x%04X\n", uc);
+ return true;
+ }
+ report_good(false, entry.str);
+ printf("failed\n");
+ return false;
+}
+
+static bool decode_bad(test_utf8_char const s)
+{
+ unsigned int uc = 0xFFFFu;
+ const char* e = cm_utf8_decode_character(s, s+4, &uc);
+ if(e)
+ {
+ report_bad(false, s);
+ printf("expected failure, got 0x%04X\n", uc);
+ return false;
+ }
+ report_bad(true, s);
+ printf("failed as expected\n");
+ return true;
+}
+
+int testUTF8(int, char*[])
+{
+ int result = 0;
+ for(test_utf8_entry const* e = good_entry; e->n; ++e)
+ {
+ if(!decode_good(*e))
+ {
+ result = 1;
+ }
+ }
+ for(test_utf8_char const* c = bad_chars; (*c)[0]; ++c)
+ {
+ if(!decode_bad(*c))
+ {
+ result = 1;
+ }
+ }
+ return result;
+}
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser.cxx b/Tests/CMakeLib/testVisualStudioSlnParser.cxx
new file mode 100644
index 0000000000..5b62f239f7
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser.cxx
@@ -0,0 +1,185 @@
+#include "testVisualStudioSlnParser.h"
+
+#include "cmVisualStudioSlnData.h"
+#include "cmVisualStudioSlnParser.h"
+
+#include <cmsys/ios/iostream>
+
+//----------------------------------------------------------------------------
+static bool parsedRight(cmVisualStudioSlnParser& parser,
+ const std::string& file, cmSlnData& data,
+ cmVisualStudioSlnParser::ParseResult expected =
+ cmVisualStudioSlnParser::ResultOK)
+{
+ if (parser.ParseFile(SOURCE_DIR "/testVisualStudioSlnParser_data/" + file
+ + "." SLN_EXTENSION,
+ data, cmVisualStudioSlnParser::DataGroupProjects))
+ {
+ if (expected == cmVisualStudioSlnParser::ResultOK)
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (parser.GetParseResult() == expected)
+ {
+ return true;
+ }
+ }
+ cmsys_ios::cerr << "cmVisualStudioSlnParser mis-parsed " << file
+ << "." SLN_EXTENSION << "; expected result " << expected
+ << ", got " << parser.GetParseResult()
+ << cmsys_ios::endl;
+ return false;
+}
+
+//----------------------------------------------------------------------------
+int testVisualStudioSlnParser(int, char*[])
+{
+ cmVisualStudioSlnParser parser;
+
+ // Test clean parser
+ if (parser.GetParseResult() != cmVisualStudioSlnParser::ResultOK)
+ {
+ cmsys_ios::cerr << "cmVisualStudioSlnParser initialisation failed"
+ << cmsys_ios::endl;
+ return 1;
+ }
+
+ // Test parsing valid sln
+ {
+ cmSlnData data;
+ if (!parsedRight(parser, "valid", data))
+ {
+ return 1;
+ }
+ const std::vector<cmSlnProjectEntry>& projects = data.GetProjects();
+ const char * const names[] =
+ {
+ "3rdParty", "ALL_BUILD", "CMakeLib", "CMakeLibTests",
+ "CMakePredefinedTargets", "CPackLib", "CTestDashboardTargets", "CTestLib",
+ "Continuous", "Documentation",
+ "Experimental", "INSTALL", "KWSys", "LIBCURL", "Nightly",
+ "NightlyMemoryCheck", "PACKAGE", "RUN_TESTS", "Tests", "Utilities",
+ "Win9xCompat", "ZERO_CHECK", "cmIML_test", "cmake", "cmbzip2", "cmcldeps",
+ "cmcompress", "cmcurl", "cmexpat", "cmlibarchive", "cmsys",
+ "cmsysEncodeExecutable", "cmsysProcessFwd9x", "cmsysTestDynload",
+ "cmsysTestProcess", "cmsysTestSharedForward", "cmsysTestsC",
+ "cmsysTestsCxx", "cmsys_c", "cmw9xcom", "cmzlib", "cpack", "ctest",
+ "documentation", "memcheck_fail", "pseudo_BC", "pseudo_purify",
+ "pseudo_valgrind", "test_clean", "uninstall"
+ };
+ const size_t expectedProjectCount = sizeof(names) / sizeof(*names);
+ if (projects.size() != expectedProjectCount)
+ {
+ cmsys_ios::cerr << "cmVisualStudioSlnParser returned bad number of "
+ << "projects (" << projects.size() << " instead of "
+ << expectedProjectCount << ')'
+ << cmsys_ios::endl;
+ return 1;
+ }
+ for (size_t idx = 0; idx < expectedProjectCount; ++idx)
+ {
+ if (projects[idx].GetName() != names[idx])
+ {
+ cmsys_ios::cerr << "cmVisualStudioSlnParser returned bad project #"
+ << idx << "; expected \"" << names[idx] << "\", got \""
+ << projects[idx].GetName() << '"'
+ << cmsys_ios::endl;
+ return 1;
+ }
+ }
+ if (projects[0].GetRelativePath() != "Utilities\\3rdParty")
+ {
+ cmsys_ios::cerr << "cmVisualStudioSlnParser returned bad relative path of "
+ << "project 3rdParty; expected \"Utilities\\3rdParty\", "
+ << "got \"" << projects[0].GetRelativePath() << '"'
+ << cmsys_ios::endl;
+ return 1;
+ }
+ if (projects[2].GetGUID() != "{59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}")
+ {
+ cmsys_ios::cerr << "cmVisualStudioSlnParser returned bad relative path of "
+ << "project CMakeLib; expected "
+ << "\"{59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}\", "
+ << "got \"" << projects[2].GetGUID() << '"'
+ << cmsys_ios::endl;
+ return 1;
+ }
+ }
+
+ // Test BOM parsing
+ {
+ cmSlnData data;
+
+ if (!parsedRight(parser, "bom", data))
+ {
+ return 1;
+ }
+ if (!parser.GetParseHadBOM())
+ {
+ cmsys_ios::cerr << "cmVisualStudioSlnParser didn't find BOM in bom."
+ << SLN_EXTENSION
+ << cmsys_ios::endl;
+ return 1;
+ }
+
+ if (!parsedRight(parser, "nobom", data))
+ {
+ return 1;
+ }
+ if (parser.GetParseHadBOM())
+ {
+ cmsys_ios::cerr << "cmVisualStudioSlnParser found BOM in nobom."
+ << SLN_EXTENSION
+ << cmsys_ios::endl;
+ return 1;
+ }
+ }
+
+ // Test invalid sln
+ {
+ {
+ cmSlnData data;
+ if (!parsedRight(parser, "err-nonexistent", data,
+ cmVisualStudioSlnParser::ResultErrorOpeningInput))
+ {
+ return 1;
+ }
+ }
+ {
+ cmSlnData data;
+ if (!parsedRight(parser, "err-empty", data,
+ cmVisualStudioSlnParser::ResultErrorReadingInput))
+ {
+ return 1;
+ }
+ }
+ const char * const files[] =
+ {
+ "header", "projectArgs", "topLevel", "projectContents", "projectSection",
+ "global", "unclosed", "strayQuote", "strayParen", "strayQuote2"
+ };
+ for (size_t idx = 0; idx < sizeof(files) / sizeof(files[0]); ++idx)
+ {
+ cmSlnData data;
+ if (!parsedRight(parser, std::string("err-structure-") + files[idx], data,
+ cmVisualStudioSlnParser::ResultErrorInputStructure))
+ {
+ return 1;
+ }
+ }
+ {
+ cmSlnData data;
+ if (!parsedRight(parser, "err-data", data,
+ cmVisualStudioSlnParser::ResultErrorInputData))
+ {
+ return 1;
+ }
+ }
+ }
+
+ // All is well
+ return 0;
+}
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser.h.in b/Tests/CMakeLib/testVisualStudioSlnParser.h.in
new file mode 100644
index 0000000000..62c3f4dcc6
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser.h.in
@@ -0,0 +1,7 @@
+#ifndef testVisualStudioSlnParser_h
+#define testVisualStudioSlnParser_h
+
+#define SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@"
+#define SLN_EXTENSION "sln-file"
+
+#endif
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/.gitattributes b/Tests/CMakeLib/testVisualStudioSlnParser_data/.gitattributes
new file mode 100644
index 0000000000..5be3dc5bcb
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/.gitattributes
@@ -0,0 +1 @@
+*.sln-file -crlf whitespace=cr-at-eol
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/bom.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/bom.sln-file
new file mode 100644
index 0000000000..52c2483f44
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/bom.sln-file
@@ -0,0 +1,2 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-data.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-data.sln-file
new file mode 100644
index 0000000000..bd66ed41da
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-data.sln-file
@@ -0,0 +1,6 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+EndProject
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-empty.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-empty.sln-file
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-empty.sln-file
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-global.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-global.sln-file
new file mode 100644
index 0000000000..32176b882e
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-global.sln-file
@@ -0,0 +1,9 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Global
+EndGlobalSection
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-header.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-header.sln-file
new file mode 100644
index 0000000000..f838a71129
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-header.sln-file
@@ -0,0 +1,4 @@
+Microsoft Visual Studio Solution2 File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+EndProject
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectArgs.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectArgs.sln-file
new file mode 100644
index 0000000000..3e8d35a4f9
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectArgs.sln-file
@@ -0,0 +1,4 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous", "Continuous.vcxproj"
+EndProject
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectContents.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectContents.sln-file
new file mode 100644
index 0000000000..e0d58c92b1
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectContents.sln-file
@@ -0,0 +1,6 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous2", "Continuous2.vcxproj", "{E5071091-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+ EndProject
+EndProject
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectSection.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectSection.sln-file
new file mode 100644
index 0000000000..ed0aa02591
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-projectSection.sln-file
@@ -0,0 +1,11 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZERO_CHECK", "ZERO_CHECK.vcxproj", "{90BC31D7-A3E8-4F04-8049-2236C239A044}"
+ ProjectSection(ProjectDependencies) = postProject
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProject
+EndProject
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayParen.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayParen.sln-file
new file mode 100644
index 0000000000..d2bb9e3e59
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayParen.sln-file
@@ -0,0 +1,4 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}" = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+EndProject
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayQuote.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayQuote.sln-file
new file mode 100644
index 0000000000..3c1a2ecca8
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayQuote.sln-file
@@ -0,0 +1,4 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}
+EndProject
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayQuote2.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayQuote2.sln-file
new file mode 100644
index 0000000000..db8bbcf2c5
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-strayQuote2.sln-file
@@ -0,0 +1,4 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}) = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+EndProject
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-topLevel.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-topLevel.sln-file
new file mode 100644
index 0000000000..1727bf378e
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-topLevel.sln-file
@@ -0,0 +1,4 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+GlobalSection(ExtensibilityGlobals) = postSolution
+EndGlobalSection
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-unclosed.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-unclosed.sln-file
new file mode 100644
index 0000000000..4e6909ef51
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/err-structure-unclosed.sln-file
@@ -0,0 +1,5 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Global
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/nobom.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/nobom.sln-file
new file mode 100644
index 0000000000..fc1e4e947d
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/nobom.sln-file
@@ -0,0 +1,2 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser_data/valid.sln-file b/Tests/CMakeLib/testVisualStudioSlnParser_data/valid.sln-file
new file mode 100644
index 0000000000..7ba28a2f6a
--- /dev/null
+++ b/Tests/CMakeLib/testVisualStudioSlnParser_data/valid.sln-file
@@ -0,0 +1,680 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ALL_BUILD", "ALL_BUILD.vcxproj", "{BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}"
+ ProjectSection(ProjectDependencies) = postProject
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2} = {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}
+ {B025BD09-8389-4D9F-9150-F33418A664B1} = {B025BD09-8389-4D9F-9150-F33418A664B1}
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8} = {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8} = {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}
+ {0283B293-0067-4D02-ADA6-892704398F48} = {0283B293-0067-4D02-ADA6-892704398F48}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B} = {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8} = {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}
+ {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84} = {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C} = {561AD1BB-6DD3-466D-B270-3696DEE8C26C}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3} = {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54} = {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE} = {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996} = {29D5FCAF-20D0-4DEF-8529-F035C249E996}
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591} = {A0421DCA-AC3E-42D0-94AC-379A21A1E591}
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E} = {C6AF7E57-CE57-4462-AE1D-BF520701480E}
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7} = {F2CAAAB3-9568-4284-B8E3-13955183A6D7}
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0} = {D8294E4A-03C5-43D7-AE35-15603F502DC0}
+ {A4921D15-411F-436A-B6F3-F8381652A8E1} = {A4921D15-411F-436A-B6F3-F8381652A8E1}
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C} = {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C} = {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5} = {0E9E295F-3854-415B-AE9F-7B62F17932F5}
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644} = {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}
+ {F77AD922-B4BC-43D7-B268-865312085495} = {F77AD922-B4BC-43D7-B268-865312085495}
+ {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88} = {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}
+ {1DFA0599-77CC-4768-B47A-107EEE86C20C} = {1DFA0599-77CC-4768-B47A-107EEE86C20C}
+ {0E45A3EF-8636-46CF-94A3-7B5CE875DE48} = {0E45A3EF-8636-46CF-94A3-7B5CE875DE48}
+ {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C} = {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CMakeLib", "Source\CMakeLib.vcxproj", "{59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C} = {561AD1BB-6DD3-466D-B270-3696DEE8C26C}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3} = {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54} = {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CMakeLibTests", "Tests\CMakeLib\CMakeLibTests.vcxproj", "{B025BD09-8389-4D9F-9150-F33418A664B1}"
+ ProjectSection(ProjectDependencies) = postProject
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2} = {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C} = {561AD1BB-6DD3-466D-B270-3696DEE8C26C}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3} = {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54} = {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPackLib", "Source\CPackLib.vcxproj", "{94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}"
+ ProjectSection(ProjectDependencies) = postProject
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2} = {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C} = {561AD1BB-6DD3-466D-B270-3696DEE8C26C}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3} = {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54} = {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CTestLib", "Source\CTestLib.vcxproj", "{1002C8FC-7242-4A69-AF51-C59BB10BA6D8}"
+ ProjectSection(ProjectDependencies) = postProject
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2} = {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C} = {561AD1BB-6DD3-466D-B270-3696DEE8C26C}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3} = {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54} = {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Continuous", "Continuous.vcxproj", "{E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Experimental", "Experimental.vcxproj", "{B28E8445-DFD2-46EA-BA6C-C2A1864F2FB1}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "INSTALL", "INSTALL.vcxproj", "{3B126B2D-DEAA-4CDF-9F44-28D3600F5754}"
+ ProjectSection(ProjectDependencies) = postProject
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C} = {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LIBCURL", "Utilities\cmcurl\LIBCURL.vcxproj", "{0283B293-0067-4D02-ADA6-892704398F48}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Nightly", "Nightly.vcxproj", "{7BAF09E0-DCD4-4567-9486-79E1E5F18333}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NightlyMemoryCheck", "NightlyMemoryCheck.vcxproj", "{D0413FDA-31C5-41C2-A53A-C1B87061EC96}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PACKAGE", "PACKAGE.vcxproj", "{4C488FF0-7C06-47FE-A8FD-67DAD51A3E85}"
+ ProjectSection(ProjectDependencies) = postProject
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C} = {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RUN_TESTS", "RUN_TESTS.vcxproj", "{D87B08A8-638E-43FA-96C2-404B41363D3B}"
+ ProjectSection(ProjectDependencies) = postProject
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZERO_CHECK", "ZERO_CHECK.vcxproj", "{90BC31D7-A3E8-4F04-8049-2236C239A044}"
+ ProjectSection(ProjectDependencies) = postProject
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmIML_test", "Utilities\KWIML\test\cmIML_test.vcxproj", "{48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmake", "Source\cmake.vcxproj", "{6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}"
+ ProjectSection(ProjectDependencies) = postProject
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2} = {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C} = {561AD1BB-6DD3-466D-B270-3696DEE8C26C}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3} = {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54} = {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmbzip2", "Utilities\cmbzip2\cmbzip2.vcxproj", "{1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmcldeps", "Source\cmcldeps.vcxproj", "{A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}"
+ ProjectSection(ProjectDependencies) = postProject
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2} = {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C} = {561AD1BB-6DD3-466D-B270-3696DEE8C26C}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3} = {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54} = {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmcompress", "Utilities\cmcompress\cmcompress.vcxproj", "{561AD1BB-6DD3-466D-B270-3696DEE8C26C}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmcurl", "Utilities\cmcurl\cmcurl.vcxproj", "{1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmexpat", "Utilities\cmexpat\cmexpat.vcxproj", "{459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmlibarchive", "Utilities\cmlibarchive\libarchive\cmlibarchive.vcxproj", "{25A91A7A-9C4E-420C-98BD-2D1F0165DA54}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsys", "Source\kwsys\cmsys.vcxproj", "{BDB424DC-15B3-4A06-A1E2-3D61380F359F}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE} = {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996} = {29D5FCAF-20D0-4DEF-8529-F035C249E996}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsysEncodeExecutable", "Source\kwsys\cmsysEncodeExecutable.vcxproj", "{4810B052-899E-4CA5-A0BC-2E383F8AEFAE}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsysProcessFwd9x", "Source\kwsys\cmsysProcessFwd9x.vcxproj", "{29D5FCAF-20D0-4DEF-8529-F035C249E996}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsysTestDynload", "Source\kwsys\cmsysTestDynload.vcxproj", "{A0421DCA-AC3E-42D0-94AC-379A21A1E591}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsysTestProcess", "Source\kwsys\cmsysTestProcess.vcxproj", "{C6AF7E57-CE57-4462-AE1D-BF520701480E}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C} = {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsysTestSharedForward", "Source\kwsys\cmsysTestSharedForward.vcxproj", "{F2CAAAB3-9568-4284-B8E3-13955183A6D7}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C} = {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsysTestsC", "Source\kwsys\cmsysTestsC.vcxproj", "{D8294E4A-03C5-43D7-AE35-15603F502DC0}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C} = {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsysTestsCxx", "Source\kwsys\cmsysTestsCxx.vcxproj", "{A4921D15-411F-436A-B6F3-F8381652A8E1}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsys_c", "Source\kwsys\cmsys_c.vcxproj", "{60BEB3AF-B4EF-4363-8747-C40177BC2D9C}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE} = {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996} = {29D5FCAF-20D0-4DEF-8529-F035C249E996}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmw9xcom", "Source\cmw9xcom.vcxproj", "{ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}"
+ ProjectSection(ProjectDependencies) = postProject
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2} = {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C} = {561AD1BB-6DD3-466D-B270-3696DEE8C26C}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3} = {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54} = {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {BDB424DC-15B3-4A06-A1E2-3D61380F359F}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmzlib", "Utilities\cmzlib\cmzlib.vcxproj", "{0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpack", "Source\cpack.vcxproj", "{0E9E295F-3854-415B-AE9F-7B62F17932F5}"
+ ProjectSection(ProjectDependencies) = postProject
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2} = {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8} = {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ctest", "Source\ctest.vcxproj", "{4BFA4D7C-C6F7-4270-9E87-B922DCE05644}"
+ ProjectSection(ProjectDependencies) = postProject
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2} = {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8} = {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "documentation", "Utilities\documentation.vcxproj", "{F77AD922-B4BC-43D7-B268-865312085495}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8} = {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5} = {0E9E295F-3854-415B-AE9F-7B62F17932F5}
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644} = {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "memcheck_fail", "Tests\CTestTestMemcheck\memcheck_fail.vcxproj", "{8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pseudo_BC", "Tests\CTestTestMemcheck\pseudo_BC.vcxproj", "{1DFA0599-77CC-4768-B47A-107EEE86C20C}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pseudo_purify", "Tests\CTestTestMemcheck\pseudo_purify.vcxproj", "{0E45A3EF-8636-46CF-94A3-7B5CE875DE48}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pseudo_valgrind", "Tests\CTestTestMemcheck\pseudo_valgrind.vcxproj", "{CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_clean", "Tests\test_clean.vcxproj", "{02D16A66-6D59-4A0E-ABB3-BD12926934FE}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "uninstall", "uninstall.vcxproj", "{B5A9B8B7-53AC-46D7-9ADE-76F708A7189C}"
+ ProjectSection(ProjectDependencies) = postProject
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {90BC31D7-A3E8-4F04-8049-2236C239A044}
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CMakePredefinedTargets", "CMakePredefinedTargets", "{31CE49D7-85CA-41E2-83D2-CC6962519DB6}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CTestDashboardTargets", "CTestDashboardTargets", "{BD073C58-BAED-420E-80EA-DC9F52E21AF7}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentation", "{8ECAB3CD-B434-426B-B63A-115919D393BC}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{964DC7DE-990A-4CA4-8395-10D9F9CB2A23}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utilities", "Utilities", "{7E002D15-21D1-4927-B486-82E496444441}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3rdParty", "Utilities\3rdParty", "{0984A63C-130E-4B62-9A94-AAC28A88C137}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "KWSys", "Utilities\KWSys", "{EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Win9xCompat", "Utilities\Win9xCompat", "{2485E202-B981-41E0-98CA-CF363437A4E4}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Release|x64 = Release|x64
+ MinSizeRel|x64 = MinSizeRel|x64
+ RelWithDebInfo|x64 = RelWithDebInfo|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}.Debug|x64.ActiveCfg = Debug|x64
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}.Debug|x64.Build.0 = Debug|x64
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}.Release|x64.ActiveCfg = Release|x64
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}.Release|x64.Build.0 = Release|x64
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {BC04E6F9-A1E4-43BA-88B3-6FBF45FA561C}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}.Debug|x64.ActiveCfg = Debug|x64
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}.Debug|x64.Build.0 = Debug|x64
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}.Release|x64.ActiveCfg = Release|x64
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}.Release|x64.Build.0 = Release|x64
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {B025BD09-8389-4D9F-9150-F33418A664B1}.Debug|x64.ActiveCfg = Debug|x64
+ {B025BD09-8389-4D9F-9150-F33418A664B1}.Debug|x64.Build.0 = Debug|x64
+ {B025BD09-8389-4D9F-9150-F33418A664B1}.Release|x64.ActiveCfg = Release|x64
+ {B025BD09-8389-4D9F-9150-F33418A664B1}.Release|x64.Build.0 = Release|x64
+ {B025BD09-8389-4D9F-9150-F33418A664B1}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {B025BD09-8389-4D9F-9150-F33418A664B1}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {B025BD09-8389-4D9F-9150-F33418A664B1}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {B025BD09-8389-4D9F-9150-F33418A664B1}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}.Debug|x64.ActiveCfg = Debug|x64
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}.Debug|x64.Build.0 = Debug|x64
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}.Release|x64.ActiveCfg = Release|x64
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}.Release|x64.Build.0 = Release|x64
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {94EAABE8-174B-4EE9-8EDF-C5FED49A31B8}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}.Debug|x64.ActiveCfg = Debug|x64
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}.Debug|x64.Build.0 = Debug|x64
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}.Release|x64.ActiveCfg = Release|x64
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}.Release|x64.Build.0 = Release|x64
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {1002C8FC-7242-4A69-AF51-C59BB10BA6D8}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}.Debug|x64.ActiveCfg = Debug|x64
+ {E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}.Release|x64.ActiveCfg = Release|x64
+ {E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {B28E8445-DFD2-46EA-BA6C-C2A1864F2FB1}.Debug|x64.ActiveCfg = Debug|x64
+ {B28E8445-DFD2-46EA-BA6C-C2A1864F2FB1}.Release|x64.ActiveCfg = Release|x64
+ {B28E8445-DFD2-46EA-BA6C-C2A1864F2FB1}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {B28E8445-DFD2-46EA-BA6C-C2A1864F2FB1}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {3B126B2D-DEAA-4CDF-9F44-28D3600F5754}.Debug|x64.ActiveCfg = Debug|x64
+ {3B126B2D-DEAA-4CDF-9F44-28D3600F5754}.Release|x64.ActiveCfg = Release|x64
+ {3B126B2D-DEAA-4CDF-9F44-28D3600F5754}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {3B126B2D-DEAA-4CDF-9F44-28D3600F5754}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {0283B293-0067-4D02-ADA6-892704398F48}.Debug|x64.ActiveCfg = Debug|x64
+ {0283B293-0067-4D02-ADA6-892704398F48}.Debug|x64.Build.0 = Debug|x64
+ {0283B293-0067-4D02-ADA6-892704398F48}.Release|x64.ActiveCfg = Release|x64
+ {0283B293-0067-4D02-ADA6-892704398F48}.Release|x64.Build.0 = Release|x64
+ {0283B293-0067-4D02-ADA6-892704398F48}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {0283B293-0067-4D02-ADA6-892704398F48}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {0283B293-0067-4D02-ADA6-892704398F48}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {0283B293-0067-4D02-ADA6-892704398F48}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {7BAF09E0-DCD4-4567-9486-79E1E5F18333}.Debug|x64.ActiveCfg = Debug|x64
+ {7BAF09E0-DCD4-4567-9486-79E1E5F18333}.Release|x64.ActiveCfg = Release|x64
+ {7BAF09E0-DCD4-4567-9486-79E1E5F18333}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {7BAF09E0-DCD4-4567-9486-79E1E5F18333}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {D0413FDA-31C5-41C2-A53A-C1B87061EC96}.Debug|x64.ActiveCfg = Debug|x64
+ {D0413FDA-31C5-41C2-A53A-C1B87061EC96}.Release|x64.ActiveCfg = Release|x64
+ {D0413FDA-31C5-41C2-A53A-C1B87061EC96}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {D0413FDA-31C5-41C2-A53A-C1B87061EC96}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {4C488FF0-7C06-47FE-A8FD-67DAD51A3E85}.Debug|x64.ActiveCfg = Debug|x64
+ {4C488FF0-7C06-47FE-A8FD-67DAD51A3E85}.Release|x64.ActiveCfg = Release|x64
+ {4C488FF0-7C06-47FE-A8FD-67DAD51A3E85}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {4C488FF0-7C06-47FE-A8FD-67DAD51A3E85}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {D87B08A8-638E-43FA-96C2-404B41363D3B}.Debug|x64.ActiveCfg = Debug|x64
+ {D87B08A8-638E-43FA-96C2-404B41363D3B}.Release|x64.ActiveCfg = Release|x64
+ {D87B08A8-638E-43FA-96C2-404B41363D3B}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {D87B08A8-638E-43FA-96C2-404B41363D3B}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {90BC31D7-A3E8-4F04-8049-2236C239A044}.Debug|x64.ActiveCfg = Debug|x64
+ {90BC31D7-A3E8-4F04-8049-2236C239A044}.Debug|x64.Build.0 = Debug|x64
+ {90BC31D7-A3E8-4F04-8049-2236C239A044}.Release|x64.ActiveCfg = Release|x64
+ {90BC31D7-A3E8-4F04-8049-2236C239A044}.Release|x64.Build.0 = Release|x64
+ {90BC31D7-A3E8-4F04-8049-2236C239A044}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {90BC31D7-A3E8-4F04-8049-2236C239A044}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {90BC31D7-A3E8-4F04-8049-2236C239A044}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {90BC31D7-A3E8-4F04-8049-2236C239A044}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}.Debug|x64.ActiveCfg = Debug|x64
+ {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}.Debug|x64.Build.0 = Debug|x64
+ {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}.Release|x64.ActiveCfg = Release|x64
+ {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}.Release|x64.Build.0 = Release|x64
+ {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {48D43A03-3C1B-439A-9517-8F2A2B4CEC3B}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}.Debug|x64.ActiveCfg = Debug|x64
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}.Debug|x64.Build.0 = Debug|x64
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}.Release|x64.ActiveCfg = Release|x64
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}.Release|x64.Build.0 = Release|x64
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {6ADE54B3-3FDA-4E76-9B87-66D95E5265A8}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}.Debug|x64.ActiveCfg = Debug|x64
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}.Debug|x64.Build.0 = Debug|x64
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}.Release|x64.ActiveCfg = Release|x64
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}.Release|x64.Build.0 = Release|x64
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}.Debug|x64.ActiveCfg = Debug|x64
+ {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}.Debug|x64.Build.0 = Debug|x64
+ {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}.Release|x64.ActiveCfg = Release|x64
+ {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}.Release|x64.Build.0 = Release|x64
+ {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {A51EB64E-E1EA-4B4A-8FDC-56ADFE635E84}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C}.Debug|x64.ActiveCfg = Debug|x64
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C}.Debug|x64.Build.0 = Debug|x64
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C}.Release|x64.ActiveCfg = Release|x64
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C}.Release|x64.Build.0 = Release|x64
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}.Debug|x64.ActiveCfg = Debug|x64
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}.Debug|x64.Build.0 = Debug|x64
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}.Release|x64.ActiveCfg = Release|x64
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}.Release|x64.Build.0 = Release|x64
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}.Debug|x64.ActiveCfg = Debug|x64
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}.Debug|x64.Build.0 = Debug|x64
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}.Release|x64.ActiveCfg = Release|x64
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}.Release|x64.Build.0 = Release|x64
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}.Debug|x64.ActiveCfg = Debug|x64
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}.Debug|x64.Build.0 = Debug|x64
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}.Release|x64.ActiveCfg = Release|x64
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}.Release|x64.Build.0 = Release|x64
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F}.Debug|x64.ActiveCfg = Debug|x64
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F}.Debug|x64.Build.0 = Debug|x64
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F}.Release|x64.ActiveCfg = Release|x64
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F}.Release|x64.Build.0 = Release|x64
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}.Debug|x64.ActiveCfg = Debug|x64
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}.Debug|x64.Build.0 = Debug|x64
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}.Release|x64.ActiveCfg = Release|x64
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}.Release|x64.Build.0 = Release|x64
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996}.Debug|x64.ActiveCfg = Debug|x64
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996}.Debug|x64.Build.0 = Debug|x64
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996}.Release|x64.ActiveCfg = Release|x64
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996}.Release|x64.Build.0 = Release|x64
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591}.Debug|x64.ActiveCfg = Debug|x64
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591}.Debug|x64.Build.0 = Debug|x64
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591}.Release|x64.ActiveCfg = Release|x64
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591}.Release|x64.Build.0 = Release|x64
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E}.Debug|x64.ActiveCfg = Debug|x64
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E}.Debug|x64.Build.0 = Debug|x64
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E}.Release|x64.ActiveCfg = Release|x64
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E}.Release|x64.Build.0 = Release|x64
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7}.Debug|x64.ActiveCfg = Debug|x64
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7}.Debug|x64.Build.0 = Debug|x64
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7}.Release|x64.ActiveCfg = Release|x64
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7}.Release|x64.Build.0 = Release|x64
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0}.Debug|x64.ActiveCfg = Debug|x64
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0}.Debug|x64.Build.0 = Debug|x64
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0}.Release|x64.ActiveCfg = Release|x64
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0}.Release|x64.Build.0 = Release|x64
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {A4921D15-411F-436A-B6F3-F8381652A8E1}.Debug|x64.ActiveCfg = Debug|x64
+ {A4921D15-411F-436A-B6F3-F8381652A8E1}.Debug|x64.Build.0 = Debug|x64
+ {A4921D15-411F-436A-B6F3-F8381652A8E1}.Release|x64.ActiveCfg = Release|x64
+ {A4921D15-411F-436A-B6F3-F8381652A8E1}.Release|x64.Build.0 = Release|x64
+ {A4921D15-411F-436A-B6F3-F8381652A8E1}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {A4921D15-411F-436A-B6F3-F8381652A8E1}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {A4921D15-411F-436A-B6F3-F8381652A8E1}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {A4921D15-411F-436A-B6F3-F8381652A8E1}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}.Debug|x64.ActiveCfg = Debug|x64
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}.Debug|x64.Build.0 = Debug|x64
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}.Release|x64.ActiveCfg = Release|x64
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}.Release|x64.Build.0 = Release|x64
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}.Debug|x64.ActiveCfg = Debug|x64
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}.Debug|x64.Build.0 = Debug|x64
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}.Release|x64.ActiveCfg = Release|x64
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}.Release|x64.Build.0 = Release|x64
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}.Debug|x64.ActiveCfg = Debug|x64
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}.Debug|x64.Build.0 = Debug|x64
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}.Release|x64.ActiveCfg = Release|x64
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}.Release|x64.Build.0 = Release|x64
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5}.Debug|x64.ActiveCfg = Debug|x64
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5}.Debug|x64.Build.0 = Debug|x64
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5}.Release|x64.ActiveCfg = Release|x64
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5}.Release|x64.Build.0 = Release|x64
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {0E9E295F-3854-415B-AE9F-7B62F17932F5}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}.Debug|x64.ActiveCfg = Debug|x64
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}.Debug|x64.Build.0 = Debug|x64
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}.Release|x64.ActiveCfg = Release|x64
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}.Release|x64.Build.0 = Release|x64
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {4BFA4D7C-C6F7-4270-9E87-B922DCE05644}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {F77AD922-B4BC-43D7-B268-865312085495}.Debug|x64.ActiveCfg = Debug|x64
+ {F77AD922-B4BC-43D7-B268-865312085495}.Debug|x64.Build.0 = Debug|x64
+ {F77AD922-B4BC-43D7-B268-865312085495}.Release|x64.ActiveCfg = Release|x64
+ {F77AD922-B4BC-43D7-B268-865312085495}.Release|x64.Build.0 = Release|x64
+ {F77AD922-B4BC-43D7-B268-865312085495}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {F77AD922-B4BC-43D7-B268-865312085495}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {F77AD922-B4BC-43D7-B268-865312085495}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {F77AD922-B4BC-43D7-B268-865312085495}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}.Debug|x64.ActiveCfg = Debug|x64
+ {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}.Debug|x64.Build.0 = Debug|x64
+ {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}.Release|x64.ActiveCfg = Release|x64
+ {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}.Release|x64.Build.0 = Release|x64
+ {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {8DF3790D-AF1B-4505-BA5B-4D61EF9FBE88}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {1DFA0599-77CC-4768-B47A-107EEE86C20C}.Debug|x64.ActiveCfg = Debug|x64
+ {1DFA0599-77CC-4768-B47A-107EEE86C20C}.Debug|x64.Build.0 = Debug|x64
+ {1DFA0599-77CC-4768-B47A-107EEE86C20C}.Release|x64.ActiveCfg = Release|x64
+ {1DFA0599-77CC-4768-B47A-107EEE86C20C}.Release|x64.Build.0 = Release|x64
+ {1DFA0599-77CC-4768-B47A-107EEE86C20C}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {1DFA0599-77CC-4768-B47A-107EEE86C20C}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {1DFA0599-77CC-4768-B47A-107EEE86C20C}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {1DFA0599-77CC-4768-B47A-107EEE86C20C}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {0E45A3EF-8636-46CF-94A3-7B5CE875DE48}.Debug|x64.ActiveCfg = Debug|x64
+ {0E45A3EF-8636-46CF-94A3-7B5CE875DE48}.Debug|x64.Build.0 = Debug|x64
+ {0E45A3EF-8636-46CF-94A3-7B5CE875DE48}.Release|x64.ActiveCfg = Release|x64
+ {0E45A3EF-8636-46CF-94A3-7B5CE875DE48}.Release|x64.Build.0 = Release|x64
+ {0E45A3EF-8636-46CF-94A3-7B5CE875DE48}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {0E45A3EF-8636-46CF-94A3-7B5CE875DE48}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {0E45A3EF-8636-46CF-94A3-7B5CE875DE48}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {0E45A3EF-8636-46CF-94A3-7B5CE875DE48}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}.Debug|x64.ActiveCfg = Debug|x64
+ {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}.Debug|x64.Build.0 = Debug|x64
+ {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}.Release|x64.ActiveCfg = Release|x64
+ {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}.Release|x64.Build.0 = Release|x64
+ {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
+ {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {CAEF2D10-B14D-4E0C-8B79-8AC767B12F7C}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
+ {02D16A66-6D59-4A0E-ABB3-BD12926934FE}.Debug|x64.ActiveCfg = Debug|x64
+ {02D16A66-6D59-4A0E-ABB3-BD12926934FE}.Release|x64.ActiveCfg = Release|x64
+ {02D16A66-6D59-4A0E-ABB3-BD12926934FE}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {02D16A66-6D59-4A0E-ABB3-BD12926934FE}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ {B5A9B8B7-53AC-46D7-9ADE-76F708A7189C}.Debug|x64.ActiveCfg = Debug|x64
+ {B5A9B8B7-53AC-46D7-9ADE-76F708A7189C}.Release|x64.ActiveCfg = Release|x64
+ {B5A9B8B7-53AC-46D7-9ADE-76F708A7189C}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
+ {B5A9B8B7-53AC-46D7-9ADE-76F708A7189C}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {3B126B2D-DEAA-4CDF-9F44-28D3600F5754} = {31CE49D7-85CA-41E2-83D2-CC6962519DB6}
+ {4C488FF0-7C06-47FE-A8FD-67DAD51A3E85} = {31CE49D7-85CA-41E2-83D2-CC6962519DB6}
+ {D87B08A8-638E-43FA-96C2-404B41363D3B} = {31CE49D7-85CA-41E2-83D2-CC6962519DB6}
+ {90BC31D7-A3E8-4F04-8049-2236C239A044} = {31CE49D7-85CA-41E2-83D2-CC6962519DB6}
+ {E5071092-DBFB-49E2-AF0F-E8B0FDEF6C89} = {BD073C58-BAED-420E-80EA-DC9F52E21AF7}
+ {B28E8445-DFD2-46EA-BA6C-C2A1864F2FB1} = {BD073C58-BAED-420E-80EA-DC9F52E21AF7}
+ {7BAF09E0-DCD4-4567-9486-79E1E5F18333} = {BD073C58-BAED-420E-80EA-DC9F52E21AF7}
+ {D0413FDA-31C5-41C2-A53A-C1B87061EC96} = {BD073C58-BAED-420E-80EA-DC9F52E21AF7}
+ {F77AD922-B4BC-43D7-B268-865312085495} = {8ECAB3CD-B434-426B-B63A-115919D393BC}
+ {B025BD09-8389-4D9F-9150-F33418A664B1} = {964DC7DE-990A-4CA4-8395-10D9F9CB2A23}
+ {0984A63C-130E-4B62-9A94-AAC28A88C137} = {7E002D15-21D1-4927-B486-82E496444441}
+ {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54} = {7E002D15-21D1-4927-B486-82E496444441}
+ {2485E202-B981-41E0-98CA-CF363437A4E4} = {7E002D15-21D1-4927-B486-82E496444441}
+ {0283B293-0067-4D02-ADA6-892704398F48} = {0984A63C-130E-4B62-9A94-AAC28A88C137}
+ {1C5345F9-9C47-4F4B-9760-7A74C9D35DE0} = {0984A63C-130E-4B62-9A94-AAC28A88C137}
+ {561AD1BB-6DD3-466D-B270-3696DEE8C26C} = {0984A63C-130E-4B62-9A94-AAC28A88C137}
+ {1342243A-C3D9-45A0-B4BC-65A8F16BCC9D} = {0984A63C-130E-4B62-9A94-AAC28A88C137}
+ {459BD82A-588C-4BFD-B3E6-1E4E3BC1B1E3} = {0984A63C-130E-4B62-9A94-AAC28A88C137}
+ {25A91A7A-9C4E-420C-98BD-2D1F0165DA54} = {0984A63C-130E-4B62-9A94-AAC28A88C137}
+ {0B7FB622-7A90-490C-B4E4-2DE3112BB5E0} = {0984A63C-130E-4B62-9A94-AAC28A88C137}
+ {BDB424DC-15B3-4A06-A1E2-3D61380F359F} = {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}
+ {4810B052-899E-4CA5-A0BC-2E383F8AEFAE} = {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}
+ {29D5FCAF-20D0-4DEF-8529-F035C249E996} = {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}
+ {A0421DCA-AC3E-42D0-94AC-379A21A1E591} = {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}
+ {C6AF7E57-CE57-4462-AE1D-BF520701480E} = {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}
+ {F2CAAAB3-9568-4284-B8E3-13955183A6D7} = {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}
+ {D8294E4A-03C5-43D7-AE35-15603F502DC0} = {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}
+ {A4921D15-411F-436A-B6F3-F8381652A8E1} = {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}
+ {60BEB3AF-B4EF-4363-8747-C40177BC2D9C} = {EF1DFA45-6F7A-4760-8EB5-69A8A221FC54}
+ {ACC30B92-8B65-4A9D-9BF2-6BBD0B008C8C} = {2485E202-B981-41E0-98CA-CF363437A4E4}
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
+ GlobalSection(ExtensibilityAddIns) = postSolution
+ EndGlobalSection
+EndGlobal
diff --git a/Tests/CMakeLib/testXMLParser.cxx b/Tests/CMakeLib/testXMLParser.cxx
new file mode 100644
index 0000000000..54ed5dc90e
--- /dev/null
+++ b/Tests/CMakeLib/testXMLParser.cxx
@@ -0,0 +1,17 @@
+#include "testXMLParser.h"
+
+#include "cmXMLParser.h"
+
+#include <cmsys/ios/iostream>
+
+int testXMLParser(int, char*[])
+{
+ // TODO: Derive from parser and check attributes.
+ cmXMLParser parser;
+ if(!parser.ParseFile(SOURCE_DIR "/testXMLParser.xml"))
+ {
+ cmsys_ios::cerr << "cmXMLParser failed!" << cmsys_ios::endl;
+ return 1;
+ }
+ return 0;
+}
diff --git a/Tests/CMakeLib/testXMLParser.h.in b/Tests/CMakeLib/testXMLParser.h.in
new file mode 100644
index 0000000000..da0b2757bd
--- /dev/null
+++ b/Tests/CMakeLib/testXMLParser.h.in
@@ -0,0 +1,6 @@
+#ifndef testXMLParser_h
+#define testXMLParser_h
+
+#define SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@"
+
+#endif
diff --git a/Tests/CMakeLib/testXMLParser.xml b/Tests/CMakeLib/testXMLParser.xml
new file mode 100644
index 0000000000..5a13f070a4
--- /dev/null
+++ b/Tests/CMakeLib/testXMLParser.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Document>
+ <Element attr="1"/>
+</Document>
diff --git a/Tests/CMakeLib/testXMLSafe.cxx b/Tests/CMakeLib/testXMLSafe.cxx
new file mode 100644
index 0000000000..60442fab7c
--- /dev/null
+++ b/Tests/CMakeLib/testXMLSafe.cxx
@@ -0,0 +1,47 @@
+/*============================================================================
+ 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 <cmXMLSafe.h>
+
+#include "cmStandardIncludes.h"
+
+struct test_pair
+{
+ const char* in;
+ const char* out;
+};
+
+static test_pair const pairs[] = {
+ {"copyright \xC2\xA9", "copyright \xC2\xA9"},
+ {"form-feed \f", "form-feed [NON-XML-CHAR-0xC]"},
+ {"angles <>", "angles &lt;&gt;"},
+ {"ampersand &", "ampersand &amp;"},
+ {"bad-byte \x80", "bad-byte [NON-UTF-8-BYTE-0x80]"},
+ {0,0}
+};
+
+int testXMLSafe(int, char*[])
+{
+ int result = 0;
+ for(test_pair const* p = pairs; p->in; ++p)
+ {
+ cmXMLSafe xs(p->in);
+ cmOStringStream oss;
+ oss << xs;
+ std::string out = oss.str();
+ if(out != p->out)
+ {
+ printf("expected [%s], got [%s]\n", p->out, out.c_str());
+ result = 1;
+ }
+ }
+ return result;
+}
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
new file mode 100644
index 0000000000..25cc846ae1
--- /dev/null
+++ b/Tests/CMakeLists.txt
@@ -0,0 +1,2993 @@
+# a macro for tests that have a simple format where the name matches the
+# directory and project
+macro(ADD_TEST_MACRO NAME COMMAND)
+ string(REPLACE "." "/" dir "${NAME}")
+ string(REGEX REPLACE "[^.]*\\." "" proj "${NAME}")
+ add_test(NAME "${NAME}" COMMAND "${CMAKE_CTEST_COMMAND}"
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/${dir}"
+ "${CMake_BINARY_DIR}/Tests/${dir}"
+ --build-two-config
+ ${build_generator_args}
+ --build-project ${proj}
+ ${${NAME}_CTEST_OPTIONS}
+ --build-options ${build_options}
+ ${${NAME}_BUILD_OPTIONS}
+ --test-command ${COMMAND} ${ARGN})
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${dir}")
+endmacro()
+
+include(${CMAKE_CURRENT_SOURCE_DIR}/RegexEscapeString.cmake)
+
+include(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
+
+# Fake a user home directory to avoid polluting the real one.
+if(DEFINED ENV{HOME} AND NOT CTEST_NO_TEST_HOME)
+ set(TEST_HOME "${CMake_BINARY_DIR}/Tests/CMakeFiles/TestHome")
+ file(MAKE_DIRECTORY "${TEST_HOME}")
+ file(WRITE "${TEST_HOME}/.cvspass" ":pserver:anoncvs@www.cmake.org:/cvsroot/KWSys A\n")
+ set(TEST_HOME_ENV_CODE "# Fake a user home directory to avoid polluting the real one.
+# But provide original ENV{HOME} value in ENV{CTEST_REAL_HOME} for tests that
+# need access to the real HOME directory.
+set(ENV{CTEST_REAL_HOME} \"\$ENV{HOME}\")
+set(ENV{HOME} \"${TEST_HOME}\")
+")
+endif()
+
+# Choose a default configuration for CTest tests.
+set(CTestTest_CONFIG Debug)
+if(NOT CMAKE_CONFIGURATION_TYPES AND CMAKE_BUILD_TYPE)
+ set(CTestTest_CONFIG ${CMAKE_BUILD_TYPE})
+endif()
+
+configure_file(${CMake_SOURCE_DIR}/Tests/EnforceConfig.cmake.in
+ ${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake @ONLY)
+
+# Testing
+if(BUILD_TESTING)
+ set(CMake_TEST_DEVENV "")
+ if(CMAKE_GENERATOR MATCHES "Visual Studio [7-9] " AND
+ NOT CMAKE_MAKE_PROGRAM MATCHES "[mM][sS][bB][uU][iI][lL][dD]\\.[eE][xX][eE]")
+ set(CMake_TEST_DEVENV "${CMAKE_MAKE_PROGRAM}")
+ endif()
+
+ if(CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "")
+ else()
+ set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
+ endif()
+
+ if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles" OR ("${CMAKE_GENERATOR}" MATCHES Ninja AND NOT WIN32))
+ set(TEST_CompileCommandOutput 1)
+ endif()
+ endif()
+
+ set(MAKE_IS_GNU )
+ if(CMAKE_MAKE_PROGRAM MATCHES make)
+ execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} no_such_target --version
+ RESULT_VARIABLE res OUTPUT_VARIABLE out ERROR_VARIABLE out)
+ if("${res}" STREQUAL "0")
+ if("${out}" MATCHES "GNU")
+ set(MAKE_IS_GNU 1)
+ endif()
+ endif()
+ endif()
+
+ # some old versions of make simply cannot handle spaces in paths
+ if (MAKE_IS_GNU OR
+ CMAKE_MAKE_PROGRAM MATCHES "nmake|gmake|wmake" OR
+ CMAKE_GENERATOR MATCHES "Visual Studio|Xcode|Borland")
+ set(MAKE_SUPPORTS_SPACES 1)
+ else()
+ set(MAKE_SUPPORTS_SPACES 0)
+ endif()
+
+ set(build_generator_args
+ --build-generator ${CMAKE_GENERATOR}
+ )
+ if(CMAKE_GENERATOR_PLATFORM)
+ list(APPEND build_generator_args
+ --build-generator-platform ${CMAKE_GENERATOR_PLATFORM}
+ )
+ endif()
+ if(CMAKE_GENERATOR_TOOLSET)
+ list(APPEND build_generator_args
+ --build-generator-toolset ${CMAKE_GENERATOR_TOOLSET}
+ )
+ endif()
+
+ set(build_options)
+ if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
+ list(APPEND build_options -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
+ endif()
+
+ if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ add_subdirectory(CMakeLib)
+ endif()
+ add_subdirectory(CMakeOnly)
+ add_subdirectory(RunCMake)
+
+ add_subdirectory(FindPackageModeMakefileTest)
+
+ if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ add_subdirectory(CTestTestMemcheck)
+ endif()
+
+ # Collect a list of all test build directories.
+ set(TEST_BUILD_DIRS)
+
+ # Should the long tests be run?
+ option(CMAKE_RUN_LONG_TESTS
+ "Should the long tests be run (such as Bootstrap)." ON)
+ mark_as_advanced(CMAKE_RUN_LONG_TESTS)
+
+ if (CMAKE_RUN_LONG_TESTS)
+ option(CTEST_TEST_CTEST
+ "Should the tests that run a full sub ctest process be run?"
+ OFF)
+ mark_as_advanced(CTEST_TEST_CTEST)
+ endif ()
+
+ # Should tests that use CVS be run?
+ #
+ set(do_cvs_tests 0)
+
+ if(EXISTS ${CMAKE_ROOT}/Modules/FindCVS.cmake)
+ find_package(CVS QUIET)
+ else()
+ find_program(CVS_EXECUTABLE NAMES cvs)
+ endif()
+
+ if(CVS_EXECUTABLE)
+ set(do_cvs_tests 1)
+ endif()
+
+ if(do_cvs_tests AND NOT UNIX)
+ if("${CVS_EXECUTABLE}" MATCHES "cygwin")
+ set(do_cvs_tests 0)
+ endif()
+ endif()
+
+ # Should CPack tests be run? By default, yes, but...
+ #
+ # Disable packaging test on Apple 10.3 and below. PackageMaker starts
+ # DiskManagementTool as root and disowns it
+ # (http://lists.apple.com/archives/installer-dev/2005/Jul/msg00005.html).
+ # It is left holding open pipe handles and preventing ProcessUNIX from
+ # detecting end-of-data even after its immediate child exits. Then
+ # the test hangs until it times out and is killed. This is a
+ # well-known bug in kwsys process execution that I would love to get
+ # time to fix.
+ #
+ option(CTEST_TEST_CPACK
+ "Should the tests that use '--build-target package' be run?"
+ ON)
+ mark_as_advanced(CTEST_TEST_CPACK)
+ set(CTEST_TEST_OSX_ARCH 0)
+ if(APPLE)
+ execute_process(
+ COMMAND sw_vers -productVersion
+ OUTPUT_VARIABLE OSX_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(OSX_VERSION MATCHES "^10\\.[0123]" OR OSX_VERSION MATCHES "ProductVersion:\t10\\.[0123]")
+ message(STATUS "Forcing CTEST_TEST_CPACK=OFF on OSX < 10.4")
+ message(STATUS "OSX_VERSION='${OSX_VERSION}'")
+ set(CTEST_TEST_CPACK OFF)
+ else()
+ set(CTEST_TEST_OSX_ARCH 1)
+ endif()
+ endif()
+
+ # Use 1500 or CTEST_TEST_TIMEOUT for long test timeout value,
+ # whichever is greater.
+ set(CMAKE_LONG_TEST_TIMEOUT 1500)
+ if(CTEST_TEST_TIMEOUT)
+ set(CMAKE_LONG_TEST_TIMEOUT ${CTEST_TEST_TIMEOUT})
+ endif()
+ if(CMAKE_LONG_TEST_TIMEOUT LESS 1500)
+ set(CMAKE_LONG_TEST_TIMEOUT 1500)
+ endif()
+
+ add_test(NAME CMake.Copyright
+ COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/CMakeCopyright.cmake)
+
+ # add a bunch of standard build-and-test style tests
+ ADD_TEST_MACRO(CommandLineTest CommandLineTest)
+ ADD_TEST_MACRO(FindPackageTest FindPackageTest)
+ ADD_TEST_MACRO(FindModulesExecuteAll FindModulesExecuteAll)
+ ADD_TEST_MACRO(StringFileTest StringFileTest)
+ ADD_TEST_MACRO(TryCompile TryCompile)
+ ADD_TEST_MACRO(TarTest TarTest)
+ ADD_TEST_MACRO(SystemInformation SystemInformation)
+ ADD_TEST_MACRO(MathTest MathTest)
+ ADD_TEST_MACRO(CompileFeatures CompileFeatures)
+ ADD_TEST_MACRO(CMakeCommands.target_compile_features target_compile_features)
+
+ # assume no resources building to test
+ set(TEST_RESOURCES FALSE)
+ # for windows and cygwin assume we have resources
+ if(WIN32 OR CYGWIN)
+ set(TEST_RESOURCES TRUE)
+ endif()
+ # for borland and watcom there is no resource support
+ if("${CMAKE_GENERATOR}" MATCHES "WMake" OR
+ "${CMAKE_GENERATOR}" MATCHES "Borland")
+ set(TEST_RESOURCES FALSE)
+ endif()
+ if(TEST_RESOURCES)
+ ADD_TEST_MACRO(VSResource VSResource)
+ endif()
+ ADD_TEST_MACRO(Simple Simple)
+ ADD_TEST_MACRO(PreOrder PreOrder)
+ ADD_TEST_MACRO(MissingSourceFile MissingSourceFile)
+ set_tests_properties(MissingSourceFile PROPERTIES
+ PASS_REGULAR_EXPRESSION "CMake Error at CMakeLists.txt:3 \\(add_executable\\):[ \r\n]*Cannot find source file:[ \r\n]*DoesNotExist/MissingSourceFile.c")
+ if(CMAKE_Fortran_COMPILER)
+ ADD_TEST_MACRO(FortranOnly FortranOnly)
+ endif()
+ # test Visual Studio GNU Fortran mixing with cmake_add_fortran_subdirectory
+ # run this project if we have a working fortran compiler or
+ # the test is enabled with CMAKE_TEST_CMAKE_ADD_FORTRAN cache variable.
+ # If you enable the test, CMake should find the MinGW fortran install,
+ # or in some cases you might need to set the PATH so that cmake can find
+ # the gfortran from mingw.
+ if(CMAKE_Fortran_COMPILER OR CMAKE_TEST_CMAKE_ADD_FORTRAN)
+ set(CMAKE_SKIP_VSGNUFortran FALSE)
+ # disable test for apple builds using ifort if they are building
+ # more than one architecture, as ifort does not support that.
+ if(APPLE AND (CMAKE_Fortran_COMPILER MATCHES ifort))
+ list(LENGTH CMAKE_OSX_ARCHITECTURES len)
+ if("${len}" GREATER 1)
+ message(STATUS "Skip VSGNUFortran for ifort dual cpu mac build")
+ set(CMAKE_SKIP_VSGNUFortran TRUE)
+ endif()
+ endif()
+ if((CMAKE_C_COMPILER MATCHES lsb)
+ AND (CMAKE_Fortran_COMPILER MATCHES ifort))
+ message(STATUS "Skip VSGNUFortran for ifort and lsb compilers")
+ set(CMAKE_SKIP_VSGNUFortran TRUE)
+ endif()
+ if(NOT CMAKE_SKIP_VSGNUFortran)
+ ADD_TEST_MACRO(VSGNUFortran ${CMAKE_COMMAND} -P runtest.cmake)
+ endif()
+ endif()
+ ADD_TEST_MACRO(COnly COnly)
+ ADD_TEST_MACRO(CxxOnly CxxOnly)
+ ADD_TEST_MACRO(IPO COnly/COnly)
+ ADD_TEST_MACRO(OutDir runtime/OutDir)
+ ADD_TEST_MACRO(ObjectLibrary UseCshared)
+ ADD_TEST_MACRO(NewlineArgs NewlineArgs)
+ ADD_TEST_MACRO(SetLang SetLang)
+ ADD_TEST_MACRO(EmptyProperty EmptyProperty)
+ ADD_TEST_MACRO(ExternalOBJ ExternalOBJ)
+ if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ ADD_TEST_MACRO(LoadCommand LoadedCommand)
+ endif()
+ ADD_TEST_MACRO(LinkDirectory bin/LinkDirectory)
+ ADD_TEST_MACRO(LinkLanguage LinkLanguage)
+ ADD_TEST_MACRO(LinkLine LinkLine)
+ ADD_TEST_MACRO(MacroTest miniMacroTest)
+ ADD_TEST_MACRO(FunctionTest miniFunctionTest)
+ ADD_TEST_MACRO(ReturnTest ReturnTest)
+ ADD_TEST_MACRO(Properties Properties)
+ ADD_TEST_MACRO(Assembler HelloAsm)
+ ADD_TEST_MACRO(SourceGroups SourceGroups)
+ ADD_TEST_MACRO(Preprocess Preprocess)
+ set(ExportImport_BUILD_OPTIONS -DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
+ ADD_TEST_MACRO(ExportImport ExportImport)
+ ADD_TEST_MACRO(Unset Unset)
+ ADD_TEST_MACRO(PolicyScope PolicyScope)
+ ADD_TEST_MACRO(EmptyLibrary EmptyLibrary)
+ ADD_TEST_MACRO(CompileDefinitions CompileDefinitions)
+ ADD_TEST_MACRO(CompileOptions CompileOptions)
+ ADD_TEST_MACRO(CompatibleInterface CompatibleInterface)
+ ADD_TEST_MACRO(AliasTarget AliasTarget)
+ ADD_TEST_MACRO(StagingPrefix StagingPrefix)
+ ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary)
+ if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
+ set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+ ADD_TEST_MACRO(ConfigSources ConfigSources)
+ endif()
+ ADD_TEST_MACRO(SourcesProperty SourcesProperty)
+ if(CMAKE_CXX_COMPILER_ID STREQUAL GNU
+ AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
+ set(runCxxDialectTest 1)
+ endif()
+ if(CMAKE_CXX_COMPILER_ID STREQUAL Clang
+ AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.9)
+ if(NOT APPLE OR POLICY CMP0025)
+ set(runCxxDialectTest 1)
+ endif()
+ endif()
+ if(runCxxDialectTest)
+ ADD_TEST_MACRO(CxxDialect CxxDialect)
+ endif()
+ set_tests_properties(EmptyLibrary PROPERTIES
+ PASS_REGULAR_EXPRESSION "CMake Error: CMake can not determine linker language for target: test")
+ ADD_TEST_MACRO(CrossCompile CrossCompile)
+ set_tests_properties(CrossCompile PROPERTIES
+ PASS_REGULAR_EXPRESSION "TRY_RUN.. invoked in cross-compiling mode")
+ if("${CMAKE_GENERATOR}" MATCHES "Make")
+ ADD_TEST_MACRO(Policy0002 Policy0002)
+ endif()
+ if(CTEST_TEST_OSX_ARCH)
+ ADD_TEST_MACRO(Architecture Architecture)
+ set_tests_properties(Architecture PROPERTIES
+ PASS_REGULAR_EXPRESSION "(file is not of required architecture|does not match cputype|not the architecture being linked)")
+ endif()
+
+ list(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX})
+
+ if(NOT QT4_FOUND)
+ find_package(Qt4 QUIET)
+ endif()
+
+ if(QT4_FOUND)
+ # test whether the Qt4 which has been found works, on some machines
+ # which run nightly builds there were errors like "wrong file format"
+ # for libQtCore.so. So first check it works, and only if it does add
+ # the automoc test.
+ include(CheckCXXSourceCompiles)
+ set(_save_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
+ set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+
+ set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES})
+ set(CMAKE_REQUIRED_LIBRARIES ${QT_QTCORE_LIBRARIES})
+
+ CHECK_CXX_SOURCE_COMPILES("#include <QCoreApplication>\n int main() {return (qApp == 0 ? 0 : 1); }\n"
+ QT4_WORKS)
+
+ set(CMAKE_REQUIRED_INCLUDES "${_save_CMAKE_REQUIRED_INCLUDES}")
+ set(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}")
+ endif()
+
+ # run test for BundleUtilities on supported platforms/compilers
+ if(MSVC OR
+ MINGW OR
+ CMAKE_SYSTEM_NAME MATCHES "Linux" OR
+ CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ if(NOT "${CMAKE_GENERATOR}" STREQUAL "Watcom WMake")
+
+ add_test(BundleUtilities ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/BundleUtilities"
+ "${CMake_BINARY_DIR}/Tests/BundleUtilities"
+ ${build_generator_args}
+ --build-project BundleUtilities
+ --build-options ${build_options}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities")
+
+ # run test for DeployQt4 on supported platforms/compilers (which depends on BundleUtilities)
+ # this test also depends on the existence of the standard qtiff plugin
+ if(QT4_WORKS AND QT_QTSQL_FOUND)
+ add_test(Qt4Deploy ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Qt4Deploy"
+ "${CMake_BINARY_DIR}/Tests/Qt4Deploy"
+ ${build_generator_args}
+ --build-project Qt4Deploy
+ --build-options ${build_options}
+ -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
+ -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Deploy")
+ endif()
+
+ endif()
+ endif()
+
+ set(CMAKE_BUILD_TEST_SOURCE_DIR "${CMake_SOURCE_DIR}/Tests/COnly")
+ set(CMAKE_BUILD_TEST_BINARY_DIR "${CMake_BINARY_DIR}/Tests/CMakeBuildCOnly")
+ set(CMAKE_BUILD_TEST_EXE COnly)
+ configure_file("${CMake_SOURCE_DIR}/Tests/CMakeBuildTest.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake" @ONLY)
+ add_test(CMakeBuildTest ${CMAKE_CMAKE_COMMAND} -P
+ "${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake")
+ list(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
+ # now do it again for a project that has two project commands
+ set(CMAKE_BUILD_TEST_SOURCE_DIR "${CMake_SOURCE_DIR}/Tests/DoubleProject")
+ set(CMAKE_BUILD_TEST_BINARY_DIR "${CMake_BINARY_DIR}/Tests/DoubleProject")
+ set(CMAKE_BUILD_TEST_EXE just_silly)
+ configure_file("${CMake_SOURCE_DIR}/Tests/CMakeBuildTest.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CMakeBuildDoubleProjectTest.cmake" @ONLY)
+ add_test(CMakeDoubleProject ${CMAKE_CMAKE_COMMAND} -P
+ "${CMake_BINARY_DIR}/Tests/CMakeBuildDoubleProjectTest.cmake")
+ list(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
+
+ ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)
+
+ add_test(Module.ExternalData ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Module/ExternalData"
+ "${CMake_BINARY_DIR}/Tests/Module/ExternalData"
+ ${build_generator_args}
+ --build-project ExternalDataTest
+ --build-noclean
+ --force-new-ctest-process
+ --build-options ${build_options}
+ -DMAKE_SUPPORTS_SPACES=${MAKE_SUPPORTS_SPACES}
+ --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Module/ExternalData")
+
+ ADD_TEST_MACRO(Module.GenerateExportHeader GenerateExportHeader)
+ ADD_TEST_MACRO(Module.FindDependency FindDependency)
+
+ ADD_TEST_MACRO(Module.WriteCompilerDetectionHeader WriteCompilerDetectionHeader)
+
+ if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ include(CheckCXXCompilerFlag)
+ check_cxx_compiler_flag(-fPIE run_pic_test)
+ else()
+ if (CMAKE_CXX_COMPILER_ID MATCHES "PGI"
+ OR CMAKE_CXX_COMPILER_ID MATCHES "PathScale"
+ OR CMAKE_SYSTEM_NAME MATCHES "IRIX64"
+ OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
+ set(run_pic_test 0)
+ else()
+ set(run_pic_test 1)
+ endif()
+ endif()
+
+ if (run_pic_test)
+ ADD_TEST_MACRO(PositionIndependentTargets PositionIndependentTargets)
+ endif()
+
+ if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") AND
+ (NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 4.2) AND
+ (CMAKE_SYSTEM_NAME MATCHES "Linux"))
+
+ include(CheckCXXCompilerFlag)
+ check_cxx_compiler_flag(
+ -fvisibility-inlines-hidden run_inlines_hidden_test)
+ endif()
+
+ if(run_inlines_hidden_test)
+ add_test(VisibilityInlinesHidden ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VisibilityInlinesHidden"
+ "${CMake_BINARY_DIR}/Tests/VisibilityInlinesHidden"
+ ${build_generator_args}
+ --build-project VisibilityInlinesHidden
+ --build-options ${build_options}
+ )
+ list(APPEND TEST_BUILD_DIRS
+ "${CMake_BINARY_DIR}/Tests/VisibilityInlinesHidden"
+ )
+ endif()
+
+ add_test(LinkFlags-prepare
+ ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/LinkFlags"
+ "${CMake_BINARY_DIR}/Tests/LinkFlags"
+ ${build_generator_args}
+ --build-project LinkFlags
+ --build-target LinkFlags
+ --build-options ${build_options}
+ -DTEST_CONFIG=\${CTEST_CONFIGURATION_TYPE}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LinkFlags")
+
+ macro(ADD_LINK_FLAGS_TEST name depends)
+ add_test(LinkFlags-${name}
+ ${CMAKE_CMAKE_COMMAND} --build "${CMake_BINARY_DIR}/Tests/LinkFlags"
+ --target LinkFlags_${name} --config \${CTEST_CONFIGURATION_TYPE}
+ )
+ set_tests_properties(LinkFlags-${name} PROPERTIES
+ PASS_REGULAR_EXPRESSION "BADFLAG" DEPENDS LinkFlags-${depends})
+ endmacro()
+ ADD_LINK_FLAGS_TEST(lib prepare)
+ ADD_LINK_FLAGS_TEST(dll lib)
+ ADD_LINK_FLAGS_TEST(mod dll)
+ ADD_LINK_FLAGS_TEST(exe mod)
+ ADD_LINK_FLAGS_TEST(lib_config exe)
+ ADD_LINK_FLAGS_TEST(dll_config lib_config)
+ ADD_LINK_FLAGS_TEST(mod_config dll_config)
+ ADD_LINK_FLAGS_TEST(exe_config mod_config)
+ ADD_LINK_FLAGS_TEST(lib_flags exe_config)
+ ADD_LINK_FLAGS_TEST(dll_flags lib_flags)
+ ADD_LINK_FLAGS_TEST(mod_flags dll_flags)
+ ADD_LINK_FLAGS_TEST(exe_flags mod_flags)
+ ADD_LINK_FLAGS_TEST(lib_flags_config exe_flags)
+ ADD_LINK_FLAGS_TEST(dll_flags_config lib_flags_config)
+ ADD_LINK_FLAGS_TEST(mod_flags_config dll_flags_config)
+ ADD_LINK_FLAGS_TEST(exe_flags_config mod_flags_config)
+
+ # If we are running right now with a UnixMakefiles based generator,
+ # build the "Simple" test with the ExtraGenerators, if available
+ # This doesn't test whether the generated project files work (unfortunately),
+ # mainly it tests that cmake doesn't crash when generating these project files.
+ if(${CMAKE_GENERATOR} MATCHES "Unix Makefiles" OR ${CMAKE_GENERATOR} MATCHES "KDevelop")
+ # check which generators we have
+ execute_process(COMMAND ${CMAKE_CMAKE_COMMAND} --help
+ OUTPUT_VARIABLE cmakeOutput ERROR_VARIABLE cmakeOutput)
+ # check for the Eclipse generator
+ if ("${cmakeOutput}" MATCHES Eclipse)
+ add_test(Simple_EclipseGenerator ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Simple"
+ "${CMake_BINARY_DIR}/Tests/Simple_EclipseGenerator"
+ --build-two-config
+ --build-generator "Eclipse CDT4 - Unix Makefiles"
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-project Simple
+ --build-options ${build_options}
+ --test-command Simple)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Simple_EclipseGenerator")
+ endif ()
+
+ # check for the CodeBlocks generator
+ if ("${cmakeOutput}" MATCHES CodeBlocks)
+ add_test(Simple_CodeBlocksGenerator ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Simple"
+ "${CMake_BINARY_DIR}/Tests/Simple_CodeBlocksGenerator"
+ --build-two-config
+ --build-generator "CodeBlocks - Unix Makefiles"
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-project Simple
+ --build-options ${build_options}
+ --test-command Simple)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Simple_CodeBlocksGenerator")
+ endif ()
+ # check for the KDevelop3 generator
+ if ("${cmakeOutput}" MATCHES KDevelop3)
+ add_test(Simple_KDevelop3Generator ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Simple"
+ "${CMake_BINARY_DIR}/Tests/Simple_KDevelop3Generator"
+ --build-two-config
+ --build-generator "KDevelop3 - Unix Makefiles"
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-project Simple
+ --build-options ${build_options}
+ --test-command Simple)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Simple_KDevelop3Generator")
+ endif ()
+
+ endif()
+
+ # test for correct sub-project generation
+ # not implemented in VS 6, VS 7.0, Xcode, or Ninja
+ if(NOT CMAKE_GENERATOR MATCHES "Visual Studio [67]$|Xcode|Ninja")
+ # run cmake and configure all of SubProject
+ # but only build the independent executable car
+ add_test(SubProject ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/SubProject"
+ "${CMake_BINARY_DIR}/Tests/SubProject"
+ --build-project SubProject
+ ${build_generator_args}
+ --build-target car
+ --build-options ${build_options}
+ --test-command car
+ )
+
+ # For stage 2, do not run cmake again.
+ # Then build the foo sub project which should build
+ # the bar library which should be referenced because
+ # foo links to the static library bar, but bar is not
+ # directly in the foo sub project
+ if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
+ set(SubProject-Stage2_BUILD_MAKEPROGRAM
+ --build-makeprogram ${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
+ )
+ endif()
+ add_test(SubProject-Stage2 ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/SubProject/foo"
+ "${CMake_BINARY_DIR}/Tests/SubProject/foo"
+ --build-generator ${CMAKE_GENERATOR}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ ${SubProject-Stage2_BUILD_MAKEPROGRAM}
+ --build-nocmake
+ --build-project foo
+ --build-target foo
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/SubProject/foo"
+ --build-options ${build_options}
+ --test-command foo
+ )
+ set_tests_properties ( SubProject-Stage2 PROPERTIES DEPENDS SubProject)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SubProject")
+ endif()
+
+ # macro to add a test that will build a nightly release
+ # of CMake for given platform using the release scripts
+ macro(ADD_NIGHTLY_BUILD_TEST name script)
+ set(_TEST_DIR "${CMake_BINARY_DIR}/Tests/${name}")
+ file(MAKE_DIRECTORY "${_TEST_DIR}")
+ file(WRITE "${_TEST_DIR}/nightly-cmake.sh"
+ "cd ${_TEST_DIR}
+${CMake_BINARY_DIR}/bin/cmake -DCMAKE_CREATE_VERSION=nightly -P ${CMake_SOURCE_DIR}/Utilities/Release/${script}
+${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release/upload_release.cmake
+ ")
+ add_test(${name} /bin/sh ${_TEST_DIR}/nightly-cmake.sh)
+ if(COMMAND SET_TESTS_PROPERTIES AND COMMAND GET_TEST_PROPERTY)
+ set_tests_properties (${name} PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
+ endif()
+ 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
+ dashmacmini5_release.cmake)
+ ADD_NIGHTLY_BUILD_TEST(CMakeNightlyLinux
+ magrathea_release.cmake)
+ endif()
+
+ # add tests with more complex invocations
+ add_test(Framework ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Framework"
+ "${CMake_BINARY_DIR}/Tests/Framework"
+ --build-two-config
+ ${build_generator_args}
+ --build-project Framework
+ --build-options ${build_options}
+ "-DCMAKE_INSTALL_PREFIX:PATH=${CMake_BINARY_DIR}/Tests/Framework/Install"
+ --test-command bar)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Framework")
+
+ add_test(TargetName ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/TargetName"
+ "${CMake_BINARY_DIR}/Tests/TargetName"
+ --build-two-config
+ ${build_generator_args}
+ --build-project TargetName
+ --build-options ${build_options}
+ --test-command ${CMAKE_CMAKE_COMMAND} -E compare_files
+ ${CMake_SOURCE_DIR}/Tests/TargetName/scripts/hello_world
+ ${CMake_BINARY_DIR}/Tests/TargetName/scripts/hello_world)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TargetName")
+
+ add_test(LibName ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/LibName"
+ "${CMake_BINARY_DIR}/Tests/LibName"
+ --build-two-config
+ ${build_generator_args}
+ --build-project LibName
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/LibName/lib"
+ --build-options ${build_options}
+ --test-command foobar
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LibName")
+
+ add_test(CustComDepend ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CustComDepend"
+ "${CMake_BINARY_DIR}/Tests/CustComDepend"
+ --build-two-config
+ ${build_generator_args}
+ --build-project CustComDepend
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustComDepend/bin"
+ --build-options ${build_options}
+ --test-command foo bar.c
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustComDepend")
+
+ add_test(ArgumentExpansion ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/ArgumentExpansion"
+ "${CMake_BINARY_DIR}/Tests/ArgumentExpansion"
+ ${build_generator_args}
+ --build-project ArgumentExpansion
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/ArgumentExpansion/bin"
+ --build-options ${build_options}
+ )
+ set_tests_properties(ArgumentExpansion PROPERTIES
+ FAIL_REGULAR_EXPRESSION "Unexpected: ")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ArgumentExpansion")
+
+ add_test(GeneratorExpression ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/GeneratorExpression"
+ "${CMake_BINARY_DIR}/Tests/GeneratorExpression"
+ ${build_generator_args}
+ --build-project GeneratorExpression
+ --build-options ${build_options}
+ -DCMAKE_BUILD_TYPE=\${CTEST_CONFIGURATION_TYPE}
+ --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/GeneratorExpression")
+
+ add_test(CustomCommand ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CustomCommand"
+ "${CMake_BINARY_DIR}/Tests/CustomCommand"
+ --build-two-config
+ ${build_generator_args}
+ --build-project CustomCommand
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustomCommand/bin"
+ --build-options ${build_options}
+ --test-command CustomCommand
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustomCommand")
+
+ ADD_TEST_MACRO(EmptyDepends ${CMAKE_CTEST_COMMAND})
+
+ add_test(CustomCommandWorkingDirectory ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CustomCommandWorkingDirectory"
+ "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory"
+ --build-two-config
+ ${build_generator_args}
+ --build-project TestWorkingDir
+ --build-options ${build_options}
+ --test-command working
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory")
+
+ #add_test(SimpleExclude ${CMAKE_CTEST_COMMAND}
+ # --build-and-test
+ # "${CMake_SOURCE_DIR}/Tests/SimpleExclude"
+ # "${CMake_BINARY_DIR}/Tests/SimpleExclude"
+ # ${build_generator_args}
+ # --build-project SimpleExclude
+ # --build-two-config
+ # --build-options ${build_options}
+ # --test-command t4
+ #--test-command "${CMAKE_COMMAND}"
+ #"-DCONFIGURATION=\${CTEST_CONFIGURATION_TYPE}"
+ #-P "${CMake_BINARY_DIR}/Tests/SimpleExclude/run.cmake"
+ #)
+
+# add_test(SameName ${CMAKE_CTEST_COMMAND}
+# --build-and-test
+# "${CMake_SOURCE_DIR}/Tests/SameName"
+# "${CMake_BINARY_DIR}/Tests/SameName"
+# ${build_generator_args}
+# --build-project SameName
+# --build-two-config
+# --build-options ${build_options}
+# --test-command
+# "${CMake_BINARY_DIR}/Tests/SameName/Exe1/mytest2")
+
+ add_test(OutOfSource ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/OutOfSource"
+ "${CMake_BINARY_DIR}/Tests/OutOfSource"
+ ${build_generator_args}
+ --build-project OutOfSource
+ --build-two-config
+ --build-options ${build_options}
+ --test-command
+ "${CMake_BINARY_DIR}/Tests/OutOfSource/SubDir/OutOfSourceSubdir/simple")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/OutOfSource")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/OutOfSourceDeep")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/OutOfBinary")
+
+ add_test(BuildDepends ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/BuildDepends"
+ "${CMake_BINARY_DIR}/Tests/BuildDepends"
+ ${build_generator_args}
+ --build-project BuildDepends
+ --build-options ${build_options}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BuildDepends")
+
+ set(SimpleInstallInstallDir
+ "${CMake_BINARY_DIR}/Tests/SimpleInstall/InstallDirectory")
+ add_test(SimpleInstall ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/SimpleInstall"
+ "${CMake_BINARY_DIR}/Tests/SimpleInstall"
+ ${build_generator_args}
+ --build-project TestSimpleInstall
+ --build-two-config
+ --build-options ${build_options}
+ "-DCMAKE_INSTALL_PREFIX:PATH=${SimpleInstallInstallDir}"
+ "-DCTEST_TEST_CPACK:BOOL=${CTEST_TEST_CPACK}"
+ --test-command ${SimpleInstallInstallDir}/MyTest/bin/SimpleInstExe)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SimpleInstall")
+ add_test(SimpleInstall-Stage2 ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/SimpleInstallS2"
+ "${CMake_BINARY_DIR}/Tests/SimpleInstallS2"
+ ${build_generator_args}
+ --build-project TestSimpleInstall
+ --build-two-config
+ --build-options ${build_options}
+ "-DCMAKE_INSTALL_PREFIX:PATH=${SimpleInstallInstallDir}"
+ "-DSTAGE2:BOOL=1"
+ --test-command ${SimpleInstallInstallDir}/MyTest/bin/SimpleInstExeS2)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SimpleInstallS2")
+
+ set(MissingInstallInstallDir
+ "${CMake_BINARY_DIR}/Tests/MissingInstall/InstallDirectory")
+ add_test(MissingInstall ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/MissingInstall"
+ "${CMake_BINARY_DIR}/Tests/MissingInstall"
+ ${build_generator_args}
+ --build-project TestMissingInstall
+ --build-two-config
+ --build-options ${build_options}
+ "-DCMAKE_INSTALL_PREFIX:PATH=${MissingInstallInstallDir}")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/MissingInstall")
+
+ # By default, run the CPackComponents test if the CTEST_TEST_CPACK
+ # option is ON:
+ #
+ set(CTEST_RUN_CPackComponents ${CTEST_TEST_CPACK})
+ set(CTEST_package_X11_TEST ${CTEST_TEST_CPACK})
+ set(CTEST_RUN_CPackComponentsForAll ${CTEST_TEST_CPACK})
+
+ if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT CMAKE_CURRENT_BINARY_DIR MATCHES " ")
+ find_program(RPMBUILD NAMES rpmbuild)
+ endif()
+ # Do not try to build RPM
+ if (NOT RPMBUILD)
+ set(CPACK_BINARY_RPM OFF)
+ endif()
+
+ find_program(NSIS_MAKENSIS_EXECUTABLE NAMES makensis
+ PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
+ DOC "makensis program location"
+ )
+
+ # But on Windows, only run the CPackComponents test if the NSIS
+ # installer builder is available:
+ #
+ if(WIN32)
+ if(NSIS_MAKENSIS_EXECUTABLE)
+ set(CTEST_RUN_CPackComponents ON)
+ else()
+ set(CTEST_RUN_CPackComponents OFF)
+ set(CTEST_package_X11_TEST OFF)
+ endif()
+ endif()
+
+ # On Windows run the CPackWiXGenerator test
+ # if the WiX Toolset seems to be available
+ if(WIN32)
+ file(TO_CMAKE_PATH "$ENV{WIX}" WIX_ROOT)
+
+ find_program(WIX_LIGHT_EXECUTABLE light
+ PATHS "${WIX_ROOT}/bin"
+ DOC "WiX Toolset light.exe location")
+
+ if(WIX_LIGHT_EXECUTABLE)
+ add_test(CPackWiXGenerator ${CMAKE_CTEST_COMMAND}
+ -C \${CTEST_CONFIGURATION_TYPE}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CPackWiXGenerator"
+ "${CMake_BINARY_DIR}/Tests/CPackWiXGenerator"
+ ${build_generator_args}
+ --build-project CPackWiXGenerator
+ --build-options ${build_options}
+ --test-command ${CMAKE_CMAKE_COMMAND}
+ "-DCPackWiXGenerator_BINARY_DIR:PATH=${CMake_BINARY_DIR}/Tests/CPackWiXGenerator"
+ "-Dconfig=\${CTEST_CONFIGURATION_TYPE}"
+ -P "${CMake_SOURCE_DIR}/Tests/CPackWiXGenerator/RunCPackVerifyResult.cmake")
+
+ set_property(TEST CPackWiXGenerator PROPERTY
+ ATTACHED_FILES_ON_FAIL
+ "${CMake_BINARY_DIR}/Tests/CPackWiXGenerator/_CPack_Packages/win32/WIX/wix.log")
+ endif()
+ endif()
+
+ if(CTEST_RUN_CPackComponents)
+ set(CPackComponents_BUILD_OPTIONS)
+ if(APPLE)
+ set(CPackComponents_BUILD_OPTIONS -DCPACK_BINARY_DRAGNDROP:BOOL=ON)
+ endif()
+ if(NSIS_MAKENSIS_EXECUTABLE)
+ set(CPackComponents_BUILD_OPTIONS ${CPackComponents_BUILD_OPTIONS}
+ -DCPACK_BINARY_NSIS:BOOL=ON)
+ endif()
+
+ add_test(CPackComponents ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CPackComponents"
+ "${CMake_BINARY_DIR}/Tests/CPackComponents"
+ ${build_generator_args}
+ --build-project CPackComponents
+ --build-two-config
+ --build-target package
+ --build-options ${build_options}
+ -DCPACK_BINARY_DEB:BOOL=${CPACK_BINARY_DEB}
+ -DCPACK_BINARY_RPM:BOOL=${CPACK_BINARY_RPM}
+ ${CPackComponents_BUILD_OPTIONS}
+ --graphviz=CPackComponents.dot
+ --test-command ${CMAKE_CMAKE_COMMAND}
+ "-DCPackComponents_BINARY_DIR:PATH=${CMake_BINARY_DIR}/Tests/CPackComponents"
+ -P "${CMake_SOURCE_DIR}/Tests/CPackComponents/VerifyResult.cmake")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackComponents")
+ endif()
+
+ if(CTEST_RUN_CPackComponentsForAll)
+ # Check whether if rpmbuild command is found
+ # before adding RPM tests
+ find_program(RPMBUILD_EXECUTABLE NAMES rpmbuild)
+ if(RPMBUILD_EXECUTABLE)
+ list(APPEND ACTIVE_CPACK_GENERATORS RPM)
+ endif()
+ # Check whether if dpkg command is found
+ # before adding DEB tests
+ find_program(DPKG_EXECUTABLE NAMES dpkg)
+ if(DPKG_EXECUTABLE)
+ list(APPEND ACTIVE_CPACK_GENERATORS DEB)
+ endif()
+
+ # ACTIVE_CPACK_GENERATORS variable
+ # now contains the list of 'active generators'
+ set(CPackComponentsForAll_BUILD_OPTIONS)
+ # set up list of CPack generators
+ list(APPEND GENLST "ZIP")
+ if(APPLE)
+ list(APPEND GENLST "DragNDrop")
+ endif()
+ if (NOT CMAKE_CURRENT_BINARY_DIR MATCHES " ")
+ list(FIND ACTIVE_CPACK_GENERATORS "RPM" RPM_ACTIVE)
+ if (NOT ${RPM_ACTIVE} EQUAL -1)
+ list(APPEND GENLST "RPM")
+ endif()
+ endif()
+ list(FIND ACTIVE_CPACK_GENERATORS "DEB" DEB_ACTIVE)
+ if (NOT ${DEB_ACTIVE} EQUAL -1)
+ list(APPEND GENLST "DEB")
+ endif()
+
+ # set up list of component packaging ways
+ list(APPEND CWAYLST "default")
+ list(APPEND CWAYLST "OnePackPerGroup")
+ list(APPEND CWAYLST "IgnoreGroup")
+ list(APPEND CWAYLST "AllInOne")
+ foreach(CPackGen ${GENLST})
+ set(CPackRun_CPackGen "-DCPackGen=${CPackGen}")
+ foreach(CPackComponentWay ${CWAYLST})
+ set(CPackRun_CPackComponentWay "-DCPackComponentWay=${CPackComponentWay}")
+ add_test(CPackComponentsForAll-${CPackGen}-${CPackComponentWay} ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CPackComponentsForAll"
+ "${CMake_BINARY_DIR}/Tests/CPackComponentsForAll/build${CPackGen}-${CPackComponentWay}"
+ ${build_generator_args}
+ --build-project CPackComponentsForAll
+ --build-options ${build_options}
+ -DCPACK_BINARY_${CPackGen}:BOOL=ON
+ ${CPackRun_CPackComponentWay}
+ ${CPackComponentsForAll_BUILD_OPTIONS}
+ --graphviz=CPackComponentsForAll.dot
+ --test-command ${CMAKE_CMAKE_COMMAND}
+ "-DCPackComponentsForAll_BINARY_DIR:PATH=${CMake_BINARY_DIR}/Tests/CPackComponentsForAll/build${CPackGen}-${CPackComponentWay}"
+ "${CPackRun_CPackGen}"
+ "${CPackRun_CPackComponentWay}"
+ -P "${CMake_SOURCE_DIR}/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackComponentsForAll/build${CPackGen}-${CPackComponentWay}")
+ endforeach()
+ endforeach()
+ endif()
+
+ # By default, turn this test off (because it takes a long time...)
+ #
+ if(NOT DEFINED CTEST_RUN_CPackTestAllGenerators)
+ set(CTEST_RUN_CPackTestAllGenerators OFF)
+
+ # ...but: if it appears to be a coverage dashboard, or long tests are
+ # on, then set it to the generic CTEST_TEST_CPACK setting.
+ #
+ if(CMAKE_CXX_FLAGS MATCHES "-ftest-coverage" OR
+ NOT "$ENV{COVFILE}" STREQUAL "" OR
+ CMAKE_RUN_LONG_TESTS)
+ set(CTEST_RUN_CPackTestAllGenerators ${CTEST_TEST_CPACK})
+ endif()
+ endif()
+
+ if(CTEST_RUN_CPackTestAllGenerators)
+ add_test(CPackTestAllGenerators ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CPackTestAllGenerators"
+ "${CMake_BINARY_DIR}/Tests/CPackTestAllGenerators"
+ ${build_generator_args}
+ --build-project CPackTestAllGenerators
+ --build-options ${build_options}
+ --test-command
+ ${CMAKE_CMAKE_COMMAND}
+ -D dir=${CMake_BINARY_DIR}/Tests/CPackTestAllGenerators
+ -P ${CMake_SOURCE_DIR}/Tests/CPackTestAllGenerators/RunCPack.cmake
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackTestAllGenerators")
+ endif()
+
+ if(CTEST_package_X11_TEST)
+ set(X11_build_target_arg --build-target package)
+ else()
+ set(X11_build_target_arg)
+ endif()
+
+ add_test(X11 ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/X11"
+ "${CMake_BINARY_DIR}/Tests/X11"
+ ${build_generator_args}
+ --build-project UseX11
+ --build-two-config
+ ${X11_build_target_arg}
+ --build-options ${build_options}
+ --test-command UseX11)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/X11")
+
+ if(NOT DEFINED CTEST_RUN_CMakeTestAllGenerators)
+ set(CTEST_RUN_CMakeTestAllGenerators ON)
+ endif()
+
+ if(CTEST_RUN_CMakeTestAllGenerators)
+ add_test(CMakeTestAllGenerators ${CMAKE_CMAKE_COMMAND}
+ -D dir=${CMake_BINARY_DIR}/Tests/CMakeTestAllGenerators
+ -D CMake_SOURCE_DIR=${CMake_SOURCE_DIR}
+ -P ${CMake_SOURCE_DIR}/Tests/CMakeTestAllGenerators/RunCMake.cmake
+ )
+ list(APPEND TEST_BUILD_DIRS
+ "${CMake_BINARY_DIR}/Tests/CMakeTestAllGenerators")
+ endif()
+
+ if(NOT DEFINED CTEST_RUN_CMakeTestBadCommandLines)
+ set(CTEST_RUN_CMakeTestBadCommandLines ON)
+ endif()
+
+ if(CTEST_RUN_CMakeTestBadCommandLines)
+ add_test(CMakeTestBadCommandLines ${CMAKE_CMAKE_COMMAND}
+ -D dir=${CMake_BINARY_DIR}/Tests/CMakeTestBadCommandLines
+ -D gen=${CMAKE_GENERATOR}
+ -D CMake_SOURCE_DIR=${CMake_SOURCE_DIR}
+ -P ${CMake_SOURCE_DIR}/Tests/CMakeTestBadCommandLines/RunCMake.cmake
+ )
+ list(APPEND TEST_BUILD_DIRS
+ "${CMake_BINARY_DIR}/Tests/CMakeTestBadCommandLines")
+ endif()
+
+ if(NOT DEFINED CTEST_RUN_CMakeTestMultipleConfigures)
+ set(CTEST_RUN_CMakeTestMultipleConfigures ON)
+ endif()
+
+ if(CTEST_RUN_CMakeTestMultipleConfigures)
+ add_test(CMakeTestMultipleConfigures ${CMAKE_CMAKE_COMMAND}
+ -D dir=${CMake_BINARY_DIR}/Tests/CMakeTestMultipleConfigures
+ -D gen=${CMAKE_GENERATOR}
+ -D CMake_SOURCE_DIR=${CMake_SOURCE_DIR}
+ -P ${CMake_SOURCE_DIR}/Tests/CMakeTestMultipleConfigures/RunCMake.cmake
+ )
+ list(APPEND TEST_BUILD_DIRS
+ "${CMake_BINARY_DIR}/Tests/CMakeTestMultipleConfigures")
+ endif()
+
+ if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ add_test(LoadedCommandOneConfig ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/LoadCommandOneConfig"
+ "${CMake_BINARY_DIR}/Tests/LoadCommandOneConfig"
+ ${build_generator_args}
+ --build-project LoadCommand
+ --build-options ${build_options}
+ --test-command LoadedCommand
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LoadCommandOneConfig")
+ endif()
+
+ add_test(complex ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Complex"
+ "${CMake_BINARY_DIR}/Tests/Complex"
+ --build-two-config
+ --build-config-sample "${CMAKE_CTEST_COMMAND}"
+ ${build_generator_args}
+ --build-project Complex
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Complex/bin"
+ --build-options ${build_options}
+ -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
+ --test-command complex
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Complex")
+
+ add_test(complexOneConfig ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/ComplexOneConfig"
+ "${CMake_BINARY_DIR}/Tests/ComplexOneConfig"
+ ${build_generator_args}
+ --build-project Complex
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/ComplexOneConfig/bin"
+ --build-options ${build_options}
+ -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
+ --test-command complex)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ComplexOneConfig")
+ # because of the registry write these tests depend on each other
+ set_tests_properties ( complex PROPERTIES DEPENDS complexOneConfig)
+
+ add_test(Environment ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Environment"
+ "${CMake_BINARY_DIR}/Tests/Environment"
+ ${build_generator_args}
+ --build-project EnvironmentProj
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Environment"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Environment")
+
+ add_test(QtAutomocNoQt ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/QtAutomocNoQt"
+ "${CMake_BINARY_DIR}/Tests/QtAutomocNoQt"
+ ${build_generator_args}
+ --build-project QtAutomocNoQt
+ --build-options ${build_options}
+ -DCMAKE_BUILD_TYPE=\${CTEST_CONFIGURATION_TYPE}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/QtAutomocNoQt")
+
+ # On Windows there is no RPATH, so while Qt might be available for building,
+ # the required dlls may not be in the PATH, so we can't run the executables
+ # on that platform.
+ if(WIN32)
+ set(run_autogen_test ${CMAKE_CTEST_COMMAND} -V)
+ set(run_autouic_test ${CMAKE_CTEST_COMMAND} -V)
+ else()
+ set(run_autogen_test QtAutogen)
+ set(run_autouic_test QtAutoUicInterface)
+ endif()
+
+ find_package(Qt5Widgets QUIET NO_MODULE)
+ if(Qt5Widgets_FOUND)
+ add_test(Qt5Autogen ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/QtAutogen"
+ "${CMake_BINARY_DIR}/Tests/Qt5Autogen"
+ ${build_generator_args}
+ --build-project QtAutogen
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt5Autogen"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=5
+ --test-command ${run_autogen_test}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt5Autogen")
+
+ add_test(Qt5AutoUicInterface ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/QtAutoUicInterface"
+ "${CMake_BINARY_DIR}/Tests/Qt5AutoUicInterface"
+ ${build_generator_args}
+ --build-project QtAutoUicInterface
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt5AutoUicInterface"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=5
+ --test-command ${run_autouic_test}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt5AutoUicInterface")
+ endif()
+ if(QT4_WORKS AND QT_QTGUI_FOUND)
+ add_test(Qt4Autogen ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/QtAutogen"
+ "${CMake_BINARY_DIR}/Tests/Qt4Autogen"
+ ${build_generator_args}
+ --build-project QtAutogen
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4Autogen"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=4
+ --test-command ${run_autogen_test}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Autogen")
+
+ add_test(Qt4AutoUicInterface ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/QtAutoUicInterface"
+ "${CMake_BINARY_DIR}/Tests/Qt4AutoUicInterface"
+ ${build_generator_args}
+ --build-project QtAutoUicInterface
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4AutoUicInterface"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=4
+ --test-command ${run_autouic_test}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4AutoUicInterface")
+
+ add_test(Qt4Targets ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Qt4Targets"
+ "${CMake_BINARY_DIR}/Tests/Qt4Targets"
+ ${build_generator_args}
+ --build-project Qt4Targets
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4Targets"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Targets")
+
+ if(Qt5Widgets_FOUND AND NOT Qt5Widgets_VERSION VERSION_LESS 5.1.0)
+ add_test(Qt4And5Automoc ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Qt4And5Automoc"
+ "${CMake_BINARY_DIR}/Tests/Qt4And5Automoc"
+ ${build_generator_args}
+ --build-project Qt4And5Automoc
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4And5Automoc"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4And5Automoc")
+ add_test(Qt4And5AutomocReverse ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Qt4And5Automoc"
+ "${CMake_BINARY_DIR}/Tests/Qt4And5AutomocReverse"
+ ${build_generator_args}
+ --build-project Qt4And5Automoc
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4And5AutomocReverse"
+ --force-new-ctest-process
+ --build-options ${build_options} -DQT_REVERSE_FIND_ORDER=1
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4And5AutomocReverse")
+ endif()
+ endif()
+
+ find_package(GTK2 QUIET)
+ if(GTK2_FOUND)
+ add_subdirectory(FindGTK2)
+ endif()
+
+ add_test(ExternalProject ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/ExternalProject"
+ "${CMake_BINARY_DIR}/Tests/ExternalProject"
+ ${build_generator_args}
+ --build-project ExternalProjectTest
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/ExternalProject"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProject")
+ set_tests_properties(ExternalProject PROPERTIES
+ TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
+
+ add_test(ExternalProjectLocal ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/ExternalProjectLocal"
+ "${CMake_BINARY_DIR}/Tests/ExternalProjectLocal"
+ ${build_generator_args}
+ --build-project ExternalProjectLocalTest
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/ExternalProjectLocal"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectLocal")
+ set_tests_properties(ExternalProjectLocal PROPERTIES
+ TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
+
+ add_test(ExternalProjectUpdateSetup ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/ExternalProjectUpdate"
+ "${CMake_BINARY_DIR}/Tests/ExternalProjectUpdate"
+ ${build_generator_args}
+ --build-project ExternalProjectUpdateTest
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/ExternalProjectUpdate"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectUpdate")
+ set_tests_properties(ExternalProjectUpdateSetup PROPERTIES
+ TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
+
+ add_test(NAME ExternalProjectUpdate
+ COMMAND ${CMAKE_CMAKE_COMMAND}
+ -DExternalProjectUpdate_SOURCE_DIR:PATH=${CMake_SOURCE_DIR}/Tests/ExternalProjectUpdate
+ -DExternalProjectUpdate_BINARY_DIR:PATH=${CMake_BINARY_DIR}/Tests/ExternalProjectUpdate
+ -DCMAKE_GENERATOR=${CMAKE_GENERATOR}
+ -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
+ -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
+ -DCMAKE_CTEST_COMMAND=${CMAKE_CTEST_COMMAND}
+ -P ${CMake_SOURCE_DIR}/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectUpdate")
+ set_tests_properties(ExternalProjectUpdate PROPERTIES
+ TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT}
+ WORKING_DIRECTORY ${CMake_SOURCE_DIR}/Tests/ExternalProjectUpdate
+ DEPENDS ExternalProjectUpdateSetup )
+
+ # do each of the tutorial steps
+ foreach(STP RANGE 1 7)
+ add_test(TutorialStep${STP} ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Tutorial/Step${STP}"
+ "${CMake_BINARY_DIR}/Tests/Tutorial/Step${STP}"
+ --build-two-config
+ ${build_generator_args}
+ --build-project Tutorial
+ --build-options ${build_options}
+ --test-command Tutorial 25.0)
+ endforeach()
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Tutorial")
+
+ add_test(testing ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Testing"
+ "${CMake_BINARY_DIR}/Tests/Testing"
+ ${build_generator_args}
+ --build-project Testing
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
+ )
+ set_tests_properties(testing PROPERTIES PASS_REGULAR_EXPRESSION "Passed")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Testing")
+
+ add_test(wrapping ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Wrapping"
+ "${CMake_BINARY_DIR}/Tests/Wrapping"
+ ${build_generator_args}
+ --build-project Wrapping
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
+ --build-options ${build_options}
+ --test-command wrapping
+ )
+ add_test(qtwrapping ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Wrapping"
+ "${CMake_BINARY_DIR}/Tests/Wrapping"
+ ${build_generator_args}
+ --build-project Wrapping
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
+ --build-options ${build_options}
+ --test-command qtwrapping
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Wrapping")
+
+ add_test(testdriver1 ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/TestDriver"
+ "${CMake_BINARY_DIR}/Tests/TestDriver"
+ ${build_generator_args}
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
+ --build-project TestDriverTest
+ --build-options ${build_options}
+ --test-command TestDriverTest test1
+ )
+
+ add_test(testdriver2 ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/TestDriver"
+ "${CMake_BINARY_DIR}/Tests/TestDriver"
+ ${build_generator_args}
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
+ --build-project TestDriverTest
+ --build-options ${build_options}
+ --test-command TestDriverTest test2
+ )
+
+ add_test(testdriver3 ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/TestDriver"
+ "${CMake_BINARY_DIR}/Tests/TestDriver"
+ ${build_generator_args}
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
+ --build-project TestDriverTest
+ --build-options ${build_options}
+ --test-command TestDriverTest subdir/test3
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TestDriver")
+
+ add_test(Dependency ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Dependency"
+ "${CMake_BINARY_DIR}/Tests/Dependency"
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Dependency/Exec"
+ ${build_generator_args}
+ --build-project Dependency
+ --build-options ${build_options}
+ --test-command exec
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Dependency")
+
+ if(CMAKE_SYSTEM_NAME MATCHES syllable)
+
+# RPATH isn't supported under Syllable, so the tests don't
+# find their libraries. In order to fix that LIBRARY_OUTPUT_DIR
+# in the tests would have to be adjusted to ${EXECUTABLE_OUTPUT_DIR}/lib .
+# For now we just require on Syllable that the user adjusts the DLL_PATH
+# environment variable, so except the two tests below all other tests will succeed.
+
+ set(_DLL_PATH "$ENV{DLL_PATH}")
+ if(NOT "${_DLL_PATH}" MATCHES "^(.*:)?\\@bindir\\@/\\.(:.*)?$")
+ message(FATAL_ERROR "In order to successfully run the CMake test suite on Syllable you need to add \"\\@bindir\\@/.\" to the DLL_PATH environment variable")
+ endif()
+ if(NOT "${_DLL_PATH}" MATCHES "^(.*:)?\\@bindir\\@/\\.\\./lib(:.*)?$")
+ message(FATAL_ERROR "In order to successfully run the CMake test suite on Syllable you need to add \"\\@bindir\\@/../lib\" to the DLL_PATH environment variable")
+ endif()
+
+ else()
+
+ add_test(JumpWithLibOut ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Jump"
+ "${CMake_BINARY_DIR}/Tests/Jump/WithLibOut"
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Jump/WithLibOut/Executable"
+ --build-project Jump
+ ${build_generator_args}
+ --build-options ${build_options}
+ -DLIBRARY_OUTPUT_PATH:PATH=${CMake_BINARY_DIR}/Tests/Jump/WithLibOut/Lib
+ --test-command jumpExecutable
+ )
+
+ add_test(JumpNoLibOut ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Jump"
+ "${CMake_BINARY_DIR}/Tests/Jump/NoLibOut"
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Jump/NoLibOut/Executable"
+ --build-run-dir "${CMake_BINARY_DIR}/Tests/Jump/NoLibOut/Executable"
+ --build-project Jump
+ ${build_generator_args}
+ --build-options ${build_options}
+ --test-command jumpExecutable
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Jump")
+
+ add_test(Plugin ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Plugin"
+ "${CMake_BINARY_DIR}/Tests/Plugin"
+ ${build_generator_args}
+ --build-project Plugin
+ --build-two-config
+ --build-options ${build_options}
+ --test-command bin/example)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Plugin")
+
+ if(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
+ ADD_TEST_MACRO(RuntimePath RuntimePath)
+ endif()
+ endif()
+
+ if(APPLE AND "${DARWIN_MAJOR_VERSION}" GREATER 9)
+ add_test(MacRuntimePath ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/MacRuntimePath"
+ "${CMake_BINARY_DIR}/Tests/MacRuntimePath"
+ ${build_generator_args}
+ --build-project MacRuntimePath
+ --build-options ${build_options}
+ -DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
+ )
+ endif()
+
+ add_test(linkorder1 ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/LinkLineOrder"
+ "${CMake_BINARY_DIR}/Tests/LinkLineOrder"
+ ${build_generator_args}
+ --build-project LinkLineOrder
+ --build-options ${build_options}
+ --test-command Exec1
+ )
+
+ add_test(linkorder2 ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/LinkLineOrder"
+ "${CMake_BINARY_DIR}/Tests/LinkLineOrder"
+ ${build_generator_args}
+ --build-project LinkLineOrder
+ --build-options ${build_options}
+ --test-command Exec2
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LinkLineOrder")
+ set_tests_properties ( qtwrapping PROPERTIES DEPENDS wrapping)
+ set_tests_properties ( testdriver1 PROPERTIES DEPENDS qtwrapping)
+ set_tests_properties ( testdriver2 PROPERTIES DEPENDS testdriver1)
+ set_tests_properties ( testdriver3 PROPERTIES DEPENDS testdriver2)
+ set_tests_properties ( linkorder2 PROPERTIES DEPENDS linkorder1)
+ set_tests_properties ( SimpleInstall-Stage2 PROPERTIES DEPENDS SimpleInstall)
+
+ # Test static linking on toolchains known to support it.
+ if("${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU)$"
+ AND NOT APPLE AND NOT WIN32 AND NOT CYGWIN
+ AND EXISTS "/usr/lib/libm.a")
+ add_test(LinkStatic ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/LinkStatic"
+ "${CMake_BINARY_DIR}/Tests/LinkStatic"
+ ${build_generator_args}
+ --build-project LinkStatic
+ --build-options ${build_options}
+ -DMATH_LIBRARY:FILEPATH=/usr/lib/libm.a
+ --test-command LinkStatic
+ )
+ endif()
+
+ if(MAKE_SUPPORTS_SPACES AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
+ add_test(SubDirSpaces ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/SubDirSpaces"
+ "${CMake_BINARY_DIR}/Tests/SubDirSpaces"
+ --build-exe-dir
+ "${CMake_BINARY_DIR}/Tests/SubDirSpaces/Executable Sources"
+ ${build_generator_args}
+ --build-project SUBDIR
+ --build-options ${build_options}
+ --test-command test
+ "${CMake_BINARY_DIR}/Tests/SubDirSpaces/ShouldBeHere"
+ "${CMake_BINARY_DIR}/Tests/SubDirSpaces/testfromsubdir.obj"
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SubDirSpaces")
+ endif ()
+
+ if (WIN32)
+ add_test(SubDir ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/SubDir"
+ "${CMake_BINARY_DIR}/Tests/SubDir"
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/SubDir/Executable"
+ ${build_generator_args}
+ --build-project SUBDIR
+ --build-options ${build_options}
+ --test-command test
+ "${CMake_BINARY_DIR}/Tests/SubDir/ShouldBeHere"
+ "${CMake_BINARY_DIR}/Tests/SubDir/testfromsubdir.obj"
+ )
+ else ()
+ add_test(SubDir ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/SubDir"
+ "${CMake_BINARY_DIR}/Tests/SubDir"
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/SubDir/Executable"
+ ${build_generator_args}
+ --build-project SUBDIR
+ --build-options ${build_options}
+ --test-command test
+ "${CMake_BINARY_DIR}/Tests/SubDir/ShouldBeHere"
+ "${CMake_BINARY_DIR}/Tests/SubDir/testfromsubdir.o"
+ )
+ endif ()
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SubDir")
+
+ if(MSVC)
+ ADD_TEST_MACRO(ForceInclude foo)
+ ADD_TEST_MACRO(PDBDirectoryAndName myexe)
+ ADD_TEST_MACRO(PrecompiledHeader foo)
+ endif()
+ if(MSVC OR
+ "${CMAKE_GENERATOR}" MATCHES "(MSYS|MinGW) Makefiles")
+ ADD_TEST_MACRO(ModuleDefinition example_exe)
+ endif()
+
+ ADD_TEST_MACRO(CheckCompilerRelatedVariables CheckCompilerRelatedVariables)
+
+ if("${CMAKE_GENERATOR}" MATCHES "Makefile")
+ add_test(MakeClean ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/MakeClean"
+ "${CMake_BINARY_DIR}/Tests/MakeClean"
+ ${build_generator_args}
+ --build-project MakeClean
+ --build-exe-dir "${CMake_BINARY_DIR}/MakeClean"
+ --build-options ${build_options}
+ --test-command check_clean
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/MakeClean")
+ endif()
+
+ if(NOT DEFINED CTEST_RUN_MFC)
+ set(CTEST_RUN_MFC OFF)
+
+ if(MSVC)
+ set(CTEST_RUN_MFC ON)
+
+ # Look for evidence that this is a VCExpress build. If so, avoid
+ # the MFC test by default.
+ string(TOLOWER "${CMAKE_MAKE_PROGRAM}" mkprog)
+ if(mkprog MATCHES "vcexpress")
+ message(STATUS
+ "CMAKE_MAKE_PROGRAM indicates vcexpress, avoiding MFC test")
+ set(CTEST_RUN_MFC OFF)
+ endif()
+
+ # Since MSBuild might also be the "makeprogram" for a VCExpress
+ # build tree, use one more heuristic, too. The string representing
+ # the .vcproj file type contains "VCExpress" on machines where an
+ # express edition of VS was installed last:
+ if(CTEST_RUN_MFC)
+ execute_process(COMMAND cmd /c assoc .vcproj
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE ov)
+ if(ov MATCHES "VCExpress")
+ message(STATUS
+ ".vcproj file association indicates VCExpress, avoiding MFC test")
+ set(CTEST_RUN_MFC OFF)
+ endif()
+ endif()
+
+ # For the Watcom WMake generator, avoid the MFC test by default.
+ if(CTEST_RUN_MFC)
+ if("${CMAKE_GENERATOR}" MATCHES "WMake")
+ message(STATUS
+ "using the Watcom WMake generator, avoiding MFC test")
+ set(CTEST_RUN_MFC OFF)
+ endif()
+ endif()
+
+ # Last resort, after quick checks are done. Do a try_compile, and avoid
+ # the MFC test if the simplest possible MFC app cannot be compiled.
+ if(CTEST_RUN_MFC AND NOT DEFINED HAVE_MFC)
+ configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/MFC/try_compile/CMakeLists.txt
+ ${CMAKE_CURRENT_BINARY_DIR}/MFC/try_compile/CMakeLists.txt
+ COPYONLY
+ )
+ configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/MFC/mfc1/stdafx.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/MFC/try_compile/stdafx.cpp
+ COPYONLY
+ )
+ configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/MFC/mfc1/stdafx.h
+ ${CMAKE_CURRENT_BINARY_DIR}/MFC/try_compile/stdafx.h
+ COPYONLY
+ )
+
+ message(STATUS "Looking for MFC")
+
+ try_compile(HAVE_MFC
+ ${CMAKE_CURRENT_BINARY_DIR}/MFC/try_compile/build
+ ${CMAKE_CURRENT_BINARY_DIR}/MFC/try_compile
+ try_compile_mfc
+ OUTPUT_VARIABLE HAVE_MFC_OUTPUT)
+
+ if(HAVE_MFC)
+ message(STATUS "Looking for MFC - found")
+ set(HAVE_MFC 1 CACHE INTERNAL "Have MFC")
+ file(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if MFC exists passed with the following output:\n"
+ "${HAVE_MFC_OUTPUT}\n\n")
+ else()
+ message(STATUS "Looking for MFC - not found")
+ set(HAVE_MFC "" CACHE INTERNAL "Have MFC")
+ file(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if MFC exists failed with the following output:\n"
+ "${HAVE_MFC_OUTPUT}\n\n")
+ endif()
+ endif()
+
+ if(CTEST_RUN_MFC AND NOT HAVE_MFC)
+ message(STATUS
+ "cannot compile simplest ever MFC app, avoiding MFC test")
+ set(CTEST_RUN_MFC OFF)
+ endif()
+ endif()
+ endif()
+
+ if(CTEST_RUN_MFC)
+ add_test(MFC ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/MFC"
+ "${CMake_BINARY_DIR}/Tests/MFC"
+ --build-two-config
+ ${build_generator_args}
+ --build-project mfc_driver
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND}
+ -C \${CTEST_CONFIGURATION_TYPE} -VV)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/MFC")
+ endif()
+
+ if(MSVC AND NOT MSVC_VERSION LESS 1310
+ AND NOT CMAKE_GENERATOR MATCHES "Visual Studio [67]( |$)"
+ AND (NOT CMAKE_GENERATOR MATCHES "Visual Studio [89]( |$)"
+ OR CMAKE_SIZEOF_VOID_P EQUAL 4)
+ )
+ ADD_TEST_MACRO(VSMASM VSMASM)
+ endif()
+
+ if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
+ if(NOT MSVC60)
+ ADD_TEST_MACRO(SBCS SBCS)
+ endif()
+
+ if(NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio [6789]( |$)"
+ AND NOT CMAKE_GENERATOR_TOOLSET)
+ ADD_TEST_MACRO(VSWindowsFormsResx VSWindowsFormsResx)
+ endif()
+
+ add_test(VSExternalInclude ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VSExternalInclude"
+ "${CMake_BINARY_DIR}/Tests/VSExternalInclude"
+ --build-two-config
+ ${build_generator_args}
+ --build-project VSExternalInclude
+ --build-options ${build_options}
+ --test-command VSExternalInclude)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSExternalInclude")
+
+ add_test(VSMidl ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VSMidl"
+ "${CMake_BINARY_DIR}/Tests/VSMidl"
+ --build-two-config
+ ${build_generator_args}
+ --build-project VSMidl
+ --build-options ${build_options}
+ --test-command VSMidl)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSMidl")
+
+ if(CMake_TEST_DEVENV)
+ # The test (and tested property) works with .sln files, so it's skipped when:
+ # * Using VS6, which doesn't use .sln files
+ # * cmake --build is set up to use MSBuild, since the MSBuild invocation does not use the .sln file
+ set(_last_test "")
+ foreach(config ${CMAKE_CONFIGURATION_TYPES})
+ add_test(NAME VSExcludeFromDefaultBuild-${config} COMMAND ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VSExcludeFromDefaultBuild"
+ "${CMake_BINARY_DIR}/Tests/VSExcludeFromDefaultBuild"
+ --build-config ${config}
+ --build-two-config
+ --build-generator ${CMAKE_GENERATOR}
+ --build-makeprogram ${CMake_TEST_DEVENV}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-project VSExcludeFromDefaultBuild
+ --test-command ${CMAKE_COMMAND}
+ -D "activeConfig=${config}"
+ -D "allConfigs=${CMAKE_CONFIGURATION_TYPES}"
+ -D "dir=${CMake_BINARY_DIR}/Tests/VSExcludeFromDefaultBuild"
+ -P "${CMake_SOURCE_DIR}/Tests/VSExcludeFromDefaultBuild/ResultTest.cmake")
+ if(_last_test)
+ set_property(TEST VSExcludeFromDefaultBuild-${config} PROPERTY DEPENDS ${_last_test})
+ endif()
+ set(_last_test "VSExcludeFromDefaultBuild-${config}")
+ endforeach()
+ unset(_last_test)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSExcludeFromDefaultBuild")
+ endif()
+
+ if(CMAKE_GENERATOR MATCHES "Visual Studio ([0-5]|[6-9][0-9])")
+ # This is Visual Studio 10 or above, so the default build tool is MSBuild.
+ add_test(NAME VSProjectInSubdir COMMAND ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VSProjectInSubdir"
+ "${CMake_BINARY_DIR}/Tests/VSProjectInSubdir"
+ --build-two-config
+ --build-generator ${CMAKE_GENERATOR}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-project VSProjectInSubdir
+ --build-target test)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSProjectInSubdir")
+ endif()
+ endif()
+
+ if(WIN32)
+ set(reg_vs10 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0;InstallDir]")
+ set(reg_vs11 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0;InstallDir]")
+ set(reg_vs12 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\12.0;InstallDir]")
+ set(reg_ws80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]")
+ set(reg_ws81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.1;InstallationFolder]")
+ set(reg_wp80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\WindowsPhone\\v8.0;InstallationFolder]")
+ set(reg_wp81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\WindowsPhone\\v8.1;InstallationFolder]")
+ set(reg_tegra "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;sdkRoot]")
+ foreach(reg vs10 vs11 vs12 ws80 ws81 wp80 wp81 tegra)
+ get_filename_component(r "${reg_${reg}}" ABSOLUTE)
+ if(IS_DIRECTORY "${r}")
+ set(${reg} 1)
+ else()
+ set(${reg} 0)
+ endif()
+ endforeach()
+ endif()
+
+ get_filename_component(ntver "[HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion;CurrentVersion]" NAME)
+ if(WIN32 AND ntver VERSION_GREATER 6.1) # Windows >= 8.0
+ macro(add_test_VSWinStorePhone name generator systemName systemVersion)
+ add_test(NAME VSWinStorePhone.${name} COMMAND ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VSWinStorePhone"
+ "${CMake_BINARY_DIR}/Tests/VSWinStorePhone/${name}"
+ --build-generator "${generator}"
+ --build-project VSWinStorePhone
+ --build-config $<CONFIGURATION>
+ --build-options -DCMAKE_SYSTEM_NAME=${systemName}
+ -DCMAKE_SYSTEM_VERSION=${systemVersion}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSWinStorePhone/${name}")
+ endmacro()
+
+ if(vs11 AND ws80)
+ add_test_VSWinStorePhone(vs11-store80-X86 "Visual Studio 11 2012" WindowsStore 8.0)
+ add_test_VSWinStorePhone(vs11-store80-ARM "Visual Studio 11 2012 ARM" WindowsStore 8.0)
+ add_test_VSWinStorePhone(vs11-store80-X64 "Visual Studio 11 2012 Win64" WindowsStore 8.0)
+ endif()
+ if(vs12 AND ws81)
+ add_test_VSWinStorePhone(vs12-store81-X86 "Visual Studio 12 2013" WindowsStore 8.1)
+ add_test_VSWinStorePhone(vs12-store81-ARM "Visual Studio 12 2013 ARM" WindowsStore 8.1)
+ add_test_VSWinStorePhone(vs12-store81-X64 "Visual Studio 12 2013 Win64" WindowsStore 8.1)
+ endif()
+ if(vs11 AND wp80)
+ add_test_VSWinStorePhone(vs11-phone80-X86 "Visual Studio 11 2012" WindowsPhone 8.0)
+ add_test_VSWinStorePhone(vs11-phone80-ARM "Visual Studio 11 2012 ARM" WindowsPhone 8.0)
+ endif()
+ if(vs12 AND wp81)
+ add_test_VSWinStorePhone(vs12-phone81-X86 "Visual Studio 12 2013" WindowsPhone 8.1)
+ add_test_VSWinStorePhone(vs12-phone81-ARM "Visual Studio 12 2013 ARM" WindowsPhone 8.1)
+ endif()
+ endif()
+
+ if(tegra AND NOT "${CMake_SOURCE_DIR};${CMake_BINARY_DIR}" MATCHES " ")
+ macro(add_test_VSNsightTegra name generator)
+ add_test(NAME VSNsightTegra.${name} COMMAND ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VSNsightTegra"
+ "${CMake_BINARY_DIR}/Tests/VSNsightTegra/${name}"
+ --build-generator "${generator}"
+ --build-project VSNsightTegra
+ --build-config $<CONFIGURATION>
+ --build-options -DCMAKE_SYSTEM_NAME=Android
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSNsightTegra/${name}")
+ endmacro()
+ if(vs10)
+ add_test_VSNsightTegra(vs10 "Visual Studio 10 2010")
+ endif()
+ if(vs11)
+ add_test_VSNsightTegra(vs11 "Visual Studio 11 2012")
+ endif()
+ if(vs12)
+ add_test_VSNsightTegra(vs12 "Visual Studio 12 2013")
+ endif()
+ endif()
+
+ if (APPLE)
+ if (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+ set(BundleTestInstallDir
+ "${CMake_BINARY_DIR}/Tests/BundleTest/InstallDirectory")
+ add_test(BundleTest ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/BundleTest"
+ "${CMake_BINARY_DIR}/Tests/BundleTest"
+ --build-two-config
+ ${build_generator_args}
+ --build-project BundleTest
+ --build-target install
+# --build-target package
+ --build-options ${build_options}
+ "-DCMAKE_INSTALL_PREFIX:PATH=${BundleTestInstallDir}"
+ "-DCMake_SOURCE_DIR:PATH=${CMake_SOURCE_DIR}"
+ --test-command
+ ${BundleTestInstallDir}/Applications/SecondBundleExe.app/Contents/MacOS/SecondBundleExe)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleTest")
+
+ add_test(CFBundleTest ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CFBundleTest"
+ "${CMake_BINARY_DIR}/Tests/CFBundleTest"
+ --build-two-config
+ ${build_generator_args}
+ --build-project CFBundleTest
+ --build-options ${build_options}
+ --test-command
+ ${CMAKE_CMAKE_COMMAND} -DCTEST_CONFIGURATION_TYPE=\${CTEST_CONFIGURATION_TYPE}
+ -Ddir=${CMake_BINARY_DIR}/Tests/CFBundleTest
+ -Dgen=${CMAKE_GENERATOR}
+ -P ${CMake_SOURCE_DIR}/Tests/CFBundleTest/VerifyResult.cmake)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CFBundleTest")
+
+ ADD_TEST_MACRO(ObjC++ ObjC++)
+ endif ()
+ endif ()
+
+ if(APPLE AND CTEST_TEST_CPACK)
+ add_test(BundleGeneratorTest ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/BundleGeneratorTest"
+ "${CMake_BINARY_DIR}/Tests/BundleGeneratorTest"
+ --build-two-config
+ ${build_generator_args}
+ --build-project BundleGeneratorTest
+ --build-target package
+ --build-options ${build_options}
+ "-DCMAKE_INSTALL_PREFIX:PATH=${CMake_BINARY_DIR}/Tests/BundleGeneratorTest/InstallDirectory"
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleGeneratorTest")
+ endif()
+
+ add_test(WarnUnusedUnusedViaSet ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VariableUnusedViaSet"
+ "${CMake_BINARY_DIR}/Tests/WarnUnusedUnusedViaSet"
+ ${build_generator_args}
+ --build-noclean
+ --build-project WarnUnusedUnusedViaSet
+ --build-options ${build_options}
+ "--warn-unused-vars")
+ set_tests_properties(WarnUnusedUnusedViaSet PROPERTIES
+ PASS_REGULAR_EXPRESSION "unused variable \\(changing definition\\) 'UNUSED_VARIABLE'")
+ set_tests_properties(WarnUnusedUnusedViaSet PROPERTIES
+ FAIL_REGULAR_EXPRESSION "unused variable \\(unsetting\\) 'UNUSED_VARIABLE'")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUnusedUnusedViaSet")
+
+ add_test(WarnUnusedUnusedViaUnset ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VariableUnusedViaUnset"
+ "${CMake_BINARY_DIR}/Tests/WarnUnusedUnusedViaUnset"
+ ${build_generator_args}
+ --build-noclean
+ --build-project WarnUnusedUnusedViaUnset
+ --build-options ${build_options}
+ "--warn-unused-vars")
+ set_tests_properties(WarnUnusedUnusedViaUnset PROPERTIES
+ PASS_REGULAR_EXPRESSION "CMake Warning \\(dev\\) at CMakeLists.txt:7 \\(set\\):")
+ set_tests_properties(WarnUnusedUnusedViaUnset PROPERTIES
+ FAIL_REGULAR_EXPRESSION "CMakeLists.txt:5 \\(set\\):")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUnusedUnusedViaUnset")
+
+ if("${CMAKE_GENERATOR}" MATCHES "Makefile" AND NOT WIN32)
+ # Ninja does not support ADDITIONAL_MAKE_CLEAN_FILES and therefore fails
+ # this test. (See #13371)
+ # Apparently Visual Studio does not support it either. As the MakeClean
+ # test above is only run with the Makefiles generator, only run this
+ # test with the Makefiles generator also.
+ add_test(WarnUnusedCliUnused ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/WarnUnusedCliUnused"
+ "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUnused"
+ ${build_generator_args}
+ --build-project WarnUnusedCliUnused
+ --build-options ${build_options}
+ "-DUNUSED_CLI_VARIABLE=Unused")
+ set_tests_properties(WarnUnusedCliUnused PROPERTIES
+ PASS_REGULAR_EXPRESSION "CMake Warning:.*Manually-specified variables were not used by the project:.* UNUSED_CLI_VARIABLE")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUnused")
+ endif()
+
+ add_test(WarnUnusedCliUsed ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VariableUsage"
+ "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUsed"
+ ${build_generator_args}
+ --build-noclean
+ --build-project WarnUnusedCliUsed
+ --build-options ${build_options}
+ "-DUSED_VARIABLE=Usage proven")
+ set_tests_properties(WarnUnusedCliUsed PROPERTIES
+ PASS_REGULAR_EXPRESSION "Usage proven")
+ set_tests_properties(WarnUnusedCliUsed PROPERTIES
+ FAIL_REGULAR_EXPRESSION "CMake Warning: The variable, 'USED_VARIABLE'")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUsed")
+
+ add_test(WarnUninitialized ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/VariableUsage"
+ "${CMake_BINARY_DIR}/Tests/WarnUninitialized"
+ ${build_generator_args}
+ --build-noclean
+ --build-project WarnUninitialized
+ --build-options ${build_options}
+ "--warn-uninitialized")
+ set_tests_properties(WarnUninitialized PROPERTIES
+ PASS_REGULAR_EXPRESSION "uninitialized variable 'USED_VARIABLE'")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUninitialized")
+
+ add_test(TestsWorkingDirectory ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/TestsWorkingDirectory"
+ "${CMake_BINARY_DIR}/Tests/TestsWorkingDirectory"
+ ${build_generator_args}
+ --build-project TestsWorkingDirectoryProj
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/TestsWorkingDirectory"
+ --force-new-ctest-process
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C \${CTEST_CONFIGURATION_TYPE}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TestsWorkingDirectory")
+
+ # Make sure CTest can handle a test with no newline in output.
+ add_test(CTest.NoNewline
+ ${CMAKE_CMAKE_COMMAND} -E echo_append "This line has no newline!")
+
+ # A simple test for ctest in script mode
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestScriptMode/CTestTestScriptMode.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestScriptMode/CTestTestScriptMode.cmake" @ONLY)
+# add_test(CTest.ScriptMode ${CMAKE_CTEST_COMMAND}
+# -S "${CMake_BINARY_DIR}/Tests/CTestScriptMode/CTestTestScriptMode.cmake"
+# )
+
+ # A test for ctest_build() with targets in subdirectories
+ set(ctest_configure_options)
+ if(CMAKE_GENERATOR_PLATFORM)
+ list(APPEND ctest_configure_options -A ${CMAKE_GENERATOR_PLATFORM})
+ endif()
+ if(CMAKE_GENERATOR_TOOLSET)
+ list(APPEND ctest_configure_options -T ${CMAKE_GENERATOR_TOOLSET})
+ endif()
+ if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
+ list(APPEND ctest_configure_options -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
+ endif()
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake" @ONLY)
+ unset(ctest_configure_options)
+ add_test(CTest.BuildCommand.ProjectInSubdir
+ ${CMAKE_CTEST_COMMAND} -S "${CMake_BINARY_DIR}/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CTestBuildCommandProjectInSubdir/Nested")
+
+ set(CTEST_TEST_UPDATE 1)
+ if(CTEST_TEST_UPDATE)
+ # Test CTest Update with Subversion
+ find_package(Subversion QUIET)
+ if(Subversion_FOUND)
+ get_filename_component(_Subversion_BIN_DIR
+ ${Subversion_SVN_EXECUTABLE} PATH)
+ find_program(Subversion_SVNADMIN_EXECUTABLE svnadmin
+ HINTS ${_Subversion_BIN_DIR}
+ )
+ mark_as_advanced(Subversion_SVNADMIN_EXECUTABLE)
+ if(NOT Subversion_SVNADMIN_EXECUTABLE)
+ set(Subversion_FOUND FALSE)
+ endif()
+ endif()
+ if(Subversion_FOUND)
+ set(CTestUpdateSVN_DIR "CTest UpdateSVN")
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestUpdateSVN.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestUpdateSVN.cmake" @ONLY)
+ add_test(CTest.UpdateSVN ${CMAKE_CMAKE_COMMAND}
+ -P "${CMake_BINARY_DIR}/Tests/CTestUpdateSVN.cmake"
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateSVN_DIR}")
+ endif()
+
+ # Test CTest Update with CVS
+ if(EXISTS ${CMAKE_ROOT}/Modules/FindCVS.cmake)
+ find_package(CVS QUIET)
+ else()
+ find_program(CVS_EXECUTABLE NAMES cvs)
+ set(CVS_FOUND ${CVS_EXECUTABLE})
+ endif()
+ set(CTEST_TEST_UPDATE_CVS ${CVS_FOUND})
+ if(CTEST_TEST_UPDATE_CVS AND NOT UNIX)
+ if("${CVS_EXECUTABLE}" MATCHES "cygwin")
+ message(STATUS "No CTest.UpdateCVS test with cygwin cvs.exe outside cygwin!")
+ set(CTEST_TEST_UPDATE_CVS 0)
+ endif()
+ endif()
+ if(CTEST_TEST_UPDATE_CVS)
+ set(CTestUpdateCVS_DIR "CTest UpdateCVS")
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestUpdateCVS.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestUpdateCVS.cmake" @ONLY)
+ add_test(CTest.UpdateCVS ${CMAKE_CMAKE_COMMAND}
+ -P "${CMake_BINARY_DIR}/Tests/CTestUpdateCVS.cmake"
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateCVS_DIR}")
+ endif()
+
+ # Test CTest Update with BZR
+ find_program(BZR_EXECUTABLE NAMES bzr)
+ mark_as_advanced(BZR_EXECUTABLE)
+ set(CTEST_TEST_UPDATE_BZR 0)
+ if(BZR_EXECUTABLE)
+ if(NOT "${BZR_EXECUTABLE}" MATCHES "cygwin" OR UNIX)
+ set(CTEST_TEST_UPDATE_BZR 1)
+ endif()
+ endif()
+ if(CTEST_TEST_UPDATE_BZR)
+ # Check if xmloutput plugin is there
+ execute_process(COMMAND ${BZR_EXECUTABLE} xmlplugins RESULT_VARIABLE xmlplugres
+ OUTPUT_QUIET ERROR_QUIET)
+ if( NOT ${xmlplugres} )
+ set(CTestUpdateBZR_DIR "CTest UpdateBZR")
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestUpdateBZR.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestUpdateBZR.cmake" @ONLY)
+ add_test(CTest.UpdateBZR ${CMAKE_CMAKE_COMMAND}
+ -P "${CMake_BINARY_DIR}/Tests/CTestUpdateBZR.cmake"
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateBZR_DIR}")
+ set(CTestUpdateBZR_DIR "CTest UpdateBZR_CLocale")
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestUpdateBZR.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestUpdateBZR_CLocale.cmake" @ONLY)
+ add_test(CTest.UpdateBZR.CLocale ${CMAKE_CMAKE_COMMAND}
+ -P "${CMake_BINARY_DIR}/Tests/CTestUpdateBZR_CLocale.cmake"
+ )
+ set_tests_properties(CTest.UpdateBZR.CLocale PROPERTIES ENVIRONMENT LC_ALL=C)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateBZR_DIR}")
+ endif()
+ endif()
+
+ # Test CTest Update with GIT
+ find_program(GIT_EXECUTABLE NAMES git)
+ mark_as_advanced(GIT_EXECUTABLE)
+ set(CTEST_TEST_UPDATE_GIT 0)
+ if(GIT_EXECUTABLE)
+ if(NOT "${GIT_EXECUTABLE}" MATCHES "cygwin" OR UNIX)
+ set(CTEST_TEST_UPDATE_GIT 1)
+ endif()
+ endif()
+ if(CTEST_TEST_UPDATE_GIT)
+ set(CTestUpdateGIT_DIR "CTest UpdateGIT")
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestUpdateGIT.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestUpdateGIT.cmake" @ONLY)
+ add_test(CTest.UpdateGIT ${CMAKE_CMAKE_COMMAND}
+ -P "${CMake_BINARY_DIR}/Tests/CTestUpdateGIT.cmake"
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateGIT_DIR}")
+ endif()
+
+ # Test CTest Update with HG
+ find_program(HG_EXECUTABLE NAMES hg)
+ mark_as_advanced(HG_EXECUTABLE)
+ set(CTEST_TEST_UPDATE_HG 0)
+ if(HG_EXECUTABLE)
+ if(NOT "${HG_EXECUTABLE}" MATCHES "cygwin" OR UNIX)
+ set(CTEST_TEST_UPDATE_HG 1)
+ endif()
+ endif()
+ if(CTEST_TEST_UPDATE_HG)
+ set(CTestUpdateHG_DIR "CTest UpdateHG")
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestUpdateHG.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestUpdateHG.cmake" @ONLY)
+ add_test(CTest.UpdateHG ${CMAKE_CMAKE_COMMAND}
+ -P "${CMake_BINARY_DIR}/Tests/CTestUpdateHG.cmake"
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateHG_DIR}")
+ endif()
+
+ # Test CTest Update with P4
+ find_program(P4_EXECUTABLE NAMES p4)
+ find_program(P4D_EXECUTABLE NAMES p4d)
+ mark_as_advanced(P4_EXECUTABLE P4D_EXECUTABLE)
+ set(CTEST_TEST_UPDATE_P4 0)
+ if(P4_EXECUTABLE AND P4D_EXECUTABLE)
+ if(NOT "${P4_EXECUTABLE};${P4D_EXECUTABLE}" MATCHES "cygwin" OR UNIX)
+ set(CTEST_TEST_UPDATE_P4 1)
+ endif()
+ endif()
+ if(CTEST_TEST_UPDATE_P4)
+ set(CTestUpdateP4_DIR "CTest UpdateP4")
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestUpdateP4.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestUpdateP4.cmake" @ONLY)
+ add_test(CTest.UpdateP4 ${CMAKE_CMAKE_COMMAND}
+ -P "${CMake_BINARY_DIR}/Tests/CTestUpdateP4.cmake"
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateP4_DIR}")
+ endif()
+ endif()
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestFailure/testNoBuild.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestFailure/testNoBuild.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestNoBuild ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestFailure/testNoBuild.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestFailure/testOut1.log"
+ )
+ set_tests_properties(CTestTestNoBuild PROPERTIES
+ FAIL_REGULAR_EXPRESSION "Error" WILL_FAIL true)
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestFailure/testNoExe.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestFailure/testNoExe.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestNoExe ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestFailure/testNoExe.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestFailure/testOut2.log"
+ )
+ set_tests_properties(CTestTestNoExe PROPERTIES DEPENDS CTestTestNoBuild
+ PASS_REGULAR_EXPRESSION "Could not find executable"
+ FAIL_REGULAR_EXPRESSION "SegFault")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestUpload/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestUpload/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestUpload ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestUpload/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestUpload/testOut.log"
+ )
+ set_tests_properties(CTestTestUpload PROPERTIES
+ PASS_REGULAR_EXPRESSION "Upload\\.xml")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestEmptyBinaryDirectory/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestEmptyBinaryDirectory/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestEmptyBinaryDirectory ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestEmptyBinaryDirectory/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestEmptyBinaryDirectory/testOut.log"
+ )
+ set_tests_properties(CTestTestEmptyBinaryDirectory PROPERTIES
+ PASS_REGULAR_EXPRESSION "TEST_SUCCESS")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestConfigFileInBuildDir/test1.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir1/test1.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestConfigFileInBuildDir1 ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir1/test1.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir1/testOut1.log"
+ )
+ REGEX_ESCAPE_STRING(CTEST_TEST_ESCAPED_SOURCE_DIR "${CMake_SOURCE_DIR}")
+ set_tests_properties(CTestTestConfigFileInBuildDir1 PROPERTIES DEPENDS CTestTestNoBuild
+ PASS_REGULAR_EXPRESSION
+ "Reading ctest configuration file: ${CTEST_TEST_ESCAPED_SOURCE_DIR}.Tests.CTestTestConfigFileInBuildDir.CTestConfig.cmake")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestConfigFileInBuildDir/test2.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir2/test2.cmake"
+ @ONLY ESCAPE_QUOTES)
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestConfigFileInBuildDir/CTestConfig.cmake"
+ "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir2/CTestConfig.cmake"
+ @ONLY ESCAPE_QUOTES COPYONLY)
+ add_test(CTestTestConfigFileInBuildDir2 ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir2/test2.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir2/testOut2.log"
+ )
+ REGEX_ESCAPE_STRING(CTEST_TEST_ESCAPED_BINARY_DIR "${CMake_BINARY_DIR}")
+ set_tests_properties(CTestTestConfigFileInBuildDir2 PROPERTIES DEPENDS CTestTestNoBuild
+ REQUIRED_FILES ${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir2/CTestConfig.cmake
+ PASS_REGULAR_EXPRESSION
+ "Reading ctest configuration file: ${CTEST_TEST_ESCAPED_BINARY_DIR}.Tests.CTestTestConfigFileInBuildDir2.CTestConfig.cmake")
+
+ # test coverage for mumps
+ # create a MumpsCoverage dir in the binary tree under Testing to
+ # avoid the .NoDartCoverage files in the cmake testing tree
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/MumpsCoverage/DartConfiguration.tcl.in"
+ "${CMake_BINARY_DIR}/Testing/MumpsCoverage/DartConfiguration.tcl")
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/MumpsCoverage/gtm_coverage.mcov.in"
+ "${CMake_BINARY_DIR}/Testing/MumpsCoverage/gtm_coverage.mcov")
+ file(REMOVE_RECURSE "${CMake_BINARY_DIR}/Testing/MumpsCoverage/VistA-FOIA")
+ file(COPY "${CMake_SOURCE_DIR}/Tests/MumpsCoverage/VistA-FOIA"
+ DESTINATION "${CMake_BINARY_DIR}/Testing/MumpsCoverage")
+ add_test(NAME CTestGTMCoverage
+ COMMAND cmake -E chdir
+ ${CMake_BINARY_DIR}/Testing/MumpsCoverage
+ $<TARGET_FILE:ctest> -T Coverage --debug)
+ set_tests_properties(CTestGTMCoverage PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "Process file.*ZZCOVTST.m.*Total LOC:.*30.*Percentage Coverage: 80.00*"
+ ENVIRONMENT COVFILE=)
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/MumpsCoverage/DartConfiguration.cache.tcl.in"
+ "${CMake_BINARY_DIR}/Testing/MumpsCacheCoverage/DartConfiguration.tcl")
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/MumpsCoverage/cache_coverage.cmcov.in"
+ "${CMake_BINARY_DIR}/Testing/MumpsCacheCoverage/cache_coverage.cmcov")
+ file(REMOVE_RECURSE "${CMake_BINARY_DIR}/Testing/MumpsCacheCoverage/VistA-FOIA")
+ file(COPY "${CMake_SOURCE_DIR}/Tests/MumpsCoverage/VistA-FOIA"
+ DESTINATION "${CMake_BINARY_DIR}/Testing/MumpsCacheCoverage")
+ add_test(NAME CTestCacheCoverage
+ COMMAND cmake -E chdir
+ ${CMake_BINARY_DIR}/Testing/MumpsCacheCoverage
+ $<TARGET_FILE:ctest> -T Coverage --debug)
+ set_tests_properties(CTestCacheCoverage PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "Process file.*ZZCOVTST.m.*Total LOC:.*29.*Percentage Coverage: 86.21.*"
+ ENVIRONMENT COVFILE=)
+
+ # Adding a test case for Python Coverage
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/PythonCoverage/coverage.xml.in"
+ "${CMake_BINARY_DIR}/Testing/PythonCoverage/coverage.xml")
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/PythonCoverage/DartConfiguration.tcl.in"
+ "${CMake_BINARY_DIR}/Testing/PythonCoverage/DartConfiguration.tcl")
+ file(COPY "${CMake_SOURCE_DIR}/Tests/PythonCoverage/coveragetest"
+ DESTINATION "${CMake_BINARY_DIR}/Testing/PythonCoverage")
+ add_test(NAME CTestPythonCoverage
+ COMMAND cmake -E chdir
+ ${CMake_BINARY_DIR}/Testing/PythonCoverage
+ $<TARGET_FILE:ctest> -T Coverage --debug)
+ set_tests_properties(CTestPythonCoverage PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "Process file.*foo.py.*Total LOC:.*13.*Percentage Coverage: 84.62.*"
+ ENVIRONMENT COVFILE=)
+
+ # Adding a test case for non-python Cobertura Coverage
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CoberturaCoverage/DartConfiguration.tcl.in"
+ "${CMake_BINARY_DIR}/Testing/CoberturaCoverage/DartConfiguration.tcl")
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CoberturaCoverage/coverage.xml.in"
+ "${CMake_BINARY_DIR}/Testing/CoberturaCoverage/coverage.xml")
+ file(COPY "${CMake_SOURCE_DIR}/Tests/CoberturaCoverage/src"
+ DESTINATION "${CMake_BINARY_DIR}/Testing/CoberturaCoverage")
+ add_test(NAME CTestCoberturaCoverage
+ COMMAND cmake -E chdir
+ ${CMake_BINARY_DIR}/Testing/CoberturaCoverage
+ $<TARGET_FILE:ctest> -T Coverage --debug)
+ set_tests_properties(CTestCoberturaCoverage PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "Process file.*CoverageTest.java.*Total LOC:.*18.*Percentage Coverage: 72.22.*"
+ ENVIRONMENT COVFILE=)
+
+
+ # Adding a test case for JaCoCo Coverage
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/JacocoCoverage/DartConfiguration.tcl.in"
+ "${CMake_BINARY_DIR}/Testing/JacocoCoverage/DartConfiguration.tcl")
+ file(COPY "${CMake_SOURCE_DIR}/Tests/JacocoCoverage/Coverage"
+ DESTINATION "${CMake_BINARY_DIR}/Testing/JacocoCoverage")
+ add_test(NAME CTestJacocoCoverage
+ COMMAND cmake -E chdir
+ ${CMake_BINARY_DIR}/Testing/JacocoCoverage
+ $<TARGET_FILE:ctest> -T Coverage --debug)
+ set_tests_properties(CTestJacocoCoverage PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "Process file.*CoverageTest.java.*Total LOC:.*17.*Percentage Coverage: 76.47*"
+ ENVIRONMENT COVFILE=)
+
+ function(add_config_tests cfg)
+ set(base "${CMake_BINARY_DIR}/Tests/CTestConfig")
+
+ # Test -S script with a -C config arg to ctest:
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestConfig/script.cmake.in"
+ "${base}/${cfg}-script.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestConfig.Script.${cfg} ${CMAKE_CTEST_COMMAND}
+ -C ${cfg}
+ -S "${base}/${cfg}-script.cmake" -VV
+ --output-log "${base}/${cfg}-script.log"
+ )
+
+ # Test -D dashboard with a -C config arg to ctest.
+ # (Actual commands inside a cmake -P script because we need to be able to set
+ # the working directory reliably...)
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestConfig/dashboard.cmake.in"
+ "${base}/${cfg}-dashboard.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestConfig.Dashboard.${cfg} ${CMAKE_CMAKE_COMMAND}
+ -P "${base}/${cfg}-dashboard.cmake" -VV
+ )
+ endfunction()
+
+ add_config_tests(Debug)
+ add_config_tests(MinSizeRel)
+ add_config_tests(Release)
+ add_config_tests(RelWithDebInfo)
+
+ # Test -S script with some -D variable definition args to ctest:
+ add_test(CTestConfig.ScriptWithArgs ${CMAKE_CTEST_COMMAND}
+ -C "Release"
+ -D arg1=this
+ -D arg2=that
+ -D "arg3=the other"
+ "-Darg4=this is the fourth"
+ -Darg5=the_fifth
+ -Darg6:STRING=value-with-type
+ -S "${CMake_SOURCE_DIR}/Tests/CTestConfig/ScriptWithArgs.cmake" -VV
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestConfig/ScriptWithArgs.log"
+ )
+
+ ADD_TEST_MACRO(CMakeCommands.add_compile_options add_compile_options)
+ ADD_TEST_MACRO(CMakeCommands.target_link_libraries target_link_libraries)
+ ADD_TEST_MACRO(CMakeCommands.target_include_directories target_include_directories)
+ ADD_TEST_MACRO(CMakeCommands.target_compile_definitions target_compile_definitions)
+ ADD_TEST_MACRO(CMakeCommands.target_compile_options target_compile_options)
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestCrash/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestCrash/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestCrash ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestCrash/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestCrash/testOutput.log"
+ )
+ # with watcom the SEGFAULT is not found, it just fails
+ if(CMAKE_GENERATOR MATCHES "Watcom WMake")
+ set_tests_properties(CTestTestCrash PROPERTIES
+ PASS_REGULAR_EXPRESSION "Failed")
+ else()
+ set_tests_properties(CTestTestCrash PROPERTIES
+ PASS_REGULAR_EXPRESSION "(Illegal|SegFault)")
+ endif()
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestBadExe/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestBadExe/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestBadExe ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestBadExe/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestBadExe/testOutput.log"
+ )
+ set(CTestTestBadExe_REGEX "BAD_COMMAND")
+ # some cygwin can not be made to produce a BAD_COMMAND error
+ # the best we can get from it is a failed test
+ if(CYGWIN)
+ set(CTestTestBadExe_REGEX "(\\*\\*\\*Failed)|BAD_COMMAND")
+ endif()
+ set_tests_properties(CTestTestBadExe PROPERTIES
+ PASS_REGULAR_EXPRESSION "${CTestTestBadExe_REGEX}")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestBadGenerator/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestBadGenerator/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestBadGenerator ${CMAKE_CTEST_COMMAND}
+ -C "\${CTestTest_CONFIG}"
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestBadGenerator/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestBadGenerator/testOutput.log"
+ )
+ set_property(TEST CTestTestBadGenerator PROPERTY
+ PASS_REGULAR_EXPRESSION "could not create generator named \"Bad Generator\"")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestParallel/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestParallel/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestParallel ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestParallel/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestParallel/testOutput.log"
+ )
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestSkipReturnCode/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestSkipReturnCode/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestSkipReturnCode ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestSkipReturnCode/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestSkipReturnCode/testOutput.log"
+ -C \${CTEST_CONFIGURATION_TYPE}
+ )
+ set_tests_properties(CTestTestSkipReturnCode PROPERTIES
+ PASS_REGULAR_EXPRESSION "CMakeV1 \\.* +Passed.*CMakeV2 \\.+\\*+Skipped")
+
+ ADD_TEST_MACRO(CTestTestSerialInDepends ${CMAKE_CTEST_COMMAND} -j 4
+ --output-on-failure -C "\${CTestTest_CONFIG}")
+
+ ADD_TEST_MACRO(CTestTestMissingDependsExe ${CMAKE_CTEST_COMMAND}
+ --output-on-failure -C "\${CTestTest_CONFIG}")
+ set_tests_properties(CTestTestMissingDependsExe PROPERTIES
+ PASS_REGULAR_EXPRESSION "\\*\\*\\*Not Run"
+ )
+
+ ADD_TEST_MACRO(CTestTestSerialOrder ${CMAKE_CTEST_COMMAND}
+ --output-on-failure -C "\${CTestTest_CONFIG}")
+
+ if(NOT BORLAND)
+ set(CTestLimitDashJ_CTEST_OPTIONS --force-new-ctest-process)
+ add_test_macro(CTestLimitDashJ ${CMAKE_CTEST_COMMAND} -j 4
+ --output-on-failure -C "\${CTestTest_CONFIG}")
+ endif()
+
+ add_test(CTestTestPrintLabels ${CMAKE_CTEST_COMMAND} --print-labels)
+ set_tests_properties(CTestTestPrintLabels PROPERTIES LABELS "Label1;Label2")
+ set_tests_properties(CTestTestPrintLabels PROPERTIES PASS_REGULAR_EXPRESSION
+ "All Labels:.* Label1.* Label2")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestLabelRegExp/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestLabelRegExp/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(NAME CTestTestLabelRegExp
+ COMMAND ${CMAKE_CMAKE_COMMAND}
+ -DSOURCE_DIR=${CMAKE_SOURCE_DIR}/Tests/CTestTestLabelRegExp
+ -P ${CMAKE_BINARY_DIR}/Tests/CTestTestLabelRegExp/test.cmake
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Tests/CTestTestLabelRegExp
+ )
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestResourceLock/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestResourceLock/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestResourceLock ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestResourceLock/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestResourceLock/output.log"
+ )
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestScheduler/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestScheduler/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestScheduler ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestScheduler/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestScheduler/testOutput.log"
+ )
+ set_tests_properties(CTestTestScheduler PROPERTIES
+ PASS_REGULAR_EXPRESSION "Start 1.*Start 2.*Start 3.*Start 4.*Start 4.*Start 3.*Start 2.*Start 1"
+ RESOURCE_LOCK "CostData")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestCostSerial/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestCostSerial/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestCostSerial ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestCostSerial/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestCostSerial/testOutput.log"
+ )
+ set_tests_properties(CTestTestCostSerial PROPERTIES
+ PASS_REGULAR_EXPRESSION "Start 2.*Start 3.*Start 1.*Start 2.*Start 3.*Start 1"
+ RESOURCE_LOCK "CostData")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestStopTime/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestStopTime/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestStopTime/GetDate.cmake"
+ "${CMake_BINARY_DIR}/Tests/CTestTestStopTime/GetDate.cmake"
+ COPYONLY)
+ add_test(CTestTestStopTime ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestStopTime/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestStopTime/testOutput.log"
+ )
+ set_tests_properties(CTestTestStopTime PROPERTIES
+ PASS_REGULAR_EXPRESSION "The stop time has been passed")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestSubdir/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestSubdir/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestSubdir ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestSubdir/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestSubdir/testOutput.log"
+ )
+ #make sure all 3 subdirs were added
+ set_tests_properties(CTestTestSubdir PROPERTIES
+ PASS_REGULAR_EXPRESSION "0 tests failed out of 3")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestTimeout/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestTimeout/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestTimeout ${CMAKE_CTEST_COMMAND}
+ -C "\${CTestTest_CONFIG}"
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestTimeout/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestTimeout/testOutput.log"
+ )
+ set_tests_properties(CTestTestTimeout PROPERTIES
+ PASS_REGULAR_EXPRESSION "TestTimeout *\\.+ *\\*\\*\\*Timeout.*TestSleep *\\.+ *Passed.*timeout correctly killed child")
+
+ add_test(
+ NAME CTestTestRerunFailed
+ COMMAND ${CMAKE_CTEST_COMMAND} --rerun-failed)
+ set_tests_properties(CTestTestRerunFailed PROPERTIES
+ PASS_REGULAR_EXPRESSION "1/1 Test #1: TestTimeout" DEPENDS CTestTestTimeout
+ WORKING_DIRECTORY ${CMake_BINARY_DIR}/Tests/CTestTestTimeout)
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestZeroTimeout/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestZeroTimeout/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestZeroTimeout ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestZeroTimeout/test.cmake" -V
+ --output-log
+ "${CMake_BINARY_DIR}/Tests/CTestTestZeroTimeout/testOutput.log")
+ set_tests_properties(CTestTestZeroTimeout PROPERTIES
+ FAIL_REGULAR_EXPRESSION "\\*\\*\\*Timeout")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestDepends/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestDepends/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestDepends ${CMAKE_CTEST_COMMAND}
+ -C "\${CTestTest_CONFIG}"
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestDepends/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestDepends/testOutput.log"
+ )
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestCycle/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestCycle/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestCycle ${CMAKE_CTEST_COMMAND}
+ -C "\${CTestTest_CONFIG}"
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestCycle/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestCycle/testOutput.log"
+ )
+ set_tests_properties(CTestTestCycle PROPERTIES
+ PASS_REGULAR_EXPRESSION "a cycle exists in the test dependency graph")
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestRunScript/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestRunScript/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestRunScript/hello.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestRunScript/hello.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestRunScript ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestRunScript/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestRunScript/testOutput.log"
+ )
+
+ add_test(CTestTestShowOnly ${CMAKE_CTEST_COMMAND} -N)
+
+ add_test(CTestBatchTest ${CMAKE_CTEST_COMMAND} -B)
+
+ configure_file(
+ "${CMake_SOURCE_DIR}/Tests/CTestTestFdSetSize/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestFdSetSize/test.cmake"
+ @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestFdSetSize ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestFdSetSize/test.cmake" -j20 -V --timeout 120
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestFdSetSize/testOutput.log"
+ )
+
+ function(add_failed_submit_test name source build in out log regex)
+ configure_file("${in}" "${out}" @ONLY)
+ add_test(${name} ${CMAKE_CTEST_COMMAND} -S "${out}" -V --output-log "${log}")
+ set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${regex}")
+ endfunction()
+
+ set(regex "(Problems when submitting via S*CP")
+ set(regex "${regex}|Error message was: ")
+ set(regex "${regex}([Cc]ould *n.t resolve host")
+ set(regex "${regex}|[Cc]ould *n.t connect to host")
+ set(regex "${regex}|Failed *t*o* connect to")
+ set(regex "${regex}|Empty reply from server")
+ set(regex "${regex}|The requested URL returned error")
+ set(regex "${regex}|libcurl was built with SSL disabled. https: not supported)")
+ set(regex "${regex}|Submission method .xmlrpc. not compiled into CTest")
+ set(regex "${regex}|Submission problem")
+ set(regex "${regex}|Submission successful)")
+
+ set(ctest_coverage_labels_args "")
+
+ foreach(drop_method cp ftp http https scp xmlrpc)
+ # Cycle through these values each time through the loop:
+ if(ctest_coverage_labels_args STREQUAL "")
+ set(ctest_coverage_labels_args "LABELS Everything")
+ elseif(ctest_coverage_labels_args STREQUAL "LABELS Everything")
+ set(ctest_coverage_labels_args "LABELS 0ArgTest")
+ else()
+ set(ctest_coverage_labels_args "")
+ endif()
+
+ add_failed_submit_test(CTestTestFailedSubmit-${drop_method}
+ "${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast"
+ "${CMake_BINARY_DIR}/Tests/CTestTestFailedSubmits/${drop_method}"
+ "${CMake_SOURCE_DIR}/Tests/CTestTestFailedSubmits/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestFailedSubmits/test-${drop_method}.cmake"
+ "${CMake_BINARY_DIR}/Tests/CTestTestFailedSubmits/test-${drop_method}.log"
+ "${regex}"
+ )
+ endforeach()
+
+
+ if (CMAKE_TESTS_CDASH_SERVER)
+ set(regex "^([^:]+)://([^/]+)(.*)$")
+
+ if ("${CMAKE_TESTS_CDASH_SERVER}" MATCHES "${regex}")
+ set(protocol "${CMAKE_MATCH_1}")
+ set(server "${CMAKE_MATCH_2}")
+ set(path "${CMAKE_MATCH_3}")
+ else ()
+ set(protocol "http")
+ set(server "open.cdash.org")
+ set(path "")
+ message("warning: CMAKE_TESTS_CDASH_SERVER does not match expected regex...")
+ message(" ...using default url='${protocol}://${server}${path}' for CTestTest[23]")
+ endif ()
+ endif ()
+
+
+ if (CTEST_TEST_CTEST AND CMAKE_RUN_LONG_TESTS AND CMAKE_TESTS_CDASH_SERVER)
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestTest/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTest/test.cmake" @ONLY ESCAPE_QUOTES)
+ add_test(CTestTest ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTest/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTest/testOutput.log"
+ )
+
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestTest2/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTest2/test.cmake" @ONLY ESCAPE_QUOTES)
+ add_test(CTestTest2 ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTest2/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTest2/testOutput.log"
+ )
+
+ if("${CMAKE_GENERATOR}" MATCHES "Makefiles" OR "${CMAKE_GENERATOR}" MATCHES "Ninja")
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestTestLaunchers/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestLaunchers/test.cmake" @ONLY ESCAPE_QUOTES)
+ add_test(CTestTestLaunchers ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestLaunchers/test.cmake" -V
+ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestLaunchers/testOutput.log"
+ )
+ set_tests_properties(CTestTestLaunchers PROPERTIES
+ PASS_REGULAR_EXPRESSION "CTEST_TEST_LAUNCHER_SUCCESS")
+ endif()
+
+ configure_file("${CMake_SOURCE_DIR}/Tests/CTestTestChecksum/test.cmake.in"
+ "${CMake_BINARY_DIR}/Tests/CTestTestChecksum/test.cmake" @ONLY
+ ESCAPE_QUOTES)
+ add_test(CTestTestChecksum ${CMAKE_CTEST_COMMAND}
+ -S "${CMake_BINARY_DIR}/Tests/CTestTestChecksum/test.cmake" -V
+ --output-log
+ "${CMake_BINARY_DIR}/Tests/CTestTestChecksum/testOutput.log"
+ )
+ set_tests_properties(CTestTestChecksum PROPERTIES PASS_REGULAR_EXPRESSION
+ "Submission failed: Checksum failed for file")
+
+ # these tests take a long time, make sure they have it
+ # if timeouts have not already been set
+ get_test_property(CTestTest TIMEOUT PREVIOUS_TIMEOUT)
+ if ("${PREVIOUS_TIMEOUT}" MATCHES NOTFOUND)
+ set_tests_properties ( CTestTest
+ PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
+ endif ()
+
+ get_test_property(CTestTest2 TIMEOUT PREVIOUS_TIMEOUT)
+ if ("${PREVIOUS_TIMEOUT}" MATCHES NOTFOUND)
+ set_tests_properties ( CTestTest2
+ PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
+ endif ()
+ endif ()
+
+ if("${CMAKE_GENERATOR}" MATCHES Xcode)
+ set(CMAKE_SKIP_BOOTSTRAP_TEST 1)
+ endif()
+ if(EXISTS "${CMake_BINARY_DIR}/CMakeLists.txt")
+ # If there is CMakeLists.txt in the binary tree, assume in-source build
+ set(CMAKE_SKIP_BOOTSTRAP_TEST 1)
+ endif()
+ set(bootstrap "")
+ if(CMAKE_RUN_LONG_TESTS AND NOT CMAKE_SKIP_BOOTSTRAP_TEST)
+ if(UNIX)
+ set(bootstrap ${CMake_SOURCE_DIR}/bootstrap)
+ elseif(MSYS)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bootstrap.bat.in
+ ${CMAKE_CURRENT_BINARY_DIR}/bootstrap.bat @ONLY)
+ set(bootstrap ${CMAKE_CURRENT_BINARY_DIR}/bootstrap.bat)
+ endif()
+ endif()
+ if(bootstrap)
+ add_test(NAME BootstrapTest
+ COMMAND ${CMAKE_CMAKE_COMMAND}
+ -D "bootstrap=${bootstrap}"
+ -D "bin_dir=${CMake_BINARY_DIR}/Tests/BootstrapTest"
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/BootstrapTest.cmake
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BootstrapTest")
+ # Make this test run early during parallel execution
+ set_tests_properties(BootstrapTest PROPERTIES COST 5000)
+
+ # provide more time for the bootstrap test
+ get_test_property(BootstrapTest TIMEOUT PREVIOUS_TIMEOUT)
+ if ("${PREVIOUS_TIMEOUT}" MATCHES NOTFOUND)
+ set_tests_properties ( BootstrapTest
+ PROPERTIES TIMEOUT 5400)
+ endif ()
+ endif()
+
+ if(CMAKE_Fortran_COMPILER)
+ add_test(Fortran ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Fortran"
+ "${CMake_BINARY_DIR}/Tests/Fortran"
+ ${build_generator_args}
+ --build-project testf
+ --build-two-config
+ --build-options ${build_options}
+ -DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
+ --test-command testf)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Fortran")
+
+ # FortranCInterface tests.
+ if(UNIX)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/FortranC/Flags.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/FortranC/Flags.cmake @ONLY)
+ add_test(FortranC.Flags ${CMAKE_CMAKE_COMMAND} -P
+ ${CMAKE_CURRENT_BINARY_DIR}/FortranC/Flags.cmake)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/FortranC/Flags")
+ else()
+ add_test(FortranC ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FortranC"
+ "${CMake_BINARY_DIR}/Tests/FortranC"
+ ${build_generator_args}
+ --build-project FortranC
+ --build-two-config
+ --build-options ${build_options}
+ --test-command CMakeFiles/FortranCInterface/FortranCInterface)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/FortranC")
+ endif()
+ endif()
+
+ find_package(Java COMPONENTS Development QUIET)
+ if(Java_JAVA_EXECUTABLE AND Java_JAVAC_EXECUTABLE AND Java_JAR_EXECUTABLE AND NOT MINGW
+ AND NOT "${CMAKE_GENERATOR}" MATCHES "Xcode")
+ get_filename_component(JNIPATH ${JAVA_COMPILE} PATH)
+ find_file(JNI_H jni.h
+ "${JNIPATH}/../include"
+ "${JNIPATH}/../java/include")
+ if(JNI_H AND EXISTS "${JNI_H}") # in case jni.h is a broken symlink
+ file(READ "${JNI_H}" JNI_FILE)
+ if("${JNI_FILE}" MATCHES "JDK1_2")
+ add_test(Java ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Java"
+ "${CMake_BINARY_DIR}/Tests/Java"
+ ${build_generator_args}
+ --build-project hello
+ --build-two-config
+ --build-run-dir "${CMake_BINARY_DIR}/Tests/Java/"
+ --build-options ${build_options}
+ --test-command ${JAVA_RUNTIME} -classpath hello.jar HelloWorld)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Java")
+ endif()
+ endif()
+ endif()
+
+ # add some cross compiler tests, for now only with makefile based generators
+ if(CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "KDevelop")
+
+ # if sdcc is found, build the SimpleCOnly project with sdcc
+ find_program(SDCC_EXECUTABLE sdcc)
+ mark_as_advanced(SDCC_EXECUTABLE)
+ if(SDCC_EXECUTABLE)
+ add_test(SimpleCOnly_sdcc ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/SimpleCOnly"
+ "${CMake_BINARY_DIR}/Tests/SimpleCOnly_sdcc"
+ ${build_generator_args}
+ --build-project SimpleC
+ --build-options ${build_options}
+ "-DCMAKE_SYSTEM_NAME=Generic"
+ "-DCMAKE_C_COMPILER=${SDCC_EXECUTABLE}")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SimpleCOnly_sdcc")
+ endif()
+
+ # If a Linux -> MinGW cross compiler is found then try it
+ find_program(MINGW_CC_LINUX2WIN_EXECUTABLE i586-mingw32msvc-gcc)
+ find_program(MINGW_CXX_LINUX2WIN_EXECUTABLE i586-mingw32msvc-g++)
+ find_program(MINGW_RC_LINUX2WIN_EXECUTABLE i586-mingw32msvc-windres)
+ mark_as_advanced(MINGW_CC_LINUX2WIN_EXECUTABLE MINGW_CXX_LINUX2WIN_EXECUTABLE MINGW_RC_LINUX2WIN_EXECUTABLE)
+ if(MINGW_CC_LINUX2WIN_EXECUTABLE AND MINGW_CXX_LINUX2WIN_EXECUTABLE AND MINGW_RC_LINUX2WIN_EXECUTABLE)
+ add_test(Simple_Mingw_Linux2Win ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Simple"
+ "${CMake_BINARY_DIR}/Tests/Simple_Mingw_Linux2Win"
+ ${build_generator_args}
+ --build-project Simple
+ --build-options ${build_options}
+ "-DCMAKE_SYSTEM_NAME=Windows"
+ "-DCMAKE_C_COMPILER=${MINGW_CC_LINUX2WIN_EXECUTABLE}"
+ "-DCMAKE_CXX_COMPILER=${MINGW_CXX_LINUX2WIN_EXECUTABLE}"
+ "-DCMAKE_RC_COMPILER=${MINGW_RC_LINUX2WIN_EXECUTABLE}"
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Simple_Mingw_Linux2Win")
+ endif()
+ endif()
+
+ if(CMAKE_TEST_PROJECT_CSE_DIR)
+ set(script "${CMAKE_TEST_PROJECT_CSE_DIR}/BuildProjectCSE.cmake")
+ if(NOT EXISTS "${script}")
+ set(script "${CMAKE_TEST_PROJECT_CSE_DIR}/cse_build.cmake")
+ endif()
+ if(NOT EXISTS "${script}")
+ message("warning: CMAKE_TEST_PROJECT_CSE_DIR set, but no build script found...")
+ endif()
+
+ add_test(BuildCSE ${CMAKE_CTEST_COMMAND} -V -S "${script}")
+ set_tests_properties(BuildCSE PROPERTIES TIMEOUT 5400)
+ endif()
+
+ if(CMAKE_TEST_PLPLOT_DIR)
+ add_test(plplot ${CMAKE_CTEST_COMMAND} -V -S ${CMAKE_TEST_PLPLOT_DIR}/../../EasyDashboardScripts/plplot.cmake )
+ set_tests_properties ( plplot PROPERTIES TIMEOUT 5400)
+ endif()
+
+ if(CMAKE_TEST_CHICKEN_DIR)
+ add_test(Chicken ${CMAKE_CTEST_COMMAND} -V -S ${CMAKE_TEST_CHICKEN_DIR}/../../EasyDashboardScripts/Chicken.cmake )
+ set_tests_properties ( Chicken PROPERTIES TIMEOUT 5400)
+ endif()
+
+ if(CMAKE_TEST_KDELIBS_ALPHA_1_DIR)
+ add_test(KDELibsAlpha1 ${CMAKE_CTEST_COMMAND} -V -S ${CMAKE_TEST_KDELIBS_ALPHA_1_DIR}/../../EasyDashboardScripts/kdelibs.cmake )
+ set_tests_properties ( KDELibsAlpha1 PROPERTIES TIMEOUT 5400)
+ endif()
+
+ # If this is not an in-source build, provide a target to wipe out
+ # all the test build directories.
+ if(NOT EXISTS "${CMake_BINARY_DIR}/CMakeLists.txt")
+ configure_file(${CMake_SOURCE_DIR}/Tests/test_clean.cmake.in
+ ${CMake_BINARY_DIR}/Tests/test_clean.cmake @ONLY)
+ add_custom_target(test_clean
+ COMMAND ${CMAKE_COMMAND} -P ${CMake_BINARY_DIR}/Tests/test_clean.cmake
+ COMMENT "Removing test build directories."
+ )
+ endif()
+
+ add_test(NAME CMakeWizardTest COMMAND cmake -i)
+ set_property(TEST CMakeWizardTest PROPERTY PASS_REGULAR_EXPRESSION
+ "The \"cmake -i\" wizard mode is no longer supported.")
+
+ # If the cache variable CMAKE_CONTRACT_PROJECTS is set
+ # then the dashboard will run a contract with CMake test of that
+ # name. For example CMAKE_CONTRACT_PROJECTS = vtk542 would run
+ # the vtk542 contract test.
+ # For each Contract test, the project should provide a directory
+ # with at least one CMakeLists.txt file that uses ExternalProject
+ # to download and configure the project. The directory should also
+ # contain a RunTest.cmake file that has a single set of the format:
+ # set(project_RUN_TEST testToRun)
+ # The testToRun should be a test executable that can be run to
+ # smoke test the build.
+ foreach(project ${CMAKE_CONTRACT_PROJECTS})
+ include(Contracts/${project}/RunTest.cmake)
+ ADD_TEST_MACRO(Contracts.${project}
+ ${${project}_RUN_TEST})
+ # Contract test timeout in seconds.
+ # Default to 6 hours.
+ if(DEFINED ${project}_TEST_TIMEOUT)
+ set(timeout ${${project}_TEST_TIMEOUT})
+ elseif(CMAKE_CONTRACT_TEST_TIMEOUT_DEFAULT)
+ set(timeout ${CMAKE_CONTRACT_TEST_TIMEOUT_DEFAULT})
+ else()
+ set(timeout 21600)
+ endif()
+ set_tests_properties(Contracts.${project} PROPERTIES TIMEOUT ${timeout})
+ endforeach()
+
+ if(TEST_CompileCommandOutput)
+ set(CompileCommandOutput_BUILD_OPTIONS
+ -DMAKE_SUPPORTS_SPACES=${MAKE_SUPPORTS_SPACES})
+ ADD_TEST_MACRO(CompileCommandOutput
+ "${CMake_BINARY_DIR}/Tests/CMakeLib/runcompilecommands")
+ endif()
+
+ add_test(IncludeDirectories ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/IncludeDirectories"
+ "${CMake_BINARY_DIR}/Tests/IncludeDirectories"
+ --build-two-config
+ ${build_generator_args}
+ --build-project IncludeDirectories
+ --build-options ${build_options}
+ --test-command IncludeDirectories)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/IncludeDirectories")
+
+ add_test(InterfaceLinkLibraries ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/InterfaceLinkLibraries"
+ "${CMake_BINARY_DIR}/Tests/InterfaceLinkLibraries"
+ --build-two-config
+ ${build_generator_args}
+ --build-project InterfaceLinkLibraries
+ --build-options ${build_options}
+ --test-command InterfaceLinkLibraries)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/InterfaceLinkLibraries")
+
+ if(CMAKE_USE_KWSTYLE AND KWSTYLE_EXECUTABLE)
+ # The "make StyleCheck" command line as a test. If the test fails, look
+ # for lines like "Error #0 (624) Line length exceed 88 (max=79)" in the
+ # output to find where the style errors are...
+ add_test(KWStyle ${KWSTYLE_EXECUTABLE}
+ -xml ${CMake_BINARY_DIR}/CMake.kws.xml
+ -o ${CMake_SOURCE_DIR}/Utilities/KWStyle/CMakeOverwrite.txt
+ -v
+ -D ${CMake_BINARY_DIR}/CMakeKWSFiles.txt
+ )
+ set_tests_properties(KWStyle PROPERTIES
+ WORKING_DIRECTORY ${CMake_BINARY_DIR}/Utilities/KWStyle)
+ endif()
+
+ if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ add_subdirectory(CMakeTests)
+ endif()
+endif()
diff --git a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
new file mode 100644
index 0000000000..15493be41b
--- /dev/null
+++ b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
@@ -0,0 +1,95 @@
+cmake_minimum_required (VERSION 2.8)
+project(AllFindModules)
+
+if (POLICY CMP0017)
+ cmake_policy(SET CMP0017 NEW)
+endif ()
+
+# Avoid ctest truncation of output
+message(STATUS "CTEST_FULL_OUTPUT")
+
+set(ORIGINAL_MODULE_PATH "${CMAKE_MODULE_PATH}")
+
+file(GLOB FIND_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../Modules/Find*.cmake" )
+
+macro(do_find MODULE_NAME)
+ message(STATUS " Checking Find${MODULE_NAME}")
+ find_package(${MODULE_NAME})
+ set(CMAKE_MODULE_PATH "${ORIGINAL_MODULE_PATH}")
+endmacro()
+
+# It is only possible to use either Qt3 or Qt4 in one project.
+# Since FindQt will complain if both are found we explicitly request Qt4 here
+# and filter out FindQt3. FindKDE3 also depends on Qt3 and
+# is therefore also blocked
+set(DESIRED_QT_VERSION 4)
+set(NO_QT4_MODULES "Qt3" "KDE3")
+
+# ignore everything that has it's own test in Tests/Module/
+file(GLOB OWN_TEST_MODULES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/../../Module/" "${CMAKE_CURRENT_SOURCE_DIR}/../../Module/Find*")
+foreach(FIND_MODULE IN LISTS OWN_TEST_MODULES)
+ string(REGEX REPLACE "^Find" "" _MOD_NAME "${FIND_MODULE}")
+ list(APPEND NO_FIND_MODULES "${_MOD_NAME}")
+endforeach()
+
+# These modules are named Find*.cmake, but are nothing that works in
+# find_package().
+list(APPEND NO_FIND_MODULES "PackageHandleStandardArgs" "PackageMessage")
+
+foreach(FIND_MODULE IN LISTS FIND_MODULES)
+ string(REGEX REPLACE ".*/Find(.*)\\.cmake$" "\\1" MODULE_NAME "${FIND_MODULE}")
+
+ list(FIND NO_QT4_MODULES ${MODULE_NAME} NO_QT4_INDEX)
+ list(FIND NO_FIND_MODULES ${MODULE_NAME} NO_FIND_INDEX)
+ if (NO_QT4_INDEX EQUAL -1 AND NO_FIND_INDEX EQUAL -1)
+ do_find(${MODULE_NAME})
+ endif ()
+
+endforeach()
+
+# Qt4 is not present, so we can check Qt3
+if (NOT QT4_FOUND)
+ set(DESIRED_QT_VERSION 3)
+ foreach(FIND_MODULE ${NO_QT4_MODULES} "Qt")
+ do_find(${FIND_MODULE})
+ endforeach()
+endif ()
+
+macro(check_version_string MODULE_NAME VERSION_VAR)
+ if (${MODULE_NAME}_FOUND)
+ if (DEFINED ${VERSION_VAR})
+ message(STATUS "${VERSION_VAR}='${${VERSION_VAR}}'")
+ if (NOT ${VERSION_VAR} MATCHES "^[0-9]")
+ message(SEND_ERROR "unexpected: ${VERSION_VAR} does not begin with a decimal digit")
+ endif()
+ if ("${${VERSION_VAR}}" STREQUAL "")
+ message(SEND_ERROR "unexpected: ${VERSION_VAR} is empty")
+ endif()
+ if (${VERSION_VAR} VERSION_EQUAL 0)
+ message(SEND_ERROR "unexpected: ${VERSION_VAR} is VERSION_EQUAL 0")
+ endif()
+ if (NOT ${VERSION_VAR} VERSION_GREATER 0)
+ message(SEND_ERROR "unexpected: ${VERSION_VAR} is NOT VERSION_GREATER 0")
+ endif()
+ else()
+ message(SEND_ERROR "${MODULE_NAME}_FOUND is set but version number variable ${VERSION_VAR} is NOT DEFINED")
+ endif()
+ endif ()
+endmacro()
+
+# If any of these modules reported that it was found a version number should have been
+# reported.
+
+foreach(VTEST ALSA ARMADILLO BZIP2 CUPS CURL EXPAT FREETYPE GETTEXT GIT HG
+ HSPELL ICOTOOL JASPER LIBLZMA LIBXML2 LIBXSLT PERL PKG_CONFIG
+ PostgreSQL TIFF ZLIB)
+ check_version_string(${VTEST} ${VTEST}_VERSION_STRING)
+endforeach()
+
+foreach(VTEST BISON Boost CUDA DOXYGEN FLEX GIF GTK2 LibArchive OPENSCENEGRAPH
+ RUBY SWIG)
+ check_version_string(${VTEST} ${VTEST}_VERSION)
+endforeach()
+
+check_version_string(PYTHONINTERP PYTHON_VERSION_STRING)
+check_version_string(SUBVERSION Subversion_VERSION_SVN)
diff --git a/Tests/CMakeOnly/CMakeLists.txt b/Tests/CMakeOnly/CMakeLists.txt
new file mode 100644
index 0000000000..7586de6b25
--- /dev/null
+++ b/Tests/CMakeOnly/CMakeLists.txt
@@ -0,0 +1,62 @@
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Test.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake @ONLY)
+
+macro(add_CMakeOnly_test test)
+ add_test(CMakeOnly.${test} ${CMAKE_CMAKE_COMMAND}
+ -DTEST=${test}
+ -P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
+ )
+endmacro()
+
+add_CMakeOnly_test(LinkInterfaceLoop)
+set_property(TEST CMakeOnly.LinkInterfaceLoop PROPERTY TIMEOUT 90)
+
+add_CMakeOnly_test(CheckSymbolExists)
+
+add_CMakeOnly_test(CheckCXXSymbolExists)
+
+add_CMakeOnly_test(CheckCXXCompilerFlag)
+
+add_CMakeOnly_test(CheckLanguage)
+
+add_CMakeOnly_test(CheckStructHasMember)
+
+add_CMakeOnly_test(CompilerIdC)
+add_CMakeOnly_test(CompilerIdCXX)
+if(CMAKE_Fortran_COMPILER)
+ add_CMakeOnly_test(CompilerIdFortran)
+endif()
+
+add_CMakeOnly_test(AllFindModules)
+
+add_CMakeOnly_test(SelectLibraryConfigurations)
+
+add_CMakeOnly_test(TargetScope)
+
+add_CMakeOnly_test(find_library)
+add_CMakeOnly_test(find_path)
+
+add_test(CMakeOnly.ProjectInclude ${CMAKE_CMAKE_COMMAND}
+ -DTEST=ProjectInclude
+ -DCMAKE_ARGS=-DCMAKE_PROJECT_ProjectInclude_INCLUDE=${CMAKE_CURRENT_SOURCE_DIR}/ProjectInclude/include.cmake
+ -P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
+ )
+
+include(${CMAKE_SOURCE_DIR}/Modules/CMakeParseArguments.cmake)
+
+function(add_major_test module)
+ cmake_parse_arguments(MAJOR_TEST "NOLANG" "VERSION_VAR" "VERSIONS" ${ARGN})
+ foreach (_version IN LISTS MAJOR_TEST_VERSIONS)
+ add_test(CMakeOnly.MajorVersionSelection-${module}_${_version}
+ ${CMAKE_CMAKE_COMMAND}
+ -DTEST=MajorVersionSelection-${module}_${_version}
+ -DTEST_SOURCE=MajorVersionSelection
+ "-DCMAKE_ARGS=-DMAJOR_TEST_MODULE=${module};-DMAJOR_TEST_VERSION=${_version};-DMAJOR_TEST_NO_LANGUAGES=${MAJOR_TEST_NOLANG};-DMAJOR_TEST_VERSION_VAR=${MAJOR_TEST_VERSION_VAR}"
+ -P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
+ )
+ endforeach ()
+endfunction()
+
+add_major_test(PythonLibs VERSIONS 2 3 VERSION_VAR PYTHONLIBS_VERSION_STRING)
+add_major_test(PythonInterp NOLANG VERSIONS 2 3 VERSION_VAR PYTHON_VERSION_STRING)
+add_major_test(Qt VERSIONS 3 4 VERSION_VAR QT_VERSION_STRING)
diff --git a/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt
new file mode 100644
index 0000000000..e205330b08
--- /dev/null
+++ b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt
@@ -0,0 +1,58 @@
+cmake_minimum_required(VERSION 2.8)
+project(CheckCXXCompilerFlag)
+
+message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+set(CMAKE_VERBOSE_MAKEFILE 1)
+
+macro(TEST_FAIL value msg)
+ if (${value})
+ message (SEND_ERROR "Test fail:" ${msg} ${Out} )
+ endif ()
+endmacro()
+
+macro(TEST_PASS value msg)
+ if (NOT ${value})
+ message (SEND_ERROR "Test fail:" ${msg} ${Out} )
+ endif ()
+endmacro()
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE _gcc_version_info)
+ string (REGEX MATCH "[345]\\.[0-9]\\.[0-9]" _gcc_version "${_gcc_version_info}")
+ # gcc on mac just reports: "gcc (GCC) 3.3 20030304 ..." without the
+ # patch level, handle this here:
+ if(NOT _gcc_version)
+ string (REGEX REPLACE ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" _gcc_version "${_gcc_version_info}")
+ endif()
+endif()
+
+if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE _clang_version_info)
+ string (REGEX REPLACE ".*version ([0-9]\\.[0-9]).*" "\\1" _clang_version "${_clang_version_info}")
+endif()
+
+if(CMAKE_CXX_COMPILER_ID MATCHES Intel)
+ exec_program(${CMAKE_CXX_COMPILER} ARGS -V OUTPUT_VARIABLE _intel_version_info)
+ string (REGEX REPLACE ".*Version ([0-9]+(\\.[0-9]+)+).*" "\\1" _intel_version "${_intel_version_info}")
+endif()
+
+message("Platform:\n WIN32: ${WIN32}\n UNIX: ${UNIX}\n APPLE: ${APPLE}\n MINGW: ${MINGW}\n CYGWIN: ${CYGWIN}\n"
+ " MSVC: ${MSVC}\n MSVC60: ${MSVC60}\n MSVC70: ${MSVC70}\n MSVC71: ${MSVC71}\n MSVC80: ${MSVC80}\n MSVC90: ${MSVC90}\n MSVC10: ${MSVC10}\n"
+ " GCC: ${_gcc_version}\n"
+ " Clang: ${_clang_version}\n"
+ " Intel: ${_intel_version}\n"
+)
+
+include(CheckCXXCompilerFlag)
+
+check_cxx_compiler_flag(-fvisibility=hidden HAS_HIDDEN_VISIBILITY)
+
+message("HAS_HIDDEN_VISIBILITY: ${HAS_HIDDEN_VISIBILITY}\n\nCOMPILE OUTPUT:\n${OUTPUT}")
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ if(NOT WIN32)
+# test_pass(HAS_HIDDEN_VISIBILITY "GCC should support hidden visibility, but does not.")
+ endif()
+else()
+ message("Unhandled Platform")
+endif()
diff --git a/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt b/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt
new file mode 100644
index 0000000000..9528aa357d
--- /dev/null
+++ b/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt
@@ -0,0 +1,62 @@
+# This test will verify if CheckCXXSymbolExists only report symbols available
+# for linking that really are. You can find some documentation on this in
+# bug 11333 where we found out that gcc would optimize out the actual
+# reference to the symbol, so symbols that are in fact _not_ available in the
+# given libraries (but seen in header) were reported as present.
+#
+# If you change this test do not forget to change the CheckSymbolExists
+# test, too.
+
+project(CheckCXXSymbolExists CXX)
+
+cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
+
+set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../CheckSymbolExists")
+
+include(CheckCXXSymbolExists)
+
+foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
+ set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
+ unset(CSE_RESULT_${_config_type} CACHE)
+ message(STATUS "Testing configuration ${_config_type}")
+ check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type})
+
+ if (CSE_RESULT_${_config_type})
+ message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}")
+ endif ()
+endforeach()
+
+set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
+unset(CSE_RESULT_ERRNO_CERRNO CACHE)
+
+message(STATUS "Checking <cerrno>")
+
+check_cxx_symbol_exists(errno "cerrno" CSE_RESULT_ERRNO_CERRNO)
+
+if (NOT CSE_RESULT_ERRNO_CERRNO)
+ unset(CSE_RESULT_ERRNO_ERRNOH CACHE)
+
+ message(STATUS "Checking <errno.h>")
+
+ check_cxx_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO_ERRNOH)
+
+ if (NOT CSE_RESULT_ERRNO_ERRNOH)
+ message(SEND_ERROR "CheckCXXSymbolExists did not find errno in <cerrno> and <errno.h>")
+ else ()
+ message(STATUS "errno found in <errno.h>")
+ endif ()
+else ()
+ message(STATUS "errno found in <cerrno>")
+endif ()
+
+if (CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
+ unset(CSE_RESULT_O3 CACHE)
+ message(STATUS "Testing with optimization -O3")
+
+ check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3)
+
+ if (CSE_RESULT_O3)
+ message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing with optimization -O3")
+ endif ()
+endif ()
diff --git a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt
new file mode 100644
index 0000000000..f5336dc039
--- /dev/null
+++ b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt
@@ -0,0 +1,22 @@
+cmake_minimum_required (VERSION 2.8)
+project(CheckLanguage NONE)
+include(CheckLanguage)
+
+set(langs )
+set(expect_C 1)
+set(expect_CXX 1)
+unset(expect_Fortran)
+set(expect_NoSuchLanguage 0)
+foreach(lang C CXX Fortran NoSuchLanguage)
+ check_language(${lang})
+ if(NOT DEFINED CMAKE_${lang}_COMPILER)
+ message(FATAL_ERROR "check_language(${lang}) did not set result")
+ endif()
+ if(DEFINED expect_${lang})
+ if(expect_${lang} AND NOT CMAKE_${lang}_COMPILER)
+ message(FATAL_ERROR "check_language(${lang}) should not fail!")
+ elseif(NOT expect_${lang} AND CMAKE_${lang}_COMPILER)
+ message(FATAL_ERROR "check_language(${lang}) should not succeed!")
+ endif()
+ endif()
+endforeach()
diff --git a/Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt b/Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt
new file mode 100644
index 0000000000..f06d5c34dd
--- /dev/null
+++ b/Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt
@@ -0,0 +1,93 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(CheckStructHasMember)
+
+set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")
+
+include(CheckStructHasMember)
+
+foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
+ set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
+ unset(CSHM_RESULT_S1_${_config_type} CACHE)
+ unset(CSHM_RESULT_S2_${_config_type} CACHE)
+ unset(CSHM_RESULT_S3_${_config_type} CACHE)
+ message(STATUS "Testing configuration ${_config_type}")
+
+ check_struct_has_member("struct non_existent_struct" "foo" "cm_cshm.h" CSHM_RESULT_S1_${_config_type})
+ check_struct_has_member("struct struct_with_member" "non_existent_member" "cm_cshm.h" CSHM_RESULT_S2_${_config_type})
+ check_struct_has_member("struct struct_with_member" "member" "cm_cshm.h" CSHM_RESULT_S3_${_config_type})
+
+ if(CSHM_RESULT_S1_${_config_type} OR CSHM_RESULT_S2_${_config_type})
+ message(SEND_ERROR "CheckStructHasMember reported a nonexistent member as existing in configuration ${_config_type}")
+ endif()
+
+ if(NOT CSHM_RESULT_S3_${_config_type})
+ message(SEND_ERROR "CheckStructHasMember did not report an existent member as existing in configuration ${_config_type}")
+ endif()
+endforeach()
+
+foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
+ set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
+ unset(CSHM_RESULT_S1_${_config_type}_C CACHE)
+ unset(CSHM_RESULT_S2_${_config_type}_C CACHE)
+ unset(CSHM_RESULT_S3_${_config_type}_C CACHE)
+ message(STATUS "Testing configuration ${_config_type}")
+
+ check_struct_has_member("struct non_existent_struct" "foo" "cm_cshm.h" CSHM_RESULT_S1_${_config_type}_C LANGUAGE C)
+ check_struct_has_member("struct struct_with_member" "non_existent_member" "cm_cshm.h" CSHM_RESULT_S2_${_config_type}_C LANGUAGE C)
+ check_struct_has_member("struct struct_with_member" "member" "cm_cshm.h" CSHM_RESULT_S3_${_config_type}_C LANGUAGE C)
+
+ if(CSHM_RESULT_S1_${_config_type}_C OR CSHM_RESULT_S2_${_config_type}_C)
+ message(SEND_ERROR "CheckStructHasMember reported a nonexistent member as existing in configuration ${_config_type}")
+ endif()
+
+ if(NOT CSHM_RESULT_S3_${_config_type}_C)
+ message(SEND_ERROR "CheckStructHasMember did not report an existent member as existing in configuration ${_config_type}")
+ endif()
+endforeach()
+
+foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
+ set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
+ unset(CSHM_RESULT_S1_${_config_type}_CXX CACHE)
+ unset(CSHM_RESULT_S2_${_config_type}_CXX CACHE)
+ unset(CSHM_RESULT_S3_${_config_type}_CXX CACHE)
+ unset(CSHM_RESULT_C1_${_config_type}_CXX CACHE)
+ unset(CSHM_RESULT_C2_${_config_type}_CXX CACHE)
+ unset(CSHM_RESULT_C3_${_config_type}_CXX CACHE)
+
+ message(STATUS "Testing configuration ${_config_type}")
+
+ check_struct_has_member("non_existent_struct" "foo" "cm_cshm.h" CSHM_RESULT_S1_${_config_type}_CXX LANGUAGE CXX)
+ check_struct_has_member("struct_with_non_existent_members" "non_existent_member" "cm_cshm.h" CSHM_RESULT_S2_${_config_type}_CXX LANGUAGE CXX)
+ check_struct_has_member("struct struct_with_member" "member" "cm_cshm.h" CSHM_RESULT_S3_${_config_type}_CXX LANGUAGE CXX)
+ check_struct_has_member("ns::non_existent_class" "foo" "cm_cshm.hxx" CSHM_RESULT_C1_${_config_type}_CXX LANGUAGE CXX)
+ check_struct_has_member("ns::class_with_non_existent_members" "foo" "cm_cshm.hxx" CSHM_RESULT_C2_${_config_type}_CXX LANGUAGE CXX)
+ check_struct_has_member("ns::class_with_member" "foo" "cm_cshm.hxx" CSHM_RESULT_C3_${_config_type}_CXX LANGUAGE CXX)
+
+ if(CSHM_RESULT_S1_${_config_type}_CXX OR CSHM_RESULT_S2_${_config_type}_CXX OR CSHM_RESULT_C1_${_config_type}_CXX OR CSHM_RESULT_C2_${_config_type}_CXX)
+ message(SEND_ERROR "CheckStructHasMember reported a nonexistent member as existing in configuration ${_config_type}")
+ endif()
+
+ if(NOT CSHM_RESULT_S3_${_config_type}_CXX OR NOT CSHM_RESULT_C3_${_config_type}_CXX)
+ message(SEND_ERROR "CheckStructHasMember did not report an existent member as existing in configuration ${_config_type}")
+ endif()
+endforeach()
+
+
+set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
+
+if (CMAKE_COMPILER_IS_GNUCC)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
+ unset(CSHM_RESULT_O3 CACHE)
+ unset(CSHM_RESULT_O3_C CACHE)
+ unset(CSHM_RESULT_O3_CXX CACHE)
+ message(STATUS "Testing with optimization -O3")
+
+ check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" CSHM_RESULT_O3)
+ check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" CSHM_RESULT_O3_C LANGUAGE C)
+ check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" CSHM_RESULT_O3_CXX LANGUAGE CXX)
+
+ if (CSE_RESULT_O3 OR CSHM_RESULT_O3_C OR CSHM_RESULT_O3_CXX)
+ message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3")
+ endif ()
+endif ()
diff --git a/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.h b/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.h
new file mode 100644
index 0000000000..82bb0498c9
--- /dev/null
+++ b/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.h
@@ -0,0 +1,9 @@
+#ifndef _CSHM_DUMMY_H
+#define _CSHM_DUMMY_H
+
+struct non_existent_struct;
+struct struct_with_member{
+ int member;
+};
+
+#endif
diff --git a/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.hxx b/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.hxx
new file mode 100644
index 0000000000..458a99b469
--- /dev/null
+++ b/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.hxx
@@ -0,0 +1,16 @@
+#ifndef _CSHM_DUMMY_HXX
+#define _CSHM_DUMMY_HXX
+
+namespace ns {
+
+class non_existent_class;
+class class_with_non_existent_members {
+};
+class class_with_member {
+public:
+ int foo;
+};
+
+}
+
+#endif
diff --git a/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt b/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt
new file mode 100644
index 0000000000..765657712a
--- /dev/null
+++ b/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt
@@ -0,0 +1,51 @@
+# This test will verify if CheckSymbolExists only report symbols available
+# for linking that really are. You can find some documentation on this in
+# bug 11333 where we found out that gcc would optimize out the actual
+# reference to the symbol, so symbols that are in fact _not_ available in the
+# given libraries (but seen in header) were reported as present.
+#
+# If you change this test do not forget to change the CheckCXXSymbolExists
+# test, too.
+
+project(CheckSymbolExists C)
+
+cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
+
+set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")
+
+include(CheckSymbolExists)
+
+foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
+ set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
+ unset(CSE_RESULT_${_config_type} CACHE)
+ message(STATUS "Testing configuration ${_config_type}")
+
+ check_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type})
+
+ if (CSE_RESULT_${_config_type})
+ message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}")
+ endif ()
+endforeach()
+
+set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
+unset(CSE_RESULT_ERRNO CACHE)
+
+check_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO)
+
+if (NOT CSE_RESULT_ERRNO)
+ message(SEND_ERROR "CheckSymbolExists did not find errno in <errno.h>")
+else ()
+ message(STATUS "errno found as expected")
+endif ()
+
+if (CMAKE_COMPILER_IS_GNUCC)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
+ unset(CSE_RESULT_O3 CACHE)
+ message(STATUS "Testing with optimization -O3")
+
+ check_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3)
+
+ if (CSE_RESULT_O3)
+ message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3")
+ endif ()
+endif ()
diff --git a/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h b/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h
new file mode 100644
index 0000000000..4f41c76963
--- /dev/null
+++ b/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h
@@ -0,0 +1,6 @@
+#ifndef _CSE_DUMMY_H
+#define _CSE_DUMMY_H
+
+int non_existent_function_for_symbol_test();
+
+#endif
diff --git a/Tests/CMakeOnly/CompilerIdC/CMakeLists.txt b/Tests/CMakeOnly/CompilerIdC/CMakeLists.txt
new file mode 100644
index 0000000000..848ffdd36c
--- /dev/null
+++ b/Tests/CMakeOnly/CompilerIdC/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 2.8.9)
+project(CompilerIdC C)
+
+foreach(v
+ CMAKE_C_COMPILER
+ CMAKE_C_COMPILER_ID
+ CMAKE_C_COMPILER_VERSION
+ )
+ if(${v})
+ message(STATUS "${v}=[${${v}}]")
+ else()
+ message(SEND_ERROR "${v} not set!")
+ endif()
+endforeach()
diff --git a/Tests/CMakeOnly/CompilerIdCXX/CMakeLists.txt b/Tests/CMakeOnly/CompilerIdCXX/CMakeLists.txt
new file mode 100644
index 0000000000..94ac31e4c8
--- /dev/null
+++ b/Tests/CMakeOnly/CompilerIdCXX/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 2.8.9)
+project(CompilerIdCXX CXX)
+
+foreach(v
+ CMAKE_CXX_COMPILER
+ CMAKE_CXX_COMPILER_ID
+ CMAKE_CXX_COMPILER_VERSION
+ )
+ if(${v})
+ message(STATUS "${v}=[${${v}}]")
+ else()
+ message(SEND_ERROR "${v} not set!")
+ endif()
+endforeach()
diff --git a/Tests/CMakeOnly/CompilerIdFortran/CMakeLists.txt b/Tests/CMakeOnly/CompilerIdFortran/CMakeLists.txt
new file mode 100644
index 0000000000..3a2bdebd69
--- /dev/null
+++ b/Tests/CMakeOnly/CompilerIdFortran/CMakeLists.txt
@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 2.8.9)
+project(CompilerIdFortran Fortran)
+
+foreach(v
+ CMAKE_Fortran_COMPILER
+ CMAKE_Fortran_COMPILER_ID
+ )
+ if(${v})
+ message(STATUS "${v}=[${${v}}]")
+ else()
+ message(SEND_ERROR "${v} not set!")
+ endif()
+endforeach()
+foreach(v
+ CMAKE_Fortran_COMPILER_VERSION
+ )
+ if(${v})
+ message(STATUS "${v}=[${${v}}]")
+ else()
+ message(WARNING "${v} not set!")
+ endif()
+endforeach()
diff --git a/Tests/CMakeOnly/LinkInterfaceLoop/CMakeLists.txt b/Tests/CMakeOnly/LinkInterfaceLoop/CMakeLists.txt
new file mode 100644
index 0000000000..56e449afdd
--- /dev/null
+++ b/Tests/CMakeOnly/LinkInterfaceLoop/CMakeLists.txt
@@ -0,0 +1,27 @@
+cmake_minimum_required (VERSION 2.8)
+project(LinkInterfaceLoop C)
+
+# Add a shared library that incorrectly names itself as a
+# dependency, thus forming a cycle.
+add_library(A SHARED IMPORTED)
+set_target_properties(A PROPERTIES
+ IMPORTED_LINK_DEPENDENT_LIBRARIES A
+ IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/dirA/A"
+ )
+
+# Add a shared library that incorrectly names itself in
+# its link interface, thus forming a cycle.
+add_library(B SHARED IMPORTED)
+set_target_properties(B PROPERTIES
+ IMPORTED_LINK_INTERFACE_LIBRARIES B
+ IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/dirB/B"
+ )
+
+# Add a shared library with an empty link interface
+# that depends on two shared libraries.
+add_library(C SHARED lib.c)
+set_property(TARGET C PROPERTY LINK_INTERFACE_LIBRARIES "")
+target_link_libraries(C B A)
+
+add_executable(main main.c)
+target_link_libraries(main C)
diff --git a/Tests/CMakeOnly/LinkInterfaceLoop/lib.c b/Tests/CMakeOnly/LinkInterfaceLoop/lib.c
new file mode 100644
index 0000000000..fede1d61f9
--- /dev/null
+++ b/Tests/CMakeOnly/LinkInterfaceLoop/lib.c
@@ -0,0 +1 @@
+int lib(void) { return 0; }
diff --git a/Tests/CMakeOnly/LinkInterfaceLoop/main.c b/Tests/CMakeOnly/LinkInterfaceLoop/main.c
new file mode 100644
index 0000000000..78f2de106c
--- /dev/null
+++ b/Tests/CMakeOnly/LinkInterfaceLoop/main.c
@@ -0,0 +1 @@
+int main(void) { return 0; }
diff --git a/Tests/CMakeOnly/MajorVersionSelection/CMakeLists.txt b/Tests/CMakeOnly/MajorVersionSelection/CMakeLists.txt
new file mode 100644
index 0000000000..2511064a2d
--- /dev/null
+++ b/Tests/CMakeOnly/MajorVersionSelection/CMakeLists.txt
@@ -0,0 +1,46 @@
+cmake_minimum_required(VERSION 2.8)
+
+if (NOT MAJOR_TEST_MODULE OR NOT MAJOR_TEST_VERSION)
+ message(FATAL_ERROR "test selection variables not set up")
+endif ()
+
+if (MAJOR_TEST_NO_LANGUAGES)
+ project(major_detect_${MAJOR_TEST_MODULE}_${MAJOR_TEST_VERSION} NONE)
+else ()
+ project(major_detect_${MAJOR_TEST_MODULE}_${MAJOR_TEST_VERSION})
+endif ()
+
+find_package(${MAJOR_TEST_MODULE} ${MAJOR_TEST_VERSION})
+
+if (MAJOR_TEST_VERSION_VAR)
+ set(VERSION_VAR "${MAJOR_TEST_VERSION_VAR}")
+else ()
+ set(VERSION_VAR "${MAJOR_TEST_MODULE}_VERSION_STRING")
+endif ()
+
+string(TOUPPER "${MAJOR_TEST_MODULE}" MODULE_UPPER)
+
+if ( ( ${MAJOR_TEST_MODULE}_FOUND OR ${MODULE_UPPER}_FOUND ) AND ${VERSION_VAR})
+ message(STATUS "${VERSION_VAR} is '${${VERSION_VAR}}'")
+ if (${VERSION_VAR} VERSION_LESS MAJOR_TEST_VERSION)
+ message(SEND_ERROR "Found version ${${VERSION_VAR}} is less than requested major version ${MAJOR_TEST_VERSION}")
+ endif ()
+ math(EXPR V_PLUS_ONE "${MAJOR_TEST_VERSION} + 1")
+ if (${VERSION_VAR} VERSION_GREATER V_PLUS_ONE)
+ message(SEND_ERROR "Found version ${${VERSION_VAR}} is greater than requested major version ${MAJOR_TEST_VERSION}")
+ endif ()
+endif ()
+
+if ( ( ${MAJOR_TEST_MODULE}_FOUND OR ${MODULE_UPPER}_FOUND ) AND ${MAJOR_TEST_MODULE}_VERSION_MAJOR)
+ message(STATUS "${MAJOR_TEST_MODULE}_VERSION_MAJOR is '${${MAJOR_TEST_MODULE}_VERSION_MAJOR}'")
+ if (NOT ${MAJOR_TEST_VERSION} EQUAL ${MAJOR_TEST_MODULE}_VERSION_MAJOR)
+ message(SEND_ERROR "We requested major version ${MAJOR_TEST_VERSION} but ${MAJOR_TEST_MODULE} set ${MAJOR_TEST_MODULE}_VERSION_MAJOR to ${${MAJOR_TEST_MODULE}_VERSION_MAJOR}")
+ endif ()
+endif ()
+
+if ( ( ${MAJOR_TEST_MODULE}_FOUND OR ${MODULE_UPPER}_FOUND ) AND ${MODULE_UPPER}_VERSION_MAJOR)
+ message(STATUS "${MODULE_UPPER}_VERSION_MAJOR is '${${MODULE_UPPER}_VERSION_MAJOR}'")
+ if (NOT ${MAJOR_TEST_VERSION} EQUAL ${MODULE_UPPER}_VERSION_MAJOR)
+ message(SEND_ERROR "We requested major version ${MAJOR_TEST_VERSION} but ${MAJOR_TEST_MODULE} set ${MODULE_UPPER}_VERSION_MAJOR to ${${MODULE_UPPER}_VERSION_MAJOR}")
+ endif ()
+endif ()
diff --git a/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt b/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt
new file mode 100644
index 0000000000..a9abb4ad7a
--- /dev/null
+++ b/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt
@@ -0,0 +1,4 @@
+project(ProjectInclude)
+if(NOT AUTO_INCLUDE)
+ message(FATAL_ERROR "include file not found")
+endif()
diff --git a/Tests/CMakeOnly/ProjectInclude/include.cmake b/Tests/CMakeOnly/ProjectInclude/include.cmake
new file mode 100644
index 0000000000..527ebe7d04
--- /dev/null
+++ b/Tests/CMakeOnly/ProjectInclude/include.cmake
@@ -0,0 +1 @@
+set(AUTO_INCLUDE TRUE)
diff --git a/Tests/CMakeOnly/SelectLibraryConfigurations/CMakeLists.txt b/Tests/CMakeOnly/SelectLibraryConfigurations/CMakeLists.txt
new file mode 100644
index 0000000000..6d1628ae51
--- /dev/null
+++ b/Tests/CMakeOnly/SelectLibraryConfigurations/CMakeLists.txt
@@ -0,0 +1,64 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(SelectLibraryConfigurations NONE)
+
+include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake)
+
+macro(check_slc basename expect)
+ message(STATUS "checking select_library_configurations(${basename})")
+ select_library_configurations(${basename})
+ if (NOT ${basename}_LIBRARY STREQUAL "${expect}")
+ message(SEND_ERROR "select_library_configurations(${basename}) returned '${${basename}_LIBRARY}' but '${expect}' was expected")
+ endif ()
+ if (NOT ${basename}_LIBRARY STREQUAL "${${basename}_LIBRARIES}")
+ message(SEND_ERROR "select_library_configurations(${basename}) LIBRARY: '${${basename}_LIBRARY}' LIBRARIES: '${${basename}_LIBRARIES}'")
+ endif ()
+endmacro(check_slc)
+
+if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
+ set(NOTYPE_RELONLY_LIBRARY_RELEASE "opt")
+ check_slc(NOTYPE_RELONLY "opt")
+
+ set(NOTYPE_DBGONLY_LIBRARY_DEBUG "dbg")
+ check_slc(NOTYPE_DBGONLY "dbg")
+
+ set(NOTYPE_RELDBG_LIBRARY_RELEASE "opt")
+ set(NOTYPE_RELDBG_LIBRARY_DEBUG "dbg")
+ check_slc(NOTYPE_RELDBG "opt")
+
+ set(CMAKE_BUILD_TYPE Debug)
+endif ()
+
+check_slc(empty "empty_LIBRARY-NOTFOUND")
+
+set(OPTONLY_LIBRARY_RELEASE "opt")
+check_slc(OPTONLY "opt")
+
+set(DBGONLY_LIBRARY_RELEASE "dbg")
+check_slc(DBGONLY "dbg")
+
+set(SAME_LIBRARY_RELEASE "same")
+set(SAME_LIBRARY_DEBUG "same")
+check_slc(SAME "same")
+
+set(OPTONLYLIST_LIBRARY_RELEASE "opt1;opt2")
+check_slc(OPTONLYLIST "opt1;opt2")
+
+set(DBGONLYLIST_LIBRARY_RELEASE "dbg1;dbg2")
+check_slc(DBGONLYLIST "dbg1;dbg2")
+
+set(OPT1DBG1_LIBRARY_RELEASE "opt")
+set(OPT1DBG1_LIBRARY_DEBUG "dbg")
+check_slc(OPT1DBG1 "optimized;opt;debug;dbg")
+
+set(OPT1DBG2_LIBRARY_RELEASE "opt")
+set(OPT1DBG2_LIBRARY_DEBUG "dbg1;dbg2")
+check_slc(OPT1DBG2 "optimized;opt;debug;dbg1;debug;dbg2")
+
+set(OPT2DBG1_LIBRARY_RELEASE "opt1;opt2")
+set(OPT2DBG1_LIBRARY_DEBUG "dbg")
+check_slc(OPT2DBG1 "optimized;opt1;optimized;opt2;debug;dbg")
+
+set(OPT2DBG2_LIBRARY_RELEASE "opt1;opt2")
+set(OPT2DBG2_LIBRARY_DEBUG "dbg1;dbg2")
+check_slc(OPT2DBG2 "optimized;opt1;optimized;opt2;debug;dbg1;debug;dbg2")
diff --git a/Tests/CMakeOnly/TargetScope/CMakeLists.txt b/Tests/CMakeOnly/TargetScope/CMakeLists.txt
new file mode 100644
index 0000000000..fa5d8e2342
--- /dev/null
+++ b/Tests/CMakeOnly/TargetScope/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required (VERSION 2.8)
+project(TargetScope NONE)
+
+add_subdirectory(Sub)
+
+if(TARGET SubLibLocal)
+ message(FATAL_ERROR "SubLibLocal visible in top directory")
+endif()
+if(NOT TARGET SubLibGlobal)
+ message(FATAL_ERROR "SubLibGlobal not visible in top directory")
+endif()
+
+add_subdirectory(Sib)
diff --git a/Tests/CMakeOnly/TargetScope/Sib/CMakeLists.txt b/Tests/CMakeOnly/TargetScope/Sib/CMakeLists.txt
new file mode 100644
index 0000000000..7f6f4e8fdc
--- /dev/null
+++ b/Tests/CMakeOnly/TargetScope/Sib/CMakeLists.txt
@@ -0,0 +1,6 @@
+if(TARGET SubLibLocal)
+ message(FATAL_ERROR "SubLibLocal visible in sibling directory")
+endif()
+if(NOT TARGET SubLibGlobal)
+ message(FATAL_ERROR "SubLibGlobal not visible in sibling directory")
+endif()
diff --git a/Tests/CMakeOnly/TargetScope/Sub/CMakeLists.txt b/Tests/CMakeOnly/TargetScope/Sub/CMakeLists.txt
new file mode 100644
index 0000000000..27318f5853
--- /dev/null
+++ b/Tests/CMakeOnly/TargetScope/Sub/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_library(SubLibLocal UNKNOWN IMPORTED)
+add_library(SubLibGlobal UNKNOWN IMPORTED GLOBAL)
+add_subdirectory(Sub)
+if(NOT TARGET SubLibLocal)
+ message(FATAL_ERROR "SubLibLocal not visible in own directory")
+endif()
+if(NOT TARGET SubLibGlobal)
+ message(FATAL_ERROR "SubLibGlobal not visible in own directory")
+endif()
diff --git a/Tests/CMakeOnly/TargetScope/Sub/Sub/CMakeLists.txt b/Tests/CMakeOnly/TargetScope/Sub/Sub/CMakeLists.txt
new file mode 100644
index 0000000000..a351daadfc
--- /dev/null
+++ b/Tests/CMakeOnly/TargetScope/Sub/Sub/CMakeLists.txt
@@ -0,0 +1,6 @@
+if(NOT TARGET SubLibLocal)
+ message(FATAL_ERROR "SubLibLocal not visible in subdirectory")
+endif()
+if(NOT TARGET SubLibGlobal)
+ message(FATAL_ERROR "SubLibGlobal not visible in subdirectory")
+endif()
diff --git a/Tests/CMakeOnly/Test.cmake.in b/Tests/CMakeOnly/Test.cmake.in
new file mode 100644
index 0000000000..8d3258b9d0
--- /dev/null
+++ b/Tests/CMakeOnly/Test.cmake.in
@@ -0,0 +1,19 @@
+if (NOT TEST_SOURCE)
+ set(TEST_SOURCE "${TEST}")
+endif ()
+
+set(source_dir "@CMAKE_CURRENT_SOURCE_DIR@/${TEST_SOURCE}")
+set(binary_dir "@CMAKE_CURRENT_BINARY_DIR@/${TEST}-build")
+file(REMOVE_RECURSE "${binary_dir}")
+file(MAKE_DIRECTORY "${binary_dir}")
+execute_process(
+ COMMAND ${CMAKE_COMMAND} ${CMAKE_ARGS}
+ "${source_dir}" -G "@CMAKE_GENERATOR@"
+ -A "@CMAKE_GENERATOR_PLATFORM@"
+ -T "@CMAKE_GENERATOR_TOOLSET@"
+ WORKING_DIRECTORY "${binary_dir}"
+ RESULT_VARIABLE result
+ )
+if(result)
+ message(FATAL_ERROR "CMake failed to configure ${TEST}")
+endif()
diff --git a/Tests/CMakeOnly/find_library/A/libtestA.a b/Tests/CMakeOnly/find_library/A/libtestA.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/A/libtestA.a
diff --git a/Tests/CMakeOnly/find_library/B/libtestB.a b/Tests/CMakeOnly/find_library/B/libtestB.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/B/libtestB.a
diff --git a/Tests/CMakeOnly/find_library/CMakeLists.txt b/Tests/CMakeOnly/find_library/CMakeLists.txt
new file mode 100644
index 0000000000..2d4ecaf140
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/CMakeLists.txt
@@ -0,0 +1,74 @@
+cmake_minimum_required(VERSION 2.8)
+project(FindLibraryTest NONE)
+
+set(CMAKE_FIND_DEBUG_MODE 1)
+
+macro(test_find_library desc expected)
+ unset(LIB CACHE)
+ find_library(LIB ${ARGN} NO_DEFAULT_PATH)
+ if(LIB)
+ # Convert to relative path for comparison to expected location.
+ file(RELATIVE_PATH REL_LIB "${CMAKE_CURRENT_SOURCE_DIR}" "${LIB}")
+
+ # Check and report failure.
+ if(NOT "${REL_LIB}" STREQUAL "${expected}")
+ message(SEND_ERROR "Library ${expected} found as [${REL_LIB}]${desc}")
+ elseif(CMAKE_FIND_DEBUG_MODE)
+ message(STATUS "Library ${expected} found as [${REL_LIB}]${desc}")
+ endif()
+ else()
+ message(SEND_ERROR "Library ${expected} NOT FOUND${desc}")
+ endif()
+endmacro()
+
+macro(test_find_library_subst expected)
+ get_filename_component(dir ${expected} PATH)
+ get_filename_component(name ${expected} NAME)
+ string(REGEX REPLACE "lib/?64" "lib" dir "${dir}")
+ test_find_library(", searched as ${dir}" "${expected}"
+ NAMES ${name}
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}
+ )
+endmacro()
+
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
+
+set(CMAKE_SIZEOF_VOID_P 4)
+foreach(lib
+ lib/A/lib/libtest1.a
+ lib/A/libtest1.a
+ lib/libtest1.a
+ lib/libtest2.a
+ lib/libtest3.a
+ lib/libtest3.a
+ )
+ test_find_library_subst(${lib})
+endforeach()
+
+set(CMAKE_SIZEOF_VOID_P 8)
+foreach(lib64
+ lib/64/libtest2.a
+ lib/A/lib64/libtest3.a
+ lib/libtest3.a
+ lib64/A/lib/libtest2.a
+ lib64/A/lib64/libtest1.a
+ lib64/A/libtest1.a
+ lib64/libtest1.a
+ )
+ test_find_library_subst(${lib64})
+endforeach()
+
+test_find_library("" A/libtestA.a
+ NAMES testA testB
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A ${CMAKE_CURRENT_SOURCE_DIR}/B
+ )
+test_find_library("" B/libtestB.a
+ NAMES testB testA
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A ${CMAKE_CURRENT_SOURCE_DIR}/B
+ )
+test_find_library("" A/libtestA.a
+ NAMES testB testA NAMES_PER_DIR
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A ${CMAKE_CURRENT_SOURCE_DIR}/B
+ )
diff --git a/Tests/CMakeOnly/find_library/lib/64/libtest2.a b/Tests/CMakeOnly/find_library/lib/64/libtest2.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/64/libtest2.a
diff --git a/Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a b/Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a
diff --git a/Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a b/Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a
diff --git a/Tests/CMakeOnly/find_library/lib/A/libtest1.a b/Tests/CMakeOnly/find_library/lib/A/libtest1.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/A/libtest1.a
diff --git a/Tests/CMakeOnly/find_library/lib/libtest1.a b/Tests/CMakeOnly/find_library/lib/libtest1.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/libtest1.a
diff --git a/Tests/CMakeOnly/find_library/lib/libtest2.a b/Tests/CMakeOnly/find_library/lib/libtest2.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/libtest2.a
diff --git a/Tests/CMakeOnly/find_library/lib/libtest3.a b/Tests/CMakeOnly/find_library/lib/libtest3.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/libtest3.a
diff --git a/Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a b/Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a
diff --git a/Tests/CMakeOnly/find_library/lib64/A/lib64/libtest1.a b/Tests/CMakeOnly/find_library/lib64/A/lib64/libtest1.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib64/A/lib64/libtest1.a
diff --git a/Tests/CMakeOnly/find_library/lib64/A/libtest1.a b/Tests/CMakeOnly/find_library/lib64/A/libtest1.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib64/A/libtest1.a
diff --git a/Tests/CMakeOnly/find_library/lib64/libtest1.a b/Tests/CMakeOnly/find_library/lib64/libtest1.a
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib64/libtest1.a
diff --git a/Tests/CMakeOnly/find_path/CMakeLists.txt b/Tests/CMakeOnly/find_path/CMakeLists.txt
new file mode 100644
index 0000000000..0e64ed4674
--- /dev/null
+++ b/Tests/CMakeOnly/find_path/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 2.8)
+project(FindPathTest NONE)
+
+set(CMAKE_FIND_DEBUG_MODE 1)
+
+macro(test_find_path expected)
+ unset(HDR CACHE)
+ find_path(HDR ${ARGN}
+ NO_CMAKE_ENVIRONMENT_PATH
+ NO_SYSTEM_ENVIRONMENT_PATH
+ )
+ if(HDR)
+ # Convert to relative path for comparison to expected location.
+ file(RELATIVE_PATH REL_HDR "${CMAKE_CURRENT_SOURCE_DIR}" "${HDR}")
+
+ # Check and report failure.
+ if(NOT "${REL_HDR}" STREQUAL "${expected}")
+ message(SEND_ERROR "Header ${expected} found as [${REL_HDR}]")
+ elseif(CMAKE_FIND_DEBUG_MODE)
+ message(STATUS "Header ${expected} found as [${REL_HDR}]")
+ endif()
+ else()
+ message(SEND_ERROR "Header ${expected} NOT FOUND")
+ endif()
+endmacro()
+
+set(CMAKE_SYSTEM_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
+set(CMAKE_LIBRARY_ARCHITECTURE arch)
+
+test_find_path(include NAMES test1.h)
+test_find_path(include/arch NAMES test1arch.h)
diff --git a/Tests/CMakeOnly/find_path/include/arch/test1arch.h b/Tests/CMakeOnly/find_path/include/arch/test1arch.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_path/include/arch/test1arch.h
diff --git a/Tests/CMakeOnly/find_path/include/test1.h b/Tests/CMakeOnly/find_path/include/test1.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CMakeOnly/find_path/include/test1.h
diff --git a/Tests/CMakeTestAllGenerators/RunCMake.cmake b/Tests/CMakeTestAllGenerators/RunCMake.cmake
new file mode 100644
index 0000000000..6d27d3be17
--- /dev/null
+++ b/Tests/CMakeTestAllGenerators/RunCMake.cmake
@@ -0,0 +1,117 @@
+if(NOT DEFINED CMake_SOURCE_DIR)
+ message(FATAL_ERROR "CMake_SOURCE_DIR not defined")
+endif()
+
+if(NOT DEFINED dir)
+ message(FATAL_ERROR "dir not defined")
+endif()
+
+# Analyze 'cmake --help' output for list of available generators:
+#
+execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${dir})
+execute_process(COMMAND ${CMAKE_COMMAND} --help
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ WORKING_DIRECTORY ${dir})
+
+string(REPLACE ";" "\\;" stdout "${stdout}")
+string(REPLACE "\n" "E;" stdout "${stdout}")
+
+set(collecting 0)
+set(generators)
+foreach(eline ${stdout})
+ string(REGEX REPLACE "^(.*)E$" "\\1" line "${eline}")
+ if(collecting AND NOT line STREQUAL "")
+ if(line MATCHES "=")
+ string(REGEX REPLACE "^ (.+)= (.*)$" "\\1" gen "${line}")
+ if(gen MATCHES "[A-Za-z]")
+ string(REGEX REPLACE "^(.*[^ ]) +$" "\\1" gen "${gen}")
+ if(gen)
+ set(generators ${generators} ${gen})
+ endif()
+ endif()
+ else()
+ if(line MATCHES "^ [A-Za-z0-9]")
+ string(REGEX REPLACE "^ (.+)$" "\\1" gen "${line}")
+ string(REGEX REPLACE "^(.*[^ ]) +$" "\\1" gen "${gen}")
+ if(gen)
+ set(generators ${generators} ${gen})
+ endif()
+ endif()
+ endif()
+ endif()
+ if(line STREQUAL "The following generators are available on this platform:")
+ set(collecting 1)
+ endif()
+endforeach()
+
+# Also call with one non-existent generator:
+#
+set(generators ${generators} "BOGUS_CMAKE_GENERATOR")
+
+# Call cmake with -G on each available generator. We do not care if this
+# succeeds or not. We expect it *not* to succeed if the underlying packaging
+# tools are not installed on the system... This test is here simply to add
+# coverage for the various cmake generators, even/especially to test ones
+# where the tools are not installed.
+#
+message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+
+message(STATUS "CMake generators='${generators}'")
+
+# If we'll be testing any of the MinGW Makefiles generators, adjust the
+# ENV{PATH} to make sure libgmp-10.dll can be loaded as needed. But only if
+# the testing machine has a default MinGW install... (If you have a
+# non-default install, append to the PATH before running the test...)
+#
+if(generators MATCHES "MinGW Makefiles")
+ if(EXISTS "C:/MinGW/bin/libgmp-10.dll")
+ string(TOLOWER "$ENV{PATH}" path)
+ if(NOT path MATCHES "/mingw/bin")
+ if(UNIX)
+ set(sep ":")
+ set(mingw_bin "/mingw/bin")
+ else()
+ set(sep ";")
+ set(mingw_bin "C:/MinGW/bin")
+ endif()
+ set(ENV{PATH} "$ENV{PATH}${sep}${mingw_bin}")
+ message(STATUS "info: appending '${sep}${mingw_bin}' to the PATH")
+ endif()
+ endif()
+endif()
+
+# First setup a source tree to run CMake on.
+#
+execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
+ ${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast
+ ${dir}/Source
+)
+
+foreach(g ${generators})
+ message(STATUS "cmake -G \"${g}\" ..")
+
+ # Create a binary directory for each generator:
+ #
+ execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
+ ${dir}/Source/${g}
+ )
+
+ # Run cmake:
+ #
+ execute_process(COMMAND ${CMAKE_COMMAND} -G ${g} ..
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ WORKING_DIRECTORY ${dir}/Source/${g}
+ )
+
+ message(STATUS "result='${result}'")
+ message(STATUS "stdout='${stdout}'")
+ message(STATUS "stderr='${stderr}'")
+ message(STATUS "")
+endforeach()
+
+message(STATUS "CMake generators='${generators}'")
+message(STATUS "CMAKE_COMMAND='${CMAKE_COMMAND}'")
diff --git a/Tests/CMakeTestBadCommandLines/RunCMake.cmake b/Tests/CMakeTestBadCommandLines/RunCMake.cmake
new file mode 100644
index 0000000000..08549cc5e8
--- /dev/null
+++ b/Tests/CMakeTestBadCommandLines/RunCMake.cmake
@@ -0,0 +1,79 @@
+if(NOT DEFINED CMake_SOURCE_DIR)
+ message(FATAL_ERROR "CMake_SOURCE_DIR not defined")
+endif()
+
+if(NOT DEFINED dir)
+ message(FATAL_ERROR "dir not defined")
+endif()
+
+if(NOT DEFINED gen)
+ message(FATAL_ERROR "gen not defined")
+endif()
+
+message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+
+# First setup a source tree to run CMake on.
+#
+execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
+ ${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast
+ ${dir}/Source
+)
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
+ ${dir}/Build
+ )
+
+function(RunCMakeWithArgs)
+ message(STATUS "info: running cmake with ARGN='${ARGN}'")
+
+ execute_process(COMMAND ${CMAKE_COMMAND} ${ARGN}
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ WORKING_DIRECTORY ${dir}/Build
+ )
+
+ message(STATUS "result='${result}'")
+ message(STATUS "stdout='${stdout}'")
+ message(STATUS "stderr='${stderr}'")
+ message(STATUS "")
+endfunction()
+
+# Run cmake once with no errors to get a good build tree:
+#
+RunCMakeWithArgs(-G ${gen} ../Source)
+
+# Run cmake with args that produce some sort of problem to cover the error
+# cases in cmake.cxx...
+#
+# (These are not good examples of cmake command lines. Do not copy and
+# paste them elsewhere and expect them to work... See the cmake
+# documentation or other real examples of usage instead.)
+#
+RunCMakeWithArgs()
+RunCMakeWithArgs(-C)
+RunCMakeWithArgs(-C nosuchcachefile.txt)
+RunCMakeWithArgs(--check-stamp-file nostampfile)
+RunCMakeWithArgs(--check-stamp-list nostamplist)
+RunCMakeWithArgs(nosuchsubdir/CMakeCache.txt)
+RunCMakeWithArgs(nosuchsubdir/CMakeLists.txt)
+RunCMakeWithArgs(-D)
+RunCMakeWithArgs(--debug-output .)
+RunCMakeWithArgs(--debug-trycompile .)
+RunCMakeWithArgs(-E)
+RunCMakeWithArgs(-E create_symlink)
+RunCMakeWithArgs(-E echo_append)
+RunCMakeWithArgs(-E rename)
+RunCMakeWithArgs(-E touch_nocreate)
+RunCMakeWithArgs(-G)
+RunCMakeWithArgs(--graphviz= ../Source)
+RunCMakeWithArgs(--graphviz=g.dot .)
+RunCMakeWithArgs(-P)
+RunCMakeWithArgs(-P nosuchscriptfile.cmake)
+RunCMakeWithArgs(--trace .)
+RunCMakeWithArgs(-U)
+RunCMakeWithArgs(-U nosuchvariable .)
+RunCMakeWithArgs(-V)
+RunCMakeWithArgs(-V .)
+RunCMakeWithArgs(-Wno-dev .)
+RunCMakeWithArgs(-Wdev .)
diff --git a/Tests/CMakeTestMultipleConfigures/RunCMake.cmake b/Tests/CMakeTestMultipleConfigures/RunCMake.cmake
new file mode 100644
index 0000000000..96326646b5
--- /dev/null
+++ b/Tests/CMakeTestMultipleConfigures/RunCMake.cmake
@@ -0,0 +1,165 @@
+if(NOT DEFINED CMake_SOURCE_DIR)
+ message(FATAL_ERROR "CMake_SOURCE_DIR not defined")
+endif()
+
+if(NOT DEFINED dir)
+ message(FATAL_ERROR "dir not defined")
+endif()
+
+if(NOT DEFINED gen)
+ message(FATAL_ERROR "gen not defined")
+endif()
+
+# Call cmake once to get a baseline/reference output build tree: "Build".
+# Then call cmake N more times, each time making a copy of the entire
+# build tree after cmake is done configuring/generating. At the end,
+# analyze the diffs in the generated build trees. Expect no diffs.
+#
+message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+
+set(N 7)
+
+# First setup source and binary trees:
+#
+execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory
+ ${dir}/Source
+)
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory
+ ${dir}/Build
+)
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
+ ${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast
+ ${dir}/Source
+)
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
+ ${dir}/Build
+)
+
+# Patch SmallAndFast to build a .cxx executable too:
+#
+execute_process(COMMAND ${CMAKE_COMMAND} -E copy
+ ${dir}/Source/echoargs.c
+ ${dir}/Source/echoargs.cxx
+)
+file(APPEND "${dir}/Source/CMakeLists.txt" "\nadd_executable(echoargsCXX echoargs.cxx)\n")
+
+# Loop N times, saving a copy of the configured/generated build tree each time:
+#
+foreach(i RANGE 1 ${N})
+ # Equivalent sequence of shell commands:
+ #
+ message(STATUS "${i}: cd Build && cmake -G \"${gen}\" ../Source && cd .. && cp -r Build b${i}")
+
+ # Run cmake:
+ #
+ execute_process(COMMAND ${CMAKE_COMMAND} -G ${gen} ../Source
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ WORKING_DIRECTORY ${dir}/Build
+ )
+
+ message(STATUS "result='${result}'")
+ message(STATUS "stdout='${stdout}'")
+ message(STATUS "stderr='${stderr}'")
+ message(STATUS "")
+
+ # Save this iteration of the Build directory:
+ #
+ execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory
+ ${dir}/b${i}
+ )
+ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
+ ${dir}/Build
+ ${dir}/b${i}
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ )
+
+ message(STATUS "result='${result}'")
+ message(STATUS "stdout='${stdout}'")
+ message(STATUS "stderr='${stderr}'")
+ message(STATUS "")
+endforeach()
+
+
+# Function to analyze diffs between two directories.
+# Set DIFF_EXECUTABLE before calling if 'diff' is available.
+#
+function(analyze_directory_diffs d1 d2 diff_count_var)
+ set(diffs 0)
+
+ message(STATUS "Analyzing directory diffs between:")
+ message(STATUS " d1='${d1}'")
+ message(STATUS " d2='${d2}'")
+
+ if(NOT "${d1}" STREQUAL "" AND NOT "${d2}" STREQUAL "")
+ message(STATUS "info: analyzing directories")
+
+ file(GLOB_RECURSE files1 RELATIVE "${d1}" "${d1}/*")
+ file(GLOB_RECURSE files2 RELATIVE "${d2}" "${d2}/*")
+
+ if("${files1}" STREQUAL "${files2}")
+ message(STATUS "info: file lists the same")
+ #message(STATUS " files='${files1}'")
+
+ foreach(f ${files1})
+ execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files
+ ${d1}/${f}
+ ${d2}/${f}
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ )
+ if(result STREQUAL 0)
+ #message(STATUS "info: file '${f}' the same")
+ else()
+ math(EXPR diffs "${diffs} + 1")
+ message(STATUS "warning: file '${f}' differs from d1 to d2")
+ file(READ "${d1}/${f}" f1contents)
+ message(STATUS "contents of file '${d1}/${f}'
+[===[${f1contents}]===]")
+ file(READ "${d2}/${f}" f2contents)
+ message(STATUS "contents of file '${d2}/${f}'
+[===[${f2contents}]===]")
+ if(DIFF_EXECUTABLE)
+ message(STATUS "diff of files '${d1}/${f}' '${d2}/${f}'")
+ message(STATUS "[====[")
+ execute_process(COMMAND ${DIFF_EXECUTABLE} "${d1}/${f}" "${d2}/${f}")
+ message(STATUS "]====]")
+ endif()
+ endif()
+ endforeach()
+ else()
+ math(EXPR diffs "${diffs} + 1")
+ message(STATUS "warning: file *lists* differ - some files exist in d1/not-d2 or not-d1/d2...")
+ message(STATUS " files1='${files1}'")
+ message(STATUS " files2='${files2}'")
+ endif()
+ endif()
+
+ set(${diff_count_var} ${diffs} PARENT_SCOPE)
+endfunction()
+
+
+# Analyze diffs between b1:b2, b2:b3, b3:b4, b4:b5 ... bN-1:bN.
+# Expect no diffs.
+#
+find_program(DIFF_EXECUTABLE diff)
+set(total_diffs 0)
+
+foreach(i RANGE 2 ${N})
+ math(EXPR prev "${i} - 1")
+ set(count 0)
+ analyze_directory_diffs(${dir}/b${prev} ${dir}/b${i} count)
+ message(STATUS "diff count='${count}'")
+ message(STATUS "")
+ math(EXPR total_diffs "${total_diffs} + ${count}")
+endforeach()
+
+message(STATUS "CMAKE_COMMAND='${CMAKE_COMMAND}'")
+message(STATUS "total_diffs='${total_diffs}'")
diff --git a/Tests/CMakeTests/.gitattributes b/Tests/CMakeTests/.gitattributes
new file mode 100644
index 0000000000..c34e350e53
--- /dev/null
+++ b/Tests/CMakeTests/.gitattributes
@@ -0,0 +1 @@
+File-HASH-Input.txt crlf=input
diff --git a/Tests/CMakeTests/A/include/cmake_i_do_not_exist_in_the_system.h b/Tests/CMakeTests/A/include/cmake_i_do_not_exist_in_the_system.h
new file mode 100644
index 0000000000..2392aee71d
--- /dev/null
+++ b/Tests/CMakeTests/A/include/cmake_i_do_not_exist_in_the_system.h
@@ -0,0 +1 @@
+/* empty header file */
diff --git a/Tests/CMakeTests/CMakeHostSystemInformation-BadArg1.cmake b/Tests/CMakeTests/CMakeHostSystemInformation-BadArg1.cmake
new file mode 100644
index 0000000000..1655eb4069
--- /dev/null
+++ b/Tests/CMakeTests/CMakeHostSystemInformation-BadArg1.cmake
@@ -0,0 +1 @@
+cmake_host_system_information(HOSTNAME)
diff --git a/Tests/CMakeTests/CMakeHostSystemInformation-BadArg2.cmake b/Tests/CMakeTests/CMakeHostSystemInformation-BadArg2.cmake
new file mode 100644
index 0000000000..1f056d5f2a
--- /dev/null
+++ b/Tests/CMakeTests/CMakeHostSystemInformation-BadArg2.cmake
@@ -0,0 +1 @@
+cmake_host_system_information(RESULT FQDN HOSTNAME)
diff --git a/Tests/CMakeTests/CMakeHostSystemInformation-BadArg3.cmake b/Tests/CMakeTests/CMakeHostSystemInformation-BadArg3.cmake
new file mode 100644
index 0000000000..9c5a558c70
--- /dev/null
+++ b/Tests/CMakeTests/CMakeHostSystemInformation-BadArg3.cmake
@@ -0,0 +1 @@
+cmake_host_system_information(RESULT RESULT QUERY FOOBAR)
diff --git a/Tests/CMakeTests/CMakeHostSystemInformation-QueryList.cmake b/Tests/CMakeTests/CMakeHostSystemInformation-QueryList.cmake
new file mode 100644
index 0000000000..1c3156d23c
--- /dev/null
+++ b/Tests/CMakeTests/CMakeHostSystemInformation-QueryList.cmake
@@ -0,0 +1,5 @@
+cmake_host_system_information(RESULT RESULT
+ QUERY NUMBER_OF_LOGICAL_CORES NUMBER_OF_PHYSICAL_CORES
+)
+
+message("[${RESULT}]")
diff --git a/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in b/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in
new file mode 100644
index 0000000000..3294a2f0dc
--- /dev/null
+++ b/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in
@@ -0,0 +1,33 @@
+set(BadArg1-RESULT 1)
+set(BadArg1-STDERR "missing RESULT specification")
+set(BadArg2-RESULT 1)
+set(BadArg2-STDERR "missing QUERY specification")
+set(BadArg3-RESULT 1)
+set(BadArg3-STDERR "does not recognize <key> FOOBAR")
+set(QueryList-RESULT 0)
+set(QueryList-STDERR "\\[[0-9]+;[0-9]+\\]")
+
+function(try_and_print key)
+ cmake_host_system_information(RESULT RESULT QUERY ${key})
+ message(STATUS "[${key}] [${RESULT}]")
+endfunction()
+
+message("CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+
+try_and_print(NUMBER_OF_LOGICAL_CORES)
+try_and_print(NUMBER_OF_PHYSICAL_CORES)
+try_and_print(HOSTNAME)
+try_and_print(FQDN)
+try_and_print(TOTAL_VIRTUAL_MEMORY)
+try_and_print(AVAILABLE_VIRTUAL_MEMORY)
+try_and_print(TOTAL_PHYSICAL_MEMORY)
+try_and_print(AVAILABLE_PHYSICAL_MEMORY)
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
+
+check_cmake_test(CMakeHostSystemInformation
+ BadArg1
+ BadArg2
+ BadArg3
+ QueryList
+)
diff --git a/Tests/CMakeTests/CMakeLists.txt b/Tests/CMakeTests/CMakeLists.txt
new file mode 100644
index 0000000000..ce36830417
--- /dev/null
+++ b/Tests/CMakeTests/CMakeLists.txt
@@ -0,0 +1,84 @@
+set(CMAKE_EXECUTABLE "${CMake_BIN_DIR}/cmake")
+
+
+macro(AddCMakeTest TestName PreArgs)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${TestName}Test.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/${TestName}Test.cmake" @ONLY)
+ add_test(NAME CMake.${TestName}
+ COMMAND ${CMAKE_EXECUTABLE} ${PreArgs}
+ -P "${CMAKE_CURRENT_BINARY_DIR}/${TestName}Test.cmake" ${ARGN})
+endmacro()
+
+
+AddCMakeTest(List "")
+AddCMakeTest(VariableWatch "")
+AddCMakeTest(Include "")
+AddCMakeTest(FindBase "")
+AddCMakeTest(Toolchain "")
+AddCMakeTest(GetFilenameComponentRealpath "")
+AddCMakeTest(Version "")
+AddCMakeTest(Message "")
+AddCMakeTest(File "")
+AddCMakeTest(ConfigureFile "")
+AddCMakeTest(SeparateArguments "")
+AddCMakeTest(ImplicitLinkInfo "")
+AddCMakeTest(ModuleNotices "")
+AddCMakeTest(GetProperty "")
+AddCMakeTest(If "")
+AddCMakeTest(String "")
+AddCMakeTest(Math "")
+AddCMakeTest(CMakeMinimumRequired "")
+AddCMakeTest(CompilerIdVendor "")
+AddCMakeTest(ProcessorCount "-DKWSYS_TEST_EXE=$<TARGET_FILE:cmsysTestsCxx>")
+AddCMakeTest(PushCheckState "")
+AddCMakeTest(While "")
+AddCMakeTest(CMakeHostSystemInformation "")
+
+AddCMakeTest(FileDownload "")
+set_property(TEST CMake.FileDownload PROPERTY
+ PASS_REGULAR_EXPRESSION "file already exists with expected MD5 sum"
+ )
+AddCMakeTest(FileDownloadBadHash "")
+set_property(TEST CMake.FileDownloadBadHash PROPERTY
+ WILL_FAIL TRUE
+ )
+
+AddCMakeTest(FileUpload "")
+
+if(HAVE_ELF_H)
+ AddCMakeTest(ELF "")
+endif()
+
+set(EndStuff_PreArgs
+ "-Ddir:STRING=${CMAKE_CURRENT_BINARY_DIR}/EndStuffTest"
+ )
+AddCMakeTest(EndStuff "${EndStuff_PreArgs}")
+
+set(GetPrerequisites_PreArgs
+ "-DCTEST_CONFIGURATION_TYPE:STRING=\\\${CTEST_CONFIGURATION_TYPE}"
+ )
+AddCMakeTest(GetPrerequisites "${GetPrerequisites_PreArgs}")
+
+if(GIT_EXECUTABLE)
+ set(PolicyCheck_PreArgs
+ "-DCMake_BINARY_DIR:PATH=${CMake_BINARY_DIR}"
+ "-DCMake_SOURCE_DIR:PATH=${CMake_SOURCE_DIR}"
+ "-DGIT_EXECUTABLE:STRING=${GIT_EXECUTABLE}"
+ )
+ AddCMakeTest(PolicyCheck "${PolicyCheck_PreArgs}")
+endif()
+
+# Run CheckSourceTree as the very last test in the CMake/CTest/CPack test
+# suite. It detects if any changes have been made to the CMake source tree
+# by any previous configure, build or test steps.
+#
+if(GIT_EXECUTABLE)
+ string(REPLACE "\\" "/" ENV_HOME "$ENV{HOME}")
+ set(CheckSourceTree_PreArgs
+ "-DCMake_BINARY_DIR:PATH=${CMake_BINARY_DIR}"
+ "-DCMake_SOURCE_DIR:PATH=${CMake_SOURCE_DIR}"
+ "-DGIT_EXECUTABLE:STRING=${GIT_EXECUTABLE}"
+ "-DHOME:STRING=${ENV_HOME}"
+ )
+ AddCMakeTest(CheckSourceTree "${CheckSourceTree_PreArgs}")
+endif()
diff --git a/Tests/CMakeTests/CMakeMinimumRequiredTest.cmake.in b/Tests/CMakeTests/CMakeMinimumRequiredTest.cmake.in
new file mode 100644
index 0000000000..b83a779bbe
--- /dev/null
+++ b/Tests/CMakeTests/CMakeMinimumRequiredTest.cmake.in
@@ -0,0 +1,18 @@
+# Execute each test listed in:
+#
+set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/CMakeMinimumRequiredTestScript.cmake")
+set(number_of_tests_expected 8)
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/ExecuteScriptTests.cmake")
+execute_all_script_tests(${scriptname} number_of_tests_executed)
+
+# And verify that number_of_tests_executed is at least as many as we know
+# about as of this writing...
+#
+message(STATUS "scriptname='${scriptname}'")
+message(STATUS "number_of_tests_executed='${number_of_tests_executed}'")
+message(STATUS "number_of_tests_expected='${number_of_tests_expected}'")
+
+if(number_of_tests_executed LESS number_of_tests_expected)
+ message(FATAL_ERROR "error: some test cases were skipped")
+endif()
diff --git a/Tests/CMakeTests/CMakeMinimumRequiredTestScript.cmake b/Tests/CMakeTests/CMakeMinimumRequiredTestScript.cmake
new file mode 100644
index 0000000000..d434d2901c
--- /dev/null
+++ b/Tests/CMakeTests/CMakeMinimumRequiredTestScript.cmake
@@ -0,0 +1,31 @@
+message(STATUS "testname='${testname}'")
+
+if(testname STREQUAL empty) # pass
+ cmake_minimum_required()
+
+elseif(testname STREQUAL bogus) # fail
+ cmake_minimum_required(BOGUS)
+
+elseif(testname STREQUAL no_version) # fail
+ cmake_minimum_required(VERSION)
+
+elseif(testname STREQUAL no_version_before_fatal_error) # fail
+ cmake_minimum_required(VERSION FATAL_ERROR)
+
+elseif(testname STREQUAL bad_version) # fail
+ cmake_minimum_required(VERSION 2.blah.blah)
+
+elseif(testname STREQUAL worse_version) # fail
+ cmake_minimum_required(VERSION blah.blah.blah)
+
+elseif(testname STREQUAL future_version) # fail
+ math(EXPR major "${CMAKE_MAJOR_VERSION} + 1")
+ cmake_minimum_required(VERSION ${major}.2.1)
+
+elseif(testname STREQUAL unknown_arg) # fail
+ cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.0.0 SILLY)
+
+else() # fail
+ message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'")
+
+endif()
diff --git a/Tests/CMakeTests/CheckCMakeTest.cmake b/Tests/CMakeTests/CheckCMakeTest.cmake
new file mode 100644
index 0000000000..1565394bc2
--- /dev/null
+++ b/Tests/CMakeTests/CheckCMakeTest.cmake
@@ -0,0 +1,35 @@
+get_filename_component(CMakeTests_SRC_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
+
+function(check_cmake_test_single prefix test testfile)
+ message(STATUS "Test ${prefix}-${test}...")
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -P "${testfile}"
+ WORKING_DIRECTORY "${CMakeTests_BIN_DIR}"
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ RESULT_VARIABLE result
+ )
+ string(REPLACE "\n" "\n out> " out " out> ${stdout}")
+ string(REPLACE "\n" "\n err> " err " err> ${stderr}")
+ if(NOT "${result}" STREQUAL "${${test}-RESULT}")
+ message(FATAL_ERROR
+ "Test ${test} result is [${result}], not [${${test}-RESULT}].\n"
+ "Test ${test} output:\n"
+ "${out}\n"
+ "${err}")
+ endif()
+ if(${test}-STDERR AND NOT "${err}" MATCHES "${${test}-STDERR}")
+ message(FATAL_ERROR
+ "Test ${test} stderr does not match\n ${${test}-STDERR}\n"
+ "Test ${test} output:\n"
+ "${out}\n"
+ "${err}")
+ endif()
+endfunction()
+
+function(check_cmake_test prefix)
+ get_filename_component(CMakeTests_BIN_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
+ foreach(test ${ARGN})
+ check_cmake_test_single("${prefix}" "${test}" "${CMakeTests_SRC_DIR}/${prefix}-${test}.cmake")
+ endforeach()
+endfunction()
diff --git a/Tests/CMakeTests/CheckSourceTreeTest.cmake.in b/Tests/CMakeTests/CheckSourceTreeTest.cmake.in
new file mode 100644
index 0000000000..59b28904d7
--- /dev/null
+++ b/Tests/CMakeTests/CheckSourceTreeTest.cmake.in
@@ -0,0 +1,357 @@
+# Check the CMake source tree and report anything suspicious...
+#
+message("=============================================================================")
+message("CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+message("")
+message("CMake_BINARY_DIR='${CMake_BINARY_DIR}'")
+message("CMake_SOURCE_DIR='${CMake_SOURCE_DIR}'")
+message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
+message("HOME='${HOME}'")
+message("ENV{DASHBOARD_TEST_FROM_CTEST}='$ENV{DASHBOARD_TEST_FROM_CTEST}'")
+message("")
+string(REPLACE "\\" "\\\\" HOME "${HOME}")
+
+
+# Is the build directory the same as or underneath the source directory?
+# (i.e. - is it an "in source" build?)
+#
+set(in_source_build 0)
+
+if(CMake_SOURCE_DIR STREQUAL "${CMake_BINARY_DIR}")
+ message("build dir *is* source dir")
+ set(in_source_build 1)
+else()
+ string(LENGTH "${CMake_SOURCE_DIR}" src_len)
+ string(LENGTH "${CMake_BINARY_DIR}" bin_len)
+
+ if(bin_len GREATER src_len)
+ math(EXPR substr_len "${src_len}+1")
+ string(SUBSTRING "${CMake_BINARY_DIR}" 0 ${substr_len} bin_dir)
+ if(bin_dir STREQUAL "${CMake_SOURCE_DIR}/")
+ message("build dir is under source dir")
+ set(in_source_build 1)
+ endif()
+ endif()
+endif()
+
+message("src_len='${src_len}'")
+message("bin_len='${bin_len}'")
+message("substr_len='${substr_len}'")
+message("bin_dir='${bin_dir}'")
+message("in_source_build='${in_source_build}'")
+message("")
+
+
+# If this does not appear to be a git checkout, just pass the test here
+# and now. (Do not let the test fail if it is run in a tree *exported* from a
+# repository or unpacked from a .zip file source installer...)
+#
+set(is_git_checkout 0)
+if(EXISTS "${CMake_SOURCE_DIR}/.git")
+ set(is_git_checkout 1)
+endif()
+
+message("is_git_checkout='${is_git_checkout}'")
+message("")
+
+if(NOT is_git_checkout)
+ message("source tree is not a git checkout... test passes by early return...")
+ return()
+endif()
+
+# This test looks for the following types of changes in the source tree:
+#
+set(additions 0)
+set(conflicts 0)
+set(modifications 0)
+set(nonadditions 0)
+
+# ov == output variable... conditionally filled in by either git below:
+#
+set(cmd "")
+set(ov "")
+set(ev "")
+set(rv "")
+
+# If no GIT_EXECUTABLE, see if we can figure out which git was used
+# for the ctest_update step on this dashboard...
+#
+if(is_git_checkout AND NOT GIT_EXECUTABLE)
+ set(ctest_ini_file "")
+ set(exe "")
+
+ # Use the old name:
+ if(EXISTS "${CMake_BINARY_DIR}/DartConfiguration.tcl")
+ set(ctest_ini_file "${CMake_BINARY_DIR}/DartConfiguration.tcl")
+ endif()
+
+ # But if it exists, prefer the new name:
+ if(EXISTS "${CMake_BINARY_DIR}/CTestConfiguration.ini")
+ set(ctest_ini_file "${CMake_BINARY_DIR}/CTestConfiguration.ini")
+ endif()
+
+ # If there is a ctest ini file, read the update command or git command
+ # from it:
+ #
+ if(ctest_ini_file)
+ file(STRINGS "${ctest_ini_file}" line REGEX "^GITCommand: (.*)$")
+ string(REGEX REPLACE "^GITCommand: (.*)$" "\\1" line "${line}")
+ if("${line}" MATCHES "^\"")
+ string(REGEX REPLACE "^\"([^\"]+)\" *.*$" "\\1" line "${line}")
+ else()
+ string(REGEX REPLACE "^([^ ]+) *.*$" "\\1" line "${line}")
+ endif()
+ set(exe "${line}")
+ if("${exe}" STREQUAL "GITCOMMAND-NOTFOUND")
+ set(exe "")
+ endif()
+ if(exe)
+ message("info: GIT_EXECUTABLE set by 'GITCommand:' from '${ctest_ini_file}'")
+ endif()
+
+ if(NOT exe)
+ file(STRINGS "${ctest_ini_file}" line REGEX "^UpdateCommand: (.*)$")
+ string(REGEX REPLACE "^UpdateCommand: (.*)$" "\\1" line "${line}")
+ if("${line}" MATCHES "^\"")
+ string(REGEX REPLACE "^\"([^\"]+)\" *.*$" "\\1" line "${line}")
+ else()
+ string(REGEX REPLACE "^([^ ]+) *.*$" "\\1" line "${line}")
+ endif()
+ set(exe "${line}")
+ if("${exe}" STREQUAL "GITCOMMAND-NOTFOUND")
+ set(exe "")
+ endif()
+ if(exe)
+ message("info: GIT_EXECUTABLE set by 'UpdateCommand:' from '${ctest_ini_file}'")
+ endif()
+ endif()
+ else()
+ message("info: no DartConfiguration.tcl or CTestConfiguration.ini file...")
+ endif()
+
+ # If we have still not grokked the exe, look in the Update.xml file to see
+ # if we can parse it from there...
+ #
+ if(NOT exe)
+ file(GLOB_RECURSE update_xml_file "${CMake_BINARY_DIR}/Testing/Update.xml")
+ if(update_xml_file)
+ file(STRINGS "${update_xml_file}" line
+ REGEX "^.*<UpdateCommand>(.*)</UpdateCommand>$" LIMIT_COUNT 1)
+ string(REPLACE "&quot\;" "\"" line "${line}")
+ string(REGEX REPLACE "^.*<UpdateCommand>(.*)</UpdateCommand>$" "\\1" line "${line}")
+ if("${line}" MATCHES "^\"")
+ string(REGEX REPLACE "^\"([^\"]+)\" *.*$" "\\1" line "${line}")
+ else()
+ string(REGEX REPLACE "^([^ ]+) *.*$" "\\1" line "${line}")
+ endif()
+ if(line)
+ set(exe "${line}")
+ endif()
+ if(exe)
+ message("info: GIT_EXECUTABLE set by '<UpdateCommand>' from '${update_xml_file}'")
+ endif()
+ else()
+ message("info: no Update.xml file...")
+ endif()
+ endif()
+
+ if(exe)
+ set(GIT_EXECUTABLE "${exe}")
+ message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
+ message("")
+
+ if(NOT EXISTS "${GIT_EXECUTABLE}")
+ message(FATAL_ERROR "GIT_EXECUTABLE does not exist...")
+ endif()
+ else()
+ message(FATAL_ERROR "could not determine GIT_EXECUTABLE...")
+ endif()
+endif()
+
+
+if(is_git_checkout AND GIT_EXECUTABLE)
+ # Check with "git status" if there are any local modifications to the
+ # CMake source tree:
+ #
+ message("=============================================================================")
+ message("This is a git checkout, using git to verify source tree....")
+ message("")
+
+ execute_process(COMMAND ${GIT_EXECUTABLE} --version
+ WORKING_DIRECTORY ${CMake_SOURCE_DIR}
+ OUTPUT_VARIABLE version_output
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message("=== output of 'git --version' ===")
+ message("${version_output}")
+ message("=== end output ===")
+ message("")
+
+ execute_process(COMMAND ${GIT_EXECUTABLE} branch -a
+ WORKING_DIRECTORY ${CMake_SOURCE_DIR}
+ OUTPUT_VARIABLE git_branch_output
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message("=== output of 'git branch -a' ===")
+ message("${git_branch_output}")
+ message("=== end output ===")
+ message("")
+
+ execute_process(COMMAND ${GIT_EXECUTABLE} log -1
+ WORKING_DIRECTORY ${CMake_SOURCE_DIR}
+ OUTPUT_VARIABLE git_log_output
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message("=== output of 'git log -1' ===")
+ message("${git_log_output}")
+ message("=== end output ===")
+ message("")
+
+ message("Copy/paste this command to reproduce:")
+ message("cd \"${CMake_SOURCE_DIR}\" && \"${GIT_EXECUTABLE}\" status")
+ message("")
+
+ set(cmd ${GIT_EXECUTABLE} status)
+endif()
+
+
+if(cmd)
+ # Use the HOME value passed in to the script for calling git so it can
+ # find its user/global config settings...
+ #
+ set(original_ENV_HOME "$ENV{HOME}")
+ set(ENV{HOME} "${HOME}")
+
+ execute_process(COMMAND ${cmd}
+ WORKING_DIRECTORY ${CMake_SOURCE_DIR}
+ OUTPUT_VARIABLE ov
+ ERROR_VARIABLE ev
+ RESULT_VARIABLE rv)
+
+ set(ENV{HOME} "${original_ENV_HOME}")
+
+ message("Results of running ${cmd}")
+ message("rv='${rv}'")
+ message("ov='${ov}'")
+ message("ev='${ev}'")
+ message("")
+
+ if(NOT rv STREQUAL 0)
+ if(is_git_checkout AND (rv STREQUAL "1"))
+ # Many builds of git return "1" from a "nothing is changed" git status call...
+ # Do not fail with an error for rv==1 with git...
+ else()
+ message(FATAL_ERROR "error: ${cmd} attempt failed... (see output above)")
+ endif()
+ endif()
+else()
+ message(FATAL_ERROR "error: no COMMAND to run to analyze source tree...")
+endif()
+
+
+# Analyze output:
+#
+if(NOT ov STREQUAL "")
+ string(REPLACE ";" "\\\\;" lines "${ov}")
+ string(REPLACE "\n" "E;" lines "${lines}")
+
+ foreach(line ${lines})
+ message("'${line}'")
+
+ # But do not consider files that exist just because some user poked around
+ # the file system with Windows Explorer or with the Finder from a Mac...
+ # ('Thumbs.db' and '.DS_Store' files...)
+ #
+ set(consider 1)
+ set(ignore_files_regex "^(. |.*(/|\\\\))(\\.DS_Store|Thumbs.db)E$")
+ if(line MATCHES "${ignore_files_regex}")
+ message(" line matches '${ignore_files_regex}' -- not considered")
+ set(consider 0)
+ endif()
+
+ if(consider)
+ if(is_git_checkout)
+ if(line MATCHES "^#[ \t]*modified:")
+ message(" locally modified file detected...")
+ set(modifications 1)
+ endif()
+
+ if(line MATCHES "^# Untracked")
+ message(" locally non-added file/directory detected...")
+ set(nonadditions 1)
+ endif()
+ endif()
+ endif()
+ endforeach()
+endif()
+
+
+message("=============================================================================")
+message("additions='${additions}'")
+message("conflicts='${conflicts}'")
+message("modifications='${modifications}'")
+message("nonadditions='${nonadditions}'")
+message("")
+
+
+# Decide if the test passes or fails:
+#
+message("=============================================================================")
+
+if("$ENV{DASHBOARD_TEST_FROM_CTEST}" STREQUAL "")
+
+ # developers are allowed to have local additions and modifications...
+ set(is_dashboard 0)
+ message("interactive test run")
+ message("")
+
+else()
+
+ set(is_dashboard 1)
+ message("dashboard test run")
+ message("")
+
+ # but dashboard machines are not allowed to have local additions or modifications...
+ if(additions)
+ message(FATAL_ERROR "test fails: local source tree additions")
+ endif()
+
+ if(modifications)
+ message(FATAL_ERROR "test fails: local source tree modifications")
+ endif()
+
+ #
+ # It's a dashboard run if ctest was run with '-D ExperimentalTest' or some
+ # other -D arg on its command line or if ctest is running a -S script to run
+ # a dashboard... Running ctest like that sets the DASHBOARD_TEST_FROM_CTEST
+ # env var.
+ #
+
+endif()
+
+
+# ...and nobody is allowed to have local non-additions or conflicts...
+# Not even developers.
+#
+if(nonadditions)
+ if(in_source_build AND is_dashboard)
+ message("
+warning: test results confounded because this is an 'in-source' build - cannot
+distinguish between non-added files that are in-source build products and
+non-added source files that somebody forgot to 'git add'... - this is only ok
+if this is intentionally an in-source dashboard build... Developers should
+use out-of-source builds to verify a clean source tree with this test...
+
+Allowing test to pass despite the warning message...
+")
+ else()
+ message(FATAL_ERROR "test fails: local source tree non-additions: use git add before committing, or remove the files from the source tree")
+ endif()
+endif()
+
+if(conflicts)
+ message(FATAL_ERROR "test fails: local source tree conflicts: resolve before committing")
+endif()
+
+
+# Still here? Good then...
+#
+message("test passes")
+message("")
diff --git a/Tests/CMakeTests/CompilerIdVendorTest.cmake.in b/Tests/CMakeTests/CompilerIdVendorTest.cmake.in
new file mode 100644
index 0000000000..68f646212b
--- /dev/null
+++ b/Tests/CMakeTests/CompilerIdVendorTest.cmake.in
@@ -0,0 +1,31 @@
+# This is not supposed to be included by user code, but we need to
+# test it.
+include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
+
+set(MY_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@/CompilerIdVendor")
+file(REMOVE_RECURSE ${MY_BINARY_DIR})
+file(MAKE_DIRECTORY ${MY_BINARY_DIR})
+
+set(CMAKE_MyLang_COMPILER ${CMAKE_COMMAND})
+set(CMAKE_MyLang_COMPILER_ID_ARG1)
+set(CMAKE_MyLang_COMPILER_ID_FLAGS_LIST)
+set(CMAKE_MyLang_COMPILER_ID_DIR ${MY_BINARY_DIR})
+
+file(WRITE "${MY_BINARY_DIR}/BogusVendor.cmake" "message(\"This is a BogusVendor compiler\")")
+list(APPEND CMAKE_MyLang_COMPILER_ID_VENDORS BogusVendor)
+set(CMAKE_MyLang_COMPILER_ID_VENDOR_FLAGS_BogusVendor -P BogusVendor.cmake)
+set(CMAKE_MyLang_COMPILER_ID_VENDOR_REGEX_BogusVendor ThisDoesNotMatch_BogusVendor)
+
+file(WRITE "${MY_BINARY_DIR}/MyVendor.cmake" "message(\"This is a MyVendor compiler\")")
+list(APPEND CMAKE_MyLang_COMPILER_ID_VENDORS MyVendor)
+set(CMAKE_MyLang_COMPILER_ID_VENDOR_FLAGS_MyVendor -P MyVendor.cmake)
+set(CMAKE_MyLang_COMPILER_ID_VENDOR_REGEX_MyVendor MyVendor)
+
+set(CMAKE_BINARY_DIR ${MY_BINARY_DIR})
+cmake_determine_compiler_id_vendor(MyLang)
+
+if("${CMAKE_MyLang_COMPILER_ID}" STREQUAL "MyVendor")
+ message(STATUS "Found MyVendor compiler id!")
+else()
+ message(FATAL_ERROR "Did not find MyVendor compiler id: [${CMAKE_MyLang_COMPILER_ID}]")
+endif()
diff --git a/Tests/CMakeTests/ConfigureFile-BadArg.cmake b/Tests/CMakeTests/ConfigureFile-BadArg.cmake
new file mode 100644
index 0000000000..769fae1ab5
--- /dev/null
+++ b/Tests/CMakeTests/ConfigureFile-BadArg.cmake
@@ -0,0 +1 @@
+configure_file(.)
diff --git a/Tests/CMakeTests/ConfigureFile-DirInput.cmake b/Tests/CMakeTests/ConfigureFile-DirInput.cmake
new file mode 100644
index 0000000000..920ea280c7
--- /dev/null
+++ b/Tests/CMakeTests/ConfigureFile-DirInput.cmake
@@ -0,0 +1 @@
+configure_file(. .)
diff --git a/Tests/CMakeTests/ConfigureFile-DirOutput.cmake b/Tests/CMakeTests/ConfigureFile-DirOutput.cmake
new file mode 100644
index 0000000000..d682a2d855
--- /dev/null
+++ b/Tests/CMakeTests/ConfigureFile-DirOutput.cmake
@@ -0,0 +1,5 @@
+file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureFile-DirOutput.txt "DirOutput test file\n")
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ConfigureFile-DirOutput)
+configure_file(ConfigureFile-DirOutput.txt ConfigureFile-DirOutput)
+file(READ ${CMAKE_CURRENT_BINARY_DIR}/ConfigureFile-DirOutput/ConfigureFile-DirOutput.txt out)
+message("${out}")
diff --git a/Tests/CMakeTests/ConfigureFile-NewLineStyle-COPYONLY.cmake b/Tests/CMakeTests/ConfigureFile-NewLineStyle-COPYONLY.cmake
new file mode 100644
index 0000000000..3b09eb0c3f
--- /dev/null
+++ b/Tests/CMakeTests/ConfigureFile-NewLineStyle-COPYONLY.cmake
@@ -0,0 +1,3 @@
+set(file_name ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureFile-NewLineStyle.txt)
+file(WRITE ${file_name} "Data\n")
+configure_file(${file_name} ${file_name}.out COPYONLY NEWLINE_STYLE DOS)
diff --git a/Tests/CMakeTests/ConfigureFile-NewLineStyle-NoArg.cmake b/Tests/CMakeTests/ConfigureFile-NewLineStyle-NoArg.cmake
new file mode 100644
index 0000000000..133a67a8ae
--- /dev/null
+++ b/Tests/CMakeTests/ConfigureFile-NewLineStyle-NoArg.cmake
@@ -0,0 +1,3 @@
+set(file_name ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureFile-NewLineStyle.txt)
+file(WRITE ${file_name} "Data\n")
+configure_file(${file_name} ${file_name}.out NEWLINE_STYLE)
diff --git a/Tests/CMakeTests/ConfigureFile-NewLineStyle-ValidArg.cmake b/Tests/CMakeTests/ConfigureFile-NewLineStyle-ValidArg.cmake
new file mode 100644
index 0000000000..b7e619ca21
--- /dev/null
+++ b/Tests/CMakeTests/ConfigureFile-NewLineStyle-ValidArg.cmake
@@ -0,0 +1,17 @@
+set(file_name ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureFile-NewLineStyle.txt)
+
+function(test_eol style in out)
+ file(WRITE ${file_name} "${in}")
+ configure_file(${file_name} ${file_name}.out NEWLINE_STYLE ${style})
+ file(READ ${file_name}.out new HEX)
+ if(NOT "${new}" STREQUAL "${out}")
+ message(FATAL_ERROR "No ${style} line endings")
+ endif()
+endfunction()
+
+test_eol(DOS "a\n" "610d0a")
+test_eol(WIN32 "b\n" "620d0a")
+test_eol(CRLF "c\n" "630d0a")
+
+test_eol(UNIX "d\n" "640a")
+test_eol(LF "e\n" "650a")
diff --git a/Tests/CMakeTests/ConfigureFile-NewLineStyle-WrongArg.cmake b/Tests/CMakeTests/ConfigureFile-NewLineStyle-WrongArg.cmake
new file mode 100644
index 0000000000..e8887c127e
--- /dev/null
+++ b/Tests/CMakeTests/ConfigureFile-NewLineStyle-WrongArg.cmake
@@ -0,0 +1,3 @@
+set(file_name ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureFile-NewLineStyle.txt)
+file(WRITE ${file_name} "Data\n")
+configure_file(${file_name} ${file_name}.out NEWLINE_STYLE FOO)
diff --git a/Tests/CMakeTests/ConfigureFile-Relative.cmake b/Tests/CMakeTests/ConfigureFile-Relative.cmake
new file mode 100644
index 0000000000..532580a218
--- /dev/null
+++ b/Tests/CMakeTests/ConfigureFile-Relative.cmake
@@ -0,0 +1,4 @@
+file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureFile-Relative-In.txt "Relative test file\n")
+configure_file(ConfigureFile-Relative-In.txt ConfigureFile-Relative-Out.txt)
+file(READ ${CMAKE_CURRENT_BINARY_DIR}/ConfigureFile-Relative-Out.txt out)
+message("${out}")
diff --git a/Tests/CMakeTests/ConfigureFileTest.cmake.in b/Tests/CMakeTests/ConfigureFileTest.cmake.in
new file mode 100644
index 0000000000..6cc61d90ce
--- /dev/null
+++ b/Tests/CMakeTests/ConfigureFileTest.cmake.in
@@ -0,0 +1,28 @@
+set(DirInput-RESULT 1)
+set(DirInput-STDERR "is a directory")
+set(DirOutput-RESULT 0)
+set(DirOutput-STDERR "DirOutput test file")
+set(Relative-RESULT 0)
+set(Relative-STDERR "Relative test file")
+set(BadArg-RESULT 1)
+set(BadArg-STDERR "called with incorrect number of arguments")
+set(NewLineStyle-NoArg-RESULT 1)
+set(NewLineStyle-NoArg-STDERR "NEWLINE_STYLE must set a style:")
+set(NewLineStyle-WrongArg-RESULT 1)
+set(NewLineStyle-WrongArg-STDERR "NEWLINE_STYLE sets an unknown style")
+set(NewLineStyle-ValidArg-RESULT 0)
+set(NewLineStyle-ValidArg-STDERR )
+set(NewLineStyle-COPYONLY-RESULT 1)
+set(NewLineStyle-COPYONLY-STDERR "COPYONLY could not be used in combination")
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
+check_cmake_test(ConfigureFile
+ DirInput
+ DirOutput
+ Relative
+ BadArg
+ NewLineStyle-NoArg
+ NewLineStyle-WrongArg
+ NewLineStyle-ValidArg
+ NewLineStyle-COPYONLY
+ )
diff --git a/Tests/CMakeTests/DummyToolchain.cmake b/Tests/CMakeTests/DummyToolchain.cmake
new file mode 100644
index 0000000000..6a602015b5
--- /dev/null
+++ b/Tests/CMakeTests/DummyToolchain.cmake
@@ -0,0 +1,8 @@
+set(CMAKE_SYSTEM_NAME Dumdidum)
+set(CMAKE_SYSTEM_VERSION "1.0")
+
+set(CMAKE_C_COMPILER /opt/foo/bin/arm-elf-gcc)
+set(CMAKE_C_OUTPUT_EXTENSION ".foo")
+
+set(CMAKE_CXX_COMPILER /opt/bar/bin/cl.exe)
+set(CMAKE_CXX_OUTPUT_EXTENSION ".bar")
diff --git a/Tests/CMakeTests/ELF/elf32lsb.bin b/Tests/CMakeTests/ELF/elf32lsb.bin
new file mode 100644
index 0000000000..803ac43f35
--- /dev/null
+++ b/Tests/CMakeTests/ELF/elf32lsb.bin
Binary files differ
diff --git a/Tests/CMakeTests/ELF/elf32msb.bin b/Tests/CMakeTests/ELF/elf32msb.bin
new file mode 100644
index 0000000000..d04aaf76c1
--- /dev/null
+++ b/Tests/CMakeTests/ELF/elf32msb.bin
Binary files differ
diff --git a/Tests/CMakeTests/ELF/elf64lsb.bin b/Tests/CMakeTests/ELF/elf64lsb.bin
new file mode 100644
index 0000000000..a21e3eaa65
--- /dev/null
+++ b/Tests/CMakeTests/ELF/elf64lsb.bin
Binary files differ
diff --git a/Tests/CMakeTests/ELF/elf64msb.bin b/Tests/CMakeTests/ELF/elf64msb.bin
new file mode 100644
index 0000000000..bbe2551890
--- /dev/null
+++ b/Tests/CMakeTests/ELF/elf64msb.bin
Binary files differ
diff --git a/Tests/CMakeTests/ELFTest.cmake.in b/Tests/CMakeTests/ELFTest.cmake.in
new file mode 100644
index 0000000000..0271abb1f6
--- /dev/null
+++ b/Tests/CMakeTests/ELFTest.cmake.in
@@ -0,0 +1,48 @@
+set(names
+ elf32lsb.bin
+ elf32msb.bin
+ elf64lsb.bin
+ elf64msb.bin
+ )
+
+# Prepare binaries on which to operate.
+set(in "@CMAKE_CURRENT_SOURCE_DIR@/ELF")
+set(out "@CMAKE_CURRENT_BINARY_DIR@/ELF-Out")
+file(REMOVE_RECURSE "${out}")
+file(MAKE_DIRECTORY "${out}")
+foreach(f ${names})
+ file(COPY ${in}/${f} DESTINATION ${out})
+ list(APPEND files "${out}/${f}")
+endforeach()
+
+foreach(f ${files})
+ # Check for the initial RPATH.
+ file(RPATH_CHECK FILE "${f}" RPATH "/sample/rpath")
+ if(NOT EXISTS "${f}")
+ message(FATAL_ERROR "RPATH_CHECK removed ${f}")
+ endif()
+
+ # Change the RPATH.
+ file(RPATH_CHANGE FILE "${f}"
+ OLD_RPATH "/sample/rpath"
+ NEW_RPATH "/rpath/sample")
+ set(rpath)
+ file(STRINGS "${f}" rpath REGEX "/rpath/sample" LIMIT_COUNT 1)
+ if(NOT rpath)
+ message(FATAL_ERROR "RPATH not changed in ${f}")
+ endif()
+
+ # Remove the RPATH.
+ file(RPATH_REMOVE FILE "${f}")
+ set(rpath)
+ file(STRINGS "${f}" rpath REGEX "/rpath/sample" LIMIT_COUNT 1)
+ if(rpath)
+ message(FATAL_ERROR "RPATH not removed from ${f}")
+ endif()
+
+ # Check again...this should remove the file.
+ file(RPATH_CHECK FILE "${f}" RPATH "/sample/rpath")
+ if(EXISTS "${f}")
+ message(FATAL_ERROR "RPATH_CHECK did not remove ${f}")
+ endif()
+endforeach()
diff --git a/Tests/CMakeTests/EndStuffTest.cmake.in b/Tests/CMakeTests/EndStuffTest.cmake.in
new file mode 100644
index 0000000000..de5dd5073d
--- /dev/null
+++ b/Tests/CMakeTests/EndStuffTest.cmake.in
@@ -0,0 +1,18 @@
+# Execute each test listed in:
+#
+set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/EndStuffTestScript.cmake")
+set(number_of_tests_expected 9)
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/ExecuteScriptTests.cmake")
+execute_all_script_tests(${scriptname} number_of_tests_executed)
+
+# And verify that number_of_tests_executed is at least as many as we know
+# about as of this writing...
+#
+message(STATUS "scriptname='${scriptname}'")
+message(STATUS "number_of_tests_executed='${number_of_tests_executed}'")
+message(STATUS "number_of_tests_expected='${number_of_tests_expected}'")
+
+if(number_of_tests_executed LESS number_of_tests_expected)
+ message(FATAL_ERROR "error: some test cases were skipped")
+endif()
diff --git a/Tests/CMakeTests/EndStuffTestScript.cmake b/Tests/CMakeTests/EndStuffTestScript.cmake
new file mode 100644
index 0000000000..9f40818012
--- /dev/null
+++ b/Tests/CMakeTests/EndStuffTestScript.cmake
@@ -0,0 +1,70 @@
+message(STATUS "testname='${testname}'")
+
+if(testname STREQUAL bad_else) # fail
+ file(WRITE "${dir}/${testname}.cmake"
+"else()
+")
+ execute_process(COMMAND ${CMAKE_COMMAND} -P "${dir}/${testname}.cmake"
+ RESULT_VARIABLE rv)
+ if(NOT rv EQUAL 0)
+ message(FATAL_ERROR "${testname} failed")
+ endif()
+
+elseif(testname STREQUAL bad_elseif) # fail
+ file(WRITE "${dir}/${testname}.cmake"
+"elseif()
+")
+ execute_process(COMMAND ${CMAKE_COMMAND} -P "${dir}/${testname}.cmake"
+ RESULT_VARIABLE rv)
+ if(NOT rv EQUAL 0)
+ message(FATAL_ERROR "${testname} failed")
+ endif()
+
+elseif(testname STREQUAL bad_endforeach) # fail
+ endforeach()
+
+elseif(testname STREQUAL bad_endfunction) # fail
+ endfunction()
+
+elseif(testname STREQUAL bad_endif) # fail
+ file(WRITE "${dir}/${testname}.cmake"
+"cmake_minimum_required(VERSION 2.8)
+endif()
+")
+ execute_process(COMMAND ${CMAKE_COMMAND} -P "${dir}/${testname}.cmake"
+ RESULT_VARIABLE rv)
+ if(NOT rv EQUAL 0)
+ message(FATAL_ERROR "${testname} failed")
+ endif()
+
+elseif(testname STREQUAL endif_low_min_version) # pass
+ file(WRITE "${dir}/${testname}.cmake"
+"cmake_minimum_required(VERSION 1.2)
+endif()
+")
+ execute_process(COMMAND ${CMAKE_COMMAND} -P "${dir}/${testname}.cmake"
+ RESULT_VARIABLE rv)
+ if(NOT rv EQUAL 0)
+ message(FATAL_ERROR "${testname} failed")
+ endif()
+
+elseif(testname STREQUAL endif_no_min_version) # pass
+ file(WRITE "${dir}/${testname}.cmake"
+"endif()
+")
+ execute_process(COMMAND ${CMAKE_COMMAND} -P "${dir}/${testname}.cmake"
+ RESULT_VARIABLE rv)
+ if(NOT rv EQUAL 0)
+ message(FATAL_ERROR "${testname} failed")
+ endif()
+
+elseif(testname STREQUAL bad_endmacro) # fail
+ endmacro()
+
+elseif(testname STREQUAL bad_endwhile) # fail
+ endwhile()
+
+else() # fail
+ message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'")
+
+endif()
diff --git a/Tests/CMakeTests/ExecuteScriptTests.cmake b/Tests/CMakeTests/ExecuteScriptTests.cmake
new file mode 100644
index 0000000000..bceac335fc
--- /dev/null
+++ b/Tests/CMakeTests/ExecuteScriptTests.cmake
@@ -0,0 +1,63 @@
+# This function calls the ${scriptname} file to execute one test case:
+#
+function(execute_one_script_test scriptname testname expected_result)
+ message("execute_one_script_test")
+ message("testname=[${testname}]")
+
+ execute_process(
+ COMMAND ${CMAKE_COMMAND}
+ -D "dir:STRING=${dir}"
+ -D "testname:STRING=${testname}"
+ -P "${scriptname}"
+ OUTPUT_VARIABLE out
+ ERROR_VARIABLE err
+ RESULT_VARIABLE result
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_STRIP_TRAILING_WHITESPACE
+ )
+
+ message("out=[${out}]")
+ message("err=[${err}]")
+
+ if(expected_result STREQUAL "fail")
+ # case expected to fail, result should be non-0...
+ # error if it's 0
+ if("${result}" STREQUAL "0")
+ message(SEND_ERROR "script failed: testname='${testname}' [${result}] actually passed, but expected to fail...")
+ endif()
+ else()
+ # case expected to pass, result should be 0...
+ # error if it's non-0
+ if(NOT "${result}" STREQUAL "0")
+ message(SEND_ERROR "script failed: testname='${testname}' [${result}] actually failed, but expected to pass...")
+ endif()
+ endif()
+
+ message("")
+endfunction()
+
+
+# This function reads the script file and calls execute_one_script_test for
+# each testname case listed in the script. To add new cases, simply edit the
+# script file and add an elseif() clause that matches 'regex' below.
+#
+function(execute_all_script_tests scriptname result)
+ file(READ "${scriptname}" script)
+
+ string(REPLACE ";" "\\\\;" script "${script}")
+ string(REPLACE "\n" "E;" script "${script}")
+
+ set(count 0)
+ set(regex "^ *(if|elseif) *\\( *testname +STREQUAL +\\\"*([^\\\"\\)]+)\\\"* *\\) *# *(fail|pass) *E$")
+
+ foreach(line ${script})
+ if(line MATCHES "${regex}")
+ set(testname "${CMAKE_MATCH_2}")
+ set(expected_result "${CMAKE_MATCH_3}")
+ math(EXPR count "${count} + 1")
+ execute_one_script_test(${scriptname} ${testname} ${expected_result})
+ endif()
+ endforeach()
+
+ set(${result} ${count} PARENT_SCOPE)
+endfunction()
diff --git a/Tests/CMakeTests/File-Copy-BadArg.cmake b/Tests/CMakeTests/File-Copy-BadArg.cmake
new file mode 100644
index 0000000000..91952fc60f
--- /dev/null
+++ b/Tests/CMakeTests/File-Copy-BadArg.cmake
@@ -0,0 +1 @@
+file(COPY FileTest.cmake DESTINATION tmp PATTERN * BADARG)
diff --git a/Tests/CMakeTests/File-Copy-BadPerm.cmake b/Tests/CMakeTests/File-Copy-BadPerm.cmake
new file mode 100644
index 0000000000..b5cc42f00b
--- /dev/null
+++ b/Tests/CMakeTests/File-Copy-BadPerm.cmake
@@ -0,0 +1 @@
+file(COPY FileTest.cmake DESTINATION tmp FILE_PERMISSIONS BADPERM)
diff --git a/Tests/CMakeTests/File-Copy-BadRegex.cmake b/Tests/CMakeTests/File-Copy-BadRegex.cmake
new file mode 100644
index 0000000000..41340f6230
--- /dev/null
+++ b/Tests/CMakeTests/File-Copy-BadRegex.cmake
@@ -0,0 +1 @@
+file(COPY FileTest.cmake DESTINATION tmp REGEX "(")
diff --git a/Tests/CMakeTests/File-Copy-EarlyArg.cmake b/Tests/CMakeTests/File-Copy-EarlyArg.cmake
new file mode 100644
index 0000000000..03993de387
--- /dev/null
+++ b/Tests/CMakeTests/File-Copy-EarlyArg.cmake
@@ -0,0 +1 @@
+file(COPY FileTest.cmake DESTINATION tmp PERMISSIONS)
diff --git a/Tests/CMakeTests/File-Copy-LateArg.cmake b/Tests/CMakeTests/File-Copy-LateArg.cmake
new file mode 100644
index 0000000000..43d216874e
--- /dev/null
+++ b/Tests/CMakeTests/File-Copy-LateArg.cmake
@@ -0,0 +1 @@
+file(COPY FileTest.cmake DESTINATION tmp PATTERN * FILE_PERMISSIONS)
diff --git a/Tests/CMakeTests/File-Copy-NoDest.cmake b/Tests/CMakeTests/File-Copy-NoDest.cmake
new file mode 100644
index 0000000000..f6c6c6d7ea
--- /dev/null
+++ b/Tests/CMakeTests/File-Copy-NoDest.cmake
@@ -0,0 +1 @@
+file(COPY FileTest.cmake)
diff --git a/Tests/CMakeTests/File-Copy-NoFile.cmake b/Tests/CMakeTests/File-Copy-NoFile.cmake
new file mode 100644
index 0000000000..d5853d3963
--- /dev/null
+++ b/Tests/CMakeTests/File-Copy-NoFile.cmake
@@ -0,0 +1 @@
+file(COPY does_not_exist.txt DESTINATION tmp)
diff --git a/Tests/CMakeTests/File-Glob-NoArg.cmake b/Tests/CMakeTests/File-Glob-NoArg.cmake
new file mode 100644
index 0000000000..486f366c1b
--- /dev/null
+++ b/Tests/CMakeTests/File-Glob-NoArg.cmake
@@ -0,0 +1,2 @@
+# Checking that the call without arguments get caught by the file global protection.
+file(GLOB)
diff --git a/Tests/CMakeTests/File-HASH-Input.txt b/Tests/CMakeTests/File-HASH-Input.txt
new file mode 100644
index 0000000000..a1d315b2de
--- /dev/null
+++ b/Tests/CMakeTests/File-HASH-Input.txt
@@ -0,0 +1 @@
+sample input string
diff --git a/Tests/CMakeTests/File-MD5-BadArg1.cmake b/Tests/CMakeTests/File-MD5-BadArg1.cmake
new file mode 100644
index 0000000000..ac5f67ae2a
--- /dev/null
+++ b/Tests/CMakeTests/File-MD5-BadArg1.cmake
@@ -0,0 +1 @@
+file(MD5)
diff --git a/Tests/CMakeTests/File-MD5-BadArg2.cmake b/Tests/CMakeTests/File-MD5-BadArg2.cmake
new file mode 100644
index 0000000000..2acc0757e3
--- /dev/null
+++ b/Tests/CMakeTests/File-MD5-BadArg2.cmake
@@ -0,0 +1 @@
+file(MD5 ${CMAKE_CURRENT_LIST_DIR}/File-HASH-Input.txt)
diff --git a/Tests/CMakeTests/File-MD5-BadArg4.cmake b/Tests/CMakeTests/File-MD5-BadArg4.cmake
new file mode 100644
index 0000000000..79b27558d9
--- /dev/null
+++ b/Tests/CMakeTests/File-MD5-BadArg4.cmake
@@ -0,0 +1 @@
+file(MD5 ${CMAKE_CURRENT_LIST_DIR}/File-HASH-Input.txt md5 extra_arg)
diff --git a/Tests/CMakeTests/File-MD5-NoFile.cmake b/Tests/CMakeTests/File-MD5-NoFile.cmake
new file mode 100644
index 0000000000..1b91bc8d88
--- /dev/null
+++ b/Tests/CMakeTests/File-MD5-NoFile.cmake
@@ -0,0 +1 @@
+file(MD5 ${CMAKE_CURRENT_LIST_DIR}/DoesNotExist.cmake md5)
diff --git a/Tests/CMakeTests/File-MD5-Works.cmake b/Tests/CMakeTests/File-MD5-Works.cmake
new file mode 100644
index 0000000000..0fabe54a47
--- /dev/null
+++ b/Tests/CMakeTests/File-MD5-Works.cmake
@@ -0,0 +1,2 @@
+file(MD5 ${CMAKE_CURRENT_LIST_DIR}/File-HASH-Input.txt md5)
+message("${md5}")
diff --git a/Tests/CMakeTests/File-SHA1-Works.cmake b/Tests/CMakeTests/File-SHA1-Works.cmake
new file mode 100644
index 0000000000..f2ab5d7474
--- /dev/null
+++ b/Tests/CMakeTests/File-SHA1-Works.cmake
@@ -0,0 +1,2 @@
+file(SHA1 ${CMAKE_CURRENT_LIST_DIR}/File-HASH-Input.txt sha1)
+message("${sha1}")
diff --git a/Tests/CMakeTests/File-SHA224-Works.cmake b/Tests/CMakeTests/File-SHA224-Works.cmake
new file mode 100644
index 0000000000..3e86b172fc
--- /dev/null
+++ b/Tests/CMakeTests/File-SHA224-Works.cmake
@@ -0,0 +1,2 @@
+file(SHA224 ${CMAKE_CURRENT_LIST_DIR}/File-HASH-Input.txt sha224)
+message("${sha224}")
diff --git a/Tests/CMakeTests/File-SHA256-Works.cmake b/Tests/CMakeTests/File-SHA256-Works.cmake
new file mode 100644
index 0000000000..b72d89e95b
--- /dev/null
+++ b/Tests/CMakeTests/File-SHA256-Works.cmake
@@ -0,0 +1,2 @@
+file(SHA256 ${CMAKE_CURRENT_LIST_DIR}/File-HASH-Input.txt sha256)
+message("${sha256}")
diff --git a/Tests/CMakeTests/File-SHA384-Works.cmake b/Tests/CMakeTests/File-SHA384-Works.cmake
new file mode 100644
index 0000000000..0eeca33cbf
--- /dev/null
+++ b/Tests/CMakeTests/File-SHA384-Works.cmake
@@ -0,0 +1,2 @@
+file(SHA384 ${CMAKE_CURRENT_LIST_DIR}/File-HASH-Input.txt sha384)
+message("${sha384}")
diff --git a/Tests/CMakeTests/File-SHA512-Works.cmake b/Tests/CMakeTests/File-SHA512-Works.cmake
new file mode 100644
index 0000000000..d74ee44299
--- /dev/null
+++ b/Tests/CMakeTests/File-SHA512-Works.cmake
@@ -0,0 +1,2 @@
+file(SHA512 ${CMAKE_CURRENT_LIST_DIR}/File-HASH-Input.txt sha512)
+message("${sha512}")
diff --git a/Tests/CMakeTests/File-TIMESTAMP-BadArg1.cmake b/Tests/CMakeTests/File-TIMESTAMP-BadArg1.cmake
new file mode 100644
index 0000000000..cc15c77a89
--- /dev/null
+++ b/Tests/CMakeTests/File-TIMESTAMP-BadArg1.cmake
@@ -0,0 +1 @@
+file(TIMESTAMP "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")
diff --git a/Tests/CMakeTests/File-TIMESTAMP-NoFile.cmake b/Tests/CMakeTests/File-TIMESTAMP-NoFile.cmake
new file mode 100644
index 0000000000..62390e792a
--- /dev/null
+++ b/Tests/CMakeTests/File-TIMESTAMP-NoFile.cmake
@@ -0,0 +1,2 @@
+file(TIMESTAMP "${CMAKE_CURRENT_LIST_DIR}/DoesNotExist.cmake" output)
+message("~${output}~")
diff --git a/Tests/CMakeTests/File-TIMESTAMP-NotBogus.cmake b/Tests/CMakeTests/File-TIMESTAMP-NotBogus.cmake
new file mode 100644
index 0000000000..d0e5fe35f1
--- /dev/null
+++ b/Tests/CMakeTests/File-TIMESTAMP-NotBogus.cmake
@@ -0,0 +1,24 @@
+set(STAMP_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/FileTimestamp-Stamp")
+set(STAMP_FORMAT "%Y-%m-%d")
+
+string(TIMESTAMP timestamp1 "${STAMP_FORMAT}")
+
+file(WRITE "${STAMP_FILENAME}" "foo")
+file(TIMESTAMP "${STAMP_FILENAME}" timestamp2 "${STAMP_FORMAT}")
+
+string(TIMESTAMP timestamp3 "${STAMP_FORMAT}")
+
+message(STATUS "timestamp1 [${timestamp1}]")
+message(STATUS "timestamp2 [${timestamp2}]")
+message(STATUS "timestamp3 [${timestamp3}]")
+
+if(timestamp1 STREQUAL timestamp3)
+ if(NOT timestamp1 STREQUAL timestamp2)
+ message(FATAL_ERROR
+ "timestamp mismatch [${timestamp1}] != [${timestamp2}]")
+ else()
+ message("all timestamps match")
+ endif()
+else()
+ message(WARNING "this test may race when run at midnight")
+endif()
diff --git a/Tests/CMakeTests/File-TIMESTAMP-Works.cmake b/Tests/CMakeTests/File-TIMESTAMP-Works.cmake
new file mode 100644
index 0000000000..4351b19dd8
--- /dev/null
+++ b/Tests/CMakeTests/File-TIMESTAMP-Works.cmake
@@ -0,0 +1,2 @@
+file(TIMESTAMP "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" output UTC)
+message("~${output}~")
diff --git a/Tests/CMakeTests/FileDownloadBadHashTest.cmake.in b/Tests/CMakeTests/FileDownloadBadHashTest.cmake.in
new file mode 100644
index 0000000000..4a47c06957
--- /dev/null
+++ b/Tests/CMakeTests/FileDownloadBadHashTest.cmake.in
@@ -0,0 +1,10 @@
+set(url "file://@CMAKE_CURRENT_SOURCE_DIR@/FileDownloadInput.png")
+set(dir "@CMAKE_CURRENT_BINARY_DIR@/downloads")
+
+file(DOWNLOAD
+ ${url}
+ ${dir}/file3.png
+ TIMEOUT 2
+ STATUS status
+ EXPECTED_HASH SHA1=5555555555555555555555555555555555555555
+ )
diff --git a/Tests/CMakeTests/FileDownloadInput.png b/Tests/CMakeTests/FileDownloadInput.png
new file mode 100644
index 0000000000..7bbcee413c
--- /dev/null
+++ b/Tests/CMakeTests/FileDownloadInput.png
Binary files differ
diff --git a/Tests/CMakeTests/FileDownloadTest.cmake.in b/Tests/CMakeTests/FileDownloadTest.cmake.in
new file mode 100644
index 0000000000..83ade2ba75
--- /dev/null
+++ b/Tests/CMakeTests/FileDownloadTest.cmake.in
@@ -0,0 +1,109 @@
+set(url "file://@CMAKE_CURRENT_SOURCE_DIR@/FileDownloadInput.png")
+set(dir "@CMAKE_CURRENT_BINARY_DIR@/downloads")
+
+message(STATUS "FileDownload:1")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file1.png
+ TIMEOUT 2
+ )
+
+message(STATUS "FileDownload:2")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file2.png
+ TIMEOUT 2
+ SHOW_PROGRESS
+ )
+
+# Two calls in a row, exactly the same arguments.
+# Since downloaded file should exist already for 2nd call,
+# the 2nd call will short-circuit and return early...
+#
+if(EXISTS ${dir}/file3.png)
+ file(REMOVE ${dir}/file3.png)
+endif()
+
+message(STATUS "FileDownload:3")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file3.png
+ TIMEOUT 2
+ EXPECTED_MD5 d16778650db435bda3a8c3435c3ff5d1
+ )
+
+message(STATUS "FileDownload:4")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file3.png
+ TIMEOUT 2
+ STATUS status
+ EXPECTED_HASH SHA1=50c614fc28b39c1281d0517bb6d5858b4359c9b7
+ )
+
+message(STATUS "FileDownload:5")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file3.png
+ TIMEOUT 2
+ STATUS status
+ EXPECTED_HASH SHA224=73cd5f442b04e8320e4f907f8e1b21d4befff98b5bd77bc32526ea68
+ )
+
+message(STATUS "FileDownload:6")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file3.png
+ TIMEOUT 2
+ STATUS status
+ EXPECTED_HASH SHA256=2e067f6c09cbc7cd619c8fbcc44eb64cd6b45a95e4cddb3a585eee1f731c4da9
+ )
+
+message(STATUS "FileDownload:7")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file3.png
+ TIMEOUT 2
+ STATUS status
+ EXPECTED_HASH SHA384=398bf41902a7251c30e522b307e3e41e3fb617c765b3feaa99b2f7d063894708ad399267ccc25d877437a10e5e890d35
+ )
+
+message(STATUS "FileDownload:8")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file3.png
+ TIMEOUT 2
+ STATUS status
+ EXPECTED_HASH SHA512=c51854d21052713968b849c2b4263cf54be03bc3a7e9847a6c71c6c8d1d13cd805fe1b9fa95f9ba1d0a5631513974f6fae21e34ab5b171d94bad48df5f073e48
+ )
+message(STATUS "FileDownload:9")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file3.png
+ TIMEOUT 2
+ STATUS status
+ EXPECTED_HASH MD5=d16778650db435bda3a8c3435c3ff5d1
+ )
+
+message(STATUS "FileDownload:10")
+file(DOWNLOAD
+ ${url}
+ ${dir}/file3.png
+ TIMEOUT 2
+ STATUS status
+ EXPECTED_MD5 d16778650db435bda3a8c3435c3ff5d1
+ )
+message(STATUS "${status}")
+
+message(STATUS "FileDownload:11")
+file(DOWNLOAD
+ badhostname.png
+ ${dir}/file11.png
+ TIMEOUT 2
+ STATUS status
+ )
+message(STATUS "${status}")
+list(GET status 0 status_code)
+if(NOT ${status_code} EQUAL 6)
+ message(SEND_ERROR "error: expected status code 6 for bad host name, got: ${status_code}")
+endif()
diff --git a/Tests/CMakeTests/FileTest.cmake.in b/Tests/CMakeTests/FileTest.cmake.in
new file mode 100644
index 0000000000..61523e6f64
--- /dev/null
+++ b/Tests/CMakeTests/FileTest.cmake.in
@@ -0,0 +1,97 @@
+set(Copy-BadArg-RESULT 1)
+set(Copy-BadArg-STDERR "unknown argument \"BADARG\"")
+set(Copy-BadPerm-RESULT 1)
+set(Copy-BadPerm-STDERR "COPY given invalid permission \"BADPERM\"")
+set(Copy-BadRegex-RESULT 1)
+set(Copy-BadRegex-STDERR "could not compile REGEX")
+set(Copy-EarlyArg-RESULT 1)
+set(Copy-EarlyArg-STDERR "option PERMISSIONS may not appear before")
+set(Copy-LateArg-RESULT 1)
+set(Copy-LateArg-STDERR "option FILE_PERMISSIONS may not appear after")
+set(Copy-NoDest-RESULT 1)
+set(Copy-NoDest-STDERR "given no DESTINATION")
+set(Copy-NoFile-RESULT 1)
+set(Copy-NoFile-STDERR "COPY cannot find.*/does_not_exist\\.txt")
+set(Glob-NoArg-RESULT 1)
+set(Glob-NoArg-STDERR "file must be called with at least two arguments")
+set(Make_Directory-NoArg-RESULT 1)
+set(Make-Directory-NoArg-STDERR "file must be called with at least two arguments")
+set(MD5-NoFile-RESULT 1)
+set(MD5-NoFile-STDERR "file MD5 failed to read file")
+set(MD5-BadArg1-RESULT 1)
+set(MD5-BadArg1-STDERR "file must be called with at least two arguments")
+set(MD5-BadArg2-RESULT 1)
+set(MD5-BadArg2-STDERR "file MD5 requires a file name and output variable")
+set(MD5-BadArg4-RESULT 1)
+set(MD5-BadArg4-STDERR "file MD5 requires a file name and output variable")
+set(MD5-Works-RESULT 0)
+set(MD5-Works-STDERR "10d20ddb981a6202b84aa1ce1cb7fce3")
+set(SHA1-Works-RESULT 0)
+set(SHA1-Works-STDERR "83f093e04289b21a9415f408ad50be8b57ad2f34")
+set(SHA224-Works-RESULT 0)
+set(SHA224-Works-STDERR "e995a7789922c4ef9279d94e763c8375934180a51baa7147bc48edf7")
+set(SHA256-Works-RESULT 0)
+set(SHA256-Works-STDERR "d1c5915d8b71150726a1eef75a29ec6bea8fd1bef6b7299ef8048760b0402025")
+set(SHA384-Works-RESULT 0)
+set(SHA384-Works-STDERR "1de9560b4e030e02051ea408200ffc55d70c97ac64ebf822461a5c786f495c36df43259b14483bc8d364f0106f4971ee")
+set(SHA512-Works-RESULT 0)
+set(SHA512-Works-STDERR "3982a1b4e651768bec70ab1fb97045cb7a659f4ba7203d501c52ab2e803071f9d5fd272022df15f27727fc67f8cd022e710e29010b2a9c0b467c111e2f6abf51")
+set(TIMESTAMP-NoFile-RESULT 0)
+set(TIMESTAMP-NoFile-STDERR "~~")
+set(TIMESTAMP-BadArg1-RESULT 1)
+set(TIMESTAMP-BadArg1-STDERR "file sub-command TIMESTAMP requires at least two arguments")
+set(TIMESTAMP-NotBogus-RESULT 0)
+set(TIMESTAMP-NotBogus-STDERR "all timestamps match")
+set(TIMESTAMP-Works-RESULT 0)
+set(TIMESTAMP-Works-STDERR "~[0-9]*-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-6][0-9]Z~")
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
+check_cmake_test(File
+ Copy-BadArg
+ Copy-BadPerm
+ Copy-BadRegex
+ Copy-EarlyArg
+ Copy-LateArg
+ Copy-NoDest
+ Copy-NoFile
+ Glob-NoArg
+ Make_Directory-NoArg
+ MD5-NoFile
+ MD5-BadArg1
+ MD5-BadArg2
+ MD5-BadArg4
+ MD5-Works
+ SHA1-Works
+ SHA224-Works
+ SHA256-Works
+ SHA384-Works
+ SHA512-Works
+ TIMESTAMP-NoFile
+ TIMESTAMP-BadArg1
+ TIMESTAMP-NotBogus
+ TIMESTAMP-Works
+ )
+
+file(GLOB hum)
+if (NOT hum STREQUAL "")
+ message(FATAL_ERROR "file(GLOB hum) did not return an empty string.")
+endif()
+
+# Also execute each test listed in FileTestScript.cmake:
+#
+set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/FileTestScript.cmake")
+set(number_of_tests_expected 62)
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/ExecuteScriptTests.cmake")
+execute_all_script_tests(${scriptname} number_of_tests_executed)
+
+# And verify that number_of_tests_executed is at least as many as we know
+# about as of this writing...
+#
+message(STATUS "scriptname='${scriptname}'")
+message(STATUS "number_of_tests_executed='${number_of_tests_executed}'")
+message(STATUS "number_of_tests_expected='${number_of_tests_expected}'")
+
+if(number_of_tests_executed LESS number_of_tests_expected)
+ message(FATAL_ERROR "error: some test cases were skipped")
+endif()
diff --git a/Tests/CMakeTests/FileTestScript.cmake b/Tests/CMakeTests/FileTestScript.cmake
new file mode 100644
index 0000000000..9a4356973f
--- /dev/null
+++ b/Tests/CMakeTests/FileTestScript.cmake
@@ -0,0 +1,227 @@
+message(STATUS "testname='${testname}'")
+
+if(testname STREQUAL empty) # fail
+ file()
+
+elseif(testname STREQUAL bogus) # fail
+ file(BOGUS ffff)
+
+elseif(testname STREQUAL different_not_enough_args) # fail
+ file(DIFFERENT ffff)
+
+elseif(testname STREQUAL download_not_enough_args) # fail
+ file(DOWNLOAD ffff)
+
+elseif(testname STREQUAL read_not_enough_args) # fail
+ file(READ ffff)
+
+elseif(testname STREQUAL rpath_check_not_enough_args) # fail
+ file(RPATH_CHECK ffff)
+
+elseif(testname STREQUAL rpath_remove_not_enough_args) # fail
+ file(RPATH_REMOVE ffff)
+
+elseif(testname STREQUAL strings_not_enough_args) # fail
+ file(STRINGS ffff)
+
+elseif(testname STREQUAL to_native_path_not_enough_args) # fail
+ file(TO_NATIVE_PATH ffff)
+
+elseif(testname STREQUAL read_with_offset) # pass
+ file(READ ${CMAKE_CURRENT_LIST_FILE} v OFFSET 42 LIMIT 30)
+ message("v='${v}'")
+
+elseif(testname STREQUAL strings_bad_length_minimum) # fail
+ file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LENGTH_MINIMUM bogus)
+
+elseif(testname STREQUAL strings_bad_length_maximum) # fail
+ file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LENGTH_MAXIMUM bogus)
+
+elseif(testname STREQUAL strings_bad_limit_count) # fail
+ file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LIMIT_COUNT bogus)
+
+elseif(testname STREQUAL strings_bad_limit_input) # fail
+ file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LIMIT_INPUT bogus)
+
+elseif(testname STREQUAL strings_bad_limit_output) # fail
+ file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LIMIT_OUTPUT bogus)
+
+elseif(testname STREQUAL strings_bad_regex) # fail
+ file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v REGEX "(")
+
+elseif(testname STREQUAL strings_unknown_arg) # fail
+ file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v BOGUS)
+
+elseif(testname STREQUAL strings_bad_filename) # fail
+ file(STRINGS ffff v LIMIT_COUNT 10)
+
+elseif(testname STREQUAL strings_use_limit_count) # pass
+ file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LIMIT_COUNT 10)
+ message("v='${v}'")
+
+elseif(testname STREQUAL strings_use_no_hex_conversion) # pass
+ file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v NO_HEX_CONVERSION)
+ message("v='${v}'")
+
+elseif(testname STREQUAL glob_recurse_follow_symlinks_no_expression) # fail
+ file(GLOB_RECURSE v FOLLOW_SYMLINKS)
+
+elseif(testname STREQUAL glob_recurse_relative_no_directory) # fail
+ file(GLOB_RECURSE v RELATIVE)
+
+elseif(testname STREQUAL glob_recurse_relative_no_expression) # fail
+ file(GLOB_RECURSE v RELATIVE dddd)
+
+elseif(testname STREQUAL glob_non_full_path) # pass
+ file(GLOB_RECURSE v ffff*.*)
+ message("v='${v}'")
+
+elseif(testname STREQUAL make_directory_non_full_path) # pass
+ file(MAKE_DIRECTORY FileTestScriptDDDD)
+ if(NOT EXISTS FileTestScriptDDDD)
+ message(FATAL_ERROR "error: non-full-path MAKE_DIRECTORY failed")
+ endif()
+ file(REMOVE_RECURSE FileTestScriptDDDD)
+ if(EXISTS FileTestScriptDDDD)
+ message(FATAL_ERROR "error: non-full-path REMOVE_RECURSE failed")
+ endif()
+
+elseif(testname STREQUAL different_no_variable) # fail
+ file(DIFFERENT FILES)
+
+elseif(testname STREQUAL different_no_files) # fail
+ file(DIFFERENT v FILES)
+
+elseif(testname STREQUAL different_unknown_arg) # fail
+ file(DIFFERENT v FILES ffffLHS ffffRHS BOGUS)
+
+elseif(testname STREQUAL different_different) # pass
+ file(DIFFERENT v FILES ffffLHS ffffRHS)
+ message("v='${v}'")
+
+elseif(testname STREQUAL different_same) # pass
+ file(DIFFERENT v FILES
+ ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_FILE})
+ message("v='${v}'")
+
+elseif(testname STREQUAL rpath_change_unknown_arg) # fail
+ file(RPATH_CHANGE BOGUS)
+
+elseif(testname STREQUAL rpath_change_bad_file) # fail
+ file(RPATH_CHANGE FILE)
+
+elseif(testname STREQUAL rpath_change_bad_old_rpath) # fail
+ file(RPATH_CHANGE FILE ffff OLD_RPATH)
+
+elseif(testname STREQUAL rpath_change_bad_new_rpath) # fail
+ file(RPATH_CHANGE FILE ffff OLD_RPATH rrrr NEW_RPATH)
+
+elseif(testname STREQUAL rpath_change_file_does_not_exist) # fail
+ file(RPATH_CHANGE FILE ffff OLD_RPATH rrrr NEW_RPATH RRRR)
+
+elseif(testname STREQUAL rpath_change_file_is_not_executable) # fail
+ file(RPATH_CHANGE FILE ${CMAKE_CURRENT_LIST_FILE}
+ OLD_RPATH rrrr NEW_RPATH RRRR)
+
+elseif(testname STREQUAL rpath_remove_unknown_arg) # fail
+ file(RPATH_REMOVE BOGUS)
+
+elseif(testname STREQUAL rpath_remove_bad_file) # fail
+ file(RPATH_REMOVE FILE)
+
+elseif(testname STREQUAL rpath_remove_file_does_not_exist) # fail
+ file(RPATH_REMOVE FILE ffff)
+
+#elseif(testname STREQUAL rpath_remove_file_is_not_executable) # fail
+# file(RPATH_REMOVE FILE ${CMAKE_CURRENT_LIST_FILE})
+
+elseif(testname STREQUAL rpath_check_unknown_arg) # fail
+ file(RPATH_CHECK BOGUS)
+
+elseif(testname STREQUAL rpath_check_bad_file) # fail
+ file(RPATH_CHECK FILE)
+
+elseif(testname STREQUAL rpath_check_bad_rpath) # fail
+ file(RPATH_CHECK FILE ffff RPATH)
+
+elseif(testname STREQUAL rpath_check_file_does_not_exist) # pass
+ file(RPATH_CHECK FILE ffff RPATH rrrr)
+
+elseif(testname STREQUAL rpath_check_file_is_not_executable) # pass
+ file(WRITE ffff_rpath_check "")
+
+ if(NOT EXISTS ffff_rpath_check)
+ message(FATAL_ERROR "error: non-full-path WRITE failed")
+ endif()
+
+ file(RPATH_CHECK FILE ffff_rpath_check RPATH rrrr)
+ # careful: if the file does not have the given RPATH, it is deleted...
+
+ if(EXISTS ffff_rpath_check)
+ message(FATAL_ERROR "error: non-full-path RPATH_CHECK failed")
+ endif()
+
+elseif(testname STREQUAL relative_path_wrong_number_of_args) # fail
+ file(RELATIVE_PATH v dir)
+
+elseif(testname STREQUAL relative_path_non_full_path_dir) # fail
+ file(RELATIVE_PATH v dir file)
+
+elseif(testname STREQUAL relative_path_non_full_path_file) # fail
+ file(RELATIVE_PATH v /dir file)
+
+elseif(testname STREQUAL rename_wrong_number_of_args) # fail
+ file(RENAME ffff)
+
+elseif(testname STREQUAL rename_input_file_does_not_exist) # fail
+ file(RENAME ffff FFFFGGGG)
+
+elseif(testname STREQUAL to_native_path) # pass
+ file(TO_NATIVE_PATH /a/b/c\;/d/e/f:/g/h/i v)
+ message("v='${v}'")
+
+elseif(testname STREQUAL download_wrong_number_of_args) # fail
+ file(DOWNLOAD zzzz://bogus/ffff)
+
+elseif(testname STREQUAL download_file_with_no_path) # fail
+ file(DOWNLOAD zzzz://bogus/ffff ffff)
+
+elseif(testname STREQUAL download_missing_time) # fail
+ file(DOWNLOAD zzzz://bogus/ffff ./ffff TIMEOUT)
+
+elseif(testname STREQUAL download_missing_log_var) # fail
+ file(DOWNLOAD zzzz://bogus/ffff ./ffff TIMEOUT 2 LOG)
+
+elseif(testname STREQUAL download_missing_status_var) # fail
+ file(DOWNLOAD zzzz://bogus/ffff ./ffff TIMEOUT 2 LOG l STATUS)
+
+elseif(testname STREQUAL download_with_bogus_protocol) # pass
+ file(DOWNLOAD zzzz://bogus/ffff ./ffff TIMEOUT 2 LOG l STATUS s)
+ file(REMOVE ./ffff)
+ message("l='${l}'")
+ message("s='${s}'")
+
+elseif(testname STREQUAL upload_wrong_number_of_args) # fail
+ file(UPLOAD ./ffff)
+
+elseif(testname STREQUAL upload_missing_time) # fail
+ file(UPLOAD ./ffff zzzz://bogus/ffff TIMEOUT)
+
+elseif(testname STREQUAL upload_missing_log_var) # fail
+ file(UPLOAD ./ffff zzzz://bogus/ffff TIMEOUT 2 LOG)
+
+elseif(testname STREQUAL upload_missing_status_var) # fail
+ file(UPLOAD ./ffff zzzz://bogus/ffff TIMEOUT 2 LOG l STATUS)
+
+elseif(testname STREQUAL upload_file_that_doesnt_exist) # fail
+ file(UPLOAD ./ffff zzzz://bogus/ffff)
+
+elseif(testname STREQUAL upload_with_bogus_protocol) # pass
+ file(UPLOAD ${CMAKE_CURRENT_LIST_FILE} zzzz://bogus/ffff TIMEOUT 2 LOG l STATUS s)
+ message("l='${l}'")
+ message("s='${s}'")
+
+else() # fail
+ message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'")
+
+endif()
diff --git a/Tests/CMakeTests/FileUploadTest.cmake.in b/Tests/CMakeTests/FileUploadTest.cmake.in
new file mode 100644
index 0000000000..8577aefd28
--- /dev/null
+++ b/Tests/CMakeTests/FileUploadTest.cmake.in
@@ -0,0 +1,49 @@
+file(REMOVE_RECURSE "@CMAKE_CURRENT_BINARY_DIR@/uploads")
+
+if(EXISTS "@CMAKE_CURRENT_BINARY_DIR@/uploads/file1.png")
+ message(FATAL_ERROR "error: file1.png exists - should have been deleted")
+endif()
+if(EXISTS "@CMAKE_CURRENT_BINARY_DIR@/uploads/file2.png")
+ message(FATAL_ERROR "error: file2.png exists - should have been deleted")
+endif()
+
+file(MAKE_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@/uploads")
+
+set(filename "@CMAKE_CURRENT_SOURCE_DIR@/FileDownloadInput.png")
+set(urlbase "file://@CMAKE_CURRENT_BINARY_DIR@/uploads")
+
+message(STATUS "FileUpload:1")
+file(UPLOAD
+ ${filename}
+ ${urlbase}/file1.png
+ TIMEOUT 2
+ )
+
+message(STATUS "FileUpload:2")
+file(UPLOAD
+ ${filename}
+ ${urlbase}/file2.png
+ STATUS status
+ LOG log
+ SHOW_PROGRESS
+ )
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E md5sum
+ "@CMAKE_CURRENT_BINARY_DIR@/uploads/file1.png"
+ OUTPUT_VARIABLE sum1
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+if(NOT sum1 MATCHES "^d16778650db435bda3a8c3435c3ff5d1 .*/uploads/file1.png$")
+ message(FATAL_ERROR "file1.png did not upload correctly (sum1='${sum1}')")
+endif()
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E md5sum
+ "@CMAKE_CURRENT_BINARY_DIR@/uploads/file2.png"
+ OUTPUT_VARIABLE sum2
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+if(NOT sum2 MATCHES "^d16778650db435bda3a8c3435c3ff5d1 .*/uploads/file2.png$")
+ message(FATAL_ERROR "file2.png did not upload correctly (sum2='${sum2}')")
+endif()
+
+message(STATUS "log='${log}'")
+message(STATUS "status='${status}'")
+message(STATUS "DONE")
diff --git a/Tests/CMakeTests/FindBaseTest.cmake.in b/Tests/CMakeTests/FindBaseTest.cmake.in
new file mode 100644
index 0000000000..658b350228
--- /dev/null
+++ b/Tests/CMakeTests/FindBaseTest.cmake.in
@@ -0,0 +1,62 @@
+set(MY_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
+
+# The find_* commands do path normalization so we should do so too
+# before comparing results.
+get_filename_component(MY_SOURCE_DIR "${MY_SOURCE_DIR}" ABSOLUTE)
+
+set(_HEADER cmake_i_do_not_exist_in_the_system.h)
+set(_HEADER_FULL "${MY_SOURCE_DIR}/include/${_HEADER}")
+set(_HEADER_FULL_A "${MY_SOURCE_DIR}/A/include/${_HEADER}")
+
+# at first check that the header isn't found without special measures
+find_file(FOO_H_1 ${_HEADER})
+if(FOO_H_1)
+ message(FATAL_ERROR "${_HEADER} found: ${FOO_H_1}, it should not exist !")
+endif()
+
+# The HINTS option should override the system but the PATHS option
+# should not.
+set(CMAKE_SYSTEM_PREFIX_PATH ${MY_SOURCE_DIR})
+find_file(TEST_H_1 ${_HEADER} HINTS ${MY_SOURCE_DIR}/A/include)
+find_file(TEST_H_2 ${_HEADER} PATHS ${MY_SOURCE_DIR}/A/include)
+if(NOT "${TEST_H_1}" STREQUAL "${_HEADER_FULL_A}")
+ message(FATAL_ERROR "Did not find \"${_HEADER_FULL_A}\"\ngot \"${TEST_H_1}\" instead!")
+endif()
+if(NOT "${TEST_H_2}" STREQUAL "${_HEADER_FULL}")
+ message(FATAL_ERROR "Did not find \"${_HEADER_FULL}\"\ngot \"${TEST_H_2}\" instead!")
+endif()
+set(CMAKE_SYSTEM_PREFIX_PATH)
+
+# with this it still should not be found, since the include/ subdir is still missing
+set(CMAKE_INCLUDE_PATH "${MY_SOURCE_DIR}")
+find_file(FOO_H_2 ${_HEADER})
+if(FOO_H_2)
+ message(FATAL_ERROR "${_HEADER} found: ${FOO_H_2}, it should not exist !")
+endif()
+
+# now with the PATH_SUFFIX it should be found
+find_file(FOO_H_3 NAMES ${_HEADER} PATH_SUFFIXES include )
+if(NOT "${FOO_H_3}" STREQUAL "${_HEADER_FULL}")
+ message(FATAL_ERROR "Did not find \"${_HEADER_FULL}\"\ngot ${FOO_H_3} instead !")
+endif()
+
+# without PATH_SUFFIX, but with a CMAKE_INCLUDE_PATH it should not be found
+set(CMAKE_INCLUDE_PATH /include)
+find_file(FOO_H_4 ${_HEADER})
+if(FOO_H_4)
+ message(FATAL_ERROR "${_HEADER} found: ${FOO_H_4}, it should not exist !")
+endif()
+
+# when setting CMAKE_FIND_ROOT_PATH to the current source dir,
+# together with the CMAKE_INCLUDE_PATH it should be found
+set(CMAKE_FIND_ROOT_PATH blub "${MY_SOURCE_DIR}")
+find_file(FOO_H_5 ${_HEADER})
+if(NOT "${FOO_H_5}" STREQUAL "${_HEADER_FULL}")
+ message(FATAL_ERROR "Did not find \"${_HEADER_FULL}\"\ngot ${FOO_H_5} instead !")
+endif()
+
+# by explicitly disabling CMAKE_FIND_ROOT_PATH again it shouldn't be found
+find_file(FOO_H_6 ${_HEADER} NO_CMAKE_FIND_ROOT_PATH)
+if(FOO_H_6)
+ message(FATAL_ERROR "${_HEADER} found: ${FOO_H_6}, it should not exist !")
+endif()
diff --git a/Tests/CMakeTests/GetFilenameComponentRealpathTest.cmake.in b/Tests/CMakeTests/GetFilenameComponentRealpathTest.cmake.in
new file mode 100644
index 0000000000..22f6afd3b6
--- /dev/null
+++ b/Tests/CMakeTests/GetFilenameComponentRealpathTest.cmake.in
@@ -0,0 +1,72 @@
+set(bindir ${CMAKE_CURRENT_BINARY_DIR})
+
+#
+# Test nonexistent REALPATH & ABSOLUTE resolution
+#
+get_filename_component(nonexistent1 ${bindir}/THIS_IS_A_NONEXISTENT_FILE REALPATH)
+get_filename_component(nonexistent2 ${bindir}/THIS_IS_A_NONEXISTENT_FILE ABSOLUTE)
+if(NOT nonexistent1 STREQUAL "${bindir}/THIS_IS_A_NONEXISTENT_FILE")
+ message(FATAL_ERROR "REALPATH is not preserving nonexistent files")
+endif()
+if(NOT nonexistent2 STREQUAL "${bindir}/THIS_IS_A_NONEXISTENT_FILE")
+ message(FATAL_ERROR "ABSOLUTE is not preserving nonexistent files")
+endif()
+
+#
+# Test treatment of relative paths
+#
+foreach(c REALPATH ABSOLUTE)
+ get_filename_component(dir "subdir/THIS_IS_A_NONEXISTENT_FILE" ${c})
+ if(NOT "${dir}" STREQUAL "${bindir}/subdir/THIS_IS_A_NONEXISTENT_FILE")
+ message(FATAL_ERROR
+ "${c} does not handle relative paths. Expected:\n"
+ " ${bindir}/subdir/THIS_IS_A_NONEXISTENT_FILE\n"
+ "but got:\n"
+ " ${nonexistent1}\n"
+ )
+ endif()
+endforeach()
+
+#
+# Test symbolic link resolution
+#
+if(UNIX)
+ # file1 => file2 => file3 (real)
+ file(WRITE ${bindir}/file3 "test file")
+
+ find_program(LN NAMES "ln")
+ if(LN)
+ # Create symlinks using "ln -s"
+ if(NOT EXISTS ${bindir}/file2)
+ execute_process(COMMAND ${LN} "-s" "${bindir}/file3" "${bindir}/file2")
+ endif()
+ if(NOT EXISTS ${bindir}/file1)
+ execute_process(COMMAND ${LN} "-s" "${bindir}/file2" "${bindir}/file1")
+ endif()
+
+ get_filename_component(file1 ${bindir}/file1 REALPATH)
+ get_filename_component(file2 ${bindir}/file2 REALPATH)
+ get_filename_component(file3 ${bindir}/file3 REALPATH)
+
+ if(NOT file3 STREQUAL "${bindir}/file3")
+ message(FATAL_ERROR "CMake fails resolving REALPATH file file3")
+ endif()
+
+ if(NOT file2 STREQUAL "${bindir}/file3")
+ message(FATAL_ERROR "CMake fails resolving simple symlink")
+ endif()
+
+ if(NOT file1 STREQUAL "${bindir}/file3")
+ message(FATAL_ERROR "CMake fails resolving double symlink")
+ endif()
+
+ # cleanup
+ file(REMOVE ${bindir}/file1)
+ file(REMOVE ${bindir}/file2)
+ if(EXISTS file1 OR EXISTS file2)
+ message(FATAL_ERROR "removal of file1 or file2 failed")
+ endif()
+ endif()
+
+ file(REMOVE ${bindir}/file3)
+endif()
diff --git a/Tests/CMakeTests/GetPrerequisitesTest.cmake.in b/Tests/CMakeTests/GetPrerequisitesTest.cmake.in
new file mode 100644
index 0000000000..89ca735d3f
--- /dev/null
+++ b/Tests/CMakeTests/GetPrerequisitesTest.cmake.in
@@ -0,0 +1,159 @@
+# Test of the functions in the CMake Modules file:
+#
+include(GetPrerequisites)
+
+set(CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@")
+set(CMAKE_CONFIGURATION_TYPES "@CMAKE_CONFIGURATION_TYPES@")
+set(CMAKE_EXECUTABLE_SUFFIX "@CMAKE_EXECUTABLE_SUFFIX@")
+
+
+message(STATUS "=============================================================================")
+message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+message(STATUS "")
+message(STATUS "CMAKE_BUILD_TYPE='${CMAKE_BUILD_TYPE}'")
+message(STATUS "CMAKE_CONFIGURATION_TYPES='${CMAKE_CONFIGURATION_TYPES}'")
+message(STATUS "CMAKE_EXECUTABLE_SUFFIX='${CMAKE_EXECUTABLE_SUFFIX}'")
+message(STATUS "CTEST_CONFIGURATION_TYPE='${CTEST_CONFIGURATION_TYPE}'")
+message(STATUS "")
+
+
+function(stresstest_list_prerequisites file)
+ message(STATUS "=============================================================================")
+ message(STATUS "stresstest_list_prerequisites file='${file}'")
+ message(STATUS "")
+
+ get_filename_component(file_full "${file}" ABSOLUTE)
+
+ message(STATUS "list_prerequisites '${file_full}' 0 0 0")
+ list_prerequisites("${file_full}" 0 0 0)
+ message(STATUS "")
+
+ message(STATUS "list_prerequisites '${file_full}' 0 0 1")
+ list_prerequisites("${file_full}" 0 0 1)
+ message(STATUS "")
+
+ message(STATUS "list_prerequisites '${file_full}' 0 1 0")
+ list_prerequisites("${file_full}" 0 1 0)
+ message(STATUS "")
+
+ message(STATUS "list_prerequisites '${file_full}' 0 1 1")
+ list_prerequisites("${file_full}" 0 1 1)
+ message(STATUS "")
+
+ message(STATUS "list_prerequisites '${file_full}' 1 0 0")
+ list_prerequisites("${file_full}" 1 0 0)
+ message(STATUS "")
+
+ message(STATUS "list_prerequisites '${file_full}' 1 0 1")
+ list_prerequisites("${file_full}" 1 0 1)
+ message(STATUS "")
+
+ message(STATUS "list_prerequisites '${file_full}' 1 1 0")
+ list_prerequisites("${file_full}" 1 1 0)
+ message(STATUS "")
+
+ message(STATUS "list_prerequisites '${file_full}' 1 1 1")
+ list_prerequisites("${file_full}" 1 1 1)
+ message(STATUS "")
+
+ message(STATUS "=============================================================================")
+ message(STATUS "")
+endfunction()
+
+
+function(test_cmake_executables)
+ message(STATUS "=============================================================================")
+ message(STATUS "Loop over all executable files in the same directory with CMake")
+ message(STATUS "")
+
+ get_filename_component(cmake_bin_dir "${CMAKE_COMMAND}" PATH)
+ list_prerequisites_by_glob(GLOB "${cmake_bin_dir}/*" 0 0 1)
+endfunction()
+
+
+message(STATUS "=============================================================================")
+message(STATUS "Simplest test - list all the direct prerequisites of CMake itself")
+message(STATUS "")
+list_prerequisites("${CMAKE_COMMAND}" 0 0 1)
+message(STATUS "")
+
+message(STATUS "=============================================================================")
+string(LENGTH "$ENV{PATH}" PATH_LENGTH_BEGIN)
+message(STATUS "Begin PATH length is: ${PATH_LENGTH_BEGIN}")
+message(STATUS "")
+
+
+# Leave the code for these tests in here, but turn them off by default... they
+# take longer than they're worth during development...
+#
+set(do_testdefaults 0)
+if(do_testdefaults)
+ message(STATUS "=============================================================================")
+ message(STATUS "Test default argument values to list_prerequisites function...")
+ message(STATUS "")
+ list_prerequisites("${CMAKE_COMMAND}")
+ message(STATUS "")
+endif()
+
+
+set(do_stresstest 0)
+if(do_stresstest)
+ message(STATUS "=============================================================================")
+ message(STATUS "stresstest_list_prerequisites with CMake itself...")
+ message(STATUS "")
+ stresstest_list_prerequisites("${CMAKE_COMMAND}")
+ message(STATUS "")
+endif()
+
+
+test_cmake_executables()
+
+
+message(STATUS "=============================================================================")
+message(STATUS "Test overriding 'gp_tool' with bogus value")
+message(STATUS "")
+set(gp_tool "bogus")
+list_prerequisites("${CMAKE_COMMAND}" 0 0 0)
+set(gp_tool)
+message(STATUS "")
+
+
+message(STATUS "=============================================================================")
+message(STATUS "Test overriding 'gp_tool' with value unlikely to be found")
+message(STATUS "")
+if(APPLE)
+ set(gp_tool "dumpbin")
+else()
+ set(gp_tool "otool")
+endif()
+set(gp_cmd "gp_cmd-NOTFOUND")
+list_prerequisites("${CMAKE_COMMAND}" 0 0 0)
+set(gp_cmd)
+set(gp_tool)
+message(STATUS "")
+
+
+message(STATUS "=============================================================================")
+message(STATUS "All variables: (Make sure functions/macros are not leaving stuff around...")
+message(STATUS " Only variables predefined by CMake and defined in this")
+message(STATUS " test script file should be listed here...)")
+message(STATUS "")
+get_cmake_property(vs VARIABLES)
+foreach(v ${vs})
+ message(STATUS "${v}='${${v}}'")
+endforeach()
+message(STATUS "")
+
+message(STATUS "=============================================================================")
+string(LENGTH "$ENV{PATH}" PATH_LENGTH_END)
+message(STATUS "Final PATH length is: ${PATH_LENGTH_END}")
+
+if(PATH_LENGTH_END GREATER ${PATH_LENGTH_BEGIN})
+ message(FATAL_ERROR "list_prerequisties is endlessly appending the path of gp_tool to the PATH.")
+endif()
+message(STATUS "")
+
+
+message(STATUS "=============================================================================")
+message(STATUS "End of test")
+message(STATUS "")
diff --git a/Tests/CMakeTests/GetProperty-Bad-Argument.cmake b/Tests/CMakeTests/GetProperty-Bad-Argument.cmake
new file mode 100644
index 0000000000..382dabb50b
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-Bad-Argument.cmake
@@ -0,0 +1 @@
+get_property(FOO GLOBAL PROPERTY FOO FOO)
diff --git a/Tests/CMakeTests/GetProperty-Bad-Directory.cmake b/Tests/CMakeTests/GetProperty-Bad-Directory.cmake
new file mode 100644
index 0000000000..cdbfa807c2
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-Bad-Directory.cmake
@@ -0,0 +1 @@
+get_property(FOO DIRECTORY NonExistentSubDir PROPERTY FOO)
diff --git a/Tests/CMakeTests/GetProperty-Bad-Scope.cmake b/Tests/CMakeTests/GetProperty-Bad-Scope.cmake
new file mode 100644
index 0000000000..ea8566b50f
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-Bad-Scope.cmake
@@ -0,0 +1 @@
+get_property(FOO FOO FOO)
diff --git a/Tests/CMakeTests/GetProperty-Bad-Target.cmake b/Tests/CMakeTests/GetProperty-Bad-Target.cmake
new file mode 100644
index 0000000000..9992dabed4
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-Bad-Target.cmake
@@ -0,0 +1 @@
+get_property(FOO TARGET FOO PROPERTY FOO)
diff --git a/Tests/CMakeTests/GetProperty-Bad-Test.cmake b/Tests/CMakeTests/GetProperty-Bad-Test.cmake
new file mode 100644
index 0000000000..44bf3ebc54
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-Bad-Test.cmake
@@ -0,0 +1 @@
+get_property(FOO TEST FOO PROPERTY FOO)
diff --git a/Tests/CMakeTests/GetProperty-Global-Name.cmake b/Tests/CMakeTests/GetProperty-Global-Name.cmake
new file mode 100644
index 0000000000..497700cb3b
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-Global-Name.cmake
@@ -0,0 +1 @@
+get_property(FOO GLOBAL FOO PROPERTY FOO)
diff --git a/Tests/CMakeTests/GetProperty-Missing-Argument.cmake b/Tests/CMakeTests/GetProperty-Missing-Argument.cmake
new file mode 100644
index 0000000000..f0d004dc49
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-Missing-Argument.cmake
@@ -0,0 +1 @@
+get_property()
diff --git a/Tests/CMakeTests/GetProperty-No-Cache.cmake b/Tests/CMakeTests/GetProperty-No-Cache.cmake
new file mode 100644
index 0000000000..9719fe775b
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-No-Cache.cmake
@@ -0,0 +1 @@
+get_property(FOO CACHE PROPERTY FOO)
diff --git a/Tests/CMakeTests/GetProperty-No-Property.cmake b/Tests/CMakeTests/GetProperty-No-Property.cmake
new file mode 100644
index 0000000000..bee230d9b5
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-No-Property.cmake
@@ -0,0 +1 @@
+get_property(FOO GLOBAL PROPERTY)
diff --git a/Tests/CMakeTests/GetProperty-No-Source.cmake b/Tests/CMakeTests/GetProperty-No-Source.cmake
new file mode 100644
index 0000000000..89773c810b
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-No-Source.cmake
@@ -0,0 +1 @@
+get_property(FOO SOURCE PROPERTY FOO)
diff --git a/Tests/CMakeTests/GetProperty-No-Target.cmake b/Tests/CMakeTests/GetProperty-No-Target.cmake
new file mode 100644
index 0000000000..8f1fa23af5
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-No-Target.cmake
@@ -0,0 +1 @@
+get_property(FOO TARGET PROPERTY FOO)
diff --git a/Tests/CMakeTests/GetProperty-No-Test.cmake b/Tests/CMakeTests/GetProperty-No-Test.cmake
new file mode 100644
index 0000000000..045bd56ecc
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-No-Test.cmake
@@ -0,0 +1 @@
+get_property(FOO TEST PROPERTY FOO)
diff --git a/Tests/CMakeTests/GetProperty-Variable-Name.cmake b/Tests/CMakeTests/GetProperty-Variable-Name.cmake
new file mode 100644
index 0000000000..9190f80ad9
--- /dev/null
+++ b/Tests/CMakeTests/GetProperty-Variable-Name.cmake
@@ -0,0 +1 @@
+get_property(FOO VARIABLE FOO PROPERTY FOO)
diff --git a/Tests/CMakeTests/GetPropertyTest.cmake.in b/Tests/CMakeTests/GetPropertyTest.cmake.in
new file mode 100644
index 0000000000..e99193eb18
--- /dev/null
+++ b/Tests/CMakeTests/GetPropertyTest.cmake.in
@@ -0,0 +1,112 @@
+include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
+
+get_property(FOO_BRIEF GLOBAL PROPERTY FOO BRIEF_DOCS)
+get_property(FOO_FULL GLOBAL PROPERTY FOO FULL_DOCS)
+
+if (NOT FOO_BRIEF STREQUAL "NOTFOUND")
+ message(SEND_ERROR "property FOO has BRIEF_DOCS set to '${FOO_BRIEF}'")
+endif ()
+
+if (NOT FOO_FULL STREQUAL "NOTFOUND")
+ message(SEND_ERROR "property FOO has FULL_DOCS set to '${FOO_FULL}'")
+endif ()
+
+set(test_var alpha)
+get_property(result VARIABLE PROPERTY test_var)
+if(NOT result STREQUAL "alpha")
+ message(SEND_ERROR "bad value of VARIABLE PROPERTY test_var: got '${result}' instead of 'alpha'")
+endif()
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/../RegexEscapeString.cmake")
+REGEX_ESCAPE_STRING(CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
+
+set(Missing-Argument-RESULT 1)
+set(Missing-Argument-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-Missing-Argument.cmake:1 \\(get_property\\):.*get_property called with incorrect number of arguments.*")
+
+check_cmake_test(GetProperty
+ Missing-Argument
+)
+
+set(Bad-Scope-RESULT 1)
+set(Bad-Scope-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-Bad-Scope.cmake:1 \\(get_property\\):.*get_property given invalid scope FOO\\..*")
+
+check_cmake_test(GetProperty
+ Bad-Scope
+)
+
+set(Bad-Argument-RESULT 1)
+set(Bad-Argument-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-Bad-Argument.cmake:1 \\(get_property\\):.*get_property given invalid argument \"FOO\"\\..*")
+
+check_cmake_test(GetProperty
+ Bad-Argument
+)
+
+set(No-Property-RESULT 1)
+set(No-Property-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-No-Property.cmake:1 \\(get_property\\):.*get_property not given a PROPERTY <name> argument\\..*")
+
+check_cmake_test(GetProperty
+ No-Property
+)
+
+set(Global-Name-RESULT 1)
+set(Global-Name-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-Global-Name.cmake:1 \\(get_property\\):.*get_property given name for GLOBAL scope\\..*")
+
+check_cmake_test(GetProperty
+ Global-Name
+)
+
+set(Bad-Directory-RESULT 1)
+set(Bad-Directory-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-Bad-Directory.cmake:1 \\(get_property\\):.*get_property DIRECTORY scope provided but requested directory was not.*found\\..*")
+
+check_cmake_test(GetProperty
+ Bad-Directory
+)
+
+set(No-Target-RESULT 1)
+set(No-Target-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-No-Target.cmake:1 \\(get_property\\):.*get_property not given name for TARGET scope\\..*")
+
+check_cmake_test(GetProperty
+ No-Target
+)
+
+set(Bad-Target-RESULT 1)
+set(Bad-Target-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-Bad-Target.cmake:1 \\(get_property\\):.*get_property could not find TARGET FOO\\..*")
+
+check_cmake_test(GetProperty
+ Bad-Target
+)
+
+set(No-Source-RESULT 1)
+set(No-Source-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-No-Source.cmake:1 \\(get_property\\):.*get_property not given name for SOURCE scope\\..*")
+
+check_cmake_test(GetProperty
+ No-Source
+)
+
+set(No-Test-RESULT 1)
+set(No-Test-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-No-Test.cmake:1 \\(get_property\\):.*get_property not given name for TEST scope\\..*")
+
+check_cmake_test(GetProperty
+ No-Test
+)
+
+set(Bad-Test-RESULT 1)
+set(Bad-Test-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-Bad-Test.cmake:1 \\(get_property\\):.*get_property given TEST name that does not exist: FOO.*")
+
+check_cmake_test(GetProperty
+ Bad-Test
+)
+
+set(Variable-Name-RESULT 1)
+set(Variable-Name-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-Variable-Name.cmake:1 \\(get_property\\):.*get_property given name for VARIABLE scope\\..*")
+
+check_cmake_test(GetProperty
+ Variable-Name
+)
+
+set(No-Cache-RESULT 1)
+set(No-Cache-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?GetProperty-No-Cache.cmake:1 \\(get_property\\):.*get_property not given name for CACHE scope\\..*")
+
+check_cmake_test(GetProperty
+ No-Cache
+)
diff --git a/Tests/CMakeTests/If-Invalid-Argument.cmake b/Tests/CMakeTests/If-Invalid-Argument.cmake
new file mode 100644
index 0000000000..b4fb97f419
--- /dev/null
+++ b/Tests/CMakeTests/If-Invalid-Argument.cmake
@@ -0,0 +1,2 @@
+if (NOT foo bar STREQUAL "foo bar")
+endif()
diff --git a/Tests/CMakeTests/IfTest.cmake.in b/Tests/CMakeTests/IfTest.cmake.in
new file mode 100644
index 0000000000..74b8e32b52
--- /dev/null
+++ b/Tests/CMakeTests/IfTest.cmake.in
@@ -0,0 +1,169 @@
+# Prepare variable definitions.
+set(VAR_UNDEFINED)
+set(VAR_PATH /some/path/to/a/file.txt)
+set(FALSE_NAMES OFF NO FALSE N FOO-NOTFOUND IGNORE Off No False Ignore off n no false ignore)
+set(TRUE_NAMES ON YES TRUE Y On Yes True on yes true y)
+foreach(_arg "" 0 1 2 ${TRUE_NAMES} ${FALSE_NAMES})
+ set(VAR_${_arg} "${_arg}")
+endforeach()
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/../RegexEscapeString.cmake")
+REGEX_ESCAPE_STRING(CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
+
+macro(test_vars _old)
+ # Variables set to false or not set.
+ foreach(_var "" 0 ${FALSE_NAMES} UNDEFINED)
+ if(VAR_${_var})
+ message(FATAL_ERROR "${_old}if(VAR_${_var}) is true!")
+ else()
+ message(STATUS "${_old}if(VAR_${_var}) is false")
+ endif()
+
+ if(NOT VAR_${_var})
+ message(STATUS "${_old}if(NOT VAR_${_var}) is true")
+ else()
+ message(FATAL_ERROR "${_old}if(NOT VAR_${_var}) is false!")
+ endif()
+ endforeach()
+
+ # Variables set to true.
+ foreach(_var 1 2 ${TRUE_NAMES} PATH)
+ if(VAR_${_var})
+ message(STATUS "${_old}if(VAR_${_var}) is true")
+ else()
+ message(FATAL_ERROR "${_old}if(VAR_${_var}) is false!")
+ endif()
+
+ if(NOT VAR_${_var})
+ message(FATAL_ERROR "${_old}if(NOT VAR_${_var}) is true!")
+ else()
+ message(STATUS "${_old}if(NOT VAR_${_var}) is false")
+ endif()
+ endforeach()
+endmacro()
+
+#-----------------------------------------------------------------------------
+# Test the OLD behavior of CMP0012.
+cmake_policy(SET CMP0012 OLD)
+
+# False constants not recognized (still false).
+foreach(_false "" ${FALSE_NAMES})
+ if("${_false}")
+ message(FATAL_ERROR "OLD if(${_false}) is true!")
+ else()
+ message(STATUS "OLD if(${_false}) is false")
+ endif()
+
+ if(NOT "${_false}")
+ message(STATUS "OLD if(NOT ${_false}) is true")
+ else()
+ message(FATAL_ERROR "OLD if(NOT ${_false}) is false!")
+ endif()
+endforeach()
+
+# True constants not recognized.
+foreach(_false ${TRUE_NAMES})
+ if(${_false})
+ message(FATAL_ERROR "OLD if(${_false}) is true!")
+ else()
+ message(STATUS "OLD if(${_false}) is false")
+ endif()
+
+ if(NOT ${_false})
+ message(STATUS "OLD if(NOT ${_false}) is true")
+ else()
+ message(FATAL_ERROR "OLD if(NOT ${_false}) is false!")
+ endif()
+endforeach()
+
+# Numbers not recognized properly.
+foreach(_num 2 -2 2.0 -2.0 2x -2x)
+ if(${_num})
+ message(FATAL_ERROR "OLD if(${_num}) is true!")
+ else()
+ message(STATUS "OLD if(${_num}) is false")
+ endif()
+
+ if(NOT ${_num})
+ message(FATAL_ERROR "OLD if(NOT ${_num}) is true!")
+ else()
+ message(STATUS "OLD if(NOT ${_num}) is false")
+ endif()
+endforeach()
+
+test_vars("OLD ")
+
+#-----------------------------------------------------------------------------
+
+# Test the NEW behavior of CMP0012.
+cmake_policy(SET CMP0012 NEW)
+
+# Test false constants.
+foreach(_false "" 0 ${FALSE_NAMES})
+ if("${_false}")
+ message(FATAL_ERROR "if(${_false}) is true!")
+ else()
+ message(STATUS "if(${_false}) is false")
+ endif()
+
+ if(NOT "${_false}")
+ message(STATUS "if(NOT ${_false}) is true")
+ else()
+ message(FATAL_ERROR "if(NOT ${_false}) is false!")
+ endif()
+endforeach()
+
+# Test true constants.
+foreach(_true 1 ${TRUE_NAMES})
+ if(${_true})
+ message(STATUS "if(${_true}) is true")
+ else()
+ message(FATAL_ERROR "if(${_true}) is false!")
+ endif()
+
+ if(NOT ${_true})
+ message(FATAL_ERROR "if(NOT ${_true}) is true!")
+ else()
+ message(STATUS "if(NOT ${_true}) is false")
+ endif()
+endforeach()
+
+# Numbers recognized properly.
+foreach(_num 2 -2 2.0 -2.0)
+ if(${_num})
+ message(STATUS "if(${_num}) is true")
+ else()
+ message(FATAL_ERROR "if(${_num}) is false!")
+ endif()
+
+ if(NOT ${_num})
+ message(FATAL_ERROR "if(NOT ${_num}) is true!")
+ else()
+ message(STATUS "if(NOT ${_num}) is false")
+ endif()
+endforeach()
+
+# Bad numbers not recognized.
+foreach(_bad 2x -2x)
+ if(${_bad})
+ message(FATAL_ERROR "if(${_bad}) is true!")
+ else()
+ message(STATUS "if(${_bad}) is false")
+ endif()
+
+ if(NOT ${_bad})
+ message(STATUS "if(NOT ${_bad}) is true")
+ else()
+ message(FATAL_ERROR "if(NOT ${_bad}) is false!")
+ endif()
+endforeach()
+
+test_vars("")
+
+set(Invalid-Argument-RESULT 1)
+set(Invalid-Argument-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?If-Invalid-Argument.cmake:1 \\(if\\):.*Unknown arguments specified.*")
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
+check_cmake_test(If
+ Invalid-Argument
+)
diff --git a/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in b/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in
new file mode 100644
index 0000000000..055b183d6d
--- /dev/null
+++ b/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in
@@ -0,0 +1,529 @@
+# This is not supposed to be included by user code, but we need to
+# test it.
+include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
+
+#-----------------------------------------------------------------------------
+# Linux
+
+# gcc dummy.c -v
+set(linux64_gcc_text " /usr/lib/gcc/x86_64-linux-gnu/4.3.3/collect2 --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../.. -L/usr/lib/x86_64-linux-gnu /tmp/ccEO9iux.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crtn.o")
+set(linux64_gcc_libs "c")
+set(linux64_gcc_dirs "/usr/lib/gcc/x86_64-linux-gnu/4.3.3;/usr/lib;/lib;/usr/lib/x86_64-linux-gnu")
+list(APPEND platforms linux64_gcc)
+
+# g++ dummy.cxx -v
+set(linux64_g++_text " /usr/lib/gcc/x86_64-linux-gnu/4.3.3/collect2 --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../.. -L/usr/lib/x86_64-linux-gnu /tmp/ccalRBlq.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crtn.o")
+set(linux64_g++_libs "stdc++;m;c")
+set(linux64_g++_dirs "/usr/lib/gcc/x86_64-linux-gnu/4.3.3;/usr/lib;/lib;/usr/lib/x86_64-linux-gnu")
+list(APPEND platforms linux64_g++)
+
+# f95 dummy.f -v
+set(linux64_f95_text " /usr/lib/gcc/x86_64-linux-gnu/4.3.3/collect2 --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../.. -L/usr/lib/x86_64-linux-gnu /tmp/ccAVcN7N.o -lgfortranbegin -lgfortran -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crtn.o")
+set(linux64_f95_libs "gfortranbegin;gfortran;m;c")
+set(linux64_f95_dirs "/usr/lib/gcc/x86_64-linux-gnu/4.3.3;/usr/lib;/lib;/usr/lib/x86_64-linux-gnu")
+list(APPEND platforms linux64_f95)
+
+# suncc dummy.c '-#'
+set(linux64_suncc_text "/usr/bin/ld --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /opt/sun/sunstudio12/prod/lib/amd64/crti.o /opt/sun/sunstudio12/prod/lib/amd64/crt1x.o /opt/sun/sunstudio12/prod/lib/amd64/values-xa.o dummy.o -Y \"/opt/sun/sunstudio12/prod/lib/amd64:/lib64:/usr/lib64\" -Qy -lc /opt/sun/sunstudio12/prod/lib/amd64/libc_supp.a /opt/sun/sunstudio12/prod/lib/amd64/crtn.o")
+set(linux64_suncc_libs "c;/opt/sun/sunstudio12/prod/lib/amd64/libc_supp.a")
+set(linux64_suncc_dirs "/opt/sun/sunstudio12/prod/lib/amd64;/lib64;/usr/lib64")
+list(APPEND platforms linux64_suncc)
+
+# sunCC dummy.cxx -v
+set(linux64_sunCC_text "/opt/sun/sunstudio12/prod/lib/amd64/ld -u __1cH__CimplKcplus_init6F_v_ --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -R/opt/sun/sunstudio12/lib/rw7/amd64:/opt/sun/sunstudio12/lib/amd64:/opt/sun/sunstudio12/rtlibs/amd64:/opt/sun/lib/rtlibs/amd64:/opt/SUNWspro/lib/amd64:/lib64:/usr/lib64 -o a.out /opt/sun/sunstudio12/prod/lib/amd64/crti.o /opt/sun/sunstudio12/prod/lib/amd64/CCrti.o /opt/sun/sunstudio12/prod/lib/amd64/crt1x.o -Y P,/opt/sun/sunstudio12/lib/rw7/amd64:/opt/sun/sunstudio12/lib/amd64:/opt/sun/sunstudio12/rtlibs/amd64:/opt/sun/sunstudio12/prod/lib/rw7/amd64:/opt/sun/sunstudio12/prod/lib/amd64:/lib64:/usr/lib64 dummy.o -lCstd -lCrun -lm -lc /opt/sun/sunstudio12/prod/lib/amd64/libc_supp.a /opt/sun/sunstudio12/prod/lib/amd64/CCrtn.o /opt/sun/sunstudio12/prod/lib/amd64/crtn.o >&/tmp/ld.04973.2.err")
+set(linux64_sunCC_libs "Cstd;Crun;m;c;/opt/sun/sunstudio12/prod/lib/amd64/libc_supp.a")
+set(linux64_sunCC_dirs "/opt/sun/sunstudio12/lib/rw7/amd64;/opt/sun/sunstudio12/lib/amd64;/opt/sun/sunstudio12/rtlibs/amd64;/opt/sun/sunstudio12/prod/lib/rw7/amd64;/opt/sun/sunstudio12/prod/lib/amd64;/lib64;/usr/lib64")
+list(APPEND platforms linux64_sunCC)
+
+# sunf90 dummy.f -v
+set(linux64_sunf90_text "/usr/bin/ld --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -R/opt/sun/sunstudio12/lib/amd64:/opt/sun/sunstudio12/rtlibs/amd64:/opt/sun/lib/rtlibs/amd64 -o a.out /opt/sun/sunstudio12/prod/lib/amd64/crti.o /opt/sun/sunstudio12/prod/lib/amd64/crt1x.o /opt/sun/sunstudio12/prod/lib/amd64/values-xi.o -Y P,/opt/sun/sunstudio12/lib/amd64:/opt/sun/sunstudio12/rtlibs/amd64:/opt/sun/sunstudio12/prod/lib/amd64:/lib64:/usr/lib64 dummy.o -lfui -lfai -lfsu -Bdynamic -lmtsk -lpthread -lm -lc /opt/sun/sunstudio12/prod/lib/amd64/libc_supp.a /opt/sun/sunstudio12/prod/lib/amd64/crtn.o")
+set(linux64_sunf90_libs "fui;fai;fsu;mtsk;pthread;m;c;/opt/sun/sunstudio12/prod/lib/amd64/libc_supp.a")
+set(linux64_sunf90_dirs "/opt/sun/sunstudio12/lib/amd64;/opt/sun/sunstudio12/rtlibs/amd64;/opt/sun/sunstudio12/prod/lib/amd64;/lib64;/usr/lib64")
+list(APPEND platforms linux64_sunf90)
+
+# icc dummy.c -v
+set(linux64_icc_text "ld /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbegin.o --eh-frame-hdr -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /tmp/iccBP8OfN.o -L/opt/compiler/intel/compiler/11.0/lib/intel64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../.. -L/lib64 -L/lib -L/usr/lib64 -L/usr/lib -Bstatic -limf -lsvml -Bdynamic -lm -Bstatic -lipgo -ldecimal -lirc -Bdynamic -lgcc_s -lgcc -Bstatic -lirc -Bdynamic -lc -lgcc_s -lgcc -Bstatic -lirc_s -Bdynamic -ldl -lc /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crtn.o")
+set(linux64_icc_libs "imf;svml;m;ipgo;decimal;irc;irc;c;irc_s;dl;c")
+set(linux64_icc_dirs "/opt/compiler/intel/compiler/11.0/lib/intel64;/usr/lib64/gcc/x86_64-suse-linux/4.1.2;/usr/lib64;/lib64;/usr/x86_64-suse-linux/lib;/lib;/usr/lib")
+list(APPEND platforms linux64_icc)
+
+# icxx dummy.cxx -v
+set(linux64_icxx_text "ld /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbegin.o --eh-frame-hdr -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /tmp/icpc270GoT.o -L/opt/compiler/intel/compiler/11.0/lib/intel64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../.. -L/lib64 -L/lib -L/usr/lib64 -L/usr/lib -Bstatic -limf -lsvml -Bdynamic -lm -Bstatic -lipgo -ldecimal -Bdynamic -lstdc++ -Bstatic -lirc -Bdynamic -lgcc_s -lgcc -Bstatic -lirc -Bdynamic -lc -lgcc_s -lgcc -Bstatic -lirc_s -Bdynamic -ldl -lc /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crtn.o")
+set(linux64_icxx_libs "imf;svml;m;ipgo;decimal;stdc++;irc;irc;c;irc_s;dl;c")
+set(linux64_icxx_dirs "/opt/compiler/intel/compiler/11.0/lib/intel64;/usr/lib64/gcc/x86_64-suse-linux/4.1.2;/usr/lib64;/lib64;/usr/x86_64-suse-linux/lib;/lib;/usr/lib")
+list(APPEND platforms linux64_icxx)
+
+# ifort dummy.f -v
+set(linux64_ifort_text "ld --eh-frame-hdr -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out -L/opt/compiler/intel/compiler/11.0/lib/intel64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../.. -L/lib64 -L/lib -L/usr/lib64 -L/usr/lib /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbegin.o /opt/compiler/intel/compiler/11.0/lib/intel64/for_main.o dum.cxx -Bstatic -lifport -lifcore -limf -lsvml -Bdynamic -lm -Bstatic -lipgo -lirc -Bdynamic -lpthread -lc -lgcc_s -lgcc -Bstatic -lirc_s -Bdynamic -ldl -lc /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crtn.o")
+set(linux64_ifort_libs "ifport;ifcore;imf;svml;m;ipgo;irc;pthread;c;irc_s;dl;c")
+set(linux64_ifort_dirs "/opt/compiler/intel/compiler/11.0/lib/intel64;/usr/lib64/gcc/x86_64-suse-linux/4.1.2;/usr/lib64;/lib64;/usr/x86_64-suse-linux/lib;/lib;/usr/lib")
+list(APPEND platforms linux64_ifort)
+
+# pgcc dummy.c -v
+set(linux64_pgcc_text "/usr/bin/ld /usr/lib64/crt1.o /usr/lib64/crti.o /opt/compiler/pgi/linux86-64/8.0-3/lib/trace_init.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbegin.o -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /opt/compiler/pgi/linux86-64/8.0-3/lib/pgi.ld -L/opt/compiler/pgi/linux86-64/8.0-3/lib -L/usr/lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 /tmp/pgcc7OscXa5ur7Zk.o -rpath /opt/compiler/pgi/linux86-64/8.0-3/lib -lnspgc -lpgc -lm -lgcc -lc -lgcc /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtend.o /usr/lib64/crtn.o")
+set(linux64_pgcc_libs "nspgc;pgc;m;c")
+set(linux64_pgcc_dirs "/opt/compiler/pgi/linux86-64/8.0-3/lib;/usr/lib64;/usr/lib64/gcc/x86_64-suse-linux/4.1.2")
+list(APPEND platforms linux64_pgcc)
+
+# pgCC dummy.cxx -v
+set(linux64_pgCC_text "/usr/bin/ld /usr/lib64/crt1.o /usr/lib64/crti.o /opt/compiler/pgi/linux86-64/8.0-3/lib/trace_init.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbegin.o -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /opt/compiler/pgi/linux86-64/8.0-3/lib/pgi.ld -L/opt/compiler/pgi/linux86-64/8.0-3/lib -L/usr/lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 /tmp/pgCCFhjcDt1fs1Ki.o -rpath /opt/compiler/pgi/linux86-64/8.0-3/lib -lstd -lC -lnspgc -lpgc -lm -lgcc -lc -lgcc /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtend.o /usr/lib64/crtn.o")
+set(linux64_pgCC_libs "std;C;nspgc;pgc;m;c")
+set(linux64_pgCC_dirs "/opt/compiler/pgi/linux86-64/8.0-3/lib;/usr/lib64;/usr/lib64/gcc/x86_64-suse-linux/4.1.2")
+list(APPEND platforms linux64_pgCC)
+
+# pgf90 dummy.f -v
+set(linux64_pgf90_text "/usr/bin/ld /usr/lib64/crt1.o /usr/lib64/crti.o /opt/compiler/pgi/linux86-64/8.0-3/lib/trace_init.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbegin.o /opt/compiler/pgi/linux86-64/8.0-3/lib/f90main.o -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /opt/compiler/pgi/linux86-64/8.0-3/lib/pgi.ld -L/opt/compiler/pgi/linux86-64/8.0-3/lib -L/usr/lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 /tmp/pgf90QOIc_eB9xY5h.o -rpath /opt/compiler/pgi/linux86-64/8.0-3/lib -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgf90rtl -lpgftnrtl -lnspgc -lpgc -lrt -lpthread -lm -lgcc -lc -lgcc /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtend.o /usr/lib64/crtn.o")
+set(linux64_pgf90_libs "pgf90;pgf90_rpm1;pgf902;pgf90rtl;pgftnrtl;nspgc;pgc;rt;pthread;m;c")
+set(linux64_pgf90_dirs "/opt/compiler/pgi/linux86-64/8.0-3/lib;/usr/lib64;/usr/lib64/gcc/x86_64-suse-linux/4.1.2")
+list(APPEND platforms linux64_pgf90)
+
+# nagfor dummy.f -Wl,-v
+set(linux64_nagfor_text " /usr/libexec/gcc/x86_64-redhat-linux/4.4.5/collect2 --no-add-needed --eh-frame-hdr --build-id -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.4.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.4.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../.. /usr/local/NAG/lib/f90_init.o /usr/local/NAG/lib/quickfit.o dummy.o -rpath /usr/local/NAG/lib /usr/local/NAG/lib/libf53.so /usr/local/NAG/lib/libf53.a -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.4.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../lib64/crtn.o")
+set(linux64_nagfor_libs "/usr/local/NAG/lib/f90_init.o;/usr/local/NAG/lib/quickfit.o;/usr/local/NAG/lib/libf53.a;m;c")
+set(linux64_nagfor_dirs "/usr/lib/gcc/x86_64-redhat-linux/4.4.5;/usr/lib64;/lib64;/usr/lib")
+set(linux64_nagfor_obj_regex "^/usr/local/NAG/lib")
+list(APPEND platforms linux64_nagfor)
+
+# absoft dummy.f -X -v
+set(linux64_absoft_text "collect2 version 4.4.5 (x86-64 Linux/ELF)
+/usr/bin/ld --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtbegin.o -L/opt/absoft11.1/lib64 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../.. /tmp/E3Bii1/dummy.o -v -laf90math -lafio -lamisc -labsoftmain -laf77math -lm -lmv -lpthread -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crtn.o")
+set(linux64_absoft_libs "af90math;afio;amisc;absoftmain;af77math;m;mv;pthread;c")
+set(linux64_absoft_dirs "/opt/absoft11.1/lib64;/usr/lib/gcc/x86_64-linux-gnu/4.4.5;/usr/lib;/lib")
+list(APPEND platforms linux64_absoft)
+
+# gcc dummy.c -v # in strange path
+set(linux64_test1_text "
+/this/might/match/as/a/linker/ld/but/it/is/not because the ld is not the last path component
+${linux64_gcc_text}")
+set(linux64_test1_libs "${linux64_gcc_libs}")
+set(linux64_test1_dirs "${linux64_gcc_dirs}")
+list(APPEND platforms linux64_test1)
+
+# sunCC dummy.cxx -v # extra slashes
+set(linux64_test2_text "/usr/bin/ld --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /opt/sun/sunstudio12/prod/lib/amd64//crti.o /opt/sun/sunstudio12/prod/lib/amd64/crt1x.o /opt/sun/sunstudio12/prod/lib/amd64/values-xa.o dummy.o -Y \"/opt/sun/sunstudio12/prod/lib//amd64:/lib64:/usr//lib64\" -Qy -lc /opt/sun/sunstudio12/prod/lib/amd64//libc_supp.a /opt/sun/sunstudio12/prod/lib/amd64/crtn.o")
+set(linux64_test2_libs "c;/opt/sun/sunstudio12/prod/lib/amd64/libc_supp.a")
+set(linux64_test2_dirs "/opt/sun/sunstudio12/prod/lib/amd64;/lib64;/usr/lib64")
+list(APPEND platforms linux64_test2)
+
+#-----------------------------------------------------------------------------
+# Mac
+
+# gcc -arch i686 dummy.c -v -Wl,-v
+set(mac_i686_gcc_Wlv_text " /usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2 -dynamic -arch i386 -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.6.o -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/tmp//ccnhXAGL.o -lSystem -lgcc -lSystem
+collect2 version 4.2.1 (Apple Inc. build 5646) (i686 Darwin)
+/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld -dynamic -arch i386 -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.6.o -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/tmp//ccSiuUhD.o -v -lSystem -lgcc -lSystem
+@(#)PROGRAM:ld PROJECT:ld64-95.2.12
+Library search paths:
+ /usr/lib/i686-apple-darwin10/4.2.1
+ /usr/lib/gcc/i686-apple-darwin10/4.2.1
+ /usr/lib/gcc/i686-apple-darwin10/4.2.1
+ /usr/lib/i686-apple-darwin10/4.2.1
+ /usr/lib
+ /usr/lib
+ /usr/local/lib
+Framework search paths:
+ /Library/Frameworks/
+ /System/Library/Frameworks/")
+set(mac_i686_gcc_Wlv_libs "")
+set(mac_i686_gcc_Wlv_dirs "/usr/lib/i686-apple-darwin10/4.2.1;/usr/lib/gcc/i686-apple-darwin10/4.2.1;/usr/lib;/usr/local/lib")
+set(mac_i686_gcc_Wlv_fwks "/Library/Frameworks;/System/Library/Frameworks")
+list(APPEND platforms mac_i686_gcc_Wlv)
+
+# gcc -arch i686 dummy.c -v
+set(mac_i686_gcc_text " /usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2 -dynamic -arch i386 -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.6.o -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/tmp//ccnhXAGL.o -lSystem -lgcc -lSystem")
+set(mac_i686_gcc_libs "")
+set(mac_i686_gcc_dirs "/usr/lib/i686-apple-darwin10/4.2.1;/usr/lib/gcc/i686-apple-darwin10/4.2.1;/usr/lib")
+list(APPEND platforms mac_i686_gcc)
+
+# g++ -arch i686 dummy.cxx -v -Wl,-v
+set(mac_i686_g++_Wlv_text " /usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2 -dynamic -arch i386 -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.6.o -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/tmp//ccEXXICh.o -lstdc++ -lSystem -lgcc -lSystem
+collect2 version 4.2.1 (Apple Inc. build 5646) (i686 Darwin)
+/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld -dynamic -arch i386 -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.6.o -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/tmp//ccWrBoVl.o -v -lstdc++ -lSystem -lgcc -lSystem
+@(#)PROGRAM:ld PROJECT:ld64-95.2.12
+Library search paths:
+ /usr/lib/i686-apple-darwin10/4.2.1
+ /usr/lib/gcc/i686-apple-darwin10/4.2.1
+ /usr/lib/gcc/i686-apple-darwin10/4.2.1
+ /usr/lib/i686-apple-darwin10/4.2.1
+ /usr/lib
+ /usr/lib
+ /usr/local/lib
+Framework search paths:
+ /Library/Frameworks/
+ /System/Library/Frameworks/")
+set(mac_i686_g++_Wlv_libs "stdc++")
+set(mac_i686_g++_Wlv_dirs "/usr/lib/i686-apple-darwin10/4.2.1;/usr/lib/gcc/i686-apple-darwin10/4.2.1;/usr/lib;/usr/local/lib")
+set(mac_i686_g++_Wlv_fwks "/Library/Frameworks;/System/Library/Frameworks")
+list(APPEND platforms mac_i686_g++_Wlv)
+
+# g++ -arch i686 dummy.cxx -v
+set(mac_i686_g++_text " /usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2 -dynamic -arch i386 -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.6.o -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/tmp//ccEXXICh.o -lstdc++ -lSystem -lgcc -lSystem")
+set(mac_i686_g++_libs "stdc++")
+set(mac_i686_g++_dirs "/usr/lib/i686-apple-darwin10/4.2.1;/usr/lib/gcc/i686-apple-darwin10/4.2.1;/usr/lib")
+list(APPEND platforms mac_i686_g++)
+
+# gfortran dummy.f -v -Wl,-v
+set(mac_i686_gfortran_Wlv_text " /usr/local/libexec/gcc/i386-apple-darwin9.7.0/4.4.1/collect2 -dynamic -arch i386 -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.5.o -L/usr/local/lib/gcc/i386-apple-darwin9.7.0/4.4.1 -L/usr/local/lib/gcc/i386-apple-darwin9.7.0/4.4.1/../../.. /var/tmp//cc9zXNax.o -v -lgfortranbegin -lgfortran -lgcc_s.10.5 -lgcc -lSystem
+collect2 version 4.4.1 20090623 (prerelease) (i686 Darwin)
+/usr/bin/ld -dynamic -arch i386 -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.5.o -L/usr/local/lib/gcc/i386-apple-darwin9.7.0/4.4.1 -L/usr/local/lib/gcc/i386-apple-darwin9.7.0/4.4.1/../../.. /var/tmp//cc9zXNax.o -v -lgfortranbegin -lgfortran -lgcc_s.10.5 -lgcc -lSystem
+@(#)PROGRAM:ld PROJECT:ld64-95.2.12
+Library search paths:
+ /usr/local/lib/gcc/i386-apple-darwin9.7.0/4.4.1
+ /usr/local/lib
+ /usr/lib
+ /usr/local/lib
+Framework search paths:
+ /Library/Frameworks/
+ /System/Library/Frameworks/")
+set(mac_i686_gfortran_Wlv_libs "gfortranbegin;gfortran")
+set(mac_i686_gfortran_Wlv_dirs "/usr/local/lib/gcc/i386-apple-darwin9.7.0/4.4.1;/usr/local/lib;/usr/lib")
+set(mac_i686_gfortran_Wlv_fwks "/Library/Frameworks;/System/Library/Frameworks")
+list(APPEND platforms mac_i686_gfortran_Wlv)
+
+# gfortran dummy.f -v
+set(mac_i686_gfortran_text " /usr/libexec/gcc/i386-apple-darwin9.7.0/4.4.1/collect2 -dynamic -arch i386 -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.5.o -L/usr/lib/gcc/i386-apple-darwin9.7.0/4.4.1 -L/usr/lib/gcc -L/usr/lib/gcc/i386-apple-darwin9.7.0/4.4.1/../../.. /var/tmp//ccgqbX5P.o -lgfortranbegin -lgfortran -lgcc_s.10.5 -lgcc -lSystem")
+set(mac_i686_gfortran_libs "gfortranbegin;gfortran")
+set(mac_i686_gfortran_dirs "/usr/lib/gcc/i386-apple-darwin9.7.0/4.4.1;/usr/lib/gcc;/usr/lib")
+list(APPEND platforms mac_i686_gfortran)
+
+# gcc -arch ppc dummy.c -v -Wl,-v
+set(mac_ppc_gcc_Wlv_text " /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/collect2 -dynamic -arch ppc -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.5.o -L/usr/lib/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../../powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../.. /var/tmp//cclziQY4.o -v -lgcc -lSystemStubs -lSystem
+collect2 version 4.2.1 (Apple Inc. build 5646) (Darwin/PowerPC)
+/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/ld -dynamic -arch ppc -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.5.o -L/usr/lib/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../../powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../.. /var/tmp//cclziQY4.o -v -lgcc -lSystemStubs -lSystem
+@(#)PROGRAM:ld PROJECT:ld64-95.2.12
+Library search paths:
+ /usr/lib/powerpc-apple-darwin10/4.2.1
+ /usr/lib/gcc/powerpc-apple-darwin10/4.2.1
+ /usr/lib/gcc/powerpc-apple-darwin10/4.2.1
+ /usr/lib/powerpc-apple-darwin10/4.2.1
+ /usr/lib
+ /usr/lib
+ /usr/local/lib
+Framework search paths:
+ /Library/Frameworks/
+ /System/Library/Frameworks/")
+set(mac_ppc_gcc_Wlv_libs "")
+set(mac_ppc_gcc_Wlv_dirs "/usr/lib/powerpc-apple-darwin10/4.2.1;/usr/lib/gcc/powerpc-apple-darwin10/4.2.1;/usr/lib;/usr/local/lib")
+set(mac_ppc_gcc_Wlv_fwks "/Library/Frameworks;/System/Library/Frameworks")
+list(APPEND platforms mac_ppc_gcc_Wlv)
+
+# gcc -arch ppc dummy.c -v
+set(mac_ppc_gcc_text " /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/collect2 -dynamic -arch ppc -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.5.o -L/usr/lib/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../../powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../.. /var/tmp//ccdcolsP.o -lgcc -lSystemStubs -lSystem")
+set(mac_ppc_gcc_libs "")
+set(mac_ppc_gcc_dirs "/usr/lib/powerpc-apple-darwin10/4.2.1;/usr/lib/gcc/powerpc-apple-darwin10/4.2.1;/usr/lib")
+list(APPEND platforms mac_ppc_gcc)
+
+# g++ -arch ppc dummy.cxx -v -Wl,-v
+set(mac_ppc_g++_Wlv_text " /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/collect2 -dynamic -arch ppc -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.5.o -L/usr/lib/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../../powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../.. /var/tmp//ccaFTkwq.o -v -lstdc++ -lgcc -lSystemStubs -lSystem
+collect2 version 4.2.1 (Apple Inc. build 5646) (Darwin/PowerPC)
+/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/ld -dynamic -arch ppc -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.5.o -L/usr/lib/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../../powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../.. /var/tmp//ccaFTkwq.o -v -lstdc++ -lgcc -lSystemStubs -lSystem
+@(#)PROGRAM:ld PROJECT:ld64-95.2.12
+Library search paths:
+ /usr/lib/powerpc-apple-darwin10/4.2.1
+ /usr/lib/gcc/powerpc-apple-darwin10/4.2.1
+ /usr/lib/gcc/powerpc-apple-darwin10/4.2.1
+ /usr/lib/powerpc-apple-darwin10/4.2.1
+ /usr/lib
+ /usr/lib
+ /usr/local/lib
+Framework search paths:
+ /Library/Frameworks/
+ /System/Library/Frameworks/")
+set(mac_ppc_g++_Wlv_libs "stdc++")
+set(mac_ppc_g++_Wlv_dirs "/usr/lib/powerpc-apple-darwin10/4.2.1;/usr/lib/gcc/powerpc-apple-darwin10/4.2.1;/usr/lib;/usr/local/lib")
+set(mac_ppc_g++_Wlv_fwks "/Library/Frameworks;/System/Library/Frameworks")
+list(APPEND platforms mac_ppc_g++_Wlv)
+
+# g++ -arch ppc dummy.cxx -v
+set(mac_ppc_g++_text " /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/collect2 -dynamic -arch ppc -macosx_version_min 10.6.0 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.5.o -L/usr/lib/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../../powerpc-apple-darwin10/4.2.1 -L/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/../../.. /var/tmp//ccbjB6Lj.o -lstdc++ -lgcc -lSystemStubs -lSystem")
+set(mac_ppc_g++_libs "stdc++")
+set(mac_ppc_g++_dirs "/usr/lib/powerpc-apple-darwin10/4.2.1;/usr/lib/gcc/powerpc-apple-darwin10/4.2.1;/usr/lib")
+list(APPEND platforms mac_ppc_g++)
+
+# absoft dummy.f -X -v
+set(mac_absoft_text "collect2 version 4.2.1 (Apple Inc. build 5664) (i686 Darwin)
+/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld -dynamic -arch i386 -macosx_version_min 10.6.6 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.6.o -L/Applications/Absoft11.1/lib -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/folders/04/04+Djjm8GZWBmuEdp2Gsw++++TM/-Tmp-//bTAoJc/dummy.o -v -Y 10 -laf90math -lafio -lamisc -labsoftmain -laf77math -lm -lmv -lSystem -lgcc -lSystem
+")
+set(mac_absoft_libs "af90math;afio;amisc;absoftmain;af77math;m;mv")
+set(mac_absoft_dirs "/Applications/Absoft11.1/lib;/usr/lib/i686-apple-darwin10/4.2.1;/usr/lib/gcc/i686-apple-darwin10/4.2.1;/usr/lib")
+list(APPEND platforms mac_absoft)
+
+#-----------------------------------------------------------------------------
+# Sun
+
+# cc dummy.c '-#'/
+set(sun_cc_text "/usr/ccs/bin/ld /opt/SUNWspro/prod/lib/crti.o /opt/SUNWspro/prod/lib/crt1.o /opt/SUNWspro/prod/lib/misalign.o /opt/SUNWspro/prod/lib/values-xa.o dummy.o -Y \"P,/opt/SUNWspro/prod/lib/v8plus:/opt/SUNWspro/prod/lib:/usr/ccs/lib:/lib:/usr/lib\" -Qy -lc /opt/SUNWspro/prod/lib/crtn.o")
+set(sun_cc_libs "c")
+set(sun_cc_dirs "/opt/SUNWspro/prod/lib/v8plus;/opt/SUNWspro/prod/lib;/usr/ccs/lib;/lib;/usr/lib")
+list(APPEND platforms sun_cc)
+
+# CC dummy.cxx -v
+set(sun_CC_text "/usr/ccs/bin/ld -u __1cH__CimplKcplus_init6F_v_ -zld32=-S/opt/SUNWspro/prod/lib/libldstab_ws.so -zld64=-S/opt/SUNWspro/prod/lib/v9/libldstab_ws.so -zld32=-S/opt/SUNWspro/prod/lib/libCCexcept.so.1 -zld64=-S/opt/SUNWspro/prod/lib/v9/libCCexcept.so.1 -R/opt/SUNWspro/lib/rw7:/opt/SUNWspro/lib/v8plus:/opt/SUNWspro/lib:/usr/ccs/lib:/lib:/usr/lib -o a.out /opt/SUNWspro/prod/lib/crti.o /opt/SUNWspro/prod/lib/CCrti.o /opt/SUNWspro/prod/lib/crt1.o /opt/SUNWspro/prod/lib/misalign.o /opt/SUNWspro/prod/lib/values-xa.o -Y P,/opt/SUNWspro/lib/rw7:/opt/SUNWspro/lib/v8plus:/opt/SUNWspro/prod/lib/rw7:/opt/SUNWspro/prod/lib/v8plus:/opt/SUNWspro/lib:/opt/SUNWspro/prod/lib:/usr/ccs/lib:/lib:/usr/lib dummy.o -lCstd -lCrun -lm -lc /opt/SUNWspro/prod/lib/CCrtn.o /opt/SUNWspro/prod/lib/crtn.o >&/tmp/ld.14846.2.err")
+set(sun_CC_libs "Cstd;Crun;m;c")
+set(sun_CC_dirs "/opt/SUNWspro/lib/rw7;/opt/SUNWspro/lib/v8plus;/opt/SUNWspro/prod/lib/rw7;/opt/SUNWspro/prod/lib/v8plus;/opt/SUNWspro/lib;/opt/SUNWspro/prod/lib;/usr/ccs/lib;/lib;/usr/lib")
+list(APPEND platforms sun_CC)
+
+# f77 dummy.f -v
+set(sun_f77_text "/usr/ccs/bin/ld -t -R/opt/SUNWspro/lib/v8plus:/opt/SUNWspro/lib -o a.out /opt/SUNWspro/prod/lib/crti.o /opt/SUNWspro/prod/lib/crt1.o /opt/SUNWspro/prod/lib/misalign.o /opt/SUNWspro/prod/lib/values-xi.o -Y P,/opt/SUNWspro/lib/v8plus:/opt/SUNWspro/prod/lib/v8plus:/opt/SUNWspro/lib:/opt/SUNWspro/prod/lib:/usr/ccs/lib:/lib:/usr/lib dummy.o -lf77compat -zallextract -lompstubs -zdefaultextract -lfui -lfai -lfai2 -lfsumai -lfprodai -lfminlai -lfmaxlai -lfminvai -lfmaxvai -lfsu -lsunmath -lm -lc /opt/SUNWspro/prod/lib/crtn.o")
+set(sun_f77_libs "f77compat;-zallextract;ompstubs;-zdefaultextract;fui;fai;fai2;fsumai;fprodai;fminlai;fmaxlai;fminvai;fmaxvai;fsu;sunmath;m;c")
+set(sun_f77_dirs "/opt/SUNWspro/lib/v8plus;/opt/SUNWspro/prod/lib/v8plus;/opt/SUNWspro/lib;/opt/SUNWspro/prod/lib;/usr/ccs/lib;/lib;/usr/lib")
+list(APPEND platforms sun_f77)
+
+# f90 dummy.f -v
+set(sun_f90_text "/usr/ccs/bin/ld -t -R/opt/SUNWspro/lib/v8plus:/opt/SUNWspro/lib -o a.out /opt/SUNWspro/prod/lib/crti.o /opt/SUNWspro/prod/lib/crt1.o /opt/SUNWspro/prod/lib/misalign.o /opt/SUNWspro/prod/lib/values-xi.o -Y P,/opt/SUNWspro/lib/v8plus:/opt/SUNWspro/prod/lib/v8plus:/opt/SUNWspro/lib:/opt/SUNWspro/prod/lib:/usr/ccs/lib:/lib:/usr/lib dummy.o -zallextract -lompstubs -zdefaultextract -lfui -lfai -lfai2 -lfsumai -lfprodai -lfminlai -lfmaxlai -lfminvai -lfmaxvai -lfsu -lsunmath -lm -lc /opt/SUNWspro/prod/lib/crtn.o")
+set(sun_f90_libs "-zallextract;ompstubs;-zdefaultextract;fui;fai;fai2;fsumai;fprodai;fminlai;fmaxlai;fminvai;fmaxvai;fsu;sunmath;m;c")
+set(sun_f90_dirs "/opt/SUNWspro/lib/v8plus;/opt/SUNWspro/prod/lib/v8plus;/opt/SUNWspro/lib;/opt/SUNWspro/prod/lib;/usr/ccs/lib;/lib;/usr/lib")
+list(APPEND platforms sun_f90)
+
+#-----------------------------------------------------------------------------
+# AIX
+
+# xlc -q32 dummy.c -V
+set(aix_xlc_32_text "/bin/ld -b32 /lib/crt0.o -bpT:0x10000000 -bpD:0x20000000 dummy.o -L/usr/vac/lib -lxlopt -lxl -lc")
+set(aix_xlc_32_libs "xlopt;xl;c")
+set(aix_xlc_32_dirs "/usr/vac/lib")
+list(APPEND platforms aix_xlc_32)
+
+# xlc -q64 dummy.c -V
+set(aix_xlc_64_text "/bin/ld -b64 /lib/crt0_64.o -bpT:0x100000000 -bpD:0x110000000 dummy.o -L/usr/vac/lib -lxlopt -lxl -lc")
+set(aix_xlc_64_libs "xlopt;xl;c")
+set(aix_xlc_64_dirs "/usr/vac/lib")
+list(APPEND platforms aix_xlc_64)
+
+# xlC -q32 dummy.cxx -V
+set(aix_xlC_32_text "
+/bin/ld -b32 /lib/crt0.o -bpT:0x10000000 -bpD:0x20000000 dummy.o -L/usr/vac/lib -lxlopt -lxl -L/usr/vacpp/lib -lC -lm -lc -bnobind >/tmp/xlcLDW0agyh
+/bin/ld -b32 /lib/crt0.o -bpT:0x10000000 -bpD:0x20000000 dummy.o -L/usr/vac/lib -lxlopt -lxl -L/usr/vacpp/lib -lC -lm -lc |")
+set(aix_xlC_32_libs "xlopt;xl;C;m;c")
+set(aix_xlC_32_dirs "/usr/vac/lib;/usr/vacpp/lib")
+list(APPEND platforms aix_xlC_32)
+
+# xlC -q64 dummy.cxx -V
+set(aix_xlC_64_text "
+/bin/ld -b64 /lib/crt0_64.o -bpT:0x100000000 -bpD:0x110000000 dummy.o -L/usr/vac/lib -lxlopt -lxl -L/usr/vacpp/lib -lC -lm -lc -bnobind >/tmp/xlcLD5nUnah
+/bin/ld -b64 /lib/crt0_64.o -bpT:0x100000000 -bpD:0x110000000 dummy.o -L/usr/vac/lib -lxlopt -lxl -L/usr/vacpp/lib -lC -lm -lc |")
+set(aix_xlC_64_libs "xlopt;xl;C;m;c")
+set(aix_xlC_64_dirs "/usr/vac/lib;/usr/vacpp/lib")
+list(APPEND platforms aix_xlC_64)
+
+# xlf -q32 dummy.f -V
+set(aix_xlf_32_text "/bin/ld -b32 /lib/crt0.o -bpT:0x10000000 -bpD:0x20000000 -bh:4 -bh:4 -bh:4 -bh:4 dummy.o -lxlf90 -L/usr/lpp/xlf/lib -lxlopt -lxlf -lxlomp_ser -lm -lc")
+set(aix_xlf_32_libs "xlf90;xlopt;xlf;xlomp_ser;m;c")
+set(aix_xlf_32_dirs "/usr/lpp/xlf/lib")
+list(APPEND platforms aix_xlf_32)
+
+# xlf -q64 dummy.f -V
+set(aix_xlf_64_text "/bin/ld -b64 /lib/crt0_64.o -bpT:0x100000000 -bpD:0x110000000 -bh:4 -bh:4 -bh:4 -bh:4 dummy.o -lxlf90 -L/usr/lpp/xlf/lib -lxlopt -lxlf -lxlomp_ser -lm -lc")
+set(aix_xlf_64_libs "xlf90;xlopt;xlf;xlomp_ser;m;c")
+set(aix_xlf_64_dirs "/usr/lpp/xlf/lib")
+list(APPEND platforms aix_xlf_64)
+
+# xlf90 -q32 dummy.f -V
+set(aix_xlf90_32_text "/bin/ld -b32 /lib/crt0.o -bpT:0x10000000 -bpD:0x20000000 -bh:4 dummy.o -lxlf90 -L/usr/lpp/xlf/lib -lxlopt -lxlf -lxlomp_ser -lm -lc")
+set(aix_xlf90_32_libs "xlf90;xlopt;xlf;xlomp_ser;m;c")
+set(aix_xlf90_32_dirs "/usr/lpp/xlf/lib")
+list(APPEND platforms aix_xlf90_32)
+
+# xlf90 -q64 dummy.f -V
+set(aix_xlf90_64_text "/bin/ld -b64 /lib/crt0_64.o -bpT:0x100000000 -bpD:0x110000000 -bh:4 dummy.o -lxlf90 -L/usr/lpp/xlf/lib -lxlopt -lxlf -lxlomp_ser -lm -lc")
+set(aix_xlf90_64_libs "xlf90;xlopt;xlf;xlomp_ser;m;c")
+set(aix_xlf90_64_dirs "/usr/lpp/xlf/lib")
+list(APPEND platforms aix_xlf90_64)
+
+#-----------------------------------------------------------------------------
+# HP
+
+# cc dummy.c -v
+set(hp_cc_old_text "cc: LPATH is /usr/lib/pa1.1:/usr/lib:/opt/langtools/lib:
+/usr/ccs/bin/ld /opt/langtools/lib/crt0.o -u main dummy.o -lc")
+set(hp_cc_old_libs "c")
+set(hp_cc_old_dirs "/usr/lib/pa1.1;/usr/lib;/opt/langtools/lib")
+list(APPEND platforms hp_cc_old)
+
+# aCC dummy.cxx -v
+set(hp_aCC_old_text "LPATH=/usr/lib/pa1.1:/usr/lib:/opt/langtools/lib
+ /usr/ccs/bin/ld -o a.out /opt/aCC/lib/crt0.o -u ___exit -u main -L /opt/aCC/lib /opt/aCC/lib/cpprt0.o dummy.o -lstd -lstream -lCsup -lm -lcl -lc /usr/lib/libdld.sl >/var/tmp/AAAa27787 2>&1")
+set(hp_aCC_old_libs "std;stream;Csup;m;cl;c")
+set(hp_aCC_old_dirs "/usr/lib/pa1.1;/usr/lib;/opt/langtools/lib;/opt/aCC/lib")
+list(APPEND platforms hp_aCC_old)
+
+# cc dummy.c -v
+set(hp_cc_32_text "LPATH=/usr/lib/hpux32:/opt/langtools/lib/hpux32
+ /usr/ccs/bin/ld -o a.out -u___exit -umain dummy.o -lc")
+set(hp_cc_32_libs "c")
+set(hp_cc_32_dirs "/usr/lib/hpux32;/opt/langtools/lib/hpux32")
+list(APPEND platforms hp_cc_32)
+
+# cc +DD64 dummy.c -v
+set(hp_cc_64_text "LPATH=/usr/lib/hpux64:/opt/langtools/lib/hpux64
+ /usr/ccs/bin/ld -o a.out -u___exit -umain dummy.o -lc")
+set(hp_cc_64_libs "c")
+set(hp_cc_64_dirs "/usr/lib/hpux64;/opt/langtools/lib/hpux64")
+list(APPEND platforms hp_cc_64)
+
+# aCC dummy.cxx -v
+set(hp_aCC_32_text "LPATH=/usr/lib/hpux32:/opt/langtools/lib/hpux32
+ /usr/ccs/bin/ld -o a.out -u___exit -umain -L/opt/aCC/lib/hpux32 dummy.o -lstd_v2 -lCsup -lm -lunwind -lCsup -lc -ldl >/var/tmp/AAAa03601 2>&1")
+set(hp_aCC_32_libs "std_v2;Csup;m;unwind;Csup;c;dl")
+set(hp_aCC_32_dirs "/usr/lib/hpux32;/opt/langtools/lib/hpux32;/opt/aCC/lib/hpux32")
+list(APPEND platforms hp_aCC_32)
+
+# aCC +DD64 dummy.cxx -v
+set(hp_aCC_64_text "LPATH=/usr/lib/hpux64:/opt/langtools/lib/hpux64
+ /usr/ccs/bin/ld -o a.out -u___exit -umain -L/opt/aCC/lib/hpux64 dummy.o -lstd_v2 -lCsup -lm -lunwind -lCsup -lc -ldl >/var/tmp/AAAa03597 2>&1")
+set(hp_aCC_64_libs "std_v2;Csup;m;unwind;Csup;c;dl")
+set(hp_aCC_64_dirs "/usr/lib/hpux64;/opt/langtools/lib/hpux64;/opt/aCC/lib/hpux64")
+list(APPEND platforms hp_aCC_64)
+
+# f90 dummy.f -v
+set(hp_f90_32_text "LPATH is: /usr/lib/hpux32/:/opt/langtools/lib/hpux32/
+/usr/ccs/bin/ld -u f90\$sgemm -u f90\$sgemv -u f90\$dgemm -u f90\$dgemv dummy.c +vnoshlibunsats -l:libF90.a -l:libIO77.a -lm -lc -lunwind -luca")
+set(hp_f90_32_libs "-l:libF90.a;-l:libIO77.a;m;c;unwind;uca")
+set(hp_f90_32_dirs "/usr/lib/hpux32;/opt/langtools/lib/hpux32")
+list(APPEND platforms hp_f90_32)
+
+# f90 +DD64 dummy.f -v
+set(hp_f90_64_text "LPATH is: /usr/lib/hpux64/:/opt/langtools/lib/hpux64/
+/usr/ccs/bin/ld -u f90\$sgemm -u f90\$sgemv -u f90\$dgemm -u f90\$dgemv dummy.c +vnoshlibunsats -l:libF90.a -l:libIO77.a -lm -lc -lunwind -luca")
+set(hp_f90_64_libs "-l:libF90.a;-l:libIO77.a;m;c;unwind;uca")
+set(hp_f90_64_dirs "/usr/lib/hpux64;/opt/langtools/lib/hpux64")
+list(APPEND platforms hp_f90_64)
+
+#-----------------------------------------------------------------------------
+# IRIX
+
+# cc -o32 dummy.c -v
+set(irix64_cc_o32_text "/usr/lib/ld -elf -_SYSTYPE_SVR4 -require_dynamic_link _rld_new_interface -no_unresolved -Wx,-G 0 -o32 -mips2 -call_shared -g0 -KPIC -L/usr/lib/ -nocount /usr/lib/crt1.o -count dummy.o -nocount -lc /usr/lib/crtn.o")
+set(irix64_cc_o32_libs "c")
+set(irix64_cc_o32_dirs "/usr/lib")
+list(APPEND platforms irix64_cc_o32)
+
+# cc -n32 dummy.c -v
+set(irix64_cc_n32_text "/usr/lib32/cmplrs/ld32 -call_shared -no_unresolved -transitive_link -elf -_SYSTYPE_SVR4 -show -mips4 -n32 -L/usr/lib32/mips4/r10000 -L/usr/lib32/mips4 -L/usr/lib32 /usr/lib32/mips4/crt1.o dummy.o -dont_warn_unused -Bdynamic -lc /usr/lib32/mips4/crtn.o -warn_unused")
+set(irix64_cc_n32_libs "c")
+set(irix64_cc_n32_dirs "/usr/lib32/mips4/r10000;/usr/lib32/mips4;/usr/lib32")
+list(APPEND platforms irix64_cc_n32)
+
+# cc -64 dummy.c -v
+set(irix64_cc_64_text "/usr/lib32/cmplrs/ld64 -call_shared -no_unresolved -transitive_link -elf -_SYSTYPE_SVR4 -show -mips4 -64 -L/usr/lib64/mips4/r10000 -L/usr/lib64/mips4 -L/usr/lib64 /usr/lib64/mips4/crt1.o dummy.o -dont_warn_unused -Bdynamic -lc /usr/lib64/mips4/crtn.o -warn_unused")
+set(irix64_cc_64_libs "c")
+set(irix64_cc_64_dirs "/usr/lib64/mips4/r10000;/usr/lib64/mips4;/usr/lib64")
+list(APPEND platforms irix64_cc_64)
+
+# CC -o32 dummy.cxx -v
+set(irix64_CC_o32_text "/usr/lib/ld -elf -cxx -woff 134 -_SYSTYPE_SVR4 -require_dynamic_link _rld_new_interface -no_unresolved -Wx,-G 0 -o32 -mips2 -call_shared -g0 -KPIC -L/usr/lib/ -nocount /usr/lib/crt1.o /usr/lib/c++init.o -count dummy.o -nocount -dont_warn_unused -lC -warn_unused -lc /usr/lib/crtn.o")
+set(irix64_CC_o32_libs "C;c")
+set(irix64_CC_o32_dirs "/usr/lib")
+list(APPEND platforms irix64_CC_o32)
+
+# CC -n32 dummy.cxx -v
+set(irix64_CC_n32_text "/usr/lib32/cmplrs/ld32 -call_shared -init _main -fini _fini -no_unresolved -transitive_link -demangle -elf -_SYSTYPE_SVR4 -LANG:std -show -mips4 -n32 -L/usr/lib32/mips4/r10000 -L/usr/lib32/mips4 -L/usr/lib32 -cxx -woff 134 /usr/lib32/mips4/crt1.o /usr/lib32/c++init.o dummy.o -dont_warn_unused -lCsup -lC -lCio -Bdynamic -lc /usr/lib32/mips4/crtn.o -warn_unused")
+set(irix64_CC_n32_libs "Csup;C;Cio;c")
+set(irix64_CC_n32_dirs "/usr/lib32/mips4/r10000;/usr/lib32/mips4;/usr/lib32")
+list(APPEND platforms irix64_CC_n32)
+
+# CC -64 dummy.cxx -v
+set(irix64_CC_64_text "/usr/lib32/cmplrs/ld64 -call_shared -init _main -fini _fini -no_unresolved -transitive_link -demangle -elf -_SYSTYPE_SVR4 -LANG:std -show -mips4 -64 -L/usr/lib64/mips4/r10000 -L/usr/lib64/mips4 -L/usr/lib64 -cxx -woff 134 /usr/lib64/mips4/crt1.o /usr/lib64/c++init.o dummy.o -dont_warn_unused -lCsup -lC -lCio -Bdynamic -lc /usr/lib64/mips4/crtn.o -warn_unused")
+set(irix64_CC_64_libs "Csup;C;Cio;c")
+set(irix64_CC_64_dirs "/usr/lib64/mips4/r10000;/usr/lib64/mips4;/usr/lib64")
+list(APPEND platforms irix64_CC_64)
+
+# f77 -o32 dummy.f -v
+set(irix64_f77_o32_text "/usr/lib/ld -elf -_SYSTYPE_SVR4 -require_dynamic_link _rld_new_interface -no_unresolved -Wx,-G 0 -o32 -mips2 -call_shared -g0 -KPIC -L/usr/lib/ -nocount /usr/lib/crt1.o -count dummy.o -nocount -lftn -lm -lc /usr/lib/crtn.o")
+set(irix64_f77_o32_libs "ftn;m;c")
+set(irix64_f77_o32_dirs "/usr/lib")
+list(APPEND platforms irix64_f77_o32)
+
+# f77 -n32 dummy.f -v
+set(irix64_f77_n32_text "/usr/lib32/cmplrs/ld32 -call_shared -no_unresolved -transitive_link -elf -_SYSTYPE_SVR4 -show -mips4 -n32 -L/usr/lib32/mips4/r10000 -L/usr/lib32/mips4 -L/usr/lib32 /usr/lib32/mips4/crt1.o dummy.o -dont_warn_unused -lftn -lm -Bdynamic -lc /usr/lib32/mips4/crtn.o -warn_unused")
+set(irix64_f77_n32_libs "ftn;m;c")
+set(irix64_f77_n32_dirs "/usr/lib32/mips4/r10000;/usr/lib32/mips4;/usr/lib32")
+list(APPEND platforms irix64_f77_n32)
+
+# f77 -64 dummy.f -v
+set(irix64_f77_64_text "/usr/lib32/cmplrs/ld64 -call_shared -no_unresolved -transitive_link -elf -_SYSTYPE_SVR4 -show -mips4 -64 -L/usr/lib64/mips4/r10000 -L/usr/lib64/mips4 -L/usr/lib64 /usr/lib64/mips4/crt1.o dummy.o -dont_warn_unused -lftn -lm -Bdynamic -lc /usr/lib64/mips4/crtn.o -warn_unused")
+set(irix64_f77_64_libs "ftn;m;c")
+set(irix64_f77_64_dirs "/usr/lib64/mips4/r10000;/usr/lib64/mips4;/usr/lib64")
+list(APPEND platforms irix64_f77_64)
+
+# f90 -o32 dummy.f -v
+#f90 ERROR: specified abi -o32 not supported.
+
+# f90 -n32 dummy.f -v
+set(irix64_f90_n32_text "/usr/lib32/cmplrs/ld32 -call_shared -no_unresolved -transitive_link -elf -_SYSTYPE_SVR4 -show -mips4 -n32 -L/usr/lib32/mips4/r10000 -L/usr/lib32/mips4 -L/usr/lib32 /usr/lib32/mips4/crt1.o dummy.o -dont_warn_unused -lfortran -lffio -lftn -lm -Bdynamic -lc /usr/lib32/mips4/crtn.o -warn_unused")
+set(irix64_f90_n32_libs "fortran;ffio;ftn;m;c")
+set(irix64_f90_n32_dirs "/usr/lib32/mips4/r10000;/usr/lib32/mips4;/usr/lib32")
+list(APPEND platforms irix64_f90_n32)
+
+# f90 -64 dummy.f -v
+set(irix64_f90_64_text "/usr/lib32/cmplrs/ld64 -call_shared -no_unresolved -transitive_link -elf -_SYSTYPE_SVR4 -show -mips4 -64 -L/usr/lib64/mips4/r10000 -L/usr/lib64/mips4 -L/usr/lib64 /usr/lib64/mips4/crt1.o dummy.o -dont_warn_unused -lfortran -lffio -lftn -lm -Bdynamic -lc /usr/lib64/mips4/crtn.o -warn_unused")
+set(irix64_f90_64_libs "fortran;ffio;ftn;m;c")
+set(irix64_f90_64_dirs "/usr/lib64/mips4/r10000;/usr/lib64/mips4;/usr/lib64")
+list(APPEND platforms irix64_f90_64)
+
+#-----------------------------------------------------------------------------
+# Cygwin
+
+# gcc dummy.c -v
+set(cygwin_gcc_text " /usr/lib/gcc/i686-pc-cygwin/3.4.4/collect2.exe -Bdynamic --dll-search-prefix=cyg /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../crt0.o -L/usr/lib/gcc/i686-pc-cygwin/3.4.4 -L/usr/lib/gcc/i686-pc-cygwin/3.4.4 -L/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../.. /home/user/AppData/Local/Temp/cczg1Arh.o -lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc")
+set(cygwin_gcc_libs "cygwin;user32;kernel32;advapi32;shell32")
+set(cygwin_gcc_dirs "/usr/lib/gcc/i686-pc-cygwin/3.4.4;/usr/lib")
+list(APPEND platforms cygwin_gcc)
+
+# g++ dummy.cxx -v
+set(cygwin_g++_text " /usr/lib/gcc/i686-pc-cygwin/3.4.4/collect2.exe -Bdynamic --dll-search-prefix=cyg /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../crt0.o -L/usr/lib/gcc/i686-pc-cygwin/3.4.4 -L/usr/lib/gcc/i686-pc-cygwin/3.4.4 -L/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../.. /home/user/AppData/Local/Temp/ccsvcDO6.o -lstdc++ -lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc")
+set(cygwin_g++_libs "stdc++;cygwin;user32;kernel32;advapi32;shell32")
+set(cygwin_g++_dirs "/usr/lib/gcc/i686-pc-cygwin/3.4.4;/usr/lib")
+list(APPEND platforms cygwin_g++)
+
+# gfortran dummy.f -v
+set(cygwin_gfortran_text "Configured with: ... LD=/opt/gcc-tools/bin/ld.exe
+ /usr/lib/gcc/i686-pc-cygwin/4.3.2/collect2.exe -Bdynamic --dll-search-prefix=cyg -u ___register_frame_info -u ___deregister_frame_info /usr/lib/gcc/i686-pc-cygwin/4.3.2/../../../crt0.o /usr/lib/gcc/i686-pc-cygwin/4.3.2/crtbegin.o -L/usr/lib/gcc/i686-pc-cygwin/4.3.2 -L/usr/lib/gcc/i686-pc-cygwin/4.3.2 -L/usr/lib/gcc/i686-pc-cygwin/4.3.2/../../.. /home/user/AppData/Local/Temp/ccqRWKWg.o -lgfortranbegin -lgfortran -lgcc_s -lgcc_s -lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc_s -lgcc_s -lgcc /usr/lib/gcc/i686-pc-cygwin/4.3.2/crtend.o
+")
+set(cygwin_gfortran_libs "gfortranbegin;gfortran;cygwin;user32;kernel32;advapi32;shell32")
+set(cygwin_gfortran_dirs "/usr/lib/gcc/i686-pc-cygwin/4.3.2;/usr/lib")
+list(APPEND platforms cygwin_gfortran)
+
+#-----------------------------------------------------------------------------
+# MSYS
+
+# gcc dummy.c -v
+set(msys_gcc_text " C:/some-mingw/bin/../libexec/gcc/mingw32/3.4.5/collect2.exe -Bdynamic /some-mingw/lib/crt2.o C:/some-mingw/bin/../lib/gcc/mingw32/3.4.5/crtbegin.o -LC:/some-mingw/bin/../lib/gcc/mingw32/3.4.5 -LC:/some-mingw/bin/../lib/gcc -L/some-mingw/lib -LC:/some-mingw/bin/../lib/gcc/mingw32/3.4.5/../../.. C:/home/user/AppData/Local/Temp/cckQmvRt.o -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt C:/some-mingw/bin/../lib/gcc/mingw32/3.4.5/crtend.o")
+set(msys_gcc_libs "mingw32;moldname;mingwex;msvcrt;user32;kernel32;advapi32;shell32;mingw32;moldname;mingwex;msvcrt")
+set(msys_gcc_dirs "C:/some-mingw/lib/gcc/mingw32/3.4.5;C:/some-mingw/lib/gcc;/some-mingw/lib;C:/some-mingw/lib")
+list(APPEND platforms msys_gcc)
+
+# g++ dummy.cxx -v
+set(msys_g++_text " C:/some-mingw/bin/../libexec/gcc/mingw32/3.4.5/collect2.exe -Bdynamic /some-mingw/lib/crt2.o C:/some-mingw/bin/../lib/gcc/mingw32/3.4.5/crtbegin.o -LC:/some-mingw/bin/../lib/gcc/mingw32/3.4.5 -LC:/some-mingw/bin/../lib/gcc -L/some-mingw/lib -LC:/some-mingw/bin/../lib/gcc/mingw32/3.4.5/../../.. C:/home/user/AppData/Local/Temp/cci5hYPk.o -lstdc++ -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt C:/some-mingw/bin/../lib/gcc/mingw32/3.4.5/crtend.o")
+set(msys_g++_libs "stdc++;mingw32;moldname;mingwex;msvcrt;user32;kernel32;advapi32;shell32;mingw32;moldname;mingwex;msvcrt")
+set(msys_g++_dirs "C:/some-mingw/lib/gcc/mingw32/3.4.5;C:/some-mingw/lib/gcc;/some-mingw/lib;C:/some-mingw/lib")
+list(APPEND platforms msys_g++)
+
+# g77 dummy.f -v
+set(msys_g77_text " C:/some-mingw/bin/../libexec/gcc/mingw32/3.4.5/collect2.exe -Bdynamic /some-mingw/lib/crt2.o C:/some-mingw/bin/../lib/gcc/mingw32/3.4.5/crtbegin.o -LC:/some-mingw/bin/../lib/gcc/mingw32/3.4.5 -LC:/some-mingw/bin/../lib/gcc -L/some-mingw/lib -LC:/some-mingw/bin/../lib/gcc/mingw32/3.4.5/../../.. C:/home/user/AppData/Local/Temp/ccabRxQ1.o -lfrtbegin -lg2c -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt C:/some-mingw/bin/../lib/gcc/mingw32/3.4.5/crtend.o")
+set(msys_g77_libs "frtbegin;g2c;mingw32;moldname;mingwex;msvcrt;user32;kernel32;advapi32;shell32;mingw32;moldname;mingwex;msvcrt")
+set(msys_g77_dirs "C:/some-mingw/lib/gcc/mingw32/3.4.5;C:/some-mingw/lib/gcc;/some-mingw/lib;C:/some-mingw/lib")
+list(APPEND platforms msys_g77)
+
+
+#-----------------------------------------------------------------------------
+# Test parsing for all above examples.
+set(CMAKE_LINKER "not-a-linker[]().*+^$?")
+
+foreach(p IN LISTS platforms)
+ cmake_parse_implicit_link_info("${${p}_text}" libs dirs fwks log "${${p}_obj_regex}")
+
+ foreach(v libs dirs fwks)
+ if(DEFINED "${p}_${v}" AND NOT "${${v}}" STREQUAL "${${p}_${v}}")
+ message(FATAL_ERROR
+ "cmake_parse_implicit_link_info failed\n"
+ "Expected '${p}' implicit ${v}\n"
+ " [${${p}_${v}}]\n"
+ "but got\n"
+ " [${${v}}]\n"
+ "Parse log was:\n"
+ "${log}"
+ )
+ endif()
+ endforeach()
+endforeach()
diff --git a/Tests/CMakeTests/IncludeTest.cmake.in b/Tests/CMakeTests/IncludeTest.cmake.in
new file mode 100644
index 0000000000..985333c4b8
--- /dev/null
+++ b/Tests/CMakeTests/IncludeTest.cmake.in
@@ -0,0 +1,41 @@
+# this one must silently fail
+include(I_am_not_here OPTIONAL)
+
+# this one must be found and the result must be put into _includedFile
+include(CMake RESULT_VARIABLE _includedFile)
+
+set(fileOne "${_includedFile}")
+set(fileTwo "${CMAKE_ROOT}/Modules/CMake.cmake")
+if(WIN32)
+ string(TOLOWER "${fileOne}" fileOne)
+ string(TOLOWER "${fileTwo}" fileTwo)
+endif()
+
+if(NOT "${fileOne}" STREQUAL "${fileTwo}")
+ message(FATAL_ERROR "Wrong CMake.cmake was included: \"${fileOne}\" expected \"${fileTwo}\"")
+endif()
+
+# this one must return NOTFOUND in _includedFile
+include(I_do_not_exist OPTIONAL RESULT_VARIABLE _includedFile)
+
+if(_includedFile)
+ message(FATAL_ERROR "File \"I_do_not_exist\" was included, although it shouldn't exist,\nIncluded file is \"${_includedFile}\"")
+endif()
+
+# and this one must succeed too
+include(CMake OPTIONAL RESULT_VARIABLE _includedFile)
+set(fileOne "${_includedFile}")
+set(fileTwo "${CMAKE_ROOT}/Modules/CMake.cmake")
+if(WIN32)
+ string(TOLOWER "${fileOne}" fileOne)
+ string(TOLOWER "${fileTwo}" fileTwo)
+endif()
+
+if(NOT "${fileOne}" STREQUAL "${fileTwo}")
+ message(FATAL_ERROR "Wrong CMake.cmake was included: \"${fileOne}\" expected \"${fileTwo}\"")
+endif()
+
+# Check that CMAKE_CURRENT_LIST_DIR is working:
+# Needs to be a file in the build tree, which is correct cmake script
+# but doesn't do a lot, if possible only set() commands:
+include(${CMAKE_CURRENT_LIST_DIR}/../../CTestCustom.cmake)
diff --git a/Tests/CMakeTests/List-Get-CMP0007-Warn.cmake b/Tests/CMakeTests/List-Get-CMP0007-Warn.cmake
new file mode 100644
index 0000000000..0a9264fdc9
--- /dev/null
+++ b/Tests/CMakeTests/List-Get-CMP0007-Warn.cmake
@@ -0,0 +1,6 @@
+set(thelist "" NEW OLD)
+
+list(GET thelist 1 thevalue)
+if (NOT thevalue STREQUAL "OLD")
+ message(SEND_ERROR "returned element '${thevalue}', but expected 'OLD'")
+endif()
diff --git a/Tests/CMakeTests/List-Get-Invalid-Index.cmake b/Tests/CMakeTests/List-Get-Invalid-Index.cmake
new file mode 100644
index 0000000000..178295a209
--- /dev/null
+++ b/Tests/CMakeTests/List-Get-Invalid-Index.cmake
@@ -0,0 +1,2 @@
+set(mylist alpha bravo charlie)
+list(GET mylist 3 result)
diff --git a/Tests/CMakeTests/List-Insert-Invalid-Index.cmake b/Tests/CMakeTests/List-Insert-Invalid-Index.cmake
new file mode 100644
index 0000000000..4103d974b4
--- /dev/null
+++ b/Tests/CMakeTests/List-Insert-Invalid-Index.cmake
@@ -0,0 +1,2 @@
+set(mylist alpha bravo charlie)
+list(INSERT mylist 3 delta)
diff --git a/Tests/CMakeTests/List-Invalid-Subcommand.cmake b/Tests/CMakeTests/List-Invalid-Subcommand.cmake
new file mode 100644
index 0000000000..f35a1181ef
--- /dev/null
+++ b/Tests/CMakeTests/List-Invalid-Subcommand.cmake
@@ -0,0 +1 @@
+list(NO_SUCH_SUBCOMMAND mylist)
diff --git a/Tests/CMakeTests/List-Length-Too-Many-Arguments.cmake b/Tests/CMakeTests/List-Length-Too-Many-Arguments.cmake
new file mode 100644
index 0000000000..327db6a84d
--- /dev/null
+++ b/Tests/CMakeTests/List-Length-Too-Many-Arguments.cmake
@@ -0,0 +1 @@
+list(LENGTH mylist result one_too_many)
diff --git a/Tests/CMakeTests/List-No-Arguments.cmake b/Tests/CMakeTests/List-No-Arguments.cmake
new file mode 100644
index 0000000000..7916aaaecc
--- /dev/null
+++ b/Tests/CMakeTests/List-No-Arguments.cmake
@@ -0,0 +1 @@
+list()
diff --git a/Tests/CMakeTests/List-Remove_At-Invalid-Index.cmake b/Tests/CMakeTests/List-Remove_At-Invalid-Index.cmake
new file mode 100644
index 0000000000..d4f3921263
--- /dev/null
+++ b/Tests/CMakeTests/List-Remove_At-Invalid-Index.cmake
@@ -0,0 +1,2 @@
+set(mylist alpha bravo charlie)
+list(REMOVE_AT mylist 3)
diff --git a/Tests/CMakeTests/List-Remove_At-Nonexistent-List.cmake b/Tests/CMakeTests/List-Remove_At-Nonexistent-List.cmake
new file mode 100644
index 0000000000..5266c7fe99
--- /dev/null
+++ b/Tests/CMakeTests/List-Remove_At-Nonexistent-List.cmake
@@ -0,0 +1,2 @@
+unset(nosuchlist)
+list(REMOVE_AT nosuchlist 0)
diff --git a/Tests/CMakeTests/List-Remove_Duplicates-Nonexistent-List.cmake b/Tests/CMakeTests/List-Remove_Duplicates-Nonexistent-List.cmake
new file mode 100644
index 0000000000..218f2272cd
--- /dev/null
+++ b/Tests/CMakeTests/List-Remove_Duplicates-Nonexistent-List.cmake
@@ -0,0 +1,2 @@
+unset(nosuchlist)
+list(REMOVE_DUPLICATES nosuchlist)
diff --git a/Tests/CMakeTests/List-Remove_Duplicates-Too-Many-Arguments.cmake b/Tests/CMakeTests/List-Remove_Duplicates-Too-Many-Arguments.cmake
new file mode 100644
index 0000000000..b5eb46e644
--- /dev/null
+++ b/Tests/CMakeTests/List-Remove_Duplicates-Too-Many-Arguments.cmake
@@ -0,0 +1 @@
+list(REMOVE_DUPLICATES mylist one_too_many)
diff --git a/Tests/CMakeTests/List-Remove_Item-Nonexistent-List.cmake b/Tests/CMakeTests/List-Remove_Item-Nonexistent-List.cmake
new file mode 100644
index 0000000000..079e7fbce2
--- /dev/null
+++ b/Tests/CMakeTests/List-Remove_Item-Nonexistent-List.cmake
@@ -0,0 +1,2 @@
+unset(nosuchlist)
+list(REMOVE_ITEM nosuchlist alpha)
diff --git a/Tests/CMakeTests/List-Reverse-Nonexistent-List.cmake b/Tests/CMakeTests/List-Reverse-Nonexistent-List.cmake
new file mode 100644
index 0000000000..977e2ccac1
--- /dev/null
+++ b/Tests/CMakeTests/List-Reverse-Nonexistent-List.cmake
@@ -0,0 +1,2 @@
+unset(nosuchlist)
+list(REVERSE nosuchlist)
diff --git a/Tests/CMakeTests/List-Reverse-Too-Many-Arguments.cmake b/Tests/CMakeTests/List-Reverse-Too-Many-Arguments.cmake
new file mode 100644
index 0000000000..3a554a01ae
--- /dev/null
+++ b/Tests/CMakeTests/List-Reverse-Too-Many-Arguments.cmake
@@ -0,0 +1 @@
+list(REVERSE mylist one_too_many)
diff --git a/Tests/CMakeTests/List-Sort-Nonexistent-List.cmake b/Tests/CMakeTests/List-Sort-Nonexistent-List.cmake
new file mode 100644
index 0000000000..8f48e10432
--- /dev/null
+++ b/Tests/CMakeTests/List-Sort-Nonexistent-List.cmake
@@ -0,0 +1,2 @@
+unset(nosuchlist)
+list(SORT nosuchlist)
diff --git a/Tests/CMakeTests/List-Sort-Too-Many-Arguments.cmake b/Tests/CMakeTests/List-Sort-Too-Many-Arguments.cmake
new file mode 100644
index 0000000000..81b195d67b
--- /dev/null
+++ b/Tests/CMakeTests/List-Sort-Too-Many-Arguments.cmake
@@ -0,0 +1 @@
+list(SORT mylist one_too_many)
diff --git a/Tests/CMakeTests/ListTest.cmake.in b/Tests/CMakeTests/ListTest.cmake.in
new file mode 100644
index 0000000000..77c34a9c44
--- /dev/null
+++ b/Tests/CMakeTests/ListTest.cmake.in
@@ -0,0 +1,190 @@
+include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/../RegexEscapeString.cmake")
+REGEX_ESCAPE_STRING(CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
+
+macro(TEST command expected)
+ if("x${result}" STREQUAL "x${expected}")
+ #message("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
+ else()
+ message(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
+ endif()
+endmacro()
+
+set(mylist andy bill ken brad)
+
+list(LENGTH mylist result)
+TEST("LENGTH mylist result" "4")
+list(LENGTH "mylist" result)
+TEST("LENGTH \"mylist\" result" "4")
+
+list(LENGTH "nonexiting_list1" result)
+TEST("LENGTH \"nonexiting_list1\" result" "0")
+
+list(GET mylist 3 2 1 0 result)
+TEST("GET mylist 3 2 1 0 result" "brad;ken;bill;andy")
+
+list(GET mylist 0 item0)
+list(GET mylist 1 item1)
+list(GET mylist 2 item2)
+list(GET mylist 3 item3)
+set(result "${item3}" "${item0}" "${item1}" "${item2}")
+TEST("GET individual 3 2 1 0 result" "brad;andy;bill;ken")
+
+list(GET mylist -1 -2 -3 -4 result)
+TEST("GET mylist -1 -2 -3 -4 result" "brad;ken;bill;andy")
+
+list(GET mylist -1 2 -3 0 result)
+TEST("GET mylist -1 2 -3 0 ${result}" "brad;ken;bill;andy")
+
+list(GET "nonexiting_list2" 1 result)
+TEST("GET \"nonexiting_list2\" 1 result" "NOTFOUND")
+
+set(result andy)
+list(APPEND result brad)
+TEST("APPEND result brad" "andy;brad")
+
+list(APPEND "nonexiting_list3" brad)
+set(result "${nonexiting_list3}")
+TEST("APPEND \"nonexiting_list3\" brad" "brad")
+
+list(INSERT "nonexiting_list4" 0 andy bill brad ken)
+set(result "${nonexiting_list4}")
+TEST("APPEND \"nonexiting_list4\" andy bill brad ken" "andy;bill;brad;ken")
+
+set(result andy brad)
+list(INSERT result -1 bill ken)
+TEST("INSERT result -1 bill ken" "andy;bill;ken;brad")
+
+set(result andy bill brad ken bob)
+list(REMOVE_ITEM result bob)
+TEST("REMOVE_ITEM result bob" "andy;bill;brad;ken")
+
+set(result andy bill bob brad ken peter)
+list(REMOVE_ITEM result peter bob)
+TEST("REMOVE_ITEM result peter bob" "andy;bill;brad;ken")
+
+set(result bob andy bill bob brad ken bob)
+list(REMOVE_ITEM result bob)
+TEST("REMOVE_ITEM result bob" "andy;bill;brad;ken")
+
+set(result andy bill bob brad ken peter)
+list(REMOVE_AT result 2 -1)
+TEST("REMOVE_AT result 2 -1" "andy;bill;brad;ken")
+
+# ken is at index 2, nobody is not in the list so -1 should be returned
+set(mylist andy bill ken brad)
+list(FIND mylist ken result)
+TEST("FIND mylist ken result" "2")
+
+list(FIND mylist nobody result)
+TEST("FIND mylist nobody result" "-1")
+
+set(result ken bill andy brad)
+list(SORT result)
+TEST("SORT result" "andy;bill;brad;ken")
+
+set(result andy bill brad ken)
+list(REVERSE result)
+TEST("REVERSE result" "ken;brad;bill;andy")
+
+set(result bill andy bill brad ken ken ken)
+list(REMOVE_DUPLICATES result)
+TEST("REMOVE_DUPLICATES result" "bill;andy;brad;ken")
+
+# these commands should just do nothing if the list is already empty
+set(result "")
+list(REMOVE_DUPLICATES result)
+TEST("REMOVE_DUPLICATES empty result" "")
+
+list(REVERSE result)
+TEST("REVERSE empty result" "")
+
+list(SORT result)
+TEST("SORT empty result" "")
+
+set(No-Arguments-RESULT 1)
+set(No-Arguments-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?List-No-Arguments.cmake:1 \\(list\\):.*list must be called with at least two arguments.*")
+
+# these trigger top-level condition
+foreach(cmd IN ITEMS Append Find Get Insert Length Reverse Remove_At Remove_Duplicates Remove_Item Sort)
+ set(${cmd}-No-Arguments-RESULT 1)
+ set(${cmd}-No-Arguments-STDERR ".*CMake Error at List-${cmd}-No-Arguments.cmake:1 \\(list\\):.*list must be called with at least two arguments.*")
+ string(TOUPPER ${cmd} cmd_upper)
+ set(_test_file_name "${CMAKE_CURRENT_BINARY_DIR}/List-${cmd}-No-Arguments.cmake")
+ file(WRITE "${_test_file_name}" "list(${cmd_upper})\n")
+ check_cmake_test_single(List "${cmd}-No-Arguments" "${_test_file_name}")
+endforeach()
+
+set(Get-List-Only-STDERR "at least three")
+set(Find-List-Only-STDERR "three")
+set(Insert-List-Only-STDERR "at least three")
+set(Length-List-Only-STDERR "two")
+set(Remove_At-List-Only-STDERR "at least two")
+set(Remove_Item-List-Only-STDERR "two or more")
+
+foreach(cmd IN ITEMS Find Get Insert Length Remove_At Remove_Item)
+ string(TOUPPER ${cmd} cmd_upper)
+ set(${cmd}-List-Only-RESULT 1)
+ set(${cmd}-List-Only-STDERR ".*CMake Error at List-${cmd}-List-Only.cmake:1 \\(list\\):.*list sub-command ${cmd_upper} requires ${${cmd}-List-Only-STDERR} arguments.*")
+ set(_test_file_name "${CMAKE_CURRENT_BINARY_DIR}/List-${cmd}-List-Only.cmake")
+ file(WRITE "${_test_file_name}" "list(${cmd_upper} mylist)\n")
+ check_cmake_test_single(List "${cmd}-List-Only" "${_test_file_name}")
+endforeach()
+
+set(Length-Too-Many-Arguments-RESULT 1)
+set(Length-Too-Many-Arguments-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?List-Length-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command LENGTH requires two arguments.*")
+
+set(Reverse-Too-Many-Arguments-RESULT 1)
+set(Reverse-Too-Many-Arguments-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?List-Reverse-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command REVERSE only takes one argument.*")
+
+set(Remove_Duplicates-Too-Many-Arguments-RESULT 1)
+set(Remove_Duplicates-Too-Many-Arguments-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?List-Remove_Duplicates-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command REMOVE_DUPLICATES only takes one argument.*")
+
+set(Sort-Too-Many-Arguments-RESULT 1)
+set(Sort-Too-Many-Arguments-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?List-Sort-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command SORT only takes one argument.*")
+
+set(Invalid-Subcommand-RESULT 1)
+set(Invalid-Subcommand-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?List-Invalid-Subcommand.cmake:1 \\(list\\):.*list does not recognize sub-command NO_SUCH_SUBCOMMAND.*")
+
+foreach(cmd Get Insert Remove_At)
+ set(${cmd}-Invalid-Index-RESULT 1)
+ set(${cmd}-Invalid-Index-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?List-${cmd}-Invalid-Index.cmake:2 \\(list\\):.*list index: 3 out of range \\(-3, 2\\).*")
+endforeach()
+
+foreach(cmd Remove_Item Reverse Remove_Duplicates Sort Remove_At)
+ string(TOUPPER ${cmd} Cmd)
+ set(${cmd}-Nonexistent-List-RESULT 1)
+ set(${cmd}-Nonexistent-List-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?List-${cmd}-Nonexistent-List.cmake:2 \\(list\\):.*sub-command ${Cmd} requires list to be present.*")
+endforeach()
+
+set(Get-CMP0007-Warn-RESULT 0)
+set(Get-CMP0007-Warn-STDERR ".*CMake Warning \\(dev\\) at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?List-Get-CMP0007-Warn.cmake:3 \\(list\\):.*Policy CMP0007 is not set:.*")
+
+check_cmake_test(List
+ No-Arguments
+ Length-Too-Many-Arguments
+ Reverse-Too-Many-Arguments
+ Remove_Duplicates-Too-Many-Arguments
+ Sort-Too-Many-Arguments
+ Invalid-Subcommand
+ Get-Invalid-Index
+ Insert-Invalid-Index
+ Remove_Item-Nonexistent-List
+ Reverse-Nonexistent-List
+ Remove_Duplicates-Nonexistent-List
+ Sort-Nonexistent-List
+ Remove_At-Nonexistent-List
+ Remove_At-Invalid-Index
+ Get-CMP0007-Warn
+)
+
+set(thelist "" NEW OLD)
+
+foreach (_pol ${thelist})
+ cmake_policy(SET CMP0007 ${_pol})
+ list(GET thelist 1 thevalue)
+ if (NOT thevalue STREQUAL _pol)
+ message(SEND_ERROR "returned element '${thevalue}', but expected '${_pol}'")
+ endif()
+endforeach (_pol)
diff --git a/Tests/CMakeTests/Make_Directory-NoArg.cmake b/Tests/CMakeTests/Make_Directory-NoArg.cmake
new file mode 100644
index 0000000000..25b6f8984f
--- /dev/null
+++ b/Tests/CMakeTests/Make_Directory-NoArg.cmake
@@ -0,0 +1 @@
+file(MAKE_DIRECTORY)
diff --git a/Tests/CMakeTests/MathTest.cmake.in b/Tests/CMakeTests/MathTest.cmake.in
new file mode 100644
index 0000000000..91cd9220aa
--- /dev/null
+++ b/Tests/CMakeTests/MathTest.cmake.in
@@ -0,0 +1,18 @@
+# Execute each test listed in:
+#
+set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/MathTestScript.cmake")
+set(number_of_tests_expected 4)
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/ExecuteScriptTests.cmake")
+execute_all_script_tests(${scriptname} number_of_tests_executed)
+
+# And verify that number_of_tests_executed is at least as many as we know
+# about as of this writing...
+#
+message(STATUS "scriptname='${scriptname}'")
+message(STATUS "number_of_tests_executed='${number_of_tests_executed}'")
+message(STATUS "number_of_tests_expected='${number_of_tests_expected}'")
+
+if(number_of_tests_executed LESS number_of_tests_expected)
+ message(FATAL_ERROR "error: some test cases were skipped")
+endif()
diff --git a/Tests/CMakeTests/MathTestScript.cmake b/Tests/CMakeTests/MathTestScript.cmake
new file mode 100644
index 0000000000..1b7f8a6f3b
--- /dev/null
+++ b/Tests/CMakeTests/MathTestScript.cmake
@@ -0,0 +1,18 @@
+message(STATUS "testname='${testname}'")
+
+if(testname STREQUAL empty) # fail
+ math()
+
+elseif(testname STREQUAL bogus) # fail
+ math(BOGUS)
+
+elseif(testname STREQUAL not_enough_args) # fail
+ math(EXPR x)
+
+elseif(testname STREQUAL cannot_parse) # fail
+ math(EXPR x "1 + 2 +")
+
+else() # fail
+ message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'")
+
+endif()
diff --git a/Tests/CMakeTests/MessageTest.cmake.in b/Tests/CMakeTests/MessageTest.cmake.in
new file mode 100644
index 0000000000..a9833b99c9
--- /dev/null
+++ b/Tests/CMakeTests/MessageTest.cmake.in
@@ -0,0 +1,30 @@
+execute_process(
+ COMMAND ${CMAKE_COMMAND} -P
+ "@CMAKE_CURRENT_SOURCE_DIR@/MessageTestScript.cmake"
+ OUTPUT_VARIABLE out
+ ERROR_VARIABLE err
+ RESULT_VARIABLE result
+ )
+
+message("out=[${out}]")
+message("err=[${err}]")
+
+if(NOT "${result}" STREQUAL "0")
+ message(FATAL_ERROR "message script failed: [${result}]")
+endif()
+
+if(NOT "${out}" MATCHES "message-status")
+ message(FATAL_ERROR "message(STATUS) did not go to stdout")
+endif()
+
+if(NOT "${err}" MATCHES "message-default")
+ message(FATAL_ERROR "message() did not go to stderr by default")
+endif()
+
+if(NOT "${err}" MATCHES "CMake Warning at[^\n]*:\r?\n message-warning")
+ message(FATAL_ERROR "message(WARNING) did not appear properly")
+endif()
+
+if(NOT "${err}" MATCHES "CMake Warning \\(dev\\) at[^\n]*:\r?\n message-author")
+ message(FATAL_ERROR "message(AUTHOR_WARNING) did not appear properly")
+endif()
diff --git a/Tests/CMakeTests/MessageTestScript.cmake b/Tests/CMakeTests/MessageTestScript.cmake
new file mode 100644
index 0000000000..c56f88e15f
--- /dev/null
+++ b/Tests/CMakeTests/MessageTestScript.cmake
@@ -0,0 +1,4 @@
+message("message-default")
+message(STATUS "message-status")
+message(WARNING "message-warning")
+message(AUTHOR_WARNING "message-author")
diff --git a/Tests/CMakeTests/ModuleNoticesTest.cmake.in b/Tests/CMakeTests/ModuleNoticesTest.cmake.in
new file mode 100644
index 0000000000..8ecebd338f
--- /dev/null
+++ b/Tests/CMakeTests/ModuleNoticesTest.cmake.in
@@ -0,0 +1,46 @@
+# Regex to match copyright/license notices.
+# We require the Kitware copyright on the first line, but this can
+# match any additional copyright holder notices.
+set(notice_regex "
+#=============================================================================
+# Copyright (20[0-9][0-9]-)?20[0-9][0-9] [^\n]+(
+# Copyright (20[0-9][0-9]-)?20[0-9][0-9] [^\n]+)*
+#
+# 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.\\)
+")
+string(REPLACE "\n" "\r?\n" notice_regex "${notice_regex}")
+string(REPLACE "\r\r" "\r" notice_regex "${notice_regex}")
+
+# Modules that do not require our notice.
+set(notice_exceptions
+ FindCUDA.cmake # MIT License, distributed here from upstream project
+ )
+
+# Load the list of modules to check.
+set(dir "@CMake_SOURCE_DIR@/Modules")
+file(GLOB all_modules RELATIVE "${dir}" "${dir}/*.cmake")
+list(REMOVE_ITEM all_modules ${notice_exceptions})
+
+# Check each module.
+set(notice_missing)
+foreach(module ${all_modules})
+ message(STATUS "module: ${module}")
+ file(READ "${dir}/${module}" module_content)
+ if(NOT "${module_content}" MATCHES "${notice_regex}")
+ set(notice_missing "${notice_missing} ${module}\n")
+ endif()
+endforeach()
+
+# Report the list of bad modules.
+if(notice_missing)
+ message(FATAL_ERROR
+ "Some modules do not have a valid copyright notice:\n${notice_missing}")
+endif()
diff --git a/Tests/CMakeTests/PolicyCheckTest.cmake.in b/Tests/CMakeTests/PolicyCheckTest.cmake.in
new file mode 100644
index 0000000000..416dc0a75f
--- /dev/null
+++ b/Tests/CMakeTests/PolicyCheckTest.cmake.in
@@ -0,0 +1,154 @@
+# Check the CMake source tree for suspicious policy introdcutions...
+#
+message("=============================================================================")
+message("CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+message("")
+message("CMake_BINARY_DIR='${CMake_BINARY_DIR}'")
+message("CMake_SOURCE_DIR='${CMake_SOURCE_DIR}'")
+message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
+message("")
+
+
+# If this does not appear to be a git checkout, just pass the test here
+# and now. (Do not let the test fail if it is run in a tree *exported* from a
+# repository or unpacked from a .zip file source installer...)
+#
+set(is_git_checkout 0)
+if(EXISTS "${CMake_SOURCE_DIR}/.git")
+ set(is_git_checkout 1)
+endif()
+
+message("is_git_checkout='${is_git_checkout}'")
+message("")
+
+if(NOT is_git_checkout)
+ message("source tree is not a git checkout... test passes by early return...")
+ return()
+endif()
+
+# If no GIT_EXECUTABLE, see if we can figure out which git was used
+# for the ctest_update step on this dashboard...
+#
+if(is_git_checkout AND NOT GIT_EXECUTABLE)
+ set(ctest_ini_file "")
+ set(exe "")
+
+ # Use the old name:
+ if(EXISTS "${CMake_BINARY_DIR}/DartConfiguration.tcl")
+ set(ctest_ini_file "${CMake_BINARY_DIR}/DartConfiguration.tcl")
+ endif()
+
+ # But if it exists, prefer the new name:
+ if(EXISTS "${CMake_BINARY_DIR}/CTestConfiguration.ini")
+ set(ctest_ini_file "${CMake_BINARY_DIR}/CTestConfiguration.ini")
+ endif()
+
+ # If there is a ctest ini file, read the update command or git command
+ # from it:
+ #
+ if(ctest_ini_file)
+ file(STRINGS "${ctest_ini_file}" line REGEX "^GITCommand: (.*)$")
+ string(REGEX REPLACE "^GITCommand: (.*)$" "\\1" line "${line}")
+ if("${line}" MATCHES "^\"")
+ string(REGEX REPLACE "^\"([^\"]+)\" *.*$" "\\1" line "${line}")
+ else()
+ string(REGEX REPLACE "^([^ ]+) *.*$" "\\1" line "${line}")
+ endif()
+ set(exe "${line}")
+ if("${exe}" STREQUAL "GITCOMMAND-NOTFOUND")
+ set(exe "")
+ endif()
+ if(exe)
+ message("info: GIT_EXECUTABLE set by 'GITCommand:' from '${ctest_ini_file}'")
+ endif()
+
+ if(NOT exe)
+ file(STRINGS "${ctest_ini_file}" line REGEX "^UpdateCommand: (.*)$")
+ string(REGEX REPLACE "^UpdateCommand: (.*)$" "\\1" line "${line}")
+ if("${line}" MATCHES "^\"")
+ string(REGEX REPLACE "^\"([^\"]+)\" *.*$" "\\1" line "${line}")
+ else()
+ string(REGEX REPLACE "^([^ ]+) *.*$" "\\1" line "${line}")
+ endif()
+ set(exe "${line}")
+ if("${exe}" STREQUAL "GITCOMMAND-NOTFOUND")
+ set(exe "")
+ endif()
+ if(exe)
+ message("info: GIT_EXECUTABLE set by 'UpdateCommand:' from '${ctest_ini_file}'")
+ endif()
+ endif()
+ else()
+ message("info: no DartConfiguration.tcl or CTestConfiguration.ini file...")
+ endif()
+
+ # If we have still not grokked the exe, look in the Update.xml file to see
+ # if we can parse it from there...
+ #
+ if(NOT exe)
+ file(GLOB_RECURSE update_xml_file "${CMake_BINARY_DIR}/Testing/Update.xml")
+ if(update_xml_file)
+ file(STRINGS "${update_xml_file}" line
+ REGEX "^.*<UpdateCommand>(.*)</UpdateCommand>$" LIMIT_COUNT 1)
+ string(REPLACE "&quot\;" "\"" line "${line}")
+ string(REGEX REPLACE "^.*<UpdateCommand>(.*)</UpdateCommand>$" "\\1" line "${line}")
+ if("${line}" MATCHES "^\"")
+ string(REGEX REPLACE "^\"([^\"]+)\" *.*$" "\\1" line "${line}")
+ else()
+ string(REGEX REPLACE "^([^ ]+) *.*$" "\\1" line "${line}")
+ endif()
+ if(line)
+ set(exe "${line}")
+ endif()
+ if(exe)
+ message("info: GIT_EXECUTABLE set by '<UpdateCommand>' from '${update_xml_file}'")
+ endif()
+ else()
+ message("info: no Update.xml file...")
+ endif()
+ endif()
+
+ if(exe)
+ set(GIT_EXECUTABLE "${exe}")
+ message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
+ message("")
+
+ if(NOT EXISTS "${GIT_EXECUTABLE}")
+ message(FATAL_ERROR "GIT_EXECUTABLE does not exist...")
+ endif()
+ else()
+ message(FATAL_ERROR "could not determine GIT_EXECUTABLE...")
+ endif()
+endif()
+
+
+if(is_git_checkout AND GIT_EXECUTABLE)
+ # Check with "git grep" if there are any unacceptable cmPolicies additions
+ #
+ message("=============================================================================")
+ message("This is a git checkout, using git grep to verify no unacceptable policies")
+ message("are being introduced....")
+ message("")
+
+ execute_process(COMMAND ${GIT_EXECUTABLE} grep -En "[0-9][0-9][0-9][0-9][0-9].*cmPolicies"
+ WORKING_DIRECTORY ${CMake_SOURCE_DIR}
+ OUTPUT_VARIABLE grep_output
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message("=== output of 'git grep -En \"[0-9][0-9][0-9][0-9][0-9].*cmPolicies\"' ===")
+ message("${grep_output}")
+ message("=== end output ===")
+ message("")
+
+ if(NOT "${grep_output}" STREQUAL "")
+ message(FATAL_ERROR "git grep output is non-empty...
+New CMake policies must be introduced in a non-date-based version number.
+Send email to the cmake-developers list to figure out what the target
+version number for this policy should be...")
+ endif()
+endif()
+
+
+# Still here? Good then...
+#
+message("test passes")
+message("")
diff --git a/Tests/CMakeTests/ProcessorCountTest.cmake.in b/Tests/CMakeTests/ProcessorCountTest.cmake.in
new file mode 100644
index 0000000000..f92dcc44c5
--- /dev/null
+++ b/Tests/CMakeTests/ProcessorCountTest.cmake.in
@@ -0,0 +1,79 @@
+include(ProcessorCount)
+
+ProcessorCount(processor_count)
+
+message("### 1. This line should be the first line of text in the test output.")
+message("### 2. If there was output from this test before line #1, then the")
+message("### 3. ProcessorCount(...) function call is emitting output that it shouldn't...")
+
+message("processor_count='${processor_count}'")
+
+execute_process(
+ COMMAND "${KWSYS_TEST_EXE}"
+ testSystemInformation
+ OUTPUT_VARIABLE tsi_out
+ ERROR_VARIABLE tsi_err
+ RESULT_VARIABLE tsi_res
+)
+if (tsi_res)
+ message("executing \"${KWSYS_TEST_EXE}\" failed")
+ message(FATAL_ERROR "output: ${tsi_res}")
+endif ()
+
+string(REGEX REPLACE "(.*)GetNumberOfPhysicalCPU:.([0-9]*)(.*)" "\\2"
+ system_info_processor_count "${tsi_out}")
+
+message("system_info_processor_count='${system_info_processor_count}'")
+
+if(system_info_processor_count EQUAL processor_count)
+ message("processor count matches system information")
+endif()
+
+message("")
+message("CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+message("")
+message("tsi_out='${tsi_out}'")
+message("tsi_err='${tsi_err}'")
+message("")
+
+# Evaluate possible error conditions:
+#
+set(err 0)
+set(fatal 0)
+
+if(processor_count EQUAL 0)
+ set(err 1)
+ set(fatal 1)
+ message("err 1")
+ message("could not determine number of processors
+- Additional code for this platform needed in ProcessorCount.cmake?")
+ message("")
+endif()
+
+if(NOT system_info_processor_count EQUAL processor_count)
+ set(err 2)
+ message("err 2")
+ message("SystemInformation and ProcessorCount.cmake disagree:\n"
+ "processor_count='${processor_count}'\n"
+ "SystemInformation processor_count='${system_info_processor_count}'")
+ message("")
+endif()
+
+if(NOT processor_count MATCHES "^[0-9]+$")
+ set(err 3)
+ set(fatal 1)
+ message("err 3")
+ message("ProcessorCount function returned a non-integer")
+ message("")
+endif()
+
+if(NOT system_info_processor_count MATCHES "^[0-9]+$")
+ set(err 4)
+ message("err 4")
+ message("SystemInformation ProcessorCount function returned a non-integer")
+ message("")
+endif()
+
+if(fatal)
+ message(FATAL_ERROR "processor_count='${processor_count}' - see previous test output for more details - it is likely more/different code is needed in ProcessorCount.cmake to fix this test failure - processor_count should be a non-zero positive integer (>=1) for all supported CMake platforms")
+endif()
diff --git a/Tests/CMakeTests/PushCheckStateTest.cmake.in b/Tests/CMakeTests/PushCheckStateTest.cmake.in
new file mode 100644
index 0000000000..e707b9a927
--- /dev/null
+++ b/Tests/CMakeTests/PushCheckStateTest.cmake.in
@@ -0,0 +1,30 @@
+include(CMakePushCheckState)
+
+set(CMAKE_REQUIRED_DEFINITIONS defs1 )
+
+cmake_push_check_state()
+
+set(CMAKE_REQUIRED_DEFINITIONS defs2)
+
+cmake_push_check_state()
+
+set(CMAKE_REQUIRED_DEFINITIONS defs3)
+
+cmake_pop_check_state()
+
+if (NOT "${CMAKE_REQUIRED_DEFINITIONS}" STREQUAL "defs2")
+ set(fatal TRUE)
+ message("ERROR: "CMAKE_REQUIRED_DEFINITIONS is \"${CMAKE_REQUIRED_DEFINITIONS}\" (expected \"defs2\")" )
+endif()
+
+cmake_pop_check_state()
+
+if (NOT "${CMAKE_REQUIRED_DEFINITIONS}" STREQUAL "defs1")
+ set(fatal TRUE)
+ message("ERROR: "CMAKE_REQUIRED_DEFINITIONS is \"${CMAKE_REQUIRED_DEFINITIONS}\" (expected \"defs1\")" )
+endif()
+
+
+if(fatal)
+ message(FATAL_ERROR "cmake_push_check_state() test failed")
+endif()
diff --git a/Tests/CMakeTests/SeparateArgumentsTest.cmake.in b/Tests/CMakeTests/SeparateArgumentsTest.cmake.in
new file mode 100644
index 0000000000..48964b8cbd
--- /dev/null
+++ b/Tests/CMakeTests/SeparateArgumentsTest.cmake.in
@@ -0,0 +1,25 @@
+set(old_out "a b c")
+separate_arguments(old_out)
+set(old_exp "a;b;;c")
+
+set(unix_cmd "a \"b c\" 'd e' \";\" \\ \\'\\\" '\\'' \"\\\"\"")
+set(unix_exp "a;b c;d e;\;; '\";';\"")
+separate_arguments(unix_out UNIX_COMMAND "${unix_cmd}")
+
+set(windows_cmd "a \"b c\" 'd e' \";\" \\ \"c:\\windows\\path\\\\\" \\\"")
+set(windows_exp "a;b c;'d;e';\;;\\;c:\\windows\\path\\;\"")
+separate_arguments(windows_out WINDOWS_COMMAND "${windows_cmd}")
+
+foreach(mode old unix windows)
+ if(NOT "${${mode}_out}" STREQUAL "${${mode}_exp}")
+ message(FATAL_ERROR "separate_arguments ${mode}-style failed. "
+ "Expected\n [${${mode}_exp}]\nbut got\n [${${mode}_out}]\n")
+ endif()
+endforeach()
+
+set(nothing)
+separate_arguments(nothing)
+if(DEFINED nothing)
+ message(FATAL_ERROR "separate_arguments null-case failed: "
+ "nothing=[${nothing}]")
+endif()
diff --git a/Tests/CMakeTests/String-MD5-BadArg1.cmake b/Tests/CMakeTests/String-MD5-BadArg1.cmake
new file mode 100644
index 0000000000..89464769bc
--- /dev/null
+++ b/Tests/CMakeTests/String-MD5-BadArg1.cmake
@@ -0,0 +1 @@
+string(MD5)
diff --git a/Tests/CMakeTests/String-MD5-BadArg2.cmake b/Tests/CMakeTests/String-MD5-BadArg2.cmake
new file mode 100644
index 0000000000..abbbf879aa
--- /dev/null
+++ b/Tests/CMakeTests/String-MD5-BadArg2.cmake
@@ -0,0 +1 @@
+string(MD5 md5)
diff --git a/Tests/CMakeTests/String-MD5-BadArg4.cmake b/Tests/CMakeTests/String-MD5-BadArg4.cmake
new file mode 100644
index 0000000000..edd442762d
--- /dev/null
+++ b/Tests/CMakeTests/String-MD5-BadArg4.cmake
@@ -0,0 +1 @@
+string(MD5 md5 input extra_arg)
diff --git a/Tests/CMakeTests/String-MD5-Works.cmake b/Tests/CMakeTests/String-MD5-Works.cmake
new file mode 100644
index 0000000000..4ef7a07547
--- /dev/null
+++ b/Tests/CMakeTests/String-MD5-Works.cmake
@@ -0,0 +1,2 @@
+string(MD5 md5 "sample input string\n")
+message("${md5}")
diff --git a/Tests/CMakeTests/String-SHA1-Works.cmake b/Tests/CMakeTests/String-SHA1-Works.cmake
new file mode 100644
index 0000000000..2f3b51b61f
--- /dev/null
+++ b/Tests/CMakeTests/String-SHA1-Works.cmake
@@ -0,0 +1,2 @@
+string(SHA1 sha1 "sample input string\n")
+message("${sha1}")
diff --git a/Tests/CMakeTests/String-SHA224-Works.cmake b/Tests/CMakeTests/String-SHA224-Works.cmake
new file mode 100644
index 0000000000..5b7f880ee7
--- /dev/null
+++ b/Tests/CMakeTests/String-SHA224-Works.cmake
@@ -0,0 +1,2 @@
+string(SHA224 sha224 "sample input string\n")
+message("${sha224}")
diff --git a/Tests/CMakeTests/String-SHA256-Works.cmake b/Tests/CMakeTests/String-SHA256-Works.cmake
new file mode 100644
index 0000000000..e3e89ae5d1
--- /dev/null
+++ b/Tests/CMakeTests/String-SHA256-Works.cmake
@@ -0,0 +1,2 @@
+string(SHA256 sha256 "sample input string\n")
+message("${sha256}")
diff --git a/Tests/CMakeTests/String-SHA384-Works.cmake b/Tests/CMakeTests/String-SHA384-Works.cmake
new file mode 100644
index 0000000000..828a190314
--- /dev/null
+++ b/Tests/CMakeTests/String-SHA384-Works.cmake
@@ -0,0 +1,2 @@
+string(SHA384 sha384 "sample input string\n")
+message("${sha384}")
diff --git a/Tests/CMakeTests/String-SHA512-Works.cmake b/Tests/CMakeTests/String-SHA512-Works.cmake
new file mode 100644
index 0000000000..e17db5c6ea
--- /dev/null
+++ b/Tests/CMakeTests/String-SHA512-Works.cmake
@@ -0,0 +1,2 @@
+string(SHA512 sha512 "sample input string\n")
+message("${sha512}")
diff --git a/Tests/CMakeTests/String-TIMESTAMP-AllSpecifiers.cmake b/Tests/CMakeTests/String-TIMESTAMP-AllSpecifiers.cmake
new file mode 100644
index 0000000000..2d0fcc89c7
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-AllSpecifiers.cmake
@@ -0,0 +1,11 @@
+string(TIMESTAMP output "%d;%H;%I;%j;%m;%M;%S;%U;%w;%y;%Y")
+message("~${output}~")
+
+list(LENGTH output output_length)
+
+set(expected_output_length 11)
+
+if(NOT output_length EQUAL ${expected_output_length})
+ message(FATAL_ERROR "expected ${expected_output_length} entries in output "
+ "with all specifiers; found ${output_length}")
+endif()
diff --git a/Tests/CMakeTests/String-TIMESTAMP-BadArg1.cmake b/Tests/CMakeTests/String-TIMESTAMP-BadArg1.cmake
new file mode 100644
index 0000000000..8f2d9f8b4b
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-BadArg1.cmake
@@ -0,0 +1 @@
+string(TIMESTAMP)
diff --git a/Tests/CMakeTests/String-TIMESTAMP-BadArg2.cmake b/Tests/CMakeTests/String-TIMESTAMP-BadArg2.cmake
new file mode 100644
index 0000000000..c1e5126842
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-BadArg2.cmake
@@ -0,0 +1 @@
+string(TIMESTAMP output_variable "%Y" UTF)
diff --git a/Tests/CMakeTests/String-TIMESTAMP-BadArg3.cmake b/Tests/CMakeTests/String-TIMESTAMP-BadArg3.cmake
new file mode 100644
index 0000000000..3d577df3f8
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-BadArg3.cmake
@@ -0,0 +1 @@
+string(TIMESTAMP output_variable "%Y" UTC UTC)
diff --git a/Tests/CMakeTests/String-TIMESTAMP-CustomFormatLocal.cmake b/Tests/CMakeTests/String-TIMESTAMP-CustomFormatLocal.cmake
new file mode 100644
index 0000000000..eab2a45de4
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-CustomFormatLocal.cmake
@@ -0,0 +1,2 @@
+string(TIMESTAMP output "%S")
+message("~${output}~")
diff --git a/Tests/CMakeTests/String-TIMESTAMP-CustomFormatUTC.cmake b/Tests/CMakeTests/String-TIMESTAMP-CustomFormatUTC.cmake
new file mode 100644
index 0000000000..eab2a45de4
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-CustomFormatUTC.cmake
@@ -0,0 +1,2 @@
+string(TIMESTAMP output "%S")
+message("~${output}~")
diff --git a/Tests/CMakeTests/String-TIMESTAMP-DefaultFormatLocal.cmake b/Tests/CMakeTests/String-TIMESTAMP-DefaultFormatLocal.cmake
new file mode 100644
index 0000000000..d7c7dde1ca
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-DefaultFormatLocal.cmake
@@ -0,0 +1,2 @@
+string(TIMESTAMP output)
+message("~${output}~")
diff --git a/Tests/CMakeTests/String-TIMESTAMP-DefaultFormatUTC.cmake b/Tests/CMakeTests/String-TIMESTAMP-DefaultFormatUTC.cmake
new file mode 100644
index 0000000000..dad6a8d97d
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-DefaultFormatUTC.cmake
@@ -0,0 +1,2 @@
+string(TIMESTAMP output UTC)
+message("~${output}~")
diff --git a/Tests/CMakeTests/String-TIMESTAMP-IncompleteSpecifier.cmake b/Tests/CMakeTests/String-TIMESTAMP-IncompleteSpecifier.cmake
new file mode 100644
index 0000000000..ffc5656fab
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-IncompleteSpecifier.cmake
@@ -0,0 +1,2 @@
+string(TIMESTAMP output "foobar%")
+message("~${output}~")
diff --git a/Tests/CMakeTests/String-TIMESTAMP-UnknownSpecifier.cmake b/Tests/CMakeTests/String-TIMESTAMP-UnknownSpecifier.cmake
new file mode 100644
index 0000000000..0e145e5ec9
--- /dev/null
+++ b/Tests/CMakeTests/String-TIMESTAMP-UnknownSpecifier.cmake
@@ -0,0 +1,2 @@
+string(TIMESTAMP output "%g")
+message("~${output}~")
diff --git a/Tests/CMakeTests/StringTest.cmake.in b/Tests/CMakeTests/StringTest.cmake.in
new file mode 100644
index 0000000000..a9fe428e38
--- /dev/null
+++ b/Tests/CMakeTests/StringTest.cmake.in
@@ -0,0 +1,80 @@
+set(MD5-BadArg1-RESULT 1)
+set(MD5-BadArg1-STDERR "string MD5 requires an output variable")
+set(MD5-BadArg2-RESULT 1)
+set(MD5-BadArg2-STDERR "string MD5 requires an output variable and an input string")
+set(MD5-BadArg4-RESULT 1)
+set(MD5-BadArg4-STDERR "string MD5 requires an output variable and an input string")
+set(MD5-Works-RESULT 0)
+set(MD5-Works-STDERR "10d20ddb981a6202b84aa1ce1cb7fce3")
+set(SHA1-Works-RESULT 0)
+set(SHA1-Works-STDERR "83f093e04289b21a9415f408ad50be8b57ad2f34")
+set(SHA224-Works-RESULT 0)
+set(SHA224-Works-STDERR "e995a7789922c4ef9279d94e763c8375934180a51baa7147bc48edf7")
+set(SHA256-Works-RESULT 0)
+set(SHA256-Works-STDERR "d1c5915d8b71150726a1eef75a29ec6bea8fd1bef6b7299ef8048760b0402025")
+set(SHA384-Works-RESULT 0)
+set(SHA384-Works-STDERR "1de9560b4e030e02051ea408200ffc55d70c97ac64ebf822461a5c786f495c36df43259b14483bc8d364f0106f4971ee")
+set(SHA512-Works-RESULT 0)
+set(SHA512-Works-STDERR "3982a1b4e651768bec70ab1fb97045cb7a659f4ba7203d501c52ab2e803071f9d5fd272022df15f27727fc67f8cd022e710e29010b2a9c0b467c111e2f6abf51")
+set(TIMESTAMP-BadArg1-RESULT 1)
+set(TIMESTAMP-BadArg1-STDERR "string sub-command TIMESTAMP requires at least one argument")
+set(TIMESTAMP-BadArg2-RESULT 1)
+set(TIMESTAMP-BadArg2-STDERR "string TIMESTAMP sub-command does not recognize option UTF")
+set(TIMESTAMP-BadArg3-RESULT 1)
+set(TIMESTAMP-BadArg3-STDERR "string sub-command TIMESTAMP takes at most three arguments")
+set(TIMESTAMP-DefaultFormatLocal-RESULT 0)
+set(TIMESTAMP-DefaultFormatLocal-STDERR "~[0-9]*-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-6][0-9]~")
+set(TIMESTAMP-DefaultFormatUTC-RESULT 0)
+set(TIMESTAMP-DefaultFormatUTC-STDERR "~[0-9]*-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-6][0-9]Z~")
+set(TIMESTAMP-CustomFormatLocal-RESULT 0)
+set(TIMESTAMP-CustomFormatLocal-STDERR "~([0-5][0-9])|60~")
+set(TIMESTAMP-CustomFormatUTC-RESULT 0)
+set(TIMESTAMP-CustomFormatUTC-STDERR "~([0-5][0-9])|60~")
+set(TIMESTAMP-UnknownSpecifier-RESULT 0)
+set(TIMESTAMP-UnknownSpecifier-STDERR "~%g~")
+set(TIMESTAMP-IncompleteSpecifier-RESULT 0)
+set(TIMESTAMP-IncompleteSpecifier-STDERR "~foobar%~")
+set(TIMESTAMP-AllSpecifiers-RESULT 0)
+set(TIMESTAMP-AllSpecifiers-STDERR "~[0-9]+(;[0-9]+)*~")
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
+check_cmake_test(String
+ MD5-BadArg1
+ MD5-BadArg2
+ MD5-BadArg4
+ MD5-Works
+ SHA1-Works
+ SHA224-Works
+ SHA256-Works
+ SHA384-Works
+ SHA512-Works
+ TIMESTAMP-BadArg1
+ TIMESTAMP-BadArg2
+ TIMESTAMP-BadArg3
+ TIMESTAMP-DefaultFormatLocal
+ TIMESTAMP-DefaultFormatUTC
+ TIMESTAMP-CustomFormatLocal
+ TIMESTAMP-CustomFormatUTC
+ TIMESTAMP-UnknownSpecifier
+ TIMESTAMP-IncompleteSpecifier
+ TIMESTAMP-AllSpecifiers
+ )
+
+# Execute each test listed in StringTestScript.cmake:
+#
+set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/StringTestScript.cmake")
+set(number_of_tests_expected 69)
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/ExecuteScriptTests.cmake")
+execute_all_script_tests(${scriptname} number_of_tests_executed)
+
+# And verify that number_of_tests_executed is at least as many as we know
+# about as of this writing...
+#
+message(STATUS "scriptname='${scriptname}'")
+message(STATUS "number_of_tests_executed='${number_of_tests_executed}'")
+message(STATUS "number_of_tests_expected='${number_of_tests_expected}'")
+
+if(number_of_tests_executed LESS number_of_tests_expected)
+ message(FATAL_ERROR "error: some test cases were skipped")
+endif()
diff --git a/Tests/CMakeTests/StringTestScript.cmake b/Tests/CMakeTests/StringTestScript.cmake
new file mode 100644
index 0000000000..a562e71d38
--- /dev/null
+++ b/Tests/CMakeTests/StringTestScript.cmake
@@ -0,0 +1,279 @@
+message(STATUS "testname='${testname}'")
+
+if(testname STREQUAL empty) # fail
+ string()
+
+elseif(testname STREQUAL bogus) # fail
+ string(BOGUS)
+
+elseif(testname STREQUAL random) # pass
+ string(RANDOM r)
+ message(STATUS "r='${r}'")
+
+elseif(testname STREQUAL toupper_no_variable) # fail
+ string(TOUPPER)
+
+elseif(testname STREQUAL ascii_no_variable) # fail
+ string(ASCII)
+
+elseif(testname STREQUAL ascii_code_too_small) # fail
+ string(ASCII -1 bummer)
+
+elseif(testname STREQUAL ascii_code_too_large) # fail
+ string(ASCII 288 bummer)
+
+elseif(testname STREQUAL configure_no_input) # fail
+ string(CONFIGURE)
+
+elseif(testname STREQUAL configure_no_variable) # fail
+ string(CONFIGURE "this is @testname@")
+
+elseif(testname STREQUAL configure_escape_quotes) # pass
+ string(CONFIGURE "this is @testname@" v ESCAPE_QUOTES)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL configure_bogus) # fail
+ string(CONFIGURE "this is @testname@" v ESCAPE_QUOTES BOGUS)
+
+elseif(testname STREQUAL regex_no_mode) # fail
+ string(REGEX)
+
+elseif(testname STREQUAL regex_match_not_enough_args) # fail
+ string(REGEX MATCH)
+
+elseif(testname STREQUAL regex_matchall_not_enough_args) # fail
+ string(REGEX MATCHALL)
+
+elseif(testname STREQUAL regex_replace_not_enough_args) # fail
+ string(REGEX REPLACE)
+
+elseif(testname STREQUAL regex_bogus_mode) # fail
+ string(REGEX BOGUS)
+
+elseif(testname STREQUAL regex_match_multiple_inputs) # pass
+ string(REGEX MATCH ".*" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_match_bad_regex) # fail
+ string(REGEX MATCH "(.*" v input)
+
+elseif(testname STREQUAL regex_match_empty_string) # fail
+ string(REGEX MATCH "x*" v "")
+
+elseif(testname STREQUAL regex_match_no_match) # pass
+ string(REGEX MATCH "xyz" v "abc")
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_matchall_multiple_inputs) # pass
+ string(REGEX MATCHALL "input" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_matchall_bad_regex) # fail
+ string(REGEX MATCHALL "(.*" v input)
+
+elseif(testname STREQUAL regex_matchall_empty_string) # fail
+ string(REGEX MATCHALL "x*" v "")
+
+elseif(testname STREQUAL regex_replace_ends_with_backslash) # fail
+ string(REGEX REPLACE "input" "output\\" v input1 input2 input3 input4)
+
+elseif(testname STREQUAL regex_replace_ends_with_escaped_backslash) # pass
+ string(REGEX REPLACE "input" "output\\\\" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_replace_has_linefeed) # pass
+ string(REGEX REPLACE "input" "output\\n" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_replace_has_bogus_escape) # fail
+ string(REGEX REPLACE "input" "output\\a" v input1 input2 input3 input4)
+
+elseif(testname STREQUAL regex_replace_bad_regex) # fail
+ string(REGEX REPLACE "this (.*" "with that" v input)
+
+elseif(testname STREQUAL regex_replace_empty_string) # fail
+ string(REGEX REPLACE "x*" "that" v "")
+
+elseif(testname STREQUAL regex_replace_index_too_small) # fail
+ string(REGEX REPLACE "^this (.*)$" "with \\1 \\-1" v "this input")
+
+elseif(testname STREQUAL regex_replace_index_too_large) # fail
+ string(REGEX REPLACE "^this (.*)$" "with \\1 \\2" v "this input")
+
+elseif(testname STREQUAL compare_no_mode) # fail
+ string(COMPARE)
+
+elseif(testname STREQUAL compare_bogus_mode) # fail
+ string(COMPARE BOGUS)
+
+elseif(testname STREQUAL compare_not_enough_args) # fail
+ string(COMPARE EQUAL)
+
+elseif(testname STREQUAL replace_not_enough_args) # fail
+ string(REPLACE)
+
+elseif(testname STREQUAL replace_multiple_inputs) # pass
+ string(REPLACE "input" "output" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL substring_not_enough_args) # fail
+ string(SUBSTRING)
+
+elseif(testname STREQUAL substring_begin_too_large) # fail
+ string(SUBSTRING "abcdefg" 25 100 v)
+
+elseif(testname STREQUAL substring_end_too_large) # fail
+ string(SUBSTRING "abcdefg" 1 100 v)
+
+elseif(testname STREQUAL substring_begin_less_than_zero) # fail
+ string(SUBSTRING "abcdefg" -2 4 v)
+
+elseif(testname STREQUAL substring_end_less_than_begin) # fail
+ string(SUBSTRING "abcdefg" 6 3 v)
+
+elseif(testname STREQUAL length_not_enough_args) # fail
+ string(LENGTH)
+
+elseif(testname STREQUAL strip_not_enough_args) # fail
+ string(STRIP)
+
+elseif(testname STREQUAL random_not_enough_args) # fail
+ string(RANDOM)
+
+elseif(testname STREQUAL random_3_args) # fail
+ string(RANDOM LENGTH 9)
+
+elseif(testname STREQUAL random_5_args) # fail
+ string(RANDOM LENGTH 9 ALPHABET "aceimnorsuvwxz")
+
+elseif(testname STREQUAL random_with_length) # pass
+ string(RANDOM LENGTH 9 v)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL random_with_alphabet) # pass
+ string(RANDOM ALPHABET "aceimnorsuvwxz" v)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL random_bad_length) # fail
+ string(RANDOM LENGTH 0 v)
+
+elseif(testname STREQUAL random_empty_alphabet) # pass
+ string(RANDOM ALPHABET "" v)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL random_with_length_and_alphabet) # pass
+ string(RANDOM LENGTH 9 ALPHABET "aceimnorsuvwxz" v)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL random_with_various_alphabets) # pass
+ # small alphabet
+ string(RANDOM LENGTH 32 ALPHABET "ACGT" v)
+ message(STATUS "v='${v}'")
+
+ # smaller alphabet
+ string(RANDOM LENGTH 32 ALPHABET "AB" v)
+ message(STATUS "v='${v}'")
+
+ # smallest alphabet
+ string(RANDOM LENGTH 32 ALPHABET "Z" v)
+ message(STATUS "v='${v}'")
+
+ # smallest length and alphabet
+ string(RANDOM LENGTH 1 ALPHABET "Q" v)
+ message(STATUS "v='${v}'")
+
+ # seed values -- 2 same, then 1 different
+ string(RANDOM LENGTH 32 ALPHABET "ACGT" RANDOM_SEED 987654 v)
+ message(STATUS "v='${v}'")
+ string(RANDOM LENGTH 32 ALPHABET "ACGT" RANDOM_SEED 987654 v)
+ message(STATUS "v='${v}'")
+ string(RANDOM LENGTH 32 ALPHABET "ACGT" RANDOM_SEED 876543 v)
+ message(STATUS "v='${v}'")
+
+ # alphabet of many colors - use all the crazy keyboard characters
+ string(RANDOM LENGTH 78 ALPHABET "~`!@#$%^&*()_-+={}[]\\|:\\;'\",.<>/?" v)
+ message(STATUS "v='${v}'")
+
+ message(STATUS "CMAKE_SCRIPT_MODE_FILE='${CMAKE_SCRIPT_MODE_FILE}'")
+
+elseif(testname STREQUAL string_find_with_no_parameter) # fail
+ string(FIND)
+
+elseif(testname STREQUAL string_find_with_one_parameter) # fail
+ string(FIND "CMake is great.")
+
+elseif(testname STREQUAL string_find_with_two_parameters) # fail
+ string(FIND "CMake is great." "a")
+
+elseif(testname STREQUAL string_find_with_three_parameters) # pass
+ string(FIND "CMake is great." "a" v)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL string_find_with_four_parameters) # fail
+ string(FIND "CMake is great." "a" v v2)
+
+elseif(testname STREQUAL string_find_reverse_with_no_parameter) # fail
+ string(FIND REVERSE)
+
+elseif(testname STREQUAL string_find_reverse_with_one_parameter) # fail
+ string(FIND "CMake is great." REVERSE)
+
+elseif(testname STREQUAL string_find_reverse_with_two_parameters) # fail
+ string(FIND "CMake is great." "a" REVERSE)
+
+elseif(testname STREQUAL string_find_reverse_with_three_parameters) # pass
+ string(FIND "CMake is great." "a" v REVERSE)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL string_find_reverse_with_four_parameters_part1) # fail
+ string(FIND "CMake is great." "a" v v2 REVERSE)
+
+elseif(testname STREQUAL string_find_reverse_with_four_parameters_part2) # fail
+ string(FIND "CMake is great." "a" v REVERSE v2)
+
+elseif(testname STREQUAL string_find_with_no_possible_result) # pass
+ string(FIND "CMake is a great application." "z" v)
+ message(STATUS "v='${v}'")
+ if(NOT(-1 EQUAL ${v}))
+ message(SEND_ERROR "FIND sub-command should return -1 but returned ${v}.")
+ endif()
+
+elseif(testname STREQUAL string_find_reverse_with_no_possible_result) # pass
+ string(FIND "CMake is a great application." "z" v REVERSE)
+ message(STATUS "v='${v}'")
+ if(NOT(-1 EQUAL ${v}))
+ message(SEND_ERROR "FIND REVERSE sub-command should return -1 but returned ${v}.")
+ endif()
+
+elseif(testname STREQUAL string_find_with_required_result) # pass
+ string(FIND "CMake is a great application." "g" v)
+ message(STATUS "v='${v}'")
+ if(NOT(11 EQUAL ${v}))
+ message(SEND_ERROR "FIND sub-command should return 11 but returned ${v}.")
+ endif()
+
+elseif(testname STREQUAL string_find_reverse_with_required_result) # pass
+ string(FIND "CMake is a great application." "e" v REVERSE)
+ message(STATUS "v='${v}'")
+ if(NOT(13 EQUAL ${v}))
+ message(SEND_ERROR "FIND REVERSE sub-command should return 13 but returned ${v}.")
+ endif()
+
+elseif(testname STREQUAL string_find_word_reverse_with_required_result) # pass
+ string(FIND "The command should find REVERSE in this string. Or maybe this REVERSE?!" "REVERSE" v)
+ message(STATUS "v='${v}'")
+ if(NOT(24 EQUAL ${v}))
+ message(SEND_ERROR "FIND sub-command should return 24 but returned ${v}.")
+ endif()
+
+elseif(testname STREQUAL string_find_reverse_word_reverse_with_required_result) # pass
+ string(FIND "The command should find REVERSE in this string. Or maybe this REVERSE?!" "REVERSE" v REVERSE)
+ message(STATUS "v='${v}'")
+ if(NOT(62 EQUAL ${v}))
+ message(SEND_ERROR "FIND sub-command should return 62 but returned ${v}.")
+ endif()
+
+else() # fail
+ message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'")
+
+endif()
diff --git a/Tests/CMakeTests/ToolchainTest.cmake.in b/Tests/CMakeTests/ToolchainTest.cmake.in
new file mode 100644
index 0000000000..96e7196a54
--- /dev/null
+++ b/Tests/CMakeTests/ToolchainTest.cmake.in
@@ -0,0 +1,139 @@
+############################################################
+# some preparations so that the CMakeDetermineXXX.cmake files will work in scripted mode
+
+# overwrite mark_as_advanced(), since this is used in CMakeDetermineCCompiler.cmake
+# which will complain that it can"t be used in script mode
+macro(MARK_AS_ADVANCED)
+endmacro()
+# set this to a place where we are allowed to write
+set(CMAKE_PLATFORM_INFO_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+
+# don't run the compiler detection
+set(CMAKE_C_COMPILER_ID_RUN 1)
+set(CMAKE_CXX_COMPILER_ID_RUN 1)
+
+set(MY_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
+
+# at first load CMakeDetermineSystem.cmake without toolchain file
+set(CMAKE_TOOLCHAIN_FILE)
+include(CMakeDetermineSystem)
+
+# check that CMAKE_SYSTEM_XXX and CMAKE_HOST_SYSTEM_xxx are identical
+if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}")
+ message(FATAL_ERROR "CMAKE_SYSTEM_NAME and CMAKE_HOST_SYSTEM_NAME not identical: \"${CMAKE_SYSTEM_NAME}\" vs. \"${CMAKE_HOST_SYSTEM_NAME}\"")
+endif()
+
+if(NOT "${CMAKE_SYSTEM}" STREQUAL "${CMAKE_HOST_SYSTEM}")
+ message(FATAL_ERROR "CMAKE_SYSTEM and CMAKE_HOST_SYSTEM not identical: \"${CMAKE_SYSTEM}\" vs. \"${CMAKE_HOST_SYSTEM}\"")
+endif()
+
+if(NOT "${CMAKE_SYSTEM_VERSION}" STREQUAL "${CMAKE_HOST_SYSTEM_VERSION}")
+ message(FATAL_ERROR "CMAKE_SYSTEM_VERSION and CMAKE_HOST_SYSTEM_VERSION not identical: \"${CMAKE_SYSTEM_VERSION}\" vs. \"${CMAKE_HOST_SYSTEM_VERSION}\"")
+endif()
+
+if(NOT "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}")
+ message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR and CMAKE_HOST_SYSTEM_PROCESSOR not identical: \"${CMAKE_SYSTEM_PROCESSOR}\" vs. \"${CMAKE_HOST_SYSTEM_PROCESSOR}\"")
+endif()
+
+# save the values so we can compare them to CMAKE_HOST_SYSTEM_XXX in the toolchain case
+
+set(NATIVE_SYSTEM "${CMAKE_SYSTEM}")
+set(NATIVE_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
+set(NATIVE_SYSTEM_VERSION "${CMAKE_SYSTEM_VERSION}")
+set(NATIVE_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
+
+# reset them so they will be detected again now
+set(CMAKE_SYSTEM)
+set(CMAKE_SYSTEM_NAME)
+set(CMAKE_SYSTEM_VERSION)
+set(CMAKE_SYSTEM_PROCESSOR)
+set(CMAKE_HOST_SYSTEM)
+set(CMAKE_HOST_SYSTEM_NAME)
+set(CMAKE_HOST_SYSTEM_VERSION)
+set(CMAKE_HOST_SYSTEM_PROCESSOR)
+
+
+############################################################
+
+# now define a toolchain file and check that everything is
+# detected correctly and nothing predefined is overwritten
+
+set(CMAKE_TOOLCHAIN_FILE "${MY_SOURCE_DIR}/DummyToolchain.cmake")
+
+include(CMakeDetermineSystem)
+# make cmake think we are cross compiling for test to work
+set(CMAKE_CROSSCOMPILING TRUE)
+set(CMAKE_C_COMPILER_ID "GNU")
+include(CMakeDetermineCCompiler)
+include(CMakeDetermineCXXCompiler)
+
+#############################################################
+
+# check the results from DetermineSystem
+
+if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Dumdidum")
+ message(FATAL_ERROR "CMAKE_SYSTEM_NAME overwritten: \"${CMAKE_SYSTEM_NAME}\", was: \"Dumdidum\"")
+endif()
+
+if(NOT "${CMAKE_SYSTEM}" STREQUAL "Dumdidum-1.0")
+ message(FATAL_ERROR "CMAKE_SYSTEM wrong: \"${CMAKE_SYSTEM}\", expected: \"Dumdidum-1.0\"")
+endif()
+set(fileOne "${_INCLUDED_TOOLCHAIN_FILE}")
+set(fileTwo "${MY_SOURCE_DIR}/DummyToolchain.cmake")
+if(WIN32)
+ string(TOLOWER "${fileOne}" fileOne)
+ string(TOLOWER "${fileTwo}" fileTwo)
+endif()
+
+if(NOT "${fileOne}" STREQUAL "${fileTwo}")
+ message(FATAL_ERROR "Wrong toolchain was loaded: \"${fileOne}\" expected \"${fileTwo}\"")
+endif()
+
+# check that CMAKE_HOST_SYSTEM_XXX and _SYSTEM_xxx detected above are identical
+if(NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "${NATIVE_SYSTEM_NAME}")
+ message(FATAL_ERROR "CMAKE_HOST_SYSTEM_NAME and NATIVE_SYSTEM_NAME not identical: \"${CMAKE_HOST_SYSTEM_NAME}\" vs. \"${NATIVE_SYSTEM_NAME}\"")
+endif()
+if(NOT "${CMAKE_HOST_SYSTEM}" STREQUAL "${NATIVE_SYSTEM}")
+ message(FATAL_ERROR "CMAKE_HOST_SYSTEM and NATIVE_SYSTEM not identical: \"${CMAKE_HOST_SYSTEM}\" vs. \"${NATIVE_SYSTEM}\"")
+endif()
+if(NOT "${CMAKE_HOST_SYSTEM_VERSION}" STREQUAL "${NATIVE_SYSTEM_VERSION}")
+ message(FATAL_ERROR "CMAKE_HOST_SYSTEM_VERSION and NATIVE_SYSTEM_VERSION not identical: \"${CMAKE_HOST_SYSTEM_VERSION}\" vs. \"${NATIVE_SYSTEM_VERSION}\"")
+endif()
+if(NOT "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "${NATIVE_SYSTEM_PROCESSOR}")
+ message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR and NATIVE_SYSTEM_PROCESSOR not identical: \"${CMAKE_HOST_SYSTEM_PROCESSOR}\" vs. \"${NATIVE_SYSTEM_PROCESSOR}\"")
+endif()
+
+#############################################################
+
+# check the results from DetermineCCompiler
+
+if(NOT "${_CMAKE_TOOLCHAIN_PREFIX}" STREQUAL "arm-elf-")
+ message(FATAL_ERROR "wrong toolchain prefix detected: \"${_CMAKE_TOOLCHAIN_PREFIX}\", expected: \"arm-elf-\"")
+endif()
+
+if(NOT "${_CMAKE_USER_C_COMPILER_PATH}" STREQUAL "/opt/foo/bin")
+ message(FATAL_ERROR "wrong C compiler location detected: \"${_CMAKE_USER_C_COMPILER_PATH}\", expected: \"/opt/foo/bin\"")
+endif()
+
+if(NOT "${CMAKE_C_OUTPUT_EXTENSION}" STREQUAL ".foo")
+ message(FATAL_ERROR "C output extension overwritten: \"${CMAKE_C_OUTPUT_EXTENSION}\", was: \".foo\"")
+endif()
+
+#############################################################
+
+# check the results from DetermineCXXCompiler
+
+if(NOT "${_CMAKE_USER_CXX_COMPILER_PATH}" STREQUAL "/opt/bar/bin")
+ message(FATAL_ERROR "wrong CXX compiler location detected: \"${_CMAKE_USER_CXX_COMPILER_PATH}\", expected: \"/opt/bar/bin\"")
+endif()
+
+if(NOT "${CMAKE_CXX_OUTPUT_EXTENSION}" STREQUAL ".bar")
+ message(FATAL_ERROR "C output extension overwritten: \"${CMAKE_CXX_OUTPUT_EXTENSION}\", was: \".bar\"")
+endif()
+
+message(STATUS "CMAKE_SYSTEM: \"${CMAKE_SYSTEM}\"")
+message(STATUS "_CMAKE_TOOLCHAIN_PREFIX: \"${_CMAKE_TOOLCHAIN_PREFIX}\"")
+message(STATUS "_CMAKE_USER_C_COMPILER_PATH: \"${_CMAKE_USER_C_COMPILER_PATH}\"")
+message(STATUS "_CMAKE_USER_CXX_COMPILER_PATH: \"${_CMAKE_USER_CXX_COMPILER_PATH}\"")
+message(STATUS "CMAKE_C_OUTPUT_EXTENSION: \"${CMAKE_C_OUTPUT_EXTENSION}\"")
+message(STATUS "CMAKE_CXX_OUTPUT_EXTENSION: \"${CMAKE_CXX_OUTPUT_EXTENSION}\"")
diff --git a/Tests/CMakeTests/VariableWatchTest.cmake.in b/Tests/CMakeTests/VariableWatchTest.cmake.in
new file mode 100644
index 0000000000..0c084fde87
--- /dev/null
+++ b/Tests/CMakeTests/VariableWatchTest.cmake.in
@@ -0,0 +1,31 @@
+message("Start")
+
+variable_watch(TESTVAR MESSAGE)
+variable_watch(TESTVAR1)
+
+macro(testwatch var access file stack)
+ message("There was a ${access} access done on the variable: ${var} in file ${file}")
+ message("List file stack is: ${stack}")
+ set(${var}_watched 1)
+endmacro()
+
+variable_watch(somevar testwatch)
+
+set(TESTVAR1 "1")
+set(TESTVAR "1")
+set(TESTVAR1 "0")
+set(TESTVAR "0")
+
+
+message("Variable: ${somevar}")
+if(NOT somevar_watched)
+ message(SEND_ERROR "'somevar' watch failed!")
+endif()
+set(somevar_watched)
+
+set(somevar "1")
+message("Variable: ${somevar}")
+if(NOT somevar_watched)
+ message(SEND_ERROR "'somevar' watch failed!")
+endif()
+remove(somevar)
diff --git a/Tests/CMakeTests/VersionTest.cmake.in b/Tests/CMakeTests/VersionTest.cmake.in
new file mode 100644
index 0000000000..9e31cb4311
--- /dev/null
+++ b/Tests/CMakeTests/VersionTest.cmake.in
@@ -0,0 +1,16 @@
+set(min_ver 2.7.20090305)
+cmake_minimum_required(VERSION ${min_ver})
+
+if("${CMAKE_VERSION}" VERSION_LESS "${min_ver}")
+ message(FATAL_ERROR
+ "CMAKE_VERSION=[${CMAKE_VERSION}] is less than [${min_ver}]")
+else()
+ message("CMAKE_VERSION=[${CMAKE_VERSION}] is not less than [${min_ver}]")
+endif()
+
+set(v 1.2.3.4.5.6.7)
+if("${v}.8" VERSION_LESS "${v}.9")
+ message(STATUS "${v}.8 is less than ${v}.9")
+else()
+ message(FATAL_ERROR "${v}.8 is not less than ${v}.9?")
+endif()
diff --git a/Tests/CMakeTests/While-Endwhile-Alone-Args.cmake b/Tests/CMakeTests/While-Endwhile-Alone-Args.cmake
new file mode 100644
index 0000000000..886d98c7c6
--- /dev/null
+++ b/Tests/CMakeTests/While-Endwhile-Alone-Args.cmake
@@ -0,0 +1 @@
+endwhile(a)
diff --git a/Tests/CMakeTests/While-Endwhile-Alone.cmake b/Tests/CMakeTests/While-Endwhile-Alone.cmake
new file mode 100644
index 0000000000..82c09a07bf
--- /dev/null
+++ b/Tests/CMakeTests/While-Endwhile-Alone.cmake
@@ -0,0 +1 @@
+endwhile()
diff --git a/Tests/CMakeTests/While-Endwhile-Mismatch.cmake b/Tests/CMakeTests/While-Endwhile-Mismatch.cmake
new file mode 100644
index 0000000000..5c338d6974
--- /dev/null
+++ b/Tests/CMakeTests/While-Endwhile-Mismatch.cmake
@@ -0,0 +1,2 @@
+while(a)
+endwhile(b)
diff --git a/Tests/CMakeTests/While-Missing-Argument.cmake b/Tests/CMakeTests/While-Missing-Argument.cmake
new file mode 100644
index 0000000000..32eaa2698f
--- /dev/null
+++ b/Tests/CMakeTests/While-Missing-Argument.cmake
@@ -0,0 +1 @@
+while()
diff --git a/Tests/CMakeTests/While-Missing-Endwhile.cmake b/Tests/CMakeTests/While-Missing-Endwhile.cmake
new file mode 100644
index 0000000000..1abaaaf2b1
--- /dev/null
+++ b/Tests/CMakeTests/While-Missing-Endwhile.cmake
@@ -0,0 +1 @@
+while(a)
diff --git a/Tests/CMakeTests/WhileTest.cmake.in b/Tests/CMakeTests/WhileTest.cmake.in
new file mode 100644
index 0000000000..d4cf7d7dc4
--- /dev/null
+++ b/Tests/CMakeTests/WhileTest.cmake.in
@@ -0,0 +1,57 @@
+set(NUMBERS "")
+set(COUNT 0)
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/../RegexEscapeString.cmake")
+REGEX_ESCAPE_STRING(CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
+
+while(COUNT LESS 200)
+ set(NUMBERS "${NUMBERS} ${COUNT}")
+ set(COUNT "2${COUNT}")
+
+ set(NCOUNT 3)
+ while(NCOUNT LESS 31)
+ set(NUMBERS "${NUMBERS} ${NCOUNT}")
+ set(NCOUNT "${NCOUNT}0")
+ endwhile()
+endwhile()
+
+if(NOT NUMBERS STREQUAL " 0 3 30 20 3 30")
+ message(SEND_ERROR "while loop nesting error, result: '${NUMBERS}'")
+endif()
+
+
+set(Missing-Argument-RESULT 1)
+set(Missing-Argument-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?While-Missing-Argument.cmake:1 \\(while\\):.*while called with incorrect number of arguments.*")
+
+include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
+check_cmake_test(While
+ Missing-Argument
+)
+
+set(Missing-Endwhile-RESULT 1)
+set(Missing-Endwhile-STDERR ".*CMake Error in (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?While-Missing-Endwhile.cmake:.*A logical block opening on the line.*(${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?While-Missing-Endwhile.cmake:1 \\(while\\).*is not closed\\..*")
+
+check_cmake_test(While
+ Missing-Endwhile
+)
+
+set(Endwhile-Mismatch-RESULT 0)
+set(Endwhile-Mismatch-STDERR ".*CMake Warning \\(dev\\) in (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?While-Endwhile-Mismatch.cmake:.*A logical block opening on the line.*(${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?While-Endwhile-Mismatch.cmake:1 \\(while\\).*with mis-matching arguments\\..*")
+
+check_cmake_test(While
+ Endwhile-Mismatch
+)
+
+set(Endwhile-Alone-RESULT 1)
+set(Endwhile-Alone-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?While-Endwhile-Alone.cmake:1 \\(endwhile\\):.*An ENDWHILE command was found outside of a proper WHILE ENDWHILE.*structure\\.\n.*$")
+
+check_cmake_test(While
+ Endwhile-Alone
+)
+
+set(Endwhile-Alone-Args-RESULT 1)
+set(Endwhile-Alone-Args-STDERR ".*CMake Error at (${CTEST_ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/)?While-Endwhile-Alone-Args.cmake:1 \\(endwhile\\):.*An ENDWHILE command was found outside of a proper WHILE ENDWHILE.*structure\\. Or its arguments did not.*$")
+
+check_cmake_test(While
+ Endwhile-Alone-Args
+)
diff --git a/Tests/CMakeTests/include/cmake_i_do_not_exist_in_the_system.h b/Tests/CMakeTests/include/cmake_i_do_not_exist_in_the_system.h
new file mode 100644
index 0000000000..2392aee71d
--- /dev/null
+++ b/Tests/CMakeTests/include/cmake_i_do_not_exist_in_the_system.h
@@ -0,0 +1 @@
+/* empty header file */
diff --git a/Tests/COnly/CMakeLists.txt b/Tests/COnly/CMakeLists.txt
new file mode 100644
index 0000000000..b3cc43813b
--- /dev/null
+++ b/Tests/COnly/CMakeLists.txt
@@ -0,0 +1,23 @@
+# a simple C only test case
+cmake_minimum_required (VERSION 2.6)
+project (COnly C)
+
+set(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
+add_library(testc1 STATIC libc1.c)
+add_library(testc2 SHARED libc2.c)
+add_executable (COnly conly.c foo.c foo.h)
+target_link_libraries(COnly testc1 testc2)
+if(MSVC_VERSION)
+ set_target_properties(COnly PROPERTIES
+ LINK_FLAGS " /NODEFAULTLIB:\"libcdg.lib\" /NODEFAULTLIB:\"libcmtg.lib\" /NODEFAULTLIB:\"foomsvcrt.lib\" /NODEFAULTLIB:\"libbar.lib\" /NODEFAULTLIB:\"libfooba.lib\"")
+endif()
+string(ASCII 35 32 67 77 97 107 101 ASCII_STRING)
+message(STATUS "String: ${ASCII_STRING}")
+get_source_file_property(LANG conly.c LANGUAGE)
+if("${LANG}" STREQUAL "C")
+ message("Language is C")
+else()
+ message(FATAL_ERROR "Bad language for file conly.c")
+endif()
+
+add_library(testCModule MODULE testCModule.c)
diff --git a/Tests/COnly/conly.c b/Tests/COnly/conly.c
new file mode 100644
index 0000000000..7214fe1bcf
--- /dev/null
+++ b/Tests/COnly/conly.c
@@ -0,0 +1,23 @@
+#include "foo.h"
+
+#include "libc1.h"
+#include "libc2.h"
+
+#include <stdio.h>
+
+int main ()
+{
+ int class = 0;
+ if ( LibC1Func() != 2.0 )
+ {
+ printf("Problem with libc1\n");
+ return 1;
+ }
+ if ( LibC2Func() != 1.0 )
+ {
+ printf("Problem with libc2\n");
+ return 1;
+ }
+ printf("Foo: %s %d\n", foo, class);
+ return 0;
+}
diff --git a/Tests/COnly/foo.c b/Tests/COnly/foo.c
new file mode 100644
index 0000000000..e4faf38a3c
--- /dev/null
+++ b/Tests/COnly/foo.c
@@ -0,0 +1 @@
+char* foo = "Foo";
diff --git a/Tests/COnly/foo.h b/Tests/COnly/foo.h
new file mode 100644
index 0000000000..ad4a9af0fd
--- /dev/null
+++ b/Tests/COnly/foo.h
@@ -0,0 +1 @@
+extern char* foo;
diff --git a/Tests/COnly/libc1.c b/Tests/COnly/libc1.c
new file mode 100644
index 0000000000..b01e1e1b54
--- /dev/null
+++ b/Tests/COnly/libc1.c
@@ -0,0 +1,4 @@
+float LibC1Func()
+{
+ return 2.0;
+}
diff --git a/Tests/COnly/libc1.h b/Tests/COnly/libc1.h
new file mode 100644
index 0000000000..84c94a9cb9
--- /dev/null
+++ b/Tests/COnly/libc1.h
@@ -0,0 +1 @@
+extern float LibC1Func();
diff --git a/Tests/COnly/libc2.c b/Tests/COnly/libc2.c
new file mode 100644
index 0000000000..0fd8956643
--- /dev/null
+++ b/Tests/COnly/libc2.c
@@ -0,0 +1,6 @@
+#include "libc2.h"
+
+float LibC2Func()
+{
+ return 1.0;
+}
diff --git a/Tests/COnly/libc2.h b/Tests/COnly/libc2.h
new file mode 100644
index 0000000000..2713d71ae7
--- /dev/null
+++ b/Tests/COnly/libc2.h
@@ -0,0 +1,11 @@
+#ifdef _WIN32
+# ifdef testc2_EXPORTS
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+# else
+# define CM_TEST_LIB_EXPORT __declspec( dllimport )
+# endif
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+
+CM_TEST_LIB_EXPORT float LibC2Func();
diff --git a/Tests/COnly/testCModule.c b/Tests/COnly/testCModule.c
new file mode 100644
index 0000000000..1a89292b3d
--- /dev/null
+++ b/Tests/COnly/testCModule.c
@@ -0,0 +1,6 @@
+#ifdef _WIN32
+# define TEST_EXPORT __declspec(dllexport)
+#else
+# define TEST_EXPORT
+#endif
+TEST_EXPORT int testCModule(void) { return 0; }
diff --git a/Tests/CPackComponents/CMakeLists.txt b/Tests/CPackComponents/CMakeLists.txt
new file mode 100644
index 0000000000..1cb86696a7
--- /dev/null
+++ b/Tests/CPackComponents/CMakeLists.txt
@@ -0,0 +1,128 @@
+# CPack Example: User-selectable Installation Components
+#
+# In this example, we have a simple library (mylib) with an example
+# application (mylibapp). We create a binary installer that allows
+# users to select which pieces will be installed: the example
+# application, the library binaries, and/or the header file.
+cmake_minimum_required(VERSION 2.6)
+project(CPackComponents)
+
+# Create the mylib library
+add_library(mylib mylib.cpp)
+
+# Create the mylibapp application
+add_executable(mylibapp mylibapp.cpp)
+target_link_libraries(mylibapp mylib)
+
+# On Linux, enable using an absolute install path to verify that
+# CMAKE_INSTALL_PREFIX and CPACK_SET_DESTDIR interact properly.
+#
+# But only use absolute paths if not targeting an NSIS installer
+# as indicated by CPACK_BINARY_NSIS. (If we allow this, the test
+# fails on Linux machines with makensis installed when we are not
+# cross-compiling...)
+#
+if(UNIX AND NOT APPLE)
+ if(NOT CPACK_BINARY_NSIS)
+ set(mylib_install_to_absolute_path ON)
+ endif()
+endif()
+
+if(mylib_install_to_absolute_path)
+ set(CMAKE_INSTALL_PREFIX "/opt/mylib")
+ set(CPACK_SET_DESTDIR ON)
+endif()
+
+# Create installation targets. Note that we put each kind of file
+# into a different component via COMPONENT. These components will
+# be used to create the installation components.
+install(TARGETS mylib
+ ARCHIVE
+ DESTINATION lib
+ COMPONENT libraries)
+install(TARGETS mylibapp
+ RUNTIME
+ DESTINATION bin
+ COMPONENT applications)
+install(FILES mylib.h
+ DESTINATION include
+ COMPONENT headers)
+install(FILES "Issue 7470.html"
+ DESTINATION docs
+ COMPONENT documentation)
+
+if(mylib_install_to_absolute_path)
+ install(FILES mylib.cpp
+ DESTINATION /opt/mylib-source
+ COMPONENT source)
+endif()
+
+# CPack boilerplate for this project
+set(CPACK_PACKAGE_NAME "MyLib")
+set(CPACK_PACKAGE_VENDOR "CMake.org")
+set(CPACK_PACKAGE_CONTACT "somebody@cmake.org")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
+set(CPACK_PACKAGE_VERSION "1.0.0")
+set(CPACK_PACKAGE_VERSION_MAJOR "1")
+set(CPACK_PACKAGE_VERSION_MINOR "0")
+set(CPACK_PACKAGE_VERSION_PATCH "0")
+set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
+
+# Settings used when building NSIS installers
+set(CPACK_NSIS_MENU_LINKS
+ "ftp://ftpserver" "Test Ftp Link"
+ "ftps://ftpsserver" "Test Ftps Link"
+ "http://www.cmake.org" "CMake Web Site"
+ "https://github.com/" "Test Https Link"
+ "mailto:kitware@kitware.com" "Test MailTo Link"
+ "news://newsserver" "Test News Link"
+ )
+
+# Suggested default root for end users of the installer:
+set(CPACK_NSIS_INSTALL_ROOT "C:\\Program Files\\CMake Tests Install Root")
+
+# Include CPack to introduce the appropriate targets
+include(CPack)
+
+# Installation types
+cpack_add_install_type(Full
+ DISPLAY_NAME "Everything")
+cpack_add_install_type(Developer)
+
+# Component groups
+cpack_add_component_group(Runtime)
+cpack_add_component_group(Development
+ EXPANDED
+ DESCRIPTION "All of the tools you'll ever need to develop software")
+
+# Components
+cpack_add_component(applications
+ DISPLAY_NAME "MyLib Application"
+ DESCRIPTION "An extremely useful application that makes use of MyLib"
+ GROUP Runtime
+ INSTALL_TYPES Full)
+cpack_add_component(documentation
+ DISPLAY_NAME "MyLib Documentation"
+ DESCRIPTION "The extensive suite of MyLib Application documentation files"
+ GROUP Runtime
+ INSTALL_TYPES Full)
+cpack_add_component(libraries
+ DISPLAY_NAME "Libraries"
+ DESCRIPTION "Static libraries used to build programs with MyLib"
+ GROUP Development
+ INSTALL_TYPES Developer Full)
+cpack_add_component(headers
+ DISPLAY_NAME "C++ Headers"
+ DESCRIPTION "C/C++ header files for use with MyLib"
+ GROUP Development
+ DEPENDS libraries
+ INSTALL_TYPES Developer Full)
+
+if(mylib_install_to_absolute_path)
+ cpack_add_component(source
+ DISPLAY_NAME "C++ Source Files"
+ DESCRIPTION "C/C++ source files to build MyLib"
+ GROUP Development
+ DEPENDS libraries
+ INSTALL_TYPES Developer Full)
+endif()
diff --git a/Tests/CPackComponents/Issue 7470.html b/Tests/CPackComponents/Issue 7470.html
new file mode 100644
index 0000000000..12df2c87d9
--- /dev/null
+++ b/Tests/CPackComponents/Issue 7470.html
@@ -0,0 +1,9 @@
+<html>
+<body>
+The install rule for this file demonstrates the problem described in<br/>
+CMake issue #7470:<br/>
+<br/>
+<a href="http://public.kitware.com/Bug/view.php?id=7470">
+http://public.kitware.com/Bug/view.php?id=7470</a><br/>
+</body>
+</html>
diff --git a/Tests/CPackComponents/VerifyResult.cmake b/Tests/CPackComponents/VerifyResult.cmake
new file mode 100644
index 0000000000..c7c24fde15
--- /dev/null
+++ b/Tests/CPackComponents/VerifyResult.cmake
@@ -0,0 +1,48 @@
+message(STATUS "=============================================================================")
+message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+message(STATUS "")
+
+if(NOT CPackComponents_BINARY_DIR)
+ message(FATAL_ERROR "CPackComponents_BINARY_DIR not set")
+endif()
+
+set(expected_file_mask "")
+
+if(WIN32)
+ # Only expect the *.exe installer if it looks like NSIS is
+ # installed on this machine:
+ #
+ find_program(NSIS_MAKENSIS_EXECUTABLE NAMES makensis
+ PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
+ DOC "makensis.exe location"
+ )
+ if(NSIS_MAKENSIS_EXECUTABLE)
+ set(expected_file_mask "${CPackComponents_BINARY_DIR}/MyLib-*.exe")
+ endif()
+endif()
+
+if(APPLE)
+ # Always expect the *.dmg installer - PackageMaker should always
+ # be installed on a development Mac:
+ #
+ set(expected_file_mask "${CPackComponents_BINARY_DIR}/MyLib-*.dmg")
+endif()
+
+if(expected_file_mask)
+ set(expected_count 1)
+ file(GLOB expected_file "${expected_file_mask}")
+
+ message(STATUS "expected_count='${expected_count}'")
+ message(STATUS "expected_file='${expected_file}'")
+ message(STATUS "expected_file_mask='${expected_file_mask}'")
+
+ if(NOT expected_file)
+ message(FATAL_ERROR "error: expected_file does not exist: CPackComponents test fails.")
+ endif()
+
+ list(LENGTH expected_file actual_count)
+ message(STATUS "actual_count='${actual_count}'")
+ if(NOT actual_count EQUAL expected_count)
+ message(FATAL_ERROR "error: expected_count does not match actual_count: CPackComponents test fails.")
+ endif()
+endif()
diff --git a/Tests/CPackComponents/mylib.cpp b/Tests/CPackComponents/mylib.cpp
new file mode 100644
index 0000000000..8ddac198c1
--- /dev/null
+++ b/Tests/CPackComponents/mylib.cpp
@@ -0,0 +1,7 @@
+#include "mylib.h"
+#include "stdio.h"
+
+void mylib_function()
+{
+ printf("This is mylib");
+}
diff --git a/Tests/CPackComponents/mylib.h b/Tests/CPackComponents/mylib.h
new file mode 100644
index 0000000000..5d0a822db0
--- /dev/null
+++ b/Tests/CPackComponents/mylib.h
@@ -0,0 +1 @@
+void mylib_function();
diff --git a/Tests/CPackComponents/mylibapp.cpp b/Tests/CPackComponents/mylibapp.cpp
new file mode 100644
index 0000000000..a438ac77ff
--- /dev/null
+++ b/Tests/CPackComponents/mylibapp.cpp
@@ -0,0 +1,6 @@
+#include "mylib.h"
+
+int main()
+{
+ mylib_function();
+}
diff --git a/Tests/CPackComponentsForAll/CMakeLists.txt b/Tests/CPackComponentsForAll/CMakeLists.txt
new file mode 100644
index 0000000000..ff40e30981
--- /dev/null
+++ b/Tests/CPackComponentsForAll/CMakeLists.txt
@@ -0,0 +1,124 @@
+# CPack Example: User-selectable Installation Components
+#
+# In this example, we have a simple library (mylib) with an example
+# application (mylibapp). We create a binary installer (a CPack Generator)
+# which supports CPack components.
+#
+# Depending on the CPack generator and on some CPACK_xxx var values
+# the generator may produce a single (NSIS, PackageMaker)
+# or several package files (Archive Generators, RPM, DEB)
+cmake_minimum_required(VERSION 2.8.3.20101130 FATAL_ERROR)
+project(CPackComponentsForAll)
+
+# Use GNUInstallDirs in order to enforce lib64 if needed
+include(GNUInstallDirs)
+
+# Create the mylib library
+add_library(mylib mylib.cpp)
+
+# Create the mylibapp application
+add_executable(mylibapp mylibapp.cpp)
+target_link_libraries(mylibapp mylib)
+
+# Duplicate of mylibapp application
+# which won't be put in any component (?mistake?)
+add_executable(mylibapp2 mylibapp.cpp)
+target_link_libraries(mylibapp2 mylib)
+
+# Create installation targets. Note that we put each kind of file
+# into a different component via COMPONENT. These components will
+# be used to create the installation components.
+install(TARGETS mylib
+ ARCHIVE
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ COMPONENT libraries)
+install(TARGETS mylibapp
+ RUNTIME
+ DESTINATION bin
+ COMPONENT applications)
+
+# This application does not belong to any component
+# thus (as of cmake 2.8.2) it will be left "uninstalled"
+# by a component-aware installer unless a
+# CPACK_MONOLITHIC_INSTALL=1 is set (at cmake time).
+install(TARGETS mylibapp2
+ RUNTIME
+ DESTINATION bin)
+
+install(FILES mylib.h
+ DESTINATION include
+ COMPONENT headers)
+
+# CPack boilerplate for this project
+set(CPACK_PACKAGE_NAME "MyLib")
+set(CPACK_PACKAGE_CONTACT "None")
+set(CPACK_PACKAGE_VENDOR "CMake.org")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
+set(CPACK_PACKAGE_VERSION "1.0.2")
+set(CPACK_PACKAGE_VERSION_MAJOR "1")
+set(CPACK_PACKAGE_VERSION_MINOR "0")
+set(CPACK_PACKAGE_VERSION_PATCH "2")
+set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
+set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/license.txt)
+
+# Tell CPack all of the components to install. The "ALL"
+# refers to the fact that this is the set of components that
+# will be included when CPack is instructed to put everything
+# into the binary installer (the default behavior).
+set(CPACK_COMPONENTS_ALL applications libraries headers Unspecified)
+
+# Set the displayed names for each of the components to install.
+# These will be displayed in the list of components inside the installer.
+set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
+set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
+set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
+
+# Provide descriptions for each of the components to install.
+# When the user hovers the mouse over the name of a component,
+# the description will be shown in the "Description" box in the
+# installer. If no descriptions are provided, the "Description"
+# box will be removed.
+set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
+ "An extremely useful application that makes use of MyLib")
+set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
+ "Static libraries used to build programs with MyLib")
+set(CPACK_COMPONENT_HEADERS_DESCRIPTION
+ "C/C++ header files for use with MyLib")
+
+# Put the components into two different groups: "Runtime" and "Development"
+set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
+set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
+set(CPACK_COMPONENT_HEADERS_GROUP "Development")
+
+# Expand the "Development" group by default, since we have so few components.
+# Also, provide this group with a description.
+set(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON)
+set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
+ "All of the tools you'll ever need to develop software")
+
+# It doesn't make sense to install the headers without the libraries
+# (because you could never use the headers!), so make the headers component
+# depend on the libraries component.
+set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
+
+# Create two installation types with pre-selected components.
+# The "Developer" installation has just the library and headers,
+# while the "Full" installation has everything.
+set(CPACK_ALL_INSTALL_TYPES Full Developer)
+set(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything")
+set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full)
+set(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
+set(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full)
+
+# We may use the CPack specific config file in order
+# to tailor CPack behavior on a CPack generator specific way
+# (Behavior would be different for RPM or TGZ or DEB ...)
+if (NOT ("${CPackComponentWay}" STREQUAL "default"))
+ # Setup project specific CPack-time CPack Config file.
+ configure_file(${CPackComponentsForAll_SOURCE_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake.in
+ ${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake
+ @ONLY)
+ set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake)
+endif ()
+# Include CPack to introduce the appropriate targets
+include(CPack)
diff --git a/Tests/CPackComponentsForAll/MyLibCPackConfig-AllInOne.cmake.in b/Tests/CPackComponentsForAll/MyLibCPackConfig-AllInOne.cmake.in
new file mode 100644
index 0000000000..0bfbf14676
--- /dev/null
+++ b/Tests/CPackComponentsForAll/MyLibCPackConfig-AllInOne.cmake.in
@@ -0,0 +1,22 @@
+#
+# Activate component packaging
+#
+if(CPACK_GENERATOR MATCHES "ZIP")
+ set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
+endif()
+
+if(CPACK_GENERATOR MATCHES "RPM")
+ set(CPACK_RPM_COMPONENT_INSTALL "ON")
+endif()
+
+if(CPACK_GENERATOR MATCHES "DEB")
+ set(CPACK_DEB_COMPONENT_INSTALL "ON")
+endif()
+
+#
+# Choose grouping way
+#
+#set(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE 1)
+#set(CPACK_COMPONENTS_GROUPING)
+#set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
+set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
diff --git a/Tests/CPackComponentsForAll/MyLibCPackConfig-IgnoreGroup.cmake.in b/Tests/CPackComponentsForAll/MyLibCPackConfig-IgnoreGroup.cmake.in
new file mode 100644
index 0000000000..450c2047e5
--- /dev/null
+++ b/Tests/CPackComponentsForAll/MyLibCPackConfig-IgnoreGroup.cmake.in
@@ -0,0 +1,23 @@
+#
+# Activate component packaging
+#
+if(CPACK_GENERATOR MATCHES "ZIP")
+ set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
+endif()
+
+if(CPACK_GENERATOR MATCHES "RPM")
+ set(CPACK_RPM_COMPONENT_INSTALL "ON")
+ set(CPACK_RPM_applications_PACKAGE_REQUIRES "mylib-libraries")
+endif()
+
+if(CPACK_GENERATOR MATCHES "DEB")
+ set(CPACK_DEB_COMPONENT_INSTALL "ON")
+endif()
+
+#
+# Choose grouping way
+#
+#set(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE)
+#set(CPACK_COMPONENTS_GROUPING)
+set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
+#set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1) \ No newline at end of file
diff --git a/Tests/CPackComponentsForAll/MyLibCPackConfig-OnePackPerGroup.cmake.in b/Tests/CPackComponentsForAll/MyLibCPackConfig-OnePackPerGroup.cmake.in
new file mode 100644
index 0000000000..60bdd06be4
--- /dev/null
+++ b/Tests/CPackComponentsForAll/MyLibCPackConfig-OnePackPerGroup.cmake.in
@@ -0,0 +1,27 @@
+#
+# Activate component packaging
+#
+if(CPACK_GENERATOR MATCHES "ZIP")
+ set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
+endif()
+
+if(CPACK_GENERATOR MATCHES "RPM")
+ set(CPACK_RPM_COMPONENT_INSTALL "ON")
+ set(CPACK_RPM_Development_PACKAGE_REQUIRES "mylib-Runtime")
+endif()
+
+if(CPACK_GENERATOR MATCHES "DEB")
+ set(CPACK_DEB_COMPONENT_INSTALL "ON")
+endif()
+
+if(CPACK_GENERATOR MATCHES "DragNDrop")
+ set(CPACK_COMPONENTS_GROUPING "ONE_PER_GROUP")
+endif()
+
+#
+# Choose grouping way
+#
+#set(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE)
+#set(CPACK_COMPONENTS_GROUPING)
+#set(CPACK_COMPONENTS_IGNORE_GROUPS)
+#set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE)
diff --git a/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake b/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake
new file mode 100644
index 0000000000..0b6d07d970
--- /dev/null
+++ b/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake
@@ -0,0 +1,125 @@
+message(STATUS "=============================================================================")
+message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+message(STATUS "")
+
+if(NOT CPackComponentsForAll_BINARY_DIR)
+ message(FATAL_ERROR "CPackComponentsForAll_BINARY_DIR not set")
+endif()
+
+if(NOT CPackGen)
+ message(FATAL_ERROR "CPackGen not set")
+endif()
+
+message("CMAKE_CPACK_COMMAND = ${CMAKE_CPACK_COMMAND}")
+if(NOT CMAKE_CPACK_COMMAND)
+ message(FATAL_ERROR "CMAKE_CPACK_COMMAND not set")
+endif()
+
+if(NOT CPackComponentWay)
+ message(FATAL_ERROR "CPackComponentWay not set")
+endif()
+
+set(expected_file_mask "")
+# The usual default behavior is to expect a single file
+# Then some specific generators (Archive, RPM, ...)
+# May produce several numbers of files depending on
+# CPACK_COMPONENT_xxx values
+set(expected_count 1)
+set(config_type $ENV{CMAKE_CONFIG_TYPE})
+set(config_args )
+if(config_type)
+ set(config_args -C ${config_type})
+endif()
+set(config_verbose )
+
+if(CPackGen MATCHES "ZIP")
+ set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.zip")
+ if (${CPackComponentWay} STREQUAL "default")
+ set(expected_count 1)
+ elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
+ set(expected_count 3)
+ elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
+ set(expected_count 4)
+ elseif (${CPackComponentWay} STREQUAL "AllInOne")
+ set(expected_count 1)
+ endif ()
+elseif (CPackGen MATCHES "RPM")
+ set(config_verbose -D "CPACK_RPM_PACKAGE_DEBUG=1")
+ set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.rpm")
+ if (${CPackComponentWay} STREQUAL "default")
+ set(expected_count 1)
+ elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
+ set(expected_count 3)
+ elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
+ set(expected_count 4)
+ elseif (${CPackComponentWay} STREQUAL "AllInOne")
+ set(expected_count 1)
+ endif ()
+elseif (CPackGen MATCHES "DEB")
+ set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.deb")
+ if (${CPackComponentWay} STREQUAL "default")
+ set(expected_count 1)
+ elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
+ set(expected_count 3)
+ elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
+ set(expected_count 4)
+ elseif (${CPackComponentWay} STREQUAL "AllInOne")
+ set(expected_count 1)
+ endif ()
+endif()
+
+if(CPackGen MATCHES "DragNDrop")
+ set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.dmg")
+ if (${CPackComponentWay} STREQUAL "default")
+ set(expected_count 1)
+ elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
+ set(expected_count 3)
+ elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
+ set(expected_count 4)
+ elseif (${CPackComponentWay} STREQUAL "AllInOne")
+ set(expected_count 1)
+ endif ()
+endif()
+
+# clean-up previously CPack generated files
+if(expected_file_mask)
+ file(GLOB expected_file "${expected_file_mask}")
+ if (expected_file)
+ file(REMOVE ${expected_file})
+ endif()
+endif()
+
+message("config_args = ${config_args}")
+message("config_verbose = ${config_verbose}")
+execute_process(COMMAND ${CMAKE_CPACK_COMMAND} ${config_verbose} -G ${CPackGen} ${config_args}
+ RESULT_VARIABLE CPack_result
+ OUTPUT_VARIABLE CPack_output
+ ERROR_VARIABLE CPack_error
+ WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
+
+if (CPack_result)
+ message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
+else ()
+ message(STATUS "CPack_output=${CPack_output}")
+endif()
+
+# Now verify if the number of expected file is OK
+# - using expected_file_mask and
+# - expected_count
+if(expected_file_mask)
+ file(GLOB expected_file "${expected_file_mask}")
+
+ message(STATUS "expected_count='${expected_count}'")
+ message(STATUS "expected_file='${expected_file}'")
+ message(STATUS "expected_file_mask='${expected_file_mask}'")
+
+ if(NOT expected_file)
+ message(FATAL_ERROR "error: expected_file=${expected_file} does not exist: CPackComponentsForAll test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
+ endif()
+
+ list(LENGTH expected_file actual_count)
+ message(STATUS "actual_count='${actual_count}'")
+ if(NOT actual_count EQUAL expected_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()
+endif()
diff --git a/Tests/CPackComponentsForAll/license.txt b/Tests/CPackComponentsForAll/license.txt
new file mode 100644
index 0000000000..ba8ba48a71
--- /dev/null
+++ b/Tests/CPackComponentsForAll/license.txt
@@ -0,0 +1,3 @@
+LICENSE
+-------
+This is an installer created using CPack (http://www.cmake.org). No license provided.
diff --git a/Tests/CPackComponentsForAll/mylib.cpp b/Tests/CPackComponentsForAll/mylib.cpp
new file mode 100644
index 0000000000..8ddac198c1
--- /dev/null
+++ b/Tests/CPackComponentsForAll/mylib.cpp
@@ -0,0 +1,7 @@
+#include "mylib.h"
+#include "stdio.h"
+
+void mylib_function()
+{
+ printf("This is mylib");
+}
diff --git a/Tests/CPackComponentsForAll/mylib.h b/Tests/CPackComponentsForAll/mylib.h
new file mode 100644
index 0000000000..5d0a822db0
--- /dev/null
+++ b/Tests/CPackComponentsForAll/mylib.h
@@ -0,0 +1 @@
+void mylib_function();
diff --git a/Tests/CPackComponentsForAll/mylibapp.cpp b/Tests/CPackComponentsForAll/mylibapp.cpp
new file mode 100644
index 0000000000..a438ac77ff
--- /dev/null
+++ b/Tests/CPackComponentsForAll/mylibapp.cpp
@@ -0,0 +1,6 @@
+#include "mylib.h"
+
+int main()
+{
+ mylib_function();
+}
diff --git a/Tests/CPackTestAllGenerators/CMakeLists.txt b/Tests/CPackTestAllGenerators/CMakeLists.txt
new file mode 100644
index 0000000000..5eeb7e90be
--- /dev/null
+++ b/Tests/CPackTestAllGenerators/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8)
+project(CPackTestAllGenerators)
+add_subdirectory(../CTestTest/SmallAndFast SmallAndFast)
+install(FILES RunCPack.cmake DESTINATION .)
+include(CPack)
diff --git a/Tests/CPackTestAllGenerators/RunCPack.cmake b/Tests/CPackTestAllGenerators/RunCPack.cmake
new file mode 100644
index 0000000000..952d5f4ae0
--- /dev/null
+++ b/Tests/CPackTestAllGenerators/RunCPack.cmake
@@ -0,0 +1,51 @@
+if(NOT DEFINED dir)
+ message(FATAL_ERROR "dir not defined")
+endif()
+
+# Analyze 'cpack --help' output for list of available generators:
+#
+execute_process(COMMAND ${CMAKE_CPACK_COMMAND} --help
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ WORKING_DIRECTORY ${dir})
+
+string(REPLACE ";" "\\;" stdout "${stdout}")
+string(REPLACE "\n" "E;" stdout "${stdout}")
+
+set(collecting 0)
+set(generators)
+foreach(eline ${stdout})
+ string(REGEX REPLACE "^(.*)E$" "\\1" line "${eline}")
+ if(collecting AND NOT line STREQUAL "")
+ string(REGEX REPLACE "^ ([^ ]+) += (.*)$" "\\1" gen "${line}")
+ string(REGEX REPLACE "^ ([^ ]+) += (.*)$" "\\2" doc "${line}")
+ set(generators ${generators} ${gen})
+ endif()
+ if(line STREQUAL "Generators")
+ set(collecting 1)
+ endif()
+endforeach()
+
+# Call cpack with -G on each available generator. We do not care if this
+# succeeds or not. We expect it *not* to succeed if the underlying packaging
+# tools are not installed on the system... This test is here simply to add
+# coverage for the various cpack generators, even/especially to test ones
+# where the tools are not installed.
+#
+message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+
+message(STATUS "CPack generators='${generators}'")
+
+foreach(g ${generators})
+ message(STATUS "Calling cpack -G ${g}...")
+ execute_process(COMMAND ${CMAKE_CPACK_COMMAND} -G ${g}
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ WORKING_DIRECTORY ${dir})
+ message(STATUS "result='${result}'")
+ message(STATUS "stdout='${stdout}'")
+ message(STATUS "stderr='${stderr}'")
+ message(STATUS "")
+endforeach()
diff --git a/Tests/CPackWiXGenerator/CMakeLists.txt b/Tests/CPackWiXGenerator/CMakeLists.txt
new file mode 100644
index 0000000000..638e788a99
--- /dev/null
+++ b/Tests/CPackWiXGenerator/CMakeLists.txt
@@ -0,0 +1,116 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(CPackWiXGenerator)
+
+add_library(mylib mylib.cpp)
+
+add_executable(my-libapp mylibapp.cpp)
+target_link_libraries(my-libapp mylib)
+
+add_executable(my-other-app myotherapp.cpp)
+
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/empty)
+install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/empty
+ DESTINATION extras
+ COMPONENT extras)
+
+install(TARGETS mylib
+ ARCHIVE
+ DESTINATION lib
+ COMPONENT libraries)
+
+install(TARGETS my-libapp
+ RUNTIME
+ DESTINATION bin
+ COMPONENT applications)
+
+install(TARGETS my-other-app
+ RUNTIME
+ DESTINATION bin
+ COMPONENT applications2)
+
+install(FILES mylib.h "file with spaces.h"
+ DESTINATION include
+ COMPONENT headers)
+
+set(CPACK_GENERATOR "WIX")
+
+set(CPACK_PACKAGE_NAME "MyLib")
+set(CPACK_PACKAGE_VENDOR "CMake.org")
+set(CPACK_PACKAGE_CONTACT "somebody@cmake.org")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
+ "MyLib - CPack Component Installation Example")
+
+set(CPACK_PACKAGE_VERSION_MAJOR "1")
+set(CPACK_PACKAGE_VERSION_MINOR "0")
+set(CPACK_PACKAGE_VERSION_PATCH "0")
+set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
+
+set(CPACK_WIX_UPGRADE_GUID "BF20CE5E-7F7C-401D-8F7C-AB45E8D170E6")
+set(CPACK_WIX_UNINSTALL "1")
+
+set(CPACK_PACKAGE_EXECUTABLES
+ "my-libapp" "CPack WiX Test"
+ "my-other-app" "Second CPack WiX Test"
+)
+
+set(CPACK_CREATE_DESKTOP_LINKS
+ "my-libapp"
+ "my-other-app"
+)
+
+set(CPACK_WIX_PATCH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/patch.xml")
+
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt")
+
+set(CPACK_WIX_PROPERTY_ARPCOMMENTS "My Custom ARPCOMMENTS")
+set(CPACK_WIX_PROPERTY_ARPHELPLINK "http://www.cmake.org")
+
+include(CPack)
+
+cpack_add_install_type(Full DISPLAY_NAME "Everything")
+cpack_add_install_type(Developer)
+
+cpack_add_component_group(Runtime)
+
+cpack_add_component_group(Development
+ EXPANDED
+ DESCRIPTION "All of the tools you'll ever need to develop software")
+
+cpack_add_component(extras
+ DISPLAY_NAME "Extras"
+ DESCRIPTION "Extras"
+ GROUP Runtime
+ INSTALL_TYPES Full)
+
+cpack_add_component(applications
+ REQUIRED
+ DISPLAY_NAME "MyLib Application"
+ DESCRIPTION "An extremely useful application that makes use of MyLib"
+ GROUP Runtime
+ INSTALL_TYPES Full)
+
+cpack_add_component(applications2
+ DISPLAY_NAME "MyLib Extra Application"
+ DESCRIPTION "Another extremely useful application that makes use of MyLib"
+ GROUP Runtime
+ INSTALL_TYPES Full)
+
+cpack_add_component(documentation
+ DISPLAY_NAME "MyLib Documentation"
+ DESCRIPTION "The extensive suite of MyLib Application documentation files"
+ GROUP Runtime
+ INSTALL_TYPES Full)
+
+cpack_add_component(libraries
+ DISPLAY_NAME "Libraries"
+ DESCRIPTION "Static libraries used to build programs with MyLib"
+ GROUP Development
+ INSTALL_TYPES Developer Full)
+
+cpack_add_component(headers
+ DISPLAY_NAME "C++ Headers"
+ DESCRIPTION "C/C++ header files for use with MyLib"
+ GROUP Development
+ DEPENDS libraries
+ INSTALL_TYPES Developer Full)
diff --git a/Tests/CPackWiXGenerator/RunCPackVerifyResult.cmake b/Tests/CPackWiXGenerator/RunCPackVerifyResult.cmake
new file mode 100644
index 0000000000..ca9fd90495
--- /dev/null
+++ b/Tests/CPackWiXGenerator/RunCPackVerifyResult.cmake
@@ -0,0 +1,77 @@
+message(STATUS "=============================================================")
+message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
+message(STATUS "")
+
+if(NOT CPackWiXGenerator_BINARY_DIR)
+ message(FATAL_ERROR "CPackWiXGenerator_BINARY_DIR not set")
+endif()
+
+message(STATUS "CMAKE_COMMAND: ${CMAKE_COMMAND}")
+message(STATUS "CMAKE_CPACK_COMMAND: ${CMAKE_CPACK_COMMAND}")
+message(STATUS "CPackWiXGenerator_BINARY_DIR: ${CPackWiXGenerator_BINARY_DIR}")
+
+if(config)
+ set(_C_config -C ${config})
+endif()
+
+execute_process(COMMAND "${CMAKE_CPACK_COMMAND}"
+ ${_C_config}
+ RESULT_VARIABLE CPack_result
+ OUTPUT_VARIABLE CPack_output
+ ERROR_VARIABLE CPack_error
+ WORKING_DIRECTORY "${CPackWiXGenerator_BINARY_DIR}")
+
+if(CPack_result)
+ message(FATAL_ERROR "CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
+else ()
+ message(STATUS "CPack_output=${CPack_output}")
+endif()
+
+set(expected_file_mask "*.msi")
+file(GLOB installer_file "${expected_file_mask}")
+
+message(STATUS "installer_file='${installer_file}'")
+message(STATUS "expected_file_mask='${expected_file_mask}'")
+
+if(NOT installer_file)
+ message(FATAL_ERROR "installer_file does not exist.")
+endif()
+
+function(run_wix_command command)
+ file(TO_CMAKE_PATH "$ENV{WIX}" WIX_ROOT)
+ set(WIX_PROGRAM "${WIX_ROOT}/bin/${command}.exe")
+
+ if(NOT EXISTS "${WIX_PROGRAM}")
+ message(FATAL_ERROR "Failed to find WiX Tool: ${WIX_PROGRAM}")
+ endif()
+
+ message(STATUS "Running WiX Tool: ${command} ${ARGN}")
+
+ execute_process(COMMAND "${WIX_PROGRAM}" ${ARGN}
+ RESULT_VARIABLE WIX_result
+ OUTPUT_VARIABLE WIX_output
+ ERROR_VARIABLE WIX_output
+ WORKING_DIRECTORY "${CPackWiXGenerator_BINARY_DIR}")
+
+ message(STATUS "${command} Output: \n${WIX_output}")
+
+ if(WIX_result)
+ message(FATAL_ERROR "WiX ${command} failed: ${WIX_result}")
+ endif()
+endfunction()
+
+file(GLOB WXS_SOURCE_FILES
+ "${CPackWiXGenerator_BINARY_DIR}/_CPack_Packages/*/WIX/*.wxs")
+
+if(NOT WXS_SOURCE_FILES)
+ message(FATAL_ERROR "Failed finding WiX source files to validate.")
+endif()
+
+foreach(WXS_SOURCE_FILE IN LISTS WXS_SOURCE_FILES)
+ run_wix_command(wixcop "${WXS_SOURCE_FILE}")
+endforeach()
+
+# error SMOK1076 : ICE61: This product should remove only older
+# versions of itself. The Maximum version is not less
+# than the current product. (1.0.0 1.0.0)
+run_wix_command(smoke -nologo -wx -sw1076 "${installer_file}")
diff --git a/Tests/CPackWiXGenerator/file with spaces.h b/Tests/CPackWiXGenerator/file with spaces.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CPackWiXGenerator/file with spaces.h
diff --git a/Tests/CPackWiXGenerator/license.txt b/Tests/CPackWiXGenerator/license.txt
new file mode 100644
index 0000000000..79427833d3
--- /dev/null
+++ b/Tests/CPackWiXGenerator/license.txt
@@ -0,0 +1,9 @@
+hello world
+merhaba dünya
+ãƒãƒ­ãƒ¼ãƒ¯ãƒ¼ãƒ«ãƒ‰
+привет мир
+مرحبا العالم
+你好世界
+
+4-Byte sequences:
+ Perch (Fish) 𩶘 Elevator 𨋢!
diff --git a/Tests/CPackWiXGenerator/mylib.cpp b/Tests/CPackWiXGenerator/mylib.cpp
new file mode 100644
index 0000000000..8ddac198c1
--- /dev/null
+++ b/Tests/CPackWiXGenerator/mylib.cpp
@@ -0,0 +1,7 @@
+#include "mylib.h"
+#include "stdio.h"
+
+void mylib_function()
+{
+ printf("This is mylib");
+}
diff --git a/Tests/CPackWiXGenerator/mylib.h b/Tests/CPackWiXGenerator/mylib.h
new file mode 100644
index 0000000000..5d0a822db0
--- /dev/null
+++ b/Tests/CPackWiXGenerator/mylib.h
@@ -0,0 +1 @@
+void mylib_function();
diff --git a/Tests/CPackWiXGenerator/mylibapp.cpp b/Tests/CPackWiXGenerator/mylibapp.cpp
new file mode 100644
index 0000000000..a438ac77ff
--- /dev/null
+++ b/Tests/CPackWiXGenerator/mylibapp.cpp
@@ -0,0 +1,6 @@
+#include "mylib.h"
+
+int main()
+{
+ mylib_function();
+}
diff --git a/Tests/CPackWiXGenerator/myotherapp.cpp b/Tests/CPackWiXGenerator/myotherapp.cpp
new file mode 100644
index 0000000000..c272dabaeb
--- /dev/null
+++ b/Tests/CPackWiXGenerator/myotherapp.cpp
@@ -0,0 +1 @@
+int main() {} \ No newline at end of file
diff --git a/Tests/CPackWiXGenerator/patch.xml b/Tests/CPackWiXGenerator/patch.xml
new file mode 100644
index 0000000000..13c392d3ce
--- /dev/null
+++ b/Tests/CPackWiXGenerator/patch.xml
@@ -0,0 +1,7 @@
+<CPackWiXPatch>
+ <CPackWiXFragment Id="CM_CP_applications.bin.my_libapp.exe">
+ <Environment Id="MyEnvironment" Action="set"
+ Name="CPackWiXGeneratorTest"
+ Value="CPackWiXGeneratorTest"/>
+ </CPackWiXFragment>
+</CPackWiXPatch>
diff --git a/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in b/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in
new file mode 100644
index 0000000000..670a8745fa
--- /dev/null
+++ b/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.8.10)
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/VSProjectInSubdir")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestBuildCommandProjectInSubdir/Nested")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_PROJECT_NAME "VSProjectInSubdir")
+set(CTEST_BUILD_CONFIGURATION "@CTestTest_CONFIG@")
+
+ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
+ctest_start(Experimental)
+ctest_configure(OPTIONS "@ctest_configure_options@")
+ctest_build(TARGET test)
diff --git a/Tests/CTestConfig/CMakeLists.txt b/Tests/CTestConfig/CMakeLists.txt
new file mode 100644
index 0000000000..f46d89a55d
--- /dev/null
+++ b/Tests/CTestConfig/CMakeLists.txt
@@ -0,0 +1,47 @@
+cmake_minimum_required(VERSION 2.8)
+project(CTestConfig)
+
+include(CTest)
+
+
+# We expect this configure to occur through a 'ctest -D Experimental' or a
+# 'ctest -S script.cmake' call.
+#
+# In either case, we expect CMAKE_BUILD_TYPE to be defined for single-configuration
+# build trees and not defined for multi-configuration build trees.
+#
+if(CMAKE_CONFIGURATION_TYPES)
+ # multi-configuration: expect not defined, error if defined
+ if(DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE STREQUAL "")
+ message(FATAL_ERROR "CMAKE_CONFIGURATION_TYPES='${CMAKE_CONFIGURATION_TYPES}' CMAKE_BUILD_TYPE='${CMAKE_BUILD_TYPE}' is defined and non-empty (but should not be for a multi-configuration generator)")
+ endif()
+else()
+ # single-configuration: expect defined, error if not defined
+ if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
+ message(FATAL_ERROR "CMAKE_BUILD_TYPE is not defined or is empty (but should be defined and non-empty for a single-configuration generator)")
+ endif()
+endif()
+
+
+if(DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE STREQUAL "")
+ add_definitions(-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}")
+endif()
+
+add_executable(ctc CTestConfig.cxx)
+
+
+foreach(cfg ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
+ add_test(NAME ctc-${cfg} CONFIGURATIONS ${cfg} COMMAND ctc --config $<CONFIGURATION>)
+
+ if(CMAKE_CONFIGURATION_TYPES)
+ set_property(TEST ctc-${cfg}
+ PROPERTY PASS_REGULAR_EXPRESSION "CMAKE_INTDIR is ${cfg}")
+ set_property(TEST ctc-${cfg}
+ PROPERTY FAIL_REGULAR_EXPRESSION "CMAKE_BUILD_TYPE is")
+ else()
+ set_property(TEST ctc-${cfg}
+ PROPERTY PASS_REGULAR_EXPRESSION "CMAKE_BUILD_TYPE is ${cfg}")
+ set_property(TEST ctc-${cfg}
+ PROPERTY FAIL_REGULAR_EXPRESSION "CMAKE_INTDIR is")
+ endif()
+endforeach()
diff --git a/Tests/CTestConfig/CTestConfig.cxx b/Tests/CTestConfig/CTestConfig.cxx
new file mode 100644
index 0000000000..49c53241a5
--- /dev/null
+++ b/Tests/CTestConfig/CTestConfig.cxx
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+int main(int argc, const char* argv[])
+{
+ int i = 0;
+ for (; i<argc; ++i)
+ {
+ fprintf(stdout, "%s\n", argv[i]);
+ }
+
+#ifdef CMAKE_BUILD_TYPE
+ fprintf(stdout, "CMAKE_BUILD_TYPE is %s\n", CMAKE_BUILD_TYPE);
+#endif
+
+#ifdef CMAKE_INTDIR
+ fprintf(stdout, "CMAKE_INTDIR is %s\n", CMAKE_INTDIR);
+#endif
+
+ return 0;
+}
diff --git a/Tests/CTestConfig/ScriptWithArgs.cmake b/Tests/CTestConfig/ScriptWithArgs.cmake
new file mode 100644
index 0000000000..79896a7fcc
--- /dev/null
+++ b/Tests/CTestConfig/ScriptWithArgs.cmake
@@ -0,0 +1,16 @@
+set(CTEST_RUN_CURRENT_SCRIPT 0)
+
+macro(check_arg name expected_value)
+ message("${name}='${${name}}'")
+ if(NOT "${${name}}" STREQUAL "${expected_value}")
+ message(FATAL_ERROR "unexpected ${name} value '${${name}}', expected '${expected_value}'")
+ endif()
+endmacro()
+
+check_arg(arg1 "this")
+check_arg(arg2 "that")
+check_arg(arg3 "the other")
+check_arg(arg4 "this is the fourth")
+check_arg(arg5 "the_fifth")
+check_arg(arg6 "value-with-type")
+check_arg(arg7 "")
diff --git a/Tests/CTestConfig/dashboard.cmake.in b/Tests/CTestConfig/dashboard.cmake.in
new file mode 100644
index 0000000000..143fe717ab
--- /dev/null
+++ b/Tests/CTestConfig/dashboard.cmake.in
@@ -0,0 +1,47 @@
+set(CMAKE_CONFIGURATION_TYPES "@CMAKE_CONFIGURATION_TYPES@")
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestConfig")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestConfig/@cfg@-dashboard")
+
+file(MAKE_DIRECTORY "${CTEST_BINARY_DIRECTORY}")
+
+get_filename_component(dir "${CMAKE_COMMAND}" PATH)
+set(CMAKE_CTEST_COMMAND "${dir}/ctest")
+
+message("CMAKE_COMMAND='${CMAKE_COMMAND}'")
+message("CMAKE_CTEST_COMMAND='${CMAKE_CTEST_COMMAND}'")
+
+set(arg "")
+if(NOT CMAKE_CONFIGURATION_TYPES)
+ set(arg "-DCMAKE_BUILD_TYPE:STRING=@cfg@")
+endif()
+
+message("cmake initial configure")
+execute_process(COMMAND ${CMAKE_COMMAND}
+ ${arg}
+ -G "@CMAKE_GENERATOR@"
+ -A "@CMAKE_GENERATOR_PLATFORM@"
+ -T "@CMAKE_GENERATOR_TOOLSET@"
+ ${CTEST_SOURCE_DIRECTORY}
+ WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY}
+ RESULT_VARIABLE rv)
+if(NOT rv STREQUAL 0)
+ message(FATAL_ERROR "error calling cmake: rv='${rv}'")
+endif()
+
+
+function(call_ctest arg)
+ message("call_ctest ${arg}")
+ execute_process(COMMAND ${CMAKE_CTEST_COMMAND}
+ -C "@cfg@" -D ${arg} -VV
+ WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY}
+ RESULT_VARIABLE rv)
+ if(NOT rv STREQUAL 0)
+ message(FATAL_ERROR "error calling ctest: rv='${rv}'")
+ endif()
+endfunction()
+
+
+call_ctest(ExperimentalStart)
+call_ctest(ExperimentalConfigure)
+call_ctest(ExperimentalBuild)
+call_ctest(ExperimentalTest)
diff --git a/Tests/CTestConfig/script.cmake.in b/Tests/CTestConfig/script.cmake.in
new file mode 100644
index 0000000000..b6ccedb571
--- /dev/null
+++ b/Tests/CTestConfig/script.cmake.in
@@ -0,0 +1,23 @@
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_PROJECT_NAME "CTestConfig")
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestConfig")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestConfig/@cfg@-script")
+
+ctest_start(Experimental)
+
+ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE rv)
+if(NOT rv STREQUAL 0)
+ message(FATAL_ERROR "*** error in ctest_configure ***")
+endif()
+
+ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE rv)
+if(NOT rv STREQUAL 0)
+ message(FATAL_ERROR "*** error in ctest_build ***")
+endif()
+
+ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE rv)
+if(NOT rv STREQUAL 0)
+ message(FATAL_ERROR "*** error in ctest_test ***")
+endif()
diff --git a/Tests/CTestLimitDashJ/CMakeLists.txt b/Tests/CTestLimitDashJ/CMakeLists.txt
new file mode 100644
index 0000000000..0c5950c9d4
--- /dev/null
+++ b/Tests/CTestLimitDashJ/CMakeLists.txt
@@ -0,0 +1,50 @@
+cmake_minimum_required(VERSION 2.8)
+project(CTestLimitDashJ NONE)
+
+# This file demonstrates http://public.kitware.com/Bug/view.php?id=12904
+# when configured with CMake 2.8.10.2 and earlier, and when running
+# "ctest -j 4" in the resulting build tree. This example is hard-coded
+# to assume -j 4 just to reproduce the issue easily. Adjust the
+# FAIL_REGULAR_EXPRESSION and PROCESSORS values to reproduce this problem
+# with a different ctest -j value...
+
+if(EXISTS "${CMAKE_BINARY_DIR}/Testing/Temporary/CTestCostData.txt")
+ message(STATUS "Removing CTestCostData.txt to force ordering by COST PROPERTY value rather than prior run data")
+ file(REMOVE "${CMAKE_BINARY_DIR}/Testing/Temporary/CTestCostData.txt")
+endif()
+
+include(CTest)
+
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/CreateSleepDelete.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/CreateSleepDelete.cmake
+ @ONLY
+ )
+
+foreach(n RANGE 1 100)
+ add_test(NAME t${n}
+ COMMAND ${CMAKE_CTEST_COMMAND}
+ -D basefilename=f${n}
+ -S ${CMAKE_CURRENT_BINARY_DIR}/CreateSleepDelete.cmake
+ )
+ set_property(TEST t${n} PROPERTY FAIL_REGULAR_EXPRESSION "(c='[5-9]'|c='[1-9][0-9]+')")
+endforeach()
+
+set_property(TEST t1 PROPERTY RUN_SERIAL 1)
+set_property(TEST t1 PROPERTY PROCESSORS 4)
+
+set_property(TEST t51 PROPERTY RUN_SERIAL 1)
+set_property(TEST t51 PROPERTY PROCESSORS 4)
+
+foreach(n RANGE 2 50)
+ set_property(TEST t${n} PROPERTY DEPENDS t1)
+endforeach()
+set_property(TEST t1 PROPERTY DEPENDS t51)
+set_property(TEST t51 PROPERTY DEPENDS t100)
+
+foreach(n 50)
+ set_property(TEST t${n} PROPERTY COST 6)
+endforeach()
+foreach(n RANGE 52 99)
+ set_property(TEST t${n} PROPERTY COST 3)
+endforeach()
diff --git a/Tests/CTestLimitDashJ/CreateSleepDelete.cmake b/Tests/CTestLimitDashJ/CreateSleepDelete.cmake
new file mode 100644
index 0000000000..b09307feb6
--- /dev/null
+++ b/Tests/CTestLimitDashJ/CreateSleepDelete.cmake
@@ -0,0 +1,48 @@
+set(CTEST_RUN_CURRENT_SCRIPT 0)
+
+if(NOT DEFINED basefilename)
+ message(FATAL_ERROR "pass -Dbasefilename=f1")
+endif()
+
+if(NOT DEFINED ext)
+ set(ext "jkqvxz")
+endif()
+
+if(NOT DEFINED sleep_interval)
+ set(sleep_interval 1)
+endif()
+
+get_filename_component(self_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(filename "${self_dir}/${basefilename}.${ext}")
+
+# count files
+file(GLOB f1 *.${ext})
+list(LENGTH f1 c1)
+message("c='${c1}'")
+
+# write a new file
+message("Writing file: filename='${filename}'")
+file(WRITE "${filename}" "${filename}")
+
+# count files again
+file(GLOB f2 *.${ext})
+list(LENGTH f2 c2)
+message("c='${c2}'")
+
+# snooze
+message("Sleeping: sleep_interval='${sleep_interval}'")
+ctest_sleep(${sleep_interval})
+
+# count files again
+file(GLOB f3 *.${ext})
+list(LENGTH f3 c3)
+message("c='${c3}'")
+
+# delete the file we wrote earlier
+message("Removing file: filename='${filename}'")
+file(REMOVE "${filename}")
+
+# count files again
+file(GLOB f4 *.${ext})
+list(LENGTH f4 c4)
+message("c='${c4}'")
diff --git a/Tests/CTestScriptMode/CTestTestScriptMode.cmake.in b/Tests/CTestScriptMode/CTestTestScriptMode.cmake.in
new file mode 100644
index 0000000000..45f0e3710d
--- /dev/null
+++ b/Tests/CTestScriptMode/CTestTestScriptMode.cmake.in
@@ -0,0 +1,14 @@
+# This script will be executed with ctest -S
+
+# Check that the system name is determined correctly:
+set(CMAKE_CMAKE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@")
+
+if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "${CMAKE_CMAKE_SYSTEM_NAME}")
+ message(FATAL_ERROR "Error: CMAKE_SYSTEM_NAME is \"${CMAKE_SYSTEM_NAME}\", but should be \"@CMAKE_SYSTEM_NAME@\"")
+endif()
+
+# this seems to be necessary, otherwise ctest complains that these
+# variables are not set:
+set(CTEST_COMMAND "\"@CMAKE_CTEST_COMMAND@\"")
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestScriptMode/")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestScriptMode/")
diff --git a/Tests/CTestTest/SmallAndFast/CMakeLists.txt b/Tests/CTestTest/SmallAndFast/CMakeLists.txt
new file mode 100644
index 0000000000..85cb30ceff
--- /dev/null
+++ b/Tests/CTestTest/SmallAndFast/CMakeLists.txt
@@ -0,0 +1,25 @@
+cmake_minimum_required(VERSION 2.8)
+project(SmallAndFast)
+
+include(CTest)
+
+add_executable(echoargs echoargs.c)
+set_property(SOURCE echoargs.c APPEND PROPERTY LABELS SourceLabel Everything)
+set_property(TARGET echoargs APPEND PROPERTY LABELS TargetLabel Everything)
+
+add_test(test0 echoargs)
+set_property(TEST test0 APPEND PROPERTY LABELS TestLabel 0ArgTest Everything)
+
+add_test(test1 echoargs 1)
+set_property(TEST test1 APPEND PROPERTY LABELS TestLabel 1ArgTest Everything)
+
+add_test(test2 echoargs 1 2)
+set_property(TEST test2 APPEND PROPERTY LABELS TestLabel 2ArgTest Everything)
+
+if(SAF_INTENTIONAL_COMPILE_ERROR)
+ add_executable(ice intentional_compile_error.cxx)
+endif()
+
+if(SAF_INTENTIONAL_COMPILE_WARNING)
+ add_executable(icw intentional_compile_warning.cxx)
+endif()
diff --git a/Tests/CTestTest/SmallAndFast/echoargs.c b/Tests/CTestTest/SmallAndFast/echoargs.c
new file mode 100644
index 0000000000..6e17464f7b
--- /dev/null
+++ b/Tests/CTestTest/SmallAndFast/echoargs.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int main(int argc, const char* argv[])
+{
+ int i = 0;
+ for (; i<argc; ++i)
+ {
+ fprintf(stdout, "%s\n", argv[i]);
+ }
+ return 0;
+}
diff --git a/Tests/CTestTest/SmallAndFast/intentional_compile_error.cxx b/Tests/CTestTest/SmallAndFast/intentional_compile_error.cxx
new file mode 100644
index 0000000000..a8930cf724
--- /dev/null
+++ b/Tests/CTestTest/SmallAndFast/intentional_compile_error.cxx
@@ -0,0 +1 @@
+garbage - obviously this should not compile as is
diff --git a/Tests/CTestTest/SmallAndFast/intentional_compile_warning.cxx b/Tests/CTestTest/SmallAndFast/intentional_compile_warning.cxx
new file mode 100644
index 0000000000..8ea5e404f7
--- /dev/null
+++ b/Tests/CTestTest/SmallAndFast/intentional_compile_warning.cxx
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int main(int argc, const char* argv[])
+{
+ unsigned int i = 0; // "i<argc" should produce a "signed/unsigned comparison" warning
+ for (; i<argc; ++i)
+ {
+ fprintf(stdout, "%s\n", argv[i]);
+ }
+ return 0;
+}
diff --git a/Tests/CTestTest/test.cmake.in b/Tests/CTestTest/test.cmake.in
new file mode 100644
index 0000000000..bb6346b8a2
--- /dev/null
+++ b/Tests/CTestTest/test.cmake.in
@@ -0,0 +1,70 @@
+# please see common.cmake for more documentation
+###################################################################
+# The values in this section must always be provided
+###################################################################
+
+# this is the cvs module name that should be checked out
+set (CTEST_MODULE_NAME SmallAndFast)
+
+# these are the name of the source and binary directory on disk.
+# They will be appended to DASHBOARD_ROOT
+set (CTEST_SOURCE_NAME SmallAndFast)
+set (CTEST_BINARY_NAME SmallAndFastBuild)
+
+# which ctest command to use for running the dashboard
+set (CTEST_COMMAND
+ "\"${CTEST_EXECUTABLE_NAME}\" --version"
+ "\"${CTEST_EXECUTABLE_NAME}\" -D Experimental -A \"${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}\""
+ )
+
+# what cmake command to use for configuring this dashboard
+get_filename_component(CTEST_EXECUTABLE_PATH "${CTEST_EXECUTABLE_NAME}" PATH)
+set(CTEST_CMAKE_COMMAND "\"${CTEST_EXECUTABLE_PATH}/cmake\"")
+
+message("CTest executable: ${CTEST_EXECUTABLE_NAME}")
+message("CMake executable: ${CTEST_CMAKE_COMMAND}")
+
+CTEST_SLEEP(1)
+CTEST_SLEEP(1 1 1)
+
+####################################################################
+# The values in this section are optional you can either
+# have them or leave them commented out
+####################################################################
+
+# should ctest wipe the binary tree before running
+set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY TRUE)
+
+# this is the initial cache to use for the binary tree, be careful to escape
+# any quotes inside of this string if you use it
+set (CTEST_INITIAL_CACHE "
+SITE:STRING=@SITE@
+BUILDNAME:STRING=SmallAndFast-@BUILDNAME@
+CMAKE_GENERATOR:INTERNAL=@CMAKE_GENERATOR@
+CMAKE_GENERATOR_PLATFORM:INTERNAL=@CMAKE_GENERATOR_PLATFORM@
+CMAKE_GENERATOR_TOOLSET:INTERNAL=@CMAKE_GENERATOR_TOOLSET@
+CMAKE_CXX_FLAGS:STRING=@CMAKE_CXX_FLAGS@
+CMAKE_C_FLAGS:STRING=@CMAKE_C_FLAGS@
+CMAKE_C_COMPILER:STRING=@CMAKE_C_COMPILER@
+CMAKE_CXX_COMPILER:STRING=@CMAKE_CXX_COMPILER@
+CMAKE_C_COMPILER_ARG1:STRING=@CMAKE_C_COMPILER_ARG1@
+CMAKE_CXX_COMPILER_ARG1:STRING=@CMAKE_CXX_COMPILER_ARG1@
+DART_ROOT:PATH=
+MEMORYCHECK_COMMAND:STRING=@MEMORYCHECK_COMMAND@
+MEMORYCHECK_SUPPRESSIONS_FILE:FILEPATH=@MEMORYCHECK_SUPPRESSIONS_FILE@
+MEMORYCHECK_COMMAND_OPTIONS:STRING=@MEMORYCHECK_COMMAND_OPTIONS@
+COVERAGE_COMMAND:FILEPATH=@COVERAGE_COMMAND@
+")
+
+# if you do not want to use the default location for a
+# dashboard then set this variable to the directory
+# the dashboard should be in
+set (CTEST_DASHBOARD_ROOT "@CMAKE_CURRENT_BINARY_DIR@/Tests/CTestTest")
+
+
+# set any extra envionment varibles here
+set (CTEST_ENVIRONMENT
+)
+
+set (CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTest/SmallAndFast")
+set (CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTest/${CTEST_BINARY_NAME}")
diff --git a/Tests/CTestTest2/test.cmake.in b/Tests/CTestTest2/test.cmake.in
new file mode 100644
index 0000000000..852bb6b6cb
--- /dev/null
+++ b/Tests/CTestTest2/test.cmake.in
@@ -0,0 +1,62 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "KWSys-@BUILDNAME@-CTest2")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Source/kwsys")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTest2/kwsysBin")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_MEMORYCHECK_COMMAND "@MEMORYCHECK_COMMAND@")
+set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE "@MEMORYCHECK_SUPPRESSIONS_FILE@")
+set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "@MEMORYCHECK_COMMAND_OPTIONS@")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+# By default, CTESTTEST2_USE_PURIFY is not defined. If you want to run purify
+# on CTestTest2, set CTESTTEST2_USE_PURIFY to ON in CMake's cache.
+set(CTESTTEST2_USE_PURIFY @CTESTTEST2_USE_PURIFY@)
+if("${CTEST_MEMORYCHECK_COMMAND}" MATCHES purify AND NOT CTESTTEST2_USE_PURIFY)
+ set(CTEST_MEMORYCHECK_COMMAND)
+endif()
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "
+CMAKE_CXX_FLAGS:STRING=@CMAKE_CXX_FLAGS@
+CMAKE_C_FLAGS:STRING=@CMAKE_C_FLAGS@
+CMAKE_C_COMPILER:STRING=@CMAKE_C_COMPILER@
+CMAKE_CXX_COMPILER:STRING=@CMAKE_CXX_COMPILER@
+CMAKE_C_COMPILER_ARG1:STRING=@CMAKE_C_COMPILER_ARG1@
+CMAKE_CXX_COMPILER_ARG1:STRING=@CMAKE_CXX_COMPILER_ARG1@
+
+# This one is needed for testing advanced ctest features
+CTEST_TEST_KWSYS:BOOL=ON
+")
+
+CTEST_START(Experimental)
+#CTEST_UPDATE(SOURCE "${CTEST_SOURCE_DIRECTORY}" RETURN_VALUE res)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res START 1 END 5 STRIDE 2)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res START 7 STRIDE 2 SUBMIT_INDEX 1)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res START 2 END 4 STRIDE 2 SUBMIT_INDEX 2)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res START 6 STRIDE 2 SUBMIT_INDEX 3)
+CTEST_MEMCHECK(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res STRIDE 1.5)
+CTEST_COVERAGE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+
+set(CTEST_DROP_METHOD "@protocol@")
+set(CTEST_DROP_SITE "@server@")
+set(CTEST_DROP_LOCATION "@path@/submit.php?project=PublicDashboard")
+
+CTEST_SUBMIT(RETURN_VALUE res)
+
+# Test submission of a subset of parts.
+set(CTEST_EXTRA_SUBMIT_FILES ${CTEST_NOTES_FILES})
+CTEST_SUBMIT(RETURN_VALUE res PARTS ExtraFiles)
+set(CTEST_EXTRA_SUBMIT_FILES)
diff --git a/Tests/CTestTestBadExe/CMakeLists.txt b/Tests/CTestTestBadExe/CMakeLists.txt
new file mode 100644
index 0000000000..c71c21516b
--- /dev/null
+++ b/Tests/CTestTestBadExe/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestBadExe)
+include(CTest)
+
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/notAnExe.txt" "${CMAKE_CURRENT_BINARY_DIR}/notAnExe.txt" COPYONLY)
+
+add_test (TestBadExe "${CMAKE_CURRENT_BINARY_DIR}/notAnExe.txt")
diff --git a/Tests/CTestTestBadExe/CTestConfig.cmake b/Tests/CTestTestBadExe/CTestConfig.cmake
new file mode 100644
index 0000000000..c7286e2c57
--- /dev/null
+++ b/Tests/CTestTestBadExe/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set (CTEST_PROJECT_NAME "CTestTestBadExe")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestBadExe/notAnExe.txt b/Tests/CTestTestBadExe/notAnExe.txt
new file mode 100644
index 0000000000..f2a0aa4a33
--- /dev/null
+++ b/Tests/CTestTestBadExe/notAnExe.txt
@@ -0,0 +1 @@
+This is not an executable file.
diff --git a/Tests/CTestTestBadExe/test.cmake.in b/Tests/CTestTestBadExe/test.cmake.in
new file mode 100644
index 0000000000..43a85725b1
--- /dev/null
+++ b/Tests/CTestTestBadExe/test.cmake.in
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-BadExe")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestBadExe")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestBadExe")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestBadGenerator/CMakeLists.txt b/Tests/CTestTestBadGenerator/CMakeLists.txt
new file mode 100644
index 0000000000..d46d9bf4f3
--- /dev/null
+++ b/Tests/CTestTestBadGenerator/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(CTestTestDepends NONE)
+include(CTest)
diff --git a/Tests/CTestTestBadGenerator/CTestConfig.cmake b/Tests/CTestTestBadGenerator/CTestConfig.cmake
new file mode 100644
index 0000000000..1e61bf4414
--- /dev/null
+++ b/Tests/CTestTestBadGenerator/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set (CTEST_PROJECT_NAME "CTestTestBadGenerator")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestBadGenerator/test.cmake.in b/Tests/CTestTestBadGenerator/test.cmake.in
new file mode 100644
index 0000000000..ae6d0b578c
--- /dev/null
+++ b/Tests/CTestTestBadGenerator/test.cmake.in
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 3.0)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Depends")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestBadGenerator")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestBadGenerator")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "Bad Generator")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestChecksum/test.cmake.in b/Tests/CTestTestChecksum/test.cmake.in
new file mode 100644
index 0000000000..32d62bb347
--- /dev/null
+++ b/Tests/CTestTestChecksum/test.cmake.in
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Checksum")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestParallel")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestParallel")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res PARALLEL_LEVEL 4)
+
+set(CTEST_DROP_METHOD "@protocol@")
+set(CTEST_DROP_SITE "@server@")
+set(CTEST_DROP_LOCATION "@path@/submit.php?project=PublicDashboard")
+
+CTEST_SUBMIT(RETRY_DELAY 3 RETRY_COUNT 2 INTERNAL_TEST_CHECKSUM RETURN_VALUE res)
diff --git a/Tests/CTestTestConfigFileInBuildDir/CMakeLists.txt b/Tests/CTestTestConfigFileInBuildDir/CMakeLists.txt
new file mode 100644
index 0000000000..3c53e66237
--- /dev/null
+++ b/Tests/CTestTestConfigFileInBuildDir/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8)
+project(CTestTestConfigFileInBuildDir)
+include(CTest)
diff --git a/Tests/CTestTestConfigFileInBuildDir/CTestConfig.cmake b/Tests/CTestTestConfigFileInBuildDir/CTestConfig.cmake
new file mode 100644
index 0000000000..4458348af1
--- /dev/null
+++ b/Tests/CTestTestConfigFileInBuildDir/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set(CTEST_PROJECT_NAME "CTestTestConfigFileInBuildDir")
+set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
+set(CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestConfigFileInBuildDir/test1.cmake.in b/Tests/CTestTestConfigFileInBuildDir/test1.cmake.in
new file mode 100644
index 0000000000..6d29af7ae2
--- /dev/null
+++ b/Tests/CTestTestConfigFileInBuildDir/test1.cmake.in
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-ConfigFileInBuildDir1")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestConfigFileInBuildDir")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestConfigFileInBuildDir1")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestConfigFileInBuildDir/test2.cmake.in b/Tests/CTestTestConfigFileInBuildDir/test2.cmake.in
new file mode 100644
index 0000000000..fb298d471c
--- /dev/null
+++ b/Tests/CTestTestConfigFileInBuildDir/test2.cmake.in
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-ConfigFileInBuildDir2")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestConfigFileInBuildDir")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestConfigFileInBuildDir2")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestCostSerial/CMakeLists.txt b/Tests/CTestTestCostSerial/CMakeLists.txt
new file mode 100644
index 0000000000..d3344cfabe
--- /dev/null
+++ b/Tests/CTestTestCostSerial/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required (VERSION 2.6)
+project (CTestTestCostSerial)
+include (CTest)
+
+add_executable (Sleep sleep.c)
+
+foreach (index RANGE 1 3)
+ add_test (TestSleep${index} Sleep)
+endforeach ()
+
+set_tests_properties(TestSleep1 PROPERTIES COST -500)
+set_tests_properties(TestSleep2 PROPERTIES COST 12)
+set_tests_properties(TestSleep3 PROPERTIES COST 0)
diff --git a/Tests/CTestTestCostSerial/CTestConfig.cmake b/Tests/CTestTestCostSerial/CTestConfig.cmake
new file mode 100644
index 0000000000..3ab99ac5e0
--- /dev/null
+++ b/Tests/CTestTestCostSerial/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set(CTEST_PROJECT_NAME "CTestTestCostSerial")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set(CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestCostSerial/sleep.c b/Tests/CTestTestCostSerial/sleep.c
new file mode 100644
index 0000000000..cb9f87ab22
--- /dev/null
+++ b/Tests/CTestTestCostSerial/sleep.c
@@ -0,0 +1,16 @@
+#if defined(_WIN32)
+# include <windows.h>
+#else
+# include <unistd.h>
+#endif
+
+/* sleeps for 1 second */
+int main(int argc, char** argv)
+{
+#if defined(_WIN32)
+ Sleep(1000);
+#else
+ sleep(1);
+#endif
+ return 0;
+}
diff --git a/Tests/CTestTestCostSerial/test.cmake.in b/Tests/CTestTestCostSerial/test.cmake.in
new file mode 100644
index 0000000000..9b32a468b2
--- /dev/null
+++ b/Tests/CTestTestCostSerial/test.cmake.in
@@ -0,0 +1,30 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-CostSerial")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestCostSerial")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestCostSerial")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+# Remove old cost data file if it exists
+if(EXISTS "${CTEST_BINARY_DIRECTORY}/Testing/Temporary/CTestCostData.txt")
+ file(REMOVE "${CTEST_BINARY_DIRECTORY}/Testing/Temporary/CTestCostData.txt")
+endif()
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+# Run test set a second time to make sure they run in same specified order
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestCrash/CMakeLists.txt b/Tests/CTestTestCrash/CMakeLists.txt
new file mode 100644
index 0000000000..77986df349
--- /dev/null
+++ b/Tests/CTestTestCrash/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestCrash)
+include(CTest)
+
+add_executable (Crash crash.cxx)
+
+add_test (TestCrash Crash)
diff --git a/Tests/CTestTestCrash/CTestConfig.cmake b/Tests/CTestTestCrash/CTestConfig.cmake
new file mode 100644
index 0000000000..5c2ca0ea95
--- /dev/null
+++ b/Tests/CTestTestCrash/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set (CTEST_PROJECT_NAME "CTestTestCrash")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestCrash/crash.cxx b/Tests/CTestTestCrash/crash.cxx
new file mode 100644
index 0000000000..bc9e096e43
--- /dev/null
+++ b/Tests/CTestTestCrash/crash.cxx
@@ -0,0 +1,6 @@
+//causes a segfault
+int main()
+{
+ int* ptr = 0;
+ *ptr = 1;
+}
diff --git a/Tests/CTestTestCrash/test.cmake.in b/Tests/CTestTestCrash/test.cmake.in
new file mode 100644
index 0000000000..3641cb01f4
--- /dev/null
+++ b/Tests/CTestTestCrash/test.cmake.in
@@ -0,0 +1,24 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Crash")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestCrash")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestCrash")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+#CTEST_SUBMIT()
diff --git a/Tests/CTestTestCycle/CMakeLists.txt b/Tests/CTestTestCycle/CMakeLists.txt
new file mode 100644
index 0000000000..6ba6b8c953
--- /dev/null
+++ b/Tests/CTestTestCycle/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestCycle)
+include(CTest)
+
+add_executable (simple simple.cxx)
+add_test (one simple)
+add_test (two simple)
+add_test (three simple)
+
+# Add cyclical test dependency
+set_tests_properties(one PROPERTIES DEPENDS "two")
+set_tests_properties(two PROPERTIES DEPENDS "three")
+set_tests_properties(three PROPERTIES DEPENDS "one")
diff --git a/Tests/CTestTestCycle/CTestConfig.cmake b/Tests/CTestTestCycle/CTestConfig.cmake
new file mode 100644
index 0000000000..8aeb09b701
--- /dev/null
+++ b/Tests/CTestTestCycle/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set (CTEST_PROJECT_NAME "CTestTestCycle")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestCycle/simple.cxx b/Tests/CTestTestCycle/simple.cxx
new file mode 100644
index 0000000000..766b7751bf
--- /dev/null
+++ b/Tests/CTestTestCycle/simple.cxx
@@ -0,0 +1,5 @@
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/CTestTestCycle/test.cmake.in b/Tests/CTestTestCycle/test.cmake.in
new file mode 100644
index 0000000000..4a63dd612c
--- /dev/null
+++ b/Tests/CTestTestCycle/test.cmake.in
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Cycle")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestCycle")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestCycle")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestDepends/CMakeLists.txt b/Tests/CTestTestDepends/CMakeLists.txt
new file mode 100644
index 0000000000..5cd6d66657
--- /dev/null
+++ b/Tests/CTestTestDepends/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestDepends)
+include(CTest)
+
+add_executable (simple simple.cxx)
+add_executable (TestExe::Simple ALIAS simple)
+add_test (NAME one COMMAND TestExe::Simple)
+add_test (two simple)
+add_test (three simple)
+
+# Add redundant (but not cyclical) dependencies
+set_tests_properties(two PROPERTIES DEPENDS "one")
+set_tests_properties(three PROPERTIES DEPENDS "one;two")
diff --git a/Tests/CTestTestDepends/CTestConfig.cmake b/Tests/CTestTestDepends/CTestConfig.cmake
new file mode 100644
index 0000000000..7af9200e26
--- /dev/null
+++ b/Tests/CTestTestDepends/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set (CTEST_PROJECT_NAME "CTestTestDepends")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestDepends/simple.cxx b/Tests/CTestTestDepends/simple.cxx
new file mode 100644
index 0000000000..766b7751bf
--- /dev/null
+++ b/Tests/CTestTestDepends/simple.cxx
@@ -0,0 +1,5 @@
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/CTestTestDepends/test.cmake.in b/Tests/CTestTestDepends/test.cmake.in
new file mode 100644
index 0000000000..74fddb3d3c
--- /dev/null
+++ b/Tests/CTestTestDepends/test.cmake.in
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Depends")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestDepends")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestDepends")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestEmptyBinaryDirectory/test.cmake.in b/Tests/CTestTestEmptyBinaryDirectory/test.cmake.in
new file mode 100644
index 0000000000..8eb808f7de
--- /dev/null
+++ b/Tests/CTestTestEmptyBinaryDirectory/test.cmake.in
@@ -0,0 +1,66 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+set(CTEST_RUN_CURRENT_SCRIPT 0)
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestEmptyBinaryDirectory")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestEmptyBinaryDirectory")
+
+# make sure ctest does not remove directories without a CMakeCache.txt in it
+set(EMPTY_BINARY_DIR "${CTEST_BINARY_DIRECTORY}/empty_binary_dir")
+file(MAKE_DIRECTORY "${EMPTY_BINARY_DIR}")
+
+if(NOT EXISTS "${EMPTY_BINARY_DIR}"
+ OR EXISTS "${EMPTY_BINARY_DIR}/CMakeCache.txt")
+ message(FATAL_ERROR "empty_binary_dir precondition failed")
+endif()
+
+ctest_empty_binary_directory("${EMPTY_BINARY_DIR}")
+
+if(NOT EXISTS "${EMPTY_BINARY_DIR}")
+ message(FATAL_ERROR "empty_binary_dir should not have been removed")
+endif()
+
+# make sure ctest does remove directories with a CMakeCache.txt
+set(VALID_BINARY_DIR "${CTEST_BINARY_DIRECTORY}/valid_binary_dir")
+file(MAKE_DIRECTORY "${VALID_BINARY_DIR}")
+file(WRITE "${VALID_BINARY_DIR}/CMakeCache.txt")
+
+if(NOT EXISTS "${VALID_BINARY_DIR}"
+ OR NOT EXISTS "${VALID_BINARY_DIR}/CMakeCache.txt")
+ message(FATAL_ERROR "valid_binary_dir precondition failed")
+endif()
+
+ctest_empty_binary_directory("${VALID_BINARY_DIR}")
+
+if(EXISTS "${VALID_BINARY_DIR}")
+ message(FATAL_ERROR "valid_binary_dir should have been removed")
+endif()
+
+# make sure ctest removes build directories recursively
+set(DEEP_BINARY_DIR "${CTEST_BINARY_DIRECTORY}/deep_binary_dir")
+file(MAKE_DIRECTORY "${DEEP_BINARY_DIR}")
+file(WRITE "${DEEP_BINARY_DIR}/CMakeCache.txt")
+
+foreach(SUBDIR A Z A/A A/Z Z/A Z/Z)
+ set(FULL_SUBDIR "${DEEP_BINARY_DIR}/${SUBDIR}")
+ file(MAKE_DIRECTORY "${FULL_SUBDIR}")
+
+ foreach(SUBFILE A.cpp Z.bat)
+ set(FULL_SUBFILE "${FULL_SUBDIR}/${SUBFILE}")
+ file(WRITE "${FULL_SUBFILE}" "I am '${FULL_SUBFILE}'")
+ endforeach()
+endforeach()
+
+if(NOT EXISTS "${DEEP_BINARY_DIR}"
+ OR NOT EXISTS "${DEEP_BINARY_DIR}/CMakeCache.txt"
+ OR NOT EXISTS "${DEEP_BINARY_DIR}/Z/A/Z.bat")
+ message(FATAL_ERROR "deep_binary_dir precondition failed")
+endif()
+
+ctest_empty_binary_directory("${DEEP_BINARY_DIR}")
+
+if(EXISTS "${DEEP_BINARY_DIR}")
+ message(FATAL_ERROR "deep_binary_dir should have been removed")
+endif()
+
+message("TEST_SUCCESS")
diff --git a/Tests/CTestTestFailedSubmits/test.cmake.in b/Tests/CTestTestFailedSubmits/test.cmake.in
new file mode 100644
index 0000000000..5ff836feeb
--- /dev/null
+++ b/Tests/CTestTestFailedSubmits/test.cmake.in
@@ -0,0 +1,49 @@
+cmake_minimum_required(VERSION 2.8)
+
+# CTestConfig.cmake settings:
+set(CTEST_PROJECT_NAME "SmallAndFast")
+
+# Intentionally leave out other upload-related CTestConfig.cmake settings
+# so that the ctest_submit call below fails with an error message...
+#
+set(CTEST_DROP_METHOD "@drop_method@")
+
+# Settings:
+set(CTEST_USE_LAUNCHERS 1)
+
+# Emit these compiler warnings:
+set(ENV{CXXFLAGS} "$ENV{CXXFLAGS} -Wall")
+
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTestLaunchers-@drop_method@")
+
+set(CTEST_SOURCE_DIRECTORY "@source@")
+set(CTEST_BINARY_DIRECTORY "@build@")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+CTEST_START(Experimental)
+
+# explicitly do not use CTEST_UPDATE - avoid network activity
+
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}"
+ OPTIONS "-DCTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS};-DSAF_INTENTIONAL_COMPILE_ERROR:BOOL=ON;-DSAF_INTENTIONAL_COMPILE_WARNING:BOOL=ON"
+ RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_COVERAGE(BUILD "${CTEST_BINARY_DIRECTORY}" @ctest_coverage_labels_args@ RETURN_VALUE res)
+
+# ok to call ctest_submit - still avoids network activity because there is
+# not a valid drop location given above...
+CTEST_SUBMIT(RETURN_VALUE res)
+
+# Add coverage for the new APPEND arg to ctest_start:
+#
+CTEST_START(Experimental APPEND)
diff --git a/Tests/CTestTestFailure/CMakeLists.txt b/Tests/CTestTestFailure/CMakeLists.txt
new file mode 100644
index 0000000000..01fbb2c4f3
--- /dev/null
+++ b/Tests/CTestTestFailure/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestFailure)
+include(CTest)
+
+add_executable (NoBuild badCode.cxx)
+target_link_libraries (NoBuild ${EXTRA_LIBS})
+
+add_test (TestNoExe NoBuild)
diff --git a/Tests/CTestTestFailure/CTestConfig.cmake b/Tests/CTestTestFailure/CTestConfig.cmake
new file mode 100644
index 0000000000..07e1be00c5
--- /dev/null
+++ b/Tests/CTestTestFailure/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set (CTEST_PROJECT_NAME "CTestTestFailure")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestFailure/badCode.cxx b/Tests/CTestTestFailure/badCode.cxx
new file mode 100644
index 0000000000..b410f0a139
--- /dev/null
+++ b/Tests/CTestTestFailure/badCode.cxx
@@ -0,0 +1,4 @@
+int main()
+{
+this code will not compile
+}
diff --git a/Tests/CTestTestFailure/testNoBuild.cmake.in b/Tests/CTestTestFailure/testNoBuild.cmake.in
new file mode 100644
index 0000000000..86333af4a1
--- /dev/null
+++ b/Tests/CTestTestFailure/testNoBuild.cmake.in
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-NoBuild")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestFailure")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestFailure")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+CTEST_START(Experimental)
+#CTEST_UPDATE(SOURCE "${CTEST_SOURCE_DIRECTORY}" RETURN_VALUE res)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestFailure/testNoExe.cmake.in b/Tests/CTestTestFailure/testNoExe.cmake.in
new file mode 100644
index 0000000000..8875cee361
--- /dev/null
+++ b/Tests/CTestTestFailure/testNoExe.cmake.in
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-NoExe")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestFailure")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestFailure")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+CTEST_START(Experimental)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestFdSetSize/CMakeLists.txt b/Tests/CTestTestFdSetSize/CMakeLists.txt
new file mode 100644
index 0000000000..f3827460d9
--- /dev/null
+++ b/Tests/CTestTestFdSetSize/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required (VERSION 2.8.10)
+project (CTestTestFdSetSize)
+include (CTest)
+
+add_executable (Sleep sleep.c)
+
+foreach (index RANGE 1 20)
+ add_test (TestSleep${index} Sleep)
+endforeach ()
diff --git a/Tests/CTestTestFdSetSize/CTestConfig.cmake b/Tests/CTestTestFdSetSize/CTestConfig.cmake
new file mode 100644
index 0000000000..b5f3c33630
--- /dev/null
+++ b/Tests/CTestTestFdSetSize/CTestConfig.cmake
@@ -0,0 +1 @@
+set(CTEST_PROJECT_NAME "CTestTestFdSetSize")
diff --git a/Tests/CTestTestFdSetSize/sleep.c b/Tests/CTestTestFdSetSize/sleep.c
new file mode 100644
index 0000000000..b2e6a8756a
--- /dev/null
+++ b/Tests/CTestTestFdSetSize/sleep.c
@@ -0,0 +1,16 @@
+#if defined(_WIN32)
+# include <windows.h>
+#else
+# include <unistd.h>
+#endif
+
+/* sleeps for 0.1 second */
+int main(int argc, char** argv)
+{
+#if defined(_WIN32)
+ Sleep(100);
+#else
+ usleep(100 * 1000);
+#endif
+ return 0;
+}
diff --git a/Tests/CTestTestFdSetSize/test.cmake.in b/Tests/CTestTestFdSetSize/test.cmake.in
new file mode 100644
index 0000000000..bfe4459259
--- /dev/null
+++ b/Tests/CTestTestFdSetSize/test.cmake.in
@@ -0,0 +1,24 @@
+cmake_minimum_required(VERSION 2.8.10)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-FdSetSize")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestFdSetSize")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestFdSetSize")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+ctest_start(Experimental)
+ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+message("build")
+ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+message("test")
+ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}" PARALLEL_LEVEL 20 RETURN_VALUE res)
+message("done")
diff --git a/Tests/CTestTestLabelRegExp/CTestTestfile.cmake.in b/Tests/CTestTestLabelRegExp/CTestTestfile.cmake.in
new file mode 100644
index 0000000000..657f382861
--- /dev/null
+++ b/Tests/CTestTestLabelRegExp/CTestTestfile.cmake.in
@@ -0,0 +1,8 @@
+add_test(test1 ${CMAKE_COMMAND} -E echo test1)
+set_tests_properties(test1 PROPERTIES LABELS "foo")
+
+add_test(test2 ${CMAKE_COMMAND} -E echo test2)
+set_tests_properties(test2 PROPERTIES LABELS "bar")
+
+add_test(test3 ${CMAKE_COMMAND} -E echo test3)
+set_tests_properties(test3 PROPERTIES LABELS "foo;bar")
diff --git a/Tests/CTestTestLabelRegExp/test.cmake.in b/Tests/CTestTestLabelRegExp/test.cmake.in
new file mode 100644
index 0000000000..5c0c9d7ffb
--- /dev/null
+++ b/Tests/CTestTestLabelRegExp/test.cmake.in
@@ -0,0 +1,37 @@
+configure_file(${SOURCE_DIR}/CTestTestfile.cmake.in CTestTestfile.cmake)
+
+function(get_test_list TEST_LIST)
+ set(QUERY_COMMAND ${CMAKE_CTEST_COMMAND} -N ${ARGN})
+
+ execute_process(COMMAND ${QUERY_COMMAND}
+ RESULT_VARIABLE RESULT
+ OUTPUT_VARIABLE OUTPUT
+ ERROR_VARIABLE ERROR)
+
+ if(NOT ${RESULT} STREQUAL "0")
+ message(FATAL_ERROR "command [${QUERY_COMMAND}] failed: RESULT[${RESULT}] OUTPUT[${OUTPUT}] ERROR[${ERROR}]")
+ endif()
+
+ set(${TEST_LIST} "${OUTPUT}" PARENT_SCOPE)
+endfunction()
+
+function(expect_test_list EXPECTED_OUTPUT)
+ get_test_list(TEST_LIST ${ARGN})
+
+ if(NOT "${TEST_LIST}" MATCHES "${EXPECTED_OUTPUT}")
+ message(FATAL_ERROR "actual output [${TEST_LIST}] does not match expected output [${EXPECTED_OUTPUT}] for given arguments [${ARGN}]")
+ endif()
+endfunction()
+
+expect_test_list("test1.*test3.*Total Tests: 2" --label-regex foo)
+expect_test_list("test2.*test3.*Total Tests: 2" --label-regex bar)
+expect_test_list("test1.*test2.*test3.*Total Tests: 3" --label-regex foo|bar)
+expect_test_list("Total Tests: 0" --label-regex baz)
+
+expect_test_list("test2.*Total Tests: 1" --label-exclude foo)
+expect_test_list("test1.*Total Tests: 1" --label-exclude bar)
+expect_test_list("Total Tests: 0" --label-exclude foo|bar)
+expect_test_list("test1.*test2.*test3.*Total Tests: 3" --label-exclude baz)
+
+expect_test_list("test1.*Total Tests: 1" --label-regex foo --label-exclude bar)
+expect_test_list("test2.*Total Tests: 1" --label-regex bar --label-exclude foo)
diff --git a/Tests/CTestTestLaunchers/launcher_test_project/CMakeLists.txt b/Tests/CTestTestLaunchers/launcher_test_project/CMakeLists.txt
new file mode 100644
index 0000000000..06c57253df
--- /dev/null
+++ b/Tests/CTestTestLaunchers/launcher_test_project/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+project(launcher_test_project)
+
+include(CTest)
+
+add_custom_command(
+ OUTPUT test1.txt
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -DTESTID=1 -P "${CMAKE_CURRENT_SOURCE_DIR}/command.cmake"
+)
+
+add_custom_command(
+ OUTPUT test2.txt
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -DTESTID=2 -P "${CMAKE_CURRENT_SOURCE_DIR}/command.cmake"
+)
+
+add_custom_target(mytarget ALL DEPENDS test1.txt test2.txt)
diff --git a/Tests/CTestTestLaunchers/launcher_test_project/CTestConfig.cmake b/Tests/CTestTestLaunchers/launcher_test_project/CTestConfig.cmake
new file mode 100644
index 0000000000..669b0fb680
--- /dev/null
+++ b/Tests/CTestTestLaunchers/launcher_test_project/CTestConfig.cmake
@@ -0,0 +1,8 @@
+set(CTEST_USE_LAUNCHERS 1)
+set(CTEST_PROJECT_NAME "CTestTestLaunchers")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set(CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestLaunchers/launcher_test_project/command.cmake b/Tests/CTestTestLaunchers/launcher_test_project/command.cmake
new file mode 100644
index 0000000000..7f31af9508
--- /dev/null
+++ b/Tests/CTestTestLaunchers/launcher_test_project/command.cmake
@@ -0,0 +1,5 @@
+if("${TESTID}" STREQUAL "1")
+ message("success")
+elseif("${TESTID}" STREQUAL "2")
+ message(FATAL_ERROR "failure")
+endif()
diff --git a/Tests/CTestTestLaunchers/test.cmake.in b/Tests/CTestTestLaunchers/test.cmake.in
new file mode 100644
index 0000000000..03a118a406
--- /dev/null
+++ b/Tests/CTestTestLaunchers/test.cmake.in
@@ -0,0 +1,40 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+# Settings:
+set(CTEST_DASHBOARD_SOURCE "@CMake_SOURCE_DIR@/Tests/CTestTestLaunchers")
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTestLaunchers")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "Launchers-@BUILDNAME@-CTestTestLaunchers")
+
+set(CTEST_SOURCE_DIRECTORY "${CTEST_DASHBOARD_SOURCE}/launcher_test_project")
+set(CTEST_BINARY_DIRECTORY "${CTEST_DASHBOARD_ROOT}/launcher_test_project-bin")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
+
+file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "
+CMAKE_CXX_FLAGS:STRING=@CMAKE_CXX_FLAGS@
+CMAKE_C_FLAGS:STRING=@CMAKE_C_FLAGS@
+CMAKE_C_COMPILER:STRING=@CMAKE_C_COMPILER@
+CMAKE_CXX_COMPILER:STRING=@CMAKE_CXX_COMPILER@
+CMAKE_C_COMPILER_ARG1:STRING=@CMAKE_C_COMPILER_ARG1@
+CMAKE_CXX_COMPILER_ARG1:STRING=@CMAKE_CXX_COMPILER_ARG1@
+")
+
+set(TEST_SUCCESS FALSE)
+
+ctest_start(Experimental)
+ctest_configure(OPTIONS "-DCTEST_USE_LAUNCHERS=1")
+ctest_build(NUMBER_ERRORS error_count)
+
+if("${error_count}" STREQUAL "1")
+ set(TEST_SUCCESS TRUE)
+endif()
+
+if(TEST_SUCCESS)
+ message("CTEST_TEST_LAUNCHER_SUCCESS")
+endif()
diff --git a/Tests/CTestTestMemcheck/CMakeLists.txt b/Tests/CTestTestMemcheck/CMakeLists.txt
new file mode 100644
index 0000000000..2023e74cfa
--- /dev/null
+++ b/Tests/CTestTestMemcheck/CMakeLists.txt
@@ -0,0 +1,290 @@
+REGEX_ESCAPE_STRING(CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+
+get_filename_component(CTEST_REALPATH_CMAKE_CURRENT_BINARY_DIR
+ "${CMAKE_CURRENT_BINARY_DIR}" REALPATH
+)
+
+REGEX_ESCAPE_STRING(CTEST_ESCAPED_REALPATH_CMAKE_CURRENT_BINARY_DIR
+ "${CTEST_REALPATH_CMAKE_CURRENT_BINARY_DIR}"
+)
+
+foreach (_retval 0 1)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/memtester.cxx.in" "${CMAKE_CURRENT_BINARY_DIR}/ret${_retval}.cxx" @ONLY)
+endforeach ()
+
+include_directories(${CMake_SOURCE_DIR}/Source ${CMake_BINARY_DIR}/Source)
+
+# create binaries that we will use as a pseudo memory checker
+add_executable(pseudo_valgrind "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx")
+set_target_properties(pseudo_valgrind PROPERTIES OUTPUT_NAME valgrind)
+target_link_libraries(pseudo_valgrind CMakeLib)
+
+add_executable(pseudo_purify "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx")
+set_target_properties(pseudo_purify PROPERTIES OUTPUT_NAME purify)
+target_link_libraries(pseudo_purify CMakeLib)
+add_executable(pseudo_BC "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx")
+set_target_properties(pseudo_BC PROPERTIES OUTPUT_NAME BC)
+target_link_libraries(pseudo_BC CMakeLib)
+
+# binary to be used as pre- and post-memcheck command that fails
+add_executable(memcheck_fail "${CMAKE_CURRENT_BINARY_DIR}/ret1.cxx")
+target_link_libraries(memcheck_fail CMakeLib)
+
+# Binaries that are used as memchecker that do not write the expected
+# output file. Need to be in their own subdirectory as they have the
+# same filenames.
+add_subdirectory(NoLogDummyChecker)
+
+if(APPLE)
+ # filter out additional messages by Guard Malloc integrated in Xcode
+ set(guard_malloc_msg "ctest\\([0-9]+\\) malloc: ")
+ set(guard_malloc_lines "(${guard_malloc_msg}[^\n]*\n)*")
+ set(guard_malloc_output "${guard_malloc_msg}|")
+else()
+ set(guard_malloc_msg "")
+ set(guard_malloc_lines "")
+ set(guard_malloc_output "")
+endif()
+
+# When this entire test runs under coverage or memcheck tools
+# they may add output to the end, so match known cases:
+# - Bullseye adds a "BullseyeCoverage..." line.
+# - Valgrind memcheck may add extra "==..." lines.
+set(other_tool_output "((${guard_malloc_output}BullseyeCoverage|==)[^\n]*\n)*")
+
+string(REPLACE "\r\n" "\n" ctest_and_tool_outputs "
+1/1 MemCheck #1: RunCMake \\.+ Passed +[0-9]+\\.[0-9]+ sec
+${guard_malloc_lines}
+100% tests passed, 0 tests failed out of 1
+.*
+-- Processing memory checking output:( )
+${guard_malloc_lines}Memory checking results:
+${other_tool_output}")
+
+function(gen_mc_test_internal NAME CHECKER)
+ set(SUBTEST_NAME "${NAME}")
+ set(CHECKER_COMMAND "${CHECKER}")
+ foreach(_file IN ITEMS CMakeLists.txt CTestConfig.cmake test.cmake)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${_file}.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/${NAME}/${_file}" @ONLY)
+ endforeach()
+ add_test(NAME CTestTestMemcheck${NAME}
+ COMMAND ${CMAKE_CTEST_COMMAND}
+ -C $<CONFIGURATION>
+ -S "${CMAKE_CURRENT_BINARY_DIR}/${NAME}/test.cmake" -V
+ --output-log "${CMAKE_CURRENT_BINARY_DIR}/${NAME}/testOutput.log"
+ ${ARGN}
+ )
+endfunction(gen_mc_test_internal)
+
+function(gen_mc_test NAME CHECKER)
+ gen_mc_test_internal(${NAME} "${CHECKER}"
+ -D PSEUDO_BC=$<TARGET_FILE:pseudo_BC>
+ -D PSEUDO_PURIFY=$<TARGET_FILE:pseudo_purify>
+ -D PSEUDO_VALGRIND=$<TARGET_FILE:pseudo_valgrind>
+ -D ERROR_COMMAND=$<TARGET_FILE:memcheck_fail>
+ ${ARGN}
+ )
+endfunction(gen_mc_test)
+
+function(gen_mcnl_test NAME CHECKER)
+ gen_mc_test_internal(${NAME} ${CHECKER}
+ -D PSEUDO_BC=$<TARGET_FILE:pseudonl_BC>
+ -D PSEUDO_PURIFY=$<TARGET_FILE:pseudonl_purify>
+ -D PSEUDO_VALGRIND=$<TARGET_FILE:pseudonl_valgrind>
+ ${ARGN}
+ )
+ set_tests_properties(CTestTestMemcheck${NAME}
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION "\nCannot find memory tester output file: ${CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR}/${NAME}/Testing/Temporary/MemoryChecker.1.log\n(.*\n)?Error in read script: ${CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR}/${NAME}/test.cmake\n")
+endfunction(gen_mcnl_test)
+
+unset(CTEST_EXTRA_CONFIG)
+unset(CTEST_EXTRA_CODE)
+unset(CMAKELISTS_EXTRA_CODE)
+
+#-----------------------------------------------------------------------------
+# add ThreadSanitizer test
+set(CTEST_EXTRA_CODE
+"set(CTEST_MEMORYCHECK_COMMAND_OPTIONS \"report_bugs=1 history_size=5 exitcode=55\")
+")
+set(CMAKELISTS_EXTRA_CODE
+"add_test(NAME TestSan COMMAND \"${CMAKE_COMMAND}\"
+-P \"${CMAKE_CURRENT_SOURCE_DIR}/testThreadSanitizer.cmake\")
+")
+gen_mc_test_internal(DummyThreadSanitizer "" -DMEMCHECK_TYPE=ThreadSanitizer)
+set_tests_properties(CTestTestMemcheckDummyThreadSanitizer PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ ".*Memory checking results:.*data race.* - 1.*data race on vptr .ctor/dtor vs virtual call. - 1.*heap-use-after-free - 1.*thread leak - 1.*destroy of a locked mutex - 1.*double lock of a mutex - 1.*unlock of an unlocked mutex .or by a wrong thread. - 1.*read lock of a write locked mutex - 1.*read unlock of a write locked mutex - 1.*signal-unsafe call inside of a signal - 1.*signal handler spoils errno - 1.*lock-order-inversion .potential deadlock. - 1.*")
+set(CMAKELISTS_EXTRA_CODE )
+set(CTEST_EXTRA_CODE)
+
+#-----------------------------------------------------------------------------
+# add LeakSanitizer test
+set(CTEST_EXTRA_CODE
+"set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS \"simulate_sanitizer=1 report_bugs=1 history_size=5 exitcode=55\")
+")
+set(CMAKELISTS_EXTRA_CODE
+"add_test(NAME TestSan COMMAND \"${CMAKE_COMMAND}\"
+-P \"${CMAKE_CURRENT_SOURCE_DIR}/testLeakSanitizer.cmake\")
+")
+gen_mc_test_internal(DummyLeakSanitizer "" -DMEMCHECK_TYPE=AddressSanitizer)
+set(CMAKELISTS_EXTRA_CODE )
+set(CTEST_EXTRA_CODE)
+set_tests_properties(CTestTestMemcheckDummyLeakSanitizer PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ ".*Memory checking results:.*Direct leak - 2.*Indirect leak - 1.*")
+
+#-----------------------------------------------------------------------------
+# add AddressSanitizer test
+set(CTEST_EXTRA_CODE
+"set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS \"simulate_sanitizer=1 report_bugs=1 history_size=5 exitcode=55\")
+")
+set(CMAKELISTS_EXTRA_CODE
+"add_test(NAME TestSan COMMAND \"${CMAKE_COMMAND}\"
+-P \"${CMAKE_CURRENT_SOURCE_DIR}/testAddressSanitizer.cmake\")
+")
+gen_mc_test_internal(DummyAddressSanitizer "" -DMEMCHECK_TYPE=AddressSanitizer)
+set(CMAKELISTS_EXTRA_CODE )
+set(CTEST_EXTRA_CODE)
+set_tests_properties(CTestTestMemcheckDummyAddressSanitizer PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ ".*Memory checking results:.*heap-buffer-overflow - 1.*")
+
+#-----------------------------------------------------------------------------
+# add MemorySanitizer test
+set(CTEST_EXTRA_CODE
+"set(CTEST_MEMORYCHECK_COMMAND_OPTIONS \"simulate_sanitizer=1 report_bugs=1 history_size=5 exitcode=55\")
+")
+
+set(CMAKELISTS_EXTRA_CODE
+"add_test(NAME TestSan COMMAND \"${CMAKE_COMMAND}\"
+-P \"${CMAKE_CURRENT_SOURCE_DIR}/testMemorySanitizer.cmake\")
+")
+gen_mc_test_internal(DummyMemorySanitizer "" -DMEMCHECK_TYPE=MemorySanitizer)
+set(CMAKELISTS_EXTRA_CODE )
+set(CTEST_EXTRA_CODE)
+set_tests_properties(CTestTestMemcheckDummyMemorySanitizer PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ ".*Memory checking results:.*use-of-uninitialized-value - 1.*")
+
+#-----------------------------------------------------------------------------
+# add UndefinedBehaviorSanitizer test
+set(CTEST_EXTRA_CODE
+"set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS \"simulate_sanitizer=1\")
+")
+
+set(CMAKELISTS_EXTRA_CODE
+"add_test(NAME TestSan COMMAND \"${CMAKE_COMMAND}\"
+-P \"${CMAKE_CURRENT_SOURCE_DIR}/testUndefinedBehaviorSanitizer.cmake\")
+")
+gen_mc_test_internal(DummyUndefinedBehaviorSanitizer "" -DMEMCHECK_TYPE=UndefinedBehaviorSanitizer)
+set(CMAKELISTS_EXTRA_CODE )
+set(CTEST_EXTRA_CODE)
+set_tests_properties(CTestTestMemcheckDummyUndefinedBehaviorSanitizer PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ ".*Memory checking results:.*left shift of negative value -256 - 1.*")
+
+#-----------------------------------------------------------------------------
+
+gen_mc_test(DummyPurify "\${PSEUDO_PURIFY}")
+gen_mc_test(DummyValgrind "\${PSEUDO_VALGRIND}")
+gen_mc_test(DummyBC "\${PSEUDO_BC}")
+gen_mcnl_test(DummyPurifyNoLogfile "\${PSEUDO_PURIFY}")
+gen_mcnl_test(DummyValgrindNoLogfile "\${PSEUDO_VALGRIND}")
+gen_mcnl_test(DummyBCNoLogfile "\${PSEUDO_BC}")
+
+set(CTEST_EXTRA_CODE "string(REPLACE \" \" \"\\\\ \" PRE_POST_COMMAND \"\${CTEST_MEMORYCHECK_COMMAND}\")
+
+set(CTEST_CUSTOM_PRE_MEMCHECK \"\${PRE_POST_COMMAND} pre command\")
+set(CTEST_CUSTOM_POST_MEMCHECK \"\${PRE_POST_COMMAND} post command \")
+")
+gen_mc_test(DummyValgrindPrePost "\${PSEUDO_VALGRIND}")
+
+set(CTEST_EXTRA_CODE "set(CTEST_CUSTOM_POST_MEMCHECK \"\${ERROR_COMMAND}\")")
+gen_mc_test(DummyValgrindFailPost "\${PSEUDO_VALGRIND}")
+
+set(CTEST_EXTRA_CODE "set(CTEST_CUSTOM_PRE_MEMCHECK \"\${ERROR_COMMAND}\")")
+gen_mc_test(DummyValgrindFailPre "\${PSEUDO_VALGRIND}")
+
+unset(CTEST_EXTRA_CODE)
+set(CTEST_EXTRA_CONFIG "set(CTEST_CUSTOM_MEMCHECK_IGNORE RunCMakeAgain)\n")
+set(CMAKELISTS_EXTRA_CODE "add_test(NAME RunCMakeAgain COMMAND \"\${CMAKE_COMMAND}\" --version)")
+gen_mc_test(DummyValgrindIgnoreMemcheck "\${PSEUDO_VALGRIND}")
+
+unset(CTEST_EXTRA_CONFIG)
+gen_mc_test(DummyValgrindTwoTargets "\${PSEUDO_VALGRIND}" "-VV")
+
+set(CTEST_EXTRA_CONFIG "set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE \"\${CMAKE_CURRENT_BINARY_DIR}/does-not-exist\")")
+unset(CMAKELISTS_EXTRA_CODE)
+gen_mc_test(DummyValgrindInvalidSupFile "\${PSEUDO_VALGRIND}")
+
+# CTest will add the logfile option before any custom options. Set the logfile
+# again, this time to an empty string. This will cause the logfile to be
+# missing, which will be the prove for us that the custom option is indeed used.
+set(CTEST_EXTRA_CONFIG "set(CTEST_MEMORYCHECK_COMMAND_OPTIONS \"--log-file=\")")
+gen_mc_test(DummyValgrindCustomOptions "\${PSEUDO_VALGRIND}")
+
+unset(CTEST_EXTRA_CONFIG)
+gen_mc_test(NotExist "\${CTEST_BINARY_DIRECTORY}/no-memcheck-exe")
+
+gen_mc_test(Unknown "${CMAKE_COMMAND}")
+
+string(REPLACE "\\" "\\\\" CMAKE_COMMAND_ESCAPED "${CMAKE_COMMAND}")
+string(REPLACE "(" "\\(" CMAKE_COMMAND_ESCAPED "${CMAKE_COMMAND_ESCAPED}")
+string(REPLACE ")" "\\)" CMAKE_COMMAND_ESCAPED "${CMAKE_COMMAND_ESCAPED}")
+string(REPLACE "+" "\\+" CMAKE_COMMAND_ESCAPED "${CMAKE_COMMAND_ESCAPED}")
+
+set_tests_properties(CTestTestMemcheckUnknown PROPERTIES
+ PASS_REGULAR_EXPRESSION "Do not understand memory checker: ${CMAKE_COMMAND_ESCAPED}\n(.*\n)?Error in read script: ${CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR}/Unknown/test.cmake\n")
+
+set_tests_properties(CTestTestMemcheckNotExist PROPERTIES
+ PASS_REGULAR_EXPRESSION "Memory checker \\(MemoryCheckCommand\\) not set, or cannot find the specified program.")
+
+# It is a valid result if valgrind does not output any files (can e.g. happen
+# if you have not compiled in debug mode), so these tests will not fail.
+set_tests_properties(CTestTestMemcheckDummyValgrind
+ CTestTestMemcheckDummyValgrindPrePost
+ CTestTestMemcheckDummyPurify
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION "${ctest_and_tool_outputs}$")
+
+foreach (_pp Pre Post)
+ string(TOLOWER ${_pp} _pp_lower)
+ set_tests_properties(CTestTestMemcheckDummyValgrindFail${_pp}
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION "\nProblem running command: ${CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR}[^\n]*fail[^\n]*\n(.*\n)?Problem executing ${_pp_lower}-memcheck command\\(s\\\).\n(.*\n)?Error in read script: ${CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR}/DummyValgrindFail${_pp}/test.cmake\n")
+endforeach ()
+
+set_tests_properties(CTestTestMemcheckDummyValgrindIgnoreMemcheck
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION "\n2/2 Test #2: RunCMakeAgain .*${ctest_and_tool_outputs}$")
+
+set_tests_properties(CTestTestMemcheckDummyBC PROPERTIES
+ PASS_REGULAR_EXPRESSION "\n1/1 MemCheck #1: RunCMake \\.+ Passed +[0-9]+.[0-9]+ sec\n${guard_malloc_lines}\n100% tests passed, 0 tests failed out of 1\n(.*\n)?Error parsing XML in stream at line 1: no element found\n")
+
+set_tests_properties(CTestTestMemcheckDummyValgrindInvalidSupFile PROPERTIES
+ PASS_REGULAR_EXPRESSION "\nCannot find memory checker suppression file: ${CTEST_ESCAPED_REALPATH_CMAKE_CURRENT_BINARY_DIR}/does-not-exist\n")
+
+set_tests_properties(CTestTestMemcheckDummyValgrindCustomOptions PROPERTIES
+ PASS_REGULAR_EXPRESSION "\nCannot find memory tester output file: ${CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR}/DummyValgrindCustomOptions/Testing/Temporary/MemoryChecker.1.log\n(.*\n)?Error in read script: ${CMAKE_CURRENT_BINARY_DIR}/DummyValgrindCustomOptions/test.cmake\n")
+
+set_tests_properties(CTestTestMemcheckDummyValgrindTwoTargets PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "\nMemory check project ${CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR}/DummyValgrindTwoTargets\n.*\n *Start 1: RunCMake\n(.*\n)?Memory check command: .* \"--log-file=${CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR}/DummyValgrindTwoTargets/Testing/Temporary/MemoryChecker.1.log\" \"-q\".*\n *Start 2: RunCMakeAgain\n(.*\n)?Memory check command: .* \"--log-file=${CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR}/DummyValgrindTwoTargets/Testing/Temporary/MemoryChecker.2.log\" \"-q\".*\n")
+
+
+# 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]")
+ foreach(t
+ memcheck_fail
+ pseudo_BC
+ pseudo_purify
+ pseudo_valgrind
+ )
+ add_custom_command(TARGET ${t}
+ PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CFG_INTDIR}"
+ )
+ endforeach()
+endif()
diff --git a/Tests/CTestTestMemcheck/CMakeLists.txt.in b/Tests/CTestTestMemcheck/CMakeLists.txt.in
new file mode 100644
index 0000000000..d15d14822c
--- /dev/null
+++ b/Tests/CTestTestMemcheck/CMakeLists.txt.in
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 2.8.9)
+project(CTestTestMemcheck@SUBTEST_NAME@ NONE)
+include(CTest)
+
+add_test(NAME RunCMake COMMAND "${CMAKE_COMMAND}" --version)
+
+@CMAKELISTS_EXTRA_CODE@
diff --git a/Tests/CTestTestMemcheck/CTestConfig.cmake.in b/Tests/CTestTestMemcheck/CTestConfig.cmake.in
new file mode 100644
index 0000000000..19c76c26c2
--- /dev/null
+++ b/Tests/CTestTestMemcheck/CTestConfig.cmake.in
@@ -0,0 +1,9 @@
+set (CTEST_PROJECT_NAME "CTestTestMemcheck@SUBTEST_NAME@")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
+
+@CTEST_EXTRA_CONFIG@
diff --git a/Tests/CTestTestMemcheck/NoLogDummyChecker/CMakeLists.txt b/Tests/CTestTestMemcheck/NoLogDummyChecker/CMakeLists.txt
new file mode 100644
index 0000000000..3a45bfecca
--- /dev/null
+++ b/Tests/CTestTestMemcheck/NoLogDummyChecker/CMakeLists.txt
@@ -0,0 +1,22 @@
+# A dummy checker implementation that does not write the requested output file
+# so it triggers an error for every checker.
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/ret0.c.in" "int main(){return 0;}\n")
+
+configure_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/ret0.c.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/ret0.c"
+ )
+
+foreach(_pseudo IN ITEMS valgrind purify BC)
+ add_executable(pseudonl_${_pseudo} "${CMAKE_CURRENT_BINARY_DIR}/ret0.c")
+ set_target_properties(pseudonl_${_pseudo} PROPERTIES OUTPUT_NAME ${_pseudo})
+
+ # 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 pseudonl_${_pseudo}
+ PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CFG_INTDIR}"
+ )
+ endif()
+endforeach()
diff --git a/Tests/CTestTestMemcheck/memtester.cxx.in b/Tests/CTestTestMemcheck/memtester.cxx.in
new file mode 100644
index 0000000000..43c0ba7a1a
--- /dev/null
+++ b/Tests/CTestTestMemcheck/memtester.cxx.in
@@ -0,0 +1,60 @@
+#include <cmSystemTools.h>
+#include <cmsys/Encoding.hxx>
+#include <string>
+#include <locale.h>
+
+#define RETVAL @_retval@
+
+int
+main(int ac, char **av)
+{
+ setlocale(LC_CTYPE, "");
+ cmsys::Encoding::CommandLineArguments args =
+ cmsys::Encoding::CommandLineArguments::Main(ac, av);
+ int argc = args.argc();
+ const char* const* argv = args.argv();
+
+ std::string exename = argv[0];
+ std::string logarg;
+ bool nextarg = false;
+
+ if (exename.find("valgrind") != exename.npos)
+ logarg = "--log-file=";
+ else if (exename.find("purify") != exename.npos)
+#ifdef _WIN32
+ logarg = "/SAVETEXTDATA=";
+#else
+ logarg = "-log-file=";
+#endif
+ else if (exename.find("BC") != exename.npos)
+ {
+ nextarg = true;
+ logarg = "/X";
+ }
+
+ if (!logarg.empty()) {
+ std::string logfile;
+ for (int i = 1; i < argc; i++) {
+ std::string arg = argv[i];
+ if (arg.find(logarg) == 0)
+ {
+ if (nextarg)
+ {
+ if (i == argc - 1)
+ return 1; // invalid command line
+ logfile = argv[i + 1];
+ }
+ else
+ {
+ logfile = arg.substr(logarg.length());
+ }
+ // keep searching, it may be overridden later to provoke an error
+ }
+ }
+
+ if (!logfile.empty())
+ cmSystemTools::Touch(logfile.c_str(), true);
+ }
+
+ return RETVAL;
+}
diff --git a/Tests/CTestTestMemcheck/test.cmake.in b/Tests/CTestTestMemcheck/test.cmake.in
new file mode 100644
index 0000000000..f2ffd06b75
--- /dev/null
+++ b/Tests/CTestTestMemcheck/test.cmake.in
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.8.9)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMAKE_CURRENT_BINARY_DIR@")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Memcheck@SUBTEST_NAME@")
+
+set(CTEST_SOURCE_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@/@SUBTEST_NAME@")
+set(CTEST_BINARY_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@/@SUBTEST_NAME@")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+set(CTEST_MEMORYCHECK_COMMAND "@CHECKER_COMMAND@")
+set(CTEST_MEMORYCHECK_TYPE "${MEMCHECK_TYPE}")
+
+@CTEST_EXTRA_CODE@
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_MEMCHECK(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestMemcheck/testAddressSanitizer.cmake b/Tests/CTestTestMemcheck/testAddressSanitizer.cmake
new file mode 100644
index 0000000000..3082e4b5a1
--- /dev/null
+++ b/Tests/CTestTestMemcheck/testAddressSanitizer.cmake
@@ -0,0 +1,58 @@
+# this file simulates a program that has been built with address sanitizer
+# options
+
+message("ASAN_OPTIONS = [$ENV{ASAN_OPTIONS}]")
+string(REGEX REPLACE ".*log_path=\"([^\"]*)\".*" "\\1" LOG_FILE "$ENV{ASAN_OPTIONS}")
+message("LOG_FILE=[${LOG_FILE}]")
+
+# if we are not asked to simulate address sanitizer don't do it
+if(NOT "$ENV{ASAN_OPTIONS}]" MATCHES "simulate_sanitizer.1")
+ return()
+endif()
+# clear the log file
+file(REMOVE "${LOG_FILE}.2343")
+
+# create an example error from address santizer
+
+file(APPEND "${LOG_FILE}.2343"
+"=================================================================
+==19278== ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60080000bffc at pc 0x4009f1 bp 0x7fff82de6520 sp 0x7fff82de6518
+WRITE of size 4 at 0x60080000bffc thread T0
+ #0 0x4009f0 (/home/kitware/msan/a.out+0x4009f0)
+ #1 0x7f18b02c876c (/lib/x86_64-linux-gnu/libc-2.15.so+0x2176c)
+ #2 0x400858 (/home/kitware/msan/a.out+0x400858)
+0x60080000bffc is located 4 bytes to the right of 40-byte region [0x60080000bfd0,0x60080000bff8)
+allocated by thread T0 here:
+ #0 0x7f18b088f9ca (/usr/lib/x86_64-linux-gnu/libasan.so.0.0.0+0x119ca)
+ #1 0x4009a2 (/home/kitware/msan/a.out+0x4009a2)
+ #2 0x7f18b02c876c (/lib/x86_64-linux-gnu/libc-2.15.so+0x2176c)
+Shadow bytes around the buggy address:
+ 0x0c017fff97a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+ 0x0c017fff97b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+ 0x0c017fff97c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+ 0x0c017fff97d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+ 0x0c017fff97e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+=>0x0c017fff97f0: fa fa fa fa fa fa fa fa fa fa 00 00 00 00 00[fa]
+ 0x0c017fff9800:fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+ 0x0c017fff9810: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+ 0x0c017fff9820: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+ 0x0c017fff9830: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+ 0x0c017fff9840: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
+Shadow byte legend (one shadow byte represents 8 application bytes):
+ Addressable: 00
+ Partially addressable: 01 02 03 04 05 06 07
+ Heap left redzone: fa
+ Heap righ redzone: fb
+ Freed Heap region: fd
+ Stack left redzone: f1
+ Stack mid redzone: f2
+ Stack right redzone: f3
+ Stack partial redzone: f4
+ Stack after return: f5
+ Stack use after scope: f8
+ Global redzone: f9
+ Global init order: f6
+ Poisoned by user: f7
+ ASan internal: fe
+==19278== ABORTING
+")
diff --git a/Tests/CTestTestMemcheck/testLeakSanitizer.cmake b/Tests/CTestTestMemcheck/testLeakSanitizer.cmake
new file mode 100644
index 0000000000..02030be87a
--- /dev/null
+++ b/Tests/CTestTestMemcheck/testLeakSanitizer.cmake
@@ -0,0 +1,47 @@
+# this file simulates a program that has been built with thread sanitizer
+# options
+
+message("ASAN_OPTIONS = [$ENV{ASAN_OPTIONS}]")
+string(REGEX REPLACE ".*log_path=\"([^\"]*)\".*" "\\1" LOG_FILE "$ENV{ASAN_OPTIONS}")
+message("LOG_FILE=[${LOG_FILE}]")
+# if we are not asked to simulate leak sanitizer don't do it
+if(NOT "$ENV{ASAN_OPTIONS}]" MATCHES "simulate_sanitizer.1")
+ return()
+endif()
+
+# clear the log file
+file(REMOVE "${LOG_FILE}.2343")
+file(REMOVE "${LOG_FILE}.2344")
+
+# create an error of each type of thread santizer
+# these names come from tsan_report.cc in llvm
+
+file(APPEND "${LOG_FILE}.2343"
+"=================================================================
+==25308==ERROR: LeakSanitizer: detected memory leaks
+
+Direct leak of 4360 byte(s) in 1 object(s) allocated from:
+ #0 0x46c669 in operator new[](unsigned long) (/home/kitware/msan/a.out+0x46c669)
+ #1 0x4823b4 in main /home/kitware/msan/memcheck.cxx:12
+ #2 0x7fa72bee476c in __libc_start_main /build/buildd/eglibc-2.15/csu/libc-start.c:226
+
+SUMMARY: AddressSanitizer: 4436 byte(s) leaked in 2 allocation(s).
+")
+file(APPEND "${LOG_FILE}.2342"
+"=================================================================
+==25308==ERROR: LeakSanitizer: detected memory leaks
+
+Direct leak of 76 byte(s) in 1 object(s) allocated from:
+ #0 0x46c669 in operator new[](unsigned long) (/home/kitware/msan/a.out+0x46c669)
+ #1 0x4821b8 in foo() /home/kitware/msan/memcheck.cxx:4
+ #2 0x4823f2 in main /home/kitware/msan/memcheck.cxx:14
+ #3 0x7fa72bee476c in __libc_start_main /build/buildd/eglibc-2.15/csu/libc-start.c:226
+
+Indirect leak of 76 byte(s) in 1 object(s) allocated from:
+ #0 0x46c669 in operator new[](unsigned long) (/home/kitware/msan/a.out+0x46c669)
+ #1 0x4821b8 in foo() /home/kitware/msan/memcheck.cxx:4
+ #2 0x4823f2 in main /home/kitware/msan/memcheck.cxx:14
+ #3 0x7fa72bee476c in __libc_start_main /build/buildd/eglibc-2.15/csu/libc-start.c:226
+
+SUMMARY: AddressSanitizer: 4436 byte(s) leaked in 2 allocation(s).
+")
diff --git a/Tests/CTestTestMemcheck/testMemorySanitizer.cmake b/Tests/CTestTestMemcheck/testMemorySanitizer.cmake
new file mode 100644
index 0000000000..c87af9a43f
--- /dev/null
+++ b/Tests/CTestTestMemcheck/testMemorySanitizer.cmake
@@ -0,0 +1,27 @@
+# this file simulates a program that has been built with thread sanitizer
+# options
+
+message("MSAN_OPTIONS = [$ENV{MSAN_OPTIONS}]")
+string(REGEX REPLACE ".*log_path=\"([^\"]*)\".*" "\\1" LOG_FILE "$ENV{MSAN_OPTIONS}")
+message("LOG_FILE=[${LOG_FILE}]")
+
+# if we are not asked to simulate address sanitizer don't do it
+if(NOT "$ENV{MSAN_OPTIONS}]" MATCHES "simulate_sanitizer.1")
+ return()
+endif()
+# clear the log file
+file(REMOVE "${LOG_FILE}.2343")
+
+# create an error of each type of thread santizer
+# these names come from tsan_report.cc in llvm
+
+file(APPEND "${LOG_FILE}.2343"
+"=================================================================
+==28423== WARNING: MemorySanitizer: use-of-uninitialized-value
+ #0 0x7f4364210dd9 in main (/home/kitware/msan/msan-bin/umr+0x7bdd9)
+ #1 0x7f4362d9376c in __libc_start_main /build/buildd/eglibc-2.15/csu/libc-start.c:226
+ #2 0x7f4364210b0c in _start (/home/kitware/msan/msan-bin/umr+0x7bb0c)
+
+SUMMARY: MemorySanitizer: use-of-uninitialized-value ??:0 main
+Exiting
+")
diff --git a/Tests/CTestTestMemcheck/testThreadSanitizer.cmake b/Tests/CTestTestMemcheck/testThreadSanitizer.cmake
new file mode 100644
index 0000000000..d591931469
--- /dev/null
+++ b/Tests/CTestTestMemcheck/testThreadSanitizer.cmake
@@ -0,0 +1,47 @@
+# this file simulates a program that has been built with thread sanitizer
+# options
+
+message("TSAN_OPTIONS = [$ENV{TSAN_OPTIONS}]")
+string(REGEX REPLACE ".*log_path=\"([^\"]*)\".*" "\\1" LOG_FILE "$ENV{TSAN_OPTIONS}")
+message("LOG_FILE=[${LOG_FILE}]")
+
+set(error_types
+ "data race"
+ "data race on vptr (ctor/dtor vs virtual call)"
+ "heap-use-after-free"
+ "thread leak"
+ "destroy of a locked mutex"
+ "double lock of a mutex"
+ "unlock of an unlocked mutex (or by a wrong thread)"
+ "read lock of a write locked mutex"
+ "read unlock of a write locked mutex"
+ "signal-unsafe call inside of a signal"
+ "signal handler spoils errno"
+ "lock-order-inversion (potential deadlock)"
+ )
+
+# clear the log file
+file(REMOVE "${LOG_FILE}.2343")
+
+# create an error of each type of thread santizer
+# these names come from tsan_report.cc in llvm
+foreach(error_type ${error_types} )
+
+ file(APPEND "${LOG_FILE}.2343"
+"==================
+WARNING: ThreadSanitizer: ${error_type} (pid=27978)
+ Write of size 4 at 0x7fe017ce906c by thread T1:
+ #0 Thread1 ??:0 (exe+0x000000000bb0)
+ #1 <null> <null>:0 (libtsan.so.0+0x00000001b279)
+
+ Previous write of size 4 at 0x7fe017ce906c by main thread:
+ #0 main ??:0 (exe+0x000000000c3c)
+
+ Thread T1 (tid=27979, running) created by main thread at:
+ #0 <null> <null>:0 (libtsan.so.0+0x00000001ed7b)
+ #1 main ??:0 (exe+0x000000000c2c)
+
+SUMMARY: ThreadSanitizer: ${error_type} ??:0 Thread1
+==================
+")
+endforeach()
diff --git a/Tests/CTestTestMemcheck/testUndefinedBehaviorSanitizer.cmake b/Tests/CTestTestMemcheck/testUndefinedBehaviorSanitizer.cmake
new file mode 100644
index 0000000000..8ef3c0aa67
--- /dev/null
+++ b/Tests/CTestTestMemcheck/testUndefinedBehaviorSanitizer.cmake
@@ -0,0 +1,21 @@
+# this file simulates a program that has been built with undefined behavior
+# sanitizer options
+
+message("UBSAN_OPTIONS = [$ENV{UBSAN_OPTIONS}]")
+string(REGEX REPLACE ".*log_path=\"([^\"]*)\".*" "\\1" LOG_FILE "$ENV{UBSAN_OPTIONS}")
+message("LOG_FILE=[${LOG_FILE}]")
+
+# if we are not asked to simulate address sanitizer don't do it
+if(NOT "$ENV{UBSAN_OPTIONS}]" MATCHES "simulate_sanitizer.1")
+ return()
+endif()
+# clear the log file
+file(REMOVE "${LOG_FILE}.2343")
+
+# create an error like undefined behavior santizer creates;
+# these names come from ubsan_diag.cc and ubsan_handlers.cc
+# in llvm
+
+file(APPEND "${LOG_FILE}.2343"
+"<unknown>: runtime error: left shift of negative value -256
+")
diff --git a/Tests/CTestTestMissingDependsExe/CMakeLists.txt b/Tests/CTestTestMissingDependsExe/CMakeLists.txt
new file mode 100644
index 0000000000..9826da661a
--- /dev/null
+++ b/Tests/CTestTestMissingDependsExe/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+project(CTestTestMissingDependsExe)
+
+enable_testing()
+
+add_test(test1 ${CMAKE_COMMAND} -E echo test)
+add_test(test2 non-existent-command)
+
+set_tests_properties(test1 PROPERTIES DEPENDS test2)
diff --git a/Tests/CTestTestParallel/CMakeLists.txt b/Tests/CTestTestParallel/CMakeLists.txt
new file mode 100644
index 0000000000..e47085a09b
--- /dev/null
+++ b/Tests/CTestTestParallel/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestParallel)
+include(CTest)
+
+add_executable (LockFile lockFile.c)
+
+add_test (TestRunSerial1 LockFile)
+add_test (TestRunSerial2 LockFile)
+set_tests_properties(TestRunSerial1 TestRunSerial2 PROPERTIES RUN_SERIAL true)
+
+add_test (TestProcessorsGreaterThanMPL1 LockFile)
+add_test (TestProcessorsGreaterThanMPL2 LockFile)
+set_tests_properties(TestProcessorsGreaterThanMPL1 PROPERTIES PROCESSORS 10)
+set_tests_properties(TestProcessorsGreaterThanMPL1 PROPERTIES DEPENDS
+ TestProcessorsGreaterThanMPL2)
diff --git a/Tests/CTestTestParallel/CTestConfig.cmake b/Tests/CTestTestParallel/CTestConfig.cmake
new file mode 100644
index 0000000000..fc5b6668ef
--- /dev/null
+++ b/Tests/CTestTestParallel/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set(CTEST_PROJECT_NAME "CTestTestParallel")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set(CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestParallel/lockFile.c b/Tests/CTestTestParallel/lockFile.c
new file mode 100644
index 0000000000..6a6a889ccf
--- /dev/null
+++ b/Tests/CTestTestParallel/lockFile.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+/*if run serially, works fine.
+ If run in parallel, someone will attempt to delete
+ a locked file, which will fail */
+int main(void)
+{
+ FILE* file;
+ int i;
+ const char* fname = "lockedFile.txt";
+ file = fopen(fname, "w");
+
+ for(i = 0; i < 10000; i++)
+ {
+ fprintf(file, "%s", "x");
+ fflush(file);
+ }
+ fclose(file);
+ return remove(fname);
+}
diff --git a/Tests/CTestTestParallel/test.cmake.in b/Tests/CTestTestParallel/test.cmake.in
new file mode 100644
index 0000000000..045a4ca06c
--- /dev/null
+++ b/Tests/CTestTestParallel/test.cmake.in
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Parallel")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestParallel")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestParallel")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res PARALLEL_LEVEL 4)
diff --git a/Tests/CTestTestResourceLock/CMakeLists.txt b/Tests/CTestTestResourceLock/CMakeLists.txt
new file mode 100644
index 0000000000..4001643fdf
--- /dev/null
+++ b/Tests/CTestTestResourceLock/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestResourceLock)
+include(CTest)
+
+add_executable (LockFile lockFile.c)
+
+add_test (TestLockedFile1.1 LockFile locked1.txt)
+add_test (TestLockedFile1.2 LockFile locked1.txt)
+set_tests_properties(TestLockedFile1.1 TestLockedFile1.2 PROPERTIES RESOURCE_LOCK "locked1.txt")
+
+add_test (TestLockedFile2.1 LockFile locked2.txt)
+add_test (TestLockedFile2.2 LockFile locked2.txt)
+set_tests_properties(TestLockedFile2.1 TestLockedFile2.2 PROPERTIES RESOURCE_LOCK "locked2.txt")
diff --git a/Tests/CTestTestResourceLock/CTestConfig.cmake b/Tests/CTestTestResourceLock/CTestConfig.cmake
new file mode 100644
index 0000000000..c1187778d2
--- /dev/null
+++ b/Tests/CTestTestResourceLock/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set(CTEST_PROJECT_NAME "CTestTestResourceLock")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set(CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestResourceLock/lockFile.c b/Tests/CTestTestResourceLock/lockFile.c
new file mode 100644
index 0000000000..a6a4dc0f4e
--- /dev/null
+++ b/Tests/CTestTestResourceLock/lockFile.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+
+/* Disable deprecation warning for fopen */
+#pragma warning(disable: 4996)
+
+/*if run serially, works fine.
+ If run in parallel, someone will attempt to delete
+ a locked file, which will fail */
+int main(int argc, char** argv)
+{
+ FILE* file;
+ int i;
+ const char* fname;
+ if(argc >= 2)
+ {
+ fname = argv[1];
+ }
+ else
+ {
+ fname = "lockedFile.txt";
+ }
+ file = fopen(fname, "w");
+
+ for(i = 0; i < 10000; i++)
+ {
+ fprintf(file, "%s", "x");
+ fflush(file);
+ }
+ fclose(file);
+ return remove(fname);
+}
diff --git a/Tests/CTestTestResourceLock/test.cmake.in b/Tests/CTestTestResourceLock/test.cmake.in
new file mode 100644
index 0000000000..67dde18032
--- /dev/null
+++ b/Tests/CTestTestResourceLock/test.cmake.in
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-ResourceLock")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestResourceLock")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestResourceLock")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res PARALLEL_LEVEL 4)
diff --git a/Tests/CTestTestRunScript/hello.cmake.in b/Tests/CTestTestRunScript/hello.cmake.in
new file mode 100644
index 0000000000..37905e3c41
--- /dev/null
+++ b/Tests/CTestTestRunScript/hello.cmake.in
@@ -0,0 +1,2 @@
+set(CTEST_RUN_CURRENT_SCRIPT 0)
+message("hello world")
diff --git a/Tests/CTestTestRunScript/test.cmake.in b/Tests/CTestTestRunScript/test.cmake.in
new file mode 100644
index 0000000000..3074a5156e
--- /dev/null
+++ b/Tests/CTestTestRunScript/test.cmake.in
@@ -0,0 +1,2 @@
+set(CTEST_RUN_CURRENT_SCRIPT 0)
+CTEST_RUN_SCRIPT("CTestTestRunScript/hello.cmake" RETURN_VALUE res RETURN_VALUE)
diff --git a/Tests/CTestTestScheduler/CMakeLists.txt b/Tests/CTestTestScheduler/CMakeLists.txt
new file mode 100644
index 0000000000..ccd7b2cbb0
--- /dev/null
+++ b/Tests/CTestTestScheduler/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required (VERSION 2.6)
+project (CTestTestScheduler)
+include (CTest)
+
+add_executable (Sleep sleep.c)
+
+foreach (time RANGE 1 4)
+ add_test (TestSleep${time} Sleep ${time})
+endforeach ()
diff --git a/Tests/CTestTestScheduler/CTestConfig.cmake b/Tests/CTestTestScheduler/CTestConfig.cmake
new file mode 100644
index 0000000000..797387bdd8
--- /dev/null
+++ b/Tests/CTestTestScheduler/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set(CTEST_PROJECT_NAME "CTestTestScheduler")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set(CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestScheduler/sleep.c b/Tests/CTestTestScheduler/sleep.c
new file mode 100644
index 0000000000..9631a68dcb
--- /dev/null
+++ b/Tests/CTestTestScheduler/sleep.c
@@ -0,0 +1,21 @@
+#if defined(_WIN32)
+# include <windows.h>
+#else
+# include <unistd.h>
+#endif
+
+/* sleeps for 4n seconds, where n is the argument to the program */
+int main(int argc, char** argv)
+{
+ int time;
+ if(argc > 1)
+ {
+ time = 4 * atoi(argv[1]);
+ }
+#if defined(_WIN32)
+ Sleep(time * 1000);
+#else
+ sleep(time);
+#endif
+ return 0;
+}
diff --git a/Tests/CTestTestScheduler/test.cmake.in b/Tests/CTestTestScheduler/test.cmake.in
new file mode 100644
index 0000000000..f8c8ab7475
--- /dev/null
+++ b/Tests/CTestTestScheduler/test.cmake.in
@@ -0,0 +1,30 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Scheduler")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestScheduler")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestScheduler")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+# Remove old cost data file if it exists
+if(EXISTS "${CTEST_BINARY_DIRECTORY}/Testing/Temporary/CTestCostData.txt")
+ file(REMOVE "${CTEST_BINARY_DIRECTORY}/Testing/Temporary/CTestCostData.txt")
+endif()
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res PARALLEL_LEVEL 5)
+# Run test set a second time to make sure they run in reverse order
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res PARALLEL_LEVEL 5)
diff --git a/Tests/CTestTestSerialInDepends/CMakeLists.txt b/Tests/CTestTestSerialInDepends/CMakeLists.txt
new file mode 100644
index 0000000000..90e50f9827
--- /dev/null
+++ b/Tests/CTestTestSerialInDepends/CMakeLists.txt
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+project(CTestTestSerialInDepends)
+
+enable_testing()
+
+function(my_add_test NAME COST)
+ add_test(NAME ${NAME}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ COMMAND ${CMAKE_CTEST_COMMAND} -DTEST_NAME=${NAME}
+ -S ${CMAKE_CURRENT_SOURCE_DIR}/test.ctest)
+ set_tests_properties(${NAME} PROPERTIES COST ${COST})
+endfunction()
+
+my_add_test(i_like_company 1000)
+my_add_test(i_like_company_too 0)
+
+my_add_test(i_have_dependencies 1000)
+set_tests_properties(i_have_dependencies PROPERTIES
+ DEPENDS "i_want_to_be_alone")
+
+my_add_test(i_want_to_be_alone 100)
+set_tests_properties(i_want_to_be_alone PROPERTIES RUN_SERIAL 1)
diff --git a/Tests/CTestTestSerialInDepends/test.ctest b/Tests/CTestTestSerialInDepends/test.ctest
new file mode 100644
index 0000000000..28ee09436b
--- /dev/null
+++ b/Tests/CTestTestSerialInDepends/test.ctest
@@ -0,0 +1,16 @@
+set(CTEST_RUN_CURRENT_SCRIPT 0)
+
+set(LOCK_FILE "${TEST_NAME}.lock")
+
+if("${TEST_NAME}" STREQUAL "i_want_to_be_alone")
+ file(GLOB LOCK_FILES *.lock)
+ if(LOCK_FILES)
+ message(FATAL_ERROR "found lock files of other tests even though this test should be running by itself: ${LOCK_FILES}")
+ endif()
+endif()
+
+file(WRITE "${LOCK_FILE}")
+ctest_sleep(3)
+file(REMOVE "${LOCK_FILE}")
+
+return()
diff --git a/Tests/CTestTestSerialOrder/CMakeLists.txt b/Tests/CTestTestSerialOrder/CMakeLists.txt
new file mode 100644
index 0000000000..69c11fcde1
--- /dev/null
+++ b/Tests/CTestTestSerialOrder/CMakeLists.txt
@@ -0,0 +1,40 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+project(CTestTestSerialOrder)
+
+set(TEST_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/test_output.txt")
+
+enable_testing()
+
+function(add_serial_order_test TEST_NAME)
+ add_test(NAME ${TEST_NAME}
+ COMMAND ${CMAKE_COMMAND}
+ "-DTEST_OUTPUT_FILE=${TEST_OUTPUT_FILE}"
+ "-DTEST_NAME=${TEST_NAME}"
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/test.cmake"
+ )
+
+ if(ARGC GREATER 1)
+ set_tests_properties(${TEST_NAME} PROPERTIES ${ARGN})
+ endif()
+endfunction()
+
+add_serial_order_test(initialization COST 1000)
+add_serial_order_test(test1)
+add_serial_order_test(test2)
+add_serial_order_test(test3)
+add_serial_order_test(test4 DEPENDS test5)
+
+add_serial_order_test(test5)
+set_tests_properties(test5 PROPERTIES DEPENDS "test6;test7b;test7a")
+
+add_serial_order_test(test6 COST -2)
+add_serial_order_test(test7a COST -1)
+add_serial_order_test(test7b COST -1)
+add_serial_order_test(test8 COST 10)
+add_serial_order_test(test9 COST 20)
+add_serial_order_test(test10 COST 0)
+add_serial_order_test(test11)
+add_serial_order_test(test12 COST 0)
+
+add_serial_order_test(verification COST -1000)
diff --git a/Tests/CTestTestSerialOrder/test.cmake b/Tests/CTestTestSerialOrder/test.cmake
new file mode 100644
index 0000000000..8479cae953
--- /dev/null
+++ b/Tests/CTestTestSerialOrder/test.cmake
@@ -0,0 +1,31 @@
+list(APPEND EXPECTED_OUTPUT
+ initialization
+ test9
+ test8
+ test1
+ test2
+ test3
+ test6
+ test7a
+ test7b
+ test5
+ test4
+ test10
+ test11
+ test12
+)
+
+
+if("${TEST_NAME}" STREQUAL "initialization")
+ file(WRITE ${TEST_OUTPUT_FILE} "${TEST_NAME}")
+
+elseif("${TEST_NAME}" STREQUAL "verification")
+ file(READ ${TEST_OUTPUT_FILE} ACTUAL_OUTPUT)
+ if(NOT "${ACTUAL_OUTPUT}" STREQUAL "${EXPECTED_OUTPUT}")
+ message(FATAL_ERROR "Actual test order [${ACTUAL_OUTPUT}] differs from expected test order [${EXPECTED_OUTPUT}]")
+ endif()
+
+else()
+ file(APPEND ${TEST_OUTPUT_FILE} ";${TEST_NAME}")
+
+endif()
diff --git a/Tests/CTestTestSkipReturnCode/CMakeLists.txt b/Tests/CTestTestSkipReturnCode/CMakeLists.txt
new file mode 100644
index 0000000000..26c4178fd9
--- /dev/null
+++ b/Tests/CTestTestSkipReturnCode/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(CTestTestSkipReturnCode)
+include(CTest)
+
+add_test (NAME CMakeV1 COMMAND ${CMAKE_COMMAND} "--version")
+add_test (NAME CMakeV2 COMMAND ${CMAKE_COMMAND} "--version")
+
+set_tests_properties(CMakeV2 PROPERTIES SKIP_RETURN_CODE 0)
diff --git a/Tests/CTestTestSkipReturnCode/CTestConfig.cmake b/Tests/CTestTestSkipReturnCode/CTestConfig.cmake
new file mode 100644
index 0000000000..da0c76b738
--- /dev/null
+++ b/Tests/CTestTestSkipReturnCode/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set (CTEST_PROJECT_NAME "CTestTestSkipReturnCode")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestSkipReturnCode/test.cmake.in b/Tests/CTestTestSkipReturnCode/test.cmake.in
new file mode 100644
index 0000000000..112b0cd0fd
--- /dev/null
+++ b/Tests/CTestTestSkipReturnCode/test.cmake.in
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-SkipReturnCode")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestSkipReturnCode")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestSkipReturnCode")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestStopTime/CMakeLists.txt b/Tests/CTestTestStopTime/CMakeLists.txt
new file mode 100644
index 0000000000..bd8bebdda9
--- /dev/null
+++ b/Tests/CTestTestStopTime/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestStopTime)
+include(CTest)
+
+add_executable (Sleep sleep.c)
+
+add_test (TestSleep Sleep 30)
+add_test (ShouldNotRun Sleep 30)
+
+set_tests_properties(ShouldNotRun PROPERTIES DEPENDS TestSleep)
+set_tests_properties(ShouldNotRun PROPERTIES WILL_FAIL ON)
diff --git a/Tests/CTestTestStopTime/CTestConfig.cmake b/Tests/CTestTestStopTime/CTestConfig.cmake
new file mode 100644
index 0000000000..412283e69c
--- /dev/null
+++ b/Tests/CTestTestStopTime/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set (CTEST_PROJECT_NAME "CTestTestStopTime")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestStopTime/GetDate.cmake b/Tests/CTestTestStopTime/GetDate.cmake
new file mode 100644
index 0000000000..edc65192c8
--- /dev/null
+++ b/Tests/CTestTestStopTime/GetDate.cmake
@@ -0,0 +1,132 @@
+cmake_minimum_required(VERSION 2.8.11)
+
+macro(GET_DATE)
+ #
+ # All macro arguments are optional.
+ # If there's an ARGV0, use it as GD_PREFIX. Default = 'GD_'
+ # If there's an ARGV1, use it as ${GD_PREFIX}VERBOSE. Default = '0'
+ #
+ # If the date can be retrieved and parsed successfully, this macro
+ # will set the following CMake variables:
+ #
+ # GD_PREFIX
+ # ${GD_PREFIX}PREFIX (if '${GD_PREFIX}' is not 'GD_'...!)
+ # ${GD_PREFIX}VERBOSE
+ #
+ # ${GD_PREFIX}OV
+ #
+ # ${GD_PREFIX}REGEX
+ # ${GD_PREFIX}YEAR
+ # ${GD_PREFIX}MONTH
+ # ${GD_PREFIX}DAY
+ # ${GD_PREFIX}HOUR
+ # ${GD_PREFIX}MINUTE
+ # ${GD_PREFIX}SECOND
+ #
+ # Caller can then use these variables to construct names based on
+ # date and time stamps...
+ #
+
+ # If there's an ARGV0, use it as GD_PREFIX:
+ #
+ set(GD_PREFIX "GD_")
+ if(NOT "${ARGV0}" STREQUAL "")
+ set(GD_PREFIX "${ARGV0}")
+ endif()
+ if(NOT "${GD_PREFIX}" STREQUAL "GD_")
+ set(${GD_PREFIX}PREFIX "${GD_PREFIX}")
+ endif()
+
+ # If there's an ARGV1, use it as ${GD_PREFIX}VERBOSE:
+ #
+ set(${GD_PREFIX}VERBOSE "0")
+ if(NOT "${ARGV1}" STREQUAL "")
+ set(${GD_PREFIX}VERBOSE "${ARGV1}")
+ endif()
+
+ # Retrieve the current date and time in the format:
+ #
+ # 01/12/2006 08:55:12
+ # mm/dd/YYYY HH:MM:SS
+ #
+ string(TIMESTAMP "${GD_PREFIX}OV" "%m/%d/%Y %H:%M:%S")
+
+ if(${GD_PREFIX}VERBOSE)
+ message(STATUS "")
+ message(STATUS "<GET_DATE>")
+ message(STATUS "")
+ message(STATUS "GD_PREFIX='${GD_PREFIX}'")
+ if(NOT "${GD_PREFIX}" STREQUAL "GD_")
+ message(STATUS "${GD_PREFIX}PREFIX='${${GD_PREFIX}PREFIX}'")
+ endif()
+ message(STATUS "${GD_PREFIX}VERBOSE='${${GD_PREFIX}VERBOSE}'")
+ message(STATUS "")
+ message(STATUS "${GD_PREFIX}OV='${${GD_PREFIX}OV}'")
+ message(STATUS "")
+ endif()
+
+ #
+ # Extract six individual components by matching a regex with paren groupings.
+ # Use the replace functionality and \\1 thru \\6 to extract components.
+ #
+ set(${GD_PREFIX}REGEX "([^/]+)/([^/]+)/([^ ]+) +([^:]+):([^:]+):([^\\.]+)")
+
+ string(REGEX REPLACE "${${GD_PREFIX}REGEX}" "\\1" ${GD_PREFIX}MONTH "${${GD_PREFIX}OV}")
+ string(REGEX REPLACE "${${GD_PREFIX}REGEX}" "\\2" ${GD_PREFIX}DAY "${${GD_PREFIX}OV}")
+ string(REGEX REPLACE "${${GD_PREFIX}REGEX}" "\\3" ${GD_PREFIX}YEAR "${${GD_PREFIX}OV}")
+ string(REGEX REPLACE "${${GD_PREFIX}REGEX}" "\\4" ${GD_PREFIX}HOUR "${${GD_PREFIX}OV}")
+ string(REGEX REPLACE "${${GD_PREFIX}REGEX}" "\\5" ${GD_PREFIX}MINUTE "${${GD_PREFIX}OV}")
+ string(REGEX REPLACE "${${GD_PREFIX}REGEX}" "\\6" ${GD_PREFIX}SECOND "${${GD_PREFIX}OV}")
+
+ if(${GD_PREFIX}VERBOSE)
+ message(STATUS "${GD_PREFIX}REGEX='${${GD_PREFIX}REGEX}'")
+ message(STATUS "${GD_PREFIX}YEAR='${${GD_PREFIX}YEAR}'")
+ message(STATUS "${GD_PREFIX}MONTH='${${GD_PREFIX}MONTH}'")
+ message(STATUS "${GD_PREFIX}DAY='${${GD_PREFIX}DAY}'")
+ message(STATUS "${GD_PREFIX}HOUR='${${GD_PREFIX}HOUR}'")
+ message(STATUS "${GD_PREFIX}MINUTE='${${GD_PREFIX}MINUTE}'")
+ message(STATUS "${GD_PREFIX}SECOND='${${GD_PREFIX}SECOND}'")
+ message(STATUS "")
+ message(STATUS "Counters that change...")
+ message(STATUS "")
+ message(STATUS " every second : ${${GD_PREFIX}YEAR}${${GD_PREFIX}MONTH}${${GD_PREFIX}DAY}${${GD_PREFIX}HOUR}${${GD_PREFIX}MINUTE}${${GD_PREFIX}SECOND}")
+ message(STATUS " daily : ${${GD_PREFIX}YEAR}${${GD_PREFIX}MONTH}${${GD_PREFIX}DAY}")
+ message(STATUS " monthly : ${${GD_PREFIX}YEAR}${${GD_PREFIX}MONTH}")
+ message(STATUS " annually : ${${GD_PREFIX}YEAR}")
+ message(STATUS "")
+ endif()
+
+ if(${GD_PREFIX}VERBOSE)
+ message(STATUS "</GET_DATE>")
+ message(STATUS "")
+ endif()
+endmacro()
+
+macro(ADD_SECONDS sec)
+ set(new_min ${${GD_PREFIX}MINUTE})
+ set(new_hr ${${GD_PREFIX}HOUR})
+ math(EXPR new_sec "${sec} + ${${GD_PREFIX}SECOND}")
+ while(${new_sec} GREATER 60 OR ${new_sec} EQUAL 60)
+ math(EXPR new_sec "${new_sec} - 60")
+ math(EXPR new_min "${${GD_PREFIX}MINUTE} + 1")
+ endwhile()
+ while(${new_min} GREATER 60 OR ${new_min} EQUAL 60)
+ math(EXPR new_min "${new_min} - 60")
+ math(EXPR new_hr "${${GD_PREFIX}HOUR} + 1")
+ endwhile()
+ math(EXPR new_hr "${new_hr} % 24")
+
+ # Pad the H, M, S if needed
+ string(LENGTH ${new_sec} sec_len)
+ string(LENGTH ${new_min} min_len)
+ string(LENGTH ${new_hr} hr_len)
+ if(${sec_len} EQUAL 1)
+ set(new_sec "0${new_sec}")
+ endif()
+ if(${min_len} EQUAL 1)
+ set(new_min "0${new_min}")
+ endif()
+ if(${hr_len} EQUAL 1)
+ set(new_hr "0${new_hr}")
+ endif()
+endmacro()
diff --git a/Tests/CTestTestStopTime/sleep.c b/Tests/CTestTestStopTime/sleep.c
new file mode 100644
index 0000000000..b5896474b1
--- /dev/null
+++ b/Tests/CTestTestStopTime/sleep.c
@@ -0,0 +1,21 @@
+#if defined(_WIN32)
+# include <windows.h>
+#else
+# include <unistd.h>
+#endif
+
+/* sleeps for n seconds, where n is the argument to the program */
+int main(int argc, char** argv)
+{
+ int time;
+ if(argc > 1)
+ {
+ time = atoi(argv[1]);
+ }
+#if defined(_WIN32)
+ Sleep(time * 1000);
+#else
+ sleep(time);
+#endif
+ return 0;
+}
diff --git a/Tests/CTestTestStopTime/test.cmake.in b/Tests/CTestTestStopTime/test.cmake.in
new file mode 100644
index 0000000000..d3a9a4a920
--- /dev/null
+++ b/Tests/CTestTestStopTime/test.cmake.in
@@ -0,0 +1,33 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-StopTime")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestStopTime")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestStopTime")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+include("${CTEST_BINARY_DIRECTORY}/GetDate.cmake")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+
+GET_DATE()
+message("curr time: ${${GD_PREFIX}HOUR}:${${GD_PREFIX}MINUTE}:${${GD_PREFIX}SECOND}")
+ADD_SECONDS(15)
+message("stop time: ${new_hr}:${new_min}:${new_sec}")
+
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res STOP_TIME "${new_hr}:${new_min}:${new_sec}")
+
+#CTEST_SUBMIT()
diff --git a/Tests/CTestTestSubdir/CMakeLists.txt b/Tests/CTestTestSubdir/CMakeLists.txt
new file mode 100644
index 0000000000..b7cc7e2f15
--- /dev/null
+++ b/Tests/CTestTestSubdir/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestSubdir)
+include(CTest)
+
+add_subdirectory(subdir)
+subdirs(subdir2)
+subdirs("${CTestTestSubdir_SOURCE_DIR}/subdir3")
diff --git a/Tests/CTestTestSubdir/CTestConfig.cmake b/Tests/CTestTestSubdir/CTestConfig.cmake
new file mode 100644
index 0000000000..47ebb925c5
--- /dev/null
+++ b/Tests/CTestTestSubdir/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set(CTEST_PROJECT_NAME "CTestTestSubdir")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set(CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestSubdir/subdir/CMakeLists.txt b/Tests/CTestTestSubdir/subdir/CMakeLists.txt
new file mode 100644
index 0000000000..ee555354e7
--- /dev/null
+++ b/Tests/CTestTestSubdir/subdir/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable (main main.c)
+add_test (TestMain1 main)
diff --git a/Tests/CTestTestSubdir/subdir/main.c b/Tests/CTestTestSubdir/subdir/main.c
new file mode 100644
index 0000000000..8488f4e58f
--- /dev/null
+++ b/Tests/CTestTestSubdir/subdir/main.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/CTestTestSubdir/subdir2/CMakeLists.txt b/Tests/CTestTestSubdir/subdir2/CMakeLists.txt
new file mode 100644
index 0000000000..a8d0a779b0
--- /dev/null
+++ b/Tests/CTestTestSubdir/subdir2/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable (main2 main.c)
+add_test (TestMain2 main2)
diff --git a/Tests/CTestTestSubdir/subdir2/main.c b/Tests/CTestTestSubdir/subdir2/main.c
new file mode 100644
index 0000000000..8488f4e58f
--- /dev/null
+++ b/Tests/CTestTestSubdir/subdir2/main.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/CTestTestSubdir/subdir3/CMakeLists.txt b/Tests/CTestTestSubdir/subdir3/CMakeLists.txt
new file mode 100644
index 0000000000..fbc41d5e67
--- /dev/null
+++ b/Tests/CTestTestSubdir/subdir3/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable (main3 main.c)
+add_test (TestMain3 main3)
diff --git a/Tests/CTestTestSubdir/subdir3/main.c b/Tests/CTestTestSubdir/subdir3/main.c
new file mode 100644
index 0000000000..8488f4e58f
--- /dev/null
+++ b/Tests/CTestTestSubdir/subdir3/main.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/CTestTestSubdir/test.cmake.in b/Tests/CTestTestSubdir/test.cmake.in
new file mode 100644
index 0000000000..8b3957b4e1
--- /dev/null
+++ b/Tests/CTestTestSubdir/test.cmake.in
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Subdir")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestSubdir")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestSubdir")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestTestTimeout/CMakeLists.txt b/Tests/CTestTestTimeout/CMakeLists.txt
new file mode 100644
index 0000000000..c6cbc47094
--- /dev/null
+++ b/Tests/CTestTestTimeout/CMakeLists.txt
@@ -0,0 +1,21 @@
+cmake_minimum_required (VERSION 2.8)
+project(CTestTestTimeout)
+include(CTest)
+
+if(NOT TIMEOUT)
+ # Give the process time to load and start running.
+ set(TIMEOUT 4)
+endif()
+
+add_definitions(-DTIMEOUT=${TIMEOUT})
+add_executable (Sleep sleep.c)
+
+add_test(NAME TestTimeout
+ COMMAND ${CMAKE_COMMAND} -D Sleep=$<TARGET_FILE:Sleep>
+ -D Log=${CMAKE_CURRENT_BINARY_DIR}/timeout.log
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/timeout.cmake
+ )
+set_tests_properties(TestTimeout PROPERTIES TIMEOUT ${TIMEOUT})
+
+add_test(NAME TestSleep COMMAND Sleep)
+set_tests_properties(TestSleep PROPERTIES DEPENDS TestTimeout)
diff --git a/Tests/CTestTestTimeout/CTestConfig.cmake b/Tests/CTestTestTimeout/CTestConfig.cmake
new file mode 100644
index 0000000000..13114f1cab
--- /dev/null
+++ b/Tests/CTestTestTimeout/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set(CTEST_PROJECT_NAME "CTestTestTimeout")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set(CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestTimeout/sleep.c b/Tests/CTestTestTimeout/sleep.c
new file mode 100644
index 0000000000..33ce307720
--- /dev/null
+++ b/Tests/CTestTestTimeout/sleep.c
@@ -0,0 +1,21 @@
+#if defined(_WIN32)
+# include <windows.h>
+#else
+# include <unistd.h>
+#endif
+
+#include <stdio.h>
+
+int main(void)
+{
+ fprintf(stderr, "before sleep\n");
+ fflush(stderr); /* should not be needed, but just in case */
+#if defined(_WIN32)
+ Sleep((TIMEOUT+4)*1000);
+#else
+ sleep((TIMEOUT+4));
+#endif
+ fprintf(stderr, "after sleep\n");
+ fflush(stderr); /* should not be needed, but just in case */
+ return 0;
+}
diff --git a/Tests/CTestTestTimeout/test.cmake.in b/Tests/CTestTestTimeout/test.cmake.in
new file mode 100644
index 0000000000..4b5157ef09
--- /dev/null
+++ b/Tests/CTestTestTimeout/test.cmake.in
@@ -0,0 +1,40 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Timeout")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestTimeout")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestTimeout")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
+
+file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "
+TIMEOUT:STRING=@CTestTestTimeout_TIME@
+")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+
+set(log ${CTEST_BINARY_DIRECTORY}/timeout.log)
+if(EXISTS "${log}")
+ # Verify that the timeout test did not finish sleeping.
+ file(STRINGS "${log}" after_sleep REGEX "after sleep")
+ if(after_sleep)
+ message(FATAL_ERROR "Log indicates timeout did not kill child.")
+ else()
+ message(STATUS "Log indicates timeout correctly killed child.")
+ endif()
+else()
+ message(FATAL_ERROR "Log does not exist:\n ${log}")
+endif()
diff --git a/Tests/CTestTestTimeout/timeout.cmake b/Tests/CTestTestTimeout/timeout.cmake
new file mode 100644
index 0000000000..0989b65df0
--- /dev/null
+++ b/Tests/CTestTestTimeout/timeout.cmake
@@ -0,0 +1,6 @@
+# Remove the log file.
+file(REMOVE ${Log})
+
+# Run a child that sleeps longer than the timout of this test.
+# Log its output so check.cmake can verify it dies.
+execute_process(COMMAND ${Sleep} ERROR_FILE ${Log})
diff --git a/Tests/CTestTestUpload/CMakeLists.txt b/Tests/CTestTestUpload/CMakeLists.txt
new file mode 100644
index 0000000000..90d811cd94
--- /dev/null
+++ b/Tests/CTestTestUpload/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required (VERSION 2.6)
+project(CTestTestUpload)
+
+add_executable (Sleep sleep.c)
diff --git a/Tests/CTestTestUpload/CTestConfig.cmake b/Tests/CTestTestUpload/CTestConfig.cmake
new file mode 100644
index 0000000000..a54708838e
--- /dev/null
+++ b/Tests/CTestTestUpload/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set (CTEST_PROJECT_NAME "CTestTestUpload")
+set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set (CTEST_DART_SERVER_VERSION "2")
+set (CTEST_DROP_METHOD "http")
+set (CTEST_DROP_SITE "open.cdash.org")
+set (CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set (CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestUpload/sleep.c b/Tests/CTestTestUpload/sleep.c
new file mode 100644
index 0000000000..b5896474b1
--- /dev/null
+++ b/Tests/CTestTestUpload/sleep.c
@@ -0,0 +1,21 @@
+#if defined(_WIN32)
+# include <windows.h>
+#else
+# include <unistd.h>
+#endif
+
+/* sleeps for n seconds, where n is the argument to the program */
+int main(int argc, char** argv)
+{
+ int time;
+ if(argc > 1)
+ {
+ time = atoi(argv[1]);
+ }
+#if defined(_WIN32)
+ Sleep(time * 1000);
+#else
+ sleep(time);
+#endif
+ return 0;
+}
diff --git a/Tests/CTestTestUpload/test.cmake.in b/Tests/CTestTestUpload/test.cmake.in
new file mode 100644
index 0000000000..701439d371
--- /dev/null
+++ b/Tests/CTestTestUpload/test.cmake.in
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Upload")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestUpload")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestUpload")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_UPLOAD(FILES "${CTEST_SOURCE_DIRECTORY}/sleep.c" "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
+CTEST_SUBMIT()
diff --git a/Tests/CTestTestZeroTimeout/CMakeLists.txt b/Tests/CTestTestZeroTimeout/CMakeLists.txt
new file mode 100644
index 0000000000..4d2b79dc2f
--- /dev/null
+++ b/Tests/CTestTestZeroTimeout/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required (VERSION 2.6)
+project (CTestTestZeroTimeout)
+include (CTest)
+
+add_executable (Sleep sleep.c)
+
+add_test (TestExplicitZeroTimeout Sleep)
+set_tests_properties(TestExplicitZeroTimeout PROPERTIES TIMEOUT 0)
diff --git a/Tests/CTestTestZeroTimeout/CTestConfig.cmake b/Tests/CTestTestZeroTimeout/CTestConfig.cmake
new file mode 100644
index 0000000000..60948647f5
--- /dev/null
+++ b/Tests/CTestTestZeroTimeout/CTestConfig.cmake
@@ -0,0 +1,7 @@
+set(CTEST_PROJECT_NAME "CTestTestZeroTimeout")
+set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
+set(CTEST_DART_SERVER_VERSION "2")
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "open.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Tests/CTestTestZeroTimeout/sleep.c b/Tests/CTestTestZeroTimeout/sleep.c
new file mode 100644
index 0000000000..d40d59d978
--- /dev/null
+++ b/Tests/CTestTestZeroTimeout/sleep.c
@@ -0,0 +1,16 @@
+#if defined(_WIN32)
+# include <windows.h>
+#else
+# include <unistd.h>
+#endif
+
+/* sleeps for 5 seconds */
+int main(int argc, char** argv)
+{
+#if defined(_WIN32)
+ Sleep(5000);
+#else
+ sleep(5);
+#endif
+ return 0;
+}
diff --git a/Tests/CTestTestZeroTimeout/test.cmake.in b/Tests/CTestTestZeroTimeout/test.cmake.in
new file mode 100644
index 0000000000..b829fefe27
--- /dev/null
+++ b/Tests/CTestTestZeroTimeout/test.cmake.in
@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 2.4)
+
+# Settings:
+set(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest")
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-ZeroTimeout")
+
+set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestZeroTimeout")
+set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestZeroTimeout")
+set(CTEST_CVS_COMMAND "@CVSCOMMAND@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM "@CMAKE_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")
+set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+set(CTEST_TEST_TIMEOUT 2)
+
+CTEST_START(Experimental)
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
diff --git a/Tests/CTestUpdateBZR.cmake.in b/Tests/CTestUpdateBZR.cmake.in
new file mode 100644
index 0000000000..8fb1d3483b
--- /dev/null
+++ b/Tests/CTestUpdateBZR.cmake.in
@@ -0,0 +1,153 @@
+# This script drives creation of a bzr repository and checks
+# that CTest can update from it.
+
+#-----------------------------------------------------------------------------
+# Test in a directory next to this script.
+get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(TOP "${TOP}/@CTestUpdateBZR_DIR@")
+
+# Include code common to all update tests.
+include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
+
+#-----------------------------------------------------------------------------
+# Report bzr tools in use.
+message("Using BZR tools:")
+set(BZR "@BZR_EXECUTABLE@")
+message(" bzr = ${BZR}")
+
+#-----------------------------------------------------------------------------
+# Initialize the testing directory.
+message("Creating test directory...")
+init_testing()
+
+#-----------------------------------------------------------------------------
+# Create the repository.
+message("Creating repository...")
+file(MAKE_DIRECTORY ${TOP}/repo.bzr)
+run_child(
+ WORKING_DIRECTORY ${TOP}/repo.bzr
+ COMMAND ${BZR} init
+ )
+set(REPO file://${TOP}/repo.bzr)
+
+#-----------------------------------------------------------------------------
+# Import initial content into the repository.
+message("Importing content...")
+create_content(import)
+
+# Import the content into the repository.
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${BZR} init
+ )
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${BZR} whoami --branch "Test Author <testauthor@cmake.org>"
+ )
+
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${BZR} add .
+ )
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${BZR} commit -m "Initial content"
+ )
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${BZR} push --create-prefix "${REPO}"
+ )
+
+#-----------------------------------------------------------------------------
+# Create a working tree.
+message("Checking out revision 1...")
+run_child(
+ WORKING_DIRECTORY ${TOP}
+ COMMAND ${BZR} branch "${REPO}" user-source
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${BZR} whoami --branch "Test Author <testauthor@cmake.org>"
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content...")
+update_content(user-source files_added files_removed dirs_added)
+if(dirs_added)
+ run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${BZR} add ${dirs_added}
+ )
+endif()
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${BZR} add ${files_added}
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${BZR} rm ${files_removed}
+ )
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 2...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${BZR} commit -m "Changed content"
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${BZR} push "${REPO}"
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content again...")
+change_content(user-source)
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 3...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${BZR} commit -m "Changed content again"
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${BZR} push "${REPO}"
+ )
+
+#-----------------------------------------------------------------------------
+# Go back to before the changes so we can test updating.
+message("Backing up to revision 1...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${BZR} pull --overwrite -r1
+ )
+
+# Create a modified file.
+modify_content(user-source)
+
+#-----------------------------------------------------------------------------
+# Test updating the user work directory with the command-line interface.
+message("Running CTest Dashboard Command Line...")
+
+# Create the user build tree.
+create_build_tree(user-source user-binary)
+file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
+ "# BZR command configuration
+UpdateCommand: ${BZR}
+")
+
+# Run the dashboard command line interface.
+run_dashboard_command_line(user-binary)
+
+#-----------------------------------------------------------------------------
+# Test initial checkout and update with a dashboard script.
+message("Running CTest Dashboard Script...")
+
+create_dashboard_script(dash-binary
+ "# bzr command configuration
+set(CTEST_BZR_COMMAND \"${BZR}\")
+set(CTEST_CHECKOUT_COMMAND
+ \"\\\"\${CTEST_BZR_COMMAND}\\\" branch -r1 \\\"${REPO}\\\" dash-source\")
+")
+
+# Run the dashboard script with CTest.
+run_dashboard_script(dash-binary)
diff --git a/Tests/CTestUpdateCVS.cmake.in b/Tests/CTestUpdateCVS.cmake.in
new file mode 100644
index 0000000000..1699c3f1f1
--- /dev/null
+++ b/Tests/CTestUpdateCVS.cmake.in
@@ -0,0 +1,172 @@
+# This script drives creation of a CVS repository and checks
+# that CTest can update from it.
+
+#-----------------------------------------------------------------------------
+# Test in a directory next to this script.
+get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(TOP "${TOP}/@CTestUpdateCVS_DIR@")
+set(UPDATE_NOT_GLOBAL 1)
+set(UPDATE_MAYBE Updated{CTestConfig.cmake})
+
+# Include code common to all update tests.
+include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
+
+#-----------------------------------------------------------------------------
+# Report CVS tools in use.
+message("Using CVS tools:")
+set(CVS "@CVS_EXECUTABLE@")
+message(" cvs = ${CVS}")
+
+set(REPO ${TOP}/repo)
+
+# The MSYS cvs tool interprets "c:/" as a "machine:" name for SSH.
+# Detect the MSYS cvs and convert the repo path to an MSYS path.
+if(WIN32)
+ if(EXISTS "${CVS}")
+ file(STRINGS "${CVS}" cvs_is_msys LIMIT_COUNT 1 REGEX "[Mm][Ss][Yy][Ss]")
+ if(cvs_is_msys)
+ message(" '${CVS}' is from MSYS (contains '${cvs_is_msys}')")
+ string(REGEX REPLACE "^([A-Za-z]):" "/\\1" REPO "${REPO}")
+ endif()
+ endif()
+endif()
+
+set(CVSCMD ${CVS} -d${REPO})
+
+# CVSNT requires an extra option to 'cvs init'.
+set(CVS_INIT_OPT)
+execute_process(
+ COMMAND ${CVS} --version
+ RESULT_VARIABLE RESULT
+ OUTPUT_VARIABLE OUTPUT
+ ERROR_VARIABLE OUTPUT
+ )
+if("${RESULT}" STREQUAL "0" AND "${OUTPUT}" MATCHES "\\(CVSNT\\)")
+ set(CVS_INIT_OPT -n)
+ message(" cvs init needs -n")
+endif()
+
+#-----------------------------------------------------------------------------
+# Initialize the testing directory.
+message("Creating test directory...")
+init_testing()
+
+#-----------------------------------------------------------------------------
+# Create the repository.
+message("Creating repository...")
+file(MAKE_DIRECTORY ${TOP}/repo)
+run_child(
+ COMMAND ${CVSCMD} init ${CVS_INIT_OPT}
+ )
+
+#-----------------------------------------------------------------------------
+# Import initial content into the repository.
+message("Importing content...")
+create_content(import)
+
+# Import the content into the repository.
+run_child(
+ WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${CVSCMD} import -m "Initial content" Project vendor-tag release-tag
+ )
+
+#-----------------------------------------------------------------------------
+# Create a working tree.
+message("Checking out revision 1...")
+run_child(
+ WORKING_DIRECTORY ${TOP}
+ COMMAND ${CVSCMD} co -d user-source Project
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${CVSCMD} tag Revision1
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content...")
+update_content(user-source files_added files_removed dirs_added)
+if(dirs_added)
+ run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${CVSCMD} add ${dirs_added}
+ )
+endif()
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${CVSCMD} add ${files_added}
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${CVSCMD} rm ${files_removed}
+ )
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 2...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${CVSCMD} commit -m "Changed content"
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content again...")
+change_content(user-source)
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 3...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${CVSCMD} commit -m "Changed content again"
+ )
+
+#-----------------------------------------------------------------------------
+# Go back to before the changes so we can test updating.
+message("Backing up to revision 1...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${CVSCMD} up -rRevision1
+ )
+
+# Delay 1 second so the modification produces a newer time stamp.
+find_program(SLEEP sleep)
+if(SLEEP)
+ message("Delaying...")
+ execute_process(COMMAND ${SLEEP} 1)
+endif()
+
+# Create a modified file.
+message("Modifying locally...")
+modify_content(user-source)
+
+#-----------------------------------------------------------------------------
+# Test updating the user work directory with the command-line interface.
+message("Running CTest Dashboard Command Line...")
+
+# Create the user build tree.
+create_build_tree(user-source user-binary)
+file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
+ "# CVS command configuration
+CVSCommand: ${CVS}
+CVSUpdateOptions: -dAP
+")
+
+# Run the dashboard command line interface.
+run_dashboard_command_line(user-binary)
+
+#-----------------------------------------------------------------------------
+# Test initial checkout and update with a dashboard script.
+message("Running CTest Dashboard Script...")
+
+create_dashboard_script(dash-binary
+ "# CVS command configuration
+set(CTEST_CVS_COMMAND \"${CVS}\")
+set(CTEST_CVS_UPDATE_OPTIONS -dAP)
+set(CTEST_CHECKOUT_COMMAND
+ \"\\\"\${CTEST_CVS_COMMAND}\\\" -d \\\"${REPO}\\\" co -rRevision1 -d dash-source Project\")
+")
+
+# Run the dashboard script with CTest.
+run_dashboard_script(dash-binary)
diff --git a/Tests/CTestUpdateCommon.cmake b/Tests/CTestUpdateCommon.cmake
new file mode 100644
index 0000000000..97153f0f94
--- /dev/null
+++ b/Tests/CTestUpdateCommon.cmake
@@ -0,0 +1,279 @@
+#-----------------------------------------------------------------------------
+# Function to run a child process and report output only on error.
+function(run_child)
+ execute_process(${ARGN}
+ RESULT_VARIABLE FAILED
+ OUTPUT_VARIABLE OUTPUT
+ ERROR_VARIABLE OUTPUT
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_STRIP_TRAILING_WHITESPACE
+ )
+ if(FAILED)
+ string(REPLACE "\n" "\n " OUTPUT "${OUTPUT}")
+ message(FATAL_ERROR "Child failed (${FAILED}), output is\n ${OUTPUT}\n"
+ "Command = [${ARGN}]\n")
+ endif()
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to find the Update.xml file and check for expected entries.
+function(check_updates build)
+ # Find the Update.xml file for the given build tree
+ set(PATTERN ${TOP}/${build}/Testing/*/Update.xml)
+ file(GLOB UPDATE_XML_FILE RELATIVE ${TOP} ${PATTERN})
+ string(REGEX REPLACE "//Update.xml$" "/Update.xml"
+ UPDATE_XML_FILE "${UPDATE_XML_FILE}"
+ )
+ if(NOT UPDATE_XML_FILE)
+ message(FATAL_ERROR "Cannot find Update.xml with pattern\n ${PATTERN}")
+ endif()
+ message(" found ${UPDATE_XML_FILE}")
+
+ set(max_update_xml_size 16384)
+
+ # Read entries from the Update.xml file
+ set(types "Updated|Modified|Conflicting")
+ file(STRINGS ${TOP}/${UPDATE_XML_FILE} UPDATE_XML_ENTRIES
+ REGEX "<(${types}|FullName)>"
+ LIMIT_INPUT ${max_update_xml_size}
+ )
+
+ string(REGEX REPLACE
+ "[ \t]*<(${types})>[ \t]*;[ \t]*<FullName>([^<]*)</FullName>"
+ "\\1{\\2}" UPDATE_XML_ENTRIES "${UPDATE_XML_ENTRIES}")
+
+ # If specified, remove the given prefix from the files in Update.xml.
+ # Some VCS systems, like Perforce, return absolute locations
+ if(DEFINED REPOSITORY_FILE_PREFIX)
+ string(REPLACE
+ "${REPOSITORY_FILE_PREFIX}" ""
+ UPDATE_XML_ENTRIES "${UPDATE_XML_ENTRIES}")
+ endif()
+
+ # Compare expected and actual entries
+ set(EXTRA "${UPDATE_XML_ENTRIES}")
+ list(REMOVE_ITEM EXTRA ${ARGN} ${UPDATE_EXTRA} ${UPDATE_MAYBE})
+ set(MISSING "${ARGN}" ${UPDATE_EXTRA})
+ if(NOT "" STREQUAL "${UPDATE_XML_ENTRIES}")
+ list(REMOVE_ITEM MISSING ${UPDATE_XML_ENTRIES})
+ endif()
+
+ if(NOT UPDATE_NOT_GLOBAL)
+ set(rev_elements Revision PriorRevision ${UPDATE_GLOBAL_ELEMENTS})
+ string(REPLACE ";" "|" rev_regex "${rev_elements}")
+ set(rev_regex "^\t<(${rev_regex})>[^<\n]+</(${rev_regex})>$")
+ file(STRINGS ${TOP}/${UPDATE_XML_FILE} UPDATE_XML_REVISIONS
+ REGEX "${rev_regex}"
+ LIMIT_INPUT ${max_update_xml_size}
+ )
+ foreach(r IN LISTS UPDATE_XML_REVISIONS)
+ string(REGEX REPLACE "${rev_regex}" "\\1" element "${r}")
+ set(element_${element} 1)
+ endforeach()
+ foreach(element ${rev_elements})
+ if(NOT element_${element})
+ list(APPEND MISSING "global <${element}> element")
+ endif()
+ endforeach()
+ endif()
+
+ # Report the result
+ set(MSG "")
+ if(MISSING)
+ # List the missing entries
+ set(MSG "${MSG}Update.xml is missing expected entries:\n")
+ foreach(f ${MISSING})
+ set(MSG "${MSG} ${f}\n")
+ endforeach()
+ else()
+ # Success
+ message(" no entries missing from Update.xml")
+ endif()
+
+ # Report the result
+ if(EXTRA)
+ # List the extra entries
+ set(MSG "${MSG}Update.xml has extra unexpected entries:\n")
+ foreach(f ${EXTRA})
+ set(MSG "${MSG} ${f}\n")
+ endforeach()
+ else()
+ # Success
+ message(" no extra entries in Update.xml")
+ endif()
+
+ if(MSG)
+ # Provide the log file
+ file(GLOB UPDATE_LOG_FILE
+ ${TOP}/${build}/Testing/Temporary/LastUpdate*.log)
+ if(UPDATE_LOG_FILE)
+ file(READ ${UPDATE_LOG_FILE} UPDATE_LOG LIMIT ${max_update_xml_size})
+ string(REPLACE "\n" "\n " UPDATE_LOG "${UPDATE_LOG}")
+ set(MSG "${MSG}Update log:\n ${UPDATE_LOG}")
+ else()
+ set(MSG "${MSG}No update log found!")
+ endif()
+
+ # Display the error message
+ message(FATAL_ERROR "${MSG}")
+ endif()
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to create initial content.
+function(create_content dir)
+ file(MAKE_DIRECTORY ${TOP}/${dir})
+
+ # An example CTest project configuration file.
+ file(WRITE ${TOP}/${dir}/CTestConfig.cmake
+ "# CTest Configuration File
+set(CTEST_PROJECT_NAME TestProject)
+set(CTEST_NIGHTLY_START_TIME \"21:00:00 EDT\")
+")
+
+ # Some other files.
+ file(WRITE ${TOP}/${dir}/foo.txt "foo\n")
+ file(WRITE ${TOP}/${dir}/bar.txt "bar\n")
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to update content.
+function(update_content dir added_var removed_var dirs_var)
+ file(APPEND ${TOP}/${dir}/foo.txt "foo line 2\n")
+ file(WRITE ${TOP}/${dir}/zot.txt "zot\n")
+ file(REMOVE ${TOP}/${dir}/bar.txt)
+ file(MAKE_DIRECTORY ${TOP}/${dir}/subdir)
+ file(WRITE ${TOP}/${dir}/subdir/foo.txt "foo\n")
+ file(WRITE ${TOP}/${dir}/subdir/bar.txt "bar\n")
+ set(${dirs_var} subdir PARENT_SCOPE)
+ set(${added_var} zot.txt subdir/foo.txt subdir/bar.txt PARENT_SCOPE)
+ set(${removed_var} bar.txt PARENT_SCOPE)
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to change existing files
+function(change_content dir)
+ file(APPEND ${TOP}/${dir}/foo.txt "foo line 3\n")
+ file(APPEND ${TOP}/${dir}/subdir/foo.txt "foo line 2\n")
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to create local modifications before update
+function(modify_content dir)
+ file(APPEND ${TOP}/${dir}/CTestConfig.cmake "# local modification\n")
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to write CTestConfiguration.ini content.
+function(create_build_tree src_dir bin_dir)
+ file(MAKE_DIRECTORY ${TOP}/${bin_dir})
+ file(WRITE ${TOP}/${bin_dir}/CTestConfiguration.ini
+ "# CTest Configuration File
+SourceDirectory: ${TOP}/${src_dir}
+BuildDirectory: ${TOP}/${bin_dir}
+Site: test.site
+BuildName: user-test
+")
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to write the dashboard test script.
+function(create_dashboard_script bin_dir custom_text)
+ # Write the dashboard script.
+ file(WRITE ${TOP}/${bin_dir}.cmake
+ "# CTest Dashboard Script
+set(CTEST_DASHBOARD_ROOT \"${TOP}\")
+set(CTEST_SITE test.site)
+set(CTEST_BUILD_NAME dash-test)
+set(CTEST_SOURCE_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-source)
+set(CTEST_BINARY_DIRECTORY \${CTEST_DASHBOARD_ROOT}/${bin_dir})
+${custom_text}
+# Start a dashboard and run the update step
+ctest_start(Experimental)
+ctest_update(SOURCE \${CTEST_SOURCE_DIRECTORY})
+")
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to run the dashboard through the command line
+function(run_dashboard_command_line bin_dir)
+ run_child(
+ WORKING_DIRECTORY ${TOP}/${bin_dir}
+ COMMAND ${CMAKE_CTEST_COMMAND} -M Experimental -T Start -T Update
+ )
+
+ # Verify the updates reported by CTest.
+ list(APPEND UPDATE_MAYBE Updated{subdir})
+ set(_modified Modified{CTestConfig.cmake})
+ if(UPDATE_NO_MODIFIED)
+ set(_modified "")
+ endif()
+ check_updates(${bin_dir}
+ Updated{foo.txt}
+ Updated{bar.txt}
+ Updated{zot.txt}
+ Updated{subdir/foo.txt}
+ Updated{subdir/bar.txt}
+ ${_modified}
+ )
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to find the Update.xml file and make sure
+# it only has the Revision in it and no updates
+function(check_no_update bin_dir)
+ set(PATTERN ${TOP}/${bin_dir}/Testing/*/Update.xml)
+ file(GLOB UPDATE_XML_FILE RELATIVE ${TOP} ${PATTERN})
+ string(REGEX REPLACE "//Update.xml$" "/Update.xml"
+ UPDATE_XML_FILE "${UPDATE_XML_FILE}")
+ message(" found ${UPDATE_XML_FILE}")
+ set(rev_regex "Revision|PriorRevision")
+ file(STRINGS ${TOP}/${UPDATE_XML_FILE} UPDATE_XML_REVISIONS
+ REGEX "^\t<(${rev_regex})>[^<\n]+</(${rev_regex})>$"
+ )
+ set(found_revisons FALSE)
+ foreach(r IN LISTS UPDATE_XML_REVISIONS)
+ if("${r}" MATCHES "PriorRevision")
+ message(FATAL_ERROR "Found PriorRevision in no update test")
+ endif()
+ if("${r}" MATCHES "<Revision>")
+ set(found_revisons TRUE)
+ endif()
+ endforeach()
+ if(found_revisons)
+ message(" found <Revision> in no update test")
+ else()
+ message(FATAL_ERROR " missing <Revision> in no update test")
+ endif()
+endfunction()
+
+
+#-----------------------------------------------------------------------------
+# Function to run the dashboard through a script
+function(run_dashboard_script bin_dir)
+ run_child(
+ WORKING_DIRECTORY ${TOP}
+ COMMAND ${CMAKE_CTEST_COMMAND} -S ${bin_dir}.cmake -V
+ )
+
+ # Verify the updates reported by CTest.
+ list(APPEND UPDATE_MAYBE Updated{subdir} Updated{CTestConfig.cmake})
+ if(NO_UPDATE)
+ check_no_update(${bin_dir})
+ else()
+ check_updates(${bin_dir}
+ Updated{foo.txt}
+ Updated{bar.txt}
+ Updated{zot.txt}
+ Updated{subdir/foo.txt}
+ Updated{subdir/bar.txt}
+ )
+ endif()
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Function to initialize the testing directory.
+function(init_testing)
+ file(REMOVE_RECURSE ${TOP})
+ file(MAKE_DIRECTORY ${TOP})
+endfunction()
diff --git a/Tests/CTestUpdateGIT.cmake.in b/Tests/CTestUpdateGIT.cmake.in
new file mode 100644
index 0000000000..41b732b751
--- /dev/null
+++ b/Tests/CTestUpdateGIT.cmake.in
@@ -0,0 +1,336 @@
+# This script drives creation of a git repository and checks
+# that CTest can update from it.
+
+#-----------------------------------------------------------------------------
+# Test in a directory next to this script.
+get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(TOP "${TOP}/@CTestUpdateGIT_DIR@")
+set(UPDATE_EXTRA Updated{module})
+
+# Include code common to all update tests.
+include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
+
+#-----------------------------------------------------------------------------
+# Report git tools in use.
+message("Using GIT tools:")
+set(GIT "@GIT_EXECUTABLE@")
+message(" git = ${GIT}")
+
+set(AUTHOR_CONFIG "[user]
+\tname = Test Author
+\temail = testauthor@cmake.org
+")
+
+#-----------------------------------------------------------------------------
+# Initialize the testing directory.
+message("Creating test directory...")
+init_testing()
+
+if(UNIX)
+ set(src "@CMAKE_CURRENT_SOURCE_DIR@")
+ configure_file(${src}/CTestUpdateGIT.sh.in ${TOP}/git.sh @ONLY)
+ set(GIT ${TOP}/git.sh)
+endif()
+
+#-----------------------------------------------------------------------------
+# Create the repository.
+message("Creating repository...")
+file(MAKE_DIRECTORY ${TOP}/repo.git)
+run_child(
+ WORKING_DIRECTORY ${TOP}/repo.git
+ COMMAND ${GIT} --bare init
+ )
+file(REMOVE_RECURSE ${TOP}/repo.git/hooks)
+set(REPO file://${TOP}/repo.git)
+
+# Create submodule repository.
+message("Creating submodule...")
+file(MAKE_DIRECTORY ${TOP}/module.git)
+run_child(
+ WORKING_DIRECTORY ${TOP}/module.git
+ 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
+ )
+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}")
+run_child(WORKING_DIRECTORY ${TOP}/module
+ COMMAND ${GIT} add .
+ )
+run_child(WORKING_DIRECTORY ${TOP}/module
+ COMMAND ${GIT} commit -m "Initial content"
+ )
+run_child(WORKING_DIRECTORY ${TOP}/module
+ COMMAND ${GIT} push origin master:refs/heads/master
+ )
+
+#-----------------------------------------------------------------------------
+# 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
+ )
+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}")
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${GIT} add .
+ )
+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
+ )
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${GIT} commit -m "Initial content"
+ )
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${GIT} push origin master:refs/heads/master
+ )
+
+#-----------------------------------------------------------------------------
+# Modify the submodule.
+change_content(module)
+run_child(WORKING_DIRECTORY ${TOP}/module
+ COMMAND ${GIT} add -u
+ )
+run_child(WORKING_DIRECTORY ${TOP}/module
+ COMMAND ${GIT} commit -m "Changed content"
+ )
+run_child(WORKING_DIRECTORY ${TOP}/module
+ COMMAND ${GIT} push origin master:refs/heads/master
+ )
+
+#-----------------------------------------------------------------------------
+# Create a working tree.
+message("Checking out revision 1...")
+run_child(
+ WORKING_DIRECTORY ${TOP}
+ COMMAND ${GIT} clone ${REPO} user-source
+ )
+file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
+file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} submodule init
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} submodule update
+ )
+
+# Save the first revision name.
+execute_process(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} rev-parse HEAD
+ OUTPUT_VARIABLE revision1
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+#-----------------------------------------------------------------------------
+# Create an empty commit.
+message("Creating empty commit...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} commit --allow-empty -m "Empty commit"
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content...")
+update_content(user-source files_added files_removed dirs_added)
+if(dirs_added)
+ run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} add -- ${dirs_added}
+ )
+endif()
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} add -- ${files_added}
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} rm -- ${files_removed}
+ )
+run_child(WORKING_DIRECTORY ${TOP}/user-source/module
+ COMMAND ${GIT} checkout master --
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} add -u
+ )
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 2...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} commit -m "Changed content"
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} push origin
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content again...")
+change_content(user-source)
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} add -u
+ )
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 3...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} commit -m "Changed content again"
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} push origin
+ )
+
+#-----------------------------------------------------------------------------
+# Go back to before the changes so we can test updating.
+macro(rewind_source src_dir)
+ message("Backing up to revision 1...")
+ run_child(
+ WORKING_DIRECTORY ${TOP}/${src_dir}
+ COMMAND ${GIT} reset --hard ${revision1}
+ )
+ run_child(
+ WORKING_DIRECTORY ${TOP}/${src_dir}
+ COMMAND ${GIT} submodule update
+ )
+endmacro()
+rewind_source(user-source)
+
+# Make sure pull does not try to rebase (which does not work with
+# modified files) even if ~/.gitconfig sets "branch.master.rebase".
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${GIT} config branch.master.rebase false
+ )
+
+# Create a modified file.
+modify_content(user-source)
+
+#-----------------------------------------------------------------------------
+# Test updating the user work directory with the command-line interface.
+message("Running CTest Dashboard Command Line...")
+
+# Create the user build tree.
+create_build_tree(user-source user-binary)
+file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
+ "# GIT command configuration
+UpdateCommand: ${GIT}
+")
+
+# Run the dashboard command line interface.
+set(UPDATE_NO_MODIFIED 1)
+run_dashboard_command_line(user-binary)
+set(UPDATE_NO_MODIFIED 0)
+
+rewind_source(user-source)
+modify_content(user-source)
+
+message("Running CTest Dashboard Command Line (custom update)...")
+
+# Create the user build tree.
+create_build_tree(user-source user-binary-custom)
+file(APPEND ${TOP}/user-binary-custom/CTestConfiguration.ini
+ "# GIT command configuration
+UpdateCommand: ${GIT}
+GITUpdateCustom: ${GIT};pull;origin;master
+")
+
+# Run the dashboard command line interface.
+run_dashboard_command_line(user-binary-custom)
+
+#-----------------------------------------------------------------------------
+# Test initial checkout and update with a dashboard script.
+message("Running CTest Dashboard Script...")
+
+create_dashboard_script(dash-binary
+ "# git command configuration
+set(CTEST_GIT_COMMAND \"${GIT}\")
+set(CTEST_GIT_UPDATE_OPTIONS)
+execute_process(
+ WORKING_DIRECTORY \"${TOP}\"
+ COMMAND \"${GIT}\" clone \"${REPO}\" dash-source
+ )
+
+# Test .git file.
+file(RENAME \"${TOP}/dash-source/.git\" \"${TOP}/dash-source/repo.git\")
+file(WRITE \"${TOP}/dash-source/.git\" \"gitdir: repo.git\n\")
+
+execute_process(
+ WORKING_DIRECTORY \"${TOP}/dash-source\"
+ COMMAND \"${GIT}\" reset --hard ${revision1}
+ )
+execute_process(
+ WORKING_DIRECTORY \"${TOP}/dash-source\"
+ COMMAND \"${GIT}\" submodule init
+ )
+execute_process(
+ WORKING_DIRECTORY \"${TOP}/dash-source\"
+ COMMAND \"${GIT}\" submodule update
+ )
+")
+
+# Run the dashboard script with CTest.
+run_dashboard_script(dash-binary)
+
+rewind_source(dash-source)
+
+#-----------------------------------------------------------------------------
+# Test custom update with a dashboard script.
+message("Running CTest Dashboard Script (custom update)...")
+
+create_dashboard_script(dash-binary-custom
+ "# git command configuration
+set(CTEST_GIT_COMMAND \"${GIT}\")
+set(CTEST_GIT_UPDATE_OPTIONS)
+set(CTEST_GIT_UPDATE_CUSTOM \${CTEST_GIT_COMMAND} pull origin master)
+")
+
+# Run the dashboard script with CTest.
+run_dashboard_script(dash-binary-custom)
+
+
+rewind_source(dash-source)
+
+#-----------------------------------------------------------------------------
+# Test no update with a dashboard script.
+message("Running CTest Dashboard Script (No update)...")
+
+create_dashboard_script(dash-binary-no-update
+ "# git command configuration
+set(CTEST_GIT_COMMAND \"${GIT}\")
+set(CTEST_UPDATE_VERSION_ONLY TRUE)
+")
+
+# Run the dashboard script with CTest.
+set(NO_UPDATE 1)
+run_dashboard_script(dash-binary-no-update)
diff --git a/Tests/CTestUpdateGIT.sh.in b/Tests/CTestUpdateGIT.sh.in
new file mode 100755
index 0000000000..e7586d6bfa
--- /dev/null
+++ b/Tests/CTestUpdateGIT.sh.in
@@ -0,0 +1,6 @@
+#!/bin/sh
+if test "x$1" = "xpull" -o "x$1" = "xreset"; then
+ "@GIT@" "$@" && sleep 1 && touch foo.txt
+else
+ exec "@GIT@" "$@"
+fi
diff --git a/Tests/CTestUpdateHG.cmake.in b/Tests/CTestUpdateHG.cmake.in
new file mode 100644
index 0000000000..c5440f9544
--- /dev/null
+++ b/Tests/CTestUpdateHG.cmake.in
@@ -0,0 +1,166 @@
+# This script drives creation of a Mercurial repository and checks
+# that CTest can update from it.
+
+#-----------------------------------------------------------------------------
+# Test in a directory next to this script.
+get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(TOP "${TOP}/@CTestUpdateHG_DIR@")
+
+# Include code common to all update tests.
+include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
+
+#-----------------------------------------------------------------------------
+# Report hg tools in use.
+message("Using HG tools:")
+set(HG "@HG_EXECUTABLE@")
+message(" hg = ${HG}")
+
+#-----------------------------------------------------------------------------
+# Initialize the testing directory.
+message("Creating test directory...")
+init_testing()
+
+#-----------------------------------------------------------------------------
+# Create the repository.
+message("Creating repository...")
+file(MAKE_DIRECTORY ${TOP}/repo.hg)
+run_child(
+ WORKING_DIRECTORY ${TOP}/repo.hg
+ COMMAND ${HG} init
+ )
+if(NOT "${TOP}" MATCHES "^/")
+ set(slash /)
+endif()
+set(REPO file://${slash}${TOP}/repo.hg)
+
+#-----------------------------------------------------------------------------
+# Import initial content into the repository.
+message("Importing content...")
+create_content(import)
+
+# Import the content into the repository.
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${HG} init
+ )
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${HG} add .
+ )
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${HG} commit -m "Initial content"
+ -u "Test Author <testauthor@cmake.org>"
+ )
+run_child(WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${HG} push "${REPO}"
+ )
+
+#-----------------------------------------------------------------------------
+# Create a working tree.
+message("Checking out first revision...")
+run_child(
+ WORKING_DIRECTORY ${TOP}
+ COMMAND ${HG} clone ${REPO} user-source
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content...")
+update_content(user-source files_added files_removed dirs_added)
+if(dirs_added)
+ run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} add ${dirs_added}
+ )
+endif()
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} add ${files_added}
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} rm ${files_removed}
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} add
+ )
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 2...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} commit -m "Changed content"
+ -u "Test Author <testauthor@cmake.org>"
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} push
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content again...")
+change_content(user-source)
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} add
+ )
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 3...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} commit -m "Changed content again"
+ -u "Test Author <testauthor@cmake.org>"
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} push
+ )
+
+#-----------------------------------------------------------------------------
+# Go back to before the changes so we can test updating.
+message("Backing up to first revision...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${HG} update -C -r 0
+ )
+
+# Create a modified file.
+modify_content(user-source)
+
+#-----------------------------------------------------------------------------
+# Test updating the user work directory with the command-line interface.
+message("Running CTest Dashboard Command Line...")
+
+# Create the user build tree.
+create_build_tree(user-source user-binary)
+file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
+ "# HG command configuration
+UpdateCommand: ${HG}
+")
+
+# Run the dashboard command line interface.
+run_dashboard_command_line(user-binary)
+
+#-----------------------------------------------------------------------------
+# Test initial checkout and update with a dashboard script.
+message("Running CTest Dashboard Script...")
+
+create_dashboard_script(dash-binary
+ "# hg command configuration
+set(CTEST_HG_COMMAND \"${HG}\")
+set(CTEST_HG_UPDATE_OPTIONS)
+execute_process(
+ WORKING_DIRECTORY \"${TOP}\"
+ COMMAND \"${HG}\" clone \"${REPO}\" dash-source
+ )
+execute_process(
+ WORKING_DIRECTORY \"${TOP}/dash-source\"
+ COMMAND \"${HG}\" update -C -r 0
+ )
+")
+
+# Run the dashboard script with CTest.
+run_dashboard_script(dash-binary)
diff --git a/Tests/CTestUpdateP4.cmake.in b/Tests/CTestUpdateP4.cmake.in
new file mode 100644
index 0000000000..f0420c42f3
--- /dev/null
+++ b/Tests/CTestUpdateP4.cmake.in
@@ -0,0 +1,261 @@
+# This script drives creation of a perforce repository and checks
+# that CTest can update from it.
+
+#-----------------------------------------------------------------------------
+# Test in a directory next to this script.
+get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(P4_TOP "${TOP}")
+set(TOP "${TOP}/@CTestUpdateP4_DIR@")
+
+# Include code common to all update tests.
+set(REPOSITORY_FILE_PREFIX "//ctest/")
+include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
+
+#-----------------------------------------------------------------------------
+# Perforce server options
+set(P4_HOST localhost)
+set(P4_PORT 1888)
+
+#-----------------------------------------------------------------------------
+# Report p4 tools in use and set its defaults
+message("Using P4 tools:")
+set(P4 "@P4_EXECUTABLE@")
+set(P4D "@P4D_EXECUTABLE@")
+message(" p4 = ${P4}")
+message(" p4d = ${P4D}")
+
+set(P4_CLIENT -c ctest_p4)
+set(P4_OPTIONS -H ${P4_HOST} -p ${P4_PORT})
+set(P4CMD ${P4} ${P4_OPTIONS})
+
+#-----------------------------------------------------------------------------
+# Start the Perforce server
+if(UNIX)
+ set(P4_ROOT ${P4_TOP}/perforce)
+
+ message("Starting p4d on '${P4_ROOT}' listening on port ${P4_PORT}...")
+
+ # Stop a previous instance of Perforce running
+ execute_process(
+ WORKING_DIRECTORY ${TOP}
+ COMMAND ${P4CMD} admin stop
+ OUTPUT_QUIET
+ ERROR_QUIET
+ )
+
+ # Make sure we don't have a perforce directory from a previous run
+ file(REMOVE_RECURSE ${P4_ROOT})
+ file(MAKE_DIRECTORY ${P4_ROOT})
+
+ set(P4_SERVER "nohup '${P4D}' -d -r '${P4_ROOT}'")
+ set(P4_SERVER "${P4_SERVER} -L '${P4_ROOT}/p4.log'")
+ set(P4_SERVER "${P4_SERVER} -J '${P4_ROOT}/journal'")
+ set(P4_SERVER "${P4_SERVER} -p ${P4_PORT} >/dev/null 2>&1 &")
+
+ message("Server command line: ${P4_SERVER}")
+
+ execute_process(
+ COMMAND sh -c "
+${P4_SERVER}
+for i in 1 2 3 4 5 6 7 8 9 10; do
+ echo 'Waiting for server to start...'
+ sleep 1
+ if '${P4}' -H ${P4_HOST} -p ${P4_PORT} help >/dev/null 2>&1; then
+ echo 'Server started.'
+ exit
+ fi
+done
+echo 'Gave up waiting for server to start.'
+"
+ )
+endif()
+
+#-----------------------------------------------------------------------------
+# Initialize the testing directory.
+message("Creating test directory...")
+init_testing()
+
+#-----------------------------------------------------------------------------
+# Create the repository.
+message("Creating depot...")
+file(WRITE ${TOP}/depot.spec "Depot: ctest\n")
+file(APPEND ${TOP}/depot.spec "Type: local\n")
+file(APPEND ${TOP}/depot.spec "Map: ctest/...\n")
+run_child(
+ WORKING_DIRECTORY ${TOP}
+ COMMAND ${P4CMD} depot -i
+ INPUT_FILE ${TOP}/depot.spec
+)
+
+#-----------------------------------------------------------------------------
+# Import initial content into the repository.
+message("Importing content...")
+create_content(user-source)
+
+message("Creating client spec...")
+file(WRITE ${TOP}/client.spec "Client: ctest_p4\n")
+file(APPEND ${TOP}/client.spec "Root: ${TOP}/user-source\n")
+file(APPEND ${TOP}/client.spec "View: //ctest/... //ctest_p4/...\n")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} client -i
+ INPUT_FILE ${TOP}/client.spec
+)
+
+# After creating the depot and the client view, all P4 commands need to
+# have the client spec passed to them
+list(APPEND P4CMD ${P4_CLIENT})
+
+message("Adding files to repository")
+file(GLOB_RECURSE files ${TOP}/user-source/*)
+foreach(filename ${files})
+ run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} add ${filename}
+ )
+endforeach()
+
+message("Submitting changes to repository")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} submit -d "CTEST: Initial content"
+)
+message("Tagging the repository")
+file(WRITE ${TOP}/label.spec "Label: r1\n")
+file(APPEND ${TOP}/label.spec "View: //ctest/...\n")
+
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} label -i
+ INPUT_FILE ${TOP}/label.spec
+)
+
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} labelsync -l r1
+)
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content...")
+update_content(user-source files_added files_removed dirs_added)
+foreach(filename ${files_added})
+ message("add: ${filename}")
+ run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} add ${TOP}/user-source/${filename}
+ )
+endforeach()
+foreach(filename ${files_removed})
+ run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} delete ${TOP}/user-source/${filename}
+ )
+endforeach()
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 2...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} submit -d "CTEST: Changed content"
+)
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content again...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} edit //ctest/...
+)
+
+change_content(user-source)
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} revert -a //ctest/...
+)
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 3...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} submit -d "CTEST: Changed content again"
+)
+
+#-----------------------------------------------------------------------------
+# Go back to before the changes so we can test updating.
+message("Backing up to revision 1...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} sync @r1
+ )
+
+# Create a modified file.
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} sync @r1
+ )
+
+# We should p4 open any files that modify_content creates
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} open ${TOP}/user-source/CTestConfig.cmake
+)
+modify_content(user-source)
+
+#-----------------------------------------------------------------------------
+# Test updating the user work directory with the command-line interface.
+message("Running CTest Dashboard Command Line...")
+
+# Create the user build tree.
+create_build_tree(user-source user-binary)
+file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
+ "# P4 command configuration
+UpdateCommand: ${P4}
+P4Client: ctest_p4
+P4Options: -H ${P4_HOST} -p ${P4_PORT}
+")
+
+# Run the dashboard command line interface.
+run_dashboard_command_line(user-binary)
+
+# Revert the modified files
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${P4CMD} revert ${TOP}/user-source/CTestConfig.cmake
+)
+
+#-----------------------------------------------------------------------------
+# Test initial checkout and update with a dashboard script.
+# Create a new client so we can check out files on a different directory
+message("Running CTest Dashboard Script...")
+
+message("Creating client spec...")
+file(WRITE ${TOP}/client2.spec "Client: ctest2_p4\n")
+file(APPEND ${TOP}/client2.spec "Root: ${TOP}/dash-source\n")
+file(APPEND ${TOP}/client2.spec "View: //ctest/... //ctest2_p4/...\n")
+run_child(
+ COMMAND ${P4CMD} client -i
+ INPUT_FILE ${TOP}/client2.spec
+)
+
+file(MAKE_DIRECTORY ${TOP}/dash-source)
+
+create_dashboard_script(dash-binary
+ "# P4 command configuration
+set(CTEST_P4_CLIENT \"ctest2_p4\")
+set(CTEST_P4_OPTIONS \"-H ${P4_HOST} -p ${P4_PORT}\")
+set(CTEST_UPDATE_COMMAND \"${P4}\")
+")
+
+# Run the dashboard script with CTest.
+run_dashboard_script(dash-binary)
+
+#-----------------------------------------------------------------------------
+# Clean up
+message("Shutting down p4d")
+run_child(
+ WORKING_DIRECTORY ${TOP}
+ COMMAND ${P4CMD} admin stop
+) \ No newline at end of file
diff --git a/Tests/CTestUpdateSVN.cmake.in b/Tests/CTestUpdateSVN.cmake.in
new file mode 100644
index 0000000000..b5728fd67c
--- /dev/null
+++ b/Tests/CTestUpdateSVN.cmake.in
@@ -0,0 +1,149 @@
+# This script drives creation of a Subversion repository and checks
+# that CTest can update from it.
+
+#-----------------------------------------------------------------------------
+# Test in a directory next to this script.
+get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(TOP "${TOP}/@CTestUpdateSVN_DIR@")
+set(UPDATE_GLOBAL_ELEMENTS SVNPath)
+
+# Include code common to all update tests.
+include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
+
+#-----------------------------------------------------------------------------
+# Report subversion tools in use.
+message("Using subversion tools:")
+set(SVN "@Subversion_SVN_EXECUTABLE@")
+set(SVNADMIN "@Subversion_SVNADMIN_EXECUTABLE@")
+message(" svn = ${SVN}")
+message(" svnadmin = ${SVNADMIN}")
+
+# Isolate svn test operations from the user configuration.
+file(MAKE_DIRECTORY ${TOP}/config)
+set(SVNCMD ${SVN} --config-dir ${TOP}/config)
+set(SVNUSER --username "test author" --non-interactive)
+
+# Configure for this svn version.
+execute_process(
+ COMMAND ${SVN} help add OUTPUT_VARIABLE help_add ERROR_VARIABLE help_add
+ )
+if("${help_add}" MATCHES "--depth")
+ set(depth_empty "--depth=empty")
+else()
+ set(depth_empty "")
+endif()
+
+#-----------------------------------------------------------------------------
+# Initialize the testing directory.
+message("Creating test directory...")
+init_testing()
+
+#-----------------------------------------------------------------------------
+# Create the repository.
+message("Creating repository...")
+run_child(
+ COMMAND ${SVNADMIN} create --config-dir ${TOP}/config ${TOP}/repo
+ )
+set(REPO file:///${TOP}/repo/trunk)
+
+#-----------------------------------------------------------------------------
+# Import initial content into the repository.
+message("Importing content...")
+create_content(import)
+
+# Import the content into the repository.
+run_child(
+ WORKING_DIRECTORY ${TOP}/import
+ COMMAND ${SVNCMD} import ${SVNUSER} -m "Initial content" . "${REPO}"
+ )
+
+#-----------------------------------------------------------------------------
+# Create a working tree.
+message("Checking out revision 1...")
+run_child(
+ WORKING_DIRECTORY ${TOP}
+ COMMAND ${SVNCMD} co ${SVNUSER} ${REPO} user-source
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content...")
+update_content(user-source files_added files_removed dirs_added)
+if(dirs_added)
+ run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${SVNCMD} add ${depth_empty} ${dirs_added}
+ )
+endif()
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${SVNCMD} add ${files_added}
+ )
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${SVNCMD} rm ${files_removed}
+ )
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 2...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${SVNCMD} commit -m "Changed content"
+ )
+
+#-----------------------------------------------------------------------------
+# Make changes in the working tree.
+message("Changing content again...")
+change_content(user-source)
+
+#-----------------------------------------------------------------------------
+# Commit the changes to the repository.
+message("Committing revision 3...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${SVNCMD} commit -m "Changed content again"
+ )
+
+#-----------------------------------------------------------------------------
+# Go back to before the changes so we can test updating.
+message("Backing up to revision 1...")
+run_child(
+ WORKING_DIRECTORY ${TOP}/user-source
+ COMMAND ${SVNCMD} up -r1
+ )
+
+# Create a modified file.
+message("Modifying locally...")
+modify_content(user-source)
+
+#-----------------------------------------------------------------------------
+# Test updating the user work directory with the command-line interface.
+message("Running CTest Dashboard Command Line...")
+
+# Create the user build tree.
+create_build_tree(user-source user-binary)
+file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
+ "# SVN command configuration
+SVNCommand: ${SVN}
+SVNUpdateOptions: --config-dir \"${TOP}/config\"
+")
+
+# Run the dashboard command line interface.
+run_dashboard_command_line(user-binary)
+
+#-----------------------------------------------------------------------------
+# Test initial checkout and update with a dashboard script.
+message("Running CTest Dashboard Script...")
+
+create_dashboard_script(dash-binary
+ "# Subversion command configuration
+set(CTEST_SVN_COMMAND \"${SVN}\")
+set(CTEST_SVN_UPDATE_OPTIONS
+ \"--config-dir \\\"\${CTEST_DASHBOARD_ROOT}/config\\\"\")
+set(CTEST_CHECKOUT_COMMAND
+ \"\\\"\${CTEST_SVN_COMMAND}\\\" co -r1 \\\"${REPO}\\\" dash-source\")
+")
+
+# Run the dashboard script with CTest.
+run_dashboard_script(dash-binary)
diff --git a/Tests/CheckCompilerRelatedVariables/CMakeLists.txt b/Tests/CheckCompilerRelatedVariables/CMakeLists.txt
new file mode 100644
index 0000000000..87b7f1acdb
--- /dev/null
+++ b/Tests/CheckCompilerRelatedVariables/CMakeLists.txt
@@ -0,0 +1,109 @@
+cmake_minimum_required(VERSION 2.8)
+project(CheckCompilerRelatedVariables)
+
+
+function(echo_var var)
+ if(DEFINED ${var})
+ message("${var}='${${var}}' is defined")
+ else()
+ message("${var}='${${var}}' is NOT defined")
+ endif()
+endfunction()
+
+
+#
+# Check that the correct number of MSVC** variables are defined...
+#
+set(msvc_total 0)
+
+if(DEFINED MSVC60)
+ math(EXPR msvc_total "${msvc_total} + 1")
+endif()
+if(DEFINED MSVC70)
+ math(EXPR msvc_total "${msvc_total} + 1")
+endif()
+if(DEFINED MSVC71)
+ math(EXPR msvc_total "${msvc_total} + 1")
+endif()
+if(DEFINED MSVC80)
+ math(EXPR msvc_total "${msvc_total} + 1")
+endif()
+if(DEFINED MSVC90)
+ math(EXPR msvc_total "${msvc_total} + 1")
+endif()
+if(DEFINED MSVC10)
+ math(EXPR msvc_total "${msvc_total} + 1")
+endif()
+if(DEFINED MSVC11)
+ math(EXPR msvc_total "${msvc_total} + 1")
+endif()
+if(DEFINED MSVC12)
+ math(EXPR msvc_total "${msvc_total} + 1")
+endif()
+if(DEFINED MSVC14)
+ math(EXPR msvc_total "${msvc_total} + 1")
+endif()
+
+echo_var(MSVC)
+echo_var(MSVC60)
+echo_var(MSVC70)
+echo_var(MSVC71)
+echo_var(MSVC80)
+echo_var(MSVC90)
+echo_var(MSVC10)
+echo_var(MSVC11)
+echo_var(MSVC12)
+echo_var(MSVC14)
+echo_var(MSVC_IDE)
+
+if(MSVC)
+ #
+ # MSVC is set in cl.cmake when cl is the compiler...
+ #
+ # Exactly one of the numbered variables should also be set
+ # indicating which version of the cl compiler / Visual Studio
+ # is in use...
+ #
+ if(msvc_total EQUAL 1)
+ message("test passes: exactly one MSVC** variable is defined...")
+ else()
+ message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 1 expected")
+ endif()
+ if(NOT DEFINED MSVC_IDE)
+ message(FATAL_ERROR "MSVC_IDE not defined but should be!")
+ elseif("${CMAKE_GENERATOR}" MATCHES "Visual Studio" AND NOT MSVC_IDE)
+ message(FATAL_ERROR "MSVC_IDE is not true but should be (${CMAKE_GENERATOR})!")
+ elseif(NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio" AND MSVC_IDE)
+ message(FATAL_ERROR "MSVC_IDE is true but should not be (${CMAKE_GENERATOR})!")
+ endif()
+else()
+ #
+ # The compiler is something other than cl... None of the MSVC** variables
+ # should be defined...
+ #
+ if(msvc_total EQUAL 0)
+ message("test passes: no MSVC** variables are defined on non-MSVC build...")
+ else()
+ message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 0 expected")
+ endif()
+ if(DEFINED MSVC_IDE)
+ message(FATAL_ERROR "MSVC_IDE is defined but should not be!")
+ endif()
+endif()
+
+
+#
+# This is a no-op executable... If this test is going to fail, it fails during
+# the configure step while cmake is configuring this CMakeLists.txt file...
+#
+
+file(WRITE
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
+ "int main() { return 0; }
+"
+ )
+
+add_executable(
+ CheckCompilerRelatedVariables
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
+ )
diff --git a/Tests/CheckFortran.cmake b/Tests/CheckFortran.cmake
new file mode 100644
index 0000000000..ebbb426ce4
--- /dev/null
+++ b/Tests/CheckFortran.cmake
@@ -0,0 +1,50 @@
+
+#=============================================================================
+# Copyright 2009 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.)
+
+if(NOT DEFINED CMAKE_Fortran_COMPILER)
+ set(_desc "Looking for a Fortran compiler")
+ message(STATUS ${_desc})
+ file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran/CMakeLists.txt"
+ "cmake_minimum_required(VERSION 2.4)
+project(CheckFortran Fortran)
+file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
+ \"set(CMAKE_Fortran_COMPILER \\\"\${CMAKE_Fortran_COMPILER}\\\")\\n\"
+ \"set(CMAKE_Fortran_FLAGS \\\"\${CMAKE_Fortran_FLAGS}\\\")\\n\"
+ )
+")
+ execute_process(
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran
+ COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR}
+ OUTPUT_VARIABLE output
+ ERROR_VARIABLE output
+ RESULT_VARIABLE result
+ )
+ include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran/result.cmake OPTIONAL)
+ if(CMAKE_Fortran_COMPILER AND "${result}" STREQUAL "0")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "${_desc} passed with the following output:\n"
+ "${output}\n")
+ else()
+ set(CMAKE_Fortran_COMPILER NOTFOUND)
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "${_desc} failed with the following output:\n"
+ "${output}\n")
+ endif()
+ message(STATUS "${_desc} - ${CMAKE_Fortran_COMPILER}")
+ set(CMAKE_Fortran_COMPILER "${CMAKE_Fortran_COMPILER}" CACHE FILEPATH "Fortran compiler")
+ mark_as_advanced(CMAKE_Fortran_COMPILER)
+ set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" CACHE STRING "Fortran flags")
+ mark_as_advanced(CMAKE_Fortran_FLAGS)
+endif()
diff --git a/Tests/CoberturaCoverage/DartConfiguration.tcl.in b/Tests/CoberturaCoverage/DartConfiguration.tcl.in
new file mode 100644
index 0000000000..954f59a8a6
--- /dev/null
+++ b/Tests/CoberturaCoverage/DartConfiguration.tcl.in
@@ -0,0 +1,8 @@
+# This file is configured by CMake automatically as DartConfiguration.tcl
+# If you choose not to use CMake, this file may be hand configured, by
+# filling in the required variables.
+
+
+# Configuration directories and files
+SourceDirectory: ${CMake_SOURCE_DIR}/Testing/CoberturaCoverage
+BuildDirectory: ${CMake_BINARY_DIR}/Testing/CoberturaCoverage
diff --git a/Tests/CoberturaCoverage/coverage.xml.in b/Tests/CoberturaCoverage/coverage.xml.in
new file mode 100644
index 0000000000..b3f6691d03
--- /dev/null
+++ b/Tests/CoberturaCoverage/coverage.xml.in
@@ -0,0 +1,112 @@
+<?xml version="1.0"?>
+<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
+
+<coverage line-rate="0.7222222222222222" branch-rate="0.875" lines-covered="13" lines-valid="18" branches-covered="7" branches-valid="8" complexity="0.0" version="1.9.4.1" timestamp="1401890139281">
+ <sources>
+ <source>${CMake_BINARY_DIR}/Testing/CoberturaCoverage/src/main/java/</source>
+ </sources>
+ <packages>
+ <package name="org.cmake.Coverage" line-rate="0.7222222222222222" branch-rate="0.875" complexity="0.0">
+ <classes>
+ <class name="org.cmake.Coverage.CoverageTest" filename="org/cmake/CoverageTest.java" line-rate="0.7222222222222222" branch-rate="0.875" complexity="0.0">
+ <methods>
+ <method name="&lt;clinit&gt;" signature="()V" line-rate="1.0" branch-rate="1.0">
+ <lines>
+ <line number="10" hits="2" branch="false"/>
+ <line number="11" hits="2" branch="false"/>
+ </lines>
+ </method>
+ <method name="&lt;init&gt;" signature="()V" line-rate="0.0" branch-rate="1.0">
+ <lines>
+ <line number="8" hits="0" branch="false"/>
+ <line number="12" hits="0" branch="false"/>
+ </lines>
+ </method>
+ <method name="equalsVarOne" signature="(Ljava/lang/String;)Ljava/lang/Boolean;" line-rate="0.6666666666666666" branch-rate="0.5">
+ <lines>
+ <line number="16" hits="2" branch="true" condition-coverage="50% (1/2)">
+ <conditions>
+ <condition number="0" type="jump" coverage="50%"/>
+ </conditions>
+ </line>
+ <line number="17" hits="2" branch="false"/>
+ <line number="20" hits="0" branch="false"/>
+ </lines>
+ </method>
+ <method name="equalsVarTwo" signature="(Ljava/lang/String;)Z" line-rate="1.0" branch-rate="1.0">
+ <lines>
+ <line number="26" hits="4" branch="true" condition-coverage="100% (2/2)">
+ <conditions>
+ <condition number="0" type="jump" coverage="100%"/>
+ </conditions>
+ </line>
+ <line number="27" hits="2" branch="false"/>
+ <line number="30" hits="2" branch="false"/>
+ </lines>
+ </method>
+ <method name="timesIntOne" signature="(Ljava/lang/Integer;)Ljava/lang/Integer;" line-rate="0.0" branch-rate="1.0">
+ <lines>
+ <line number="35" hits="0" branch="false"/>
+ <line number="36" hits="0" branch="false"/>
+ </lines>
+ </method>
+ <method name="whileLoop" signature="(Ljava/lang/Integer;)Z" line-rate="1.0" branch-rate="1.0">
+ <lines>
+ <line number="41" hits="2" branch="false"/>
+ <line number="42" hits="10" branch="true" condition-coverage="100% (2/2)">
+ <conditions>
+ <condition number="0" type="jump" coverage="100%"/>
+ </conditions>
+ </line>
+ <line number="43" hits="8" branch="false"/>
+ <line number="45" hits="2" branch="true" condition-coverage="100% (2/2)">
+ <conditions>
+ <condition number="0" type="jump" coverage="100%"/>
+ </conditions>
+ </line>
+ <line number="46" hits="1" branch="false"/>
+ <line number="49" hits="1" branch="false"/>
+ </lines>
+ </method>
+ </methods>
+ <lines>
+ <line number="8" hits="0" branch="false"/>
+ <line number="10" hits="2" branch="false"/>
+ <line number="11" hits="2" branch="false"/>
+ <line number="12" hits="0" branch="false"/>
+ <line number="16" hits="2" branch="true" condition-coverage="50% (1/2)">
+ <conditions>
+ <condition number="0" type="jump" coverage="50%"/>
+ </conditions>
+ </line>
+ <line number="17" hits="2" branch="false"/>
+ <line number="20" hits="0" branch="false"/>
+ <line number="26" hits="4" branch="true" condition-coverage="100% (2/2)">
+ <conditions>
+ <condition number="0" type="jump" coverage="100%"/>
+ </conditions>
+ </line>
+ <line number="27" hits="2" branch="false"/>
+ <line number="30" hits="2" branch="false"/>
+ <line number="35" hits="0" branch="false"/>
+ <line number="36" hits="0" branch="false"/>
+ <line number="41" hits="2" branch="false"/>
+ <line number="42" hits="10" branch="true" condition-coverage="100% (2/2)">
+ <conditions>
+ <condition number="0" type="jump" coverage="100%"/>
+ </conditions>
+ </line>
+ <line number="43" hits="8" branch="false"/>
+ <line number="45" hits="2" branch="true" condition-coverage="100% (2/2)">
+ <conditions>
+ <condition number="0" type="jump" coverage="100%"/>
+ </conditions>
+ </line>
+ <line number="46" hits="1" branch="false"/>
+ <line number="49" hits="1" branch="false"/>
+ </lines>
+ </class>
+ </classes>
+ </package>
+ </packages>
+</coverage>
diff --git a/Tests/CoberturaCoverage/src/main/java/org/cmake/CoverageTest.java b/Tests/CoberturaCoverage/src/main/java/org/cmake/CoverageTest.java
new file mode 100644
index 0000000000..4fb43c6084
--- /dev/null
+++ b/Tests/CoberturaCoverage/src/main/java/org/cmake/CoverageTest.java
@@ -0,0 +1,52 @@
+package org.cmake.Coverage;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.List;
+import java.awt.*;
+
+public class CoverageTest {
+
+ public static String VarOne = "test1";
+ public static String VarTwo = "test2";
+ private Integer IntOne = 4;
+
+ public static Boolean equalsVarOne(String inString) {
+
+ if(VarOne.equals(inString)){
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ public static boolean equalsVarTwo(String inString){
+
+ if(VarTwo.equals(inString)){
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ private Integer timesIntOne(Integer inVal){
+
+ return inVal * IntOne;
+ }
+
+ public static boolean whileLoop(Integer StopInt){
+
+ Integer i = 0;
+ while(i < StopInt){
+ i=i+1;
+ }
+ if (i.equals(5)){
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+}
diff --git a/Tests/CommandLineTest/CMakeLists.txt b/Tests/CommandLineTest/CMakeLists.txt
new file mode 100644
index 0000000000..96aac104c2
--- /dev/null
+++ b/Tests/CommandLineTest/CMakeLists.txt
@@ -0,0 +1,79 @@
+cmake_minimum_required (VERSION 2.6)
+project(CommandLineTest)
+
+get_filename_component(CMAKE_BIN_DIR ${CMAKE_COMMAND} PATH)
+macro(EXEC_CMAKE_COMMAND CMAKE_ARGS)
+ exec_program("${CMAKE_COMMAND}" ARGS "${CMAKE_ARGS}" RETURN_VALUE RET)
+ if(${RET})
+ message(SEND_ERROR "CMake command failed with arguments \"${CMAKE_ARGS}\"")
+ endif()
+endmacro()
+
+EXEC_CMAKE_COMMAND("-E chdir \"${CMAKE_CURRENT_SOURCE_DIR}\" \"${CMAKE_COMMAND}\" -E echo \"Hello World\"")
+EXEC_CMAKE_COMMAND("-E time \"${CMAKE_COMMAND} -N -L ${CommandLineTest_SOURCE_DIR}\"")
+EXEC_CMAKE_COMMAND("-E time \"${CMAKE_COMMAND} -N -LA ${CommandLineTest_SOURCE_DIR}\"")
+EXEC_CMAKE_COMMAND("-E time \"${CMAKE_COMMAND} -N -LH ${CommandLineTest_SOURCE_DIR}\"")
+EXEC_CMAKE_COMMAND("-E time \"${CMAKE_COMMAND} -N -LAH ${CommandLineTest_SOURCE_DIR}\"")
+EXEC_CMAKE_COMMAND("--help")
+EXEC_CMAKE_COMMAND("--help-command-list")
+EXEC_CMAKE_COMMAND("--help add_executable")
+EXEC_CMAKE_COMMAND("--help-command add_executable")
+EXEC_CMAKE_COMMAND("--help-full \"${CMAKE_CURRENT_BINARY_DIR}/cmake.txt\"")
+EXEC_CMAKE_COMMAND("--help-man \"${CMAKE_CURRENT_BINARY_DIR}/cmake.man\"")
+EXEC_CMAKE_COMMAND("--help-html \"${CMAKE_CURRENT_BINARY_DIR}/cmake.html\"")
+EXEC_CMAKE_COMMAND("--copyright \"${CMAKE_CURRENT_BINARY_DIR}/Copyright.txt\"")
+EXEC_CMAKE_COMMAND("--version \"${CMAKE_CURRENT_BINARY_DIR}/version.txt\"")
+
+add_executable(CommandLineTest CommandLineTest.cxx)
+
+get_filename_component(CMAKE_COMMAND_PATH "${CMAKE_COMMAND}" PATH)
+set(CTEST_COMMAND "${CMAKE_COMMAND_PATH}/ctest")
+macro(EXEC_CTEST_COMMAND CMAKE_ARGS)
+ exec_program("${CTEST_COMMAND}" ARGS "${CMAKE_ARGS}" RETURN_VALUE RET)
+ if(${RET})
+ message(SEND_ERROR "CTest command failed with arguments \"${CMAKE_ARGS}\"")
+ endif()
+endmacro()
+macro(EXEC_CTEST_COMMAND_WITH_DIR DIR CMAKE_ARGS)
+ exec_program("${CTEST_COMMAND}" "${DIR}" ARGS "${CMAKE_ARGS}" RETURN_VALUE RET)
+ if(${RET})
+ message(SEND_ERROR "CTest command failed with arguments \"${CMAKE_ARGS}\"")
+ endif()
+endmacro()
+
+EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-N")
+EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-R complex -N")
+EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-E Simple -N")
+EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-E Simple -N")
+EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-N -I -10")
+EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-N -I 10-")
+EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-N -I 3,4")
+EXEC_CTEST_COMMAND("--help")
+EXEC_CTEST_COMMAND("--copyright")
+EXEC_CTEST_COMMAND("--help-full \"${CMAKE_CURRENT_BINARY_DIR}/ctest.txt\"")
+EXEC_CTEST_COMMAND("--help-man \"${CMAKE_CURRENT_BINARY_DIR}/ctest.man\"")
+EXEC_CTEST_COMMAND("--help-html \"${CMAKE_CURRENT_BINARY_DIR}/ctest.html\"")
+EXEC_CTEST_COMMAND("--version")
+
+if(THIS_SHOULD_BE_SET)
+ message(STATUS "***************************")
+ message(STATUS "PreLoad.cmake works fine.")
+ message(STATUS "***************************")
+else()
+ message("***************************")
+ message(FATAL_ERROR "PreLoad.cmake does not work.")
+endif()
+
+if(DEFINED ENV{TEST_ENVIRONMENT_VARIABLE_NOTSET})
+ message(SEND_ERROR "Environment variable definition test broken!")
+endif()
+
+set(ENV{TEST_ENVIRONMENT_VARIABLE} "Environment variable set")
+if("$ENV{TEST_ENVIRONMENT_VARIABLE}" STREQUAL "Environment variable set")
+ message(STATUS "Environment variable set to: $ENV{TEST_ENVIRONMENT_VARIABLE}")
+ if(NOT DEFINED ENV{TEST_ENVIRONMENT_VARIABLE})
+ message(SEND_ERROR "Environment variable definition test failed!")
+ endif()
+else()
+ message(SEND_ERROR "Environment variable setting is broken")
+endif()
diff --git a/Tests/CommandLineTest/CommandLineTest.cxx b/Tests/CommandLineTest/CommandLineTest.cxx
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/CommandLineTest/CommandLineTest.cxx
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/CommandLineTest/PreLoad.cmake b/Tests/CommandLineTest/PreLoad.cmake
new file mode 100644
index 0000000000..f059bcea6e
--- /dev/null
+++ b/Tests/CommandLineTest/PreLoad.cmake
@@ -0,0 +1 @@
+set(THIS_SHOULD_BE_SET ON CACHE BOOL "Some variable")
diff --git a/Tests/CompatibleInterface/CMakeLists.txt b/Tests/CompatibleInterface/CMakeLists.txt
new file mode 100644
index 0000000000..668a97b14c
--- /dev/null
+++ b/Tests/CompatibleInterface/CMakeLists.txt
@@ -0,0 +1,130 @@
+
+cmake_minimum_required(VERSION 3.0)
+
+project(CompatibleInterface)
+
+include(GenerateExportHeader)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_library(iface1 INTERFACE)
+set_property(TARGET iface1 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_BOOL
+ BOOL_PROP1
+ BOOL_PROP2
+ BOOL_PROP3
+ BOOL_PROP4
+)
+set_property(TARGET iface1 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_STRING
+ STRING_PROP1
+ STRING_PROP2
+ STRING_PROP3
+)
+set_property(TARGET iface1 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_NUMBER_MIN
+ NUMBER_MIN_PROP1
+ NUMBER_MIN_PROP2
+ NUMBER_MIN_PROP3
+ NUMBER_MIN_PROP4
+)
+set_property(TARGET iface1 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_NUMBER_MAX
+ NUMBER_MAX_PROP1
+ NUMBER_MAX_PROP2
+)
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES
+ BOOL_PROP1 BOOL_PROP2 BOOL_PROP3 BOOL_PROP4
+ STRING_PROP1 STRING_PROP2 STRING_PROP3
+ NUMBER_MIN_PROP1 NUMBER_MIN_PROP2 NUMBER_MIN_PROP3 NUMBER_MIN_PROP4
+ NUMBER_MAX_PROP1 NUMBER_MAX_PROP2
+)
+
+set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP1 ON)
+set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP2 ON)
+set_property(TARGET iface1 PROPERTY INTERFACE_STRING_PROP1 prop1)
+set_property(TARGET iface1 PROPERTY INTERFACE_STRING_PROP2 prop2)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP1 100)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP2 200)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP3 0x10)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP4 0x10)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP1 100)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP2 200)
+
+add_executable(CompatibleInterface main.cpp)
+target_link_libraries(CompatibleInterface iface1)
+
+add_library(foo STATIC foo.cpp)
+add_library(bar SHARED bar.cpp)
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SOMEPROP)
+set_property(TARGET foo PROPERTY INTERFACE_SOMEPROP ON)
+# Use LINK_ONLY to suppress usage requirements and allow the check to pass.
+set_property(TARGET bar PROPERTY INTERFACE_LINK_LIBRARIES $<LINK_ONLY:foo>)
+set_property(TARGET CompatibleInterface PROPERTY SOMEPROP OFF)
+target_link_libraries(CompatibleInterface bar)
+
+set_property(TARGET CompatibleInterface PROPERTY BOOL_PROP2 ON)
+set_property(TARGET CompatibleInterface PROPERTY BOOL_PROP3 ON)
+set_property(TARGET CompatibleInterface PROPERTY STRING_PROP2 prop2)
+set_property(TARGET CompatibleInterface PROPERTY STRING_PROP3 prop3)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP1 50)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP2 250)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP3 0xa)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP4 0x1A)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MAX_PROP1 50)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MAX_PROP2 250)
+
+target_compile_definitions(CompatibleInterface
+ PRIVATE
+ $<$<BOOL:$<TARGET_PROPERTY:BOOL_PROP1>>:BOOL_PROP1>
+ $<$<BOOL:$<TARGET_PROPERTY:BOOL_PROP2>>:BOOL_PROP2>
+ $<$<BOOL:$<TARGET_PROPERTY:BOOL_PROP3>>:BOOL_PROP3>
+ $<$<STREQUAL:$<TARGET_PROPERTY:STRING_PROP1>,prop1>:STRING_PROP1>
+ $<$<STREQUAL:$<TARGET_PROPERTY:STRING_PROP2>,prop2>:STRING_PROP2>
+ $<$<STREQUAL:$<TARGET_PROPERTY:STRING_PROP3>,prop3>:STRING_PROP3>
+ $<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MIN_PROP1>,50>:NUMBER_MIN_PROP1=50>
+ $<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MIN_PROP2>,200>:NUMBER_MIN_PROP2=200>
+ $<$<EQUAL:$<TARGET_PROPERTY:NUMBER_MIN_PROP3>,0xA>:NUMBER_MIN_PROP3=0xA>
+ $<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MIN_PROP4>,0x10>:NUMBER_MIN_PROP4=0x10>
+ $<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MAX_PROP1>,100>:NUMBER_MAX_PROP1=100>
+ $<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MAX_PROP2>,250>:NUMBER_MAX_PROP2=250>
+)
+
+
+add_library(iface2 SHARED iface2.cpp)
+generate_export_header(iface2)
+
+set_property(TARGET iface2 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_STRING
+ Iface2_PROP
+)
+
+# For the LINK_LIBRARIES and related properties, we should not evaluate
+# properties defined only in the interface - they should be implicitly zero
+set_property(TARGET iface2
+ APPEND PROPERTY
+ LINK_INTERFACE_LIBRARIES $<$<BOOL:$<TARGET_PROPERTY:BOOL_PROP4>>:nonexistent>
+)
+target_link_libraries(CompatibleInterface iface2
+ $<$<BOOL:$<TARGET_PROPERTY:Iface2_PROP>>:nonexistent>
+)
+# Test that this does not segfault:
+target_compile_definitions(CompatibleInterface
+ PRIVATE
+ $<$<BOOL:$<TARGET_PROPERTY:Iface2_PROP>>:SOME_DEFINE>
+)
+
+# The COMPATIBLE_INTERFACE_* properties are only read from dependencies
+# in the interface. Populating it on the CompatibleInterface target does
+# not have any effect on the interpretation of the INTERFACE variants
+# in dependencies.
+set_property(TARGET iface1 PROPERTY
+ INTERFACE_NON_RELEVANT_PROP ON
+)
+set_property(TARGET iface2 PROPERTY
+ INTERFACE_NON_RELEVANT_PROP ON
+)
+set_property(TARGET CompatibleInterface APPEND PROPERTY
+ COMPATIBLE_INTERFACE_BOOL
+ NON_RELEVANT_PROP
+)
diff --git a/Tests/CompatibleInterface/bar.cpp b/Tests/CompatibleInterface/bar.cpp
new file mode 100644
index 0000000000..2e0990093a
--- /dev/null
+++ b/Tests/CompatibleInterface/bar.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int bar()
+{
+ return 0;
+}
diff --git a/Tests/CompatibleInterface/empty.cpp b/Tests/CompatibleInterface/empty.cpp
new file mode 100644
index 0000000000..00323299cb
--- /dev/null
+++ b/Tests/CompatibleInterface/empty.cpp
@@ -0,0 +1 @@
+// no content
diff --git a/Tests/CompatibleInterface/foo.cpp b/Tests/CompatibleInterface/foo.cpp
new file mode 100644
index 0000000000..e05eb7e694
--- /dev/null
+++ b/Tests/CompatibleInterface/foo.cpp
@@ -0,0 +1,4 @@
+int foo()
+{
+ return 0;
+}
diff --git a/Tests/CompatibleInterface/iface2.cpp b/Tests/CompatibleInterface/iface2.cpp
new file mode 100644
index 0000000000..a9b501508f
--- /dev/null
+++ b/Tests/CompatibleInterface/iface2.cpp
@@ -0,0 +1,7 @@
+
+#include "iface2.h"
+
+int Iface2::foo()
+{
+ return 0;
+}
diff --git a/Tests/CompatibleInterface/iface2.h b/Tests/CompatibleInterface/iface2.h
new file mode 100644
index 0000000000..ef4ebeec21
--- /dev/null
+++ b/Tests/CompatibleInterface/iface2.h
@@ -0,0 +1,13 @@
+
+#ifndef IFACE2_H
+#define IFACE2_H
+
+#include "iface2_export.h"
+
+class IFACE2_EXPORT Iface2
+{
+public:
+ int foo();
+};
+
+#endif
diff --git a/Tests/CompatibleInterface/main.cpp b/Tests/CompatibleInterface/main.cpp
new file mode 100644
index 0000000000..d20b64b2b9
--- /dev/null
+++ b/Tests/CompatibleInterface/main.cpp
@@ -0,0 +1,53 @@
+
+#ifndef BOOL_PROP1
+#error Expected BOOL_PROP1
+#endif
+
+#ifndef BOOL_PROP2
+#error Expected BOOL_PROP2
+#endif
+
+#ifndef BOOL_PROP3
+#error Expected BOOL_PROP3
+#endif
+
+#ifndef STRING_PROP1
+#error Expected STRING_PROP1
+#endif
+
+#ifndef STRING_PROP2
+#error Expected STRING_PROP2
+#endif
+
+#ifndef STRING_PROP3
+#error Expected STRING_PROP3
+#endif
+
+template<bool test>
+struct CMakeStaticAssert;
+
+template<>
+struct CMakeStaticAssert<true> {};
+
+enum {
+ NumericMaxTest1 = sizeof(CMakeStaticAssert<NUMBER_MAX_PROP1 == 100>),
+ NumericMaxTest2 = sizeof(CMakeStaticAssert<NUMBER_MAX_PROP2 == 250>),
+ NumericMinTest1 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP1 == 50>),
+ NumericMinTest2 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP2 == 200>),
+ NumericMinTest3 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP3 == 0xA>),
+ NumericMinTest4 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP4 == 0x10>)
+};
+
+#include "iface2.h"
+
+int foo();
+#ifdef _WIN32
+__declspec(dllimport)
+#endif
+int bar();
+
+int main(int argc, char **argv)
+{
+ Iface2 if2;
+ return if2.foo() + foo() + bar();
+}
diff --git a/Tests/CompileCommandOutput/CMakeLists.txt b/Tests/CompileCommandOutput/CMakeLists.txt
new file mode 100644
index 0000000000..6f9468dcaa
--- /dev/null
+++ b/Tests/CompileCommandOutput/CMakeLists.txt
@@ -0,0 +1,16 @@
+# a simple C only test case
+cmake_minimum_required (VERSION 2.6)
+project (CompileCommandOutput CXX)
+
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+set(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
+if(MAKE_SUPPORTS_SPACES)
+ set(test1_srcs "file with spaces.cxx")
+else()
+ set(test1_srcs "file_with_underscores.cxx")
+endif()
+add_library(test1 STATIC ${test1_srcs})
+add_library(test2 SHARED "../CompileCommandOutput/relative.cxx")
+include_directories(${CompileCommandOutput_SOURCE_DIR}/../../Source)
+add_executable(CompileCommandOutput compile_command_output.cxx)
+target_link_libraries(CompileCommandOutput test1 test2)
diff --git a/Tests/CompileCommandOutput/compile_command_output.cxx b/Tests/CompileCommandOutput/compile_command_output.cxx
new file mode 100644
index 0000000000..145a064267
--- /dev/null
+++ b/Tests/CompileCommandOutput/compile_command_output.cxx
@@ -0,0 +1,9 @@
+#include "file_with_underscores.h"
+#include "relative.h"
+
+int main (int argc, char** argv)
+{
+ file_with_underscores();
+ relative();
+ return 0;
+}
diff --git a/Tests/CompileCommandOutput/file with spaces.cxx b/Tests/CompileCommandOutput/file with spaces.cxx
new file mode 100644
index 0000000000..554e176e48
--- /dev/null
+++ b/Tests/CompileCommandOutput/file with spaces.cxx
@@ -0,0 +1 @@
+#include "file_with_underscores.cxx"
diff --git a/Tests/CompileCommandOutput/file_with_underscores.cxx b/Tests/CompileCommandOutput/file_with_underscores.cxx
new file mode 100644
index 0000000000..4f42ccf569
--- /dev/null
+++ b/Tests/CompileCommandOutput/file_with_underscores.cxx
@@ -0,0 +1,3 @@
+#include "file_with_underscores.h"
+
+void file_with_underscores() {}
diff --git a/Tests/CompileCommandOutput/file_with_underscores.h b/Tests/CompileCommandOutput/file_with_underscores.h
new file mode 100644
index 0000000000..0d73e31599
--- /dev/null
+++ b/Tests/CompileCommandOutput/file_with_underscores.h
@@ -0,0 +1 @@
+void file_with_underscores();
diff --git a/Tests/CompileCommandOutput/relative.cxx b/Tests/CompileCommandOutput/relative.cxx
new file mode 100644
index 0000000000..eae11e226e
--- /dev/null
+++ b/Tests/CompileCommandOutput/relative.cxx
@@ -0,0 +1,3 @@
+#include "relative.h"
+
+void relative() {}
diff --git a/Tests/CompileCommandOutput/relative.h b/Tests/CompileCommandOutput/relative.h
new file mode 100644
index 0000000000..ddfe5519bc
--- /dev/null
+++ b/Tests/CompileCommandOutput/relative.h
@@ -0,0 +1,11 @@
+#if defined(_WIN32)
+# ifdef test2_EXPORTS
+# define TEST2_EXPORT __declspec(dllexport)
+# else
+# define TEST2_EXPORT __declspec(dllimport)
+# endif
+#else
+# define TEST2_EXPORT
+#endif
+
+TEST2_EXPORT void relative();
diff --git a/Tests/CompileDefinitions/CMakeLists.txt b/Tests/CompileDefinitions/CMakeLists.txt
new file mode 100644
index 0000000000..930d22058a
--- /dev/null
+++ b/Tests/CompileDefinitions/CMakeLists.txt
@@ -0,0 +1,26 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(CompileDefinitions)
+
+if ("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 6")
+ add_definitions(-DNO_SPACES_IN_DEFINE_VALUES)
+ set(NO_SPACES_IN_DEFINE_VALUES 1)
+endif()
+
+# Use compile flags to tell executables which config is built
+# without depending on the compile definitions functionality.
+foreach(c DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
+ set(CMAKE_C_FLAGS_${c} "${CMAKE_C_FLAGS_${c}} -DTEST_CONFIG_${c}")
+ set(CMAKE_CXX_FLAGS_${c} "${CMAKE_CXX_FLAGS_${c}} -DTEST_CONFIG_${c}")
+endforeach()
+
+set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
+ "BUILD_CONFIG_NAME=\"$<CONFIGURATION>\""
+ )
+
+add_subdirectory(add_definitions_command)
+add_subdirectory(target_prop)
+add_subdirectory(add_definitions_command_with_target_prop)
+
+add_executable(CompileDefinitions runtest.c)
diff --git a/Tests/CompileDefinitions/add_definitions_command/CMakeLists.txt b/Tests/CompileDefinitions/add_definitions_command/CMakeLists.txt
new file mode 100644
index 0000000000..23e0134258
--- /dev/null
+++ b/Tests/CompileDefinitions/add_definitions_command/CMakeLists.txt
@@ -0,0 +1,15 @@
+
+project(add_definitions_command)
+
+add_definitions(-DCMAKE_IS_FUN -DCMAKE_IS=Fun -DCMAKE_IS_="Fun")
+if (NOT NO_SPACES_IN_DEFINE_VALUES)
+ add_definitions(-DCMAKE_IS_REALLY="Very Fun")
+endif()
+add_definitions(-DCMAKE_IS_="Fun")
+if (NOT NO_SPACES_IN_DEFINE_VALUES)
+ add_definitions(-DCMAKE_IS_REALLY="Very Fun")
+endif()
+add_definitions(-DCMAKE_IS_FUN -DCMAKE_IS=Fun)
+add_definitions(-DBUILD_IS_DEBUG=$<CONFIG:Debug> -DBUILD_IS_NOT_DEBUG=$<NOT:$<CONFIG:Debug>>)
+
+add_executable(add_definitions_command_executable ../compiletest.cpp)
diff --git a/Tests/CompileDefinitions/add_definitions_command_with_target_prop/CMakeLists.txt b/Tests/CompileDefinitions/add_definitions_command_with_target_prop/CMakeLists.txt
new file mode 100644
index 0000000000..55108db7a0
--- /dev/null
+++ b/Tests/CompileDefinitions/add_definitions_command_with_target_prop/CMakeLists.txt
@@ -0,0 +1,19 @@
+
+project(add_definitions_command_with_target_prop)
+
+add_definitions(-DCMAKE_IS_FUN -DCMAKE_IS=Fun)
+
+add_executable(add_definitions_command_with_target_prop_executable ../compiletest.cpp)
+
+set_target_properties(add_definitions_command_with_target_prop_executable PROPERTIES COMPILE_DEFINITIONS CMAKE_IS_="Fun")
+
+if (NOT NO_SPACES_IN_DEFINE_VALUES)
+ set_property(TARGET add_definitions_command_with_target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_IS_REALLY="Very Fun")
+endif()
+
+add_definitions(-DCMAKE_IS_FUN)
+
+set_property(TARGET add_definitions_command_with_target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_IS=Fun CMAKE_IS_="Fun")
+
+add_definitions(-DBUILD_IS_DEBUG=$<CONFIG:Debug>)
+set_property(TARGET add_definitions_command_with_target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS BUILD_IS_NOT_DEBUG=$<NOT:$<CONFIG:Debug>>)
diff --git a/Tests/CompileDefinitions/compiletest.c b/Tests/CompileDefinitions/compiletest.c
new file mode 100644
index 0000000000..8871750af8
--- /dev/null
+++ b/Tests/CompileDefinitions/compiletest.c
@@ -0,0 +1,23 @@
+
+#ifndef LINK_C_DEFINE
+#error Expected LINK_C_DEFINE
+#endif
+#ifndef LINK_LANGUAGE_IS_C
+#error Expected LINK_LANGUAGE_IS_C
+#endif
+
+#ifdef LINK_CXX_DEFINE
+#error Unexpected LINK_CXX_DEFINE
+#endif
+#ifdef LINK_LANGUAGE_IS_CXX
+#error Unexpected LINK_LANGUAGE_IS_CXX
+#endif
+
+#ifdef DEBUG_MODE
+#error Unexpected DEBUG_MODE
+#endif
+
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/CompileDefinitions/compiletest.cpp b/Tests/CompileDefinitions/compiletest.cpp
new file mode 100644
index 0000000000..7df09df819
--- /dev/null
+++ b/Tests/CompileDefinitions/compiletest.cpp
@@ -0,0 +1,104 @@
+
+#ifndef CMAKE_IS_FUN
+#error Expect CMAKE_IS_FUN definition
+#endif
+
+#if CMAKE_IS != Fun
+#error Expect CMAKE_IS=Fun definition
+#endif
+
+
+template<bool test>
+struct CMakeStaticAssert;
+
+template<>
+struct CMakeStaticAssert<true> {};
+
+static const char fun_string[] = CMAKE_IS_;
+#ifndef NO_SPACES_IN_DEFINE_VALUES
+static const char very_fun_string[] = CMAKE_IS_REALLY;
+#endif
+
+enum {
+ StringLiteralTest1 = sizeof(CMakeStaticAssert<sizeof(CMAKE_IS_) == sizeof("Fun")>),
+#ifndef NO_SPACES_IN_DEFINE_VALUES
+ StringLiteralTest2 = sizeof(CMakeStaticAssert<sizeof(CMAKE_IS_REALLY) == sizeof("Very Fun")>),
+#endif
+#ifdef TEST_GENERATOR_EXPRESSIONS
+ StringLiteralTest3 = sizeof(CMakeStaticAssert<sizeof(LETTER_LIST1) == sizeof("A,B,C,D")>),
+ StringLiteralTest4 = sizeof(CMakeStaticAssert<sizeof(LETTER_LIST2) == sizeof("A,,B,,C,,D")>),
+ StringLiteralTest5 = sizeof(CMakeStaticAssert<sizeof(LETTER_LIST3) == sizeof("A,-B,-C,-D")>),
+ StringLiteralTest6 = sizeof(CMakeStaticAssert<sizeof(LETTER_LIST4) == sizeof("A-,-B-,-C-,-D")>),
+ StringLiteralTest7 = sizeof(CMakeStaticAssert<sizeof(LETTER_LIST5) == sizeof("A-,B-,C-,D")>)
+#endif
+};
+
+#ifdef TEST_GENERATOR_EXPRESSIONS
+#ifndef CMAKE_IS_DECLARATIVE
+#error Expect declarative definition
+#endif
+#ifdef GE_NOT_DEFINED
+#error Expect not defined generator expression
+#endif
+
+#ifndef ARGUMENT
+#error Expected define expanded from list
+#endif
+#ifndef LIST
+#error Expected define expanded from list
+#endif
+
+#ifndef PREFIX_DEF1
+#error Expect PREFIX_DEF1
+#endif
+
+#ifndef PREFIX_DEF2
+#error Expect PREFIX_DEF2
+#endif
+
+#ifndef LINK_CXX_DEFINE
+#error Expected LINK_CXX_DEFINE
+#endif
+#ifndef LINK_LANGUAGE_IS_CXX
+#error Expected LINK_LANGUAGE_IS_CXX
+#endif
+
+#ifdef LINK_C_DEFINE
+#error Unexpected LINK_C_DEFINE
+#endif
+#ifdef LINK_LANGUAGE_IS_C
+#error Unexpected LINK_LANGUAGE_IS_C
+#endif
+
+
+// TEST_GENERATOR_EXPRESSIONS
+#endif
+
+#ifndef BUILD_IS_DEBUG
+# error "BUILD_IS_DEBUG not defined!"
+#endif
+#ifndef BUILD_IS_NOT_DEBUG
+# error "BUILD_IS_NOT_DEBUG not defined!"
+#endif
+
+// Check per-config definitions.
+#ifdef TEST_CONFIG_DEBUG
+# if !BUILD_IS_DEBUG
+# error "BUILD_IS_DEBUG false with TEST_CONFIG_DEBUG!"
+# endif
+# if BUILD_IS_NOT_DEBUG
+# error "BUILD_IS_NOT_DEBUG true with TEST_CONFIG_DEBUG!"
+# endif
+#else
+# if BUILD_IS_DEBUG
+# error "BUILD_IS_DEBUG true without TEST_CONFIG_DEBUG!"
+# endif
+# if !BUILD_IS_NOT_DEBUG
+# error "BUILD_IS_NOT_DEBUG false without TEST_CONFIG_DEBUG!"
+# endif
+#endif
+
+int main(int argc, char **argv)
+{
+ return 0;
+}
diff --git a/Tests/CompileDefinitions/compiletest_mixed_c.c b/Tests/CompileDefinitions/compiletest_mixed_c.c
new file mode 100644
index 0000000000..a270b2b12e
--- /dev/null
+++ b/Tests/CompileDefinitions/compiletest_mixed_c.c
@@ -0,0 +1,23 @@
+
+#ifndef LINK_CXX_DEFINE
+#error Expected LINK_CXX_DEFINE
+#endif
+#ifndef LINK_LANGUAGE_IS_CXX
+#error Expected LINK_LANGUAGE_IS_CXX
+#endif
+
+#ifdef LINK_C_DEFINE
+#error Unexpected LINK_C_DEFINE
+#endif
+#ifdef LINK_LANGUAGE_IS_C
+#error Unexpected LINK_LANGUAGE_IS_C
+#endif
+
+#ifndef C_EXECUTABLE_LINK_LANGUAGE_IS_C
+#error Expected C_EXECUTABLE_LINK_LANGUAGE_IS_C define
+#endif
+
+void someFunc(void)
+{
+
+}
diff --git a/Tests/CompileDefinitions/compiletest_mixed_cxx.cpp b/Tests/CompileDefinitions/compiletest_mixed_cxx.cpp
new file mode 100644
index 0000000000..ae6befc5f0
--- /dev/null
+++ b/Tests/CompileDefinitions/compiletest_mixed_cxx.cpp
@@ -0,0 +1,23 @@
+
+#ifndef LINK_CXX_DEFINE
+#error Expected LINK_CXX_DEFINE
+#endif
+#ifndef LINK_LANGUAGE_IS_CXX
+#error Expected LINK_LANGUAGE_IS_CXX
+#endif
+
+#ifdef LINK_C_DEFINE
+#error Unexpected LINK_C_DEFINE
+#endif
+#ifdef LINK_LANGUAGE_IS_C
+#error Unexpected LINK_LANGUAGE_IS_C
+#endif
+
+#ifndef C_EXECUTABLE_LINK_LANGUAGE_IS_C
+#error Expected C_EXECUTABLE_LINK_LANGUAGE_IS_C define
+#endif
+
+int main(int argc, char **argv)
+{
+ return 0;
+}
diff --git a/Tests/CompileDefinitions/runtest.c b/Tests/CompileDefinitions/runtest.c
new file mode 100644
index 0000000000..02d2cadb0c
--- /dev/null
+++ b/Tests/CompileDefinitions/runtest.c
@@ -0,0 +1,47 @@
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#ifndef BUILD_CONFIG_NAME
+# error "BUILD_CONFIG_NAME not defined!"
+#endif
+
+int main()
+{
+ char build_config_name[] = BUILD_CONFIG_NAME;
+ char* c;
+ for(c = build_config_name; *c; ++c)
+ {
+ *c = (char)tolower((int)*c);
+ }
+ fprintf(stderr, "build_config_name=\"%s\"\n", build_config_name);
+#ifdef TEST_CONFIG_DEBUG
+ if(strcmp(build_config_name, "debug") != 0)
+ {
+ fprintf(stderr, "build_config_name is not \"debug\"\n");
+ return 1;
+ }
+#endif
+#ifdef TEST_CONFIG_RELEASE
+ if(strcmp(build_config_name, "release") != 0)
+ {
+ fprintf(stderr, "build_config_name is not \"release\"\n");
+ return 1;
+ }
+#endif
+#ifdef TEST_CONFIG_MINSIZEREL
+ if(strcmp(build_config_name, "minsizerel") != 0)
+ {
+ fprintf(stderr, "build_config_name is not \"minsizerel\"\n");
+ return 1;
+ }
+#endif
+#ifdef TEST_CONFIG_RELWITHDEBINFO
+ if(strcmp(build_config_name, "relwithdebinfo") != 0)
+ {
+ fprintf(stderr, "build_config_name is not \"relwithdebinfo\"\n");
+ return 1;
+ }
+#endif
+ return 0;
+}
diff --git a/Tests/CompileDefinitions/target_prop/CMakeLists.txt b/Tests/CompileDefinitions/target_prop/CMakeLists.txt
new file mode 100644
index 0000000000..311975ce52
--- /dev/null
+++ b/Tests/CompileDefinitions/target_prop/CMakeLists.txt
@@ -0,0 +1,60 @@
+
+project(target_prop)
+
+add_executable(target_prop_executable ../compiletest.cpp)
+
+set_target_properties(target_prop_executable PROPERTIES COMPILE_DEFINITIONS CMAKE_IS_FUN)
+
+if (NOT NO_SPACES_IN_DEFINE_VALUES)
+ set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_IS_REALLY="Very Fun" CMAKE_IS=Fun)
+else()
+ set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_IS=Fun)
+endif()
+set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_IS_FUN CMAKE_IS_="Fun")
+
+set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS
+ TEST_GENERATOR_EXPRESSIONS
+ "$<1:CMAKE_IS_DECLARATIVE>"
+ "$<0:GE_NOT_DEFINED>"
+ "$<1:ARGUMENT;LIST>"
+ PREFIX_$<JOIN:DEF1;DEF2,;PREFIX_>
+ LETTER_LIST1=\"$<JOIN:A;B;C;D,,>\"
+ LETTER_LIST2=\"$<JOIN:A;B;C;D,,,>\"
+ LETTER_LIST3=\"$<JOIN:A;B;C;D,,->\"
+ LETTER_LIST4=\"$<JOIN:A;B;C;D,-,->\"
+ LETTER_LIST5=\"$<JOIN:A;B;C;D,-,>\"
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:LINK_CXX_DEFINE>"
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:LINK_C_DEFINE>"
+ "LINK_LANGUAGE_IS_$<TARGET_PROPERTY:LINKER_LANGUAGE>"
+)
+
+set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS
+ BUILD_IS_DEBUG=$<CONFIG:Debug>
+ BUILD_IS_NOT_DEBUG=$<NOT:$<CONFIG:Debug>>
+ )
+
+add_executable(target_prop_c_executable ../compiletest.c)
+
+cmake_policy(SET CMP0043 NEW)
+set_property(TARGET target_prop_c_executable APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG_MODE)
+
+set_property(TARGET target_prop_c_executable APPEND PROPERTY COMPILE_DEFINITIONS
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:LINK_CXX_DEFINE>"
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:LINK_C_DEFINE>"
+ "LINK_LANGUAGE_IS_$<TARGET_PROPERTY:LINKER_LANGUAGE>"
+ )
+
+# Resulting link language will be CXX
+add_executable(target_prop_mixed_executable ../compiletest_mixed_c.c ../compiletest_mixed_cxx.cpp)
+
+set_property(TARGET target_prop_mixed_executable APPEND PROPERTY COMPILE_DEFINITIONS
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:LINK_CXX_DEFINE>"
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:LINK_C_DEFINE>"
+ "LINK_LANGUAGE_IS_$<TARGET_PROPERTY:LINKER_LANGUAGE>"
+ "C_EXECUTABLE_LINK_LANGUAGE_IS_$<TARGET_PROPERTY:target_prop_c_executable,LINKER_LANGUAGE>"
+ )
+
+add_library(tgt STATIC IMPORTED)
+set_property(TARGET tgt APPEND PROPERTY COMPILE_DEFINITIONS TGT_DEF TGT_TYPE_$<TARGET_PROPERTY:TYPE>)
+add_executable(usetgt usetgt.c)
+target_compile_definitions(usetgt PRIVATE $<TARGET_PROPERTY:tgt,COMPILE_DEFINITIONS>)
diff --git a/Tests/CompileDefinitions/target_prop/usetgt.c b/Tests/CompileDefinitions/target_prop/usetgt.c
new file mode 100644
index 0000000000..6672a3e8f7
--- /dev/null
+++ b/Tests/CompileDefinitions/target_prop/usetgt.c
@@ -0,0 +1,10 @@
+#ifndef TGT_DEF
+# error TGT_DEF incorrectly not defined
+#endif
+#ifndef TGT_TYPE_STATIC_LIBRARY
+# error TGT_TYPE_STATIC_LIBRARY incorrectly not defined
+#endif
+#ifdef TGT_TYPE_EXECUTABLE
+# error TGT_TYPE_EXECUTABLE incorrectly defined
+#endif
+int main(void) { return 0; }
diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt
new file mode 100644
index 0000000000..d02ddaf206
--- /dev/null
+++ b/Tests/CompileFeatures/CMakeLists.txt
@@ -0,0 +1,112 @@
+
+cmake_minimum_required(VERSION 3.0)
+
+project(CompileFeatures)
+
+if (NOT CMAKE_C_COMPILE_FEATURES AND NOT CMAKE_CXX_COMPILE_FEATURES)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp"
+ "int main(int,char**) { return 0; }\n"
+ )
+ add_executable(CompileFeatures "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp")
+ return()
+endif()
+
+macro(run_test feature lang)
+ if (";${CMAKE_${lang}_COMPILE_FEATURES};" MATCHES ${feature})
+ add_library(test_${feature} OBJECT ${feature})
+ set_property(TARGET test_${feature}
+ PROPERTY COMPILE_FEATURES "${feature}"
+ )
+ else()
+ list(APPEND ${lang}_non_features ${feature})
+ endif()
+endmacro()
+
+get_property(c_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES)
+foreach(feature ${c_features})
+ run_test(${feature} C)
+endforeach()
+get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
+foreach(feature ${cxx_features})
+ run_test(${feature} CXX)
+endforeach()
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL GNU
+ AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
+ list(REMOVE_ITEM CXX_non_features
+ cxx_alignof
+ )
+endif()
+if (CMAKE_CXX_COMPILER_ID STREQUAL GNU
+ AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
+ # GNU prior to 4.9 does not set any preprocessor define to distinguish
+ # c++1y from c++11, so CMake does not support c++1y features before GNU 4.9.
+ list(REMOVE_ITEM CXX_non_features
+ # GNU 4.8 knows cxx_attributes, but doesn't know [[deprecated]]
+ # and warns that it is unknown and ignored.
+ cxx_attribute_deprecated
+ cxx_binary_literals
+ cxx_lambda_init_captures
+ cxx_return_type_deduction
+ )
+endif()
+
+set(C_ext c)
+set(C_standard_flag 11)
+set(CXX_ext cpp)
+set(CXX_standard_flag 14)
+foreach(lang CXX C)
+ if (CMAKE_${lang}_COMPILE_FEATURES)
+ foreach(feature ${${lang}_non_features})
+ message("Testing feature : ${feature}")
+ try_compile(${feature}_works
+ "${CMAKE_CURRENT_BINARY_DIR}/${feature}_test"
+ "${CMAKE_CURRENT_SOURCE_DIR}/feature_test.${${lang}_ext}"
+ COMPILE_DEFINITIONS "-DTEST=${CMAKE_CURRENT_SOURCE_DIR}/${feature}.${${lang}_ext}"
+ CMAKE_FLAGS "-DCMAKE_${lang}_STANDARD=${${lang}_standard_flag}"
+ OUTPUT_VARIABLE OUTPUT
+ )
+ if (${feature}_works)
+ message(SEND_ERROR
+ "Feature ${feature} expected not to work for ${lang} ${CMAKE_${lang}_COMPILER_ID}-${CMAKE_${lang}_COMPILER_VERSION}.
+ Update the supported features or blacklist it.\n${OUTPUT}")
+ else()
+ message("Testing feature : ${feature} -- Fails, as expected.")
+ endif()
+ endforeach()
+ endif()
+endforeach()
+
+add_executable(CompileFeatures main.cpp)
+set_property(TARGET CompileFeatures
+ PROPERTY COMPILE_FEATURES "cxx_auto_type"
+)
+set_property(TARGET CompileFeatures
+ PROPERTY CXX_STANDARD_REQUIRED TRUE
+)
+
+add_executable(GenexCompileFeatures main.cpp)
+set_property(TARGET GenexCompileFeatures
+ PROPERTY COMPILE_FEATURES "$<1:cxx_auto_type>;$<0:not_a_feature>"
+)
+
+add_library(iface INTERFACE)
+set_property(TARGET iface
+ PROPERTY INTERFACE_COMPILE_FEATURES "cxx_auto_type"
+)
+add_executable(IfaceCompileFeatures main.cpp)
+target_link_libraries(IfaceCompileFeatures iface)
+
+add_executable(CompileFeaturesGenex genex_test.cpp)
+set_property(TARGET CompileFeaturesGenex PROPERTY CXX_STANDARD 11)
+target_compile_definitions(CompileFeaturesGenex PRIVATE HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>)
+
+add_executable(CompileFeaturesGenex2 genex_test.cpp)
+target_compile_features(CompileFeaturesGenex2 PRIVATE cxx_constexpr)
+target_compile_definitions(CompileFeaturesGenex2 PRIVATE HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>)
+
+add_library(noexcept_iface INTERFACE)
+target_compile_features(noexcept_iface INTERFACE cxx_noexcept)
+add_executable(CompileFeaturesGenex3 genex_test.cpp)
+target_link_libraries(CompileFeaturesGenex3 PRIVATE noexcept_iface)
+target_compile_definitions(CompileFeaturesGenex3 PRIVATE HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>)
diff --git a/Tests/CompileFeatures/c_function_prototypes.c b/Tests/CompileFeatures/c_function_prototypes.c
new file mode 100644
index 0000000000..ab3c948874
--- /dev/null
+++ b/Tests/CompileFeatures/c_function_prototypes.c
@@ -0,0 +1,9 @@
+
+int someFunc(int a, int b);
+
+int someFunc(int a, int b)
+{
+ (void)a;
+ (void)b;
+ return 0;
+}
diff --git a/Tests/CompileFeatures/c_restrict.c b/Tests/CompileFeatures/c_restrict.c
new file mode 100644
index 0000000000..7bc7566586
--- /dev/null
+++ b/Tests/CompileFeatures/c_restrict.c
@@ -0,0 +1,7 @@
+
+int f (int * restrict a, int * restrict b)
+{
+ (void)a;
+ (void)b;
+ return 0;
+}
diff --git a/Tests/CompileFeatures/c_static_assert.c b/Tests/CompileFeatures/c_static_assert.c
new file mode 100644
index 0000000000..afab504184
--- /dev/null
+++ b/Tests/CompileFeatures/c_static_assert.c
@@ -0,0 +1,2 @@
+
+_Static_assert(1, "Static assert test");
diff --git a/Tests/CompileFeatures/c_variadic_macros.c b/Tests/CompileFeatures/c_variadic_macros.c
new file mode 100644
index 0000000000..4da111e628
--- /dev/null
+++ b/Tests/CompileFeatures/c_variadic_macros.c
@@ -0,0 +1,15 @@
+
+int someFunc(int i1, char c, int i2)
+{
+ (void)i1;
+ (void)c;
+ (void)i2;
+ return 0;
+}
+
+#define FUNC_WRAPPER(...) someFunc(__VA_ARGS__)
+
+void otherFunc()
+{
+ FUNC_WRAPPER(42, 'a', 7);
+}
diff --git a/Tests/CompileFeatures/cxx_aggregate_default_initializers.cpp b/Tests/CompileFeatures/cxx_aggregate_default_initializers.cpp
new file mode 100644
index 0000000000..63a3713cf9
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_aggregate_default_initializers.cpp
@@ -0,0 +1,9 @@
+
+struct X { int i, j, k = 42; };
+
+int someFunc()
+{
+ X a[] = { 1, 2, 3, 4, 5, 6 };
+ X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
+ return a[0].k == b[0].k && a[1].k == b[1].k ? 0 : 1;
+}
diff --git a/Tests/CompileFeatures/cxx_alias_templates.cpp b/Tests/CompileFeatures/cxx_alias_templates.cpp
new file mode 100644
index 0000000000..a47e27ded2
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_alias_templates.cpp
@@ -0,0 +1,11 @@
+
+template <typename T1, typename T2>
+struct A
+{
+ typedef T1 MyT1;
+ using MyT2 = T2;
+};
+
+using B = A<int, char>;
+template<typename T>
+using C = A<int, T>;
diff --git a/Tests/CompileFeatures/cxx_alignas.cpp b/Tests/CompileFeatures/cxx_alignas.cpp
new file mode 100644
index 0000000000..35b7c8294d
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_alignas.cpp
@@ -0,0 +1,4 @@
+
+struct S1 {
+ alignas(8) int n;
+};
diff --git a/Tests/CompileFeatures/cxx_alignof.cpp b/Tests/CompileFeatures/cxx_alignof.cpp
new file mode 100644
index 0000000000..63b14fec96
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_alignof.cpp
@@ -0,0 +1,5 @@
+
+int someFunc()
+{
+ return alignof(int);
+}
diff --git a/Tests/CompileFeatures/cxx_attribute_deprecated.cpp b/Tests/CompileFeatures/cxx_attribute_deprecated.cpp
new file mode 100644
index 0000000000..b6f307d9e9
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_attribute_deprecated.cpp
@@ -0,0 +1,11 @@
+
+[[deprecated]]
+int foo()
+{
+ return 0;
+}
+
+int someFunc()
+{
+ return foo();
+}
diff --git a/Tests/CompileFeatures/cxx_attributes.cpp b/Tests/CompileFeatures/cxx_attributes.cpp
new file mode 100644
index 0000000000..a3c89eaba1
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_attributes.cpp
@@ -0,0 +1,2 @@
+
+void unusedFunc [[noreturn]] () { throw 1; }
diff --git a/Tests/CompileFeatures/cxx_auto_type.cpp b/Tests/CompileFeatures/cxx_auto_type.cpp
new file mode 100644
index 0000000000..7dbf04f678
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_auto_type.cpp
@@ -0,0 +1,5 @@
+
+void someFunc()
+{
+ auto x = 3.14;
+}
diff --git a/Tests/CompileFeatures/cxx_binary_literals.cpp b/Tests/CompileFeatures/cxx_binary_literals.cpp
new file mode 100644
index 0000000000..14a9e7523e
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_binary_literals.cpp
@@ -0,0 +1,6 @@
+
+int someFunc()
+{
+ int i = 0b101;
+ return i - 5;
+}
diff --git a/Tests/CompileFeatures/cxx_constexpr.cpp b/Tests/CompileFeatures/cxx_constexpr.cpp
new file mode 100644
index 0000000000..570c10fb9b
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_constexpr.cpp
@@ -0,0 +1,5 @@
+
+constexpr int getNum()
+{
+ return 42;
+}
diff --git a/Tests/CompileFeatures/cxx_contextual_conversions.cpp b/Tests/CompileFeatures/cxx_contextual_conversions.cpp
new file mode 100644
index 0000000000..34386246d7
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_contextual_conversions.cpp
@@ -0,0 +1,33 @@
+
+#define assert(E) if(!(E)) return 1;
+
+template<class T>
+class zero_init
+{
+public:
+ zero_init( )
+ : val( static_cast<T>(0) ) { }
+ zero_init( T val ) : val( val )
+ { }
+ operator T & ( ) { return val; }
+ operator T ( ) const { return val; }
+private:
+ T val;
+};
+
+int someFunc()
+{
+ zero_init<int*> p; assert( p == 0 );
+ p = new int(7);
+ assert( *p == 7 );
+ delete p;
+
+ zero_init<int> i; assert( i == 0 );
+ i = 7;
+ assert( i == 7 );
+ switch( i ) { }
+
+ int *vp = new int[i];
+
+ return 0;
+}
diff --git a/Tests/CompileFeatures/cxx_decltype.cpp b/Tests/CompileFeatures/cxx_decltype.cpp
new file mode 100644
index 0000000000..24ec51e845
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_decltype.cpp
@@ -0,0 +1,7 @@
+
+int someFunc()
+{
+ int i = 0;
+ decltype(i) other = 0;
+ return other;
+}
diff --git a/Tests/CompileFeatures/cxx_decltype_auto.cpp b/Tests/CompileFeatures/cxx_decltype_auto.cpp
new file mode 100644
index 0000000000..900bb6d799
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_decltype_auto.cpp
@@ -0,0 +1,6 @@
+
+int someFunc(int argc, char**)
+{
+ decltype(auto) i = argc;
+ return 0;
+}
diff --git a/Tests/CompileFeatures/cxx_decltype_incomplete_return_types.cpp b/Tests/CompileFeatures/cxx_decltype_incomplete_return_types.cpp
new file mode 100644
index 0000000000..109d0384c4
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_decltype_incomplete_return_types.cpp
@@ -0,0 +1,14 @@
+
+template<class T>
+struct A
+{
+ ~A() = delete;
+};
+
+template<class T> auto h() -> A<T>;
+template<class T> auto i(T) -> T;
+template<class T> auto f(T) -> decltype(i(h<T>()));
+template<class T> auto f(T) -> void;
+auto g() -> void {
+ f(42);
+}
diff --git a/Tests/CompileFeatures/cxx_default_function_template_args.cpp b/Tests/CompileFeatures/cxx_default_function_template_args.cpp
new file mode 100644
index 0000000000..3d14c52ca5
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_default_function_template_args.cpp
@@ -0,0 +1,12 @@
+
+template<typename T = int>
+int someFunc()
+{
+ T t = 0;
+ return t;
+}
+
+void otherFunc()
+{
+ someFunc();
+}
diff --git a/Tests/CompileFeatures/cxx_defaulted_functions.cpp b/Tests/CompileFeatures/cxx_defaulted_functions.cpp
new file mode 100644
index 0000000000..b679a92699
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_defaulted_functions.cpp
@@ -0,0 +1,9 @@
+
+struct A {
+ A() = default;
+};
+
+void someFunc()
+{
+ A a;
+}
diff --git a/Tests/CompileFeatures/cxx_defaulted_move_initializers.cpp b/Tests/CompileFeatures/cxx_defaulted_move_initializers.cpp
new file mode 100644
index 0000000000..14f987147a
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_defaulted_move_initializers.cpp
@@ -0,0 +1,7 @@
+
+struct A
+{
+ A() = default;
+ A& operator=(A&&) = default;
+ A(A&&) = default;
+};
diff --git a/Tests/CompileFeatures/cxx_delegating_constructors.cpp b/Tests/CompileFeatures/cxx_delegating_constructors.cpp
new file mode 100644
index 0000000000..4b41615b97
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_delegating_constructors.cpp
@@ -0,0 +1,15 @@
+
+class Foo
+{
+public:
+ Foo(int i);
+
+ Foo(double d)
+ : Foo(static_cast<int>(d))
+ {
+
+ }
+
+private:
+ int m_i;
+};
diff --git a/Tests/CompileFeatures/cxx_deleted_functions.cpp b/Tests/CompileFeatures/cxx_deleted_functions.cpp
new file mode 100644
index 0000000000..4ecb1e9d5e
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_deleted_functions.cpp
@@ -0,0 +1,6 @@
+
+struct A
+{
+ A(const A&) = delete;
+ A& operator=(const A&) = delete;
+};
diff --git a/Tests/CompileFeatures/cxx_digit_separators.cpp b/Tests/CompileFeatures/cxx_digit_separators.cpp
new file mode 100644
index 0000000000..abcd1c8fa6
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_digit_separators.cpp
@@ -0,0 +1,6 @@
+
+int someFunc()
+{
+ int one_thousand = 1'000;
+ return one_thousand - 1000;
+}
diff --git a/Tests/CompileFeatures/cxx_enum_forward_declarations.cpp b/Tests/CompileFeatures/cxx_enum_forward_declarations.cpp
new file mode 100644
index 0000000000..a7e1445379
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_enum_forward_declarations.cpp
@@ -0,0 +1,8 @@
+
+enum SomeEnum : short;
+
+void someFunc()
+{
+ SomeEnum value;
+ int i = value;
+}
diff --git a/Tests/CompileFeatures/cxx_explicit_conversions.cpp b/Tests/CompileFeatures/cxx_explicit_conversions.cpp
new file mode 100644
index 0000000000..0decdcd43a
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_explicit_conversions.cpp
@@ -0,0 +1,10 @@
+
+class A
+{
+ int m_i;
+public:
+ explicit operator bool()
+ {
+ return m_i != 0;
+ }
+};
diff --git a/Tests/CompileFeatures/cxx_extended_friend_declarations.cpp b/Tests/CompileFeatures/cxx_extended_friend_declarations.cpp
new file mode 100644
index 0000000000..631c699a9a
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_extended_friend_declarations.cpp
@@ -0,0 +1,25 @@
+
+template <typename T>
+struct B
+{
+ B() : m_i(42) {}
+private:
+ int m_i;
+ friend T;
+};
+
+struct A
+{
+ template<typename T>
+ int getBValue(B<T> b)
+ {
+ return b.m_i;
+ }
+};
+
+void someFunc()
+{
+ A a;
+ B<A> b;
+ a.getBValue(b);
+}
diff --git a/Tests/CompileFeatures/cxx_extern_templates.cpp b/Tests/CompileFeatures/cxx_extern_templates.cpp
new file mode 100644
index 0000000000..9fa4aa4cc0
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_extern_templates.cpp
@@ -0,0 +1,12 @@
+
+template<typename T>
+void someFunc()
+{
+}
+
+extern template void someFunc<int>();
+
+void otherFunc()
+{
+ someFunc<int>();
+}
diff --git a/Tests/CompileFeatures/cxx_final.cpp b/Tests/CompileFeatures/cxx_final.cpp
new file mode 100644
index 0000000000..598cb943f4
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_final.cpp
@@ -0,0 +1,2 @@
+
+struct A final {};
diff --git a/Tests/CompileFeatures/cxx_func_identifier.cpp b/Tests/CompileFeatures/cxx_func_identifier.cpp
new file mode 100644
index 0000000000..0c3595ceef
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_func_identifier.cpp
@@ -0,0 +1,6 @@
+
+void someFunc()
+{
+ bool b = sizeof(__func__);
+ (void)b;
+}
diff --git a/Tests/CompileFeatures/cxx_generalized_initializers.cpp b/Tests/CompileFeatures/cxx_generalized_initializers.cpp
new file mode 100644
index 0000000000..8013ef5c2d
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_generalized_initializers.cpp
@@ -0,0 +1,23 @@
+
+// Dummy implementation. Test only the compiler feature.
+namespace std {
+ typedef decltype(sizeof(int)) size_t;
+ template <class _E>
+ class initializer_list
+ {
+ const _E* __begin_;
+ size_t __size_;
+
+ };
+}
+
+template <typename T>
+struct A
+{
+ A(std::initializer_list<T>) {}
+};
+
+void someFunc()
+{
+ A<int> as = { 1, 2, 3, 4 };
+}
diff --git a/Tests/CompileFeatures/cxx_generic_lambdas.cpp b/Tests/CompileFeatures/cxx_generic_lambdas.cpp
new file mode 100644
index 0000000000..ae1b78edd8
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_generic_lambdas.cpp
@@ -0,0 +1,6 @@
+
+int someFunc()
+{
+ auto identity = [](auto a) { return a; };
+ return identity(0);
+}
diff --git a/Tests/CompileFeatures/cxx_inheriting_constructors.cpp b/Tests/CompileFeatures/cxx_inheriting_constructors.cpp
new file mode 100644
index 0000000000..a83b624ca1
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_inheriting_constructors.cpp
@@ -0,0 +1,18 @@
+
+struct A
+{
+ int m_i;
+
+ A(int i) : m_i(i) {}
+};
+
+struct B : public A
+{
+ using A::A;
+};
+
+void someFunc()
+{
+ int i;
+ B b(i);
+}
diff --git a/Tests/CompileFeatures/cxx_inline_namespaces.cpp b/Tests/CompileFeatures/cxx_inline_namespaces.cpp
new file mode 100644
index 0000000000..59fa9c8f52
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_inline_namespaces.cpp
@@ -0,0 +1,26 @@
+namespace Lib
+{
+inline namespace Lib_1
+{
+ template <typename T> class A;
+}
+
+template <typename T> void g(T);
+}
+
+struct MyClass {
+
+};
+namespace Lib
+{
+template<>
+class A<MyClass> {
+
+};
+}
+
+void someFunc()
+{
+ Lib::A<MyClass> a;
+ g(a); // ok, Lib is an associated namespace of A
+}
diff --git a/Tests/CompileFeatures/cxx_lambda_init_captures.cpp b/Tests/CompileFeatures/cxx_lambda_init_captures.cpp
new file mode 100644
index 0000000000..7e337faf41
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_lambda_init_captures.cpp
@@ -0,0 +1,6 @@
+
+int someFunc()
+{
+ int a = 0;
+ return [b = static_cast<int&&>(a)]() { return b; }();
+}
diff --git a/Tests/CompileFeatures/cxx_lambdas.cpp b/Tests/CompileFeatures/cxx_lambdas.cpp
new file mode 100644
index 0000000000..eecaa23a31
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_lambdas.cpp
@@ -0,0 +1,5 @@
+
+void someFunc()
+{
+ [](){}();
+}
diff --git a/Tests/CompileFeatures/cxx_local_type_template_args.cpp b/Tests/CompileFeatures/cxx_local_type_template_args.cpp
new file mode 100644
index 0000000000..802ea7a0ad
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_local_type_template_args.cpp
@@ -0,0 +1,21 @@
+
+template <typename T>
+class X { };
+template <typename T>
+void f(T t) { }
+struct {} unnamed_obj;
+void f() {
+ struct A { };
+ enum { e1 };
+ typedef struct {} B;
+ B b;
+ X<A> x1;
+ X<A*> x2;
+ X<B> x3;
+ f(e1);
+ f(unnamed_obj);
+ f(b);
+ (void)x1;
+ (void)x2;
+ (void)x3;
+}
diff --git a/Tests/CompileFeatures/cxx_long_long_type.cpp b/Tests/CompileFeatures/cxx_long_long_type.cpp
new file mode 100644
index 0000000000..670324c4a9
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_long_long_type.cpp
@@ -0,0 +1,5 @@
+
+void someFunc()
+{
+ long long ll = 9223372036854775807LL;
+}
diff --git a/Tests/CompileFeatures/cxx_noexcept.cpp b/Tests/CompileFeatures/cxx_noexcept.cpp
new file mode 100644
index 0000000000..a3c05b86a4
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_noexcept.cpp
@@ -0,0 +1,5 @@
+
+void someFunc() noexcept
+{
+
+}
diff --git a/Tests/CompileFeatures/cxx_nonstatic_member_init.cpp b/Tests/CompileFeatures/cxx_nonstatic_member_init.cpp
new file mode 100644
index 0000000000..6b7fa7098a
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_nonstatic_member_init.cpp
@@ -0,0 +1,4 @@
+class A
+{
+ int m_i = 42;
+};
diff --git a/Tests/CompileFeatures/cxx_nullptr.cpp b/Tests/CompileFeatures/cxx_nullptr.cpp
new file mode 100644
index 0000000000..96307dfc6a
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_nullptr.cpp
@@ -0,0 +1,10 @@
+
+void someFunc(int*)
+{
+
+}
+
+void otherFunc()
+{
+ someFunc(nullptr);
+}
diff --git a/Tests/CompileFeatures/cxx_override.cpp b/Tests/CompileFeatures/cxx_override.cpp
new file mode 100644
index 0000000000..55bec1389a
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_override.cpp
@@ -0,0 +1,7 @@
+
+struct A {
+ virtual void doNothing() {}
+};
+struct B : A {
+ void doNothing() override {}
+};
diff --git a/Tests/CompileFeatures/cxx_range_for.cpp b/Tests/CompileFeatures/cxx_range_for.cpp
new file mode 100644
index 0000000000..892109e901
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_range_for.cpp
@@ -0,0 +1,10 @@
+
+void someFunc()
+{
+ int accumulated = 0;
+ int numbers[] = { 1, 2, 5 };
+ for (int i : numbers)
+ {
+ accumulated += i;
+ }
+}
diff --git a/Tests/CompileFeatures/cxx_raw_string_literals.cpp b/Tests/CompileFeatures/cxx_raw_string_literals.cpp
new file mode 100644
index 0000000000..ea4d2312c6
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_raw_string_literals.cpp
@@ -0,0 +1,7 @@
+
+void someFunc()
+{
+const char p[] = R"(a\
+b
+c)";
+}
diff --git a/Tests/CompileFeatures/cxx_reference_qualified_functions.cpp b/Tests/CompileFeatures/cxx_reference_qualified_functions.cpp
new file mode 100644
index 0000000000..83a2361a40
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_reference_qualified_functions.cpp
@@ -0,0 +1,11 @@
+
+struct test{
+ void f() & { }
+ void f() && { }
+};
+
+void someFunc(){
+ test t;
+ t.f(); // lvalue
+ test().f(); // rvalue
+}
diff --git a/Tests/CompileFeatures/cxx_relaxed_constexpr.cpp b/Tests/CompileFeatures/cxx_relaxed_constexpr.cpp
new file mode 100644
index 0000000000..bce82e32ac
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_relaxed_constexpr.cpp
@@ -0,0 +1,23 @@
+
+struct X {
+ constexpr X() : n(5) {
+ n *= 2;
+ }
+ int n;
+};
+
+constexpr int g(const int (&is)[4]) {
+ X x;
+ int r = x.n;
+ for (int i = 0; i < 5; ++i)
+ r += i;
+ for (auto& i : is)
+ r += i;
+ return r;
+}
+
+int someFunc()
+{
+ constexpr int k3 = g({ 4, 5, 6, 7 });
+ return k3 - 42;
+}
diff --git a/Tests/CompileFeatures/cxx_return_type_deduction.cpp b/Tests/CompileFeatures/cxx_return_type_deduction.cpp
new file mode 100644
index 0000000000..009e919277
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_return_type_deduction.cpp
@@ -0,0 +1,10 @@
+
+auto sum(int a, int b)
+{
+ return a+b;
+}
+
+int someFunc()
+{
+ return sum(3, -3);
+}
diff --git a/Tests/CompileFeatures/cxx_right_angle_brackets.cpp b/Tests/CompileFeatures/cxx_right_angle_brackets.cpp
new file mode 100644
index 0000000000..2713fd8d0e
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_right_angle_brackets.cpp
@@ -0,0 +1,12 @@
+
+template<typename T>
+struct A
+{
+ typedef T Result;
+};
+
+void someFunc()
+{
+ A<A<int>> object;
+ (void)object;
+}
diff --git a/Tests/CompileFeatures/cxx_rvalue_references.cpp b/Tests/CompileFeatures/cxx_rvalue_references.cpp
new file mode 100644
index 0000000000..787026a21c
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_rvalue_references.cpp
@@ -0,0 +1,5 @@
+
+void someFunc(int&&)
+{
+
+}
diff --git a/Tests/CompileFeatures/cxx_sizeof_member.cpp b/Tests/CompileFeatures/cxx_sizeof_member.cpp
new file mode 100644
index 0000000000..ae143d26f4
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_sizeof_member.cpp
@@ -0,0 +1,10 @@
+
+struct A
+{
+ int m_i;
+};
+
+int someFunc()
+{
+ return sizeof(A::m_i) > 0 ? 1 : 2;
+}
diff --git a/Tests/CompileFeatures/cxx_static_assert.cpp b/Tests/CompileFeatures/cxx_static_assert.cpp
new file mode 100644
index 0000000000..6aa8678f6c
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_static_assert.cpp
@@ -0,0 +1,2 @@
+
+static_assert(true, "static_assert test");
diff --git a/Tests/CompileFeatures/cxx_strong_enums.cpp b/Tests/CompileFeatures/cxx_strong_enums.cpp
new file mode 100644
index 0000000000..6262456661
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_strong_enums.cpp
@@ -0,0 +1,7 @@
+
+enum class Colors
+{
+ RedColor,
+ GreenColor,
+ BlueColor
+};
diff --git a/Tests/CompileFeatures/cxx_template_template_parameters.cpp b/Tests/CompileFeatures/cxx_template_template_parameters.cpp
new file mode 100644
index 0000000000..0fdd18d928
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_template_template_parameters.cpp
@@ -0,0 +1,18 @@
+
+template<template <typename> class T, typename U>
+void someFunc(T<U>)
+{
+
+}
+
+template<typename T>
+struct A
+{
+
+};
+
+void otherFunc()
+{
+ A<int> a;
+ someFunc(a);
+}
diff --git a/Tests/CompileFeatures/cxx_thread_local.cpp b/Tests/CompileFeatures/cxx_thread_local.cpp
new file mode 100644
index 0000000000..1fb27e241e
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_thread_local.cpp
@@ -0,0 +1,2 @@
+
+thread_local unsigned int rage = 1;
diff --git a/Tests/CompileFeatures/cxx_trailing_return_types.cpp b/Tests/CompileFeatures/cxx_trailing_return_types.cpp
new file mode 100644
index 0000000000..01a76cbff2
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_trailing_return_types.cpp
@@ -0,0 +1,5 @@
+
+auto someFunc() -> int
+{
+ return 42;
+}
diff --git a/Tests/CompileFeatures/cxx_unicode_literals.cpp b/Tests/CompileFeatures/cxx_unicode_literals.cpp
new file mode 100644
index 0000000000..a7b7df0cd2
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_unicode_literals.cpp
@@ -0,0 +1,3 @@
+
+const char16_t lit_16[] = u"\u00DA";
+const char32_t lit_32[] = U"\u00DA";
diff --git a/Tests/CompileFeatures/cxx_uniform_initialization.cpp b/Tests/CompileFeatures/cxx_uniform_initialization.cpp
new file mode 100644
index 0000000000..82c76e20cb
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_uniform_initialization.cpp
@@ -0,0 +1,9 @@
+struct A {};
+struct B {
+ B(A) {}
+};
+
+void Func()
+{
+ B b{A{}};
+}
diff --git a/Tests/CompileFeatures/cxx_unrestricted_unions.cpp b/Tests/CompileFeatures/cxx_unrestricted_unions.cpp
new file mode 100644
index 0000000000..698fd61f96
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_unrestricted_unions.cpp
@@ -0,0 +1,11 @@
+
+struct point {
+ point() {}
+ point(int x, int y) : x_(x), y_(y) {}
+ int x_, y_;
+};
+union u {
+ point p_;
+ int i_;
+ const char* s_;
+};
diff --git a/Tests/CompileFeatures/cxx_user_literals.cpp b/Tests/CompileFeatures/cxx_user_literals.cpp
new file mode 100644
index 0000000000..9e5a5889ea
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_user_literals.cpp
@@ -0,0 +1,7 @@
+
+long double operator "" _meters(long double);
+
+void someFunc()
+{
+ long double i = 1.2_meters;
+}
diff --git a/Tests/CompileFeatures/cxx_variable_templates.cpp b/Tests/CompileFeatures/cxx_variable_templates.cpp
new file mode 100644
index 0000000000..5d4bdbc355
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_variable_templates.cpp
@@ -0,0 +1,10 @@
+
+template<typename T>
+constexpr T pi = T(3.1415926535897932385);
+
+int someFunc()
+{
+ auto pi_int = pi<int>;
+ auto pi_float = pi<float>;
+ return pi_int - 3;
+}
diff --git a/Tests/CompileFeatures/cxx_variadic_macros.cpp b/Tests/CompileFeatures/cxx_variadic_macros.cpp
new file mode 100644
index 0000000000..4d007a5362
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_variadic_macros.cpp
@@ -0,0 +1,12 @@
+
+int someFunc(int, char, int)
+{
+ return 0;
+}
+
+#define FUNC_WRAPPER(...) someFunc(__VA_ARGS__)
+
+void otherFunc()
+{
+ FUNC_WRAPPER(42, 'a', 7);
+}
diff --git a/Tests/CompileFeatures/cxx_variadic_templates.cpp b/Tests/CompileFeatures/cxx_variadic_templates.cpp
new file mode 100644
index 0000000000..1d5a7061b6
--- /dev/null
+++ b/Tests/CompileFeatures/cxx_variadic_templates.cpp
@@ -0,0 +1,65 @@
+template<int I, int... Is>
+struct Interface;
+
+template<int I>
+struct Interface<I>
+{
+ static int accumulate()
+ {
+ return I;
+ }
+};
+
+template<int I, int... Is>
+struct Interface
+{
+ static int accumulate()
+ {
+ return I + Interface<Is...>::accumulate();
+ }
+};
+
+// Note: split this into a separate test if a
+// cxx_variadic_template_template_parameters feature is added.
+
+template<typename T>
+struct eval {
+ enum {
+ Matched = 0
+ };
+};
+
+template<template<typename...> class T, typename... U>
+struct eval<T<U...> > {
+ enum {
+ Matched = 1
+ };
+};
+
+template<typename...>
+struct A {
+
+};
+template<typename T>
+struct B {
+
+};
+template<typename T, typename U>
+struct C {
+
+};
+template<typename T, typename U, typename...>
+struct D {
+
+};
+
+// Note: This test assumes that a compiler supporting this feature
+// supports static_assert. Add a workaround if that does not hold.
+static_assert(eval<A<> >::Matched, "A Matches");
+static_assert(eval<A<int> >::Matched, "A Matches");
+static_assert(eval<A<int, char> >::Matched, "A Matches");
+static_assert(eval<B<int> >::Matched, "B Matches");
+static_assert(eval<C<int, char> >::Matched, "C Matches");
+static_assert(eval<D<int, char> >::Matched, "D Matches");
+static_assert(eval<D<int, char, bool> >::Matched, "D Matches");
+static_assert(eval<D<int, char, bool, double> >::Matched, "D Matches");
diff --git a/Tests/CompileFeatures/feature_test.cpp b/Tests/CompileFeatures/feature_test.cpp
new file mode 100644
index 0000000000..4406c16e2c
--- /dev/null
+++ b/Tests/CompileFeatures/feature_test.cpp
@@ -0,0 +1,10 @@
+
+#define STRINGIFY_IMPL(X) #X
+#define STRINGIFY(X) STRINGIFY_IMPL(X)
+
+#include STRINGIFY(TEST)
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/CompileFeatures/genex_test.cpp b/Tests/CompileFeatures/genex_test.cpp
new file mode 100644
index 0000000000..ca38883564
--- /dev/null
+++ b/Tests/CompileFeatures/genex_test.cpp
@@ -0,0 +1,21 @@
+
+#if !HAVE_OVERRIDE_CONTROL
+#error "Expect override control feature"
+#else
+
+struct A
+{
+ virtual int getA() { return 7; }
+};
+
+struct B final : A
+{
+ int getA() override { return 42; }
+};
+
+#endif
+
+int main()
+{
+
+}
diff --git a/Tests/CompileFeatures/main.c b/Tests/CompileFeatures/main.c
new file mode 100644
index 0000000000..831c5eb275
--- /dev/null
+++ b/Tests/CompileFeatures/main.c
@@ -0,0 +1,12 @@
+
+int foo(int * restrict a, int * restrict b)
+{
+ (void)a;
+ (void)b;
+ return 0;
+}
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/CompileFeatures/main.cpp b/Tests/CompileFeatures/main.cpp
new file mode 100644
index 0000000000..3a8e0fcea3
--- /dev/null
+++ b/Tests/CompileFeatures/main.cpp
@@ -0,0 +1,6 @@
+
+int main(int,char**)
+{
+ auto value = 0;
+ return value;
+}
diff --git a/Tests/CompileOptions/CMakeLists.txt b/Tests/CompileOptions/CMakeLists.txt
new file mode 100644
index 0000000000..05a5f826fe
--- /dev/null
+++ b/Tests/CompileOptions/CMakeLists.txt
@@ -0,0 +1,44 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(CompileOptions)
+
+add_library(testlib other.cpp)
+
+add_executable(CompileOptions main.cpp)
+
+macro(get_compiler_test_genex lst lang)
+ list(APPEND ${lst} -DTEST_${lang}_COMPILER_VERSION="$<${lang}_COMPILER_VERSION>")
+ list(APPEND ${lst} -DTEST_${lang}_COMPILER_VERSION_EQUALITY=$<${lang}_COMPILER_VERSION:${CMAKE_${lang}_COMPILER_VERSION}>)
+endmacro()
+
+get_compiler_test_genex(c_tests C)
+get_compiler_test_genex(cxx_tests CXX)
+
+set_property(TARGET CompileOptions PROPERTY COMPILE_OPTIONS
+ "-DTEST_DEFINE"
+ "-DNEEDS_ESCAPE=\"E$CAPE\""
+ "$<$<CXX_COMPILER_ID:GNU>:-DTEST_DEFINE_GNU>"
+ ${c_tests}
+ ${cxx_tests}
+ )
+
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Borland")
+ set_property(TARGET CompileOptions APPEND PROPERTY COMPILE_OPTIONS
+ "-DTEST_OCTOTHORPE=\"#\""
+ )
+endif()
+
+target_link_libraries(CompileOptions testlib)
+
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ target_compile_definitions(CompileOptions
+ PRIVATE
+ "DO_GNU_TESTS"
+ )
+endif()
+
+target_compile_definitions(CompileOptions
+ PRIVATE
+ "EXPECTED_C_COMPILER_VERSION=\"${CMAKE_C_COMPILER_VERSION}\""
+ "EXPECTED_CXX_COMPILER_VERSION=\"${CMAKE_CXX_COMPILER_VERSION}\""
+)
diff --git a/Tests/CompileOptions/main.cpp b/Tests/CompileOptions/main.cpp
new file mode 100644
index 0000000000..f3c1355930
--- /dev/null
+++ b/Tests/CompileOptions/main.cpp
@@ -0,0 +1,27 @@
+#ifndef TEST_DEFINE
+# error Expected definition TEST_DEFINE
+#endif
+
+#ifndef NEEDS_ESCAPE
+# error Expected definition NEEDS_ESCAPE
+#endif
+
+#ifdef DO_GNU_TESTS
+# ifndef TEST_DEFINE_GNU
+# error Expected definition TEST_DEFINE_GNU
+# endif
+#endif
+
+#include <string.h>
+
+int main()
+{
+ return (strcmp(NEEDS_ESCAPE, "E$CAPE") == 0
+#ifdef TEST_OCTOTHORPE
+ && strcmp(TEST_OCTOTHORPE, "#") == 0
+#endif
+ && strcmp(EXPECTED_C_COMPILER_VERSION, TEST_C_COMPILER_VERSION) == 0
+ && strcmp(EXPECTED_CXX_COMPILER_VERSION, TEST_CXX_COMPILER_VERSION) == 0
+ && TEST_C_COMPILER_VERSION_EQUALITY == 1
+ && TEST_CXX_COMPILER_VERSION_EQUALITY == 1) ? 0 : 1;
+}
diff --git a/Tests/CompileOptions/other.cpp b/Tests/CompileOptions/other.cpp
new file mode 100644
index 0000000000..0e34375791
--- /dev/null
+++ b/Tests/CompileOptions/other.cpp
@@ -0,0 +1,5 @@
+
+void foo(void)
+{
+
+}
diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt
new file mode 100644
index 0000000000..5e5eead809
--- /dev/null
+++ b/Tests/Complex/CMakeLists.txt
@@ -0,0 +1,441 @@
+#
+# A more complex test case
+#
+cmake_minimum_required(VERSION 2.4)
+project (Complex)
+
+# Try setting a new policy. The IF test is for coverage.
+if(POLICY CMP0003)
+ cmake_policy(SET CMP0003 NEW)
+
+ cmake_policy(GET CMP0003 P3)
+ if(NOT "${P3}" STREQUAL "NEW")
+ message(FATAL_ERROR "cmake_policy(GET) did not report NEW!")
+ endif()
+endif()
+
+# It is not recommended to set a policy to OLD, but this test
+# covers the OLD behavior of some policies.
+foreach(p
+ CMP0029
+ CMP0032
+ CMP0033
+ CMP0034
+ CMP0043
+ CMP0050
+ )
+ if(POLICY ${p})
+ cmake_policy(SET ${p} OLD)
+ endif()
+endforeach()
+
+# Test building without per-rule echo lines in Makefiles.
+set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
+
+set(CPACK_SOURCE_IGNORE_FILES "~$;\\.cvsignore$;^C:/hoffman/My Builds/testcase.*/CVS/;^C:/hoffman/My Builds/testcase.*/\\.svn/;^C:/hoffman/My Builds/testcase.*/sweigart/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/eos2001/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_tables_new/;^C:/hoffman/My Builds/testcase/COPYING$;^C:/hoffman/My Builds/testcase/INSTALL$;^C:/hoffman/My Builds/testcase/Makefile$;^C:/hoffman/My Builds/testcase/Makefile\\.in$;^C:/hoffman/My Builds/testcase/.*\\.lo$;^C:/hoffman/My Builds/testcase/.*\\.la$;^C:/hoffman/My Builds/testcase/mkinstalldirs$;^C:/hoffman/My Builds/testcase/missing$;^C:/hoffman/My Builds/testcase/ltmain\\.sh$;^C:/hoffman/My Builds/testcase/libtool$;^C:/hoffman/My Builds/testcase/install-sh$;^C:/hoffman/My Builds/testcase/configure$;^C:/hoffman/My Builds/testcase/config\\.sub$;^C:/hoffman/My Builds/testcase/config\\.status$;^C:/hoffman/My Builds/testcase/config\\.log$;^C:/hoffman/My Builds/testcase/config\\.guess$;^C:/hoffman/My Builds/testcase/autom4te\\.cache$;^C:/hoffman/My Builds/testcase/aclocal\\.m4$;^C:/hoffman/My Builds/testcase/depcomp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10_corr$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_scvh$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.rgbtip\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.zahb\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.085\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.mem$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.tex\\.bak$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j16\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j26\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j36\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_JNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Jseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_KNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Kseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check34_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check35_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check36_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check43_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check44_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check45_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check46_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check47_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check48_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/Makefile$;^C:/hoffman/My Builds/testcase/www/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/.*\\.flc$;^C:/hoffman/My Builds/testcase/src/Makefile$;^C:/hoffman/My Builds/testcase/src/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/\\.deps$;^C:/hoffman/My Builds/testcase/src/\\.libs$;^C:/hoffman/My Builds/testcase/src/.*\\.la$;^C:/hoffman/My Builds/testcase/src/.*\\.lo$;^C:/hoffman/My Builds/testcase/src/make\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/statef.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_15$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_rel$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/hot_post_agb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgb_tip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/start_shellflash\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/white_dwarf\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/3order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/5order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/8order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check8_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check5_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effoo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/tc\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/include/Makefile\\.in$;^C:/hoffman/My Builds/testcase/include/Makefile$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/0\\.1\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_eos1a-eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_0\\.1\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_eos1a-eos1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/fort\\.91$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/oldversion_grid$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2005Ap&SS\\.298\\.\\.135S\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2007Ap&SS\\.307\\.\\.263C\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/astro-ph\\.9909168_eprint_submitted_to_High_Press\\.Res\\.16,331\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/statef_grid-newversion$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/old$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/make\\.out.*$;^C:/hoffman/My Builds/testcase/utils/.*\\.flc$;^C:/hoffman/My Builds/testcase/utils/Makefile$;^C:/hoffman/My Builds/testcase/utils/Makefile\\.in$;^C:/hoffman/My Builds/testcase/utils/\\.deps$;^C:/hoffman/My Builds/testcase/utils/\\.libs$;^C:/hoffman/My Builds/testcase/utils/.*\\.la$;^C:/hoffman/My Builds/testcase/utils/.*\\.lo$;^C:/hoffman/My Builds/testcase/utils/free_eos_test$;^C:/hoffman/My Builds/testcase/utils/test_rosenbrock$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check5\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check8\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_checknr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effoo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence_20070613$;^C:/hoffman/My Builds/testcase/www/eospaper/text$;^C:/hoffman/My Builds/testcase/www/eospaper/cassisi_book_fig$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.1\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/2\\.0\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.2\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.3\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.4\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.5\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.6\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/figures$;^C:/hoffman/My Builds/testcase/www/eospaper/old$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_JNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Jseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_KNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Kseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check34\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check35\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check36\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check44\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check45\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check46\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_1_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_2_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_linear_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_nr_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_series_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.1\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.3\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_linear\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_nr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.rgbtip\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.zahb\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.rgbtip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_linear$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_noexchange$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_nr$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/delta\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos1gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos2gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb_adjust/coulomb_adjust\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/rtc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/make\\.out.*$")
+
+#
+# Define a macro
+#
+macro(ASSERT value msg)
+ if (NOT ${value})
+ message ("Assertion failure:" ${msg} )
+ endif ()
+endmacro()
+
+# invoke the macro
+ASSERT(Complex_BINARY_DIR "The PROJECT command is broken")
+
+#
+# Define a var args macro, it must take two or four args
+#
+macro(TEST_ARGC value1 value2)
+ add_definitions(${value1} ${value2})
+ if (${ARGC} EQUAL 4)
+ add_definitions(${ARGV2} ${ARGV3})
+ endif ()
+endmacro()
+
+# invoke the macro
+TEST_ARGC(-DCMAKE_ARGV1 -DCMAKE_ARGV2 -DCMAKE_ARGV3 -DCMAKE_ARGV4)
+
+macro(TEST_VAR_ARG fa)
+ if("${ARGV}" STREQUAL "1;2;3")
+ message(STATUS "ARGV works")
+ else()
+ message(FATAL_ERROR "ARGV does not work; got \"${ARGV}\" instead of \"1;2;3\"")
+ endif()
+ if("${ARGN}" STREQUAL "2;3")
+ message(STATUS "ARGN works")
+ else()
+ message(FATAL_ERROR "ARGV does not work; got \"${ARGN}\" instead of \"2;3\"")
+ endif()
+endmacro()
+
+TEST_VAR_ARG(1 2 3)
+
+# Floating-point comparison test.
+if(2.4 LESS 2.4)
+ message(FATAL_ERROR "Failed: 2.4 LESS 2.4")
+endif()
+if(2.4 GREATER 2.4)
+ message(FATAL_ERROR "Failed: 2.4 GREATER 2.4")
+endif()
+if(NOT 2.4 EQUAL 2.4)
+ message(FATAL_ERROR "Failed: NOT 2.4 EQUAL 2.4")
+endif()
+
+if(CMAKE_SYSTEM MATCHES "OSF1-V")
+ if(NOT CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local -no_implicit_include ")
+ endif()
+endif()
+
+
+add_definitions(-DCMAKE_IS_FUN)
+add_definitions(-DCMAKE_IS_REALLY_FUN)
+set_property(DIRECTORY
+ PROPERTY COMPILE_DEFINITIONS_RELEASE
+ CMAKE_IS_FUN_IN_RELEASE_MODE
+ )
+set_property(DIRECTORY
+ PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO
+ CMAKE_IS_FUN_IN_RELEASE_MODE
+ )
+set_property(DIRECTORY
+ PROPERTY COMPILE_DEFINITIONS_MINSIZEREL
+ CMAKE_IS_FUN_IN_RELEASE_MODE
+ )
+
+set(TEST_SEP "a b c")
+separate_arguments(TEST_SEP)
+
+
+#
+# Include vars from a file and from a cache
+#
+if (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
+ include(${Complex_SOURCE_DIR}/VarTests.cmake)
+endif ()
+include(fileshouldnotbehere OPTIONAL)
+load_cache(${Complex_SOURCE_DIR}/Cache
+ EXCLUDE
+ CACHE_TEST_VAR_EXCLUDED
+ INCLUDE_INTERNALS
+ CACHE_TEST_VAR_INTERNAL)
+
+load_cache(${Complex_SOURCE_DIR}/Cache READ_WITH_PREFIX foo CACHE_TEST_VAR2)
+if(${fooCACHE_TEST_VAR2} MATCHES bar)
+ message("Load cache worked: ${fooCACHE_TEST_VAR2}")
+else()
+ message(FATAL_ERROR "Load cache with prefix failed: ${fooCACHE_TEST_VAR2}")
+endif()
+
+
+
+#
+# Specify include and lib dirs
+# (BEFORE is for coverage)
+#
+include_directories(
+ Library
+)
+
+include_directories(BEFORE
+ ${Complex_BINARY_DIR}
+)
+include_directories(SYSTEM Library/SystemDir)
+
+include_regular_expression("^(cmTest|file|sharedFile|test).*$" "^cmMissing")
+
+link_directories(
+ ${Complex_BINARY_DIR}/Library
+)
+
+#
+# check for SET CACHE FORCE
+#
+set(FORCE_TEST 1 CACHE STRING "a test")
+set(FORCE_TEST 0 CACHE STRING "a test" FORCE)
+
+#
+# Lib and exe path
+#
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${Complex_BINARY_DIR}/lib/static")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${Complex_BINARY_DIR}/lib")
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${Complex_BINARY_DIR}/bin")
+
+message (Test " " escape " " semi-colon " " \; \;)
+#
+# Exec program (TODO: test a result)
+# Increase coverage.
+#
+message("\nIgnore this message")
+option(NO_EXEC_PROGRAM "Do not test EXEC_PROGRAM" 0)
+if (NOT NO_EXEC_PROGRAM)
+ exec_program(${CMAKE_COMMAND} ARGS -E echo NO_EXEC_PROGRAM "${Complex_BINARY_DIR}")
+else ()
+ message("Set this option ON")
+endif ()
+
+mark_as_advanced(NO_EXEC_PROGRAM)
+mark_as_advanced(CLEAR NO_EXEC_PROGRAM)
+
+# Execute a process. Add coverage for this command.
+execute_process(
+ COMMAND ${CMAKE_COMMAND} -E echo "ABCDEFG"
+ OUTPUT_VARIABLE TEST_OUT
+ )
+if("${TEST_OUT}" STREQUAL "ABCDEFG\n")
+else()
+ message(SEND_ERROR "EXECUTE_PROCESS output test failed: [${TEST_OUT}]")
+endif()
+
+# This test has some problems on UNIX systems. Disabling for now.
+#
+# execute_process(
+# COMMAND ${CMAKE_COMMAND} -E echo "ABCDEFG"
+# COMMAND /process/does/not/exist
+# OUTPUT_QUIET
+# ERROR_QUIET
+# RESULT_VARIABLE RESULT
+# )
+# if("${RESULT}" STREQUAL "0")
+# message(SEND_ERROR
+# "EXECUTE_PROCESS result test failed with RESULT=[${RESULT}]")
+# else()
+# message(STATUS "EXECUTE_PROCESS result test passed with RESULT=[${RESULT}]")
+# endif()
+
+#
+# Create directory.
+# The 'complex' executable will then test if this dir exists,
+# sadly it won't be able to remove it.
+#
+make_directory("${Complex_BINARY_DIR}/make_dir")
+
+#
+# Test FIND_LIBARY
+# Create a dummy empty lib
+#
+configure_file(
+ ${Complex_SOURCE_DIR}/Library/dummy
+ ${Complex_BINARY_DIR}/Library/dummylib.lib
+ COPYONLY)
+foreach (ext ${CMAKE_SHLIB_SUFFIX};.so;.a;.sl
+ ${CMAKE_SHARED_LIBRARY_SUFFIX}.2
+ ${CMAKE_STATIC_LIBRARY_SUFFIX}.2)
+ configure_file(
+ ${Complex_SOURCE_DIR}/Library/dummy
+ ${Complex_BINARY_DIR}/Library/libdummylib${ext}
+ COPYONLY)
+endforeach ()
+
+find_library(FIND_DUMMY_LIB
+ dummylib
+ PATHS
+ ${Complex_BINARY_DIR}/Library DOC "find dummy lib")
+
+find_library(FIND_DUMMY_LIB
+ NAMES dummylib dummylib2
+ PATHS
+ ${Complex_BINARY_DIR}/Library DOC "find dummy lib")
+
+# This doesn't work for platforms that have a shared library and an import
+# library, like Windows with .dll and .lib. Limit is to ".so" now because it's
+# known to work there.
+if(CMAKE_SHARED_LIBRARY_SUFFIX STREQUAL ".so")
+ find_library(FIND_DUMMY_SHLIB_VERSIONED
+ NAMES libdummylib${CMAKE_SHARED_LIBRARY_SUFFIX}.2
+ PATHS ${Complex_BINARY_DIR}/Library
+ DOC "find versioned dummy shared lib"
+ NO_DEFAULT_PATH)
+
+ if(NOT FIND_DUMMY_SHLIB_VERSIONED MATCHES "/libdummylib${CMAKE_SHARED_LIBRARY_SUFFIX}.2")
+ message(SEND_ERROR "FIND_DUMMY_SHLIB_VERSIONED is not set correctly: "
+ "${FIND_DUMMY_SHLIB_VERSIONED}")
+ endif()
+endif()
+
+# Static library, should work everywhere
+find_library(FIND_DUMMY_STLIB_VERSIONED
+ NAMES libdummylib${CMAKE_STATIC_LIBRARY_SUFFIX}.2
+ PATHS ${Complex_BINARY_DIR}/Library
+ DOC "find versioned dummy static lib"
+ NO_DEFAULT_PATH)
+
+if(NOT FIND_DUMMY_STLIB_VERSIONED MATCHES "/libdummylib${CMAKE_STATIC_LIBRARY_SUFFIX}.2")
+ message(SEND_ERROR "FIND_DUMMY_STLIB_VERSIONED is not set correctly: "
+ "${FIND_DUMMY_STLIB_VERSIONED}")
+endif()
+
+#
+# Test SET_SOURCE_FILES_PROPERTIES
+#
+set_source_files_properties(nonexisting_file2
+ GENERATED
+ ABSTRACT
+ WRAP_EXCLUDE
+ COMPILE_FLAGS "-foo -bar")
+
+get_source_file_property(FILE_HAS_ABSTRACT nonexisting_file2 ABSTRACT)
+get_source_file_property(FILE_HAS_WRAP_EXCLUDE nonexisting_file2 WRAP_EXCLUDE)
+get_source_file_property(FILE_COMPILE_FLAGS nonexisting_file2 COMPILE_FLAGS)
+
+set_source_files_properties(nonexisting_file3 PROPERTIES
+ GENERATED 1
+ ABSTRACT 1
+ WRAP_EXCLUDE 1
+ COMPILE_FLAGS "-foo -bar")
+get_source_file_property(FILE_HAS_ABSTRACT nonexisting_file3 ABSTRACT)
+get_source_file_property(FILE_HAS_WRAP_EXCLUDE nonexisting_file3 WRAP_EXCLUDE)
+get_source_file_property(FILE_COMPILE_FLAGS nonexisting_file3 COMPILE_FLAGS)
+
+#
+# Test registry (win32)
+# Create a file, put its path in a registry key, try to find the file in that
+# path using that registry key, then remove the file and the key
+#
+if (WIN32)
+ if (NOT UNIX)
+ set(dir "${Complex_BINARY_DIR}/registry_dir")
+ set(file "registry_test_dummy")
+ set(hkey "HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Tests\\Complex;registry_test")
+ configure_file(
+ ${Complex_SOURCE_DIR}/Library/dummy
+ "${dir}/${file}"
+ COPYONLY)
+ exec_program(${CMAKE_COMMAND} ARGS "-E write_regv \"${hkey}\" \"${dir}\"")
+ find_path(REGISTRY_TEST_PATH
+ ${file}
+ "[${hkey}]" DOC "Registry_Test_Path")
+ exec_program(${CMAKE_COMMAND} ARGS "-E delete_regv \"${hkey}\"")
+ exec_program(${CMAKE_COMMAND} ARGS "-E remove \"${dir}/${file}\"")
+ endif ()
+endif ()
+
+#
+# Test a set and a remove
+#
+set(REMOVE_STRING a b c d e f)
+set(removeVar1 c e)
+remove(REMOVE_STRING ${removeVar1} f)
+
+#
+# Test an IF inside a FOREACH.
+#
+foreach(x "a")
+ if(${x} MATCHES "a")
+ # Should always execute.
+ set(IF_INSIDE_FOREACH_THEN_EXECUTED 1)
+ else()
+ # Should never execute.
+ set(IF_INSIDE_FOREACH_ELSE_EXECUTED 1)
+ endif()
+endforeach()
+
+# test WHILE command
+set (while_var 1)
+while (while_var LESS 1000)
+ set(while_var ${while_var}0)
+endwhile()
+
+set(SHOULD_BE_ZERO )
+set(SHOULD_BE_ONE 1)
+
+# test elseif functionality, the mess below tries to catch problem
+# of clauses being executed early or late etc
+set (RESULT 3)
+if (RESULT EQUAL 1)
+ if (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+ elseif (RESULT EQUAL 3)
+ set (ELSEIF_RESULT 1)
+ endif ()
+elseif (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+elseif (RESULT EQUAL 3)
+ if (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+ elseif (RESULT EQUAL 3)
+ if (NOT ELSEIF_RESULT EQUAL 1)
+ set (ELSEIF_RESULT 2)
+ endif ()
+ endif ()
+elseif (RESULT EQUAL 4)
+ if (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+ elseif (RESULT EQUAL 3)
+ set (ELSEIF_RESULT 1)
+ endif ()
+else ()
+ if (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+ elseif (RESULT EQUAL 3)
+ set (ELSEIF_RESULT 1)
+ endif ()
+endif ()
+
+if (NOT ELSEIF_RESULT EQUAL 2)
+ set (ELSEIF_RESULT 0)
+endif ()
+
+# test handling of parenthetical groups in conditionals
+if (2 GREATER 1 AND (4 LESS 3 OR 5 LESS 6) AND NOT (7 GREATER 8))
+ set(CONDITIONAL_PARENTHESES 1)
+endif()
+
+
+#
+# Configure file
+# (plug vars to #define so that they can be tested)
+#
+configure_file(
+ ${Complex_SOURCE_DIR}/cmTestConfigure.h.in
+ ${Complex_BINARY_DIR}/cmTestConfigure.h)
+
+set(STRING_WITH_QUOTES "\"hello world\"")
+# test CONFIGURE_FILE with ESCAPE_QUOTES on
+configure_file(
+ ${Complex_SOURCE_DIR}/cmTestConfigureEscape.h.in
+ ${Complex_BINARY_DIR}/cmTestConfigureEscape.h ESCAPE_QUOTES)
+
+# Test regular expression commands.
+string(REGEX MATCH "b" RESULT "abc")
+if(NOT RESULT)
+ message(SEND_ERROR "string(REGEX MATCH ... ) test failed.")
+endif()
+string(REGEX MATCHALL "b" RESULT "abcb")
+if(NOT RESULT)
+ message(SEND_ERROR "string(REGEX MATCHALL ... ) test failed.")
+endif()
+string(REGEX REPLACE ".([bd])." "[\\1]" RESULT "a(b)c(d)e")
+if(NOT RESULT STREQUAL "a[b]c[d]e")
+ message(SEND_ERROR
+ "string(REGEX REPLACE ... ) test failed (\"${RESULT}\" v. \"a[b]c[d]e\")")
+endif()
+
+#
+# This tests needs Ansi C++98
+#
+set(CMAKE_CXX_STANDARD 98)
+#
+# GNU extensions are needed for stricmp() on Windows.
+#
+set(CMAKE_CXX_EXTENSIONS TRUE)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+ CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
+
+#
+# Create the libs and the main exe
+#
+add_subdirectory(Library)
+add_subdirectory(Executable)
+subdir_depends(Executable Library)
+export_library_dependencies(${Complex_BINARY_DIR}/ComplexLibraryDepends.cmake)
+include(${Complex_BINARY_DIR}/ComplexLibraryDepends.cmake OPTIONAL)
diff --git a/Tests/Complex/Cache/CMakeCache.txt b/Tests/Complex/Cache/CMakeCache.txt
new file mode 100644
index 0000000000..17c55aa011
--- /dev/null
+++ b/Tests/Complex/Cache/CMakeCache.txt
@@ -0,0 +1,34 @@
+# This is the CMakeCache file.
+# For build in directory: d:/build/kitware/cmake/CMake-nmake/Tests/Complex
+# You can edit this file to change values found and used by cmake.
+# If you do not want to change any of the values, simply exit the editor.
+# If you do want to change a value, simply edit, save, and exit the editor.
+# The syntax for the file is as follows:
+# KEY:TYPE=VALUE
+# KEY is the name of a varible in the cache.
+# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT TYPE!.
+# VALUE is the current value for the KEY.
+
+########################
+# EXTERNAL cache entries
+########################
+
+//A var.
+CACHE_TEST_VAR1:STRING=foo
+
+//A var.
+CACHE_TEST_VAR2:FILEPATH=bar
+
+//A var.
+CACHE_TEST_VAR3:BOOL=1
+
+//A var.
+CACHE_TEST_VAR_EXCLUDED:BOOL=1
+
+
+########################
+# INTERNAL cache entries
+########################
+
+//A var.
+CACHE_TEST_VAR_INTERNAL:INTERNAL=bar
diff --git a/Tests/Complex/Executable/A.cxx b/Tests/Complex/Executable/A.cxx
new file mode 100644
index 0000000000..fb3eb08192
--- /dev/null
+++ b/Tests/Complex/Executable/A.cxx
@@ -0,0 +1,9 @@
+// Include code from a header that should not be compiled separately.
+#include "A.hh"
+
+#include <stdio.h>
+int main()
+{
+ printf("#define A_VALUE %d\n", A());
+ return 0;
+}
diff --git a/Tests/Complex/Executable/A.h b/Tests/Complex/Executable/A.h
new file mode 100644
index 0000000000..25c45fcbf8
--- /dev/null
+++ b/Tests/Complex/Executable/A.h
@@ -0,0 +1,4 @@
+// This header should not be compiled directly but through inclusion
+// in A.cxx through A.hh.
+extern int A();
+int A() { return 10; }
diff --git a/Tests/Complex/Executable/A.hh b/Tests/Complex/Executable/A.hh
new file mode 100644
index 0000000000..e6bab022e7
--- /dev/null
+++ b/Tests/Complex/Executable/A.hh
@@ -0,0 +1,2 @@
+// This header should not be compiled directly but through inclusion in A.cxx
+#include "A.h"
diff --git a/Tests/Complex/Executable/A.txt b/Tests/Complex/Executable/A.txt
new file mode 100644
index 0000000000..8ee9462be0
--- /dev/null
+++ b/Tests/Complex/Executable/A.txt
@@ -0,0 +1 @@
+This file should not be compiled!
diff --git a/Tests/Complex/Executable/CMakeLists.txt b/Tests/Complex/Executable/CMakeLists.txt
new file mode 100644
index 0000000000..bf23d4aa28
--- /dev/null
+++ b/Tests/Complex/Executable/CMakeLists.txt
@@ -0,0 +1,169 @@
+#
+# Create exe.
+#
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
+
+# Create an imported target for if(TARGET) test below.
+add_library(ExeImportedTarget UNKNOWN IMPORTED)
+
+# Test if(TARGET) command.
+if(NOT TARGET CMakeTestLibrary)
+ message(FATAL_ERROR "if(NOT TARGET CMakeTestLibrary) returned true!")
+endif()
+if(NOT TARGET ExeImportedTarget)
+ message(FATAL_ERROR "if(NOT TARGET ExeImportedTarget) returned true!")
+endif()
+if(TARGET LibImportedTarget)
+ message(FATAL_ERROR "if(TARGET LibImportedTarget) returned true!")
+endif()
+if(TARGET NotATarget)
+ message(FATAL_ERROR "if(TARGET NotATarget) returned true!")
+endif()
+
+ # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
+set(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
+link_libraries(${COMPLEX_LIBS})
+
+# Test forcing a .cxx file to not build.
+set_source_files_properties(complex_nobuild.cxx PROPERTIES
+ HEADER_FILE_ONLY 1)
+
+# Test forcing a .c file to not build.
+# This makes sure a mixed language library is created
+# with header file only sources
+set_source_files_properties(complex_nobuild.c PROPERTIES
+ HEADER_FILE_ONLY 1)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+add_executable(A A.cxx A.hh A.h A.txt)
+add_custom_command(OUTPUT Aout.h COMMAND A > Aout.h VERBATIM)
+add_executable(complex complex testcflags.c Aout.h)
+# Sub1/NameConflictTest.c Sub2/NameConflictTest.c)
+add_executable(complex.file complex.file.cxx complex_nobuild.cxx
+ complex_nobuild.c)
+
+if (UNIX)
+ target_link_libraries(complex ${CMAKE_DL_LIBS})
+else()
+ if (NOT BORLAND)
+ if(NOT MINGW)
+ target_link_libraries(complex rpcrt4.lib)
+ endif()
+ endif()
+endif ()
+
+# Test linking to static lib when a shared lib has the same name.
+if(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
+ add_definitions(-DCOMPLEX_TEST_LINK_STATIC)
+ target_link_libraries(complex CMakeTestLinkStatic)
+endif()
+
+# can we get the path to a source file
+get_source_file_property(A_LOCATION A.cxx LOCATION)
+if ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")
+ add_definitions(-DCMAKE_FOUND_ACXX)
+endif ()
+
+# get the directory parent
+get_directory_property(P_VALUE PARENT_DIRECTORY)
+if ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")
+ add_definitions(-DCMAKE_FOUND_PARENT)
+endif ()
+
+# get the stack of listfiles
+include(Included.cmake)
+if ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
+ add_definitions(-DCMAKE_FOUND_LISTFILE_STACK)
+endif ()
+
+# Test add/remove definitions.
+add_definitions(
+ -DCOMPLEX_DEFINED_PRE
+ -DCOMPLEX_DEFINED
+ -DCOMPLEX_DEFINED_POST
+ -DCOMPLEX_DEFINED
+ )
+remove_definitions(-DCOMPLEX_DEFINED)
+
+# Test pre-build/pre-link/post-build rules for an executable.
+add_custom_command(TARGET complex PRE_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Executable/prebuild.txt")
+add_custom_command(TARGET complex PRE_LINK
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Executable/prelink.txt")
+add_custom_command(TARGET complex POST_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Executable/postbuild.txt")
+add_custom_command(TARGET complex POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy
+ "${Complex_BINARY_DIR}/Executable/postbuild.txt"
+ "${Complex_BINARY_DIR}/Executable/postbuild2.txt")
+
+set_source_files_properties(complex
+ COMPILE_FLAGS
+ "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
+ #" -DFILE_DEFINE_STRING=\\\"hello\\\""
+ OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
+)
+set_target_properties(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
+add_custom_command(
+ TARGET complex
+ SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
+ ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
+ OUTPUTS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
+ DEPENDS ${CMAKE_COMMAND}
+)
+
+# Test creating an executable that is not built by default.
+add_executable(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx)
+target_link_libraries(notInAllExe notInAllLib)
+
+# Test user-value flag mapping for the VS IDE.
+if(MSVC)
+ set_target_properties(notInAllExe PROPERTIES
+ LINK_FLAGS "/NODEFAULTLIB:LIBC;LIBCMT;MSVCRT")
+endif()
+
+# Test creating a custom target that builds not-in-all targets.
+add_custom_target(notInAllCustom)
+add_dependencies(notInAllCustom notInAllExe)
+
+#
+# Output the files required by 'complex' to a file.
+#
+# This test has been moved to the 'required' subdir so that it
+# has no side-effects on the current Makefile (duplicated source file
+# due to source list expansion done twice).
+#
+add_subdirectory(Temp)
+
+if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
+ add_executable(testSystemDir testSystemDir.cxx)
+ set_target_properties(testSystemDir PROPERTIES COMPILE_FLAGS "-Werror")
+endif()
+
+#
+# Extra coverage.Not used.
+#
+install_targets(/tmp complex)
+install_programs(/tmp complex)
+
+configure_file(
+ ${Complex_SOURCE_DIR}/Executable/cmVersion.h.in
+ ${Complex_BINARY_DIR}/cmVersion.h)
+
+source_group(A_GROUP ".cxx")
+source_group(B_GROUP REGULAR_EXPRESSION "cxx")
+source_group(C_GROUP FILES complex.cxx)
+
+file(WRITE ${Complex_BINARY_DIR}/A/libA.a "test")
+file(WRITE ${Complex_BINARY_DIR}/A/libC.a "test")
+file(WRITE ${Complex_BINARY_DIR}/B/libB.a "test")
+file(WRITE ${Complex_BINARY_DIR}/B/libA.a "test")
+file(WRITE ${Complex_BINARY_DIR}/C/libC.a "test")
+file(WRITE ${Complex_BINARY_DIR}/C/libB.a "test")
diff --git a/Tests/Complex/Executable/Included.cmake b/Tests/Complex/Executable/Included.cmake
new file mode 100644
index 0000000000..520a68be17
--- /dev/null
+++ b/Tests/Complex/Executable/Included.cmake
@@ -0,0 +1,2 @@
+get_directory_property(LF_VALUE LISTFILE_STACK)
+
diff --git a/Tests/Complex/Executable/Sub1/NameConflictTest.c b/Tests/Complex/Executable/Sub1/NameConflictTest.c
new file mode 100644
index 0000000000..87203861f3
--- /dev/null
+++ b/Tests/Complex/Executable/Sub1/NameConflictTest.c
@@ -0,0 +1,4 @@
+int NameConflictTest1()
+{
+ return 0;
+}
diff --git a/Tests/Complex/Executable/Sub2/NameConflictTest.c b/Tests/Complex/Executable/Sub2/NameConflictTest.c
new file mode 100644
index 0000000000..4a32572555
--- /dev/null
+++ b/Tests/Complex/Executable/Sub2/NameConflictTest.c
@@ -0,0 +1,4 @@
+int NameConflictTest2()
+{
+ return 0;
+}
diff --git a/Tests/Complex/Executable/Temp/CMakeLists.txt b/Tests/Complex/Executable/Temp/CMakeLists.txt
new file mode 100644
index 0000000000..041fcff20c
--- /dev/null
+++ b/Tests/Complex/Executable/Temp/CMakeLists.txt
@@ -0,0 +1,8 @@
+#
+# Output the files required by 'complex' to a file.
+# The 'complex' executable will then test if this file exists and remove it.
+# The contents of this file is not tested (absolute paths).
+#
+output_required_files(
+ ${Complex_SOURCE_DIR}/Executable/complex.cxx
+ ${Complex_BINARY_DIR}/Executable/Temp/complex-required.txt)
diff --git a/Tests/Complex/Executable/cmVersion.h.in b/Tests/Complex/Executable/cmVersion.h.in
new file mode 100644
index 0000000000..de7522d1db
--- /dev/null
+++ b/Tests/Complex/Executable/cmVersion.h.in
@@ -0,0 +1 @@
+#define CMAKE_MINIMUM_REQUIRED_VERSION "${CMAKE_MINIMUM_REQUIRED_VERSION}"
diff --git a/Tests/Complex/Executable/complex.cxx b/Tests/Complex/Executable/complex.cxx
new file mode 100644
index 0000000000..31442bafa6
--- /dev/null
+++ b/Tests/Complex/Executable/complex.cxx
@@ -0,0 +1,946 @@
+#include "cmTestConfigure.h"
+#include "cmTestConfigureEscape.h"
+#include "cmTestGeneratedHeader.h"
+#include "cmVersion.h"
+#include "ExtraSources/file1.h"
+#include "Aout.h"
+#include "file2.h"
+#include "sharedFile.h"
+extern "C" {
+#include "testConly.h"
+}
+#include <vector>
+#include <string>
+#include <iostream>
+#include <string.h>
+
+#include <stdio.h>
+#include <sys/stat.h>
+#if !defined(S_ISDIR)
+# define S_ISDIR(mode) ((mode) & _S_IFDIR)
+#endif
+
+#ifdef COMPLEX_TEST_LINK_STATIC
+extern "C"
+{
+ int TestLinkGetType();
+}
+#endif
+
+int cm_passed = 0;
+int cm_failed = 0;
+// ======================================================================
+
+void cmFailed(const char* Message, const char* m2= "", const char* m3 = "")
+{
+ std::cout << "FAILED: " << Message << m2 << m3 << "\n";
+ cm_failed++;
+}
+
+// ======================================================================
+
+void cmPassed(const char* Message, const char* m2="")
+{
+ std::cout << "Passed: " << Message << m2 << "\n";
+ cm_passed++;
+}
+
+#ifndef COMPLEX_DEFINED_PRE
+# error "COMPLEX_DEFINED_PRE not defined!"
+#endif
+
+#ifdef COMPLEX_DEFINED
+# error "COMPLEX_DEFINED is defined but it should not!"
+#endif
+
+#ifndef COMPLEX_DEFINED_POST
+# error "COMPLEX_DEFINED_POST not defined!"
+#endif
+
+#ifndef CMAKE_IS_REALLY_FUN
+# error This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
+#endif
+
+#if defined(NDEBUG) && !defined(CMAKE_IS_FUN_IN_RELEASE_MODE)
+# error Per-configuration directory-level definition not inherited.
+#endif
+
+// ======================================================================
+
+void TestAndRemoveFile(const char* filename)
+{
+ struct stat st;
+ if(stat(filename, &st) < 0)
+ {
+ cmFailed("Could not find file: ", filename);
+ }
+ else
+ {
+ if (remove(filename) < 0)
+ {
+ cmFailed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename);
+ }
+ else
+ {
+ cmPassed("Find and remove file: ", filename);
+ }
+ }
+}
+
+// ======================================================================
+
+void TestDir(const char* filename)
+{
+ struct stat st;
+ if(stat(filename, &st) < 0 || !S_ISDIR(st.st_mode))
+ {
+ cmFailed("Could not find dir: ", filename);
+ }
+ else
+ {
+ cmPassed("Find dir: ", filename);
+ }
+}
+
+// Here is a stupid function that tries to use std::string methods
+// so that the dec cxx compiler will instantiate the stuff that
+// we are using from the CMakeLib library....
+void ForceStringUse()
+{
+ std::vector<std::string> v;
+ std::vector<std::string> v2;
+ v = v2;
+ std::string cachetest = CACHE_TEST_VAR_INTERNAL;
+ v.push_back(cachetest);
+ v2 = v;
+ std::string x(5,'x');
+ char buff[5];
+ x.copy(buff, 1, 0);
+ x[0] = 'a';
+ std::string::size_type pos = 0;
+ x.replace(pos, pos, pos, 'x');
+ std::string copy = cachetest;
+ cachetest.find("bar");
+ cachetest.rfind("bar");
+ copy.append(cachetest);
+ copy = cachetest.substr(0, cachetest.size());
+}
+
+
+// defined in testcflags.c
+extern "C" int TestCFlags(char* m);
+extern "C" int TestTargetCompileFlags(char* m);
+
+#if 0
+// defined in Sub1/NameConflictTest.c
+extern "C" int NameConflictTest1();
+// defined in Sub2/NameConflictTest.c
+extern "C" int NameConflictTest2();
+#endif
+
+// ======================================================================
+
+int main()
+{
+#if 0
+ if(NameConflictTest1() == 0 && NameConflictTest2() == 0)
+ {
+ cmPassed("Sub dir with same named source works");
+ }
+ else
+ {
+ cmFailed("Sub dir with same named source fails");
+ }
+#endif
+ if(file1() != 1)
+ {
+ cmFailed("Call to file1 function from library failed.");
+ }
+ else
+ {
+ cmPassed("Call to file1 function returned 1.");
+ }
+#ifndef COMPLEX_TARGET_FLAG
+ cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
+#else
+ cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
+#endif
+
+#ifdef ELSEIF_RESULT
+ cmPassed("ELSEIF did work");
+#else
+ cmFailed("ELSEIF did not work");
+#endif
+
+#ifdef CONDITIONAL_PARENTHESES
+ cmPassed("CONDITIONAL_PARENTHESES did work");
+#else
+ cmFailed("CONDITIONAL_PARENTHESES did not work");
+#endif
+
+ if(file2() != 1)
+ {
+ cmFailed("Call to file2 function from library failed.");
+ }
+ else
+ {
+ cmPassed("Call to file2 function returned 1.");
+ }
+#ifndef TEST_CXX_FLAGS
+ cmFailed("CMake CMAKE_CXX_FLAGS is not being passed to the compiler!");
+#else
+ cmPassed("CMake CMAKE_CXX_FLAGS is being passed to the compiler.");
+#endif
+ std::string gen = CMAKE_GENERATOR;
+ // visual studio is currently broken for c flags
+ char msg[1024];
+ if(gen.find("Visual") == gen.npos)
+ {
+#ifdef TEST_C_FLAGS
+ cmFailed("CMake CMAKE_C_FLAGS are being passed to c++ files the compiler!");
+#else
+ cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
+#endif
+ if(TestCFlags(msg))
+ {
+ cmPassed(
+ "CMake CMAKE_C_FLAGS are being passed to c files and CXX flags are not.");
+ }
+ else
+ {
+ cmFailed(msg);
+ }
+ }
+ if(TestTargetCompileFlags(msg))
+ {
+ cmPassed(msg);
+ }
+ else
+ {
+ cmFailed(msg);
+ }
+
+ // ----------------------------------------------------------------------
+ // Test ADD_DEFINITIONS
+
+#ifndef CMAKE_IS_FUN
+ cmFailed("CMake is not fun, so it is broken and should be fixed.");
+#else
+ cmPassed("CMAKE_IS_FUN is defined.");
+#endif
+
+#if defined(CMAKE_ARGV1) && defined(CMAKE_ARGV2) && defined(CMAKE_ARGV3) && defined(CMAKE_ARGV4)
+ cmPassed("Variable args for MACROs are working.");
+#else
+ cmFailed("Variable args for MACROs are failing.");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test GET_SOURCE_FILE_PROPERTY for location
+#ifndef CMAKE_FOUND_ACXX
+ cmFailed("CMake did not get the location of A.cxx correctly");
+#else
+ cmPassed("CMake found A.cxx properly");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test GET_DIRECTORY_PROPERTY for parent
+#ifndef CMAKE_FOUND_PARENT
+ cmFailed("CMake did not get the location of the parent directory properly");
+#else
+ cmPassed("CMake found the parent directory properly");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test GET_DIRECTORY_PROPERTY for listfiles
+#ifndef CMAKE_FOUND_LISTFILE_STACK
+ cmFailed("CMake did not get the listfile stack properly");
+#else
+ cmPassed("CMake found the listfile stack properly");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test SET, VARIABLE_REQUIRES
+
+#ifdef SHOULD_NOT_BE_DEFINED
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED is defined.");
+#endif
+
+#ifndef ONE_VAR
+ cmFailed("cmakedefine is broken, ONE_VAR is not defined.");
+#else
+ cmPassed("ONE_VAR is defined.");
+#endif
+
+#ifndef ONE_VAR_IS_DEFINED
+ cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
+ "ONE_VAR_IS_DEFINED is not defined.");
+#else
+ cmPassed("ONE_VAR_IS_DEFINED is defined.");
+#endif
+
+#ifdef ZERO_VAR
+ cmFailed("cmakedefine is broken, ZERO_VAR is defined.");
+#else
+ cmPassed("ZERO_VAR is not defined.");
+#endif
+
+#ifndef STRING_VAR
+ cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
+#else
+ if(strcmp(STRING_VAR, "CMake is great") != 0)
+ {
+ cmFailed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
+ STRING_VAR);
+ }
+ else
+ {
+ cmPassed("STRING_VAR == ", STRING_VAR);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test various IF/ELSE combinations
+
+#ifdef SHOULD_NOT_BE_DEFINED_NOT
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_NOT is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_NOT
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_NOT is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_NOT2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_NOT2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_NOT2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_NOT2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_AND
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_AND is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_AND
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_AND is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_AND2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_AND2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_AND2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_AND2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_OR
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_OR is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_OR
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_OR is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_OR2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_OR2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_OR2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_OR2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_MATCHES
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_MATCHES
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_MATCHES is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_MATCHES2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_MATCHES2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_MATCHES2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_COMMAND
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_COMMAND
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_COMMAND is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_COMMAND2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_COMMAND2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_COMMAND2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_EXISTS
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_EXISTS
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_EXISTS is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_EXISTS2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_EXISTS2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_IS_DIRECTORY
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY is defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_IS_DIRECTORY2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_LESS
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_LESS is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_LESS
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_LESS is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_LESS2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_LESS2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_LESS2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_LESS2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_GREATER
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_GREATER is not defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_EQUAL
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EQUAL is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_EQUAL is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_EQUAL
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EQUAL is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_EQUAL is defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_GREATER
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_GREATER is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_GREATER2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_GREATER2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_GREATER2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_GREATER2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_STRLESS
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_STRLESS
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_STRLESS is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_STRLESS2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_STRLESS2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_STRLESS2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_STRGREATER
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_STRGREATER
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_STRGREATER is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_STRGREATER2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_STRGREATER2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_STRGREATER2 is defined.");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test FOREACH
+
+#ifndef FOREACH_VAR1
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_VAR1 is not defined.");
+#else
+ if(strcmp(FOREACH_VAR1, "VALUE1") != 0)
+ {
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_VAR1 == ", FOREACH_VAR1);
+ }
+ else
+ {
+ cmPassed("FOREACH_VAR1 == ", FOREACH_VAR1);
+ }
+#endif
+
+#ifndef FOREACH_VAR2
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_VAR2 is not defined.");
+#else
+ if(strcmp(FOREACH_VAR2, "VALUE2") != 0)
+ {
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_VAR2 == ", FOREACH_VAR2);
+ }
+ else
+ {
+ cmPassed("FOREACH_VAR2 == ", FOREACH_VAR2);
+ }
+#endif
+
+#ifndef FOREACH_CONCAT
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_CONCAT is not defined.");
+#else
+ if(strcmp(FOREACH_CONCAT, "abcdefg") != 0)
+ {
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_CONCAT == ", FOREACH_CONCAT);
+ }
+ else
+ {
+ cmPassed("FOREACH_CONCAT == ", FOREACH_CONCAT);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test WHILE
+
+ if(WHILE_VALUE != 1000)
+ {
+ cmFailed("WHILE command is not working");
+ }
+ else
+ {
+ cmPassed("WHILE command is working");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test LOAD_CACHE
+
+#ifndef CACHE_TEST_VAR1
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR1 is not defined.");
+#else
+ if(strcmp(CACHE_TEST_VAR1, "foo") != 0)
+ {
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
+ }
+ else
+ {
+ cmPassed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
+ }
+#endif
+
+#ifndef CACHE_TEST_VAR2
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR2 is not defined.");
+#else
+ if(strcmp(CACHE_TEST_VAR2, "bar") != 0)
+ {
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
+ }
+ else
+ {
+ cmPassed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
+ }
+#endif
+
+#ifndef CACHE_TEST_VAR3
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR3 is not defined.");
+#else
+ if(strcmp(CACHE_TEST_VAR3, "1") != 0)
+ {
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
+ }
+ else
+ {
+ cmPassed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
+ }
+#endif
+
+#ifdef CACHE_TEST_VAR_EXCLUDED
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command or cmakedefine is broken, "
+ "CACHE_TEST_VAR_EXCLUDED is defined (should not have been loaded).");
+#else
+ cmPassed("CACHE_TEST_VAR_EXCLUDED is not defined.");
+#endif
+
+#ifndef CACHE_TEST_VAR_INTERNAL
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR_INTERNAL is not defined.");
+#else
+ std::string cachetest = CACHE_TEST_VAR_INTERNAL;
+ if(cachetest != "bar")
+ {
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
+ }
+ else
+ {
+ cmPassed("CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Some pre-build/pre-link/post-build custom-commands have been
+ // attached to the lib (see Library/).
+ // Each runs ${CREATE_FILE_EXE} which will create a file.
+ // It also copies that file again using cmake -E.
+ // Similar rules have been added to this executable.
+ //
+ // WARNING: if you run 'complex' manually, this *will* fail, because
+ // the file was removed the last time 'complex' was run, and it is
+ // only created during a build.
+
+ TestAndRemoveFile(BINARY_DIR "/Library/prebuild.txt");
+ TestAndRemoveFile(BINARY_DIR "/Library/prelink.txt");
+ TestAndRemoveFile(BINARY_DIR "/Library/postbuild.txt");
+ TestAndRemoveFile(BINARY_DIR "/Library/postbuild2.txt");
+ TestAndRemoveFile(BINARY_DIR "/Executable/prebuild.txt");
+ TestAndRemoveFile(BINARY_DIR "/Executable/prelink.txt");
+ TestAndRemoveFile(BINARY_DIR "/Executable/postbuild.txt");
+ TestAndRemoveFile(BINARY_DIR "/Executable/postbuild2.txt");
+
+ // ----------------------------------------------------------------------
+ // A custom target has been created (see Library/).
+ // It runs ${CREATE_FILE_EXE} which will create a file.
+ //
+ // WARNING: if you run 'complex' manually, this *will* fail, because
+ // the file was removed the last time 'complex' was run, and it is
+ // only created during a build.
+
+ TestAndRemoveFile(BINARY_DIR "/Library/custom_target1.txt");
+
+ // ----------------------------------------------------------------------
+ // A directory has been created.
+
+ TestDir(BINARY_DIR "/make_dir");
+
+ // ----------------------------------------------------------------------
+ // Test OUTPUT_REQUIRED_FILES
+ // The files required by 'complex' have been output to a file.
+ // The contents of this file is not tested (absolute paths).
+ //
+ // WARNING: if you run 'complex' manually, this *will* fail, because
+ // the file was removed the last time 'complex' was run, and it is
+ // only created during a build.
+
+ TestAndRemoveFile(BINARY_DIR "/Executable/Temp/complex-required.txt");
+
+ // ----------------------------------------------------------------------
+ // Test FIND_LIBRARY
+
+#ifndef FIND_DUMMY_LIB
+ cmFailed("the CONFIGURE_FILE command is broken, "
+ "FIND_DUMMY_LIB is not defined.");
+#else
+ if(strstr(FIND_DUMMY_LIB, "dummylib") == NULL)
+ {
+ cmFailed("the FIND_LIBRARY or CONFIGURE_FILE command is broken, "
+ "FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
+ }
+ else
+ {
+ cmPassed("FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test SET_SOURCE_FILES_PROPERTIES
+
+#ifndef FILE_HAS_EXTRA_COMPILE_FLAGS
+ cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
+#else
+ cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
+#endif
+
+#if 0 // Disable until implemented everywhere.
+#ifndef FILE_DEFINE_STRING
+ cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag");
+#else
+ if(strcmp(FILE_DEFINE_STRING, "hello") != 0)
+ {
+ cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag correctly");
+ }
+ else
+ {
+ cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_DEFINE_STRING flag");
+ }
+#endif
+#endif
+
+#ifndef FILE_HAS_ABSTRACT
+ cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting ABSTRACT flag");
+#else
+ cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting ABSTRACT flag");
+#endif
+
+#ifndef FILE_HAS_WRAP_EXCLUDE
+ cmFailed("FILE_HAS_WRAP_EXCLUDE failed at setting WRAP_EXCLUDE flag");
+#else
+ cmPassed("FILE_HAS_WRAP_EXCLUDE succeeded in setting WRAP_EXCLUDE flag");
+#endif
+
+#ifndef FILE_COMPILE_FLAGS
+ cmFailed("the CONFIGURE_FILE command is broken, FILE_COMPILE_FLAGS is not defined.");
+#else
+ if(strcmp(FILE_COMPILE_FLAGS, "-foo -bar") != 0)
+ {
+ cmFailed("the SET_SOURCE_FILES_PROPERTIES or CONFIGURE_FILE command is broken. FILE_COMPILE_FLAGS == ",
+ FILE_COMPILE_FLAGS);
+ }
+ else
+ {
+ cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting extra flags == ", FILE_COMPILE_FLAGS);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test registry (win32)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#ifndef REGISTRY_TEST_PATH
+ cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not defined.");
+#else
+ std::cout << "REGISTRY_TEST_PATH == " << REGISTRY_TEST_PATH << "\n";
+ if(stricmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0)
+ {
+ cmFailed("the 'read registry value' function or CONFIGURE_FILE command is broken. REGISTRY_TEST_PATH == ",
+ REGISTRY_TEST_PATH, " is not " BINARY_DIR "/registry_dir");
+ }
+ else
+ {
+ cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
+ }
+#endif
+#endif // defined(_WIN32) && !defined(__CYGWIN__)
+
+ if(strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "2.4") == 0)
+ {
+ cmPassed("CMAKE_MINIMUM_REQUIRED_VERSION is set to 2.4");
+ }
+ else
+ {
+ cmFailed("CMAKE_MINIMUM_REQUIRED_VERSION is not set to the expected 2.4");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test REMOVE command
+ if (strcmp("a;b;d",REMOVE_STRING) == 0)
+ {
+ cmPassed("REMOVE is working");
+ }
+ else
+ {
+ cmFailed("REMOVE is not working");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test SEPARATE_ARGUMENTS
+ if(strcmp("a;b;c", TEST_SEP) == 0)
+ {
+ cmPassed("SEPARATE_ARGUMENTS is working");
+ }
+ else
+ {
+ cmFailed("SEPARATE_ARGUMENTS is not working");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test Escape Quotes
+ if(strcmp("\"hello world\"", STRING_WITH_QUOTES) == 0)
+ {
+ cmPassed("ESCAPE_QUOTES is working");
+ }
+ else
+ {
+ cmFailed("ESCAPE_QUOTES is not working");
+ }
+
+
+ // ----------------------------------------------------------------------
+ // Test if IF command inside a FOREACH works.
+#if defined(IF_INSIDE_FOREACH_THEN_EXECUTED) && !defined(IF_INSIDE_FOREACH_ELSE_EXECUTED)
+ cmPassed("IF inside a FOREACH block works");
+#else
+ cmFailed("IF inside a FOREACH block is broken");
+#endif
+
+#if defined(GENERATED_HEADER_INCLUDED)
+ cmPassed("Generated header included by non-generated source works.");
+#else
+ cmFailed("Generated header included by non-generated source failed.");
+#endif
+ if(SHOULD_BE_ZERO == 0)
+ {
+ cmPassed("cmakedefine01 is working for 0");
+ }
+ else
+ {
+ cmFailed("cmakedefine01 is not working for 0");
+ }
+ if(SHOULD_BE_ONE == 1)
+ {
+ cmPassed("cmakedefine01 is working for 1");
+ }
+ else
+ {
+ cmFailed("cmakedefine01 is not working for 1");
+ }
+#ifdef FORCE_TEST
+ cmFailed("CMake SET CACHE FORCE");
+#else
+ cmPassed("CMake SET CACHE FORCE");
+#endif
+
+#ifdef COMPLEX_TEST_LINK_STATIC
+ if(TestLinkGetType())
+ {
+ cmPassed("Link to static over shared worked.");
+ }
+ else
+ {
+ cmFailed("Link to static over shared failed.");
+ }
+#endif
+
+#if defined(A_VALUE) && A_VALUE == 10
+ cmPassed("Single-character executable A worked.");
+#else
+ cmFailed("Single-character executable A failed.");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Summary
+
+ std::cout << "Passed: " << cm_passed << "\n";
+ if(cm_failed)
+ {
+ std::cout << "Failed: " << cm_failed << "\n";
+ return cm_failed;
+ }
+ return 0;
+}
diff --git a/Tests/Complex/Executable/complex.file.cxx b/Tests/Complex/Executable/complex.file.cxx
new file mode 100644
index 0000000000..e873fa6440
--- /dev/null
+++ b/Tests/Complex/Executable/complex.file.cxx
@@ -0,0 +1,8 @@
+#if 0
+#include "cmMissingHeader.h"
+#endif
+
+int main(int , char**)
+{
+ return 0;
+}
diff --git a/Tests/Complex/Executable/complex_nobuild.c b/Tests/Complex/Executable/complex_nobuild.c
new file mode 100644
index 0000000000..6b3c2c1e2d
--- /dev/null
+++ b/Tests/Complex/Executable/complex_nobuild.c
@@ -0,0 +1 @@
+#error "This file should not be compiled."
diff --git a/Tests/Complex/Executable/complex_nobuild.cxx b/Tests/Complex/Executable/complex_nobuild.cxx
new file mode 100644
index 0000000000..6b3c2c1e2d
--- /dev/null
+++ b/Tests/Complex/Executable/complex_nobuild.cxx
@@ -0,0 +1 @@
+#error "This file should not be compiled."
diff --git a/Tests/Complex/Executable/notInAllExe.cxx b/Tests/Complex/Executable/notInAllExe.cxx
new file mode 100644
index 0000000000..70275cd513
--- /dev/null
+++ b/Tests/Complex/Executable/notInAllExe.cxx
@@ -0,0 +1,10 @@
+extern int notInAllLibFunc();
+
+int main()
+{
+ return notInAllLibFunc();
+}
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif
diff --git a/Tests/Complex/Executable/testSystemDir.cxx b/Tests/Complex/Executable/testSystemDir.cxx
new file mode 100644
index 0000000000..e4815c679a
--- /dev/null
+++ b/Tests/Complex/Executable/testSystemDir.cxx
@@ -0,0 +1,3 @@
+#include <testSystemDir.h>
+
+int main() { return foo(); }
diff --git a/Tests/Complex/Executable/testcflags.c b/Tests/Complex/Executable/testcflags.c
new file mode 100644
index 0000000000..6c2dd5db32
--- /dev/null
+++ b/Tests/Complex/Executable/testcflags.c
@@ -0,0 +1,26 @@
+#include <string.h>
+
+int TestTargetCompileFlags(char* m)
+{
+#ifndef COMPLEX_TARGET_FLAG
+ strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS did not work");
+ return 0;
+#endif
+ strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS worked");
+ return 1;
+}
+
+int TestCFlags(char* m)
+{
+ /* TEST_CXX_FLAGS should not be defined in a c file */
+#ifdef TEST_CXX_FLAGS
+ strcpy(m, "CMake CMAKE_CXX_FLAGS (TEST_CXX_FLAGS) found in c file.");
+ return 0;
+#endif
+ /* TEST_C_FLAGS should be defined in a c file */
+#ifndef TEST_C_FLAGS
+ strcpy(m, "CMake CMAKE_C_FLAGS (TEST_C_FLAGS) not found in c file.");
+ return 0;
+#endif
+ return 1;
+}
diff --git a/Tests/Complex/Library/CMakeLists.txt b/Tests/Complex/Library/CMakeLists.txt
new file mode 100644
index 0000000000..f00cbd611a
--- /dev/null
+++ b/Tests/Complex/Library/CMakeLists.txt
@@ -0,0 +1,140 @@
+remove_definitions(-DCMAKE_IS_REALLY_FUN)
+
+#
+# Small utility used to create file
+# UTILITY_SOURCE is used for coverage and for getting the exact name
+# of the executable.
+#
+utility_source(CREATE_FILE_EXE create_file "." create_file.cxx)
+add_executable(create_file create_file.cxx)
+set_target_properties(create_file PROPERTIES RUNTIME_OUTPUT_DIRECTORY ".")
+
+#
+# Create static library
+# SOURCE_FILES_REMOVE is used for Coverage. empty.h is included for coverage
+#
+aux_source_directory(ExtraSources LibrarySources)
+set(LibrarySources ${LibrarySources}
+ file2
+ empty
+ create_file.cxx
+ GENERATED
+ nonexisting_file)
+remove(LibrarySources create_file.cxx GENERATED nonexisting_file)
+add_library(CMakeTestLibrary ${LibrarySources})
+
+if(WIN32)
+ if(NOT CYGWIN)
+ if(NOT BORLAND)
+ if(NOT MINGW)
+ target_link_libraries(CMakeTestLibrary
+ debug
+ user32.lib)
+ target_link_libraries(CMakeTestLibrary
+ optimized
+ kernel32.lib)
+ endif()
+ endif()
+ endif()
+endif()
+
+#
+# Create shared library
+#
+set(SharedLibrarySources sharedFile)
+add_library(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
+add_library(CMakeTestCLibraryShared SHARED testConly.c)
+define_property(
+ TARGET PROPERTY FOO
+ BRIEF_DOCS "a test property"
+ FULL_DOCS "A simple etst proerty that means nothign and is used for nothing"
+ )
+set_target_properties(CMakeTestCLibraryShared PROPERTIES FOO BAR)
+if(NOT BEOS AND NOT WIN32 AND NOT HAIKU) # No libm on BeOS.
+ set_target_properties(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
+endif()
+get_target_property(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
+if(${FOO_BAR_VAR} MATCHES "BAR")
+else()
+ message(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}")
+endif()
+
+# Create static and shared lib of same name.
+if(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
+ add_library(CMakeTestLinkStatic STATIC TestLink.c)
+ add_library(CMakeTestLinkShared SHARED TestLink.c)
+ set_target_properties(CMakeTestLinkStatic CMakeTestLinkShared
+ PROPERTIES OUTPUT_NAME CMakeTestLink)
+endif()
+
+#
+# Attach pre-build/pre-link/post-build custom-commands to the lib.
+# Each runs ${CREATE_FILE_EXE} which will create a file.
+# The 'complex' executable will then test if this file exists and remove it.
+#
+add_dependencies(CMakeTestLibraryShared create_file)
+message("complex bin dir is ${Complex_BINARY_DIR}")
+add_custom_command(TARGET CMakeTestLibraryShared PRE_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Library/prebuild.txt")
+add_custom_command(TARGET CMakeTestLibraryShared PRE_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Library/prelink.txt")
+add_custom_command(TARGET CMakeTestLibraryShared POST_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt")
+add_custom_command(TARGET CMakeTestLibraryShared POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy
+ "${Complex_BINARY_DIR}/Library/postbuild.txt"
+ "${Complex_BINARY_DIR}/Library/postbuild2.txt")
+
+#
+# Add a custom target.
+# It runs ${CREATE_FILE_EXE} which will create a file.
+# The 'complex' executable will then test if this file exists and remove it.
+#
+add_custom_target(custom_target1
+ ALL
+ ${CREATE_FILE_EXE}
+ "${Complex_BINARY_DIR}/Library/custom_target1.txt")
+
+add_dependencies(custom_target1 create_file)
+
+#
+# Extra coverage
+#
+set_source_files_properties(file2 PROPERTIES ABSTRACT 1)
+
+install_files(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
+install_files(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)
+
+# Test creating a library that is not built by default.
+add_library(notInAllLib EXCLUDE_FROM_ALL notInAllLib.cxx)
+
+# Create an imported target for if(TARGET) test in Executable dir.
+# That test should not see this target.
+add_library(LibImportedTarget UNKNOWN IMPORTED)
+
+# Test generation of preprocessed sources.
+if("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)
+ if(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE)
+ # Skip running this part of the test on certain platforms
+ # until they are fixed.
+ set(MAYBE_ALL ALL)
+ list(LENGTH CMAKE_OSX_ARCHITECTURES ARCH_COUNT)
+ if(ARCH_COUNT GREATER 1)
+ # OSX does not support preprocessing more than one architecture.
+ set(MAYBE_ALL)
+ endif()
+
+ # Custom target to try preprocessing invocation.
+ add_custom_target(test_preprocess ${MAYBE_ALL}
+ COMMAND ${CMAKE_COMMAND} -E remove CMakeFiles/create_file.dir/create_file.i
+ COMMAND ${CMAKE_MAKE_PROGRAM} create_file.i
+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/test_preprocess.cmake
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ )
+ endif()
+endif()
diff --git a/Tests/Complex/Library/ExtraSources/file1.cxx b/Tests/Complex/Library/ExtraSources/file1.cxx
new file mode 100644
index 0000000000..e22812e51d
--- /dev/null
+++ b/Tests/Complex/Library/ExtraSources/file1.cxx
@@ -0,0 +1,4 @@
+int file1()
+{
+ return 1;
+}
diff --git a/Tests/Complex/Library/ExtraSources/file1.h b/Tests/Complex/Library/ExtraSources/file1.h
new file mode 100644
index 0000000000..ce0d818a3d
--- /dev/null
+++ b/Tests/Complex/Library/ExtraSources/file1.h
@@ -0,0 +1 @@
+int file1();
diff --git a/Tests/Complex/Library/SystemDir/testSystemDir.h b/Tests/Complex/Library/SystemDir/testSystemDir.h
new file mode 100644
index 0000000000..73be3538ef
--- /dev/null
+++ b/Tests/Complex/Library/SystemDir/testSystemDir.h
@@ -0,0 +1,2 @@
+// Purposely leave off the return type to create a warning.
+foo() { return 0; }
diff --git a/Tests/Complex/Library/TestLink.c b/Tests/Complex/Library/TestLink.c
new file mode 100644
index 0000000000..25dee082f4
--- /dev/null
+++ b/Tests/Complex/Library/TestLink.c
@@ -0,0 +1,8 @@
+int TestLinkGetType()
+{
+#ifdef CMakeTestLinkShared_EXPORTS
+ return 0;
+#else
+ return 1;
+#endif
+}
diff --git a/Tests/Complex/Library/create_file.cxx b/Tests/Complex/Library/create_file.cxx
new file mode 100644
index 0000000000..050ed0bac3
--- /dev/null
+++ b/Tests/Complex/Library/create_file.cxx
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf(stderr, "Missing name of file to create.\n");
+ return EXIT_FAILURE;
+ }
+
+ FILE *stream = fopen(argv[1], "w");
+ if(stream == NULL)
+ {
+ fprintf(stderr, "Unable to open %s for writing!\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ if(fclose(stream))
+ {
+ fprintf(stderr, "Unable to close %s!\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ fprintf(stdout, ">> Creating %s!\n", argv[1]);
+
+ return EXIT_SUCCESS;
+}
diff --git a/Tests/Complex/Library/dummy b/Tests/Complex/Library/dummy
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/Complex/Library/dummy
diff --git a/Tests/Complex/Library/empty.h b/Tests/Complex/Library/empty.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/Complex/Library/empty.h
diff --git a/Tests/Complex/Library/file2.cxx b/Tests/Complex/Library/file2.cxx
new file mode 100644
index 0000000000..863fcaa51b
--- /dev/null
+++ b/Tests/Complex/Library/file2.cxx
@@ -0,0 +1,10 @@
+#include <string.h>
+
+#ifdef CMAKE_IS_REALLY_FUN
+This is a problem. Looks like REMOVE_DEFINITION does not work
+#endif
+
+int file2()
+{
+ return 1;
+}
diff --git a/Tests/Complex/Library/file2.h b/Tests/Complex/Library/file2.h
new file mode 100644
index 0000000000..dea4b80b1a
--- /dev/null
+++ b/Tests/Complex/Library/file2.h
@@ -0,0 +1 @@
+int file2();
diff --git a/Tests/Complex/Library/notInAllLib.cxx b/Tests/Complex/Library/notInAllLib.cxx
new file mode 100644
index 0000000000..5d928f44a6
--- /dev/null
+++ b/Tests/Complex/Library/notInAllLib.cxx
@@ -0,0 +1,5 @@
+int notInAllLibFunc() { return 0; }
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif
diff --git a/Tests/Complex/Library/sharedFile.cxx b/Tests/Complex/Library/sharedFile.cxx
new file mode 100644
index 0000000000..cafac68f45
--- /dev/null
+++ b/Tests/Complex/Library/sharedFile.cxx
@@ -0,0 +1,6 @@
+#include "sharedFile.h"
+
+int sharedFunction()
+{
+ return 1;
+}
diff --git a/Tests/Complex/Library/sharedFile.h b/Tests/Complex/Library/sharedFile.h
new file mode 100644
index 0000000000..65ac2e2ba8
--- /dev/null
+++ b/Tests/Complex/Library/sharedFile.h
@@ -0,0 +1,12 @@
+#if defined(_WIN32) || defined(WIN32) /* Win32 version */
+#ifdef CMakeTestLibraryShared_EXPORTS
+# define CMakeTest_EXPORT __declspec(dllexport)
+#else
+# define CMakeTest_EXPORT __declspec(dllimport)
+#endif
+#else
+/* unix needs nothing */
+#define CMakeTest_EXPORT
+#endif
+
+CMakeTest_EXPORT int sharedFunction();
diff --git a/Tests/Complex/Library/testConly.c b/Tests/Complex/Library/testConly.c
new file mode 100644
index 0000000000..a7d20b0b58
--- /dev/null
+++ b/Tests/Complex/Library/testConly.c
@@ -0,0 +1,13 @@
+#include "testConly.h"
+#include <stdio.h>
+
+int CsharedFunction()
+{
+#ifndef TEST_C_FLAGS
+ printf("TEST_C_FLAGS failed\n");
+ return 0;
+#else
+ printf("Passed: TEST_C_FLAGS passed\n");
+#endif
+ return 1;
+}
diff --git a/Tests/Complex/Library/testConly.h b/Tests/Complex/Library/testConly.h
new file mode 100644
index 0000000000..ba8458923d
--- /dev/null
+++ b/Tests/Complex/Library/testConly.h
@@ -0,0 +1,13 @@
+#if defined(_WIN32) || defined(WIN32) /* Win32 version */
+#ifdef CMakeTestCLibraryShared_EXPORTS
+# define CMakeTest_EXPORT __declspec(dllexport)
+#else
+# define CMakeTest_EXPORT __declspec(dllimport)
+#endif
+#else
+/* unix needs nothing */
+#define CMakeTest_EXPORT
+#endif
+
+CMakeTest_EXPORT int CsharedFunction();
+
diff --git a/Tests/Complex/Library/test_preprocess.cmake b/Tests/Complex/Library/test_preprocess.cmake
new file mode 100644
index 0000000000..4c8ec21748
--- /dev/null
+++ b/Tests/Complex/Library/test_preprocess.cmake
@@ -0,0 +1,7 @@
+set(TEST_FILE CMakeFiles/create_file.dir/create_file.i)
+file(READ ${TEST_FILE} CONTENTS)
+if("${CONTENTS}" MATCHES "Unable to close")
+ message(STATUS "${TEST_FILE} created successfully!")
+else()
+ message(FATAL_ERROR "${TEST_FILE} creation failed!")
+endif()
diff --git a/Tests/Complex/VarTests.cmake b/Tests/Complex/VarTests.cmake
new file mode 100644
index 0000000000..70b803a1e5
--- /dev/null
+++ b/Tests/Complex/VarTests.cmake
@@ -0,0 +1,184 @@
+#
+# Test SET
+#
+set (ZERO_VAR 0)
+set (ZERO_VAR2 0)
+
+if(ZERO_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED)
+endif()
+
+set(ONE_VAR 1)
+set(ONE_VAR2 1)
+set(STRING_VAR "CMake is great" CACHE STRING "test a cache variable")
+
+#
+# Test VARIABLE_REQUIRES
+#
+variable_requires(ONE_VAR
+ ONE_VAR_IS_DEFINED ONE_VAR)
+
+#
+# Test various IF/ELSE combinations
+#
+if(NOT ZERO_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_NOT)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_NOT)
+endif()
+
+if(NOT ONE_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_NOT2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_NOT2)
+endif()
+
+if(ONE_VAR AND ONE_VAR2)
+ add_definitions(-DSHOULD_BE_DEFINED_AND)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_AND)
+endif()
+
+if(ONE_VAR AND ZERO_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_AND2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_AND2)
+endif()
+
+if(ZERO_VAR OR ONE_VAR2)
+ add_definitions(-DSHOULD_BE_DEFINED_OR)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_OR)
+endif()
+
+if(ZERO_VAR OR ZERO_VAR2)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_OR2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_OR2)
+endif()
+
+if(STRING_VAR MATCHES "^CMake")
+ add_definitions(-DSHOULD_BE_DEFINED_MATCHES)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_MATCHES)
+endif()
+
+if(STRING_VAR MATCHES "^foo")
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_MATCHES2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_MATCHES2)
+endif()
+
+if(COMMAND "IF")
+ add_definitions(-DSHOULD_BE_DEFINED_COMMAND)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_COMMAND)
+endif()
+
+if(COMMAND "ROQUEFORT")
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_COMMAND2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_COMMAND2)
+endif()
+
+if (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
+ add_definitions(-DSHOULD_BE_DEFINED_EXISTS)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_EXISTS)
+endif ()
+
+if (EXISTS ${Complex_SOURCE_DIR}/roquefort.txt)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_EXISTS2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_EXISTS2)
+endif ()
+
+if (IS_DIRECTORY ${Complex_SOURCE_DIR})
+ add_definitions(-DSHOULD_BE_DEFINED_IS_DIRECTORY)
+endif ()
+
+if (NOT IS_DIRECTORY ${Complex_SOURCE_DIR}/VarTests.cmake)
+ add_definitions(-DSHOULD_BE_DEFINED_IS_DIRECTORY2)
+endif ()
+
+set (SNUM1_VAR "1")
+set (SNUM2_VAR "2")
+set (SNUM3_VAR "1")
+
+
+if (SNUM1_VAR LESS SNUM2_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_LESS)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_LESS)
+endif ()
+
+if (SNUM2_VAR LESS SNUM1_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_LESS2)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_LESS2)
+endif ()
+
+if (SNUM2_VAR GREATER SNUM1_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_GREATER)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_GREATER)
+endif ()
+
+if (SNUM2_VAR EQUAL SNUM1_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_EQUAL)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_EQUAL)
+endif ()
+
+if (SNUM3_VAR EQUAL SNUM1_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_EQUAL)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_EQUAL)
+endif ()
+
+if (SNUM1_VAR GREATER SNUM2_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_GREATER2)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_GREATER2)
+endif ()
+
+set (SSTR1_VAR "abc")
+set (SSTR2_VAR "bcd")
+
+if (SSTR1_VAR STRLESS SSTR2_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_STRLESS)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_STRLESS)
+endif ()
+
+if (SSTR2_VAR STRLESS SSTR1_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_STRLESS2)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_STRLESS2)
+endif ()
+
+if (SSTR2_VAR STRGREATER SSTR1_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_STRGREATER)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_STRGREATER)
+endif ()
+
+if (SSTR1_VAR STRGREATER SSTR2_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_STRGREATER2)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_STRGREATER2)
+endif ()
+
+#
+# Test FOREACH
+#
+foreach (INDEX 1 2)
+ set(FOREACH_VAR${INDEX} "VALUE${INDEX}")
+endforeach()
+
+set(FOREACH_CONCAT "")
+foreach (INDEX a;b;c;d;e;f;g)
+ set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}")
+endforeach()
diff --git a/Tests/Complex/cmTestConfigure.h.in b/Tests/Complex/cmTestConfigure.h.in
new file mode 100644
index 0000000000..d7424b1845
--- /dev/null
+++ b/Tests/Complex/cmTestConfigure.h.in
@@ -0,0 +1,76 @@
+// Test SET, VARIABLE_REQUIRES
+
+#cmakedefine ONE_VAR
+#cmakedefine ONE_VAR_IS_DEFINED
+#cmakedefine ZERO_VAR
+
+#define STRING_VAR "${STRING_VAR}"
+
+// Test FOREACH
+
+#define FOREACH_VAR1 "${FOREACH_VAR1}"
+#define FOREACH_VAR2 "${FOREACH_VAR2}"
+#define FOREACH_CONCAT "${FOREACH_CONCAT}"
+
+// Test WHILE
+#define WHILE_VALUE ${while_var}
+
+// Test LOAD_CACHE
+
+#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}"
+#define CACHE_TEST_VAR2 "${CACHE_TEST_VAR2}"
+#define CACHE_TEST_VAR3 "${CACHE_TEST_VAR3}"
+#cmakedefine CACHE_TEST_VAR_EXCLUDED
+#define CACHE_TEST_VAR_INTERNAL "${CACHE_TEST_VAR_INTERNAL}"
+
+// Test internal CMake vars from C++ flags
+
+#cmakedefine CMAKE_NO_STD_NAMESPACE
+#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS
+#cmakedefine CMAKE_NO_ANSI_STRING_STREAM
+#cmakedefine CMAKE_NO_ANSI_FOR_SCOPE
+
+#cmakedefine01 SHOULD_BE_ZERO
+#cmakedefine01 SHOULD_BE_ONE
+// Needed to check for files
+
+#define BINARY_DIR "${Complex_BINARY_DIR}"
+
+// Test FIND_LIBRARY
+
+#define FIND_DUMMY_LIB "${FIND_DUMMY_LIB}"
+
+// Test SET_SOURCE_FILES_PROPERTIES
+
+#cmakedefine FILE_HAS_ABSTRACT
+#cmakedefine FILE_HAS_WRAP_EXCLUDE
+#define FILE_COMPILE_FLAGS "${FILE_COMPILE_FLAGS}"
+
+#define TEST_SEP "${TEST_SEP}"
+
+// Test registry read
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define REGISTRY_TEST_PATH "${REGISTRY_TEST_PATH}"
+#endif
+
+// Test Remove command
+#define REMOVE_STRING "${REMOVE_STRING}"
+
+// Test IF inside FOREACH
+#cmakedefine IF_INSIDE_FOREACH_THEN_EXECUTED
+#cmakedefine IF_INSIDE_FOREACH_ELSE_EXECUTED
+
+// Test SET CACHE FORCE
+#cmakedefine FORCE_TEST
+#define CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+
+#define CMAKE_SHARED_MODULE_PREFIX "${CMAKE_SHARED_MODULE_PREFIX}"
+#define CMAKE_SHARED_MODULE_SUFFIX "${CMAKE_SHARED_MODULE_SUFFIX}"
+
+// test elseif
+#cmakedefine ELSEIF_RESULT
+
+// test parenthesis in conditionals
+#cmakedefine CONDITIONAL_PARENTHESES
+
diff --git a/Tests/Complex/cmTestConfigureEscape.h.in b/Tests/Complex/cmTestConfigureEscape.h.in
new file mode 100644
index 0000000000..39a8bd627d
--- /dev/null
+++ b/Tests/Complex/cmTestConfigureEscape.h.in
@@ -0,0 +1 @@
+#define STRING_WITH_QUOTES "${STRING_WITH_QUOTES}"
diff --git a/Tests/Complex/cmTestGeneratedHeader.h.in b/Tests/Complex/cmTestGeneratedHeader.h.in
new file mode 100644
index 0000000000..0e9dd3ff37
--- /dev/null
+++ b/Tests/Complex/cmTestGeneratedHeader.h.in
@@ -0,0 +1 @@
+#define GENERATED_HEADER_INCLUDED
diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt
new file mode 100644
index 0000000000..3b73e709a8
--- /dev/null
+++ b/Tests/ComplexOneConfig/CMakeLists.txt
@@ -0,0 +1,411 @@
+#
+# A more complex test case
+#
+cmake_minimum_required(VERSION 2.4)
+project (Complex)
+
+# Try setting a new policy. The IF test is for coverage.
+if(POLICY CMP0003)
+ cmake_policy(SET CMP0003 NEW)
+
+ cmake_policy(GET CMP0003 P3)
+ if(NOT "${P3}" STREQUAL "NEW")
+ message(FATAL_ERROR "cmake_policy(GET) did not report NEW!")
+ endif()
+endif()
+
+# It is not recommended to set a policy to OLD, but this test
+# covers the OLD behavior of some policies.
+foreach(p
+ CMP0029
+ CMP0032
+ CMP0033
+ CMP0034
+ CMP0043
+ CMP0050
+ )
+ if(POLICY ${p})
+ cmake_policy(SET ${p} OLD)
+ endif()
+endforeach()
+
+# Test building without per-rule echo lines in Makefiles.
+set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
+
+set(CPACK_SOURCE_IGNORE_FILES "~$;\\.cvsignore$;^C:/hoffman/My Builds/testcase.*/CVS/;^C:/hoffman/My Builds/testcase.*/\\.svn/;^C:/hoffman/My Builds/testcase.*/sweigart/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/eos2001/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_tables_new/;^C:/hoffman/My Builds/testcase/COPYING$;^C:/hoffman/My Builds/testcase/INSTALL$;^C:/hoffman/My Builds/testcase/Makefile$;^C:/hoffman/My Builds/testcase/Makefile\\.in$;^C:/hoffman/My Builds/testcase/.*\\.lo$;^C:/hoffman/My Builds/testcase/.*\\.la$;^C:/hoffman/My Builds/testcase/mkinstalldirs$;^C:/hoffman/My Builds/testcase/missing$;^C:/hoffman/My Builds/testcase/ltmain\\.sh$;^C:/hoffman/My Builds/testcase/libtool$;^C:/hoffman/My Builds/testcase/install-sh$;^C:/hoffman/My Builds/testcase/configure$;^C:/hoffman/My Builds/testcase/config\\.sub$;^C:/hoffman/My Builds/testcase/config\\.status$;^C:/hoffman/My Builds/testcase/config\\.log$;^C:/hoffman/My Builds/testcase/config\\.guess$;^C:/hoffman/My Builds/testcase/autom4te\\.cache$;^C:/hoffman/My Builds/testcase/aclocal\\.m4$;^C:/hoffman/My Builds/testcase/depcomp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10_corr$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_scvh$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.rgbtip\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.zahb\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.085\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.mem$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.tex\\.bak$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j16\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j26\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j36\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_JNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Jseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_KNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Kseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check34_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check35_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check36_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check43_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check44_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check45_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check46_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check47_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check48_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/Makefile$;^C:/hoffman/My Builds/testcase/www/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/.*\\.flc$;^C:/hoffman/My Builds/testcase/src/Makefile$;^C:/hoffman/My Builds/testcase/src/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/\\.deps$;^C:/hoffman/My Builds/testcase/src/\\.libs$;^C:/hoffman/My Builds/testcase/src/.*\\.la$;^C:/hoffman/My Builds/testcase/src/.*\\.lo$;^C:/hoffman/My Builds/testcase/src/make\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/statef.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_15$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_rel$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/hot_post_agb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgb_tip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/start_shellflash\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/white_dwarf\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/3order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/5order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/8order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check8_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check5_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effoo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/tc\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/include/Makefile\\.in$;^C:/hoffman/My Builds/testcase/include/Makefile$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/0\\.1\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_eos1a-eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_0\\.1\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_eos1a-eos1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/fort\\.91$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/oldversion_grid$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2005Ap&SS\\.298\\.\\.135S\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2007Ap&SS\\.307\\.\\.263C\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/astro-ph\\.9909168_eprint_submitted_to_High_Press\\.Res\\.16,331\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/statef_grid-newversion$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/old$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/make\\.out.*$;^C:/hoffman/My Builds/testcase/utils/.*\\.flc$;^C:/hoffman/My Builds/testcase/utils/Makefile$;^C:/hoffman/My Builds/testcase/utils/Makefile\\.in$;^C:/hoffman/My Builds/testcase/utils/\\.deps$;^C:/hoffman/My Builds/testcase/utils/\\.libs$;^C:/hoffman/My Builds/testcase/utils/.*\\.la$;^C:/hoffman/My Builds/testcase/utils/.*\\.lo$;^C:/hoffman/My Builds/testcase/utils/free_eos_test$;^C:/hoffman/My Builds/testcase/utils/test_rosenbrock$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check5\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check8\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_checknr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effoo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence_20070613$;^C:/hoffman/My Builds/testcase/www/eospaper/text$;^C:/hoffman/My Builds/testcase/www/eospaper/cassisi_book_fig$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.1\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/2\\.0\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.2\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.3\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.4\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.5\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.6\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/figures$;^C:/hoffman/My Builds/testcase/www/eospaper/old$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_JNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Jseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_KNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Kseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check34\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check35\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check36\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check44\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check45\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check46\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_1_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_2_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_linear_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_nr_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_series_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.1\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.3\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_linear\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_nr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.rgbtip\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.zahb\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.rgbtip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_linear$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_noexchange$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_nr$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/delta\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos1gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos2gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb_adjust/coulomb_adjust\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/rtc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/make\\.out.*$")
+
+#
+# Define a macro
+#
+macro(ASSERT value msg)
+ if (NOT ${value})
+ message ("Assertion failure:" ${msg} )
+ endif ()
+endmacro()
+
+# invoke the macro
+ASSERT(Complex_BINARY_DIR "The PROJECT command is broken")
+
+#
+# Define a var args macro, it must take two or four args
+#
+macro(TEST_ARGC value1 value2)
+ add_definitions(${value1} ${value2})
+ if (${ARGC} EQUAL 4)
+ add_definitions(${ARGV2} ${ARGV3})
+ endif ()
+endmacro()
+
+# invoke the macro
+TEST_ARGC(-DCMAKE_ARGV1 -DCMAKE_ARGV2 -DCMAKE_ARGV3 -DCMAKE_ARGV4)
+
+macro(TEST_VAR_ARG fa)
+ if("${ARGV}" STREQUAL "1;2;3")
+ message(STATUS "ARGV works")
+ else()
+ message(FATAL_ERROR "ARGV does not work; got \"${ARGV}\" instead of \"1;2;3\"")
+ endif()
+ if("${ARGN}" STREQUAL "2;3")
+ message(STATUS "ARGN works")
+ else()
+ message(FATAL_ERROR "ARGV does not work; got \"${ARGN}\" instead of \"2;3\"")
+ endif()
+endmacro()
+
+TEST_VAR_ARG(1 2 3)
+
+# Floating-point comparison test.
+if(2.4 LESS 2.4)
+ message(FATAL_ERROR "Failed: 2.4 LESS 2.4")
+endif()
+if(2.4 GREATER 2.4)
+ message(FATAL_ERROR "Failed: 2.4 GREATER 2.4")
+endif()
+if(NOT 2.4 EQUAL 2.4)
+ message(FATAL_ERROR "Failed: NOT 2.4 EQUAL 2.4")
+endif()
+
+if(CMAKE_SYSTEM MATCHES "OSF1-V")
+ if(NOT CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local -no_implicit_include ")
+ endif()
+endif()
+
+
+add_definitions(-DCMAKE_IS_FUN)
+add_definitions(-DCMAKE_IS_REALLY_FUN)
+set_property(DIRECTORY
+ PROPERTY COMPILE_DEFINITIONS_RELEASE
+ CMAKE_IS_FUN_IN_RELEASE_MODE
+ )
+set_property(DIRECTORY
+ PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO
+ CMAKE_IS_FUN_IN_RELEASE_MODE
+ )
+set_property(DIRECTORY
+ PROPERTY COMPILE_DEFINITIONS_MINSIZEREL
+ CMAKE_IS_FUN_IN_RELEASE_MODE
+ )
+
+set(TEST_SEP "a b c")
+separate_arguments(TEST_SEP)
+
+
+#
+# Include vars from a file and from a cache
+#
+if (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
+ include(${Complex_SOURCE_DIR}/VarTests.cmake)
+endif ()
+include(fileshouldnotbehere OPTIONAL)
+load_cache(${Complex_SOURCE_DIR}/Cache
+ EXCLUDE
+ CACHE_TEST_VAR_EXCLUDED
+ INCLUDE_INTERNALS
+ CACHE_TEST_VAR_INTERNAL)
+
+load_cache(${Complex_SOURCE_DIR}/Cache READ_WITH_PREFIX foo CACHE_TEST_VAR2)
+if(${fooCACHE_TEST_VAR2} MATCHES bar)
+ message("Load cache worked: ${fooCACHE_TEST_VAR2}")
+else()
+ message(FATAL_ERROR "Load cache with prefix failed: ${fooCACHE_TEST_VAR2}")
+endif()
+
+
+
+#
+# Specify include and lib dirs
+# (BEFORE is for coverage)
+#
+include_directories(
+ Library
+)
+
+include_directories(BEFORE
+ ${Complex_BINARY_DIR}
+)
+include_directories(SYSTEM Library/SystemDir)
+
+include_regular_expression("^(cmTest|file|sharedFile|test).*$" "^cmMissing")
+
+link_directories(
+ ${Complex_BINARY_DIR}/Library
+)
+
+#
+# check for SET CACHE FORCE
+#
+set(FORCE_TEST 1 CACHE STRING "a test")
+set(FORCE_TEST 0 CACHE STRING "a test" FORCE)
+
+#
+# Lib and exe path
+#
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${Complex_BINARY_DIR}/lib/static")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${Complex_BINARY_DIR}/lib")
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${Complex_BINARY_DIR}/bin")
+
+message (Test " " escape " " semi-colon " " \; \;)
+#
+# Exec program (TODO: test a result)
+# Increase coverage.
+#
+message("\nIgnore this message")
+option(NO_EXEC_PROGRAM "Do not test EXEC_PROGRAM" 0)
+if (NOT NO_EXEC_PROGRAM)
+ exec_program(${CMAKE_COMMAND} ARGS -E echo NO_EXEC_PROGRAM "${Complex_BINARY_DIR}")
+else ()
+ message("Set this option ON")
+endif ()
+
+mark_as_advanced(NO_EXEC_PROGRAM)
+mark_as_advanced(CLEAR NO_EXEC_PROGRAM)
+
+# Execute a process. Add coverage for this command.
+execute_process(
+ COMMAND ${CMAKE_COMMAND} -E echo "ABCDEFG"
+ OUTPUT_VARIABLE TEST_OUT
+ )
+if("${TEST_OUT}" STREQUAL "ABCDEFG\n")
+else()
+ message(SEND_ERROR "EXECUTE_PROCESS output test failed: [${TEST_OUT}]")
+endif()
+
+# This test has some problems on UNIX systems. Disabling for now.
+#
+# execute_process(
+# COMMAND ${CMAKE_COMMAND} -E echo "ABCDEFG"
+# COMMAND /process/does/not/exist
+# OUTPUT_QUIET
+# ERROR_QUIET
+# RESULT_VARIABLE RESULT
+# )
+# if("${RESULT}" STREQUAL "0")
+# message(SEND_ERROR
+# "EXECUTE_PROCESS result test failed with RESULT=[${RESULT}]")
+# else()
+# message(STATUS "EXECUTE_PROCESS result test passed with RESULT=[${RESULT}]")
+# endif()
+
+#
+# Create directory.
+# The 'complex' executable will then test if this dir exists,
+# sadly it won't be able to remove it.
+#
+make_directory("${Complex_BINARY_DIR}/make_dir")
+
+#
+# Test FIND_LIBARY
+# Create a dummy empty lib
+#
+configure_file(
+ ${Complex_SOURCE_DIR}/Library/dummy
+ ${Complex_BINARY_DIR}/Library/dummylib.lib
+ COPYONLY)
+foreach (ext ${CMAKE_SHLIB_SUFFIX};.so;.a;.sl)
+ configure_file(
+ ${Complex_SOURCE_DIR}/Library/dummy
+ ${Complex_BINARY_DIR}/Library/libdummylib${ext}
+ COPYONLY)
+endforeach ()
+
+find_library(FIND_DUMMY_LIB
+ dummylib
+ PATHS
+ ${Complex_BINARY_DIR}/Library DOC "find dummy lib")
+
+find_library(FIND_DUMMY_LIB
+ NAMES dummylib dummylib2
+ PATHS
+ ${Complex_BINARY_DIR}/Library DOC "find dummy lib")
+
+#
+# Test SET_SOURCE_FILES_PROPERTIES
+#
+set_source_files_properties(nonexisting_file2
+ GENERATED
+ ABSTRACT
+ WRAP_EXCLUDE
+ COMPILE_FLAGS "-foo -bar")
+
+get_source_file_property(FILE_HAS_ABSTRACT nonexisting_file2 ABSTRACT)
+get_source_file_property(FILE_HAS_WRAP_EXCLUDE nonexisting_file2 WRAP_EXCLUDE)
+get_source_file_property(FILE_COMPILE_FLAGS nonexisting_file2 COMPILE_FLAGS)
+
+set_source_files_properties(nonexisting_file3 PROPERTIES
+ GENERATED 1
+ ABSTRACT 1
+ WRAP_EXCLUDE 1
+ COMPILE_FLAGS "-foo -bar")
+get_source_file_property(FILE_HAS_ABSTRACT nonexisting_file3 ABSTRACT)
+get_source_file_property(FILE_HAS_WRAP_EXCLUDE nonexisting_file3 WRAP_EXCLUDE)
+get_source_file_property(FILE_COMPILE_FLAGS nonexisting_file3 COMPILE_FLAGS)
+
+#
+# Test registry (win32)
+# Create a file, put its path in a registry key, try to find the file in that
+# path using that registry key, then remove the file and the key
+#
+if (WIN32)
+ if (NOT UNIX)
+ set(dir "${Complex_BINARY_DIR}/registry_dir")
+ set(file "registry_test_dummy")
+ set(hkey "HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Tests\\Complex;registry_test")
+ configure_file(
+ ${Complex_SOURCE_DIR}/Library/dummy
+ "${dir}/${file}"
+ COPYONLY)
+ exec_program(${CMAKE_COMMAND} ARGS "-E write_regv \"${hkey}\" \"${dir}\"")
+ find_path(REGISTRY_TEST_PATH
+ ${file}
+ "[${hkey}]" DOC "Registry_Test_Path")
+ exec_program(${CMAKE_COMMAND} ARGS "-E delete_regv \"${hkey}\"")
+ exec_program(${CMAKE_COMMAND} ARGS "-E remove \"${dir}/${file}\"")
+ endif ()
+endif ()
+
+#
+# Test a set and a remove
+#
+set(REMOVE_STRING a b c d e f)
+set(removeVar1 c e)
+remove(REMOVE_STRING ${removeVar1} f)
+
+#
+# Test an IF inside a FOREACH.
+#
+foreach(x "a")
+ if(${x} MATCHES "a")
+ # Should always execute.
+ set(IF_INSIDE_FOREACH_THEN_EXECUTED 1)
+ else()
+ # Should never execute.
+ set(IF_INSIDE_FOREACH_ELSE_EXECUTED 1)
+ endif()
+endforeach()
+
+# test WHILE command
+set (while_var 1)
+while (while_var LESS 1000)
+ set(while_var ${while_var}0)
+endwhile()
+
+set(SHOULD_BE_ZERO )
+set(SHOULD_BE_ONE 1)
+
+# test elseif functionality, the mess below tries to catch problem
+# of clauses being executed early or late etc
+set (RESULT 3)
+if (RESULT EQUAL 1)
+ if (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+ elseif (RESULT EQUAL 3)
+ set (ELSEIF_RESULT 1)
+ endif ()
+elseif (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+elseif (RESULT EQUAL 3)
+ if (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+ elseif (RESULT EQUAL 3)
+ if (NOT ELSEIF_RESULT EQUAL 1)
+ set (ELSEIF_RESULT 2)
+ endif ()
+ endif ()
+elseif (RESULT EQUAL 4)
+ if (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+ elseif (RESULT EQUAL 3)
+ set (ELSEIF_RESULT 1)
+ endif ()
+else ()
+ if (RESULT EQUAL 2)
+ set (ELSEIF_RESULT 1)
+ elseif (RESULT EQUAL 3)
+ set (ELSEIF_RESULT 1)
+ endif ()
+endif ()
+
+if (NOT ELSEIF_RESULT EQUAL 2)
+ set (ELSEIF_RESULT 0)
+endif ()
+
+# test handling of parenthetical groups in conditionals
+if (2 GREATER 1 AND (4 LESS 3 OR 5 LESS 6) AND NOT (7 GREATER 8))
+ set(CONDITIONAL_PARENTHESES 1)
+endif()
+
+
+#
+# Configure file
+# (plug vars to #define so that they can be tested)
+#
+configure_file(
+ ${Complex_SOURCE_DIR}/cmTestConfigure.h.in
+ ${Complex_BINARY_DIR}/cmTestConfigure.h)
+
+set(STRING_WITH_QUOTES "\"hello world\"")
+# test CONFIGURE_FILE with ESCAPE_QUOTES on
+configure_file(
+ ${Complex_SOURCE_DIR}/cmTestConfigureEscape.h.in
+ ${Complex_BINARY_DIR}/cmTestConfigureEscape.h ESCAPE_QUOTES)
+
+# Test regular expression commands.
+string(REGEX MATCH "b" RESULT "abc")
+if(NOT RESULT)
+ message(SEND_ERROR "string(REGEX MATCH ... ) test failed.")
+endif()
+string(REGEX MATCHALL "b" RESULT "abcb")
+if(NOT RESULT)
+ message(SEND_ERROR "string(REGEX MATCHALL ... ) test failed.")
+endif()
+string(REGEX REPLACE ".([bd])." "[\\1]" RESULT "a(b)c(d)e")
+if(NOT RESULT STREQUAL "a[b]c[d]e")
+ message(SEND_ERROR
+ "string(REGEX REPLACE ... ) test failed (\"${RESULT}\" v. \"a[b]c[d]e\")")
+endif()
+
+#
+# This tests needs Ansi C++98
+#
+set(CMAKE_CXX_STANDARD 98)
+#
+# GNU extensions are needed for stricmp() on Windows.
+#
+set(CMAKE_CXX_EXTENSIONS TRUE)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+ CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
+
+#
+# Create the libs and the main exe
+#
+add_subdirectory(Library)
+add_subdirectory(Executable)
+subdir_depends(Executable Library)
+export_library_dependencies(${Complex_BINARY_DIR}/ComplexLibraryDepends.cmake)
+include(${Complex_BINARY_DIR}/ComplexLibraryDepends.cmake OPTIONAL)
diff --git a/Tests/ComplexOneConfig/Cache/CMakeCache.txt b/Tests/ComplexOneConfig/Cache/CMakeCache.txt
new file mode 100644
index 0000000000..17c55aa011
--- /dev/null
+++ b/Tests/ComplexOneConfig/Cache/CMakeCache.txt
@@ -0,0 +1,34 @@
+# This is the CMakeCache file.
+# For build in directory: d:/build/kitware/cmake/CMake-nmake/Tests/Complex
+# You can edit this file to change values found and used by cmake.
+# If you do not want to change any of the values, simply exit the editor.
+# If you do want to change a value, simply edit, save, and exit the editor.
+# The syntax for the file is as follows:
+# KEY:TYPE=VALUE
+# KEY is the name of a varible in the cache.
+# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT TYPE!.
+# VALUE is the current value for the KEY.
+
+########################
+# EXTERNAL cache entries
+########################
+
+//A var.
+CACHE_TEST_VAR1:STRING=foo
+
+//A var.
+CACHE_TEST_VAR2:FILEPATH=bar
+
+//A var.
+CACHE_TEST_VAR3:BOOL=1
+
+//A var.
+CACHE_TEST_VAR_EXCLUDED:BOOL=1
+
+
+########################
+# INTERNAL cache entries
+########################
+
+//A var.
+CACHE_TEST_VAR_INTERNAL:INTERNAL=bar
diff --git a/Tests/ComplexOneConfig/Executable/A.cxx b/Tests/ComplexOneConfig/Executable/A.cxx
new file mode 100644
index 0000000000..fb3eb08192
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/A.cxx
@@ -0,0 +1,9 @@
+// Include code from a header that should not be compiled separately.
+#include "A.hh"
+
+#include <stdio.h>
+int main()
+{
+ printf("#define A_VALUE %d\n", A());
+ return 0;
+}
diff --git a/Tests/ComplexOneConfig/Executable/A.h b/Tests/ComplexOneConfig/Executable/A.h
new file mode 100644
index 0000000000..25c45fcbf8
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/A.h
@@ -0,0 +1,4 @@
+// This header should not be compiled directly but through inclusion
+// in A.cxx through A.hh.
+extern int A();
+int A() { return 10; }
diff --git a/Tests/ComplexOneConfig/Executable/A.hh b/Tests/ComplexOneConfig/Executable/A.hh
new file mode 100644
index 0000000000..e6bab022e7
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/A.hh
@@ -0,0 +1,2 @@
+// This header should not be compiled directly but through inclusion in A.cxx
+#include "A.h"
diff --git a/Tests/ComplexOneConfig/Executable/A.txt b/Tests/ComplexOneConfig/Executable/A.txt
new file mode 100644
index 0000000000..8ee9462be0
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/A.txt
@@ -0,0 +1 @@
+This file should not be compiled!
diff --git a/Tests/ComplexOneConfig/Executable/CMakeLists.txt b/Tests/ComplexOneConfig/Executable/CMakeLists.txt
new file mode 100644
index 0000000000..01f1005de2
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/CMakeLists.txt
@@ -0,0 +1,169 @@
+#
+# Create exe.
+#
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
+
+# Create an imported target for if(TARGET) test below.
+add_library(ExeImportedTarget UNKNOWN IMPORTED)
+
+# Test if(TARGET) command.
+if(NOT TARGET CMakeTestLibrary)
+ message(FATAL_ERROR "if(NOT TARGET CMakeTestLibrary) returned true!")
+endif()
+if(NOT TARGET ExeImportedTarget)
+ message(FATAL_ERROR "if(NOT TARGET ExeImportedTarget) returned true!")
+endif()
+if(TARGET LibImportedTarget)
+ message(FATAL_ERROR "if(TARGET LibImportedTarget) returned true!")
+endif()
+if(TARGET NotATarget)
+ message(FATAL_ERROR "if(TARGET NotATarget) returned true!")
+endif()
+
+ # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
+set(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
+link_libraries(${COMPLEX_LIBS})
+
+# Test forcing a .cxx file to not build.
+set_source_files_properties(complex_nobuild.cxx PROPERTIES
+ HEADER_FILE_ONLY 1)
+
+# Test forcing a .c file to not build.
+# This makes sure a mixed language library is created
+# with header file only sources
+set_source_files_properties(complex_nobuild.c PROPERTIES
+ HEADER_FILE_ONLY 1)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+add_executable(A A.cxx A.hh A.h A.txt)
+add_custom_command(OUTPUT Aout.h COMMAND A > Aout.h VERBATIM)
+add_executable(complex complex testcflags.c Aout.h)
+# Sub1/NameConflictTest.c Sub2/NameConflictTest.c)
+add_executable(complex.file complex.file.cxx complex_nobuild.cxx
+ complex_nobuild.c)
+
+if (UNIX)
+ target_link_libraries(complex ${CMAKE_DL_LIBS})
+else()
+ if (NOT BORLAND)
+ if(NOT MINGW)
+ target_link_libraries(complex rpcrt4.lib)
+ endif()
+ endif()
+endif ()
+
+# Test linking to static lib when a shared lib has the same name.
+if(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
+ add_definitions(-DCOMPLEX_TEST_LINK_STATIC)
+ target_link_libraries(complex CMakeTestLinkStatic)
+endif()
+
+# can we get the path to a source file
+get_source_file_property(A_LOCATION A.cxx LOCATION)
+if ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")
+ add_definitions(-DCMAKE_FOUND_ACXX)
+endif ()
+
+# get the directory parent
+get_directory_property(P_VALUE PARENT_DIRECTORY)
+if ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")
+ add_definitions(-DCMAKE_FOUND_PARENT)
+endif ()
+
+# get the stack of listfiles
+include(Included.cmake)
+if ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
+ add_definitions(-DCMAKE_FOUND_LISTFILE_STACK)
+endif ()
+
+# Test add/remove definitions.
+add_definitions(
+ -DCOMPLEX_DEFINED_PRE
+ -DCOMPLEX_DEFINED
+ -DCOMPLEX_DEFINED_POST
+ -DCOMPLEX_DEFINED
+ )
+remove_definitions(-DCOMPLEX_DEFINED)
+
+# Test pre-build/pre-link/post-build rules for an executable.
+add_custom_command(TARGET complex PRE_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Executable/prebuild.txt")
+add_custom_command(TARGET complex PRE_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Executable/prelink.txt")
+add_custom_command(TARGET complex POST_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Executable/postbuild.txt")
+add_custom_command(TARGET complex POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy
+ "${Complex_BINARY_DIR}/Executable/postbuild.txt"
+ "${Complex_BINARY_DIR}/Executable/postbuild2.txt")
+
+set_source_files_properties(complex
+ COMPILE_FLAGS
+ "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
+ #" -DFILE_DEFINE_STRING=\\\"hello\\\""
+ OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
+)
+set_target_properties(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
+add_custom_command(
+ TARGET complex
+ SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
+ ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
+ OUTPUTS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
+ DEPENDS ${CMAKE_COMMAND}
+)
+
+# Test creating an executable that is not built by default.
+add_executable(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx)
+target_link_libraries(notInAllExe notInAllLib)
+
+# Test user-value flag mapping for the VS IDE.
+if(MSVC)
+ set_target_properties(notInAllExe PROPERTIES
+ LINK_FLAGS "/NODEFAULTLIB:LIBC;LIBCMT;MSVCRT")
+endif()
+
+# Test creating a custom target that builds not-in-all targets.
+add_custom_target(notInAllCustom)
+add_dependencies(notInAllCustom notInAllExe)
+
+#
+# Output the files required by 'complex' to a file.
+#
+# This test has been moved to the 'required' subdir so that it
+# has no side-effects on the current Makefile (duplicated source file
+# due to source list expansion done twice).
+#
+add_subdirectory(Temp)
+
+if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
+ add_executable(testSystemDir testSystemDir.cxx)
+ set_target_properties(testSystemDir PROPERTIES COMPILE_FLAGS "-Werror")
+endif()
+
+#
+# Extra coverage.Not used.
+#
+install_targets(/tmp complex)
+install_programs(/tmp complex)
+
+configure_file(
+ ${Complex_SOURCE_DIR}/Executable/cmVersion.h.in
+ ${Complex_BINARY_DIR}/cmVersion.h)
+
+source_group(A_GROUP ".cxx")
+source_group(B_GROUP REGULAR_EXPRESSION "cxx")
+source_group(C_GROUP FILES complex.cxx)
+
+file(WRITE ${Complex_BINARY_DIR}/A/libA.a "test")
+file(WRITE ${Complex_BINARY_DIR}/A/libC.a "test")
+file(WRITE ${Complex_BINARY_DIR}/B/libB.a "test")
+file(WRITE ${Complex_BINARY_DIR}/B/libA.a "test")
+file(WRITE ${Complex_BINARY_DIR}/C/libC.a "test")
+file(WRITE ${Complex_BINARY_DIR}/C/libB.a "test")
diff --git a/Tests/ComplexOneConfig/Executable/Included.cmake b/Tests/ComplexOneConfig/Executable/Included.cmake
new file mode 100644
index 0000000000..520a68be17
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/Included.cmake
@@ -0,0 +1,2 @@
+get_directory_property(LF_VALUE LISTFILE_STACK)
+
diff --git a/Tests/ComplexOneConfig/Executable/Sub1/NameConflictTest.c b/Tests/ComplexOneConfig/Executable/Sub1/NameConflictTest.c
new file mode 100644
index 0000000000..87203861f3
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/Sub1/NameConflictTest.c
@@ -0,0 +1,4 @@
+int NameConflictTest1()
+{
+ return 0;
+}
diff --git a/Tests/ComplexOneConfig/Executable/Sub2/NameConflictTest.c b/Tests/ComplexOneConfig/Executable/Sub2/NameConflictTest.c
new file mode 100644
index 0000000000..4a32572555
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/Sub2/NameConflictTest.c
@@ -0,0 +1,4 @@
+int NameConflictTest2()
+{
+ return 0;
+}
diff --git a/Tests/ComplexOneConfig/Executable/Temp/CMakeLists.txt b/Tests/ComplexOneConfig/Executable/Temp/CMakeLists.txt
new file mode 100644
index 0000000000..041fcff20c
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/Temp/CMakeLists.txt
@@ -0,0 +1,8 @@
+#
+# Output the files required by 'complex' to a file.
+# The 'complex' executable will then test if this file exists and remove it.
+# The contents of this file is not tested (absolute paths).
+#
+output_required_files(
+ ${Complex_SOURCE_DIR}/Executable/complex.cxx
+ ${Complex_BINARY_DIR}/Executable/Temp/complex-required.txt)
diff --git a/Tests/ComplexOneConfig/Executable/cmVersion.h.in b/Tests/ComplexOneConfig/Executable/cmVersion.h.in
new file mode 100644
index 0000000000..de7522d1db
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/cmVersion.h.in
@@ -0,0 +1 @@
+#define CMAKE_MINIMUM_REQUIRED_VERSION "${CMAKE_MINIMUM_REQUIRED_VERSION}"
diff --git a/Tests/ComplexOneConfig/Executable/complex.cxx b/Tests/ComplexOneConfig/Executable/complex.cxx
new file mode 100644
index 0000000000..31442bafa6
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/complex.cxx
@@ -0,0 +1,946 @@
+#include "cmTestConfigure.h"
+#include "cmTestConfigureEscape.h"
+#include "cmTestGeneratedHeader.h"
+#include "cmVersion.h"
+#include "ExtraSources/file1.h"
+#include "Aout.h"
+#include "file2.h"
+#include "sharedFile.h"
+extern "C" {
+#include "testConly.h"
+}
+#include <vector>
+#include <string>
+#include <iostream>
+#include <string.h>
+
+#include <stdio.h>
+#include <sys/stat.h>
+#if !defined(S_ISDIR)
+# define S_ISDIR(mode) ((mode) & _S_IFDIR)
+#endif
+
+#ifdef COMPLEX_TEST_LINK_STATIC
+extern "C"
+{
+ int TestLinkGetType();
+}
+#endif
+
+int cm_passed = 0;
+int cm_failed = 0;
+// ======================================================================
+
+void cmFailed(const char* Message, const char* m2= "", const char* m3 = "")
+{
+ std::cout << "FAILED: " << Message << m2 << m3 << "\n";
+ cm_failed++;
+}
+
+// ======================================================================
+
+void cmPassed(const char* Message, const char* m2="")
+{
+ std::cout << "Passed: " << Message << m2 << "\n";
+ cm_passed++;
+}
+
+#ifndef COMPLEX_DEFINED_PRE
+# error "COMPLEX_DEFINED_PRE not defined!"
+#endif
+
+#ifdef COMPLEX_DEFINED
+# error "COMPLEX_DEFINED is defined but it should not!"
+#endif
+
+#ifndef COMPLEX_DEFINED_POST
+# error "COMPLEX_DEFINED_POST not defined!"
+#endif
+
+#ifndef CMAKE_IS_REALLY_FUN
+# error This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
+#endif
+
+#if defined(NDEBUG) && !defined(CMAKE_IS_FUN_IN_RELEASE_MODE)
+# error Per-configuration directory-level definition not inherited.
+#endif
+
+// ======================================================================
+
+void TestAndRemoveFile(const char* filename)
+{
+ struct stat st;
+ if(stat(filename, &st) < 0)
+ {
+ cmFailed("Could not find file: ", filename);
+ }
+ else
+ {
+ if (remove(filename) < 0)
+ {
+ cmFailed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename);
+ }
+ else
+ {
+ cmPassed("Find and remove file: ", filename);
+ }
+ }
+}
+
+// ======================================================================
+
+void TestDir(const char* filename)
+{
+ struct stat st;
+ if(stat(filename, &st) < 0 || !S_ISDIR(st.st_mode))
+ {
+ cmFailed("Could not find dir: ", filename);
+ }
+ else
+ {
+ cmPassed("Find dir: ", filename);
+ }
+}
+
+// Here is a stupid function that tries to use std::string methods
+// so that the dec cxx compiler will instantiate the stuff that
+// we are using from the CMakeLib library....
+void ForceStringUse()
+{
+ std::vector<std::string> v;
+ std::vector<std::string> v2;
+ v = v2;
+ std::string cachetest = CACHE_TEST_VAR_INTERNAL;
+ v.push_back(cachetest);
+ v2 = v;
+ std::string x(5,'x');
+ char buff[5];
+ x.copy(buff, 1, 0);
+ x[0] = 'a';
+ std::string::size_type pos = 0;
+ x.replace(pos, pos, pos, 'x');
+ std::string copy = cachetest;
+ cachetest.find("bar");
+ cachetest.rfind("bar");
+ copy.append(cachetest);
+ copy = cachetest.substr(0, cachetest.size());
+}
+
+
+// defined in testcflags.c
+extern "C" int TestCFlags(char* m);
+extern "C" int TestTargetCompileFlags(char* m);
+
+#if 0
+// defined in Sub1/NameConflictTest.c
+extern "C" int NameConflictTest1();
+// defined in Sub2/NameConflictTest.c
+extern "C" int NameConflictTest2();
+#endif
+
+// ======================================================================
+
+int main()
+{
+#if 0
+ if(NameConflictTest1() == 0 && NameConflictTest2() == 0)
+ {
+ cmPassed("Sub dir with same named source works");
+ }
+ else
+ {
+ cmFailed("Sub dir with same named source fails");
+ }
+#endif
+ if(file1() != 1)
+ {
+ cmFailed("Call to file1 function from library failed.");
+ }
+ else
+ {
+ cmPassed("Call to file1 function returned 1.");
+ }
+#ifndef COMPLEX_TARGET_FLAG
+ cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
+#else
+ cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
+#endif
+
+#ifdef ELSEIF_RESULT
+ cmPassed("ELSEIF did work");
+#else
+ cmFailed("ELSEIF did not work");
+#endif
+
+#ifdef CONDITIONAL_PARENTHESES
+ cmPassed("CONDITIONAL_PARENTHESES did work");
+#else
+ cmFailed("CONDITIONAL_PARENTHESES did not work");
+#endif
+
+ if(file2() != 1)
+ {
+ cmFailed("Call to file2 function from library failed.");
+ }
+ else
+ {
+ cmPassed("Call to file2 function returned 1.");
+ }
+#ifndef TEST_CXX_FLAGS
+ cmFailed("CMake CMAKE_CXX_FLAGS is not being passed to the compiler!");
+#else
+ cmPassed("CMake CMAKE_CXX_FLAGS is being passed to the compiler.");
+#endif
+ std::string gen = CMAKE_GENERATOR;
+ // visual studio is currently broken for c flags
+ char msg[1024];
+ if(gen.find("Visual") == gen.npos)
+ {
+#ifdef TEST_C_FLAGS
+ cmFailed("CMake CMAKE_C_FLAGS are being passed to c++ files the compiler!");
+#else
+ cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
+#endif
+ if(TestCFlags(msg))
+ {
+ cmPassed(
+ "CMake CMAKE_C_FLAGS are being passed to c files and CXX flags are not.");
+ }
+ else
+ {
+ cmFailed(msg);
+ }
+ }
+ if(TestTargetCompileFlags(msg))
+ {
+ cmPassed(msg);
+ }
+ else
+ {
+ cmFailed(msg);
+ }
+
+ // ----------------------------------------------------------------------
+ // Test ADD_DEFINITIONS
+
+#ifndef CMAKE_IS_FUN
+ cmFailed("CMake is not fun, so it is broken and should be fixed.");
+#else
+ cmPassed("CMAKE_IS_FUN is defined.");
+#endif
+
+#if defined(CMAKE_ARGV1) && defined(CMAKE_ARGV2) && defined(CMAKE_ARGV3) && defined(CMAKE_ARGV4)
+ cmPassed("Variable args for MACROs are working.");
+#else
+ cmFailed("Variable args for MACROs are failing.");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test GET_SOURCE_FILE_PROPERTY for location
+#ifndef CMAKE_FOUND_ACXX
+ cmFailed("CMake did not get the location of A.cxx correctly");
+#else
+ cmPassed("CMake found A.cxx properly");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test GET_DIRECTORY_PROPERTY for parent
+#ifndef CMAKE_FOUND_PARENT
+ cmFailed("CMake did not get the location of the parent directory properly");
+#else
+ cmPassed("CMake found the parent directory properly");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test GET_DIRECTORY_PROPERTY for listfiles
+#ifndef CMAKE_FOUND_LISTFILE_STACK
+ cmFailed("CMake did not get the listfile stack properly");
+#else
+ cmPassed("CMake found the listfile stack properly");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test SET, VARIABLE_REQUIRES
+
+#ifdef SHOULD_NOT_BE_DEFINED
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED is defined.");
+#endif
+
+#ifndef ONE_VAR
+ cmFailed("cmakedefine is broken, ONE_VAR is not defined.");
+#else
+ cmPassed("ONE_VAR is defined.");
+#endif
+
+#ifndef ONE_VAR_IS_DEFINED
+ cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
+ "ONE_VAR_IS_DEFINED is not defined.");
+#else
+ cmPassed("ONE_VAR_IS_DEFINED is defined.");
+#endif
+
+#ifdef ZERO_VAR
+ cmFailed("cmakedefine is broken, ZERO_VAR is defined.");
+#else
+ cmPassed("ZERO_VAR is not defined.");
+#endif
+
+#ifndef STRING_VAR
+ cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
+#else
+ if(strcmp(STRING_VAR, "CMake is great") != 0)
+ {
+ cmFailed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
+ STRING_VAR);
+ }
+ else
+ {
+ cmPassed("STRING_VAR == ", STRING_VAR);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test various IF/ELSE combinations
+
+#ifdef SHOULD_NOT_BE_DEFINED_NOT
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_NOT is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_NOT
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_NOT is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_NOT2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_NOT2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_NOT2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_NOT2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_AND
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_AND is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_AND
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_AND is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_AND2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_AND2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_AND2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_AND2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_OR
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_OR is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_OR
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_OR is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_OR2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_OR2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_OR2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_OR2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_MATCHES
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_MATCHES
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_MATCHES is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_MATCHES2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_MATCHES2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_MATCHES2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_COMMAND
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_COMMAND
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_COMMAND is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_COMMAND2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_COMMAND2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_COMMAND2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_EXISTS
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_EXISTS
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_EXISTS is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_EXISTS2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_EXISTS2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_IS_DIRECTORY
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY is defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_IS_DIRECTORY2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_LESS
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_LESS is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_LESS
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_LESS is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_LESS2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_LESS2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_LESS2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_LESS2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_GREATER
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_GREATER is not defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_EQUAL
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EQUAL is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_EQUAL is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_EQUAL
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EQUAL is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_EQUAL is defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_GREATER
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_GREATER is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_GREATER2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_GREATER2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_GREATER2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_GREATER2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_STRLESS
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_STRLESS
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_STRLESS is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_STRLESS2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_STRLESS2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_STRLESS2 is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_STRGREATER
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_STRGREATER
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_STRGREATER is defined.");
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED_STRGREATER2
+ cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER2 is defined.");
+#else
+ cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER2 is not defined.");
+#endif
+
+#ifndef SHOULD_BE_DEFINED_STRGREATER2
+ cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER2 is not defined.\n");
+#else
+ cmPassed("SHOULD_BE_DEFINED_STRGREATER2 is defined.");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test FOREACH
+
+#ifndef FOREACH_VAR1
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_VAR1 is not defined.");
+#else
+ if(strcmp(FOREACH_VAR1, "VALUE1") != 0)
+ {
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_VAR1 == ", FOREACH_VAR1);
+ }
+ else
+ {
+ cmPassed("FOREACH_VAR1 == ", FOREACH_VAR1);
+ }
+#endif
+
+#ifndef FOREACH_VAR2
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_VAR2 is not defined.");
+#else
+ if(strcmp(FOREACH_VAR2, "VALUE2") != 0)
+ {
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_VAR2 == ", FOREACH_VAR2);
+ }
+ else
+ {
+ cmPassed("FOREACH_VAR2 == ", FOREACH_VAR2);
+ }
+#endif
+
+#ifndef FOREACH_CONCAT
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_CONCAT is not defined.");
+#else
+ if(strcmp(FOREACH_CONCAT, "abcdefg") != 0)
+ {
+ cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
+ "FOREACH_CONCAT == ", FOREACH_CONCAT);
+ }
+ else
+ {
+ cmPassed("FOREACH_CONCAT == ", FOREACH_CONCAT);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test WHILE
+
+ if(WHILE_VALUE != 1000)
+ {
+ cmFailed("WHILE command is not working");
+ }
+ else
+ {
+ cmPassed("WHILE command is working");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test LOAD_CACHE
+
+#ifndef CACHE_TEST_VAR1
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR1 is not defined.");
+#else
+ if(strcmp(CACHE_TEST_VAR1, "foo") != 0)
+ {
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
+ }
+ else
+ {
+ cmPassed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
+ }
+#endif
+
+#ifndef CACHE_TEST_VAR2
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR2 is not defined.");
+#else
+ if(strcmp(CACHE_TEST_VAR2, "bar") != 0)
+ {
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
+ }
+ else
+ {
+ cmPassed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
+ }
+#endif
+
+#ifndef CACHE_TEST_VAR3
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR3 is not defined.");
+#else
+ if(strcmp(CACHE_TEST_VAR3, "1") != 0)
+ {
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
+ }
+ else
+ {
+ cmPassed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
+ }
+#endif
+
+#ifdef CACHE_TEST_VAR_EXCLUDED
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command or cmakedefine is broken, "
+ "CACHE_TEST_VAR_EXCLUDED is defined (should not have been loaded).");
+#else
+ cmPassed("CACHE_TEST_VAR_EXCLUDED is not defined.");
+#endif
+
+#ifndef CACHE_TEST_VAR_INTERNAL
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR_INTERNAL is not defined.");
+#else
+ std::string cachetest = CACHE_TEST_VAR_INTERNAL;
+ if(cachetest != "bar")
+ {
+ cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
+ "CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
+ }
+ else
+ {
+ cmPassed("CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Some pre-build/pre-link/post-build custom-commands have been
+ // attached to the lib (see Library/).
+ // Each runs ${CREATE_FILE_EXE} which will create a file.
+ // It also copies that file again using cmake -E.
+ // Similar rules have been added to this executable.
+ //
+ // WARNING: if you run 'complex' manually, this *will* fail, because
+ // the file was removed the last time 'complex' was run, and it is
+ // only created during a build.
+
+ TestAndRemoveFile(BINARY_DIR "/Library/prebuild.txt");
+ TestAndRemoveFile(BINARY_DIR "/Library/prelink.txt");
+ TestAndRemoveFile(BINARY_DIR "/Library/postbuild.txt");
+ TestAndRemoveFile(BINARY_DIR "/Library/postbuild2.txt");
+ TestAndRemoveFile(BINARY_DIR "/Executable/prebuild.txt");
+ TestAndRemoveFile(BINARY_DIR "/Executable/prelink.txt");
+ TestAndRemoveFile(BINARY_DIR "/Executable/postbuild.txt");
+ TestAndRemoveFile(BINARY_DIR "/Executable/postbuild2.txt");
+
+ // ----------------------------------------------------------------------
+ // A custom target has been created (see Library/).
+ // It runs ${CREATE_FILE_EXE} which will create a file.
+ //
+ // WARNING: if you run 'complex' manually, this *will* fail, because
+ // the file was removed the last time 'complex' was run, and it is
+ // only created during a build.
+
+ TestAndRemoveFile(BINARY_DIR "/Library/custom_target1.txt");
+
+ // ----------------------------------------------------------------------
+ // A directory has been created.
+
+ TestDir(BINARY_DIR "/make_dir");
+
+ // ----------------------------------------------------------------------
+ // Test OUTPUT_REQUIRED_FILES
+ // The files required by 'complex' have been output to a file.
+ // The contents of this file is not tested (absolute paths).
+ //
+ // WARNING: if you run 'complex' manually, this *will* fail, because
+ // the file was removed the last time 'complex' was run, and it is
+ // only created during a build.
+
+ TestAndRemoveFile(BINARY_DIR "/Executable/Temp/complex-required.txt");
+
+ // ----------------------------------------------------------------------
+ // Test FIND_LIBRARY
+
+#ifndef FIND_DUMMY_LIB
+ cmFailed("the CONFIGURE_FILE command is broken, "
+ "FIND_DUMMY_LIB is not defined.");
+#else
+ if(strstr(FIND_DUMMY_LIB, "dummylib") == NULL)
+ {
+ cmFailed("the FIND_LIBRARY or CONFIGURE_FILE command is broken, "
+ "FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
+ }
+ else
+ {
+ cmPassed("FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test SET_SOURCE_FILES_PROPERTIES
+
+#ifndef FILE_HAS_EXTRA_COMPILE_FLAGS
+ cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
+#else
+ cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
+#endif
+
+#if 0 // Disable until implemented everywhere.
+#ifndef FILE_DEFINE_STRING
+ cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag");
+#else
+ if(strcmp(FILE_DEFINE_STRING, "hello") != 0)
+ {
+ cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag correctly");
+ }
+ else
+ {
+ cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_DEFINE_STRING flag");
+ }
+#endif
+#endif
+
+#ifndef FILE_HAS_ABSTRACT
+ cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting ABSTRACT flag");
+#else
+ cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting ABSTRACT flag");
+#endif
+
+#ifndef FILE_HAS_WRAP_EXCLUDE
+ cmFailed("FILE_HAS_WRAP_EXCLUDE failed at setting WRAP_EXCLUDE flag");
+#else
+ cmPassed("FILE_HAS_WRAP_EXCLUDE succeeded in setting WRAP_EXCLUDE flag");
+#endif
+
+#ifndef FILE_COMPILE_FLAGS
+ cmFailed("the CONFIGURE_FILE command is broken, FILE_COMPILE_FLAGS is not defined.");
+#else
+ if(strcmp(FILE_COMPILE_FLAGS, "-foo -bar") != 0)
+ {
+ cmFailed("the SET_SOURCE_FILES_PROPERTIES or CONFIGURE_FILE command is broken. FILE_COMPILE_FLAGS == ",
+ FILE_COMPILE_FLAGS);
+ }
+ else
+ {
+ cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting extra flags == ", FILE_COMPILE_FLAGS);
+ }
+#endif
+
+ // ----------------------------------------------------------------------
+ // Test registry (win32)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#ifndef REGISTRY_TEST_PATH
+ cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not defined.");
+#else
+ std::cout << "REGISTRY_TEST_PATH == " << REGISTRY_TEST_PATH << "\n";
+ if(stricmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0)
+ {
+ cmFailed("the 'read registry value' function or CONFIGURE_FILE command is broken. REGISTRY_TEST_PATH == ",
+ REGISTRY_TEST_PATH, " is not " BINARY_DIR "/registry_dir");
+ }
+ else
+ {
+ cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
+ }
+#endif
+#endif // defined(_WIN32) && !defined(__CYGWIN__)
+
+ if(strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "2.4") == 0)
+ {
+ cmPassed("CMAKE_MINIMUM_REQUIRED_VERSION is set to 2.4");
+ }
+ else
+ {
+ cmFailed("CMAKE_MINIMUM_REQUIRED_VERSION is not set to the expected 2.4");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test REMOVE command
+ if (strcmp("a;b;d",REMOVE_STRING) == 0)
+ {
+ cmPassed("REMOVE is working");
+ }
+ else
+ {
+ cmFailed("REMOVE is not working");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test SEPARATE_ARGUMENTS
+ if(strcmp("a;b;c", TEST_SEP) == 0)
+ {
+ cmPassed("SEPARATE_ARGUMENTS is working");
+ }
+ else
+ {
+ cmFailed("SEPARATE_ARGUMENTS is not working");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test Escape Quotes
+ if(strcmp("\"hello world\"", STRING_WITH_QUOTES) == 0)
+ {
+ cmPassed("ESCAPE_QUOTES is working");
+ }
+ else
+ {
+ cmFailed("ESCAPE_QUOTES is not working");
+ }
+
+
+ // ----------------------------------------------------------------------
+ // Test if IF command inside a FOREACH works.
+#if defined(IF_INSIDE_FOREACH_THEN_EXECUTED) && !defined(IF_INSIDE_FOREACH_ELSE_EXECUTED)
+ cmPassed("IF inside a FOREACH block works");
+#else
+ cmFailed("IF inside a FOREACH block is broken");
+#endif
+
+#if defined(GENERATED_HEADER_INCLUDED)
+ cmPassed("Generated header included by non-generated source works.");
+#else
+ cmFailed("Generated header included by non-generated source failed.");
+#endif
+ if(SHOULD_BE_ZERO == 0)
+ {
+ cmPassed("cmakedefine01 is working for 0");
+ }
+ else
+ {
+ cmFailed("cmakedefine01 is not working for 0");
+ }
+ if(SHOULD_BE_ONE == 1)
+ {
+ cmPassed("cmakedefine01 is working for 1");
+ }
+ else
+ {
+ cmFailed("cmakedefine01 is not working for 1");
+ }
+#ifdef FORCE_TEST
+ cmFailed("CMake SET CACHE FORCE");
+#else
+ cmPassed("CMake SET CACHE FORCE");
+#endif
+
+#ifdef COMPLEX_TEST_LINK_STATIC
+ if(TestLinkGetType())
+ {
+ cmPassed("Link to static over shared worked.");
+ }
+ else
+ {
+ cmFailed("Link to static over shared failed.");
+ }
+#endif
+
+#if defined(A_VALUE) && A_VALUE == 10
+ cmPassed("Single-character executable A worked.");
+#else
+ cmFailed("Single-character executable A failed.");
+#endif
+
+ // ----------------------------------------------------------------------
+ // Summary
+
+ std::cout << "Passed: " << cm_passed << "\n";
+ if(cm_failed)
+ {
+ std::cout << "Failed: " << cm_failed << "\n";
+ return cm_failed;
+ }
+ return 0;
+}
diff --git a/Tests/ComplexOneConfig/Executable/complex.file.cxx b/Tests/ComplexOneConfig/Executable/complex.file.cxx
new file mode 100644
index 0000000000..e873fa6440
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/complex.file.cxx
@@ -0,0 +1,8 @@
+#if 0
+#include "cmMissingHeader.h"
+#endif
+
+int main(int , char**)
+{
+ return 0;
+}
diff --git a/Tests/ComplexOneConfig/Executable/complex_nobuild.c b/Tests/ComplexOneConfig/Executable/complex_nobuild.c
new file mode 100644
index 0000000000..6b3c2c1e2d
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/complex_nobuild.c
@@ -0,0 +1 @@
+#error "This file should not be compiled."
diff --git a/Tests/ComplexOneConfig/Executable/complex_nobuild.cxx b/Tests/ComplexOneConfig/Executable/complex_nobuild.cxx
new file mode 100644
index 0000000000..6b3c2c1e2d
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/complex_nobuild.cxx
@@ -0,0 +1 @@
+#error "This file should not be compiled."
diff --git a/Tests/ComplexOneConfig/Executable/notInAllExe.cxx b/Tests/ComplexOneConfig/Executable/notInAllExe.cxx
new file mode 100644
index 0000000000..70275cd513
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/notInAllExe.cxx
@@ -0,0 +1,10 @@
+extern int notInAllLibFunc();
+
+int main()
+{
+ return notInAllLibFunc();
+}
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif
diff --git a/Tests/ComplexOneConfig/Executable/testSystemDir.cxx b/Tests/ComplexOneConfig/Executable/testSystemDir.cxx
new file mode 100644
index 0000000000..e4815c679a
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/testSystemDir.cxx
@@ -0,0 +1,3 @@
+#include <testSystemDir.h>
+
+int main() { return foo(); }
diff --git a/Tests/ComplexOneConfig/Executable/testcflags.c b/Tests/ComplexOneConfig/Executable/testcflags.c
new file mode 100644
index 0000000000..6c2dd5db32
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/testcflags.c
@@ -0,0 +1,26 @@
+#include <string.h>
+
+int TestTargetCompileFlags(char* m)
+{
+#ifndef COMPLEX_TARGET_FLAG
+ strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS did not work");
+ return 0;
+#endif
+ strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS worked");
+ return 1;
+}
+
+int TestCFlags(char* m)
+{
+ /* TEST_CXX_FLAGS should not be defined in a c file */
+#ifdef TEST_CXX_FLAGS
+ strcpy(m, "CMake CMAKE_CXX_FLAGS (TEST_CXX_FLAGS) found in c file.");
+ return 0;
+#endif
+ /* TEST_C_FLAGS should be defined in a c file */
+#ifndef TEST_C_FLAGS
+ strcpy(m, "CMake CMAKE_C_FLAGS (TEST_C_FLAGS) not found in c file.");
+ return 0;
+#endif
+ return 1;
+}
diff --git a/Tests/ComplexOneConfig/Library/CMakeLists.txt b/Tests/ComplexOneConfig/Library/CMakeLists.txt
new file mode 100644
index 0000000000..f00cbd611a
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/CMakeLists.txt
@@ -0,0 +1,140 @@
+remove_definitions(-DCMAKE_IS_REALLY_FUN)
+
+#
+# Small utility used to create file
+# UTILITY_SOURCE is used for coverage and for getting the exact name
+# of the executable.
+#
+utility_source(CREATE_FILE_EXE create_file "." create_file.cxx)
+add_executable(create_file create_file.cxx)
+set_target_properties(create_file PROPERTIES RUNTIME_OUTPUT_DIRECTORY ".")
+
+#
+# Create static library
+# SOURCE_FILES_REMOVE is used for Coverage. empty.h is included for coverage
+#
+aux_source_directory(ExtraSources LibrarySources)
+set(LibrarySources ${LibrarySources}
+ file2
+ empty
+ create_file.cxx
+ GENERATED
+ nonexisting_file)
+remove(LibrarySources create_file.cxx GENERATED nonexisting_file)
+add_library(CMakeTestLibrary ${LibrarySources})
+
+if(WIN32)
+ if(NOT CYGWIN)
+ if(NOT BORLAND)
+ if(NOT MINGW)
+ target_link_libraries(CMakeTestLibrary
+ debug
+ user32.lib)
+ target_link_libraries(CMakeTestLibrary
+ optimized
+ kernel32.lib)
+ endif()
+ endif()
+ endif()
+endif()
+
+#
+# Create shared library
+#
+set(SharedLibrarySources sharedFile)
+add_library(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
+add_library(CMakeTestCLibraryShared SHARED testConly.c)
+define_property(
+ TARGET PROPERTY FOO
+ BRIEF_DOCS "a test property"
+ FULL_DOCS "A simple etst proerty that means nothign and is used for nothing"
+ )
+set_target_properties(CMakeTestCLibraryShared PROPERTIES FOO BAR)
+if(NOT BEOS AND NOT WIN32 AND NOT HAIKU) # No libm on BeOS.
+ set_target_properties(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
+endif()
+get_target_property(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
+if(${FOO_BAR_VAR} MATCHES "BAR")
+else()
+ message(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}")
+endif()
+
+# Create static and shared lib of same name.
+if(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
+ add_library(CMakeTestLinkStatic STATIC TestLink.c)
+ add_library(CMakeTestLinkShared SHARED TestLink.c)
+ set_target_properties(CMakeTestLinkStatic CMakeTestLinkShared
+ PROPERTIES OUTPUT_NAME CMakeTestLink)
+endif()
+
+#
+# Attach pre-build/pre-link/post-build custom-commands to the lib.
+# Each runs ${CREATE_FILE_EXE} which will create a file.
+# The 'complex' executable will then test if this file exists and remove it.
+#
+add_dependencies(CMakeTestLibraryShared create_file)
+message("complex bin dir is ${Complex_BINARY_DIR}")
+add_custom_command(TARGET CMakeTestLibraryShared PRE_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Library/prebuild.txt")
+add_custom_command(TARGET CMakeTestLibraryShared PRE_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Library/prelink.txt")
+add_custom_command(TARGET CMakeTestLibraryShared POST_BUILD
+ COMMAND ${CREATE_FILE_EXE}
+ ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt")
+add_custom_command(TARGET CMakeTestLibraryShared POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy
+ "${Complex_BINARY_DIR}/Library/postbuild.txt"
+ "${Complex_BINARY_DIR}/Library/postbuild2.txt")
+
+#
+# Add a custom target.
+# It runs ${CREATE_FILE_EXE} which will create a file.
+# The 'complex' executable will then test if this file exists and remove it.
+#
+add_custom_target(custom_target1
+ ALL
+ ${CREATE_FILE_EXE}
+ "${Complex_BINARY_DIR}/Library/custom_target1.txt")
+
+add_dependencies(custom_target1 create_file)
+
+#
+# Extra coverage
+#
+set_source_files_properties(file2 PROPERTIES ABSTRACT 1)
+
+install_files(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
+install_files(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)
+
+# Test creating a library that is not built by default.
+add_library(notInAllLib EXCLUDE_FROM_ALL notInAllLib.cxx)
+
+# Create an imported target for if(TARGET) test in Executable dir.
+# That test should not see this target.
+add_library(LibImportedTarget UNKNOWN IMPORTED)
+
+# Test generation of preprocessed sources.
+if("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)
+ if(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE)
+ # Skip running this part of the test on certain platforms
+ # until they are fixed.
+ set(MAYBE_ALL ALL)
+ list(LENGTH CMAKE_OSX_ARCHITECTURES ARCH_COUNT)
+ if(ARCH_COUNT GREATER 1)
+ # OSX does not support preprocessing more than one architecture.
+ set(MAYBE_ALL)
+ endif()
+
+ # Custom target to try preprocessing invocation.
+ add_custom_target(test_preprocess ${MAYBE_ALL}
+ COMMAND ${CMAKE_COMMAND} -E remove CMakeFiles/create_file.dir/create_file.i
+ COMMAND ${CMAKE_MAKE_PROGRAM} create_file.i
+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/test_preprocess.cmake
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ )
+ endif()
+endif()
diff --git a/Tests/ComplexOneConfig/Library/ExtraSources/file1.cxx b/Tests/ComplexOneConfig/Library/ExtraSources/file1.cxx
new file mode 100644
index 0000000000..e22812e51d
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/ExtraSources/file1.cxx
@@ -0,0 +1,4 @@
+int file1()
+{
+ return 1;
+}
diff --git a/Tests/ComplexOneConfig/Library/ExtraSources/file1.h b/Tests/ComplexOneConfig/Library/ExtraSources/file1.h
new file mode 100644
index 0000000000..ce0d818a3d
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/ExtraSources/file1.h
@@ -0,0 +1 @@
+int file1();
diff --git a/Tests/ComplexOneConfig/Library/SystemDir/testSystemDir.h b/Tests/ComplexOneConfig/Library/SystemDir/testSystemDir.h
new file mode 100644
index 0000000000..73be3538ef
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/SystemDir/testSystemDir.h
@@ -0,0 +1,2 @@
+// Purposely leave off the return type to create a warning.
+foo() { return 0; }
diff --git a/Tests/ComplexOneConfig/Library/TestLink.c b/Tests/ComplexOneConfig/Library/TestLink.c
new file mode 100644
index 0000000000..25dee082f4
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/TestLink.c
@@ -0,0 +1,8 @@
+int TestLinkGetType()
+{
+#ifdef CMakeTestLinkShared_EXPORTS
+ return 0;
+#else
+ return 1;
+#endif
+}
diff --git a/Tests/ComplexOneConfig/Library/create_file.cxx b/Tests/ComplexOneConfig/Library/create_file.cxx
new file mode 100644
index 0000000000..050ed0bac3
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/create_file.cxx
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf(stderr, "Missing name of file to create.\n");
+ return EXIT_FAILURE;
+ }
+
+ FILE *stream = fopen(argv[1], "w");
+ if(stream == NULL)
+ {
+ fprintf(stderr, "Unable to open %s for writing!\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ if(fclose(stream))
+ {
+ fprintf(stderr, "Unable to close %s!\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ fprintf(stdout, ">> Creating %s!\n", argv[1]);
+
+ return EXIT_SUCCESS;
+}
diff --git a/Tests/ComplexOneConfig/Library/dummy b/Tests/ComplexOneConfig/Library/dummy
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/dummy
diff --git a/Tests/ComplexOneConfig/Library/empty.h b/Tests/ComplexOneConfig/Library/empty.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/empty.h
diff --git a/Tests/ComplexOneConfig/Library/file2.cxx b/Tests/ComplexOneConfig/Library/file2.cxx
new file mode 100644
index 0000000000..863fcaa51b
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/file2.cxx
@@ -0,0 +1,10 @@
+#include <string.h>
+
+#ifdef CMAKE_IS_REALLY_FUN
+This is a problem. Looks like REMOVE_DEFINITION does not work
+#endif
+
+int file2()
+{
+ return 1;
+}
diff --git a/Tests/ComplexOneConfig/Library/file2.h b/Tests/ComplexOneConfig/Library/file2.h
new file mode 100644
index 0000000000..dea4b80b1a
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/file2.h
@@ -0,0 +1 @@
+int file2();
diff --git a/Tests/ComplexOneConfig/Library/notInAllLib.cxx b/Tests/ComplexOneConfig/Library/notInAllLib.cxx
new file mode 100644
index 0000000000..5d928f44a6
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/notInAllLib.cxx
@@ -0,0 +1,5 @@
+int notInAllLibFunc() { return 0; }
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif
diff --git a/Tests/ComplexOneConfig/Library/sharedFile.cxx b/Tests/ComplexOneConfig/Library/sharedFile.cxx
new file mode 100644
index 0000000000..cafac68f45
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/sharedFile.cxx
@@ -0,0 +1,6 @@
+#include "sharedFile.h"
+
+int sharedFunction()
+{
+ return 1;
+}
diff --git a/Tests/ComplexOneConfig/Library/sharedFile.h b/Tests/ComplexOneConfig/Library/sharedFile.h
new file mode 100644
index 0000000000..65ac2e2ba8
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/sharedFile.h
@@ -0,0 +1,12 @@
+#if defined(_WIN32) || defined(WIN32) /* Win32 version */
+#ifdef CMakeTestLibraryShared_EXPORTS
+# define CMakeTest_EXPORT __declspec(dllexport)
+#else
+# define CMakeTest_EXPORT __declspec(dllimport)
+#endif
+#else
+/* unix needs nothing */
+#define CMakeTest_EXPORT
+#endif
+
+CMakeTest_EXPORT int sharedFunction();
diff --git a/Tests/ComplexOneConfig/Library/testConly.c b/Tests/ComplexOneConfig/Library/testConly.c
new file mode 100644
index 0000000000..a7d20b0b58
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/testConly.c
@@ -0,0 +1,13 @@
+#include "testConly.h"
+#include <stdio.h>
+
+int CsharedFunction()
+{
+#ifndef TEST_C_FLAGS
+ printf("TEST_C_FLAGS failed\n");
+ return 0;
+#else
+ printf("Passed: TEST_C_FLAGS passed\n");
+#endif
+ return 1;
+}
diff --git a/Tests/ComplexOneConfig/Library/testConly.h b/Tests/ComplexOneConfig/Library/testConly.h
new file mode 100644
index 0000000000..ba8458923d
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/testConly.h
@@ -0,0 +1,13 @@
+#if defined(_WIN32) || defined(WIN32) /* Win32 version */
+#ifdef CMakeTestCLibraryShared_EXPORTS
+# define CMakeTest_EXPORT __declspec(dllexport)
+#else
+# define CMakeTest_EXPORT __declspec(dllimport)
+#endif
+#else
+/* unix needs nothing */
+#define CMakeTest_EXPORT
+#endif
+
+CMakeTest_EXPORT int CsharedFunction();
+
diff --git a/Tests/ComplexOneConfig/Library/test_preprocess.cmake b/Tests/ComplexOneConfig/Library/test_preprocess.cmake
new file mode 100644
index 0000000000..4c8ec21748
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/test_preprocess.cmake
@@ -0,0 +1,7 @@
+set(TEST_FILE CMakeFiles/create_file.dir/create_file.i)
+file(READ ${TEST_FILE} CONTENTS)
+if("${CONTENTS}" MATCHES "Unable to close")
+ message(STATUS "${TEST_FILE} created successfully!")
+else()
+ message(FATAL_ERROR "${TEST_FILE} creation failed!")
+endif()
diff --git a/Tests/ComplexOneConfig/VarTests.cmake b/Tests/ComplexOneConfig/VarTests.cmake
new file mode 100644
index 0000000000..70b803a1e5
--- /dev/null
+++ b/Tests/ComplexOneConfig/VarTests.cmake
@@ -0,0 +1,184 @@
+#
+# Test SET
+#
+set (ZERO_VAR 0)
+set (ZERO_VAR2 0)
+
+if(ZERO_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED)
+endif()
+
+set(ONE_VAR 1)
+set(ONE_VAR2 1)
+set(STRING_VAR "CMake is great" CACHE STRING "test a cache variable")
+
+#
+# Test VARIABLE_REQUIRES
+#
+variable_requires(ONE_VAR
+ ONE_VAR_IS_DEFINED ONE_VAR)
+
+#
+# Test various IF/ELSE combinations
+#
+if(NOT ZERO_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_NOT)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_NOT)
+endif()
+
+if(NOT ONE_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_NOT2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_NOT2)
+endif()
+
+if(ONE_VAR AND ONE_VAR2)
+ add_definitions(-DSHOULD_BE_DEFINED_AND)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_AND)
+endif()
+
+if(ONE_VAR AND ZERO_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_AND2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_AND2)
+endif()
+
+if(ZERO_VAR OR ONE_VAR2)
+ add_definitions(-DSHOULD_BE_DEFINED_OR)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_OR)
+endif()
+
+if(ZERO_VAR OR ZERO_VAR2)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_OR2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_OR2)
+endif()
+
+if(STRING_VAR MATCHES "^CMake")
+ add_definitions(-DSHOULD_BE_DEFINED_MATCHES)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_MATCHES)
+endif()
+
+if(STRING_VAR MATCHES "^foo")
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_MATCHES2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_MATCHES2)
+endif()
+
+if(COMMAND "IF")
+ add_definitions(-DSHOULD_BE_DEFINED_COMMAND)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_COMMAND)
+endif()
+
+if(COMMAND "ROQUEFORT")
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_COMMAND2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_COMMAND2)
+endif()
+
+if (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
+ add_definitions(-DSHOULD_BE_DEFINED_EXISTS)
+else()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_EXISTS)
+endif ()
+
+if (EXISTS ${Complex_SOURCE_DIR}/roquefort.txt)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_EXISTS2)
+else()
+ add_definitions(-DSHOULD_BE_DEFINED_EXISTS2)
+endif ()
+
+if (IS_DIRECTORY ${Complex_SOURCE_DIR})
+ add_definitions(-DSHOULD_BE_DEFINED_IS_DIRECTORY)
+endif ()
+
+if (NOT IS_DIRECTORY ${Complex_SOURCE_DIR}/VarTests.cmake)
+ add_definitions(-DSHOULD_BE_DEFINED_IS_DIRECTORY2)
+endif ()
+
+set (SNUM1_VAR "1")
+set (SNUM2_VAR "2")
+set (SNUM3_VAR "1")
+
+
+if (SNUM1_VAR LESS SNUM2_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_LESS)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_LESS)
+endif ()
+
+if (SNUM2_VAR LESS SNUM1_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_LESS2)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_LESS2)
+endif ()
+
+if (SNUM2_VAR GREATER SNUM1_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_GREATER)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_GREATER)
+endif ()
+
+if (SNUM2_VAR EQUAL SNUM1_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_EQUAL)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_EQUAL)
+endif ()
+
+if (SNUM3_VAR EQUAL SNUM1_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_EQUAL)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_EQUAL)
+endif ()
+
+if (SNUM1_VAR GREATER SNUM2_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_GREATER2)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_GREATER2)
+endif ()
+
+set (SSTR1_VAR "abc")
+set (SSTR2_VAR "bcd")
+
+if (SSTR1_VAR STRLESS SSTR2_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_STRLESS)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_STRLESS)
+endif ()
+
+if (SSTR2_VAR STRLESS SSTR1_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_STRLESS2)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_STRLESS2)
+endif ()
+
+if (SSTR2_VAR STRGREATER SSTR1_VAR)
+ add_definitions(-DSHOULD_BE_DEFINED_STRGREATER)
+else ()
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_STRGREATER)
+endif ()
+
+if (SSTR1_VAR STRGREATER SSTR2_VAR)
+ add_definitions(-DSHOULD_NOT_BE_DEFINED_STRGREATER2)
+else ()
+ add_definitions(-DSHOULD_BE_DEFINED_STRGREATER2)
+endif ()
+
+#
+# Test FOREACH
+#
+foreach (INDEX 1 2)
+ set(FOREACH_VAR${INDEX} "VALUE${INDEX}")
+endforeach()
+
+set(FOREACH_CONCAT "")
+foreach (INDEX a;b;c;d;e;f;g)
+ set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}")
+endforeach()
diff --git a/Tests/ComplexOneConfig/cmTestConfigure.h.in b/Tests/ComplexOneConfig/cmTestConfigure.h.in
new file mode 100644
index 0000000000..d7424b1845
--- /dev/null
+++ b/Tests/ComplexOneConfig/cmTestConfigure.h.in
@@ -0,0 +1,76 @@
+// Test SET, VARIABLE_REQUIRES
+
+#cmakedefine ONE_VAR
+#cmakedefine ONE_VAR_IS_DEFINED
+#cmakedefine ZERO_VAR
+
+#define STRING_VAR "${STRING_VAR}"
+
+// Test FOREACH
+
+#define FOREACH_VAR1 "${FOREACH_VAR1}"
+#define FOREACH_VAR2 "${FOREACH_VAR2}"
+#define FOREACH_CONCAT "${FOREACH_CONCAT}"
+
+// Test WHILE
+#define WHILE_VALUE ${while_var}
+
+// Test LOAD_CACHE
+
+#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}"
+#define CACHE_TEST_VAR2 "${CACHE_TEST_VAR2}"
+#define CACHE_TEST_VAR3 "${CACHE_TEST_VAR3}"
+#cmakedefine CACHE_TEST_VAR_EXCLUDED
+#define CACHE_TEST_VAR_INTERNAL "${CACHE_TEST_VAR_INTERNAL}"
+
+// Test internal CMake vars from C++ flags
+
+#cmakedefine CMAKE_NO_STD_NAMESPACE
+#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS
+#cmakedefine CMAKE_NO_ANSI_STRING_STREAM
+#cmakedefine CMAKE_NO_ANSI_FOR_SCOPE
+
+#cmakedefine01 SHOULD_BE_ZERO
+#cmakedefine01 SHOULD_BE_ONE
+// Needed to check for files
+
+#define BINARY_DIR "${Complex_BINARY_DIR}"
+
+// Test FIND_LIBRARY
+
+#define FIND_DUMMY_LIB "${FIND_DUMMY_LIB}"
+
+// Test SET_SOURCE_FILES_PROPERTIES
+
+#cmakedefine FILE_HAS_ABSTRACT
+#cmakedefine FILE_HAS_WRAP_EXCLUDE
+#define FILE_COMPILE_FLAGS "${FILE_COMPILE_FLAGS}"
+
+#define TEST_SEP "${TEST_SEP}"
+
+// Test registry read
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define REGISTRY_TEST_PATH "${REGISTRY_TEST_PATH}"
+#endif
+
+// Test Remove command
+#define REMOVE_STRING "${REMOVE_STRING}"
+
+// Test IF inside FOREACH
+#cmakedefine IF_INSIDE_FOREACH_THEN_EXECUTED
+#cmakedefine IF_INSIDE_FOREACH_ELSE_EXECUTED
+
+// Test SET CACHE FORCE
+#cmakedefine FORCE_TEST
+#define CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+
+#define CMAKE_SHARED_MODULE_PREFIX "${CMAKE_SHARED_MODULE_PREFIX}"
+#define CMAKE_SHARED_MODULE_SUFFIX "${CMAKE_SHARED_MODULE_SUFFIX}"
+
+// test elseif
+#cmakedefine ELSEIF_RESULT
+
+// test parenthesis in conditionals
+#cmakedefine CONDITIONAL_PARENTHESES
+
diff --git a/Tests/ComplexOneConfig/cmTestConfigureEscape.h.in b/Tests/ComplexOneConfig/cmTestConfigureEscape.h.in
new file mode 100644
index 0000000000..39a8bd627d
--- /dev/null
+++ b/Tests/ComplexOneConfig/cmTestConfigureEscape.h.in
@@ -0,0 +1 @@
+#define STRING_WITH_QUOTES "${STRING_WITH_QUOTES}"
diff --git a/Tests/ComplexOneConfig/cmTestGeneratedHeader.h.in b/Tests/ComplexOneConfig/cmTestGeneratedHeader.h.in
new file mode 100644
index 0000000000..0e9dd3ff37
--- /dev/null
+++ b/Tests/ComplexOneConfig/cmTestGeneratedHeader.h.in
@@ -0,0 +1 @@
+#define GENERATED_HEADER_INCLUDED
diff --git a/Tests/ConfigSources/CMakeLists.txt b/Tests/ConfigSources/CMakeLists.txt
new file mode 100644
index 0000000000..c272257ca3
--- /dev/null
+++ b/Tests/ConfigSources/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+cmake_minimum_required(VERSION 3.0)
+
+project(ConfigSources)
+
+add_library(iface INTERFACE)
+set_property(TARGET iface PROPERTY INTERFACE_SOURCES
+ iface_src.cpp
+ $<$<CONFIG:Debug>:iface_debug_src.cpp>
+ $<$<CONFIG:Release>:does_not_exist.cpp>
+)
+
+add_executable(ConfigSources
+ $<$<CONFIG:Debug>:main.cpp>
+ $<$<CONFIG:Release>:does_not_exist.cpp>
+)
+target_link_libraries(ConfigSources iface)
diff --git a/Tests/ConfigSources/iface_debug.h b/Tests/ConfigSources/iface_debug.h
new file mode 100644
index 0000000000..a23d7374b8
--- /dev/null
+++ b/Tests/ConfigSources/iface_debug.h
@@ -0,0 +1,4 @@
+
+int iface_src();
+
+int iface_debug();
diff --git a/Tests/ConfigSources/iface_debug_src.cpp b/Tests/ConfigSources/iface_debug_src.cpp
new file mode 100644
index 0000000000..63b22fcd14
--- /dev/null
+++ b/Tests/ConfigSources/iface_debug_src.cpp
@@ -0,0 +1,7 @@
+
+#include "iface_debug.h"
+
+int iface_debug()
+{
+ return 0;
+}
diff --git a/Tests/ConfigSources/iface_src.cpp b/Tests/ConfigSources/iface_src.cpp
new file mode 100644
index 0000000000..c3a0c8f1e5
--- /dev/null
+++ b/Tests/ConfigSources/iface_src.cpp
@@ -0,0 +1,5 @@
+
+int iface_src()
+{
+ return 0;
+}
diff --git a/Tests/ConfigSources/main.cpp b/Tests/ConfigSources/main.cpp
new file mode 100644
index 0000000000..71af72f700
--- /dev/null
+++ b/Tests/ConfigSources/main.cpp
@@ -0,0 +1,7 @@
+
+#include "iface_debug.h"
+
+int main(int argc, char** argv)
+{
+ return iface_src() + iface_debug();
+}
diff --git a/Tests/Contracts/Trilinos/CMakeLists.txt b/Tests/Contracts/Trilinos/CMakeLists.txt
new file mode 100644
index 0000000000..f5757b5786
--- /dev/null
+++ b/Tests/Contracts/Trilinos/CMakeLists.txt
@@ -0,0 +1,103 @@
+cmake_minimum_required(VERSION 2.8)
+project(Trilinos)
+
+include(ExternalProject)
+
+include("${CMAKE_CURRENT_SOURCE_DIR}/LocalOverrides.cmake" OPTIONAL)
+include("${CMAKE_CURRENT_BINARY_DIR}/LocalOverrides.cmake" OPTIONAL)
+
+if(NOT DEFINED HOME)
+ if(DEFINED ENV{CTEST_REAL_HOME})
+ set(HOME "$ENV{CTEST_REAL_HOME}")
+ else()
+ set(HOME "$ENV{HOME}")
+ endif()
+
+ if(NOT HOME AND WIN32)
+ # Try for USERPROFILE as HOME equivalent:
+ string(REPLACE "\\" "/" HOME "$ENV{USERPROFILE}")
+
+ # But just use root of SystemDrive if USERPROFILE contains any spaces:
+ # (Default on XP and earlier...)
+ if(HOME MATCHES " ")
+ string(REPLACE "\\" "/" HOME "$ENV{SystemDrive}")
+ endif()
+ endif()
+endif()
+message(STATUS "HOME='${HOME}'")
+
+if(NOT DEFINED url)
+ set(url "http://www.cmake.org/files/contracts/trilinos-11.4.1.tar.gz")
+endif()
+message(STATUS "url='${url}'")
+
+if(NOT DEFINED md5)
+ set(md5 "28b6a3c7c0fb317b3a237997293faa8b")
+endif()
+message(STATUS "md5='${md5}'")
+
+string(SUBSTRING "${md5}" 0 8 shorttag)
+set(shorttag "m${shorttag}")
+
+set(download_dir "${HOME}/.cmake/Downloads")
+
+set(base_dir "${HOME}/.cmake/Contracts/${PROJECT_NAME}/${shorttag}")
+set(binary_dir "${base_dir}/build")
+set(script_dir "${base_dir}")
+set(source_dir "${base_dir}/src")
+
+if(NOT DEFINED BUILDNAME)
+ set(BUILDNAME "CMakeContract-${shorttag}")
+endif()
+message(STATUS "BUILDNAME='${BUILDNAME}'")
+
+if(NOT DEFINED SITE)
+ site_name(SITE)
+endif()
+message(STATUS "SITE='${SITE}'")
+
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/Dashboard.cmake.in"
+ "${script_dir}/Dashboard.cmake"
+ @ONLY)
+
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/ValidateBuild.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/ValidateBuild.cmake"
+ @ONLY)
+
+# Source dir for this project exists outside the CMake build tree because it
+# is absolutely huge. Source dir is therefore cached under a '.cmake/Contracts'
+# dir in your HOME directory. Downloads are cached under '.cmake/Downloads'
+#
+if(EXISTS "${source_dir}/cmake/ctest/TrilinosCTestDriverCore.cmake")
+ # If it exists already, download is a complete no-op:
+ ExternalProject_Add(download-${PROJECT_NAME}
+ DOWNLOAD_COMMAND ""
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ )
+else()
+ # If it does not yet exist, download pulls the tarball from the web (or
+ # no-ops if it already exists with the given md5 sum):
+ #
+ ExternalProject_Add(download-${PROJECT_NAME}
+ DOWNLOAD_DIR "${download_dir}"
+ URL "${url}"
+ URL_MD5 "${md5}"
+ SOURCE_DIR "${source_dir}"
+ PATCH_COMMAND ${CMAKE_COMMAND} -Dsource_dir=${source_dir} -P "${CMAKE_CURRENT_SOURCE_DIR}/Patch.cmake"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ )
+endif()
+
+ExternalProject_Add(build-${PROJECT_NAME}
+ DOWNLOAD_COMMAND ""
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ${CMAKE_COMMAND} -P "${script_dir}/Dashboard.cmake"
+ INSTALL_COMMAND ""
+ DEPENDS download-${PROJECT_NAME}
+ )
diff --git a/Tests/Contracts/Trilinos/Dashboard.cmake.in b/Tests/Contracts/Trilinos/Dashboard.cmake.in
new file mode 100644
index 0000000000..93d4f61ac0
--- /dev/null
+++ b/Tests/Contracts/Trilinos/Dashboard.cmake.in
@@ -0,0 +1,63 @@
+# This "cmake -P" script may be configured to drive a dashboard on any machine.
+#
+set(CTEST_BINARY_DIRECTORY "@binary_dir@")
+set(CTEST_BUILD_NAME "@BUILDNAME@")
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_SITE "@SITE@")
+set(CTEST_SOURCE_DIRECTORY "@source_dir@")
+
+# Set the environment:
+#
+set(ENV{CTEST_BUILD_NAME} "${CTEST_BUILD_NAME}")
+set(ENV{CTEST_CMAKE_GENERATOR} "${CTEST_CMAKE_GENERATOR}")
+set(ENV{CTEST_SITE} "${CTEST_SITE}")
+
+# Allow override of the environment on a per-client basis:
+#
+set(ENV_SCRIPT "$ENV{CMAKE_CONTRACT_Trilinos_ENV_SCRIPT}")
+if(ENV_SCRIPT AND EXISTS "${ENV_SCRIPT}")
+ include("${ENV_SCRIPT}")
+endif()
+
+# Empty build dir to start with:
+#
+message("Cleaning binary dir '${CTEST_BINARY_DIRECTORY}'")
+file(REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}")
+
+# Generate 'do-configure' script:
+#
+file(WRITE "${CTEST_BINARY_DIRECTORY}/do-configure" "
+\"${CMAKE_COMMAND}\" -G \"${CTEST_CMAKE_GENERATOR}\" \"${CTEST_SOURCE_DIRECTORY}\"
+")
+
+# Make the 'do-configure' script executable and execute it:
+#
+if(WIN32)
+ configure_file(
+ "${CTEST_BINARY_DIRECTORY}/do-configure"
+ "${CTEST_BINARY_DIRECTORY}/do-configure.cmd"
+ COPYONLY)
+ execute_process(COMMAND "${CTEST_BINARY_DIRECTORY}/do-configure.cmd"
+ WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}")
+else()
+ execute_process(COMMAND chmod +x "${CTEST_BINARY_DIRECTORY}/do-configure")
+ execute_process(COMMAND "${CTEST_BINARY_DIRECTORY}/do-configure"
+ WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}")
+endif()
+
+# Run an experimental Trilinos dashboard:
+#
+execute_process(COMMAND
+ "${CMAKE_CTEST_COMMAND}"
+ -S "${CTEST_SOURCE_DIRECTORY}/cmake/tribits/ctest/experimental_build_test.cmake"
+ -VV
+ WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
+ RESULT_VARIABLE rv
+ )
+
+if(NOT "${rv}" STREQUAL "0")
+ message("error(s) (or warnings or test failures) running Trilinos dashboard
+script experimental_build_test.cmake...
+ctest returned rv='${rv}'
+")
+endif()
diff --git a/Tests/Contracts/Trilinos/EnvScript.cmake b/Tests/Contracts/Trilinos/EnvScript.cmake
new file mode 100644
index 0000000000..dacb704f79
--- /dev/null
+++ b/Tests/Contracts/Trilinos/EnvScript.cmake
@@ -0,0 +1,32 @@
+# Site specific settings:
+#
+if(CTEST_SITE MATCHES "faraway")
+ set(CTEST_SITE "faraway.kitware")
+ set(ENV{CTEST_SITE} "${CTEST_SITE}")
+endif()
+
+if(CTEST_SITE STREQUAL "HUT11")
+ set(CTEST_SITE "hut11.kitware")
+ set(ENV{CTEST_SITE} "${CTEST_SITE}")
+
+ set(ENV{CLAPACK_DIR} "C:/T/clapack/b/clapack-prefix/src/clapack-build")
+endif()
+
+if(CTEST_SITE MATCHES "qwghlm")
+ set(CTEST_SITE "qwghlm.kitware")
+ set(ENV{CTEST_SITE} "${CTEST_SITE}")
+
+ set(ENV{PATH} "/opt/local/bin:$ENV{PATH}")
+ set(ENV{CC} "gcc-mp-4.3")
+ set(ENV{CXX} "g++-mp-4.3")
+ set(ENV{FC} "gfortran-mp-4.3")
+endif()
+
+# Submit to alternate CDash server:
+#
+#set(ENV{CTEST_DROP_SITE} "localhost")
+#set(ENV{CTEST_DROP_LOCATION} "/CDash/submit.php?project=Trilinos")
+
+# Limit packages built:
+#
+set(ENV{Trilinos_PACKAGES} "Teuchos;Kokkos")
diff --git a/Tests/Contracts/Trilinos/Patch.cmake b/Tests/Contracts/Trilinos/Patch.cmake
new file mode 100644
index 0000000000..6c619ac4fd
--- /dev/null
+++ b/Tests/Contracts/Trilinos/Patch.cmake
@@ -0,0 +1,38 @@
+if(NOT DEFINED source_dir)
+ message(FATAL_ERROR "variable 'source_dir' not defined")
+endif()
+
+
+if(NOT EXISTS "${source_dir}/CMakeLists.txt")
+ message(FATAL_ERROR "error: No CMakeLists.txt file to patch!")
+endif()
+
+set(text "
+
+#
+# Reference variables typically given as experimental_build_test configure
+# options to avoid CMake warnings about unused variables
+#
+
+message(\"Trilinos_ALLOW_NO_PACKAGES='\${Trilinos_ALLOW_NO_PACKAGES}'\")
+message(\"Trilinos_WARNINGS_AS_ERRORS_FLAGS='\${Trilinos_WARNINGS_AS_ERRORS_FLAGS}'\")
+")
+
+file(APPEND "${source_dir}/CMakeLists.txt" "${text}")
+
+
+if(NOT EXISTS "${source_dir}/CTestConfig.cmake")
+ message(FATAL_ERROR "error: No CTestConfig.cmake file to patch!")
+endif()
+
+set(text "
+
+#
+# Use newer than 10.6.1 CTestConfig settings from the Trilinos project.
+# Send the Trilinos dashboards to the new Trilinos CDash server instance.
+#
+set(CTEST_NIGHTLY_START_TIME \"04:00:00 UTC\") # 10 PM MDT or 9 PM MST
+set(CTEST_DROP_SITE \"testing.sandia.gov\")
+")
+
+file(APPEND "${source_dir}/CTestConfig.cmake" "${text}")
diff --git a/Tests/Contracts/Trilinos/RunTest.cmake b/Tests/Contracts/Trilinos/RunTest.cmake
new file mode 100644
index 0000000000..d661a4c1f5
--- /dev/null
+++ b/Tests/Contracts/Trilinos/RunTest.cmake
@@ -0,0 +1,7 @@
+# ValidateBuild.cmake is configured into this location when the test is built:
+set(dir "${CMAKE_CURRENT_BINARY_DIR}/Contracts/${project}")
+
+set(exe "${CMAKE_COMMAND}")
+set(args -P "${dir}/ValidateBuild.cmake")
+
+set(Trilinos_RUN_TEST ${exe} ${args})
diff --git a/Tests/Contracts/Trilinos/ValidateBuild.cmake.in b/Tests/Contracts/Trilinos/ValidateBuild.cmake.in
new file mode 100644
index 0000000000..fa38ada54a
--- /dev/null
+++ b/Tests/Contracts/Trilinos/ValidateBuild.cmake.in
@@ -0,0 +1,39 @@
+#
+# This code validates that the Trilinos build was "successful enough" (since it
+# is difficult to detect this from the caller of the experimental_build_test
+# dashboard script...)
+#
+set(binary_dir "@binary_dir@")
+message("binary_dir='${binary_dir}'")
+
+
+# Count *.exe files:
+#
+file(GLOB_RECURSE exes "${binary_dir}/*.exe")
+message(STATUS "exes='${exes}'")
+list(LENGTH exes len)
+if(len LESS 47)
+ message(FATAL_ERROR "len='${len}' is less than minimum expected='47' (count of executables)")
+endif()
+message(STATUS "Found len='${len}' *.exe files")
+
+
+# Try to find the Teuchos unit tests executable:
+#
+file(GLOB_RECURSE exe "${binary_dir}/TeuchosCore_UnitTest_UnitTests.exe")
+list(LENGTH exe len)
+if(NOT len EQUAL 1)
+ message(FATAL_ERROR "len='${len}' is not the expected='1' (count of TeuchosCore_UnitTest_UnitTests.exe)")
+endif()
+message(STATUS "Found exe='${exe}'")
+
+
+# Try to run it:
+execute_process(COMMAND ${exe} RESULT_VARIABLE rv)
+if(NOT "${rv}" STREQUAL "0")
+ message(FATAL_ERROR "rv='${rv}' is not the expected='0' (result of running TeuchosCore_UnitTest_UnitTests.exe)")
+endif()
+message(STATUS "Ran exe='${exe}' rv='${rv}'")
+
+
+message(STATUS "All Trilinos build validation tests pass.")
diff --git a/Tests/Contracts/VTK/CMakeLists.txt b/Tests/Contracts/VTK/CMakeLists.txt
new file mode 100644
index 0000000000..ef19325a47
--- /dev/null
+++ b/Tests/Contracts/VTK/CMakeLists.txt
@@ -0,0 +1,47 @@
+# The VTK external project for CMake
+# ---------------------------------------------------------------------------
+cmake_minimum_required(VERSION 2.8)
+project(VTK)
+include(ExternalProject)
+
+# find "HOME". VTK will be downloaded & built within a subdirectory.
+if(NOT DEFINED HOME)
+ if(DEFINED ENV{CTEST_REAL_HOME})
+ set(HOME "$ENV{CTEST_REAL_HOME}")
+ else()
+ set(HOME "$ENV{HOME}")
+ endif()
+
+ if(NOT HOME AND WIN32)
+ # Try for USERPROFILE as HOME equivalent:
+ string(REPLACE "\\" "/" HOME "$ENV{USERPROFILE}")
+
+ # But just use root of SystemDrive if USERPROFILE contains any spaces:
+ # (Default on XP and earlier...)
+ if(HOME MATCHES " ")
+ string(REPLACE "\\" "/" HOME "$ENV{SystemDrive}")
+ endif()
+ endif()
+endif()
+
+set(base_dir "${HOME}/.cmake/Contracts/VTK")
+
+if(NOT DEFINED SITE)
+ site_name(SITE)
+endif()
+
+# configure our dashboard script
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/Dashboard.cmake.in
+ ${base_dir}/Dashboard.cmake
+ @ONLY)
+
+# build & test VTK's release branch
+ExternalProject_Add(${PROJECT_NAME}
+ GIT_REPOSITORY "git://vtk.org/VTK.git"
+ GIT_TAG "release"
+ PREFIX ${base_dir}
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ${CMAKE_CTEST_COMMAND} -S "${base_dir}/Dashboard.cmake"
+ INSTALL_COMMAND ""
+)
diff --git a/Tests/Contracts/VTK/Dashboard.cmake.in b/Tests/Contracts/VTK/Dashboard.cmake.in
new file mode 100644
index 0000000000..c3d10f4bf2
--- /dev/null
+++ b/Tests/Contracts/VTK/Dashboard.cmake.in
@@ -0,0 +1,37 @@
+# This submission's role is to test leading edge of cmake development
+# against VTK release
+#
+# Maintainer: Zack Galbreath <zack.galbreath@kitware.com>
+#
+# This file was generated as part of the CMake/VTK Contracts test.
+# See <CMake-src>/Tests/Contracts/VTK/ for more information
+
+set(CTEST_SITE "@SITE@")
+set(CTEST_BUILD_NAME "Contracts.VTK")
+set(CTEST_DASHBOARD_ROOT "@base_dir@")
+set(CTEST_SOURCE_DIRECTORY "${CTEST_DASHBOARD_ROOT}/src/VTK")
+set(CTEST_BINARY_DIRECTORY "${CTEST_DASHBOARD_ROOT}/VTK-build")
+
+set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
+set(CTEST_CONFIGURATION_TYPE Debug)
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+# Assume a Linux build, with a make that supports -j9. Modify this script if
+# assumption is ever invalid.
+#
+set(CTEST_BUILD_COMMAND "@CMAKE_MAKE_PROGRAM@ -j9 -i")
+
+ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
+
+file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "
+ BUILD_EXAMPLES:BOOL=ON
+ BUILD_TESTING:BOOL=ON
+ VTK_WRAP_PYTHON:BOOL=ON
+ ExternalData_OBJECT_STORES:FILEPATH=@base_dir@/ExternalData
+")
+
+ctest_start(Nightly)
+ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
+ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}")
+ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}" INCLUDE "PythonSmoke")
+ctest_submit(BUILD "${CTEST_BINARY_DIRECTORY}")
diff --git a/Tests/Contracts/VTK/RunTest.cmake b/Tests/Contracts/VTK/RunTest.cmake
new file mode 100644
index 0000000000..65285cf77a
--- /dev/null
+++ b/Tests/Contracts/VTK/RunTest.cmake
@@ -0,0 +1,3 @@
+set(exe "$ENV{HOME}/.cmake/Contracts/VTK/VTK-build/bin/vtkCommonCoreCxxTests")
+set(args otherArrays)
+set(VTK_RUN_TEST ${exe} ${args})
diff --git a/Tests/Contracts/cse-snapshot/CMakeLists.txt b/Tests/Contracts/cse-snapshot/CMakeLists.txt
new file mode 100644
index 0000000000..913421010a
--- /dev/null
+++ b/Tests/Contracts/cse-snapshot/CMakeLists.txt
@@ -0,0 +1,114 @@
+cmake_minimum_required(VERSION 2.8)
+project(cse-snapshot)
+
+include(ExternalProject)
+
+include("${CMAKE_CURRENT_SOURCE_DIR}/LocalOverrides.cmake" OPTIONAL)
+include("${CMAKE_CURRENT_BINARY_DIR}/LocalOverrides.cmake" OPTIONAL)
+
+if(NOT DEFINED HOME)
+ if(DEFINED ENV{CTEST_REAL_HOME})
+ set(HOME "$ENV{CTEST_REAL_HOME}")
+ else()
+ set(HOME "$ENV{HOME}")
+ endif()
+endif()
+message(STATUS "HOME='${HOME}'")
+
+if(NOT DEFINED repo)
+ set(repo "git://public.kitware.com/cse.git")
+endif()
+message(STATUS "repo='${repo}'")
+
+if(NOT DEFINED tag)
+ set(tag "cc1dcb95439a21ab1d58f444d93481598414196e")
+endif()
+message(STATUS "tag='${tag}'")
+
+string(SUBSTRING "${tag}" 0 8 shorttag)
+
+set(base_dir "${HOME}/.cmake/Contracts/${PROJECT_NAME}/${shorttag}")
+set(binary_dir "${base_dir}/build")
+set(script_dir "${base_dir}")
+set(source_dir "${base_dir}/src")
+
+if(NOT DEFINED BUILDNAME)
+ set(BUILDNAME "CMakeContract-${shorttag}")
+endif()
+message(STATUS "BUILDNAME='${BUILDNAME}'")
+
+if(NOT DEFINED SITE)
+ site_name(SITE)
+endif()
+message(STATUS "SITE='${SITE}'")
+
+if(NOT DEFINED PROCESSOR_COUNT)
+ # Unknown:
+ set(PROCESSOR_COUNT 0)
+
+ # Linux:
+ set(cpuinfo_file "/proc/cpuinfo")
+ if(EXISTS "${cpuinfo_file}")
+ file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$")
+ list(LENGTH procs PROCESSOR_COUNT)
+ endif()
+
+ # Mac:
+ if(APPLE)
+ find_program(cmd_sysctl "sysctl")
+ if(cmd_sysctl)
+ execute_process(COMMAND ${cmd_sysctl} -n hw.ncpu
+ OUTPUT_VARIABLE PROCESSOR_COUNT
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ endif()
+ endif()
+
+ # Windows:
+ if(WIN32)
+ set(PROCESSOR_COUNT "$ENV{NUMBER_OF_PROCESSORS}")
+ endif()
+endif()
+message(STATUS "PROCESSOR_COUNT='${PROCESSOR_COUNT}'")
+
+find_package(Git)
+if(NOT GIT_EXECUTABLE)
+ message(FATAL_ERROR "error: could not find git")
+ # adjust PATH to find git, or set GIT_EXECUTABLE in LocalOverrides.cmake
+endif()
+message(STATUS "GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
+
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/Dashboard.cmake.in"
+ "${script_dir}/Dashboard.cmake"
+ @ONLY)
+
+# Source dir for this project exists outside the CMake build tree because it
+# is absolutely huge.
+#
+if(EXISTS "${source_dir}/.git")
+ # If it exists already, download is a complete no-op:
+ ExternalProject_Add(download-${PROJECT_NAME}
+ DOWNLOAD_COMMAND ""
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ )
+else()
+ # If it does not yet exist, download clones the git repository:
+ ExternalProject_Add(download-${PROJECT_NAME}
+ SOURCE_DIR "${source_dir}"
+ GIT_REPOSITORY "${repo}"
+ GIT_TAG "${tag}"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ )
+endif()
+
+ExternalProject_Add(build-${PROJECT_NAME}
+ DOWNLOAD_COMMAND ""
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ${CMAKE_CTEST_COMMAND} -S "${script_dir}/Dashboard.cmake"
+ INSTALL_COMMAND ""
+ DEPENDS download-${PROJECT_NAME}
+ )
diff --git a/Tests/Contracts/cse-snapshot/Dashboard.cmake.in b/Tests/Contracts/cse-snapshot/Dashboard.cmake.in
new file mode 100644
index 0000000000..138eb3f810
--- /dev/null
+++ b/Tests/Contracts/cse-snapshot/Dashboard.cmake.in
@@ -0,0 +1,76 @@
+# This "ctest -S" script may be configured to drive a nightly dashboard on any
+# Linux machine.
+#
+set(CTEST_BINARY_DIRECTORY "@binary_dir@")
+set(CTEST_BUILD_NAME "@BUILDNAME@")
+set(CTEST_SITE "@SITE@")
+set(CTEST_SOURCE_DIRECTORY "@source_dir@")
+set(PROCESSOR_COUNT "@PROCESSOR_COUNT@")
+
+# Assume a Linux build, with a make that supports -j. Modify this script if
+# assumption is ever invalid.
+#
+if(PROCESSOR_COUNT)
+ set(CTEST_BUILD_FLAGS "-j${PROCESSOR_COUNT}")
+endif()
+
+set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
+set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
+
+message("Cleaning binary dir '${CTEST_BINARY_DIRECTORY}'")
+ctest_empty_binary_directory("${CTEST_BINARY_DIRECTORY}")
+
+# Intentionally no ctest_update step in this script. This script is run as a
+# "Contract" test on a CMake dashboard submission using the just-built ctest
+# as the driver. The download step in the Contract CMakeLists file takes care
+# of setting up the source tree before calling this ctest -S script. The idea
+# is that the source tree will be the same every day, so there should not be
+# an "update" step for this build.
+
+message("Configuring CSE in binary dir '${CTEST_BINARY_DIRECTORY}'")
+set_property(GLOBAL PROPERTY SubProject "CSE-toplevel")
+set_property(GLOBAL PROPERTY Label "CSE-toplevel")
+
+ctest_start("Experimental")
+
+set(CSE_TOPLEVEL_OPTIONS
+ -DEXTERNAL_PROJECT_DASHBOARD_BUILD:BOOL=ON
+ -DEXTERNAL_PROJECT_TESTS:BOOL=ON
+ -DCSE_INSTALL_PREFIX:PATH=${CTEST_BINARY_DIRECTORY}/built
+ -DCSE_SUBSET:STRING=ALL
+ -DCTEST_SITE:STRING=${CTEST_SITE}
+)
+
+ctest_configure(OPTIONS "${CSE_TOPLEVEL_OPTIONS}")
+
+# The configure step produces a file listing the CSE packages and dependencies.
+# This file also generates Project.xml and stores it in ${PROJECT_XML}.
+#
+set(subprojects "")
+if(EXISTS "${CTEST_BINARY_DIRECTORY}/CSEBuildtimeDepends.cmake")
+ message("Including CSEBuildtimeDepends.cmake")
+ include("${CTEST_BINARY_DIRECTORY}/CSEBuildtimeDepends.cmake")
+ set(subprojects ${CSE_ALL_SORTED})
+ message("Submitting Project.xml")
+ ctest_submit(FILES ${PROJECT_XML})
+endif()
+
+message("Submitting CSE configure results")
+ctest_submit()
+
+if(subprojects)
+ message("Building by looping over subprojects...")
+ foreach(subproject ${subprojects})
+ message("########## ${subproject} ##########")
+ set_property(GLOBAL PROPERTY SubProject "${subproject}")
+ set_property(GLOBAL PROPERTY Label "${subproject}")
+ ctest_build(TARGET "${subproject}" APPEND)
+ message("Submitting ${subproject} build results")
+ ctest_submit(PARTS build)
+ endforeach()
+else()
+ message("Building all...")
+ ctest_build(APPEND)
+ message("Submitting build results")
+ ctest_submit(PARTS build)
+endif()
diff --git a/Tests/Contracts/cse-snapshot/RunTest.cmake b/Tests/Contracts/cse-snapshot/RunTest.cmake
new file mode 100644
index 0000000000..7eb630116a
--- /dev/null
+++ b/Tests/Contracts/cse-snapshot/RunTest.cmake
@@ -0,0 +1,3 @@
+set(exe "$ENV{HOME}/.cmake/Contracts/cse-snapshot/510345e4/build/built/Release/git-1.6.5.2/bin/git")
+set(args help clone)
+set(cse-snapshot_RUN_TEST ${exe} ${args})
diff --git a/Tests/CrossCompile/CMakeLists.txt b/Tests/CrossCompile/CMakeLists.txt
new file mode 100644
index 0000000000..121cb815e1
--- /dev/null
+++ b/Tests/CrossCompile/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required (VERSION 2.6)
+project(CrossCompile)
+
+unset(run_result CACHE)
+
+#Simulate the cross compile condition
+set(CMAKE_CROSSCOMPILING ON)
+
+add_executable(CrossCompile main.c)
+
+try_run(run_result compile_result
+ ${CrossCompile_BINARY_DIR}
+ ${CrossCompile_SOURCE_DIR}/main.c)
diff --git a/Tests/CrossCompile/main.c b/Tests/CrossCompile/main.c
new file mode 100644
index 0000000000..8488f4e58f
--- /dev/null
+++ b/Tests/CrossCompile/main.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/CustComDepend/CMakeLists.txt b/Tests/CustComDepend/CMakeLists.txt
new file mode 100644
index 0000000000..46276b2ef6
--- /dev/null
+++ b/Tests/CustComDepend/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required (VERSION 2.6)
+project(CustComDepend)
+include_directories("${CustComDepend_SOURCE_DIR}")
+add_definitions(-D_CRT_SECURE_NO_DEPRECATE=1)
+set(EXECUTABLE_OUTPUT_PATH ${CustComDepend_BINARY_DIR}/bin)
+add_executable(foo foo.cxx)
+add_custom_command(
+ OUTPUT ${CustComDepend_BINARY_DIR}/bar.c
+ COMMAND ${CustComDepend_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/foo
+ ${CustComDepend_BINARY_DIR}/bar.c
+ DEPENDS ${CustComDepend_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/foo
+)
+
+add_library(bar SHARED ${CustComDepend_BINARY_DIR}/bar.c)
diff --git a/Tests/CustComDepend/bar.h b/Tests/CustComDepend/bar.h
new file mode 100644
index 0000000000..d179464284
--- /dev/null
+++ b/Tests/CustComDepend/bar.h
@@ -0,0 +1,9 @@
+#ifdef _WIN32
+# ifdef bar_EXPORTS
+# define BAR_EXPORT __declspec( dllexport )
+# else
+# define BAR_EXPORT __declspec( dllimport )
+# endif
+#else
+# define BAR_EXPORT
+#endif
diff --git a/Tests/CustComDepend/foo.cxx b/Tests/CustComDepend/foo.cxx
new file mode 100644
index 0000000000..19dfcb1430
--- /dev/null
+++ b/Tests/CustComDepend/foo.cxx
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main(int ac, char** av)
+{
+ FILE* fout = fopen(av[1], "w");
+ printf("create %s\n", av[1]);
+ if(!fout)
+ {
+ return -1;
+ }
+ fprintf(fout, "#include <bar.h>\nBAR_EXPORT int bar(){ return 10;}\n");
+ fclose(fout);
+ return 0;
+}
+
diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt
new file mode 100644
index 0000000000..b97cd1642f
--- /dev/null
+++ b/Tests/CustomCommand/CMakeLists.txt
@@ -0,0 +1,485 @@
+#
+# Wrapping
+#
+cmake_minimum_required (VERSION 2.6)
+project (CustomCommand)
+
+add_subdirectory(GeneratedHeader)
+
+#
+# Lib and exe path
+#
+if(NOT DEFINED bin_dir)
+ set(bin_dir "bin")
+endif()
+
+set (LIBRARY_OUTPUT_PATH
+ ${PROJECT_BINARY_DIR}/${bin_dir} CACHE INTERNAL
+ "Single output directory for building all libraries.")
+
+set (EXECUTABLE_OUTPUT_PATH
+ ${PROJECT_BINARY_DIR}/${bin_dir} CACHE INTERNAL
+ "Single output directory for building all executables.")
+
+################################################################
+#
+# First test using a compiled generator to create a .c file
+#
+################################################################
+# add the executable that will generate the file
+add_executable(generator generator.cxx)
+
+################################################################
+#
+# Test using a wrapper to wrap a header file
+#
+################################################################
+# add the executable that will generate the file
+add_executable(wrapper wrapper.cxx)
+
+add_custom_command(
+ OUTPUT ${PROJECT_BINARY_DIR}/wrapped.c ${PROJECT_BINARY_DIR}/wrapped_help.c
+ DEPENDS wrapper
+ MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/wrapped.h
+ COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/wrapper
+ ${PROJECT_BINARY_DIR}/wrapped.c ${PROJECT_BINARY_DIR}/wrapped_help.c
+ ${CMAKE_CFG_INTDIR} # this argument tests passing of the configuration
+ VERBATIM # passing of configuration should work in this mode
+ )
+
+################################################################
+#
+# Test creating files from a custom target
+#
+################################################################
+add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}//doc1.dvi # test 2 slashes
+ DEPENDS ${PROJECT_SOURCE_DIR}/doc1.tex
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${PROJECT_SOURCE_DIR}/doc1.tex
+ ${PROJECT_BINARY_DIR}/doc1.dvi
+ )
+
+add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/doc1.h
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1.dvi to doc1temp.h."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1.dvi
+ ${PROJECT_BINARY_DIR}/doc1temp.h
+ )
+add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/doc1.h APPEND
+ DEPENDS ${PROJECT_BINARY_DIR}/doc1.dvi
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1temp.h to doc1.h."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1temp.h
+ ${PROJECT_BINARY_DIR}/doc1.h
+ COMMAND ${CMAKE_COMMAND} -E echo " Removing doc1temp.h."
+ COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/doc1temp.h
+ )
+
+# Add custom command to generate foo.h.
+add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/foo.h
+ DEPENDS ${PROJECT_SOURCE_DIR}/foo.h.in
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying foo.h.in to foo.h."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/foo.h.in
+ ${PROJECT_BINARY_DIR}/foo.h
+ )
+
+# Add the location of foo.h to the include path.
+include_directories(${PROJECT_BINARY_DIR})
+
+# Test generation of a file to the build tree without full path. As
+# of CMake 2.6 custom command outputs specified by relative path go in
+# the build tree.
+add_custom_command(
+ OUTPUT doc1.txt
+ COMMAND ${CMAKE_COMMAND} -E echo "Example Document Target" > doc1.txt
+ DEPENDS doc1.tex
+ VERBATIM
+ )
+
+# Add a custom target to drive generation of doc1.h.
+add_custom_target(TDocument ALL
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1.h to doc2.h."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1.h
+ ${PROJECT_BINARY_DIR}/doc2.h
+ DEPENDS doc1.txt ${PROJECT_BINARY_DIR}//doc1.h # test 2 slashes
+ COMMENT "Running top-level TDocument commands"
+ SOURCES doc1.tex
+ )
+
+# Setup a pre- and post-build pair that will fail if not run in the
+# proper order.
+add_custom_command(
+ TARGET TDocument PRE_BUILD
+ COMMAND ${CMAKE_COMMAND} -E echo " Writing doc1pre.txt."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/doc1.tex ${PROJECT_BINARY_DIR}/doc1pre.txt
+ COMMENT "Running TDocument pre-build commands"
+ )
+add_custom_command(
+ TARGET TDocument POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1pre.txt to doc2post.txt."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1pre.txt
+ ${PROJECT_BINARY_DIR}/doc2post.txt
+ COMMENT "Running TDocument post-build commands"
+ )
+
+# Setup a custom target that will fail if the POST_BUILD custom command
+# isn't run before it.
+add_custom_command(
+ OUTPUT doc3post.txt
+ DEPENDS ${PROJECT_BINARY_DIR}/doc2post.txt
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying doc2pre.txt to doc3post.txt."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc2post.txt
+ ${PROJECT_BINARY_DIR}/doc3post.txt
+ COMMENT "Running TDocument post-build dependent custom command"
+ )
+add_custom_target(doc3Post ALL DEPENDS doc3post.txt)
+add_dependencies(doc3Post TDocument)
+
+################################################################
+#
+# Test using a multistep generated file
+#
+################################################################
+add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/foo.pre
+ DEPENDS ${PROJECT_SOURCE_DIR}/foo.in
+ TDocument # Ensure doc1.h generates before this target
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${PROJECT_SOURCE_DIR}/foo.in
+ ${PROJECT_BINARY_DIR}/foo.pre
+ )
+
+add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/foo.c
+ DEPENDS ${PROJECT_BINARY_DIR}/foo.pre
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${PROJECT_BINARY_DIR}/foo.pre
+ ${PROJECT_BINARY_DIR}/foo.c
+ )
+
+# Add custom command to generate not_included.h, which is a header
+# file that is not included by any source in this project. This will
+# test whether all custom command outputs explicitly listed as sources
+# get generated even if they are not needed by an object file.
+add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/not_included.h
+ DEPENDS ${PROJECT_SOURCE_DIR}/foo.h.in
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/foo.h.in
+ ${PROJECT_BINARY_DIR}/not_included.h
+ )
+
+# Tell the executable where to find not_included.h.
+configure_file(
+ ${PROJECT_SOURCE_DIR}/config.h.in
+ ${PROJECT_BINARY_DIR}/config.h
+ @ONLY
+ )
+
+# add the executable
+add_executable(CustomCommand
+ ${PROJECT_BINARY_DIR}/foo.h
+ ${PROJECT_BINARY_DIR}/foo.c
+ ${PROJECT_BINARY_DIR}/wrapped.c
+ ${PROJECT_BINARY_DIR}/wrapped_help.c
+ ${PROJECT_BINARY_DIR}/generated.c
+ ${PROJECT_BINARY_DIR}/not_included.h
+ gen_redirect.c # default location for custom commands is in build tree
+ )
+
+# Add the rule to create generated.c at build time. This is placed
+# here to test adding the generation rule after referencing the
+# generated source in a target.
+add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/generated.c
+ DEPENDS $<1:generator> $<0:does_not_exist>
+ COMMAND generator
+ ARGS ${PROJECT_BINARY_DIR}/generated.c
+ )
+
+target_link_libraries(CustomCommand GeneratedHeader)
+
+##############################################################################
+# Test for using just the target name as executable in the COMMAND
+# section. Has to be recognized and replaced by CMake with the output
+# actual location of the executable.
+# Additionally the generator is created in an extra subdir after the
+# add_custom_command() is used.
+#
+# Test the same for add_custom_target()
+
+add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx
+ COMMAND generator_extern ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx
+ )
+
+add_executable(CustomCommandUsingTargetTest main.cxx ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx )
+
+add_custom_target(RunTarget
+ COMMAND generator_extern ${CMAKE_CURRENT_BINARY_DIR}/run_target.cxx
+ )
+
+add_custom_command(TARGET CustomCommandUsingTargetTest POST_BUILD
+ COMMAND dummy_generator ${CMAKE_CURRENT_BINARY_DIR}/generated_dummy.cxx)
+
+add_subdirectory(GeneratorInExtraDir)
+
+##############################################################################
+# Test shell operators in custom commands.
+
+add_executable(tcat tcat.cxx)
+
+# Test that list expansion from a generator expression works.
+set_property(TARGET tcat PROPERTY DEPSLIST tcat gen_redirect_in.c)
+
+add_custom_command(OUTPUT gen_redirect.c
+ DEPENDS $<TARGET_PROPERTY:tcat,DEPSLIST>
+ COMMAND tcat < ${CMAKE_CURRENT_SOURCE_DIR}/gen_redirect_in.c > gen_redirect.c
+ COMMAND ${CMAKE_COMMAND} -E echo "#endif" >> gen_redirect.c
+ VERBATIM
+ )
+
+##############################################################################
+# Test non-trivial command line arguments in custom commands.
+set(EXPECTED_ARGUMENTS)
+set(CHECK_ARGS)
+if(NOT MSVC71)
+ set(CHECK_ARGS -DPATH=c:/posix/path)
+endif()
+set(CHECK_ARGS
+ ${CHECK_ARGS}
+ c:/posix/path
+ c:\\windows\\path
+ 'single-quotes'
+ single'quote
+ \"double-quotes\"
+ "\\;semi-colons\\;"
+ "semi\\;colon"
+ `back-ticks`
+ back`tick
+ "(parens)"
+ "(lparen"
+ "rparen)"
+ {curly}
+ {lcurly}
+ rcurly}
+ <angle>
+ <langle
+ rangle>
+ [square]
+ [lsquare # these have funny behavior due to special cases for
+ rsquare] # windows registry value names in list expansion
+ $dollar-signs$
+ dollar$sign
+ &ampersands&x # Borland make does not like trailing ampersand
+ one&ampersand
+ @two-ats@
+ one@at
+ ~two-tilda~
+ one~tilda
+ ^two-carrots^
+ one^carrot
+ %two-percents%
+ one%percent
+ !two-exclamations!
+ one!exclamation
+ ?two-questions?
+ one?question
+ *two-stars*
+ one*star
+ =two+equals=
+ one=equals
+ _two-underscores_
+ one_underscore
+ ,two-commas,
+ one,comma
+ .two-periods.
+ one.period
+ |two-pipes|
+ one|pipe
+ |nopipe
+ "#two-pounds#"
+ "one#pound"
+ "#nocomment"
+ "c:/posix/path/with space"
+ "c:\\windows\\path\\with space"
+ "'single quotes with space'"
+ "single'quote with space"
+ "\"double-quotes with space\""
+ "\\;semi-colons w s\\;"
+ "semi\\;colon w s"
+ "`back-ticks` w s"
+ "back`tick w s"
+ "(parens) w s"
+ "(lparen w s"
+ "rparen) w s"
+ "{curly} w s"
+ "{lcurly w s"
+ "rcurly} w s"
+ "<angle> w s"
+ "<langle w s"
+ "rangle> w s"
+ "[square] w s"
+ "[lsquare w s" # these have funny behavior due to special cases for
+ "rsquare] w s" # windows registry value names in list expansion
+ "$dollar-signs$ w s"
+ "dollar$sign w s"
+ "&ampersands& w s"
+ "one&ampersand w s"
+ "@two-ats@ w s"
+ "one@at w s"
+ "~two-tilda~ w s"
+ "one~tilda w s"
+ "^two-carrots^ w s"
+ "one^carrot w s"
+ "%two-percents% w s"
+ "one%percent w s"
+ "!two-exclamations! w s"
+ "one!exclamation w s"
+ "*two-stars* w s"
+ "one*star w s"
+ "=two+equals= w s"
+ "one=equals w s"
+ "_two-underscores_ w s"
+ "one_underscore w s"
+ "?two-questions? w s"
+ "one?question w s"
+ ",two-commas, w s"
+ "one,comma w s"
+ ".two-periods. w s"
+ "one.period w s"
+ "|two-pipes| w s"
+ "one|pipe w s"
+ "#two-pounds# w s"
+ "one#pound w s"
+ ~ ` ! @ \# $ % ^ & _ - + = : "\;" \" ' , . ? "(" ")" { } []
+ )
+if(NOT MINGW)
+ # * # MinGW programs on windows always expands the wildcard!
+ # / # MSys make converts a leading slash to the mingw home directory
+ list(APPEND CHECK_ARGS * /)
+endif()
+
+# The windows command shell does not support a double quote by itself:
+# double\"quote
+# without messing up quoting of arguments following it.
+
+# Make tools need help with escaping a single backslash
+# \
+# at the end of a command because they think it is a continuation
+# character.
+
+# We now have special cases for shell operators:
+# | < > << >> &> 2>&1 1>&2
+# to allow custom commands to perform redirection.
+
+foreach(arg ${CHECK_ARGS} "")
+ set(ARG "${arg}")
+ string(REPLACE "\\" "\\\\" ARG "${ARG}")
+ string(REPLACE "\"" "\\\"" ARG "${ARG}")
+ set(EXPECTED_ARGUMENTS
+ "${EXPECTED_ARGUMENTS} \"${ARG}\",
+")
+endforeach()
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/check_command_line.c.in
+ ${CMAKE_CURRENT_BINARY_DIR}/check_command_line.c
+ @ONLY)
+add_executable(check_command_line
+ ${CMAKE_CURRENT_BINARY_DIR}/check_command_line.c)
+set(output_name "check_command_line")
+set_property(TARGET check_command_line
+ PROPERTY OUTPUT_NAME ${output_name})
+# set_target_properties(check_command_line PROPERTIES
+# COMPILE_FLAGS -DCHECK_COMMAND_LINE_VERBOSE)
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/command_line_check
+ COMMAND ${CMAKE_COMMAND} -DMARK_FILE=${CMAKE_CURRENT_BINARY_DIR}/check_mark.txt
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check_mark.cmake
+ COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${output_name}
+ ${CHECK_ARGS} ""
+ VERBATIM
+ COMMENT "Checking custom command line escapes (single'quote)"
+ )
+set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/command_line_check
+ PROPERTIES SYMBOLIC 1)
+add_custom_target(do_check_command_line ALL
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/command_line_check
+ COMMAND ${CMAKE_COMMAND} -E echo "Checking custom target command escapes"
+ COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${output_name}
+ ${CHECK_ARGS} ""
+ VERBATIM
+ COMMENT "Checking custom target command line escapes ($dollar-signs$)"
+ )
+add_dependencies(do_check_command_line check_command_line)
+
+add_custom_target(pre_check_command_line
+ COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/check_mark.txt
+ )
+add_dependencies(do_check_command_line pre_check_command_line)
+
+# <SameNameTest>
+#
+# Add a custom target called "SameName" -- then add a custom command in a
+# different target whose output is a full-path file called "SameName" -- then
+# add a second custom target that depends on the full-path file ".../SameName"
+#
+# At first, this reproduces a bug reported by a customer. After fixing it,
+# having this test here makes sure it stays fixed moving forward.
+#
+add_custom_command(
+ OUTPUT SameName1.txt
+ COMMAND ${CMAKE_COMMAND} -E touch SameName1.txt
+ )
+add_custom_target(SameName ALL
+ DEPENDS SameName1.txt
+ )
+
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/subdir/SameName
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/subdir
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/subdir/SameName
+ )
+add_custom_target(DifferentName ALL
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/subdir/SameName
+ )
+#
+# </SameNameTest>
+
+# Per-config target name and generator expressions.
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../PerConfig PerConfig)
+add_custom_command(
+ OUTPUT perconfig.out
+ COMMAND ${PerConfig_COMMAND}
+ DEPENDS ${PerConfig_DEPENDS}
+ VERBATIM
+ )
+set_property(SOURCE perconfig.out PROPERTY SYMBOLIC 1)
+add_custom_target(perconfig_target ALL
+ COMMAND ${CMAKE_COMMAND} -E echo "perconfig=$<TARGET_FILE:perconfig>" "config=$<CONFIGURATION>"
+ DEPENDS perconfig.out)
+
+# Test SOURCES in add_custom_target() with COMPILE_DEFINITIONS
+# which previously caused a crash in the makefile generators.
+add_custom_target(source_in_custom_target SOURCES source_in_custom_target.cpp)
+set_property(SOURCE source_in_custom_target
+ PROPERTY COMPILE_DEFINITIONS "TEST"
+)
+
+set(gen_path "${CMAKE_CURRENT_BINARY_DIR}//./foo")
+set(gen_file "${gen_path}/foo.cxx")
+
+add_custom_command(
+ OUTPUT "${gen_file}"
+ # Make sure the output directory exists before trying to write to it.
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${gen_path}"
+ COMMAND ${CMAKE_COMMAND} -E touch "${gen_file}"
+)
+
+add_library(NormOutput "${gen_file}")
+
+set(gen_path "${gen_path}/bar")
+set(gen_file "${gen_path}/bar.cxx")
+
+add_custom_command(
+ OUTPUT "${gen_path}"
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${gen_path}"
+)
+
+add_custom_command(
+ OUTPUT "${gen_file}"
+ DEPENDS "${gen_path}"
+ COMMAND ${CMAKE_COMMAND} -E touch "${gen_file}")
+
+add_library(NormDepends "${gen_file}")
diff --git a/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt b/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt
new file mode 100644
index 0000000000..f7308e8905
--- /dev/null
+++ b/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt
@@ -0,0 +1,13 @@
+# Simulate in-source build include-file behavior for out-of-source
+# builds.
+set(CMAKE_INCLUDE_CURRENT_DIR 1)
+
+add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ COMMAND
+ ${CMAKE_COMMAND} ARGS -E
+ copy ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+)
+
+add_library(GeneratedHeader main.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated.h)
+
diff --git a/Tests/CustomCommand/GeneratedHeader/generated.h.in b/Tests/CustomCommand/GeneratedHeader/generated.h.in
new file mode 100644
index 0000000000..ae6f64c1c5
--- /dev/null
+++ b/Tests/CustomCommand/GeneratedHeader/generated.h.in
@@ -0,0 +1 @@
+//hello
diff --git a/Tests/CustomCommand/GeneratedHeader/main.cpp b/Tests/CustomCommand/GeneratedHeader/main.cpp
new file mode 100644
index 0000000000..0b43ffe83f
--- /dev/null
+++ b/Tests/CustomCommand/GeneratedHeader/main.cpp
@@ -0,0 +1,5 @@
+#include "generated.h"
+int mainGeneratedHeader()
+{
+ return 0;
+}
diff --git a/Tests/CustomCommand/GeneratorInExtraDir/CMakeLists.txt b/Tests/CustomCommand/GeneratorInExtraDir/CMakeLists.txt
new file mode 100644
index 0000000000..04506db3b9
--- /dev/null
+++ b/Tests/CustomCommand/GeneratorInExtraDir/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_definitions(-DGENERATOR_EXTERN)
+
+# add the executable which will be used for generating files
+add_executable(generator_extern ../generator.cxx)
+set_target_properties(generator_extern PROPERTIES OUTPUT_NAME the_external_generator)
+
+# add an executable which will be called from add_custom_command( ... POST_BUILD)
+add_executable(dummy_generator ../generator.cxx)
diff --git a/Tests/CustomCommand/check_command_line.c.in b/Tests/CustomCommand/check_command_line.c.in
new file mode 100644
index 0000000000..e0e0d21423
--- /dev/null
+++ b/Tests/CustomCommand/check_command_line.c.in
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <string.h>
+
+const char* expected_arguments[] =
+{
+@EXPECTED_ARGUMENTS@ 0
+};
+
+int main(int argc, const char* argv[])
+{
+ const char** a = argv+1;
+ const char** e = expected_arguments;
+ (void)argc;
+ for(;*a && *e; ++a, ++e)
+ {
+ if(strcmp(*a, *e) != 0)
+ {
+ fprintf(stderr, "Argument [%s] does not match expected [%s].\n",
+ *a, *e);
+ return 1;
+ }
+ else
+ {
+#if defined(CHECK_COMMAND_LINE_VERBOSE)
+ printf("[%s]\n", *a);
+#endif
+ }
+ }
+ if(*a || *e)
+ {
+ fprintf(stderr, "Number of arguments does not match expected.\n");
+ return 1;
+ }
+ printf("Command line escapes work!\n");
+ return 0;
+}
diff --git a/Tests/CustomCommand/check_mark.cmake b/Tests/CustomCommand/check_mark.cmake
new file mode 100644
index 0000000000..1f47fd0bde
--- /dev/null
+++ b/Tests/CustomCommand/check_mark.cmake
@@ -0,0 +1,5 @@
+if(EXISTS "${MARK_FILE}")
+ message(FATAL_ERROR "Custom command run more than once!")
+else()
+ file(WRITE "${MARK_FILE}" "check for running custom command twice\n")
+endif()
diff --git a/Tests/CustomCommand/config.h.in b/Tests/CustomCommand/config.h.in
new file mode 100644
index 0000000000..86c97bd959
--- /dev/null
+++ b/Tests/CustomCommand/config.h.in
@@ -0,0 +1 @@
+#define PROJECT_BINARY_DIR "@PROJECT_BINARY_DIR@"
diff --git a/Tests/CustomCommand/doc1.tex b/Tests/CustomCommand/doc1.tex
new file mode 100644
index 0000000000..e6b6ccbe51
--- /dev/null
+++ b/Tests/CustomCommand/doc1.tex
@@ -0,0 +1 @@
+int doc() { return 7;}
diff --git a/Tests/CustomCommand/foo.h.in b/Tests/CustomCommand/foo.h.in
new file mode 100644
index 0000000000..d7721a2a50
--- /dev/null
+++ b/Tests/CustomCommand/foo.h.in
@@ -0,0 +1 @@
+/* Empty header file just used to test header generation. */
diff --git a/Tests/CustomCommand/foo.in b/Tests/CustomCommand/foo.in
new file mode 100644
index 0000000000..0c5021caac
--- /dev/null
+++ b/Tests/CustomCommand/foo.in
@@ -0,0 +1,28 @@
+#include "doc1.h"
+#include "foo.h"
+#include "config.h"
+
+#include <stdio.h>
+
+int generated();
+int wrapped();
+
+int main ()
+{
+ if (generated()*wrapped()*doc() == 3*5*7)
+ {
+ FILE* fin = fopen(PROJECT_BINARY_DIR "/not_included.h", "r");
+ if(fin)
+ {
+ fclose(fin);
+ return 0;
+ }
+ else
+ {
+ return -2;
+ }
+ }
+
+ return -1;
+}
+
diff --git a/Tests/CustomCommand/gen_redirect_in.c b/Tests/CustomCommand/gen_redirect_in.c
new file mode 100644
index 0000000000..8dd8f43f0c
--- /dev/null
+++ b/Tests/CustomCommand/gen_redirect_in.c
@@ -0,0 +1,5 @@
+#if 1
+
+int gen_redirect() { return 3; }
+
+/* endif should be concatenated to generated file */
diff --git a/Tests/CustomCommand/generator.cxx b/Tests/CustomCommand/generator.cxx
new file mode 100644
index 0000000000..cceac073a3
--- /dev/null
+++ b/Tests/CustomCommand/generator.cxx
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ if ( argc < 2 )
+ {
+ fprintf(stderr, "Usage: %s <file>\n", argv[0]);
+ return 1;
+ }
+ FILE *fp = fopen(argv[1],"w");
+#ifdef GENERATOR_EXTERN
+ fprintf(fp,"int generated() { return 3; }\n");
+#else
+ fprintf(fp,"extern int gen_redirect(void);\n");
+ fprintf(fp,"int generated() { return gen_redirect(); }\n");
+#endif
+ fclose(fp);
+ return 0;
+}
diff --git a/Tests/CustomCommand/main.cxx b/Tests/CustomCommand/main.cxx
new file mode 100644
index 0000000000..600e751dd0
--- /dev/null
+++ b/Tests/CustomCommand/main.cxx
@@ -0,0 +1,6 @@
+extern int generated();
+
+int main()
+{
+ return generated();
+}
diff --git a/Tests/CustomCommand/source_in_custom_target.cpp b/Tests/CustomCommand/source_in_custom_target.cpp
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/CustomCommand/source_in_custom_target.cpp
diff --git a/Tests/CustomCommand/tcat.cxx b/Tests/CustomCommand/tcat.cxx
new file mode 100644
index 0000000000..89e3cb0a2e
--- /dev/null
+++ b/Tests/CustomCommand/tcat.cxx
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int main()
+{
+ int c;
+ while((c = getc(stdin), c != EOF))
+ {
+ putc(c, stdout);
+ }
+ return 0;
+}
diff --git a/Tests/CustomCommand/wrapped.h b/Tests/CustomCommand/wrapped.h
new file mode 100644
index 0000000000..fa882cb5b0
--- /dev/null
+++ b/Tests/CustomCommand/wrapped.h
@@ -0,0 +1 @@
+/* empty file */
diff --git a/Tests/CustomCommand/wrapper.cxx b/Tests/CustomCommand/wrapper.cxx
new file mode 100644
index 0000000000..93cb079fe4
--- /dev/null
+++ b/Tests/CustomCommand/wrapper.cxx
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+ if ( argc < 3 )
+ {
+ fprintf(stderr, "Usage: %s <file1> <file2>\n", argv[0]);
+ return 1;
+ }
+ FILE *fp = fopen(argv[1],"w");
+ fprintf(fp,"extern int wrapped_help();\n");
+ fprintf(fp,"int wrapped() { return wrapped_help(); }\n");
+ fclose(fp);
+ fp = fopen(argv[2],"w");
+ fprintf(fp,"int wrapped_help() { return 5; }\n");
+ fclose(fp);
+#ifdef CMAKE_INTDIR
+ /* The VS6 IDE passes a leading ".\\" in its variable expansion. */
+# if defined(_MSC_VER) && _MSC_VER == 1200
+# define CFG_DIR ".\\" CMAKE_INTDIR
+# else
+# define CFG_DIR CMAKE_INTDIR
+# endif
+ const char* cfg = (argc >= 4)? argv[3] : "";
+ if(strcmp(cfg, CFG_DIR) != 0)
+ {
+ fprintf(stderr,
+ "Did not receive expected configuration argument:\n"
+ " expected [" CFG_DIR "]\n"
+ " received [%s]\n", cfg);
+ return 1;
+ }
+#endif
+ return 0;
+}
diff --git a/Tests/CustomCommandWorkingDirectory/CMakeLists.txt b/Tests/CustomCommandWorkingDirectory/CMakeLists.txt
new file mode 100644
index 0000000000..f917cd7f37
--- /dev/null
+++ b/Tests/CustomCommandWorkingDirectory/CMakeLists.txt
@@ -0,0 +1,42 @@
+cmake_minimum_required (VERSION 2.6)
+project(TestWorkingDir)
+
+add_custom_command(
+ OUTPUT "${TestWorkingDir_BINARY_DIR}/working.c"
+ COMMAND "${CMAKE_COMMAND}" -E copy ./working.c.in "${TestWorkingDir_BINARY_DIR}/working.c"
+ WORKING_DIRECTORY "${TestWorkingDir_SOURCE_DIR}"
+ COMMENT "custom command"
+)
+
+set_source_files_properties(
+ "${TestWorkingDir_BINARY_DIR}/customTarget.c"
+ "${TestWorkingDir_BINARY_DIR}/customTarget2.c"
+ PROPERTIES GENERATED 1)
+
+add_executable(working "${TestWorkingDir_BINARY_DIR}/working.c"
+ "${TestWorkingDir_BINARY_DIR}/customTarget.c")
+
+add_custom_target(
+ Custom ALL
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different ./customTarget.c "${TestWorkingDir_BINARY_DIR}/customTarget.c"
+ WORKING_DIRECTORY "${TestWorkingDir_SOURCE_DIR}"
+)
+
+add_dependencies(working Custom)
+
+file(MAKE_DIRECTORY ${TestWorkingDir_BINARY_DIR}/work)
+add_custom_command(
+ OUTPUT working2.c # Relative to build tree
+ COMMAND "${CMAKE_COMMAND}" -E copy ${TestWorkingDir_SOURCE_DIR}/working.c.in ../working2.c
+ DEPENDS ${TestWorkingDir_SOURCE_DIR}/working.c.in/ # trailing slash should be removed
+ WORKING_DIRECTORY work/ # Relative to build tree, trailing slash
+ )
+add_executable(working2 working2.c ${TestWorkingDir_BINARY_DIR}/customTarget2.c)
+
+add_custom_target(
+ Custom2 ALL
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${TestWorkingDir_SOURCE_DIR}/customTarget.c ../customTarget2.c
+ WORKING_DIRECTORY work/ # Relative to build tree, trailing slash
+)
+
+add_dependencies(working2 Custom2)
diff --git a/Tests/CustomCommandWorkingDirectory/customTarget.c b/Tests/CustomCommandWorkingDirectory/customTarget.c
new file mode 100644
index 0000000000..8dbf0d4780
--- /dev/null
+++ b/Tests/CustomCommandWorkingDirectory/customTarget.c
@@ -0,0 +1,4 @@
+int customTarget()
+{
+ return 0;
+}
diff --git a/Tests/CustomCommandWorkingDirectory/working.c.in b/Tests/CustomCommandWorkingDirectory/working.c.in
new file mode 100644
index 0000000000..cf75bd1645
--- /dev/null
+++ b/Tests/CustomCommandWorkingDirectory/working.c.in
@@ -0,0 +1,7 @@
+int customTarget();
+
+int main()
+{
+ return customTarget();
+}
+
diff --git a/Tests/CxxDialect/CMakeLists.txt b/Tests/CxxDialect/CMakeLists.txt
new file mode 100644
index 0000000000..8c903398cb
--- /dev/null
+++ b/Tests/CxxDialect/CMakeLists.txt
@@ -0,0 +1,28 @@
+cmake_minimum_required(VERSION 2.8.12)
+cmake_policy(SET CMP0025 NEW)
+project(CxxDialect)
+
+add_executable(use_typeof use_typeof.cxx)
+set_property(TARGET use_typeof PROPERTY CXX_STANDARD 98)
+
+add_executable(use_constexpr use_constexpr.cxx)
+set_property(TARGET use_constexpr PROPERTY CXX_STANDARD 11)
+
+add_executable(CxxDialect use_constexpr_and_typeof.cxx)
+set_property(TARGET CxxDialect PROPERTY CXX_STANDARD 11)
+
+try_compile(typeof_no_extensions_works
+ "${CMAKE_CURRENT_BINARY_DIR}/use_typeof_test"
+ "${CMAKE_CURRENT_SOURCE_DIR}/use_typeof.cxx"
+ COMPILE_DEFINITIONS
+ CMAKE_FLAGS
+ "-DCMAKE_CXX_STANDARD=98"
+ "-DCMAKE_CXX_EXTENSIONS=FALSE"
+ OUTPUT_VARIABLE OUTPUT
+)
+
+if (typeof_no_extensions_works)
+ message("Use of typeof extension with extensions disabled works, but is expected to fail: ${OUTPUT}")
+else()
+ message("Use of typeof extension with extensions disabled fails, as expected")
+endif()
diff --git a/Tests/CxxDialect/use_constexpr.cxx b/Tests/CxxDialect/use_constexpr.cxx
new file mode 100644
index 0000000000..30ccc4cace
--- /dev/null
+++ b/Tests/CxxDialect/use_constexpr.cxx
@@ -0,0 +1,10 @@
+
+constexpr int foo()
+{
+ return 0;
+}
+
+int main(int argc, char**)
+{
+ return foo();
+}
diff --git a/Tests/CxxDialect/use_constexpr_and_typeof.cxx b/Tests/CxxDialect/use_constexpr_and_typeof.cxx
new file mode 100644
index 0000000000..af217b67e3
--- /dev/null
+++ b/Tests/CxxDialect/use_constexpr_and_typeof.cxx
@@ -0,0 +1,11 @@
+
+constexpr int foo()
+{
+ return 0;
+}
+
+int main(int argc, char**)
+{
+ typeof(argc) ret = foo();
+ return ret;
+}
diff --git a/Tests/CxxDialect/use_typeof.cxx b/Tests/CxxDialect/use_typeof.cxx
new file mode 100644
index 0000000000..dabb61f4f1
--- /dev/null
+++ b/Tests/CxxDialect/use_typeof.cxx
@@ -0,0 +1,6 @@
+
+int main(int argc, char**)
+{
+ typeof(argc) ret = 0;
+ return ret;
+}
diff --git a/Tests/CxxOnly/CMakeLists.txt b/Tests/CxxOnly/CMakeLists.txt
new file mode 100644
index 0000000000..e62f3c797e
--- /dev/null
+++ b/Tests/CxxOnly/CMakeLists.txt
@@ -0,0 +1,13 @@
+# a simple CXX only test case
+project (CxxOnly CXX)
+
+set(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
+if(WIN32)
+ set(EXTRA_SRCS test.CPP)
+endif()
+add_library(testcxx1.my STATIC libcxx1.cxx ${EXTRA_SRCS})
+add_library(testcxx2 SHARED libcxx2.cxx)
+add_executable (CxxOnly cxxonly.cxx)
+target_link_libraries(CxxOnly testcxx1.my testcxx2)
+
+add_library(testCxxModule MODULE testCxxModule.cxx)
diff --git a/Tests/CxxOnly/cxxonly.cxx b/Tests/CxxOnly/cxxonly.cxx
new file mode 100644
index 0000000000..9cf6f2d29b
--- /dev/null
+++ b/Tests/CxxOnly/cxxonly.cxx
@@ -0,0 +1,25 @@
+#include "libcxx1.h"
+#include "libcxx2.h"
+#ifdef _MSC_VER
+extern int testCPP;
+#endif
+
+#include <stdio.h>
+
+int main ()
+{
+#ifdef _MSC_VER
+ testCPP = 1;
+#endif
+ if ( LibCxx1Class::Method() != 2.0 )
+ {
+ printf("Problem with libcxx1\n");
+ return 1;
+ }
+ if ( LibCxx2Class::Method() != 1.0 )
+ {
+ printf("Problem with libcxx2\n");
+ return 1;
+ }
+ return 0;
+}
diff --git a/Tests/CxxOnly/libcxx1.cxx b/Tests/CxxOnly/libcxx1.cxx
new file mode 100644
index 0000000000..da18019d3d
--- /dev/null
+++ b/Tests/CxxOnly/libcxx1.cxx
@@ -0,0 +1,6 @@
+#include "libcxx1.h"
+
+float LibCxx1Class::Method()
+{
+ return 2.0;
+}
diff --git a/Tests/CxxOnly/libcxx1.h b/Tests/CxxOnly/libcxx1.h
new file mode 100644
index 0000000000..9452a64b15
--- /dev/null
+++ b/Tests/CxxOnly/libcxx1.h
@@ -0,0 +1,5 @@
+class LibCxx1Class
+{
+public:
+ static float Method();
+};
diff --git a/Tests/CxxOnly/libcxx2.cxx b/Tests/CxxOnly/libcxx2.cxx
new file mode 100644
index 0000000000..453039c585
--- /dev/null
+++ b/Tests/CxxOnly/libcxx2.cxx
@@ -0,0 +1,6 @@
+#include "libcxx2.h"
+
+float LibCxx2Class::Method()
+{
+ return 1.0;
+}
diff --git a/Tests/CxxOnly/libcxx2.h b/Tests/CxxOnly/libcxx2.h
new file mode 100644
index 0000000000..5dd84f6c23
--- /dev/null
+++ b/Tests/CxxOnly/libcxx2.h
@@ -0,0 +1,15 @@
+#ifdef _WIN32
+# ifdef testcxx2_EXPORTS
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+# else
+# define CM_TEST_LIB_EXPORT __declspec( dllimport )
+# endif
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+
+class CM_TEST_LIB_EXPORT LibCxx2Class
+{
+public:
+ static float Method();
+};
diff --git a/Tests/CxxOnly/test.CPP b/Tests/CxxOnly/test.CPP
new file mode 100644
index 0000000000..8a3cde2627
--- /dev/null
+++ b/Tests/CxxOnly/test.CPP
@@ -0,0 +1 @@
+int testCPP;
diff --git a/Tests/CxxOnly/testCxxModule.cxx b/Tests/CxxOnly/testCxxModule.cxx
new file mode 100644
index 0000000000..dd16d2bfa8
--- /dev/null
+++ b/Tests/CxxOnly/testCxxModule.cxx
@@ -0,0 +1,6 @@
+#ifdef _WIN32
+# define TEST_EXPORT __declspec(dllexport)
+#else
+# define TEST_EXPORT
+#endif
+TEST_EXPORT int testCxxModule(void) { return 0; }
diff --git a/Tests/Dependency/1/CMakeLists.txt b/Tests/Dependency/1/CMakeLists.txt
new file mode 100644
index 0000000000..a8e74e40ba
--- /dev/null
+++ b/Tests/Dependency/1/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library( One OneSrc.c )
+# This library has no dependencies
+target_link_libraries( One "" )
diff --git a/Tests/Dependency/1/OneSrc.c b/Tests/Dependency/1/OneSrc.c
new file mode 100644
index 0000000000..9801c2524f
--- /dev/null
+++ b/Tests/Dependency/1/OneSrc.c
@@ -0,0 +1,3 @@
+void OneFunction()
+{
+}
diff --git a/Tests/Dependency/CMakeLists.txt b/Tests/Dependency/CMakeLists.txt
new file mode 100644
index 0000000000..ef4204803a
--- /dev/null
+++ b/Tests/Dependency/CMakeLists.txt
@@ -0,0 +1,53 @@
+cmake_minimum_required (VERSION 2.6)
+project( Dependency )
+
+# to test directories with only one character One was changed to 1
+# There is one executable that depends on eight libraries. The
+# system has the following dependency graph:
+#
+# NoDepA:
+# NoDepB: NoDepA
+# NoDepC: NoDepA
+# 1:
+# Two: Three
+# Three: 1 Four
+# Four: 1 Two NoDepA
+# Five: Two
+# SixA: Two Five
+# SixB: Four Five
+# Seven: Two
+# Eight: Seven
+#
+# Exec: NoDepB NoDepC SixA SixB
+# Exec2: Eight Five
+# Exec3: Eight Five
+# Exec4: Five Two
+#
+# The libraries One,...,Eight have their dependencies explicitly
+# encoded. The libraries NoDepA,...,NoDepC do not.
+#
+# Although SixB does not depend on Two, there is a dependency listed
+# in the corresponding CMakeLists.txt just because of commands used.
+
+add_subdirectory(NoDepA)
+add_subdirectory(NoDepB)
+add_subdirectory(NoDepC)
+add_subdirectory(1)
+add_subdirectory(Two)
+add_subdirectory(Three)
+add_subdirectory(Four)
+add_subdirectory(Five)
+add_subdirectory(Six)
+add_subdirectory(Seven)
+add_subdirectory(Eight)
+add_subdirectory(Exec)
+add_subdirectory(Exec2)
+add_subdirectory(Exec3)
+add_subdirectory(Exec4)
+
+# Specific cases added to test fixes to problems found in real
+# projects.
+add_subdirectory(Case1)
+add_subdirectory(Case2)
+add_subdirectory(Case3)
+add_subdirectory(Case4)
diff --git a/Tests/Dependency/Case1/CMakeLists.txt b/Tests/Dependency/Case1/CMakeLists.txt
new file mode 100644
index 0000000000..4c5fc20375
--- /dev/null
+++ b/Tests/Dependency/Case1/CMakeLists.txt
@@ -0,0 +1,19 @@
+project(CASE1)
+
+# The old anaylize lib depends stuff in cmTarget gets this case wrong.
+# The cmComputeLinkDepends implementation gets it right.
+
+add_library(case1a STATIC a.c)
+
+add_library(case1b STATIC b.c b2.c)
+target_link_libraries(case1b case1a)
+
+add_library(case1c STATIC c.c c2.c)
+target_link_libraries(case1c case1b)
+
+add_library(case1d STATIC d.c)
+target_link_libraries(case1d case1c)
+
+add_executable(hello main.c)
+target_link_libraries(hello case1c case1b case1d case1c)
+
diff --git a/Tests/Dependency/Case1/a.c b/Tests/Dependency/Case1/a.c
new file mode 100644
index 0000000000..d702db1af7
--- /dev/null
+++ b/Tests/Dependency/Case1/a.c
@@ -0,0 +1,5 @@
+int a()
+{
+ return 5;
+}
+
diff --git a/Tests/Dependency/Case1/b.c b/Tests/Dependency/Case1/b.c
new file mode 100644
index 0000000000..6bdfafafb4
--- /dev/null
+++ b/Tests/Dependency/Case1/b.c
@@ -0,0 +1,6 @@
+extern int a();
+
+int b()
+{
+ return a()+17;
+}
diff --git a/Tests/Dependency/Case1/b2.c b/Tests/Dependency/Case1/b2.c
new file mode 100644
index 0000000000..f37e1bb759
--- /dev/null
+++ b/Tests/Dependency/Case1/b2.c
@@ -0,0 +1,4 @@
+int b2()
+{
+ return 3;
+}
diff --git a/Tests/Dependency/Case1/c.c b/Tests/Dependency/Case1/c.c
new file mode 100644
index 0000000000..c180a59b64
--- /dev/null
+++ b/Tests/Dependency/Case1/c.c
@@ -0,0 +1,6 @@
+extern int b();
+
+int c()
+{
+ return b()+42;
+}
diff --git a/Tests/Dependency/Case1/c2.c b/Tests/Dependency/Case1/c2.c
new file mode 100644
index 0000000000..4cf4426e55
--- /dev/null
+++ b/Tests/Dependency/Case1/c2.c
@@ -0,0 +1,6 @@
+extern int b2();
+
+int c2()
+{
+ return b2()+1;
+}
diff --git a/Tests/Dependency/Case1/d.c b/Tests/Dependency/Case1/d.c
new file mode 100644
index 0000000000..ea5457d4dc
--- /dev/null
+++ b/Tests/Dependency/Case1/d.c
@@ -0,0 +1,7 @@
+extern int c2();
+
+int d()
+{
+ return c2()+2;
+}
+
diff --git a/Tests/Dependency/Case1/main.c b/Tests/Dependency/Case1/main.c
new file mode 100644
index 0000000000..1e5f6d4aab
--- /dev/null
+++ b/Tests/Dependency/Case1/main.c
@@ -0,0 +1,10 @@
+extern int b();
+extern int c();
+extern int d();
+
+int main()
+{
+ c();
+ b();
+ d();
+}
diff --git a/Tests/Dependency/Case2/CMakeLists.txt b/Tests/Dependency/Case2/CMakeLists.txt
new file mode 100644
index 0000000000..21caaad3e6
--- /dev/null
+++ b/Tests/Dependency/Case2/CMakeLists.txt
@@ -0,0 +1,22 @@
+project(CASE2 C)
+
+add_library(case2Foo1 STATIC foo1.c foo1b.c foo1c.c)
+add_library(case2Foo2 STATIC foo2.c foo2b.c foo2c.c)
+add_library(case2Foo3 STATIC foo3.c foo3b.c foo3c.c)
+target_link_libraries(case2Foo1 case2Foo2)
+target_link_libraries(case2Foo2 case2Foo3)
+target_link_libraries(case2Foo3 case2Foo1)
+set_property(TARGET case2Foo1 PROPERTY LINK_INTERFACE_MULTIPLICITY 3)
+
+add_library(case2Bar1 STATIC bar1.c)
+add_library(case2Bar2 STATIC bar2.c)
+add_library(case2Bar3 STATIC bar3.c)
+target_link_libraries(case2Bar1 case2Bar2 case2Foo1)
+target_link_libraries(case2Bar2 case2Bar3)
+target_link_libraries(case2Bar3 case2Bar1)
+
+add_executable(case2Zot zot.c)
+target_link_libraries(case2Zot case2Bar1)
+
+#set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1)
+#set(CMAKE_LINK_DEPENDS_DEBUG_MODE 1)
diff --git a/Tests/Dependency/Case2/bar1.c b/Tests/Dependency/Case2/bar1.c
new file mode 100644
index 0000000000..6108fba725
--- /dev/null
+++ b/Tests/Dependency/Case2/bar1.c
@@ -0,0 +1,4 @@
+extern int foo1();
+extern int bar2(void);
+int bar1(void) { return bar2(); }
+int bar1_from_bar3(void) { return foo1(); }
diff --git a/Tests/Dependency/Case2/bar2.c b/Tests/Dependency/Case2/bar2.c
new file mode 100644
index 0000000000..b9a2360900
--- /dev/null
+++ b/Tests/Dependency/Case2/bar2.c
@@ -0,0 +1,2 @@
+extern int bar3(void);
+int bar2(void) { return bar3(); }
diff --git a/Tests/Dependency/Case2/bar3.c b/Tests/Dependency/Case2/bar3.c
new file mode 100644
index 0000000000..73e85567a3
--- /dev/null
+++ b/Tests/Dependency/Case2/bar3.c
@@ -0,0 +1,2 @@
+extern int bar1_from_bar3(void);
+int bar3(void) { return bar1_from_bar3(); }
diff --git a/Tests/Dependency/Case2/foo1.c b/Tests/Dependency/Case2/foo1.c
new file mode 100644
index 0000000000..5f1f8ac842
--- /dev/null
+++ b/Tests/Dependency/Case2/foo1.c
@@ -0,0 +1,2 @@
+extern int foo2(void);
+int foo1(void) { return foo2(); }
diff --git a/Tests/Dependency/Case2/foo1b.c b/Tests/Dependency/Case2/foo1b.c
new file mode 100644
index 0000000000..e2b6dc341b
--- /dev/null
+++ b/Tests/Dependency/Case2/foo1b.c
@@ -0,0 +1,2 @@
+extern int foo2b(void);
+int foo1b(void) { return foo2b(); }
diff --git a/Tests/Dependency/Case2/foo1c.c b/Tests/Dependency/Case2/foo1c.c
new file mode 100644
index 0000000000..1dcca58c68
--- /dev/null
+++ b/Tests/Dependency/Case2/foo1c.c
@@ -0,0 +1,2 @@
+extern int foo2c(void);
+int foo1c(void) { return foo2c(); }
diff --git a/Tests/Dependency/Case2/foo2.c b/Tests/Dependency/Case2/foo2.c
new file mode 100644
index 0000000000..601923663e
--- /dev/null
+++ b/Tests/Dependency/Case2/foo2.c
@@ -0,0 +1,2 @@
+extern int foo3(void);
+int foo2(void) { return foo3(); }
diff --git a/Tests/Dependency/Case2/foo2b.c b/Tests/Dependency/Case2/foo2b.c
new file mode 100644
index 0000000000..34d6944118
--- /dev/null
+++ b/Tests/Dependency/Case2/foo2b.c
@@ -0,0 +1,2 @@
+extern int foo3b(void);
+int foo2b(void) { return foo3b(); }
diff --git a/Tests/Dependency/Case2/foo2c.c b/Tests/Dependency/Case2/foo2c.c
new file mode 100644
index 0000000000..dbc54de746
--- /dev/null
+++ b/Tests/Dependency/Case2/foo2c.c
@@ -0,0 +1,2 @@
+extern int foo3c(void);
+int foo2c(void) { return foo3c(); }
diff --git a/Tests/Dependency/Case2/foo3.c b/Tests/Dependency/Case2/foo3.c
new file mode 100644
index 0000000000..dacef6ae46
--- /dev/null
+++ b/Tests/Dependency/Case2/foo3.c
@@ -0,0 +1,2 @@
+extern int foo1b(void);
+int foo3(void) { return foo1b(); }
diff --git a/Tests/Dependency/Case2/foo3b.c b/Tests/Dependency/Case2/foo3b.c
new file mode 100644
index 0000000000..ca25fd8ffe
--- /dev/null
+++ b/Tests/Dependency/Case2/foo3b.c
@@ -0,0 +1,2 @@
+extern int foo1c(void);
+int foo3b(void) { return foo1c(); }
diff --git a/Tests/Dependency/Case2/foo3c.c b/Tests/Dependency/Case2/foo3c.c
new file mode 100644
index 0000000000..0ad65fe449
--- /dev/null
+++ b/Tests/Dependency/Case2/foo3c.c
@@ -0,0 +1 @@
+int foo3c(void) { return 0; }
diff --git a/Tests/Dependency/Case2/zot.c b/Tests/Dependency/Case2/zot.c
new file mode 100644
index 0000000000..f25b49343a
--- /dev/null
+++ b/Tests/Dependency/Case2/zot.c
@@ -0,0 +1,5 @@
+extern int bar1(void);
+int main(void)
+{
+ return bar1();
+}
diff --git a/Tests/Dependency/Case3/CMakeLists.txt b/Tests/Dependency/Case3/CMakeLists.txt
new file mode 100644
index 0000000000..f01dd057a1
--- /dev/null
+++ b/Tests/Dependency/Case3/CMakeLists.txt
@@ -0,0 +1,10 @@
+project(CASE3 C)
+
+add_library(case3Foo1 STATIC foo1.c foo1b.c)
+add_library(case3Foo2 STATIC foo2.c)
+
+add_executable(case3Bar bar.c)
+target_link_libraries(case3Bar case3Foo1 case3Foo2 case3Foo1)
+
+#set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1)
+#set(CMAKE_LINK_DEPENDS_DEBUG_MODE 1)
diff --git a/Tests/Dependency/Case3/bar.c b/Tests/Dependency/Case3/bar.c
new file mode 100644
index 0000000000..62959c1cb1
--- /dev/null
+++ b/Tests/Dependency/Case3/bar.c
@@ -0,0 +1,5 @@
+extern int foo1(void);
+int main(void)
+{
+ return foo1();
+}
diff --git a/Tests/Dependency/Case3/foo1.c b/Tests/Dependency/Case3/foo1.c
new file mode 100644
index 0000000000..5f1f8ac842
--- /dev/null
+++ b/Tests/Dependency/Case3/foo1.c
@@ -0,0 +1,2 @@
+extern int foo2(void);
+int foo1(void) { return foo2(); }
diff --git a/Tests/Dependency/Case3/foo1b.c b/Tests/Dependency/Case3/foo1b.c
new file mode 100644
index 0000000000..6ae3babdc1
--- /dev/null
+++ b/Tests/Dependency/Case3/foo1b.c
@@ -0,0 +1 @@
+int foo1b(void) { return 0; }
diff --git a/Tests/Dependency/Case3/foo2.c b/Tests/Dependency/Case3/foo2.c
new file mode 100644
index 0000000000..33dbbfce66
--- /dev/null
+++ b/Tests/Dependency/Case3/foo2.c
@@ -0,0 +1,2 @@
+extern int foo1b(void);
+int foo2(void) { return foo1b(); }
diff --git a/Tests/Dependency/Case4/CMakeLists.txt b/Tests/Dependency/Case4/CMakeLists.txt
new file mode 100644
index 0000000000..a71049da39
--- /dev/null
+++ b/Tests/Dependency/Case4/CMakeLists.txt
@@ -0,0 +1,19 @@
+project(CASE4 C)
+
+# This is not really a circular dependency. "case4Bar" refers to a
+# third-party library that happens to match the executable name, which
+# is okay when the executable is not a linkable target (ENABLE_EXPORTS
+# is not set). This tests whether CMake avoids incorrectly reporting
+# a circular dependency. In practice case4Foo may be a shared
+# library, but we skip that here because we do not want it to actually
+# have to find the third-party library.
+add_library(case4Foo STATIC foo.c)
+target_link_libraries(case4Foo case4Bar)
+
+# The executable avoids linking to a library with its own name, which
+# has been a CMake-ism for a long time, so we will not get a link
+# failure. An imported target or executable with an OUTPUT_NAME set
+# may be used if the user really wants to link a third-party library
+# into an executable of the same name.
+add_executable(case4Bar bar.c)
+target_link_libraries(case4Bar case4Foo)
diff --git a/Tests/Dependency/Case4/bar.c b/Tests/Dependency/Case4/bar.c
new file mode 100644
index 0000000000..d0bb0c43c2
--- /dev/null
+++ b/Tests/Dependency/Case4/bar.c
@@ -0,0 +1,2 @@
+extern int foo();
+int main() { return foo(); }
diff --git a/Tests/Dependency/Case4/foo.c b/Tests/Dependency/Case4/foo.c
new file mode 100644
index 0000000000..9fe07f82f9
--- /dev/null
+++ b/Tests/Dependency/Case4/foo.c
@@ -0,0 +1 @@
+int foo() { return 0; }
diff --git a/Tests/Dependency/Eight/CMakeLists.txt b/Tests/Dependency/Eight/CMakeLists.txt
new file mode 100644
index 0000000000..db5e2dfb5b
--- /dev/null
+++ b/Tests/Dependency/Eight/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library( Eight EightSrc.c )
+target_link_libraries( Eight Seven )
+
diff --git a/Tests/Dependency/Eight/EightSrc.c b/Tests/Dependency/Eight/EightSrc.c
new file mode 100644
index 0000000000..7bfa481e2a
--- /dev/null
+++ b/Tests/Dependency/Eight/EightSrc.c
@@ -0,0 +1,6 @@
+void SevenFunction();
+
+void EightFunction()
+{
+ SevenFunction();
+}
diff --git a/Tests/Dependency/Exec/CMakeLists.txt b/Tests/Dependency/Exec/CMakeLists.txt
new file mode 100644
index 0000000000..a9206857f3
--- /dev/null
+++ b/Tests/Dependency/Exec/CMakeLists.txt
@@ -0,0 +1,7 @@
+# This executable directly depends on NoDepB, NoDepC, SixA and SixB. However,
+# since NoDepB and NoDepC do not have explicit dependency information,
+# and they depend on NoDepA, we have to manually specify that dependency.
+link_libraries( NoDepB NoDepC NoDepA SixB SixA )
+
+add_executable( exec ExecMain.c )
+
diff --git a/Tests/Dependency/Exec/ExecMain.c b/Tests/Dependency/Exec/ExecMain.c
new file mode 100644
index 0000000000..d2f551c7a0
--- /dev/null
+++ b/Tests/Dependency/Exec/ExecMain.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+void NoDepBFunction();
+void NoDepCFunction();
+void SixAFunction();
+void SixBFunction();
+
+int main( )
+{
+ SixAFunction();
+ SixBFunction();
+ NoDepBFunction();
+ NoDepCFunction();
+
+ printf("Dependency test executable ran successfully.\n");
+
+ return 0;
+}
diff --git a/Tests/Dependency/Exec2/CMakeLists.txt b/Tests/Dependency/Exec2/CMakeLists.txt
new file mode 100644
index 0000000000..04d6fe8103
--- /dev/null
+++ b/Tests/Dependency/Exec2/CMakeLists.txt
@@ -0,0 +1,12 @@
+# Here, Eight depends on Seven, which has the same dependencies as Five.
+# If the dependencies of Five are emitted, and then we attempt to emit the
+# dependencies of Seven, then we find that they have already been done. So:
+# Original line: Eight Five
+# Add deps of Five: Eight Five Two ... NoDepA
+# Now, we must make sure that Seven gets inserted between Five and Two, and
+# not at the end. Unfortunately, if we get it wrong, the test will only
+# fail on a platform where the link order makes a difference.
+link_libraries( Eight Five )
+
+add_executable( exec2 ExecMain.c )
+
diff --git a/Tests/Dependency/Exec2/ExecMain.c b/Tests/Dependency/Exec2/ExecMain.c
new file mode 100644
index 0000000000..d08a796c34
--- /dev/null
+++ b/Tests/Dependency/Exec2/ExecMain.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+void FiveFunction();
+void EightFunction();
+
+int main( )
+{
+ FiveFunction();
+ EightFunction();
+
+ printf("Dependency test executable ran successfully.\n");
+
+ return 0;
+}
diff --git a/Tests/Dependency/Exec3/CMakeLists.txt b/Tests/Dependency/Exec3/CMakeLists.txt
new file mode 100644
index 0000000000..605fbc9f1d
--- /dev/null
+++ b/Tests/Dependency/Exec3/CMakeLists.txt
@@ -0,0 +1,6 @@
+# Here, Five already has it's immediate dependency, Two satisfied. We must
+# make sure Two gets output anyway, because Eight indirectly depends on it.
+link_libraries( Five Two Eight Five )
+
+add_executable( exec3 ExecMain.c )
+
diff --git a/Tests/Dependency/Exec3/ExecMain.c b/Tests/Dependency/Exec3/ExecMain.c
new file mode 100644
index 0000000000..d08a796c34
--- /dev/null
+++ b/Tests/Dependency/Exec3/ExecMain.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+void FiveFunction();
+void EightFunction();
+
+int main( )
+{
+ FiveFunction();
+ EightFunction();
+
+ printf("Dependency test executable ran successfully.\n");
+
+ return 0;
+}
diff --git a/Tests/Dependency/Exec4/CMakeLists.txt b/Tests/Dependency/Exec4/CMakeLists.txt
new file mode 100644
index 0000000000..94c6bf588b
--- /dev/null
+++ b/Tests/Dependency/Exec4/CMakeLists.txt
@@ -0,0 +1,6 @@
+# Even though Five's dependency on Two is explicitly satisfied, Two
+# must be emitted again in order to satisfy a cyclic dependency on Three.
+link_libraries( Five Two Five )
+
+add_executable( exec4 ExecMain.c )
+
diff --git a/Tests/Dependency/Exec4/ExecMain.c b/Tests/Dependency/Exec4/ExecMain.c
new file mode 100644
index 0000000000..3f53573bfc
--- /dev/null
+++ b/Tests/Dependency/Exec4/ExecMain.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+void FiveFunction();
+void TwoFunction();
+
+int main( )
+{
+ FiveFunction();
+ TwoFunction();
+
+ printf("Dependency test executable ran successfully.\n");
+
+ return 0;
+}
diff --git a/Tests/Dependency/Five/CMakeLists.txt b/Tests/Dependency/Five/CMakeLists.txt
new file mode 100644
index 0000000000..19c1c77d32
--- /dev/null
+++ b/Tests/Dependency/Five/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library( Five FiveSrc.c )
+target_link_libraries( Five Two )
+
diff --git a/Tests/Dependency/Five/FiveSrc.c b/Tests/Dependency/Five/FiveSrc.c
new file mode 100644
index 0000000000..33d8ad7dc1
--- /dev/null
+++ b/Tests/Dependency/Five/FiveSrc.c
@@ -0,0 +1,6 @@
+void TwoFunction();
+
+void FiveFunction()
+{
+ TwoFunction();
+}
diff --git a/Tests/Dependency/Four/CMakeLists.txt b/Tests/Dependency/Four/CMakeLists.txt
new file mode 100644
index 0000000000..71c531fe90
--- /dev/null
+++ b/Tests/Dependency/Four/CMakeLists.txt
@@ -0,0 +1,6 @@
+include_directories(${Dependency_BINARY_DIR}/Two)
+add_library( Four FourSrc.c )
+target_link_libraries( Four One Two NoDepA )
+
+# TwoCustom must build before Four.
+add_dependencies(Four TwoCustom)
diff --git a/Tests/Dependency/Four/FourSrc.c b/Tests/Dependency/Four/FourSrc.c
new file mode 100644
index 0000000000..23a66a49ae
--- /dev/null
+++ b/Tests/Dependency/Four/FourSrc.c
@@ -0,0 +1,15 @@
+#include <two-test.h> /* Requires TwoCustom to be built first. */
+void NoDepAFunction();
+void OneFunction();
+void TwoFunction();
+
+void FourFunction()
+{
+ static int count = 0;
+ if( count == 0 ) {
+ ++count;
+ TwoFunction();
+ }
+ OneFunction();
+ NoDepAFunction();
+}
diff --git a/Tests/Dependency/NoDepA/CMakeLists.txt b/Tests/Dependency/NoDepA/CMakeLists.txt
new file mode 100644
index 0000000000..543402d9d3
--- /dev/null
+++ b/Tests/Dependency/NoDepA/CMakeLists.txt
@@ -0,0 +1 @@
+add_library( NoDepA NoDepASrc.c )
diff --git a/Tests/Dependency/NoDepA/NoDepASrc.c b/Tests/Dependency/NoDepA/NoDepASrc.c
new file mode 100644
index 0000000000..8c4072bd1a
--- /dev/null
+++ b/Tests/Dependency/NoDepA/NoDepASrc.c
@@ -0,0 +1,3 @@
+void NoDepAFunction()
+{
+}
diff --git a/Tests/Dependency/NoDepB/CMakeLists.txt b/Tests/Dependency/NoDepB/CMakeLists.txt
new file mode 100644
index 0000000000..1c70f375c5
--- /dev/null
+++ b/Tests/Dependency/NoDepB/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library( NoDepB NoDepBSrc.c )
+# This library depends on NoDepA, but the
+# dependency is not explicitly specified.
diff --git a/Tests/Dependency/NoDepB/NoDepBSrc.c b/Tests/Dependency/NoDepB/NoDepBSrc.c
new file mode 100644
index 0000000000..ddc71c527d
--- /dev/null
+++ b/Tests/Dependency/NoDepB/NoDepBSrc.c
@@ -0,0 +1,6 @@
+void NoDepAFunction();
+
+void NoDepBFunction()
+{
+ NoDepAFunction();
+}
diff --git a/Tests/Dependency/NoDepC/CMakeLists.txt b/Tests/Dependency/NoDepC/CMakeLists.txt
new file mode 100644
index 0000000000..dd41cebb6b
--- /dev/null
+++ b/Tests/Dependency/NoDepC/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library( NoDepC NoDepCSrc.c )
+# This library depends on NoDepA, but the
+# dependency is not explicitly specified.
diff --git a/Tests/Dependency/NoDepC/NoDepCSrc.c b/Tests/Dependency/NoDepC/NoDepCSrc.c
new file mode 100644
index 0000000000..b478c596df
--- /dev/null
+++ b/Tests/Dependency/NoDepC/NoDepCSrc.c
@@ -0,0 +1,6 @@
+void NoDepAFunction();
+
+void NoDepCFunction()
+{
+ NoDepAFunction();
+}
diff --git a/Tests/Dependency/Seven/CMakeLists.txt b/Tests/Dependency/Seven/CMakeLists.txt
new file mode 100644
index 0000000000..7fba55cb9e
--- /dev/null
+++ b/Tests/Dependency/Seven/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library( Seven SevenSrc.c )
+target_link_libraries( Seven Two )
+
diff --git a/Tests/Dependency/Seven/SevenSrc.c b/Tests/Dependency/Seven/SevenSrc.c
new file mode 100644
index 0000000000..e1f3329e87
--- /dev/null
+++ b/Tests/Dependency/Seven/SevenSrc.c
@@ -0,0 +1,6 @@
+void TwoFunction();
+
+void SevenFunction()
+{
+ TwoFunction();
+}
diff --git a/Tests/Dependency/Six/CMakeLists.txt b/Tests/Dependency/Six/CMakeLists.txt
new file mode 100644
index 0000000000..db12051e2e
--- /dev/null
+++ b/Tests/Dependency/Six/CMakeLists.txt
@@ -0,0 +1,12 @@
+# In some projects, people don't use TARGET_LINK_LIBRARIES, but just
+# use an all-encompassing LINK_LIBRARIES. And sometimes they don't
+# specify them in the correct order.
+
+link_libraries( Two )
+link_libraries( Five )
+
+add_library( SixA SixASrc.c )
+
+add_library( SixB SixBSrc.c )
+target_link_libraries( SixB Four )
+
diff --git a/Tests/Dependency/Six/SixASrc.c b/Tests/Dependency/Six/SixASrc.c
new file mode 100644
index 0000000000..7ea3711f2a
--- /dev/null
+++ b/Tests/Dependency/Six/SixASrc.c
@@ -0,0 +1,8 @@
+void FiveFunction();
+void TwoFunction();
+
+void SixAFunction()
+{
+ FiveFunction();
+ TwoFunction();
+}
diff --git a/Tests/Dependency/Six/SixBSrc.c b/Tests/Dependency/Six/SixBSrc.c
new file mode 100644
index 0000000000..92f9607f80
--- /dev/null
+++ b/Tests/Dependency/Six/SixBSrc.c
@@ -0,0 +1,10 @@
+void TwoFunction();
+void FiveFunction();
+void FourFunction();
+
+void SixBFunction()
+{
+ TwoFunction();
+ FiveFunction();
+ FourFunction();
+}
diff --git a/Tests/Dependency/Three/CMakeLists.txt b/Tests/Dependency/Three/CMakeLists.txt
new file mode 100644
index 0000000000..3897f0cddf
--- /dev/null
+++ b/Tests/Dependency/Three/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library( Three ThreeSrc.c )
+target_link_libraries( Three One Four )
+
diff --git a/Tests/Dependency/Three/ThreeSrc.c b/Tests/Dependency/Three/ThreeSrc.c
new file mode 100644
index 0000000000..9c77f17a0e
--- /dev/null
+++ b/Tests/Dependency/Three/ThreeSrc.c
@@ -0,0 +1,12 @@
+void OneFunction();
+void FourFunction();
+
+void ThreeFunction()
+{
+ static int count = 0;
+ if( count == 0 ) {
+ ++count;
+ FourFunction();
+ }
+ OneFunction();
+}
diff --git a/Tests/Dependency/Two/CMakeLists.txt b/Tests/Dependency/Two/CMakeLists.txt
new file mode 100644
index 0000000000..19a0703280
--- /dev/null
+++ b/Tests/Dependency/Two/CMakeLists.txt
@@ -0,0 +1,20 @@
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+add_library( Two TwoSrc.c )
+target_link_libraries( Two Three )
+
+# Setup a target to cause failure if Two does not depend on it or if
+# Two actually links to it. This will test that a utility dependency
+# on a library target works properly.
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/two-test.h
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${CMAKE_CURRENT_SOURCE_DIR}/two-test.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/two-test.h
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/two-test.h.in
+ )
+add_library( TwoCustom TwoCustomSrc.c ${CMAKE_CURRENT_BINARY_DIR}/two-test.h)
+set_target_properties(TwoCustom PROPERTIES EXCLUDE_FROM_ALL 1)
+target_link_libraries(TwoCustom Three)
+
+# Add a utility dependency to make sure it works without linking.
+add_dependencies(Two TwoCustom)
diff --git a/Tests/Dependency/Two/TwoCustomSrc.c b/Tests/Dependency/Two/TwoCustomSrc.c
new file mode 100644
index 0000000000..ac31dcf37b
--- /dev/null
+++ b/Tests/Dependency/Two/TwoCustomSrc.c
@@ -0,0 +1,10 @@
+extern void NoFunction();
+
+/* Provide a function that is supposed to be found in the Three
+ library. If Two links to TwoCustom then TwoCustom will come before
+ Three and this symbol will be used. Since NoFunction is not
+ defined, that will cause a link failure. */
+void ThreeFunction()
+{
+ NoFunction();
+}
diff --git a/Tests/Dependency/Two/TwoSrc.c b/Tests/Dependency/Two/TwoSrc.c
new file mode 100644
index 0000000000..0b3366b2bd
--- /dev/null
+++ b/Tests/Dependency/Two/TwoSrc.c
@@ -0,0 +1,10 @@
+#include <two-test.h>
+
+void TwoFunction()
+{
+ static int count = 0;
+ if( count == 0 ) {
+ ++count;
+ ThreeFunction();
+ }
+}
diff --git a/Tests/Dependency/Two/two-test.h.in b/Tests/Dependency/Two/two-test.h.in
new file mode 100644
index 0000000000..8c6a7f770a
--- /dev/null
+++ b/Tests/Dependency/Two/two-test.h.in
@@ -0,0 +1 @@
+extern void ThreeFunction();
diff --git a/Tests/DoubleProject/CMakeLists.txt b/Tests/DoubleProject/CMakeLists.txt
new file mode 100644
index 0000000000..02a6275970
--- /dev/null
+++ b/Tests/DoubleProject/CMakeLists.txt
@@ -0,0 +1,3 @@
+project(dumb)
+project(dumber)
+add_executable(just_silly silly.c)
diff --git a/Tests/DoubleProject/silly.c b/Tests/DoubleProject/silly.c
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/DoubleProject/silly.c
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/EmptyDepends/CMakeLists.txt b/Tests/EmptyDepends/CMakeLists.txt
new file mode 100644
index 0000000000..832d9dce6c
--- /dev/null
+++ b/Tests/EmptyDepends/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.8)
+project(EmptyDepends)
+
+include(CTest)
+
+set(extra_dep)
+
+add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/qrc_my.cxx
+ COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_BINARY_DIR}/qrc_my.cxx"
+ DEPENDS "${extra_dep}" "${CMAKE_BINARY_DIR}/my.qrc")
+
+add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/my.qrc
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/my.qrc)
+
+add_library(qrc STATIC ${CMAKE_BINARY_DIR}/qrc_my.cxx)
diff --git a/Tests/EmptyLibrary/CMakeLists.txt b/Tests/EmptyLibrary/CMakeLists.txt
new file mode 100644
index 0000000000..baddbbf5e0
--- /dev/null
+++ b/Tests/EmptyLibrary/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.6)
+project(TestEmptyLibrary)
+
+add_subdirectory(subdir)
diff --git a/Tests/EmptyLibrary/subdir/CMakeLists.txt b/Tests/EmptyLibrary/subdir/CMakeLists.txt
new file mode 100644
index 0000000000..e273f8db94
--- /dev/null
+++ b/Tests/EmptyLibrary/subdir/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(test test.h)
diff --git a/Tests/EmptyLibrary/subdir/test.h b/Tests/EmptyLibrary/subdir/test.h
new file mode 100644
index 0000000000..8511f53d6e
--- /dev/null
+++ b/Tests/EmptyLibrary/subdir/test.h
@@ -0,0 +1 @@
+extern int dummy;
diff --git a/Tests/EmptyProperty/CMakeLists.txt b/Tests/EmptyProperty/CMakeLists.txt
new file mode 100644
index 0000000000..39e75f36a9
--- /dev/null
+++ b/Tests/EmptyProperty/CMakeLists.txt
@@ -0,0 +1,9 @@
+project (EmptyProperty)
+
+set_property(DIRECTORY APPEND
+ PROPERTY
+ COMPILE_DEFINITIONS)
+
+include(CTest)
+
+add_executable(EmptyProperty EmptyProperty.cxx)
diff --git a/Tests/EmptyProperty/EmptyProperty.cxx b/Tests/EmptyProperty/EmptyProperty.cxx
new file mode 100644
index 0000000000..78f2de106c
--- /dev/null
+++ b/Tests/EmptyProperty/EmptyProperty.cxx
@@ -0,0 +1 @@
+int main(void) { return 0; }
diff --git a/Tests/EnforceConfig.cmake.in b/Tests/EnforceConfig.cmake.in
new file mode 100644
index 0000000000..8c0817cd68
--- /dev/null
+++ b/Tests/EnforceConfig.cmake.in
@@ -0,0 +1,26 @@
+# Choose a configuration with which to drive CTest tests.
+if(CTEST_CONFIGURATION_TYPE)
+ set(CTestTest_CONFIG "${CTEST_CONFIGURATION_TYPE}")
+else()
+ set(CTestTest_CONFIG "@CTestTest_CONFIG@")
+endif()
+
+# Choose a configuration that was built if none is given.
+if(NOT CTEST_CONFIGURATION_TYPE)
+ set(CTEST_CMD "@CMAKE_CTEST_COMMAND@@CMAKE_EXECUTABLE_SUFFIX@")
+ get_filename_component(CTEST_DIR "${CTEST_CMD}" PATH)
+ get_filename_component(CTEST_EXE "${CTEST_CMD}" NAME)
+ foreach(cfg Release Debug MinSizeRel RelWithDebInfo)
+ if(NOT CTEST_CONFIGURATION_TYPE)
+ if(EXISTS "${CTEST_DIR}/${cfg}/${CTEST_EXE}")
+ set(CTEST_CONFIGURATION_TYPE ${cfg})
+ endif()
+ endif()
+ endforeach()
+ if(NOT CTEST_CONFIGURATION_TYPE)
+ set(CTEST_CONFIGURATION_TYPE NoConfig)
+ endif()
+ message("Guessing configuration ${CTEST_CONFIGURATION_TYPE}")
+endif()
+
+@TEST_HOME_ENV_CODE@
diff --git a/Tests/Environment/CMakeLists.txt b/Tests/Environment/CMakeLists.txt
new file mode 100644
index 0000000000..2b18d24666
--- /dev/null
+++ b/Tests/Environment/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.6)
+project(EnvironmentProj)
+
+add_executable(Environment main.cxx)
+
+enable_testing()
+
+add_test(Environment1 Environment)
+add_test(Environment2 Environment)
+add_test(EchoEnvironment1 ${CMAKE_COMMAND} -E environment)
+add_test(EchoEnvironment2 ${CMAKE_COMMAND} -E environment)
+
+# Make sure "CMAKE_ENV.*Happy Thanksgiving" is in the output of
+# the "1" tests:
+#
+set_tests_properties(Environment1 EchoEnvironment1 PROPERTIES
+ ENVIRONMENT "CMAKE_ENVIRONMENT_TEST_VAR=Happy Thanksgiving!"
+ PASS_REGULAR_EXPRESSION "CMAKE_ENV.*Happy Thanksgiving"
+)
+
+# Make sure "CMAKE_ENV.*Happy Thanksgiving" is *NOT* in the output of
+# the "2" tests:
+#
+set_tests_properties(Environment2 EchoEnvironment2 PROPERTIES
+ FAIL_REGULAR_EXPRESSION "CMAKE_ENV.*Happy Thanksgiving"
+)
diff --git a/Tests/Environment/main.cxx b/Tests/Environment/main.cxx
new file mode 100644
index 0000000000..2e1bf4c28b
--- /dev/null
+++ b/Tests/Environment/main.cxx
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+ char* var = getenv("CMAKE_ENVIRONMENT_TEST_VAR");
+ if (!var)
+ {
+ var = "(null)";
+ }
+
+ fprintf(stdout, "Environment:\n");
+ fprintf(stdout, " CMAKE_ENVIRONMENT_TEST_VAR='%s'\n", var);
+
+ return 0;
+}
diff --git a/Tests/ExportImport/CMakeLists.txt b/Tests/ExportImport/CMakeLists.txt
new file mode 100644
index 0000000000..eaad3d46c1
--- /dev/null
+++ b/Tests/ExportImport/CMakeLists.txt
@@ -0,0 +1,82 @@
+cmake_minimum_required (VERSION 2.7.20090711)
+project(ExportImport C CXX)
+if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
+endif()
+
+# Wipe out the install tree to make sure the exporter works.
+add_custom_command(
+ OUTPUT ${ExportImport_BINARY_DIR}/CleanupProject
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${ExportImport_BINARY_DIR}/Root
+ )
+add_custom_target(CleanupTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/CleanupProject)
+set_property(
+ SOURCE ${ExportImport_BINARY_DIR}/CleanupProject
+ PROPERTY SYMBOLIC 1
+ )
+
+if(CMAKE_CONFIGURATION_TYPES)
+ set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
+else()
+ if(CMAKE_BUILD_TYPE)
+ set(NESTED_CONFIG_TYPE -C "${CMAKE_BUILD_TYPE}")
+ else()
+ set(NESTED_CONFIG_TYPE)
+ endif()
+endif()
+
+if(MINGW OR MSYS)
+ # Test CMAKE_GNUtoMS whether we have VS or not.
+ set(ExportImport_GNUtoMS 1)
+endif()
+
+configure_file(${ExportImport_SOURCE_DIR}/InitialCache.cmake.in
+ ${ExportImport_BINARY_DIR}/InitialCache.cmake @ONLY)
+
+# Build and install the exporter.
+add_custom_command(
+ OUTPUT ${ExportImport_BINARY_DIR}/ExportProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
+ --build-and-test
+ ${ExportImport_SOURCE_DIR}/Export
+ ${ExportImport_BINARY_DIR}/Export
+ --build-noclean
+ --build-project Export
+ --build-target install
+ --build-generator ${CMAKE_GENERATOR}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-options -C${ExportImport_BINARY_DIR}/InitialCache.cmake
+ VERBATIM
+ )
+add_custom_target(ExportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ExportProject)
+add_dependencies(ExportTarget CleanupTarget)
+set_property(
+ SOURCE ${ExportImport_BINARY_DIR}/ExportProject
+ PROPERTY SYMBOLIC 1
+ )
+
+# Build and install the importer.
+add_custom_command(
+ OUTPUT ${ExportImport_BINARY_DIR}/ImportProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
+ --build-and-test
+ ${ExportImport_SOURCE_DIR}/Import
+ ${ExportImport_BINARY_DIR}/Import
+ --build-noclean
+ --build-project Import
+ --build-generator ${CMAKE_GENERATOR}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-options -C${ExportImport_BINARY_DIR}/InitialCache.cmake
+ VERBATIM
+ )
+add_custom_target(ImportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ImportProject)
+add_dependencies(ImportTarget ExportTarget)
+set_property(
+ SOURCE ${ExportImport_BINARY_DIR}/ImportProject
+ PROPERTY SYMBOLIC 1
+ )
+
+add_executable(ExportImport main.c)
+add_dependencies(ExportImport ImportTarget)
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt
new file mode 100644
index 0000000000..febdfe6bc3
--- /dev/null
+++ b/Tests/ExportImport/Export/CMakeLists.txt
@@ -0,0 +1,510 @@
+cmake_minimum_required (VERSION 2.7.20090711)
+project(Export C CXX)
+
+# Pretend that RelWithDebInfo should link to debug libraries to test
+# the DEBUG_CONFIGURATIONS property.
+set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug RelWithDebInfo)
+
+add_library(testExe1lib STATIC testExe1lib.c) # not exported
+add_executable(testExe1 testExe1.c)
+target_link_libraries(testExe1 testExe1lib)
+set_property(TARGET testExe1 PROPERTY VERSION 4)
+
+add_library(testExe2libImp SHARED testExe2libImp.c)
+set_property(TARGET testExe2libImp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
+add_library(testExe2lib SHARED testExe2lib.c)
+target_link_libraries(testExe2lib testExe2libImp)
+set_property(TARGET testExe2lib PROPERTY LINK_INTERFACE_LIBRARIES "")
+add_executable(testExe2 testExe2.c)
+set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
+set_property(TARGET testExe2 PROPERTY LINK_INTERFACE_LIBRARIES testExe2lib)
+
+add_library(testLib1 STATIC testLib1.c)
+add_library(testLib2 STATIC testLib2.c)
+target_link_libraries(testLib2 testLib1)
+
+# Test install(FILES) with generator expressions referencing testLib1.
+add_custom_command(TARGET testLib1 POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:testLib1>
+ $<TARGET_FILE:testLib1>.genex
+ )
+install(FILES $<TARGET_FILE:testLib1>.genex
+ DESTINATION lib
+ )
+set_property(TARGET testLib1 PROPERTY MY_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/testLib1file1.txt
+ ${CMAKE_CURRENT_SOURCE_DIR}/testLib1file2.txt
+ )
+install(FILES $<TARGET_PROPERTY:testLib1,MY_FILES>
+ DESTINATION doc
+ )
+
+# Test library with empty link interface. Link it to an implementation
+# dependency that itself links to dependencies publicly.
+add_library(testLib3ImpDep SHARED testLib3ImpDep.c)
+set_property(TARGET testLib3ImpDep PROPERTY LIBRARY_OUTPUT_DIRECTORY impl/dep)
+add_library(testLib3Imp SHARED testLib3Imp.c)
+set_property(TARGET testLib3Imp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
+target_link_libraries(testLib3Imp testLib3ImpDep)
+add_library(testLib3 SHARED testLib3.c)
+target_link_libraries(testLib3 testLib3Imp)
+set_property(TARGET testLib3 PROPERTY LINK_INTERFACE_LIBRARIES "")
+set_property(TARGET testLib3 PROPERTY VERSION 1.2)
+set_property(TARGET testLib3 PROPERTY SOVERSION 3)
+
+# Test <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME[_<CONFIG>] properties.
+set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME_DEBUG testLib3dll-d)
+set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME_RELEASE testLib3dll-r)
+set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME testLib3dll)
+set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME_DEBUG testLib3lib-d)
+set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME_RELEASE testLib3lib-r)
+set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME testLib3lib)
+set_property(TARGET testLib3 PROPERTY ARCHIVE_OUTPUT_NAME testLib3import)
+
+add_library(testLib4 SHARED testLib4.c)
+set_property(TARGET testLib4 PROPERTY FRAMEWORK 1)
+
+add_library(testLib5 SHARED testLib5.c)
+
+add_library(testLib6 STATIC testLib6.cxx testLib6c.c)
+
+# Work-around: Visual Studio 6 does not support per-target object files.
+set(VS6)
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+ set(VS6 1)
+endif()
+
+# Test using the target_link_libraries command to set the
+# LINK_INTERFACE_LIBRARIES* properties. We construct two libraries
+# providing the same two symbols. In each library one of the symbols
+# will work and the other one will fail to link. The import part of
+# this test will try to use the symbol corresponding to the
+# configuration in which it is built. If the proper library is not
+# used via the link interface the import test will fail to link.
+add_library(testLib4lib STATIC testLib4lib.c)
+add_library(testLib4libdbg STATIC testLib4libopt.c testLib4libdbg${VS6}.c)
+add_library(testLib4libopt STATIC testLib4libdbg.c testLib4libopt${VS6}.c)
+set_property(TARGET testLib4libdbg PROPERTY COMPILE_DEFINITIONS LIB_DBG)
+set_property(TARGET testLib4libopt PROPERTY COMPILE_DEFINITIONS LIB_OPT)
+target_link_libraries(testLib4
+ LINK_INTERFACE_LIBRARIES
+ testLib4lib debug testLib4libdbg optimized testLib4libopt
+ )
+
+add_executable(testExe3 testExe3.c)
+set_property(TARGET testExe3 PROPERTY MACOSX_BUNDLE 1)
+
+# Test cyclic dependencies.
+add_library(testLibCycleA STATIC
+ testLibCycleA1.c testLibCycleA2.c testLibCycleA3.c)
+add_library(testLibCycleB STATIC
+ testLibCycleB1.c testLibCycleB2.c testLibCycleB3.c)
+target_link_libraries(testLibCycleA testLibCycleB)
+target_link_libraries(testLibCycleB testLibCycleA)
+set_property(TARGET testLibCycleA PROPERTY LINK_INTERFACE_MULTIPLICITY 3)
+
+# Test exporting dependent libraries into different exports
+add_library(testLibRequired testLibRequired.c)
+add_library(testLibDepends testLibDepends.c)
+target_link_libraries(testLibDepends LINK_PUBLIC testLibRequired)
+
+macro(add_include_lib _libName)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_libName}.c" "// no content\n")
+ add_library(${_libName} "${CMAKE_CURRENT_BINARY_DIR}/${_libName}.c")
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_libName}")
+ set_property(TARGET ${_libName} APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${_libName}>"
+ )
+ if (NOT "${ARGV1}" STREQUAL "NO_HEADER")
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_libName}/${_libName}.h" "// no content\n")
+ install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/${_libName}/${_libName}.h"
+ DESTINATION include/${_libName}
+ )
+ endif()
+endmacro()
+
+add_include_lib(testLibIncludeRequired1)
+add_include_lib(testLibIncludeRequired2)
+add_include_lib(testLibIncludeRequired3 NO_HEADER)
+# Generate testLibIncludeRequired4 in the testLibIncludeRequired3 directory
+# with an error. If the includes from testLibIncludeRequired3 appear first,
+# the error will be hit.
+# Below, the '3' library appears before the '4' library
+# but we are testing that the INSTALL_INTERFACE causes it not to be used
+# at build time.
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired3/testLibIncludeRequired4.h" "#error Should not be included\n")
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired3/testLibIncludeRequired4.h"
+ DESTINATION include/testLibIncludeRequired3
+)
+add_include_lib(testLibIncludeRequired4)
+add_include_lib(testLibIncludeRequired5 NO_HEADER)
+# Generate testLibIncludeRequired6 in the testLibIncludeRequired5 directory
+# with an error. If the includes from testLibIncludeRequired5 appear first,
+# the error will be hit.
+# Below, the '5' library appears before the '6' library
+# but we are testing that when the installed IMPORTED target is used, from
+# the Import side of this unit test, the '6' include from the '5' directory
+# will not be used because it is in the BUILD_INTERFACE only.
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired5/testLibIncludeRequired6.h" "#error Should not be included\n")
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired5/testLibIncludeRequired6.h"
+ DESTINATION include/testLibIncludeRequired5
+)
+add_include_lib(testLibIncludeRequired6)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired7/testLibIncludeRequired7.h" "// No content\n")
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired7/testLibIncludeRequired7.h"
+ DESTINATION include/testLibIncludeRequired7
+)
+
+set_property(TARGET testLibRequired APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES
+ $<TARGET_PROPERTY:testLibIncludeRequired1,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:$<1:$<TARGET_NAME:testLibIncludeRequired2>>,INTERFACE_INCLUDE_DIRECTORIES>
+ $<INSTALL_INTERFACE:$<TARGET_PROPERTY:testLibIncludeRequired3,INTERFACE_INCLUDE_DIRECTORIES>>
+ $<BUILD_INTERFACE:$<TARGET_PROPERTY:testLibIncludeRequired4,INTERFACE_INCLUDE_DIRECTORIES>>
+ $<BUILD_INTERFACE:$<TARGET_PROPERTY:testLibIncludeRequired5,INTERFACE_INCLUDE_DIRECTORIES>>
+ $<INSTALL_INTERFACE:$<TARGET_PROPERTY:testLibIncludeRequired6,INTERFACE_INCLUDE_DIRECTORIES>>
+ # The BUILD_INTERFACE entry from above is duplicated below. This is to test that
+ # the INSTALL_INTERFACE entry bound by a BUILD_INTERFACE entry on either side is
+ # preprocessed correctly on install(EXPORT).
+ $<BUILD_INTERFACE:$<TARGET_PROPERTY:testLibIncludeRequired5,INTERFACE_INCLUDE_DIRECTORIES>>
+ # Test that the below is non-fatal
+ $<$<STREQUAL:one,two>:$<TARGET_PROPERTY:not_a_target,INTERFACE_INCLUDE_DIRECTORIES>>
+ $<INSTALL_INTERFACE:include/testLibIncludeRequired7;include/testLibIncludeRequired4>
+)
+
+set_property(TARGET testLibRequired APPEND PROPERTY
+ INTERFACE_COMPILE_DEFINITIONS
+ testLibRequired_IFACE_DEFINE
+ $<BUILD_INTERFACE:BuildOnly_DEFINE>
+ $<INSTALL_INTERFACE:InstallOnly_DEFINE>
+)
+include(GenerateExportHeader)
+
+add_subdirectory(renamed)
+
+add_library(testSharedLibRequired SHARED testSharedLibRequired.cpp)
+generate_export_header(testSharedLibRequired)
+set_property(TARGET testSharedLibRequired
+ PROPERTY
+ INTERFACE_POSITION_INDEPENDENT_CODE ON
+)
+set_property(TARGET testSharedLibRequired APPEND PROPERTY
+ INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}"
+)
+install(FILES
+ "${CMAKE_CURRENT_SOURCE_DIR}/testSharedLibRequired.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/testsharedlibrequired_export.h"
+ DESTINATION include/testSharedLibRequired
+)
+set_property(TARGET testSharedLibRequired APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
+)
+set_property(TARGET testSharedLibRequired APPEND PROPERTY
+ INTERFACE_COMPILE_DEFINITIONS USING_TESTSHAREDLIBREQUIRED
+)
+set_property(TARGET testSharedLibRequired
+ APPEND PROPERTY
+ COMPATIBLE_INTERFACE_BOOL CUSTOM_PROP
+)
+set_property(TARGET testSharedLibRequired
+ PROPERTY
+ INTERFACE_CUSTOM_PROP ON
+)
+set_property(TARGET testSharedLibRequired
+ APPEND PROPERTY
+ COMPATIBLE_INTERFACE_STRING CUSTOM_STRING
+)
+set_property(TARGET testSharedLibRequired
+ PROPERTY
+ INTERFACE_CUSTOM_STRING testcontent
+)
+set_property(TARGET testSharedLibRequired APPEND PROPERTY
+ INTERFACE_COMPILE_OPTIONS
+ $<$<CXX_COMPILER_ID:GNU>:-DCUSTOM_COMPILE_OPTION>
+)
+
+add_library(testSharedLibRequiredUser SHARED testSharedLibRequiredUser.cpp)
+generate_export_header(testSharedLibRequiredUser)
+# LINK_PRIVATE so that it appears in the LINK_DEPENDENT_LIBRARIES, but not
+# the INTERFACE_LINK_LIBRARIES.
+set_property(TARGET testSharedLibRequiredUser APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
+)
+target_link_libraries(testSharedLibRequiredUser LINK_PRIVATE testSharedLibRequired)
+install(FILES
+ "${CMAKE_CURRENT_SOURCE_DIR}/testSharedLibRequiredUser.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/testsharedlibrequireduser_export.h"
+ DESTINATION include/testSharedLibRequiredUser
+)
+
+cmake_policy(SET CMP0022 NEW)
+add_library(testSharedLibRequiredUser2 SHARED testSharedLibRequiredUser2.cpp)
+generate_export_header(testSharedLibRequiredUser2)
+set_property(TARGET testSharedLibRequiredUser2 APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
+)
+set_property(TARGET testSharedLibRequiredUser2 PROPERTY LINK_LIBRARIES testSharedLibRequired)
+set_property(TARGET testSharedLibRequiredUser2 PROPERTY INTERFACE_LINK_LIBRARIES testSharedLibRequired)
+install(FILES
+ "${CMAKE_CURRENT_SOURCE_DIR}/testSharedLibRequiredUser2.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/testsharedlibrequireduser2_export.h"
+ DESTINATION include/testSharedLibRequiredUser2
+)
+cmake_policy(SET CMP0022 OLD)
+
+add_library(testSharedLibDepends SHARED testSharedLibDepends.cpp)
+set_property(TARGET testSharedLibDepends APPEND PROPERTY
+ INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}"
+)
+generate_export_header(testSharedLibDepends)
+
+set_property(TARGET testSharedLibDepends APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES
+ $<TARGET_PROPERTY:testSharedLibRequired,INTERFACE_INCLUDE_DIRECTORIES>
+)
+install(FILES
+ "${CMAKE_CURRENT_SOURCE_DIR}/testSharedLibDepends.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/testsharedlibdepends_export.h"
+ DESTINATION include/testSharedLibDepends
+)
+set_property(TARGET testSharedLibDepends APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/testSharedLibDepends>"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
+)
+
+# LINK_PRIVATE because the LINK_INTERFACE_LIBRARIES is specified above.
+target_link_libraries(testSharedLibDepends LINK_PRIVATE testSharedLibRequired)
+target_link_libraries(testSharedLibDepends LINK_PUBLIC renamed_on_export)
+target_link_libraries(testSharedLibDepends LINK_INTERFACE_LIBRARIES
+ $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:$<TARGET_NAME:testSharedLibRequired>>)
+
+add_library(cmp0022OLD SHARED cmp0022_vs6_1.cpp)
+generate_export_header(cmp0022OLD BASE_NAME cmp0022)
+target_include_directories(cmp0022OLD PUBLIC
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
+ "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/cmp0022>"
+)
+cmake_policy(SET CMP0022 NEW)
+add_library(cmp0022NEW SHARED cmp0022_vs6_1.cpp)
+set_property(TARGET cmp0022NEW PROPERTY DEFINE_SYMBOL cmp0022OLD_EXPORTS)
+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)
+install(FILES
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmp0022.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/cmp0022_export.h"
+ DESTINATION include/cmp0022
+)
+
+set_property(TARGET testLib2 APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS USING_TESTLIB2)
+set_property(TARGET testLib3 APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS USING_TESTLIB3)
+
+set_property(TARGET cmp0022NEW APPEND PROPERTY INTERFACE_LINK_LIBRARIES testLib2)
+# set_property(TARGET cmp0022NEW APPEND PROPERTY LINK_INTERFACE_LIBRARIES testLibIncludeRequired2) # TODO: Test for error
+set_property(TARGET cmp0022OLD APPEND PROPERTY INTERFACE_LINK_LIBRARIES testLib2)
+set_property(TARGET cmp0022OLD APPEND PROPERTY LINK_INTERFACE_LIBRARIES testLib3)
+
+add_library(noIncludesInterface empty.cpp)
+
+add_library(systemlib SHARED systemlib.cpp)
+install(FILES systemlib.h DESTINATION include/systemlib)
+target_include_directories(systemlib
+ INTERFACE
+ $<INSTALL_INTERFACE:include/systemlib>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+)
+
+install(TARGETS testLibRequired
+ EXPORT RequiredExp DESTINATION lib
+ INCLUDES DESTINATION
+ installIncludesTest
+ $<INSTALL_PREFIX>/installIncludesTest2
+ installIncludesTest3/$<TARGET_PROPERTY:NAME>
+ $<TARGET_PROPERTY:NAME>/installIncludesTest4
+ $<INSTALL_INTERFACE:installIncludesTest5$<0:>>
+ $<INSTALL_INTERFACE:$<0:>installIncludesTest6>
+ $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/installIncludesTest7>
+)
+
+target_include_directories(testLibRequired INTERFACE
+ # These can't be in the above install(INCLUDES DESTINATION call because
+ # that is only for installed interfaces. These directories are prefixes
+ # in the build dir, which is an error for the installed interface.
+ # We add them here so that we don't have to add conditions in the Import
+ # component of the test.
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest5$<0:>>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/$<0:>installIncludesTest6>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest7>
+ $<INSTALL_INTERFACE:installIncludesTest8/$<0:>>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest8$<0:>>
+)
+install(TARGETS
+ testLibIncludeRequired1
+ testLibIncludeRequired2
+ testLibIncludeRequired3
+ testLibIncludeRequired4
+ testLibIncludeRequired5
+ testLibIncludeRequired6
+ testSharedLibRequired
+ testSharedLibRequiredUser
+ testSharedLibRequiredUser2
+ noIncludesInterface
+ EXPORT RequiredExp DESTINATION lib
+ INCLUDES DESTINATION
+ $<INSTALL_PREFIX>/include/$<TARGET_PROPERTY:NAME>
+)
+install(EXPORT RequiredExp NAMESPACE Req:: FILE testLibRequiredTargets.cmake DESTINATION lib/cmake/testLibRequired)
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest/installIncludesTest.h" "// No content\n")
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest2")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest2/installIncludesTest2.h" "// No content\n")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest3/testLibRequired")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest3/testLibRequired/installIncludesTest3.h" "// No content\n")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/testLibRequired/installIncludesTest4")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testLibRequired/installIncludesTest4/installIncludesTest4.h" "// No content\n")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest5")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest5/installIncludesTest5.h" "// No content\n")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest6")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest6/installIncludesTest6.h" "// No content\n")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest7")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest7/installIncludesTest7.h" "// No content\n")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest8")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest8/installIncludesTest8.h" "// No content\n")
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest/installIncludesTest.h"
+ DESTINATION installIncludesTest
+)
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest2/installIncludesTest2.h"
+ DESTINATION installIncludesTest2
+)
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest3/testLibRequired/installIncludesTest3.h"
+ DESTINATION installIncludesTest3/testLibRequired
+)
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/testLibRequired/installIncludesTest4/installIncludesTest4.h"
+ DESTINATION testLibRequired/installIncludesTest4
+)
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest5/installIncludesTest5.h"
+ DESTINATION installIncludesTest5
+)
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest6/installIncludesTest6.h"
+ DESTINATION installIncludesTest6
+)
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest7/installIncludesTest7.h"
+ DESTINATION installIncludesTest7
+)
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest8/installIncludesTest8.h"
+ DESTINATION installIncludesTest8
+)
+
+install(TARGETS testLibDepends testSharedLibDepends EXPORT DependsExp DESTINATION lib )
+install(EXPORT DependsExp FILE testLibDependsTargets.cmake DESTINATION lib/cmake/testLibDepends)
+
+file(WRITE
+ "${CMAKE_CURRENT_BINARY_DIR}/testLibRequiredConfig.cmake"
+ "
+if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION VERSION_LESS 2.3 AND NOT \${CMAKE_FIND_PACKAGE_NAME}_INTERFACES)
+ set(\${CMAKE_FIND_PACKAGE_NAME}_NO_INTERFACES 1)
+endif()
+include(\"\${CMAKE_CURRENT_LIST_DIR}/testLibRequiredTargets.cmake\")
+set(\${CMAKE_FIND_PACKAGE_NAME}_INCLUDE_DIRS \"${CMAKE_CURRENT_BINARY_DIR}\" \"${CMAKE_CURRENT_SOURCE_DIR}\" )
+"
+)
+
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file( testLibRequiredConfigVersion.cmake VERSION 2.5 COMPATIBILITY AnyNewerVersion)
+
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/testLibRequiredConfig.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/testLibRequiredConfigVersion.cmake"
+ DESTINATION lib/cmake/testLibRequired
+)
+
+# Install and export from install tree.
+install(
+ TARGETS
+ testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3
+ testExe2lib testLib4lib testLib4libdbg testLib4libopt
+ testLib6
+ testLibCycleA testLibCycleB
+ cmp0022NEW cmp0022OLD
+ systemlib
+ EXPORT exp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib NAMELINK_SKIP
+ ARCHIVE DESTINATION lib
+ FRAMEWORK DESTINATION Frameworks
+ BUNDLE DESTINATION Applications
+ )
+if (APPLE)
+ file(COPY testLib4.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/testLib4.framework/Headers)
+ file(COPY testLib4.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug/testLib4.framework/Headers)
+ file(COPY testLib4.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Release/testLib4.framework/Headers)
+ install(FILES testLib4.h DESTINATION Frameworks/testLib4.framework/Headers)
+endif()
+install(
+ TARGETS
+ testExe2libImp testLib3Imp
+ EXPORT exp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib/impl
+ ARCHIVE DESTINATION lib/impl
+ )
+install(
+ TARGETS
+ testLib3ImpDep
+ EXPORT exp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib/impl/dep
+ ARCHIVE DESTINATION lib/impl/dep
+ )
+install(
+ TARGETS testLib5
+ EXPORT exp
+ # Leave out RUNTIME DESTINATION to test implib-only export.
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+ )
+install(EXPORT exp NAMESPACE exp_ DESTINATION lib/exp)
+
+# Install testLib5.dll outside the export.
+if(WIN32)
+ install(TARGETS testLib5 RUNTIME DESTINATION bin)
+endif()
+
+add_subdirectory(sublib) # For CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE test.
+
+# Export from build tree.
+export(TARGETS testExe1 testLib1 testLib2 testLib3
+ testExe2libImp testLib3Imp testLib3ImpDep subdirlib
+ testSharedLibRequired testSharedLibRequiredUser testSharedLibRequiredUser2
+ testSharedLibDepends renamed_on_export
+ cmp0022NEW cmp0022OLD
+ systemlib
+ NAMESPACE bld_
+ FILE ExportBuildTree.cmake
+ )
+export(TARGETS testExe2 testLib4 testLib5 testLib6 testExe3 testExe2lib
+ testLib4lib testLib4libdbg testLib4libopt
+ testLibCycleA testLibCycleB
+ NAMESPACE bld_
+ APPEND FILE ExportBuildTree.cmake
+ )
+
+add_subdirectory(Interface)
diff --git a/Tests/ExportImport/Export/Interface/CMakeLists.txt b/Tests/ExportImport/Export/Interface/CMakeLists.txt
new file mode 100644
index 0000000000..523fc298c9
--- /dev/null
+++ b/Tests/ExportImport/Export/Interface/CMakeLists.txt
@@ -0,0 +1,58 @@
+
+add_library(headeronly INTERFACE)
+set_property(TARGET headeronly PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/headeronly>"
+ "$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/headeronly>"
+)
+set_property(TARGET headeronly PROPERTY INTERFACE_COMPILE_DEFINITIONS "HEADERONLY_DEFINE")
+
+include(GenerateExportHeader)
+add_library(sharedlib SHARED sharedlib.cpp)
+generate_export_header(sharedlib)
+set_property(TARGET sharedlib PROPERTY INCLUDE_DIRECTORIES
+ "${CMAKE_CURRENT_SOURCE_DIR}/sharedlib"
+ "${CMAKE_CURRENT_BINARY_DIR}"
+)
+set_property(TARGET sharedlib PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sharedlib;${CMAKE_CURRENT_BINARY_DIR}>"
+ "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/sharedlib>"
+)
+
+set_property(TARGET sharedlib PROPERTY INTERFACE_COMPILE_DEFINITIONS "SHAREDLIB_DEFINE")
+
+add_library(sharediface INTERFACE)
+target_link_libraries(sharediface INTERFACE sharedlib)
+
+add_library(use_auto_type INTERFACE)
+target_compile_features(use_auto_type INTERFACE cxx_auto_type)
+
+add_library(use_c_restrict INTERFACE)
+target_compile_features(use_c_restrict INTERFACE c_restrict)
+
+install(TARGETS headeronly sharediface use_auto_type use_c_restrict
+ EXPORT expInterface
+)
+install(TARGETS sharedlib
+ EXPORT expInterface
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib NAMELINK_SKIP
+ ARCHIVE DESTINATION lib
+ FRAMEWORK DESTINATION Frameworks
+ BUNDLE DESTINATION Applications
+)
+install(FILES
+ headeronly/headeronly.h
+ DESTINATION include/headeronly
+)
+install(FILES
+ sharedlib/sharedlib.h
+ "${CMAKE_CURRENT_BINARY_DIR}/sharedlib_export.h"
+ DESTINATION include/sharedlib
+)
+
+install(EXPORT expInterface NAMESPACE exp:: DESTINATION lib/exp)
+
+export(EXPORT expInterface
+ NAMESPACE bld::
+ FILE ../ExportInterfaceBuildTree.cmake
+)
diff --git a/Tests/ExportImport/Export/Interface/headeronly/headeronly.h b/Tests/ExportImport/Export/Interface/headeronly/headeronly.h
new file mode 100644
index 0000000000..3673c21875
--- /dev/null
+++ b/Tests/ExportImport/Export/Interface/headeronly/headeronly.h
@@ -0,0 +1,7 @@
+
+enum { one };
+
+struct HeaderOnly
+{
+ int foo() const { return 0; }
+};
diff --git a/Tests/ExportImport/Export/Interface/sharedlib.cpp b/Tests/ExportImport/Export/Interface/sharedlib.cpp
new file mode 100644
index 0000000000..88ca7130f0
--- /dev/null
+++ b/Tests/ExportImport/Export/Interface/sharedlib.cpp
@@ -0,0 +1,7 @@
+
+#include "sharedlib.h"
+
+int SharedLibObject::foo() const
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/Interface/sharedlib/sharedlib.h b/Tests/ExportImport/Export/Interface/sharedlib/sharedlib.h
new file mode 100644
index 0000000000..aad9ef3f47
--- /dev/null
+++ b/Tests/ExportImport/Export/Interface/sharedlib/sharedlib.h
@@ -0,0 +1,7 @@
+
+#include "sharedlib_export.h"
+
+struct SHAREDLIB_EXPORT SharedLibObject
+{
+ int foo() const;
+};
diff --git a/Tests/ExportImport/Export/cmp0022.cpp b/Tests/ExportImport/Export/cmp0022.cpp
new file mode 100644
index 0000000000..bef8e6180b
--- /dev/null
+++ b/Tests/ExportImport/Export/cmp0022.cpp
@@ -0,0 +1,7 @@
+
+#include "cmp0022.h"
+
+int cmp0022()
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/cmp0022.h b/Tests/ExportImport/Export/cmp0022.h
new file mode 100644
index 0000000000..32bf71a449
--- /dev/null
+++ b/Tests/ExportImport/Export/cmp0022.h
@@ -0,0 +1,4 @@
+
+#include "cmp0022_export.h"
+
+int CMP0022_EXPORT cmp0022();
diff --git a/Tests/ExportImport/Export/cmp0022_vs6_1.cpp b/Tests/ExportImport/Export/cmp0022_vs6_1.cpp
new file mode 100644
index 0000000000..a6ec838059
--- /dev/null
+++ b/Tests/ExportImport/Export/cmp0022_vs6_1.cpp
@@ -0,0 +1 @@
+#include "cmp0022.cpp"
diff --git a/Tests/ExportImport/Export/cmp0022_vs6_2.cpp b/Tests/ExportImport/Export/cmp0022_vs6_2.cpp
new file mode 100644
index 0000000000..a6ec838059
--- /dev/null
+++ b/Tests/ExportImport/Export/cmp0022_vs6_2.cpp
@@ -0,0 +1 @@
+#include "cmp0022.cpp"
diff --git a/Tests/ExportImport/Export/empty.cpp b/Tests/ExportImport/Export/empty.cpp
new file mode 100644
index 0000000000..1787013f64
--- /dev/null
+++ b/Tests/ExportImport/Export/empty.cpp
@@ -0,0 +1,4 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty() { return 0; }
diff --git a/Tests/ExportImport/Export/renamed/CMakeLists.txt b/Tests/ExportImport/Export/renamed/CMakeLists.txt
new file mode 100644
index 0000000000..a763251391
--- /dev/null
+++ b/Tests/ExportImport/Export/renamed/CMakeLists.txt
@@ -0,0 +1,20 @@
+
+add_library(renamed_on_export SHARED renamed.cxx)
+generate_export_header(renamed_on_export)
+target_include_directories(renamed_on_export
+ PUBLIC "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/renamed>"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
+)
+set_property(TARGET renamed_on_export
+ PROPERTY
+ EXPORT_NAME renamed
+)
+
+install(FILES
+ "${CMAKE_CURRENT_SOURCE_DIR}/renamed.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/renamed_on_export_export.h"
+ DESTINATION include/renamed
+)
+
+install(TARGETS renamed_on_export
+ EXPORT exp DESTINATION lib )
diff --git a/Tests/ExportImport/Export/renamed/renamed.cxx b/Tests/ExportImport/Export/renamed/renamed.cxx
new file mode 100644
index 0000000000..b3e3e7e129
--- /dev/null
+++ b/Tests/ExportImport/Export/renamed/renamed.cxx
@@ -0,0 +1,7 @@
+
+#include "renamed.h"
+
+int Renamed::foo()
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/renamed/renamed.h b/Tests/ExportImport/Export/renamed/renamed.h
new file mode 100644
index 0000000000..06ac601d5d
--- /dev/null
+++ b/Tests/ExportImport/Export/renamed/renamed.h
@@ -0,0 +1,12 @@
+
+#ifndef RENAMED_H
+#define RENAMED_H
+
+#include "renamed_on_export_export.h"
+
+struct RENAMED_ON_EXPORT_EXPORT Renamed
+{
+ int foo();
+};
+
+#endif
diff --git a/Tests/ExportImport/Export/sublib/CMakeLists.txt b/Tests/ExportImport/Export/sublib/CMakeLists.txt
new file mode 100644
index 0000000000..a5c6413c10
--- /dev/null
+++ b/Tests/ExportImport/Export/sublib/CMakeLists.txt
@@ -0,0 +1,6 @@
+
+set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_library(subdirlib SHARED subdir.cpp)
+generate_export_header(subdirlib)
diff --git a/Tests/ExportImport/Export/sublib/subdir.cpp b/Tests/ExportImport/Export/sublib/subdir.cpp
new file mode 100644
index 0000000000..35b0743686
--- /dev/null
+++ b/Tests/ExportImport/Export/sublib/subdir.cpp
@@ -0,0 +1,7 @@
+
+#include "subdir.h"
+
+int SubDirObject::foo()
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/sublib/subdir.h b/Tests/ExportImport/Export/sublib/subdir.h
new file mode 100644
index 0000000000..3a4b73d735
--- /dev/null
+++ b/Tests/ExportImport/Export/sublib/subdir.h
@@ -0,0 +1,12 @@
+
+#ifndef SUBDIR_H
+#define SUBDIR_H
+
+#include "subdirlib_export.h"
+
+struct SUBDIRLIB_EXPORT SubDirObject
+{
+ int foo();
+};
+
+#endif
diff --git a/Tests/ExportImport/Export/systemlib.cpp b/Tests/ExportImport/Export/systemlib.cpp
new file mode 100644
index 0000000000..ec45148f74
--- /dev/null
+++ b/Tests/ExportImport/Export/systemlib.cpp
@@ -0,0 +1,7 @@
+
+#include "systemlib.h"
+
+SystemStruct::SystemStruct()
+{
+
+}
diff --git a/Tests/ExportImport/Export/systemlib.h b/Tests/ExportImport/Export/systemlib.h
new file mode 100644
index 0000000000..f7900c0986
--- /dev/null
+++ b/Tests/ExportImport/Export/systemlib.h
@@ -0,0 +1,22 @@
+
+#ifndef SYSTEMLIB_H
+#define SYSTEMLIB_H
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define systemlib_EXPORT __declspec(dllexport)
+#else
+# define systemlib_EXPORT
+#endif
+
+struct systemlib_EXPORT SystemStruct
+{
+ SystemStruct();
+
+ void someMethod()
+ {
+ int unused;
+ // unused warning not issued when this header is used as a system header.
+ }
+};
+
+#endif
diff --git a/Tests/ExportImport/Export/testExe1.c b/Tests/ExportImport/Export/testExe1.c
new file mode 100644
index 0000000000..e00fac74f4
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe1.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+extern int testExe1lib(void);
+
+int main(int argc, const char* argv[])
+{
+ if(argc < 2)
+ {
+ fprintf(stderr, "Must specify output file.\n");
+ return 1;
+ }
+ {
+ FILE* f = fopen(argv[1], "w");
+ if(f)
+ {
+ fprintf(f, "int generated_by_testExe1() { return 0; }\n");
+ fclose(f);
+ }
+ else
+ {
+ fprintf(stderr, "Error writing to %s\n", argv[1]);
+ return 1;
+ }
+ }
+ return testExe1lib();
+}
diff --git a/Tests/ExportImport/Export/testExe1lib.c b/Tests/ExportImport/Export/testExe1lib.c
new file mode 100644
index 0000000000..7ad48a3921
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe1lib.c
@@ -0,0 +1 @@
+int testExe1lib(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testExe2.c b/Tests/ExportImport/Export/testExe2.c
new file mode 100644
index 0000000000..f7d93453a1
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe2.c
@@ -0,0 +1,12 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testExe2_EXPORT __declspec(dllexport)
+#else
+# define testExe2_EXPORT
+#endif
+
+testExe2_EXPORT int testExe2Func(void) { return 123; }
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/testExe2lib.c b/Tests/ExportImport/Export/testExe2lib.c
new file mode 100644
index 0000000000..1991439005
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe2lib.c
@@ -0,0 +1,10 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testExe2lib_EXPORT __declspec(dllexport)
+# define testExe2libImp_IMPORT __declspec(dllimport)
+#else
+# define testExe2lib_EXPORT
+# define testExe2libImp_IMPORT
+#endif
+
+testExe2libImp_IMPORT int testExe2libImp(void);
+testExe2lib_EXPORT int testExe2lib(void) { return testExe2libImp(); }
diff --git a/Tests/ExportImport/Export/testExe2libImp.c b/Tests/ExportImport/Export/testExe2libImp.c
new file mode 100644
index 0000000000..f5a23af555
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe2libImp.c
@@ -0,0 +1,7 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testExe2libImp_EXPORT __declspec(dllexport)
+#else
+# define testExe2libImp_EXPORT
+#endif
+
+testExe2libImp_EXPORT int testExe2libImp(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testExe3.c b/Tests/ExportImport/Export/testExe3.c
new file mode 100644
index 0000000000..895e2fc2d0
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe3.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int main(int argc, const char* argv[])
+{
+ if(argc < 2)
+ {
+ fprintf(stderr, "Must specify output file.\n");
+ return 1;
+ }
+ {
+ FILE* f = fopen(argv[1], "w");
+ if(f)
+ {
+ fprintf(f, "int generated_by_testExe3() { return 0; }\n");
+ fclose(f);
+ }
+ else
+ {
+ fprintf(stderr, "Error writing to %s\n", argv[1]);
+ return 1;
+ }
+ }
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/testLib1.c b/Tests/ExportImport/Export/testLib1.c
new file mode 100644
index 0000000000..35bb1e5db5
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib1.c
@@ -0,0 +1 @@
+int testLib1(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testLib1file1.txt b/Tests/ExportImport/Export/testLib1file1.txt
new file mode 100644
index 0000000000..73601df59a
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib1file1.txt
@@ -0,0 +1 @@
+testLib1file1
diff --git a/Tests/ExportImport/Export/testLib1file2.txt b/Tests/ExportImport/Export/testLib1file2.txt
new file mode 100644
index 0000000000..4874ed1091
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib1file2.txt
@@ -0,0 +1 @@
+testLib1file2
diff --git a/Tests/ExportImport/Export/testLib2.c b/Tests/ExportImport/Export/testLib2.c
new file mode 100644
index 0000000000..aabc0d30f0
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib2.c
@@ -0,0 +1,4 @@
+
+extern int testLib1(void);
+
+int testLib2(void) { return testLib1(); }
diff --git a/Tests/ExportImport/Export/testLib3.c b/Tests/ExportImport/Export/testLib3.c
new file mode 100644
index 0000000000..31cec9435c
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib3.c
@@ -0,0 +1,10 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib3_EXPORT __declspec(dllexport)
+# define testLib3Imp_IMPORT __declspec(dllimport)
+#else
+# define testLib3_EXPORT
+# define testLib3Imp_IMPORT
+#endif
+
+testLib3Imp_IMPORT int testLib3Imp(void);
+testLib3_EXPORT int testLib3(void) { return testLib3Imp(); }
diff --git a/Tests/ExportImport/Export/testLib3Imp.c b/Tests/ExportImport/Export/testLib3Imp.c
new file mode 100644
index 0000000000..c27bccd409
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib3Imp.c
@@ -0,0 +1,10 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib3Imp_EXPORT __declspec(dllexport)
+# define testLib3ImpDep_IMPORT __declspec(dllimport)
+#else
+# define testLib3Imp_EXPORT
+# define testLib3ImpDep_IMPORT
+#endif
+
+testLib3ImpDep_IMPORT int testLib3ImpDep(void);
+testLib3Imp_EXPORT int testLib3Imp(void) { return testLib3ImpDep(); }
diff --git a/Tests/ExportImport/Export/testLib3ImpDep.c b/Tests/ExportImport/Export/testLib3ImpDep.c
new file mode 100644
index 0000000000..578ac30ef1
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib3ImpDep.c
@@ -0,0 +1,7 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib3ImpDep_EXPORT __declspec(dllexport)
+#else
+# define testLib3ImpDep_EXPORT
+#endif
+
+testLib3ImpDep_EXPORT int testLib3ImpDep(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testLib4.c b/Tests/ExportImport/Export/testLib4.c
new file mode 100644
index 0000000000..846b4389b4
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4.c
@@ -0,0 +1,7 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib4_EXPORT __declspec(dllexport)
+#else
+# define testLib4_EXPORT
+#endif
+
+testLib4_EXPORT int testLib4(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testLib4.h b/Tests/ExportImport/Export/testLib4.h
new file mode 100644
index 0000000000..9eeda7c0e6
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4.h
@@ -0,0 +1,2 @@
+
+#define TESTLIB4_H
diff --git a/Tests/ExportImport/Export/testLib4lib.c b/Tests/ExportImport/Export/testLib4lib.c
new file mode 100644
index 0000000000..bf3c11ec65
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4lib.c
@@ -0,0 +1,4 @@
+int testLib4lib(void)
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/testLib4libdbg.c b/Tests/ExportImport/Export/testLib4libdbg.c
new file mode 100644
index 0000000000..453f262828
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4libdbg.c
@@ -0,0 +1,14 @@
+#ifdef LIB_DBG
+/* We are building in testLib4libdbg. Provide the correct symbol. */
+int testLib4libdbg(void)
+{
+ return 0;
+}
+#else
+/* We are not building in testLib4libdbg. Poison the symbol. */
+extern int testLib4libdbg_noexist(void);
+int testLib4libdbg(void)
+{
+ return testLib4libdbg_noexist();
+}
+#endif
diff --git a/Tests/ExportImport/Export/testLib4libdbg1.c b/Tests/ExportImport/Export/testLib4libdbg1.c
new file mode 100644
index 0000000000..cc56cf9337
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4libdbg1.c
@@ -0,0 +1 @@
+#include "testLib4libdbg.c"
diff --git a/Tests/ExportImport/Export/testLib4libopt.c b/Tests/ExportImport/Export/testLib4libopt.c
new file mode 100644
index 0000000000..605edd05bf
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4libopt.c
@@ -0,0 +1,14 @@
+#ifdef LIB_OPT
+/* We are building in testLib4libopt. Provide the correct symbol. */
+int testLib4libopt(void)
+{
+ return 0;
+}
+#else
+/* We are not building in testLib4libopt. Poison the symbol. */
+extern int testLib4libopt_noexist(void);
+int testLib4libopt(void)
+{
+ return testLib4libopt_noexist();
+}
+#endif
diff --git a/Tests/ExportImport/Export/testLib4libopt1.c b/Tests/ExportImport/Export/testLib4libopt1.c
new file mode 100644
index 0000000000..d9b55879d3
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4libopt1.c
@@ -0,0 +1 @@
+#include "testLib4libopt.c"
diff --git a/Tests/ExportImport/Export/testLib5.c b/Tests/ExportImport/Export/testLib5.c
new file mode 100644
index 0000000000..20a8215132
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib5.c
@@ -0,0 +1,7 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib5_EXPORT __declspec(dllexport)
+#else
+# define testLib5_EXPORT
+#endif
+
+testLib5_EXPORT int testLib5(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testLib6.cxx b/Tests/ExportImport/Export/testLib6.cxx
new file mode 100644
index 0000000000..338e6399a9
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib6.cxx
@@ -0,0 +1,6 @@
+extern "C" int testLib6cxx(void)
+{
+ // Reference C++ standard library symbols.
+ delete new int;
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/testLib6c.c b/Tests/ExportImport/Export/testLib6c.c
new file mode 100644
index 0000000000..493ca070ee
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib6c.c
@@ -0,0 +1,5 @@
+extern int testLib6cxx(void);
+int testLib6(void)
+{
+ return testLib6cxx();
+}
diff --git a/Tests/ExportImport/Export/testLibCycleA1.c b/Tests/ExportImport/Export/testLibCycleA1.c
new file mode 100644
index 0000000000..3db9e53569
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleA1.c
@@ -0,0 +1,2 @@
+extern int testLibCycleB1(void);
+int testLibCycleA1(void) { return testLibCycleB1(); }
diff --git a/Tests/ExportImport/Export/testLibCycleA2.c b/Tests/ExportImport/Export/testLibCycleA2.c
new file mode 100644
index 0000000000..29ad46d4e9
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleA2.c
@@ -0,0 +1,2 @@
+extern int testLibCycleB2(void);
+int testLibCycleA2(void) { return testLibCycleB2(); }
diff --git a/Tests/ExportImport/Export/testLibCycleA3.c b/Tests/ExportImport/Export/testLibCycleA3.c
new file mode 100644
index 0000000000..565447b213
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleA3.c
@@ -0,0 +1,2 @@
+extern int testLibCycleB3(void);
+int testLibCycleA3(void) { return testLibCycleB3(); }
diff --git a/Tests/ExportImport/Export/testLibCycleB1.c b/Tests/ExportImport/Export/testLibCycleB1.c
new file mode 100644
index 0000000000..36cb7b0e92
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleB1.c
@@ -0,0 +1,2 @@
+extern int testLibCycleA2(void);
+int testLibCycleB1(void) { return testLibCycleA2(); }
diff --git a/Tests/ExportImport/Export/testLibCycleB2.c b/Tests/ExportImport/Export/testLibCycleB2.c
new file mode 100644
index 0000000000..ff1209302c
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleB2.c
@@ -0,0 +1,2 @@
+extern int testLibCycleA3(void);
+int testLibCycleB2(void) { return testLibCycleA3(); }
diff --git a/Tests/ExportImport/Export/testLibCycleB3.c b/Tests/ExportImport/Export/testLibCycleB3.c
new file mode 100644
index 0000000000..ca8d470052
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleB3.c
@@ -0,0 +1 @@
+int testLibCycleB3(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testLibDepends.c b/Tests/ExportImport/Export/testLibDepends.c
new file mode 100644
index 0000000000..fb5a002e06
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibDepends.c
@@ -0,0 +1,20 @@
+
+#include "testLibIncludeRequired1.h"
+#include "testLibIncludeRequired2.h"
+#include "testLibIncludeRequired4.h"
+
+#ifndef testLibRequired_IFACE_DEFINE
+#error Expected testLibRequired_IFACE_DEFINE
+#endif
+
+#ifndef BuildOnly_DEFINE
+#error Expected BuildOnly_DEFINE
+#endif
+
+#ifdef InstallOnly_DEFINE
+#error Unexpected InstallOnly_DEFINE
+#endif
+
+extern int testLibRequired(void);
+
+int testLibDepends(void) { return testLibRequired(); }
diff --git a/Tests/ExportImport/Export/testLibRequired.c b/Tests/ExportImport/Export/testLibRequired.c
new file mode 100644
index 0000000000..e126d44e7d
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibRequired.c
@@ -0,0 +1 @@
+int testLibRequired(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testSharedLibDepends.cpp b/Tests/ExportImport/Export/testSharedLibDepends.cpp
new file mode 100644
index 0000000000..962223faf4
--- /dev/null
+++ b/Tests/ExportImport/Export/testSharedLibDepends.cpp
@@ -0,0 +1,9 @@
+
+#include "testSharedLibDepends.h"
+
+int TestSharedLibDepends::foo()
+{
+ TestSharedLibRequired req;
+ Renamed renamed;
+ return req.foo() + renamed.foo();
+}
diff --git a/Tests/ExportImport/Export/testSharedLibDepends.h b/Tests/ExportImport/Export/testSharedLibDepends.h
new file mode 100644
index 0000000000..8b2f84eb34
--- /dev/null
+++ b/Tests/ExportImport/Export/testSharedLibDepends.h
@@ -0,0 +1,15 @@
+
+#ifndef TESTSHAREDLIBDEPENDS_H
+#define TESTSHAREDLIBDEPENDS_H
+
+#include "testsharedlibdepends_export.h"
+
+#include "testSharedLibRequired.h"
+#include "renamed.h"
+
+struct TESTSHAREDLIBDEPENDS_EXPORT TestSharedLibDepends
+{
+ int foo();
+};
+
+#endif
diff --git a/Tests/ExportImport/Export/testSharedLibRequired.cpp b/Tests/ExportImport/Export/testSharedLibRequired.cpp
new file mode 100644
index 0000000000..1ac34aaef9
--- /dev/null
+++ b/Tests/ExportImport/Export/testSharedLibRequired.cpp
@@ -0,0 +1,7 @@
+
+#include "testSharedLibRequired.h"
+
+int TestSharedLibRequired::foo()
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/testSharedLibRequired.h b/Tests/ExportImport/Export/testSharedLibRequired.h
new file mode 100644
index 0000000000..edaddd4853
--- /dev/null
+++ b/Tests/ExportImport/Export/testSharedLibRequired.h
@@ -0,0 +1,12 @@
+
+#ifndef TESTSHAREDLIBREQUIRED_H
+#define TESTSHAREDLIBREQUIRED_H
+
+#include "testsharedlibrequired_export.h"
+
+struct TESTSHAREDLIBREQUIRED_EXPORT TestSharedLibRequired
+{
+ int foo();
+};
+
+#endif
diff --git a/Tests/ExportImport/Export/testSharedLibRequiredUser.cpp b/Tests/ExportImport/Export/testSharedLibRequiredUser.cpp
new file mode 100644
index 0000000000..5580005176
--- /dev/null
+++ b/Tests/ExportImport/Export/testSharedLibRequiredUser.cpp
@@ -0,0 +1,10 @@
+
+#include "testSharedLibRequiredUser.h"
+
+#include "testSharedLibRequired.h"
+
+int TestSharedLibRequiredUser::foo()
+{
+ TestSharedLibRequired req;
+ return req.foo();
+}
diff --git a/Tests/ExportImport/Export/testSharedLibRequiredUser.h b/Tests/ExportImport/Export/testSharedLibRequiredUser.h
new file mode 100644
index 0000000000..58bcaa5070
--- /dev/null
+++ b/Tests/ExportImport/Export/testSharedLibRequiredUser.h
@@ -0,0 +1,12 @@
+
+#ifndef TESTSHAREDLIBREQUIREDUSER_H
+#define TESTSHAREDLIBREQUIREDUSER_H
+
+#include "testsharedlibrequireduser_export.h"
+
+struct TESTSHAREDLIBREQUIREDUSER_EXPORT TestSharedLibRequiredUser
+{
+ int foo();
+};
+
+#endif
diff --git a/Tests/ExportImport/Export/testSharedLibRequiredUser2.cpp b/Tests/ExportImport/Export/testSharedLibRequiredUser2.cpp
new file mode 100644
index 0000000000..d671bf0651
--- /dev/null
+++ b/Tests/ExportImport/Export/testSharedLibRequiredUser2.cpp
@@ -0,0 +1,8 @@
+
+#include "testSharedLibRequiredUser2.h"
+
+TestSharedLibRequired TestSharedLibRequiredUser2::foo()
+{
+ TestSharedLibRequired req;
+ return req;
+}
diff --git a/Tests/ExportImport/Export/testSharedLibRequiredUser2.h b/Tests/ExportImport/Export/testSharedLibRequiredUser2.h
new file mode 100644
index 0000000000..a132940289
--- /dev/null
+++ b/Tests/ExportImport/Export/testSharedLibRequiredUser2.h
@@ -0,0 +1,14 @@
+
+#ifndef TESTSHAREDLIBREQUIREDUSER2_H
+#define TESTSHAREDLIBREQUIREDUSER2_H
+
+#include "testsharedlibrequireduser2_export.h"
+
+#include "testSharedLibRequired.h"
+
+struct TESTSHAREDLIBREQUIREDUSER2_EXPORT TestSharedLibRequiredUser2
+{
+ TestSharedLibRequired foo();
+};
+
+#endif
diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt
new file mode 100644
index 0000000000..eb0bbf8b44
--- /dev/null
+++ b/Tests/ExportImport/Import/A/CMakeLists.txt
@@ -0,0 +1,320 @@
+# Import targets from the exported build tree.
+include(${Import_BINARY_DIR}/../Export/ExportBuildTree.cmake)
+
+# Import targets from the exported install tree.
+include(${CMAKE_INSTALL_PREFIX}/lib/exp/exp.cmake)
+
+# Import two exports, where the Depends one depends on an exported target from the Required one:
+include(${CMAKE_INSTALL_PREFIX}/lib/cmake/testLibRequired/testLibRequiredTargets.cmake)
+include(${CMAKE_INSTALL_PREFIX}/lib/cmake/testLibDepends/testLibDependsTargets.cmake)
+
+# Try referencing an executable imported from the install tree.
+add_custom_command(
+ OUTPUT ${Import_BINARY_DIR}/exp_generated.c
+ COMMAND exp_testExe1 ${Import_BINARY_DIR}/exp_generated.c
+ DEPENDS exp_testExe1
+ )
+add_custom_command(
+ OUTPUT ${Import_BINARY_DIR}/exp_generated3.c
+ COMMAND exp_testExe3 ${Import_BINARY_DIR}/exp_generated3.c
+ DEPENDS exp_testExe3
+ )
+
+add_executable(imp_testExe1
+ imp_testExe1.c
+ ${Import_BINARY_DIR}/exp_generated.c
+ ${Import_BINARY_DIR}/exp_generated3.c
+ )
+
+# Try linking to a library imported from the install tree.
+target_link_libraries(imp_testExe1
+ exp_testLib2
+ exp_testLib3
+ exp_testLib4
+ exp_testLib5
+ exp_testLib6
+ exp_testLibCycleA
+ )
+
+# Try building a plugin to an executable imported from the install tree.
+add_library(imp_mod1 MODULE imp_mod1.c)
+target_link_libraries(imp_mod1 exp_testExe2)
+
+# Try referencing an executable imported from the build tree.
+add_custom_command(
+ OUTPUT ${Import_BINARY_DIR}/bld_generated.c
+ COMMAND bld_testExe1 ${Import_BINARY_DIR}/bld_generated.c
+ DEPENDS bld_testExe1
+ )
+add_custom_command(
+ OUTPUT ${Import_BINARY_DIR}/bld_generated3.c
+ COMMAND bld_testExe3 ${Import_BINARY_DIR}/bld_generated3.c
+ DEPENDS bld_testExe3
+ )
+
+add_executable(imp_testExe1b
+ imp_testExe1.c
+ ${Import_BINARY_DIR}/bld_generated.c
+ ${Import_BINARY_DIR}/bld_generated3.c
+ )
+
+# Try linking to a library imported from the build tree.
+target_link_libraries(imp_testExe1b
+ bld_testLib2
+ bld_testLib3
+ bld_testLib4
+ bld_testLib5
+ bld_testLib6
+ bld_testLibCycleA
+ )
+
+add_custom_target(check_testLib1_genex ALL
+ COMMAND ${CMAKE_COMMAND} -DtestLib1=$<TARGET_FILE:exp_testLib1>
+ -Dprefix=${CMAKE_INSTALL_PREFIX}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check_testLib1_genex.cmake
+ )
+
+add_executable(cmp0022OLD_test cmp0022OLD_test_vs6_1.cpp)
+target_link_libraries(cmp0022OLD_test bld_cmp0022OLD)
+add_executable(cmp0022NEW_test cmp0022NEW_test_vs6_1.cpp)
+target_link_libraries(cmp0022NEW_test bld_cmp0022NEW)
+
+add_executable(cmp0022OLD_exp_test cmp0022OLD_test_vs6_2.cpp)
+target_link_libraries(cmp0022OLD_exp_test exp_cmp0022OLD)
+add_executable(cmp0022NEW_exp_test cmp0022NEW_test_vs6_2.cpp)
+target_link_libraries(cmp0022NEW_exp_test exp_cmp0022NEW)
+
+# Try building a plugin to an executable imported from the build tree.
+add_library(imp_mod1b MODULE imp_mod1.c)
+target_link_libraries(imp_mod1b bld_testExe2)
+
+# Export/CMakeLists.txt pretends the RelWithDebInfo (as well as Debug)
+# configuration should link to debug libs.
+foreach(c DEBUG RELWITHDEBINFO)
+ set_property(TARGET imp_testExe1 PROPERTY COMPILE_DEFINITIONS_${c} EXE_DBG)
+ set_property(TARGET imp_testExe1b PROPERTY COMPILE_DEFINITIONS_${c} EXE_DBG)
+endforeach()
+
+#-----------------------------------------------------------------------------
+# Create a custom target to generate a header for the libraries below.
+# Drive the header generation through an indirect chain of imported
+# target dependencies.
+
+# testLib2tmp1.h
+add_custom_command(
+ OUTPUT testLib2tmp1.h
+ VERBATIM COMMAND
+ ${CMAKE_COMMAND} -E echo "extern int testLib2(void);" > testLib2tmp1.h
+ )
+
+# hdr_testLib2tmp1 needs testLib2tmp1.h
+add_custom_target(hdr_testLib2tmp1 DEPENDS testLib2tmp1.h)
+
+# exp_testExe2 needs hdr_testLib2tmp1
+add_dependencies(exp_testExe2 hdr_testLib2tmp1)
+
+# testLib2tmp.h needs exp_testExe2
+add_custom_command(
+ OUTPUT testLib2tmp.h
+ VERBATIM COMMAND exp_testExe2
+ COMMAND ${CMAKE_COMMAND} -E copy testLib2tmp1.h testLib2tmp.h
+ )
+
+# hdr_testLib2tmp needs testLib2tmp.h
+add_custom_target(hdr_testLib2tmp DEPENDS testLib2tmp.h)
+
+add_library(dep_testLib2tmp UNKNOWN IMPORTED)
+set_property(TARGET dep_testLib2tmp PROPERTY
+ IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/testLib2tmp.h)
+
+# dep_testLib2tmp needs hdr_testLib2tmp
+add_dependencies(dep_testLib2tmp hdr_testLib2tmp)
+
+# testLib2.h needs dep_testLib2tmp
+add_custom_command(
+ OUTPUT testLib2.h
+ VERBATIM COMMAND ${CMAKE_COMMAND} -E copy testLib2tmp.h testLib2.h
+ DEPENDS dep_testLib2tmp
+ )
+
+# hdr_testLib2 needs testLib2.h
+add_custom_target(hdr_testLib2 DEPENDS testLib2.h)
+
+add_library(dep_testLib2 UNKNOWN IMPORTED)
+
+# dep_testLib2 needs hdr_testLib2
+add_dependencies(dep_testLib2 hdr_testLib2)
+
+# exp_testLib2 and bld_testLib2 both need dep_testLib2
+add_dependencies(bld_testLib2 dep_testLib2)
+add_dependencies(exp_testLib2 dep_testLib2)
+
+#-----------------------------------------------------------------------------
+# Create a library to be linked by another directory in this project
+# to test transitive linking to otherwise invisible imported targets.
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+add_library(imp_lib1 STATIC imp_lib1.c)
+target_link_libraries(imp_lib1 exp_testLib2)
+add_library(imp_lib1b STATIC imp_lib1.c)
+target_link_libraries(imp_lib1b bld_testLib2)
+
+#-----------------------------------------------------------------------------
+# Test that handling imported targets, including transitive dependencies,
+# works in CheckFunctionExists (...and hopefully all other try_compile() checks
+include(CheckFunctionExists)
+unset(HAVE_TESTLIB1_FUNCTION CACHE)
+set(CMAKE_REQUIRED_LIBRARIES exp_testLib2)
+check_function_exists(testLib1 HAVE_TESTLIB1_FUNCTION)
+if (NOT HAVE_TESTLIB1_FUNCTION)
+ message(SEND_ERROR "Using imported target testLib2 in check_function_exists() failed !")
+endif()
+
+#-----------------------------------------------------------------------------
+# Test that dependent imported targets have usable
+# INTERFACE_COMPILE_DEFINITIONS and INTERFACE_INCLUDE_DIRECTORIES
+
+add_executable(deps_iface deps_iface.c)
+target_link_libraries(deps_iface testLibDepends)
+
+add_executable(deps_shared_iface deps_shared_iface.cpp)
+target_link_libraries(deps_shared_iface testSharedLibDepends)
+target_compile_definitions(deps_shared_iface
+ PRIVATE
+ $<$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>:PIC_PROPERTY_IS_ON>
+ $<$<BOOL:$<TARGET_PROPERTY:CUSTOM_PROP>>:CUSTOM_PROPERTY_IS_ON>
+ $<$<STREQUAL:$<TARGET_PROPERTY:CUSTOM_STRING>,testcontent>:CUSTOM_STRING_IS_MATCH>
+)
+
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ target_compile_definitions(deps_shared_iface
+ PRIVATE
+ "DO_GNU_TESTS"
+ )
+endif()
+
+if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ include(CheckCXXCompilerFlag)
+ check_cxx_compiler_flag(-fPIE run_pic_test)
+else()
+ if (CMAKE_CXX_COMPILER_ID MATCHES "PGI"
+ OR CMAKE_CXX_COMPILER_ID MATCHES "PathScale"
+ OR CMAKE_SYSTEM_NAME MATCHES "IRIX64"
+ OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
+ set(run_pic_test 0)
+ else()
+ set(run_pic_test 1)
+ endif()
+endif()
+
+add_executable(exp_renamed_test renamed_test.cpp)
+target_link_libraries(exp_renamed_test exp_renamed)
+
+add_executable(bld_renamed_test renamed_test.cpp)
+target_link_libraries(bld_renamed_test bld_renamed)
+
+if (run_pic_test)
+ target_compile_definitions(deps_shared_iface PRIVATE CHECK_PIC_WORKS)
+endif()
+
+if(APPLE)
+ add_subdirectory(framework_interface)
+endif()
+
+#-----------------------------------------------------------------------------
+# Test that targets imported from the build tree have their dependencies
+# evaluated correctly. The above already tests the same for the install tree.
+
+add_executable(deps_shared_iface2 deps_shared_iface.cpp)
+target_link_libraries(deps_shared_iface2 bld_testSharedLibDepends bld_subdirlib)
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ target_compile_definitions(deps_shared_iface2
+ PRIVATE
+ "DO_GNU_TESTS"
+ )
+endif()
+target_compile_definitions(deps_shared_iface2
+ PRIVATE TEST_SUBDIR_LIB
+ $<$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>:PIC_PROPERTY_IS_ON>
+ $<$<BOOL:$<TARGET_PROPERTY:CUSTOM_PROP>>:CUSTOM_PROPERTY_IS_ON>
+ $<$<STREQUAL:$<TARGET_PROPERTY:CUSTOM_STRING>,testcontent>:CUSTOM_STRING_IS_MATCH>
+)
+
+add_subdirectory(excludedFromAll)
+
+add_executable(iface_test_bld iface_test.cpp)
+target_link_libraries(iface_test_bld bld_testSharedLibDepends)
+
+set_property(TARGET bld_testSharedLibRequired APPEND PROPERTY
+ LINK_INTERFACE_LIBRARIES
+ excludedFromAll
+)
+get_target_property(_configs bld_testSharedLibRequired IMPORTED_CONFIGURATIONS)
+foreach(_config ${_configs})
+ set_property(TARGET bld_testSharedLibRequired APPEND PROPERTY
+ IMPORTED_LINK_INTERFACE_LIBRARIES_${_config}
+ excludedFromAll
+ )
+endforeach()
+unset(_configs)
+add_executable(iface_test_exp iface_test.cpp)
+target_link_libraries(iface_test_exp testSharedLibDepends)
+
+set_property(TARGET testSharedLibDepends APPEND PROPERTY
+ LINK_INTERFACE_LIBRARIES
+ excludedFromAll
+)
+get_target_property(_configs testSharedLibDepends IMPORTED_CONFIGURATIONS)
+foreach(_config ${_configs})
+ set_property(TARGET testSharedLibDepends APPEND PROPERTY
+ IMPORTED_LINK_INTERFACE_LIBRARIES_${_config}
+ excludedFromAll
+ )
+endforeach()
+unset(_configs)
+
+if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4)
+ OR CMAKE_C_COMPILER_ID STREQUAL Clang)
+ AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja"))
+ include(CheckCXXCompilerFlag)
+ check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test)
+ if(run_sys_includes_test)
+ # The Bullseye wrapper appears to break the -isystem effect.
+ execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE out ERROR_VARIABLE out)
+ if("x${out}" MATCHES "Bullseye")
+ set(run_sys_includes_test 0)
+ endif()
+ endif()
+ if (run_sys_includes_test)
+ add_executable(test_system_exp test_system.cpp)
+ target_link_libraries(test_system_exp exp_systemlib)
+ target_compile_options(test_system_exp PRIVATE -Wunused-variable -Werror=unused-variable)
+
+ unset(EXP_ERROR_VARIABLE CACHE)
+ try_compile(EXP_ERROR_VARIABLE
+ "${CMAKE_CURRENT_SOURCE_DIR}/test_system"
+ "${CMAKE_CURRENT_SOURCE_DIR}/test_system.cpp"
+ COMPILE_DEFINITIONS "-Wunused-variable -Werror=unused-variable"
+ LINK_LIBRARIES exp_systemlib
+ OUTPUT_VARIABLE OUTPUT
+ )
+ if(NOT EXP_ERROR_VARIABLE)
+ message(SEND_ERROR "EXP_ERROR_VARIABLE try_compile failed, but it was expected to succeed ${OUTPUT}.")
+ endif()
+
+ add_executable(test_system_bld test_system.cpp)
+ target_link_libraries(test_system_bld bld_systemlib)
+ target_compile_options(test_system_bld PRIVATE -Wunused-variable -Werror=unused-variable)
+
+ unset(BLD_ERROR_VARIABLE CACHE)
+ try_compile(BLD_ERROR_VARIABLE
+ "${CMAKE_CURRENT_SOURCE_DIR}/test_system"
+ "${CMAKE_CURRENT_SOURCE_DIR}/test_system.cpp"
+ COMPILE_DEFINITIONS "-Wunused-variable -Werror=unused-variable"
+ LINK_LIBRARIES bld_systemlib
+ OUTPUT_VARIABLE OUTPUT
+ )
+ if(NOT BLD_ERROR_VARIABLE)
+ message(SEND_ERROR "BLD_ERROR_VARIABLE try_compile failed, but it was expected to succeed.")
+ endif()
+ endif()
+endif()
diff --git a/Tests/ExportImport/Import/A/check_testLib1_genex.cmake b/Tests/ExportImport/Import/A/check_testLib1_genex.cmake
new file mode 100644
index 0000000000..7c0265248b
--- /dev/null
+++ b/Tests/ExportImport/Import/A/check_testLib1_genex.cmake
@@ -0,0 +1,11 @@
+foreach(f
+ "${testLib1}.genex"
+ "${prefix}/doc/testLib1file1.txt"
+ "${prefix}/doc/testLib1file2.txt"
+ )
+ if(EXISTS "${f}")
+ message(STATUS "'${f}' exists!")
+ else()
+ message(FATAL_ERROR "Missing file:\n ${f}")
+ endif()
+endforeach()
diff --git a/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp b/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp
new file mode 100644
index 0000000000..587834987d
--- /dev/null
+++ b/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp
@@ -0,0 +1,12 @@
+
+#ifndef USING_TESTLIB2
+#error Expected USING_TESTLIB2
+#endif
+#ifdef USING_TESTLIB3
+#error Unexpected USING_TESTLIB3
+#endif
+
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Import/A/cmp0022NEW_test_vs6_1.cpp b/Tests/ExportImport/Import/A/cmp0022NEW_test_vs6_1.cpp
new file mode 100644
index 0000000000..033b7463f3
--- /dev/null
+++ b/Tests/ExportImport/Import/A/cmp0022NEW_test_vs6_1.cpp
@@ -0,0 +1 @@
+#include "cmp0022NEW_test.cpp"
diff --git a/Tests/ExportImport/Import/A/cmp0022NEW_test_vs6_2.cpp b/Tests/ExportImport/Import/A/cmp0022NEW_test_vs6_2.cpp
new file mode 100644
index 0000000000..033b7463f3
--- /dev/null
+++ b/Tests/ExportImport/Import/A/cmp0022NEW_test_vs6_2.cpp
@@ -0,0 +1 @@
+#include "cmp0022NEW_test.cpp"
diff --git a/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp b/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp
new file mode 100644
index 0000000000..e50158b76f
--- /dev/null
+++ b/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp
@@ -0,0 +1,12 @@
+
+#ifdef USING_TESTLIB2
+#error Unexpected USING_TESTLIB2
+#endif
+#ifndef USING_TESTLIB3
+#error Expected USING_TESTLIB3
+#endif
+
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Import/A/cmp0022OLD_test_vs6_1.cpp b/Tests/ExportImport/Import/A/cmp0022OLD_test_vs6_1.cpp
new file mode 100644
index 0000000000..90d804ce79
--- /dev/null
+++ b/Tests/ExportImport/Import/A/cmp0022OLD_test_vs6_1.cpp
@@ -0,0 +1 @@
+#include "cmp0022OLD_test.cpp"
diff --git a/Tests/ExportImport/Import/A/cmp0022OLD_test_vs6_2.cpp b/Tests/ExportImport/Import/A/cmp0022OLD_test_vs6_2.cpp
new file mode 100644
index 0000000000..90d804ce79
--- /dev/null
+++ b/Tests/ExportImport/Import/A/cmp0022OLD_test_vs6_2.cpp
@@ -0,0 +1 @@
+#include "cmp0022OLD_test.cpp"
diff --git a/Tests/ExportImport/Import/A/deps_iface.c b/Tests/ExportImport/Import/A/deps_iface.c
new file mode 100644
index 0000000000..953d0ad85d
--- /dev/null
+++ b/Tests/ExportImport/Import/A/deps_iface.c
@@ -0,0 +1,34 @@
+
+#include "testLibIncludeRequired1.h"
+#include "testLibIncludeRequired2.h"
+#include "testLibIncludeRequired6.h"
+#include "testLibIncludeRequired7.h"
+
+#include "installIncludesTest.h"
+#include "installIncludesTest2.h"
+#include "installIncludesTest3.h"
+#include "installIncludesTest4.h"
+#include "installIncludesTest5.h"
+#include "installIncludesTest6.h"
+#include "installIncludesTest7.h"
+#include "installIncludesTest8.h"
+
+#ifndef testLibRequired_IFACE_DEFINE
+#error Expected testLibRequired_IFACE_DEFINE
+#endif
+
+#ifdef BuildOnly_DEFINE
+#error Unexpected BuildOnly_DEFINE
+#endif
+
+#ifndef InstallOnly_DEFINE
+#error Expected InstallOnly_DEFINE
+#endif
+
+extern int testLibDepends(void);
+
+
+int main()
+{
+ return testLibDepends();
+}
diff --git a/Tests/ExportImport/Import/A/deps_shared_iface.cpp b/Tests/ExportImport/Import/A/deps_shared_iface.cpp
new file mode 100644
index 0000000000..d5e4de3c0a
--- /dev/null
+++ b/Tests/ExportImport/Import/A/deps_shared_iface.cpp
@@ -0,0 +1,49 @@
+
+
+#include "testSharedLibDepends.h"
+
+#ifdef CHECK_PIC_WORKS
+#if defined(__ELF__) && !defined(__PIC__) && !defined(__PIE__)
+#error Expected by INTERFACE_POSITION_INDEPENDENT_CODE property of dependency
+#endif
+#endif
+
+#ifndef PIC_PROPERTY_IS_ON
+#error Expected PIC_PROPERTY_IS_ON
+#endif
+
+#ifndef CUSTOM_PROPERTY_IS_ON
+#error Expected CUSTOM_PROPERTY_IS_ON
+#endif
+
+#ifndef CUSTOM_STRING_IS_MATCH
+#error Expected CUSTOM_STRING_IS_MATCH
+#endif
+
+#ifdef TEST_SUBDIR_LIB
+#include "subdir.h"
+#include "renamed.h"
+#endif
+
+#ifdef DO_GNU_TESTS
+#ifndef CUSTOM_COMPILE_OPTION
+#error Expected CUSTOM_COMPILE_OPTION
+#endif
+#endif
+
+int main(int,char **)
+{
+ TestSharedLibDepends dep;
+ TestSharedLibRequired req;
+
+#ifdef TEST_SUBDIR_LIB
+ SubDirObject sdo;
+ Renamed ren;
+#endif
+
+ return dep.foo() + req.foo()
+#ifdef TEST_SUBDIR_LIB
+ + sdo.foo() + ren.foo()
+#endif
+ ;
+}
diff --git a/Tests/ExportImport/Import/A/excludedFromAll/CMakeLists.txt b/Tests/ExportImport/Import/A/excludedFromAll/CMakeLists.txt
new file mode 100644
index 0000000000..cd5a59bfe2
--- /dev/null
+++ b/Tests/ExportImport/Import/A/excludedFromAll/CMakeLists.txt
@@ -0,0 +1,7 @@
+
+set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+include(GenerateExportHeader)
+add_library(excludedFromAll SHARED EXCLUDE_FROM_ALL excludedFromAll.cpp)
+generate_export_header(excludedFromAll)
diff --git a/Tests/ExportImport/Import/A/excludedFromAll/excludedFromAll.cpp b/Tests/ExportImport/Import/A/excludedFromAll/excludedFromAll.cpp
new file mode 100644
index 0000000000..2269a0402a
--- /dev/null
+++ b/Tests/ExportImport/Import/A/excludedFromAll/excludedFromAll.cpp
@@ -0,0 +1,7 @@
+
+#include "excludedFromAll.h"
+
+int excludedFromAll()
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Import/A/excludedFromAll/excludedFromAll.h b/Tests/ExportImport/Import/A/excludedFromAll/excludedFromAll.h
new file mode 100644
index 0000000000..4820c76c18
--- /dev/null
+++ b/Tests/ExportImport/Import/A/excludedFromAll/excludedFromAll.h
@@ -0,0 +1,4 @@
+
+#include "excludedfromall_export.h"
+
+int EXCLUDEDFROMALL_EXPORT excludedFromAll();
diff --git a/Tests/ExportImport/Import/A/framework_interface/CMakeLists.txt b/Tests/ExportImport/Import/A/framework_interface/CMakeLists.txt
new file mode 100644
index 0000000000..0e00655557
--- /dev/null
+++ b/Tests/ExportImport/Import/A/framework_interface/CMakeLists.txt
@@ -0,0 +1,9 @@
+
+add_library(exp_framework_test framework_test.cpp)
+get_target_property(exp_loc exp_testLib4 LOCATION)
+target_link_libraries(exp_framework_test ${exp_loc})
+
+
+add_library(bld_framework_test framework_test.cpp)
+get_target_property(bld_loc bld_testLib4 LOCATION)
+target_link_libraries(bld_framework_test ${bld_loc})
diff --git a/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp b/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp
new file mode 100644
index 0000000000..357f64f02a
--- /dev/null
+++ b/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp
@@ -0,0 +1,6 @@
+
+#include <testLib4/testLib4.h>
+
+#ifndef TESTLIB4_H
+#error Expected define TESTLIB4_H
+#endif
diff --git a/Tests/ExportImport/Import/A/iface_test.cpp b/Tests/ExportImport/Import/A/iface_test.cpp
new file mode 100644
index 0000000000..fa4474bdbe
--- /dev/null
+++ b/Tests/ExportImport/Import/A/iface_test.cpp
@@ -0,0 +1,11 @@
+
+#ifndef USING_TESTSHAREDLIBREQUIRED
+#error Expected USING_TESTSHAREDLIBREQUIRED
+#endif
+
+#include "excludedFromAll.h"
+
+int main(void)
+{
+ return excludedFromAll();
+}
diff --git a/Tests/ExportImport/Import/A/imp_lib1.c b/Tests/ExportImport/Import/A/imp_lib1.c
new file mode 100644
index 0000000000..5b3215e991
--- /dev/null
+++ b/Tests/ExportImport/Import/A/imp_lib1.c
@@ -0,0 +1,6 @@
+#include "testLib2.h"
+
+int imp_lib1(void)
+{
+ return testLib2();
+}
diff --git a/Tests/ExportImport/Import/A/imp_mod1.c b/Tests/ExportImport/Import/A/imp_mod1.c
new file mode 100644
index 0000000000..579d949c3f
--- /dev/null
+++ b/Tests/ExportImport/Import/A/imp_mod1.c
@@ -0,0 +1,13 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testExe2_IMPORT __declspec(dllimport)
+#else
+# define testExe2_IMPORT
+#endif
+
+testExe2_IMPORT int testExe2Func(void);
+testExe2_IMPORT int testExe2lib(void);
+
+int imp_mod1()
+{
+ return testExe2Func() + testExe2lib();
+}
diff --git a/Tests/ExportImport/Import/A/imp_testExe1.c b/Tests/ExportImport/Import/A/imp_testExe1.c
new file mode 100644
index 0000000000..451998ab77
--- /dev/null
+++ b/Tests/ExportImport/Import/A/imp_testExe1.c
@@ -0,0 +1,25 @@
+extern int generated_by_testExe1();
+extern int generated_by_testExe3();
+extern int testLib2();
+extern int testLib3();
+extern int testLib4();
+extern int testLib4lib();
+extern int testLib5();
+extern int testLib6();
+extern int testLibCycleA1();
+
+/* Switch a symbol between debug and optimized builds to make sure the
+ proper library is found from the testLib4 link interface. */
+#ifdef EXE_DBG
+# define testLib4libcfg testLib4libdbg
+#else
+# define testLib4libcfg testLib4libopt
+#endif
+extern testLib4libcfg(void);
+
+int main()
+{
+ return (testLib2() + generated_by_testExe1() + testLib3() + testLib4()
+ + testLib5() + testLib6() + testLibCycleA1()
+ + generated_by_testExe3() + testLib4lib() + testLib4libcfg());
+}
diff --git a/Tests/ExportImport/Import/A/renamed_test.cpp b/Tests/ExportImport/Import/A/renamed_test.cpp
new file mode 100644
index 0000000000..e2ee126aa9
--- /dev/null
+++ b/Tests/ExportImport/Import/A/renamed_test.cpp
@@ -0,0 +1,8 @@
+
+#include "renamed.h"
+
+int main(int, char **)
+{
+ Renamed ren;
+ return ren.foo();
+}
diff --git a/Tests/ExportImport/Import/A/test_system.cpp b/Tests/ExportImport/Import/A/test_system.cpp
new file mode 100644
index 0000000000..aae358333a
--- /dev/null
+++ b/Tests/ExportImport/Import/A/test_system.cpp
@@ -0,0 +1,9 @@
+
+#include "systemlib.h"
+
+int main()
+{
+ SystemStruct s;
+ (void)s;
+ return 0;
+}
diff --git a/Tests/ExportImport/Import/CMakeLists.txt b/Tests/ExportImport/Import/CMakeLists.txt
new file mode 100644
index 0000000000..189f7a2bc5
--- /dev/null
+++ b/Tests/ExportImport/Import/CMakeLists.txt
@@ -0,0 +1,25 @@
+cmake_minimum_required (VERSION 2.7.20090711)
+cmake_policy(SET CMP0025 NEW)
+project(Import C CXX)
+
+# Import everything in a subdirectory.
+add_subdirectory(A)
+
+# Make sure the imported targets are scoped inside the subdirectory.
+if(TARGET exp_testLib2)
+ message(FATAL_ERROR "Imported target exp_testLib2 is not scoped in subdir!")
+endif()
+if(TARGET bld_testLib2)
+ message(FATAL_ERROR "Imported target bld_testLib2 is not scoped in subdir!")
+endif()
+
+# Test transitive linking to a target imported in the subdirectory.
+add_executable(imp_testTransExe1 imp_testTransExe1.c)
+target_link_libraries(imp_testTransExe1 imp_lib1)
+add_executable(imp_testTransExe1b imp_testTransExe1.c)
+target_link_libraries(imp_testTransExe1b imp_lib1b)
+
+add_subdirectory(try_compile)
+
+# Test package INTERFACE controls
+add_subdirectory(Interface)
diff --git a/Tests/ExportImport/Import/Interface/CMakeLists.txt b/Tests/ExportImport/Import/Interface/CMakeLists.txt
new file mode 100644
index 0000000000..4028405ae2
--- /dev/null
+++ b/Tests/ExportImport/Import/Interface/CMakeLists.txt
@@ -0,0 +1,93 @@
+
+# Import targets from the exported build tree.
+include(${Import_BINARY_DIR}/../Export/ExportInterfaceBuildTree.cmake)
+
+# Import targets from the exported install tree.
+include(${CMAKE_INSTALL_PREFIX}/lib/exp/expInterface.cmake)
+
+add_library(define_iface INTERFACE)
+set_property(TARGET define_iface PROPERTY
+ INTERFACE_COMPILE_DEFINITIONS DEFINE_IFACE_DEFINE)
+
+add_executable(headeronlytest_bld headeronlytest.cpp)
+target_link_libraries(headeronlytest_bld bld::headeronly)
+
+set_property(TARGET bld::sharediface APPEND PROPERTY INTERFACE_LINK_LIBRARIES define_iface)
+
+add_executable(interfacetest_bld interfacetest.cpp)
+target_link_libraries(interfacetest_bld bld::sharediface)
+
+include(CheckCSourceCompiles)
+include(CheckCXXSourceCompiles)
+
+macro(do_try_compile prefix)
+
+ set(CMAKE_REQUIRED_LIBRARIES ${prefix}::headeronly)
+ check_cxx_source_compiles(
+ "
+ #include \"headeronly.h\"
+
+ #ifndef HEADERONLY_DEFINE
+ #error Expected HEADERONLY_DEFINE
+ #endif
+
+ int main(int,char**)
+ {
+ HeaderOnly ho;
+ return ho.foo();
+ }
+ " ${prefix}IFACE_TRY_COMPILE)
+
+ if(NOT ${prefix}IFACE_TRY_COMPILE)
+ message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}")
+ endif()
+
+ if (";${CMAKE_C_COMPILE_FEATURES};" MATCHES ";c_restrict;")
+ set(CMAKE_REQUIRED_LIBRARIES ${prefix}::use_c_restrict)
+ check_c_source_compiles(
+ "
+ int foo(int * restrict a, int * restrict b)
+ {
+ (void)a;
+ (void)b;
+ return 0;
+ }
+ int main()
+ {
+ return 0;
+ }
+ " ${prefix}IMPORTED_IFACE_C_RESTRICT)
+
+ if(NOT ${prefix}IMPORTED_IFACE_C_RESTRICT)
+ message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}")
+ endif()
+ endif()
+ if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_auto_type;")
+ set(CMAKE_REQUIRED_LIBRARIES ${prefix}::use_auto_type)
+ check_cxx_source_compiles(
+ "
+ int main(int,char**)
+ {
+ auto value = 0;
+ return value;
+ }
+ " ${prefix}IMPORTED_IFACE_AUTO_TYPE)
+
+ if(NOT ${prefix}IMPORTED_IFACE_AUTO_TYPE)
+ message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}")
+ endif()
+ endif()
+
+endmacro()
+
+do_try_compile(bld)
+
+add_executable(headeronlytest_exp headeronlytest.cpp)
+target_link_libraries(headeronlytest_exp exp::headeronly)
+
+set_property(TARGET exp::sharediface APPEND PROPERTY INTERFACE_LINK_LIBRARIES define_iface)
+
+add_executable(interfacetest_exp interfacetest.cpp)
+target_link_libraries(interfacetest_exp exp::sharediface)
+
+do_try_compile(exp)
diff --git a/Tests/ExportImport/Import/Interface/headeronlytest.cpp b/Tests/ExportImport/Import/Interface/headeronlytest.cpp
new file mode 100644
index 0000000000..20674a7253
--- /dev/null
+++ b/Tests/ExportImport/Import/Interface/headeronlytest.cpp
@@ -0,0 +1,17 @@
+
+#include "headeronly.h"
+
+#ifndef HEADERONLY_DEFINE
+#error Expected HEADERONLY_DEFINE
+#endif
+
+#ifdef SHAREDLIB_DEFINE
+#error Unexpected SHAREDLIB_DEFINE
+#endif
+
+
+int main(int,char**)
+{
+ HeaderOnly ho;
+ return ho.foo();
+}
diff --git a/Tests/ExportImport/Import/Interface/interfacetest.cpp b/Tests/ExportImport/Import/Interface/interfacetest.cpp
new file mode 100644
index 0000000000..786458d19b
--- /dev/null
+++ b/Tests/ExportImport/Import/Interface/interfacetest.cpp
@@ -0,0 +1,20 @@
+
+#include "sharedlib.h"
+
+#ifndef SHAREDLIB_DEFINE
+#error Expected SHAREDLIB_DEFINE
+#endif
+
+#ifdef HEADERONLY_DEFINE
+#error Unexpected HEADERONLY_DEFINE
+#endif
+
+#ifndef DEFINE_IFACE_DEFINE
+#error Expected DEFINE_IFACE_DEFINE
+#endif
+
+int main(int,char**)
+{
+ SharedLibObject slo;
+ return slo.foo();
+}
diff --git a/Tests/ExportImport/Import/imp_testTransExe1.c b/Tests/ExportImport/Import/imp_testTransExe1.c
new file mode 100644
index 0000000000..360a112ac3
--- /dev/null
+++ b/Tests/ExportImport/Import/imp_testTransExe1.c
@@ -0,0 +1,6 @@
+extern int imp_lib1(void);
+
+int main()
+{
+ return imp_lib1();
+}
diff --git a/Tests/ExportImport/Import/try_compile/CMakeLists.txt b/Tests/ExportImport/Import/try_compile/CMakeLists.txt
new file mode 100644
index 0000000000..10884616ba
--- /dev/null
+++ b/Tests/ExportImport/Import/try_compile/CMakeLists.txt
@@ -0,0 +1,36 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+find_package(testLibRequired 2.5 REQUIRED)
+
+include(CheckCXXSourceCompiles)
+
+set(CMAKE_REQUIRED_LIBRARIES Req::testSharedLibRequiredUser)
+check_cxx_source_compiles(
+ "
+#include \"testSharedLibRequiredUser.h\"
+int main(int argc, char **argv)
+{
+ TestSharedLibRequiredUser user;
+ return user.foo();
+}
+" SHARED_LIB_DEPENDS)
+
+if(NOT SHARED_LIB_DEPENDS)
+ message(SEND_ERROR "try_compile with IMPORTED targets failed!\n\n${OUTPUT}")
+endif()
+
+set(CMAKE_REQUIRED_LIBRARIES Req::testSharedLibRequiredUser2)
+check_cxx_source_compiles(
+ "
+#include \"testSharedLibRequiredUser2.h\"
+int main(int argc, char **argv)
+{
+ TestSharedLibRequiredUser2 user;
+ return user.foo().foo();
+}
+" SHARED_LIB_DEPENDS2)
+
+if(NOT SHARED_LIB_DEPENDS2)
+ message(SEND_ERROR "try_compile with IMPORTED targets failed!\n\n${OUTPUT}")
+endif()
diff --git a/Tests/ExportImport/InitialCache.cmake.in b/Tests/ExportImport/InitialCache.cmake.in
new file mode 100644
index 0000000000..f600d90e7e
--- /dev/null
+++ b/Tests/ExportImport/InitialCache.cmake.in
@@ -0,0 +1,16 @@
+set(CMAKE_MAKE_PROGRAM "@CMake_TEST_NESTED_MAKE_PROGRAM@" CACHE FILEPATH "Make Program")
+set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@" CACHE STRING "C Compiler")
+set(CMAKE_C_FLAGS "@CMAKE_C_FLAGS@" CACHE STRING "C Flags")
+set(CMAKE_C_FLAGS_DEBUG "@CMAKE_C_FLAGS_DEBUG@" CACHE STRING "C Flags")
+set(CMAKE_C_FLAGS_RELEASE "@CMAKE_C_FLAGS_RELEASE@" CACHE STRING "C Flags")
+set(CMAKE_C_FLAGS_MINSIZEREL "@CMAKE_C_FLAGS_MINSIZEREL@" CACHE STRING "C Flags")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "@CMAKE_C_FLAGS_RELWITHDEBINFO@" CACHE STRING "C Flags")
+set(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@" CACHE STRING "C++ Compiler")
+set(CMAKE_CXX_FLAGS "@CMAKE_CXX_FLAGS@" CACHE STRING "C++ Flags")
+set(CMAKE_CXX_FLAGS_DEBUG "@CMAKE_CXX_FLAGS_DEBUG@" CACHE STRING "C++ Flags")
+set(CMAKE_CXX_FLAGS_RELEASE "@CMAKE_CXX_FLAGS_RELEASE@" CACHE STRING "C++ Flags")
+set(CMAKE_CXX_FLAGS_MINSIZEREL "@CMAKE_CXX_FLAGS_MINSIZEREL@" CACHE STRING "C++ Flags")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "@CMAKE_CXX_FLAGS_RELWITHDEBINFO@" CACHE STRING "C++ Flags")
+set(CMAKE_INSTALL_PREFIX "@ExportImport_BINARY_DIR@/Root" CACHE STRING "Installation Prefix")
+set(CMAKE_SKIP_RPATH ON CACHE BOOL "No RPATH")
+set(CMAKE_GNUtoMS "@ExportImport_GNUtoMS@" CACHE BOOL "CMAKE_GNUtoMS")
diff --git a/Tests/ExportImport/main.c b/Tests/ExportImport/main.c
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/ExportImport/main.c
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/ExternalOBJ/CMakeLists.txt b/Tests/ExternalOBJ/CMakeLists.txt
new file mode 100644
index 0000000000..458c88bfd3
--- /dev/null
+++ b/Tests/ExternalOBJ/CMakeLists.txt
@@ -0,0 +1,63 @@
+cmake_minimum_required (VERSION 2.6)
+project (ExternalOBJ)
+
+if(APPLE)
+ # set _CMAKE_OSX_MACHINE to umame -m
+ exec_program(uname ARGS -m OUTPUT_VARIABLE _CMAKE_OSX_MACHINE)
+ # check for Power PC and change to ppc
+ if("${_CMAKE_OSX_MACHINE}" MATCHES "Power")
+ set(_CMAKE_OSX_MACHINE ppc)
+ endif()
+ set(CMAKE_OSX_ARCHITECTURES ${_CMAKE_OSX_MACHINE})
+endif()
+
+# Build the external object file.
+try_compile(EXTERNAL_OBJECT_BUILT
+ ${ExternalOBJ_BINARY_DIR}/Object
+ ${ExternalOBJ_SOURCE_DIR}/Object
+ Object
+ external
+ OUTPUT_VARIABLE OUTPUT
+ )
+if(EXTERNAL_OBJECT_BUILT)
+ message(
+ "Building external_object.cxx succeeded with the following output:\n"
+ "[${OUTPUT}]"
+ )
+else()
+ message(FATAL_ERROR
+ "Building external_object.cxx failed with the following output:\n"
+ "[${OUTPUT}]"
+ )
+endif()
+
+# Find the external object file.
+set(DIR ${ExternalOBJ_BINARY_DIR}/Object)
+file(GLOB_RECURSE EXTERNAL_OBJECT
+ "${DIR}/external_object*${CMAKE_CXX_OUTPUT_EXTENSION}")
+if(EXTERNAL_OBJECT)
+ list (GET EXTERNAL_OBJECT 0 EXTERNAL_OBJECT)
+ message("Found \"${EXTERNAL_OBJECT}\".")
+else()
+ message(FATAL_ERROR "Could not find external object.")
+endif()
+
+# Test creation of external objects by custom commands.
+set(CUSTOM_OBJECT
+ ${CMAKE_CURRENT_BINARY_DIR}/custom_object${CMAKE_C_OUTPUT_EXTENSION})
+add_custom_command(
+ OUTPUT ${CUSTOM_OBJECT}
+ COMMAND ${CMAKE_COMMAND} -E copy ${EXTERNAL_OBJECT} ${CUSTOM_OBJECT}
+ DEPENDS ${EXTERNAL_OBJECT}
+ )
+
+message("${EXTERNAL_OBJECT}")
+# Build an executable using the external object file.
+add_executable(ExternalOBJ executable.cxx ${CUSTOM_OBJECT})
+# A bug showed up in VS2010 where an object file that was
+# part of a custom commad output worked, but ones that were
+# not didn't work. So, repeat the executable using the object
+# directly and not from the output of the copy.
+add_executable(ExternalOBJ2 executable.cxx ${EXTERNAL_OBJECT})
+
+add_subdirectory(Sub)
diff --git a/Tests/ExternalOBJ/Object/CMakeLists.txt b/Tests/ExternalOBJ/Object/CMakeLists.txt
new file mode 100644
index 0000000000..dbfe09ee69
--- /dev/null
+++ b/Tests/ExternalOBJ/Object/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required (VERSION 2.6)
+project(Object)
+if(APPLE)
+ # set _CMAKE_OSX_MACHINE to umame -m
+ exec_program(uname ARGS -m OUTPUT_VARIABLE _CMAKE_OSX_MACHINE)
+ # check for Power PC and change to ppc
+ if("${_CMAKE_OSX_MACHINE}" MATCHES "Power")
+ set(_CMAKE_OSX_MACHINE ppc)
+ endif()
+ set(CMAKE_OSX_ARCHITECTURES ${_CMAKE_OSX_MACHINE})
+endif()
+
+add_executable(external external_object.cxx external_main.cxx)
diff --git a/Tests/ExternalOBJ/Object/external_main.cxx b/Tests/ExternalOBJ/Object/external_main.cxx
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/ExternalOBJ/Object/external_main.cxx
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/ExternalOBJ/Object/external_object.cxx b/Tests/ExternalOBJ/Object/external_object.cxx
new file mode 100644
index 0000000000..5b4adaf0c5
--- /dev/null
+++ b/Tests/ExternalOBJ/Object/external_object.cxx
@@ -0,0 +1,4 @@
+int external_object_function()
+{
+ return 0;
+}
diff --git a/Tests/ExternalOBJ/Sub/CMakeLists.txt b/Tests/ExternalOBJ/Sub/CMakeLists.txt
new file mode 100644
index 0000000000..35cd30c7d7
--- /dev/null
+++ b/Tests/ExternalOBJ/Sub/CMakeLists.txt
@@ -0,0 +1,3 @@
+set_property(SOURCE ${CUSTOM_OBJECT} PROPERTY GENERATED 1)
+add_executable(ExternalOBJSub ../executable.cxx ${CUSTOM_OBJECT})
+add_dependencies(ExternalOBJSub ExternalOBJ) # depend on generating target
diff --git a/Tests/ExternalOBJ/executable.cxx b/Tests/ExternalOBJ/executable.cxx
new file mode 100644
index 0000000000..f9ec61df53
--- /dev/null
+++ b/Tests/ExternalOBJ/executable.cxx
@@ -0,0 +1,5 @@
+extern int external_object_function();
+int main()
+{
+ return external_object_function();
+}
diff --git a/Tests/ExternalProject/CMakeLists.txt b/Tests/ExternalProject/CMakeLists.txt
new file mode 100644
index 0000000000..2f74121ff2
--- /dev/null
+++ b/Tests/ExternalProject/CMakeLists.txt
@@ -0,0 +1,487 @@
+cmake_minimum_required(VERSION 2.8)
+project(ExternalProjectTest NONE)
+
+include(ExternalProject)
+
+# Test ExternalProject, especially with checkouts from VCS
+
+find_package(CVS)
+find_package(Subversion)
+find_package(Git)
+find_package(Hg)
+
+option(ExternalProjectTest_USE_FOLDERS "Enable folder grouping in IDEs." ON)
+if(ExternalProjectTest_USE_FOLDERS)
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+else()
+ set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
+endif()
+
+set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER
+ "CMakePredefinedTargets-in-ExternalProjectTest")
+
+set(base "${CMAKE_BINARY_DIR}/CMakeExternals")
+set(binary_base "${base}/Build")
+set_property(DIRECTORY PROPERTY EP_BASE ${base})
+set_property(DIRECTORY PROPERTY EP_STEP_TARGETS configure build test)
+
+add_custom_target(NonExternalProjectTarget
+ COMMAND ${CMAKE_COMMAND} -E echo NonExternalProjectTarget)
+
+# Empty projects that test all the known ExternalProject_Add argument key words:
+#
+set(proj AAA-TestAlphabetization)
+ExternalProject_Add(${proj}
+ BUILD_COMMAND ""
+ CONFIGURE_COMMAND ""
+ DOWNLOAD_COMMAND ""
+ INSTALL_COMMAND ""
+)
+
+set(proj ZZZ-TestAlphabetization)
+ExternalProject_Add(${proj}
+ BUILD_COMMAND ""
+ CONFIGURE_COMMAND ""
+ DOWNLOAD_COMMAND ""
+ INSTALL_COMMAND ""
+)
+
+set(proj TargetNameSameAsFolder)
+ExternalProject_Add(${proj}
+ BUILD_COMMAND ""
+ CONFIGURE_COMMAND ""
+ DOWNLOAD_COMMAND ""
+ INSTALL_COMMAND ""
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "${proj}")
+
+set(proj MinimalNoOpProject)
+ExternalProject_Add(${proj}
+ BUILD_COMMAND ""
+ CONFIGURE_COMMAND ""
+ DOWNLOAD_COMMAND ""
+ INSTALL_COMMAND ""
+)
+
+set(proj EmptyNoOpProject)
+ExternalProject_Add(${proj}
+ BUILD_COMMAND ""
+ CMAKE_ARGS ""
+ CONFIGURE_COMMAND ""
+ CVS_REPOSITORY ""
+ CVS_MODULE ""
+ CVS_TAG ""
+ DEPENDS "MinimalNoOpProject" NonExternalProjectTarget
+ DOWNLOAD_COMMAND ""
+ DOWNLOAD_NO_PROGRESS 1
+ INSTALL_COMMAND ""
+ PATCH_COMMAND ""
+ STEP_TARGETS install update
+ SVN_REPOSITORY ""
+ SVN_REVISION ""
+ SVN_USERNAME ""
+ SVN_PASSWORD ""
+ SVN_TRUST_CERT 1
+ TEST_COMMAND ""
+ TIMEOUT ""
+ URL ""
+ URL_MD5 ""
+ UPDATE_COMMAND ""
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "")
+
+
+# CVS-based tests:
+#
+set(do_cvs_tests 0)
+
+if(CVS_EXECUTABLE)
+ set(do_cvs_tests 1)
+endif()
+
+if(do_cvs_tests AND NOT UNIX)
+ if("${CVS_EXECUTABLE}" MATCHES "cygwin")
+ message(STATUS "No ExternalProject cvs tests with cygwin cvs.exe outside cygwin!")
+ set(do_cvs_tests 0)
+ endif()
+endif()
+
+if(do_cvs_tests)
+ # Unzip/untar the CVS repository in our source folder so that other
+ # projects below may use it to test CVS args of ExternalProject_Add
+ #
+ set(proj SetupLocalCVSRepository)
+ set(local_cvs_repo "${CMAKE_CURRENT_BINARY_DIR}/LocalRepositories/CVS")
+ ExternalProject_Add(${proj}
+ SOURCE_DIR ${local_cvs_repo}
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/cvsrepo.tgz
+ URL_MD5 55fc85825ffdd9ed2597123c68b79f7e
+ BUILD_COMMAND ""
+ CONFIGURE_COMMAND "${CVS_EXECUTABLE}" --version
+ INSTALL_COMMAND ""
+ )
+ set_property(TARGET ${proj}
+ PROPERTY FOLDER "SetupRepos/Local/Deeply/Nested/For/Testing")
+
+ # The MSYS cvs tool interprets "c:/" as a "machine:" name for SSH.
+ # Detect the MSYS cvs and convert the repo path to an MSYS path.
+ if(WIN32)
+ if(EXISTS "${CVS_EXECUTABLE}")
+ file(STRINGS "${CVS_EXECUTABLE}" cvs_is_msys LIMIT_COUNT 1 REGEX "[Mm][Ss][Yy][Ss]")
+ if(cvs_is_msys)
+ message(STATUS "'${CVS_EXECUTABLE}' is from MSYS (contains '${cvs_is_msys}')")
+ string(REGEX REPLACE "^([A-Za-z]):" "/\\1" local_cvs_repo "${local_cvs_repo}")
+ endif()
+ endif()
+ endif()
+
+ # CVS by date stamp:
+ #
+ set(proj TutorialStep1-CVS-20090626)
+ ExternalProject_Add(${proj}
+ CVS_REPOSITORY "${local_cvs_repo}"
+ CVS_MODULE "TutorialStep1"
+ CVS_TAG "-D2009-06-26 16:50:00 UTC"
+ UPDATE_COMMAND ""
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalCVSRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "CVS")
+
+ # CVS by tag:
+ #
+ set(proj TutorialStep1-CVS-testtag1)
+ ExternalProject_Add(${proj}
+ CVS_REPOSITORY "${local_cvs_repo}"
+ CVS_MODULE "TutorialStep1"
+ CVS_TAG -rtesttag1
+ UPDATE_COMMAND ""
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalCVSRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "CVS")
+
+ # Live CVS / HEAD (no CVS_TAG):
+ #
+ set(proj TutorialStep1-CVS-HEAD)
+ ExternalProject_Add(${proj}
+ CVS_REPOSITORY "${local_cvs_repo}"
+ CVS_MODULE "TutorialStep1"
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalCVSRepository"
+ DEPENDS "EmptyNoOpProject"
+ DEPENDS "TutorialStep1-CVS-20090626"
+ DEPENDS "TutorialStep1-CVS-testtag1"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "CVS")
+endif()
+
+
+# SVN-based tests:
+#
+set(do_svn_tests 0)
+
+if(Subversion_SVN_EXECUTABLE)
+ set(do_svn_tests 1)
+endif()
+
+# Only do svn tests with svn >= version 1.2
+#
+if(do_svn_tests)
+ if(Subversion_VERSION_SVN VERSION_LESS 1.2)
+ message(STATUS "No ExternalProject svn tests with svn client less than version 1.2")
+ set(do_svn_tests 0)
+ endif()
+endif()
+
+# Only do svn tests in cygwin/cygwin or not-cygwin/not-cygwin arrangements:
+#
+if(do_svn_tests)
+ if(CMAKE_CURRENT_BINARY_DIR MATCHES "cygdrive/" AND
+ NOT "${Subversion_SVN_EXECUTABLE}" MATCHES "cygwin")
+ message(STATUS "No ExternalProject svn tests with non-cygwin svn client in a /cygdrive based build")
+ set(do_svn_tests 0)
+ endif()
+endif()
+
+if(do_svn_tests)
+ # Unzip/untar the SVN repository in our source folder so that other
+ # projects below may use it to test SVN args of ExternalProject_Add
+ #
+ set(proj SetupLocalSVNRepository)
+ set(local_svn_repo "${CMAKE_CURRENT_BINARY_DIR}/LocalRepositories/SVN")
+ set(local_svn_repo_url "file:///${local_svn_repo}/TutorialStep1")
+ ExternalProject_Add(${proj}
+ SOURCE_DIR ${local_svn_repo}
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/svnrepo.tgz
+ URL_MD5 2f468be4ed1fa96377fca0cc830819c4
+ BUILD_COMMAND ""
+ CONFIGURE_COMMAND "${Subversion_SVN_EXECUTABLE}" --version
+ INSTALL_COMMAND ""
+ )
+ set_property(TARGET ${proj}
+ PROPERTY FOLDER "SetupRepos/Local/Deeply/Nested/For/Testing")
+
+ # SVN by date stamp:
+ #
+ set(proj TutorialStep1-SVN-20090626)
+ ExternalProject_Add(${proj}
+ SVN_REPOSITORY "${local_svn_repo_url}"
+ SVN_REVISION "-r{2009-06-26 16:50:00 +0000}"
+ UPDATE_COMMAND ""
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalSVNRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "SVN")
+
+ # SVN by revision number:
+ #
+ set(proj TutorialStep1-SVN-r2)
+ ExternalProject_Add(${proj}
+ SVN_REPOSITORY "${local_svn_repo_url}"
+ SVN_REVISION "-r2"
+ UPDATE_COMMAND ""
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalSVNRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "SVN")
+
+ # Live SVN / trunk (no SVN_REVISION):
+ #
+ set(proj TutorialStep1-SVN-trunk)
+ ExternalProject_Add(${proj}
+ SVN_REPOSITORY "${local_svn_repo_url}"
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalSVNRepository"
+ LOG_DOWNLOAD 1
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "SVN")
+endif()
+
+
+set(do_git_tests 0)
+
+if(GIT_EXECUTABLE)
+ set(do_git_tests 1)
+
+ execute_process(
+ COMMAND "${GIT_EXECUTABLE}" --version
+ OUTPUT_VARIABLE ov
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ string(REGEX REPLACE "^git version (.+)$" "\\1" git_version "${ov}")
+ message(STATUS "git_version='${git_version}'")
+
+ if(git_version VERSION_LESS 1.6.5)
+ message(STATUS "No ExternalProject git tests with git client less than version 1.6.5")
+ set(do_git_tests 0)
+ endif()
+endif()
+
+
+if(do_git_tests)
+ set(local_git_repo "../../LocalRepositories/GIT")
+
+ # Unzip/untar the git repository in our source folder so that other
+ # projects below may use it to test git args of ExternalProject_Add
+ #
+ set(proj SetupLocalGITRepository)
+ ExternalProject_Add(${proj}
+ SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/LocalRepositories/GIT
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/gitrepo.tgz
+ BUILD_COMMAND ""
+ CONFIGURE_COMMAND "${GIT_EXECUTABLE}" --version
+ INSTALL_COMMAND ""
+ )
+ set_property(TARGET ${proj}
+ PROPERTY FOLDER "SetupRepos/Local/Deeply/Nested/For/Testing")
+
+ # git by commit id:
+ #
+ set(proj TutorialStep1-GIT-byhash)
+ ExternalProject_Add(${proj}
+ GIT_REPOSITORY "${local_git_repo}"
+ GIT_TAG d1970730310fe8bc07e73f15dc570071f9f9654a
+ UPDATE_COMMAND ""
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalGITRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "GIT")
+
+ # git by explicit branch/tag name:
+ #
+ set(proj TutorialStep1-GIT-bytag)
+ ExternalProject_Add(${proj}
+ GIT_REPOSITORY "${local_git_repo}"
+ GIT_TAG "origin/master"
+ UPDATE_COMMAND ""
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalGITRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "GIT")
+
+ # Live git / master (no GIT_TAG):
+ #
+ set(proj TutorialStep1-GIT-master)
+ ExternalProject_Add(${proj}
+ GIT_REPOSITORY "${local_git_repo}"
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalGITRepository"
+ LOG_UPDATE 1
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "GIT")
+
+ # git by explicit branch/tag with empty submodule list
+ #
+ set(proj TutorialStep1-GIT-bytag-withsubmodules)
+ ExternalProject_Add(${proj}
+ GIT_REPOSITORY "${local_git_repo}"
+ GIT_TAG "origin/master"
+ GIT_SUBMODULES ""
+ UPDATE_COMMAND ""
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalGITRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "GIT")
+
+endif()
+
+set(do_hg_tests 0)
+
+if(HG_EXECUTABLE)
+ set(do_hg_tests 1)
+endif()
+
+if(do_hg_tests)
+ set(local_hg_repo "../../LocalRepositories/HG")
+
+ # Unzip/untar the hg repository in our source folder so that other
+ # projects below may use it to test hg args of ExternalProject_Add
+ #
+ set(proj SetupLocalHGRepository)
+ ExternalProject_Add(${proj}
+ SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/LocalRepositories/HG
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/hgrepo.tgz
+ BUILD_COMMAND ""
+ CONFIGURE_COMMAND "${HG_EXECUTABLE}" --version
+ INSTALL_COMMAND ""
+ )
+ set_property(TARGET ${proj}
+ PROPERTY FOLDER "SetupRepos/Local/Deeply/Nested/For/Testing")
+
+
+ # hg by commit id:
+ #
+ set(proj TutorialStep1-HG-byhash)
+ ExternalProject_Add(${proj}
+ HG_REPOSITORY "${local_hg_repo}"
+ HG_TAG dd2ce38a6b8a
+ UPDATE_COMMAND ""
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalHGRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "HG")
+
+ # hg by explicit branch/tag name:
+ #
+ set(proj TutorialStep1-HG-bytag)
+ ExternalProject_Add(${proj}
+ HG_REPOSITORY "${local_hg_repo}"
+ HG_TAG "default"
+ UPDATE_COMMAND ""
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalHGRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "HG")
+
+ # Live hg / tip (no HG_TAG):
+ #
+ # Mercurial 2.1 does not distinguish an empty pull from a failed pull,
+ # so do not run the test with that version.
+ if(NOT "${HG_VERSION_STRING}" STREQUAL "2.1")
+ set(proj TutorialStep1-HG-tip)
+ ExternalProject_Add(${proj}
+ HG_REPOSITORY "${local_hg_repo}"
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalHGRepository"
+ LOG_UPDATE 1
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "HG")
+ endif()
+endif()
+
+
+# Test the testable built/installed products:
+#
+enable_testing()
+
+
+# Do at least a smoke test of a built executable from each
+# project's build directory...
+#
+# BuildTree tests:
+#
+if(do_cvs_tests)
+ add_test(TutorialStep1-CVS-20090626-BuildTreeTest
+ "${binary_base}/TutorialStep1-CVS-20090626/Tutorial" 4)
+
+ add_test(TutorialStep1-CVS-testtag1-BuildTreeTest
+ "${binary_base}/TutorialStep1-CVS-testtag1/Tutorial" 64)
+
+ add_test(TutorialStep1-CVS-HEAD-BuildTreeTest
+ "${binary_base}/TutorialStep1-CVS-HEAD/Tutorial" 81)
+endif()
+
+if(do_svn_tests)
+ add_test(TutorialStep1-SVN-20090626-BuildTreeTest
+ "${binary_base}/TutorialStep1-SVN-20090626/Tutorial" 100)
+
+ add_test(TutorialStep1-SVN-r2-BuildTreeTest
+ "${binary_base}/TutorialStep1-SVN-r2/Tutorial" 99)
+
+ add_test(TutorialStep1-SVN-trunk-BuildTreeTest
+ "${binary_base}/TutorialStep1-SVN-trunk/Tutorial" 98)
+endif()
+
+if(do_git_tests)
+ add_test(TutorialStep1-GIT-byhash
+ "${binary_base}/TutorialStep1-GIT-byhash/Tutorial" 100)
+
+ add_test(TutorialStep1-GIT-bytag
+ "${binary_base}/TutorialStep1-GIT-bytag/Tutorial" 99)
+
+ add_test(TutorialStep1-GIT-master
+ "${binary_base}/TutorialStep1-GIT-master/Tutorial" 98)
+endif()
+
+
+message(STATUS "do_cvs_tests='${do_cvs_tests}'")
+message(STATUS "do_svn_tests='${do_svn_tests}'")
+message(STATUS "do_git_tests='${do_git_tests}' GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
+message(STATUS "do_hg_tests='${do_hg_tests}' HG_EXECUTABLE='${HG_EXECUTABLE}'")
diff --git a/Tests/ExternalProject/Example/CMakeLists.txt b/Tests/ExternalProject/Example/CMakeLists.txt
new file mode 100644
index 0000000000..69ebaaf511
--- /dev/null
+++ b/Tests/ExternalProject/Example/CMakeLists.txt
@@ -0,0 +1,11 @@
+# This is the canonical simplest ExternalProject example CMakeLists.txt file:
+cmake_minimum_required(VERSION 2.8)
+project(ExternalProjectExample NONE)
+include(ExternalProject)
+
+ExternalProject_Add(
+ cmake281
+ URL http://www.cmake.org/files/v2.8/cmake-2.8.1.tar.gz
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ BUILD_COMMAND ""
+)
diff --git a/Tests/ExternalProject/cvsrepo.tgz b/Tests/ExternalProject/cvsrepo.tgz
new file mode 100644
index 0000000000..baba6d3c2e
--- /dev/null
+++ b/Tests/ExternalProject/cvsrepo.tgz
Binary files differ
diff --git a/Tests/ExternalProject/gitrepo.tgz b/Tests/ExternalProject/gitrepo.tgz
new file mode 100644
index 0000000000..0a84bda7c1
--- /dev/null
+++ b/Tests/ExternalProject/gitrepo.tgz
Binary files differ
diff --git a/Tests/ExternalProject/hgrepo.tgz b/Tests/ExternalProject/hgrepo.tgz
new file mode 100644
index 0000000000..0d75ce22f0
--- /dev/null
+++ b/Tests/ExternalProject/hgrepo.tgz
Binary files differ
diff --git a/Tests/ExternalProject/svnrepo.tgz b/Tests/ExternalProject/svnrepo.tgz
new file mode 100644
index 0000000000..b8484165e0
--- /dev/null
+++ b/Tests/ExternalProject/svnrepo.tgz
Binary files differ
diff --git a/Tests/ExternalProjectLocal/CMakeLists.txt b/Tests/ExternalProjectLocal/CMakeLists.txt
new file mode 100644
index 0000000000..f94219766a
--- /dev/null
+++ b/Tests/ExternalProjectLocal/CMakeLists.txt
@@ -0,0 +1,229 @@
+cmake_minimum_required(VERSION 2.8)
+project(ExternalProjectLocalTest NONE)
+
+include(ExternalProject)
+
+# Test ExternalProject with local projects
+
+option(ExternalProjectTest_USE_FOLDERS "Enable folder grouping in IDEs." ON)
+if(ExternalProjectTest_USE_FOLDERS)
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+else()
+ set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
+endif()
+
+set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER
+ "CMakePredefinedTargets-in-ExternalProjectTest")
+
+set(base "${CMAKE_BINARY_DIR}/CMakeExternals")
+set(binary_base "${base}/Build")
+set_property(DIRECTORY PROPERTY EP_BASE ${base})
+set_property(DIRECTORY PROPERTY EP_STEP_TARGETS configure build test)
+
+if(NOT DEFINED can_build_tutorial_step5)
+ set(can_build_tutorial_step5 1)
+
+ # Tutorial Step5 cannot build correctly using Visual Studio 6
+ # on Windows 98 if the path of its build tree exceeds 72
+ # characters in length... So don't attempt to build it
+ # in a long path on Win98:
+ #
+ if(CMAKE_SYSTEM STREQUAL "Windows-4.10")
+ string(LENGTH "${binary_base}/TutorialStep5-Local" n)
+ if(n GREATER 72)
+ set(can_build_tutorial_step5 0)
+ endif()
+ endif()
+
+ # The ExternalProject builds of Tutorial Step5 cannot be built
+ # correctly 2nd and later times in an in-source build...
+ # (because the CMakeCache.txt from the real in-source build of
+ # the Tests/Tutorial/Step5 directory gets copied when we do
+ # the "source directory copy" step... but it still refers to
+ # its original path which yields a configure error.) So:
+ #
+ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
+ set(can_build_tutorial_step5 0)
+ endif()
+endif()
+
+# Local DIR:
+#
+if(can_build_tutorial_step5)
+ set(proj TutorialStep5-Local)
+ ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/../Tutorial/Step5"
+ CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ CMAKE_ARGS -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+ TEST_BEFORE_INSTALL 1
+ LOG_INSTALL 1
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "Local")
+ ExternalProject_Get_Property(${proj} install_dir)
+ set(TutorialStep5_install_dir ${install_dir})
+
+ set(proj TutorialStep5-Local-TestAfterInstall)
+ ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/../Tutorial/Step5"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+ TEST_AFTER_INSTALL 1
+ LOG_TEST 1
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "Local")
+endif()
+
+
+# Local TAR:
+#
+set(proj TutorialStep1-LocalTAR)
+ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/Step1.tar"
+ URL_MD5 a87c5b47c0201c09ddfe1d5738fdb1e3
+ LIST_SEPARATOR ::
+ PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/Step1Patch.cmake
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ -DTEST_LIST:STRING=A::B::C
+ INSTALL_COMMAND ""
+ LOG_CONFIGURE 1
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local/TAR")
+
+set(proj TutorialStep1-LocalNoDirTAR)
+ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/Step1NoDir.tar"
+ URL_MD5 d09e3d370c5c908fa035c30939ee438e
+ LIST_SEPARATOR @@
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+ -DTEST_LIST:STRING=1@@2@@3
+ INSTALL_COMMAND ""
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local/TAR")
+ExternalProject_Add_Step(${proj} mypatch
+ COMMAND ${CMAKE_COMMAND} -E echo "This is a custom external project step."
+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/Step1Patch.cmake
+ WORKING_DIRECTORY <SOURCE_DIR>
+ DEPENDEES download
+ DEPENDERS configure
+ )
+
+
+# Local TGZ:
+#
+set(proj TutorialStep1-LocalTGZ)
+ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/Step1.tgz"
+ URL_MD5 38c648e817339c356f6be00eeed79bd0
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+ INSTALL_COMMAND ""
+ LOG_BUILD 1
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local/TGZ")
+
+set(proj TutorialStep1-LocalNoDirTGZ)
+ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/Step1NoDir.tgz"
+ URL_HASH SHA256=496229e2a5ed620a37c385ad9406004a18026beab8b55dd2c4565d4b7f1d5383
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local/TGZ")
+
+
+# Local BZ2:
+#
+# (The bz2 tests are here just to verify that the bz2 decompression is executed
+# during a test suite run... The configure and build commands are set to
+# nothing to make the test quicker. To make this more complete, I should add
+# a diff between this and the TGZ source tree since that one does build...)
+#
+set(proj TutorialStep1-LocalBZ2)
+ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/Step1.tar.bz2"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local/BZ2")
+
+set(proj TutorialStep1-LocalNoDirBZ2)
+ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/Step1NoDir.tar.bz2"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local/BZ2")
+
+
+# Local ZIP:
+#
+# (The zip tests are here just to verify that the zip decompression is executed
+# during a test suite run... The configure and build commands are set to
+# nothing to make the test quicker. To make this more complete, I should add
+# a diff between this and the TGZ source tree since that one does build...)
+#
+set(proj TutorialStep1-LocalZIP)
+ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/Step1.zip"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local/ZIP")
+
+set(proj TutorialStep1-LocalNoDirZIP)
+ExternalProject_Add(${proj}
+ URL "${CMAKE_CURRENT_SOURCE_DIR}/Step1NoDir.zip"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local/ZIP")
+
+
+# Test the testable built/installed products:
+#
+enable_testing()
+
+
+# Do at least a smoke test of a built executable from each
+# project's build directory...
+#
+# BuildTree tests:
+#
+if(can_build_tutorial_step5)
+ add_test(TutorialStep5-Local-BuildTreeTest
+ "${binary_base}/TutorialStep5-Local/Tutorial" 42)
+ set_property(TEST TutorialStep5-Local-BuildTreeTest
+ APPEND PROPERTY LABELS Step5 BuildTree)
+endif()
+
+add_test(TutorialStep1-LocalTAR-BuildTreeTest
+ "${binary_base}/TutorialStep1-LocalTAR/EP-Tutorial" 36)
+set_property(TEST TutorialStep1-LocalTAR-BuildTreeTest
+ APPEND PROPERTY LABELS TAR)
+
+add_test(TutorialStep1-LocalNoDirTAR-BuildTreeTest
+ "${binary_base}/TutorialStep1-LocalNoDirTAR/EP-Tutorial" 25)
+
+add_test(TutorialStep1-LocalTGZ-BuildTreeTest
+ "${binary_base}/TutorialStep1-LocalTGZ/Tutorial" 16)
+set_property(TEST TutorialStep1-LocalTGZ-BuildTreeTest
+ APPEND PROPERTY LABELS TGZ)
+
+add_test(TutorialStep1-LocalNoDirTGZ-BuildTreeTest
+ "${binary_base}/TutorialStep1-LocalNoDirTGZ/Tutorial" 9)
+
+# InstallTree tests:
+#
+if(can_build_tutorial_step5)
+ add_test(TutorialStep5-InstallTreeTest
+ "${TutorialStep5_install_dir}/bin/Tutorial" 49)
+ set_property(TEST TutorialStep5-InstallTreeTest
+ APPEND PROPERTY LABELS Step5 InstallTree)
+endif()
+
+
+message(STATUS "can_build_tutorial_step5='${can_build_tutorial_step5}'")
diff --git a/Tests/ExternalProjectLocal/Step1.tar b/Tests/ExternalProjectLocal/Step1.tar
new file mode 100644
index 0000000000..3711f07fb3
--- /dev/null
+++ b/Tests/ExternalProjectLocal/Step1.tar
Binary files differ
diff --git a/Tests/ExternalProjectLocal/Step1.tar.bz2 b/Tests/ExternalProjectLocal/Step1.tar.bz2
new file mode 100644
index 0000000000..49b5f23a6b
--- /dev/null
+++ b/Tests/ExternalProjectLocal/Step1.tar.bz2
Binary files differ
diff --git a/Tests/ExternalProjectLocal/Step1.tgz b/Tests/ExternalProjectLocal/Step1.tgz
new file mode 100644
index 0000000000..d9b4cd259d
--- /dev/null
+++ b/Tests/ExternalProjectLocal/Step1.tgz
Binary files differ
diff --git a/Tests/ExternalProjectLocal/Step1.zip b/Tests/ExternalProjectLocal/Step1.zip
new file mode 100644
index 0000000000..49dac24edf
--- /dev/null
+++ b/Tests/ExternalProjectLocal/Step1.zip
Binary files differ
diff --git a/Tests/ExternalProjectLocal/Step1NoDir.tar b/Tests/ExternalProjectLocal/Step1NoDir.tar
new file mode 100644
index 0000000000..03664b856b
--- /dev/null
+++ b/Tests/ExternalProjectLocal/Step1NoDir.tar
Binary files differ
diff --git a/Tests/ExternalProjectLocal/Step1NoDir.tar.bz2 b/Tests/ExternalProjectLocal/Step1NoDir.tar.bz2
new file mode 100644
index 0000000000..92eb480d6a
--- /dev/null
+++ b/Tests/ExternalProjectLocal/Step1NoDir.tar.bz2
Binary files differ
diff --git a/Tests/ExternalProjectLocal/Step1NoDir.tgz b/Tests/ExternalProjectLocal/Step1NoDir.tgz
new file mode 100644
index 0000000000..71a2d81421
--- /dev/null
+++ b/Tests/ExternalProjectLocal/Step1NoDir.tgz
Binary files differ
diff --git a/Tests/ExternalProjectLocal/Step1NoDir.zip b/Tests/ExternalProjectLocal/Step1NoDir.zip
new file mode 100644
index 0000000000..b42d318798
--- /dev/null
+++ b/Tests/ExternalProjectLocal/Step1NoDir.zip
Binary files differ
diff --git a/Tests/ExternalProjectLocal/Step1Patch.cmake b/Tests/ExternalProjectLocal/Step1Patch.cmake
new file mode 100644
index 0000000000..35e09d948d
--- /dev/null
+++ b/Tests/ExternalProjectLocal/Step1Patch.cmake
@@ -0,0 +1,25 @@
+# Verify the current working directory.
+if(NOT EXISTS CMakeLists.txt)
+ message(FATAL_ERROR "File does not exist:\n ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt")
+endif()
+if(NOT EXISTS tutorial.cxx)
+ message(FATAL_ERROR "File does not exist:\n ${CMAKE_CURRENT_SOURCE_DIR}/tutorial.cxx")
+endif()
+
+# Check if the patch is already applied.
+file(STRINGS CMakeLists.txt prop_line REGEX "^set_property")
+if(prop_line)
+ message(STATUS "Patch already applied!")
+ return()
+endif()
+
+# Apply the patch.
+file(APPEND CMakeLists.txt "
+# Patch by ExternalProject test:
+set_property(TARGET Tutorial PROPERTY OUTPUT_NAME EP-Tutorial)
+list(LENGTH TEST_LIST len)
+if(NOT len EQUAL 3)
+ message(FATAL_ERROR \"TEST_LIST length is \${len}, not 3\")
+endif()
+")
+message(STATUS "Patched ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt")
diff --git a/Tests/ExternalProjectUpdate/CMakeLists.txt b/Tests/ExternalProjectUpdate/CMakeLists.txt
new file mode 100644
index 0000000000..c33e90b51b
--- /dev/null
+++ b/Tests/ExternalProjectUpdate/CMakeLists.txt
@@ -0,0 +1,94 @@
+cmake_minimum_required(VERSION 2.8)
+project(ExternalProjectUpdateTest NONE)
+
+include(ExternalProject)
+
+find_package(Git)
+
+option(ExternalProjectUpdateTest_USE_FOLDERS "Enable folder grouping in IDEs." ON)
+if(ExternalProjectUpdateTest_USE_FOLDERS)
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+else()
+ set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
+endif()
+
+set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER
+ "CMakePredefinedTargets-in-ExternalProjectUpdateTest")
+
+set(base "${CMAKE_BINARY_DIR}/CMakeExternals")
+set(binary_base "${base}/Build")
+set_property(DIRECTORY PROPERTY EP_BASE ${base})
+set_property(DIRECTORY PROPERTY EP_STEP_TARGETS configure build test)
+
+set(do_git_tests 0)
+
+if(GIT_EXECUTABLE)
+ set(do_git_tests 1)
+
+ execute_process(
+ COMMAND "${GIT_EXECUTABLE}" --version
+ OUTPUT_VARIABLE ov
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ string(REGEX REPLACE "^git version (.+)$" "\\1" git_version "${ov}")
+ message(STATUS "git_version='${git_version}'")
+
+ if(git_version VERSION_LESS 1.6.5)
+ message(STATUS "No ExternalProject git tests with git client less than version 1.6.5")
+ set(do_git_tests 0)
+ endif()
+endif()
+
+# This should be specified from the command line.
+if(NOT TEST_GIT_TAG)
+ set(TEST_GIT_TAG origin/master)
+endif()
+
+if(do_git_tests)
+ set(local_git_repo "../../LocalRepositories/GIT")
+
+ # Unzip/untar the git repository in our source folder so that other
+ # projects below may use it to test git args of ExternalProject_Add
+ #
+ set(proj SetupLocalGITRepository)
+ ExternalProject_Add(${proj}
+ SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/LocalRepositories/GIT
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/gitrepo.tgz
+ BUILD_COMMAND ""
+ CONFIGURE_COMMAND "${GIT_EXECUTABLE}" --version
+ INSTALL_COMMAND ""
+ )
+ set_property(TARGET ${proj}
+ PROPERTY FOLDER "SetupRepos/Local/Deeply/Nested/For/Testing")
+
+ set(proj TutorialStep1-GIT)
+ ExternalProject_Add(${proj}
+ GIT_REPOSITORY "${local_git_repo}"
+ GIT_TAG ${TEST_GIT_TAG}
+ CMAKE_GENERATOR "${CMAKE_GENERATOR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ INSTALL_COMMAND ""
+ DEPENDS "SetupLocalGITRepository"
+ )
+ set_property(TARGET ${proj} PROPERTY FOLDER "GIT")
+endif()
+
+
+# Test the testable built/installed products:
+#
+enable_testing()
+
+
+# Do at least a smoke test of a built executable from each
+# project's build directory...
+#
+# BuildTree tests:
+#
+
+if(do_git_tests)
+ add_test(TutorialStep1-GIT
+ "${binary_base}/TutorialStep1-GIT/Tutorial" 81)
+endif()
+
+message(STATUS "do_git_tests='${do_git_tests}'")
+message(STATUS "GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
diff --git a/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake b/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake
new file mode 100644
index 0000000000..6c7bcfe402
--- /dev/null
+++ b/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake
@@ -0,0 +1,95 @@
+# Set the ExternalProject GIT_TAG to desired_tag, and make sure the
+# resulting checked out version is resulting_sha and rebuild.
+# This check's the correct behavior of the ExternalProject UPDATE_COMMAND.
+# Also verify that a fetch only occurs when fetch_expected is 1.
+macro(check_a_tag desired_tag resulting_sha fetch_expected)
+ message( STATUS "Checking ExternalProjectUpdate to tag: ${desired_tag}" )
+
+ # Remove the FETCH_HEAD file, so we can check if it gets replaced with a 'git
+ # fetch'.
+ set( FETCH_HEAD_file ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT/.git/FETCH_HEAD )
+ file( REMOVE ${FETCH_HEAD_file} )
+
+ # Configure
+ execute_process(COMMAND ${CMAKE_COMMAND}
+ -G ${CMAKE_GENERATOR} -T "${CMAKE_GENERATOR_TOOLSET}"
+ -A "${CMAKE_GENERATOR_PLATFORM}"
+ -DTEST_GIT_TAG:STRING=${desired_tag}
+ ${ExternalProjectUpdate_SOURCE_DIR}
+ WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}
+ RESULT_VARIABLE error_code
+ )
+ if(error_code)
+ message(FATAL_ERROR "Could not configure the project.")
+ endif()
+
+ # Build
+ execute_process(COMMAND ${CMAKE_COMMAND}
+ --build ${ExternalProjectUpdate_BINARY_DIR}
+ RESULT_VARIABLE error_code
+ )
+ if(error_code)
+ message(FATAL_ERROR "Could not build the project.")
+ endif()
+
+ # Check the resulting SHA
+ execute_process(COMMAND ${GIT_EXECUTABLE}
+ rev-list --max-count=1 HEAD
+ WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT
+ RESULT_VARIABLE error_code
+ OUTPUT_VARIABLE tag_sha
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(error_code)
+ message(FATAL_ERROR "Could not check the sha.")
+ endif()
+
+ if(NOT (${tag_sha} STREQUAL ${resulting_sha}))
+ message(FATAL_ERROR "UPDATE_COMMAND produced
+ ${tag_sha}
+when
+ ${resulting_sha}
+was expected."
+ )
+ endif()
+
+ if( NOT EXISTS ${FETCH_HEAD_file} AND ${fetch_expected})
+ message( FATAL_ERROR "Fetch did NOT occur when it was expected.")
+ endif()
+ if( EXISTS ${FETCH_HEAD_file} AND NOT ${fetch_expected})
+ message( FATAL_ERROR "Fetch DID occur when it was not expected.")
+ endif()
+endmacro()
+
+find_package(Git)
+set(do_git_tests 0)
+if(GIT_EXECUTABLE)
+ set(do_git_tests 1)
+
+ execute_process(
+ COMMAND "${GIT_EXECUTABLE}" --version
+ OUTPUT_VARIABLE ov
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ string(REGEX REPLACE "^git version (.+)$" "\\1" git_version "${ov}")
+ message(STATUS "git_version='${git_version}'")
+
+ if(git_version VERSION_LESS 1.6.5)
+ message(STATUS "No ExternalProject git tests with git client less than version 1.6.5")
+ set(do_git_tests 0)
+ endif()
+endif()
+
+if(do_git_tests)
+ check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
+ check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 1)
+ # With the Git UPDATE_COMMAND performance patch, this will not required a
+ # 'git fetch'
+ check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 0)
+ check_a_tag(tag2 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
+ check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 1)
+ check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 0)
+ check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
+ # This is a remote symbolic ref, so it will always trigger a 'git fetch'
+ check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
+endif()
diff --git a/Tests/ExternalProjectUpdate/gitrepo.tgz b/Tests/ExternalProjectUpdate/gitrepo.tgz
new file mode 100644
index 0000000000..87090ab0be
--- /dev/null
+++ b/Tests/ExternalProjectUpdate/gitrepo.tgz
Binary files differ
diff --git a/Tests/FindGTK2/CMakeLists.txt b/Tests/FindGTK2/CMakeLists.txt
new file mode 100644
index 0000000000..1c5987ce36
--- /dev/null
+++ b/Tests/FindGTK2/CMakeLists.txt
@@ -0,0 +1,317 @@
+find_package(GTK2 COMPONENTS gtk glade gtkmm glademm QUIET)
+
+
+# Test GTK2 components
+if(GTK2_GTK_FOUND)
+ add_test(GTK2Components.gtk ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gtk"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Components/gtk"
+ ${build_generator_args}
+ --build-target gtk-all-libs
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Components/gtk"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(GTK2_GTKMM_FOUND)
+ add_test(GTK2Components.gtkmm ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gtkmm"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Components/gtkmm"
+ ${build_generator_args}
+ --build-target gtkmm-all-libs
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Components/gtkmm"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+
+# Test GTK2 targets
+if(TARGET GTK2::glib)
+ add_test(GTK2Targets.glib ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/glib"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/glib"
+ ${build_generator_args}
+ --build-project glib
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/glib"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::gobject)
+ add_test(GTK2Targets.gobject ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gobject"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gobject"
+ ${build_generator_args}
+ --build-project gobject
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gobject"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::gio)
+ add_test(GTK2Targets.gio ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gio"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gio"
+ ${build_generator_args}
+ --build-project gio
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gio"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::gmodule)
+ add_test(GTK2Targets.gmodule ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gmodule"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gmodule"
+ ${build_generator_args}
+ --build-project gmodule
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gmodule"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::gthread)
+ add_test(GTK2Targets.gthread ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gthread"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gthread"
+ ${build_generator_args}
+ --build-project gthread
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gthread"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::atk)
+ add_test(GTK2Targets.atk ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/atk"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/atk"
+ ${build_generator_args}
+ --build-project atk
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/atk"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::gdk_pixbuf)
+ add_test(GTK2Targets.gdk_pixbuf ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gdk_pixbuf"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gdk_pixbuf"
+ ${build_generator_args}
+ --build-project gdk_pixbuf
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gdk_pixbuf"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::cairo)
+ add_test(GTK2Targets.cairo ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/cairo"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/cairo"
+ ${build_generator_args}
+ --build-project cairo
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/cairo"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::pango)
+ add_test(GTK2Targets.pango ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/pango"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pango"
+ ${build_generator_args}
+ --build-project pango
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pango"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::pangocairo)
+ add_test(GTK2Targets.pangocairo ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/pangocairo"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pangocairo"
+ ${build_generator_args}
+ --build-project pangocairo
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pangocairo"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::pangoxft)
+ add_test(GTK2Targets.pangoxft ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/pangoxft"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pangoxft"
+ ${build_generator_args}
+ --build-project pangoxft
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pangoxft"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::pangoft2)
+ add_test(GTK2Targets.pangoft2 ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/pangoft2"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pangoft2"
+ ${build_generator_args}
+ --build-project pangoft2
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pangoft2"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::gdk)
+ add_test(GTK2Targets.gdk ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gdk"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gdk"
+ ${build_generator_args}
+ --build-project gdk
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gdk"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::gtk)
+ add_test(GTK2Targets.gtk ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gtk"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gtk"
+ ${build_generator_args}
+ --build-project gtk
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gtk"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::sigc++)
+ add_test(GTK2Targets.sigc++ ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/sigc++"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/sigc++"
+ ${build_generator_args}
+ --build-project sigc++
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/sigc++"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::glibmm)
+ add_test(GTK2Targets.glibmm ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/glibmm"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/glibmm"
+ ${build_generator_args}
+ --build-project glibmm
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/glibmm"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::giomm)
+ add_test(GTK2Targets.giomm ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/giomm"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/giomm"
+ ${build_generator_args}
+ --build-project giomm
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/giomm"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::atkmm)
+ add_test(GTK2Targets.atkmm ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/atkmm"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/atkmm"
+ ${build_generator_args}
+ --build-project atkmm
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/atkmm"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::cairomm)
+ add_test(GTK2Targets.cairomm ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/cairomm"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/cairomm"
+ ${build_generator_args}
+ --build-project cairomm
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/cairomm"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::pangomm)
+ add_test(GTK2Targets.pangomm ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/pangomm"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pangomm"
+ ${build_generator_args}
+ --build-project pangomm
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/pangomm"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::gdkmm)
+ add_test(GTK2Targets.gdkmm ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gdkmm"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/GTK2Targets/gdkmm"
+ ${build_generator_args}
+ --build-project gdkmm
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/GTK2Targets/gdkmm"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
+
+if(TARGET GTK2::gtkmm)
+ add_test(GTK2Targets.gtkmm ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGTK2/gtkmm"
+ "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gtkmm"
+ ${build_generator_args}
+ --build-target gtkmm-target
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/FindGTK2/GTK2Targets/gtkmm"
+ --force-new-ctest-process
+ --test-command ${CMAKE_CTEST_COMMAND} -V
+ )
+endif()
diff --git a/Tests/FindGTK2/atk/CMakeLists.txt b/Tests/FindGTK2/atk/CMakeLists.txt
new file mode 100644
index 0000000000..be37957edb
--- /dev/null
+++ b/Tests/FindGTK2/atk/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(atk C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(atk WIN32 main.c)
+target_link_libraries(atk GTK2::atk)
diff --git a/Tests/FindGTK2/atk/main.c b/Tests/FindGTK2/atk/main.c
new file mode 100644
index 0000000000..e25030ebdd
--- /dev/null
+++ b/Tests/FindGTK2/atk/main.c
@@ -0,0 +1,7 @@
+#include <atk/atk.h>
+
+int main(int argc, char *argv[])
+{
+ const gchar *name = atk_get_toolkit_name();
+ return 0;
+}
diff --git a/Tests/FindGTK2/atkmm/CMakeLists.txt b/Tests/FindGTK2/atkmm/CMakeLists.txt
new file mode 100644
index 0000000000..e8320b533f
--- /dev/null
+++ b/Tests/FindGTK2/atkmm/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(atkmm CXX)
+
+find_package(GTK2 COMPONENTS gtk gtkmm REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(atkmm WIN32 main.cpp)
+target_link_libraries(atkmm GTK2::atkmm)
diff --git a/Tests/FindGTK2/atkmm/main.cpp b/Tests/FindGTK2/atkmm/main.cpp
new file mode 100644
index 0000000000..f455c7a96d
--- /dev/null
+++ b/Tests/FindGTK2/atkmm/main.cpp
@@ -0,0 +1,8 @@
+#include <atkmm.h>
+#include <atkmm/init.h>
+
+int main(int argc, char *argv[])
+{
+ Atk::init();
+ return 0;
+}
diff --git a/Tests/FindGTK2/cairo/CMakeLists.txt b/Tests/FindGTK2/cairo/CMakeLists.txt
new file mode 100644
index 0000000000..97a7369440
--- /dev/null
+++ b/Tests/FindGTK2/cairo/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(cairo C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(cairo WIN32 main.c)
+target_link_libraries(cairo GTK2::cairo)
diff --git a/Tests/FindGTK2/cairo/main.c b/Tests/FindGTK2/cairo/main.c
new file mode 100644
index 0000000000..1b6100117c
--- /dev/null
+++ b/Tests/FindGTK2/cairo/main.c
@@ -0,0 +1,52 @@
+/* Taken from http://cairographics.org/samples/ */
+
+
+#include <cairo.h>
+#include <math.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ char *filename;
+ if (argc != 2)
+ {
+ fprintf (stderr, "Usage: %s OUTPUT_FILENAME\n", argv[0]);
+ return 1;
+ }
+ filename = argv[1];
+ double xc = 128.0;
+ double yc = 128.0;
+ double radius = 100.0;
+ double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */
+ double angle2 = 180.0 * (M_PI/180.0); /* in radians */
+
+ cairo_surface_t *im = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, xc * 2, yc * 2);
+ cairo_t *cr = cairo_create(im);
+
+
+ cairo_set_line_width (cr, 10.0);
+ cairo_arc (cr, xc, yc, radius, angle1, angle2);
+ cairo_stroke (cr);
+
+ /* draw helping lines */
+ cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
+ cairo_set_line_width (cr, 6.0);
+
+ cairo_arc (cr, xc, yc, 10.0, 0, 2*M_PI);
+ cairo_fill (cr);
+
+ cairo_arc (cr, xc, yc, radius, angle1, angle1);
+ cairo_line_to (cr, xc, yc);
+ cairo_arc (cr, xc, yc, radius, angle2, angle2);
+ cairo_line_to (cr, xc, yc);
+ cairo_stroke (cr);
+
+ cairo_status_t status = cairo_surface_write_to_png (im, filename);
+ cairo_surface_destroy (im);
+ if (status != CAIRO_STATUS_SUCCESS) {
+ fprintf(stderr, "Could not save png to '%s'\n", filename);
+ }
+
+ cairo_destroy(cr);
+ return 0;
+}
diff --git a/Tests/FindGTK2/cairomm/CMakeLists.txt b/Tests/FindGTK2/cairomm/CMakeLists.txt
new file mode 100644
index 0000000000..47a156e2cb
--- /dev/null
+++ b/Tests/FindGTK2/cairomm/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(cairomm CXX)
+
+find_package(GTK2 COMPONENTS gtk gtkmm REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(cairomm WIN32 main.cpp)
+target_link_libraries(cairomm GTK2::cairomm)
diff --git a/Tests/FindGTK2/cairomm/main.cpp b/Tests/FindGTK2/cairomm/main.cpp
new file mode 100644
index 0000000000..ea8f1065cc
--- /dev/null
+++ b/Tests/FindGTK2/cairomm/main.cpp
@@ -0,0 +1,62 @@
+// Taken from http://cgit.freedesktop.org/cairomm/plain/examples/surfaces/image-surface.cc
+
+
+/* M_PI is defined in math.h in the case of Microsoft Visual C++, Solaris,
+ * et. al.
+ */
+#if defined(_MSC_VER)
+#define _USE_MATH_DEFINES
+#endif
+
+#include <string>
+#include <iostream>
+#include <cairommconfig.h>
+#include <cairomm/context.h>
+#include <cairomm/surface.h>
+
+#include <cmath>
+
+int main()
+{
+ Cairo::RefPtr<Cairo::ImageSurface> surface =
+ Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 400);
+
+ Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
+
+ cr->save(); // save the state of the context
+ cr->set_source_rgb(0.86, 0.85, 0.47);
+ cr->paint(); // fill image with the color
+ cr->restore(); // color is back to black now
+
+ cr->save();
+ // draw a border around the image
+ cr->set_line_width(20.0); // make the line wider
+ cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height());
+ cr->stroke();
+
+ cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
+ // draw a circle in the center of the image
+ cr->arc(surface->get_width() / 2.0, surface->get_height() / 2.0,
+ surface->get_height() / 4.0, 0.0, 2.0 * M_PI);
+ cr->stroke();
+
+ // draw a diagonal line
+ cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0);
+ cr->line_to(surface->get_width() * 3.0 / 4.0, surface->get_height() * 3.0 / 4.0);
+ cr->stroke();
+ cr->restore();
+
+#ifdef CAIRO_HAS_PNG_FUNCTIONS
+
+ std::string filename = "image.png";
+ surface->write_to_png(filename);
+
+ std::cout << "Wrote png file \"" << filename << "\"" << std::endl;
+
+#else
+
+ std::cout << "You must compile cairo with PNG support for this example to work."
+ << std::endl;
+
+#endif
+}
diff --git a/Tests/FindGTK2/gdk/CMakeLists.txt b/Tests/FindGTK2/gdk/CMakeLists.txt
new file mode 100644
index 0000000000..f4852368c7
--- /dev/null
+++ b/Tests/FindGTK2/gdk/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(gdk C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(gdk WIN32 main.c)
+target_link_libraries(gdk GTK2::gdk)
diff --git a/Tests/FindGTK2/gdk/main.c b/Tests/FindGTK2/gdk/main.c
new file mode 100644
index 0000000000..ac1bd4b594
--- /dev/null
+++ b/Tests/FindGTK2/gdk/main.c
@@ -0,0 +1,7 @@
+#include <gdk/gdk.h>
+
+int main(int argc, char *argv[])
+{
+ gdk_init(argc, argv);
+ return 0;
+}
diff --git a/Tests/FindGTK2/gdk_pixbuf/CMakeLists.txt b/Tests/FindGTK2/gdk_pixbuf/CMakeLists.txt
new file mode 100644
index 0000000000..004e82e8aa
--- /dev/null
+++ b/Tests/FindGTK2/gdk_pixbuf/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(gdk_pixbuf C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(gdk_pixbuf WIN32 main.c)
+target_link_libraries(gdk_pixbuf GTK2::gdk_pixbuf)
diff --git a/Tests/FindGTK2/gdk_pixbuf/main.c b/Tests/FindGTK2/gdk_pixbuf/main.c
new file mode 100644
index 0000000000..e42b83e86c
--- /dev/null
+++ b/Tests/FindGTK2/gdk_pixbuf/main.c
@@ -0,0 +1,10 @@
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+int main(int argc, char *argv[])
+{
+ const char *version = gdk_pixbuf_version;
+ const guint major = gdk_pixbuf_major_version;
+ const guint minor = gdk_pixbuf_minor_version;
+ const guint micro = gdk_pixbuf_micro_version;
+ return 0;
+}
diff --git a/Tests/FindGTK2/gdkmm/CMakeLists.txt b/Tests/FindGTK2/gdkmm/CMakeLists.txt
new file mode 100644
index 0000000000..a54fc4f130
--- /dev/null
+++ b/Tests/FindGTK2/gdkmm/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(gdkmm CXX)
+
+find_package(GTK2 COMPONENTS gtk gtkmm REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(gdkmm WIN32 main.cpp)
+target_link_libraries(gdkmm GTK2::gdkmm)
diff --git a/Tests/FindGTK2/gdkmm/main.cpp b/Tests/FindGTK2/gdkmm/main.cpp
new file mode 100644
index 0000000000..935bcc42c3
--- /dev/null
+++ b/Tests/FindGTK2/gdkmm/main.cpp
@@ -0,0 +1,7 @@
+#include <gdkmm.h>
+
+int main(int argc, char *argv[])
+{
+ Gdk::Color red = Gdk::Color("red");
+ return 0;
+}
diff --git a/Tests/FindGTK2/gio/CMakeLists.txt b/Tests/FindGTK2/gio/CMakeLists.txt
new file mode 100644
index 0000000000..db9cdd00a2
--- /dev/null
+++ b/Tests/FindGTK2/gio/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(gio C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(gio WIN32 main.c)
+target_link_libraries(gio GTK2::gio)
diff --git a/Tests/FindGTK2/gio/main.c b/Tests/FindGTK2/gio/main.c
new file mode 100644
index 0000000000..13f4304a27
--- /dev/null
+++ b/Tests/FindGTK2/gio/main.c
@@ -0,0 +1,8 @@
+#include <gio/gio.h>
+
+int main(int argc, char *argv[])
+{
+ GFile *file = g_file_new_for_path("path");
+ g_object_unref(file);
+ return 0;
+}
diff --git a/Tests/FindGTK2/giomm/CMakeLists.txt b/Tests/FindGTK2/giomm/CMakeLists.txt
new file mode 100644
index 0000000000..46cfef50a6
--- /dev/null
+++ b/Tests/FindGTK2/giomm/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(giomm CXX)
+
+find_package(GTK2 COMPONENTS gtk gtkmm REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(giomm WIN32 main.cpp)
+target_link_libraries(giomm GTK2::giomm)
diff --git a/Tests/FindGTK2/giomm/main.cpp b/Tests/FindGTK2/giomm/main.cpp
new file mode 100644
index 0000000000..8303ba9ecf
--- /dev/null
+++ b/Tests/FindGTK2/giomm/main.cpp
@@ -0,0 +1,7 @@
+#include <giomm.h>
+
+int main(int argc, char *argv[])
+{
+ Glib::RefPtr<Gio::File> f = Gio::File::create_for_path("path");
+ return 0;
+}
diff --git a/Tests/FindGTK2/glib/CMakeLists.txt b/Tests/FindGTK2/glib/CMakeLists.txt
new file mode 100644
index 0000000000..1aa73ff16c
--- /dev/null
+++ b/Tests/FindGTK2/glib/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(glib C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(glib WIN32 main.c)
+target_link_libraries(glib GTK2::glib)
diff --git a/Tests/FindGTK2/glib/main.c b/Tests/FindGTK2/glib/main.c
new file mode 100644
index 0000000000..80d0554e42
--- /dev/null
+++ b/Tests/FindGTK2/glib/main.c
@@ -0,0 +1,11 @@
+#include <glib.h>
+
+int main(int argc, char *argv[])
+{
+ if (!g_file_test("file", G_FILE_TEST_EXISTS)) {
+ g_print("File not found. \n");
+ } else {
+ g_print("File found. \n");
+ }
+ return 0;
+}
diff --git a/Tests/FindGTK2/glibmm/CMakeLists.txt b/Tests/FindGTK2/glibmm/CMakeLists.txt
new file mode 100644
index 0000000000..af8ddcf277
--- /dev/null
+++ b/Tests/FindGTK2/glibmm/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(glibmm CXX)
+
+find_package(GTK2 COMPONENTS gtk gtkmm REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(glibmm WIN32 main.cpp)
+target_link_libraries(glibmm GTK2::glibmm)
diff --git a/Tests/FindGTK2/glibmm/main.cpp b/Tests/FindGTK2/glibmm/main.cpp
new file mode 100644
index 0000000000..0e8cdae7d5
--- /dev/null
+++ b/Tests/FindGTK2/glibmm/main.cpp
@@ -0,0 +1,7 @@
+#include <glibmm/init.h>
+
+int main(int, char**)
+{
+ Glib::init();
+ return 0;
+}
diff --git a/Tests/FindGTK2/gmodule/CMakeLists.txt b/Tests/FindGTK2/gmodule/CMakeLists.txt
new file mode 100644
index 0000000000..9717da8d5f
--- /dev/null
+++ b/Tests/FindGTK2/gmodule/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(gmodule C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(gmodule WIN32 main.c)
+target_link_libraries(gmodule GTK2::gmodule)
diff --git a/Tests/FindGTK2/gmodule/main.c b/Tests/FindGTK2/gmodule/main.c
new file mode 100644
index 0000000000..5c85a6f987
--- /dev/null
+++ b/Tests/FindGTK2/gmodule/main.c
@@ -0,0 +1,7 @@
+#include <gmodule.h>
+
+int main(int argc, char *argv[])
+{
+ gboolean b = g_module_supported();
+ return 0;
+}
diff --git a/Tests/FindGTK2/gobject/CMakeLists.txt b/Tests/FindGTK2/gobject/CMakeLists.txt
new file mode 100644
index 0000000000..c51fd4dee1
--- /dev/null
+++ b/Tests/FindGTK2/gobject/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(gobject C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(gobject WIN32 main.c)
+target_link_libraries(gobject GTK2::gobject)
diff --git a/Tests/FindGTK2/gobject/main.c b/Tests/FindGTK2/gobject/main.c
new file mode 100644
index 0000000000..d3e13f9e5f
--- /dev/null
+++ b/Tests/FindGTK2/gobject/main.c
@@ -0,0 +1,72 @@
+/* Taken from https://developer.gnome.org/gobject/stable/chapter-gobject.html */
+
+
+#include <glib-object.h>
+
+
+#define MAMAN_TYPE_BAR (maman_bar_get_type ())
+#define MAMAN_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAMAN_TYPE_BAR, MamanBar))
+#define MAMAN_IS_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAMAN_TYPE_BAR))
+#define MAMAN_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAMAN_TYPE_BAR, MamanBarClass))
+#define MAMAN_IS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAMAN_TYPE_BAR))
+#define MAMAN_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAMAN_TYPE_BAR, MamanBarClass))
+
+typedef struct _MamanBar MamanBar;
+typedef struct _MamanBarClass MamanBarClass;
+
+struct _MamanBar
+{
+ GObject parent_instance;
+
+ /* instance members */
+};
+
+struct _MamanBarClass
+{
+ GObjectClass parent_class;
+
+ /* class members */
+};
+
+/* will create maman_bar_get_type and set maman_bar_parent_class */
+G_DEFINE_TYPE (MamanBar, maman_bar, G_TYPE_OBJECT);
+
+static GObject *
+maman_bar_constructor (GType gtype,
+ guint n_properties,
+ GObjectConstructParam *properties)
+{
+ GObject *obj;
+
+ {
+ /* Always chain up to the parent constructor */
+ obj = G_OBJECT_CLASS (maman_bar_parent_class)->constructor (gtype, n_properties, properties);
+ }
+
+ /* update the object state depending on constructor properties */
+
+ return obj;
+}
+
+static void
+maman_bar_class_init (MamanBarClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->constructor = maman_bar_constructor;
+}
+
+static void
+maman_bar_init (MamanBar *self)
+{
+ /* initialize the object */
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ MamanBar *bar = g_object_new (MAMAN_TYPE_BAR, NULL);
+ g_object_unref(bar);
+ return 0;
+}
diff --git a/Tests/FindGTK2/gthread/CMakeLists.txt b/Tests/FindGTK2/gthread/CMakeLists.txt
new file mode 100644
index 0000000000..a90294d0ab
--- /dev/null
+++ b/Tests/FindGTK2/gthread/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(gthread C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(gthread WIN32 main.c)
+target_link_libraries(gthread GTK2::gthread)
diff --git a/Tests/FindGTK2/gthread/main.c b/Tests/FindGTK2/gthread/main.c
new file mode 100644
index 0000000000..ce68cbd6bc
--- /dev/null
+++ b/Tests/FindGTK2/gthread/main.c
@@ -0,0 +1,7 @@
+#include <glib.h>
+
+int main(int argc, char *argv[])
+{
+ g_thread_init(NULL);
+ return 0;
+}
diff --git a/Tests/FindGTK2/gtk/CMakeLists.txt b/Tests/FindGTK2/gtk/CMakeLists.txt
new file mode 100644
index 0000000000..11603aec95
--- /dev/null
+++ b/Tests/FindGTK2/gtk/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(gtk C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(gtk WIN32 main.c)
+target_link_libraries(gtk GTK2::gtk)
+
+add_executable(gtk-all-libs WIN32 main.c)
+target_link_libraries(gtk-all-libs ${GTK2_LIBRARIES})
+target_include_directories(gtk-all-libs PRIVATE ${GTK2_INCLUDE_DIRS})
diff --git a/Tests/FindGTK2/gtk/main.c b/Tests/FindGTK2/gtk/main.c
new file mode 100644
index 0000000000..309c32896e
--- /dev/null
+++ b/Tests/FindGTK2/gtk/main.c
@@ -0,0 +1,15 @@
+#include <gtk/gtk.h>
+
+int main(int argc, char *argv[])
+{
+ GtkWidget *window;
+
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_widget_show (window);
+
+ gtk_main ();
+
+ return 0;
+}
diff --git a/Tests/FindGTK2/gtkmm/CMakeLists.txt b/Tests/FindGTK2/gtkmm/CMakeLists.txt
new file mode 100644
index 0000000000..32aafe2c1e
--- /dev/null
+++ b/Tests/FindGTK2/gtkmm/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(gtkmm CXX)
+
+find_package(GTK2 COMPONENTS gtk gtkmm REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(gtkmm-target WIN32 main.cpp helloworld.cpp helloworld.h)
+target_link_libraries(gtkmm-target GTK2::gtkmm)
+
+add_executable(gtkmm-all-libs WIN32 main.cpp helloworld.cpp helloworld.h)
+target_link_libraries(gtkmm-all-libs ${GTK2_LIBRARIES})
+target_include_directories(gtkmm-all-libs PRIVATE ${GTK2_INCLUDE_DIRS})
diff --git a/Tests/FindGTK2/gtkmm/helloworld.cpp b/Tests/FindGTK2/gtkmm/helloworld.cpp
new file mode 100644
index 0000000000..535f44a5d5
--- /dev/null
+++ b/Tests/FindGTK2/gtkmm/helloworld.cpp
@@ -0,0 +1,29 @@
+#include "helloworld.h"
+#include <iostream>
+
+HelloWorld::HelloWorld()
+ : m_button("Hello World") // creates a new button with label "Hello World".
+{
+ // Sets the border width of the window.
+ set_border_width(10);
+
+ // When the button receives the "clicked" signal, it will call the
+ // on_button_clicked() method defined below.
+ m_button.signal_clicked().connect(sigc::mem_fun(*this,
+ &HelloWorld::on_button_clicked));
+
+ // This packs the button into the Window (a container).
+ add(m_button);
+
+ // The final step is to display this newly created widget...
+ m_button.show();
+}
+
+HelloWorld::~HelloWorld()
+{
+}
+
+void HelloWorld::on_button_clicked()
+{
+ std::cout << "Hello World" << std::endl;
+}
diff --git a/Tests/FindGTK2/gtkmm/helloworld.h b/Tests/FindGTK2/gtkmm/helloworld.h
new file mode 100644
index 0000000000..ab9a076b7d
--- /dev/null
+++ b/Tests/FindGTK2/gtkmm/helloworld.h
@@ -0,0 +1,20 @@
+#ifndef GTKMM_EXAMPLE_HELLOWORLD_H
+#define GTKMM_EXAMPLE_HELLOWORLD_H
+
+#include <gtkmm.h>
+
+class HelloWorld : public Gtk::Window
+{
+public:
+ HelloWorld();
+ virtual ~HelloWorld();
+
+protected:
+ //Signal handlers:
+ void on_button_clicked();
+
+ //Member widgets:
+ Gtk::Button m_button;
+};
+
+#endif // GTKMM_EXAMPLE_HELLOWORLD_H
diff --git a/Tests/FindGTK2/gtkmm/main.cpp b/Tests/FindGTK2/gtkmm/main.cpp
new file mode 100644
index 0000000000..5ff64d113a
--- /dev/null
+++ b/Tests/FindGTK2/gtkmm/main.cpp
@@ -0,0 +1,13 @@
+#include <gtkmm.h>
+#include "helloworld.h"
+
+int main(int argc, char *argv[])
+{
+ Gtk::Main kit(argc, argv);
+
+ HelloWorld helloworld;
+ //Shows the window and returns when it is closed.
+ Gtk::Main::run(helloworld);
+
+ return 0;
+}
diff --git a/Tests/FindGTK2/pango/CMakeLists.txt b/Tests/FindGTK2/pango/CMakeLists.txt
new file mode 100644
index 0000000000..af382a4c71
--- /dev/null
+++ b/Tests/FindGTK2/pango/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(pango C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(pango WIN32 main.c)
+target_link_libraries(pango GTK2::pango)
diff --git a/Tests/FindGTK2/pango/main.c b/Tests/FindGTK2/pango/main.c
new file mode 100644
index 0000000000..ef87ce447c
--- /dev/null
+++ b/Tests/FindGTK2/pango/main.c
@@ -0,0 +1,7 @@
+#include <pango/pango.h>
+
+int main(int argc, char *argv[])
+{
+ gboolean ret = pango_color_parse(NULL, "#ffffff");
+ return 0;
+}
diff --git a/Tests/FindGTK2/pangocairo/CMakeLists.txt b/Tests/FindGTK2/pangocairo/CMakeLists.txt
new file mode 100644
index 0000000000..8f61379b30
--- /dev/null
+++ b/Tests/FindGTK2/pangocairo/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(pangocairo C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(pangocairo WIN32 main.c)
+target_link_libraries(pangocairo GTK2::pangocairo m)
diff --git a/Tests/FindGTK2/pangocairo/main.c b/Tests/FindGTK2/pangocairo/main.c
new file mode 100644
index 0000000000..78268d6f0f
--- /dev/null
+++ b/Tests/FindGTK2/pangocairo/main.c
@@ -0,0 +1,72 @@
+/* Taken from https://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html */
+
+
+#include <math.h>
+#include <pango/pangocairo.h>
+static void
+draw_text (cairo_t *cr)
+{
+#define RADIUS 150
+#define N_WORDS 10
+#define FONT "Sans Bold 27"
+ PangoLayout *layout;
+ PangoFontDescription *desc;
+ int i;
+ /* Center coordinates on the middle of the region we are drawing
+ */
+ cairo_translate (cr, RADIUS, RADIUS);
+ /* Create a PangoLayout, set the font and text */
+ layout = pango_cairo_create_layout (cr);
+ pango_layout_set_text (layout, "Text", -1);
+ desc = pango_font_description_from_string (FONT);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+ /* Draw the layout N_WORDS times in a circle */
+ for (i = 0; i < N_WORDS; i++)
+ {
+ int width, height;
+ double angle = (360. * i) / N_WORDS;
+ double red;
+ cairo_save (cr);
+ /* Gradient from red at angle == 60 to blue at angle == 240 */
+ red = (1 + cos ((angle - 60) * G_PI / 180.)) / 2;
+ cairo_set_source_rgb (cr, red, 0, 1.0 - red);
+ cairo_rotate (cr, angle * G_PI / 180.);
+ /* Inform Pango to re-layout the text with the new transformation */
+ pango_cairo_update_layout (cr, layout);
+ pango_layout_get_size (layout, &width, &height);
+ cairo_move_to (cr, - ((double)width / PANGO_SCALE) / 2, - RADIUS);
+ pango_cairo_show_layout (cr, layout);
+ cairo_restore (cr);
+ }
+ /* free the layout object */
+ g_object_unref (layout);
+}
+int main (int argc, char **argv)
+{
+ cairo_t *cr;
+ char *filename;
+ cairo_status_t status;
+ cairo_surface_t *surface;
+ if (argc != 2)
+ {
+ g_printerr ("Usage: cairosimple OUTPUT_FILENAME\n");
+ return 1;
+ }
+ filename = argv[1];
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ 2 * RADIUS, 2 * RADIUS);
+ cr = cairo_create (surface);
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ cairo_paint (cr);
+ draw_text (cr);
+ cairo_destroy (cr);
+ status = cairo_surface_write_to_png (surface, filename);
+ cairo_surface_destroy (surface);
+ if (status != CAIRO_STATUS_SUCCESS)
+ {
+ g_printerr ("Could not save png to '%s'\n", filename);
+ return 1;
+ }
+ return 0;
+}
diff --git a/Tests/FindGTK2/pangoft2/CMakeLists.txt b/Tests/FindGTK2/pangoft2/CMakeLists.txt
new file mode 100644
index 0000000000..0f84c7fdf0
--- /dev/null
+++ b/Tests/FindGTK2/pangoft2/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(pangoft2 C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(pangoft2 WIN32 main.c)
+target_link_libraries(pangoft2 GTK2::pangoft2)
diff --git a/Tests/FindGTK2/pangoft2/main.c b/Tests/FindGTK2/pangoft2/main.c
new file mode 100644
index 0000000000..cf3459ecf3
--- /dev/null
+++ b/Tests/FindGTK2/pangoft2/main.c
@@ -0,0 +1,8 @@
+#include <pango/pangoft2.h>
+
+int main(int argc, char *argv[])
+{
+ PangoFontMap* pfm = pango_ft2_font_map_new();
+ g_object_unref(pfm);
+ return 0;
+}
diff --git a/Tests/FindGTK2/pangomm/CMakeLists.txt b/Tests/FindGTK2/pangomm/CMakeLists.txt
new file mode 100644
index 0000000000..3650c50809
--- /dev/null
+++ b/Tests/FindGTK2/pangomm/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(pangomm CXX)
+
+find_package(GTK2 COMPONENTS gtk gtkmm REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(pangomm WIN32 main.cpp)
+target_link_libraries(pangomm GTK2::pangomm)
diff --git a/Tests/FindGTK2/pangomm/main.cpp b/Tests/FindGTK2/pangomm/main.cpp
new file mode 100644
index 0000000000..32ec914e7c
--- /dev/null
+++ b/Tests/FindGTK2/pangomm/main.cpp
@@ -0,0 +1,8 @@
+#include <pangomm.h>
+#include <pangomm/init.h>
+
+int main(int argc, char *argv[])
+{
+ Pango::init();
+ return 0;
+}
diff --git a/Tests/FindGTK2/pangoxft/CMakeLists.txt b/Tests/FindGTK2/pangoxft/CMakeLists.txt
new file mode 100644
index 0000000000..0db16b1532
--- /dev/null
+++ b/Tests/FindGTK2/pangoxft/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(pangoxft C)
+
+find_package(GTK2 COMPONENTS gtk REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(pangoxft WIN32 main.c)
+target_link_libraries(pangoxft GTK2::pangoxft)
diff --git a/Tests/FindGTK2/pangoxft/main.c b/Tests/FindGTK2/pangoxft/main.c
new file mode 100644
index 0000000000..cb04f6185e
--- /dev/null
+++ b/Tests/FindGTK2/pangoxft/main.c
@@ -0,0 +1,7 @@
+#include <pango/pangoxft.h>
+
+int main(int argc, char *argv[])
+{
+ pango_xft_get_context(NULL, 0);
+ return 0;
+}
diff --git a/Tests/FindGTK2/sigc++/CMakeLists.txt b/Tests/FindGTK2/sigc++/CMakeLists.txt
new file mode 100644
index 0000000000..f830b81b74
--- /dev/null
+++ b/Tests/FindGTK2/sigc++/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(sigc++ CXX)
+
+find_package(GTK2 COMPONENTS gtk gtkmm REQUIRED)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(sigc++ WIN32 main.cpp)
+target_link_libraries(sigc++ GTK2::sigc++)
diff --git a/Tests/FindGTK2/sigc++/main.cpp b/Tests/FindGTK2/sigc++/main.cpp
new file mode 100644
index 0000000000..78428e76bf
--- /dev/null
+++ b/Tests/FindGTK2/sigc++/main.cpp
@@ -0,0 +1,30 @@
+// Taken from https://developer.gnome.org/libsigc++-tutorial/stable/ch02.html
+
+
+#include <sigc++/sigc++.h>
+#include <iostream>
+
+class AlienDetector
+{
+public:
+ AlienDetector() {}
+
+ void run() {}
+
+ sigc::signal<void> signal_detected;
+};
+
+void warn_people()
+{
+ std::cout << "There are aliens in the carpark!" << std::endl;
+}
+
+int main()
+{
+ AlienDetector mydetector;
+ mydetector.signal_detected.connect( sigc::ptr_fun(warn_people) );
+
+ mydetector.run();
+
+ return 0;
+}
diff --git a/Tests/FindModulesExecuteAll/CMakeLists.txt b/Tests/FindModulesExecuteAll/CMakeLists.txt
new file mode 100644
index 0000000000..21b9d3897f
--- /dev/null
+++ b/Tests/FindModulesExecuteAll/CMakeLists.txt
@@ -0,0 +1,30 @@
+# This file includes all FindXXX.cmake modules, so they are all executed.
+# As it is it doesn't test a lot.
+# It makes sure that the modules don't contain basic syntax errors.
+# It also makes sure that modules don't fail with an error if something
+# wasn't found but REQUIRED was not given.
+#
+# I guess more things could be added, like checking whether variables are
+# defined after running the modules (e.g. FOO_FOUND etc.).
+project(FindModulesExecuteAll)
+cmake_minimum_required(VERSION 2.7)
+
+file(GLOB all_modules "${CMAKE_CURRENT_SOURCE_DIR}/../../Modules/Find*cmake")
+
+foreach(module ${all_modules})
+ message(STATUS "module: ${module}")
+ include("${module}")
+
+ # get the "basename" of the package, so the existence of variables like
+ # FOO_FOUND could be tested later on, Alex
+ string(REGEX REPLACE ".+Find([^\\.]+)\\.cmake" "\\1" packageName "${module}")
+ string(TOUPPER "${packageName}" packageNameUpper)
+
+# disabled for now, since too many modules break:
+# if(NOT DEFINED ${packageNameUpper}_FOUND)
+# message(SEND_ERROR "${packageNameUpper}_FOUND not defined !")
+# endif()
+
+endforeach()
+
+add_executable(FindModulesExecuteAll main.c)
diff --git a/Tests/FindModulesExecuteAll/main.c b/Tests/FindModulesExecuteAll/main.c
new file mode 100644
index 0000000000..c13815cea8
--- /dev/null
+++ b/Tests/FindModulesExecuteAll/main.c
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/FindPackageModeMakefileTest/CMakeLists.txt b/Tests/FindPackageModeMakefileTest/CMakeLists.txt
new file mode 100644
index 0000000000..8e21c32b61
--- /dev/null
+++ b/Tests/FindPackageModeMakefileTest/CMakeLists.txt
@@ -0,0 +1,39 @@
+
+
+if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Makefile")
+
+ # Test whether the make is GNU make, and only add the test in this case,
+ # since the configured makefile in this test uses $(shell ...), which
+ # is AFAIK a GNU make extension. Alex
+ execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} -v
+ OUTPUT_VARIABLE makeVersionOutput
+ ERROR_QUIET
+ TIMEOUT 10)
+ string(TOUPPER "${makeVersionOutput}" MAKE_VERSION_OUTPUT)
+ if("${MAKE_VERSION_OUTPUT}" MATCHES "GNU MAKE")
+
+ # build a library which we can search during the test
+ add_library(foo STATIC foo.cpp)
+
+ # configure a FindFoo.cmake so it knows where the library can be found
+ configure_file(FindFoo.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FindFoo.cmake @ONLY)
+
+ # now set up the test:
+ if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
+ file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cmakeExecutable.mk"
+ CONTENT "CMAKE = \"$<TARGET_FILE:cmake>\"\n"
+ )
+ else()
+ get_target_property(cmakeLocation cmake LOCATION)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cmakeExecutable.mk"
+ "CMAKE = \"${cmakeLocation}\"\n"
+ )
+ endif()
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Makefile.in ${CMAKE_CURRENT_BINARY_DIR}/ConfMakefile @ONLY)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/main.cpp COPYONLY)
+
+ add_test(FindPackageModeMakefileTest ${CMAKE_MAKE_PROGRAM} -f ${CMAKE_CURRENT_BINARY_DIR}/ConfMakefile )
+
+ endif()
+
+endif()
diff --git a/Tests/FindPackageModeMakefileTest/FindFoo.cmake.in b/Tests/FindPackageModeMakefileTest/FindFoo.cmake.in
new file mode 100644
index 0000000000..dc62bac416
--- /dev/null
+++ b/Tests/FindPackageModeMakefileTest/FindFoo.cmake.in
@@ -0,0 +1,9 @@
+
+find_library(FOO_LIBRARY NAMES foo HINTS "@CMAKE_CURRENT_BINARY_DIR@" )
+find_path(FOO_INCLUDE_DIR NAMES foo.h HINTS "@CMAKE_CURRENT_SOURCE_DIR@" )
+
+set(FOO_LIBRARIES ${FOO_LIBRARY})
+set(FOO_INCLUDE_DIRS "${FOO_INCLUDE_DIR}" "/some/path/with a space/include" )
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Foo DEFAULT_MSG FOO_LIBRARY FOO_INCLUDE_DIR )
diff --git a/Tests/FindPackageModeMakefileTest/Makefile.in b/Tests/FindPackageModeMakefileTest/Makefile.in
new file mode 100644
index 0000000000..e4df9d6461
--- /dev/null
+++ b/Tests/FindPackageModeMakefileTest/Makefile.in
@@ -0,0 +1,31 @@
+
+include cmakeExecutable.mk
+
+CMAKE_CURRENT_BINARY_DIR = "@CMAKE_CURRENT_BINARY_DIR@"
+CMAKE_CXX_COMPILER = "@CMAKE_CXX_COMPILER@"
+CMAKE_CXX_COMPILER_ID = "@CMAKE_CXX_COMPILER_ID@"
+
+CMAKE_FOO = $(CMAKE) --find-package -DCMAKE_MODULE_PATH=$(CMAKE_CURRENT_BINARY_DIR) -DNAME=Foo -DLANGUAGE=CXX -DCOMPILER_ID=$(CMAKE_CXX_COMPILER_ID)
+
+tmp = tmp.txt
+
+all: pngtest
+
+main.o: clean main.cpp
+ @$(CMAKE_FOO) -DMODE=COMPILE >$(tmp)
+ @foo="`cat $(tmp)`"; \
+ printf '"%s" %s %s -c main.cpp\n' $(CMAKE_CXX_COMPILER) "$(CXXFLAGS)" "$$foo" >$(tmp)
+ @cat $(tmp)
+ @sh $(tmp)
+ @rm -f $(tmp)
+
+pngtest: main.o
+ @$(CMAKE_FOO) -DMODE=LINK >$(tmp)
+ @foo="`cat $(tmp)`"; \
+ printf '"%s" %s %s -o pngtest main.o %s\n' $(CMAKE_CXX_COMPILER) "$(CXXFLAGS)" "$(LDFLAGS)" "$$foo" >$(tmp)
+ @cat $(tmp)
+ @sh $(tmp)
+ @rm -f $(tmp)
+
+clean:
+ rm -f $(tmp) *.o pngtest
diff --git a/Tests/FindPackageModeMakefileTest/foo.cpp b/Tests/FindPackageModeMakefileTest/foo.cpp
new file mode 100644
index 0000000000..6aea22629a
--- /dev/null
+++ b/Tests/FindPackageModeMakefileTest/foo.cpp
@@ -0,0 +1,4 @@
+int foo()
+{
+ return 1477;
+}
diff --git a/Tests/FindPackageModeMakefileTest/foo.h b/Tests/FindPackageModeMakefileTest/foo.h
new file mode 100644
index 0000000000..4ec598ad51
--- /dev/null
+++ b/Tests/FindPackageModeMakefileTest/foo.h
@@ -0,0 +1,6 @@
+#ifndef FOO_H
+#define FOO_H
+
+int foo();
+
+#endif
diff --git a/Tests/FindPackageModeMakefileTest/main.cpp b/Tests/FindPackageModeMakefileTest/main.cpp
new file mode 100644
index 0000000000..e5f9134ce9
--- /dev/null
+++ b/Tests/FindPackageModeMakefileTest/main.cpp
@@ -0,0 +1,8 @@
+#include <stdio.h>
+#include <foo.h>
+
+int main()
+{
+ printf("foo is: %d\n", foo());
+ return 0;
+}
diff --git a/Tests/FindPackageTest/A/wibble-config.cmake b/Tests/FindPackageTest/A/wibble-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/A/wibble-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/B/wibble-config.cmake b/Tests/FindPackageTest/B/wibble-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/B/wibble-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/Baz 1.1/BazConfig.cmake b/Tests/FindPackageTest/Baz 1.1/BazConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/Baz 1.1/BazConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/Baz 1.1/BazConfigVersion.cmake b/Tests/FindPackageTest/Baz 1.1/BazConfigVersion.cmake
new file mode 100644
index 0000000000..979bbdf18c
--- /dev/null
+++ b/Tests/FindPackageTest/Baz 1.1/BazConfigVersion.cmake
@@ -0,0 +1,8 @@
+set(PACKAGE_VERSION 1.1)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 1)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+ if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 1)
+ set(PACKAGE_VERSION_EXACT 1)
+ endif()
+endif()
+
diff --git a/Tests/FindPackageTest/Baz 1.2/CMake/BazConfig.cmake b/Tests/FindPackageTest/Baz 1.2/CMake/BazConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/Baz 1.2/CMake/BazConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/Baz 1.2/CMake/BazConfigVersion.cmake b/Tests/FindPackageTest/Baz 1.2/CMake/BazConfigVersion.cmake
new file mode 100644
index 0000000000..17caaa7280
--- /dev/null
+++ b/Tests/FindPackageTest/Baz 1.2/CMake/BazConfigVersion.cmake
@@ -0,0 +1,8 @@
+set(PACKAGE_VERSION 1.2)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 1)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+ if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 2)
+ set(PACKAGE_VERSION_EXACT 1)
+ endif()
+endif()
+
diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt
new file mode 100644
index 0000000000..f311fb9dd0
--- /dev/null
+++ b/Tests/FindPackageTest/CMakeLists.txt
@@ -0,0 +1,618 @@
+cmake_minimum_required (VERSION 2.6)
+project(FindPackageTest)
+
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
+
+# Look for a package which uses FindPackageHandleStandardArgs.cmake with the
+# new (as of cmake 2.8.3) syntax. This works only if CMP0017 is set to NEW,
+# because otherwise FindPackageHandleStandardArgs.cmake from the current
+# directory is included (via CMAKE_MODULE_PATH).
+cmake_policy(SET CMP0017 NEW)
+find_package(ZLIB QUIET)
+
+# Look for a package that has a find module and may be found.
+find_package(OpenGL QUIET)
+
+# Look for a package that has no find module and will not be found.
+find_package(NotAPackage QUIET)
+
+# Look for a package that has an advanced find module.
+find_package(VTK QUIET)
+
+add_executable(FindPackageTest FindPackageTest.cxx)
+
+# test behaviour of cmFindBase wrt. the CMAKE_PREFIX_PATH variable
+# foo.h should be found in ${CMAKE_CURRENT_SOURCE_DIR}/include:
+
+set(CMAKE_PREFIX_PATH /blub /blah "${CMAKE_CURRENT_SOURCE_DIR}")
+find_path(FOO_DIR foo.h)
+
+if(NOT FOO_DIR)
+ message(FATAL_ERROR "Did not find foo.h which is in ${CMAKE_CURRENT_SOURCE_DIR}/include
+ CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}")
+endif()
+
+find_package(VersionTestA 1)
+find_package(VersionTestB 1.2)
+find_package(VersionTestC 1.2.3)
+find_package(VersionTestD 1.2.3.4)
+
+
+find_package(LotsOfComponents COMPONENTS AComp OPTIONAL_COMPONENTS BComp CComp)
+if(NOT LOTSOFCOMPONENTS_FOUND)
+ message(SEND_ERROR "LotsOfComponents not found !")
+endif()
+
+find_package(SomePackage)
+if(NOT SomePackage_FOUND)
+ message(SEND_ERROR "SomePackage with FOUND_VAR SomePackage_FOUND not found !")
+endif()
+
+find_package(UpperCasePackage)
+if(NOT UPPERCASEPACKAGE_FOUND)
+ message(SEND_ERROR "UpperCasePackage with FOUND_VAR UPPERCASEPACKAGE_FOUND not found !")
+endif()
+
+#-----------------------------------------------------------------------------
+# Test system package registry if possible.
+set(CMakeTestSystemPackage "")
+if(WIN32 AND NOT CYGWIN)
+ # Try writing a value to the system package registry.
+ set(_data "${FindPackageTest_SOURCE_DIR}/SystemPackage")
+ set(_key "HKLM\\Software\\Kitware\\CMake\\Packages\\CMakeTestSystemPackage")
+ set(_file "${FindPackageTest_BINARY_DIR}/CMakeTestSystemPackage.data")
+ file(WRITE ${_file} "${_data}\n")
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E md5sum ${_file}
+ OUTPUT_VARIABLE _output ERROR_VARIABLE _error RESULT_VARIABLE _failed
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ string(REGEX REPLACE " .*" "" _value "${_output}")
+ if(NOT _failed AND _value)
+ execute_process(
+ COMMAND reg add "${_key}" /v "${_value}" /t REG_SZ /d "${_data}" /f
+ OUTPUT_VARIABLE _output ERROR_VARIABLE _output RESULT_VARIABLE _failed
+ )
+ endif()
+ # If the above worked, add the rest of the test and a rule to
+ # cleanup the value.
+ if(NOT _failed)
+ message(STATUS "HKLM is writable: enabling CMakeTestSystemPackage")
+ set(CMakeTestSystemPackage_CLEANUP reg delete "${_key}" /v "${_value}" /f)
+ set(CMakeTestSystemPackage CMakeTestSystemPackage)
+ else()
+ message(STATUS "HKLM is readonly: disabling CMakeTestSystemPackage")
+ endif()
+endif()
+
+#-----------------------------------------------------------------------------
+
+#set(CMAKE_FIND_DEBUG_MODE 1)
+
+# For purposes of the test wipe out previous find results.
+set(PACKAGES
+ foo Foo Bar Blub TFramework Tframework TApp Tapp Special
+ VersionedA VersionedB VersionedC VersionedD VersionedE
+ WrongA WrongB WrongC WrongD
+ wibbleA wibbleB
+ RecursiveA RecursiveB RecursiveC
+ ArchA ArchB ArchC ArchD
+ EnvA EnvB
+ SetFoundTRUE SetFoundFALSE
+ ${CMakeTestSystemPackage}
+ )
+foreach(p ${PACKAGES})
+ set(${p}_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
+endforeach()
+
+# Enable framework and bundle searching. Make sure bundles are found
+# before unix-syle packages.
+set(CMAKE_FIND_FRAMEWORK LAST)
+set(CMAKE_FIND_APPBUNDLE FIRST)
+
+# Set the wrong answer for a find to make sure it re-finds.
+set(VersionedA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/cmake/zot-4.0)
+
+# Test that CMAKE_IGNORE_PATH can ignore the purposely bad package
+# files in the lib/cmake/zot-3.1 directory.
+set(CMAKE_IGNORE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib/cmake/zot-3.1)
+
+# Look for packages with new-style signatures.
+find_package(foo NO_MODULE)
+find_package(Foo CONFIGS FooConfig.cmake)
+find_package(Bar)
+set(CMAKE_DISABLE_FIND_PACKAGE_Blub TRUE)
+find_package(Blub NO_MODULE)
+find_package(TFramework CONFIGS TFrameworkConfig.cmake)
+find_package(Tframework)
+find_package(TApp)
+find_package(Tapp CONFIGS tapp-config.cmake)
+find_package(Special NAMES Suffix SuffixTest PATH_SUFFIXES test)
+find_package(VersionedA 2 NAMES zot)
+find_package(VersionedB 3.1 EXACT NAMES zot)
+find_package(VersionedC 4.0 EXACT NAMES zot)
+find_package(VersionedD 1.1 EXACT NAMES Baz)
+find_package(VersionedE 1.2 EXACT NAMES Baz)
+
+# Test Config files which set Xyz_FOUND themselves:
+find_package(SetFoundTRUE NO_MODULE)
+find_package(SetFoundFALSE NO_MODULE)
+
+# Test wrong initial path when result is present.
+set(WrongA_DIR "${VersionedD_DIR}")
+find_package(WrongA 1.2 EXACT NAMES Baz)
+
+# Test wrong initial cache entry of UNINITIALIZED type when result is present.
+set(WrongB_DIR "${VersionedD_DIR}" CACHE UNINITIALIZED "Wrong Value" FORCE)
+get_property(type CACHE WrongB_DIR PROPERTY TYPE)
+find_package(WrongB 1.2 EXACT NAMES Baz)
+
+# Test wrong initial path when result is missing.
+set(WrongC_DIR "${VersionedD_DIR}")
+find_package(WrongC 1.3 EXACT QUIET NAMES Baz)
+
+# Test wrong initial cache entry of UNINITIALIZED type when result is missing.
+set(WrongD_DIR "${VersionedD_DIR}" CACHE UNINITIALIZED "Wrong Value" FORCE)
+get_property(type CACHE WrongD_DIR PROPERTY TYPE)
+find_package(WrongD 1.3 EXACT QUIET NAMES Baz)
+
+# HINTS should override the system but PATHS should not
+list(INSERT CMAKE_SYSTEM_PREFIX_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/A")
+find_package(wibbleA NAMES wibble PATHS B)
+find_package(wibbleB NAMES wibble HINTS B)
+
+# Look for package with recursive find-modules.
+find_package(RecursiveA COMPONENTS A)
+find_package(RecursiveB 2)
+find_package(RecursiveC 3.1 EXACT)
+
+# Test architecture-specific search directories.
+set(CMAKE_LIBRARY_ARCHITECTURE arch)
+find_package(ArchA NAMES Bar)
+find_package(ArchB NAMES Foo CONFIGS FooConfig.cmake)
+find_package(ArchC 3.1 EXACT NAMES zot)
+find_package(ArchD 4.0 EXACT NAMES zot)
+unset(CMAKE_LIBRARY_ARCHITECTURE)
+
+# Test <Package>_DIR environment variable.
+# We erase the main prefix path to ensure the env var is used.
+set(CMAKE_PREFIX_PATH)
+set(ENV{EnvA_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/lib/zot-3.1")
+find_package(EnvA 3.1 EXACT QUIET NAMES zot) # Should Work
+find_package(EnvB 3.1 EXACT QUIET NAMES zot) # Should Fail
+
+# Test system package registry if available.
+if(CMakeTestSystemPackage)
+ find_package(CMakeTestSystemPackage)
+ execute_process(COMMAND ${CMakeTestSystemPackage_CLEANUP}
+ OUTPUT_VARIABLE _output ERROR_VARIABLE _error)
+endif()
+
+# Expected locations at which packages should be found.
+set(foo_EXPECTED "lib/foo-1.2/foo-config.cmake")
+set(Foo_EXPECTED "lib/foo-1.2/CMake/FooConfig.cmake")
+set(Bar_EXPECTED "lib/Bar/BarConfig.cmake")
+set(Blub_MISSING "")
+set(Special_EXPECTED "lib/suffix/test/SuffixTestConfig.cmake")
+set(TFramework_EXPECTED
+ "TFramework.framework/Versions/A/Resources/CMake/TFrameworkConfig.cmake")
+set(Tframework_EXPECTED
+ "TFramework.framework/Versions/A/Resources/tframework-config.cmake")
+set(TApp_EXPECTED
+ "TApp.app/Contents/Resources/TAppConfig.cmake")
+set(Tapp_EXPECTED
+ "TApp.app/Contents/Resources/cmake/tapp-config.cmake")
+set(VersionedA_EXPECTED "lib/zot-2.0/zot-config.cmake")
+set(VersionedB_EXPECTED "lib/zot-3.1/zot-config.cmake")
+set(VersionedC_EXPECTED "lib/cmake/zot-4.0/zot-config.cmake")
+set(VersionedD_EXPECTED "Baz 1.1/BazConfig.cmake")
+set(VersionedE_EXPECTED "Baz 1.2/CMake/BazConfig.cmake")
+set(WrongA_EXPECTED "${VersionedE_EXPECTED}")
+set(WrongB_EXPECTED "${VersionedE_EXPECTED}")
+set(WrongC_MISSING "WrongC_DIR-NOTFOUND")
+set(WrongD_MISSING "WrongD_DIR-NOTFOUND")
+set(wibbleA_EXPECTED "A/wibble-config.cmake")
+set(wibbleB_EXPECTED "B/wibble-config.cmake")
+set(RecursiveA_EXPECTED "lib/RecursiveA/recursivea-config.cmake")
+set(RecursiveB_EXPECTED "lib/zot-2.0/zot-config.cmake")
+set(RecursiveC_EXPECTED "lib/zot-3.1/zot-config.cmake")
+set(ArchA_EXPECTED "lib/arch/Bar/BarConfig.cmake")
+set(ArchB_EXPECTED "lib/arch/foo-1.2/CMake/FooConfig.cmake")
+set(ArchC_EXPECTED "lib/arch/zot-3.1/zot-config.cmake")
+set(ArchD_EXPECTED "lib/arch/cmake/zot-4.0/zot-config.cmake")
+set(EnvA_EXPECTED "lib/zot-3.1/zot-config.cmake")
+set(EnvB_MISSING "EnvB_DIR-NOTFOUND")
+set(SetFoundTRUE_EXPECTED "cmake/SetFoundTRUEConfig.cmake")
+set(SetFoundFALSE_MISSING "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+set(CMakeTestSystemPackage_EXPECTED "SystemPackage/CMakeTestSystemPackageConfig.cmake")
+
+# Check the results.
+foreach(p ${PACKAGES})
+ if(DEFINED ${p}_MISSING)
+ # Check and report failure.
+ if(NOT "${${p}_DIR}" STREQUAL "${${p}_MISSING}")
+ message(SEND_ERROR
+ "Package ${p} should have been [${${p}_MISSING}] but "
+ "was [${${p}_DIR}]")
+ endif()
+ if(${p}_FOUND)
+ message(SEND_ERROR
+ "Package ${p} should not have been found, but ${p}_FOUND is set to "
+ "\"${${p}_FOUND}\"")
+ endif()
+ elseif(${p}_FOUND)
+ # Convert to relative path for comparison to expected location.
+ file(RELATIVE_PATH REL_${p}_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}"
+ "${${p}_CONFIG}")
+
+ # Debugging output.
+ if(CMAKE_FIND_DEBUG_MODE)
+ message("Package ${p} found [${REL_${p}_CONFIG}]")
+ endif()
+
+ # Check and report failure.
+ if(NOT "${REL_${p}_CONFIG}" STREQUAL "${${p}_EXPECTED}")
+ message(SEND_ERROR
+ "Package ${p} should have been [${${p}_EXPECTED}] but "
+ "was [${REL_${p}_CONFIG}]")
+ endif()
+ else()
+ message(SEND_ERROR "Package ${p} not found!")
+ endif()
+endforeach()
+
+# Check that version information was extracted.
+if(NOT "${VersionedA_VERSION}" STREQUAL "2.0")
+ message(SEND_ERROR
+ "Package VersionedA is version [${VersionedA_VERSION}], not [2.0]")
+endif()
+if(NOT "${VersionedA_VERSION_MAJOR}" STREQUAL "2")
+ message(SEND_ERROR
+ "Package VersionedA is major version [${VersionedA_VERSION_MAJOR}], not [2]")
+endif()
+if(NOT "${VersionedA_VERSION_MINOR}" STREQUAL "0")
+ message(SEND_ERROR
+ "Package VersionedA is minor version [${VersionedA_VERSION_MINOR}], not [0]")
+endif()
+
+if(NOT "${VersionedB_VERSION}" STREQUAL "3.1")
+ message(SEND_ERROR
+ "Package VersionedB is version [${VersionedB_VERSION}], not [3.1]")
+endif()
+if(NOT "${VersionedB_VERSION_MAJOR}" STREQUAL "3")
+ message(SEND_ERROR
+ "Package VersionedB is major version [${VersionedB_VERSION_MAJOR}], not [3]")
+endif()
+if(NOT "${VersionedB_VERSION_MINOR}" STREQUAL "1")
+ message(SEND_ERROR
+ "Package VersionedB is minor version [${VersionedB_VERSION_MINOR}], not [1]")
+endif()
+
+if(NOT "${Special_VERSION}" STREQUAL "1.2")
+ message(SEND_ERROR
+ "Package Special is version [${Special_VERSION}], not [1.2]")
+endif()
+if(NOT "${Special_VERSION_MAJOR}" STREQUAL "1")
+ message(SEND_ERROR
+ "Package Special is major version [${Special_VERSION_MAJOR}], not [1]")
+endif()
+if(NOT "${Special_VERSION_MINOR}" STREQUAL "2")
+ message(SEND_ERROR
+ "Package Special is minor version [${Special_VERSION_MINOR}], not [2]")
+endif()
+
+# Test version number comparison.
+if(NOT "1.2.3.4" VERSION_LESS "1.2.3.5")
+ message(SEND_ERROR "1.2.3.4 VERSION_LESS 1.2.3.5 is not true!")
+endif()
+if(NOT "1.2" VERSION_LESS "1.10")
+ message(SEND_ERROR "1.2 VERSION_LESS 1.10 is not true!")
+endif()
+if(NOT "1.02" VERSION_GREATER "1.1")
+ message(SEND_ERROR "1.02 VERSION_GREATER 1.1 is not true!")
+endif()
+if("1.2.3" VERSION_GREATER "1.2.3.4")
+ message(SEND_ERROR "1.2.3 VERSION_GREATER 1.2.3.4 is not false!")
+endif()
+if(NOT "1.2" VERSION_EQUAL "1.2.0.0")
+ message(SEND_ERROR "1.2 VERSION_EQUAL 1.2.0.0 is not true!")
+endif()
+
+#-----------------------------------------------------------------------------
+# Test export(PACKAGE) with find_package.
+
+# Choose a unique version.
+string(REGEX REPLACE "-.*$" "" version ${CMAKE_VERSION})
+string(RANDOM LENGTH 4 ALPHABET "0123456789" v)
+set(version "${version}.${v}")
+
+message(STATUS "Preparing export(PACKAGE) test project")
+try_compile(EXPORTER_COMPILED
+ ${FindPackageTest_BINARY_DIR}/Exporter-build
+ ${FindPackageTest_SOURCE_DIR}/Exporter
+ CMakeTestExportPackage dummy
+ CMAKE_FLAGS "-UCMAKE_EXPORT_NO_PACKAGE_REGISTRY"
+ -Dversion=${version}
+ OUTPUT_VARIABLE output)
+message(STATUS "Searching for export(PACKAGE) test project")
+set(CMakeTestExportPackage_DIR "" CACHE FILEPATH
+ "Wipe out find results for testing." FORCE)
+find_package(CMakeTestExportPackage 1.${version} EXACT REQUIRED)
+
+message(STATUS "Searching for export(PACKAGE) test project with CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=TRUE")
+set(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY TRUE)
+set(CMakeTestExportPackage_DIR "" CACHE FILEPATH
+ "Wipe out find results for testing." FORCE)
+find_package(CMakeTestExportPackage 1.${version} EXACT QUIET)
+if(CMakeTestExportPackage_FOUND)
+ message(SEND_ERROR "CMakeTestExportPackage should not be FOUND!")
+endif()
+unset(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY)
+
+message(STATUS "Remove export(PACKAGE) test project")
+file(REMOVE_RECURSE ${FindPackageTest_BINARY_DIR}/Exporter-build)
+set(CMakeTestExportPackage_DIR "" CACHE FILEPATH
+ "Wipe out find results for testing." FORCE)
+find_package(CMakeTestExportPackage QUIET) # Should clean the user package cache
+#
+message(STATUS "Preparing export(PACKAGE) test project with CMAKE_EXPORT_NO_PACKAGE_REGISTRY=TRUE")
+try_compile(EXPORTER_COMPILED
+ ${FindPackageTest_BINARY_DIR}/Exporter-build
+ ${FindPackageTest_SOURCE_DIR}/Exporter
+ CMakeTestExportPackage dummy
+ CMAKE_FLAGS "-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY:BOOL=TRUE"
+ -Dversion=${version}
+ OUTPUT_VARIABLE output)
+message(STATUS "Searching for export(PACKAGE) test project")
+find_package(CMakeTestExportPackage 1.${version} EXACT QUIET)
+if(CMakeTestExportPackage_FOUND)
+ message(SEND_ERROR "CMakeTestExportPackage should not be FOUND!")
+endif()
+
+#-----------------------------------------------------------------------------
+# Test configure_package_config_file().
+
+include(CMakePackageConfigHelpers)
+
+# Generate a config file ready to be installed.
+set(INCLUDE_INSTALL_DIR include )
+set(SHARE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/" )
+set(CURRENT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}" )
+
+configure_package_config_file(RelocatableConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/RelocatableConfig.cmake"
+ INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}"
+ PATH_VARS INCLUDE_INSTALL_DIR SHARE_INSTALL_DIR CURRENT_BUILD_DIR
+ )
+
+set(Relocatable_FIND_COMPONENTS AComp BComp CComp)
+set(Relocatable_FIND_REQUIRED_BComp 1)
+include("${CMAKE_CURRENT_BINARY_DIR}/RelocatableConfig.cmake")
+
+if(NOT "${RELOC_INCLUDE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/include")
+ message(SEND_ERROR "RELOC_INCLUDE_DIR set by configure_package_config_file() is set to \"${RELOC_INCLUDE_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}/include\")")
+endif()
+
+if(NOT "${RELOC_SHARE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/share/")
+ message(SEND_ERROR "RELOC_SHARE_DIR set by configure_package_config_file() is set to \"${RELOC_SHARE_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}/share/\")")
+endif()
+
+if(NOT "${RELOC_BUILD_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
+ message(SEND_ERROR "RELOC_BUILD_DIR set by configure_package_config_file() is set to \"${RELOC_BUILD_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}\")")
+endif()
+
+if(NOT DEFINED Relocatable_FOUND)
+ message(SEND_ERROR "Relocatable_FOUND not defined !")
+endif()
+
+if(Relocatable_FOUND)
+ message(SEND_ERROR "Relocatable_FOUND set to TRUE !")
+endif()
+
+# Generate a config file for the build tree.
+set(INCLUDE_INSTALL_DIR include )
+set(SHARE_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/share/" )
+set(CURRENT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}" )
+
+configure_package_config_file(RelocatableConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/RelocatableConfig.cmake"
+ INSTALL_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
+ PATH_VARS INCLUDE_INSTALL_DIR SHARE_INSTALL_DIR CURRENT_BUILD_DIR
+ INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}"
+ )
+
+set(Relocatable_FIND_COMPONENTS AComp BComp CComp)
+set(Relocatable_FIND_REQUIRED_BComp 1)
+include("${CMAKE_CURRENT_BINARY_DIR}/RelocatableConfig.cmake")
+
+if(NOT "${RELOC_INCLUDE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/include")
+ message(SEND_ERROR "RELOC_INCLUDE_DIR set by configure_package_config_file() is set to \"${RELOC_INCLUDE_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}/include\")")
+endif()
+
+if(NOT "${RELOC_SHARE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/share/")
+ message(SEND_ERROR "RELOC_SHARE_DIR set by configure_package_config_file() is set to \"${RELOC_SHARE_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}/share/\")")
+endif()
+
+if(NOT "${RELOC_BUILD_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
+ message(SEND_ERROR "RELOC_BUILD_DIR set by configure_package_config_file() is set to \"${RELOC_BUILD_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}\")")
+endif()
+
+if(NOT DEFINED Relocatable_FOUND)
+ message(SEND_ERROR "Relocatable_FOUND not defined !")
+endif()
+
+if(Relocatable_FOUND)
+ message(SEND_ERROR "Relocatable_FOUND set to TRUE !")
+endif()
+
+
+
+#-----------------------------------------------------------------------------
+# Test write_basic_config_version_file().
+
+# also test that an empty CMAKE_SIZEOF_VOID_P is accepted:
+set(_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
+set(CMAKE_SIZEOF_VOID_P "")
+
+write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/Foo123ConfigVersion.cmake
+ VERSION 1.2.3
+ COMPATIBILITY AnyNewerVersion)
+
+set(CMAKE_SIZEOF_VOID_P ${_CMAKE_SIZEOF_VOID_P})
+
+set(PACKAGE_FIND_VERSION 2.3.4)
+include(${CMAKE_CURRENT_BINARY_DIR}/Foo123ConfigVersion.cmake)
+if(PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Found Foo123 with version 1.2.3, but 2.3.4 was requested !")
+endif()
+
+set(PACKAGE_FIND_VERSION 0.0.1)
+include(${CMAKE_CURRENT_BINARY_DIR}/Foo123ConfigVersion.cmake)
+if(NOT PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Did not find Foo123 with version 1.2.3 (0.0.1 was requested) !")
+endif()
+
+if(PACKAGE_VERSION_UNSUITABLE)
+ message(SEND_ERROR "PACKAGE_VERSION_UNSUITABLE set, but must not be !")
+endif()
+
+set(PACKAGE_FIND_VERSION 1.0.0)
+include(${CMAKE_CURRENT_BINARY_DIR}/Foo123ConfigVersion.cmake)
+if(NOT PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Did not find Foo123 with version 1.2.3 (1.0.0 was requested) !")
+endif()
+if(PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+endif()
+
+set(PACKAGE_FIND_VERSION 1.2.3)
+include(${CMAKE_CURRENT_BINARY_DIR}/Foo123ConfigVersion.cmake)
+if(NOT PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Did not find Foo123 with version 1.2.3 (1.2.3 was requested) !")
+endif()
+if(NOT PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT not set, although it should be !")
+endif()
+
+
+#######################
+include(WriteBasicConfigVersionFile)
+
+write_basic_config_version_file(${CMAKE_CURRENT_BINARY_DIR}/Boo123ConfigVersion.cmake
+ VERSION 1.2.3
+ COMPATIBILITY SameMajorVersion)
+
+unset(PACKAGE_VERSION_UNSUITABLE)
+set(PACKAGE_VERSION_EXACT FALSE)
+set(PACKAGE_FIND_VERSION 2.3.4)
+set(PACKAGE_FIND_VERSION_MAJOR 2)
+include(${CMAKE_CURRENT_BINARY_DIR}/Boo123ConfigVersion.cmake)
+if(PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Found Boo123 with version 1.2.3, but 2.3.4 was requested !")
+endif()
+if(PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+endif()
+
+set(PACKAGE_FIND_VERSION 0.0.1)
+set(PACKAGE_FIND_VERSION_MAJOR 0)
+include(${CMAKE_CURRENT_BINARY_DIR}/Boo123ConfigVersion.cmake)
+if(PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Found Boo123 with version 1.2.3, but 0.0.1 was requested !")
+endif()
+if(PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+endif()
+
+set(PACKAGE_FIND_VERSION 1.0.0)
+set(PACKAGE_FIND_VERSION_MAJOR 1)
+include(${CMAKE_CURRENT_BINARY_DIR}/Boo123ConfigVersion.cmake)
+if(NOT PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Did not find Boo123 with version 1.2.3 (1.0.0 was requested) !")
+endif()
+if(PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+endif()
+
+set(PACKAGE_FIND_VERSION 1.2.3)
+set(PACKAGE_FIND_VERSION_MAJOR 1)
+include(${CMAKE_CURRENT_BINARY_DIR}/Boo123ConfigVersion.cmake)
+if(NOT PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Did not find Boo123 with version 1.2.3 (1.2.3 was requested) !")
+endif()
+if(NOT PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT not set, although it should be !")
+endif()
+
+if(PACKAGE_VERSION_UNSUITABLE)
+ message(SEND_ERROR "PACKAGE_VERSION_UNSUITABLE set, but must not be !")
+endif()
+
+#######################
+
+write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake
+ VERSION 1.2.3.17
+ COMPATIBILITY ExactVersion)
+
+unset(PACKAGE_VERSION_UNSUITABLE)
+set(PACKAGE_VERSION_EXACT FALSE)
+set(PACKAGE_FIND_VERSION 2.3.4)
+include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake)
+if(PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Found Bar123 with version 1.2.3 (2.3.4 was requested) !")
+endif()
+if(PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+endif()
+
+set(PACKAGE_FIND_VERSION 1.2)
+include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake)
+if(PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Found Bar123 with version 1.2.3 (1.2 was requested) !")
+endif()
+if(PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+endif()
+
+set(PACKAGE_FIND_VERSION 1)
+include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake)
+if(PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Found Bar123 with version 1.2.3 (1 was requested) !")
+endif()
+if(PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+endif()
+
+set(PACKAGE_FIND_VERSION 1.2.3.4)
+include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake)
+if(NOT PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Did not find Bar123 with version 1.2.3 (1.2.3.4 was requested) !")
+endif()
+if(PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+endif()
+
+set(PACKAGE_FIND_VERSION 1.2.3)
+set(PACKAGE_VERSION_EXACT FALSE)
+set(PACKAGE_VERSION_COMPATIBLE FALSE)
+include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake)
+if(NOT PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Did not find Bar123 with version 1.2.3 (1.2.3 was requested) !")
+endif()
+if(PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+endif()
+
+
+set(PACKAGE_FIND_VERSION 1.2.3.17)
+set(PACKAGE_VERSION_EXACT FALSE)
+set(PACKAGE_VERSION_COMPATIBLE FALSE)
+include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake)
+if(NOT PACKAGE_VERSION_COMPATIBLE)
+ message(SEND_ERROR "Did not find Bar123 with version 1.2.3 (1.2.3.17 was requested) !")
+endif()
+if(NOT PACKAGE_VERSION_EXACT)
+ message(SEND_ERROR "PACKAGE_VERSION_EXACT not set, although it should be !")
+endif()
+
+if(PACKAGE_VERSION_UNSUITABLE)
+ message(SEND_ERROR "PACKAGE_VERSION_UNSUITABLE set, but must not be !")
+endif()
diff --git a/Tests/FindPackageTest/Exporter/CMakeLists.txt b/Tests/FindPackageTest/Exporter/CMakeLists.txt
new file mode 100644
index 0000000000..d25a2e74c6
--- /dev/null
+++ b/Tests/FindPackageTest/Exporter/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.7.20090831)
+project(CMakeTestExportPackage C)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeTestExportPackageConfig.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestExportPackageConfig.cmake
+ @ONLY)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeTestExportPackageConfigVersion.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestExportPackageConfigVersion.cmake
+ @ONLY)
+export(PACKAGE CMakeTestExportPackage)
+
+add_executable(dummy dummy.c)
diff --git a/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfig.cmake.in b/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfig.cmake.in
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfig.cmake.in
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfigVersion.cmake.in b/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfigVersion.cmake.in
new file mode 100644
index 0000000000..6eac6e6728
--- /dev/null
+++ b/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfigVersion.cmake.in
@@ -0,0 +1,6 @@
+# Test config file.
+set(PACKAGE_VERSION "1.@version@")
+if("${PACKAGE_FIND_VERSION}" VERSION_EQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+ set(PACKAGE_VERSION_EXACT 1)
+endif()
diff --git a/Tests/FindPackageTest/Exporter/dummy.c b/Tests/FindPackageTest/Exporter/dummy.c
new file mode 100644
index 0000000000..76e8197013
--- /dev/null
+++ b/Tests/FindPackageTest/Exporter/dummy.c
@@ -0,0 +1 @@
+int main() { return 0; }
diff --git a/Tests/FindPackageTest/FindLotsOfComponents.cmake b/Tests/FindPackageTest/FindLotsOfComponents.cmake
new file mode 100644
index 0000000000..5d959c5949
--- /dev/null
+++ b/Tests/FindPackageTest/FindLotsOfComponents.cmake
@@ -0,0 +1,10 @@
+set(LOC_FOO TRUE)
+
+set(LotsOfComponents_AComp_FOUND TRUE)
+set(LotsOfComponents_BComp_FOUND FALSE)
+set(LotsOfComponents_CComp_FOUND TRUE)
+
+include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
+
+find_package_handle_standard_args(LotsOfComponents REQUIRED_VARS LOC_FOO
+ HANDLE_COMPONENTS)
diff --git a/Tests/FindPackageTest/FindPackageHandleStandardArgs.cmake b/Tests/FindPackageTest/FindPackageHandleStandardArgs.cmake
new file mode 100644
index 0000000000..7e41c96c9f
--- /dev/null
+++ b/Tests/FindPackageTest/FindPackageHandleStandardArgs.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "This file (${CMAKE_CURRENT_LIST_FILE}) must not be included, but FindPackageHandleStandardArgs.cmake from Modules/ instead !")
diff --git a/Tests/FindPackageTest/FindPackageTest.cxx b/Tests/FindPackageTest/FindPackageTest.cxx
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/FindPackageTest/FindPackageTest.cxx
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/FindPackageTest/FindRecursiveA.cmake b/Tests/FindPackageTest/FindRecursiveA.cmake
new file mode 100644
index 0000000000..a6d25dc4be
--- /dev/null
+++ b/Tests/FindPackageTest/FindRecursiveA.cmake
@@ -0,0 +1 @@
+find_package(RecursiveA NO_MODULE)
diff --git a/Tests/FindPackageTest/FindRecursiveB.cmake b/Tests/FindPackageTest/FindRecursiveB.cmake
new file mode 100644
index 0000000000..9e28f2ce9e
--- /dev/null
+++ b/Tests/FindPackageTest/FindRecursiveB.cmake
@@ -0,0 +1 @@
+find_package(RecursiveB NAMES zot)
diff --git a/Tests/FindPackageTest/FindRecursiveC.cmake b/Tests/FindPackageTest/FindRecursiveC.cmake
new file mode 100644
index 0000000000..cd4400ca00
--- /dev/null
+++ b/Tests/FindPackageTest/FindRecursiveC.cmake
@@ -0,0 +1 @@
+find_package(RecursiveC NAMES zot)
diff --git a/Tests/FindPackageTest/FindSomePackage.cmake b/Tests/FindPackageTest/FindSomePackage.cmake
new file mode 100644
index 0000000000..7283d247e2
--- /dev/null
+++ b/Tests/FindPackageTest/FindSomePackage.cmake
@@ -0,0 +1,6 @@
+set(SOP_FOO TRUE)
+
+include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
+
+find_package_handle_standard_args(SomePackage REQUIRED_VARS SOP_FOO
+ FOUND_VAR SomePackage_FOUND )
diff --git a/Tests/FindPackageTest/FindUpperCasePackage.cmake b/Tests/FindPackageTest/FindUpperCasePackage.cmake
new file mode 100644
index 0000000000..425d41769a
--- /dev/null
+++ b/Tests/FindPackageTest/FindUpperCasePackage.cmake
@@ -0,0 +1,6 @@
+set(UCP_FOO TRUE)
+
+include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
+
+find_package_handle_standard_args(UpperCasePackage REQUIRED_VARS UCP_FOO
+ FOUND_VAR UPPERCASEPACKAGE_FOUND )
diff --git a/Tests/FindPackageTest/FindVersionTestA.cmake b/Tests/FindPackageTest/FindVersionTestA.cmake
new file mode 100644
index 0000000000..9828593828
--- /dev/null
+++ b/Tests/FindPackageTest/FindVersionTestA.cmake
@@ -0,0 +1,18 @@
+if(NOT "${VersionTestA_FIND_VERSION}" STREQUAL "1")
+ message(SEND_ERROR "VersionTestA_FIND_VERSION=${VersionTestA_FIND_VERSION} is not 1")
+endif()
+if(NOT "${VersionTestA_FIND_VERSION_MAJOR}" STREQUAL "1")
+ message(SEND_ERROR "VersionTestA_FIND_VERSION_MAJOR=${VersionTestA_FIND_VERSION_MAJOR} is not 1")
+endif()
+if(NOT "${VersionTestA_FIND_VERSION_MINOR}" STREQUAL "0")
+ message(SEND_ERROR "VersionTestA_FIND_VERSION_MINOR=${VersionTestA_FIND_VERSION_MINOR} is not 0")
+endif()
+if(NOT "${VersionTestA_FIND_VERSION_PATCH}" STREQUAL "0")
+ message(SEND_ERROR "VersionTestA_FIND_VERSION_PATCH=${VersionTestA_FIND_VERSION_PATCH} is not 0")
+endif()
+if(NOT "${VersionTestA_FIND_VERSION_TWEAK}" STREQUAL "0")
+ message(SEND_ERROR "VersionTestA_FIND_VERSION_TWEAK=${VersionTestA_FIND_VERSION_TWEAK} is not 0")
+endif()
+if(NOT "${VersionTestA_FIND_VERSION_COUNT}" STREQUAL "1")
+ message(SEND_ERROR "VersionTestA_FIND_VERSION_COUNT=${VersionTestA_FIND_VERSION_COUNT} is not 1")
+endif()
diff --git a/Tests/FindPackageTest/FindVersionTestB.cmake b/Tests/FindPackageTest/FindVersionTestB.cmake
new file mode 100644
index 0000000000..1ebb82302a
--- /dev/null
+++ b/Tests/FindPackageTest/FindVersionTestB.cmake
@@ -0,0 +1,18 @@
+if(NOT "${VersionTestB_FIND_VERSION}" STREQUAL "1.2")
+ message(SEND_ERROR "VersionTestB_FIND_VERSION=${VersionTestB_FIND_VERSION} is not 1.2")
+endif()
+if(NOT "${VersionTestB_FIND_VERSION_MAJOR}" STREQUAL "1")
+ message(SEND_ERROR "VersionTestB_FIND_VERSION_MAJOR=${VersionTestB_FIND_VERSION_MAJOR} is not 1")
+endif()
+if(NOT "${VersionTestB_FIND_VERSION_MINOR}" STREQUAL "2")
+ message(SEND_ERROR "VersionTestB_FIND_VERSION_MINOR=${VersionTestB_FIND_VERSION_MINOR} is not 2")
+endif()
+if(NOT "${VersionTestB_FIND_VERSION_PATCH}" STREQUAL "0")
+ message(SEND_ERROR "VersionTestB_FIND_VERSION_PATCH=${VersionTestB_FIND_VERSION_PATCH} is not 0")
+endif()
+if(NOT "${VersionTestB_FIND_VERSION_TWEAK}" STREQUAL "0")
+ message(SEND_ERROR "VersionTestB_FIND_VERSION_TWEAK=${VersionTestB_FIND_VERSION_TWEAK} is not 0")
+endif()
+if(NOT "${VersionTestB_FIND_VERSION_COUNT}" STREQUAL "2")
+ message(SEND_ERROR "VersionTestB_FIND_VERSION_COUNT=${VersionTestB_FIND_VERSION_COUNT} is not 2")
+endif()
diff --git a/Tests/FindPackageTest/FindVersionTestC.cmake b/Tests/FindPackageTest/FindVersionTestC.cmake
new file mode 100644
index 0000000000..450c2e9147
--- /dev/null
+++ b/Tests/FindPackageTest/FindVersionTestC.cmake
@@ -0,0 +1,18 @@
+if(NOT "${VersionTestC_FIND_VERSION}" STREQUAL "1.2.3")
+ message(SEND_ERROR "VersionTestC_FIND_VERSION=${VersionTestC_FIND_VERSION} is not 1.2.3")
+endif()
+if(NOT "${VersionTestC_FIND_VERSION_MAJOR}" STREQUAL "1")
+ message(SEND_ERROR "VersionTestC_FIND_VERSION_MAJOR=${VersionTestC_FIND_VERSION_MAJOR} is not 1")
+endif()
+if(NOT "${VersionTestC_FIND_VERSION_MINOR}" STREQUAL "2")
+ message(SEND_ERROR "VersionTestC_FIND_VERSION_MINOR=${VersionTestC_FIND_VERSION_MINOR} is not 2")
+endif()
+if(NOT "${VersionTestC_FIND_VERSION_PATCH}" STREQUAL "3")
+ message(SEND_ERROR "VersionTestC_FIND_VERSION_PATCH=${VersionTestC_FIND_VERSION_PATCH} is not 3")
+endif()
+if(NOT "${VersionTestC_FIND_VERSION_TWEAK}" STREQUAL "0")
+ message(SEND_ERROR "VersionTestC_FIND_VERSION_TWEAK=${VersionTestC_FIND_VERSION_TWEAK} is not 0")
+endif()
+if(NOT "${VersionTestC_FIND_VERSION_COUNT}" STREQUAL "3")
+ message(SEND_ERROR "VersionTestC_FIND_VERSION_COUNT=${VersionTestC_FIND_VERSION_COUNT} is not 3")
+endif()
diff --git a/Tests/FindPackageTest/FindVersionTestD.cmake b/Tests/FindPackageTest/FindVersionTestD.cmake
new file mode 100644
index 0000000000..9f2db72e4f
--- /dev/null
+++ b/Tests/FindPackageTest/FindVersionTestD.cmake
@@ -0,0 +1,18 @@
+if(NOT "${VersionTestD_FIND_VERSION}" STREQUAL "1.2.3.4")
+ message(SEND_ERROR "VersionTestD_FIND_VERSION=${VersionTestD_FIND_VERSION} is not 1.2.3.4")
+endif()
+if(NOT "${VersionTestD_FIND_VERSION_MAJOR}" STREQUAL "1")
+ message(SEND_ERROR "VersionTestD_FIND_VERSION_MAJOR=${VersionTestD_FIND_VERSION_MAJOR} is not 1")
+endif()
+if(NOT "${VersionTestD_FIND_VERSION_MINOR}" STREQUAL "2")
+ message(SEND_ERROR "VersionTestD_FIND_VERSION_MINOR=${VersionTestD_FIND_VERSION_MINOR} is not 2")
+endif()
+if(NOT "${VersionTestD_FIND_VERSION_PATCH}" STREQUAL "3")
+ message(SEND_ERROR "VersionTestD_FIND_VERSION_PATCH=${VersionTestD_FIND_VERSION_PATCH} is not 3")
+endif()
+if(NOT "${VersionTestD_FIND_VERSION_TWEAK}" STREQUAL "4")
+ message(SEND_ERROR "VersionTestD_FIND_VERSION_TWEAK=${VersionTestD_FIND_VERSION_TWEAK} is not 4")
+endif()
+if(NOT "${VersionTestD_FIND_VERSION_COUNT}" STREQUAL "4")
+ message(SEND_ERROR "VersionTestD_FIND_VERSION_COUNT=${VersionTestD_FIND_VERSION_COUNT} is not 4")
+endif()
diff --git a/Tests/FindPackageTest/RelocatableConfig.cmake.in b/Tests/FindPackageTest/RelocatableConfig.cmake.in
new file mode 100644
index 0000000000..4a4b4e9c60
--- /dev/null
+++ b/Tests/FindPackageTest/RelocatableConfig.cmake.in
@@ -0,0 +1,11 @@
+@PACKAGE_INIT@
+
+set(RELOC_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
+set(RELOC_SHARE_DIR "@PACKAGE_SHARE_INSTALL_DIR@")
+set_and_check(RELOC_BUILD_DIR "@PACKAGE_CURRENT_BUILD_DIR@")
+
+set(Relocatable_AComp_FOUND TRUE)
+set(Relocatable_BComp_FOUND FALSE)
+set(Relocatable_CComp_FOUND FALSE)
+
+check_required_components(Relocatable)
diff --git a/Tests/FindPackageTest/SystemPackage/CMakeTestSystemPackageConfig.cmake b/Tests/FindPackageTest/SystemPackage/CMakeTestSystemPackageConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/SystemPackage/CMakeTestSystemPackageConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/TApp.app/Contents/Resources/TAppConfig.cmake b/Tests/FindPackageTest/TApp.app/Contents/Resources/TAppConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/TApp.app/Contents/Resources/TAppConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/TApp.app/Contents/Resources/cmake/tapp-config.cmake b/Tests/FindPackageTest/TApp.app/Contents/Resources/cmake/tapp-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/TApp.app/Contents/Resources/cmake/tapp-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/TFramework.framework/Versions/A/Resources/CMake/TFrameworkConfig.cmake b/Tests/FindPackageTest/TFramework.framework/Versions/A/Resources/CMake/TFrameworkConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/TFramework.framework/Versions/A/Resources/CMake/TFrameworkConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/TFramework.framework/Versions/A/Resources/tframework-config.cmake b/Tests/FindPackageTest/TFramework.framework/Versions/A/Resources/tframework-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/TFramework.framework/Versions/A/Resources/tframework-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/cmake/SetFoundFALSEConfig.cmake b/Tests/FindPackageTest/cmake/SetFoundFALSEConfig.cmake
new file mode 100644
index 0000000000..ae6bd14540
--- /dev/null
+++ b/Tests/FindPackageTest/cmake/SetFoundFALSEConfig.cmake
@@ -0,0 +1 @@
+set(SetFoundFALSE_FOUND FALSE)
diff --git a/Tests/FindPackageTest/cmake/SetFoundTRUEConfig.cmake b/Tests/FindPackageTest/cmake/SetFoundTRUEConfig.cmake
new file mode 100644
index 0000000000..19d071144d
--- /dev/null
+++ b/Tests/FindPackageTest/cmake/SetFoundTRUEConfig.cmake
@@ -0,0 +1 @@
+set(SetFoundTRUE_FOUND TRUE)
diff --git a/Tests/FindPackageTest/include/foo.h b/Tests/FindPackageTest/include/foo.h
new file mode 100644
index 0000000000..2392aee71d
--- /dev/null
+++ b/Tests/FindPackageTest/include/foo.h
@@ -0,0 +1 @@
+/* empty header file */
diff --git a/Tests/FindPackageTest/lib/Bar/BarConfig.cmake b/Tests/FindPackageTest/lib/Bar/BarConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/Bar/BarConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/Bar/cmake/bar-config.cmake b/Tests/FindPackageTest/lib/Bar/cmake/bar-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/Bar/cmake/bar-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/Blub/BlubConfig.cmake b/Tests/FindPackageTest/lib/Blub/BlubConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/Blub/BlubConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/RecursiveA/recursivea-config.cmake b/Tests/FindPackageTest/lib/RecursiveA/recursivea-config.cmake
new file mode 100644
index 0000000000..eff4d4fd06
--- /dev/null
+++ b/Tests/FindPackageTest/lib/RecursiveA/recursivea-config.cmake
@@ -0,0 +1,4 @@
+# Test config file.
+if(NOT "${RecursiveA_FIND_COMPONENTS}" STREQUAL "A")
+ message(FATAL_ERROR "find_package(RecursiveA NO_MODULE) did not forward components")
+endif()
diff --git a/Tests/FindPackageTest/lib/TApp/TAppConfig.cmake b/Tests/FindPackageTest/lib/TApp/TAppConfig.cmake
new file mode 100644
index 0000000000..5ba8d55858
--- /dev/null
+++ b/Tests/FindPackageTest/lib/TApp/TAppConfig.cmake
@@ -0,0 +1,2 @@
+# Test config file that should not be found.
+message("Package TApp found non-bundle first!")
diff --git a/Tests/FindPackageTest/lib/arch/Bar/BarConfig.cmake b/Tests/FindPackageTest/lib/arch/Bar/BarConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/arch/Bar/BarConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/arch/cmake/zot-4.0/zot-config-version.cmake b/Tests/FindPackageTest/lib/arch/cmake/zot-4.0/zot-config-version.cmake
new file mode 100644
index 0000000000..822b449661
--- /dev/null
+++ b/Tests/FindPackageTest/lib/arch/cmake/zot-4.0/zot-config-version.cmake
@@ -0,0 +1,7 @@
+set(PACKAGE_VERSION 4.0)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 4)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+ if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 0)
+ set(PACKAGE_VERSION_EXACT 1)
+ endif()
+endif()
diff --git a/Tests/FindPackageTest/lib/arch/cmake/zot-4.0/zot-config.cmake b/Tests/FindPackageTest/lib/arch/cmake/zot-4.0/zot-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/arch/cmake/zot-4.0/zot-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/arch/foo-1.2/CMake/FooConfig.cmake b/Tests/FindPackageTest/lib/arch/foo-1.2/CMake/FooConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/arch/foo-1.2/CMake/FooConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/arch/zot-3.1/zot-config-version.cmake b/Tests/FindPackageTest/lib/arch/zot-3.1/zot-config-version.cmake
new file mode 100644
index 0000000000..31573b90a0
--- /dev/null
+++ b/Tests/FindPackageTest/lib/arch/zot-3.1/zot-config-version.cmake
@@ -0,0 +1,7 @@
+set(PACKAGE_VERSION 3.1)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 3)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+ if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 1)
+ set(PACKAGE_VERSION_EXACT 1)
+ endif()
+endif()
diff --git a/Tests/FindPackageTest/lib/arch/zot-3.1/zot-config.cmake b/Tests/FindPackageTest/lib/arch/zot-3.1/zot-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/arch/zot-3.1/zot-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/cmake/zot-3.1/zot-config-version.cmake b/Tests/FindPackageTest/lib/cmake/zot-3.1/zot-config-version.cmake
new file mode 100644
index 0000000000..e3e17de7c0
--- /dev/null
+++ b/Tests/FindPackageTest/lib/cmake/zot-3.1/zot-config-version.cmake
@@ -0,0 +1,4 @@
+# Claim to be any version to test that CMAKE_IGNORE_PATH hides us.
+set(PACKAGE_VERSION 3.1)
+set(PACKAGE_VERSION_COMPATIBLE 1)
+set(PACKAGE_VERSION_EXACT 1)
diff --git a/Tests/FindPackageTest/lib/cmake/zot-3.1/zot-config.cmake b/Tests/FindPackageTest/lib/cmake/zot-3.1/zot-config.cmake
new file mode 100644
index 0000000000..2fbd525f3c
--- /dev/null
+++ b/Tests/FindPackageTest/lib/cmake/zot-3.1/zot-config.cmake
@@ -0,0 +1,2 @@
+# Test config file.
+message(WARNING "CMAKE_IGNORE_PATH failed to ignore this file!")
diff --git a/Tests/FindPackageTest/lib/cmake/zot-4.0/zot-config-version.cmake b/Tests/FindPackageTest/lib/cmake/zot-4.0/zot-config-version.cmake
new file mode 100644
index 0000000000..bcefcd746e
--- /dev/null
+++ b/Tests/FindPackageTest/lib/cmake/zot-4.0/zot-config-version.cmake
@@ -0,0 +1,8 @@
+set(PACKAGE_VERSION 4.0)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 4)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+ if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 0)
+ set(PACKAGE_VERSION_EXACT 1)
+ endif()
+endif()
+
diff --git a/Tests/FindPackageTest/lib/cmake/zot-4.0/zot-config.cmake b/Tests/FindPackageTest/lib/cmake/zot-4.0/zot-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/cmake/zot-4.0/zot-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/foo-1.2/CMake/FooConfig.cmake b/Tests/FindPackageTest/lib/foo-1.2/CMake/FooConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/foo-1.2/CMake/FooConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/foo-1.2/foo-config.cmake b/Tests/FindPackageTest/lib/foo-1.2/foo-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/foo-1.2/foo-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/suffix/test/SuffixTestConfig.cmake b/Tests/FindPackageTest/lib/suffix/test/SuffixTestConfig.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/suffix/test/SuffixTestConfig.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/suffix/test/SuffixTestConfigVersion.cmake b/Tests/FindPackageTest/lib/suffix/test/SuffixTestConfigVersion.cmake
new file mode 100644
index 0000000000..b37bc8e223
--- /dev/null
+++ b/Tests/FindPackageTest/lib/suffix/test/SuffixTestConfigVersion.cmake
@@ -0,0 +1,7 @@
+set(PACKAGE_VERSION 1.2)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 1)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+ if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 2)
+ set(PACKAGE_VERSION_EXACT 1)
+ endif()
+endif()
diff --git a/Tests/FindPackageTest/lib/zot-1.0/zot-config.cmake b/Tests/FindPackageTest/lib/zot-1.0/zot-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/zot-1.0/zot-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/zot-2.0/zot-config-version.cmake b/Tests/FindPackageTest/lib/zot-2.0/zot-config-version.cmake
new file mode 100644
index 0000000000..db3a8a40c8
--- /dev/null
+++ b/Tests/FindPackageTest/lib/zot-2.0/zot-config-version.cmake
@@ -0,0 +1,5 @@
+set(PACKAGE_VERSION 2.0)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 2)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+endif()
+
diff --git a/Tests/FindPackageTest/lib/zot-2.0/zot-config.cmake b/Tests/FindPackageTest/lib/zot-2.0/zot-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/zot-2.0/zot-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/zot-3.0/zot-config-version.cmake b/Tests/FindPackageTest/lib/zot-3.0/zot-config-version.cmake
new file mode 100644
index 0000000000..dd9c939c52
--- /dev/null
+++ b/Tests/FindPackageTest/lib/zot-3.0/zot-config-version.cmake
@@ -0,0 +1,5 @@
+set(PACKAGE_VERSION 3.0)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 3)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+endif()
+
diff --git a/Tests/FindPackageTest/lib/zot-3.0/zot-config.cmake b/Tests/FindPackageTest/lib/zot-3.0/zot-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/zot-3.0/zot-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/zot-3.1/zot-config-version.cmake b/Tests/FindPackageTest/lib/zot-3.1/zot-config-version.cmake
new file mode 100644
index 0000000000..8fa767ea10
--- /dev/null
+++ b/Tests/FindPackageTest/lib/zot-3.1/zot-config-version.cmake
@@ -0,0 +1,8 @@
+set(PACKAGE_VERSION 3.1)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 3)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+ if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 1)
+ set(PACKAGE_VERSION_EXACT 1)
+ endif()
+endif()
+
diff --git a/Tests/FindPackageTest/lib/zot-3.1/zot-config.cmake b/Tests/FindPackageTest/lib/zot-3.1/zot-config.cmake
new file mode 100644
index 0000000000..deffa57294
--- /dev/null
+++ b/Tests/FindPackageTest/lib/zot-3.1/zot-config.cmake
@@ -0,0 +1 @@
+# Test config file.
diff --git a/Tests/FindPackageTest/lib/zot/zot-config-version.cmake b/Tests/FindPackageTest/lib/zot/zot-config-version.cmake
new file mode 100644
index 0000000000..430f009e14
--- /dev/null
+++ b/Tests/FindPackageTest/lib/zot/zot-config-version.cmake
@@ -0,0 +1,10 @@
+# This version should never, ever be used.
+set(PACKAGE_VERSION_UNSUITABLE 1)
+set(PACKAGE_VERSION 3.1)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 3)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+ if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 1)
+ set(PACKAGE_VERSION_EXACT 1)
+ endif()
+endif()
+
diff --git a/Tests/FindPackageTest/lib/zot/zot-config.cmake b/Tests/FindPackageTest/lib/zot/zot-config.cmake
new file mode 100644
index 0000000000..9168183604
--- /dev/null
+++ b/Tests/FindPackageTest/lib/zot/zot-config.cmake
@@ -0,0 +1,2 @@
+# Test config file that is unsuitable.
+message(FATAL_ERROR "Unsuitable version of zot was found")
diff --git a/Tests/ForceInclude/CMakeLists.txt b/Tests/ForceInclude/CMakeLists.txt
new file mode 100644
index 0000000000..5c02ebbd09
--- /dev/null
+++ b/Tests/ForceInclude/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8.3.20110103)
+project(ForceInclude C)
+
+# Make sure the proper compiler is in use.
+if(NOT MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")
+ message(FATAL_ERROR "The ForceInclude test works only with MSVC or Intel")
+endif()
+
+add_executable(foo foo.c)
+set_property(SOURCE foo.c PROPERTY COMPILE_FLAGS "/FIfoo1.h /FIfoo2.h")
diff --git a/Tests/ForceInclude/foo.c b/Tests/ForceInclude/foo.c
new file mode 100644
index 0000000000..af898f4aa6
--- /dev/null
+++ b/Tests/ForceInclude/foo.c
@@ -0,0 +1,7 @@
+#ifndef FOO_1
+# error "foo1.h not included by /FI"
+#endif
+#ifndef FOO_2
+# error "foo2.h not included by /FI"
+#endif
+int main(void) { return 0; }
diff --git a/Tests/ForceInclude/foo1.h b/Tests/ForceInclude/foo1.h
new file mode 100644
index 0000000000..2c1cb7bb3c
--- /dev/null
+++ b/Tests/ForceInclude/foo1.h
@@ -0,0 +1 @@
+#define FOO_1
diff --git a/Tests/ForceInclude/foo2.h b/Tests/ForceInclude/foo2.h
new file mode 100644
index 0000000000..e47524dfae
--- /dev/null
+++ b/Tests/ForceInclude/foo2.h
@@ -0,0 +1 @@
+#define FOO_2
diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt
new file mode 100644
index 0000000000..1982a6025f
--- /dev/null
+++ b/Tests/Fortran/CMakeLists.txt
@@ -0,0 +1,227 @@
+cmake_minimum_required (VERSION 3.0)
+project(testf C CXX Fortran)
+if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
+endif()
+
+message("CTEST_FULL_OUTPUT ")
+set(CMAKE_VERBOSE_MAKEFILE 1)
+message("ENV_FLAGS = $ENV{FFLAGS}")
+message("CMAKE_Fortran_COMPILER_INIT = ${CMAKE_Fortran_COMPILER_INIT}")
+message("CMAKE_Fortran_COMPILER_FULLPATH = ${CMAKE_Fortran_COMPILER_FULLPATH}")
+message("CMAKE_Fortran_COMPILER = ${CMAKE_Fortran_COMPILER}")
+message("CMAKE_Fortran_FLAGS = ${CMAKE_Fortran_FLAGS}")
+
+set(_SHARED SHARED)
+if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "^(XL|VisualAge)$")
+ # We do not implement SHARED Fortran libs on AIX yet!
+ # Workaround: Set LINKER_LANGUAGE to C, which uses 'xlc' and Fortran implicits.
+ set(_SHARED STATIC)
+elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU")
+ # g77 2.96 does not support shared libs on Itanium because g2c is not -fPIC
+ execute_process(COMMAND ${CMAKE_Fortran_COMPILER} --version
+ OUTPUT_VARIABLE output ERROR_VARIABLE output)
+ if("${output}" MATCHES "Red Hat .* 2\\.96")
+ set(_SHARED STATIC)
+ endif()
+endif()
+
+# Pick a module .def file with the properly mangled symbol name.
+set(world_def "")
+if(WIN32 AND NOT CYGWIN)
+ if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
+ set(world_def world_gnu.def)
+ elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel" OR
+ "${CMAKE_GENERATOR}" MATCHES "Visual Studio") # Intel plugin
+ set(world_def world_icl.def)
+ endif()
+endif()
+
+add_library(hello STATIC hello.f)
+add_library(world ${_SHARED} world.f ${world_def})
+add_executable(testf testf.f)
+target_link_libraries(testf hello world)
+
+function(test_fortran_c_interface_module)
+ message(STATUS "Testing FortranCInterface module")
+ # test the C to Fortran interface module
+ include(FortranCInterface)
+ FortranCInterface_VERIFY()
+ FortranCInterface_VERIFY(CXX)
+ if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
+ if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|MIPSpro|PathScale|Absoft")
+ set(module_expected 1)
+ endif()
+ if(FortranCInterface_MODULE_FOUND OR module_expected)
+ set(srcs foo.f)
+ set(FORTRAN_FUNCTIONS test_mod:sub)
+ set(MYC_DEFS TEST_MOD)
+ else()
+ message("${CMAKE_Fortran_COMPILER_ID} compilers do not support"
+ " linking Fortran module procedures from C")
+ endif()
+ endif()
+ list(APPEND FORTRAN_FUNCTIONS my_sub mysub)
+ FortranCInterface_HEADER(foo.h
+ MACRO_NAMESPACE "FC_"
+ SYMBOL_NAMESPACE "F_"
+ SYMBOLS ${FORTRAN_FUNCTIONS}
+ )
+ include_directories("${testf_BINARY_DIR}")
+
+ # if the name mangling is not found for a F90 compiler
+ # print out some diagnostic stuff for the dashboard
+ if(NOT FortranCInterface_GLOBAL_FOUND OR
+ (NOT FortranCInterface_MODULE_FOUND AND module_expected) )
+ find_program(FortranCInterface_EXE
+ NAMES FortranCInterface
+ PATHS ${FortranCInterface_BINARY_DIR} ${FortranCInterface_BINARY_DIR}/Debug
+ NO_DEFAULT_PATH
+ )
+ find_program(DUMPBIN dumpbin)
+ find_program(NM nm)
+ if(FortranCInterface_EXE)
+ if(DEPENDS)
+ execute_process(COMMAND ${DUMPBIN} /symbols "${FortranCInterface_EXE}"
+ OUTPUT_VARIABLE out)
+ message("symbols in ${FortranCInterface_EXE}:\n${out}")
+ endif()
+ if(NM)
+ execute_process(COMMAND ${NM} "${FortranCInterface_EXE}"
+ OUTPUT_VARIABLE out)
+ message("symbols in ${FortranCInterface_EXE}:\n${out}")
+ endif()
+ endif()
+ endif()
+ message("Fortran = ${CMAKE_Fortran_COMPILER_ID}")
+ message("C = ${CMAKE_C_COMPILER_ID}")
+
+ add_library(myfort mysub.f ${srcs})
+
+ add_library(myc myc.c)
+ target_link_libraries(myc myfort)
+ set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS})
+
+ add_library(mycxx mycxx.cxx)
+ target_link_libraries(mycxx myc)
+
+ add_executable(mainc mainc.c)
+ target_link_libraries(mainc myc)
+ add_executable(maincxx maincxx.c)
+ target_link_libraries(maincxx mycxx)
+
+ # print out some stuff to help debug on machines via cdash
+ file(READ "${testf_BINARY_DIR}/foo.h" fooh)
+ message("foo.h contents:\n${fooh}")
+endfunction()
+
+# if the id's match or the compilers are compatible, then
+# call the test_fortran_c_interface_module function
+if("${CMAKE_Fortran_COMPILER_ID}:${CMAKE_C_COMPILER_ID}" MATCHES
+ "(Intel:MSVC|Absoft:GNU)"
+ OR ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "${CMAKE_C_COMPILER_ID}" ))
+ test_fortran_c_interface_module()
+else()
+ message("Fortran does not match c compiler")
+ message("Fortran = ${CMAKE_Fortran_COMPILER_ID}")
+ message("C = ${CMAKE_C_COMPILER_ID}")
+ # hack to make g77 work after CL has been enabled
+ # as a languge, cmake needs language specific versions
+ # of these variables....
+ if(WIN32 AND "${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
+ set(CMAKE_CREATE_CONSOLE_EXE )
+ set(CMAKE_LIBRARY_PATH_FLAG "-L")
+ set(CMAKE_LINK_LIBRARY_FLAG "-l")
+ set(CMAKE_LINK_LIBRARY_SUFFIX )
+ endif()
+ # gnu and sunpro do not use the same flags here...
+ # however if LDFLAGS is used to set -m64 it causes odd stuf
+ # with the fortran build
+ if( ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU")
+ AND ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "SunPro"))
+ set(CMAKE_EXE_LINKER_FLAGS "")
+ set(CMAKE_Fortran_FLAGS "")
+ endif()
+
+endif()
+
+
+
+
+set(TEST_MODULE_DEPENDS 0)
+if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
+ add_executable(test_module
+ test_module_main.f90
+ test_module_implementation.f90
+ test_module_interface.f90)
+
+ add_executable(test_use_in_comment_fixedform
+ test_use_in_comment_fixedform.f)
+ set_property(SOURCE test_use_in_comment_fixedform.f PROPERTY Fortran_FORMAT FIXED)
+ add_executable(test_use_in_comment_freeform
+ test_use_in_comment_freeform.f90)
+ set_property(SOURCE test_use_in_comment_freeform.f90 PROPERTY Fortran_FORMAT FREE)
+
+ add_executable(test_in_interface
+ in_interface/main.f90
+ in_interface/module.f90)
+
+ add_definitions(-DFOO -DBAR=1)
+ include_directories(${testf_SOURCE_DIR}/include)
+ add_executable(test_preprocess test_preprocess.F90)
+
+ set(TEST_MODULE_DEPENDS 1)
+endif()
+
+if(TEST_MODULE_DEPENDS)
+ # Build the external project separately using a custom target.
+ # Make sure it uses the same build configuration as this test.
+ if(CMAKE_CONFIGURATION_TYPES)
+ set(External_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
+ set(External_BUILD_TYPE)
+ else()
+ set(External_CONFIG_TYPE)
+ set(External_BUILD_TYPE -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE})
+ endif()
+ set(External_SOURCE_DIR "${testf_SOURCE_DIR}/External")
+ set(External_BINARY_DIR "${testf_BINARY_DIR}/External")
+ if("${testf_BINARY_DIR}" MATCHES " ")
+ # Our build tree has a space, so the build tool supports spaces.
+ # Test using modules from a path with spaces.
+ set(External_BINARY_DIR "${External_BINARY_DIR} Build")
+ endif()
+ add_custom_command(
+ OUTPUT ${testf_BINARY_DIR}/ExternalProject
+ COMMAND ${CMAKE_CTEST_COMMAND}
+ ARGS ${External_CONFIG_TYPE}
+ --build-and-test
+ ${External_SOURCE_DIR}
+ ${External_BINARY_DIR}
+ --build-noclean
+ --build-two-config
+ --build-project ExtFort
+ --build-generator ${CMAKE_GENERATOR}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-options -DCMAKE_Fortran_COMPILER:STRING=${CMAKE_Fortran_COMPILER}
+ -DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}
+ -DCMAKE_Fortran_FLAGS_DEBUG:STRING=${CMAKE_Fortran_FLAGS_DEBUG}
+ -DCMAKE_Fortran_FLAGS_RELEASE:STRING=${CMAKE_Fortran_FLAGS_RELEASE}
+ -DCMAKE_Fortran_FLAGS_MINSIZEREL:STRING=${CMAKE_Fortran_FLAGS_MINSIZEREL}
+ -DCMAKE_Fortran_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}
+ -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_NESTED_MAKE_PROGRAM}
+ ${External_BUILD_TYPE}
+ VERBATIM
+ )
+ add_custom_target(ExternalTarget ALL DEPENDS ${testf_BINARY_DIR}/ExternalProject)
+
+ # Test module output directory if available.
+ if(CMAKE_Fortran_MODDIR_FLAG)
+ set(Library_MODDIR "${testf_BINARY_DIR}/Library/modules")
+ else()
+ set(Library_MODDIR "${testf_BINARY_DIR}/Library")
+ endif()
+
+ add_subdirectory(Library)
+ add_subdirectory(Executable)
+endif()
diff --git a/Tests/Fortran/Executable/CMakeLists.txt b/Tests/Fortran/Executable/CMakeLists.txt
new file mode 100644
index 0000000000..55f21ad462
--- /dev/null
+++ b/Tests/Fortran/Executable/CMakeLists.txt
@@ -0,0 +1,8 @@
+include_directories(${Library_MODDIR})
+include_directories(${External_BINARY_DIR})
+link_directories(${External_BINARY_DIR})
+
+add_executable(subdir_exe2 main.f90)
+target_link_libraries(subdir_exe2 subdir_mods)
+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
new file mode 100644
index 0000000000..f21156cda7
--- /dev/null
+++ b/Tests/Fortran/Executable/main.f90
@@ -0,0 +1,6 @@
+PROGRAM MAINF90
+ USE libraryModuleA
+ USE libraryModuleB
+ USE externalMod
+ CALL printExtModGreeting
+END PROGRAM MAINF90
diff --git a/Tests/Fortran/External/CMakeLists.txt b/Tests/Fortran/External/CMakeLists.txt
new file mode 100644
index 0000000000..0eb1cfeed9
--- /dev/null
+++ b/Tests/Fortran/External/CMakeLists.txt
@@ -0,0 +1,4 @@
+project(ExtFort Fortran)
+
+add_library(myext a.f90)
+
diff --git a/Tests/Fortran/External/a.f90 b/Tests/Fortran/External/a.f90
new file mode 100644
index 0000000000..2be73c53c9
--- /dev/null
+++ b/Tests/Fortran/External/a.f90
@@ -0,0 +1,7 @@
+MODULE externalMod
+!
+CONTAINS
+ SUBROUTINE printExtModGreeting
+ WRITE(*,*) "Greetings from Module externalMod"
+ END SUBROUTINE
+END MODULE
diff --git a/Tests/Fortran/Library/CMakeLists.txt b/Tests/Fortran/Library/CMakeLists.txt
new file mode 100644
index 0000000000..17438cafbb
--- /dev/null
+++ b/Tests/Fortran/Library/CMakeLists.txt
@@ -0,0 +1,11 @@
+include_directories(${Library_MODDIR})
+add_library(subdir_mods a.f90 b.f90)
+add_executable(subdir_exe main.f90)
+target_link_libraries(subdir_exe subdir_mods)
+
+# Test module output directory if available.
+if(CMAKE_Fortran_MODDIR_FLAG)
+ set_target_properties(subdir_mods PROPERTIES
+ Fortran_MODULE_DIRECTORY modules
+ )
+endif()
diff --git a/Tests/Fortran/Library/a.f90 b/Tests/Fortran/Library/a.f90
new file mode 100644
index 0000000000..3031c07237
--- /dev/null
+++ b/Tests/Fortran/Library/a.f90
@@ -0,0 +1,3 @@
+MODULE libraryModuleA
+ USE libraryModuleB
+END MODULE
diff --git a/Tests/Fortran/Library/b.f90 b/Tests/Fortran/Library/b.f90
new file mode 100644
index 0000000000..ae1edcb20d
--- /dev/null
+++ b/Tests/Fortran/Library/b.f90
@@ -0,0 +1,2 @@
+MODULE libraryModuleB
+END MODULE
diff --git a/Tests/Fortran/Library/main.f90 b/Tests/Fortran/Library/main.f90
new file mode 100644
index 0000000000..2385408a28
--- /dev/null
+++ b/Tests/Fortran/Library/main.f90
@@ -0,0 +1,3 @@
+PROGRAM MAINF90
+ USE libraryModuleA
+END PROGRAM MAINF90
diff --git a/Tests/Fortran/foo.f b/Tests/Fortran/foo.f
new file mode 100644
index 0000000000..ece0df44ce
--- /dev/null
+++ b/Tests/Fortran/foo.f
@@ -0,0 +1,9 @@
+ module test_mod
+ interface dummy
+ module procedure sub
+ end interface
+ contains
+ subroutine sub
+ end subroutine
+
+ end module test_mod
diff --git a/Tests/Fortran/hello.f b/Tests/Fortran/hello.f
new file mode 100644
index 0000000000..aa0de77150
--- /dev/null
+++ b/Tests/Fortran/hello.f
@@ -0,0 +1,6 @@
+ SUBROUTINE HELLO
+
+ PRINT *, 'Hello'
+
+ END
+
diff --git a/Tests/Fortran/in_interface/main.f90 b/Tests/Fortran/in_interface/main.f90
new file mode 100644
index 0000000000..28bcf36d5c
--- /dev/null
+++ b/Tests/Fortran/in_interface/main.f90
@@ -0,0 +1,3 @@
+program hello
+ use test_interface
+end program hello
diff --git a/Tests/Fortran/in_interface/module.f90 b/Tests/Fortran/in_interface/module.f90
new file mode 100644
index 0000000000..1064d74b0f
--- /dev/null
+++ b/Tests/Fortran/in_interface/module.f90
@@ -0,0 +1,12 @@
+module test_interface
+
+ interface dummy
+ module procedure module_function
+ end interface
+
+contains
+
+ subroutine module_function
+ end subroutine
+
+end module test_interface \ No newline at end of file
diff --git a/Tests/Fortran/include/test_preprocess.h b/Tests/Fortran/include/test_preprocess.h
new file mode 100644
index 0000000000..29ac4b65fe
--- /dev/null
+++ b/Tests/Fortran/include/test_preprocess.h
@@ -0,0 +1,5 @@
+#ifdef BAR
+ PRINT * , 'BAR was defined via ADD_DEFINITIONS'
+#else
+ PRINT *, 'If you can read this something went wrong'
+#endif
diff --git a/Tests/Fortran/mainc.c b/Tests/Fortran/mainc.c
new file mode 100644
index 0000000000..9efafc5c00
--- /dev/null
+++ b/Tests/Fortran/mainc.c
@@ -0,0 +1,5 @@
+extern int myc(void);
+int main()
+{
+ return myc();
+}
diff --git a/Tests/Fortran/maincxx.c b/Tests/Fortran/maincxx.c
new file mode 100644
index 0000000000..d35ea7e25a
--- /dev/null
+++ b/Tests/Fortran/maincxx.c
@@ -0,0 +1,6 @@
+extern int myc(void);
+extern int mycxx(void);
+int main()
+{
+ return myc() + mycxx();
+}
diff --git a/Tests/Fortran/myc.c b/Tests/Fortran/myc.c
new file mode 100644
index 0000000000..efd9b68aa5
--- /dev/null
+++ b/Tests/Fortran/myc.c
@@ -0,0 +1,12 @@
+#include "foo.h"
+extern F_test_mod_sub(void);
+extern F_mysub(void);
+int myc(void)
+{
+ F_mysub();
+ F_my_sub();
+#ifdef TEST_MOD
+ F_test_mod_sub();
+#endif
+ return 0;
+}
diff --git a/Tests/Fortran/mycxx.cxx b/Tests/Fortran/mycxx.cxx
new file mode 100644
index 0000000000..bf04062ed5
--- /dev/null
+++ b/Tests/Fortran/mycxx.cxx
@@ -0,0 +1,6 @@
+extern "C" int myc(void);
+extern "C" int mycxx(void)
+{
+ delete new int;
+ return myc();
+}
diff --git a/Tests/Fortran/mysub.f b/Tests/Fortran/mysub.f
new file mode 100644
index 0000000000..4b108e333c
--- /dev/null
+++ b/Tests/Fortran/mysub.f
@@ -0,0 +1,5 @@
+ subroutine mysub
+ print *, 'Printing this requires fortran language libraries'
+ end subroutine
+ subroutine my_sub
+ end subroutine
diff --git a/Tests/Fortran/test_module_implementation.f90 b/Tests/Fortran/test_module_implementation.f90
new file mode 100644
index 0000000000..de3cb574c1
--- /dev/null
+++ b/Tests/Fortran/test_module_implementation.f90
@@ -0,0 +1,6 @@
+FUNCTION TEST_MODULE_FUNCTION(A,B)
+ REAL :: TEST_MODULE_FUNCTION
+ REAL, INTENT(IN) :: A
+ REAL, INTENT(IN) :: B
+ TEST_MODULE_FUNCTION = A + B
+END FUNCTION TEST_MODULE_FUNCTION
diff --git a/Tests/Fortran/test_module_interface.f90 b/Tests/Fortran/test_module_interface.f90
new file mode 100644
index 0000000000..dd0f35c56e
--- /dev/null
+++ b/Tests/Fortran/test_module_interface.f90
@@ -0,0 +1,9 @@
+MODULE TEST_MODULE
+ INTERFACE
+ FUNCTION TEST_MODULE_FUNCTION(A,B)
+ REAL :: TEST_MODULE_FUNCTION
+ REAL, INTENT(IN) :: A
+ REAL, INTENT(IN) :: B
+ END FUNCTION TEST_MODULE_FUNCTION
+ END INTERFACE
+END MODULE TEST_MODULE
diff --git a/Tests/Fortran/test_module_main.f90 b/Tests/Fortran/test_module_main.f90
new file mode 100644
index 0000000000..6ac97fa914
--- /dev/null
+++ b/Tests/Fortran/test_module_main.f90
@@ -0,0 +1,4 @@
+PROGRAM MAINF90
+ USE TEST_MODULE
+ PRINT *,'Sum is',TEST_MODULE_FUNCTION(1., 2.)
+END PROGRAM MAINF90
diff --git a/Tests/Fortran/test_preprocess.F90 b/Tests/Fortran/test_preprocess.F90
new file mode 100644
index 0000000000..e4f1fbe768
--- /dev/null
+++ b/Tests/Fortran/test_preprocess.F90
@@ -0,0 +1,51 @@
+MODULE Available
+! no conent
+END MODULE
+
+PROGRAM PPTEST
+! value of InPPFalseBranch ; values of SkipToEnd
+! 0 <empty>
+#ifndef FOO
+ ! 1 ; <0>
+ USE NotAvailable
+# ifndef FOO
+ ! 2 ; <0,0>
+ USE NotAvailable
+# else
+ ! 2 ; <0,0>
+ USE NotAvailable
+# endif
+ ! 1 ; <0>
+# ifdef FOO
+ ! 2 ; <0,1>
+ USE NotAvailable
+# else
+ ! 2 ; <0,1>
+ USE NotAvailable
+# endif
+ ! 1 ; <0>
+#else
+ ! 0 ; <0>
+ USE Available
+# ifndef FOO
+ ! 1 ; <0,0>
+ USE NotAvailable
+# else
+ ! 0 ; <0,0>
+ USE Available
+# endif
+ ! 0 ; <0>
+# ifdef FOO
+ ! 0 ; <0,1>
+ USE Available
+# else
+ ! 1 ; <0,1>
+ USE NotAvailable
+# endif
+ ! 0 ; <0>
+#endif
+! 0 ; <empty>
+
+#include "test_preprocess.h"
+
+END PROGRAM
diff --git a/Tests/Fortran/test_use_in_comment_fixedform.f b/Tests/Fortran/test_use_in_comment_fixedform.f
new file mode 100644
index 0000000000..39f486bf9b
--- /dev/null
+++ b/Tests/Fortran/test_use_in_comment_fixedform.f
@@ -0,0 +1,7 @@
+ PROGRAM foo
+! USE bar
+! use bar
+! Use bar
+
+ WRITE(*,*) 'Hello, Fortran world.'
+ END PROGRAM
diff --git a/Tests/Fortran/test_use_in_comment_freeform.f90 b/Tests/Fortran/test_use_in_comment_freeform.f90
new file mode 100644
index 0000000000..48bcd5a210
--- /dev/null
+++ b/Tests/Fortran/test_use_in_comment_freeform.f90
@@ -0,0 +1,7 @@
+PROGRAM foo
+! USE bar
+! use bar
+! Use bar
+
+ WRITE(*,*) 'Hello, Fortran world.'
+END PROGRAM
diff --git a/Tests/Fortran/testf.f b/Tests/Fortran/testf.f
new file mode 100644
index 0000000000..abf6c6df7d
--- /dev/null
+++ b/Tests/Fortran/testf.f
@@ -0,0 +1,7 @@
+ PROGRAM TESTF
+
+ CALL HELLO()
+ CALL WORLD()
+
+ END
+
diff --git a/Tests/Fortran/world.f b/Tests/Fortran/world.f
new file mode 100644
index 0000000000..0487dffe46
--- /dev/null
+++ b/Tests/Fortran/world.f
@@ -0,0 +1,6 @@
+ SUBROUTINE WORLD
+
+ PRINT *, 'World!'
+
+ END
+
diff --git a/Tests/Fortran/world_gnu.def b/Tests/Fortran/world_gnu.def
new file mode 100644
index 0000000000..161779877a
--- /dev/null
+++ b/Tests/Fortran/world_gnu.def
@@ -0,0 +1,2 @@
+EXPORTS
+ world_
diff --git a/Tests/Fortran/world_icl.def b/Tests/Fortran/world_icl.def
new file mode 100644
index 0000000000..ead7710cd7
--- /dev/null
+++ b/Tests/Fortran/world_icl.def
@@ -0,0 +1,2 @@
+EXPORTS
+ WORLD
diff --git a/Tests/FortranC/CMakeLists.txt b/Tests/FortranC/CMakeLists.txt
new file mode 100644
index 0000000000..f335583976
--- /dev/null
+++ b/Tests/FortranC/CMakeLists.txt
@@ -0,0 +1,25 @@
+cmake_minimum_required(VERSION 2.8)
+project(FortranC C Fortran)
+
+# Skip this test for compilers not known to be compatible.
+if(NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "${CMAKE_Fortran_COMPILER_ID}" OR
+ "${CMAKE_C_COMPILER_ID}-${CMAKE_Fortran_COMPILER_ID}" MATCHES "^(MSVC-Intel)$"))
+ message(STATUS "${CMAKE_C_COMPILER_ID} C and ${CMAKE_Fortran_COMPILER_ID} Fortran not known to be compatible!")
+ return()
+endif()
+
+# Wipe out all FortranCInterface information to ensure it re-runs.
+file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/CMakeFiles/FortranCInterface)
+
+if(FortranC_TEST_FLAGS)
+ # Test whether FortranCInterface checks see C flags.
+ set(ENV{TEST_OPT_CC} "--test-opt-cc=1")
+ set(CMAKE_C_FLAGS "$ENV{TEST_OPT_CC} ${CMAKE_C_FLAGS}")
+
+ # Test whether FortranCInterface checks see Fortran flags.
+ set(ENV{TEST_OPT_FC} "--test-opt-fc=1")
+ set(CMAKE_Fortran_FLAGS "$ENV{TEST_OPT_FC} ${CMAKE_Fortran_FLAGS}")
+endif()
+
+include(FortranCInterface)
+FortranCInterface_VERIFY()
diff --git a/Tests/FortranC/Flags.cmake.in b/Tests/FortranC/Flags.cmake.in
new file mode 100644
index 0000000000..2300fc61ff
--- /dev/null
+++ b/Tests/FortranC/Flags.cmake.in
@@ -0,0 +1,30 @@
+set(src "@CMAKE_CURRENT_SOURCE_DIR@/FortranC")
+set(bld "@CMAKE_CURRENT_BINARY_DIR@/FortranC/Flags")
+
+# Create wrapper scripts for the compilers that check for expected
+# flags, remove them, and invoke the real compiler.
+set(ID "CC")
+set(COMMAND "@CMAKE_C_COMPILER@")
+configure_file("${src}/test_opt.sh.in" "${bld}/cc.sh" @ONLY)
+set(ID "FC")
+set(COMMAND "@CMAKE_Fortran_COMPILER@")
+configure_file("${src}/test_opt.sh.in" "${bld}/fc.sh" @ONLY)
+set(ID)
+set(COMMAND)
+
+execute_process(
+ WORKING_DIRECTORY "${bld}"
+ COMMAND ${CMAKE_COMMAND} "${src}" -G "@CMAKE_GENERATOR@"
+ -A "@CMAKE_GENERATOR_PLATFORM@"
+ -T "@CMAKE_GENERATOR_TOOLSET@"
+ "-DFortranC_TEST_FLAGS=1"
+ "-DCMAKE_C_COMPILER=${bld}/cc.sh"
+ "-DCMAKE_C_FLAGS:STRING=@CMAKE_C_FLAGS@"
+ "-DCMAKE_Fortran_COMPILER=${bld}/fc.sh"
+ "-DCMAKE_Fortran_FLAGS:STRING=@CMAKE_Fortran_FLAGS@"
+ RESULT_VARIABLE result
+ )
+
+if(NOT "${result}" STREQUAL "0")
+ message(FATAL_ERROR "Configuration failed: ${result}")
+endif()
diff --git a/Tests/FortranC/test_opt.sh.in b/Tests/FortranC/test_opt.sh.in
new file mode 100755
index 0000000000..f3d93dcf19
--- /dev/null
+++ b/Tests/FortranC/test_opt.sh.in
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+TEST_OPT_@ID@_FOUND=0
+ARGS=""
+for a in "$@"; do
+ if [ "x${TEST_OPT_@ID@}" != "x" -a "x${TEST_OPT_@ID@}" = "x$a" ]; then
+ TEST_OPT_@ID@_FOUND=1
+ else
+ ARGS="$ARGS \"$a\""
+ fi
+done
+
+if [ "x${TEST_OPT_@ID@}" != "x" -a "x${TEST_OPT_@ID@_FOUND}" != "x1" ]; then
+ echo "Not given option '${TEST_OPT_@ID@}' as expected!"
+ exit 1
+fi
+
+eval "\"@COMMAND@\"" "$ARGS"
diff --git a/Tests/FortranOnly/CMakeLists.txt b/Tests/FortranOnly/CMakeLists.txt
new file mode 100644
index 0000000000..f55e727074
--- /dev/null
+++ b/Tests/FortranOnly/CMakeLists.txt
@@ -0,0 +1,68 @@
+cmake_minimum_required (VERSION 2.8)
+project(FortranOnly Fortran)
+message("CTEST_FULL_OUTPUT ")
+
+# create a library with hello and world functions
+add_library(FortranOnlylib hello.f world.f)
+set_property(TARGET FortranOnlylib PROPERTY Fortran_FORMAT FIXED)
+set_property(SOURCE world.f PROPERTY Fortran_FORMAT FREE)
+
+# create an executable that calls hello and world
+add_executable(FortranOnly1 testf.f)
+set_property(TARGET FortranOnly1 PROPERTY OUTPUT_NAME FortranOnly)
+target_link_libraries(FortranOnly1 FortranOnlylib)
+
+# create a custom command that runs FortranOnly1 and puts
+# the output into the file testfhello.txt
+add_custom_command(OUTPUT ${FortranOnly_BINARY_DIR}/testfhello.txt
+ COMMAND FortranOnly1
+ > testfhello.txt)
+# create a second executable FortranOnly2 that has
+# testfhello.txt has an source file so that it will
+# run the above custom command.
+add_executable(FortranOnly2 testfhello.txt testf.f)
+target_link_libraries(FortranOnly2 FortranOnlylib)
+# create a custom target to check the content of testfhello.txt
+# by running the cmake script checktestf2.cmake
+add_custom_target(checktestf2 ALL
+ COMMAND ${CMAKE_COMMAND}
+ -P ${FortranOnly_SOURCE_DIR}/checktestf2.cmake)
+
+# create a custom target that runs FortranOnly1 exectuable and creates
+# a file out.txt that should have hello world in it.
+add_custom_target(sayhello ALL
+ COMMAND FortranOnly1 > out.txt
+)
+# make sure stuff is built in the right order
+add_dependencies(checktestf2 FortranOnly2)
+add_dependencies(sayhello FortranOnly1)
+add_dependencies(FortranOnly2 FortranOnly1)
+
+# add a custom target that checkes that out.txt has the correct
+# content
+add_custom_target(checksayhello ALL
+ COMMAND ${CMAKE_COMMAND} -P ${FortranOnly_SOURCE_DIR}/checksayhello.cmake
+ )
+add_dependencies(checksayhello sayhello)
+
+# Exclude this test on IBM XL for now because the check strangely
+# fails with 'ld: 0706-029 Use a number with the -H flag'.
+if(NOT CMAKE_Fortran_COMPILER_ID STREQUAL XL)
+ set(err_log ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log)
+ file(REMOVE "${err_log}")
+ include(CheckFortranSourceCompiles)
+ unset(HAVE_PRINT CACHE)
+ CHECK_Fortran_SOURCE_COMPILES([[
+ PROGRAM TEST_HAVE_PRINT
+ PRINT *, 'Hello'
+ END
+]] HAVE_PRINT)
+ if(NOT HAVE_PRINT)
+ if(EXISTS "${err_log}")
+ file(READ "${err_log}" err)
+ endif()
+ string(REPLACE "\n" "\n " err " ${err}")
+ message(SEND_ERROR "CHECK_Fortran_SOURCE_COMPILES for HAVE_PRINT failed:\n"
+ "${err}")
+ endif()
+endif()
diff --git a/Tests/FortranOnly/checksayhello.cmake b/Tests/FortranOnly/checksayhello.cmake
new file mode 100644
index 0000000000..5352290ab5
--- /dev/null
+++ b/Tests/FortranOnly/checksayhello.cmake
@@ -0,0 +1,7 @@
+file(READ out.txt IN)
+message("${IN}")
+if(IN MATCHES Hello AND IN MATCHES World)
+ message("Passed")
+else()
+ message(FATAL_ERROR "Hello world not found")
+endif()
diff --git a/Tests/FortranOnly/checktestf2.cmake b/Tests/FortranOnly/checktestf2.cmake
new file mode 100644
index 0000000000..f0e6be3291
--- /dev/null
+++ b/Tests/FortranOnly/checktestf2.cmake
@@ -0,0 +1,8 @@
+file(READ testfhello.txt IN)
+message("${IN}")
+if(IN MATCHES Hello AND IN MATCHES World)
+ message("Passed")
+else()
+ message(FATAL_ERROR "Hello world not found")
+endif()
+file(WRITE testfhello2.txt ${IN})
diff --git a/Tests/FortranOnly/hello.f b/Tests/FortranOnly/hello.f
new file mode 100644
index 0000000000..63e64080de
--- /dev/null
+++ b/Tests/FortranOnly/hello.f
@@ -0,0 +1,5 @@
+ SUBROUTINE HELLO
+
+ PRINT *, 'Hello'
+
+ END
diff --git a/Tests/FortranOnly/testf.f b/Tests/FortranOnly/testf.f
new file mode 100644
index 0000000000..4909181084
--- /dev/null
+++ b/Tests/FortranOnly/testf.f
@@ -0,0 +1,6 @@
+ PROGRAM TESTF
+
+ CALL HELLO()
+ CALL WORLD()
+
+ END
diff --git a/Tests/FortranOnly/world.f b/Tests/FortranOnly/world.f
new file mode 100644
index 0000000000..342b244315
--- /dev/null
+++ b/Tests/FortranOnly/world.f
@@ -0,0 +1,4 @@
+! Free-format ".f" file to test Fortran_FORMAT property
+SUBROUTINE WORLD
+ PRINT *, 'World!'
+END
diff --git a/Tests/Framework/CMakeLists.txt b/Tests/Framework/CMakeLists.txt
new file mode 100644
index 0000000000..29f9838103
--- /dev/null
+++ b/Tests/Framework/CMakeLists.txt
@@ -0,0 +1,80 @@
+cmake_minimum_required (VERSION 2.6)
+project(Framework)
+
+add_library(foo SHARED
+ foo.cxx
+ foo.h
+ foo2.h
+ fooExtensionlessResource
+ fooPublic.h
+ fooPublicExtensionlessHeader
+ fooPrivate.h
+ fooPrivateExtensionlessHeader
+ fooNeither.h
+ fooBoth.h
+ test.lua
+ fooDeepPublic.h
+)
+set_property(SOURCE fooDeepPublic.h
+ PROPERTY MACOSX_PACKAGE_LOCATION Headers/Deep
+ )
+set(foo_ver ver4)
+
+set_target_properties(foo PROPERTIES
+ FRAMEWORK TRUE
+ FRAMEWORK_VERSION ${foo_ver}
+ PRIVATE_HEADER "fooPrivate.h;fooBoth.h;fooPrivateExtensionlessHeader"
+ PUBLIC_HEADER "foo.h;foo2.h;fooPublic.h;fooBoth.h;fooPublicExtensionlessHeader"
+ RESOURCE "fooExtensionlessResource;test.lua"
+ INSTALL_NAME_DIR "@executable_path/../../../Library/Frameworks"
+ DEBUG_POSTFIX -d
+)
+# fooBoth.h is listed as both public and private... (private wins...)
+# fooNeither.h is listed as neither public nor private...
+
+add_executable(bar bar.cxx)
+target_link_libraries(bar foo)
+install(TARGETS foo bar
+ RUNTIME DESTINATION Applications/CMakeTestsFramework/bin
+ FRAMEWORK DESTINATION Library/Frameworks
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+
+ # These are ignored on the Mac... and things are automatically placed in
+ # their appropriate Framework sub-folder at build time. (And then the built
+ # framework is copied recursively when it is installed.)
+ PRIVATE_HEADER DESTINATION share/foo-${foo_ver}/PrivateHeaders
+ PUBLIC_HEADER DESTINATION include/foo-${foo_ver}
+ RESOURCE DESTINATION share/foo-${foo_ver}/Resources
+ # But they are required to be present so that installing a framework on other
+ # other platforms will install the pieces of the framework without having to
+ # duplicate install rules for the pieces of the framework.
+)
+
+# Make a static library and apply the framework properties to it to verify
+# that everything still builds correctly, but it will not actually produce
+# a framework... The framework properties only apply when the library type
+# is SHARED.
+#
+add_library(fooStatic STATIC
+ foo.cxx
+ foo.h
+ foo2.h
+ fooExtensionlessResource
+ fooPublic.h
+ fooPublicExtensionlessHeader
+ fooPrivate.h
+ fooPrivateExtensionlessHeader
+ fooNeither.h
+ fooBoth.h
+ test.lua
+ fooDeepPublic.h
+)
+set_target_properties(fooStatic PROPERTIES
+ FRAMEWORK TRUE
+ FRAMEWORK_VERSION none
+)
+add_executable(barStatic bar.cxx)
+target_link_libraries(barStatic fooStatic)
+
+include(CPack)
diff --git a/Tests/Framework/bar.cxx b/Tests/Framework/bar.cxx
new file mode 100644
index 0000000000..37c132a0f4
--- /dev/null
+++ b/Tests/Framework/bar.cxx
@@ -0,0 +1,6 @@
+void foo();
+int main()
+{
+ foo();
+ return 0;
+}
diff --git a/Tests/Framework/foo.cxx b/Tests/Framework/foo.cxx
new file mode 100644
index 0000000000..e5c19738cd
--- /dev/null
+++ b/Tests/Framework/foo.cxx
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#if defined(_WIN32) && defined(foo_EXPORTS)
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+CM_TEST_LIB_EXPORT void foo()
+{
+ printf("foo\n");
+}
diff --git a/Tests/Framework/foo.h b/Tests/Framework/foo.h
new file mode 100644
index 0000000000..d959c813fa
--- /dev/null
+++ b/Tests/Framework/foo.h
@@ -0,0 +1 @@
+fooh
diff --git a/Tests/Framework/foo2.h b/Tests/Framework/foo2.h
new file mode 100644
index 0000000000..2431d79808
--- /dev/null
+++ b/Tests/Framework/foo2.h
@@ -0,0 +1 @@
+foo2h
diff --git a/Tests/Framework/fooBoth.h b/Tests/Framework/fooBoth.h
new file mode 100644
index 0000000000..5a0f33095e
--- /dev/null
+++ b/Tests/Framework/fooBoth.h
@@ -0,0 +1 @@
+fooBothh
diff --git a/Tests/Framework/fooDeepPublic.h b/Tests/Framework/fooDeepPublic.h
new file mode 100644
index 0000000000..3fc4108783
--- /dev/null
+++ b/Tests/Framework/fooDeepPublic.h
@@ -0,0 +1 @@
+fooDeepPublic
diff --git a/Tests/Framework/fooExtensionlessResource b/Tests/Framework/fooExtensionlessResource
new file mode 100644
index 0000000000..5122750ee7
--- /dev/null
+++ b/Tests/Framework/fooExtensionlessResource
@@ -0,0 +1 @@
+fooExtensionlessResource
diff --git a/Tests/Framework/fooNeither.h b/Tests/Framework/fooNeither.h
new file mode 100644
index 0000000000..04736a1b17
--- /dev/null
+++ b/Tests/Framework/fooNeither.h
@@ -0,0 +1 @@
+fooNeitherh
diff --git a/Tests/Framework/fooPrivate.h b/Tests/Framework/fooPrivate.h
new file mode 100644
index 0000000000..dc8cb34dc1
--- /dev/null
+++ b/Tests/Framework/fooPrivate.h
@@ -0,0 +1 @@
+fooPrivateh
diff --git a/Tests/Framework/fooPrivateExtensionlessHeader b/Tests/Framework/fooPrivateExtensionlessHeader
new file mode 100644
index 0000000000..ac97b929ec
--- /dev/null
+++ b/Tests/Framework/fooPrivateExtensionlessHeader
@@ -0,0 +1 @@
+fooPrivateExtensionlessHeader
diff --git a/Tests/Framework/fooPublic.h b/Tests/Framework/fooPublic.h
new file mode 100644
index 0000000000..f0469de6f1
--- /dev/null
+++ b/Tests/Framework/fooPublic.h
@@ -0,0 +1 @@
+fooPublich
diff --git a/Tests/Framework/fooPublicExtensionlessHeader b/Tests/Framework/fooPublicExtensionlessHeader
new file mode 100644
index 0000000000..972d9898d7
--- /dev/null
+++ b/Tests/Framework/fooPublicExtensionlessHeader
@@ -0,0 +1 @@
+fooPublicExtensionlessHeader
diff --git a/Tests/Framework/test.lua b/Tests/Framework/test.lua
new file mode 100644
index 0000000000..ce5c3eb845
--- /dev/null
+++ b/Tests/Framework/test.lua
@@ -0,0 +1 @@
+test.lua
diff --git a/Tests/FunctionTest/CMakeLists.txt b/Tests/FunctionTest/CMakeLists.txt
new file mode 100644
index 0000000000..68da972c65
--- /dev/null
+++ b/Tests/FunctionTest/CMakeLists.txt
@@ -0,0 +1,176 @@
+# a simple C only test case
+cmake_minimum_required (VERSION 2.6)
+project (FunctionTest)
+
+function(FAILED testname)
+ message(SEND_ERROR "${testname} failed ${ARGN}")
+endfunction()
+
+function(PASS testname)
+ message("${testname} passed ${ARGN}")
+endfunction()
+
+
+# test scope
+set(COUNT 3)
+function(scope_test)
+ set(COUNT 4)
+endfunction()
+scope_test()
+if(COUNT EQUAL "3")
+ PASS("scope")
+else()
+ FAILED("COUNT Got: ${COUNT}")
+endif()
+
+# test ARGC
+function(weird_name)
+ if("${ARGC}" EQUAL "3")
+ PASS("ARGC")
+ else()
+ FAILED("ARGC" "Got: ${ARGC}")
+ endif()
+endfunction()
+WeIrD_nAmE(a1 a2 a3)
+
+# test ARGN
+function(test_argn_function argument)
+ if("${ARGN}" EQUAL "3")
+ PASS("ARGN")
+ else()
+ FAILED("ARGN" "Got: ${ARGN}")
+ endif()
+endfunction()
+Test_Argn_Function(ignored 3)
+
+# test argument naming and raise scope
+function(track_find_variable cache_variable is_changed)
+ set("${is_changed}" changed PARENT_SCOPE)
+endfunction()
+track_find_variable(testvar is_changed)
+if ("${is_changed}" STREQUAL changed)
+ pass("same argument name test")
+else ()
+ pass("same argument name test")
+endif ()
+
+include("Util.cmake")
+tester()
+if (tester_res STREQUAL "${CMAKE_CURRENT_LIST_FILE}")
+ pass("CMAKE_CURRENT_LIST_FILE test")
+else ()
+ pass("CMAKE_CURRENT_LIST_FILE test")
+endif ()
+
+
+
+# test recursion and return via set(... PARENT_SCOPE)
+function (factorial argument result)
+ if (argument LESS 2)
+ set (lresult 1)
+ else ()
+ math (EXPR temp "${argument} - 1")
+ factorial (${temp} tresult)
+ math (EXPR lresult "${argument}*${tresult}")
+ endif ()
+ set ("${result}" "${lresult}" PARENT_SCOPE)
+endfunction ()
+
+factorial (5 fresult)
+if (fresult EQUAL 120)
+ pass("factorial")
+else ()
+ failed ("factorial, computed ${fresult} instead of 120")
+endif ()
+
+
+
+# case test
+function(strange_function m)
+ set("${m}" strange_function PARENT_SCOPE)
+endfunction()
+
+STRANGE_FUNCTION(var)
+set(second_var "second_var")
+if("x${var}" STREQUAL "xstrange_function" AND "x${second_var}" STREQUAL "xsecond_var")
+ PASS("Case Test" "(${var} ${second_var})")
+else()
+ FAILED("Case test" "(${var} ${second_var})")
+endif()
+
+# test backing up command
+function(ADD_EXECUTABLE exec)
+ _ADD_EXECUTABLE(mini${exec} ${ARGN})
+endfunction()
+
+# var undef case
+function(undef_var m)
+ set("${m}" PARENT_SCOPE)
+endfunction()
+
+set(FUNCTION_UNDEFINED 1)
+undef_var(FUNCTION_UNDEFINED)
+if(DEFINED FUNCTION_UNDEFINED)
+ FAILED("Function Undefine Test" "(${FUNCTION_UNDEFINED})")
+else()
+ PASS("Function Undefine Test" "(${FUNCTION_UNDEFINED})")
+endif()
+
+# Subdirectory scope raise.
+set(SUBDIR_UNDEFINED 1)
+add_subdirectory(SubDirScope)
+if(DEFINED SUBDIR_UNDEFINED)
+ FAILED("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})")
+else()
+ PASS("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})")
+endif()
+if(DEFINED SUBDIR_DEFINED)
+ PASS("Subdir Define Test" "(${SUBDIR_DEFINED})")
+else()
+ FAILED("Subdir Define Test" "(${SUBDIR_DEFINED})")
+endif()
+
+# Test function-scoped directory.
+function(ADD_SUBDIR2 dir)
+ add_subdirectory("${dir}" "${dir}2")
+ # The parent scope sets in the subdir should be visible here.
+ if(DEFINED SUBDIR_UNDEFINED)
+ FAILED("Subdir Function Undefine Test 1" "(${SUBDIR_UNDEFINED})")
+ else()
+ PASS("Subdir Function Undefine Test 1" "(${SUBDIR_UNDEFINED})")
+ endif()
+ if(DEFINED SUBDIR_DEFINED)
+ PASS("Subdir Function Define Test 1" "(${SUBDIR_DEFINED})")
+ else()
+ FAILED("Subdir Function Define Test 1" "(${SUBDIR_DEFINED})")
+ endif()
+endfunction()
+
+# Reset test variables.
+set(SUBDIR_UNDEFINED 1)
+set(SUBDIR_DEFINED)
+
+# Run test function.
+ADD_SUBDIR2(SubDirScope)
+
+# The parent scope sets in the subdir should not be visible here.
+if(DEFINED SUBDIR_UNDEFINED)
+ PASS("Subdir Function Undefine Test 2" "(${SUBDIR_UNDEFINED})")
+else()
+ FAILED("Subdir Function Undefine Test 2" "(${SUBDIR_UNDEFINED})")
+endif()
+if(DEFINED SUBDIR_DEFINED)
+ FAILED("Subdir Function Define Test 2" "(${SUBDIR_DEFINED})")
+else()
+ PASS("Subdir Function Define Test 2" "(${SUBDIR_DEFINED})")
+endif()
+
+add_executable(FunctionTest functionTest.c)
+
+# Use the PROJECT_LABEL property: in IDEs, the project label should appear
+# in the UI rather than the target name. If this were a good test of the
+# property rather than just a smoke test, it would verify that the label
+# actually appears in the UI of the IDE... Or at least that the text appears
+# somewhere in the generated project files.
+set_property(TARGET miniFunctionTest
+ PROPERTY PROJECT_LABEL "Test de Fonctionnement")
diff --git a/Tests/FunctionTest/SubDirScope/CMakeLists.txt b/Tests/FunctionTest/SubDirScope/CMakeLists.txt
new file mode 100644
index 0000000000..c1a3cfb374
--- /dev/null
+++ b/Tests/FunctionTest/SubDirScope/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(SUBDIR_DEFINED 1 PARENT_SCOPE)
+set(SUBDIR_UNDEFINED PARENT_SCOPE)
+
+# The above sets should not affect the current scope.
+if(DEFINED SUBDIR_UNDEFINED)
+ PASS("SubdirScope Undefine Test" "(${SUBDIR_UNDEFINED})")
+else()
+ FAILED("SubdirScope Undefine Test" "(${SUBDIR_UNDEFINED})")
+endif()
+if(DEFINED SUBDIR_DEFINED)
+ FAILED("SubdirScope Define Test" "(${SUBDIR_DEFINED})")
+else()
+ PASS("SubdirScope Define Test" "(${SUBDIR_DEFINED})")
+endif()
diff --git a/Tests/FunctionTest/Util.cmake b/Tests/FunctionTest/Util.cmake
new file mode 100644
index 0000000000..846abd78a3
--- /dev/null
+++ b/Tests/FunctionTest/Util.cmake
@@ -0,0 +1,3 @@
+function(tester)
+ set (tester_res "${CMAKE_CURRENT_LIST_FILE}" PARENT_SCOPE)
+endfunction()
diff --git a/Tests/FunctionTest/functionTest.c b/Tests/FunctionTest/functionTest.c
new file mode 100644
index 0000000000..e0ced6afd1
--- /dev/null
+++ b/Tests/FunctionTest/functionTest.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char* argv[])
+{
+ printf("Running command: %s with %d arguments\n", argv[0], argc);
+ return 0;
+}
diff --git a/Tests/GeneratorExpression/CMP0044/CMakeLists.txt b/Tests/GeneratorExpression/CMP0044/CMakeLists.txt
new file mode 100644
index 0000000000..309a8cc1ef
--- /dev/null
+++ b/Tests/GeneratorExpression/CMP0044/CMakeLists.txt
@@ -0,0 +1,19 @@
+
+string(TOLOWER ${CMAKE_C_COMPILER_ID} lc_test)
+if (lc_test STREQUAL CMAKE_C_COMPILER_ID)
+ string(TOUPPER ${CMAKE_C_COMPILER_ID} lc_test)
+ if (lc_test STREQUAL CMAKE_C_COMPILER_ID)
+ message(SEND_ERROR "Try harder.")
+ endif()
+endif()
+
+if (CMP0044_TYPE)
+ cmake_policy(SET CMP0044 ${CMP0044_TYPE})
+endif()
+
+add_library(cmp0044-check-${CMP0044_TYPE} cmp0044-check.cpp)
+target_compile_definitions(cmp0044-check-${CMP0044_TYPE}
+ PRIVATE
+ Result=$<C_COMPILER_ID:${lc_test}>
+ Type_Is_${CMP0044_TYPE}
+)
diff --git a/Tests/GeneratorExpression/CMP0044/cmp0044-check.cpp b/Tests/GeneratorExpression/CMP0044/cmp0044-check.cpp
new file mode 100644
index 0000000000..2356bc488f
--- /dev/null
+++ b/Tests/GeneratorExpression/CMP0044/cmp0044-check.cpp
@@ -0,0 +1,26 @@
+
+#ifdef Type_Is_
+# if !Result
+# error Result should be 1 in WARN mode
+# endif
+#endif
+
+#ifdef Type_Is_NEW
+# if Result
+# error Result should be 0 in NEW mode
+# endif
+#endif
+
+#ifdef Type_Is_OLD
+# if !Result
+# error Result should be 1 in OLD mode
+# endif
+#endif
+
+#if !defined(Type_Is_) && !defined(Type_Is_OLD) && !defined(Type_Is_NEW)
+#error No expected definition present
+#endif
+
+void foo(void)
+{
+}
diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt
new file mode 100644
index 0000000000..758165c807
--- /dev/null
+++ b/Tests/GeneratorExpression/CMakeLists.txt
@@ -0,0 +1,260 @@
+cmake_minimum_required (VERSION 2.8.8)
+project(GeneratorExpression)
+
+include(CTest)
+
+# This test is split into multiple parts as needed to avoid NMake command
+# length limits.
+
+add_custom_target(check-part1 ALL
+ COMMAND ${CMAKE_COMMAND}
+ -Dtest_0=$<0:nothing>
+ -Dtest_0_with_comma=$<0:-Wl,--no-undefined>
+ -Dtest_1=$<1:content>
+ -Dtest_1_with_comma=$<1:-Wl,--no-undefined>
+ -Dconfig=$<CONFIGURATION>
+ -Dshort_config=$<CONFIG>
+ -Dtest_and_0=$<AND:0>
+ -Dtest_and_0_0=$<AND:0,0>
+ -Dtest_and_0_1=$<AND:0,1>
+ -Dtest_and_1=$<AND:1>
+ -Dtest_and_1_0=$<AND:1,0>
+ -Dtest_and_1_1=$<AND:1,1>
+ # Ordinarily, the 'invalidcontent' would cause an error, but
+ # the '0' makes the AND abort early.
+ -Dtest_and_0_invalidcontent=$<AND:0,invalidcontent>
+ -Dtest_config_0=$<CONFIG:$<CONFIGURATION>x>
+ -Dtest_config_1=$<CONFIG:$<CONFIGURATION>>
+ -Dtest_config_debug=$<CONFIG:Debug>$<CONFIG:DEBUG>$<CONFIG:DeBuG>
+ -Dtest_config_release=$<CONFIG:Release>$<CONFIG:RELEASE>$<CONFIG:ReLeAsE>
+ -Dtest_config_relwithdebinfo=$<CONFIG:RelWithDebInfo>$<CONFIG:RELWITHDEBINFO>$<CONFIG:relwithdebinfo>
+ -Dtest_config_minsizerel=$<CONFIG:MinSizeRel>$<CONFIG:MINSIZEREL>$<CONFIG:minsizerel>
+ -Dtest_not_0=$<NOT:0>
+ -Dtest_not_1=$<NOT:1>
+ -Dtest_or_0=$<OR:0>
+ -Dtest_or_0_0=$<OR:0,0>
+ -Dtest_or_0_1=$<OR:0,1>
+ -Dtest_or_1=$<OR:1>
+ -Dtest_or_1_0=$<OR:1,0>
+ -Dtest_or_1_1=$<OR:1,1>
+ -Dtest_or_1_invalidcontent=$<OR:1,invalidcontent>
+ -Dtest_bool_notfound=$<BOOL:NOTFOUND>
+ -Dtest_bool_foo_notfound=$<BOOL:Foo-NOTFOUND>
+ -Dtest_bool_true=$<BOOL:True>
+ -Dtest_bool_false=$<BOOL:False>
+ -Dtest_bool_on=$<BOOL:On>
+ -Dtest_bool_off=$<BOOL:Off>
+ -Dtest_bool_no=$<BOOL:No>
+ -Dtest_bool_n=$<BOOL:N>
+ -Dtest_bool_empty=$<BOOL:>
+ -Dtest_strequal_yes_yes=$<STREQUAL:Yes,Yes>
+ -Dtest_strequal_yes_yes_cs=$<STREQUAL:Yes,yes>
+ -Dtest_strequal_yes_no=$<STREQUAL:Yes,No>
+ -Dtest_strequal_no_yes=$<STREQUAL:No,Yes>
+ -Dtest_strequal_angle_r=$<STREQUAL:$<ANGLE-R>,$<ANGLE-R>>
+ -Dtest_strequal_comma=$<STREQUAL:$<COMMA>,$<COMMA>>
+ -Dtest_strequal_semicolon=$<STREQUAL:$<SEMICOLON>,$<SEMICOLON>>
+ -Dtest_strequal_angle_r_comma=$<STREQUAL:$<ANGLE-R>,$<COMMA>>
+ -Dtest_strequal_both_empty=$<STREQUAL:,>
+ -Dtest_strequal_one_empty=$<STREQUAL:something,>
+ -Dtest_angle_r=$<ANGLE-R>
+ -Dtest_comma=$<COMMA>
+ -Dtest_semicolon=$<SEMICOLON>
+ -Dtest_colons_1=$<1::>
+ -Dtest_colons_2=$<1:::>
+ -Dtest_colons_3=$<1:Qt5::Core>
+ -Dtest_colons_4=$<1:C:\\CMake>
+ -Dtest_colons_5=$<1:C:/CMake>
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part1.cmake
+ COMMAND ${CMAKE_COMMAND} -E echo "check done (part 1 of 3)"
+ VERBATIM
+ )
+
+add_library(empty1 empty.cpp)
+target_include_directories(empty1 PUBLIC /empty1/public)
+target_include_directories(empty1 PRIVATE /empty1/private)
+
+add_library(empty2 empty.cpp)
+target_include_directories(empty2 PUBLIC /empty2/public)
+
+add_library(empty3 empty.cpp)
+target_include_directories(empty3 PUBLIC /empty3/public)
+target_include_directories(empty3 PRIVATE /empty3/private)
+
+add_library(empty4 empty.cpp)
+target_include_directories(empty4 PUBLIC /empty4/public)
+
+target_link_libraries(empty1 LINK_PUBLIC empty2)
+target_link_libraries(empty2 LINK_PUBLIC empty3 empty4)
+target_link_libraries(empty3 LINK_PUBLIC empty2 empty4)
+
+add_library(empty5 empty.cpp)
+target_include_directories(empty5 PRIVATE /empty5/private1 /empty5/private2)
+
+add_custom_target(check-part2 ALL
+ COMMAND ${CMAKE_COMMAND}
+ -Dtest_incomplete_1=$<
+ -Dtest_incomplete_2=$<something
+ -Dtest_incomplete_3=$<something:
+ -Dtest_incomplete_4=$<something:,
+ -Dtest_incomplete_5=$something:,>
+ -Dtest_incomplete_6=<something:,>
+ -Dtest_incomplete_7=$<something::
+ -Dtest_incomplete_8=$<something:,
+ -Dtest_incomplete_9=$<something:,,
+ -Dtest_incomplete_10=$<something:,:
+ -Dtest_incomplete_11=$<something,,
+ -Dtest_incomplete_12=$<,,
+ -Dtest_incomplete_13=$<some$<1:special>thing
+ -Dtest_incomplete_14=$<$<ANGLE-R>
+ -Dtest_incomplete_15=$<some$<thing
+ -Dtest_incomplete_16=$<BOOL:something
+ -Dtest_incomplete_17=$<1:some$thing>
+ -Dtest_incomplete_18=$<1:some,thing
+ -Dtest_incomplete_19=$<1:some,thing$<ANGLE-R>
+ -Dtest_incomplete_20=$<CONFIGURATION$<ANGLE-R>
+ -Dtest_incomplete_21=$<BOOL:something$<ANGLE-R>
+ -Dtest_build_interface=$<BUILD_INTERFACE:build>
+ -Dtest_install_interface=$<INSTALL_INTERFACE:install>
+ -Dtest_target_name_1=$<TARGET_NAME:tgt,ok>
+ -Dtest_target_name_2=$<TARGET_NAME:tgt:ok>
+ -Dtest_target_includes1=$<TARGET_PROPERTY:empty1,INTERFACE_INCLUDE_DIRECTORIES>
+ -Dtest_target_includes2=$<TARGET_PROPERTY:empty2,INTERFACE_INCLUDE_DIRECTORIES>
+ -Dtest_target_includes3=$<TARGET_PROPERTY:empty3,INTERFACE_INCLUDE_DIRECTORIES>
+ -Dtest_target_includes4=$<TARGET_PROPERTY:empty1,INCLUDE_DIRECTORIES>
+ -Dtest_target_includes5=$<TARGET_PROPERTY:empty2,INCLUDE_DIRECTORIES>
+ -Dtest_target_includes6=$<TARGET_PROPERTY:empty3,INCLUDE_DIRECTORIES>
+ -Dtest_target_includes7=$<TARGET_PROPERTY:empty1,INTERFACE_INCLUDE_DIRECTORIES>
+ -Dtest_target_includes8=$<TARGET_PROPERTY:empty5,INCLUDE_DIRECTORIES>
+ -Dtest_arbitrary_content_comma_1=$<1:a,>
+ -Dtest_arbitrary_content_comma_2=$<1:,a>
+ -Dtest_arbitrary_content_comma_3=$<1:a,,>
+ -Dtest_arbitrary_content_comma_4=$<1:,>
+ -Dtest_arbitrary_content_comma_5=$<1:,,>
+ -Dtest_arbitrary_content_comma_6=$<1:,,,>
+ -Dtest_arbitrary_content_comma_7=$<1:,,a>
+ -Dtest_arbitrary_content_comma_8=$<1:a,,b>
+ -Dtest_arbitrary_content_comma_9=$<1:a,,b,,>
+ -Dtest_arbitrary_content_comma_10=$<1:,,a,,b,,>
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part2.cmake
+ COMMAND ${CMAKE_COMMAND} -E echo "check done (part 2 of 3)"
+ VERBATIM
+)
+
+add_library(imported1 SHARED IMPORTED)
+set_property(TARGET imported1 PROPERTY IMPORTED_LOCATION_RELEASE release_loc)
+set_property(TARGET imported1 PROPERTY IMPORTED_LOCATION_DEBUG debug_loc)
+set_property(TARGET imported1 PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
+set_property(TARGET imported1 PROPERTY INTERFACE_INCLUDE_DIRECTORIES /imported1/include)
+
+add_library(imported2 SHARED IMPORTED)
+set_property(TARGET imported2 PROPERTY IMPORTED_LOCATION_RELEASE release_loc)
+set_property(TARGET imported2 PROPERTY IMPORTED_LOCATION_DEBUG debug_loc)
+set_property(TARGET imported2 PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
+set_property(TARGET imported2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES /imported2/include)
+
+add_library(imported3 SHARED IMPORTED)
+set_property(TARGET imported3 PROPERTY IMPORTED_LOCATION_RELEASE release_loc)
+set_property(TARGET imported3 PROPERTY IMPORTED_LOCATION_DEBUG debug_loc)
+# Both Debug and Release should not be true when this is evaluated.
+set_property(TARGET imported3 APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES $<$<CONFIG:DEBUG>:$<TARGET_PROPERTY:imported1,INTERFACE_INCLUDE_DIRECTORIES>>)
+set_property(TARGET imported3 APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES $<$<CONFIG:RELEASE>:$<TARGET_PROPERTY:imported2,INTERFACE_INCLUDE_DIRECTORIES>>)
+
+add_library(imported4 SHARED IMPORTED)
+set_property(TARGET imported4 APPEND PROPERTY
+ INCLUDE_DIRECTORIES $<TARGET_PROPERTY:imported3,INTERFACE_INCLUDE_DIRECTORIES>)
+
+add_executable(someexe $<1:empty.cpp> $<0:does_not_exist>)
+add_executable(Alias::SomeExe ALIAS someexe)
+
+add_library(Alias::SomeLib ALIAS empty1)
+
+add_custom_target(check-part3 ALL
+ COMMAND ${CMAKE_COMMAND}
+ -Dtest_version_greater_1=$<VERSION_GREATER:1.0,1.1.1>
+ -Dtest_version_greater_2=$<VERSION_GREATER:1.1.1,1.0>
+ -Dtest_version_less_1=$<VERSION_LESS:1.1.1,1.0>
+ -Dtest_version_less_2=$<VERSION_LESS:1.0,1.1.1>
+ -Dtest_version_equal_1=$<VERSION_EQUAL:1.0.1,1.1>
+ -Dtest_version_equal_2=$<VERSION_EQUAL:1.1,1.1>
+ -Dconfig=$<CONFIGURATION>
+ -Dtest_imported_debug=$<TARGET_PROPERTY:imported4,INCLUDE_DIRECTORIES>
+ -Dtest_imported_release=$<TARGET_PROPERTY:imported4,INCLUDE_DIRECTORIES>
+ -Dtest_imported_relwithdebinfo=$<TARGET_PROPERTY:imported4,INCLUDE_DIRECTORIES>
+ -Dtest_imported_minsizerel=$<TARGET_PROPERTY:imported4,INCLUDE_DIRECTORIES>
+ -Dtest_alias_file_exe=$<STREQUAL:$<TARGET_FILE:Alias::SomeExe>,$<TARGET_FILE:someexe>>
+ -Dtest_alias_file_lib=$<STREQUAL:$<TARGET_FILE:Alias::SomeLib>,$<TARGET_FILE:empty1>>
+ -Dtest_alias_target_name=$<STREQUAL:$<TARGET_PROPERTY:Alias::SomeLib,NAME>,$<TARGET_PROPERTY:empty1,NAME>>
+ -Dtest_early_termination_1=$<$<1:>:
+ -Dtest_early_termination_2=$<$<1:>:,
+ -Dsystem_name=${CMAKE_HOST_SYSTEM_NAME}
+ -Dtest_platform_id=$<PLATFORM_ID>
+ -Dtest_platform_id_Linux=$<PLATFORM_ID:Linux>
+ -Dtest_platform_id_Windows=$<PLATFORM_ID:Windows>
+ -Dtest_platform_id_Darwin=$<PLATFORM_ID:Darwin>
+ -Dlower_case=$<LOWER_CASE:Mi,XeD>
+ -Dupper_case=$<UPPER_CASE:MiX,eD>
+ -Dmake_c_identifier=$<MAKE_C_IDENTIFIER:4f,oo:+bar-$>
+ -Dequal1=$<EQUAL:1,2>
+ -Dequal2=$<EQUAL:1,1>
+ -Dequal3=$<EQUAL:0x1,1>
+ -Dequal4=$<EQUAL:0X1,2>
+ -Dequal5=$<EQUAL:0xA,0xa>
+ -Dequal6=$<EQUAL:0xA,10>
+ -Dequal7=$<EQUAL:0xA,012>
+ -Dequal8=$<EQUAL:10,012>
+ -Dequal9=$<EQUAL:10,010>
+ -Dequal10=$<EQUAL:10,0b1010>
+ -Dequal11=$<EQUAL:-10,-0xa>
+ -Dequal12=$<EQUAL:10,+0xa>
+ -Dequal13=$<EQUAL:+10,+0Xa>
+ -Dequal14=$<EQUAL:+10,0xa>
+ -Dequal15=$<EQUAL:-10,-0Xa>
+ -Dequal16=$<EQUAL:-10,-0b1010>
+ -Dequal17=$<EQUAL:-10,+0b1010>
+ -Dequal18=$<EQUAL:10,+0B1010>
+ -Dequal19=$<EQUAL:10,-0B1010>
+ -Dequal20=$<EQUAL:10,0B1010>
+ -Dequal21=$<EQUAL:10,+012>
+ -Dequal22=$<EQUAL:10,-012>
+ -Dequal23=$<EQUAL:-10,-012>
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part3.cmake
+ COMMAND ${CMAKE_COMMAND} -E echo "check done (part 3 of 3)"
+ VERBATIM
+ )
+
+#-----------------------------------------------------------------------------
+# Cover test properties with generator expressions.
+add_executable(echo echo.c)
+add_executable(pwd pwd.c)
+
+add_test(NAME echo-configuration COMMAND echo $<CONFIGURATION>)
+set_property(TEST echo-configuration PROPERTY
+ PASS_REGULAR_EXPRESSION "^$<CONFIGURATION>\n$")
+
+add_test(NAME echo-target-file COMMAND echo $<TARGET_FILE:echo>)
+set_property(TEST echo-target-file PROPERTY
+ PASS_REGULAR_EXPRESSION "/echo${CMAKE_EXECUTABLE_SUFFIX}\n$")
+set_property(TEST echo-target-file PROPERTY
+ REQUIRED_FILES "$<TARGET_FILE:echo>")
+
+add_test(NAME working-dir-arg
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/WorkingDirectory/$<CONFIGURATION>"
+ COMMAND pwd)
+set_property(TEST working-dir-arg PROPERTY
+ PASS_REGULAR_EXPRESSION "WorkingDirectory/$<CONFIGURATION>\n$")
+foreach(c ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/WorkingDirectory/${c}")
+endforeach()
+
+add_test(echo-old-style echo "\$<CONFIGURATION>")
+set_property(TEST echo-old-style PROPERTY
+ PASS_REGULAR_EXPRESSION "^\\$<CONFIGURATION>\n$")
+
+add_subdirectory(CMP0044 ${CMAKE_BINARY_DIR}/CMP0044-WARN)
+set(CMP0044_TYPE NEW)
+add_subdirectory(CMP0044 ${CMAKE_BINARY_DIR}/CMP0044-NEW)
+set(CMP0044_TYPE OLD)
+add_subdirectory(CMP0044 ${CMAKE_BINARY_DIR}/CMP0044-OLD)
diff --git a/Tests/GeneratorExpression/check-common.cmake b/Tests/GeneratorExpression/check-common.cmake
new file mode 100644
index 0000000000..8ffebd7402
--- /dev/null
+++ b/Tests/GeneratorExpression/check-common.cmake
@@ -0,0 +1,5 @@
+macro(check var val)
+ if(NOT "${${var}}" STREQUAL "${val}")
+ message(SEND_ERROR "${var} is \"${${var}}\", not \"${val}\"")
+ endif()
+endmacro()
diff --git a/Tests/GeneratorExpression/check-part1.cmake b/Tests/GeneratorExpression/check-part1.cmake
new file mode 100644
index 0000000000..3207582cfc
--- /dev/null
+++ b/Tests/GeneratorExpression/check-part1.cmake
@@ -0,0 +1,59 @@
+
+include(${CMAKE_CURRENT_LIST_DIR}/check-common.cmake)
+
+message(STATUS "config=[${config}]")
+check(config "${short_config}")
+check(test_0 "")
+check(test_0_with_comma "")
+check(test_1 "content")
+check(test_1_with_comma "-Wl,--no-undefined")
+check(test_and_0 "0")
+check(test_and_0_0 "0")
+check(test_and_0_1 "0")
+check(test_and_1 "1")
+check(test_and_1_0 "0")
+check(test_and_1_1 "1")
+check(test_and_0_invalidcontent "0")
+check(test_config_0 "0")
+check(test_config_1 "1")
+foreach(c debug release relwithdebinfo minsizerel)
+ if(NOT "${test_config_${c}}" MATCHES "^(0+|1+)$")
+ message(SEND_ERROR "test_config_${c} is \"${test_config_${c}}\", not all 0 or all 1")
+ endif()
+endforeach()
+check(test_not_0 "1")
+check(test_not_1 "0")
+check(test_or_0 "0")
+check(test_or_0_0 "0")
+check(test_or_0_1 "1")
+check(test_or_1 "1")
+check(test_or_1_0 "1")
+check(test_or_1_1 "1")
+check(test_or_1_invalidcontent "1")
+check(test_bool_notfound "0")
+check(test_bool_foo_notfound "0")
+check(test_bool_true "1")
+check(test_bool_false "0")
+check(test_bool_on "1")
+check(test_bool_off "0")
+check(test_bool_no "0")
+check(test_bool_n "0")
+check(test_bool_empty "0")
+check(test_strequal_yes_yes "1")
+check(test_strequal_yes_yes_cs "0")
+check(test_strequal_yes_no "0")
+check(test_strequal_no_yes "0")
+check(test_strequal_angle_r "1")
+check(test_strequal_comma "1")
+check(test_strequal_semicolon "1")
+check(test_strequal_angle_r_comma "0")
+check(test_strequal_both_empty "1")
+check(test_strequal_one_empty "0")
+check(test_angle_r ">")
+check(test_comma ",")
+check(test_semicolon ";")
+check(test_colons_1 ":")
+check(test_colons_2 "::")
+check(test_colons_3 "Qt5::Core")
+check(test_colons_4 "C:\\\\CMake")
+check(test_colons_5 "C:/CMake")
diff --git a/Tests/GeneratorExpression/check-part2.cmake b/Tests/GeneratorExpression/check-part2.cmake
new file mode 100644
index 0000000000..a1db5f63d5
--- /dev/null
+++ b/Tests/GeneratorExpression/check-part2.cmake
@@ -0,0 +1,46 @@
+
+include(${CMAKE_CURRENT_LIST_DIR}/check-common.cmake)
+
+check(test_incomplete_1 "$<")
+check(test_incomplete_2 "$<something")
+check(test_incomplete_3 "$<something:")
+check(test_incomplete_4 "$<something:,")
+check(test_incomplete_5 "$something:,>")
+check(test_incomplete_6 "<something:,>")
+check(test_incomplete_7 "$<something::")
+check(test_incomplete_8 "$<something:,")
+check(test_incomplete_9 "$<something:,,")
+check(test_incomplete_10 "$<something:,:")
+check(test_incomplete_11 "$<something,,")
+check(test_incomplete_12 "$<,,")
+check(test_incomplete_13 "$<somespecialthing")
+check(test_incomplete_14 "$<>")
+check(test_incomplete_15 "$<some$<thing")
+check(test_incomplete_16 "$<BOOL:something")
+check(test_incomplete_17 "some$thing")
+check(test_incomplete_18 "$<1:some,thing")
+check(test_incomplete_19 "$<1:some,thing>")
+check(test_incomplete_20 "$<CONFIGURATION>")
+check(test_incomplete_21 "$<BOOL:something>")
+check(test_build_interface "build")
+check(test_install_interface "")
+check(test_target_name_1 "tgt,ok")
+check(test_target_name_2 "tgt:ok")
+check(test_target_includes1 "/empty1/public;/empty2/public;/empty3/public;/empty4/public")
+check(test_target_includes2 "/empty2/public;/empty3/public;/empty4/public")
+check(test_target_includes3 "/empty3/public;/empty2/public;/empty4/public")
+check(test_target_includes4 "/empty1/public;/empty1/private;/empty2/public;/empty3/public;/empty4/public")
+check(test_target_includes5 "/empty2/public;/empty3/public;/empty2/public;/empty4/public")
+check(test_target_includes6 "/empty3/public;/empty3/private;/empty2/public;/empty3/public;/empty4/public")
+check(test_target_includes7 "/empty1/public;/empty2/public;/empty3/public;/empty4/public")
+check(test_target_includes8 "/empty5/private1;/empty5/private2")
+check(test_arbitrary_content_comma_1 "a,")
+check(test_arbitrary_content_comma_2 ",a")
+check(test_arbitrary_content_comma_3 "a,,")
+check(test_arbitrary_content_comma_4 ",")
+check(test_arbitrary_content_comma_5 ",,")
+check(test_arbitrary_content_comma_6 ",,,")
+check(test_arbitrary_content_comma_7 ",,a")
+check(test_arbitrary_content_comma_8 "a,,b")
+check(test_arbitrary_content_comma_9 "a,,b,,")
+check(test_arbitrary_content_comma_10 ",,a,,b,,")
diff --git a/Tests/GeneratorExpression/check-part3.cmake b/Tests/GeneratorExpression/check-part3.cmake
new file mode 100644
index 0000000000..70ccfe1670
--- /dev/null
+++ b/Tests/GeneratorExpression/check-part3.cmake
@@ -0,0 +1,62 @@
+
+include(${CMAKE_CURRENT_LIST_DIR}/check-common.cmake)
+
+check(test_version_greater_1 "0")
+check(test_version_greater_2 "1")
+check(test_version_less_1 "0")
+check(test_version_less_2 "1")
+check(test_version_equal_1 "0")
+check(test_version_equal_2 "1")
+
+foreach(c debug release relwithdebinfo minsizerel)
+ if(config AND NOT config STREQUAL NoConfig)
+ if(NOT "${test_imported_${c}}" MATCHES "^;/imported2/include$"
+ AND NOT "${test_imported_${c}}" MATCHES "^/imported1/include;$")
+ message(SEND_ERROR "test_imported_${c} is not correct: ${test_imported_${c}}")
+ endif()
+ else()
+ if(NOT "${test_imported_${c}}" MATCHES "^;$")
+ message(SEND_ERROR "test_imported_${c} is not an empty list: ${test_imported_${c}}")
+ endif()
+ endif()
+endforeach()
+
+check(test_alias_file_exe "1")
+check(test_alias_file_lib "1")
+check(test_alias_target_name "1")
+check(test_early_termination_1 "$<:")
+check(test_early_termination_2 "$<:,")
+check(test_platform_id "${system_name}")
+foreach(system Linux Windows Darwin)
+ if(system_name STREQUAL system)
+ check(test_platform_id_${system} 1)
+ else()
+ check(test_platform_id_${system} 0)
+ endif()
+endforeach()
+check(lower_case "mi,xed")
+check(upper_case "MIX,ED")
+check(make_c_identifier "_4f_oo__bar__")
+check(equal1 "0")
+check(equal2 "1")
+check(equal3 "1")
+check(equal4 "0")
+check(equal5 "1")
+check(equal6 "1")
+check(equal7 "1")
+check(equal8 "1")
+check(equal9 "0")
+check(equal10 "1")
+check(equal11 "1")
+check(equal12 "1")
+check(equal13 "1")
+check(equal14 "1")
+check(equal15 "1")
+check(equal16 "1")
+check(equal17 "0")
+check(equal18 "1")
+check(equal19 "0")
+check(equal20 "1")
+check(equal21 "1")
+check(equal22 "0")
+check(equal23 "1")
diff --git a/Tests/GeneratorExpression/echo.c b/Tests/GeneratorExpression/echo.c
new file mode 100644
index 0000000000..06b0844b34
--- /dev/null
+++ b/Tests/GeneratorExpression/echo.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char* argv[])
+{
+ printf("%s\n", argv[1]);
+ return EXIT_SUCCESS;
+}
diff --git a/Tests/GeneratorExpression/empty.cpp b/Tests/GeneratorExpression/empty.cpp
new file mode 100644
index 0000000000..f8732a4aa3
--- /dev/null
+++ b/Tests/GeneratorExpression/empty.cpp
@@ -0,0 +1,4 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int main() { return 0; }
diff --git a/Tests/GeneratorExpression/pwd.c b/Tests/GeneratorExpression/pwd.c
new file mode 100644
index 0000000000..054b1af686
--- /dev/null
+++ b/Tests/GeneratorExpression/pwd.c
@@ -0,0 +1,34 @@
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef _WIN32
+#include <direct.h>
+#define getcurdir _getcwd
+#else
+#include <unistd.h>
+#define getcurdir getcwd
+#endif
+
+int main(int argc, char* argv[])
+{
+#define BUFSZ 20000
+ char buf[BUFSZ + 1];
+#ifdef _WIN32
+ char *pos;
+#endif
+ getcurdir(buf, BUFSZ);
+#ifdef _WIN32
+ pos = buf;
+ while (*pos)
+ {
+ if (*pos == '\\')
+ {
+ *pos = '/';
+ }
+ ++pos;
+ }
+#endif
+ printf("%s\n", buf);
+ return EXIT_SUCCESS;
+}
diff --git a/Tests/IPO/CMakeLists.txt b/Tests/IPO/CMakeLists.txt
new file mode 100644
index 0000000000..6dabf86bbf
--- /dev/null
+++ b/Tests/IPO/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required (VERSION 2.8)
+project(IPO NONE)
+
+set_property(DIRECTORY PROPERTY INTERPROCEDURAL_OPTIMIZATION 1)
+
+add_subdirectory(../COnly COnly)
+add_subdirectory(../CxxOnly CxxOnly)
diff --git a/Tests/IncludeDirectories/CMP0021/CMakeLists.txt b/Tests/IncludeDirectories/CMP0021/CMakeLists.txt
new file mode 100644
index 0000000000..0b9aee899a
--- /dev/null
+++ b/Tests/IncludeDirectories/CMP0021/CMakeLists.txt
@@ -0,0 +1,14 @@
+
+cmake_policy(SET CMP0021 OLD)
+add_executable(cmp0021exe main.cpp)
+
+if(NOT CMAKE_CURRENT_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/includes")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E
+ copy_directory
+ "${CMAKE_CURRENT_SOURCE_DIR}/includes"
+ "${CMAKE_CURRENT_BINARY_DIR}/includes"
+ )
+endif()
+set_property(TARGET cmp0021exe PROPERTY
+ INCLUDE_DIRECTORIES includes/cmp0021)
diff --git a/Tests/IncludeDirectories/CMP0021/includes/cmp0021/cmp0021.h b/Tests/IncludeDirectories/CMP0021/includes/cmp0021/cmp0021.h
new file mode 100644
index 0000000000..3d49b31d57
--- /dev/null
+++ b/Tests/IncludeDirectories/CMP0021/includes/cmp0021/cmp0021.h
@@ -0,0 +1,2 @@
+
+#define CMP0021_DEFINE
diff --git a/Tests/IncludeDirectories/CMP0021/main.cpp b/Tests/IncludeDirectories/CMP0021/main.cpp
new file mode 100644
index 0000000000..f886c4629c
--- /dev/null
+++ b/Tests/IncludeDirectories/CMP0021/main.cpp
@@ -0,0 +1,11 @@
+
+#include "cmp0021.h"
+
+#ifndef CMP0021_DEFINE
+#error Expected CMP0021_DEFINE
+#endif
+
+int main(int, char **)
+{
+ return 0;
+}
diff --git a/Tests/IncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/CMakeLists.txt
new file mode 100644
index 0000000000..9ee195714c
--- /dev/null
+++ b/Tests/IncludeDirectories/CMakeLists.txt
@@ -0,0 +1,92 @@
+cmake_minimum_required (VERSION 2.6)
+project(IncludeDirectories)
+
+if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4)
+ OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL AppleClang)
+ AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja"))
+ include(CheckCXXCompilerFlag)
+ check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test)
+ if(run_sys_includes_test)
+ # The Bullseye wrapper appears to break the -isystem effect.
+ execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE out ERROR_VARIABLE out)
+ if("x${out}" MATCHES "Bullseye")
+ set(run_sys_includes_test 0)
+ endif()
+ endif()
+ if (run_sys_includes_test)
+ add_subdirectory(SystemIncludeDirectories)
+ endif()
+endif()
+
+file(WRITE ${CMAKE_BINARY_DIR}/Flags/Flags.h
+"//Flags.h
+")
+file(WRITE ${CMAKE_BINARY_DIR}/IncDir/IncDir.h
+"//IncDir.h
+")
+file(WRITE ${CMAKE_BINARY_DIR}/SrcProp/SrcProp.h
+"//SrcProp.h
+")
+file(WRITE ${CMAKE_BINARY_DIR}/TarProp/TarProp.h
+"//TarProp.h
+")
+
+# default to testing with full path
+# some compilers can not handle the escape for directories
+# with spaces in them.
+set(USE_FULLPATH TRUE)
+if(WATCOM OR MSVC60)
+ set(USE_FULLPATH FALSE)
+endif()
+if(USE_FULLPATH)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \"-I${CMAKE_BINARY_DIR}/Flags\"")
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -IFlags")
+endif()
+
+include_directories(${CMAKE_BINARY_DIR}/IncDir)
+if(USE_FULLPATH)
+ set_source_files_properties(main.cpp PROPERTIES COMPILE_FLAGS
+ "\"-I${CMAKE_BINARY_DIR}/SrcProp\"")
+else()
+ set_source_files_properties(main.cpp PROPERTIES COMPILE_FLAGS
+ "-ISrcProp")
+endif()
+
+add_executable(IncludeDirectories main.cpp)
+
+if(USE_FULLPATH)
+ set_target_properties(IncludeDirectories
+ PROPERTIES COMPILE_FLAGS "\"-I${CMAKE_BINARY_DIR}/TarProp\"")
+else()
+ set_target_properties(IncludeDirectories
+ PROPERTIES COMPILE_FLAGS "-ITarProp")
+endif()
+
+add_subdirectory(TargetIncludeDirectories)
+
+set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}")
+get_property(propContent DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
+if (NOT propContent STREQUAL "${CMAKE_BINARY_DIR}")
+ message(SEND_ERROR "Setting DIRECTORY property failed.")
+endif()
+set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
+get_property(propContentAfter DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
+if (NOT propContentAfter STREQUAL "")
+ message(SEND_ERROR "Clearing DIRECTORY property failed.")
+endif()
+
+add_library(empty_entry_test SHARED empty.cpp)
+set_target_properties(empty_entry_test PROPERTIES INCLUDE_DIRECTORIES "")
+include_directories(/one/two
+ " "
+ " "
+)
+get_target_property(incs empty_entry_test INCLUDE_DIRECTORIES)
+if (NOT incs STREQUAL ";/one/two")
+ message(SEND_ERROR "Empty include_directories entry was not ignored.")
+endif()
+
+if(NOT CMAKE_GENERATOR STREQUAL Xcode AND NOT CMAKE_GENERATOR STREQUAL Ninja)
+ add_subdirectory(CMP0021)
+endif()
diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt
new file mode 100644
index 0000000000..abe9f74d97
--- /dev/null
+++ b/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt
@@ -0,0 +1,51 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(SystemIncludeDirectories)
+
+add_library(systemlib systemlib.cpp)
+target_include_directories(systemlib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/systemlib")
+
+add_library(upstream upstream.cpp)
+target_link_libraries(upstream LINK_PUBLIC systemlib)
+target_compile_options(upstream PRIVATE -Werror=unused-variable)
+
+target_include_directories(upstream SYSTEM PUBLIC
+ $<TARGET_PROPERTY:systemlib,INTERFACE_INCLUDE_DIRECTORIES>
+)
+
+add_library(consumer consumer.cpp)
+target_link_libraries(consumer upstream)
+target_compile_options(consumer PRIVATE -Werror=unused-variable)
+
+add_library(iface IMPORTED INTERFACE)
+set_property(TARGET iface PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/systemlib_header_only")
+
+add_library(imported_consumer imported_consumer.cpp)
+target_link_libraries(imported_consumer iface)
+target_compile_options(imported_consumer PRIVATE -Werror=unused-variable)
+
+add_library(imported_consumer2 imported_consumer.cpp)
+target_link_libraries(imported_consumer2 imported_consumer)
+target_compile_options(imported_consumer2 PRIVATE -Werror=unused-variable)
+
+macro(do_try_compile error_option)
+ set(TC_ARGS
+ IFACE_TRY_COMPILE_${error_option}
+ "${CMAKE_CURRENT_BINARY_DIR}/try_compile_iface" "${CMAKE_CURRENT_SOURCE_DIR}/imported_consumer.cpp"
+ LINK_LIBRARIES iface
+ )
+ if (${error_option} STREQUAL WITH_ERROR)
+ list(APPEND TC_ARGS COMPILE_DEFINITIONS -Werror=unused-variable)
+ endif()
+ try_compile(${TC_ARGS})
+endmacro()
+
+do_try_compile(NO_ERROR)
+if (NOT IFACE_TRY_COMPILE_NO_ERROR)
+ message(SEND_ERROR "try_compile failed with imported target.")
+endif()
+do_try_compile(WITH_ERROR)
+if (NOT IFACE_TRY_COMPILE_WITH_ERROR)
+ message(SEND_ERROR "try_compile failed with imported target with error option.")
+endif()
diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/consumer.cpp b/Tests/IncludeDirectories/SystemIncludeDirectories/consumer.cpp
new file mode 100644
index 0000000000..197dae86d5
--- /dev/null
+++ b/Tests/IncludeDirectories/SystemIncludeDirectories/consumer.cpp
@@ -0,0 +1,7 @@
+
+#include "upstream.h"
+
+int consumer()
+{
+ return upstream();
+}
diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/imported_consumer.cpp b/Tests/IncludeDirectories/SystemIncludeDirectories/imported_consumer.cpp
new file mode 100644
index 0000000000..1dbe819e13
--- /dev/null
+++ b/Tests/IncludeDirectories/SystemIncludeDirectories/imported_consumer.cpp
@@ -0,0 +1,7 @@
+
+#include "systemlib.h"
+
+int main()
+{
+ return systemlib();
+}
diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/systemlib.cpp b/Tests/IncludeDirectories/SystemIncludeDirectories/systemlib.cpp
new file mode 100644
index 0000000000..f111bfa554
--- /dev/null
+++ b/Tests/IncludeDirectories/SystemIncludeDirectories/systemlib.cpp
@@ -0,0 +1,4 @@
+
+#include "systemlib.h"
+
+int systemlib() { return 0; }
diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/systemlib/systemlib.h b/Tests/IncludeDirectories/SystemIncludeDirectories/systemlib/systemlib.h
new file mode 100644
index 0000000000..c84de6a287
--- /dev/null
+++ b/Tests/IncludeDirectories/SystemIncludeDirectories/systemlib/systemlib.h
@@ -0,0 +1,19 @@
+
+#ifndef SYSTEMLIB_H
+#define SYSTEMLIB_H
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int systemlib();
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int unusedFunc()
+{
+ int unused;
+ return systemlib();
+}
+
+#endif
diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/systemlib_header_only/systemlib.h b/Tests/IncludeDirectories/SystemIncludeDirectories/systemlib_header_only/systemlib.h
new file mode 100644
index 0000000000..93622c433e
--- /dev/null
+++ b/Tests/IncludeDirectories/SystemIncludeDirectories/systemlib_header_only/systemlib.h
@@ -0,0 +1,16 @@
+
+#ifndef SYSTEMLIB_H
+#define SYSTEMLIB_H
+
+int systemlib()
+{
+ return 0;
+}
+
+int unusedFunc()
+{
+ int unused;
+ return systemlib();
+}
+
+#endif
diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/upstream.cpp b/Tests/IncludeDirectories/SystemIncludeDirectories/upstream.cpp
new file mode 100644
index 0000000000..f716b99e6d
--- /dev/null
+++ b/Tests/IncludeDirectories/SystemIncludeDirectories/upstream.cpp
@@ -0,0 +1,4 @@
+
+#include "upstream.h"
+
+int upstream() { return systemlib(); }
diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/upstream.h b/Tests/IncludeDirectories/SystemIncludeDirectories/upstream.h
new file mode 100644
index 0000000000..3628568cf8
--- /dev/null
+++ b/Tests/IncludeDirectories/SystemIncludeDirectories/upstream.h
@@ -0,0 +1,12 @@
+
+#ifndef UPSTREAM_H
+#define UPSTREAM_H
+
+#include "systemlib.h"
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int upstream();
+
+#endif
diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt
new file mode 100644
index 0000000000..8e2bd0a0d3
--- /dev/null
+++ b/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt
@@ -0,0 +1,170 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(TargetIncludeDirectories)
+
+macro(create_header _name)
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_name}")
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_name}/${_name}.h" "//${_name}.h\n")
+endmacro()
+
+create_header(bar)
+create_header(bat)
+create_header(foo)
+create_header(baz)
+create_header(bang)
+create_header(bing)
+create_header(bung)
+create_header(arguments)
+create_header(list)
+create_header(target)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/bar")
+include_directories("$<1:${CMAKE_CURRENT_BINARY_DIR}/bang>")
+
+add_executable(TargetIncludeDirectories main.cpp)
+
+set_property(TARGET TargetIncludeDirectories APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/bat")
+set_property(TARGET TargetIncludeDirectories APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/foo")
+set_property(TARGET TargetIncludeDirectories APPEND PROPERTY
+ INCLUDE_DIRECTORIES "$<1:${CMAKE_CURRENT_BINARY_DIR}/bing>")
+
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/baz")
+include_directories("$<1:${CMAKE_CURRENT_BINARY_DIR}/bung>")
+include_directories("sing$<1:/ting>")
+
+include_directories("$<1:${CMAKE_CURRENT_BINARY_DIR}/arguments;${CMAKE_CURRENT_BINARY_DIR}/list>")
+
+create_header(fee)
+create_header(fiy)
+create_header(foh)
+create_header(fum)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lib1.cpp" "#include \"fee.h\"\n")
+add_library(lib1 "${CMAKE_CURRENT_BINARY_DIR}/lib1.cpp")
+set_property(TARGET lib1 APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/fee")
+set_property(TARGET lib1 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/fiy")
+set_property(TARGET lib1 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:${CMAKE_CURRENT_BINARY_DIR}/foh>")
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lib2.cpp" "#include \"fiy.h\"\n")
+add_library(lib2 "${CMAKE_CURRENT_BINARY_DIR}/lib2.cpp")
+set_property(TARGET lib2 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/fum;$<TARGET_PROPERTY:lib1,INTERFACE_INCLUDE_DIRECTORIES>")
+set_property(TARGET lib2 APPEND PROPERTY INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:lib1,INTERFACE_INCLUDE_DIRECTORIES>")
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main3.cpp" "#include \"fiy.h\"\n#include \"foh.h\"\n#include \"fum.h\"\nint main(int,char**) { return 0; }\n")
+add_executable(exe3 "${CMAKE_CURRENT_BINARY_DIR}/main3.cpp")
+set_property(TARGET exe3 APPEND PROPERTY INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:lib2,INTERFACE_INCLUDE_DIRECTORIES>")
+
+# Test cycles
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lib3.cpp" "#include \"fiy.h\"\n#include \"foh.h\"\n")
+add_library(lib3 "${CMAKE_CURRENT_BINARY_DIR}/lib3.cpp")
+set_property(TARGET lib3 APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/fiy;$<TARGET_PROPERTY:lib4,INTERFACE_INCLUDE_DIRECTORIES>")
+set_property(TARGET lib3 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/fiy;$<TARGET_PROPERTY:lib4,INTERFACE_INCLUDE_DIRECTORIES>")
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lib4.cpp" "#include \"fiy.h\"\n#include \"foh.h\"\n")
+add_library(lib4 "${CMAKE_CURRENT_BINARY_DIR}/lib4.cpp")
+set_property(TARGET lib4 APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/foh;$<TARGET_PROPERTY:lib3,INTERFACE_INCLUDE_DIRECTORIES>")
+set_property(TARGET lib4 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/foh;$<TARGET_PROPERTY:lib3,INTERFACE_INCLUDE_DIRECTORIES>")
+
+add_library(somelib::withcolons UNKNOWN IMPORTED)
+set_property(TARGET somelib::withcolons PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/target")
+set_property(TARGET somelib::withcolons PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/target")
+
+set_property(TARGET TargetIncludeDirectories
+ APPEND PROPERTY INCLUDE_DIRECTORIES
+ "$<TARGET_PROPERTY:somelib::withcolons,INTERFACE_INCLUDE_DIRECTORIES>"
+)
+
+add_custom_target(test_custom_target
+ "some_bogus_custom_tool"
+ $<TARGET_PROPERTY:TargetIncludeDirectories,COMPILE_DEFINITIONS>
+ WORKING_DIRECTORY
+ "${CMAKE_CURRENT_SOURCE_DIR}")
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bad")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/bad/common.h" "#error Should not be included\n")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/good")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/good/common.h" "#include \"othergood.h\"\n")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/othergood")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/othergood/othergood.h" "// No error\n")
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libothergood.cpp" "// No content \n")
+add_library(libothergood "${CMAKE_CURRENT_BINARY_DIR}/libothergood.cpp")
+set_property(TARGET libothergood APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/othergood"
+)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libgood.cpp" "// No content \n")
+add_library(libgood "${CMAKE_CURRENT_BINARY_DIR}/libgood.cpp")
+set_property(TARGET libgood APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES
+ "${CMAKE_CURRENT_BINARY_DIR}/good;$<TARGET_PROPERTY:libothergood,INTERFACE_INCLUDE_DIRECTORIES>"
+)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libbad.cpp" "// No content \n")
+add_library(libbad "${CMAKE_CURRENT_BINARY_DIR}/libbad.cpp")
+set_property(TARGET libbad APPEND PROPERTY
+ INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/bad"
+)
+
+add_library(lib6 SHARED other.cpp)
+add_library(lib7 SHARED other.cpp)
+target_link_libraries(lib7 $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:lib6>)
+target_include_directories(lib7 PUBLIC $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:/lib7/include>)
+add_custom_target(head_target_test "some_bogus_custom_tool \"$<TARGET_PROPERTY:lib7,INCLUDE_DIRECTORIES>$<TARGET_PROPERTY:lib7,INTERFACE_INCLUDE_DIRECTORIES>\"")
+
+add_library(includes_source_good empty.cpp)
+target_include_directories(includes_source_good
+ INTERFACE
+ "${CMAKE_CURRENT_BINARY_DIR}/good"
+ "${CMAKE_CURRENT_BINARY_DIR}/othergood/"
+)
+add_library(includes_source_bad empty.cpp)
+target_include_directories(includes_source_bad
+ INTERFACE
+ "${CMAKE_CURRENT_BINARY_DIR}/bad"
+)
+
+add_library(includes_proxy SHARED empty.cpp)
+target_link_libraries(includes_proxy includes_source_good)
+target_link_libraries(includes_proxy LINK_INTERFACE_LIBRARIES includes_source_bad)
+add_executable(copy_includes copy_includes.cpp)
+target_include_directories(copy_includes PRIVATE $<TARGET_PROPERTY:includes_proxy,INCLUDE_DIRECTORIES>)
+
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lib5.cpp" "#include \"common.h\"\n")
+add_library(lib5 "${CMAKE_CURRENT_BINARY_DIR}/lib5.cpp")
+
+# Assuming the link order must be:
+target_link_libraries(lib5 libbad libgood)
+
+# Oops!.
+# As include directory order and link order are the same when using target_link_libraries, we have to
+# get the libgood includes in before the libbad includes.
+# We do that with this command:
+target_include_directories(lib5
+ BEFORE PRIVATE $<TARGET_PROPERTY:libgood,INTERFACE_INCLUDE_DIRECTORIES>
+)
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/prefix_foo/prefix_bar/prefix_bat")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/prefix_foo/prefix_bar/prefix_bat/prefix_foo_bar_bat.h" "// prefix_foo_bar_bat.h\n")
+
+target_include_directories(TargetIncludeDirectories PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/prefix_$<JOIN:foo;bar;bat,/prefix_>")
+
+# Test that the language generator expressions work
+set_property(TARGET TargetIncludeDirectories
+ APPEND PROPERTY INCLUDE_DIRECTORIES
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:${CMAKE_CURRENT_BINARY_DIR}/bad>"
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:${CMAKE_CURRENT_BINARY_DIR}/good>"
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:${CMAKE_CURRENT_BINARY_DIR}/othergood/>"
+)
+
+add_executable(TargetIncludeDirectories_C main.c)
+set_property(TARGET TargetIncludeDirectories_C
+ APPEND PROPERTY INCLUDE_DIRECTORIES
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:${CMAKE_CURRENT_BINARY_DIR}/bad>"
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:${CMAKE_CURRENT_BINARY_DIR}/good>"
+ "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:${CMAKE_CURRENT_BINARY_DIR}/othergood/>"
+)
diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/copy_includes.cpp b/Tests/IncludeDirectories/TargetIncludeDirectories/copy_includes.cpp
new file mode 100644
index 0000000000..fed4c03673
--- /dev/null
+++ b/Tests/IncludeDirectories/TargetIncludeDirectories/copy_includes.cpp
@@ -0,0 +1,7 @@
+
+#include "common.h"
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/empty.cpp b/Tests/IncludeDirectories/TargetIncludeDirectories/empty.cpp
new file mode 100644
index 0000000000..7279c5e0b9
--- /dev/null
+++ b/Tests/IncludeDirectories/TargetIncludeDirectories/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty(void)
+{
+ return 0;
+}
diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/main.c b/Tests/IncludeDirectories/TargetIncludeDirectories/main.c
new file mode 100644
index 0000000000..a597daad0e
--- /dev/null
+++ b/Tests/IncludeDirectories/TargetIncludeDirectories/main.c
@@ -0,0 +1,7 @@
+
+#include "common.h"
+
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp b/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp
new file mode 100644
index 0000000000..aed0bde46b
--- /dev/null
+++ b/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp
@@ -0,0 +1,19 @@
+
+#include "bar.h"
+#include "bat.h"
+#include "foo.h"
+#include "baz.h"
+#include "bang.h"
+#include "bing.h"
+#include "bung.h"
+#include "ting.h"
+#include "arguments.h"
+#include "list.h"
+#include "target.h"
+#include "prefix_foo_bar_bat.h"
+#include "common.h"
+
+int main(int, char**)
+{
+ return 0;
+}
diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/other.cpp b/Tests/IncludeDirectories/TargetIncludeDirectories/other.cpp
new file mode 100644
index 0000000000..6673471b5f
--- /dev/null
+++ b/Tests/IncludeDirectories/TargetIncludeDirectories/other.cpp
@@ -0,0 +1,6 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int other() {
+ return 0;
+}
diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/sing/ting/ting.h b/Tests/IncludeDirectories/TargetIncludeDirectories/sing/ting/ting.h
new file mode 100644
index 0000000000..4fe01dd3e0
--- /dev/null
+++ b/Tests/IncludeDirectories/TargetIncludeDirectories/sing/ting/ting.h
@@ -0,0 +1 @@
+//ting.h
diff --git a/Tests/IncludeDirectories/empty.cpp b/Tests/IncludeDirectories/empty.cpp
new file mode 100644
index 0000000000..1787013f64
--- /dev/null
+++ b/Tests/IncludeDirectories/empty.cpp
@@ -0,0 +1,4 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty() { return 0; }
diff --git a/Tests/IncludeDirectories/main.cpp b/Tests/IncludeDirectories/main.cpp
new file mode 100644
index 0000000000..a59d27c396
--- /dev/null
+++ b/Tests/IncludeDirectories/main.cpp
@@ -0,0 +1,9 @@
+#include "Flags.h"
+#include "IncDir.h"
+#include "SrcProp.h"
+#include "TarProp.h"
+
+int main(int argc, char** argv)
+{
+ return 0;
+}
diff --git a/Tests/InterfaceLibrary/CMakeLists.txt b/Tests/InterfaceLibrary/CMakeLists.txt
new file mode 100644
index 0000000000..fe202dd26a
--- /dev/null
+++ b/Tests/InterfaceLibrary/CMakeLists.txt
@@ -0,0 +1,58 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(InterfaceLibrary)
+
+add_library(iface_nodepends INTERFACE)
+target_compile_definitions(iface_nodepends INTERFACE IFACE_DEFINE)
+
+add_subdirectory(headerdir)
+
+# Add an interface target in a subdirectory that uses an imported interface.
+add_subdirectory(ifacedir)
+
+# Poison an imported interface with the same name as that in the subdir
+# to ensure that the transitive lookup occurs in the subdir.
+add_library(imp::iface INTERFACE IMPORTED)
+set_property(TARGET imp::iface APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SOMEPROP)
+set_property(TARGET imp::iface PROPERTY INTERFACE_SOMEPROP OFF)
+set_property(TARGET imp::iface PROPERTY INTERFACE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/does_not_exist.cpp)
+
+add_library(objlib OBJECT obj.cpp)
+add_library(iface_objlib INTERFACE)
+target_sources(iface_objlib INTERFACE $<TARGET_OBJECTS:objlib>)
+
+add_executable(InterfaceLibrary definetestexe.cpp)
+target_link_libraries(InterfaceLibrary iface_nodepends headeriface subiface iface_objlib)
+
+add_subdirectory(libsdir)
+
+add_executable(sharedlibtestexe sharedlibtestexe.cpp)
+target_link_libraries(sharedlibtestexe shared_iface imported::iface)
+
+add_library(broken EXCLUDE_FROM_ALL broken.cpp)
+
+add_library(iface_broken INTERFACE)
+# This is not a dependency, so broken will not be built (and the error in
+# it will not be hit)
+target_link_libraries(iface_broken INTERFACE broken)
+
+add_library(iface_whitelist INTERFACE)
+# The target property CUSTOM will never be evaluated on the INTERFACE library.
+target_link_libraries(iface_whitelist INTERFACE $<$<BOOL:$<TARGET_PROPERTY:CUSTOM>>:irrelevant>)
+
+add_executable(exec_whitelist dummy.cpp)
+target_link_libraries(exec_whitelist iface_whitelist)
+
+add_library(iface_imported INTERFACE IMPORTED)
+set_property(TARGET iface_imported PROPERTY
+ INTERFACE_COMPILE_DEFINITIONS
+ $<$<CONFIG:SPECIAL>:SPECIAL_MODE>
+ $<$<CONFIG:Debug>:DEBUG_MODE>
+)
+set_property(TARGET iface_imported PROPERTY
+ MAP_IMPORTED_CONFIG_DEBUG SPECIAL
+)
+
+add_executable(map_config map_config.cpp)
+target_link_libraries(map_config iface_imported)
diff --git a/Tests/InterfaceLibrary/broken.cpp b/Tests/InterfaceLibrary/broken.cpp
new file mode 100644
index 0000000000..1fd10416b4
--- /dev/null
+++ b/Tests/InterfaceLibrary/broken.cpp
@@ -0,0 +1,2 @@
+
+#error Broken
diff --git a/Tests/InterfaceLibrary/definetestexe.cpp b/Tests/InterfaceLibrary/definetestexe.cpp
new file mode 100644
index 0000000000..904407646a
--- /dev/null
+++ b/Tests/InterfaceLibrary/definetestexe.cpp
@@ -0,0 +1,24 @@
+
+#ifndef IFACE_DEFINE
+#error Expected IFACE_DEFINE
+#endif
+
+#include "iface_header.h"
+
+#ifndef IFACE_HEADER_SRCDIR
+#error Expected IFACE_HEADER_SRCDIR
+#endif
+
+#include "iface_header_builddir.h"
+
+#ifndef IFACE_HEADER_BUILDDIR
+#error Expected IFACE_HEADER_BUILDDIR
+#endif
+
+extern int obj();
+extern int sub();
+
+int main(int,char**)
+{
+ return obj() + sub();
+}
diff --git a/Tests/InterfaceLibrary/dummy.cpp b/Tests/InterfaceLibrary/dummy.cpp
new file mode 100644
index 0000000000..341aaafa0a
--- /dev/null
+++ b/Tests/InterfaceLibrary/dummy.cpp
@@ -0,0 +1,5 @@
+
+int main(int, char **)
+{
+ return 0;
+}
diff --git a/Tests/InterfaceLibrary/headerdir/CMakeLists.txt b/Tests/InterfaceLibrary/headerdir/CMakeLists.txt
new file mode 100644
index 0000000000..98f521e8ce
--- /dev/null
+++ b/Tests/InterfaceLibrary/headerdir/CMakeLists.txt
@@ -0,0 +1,8 @@
+
+set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+
+add_library(headeriface INTERFACE)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/iface_header_builddir.h"
+ "#define IFACE_HEADER_BUILDDIR\n"
+)
diff --git a/Tests/InterfaceLibrary/headerdir/iface_header.h b/Tests/InterfaceLibrary/headerdir/iface_header.h
new file mode 100644
index 0000000000..82dd157492
--- /dev/null
+++ b/Tests/InterfaceLibrary/headerdir/iface_header.h
@@ -0,0 +1 @@
+#define IFACE_HEADER_SRCDIR
diff --git a/Tests/InterfaceLibrary/ifacedir/CMakeLists.txt b/Tests/InterfaceLibrary/ifacedir/CMakeLists.txt
new file mode 100644
index 0000000000..228715e756
--- /dev/null
+++ b/Tests/InterfaceLibrary/ifacedir/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_library(imp::iface INTERFACE IMPORTED)
+set_property(TARGET imp::iface APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SOMEPROP)
+set_property(TARGET imp::iface PROPERTY INTERFACE_SOMEPROP ON)
+set_property(TARGET imp::iface PROPERTY INTERFACE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sub.cpp)
+
+add_library(subiface INTERFACE)
+target_link_libraries(subiface INTERFACE imp::iface)
+set_property(TARGET subiface PROPERTY INTERFACE_SOMEPROP ON)
diff --git a/Tests/InterfaceLibrary/ifacedir/sub.cpp b/Tests/InterfaceLibrary/ifacedir/sub.cpp
new file mode 100644
index 0000000000..165a66adbf
--- /dev/null
+++ b/Tests/InterfaceLibrary/ifacedir/sub.cpp
@@ -0,0 +1 @@
+int sub() { return 0; }
diff --git a/Tests/InterfaceLibrary/libsdir/CMakeLists.txt b/Tests/InterfaceLibrary/libsdir/CMakeLists.txt
new file mode 100644
index 0000000000..4e529dfb11
--- /dev/null
+++ b/Tests/InterfaceLibrary/libsdir/CMakeLists.txt
@@ -0,0 +1,28 @@
+
+include(GenerateExportHeader)
+
+add_library(sharedlib SHARED sharedlib.cpp)
+generate_export_header(sharedlib)
+
+add_library(shareddependlib SHARED shareddependlib.cpp)
+generate_export_header(shareddependlib)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+
+target_link_libraries(sharedlib PUBLIC shareddependlib)
+
+target_include_directories(shareddependlib
+ PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/shareddependlib")
+target_compile_definitions(shareddependlib
+ INTERFACE $<1:SHAREDDEPENDLIB_DEFINE>)
+
+target_include_directories(sharedlib
+ PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/sharedlib")
+target_compile_definitions(shareddependlib
+ INTERFACE $<1:SHAREDLIB_DEFINE>)
+
+add_library(shared_iface INTERFACE)
+target_link_libraries(shared_iface INTERFACE sharedlib)
+
+add_library(imported::iface INTERFACE IMPORTED GLOBAL)
diff --git a/Tests/InterfaceLibrary/libsdir/shareddependlib.cpp b/Tests/InterfaceLibrary/libsdir/shareddependlib.cpp
new file mode 100644
index 0000000000..378ba8165f
--- /dev/null
+++ b/Tests/InterfaceLibrary/libsdir/shareddependlib.cpp
@@ -0,0 +1,7 @@
+
+#include "shareddependlib.h"
+
+int SharedDependLibObject::foo() const
+{
+ return 0;
+}
diff --git a/Tests/InterfaceLibrary/libsdir/shareddependlib/shareddependlib.h b/Tests/InterfaceLibrary/libsdir/shareddependlib/shareddependlib.h
new file mode 100644
index 0000000000..ad9b484b7a
--- /dev/null
+++ b/Tests/InterfaceLibrary/libsdir/shareddependlib/shareddependlib.h
@@ -0,0 +1,12 @@
+
+#ifndef SHAREDDEPENDLIB_H
+#define SHAREDDEPENDLIB_H
+
+#include "shareddependlib_export.h"
+
+struct SHAREDDEPENDLIB_EXPORT SharedDependLibObject
+{
+ int foo() const;
+};
+
+#endif
diff --git a/Tests/InterfaceLibrary/libsdir/sharedlib.cpp b/Tests/InterfaceLibrary/libsdir/sharedlib.cpp
new file mode 100644
index 0000000000..c49ce905b1
--- /dev/null
+++ b/Tests/InterfaceLibrary/libsdir/sharedlib.cpp
@@ -0,0 +1,12 @@
+
+#include "sharedlib.h"
+
+SharedDependLibObject SharedLibObject::object() const
+{
+ SharedDependLibObject sdlo;
+ return sdlo;
+}
+int SharedLibObject::foo() const
+{
+ return 0;
+}
diff --git a/Tests/InterfaceLibrary/libsdir/sharedlib/sharedlib.h b/Tests/InterfaceLibrary/libsdir/sharedlib/sharedlib.h
new file mode 100644
index 0000000000..5b3c7db732
--- /dev/null
+++ b/Tests/InterfaceLibrary/libsdir/sharedlib/sharedlib.h
@@ -0,0 +1,15 @@
+
+#ifndef SHAREDLIB_H
+#define SHAREDLIB_H
+
+#include "sharedlib_export.h"
+
+#include "shareddependlib.h"
+
+struct SHAREDLIB_EXPORT SharedLibObject
+{
+ SharedDependLibObject object() const;
+ int foo() const;
+};
+
+#endif
diff --git a/Tests/InterfaceLibrary/map_config.cpp b/Tests/InterfaceLibrary/map_config.cpp
new file mode 100644
index 0000000000..81bb66605a
--- /dev/null
+++ b/Tests/InterfaceLibrary/map_config.cpp
@@ -0,0 +1,15 @@
+
+#ifdef DEBUG_MODE
+#ifndef SPECIAL_MODE
+#error Special configuration should be mapped to debug configuration.
+#endif
+#else
+#ifdef SPECIAL_MODE
+#error Special configuration should not be enabled if not debug configuration
+#endif
+#endif
+
+int main(int,char**)
+{
+ return 0;
+}
diff --git a/Tests/InterfaceLibrary/obj.cpp b/Tests/InterfaceLibrary/obj.cpp
new file mode 100644
index 0000000000..ee6f5fef27
--- /dev/null
+++ b/Tests/InterfaceLibrary/obj.cpp
@@ -0,0 +1 @@
+int obj() { return 0; }
diff --git a/Tests/InterfaceLibrary/sharedlibtestexe.cpp b/Tests/InterfaceLibrary/sharedlibtestexe.cpp
new file mode 100644
index 0000000000..c677f7067a
--- /dev/null
+++ b/Tests/InterfaceLibrary/sharedlibtestexe.cpp
@@ -0,0 +1,19 @@
+
+#ifndef SHAREDLIB_DEFINE
+#error Expected SHAREDLIB_DEFINE
+#endif
+
+#ifndef SHAREDDEPENDLIB_DEFINE
+#error Expected SHAREDDEPENDLIB_DEFINE
+#endif
+
+#include "sharedlib.h"
+#include "shareddependlib.h"
+
+int main(int,char**)
+{
+ SharedLibObject sl;
+ SharedDependLibObject sdl = sl.object();
+
+ return sdl.foo() + sl.foo();
+}
diff --git a/Tests/InterfaceLinkLibraries/CMakeLists.txt b/Tests/InterfaceLinkLibraries/CMakeLists.txt
new file mode 100644
index 0000000000..9e14c44005
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/CMakeLists.txt
@@ -0,0 +1,61 @@
+cmake_minimum_required (VERSION 2.8)
+
+cmake_policy(SET CMP0022 NEW)
+
+project(InterfaceLinkLibraries)
+
+add_library(foo_shared SHARED foo_vs6_1.cpp)
+target_compile_definitions(foo_shared INTERFACE FOO_LIBRARY)
+add_library(bar_shared SHARED bar_vs6_1.cpp)
+target_compile_definitions(bar_shared INTERFACE BAR_LIBRARY)
+set_property(TARGET bar_shared APPEND PROPERTY INTERFACE_LINK_LIBRARIES foo_shared)
+add_library(zot_shared SHARED zot_vs6_1.cpp)
+target_compile_definitions(zot_shared INTERFACE ZOT_LIBRARY)
+set_property(TARGET bar_shared APPEND PROPERTY INTERFACE_LINK_LIBRARIES $<LINK_ONLY:zot_shared>)
+
+add_executable(shared_test main_vs6_1.cpp)
+set_property(TARGET shared_test APPEND PROPERTY LINK_LIBRARIES bar_shared)
+
+add_library(foo_static STATIC foo_vs6_2.cpp)
+target_compile_definitions(foo_static INTERFACE FOO_LIBRARY)
+add_library(bar_static STATIC bar_vs6_2.cpp)
+target_compile_definitions(bar_static INTERFACE BAR_LIBRARY)
+set_property(TARGET bar_static APPEND PROPERTY INTERFACE_LINK_LIBRARIES foo_static)
+add_library(zot_static STATIC zot_vs6_2.cpp)
+target_compile_definitions(zot_static INTERFACE ZOT_LIBRARY)
+set_property(TARGET bar_static APPEND PROPERTY INTERFACE_LINK_LIBRARIES $<LINK_ONLY:zot_static>)
+
+add_executable(static_test main_vs6_2.cpp)
+set_property(TARGET static_test APPEND PROPERTY LINK_LIBRARIES bar_static)
+
+add_library(foo_shared_private SHARED foo_vs6_3.cpp)
+target_compile_definitions(foo_shared_private INTERFACE FOO_LIBRARY)
+add_library(bang_shared_private SHARED bang_vs6_1.cpp)
+target_compile_definitions(bang_shared_private INTERFACE BANG_LIBRARY)
+add_library(bar_shared_private SHARED bar_vs6_3.cpp)
+target_compile_definitions(bar_shared_private INTERFACE BAR_LIBRARY)
+target_compile_definitions(bar_shared_private PRIVATE BAR_USE_BANG)
+set_property(TARGET bar_shared_private APPEND PROPERTY LINK_LIBRARIES bang_shared_private)
+set_property(TARGET bar_shared_private APPEND PROPERTY INTERFACE_LINK_LIBRARIES foo_shared_private)
+add_library(zot_shared_private SHARED zot_vs6_3.cpp)
+target_compile_definitions(zot_shared_private INTERFACE ZOT_LIBRARY)
+set_property(TARGET bar_shared_private APPEND PROPERTY INTERFACE_LINK_LIBRARIES $<LINK_ONLY:zot_shared_private>)
+
+add_executable(shared_private_test main_vs6_3.cpp)
+set_property(TARGET shared_private_test APPEND PROPERTY LINK_LIBRARIES bar_shared_private)
+
+add_library(foo_static_private STATIC foo_vs6_4.cpp)
+target_compile_definitions(foo_static_private INTERFACE FOO_LIBRARY)
+add_library(bang_static_private STATIC bang_vs6_2.cpp)
+target_compile_definitions(bang_static_private INTERFACE BANG_LIBRARY)
+add_library(bar_static_private STATIC bar_vs6_4.cpp)
+target_compile_definitions(bar_static_private INTERFACE BAR_LIBRARY)
+target_compile_definitions(bar_static_private PRIVATE BAR_USE_BANG)
+set_property(TARGET bar_static_private APPEND PROPERTY LINK_LIBRARIES bang_static_private)
+set_property(TARGET bar_static_private APPEND PROPERTY INTERFACE_LINK_LIBRARIES $<LINK_ONLY:bang_static_private> foo_static_private)
+add_library(zot_static_private STATIC zot_vs6_4.cpp)
+target_compile_definitions(zot_static_private INTERFACE ZOT_LIBRARY)
+set_property(TARGET bar_static_private APPEND PROPERTY INTERFACE_LINK_LIBRARIES $<LINK_ONLY:zot_static_private>)
+
+add_executable(InterfaceLinkLibraries main_vs6_4.cpp)
+set_property(TARGET InterfaceLinkLibraries APPEND PROPERTY LINK_LIBRARIES bar_static_private)
diff --git a/Tests/InterfaceLinkLibraries/bang.cpp b/Tests/InterfaceLinkLibraries/bang.cpp
new file mode 100644
index 0000000000..2e950986be
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bang.cpp
@@ -0,0 +1,15 @@
+
+#ifdef FOO_LIBRARY
+#error Unexpected FOO_LIBRARY
+#endif
+
+#ifdef BAR_LIBRARY
+#error Unexpected BAR_LIBRARY
+#endif
+
+#include "bang.h"
+
+int bang()
+{
+ return 0;
+}
diff --git a/Tests/InterfaceLinkLibraries/bang.h b/Tests/InterfaceLinkLibraries/bang.h
new file mode 100644
index 0000000000..acffb39d94
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bang.h
@@ -0,0 +1,4 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int bang();
diff --git a/Tests/InterfaceLinkLibraries/bang_vs6_1.cpp b/Tests/InterfaceLinkLibraries/bang_vs6_1.cpp
new file mode 100644
index 0000000000..488686144f
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bang_vs6_1.cpp
@@ -0,0 +1 @@
+#include "bang.cpp"
diff --git a/Tests/InterfaceLinkLibraries/bang_vs6_2.cpp b/Tests/InterfaceLinkLibraries/bang_vs6_2.cpp
new file mode 100644
index 0000000000..488686144f
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bang_vs6_2.cpp
@@ -0,0 +1 @@
+#include "bang.cpp"
diff --git a/Tests/InterfaceLinkLibraries/bar.cpp b/Tests/InterfaceLinkLibraries/bar.cpp
new file mode 100644
index 0000000000..f39bfa55e5
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bar.cpp
@@ -0,0 +1,26 @@
+
+#ifdef FOO_LIBRARY
+#error Unexpected FOO_LIBRARY
+#endif
+
+#ifdef BAR_USE_BANG
+# ifndef BANG_LIBRARY
+# error Expected BANG_LIBRARY
+# endif
+# include "bang.h"
+#else
+# ifdef BANG_LIBRARY
+# error Unexpected BANG_LIBRARY
+# endif
+#endif
+
+#include "bar.h"
+
+int bar()
+{
+#ifdef BAR_USE_BANG
+ return bang();
+#else
+ return 0;
+#endif
+}
diff --git a/Tests/InterfaceLinkLibraries/bar.h b/Tests/InterfaceLinkLibraries/bar.h
new file mode 100644
index 0000000000..f83b37e572
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bar.h
@@ -0,0 +1,7 @@
+
+#include "foo.h"
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int bar();
diff --git a/Tests/InterfaceLinkLibraries/bar_vs6_1.cpp b/Tests/InterfaceLinkLibraries/bar_vs6_1.cpp
new file mode 100644
index 0000000000..58a04c402d
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bar_vs6_1.cpp
@@ -0,0 +1 @@
+#include "bar.cpp"
diff --git a/Tests/InterfaceLinkLibraries/bar_vs6_2.cpp b/Tests/InterfaceLinkLibraries/bar_vs6_2.cpp
new file mode 100644
index 0000000000..58a04c402d
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bar_vs6_2.cpp
@@ -0,0 +1 @@
+#include "bar.cpp"
diff --git a/Tests/InterfaceLinkLibraries/bar_vs6_3.cpp b/Tests/InterfaceLinkLibraries/bar_vs6_3.cpp
new file mode 100644
index 0000000000..58a04c402d
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bar_vs6_3.cpp
@@ -0,0 +1 @@
+#include "bar.cpp"
diff --git a/Tests/InterfaceLinkLibraries/bar_vs6_4.cpp b/Tests/InterfaceLinkLibraries/bar_vs6_4.cpp
new file mode 100644
index 0000000000..58a04c402d
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/bar_vs6_4.cpp
@@ -0,0 +1 @@
+#include "bar.cpp"
diff --git a/Tests/InterfaceLinkLibraries/foo.cpp b/Tests/InterfaceLinkLibraries/foo.cpp
new file mode 100644
index 0000000000..5295707b53
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/foo.cpp
@@ -0,0 +1,15 @@
+
+#ifdef BAR_LIBRARY
+#error Unexpected BAR_LIBRARY
+#endif
+
+#ifdef BANG_LIBRARY
+#error Unexpected BANG_LIBRARY
+#endif
+
+#include "foo.h"
+
+int foo()
+{
+ return 0;
+}
diff --git a/Tests/InterfaceLinkLibraries/foo.h b/Tests/InterfaceLinkLibraries/foo.h
new file mode 100644
index 0000000000..e12e23c499
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/foo.h
@@ -0,0 +1,4 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int foo();
diff --git a/Tests/InterfaceLinkLibraries/foo_vs6_1.cpp b/Tests/InterfaceLinkLibraries/foo_vs6_1.cpp
new file mode 100644
index 0000000000..d2e5e52be5
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/foo_vs6_1.cpp
@@ -0,0 +1 @@
+#include "foo.cpp"
diff --git a/Tests/InterfaceLinkLibraries/foo_vs6_2.cpp b/Tests/InterfaceLinkLibraries/foo_vs6_2.cpp
new file mode 100644
index 0000000000..d2e5e52be5
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/foo_vs6_2.cpp
@@ -0,0 +1 @@
+#include "foo.cpp"
diff --git a/Tests/InterfaceLinkLibraries/foo_vs6_3.cpp b/Tests/InterfaceLinkLibraries/foo_vs6_3.cpp
new file mode 100644
index 0000000000..d2e5e52be5
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/foo_vs6_3.cpp
@@ -0,0 +1 @@
+#include "foo.cpp"
diff --git a/Tests/InterfaceLinkLibraries/foo_vs6_4.cpp b/Tests/InterfaceLinkLibraries/foo_vs6_4.cpp
new file mode 100644
index 0000000000..d2e5e52be5
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/foo_vs6_4.cpp
@@ -0,0 +1 @@
+#include "foo.cpp"
diff --git a/Tests/InterfaceLinkLibraries/main.cpp b/Tests/InterfaceLinkLibraries/main.cpp
new file mode 100644
index 0000000000..6e1295a10c
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/main.cpp
@@ -0,0 +1,23 @@
+
+#ifndef FOO_LIBRARY
+#error Expected FOO_LIBRARY
+#endif
+
+#ifndef BAR_LIBRARY
+#error Expected BAR_LIBRARY
+#endif
+
+#ifdef BANG_LIBRARY
+#error Unexpected BANG_LIBRARY
+#endif
+
+#ifdef ZOT_LIBRARY
+#error Unexpected ZOT_LIBRARY
+#endif
+
+#include "zot.h"
+
+int main(void)
+{
+ return foo() + bar() + zot();
+}
diff --git a/Tests/InterfaceLinkLibraries/main_vs6_1.cpp b/Tests/InterfaceLinkLibraries/main_vs6_1.cpp
new file mode 100644
index 0000000000..9b10ef2f86
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/main_vs6_1.cpp
@@ -0,0 +1 @@
+#include "main.cpp"
diff --git a/Tests/InterfaceLinkLibraries/main_vs6_2.cpp b/Tests/InterfaceLinkLibraries/main_vs6_2.cpp
new file mode 100644
index 0000000000..9b10ef2f86
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/main_vs6_2.cpp
@@ -0,0 +1 @@
+#include "main.cpp"
diff --git a/Tests/InterfaceLinkLibraries/main_vs6_3.cpp b/Tests/InterfaceLinkLibraries/main_vs6_3.cpp
new file mode 100644
index 0000000000..9b10ef2f86
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/main_vs6_3.cpp
@@ -0,0 +1 @@
+#include "main.cpp"
diff --git a/Tests/InterfaceLinkLibraries/main_vs6_4.cpp b/Tests/InterfaceLinkLibraries/main_vs6_4.cpp
new file mode 100644
index 0000000000..9b10ef2f86
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/main_vs6_4.cpp
@@ -0,0 +1 @@
+#include "main.cpp"
diff --git a/Tests/InterfaceLinkLibraries/zot.cpp b/Tests/InterfaceLinkLibraries/zot.cpp
new file mode 100644
index 0000000000..69462b0630
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/zot.cpp
@@ -0,0 +1,6 @@
+#include "zot.h"
+
+int zot()
+{
+ return 0;
+}
diff --git a/Tests/InterfaceLinkLibraries/zot.h b/Tests/InterfaceLinkLibraries/zot.h
new file mode 100644
index 0000000000..5e4fb1ebae
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/zot.h
@@ -0,0 +1,7 @@
+
+#include "bar.h"
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int zot();
diff --git a/Tests/InterfaceLinkLibraries/zot_vs6_1.cpp b/Tests/InterfaceLinkLibraries/zot_vs6_1.cpp
new file mode 100644
index 0000000000..c588c5fe99
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/zot_vs6_1.cpp
@@ -0,0 +1 @@
+#include "zot.cpp"
diff --git a/Tests/InterfaceLinkLibraries/zot_vs6_2.cpp b/Tests/InterfaceLinkLibraries/zot_vs6_2.cpp
new file mode 100644
index 0000000000..c588c5fe99
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/zot_vs6_2.cpp
@@ -0,0 +1 @@
+#include "zot.cpp"
diff --git a/Tests/InterfaceLinkLibraries/zot_vs6_3.cpp b/Tests/InterfaceLinkLibraries/zot_vs6_3.cpp
new file mode 100644
index 0000000000..c588c5fe99
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/zot_vs6_3.cpp
@@ -0,0 +1 @@
+#include "zot.cpp"
diff --git a/Tests/InterfaceLinkLibraries/zot_vs6_4.cpp b/Tests/InterfaceLinkLibraries/zot_vs6_4.cpp
new file mode 100644
index 0000000000..c588c5fe99
--- /dev/null
+++ b/Tests/InterfaceLinkLibraries/zot_vs6_4.cpp
@@ -0,0 +1 @@
+#include "zot.cpp"
diff --git a/Tests/JCTest/CMakeLists.txt b/Tests/JCTest/CMakeLists.txt
new file mode 100644
index 0000000000..31dcc3abfa
--- /dev/null
+++ b/Tests/JCTest/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 2.6)
+project(TestTime)
+enable_testing()
+add_executable(TestTime TestTime.cxx)
+
+foreach(f 1 2 3 4 5 6 7 8 9 10 11 12 12 14 15 16 17 18 19
+20 21 22 23 24 25 26 27 28 29 30)
+ add_test(TestTime${f} TestTime 50000000)
+endforeach()
diff --git a/Tests/JCTest/TestTime.cxx b/Tests/JCTest/TestTime.cxx
new file mode 100644
index 0000000000..5768ab5227
--- /dev/null
+++ b/Tests/JCTest/TestTime.cxx
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int ac, char** av)
+{
+ float d = 10.0;
+ for(int i =0; i < atoi(av[1]); i++)
+ {
+ d *= .2;
+ }
+ printf("%f", d);
+}
diff --git a/Tests/JacocoCoverage/Coverage/src/main/java/org/cmake/CoverageTest.java b/Tests/JacocoCoverage/Coverage/src/main/java/org/cmake/CoverageTest.java
new file mode 100644
index 0000000000..4fb43c6084
--- /dev/null
+++ b/Tests/JacocoCoverage/Coverage/src/main/java/org/cmake/CoverageTest.java
@@ -0,0 +1,52 @@
+package org.cmake.Coverage;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.List;
+import java.awt.*;
+
+public class CoverageTest {
+
+ public static String VarOne = "test1";
+ public static String VarTwo = "test2";
+ private Integer IntOne = 4;
+
+ public static Boolean equalsVarOne(String inString) {
+
+ if(VarOne.equals(inString)){
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ public static boolean equalsVarTwo(String inString){
+
+ if(VarTwo.equals(inString)){
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ private Integer timesIntOne(Integer inVal){
+
+ return inVal * IntOne;
+ }
+
+ public static boolean whileLoop(Integer StopInt){
+
+ Integer i = 0;
+ while(i < StopInt){
+ i=i+1;
+ }
+ if (i.equals(5)){
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+}
diff --git a/Tests/JacocoCoverage/Coverage/target/site/jacoco.xml b/Tests/JacocoCoverage/Coverage/target/site/jacoco.xml
new file mode 100644
index 0000000000..49c3e87409
--- /dev/null
+++ b/Tests/JacocoCoverage/Coverage/target/site/jacoco.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.0//EN" "report.dtd"><report name="Coverage"><sessioninfo id="vagrant-ubuntu-precise-32-f1c264e9" start="1402427058670" dump="1402427059269"/><package name="org/cmake"><class name="org/cmake/Coverage/CoverageTest"><method name="&lt;init&gt;" desc="()V" line="8"><counter type="INSTRUCTION" missed="7" covered="0"/><counter type="LINE" missed="2" covered="0"/><counter type="COMPLEXITY" missed="1" covered="0"/><counter type="METHOD" missed="1" covered="0"/></method><method name="equalsVarOne" desc="(Ljava/lang/String;)Ljava/lang/Boolean;" line="16"><counter type="INSTRUCTION" missed="3" covered="7"/><counter type="BRANCH" missed="1" covered="1"/><counter type="LINE" missed="1" covered="2"/><counter type="COMPLEXITY" missed="1" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="equalsVarTwo" desc="(Ljava/lang/String;)Z" line="26"><counter type="INSTRUCTION" missed="0" covered="8"/><counter type="BRANCH" missed="0" covered="2"/><counter type="LINE" missed="0" covered="3"/><counter type="COMPLEXITY" missed="0" covered="2"/><counter type="METHOD" missed="0" covered="1"/></method><method name="timesIntOne" desc="(Ljava/lang/Integer;)Ljava/lang/Integer;" line="36"><counter type="INSTRUCTION" missed="8" covered="0"/><counter type="LINE" missed="1" covered="0"/><counter type="COMPLEXITY" missed="1" covered="0"/><counter type="METHOD" missed="1" covered="0"/></method><method name="whileLoop" desc="(Ljava/lang/Integer;)Z" line="41"><counter type="INSTRUCTION" missed="0" covered="24"/><counter type="BRANCH" missed="0" covered="4"/><counter type="LINE" missed="0" covered="6"/><counter type="COMPLEXITY" missed="0" covered="3"/><counter type="METHOD" missed="0" covered="1"/></method><method name="&lt;clinit&gt;" desc="()V" line="10"><counter type="INSTRUCTION" missed="0" covered="5"/><counter type="LINE" missed="0" covered="2"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><counter type="INSTRUCTION" missed="18" covered="44"/><counter type="BRANCH" missed="1" covered="7"/><counter type="LINE" missed="4" covered="13"/><counter type="COMPLEXITY" missed="3" covered="7"/><counter type="METHOD" missed="2" covered="4"/><counter type="CLASS" missed="0" covered="1"/></class><sourcefile name="CoverageTest.java"><line nr="8" mi="2" ci="0" mb="0" cb="0"/><line nr="10" mi="0" ci="2" mb="0" cb="0"/><line nr="11" mi="0" ci="3" mb="0" cb="0"/><line nr="12" mi="5" ci="0" mb="0" cb="0"/><line nr="16" mi="0" ci="4" mb="1" cb="1"/><line nr="17" mi="0" ci="3" mb="0" cb="0"/><line nr="20" mi="3" ci="0" mb="0" cb="0"/><line nr="26" mi="0" ci="4" mb="0" cb="2"/><line nr="27" mi="0" ci="2" mb="0" cb="0"/><line nr="30" mi="0" ci="2" mb="0" cb="0"/><line nr="36" mi="8" ci="0" mb="0" cb="0"/><line nr="41" mi="0" ci="3" mb="0" cb="0"/><line nr="42" mi="0" ci="5" mb="0" cb="2"/><line nr="43" mi="0" ci="7" mb="0" cb="0"/><line nr="45" mi="0" ci="5" mb="0" cb="2"/><line nr="46" mi="0" ci="2" mb="0" cb="0"/><line nr="49" mi="0" ci="2" mb="0" cb="0"/><counter type="INSTRUCTION" missed="18" covered="44"/><counter type="BRANCH" missed="1" covered="7"/><counter type="LINE" missed="4" covered="13"/><counter type="COMPLEXITY" missed="3" covered="7"/><counter type="METHOD" missed="2" covered="4"/><counter type="CLASS" missed="0" covered="1"/></sourcefile><counter type="INSTRUCTION" missed="18" covered="44"/><counter type="BRANCH" missed="1" covered="7"/><counter type="LINE" missed="4" covered="13"/><counter type="COMPLEXITY" missed="3" covered="7"/><counter type="METHOD" missed="2" covered="4"/><counter type="CLASS" missed="0" covered="1"/></package><counter type="INSTRUCTION" missed="18" covered="44"/><counter type="BRANCH" missed="1" covered="7"/><counter type="LINE" missed="4" covered="13"/><counter type="COMPLEXITY" missed="3" covered="7"/><counter type="METHOD" missed="2" covered="4"/><counter type="CLASS" missed="0" covered="1"/></report>
diff --git a/Tests/JacocoCoverage/DartConfiguration.tcl.in b/Tests/JacocoCoverage/DartConfiguration.tcl.in
new file mode 100644
index 0000000000..cc10e9c766
--- /dev/null
+++ b/Tests/JacocoCoverage/DartConfiguration.tcl.in
@@ -0,0 +1,8 @@
+# This file is configured by CMake automatically as DartConfiguration.tcl
+# If you choose not to use CMake, this file may be hand configured, by
+# filling in the required variables.
+
+
+# Configuration directories and files
+SourceDirectory: ${CMake_BINARY_DIR}/Testing/JacocoCoverage
+BuildDirectory: ${CMake_BINARY_DIR}/Testing/JacocoCoverage
diff --git a/Tests/Java/A.java b/Tests/Java/A.java
new file mode 100644
index 0000000000..403a7f889d
--- /dev/null
+++ b/Tests/Java/A.java
@@ -0,0 +1,11 @@
+class A
+{
+ public A()
+ {
+ }
+
+ public void printName()
+ {
+ System.out.println("A");
+ }
+}
diff --git a/Tests/Java/CMakeLists.txt b/Tests/Java/CMakeLists.txt
new file mode 100644
index 0000000000..6a69a24643
--- /dev/null
+++ b/Tests/Java/CMakeLists.txt
@@ -0,0 +1,9 @@
+project(hello Java)
+
+cmake_minimum_required (VERSION 2.6)
+set(CMAKE_VERBOSE_MAKEFILE 1)
+
+find_package(Java COMPONENTS Development)
+include (UseJava)
+
+add_jar(hello A.java HelloWorld.java)
diff --git a/Tests/Java/HelloWorld.java b/Tests/Java/HelloWorld.java
new file mode 100644
index 0000000000..378e37193d
--- /dev/null
+++ b/Tests/Java/HelloWorld.java
@@ -0,0 +1,11 @@
+class HelloWorld
+{
+ public static void main(String args[])
+ {
+ A a;
+ a = new A();
+ a.printName();
+ System.out.println("Hello World!");
+ }
+}
+
diff --git a/Tests/Jump/CMakeLists.txt b/Tests/Jump/CMakeLists.txt
new file mode 100644
index 0000000000..4c5ad303f1
--- /dev/null
+++ b/Tests/Jump/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required (VERSION 2.6)
+project(Jump)
+
+set(CMAKE_IGNORE_DEPENDENCIES_ORDERING 1)
+add_subdirectory(Executable)
+add_subdirectory(Library)
diff --git a/Tests/Jump/Executable/CMakeLists.txt b/Tests/Jump/Executable/CMakeLists.txt
new file mode 100644
index 0000000000..bc6731ff14
--- /dev/null
+++ b/Tests/Jump/Executable/CMakeLists.txt
@@ -0,0 +1,6 @@
+if(NOT LIBRARY_OUTPUT_PATH)
+ link_directories(${Jump_BINARY_DIR}/Library/Static
+ ${Jump_BINARY_DIR}/Library/Shared)
+endif()
+add_executable(jumpExecutable jumpExecutable.cxx)
+target_link_libraries(jumpExecutable jumpStatic jumpShared)
diff --git a/Tests/Jump/Executable/jumpExecutable.cxx b/Tests/Jump/Executable/jumpExecutable.cxx
new file mode 100644
index 0000000000..7a050c7028
--- /dev/null
+++ b/Tests/Jump/Executable/jumpExecutable.cxx
@@ -0,0 +1,12 @@
+#ifdef _WIN32
+# define JUMP_IMPORT __declspec(dllimport)
+#else
+# define JUMP_IMPORT extern
+#endif
+
+extern int jumpStatic();
+JUMP_IMPORT int jumpShared();
+int main()
+{
+ return jumpShared() && jumpShared();
+}
diff --git a/Tests/Jump/Library/CMakeLists.txt b/Tests/Jump/Library/CMakeLists.txt
new file mode 100644
index 0000000000..1d9fed934f
--- /dev/null
+++ b/Tests/Jump/Library/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(Static)
+add_subdirectory(Shared)
diff --git a/Tests/Jump/Library/Shared/CMakeLists.txt b/Tests/Jump/Library/Shared/CMakeLists.txt
new file mode 100644
index 0000000000..a37299a799
--- /dev/null
+++ b/Tests/Jump/Library/Shared/CMakeLists.txt
@@ -0,0 +1,26 @@
+add_library(jumpShared SHARED jumpShared.cxx)
+
+if(WIN32 OR CYGWIN)
+ set(SHARED_MUST_BE_IN_EXE_DIR 1)
+endif()
+
+if(APPLE)
+ set(SHARED_MUST_BE_IN_EXE_DIR 1)
+endif()
+
+if(SHARED_MUST_BE_IN_EXE_DIR)
+ set(LIB_NAME
+ ${CMAKE_SHARED_LIBRARY_PREFIX}jumpShared${CMAKE_SHARED_LIBRARY_SUFFIX})
+ set(EXE_DIR ${Jump_BINARY_DIR}/Executable)
+ if(EXECUTABLE_OUTPUT_PATH)
+ set(EXE_DIR ${EXECUTABLE_OUTPUT_PATH})
+ endif()
+ set(LIB_DIR ${Jump_BINARY_DIR}/Library/Shared)
+ if(LIBRARY_OUTPUT_PATH)
+ set(LIB_DIR ${LIBRARY_OUTPUT_PATH})
+ endif()
+ add_custom_command(TARGET jumpShared
+ POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy
+ ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME}
+ ${EXE_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME})
+endif()
diff --git a/Tests/Jump/Library/Shared/jumpShared.cxx b/Tests/Jump/Library/Shared/jumpShared.cxx
new file mode 100644
index 0000000000..f500058cc8
--- /dev/null
+++ b/Tests/Jump/Library/Shared/jumpShared.cxx
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+# define JUMP_EXPORT __declspec(dllexport)
+#else
+# define JUMP_EXPORT
+#endif
+
+JUMP_EXPORT int jumpShared() { return 0; }
diff --git a/Tests/Jump/Library/Static/CMakeLists.txt b/Tests/Jump/Library/Static/CMakeLists.txt
new file mode 100644
index 0000000000..4ee39545a4
--- /dev/null
+++ b/Tests/Jump/Library/Static/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(jumpStatic STATIC jumpStatic.cxx)
diff --git a/Tests/Jump/Library/Static/jumpStatic.cxx b/Tests/Jump/Library/Static/jumpStatic.cxx
new file mode 100644
index 0000000000..1f92eb9986
--- /dev/null
+++ b/Tests/Jump/Library/Static/jumpStatic.cxx
@@ -0,0 +1 @@
+int jumpStatic() { return 0; }
diff --git a/Tests/LibName/CMakeLists.txt b/Tests/LibName/CMakeLists.txt
new file mode 100644
index 0000000000..3ac125fb97
--- /dev/null
+++ b/Tests/LibName/CMakeLists.txt
@@ -0,0 +1,26 @@
+project(LibName)
+# this is a test to make sure that relative path
+# LIBRARY_OUTPUT_PATH and EXECUTABLE_OUTPUT_PATH work
+set(LIBRARY_OUTPUT_PATH lib)
+set(EXECUTABLE_OUTPUT_PATH lib)
+
+add_library(bar SHARED bar.c)
+
+add_library(foo SHARED foo.c)
+target_link_libraries(foo bar)
+
+add_executable(foobar foobar.c)
+target_link_libraries(foobar foo)
+if(UNIX)
+ target_link_libraries(foobar -L/usr/local/lib)
+endif()
+
+
+# check with lib version
+
+add_library(verFoo SHARED foo.c)
+target_link_libraries(verFoo bar)
+set_target_properties(verFoo PROPERTIES VERSION 3.1.4 SOVERSION 3)
+
+add_executable(verFoobar foobar.c)
+target_link_libraries(verFoobar verFoo)
diff --git a/Tests/LibName/bar.c b/Tests/LibName/bar.c
new file mode 100644
index 0000000000..f82aa28e83
--- /dev/null
+++ b/Tests/LibName/bar.c
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+
+extern void foo()
+{
+}
diff --git a/Tests/LibName/foo.c b/Tests/LibName/foo.c
new file mode 100644
index 0000000000..6d258e0e96
--- /dev/null
+++ b/Tests/LibName/foo.c
@@ -0,0 +1,11 @@
+#ifdef _WIN32
+__declspec(dllimport)
+#endif
+extern void foo();
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+ void bar()
+{
+ foo();
+}
diff --git a/Tests/LibName/foobar.c b/Tests/LibName/foobar.c
new file mode 100644
index 0000000000..2f8a3ff087
--- /dev/null
+++ b/Tests/LibName/foobar.c
@@ -0,0 +1,10 @@
+#ifdef _WIN32
+__declspec(dllimport)
+#endif
+extern void bar();
+
+int main()
+{
+ bar();
+ return 0;
+}
diff --git a/Tests/LinkDirectory/CMakeLists.txt b/Tests/LinkDirectory/CMakeLists.txt
new file mode 100644
index 0000000000..c60de84e96
--- /dev/null
+++ b/Tests/LinkDirectory/CMakeLists.txt
@@ -0,0 +1,45 @@
+cmake_minimum_required(VERSION 2.8)
+project(LinkDirectory C)
+
+# Put the subproject source tree in our build tree so it can refer to
+# link directories relative to its source.
+if(NOT "${LinkDirectory_SOURCE_DIR}" STREQUAL "${LinkDirectory_BINARY_DIR}")
+ file(COPY External/ DESTINATION External PATTERN CVS EXCLUDE)
+endif()
+
+# Build a library into the subproject source tree.
+add_library(mylibA STATIC mylibA.c)
+set_property(TARGET mylibA PROPERTY
+ ARCHIVE_OUTPUT_DIRECTORY "${LinkDirectory_BINARY_DIR}/External/lib")
+
+# Build a library into our build tree relative to the subproject build tree.
+add_library(mylibB STATIC mylibB.c)
+set_property(TARGET mylibB PROPERTY
+ ARCHIVE_OUTPUT_DIRECTORY "${LinkDirectory_BINARY_DIR}/lib")
+
+# Create a custom target to drive the subproject build.
+include(ExternalProject)
+ExternalProject_Add(ExternalTarget
+ SOURCE_DIR "${LinkDirectory_BINARY_DIR}/External"
+ BINARY_DIR "${LinkDirectory_BINARY_DIR}/External-build"
+ CMAKE_ARGS "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${LinkDirectory_BINARY_DIR}/bin"
+ PREFIX "${LinkDirectory_BINARY_DIR}/External-build/root"
+ DOWNLOAD_COMMAND ""
+ INSTALL_COMMAND ""
+ )
+
+# Add a step to wipe out the subproject executable after our libraries
+# change. This is needed because the subproject cannot depend on them
+# directly because it does not know the full paths to the libraries.
+# (The purpose of this test is to check that link_directories works.)
+ExternalProject_Add_Step(ExternalTarget cleanup
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${LinkDirectory_BINARY_DIR}/bin
+ DEPENDEES download
+ DEPENDERS configure
+ DEPENDS mylibA mylibB
+ "${LinkDirectory_BINARY_DIR}/External/CMakeLists.txt"
+ "${LinkDirectory_BINARY_DIR}/External/myexe.c"
+ )
+
+# Make the subproject build after our targets.
+add_dependencies(ExternalTarget mylibA mylibB)
diff --git a/Tests/LinkDirectory/External/CMakeLists.txt b/Tests/LinkDirectory/External/CMakeLists.txt
new file mode 100644
index 0000000000..f7c840f9a2
--- /dev/null
+++ b/Tests/LinkDirectory/External/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 2.8)
+project(LinkDirectoryExternal C)
+
+# Test CMP0015 OLD behavior: -L../lib
+cmake_policy(SET CMP0015 OLD)
+link_directories(../lib)
+
+# Test CMP0015 NEW behavior: -L${CMAKE_CURRENT_SOURCE_DIR}/lib
+cmake_policy(SET CMP0015 NEW)
+link_directories(lib)
+
+add_executable(myexe myexe.c)
+set_property(TARGET myexe PROPERTY OUTPUT_NAME LinkDirectory)
+target_link_libraries(myexe mylibA mylibB)
diff --git a/Tests/LinkDirectory/External/myexe.c b/Tests/LinkDirectory/External/myexe.c
new file mode 100644
index 0000000000..6ef1ebe598
--- /dev/null
+++ b/Tests/LinkDirectory/External/myexe.c
@@ -0,0 +1,3 @@
+extern int mylibA(void);
+extern int mylibB(void);
+int main(void) { return mylibA() + mylibB(); }
diff --git a/Tests/LinkDirectory/mylibA.c b/Tests/LinkDirectory/mylibA.c
new file mode 100644
index 0000000000..890a0890ee
--- /dev/null
+++ b/Tests/LinkDirectory/mylibA.c
@@ -0,0 +1 @@
+int mylibA(void) { return 0; }
diff --git a/Tests/LinkDirectory/mylibB.c b/Tests/LinkDirectory/mylibB.c
new file mode 100644
index 0000000000..090cc6ce59
--- /dev/null
+++ b/Tests/LinkDirectory/mylibB.c
@@ -0,0 +1 @@
+int mylibB(void) { return 0; }
diff --git a/Tests/LinkFlags/CMakeLists.txt b/Tests/LinkFlags/CMakeLists.txt
new file mode 100644
index 0000000000..4607035422
--- /dev/null
+++ b/Tests/LinkFlags/CMakeLists.txt
@@ -0,0 +1,37 @@
+cmake_minimum_required(VERSION 2.8)
+project(LinkFlags C)
+
+string(TOUPPER "${TEST_CONFIG}" TEST_CONFIG_UPPER)
+set(obj "${CMAKE_C_OUTPUT_EXTENSION}")
+if(BORLAND)
+ set(pre -)
+endif()
+
+add_library(LinkFlags_lib STATIC LinkFlagsLib.c)
+set_property(TARGET LinkFlags_lib PROPERTY STATIC_LIBRARY_FLAGS ${pre}BADFLAG${obj})
+
+add_library(LinkFlags_dll SHARED LinkFlagsLib.c)
+set_property(TARGET LinkFlags_dll PROPERTY LINK_FLAGS ${pre}BADFLAG${obj})
+
+add_library(LinkFlags_mod MODULE LinkFlagsLib.c)
+set_property(TARGET LinkFlags_mod PROPERTY LINK_FLAGS ${pre}BADFLAG${obj})
+
+add_executable(LinkFlags_exe LinkFlagsExe.c)
+set_property(TARGET LinkFlags_exe PROPERTY LINK_FLAGS ${pre}BADFLAG${obj})
+
+add_library(LinkFlags_lib_config STATIC LinkFlagsLib.c)
+set_property(TARGET LinkFlags_lib_config PROPERTY STATIC_LIBRARY_FLAGS_${TEST_CONFIG_UPPER} ${pre}BADFLAG_${TEST_CONFIG}${obj})
+
+add_library(LinkFlags_dll_config SHARED LinkFlagsLib.c)
+set_property(TARGET LinkFlags_dll_config PROPERTY LINK_FLAGS_${TEST_CONFIG_UPPER} ${pre}BADFLAG_${TEST_CONFIG}${obj})
+
+add_library(LinkFlags_mod_config MODULE LinkFlagsLib.c)
+set_property(TARGET LinkFlags_mod_config PROPERTY LINK_FLAGS_${TEST_CONFIG_UPPER} ${pre}BADFLAG_${TEST_CONFIG}${obj})
+
+add_executable(LinkFlags_exe_config LinkFlagsExe.c)
+set_property(TARGET LinkFlags_exe_config PROPERTY LINK_FLAGS_${TEST_CONFIG_UPPER} ${pre}BADFLAG_${TEST_CONFIG}${obj})
+
+add_executable(LinkFlags LinkFlags.c)
+
+add_subdirectory(LinkerFlags)
+add_subdirectory(LinkerFlagsConfig)
diff --git a/Tests/LinkFlags/LinkFlags.c b/Tests/LinkFlags/LinkFlags.c
new file mode 100644
index 0000000000..78f2de106c
--- /dev/null
+++ b/Tests/LinkFlags/LinkFlags.c
@@ -0,0 +1 @@
+int main(void) { return 0; }
diff --git a/Tests/LinkFlags/LinkFlagsExe.c b/Tests/LinkFlags/LinkFlagsExe.c
new file mode 100644
index 0000000000..123587a1f7
--- /dev/null
+++ b/Tests/LinkFlags/LinkFlagsExe.c
@@ -0,0 +1,6 @@
+int main(void) { return 0; }
+
+/* Intel compiler does not reject bad flags or objects! */
+#if defined(__INTEL_COMPILER)
+# error BADFLAG
+#endif
diff --git a/Tests/LinkFlags/LinkFlagsLib.c b/Tests/LinkFlags/LinkFlagsLib.c
new file mode 100644
index 0000000000..9d8d088191
--- /dev/null
+++ b/Tests/LinkFlags/LinkFlagsLib.c
@@ -0,0 +1,6 @@
+int flags_lib(void) { return 0; }
+
+/* Intel compiler does not reject bad flags or objects! */
+#if defined(__INTEL_COMPILER)
+# error BADFLAG
+#endif
diff --git a/Tests/LinkFlags/LinkerFlags/CMakeLists.txt b/Tests/LinkFlags/LinkerFlags/CMakeLists.txt
new file mode 100644
index 0000000000..4707f474cd
--- /dev/null
+++ b/Tests/LinkFlags/LinkerFlags/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(CMAKE_STATIC_LINKER_FLAGS ${pre}BADFLAG${obj})
+add_library(LinkFlags_lib_flags STATIC ../LinkFlagsLib.c)
+
+set(CMAKE_SHARED_LINKER_FLAGS ${pre}BADFLAG${obj})
+add_library(LinkFlags_dll_flags SHARED ../LinkFlagsLib.c)
+
+set(CMAKE_MODULE_LINKER_FLAGS ${pre}BADFLAG${obj})
+add_library(LinkFlags_mod_flags MODULE ../LinkFlagsLib.c)
+
+set(CMAKE_EXE_LINKER_FLAGS ${pre}BADFLAG${obj})
+add_executable(LinkFlags_exe_flags ../LinkFlagsExe.c)
diff --git a/Tests/LinkFlags/LinkerFlagsConfig/CMakeLists.txt b/Tests/LinkFlags/LinkerFlagsConfig/CMakeLists.txt
new file mode 100644
index 0000000000..2854fe78b6
--- /dev/null
+++ b/Tests/LinkFlags/LinkerFlagsConfig/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(CMAKE_STATIC_LINKER_FLAGS_${TEST_CONFIG_UPPER} ${pre}BADFLAG${obj})
+add_library(LinkFlags_lib_flags_config STATIC ../LinkFlagsLib.c)
+
+set(CMAKE_SHARED_LINKER_FLAGS_${TEST_CONFIG_UPPER} ${pre}BADFLAG${obj})
+add_library(LinkFlags_dll_flags_config SHARED ../LinkFlagsLib.c)
+
+set(CMAKE_MODULE_LINKER_FLAGS_${TEST_CONFIG_UPPER} ${pre}BADFLAG${obj})
+add_library(LinkFlags_mod_flags_config MODULE ../LinkFlagsLib.c)
+
+set(CMAKE_EXE_LINKER_FLAGS_${TEST_CONFIG_UPPER} ${pre}BADFLAG${obj})
+add_executable(LinkFlags_exe_flags_config ../LinkFlagsExe.c)
diff --git a/Tests/LinkLanguage/CMakeLists.txt b/Tests/LinkLanguage/CMakeLists.txt
new file mode 100644
index 0000000000..b4e53925d6
--- /dev/null
+++ b/Tests/LinkLanguage/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.7.20090708)
+project(LinkLanguage C CXX)
+
+add_library(foo STATIC foo.cxx)
+add_executable(LinkLanguage LinkLanguage.c)
+
+# Export the target now to compute its link interface and implementation.
+# This tests that the link info is recomputed after the library is linked.
+export(TARGETS LinkLanguage FILE LinkLanguageTargets.cmake)
+
+target_link_libraries(LinkLanguage foo)
+
+# CMake should now automatically choose CXX for linking, so we need
+# not set the property:
+#set_property(TARGET LinkLanguage PROPERTY LINKER_LANGUAGE CXX)
diff --git a/Tests/LinkLanguage/LinkLanguage.c b/Tests/LinkLanguage/LinkLanguage.c
new file mode 100644
index 0000000000..cf1557cabe
--- /dev/null
+++ b/Tests/LinkLanguage/LinkLanguage.c
@@ -0,0 +1,6 @@
+extern int foo(void);
+int main()
+{
+ return foo();
+}
+
diff --git a/Tests/LinkLanguage/foo.cxx b/Tests/LinkLanguage/foo.cxx
new file mode 100644
index 0000000000..5321c2dc0f
--- /dev/null
+++ b/Tests/LinkLanguage/foo.cxx
@@ -0,0 +1,6 @@
+extern "C" int foo(void)
+{
+ // Reference C++ standard library symbols.
+ delete new int;
+ return 0;
+}
diff --git a/Tests/LinkLine/CMakeLists.txt b/Tests/LinkLine/CMakeLists.txt
new file mode 100644
index 0000000000..6154dd4694
--- /dev/null
+++ b/Tests/LinkLine/CMakeLists.txt
@@ -0,0 +1,12 @@
+project( LinkLine )
+
+# Makes sure that the library order as specified by the user are
+# unchanged by dependency analysis, etc. libOne and libTwo are
+# dependent on each other. The link line should be -lOne -lTwo -lOne.
+
+add_library( One One.c )
+add_library( Two Two.c )
+
+link_libraries( One Two )
+add_executable( LinkLine Exec.c )
+link_libraries( One )
diff --git a/Tests/LinkLine/Exec.c b/Tests/LinkLine/Exec.c
new file mode 100644
index 0000000000..807a7a8cc6
--- /dev/null
+++ b/Tests/LinkLine/Exec.c
@@ -0,0 +1,9 @@
+void OneFunc();
+void TwoFunc();
+
+int main()
+{
+ OneFunc();
+ TwoFunc();
+ return 0;
+}
diff --git a/Tests/LinkLine/One.c b/Tests/LinkLine/One.c
new file mode 100644
index 0000000000..167f07d0d9
--- /dev/null
+++ b/Tests/LinkLine/One.c
@@ -0,0 +1,10 @@
+void TwoFunc();
+
+void OneFunc()
+{
+ static int i = 0;
+ ++i;
+ if( i==1 ) {
+ TwoFunc();
+ }
+}
diff --git a/Tests/LinkLine/Two.c b/Tests/LinkLine/Two.c
new file mode 100644
index 0000000000..0db73a882c
--- /dev/null
+++ b/Tests/LinkLine/Two.c
@@ -0,0 +1,10 @@
+void OneFunc();
+
+void TwoFunc()
+{
+ static int i = 0;
+ ++i;
+ if( i==1 ) {
+ OneFunc();
+ }
+}
diff --git a/Tests/LinkLineOrder/CMakeLists.txt b/Tests/LinkLineOrder/CMakeLists.txt
new file mode 100644
index 0000000000..78455e9712
--- /dev/null
+++ b/Tests/LinkLineOrder/CMakeLists.txt
@@ -0,0 +1,36 @@
+project( LinkLineOrder )
+
+# This tests ensures that the order of libraries are preserved when
+# they don't have dependency information, even if they are deep in the
+# dependency tree.
+
+# NoDepC depends on NoDepA which depends on NoDepB. NoDepE and NoDepF
+# are dependent on each other (recursive dependency). However, CMake
+# has no information about these libraries except for the order they
+# are specified in One. We must make sure we don't lose that.
+
+add_library( NoDepA NoDepA.c )
+add_library( NoDepB NoDepB.c )
+add_library( NoDepC NoDepC.c )
+add_library( NoDepE NoDepE.c )
+add_library( NoDepF NoDepF.c )
+
+add_library( One One.c )
+target_link_libraries( One NoDepC NoDepA NoDepB NoDepE NoDepF NoDepE )
+
+add_executable( Exec1 Exec1.c )
+target_link_libraries( Exec1 One )
+
+
+# Similar situation as One, except at a different level of the
+# dependency tree. This makes sure that the order is presevered
+# everywhere in the graph.
+add_library( NoDepX NoDepX.c )
+add_library( NoDepY NoDepY.c )
+add_library( NoDepZ NoDepZ.c )
+
+add_library( Two Two.c )
+target_link_libraries( Two One NoDepZ NoDepX NoDepY )
+
+add_executable( Exec2 Exec2.c )
+target_link_libraries( Exec2 Two )
diff --git a/Tests/LinkLineOrder/Exec1.c b/Tests/LinkLineOrder/Exec1.c
new file mode 100644
index 0000000000..9bbf0f68f1
--- /dev/null
+++ b/Tests/LinkLineOrder/Exec1.c
@@ -0,0 +1,8 @@
+/* Directly depends on One */
+void OneFunc();
+
+int main()
+{
+ OneFunc();
+ return 0;
+}
diff --git a/Tests/LinkLineOrder/Exec2.c b/Tests/LinkLineOrder/Exec2.c
new file mode 100644
index 0000000000..91b85758e4
--- /dev/null
+++ b/Tests/LinkLineOrder/Exec2.c
@@ -0,0 +1,8 @@
+/* Directly depends on Two */
+void TwoFunc();
+
+int main()
+{
+ TwoFunc();
+ return 0;
+}
diff --git a/Tests/LinkLineOrder/NoDepA.c b/Tests/LinkLineOrder/NoDepA.c
new file mode 100644
index 0000000000..76f97bc8c3
--- /dev/null
+++ b/Tests/LinkLineOrder/NoDepA.c
@@ -0,0 +1,7 @@
+/* depends on NoDepB */
+void NoDepB_func();
+
+void NoDepA_func()
+{
+ NoDepB_func();
+}
diff --git a/Tests/LinkLineOrder/NoDepB.c b/Tests/LinkLineOrder/NoDepB.c
new file mode 100644
index 0000000000..fa89ae9ee0
--- /dev/null
+++ b/Tests/LinkLineOrder/NoDepB.c
@@ -0,0 +1,4 @@
+/* No dependencies */
+void NoDepB_func()
+{
+}
diff --git a/Tests/LinkLineOrder/NoDepC.c b/Tests/LinkLineOrder/NoDepC.c
new file mode 100644
index 0000000000..f05d962b74
--- /dev/null
+++ b/Tests/LinkLineOrder/NoDepC.c
@@ -0,0 +1,7 @@
+/* depends on NoDepA */
+void NoDepA_func();
+
+void NoDepC_func()
+{
+ NoDepA_func();
+}
diff --git a/Tests/LinkLineOrder/NoDepE.c b/Tests/LinkLineOrder/NoDepE.c
new file mode 100644
index 0000000000..e1ba749966
--- /dev/null
+++ b/Tests/LinkLineOrder/NoDepE.c
@@ -0,0 +1,11 @@
+/* depends on NoDepF */
+void NoDepF_func();
+
+void NoDepE_func()
+{
+ static int firstcall = 1;
+ if( firstcall ) {
+ firstcall = 0;
+ NoDepF_func();
+ }
+}
diff --git a/Tests/LinkLineOrder/NoDepF.c b/Tests/LinkLineOrder/NoDepF.c
new file mode 100644
index 0000000000..8311cb868a
--- /dev/null
+++ b/Tests/LinkLineOrder/NoDepF.c
@@ -0,0 +1,11 @@
+/* depends on NoDepE */
+void NoDepE_func();
+
+void NoDepF_func()
+{
+ static int firstcall = 1;
+ if( firstcall ) {
+ firstcall = 0;
+ NoDepE_func();
+ }
+}
diff --git a/Tests/LinkLineOrder/NoDepX.c b/Tests/LinkLineOrder/NoDepX.c
new file mode 100644
index 0000000000..c895dd11bc
--- /dev/null
+++ b/Tests/LinkLineOrder/NoDepX.c
@@ -0,0 +1,7 @@
+/* depends on NoDepY*/
+void NoDepY_func();
+
+void NoDepX_func()
+{
+ NoDepY_func();
+}
diff --git a/Tests/LinkLineOrder/NoDepY.c b/Tests/LinkLineOrder/NoDepY.c
new file mode 100644
index 0000000000..1e6a4aec3f
--- /dev/null
+++ b/Tests/LinkLineOrder/NoDepY.c
@@ -0,0 +1,4 @@
+/* No dependencies */
+void NoDepY_func()
+{
+}
diff --git a/Tests/LinkLineOrder/NoDepZ.c b/Tests/LinkLineOrder/NoDepZ.c
new file mode 100644
index 0000000000..045e5705a6
--- /dev/null
+++ b/Tests/LinkLineOrder/NoDepZ.c
@@ -0,0 +1,7 @@
+/* depends on NoDepX */
+void NoDepX_func();
+
+void NoDepZ_func()
+{
+ NoDepX_func();
+}
diff --git a/Tests/LinkLineOrder/One.c b/Tests/LinkLineOrder/One.c
new file mode 100644
index 0000000000..b23b1ece9d
--- /dev/null
+++ b/Tests/LinkLineOrder/One.c
@@ -0,0 +1,10 @@
+/* depends on NoDepC and NoDepE (and hence on NoDepA, NoDepB and */
+/* NoDepF) */
+void NoDepC_func();
+void NoDepE_func();
+
+void OneFunc()
+{
+ NoDepC_func();
+ NoDepE_func();
+}
diff --git a/Tests/LinkLineOrder/Two.c b/Tests/LinkLineOrder/Two.c
new file mode 100644
index 0000000000..6bffaa866a
--- /dev/null
+++ b/Tests/LinkLineOrder/Two.c
@@ -0,0 +1,8 @@
+void OneFunc();
+void NoDepZ_func();
+
+void TwoFunc()
+{
+ OneFunc();
+ NoDepZ_func();
+}
diff --git a/Tests/LinkStatic/CMakeLists.txt b/Tests/LinkStatic/CMakeLists.txt
new file mode 100644
index 0000000000..2062c43456
--- /dev/null
+++ b/Tests/LinkStatic/CMakeLists.txt
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 2.8.4.20110303 FATAL_ERROR)
+project(LinkStatic C)
+
+if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU)$")
+ message(FATAL_ERROR "This test works only with the GNU compiler!")
+endif()
+
+find_library(MATH_LIBRARY NAMES libm.a)
+if(MATH_LIBRARY)
+ get_filename_component(MATH_LIB_DIR ${MATH_LIBRARY} PATH)
+ link_directories(${MATH_LIB_DIR})
+ # Name the library both with a full path and as "-lm" to
+ # activate the link type switching code for both cases.
+ # If the second one links shared then the link will fail.
+ set(MATH_LIBRARIES ${MATH_LIBRARY} -lm)
+else()
+ message(FATAL_ERROR "Cannot find libm.a needed for this test")
+endif()
+
+add_executable(LinkStatic LinkStatic.c)
+target_link_libraries(LinkStatic ${MATH_LIBRARIES})
+
+# Enable static linking.
+set(LinkStatic_FLAG "-static" CACHE STRING "Flag to link statically")
+set_property(TARGET LinkStatic PROPERTY LINK_FLAGS "${LinkStatic_FLAG}")
+set_property(TARGET LinkStatic PROPERTY LINK_SEARCH_START_STATIC 1)
+#set_property(TARGET LinkStatic PROPERTY LINK_SEARCH_END_STATIC 1) # insufficient
diff --git a/Tests/LinkStatic/LinkStatic.c b/Tests/LinkStatic/LinkStatic.c
new file mode 100644
index 0000000000..3600977440
--- /dev/null
+++ b/Tests/LinkStatic/LinkStatic.c
@@ -0,0 +1,5 @@
+#include <math.h>
+int main(void)
+{
+ return (int)sin(0);
+}
diff --git a/Tests/LoadCommand/CMakeCommands/CMakeLists.txt b/Tests/LoadCommand/CMakeCommands/CMakeLists.txt
new file mode 100644
index 0000000000..99b1aba82a
--- /dev/null
+++ b/Tests/LoadCommand/CMakeCommands/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required (VERSION 2.6)
+project(CMAKE_LOADED_COMMANDS)
+
+if (MUDSLIDE_TYPE MATCHES MUCHO)
+ add_definitions(-DMUCHO_MUDSLIDE)
+endif ()
+
+include_directories(${CMAKE_ROOT}/include ${CMAKE_ROOT}/Source)
+
+add_library(cmCMAKE_TEST_COMMAND MODULE cmTestCommand.c)
+
+if(WATCOM)
+ target_link_libraries(cmCMAKE_TEST_COMMAND clbsdll.lib)
+endif()
diff --git a/Tests/LoadCommand/CMakeCommands/cmTestCommand.c b/Tests/LoadCommand/CMakeCommands/cmTestCommand.c
new file mode 100644
index 0000000000..fc04934dd9
--- /dev/null
+++ b/Tests/LoadCommand/CMakeCommands/cmTestCommand.c
@@ -0,0 +1,219 @@
+#include "cmCPluginAPI.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+typedef struct
+{
+ char *LibraryName;
+ int Argc;
+ char** Argv;
+} cmVTKWrapTclData;
+
+/* do almost everything in the initial pass */
+static int CCONV InitialPass(void *inf, void *mf, int argc, char *argv[])
+{
+ char* file;
+ char* str;
+ char *srcs;
+ const char* cstr;
+ char buffer[1024];
+ void *source_file;
+ char *args[2];
+ char *ccArgs[4];
+ char *ccDep[1];
+ char *ccOut[1];
+ cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
+
+ cmVTKWrapTclData *cdata =
+ (cmVTKWrapTclData *)malloc(sizeof(cmVTKWrapTclData));
+ cdata->LibraryName = "BOO";
+ cdata->Argc = argc;
+ cdata->Argv = argv;
+ info->CAPI->SetClientData(info,cdata);
+
+ /* Now check and see if the value has been stored in the cache */
+ /* already, if so use that value and don't look for the program */
+ if(!info->CAPI->IsOn(mf,"TEST_COMMAND_TEST1"))
+ {
+ info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
+ return 1;
+ }
+
+ info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
+ cdata->LibraryName = "HOO";
+
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE", "ON",
+ "Test cache variable",
+ CM_CACHE_BOOL);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE1", "",
+ "Test cache variable 1",
+ CM_CACHE_PATH);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE2", "",
+ "Test cache variable 2",
+ CM_CACHE_FILEPATH);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE3", "",
+ "Test cache variable 3",
+ CM_CACHE_STRING);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE4", "",
+ "Test cache variable 4",
+ CM_CACHE_INTERNAL);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE5", "",
+ "Test cache variable 5",
+ CM_CACHE_STATIC);
+
+
+ file = info->CAPI->ExpandVariablesInString(mf, "${CMAKE_COMMAND}", 0, 0);
+
+ str = info->CAPI->GetFilenameWithoutExtension(file);
+ info->CAPI->DisplaySatus(mf, str);
+ info->CAPI->Free(str);
+ str = info->CAPI->GetFilenamePath(file);
+ info->CAPI->DisplaySatus(mf, str);
+ info->CAPI->Free(str);
+ str = info->CAPI->Capitalized("cmake");
+ info->CAPI->DisplaySatus(mf, str);
+ info->CAPI->Free(str);
+
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetProjectName(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeOutputDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetStartDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetStartOutputDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentOutputDirectory(mf));
+ sprintf(buffer, "Cache version: %d.%d, CMake version: %d.%d",
+ info->CAPI->GetCacheMajorVersion(mf),
+ info->CAPI->GetCacheMinorVersion(mf),
+ info->CAPI->GetMajorVersion(mf),
+ info->CAPI->GetMinorVersion(mf));
+ info->CAPI->DisplaySatus(mf, buffer);
+ if ( info->CAPI->CommandExists(mf, "SET") )
+ {
+ info->CAPI->DisplaySatus(mf, "Command SET exists");
+ }
+ if ( info->CAPI->CommandExists(mf, "SET_FOO_BAR") )
+ {
+ info->CAPI->SetError(mf, "Command SET_FOO_BAR should not exists");
+ return 0;
+ }
+ info->CAPI->AddDefineFlag(mf, "-DADDED_DEFINITION");
+
+ source_file = info->CAPI->CreateNewSourceFile(mf);
+ cstr = info->CAPI->SourceFileGetSourceName(source_file);
+ sprintf(buffer, "Shold be empty (source file name): [%s]", cstr);
+ info->CAPI->DisplaySatus(mf, buffer);
+ cstr = info->CAPI->SourceFileGetFullPath(source_file);
+ sprintf(buffer, "Should be empty (source file full path): [%s]", cstr);
+ info->CAPI->DisplaySatus(mf, buffer);
+ info->CAPI->DefineSourceFileProperty(mf,"SOME_PROPERTY","unused old prop",
+ "This property is no longer used",
+ 0);
+ if ( info->CAPI->SourceFileGetPropertyAsBool(source_file, "SOME_PROPERTY") )
+ {
+ info->CAPI->SetError(mf, "Property SOME_PROPERTY should not be defined");
+ return 0;
+ }
+ info->CAPI->DefineSourceFileProperty(mf,"SOME_PROPERTY2","nice prop",
+ "This property is for testing.",
+ 0);
+ info->CAPI->SourceFileSetProperty(source_file, "SOME_PROPERTY2", "HERE");
+ cstr = info->CAPI->SourceFileGetProperty(source_file, "ABSTRACT");
+ sprintf(buffer, "Should be 0 (source file abstract property): [%p]", cstr);
+ info->CAPI->DisplaySatus(mf, buffer);
+
+ info->CAPI->DestroySourceFile(source_file);
+
+ srcs = argv[2];
+ info->CAPI->AddExecutable(mf,"LoadedCommand",1, &srcs, 0);
+
+ /* add customs commands to generate the source file */
+ ccArgs[0] = "-E";
+ ccArgs[1] = "copy";
+ ccArgs[2] = argv[0];
+ ccArgs[3] = argv[1];
+ ccDep[0] = ccArgs[2];
+ ccOut[0] = ccArgs[3];
+ info->CAPI->AddCustomCommand(mf, "LoadedCommand.cxx.in",
+ file,
+ 4, ccArgs,
+ 1, ccDep,
+ 1, ccOut,
+ "LoadedCommand");
+
+
+ ccArgs[2] = argv[1];
+ ccArgs[3] = argv[2];
+ ccDep[0] = ccArgs[2];
+ ccOut[0] = ccArgs[3];
+ info->CAPI->AddCustomCommandToOutput(mf, ccOut[0],
+ file,
+ 4, ccArgs,
+ ccDep[0],
+ 0, 0);
+
+
+ ccArgs[1] = "echo";
+ ccArgs[2] = "Build has finished";
+ info->CAPI->AddCustomCommandToTarget(mf, "LoadedCommand",
+ file,
+ 3, ccArgs,
+ CM_POST_BUILD);
+
+ info->CAPI->Free(file);
+
+ args[0] = "TEST_EXEC";
+ args[1] = "TRUE";
+
+ /* code coverage */
+ if (info->CAPI->GetTotalArgumentSize(2,args) != 13)
+ {
+ return 0;
+ }
+ info->CAPI->ExecuteCommand(mf,"SET",2,args);
+
+ /* make sure we can find the source file */
+ if (!info->CAPI->GetSource(mf,argv[1]))
+ {
+ info->CAPI->SetError(mf, "Source file could not be found!");
+ return 0;
+ }
+
+ return 1;
+}
+
+static void CCONV FinalPass(void *inf, void *mf)
+{
+ cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
+ /* get our client data from initial pass */
+ cmVTKWrapTclData *cdata =
+ (cmVTKWrapTclData *)info->CAPI->GetClientData(info);
+ if (strcmp(info->CAPI->GetDefinition(mf, "TEST_DEF"),"HOO") ||
+ strcmp(cdata->LibraryName,"HOO"))
+ {
+ fprintf(stderr,"*** Failed LOADED COMMAND Final Pass\n");
+ }
+}
+static void CCONV Destructor(void *inf)
+{
+ cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
+ /* get our client data from initial pass */
+ cmVTKWrapTclData *cdata =
+ (cmVTKWrapTclData *)info->CAPI->GetClientData(info);
+ free(cdata);
+}
+
+#ifdef MUCHO_MUDSLIDE
+void CM_PLUGIN_EXPORT CCONV CMAKE_TEST_COMMANDInit(cmLoadedCommandInfo *info)
+{
+ info->InitialPass = InitialPass;
+ info->FinalPass = FinalPass;
+ info->Destructor = Destructor;
+ info->m_Inherited = 0;
+ info->Name = "CMAKE_TEST_COMMAND";
+}
+#endif
+
+
+
+
diff --git a/Tests/LoadCommand/CMakeLists.txt b/Tests/LoadCommand/CMakeLists.txt
new file mode 100644
index 0000000000..03a3b49424
--- /dev/null
+++ b/Tests/LoadCommand/CMakeLists.txt
@@ -0,0 +1,59 @@
+cmake_minimum_required (VERSION 2.6)
+project(LoadCommand)
+
+# set a definition
+set (TEST_COMMAND_TEST1 1)
+
+include (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)
+CHECK_TYPE_SIZE(char SIZEOF_CHAR)
+CHECK_TYPE_SIZE(short SIZEOF_SHORT)
+
+configure_file(${LoadCommand_SOURCE_DIR}/LoadedCommand.h.in
+ ${LoadCommand_BINARY_DIR}/LoadedCommand.h)
+
+include_directories(${LoadCommand_BINARY_DIR})
+
+# try to compile the command
+# make sure it is not already loaded
+if(COMMAND CMAKE_TEST_COMMAND)
+else()
+ try_compile(COMPILE_OK
+ ${LoadCommand_BINARY_DIR}/CMakeCommands
+ ${LoadCommand_SOURCE_DIR}/CMakeCommands
+ CMAKE_LOADED_COMMANDS CMAKE_FLAGS -DMUDSLIDE_TYPE:STRING=MUCHO
+ OUTPUT_VARIABLE OUTPUT )
+# do another TRY_COMPILE to get around make
+# problem on hp
+ try_compile(COMPILE_OK
+ ${LoadCommand_BINARY_DIR}/CMakeCommands
+ ${LoadCommand_SOURCE_DIR}/CMakeCommands
+ CMAKE_LOADED_COMMANDS CMAKE_FLAGS -DMUDSLIDE_TYPE:STRING=MUCHO
+ OUTPUT_VARIABLE OUTPUT )
+endif()
+
+message("Output from try compile: ${OUTPUT}")
+
+# if the compile was OK, try loading the command
+if (COMPILE_OK)
+ load_command(CMAKE_TEST_COMMAND
+ ${LoadCommand_BINARY_DIR}/CMakeCommands
+ ${LoadCommand_BINARY_DIR}/CMakeCommands/Debug
+ ${LoadCommand_BINARY_DIR}/CMakeCommands/Development
+ )
+ # if the command loaded, execute the command
+ if (COMMAND CMAKE_TEST_COMMAND)
+ CMAKE_TEST_COMMAND(
+ "${LoadCommand_SOURCE_DIR}/LoadedCommand.cxx.in"
+ "${LoadCommand_BINARY_DIR}/LoadedCommand2.cxx.in"
+ "${LoadCommand_BINARY_DIR}/LoadedCommand3.cxx"
+ )
+ endif ()
+else ()
+ message("failed to compile CMAKE_LOADED_COMMANDS")
+endif ()
+
+# TEST_DEF is set by the loaded command cmTestCommand.c
+if (TEST_DEF AND SOME_CACHE_VARIABLE AND TEST_EXEC)
+ add_definitions(-DCMAKE_IS_FUN)
+endif ()
+
diff --git a/Tests/LoadCommand/LoadedCommand.cxx.in b/Tests/LoadCommand/LoadedCommand.cxx.in
new file mode 100644
index 0000000000..72ec014f1f
--- /dev/null
+++ b/Tests/LoadCommand/LoadedCommand.cxx.in
@@ -0,0 +1,32 @@
+#include "LoadedCommand.h"
+#include <stdio.h>
+
+int testSizeOf(int s1, int s2)
+{
+ return s1 - s2;
+}
+
+int main ()
+{
+ int ret = 0;
+
+#if !defined( ADDED_DEFINITION )
+ printf("Should have ADDED_DEFINITION defined\n");
+ ret= 1;
+#endif
+#if !defined(CMAKE_IS_FUN)
+ printf("Loaded Command was not built with CMAKE_IS_FUN: failed.\n");
+ ret = 1;
+#endif
+ if(testSizeOf(SIZEOF_CHAR, sizeof(char)))
+ {
+ printf("Size of char is broken.\n");
+ ret = 1;
+ }
+ if(testSizeOf(SIZEOF_SHORT, sizeof(short)))
+ {
+ printf("Size of short is broken.\n");
+ ret = 1;
+ }
+ return ret;
+}
diff --git a/Tests/LoadCommand/LoadedCommand.h.in b/Tests/LoadCommand/LoadedCommand.h.in
new file mode 100644
index 0000000000..733c414a35
--- /dev/null
+++ b/Tests/LoadCommand/LoadedCommand.h.in
@@ -0,0 +1,3 @@
+/* Check for size of types */
+#cmakedefine SIZEOF_CHAR ${SIZEOF_CHAR}
+#cmakedefine SIZEOF_SHORT ${SIZEOF_SHORT}
diff --git a/Tests/LoadCommandOneConfig/CMakeCommands/CMakeLists.txt b/Tests/LoadCommandOneConfig/CMakeCommands/CMakeLists.txt
new file mode 100644
index 0000000000..5ee2ed0f1e
--- /dev/null
+++ b/Tests/LoadCommandOneConfig/CMakeCommands/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required (VERSION 2.6)
+project(CMAKE_LOADED_COMMANDS)
+
+if (MUDSLIDE_TYPE MATCHES MUCHO)
+ add_definitions(-DMUCHO_MUDSLIDE)
+endif ()
+
+if(WATCOM)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+endif()
+include_directories(${CMAKE_ROOT}/include ${CMAKE_ROOT}/Source)
+
+add_library(cmCMAKE_TEST_COMMAND MODULE cmTestCommand.c)
+
+if(WATCOM)
+ target_link_libraries(cmCMAKE_TEST_COMMAND clbsdll.lib)
+endif()
diff --git a/Tests/LoadCommandOneConfig/CMakeCommands/cmTestCommand.c b/Tests/LoadCommandOneConfig/CMakeCommands/cmTestCommand.c
new file mode 100644
index 0000000000..fc04934dd9
--- /dev/null
+++ b/Tests/LoadCommandOneConfig/CMakeCommands/cmTestCommand.c
@@ -0,0 +1,219 @@
+#include "cmCPluginAPI.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+typedef struct
+{
+ char *LibraryName;
+ int Argc;
+ char** Argv;
+} cmVTKWrapTclData;
+
+/* do almost everything in the initial pass */
+static int CCONV InitialPass(void *inf, void *mf, int argc, char *argv[])
+{
+ char* file;
+ char* str;
+ char *srcs;
+ const char* cstr;
+ char buffer[1024];
+ void *source_file;
+ char *args[2];
+ char *ccArgs[4];
+ char *ccDep[1];
+ char *ccOut[1];
+ cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
+
+ cmVTKWrapTclData *cdata =
+ (cmVTKWrapTclData *)malloc(sizeof(cmVTKWrapTclData));
+ cdata->LibraryName = "BOO";
+ cdata->Argc = argc;
+ cdata->Argv = argv;
+ info->CAPI->SetClientData(info,cdata);
+
+ /* Now check and see if the value has been stored in the cache */
+ /* already, if so use that value and don't look for the program */
+ if(!info->CAPI->IsOn(mf,"TEST_COMMAND_TEST1"))
+ {
+ info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
+ return 1;
+ }
+
+ info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
+ cdata->LibraryName = "HOO";
+
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE", "ON",
+ "Test cache variable",
+ CM_CACHE_BOOL);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE1", "",
+ "Test cache variable 1",
+ CM_CACHE_PATH);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE2", "",
+ "Test cache variable 2",
+ CM_CACHE_FILEPATH);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE3", "",
+ "Test cache variable 3",
+ CM_CACHE_STRING);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE4", "",
+ "Test cache variable 4",
+ CM_CACHE_INTERNAL);
+ info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE5", "",
+ "Test cache variable 5",
+ CM_CACHE_STATIC);
+
+
+ file = info->CAPI->ExpandVariablesInString(mf, "${CMAKE_COMMAND}", 0, 0);
+
+ str = info->CAPI->GetFilenameWithoutExtension(file);
+ info->CAPI->DisplaySatus(mf, str);
+ info->CAPI->Free(str);
+ str = info->CAPI->GetFilenamePath(file);
+ info->CAPI->DisplaySatus(mf, str);
+ info->CAPI->Free(str);
+ str = info->CAPI->Capitalized("cmake");
+ info->CAPI->DisplaySatus(mf, str);
+ info->CAPI->Free(str);
+
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetProjectName(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeOutputDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetStartDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetStartOutputDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentDirectory(mf));
+ info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentOutputDirectory(mf));
+ sprintf(buffer, "Cache version: %d.%d, CMake version: %d.%d",
+ info->CAPI->GetCacheMajorVersion(mf),
+ info->CAPI->GetCacheMinorVersion(mf),
+ info->CAPI->GetMajorVersion(mf),
+ info->CAPI->GetMinorVersion(mf));
+ info->CAPI->DisplaySatus(mf, buffer);
+ if ( info->CAPI->CommandExists(mf, "SET") )
+ {
+ info->CAPI->DisplaySatus(mf, "Command SET exists");
+ }
+ if ( info->CAPI->CommandExists(mf, "SET_FOO_BAR") )
+ {
+ info->CAPI->SetError(mf, "Command SET_FOO_BAR should not exists");
+ return 0;
+ }
+ info->CAPI->AddDefineFlag(mf, "-DADDED_DEFINITION");
+
+ source_file = info->CAPI->CreateNewSourceFile(mf);
+ cstr = info->CAPI->SourceFileGetSourceName(source_file);
+ sprintf(buffer, "Shold be empty (source file name): [%s]", cstr);
+ info->CAPI->DisplaySatus(mf, buffer);
+ cstr = info->CAPI->SourceFileGetFullPath(source_file);
+ sprintf(buffer, "Should be empty (source file full path): [%s]", cstr);
+ info->CAPI->DisplaySatus(mf, buffer);
+ info->CAPI->DefineSourceFileProperty(mf,"SOME_PROPERTY","unused old prop",
+ "This property is no longer used",
+ 0);
+ if ( info->CAPI->SourceFileGetPropertyAsBool(source_file, "SOME_PROPERTY") )
+ {
+ info->CAPI->SetError(mf, "Property SOME_PROPERTY should not be defined");
+ return 0;
+ }
+ info->CAPI->DefineSourceFileProperty(mf,"SOME_PROPERTY2","nice prop",
+ "This property is for testing.",
+ 0);
+ info->CAPI->SourceFileSetProperty(source_file, "SOME_PROPERTY2", "HERE");
+ cstr = info->CAPI->SourceFileGetProperty(source_file, "ABSTRACT");
+ sprintf(buffer, "Should be 0 (source file abstract property): [%p]", cstr);
+ info->CAPI->DisplaySatus(mf, buffer);
+
+ info->CAPI->DestroySourceFile(source_file);
+
+ srcs = argv[2];
+ info->CAPI->AddExecutable(mf,"LoadedCommand",1, &srcs, 0);
+
+ /* add customs commands to generate the source file */
+ ccArgs[0] = "-E";
+ ccArgs[1] = "copy";
+ ccArgs[2] = argv[0];
+ ccArgs[3] = argv[1];
+ ccDep[0] = ccArgs[2];
+ ccOut[0] = ccArgs[3];
+ info->CAPI->AddCustomCommand(mf, "LoadedCommand.cxx.in",
+ file,
+ 4, ccArgs,
+ 1, ccDep,
+ 1, ccOut,
+ "LoadedCommand");
+
+
+ ccArgs[2] = argv[1];
+ ccArgs[3] = argv[2];
+ ccDep[0] = ccArgs[2];
+ ccOut[0] = ccArgs[3];
+ info->CAPI->AddCustomCommandToOutput(mf, ccOut[0],
+ file,
+ 4, ccArgs,
+ ccDep[0],
+ 0, 0);
+
+
+ ccArgs[1] = "echo";
+ ccArgs[2] = "Build has finished";
+ info->CAPI->AddCustomCommandToTarget(mf, "LoadedCommand",
+ file,
+ 3, ccArgs,
+ CM_POST_BUILD);
+
+ info->CAPI->Free(file);
+
+ args[0] = "TEST_EXEC";
+ args[1] = "TRUE";
+
+ /* code coverage */
+ if (info->CAPI->GetTotalArgumentSize(2,args) != 13)
+ {
+ return 0;
+ }
+ info->CAPI->ExecuteCommand(mf,"SET",2,args);
+
+ /* make sure we can find the source file */
+ if (!info->CAPI->GetSource(mf,argv[1]))
+ {
+ info->CAPI->SetError(mf, "Source file could not be found!");
+ return 0;
+ }
+
+ return 1;
+}
+
+static void CCONV FinalPass(void *inf, void *mf)
+{
+ cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
+ /* get our client data from initial pass */
+ cmVTKWrapTclData *cdata =
+ (cmVTKWrapTclData *)info->CAPI->GetClientData(info);
+ if (strcmp(info->CAPI->GetDefinition(mf, "TEST_DEF"),"HOO") ||
+ strcmp(cdata->LibraryName,"HOO"))
+ {
+ fprintf(stderr,"*** Failed LOADED COMMAND Final Pass\n");
+ }
+}
+static void CCONV Destructor(void *inf)
+{
+ cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
+ /* get our client data from initial pass */
+ cmVTKWrapTclData *cdata =
+ (cmVTKWrapTclData *)info->CAPI->GetClientData(info);
+ free(cdata);
+}
+
+#ifdef MUCHO_MUDSLIDE
+void CM_PLUGIN_EXPORT CCONV CMAKE_TEST_COMMANDInit(cmLoadedCommandInfo *info)
+{
+ info->InitialPass = InitialPass;
+ info->FinalPass = FinalPass;
+ info->Destructor = Destructor;
+ info->m_Inherited = 0;
+ info->Name = "CMAKE_TEST_COMMAND";
+}
+#endif
+
+
+
+
diff --git a/Tests/LoadCommandOneConfig/CMakeLists.txt b/Tests/LoadCommandOneConfig/CMakeLists.txt
new file mode 100644
index 0000000000..6affd343f7
--- /dev/null
+++ b/Tests/LoadCommandOneConfig/CMakeLists.txt
@@ -0,0 +1,65 @@
+cmake_minimum_required (VERSION 2.6)
+project(LoadCommand)
+
+# set a definition
+set (TEST_COMMAND_TEST1 1)
+
+include (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)
+CHECK_TYPE_SIZE(char SIZEOF_CHAR)
+CHECK_TYPE_SIZE(short SIZEOF_SHORT)
+
+include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
+CHECK_INCLUDE_FILE("sys/prctl.h" HAVE_SYS_PRCTL_H)
+
+include (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake)
+CHECK_LIBRARY_EXISTS(m ceil "" HAVE_LIBM)
+
+configure_file(${LoadCommand_SOURCE_DIR}/LoadedCommand.h.in
+ ${LoadCommand_BINARY_DIR}/LoadedCommand.h)
+
+include_directories(${LoadCommand_BINARY_DIR})
+
+# try to compile the command
+# make sure it is not already loaded
+if(COMMAND CMAKE_TEST_COMMAND)
+else()
+ try_compile(COMPILE_OK
+ ${LoadCommand_BINARY_DIR}/CMakeCommands
+ ${LoadCommand_SOURCE_DIR}/CMakeCommands
+ CMAKE_LOADED_COMMANDS CMAKE_FLAGS -DMUDSLIDE_TYPE:STRING=MUCHO
+ OUTPUT_VARIABLE OUTPUT )
+# do another TRY_COMPILE to get around make
+# problem on hp
+ try_compile(COMPILE_OK
+ ${LoadCommand_BINARY_DIR}/CMakeCommands
+ ${LoadCommand_SOURCE_DIR}/CMakeCommands
+ CMAKE_LOADED_COMMANDS CMAKE_FLAGS -DMUDSLIDE_TYPE:STRING=MUCHO
+ OUTPUT_VARIABLE OUTPUT )
+endif()
+
+message("Output from try compile: ${OUTPUT}")
+
+# if the compile was OK, try loading the command
+if (COMPILE_OK)
+ load_command(CMAKE_TEST_COMMAND
+ ${LoadCommand_BINARY_DIR}/CMakeCommands
+ ${LoadCommand_BINARY_DIR}/CMakeCommands/Debug
+ ${LoadCommand_BINARY_DIR}/CMakeCommands/Development
+ )
+ # if the command loaded, execute the command
+ if (COMMAND CMAKE_TEST_COMMAND)
+ CMAKE_TEST_COMMAND(
+ "${LoadCommand_SOURCE_DIR}/LoadedCommand.cxx.in"
+ "${LoadCommand_BINARY_DIR}/LoadedCommand2.cxx.in"
+ "${LoadCommand_BINARY_DIR}/LoadedCommand3.cxx"
+ )
+ endif ()
+else ()
+ message("failed to compile CMAKE_LOADED_COMMANDS")
+endif ()
+
+# TEST_DEF is set by the loaded command cmTestCommand.c
+if (TEST_DEF AND SOME_CACHE_VARIABLE AND TEST_EXEC)
+ add_definitions(-DCMAKE_IS_FUN)
+endif ()
+
diff --git a/Tests/LoadCommandOneConfig/LoadedCommand.cxx.in b/Tests/LoadCommandOneConfig/LoadedCommand.cxx.in
new file mode 100644
index 0000000000..72ec014f1f
--- /dev/null
+++ b/Tests/LoadCommandOneConfig/LoadedCommand.cxx.in
@@ -0,0 +1,32 @@
+#include "LoadedCommand.h"
+#include <stdio.h>
+
+int testSizeOf(int s1, int s2)
+{
+ return s1 - s2;
+}
+
+int main ()
+{
+ int ret = 0;
+
+#if !defined( ADDED_DEFINITION )
+ printf("Should have ADDED_DEFINITION defined\n");
+ ret= 1;
+#endif
+#if !defined(CMAKE_IS_FUN)
+ printf("Loaded Command was not built with CMAKE_IS_FUN: failed.\n");
+ ret = 1;
+#endif
+ if(testSizeOf(SIZEOF_CHAR, sizeof(char)))
+ {
+ printf("Size of char is broken.\n");
+ ret = 1;
+ }
+ if(testSizeOf(SIZEOF_SHORT, sizeof(short)))
+ {
+ printf("Size of short is broken.\n");
+ ret = 1;
+ }
+ return ret;
+}
diff --git a/Tests/LoadCommandOneConfig/LoadedCommand.h.in b/Tests/LoadCommandOneConfig/LoadedCommand.h.in
new file mode 100644
index 0000000000..d748d063ea
--- /dev/null
+++ b/Tests/LoadCommandOneConfig/LoadedCommand.h.in
@@ -0,0 +1,9 @@
+/* Check for size of types */
+#cmakedefine SIZEOF_CHAR ${SIZEOF_CHAR}
+#cmakedefine SIZEOF_SHORT ${SIZEOF_SHORT}
+
+/* Check for headers */
+#cmakedefine HAVE_SYS_PRCTL_H
+
+/* Check for libraries */
+#cmakedefine HAVE_LIBM
diff --git a/Tests/MFC/CMakeLists.txt b/Tests/MFC/CMakeLists.txt
new file mode 100644
index 0000000000..62ff749fe6
--- /dev/null
+++ b/Tests/MFC/CMakeLists.txt
@@ -0,0 +1,61 @@
+cmake_minimum_required(VERSION 2.8)
+project(mfc_driver)
+
+include(CTest)
+include(ExternalProject)
+
+
+set(CMAKE_MFC_FLAG_VALUE "2")
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in
+ ${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.SharedMfcDll.txt
+ @ONLY
+ )
+
+ExternalProject_Add(mfcShared
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/mfc1
+ PATCH_COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.SharedMfcDll.txt
+ <SOURCE_DIR>/CMakeLists.txt
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ )
+
+
+set(CMAKE_MFC_FLAG_VALUE "1")
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in
+ ${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.StaticMfcLib.txt
+ @ONLY
+ )
+
+ExternalProject_Add(mfcStatic
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/mfc1
+ PATCH_COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.StaticMfcLib.txt
+ <SOURCE_DIR>/CMakeLists.txt
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ )
+
+
+set(binary_dir "${CMAKE_CURRENT_BINARY_DIR}")
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/ValidateBuild.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/ValidateBuild.cmake
+ @ONLY
+ )
+add_test(
+ NAME validate
+ COMMAND ${CMAKE_COMMAND}
+ -P "${CMAKE_CURRENT_BINARY_DIR}/ValidateBuild.cmake"
+ )
+
+
+add_test(
+ NAME environment
+ COMMAND ${CMAKE_COMMAND} -E environment
+ )
+
+
+message(STATUS "===== environment =====")
+execute_process(COMMAND ${CMAKE_COMMAND} -E environment)
+message(STATUS "===== /environment =====")
diff --git a/Tests/MFC/CMakeLists.txt.in b/Tests/MFC/CMakeLists.txt.in
new file mode 100644
index 0000000000..e6bfabd333
--- /dev/null
+++ b/Tests/MFC/CMakeLists.txt.in
@@ -0,0 +1,62 @@
+cmake_minimum_required(VERSION 2.8)
+project(mfc1)
+
+macro(replace_flags var these those)
+ if("${${var}}" MATCHES "${these}")
+ string(REGEX REPLACE "${these}" "${those}" ${var} "${${var}}")
+ #message(STATUS "info: ${var} changed to '${${var}}'")
+ endif()
+ message(STATUS "info: ${var}='${${var}}'")
+endmacro()
+
+macro(msvc_link_to_static_crt)
+ if(MSVC)
+ set(has_correct_flag 0)
+ foreach(lang C CXX)
+ foreach(suffix "" _DEBUG _MINSIZEREL _RELEASE _RELWITHDEBINFO)
+ replace_flags("CMAKE_${lang}_FLAGS${suffix}" "/MD" "/MT")
+ if(CMAKE_${lang}_FLAGS${suffix} MATCHES "/MT")
+ set(has_correct_flag 1)
+ endif()
+ endforeach()
+ endforeach()
+ if(NOT has_correct_flag)
+ message(FATAL_ERROR "no CMAKE_*_FLAGS var contains /MT")
+ endif()
+ endif()
+endmacro()
+
+set(files
+ ChildFrm.cpp
+ ChildFrm.h
+ MainFrm.cpp
+ MainFrm.h
+ mfc1.cpp
+ mfc1.h
+ mfc1.rc
+ mfc1Doc.cpp
+ mfc1Doc.h
+ mfc1View.cpp
+ mfc1View.h
+ Resource.h
+ stdafx.cpp
+ stdafx.h
+)
+
+set(CMAKE_MFC_FLAG "@CMAKE_MFC_FLAG_VALUE@")
+
+if("${CMAKE_MFC_FLAG}" STREQUAL "1")
+ msvc_link_to_static_crt()
+else()
+ # VS generators add this automatically based on the CMAKE_MFC_FLAG value,
+ # but generators matching "Make" require:
+ add_definitions(-D_AFXDLL)
+endif()
+
+add_executable(mfc1 WIN32 ${files})
+install(TARGETS mfc1 DESTINATION bin)
+
+if("${CMAKE_MFC_FLAG}" STREQUAL "2")
+ set(CMAKE_INSTALL_MFC_LIBRARIES ON)
+ include(InstallRequiredSystemLibraries)
+endif()
diff --git a/Tests/MFC/ValidateBuild.cmake.in b/Tests/MFC/ValidateBuild.cmake.in
new file mode 100644
index 0000000000..ed923f5e72
--- /dev/null
+++ b/Tests/MFC/ValidateBuild.cmake.in
@@ -0,0 +1,68 @@
+#
+# This code validates that the install trees of the shared and static builds
+# of "mfc1" have the expected contents:
+#
+set(binary_dir "@binary_dir@")
+message("binary_dir='${binary_dir}'")
+
+# There should be exactly one file in the static install tree "bin" directory
+# and it should be named "mfc1.exe"
+#
+message(STATUS "===== mfcStatic install tree =====")
+file(GLOB_RECURSE files "${binary_dir}/mfcStatic-prefix/bin/*.*")
+message(STATUS "mfcStatic files='${files}'")
+list(LENGTH files len)
+if(NOT len EQUAL 1)
+ message(FATAL_ERROR
+ "len='${len}' is not '1' (count of static 'bin' files)")
+endif()
+get_filename_component(name "${files}" NAME)
+string(TOLOWER "${name}" name)
+if(NOT "${name}" STREQUAL "mfc1.exe")
+ message(FATAL_ERROR "unexpected mfcStatic file name '${name}'")
+endif()
+
+# There should be at least 3 files in the shared install tree "bin"
+# directory: mfc1.exe, the main MFC dll and the C runtime dll. With more
+# recent versions of VS, there will also be an MFC language dll and a
+# manifest file.
+#
+message(STATUS "===== mfcShared install tree =====")
+file(GLOB_RECURSE files "${binary_dir}/mfcShared-prefix/bin/*.*")
+message(STATUS "mfcShared files='${files}'")
+list(LENGTH files len)
+
+set(msvc6 "@MSVC60@")
+if("${msvc6}" STREQUAL "1")
+ set(expected_minimum_file_count 1)
+else()
+ set(expected_minimum_file_count 3)
+endif()
+
+if(len LESS ${expected_minimum_file_count})
+ message(FATAL_ERROR
+ "len='${len}' is less than '${expected_minimum_file_count}' (count of shared 'bin' files)")
+endif()
+foreach(f ${files})
+ message(STATUS "file '${f}'")
+ get_filename_component(ext "${f}" EXT)
+ string(TOLOWER "${ext}" ext)
+
+ if("${ext}" MATCHES "\\.exe$")
+ message(STATUS " exe file")
+ get_filename_component(name "${f}" NAME)
+ string(TOLOWER "${name}" name)
+ if(NOT "${name}" STREQUAL "mfc1.exe")
+ message(FATAL_ERROR "unexpected mfcShared .exe file name '${name}'")
+ endif()
+ elseif("${ext}" MATCHES "\\.dll$")
+ message(STATUS " dll file")
+ elseif("${ext}" MATCHES "\\.manifest$")
+ message(STATUS " manifest file")
+ else()
+ message(STATUS " unknown file")
+ message(FATAL_ERROR "unexpected mfcShared ${ext} file name '${f}'")
+ endif()
+endforeach()
+
+message(STATUS "All mfc1 build validation tests pass.")
diff --git a/Tests/MFC/mfc1/.gitattributes b/Tests/MFC/mfc1/.gitattributes
new file mode 100644
index 0000000000..59be5dcfbe
--- /dev/null
+++ b/Tests/MFC/mfc1/.gitattributes
@@ -0,0 +1,6 @@
+.gitattributes export-ignore
+
+*.sln -crlf
+*.vcproj -crlf
+
+* -whitespace
diff --git a/Tests/MFC/mfc1/ChildFrm.cpp b/Tests/MFC/mfc1/ChildFrm.cpp
new file mode 100644
index 0000000000..b04c4f2314
--- /dev/null
+++ b/Tests/MFC/mfc1/ChildFrm.cpp
@@ -0,0 +1,59 @@
+// ChildFrm.cpp : implementation of the CChildFrame class
+//
+#include "stdafx.h"
+#include "mfc1.h"
+
+#include "ChildFrm.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+
+// CChildFrame
+
+IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
+
+BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
+END_MESSAGE_MAP()
+
+
+// CChildFrame construction/destruction
+
+CChildFrame::CChildFrame()
+{
+ // TODO: add member initialization code here
+}
+
+CChildFrame::~CChildFrame()
+{
+}
+
+
+BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
+{
+ // TODO: Modify the Window class or styles here by modifying the CREATESTRUCT cs
+ if( !CMDIChildWnd::PreCreateWindow(cs) )
+ return FALSE;
+
+ return TRUE;
+}
+
+
+// CChildFrame diagnostics
+
+#ifdef _DEBUG
+void CChildFrame::AssertValid() const
+{
+ CMDIChildWnd::AssertValid();
+}
+
+void CChildFrame::Dump(CDumpContext& dc) const
+{
+ CMDIChildWnd::Dump(dc);
+}
+
+#endif //_DEBUG
+
+
+// CChildFrame message handlers
diff --git a/Tests/MFC/mfc1/ChildFrm.h b/Tests/MFC/mfc1/ChildFrm.h
new file mode 100644
index 0000000000..34b80f1260
--- /dev/null
+++ b/Tests/MFC/mfc1/ChildFrm.h
@@ -0,0 +1,34 @@
+// ChildFrm.h : interface of the CChildFrame class
+//
+
+
+#pragma once
+
+
+class CChildFrame : public CMDIChildWnd
+{
+ DECLARE_DYNCREATE(CChildFrame)
+public:
+ CChildFrame();
+
+// Attributes
+public:
+
+// Operations
+public:
+
+// Overrides
+ virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
+
+// Implementation
+public:
+ virtual ~CChildFrame();
+#ifdef _DEBUG
+ virtual void AssertValid() const;
+ virtual void Dump(CDumpContext& dc) const;
+#endif
+
+// Generated message map functions
+protected:
+ DECLARE_MESSAGE_MAP()
+};
diff --git a/Tests/MFC/mfc1/MainFrm.cpp b/Tests/MFC/mfc1/MainFrm.cpp
new file mode 100644
index 0000000000..44554bf4c8
--- /dev/null
+++ b/Tests/MFC/mfc1/MainFrm.cpp
@@ -0,0 +1,98 @@
+// MainFrm.cpp : implementation of the CMainFrame class
+//
+
+#include "stdafx.h"
+#include "mfc1.h"
+
+#include "MainFrm.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+
+// CMainFrame
+
+IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
+
+BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
+ ON_WM_CREATE()
+END_MESSAGE_MAP()
+
+static UINT indicators[] =
+{
+ ID_SEPARATOR, // status line indicator
+ ID_INDICATOR_CAPS,
+ ID_INDICATOR_NUM,
+ ID_INDICATOR_SCRL,
+};
+
+
+// CMainFrame construction/destruction
+
+CMainFrame::CMainFrame()
+{
+ // TODO: add member initialization code here
+}
+
+CMainFrame::~CMainFrame()
+{
+}
+
+
+int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
+{
+ if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
+ return -1;
+
+ if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
+ | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
+ !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
+ {
+ TRACE0("Failed to create toolbar\n");
+ return -1; // fail to create
+ }
+
+ if (!m_wndStatusBar.Create(this) ||
+ !m_wndStatusBar.SetIndicators(indicators,
+ sizeof(indicators)/sizeof(UINT)))
+ {
+ TRACE0("Failed to create status bar\n");
+ return -1; // fail to create
+ }
+ // TODO: Delete these three lines if you don't want the toolbar to be dockable
+ m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
+ EnableDocking(CBRS_ALIGN_ANY);
+ DockControlBar(&m_wndToolBar);
+
+ return 0;
+}
+
+BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
+{
+ if( !CMDIFrameWnd::PreCreateWindow(cs) )
+ return FALSE;
+ // TODO: Modify the Window class or styles here by modifying
+ // the CREATESTRUCT cs
+
+ return TRUE;
+}
+
+
+// CMainFrame diagnostics
+
+#ifdef _DEBUG
+void CMainFrame::AssertValid() const
+{
+ CMDIFrameWnd::AssertValid();
+}
+
+void CMainFrame::Dump(CDumpContext& dc) const
+{
+ CMDIFrameWnd::Dump(dc);
+}
+
+#endif //_DEBUG
+
+
+// CMainFrame message handlers
diff --git a/Tests/MFC/mfc1/MainFrm.h b/Tests/MFC/mfc1/MainFrm.h
new file mode 100644
index 0000000000..1039ac5ee1
--- /dev/null
+++ b/Tests/MFC/mfc1/MainFrm.h
@@ -0,0 +1,38 @@
+// MainFrm.h : interface of the CMainFrame class
+//
+
+
+#pragma once
+class CMainFrame : public CMDIFrameWnd
+{
+ DECLARE_DYNAMIC(CMainFrame)
+public:
+ CMainFrame();
+
+// Attributes
+public:
+
+// Operations
+public:
+
+// Overrides
+public:
+ virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
+
+// Implementation
+public:
+ virtual ~CMainFrame();
+#ifdef _DEBUG
+ virtual void AssertValid() const;
+ virtual void Dump(CDumpContext& dc) const;
+#endif
+
+protected: // control bar embedded members
+ CStatusBar m_wndStatusBar;
+ CToolBar m_wndToolBar;
+
+// Generated message map functions
+protected:
+ afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+ DECLARE_MESSAGE_MAP()
+};
diff --git a/Tests/MFC/mfc1/ReadMe.txt b/Tests/MFC/mfc1/ReadMe.txt
new file mode 100644
index 0000000000..d84608e712
--- /dev/null
+++ b/Tests/MFC/mfc1/ReadMe.txt
@@ -0,0 +1,135 @@
+================================================================================
+ MICROSOFT FOUNDATION CLASS LIBRARY : mfc1 Project Overview
+===============================================================================
+
+The application wizard has created this mfc1 application for
+you. This application not only demonstrates the basics of using the Microsoft
+Foundation Classes but is also a starting point for writing your application.
+
+This file contains a summary of what you will find in each of the files that
+make up your mfc1 application.
+
+mfc1.vcproj
+ This is the main project file for VC++ projects generated using an application wizard.
+ It contains information about the version of Visual C++ that generated the file, and
+ information about the platforms, configurations, and project features selected with the
+ application wizard.
+
+mfc1.h
+ This is the main header file for the application. It includes other
+ project specific headers (including Resource.h) and declares the
+ Cmfc1App application class.
+
+mfc1.cpp
+ This is the main application source file that contains the application
+ class Cmfc1App.
+
+mfc1.rc
+ This is a listing of all of the Microsoft Windows resources that the
+ program uses. It includes the icons, bitmaps, and cursors that are stored
+ in the RES subdirectory. This file can be directly edited in Microsoft
+ Visual C++. Your project resources are in 1033.
+
+res\mfc1.ico
+ This is an icon file, which is used as the application's icon. This
+ icon is included by the main resource file mfc1.rc.
+
+res\mfc1.rc2
+ This file contains resources that are not edited by Microsoft
+ Visual C++. You should place all resources not editable by
+ the resource editor in this file.
+mfc1.reg
+ This is an example .reg file that shows you the kind of registration
+ settings the framework will set for you. You can use this as a .reg
+ file to go along with your application or just delete it and rely
+ on the default RegisterShellFileTypes registration.
+/////////////////////////////////////////////////////////////////////////////
+
+For the main frame window:
+ The project includes a standard MFC interface.
+MainFrm.h, MainFrm.cpp
+ These files contain the frame class CMainFrame, which is derived from
+ CMDIFrameWnd and controls all MDI frame features.
+res\Toolbar.bmp
+ This bitmap file is used to create tiled images for the toolbar.
+ The initial toolbar and status bar are constructed in the CMainFrame
+ class. Edit this toolbar bitmap using the resource editor, and
+ update the IDR_MAINFRAME TOOLBAR array in mfc1.rc to add
+ toolbar buttons.
+/////////////////////////////////////////////////////////////////////////////
+
+For the child frame window:
+
+ChildFrm.h, ChildFrm.cpp
+ These files define and implement the CChildFrame class, which
+ supports the child windows in an MDI application.
+
+/////////////////////////////////////////////////////////////////////////////
+
+The application wizard creates one document type and one view:
+
+mfc1Doc.h, mfc1Doc.cpp - the document
+ These files contain your Cmfc1Doc class. Edit these files to
+ add your special document data and to implement file saving and loading
+ (via Cmfc1Doc::Serialize).
+ The Document will have the following strings:
+ File extension: mf1
+ File type ID: mfc1.Document
+ Main frame caption: mfc1
+ Doc type name: mfc1
+ Filter name: mfc1 Files (*.mf1)
+ File new short name: mfc1
+ File type long name: mfc1.Document
+mfc1View.h, mfc1View.cpp - the view of the document
+ These files contain your Cmfc1View class.
+ Cmfc1View objects are used to view Cmfc1Doc objects.
+res\mfc1Doc.ico
+ This is an icon file, which is used as the icon for MDI child windows
+ for the Cmfc1Doc class. This icon is included by the main
+ resource file mfc1.rc.
+/////////////////////////////////////////////////////////////////////////////
+
+Other Features:
+
+ActiveX Controls
+ The application includes support to use ActiveX controls.
+
+Printing and Print Preview support
+ The application wizard has generated code to handle the print, print setup, and print preview
+ commands by calling member functions in the CView class from the MFC library.
+/////////////////////////////////////////////////////////////////////////////
+
+Other standard files:
+
+StdAfx.h, StdAfx.cpp
+ These files are used to build a precompiled header (PCH) file
+ named mfc1.pch and a precompiled types file named StdAfx.obj.
+
+Resource.h
+ This is the standard header file, which defines new resource IDs.
+ Microsoft Visual C++ reads and updates this file.
+
+mfc1.manifest
+ Application manifest files are used by Windows XP to describe an applications
+ dependency on specific versions of Side-by-Side assemblies. The loader uses this
+ information to load the appropriate assembly from the assembly cache or private
+ from the application. The Application manifest maybe included for redistribution
+ as an external .manifest file that is installed in the same folder as the application
+ executable or it may be included in the executable in the form of a resource.
+/////////////////////////////////////////////////////////////////////////////
+
+Other notes:
+
+The application wizard uses "TODO:" to indicate parts of the source code you
+should add to or customize.
+
+If your application uses MFC in a shared DLL, and your application is in a
+language other than the operating system's current language, you will need
+to copy the corresponding localized resources MFC70XXX.DLL from the Microsoft
+Visual C++ CD-ROM under the Win\System directory to your computer's system or
+system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the
+language abbreviation. For example, MFC70DEU.DLL contains resources
+translated to German.) If you don't do this, some of the UI elements of
+your application will remain in the language of the operating system.
+
+/////////////////////////////////////////////////////////////////////////////
diff --git a/Tests/MFC/mfc1/Resource.h b/Tests/MFC/mfc1/Resource.h
new file mode 100644
index 0000000000..0a9c13f574
--- /dev/null
+++ b/Tests/MFC/mfc1/Resource.h
@@ -0,0 +1,20 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by mfc1.rc
+//
+#define IDD_ABOUTBOX 100
+#define IDP_OLE_INIT_FAILED 100
+#define IDR_MAINFRAME 128
+#define IDR_mfc1TYPE 129
+#define IDR_MANIFEST CREATEPROCESS_MANIFEST_RESOURCE_ID
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 130
+#define _APS_NEXT_CONTROL_VALUE 1000
+#define _APS_NEXT_SYMED_VALUE 101
+#define _APS_NEXT_COMMAND_VALUE 32771
+#endif
+#endif
diff --git a/Tests/MFC/mfc1/mfc1.cpp b/Tests/MFC/mfc1/mfc1.cpp
new file mode 100644
index 0000000000..9530cd2b94
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1.cpp
@@ -0,0 +1,144 @@
+// mfc1.cpp : Defines the class behaviors for the application.
+//
+
+#include "stdafx.h"
+#include "mfc1.h"
+#include "MainFrm.h"
+
+#include "ChildFrm.h"
+#include "mfc1Doc.h"
+#include "mfc1View.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+
+// Cmfc1App
+
+BEGIN_MESSAGE_MAP(Cmfc1App, CWinApp)
+ ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
+ // Standard file based document commands
+ ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
+ ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
+ // Standard print setup command
+ ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
+END_MESSAGE_MAP()
+
+
+// Cmfc1App construction
+
+Cmfc1App::Cmfc1App()
+{
+ // TODO: add construction code here,
+ // Place all significant initialization in InitInstance
+}
+
+
+// The one and only Cmfc1App object
+
+Cmfc1App theApp;
+
+// Cmfc1App initialization
+
+BOOL Cmfc1App::InitInstance()
+{
+ // InitCommonControls() is required on Windows XP if an application
+ // manifest specifies use of ComCtl32.dll version 6 or later to enable
+ // visual styles. Otherwise, any window creation will fail.
+ InitCommonControls();
+
+ CWinApp::InitInstance();
+
+ // Initialize OLE libraries
+ if (!AfxOleInit())
+ {
+ AfxMessageBox(IDP_OLE_INIT_FAILED);
+ return FALSE;
+ }
+ AfxEnableControlContainer();
+ // Standard initialization
+ // If you are not using these features and wish to reduce the size
+ // of your final executable, you should remove from the following
+ // the specific initialization routines you do not need
+ // Change the registry key under which our settings are stored
+ // TODO: You should modify this string to be something appropriate
+ // such as the name of your company or organization
+ SetRegistryKey(_T("Local AppWizard-Generated Applications"));
+ LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
+ // Register the application's document templates. Document templates
+ // serve as the connection between documents, frame windows and views
+ CMultiDocTemplate* pDocTemplate;
+ pDocTemplate = new CMultiDocTemplate(IDR_mfc1TYPE,
+ RUNTIME_CLASS(Cmfc1Doc),
+ RUNTIME_CLASS(CChildFrame), // custom MDI child frame
+ RUNTIME_CLASS(Cmfc1View));
+ if (!pDocTemplate)
+ return FALSE;
+ AddDocTemplate(pDocTemplate);
+ // create main MDI Frame window
+ CMainFrame* pMainFrame = new CMainFrame;
+ if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
+ return FALSE;
+ m_pMainWnd = pMainFrame;
+ // call DragAcceptFiles only if there's a suffix
+ // In an MDI app, this should occur immediately after setting m_pMainWnd
+ // Enable drag/drop open
+ m_pMainWnd->DragAcceptFiles();
+ // Enable DDE Execute open
+ EnableShellOpen();
+ RegisterShellFileTypes(TRUE);
+ // Parse command line for standard shell commands, DDE, file open
+ CCommandLineInfo cmdInfo;
+ ParseCommandLine(cmdInfo);
+ // Dispatch commands specified on the command line. Will return FALSE if
+ // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
+ if (!ProcessShellCommand(cmdInfo))
+ return FALSE;
+ // The main window has been initialized, so show and update it
+ pMainFrame->ShowWindow(m_nCmdShow);
+ pMainFrame->UpdateWindow();
+ return TRUE;
+}
+
+
+
+// CAboutDlg dialog used for App About
+
+class CAboutDlg : public CDialog
+{
+public:
+ CAboutDlg();
+
+// Dialog Data
+ enum { IDD = IDD_ABOUTBOX };
+
+protected:
+ virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
+
+// Implementation
+protected:
+ DECLARE_MESSAGE_MAP()
+};
+
+CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
+{
+}
+
+void CAboutDlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialog::DoDataExchange(pDX);
+}
+
+BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
+END_MESSAGE_MAP()
+
+// App command to run the dialog
+void Cmfc1App::OnAppAbout()
+{
+ CAboutDlg aboutDlg;
+ aboutDlg.DoModal();
+}
+
+
+// Cmfc1App message handlers
diff --git a/Tests/MFC/mfc1/mfc1.h b/Tests/MFC/mfc1/mfc1.h
new file mode 100644
index 0000000000..c273601f89
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1.h
@@ -0,0 +1,31 @@
+// mfc1.h : main header file for the mfc1 application
+//
+#pragma once
+
+#ifndef __AFXWIN_H__
+ #error include 'stdafx.h' before including this file for PCH
+#endif
+
+#include "resource.h" // main symbols
+
+
+// Cmfc1App:
+// See mfc1.cpp for the implementation of this class
+//
+
+class Cmfc1App : public CWinApp
+{
+public:
+ Cmfc1App();
+
+
+// Overrides
+public:
+ virtual BOOL InitInstance();
+
+// Implementation
+ afx_msg void OnAppAbout();
+ DECLARE_MESSAGE_MAP()
+};
+
+extern Cmfc1App theApp;
diff --git a/Tests/MFC/mfc1/mfc1.rc b/Tests/MFC/mfc1/mfc1.rc
new file mode 100644
index 0000000000..346c5fb77d
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1.rc
@@ -0,0 +1,393 @@
+//Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+#ifdef APSTUDIO_INVOKED
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
+ "#define _AFX_NO_OLE_RESOURCES\r\n"
+ "#define _AFX_NO_TRACKER_RESOURCES\r\n"
+ "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
+ "\r\n"
+ "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
+ "LANGUAGE 9, 1\r\n"
+ "#pragma code_page(1252)\r\n"
+ "#include ""res\\mfc1.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
+ "#include ""afxres.rc"" // Standard components\r\n"
+ "#include ""afxprint.rc"" // printing/print preview resources\r\n"
+ "#endif\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+LANGUAGE 9, 1
+#pragma code_page(1252)
+IDR_MAINFRAME ICON "res\\mfc1.ico"
+IDR_mfc1TYPE ICON "res\\mfc1Doc.ico"
+#endif
+/////////////////////////////////////////////////////////////////////////////
+//
+// Bitmap
+//
+
+IDR_MAINFRAME BITMAP "res\\Toolbar.bmp"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Toolbar
+//
+
+IDR_MAINFRAME TOOLBAR 16, 15
+BEGIN
+ BUTTON ID_FILE_NEW
+ BUTTON ID_FILE_OPEN
+ BUTTON ID_FILE_SAVE
+ SEPARATOR
+ BUTTON ID_EDIT_CUT
+ BUTTON ID_EDIT_COPY
+ BUTTON ID_EDIT_PASTE
+ SEPARATOR
+ BUTTON ID_FILE_PRINT
+ BUTTON ID_APP_ABOUT
+END
+
+
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+LANGUAGE 9, 1
+#pragma code_page(1252)
+/////////////////////////////////////////////////////////////////////////////
+//
+// Menu
+//
+
+IDR_MAINFRAME MENU
+BEGIN
+ POPUP "&File"
+ BEGIN
+ MENUITEM "&New\tCtrl+N", ID_FILE_NEW
+ MENUITEM "&Open...\tCtrl+O", ID_FILE_OPEN
+ MENUITEM SEPARATOR
+ MENUITEM "P&rint Setup...", ID_FILE_PRINT_SETUP
+ MENUITEM SEPARATOR
+ MENUITEM "Recent File", ID_FILE_MRU_FILE1,GRAYED
+ MENUITEM SEPARATOR
+ MENUITEM "&Close", ID_FILE_CLOSE
+ MENUITEM "E&xit", ID_APP_EXIT
+ END
+ POPUP "&View"
+ BEGIN
+ MENUITEM "&Toolbar", ID_VIEW_TOOLBAR
+ MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
+ END
+ POPUP "&Help"
+ BEGIN
+ MENUITEM "&About mfc1...", ID_APP_ABOUT
+ END
+END
+IDR_mfc1TYPE MENU
+BEGIN
+ POPUP "&File"
+ BEGIN
+ MENUITEM "&New\tCtrl+N", ID_FILE_NEW
+ MENUITEM "&Open...\tCtrl+O", ID_FILE_OPEN
+ MENUITEM "&Close", ID_FILE_CLOSE
+ MENUITEM "&Save\tCtrl+S", ID_FILE_SAVE
+ MENUITEM "Save &As...", ID_FILE_SAVE_AS
+ MENUITEM SEPARATOR
+ MENUITEM "&Print...\tCtrl+P", ID_FILE_PRINT
+ MENUITEM "Print Pre&view", ID_FILE_PRINT_PREVIEW
+ MENUITEM "P&rint Setup...", ID_FILE_PRINT_SETUP
+ MENUITEM SEPARATOR
+ MENUITEM "Recent File", ID_FILE_MRU_FILE1,GRAYED
+ MENUITEM SEPARATOR
+ MENUITEM "E&xit", ID_APP_EXIT
+ END
+ POPUP "&Edit"
+ BEGIN
+ MENUITEM "&Undo\tCtrl+Z", ID_EDIT_UNDO
+ MENUITEM SEPARATOR
+ MENUITEM "Cu&t\tCtrl+X", ID_EDIT_CUT
+ MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY
+ MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE
+ END
+ POPUP "&View"
+ BEGIN
+ MENUITEM "&Toolbar", ID_VIEW_TOOLBAR
+ MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
+ END
+ POPUP "&Window"
+ BEGIN
+ MENUITEM "&New Window", ID_WINDOW_NEW
+ MENUITEM "&Cascade", ID_WINDOW_CASCADE
+ MENUITEM "&Tile", ID_WINDOW_TILE_HORZ
+ MENUITEM "&Arrange Icons", ID_WINDOW_ARRANGE
+ END
+ POPUP "&Help"
+ BEGIN
+ MENUITEM "&About mfc1...", ID_APP_ABOUT
+ END
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Accelerator
+//
+
+IDR_MAINFRAME ACCELERATORS
+BEGIN
+ "N", ID_FILE_NEW, VIRTKEY,CONTROL
+ "O", ID_FILE_OPEN, VIRTKEY,CONTROL
+ "S", ID_FILE_SAVE, VIRTKEY,CONTROL
+ "P", ID_FILE_PRINT, VIRTKEY,CONTROL
+ "Z", ID_EDIT_UNDO, VIRTKEY,CONTROL
+ "X", ID_EDIT_CUT, VIRTKEY,CONTROL
+ "C", ID_EDIT_COPY, VIRTKEY,CONTROL
+ "V", ID_EDIT_PASTE, VIRTKEY,CONTROL
+ VK_BACK, ID_EDIT_UNDO, VIRTKEY,ALT
+ VK_DELETE, ID_EDIT_CUT, VIRTKEY,SHIFT
+ VK_INSERT, ID_EDIT_COPY, VIRTKEY,CONTROL
+ VK_INSERT, ID_EDIT_PASTE, VIRTKEY,SHIFT
+ VK_F6, ID_NEXT_PANE, VIRTKEY
+ VK_F6, ID_PREV_PANE, VIRTKEY,SHIFT
+END
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+#if _MSC_VER < 1300
+#define DS_SHELLFONT_FLAG 0
+#else
+#define DS_SHELLFONT_FLAG DS_SHELLFONT
+#endif
+
+IDD_ABOUTBOX DIALOGEX 0, 0, 235, 55
+CAPTION "About mfc1"
+STYLE DS_MODALFRAME | DS_SHELLFONT_FLAG | WS_POPUP | WS_CAPTION | WS_SYSMENU
+FONT 8, "MS Shell Dlg"
+BEGIN
+ ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
+ LTEXT "mfc1 Version 1.0",IDC_STATIC,40,10,119,8,
+ SS_NOPREFIX
+ LTEXT "Copyright (C) 2011",IDC_STATIC,40,25,119,8
+ DEFPUSHBUTTON "OK",IDOK,178,7,50,16,WS_GROUP
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 1,0,0,1
+ PRODUCTVERSION 1,0,0,1
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904e4"
+ BEGIN
+ VALUE "CompanyName", "TODO: <Company name>"
+ VALUE "FileDescription", "TODO: <File description>"
+ VALUE "FileVersion", "1.0.0.1"
+ VALUE "InternalName", "mfc1.exe"
+ VALUE "LegalCopyright", "TODO: (c) <Company name>. All rights reserved."
+ VALUE "OriginalFilename","mfc1.exe"
+ VALUE "ProductName", "TODO: <Product name>"
+ VALUE "ProductVersion", "1.0.0.1"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x0409, 1252
+ END
+END
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_ABOUTBOX, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 228
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 48
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE
+BEGIN
+// Non-mac-targeting apps remove the two extra substrings
+ IDR_MAINFRAME "mfc1"
+ // has a file suffix - shell file type too
+ IDR_mfc1TYPE "\nmfc1\nmfc1\nmfc1 Files (*.mf1)\n.mf1\nmfc1.Document\nmfc1.Document"
+END
+STRINGTABLE
+BEGIN
+ AFX_IDS_APP_TITLE "mfc1"
+ AFX_IDS_IDLEMESSAGE "Ready"
+END
+STRINGTABLE
+BEGIN
+ ID_INDICATOR_EXT "EXT"
+ ID_INDICATOR_CAPS "CAP"
+ ID_INDICATOR_NUM "NUM"
+ ID_INDICATOR_SCRL "SCRL"
+ ID_INDICATOR_OVR "OVR"
+ ID_INDICATOR_REC "REC"
+END
+STRINGTABLE
+BEGIN
+ ID_FILE_NEW "Create a new document\nNew"
+ ID_FILE_OPEN "Open an existing document\nOpen"
+ ID_FILE_CLOSE "Close the active document\nClose"
+ ID_FILE_SAVE "Save the active document\nSave"
+ ID_FILE_SAVE_AS "Save the active document with a new name\nSave As"
+ ID_FILE_PAGE_SETUP "Change the printing options\nPage Setup"
+ ID_FILE_PRINT_SETUP "Change the printer and printing options\nPrint Setup"
+ ID_FILE_PRINT "Print the active document\nPrint"
+ ID_FILE_PRINT_PREVIEW "Display full pages\nPrint Preview"
+ ID_APP_ABOUT "Display program information, version number and copyright\nAbout"
+ ID_APP_EXIT "Quit the application; prompts to save documents\nExit"
+ ID_FILE_MRU_FILE1 "Open this document"
+ ID_FILE_MRU_FILE2 "Open this document"
+ ID_FILE_MRU_FILE3 "Open this document"
+ ID_FILE_MRU_FILE4 "Open this document"
+ ID_FILE_MRU_FILE5 "Open this document"
+ ID_FILE_MRU_FILE6 "Open this document"
+ ID_FILE_MRU_FILE7 "Open this document"
+ ID_FILE_MRU_FILE8 "Open this document"
+ ID_FILE_MRU_FILE9 "Open this document"
+ ID_FILE_MRU_FILE10 "Open this document"
+ ID_FILE_MRU_FILE11 "Open this document"
+ ID_FILE_MRU_FILE12 "Open this document"
+ ID_FILE_MRU_FILE13 "Open this document"
+ ID_FILE_MRU_FILE14 "Open this document"
+ ID_FILE_MRU_FILE15 "Open this document"
+ ID_FILE_MRU_FILE16 "Open this document"
+ ID_NEXT_PANE "Switch to the next window pane\nNext Pane"
+ ID_PREV_PANE "Switch back to the previous window pane\nPrevious Pane"
+ ID_WINDOW_NEW "Open another window for the active document\nNew Window"
+ ID_WINDOW_ARRANGE "Arrange icons at the bottom of the window\nArrange Icons"
+ ID_WINDOW_CASCADE "Arrange windows so they overlap\nCascade Windows"
+ ID_WINDOW_TILE_HORZ "Arrange windows as non-overlapping tiles\nTile Windows"
+ ID_WINDOW_TILE_VERT "Arrange windows as non-overlapping tiles\nTile Windows"
+ ID_WINDOW_SPLIT "Split the active window into panes\nSplit"
+ ID_EDIT_CLEAR "Erase the selection\nErase"
+ ID_EDIT_CLEAR_ALL "Erase everything\nErase All"
+ ID_EDIT_COPY "Copy the selection and put it on the Clipboard\nCopy"
+ ID_EDIT_CUT "Cut the selection and put it on the Clipboard\nCut"
+ ID_EDIT_FIND "Find the specified text\nFind"
+ ID_EDIT_PASTE "Insert Clipboard contents\nPaste"
+ ID_EDIT_REPEAT "Repeat the last action\nRepeat"
+ ID_EDIT_REPLACE "Replace specific text with different text\nReplace"
+ ID_EDIT_SELECT_ALL "Select the entire document\nSelect All"
+ ID_EDIT_UNDO "Undo the last action\nUndo"
+ ID_EDIT_REDO "Redo the previously undone action\nRedo"
+ ID_VIEW_TOOLBAR "Show or hide the toolbar\nToggle ToolBar"
+ ID_VIEW_STATUS_BAR "Show or hide the status bar\nToggle StatusBar"
+END
+
+STRINGTABLE
+BEGIN
+ AFX_IDS_SCSIZE "Change the window size"
+ AFX_IDS_SCMOVE "Change the window position"
+ AFX_IDS_SCMINIMIZE "Reduce the window to an icon"
+ AFX_IDS_SCMAXIMIZE "Enlarge the window to full size"
+ AFX_IDS_SCNEXTWINDOW "Switch to the next document window"
+ AFX_IDS_SCPREVWINDOW "Switch to the previous document window"
+ AFX_IDS_SCCLOSE "Close the active window and prompts to save the documents"
+ AFX_IDS_SCRESTORE "Restore the window to normal size"
+ AFX_IDS_SCTASKLIST "Activate Task List"
+ AFX_IDS_MDICHILD "Activate this window"
+ AFX_IDS_PREVIEW_CLOSE "Close print preview mode\nCancel Preview"
+END
+
+#endif
+
+#ifdef _UNICODE
+IDR_MANIFEST RT_MANIFEST "res\\mfc1.manifest"
+#endif
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+#define _AFX_NO_SPLITTER_RESOURCES
+#define _AFX_NO_OLE_RESOURCES
+#define _AFX_NO_TRACKER_RESOURCES
+#define _AFX_NO_PROPERTY_RESOURCES
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+LANGUAGE 9, 1
+#pragma code_page(1252)
+#include "res\\mfc1.rc2" // non-Microsoft Visual C++ edited resources
+#include "afxres.rc" // Standard components
+#include "afxprint.rc" // printing/print preview resources
+#endif
+#endif // not APSTUDIO_INVOKED
diff --git a/Tests/MFC/mfc1/mfc1.reg b/Tests/MFC/mfc1/mfc1.reg
new file mode 100644
index 0000000000..9f3a86ffb3
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1.reg
@@ -0,0 +1,13 @@
+REGEDIT
+; This .REG file may be used by your SETUP program.
+; If a SETUP program is not available, the entries below will be
+; registered in your InitInstance automatically with a call to
+; CWinApp::RegisterShellFileTypes and COleObjectFactory::UpdateRegistryAll.
+
+HKEY_CLASSES_ROOT\.mf1 = mfc1.Document
+HKEY_CLASSES_ROOT\mfc1.Document\shell\open\command = mfc1.EXE %1
+HKEY_CLASSES_ROOT\mfc1.Document\shell\open\ddeexec = [open("%1")]
+HKEY_CLASSES_ROOT\mfc1.Document\shell\open\ddeexec\application = mfc1
+ ; note: the application is optional
+ ; (it defaults to the app name in "command")
+HKEY_CLASSES_ROOT\mfc1.Document = mfc1.Document
diff --git a/Tests/MFC/mfc1/mfc1.sln b/Tests/MFC/mfc1/mfc1.sln
new file mode 100644
index 0000000000..78bbe56f21
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1.sln
@@ -0,0 +1,21 @@
+Microsoft Visual Studio Solution File, Format Version 8.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mfc1", "mfc1.vcproj", "{06C08100-1145-4104-AEC3-6BC8C608B819}"
+ ProjectSection(ProjectDependencies) = postProject
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfiguration) = preSolution
+ Debug = Debug
+ Release = Release
+ EndGlobalSection
+ GlobalSection(ProjectConfiguration) = postSolution
+ {06C08100-1145-4104-AEC3-6BC8C608B819}.Debug.ActiveCfg = Debug|Win32
+ {06C08100-1145-4104-AEC3-6BC8C608B819}.Debug.Build.0 = Debug|Win32
+ {06C08100-1145-4104-AEC3-6BC8C608B819}.Release.ActiveCfg = Release|Win32
+ {06C08100-1145-4104-AEC3-6BC8C608B819}.Release.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
+ GlobalSection(ExtensibilityAddIns) = postSolution
+ EndGlobalSection
+EndGlobal
diff --git a/Tests/MFC/mfc1/mfc1.vcproj b/Tests/MFC/mfc1/mfc1.vcproj
new file mode 100644
index 0000000000..6df86e564e
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1.vcproj
@@ -0,0 +1,216 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="mfc1"
+ ProjectGUID="{06C08100-1145-4104-AEC3-6BC8C608B819}"
+ Keyword="MFCProj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ UseOfMFC="2"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ TreatWChar_tAsBuiltInType="TRUE"
+ UsePrecompiledHeader="3"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"
+ PreprocessorDefinitions="_DEBUG"
+ MkTypLibCompatible="FALSE"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ AdditionalIncludeDirectories="$(IntDir)"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ UseOfMFC="2"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG"
+ MinimalRebuild="FALSE"
+ RuntimeLibrary="2"
+ TreatWChar_tAsBuiltInType="TRUE"
+ UsePrecompiledHeader="3"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"
+ PreprocessorDefinitions="NDEBUG"
+ MkTypLibCompatible="FALSE"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ AdditionalIncludeDirectories="$(IntDir)"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ <File
+ RelativePath=".\ChildFrm.cpp">
+ </File>
+ <File
+ RelativePath=".\MainFrm.cpp">
+ </File>
+ <File
+ RelativePath=".\mfc1.cpp">
+ </File>
+ <File
+ RelativePath=".\mfc1Doc.cpp">
+ </File>
+ <File
+ RelativePath=".\mfc1View.cpp">
+ </File>
+ <File
+ RelativePath=".\stdafx.cpp">
+ <FileConfiguration
+ Name="Debug|Win32">
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32">
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ <File
+ RelativePath=".\ChildFrm.h">
+ </File>
+ <File
+ RelativePath=".\MainFrm.h">
+ </File>
+ <File
+ RelativePath=".\mfc1.h">
+ </File>
+ <File
+ RelativePath=".\mfc1Doc.h">
+ </File>
+ <File
+ RelativePath=".\mfc1View.h">
+ </File>
+ <File
+ RelativePath=".\Resource.h">
+ </File>
+ <File
+ RelativePath=".\stdafx.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ <File
+ RelativePath=".\res\mfc1.ico">
+ </File>
+ <File
+ RelativePath=".\mfc1.rc">
+ </File>
+ <File
+ RelativePath=".\res\mfc1.rc2">
+ </File>
+ <File
+ RelativePath=".\res\mfc1Doc.ico">
+ </File>
+ <File
+ RelativePath=".\res\Toolbar.bmp">
+ </File>
+ </Filter>
+ <File
+ RelativePath=".\res\mfc1.manifest">
+ </File>
+ <File
+ RelativePath=".\mfc1.reg">
+ </File>
+ <File
+ RelativePath=".\ReadMe.txt">
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/Tests/MFC/mfc1/mfc1Doc.cpp b/Tests/MFC/mfc1/mfc1Doc.cpp
new file mode 100644
index 0000000000..8767052ed2
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1Doc.cpp
@@ -0,0 +1,78 @@
+// mfc1Doc.cpp : implementation of the Cmfc1Doc class
+//
+
+#include "stdafx.h"
+#include "mfc1.h"
+
+#include "mfc1Doc.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+
+// Cmfc1Doc
+
+IMPLEMENT_DYNCREATE(Cmfc1Doc, CDocument)
+
+BEGIN_MESSAGE_MAP(Cmfc1Doc, CDocument)
+END_MESSAGE_MAP()
+
+
+// Cmfc1Doc construction/destruction
+
+Cmfc1Doc::Cmfc1Doc()
+{
+ // TODO: add one-time construction code here
+
+}
+
+Cmfc1Doc::~Cmfc1Doc()
+{
+}
+
+BOOL Cmfc1Doc::OnNewDocument()
+{
+ if (!CDocument::OnNewDocument())
+ return FALSE;
+
+ // TODO: add reinitialization code here
+ // (SDI documents will reuse this document)
+
+ return TRUE;
+}
+
+
+
+
+// Cmfc1Doc serialization
+
+void Cmfc1Doc::Serialize(CArchive& ar)
+{
+ if (ar.IsStoring())
+ {
+ // TODO: add storing code here
+ }
+ else
+ {
+ // TODO: add loading code here
+ }
+}
+
+
+// Cmfc1Doc diagnostics
+
+#ifdef _DEBUG
+void Cmfc1Doc::AssertValid() const
+{
+ CDocument::AssertValid();
+}
+
+void Cmfc1Doc::Dump(CDumpContext& dc) const
+{
+ CDocument::Dump(dc);
+}
+#endif //_DEBUG
+
+
+// Cmfc1Doc commands
diff --git a/Tests/MFC/mfc1/mfc1Doc.h b/Tests/MFC/mfc1/mfc1Doc.h
new file mode 100644
index 0000000000..92d8e3541c
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1Doc.h
@@ -0,0 +1,37 @@
+// mfc1Doc.h : interface of the Cmfc1Doc class
+//
+
+
+#pragma once
+
+class Cmfc1Doc : public CDocument
+{
+protected: // create from serialization only
+ Cmfc1Doc();
+ DECLARE_DYNCREATE(Cmfc1Doc)
+
+// Attributes
+public:
+
+// Operations
+public:
+
+// Overrides
+ public:
+ virtual BOOL OnNewDocument();
+ virtual void Serialize(CArchive& ar);
+
+// Implementation
+public:
+ virtual ~Cmfc1Doc();
+#ifdef _DEBUG
+ virtual void AssertValid() const;
+ virtual void Dump(CDumpContext& dc) const;
+#endif
+
+protected:
+
+// Generated message map functions
+protected:
+ DECLARE_MESSAGE_MAP()
+};
diff --git a/Tests/MFC/mfc1/mfc1View.cpp b/Tests/MFC/mfc1/mfc1View.cpp
new file mode 100644
index 0000000000..06c765230f
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1View.cpp
@@ -0,0 +1,99 @@
+// mfc1View.cpp : implementation of the Cmfc1View class
+//
+
+#include "stdafx.h"
+#include "mfc1.h"
+
+#include "mfc1Doc.h"
+#include "mfc1View.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+
+// Cmfc1View
+
+IMPLEMENT_DYNCREATE(Cmfc1View, CView)
+
+BEGIN_MESSAGE_MAP(Cmfc1View, CView)
+ // Standard printing commands
+ ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
+ ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
+ ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
+END_MESSAGE_MAP()
+
+// Cmfc1View construction/destruction
+
+Cmfc1View::Cmfc1View()
+{
+ // TODO: add construction code here
+
+}
+
+Cmfc1View::~Cmfc1View()
+{
+}
+
+BOOL Cmfc1View::PreCreateWindow(CREATESTRUCT& cs)
+{
+ // TODO: Modify the Window class or styles here by modifying
+ // the CREATESTRUCT cs
+
+ return CView::PreCreateWindow(cs);
+}
+
+// Cmfc1View drawing
+
+void Cmfc1View::OnDraw(CDC* /*pDC*/)
+{
+ Cmfc1Doc* pDoc = GetDocument();
+ ASSERT_VALID(pDoc);
+ if (!pDoc)
+ return;
+
+ // TODO: add draw code for native data here
+}
+
+
+// Cmfc1View printing
+
+BOOL Cmfc1View::OnPreparePrinting(CPrintInfo* pInfo)
+{
+ // default preparation
+ return DoPreparePrinting(pInfo);
+}
+
+void Cmfc1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
+{
+ // TODO: add extra initialization before printing
+}
+
+void Cmfc1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
+{
+ // TODO: add cleanup after printing
+}
+
+
+// Cmfc1View diagnostics
+
+#ifdef _DEBUG
+void Cmfc1View::AssertValid() const
+{
+ CView::AssertValid();
+}
+
+void Cmfc1View::Dump(CDumpContext& dc) const
+{
+ CView::Dump(dc);
+}
+
+Cmfc1Doc* Cmfc1View::GetDocument() const // non-debug version is inline
+{
+ ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Cmfc1Doc)));
+ return (Cmfc1Doc*)m_pDocument;
+}
+#endif //_DEBUG
+
+
+// Cmfc1View message handlers
diff --git a/Tests/MFC/mfc1/mfc1View.h b/Tests/MFC/mfc1/mfc1View.h
new file mode 100644
index 0000000000..42446536bb
--- /dev/null
+++ b/Tests/MFC/mfc1/mfc1View.h
@@ -0,0 +1,48 @@
+// mfc1View.h : interface of the Cmfc1View class
+//
+
+
+#pragma once
+
+
+class Cmfc1View : public CView
+{
+protected: // create from serialization only
+ Cmfc1View();
+ DECLARE_DYNCREATE(Cmfc1View)
+
+// Attributes
+public:
+ Cmfc1Doc* GetDocument() const;
+
+// Operations
+public:
+
+// Overrides
+ public:
+ virtual void OnDraw(CDC* pDC); // overridden to draw this view
+virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
+protected:
+ virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
+ virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
+ virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
+
+// Implementation
+public:
+ virtual ~Cmfc1View();
+#ifdef _DEBUG
+ virtual void AssertValid() const;
+ virtual void Dump(CDumpContext& dc) const;
+#endif
+
+protected:
+
+// Generated message map functions
+protected:
+ DECLARE_MESSAGE_MAP()
+};
+
+#ifndef _DEBUG // debug version in mfc1View.cpp
+inline Cmfc1Doc* Cmfc1View::GetDocument() const
+ { return reinterpret_cast<Cmfc1Doc*>(m_pDocument); }
+#endif
diff --git a/Tests/MFC/mfc1/res/Toolbar.bmp b/Tests/MFC/mfc1/res/Toolbar.bmp
new file mode 100644
index 0000000000..d501723c1c
--- /dev/null
+++ b/Tests/MFC/mfc1/res/Toolbar.bmp
Binary files differ
diff --git a/Tests/MFC/mfc1/res/mfc1.ico b/Tests/MFC/mfc1/res/mfc1.ico
new file mode 100644
index 0000000000..8a84ca3d34
--- /dev/null
+++ b/Tests/MFC/mfc1/res/mfc1.ico
Binary files differ
diff --git a/Tests/MFC/mfc1/res/mfc1.manifest b/Tests/MFC/mfc1/res/mfc1.manifest
new file mode 100644
index 0000000000..b15d2f2f22
--- /dev/null
+++ b/Tests/MFC/mfc1/res/mfc1.manifest
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+<assemblyIdentity
+ version="1.0.0.0"
+ processorArchitecture="X86"
+ name="Microsoft.Windows.mfc1"
+ type="win32"
+/>
+<description>Your app description here</description>
+<dependency>
+ <dependentAssembly>
+ <assemblyIdentity
+ type="win32"
+ name="Microsoft.Windows.Common-Controls"
+ version="6.0.0.0"
+ processorArchitecture="X86"
+ publicKeyToken="6595b64144ccf1df"
+ language="*"
+ />
+ </dependentAssembly>
+</dependency>
+</assembly>
diff --git a/Tests/MFC/mfc1/res/mfc1.rc2 b/Tests/MFC/mfc1/res/mfc1.rc2
new file mode 100644
index 0000000000..62a3ab0d60
--- /dev/null
+++ b/Tests/MFC/mfc1/res/mfc1.rc2
@@ -0,0 +1,13 @@
+//
+// mfc1.RC2 - resources Microsoft Visual C++ does not edit directly
+//
+
+#ifdef APSTUDIO_INVOKED
+#error this file is not editable by Microsoft Visual C++
+#endif //APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+// Add manually edited resources here...
+
+/////////////////////////////////////////////////////////////////////////////
diff --git a/Tests/MFC/mfc1/res/mfc1Doc.ico b/Tests/MFC/mfc1/res/mfc1Doc.ico
new file mode 100644
index 0000000000..2a1f1ae6ef
--- /dev/null
+++ b/Tests/MFC/mfc1/res/mfc1Doc.ico
Binary files differ
diff --git a/Tests/MFC/mfc1/stdafx.cpp b/Tests/MFC/mfc1/stdafx.cpp
new file mode 100644
index 0000000000..67fd1b5394
--- /dev/null
+++ b/Tests/MFC/mfc1/stdafx.cpp
@@ -0,0 +1,5 @@
+// stdafx.cpp : source file that includes just the standard includes
+// mfc1.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
diff --git a/Tests/MFC/mfc1/stdafx.h b/Tests/MFC/mfc1/stdafx.h
new file mode 100644
index 0000000000..35a678dcde
--- /dev/null
+++ b/Tests/MFC/mfc1/stdafx.h
@@ -0,0 +1,56 @@
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently,
+// but are changed infrequently
+
+#pragma once
+
+#ifndef VC_EXTRALEAN
+#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
+#endif
+
+// See http://msdn.microsoft.com/en-us/library/6sehtctf.aspx for more info
+// on WINVER and _WIN32_WINNT
+
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
+#if _MSC_VER < 1600
+#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
+#else
+#define WINVER 0x0501 // Target Windows XP and later with VS 10 and later
+#endif
+#endif
+
+#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
+#if _MSC_VER < 1600
+#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
+#else
+#define _WIN32_WINNT 0x0501 // Target Windows XP and later with VS 10 and later
+#endif
+#endif
+
+#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
+#if _MSC_VER < 1600
+#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
+#endif
+#endif
+
+#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
+#if _MSC_VER < 1600
+#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
+#endif
+#endif
+
+#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
+
+// turns off MFC's hiding of some common and often safely ignored warning messages
+#define _AFX_ALL_WARNINGS
+
+#include <afxwin.h> // MFC core and standard components
+#include <afxext.h> // MFC extensions
+#include <afxdisp.h> // MFC Automation classes
+
+#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
+#ifndef _AFX_NO_AFXCMN_SUPPORT
+#include <afxcmn.h> // MFC support for Windows Common Controls
+#endif // _AFX_NO_AFXCMN_SUPPORT
diff --git a/Tests/MFC/try_compile/CMakeLists.txt b/Tests/MFC/try_compile/CMakeLists.txt
new file mode 100644
index 0000000000..8e5d746f61
--- /dev/null
+++ b/Tests/MFC/try_compile/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.8)
+project(try_compile_mfc)
+
+set(files
+ stdafx.cpp
+ stdafx.h
+)
+
+set(CMAKE_MFC_FLAG "2")
+
+# VS generators add this automatically based on the CMAKE_MFC_FLAG value,
+# but generators matching "Make" require:
+add_definitions(-D_AFXDLL)
+
+add_executable(simplest_possible_mfc_exe WIN32 ${files})
diff --git a/Tests/MacRuntimePath/A/CMakeLists.txt b/Tests/MacRuntimePath/A/CMakeLists.txt
new file mode 100644
index 0000000000..ade0a3cfb8
--- /dev/null
+++ b/Tests/MacRuntimePath/A/CMakeLists.txt
@@ -0,0 +1,70 @@
+cmake_minimum_required(VERSION 2.8)
+project(MacRuntimePath_A)
+
+# a shared library
+add_library(shared SHARED shared.cpp shared.h)
+set_target_properties(shared PROPERTIES MACOSX_RPATH 1)
+
+# a shared library with custom set @rpath
+add_library(shared2 SHARED shared.cpp shared.h)
+set_target_properties(shared2 PROPERTIES
+ BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@rpath")
+
+cmake_policy(SET CMP0042 NEW)
+
+# a framework library
+add_library(framework SHARED framework.cpp framework.h)
+set_target_properties(framework PROPERTIES FRAMEWORK 1)
+
+# another framework
+add_library(framework2 SHARED framework2.cpp framework2.h)
+set_target_properties(framework2 PROPERTIES FRAMEWORK 1)
+
+# executable to test a shared library dependency with install rpaths
+add_executable(test1 test1.cpp)
+target_link_libraries(test1 shared)
+set_target_properties(test1 PROPERTIES
+ BUILD_WITH_INSTALL_RPATH 1 INSTALL_RPATH "@loader_path/../lib")
+
+# executable to test a framework library dependency with install rpaths
+add_executable(test2 test2.cpp)
+target_link_libraries(test2 framework)
+set_target_properties(test2 PROPERTIES
+ BUILD_WITH_INSTALL_RPATH 1 INSTALL_RPATH "@loader_path/../lib")
+
+# executable to test a framework library dependency with build tree rpaths
+add_executable(test3 test3.cpp)
+target_link_libraries(test3 framework)
+
+# executable to test a framework library dependency with build tree rpaths
+add_executable(test4 test1.cpp)
+target_link_libraries(test4 shared2)
+
+set_target_properties(shared shared2 framework PROPERTIES
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
+set_target_properties(test1 test2 test3 test4 PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
+foreach(config ${CMAKE_CONFIGURATION_TYPES})
+ string(TOUPPER ${config} CONFIG)
+ set_target_properties(shared shared2 framework PROPERTIES
+ LIBRARY_OUTPUT_DIRECTORY_${CONFIG}
+ "${CMAKE_CURRENT_BINARY_DIR}/${config}/lib")
+ set_target_properties(test1 test2 test3 test4 PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY_${CONFIG}
+ "${CMAKE_CURRENT_BINARY_DIR}/${config}/bin")
+endforeach()
+
+foreach(test test1 test2 test3 test4)
+ add_custom_target(${test}_run ALL
+ COMMAND ${test}
+ DEPENDS ${test}
+ )
+endforeach()
+
+export(TARGETS shared shared2 framework FILE "${CMAKE_CURRENT_BINARY_DIR}/exp.cmake")
+
+install(TARGETS shared EXPORT MyExport DESTINATION lib)
+install(TARGETS shared2 EXPORT MyExport DESTINATION lib2)
+install(TARGETS framework EXPORT MyExport DESTINATION lib-fw)
+install(TARGETS framework2 EXPORT MyExport DESTINATION lib-fw2)
+install(EXPORT MyExport DESTINATION lib FILE exp.cmake)
diff --git a/Tests/MacRuntimePath/A/framework.cpp b/Tests/MacRuntimePath/A/framework.cpp
new file mode 100644
index 0000000000..abda195edb
--- /dev/null
+++ b/Tests/MacRuntimePath/A/framework.cpp
@@ -0,0 +1,8 @@
+
+#include "framework.h"
+#include "stdio.h"
+
+void framework()
+{
+ printf("framework\n");
+}
diff --git a/Tests/MacRuntimePath/A/framework.h b/Tests/MacRuntimePath/A/framework.h
new file mode 100644
index 0000000000..bdd10f05d6
--- /dev/null
+++ b/Tests/MacRuntimePath/A/framework.h
@@ -0,0 +1,17 @@
+
+#ifndef framework_h
+#define framework_h
+
+#ifdef WIN32
+# ifdef framework_EXPORTS
+# define FRAMEWORK_EXPORT __declspec(dllexport)
+# else
+# define FRAMEWORK_EXPORT __declspec(dllimport)
+# endif
+#else
+# define FRAMEWORK_EXPORT
+#endif
+
+void FRAMEWORK_EXPORT framework();
+
+#endif
diff --git a/Tests/MacRuntimePath/A/framework2.cpp b/Tests/MacRuntimePath/A/framework2.cpp
new file mode 100644
index 0000000000..d3c2c458d2
--- /dev/null
+++ b/Tests/MacRuntimePath/A/framework2.cpp
@@ -0,0 +1,8 @@
+
+#include "framework2.h"
+#include "stdio.h"
+
+void framework2()
+{
+ printf("framework 2\n");
+}
diff --git a/Tests/MacRuntimePath/A/framework2.h b/Tests/MacRuntimePath/A/framework2.h
new file mode 100644
index 0000000000..4576d12dcb
--- /dev/null
+++ b/Tests/MacRuntimePath/A/framework2.h
@@ -0,0 +1,17 @@
+
+#ifndef framework2_h
+#define framework2_h
+
+#ifdef WIN32
+# ifdef framework2_EXPORTS
+# define FRAMEWORK2_EXPORT __declspec(dllexport)
+# else
+# define FRAMEWORK2_EXPORT __declspec(dllimport)
+# endif
+#else
+# define FRAMEWORK2_EXPORT
+#endif
+
+void FRAMEWORK2_EXPORT framework2();
+
+#endif
diff --git a/Tests/MacRuntimePath/A/shared.cpp b/Tests/MacRuntimePath/A/shared.cpp
new file mode 100644
index 0000000000..e5e7dc5aeb
--- /dev/null
+++ b/Tests/MacRuntimePath/A/shared.cpp
@@ -0,0 +1,8 @@
+
+#include "shared.h"
+#include "stdio.h"
+
+void shared()
+{
+ printf("shared\n");
+}
diff --git a/Tests/MacRuntimePath/A/shared.h b/Tests/MacRuntimePath/A/shared.h
new file mode 100644
index 0000000000..3588fb88ed
--- /dev/null
+++ b/Tests/MacRuntimePath/A/shared.h
@@ -0,0 +1,17 @@
+
+#ifndef shared_h
+#define shared_h
+
+#ifdef WIN32
+# ifdef shared_EXPORTS
+# define SHARED_EXPORT __declspec(dllexport)
+# else
+# define SHARED_EXPORT __declspec(dllimport)
+# endif
+#else
+# define SHARED_EXPORT
+#endif
+
+void SHARED_EXPORT shared();
+
+#endif
diff --git a/Tests/MacRuntimePath/A/test1.cpp b/Tests/MacRuntimePath/A/test1.cpp
new file mode 100644
index 0000000000..cb934488fe
--- /dev/null
+++ b/Tests/MacRuntimePath/A/test1.cpp
@@ -0,0 +1,8 @@
+
+#include "shared.h"
+
+int main(int, char**)
+{
+ shared();
+ return 0;
+}
diff --git a/Tests/MacRuntimePath/A/test2.cpp b/Tests/MacRuntimePath/A/test2.cpp
new file mode 100644
index 0000000000..26bc9ddf99
--- /dev/null
+++ b/Tests/MacRuntimePath/A/test2.cpp
@@ -0,0 +1,8 @@
+
+#include "framework.h"
+
+int main(int, char**)
+{
+ framework();
+ return 0;
+}
diff --git a/Tests/MacRuntimePath/A/test3.cpp b/Tests/MacRuntimePath/A/test3.cpp
new file mode 100644
index 0000000000..26bc9ddf99
--- /dev/null
+++ b/Tests/MacRuntimePath/A/test3.cpp
@@ -0,0 +1,8 @@
+
+#include "framework.h"
+
+int main(int, char**)
+{
+ framework();
+ return 0;
+}
diff --git a/Tests/MacRuntimePath/B/CMakeLists.txt b/Tests/MacRuntimePath/B/CMakeLists.txt
new file mode 100644
index 0000000000..4317af6558
--- /dev/null
+++ b/Tests/MacRuntimePath/B/CMakeLists.txt
@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 2.8)
+project(MacRuntimePath_B)
+
+include(${MacRuntimePath_B_BINARY_DIR}/../Root/lib/exp.cmake)
+
+add_executable(testb ${MacRuntimePath_B_SOURCE_DIR}/../A/test3.cpp)
+
+# test link with rpath enabled targets
+target_link_libraries(testb shared framework)
+
+# test link with rpath enabled library by filename
+find_library(fw2 NAMES framework2 HINTS ${MacRuntimePath_B_BINARY_DIR}/../Root/lib-fw2)
+target_link_libraries(testb $<TARGET_LINKER_FILE:shared2> ${fw2})
+
+add_custom_target(testb_run ALL
+ COMMAND testb
+ DEPENDS testb
+ )
diff --git a/Tests/MacRuntimePath/CMakeLists.txt b/Tests/MacRuntimePath/CMakeLists.txt
new file mode 100644
index 0000000000..3e9ab8a558
--- /dev/null
+++ b/Tests/MacRuntimePath/CMakeLists.txt
@@ -0,0 +1,74 @@
+cmake_minimum_required (VERSION 2.8)
+project(MacRuntimePath)
+if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
+endif()
+
+# Wipe out the install tree to make sure the exporter works.
+add_custom_command(
+ OUTPUT ${MacRuntimePath_BINARY_DIR}/CleanupProject
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${MacRuntimePath_BINARY_DIR}/Root
+ )
+add_custom_target(CleanupTarget ALL DEPENDS ${MacRuntimePath_BINARY_DIR}/CleanupProject)
+set_property(
+ SOURCE ${MacRuntimePath_BINARY_DIR}/CleanupProject
+ PROPERTY SYMBOLIC 1
+ )
+
+configure_file(${MacRuntimePath_SOURCE_DIR}/InitialCache.cmake.in
+ ${MacRuntimePath_BINARY_DIR}/InitialCache.cmake @ONLY)
+
+if(CMAKE_CONFIGURATION_TYPES)
+ set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
+else()
+ if(CMAKE_BUILD_TYPE)
+ set(NESTED_CONFIG_TYPE -C "${CMAKE_BUILD_TYPE}")
+ else()
+ set(NESTED_CONFIG_TYPE)
+ endif()
+endif()
+
+# Build and install the exporter.
+add_custom_command(
+ OUTPUT ${MacRuntimePath_BINARY_DIR}/ExportProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
+ --build-and-test
+ ${MacRuntimePath_SOURCE_DIR}/A
+ ${MacRuntimePath_BINARY_DIR}/A
+ --build-noclean
+ --build-project MacRuntimePath_A
+ --build-target install
+ --build-generator ${CMAKE_GENERATOR}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-options -C${MacRuntimePath_BINARY_DIR}/InitialCache.cmake
+ VERBATIM
+ )
+add_custom_target(ExportTarget ALL DEPENDS ${MacRuntimePath_BINARY_DIR}/ExportProject)
+add_dependencies(ExportTarget CleanupTarget)
+set_property(
+ SOURCE ${MacRuntimePath_BINARY_DIR}/ExportProject
+ PROPERTY SYMBOLIC 1
+ )
+
+# Build the importer.
+add_custom_command(
+ OUTPUT ${MacRuntimePath_BINARY_DIR}/ImportProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
+ --build-and-test
+ ${MacRuntimePath_SOURCE_DIR}/B
+ ${MacRuntimePath_BINARY_DIR}/B
+ --build-noclean
+ --build-project MacRuntimePath_B
+ --build-generator ${CMAKE_GENERATOR}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-options -C${MacRuntimePath_BINARY_DIR}/InitialCache.cmake
+ VERBATIM
+ )
+add_custom_target(ImportTarget ALL DEPENDS ${MacRuntimePath_BINARY_DIR}/ImportProject)
+add_dependencies(ImportTarget ExportTarget)
+set_property(
+ SOURCE ${MacRuntimePath_BINARY_DIR}/ImportProject
+ PROPERTY SYMBOLIC 1
+ )
diff --git a/Tests/MacRuntimePath/InitialCache.cmake.in b/Tests/MacRuntimePath/InitialCache.cmake.in
new file mode 100644
index 0000000000..a9f6a3c0de
--- /dev/null
+++ b/Tests/MacRuntimePath/InitialCache.cmake.in
@@ -0,0 +1,14 @@
+set(CMAKE_MAKE_PROGRAM "@CMake_TEST_NESTED_MAKE_PROGRAM@" CACHE FILEPATH "Make Program")
+set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@" CACHE STRING "C Compiler")
+set(CMAKE_C_FLAGS "@CMAKE_C_FLAGS@" CACHE STRING "C Flags")
+set(CMAKE_C_FLAGS_DEBUG "@CMAKE_C_FLAGS_DEBUG@" CACHE STRING "C Flags")
+set(CMAKE_C_FLAGS_RELEASE "@CMAKE_C_FLAGS_RELEASE@" CACHE STRING "C Flags")
+set(CMAKE_C_FLAGS_MINSIZEREL "@CMAKE_C_FLAGS_MINSIZEREL@" CACHE STRING "C Flags")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "@CMAKE_C_FLAGS_RELWITHDEBINFO@" CACHE STRING "C Flags")
+set(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@" CACHE STRING "C++ Compiler")
+set(CMAKE_CXX_FLAGS "@CMAKE_CXX_FLAGS@" CACHE STRING "C++ Flags")
+set(CMAKE_CXX_FLAGS_DEBUG "@CMAKE_CXX_FLAGS_DEBUG@" CACHE STRING "C++ Flags")
+set(CMAKE_CXX_FLAGS_RELEASE "@CMAKE_CXX_FLAGS_RELEASE@" CACHE STRING "C++ Flags")
+set(CMAKE_CXX_FLAGS_MINSIZEREL "@CMAKE_CXX_FLAGS_MINSIZEREL@" CACHE STRING "C++ Flags")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "@CMAKE_CXX_FLAGS_RELWITHDEBINFO@" CACHE STRING "C++ Flags")
+set(CMAKE_INSTALL_PREFIX "@MacRuntimePath_BINARY_DIR@/Root" CACHE STRING "Installation Prefix")
diff --git a/Tests/MacroTest/CMakeLists.txt b/Tests/MacroTest/CMakeLists.txt
new file mode 100644
index 0000000000..6c6dfb6251
--- /dev/null
+++ b/Tests/MacroTest/CMakeLists.txt
@@ -0,0 +1,91 @@
+# a simple C only test case
+cmake_minimum_required (VERSION 2.6)
+project (MacroTest)
+
+macro(FAILED testname)
+ message(SEND_ERROR "${testname} failed ${ARGN}")
+endmacro()
+
+macro(PASS testname)
+ message("${testname} passed ${ARGN}")
+endmacro()
+
+# test ARGC
+macro(weird_name)
+ if("${ARGC}" EQUAL "3")
+ PASS("ARGC")
+ else()
+ FAILED("ARGC" "Got: ${ARGC}")
+ endif()
+endmacro()
+WeIrD_nAmE(a1 a2 a3)
+
+# test ARGN
+macro(test_argn_macro argument)
+ if("${ARGN}" EQUAL "3")
+ PASS("ARGN")
+ else()
+ FAILED("ARGN" "Got: ${ARGN}")
+ endif()
+endmacro()
+Test_Argn_Macro(ignored 3)
+
+# case test
+macro(strange_macro m)
+ set("${m}" strange_macro)
+endmacro()
+STRANGE_MACRO(var)
+set(second_var "second_var")
+if("x${var}" STREQUAL "xstrange_macro" AND "x${second_var}" STREQUAL "xsecond_var")
+ PASS("Case Test" "(${var} ${second_var})")
+else()
+ FAILED("Case test" "(${var} ${second_var})")
+endif()
+
+# test backing up command
+macro(ADD_EXECUTABLE exec)
+ _ADD_EXECUTABLE("mini${exec}" ${ARGN})
+endmacro()
+
+include(CheckCSourceCompiles)
+Check_C_Source_Compiles(
+"
+#include <stdio.h>
+#ifdef __CLASSIC_C__
+int main(){
+ int ac;
+ char*av[];
+#else
+int main(int ac, char*av[]){
+#endif
+ if(ac > 1000){return *av[0];}
+ return 0;
+}"
+SOME_CHECK)
+if(SOME_CHECK)
+ message("CheckCSourceCompiles works")
+else()
+ message(FATAL_ERROR "CheckCSourceCompiles does not work")
+endif()
+
+include(CheckCXXSourceCompiles)
+Check_CXX_Source_Compiles(
+"
+#include <stdio.h>
+int main(int ac, char*av[]){
+ if(ac > 1000){return *av[0];}
+ return 0;
+}"
+SOME_CHECK)
+if(SOME_CHECK)
+ message("CheckCXXSourceCompiles works")
+else()
+ message(FATAL_ERROR "CheckCXXSourceCompiles does not work")
+endif()
+
+add_executable(MacroTest macroTest.c)
+
+macro(GET_CURRENT_FILE var)
+ set(${var} ${CMAKE_CURRENT_LIST_FILE})
+endmacro()
+include(context.cmake)
diff --git a/Tests/MacroTest/context.cmake b/Tests/MacroTest/context.cmake
new file mode 100644
index 0000000000..f7350d7713
--- /dev/null
+++ b/Tests/MacroTest/context.cmake
@@ -0,0 +1,10 @@
+GET_CURRENT_FILE(current_file)
+if(NOT "${current_file}" STREQUAL "${CMAKE_CURRENT_LIST_FILE}")
+ message(FATAL_ERROR
+ "Macro file context is broken. Expected:\n"
+ " ${CMAKE_CURRENT_LIST_FILE}\n"
+ "but got:\n"
+ " ${current_file}\n"
+ "from the macro."
+ )
+endif()
diff --git a/Tests/MacroTest/macroTest.c b/Tests/MacroTest/macroTest.c
new file mode 100644
index 0000000000..e0ced6afd1
--- /dev/null
+++ b/Tests/MacroTest/macroTest.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char* argv[])
+{
+ printf("Running command: %s with %d arguments\n", argv[0], argc);
+ return 0;
+}
diff --git a/Tests/MakeClean/CMakeLists.txt b/Tests/MakeClean/CMakeLists.txt
new file mode 100644
index 0000000000..8ac624a636
--- /dev/null
+++ b/Tests/MakeClean/CMakeLists.txt
@@ -0,0 +1,50 @@
+cmake_minimum_required (VERSION 2.6)
+project(MakeClean)
+
+# Build the to-clean project.
+try_compile(TOCLEAN_BUILT
+ ${MakeClean_BINARY_DIR}/ToClean
+ ${MakeClean_SOURCE_DIR}/ToClean
+ ToClean
+ OUTPUT_VARIABLE OUTPUT
+ )
+if(TOCLEAN_BUILT)
+ message(
+ "Building ToClean succeeded with the following output:\n"
+ "[${OUTPUT}]"
+ )
+else()
+ message(FATAL_ERROR
+ "Building ToClean failed with the following output:\n"
+ "[${OUTPUT}]"
+ )
+endif()
+
+# Get the set of files to check from the ToClean project.
+include(${MakeClean_BINARY_DIR}/ToClean/ToCleanFiles.cmake)
+
+# Check for the existence of the files.
+foreach(f ${TOCLEAN_FILES})
+ if(EXISTS "${f}")
+ else()
+ message(FATAL_ERROR "File \"${f}\" does not exist!")
+ endif()
+endforeach()
+
+# Configure an executable to check that all the files are missing.
+set(CHECK_FILES)
+foreach(f ${TOCLEAN_FILES})
+ set(CHECK_FILES "${CHECK_FILES} \"${f}\",\n")
+endforeach()
+configure_file(${MakeClean_SOURCE_DIR}/check_clean.c.in
+ ${MakeClean_BINARY_DIR}/check_clean.c @ONLY)
+add_executable(check_clean ${MakeClean_BINARY_DIR}/check_clean.c)
+
+# After the executable builds, clean the files.
+add_custom_command(
+ TARGET check_clean
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} --build ${MakeClean_BINARY_DIR}/ToClean
+ --target clean
+ COMMENT "Clean the ToClean Project"
+ )
diff --git a/Tests/MakeClean/ToClean/CMakeLists.txt b/Tests/MakeClean/ToClean/CMakeLists.txt
new file mode 100644
index 0000000000..d0e24cefe3
--- /dev/null
+++ b/Tests/MakeClean/ToClean/CMakeLists.txt
@@ -0,0 +1,42 @@
+cmake_minimum_required(VERSION 2.6)
+project(ToClean)
+
+# Build a simple project.
+add_executable(toclean toclean.cxx)
+
+# List some build-time-generated files.
+set(TOCLEAN_FILES ${TOCLEAN_FILES}
+ "${ToClean_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}")
+
+# Create a file that must be registered for cleaning.
+file(WRITE "${ToClean_BINARY_DIR}/Registered.txt"
+ "File registered for cleaning.\n")
+set_directory_properties(PROPERTIES
+ ADDITIONAL_MAKE_CLEAN_FILES "${ToClean_BINARY_DIR}/Registered.txt")
+set(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/Registered.txt")
+
+# Create a custom command whose output should be cleaned.
+add_custom_command(OUTPUT ${ToClean_BINARY_DIR}/generated.txt
+ DEPENDS ${ToClean_SOURCE_DIR}/toclean.cxx
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${ToClean_SOURCE_DIR}/toclean.cxx
+ ${ToClean_BINARY_DIR}/generated.txt
+ )
+add_custom_target(generate ALL DEPENDS ${ToClean_BINARY_DIR}/generated.txt)
+set(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/generated.txt")
+
+# Create a custom command whose output should be cleaned, but whose name
+# is not known until generate-time
+set(copied_exe "$<TARGET_FILE_DIR:toclean>/toclean_copy${CMAKE_EXECUTABLE_SUFFIX}")
+add_custom_command(TARGET toclean POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy $<TARGET_FILE:toclean>
+ ${copied_exe}
+ )
+set_property(DIRECTORY APPEND PROPERTY
+ ADDITIONAL_MAKE_CLEAN_FILES ${copied_exe})
+list(APPEND TOCLEAN_FILES "${ToClean_BINARY_DIR}/toclean_copy${CMAKE_EXECUTABLE_SUFFIX}")
+
+# Configure a file listing these build-time-generated files.
+configure_file(${ToClean_SOURCE_DIR}/ToCleanFiles.cmake.in
+ ${ToClean_BINARY_DIR}/ToCleanFiles.cmake @ONLY)
diff --git a/Tests/MakeClean/ToClean/ToCleanFiles.cmake.in b/Tests/MakeClean/ToClean/ToCleanFiles.cmake.in
new file mode 100644
index 0000000000..e7d99470cb
--- /dev/null
+++ b/Tests/MakeClean/ToClean/ToCleanFiles.cmake.in
@@ -0,0 +1 @@
+set(TOCLEAN_FILES "@TOCLEAN_FILES@")
diff --git a/Tests/MakeClean/ToClean/toclean.cxx b/Tests/MakeClean/ToClean/toclean.cxx
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/MakeClean/ToClean/toclean.cxx
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/MakeClean/check_clean.c.in b/Tests/MakeClean/check_clean.c.in
new file mode 100644
index 0000000000..5bc4ab8807
--- /dev/null
+++ b/Tests/MakeClean/check_clean.c.in
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+int main()
+{
+ /* The list of files to check. */
+ const char* files[] =
+ {
+ @CHECK_FILES@
+ 0
+ };
+
+ /* No file should exist. */
+ const char** f = files;
+ int result = 0;
+ for(; *f; ++f)
+ {
+ FILE* pf = fopen(*f, "rb");
+ if(pf)
+ {
+ fclose(pf);
+ fprintf(stderr, "File \"%s\" exists!", *f);
+ result = 1;
+ }
+ }
+ return result;
+}
diff --git a/Tests/MathTest/CMakeLists.txt b/Tests/MathTest/CMakeLists.txt
new file mode 100644
index 0000000000..34beaa0aa7
--- /dev/null
+++ b/Tests/MathTest/CMakeLists.txt
@@ -0,0 +1,29 @@
+cmake_minimum_required (VERSION 2.6)
+project(MathTest)
+
+
+# Expression test
+
+set(expressions
+ "5 * ( 3 + 4)"
+ "(1 | 2 | 4 | 8) & 16"
+ "1 +(3*4) + 10 >> 2"
+ "10000 / 20 / 4"
+ "10000 / (20 / 4)"
+ )
+
+set(FILE_EXPRESSIONS "")
+foreach(expression
+ ${expressions})
+ math(EXPR expr "${expression}")
+ set(FILE_EXPRESSIONS "${FILE_EXPRESSIONS}TEST_EXPRESSION(${expression}, ${expr})\n")
+endforeach()
+
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/MathTestTests.h.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/MathTestTests.h"
+ @ONLY)
+
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+add_executable(MathTest MathTestExec.cxx)
+
diff --git a/Tests/MathTest/MathTestExec.cxx b/Tests/MathTest/MathTestExec.cxx
new file mode 100644
index 0000000000..5b94602a68
--- /dev/null
+++ b/Tests/MathTest/MathTestExec.cxx
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+#define TEST_EXPRESSION(x, y) \
+ if ( (x) != (y) ) \
+ { \
+ printf("Problem with EXPR: Expression: \"%s\" in C returns %d while in CMake returns: %d\n", \
+ #x, (x), (y)); \
+ res ++; \
+ }
+
+int main(int argc, char* argv[])
+{
+ if ( argc > 1 )
+ {
+ printf("Usage: %s\n", argv[0]);
+ return 1;
+ }
+ int res = 0;
+#include "MathTestTests.h"
+ if ( res != 0 )
+ {
+ printf("%s: %d math tests failed\n", argv[0], res);
+ return 1;
+ }
+ return 0;
+}
diff --git a/Tests/MathTest/MathTestTests.h.in b/Tests/MathTest/MathTestTests.h.in
new file mode 100644
index 0000000000..39c6861d73
--- /dev/null
+++ b/Tests/MathTest/MathTestTests.h.in
@@ -0,0 +1 @@
+@FILE_EXPRESSIONS@
diff --git a/Tests/MissingInstall/CMakeLists.txt b/Tests/MissingInstall/CMakeLists.txt
new file mode 100644
index 0000000000..91624f710b
--- /dev/null
+++ b/Tests/MissingInstall/CMakeLists.txt
@@ -0,0 +1,25 @@
+cmake_minimum_required (VERSION 2.8.12)
+project(TestMissingInstall)
+
+set(CMAKE_SKIP_INSTALL_RULES ON)
+
+# Skip the dependency that causes a build when installing. This
+# avoids infinite loops when the post-build rule below installs.
+set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY 1)
+set(CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY 1)
+
+if(CMAKE_CONFIGURATION_TYPES)
+ set(MULTI_CONFIG ON)
+else()
+ set(MULTI_CONFIG OFF)
+endif()
+
+add_executable(mybin mybin.cpp)
+install(TARGETS mybin RUNTIME DESTINATION bin)
+
+add_custom_command(TARGET mybin
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} "-DMULTI_CONFIG=${MULTI_CONFIG}"
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/ExpectInstallFail.cmake
+ COMMENT "Install Project"
+)
diff --git a/Tests/MissingInstall/ExpectInstallFail.cmake b/Tests/MissingInstall/ExpectInstallFail.cmake
new file mode 100644
index 0000000000..3d677bf72c
--- /dev/null
+++ b/Tests/MissingInstall/ExpectInstallFail.cmake
@@ -0,0 +1,18 @@
+if(MULTI_CONFIG)
+ set(SI_CONFIG --config $<CONFIGURATION>)
+else()
+ set(SI_CONFIG)
+endif()
+
+execute_process(
+ COMMAND ${CMAKE_COMMAND}
+ --build .
+ --target install ${SI_CONFIG}
+ RESULT_VARIABLE RESULT
+ OUTPUT_VARIABLE OUTPUT
+ ERROR_VARIABLE ERROR
+)
+
+if(RESULT EQUAL 0)
+ message(FATAL_ERROR "install should have failed")
+endif()
diff --git a/Tests/MissingInstall/mybin.cpp b/Tests/MissingInstall/mybin.cpp
new file mode 100644
index 0000000000..237c8ce181
--- /dev/null
+++ b/Tests/MissingInstall/mybin.cpp
@@ -0,0 +1 @@
+int main() {}
diff --git a/Tests/MissingSourceFile/CMakeLists.txt b/Tests/MissingSourceFile/CMakeLists.txt
new file mode 100644
index 0000000000..a7206c897e
--- /dev/null
+++ b/Tests/MissingSourceFile/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8)
+project(MissingSourceFile C)
+add_executable(MissingSourceFile DoesNotExist/MissingSourceFile.c)
diff --git a/Tests/Module/CheckTypeSize/CMakeLists.txt b/Tests/Module/CheckTypeSize/CMakeLists.txt
new file mode 100644
index 0000000000..16989fe23f
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/CMakeLists.txt
@@ -0,0 +1,37 @@
+cmake_minimum_required(VERSION 2.8.1 FATAL_ERROR)
+project(CheckTypeSize)
+
+# Check C types
+include(CheckTypeSize)
+check_type_size("void*" SIZEOF_DATA_PTR)
+check_type_size(char SIZEOF_CHAR)
+check_type_size(short SIZEOF_SHORT)
+check_type_size(int SIZEOF_INT)
+check_type_size(long SIZEOF_LONG)
+check_type_size("long long" SIZEOF_LONG_LONG)
+check_type_size(__int64 SIZEOF___INT64)
+check_type_size(size_t SIZEOF_SIZE_T)
+check_type_size(ssize_t SIZEOF_SSIZE_T)
+
+set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")
+set(CMAKE_EXTRA_INCLUDE_FILES somestruct.h)
+check_type_size("((struct somestruct*)0)->someint" SIZEOF_STRUCTMEMBER_INT)
+check_type_size("((struct somestruct*)0)->someptr" SIZEOF_STRUCTMEMBER_PTR)
+check_type_size("((struct somestruct*)0)->somechar" SIZEOF_STRUCTMEMBER_CHAR)
+
+# Check CXX types
+check_type_size(bool SIZEOF_BOOL LANGUAGE CXX)
+
+set(CMAKE_EXTRA_INCLUDE_FILES someclass.hxx)
+check_type_size("((ns::someclass*)0)->someint" SIZEOF_NS_CLASSMEMBER_INT LANGUAGE CXX)
+check_type_size("((ns::someclass*)0)->someptr" SIZEOF_NS_CLASSMEMBER_PTR LANGUAGE CXX)
+check_type_size("((ns::someclass*)0)->somechar" SIZEOF_NS_CLASSMEMBER_CHAR LANGUAGE CXX)
+check_type_size("((ns::someclass*)0)->somebool" SIZEOF_NS_CLASSMEMBER_BOOL LANGUAGE CXX)
+
+configure_file(config.h.in config.h)
+configure_file(config.hxx.in config.hxx)
+
+include_directories("${CheckTypeSize_BINARY_DIR}")
+
+add_executable(CheckTypeSize CheckTypeSize.c)
+add_executable(CheckTypeSizeCXX CheckTypeSize.cxx)
diff --git a/Tests/Module/CheckTypeSize/CheckTypeSize.c b/Tests/Module/CheckTypeSize/CheckTypeSize.c
new file mode 100644
index 0000000000..32e395cca0
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/CheckTypeSize.c
@@ -0,0 +1,160 @@
+#include "config.h"
+#include "somestruct.h"
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_STDDEF_H
+# include <stddef.h>
+#endif
+
+#include <stdio.h>
+
+#define CHECK(t,m) do { \
+ if(sizeof(t) != m) \
+ { \
+ printf(#m ": expected %d, got %d (line %d)\n", \
+ (int)sizeof(t), (int)m, __LINE__); \
+ result = 1; \
+ } \
+ } while(0)
+
+#define NODEF(m) do { \
+ printf(#m": not defined (line %d)\n", __LINE__); \
+ result = 1; \
+ } while(0)
+
+int main()
+{
+ int result = 0;
+ struct somestruct x;
+
+ /* void* */
+#if !defined(HAVE_SIZEOF_DATA_PTR)
+ NODEF(HAVE_SIZEOF_DATA_PTR);
+#endif
+#if defined(SIZEOF_DATA_PTR)
+ CHECK(void*, SIZEOF_DATA_PTR);
+#else
+ NODEF(SIZEOF_DATA_PTR);
+#endif
+
+ /* char */
+#if !defined(HAVE_SIZEOF_CHAR)
+ NODEF(HAVE_SIZEOF_CHAR);
+#endif
+#if defined(SIZEOF_CHAR)
+ CHECK(char, SIZEOF_CHAR);
+#else
+ NODEF(SIZEOF_CHAR);
+#endif
+
+ /* short */
+#if !defined(HAVE_SIZEOF_SHORT)
+ NODEF(HAVE_SIZEOF_SHORT);
+#endif
+#if defined(SIZEOF_SHORT)
+ CHECK(short, SIZEOF_SHORT);
+#else
+ NODEF(SIZEOF_SHORT);
+#endif
+
+ /* int */
+#if !defined(HAVE_SIZEOF_INT)
+ NODEF(HAVE_SIZEOF_INT);
+#endif
+#if defined(SIZEOF_INT)
+ CHECK(int, SIZEOF_INT);
+#else
+ NODEF(SIZEOF_INT);
+#endif
+
+ /* long */
+#if !defined(HAVE_SIZEOF_LONG)
+ NODEF(HAVE_SIZEOF_LONG);
+#endif
+#if defined(SIZEOF_LONG)
+ CHECK(long, SIZEOF_LONG);
+#else
+ NODEF(SIZEOF_LONG);
+#endif
+
+ /* long long */
+#if defined(SIZEOF_LONG_LONG)
+ CHECK(long long, SIZEOF_LONG_LONG);
+# if !defined(HAVE_SIZEOF_LONG_LONG)
+ NODEF(HAVE_SIZEOF_LONG_LONG);
+# endif
+#endif
+
+ /* __int64 */
+#if defined(SIZEOF___INT64)
+ CHECK(__int64, SIZEOF___INT64);
+# if !defined(HAVE_SIZEOF___INT64)
+ NODEF(HAVE_SIZEOF___INT64);
+# endif
+#elif defined(HAVE_SIZEOF___INT64)
+ NODEF(SIZEOF___INT64);
+#endif
+
+ /* size_t */
+#if !defined(HAVE_SIZEOF_SIZE_T)
+ NODEF(HAVE_SIZEOF_SIZE_T);
+#endif
+#if defined(SIZEOF_SIZE_T)
+ CHECK(size_t, SIZEOF_SIZE_T);
+#else
+ NODEF(SIZEOF_SIZE_T);
+#endif
+
+ /* ssize_t */
+#if defined(SIZEOF_SSIZE_T)
+ CHECK(ssize_t, SIZEOF_SSIZE_T);
+# if !defined(HAVE_SIZEOF_SSIZE_T)
+ NODEF(HAVE_SIZEOF_SSIZE_T);
+# endif
+#elif defined(HAVE_SIZEOF_SSIZE_T)
+ NODEF(SIZEOF_SSIZE_T);
+#endif
+
+ /* struct somestruct::someint */
+#if defined(SIZEOF_STRUCTMEMBER_INT)
+ CHECK(x.someint, SIZEOF_STRUCTMEMBER_INT);
+ CHECK(x.someint, SIZEOF_INT);
+# if !defined(HAVE_SIZEOF_STRUCTMEMBER_INT)
+ NODEF(HAVE_SIZEOF_STRUCTMEMBER_INT);
+# endif
+#elif defined(HAVE_SIZEOF_STRUCTMEMBER_INT)
+ NODEF(SIZEOF_STRUCTMEMBER_INT);
+#endif
+
+ /* struct somestruct::someptr */
+#if defined(SIZEOF_STRUCTMEMBER_PTR)
+ CHECK(x.someptr, SIZEOF_STRUCTMEMBER_PTR);
+ CHECK(x.someptr, SIZEOF_DATA_PTR);
+# if !defined(HAVE_SIZEOF_STRUCTMEMBER_PTR)
+ NODEF(HAVE_SIZEOF_STRUCTMEMBER_PTR);
+# endif
+#elif defined(HAVE_SIZEOF_STRUCTMEMBER_PTR)
+ NODEF(SIZEOF_STRUCTMEMBER_PTR);
+#endif
+
+ /* struct somestruct::someint */
+#if defined(SIZEOF_STRUCTMEMBER_CHAR)
+ CHECK(x.somechar, SIZEOF_STRUCTMEMBER_CHAR);
+ CHECK(x.somechar, SIZEOF_CHAR);
+# if !defined(HAVE_SIZEOF_STRUCTMEMBER_CHAR)
+ NODEF(HAVE_SIZEOF_STRUCTMEMBER_CHAR);
+# endif
+#elif defined(HAVE_SIZEOF_STRUCTMEMBER_CHAR)
+ NODEF(SIZEOF_STRUCTMEMBER_CHAR);
+#endif
+
+ /* to avoid possible warnings about unused or write-only variable */
+ x.someint = result;
+
+ return x.someint;
+}
diff --git a/Tests/Module/CheckTypeSize/CheckTypeSize.cxx b/Tests/Module/CheckTypeSize/CheckTypeSize.cxx
new file mode 100644
index 0000000000..b5692cdbfc
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/CheckTypeSize.cxx
@@ -0,0 +1,172 @@
+#include "config.h"
+#include "config.hxx"
+#include "someclass.hxx"
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_STDDEF_H
+# include <stddef.h>
+#endif
+
+#include <stdio.h>
+
+#define CHECK(t,m) do { \
+ if(sizeof(t) != m) \
+ { \
+ printf(#m ": expected %d, got %d (line %d)\n", \
+ (int)sizeof(t), (int)m, __LINE__); \
+ result = 1; \
+ } \
+ } while(0)
+
+#define NODEF(m) do { \
+ printf(#m": not defined (line %d)\n", __LINE__); \
+ result = 1; \
+ } while(0)
+
+int main()
+{
+ int result = 0;
+ ns::someclass y;
+
+ /* void* */
+#if !defined(HAVE_SIZEOF_DATA_PTR)
+ NODEF(HAVE_SIZEOF_DATA_PTR);
+#endif
+#if defined(SIZEOF_DATA_PTR)
+ CHECK(void*, SIZEOF_DATA_PTR);
+#else
+ NODEF(SIZEOF_DATA_PTR);
+#endif
+
+ /* char */
+#if !defined(HAVE_SIZEOF_CHAR)
+ NODEF(HAVE_SIZEOF_CHAR);
+#endif
+#if defined(SIZEOF_CHAR)
+ CHECK(char, SIZEOF_CHAR);
+#else
+ NODEF(SIZEOF_CHAR);
+#endif
+
+ /* short */
+#if !defined(HAVE_SIZEOF_SHORT)
+ NODEF(HAVE_SIZEOF_SHORT);
+#endif
+#if defined(SIZEOF_SHORT)
+ CHECK(short, SIZEOF_SHORT);
+#else
+ NODEF(SIZEOF_SHORT);
+#endif
+
+ /* int */
+#if !defined(HAVE_SIZEOF_INT)
+ NODEF(HAVE_SIZEOF_INT);
+#endif
+#if defined(SIZEOF_INT)
+ CHECK(int, SIZEOF_INT);
+#else
+ NODEF(SIZEOF_INT);
+#endif
+
+ /* long */
+#if !defined(HAVE_SIZEOF_LONG)
+ NODEF(HAVE_SIZEOF_LONG);
+#endif
+#if defined(SIZEOF_LONG)
+ CHECK(long, SIZEOF_LONG);
+#else
+ NODEF(SIZEOF_LONG);
+#endif
+
+ /* long long */
+#if defined(SIZEOF_LONG_LONG)
+ CHECK(long long, SIZEOF_LONG_LONG);
+# if !defined(HAVE_SIZEOF_LONG_LONG)
+ NODEF(HAVE_SIZEOF_LONG_LONG);
+# endif
+#endif
+
+ /* __int64 */
+#if defined(SIZEOF___INT64)
+ CHECK(__int64, SIZEOF___INT64);
+# if !defined(HAVE_SIZEOF___INT64)
+ NODEF(HAVE_SIZEOF___INT64);
+# endif
+#elif defined(HAVE_SIZEOF___INT64)
+ NODEF(SIZEOF___INT64);
+#endif
+
+ /* size_t */
+#if !defined(HAVE_SIZEOF_SIZE_T)
+ NODEF(HAVE_SIZEOF_SIZE_T);
+#endif
+#if defined(SIZEOF_SIZE_T)
+ CHECK(size_t, SIZEOF_SIZE_T);
+#else
+ NODEF(SIZEOF_SIZE_T);
+#endif
+
+ /* ssize_t */
+#if defined(SIZEOF_SSIZE_T)
+ CHECK(ssize_t, SIZEOF_SSIZE_T);
+# if !defined(HAVE_SIZEOF_SSIZE_T)
+ NODEF(HAVE_SIZEOF_SSIZE_T);
+# endif
+#elif defined(HAVE_SIZEOF_SSIZE_T)
+ NODEF(SIZEOF_SSIZE_T);
+#endif
+
+ /* ns::someclass::someint */
+#if defined(SIZEOF_NS_CLASSMEMBER_INT)
+ CHECK(y.someint, SIZEOF_NS_CLASSMEMBER_INT);
+ CHECK(y.someint, SIZEOF_INT);
+# if !defined(HAVE_SIZEOF_NS_CLASSMEMBER_INT)
+ NODEF(HAVE_SIZEOF_STRUCTMEMBER_INT);
+# endif
+#elif defined(HAVE_SIZEOF_STRUCTMEMBER_INT)
+ NODEF(SIZEOF_STRUCTMEMBER_INT);
+#endif
+
+ /* ns::someclass::someptr */
+#if defined(SIZEOF_NS_CLASSMEMBER_PTR)
+ CHECK(y.someptr, SIZEOF_NS_CLASSMEMBER_PTR);
+ CHECK(y.someptr, SIZEOF_DATA_PTR);
+# if !defined(HAVE_SIZEOF_NS_CLASSMEMBER_PTR)
+ NODEF(HAVE_SIZEOF_NS_CLASSMEMBER_PTR);
+# endif
+#elif defined(HAVE_SIZEOF_NS_CLASSMEMBER_PTR)
+ NODEF(SIZEOF_NS_CLASSMEMBER_PTR);
+#endif
+
+ /* ns::someclass::somechar */
+#if defined(SIZEOF_NS_CLASSMEMBER_CHAR)
+ CHECK(y.somechar, SIZEOF_NS_CLASSMEMBER_CHAR);
+ CHECK(y.somechar, SIZEOF_CHAR);
+# if !defined(HAVE_SIZEOF_NS_CLASSMEMBER_CHAR)
+ NODEF(HAVE_SIZEOF_NS_CLASSMEMBER_CHAR);
+# endif
+#elif defined(HAVE_SIZEOF_NS_CLASSMEMBER_CHAR)
+ NODEF(SIZEOF_NS_CLASSMEMBER_CHAR);
+#endif
+
+ /* ns::someclass::somebool */
+#if defined(SIZEOF_NS_CLASSMEMBER_BOOL)
+ CHECK(y.somechar, SIZEOF_NS_CLASSMEMBER_BOOL);
+ CHECK(y.somechar, SIZEOF_BOOL);
+# if !defined(HAVE_SIZEOF_NS_CLASSMEMBER_BOOL)
+ NODEF(HAVE_SIZEOF_NS_CLASSMEMBER_BOOL);
+# endif
+#elif defined(HAVE_SIZEOF_NS_CLASSMEMBER_BOOL)
+ NODEF(SIZEOF_NS_CLASSMEMBER_BOOL);
+#endif
+
+ /* to avoid possible warnings about unused or write-only variable */
+ y.someint = result;
+
+ return y.someint;
+}
diff --git a/Tests/Module/CheckTypeSize/config.h.in b/Tests/Module/CheckTypeSize/config.h.in
new file mode 100644
index 0000000000..c601075884
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/config.h.in
@@ -0,0 +1,51 @@
+#cmakedefine HAVE_SYS_TYPES_H
+#cmakedefine HAVE_STDINT_H
+#cmakedefine HAVE_STDDEF_H
+
+/* void* */
+#cmakedefine HAVE_SIZEOF_DATA_PTR
+@SIZEOF_DATA_PTR_CODE@
+
+/* char */
+#cmakedefine HAVE_SIZEOF_CHAR
+@SIZEOF_CHAR_CODE@
+
+/* short */
+#cmakedefine HAVE_SIZEOF_SHORT
+@SIZEOF_SHORT_CODE@
+
+/* int */
+#cmakedefine HAVE_SIZEOF_INT
+@SIZEOF_INT_CODE@
+
+/* long */
+#cmakedefine HAVE_SIZEOF_LONG
+@SIZEOF_LONG_CODE@
+
+/* long long */
+#cmakedefine HAVE_SIZEOF_LONG_LONG
+@SIZEOF_LONG_LONG_CODE@
+
+/* __int64 */
+#cmakedefine HAVE_SIZEOF___INT64
+@SIZEOF___INT64_CODE@
+
+/* size_t */
+#cmakedefine HAVE_SIZEOF_SIZE_T
+@SIZEOF_SIZE_T_CODE@
+
+/* ssize_t */
+#cmakedefine HAVE_SIZEOF_SSIZE_T
+@SIZEOF_SSIZE_T_CODE@
+
+/* struct somestruct::someint */
+#cmakedefine HAVE_SIZEOF_STRUCTMEMBER_INT
+@SIZEOF_STRUCTMEMBER_INT_CODE@
+
+/* struct somestruct::someptr */
+#cmakedefine HAVE_SIZEOF_STRUCTMEMBER_PTR
+@SIZEOF_STRUCTMEMBER_PTR_CODE@
+
+/* struct somestruct::somechar */
+#cmakedefine HAVE_SIZEOF_STRUCTMEMBER_CHAR
+@SIZEOF_STRUCTMEMBER_CHAR_CODE@
diff --git a/Tests/Module/CheckTypeSize/config.hxx.in b/Tests/Module/CheckTypeSize/config.hxx.in
new file mode 100644
index 0000000000..8c66ade6c2
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/config.hxx.in
@@ -0,0 +1,23 @@
+#cmakedefine HAVE_SYS_TYPES_H
+#cmakedefine HAVE_STDINT_H
+#cmakedefine HAVE_STDDEF_H
+
+/* bool */
+#cmakedefine HAVE_SIZEOF_BOOL
+@SIZEOF_BOOL_CODE@
+
+/* struct ns::somestruct::someint */
+#cmakedefine HAVE_SIZEOF_NS_STRUCTMEMBER_INT
+@SIZEOF_NS_STRUCTMEMBER_INT_CODE@
+
+/* struct ns::somestruct::someptr */
+#cmakedefine HAVE_SIZEOF_NS_STRUCTMEMBER_PTR
+@SIZEOF_NS_STRUCTMEMBER_PTR_CODE@
+
+/* struct ns::somestruct::somechar */
+#cmakedefine HAVE_SIZEOF_NS_STRUCTMEMBER_CHAR
+@SIZEOF_NS_STRUCTMEMBER_CHAR_CODE@
+
+/* struct ns::somestruct::somebool */
+#cmakedefine HAVE_SIZEOF_NS_STRUCTMEMBER_BOOL
+@SIZEOF_NS_STRUCTMEMBER_BOOL_CODE@
diff --git a/Tests/Module/CheckTypeSize/someclass.hxx b/Tests/Module/CheckTypeSize/someclass.hxx
new file mode 100644
index 0000000000..76c07ecdb0
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/someclass.hxx
@@ -0,0 +1,14 @@
+#ifndef _CMAKE_SOMECLASS_HXX
+#define _CMAKE_SOMECLASS_HXX
+
+namespace ns {
+class someclass {
+public:
+ int someint;
+ void *someptr;
+ char somechar;
+ bool somebool;
+};
+}
+
+#endif
diff --git a/Tests/Module/CheckTypeSize/somestruct.h b/Tests/Module/CheckTypeSize/somestruct.h
new file mode 100644
index 0000000000..e08efc4ca6
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/somestruct.h
@@ -0,0 +1,10 @@
+#ifndef _CMAKE_SOMESTRUCT_H
+#define _CMAKE_SOMESTRUCT_H
+
+struct somestruct {
+ int someint;
+ void *someptr;
+ char somechar;
+};
+
+#endif
diff --git a/Tests/Module/ExternalData/CMakeLists.txt b/Tests/Module/ExternalData/CMakeLists.txt
new file mode 100644
index 0000000000..ebca48e449
--- /dev/null
+++ b/Tests/Module/ExternalData/CMakeLists.txt
@@ -0,0 +1,47 @@
+cmake_minimum_required(VERSION 2.8.10.20130115)
+project(ExternalDataTest NONE)
+
+include(CTest)
+
+include(ExternalData)
+
+if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" MATCHES "^/")
+ set(slash /)
+endif()
+set(ExternalData_URL_TEMPLATES
+ "file://${slash}${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
+ )
+set(ExternalData_BINARY_ROOT "${CMAKE_CURRENT_BINARY_DIR}/ExternalData")
+file(REMOVE_RECURSE ${ExternalData_BINARY_ROOT}) # clean test
+
+if(MAKE_SUPPORTS_SPACES)
+ set(Data1CheckSpaces -D "DataSpace=DATA{Data Space.dat}")
+endif()
+
+ExternalData_Add_Test(Data1
+ NAME Data1Check
+ COMMAND ${CMAKE_COMMAND}
+ -D Data=DATA{Data.dat}
+ ${Data1CheckSpaces}
+ -D DataMissing=DATA{DataMissing.dat}
+ -D DataMissingWithAssociated=DATA{DataMissing.dat,Data.dat}
+ -D SeriesA=DATA{SeriesA.dat,:}
+ -D SeriesB=DATA{SeriesB.dat,:}
+ -D SeriesC=DATA{SeriesC.dat,:}
+ -D SeriesD=DATA{SeriesD.dat,:}
+ -D SeriesAn=DATA{SeriesAn1.dat,:}
+ -D SeriesBn=DATA{SeriesBn_1.dat,:}
+ -D SeriesCn=DATA{SeriesCn.1.dat,:}
+ -D SeriesDn=DATA{SeriesDn-1.dat,:}
+ -D SeriesMixed=DATA{SeriesMixed.1.dat,:}
+ -D Paired=DATA{PairedA.dat,PairedB.dat}
+ -D Meta=DATA{MetaTop.dat,REGEX:Meta[ABC].dat}
+ -D Directory=DATA{Directory/,A.dat,REGEX:[BC].dat}
+ -D "Semicolons=DATA{Data.dat}\\;DATA{Data.dat}"
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/Data1Check.cmake
+ )
+ExternalData_Add_Target(Data1)
+
+add_subdirectory(Data2)
+add_subdirectory(Data3)
+add_subdirectory(Data4)
diff --git a/Tests/Module/ExternalData/Data Space.dat.md5 b/Tests/Module/ExternalData/Data Space.dat.md5
new file mode 100644
index 0000000000..70e39bd5d1
--- /dev/null
+++ b/Tests/Module/ExternalData/Data Space.dat.md5
@@ -0,0 +1 @@
+8c018830e3efa5caf3c7415028335a57
diff --git a/Tests/Module/ExternalData/Data.dat.md5 b/Tests/Module/ExternalData/Data.dat.md5
new file mode 100644
index 0000000000..70e39bd5d1
--- /dev/null
+++ b/Tests/Module/ExternalData/Data.dat.md5
@@ -0,0 +1 @@
+8c018830e3efa5caf3c7415028335a57
diff --git a/Tests/Module/ExternalData/Data1Check.cmake b/Tests/Module/ExternalData/Data1Check.cmake
new file mode 100644
index 0000000000..485b5c6c24
--- /dev/null
+++ b/Tests/Module/ExternalData/Data1Check.cmake
@@ -0,0 +1,90 @@
+file(STRINGS "${Data}" lines LIMIT_INPUT 1024)
+if(NOT "x${lines}" STREQUAL "xInput file already transformed.")
+ message(SEND_ERROR "Input file:\n ${Data}\ndoes not have expected content, but [[${lines}]]")
+endif()
+if(DEFINED DataSpace)
+ file(STRINGS "${DataSpace}" lines LIMIT_INPUT 1024)
+ if(NOT "x${lines}" STREQUAL "xInput file already transformed.")
+ message(SEND_ERROR "Input file:\n ${DataSpace}\ndoes not have expected content, but [[${lines}]]")
+ endif()
+endif()
+if(DataMissing)
+ if(EXISTS "${DataMissing}")
+ message(SEND_ERROR
+ "Input file:\n"
+ " ${DataMissing}\n"
+ "exists but should not."
+ )
+ endif()
+else()
+ message(SEND_ERROR "DataMissing is not set!")
+endif()
+if(DataMissingWithAssociated)
+ if(EXISTS "${DataMissingWithAssociated}")
+ message(SEND_ERROR
+ "Input file:\n"
+ " ${DataMissingWithAssociated}\n"
+ "exists but should not."
+ )
+ endif()
+else()
+ message(SEND_ERROR "DataMissingWithAssociated is not set!")
+endif()
+set(SeriesAn1 "1\\.dat")
+set(SeriesBn1 "_1\\.dat")
+set(SeriesCn1 "\\.1\\.dat")
+set(SeriesDn1 "-1\\.dat")
+set(SeriesAl 1 2 3)
+set(SeriesBl _1 _2 _3)
+set(SeriesCl .1 .2 .3)
+set(SeriesDl -1 -2 -3)
+foreach(s A B C D)
+ foreach(n "" ${Series${s}l})
+ string(REGEX REPLACE "\\.dat$" "${n}.dat" file "${Series${s}}")
+ if(NOT EXISTS "${file}")
+ message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
+ endif()
+ endforeach()
+endforeach()
+foreach(s A B C D)
+ foreach(n ${Series${s}l})
+ string(REGEX REPLACE "${Series${s}n1}$" "${n}.dat" file "${Series${s}n}")
+ if(NOT EXISTS "${file}")
+ message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
+ endif()
+ endforeach()
+endforeach()
+foreach(n .1 .2 .3 .4)
+ string(REGEX REPLACE "\\.1\\.dat$" "${n}.dat" file "${SeriesMixed}")
+ if(NOT EXISTS "${file}")
+ message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
+ endif()
+endforeach()
+foreach(n A B)
+ string(REGEX REPLACE "A\\.dat$" "${n}.dat" file "${Paired}")
+ if(NOT EXISTS "${file}")
+ message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
+ endif()
+endforeach()
+foreach(n Top A B C)
+ string(REGEX REPLACE "Top\\.dat$" "${n}.dat" file "${Meta}")
+ if(NOT EXISTS "${file}")
+ message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
+ endif()
+endforeach()
+foreach(n A B C)
+ set(file "${Directory}/${n}.dat")
+ if(NOT EXISTS "${file}")
+ message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
+ endif()
+endforeach()
+list(LENGTH Semicolons len)
+if("${len}" EQUAL 2)
+ foreach(file ${Semicolons})
+ if(NOT EXISTS "${file}")
+ message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
+ endif()
+ endforeach()
+else()
+ message(SEND_ERROR "Semicolons value:\n ${Semicolons}\nis not a list of length 2.")
+endif()
diff --git a/Tests/Module/ExternalData/Data2.dat.md5 b/Tests/Module/ExternalData/Data2.dat.md5
new file mode 100644
index 0000000000..70e39bd5d1
--- /dev/null
+++ b/Tests/Module/ExternalData/Data2.dat.md5
@@ -0,0 +1 @@
+8c018830e3efa5caf3c7415028335a57
diff --git a/Tests/Module/ExternalData/Data2/CMakeLists.txt b/Tests/Module/ExternalData/Data2/CMakeLists.txt
new file mode 100644
index 0000000000..c5b79ac05a
--- /dev/null
+++ b/Tests/Module/ExternalData/Data2/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(ExternalData_SERIES_PARSE "([0-9]+)(_\\.my\\.dat)$")
+set(ExternalData_SERIES_MATCH "([0-9]+)")
+ExternalData_Add_Test(Data2
+ NAME Data2Check
+ COMMAND ${CMAKE_COMMAND}
+ -D Data2=DATA{../Data2.dat}
+ -D Data2b=DATA{${CMAKE_CURRENT_SOURCE_DIR}/../Data2b.dat}
+ -D SeriesC=DATA{SeriesC_1_.my.dat,:}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/Data2Check.cmake
+ )
+ExternalData_Add_Target(Data2)
diff --git a/Tests/Module/ExternalData/Data2/Data2Check.cmake b/Tests/Module/ExternalData/Data2/Data2Check.cmake
new file mode 100644
index 0000000000..d5b0c7b68c
--- /dev/null
+++ b/Tests/Module/ExternalData/Data2/Data2Check.cmake
@@ -0,0 +1,12 @@
+foreach(d "${Data2}" "${Data2b}")
+ file(STRINGS "${d}" lines LIMIT_INPUT 1024)
+ if(NOT "x${lines}" STREQUAL "xInput file already transformed.")
+ message(SEND_ERROR "Input file:\n ${d}\ndoes not have expected content, but [[${lines}]]")
+ endif()
+endforeach()
+foreach(n 1 2 3)
+ string(REGEX REPLACE "_1_\\.my\\.dat$" "_${n}_.my.dat" SeriesCFile "${SeriesC}")
+ if(NOT EXISTS "${SeriesCFile}")
+ message(SEND_ERROR "Input file:\n ${SeriesCFile}\ndoes not exist!")
+ endif()
+endforeach()
diff --git a/Tests/Module/ExternalData/Data2/SeriesC_1_.my.dat.md5 b/Tests/Module/ExternalData/Data2/SeriesC_1_.my.dat.md5
new file mode 100644
index 0000000000..f22e266a6d
--- /dev/null
+++ b/Tests/Module/ExternalData/Data2/SeriesC_1_.my.dat.md5
@@ -0,0 +1 @@
+31eff09e84fca01415f8cd9d82ec432b
diff --git a/Tests/Module/ExternalData/Data2/SeriesC_2_.my.dat.md5 b/Tests/Module/ExternalData/Data2/SeriesC_2_.my.dat.md5
new file mode 100644
index 0000000000..2b917e793f
--- /dev/null
+++ b/Tests/Module/ExternalData/Data2/SeriesC_2_.my.dat.md5
@@ -0,0 +1 @@
+f7ab5a04aae9cb9a520e70b20b9c8ed7
diff --git a/Tests/Module/ExternalData/Data2/SeriesC_3_.my.dat.md5 b/Tests/Module/ExternalData/Data2/SeriesC_3_.my.dat.md5
new file mode 100644
index 0000000000..b9c9760c43
--- /dev/null
+++ b/Tests/Module/ExternalData/Data2/SeriesC_3_.my.dat.md5
@@ -0,0 +1 @@
+30ba0acdee9096b3b9fc6c69362c6b42
diff --git a/Tests/Module/ExternalData/Data2b.dat.md5 b/Tests/Module/ExternalData/Data2b.dat.md5
new file mode 100644
index 0000000000..70e39bd5d1
--- /dev/null
+++ b/Tests/Module/ExternalData/Data2b.dat.md5
@@ -0,0 +1 @@
+8c018830e3efa5caf3c7415028335a57
diff --git a/Tests/Module/ExternalData/Data3/CMakeLists.txt b/Tests/Module/ExternalData/Data3/CMakeLists.txt
new file mode 100644
index 0000000000..a7c2b6e068
--- /dev/null
+++ b/Tests/Module/ExternalData/Data3/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(Store0 ${CMAKE_BINARY_DIR}/ExternalData/Other)
+set(Store1 ${CMAKE_BINARY_DIR}/ExternalData/Objects)
+set(ExternalData_OBJECT_STORES ${Store0} ${Store1})
+ExternalData_Add_Test(Data3
+ NAME Data3Check
+ COMMAND ${CMAKE_COMMAND}
+ -D Data=DATA{Data.dat}
+ -D Other=DATA{Other.dat}
+ -D Store0=${Store0}
+ -D Store1=${Store1}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/Data3Check.cmake
+ )
+ExternalData_Add_Target(Data3)
+add_dependencies(Data3 Data1 Data2)
diff --git a/Tests/Module/ExternalData/Data3/Data.dat.md5 b/Tests/Module/ExternalData/Data3/Data.dat.md5
new file mode 100644
index 0000000000..70e39bd5d1
--- /dev/null
+++ b/Tests/Module/ExternalData/Data3/Data.dat.md5
@@ -0,0 +1 @@
+8c018830e3efa5caf3c7415028335a57
diff --git a/Tests/Module/ExternalData/Data3/Data3Check.cmake b/Tests/Module/ExternalData/Data3/Data3Check.cmake
new file mode 100644
index 0000000000..de9883948d
--- /dev/null
+++ b/Tests/Module/ExternalData/Data3/Data3Check.cmake
@@ -0,0 +1,25 @@
+if(NOT EXISTS "${Data}")
+ message(SEND_ERROR "Input file:\n ${Data}\ndoes not exist!")
+endif()
+if(NOT EXISTS "${Other}")
+ message(SEND_ERROR "Input file:\n ${Other}\ndoes not exist!")
+endif()
+# Verify that the 'Data' object was found in the second store location left
+# from Data1 target downloads and that the 'Other' object was downloaded to
+# our first store location. Neither object should exist in the other store.
+foreach(should_exist
+ "${Store0}/MD5/aaad162b85f60d1eb57ca71a23e8efd7"
+ "${Store1}/MD5/8c018830e3efa5caf3c7415028335a57"
+ )
+ if(NOT EXISTS ${should_exist})
+ message(SEND_ERROR "Store file:\n ${should_exist}\nshould exist!")
+ endif()
+endforeach()
+foreach(should_not_exist
+ "${Store0}/MD5/8c018830e3efa5caf3c7415028335a57"
+ "${Store1}/MD5/aaad162b85f60d1eb57ca71a23e8efd7"
+ )
+ if(EXISTS ${should_not_exist})
+ message(SEND_ERROR "Store file:\n ${should_not_exist}\nshould not exist!")
+ endif()
+endforeach()
diff --git a/Tests/Module/ExternalData/Data3/Other.dat.md5 b/Tests/Module/ExternalData/Data3/Other.dat.md5
new file mode 100644
index 0000000000..5312faac0a
--- /dev/null
+++ b/Tests/Module/ExternalData/Data3/Other.dat.md5
@@ -0,0 +1 @@
+aaad162b85f60d1eb57ca71a23e8efd7
diff --git a/Tests/Module/ExternalData/Data4/CMakeLists.txt b/Tests/Module/ExternalData/Data4/CMakeLists.txt
new file mode 100644
index 0000000000..ac977fb6d1
--- /dev/null
+++ b/Tests/Module/ExternalData/Data4/CMakeLists.txt
@@ -0,0 +1,15 @@
+set(Store0 ${CMAKE_BINARY_DIR}/ExternalData/Other)
+set(Store1 ${CMAKE_BINARY_DIR}/ExternalData/Objects)
+set(ExternalData_OBJECT_STORES ${Store0} ${Store1})
+unset(ExternalData_URL_TEMPLATES) # All objects already in stores!
+ExternalData_Add_Test(Data4
+ NAME Data4Check
+ COMMAND ${CMAKE_COMMAND}
+ -D Data=DATA{Data.dat}
+ -D Other=DATA{Other.dat}
+ -D Store0=${Store0}
+ -D Store1=${Store1}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/Data4Check.cmake
+ )
+ExternalData_Add_Target(Data4)
+add_dependencies(Data4 Data3)
diff --git a/Tests/Module/ExternalData/Data4/Data.dat.md5 b/Tests/Module/ExternalData/Data4/Data.dat.md5
new file mode 100644
index 0000000000..70e39bd5d1
--- /dev/null
+++ b/Tests/Module/ExternalData/Data4/Data.dat.md5
@@ -0,0 +1 @@
+8c018830e3efa5caf3c7415028335a57
diff --git a/Tests/Module/ExternalData/Data4/Data4Check.cmake b/Tests/Module/ExternalData/Data4/Data4Check.cmake
new file mode 100644
index 0000000000..e614cc4e36
--- /dev/null
+++ b/Tests/Module/ExternalData/Data4/Data4Check.cmake
@@ -0,0 +1,26 @@
+if(NOT EXISTS "${Data}")
+ message(SEND_ERROR "Input file:\n ${Data}\ndoes not exist!")
+endif()
+if(NOT EXISTS "${Other}")
+ message(SEND_ERROR "Input file:\n ${Other}\ndoes not exist!")
+endif()
+# Verify that the 'Data' object was found in the second store location left
+# from Data1 target downloads and that the 'Other' object was found in the
+# first store location left from Data3 target downloads. Neither object
+# should exist in the opposite store.
+foreach(should_exist
+ "${Store0}/MD5/aaad162b85f60d1eb57ca71a23e8efd7"
+ "${Store1}/MD5/8c018830e3efa5caf3c7415028335a57"
+ )
+ if(NOT EXISTS ${should_exist})
+ message(SEND_ERROR "Store file:\n ${should_exist}\nshould exist!")
+ endif()
+endforeach()
+foreach(should_not_exist
+ "${Store0}/MD5/8c018830e3efa5caf3c7415028335a57"
+ "${Store1}/MD5/aaad162b85f60d1eb57ca71a23e8efd7"
+ )
+ if(EXISTS ${should_not_exist})
+ message(SEND_ERROR "Store file:\n ${should_not_exist}\nshould not exist!")
+ endif()
+endforeach()
diff --git a/Tests/Module/ExternalData/Data4/Other.dat.md5 b/Tests/Module/ExternalData/Data4/Other.dat.md5
new file mode 100644
index 0000000000..5312faac0a
--- /dev/null
+++ b/Tests/Module/ExternalData/Data4/Other.dat.md5
@@ -0,0 +1 @@
+aaad162b85f60d1eb57ca71a23e8efd7
diff --git a/Tests/Module/ExternalData/Directory/A.dat.md5 b/Tests/Module/ExternalData/Directory/A.dat.md5
new file mode 100644
index 0000000000..4a78fc7834
--- /dev/null
+++ b/Tests/Module/ExternalData/Directory/A.dat.md5
@@ -0,0 +1 @@
+9d980b06c2f0fec3d4872d68175b9822
diff --git a/Tests/Module/ExternalData/Directory/B.dat.md5 b/Tests/Module/ExternalData/Directory/B.dat.md5
new file mode 100644
index 0000000000..4557a216ad
--- /dev/null
+++ b/Tests/Module/ExternalData/Directory/B.dat.md5
@@ -0,0 +1 @@
+8f4add4581551facf27237e6577fd662
diff --git a/Tests/Module/ExternalData/Directory/C.dat.md5 b/Tests/Module/ExternalData/Directory/C.dat.md5
new file mode 100644
index 0000000000..a7f23dd7fe
--- /dev/null
+++ b/Tests/Module/ExternalData/Directory/C.dat.md5
@@ -0,0 +1 @@
+c1030719c95f3435d8abc39c0d442946
diff --git a/Tests/Module/ExternalData/MD5/.gitattributes b/Tests/Module/ExternalData/MD5/.gitattributes
new file mode 100644
index 0000000000..3e51d39dba
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/.gitattributes
@@ -0,0 +1 @@
+* -crlf
diff --git a/Tests/Module/ExternalData/MD5/08cfcf221f76ace7b906b312284e73d7 b/Tests/Module/ExternalData/MD5/08cfcf221f76ace7b906b312284e73d7
new file mode 100644
index 0000000000..a689e3cc49
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/08cfcf221f76ace7b906b312284e73d7
@@ -0,0 +1 @@
+MetaTop
diff --git a/Tests/Module/ExternalData/MD5/30ba0acdee9096b3b9fc6c69362c6b42 b/Tests/Module/ExternalData/MD5/30ba0acdee9096b3b9fc6c69362c6b42
new file mode 100644
index 0000000000..5491241b0b
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/30ba0acdee9096b3b9fc6c69362c6b42
@@ -0,0 +1 @@
+Series.3
diff --git a/Tests/Module/ExternalData/MD5/31eff09e84fca01415f8cd9d82ec432b b/Tests/Module/ExternalData/MD5/31eff09e84fca01415f8cd9d82ec432b
new file mode 100644
index 0000000000..4d0475e228
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/31eff09e84fca01415f8cd9d82ec432b
@@ -0,0 +1 @@
+Series.1
diff --git a/Tests/Module/ExternalData/MD5/401767f22a456b3522953722090a2c36 b/Tests/Module/ExternalData/MD5/401767f22a456b3522953722090a2c36
new file mode 100644
index 0000000000..9dec116617
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/401767f22a456b3522953722090a2c36
@@ -0,0 +1 @@
+PairedA
diff --git a/Tests/Module/ExternalData/MD5/8c018830e3efa5caf3c7415028335a57 b/Tests/Module/ExternalData/MD5/8c018830e3efa5caf3c7415028335a57
new file mode 100644
index 0000000000..fa701e21bb
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/8c018830e3efa5caf3c7415028335a57
@@ -0,0 +1 @@
+Input file already transformed.
diff --git a/Tests/Module/ExternalData/MD5/8f4add4581551facf27237e6577fd662 b/Tests/Module/ExternalData/MD5/8f4add4581551facf27237e6577fd662
new file mode 100644
index 0000000000..69ba09c86c
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/8f4add4581551facf27237e6577fd662
@@ -0,0 +1 @@
+MetaB
diff --git a/Tests/Module/ExternalData/MD5/9d980b06c2f0fec3d4872d68175b9822 b/Tests/Module/ExternalData/MD5/9d980b06c2f0fec3d4872d68175b9822
new file mode 100644
index 0000000000..000e7b2bf3
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/9d980b06c2f0fec3d4872d68175b9822
@@ -0,0 +1 @@
+MetaA
diff --git a/Tests/Module/ExternalData/MD5/aaad162b85f60d1eb57ca71a23e8efd7 b/Tests/Module/ExternalData/MD5/aaad162b85f60d1eb57ca71a23e8efd7
new file mode 100644
index 0000000000..df0510c3c0
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/aaad162b85f60d1eb57ca71a23e8efd7
@@ -0,0 +1 @@
+Another input file already transformed.
diff --git a/Tests/Module/ExternalData/MD5/c1030719c95f3435d8abc39c0d442946 b/Tests/Module/ExternalData/MD5/c1030719c95f3435d8abc39c0d442946
new file mode 100644
index 0000000000..3fac5e63d3
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/c1030719c95f3435d8abc39c0d442946
@@ -0,0 +1 @@
+MetaC
diff --git a/Tests/Module/ExternalData/MD5/ce38ea6c3c1e00fa6405dd64b8bf6da0 b/Tests/Module/ExternalData/MD5/ce38ea6c3c1e00fa6405dd64b8bf6da0
new file mode 100644
index 0000000000..362d4b4f2b
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/ce38ea6c3c1e00fa6405dd64b8bf6da0
@@ -0,0 +1 @@
+SeriesMixed.1
diff --git a/Tests/Module/ExternalData/MD5/ecfa1ecd417d4253af81ae04d1bd6581 b/Tests/Module/ExternalData/MD5/ecfa1ecd417d4253af81ae04d1bd6581
new file mode 100644
index 0000000000..8c414f53bf
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/ecfa1ecd417d4253af81ae04d1bd6581
@@ -0,0 +1 @@
+PairedB
diff --git a/Tests/Module/ExternalData/MD5/f41c94425d01ecbbee70440b951cb058 b/Tests/Module/ExternalData/MD5/f41c94425d01ecbbee70440b951cb058
new file mode 100644
index 0000000000..3503da4f28
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/f41c94425d01ecbbee70440b951cb058
@@ -0,0 +1 @@
+Series
diff --git a/Tests/Module/ExternalData/MD5/f7ab5a04aae9cb9a520e70b20b9c8ed7 b/Tests/Module/ExternalData/MD5/f7ab5a04aae9cb9a520e70b20b9c8ed7
new file mode 100644
index 0000000000..29d727b8fe
--- /dev/null
+++ b/Tests/Module/ExternalData/MD5/f7ab5a04aae9cb9a520e70b20b9c8ed7
@@ -0,0 +1 @@
+Series.2
diff --git a/Tests/Module/ExternalData/MetaA.dat.md5 b/Tests/Module/ExternalData/MetaA.dat.md5
new file mode 100644
index 0000000000..4a78fc7834
--- /dev/null
+++ b/Tests/Module/ExternalData/MetaA.dat.md5
@@ -0,0 +1 @@
+9d980b06c2f0fec3d4872d68175b9822
diff --git a/Tests/Module/ExternalData/MetaB.dat.md5 b/Tests/Module/ExternalData/MetaB.dat.md5
new file mode 100644
index 0000000000..4557a216ad
--- /dev/null
+++ b/Tests/Module/ExternalData/MetaB.dat.md5
@@ -0,0 +1 @@
+8f4add4581551facf27237e6577fd662
diff --git a/Tests/Module/ExternalData/MetaC.dat.md5 b/Tests/Module/ExternalData/MetaC.dat.md5
new file mode 100644
index 0000000000..a7f23dd7fe
--- /dev/null
+++ b/Tests/Module/ExternalData/MetaC.dat.md5
@@ -0,0 +1 @@
+c1030719c95f3435d8abc39c0d442946
diff --git a/Tests/Module/ExternalData/MetaTop.dat.md5 b/Tests/Module/ExternalData/MetaTop.dat.md5
new file mode 100644
index 0000000000..1906cbf7ff
--- /dev/null
+++ b/Tests/Module/ExternalData/MetaTop.dat.md5
@@ -0,0 +1 @@
+08cfcf221f76ace7b906b312284e73d7
diff --git a/Tests/Module/ExternalData/PairedA.dat.md5 b/Tests/Module/ExternalData/PairedA.dat.md5
new file mode 100644
index 0000000000..1ffe035e03
--- /dev/null
+++ b/Tests/Module/ExternalData/PairedA.dat.md5
@@ -0,0 +1 @@
+401767f22a456b3522953722090a2c36
diff --git a/Tests/Module/ExternalData/PairedB.dat.md5 b/Tests/Module/ExternalData/PairedB.dat.md5
new file mode 100644
index 0000000000..89c942b636
--- /dev/null
+++ b/Tests/Module/ExternalData/PairedB.dat.md5
@@ -0,0 +1 @@
+ecfa1ecd417d4253af81ae04d1bd6581
diff --git a/Tests/Module/ExternalData/SHA1/.gitattributes b/Tests/Module/ExternalData/SHA1/.gitattributes
new file mode 100644
index 0000000000..3e51d39dba
--- /dev/null
+++ b/Tests/Module/ExternalData/SHA1/.gitattributes
@@ -0,0 +1 @@
+* -crlf
diff --git a/Tests/Module/ExternalData/SHA1/2af59a7022024974f3b8521b7ed8137c996a79f1 b/Tests/Module/ExternalData/SHA1/2af59a7022024974f3b8521b7ed8137c996a79f1
new file mode 100644
index 0000000000..a388540608
--- /dev/null
+++ b/Tests/Module/ExternalData/SHA1/2af59a7022024974f3b8521b7ed8137c996a79f1
@@ -0,0 +1 @@
+SeriesMixed.2
diff --git a/Tests/Module/ExternalData/SHA224/.gitattributes b/Tests/Module/ExternalData/SHA224/.gitattributes
new file mode 100644
index 0000000000..3e51d39dba
--- /dev/null
+++ b/Tests/Module/ExternalData/SHA224/.gitattributes
@@ -0,0 +1 @@
+* -crlf
diff --git a/Tests/Module/ExternalData/SHA224/3b679da7908562fe1cc28db47ffb89bae025f4551dceb343a5869174 b/Tests/Module/ExternalData/SHA224/3b679da7908562fe1cc28db47ffb89bae025f4551dceb343a5869174
new file mode 100644
index 0000000000..e806d98532
--- /dev/null
+++ b/Tests/Module/ExternalData/SHA224/3b679da7908562fe1cc28db47ffb89bae025f4551dceb343a5869174
@@ -0,0 +1 @@
+SeriesMixed.3
diff --git a/Tests/Module/ExternalData/SHA256/.gitattributes b/Tests/Module/ExternalData/SHA256/.gitattributes
new file mode 100644
index 0000000000..3e51d39dba
--- /dev/null
+++ b/Tests/Module/ExternalData/SHA256/.gitattributes
@@ -0,0 +1 @@
+* -crlf
diff --git a/Tests/Module/ExternalData/SHA256/969171a0dd70d49ce096bd3e8178c7e26c711c9b20dbcaa3853d869d3871f133 b/Tests/Module/ExternalData/SHA256/969171a0dd70d49ce096bd3e8178c7e26c711c9b20dbcaa3853d869d3871f133
new file mode 100644
index 0000000000..e3d1e0cc74
--- /dev/null
+++ b/Tests/Module/ExternalData/SHA256/969171a0dd70d49ce096bd3e8178c7e26c711c9b20dbcaa3853d869d3871f133
@@ -0,0 +1 @@
+SeriesMixed.4
diff --git a/Tests/Module/ExternalData/SeriesA.dat.md5 b/Tests/Module/ExternalData/SeriesA.dat.md5
new file mode 100644
index 0000000000..be2d6878b0
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesA.dat.md5
@@ -0,0 +1 @@
+f41c94425d01ecbbee70440b951cb058
diff --git a/Tests/Module/ExternalData/SeriesA1.dat.md5 b/Tests/Module/ExternalData/SeriesA1.dat.md5
new file mode 100644
index 0000000000..f22e266a6d
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesA1.dat.md5
@@ -0,0 +1 @@
+31eff09e84fca01415f8cd9d82ec432b
diff --git a/Tests/Module/ExternalData/SeriesA2.dat.md5 b/Tests/Module/ExternalData/SeriesA2.dat.md5
new file mode 100644
index 0000000000..2b917e793f
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesA2.dat.md5
@@ -0,0 +1 @@
+f7ab5a04aae9cb9a520e70b20b9c8ed7
diff --git a/Tests/Module/ExternalData/SeriesA3.dat.md5 b/Tests/Module/ExternalData/SeriesA3.dat.md5
new file mode 100644
index 0000000000..b9c9760c43
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesA3.dat.md5
@@ -0,0 +1 @@
+30ba0acdee9096b3b9fc6c69362c6b42
diff --git a/Tests/Module/ExternalData/SeriesAn1.dat.md5 b/Tests/Module/ExternalData/SeriesAn1.dat.md5
new file mode 100644
index 0000000000..f22e266a6d
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesAn1.dat.md5
@@ -0,0 +1 @@
+31eff09e84fca01415f8cd9d82ec432b
diff --git a/Tests/Module/ExternalData/SeriesAn2.dat.md5 b/Tests/Module/ExternalData/SeriesAn2.dat.md5
new file mode 100644
index 0000000000..2b917e793f
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesAn2.dat.md5
@@ -0,0 +1 @@
+f7ab5a04aae9cb9a520e70b20b9c8ed7
diff --git a/Tests/Module/ExternalData/SeriesAn3.dat.md5 b/Tests/Module/ExternalData/SeriesAn3.dat.md5
new file mode 100644
index 0000000000..b9c9760c43
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesAn3.dat.md5
@@ -0,0 +1 @@
+30ba0acdee9096b3b9fc6c69362c6b42
diff --git a/Tests/Module/ExternalData/SeriesB.dat.md5 b/Tests/Module/ExternalData/SeriesB.dat.md5
new file mode 100644
index 0000000000..be2d6878b0
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesB.dat.md5
@@ -0,0 +1 @@
+f41c94425d01ecbbee70440b951cb058
diff --git a/Tests/Module/ExternalData/SeriesB_1.dat.md5 b/Tests/Module/ExternalData/SeriesB_1.dat.md5
new file mode 100644
index 0000000000..f22e266a6d
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesB_1.dat.md5
@@ -0,0 +1 @@
+31eff09e84fca01415f8cd9d82ec432b
diff --git a/Tests/Module/ExternalData/SeriesB_2.dat.md5 b/Tests/Module/ExternalData/SeriesB_2.dat.md5
new file mode 100644
index 0000000000..2b917e793f
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesB_2.dat.md5
@@ -0,0 +1 @@
+f7ab5a04aae9cb9a520e70b20b9c8ed7
diff --git a/Tests/Module/ExternalData/SeriesB_3.dat.md5 b/Tests/Module/ExternalData/SeriesB_3.dat.md5
new file mode 100644
index 0000000000..b9c9760c43
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesB_3.dat.md5
@@ -0,0 +1 @@
+30ba0acdee9096b3b9fc6c69362c6b42
diff --git a/Tests/Module/ExternalData/SeriesBn_1.dat.md5 b/Tests/Module/ExternalData/SeriesBn_1.dat.md5
new file mode 100644
index 0000000000..f22e266a6d
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesBn_1.dat.md5
@@ -0,0 +1 @@
+31eff09e84fca01415f8cd9d82ec432b
diff --git a/Tests/Module/ExternalData/SeriesBn_2.dat.md5 b/Tests/Module/ExternalData/SeriesBn_2.dat.md5
new file mode 100644
index 0000000000..2b917e793f
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesBn_2.dat.md5
@@ -0,0 +1 @@
+f7ab5a04aae9cb9a520e70b20b9c8ed7
diff --git a/Tests/Module/ExternalData/SeriesBn_3.dat.md5 b/Tests/Module/ExternalData/SeriesBn_3.dat.md5
new file mode 100644
index 0000000000..b9c9760c43
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesBn_3.dat.md5
@@ -0,0 +1 @@
+30ba0acdee9096b3b9fc6c69362c6b42
diff --git a/Tests/Module/ExternalData/SeriesC.1.dat.md5 b/Tests/Module/ExternalData/SeriesC.1.dat.md5
new file mode 100644
index 0000000000..f22e266a6d
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesC.1.dat.md5
@@ -0,0 +1 @@
+31eff09e84fca01415f8cd9d82ec432b
diff --git a/Tests/Module/ExternalData/SeriesC.2.dat.md5 b/Tests/Module/ExternalData/SeriesC.2.dat.md5
new file mode 100644
index 0000000000..2b917e793f
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesC.2.dat.md5
@@ -0,0 +1 @@
+f7ab5a04aae9cb9a520e70b20b9c8ed7
diff --git a/Tests/Module/ExternalData/SeriesC.3.dat.md5 b/Tests/Module/ExternalData/SeriesC.3.dat.md5
new file mode 100644
index 0000000000..b9c9760c43
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesC.3.dat.md5
@@ -0,0 +1 @@
+30ba0acdee9096b3b9fc6c69362c6b42
diff --git a/Tests/Module/ExternalData/SeriesC.dat.md5 b/Tests/Module/ExternalData/SeriesC.dat.md5
new file mode 100644
index 0000000000..be2d6878b0
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesC.dat.md5
@@ -0,0 +1 @@
+f41c94425d01ecbbee70440b951cb058
diff --git a/Tests/Module/ExternalData/SeriesCn.1.dat.md5 b/Tests/Module/ExternalData/SeriesCn.1.dat.md5
new file mode 100644
index 0000000000..f22e266a6d
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesCn.1.dat.md5
@@ -0,0 +1 @@
+31eff09e84fca01415f8cd9d82ec432b
diff --git a/Tests/Module/ExternalData/SeriesCn.2.dat.md5 b/Tests/Module/ExternalData/SeriesCn.2.dat.md5
new file mode 100644
index 0000000000..2b917e793f
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesCn.2.dat.md5
@@ -0,0 +1 @@
+f7ab5a04aae9cb9a520e70b20b9c8ed7
diff --git a/Tests/Module/ExternalData/SeriesCn.3.dat.md5 b/Tests/Module/ExternalData/SeriesCn.3.dat.md5
new file mode 100644
index 0000000000..b9c9760c43
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesCn.3.dat.md5
@@ -0,0 +1 @@
+30ba0acdee9096b3b9fc6c69362c6b42
diff --git a/Tests/Module/ExternalData/SeriesD-1.dat.md5 b/Tests/Module/ExternalData/SeriesD-1.dat.md5
new file mode 100644
index 0000000000..f22e266a6d
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesD-1.dat.md5
@@ -0,0 +1 @@
+31eff09e84fca01415f8cd9d82ec432b
diff --git a/Tests/Module/ExternalData/SeriesD-2.dat.md5 b/Tests/Module/ExternalData/SeriesD-2.dat.md5
new file mode 100644
index 0000000000..2b917e793f
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesD-2.dat.md5
@@ -0,0 +1 @@
+f7ab5a04aae9cb9a520e70b20b9c8ed7
diff --git a/Tests/Module/ExternalData/SeriesD-3.dat.md5 b/Tests/Module/ExternalData/SeriesD-3.dat.md5
new file mode 100644
index 0000000000..b9c9760c43
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesD-3.dat.md5
@@ -0,0 +1 @@
+30ba0acdee9096b3b9fc6c69362c6b42
diff --git a/Tests/Module/ExternalData/SeriesD.dat.md5 b/Tests/Module/ExternalData/SeriesD.dat.md5
new file mode 100644
index 0000000000..be2d6878b0
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesD.dat.md5
@@ -0,0 +1 @@
+f41c94425d01ecbbee70440b951cb058
diff --git a/Tests/Module/ExternalData/SeriesDn-1.dat.md5 b/Tests/Module/ExternalData/SeriesDn-1.dat.md5
new file mode 100644
index 0000000000..f22e266a6d
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesDn-1.dat.md5
@@ -0,0 +1 @@
+31eff09e84fca01415f8cd9d82ec432b
diff --git a/Tests/Module/ExternalData/SeriesDn-2.dat.md5 b/Tests/Module/ExternalData/SeriesDn-2.dat.md5
new file mode 100644
index 0000000000..2b917e793f
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesDn-2.dat.md5
@@ -0,0 +1 @@
+f7ab5a04aae9cb9a520e70b20b9c8ed7
diff --git a/Tests/Module/ExternalData/SeriesDn-3.dat.md5 b/Tests/Module/ExternalData/SeriesDn-3.dat.md5
new file mode 100644
index 0000000000..b9c9760c43
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesDn-3.dat.md5
@@ -0,0 +1 @@
+30ba0acdee9096b3b9fc6c69362c6b42
diff --git a/Tests/Module/ExternalData/SeriesMixed.1.dat.md5 b/Tests/Module/ExternalData/SeriesMixed.1.dat.md5
new file mode 100644
index 0000000000..f962d8f79e
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesMixed.1.dat.md5
@@ -0,0 +1 @@
+ce38ea6c3c1e00fa6405dd64b8bf6da0
diff --git a/Tests/Module/ExternalData/SeriesMixed.2.dat.sha1 b/Tests/Module/ExternalData/SeriesMixed.2.dat.sha1
new file mode 100644
index 0000000000..43a354086a
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesMixed.2.dat.sha1
@@ -0,0 +1 @@
+2af59a7022024974f3b8521b7ed8137c996a79f1
diff --git a/Tests/Module/ExternalData/SeriesMixed.3.dat.sha224 b/Tests/Module/ExternalData/SeriesMixed.3.dat.sha224
new file mode 100644
index 0000000000..a18e40e4c6
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesMixed.3.dat.sha224
@@ -0,0 +1 @@
+3b679da7908562fe1cc28db47ffb89bae025f4551dceb343a5869174
diff --git a/Tests/Module/ExternalData/SeriesMixed.4.dat.sha256 b/Tests/Module/ExternalData/SeriesMixed.4.dat.sha256
new file mode 100644
index 0000000000..67fc3c2f1b
--- /dev/null
+++ b/Tests/Module/ExternalData/SeriesMixed.4.dat.sha256
@@ -0,0 +1 @@
+969171a0dd70d49ce096bd3e8178c7e26c711c9b20dbcaa3853d869d3871f133
diff --git a/Tests/Module/FindDependency/CMakeLists.txt b/Tests/Module/FindDependency/CMakeLists.txt
new file mode 100644
index 0000000000..dcb998a4b3
--- /dev/null
+++ b/Tests/Module/FindDependency/CMakeLists.txt
@@ -0,0 +1,11 @@
+
+cmake_minimum_required(VERSION 3.0)
+project(FindDependency)
+
+set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/packages")
+
+find_package(Pack1 REQUIRED)
+find_package(Pack4 4.3 EXACT REQUIRED)
+
+add_executable(FindDependency main.cpp)
+target_link_libraries(FindDependency Pack1::Lib Pack4::Lib)
diff --git a/Tests/Module/FindDependency/main.cpp b/Tests/Module/FindDependency/main.cpp
new file mode 100644
index 0000000000..50c5958cae
--- /dev/null
+++ b/Tests/Module/FindDependency/main.cpp
@@ -0,0 +1,29 @@
+
+#ifndef HAVE_PACK1
+#error Expected HAVE_PACK1
+#endif
+
+#ifndef HAVE_PACK2
+#error Expected HAVE_PACK2
+#endif
+
+#ifndef HAVE_PACK3
+#error Expected HAVE_PACK3
+#endif
+
+#ifndef HAVE_PACK4
+#error Expected HAVE_PACK4
+#endif
+
+#ifndef HAVE_PACK5
+#error Expected HAVE_PACK5
+#endif
+
+#ifndef HAVE_PACK6
+#error Expected HAVE_PACK6
+#endif
+
+int main(int argc, char** argv)
+{
+ return 0;
+}
diff --git a/Tests/Module/FindDependency/packages/Pack1/Pack1Config.cmake b/Tests/Module/FindDependency/packages/Pack1/Pack1Config.cmake
new file mode 100644
index 0000000000..ff533c2a00
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack1/Pack1Config.cmake
@@ -0,0 +1,9 @@
+
+include(CMakeFindDependencyMacro)
+
+find_dependency(Pack2 2.3)
+find_dependency(Pack3)
+
+add_library(Pack1::Lib INTERFACE IMPORTED)
+set_property(TARGET Pack1::Lib PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_PACK1)
+set_property(TARGET Pack1::Lib PROPERTY INTERFACE_LINK_LIBRARIES Pack2::Lib Pack3::Lib)
diff --git a/Tests/Module/FindDependency/packages/Pack1/Pack1ConfigVersion.cmake b/Tests/Module/FindDependency/packages/Pack1/Pack1ConfigVersion.cmake
new file mode 100644
index 0000000000..dfb7b6c847
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack1/Pack1ConfigVersion.cmake
@@ -0,0 +1,11 @@
+
+set(PACKAGE_VERSION "1.3")
+
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
diff --git a/Tests/Module/FindDependency/packages/Pack2/Pack2Config.cmake b/Tests/Module/FindDependency/packages/Pack2/Pack2Config.cmake
new file mode 100644
index 0000000000..672288ec8c
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack2/Pack2Config.cmake
@@ -0,0 +1,5 @@
+
+set(PACK2_VAR ON)
+
+add_library(Pack2::Lib INTERFACE IMPORTED)
+set_property(TARGET Pack2::Lib PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_PACK2)
diff --git a/Tests/Module/FindDependency/packages/Pack2/Pack2ConfigVersion.cmake b/Tests/Module/FindDependency/packages/Pack2/Pack2ConfigVersion.cmake
new file mode 100644
index 0000000000..42f58c05b2
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack2/Pack2ConfigVersion.cmake
@@ -0,0 +1,11 @@
+
+set(PACKAGE_VERSION "2.4")
+
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
diff --git a/Tests/Module/FindDependency/packages/Pack3/Pack3Config.cmake b/Tests/Module/FindDependency/packages/Pack3/Pack3Config.cmake
new file mode 100644
index 0000000000..25c32f3264
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack3/Pack3Config.cmake
@@ -0,0 +1,5 @@
+
+set(PACK3_VAR ON)
+
+add_library(Pack3::Lib INTERFACE IMPORTED)
+set_property(TARGET Pack3::Lib PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_PACK3)
diff --git a/Tests/Module/FindDependency/packages/Pack3/Pack3ConfigVersion.cmake b/Tests/Module/FindDependency/packages/Pack3/Pack3ConfigVersion.cmake
new file mode 100644
index 0000000000..870f7478dd
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack3/Pack3ConfigVersion.cmake
@@ -0,0 +1,11 @@
+
+set(PACKAGE_VERSION "1.4")
+
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
diff --git a/Tests/Module/FindDependency/packages/Pack4/Pack4Config.cmake b/Tests/Module/FindDependency/packages/Pack4/Pack4Config.cmake
new file mode 100644
index 0000000000..62fddb1c58
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack4/Pack4Config.cmake
@@ -0,0 +1,9 @@
+
+include(CMakeFindDependencyMacro)
+
+find_dependency(Pack5 3.1) # Actual version is 3.3. EXACT not propagated.
+find_dependency(Pack6 5.5 EXACT)
+
+add_library(Pack4::Lib INTERFACE IMPORTED)
+set_property(TARGET Pack4::Lib PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_PACK4)
+set_property(TARGET Pack4::Lib PROPERTY INTERFACE_LINK_LIBRARIES Pack5::Lib Pack6::Lib)
diff --git a/Tests/Module/FindDependency/packages/Pack4/Pack4ConfigVersion.cmake b/Tests/Module/FindDependency/packages/Pack4/Pack4ConfigVersion.cmake
new file mode 100644
index 0000000000..ae982b0fff
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack4/Pack4ConfigVersion.cmake
@@ -0,0 +1,11 @@
+
+set(PACKAGE_VERSION "4.3")
+
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
diff --git a/Tests/Module/FindDependency/packages/Pack5/Pack5Config.cmake b/Tests/Module/FindDependency/packages/Pack5/Pack5Config.cmake
new file mode 100644
index 0000000000..1edda9aa8e
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack5/Pack5Config.cmake
@@ -0,0 +1,3 @@
+
+add_library(Pack5::Lib INTERFACE IMPORTED)
+set_property(TARGET Pack5::Lib PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_PACK5)
diff --git a/Tests/Module/FindDependency/packages/Pack5/Pack5ConfigVersion.cmake b/Tests/Module/FindDependency/packages/Pack5/Pack5ConfigVersion.cmake
new file mode 100644
index 0000000000..e944f9668a
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack5/Pack5ConfigVersion.cmake
@@ -0,0 +1,11 @@
+
+set(PACKAGE_VERSION "3.3")
+
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
diff --git a/Tests/Module/FindDependency/packages/Pack6/Pack6Config.cmake b/Tests/Module/FindDependency/packages/Pack6/Pack6Config.cmake
new file mode 100644
index 0000000000..d6c85fb378
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack6/Pack6Config.cmake
@@ -0,0 +1,3 @@
+
+add_library(Pack6::Lib INTERFACE IMPORTED)
+set_property(TARGET Pack6::Lib PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_PACK6)
diff --git a/Tests/Module/FindDependency/packages/Pack6/Pack6ConfigVersion.cmake b/Tests/Module/FindDependency/packages/Pack6/Pack6ConfigVersion.cmake
new file mode 100644
index 0000000000..0dd00d22e9
--- /dev/null
+++ b/Tests/Module/FindDependency/packages/Pack6/Pack6ConfigVersion.cmake
@@ -0,0 +1,11 @@
+
+set(PACKAGE_VERSION "5.5")
+
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
diff --git a/Tests/Module/GenerateExportHeader/CMakeLists.txt b/Tests/Module/GenerateExportHeader/CMakeLists.txt
new file mode 100644
index 0000000000..b52c44d733
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/CMakeLists.txt
@@ -0,0 +1,129 @@
+cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
+
+project(GenerateExportHeader)
+
+# Prevent timeout on Watcom by not running the tests.
+if ("${CMAKE_CXX_COMPILER_ID}" MATCHES Watcom)
+ file(WRITE
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
+ "int main() { return 0; }
+ "
+ )
+
+ add_executable(
+ GenerateExportHeader
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
+ )
+ return()
+endif()
+
+include(CheckCXXCompilerFlag)
+
+set( CMAKE_INCLUDE_CURRENT_DIR ON )
+
+macro(TEST_FAIL value msg)
+ if (${value})
+ message (SEND_ERROR "Test fail:" "${msg}\n" ${Out} )
+ endif ()
+endmacro()
+
+macro(TEST_PASS value msg)
+ if (NOT ${value})
+ message (SEND_ERROR "Test fail:" "${msg}\n" ${Out} )
+ endif ()
+endmacro()
+
+check_cxx_compiler_flag(-Werror HAS_WERROR_FLAG)
+
+if(HAS_WERROR_FLAG)
+ set(ERROR_FLAG "-Werror")
+else()
+ # MSVC
+ # And intel on windows?
+ # http://software.intel.com/en-us/articles/how-to-handle-warnings-message-in-compiler/?wapkw=%28compiler+warning+message%29
+ check_cxx_compiler_flag("/WX" HAS_WX_FLAG)
+ if(HAS_WX_FLAG)
+ set(ERROR_FLAG "/WX")
+ else()
+ # Sun CC
+ # http://www.acsu.buffalo.edu/~charngda/sunstudio.html
+ check_cxx_compiler_flag("-errwarn=%all" HAS_ERRWARN_ALL)
+ if (HAS_ERRWARN_ALL)
+ set(ERROR_FLAG "-errwarn=%all")
+ else()
+ endif()
+ endif()
+endif()
+
+include(GenerateExportHeader)
+
+set(CMAKE_CXX_STANDARD 98)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+ CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
+
+add_subdirectory(lib_shared_and_static)
+
+add_compiler_export_flags()
+
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+
+message("#### COMPILER_HAS_DEPRECATED: " ${COMPILER_HAS_DEPRECATED})
+message("#### COMPILER_HAS_HIDDEN_VISIBILITY: " ${COMPILER_HAS_HIDDEN_VISIBILITY})
+message("#### WIN32: " ${WIN32})
+message("#### HAS_WERROR_FLAG: " ${HAS_WERROR_FLAG})
+
+set(link_libraries)
+macro(macro_add_test_library name)
+ add_subdirectory(${name})
+ include_directories(${name}
+ ${${name}_BINARY_DIR} # For the export header.
+ )
+ list(APPEND link_libraries ${name})
+endmacro()
+
+macro_add_test_library(libshared)
+macro_add_test_library(libstatic)
+
+add_subdirectory(nodeprecated)
+if(NOT BORLAND)
+ add_subdirectory(c_identifier)
+endif()
+
+if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES Clang))
+ # No need to clutter the test output with warnings.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
+endif()
+
+if(MSVC AND COMPILER_HAS_DEPRECATED)
+ add_definitions(/wd4996)
+endif()
+
+add_executable(GenerateExportHeader exportheader_test.cpp)
+
+target_link_libraries(GenerateExportHeader ${link_libraries})
+if (WIN32)
+ if(MSVC AND COMPILER_HAS_DEPRECATED)
+ set(_platform Win32)
+ elseif(MINGW AND COMPILER_HAS_DEPRECATED)
+ set(_platform MinGW)
+ else()
+ set(_platform WinEmpty)
+ endif()
+elseif(COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
+ set(_platform UNIX)
+elseif(COMPILER_HAS_DEPRECATED)
+ set(_platform UNIX_DeprecatedOnly)
+else()
+ set(_platform Empty)
+endif()
+message("#### Testing reference: ${_platform}")
+target_compile_definitions(GenerateExportHeader
+ PRIVATE
+ "SRC_DIR=${CMAKE_CURRENT_SOURCE_DIR}/reference/${_platform}"
+ "BIN_DIR=${CMAKE_CURRENT_BINARY_DIR}"
+)
diff --git a/Tests/Module/GenerateExportHeader/c_identifier/CMakeLists.txt b/Tests/Module/GenerateExportHeader/c_identifier/CMakeLists.txt
new file mode 100644
index 0000000000..9f8c8efe6a
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/c_identifier/CMakeLists.txt
@@ -0,0 +1,13 @@
+project(c_identifier)
+
+set(c_identifier_lib_SRCS
+ c_identifier_class.cpp
+)
+
+add_library(7c-identifier-lib++ SHARED c_identifier_class.cpp)
+
+generate_export_header(7c-identifier-lib++)
+
+add_executable(c_identifier_exe main.cpp)
+
+target_link_libraries(c_identifier_exe 7c-identifier-lib++)
diff --git a/Tests/Module/GenerateExportHeader/c_identifier/c_identifier_class.cpp b/Tests/Module/GenerateExportHeader/c_identifier/c_identifier_class.cpp
new file mode 100644
index 0000000000..d252c8e8f1
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/c_identifier/c_identifier_class.cpp
@@ -0,0 +1,7 @@
+
+#include "c_identifier_class.h"
+
+int CIdentifierClass::someMethod() const
+{
+ return 0;
+}
diff --git a/Tests/Module/GenerateExportHeader/c_identifier/c_identifier_class.h b/Tests/Module/GenerateExportHeader/c_identifier/c_identifier_class.h
new file mode 100644
index 0000000000..741efdcec0
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/c_identifier/c_identifier_class.h
@@ -0,0 +1,13 @@
+
+#ifndef C_IDENTIFIER_CLASS_H
+#define C_IDENTIFIER_CLASS_H
+
+#include "7c-identifier-lib++_export.h"
+
+class _7C_IDENTIFIER_LIB___EXPORT CIdentifierClass
+{
+public:
+ int someMethod() const;
+};
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/c_identifier/main.cpp b/Tests/Module/GenerateExportHeader/c_identifier/main.cpp
new file mode 100644
index 0000000000..68beebb8fa
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/c_identifier/main.cpp
@@ -0,0 +1,8 @@
+
+#include "c_identifier_class.h"
+
+int main(int argc, char **argv)
+{
+ CIdentifierClass cic;
+ return cic.someMethod();
+}
diff --git a/Tests/Module/GenerateExportHeader/exportheader_test.cpp b/Tests/Module/GenerateExportHeader/exportheader_test.cpp
new file mode 100644
index 0000000000..146374ad33
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/exportheader_test.cpp
@@ -0,0 +1,136 @@
+
+#include "libshared.h"
+
+#include "libstatic.h"
+
+// #define BUILD_FAIL
+
+#ifndef BUILD_FAIL
+#define DOES_NOT_BUILD(function)
+#else
+#define DOES_NOT_BUILD(function) function
+#endif
+
+#include <fstream>
+#include <iostream>
+#include <stdlib.h>
+#include <string>
+
+void compare(const char* refName, const char* testName)
+{
+ std::ifstream ref;
+ ref.open(refName);
+ if (!ref.is_open())
+ {
+ std::cout << "Could not open \"" << refName << "\"." << std::endl;
+ exit(1);
+ }
+ std::ifstream test;
+ test.open(testName);
+ if (!test.is_open())
+ {
+ std::cout << "Could not open \"" << testName << "\"." << std::endl;
+ exit(1);
+ }
+
+ while (!ref.eof() && !test.eof())
+ {
+ std::string refLine;
+ std::string testLine;
+ std::getline(ref, refLine);
+ std::getline(test, testLine);
+ if (testLine.size() && testLine[testLine.size()-1] == ' ')
+ {
+ testLine = testLine.substr(0, testLine.size() - 1);
+ }
+ if (refLine != testLine)
+ {
+ std::cout << "Ref and test are not the same:\n Ref: \""
+ << refLine << "\"\n Test: \"" << testLine << "\"\n";
+ exit(1);
+ }
+ }
+ if (!ref.eof() || !test.eof())
+ {
+ std::cout << "Ref and test have differing numbers of lines.";
+ exit(1);
+ }
+}
+
+int main()
+{
+ {
+ Libshared l;
+ l.libshared();
+ l.libshared_exported();
+ l.libshared_deprecated();
+ l.libshared_not_exported();
+
+ DOES_NOT_BUILD(l.libshared_excluded();)
+ }
+
+ {
+ LibsharedNotExported l;
+ DOES_NOT_BUILD(l.libshared();)
+ l.libshared_exported();
+ l.libshared_deprecated();
+ DOES_NOT_BUILD(l.libshared_not_exported();)
+ DOES_NOT_BUILD(l.libshared_excluded();)
+ }
+
+ {
+ LibsharedExcluded l;
+ DOES_NOT_BUILD(l.libshared();)
+ l.libshared_exported();
+ l.libshared_deprecated();
+ DOES_NOT_BUILD(l.libshared_not_exported();)
+ DOES_NOT_BUILD(l.libshared_excluded();)
+ }
+
+ libshared_exported();
+ libshared_deprecated();
+ DOES_NOT_BUILD(libshared_not_exported();)
+ DOES_NOT_BUILD(libshared_excluded();)
+
+ {
+ Libstatic l;
+ l.libstatic();
+ l.libstatic_exported();
+ l.libstatic_deprecated();
+ l.libstatic_not_exported();
+ l.libstatic_excluded();
+ }
+
+ {
+ LibstaticNotExported l;
+ l.libstatic();
+ l.libstatic_exported();
+ l.libstatic_deprecated();
+ l.libstatic_not_exported();
+ l.libstatic_excluded();
+ }
+
+ {
+ LibstaticExcluded l;
+ l.libstatic();
+ l.libstatic_exported();
+ l.libstatic_deprecated();
+ l.libstatic_not_exported();
+ l.libstatic_excluded();
+ }
+
+ libstatic_exported();
+ libstatic_deprecated();
+ libstatic_not_exported();
+ libstatic_excluded();
+
+#define STRINGIFY_IMPL(A) #A
+#define STRINGIFY(A) STRINGIFY_IMPL(A)
+
+ compare(STRINGIFY(SRC_DIR) "/libshared_export.h",
+ STRINGIFY(BIN_DIR) "/libshared/libshared_export.h");
+ compare(STRINGIFY(SRC_DIR) "/libstatic_export.h",
+ STRINGIFY(BIN_DIR) "/libstatic/libstatic_export.h");
+
+ return 0;
+}
diff --git a/Tests/Module/GenerateExportHeader/lib_shared_and_static/CMakeLists.txt b/Tests/Module/GenerateExportHeader/lib_shared_and_static/CMakeLists.txt
new file mode 100644
index 0000000000..c1be12556f
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/lib_shared_and_static/CMakeLists.txt
@@ -0,0 +1,35 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(lib_shared_and_static)
+
+include(GenerateExportHeader)
+
+set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
+
+if (CMAKE_CXX_FLAGS MATCHES "-fvisibility=hidden")
+ message(SEND_ERROR "Do not use add_compiler_export_flags before adding this directory")
+endif()
+if (CMAKE_CXX_FLAGS MATCHES "-fvisibility-inlines-hidden")
+ message(SEND_ERROR "Do not use add_compiler_export_flags before adding this directory")
+endif()
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(lib_SRCS
+ libshared_and_static.cpp
+)
+
+add_library(shared_variant SHARED ${lib_SRCS})
+set_target_properties(shared_variant PROPERTIES DEFINE_SYMBOL SHARED_VARIANT_MAKEDLL)
+add_library(static_variant ${lib_SRCS})
+
+generate_export_header(shared_variant
+ BASE_NAME libshared_and_static
+ PREFIX_NAME MYPREFIX_
+)
+
+set_target_properties(static_variant PROPERTIES COMPILE_FLAGS -DLIBSHARED_AND_STATIC_STATIC_DEFINE)
+
+export(TARGETS shared_variant static_variant FILE Targets.cmake)
diff --git a/Tests/Module/GenerateExportHeader/lib_shared_and_static/libshared_and_static.cpp b/Tests/Module/GenerateExportHeader/lib_shared_and_static/libshared_and_static.cpp
new file mode 100644
index 0000000000..1e07273627
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/lib_shared_and_static/libshared_and_static.cpp
@@ -0,0 +1,91 @@
+
+#include "libshared_and_static.h"
+
+int LibsharedAndStatic::libshared_and_static() const
+{
+ return 0;
+}
+
+int LibsharedAndStatic::libshared_and_static_exported() const
+{
+ return 0;
+}
+
+int LibsharedAndStatic::libshared_and_static_deprecated() const
+{
+ return 0;
+}
+
+int LibsharedAndStatic::libshared_and_static_not_exported() const {
+ return 0;
+}
+
+int LibsharedAndStatic::libshared_and_static_excluded() const {
+ return 0;
+}
+
+int LibsharedAndStaticNotExported::libshared_and_static() const
+{
+ return 0;
+}
+
+int LibsharedAndStaticNotExported::libshared_and_static_exported() const
+{
+ return 0;
+}
+
+int LibsharedAndStaticNotExported::libshared_and_static_deprecated() const
+{
+ return 0;
+}
+
+int LibsharedAndStaticNotExported::libshared_and_static_not_exported() const {
+ return 0;
+}
+
+int LibsharedAndStaticNotExported::libshared_and_static_excluded() const {
+ return 0;
+}
+
+int LibsharedAndStaticExcluded::libshared_and_static() const
+{
+ return 0;
+}
+
+int LibsharedAndStaticExcluded::libshared_and_static_exported() const
+{
+ return 0;
+}
+
+int LibsharedAndStaticExcluded::libshared_and_static_deprecated() const
+{
+ return 0;
+}
+
+int LibsharedAndStaticExcluded::libshared_and_static_not_exported() const {
+ return 0;
+}
+
+int LibsharedAndStaticExcluded::libshared_and_static_excluded() const {
+ return 0;
+}
+
+int libshared_and_static() {
+ return 0;
+}
+
+int libshared_and_static_exported() {
+ return 0;
+}
+
+int libshared_and_static_deprecated() {
+ return 0;
+}
+
+int libshared_and_static_not_exported() {
+ return 0;
+}
+
+int libshared_and_static_excluded() {
+ return 0;
+}
diff --git a/Tests/Module/GenerateExportHeader/lib_shared_and_static/libshared_and_static.h b/Tests/Module/GenerateExportHeader/lib_shared_and_static/libshared_and_static.h
new file mode 100644
index 0000000000..5ad77f4a96
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/lib_shared_and_static/libshared_and_static.h
@@ -0,0 +1,54 @@
+
+#ifndef SHARED_AND_STATIC_H
+#define SHARED_AND_STATIC_H
+
+#include "libshared_and_static_export.h"
+
+class MYPREFIX_LIBSHARED_AND_STATIC_EXPORT LibsharedAndStatic {
+public:
+ int libshared_and_static() const;
+
+ int libshared_and_static_exported() const;
+
+ int MYPREFIX_LIBSHARED_AND_STATIC_DEPRECATED libshared_and_static_deprecated() const;
+
+ int libshared_and_static_not_exported() const;
+
+ int MYPREFIX_LIBSHARED_AND_STATIC_NO_EXPORT libshared_and_static_excluded() const;
+};
+
+class LibsharedAndStaticNotExported {
+public:
+ int libshared_and_static() const;
+
+ int MYPREFIX_LIBSHARED_AND_STATIC_EXPORT libshared_and_static_exported() const;
+
+ int MYPREFIX_LIBSHARED_AND_STATIC_DEPRECATED libshared_and_static_deprecated() const;
+
+ int libshared_and_static_not_exported() const;
+
+ int MYPREFIX_LIBSHARED_AND_STATIC_NO_EXPORT libshared_and_static_excluded() const;
+};
+
+class MYPREFIX_LIBSHARED_AND_STATIC_NO_EXPORT LibsharedAndStaticExcluded {
+public:
+ int libshared_and_static() const;
+
+ int MYPREFIX_LIBSHARED_AND_STATIC_EXPORT libshared_and_static_exported() const;
+
+ int MYPREFIX_LIBSHARED_AND_STATIC_DEPRECATED libshared_and_static_deprecated() const;
+
+ int libshared_and_static_not_exported() const;
+
+ int MYPREFIX_LIBSHARED_AND_STATIC_NO_EXPORT libshared_and_static_excluded() const;
+};
+
+MYPREFIX_LIBSHARED_AND_STATIC_EXPORT int libshared_and_static_exported();
+
+MYPREFIX_LIBSHARED_AND_STATIC_DEPRECATED_EXPORT int libshared_and_static_deprecated();
+
+int libshared_and_static_not_exported();
+
+int MYPREFIX_LIBSHARED_AND_STATIC_NO_EXPORT libshared_and_static_excluded();
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/libshared/CMakeLists.txt b/Tests/Module/GenerateExportHeader/libshared/CMakeLists.txt
new file mode 100644
index 0000000000..e20adb1a7c
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/libshared/CMakeLists.txt
@@ -0,0 +1,16 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(libshared)
+
+include(GenerateExportHeader)
+
+add_compiler_export_flags()
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_library(libshared SHARED libshared.cpp)
+
+generate_export_header(libshared)
+
+export(TARGETS libshared FILE Targets.cmake)
diff --git a/Tests/Module/GenerateExportHeader/libshared/libshared.cpp b/Tests/Module/GenerateExportHeader/libshared/libshared.cpp
new file mode 100644
index 0000000000..d4041b36d7
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/libshared/libshared.cpp
@@ -0,0 +1,91 @@
+
+#include "libshared.h"
+
+int Libshared::libshared() const
+{
+ return 0;
+}
+
+int Libshared::libshared_exported() const
+{
+ return 0;
+}
+
+int Libshared::libshared_deprecated() const
+{
+ return 0;
+}
+
+int Libshared::libshared_not_exported() const {
+ return 0;
+}
+
+int Libshared::libshared_excluded() const {
+ return 0;
+}
+
+int LibsharedNotExported::libshared() const
+{
+ return 0;
+}
+
+int LibsharedNotExported::libshared_exported() const
+{
+ return 0;
+}
+
+int LibsharedNotExported::libshared_deprecated() const
+{
+ return 0;
+}
+
+int LibsharedNotExported::libshared_not_exported() const {
+ return 0;
+}
+
+int LibsharedNotExported::libshared_excluded() const {
+ return 0;
+}
+
+int LibsharedExcluded::libshared() const
+{
+ return 0;
+}
+
+int LibsharedExcluded::libshared_exported() const
+{
+ return 0;
+}
+
+int LibsharedExcluded::libshared_deprecated() const
+{
+ return 0;
+}
+
+int LibsharedExcluded::libshared_not_exported() const {
+ return 0;
+}
+
+int LibsharedExcluded::libshared_excluded() const {
+ return 0;
+}
+
+int libshared() {
+ return 0;
+}
+
+int libshared_exported() {
+ return 0;
+}
+
+int libshared_deprecated() {
+ return 0;
+}
+
+int libshared_not_exported() {
+ return 0;
+}
+
+int libshared_excluded() {
+ return 0;
+}
diff --git a/Tests/Module/GenerateExportHeader/libshared/libshared.h b/Tests/Module/GenerateExportHeader/libshared/libshared.h
new file mode 100644
index 0000000000..3d9bbff4fd
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/libshared/libshared.h
@@ -0,0 +1,54 @@
+
+#ifndef LIBSHARED_H
+#define LIBSHARED_H
+
+#include "libshared_export.h"
+
+class LIBSHARED_EXPORT Libshared {
+public:
+ int libshared() const;
+
+ int libshared_exported() const;
+
+ int LIBSHARED_DEPRECATED libshared_deprecated() const;
+
+ int libshared_not_exported() const;
+
+ int LIBSHARED_NO_EXPORT libshared_excluded() const;
+};
+
+class LibsharedNotExported {
+public:
+ int libshared() const;
+
+ int LIBSHARED_EXPORT libshared_exported() const;
+
+ int LIBSHARED_DEPRECATED_EXPORT libshared_deprecated() const;
+
+ int libshared_not_exported() const;
+
+ int LIBSHARED_NO_EXPORT libshared_excluded() const;
+};
+
+class LIBSHARED_NO_EXPORT LibsharedExcluded {
+public:
+ int libshared() const;
+
+ int LIBSHARED_EXPORT libshared_exported() const;
+
+ int LIBSHARED_DEPRECATED_EXPORT libshared_deprecated() const;
+
+ int libshared_not_exported() const;
+
+ int LIBSHARED_NO_EXPORT libshared_excluded() const;
+};
+
+LIBSHARED_EXPORT int libshared_exported();
+
+LIBSHARED_DEPRECATED_EXPORT int libshared_deprecated();
+
+int libshared_not_exported();
+
+int LIBSHARED_NO_EXPORT libshared_excluded();
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/libstatic/CMakeLists.txt b/Tests/Module/GenerateExportHeader/libstatic/CMakeLists.txt
new file mode 100644
index 0000000000..b2db3ea74b
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/libstatic/CMakeLists.txt
@@ -0,0 +1,18 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(libstatic)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+include(GenerateExportHeader)
+
+add_compiler_export_flags()
+
+# Show that the export header has no effect on a static library.
+
+add_library(libstatic STATIC libstatic.cpp)
+
+generate_export_header(libstatic)
+
+export(TARGETS libstatic FILE Targets.cmake)
diff --git a/Tests/Module/GenerateExportHeader/libstatic/libstatic.cpp b/Tests/Module/GenerateExportHeader/libstatic/libstatic.cpp
new file mode 100644
index 0000000000..0710c3e9e9
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/libstatic/libstatic.cpp
@@ -0,0 +1,87 @@
+
+#include "libstatic.h"
+
+int Libstatic::libstatic() const
+{
+ return 0;
+}
+
+int Libstatic::libstatic_exported() const
+{
+ return 0;
+}
+
+int Libstatic::libstatic_deprecated() const
+{
+ return 0;
+}
+
+int Libstatic::libstatic_not_exported() const {
+ return 0;
+}
+
+int Libstatic::libstatic_excluded() const {
+ return 0;
+}
+
+int LibstaticNotExported::libstatic() const
+{
+ return 0;
+}
+
+int LibstaticNotExported::libstatic_exported() const
+{
+ return 0;
+}
+
+int LibstaticNotExported::libstatic_deprecated() const
+{
+ return 0;
+}
+
+int LibstaticNotExported::libstatic_not_exported() const {
+ return 0;
+}
+
+int LibstaticNotExported::libstatic_excluded() const {
+ return 0;
+}
+
+int LibstaticExcluded::libstatic() const
+{
+ return 0;
+}
+
+int LibstaticExcluded::libstatic_exported() const
+{
+ return 0;
+}
+
+int LibstaticExcluded::libstatic_deprecated() const
+{
+ return 0;
+}
+
+int LibstaticExcluded::libstatic_not_exported() const {
+ return 0;
+}
+
+int LibstaticExcluded::libstatic_excluded() const {
+ return 0;
+}
+
+int libstatic_exported() {
+ return 0;
+}
+
+int libstatic_deprecated() {
+ return 0;
+}
+
+int libstatic_not_exported() {
+ return 0;
+}
+
+int libstatic_excluded() {
+ return 0;
+}
diff --git a/Tests/Module/GenerateExportHeader/libstatic/libstatic.h b/Tests/Module/GenerateExportHeader/libstatic/libstatic.h
new file mode 100644
index 0000000000..cc7a35b4eb
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/libstatic/libstatic.h
@@ -0,0 +1,54 @@
+
+#ifndef LIBSTATIC_H
+#define LIBSTATIC_H
+
+#include "libstatic_export.h"
+
+class LIBSTATIC_EXPORT Libstatic {
+public:
+ int libstatic() const;
+
+ int libstatic_exported() const;
+
+ int LIBSTATIC_DEPRECATED libstatic_deprecated() const;
+
+ int libstatic_not_exported() const;
+
+ int LIBSTATIC_NO_EXPORT libstatic_excluded() const;
+};
+
+class LibstaticNotExported {
+public:
+ int libstatic() const;
+
+ int LIBSTATIC_EXPORT libstatic_exported() const;
+
+ int LIBSTATIC_DEPRECATED libstatic_deprecated() const;
+
+ int libstatic_not_exported() const;
+
+ int LIBSTATIC_NO_EXPORT libstatic_excluded() const;
+};
+
+class LIBSTATIC_NO_EXPORT LibstaticExcluded {
+public:
+ int libstatic() const;
+
+ int LIBSTATIC_EXPORT libstatic_exported() const;
+
+ int LIBSTATIC_DEPRECATED libstatic_deprecated() const;
+
+ int libstatic_not_exported() const;
+
+ int LIBSTATIC_NO_EXPORT libstatic_excluded() const;
+};
+
+LIBSTATIC_EXPORT int libstatic_exported();
+
+LIBSTATIC_DEPRECATED_EXPORT int libstatic_deprecated();
+
+int libstatic_not_exported();
+
+int LIBSTATIC_NO_EXPORT libstatic_excluded();
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/nodeprecated/CMakeLists.txt b/Tests/Module/GenerateExportHeader/nodeprecated/CMakeLists.txt
new file mode 100644
index 0000000000..aeeb13a85d
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/nodeprecated/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(nodeprecated)
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_defined)
+execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_not_defined)
+
+configure_file(CMakeLists.txt.in ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_not_defined/CMakeLists.txt)
+set(DEFINE_NO_DEPRECATED DEFINE_NO_DEPRECATED)
+configure_file(CMakeLists.txt.in ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_defined/CMakeLists.txt)
+
+try_compile(Result ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_not_defined_build
+ ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_not_defined
+ nodeprecated_test
+ OUTPUT_VARIABLE Out
+)
+
+test_pass(Result "Failed to build without no-deprecated define")
+
+try_compile(Result ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_defined_build
+ ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_defined
+ nodeprecated_test
+ OUTPUT_VARIABLE Out
+)
+
+test_fail(Result "Built even with no-deprecated define") \ No newline at end of file
diff --git a/Tests/Module/GenerateExportHeader/nodeprecated/CMakeLists.txt.in b/Tests/Module/GenerateExportHeader/nodeprecated/CMakeLists.txt.in
new file mode 100644
index 0000000000..d8dc482f3e
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/nodeprecated/CMakeLists.txt.in
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(nodeprecated_test)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+include(GenerateExportHeader)
+
+add_library(nodeprecatedlib SHARED someclass.cpp)
+
+generate_export_header(nodeprecatedlib @DEFINE_NO_DEPRECATED@)
+
+add_executable(nodeprecatedconsumer main.cpp)
+
+target_link_libraries(nodeprecatedconsumer nodeprecatedlib)
diff --git a/Tests/Module/GenerateExportHeader/nodeprecated/src/main.cpp b/Tests/Module/GenerateExportHeader/nodeprecated/src/main.cpp
new file mode 100644
index 0000000000..eec46d3f2e
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/nodeprecated/src/main.cpp
@@ -0,0 +1,9 @@
+
+#include "someclass.h"
+
+int main(int, char**)
+{
+ SomeClass sc;
+ sc.someMethod();
+ return 0;
+}
diff --git a/Tests/Module/GenerateExportHeader/nodeprecated/src/someclass.cpp b/Tests/Module/GenerateExportHeader/nodeprecated/src/someclass.cpp
new file mode 100644
index 0000000000..a3f41111cf
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/nodeprecated/src/someclass.cpp
@@ -0,0 +1,9 @@
+
+#include "someclass.h"
+
+#ifndef NODEPRECATEDLIB_NO_DEPRECATED
+void SomeClass::someMethod() const
+{
+
+}
+#endif
diff --git a/Tests/Module/GenerateExportHeader/nodeprecated/src/someclass.h b/Tests/Module/GenerateExportHeader/nodeprecated/src/someclass.h
new file mode 100644
index 0000000000..312a177f18
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/nodeprecated/src/someclass.h
@@ -0,0 +1,10 @@
+
+#include "nodeprecatedlib_export.h"
+
+class NODEPRECATEDLIB_EXPORT SomeClass
+{
+public:
+#ifndef NODEPRECATEDLIB_NO_DEPRECATED
+ void someMethod() const;
+#endif
+};
diff --git a/Tests/Module/GenerateExportHeader/reference/Empty/libshared_export.h b/Tests/Module/GenerateExportHeader/reference/Empty/libshared_export.h
new file mode 100644
index 0000000000..b6749b2570
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/Empty/libshared_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSHARED_EXPORT_H
+#define LIBSHARED_EXPORT_H
+
+#ifdef LIBSHARED_STATIC_DEFINE
+# define LIBSHARED_EXPORT
+# define LIBSHARED_NO_EXPORT
+#else
+# ifndef LIBSHARED_EXPORT
+# ifdef libshared_EXPORTS
+ /* We are building this library */
+# define LIBSHARED_EXPORT
+# else
+ /* We are using this library */
+# define LIBSHARED_EXPORT
+# endif
+# endif
+
+# ifndef LIBSHARED_NO_EXPORT
+# define LIBSHARED_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSHARED_DEPRECATED
+# define LIBSHARED_DEPRECATED
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_EXPORT
+# define LIBSHARED_DEPRECATED_EXPORT LIBSHARED_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_NO_EXPORT
+# define LIBSHARED_DEPRECATED_NO_EXPORT LIBSHARED_NO_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSHARED_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/Empty/libstatic_export.h b/Tests/Module/GenerateExportHeader/reference/Empty/libstatic_export.h
new file mode 100644
index 0000000000..e8000e2518
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/Empty/libstatic_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSTATIC_EXPORT_H
+#define LIBSTATIC_EXPORT_H
+
+#ifdef LIBSTATIC_STATIC_DEFINE
+# define LIBSTATIC_EXPORT
+# define LIBSTATIC_NO_EXPORT
+#else
+# ifndef LIBSTATIC_EXPORT
+# ifdef libstatic_EXPORTS
+ /* We are building this library */
+# define LIBSTATIC_EXPORT
+# else
+ /* We are using this library */
+# define LIBSTATIC_EXPORT
+# endif
+# endif
+
+# ifndef LIBSTATIC_NO_EXPORT
+# define LIBSTATIC_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED
+# define LIBSTATIC_DEPRECATED
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_EXPORT
+# define LIBSTATIC_DEPRECATED_EXPORT LIBSTATIC_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_NO_EXPORT
+# define LIBSTATIC_DEPRECATED_NO_EXPORT LIBSTATIC_NO_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSTATIC_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/MinGW/libshared_export.h b/Tests/Module/GenerateExportHeader/reference/MinGW/libshared_export.h
new file mode 100644
index 0000000000..d37663102d
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/MinGW/libshared_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSHARED_EXPORT_H
+#define LIBSHARED_EXPORT_H
+
+#ifdef LIBSHARED_STATIC_DEFINE
+# define LIBSHARED_EXPORT
+# define LIBSHARED_NO_EXPORT
+#else
+# ifndef LIBSHARED_EXPORT
+# ifdef libshared_EXPORTS
+ /* We are building this library */
+# define LIBSHARED_EXPORT __declspec(dllexport)
+# else
+ /* We are using this library */
+# define LIBSHARED_EXPORT __declspec(dllimport)
+# endif
+# endif
+
+# ifndef LIBSHARED_NO_EXPORT
+# define LIBSHARED_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSHARED_DEPRECATED
+# define LIBSHARED_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_EXPORT
+# define LIBSHARED_DEPRECATED_EXPORT LIBSHARED_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_NO_EXPORT
+# define LIBSHARED_DEPRECATED_NO_EXPORT LIBSHARED_NO_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSHARED_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/MinGW/libstatic_export.h b/Tests/Module/GenerateExportHeader/reference/MinGW/libstatic_export.h
new file mode 100644
index 0000000000..fd021e9d01
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/MinGW/libstatic_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSTATIC_EXPORT_H
+#define LIBSTATIC_EXPORT_H
+
+#ifdef LIBSTATIC_STATIC_DEFINE
+# define LIBSTATIC_EXPORT
+# define LIBSTATIC_NO_EXPORT
+#else
+# ifndef LIBSTATIC_EXPORT
+# ifdef libstatic_EXPORTS
+ /* We are building this library */
+# define LIBSTATIC_EXPORT
+# else
+ /* We are using this library */
+# define LIBSTATIC_EXPORT
+# endif
+# endif
+
+# ifndef LIBSTATIC_NO_EXPORT
+# define LIBSTATIC_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED
+# define LIBSTATIC_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_EXPORT
+# define LIBSTATIC_DEPRECATED_EXPORT LIBSTATIC_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_NO_EXPORT
+# define LIBSTATIC_DEPRECATED_NO_EXPORT LIBSTATIC_NO_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSTATIC_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/UNIX/libshared_export.h b/Tests/Module/GenerateExportHeader/reference/UNIX/libshared_export.h
new file mode 100644
index 0000000000..7d8087f60f
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/UNIX/libshared_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSHARED_EXPORT_H
+#define LIBSHARED_EXPORT_H
+
+#ifdef LIBSHARED_STATIC_DEFINE
+# define LIBSHARED_EXPORT
+# define LIBSHARED_NO_EXPORT
+#else
+# ifndef LIBSHARED_EXPORT
+# ifdef libshared_EXPORTS
+ /* We are building this library */
+# define LIBSHARED_EXPORT __attribute__((visibility("default")))
+# else
+ /* We are using this library */
+# define LIBSHARED_EXPORT __attribute__((visibility("default")))
+# endif
+# endif
+
+# ifndef LIBSHARED_NO_EXPORT
+# define LIBSHARED_NO_EXPORT __attribute__((visibility("hidden")))
+# endif
+#endif
+
+#ifndef LIBSHARED_DEPRECATED
+# define LIBSHARED_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_EXPORT
+# define LIBSHARED_DEPRECATED_EXPORT LIBSHARED_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_NO_EXPORT
+# define LIBSHARED_DEPRECATED_NO_EXPORT LIBSHARED_NO_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSHARED_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/UNIX/libstatic_export.h b/Tests/Module/GenerateExportHeader/reference/UNIX/libstatic_export.h
new file mode 100644
index 0000000000..fd021e9d01
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/UNIX/libstatic_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSTATIC_EXPORT_H
+#define LIBSTATIC_EXPORT_H
+
+#ifdef LIBSTATIC_STATIC_DEFINE
+# define LIBSTATIC_EXPORT
+# define LIBSTATIC_NO_EXPORT
+#else
+# ifndef LIBSTATIC_EXPORT
+# ifdef libstatic_EXPORTS
+ /* We are building this library */
+# define LIBSTATIC_EXPORT
+# else
+ /* We are using this library */
+# define LIBSTATIC_EXPORT
+# endif
+# endif
+
+# ifndef LIBSTATIC_NO_EXPORT
+# define LIBSTATIC_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED
+# define LIBSTATIC_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_EXPORT
+# define LIBSTATIC_DEPRECATED_EXPORT LIBSTATIC_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_NO_EXPORT
+# define LIBSTATIC_DEPRECATED_NO_EXPORT LIBSTATIC_NO_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSTATIC_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libshared_export.h b/Tests/Module/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libshared_export.h
new file mode 100644
index 0000000000..5681f58428
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libshared_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSHARED_EXPORT_H
+#define LIBSHARED_EXPORT_H
+
+#ifdef LIBSHARED_STATIC_DEFINE
+# define LIBSHARED_EXPORT
+# define LIBSHARED_NO_EXPORT
+#else
+# ifndef LIBSHARED_EXPORT
+# ifdef libshared_EXPORTS
+ /* We are building this library */
+# define LIBSHARED_EXPORT
+# else
+ /* We are using this library */
+# define LIBSHARED_EXPORT
+# endif
+# endif
+
+# ifndef LIBSHARED_NO_EXPORT
+# define LIBSHARED_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSHARED_DEPRECATED
+# define LIBSHARED_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_EXPORT
+# define LIBSHARED_DEPRECATED_EXPORT LIBSHARED_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_NO_EXPORT
+# define LIBSHARED_DEPRECATED_NO_EXPORT LIBSHARED_NO_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSHARED_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libstatic_export.h b/Tests/Module/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libstatic_export.h
new file mode 100644
index 0000000000..fd021e9d01
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libstatic_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSTATIC_EXPORT_H
+#define LIBSTATIC_EXPORT_H
+
+#ifdef LIBSTATIC_STATIC_DEFINE
+# define LIBSTATIC_EXPORT
+# define LIBSTATIC_NO_EXPORT
+#else
+# ifndef LIBSTATIC_EXPORT
+# ifdef libstatic_EXPORTS
+ /* We are building this library */
+# define LIBSTATIC_EXPORT
+# else
+ /* We are using this library */
+# define LIBSTATIC_EXPORT
+# endif
+# endif
+
+# ifndef LIBSTATIC_NO_EXPORT
+# define LIBSTATIC_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED
+# define LIBSTATIC_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_EXPORT
+# define LIBSTATIC_DEPRECATED_EXPORT LIBSTATIC_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_NO_EXPORT
+# define LIBSTATIC_DEPRECATED_NO_EXPORT LIBSTATIC_NO_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSTATIC_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/Win32/libshared_export.h b/Tests/Module/GenerateExportHeader/reference/Win32/libshared_export.h
new file mode 100644
index 0000000000..976c92ef84
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/Win32/libshared_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSHARED_EXPORT_H
+#define LIBSHARED_EXPORT_H
+
+#ifdef LIBSHARED_STATIC_DEFINE
+# define LIBSHARED_EXPORT
+# define LIBSHARED_NO_EXPORT
+#else
+# ifndef LIBSHARED_EXPORT
+# ifdef libshared_EXPORTS
+ /* We are building this library */
+# define LIBSHARED_EXPORT __declspec(dllexport)
+# else
+ /* We are using this library */
+# define LIBSHARED_EXPORT __declspec(dllimport)
+# endif
+# endif
+
+# ifndef LIBSHARED_NO_EXPORT
+# define LIBSHARED_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSHARED_DEPRECATED
+# define LIBSHARED_DEPRECATED __declspec(deprecated)
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_EXPORT
+# define LIBSHARED_DEPRECATED_EXPORT LIBSHARED_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_NO_EXPORT
+# define LIBSHARED_DEPRECATED_NO_EXPORT LIBSHARED_NO_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSHARED_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/Win32/libstatic_export.h b/Tests/Module/GenerateExportHeader/reference/Win32/libstatic_export.h
new file mode 100644
index 0000000000..db4df61b44
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/Win32/libstatic_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSTATIC_EXPORT_H
+#define LIBSTATIC_EXPORT_H
+
+#ifdef LIBSTATIC_STATIC_DEFINE
+# define LIBSTATIC_EXPORT
+# define LIBSTATIC_NO_EXPORT
+#else
+# ifndef LIBSTATIC_EXPORT
+# ifdef libstatic_EXPORTS
+ /* We are building this library */
+# define LIBSTATIC_EXPORT
+# else
+ /* We are using this library */
+# define LIBSTATIC_EXPORT
+# endif
+# endif
+
+# ifndef LIBSTATIC_NO_EXPORT
+# define LIBSTATIC_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED
+# define LIBSTATIC_DEPRECATED __declspec(deprecated)
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_EXPORT
+# define LIBSTATIC_DEPRECATED_EXPORT LIBSTATIC_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_NO_EXPORT
+# define LIBSTATIC_DEPRECATED_NO_EXPORT LIBSTATIC_NO_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSTATIC_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/WinEmpty/libshared_export.h b/Tests/Module/GenerateExportHeader/reference/WinEmpty/libshared_export.h
new file mode 100644
index 0000000000..2dc41d414e
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/WinEmpty/libshared_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSHARED_EXPORT_H
+#define LIBSHARED_EXPORT_H
+
+#ifdef LIBSHARED_STATIC_DEFINE
+# define LIBSHARED_EXPORT
+# define LIBSHARED_NO_EXPORT
+#else
+# ifndef LIBSHARED_EXPORT
+# ifdef libshared_EXPORTS
+ /* We are building this library */
+# define LIBSHARED_EXPORT __declspec(dllexport)
+# else
+ /* We are using this library */
+# define LIBSHARED_EXPORT __declspec(dllimport)
+# endif
+# endif
+
+# ifndef LIBSHARED_NO_EXPORT
+# define LIBSHARED_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSHARED_DEPRECATED
+# define LIBSHARED_DEPRECATED
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_EXPORT
+# define LIBSHARED_DEPRECATED_EXPORT LIBSHARED_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#ifndef LIBSHARED_DEPRECATED_NO_EXPORT
+# define LIBSHARED_DEPRECATED_NO_EXPORT LIBSHARED_NO_EXPORT LIBSHARED_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSHARED_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/GenerateExportHeader/reference/WinEmpty/libstatic_export.h b/Tests/Module/GenerateExportHeader/reference/WinEmpty/libstatic_export.h
new file mode 100644
index 0000000000..e8000e2518
--- /dev/null
+++ b/Tests/Module/GenerateExportHeader/reference/WinEmpty/libstatic_export.h
@@ -0,0 +1,41 @@
+
+#ifndef LIBSTATIC_EXPORT_H
+#define LIBSTATIC_EXPORT_H
+
+#ifdef LIBSTATIC_STATIC_DEFINE
+# define LIBSTATIC_EXPORT
+# define LIBSTATIC_NO_EXPORT
+#else
+# ifndef LIBSTATIC_EXPORT
+# ifdef libstatic_EXPORTS
+ /* We are building this library */
+# define LIBSTATIC_EXPORT
+# else
+ /* We are using this library */
+# define LIBSTATIC_EXPORT
+# endif
+# endif
+
+# ifndef LIBSTATIC_NO_EXPORT
+# define LIBSTATIC_NO_EXPORT
+# endif
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED
+# define LIBSTATIC_DEPRECATED
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_EXPORT
+# define LIBSTATIC_DEPRECATED_EXPORT LIBSTATIC_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#ifndef LIBSTATIC_DEPRECATED_NO_EXPORT
+# define LIBSTATIC_DEPRECATED_NO_EXPORT LIBSTATIC_NO_EXPORT LIBSTATIC_DEPRECATED
+#endif
+
+#define DEFINE_NO_DEPRECATED 0
+#if DEFINE_NO_DEPRECATED
+# define LIBSTATIC_NO_DEPRECATED
+#endif
+
+#endif
diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
new file mode 100644
index 0000000000..645cc65244
--- /dev/null
+++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
@@ -0,0 +1,88 @@
+cmake_minimum_required(VERSION 3.0.0)
+project(WriteCompilerDetectionHeader)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+include(WriteCompilerDetectionHeader)
+
+get_property(cxx_known_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
+get_property(c_known_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection.h"
+ PREFIX TEST
+ COMPILERS GNU Clang
+ VERSION 3.1
+ PROLOG "// something"
+ EPILOG "// more"
+ FEATURES
+ ${cxx_known_features} ${c_known_features}
+)
+
+if (NOT CMAKE_CXX_COMPILE_FEATURES AND NOT CMAKE_C_COMPILE_FEATURES)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp"
+ "int main(int,char**) { return 0; }\n"
+ )
+ add_executable(WriteCompilerDetectionHeader "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp")
+
+ include(CheckCXXSourceCompiles)
+ check_cxx_source_compiles("#include \"${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection.h\"\nint main() { return 0; }\n"
+ file_include_works
+ )
+ if (file_include_works)
+ message(SEND_ERROR "Inclusion of ${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection.h was expected to cause an error, but did not.")
+ endif()
+ return()
+endif()
+
+string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" COMPILER_VERSION_MAJOR "${CMAKE_CXX_COMPILER_VERSION}")
+string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" COMPILER_VERSION_MINOR "${CMAKE_CXX_COMPILER_VERSION}")
+string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" COMPILER_VERSION_PATCH "${CMAKE_CXX_COMPILER_VERSION}")
+
+macro(set_defines target true_defs false_defs)
+ set(defines)
+ foreach(def ${true_defs})
+ list(APPEND defines ${def}=1)
+ endforeach()
+ foreach(def ${false_defs})
+ list(APPEND defines ${def}=0)
+ endforeach()
+ target_compile_definitions(${target}
+ PRIVATE
+ ${defines}
+ EXPECTED_COMPILER_VERSION_MAJOR=${COMPILER_VERSION_MAJOR}
+ EXPECTED_COMPILER_VERSION_MINOR=${COMPILER_VERSION_MINOR}
+ EXPECTED_COMPILER_VERSION_PATCH=${COMPILER_VERSION_PATCH}
+ )
+endmacro()
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL GNU
+ OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
+ # False for C++98 mode.
+ list(APPEND false_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
+ list(APPEND false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
+endif()
+
+add_executable(WriteCompilerDetectionHeader main.cpp)
+set_property(TARGET WriteCompilerDetectionHeader PROPERTY CXX_STANDARD 98)
+set_defines(WriteCompilerDetectionHeader "${true_defs}" "${false_defs}")
+
+if(MSVC)
+ return() # MSVC has only one mode.
+endif()
+
+# Since GNU 4.7
+if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;")
+ list(APPEND true_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
+ list(REMOVE_ITEM false_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
+endif()
+
+# Since GNU 4.4
+if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_variadic_templates;")
+ list(APPEND true_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
+ list(REMOVE_ITEM false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
+endif()
+
+add_executable(WriteCompilerDetectionHeader_11 main.cpp)
+set_property(TARGET WriteCompilerDetectionHeader_11 PROPERTY CXX_STANDARD 11)
+set_defines(WriteCompilerDetectionHeader_11 "${true_defs}" "${false_defs}")
diff --git a/Tests/Module/WriteCompilerDetectionHeader/main.cpp b/Tests/Module/WriteCompilerDetectionHeader/main.cpp
new file mode 100644
index 0000000000..b807ad5eb0
--- /dev/null
+++ b/Tests/Module/WriteCompilerDetectionHeader/main.cpp
@@ -0,0 +1,31 @@
+
+#include "test_compiler_detection.h"
+
+#define JOIN_IMPL(A, B) A ## B
+#define JOIN(A, B) JOIN_IMPL(A, B)
+#define CHECK(FEATURE) (JOIN(TEST_COMPILER_, FEATURE) == JOIN(EXPECTED_COMPILER_, FEATURE))
+
+#if !CHECK(CXX_DELEGATING_CONSTRUCTORS)
+#error cxx_delegating_constructors expected availability did not match.
+#endif
+
+#if !CHECK(CXX_VARIADIC_TEMPLATES)
+#error cxx_variadic_templates expected availability did not match.
+#endif
+
+#if !CHECK(VERSION_MAJOR)
+#error Compiler major version did not match.
+#endif
+
+#if !CHECK(VERSION_MINOR)
+#error Compiler minor version did not match.
+#endif
+
+#if !CHECK(VERSION_PATCH)
+#error Compiler patch version did not match.
+#endif
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/ModuleDefinition/CMakeLists.txt b/Tests/ModuleDefinition/CMakeLists.txt
new file mode 100644
index 0000000000..a30f643639
--- /dev/null
+++ b/Tests/ModuleDefinition/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 2.6)
+project(ModuleDefinition C)
+
+# Test .def file source recognition for DLLs.
+add_library(example_dll SHARED example_dll.c example_dll.def)
+
+# Test generated .def file.
+add_custom_command(OUTPUT example_dll_gen.def
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/example_dll_gen.def.in
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/example_dll_gen.def.in
+ ${CMAKE_CURRENT_BINARY_DIR}/example_dll_gen.def
+ )
+add_library(example_dll_gen SHARED example_dll_gen.c example_dll_gen.def)
+
+# Test /DEF:<file> flag recognition for VS.
+if(MSVC OR "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")
+ add_library(example_dll_2 SHARED example_dll_2.c)
+ set_property(TARGET example_dll_2 PROPERTY LINK_FLAGS
+ /DEF:"${ModuleDefinition_SOURCE_DIR}/example_dll_2.def")
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS EXAMPLE_DLL_2)
+ set(example_dll_2 example_dll_2)
+endif()
+
+# Test .def file source recognition for EXEs.
+add_executable(example_exe example_exe.c example_exe.def)
+set_property(TARGET example_exe PROPERTY ENABLE_EXPORTS 1)
+target_link_libraries(example_exe example_dll example_dll_gen ${example_dll_2})
+
+# Test linking to the executable.
+add_library(example_mod_1 MODULE example_mod_1.c)
+target_link_libraries(example_mod_1 example_exe example_dll ${example_dll_2})
diff --git a/Tests/ModuleDefinition/example_dll.c b/Tests/ModuleDefinition/example_dll.c
new file mode 100644
index 0000000000..88b3904a76
--- /dev/null
+++ b/Tests/ModuleDefinition/example_dll.c
@@ -0,0 +1 @@
+int example_dll_function(void) { return 0; }
diff --git a/Tests/ModuleDefinition/example_dll.def b/Tests/ModuleDefinition/example_dll.def
new file mode 100644
index 0000000000..df64fb3c10
--- /dev/null
+++ b/Tests/ModuleDefinition/example_dll.def
@@ -0,0 +1,2 @@
+EXPORTS
+example_dll_function
diff --git a/Tests/ModuleDefinition/example_dll_2.c b/Tests/ModuleDefinition/example_dll_2.c
new file mode 100644
index 0000000000..9d79acdd38
--- /dev/null
+++ b/Tests/ModuleDefinition/example_dll_2.c
@@ -0,0 +1 @@
+int example_dll_2_function(void) { return 0; }
diff --git a/Tests/ModuleDefinition/example_dll_2.def b/Tests/ModuleDefinition/example_dll_2.def
new file mode 100644
index 0000000000..8eba7f9cdc
--- /dev/null
+++ b/Tests/ModuleDefinition/example_dll_2.def
@@ -0,0 +1,2 @@
+EXPORTS
+example_dll_2_function
diff --git a/Tests/ModuleDefinition/example_dll_gen.c b/Tests/ModuleDefinition/example_dll_gen.c
new file mode 100644
index 0000000000..be5d1eed79
--- /dev/null
+++ b/Tests/ModuleDefinition/example_dll_gen.c
@@ -0,0 +1 @@
+int example_dll_gen_function(void) { return 0; }
diff --git a/Tests/ModuleDefinition/example_dll_gen.def.in b/Tests/ModuleDefinition/example_dll_gen.def.in
new file mode 100644
index 0000000000..c489dbc836
--- /dev/null
+++ b/Tests/ModuleDefinition/example_dll_gen.def.in
@@ -0,0 +1,2 @@
+EXPORTS
+example_dll_gen_function
diff --git a/Tests/ModuleDefinition/example_exe.c b/Tests/ModuleDefinition/example_exe.c
new file mode 100644
index 0000000000..253ae8b70b
--- /dev/null
+++ b/Tests/ModuleDefinition/example_exe.c
@@ -0,0 +1,16 @@
+extern int __declspec(dllimport) example_dll_function(void);
+extern int __declspec(dllimport) example_dll_gen_function(void);
+#ifdef EXAMPLE_DLL_2
+extern int __declspec(dllimport) example_dll_2_function(void);
+#endif
+int example_exe_function(void) { return 0; }
+int main(void)
+{
+ return
+ example_dll_function() +
+ example_dll_gen_function() +
+#ifdef EXAMPLE_DLL_2
+ example_dll_2_function() +
+#endif
+ example_exe_function();
+}
diff --git a/Tests/ModuleDefinition/example_exe.def b/Tests/ModuleDefinition/example_exe.def
new file mode 100644
index 0000000000..2a0df1f849
--- /dev/null
+++ b/Tests/ModuleDefinition/example_exe.def
@@ -0,0 +1,2 @@
+EXPORTS
+example_exe_function
diff --git a/Tests/ModuleDefinition/example_mod_1.c b/Tests/ModuleDefinition/example_mod_1.c
new file mode 100644
index 0000000000..4e2f9ba1f5
--- /dev/null
+++ b/Tests/ModuleDefinition/example_mod_1.c
@@ -0,0 +1,21 @@
+#ifdef __WATCOMC__
+# define MODULE_CCONV __cdecl
+#else
+# define MODULE_CCONV
+#endif
+
+int __declspec(dllimport) example_exe_function(void);
+int __declspec(dllimport) example_dll_function(void);
+#ifdef EXAMPLE_DLL_2
+int __declspec(dllimport) example_dll_2_function(void);
+#endif
+
+__declspec(dllexport) int MODULE_CCONV example_mod_1_function(int n)
+{
+ return
+ example_dll_function() +
+#ifdef EXAMPLE_DLL_2
+ example_dll_2_function() +
+#endif
+ example_exe_function() + n;
+}
diff --git a/Tests/MumpsCoverage/.gitattributes b/Tests/MumpsCoverage/.gitattributes
new file mode 100644
index 0000000000..b6806125de
--- /dev/null
+++ b/Tests/MumpsCoverage/.gitattributes
@@ -0,0 +1,2 @@
+*.cmcov -crlf -whitespace
+*.mcov -crlf -whitespace
diff --git a/Tests/MumpsCoverage/DartConfiguration.cache.tcl.in b/Tests/MumpsCoverage/DartConfiguration.cache.tcl.in
new file mode 100644
index 0000000000..a1c6b17f60
--- /dev/null
+++ b/Tests/MumpsCoverage/DartConfiguration.cache.tcl.in
@@ -0,0 +1,8 @@
+# This file is configured by CMake automatically as DartConfiguration.tcl
+# If you choose not to use CMake, this file may be hand configured, by
+# filling in the required variables.
+
+
+# Configuration directories and files
+SourceDirectory: ${CMake_SOURCE_DIR}/Testing/MumpsCoverage
+BuildDirectory: ${CMake_BINARY_DIR}/Testing/MumpsCacheCoverage
diff --git a/Tests/MumpsCoverage/DartConfiguration.tcl.in b/Tests/MumpsCoverage/DartConfiguration.tcl.in
new file mode 100644
index 0000000000..2d7eaa5217
--- /dev/null
+++ b/Tests/MumpsCoverage/DartConfiguration.tcl.in
@@ -0,0 +1,8 @@
+# This file is configured by CMake automatically as DartConfiguration.tcl
+# If you choose not to use CMake, this file may be hand configured, by
+# filling in the required variables.
+
+
+# Configuration directories and files
+SourceDirectory: ${CMake_SOURCE_DIR}/Testing/MumpsCoverage
+BuildDirectory: ${CMake_BINARY_DIR}/Testing/MumpsCoverage
diff --git a/Tests/MumpsCoverage/VistA-FOIA/Packages/Uncategorized/ZZCOVTST.m b/Tests/MumpsCoverage/VistA-FOIA/Packages/Uncategorized/ZZCOVTST.m
new file mode 100644
index 0000000000..ee7068240a
--- /dev/null
+++ b/Tests/MumpsCoverage/VistA-FOIA/Packages/Uncategorized/ZZCOVTST.m
@@ -0,0 +1,43 @@
+ZZCOVTST;OSEHRA/JPS -- Test routine for Coverage Parsing;4/28/2014
+ ; (tab) This is series of comments
+ ; (tab) it should all be not executable
+ ; (spaces) one of these sets might be a problem
+ ; (spaces) we will have to see.
+EN ; This entry point shouldn't be found without fixing
+ N D
+ S D=1 ;An executable line
+ D T1^ZZCOVTST
+ I '$$T5 W "RETURNED FROM t5",!
+ Q
+ ; This line not executable
+ D T6^ZZCOVTST
+ ;
+T1 ; This line should always be found
+ N D
+ S D=2
+ W !,D,!,"This is the second entry point",!
+ D T2^ZZCOVTST(D)
+ Q
+ ;
+T2(EQ) ; This is debatable and only called with ENT^ROU notation
+ N D
+ S D=3
+ W !,D,!,EQ,"This is the third entry point",!
+ D T3^ZZCOVTST
+ Q
+ ;
+T3 N D S D=4 W D,!,"Fourth Entry point",! Q
+ ;
+T4 N D S D=5 W "Shouldn't be executed"
+ W "Lots to not do"
+ Q
+T5(EQ) ;this entry point is called with a $$ notation
+ W "THIS IS THE $$ NOTATION!",!
+ Q 0
+T6 ; An entry point to show comments inside of "DO" blocks
+ D
+ . W "This is executable code",!
+ . ;This is a comment inside the do block, not executable
+ . S ZZBLAH="blah"
+ W "Ending T6",!
+ ;
diff --git a/Tests/MumpsCoverage/ZZCOVTST.cmcov b/Tests/MumpsCoverage/ZZCOVTST.cmcov
new file mode 100644
index 0000000000..7a5df61054
--- /dev/null
+++ b/Tests/MumpsCoverage/ZZCOVTST.cmcov
@@ -0,0 +1,45 @@
+Routine,Line,RtnLine,Code
+ZZCOVTST,1,1,"ZZCOVTST;OSEHRA/JPS -- Test routine for Coverage Parsing;4/28/2014"
+,2,0," ; (tab) This is series of comments"
+,3,0," ; (tab) it should all be not executable"
+,4,0," ; (spaces) one of these sets might be a problem"
+,5,0," ; (spaces) we will have to see."
+,6,0,"EN ; This entry point shouldn't be found without fixing"
+,7,1," N D"
+,8,1," S D=1 ;An executable line"
+,9,1," D T1^ZZCOVTST"
+,10,1," I '$$T5 W ""RETURNED FROM t5"",!"
+,11,1," D T6^ZZCOVTST"
+,12,1," Q"
+,13,0," ; This line not executable"
+,14,0," ;"
+,15,0,"T1 ; This line should always be found"
+,16,1," N D"
+,17,1," S D=2"
+,18,1," W !,D,!,""This is the second entry point"",!"
+,19,1," D T2^ZZCOVTST(D)"
+,20,1," Q"
+,21,0," ;"
+,22,0,"T2(EQ) ; This is debatable and only called with ENT^ROU notation"
+,23,1," N D"
+,24,1," S D=3"
+,25,1," W !,D,!,EQ,""This is the third entry point"",!"
+,26,1," D T3^ZZCOVTST"
+,27,1," Q"
+,28,0," ;"
+,29,1,"T3 N D S D=4 W D,!,""Fourth Entry point"",! Q"
+,30,0," ;"
+,31,0,"T4 N D S D=5 W ""Shouldn't be executed"""
+,32,0," W ""Lots to not do"""
+,33,0," Q"
+,34,1,"T5(EQ) ;this entry point is called with a $$ notation"
+,35,1," W ""THIS IS THE $$ NOTATION!"",!"
+,36,1," Q 0"
+,37,0,"T6 ; An entry point to show comments inside of ""DO"" blocks"
+,38,1," D"
+,39,1," . W ""This is executable code"",!"
+,40,0," . ; This is a comment inside the do block, not executable"
+,41,1," . S ZZBLAH=""blah"""
+,42,1," W ""Ending T6"",!"
+,43,0," ;"
+Totals for ZZCOVTST,,25, \ No newline at end of file
diff --git a/Tests/MumpsCoverage/ZZCOVTST.mcov b/Tests/MumpsCoverage/ZZCOVTST.mcov
new file mode 100644
index 0000000000..b2608d952b
--- /dev/null
+++ b/Tests/MumpsCoverage/ZZCOVTST.mcov
@@ -0,0 +1,38 @@
+%GO Global Output Utility
+GT.M 15-AUG-2014 10:14:32 ZWR
+^ZZCOVERAGE("*CHILDREN")="212000:68000:280000"
+^ZZCOVERAGE("*RUN")="56000:136000:192000"
+^ZZCOVERAGE("ZZCOVTST","EN")="1:4000:4000:8000:8627798"
+^ZZCOVERAGE("ZZCOVTST","EN",1)="1:0:0:0:27"
+^ZZCOVERAGE("ZZCOVTST","EN",2)="1:0:0:0:23"
+^ZZCOVERAGE("ZZCOVTST","EN",3)="1:0:0:0:70"
+^ZZCOVERAGE("ZZCOVTST","EN",4)="1:0:0:0:74"
+^ZZCOVERAGE("ZZCOVTST","EN",5)="1:0:0:0:66"
+^ZZCOVERAGE("ZZCOVTST","EN",6)="1:0:0:0:40"
+^ZZCOVERAGE("ZZCOVTST","T1")="1:0:0:0:208"
+^ZZCOVERAGE("ZZCOVTST","T1",1)="1:0:0:0:23"
+^ZZCOVERAGE("ZZCOVTST","T1",2)="1:0:0:0:24"
+^ZZCOVERAGE("ZZCOVTST","T1",3)="1:0:0:0:26"
+^ZZCOVERAGE("ZZCOVTST","T1",4)="1:0:0:0:73"
+^ZZCOVERAGE("ZZCOVTST","T1",5)="1:0:0:0:40"
+^ZZCOVERAGE("ZZCOVTST","T2")="1:0:0:0:1783"
+^ZZCOVERAGE("ZZCOVTST","T2",0)="1:0:0:0:25"
+^ZZCOVERAGE("ZZCOVTST","T2",1)="1:0:0:0:524"
+^ZZCOVERAGE("ZZCOVTST","T2",2)="1:0:0:0:40"
+^ZZCOVERAGE("ZZCOVTST","T2",3)="1:0:0:0:95"
+^ZZCOVERAGE("ZZCOVTST","T2",4)="1:0:0:0:607"
+^ZZCOVERAGE("ZZCOVTST","T2",5)="1:0:0:0:470"
+^ZZCOVERAGE("ZZCOVTST","T3")="1:0:0:0:254"
+^ZZCOVERAGE("ZZCOVTST","T3",0)="1:0:0:0:76"
+^ZZCOVERAGE("ZZCOVTST","T5")="1:0:0:0:153"
+^ZZCOVERAGE("ZZCOVTST","T5",0)="1:0:0:0:40"
+^ZZCOVERAGE("ZZCOVTST","T5",1)="1:0:0:0:41"
+^ZZCOVERAGE("ZZCOVTST","T5",2)="1:0:0:0:41"
+^ZZCOVERAGE("ZZCOVTST","T6")="1:0:0:0:227"
+^ZZCOVERAGE("ZZCOVTST","T6",1)="1:0:0:0:41"
+^ZZCOVERAGE("ZZCOVTST","T6",2)="1:0:0:0:42"
+^ZZCOVERAGE("ZZCOVTST","T6",4)="1:0:0:0:41"
+^ZZCOVERAGE("ZZCOVTST","T6",5)="1:0:0:0:34"
+^ZZCOVERAGE("ZZCOVTST","T6",6)="1:0:0:0:38"
+
+
diff --git a/Tests/MumpsCoverage/cache_coverage.cmcov.in b/Tests/MumpsCoverage/cache_coverage.cmcov.in
new file mode 100644
index 0000000000..b431dbdc16
--- /dev/null
+++ b/Tests/MumpsCoverage/cache_coverage.cmcov.in
@@ -0,0 +1,2 @@
+packages:${CMake_BINARY_DIR}/Testing/MumpsCoverage/VistA-FOIA/Packages
+coverage_dir:${CMake_SOURCE_DIR}/Tests/MumpsCoverage
diff --git a/Tests/MumpsCoverage/gtm_coverage.mcov.in b/Tests/MumpsCoverage/gtm_coverage.mcov.in
new file mode 100644
index 0000000000..b431dbdc16
--- /dev/null
+++ b/Tests/MumpsCoverage/gtm_coverage.mcov.in
@@ -0,0 +1,2 @@
+packages:${CMake_BINARY_DIR}/Testing/MumpsCoverage/VistA-FOIA/Packages
+coverage_dir:${CMake_SOURCE_DIR}/Tests/MumpsCoverage
diff --git a/Tests/NewlineArgs/CMakeLists.txt b/Tests/NewlineArgs/CMakeLists.txt
new file mode 100644
index 0000000000..7551601024
--- /dev/null
+++ b/Tests/NewlineArgs/CMakeLists.txt
@@ -0,0 +1,16 @@
+# a simple CXX only test case
+cmake_minimum_required (VERSION 2.6)
+project (NewlineArgs CXX)
+
+add_definitions("-DTEST_FLAG_1
+-DTEST_FLAG_2")
+
+include_directories(" ${NewlineArgs_BINARY_DIR}
+ ${NewlineArgs_SOURCE_DIR} ")
+
+configure_file("${NewlineArgs_SOURCE_DIR}/libcxx2.h.in"
+ "${NewlineArgs_BINARY_DIR}/libcxx2.h")
+
+add_library(testcxx1 libcxx1.cxx)
+add_executable (NewlineArgs cxxonly.cxx)
+target_link_libraries(NewlineArgs testcxx1)
diff --git a/Tests/NewlineArgs/cxxonly.cxx b/Tests/NewlineArgs/cxxonly.cxx
new file mode 100644
index 0000000000..05d55e4ef2
--- /dev/null
+++ b/Tests/NewlineArgs/cxxonly.cxx
@@ -0,0 +1,19 @@
+#include "libcxx1.h"
+#include "libcxx2.h"
+
+#include <stdio.h>
+
+int main ()
+{
+ if ( LibCxx1Class::Method() != 2.0 )
+ {
+ printf("Problem with libcxx1\n");
+ return 1;
+ }
+#ifdef TEST_FLAG_3
+ return 0;
+#else
+ printf("Problem with libcxx2.h include dir probably!\n");
+ return 1;
+#endif
+}
diff --git a/Tests/NewlineArgs/libcxx1.cxx b/Tests/NewlineArgs/libcxx1.cxx
new file mode 100644
index 0000000000..72f171d5c5
--- /dev/null
+++ b/Tests/NewlineArgs/libcxx1.cxx
@@ -0,0 +1,10 @@
+#include "libcxx1.h"
+
+#ifdef TEST_FLAG_1
+#ifdef TEST_FLAG_2
+float LibCxx1Class::Method()
+{
+ return 2.0;
+}
+#endif
+#endif
diff --git a/Tests/NewlineArgs/libcxx1.h b/Tests/NewlineArgs/libcxx1.h
new file mode 100644
index 0000000000..ea094d7582
--- /dev/null
+++ b/Tests/NewlineArgs/libcxx1.h
@@ -0,0 +1,9 @@
+class LibCxx1Class
+{
+public:
+#ifdef TEST_FLAG_1
+#ifdef TEST_FLAG_2
+ static float Method();
+#endif
+#endif
+};
diff --git a/Tests/NewlineArgs/libcxx2.h.in b/Tests/NewlineArgs/libcxx2.h.in
new file mode 100644
index 0000000000..bdf9cfa93d
--- /dev/null
+++ b/Tests/NewlineArgs/libcxx2.h.in
@@ -0,0 +1,6 @@
+#ifdef TEST_FLAG_1
+#ifdef TEST_FLAG_2
+#define TEST_FLAG_3
+#endif
+#endif
+
diff --git a/Tests/ObjC++/CMakeLists.txt b/Tests/ObjC++/CMakeLists.txt
new file mode 100644
index 0000000000..8b1563ed85
--- /dev/null
+++ b/Tests/ObjC++/CMakeLists.txt
@@ -0,0 +1,6 @@
+# a simple objc++ test case that uses Cocoa framework
+project (ObjC++)
+
+add_executable (ObjC++ objc++.mm)
+target_link_libraries(ObjC++ "-framework Cocoa")
+
diff --git a/Tests/ObjC++/objc++.mm b/Tests/ObjC++/objc++.mm
new file mode 100644
index 0000000000..258ebaa52f
--- /dev/null
+++ b/Tests/ObjC++/objc++.mm
@@ -0,0 +1,23 @@
+#import <Cocoa/Cocoa.h>
+#import <iostream>
+using namespace std;
+
+int main()
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSMutableSet *mySet = [NSMutableSet set];
+ cout<<"Adding values to the set."<<endl;
+ [mySet addObject:[NSNumber numberWithInt:356]];
+ [mySet addObject:[NSNumber numberWithInt:550]];
+ [mySet addObject:[NSNumber numberWithInt:914]];
+
+ cout<<"The set contains "<<[mySet count]<<" objects."<<endl;
+ if ([mySet containsObject:[NSNumber numberWithInt:911]])
+ cout<<"It's there!"<<endl;
+ else
+ cout<<"It's not there."<<endl;
+
+ [pool release];
+ return 0;
+}
diff --git a/Tests/ObjectLibrary/A/CMakeLists.txt b/Tests/ObjectLibrary/A/CMakeLists.txt
new file mode 100644
index 0000000000..c24c5ed92e
--- /dev/null
+++ b/Tests/ObjectLibrary/A/CMakeLists.txt
@@ -0,0 +1,26 @@
+project(ObjectLibraryA C)
+# Add -fPIC so objects can be used in shared libraries.
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+add_definitions(-DA_DEF)
+
+add_custom_command(
+ OUTPUT a1.c
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/a1.c.in
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/a1.c.in
+ ${CMAKE_CURRENT_BINARY_DIR}/a1.c
+ )
+
+# Remove the custom command output to be sure it runs in an
+# incremental test. Skip this on VS 6 because it sometimes
+# re-runs CMake after the custom command runs.
+if(NOT CMAKE_GENERATOR STREQUAL "Visual Studio 6")
+ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/a.cmake)
+endif()
+add_custom_command(
+ OUTPUT a.cmake
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/a.cmake
+ )
+
+add_library(A OBJECT a1.c a2.c a.cmake)
+target_include_directories(A PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/Tests/ObjectLibrary/A/a.h b/Tests/ObjectLibrary/A/a.h
new file mode 100644
index 0000000000..7259f982ed
--- /dev/null
+++ b/Tests/ObjectLibrary/A/a.h
@@ -0,0 +1,6 @@
+#ifndef A_DEF
+# error "A_DEF not defined"
+#endif
+#ifdef B_DEF
+# error "B_DEF must not be defined"
+#endif
diff --git a/Tests/ObjectLibrary/A/a1.c.in b/Tests/ObjectLibrary/A/a1.c.in
new file mode 100644
index 0000000000..d1eaf58fd0
--- /dev/null
+++ b/Tests/ObjectLibrary/A/a1.c.in
@@ -0,0 +1,2 @@
+#include "a.h"
+int a1(void) { return 0; }
diff --git a/Tests/ObjectLibrary/A/a2.c b/Tests/ObjectLibrary/A/a2.c
new file mode 100644
index 0000000000..d8f225eb7a
--- /dev/null
+++ b/Tests/ObjectLibrary/A/a2.c
@@ -0,0 +1,2 @@
+#include "a.h"
+int a2(void) { return 0; }
diff --git a/Tests/ObjectLibrary/AB.def b/Tests/ObjectLibrary/AB.def
new file mode 100644
index 0000000000..3f2b5c0547
--- /dev/null
+++ b/Tests/ObjectLibrary/AB.def
@@ -0,0 +1,5 @@
+EXPORTS
+a1
+a2
+b1
+b2
diff --git a/Tests/ObjectLibrary/B/CMakeLists.txt b/Tests/ObjectLibrary/B/CMakeLists.txt
new file mode 100644
index 0000000000..215808449e
--- /dev/null
+++ b/Tests/ObjectLibrary/B/CMakeLists.txt
@@ -0,0 +1,17 @@
+project(ObjectLibraryB C)
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+ # VS 6 generator does not use per-target object locations.
+ set(vs6 _vs6)
+endif()
+
+# Add -fPIC so objects can be used in shared libraries.
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+add_library(B OBJECT b1.c b2.c)
+target_include_directories(B PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_compile_definitions(B PUBLIC B_DEF)
+
+add_library(Bexport OBJECT b1${vs6}.c b2${vs6}.c)
+set_property(TARGET Bexport PROPERTY COMPILE_DEFINITIONS Bexport)
+target_include_directories(Bexport PRIVATE $<TARGET_PROPERTY:B,INTERFACE_INCLUDE_DIRECTORIES>)
+target_compile_definitions(Bexport PRIVATE $<TARGET_PROPERTY:B,INTERFACE_COMPILE_DEFINITIONS>)
diff --git a/Tests/ObjectLibrary/B/b.h b/Tests/ObjectLibrary/B/b.h
new file mode 100644
index 0000000000..3489c71052
--- /dev/null
+++ b/Tests/ObjectLibrary/B/b.h
@@ -0,0 +1,18 @@
+#ifdef A_DEF
+# error "A_DEF must not be defined"
+#endif
+#ifndef B_DEF
+# error "B_DEF not defined"
+#endif
+
+#if defined(_WIN32) && defined(Bexport)
+# define EXPORT_B __declspec(dllexport)
+#else
+# define EXPORT_B
+#endif
+
+#if defined(_WIN32) && defined(SHARED_B)
+# define IMPORT_B __declspec(dllimport)
+#else
+# define IMPORT_B
+#endif
diff --git a/Tests/ObjectLibrary/B/b1.c b/Tests/ObjectLibrary/B/b1.c
new file mode 100644
index 0000000000..fdeffe491d
--- /dev/null
+++ b/Tests/ObjectLibrary/B/b1.c
@@ -0,0 +1,2 @@
+#include "b.h"
+EXPORT_B int b1(void) { return 0; }
diff --git a/Tests/ObjectLibrary/B/b1_vs6.c b/Tests/ObjectLibrary/B/b1_vs6.c
new file mode 100644
index 0000000000..b606e10e68
--- /dev/null
+++ b/Tests/ObjectLibrary/B/b1_vs6.c
@@ -0,0 +1 @@
+#include "b1.c"
diff --git a/Tests/ObjectLibrary/B/b2.c b/Tests/ObjectLibrary/B/b2.c
new file mode 100644
index 0000000000..6e0d17cbe0
--- /dev/null
+++ b/Tests/ObjectLibrary/B/b2.c
@@ -0,0 +1,2 @@
+#include "b.h"
+EXPORT_B int b2(void) { return 0; }
diff --git a/Tests/ObjectLibrary/B/b2_vs6.c b/Tests/ObjectLibrary/B/b2_vs6.c
new file mode 100644
index 0000000000..d96a43e04c
--- /dev/null
+++ b/Tests/ObjectLibrary/B/b2_vs6.c
@@ -0,0 +1 @@
+#include "b2.c"
diff --git a/Tests/ObjectLibrary/CMakeLists.txt b/Tests/ObjectLibrary/CMakeLists.txt
new file mode 100644
index 0000000000..e9f553e2be
--- /dev/null
+++ b/Tests/ObjectLibrary/CMakeLists.txt
@@ -0,0 +1,69 @@
+cmake_minimum_required(VERSION 2.8)
+project(ObjectLibrary C)
+
+add_subdirectory(A)
+add_subdirectory(B)
+
+add_library(Cstatic STATIC c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>)
+add_executable(UseCstatic main.c)
+target_link_libraries(UseCstatic Cstatic)
+
+add_library(Cshared SHARED c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:Bexport>)
+add_executable(UseCshared main.c)
+set_property(TARGET UseCshared PROPERTY COMPILE_DEFINITIONS SHARED_C)
+target_link_libraries(UseCshared Cshared)
+add_custom_command(TARGET UseCshared POST_BUILD COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/A/a.cmake)
+
+add_executable(UseCinternal main.c c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>)
+
+if("${CMAKE_GENERATOR}" MATCHES "^Visual Studio (6|7|7 .NET 2003)$")
+ # VS 6 and 7 generators do not add objects as sources so we need a
+ # dummy object to convince the IDE to build the targets below.
+ set(dummy dummy.obj) # In MinGW: gcc -c dummy.c -o dummy.obj
+elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
+ # Xcode does not seem to support targets without sources.
+ set(dummy dummy.c)
+endif()
+
+# Test static library without its own sources.
+add_library(ABstatic STATIC ${dummy} $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>)
+target_include_directories(ABstatic PUBLIC $<TARGET_PROPERTY:B,INTERFACE_INCLUDE_DIRECTORIES>)
+target_compile_definitions(ABstatic PUBLIC $<TARGET_PROPERTY:B,INTERFACE_COMPILE_DEFINITIONS>)
+
+add_executable(UseABstatic mainAB.c)
+target_link_libraries(UseABstatic ABstatic)
+
+# Test module definition file to export object library symbols in the test
+# below if the platform needs and supports it.
+set(ABshared_SRCS $<TARGET_OBJECTS:A>)
+if(CMAKE_LINK_DEF_FILE_FLAG OR NOT WIN32)
+ list(APPEND ABshared_SRCS $<TARGET_OBJECTS:B> AB.def)
+else()
+ set(NO_A NO_A)
+ list(APPEND ABshared_SRCS $<TARGET_OBJECTS:Bexport>)
+endif()
+
+# Test shared library without its own sources.
+add_library(ABshared SHARED ${dummy} ${ABshared_SRCS})
+target_include_directories(ABshared PUBLIC $<TARGET_PROPERTY:B,INTERFACE_INCLUDE_DIRECTORIES>)
+target_compile_definitions(ABshared PUBLIC $<TARGET_PROPERTY:B,INTERFACE_COMPILE_DEFINITIONS>)
+
+add_executable(UseABshared mainAB.c)
+set_property(TARGET UseABshared PROPERTY COMPILE_DEFINITIONS SHARED_B ${NO_A})
+target_link_libraries(UseABshared ABshared)
+
+# Test executable without its own sources.
+add_library(ABmain OBJECT mainAB.c)
+target_include_directories(ABmain PUBLIC $<TARGET_PROPERTY:B,INTERFACE_INCLUDE_DIRECTORIES>)
+target_compile_definitions(ABmain PUBLIC $<TARGET_PROPERTY:B,INTERFACE_COMPILE_DEFINITIONS>)
+add_executable(UseABinternal ${dummy}
+ $<TARGET_OBJECTS:ABmain> $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>
+ )
+
+# Test target-level dependencies of executable without sources.
+file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/UseABinternalDep.cmake)
+add_custom_target(UseABinternalDep COMMAND ${CMAKE_COMMAND} -E touch UseABinternalDep.cmake)
+add_custom_command(TARGET UseABinternal POST_BUILD COMMAND ${CMAKE_COMMAND} -P UseABinternalDep.cmake)
+add_dependencies(UseABinternal UseABinternalDep)
+
+add_subdirectory(ExportLanguages)
diff --git a/Tests/ObjectLibrary/ExportLanguages/CMakeLists.txt b/Tests/ObjectLibrary/ExportLanguages/CMakeLists.txt
new file mode 100644
index 0000000000..22c92a7f3c
--- /dev/null
+++ b/Tests/ObjectLibrary/ExportLanguages/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.8)
+project(ExportLanguages CXX)
+add_library(ExportLanguagesA OBJECT a.cxx)
+add_library(ExportLanguagesB STATIC a.c $<TARGET_OBJECTS:ExportLanguagesA>)
+
+# Verify that object library languages are propagated.
+export(TARGETS ExportLanguagesB NAMESPACE Exp FILE BExport.cmake)
+include(ExternalProject)
+ExternalProject_Add(ExportLanguagesTest
+ SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ExportLanguagesTest"
+ BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ExportLanguagesTest"
+ DOWNLOAD_COMMAND ""
+ INSTALL_COMMAND ""
+)
+add_dependencies(ExportLanguagesTest ExportLanguagesA ExportLanguagesB)
diff --git a/Tests/ObjectLibrary/ExportLanguages/ExportLanguagesTest/CMakeLists.txt b/Tests/ObjectLibrary/ExportLanguages/ExportLanguagesTest/CMakeLists.txt
new file mode 100644
index 0000000000..fc8dd2b78a
--- /dev/null
+++ b/Tests/ObjectLibrary/ExportLanguages/ExportLanguagesTest/CMakeLists.txt
@@ -0,0 +1,14 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(ExportLanguagesTest)
+
+include(${CMAKE_CURRENT_BINARY_DIR}/../BExport.cmake)
+get_property(configs TARGET ExpExportLanguagesB PROPERTY IMPORTED_CONFIGURATIONS)
+foreach(c ${configs})
+ get_property(langs TARGET ExpExportLanguagesB PROPERTY IMPORTED_LINK_INTERFACE_LANGUAGES_${c})
+ list(FIND langs CXX pos)
+ if(${pos} LESS 0)
+ message(FATAL_ERROR "Target export does not list object library languages.")
+ endif()
+endforeach()
diff --git a/Tests/ObjectLibrary/ExportLanguages/a.c b/Tests/ObjectLibrary/ExportLanguages/a.c
new file mode 100644
index 0000000000..af20d3ff65
--- /dev/null
+++ b/Tests/ObjectLibrary/ExportLanguages/a.c
@@ -0,0 +1 @@
+int a(void) { return 0; }
diff --git a/Tests/ObjectLibrary/ExportLanguages/a.cxx b/Tests/ObjectLibrary/ExportLanguages/a.cxx
new file mode 100644
index 0000000000..ae9c87c496
--- /dev/null
+++ b/Tests/ObjectLibrary/ExportLanguages/a.cxx
@@ -0,0 +1 @@
+extern "C" int acxx(void) { return 0; }
diff --git a/Tests/ObjectLibrary/c.c b/Tests/ObjectLibrary/c.c
new file mode 100644
index 0000000000..968095b8b8
--- /dev/null
+++ b/Tests/ObjectLibrary/c.c
@@ -0,0 +1,19 @@
+#if defined(_WIN32) && defined(Cshared_EXPORTS)
+# define EXPORT_C __declspec(dllexport)
+#else
+# define EXPORT_C
+#endif
+
+extern int a1(void);
+extern int a2(void);
+extern int b1(void);
+extern int b2(void);
+EXPORT_C int c(void)
+{
+ return 0
+ + a1()
+ + a2()
+ + b1()
+ + b2()
+ ;
+}
diff --git a/Tests/ObjectLibrary/dummy.c b/Tests/ObjectLibrary/dummy.c
new file mode 100644
index 0000000000..2b17d816d6
--- /dev/null
+++ b/Tests/ObjectLibrary/dummy.c
@@ -0,0 +1 @@
+int dummy(void) {return 0;}
diff --git a/Tests/ObjectLibrary/dummy.obj b/Tests/ObjectLibrary/dummy.obj
new file mode 100644
index 0000000000..77f6f2f1b2
--- /dev/null
+++ b/Tests/ObjectLibrary/dummy.obj
Binary files differ
diff --git a/Tests/ObjectLibrary/main.c b/Tests/ObjectLibrary/main.c
new file mode 100644
index 0000000000..6819f1c6d7
--- /dev/null
+++ b/Tests/ObjectLibrary/main.c
@@ -0,0 +1,16 @@
+#if defined(_WIN32) && defined(SHARED_C)
+# define IMPORT_C __declspec(dllimport)
+#else
+# define IMPORT_C
+#endif
+extern IMPORT_C int b1(void);
+extern IMPORT_C int b2(void);
+extern IMPORT_C int c(void);
+int main(void)
+{
+ return 0
+ + c()
+ + b1()
+ + b2()
+ ;
+}
diff --git a/Tests/ObjectLibrary/mainAB.c b/Tests/ObjectLibrary/mainAB.c
new file mode 100644
index 0000000000..38db20520e
--- /dev/null
+++ b/Tests/ObjectLibrary/mainAB.c
@@ -0,0 +1,20 @@
+
+#include "b.h"
+
+extern IMPORT_B int b1(void);
+extern IMPORT_B int b2(void);
+#ifndef NO_A
+extern int a1(void);
+extern int a2(void);
+#endif
+int main(void)
+{
+ return 0
+#ifndef NO_A
+ + a1()
+ + a2()
+#endif
+ + b1()
+ + b2()
+ ;
+}
diff --git a/Tests/OutDir/CMakeLists.txt b/Tests/OutDir/CMakeLists.txt
new file mode 100644
index 0000000000..88468c3c0b
--- /dev/null
+++ b/Tests/OutDir/CMakeLists.txt
@@ -0,0 +1,35 @@
+cmake_minimum_required(VERSION 2.8)
+project(OutDir C)
+
+if(CMAKE_CONFIGURATION_TYPES)
+ foreach(config ${CMAKE_CONFIGURATION_TYPES})
+ string(TOUPPER "${config}" CONFIG)
+ list(APPEND configs "${CONFIG}")
+ endforeach()
+ set(CMAKE_BUILD_TYPE)
+elseif(NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE Debug)
+endif()
+
+if(CMAKE_BUILD_TYPE)
+ string(TOUPPER "${CMAKE_BUILD_TYPE}" configs)
+endif()
+
+set(top "${OutDir_BINARY_DIR}")
+foreach(config ${configs})
+ foreach(type archive runtime library)
+ string(TOUPPER "${type}" TYPE)
+ set(CMAKE_${TYPE}_OUTPUT_DIRECTORY_${config} "${top}/${type}")
+ file(REMOVE_RECURSE "${top}/${type}")
+ endforeach()
+endforeach()
+
+add_subdirectory(../COnly COnly)
+
+add_custom_command(
+ OUTPUT OutDir.h
+ COMMAND ${CMAKE_COMMAND} -Dtop=${top} -P ${OutDir_SOURCE_DIR}/OutDir.cmake
+ DEPENDS COnly ${OutDir_SOURCE_DIR}/OutDir.cmake
+ )
+include_directories(${top})
+add_executable(OutDir OutDir.c OutDir.h)
diff --git a/Tests/OutDir/OutDir.c b/Tests/OutDir/OutDir.c
new file mode 100644
index 0000000000..53f925926e
--- /dev/null
+++ b/Tests/OutDir/OutDir.c
@@ -0,0 +1,24 @@
+#include <OutDir.h>
+#include <stdio.h>
+
+int main(void)
+{
+ const char* files[] = {TESTC1_LIB, TESTC2_LIB, CONLY_EXE, 0};
+ int result = 0;
+ const char** fname = files;
+ for(;*fname;++fname)
+ {
+ FILE* f = fopen(*fname, "rb");
+ if(f)
+ {
+ printf("found: [%s]\n", *fname);
+ fclose(f);
+ }
+ else
+ {
+ printf("error: [%s]\n", *fname);
+ result = 1;
+ }
+ }
+ return result;
+}
diff --git a/Tests/OutDir/OutDir.cmake b/Tests/OutDir/OutDir.cmake
new file mode 100644
index 0000000000..e1e6b7f931
--- /dev/null
+++ b/Tests/OutDir/OutDir.cmake
@@ -0,0 +1,28 @@
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".a" ".so" ".sl" ".dylib" ".dll.a")
+
+find_library(TESTC1_LIB
+ NAMES testc1 testc1_test_debug_postfix
+ PATHS ${top}/archive
+ NO_DEFAULT_PATH)
+
+find_library(TESTC2_LIB
+ NAMES testc2 testc2_test_debug_postfix
+ PATHS ${top}/archive ${top}/library
+ NO_DEFAULT_PATH)
+
+find_program(CONLY_EXE
+ NAMES COnly
+ PATHS ${top}/runtime
+ NO_DEFAULT_PATH)
+
+file(WRITE ${top}/OutDir.h "/* Generated by ${CMAKE_CURRENT_LIST_FILE} */
+#ifndef OutDir_h
+#define OutDir_h
+
+#define TESTC1_LIB \"${TESTC1_LIB}\"
+#define TESTC2_LIB \"${TESTC2_LIB}\"
+#define CONLY_EXE \"${CONLY_EXE}\"
+
+#endif
+")
diff --git a/Tests/OutOfBinary/CMakeLists.txt b/Tests/OutOfBinary/CMakeLists.txt
new file mode 100644
index 0000000000..e327541436
--- /dev/null
+++ b/Tests/OutOfBinary/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(outlib outlib.c)
+
diff --git a/Tests/OutOfBinary/outlib.c b/Tests/OutOfBinary/outlib.c
new file mode 100644
index 0000000000..9ea579b7ae
--- /dev/null
+++ b/Tests/OutOfBinary/outlib.c
@@ -0,0 +1,2 @@
+int outlib() { return 456; }
+
diff --git a/Tests/OutOfSource/CMakeLists.txt b/Tests/OutOfSource/CMakeLists.txt
new file mode 100644
index 0000000000..de1603a555
--- /dev/null
+++ b/Tests/OutOfSource/CMakeLists.txt
@@ -0,0 +1,18 @@
+# a simple test cas
+cmake_minimum_required (VERSION 2.6)
+project (OutOfSource)
+
+add_subdirectory(SubDir)
+
+get_directory_property(ANIMAL DIRECTORY OutOfSourceSubdir DEFINITION WEASELS)
+get_directory_property(ANIMALREL DIRECTORY SubDir/../OutOfSourceSubdir DEFINITION WEASELS)
+if(NOT "${ANIMAL}" STREQUAL "${ANIMALREL}")
+ message(FATAL_ERROR "GET_DIRECTORY_PROPERTY does not seem to collapse paths.")
+endif()
+
+configure_file(
+ ${OutOfSource_SOURCE_DIR}/testdp.h.in
+ ${OutOfSource_BINARY_DIR}/SubDir/OutOfSourceSubdir/testdp.h
+ )
+
+set(KEN 1)
diff --git a/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt b/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt
new file mode 100644
index 0000000000..10a2f59d1a
--- /dev/null
+++ b/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt
@@ -0,0 +1,62 @@
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+if ("${PROJECT_SOURCE_DIR}" STREQUAL "${ANOTHER_PROJ_SOURCE_DIR}")
+ set(BUILD_SHARED_LIBS 1)
+
+ # Construct a source file outside the tree whose full path is close to
+ # the path length limit. This will cause the full path to the object
+ # file in the build tree to exceed the maximum path length which will
+ # test cmLocalGenerator::CreateSafeUniqueObjectFileName.
+ get_filename_component(DEEPDIR
+ ${OutOfSource_BINARY_DIR}/../OutOfSourceDeep/deeper ABSOLUTE)
+
+ # Test giving the generator a custom limit.
+ set(CMAKE_OBJECT_PATH_MAX 220)
+
+ # Use a separate variable for computation.
+ set(MAXPATH "${CMAKE_OBJECT_PATH_MAX}")
+
+ # VS8 adds "OutOfSource/SubDir/OutOfSourceSubdir/../../../" to the
+ # path of the source file for no good reason. Reduce the length
+ # limit by 46 characters to account for it. It should still be long
+ # enough to require special object file name conversion.
+ if(${CMAKE_GENERATOR} MATCHES "Visual Studio (8|10)")
+ math(EXPR MAXPATH "${MAXPATH} - 46")
+ endif()
+
+ # Ninja imposes a maximum path component count of 30. Permit more
+ # path components in the source path.
+ if(${CMAKE_GENERATOR} MATCHES "Ninja")
+ math(EXPR MAXPATH "${MAXPATH} - 44")
+ endif()
+
+ # MAXPATH less 25 for last /and/deeper/simple.cxx part and small safety
+ math(EXPR MAXPATH "${MAXPATH} - 25")
+ string(LENGTH "${DEEPDIR}" DEEPDIR_LEN)
+ while("${DEEPDIR_LEN}" LESS "${MAXPATH}")
+ set(DEEPDIR ${DEEPDIR}/and/deeper)
+ string(LENGTH "${DEEPDIR}" DEEPDIR_LEN)
+ endwhile()
+ set(DEEPSRC ${DEEPDIR}/simple.cxx)
+ string(LENGTH "${DEEPSRC}" DEEPSRC_LEN)
+ configure_file(simple.cxx.in ${DEEPSRC} COPYONLY)
+
+ # Watcom WMake seems to have problems with long command lines. Just
+ # disable this part of the test until it is resolved.
+ if(${CMAKE_GENERATOR} MATCHES "Watcom WMake")
+ set(DEEPSRC "")
+ add_definitions(-DNO_DEEPSRC)
+ endif()
+
+ add_library(testlib testlib.cxx)
+ add_executable (simple simple.cxx ../simple.cxx ${DEEPSRC})
+ target_link_libraries(simple testlib outlib)
+endif ()
+
+# test getting a definition from a subdir
+set (WEASELS SIZZLING)
+
+get_directory_property(incDirs INCLUDE_DIRECTORIES)
+if(NOT incDirs)
+ message(FATAL_ERROR "get_directory_property(INCLUDE_DIRECTORIES) returned empty list")
+endif()
diff --git a/Tests/OutOfSource/OutOfSourceSubdir/simple.cxx b/Tests/OutOfSource/OutOfSourceSubdir/simple.cxx
new file mode 100644
index 0000000000..d88c311f8e
--- /dev/null
+++ b/Tests/OutOfSource/OutOfSourceSubdir/simple.cxx
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "testlib.h"
+#include "testdp.h"
+
+extern int simple();
+#ifndef NO_DEEPSRC
+extern int simple2();
+#endif
+extern "C" int outlib();
+
+int main ()
+{
+ if(simple() != 123)
+ {
+ return -3;
+ }
+ if (strcmp(animal,"SIZZLING"))
+ {
+ fprintf(stderr,"Get definitions from a subdir did not work\n");
+ return -2;
+ }
+ if(TestLib() != 1.0)
+ {
+ return -1;
+ }
+ if(outlib() != 456)
+ {
+ return -4;
+ }
+#ifndef NO_DEEPSRC
+ if(simple2() != 789)
+ {
+ return -5;
+ }
+#endif
+ return 0;
+}
diff --git a/Tests/OutOfSource/OutOfSourceSubdir/simple.cxx.in b/Tests/OutOfSource/OutOfSourceSubdir/simple.cxx.in
new file mode 100644
index 0000000000..8339b7c6ef
--- /dev/null
+++ b/Tests/OutOfSource/OutOfSourceSubdir/simple.cxx.in
@@ -0,0 +1 @@
+int simple2() { return 789; }
diff --git a/Tests/OutOfSource/OutOfSourceSubdir/testlib.cxx b/Tests/OutOfSource/OutOfSourceSubdir/testlib.cxx
new file mode 100644
index 0000000000..1f78bd3e0e
--- /dev/null
+++ b/Tests/OutOfSource/OutOfSourceSubdir/testlib.cxx
@@ -0,0 +1,6 @@
+#include "testlib.h"
+
+float TestLib()
+{
+ return 1.0;
+}
diff --git a/Tests/OutOfSource/OutOfSourceSubdir/testlib.h b/Tests/OutOfSource/OutOfSourceSubdir/testlib.h
new file mode 100644
index 0000000000..75c2d84fd7
--- /dev/null
+++ b/Tests/OutOfSource/OutOfSourceSubdir/testlib.h
@@ -0,0 +1,11 @@
+#ifdef _WIN32
+# ifdef testlib_EXPORTS
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+# else
+# define CM_TEST_LIB_EXPORT __declspec( dllimport )
+# endif
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+
+CM_TEST_LIB_EXPORT float TestLib();
diff --git a/Tests/OutOfSource/SubDir/CMakeLists.txt b/Tests/OutOfSource/SubDir/CMakeLists.txt
new file mode 100644
index 0000000000..c5df36e1b5
--- /dev/null
+++ b/Tests/OutOfSource/SubDir/CMakeLists.txt
@@ -0,0 +1,8 @@
+project(ANOTHER_PROJ)
+
+# subdir to an out of source and out of binary directory
+add_subdirectory(${OutOfSource_SOURCE_DIR}/../OutOfBinary
+ ${OutOfSource_BINARY_DIR}/../OutOfBinary)
+
+# subdir to a sibling dir
+add_subdirectory(${OutOfSource_SOURCE_DIR}/${KEN}OutOfSourceSubdir OutOfSourceSubdir )
diff --git a/Tests/OutOfSource/simple.cxx b/Tests/OutOfSource/simple.cxx
new file mode 100644
index 0000000000..27e79f4ad4
--- /dev/null
+++ b/Tests/OutOfSource/simple.cxx
@@ -0,0 +1 @@
+int simple() { return 123; }
diff --git a/Tests/OutOfSource/testdp.h.in b/Tests/OutOfSource/testdp.h.in
new file mode 100644
index 0000000000..2ca99d523b
--- /dev/null
+++ b/Tests/OutOfSource/testdp.h.in
@@ -0,0 +1 @@
+char *animal = "${ANIMAL}";
diff --git a/Tests/PDBDirectoryAndName/CMakeLists.txt b/Tests/PDBDirectoryAndName/CMakeLists.txt
new file mode 100644
index 0000000000..90af600fc9
--- /dev/null
+++ b/Tests/PDBDirectoryAndName/CMakeLists.txt
@@ -0,0 +1,92 @@
+cmake_minimum_required(VERSION 2.8)
+project(PDBDirectoryAndName C)
+
+# Make sure the proper compiler is in use.
+if(NOT MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")
+ message(FATAL_ERROR "The PDBDirectoryAndName test works only with MSVC or Intel")
+endif()
+
+# Intel 11.1 does not support /Fd but Intel 14.0 does.
+# TODO: Did a version in between these add it?
+if(CMAKE_C_COMPILER_ID STREQUAL Intel AND
+ CMAKE_C_COMPILER_VERSION VERSION_LESS 14.0)
+ set(NO_COMPILE_PDB 1)
+endif()
+
+set(my_targets "")
+
+add_library(mylibA SHARED mylibA.c)
+set_target_properties(mylibA PROPERTIES
+ PDB_NAME "mylibA_Special"
+ PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibA_PDB"
+)
+list(APPEND my_targets mylibA)
+
+add_library(mylibB STATIC mylibB.c)
+set_target_properties(mylibB PROPERTIES
+ COMPILE_PDB_NAME "mylibB_Special"
+ COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibB_PDB"
+)
+if(NOT NO_COMPILE_PDB)
+ list(APPEND my_targets mylibB)
+endif()
+
+add_library(mylibC SHARED mylibC.c)
+set_target_properties(mylibC PROPERTIES
+ PDB_NAME "mylibC_Special"
+)
+list(APPEND my_targets mylibC)
+
+add_library(mylibD STATIC mylibD.c)
+set_target_properties(mylibD PROPERTIES
+ COMPILE_PDB_NAME "mylibD_Special"
+)
+if(NOT NO_COMPILE_PDB)
+ list(APPEND my_targets mylibD)
+endif()
+
+add_executable(myexe myexe.c)
+set_target_properties(myexe PROPERTIES
+ PDB_NAME "myexe_Special"
+ PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/myexe_PDB"
+)
+list(APPEND my_targets myexe)
+
+target_link_libraries(myexe mylibA mylibB mylibC mylibD)
+
+add_executable(myexe2 myexe2.c)
+set_target_properties(myexe2 PROPERTIES
+ PDB_NAME "myexe2_Special"
+)
+list(APPEND my_targets myexe2)
+
+target_link_libraries(myexe2 mylibA mylibD)
+
+#-----------------------------------------------------------------------------
+# Check that PDB files actually appear where expected.
+
+# The PDB_NAME and PDB_OUTPUT_DIRECTORY options do not work in VS 6.
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+ return()
+endif()
+
+set(pdbs "")
+foreach(t ${my_targets})
+ get_property(pdb_name TARGET ${t} PROPERTY PDB_NAME)
+ get_property(pdb_dir TARGET ${t} PROPERTY PDB_OUTPUT_DIRECTORY)
+ if(NOT pdb_name)
+ get_property(pdb_name TARGET ${t} PROPERTY COMPILE_PDB_NAME)
+ endif()
+ if(NOT pdb_dir)
+ get_property(pdb_dir TARGET ${t} PROPERTY COMPILE_PDB_OUTPUT_DIRECTORY)
+ endif()
+ if(NOT pdb_dir)
+ set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR})
+ endif()
+ list(APPEND pdbs ${pdb_dir}/${CMAKE_CFG_INTDIR}/${pdb_name}.pdb)
+endforeach()
+add_custom_target(check_pdbs ALL VERBATIM
+ COMMAND ${CMAKE_COMMAND} -Dconfig=$<CONFIGURATION> "-Dpdbs=${pdbs}"
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check_pdbs.cmake
+ )
+add_dependencies(check_pdbs ${my_targets})
diff --git a/Tests/PDBDirectoryAndName/check_pdbs.cmake b/Tests/PDBDirectoryAndName/check_pdbs.cmake
new file mode 100644
index 0000000000..89cdb3c72a
--- /dev/null
+++ b/Tests/PDBDirectoryAndName/check_pdbs.cmake
@@ -0,0 +1,10 @@
+if(NOT "${config}" MATCHES "[Dd][Ee][Bb]")
+ return()
+endif()
+foreach(pdb ${pdbs})
+ if(EXISTS "${pdb}")
+ message(STATUS "PDB Exists: ${pdb}")
+ else()
+ message(SEND_ERROR "PDB MISSING: ${pdb}")
+ endif()
+endforeach()
diff --git a/Tests/PDBDirectoryAndName/myexe.c b/Tests/PDBDirectoryAndName/myexe.c
new file mode 100644
index 0000000000..c6d9065fe1
--- /dev/null
+++ b/Tests/PDBDirectoryAndName/myexe.c
@@ -0,0 +1,5 @@
+extern int mylibA();
+extern int mylibB();
+extern int mylibC();
+extern int mylibD();
+int main() { return mylibA() + mylibB() + mylibC() + mylibD(); }
diff --git a/Tests/PDBDirectoryAndName/myexe2.c b/Tests/PDBDirectoryAndName/myexe2.c
new file mode 100644
index 0000000000..75b39cd28b
--- /dev/null
+++ b/Tests/PDBDirectoryAndName/myexe2.c
@@ -0,0 +1,3 @@
+extern int mylibA();
+extern int mylibD();
+int main() { return mylibA() + mylibD(); }
diff --git a/Tests/PDBDirectoryAndName/mylibA.c b/Tests/PDBDirectoryAndName/mylibA.c
new file mode 100644
index 0000000000..f4c553f420
--- /dev/null
+++ b/Tests/PDBDirectoryAndName/mylibA.c
@@ -0,0 +1 @@
+__declspec(dllexport) int mylibA() { return 1; }
diff --git a/Tests/PDBDirectoryAndName/mylibB.c b/Tests/PDBDirectoryAndName/mylibB.c
new file mode 100644
index 0000000000..2040c6795f
--- /dev/null
+++ b/Tests/PDBDirectoryAndName/mylibB.c
@@ -0,0 +1 @@
+int mylibB() { return -1; }
diff --git a/Tests/PDBDirectoryAndName/mylibC.c b/Tests/PDBDirectoryAndName/mylibC.c
new file mode 100644
index 0000000000..adf7c70988
--- /dev/null
+++ b/Tests/PDBDirectoryAndName/mylibC.c
@@ -0,0 +1 @@
+__declspec(dllexport) int mylibC() { return 1; }
diff --git a/Tests/PDBDirectoryAndName/mylibD.c b/Tests/PDBDirectoryAndName/mylibD.c
new file mode 100644
index 0000000000..efa8a82345
--- /dev/null
+++ b/Tests/PDBDirectoryAndName/mylibD.c
@@ -0,0 +1 @@
+int mylibD() { return -1; }
diff --git a/Tests/PerConfig/CMakeLists.txt b/Tests/PerConfig/CMakeLists.txt
new file mode 100644
index 0000000000..7f461b0ecb
--- /dev/null
+++ b/Tests/PerConfig/CMakeLists.txt
@@ -0,0 +1,34 @@
+project(PerConfig C)
+
+# Targets with per-configuration names.
+add_library(pcStatic STATIC pcStatic.c)
+set_property(TARGET pcStatic PROPERTY RELEASE_POSTFIX -opt)
+set_property(TARGET pcStatic PROPERTY DEBUG_POSTFIX -dbg)
+add_library(pcShared SHARED pcShared.c)
+set_property(TARGET pcShared PROPERTY RELEASE_POSTFIX -opt)
+set_property(TARGET pcShared PROPERTY DEBUG_POSTFIX -dbg)
+set_property(TARGET pcShared PROPERTY VERSION 1.2)
+set_property(TARGET pcShared PROPERTY SOVERSION 3)
+if(UNIX AND NOT CYGWIN)
+ set(soname_file -DpcShared_soname_file=$<TARGET_SONAME_FILE:pcShared>)
+endif()
+add_executable(perconfig perconfig.c)
+target_link_libraries(perconfig pcStatic pcShared)
+set_property(TARGET perconfig PROPERTY RELEASE_POSTFIX -opt)
+set_property(TARGET perconfig PROPERTY DEBUG_POSTFIX -dbg)
+
+set(PerConfig_COMMAND
+ ${CMAKE_COMMAND}
+ -Dconfiguration=$<CONFIGURATION>
+ -Dperconfig_file_dir=$<TARGET_FILE_DIR:perconfig>
+ -Dperconfig_file_name=$<TARGET_FILE_NAME:perconfig>
+ -Dperconfig_file=$<TARGET_FILE:perconfig>
+ -DpcStatic_file=$<TARGET_FILE:pcStatic>
+ -DpcStatic_linker_file=$<TARGET_LINKER_FILE:pcStatic>
+ -DpcShared_file=$<TARGET_FILE:pcShared>
+ -DpcShared_linker_file=$<TARGET_LINKER_FILE:pcShared>
+ ${soname_file}
+ -P ${PerConfig_SOURCE_DIR}/perconfig.cmake
+ )
+set(PerConfig_COMMAND "${PerConfig_COMMAND}" PARENT_SCOPE)
+set(PerConfig_DEPENDS ${PerConfig_SOURCE_DIR}/perconfig.cmake perconfig pcStatic pcShared)
diff --git a/Tests/PerConfig/pcShared.c b/Tests/PerConfig/pcShared.c
new file mode 100644
index 0000000000..b08fadc948
--- /dev/null
+++ b/Tests/PerConfig/pcShared.c
@@ -0,0 +1,5 @@
+#include "pcShared.h"
+const char* pcShared(void)
+{
+ return "INFO:symbol[pcShared]";
+}
diff --git a/Tests/PerConfig/pcShared.h b/Tests/PerConfig/pcShared.h
new file mode 100644
index 0000000000..59a6ef43bc
--- /dev/null
+++ b/Tests/PerConfig/pcShared.h
@@ -0,0 +1,16 @@
+#ifndef pcShared_h
+#define pcShared_h
+
+#ifdef _WIN32
+# ifdef pcShared_EXPORTS
+# define PC_EXPORT __declspec(dllexport)
+# else
+# define PC_EXPORT __declspec(dllimport)
+# endif
+#else
+# define PC_EXPORT
+#endif
+
+PC_EXPORT const char* pcShared(void);
+
+#endif
diff --git a/Tests/PerConfig/pcStatic.c b/Tests/PerConfig/pcStatic.c
new file mode 100644
index 0000000000..7e1bf512d0
--- /dev/null
+++ b/Tests/PerConfig/pcStatic.c
@@ -0,0 +1,4 @@
+const char* pcStatic(void)
+{
+ return "INFO:symbol[pcStatic]";
+}
diff --git a/Tests/PerConfig/perconfig.c b/Tests/PerConfig/perconfig.c
new file mode 100644
index 0000000000..d942d4562c
--- /dev/null
+++ b/Tests/PerConfig/perconfig.c
@@ -0,0 +1,8 @@
+#include "pcShared.h"
+extern const char* pcStatic(void);
+int main()
+{
+ pcStatic();
+ pcShared();
+ return 0;
+}
diff --git a/Tests/PerConfig/perconfig.cmake b/Tests/PerConfig/perconfig.cmake
new file mode 100644
index 0000000000..5286307a09
--- /dev/null
+++ b/Tests/PerConfig/perconfig.cmake
@@ -0,0 +1,40 @@
+# Print values for human reference.
+foreach(v
+ configuration
+ perconfig_file_dir
+ perconfig_file_name
+ perconfig_file
+ pcStatic_file
+ pcStatic_linker_file
+ pcShared_file
+ pcShared_linker_file
+ pcShared_soname_file
+ )
+ message(STATUS "${v}=${${v}}")
+endforeach()
+
+# Verify that file names match as expected.
+set(pc_file_components ${perconfig_file_dir}/${perconfig_file_name})
+if(NOT "${pc_file_components}" STREQUAL "${perconfig_file}")
+ message(SEND_ERROR
+ "File components ${pc_file_components} do not match ${perconfig_file}")
+endif()
+if(NOT "${pcStatic_file}" STREQUAL "${pcStatic_linker_file}")
+ message(SEND_ERROR
+ "pcStatic_file does not match pcStatic_linker_file:\n"
+ " ${pcStatic_file}\n"
+ " ${pcStatic_linker_file}\n"
+ )
+endif()
+
+# Verify that the implementation files are named correctly.
+foreach(lib pcStatic pcShared)
+ file(STRINGS "${${lib}_file}" info LIMIT_COUNT 1 REGEX "INFO:[A-Za-z0-9_]+\\[[^]]*\\]")
+ if(NOT "${info}" MATCHES "INFO:symbol\\[${lib}\\]")
+ message(SEND_ERROR "No INFO:symbol[${lib}] found in:\n ${${lib}_file}")
+ endif()
+endforeach()
+execute_process(COMMAND ${perconfig_file} RESULT_VARIABLE result)
+if(result)
+ message(SEND_ERROR "Error running:\n ${perconfig_file}\n(${result})")
+endif()
diff --git a/Tests/Plugin/CMakeLists.txt b/Tests/Plugin/CMakeLists.txt
new file mode 100644
index 0000000000..ecdece8b50
--- /dev/null
+++ b/Tests/Plugin/CMakeLists.txt
@@ -0,0 +1,76 @@
+cmake_minimum_required (VERSION 2.6)
+project(Plugin)
+
+# Test per-target output directory properties.
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/bin)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/plugin)
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/static)
+
+# We need the dynamic loader support from KWSys to load the plugin in
+# the executable.
+set(KWSYS_NAMESPACE kwsys)
+set(KWSYS_HEADER_ROOT ${Plugin_BINARY_DIR}/include)
+set(KWSYS_USE_DynamicLoader 1)
+add_subdirectory(${Plugin_SOURCE_DIR}/../../Source/kwsys src/kwsys)
+
+# Configure the location of plugins.
+configure_file(${Plugin_SOURCE_DIR}/src/example_exe.h.in
+ ${Plugin_BINARY_DIR}/include/example_exe.h @ONLY)
+
+# We need to include headers from the source tree and configured
+# headers in the build tree.
+include_directories(
+ ${Plugin_BINARY_DIR}/include
+ ${Plugin_SOURCE_DIR}/include
+ )
+
+# We need proper C++98 support from the compiler
+set(CMAKE_CXX_STANDARD 98)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+ CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
+
+# Create an executable that exports an API for use by plugins.
+add_executable(example_exe src/example_exe.cxx)
+set_target_properties(example_exe PROPERTIES
+ ENABLE_EXPORTS 1
+ OUTPUT_NAME example
+ # Test placing exe import library in unique directory.
+ ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/exe
+ )
+target_link_libraries(example_exe kwsys)
+
+# Create a plugin that uses the API provided by the executable.
+# This module "links" to the executable to use the symbols.
+add_library(example_mod_1 MODULE src/example_mod_1.c)
+target_link_libraries(example_mod_1 example_exe)
+
+
+if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND
+ "${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG")
+ # Add a second plugin that should not have any soname.
+ add_library(example_mod_2 MODULE src/example_mod_1.c)
+ target_link_libraries(example_mod_2 example_exe)
+ set_property(TARGET example_mod_2 PROPERTY NO_SONAME 1)
+
+ # Verify that targets export with proper IMPORTED SONAME properties.
+ export(TARGETS example_mod_1 example_mod_2 NAMESPACE exp_
+ FILE ${CMAKE_CURRENT_BINARY_DIR}/mods.cmake)
+
+ include(ExternalProject)
+ ExternalProject_Add(PluginTest
+ SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PluginTest"
+ BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/PluginTest"
+ DOWNLOAD_COMMAND ""
+ INSTALL_COMMAND ""
+ )
+ add_dependencies(PluginTest example_mod_1 example_mod_2)
+endif()
+
+# TODO:
+# - create a plugin that links to a static lib
+# - create a plugin that links to a shared lib
diff --git a/Tests/Plugin/PluginTest/CMakeLists.txt b/Tests/Plugin/PluginTest/CMakeLists.txt
new file mode 100644
index 0000000000..79ef8a9502
--- /dev/null
+++ b/Tests/Plugin/PluginTest/CMakeLists.txt
@@ -0,0 +1,34 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(PluginTest)
+
+include(${CMAKE_CURRENT_BINARY_DIR}/../mods.cmake)
+get_property(configs TARGET exp_example_mod_1 PROPERTY IMPORTED_CONFIGURATIONS)
+foreach(c ${configs})
+ string(TOUPPER "${c}" CONFIG)
+ get_property(soname1 TARGET exp_example_mod_1 PROPERTY IMPORTED_SONAME_${CONFIG})
+ get_property(soname2 TARGET exp_example_mod_2 PROPERTY IMPORTED_NO_SONAME_${CONFIG})
+ if(soname1)
+ message(STATUS "exp_example_mod_1 has IMPORTED_SONAME_${CONFIG} as expected: ${soname1}")
+ else()
+ message(SEND_ERROR "exp_example_mod_1 does not have IMPORTED_SONAME_${CONFIG} but should")
+ endif()
+ if(soname2)
+ message(STATUS "exp_example_mod_2 has IMPORTED_NO_SONAME_${CONFIG} as expected: ${soname2}")
+ else()
+ message(SEND_ERROR "exp_example_mod_2 does not have IMPORTED_NO_SONAME_${CONFIG} but should")
+ endif()
+endforeach()
+
+# Parse the binary to check for SONAME if possible.
+if("${CMAKE_EXECUTABLE_FORMAT}" MATCHES "ELF")
+ find_program(READELF_EXE readelf)
+ if(READELF_EXE)
+ add_custom_target(check_mod_soname ALL COMMAND
+ ${CMAKE_COMMAND} -Dreadelf=${READELF_EXE}
+ -Dmod1=$<TARGET_FILE:exp_example_mod_1>
+ -Dmod2=$<TARGET_FILE:exp_example_mod_2>
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/../check_mod_soname.cmake
+ )
+ endif()
+endif()
diff --git a/Tests/Plugin/check_mod_soname.cmake b/Tests/Plugin/check_mod_soname.cmake
new file mode 100644
index 0000000000..3737b450d8
--- /dev/null
+++ b/Tests/Plugin/check_mod_soname.cmake
@@ -0,0 +1,14 @@
+execute_process(COMMAND ${readelf} -d ${mod1} OUTPUT_FILE ${mod1}.readelf.txt)
+execute_process(COMMAND ${readelf} -d ${mod2} OUTPUT_FILE ${mod2}.readelf.txt)
+file(STRINGS ${mod1}.readelf.txt soname1 REGEX "\\(SONAME\\)")
+file(STRINGS ${mod2}.readelf.txt soname2 REGEX "\\(SONAME\\)")
+if(soname1)
+ message(STATUS "${mod1} has soname as expected: ${soname1}")
+else()
+ message(FATAL_ERROR "${mod1} has no soname but should:\n ${soname1}")
+endif()
+if(soname2)
+ message(FATAL_ERROR "${mod2} has soname but should not:\n ${soname2}")
+else()
+ message(STATUS "${mod2} has no soname as expected")
+endif()
diff --git a/Tests/Plugin/include/example.h b/Tests/Plugin/include/example.h
new file mode 100644
index 0000000000..1d7e8c0150
--- /dev/null
+++ b/Tests/Plugin/include/example.h
@@ -0,0 +1,25 @@
+#ifndef example_h
+#define example_h
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+# if defined(example_exe_EXPORTS)
+# define EXAMPLE_EXPORT __declspec(dllexport)
+# else
+# define EXAMPLE_EXPORT __declspec(dllimport)
+# endif
+#else
+# define EXAMPLE_EXPORT
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+EXAMPLE_EXPORT int example_exe_function(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/Tests/Plugin/src/example_exe.cxx b/Tests/Plugin/src/example_exe.cxx
new file mode 100644
index 0000000000..309302e581
--- /dev/null
+++ b/Tests/Plugin/src/example_exe.cxx
@@ -0,0 +1,60 @@
+#include <example.h>
+
+#include <example_exe.h>
+
+#include <kwsys/DynamicLoader.hxx>
+#include <kwsys/ios/iostream>
+#include <kwsys/stl/string>
+
+#include <stdio.h>
+
+// Implement the ABI used by plugins.
+extern "C" int example_exe_function()
+{
+ kwsys_ios::cout << "hello" << kwsys_ios::endl;
+ return 123;
+}
+
+#ifdef CMAKE_INTDIR
+# define CONFIG_DIR "/" CMAKE_INTDIR
+#else
+# define CONFIG_DIR ""
+#endif
+
+int main()
+{
+ kwsys_stl::string libName = EXAMPLE_EXE_PLUGIN_DIR CONFIG_DIR "/";
+ libName += kwsys::DynamicLoader::LibPrefix();
+ libName += "example_mod_1";
+ libName += kwsys::DynamicLoader::LibExtension();
+ kwsys::DynamicLoader::LibraryHandle handle =
+ kwsys::DynamicLoader::OpenLibrary(libName.c_str());
+ if(!handle)
+ {
+ kwsys_ios::cerr << "Could not open plugin \""
+ << libName << "\"!" << kwsys_ios::endl;
+ return 1;
+ }
+ kwsys::DynamicLoader::SymbolPointer sym =
+ kwsys::DynamicLoader::GetSymbolAddress(handle, "example_mod_1_function");
+ if(!sym)
+ {
+ kwsys_ios::cerr
+ << "Could not get plugin symbol \"example_mod_1_function\"!"
+ << kwsys_ios::endl;
+ return 1;
+ }
+#ifdef __WATCOMC__
+ int(__cdecl *f)(int) = (int(__cdecl *)(int))(sym);
+#else
+ int(*f)(int) = reinterpret_cast<int(*)(int)>(sym);
+#endif
+ if(f(456) != (123+456))
+ {
+ kwsys_ios::cerr << "Incorrect return value from plugin!"
+ << kwsys_ios::endl;
+ return 1;
+ }
+ kwsys::DynamicLoader::CloseLibrary(handle);
+ return 0;
+}
diff --git a/Tests/Plugin/src/example_exe.h.in b/Tests/Plugin/src/example_exe.h.in
new file mode 100644
index 0000000000..62f0d9f02b
--- /dev/null
+++ b/Tests/Plugin/src/example_exe.h.in
@@ -0,0 +1,6 @@
+#ifndef example_exe_h
+#define example_exe_h
+
+#define EXAMPLE_EXE_PLUGIN_DIR "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@"
+
+#endif
diff --git a/Tests/Plugin/src/example_mod_1.c b/Tests/Plugin/src/example_mod_1.c
new file mode 100644
index 0000000000..1fc7338451
--- /dev/null
+++ b/Tests/Plugin/src/example_mod_1.c
@@ -0,0 +1,22 @@
+#include <example.h>
+
+#include <stdio.h>
+
+#if defined(_WIN32)
+# define MODULE_EXPORT __declspec(dllexport)
+#else
+# define MODULE_EXPORT
+#endif
+
+#ifdef __WATCOMC__
+# define MODULE_CCONV __cdecl
+#else
+# define MODULE_CCONV
+#endif
+
+MODULE_EXPORT int MODULE_CCONV example_mod_1_function(int n)
+{
+ int result = example_exe_function() + n;
+ printf("world\n");
+ return result;
+}
diff --git a/Tests/Policy0002/A/CMakeLists.txt b/Tests/Policy0002/A/CMakeLists.txt
new file mode 100644
index 0000000000..cee6422a9a
--- /dev/null
+++ b/Tests/Policy0002/A/CMakeLists.txt
@@ -0,0 +1 @@
+add_executable(Policy0002 ../policy0002.c)
diff --git a/Tests/Policy0002/CMakeLists.txt b/Tests/Policy0002/CMakeLists.txt
new file mode 100644
index 0000000000..0f6d3319a7
--- /dev/null
+++ b/Tests/Policy0002/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.6)
+project(Policy0002 C)
+cmake_policy(SET CMP0002 OLD)
+add_subdirectory(A)
+add_executable(Policy0002 policy0002.c)
diff --git a/Tests/Policy0002/policy0002.c b/Tests/Policy0002/policy0002.c
new file mode 100644
index 0000000000..8488f4e58f
--- /dev/null
+++ b/Tests/Policy0002/policy0002.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/PolicyScope/Bar.cmake b/Tests/PolicyScope/Bar.cmake
new file mode 100644
index 0000000000..cf1904c48a
--- /dev/null
+++ b/Tests/PolicyScope/Bar.cmake
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 2.6.3)
+
+# Make sure a policy set differently by our includer is now correct.
+cmake_policy(GET CMP0003 cmp)
+check(CMP0003 "NEW" "${cmp}")
+
+# Test allowing the top-level file to not have cmake_minimum_required.
+cmake_policy(SET CMP0000 OLD)
diff --git a/Tests/PolicyScope/CMakeLists.txt b/Tests/PolicyScope/CMakeLists.txt
new file mode 100644
index 0000000000..413195a5c6
--- /dev/null
+++ b/Tests/PolicyScope/CMakeLists.txt
@@ -0,0 +1,104 @@
+project(PolicyScope C)
+# No cmake_minimum_required(VERSION), it's in FindFoo.
+
+#-----------------------------------------------------------------------------
+# Helper function to report results.
+function(check msg lhs rhs)
+ if(NOT "${lhs}" STREQUAL "${rhs}")
+ message(FATAL_ERROR "${msg}: expected [${lhs}], got [${rhs}]")
+ endif()
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Test using a development framework that sets policies for us.
+
+# Policy CMP0011 should not be set at this point.
+cmake_policy(GET CMP0011 cmp)
+check(CMP0011 "" "${cmp}")
+
+# Put the test modules in the search path.
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
+
+# The included file should set policies for us.
+find_package(Foo)
+
+# Check policies set by the package.
+cmake_policy(GET CMP0003 cmp)
+check(CMP0003 "OLD" "${cmp}")
+cmake_policy(GET CMP0002 cmp)
+check(CMP0002 "NEW" "${cmp}")
+cmake_policy(GET CMP0011 cmp)
+check(CMP0011 "NEW" "${cmp}")
+
+# Make sure an included file cannot change policies.
+include(Bar)
+cmake_policy(GET CMP0003 cmp)
+check(CMP0003 "OLD" "${cmp}")
+
+# Allow the included file to change policies.
+include(Bar NO_POLICY_SCOPE)
+cmake_policy(GET CMP0003 cmp)
+check(CMP0003 "NEW" "${cmp}")
+
+#-----------------------------------------------------------------------------
+# Test function and macro policy recording.
+
+# Create the functions in an isolated scope in which we change policies.
+cmake_policy(PUSH)
+if(1)
+ # Change CMP0002
+ cmake_policy(SET CMP0002 OLD)
+ function(func1)
+ # CMP0002 should be changed when this function is invoked
+ cmake_policy(GET CMP0002 cmp)
+ check(CMP0002 "OLD" "${cmp}")
+ endfunction()
+
+ # Unset CMP0002
+ cmake_policy(VERSION 2.4)
+ macro(macro1)
+ # CMP0002 should be unset when this macro is invoked
+ cmake_policy(GET CMP0002 cmp)
+ check(CMP0002 "" "${cmp}")
+
+ # Setting the policy should work here and also in the caller.
+ cmake_policy(SET CMP0002 OLD)
+ cmake_policy(GET CMP0002 cmp)
+ check(CMP0002 "OLD" "${cmp}")
+ endmacro()
+endif()
+cmake_policy(POP)
+
+# CMP0002 should still be NEW in this context.
+cmake_policy(GET CMP0002 cmp)
+check(CMP0002 "NEW" "${cmp}")
+
+# Check the recorded policies
+func1()
+macro1()
+
+# The macro should have changed CMP0002.
+cmake_policy(GET CMP0002 cmp)
+check(CMP0002 "OLD" "${cmp}")
+
+#-----------------------------------------------------------------------------
+# Test CMAKE_POLICY_DEFAULT_CMP<NNNN> variable.
+cmake_policy(PUSH)
+ set(CMAKE_POLICY_DEFAULT_CMP0010 OLD) # ignored
+ set(CMAKE_POLICY_DEFAULT_CMP0012 OLD) # honored
+ set(CMAKE_POLICY_DEFAULT_CMP0013 NEW) # honored
+ set(CMAKE_POLICY_DEFAULT_CMP0014 "") # noop
+ cmake_policy(VERSION 2.6.3)
+ cmake_policy(GET CMP0010 cmp)
+ check(CMP0010 "NEW" "${cmp}")
+ cmake_policy(GET CMP0012 cmp)
+ check(CMP0012 "OLD" "${cmp}")
+ cmake_policy(GET CMP0013 cmp)
+ check(CMP0013 "NEW" "${cmp}")
+ cmake_policy(GET CMP0014 cmp)
+ check(CMP0014 "" "${cmp}")
+cmake_policy(POP)
+
+#-----------------------------------------------------------------------------
+# Dummy executable so the project can build and run.
+add_executable(PolicyScope main.c)
diff --git a/Tests/PolicyScope/FindFoo.cmake b/Tests/PolicyScope/FindFoo.cmake
new file mode 100644
index 0000000000..5b441e20ec
--- /dev/null
+++ b/Tests/PolicyScope/FindFoo.cmake
@@ -0,0 +1,2 @@
+cmake_minimum_required(VERSION 2.6.3)
+cmake_policy(SET CMP0003 OLD)
diff --git a/Tests/PolicyScope/main.c b/Tests/PolicyScope/main.c
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/PolicyScope/main.c
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/PositionIndependentTargets/CMakeLists.txt b/Tests/PositionIndependentTargets/CMakeLists.txt
new file mode 100644
index 0000000000..e79f3b74b7
--- /dev/null
+++ b/Tests/PositionIndependentTargets/CMakeLists.txt
@@ -0,0 +1,14 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(PositionIndependentTargets)
+
+include(CheckCXXSourceCompiles)
+
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}") # For pic_test.h
+
+add_subdirectory(global)
+add_subdirectory(targets)
+add_subdirectory(interface)
+
+add_executable(PositionIndependentTargets main.cpp)
diff --git a/Tests/PositionIndependentTargets/global/CMakeLists.txt b/Tests/PositionIndependentTargets/global/CMakeLists.txt
new file mode 100644
index 0000000000..1d662f8ea2
--- /dev/null
+++ b/Tests/PositionIndependentTargets/global/CMakeLists.txt
@@ -0,0 +1,37 @@
+
+set(CMAKE_POSITION_INDEPENDENT_CODE True)
+
+add_executable(test_target_executable_global
+ "${CMAKE_CURRENT_SOURCE_DIR}/../pic_main.cpp"
+)
+
+add_library(test_target_shared_library_global
+ SHARED "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp"
+)
+set_target_properties(test_target_shared_library_global
+ PROPERTIES DEFINE_SYMBOL PIC_TEST_BUILD_DLL
+)
+
+add_library(test_target_static_library_global
+ STATIC "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp"
+)
+set_target_properties(test_target_static_library_global
+ PROPERTIES COMPILE_DEFINITIONS PIC_TEST_STATIC_BUILD
+)
+
+
+file(READ
+ "${CMAKE_CURRENT_SOURCE_DIR}/../pic_test.h"
+ PIC_HEADER_CONTENT
+)
+
+check_cxx_source_compiles(
+ "
+${PIC_HEADER_CONTENT}
+int main(int,char**) { return 0; }\n"
+ PIC_TRY_COMPILE_RESULT
+)
+
+if (NOT PIC_TRY_COMPILE_RESULT)
+ message(SEND_ERROR "TRY_COMPILE with content requiring __PIC__ failed. ${OUTPUT}")
+endif()
diff --git a/Tests/PositionIndependentTargets/interface/CMakeLists.txt b/Tests/PositionIndependentTargets/interface/CMakeLists.txt
new file mode 100644
index 0000000000..65f3b767ed
--- /dev/null
+++ b/Tests/PositionIndependentTargets/interface/CMakeLists.txt
@@ -0,0 +1,27 @@
+
+add_library(piciface INTERFACE)
+set_property(TARGET piciface PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+add_executable(test_empty_iface "${CMAKE_CURRENT_SOURCE_DIR}/../pic_main.cpp")
+target_link_libraries(test_empty_iface piciface)
+
+add_library(sharedlib SHARED "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp")
+target_link_libraries(sharedlib piciface)
+set_property(TARGET sharedlib PROPERTY DEFINE_SYMBOL PIC_TEST_BUILD_DLL)
+
+add_executable(test_iface_via_shared "${CMAKE_CURRENT_SOURCE_DIR}/../pic_main.cpp")
+target_link_libraries(test_iface_via_shared sharedlib)
+
+add_library(sharedlibpic SHARED "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp")
+set_property(TARGET sharedlibpic PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+set_property(TARGET sharedlibpic PROPERTY DEFINE_SYMBOL PIC_TEST_BUILD_DLL)
+
+add_library(shared_iface INTERFACE)
+target_link_libraries(shared_iface INTERFACE sharedlibpic)
+
+add_executable(test_shared_via_iface "${CMAKE_CURRENT_SOURCE_DIR}/../pic_main.cpp")
+target_link_libraries(test_shared_via_iface shared_iface)
+
+add_executable(test_shared_via_iface_non_conflict "${CMAKE_CURRENT_SOURCE_DIR}/../pic_main.cpp")
+set_property(TARGET test_shared_via_iface_non_conflict PROPERTY POSITION_INDEPENDENT_CODE ON)
+target_link_libraries(test_shared_via_iface_non_conflict shared_iface)
diff --git a/Tests/PositionIndependentTargets/main.cpp b/Tests/PositionIndependentTargets/main.cpp
new file mode 100644
index 0000000000..e72cef7eb1
--- /dev/null
+++ b/Tests/PositionIndependentTargets/main.cpp
@@ -0,0 +1,2 @@
+
+int main(int,char**) { return 0; }
diff --git a/Tests/PositionIndependentTargets/pic_lib.cpp b/Tests/PositionIndependentTargets/pic_lib.cpp
new file mode 100644
index 0000000000..b8b25a33ef
--- /dev/null
+++ b/Tests/PositionIndependentTargets/pic_lib.cpp
@@ -0,0 +1,12 @@
+
+#include "pic_test.h"
+
+class PIC_TEST_EXPORT Dummy
+{
+ int dummy();
+};
+
+int Dummy::dummy()
+{
+ return 0;
+}
diff --git a/Tests/PositionIndependentTargets/pic_main.cpp b/Tests/PositionIndependentTargets/pic_main.cpp
new file mode 100644
index 0000000000..6a41a7a6b5
--- /dev/null
+++ b/Tests/PositionIndependentTargets/pic_main.cpp
@@ -0,0 +1,4 @@
+
+#include "pic_test.h"
+
+int main(int,char**) { return 0; }
diff --git a/Tests/PositionIndependentTargets/pic_test.h b/Tests/PositionIndependentTargets/pic_test.h
new file mode 100644
index 0000000000..13cf8f79f1
--- /dev/null
+++ b/Tests/PositionIndependentTargets/pic_test.h
@@ -0,0 +1,20 @@
+
+#if defined(__ELF__)
+# if !defined(__PIC__) && !defined(__PIE__)
+# error "The POSITION_INDEPENDENT_CODE property should cause __PIC__ or __PIE__ to be defined on ELF platforms."
+# endif
+#endif
+
+#if defined(PIC_TEST_STATIC_BUILD)
+# define PIC_TEST_EXPORT
+#else
+# if defined(_WIN32) || defined(WIN32) /* Win32 version */
+# ifdef PIC_TEST_BUILD_DLL
+# define PIC_TEST_EXPORT __declspec(dllexport)
+# else
+# define PIC_TEST_EXPORT __declspec(dllimport)
+# endif
+# else
+# define PIC_TEST_EXPORT
+# endif
+#endif
diff --git a/Tests/PositionIndependentTargets/targets/CMakeLists.txt b/Tests/PositionIndependentTargets/targets/CMakeLists.txt
new file mode 100644
index 0000000000..4724c854a9
--- /dev/null
+++ b/Tests/PositionIndependentTargets/targets/CMakeLists.txt
@@ -0,0 +1,20 @@
+
+add_executable(test_target_executable_properties "${CMAKE_CURRENT_SOURCE_DIR}/../pic_main.cpp")
+set_target_properties(test_target_executable_properties
+ PROPERTIES
+ POSITION_INDEPENDENT_CODE True
+)
+
+add_library(test_target_shared_library_properties SHARED "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp")
+set_target_properties(test_target_shared_library_properties
+ PROPERTIES
+ POSITION_INDEPENDENT_CODE True
+ DEFINE_SYMBOL PIC_TEST_BUILD_DLL
+)
+
+add_library(test_target_static_library_properties STATIC "${CMAKE_CURRENT_SOURCE_DIR}/../pic_lib.cpp")
+set_target_properties(test_target_static_library_properties
+ PROPERTIES
+ POSITION_INDEPENDENT_CODE True
+ COMPILE_DEFINITIONS PIC_TEST_STATIC_BUILD
+)
diff --git a/Tests/PreOrder/CMakeLists.txt b/Tests/PreOrder/CMakeLists.txt
new file mode 100644
index 0000000000..8b4c43954b
--- /dev/null
+++ b/Tests/PreOrder/CMakeLists.txt
@@ -0,0 +1,6 @@
+# a simple test case
+project (PreOrder)
+set(CMAKE_IGNORE_DEPENDENCIES_ORDERING 1)
+add_subdirectory(Library)
+add_executable (PreOrder simple.cxx)
+target_link_libraries(PreOrder simpleLib)
diff --git a/Tests/PreOrder/Library/CMakeLists.txt b/Tests/PreOrder/Library/CMakeLists.txt
new file mode 100644
index 0000000000..018ffa5e25
--- /dev/null
+++ b/Tests/PreOrder/Library/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(simpleLib simpleLib.cxx )
+
diff --git a/Tests/PreOrder/Library/simpleLib.cxx b/Tests/PreOrder/Library/simpleLib.cxx
new file mode 100644
index 0000000000..281d8885a8
--- /dev/null
+++ b/Tests/PreOrder/Library/simpleLib.cxx
@@ -0,0 +1,3 @@
+void simpleLib()
+{
+}
diff --git a/Tests/PreOrder/simple.cxx b/Tests/PreOrder/simple.cxx
new file mode 100644
index 0000000000..ef26e7984e
--- /dev/null
+++ b/Tests/PreOrder/simple.cxx
@@ -0,0 +1,6 @@
+extern void simpleLib();
+int main ()
+{
+ simpleLib();
+ return 0;
+}
diff --git a/Tests/PrecompiledHeader/CMakeLists.txt b/Tests/PrecompiledHeader/CMakeLists.txt
new file mode 100644
index 0000000000..6958131bf5
--- /dev/null
+++ b/Tests/PrecompiledHeader/CMakeLists.txt
@@ -0,0 +1,59 @@
+cmake_minimum_required (VERSION 2.6)
+project(PrecompiledHeader C)
+
+# Make sure the proper compiler is in use.
+if(NOT MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")
+ message(FATAL_ERROR "The PrecompiledHeader test works only with MSVC or Intel")
+endif()
+
+# Compute a custom name for the precompiled header.
+if(CMAKE_CONFIGURATION_TYPES)
+ set(PCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/PCH/${CMAKE_CFG_INTDIR}")
+ foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/PCH/${cfg})
+ endforeach()
+else()
+ set(PCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/PCH")
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/PCH)
+endif()
+
+# The VS6 IDE does not support renaming .pch files with /Fp.
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+ set(PCH_USE_INCLUDE_DIR 1)
+ set(PCH_FILE)
+else()
+ set(PCH_USE_INCLUDE_DIR 0)
+ set(PCH_FILE "\"/Fp${PCH_DIR}/foo_precompiled.pch\"")
+endif()
+
+# Choose between an explicit include path and using /I during
+# precompilation. The /I form is used to test that the PCH is
+# actually used. In practice the include path form would be used.
+if(PCH_USE_INCLUDE_DIR)
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
+else()
+ set(PCH_INCLUDE_DIR "\"/I${CMAKE_CURRENT_SOURCE_DIR}/include\"")
+endif()
+
+# Create a target that will use a precompiled header.
+set(foo_SRCS foo1.c foo2.c)
+add_executable(foo foo_precompile.c ${foo_SRCS})
+
+# Setup flags on the target to create and use the precompiled header.
+set_target_properties(foo PROPERTIES
+ COMPILE_FLAGS "/Yufoo_precompiled.h /FIfoo_precompiled.h ${PCH_FILE}")
+set_source_files_properties(foo_precompile.c PROPERTIES
+ COMPILE_FLAGS "/Ycfoo_precompiled.h ${PCH_INCLUDE_DIR}")
+
+# Setup dependencies for precompiled header creation and use. The VS
+# IDE takes care of this automatically.
+if("${CMAKE_GENERATOR}" MATCHES "Makefile" OR
+ "${CMAKE_GENERATOR}" MATCHES "Ninja")
+ # This source file creates the precompiled header as a side-effect.
+ set_source_files_properties(foo_precompile.c PROPERTIES
+ OBJECT_OUTPUTS "${PCH_DIR}/foo_precompiled.pch")
+
+ # These source files use the precompiled header.
+ set_source_files_properties(${foo_SRCS} PROPERTIES
+ OBJECT_DEPENDS "${PCH_DIR}/foo_precompiled.pch")
+endif()
diff --git a/Tests/PrecompiledHeader/foo1.c b/Tests/PrecompiledHeader/foo1.c
new file mode 100644
index 0000000000..b10eba7e9f
--- /dev/null
+++ b/Tests/PrecompiledHeader/foo1.c
@@ -0,0 +1,8 @@
+#ifndef foo_h
+# error "Precompiled header foo_precompiled.h has not been loaded."
+#endif
+
+int main()
+{
+ return foo();
+}
diff --git a/Tests/PrecompiledHeader/foo2.c b/Tests/PrecompiledHeader/foo2.c
new file mode 100644
index 0000000000..2845cdb153
--- /dev/null
+++ b/Tests/PrecompiledHeader/foo2.c
@@ -0,0 +1,9 @@
+#ifndef foo_h
+# include "foo.h"
+# error "Precompiled header foo_precompiled.h has not been loaded."
+#endif
+
+int foo()
+{
+ return 0;
+}
diff --git a/Tests/PrecompiledHeader/foo_precompile.c b/Tests/PrecompiledHeader/foo_precompile.c
new file mode 100644
index 0000000000..c37d69a1c8
--- /dev/null
+++ b/Tests/PrecompiledHeader/foo_precompile.c
@@ -0,0 +1,5 @@
+/* The foo_precompiled.h header is included by a /FI option when this
+ source is used to create a precompiled header. Include it here
+ explicitly to allow dependency scanning to detect the dependency
+ whether or not the include path is known to the scanner. */
+#include "include/foo_precompiled.h"
diff --git a/Tests/PrecompiledHeader/include/foo.h b/Tests/PrecompiledHeader/include/foo.h
new file mode 100644
index 0000000000..2210cb41df
--- /dev/null
+++ b/Tests/PrecompiledHeader/include/foo.h
@@ -0,0 +1,4 @@
+#ifndef foo_h
+#define foo_h
+extern int foo();
+#endif
diff --git a/Tests/PrecompiledHeader/include/foo_precompiled.h b/Tests/PrecompiledHeader/include/foo_precompiled.h
new file mode 100644
index 0000000000..f4de601ff4
--- /dev/null
+++ b/Tests/PrecompiledHeader/include/foo_precompiled.h
@@ -0,0 +1 @@
+#include "foo.h"
diff --git a/Tests/Preprocess/CMakeLists.txt b/Tests/Preprocess/CMakeLists.txt
new file mode 100644
index 0000000000..cdfdcc1a46
--- /dev/null
+++ b/Tests/Preprocess/CMakeLists.txt
@@ -0,0 +1,275 @@
+cmake_minimum_required(VERSION 2.6)
+project(Preprocess)
+
+# This test is meant both as a test and as a reference for supported
+# syntax on native tool command lines.
+
+# Determine the build tool being used. Not all characters can be
+# escaped for all build tools. This test checks all characters known
+# to work with each tool and documents those known to not work.
+if("${CMAKE_GENERATOR}" MATCHES "Xcode")
+ set(PP_XCODE 1)
+endif()
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+ set(PP_VS6 1)
+endif()
+if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles")
+ set(PP_UMAKE 1)
+endif()
+if("${CMAKE_GENERATOR}" MATCHES "NMake Makefiles")
+ set(PP_NMAKE 1)
+endif()
+if("${CMAKE_GENERATOR}" MATCHES "MinGW Makefiles")
+ set(PP_MINGW 1)
+endif()
+if("${CMAKE_GENERATOR}" MATCHES "Borland Makefiles")
+ set(PP_BORLAND 1)
+endif()
+if("${CMAKE_GENERATOR}" MATCHES "Watcom WMake")
+ set(PP_WATCOM 1)
+endif()
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 7$")
+ set(PP_VS70 1)
+endif()
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
+ set(PP_VS 1)
+endif()
+
+# Some tests below check the PP_* variables set above. They are meant
+# to test the case that the build tool is at fault. Other tests below
+# check the compiler that will be used when the compiler is at fault
+# (does not work even from a command shell).
+
+#-----------------------------------------------------------------------------
+# Construct a C-string literal to test passing through a definition on
+# the command line. We configure the value into a header so it can be
+# checked in the executable at runtime. The semicolon is handled
+# specially because it needs to be escaped in the COMPILE_DEFINITIONS
+# property value to avoid separating definitions but the string value
+# must not have it escaped inside the configured header.
+set(STRING_EXTRA "")
+
+if(NOT BORLAND AND NOT PP_VS70)
+ # Borland, VS70 IDE: ;
+ # The Borland compiler will simply not accept a non-escaped semicolon
+ # on the command line. If it is escaped \; then the escape character
+ # shows up in the preprocessing output too.
+ #
+ # The VS 7.0 IDE separates definitions on semicolons and commas with
+ # no regard for quotes. Fortunately VS 7.1 and above are okay.
+ set(SEMICOLON "\;")
+endif()
+
+if(NOT PP_VS6)
+ # VS 6 IDE: spaces and '"', '$', or ';'
+ # The project parser cannot handle spaces if there are quotes.
+ # Since we test passing in a quoted string, we cannot have spaces.
+ set(STRING_EXTRA "${STRING_EXTRA} ")
+
+ if(NOT PP_BORLAND AND NOT PP_WATCOM)
+ # Borland, WMake: multiple spaces
+ # The make tool seems to remove extra whitespace from inside
+ # quoted strings when passing to the compiler. It does not have
+ # trouble passing to other tools, and the compiler may be directly
+ # invoked from the command line.
+ set(STRING_EXTRA "${STRING_EXTRA} ")
+ endif()
+endif()
+
+if(NOT PP_VS)
+ # VS: ,
+ # Visual Studio will not accept a comma in the value of a definition.
+ # The comma-separated list of PreprocessorDefinitions in the project
+ # file seems to be parsed before the content of entries is examined.
+ set(STRING_EXTRA "${STRING_EXTRA},")
+endif()
+
+if(NOT PP_MINGW)
+ # MinGW: &
+ # When inside -D"FOO=\"a & b\"" MinGW make wants -D"FOO=\"a "&" b\""
+ # but it does not like quoted ampersand elsewhere.
+ set(STRING_EXTRA "${STRING_EXTRA}&")
+endif()
+
+if(NOT PP_MINGW)
+ # MinGW: |
+ # When inside -D"FOO=\"a | b\"" MinGW make wants -D"FOO=\"a "|" b\""
+ # but it does not like quoted pipe elsewhere.
+ set(STRING_EXTRA "${STRING_EXTRA}|")
+endif()
+
+if(NOT PP_BORLAND AND NOT PP_MINGW AND NOT PP_NMAKE)
+ # Borland, NMake, MinGW: ^
+ # When inside -D"FOO=\"a ^ b\"" the make tools want -D"FOO=\"a "^" b\""
+ # but do not like quoted carrot elsewhere. In NMake the non-quoted
+ # syntax works when the flags are not in a make variable.
+ set(STRING_EXTRA "${STRING_EXTRA}^")
+endif()
+
+if(NOT PP_BORLAND AND NOT PP_MINGW AND NOT PP_NMAKE)
+ # Borland, MinGW: < >
+ # Angle-brackets have funny behavior that is hard to escape.
+ set(STRING_EXTRA "${STRING_EXTRA}<>")
+endif()
+
+set(EXPR_OP1 "/")
+if((NOT MSVC OR PP_NMAKE) AND
+ NOT "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")
+ # MSVC cl, Intel icl: %
+ # When the cl compiler is invoked from the command line then % must
+ # be written %% (to distinguish from %ENV% syntax). However cl does
+ # not seem to accept the syntax when it is invoked from inside a
+ # make tool (nmake, mingw32-make, etc.). Instead the argument must
+ # be placed inside a response file. Then cl accepts it because it
+ # parses the response file as it would the normal windows command
+ # line. Currently only NMake supports running cl with a response
+ # file. Supporting other make tools would require CMake to generate
+ # response files explicitly for each object file.
+ #
+ # When the icl compiler is invoked from the command line then % must
+ # be written just '%'. However nmake requires '%%' except when using
+ # response files. Currently we have no way to affect escaping based
+ # on whether flags go in a response file, so we just have to skip it.
+ set(STRING_EXTRA "${STRING_EXTRA}%")
+ set(EXPR_OP1 "%")
+endif()
+
+# General: \"
+# Make tools do not reliably accept \\\" syntax:
+# - MinGW and MSYS make tools crash with \\\"
+# - Borland make actually wants a mis-matched quote \\"
+# or $(BACKSLASH)\" where BACKSLASH is a variable set to \\
+# - VS IDE gets confused about the bounds of the definition value \\\"
+# - NMake is okay with just \\\"
+if(PP_NMAKE OR PP_UMAKE)
+ set(STRING_EXTRA "${STRING_EXTRA}\\\"")
+endif()
+
+# General: #
+# MSVC will not accept a # in the value of a string definition on the
+# command line. The character seems to be simply replaced by an
+# equals =. According to "cl -help" definitions may be specified by
+# -DMACRO#VALUE as well as -DMACRO=VALUE. It must be implemented by a
+# simple search-and-replace.
+#
+# The Borland compiler will parse both # and \# as just # but the make
+# tool seems to want \# sometimes and not others.
+#
+# Unix make does not like # in variable settings without extra
+# escaping. This could probably be fixed but since MSVC does not
+# support it and it is not an operator it is not worthwhile.
+
+# Compose the final test string.
+set(STRING_VALUE "hello`~!@$*)(_+-=}{][:'.?/${STRING_EXTRA}world")
+
+#-----------------------------------------------------------------------------
+# Function-style macro command-line support:
+# - Borland does not support
+# - MSVC does not support
+# - Watcom does not support
+# - GCC supports
+
+# Too few platforms support this to bother implementing.
+# People can just configure headers with the macros.
+
+#-----------------------------------------------------------------------------
+# Construct a sample expression to pass as a macro definition.
+
+set(EXPR "x*y+!(x==(y+1*2))*f(x${EXPR_OP1}2)")
+
+if(NOT WATCOM)
+ # Watcom does not support - or / because it parses them as options.
+ set(EXPR "${EXPR} + y/x-x")
+endif()
+
+#-----------------------------------------------------------------------------
+
+# Inform the test if the debug configuration is getting built.
+# The NDEBUG definition takes care of this for release.
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DPREPROCESS_DEBUG")
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DPREPROCESS_DEBUG")
+
+# Inform the test if it built from Xcode or VS6 IDE.
+if(PP_XCODE)
+ set(PREPROCESS_XCODE 1)
+endif()
+if(PP_VS6)
+ set(PREPROCESS_VS6 1)
+ set(VS6 _vs6)
+endif()
+
+# Test old-style definitions.
+add_definitions(-DOLD_DEF -DOLD_EXPR=2)
+
+# Make sure old-style definitions are converted to directory property.
+set(OLD_DEFS_EXPECTED "OLD_DEF;OLD_EXPR=2")
+get_property(OLD_DEFS DIRECTORY PROPERTY COMPILE_DEFINITIONS)
+if(NOT "${OLD_DEFS}" STREQUAL "${OLD_DEFS_EXPECTED}")
+ message(SEND_ERROR "add_definitions not converted to directory property!")
+endif()
+
+add_executable(Preprocess preprocess.c preprocess${VS6}.cxx)
+
+set(FILE_PATH "${Preprocess_SOURCE_DIR}/file_def.h")
+set(TARGET_PATH "${Preprocess_SOURCE_DIR}/target_def.h")
+
+# Set some definition properties.
+foreach(c "" "_DEBUG" "_RELEASE")
+ set_property(
+ DIRECTORY .
+ APPEND PROPERTY COMPILE_DEFINITIONS${c} "DIRECTORY_DEF${c}"
+ )
+ set_property(
+ TARGET Preprocess
+ PROPERTY COMPILE_DEFINITIONS${c} "TARGET_DEF${c}"
+ )
+ set_property(
+ SOURCE preprocess.c preprocess${VS6}.cxx
+ PROPERTY COMPILE_DEFINITIONS${c} "FILE_DEF${c}"
+ )
+endforeach()
+
+# Add definitions with values.
+if(NOT PREPROCESS_VS6)
+ # The path might have spaces, which VS6 does not support.
+ set(DEF_TARGET_PATH "TARGET_PATH=\"${TARGET_PATH}\"")
+ set(DEF_FILE_PATH "FILE_PATH=\"${FILE_PATH}\"")
+endif()
+set_property(
+ TARGET Preprocess
+ APPEND PROPERTY COMPILE_DEFINITIONS
+ "TARGET_STRING=\"${STRING_VALUE}${SEMICOLON}\""
+ "TARGET_EXPR=${EXPR}"
+ ${DEF_TARGET_PATH}
+ )
+set_property(
+ SOURCE preprocess.c preprocess${VS6}.cxx
+ APPEND PROPERTY COMPILE_DEFINITIONS
+ "FILE_STRING=\"${STRING_VALUE}${SEMICOLON}\""
+ "FILE_EXPR=${EXPR}"
+ ${DEF_FILE_PATH}
+ )
+
+# Try reading and writing the property value to ensure the string is
+# preserved.
+get_property(defs1 TARGET Preprocess PROPERTY COMPILE_DEFINITIONS)
+set_property(TARGET Preprocess PROPERTY COMPILE_DEFINITIONS "${defs1}")
+get_property(defs2 TARGET Preprocess PROPERTY COMPILE_DEFINITIONS)
+if(NOT "x${defs1}" STREQUAL "x${defs2}")
+ message(FATAL_ERROR "get/set/get COMPILE_DEFINITIONS round trip failed. "
+ "First get:\n"
+ " ${defs1}\n"
+ "Second get:\n"
+ " ${defs2}")
+endif()
+
+# Helper target for running test manually in build tree.
+add_custom_target(drive COMMAND Preprocess)
+
+# Configure the header file with the desired string value.
+if(SEMICOLON)
+ set(STRING_VALUE "${STRING_VALUE};")
+endif()
+configure_file(${Preprocess_SOURCE_DIR}/preprocess.h.in
+ ${Preprocess_BINARY_DIR}/preprocess.h)
+include_directories(${Preprocess_BINARY_DIR})
diff --git a/Tests/Preprocess/file_def.h b/Tests/Preprocess/file_def.h
new file mode 100644
index 0000000000..fbf8986a06
--- /dev/null
+++ b/Tests/Preprocess/file_def.h
@@ -0,0 +1 @@
+#define FILE_PATH_DEF
diff --git a/Tests/Preprocess/preprocess.c b/Tests/Preprocess/preprocess.c
new file mode 100644
index 0000000000..16209acf49
--- /dev/null
+++ b/Tests/Preprocess/preprocess.c
@@ -0,0 +1,198 @@
+#include <preprocess.h>
+
+#include FILE_PATH
+#include TARGET_PATH
+
+#include <string.h>
+#include <stdio.h>
+
+int check_defines_C(void)
+{
+ int result = 1;
+ if(strcmp(FILE_STRING, STRING_VALUE) != 0)
+ {
+ fprintf(stderr,
+ "FILE_STRING has wrong value in C [%s]\n", FILE_STRING);
+ result = 0;
+ }
+ if(strcmp(TARGET_STRING, STRING_VALUE) != 0)
+ {
+ fprintf(stderr,
+ "TARGET_STRING has wrong value in C [%s]\n", TARGET_STRING);
+ result = 0;
+ }
+ {
+ int x = 2;
+ int y = 3;
+ if((FILE_EXPR) != (EXPR))
+ {
+ fprintf(stderr, "FILE_EXPR did not work in C [%s]\n",
+ TO_STRING(FILE_EXPR));
+ result = 0;
+ }
+ if((TARGET_EXPR) != (EXPR))
+ {
+ fprintf(stderr, "TARGET_EXPR did not work in C [%s]\n",
+ TO_STRING(FILE_EXPR));
+ result = 0;
+ }
+ }
+#ifdef NDEBUG
+# ifdef FILE_DEF_DEBUG
+ {
+ fprintf(stderr, "FILE_DEF_DEBUG should not be defined in C\n");
+ result = 0;
+ }
+# endif
+# ifdef TARGET_DEF_DEBUG
+ {
+ fprintf(stderr, "TARGET_DEF_DEBUG should not be defined in C\n");
+ result = 0;
+ }
+# endif
+# ifdef DIRECTORY_DEF_DEBUG
+ {
+ fprintf(stderr, "DIRECTORY_DEF_DEBUG should not be defined in C\n");
+ result = 0;
+ }
+# endif
+# ifndef FILE_DEF_RELEASE
+# ifndef PREPROCESS_XCODE
+ {
+ fprintf(stderr, "FILE_DEF_RELEASE should be defined in C\n");
+ result = 0;
+ }
+# endif
+# endif
+# ifndef TARGET_DEF_RELEASE
+ {
+ fprintf(stderr, "TARGET_DEF_RELEASE should be defined in C\n");
+ result = 0;
+ }
+# endif
+# ifndef DIRECTORY_DEF_RELEASE
+ {
+ fprintf(stderr, "DIRECTORY_DEF_RELEASE should be defined in C\n");
+ result = 0;
+ }
+# endif
+#endif
+#ifdef PREPROCESS_DEBUG
+# ifndef FILE_DEF_DEBUG
+# ifndef PREPROCESS_XCODE
+ {
+ fprintf(stderr, "FILE_DEF_DEBUG should be defined in C\n");
+ result = 0;
+ }
+# endif
+# endif
+# ifndef TARGET_DEF_DEBUG
+ {
+ fprintf(stderr, "TARGET_DEF_DEBUG should be defined in C\n");
+ result = 0;
+ }
+# endif
+# ifndef DIRECTORY_DEF_DEBUG
+ {
+ fprintf(stderr, "DIRECTORY_DEF_DEBUG should be defined in C\n");
+ result = 0;
+ }
+# endif
+# ifdef FILE_DEF_RELEASE
+ {
+ fprintf(stderr, "FILE_DEF_RELEASE should not be defined in C\n");
+ result = 0;
+ }
+# endif
+# ifdef TARGET_DEF_RELEASE
+ {
+ fprintf(stderr, "TARGET_DEF_RELEASE should not be defined in C\n");
+ result = 0;
+ }
+# endif
+# ifdef DIRECTORY_DEF_RELEASE
+ {
+ fprintf(stderr, "DIRECTORY_DEF_RELEASE should not be defined in C\n");
+ result = 0;
+ }
+# endif
+#endif
+#if defined(FILE_DEF_DEBUG) || defined(TARGET_DEF_DEBUG)
+# if !defined(FILE_DEF_DEBUG) || !defined(TARGET_DEF_DEBUG)
+# ifndef PREPROCESS_XCODE
+ {
+ fprintf(stderr,
+ "FILE_DEF_DEBUG and TARGET_DEF_DEBUG inconsistent in C\n");
+ result = 0;
+ }
+# endif
+# endif
+# if defined(FILE_DEF_RELEASE) || defined(TARGET_DEF_RELEASE)
+ {
+ fprintf(stderr, "DEBUG and RELEASE definitions inconsistent in C\n");
+ result = 0;
+ }
+# endif
+#endif
+#if defined(FILE_DEF_RELEASE) || defined(TARGET_DEF_RELEASE)
+# if !defined(FILE_DEF_RELEASE) || !defined(TARGET_DEF_RELEASE)
+# ifndef PREPROCESS_XCODE
+ {
+ fprintf(stderr,
+ "FILE_DEF_RELEASE and TARGET_DEF_RELEASE inconsistent in C\n");
+ result = 0;
+ }
+# endif
+# endif
+# if defined(FILE_DEF_DEBUG) || defined(TARGET_DEF_DEBUG)
+ {
+ fprintf(stderr, "RELEASE and DEBUG definitions inconsistent in C\n");
+ result = 0;
+ }
+# endif
+#endif
+#ifndef FILE_PATH_DEF
+ {
+ fprintf(stderr, "FILE_PATH_DEF not defined in C\n");
+ result = 0;
+ }
+#endif
+#ifndef TARGET_PATH_DEF
+ {
+ fprintf(stderr, "TARGET_PATH_DEF not defined in C\n");
+ result = 0;
+ }
+#endif
+#ifndef FILE_DEF
+ {
+ fprintf(stderr, "FILE_DEF not defined in C\n");
+ result = 0;
+ }
+#endif
+#ifndef TARGET_DEF
+ {
+ fprintf(stderr, "TARGET_DEF not defined in C\n");
+ result = 0;
+ }
+#endif
+#ifndef DIRECTORY_DEF
+ {
+ fprintf(stderr, "DIRECTORY_DEF not defined in C\n");
+ result = 0;
+ }
+#endif
+#ifndef OLD_DEF
+ {
+ fprintf(stderr, "OLD_DEF not defined in C\n");
+ result = 0;
+ }
+#endif
+#if !defined(OLD_EXPR) || OLD_EXPR != 2
+ {
+ fprintf(stderr, "OLD_EXPR id not work in C [%s]\n",
+ TO_STRING(OLD_EXPR));
+ result = 0;
+ }
+#endif
+ return result;
+}
diff --git a/Tests/Preprocess/preprocess.cxx b/Tests/Preprocess/preprocess.cxx
new file mode 100644
index 0000000000..27b6ac89a6
--- /dev/null
+++ b/Tests/Preprocess/preprocess.cxx
@@ -0,0 +1,225 @@
+#include <preprocess.h>
+
+#include FILE_PATH
+#include TARGET_PATH
+
+#include <string.h>
+#include <stdio.h>
+
+extern "C" int check_defines_C(void);
+
+int check_defines_CXX()
+{
+ int result = 1;
+ if(strcmp(FILE_STRING, STRING_VALUE) != 0)
+ {
+ fprintf(stderr,
+ "FILE_STRING has wrong value in CXX [%s]\n", FILE_STRING);
+ result = 0;
+ }
+ if(strcmp(TARGET_STRING, STRING_VALUE) != 0)
+ {
+ fprintf(stderr,
+ "TARGET_STRING has wrong value in CXX [%s]\n", TARGET_STRING);
+ result = 0;
+ }
+ {
+ int x = 2;
+ int y = 3;
+ if((FILE_EXPR) != (EXPR))
+ {
+ fprintf(stderr, "FILE_EXPR did not work in CXX [%s]\n",
+ TO_STRING(FILE_EXPR));
+ result = 0;
+ }
+ if((TARGET_EXPR) != (EXPR))
+ {
+ fprintf(stderr, "TARGET_EXPR did not work in CXX [%s]\n",
+ TO_STRING(FILE_EXPR));
+ result = 0;
+ }
+ }
+#ifdef NDEBUG
+# ifdef FILE_DEF_DEBUG
+ {
+ fprintf(stderr, "FILE_DEF_DEBUG should not be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# ifdef TARGET_DEF_DEBUG
+ {
+ fprintf(stderr, "TARGET_DEF_DEBUG should not be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# ifdef DIRECTORY_DEF_DEBUG
+ {
+ fprintf(stderr, "DIRECTORY_DEF_DEBUG should not be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# ifndef FILE_DEF_RELEASE
+# ifndef PREPROCESS_XCODE
+ {
+ fprintf(stderr, "FILE_DEF_RELEASE should be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# endif
+# ifndef TARGET_DEF_RELEASE
+ {
+ fprintf(stderr, "TARGET_DEF_RELEASE should be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# ifndef DIRECTORY_DEF_RELEASE
+ {
+ fprintf(stderr, "DIRECTORY_DEF_RELEASE should be defined in CXX\n");
+ result = 0;
+ }
+# endif
+#endif
+#ifdef PREPROCESS_DEBUG
+# ifndef FILE_DEF_DEBUG
+# ifndef PREPROCESS_XCODE
+ {
+ fprintf(stderr, "FILE_DEF_DEBUG should be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# endif
+# ifndef TARGET_DEF_DEBUG
+ {
+ fprintf(stderr, "TARGET_DEF_DEBUG should be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# ifndef DIRECTORY_DEF_DEBUG
+ {
+ fprintf(stderr, "DIRECTORY_DEF_DEBUG should be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# ifdef FILE_DEF_RELEASE
+ {
+ fprintf(stderr, "FILE_DEF_RELEASE should not be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# ifdef TARGET_DEF_RELEASE
+ {
+ fprintf(stderr, "TARGET_DEF_RELEASE should not be defined in CXX\n");
+ result = 0;
+ }
+# endif
+# ifdef DIRECTORY_DEF_RELEASE
+ {
+ fprintf(stderr, "DIRECTORY_DEF_RELEASE should not be defined in CXX\n");
+ result = 0;
+ }
+# endif
+#endif
+#if defined(FILE_DEF_DEBUG) || defined(TARGET_DEF_DEBUG)
+# if !defined(FILE_DEF_DEBUG) || !defined(TARGET_DEF_DEBUG)
+# ifndef PREPROCESS_XCODE
+ {
+ fprintf(stderr,
+ "FILE_DEF_DEBUG and TARGET_DEF_DEBUG inconsistent in CXX\n");
+ result = 0;
+ }
+# endif
+# endif
+# if defined(FILE_DEF_RELEASE) || defined(TARGET_DEF_RELEASE)
+ {
+ fprintf(stderr, "DEBUG and RELEASE definitions inconsistent in CXX\n");
+ result = 0;
+ }
+# endif
+#endif
+#if defined(FILE_DEF_RELEASE) || defined(TARGET_DEF_RELEASE)
+# if !defined(FILE_DEF_RELEASE) || !defined(TARGET_DEF_RELEASE)
+# ifndef PREPROCESS_XCODE
+ {
+ fprintf(stderr,
+ "FILE_DEF_RELEASE and TARGET_DEF_RELEASE inconsistent in CXX\n");
+ result = 0;
+ }
+# endif
+# endif
+# if defined(FILE_DEF_DEBUG) || defined(TARGET_DEF_DEBUG)
+ {
+ fprintf(stderr, "RELEASE and DEBUG definitions inconsistent in CXX\n");
+ result = 0;
+ }
+# endif
+#endif
+#ifndef FILE_PATH_DEF
+ {
+ fprintf(stderr, "FILE_PATH_DEF not defined in CXX\n");
+ result = 0;
+ }
+#endif
+#ifndef TARGET_PATH_DEF
+ {
+ fprintf(stderr, "TARGET_PATH_DEF not defined in CXX\n");
+ result = 0;
+ }
+#endif
+#ifndef FILE_DEF
+ {
+ fprintf(stderr, "FILE_DEF not defined in CXX\n");
+ result = 0;
+ }
+#endif
+#ifndef TARGET_DEF
+ {
+ fprintf(stderr, "TARGET_DEF not defined in CXX\n");
+ result = 0;
+ }
+#endif
+#ifndef DIRECTORY_DEF
+ {
+ fprintf(stderr, "DIRECTORY_DEF not defined in CXX\n");
+ result = 0;
+ }
+#endif
+#ifndef OLD_DEF
+ {
+ fprintf(stderr, "OLD_DEF not defined in CXX\n");
+ result = 0;
+ }
+#endif
+#if !defined(OLD_EXPR) || OLD_EXPR != 2
+ {
+ fprintf(stderr, "OLD_EXPR id not work in C [%s]\n",
+ TO_STRING(OLD_EXPR));
+ result = 0;
+ }
+#endif
+ return result;
+}
+
+int main()
+{
+ int result = 1;
+
+ if(!check_defines_C())
+ {
+ result = 0;
+ }
+
+ if(!check_defines_CXX())
+ {
+ result = 0;
+ }
+
+ if(result)
+ {
+ printf("All preprocessor definitions are correct.\n");
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+}
diff --git a/Tests/Preprocess/preprocess.h.in b/Tests/Preprocess/preprocess.h.in
new file mode 100644
index 0000000000..3e1c7a07ae
--- /dev/null
+++ b/Tests/Preprocess/preprocess.h.in
@@ -0,0 +1,16 @@
+/* Define configured macros. */
+#define STRING_VALUE "@STRING_VALUE@"
+#define EXPR @EXPR@
+#cmakedefine PREPROCESS_XCODE
+#cmakedefine PREPROCESS_VS6
+
+#ifdef PREPROCESS_VS6
+# define FILE_PATH "@FILE_PATH@"
+# define TARGET_PATH "@TARGET_PATH@"
+#endif
+
+/* Declarations and macros shared by all sources. */
+#define TO_STRING(x) TO_STRING0(x)
+#define TO_STRING0(x) #x
+
+static int f(int i) { return i*3; }
diff --git a/Tests/Preprocess/preprocess_vs6.cxx b/Tests/Preprocess/preprocess_vs6.cxx
new file mode 100644
index 0000000000..9df89f6a02
--- /dev/null
+++ b/Tests/Preprocess/preprocess_vs6.cxx
@@ -0,0 +1,3 @@
+// The VS6 IDE does not support object name configuration so we need a
+// source file with a different name. Include the real source file.
+#include "preprocess.cxx"
diff --git a/Tests/Preprocess/target_def.h b/Tests/Preprocess/target_def.h
new file mode 100644
index 0000000000..f016d5cd2a
--- /dev/null
+++ b/Tests/Preprocess/target_def.h
@@ -0,0 +1 @@
+#define TARGET_PATH_DEF
diff --git a/Tests/Properties/CMakeLists.txt b/Tests/Properties/CMakeLists.txt
new file mode 100644
index 0000000000..11fca45b01
--- /dev/null
+++ b/Tests/Properties/CMakeLists.txt
@@ -0,0 +1,147 @@
+# a simple CXX only test case
+cmake_minimum_required (VERSION 2.6)
+project (Properties)
+
+# these first three tests really test both properties and the management of
+# cmSourceFile objects by CMake.
+
+# test properties on a build tree file that is relative (yuck)
+configure_file(properties.h.in "${Properties_BINARY_DIR}/properties.h")
+set_source_files_properties(properties.h PROPERTIES TEST1 1)
+get_source_file_property(RESULT1 properties.h TEST1)
+
+# test properties on a headerfile in the source tree
+# accessed without an extenion (also yuck)
+set_source_files_properties(properties2 PROPERTIES TEST2 1)
+get_source_file_property(RESULT2 properties2 TEST2)
+
+# test properties on a relative source that is not generated
+set_source_files_properties(SubDir/properties3.cxx PROPERTIES TEST3 1)
+get_source_file_property(RESULT3 SubDir/properties3.cxx TEST3)
+
+include_directories("${Properties_SOURCE_DIR}" "${Properties_BINARY_DIR}")
+
+
+# test generic property interfaces
+get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
+if (GLOBALRESULT)
+ message(SEND_ERROR "Error: global prop defined when it should not be, "
+ "result is GLOBALRESULT=${GLOBALRESULT}")
+endif ()
+
+define_property(GLOBAL PROPERTY GLOBALTEST
+ BRIEF_DOCS "A test property"
+ FULL_DOCS "A long description of this test property"
+ )
+
+get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
+if (NOT GLOBALRESULT)
+ message(SEND_ERROR "Error: global prop not defined "
+ "result is GLOBALRESULT=${GLOBALRESULT}")
+endif ()
+
+set_property(GLOBAL PROPERTY GLOBALTEST 1)
+set_property(DIRECTORY PROPERTY DIRECTORYTEST 1)
+set_property(SOURCE SubDir/properties3.cxx PROPERTY SOURCETEST 1)
+get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST)
+get_property(DIRECTORYRESULT DIRECTORY PROPERTY DIRECTORYTEST)
+get_property(SOURCERESULT
+ SOURCE SubDir/properties3.cxx
+ PROPERTY SOURCETEST
+ )
+
+if (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
+ DIRECTORYRESULT AND SOURCERESULT)
+ add_executable (Properties SubDir/properties3.cxx properties)
+else ()
+ message(SEND_ERROR
+ "Error: test results are RESULT1=${RESULT1} RESULT2=${RESULT2} "
+ "RESULT3=${RESULT3} GLOBALRESULT=${GLOBALRESULT} "
+ "DIRECTORYRESULT=${DIRECTORYRESULT} "
+ "SOURCERESULT=${SOURCERESULT}")
+endif ()
+
+# test the target property
+set_property(TARGET Properties PROPERTY TARGETTEST 1)
+get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST)
+if (NOT TARGETRESULT)
+ message(SEND_ERROR
+ "Error: target result is TARGETRESULT=${TARGETRESULT}")
+endif ()
+
+# test APPEND and APPEND_STRING set_property()
+set_property(TARGET Properties PROPERTY FOO foo)
+set_property(TARGET Properties PROPERTY BAR bar)
+set_property(TARGET Properties APPEND PROPERTY FOO 123)
+set_property(TARGET Properties APPEND_STRING PROPERTY BAR 456)
+
+get_property(APPEND_RESULT TARGET Properties PROPERTY FOO)
+if (NOT "${APPEND_RESULT}" STREQUAL "foo;123")
+ message(SEND_ERROR
+ "Error: target result is APPEND_RESULT=${APPEND_RESULT}")
+endif ()
+
+get_property(APPEND_STRING_RESULT TARGET Properties PROPERTY BAR)
+if (NOT "${APPEND_STRING_RESULT}" STREQUAL "bar456")
+ message(SEND_ERROR
+ "Error: target result is APPEND_STRING_RESULT=${APPEND_STRING_RESULT}")
+endif ()
+
+# test get_property SET
+get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
+if (NOT TARGETRESULT)
+ message(SEND_ERROR
+ "Error: target prop not set, result is TARGETRESULT=${TARGETRESULT}")
+endif ()
+
+# test unsetting a property
+set_property(TARGET Properties PROPERTY TARGETTEST)
+get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
+if (TARGETRESULT)
+ message(SEND_ERROR "Error: target prop not unset, "
+ "result is TARGETRESULT=${TARGETRESULT}")
+endif ()
+
+
+
+# test the target SOURCES property
+get_property(Properties_SOURCES TARGET Properties PROPERTY SOURCES)
+set_source_files_properties(${Properties_SOURCES} PROPERTIES TEST4 1)
+get_source_file_property(RESULT4 properties.h TEST4)
+if(NOT RESULT4)
+ message(SEND_ERROR "Error: target result is"
+ " RESULT4=${RESULT4}"
+ " Properties_SOURCES=[${Properties_SOURCES}]")
+endif()
+
+# test CACHE properties
+macro(check_cache_props)
+ foreach(prop VALUE TYPE HELPSTRING ADVANCED STRINGS)
+ get_property(result CACHE SOME_ENTRY PROPERTY ${prop})
+ if(NOT "x${result}" STREQUAL "x${expect_${prop}}")
+ message(SEND_ERROR "CACHE property ${prop} is [${result}], not [${expect_${prop}}]")
+ endif()
+ endforeach()
+endmacro()
+set(expect_VALUE "ON")
+set(expect_TYPE "BOOL")
+set(expect_HELPSTRING "sample cache entry")
+set(expect_ADVANCED 0)
+set(expect_STRINGS "")
+set(SOME_ENTRY "${expect_VALUE}" CACHE ${expect_TYPE} "${expect_HELPSTRING}" FORCE)
+mark_as_advanced(CLEAR SOME_ENTRY)
+set_property(CACHE SOME_ENTRY PROPERTY STRINGS "")
+check_cache_props()
+set(expect_VALUE "Some string")
+set(expect_TYPE "STRING")
+set(expect_HELPSTRING "sample cache entry help")
+set(expect_ADVANCED 1)
+set(expect_STRINGS "Some string;Some other string;Some third string")
+set_property(CACHE SOME_ENTRY PROPERTY TYPE "${expect_TYPE}")
+set_property(CACHE SOME_ENTRY PROPERTY HELPSTRING "${expect_HELPSTRING}")
+set_property(CACHE SOME_ENTRY PROPERTY VALUE "${expect_VALUE}")
+set_property(CACHE SOME_ENTRY PROPERTY ADVANCED "${expect_ADVANCED}")
+set_property(CACHE SOME_ENTRY PROPERTY STRINGS "${expect_STRINGS}")
+check_cache_props()
+
+add_subdirectory(SubDir2)
diff --git a/Tests/Properties/SubDir/properties3.cxx b/Tests/Properties/SubDir/properties3.cxx
new file mode 100644
index 0000000000..1a27a04d4f
--- /dev/null
+++ b/Tests/Properties/SubDir/properties3.cxx
@@ -0,0 +1,9 @@
+#include "properties.h"
+#include "properties2.h"
+
+#if defined HAVE_PROPERTIES_H && defined HAVE_PROPERTIES2_H
+int main ()
+{
+ return 0;
+}
+#endif
diff --git a/Tests/Properties/SubDir2/CMakeLists.txt b/Tests/Properties/SubDir2/CMakeLists.txt
new file mode 100644
index 0000000000..377dc830ef
--- /dev/null
+++ b/Tests/Properties/SubDir2/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/../subdirtest.cxx"
+ PROPERTIES COMPILE_DEFINITIONS SUBDIR_TEST)
+
+add_executable(subdirtest "${CMAKE_CURRENT_SOURCE_DIR}/../subdirtest.cxx")
diff --git a/Tests/Properties/properties.h.in b/Tests/Properties/properties.h.in
new file mode 100644
index 0000000000..5e92831688
--- /dev/null
+++ b/Tests/Properties/properties.h.in
@@ -0,0 +1 @@
+#define HAVE_PROPERTIES_H
diff --git a/Tests/Properties/properties2.h b/Tests/Properties/properties2.h
new file mode 100644
index 0000000000..898fd9e6af
--- /dev/null
+++ b/Tests/Properties/properties2.h
@@ -0,0 +1 @@
+#define HAVE_PROPERTIES2_H
diff --git a/Tests/Properties/subdirtest.cxx b/Tests/Properties/subdirtest.cxx
new file mode 100644
index 0000000000..02d8f3d3ff
--- /dev/null
+++ b/Tests/Properties/subdirtest.cxx
@@ -0,0 +1,9 @@
+
+#ifndef SUBDIR_TEST
+#error Expected SUBDIR_TEST
+#endif
+
+int main(int, char**)
+{
+ return 0;
+}
diff --git a/Tests/PythonCoverage/DartConfiguration.tcl.in b/Tests/PythonCoverage/DartConfiguration.tcl.in
new file mode 100644
index 0000000000..e29cffe4f9
--- /dev/null
+++ b/Tests/PythonCoverage/DartConfiguration.tcl.in
@@ -0,0 +1,8 @@
+# This file is configured by CMake automatically as DartConfiguration.tcl
+# If you choose not to use CMake, this file may be hand configured, by
+# filling in the required variables.
+
+
+# Configuration directories and files
+SourceDirectory: ${CMake_BINARY_DIR}/Testing/PythonCoverage/coveragetest
+BuildDirectory: ${CMake_BINARY_DIR}/Testing/PythonCoverage
diff --git a/Tests/PythonCoverage/coverage.xml.in b/Tests/PythonCoverage/coverage.xml.in
new file mode 100644
index 0000000000..fcc1b1c67d
--- /dev/null
+++ b/Tests/PythonCoverage/coverage.xml.in
@@ -0,0 +1,35 @@
+<?xml version="1.0" ?>
+<!DOCTYPE coverage
+ SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
+<coverage branch-rate="0" line-rate="0.8462" timestamp="1380469411433" version="3.6">
+ <!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage -->
+ <packages>
+ <package branch-rate="0" complexity="0" line-rate="0.8462" name="">
+ <classes>
+ <class branch-rate="0" complexity="0" filename="foo.py" line-rate="0.6667" name="foo">
+ <methods/>
+ <lines>
+ <line hits="1" number="2"/>
+ <line hits="1" number="3"/>
+ <line hits="1" number="4"/>
+ <line hits="1" number="6"/>
+ <line hits="0" number="7"/>
+ <line hits="0" number="8"/>
+ </lines>
+ </class>
+ <class branch-rate="0" complexity="0" filename="test_foo.py" line-rate="1" name="test_foo">
+ <methods/>
+ <lines>
+ <line hits="1" number="2"/>
+ <line hits="1" number="3"/>
+ <line hits="1" number="5"/>
+ <line hits="1" number="7"/>
+ <line hits="1" number="8"/>
+ <line hits="1" number="10"/>
+ <line hits="1" number="11"/>
+ </lines>
+ </class>
+ </classes>
+ </package>
+ </packages>
+</coverage>
diff --git a/Tests/PythonCoverage/coveragetest/foo.py b/Tests/PythonCoverage/coveragetest/foo.py
new file mode 100644
index 0000000000..97b5a41e9d
--- /dev/null
+++ b/Tests/PythonCoverage/coveragetest/foo.py
@@ -0,0 +1,8 @@
+
+def foo():
+ x = 3 + 3
+ return x
+
+def bar():
+ y = 2 + 2
+ return y
diff --git a/Tests/PythonCoverage/coveragetest/test_foo.py b/Tests/PythonCoverage/coveragetest/test_foo.py
new file mode 100644
index 0000000000..51a69d89e1
--- /dev/null
+++ b/Tests/PythonCoverage/coveragetest/test_foo.py
@@ -0,0 +1,11 @@
+
+import foo
+import unittest
+
+class TestFoo(unittest.TestCase):
+
+ def testFoo(self):
+ self.assertEquals(foo.foo(), 6, 'foo() == 6')
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/Tests/Qt4And5Automoc/CMakeLists.txt b/Tests/Qt4And5Automoc/CMakeLists.txt
new file mode 100644
index 0000000000..ad74961d9f
--- /dev/null
+++ b/Tests/Qt4And5Automoc/CMakeLists.txt
@@ -0,0 +1,29 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+project(Qt4And5Automoc)
+
+if (QT_REVERSE_FIND_ORDER)
+ find_package(Qt5Core REQUIRED)
+ find_package(Qt4 REQUIRED)
+else()
+ find_package(Qt4 REQUIRED)
+ find_package(Qt5Core REQUIRED)
+endif()
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+macro(generate_main_file VERSION)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/main.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/main_qt${VERSION}.cpp" COPYONLY)
+ file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/main_qt${VERSION}.cpp"
+ "#include \"main_qt${VERSION}.moc\"\n"
+ )
+endmacro()
+
+generate_main_file(4)
+generate_main_file(5)
+
+add_executable(qt4_exe "${CMAKE_CURRENT_BINARY_DIR}/main_qt4.cpp")
+target_link_libraries(qt4_exe Qt4::QtCore)
+add_executable(qt5_exe "${CMAKE_CURRENT_BINARY_DIR}/main_qt5.cpp")
+target_link_libraries(qt5_exe Qt5::Core)
diff --git a/Tests/Qt4And5Automoc/main.cpp.in b/Tests/Qt4And5Automoc/main.cpp.in
new file mode 100644
index 0000000000..00fd641535
--- /dev/null
+++ b/Tests/Qt4And5Automoc/main.cpp.in
@@ -0,0 +1,18 @@
+
+#include <QObject>
+
+class SomeObject : public QObject
+{
+ Q_OBJECT
+public:
+ explicit SomeObject(QObject *parent = 0)
+ : QObject(parent)
+ {
+
+ }
+};
+
+int main(int argc, char **argv)
+{
+ return 0;
+}
diff --git a/Tests/Qt4Deploy/CMakeLists.txt b/Tests/Qt4Deploy/CMakeLists.txt
new file mode 100644
index 0000000000..646ea9f3b6
--- /dev/null
+++ b/Tests/Qt4Deploy/CMakeLists.txt
@@ -0,0 +1,70 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(Qt4Deploy)
+set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/install)
+
+find_package(Qt4 REQUIRED QtMain QtCore QtSql)
+include(${QT_USE_FILE})
+
+add_executable(testdeploy MACOSX_BUNDLE testdeploy.cpp)
+target_link_libraries(testdeploy ${QT_LIBRARIES})
+set_target_properties(testdeploy PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}")
+
+if(CMAKE_CONFIGURATION_TYPES AND QT_QTCORE_LIBRARY_RELEASE AND QT_QTCORE_LIBRARY_DEBUG)
+ # note: installing debug Qt libraries from a Qt installation configured with
+ # -debug-and-release not yet supported (very low priority).
+ install(CODE "
+ if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Dd][Ee][Bb][Uu][Gg])$\")
+ return()
+ endif()
+ ")
+endif()
+
+# install the Qt4 app with qsqlite plugin
+install(CODE "file(REMOVE_RECURSE \"${CMAKE_INSTALL_PREFIX}\")")
+install(TARGETS testdeploy DESTINATION .)
+include(../../Modules/DeployQt4.cmake)
+if(APPLE)
+ install_qt4_executable(testdeploy.app "qsqlite")
+elseif(WIN32)
+ install_qt4_executable(testdeploy.exe "qsqlite")
+else()
+ install_qt4_executable(testdeploy "qsqlite")
+endif()
+
+
+# test depends on standard qsqlite plugin
+if(QT_QSQLITE_PLUGIN_DEBUG OR QT_QSQLITE_PLUGIN_RELEASE)
+
+ # test the deployed Qt application
+ if(APPLE)
+ install(CODE "
+ message(STATUS \"executing: ${CMAKE_INSTALL_PREFIX}/testdeploy.app/Contents/MacOS/testdeploy\")
+ execute_process(COMMAND \"${CMAKE_INSTALL_PREFIX}/testdeploy.app/Contents/MacOS/testdeploy\"
+ RESULT_VARIABLE result)
+ if(NOT result STREQUAL \"0\")
+ message(FATAL_ERROR \"error running testdeploy app\")
+ endif()
+ ")
+ else()
+ install(CODE "
+ message(STATUS \"executing: ${CMAKE_INSTALL_PREFIX}/testdeploy\")
+ execute_process(COMMAND \"${CMAKE_INSTALL_PREFIX}/testdeploy\"
+ RESULT_VARIABLE result)
+ if(NOT result STREQUAL \"0\")
+ message(FATAL_ERROR \"error running testdeploy app\")
+ endif()
+ ")
+ endif()
+
+ # custom target to install and test the installation at build time
+ if(CMAKE_CONFIGURATION_TYPES)
+ set(install_config "-DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_CFG_INTDIR}")
+ endif()
+
+ add_custom_target(testdeploy_test ALL
+ COMMAND ${CMAKE_COMMAND} ${install_config} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
+ COMMENT "${CMAKE_COMMAND} ${install_config} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake"
+ DEPENDS testdeploy)
+
+endif()
diff --git a/Tests/Qt4Deploy/testdeploy.cpp b/Tests/Qt4Deploy/testdeploy.cpp
new file mode 100644
index 0000000000..8b9c8d6fa5
--- /dev/null
+++ b/Tests/Qt4Deploy/testdeploy.cpp
@@ -0,0 +1,29 @@
+#include <QCoreApplication>
+#include <QSqlDatabase>
+#include <QLibraryInfo>
+#include <QDebug>
+#include <QStringList>
+
+int main(int argc, char** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ qDebug() << "App path:" << app.applicationDirPath();
+ qDebug() << "Plugin path:" << QLibraryInfo::location(QLibraryInfo::PluginsPath);
+
+ bool foundSqlite = false;
+
+ qDebug() << "Supported Database Drivers:";
+ foreach(const QString &sqlDriver, QSqlDatabase::drivers())
+ {
+ qDebug() << " " << sqlDriver;
+ if(sqlDriver == "QSQLITE")
+ foundSqlite = true;
+ }
+
+ if(foundSqlite)
+ qDebug() << "Found sqlite support from plugin.";
+ else
+ qDebug() << "Could not find sqlite support from plugin.";
+ return foundSqlite ? 0 : 1;
+}
diff --git a/Tests/Qt4Targets/CMakeLists.txt b/Tests/Qt4Targets/CMakeLists.txt
new file mode 100644
index 0000000000..ae0a02bb69
--- /dev/null
+++ b/Tests/Qt4Targets/CMakeLists.txt
@@ -0,0 +1,80 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(Qt4Targets)
+
+cmake_policy(SET CMP0020 NEW)
+
+find_package(Qt4 REQUIRED)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(Qt4Targets WIN32 main.cpp)
+target_link_libraries(Qt4Targets Qt4::QtGui)
+
+if (WIN32)
+ if (TARGET Qt4::QAxServer)
+ add_executable(activeqtexe WIN32 activeqtexe.cpp)
+ set_property(TARGET activeqtexe PROPERTY QT4_NO_LINK_QTMAIN ON)
+ target_link_libraries(activeqtexe Qt4::QAxServer Qt4::QtGui)
+ endif()
+endif()
+
+qt4_generate_moc(main_gen_test.cpp
+ "${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc"
+ TARGET Qt4GenerateMacroTest
+)
+add_executable(Qt4GenerateMacroTest WIN32 main_gen_test.cpp "${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc")
+set_property(TARGET Qt4GenerateMacroTest PROPERTY AUTOMOC OFF)
+target_include_directories(Qt4GenerateMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
+target_link_libraries(Qt4GenerateMacroTest Qt4::QtGui)
+
+qt4_wrap_cpp(moc_file mywrapobject.h
+ TARGET Qt4WrapMacroTest
+)
+add_executable(Qt4WrapMacroTest WIN32 main_wrap_test.cpp ${moc_file})
+set_property(TARGET Qt4WrapMacroTest PROPERTY AUTOMOC OFF)
+target_include_directories(Qt4WrapMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
+target_link_libraries(Qt4WrapMacroTest Qt4::QtGui)
+
+macro(test_incremental def)
+ set(timeformat "%Y%j%H%M%S")
+ try_compile(RESULT
+ "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild_${def}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/IncrementalMoc"
+ IncrementalMoc
+ CMAKE_FLAGS -D${def}=0 "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
+ OUTPUT_VARIABLE output
+ )
+ file(TIMESTAMP "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild_${def}/moc_foo.cpp" tsvar_before "${timeformat}")
+ if (NOT tsvar_before)
+ message(SEND_ERROR
+ "Unable to read timestamp from moc file from first build with -D${def}!\n"
+ "try_compile output:\n${output}"
+ )
+ endif()
+
+ execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 2) # Ensure that the timestamp will change.
+
+ try_compile(RESULT
+ "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild_${def}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/IncrementalMoc"
+ IncrementalMoc
+ CMAKE_FLAGS -D${def}=1 "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
+ OUTPUT_VARIABLE output
+ )
+ file(TIMESTAMP "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild_${def}/moc_foo.cpp" tsvar_after "${timeformat}")
+ if (NOT tsvar_after)
+ message(SEND_ERROR
+ "Unable to read timestamp from moc file from second build!\n"
+ "try_compile output:\n${output}"
+ )
+ endif()
+
+ if (NOT tsvar_after GREATER tsvar_before)
+ message(SEND_ERROR "Rebuild did not re-create moc file with -D${def}. Before: ${tsvar_before}. After: ${tsvar_after}")
+ endif()
+endmacro()
+
+test_incremental(ADD_TARGET_DEF)
+test_incremental(ADD_DIR_DEF)
diff --git a/Tests/Qt4Targets/IncrementalMoc/CMakeLists.txt b/Tests/Qt4Targets/IncrementalMoc/CMakeLists.txt
new file mode 100644
index 0000000000..65e2b64bfc
--- /dev/null
+++ b/Tests/Qt4Targets/IncrementalMoc/CMakeLists.txt
@@ -0,0 +1,21 @@
+
+cmake_minimum_required(VERSION 2.8.12)
+project(IncrementalMoc)
+
+find_package(Qt4 REQUIRED)
+
+if (ADD_TARGET_DEF)
+ set(target_args TARGET testlib)
+endif()
+
+if (ADD_DIR_DEF)
+ add_definitions(-DNEW_DEF)
+endif()
+
+qt4_generate_moc(foo.h moc_foo.cpp ${target_args})
+
+add_library(testlib foo.cpp moc_foo.cpp)
+target_link_libraries(testlib Qt4::QtCore)
+if (ADD_TARGET_DEF)
+ target_compile_definitions(testlib PRIVATE NEW_DEF)
+endif()
diff --git a/Tests/Qt4Targets/IncrementalMoc/foo.cpp b/Tests/Qt4Targets/IncrementalMoc/foo.cpp
new file mode 100644
index 0000000000..e924f7e260
--- /dev/null
+++ b/Tests/Qt4Targets/IncrementalMoc/foo.cpp
@@ -0,0 +1,8 @@
+
+#include "foo.h"
+
+Foo::Foo()
+ : QObject(0)
+{
+
+}
diff --git a/Tests/Qt4Targets/IncrementalMoc/foo.h b/Tests/Qt4Targets/IncrementalMoc/foo.h
new file mode 100644
index 0000000000..38d899f0a4
--- /dev/null
+++ b/Tests/Qt4Targets/IncrementalMoc/foo.h
@@ -0,0 +1,9 @@
+
+#include <QObject>
+
+class Foo : QObject
+{
+ Q_OBJECT
+public:
+ Foo();
+};
diff --git a/Tests/Qt4Targets/activeqtexe.cpp b/Tests/Qt4Targets/activeqtexe.cpp
new file mode 100644
index 0000000000..d4a9121732
--- /dev/null
+++ b/Tests/Qt4Targets/activeqtexe.cpp
@@ -0,0 +1,36 @@
+
+#include <QApplication>
+
+#ifndef QT_QAXSERVER_LIB
+#error Expected QT_QAXSERVER_LIB
+#endif
+
+#include <QAxFactory>
+
+class MyObject : public QObject
+{
+ Q_OBJECT
+public:
+ MyObject(QObject *parent = 0)
+ : QObject(parent)
+ {
+ }
+};
+
+QAXFACTORY_DEFAULT(MyObject,
+ "{4dc3f340-a6f7-44e4-a79b-3e9217685fbd}",
+ "{9ee49617-7d5c-441a-b833-4b068d41d751}",
+ "{13eca64b-ee2a-4f3c-aa04-5d9d975779a7}",
+ "{ce947ee3-0403-4fdc-895a-4fe779344b46}",
+ "{8de435ce-8d2a-46ac-b3b3-cb800d0547c7}");
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ QAxFactory::isServer();
+
+ return app.exec();
+}
+
+#include "activeqtexe.moc"
diff --git a/Tests/Qt4Targets/interface/myinterface.h b/Tests/Qt4Targets/interface/myinterface.h
new file mode 100644
index 0000000000..59b43adf4e
--- /dev/null
+++ b/Tests/Qt4Targets/interface/myinterface.h
@@ -0,0 +1,12 @@
+
+#ifndef MYINTERFACE_H
+#define MYINTERFACE_H
+
+class MyInterface
+{
+
+};
+
+Q_DECLARE_INTERFACE(MyInterface, "org.cmake.example.MyInterface")
+
+#endif
diff --git a/Tests/Qt4Targets/main.cpp b/Tests/Qt4Targets/main.cpp
new file mode 100644
index 0000000000..3c98c99f66
--- /dev/null
+++ b/Tests/Qt4Targets/main.cpp
@@ -0,0 +1,24 @@
+
+#include <QApplication>
+#include <QWidget>
+
+#include <QString>
+
+#ifndef QT_CORE_LIB
+#error Expected QT_CORE_LIB
+#endif
+
+#ifndef QT_GUI_LIB
+#error Expected QT_GUI_LIB
+#endif
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ QWidget w;
+ w.setWindowTitle(QString::fromLatin1("SomeTitle"));
+ w.show();
+
+ return 0;
+}
diff --git a/Tests/Qt4Targets/main_gen_test.cpp b/Tests/Qt4Targets/main_gen_test.cpp
new file mode 100644
index 0000000000..984424b1e2
--- /dev/null
+++ b/Tests/Qt4Targets/main_gen_test.cpp
@@ -0,0 +1,21 @@
+
+#include <QObject>
+
+#include "myinterface.h"
+
+class MyObject : public QObject, MyInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(MyInterface)
+public:
+ explicit MyObject(QObject *parent = 0) : QObject(parent) { }
+};
+
+int main(int argc, char **argv)
+{
+ MyObject mo;
+ mo.objectName();
+ return 0;
+}
+
+#include "main_gen_test.moc"
diff --git a/Tests/Qt4Targets/main_wrap_test.cpp b/Tests/Qt4Targets/main_wrap_test.cpp
new file mode 100644
index 0000000000..21edc7b32f
--- /dev/null
+++ b/Tests/Qt4Targets/main_wrap_test.cpp
@@ -0,0 +1,11 @@
+
+#include <QObject>
+
+#include "mywrapobject.h"
+
+int main(int argc, char **argv)
+{
+ MyWrapObject mwo;
+ mwo.objectName();
+ return 0;
+}
diff --git a/Tests/Qt4Targets/mywrapobject.h b/Tests/Qt4Targets/mywrapobject.h
new file mode 100644
index 0000000000..de23540a29
--- /dev/null
+++ b/Tests/Qt4Targets/mywrapobject.h
@@ -0,0 +1,17 @@
+
+#ifndef MYWRAPOBJECT_H
+#define MYWRAPOBJECT_H
+
+#include <QObject>
+
+#include "myinterface.h"
+
+class MyWrapObject : public QObject, MyInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(MyInterface)
+public:
+ explicit MyWrapObject(QObject *parent = 0) : QObject(parent) { }
+};
+
+#endif
diff --git a/Tests/QtAutoUicInterface/CMakeLists.txt b/Tests/QtAutoUicInterface/CMakeLists.txt
new file mode 100644
index 0000000000..555f01689b
--- /dev/null
+++ b/Tests/QtAutoUicInterface/CMakeLists.txt
@@ -0,0 +1,70 @@
+
+cmake_minimum_required(VERSION 2.8.12)
+
+project(QtAutoUicInterface)
+
+if (QT_TEST_VERSION STREQUAL 4)
+ find_package(Qt4 REQUIRED)
+
+ include(UseQt4)
+
+ set(QT_CORE_TARGET Qt4::QtCore)
+ set(QT_GUI_TARGET Qt4::QtGui)
+else()
+ if (NOT QT_TEST_VERSION STREQUAL 5)
+ message(SEND_ERROR "Invalid Qt version specified.")
+ endif()
+ find_package(Qt5Widgets REQUIRED)
+
+ set(QT_CORE_TARGET Qt5::Core)
+ set(QT_GUI_TARGET Qt5::Widgets)
+endif()
+
+set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTOUIC ON)
+
+# BEGIN Upstream
+
+set(CMAKE_VERBOSE_MAKEFILE ON)
+
+add_library(KI18n klocalizedstring.cpp)
+target_link_libraries(KI18n ${QT_CORE_TARGET})
+
+set(autouic_options
+ -tr tr2$<$<NOT:$<BOOL:$<TARGET_PROPERTY:NO_KUIT_SEMANTIC>>>:x>i18n
+)
+if (NOT Qt5Widgets_VERSION VERSION_LESS 5.3.0)
+ list(APPEND autouic_options -include klocalizedstring.h)
+endif()
+
+set_property(TARGET KI18n APPEND PROPERTY
+ INTERFACE_AUTOUIC_OPTIONS ${autouic_options}
+)
+
+set(domainProp $<TARGET_PROPERTY:TRANSLATION_DOMAIN>)
+set(nameLower $<LOWER_CASE:$<MAKE_C_IDENTIFIER:$<TARGET_PROPERTY:NAME>>>)
+set(domain_logic
+ $<$<BOOL:${domainProp}>:${domainProp}>$<$<NOT:$<BOOL:${domainProp}>>:${nameLower}>
+)
+set_property(TARGET KI18n APPEND PROPERTY
+ INTERFACE_COMPILE_DEFINITIONS "TRANSLATION_DOMAIN=${domain_logic}"
+)
+
+# END upstream
+
+add_library(LibWidget libwidget.cpp)
+target_link_libraries(LibWidget KI18n ${QT_GUI_TARGET})
+set_property(TARGET LibWidget PROPERTY NO_KUIT_SEMANTIC ON)
+set_property(TARGET LibWidget PROPERTY TRANSLATION_DOMAIN customdomain)
+
+add_library(MyWidget mywidget.cpp)
+target_link_libraries(MyWidget KI18n ${QT_GUI_TARGET})
+
+add_executable(QtAutoUicInterface main.cpp)
+target_compile_definitions(QtAutoUicInterface
+ PRIVATE
+ UI_LIBWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/ui_libwidget.h"
+ UI_MYWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/ui_mywidget.h"
+)
diff --git a/Tests/QtAutoUicInterface/klocalizedstring.cpp b/Tests/QtAutoUicInterface/klocalizedstring.cpp
new file mode 100644
index 0000000000..f2324bb096
--- /dev/null
+++ b/Tests/QtAutoUicInterface/klocalizedstring.cpp
@@ -0,0 +1,12 @@
+
+#include "klocalizedstring.h"
+
+QString tr2xi18n(const char *text, const char *)
+{
+ return QLatin1String("TranslatedX") + QString::fromLatin1(text);
+}
+
+QString tr2i18n(const char *text, const char *)
+{
+ return QLatin1String("Translated") + QString::fromLatin1(text);
+}
diff --git a/Tests/QtAutoUicInterface/klocalizedstring.h b/Tests/QtAutoUicInterface/klocalizedstring.h
new file mode 100644
index 0000000000..559058fa32
--- /dev/null
+++ b/Tests/QtAutoUicInterface/klocalizedstring.h
@@ -0,0 +1,17 @@
+
+#ifndef KLOCALIZEDSTRING_H
+#define KLOCALIZEDSTRING_H
+
+#include <QString>
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+QString tr2xi18n(const char *text, const char *comment = 0);
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+QString tr2i18n(const char *text, const char *comment = 0);
+
+#endif
diff --git a/Tests/QtAutoUicInterface/libwidget.cpp b/Tests/QtAutoUicInterface/libwidget.cpp
new file mode 100644
index 0000000000..8a921b397d
--- /dev/null
+++ b/Tests/QtAutoUicInterface/libwidget.cpp
@@ -0,0 +1,9 @@
+
+#include "libwidget.h"
+
+LibWidget::LibWidget(QWidget *parent)
+ : QWidget(parent),
+ ui(new Ui::LibWidget)
+{
+ ui->setupUi(this);
+}
diff --git a/Tests/QtAutoUicInterface/libwidget.h b/Tests/QtAutoUicInterface/libwidget.h
new file mode 100644
index 0000000000..8b592ecfc4
--- /dev/null
+++ b/Tests/QtAutoUicInterface/libwidget.h
@@ -0,0 +1,24 @@
+
+#ifndef LIBWIDGET_H
+#define LIBWIDGET_H
+
+#include <QWidget>
+#include <memory>
+
+#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
+#include <klocalizedstring.h>
+#endif
+
+#include "ui_libwidget.h"
+
+class LibWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit LibWidget(QWidget *parent = 0);
+
+private:
+ const std::auto_ptr<Ui::LibWidget> ui;
+};
+
+#endif
diff --git a/Tests/QtAutoUicInterface/libwidget.ui b/Tests/QtAutoUicInterface/libwidget.ui
new file mode 100644
index 0000000000..897371e4a3
--- /dev/null
+++ b/Tests/QtAutoUicInterface/libwidget.ui
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LibWidget</class>
+ <widget class="QWidget" name="LibWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <widget class="QLabel" name="label">
+ <property name="geometry">
+ <rect>
+ <x>180</x>
+ <y>60</y>
+ <width>57</width>
+ <height>15</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>LibLabel</string>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutoUicInterface/main.cpp b/Tests/QtAutoUicInterface/main.cpp
new file mode 100644
index 0000000000..42d59588e0
--- /dev/null
+++ b/Tests/QtAutoUicInterface/main.cpp
@@ -0,0 +1,75 @@
+
+#include <fstream>
+#include <iostream>
+#include <string>
+
+int main(int argc, char **argv)
+{
+ std::ifstream f;
+ f.open(UI_LIBWIDGET_H);
+ if (!f.is_open())
+ {
+ std::cout << "Could not open \"" UI_LIBWIDGET_H "\"." << std::endl;
+ return -1;
+ }
+
+ {
+ bool gotTr2i18n = false;
+
+ while (!f.eof())
+ {
+ std::string output;
+ getline(f, output);
+ if (!gotTr2i18n)
+ {
+ gotTr2i18n = output.find("tr2i18n") != std::string::npos;
+ }
+ if (output.find("tr2xi18n") != std::string::npos)
+ {
+ std::cout << "ui_libwidget,h uses tr2xi18n, though it should not." << std::endl;
+ return -1;
+ }
+ }
+
+ if (!gotTr2i18n)
+ {
+ std::cout << "Did not find tr2i18n in ui_libwidget.h" << std::endl;
+ return -1;
+ }
+ }
+
+ f.close();
+ f.open(UI_MYWIDGET_H);
+ if (!f.is_open())
+ {
+ std::cout << "Could not open \"" UI_MYWIDGET_H "\"." << std::endl;
+ return -1;
+ }
+
+ {
+ bool gotTr2xi18n = false;
+
+ while (!f.eof())
+ {
+ std::string output;
+ getline(f, output);
+ if (!gotTr2xi18n)
+ {
+ gotTr2xi18n = output.find("tr2xi18n") != std::string::npos;
+ }
+ if (output.find("tr2i18n") != std::string::npos)
+ {
+ std::cout << "ui_mywidget,h uses tr2i18n, though it should not." << std::endl;
+ return -1;
+ }
+ }
+ if (!gotTr2xi18n)
+ {
+ std::cout << "Did not find tr2xi18n in ui_mywidget.h" << std::endl;
+ return -1;
+ }
+ }
+ f.close();
+
+ return 0;
+}
diff --git a/Tests/QtAutoUicInterface/mywidget.cpp b/Tests/QtAutoUicInterface/mywidget.cpp
new file mode 100644
index 0000000000..b528b1a433
--- /dev/null
+++ b/Tests/QtAutoUicInterface/mywidget.cpp
@@ -0,0 +1,9 @@
+
+#include "mywidget.h"
+
+MyWidget::MyWidget(QWidget *parent)
+ : QWidget(parent),
+ ui(new Ui::MyWidget)
+{
+ ui->setupUi(this);
+}
diff --git a/Tests/QtAutoUicInterface/mywidget.h b/Tests/QtAutoUicInterface/mywidget.h
new file mode 100644
index 0000000000..c96fb98284
--- /dev/null
+++ b/Tests/QtAutoUicInterface/mywidget.h
@@ -0,0 +1,24 @@
+
+#ifndef MYWIDGET_H
+#define MYWIDGET_H
+
+#include <QWidget>
+#include <memory>
+
+#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
+#include <klocalizedstring.h>
+#endif
+
+#include "ui_mywidget.h"
+
+class MyWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit MyWidget(QWidget *parent = 0);
+
+private:
+ const std::auto_ptr<Ui::MyWidget> ui;
+};
+
+#endif
diff --git a/Tests/QtAutoUicInterface/mywidget.ui b/Tests/QtAutoUicInterface/mywidget.ui
new file mode 100644
index 0000000000..b2b9cc5925
--- /dev/null
+++ b/Tests/QtAutoUicInterface/mywidget.ui
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MyWidget</class>
+ <widget class="QWidget" name="MyWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <widget class="QPushButton" name="pushButton">
+ <property name="geometry">
+ <rect>
+ <x>110</x>
+ <y>40</y>
+ <width>81</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Special button</string>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/Adir/CMakeLists.txt b/Tests/QtAutogen/Adir/CMakeLists.txt
new file mode 100644
index 0000000000..a1c36ffced
--- /dev/null
+++ b/Tests/QtAutogen/Adir/CMakeLists.txt
@@ -0,0 +1,8 @@
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+
+add_library(libA SHARED libA.cpp)
+target_link_libraries(libA LINK_PUBLIC ${QT_QTCORE_TARGET})
+generate_export_header(libA)
diff --git a/Tests/QtAutogen/Adir/libA.cpp b/Tests/QtAutogen/Adir/libA.cpp
new file mode 100644
index 0000000000..3968c44154
--- /dev/null
+++ b/Tests/QtAutogen/Adir/libA.cpp
@@ -0,0 +1,13 @@
+
+#include "libA.h"
+
+LibA::LibA(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+int LibA::foo()
+{
+ return 0;
+}
diff --git a/Tests/QtAutogen/Adir/libA.h b/Tests/QtAutogen/Adir/libA.h
new file mode 100644
index 0000000000..03ad1e006e
--- /dev/null
+++ b/Tests/QtAutogen/Adir/libA.h
@@ -0,0 +1,18 @@
+
+#ifndef LIBA_H
+#define LIBA_H
+
+#include "liba_export.h"
+
+#include <QObject>
+
+class LIBA_EXPORT LibA : public QObject
+{
+ Q_OBJECT
+public:
+ explicit LibA(QObject *parent = 0);
+
+ int foo();
+};
+
+#endif
diff --git a/Tests/QtAutogen/Bdir/CMakeLists.txt b/Tests/QtAutogen/Bdir/CMakeLists.txt
new file mode 100644
index 0000000000..d9d4aa7fa3
--- /dev/null
+++ b/Tests/QtAutogen/Bdir/CMakeLists.txt
@@ -0,0 +1,10 @@
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+
+add_library(libB SHARED libB.cpp)
+generate_export_header(libB)
+
+# set_property(TARGET libB APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
+target_link_libraries(libB LINK_PUBLIC libA)
diff --git a/Tests/QtAutogen/Bdir/libB.cpp b/Tests/QtAutogen/Bdir/libB.cpp
new file mode 100644
index 0000000000..72f2cfae9e
--- /dev/null
+++ b/Tests/QtAutogen/Bdir/libB.cpp
@@ -0,0 +1,13 @@
+
+#include "libB.h"
+
+LibB::LibB(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+int LibB::foo()
+{
+ return a.foo();
+}
diff --git a/Tests/QtAutogen/Bdir/libB.h b/Tests/QtAutogen/Bdir/libB.h
new file mode 100644
index 0000000000..510c17f8fe
--- /dev/null
+++ b/Tests/QtAutogen/Bdir/libB.h
@@ -0,0 +1,21 @@
+
+#ifndef LIBB_H
+#define LIBB_H
+
+#include "libb_export.h"
+
+#include <QObject>
+#include "libA.h"
+
+class LIBB_EXPORT LibB : public QObject
+{
+ Q_OBJECT
+public:
+ explicit LibB(QObject *parent = 0);
+
+ int foo();
+private:
+ LibA a;
+};
+
+#endif
diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt
new file mode 100644
index 0000000000..3fd00b8e05
--- /dev/null
+++ b/Tests/QtAutogen/CMakeLists.txt
@@ -0,0 +1,115 @@
+cmake_minimum_required(VERSION 2.8.11)
+
+project(QtAutogen)
+
+if (QT_TEST_VERSION STREQUAL 4)
+ find_package(Qt4 REQUIRED)
+
+ # Include this directory before using the UseQt4 file.
+ add_subdirectory(defines_test)
+
+ include(UseQt4)
+
+ set(QT_QTCORE_TARGET Qt4::QtCore)
+
+ macro(qtx_wrap_cpp)
+ qt4_wrap_cpp(${ARGN})
+ endmacro()
+
+else()
+ if (NOT QT_TEST_VERSION STREQUAL 5)
+ message(SEND_ERROR "Invalid Qt version specified.")
+ endif()
+ find_package(Qt5Widgets REQUIRED)
+
+ set(QT_QTCORE_TARGET Qt5::Core)
+
+ include_directories(${Qt5Widgets_INCLUDE_DIRS})
+ set(QT_LIBRARIES Qt5::Widgets)
+
+ if(Qt5_POSITION_INDEPENDENT_CODE)
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+ endif()
+
+ macro(qtx_wrap_cpp)
+ qt5_wrap_cpp(${ARGN})
+ endmacro()
+
+endif()
+
+add_executable(rcconly rcconly.cpp second_resource.qrc)
+set_property(TARGET rcconly PROPERTY AUTORCC ON)
+target_link_libraries(rcconly ${QT_QTCORE_TARGET})
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+add_definitions(-DFOO -DSomeDefine="Barx")
+
+# enable relaxed mode so automoc can handle all the special cases:
+set(CMAKE_AUTOMOC_RELAXED_MODE TRUE)
+
+set(CMAKE_AUTOUIC ON)
+set(CMAKE_AUTORCC ON)
+
+# create an executable and two library targets, each requiring automoc:
+add_library(codeeditorLib STATIC codeeditor.cpp)
+
+add_library(privateSlot OBJECT private_slot.cpp)
+
+add_custom_target(generate_moc_input
+ COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}"
+ COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h"
+)
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h"
+ COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/myotherinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h"
+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/myotherinterface.h.in"
+)
+
+message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
+if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]" AND NOT CMAKE_CONFIGURATION_TYPES)
+ set(debug_srcs "$<$<CONFIG:Debug>:debug_class.cpp>" $<$<CONFIG:Debug>:debug_resource.qrc>)
+ add_definitions(-DTEST_DEBUG_CLASS)
+endif()
+
+add_executable(QtAutogen main.cpp calwidget.cpp second_widget.cpp foo.cpp blub.cpp bar.cpp abc.cpp
+ multiplewidgets.cpp
+ xyz.cpp yaf.cpp gadget.cpp $<TARGET_OBJECTS:privateSlot>
+ test.qrc second_resource.qrc resourcetester.cpp generated.cpp ${debug_srcs}
+)
+set_property(TARGET QtAutogen APPEND PROPERTY AUTOGEN_TARGET_DEPENDS generate_moc_input "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h")
+
+set_target_properties(QtAutogen codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE)
+
+include(GenerateExportHeader)
+# The order is relevant here. B depends on A, and B headers depend on A
+# headers both subdirectories use CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE and we
+# test that CMAKE_AUTOMOC successfully reads the include directories
+# for the build interface from those targets. There has previously been
+# a bug where caching of the include directories happened before
+# extracting the includes to pass to moc.
+add_subdirectory(Bdir)
+add_subdirectory(Adir)
+add_library(libC SHARED libC.cpp)
+set_target_properties(libC PROPERTIES AUTOMOC TRUE)
+generate_export_header(libC)
+target_link_libraries(libC LINK_PUBLIC libB)
+
+target_link_libraries(QtAutogen codeeditorLib ${QT_LIBRARIES} libC)
+
+# Add not_generated_file.qrc to the source list to get the file-level
+# dependency, but don't generate a c++ file from it. Disable the AUTORCC
+# feature for this target. This tests that qrc files in the sources don't
+# have an effect on generation if AUTORCC is off.
+add_library(empty STATIC empty.cpp not_generated_file.qrc)
+set_target_properties(empty PROPERTIES AUTORCC OFF)
+
+set_target_properties(empty PROPERTIES AUTOMOC TRUE)
+target_link_libraries(empty no_link_language)
+add_library(no_link_language STATIC empty.h)
+set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE)
+
+qtx_wrap_cpp(uicOnlyMoc sub/uiconly.h)
+add_executable(uiconly sub/uiconly.cpp ${uicOnlyMoc})
+target_link_libraries(uiconly ${QT_LIBRARIES})
diff --git a/Tests/QtAutogen/abc.cpp b/Tests/QtAutogen/abc.cpp
new file mode 100644
index 0000000000..4bbc769057
--- /dev/null
+++ b/Tests/QtAutogen/abc.cpp
@@ -0,0 +1,49 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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 "abc.h"
+#include "abc_p.h"
+
+#include <stdio.h>
+
+class PrintAbc : public QObject
+{
+ Q_OBJECT
+ public:
+ PrintAbc():QObject() {}
+ public slots:
+ void print() const { printf("abc\n"); }
+};
+
+Abc::Abc()
+:QObject()
+{
+}
+
+
+void Abc::doAbc()
+{
+ PrintAbc pa;
+ pa.print();
+ AbcP abcP;
+ abcP.doAbcP();
+}
+
+// check that including the moc file for the cpp file and the header works:
+#include "abc.moc"
+#include "moc_abc.cpp"
+#include "moc_abc_p.cpp"
+
+// check that including a moc file from another header works:
+#include "moc_xyz.cpp"
diff --git a/Tests/QtAutogen/abc.h b/Tests/QtAutogen/abc.h
new file mode 100644
index 0000000000..d1924b0da3
--- /dev/null
+++ b/Tests/QtAutogen/abc.h
@@ -0,0 +1,28 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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.
+============================================================================*/
+
+#ifndef ABC_H
+#define ABC_H
+
+#include <QObject>
+
+class Abc : public QObject
+{
+ Q_OBJECT
+ public:
+ Abc();
+ public slots:
+ void doAbc();
+};
+
+#endif
diff --git a/Tests/QtAutogen/abc_p.h b/Tests/QtAutogen/abc_p.h
new file mode 100644
index 0000000000..952fff315c
--- /dev/null
+++ b/Tests/QtAutogen/abc_p.h
@@ -0,0 +1,30 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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.
+============================================================================*/
+
+#ifndef ABC_P_H
+#define ABC_P_H
+
+#include <QObject>
+
+#include <stdio.h>
+
+class AbcP : public QObject
+{
+ Q_OBJECT
+ public:
+ AbcP() {}
+ public slots:
+ void doAbcP() { printf("I am private abc !\n"); }
+};
+
+#endif
diff --git a/Tests/QtAutogen/bar.cpp b/Tests/QtAutogen/bar.cpp
new file mode 100644
index 0000000000..8be48159d0
--- /dev/null
+++ b/Tests/QtAutogen/bar.cpp
@@ -0,0 +1,28 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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 "sub/bar.h"
+
+#include <stdio.h>
+
+Bar::Bar()
+:QObject()
+{
+}
+
+void Bar::doBar()
+{
+ printf("Hello bar !\n");
+}
+
+#include "sub/moc_bar.cpp"
diff --git a/Tests/QtAutogen/blub.cpp b/Tests/QtAutogen/blub.cpp
new file mode 100644
index 0000000000..bd53972acd
--- /dev/null
+++ b/Tests/QtAutogen/blub.cpp
@@ -0,0 +1,40 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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 "blub.h"
+
+#include <stdio.h>
+
+class BlubBlub : public QObject
+{
+ Q_OBJECT
+ public:
+ BlubBlub():QObject() {}
+ public slots:
+ int getValue() const { return 13; }
+};
+
+Blub::Blub()
+{
+}
+
+
+void Blub::blubber()
+{
+ BlubBlub bb;
+ printf("Blub blub %d ! \n", bb.getValue());
+}
+
+// test the case that the wrong moc-file is included, it should
+// actually be "blub.moc"
+#include "moc_blub.cpp"
diff --git a/Tests/QtAutogen/blub.h b/Tests/QtAutogen/blub.h
new file mode 100644
index 0000000000..1967bc1ea3
--- /dev/null
+++ b/Tests/QtAutogen/blub.h
@@ -0,0 +1,26 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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.
+============================================================================*/
+
+#ifndef BLUB_H
+#define BLUB_H
+
+#include <QObject>
+
+class Blub
+{
+ public:
+ Blub();
+ void blubber();
+};
+
+#endif
diff --git a/Tests/QtAutogen/calwidget.cpp b/Tests/QtAutogen/calwidget.cpp
new file mode 100644
index 0000000000..defde20067
--- /dev/null
+++ b/Tests/QtAutogen/calwidget.cpp
@@ -0,0 +1,434 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ ** All rights reserved.
+ ** Contact: Nokia Corporation (qt-info@nokia.com)
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:BSD$
+ ** You may use this file under the terms of the BSD license as follows:
+ **
+ ** "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 Nokia Corporation and its Subsidiary(-ies) 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
+ ** 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."
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+ #include <QComboBox>
+ #include <QGridLayout>
+ #include <QLabel>
+ #include <QGroupBox>
+ #include <QCheckBox>
+ #include <QDateEdit>
+ #include <QCalendarWidget>
+ #include <QTextCharFormat>
+
+ #include "calwidget.h"
+
+ #include "ui_calwidget.h"
+
+ Window::Window()
+ : ui(new Ui::Window)
+ {
+ createPreviewGroupBox();
+ createGeneralOptionsGroupBox();
+ createDatesGroupBox();
+ createTextFormatsGroupBox();
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(previewGroupBox, 0, 0);
+ layout->addWidget(generalOptionsGroupBox, 0, 1);
+ layout->addWidget(datesGroupBox, 1, 0);
+ layout->addWidget(textFormatsGroupBox, 1, 1);
+ layout->setSizeConstraint(QLayout::SetFixedSize);
+ setLayout(layout);
+
+ previewLayout->setRowMinimumHeight(0, calendar->sizeHint().height());
+ previewLayout->setColumnMinimumWidth(0, calendar->sizeHint().width());
+
+ setWindowTitle(tr("Calendar Widget"));
+ }
+
+ void Window::localeChanged(int index)
+ {
+ calendar->setLocale(localeCombo->itemData(index).toLocale());
+ }
+
+ void Window::firstDayChanged(int index)
+ {
+ calendar->setFirstDayOfWeek(Qt::DayOfWeek(
+ firstDayCombo->itemData(index).toInt()));
+ }
+
+ void Window::selectionModeChanged(int index)
+ {
+ calendar->setSelectionMode(QCalendarWidget::SelectionMode(
+ selectionModeCombo->itemData(index).toInt()));
+ }
+
+ void Window::horizontalHeaderChanged(int index)
+ {
+ calendar->setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat(
+ horizontalHeaderCombo->itemData(index).toInt()));
+ }
+
+ void Window::verticalHeaderChanged(int index)
+ {
+ calendar->setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat(
+ verticalHeaderCombo->itemData(index).toInt()));
+ }
+
+ void Window::selectedDateChanged()
+ {
+ currentDateEdit->setDate(calendar->selectedDate());
+ }
+
+ void Window::minimumDateChanged(const QDate &date)
+ {
+ calendar->setMinimumDate(date);
+ maximumDateEdit->setDate(calendar->maximumDate());
+ }
+
+ void Window::maximumDateChanged(const QDate &date)
+ {
+ calendar->setMaximumDate(date);
+ minimumDateEdit->setDate(calendar->minimumDate());
+ }
+
+ void Window::weekdayFormatChanged()
+ {
+ QTextCharFormat format;
+
+ format.setForeground(qvariant_cast<QColor>(
+ weekdayColorCombo->itemData(weekdayColorCombo->currentIndex())));
+ calendar->setWeekdayTextFormat(Qt::Monday, format);
+ calendar->setWeekdayTextFormat(Qt::Tuesday, format);
+ calendar->setWeekdayTextFormat(Qt::Wednesday, format);
+ calendar->setWeekdayTextFormat(Qt::Thursday, format);
+ calendar->setWeekdayTextFormat(Qt::Friday, format);
+ }
+
+ void Window::weekendFormatChanged()
+ {
+ QTextCharFormat format;
+
+ format.setForeground(qvariant_cast<QColor>(
+ weekendColorCombo->itemData(weekendColorCombo->currentIndex())));
+ calendar->setWeekdayTextFormat(Qt::Saturday, format);
+ calendar->setWeekdayTextFormat(Qt::Sunday, format);
+ }
+
+ void Window::reformatHeaders()
+ {
+ QString text = headerTextFormatCombo->currentText();
+ QTextCharFormat format;
+
+ if (text == tr("Bold")) {
+ format.setFontWeight(QFont::Bold);
+ } else if (text == tr("Italic")) {
+ format.setFontItalic(true);
+ } else if (text == tr("Green")) {
+ format.setForeground(Qt::green);
+ }
+ calendar->setHeaderTextFormat(format);
+ }
+
+ void Window::reformatCalendarPage()
+ {
+ if (firstFridayCheckBox->isChecked()) {
+ QDate firstFriday(calendar->yearShown(), calendar->monthShown(), 1);
+ while (firstFriday.dayOfWeek() != Qt::Friday)
+ firstFriday = firstFriday.addDays(1);
+ QTextCharFormat firstFridayFormat;
+ firstFridayFormat.setForeground(Qt::blue);
+ calendar->setDateTextFormat(firstFriday, firstFridayFormat);
+ }
+
+ //May First in Red takes precedence
+ if (mayFirstCheckBox->isChecked()) {
+ const QDate mayFirst(calendar->yearShown(), 5, 1);
+ QTextCharFormat mayFirstFormat;
+ mayFirstFormat.setForeground(Qt::red);
+ calendar->setDateTextFormat(mayFirst, mayFirstFormat);
+ }
+ }
+
+ void Window::createPreviewGroupBox()
+ {
+ previewGroupBox = new QGroupBox(tr("Preview"));
+
+ calendar = new QCalendarWidget;
+ calendar->setMinimumDate(QDate(1900, 1, 1));
+ calendar->setMaximumDate(QDate(3000, 1, 1));
+ calendar->setGridVisible(true);
+
+ connect(calendar, SIGNAL(currentPageChanged(int,int)),
+ this, SLOT(reformatCalendarPage()));
+
+ previewLayout = new QGridLayout;
+ previewLayout->addWidget(calendar, 0, 0, Qt::AlignCenter);
+ previewGroupBox->setLayout(previewLayout);
+ }
+
+ void Window::createGeneralOptionsGroupBox()
+ {
+ generalOptionsGroupBox = new QGroupBox(tr("General Options"));
+
+ localeCombo = new QComboBox;
+ int curLocaleIndex = -1;
+ int index = 0;
+ for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
+ QLocale::Language lang = static_cast<QLocale::Language>(_lang);
+ QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);
+ for (int i = 0; i < countries.count(); ++i) {
+ QLocale::Country country = countries.at(i);
+ QString label = QLocale::languageToString(lang);
+ label += QLatin1Char('/');
+ label += QLocale::countryToString(country);
+ QLocale locale(lang, country);
+ if (this->locale().language() == lang && this->locale().country() == country)
+ curLocaleIndex = index;
+ localeCombo->addItem(label, locale);
+ ++index;
+ }
+ }
+ if (curLocaleIndex != -1)
+ localeCombo->setCurrentIndex(curLocaleIndex);
+ localeLabel = new QLabel(tr("&Locale"));
+ localeLabel->setBuddy(localeCombo);
+
+ firstDayCombo = new QComboBox;
+ firstDayCombo->addItem(tr("Sunday"), Qt::Sunday);
+ firstDayCombo->addItem(tr("Monday"), Qt::Monday);
+ firstDayCombo->addItem(tr("Tuesday"), Qt::Tuesday);
+ firstDayCombo->addItem(tr("Wednesday"), Qt::Wednesday);
+ firstDayCombo->addItem(tr("Thursday"), Qt::Thursday);
+ firstDayCombo->addItem(tr("Friday"), Qt::Friday);
+ firstDayCombo->addItem(tr("Saturday"), Qt::Saturday);
+
+ firstDayLabel = new QLabel(tr("Wee&k starts on:"));
+ firstDayLabel->setBuddy(firstDayCombo);
+
+ selectionModeCombo = new QComboBox;
+ selectionModeCombo->addItem(tr("Single selection"),
+ QCalendarWidget::SingleSelection);
+ selectionModeCombo->addItem(tr("None"), QCalendarWidget::NoSelection);
+
+ selectionModeLabel = new QLabel(tr("&Selection mode:"));
+ selectionModeLabel->setBuddy(selectionModeCombo);
+
+ gridCheckBox = new QCheckBox(tr("&Grid"));
+ gridCheckBox->setChecked(calendar->isGridVisible());
+
+ navigationCheckBox = new QCheckBox(tr("&Navigation bar"));
+ navigationCheckBox->setChecked(true);
+
+ horizontalHeaderCombo = new QComboBox;
+ horizontalHeaderCombo->addItem(tr("Single letter day names"),
+ QCalendarWidget::SingleLetterDayNames);
+ horizontalHeaderCombo->addItem(tr("Short day names"),
+ QCalendarWidget::ShortDayNames);
+ horizontalHeaderCombo->addItem(tr("None"),
+ QCalendarWidget::NoHorizontalHeader);
+ horizontalHeaderCombo->setCurrentIndex(1);
+
+ horizontalHeaderLabel = new QLabel(tr("&Horizontal header:"));
+ horizontalHeaderLabel->setBuddy(horizontalHeaderCombo);
+
+ verticalHeaderCombo = new QComboBox;
+ verticalHeaderCombo->addItem(tr("ISO week numbers"),
+ QCalendarWidget::ISOWeekNumbers);
+ verticalHeaderCombo->addItem(tr("None"), QCalendarWidget::NoVerticalHeader);
+
+ verticalHeaderLabel = new QLabel(tr("&Vertical header:"));
+ verticalHeaderLabel->setBuddy(verticalHeaderCombo);
+
+ connect(localeCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(localeChanged(int)));
+ connect(firstDayCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(firstDayChanged(int)));
+ connect(selectionModeCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(selectionModeChanged(int)));
+ connect(gridCheckBox, SIGNAL(toggled(bool)),
+ calendar, SLOT(setGridVisible(bool)));
+ connect(navigationCheckBox, SIGNAL(toggled(bool)),
+ calendar, SLOT(setNavigationBarVisible(bool)));
+ connect(horizontalHeaderCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(horizontalHeaderChanged(int)));
+ connect(verticalHeaderCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(verticalHeaderChanged(int)));
+
+ QHBoxLayout *checkBoxLayout = new QHBoxLayout;
+ checkBoxLayout->addWidget(gridCheckBox);
+ checkBoxLayout->addStretch();
+ checkBoxLayout->addWidget(navigationCheckBox);
+
+ QGridLayout *outerLayout = new QGridLayout;
+ outerLayout->addWidget(localeLabel, 0, 0);
+ outerLayout->addWidget(localeCombo, 0, 1);
+ outerLayout->addWidget(firstDayLabel, 1, 0);
+ outerLayout->addWidget(firstDayCombo, 1, 1);
+ outerLayout->addWidget(selectionModeLabel, 2, 0);
+ outerLayout->addWidget(selectionModeCombo, 2, 1);
+ outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2);
+ outerLayout->addWidget(horizontalHeaderLabel, 4, 0);
+ outerLayout->addWidget(horizontalHeaderCombo, 4, 1);
+ outerLayout->addWidget(verticalHeaderLabel, 5, 0);
+ outerLayout->addWidget(verticalHeaderCombo, 5, 1);
+ generalOptionsGroupBox->setLayout(outerLayout);
+
+ firstDayChanged(firstDayCombo->currentIndex());
+ selectionModeChanged(selectionModeCombo->currentIndex());
+ horizontalHeaderChanged(horizontalHeaderCombo->currentIndex());
+ verticalHeaderChanged(verticalHeaderCombo->currentIndex());
+ }
+
+ void Window::createDatesGroupBox()
+ {
+ datesGroupBox = new QGroupBox(tr("Dates"));
+
+ minimumDateEdit = new QDateEdit;
+ minimumDateEdit->setDisplayFormat("MMM d yyyy");
+ minimumDateEdit->setDateRange(calendar->minimumDate(),
+ calendar->maximumDate());
+ minimumDateEdit->setDate(calendar->minimumDate());
+
+ minimumDateLabel = new QLabel(tr("&Minimum Date:"));
+ minimumDateLabel->setBuddy(minimumDateEdit);
+
+ currentDateEdit = new QDateEdit;
+ currentDateEdit->setDisplayFormat("MMM d yyyy");
+ currentDateEdit->setDate(calendar->selectedDate());
+ currentDateEdit->setDateRange(calendar->minimumDate(),
+ calendar->maximumDate());
+
+ currentDateLabel = new QLabel(tr("&Current Date:"));
+ currentDateLabel->setBuddy(currentDateEdit);
+
+ maximumDateEdit = new QDateEdit;
+ maximumDateEdit->setDisplayFormat("MMM d yyyy");
+ maximumDateEdit->setDateRange(calendar->minimumDate(),
+ calendar->maximumDate());
+ maximumDateEdit->setDate(calendar->maximumDate());
+
+ maximumDateLabel = new QLabel(tr("Ma&ximum Date:"));
+ maximumDateLabel->setBuddy(maximumDateEdit);
+
+ connect(currentDateEdit, SIGNAL(dateChanged(QDate)),
+ calendar, SLOT(setSelectedDate(QDate)));
+ connect(calendar, SIGNAL(selectionChanged()),
+ this, SLOT(selectedDateChanged()));
+ connect(minimumDateEdit, SIGNAL(dateChanged(QDate)),
+ this, SLOT(minimumDateChanged(QDate)));
+ connect(maximumDateEdit, SIGNAL(dateChanged(QDate)),
+ this, SLOT(maximumDateChanged(QDate)));
+
+ QGridLayout *dateBoxLayout = new QGridLayout;
+ dateBoxLayout->addWidget(currentDateLabel, 1, 0);
+ dateBoxLayout->addWidget(currentDateEdit, 1, 1);
+ dateBoxLayout->addWidget(minimumDateLabel, 0, 0);
+ dateBoxLayout->addWidget(minimumDateEdit, 0, 1);
+ dateBoxLayout->addWidget(maximumDateLabel, 2, 0);
+ dateBoxLayout->addWidget(maximumDateEdit, 2, 1);
+ dateBoxLayout->setRowStretch(3, 1);
+
+ datesGroupBox->setLayout(dateBoxLayout);
+ }
+
+ void Window::createTextFormatsGroupBox()
+ {
+ textFormatsGroupBox = new QGroupBox(tr("Text Formats"));
+
+ weekdayColorCombo = createColorComboBox();
+ weekdayColorCombo->setCurrentIndex(
+ weekdayColorCombo->findText(tr("Black")));
+
+ weekdayColorLabel = new QLabel(tr("&Weekday color:"));
+ weekdayColorLabel->setBuddy(weekdayColorCombo);
+
+ weekendColorCombo = createColorComboBox();
+ weekendColorCombo->setCurrentIndex(
+ weekendColorCombo->findText(tr("Red")));
+
+ weekendColorLabel = new QLabel(tr("Week&end color:"));
+ weekendColorLabel->setBuddy(weekendColorCombo);
+
+ headerTextFormatCombo = new QComboBox;
+ headerTextFormatCombo->addItem(tr("Bold"));
+ headerTextFormatCombo->addItem(tr("Italic"));
+ headerTextFormatCombo->addItem(tr("Plain"));
+
+ headerTextFormatLabel = new QLabel(tr("&Header text:"));
+ headerTextFormatLabel->setBuddy(headerTextFormatCombo);
+
+ firstFridayCheckBox = new QCheckBox(tr("&First Friday in blue"));
+
+ mayFirstCheckBox = new QCheckBox(tr("May &1 in red"));
+
+ connect(weekdayColorCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(weekdayFormatChanged()));
+ connect(weekendColorCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(weekendFormatChanged()));
+ connect(headerTextFormatCombo, SIGNAL(currentIndexChanged(QString)),
+ this, SLOT(reformatHeaders()));
+ connect(firstFridayCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(reformatCalendarPage()));
+ connect(mayFirstCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(reformatCalendarPage()));
+
+ QHBoxLayout *checkBoxLayout = new QHBoxLayout;
+ checkBoxLayout->addWidget(firstFridayCheckBox);
+ checkBoxLayout->addStretch();
+ checkBoxLayout->addWidget(mayFirstCheckBox);
+
+ QGridLayout *outerLayout = new QGridLayout;
+ outerLayout->addWidget(weekdayColorLabel, 0, 0);
+ outerLayout->addWidget(weekdayColorCombo, 0, 1);
+ outerLayout->addWidget(weekendColorLabel, 1, 0);
+ outerLayout->addWidget(weekendColorCombo, 1, 1);
+ outerLayout->addWidget(headerTextFormatLabel, 2, 0);
+ outerLayout->addWidget(headerTextFormatCombo, 2, 1);
+ outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2);
+ textFormatsGroupBox->setLayout(outerLayout);
+
+ weekdayFormatChanged();
+ weekendFormatChanged();
+ reformatHeaders();
+ reformatCalendarPage();
+ }
+
+QComboBox *Window::createColorComboBox()
+ {
+ QComboBox *comboBox = new QComboBox;
+ comboBox->addItem(tr("Red"), QColor(Qt::red));
+ comboBox->addItem(tr("Blue"), QColor(Qt::blue));
+ comboBox->addItem(tr("Black"), QColor(Qt::black));
+ comboBox->addItem(tr("Magenta"), QColor(Qt::magenta));
+ return comboBox;
+ }
+
+//#include "moc_calwidget.cpp"
diff --git a/Tests/QtAutogen/calwidget.h b/Tests/QtAutogen/calwidget.h
new file mode 100644
index 0000000000..d21a473de3
--- /dev/null
+++ b/Tests/QtAutogen/calwidget.h
@@ -0,0 +1,128 @@
+ /****************************************************************************
+ **
+ ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ ** All rights reserved.
+ ** Contact: Nokia Corporation (qt-info@nokia.com)
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:BSD$
+ ** You may use this file under the terms of the BSD license as follows:
+ **
+ ** "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 Nokia Corporation and its Subsidiary(-ies) 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
+ ** 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."
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+ class QCalendarWidget;
+ class QCheckBox;
+ class QComboBox;
+ class QDate;
+ class QDateEdit;
+ class QGridLayout;
+ class QGroupBox;
+ class QLabel;
+
+ namespace Ui
+ {
+ class Window;
+ }
+
+ class Window : public QWidget
+ {
+ Q_OBJECT
+
+ public:
+ Window();
+
+ private slots:
+ void localeChanged(int index);
+ void firstDayChanged(int index);
+ void selectionModeChanged(int index);
+ void horizontalHeaderChanged(int index);
+ void verticalHeaderChanged(int index);
+ void selectedDateChanged();
+ void minimumDateChanged(const QDate &date);
+ void maximumDateChanged(const QDate &date);
+ void weekdayFormatChanged();
+ void weekendFormatChanged();
+ void reformatHeaders();
+ void reformatCalendarPage();
+
+ private:
+ void createPreviewGroupBox();
+ void createGeneralOptionsGroupBox();
+ void createDatesGroupBox();
+ void createTextFormatsGroupBox();
+ QComboBox *createColorComboBox();
+
+ QGroupBox *previewGroupBox;
+ QGridLayout *previewLayout;
+ QCalendarWidget *calendar;
+
+ QGroupBox *generalOptionsGroupBox;
+ QLabel *localeLabel;
+ QLabel *firstDayLabel;
+ QLabel *selectionModeLabel;
+ QLabel *horizontalHeaderLabel;
+ QLabel *verticalHeaderLabel;
+ QComboBox *localeCombo;
+ QComboBox *firstDayCombo;
+ QComboBox *selectionModeCombo;
+ QCheckBox *gridCheckBox;
+ QCheckBox *navigationCheckBox;
+ QComboBox *horizontalHeaderCombo;
+ QComboBox *verticalHeaderCombo;
+
+ QGroupBox *datesGroupBox;
+ QLabel *currentDateLabel;
+ QLabel *minimumDateLabel;
+ QLabel *maximumDateLabel;
+ QDateEdit *currentDateEdit;
+ QDateEdit *minimumDateEdit;
+ QDateEdit *maximumDateEdit;
+
+ QGroupBox *textFormatsGroupBox;
+ QLabel *weekdayColorLabel;
+ QLabel *weekendColorLabel;
+ QLabel *headerTextFormatLabel;
+ QComboBox *weekdayColorCombo;
+ QComboBox *weekendColorCombo;
+ QComboBox *headerTextFormatCombo;
+
+ QCheckBox *firstFridayCheckBox;
+ QCheckBox *mayFirstCheckBox;
+
+ Ui::Window *ui;
+ };
+
+ #endif
diff --git a/Tests/QtAutogen/calwidget.ui b/Tests/QtAutogen/calwidget.ui
new file mode 100644
index 0000000000..1c245cac94
--- /dev/null
+++ b/Tests/QtAutogen/calwidget.ui
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Window</class>
+ <widget class="QWidget" name="Window">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <widget class="QPushButton" name="pushButton">
+ <property name="geometry">
+ <rect>
+ <x>90</x>
+ <y>180</y>
+ <width>94</width>
+ <height>24</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>PushButton</string>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/codeeditor.cpp b/Tests/QtAutogen/codeeditor.cpp
new file mode 100644
index 0000000000..01da062765
--- /dev/null
+++ b/Tests/QtAutogen/codeeditor.cpp
@@ -0,0 +1,153 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ ** All rights reserved.
+ ** Contact: Nokia Corporation (qt-info@nokia.com)
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:BSD$
+ ** You may use this file under the terms of the BSD license as follows:
+ **
+ ** "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 Nokia Corporation and its Subsidiary(-ies) 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
+ ** 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."
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+ #include <QtGui>
+
+ #include "codeeditor.h"
+
+
+ CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
+ {
+ lineNumberArea = new LineNumberArea(this);
+
+ connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
+ connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
+ connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
+
+ updateLineNumberAreaWidth(0);
+ highlightCurrentLine();
+ }
+
+
+
+ int CodeEditor::lineNumberAreaWidth()
+ {
+ int digits = 1;
+ int max = qMax(1, blockCount());
+ while (max >= 10) {
+ max /= 10;
+ ++digits;
+ }
+
+ int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
+
+ return space;
+ }
+
+
+
+ void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
+ {
+ setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
+ }
+
+
+
+ void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
+ {
+ if (dy)
+ lineNumberArea->scroll(0, dy);
+ else
+ lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
+
+ if (rect.contains(viewport()->rect()))
+ updateLineNumberAreaWidth(0);
+ }
+
+
+
+ void CodeEditor::resizeEvent(QResizeEvent *e)
+ {
+ QPlainTextEdit::resizeEvent(e);
+
+ QRect cr = contentsRect();
+ lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
+ }
+
+
+
+ void CodeEditor::highlightCurrentLine()
+ {
+ QList<QTextEdit::ExtraSelection> extraSelections;
+
+ if (!isReadOnly()) {
+ QTextEdit::ExtraSelection selection;
+
+ QColor lineColor = QColor(Qt::yellow).lighter(160);
+
+ selection.format.setBackground(lineColor);
+ selection.format.setProperty(QTextFormat::FullWidthSelection, true);
+ selection.cursor = textCursor();
+ selection.cursor.clearSelection();
+ extraSelections.append(selection);
+ }
+
+ setExtraSelections(extraSelections);
+ }
+
+
+
+ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
+ {
+ QPainter painter(lineNumberArea);
+ painter.fillRect(event->rect(), Qt::lightGray);
+
+
+ QTextBlock block = firstVisibleBlock();
+ int blockNumber = block.blockNumber();
+ int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
+ int bottom = top + (int) blockBoundingRect(block).height();
+
+ while (block.isValid() && top <= event->rect().bottom()) {
+ if (block.isVisible() && bottom >= event->rect().top()) {
+ QString number = QString::number(blockNumber + 1);
+ painter.setPen(Qt::black);
+ painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
+ Qt::AlignRight, number);
+ }
+
+ block = block.next();
+ top = bottom;
+ bottom = top + (int) blockBoundingRect(block).height();
+ ++blockNumber;
+ }
+ }
+
+#include "codeeditor.moc"
diff --git a/Tests/QtAutogen/codeeditor.h b/Tests/QtAutogen/codeeditor.h
new file mode 100644
index 0000000000..56e9e79239
--- /dev/null
+++ b/Tests/QtAutogen/codeeditor.h
@@ -0,0 +1,99 @@
+ /****************************************************************************
+ **
+ ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ ** All rights reserved.
+ ** Contact: Nokia Corporation (qt-info@nokia.com)
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:BSD$
+ ** You may use this file under the terms of the BSD license as follows:
+ **
+ ** "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 Nokia Corporation and its Subsidiary(-ies) 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
+ ** 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."
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+ #ifndef CODEEDITOR_H
+ #define CODEEDITOR_H
+
+ #include <QPlainTextEdit>
+ #include <QObject>
+
+ class QPaintEvent;
+ class QResizeEvent;
+ class QSize;
+ class QWidget;
+
+ class LineNumberArea;
+
+
+ class CodeEditor : public QPlainTextEdit
+ {
+ Q_OBJECT
+
+ public:
+ CodeEditor(QWidget *parent = 0);
+
+ void lineNumberAreaPaintEvent(QPaintEvent *event);
+ int lineNumberAreaWidth();
+
+ protected:
+ void resizeEvent(QResizeEvent *event);
+
+ private slots:
+ void updateLineNumberAreaWidth(int newBlockCount);
+ void highlightCurrentLine();
+ void updateLineNumberArea(const QRect &, int);
+
+ private:
+ QWidget *lineNumberArea;
+ };
+
+
+ class LineNumberArea : public QWidget
+ {
+ public:
+ LineNumberArea(CodeEditor *editor) : QWidget(editor) {
+ codeEditor = editor;
+ }
+
+ QSize sizeHint() const {
+ return QSize(codeEditor->lineNumberAreaWidth(), 0);
+ }
+
+ protected:
+ void paintEvent(QPaintEvent *event) {
+ codeEditor->lineNumberAreaPaintEvent(event);
+ }
+
+ private:
+ CodeEditor *codeEditor;
+ };
+
+
+ #endif
diff --git a/Tests/QtAutogen/debug_class.cpp b/Tests/QtAutogen/debug_class.cpp
new file mode 100644
index 0000000000..58e72e46cc
--- /dev/null
+++ b/Tests/QtAutogen/debug_class.cpp
@@ -0,0 +1,9 @@
+
+#include "debug_class.h"
+#include "ui_debug_class.h"
+
+DebugClass::DebugClass(QWidget *parent)
+ : QWidget(parent), ui(new Ui::DebugClass)
+{
+ ui->setupUi(this);
+}
diff --git a/Tests/QtAutogen/debug_class.h b/Tests/QtAutogen/debug_class.h
new file mode 100644
index 0000000000..71bc1045a4
--- /dev/null
+++ b/Tests/QtAutogen/debug_class.h
@@ -0,0 +1,20 @@
+
+#include <QWidget>
+
+namespace Ui
+{
+class DebugClass;
+}
+
+class DebugClass : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit DebugClass(QWidget *parent = 0);
+
+signals:
+ void someSignal();
+
+private:
+ Ui::DebugClass *ui;
+};
diff --git a/Tests/QtAutogen/debug_class.ui b/Tests/QtAutogen/debug_class.ui
new file mode 100644
index 0000000000..dc2e1ac189
--- /dev/null
+++ b/Tests/QtAutogen/debug_class.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DebugClass</class>
+ <widget class="QWidget" name="DebugClass">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>DebugClass</string>
+ </property>
+ <widget class="QCheckBox" name="checkBox">
+ <property name="geometry">
+ <rect>
+ <x>50</x>
+ <y>20</y>
+ <width>82</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>CheckBox</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="pushButton">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>70</y>
+ <width>94</width>
+ <height>24</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>PushButton</string>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/debug_resource.qrc b/Tests/QtAutogen/debug_resource.qrc
new file mode 100644
index 0000000000..db98b9bc1e
--- /dev/null
+++ b/Tests/QtAutogen/debug_resource.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>debug_class.ui</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/defines_test/CMakeLists.txt b/Tests/QtAutogen/defines_test/CMakeLists.txt
new file mode 100644
index 0000000000..ad4e684cbf
--- /dev/null
+++ b/Tests/QtAutogen/defines_test/CMakeLists.txt
@@ -0,0 +1,6 @@
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+add_executable(defines_test defines_test.cpp)
+set_target_properties(defines_test PROPERTIES AUTOMOC TRUE)
+target_link_libraries(defines_test Qt4::QtGui)
diff --git a/Tests/QtAutogen/defines_test/defines_test.cpp b/Tests/QtAutogen/defines_test/defines_test.cpp
new file mode 100644
index 0000000000..2836d357b6
--- /dev/null
+++ b/Tests/QtAutogen/defines_test/defines_test.cpp
@@ -0,0 +1,38 @@
+
+#include <QObject>
+
+#ifdef QT_GUI_LIB
+#include <QTextDocument>
+
+class SomeDocument : public QTextDocument
+{
+ Q_OBJECT
+
+Q_SIGNALS:
+ void someSig();
+};
+#endif
+
+#ifdef QT_CORE_LIB
+class SomeObject : public QObject
+{
+ Q_OBJECT
+
+Q_SIGNALS:
+ void someSig();
+};
+#endif
+
+int main(int argc, char **argv)
+{
+#ifdef QT_CORE_LIB
+ QMetaObject sosmo = SomeObject::staticMetaObject;
+#endif
+#ifdef QT_GUI_LIB
+ QMetaObject sdsmo = SomeDocument::staticMetaObject;
+#endif
+
+ return 0;
+}
+
+#include "defines_test.moc"
diff --git a/Tests/QtAutogen/empty.cpp b/Tests/QtAutogen/empty.cpp
new file mode 100644
index 0000000000..ab32cf6c8a
--- /dev/null
+++ b/Tests/QtAutogen/empty.cpp
@@ -0,0 +1 @@
+// No content
diff --git a/Tests/QtAutogen/empty.h b/Tests/QtAutogen/empty.h
new file mode 100644
index 0000000000..4566142c14
--- /dev/null
+++ b/Tests/QtAutogen/empty.h
@@ -0,0 +1,9 @@
+
+#include <QObject>
+
+class Empty : public QObject
+{
+ Q_OBJECT
+public:
+ explicit Empty(QObject *parent = 0) {}
+};
diff --git a/Tests/QtAutogen/foo.cpp b/Tests/QtAutogen/foo.cpp
new file mode 100644
index 0000000000..699ba094b2
--- /dev/null
+++ b/Tests/QtAutogen/foo.cpp
@@ -0,0 +1,39 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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 "foo.h"
+
+#include <stdio.h>
+
+class FooFoo : public QObject
+{
+ Q_OBJECT
+ public:
+ FooFoo():QObject() {}
+ public slots:
+ int getValue() const { return 12; }
+};
+
+Foo::Foo()
+:QObject()
+{
+}
+
+
+void Foo::doFoo()
+{
+ FooFoo ff;
+ printf("Hello automoc: %d\n", ff.getValue());
+}
+
+#include "foo.moc"
diff --git a/Tests/QtAutogen/foo.h b/Tests/QtAutogen/foo.h
new file mode 100644
index 0000000000..f23ec0739f
--- /dev/null
+++ b/Tests/QtAutogen/foo.h
@@ -0,0 +1,31 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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.
+============================================================================*/
+
+#ifndef FOO_H
+#define FOO_H
+
+#include <QObject>
+
+class Foo
+#ifdef FOO
+ : public QObject
+#endif
+{
+ Q_OBJECT
+ public:
+ Foo();
+ public slots:
+ void doFoo();
+};
+
+#endif
diff --git a/Tests/QtAutogen/gadget.cpp b/Tests/QtAutogen/gadget.cpp
new file mode 100644
index 0000000000..23d95fa4a5
--- /dev/null
+++ b/Tests/QtAutogen/gadget.cpp
@@ -0,0 +1,4 @@
+
+#include "gadget.h"
+
+#include "moc_gadget.cpp"
diff --git a/Tests/QtAutogen/gadget.h b/Tests/QtAutogen/gadget.h
new file mode 100644
index 0000000000..7c688ee456
--- /dev/null
+++ b/Tests/QtAutogen/gadget.h
@@ -0,0 +1,18 @@
+
+#ifndef GADGET_H
+#define GADGET_H
+
+#include <QObject>
+
+class Gadget
+{
+ Q_GADGET
+ Q_ENUMS(Type)
+public:
+ enum Type {
+ Type0,
+ Type1
+ };
+};
+
+#endif
diff --git a/Tests/QtAutogen/generated.cpp b/Tests/QtAutogen/generated.cpp
new file mode 100644
index 0000000000..f53bf53425
--- /dev/null
+++ b/Tests/QtAutogen/generated.cpp
@@ -0,0 +1,10 @@
+
+#include "generated.h"
+
+Generated::Generated(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+#include "moc_generated.cpp"
diff --git a/Tests/QtAutogen/generated.h b/Tests/QtAutogen/generated.h
new file mode 100644
index 0000000000..b6c2711154
--- /dev/null
+++ b/Tests/QtAutogen/generated.h
@@ -0,0 +1,18 @@
+
+#ifndef GENERATED_H
+#define GENERATED_H
+
+#include <QObject>
+
+#include "myinterface.h"
+#include "myotherinterface.h"
+
+class Generated : public QObject, MyInterface, MyOtherInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(MyInterface MyOtherInterface)
+public:
+ explicit Generated(QObject *parent = 0);
+};
+
+#endif
diff --git a/Tests/QtAutogen/libC.cpp b/Tests/QtAutogen/libC.cpp
new file mode 100644
index 0000000000..8d61cb1bf8
--- /dev/null
+++ b/Tests/QtAutogen/libC.cpp
@@ -0,0 +1,13 @@
+
+#include "libC.h"
+
+LibC::LibC(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+int LibC::foo()
+{
+ return b.foo();
+}
diff --git a/Tests/QtAutogen/libC.h b/Tests/QtAutogen/libC.h
new file mode 100644
index 0000000000..4fb4a2cf4c
--- /dev/null
+++ b/Tests/QtAutogen/libC.h
@@ -0,0 +1,22 @@
+
+#ifndef LIBC_H
+#define LIBC_H
+
+#include "libc_export.h"
+
+#include <QObject>
+#include "libB.h"
+
+class LIBC_EXPORT LibC : public QObject
+{
+ Q_OBJECT
+public:
+ explicit LibC(QObject *parent = 0);
+
+
+ int foo();
+private:
+ LibB b;
+};
+
+#endif
diff --git a/Tests/QtAutogen/main.cpp b/Tests/QtAutogen/main.cpp
new file mode 100644
index 0000000000..eb596650e5
--- /dev/null
+++ b/Tests/QtAutogen/main.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ ** All rights reserved.
+ ** Contact: Nokia Corporation (qt-info@nokia.com)
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:BSD$
+ ** You may use this file under the terms of the BSD license as follows:
+ **
+ ** "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 Nokia Corporation and its Subsidiary(-ies) 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
+ ** 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."
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+#include <QCoreApplication>
+#include <QTimer>
+
+#include "codeeditor.h"
+#include "calwidget.h"
+#include "foo.h"
+#include "blub.h"
+#include "sub/bar.h"
+#include "abc.h"
+#include "xyz.h"
+#include "yaf.h"
+#include "libC.h"
+#include "resourcetester.h"
+#ifdef TEST_DEBUG_CLASS
+#include "debug_class.h"
+#include <iostream>
+#endif
+
+
+int main(int argv, char **args)
+{
+ QCoreApplication app(argv, args);
+
+ Foo foo;
+ foo.doFoo();
+
+ Blub b;
+ b.blubber();
+
+ Bar bar;
+ bar.doBar();
+
+ Abc abc;
+ abc.doAbc();
+
+ Xyz xyz;
+ xyz.doXyz();
+
+ Yaf yaf;
+ yaf.doYaf();
+
+ LibC lc;
+ lc.foo();
+
+ ResourceTester rt;
+
+ QTimer::singleShot(0, &rt, SLOT(doTest()));
+
+#ifdef TEST_DEBUG_CLASS
+ std::cout << DebugClass::staticMetaObject.className() << std::endl;
+#endif
+
+ return app.exec();
+}
diff --git a/Tests/QtAutogen/multiplewidgets.cpp b/Tests/QtAutogen/multiplewidgets.cpp
new file mode 100644
index 0000000000..f143875914
--- /dev/null
+++ b/Tests/QtAutogen/multiplewidgets.cpp
@@ -0,0 +1,19 @@
+
+#include "multiplewidgets.h"
+
+#include "ui_widget1.h"
+#include "ui_widget2.h"
+
+Widget1::Widget1(QWidget *parent)
+ : QWidget(parent),
+ ui(new Ui::Widget1)
+{
+ ui->setupUi(this);
+}
+
+Widget2::Widget2(QWidget *parent)
+ : QWidget(parent),
+ ui(new Ui::Widget2)
+{
+ ui->setupUi(this);
+}
diff --git a/Tests/QtAutogen/multiplewidgets.h b/Tests/QtAutogen/multiplewidgets.h
new file mode 100644
index 0000000000..6ae6ad1258
--- /dev/null
+++ b/Tests/QtAutogen/multiplewidgets.h
@@ -0,0 +1,33 @@
+
+#ifndef MULTIPLEWIDGETS_H
+#define MULTIPLEWIDGETS_H
+
+#include <QWidget>
+
+namespace Ui {
+class Widget1;
+}
+
+class Widget1 : public QWidget
+{
+ Q_OBJECT
+public:
+ Widget1(QWidget *parent = 0);
+private:
+ Ui::Widget1 *ui;
+};
+
+namespace Ui {
+class Widget2;
+}
+
+class Widget2 : public QWidget
+{
+ Q_OBJECT
+public:
+ Widget2(QWidget *parent = 0);
+private:
+ Ui::Widget2 *ui;
+};
+
+#endif
diff --git a/Tests/QtAutogen/myinterface.h.in b/Tests/QtAutogen/myinterface.h.in
new file mode 100644
index 0000000000..c6c0ba1b6e
--- /dev/null
+++ b/Tests/QtAutogen/myinterface.h.in
@@ -0,0 +1,14 @@
+
+#ifndef MYINTERFACE_H
+#define MYINTERFACE_H
+
+#include <QObject>
+
+class MyInterface
+{
+
+};
+
+Q_DECLARE_INTERFACE(MyInterface, "org.cmake.example.MyInterface")
+
+#endif
diff --git a/Tests/QtAutogen/myotherinterface.h.in b/Tests/QtAutogen/myotherinterface.h.in
new file mode 100644
index 0000000000..d21e7af7c2
--- /dev/null
+++ b/Tests/QtAutogen/myotherinterface.h.in
@@ -0,0 +1,14 @@
+
+#ifndef MYOTHERINTERFACE_H
+#define MYOTHERINTERFACE_H
+
+#include <QObject>
+
+class MyOtherInterface
+{
+
+};
+
+Q_DECLARE_INTERFACE(MyOtherInterface, "org.cmake.example.MyOtherInterface")
+
+#endif
diff --git a/Tests/QtAutogen/not_generated_file.qrc b/Tests/QtAutogen/not_generated_file.qrc
new file mode 100644
index 0000000000..c7698343a7
--- /dev/null
+++ b/Tests/QtAutogen/not_generated_file.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>abc.cpp</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/private_slot.cpp b/Tests/QtAutogen/private_slot.cpp
new file mode 100644
index 0000000000..1387a70cfa
--- /dev/null
+++ b/Tests/QtAutogen/private_slot.cpp
@@ -0,0 +1,21 @@
+
+#include "private_slot.h"
+
+class PrivateSlotPrivate
+{
+public:
+
+ void privateSlot()
+ {
+
+ }
+};
+
+PrivateSlot::PrivateSlot(QObject *parent)
+ : QObject(parent),
+ d(new PrivateSlotPrivate)
+{
+
+}
+
+#include "private_slot.moc"
diff --git a/Tests/QtAutogen/private_slot.h b/Tests/QtAutogen/private_slot.h
new file mode 100644
index 0000000000..28e54482a9
--- /dev/null
+++ b/Tests/QtAutogen/private_slot.h
@@ -0,0 +1,20 @@
+
+#ifndef PRIVATE_SLOT_H
+#define PRIVATE_SLOT_H
+
+#include <QObject>
+
+class PrivateSlotPrivate;
+
+class PrivateSlot : public QObject
+{
+ Q_OBJECT
+public:
+ PrivateSlot(QObject *parent = 0);
+
+private:
+ PrivateSlotPrivate * const d;
+ Q_PRIVATE_SLOT(d, void privateSlot())
+};
+
+#endif
diff --git a/Tests/QtAutogen/rcconly.cpp b/Tests/QtAutogen/rcconly.cpp
new file mode 100644
index 0000000000..854c4c1bc0
--- /dev/null
+++ b/Tests/QtAutogen/rcconly.cpp
@@ -0,0 +1,9 @@
+
+extern int qInitResources_second_resource();
+
+int main(int, char**)
+{
+ // Fails to link if the symbol is not present.
+ qInitResources_second_resource();
+ return 0;
+}
diff --git a/Tests/QtAutogen/resourcetester.cpp b/Tests/QtAutogen/resourcetester.cpp
new file mode 100644
index 0000000000..043ec75fc3
--- /dev/null
+++ b/Tests/QtAutogen/resourcetester.cpp
@@ -0,0 +1,27 @@
+
+#include "resourcetester.h"
+
+#include <QDebug>
+#include <QApplication>
+#include <QFile>
+#include <QTimer>
+
+ResourceTester::ResourceTester(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+void ResourceTester::doTest()
+{
+ if (!QFile::exists(":/CMakeLists.txt"))
+ qApp->exit(EXIT_FAILURE);
+ if (!QFile::exists(":/main.cpp"))
+ qApp->exit(EXIT_FAILURE);
+#ifdef TEST_DEBUG_CLASS
+ if (!QFile::exists(":/debug_class.ui"))
+ qApp->exit(EXIT_FAILURE);
+#endif
+
+ QTimer::singleShot(0, qApp, SLOT(quit()));
+}
diff --git a/Tests/QtAutogen/resourcetester.h b/Tests/QtAutogen/resourcetester.h
new file mode 100644
index 0000000000..b02cb4ed27
--- /dev/null
+++ b/Tests/QtAutogen/resourcetester.h
@@ -0,0 +1,17 @@
+
+#ifndef RESOURCE_TESTER_H
+#define RESOURCE_TESTER_H
+
+#include <QObject>
+
+class ResourceTester : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ResourceTester(QObject *parent = 0);
+
+private slots:
+ void doTest();
+};
+
+#endif
diff --git a/Tests/QtAutogen/second_resource.qrc b/Tests/QtAutogen/second_resource.qrc
new file mode 100644
index 0000000000..27bfb143b9
--- /dev/null
+++ b/Tests/QtAutogen/second_resource.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>main.cpp</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/second_widget.cpp b/Tests/QtAutogen/second_widget.cpp
new file mode 100644
index 0000000000..65ba9627c5
--- /dev/null
+++ b/Tests/QtAutogen/second_widget.cpp
@@ -0,0 +1,14 @@
+
+#include "second_widget.h"
+#include "ui_second_widget.h"
+
+SecondWidget::SecondWidget(QWidget *parent)
+ : QWidget(parent), ui(new Ui::SecondWidget)
+{
+ ui->setupUi(this);
+}
+
+SecondWidget::~SecondWidget()
+{
+ delete ui;
+}
diff --git a/Tests/QtAutogen/second_widget.h b/Tests/QtAutogen/second_widget.h
new file mode 100644
index 0000000000..fe4d175f71
--- /dev/null
+++ b/Tests/QtAutogen/second_widget.h
@@ -0,0 +1,19 @@
+
+#include <QWidget>
+
+namespace Ui
+{
+class SecondWidget;
+}
+
+class SecondWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit SecondWidget(QWidget *parent = 0);
+
+ ~SecondWidget();
+
+private:
+ Ui::SecondWidget* ui;
+};
diff --git a/Tests/QtAutogen/second_widget.ui b/Tests/QtAutogen/second_widget.ui
new file mode 100644
index 0000000000..4effa589c4
--- /dev/null
+++ b/Tests/QtAutogen/second_widget.ui
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SecondWidget</class>
+ <widget class="QWidget" name="SecondWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <widget class="QPushButton" name="pushButton">
+ <property name="geometry">
+ <rect>
+ <x>80</x>
+ <y>20</y>
+ <width>94</width>
+ <height>24</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>PushButton</string>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/sub/bar.h b/Tests/QtAutogen/sub/bar.h
new file mode 100644
index 0000000000..db56b8ed58
--- /dev/null
+++ b/Tests/QtAutogen/sub/bar.h
@@ -0,0 +1,28 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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.
+============================================================================*/
+
+#ifndef BAR_H
+#define BAR_H
+
+#include <QObject>
+
+class Bar : public QObject
+{
+ Q_OBJECT
+ public:
+ Bar();
+ public slots:
+ void doBar();
+};
+
+#endif
diff --git a/Tests/QtAutogen/sub/uiconly.cpp b/Tests/QtAutogen/sub/uiconly.cpp
new file mode 100644
index 0000000000..cdb33184d9
--- /dev/null
+++ b/Tests/QtAutogen/sub/uiconly.cpp
@@ -0,0 +1,13 @@
+
+#include "uiconly.h"
+
+UicOnly::UicOnly(QWidget *parent)
+ : QWidget(parent), ui(new Ui::UicOnly)
+{
+
+}
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/QtAutogen/sub/uiconly.h b/Tests/QtAutogen/sub/uiconly.h
new file mode 100644
index 0000000000..9e21f82e48
--- /dev/null
+++ b/Tests/QtAutogen/sub/uiconly.h
@@ -0,0 +1,20 @@
+
+#ifndef UIC_ONLY_H
+#define UIC_ONLY_H
+
+#include <QWidget>
+#include <memory>
+
+#include "ui_uiconly.h"
+
+class UicOnly : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit UicOnly(QWidget *parent = 0);
+
+private:
+ const std::auto_ptr<Ui::UicOnly> ui;
+};
+
+#endif
diff --git a/Tests/QtAutogen/sub/uiconly.ui b/Tests/QtAutogen/sub/uiconly.ui
new file mode 100644
index 0000000000..13fb832eb7
--- /dev/null
+++ b/Tests/QtAutogen/sub/uiconly.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UicOnly</class>
+ <widget class="QWidget" name="UicOnly">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QTreeView" name="treeView"/>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/test.qrc b/Tests/QtAutogen/test.qrc
new file mode 100644
index 0000000000..c3d4e3cdbe
--- /dev/null
+++ b/Tests/QtAutogen/test.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>CMakeLists.txt</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/widget1.ui b/Tests/QtAutogen/widget1.ui
new file mode 100644
index 0000000000..8fce81a9a2
--- /dev/null
+++ b/Tests/QtAutogen/widget1.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Widget1</class>
+ <widget class="QWidget" name="Widget1">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <widget class="QPushButton" name="pushButton">
+ <property name="geometry">
+ <rect>
+ <x>140</x>
+ <y>80</y>
+ <width>80</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>PushButton</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="pushButton_2">
+ <property name="geometry">
+ <rect>
+ <x>190</x>
+ <y>170</y>
+ <width>80</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>PushButton</string>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/widget2.ui b/Tests/QtAutogen/widget2.ui
new file mode 100644
index 0000000000..1f411b9fb9
--- /dev/null
+++ b/Tests/QtAutogen/widget2.ui
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Widget2</class>
+ <widget class="QWidget" name="Widget1">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <widget class="QListWidget" name="listWidget">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>20</y>
+ <width>256</width>
+ <height>192</height>
+ </rect>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/xyz.cpp b/Tests/QtAutogen/xyz.cpp
new file mode 100644
index 0000000000..a3562a3371
--- /dev/null
+++ b/Tests/QtAutogen/xyz.cpp
@@ -0,0 +1,28 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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 "xyz.h"
+
+#include <stdio.h>
+
+Xyz::Xyz()
+:QObject()
+{
+}
+
+
+void Xyz::doXyz()
+{
+ printf("This is xyz !\n");
+}
diff --git a/Tests/QtAutogen/xyz.h b/Tests/QtAutogen/xyz.h
new file mode 100644
index 0000000000..8175d3792b
--- /dev/null
+++ b/Tests/QtAutogen/xyz.h
@@ -0,0 +1,28 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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.
+============================================================================*/
+
+#ifndef XYZ_H
+#define XYZ_H
+
+#include <QObject>
+
+class Xyz : public QObject
+{
+ Q_OBJECT
+ public:
+ Xyz();
+ public slots:
+ void doXyz();
+};
+
+#endif
diff --git a/Tests/QtAutogen/yaf.cpp b/Tests/QtAutogen/yaf.cpp
new file mode 100644
index 0000000000..d278ab4227
--- /dev/null
+++ b/Tests/QtAutogen/yaf.cpp
@@ -0,0 +1,32 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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 "yaf.h"
+#include "yaf_p.h"
+
+#include <stdio.h>
+
+Yaf::Yaf()
+{
+}
+
+
+void Yaf::doYaf()
+{
+ YafP yafP;
+ yafP.doYafP();
+}
+
+// check that including a moc file from a private header the wrong way works:
+#include "yaf_p.moc"
diff --git a/Tests/QtAutogen/yaf.h b/Tests/QtAutogen/yaf.h
new file mode 100644
index 0000000000..8689f83084
--- /dev/null
+++ b/Tests/QtAutogen/yaf.h
@@ -0,0 +1,25 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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.
+============================================================================*/
+
+#ifndef YAF_H
+#define YAF_H
+
+class Yaf
+{
+ public:
+ Yaf();
+ public:
+ void doYaf();
+};
+
+#endif
diff --git a/Tests/QtAutogen/yaf_p.h b/Tests/QtAutogen/yaf_p.h
new file mode 100644
index 0000000000..f0368ade1c
--- /dev/null
+++ b/Tests/QtAutogen/yaf_p.h
@@ -0,0 +1,30 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2004-2011 Kitware, Inc.
+ Copyright 2011 Alexander Neundorf (neundorf@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.
+============================================================================*/
+
+#ifndef YAF_P_H
+#define YAF_P_H
+
+#include <QObject>
+
+#include <stdio.h>
+
+class YafP : public QObject
+{
+ Q_OBJECT
+ public:
+ YafP() {}
+ public slots:
+ void doYafP() { printf("I am yet another file !\n"); }
+};
+
+#endif
diff --git a/Tests/QtAutomocNoQt/CMakeLists.txt b/Tests/QtAutomocNoQt/CMakeLists.txt
new file mode 100644
index 0000000000..b26e471174
--- /dev/null
+++ b/Tests/QtAutomocNoQt/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(QtAutomocNoQt)
+
+set(CMAKE_AUTOMOC ON)
+
+add_executable(hello main.c)
diff --git a/Tests/QtAutomocNoQt/main.c b/Tests/QtAutomocNoQt/main.c
new file mode 100644
index 0000000000..8488f4e58f
--- /dev/null
+++ b/Tests/QtAutomocNoQt/main.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/README b/Tests/README
new file mode 100644
index 0000000000..8b2fda8454
--- /dev/null
+++ b/Tests/README
@@ -0,0 +1,39 @@
+If you think about adding a new testcase then here is a small checklist you
+can run through to find a proper place for it. Go through the list from the
+beginning and stop once you find something that matches your tests needs,
+i.e. if you will test a module and only need the configure mode use the
+instructions from section 2, not 3.
+
+1. Your testcase can run in CMake script mode, i.e. "cmake -P something"
+
+Put your test in Tests/CMakeTests/ directory as a .cmake.in file. It will be
+put into the test binary directory by configure_file(... @ONLY) and run from
+there. Use the AddCMakeTest() macro in Tests/CMakeTests/CMakeLists.txt to add
+your test to the test runs.
+
+2. Your test needs CMake to run in configure mode, but will not build anything
+
+This includes tests that will build something using try_compile() and friends,
+but nothing that expects add_executable(), add_library(), or add_test() to run.
+
+If the test configures the project only once and it must succeed then put it
+into the Tests/CMakeOnly/ directory. Create a subdirectory named like your
+test and write the CMakeLists.txt you need into that subdirectory. Use the
+add_CMakeOnly_test() macro from Tests/CMakeOnly/CMakeLists.txt to add your
+test to the test runs.
+
+If the test configures the project with multiple variations and verifies
+success or failure each time then put it into the Tests/RunCMake/ directory.
+Read the instructions in Tests/RunCMake/CMakeLists.txt to add a test.
+
+3. If you are testing something from the Modules directory
+
+Put your test in the Tests/Modules/ directory. Create a subdirectory there
+named after your test. Use the ADD_TEST_MACRO macro from Tests/CMakeLists.txt
+to add your test to the test run. If you have put your stuff in
+Tests/Modules/Foo then you call it using ADD_TEST_MACRO(Module.Foo Foo).
+
+4. You are doing other stuff.
+
+Find a good place ;) In doubt mail to cmake-developers@cmake.org and ask for
+advise.
diff --git a/Tests/RegexEscapeString.cmake b/Tests/RegexEscapeString.cmake
new file mode 100644
index 0000000000..92aed17b1f
--- /dev/null
+++ b/Tests/RegexEscapeString.cmake
@@ -0,0 +1,4 @@
+macro(REGEX_ESCAPE_STRING _OUT _IN)
+ # Escape special regex metacharacters with a backslash
+ string(REGEX REPLACE "([$^.[|*+?()]|])" "\\\\\\1" ${_OUT} "${_IN}")
+endmacro()
diff --git a/Tests/ReturnTest/CMakeLists.txt b/Tests/ReturnTest/CMakeLists.txt
new file mode 100644
index 0000000000..c4c606c58c
--- /dev/null
+++ b/Tests/ReturnTest/CMakeLists.txt
@@ -0,0 +1,147 @@
+# a simple C only test case
+cmake_minimum_required (VERSION 2.6)
+project (ReturnTest)
+
+function (FAILED testname)
+ message (SEND_ERROR "${testname} failed ${ARGN}")
+endfunction ()
+
+function (PASS testname)
+ message ("${testname} passed ${ARGN}")
+endfunction ()
+
+# test simple return
+function (simple)
+ set(simpleResult 1 PARENT_SCOPE)
+ return()
+ set(simpleResult 0 PARENT_SCOPE)
+endfunction ()
+simple()
+if ("${simpleResult}")
+ pass ("simple")
+else ()
+ failed ("simple got: ${simpleResult}")
+endif ()
+
+#test return in an if statement
+set (simple2IF 1)
+function (simple2)
+ set(simple2Result 1 PARENT_SCOPE)
+ if (simple2IF)
+ return()
+ endif ()
+ set(simple2Result 0 PARENT_SCOPE)
+endfunction ()
+simple2()
+if ("${simple2Result}")
+ pass ("simple2")
+else ()
+ failed ("simple2 got: ${simple2Result}")
+endif ()
+
+#test return in a foreach loop
+function (looptest)
+ foreach (iter RANGE 1 5)
+ set (looptestResult "${iter}" PARENT_SCOPE)
+ if ("${iter}" EQUAL 3)
+ return ()
+ endif ()
+ endforeach ()
+endfunction ()
+looptest()
+if ("${looptestResult}" EQUAL 3)
+ pass ("looptest")
+else ()
+ failed ("looptest got: ${looptestResult}")
+endif ()
+
+#test return in a while loop
+function (whiletest)
+ set (iter "a")
+ while(NOT "${iter}" STREQUAL "aaaaa")
+ set (whiletestResult "${iter}" PARENT_SCOPE)
+ if ("${iter}" STREQUAL "aaa")
+ return ()
+ endif ()
+ set (iter "${iter}a")
+ endwhile()
+endfunction ()
+whiletest()
+if ("${whiletestResult}" STREQUAL "aaa")
+ pass ("whiletest")
+else ()
+ failed ("whiletest got: ${whiletestResult}")
+endif ()
+
+# check subdir return
+add_subdirectory(subdir)
+get_directory_property(subdirResult DIRECTORY subdir DEFINITION subdirreturn)
+if ("${subdirResult}" EQUAL 1)
+ pass ("subdir")
+else ()
+ failed ("subdir got: ${subdirResult}")
+endif ()
+
+# check return from a file
+include(include_return.cmake)
+if ("${include_returnResult}" EQUAL 1)
+ pass ("include_return")
+else ()
+ failed ("include_return got: ${include_returnResult}")
+endif ()
+
+# check return from within a macro
+macro (mymacro)
+ set (foo 1)
+ if (foo)
+ return()
+ endif ()
+endmacro()
+
+# test simple return
+function (simple3)
+ set (bar 0)
+ set(simple3Result 1 PARENT_SCOPE)
+ if (bar)
+ else ()
+ mymacro()
+ endif()
+ set(simple3Result 0 PARENT_SCOPE)
+endfunction ()
+simple3()
+if ("${simple3Result}")
+ pass ("macrotest")
+else ()
+ failed ("macrotest got: ${simple3Result}")
+endif ()
+
+
+# test break command now in a foreach
+foreach (iter RANGE 1 5)
+ set (break1 "${iter}")
+ if ("${iter}" EQUAL 3)
+ break ()
+ endif ()
+endforeach ()
+if ("${break1}" EQUAL 3)
+ pass ("break in foreach")
+else ()
+ failed ("break in foreach got: ${break1}")
+endif ()
+
+# test break in a while loop
+set (iter "a")
+while(NOT "${iter}" STREQUAL "aaaaa")
+ if ("${iter}" STREQUAL "aaa")
+ break ()
+ endif ()
+ set (iter "${iter}a")
+endwhile()
+if ("${iter}" STREQUAL "aaa")
+ pass ("break in a while")
+else ()
+ failed ("break in a while got: ${whiletestResult}")
+endif ()
+
+
+add_executable (ReturnTest returnTest.c)
diff --git a/Tests/ReturnTest/include_return.cmake b/Tests/ReturnTest/include_return.cmake
new file mode 100644
index 0000000000..7cea1fb2d4
--- /dev/null
+++ b/Tests/ReturnTest/include_return.cmake
@@ -0,0 +1,3 @@
+set(include_returnResult 1)
+return()
+set(include_returnResult 0)
diff --git a/Tests/ReturnTest/returnTest.c b/Tests/ReturnTest/returnTest.c
new file mode 100644
index 0000000000..e0ced6afd1
--- /dev/null
+++ b/Tests/ReturnTest/returnTest.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char* argv[])
+{
+ printf("Running command: %s with %d arguments\n", argv[0], argc);
+ return 0;
+}
diff --git a/Tests/ReturnTest/subdir/CMakeLists.txt b/Tests/ReturnTest/subdir/CMakeLists.txt
new file mode 100644
index 0000000000..b9510924f4
--- /dev/null
+++ b/Tests/ReturnTest/subdir/CMakeLists.txt
@@ -0,0 +1,3 @@
+set (subdirreturn 1)
+return()
+set (subdirreturn 0)
diff --git a/Tests/RunCMake/CMP0004/CMP0004-NEW-result.txt b/Tests/RunCMake/CMP0004/CMP0004-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0004/CMP0004-NEW-stderr.txt b/Tests/RunCMake/CMP0004/CMP0004-NEW-stderr.txt
new file mode 100644
index 0000000000..a21cb6ae3a
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-NEW-stderr.txt
@@ -0,0 +1,2 @@
+ Target "foo" links to item " bar " which has leading or trailing
+ whitespace. This is now an error according to policy CMP0004.
diff --git a/Tests/RunCMake/CMP0004/CMP0004-NEW.cmake b/Tests/RunCMake/CMP0004/CMP0004-NEW.cmake
new file mode 100644
index 0000000000..f42d8e49dc
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-NEW.cmake
@@ -0,0 +1,9 @@
+
+cmake_minimum_required(VERSION 2.8.4)
+
+cmake_policy(SET CMP0004 NEW)
+
+add_library(foo SHARED empty.cpp)
+add_library(bar SHARED empty.cpp)
+
+target_link_libraries(foo "$<1: bar >")
diff --git a/Tests/RunCMake/CMP0004/CMP0004-OLD-result.txt b/Tests/RunCMake/CMP0004/CMP0004-OLD-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-OLD-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0004/CMP0004-OLD-stderr.txt b/Tests/RunCMake/CMP0004/CMP0004-OLD-stderr.txt
new file mode 100644
index 0000000000..782e45c577
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-OLD-stderr.txt
@@ -0,0 +1,2 @@
+ Target "bat" links to item " bar " which has leading or trailing
+ whitespace. This is now an error according to policy CMP0004.
diff --git a/Tests/RunCMake/CMP0004/CMP0004-OLD.cmake b/Tests/RunCMake/CMP0004/CMP0004-OLD.cmake
new file mode 100644
index 0000000000..3fa58b6b6a
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-OLD.cmake
@@ -0,0 +1,21 @@
+
+cmake_minimum_required(VERSION 2.8.4)
+
+cmake_policy(SET CMP0004 OLD)
+
+add_library(foo SHARED empty.cpp)
+add_library(bar SHARED empty.cpp)
+add_library(bing SHARED empty.cpp)
+add_library(bung SHARED empty.cpp)
+
+cmake_policy(SET CMP0004 NEW)
+
+add_library(bat SHARED empty.cpp)
+
+target_link_libraries(foo "$<1: bar >")
+target_link_libraries(bing "$<$<NOT:$<TARGET_POLICY:CMP0004>>: bar >")
+target_link_libraries(bung "$<$<TARGET_POLICY:CMP0004>: bar >")
+
+# The line below causes the error because the policy is NEW when bat
+# is created.
+target_link_libraries(bat "$<1: bar >")
diff --git a/Tests/RunCMake/CMP0004/CMP0004-WARN-stderr.txt b/Tests/RunCMake/CMP0004/CMP0004-WARN-stderr.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-WARN-stderr.txt
diff --git a/Tests/RunCMake/CMP0004/CMP0004-policy-genex-result.txt b/Tests/RunCMake/CMP0004/CMP0004-policy-genex-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-policy-genex-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0004/CMP0004-policy-genex-stderr.txt b/Tests/RunCMake/CMP0004/CMP0004-policy-genex-stderr.txt
new file mode 100644
index 0000000000..eed53e7f46
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-policy-genex-stderr.txt
@@ -0,0 +1,2 @@
+ Target "foo" links to item " bat " which has leading or trailing
+ whitespace. This is now an error according to policy CMP0004.
diff --git a/Tests/RunCMake/CMP0004/CMP0004-policy-genex.cmake b/Tests/RunCMake/CMP0004/CMP0004-policy-genex.cmake
new file mode 100644
index 0000000000..297047662c
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMP0004-policy-genex.cmake
@@ -0,0 +1,14 @@
+
+cmake_minimum_required(VERSION 2.8.4)
+
+cmake_policy(SET CMP0004 NEW)
+
+add_library(foo SHARED empty.cpp)
+add_library(bar SHARED empty.cpp)
+add_library(bat SHARED empty.cpp)
+
+# The negation here avoids the error.
+target_link_libraries(foo "$<$<NOT:$<TARGET_POLICY:CMP0004>>: bar >")
+
+# The below line causes the error.
+target_link_libraries(foo "$<$<TARGET_POLICY:CMP0004>: bat >")
diff --git a/Tests/RunCMake/CMP0004/CMakeLists.txt b/Tests/RunCMake/CMP0004/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0004/RunCMakeTest.cmake b/Tests/RunCMake/CMP0004/RunCMakeTest.cmake
new file mode 100644
index 0000000000..950d0edbd4
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0004-OLD)
+run_cmake(CMP0004-NEW)
+run_cmake(CMP0004-policy-genex)
diff --git a/Tests/RunCMake/CMP0004/empty.cpp b/Tests/RunCMake/CMP0004/empty.cpp
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/CMP0004/empty.cpp
diff --git a/Tests/RunCMake/CMP0019/CMP0019-NEW.cmake b/Tests/RunCMake/CMP0019/CMP0019-NEW.cmake
new file mode 100644
index 0000000000..3091e66ac7
--- /dev/null
+++ b/Tests/RunCMake/CMP0019/CMP0019-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0019 NEW)
+include(CMP0019-code.cmake)
diff --git a/Tests/RunCMake/CMP0019/CMP0019-OLD.cmake b/Tests/RunCMake/CMP0019/CMP0019-OLD.cmake
new file mode 100644
index 0000000000..0f02f9ce57
--- /dev/null
+++ b/Tests/RunCMake/CMP0019/CMP0019-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0019 OLD)
+include(CMP0019-code.cmake)
diff --git a/Tests/RunCMake/CMP0019/CMP0019-WARN-stderr.txt b/Tests/RunCMake/CMP0019/CMP0019-WARN-stderr.txt
new file mode 100644
index 0000000000..03faef90ed
--- /dev/null
+++ b/Tests/RunCMake/CMP0019/CMP0019-WARN-stderr.txt
@@ -0,0 +1,40 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+ Policy CMP0019 is not set: Do not re-expand variables in include and link
+ information. Run "cmake --help-policy CMP0019" for policy details. Use
+ the cmake_policy command to set the policy and suppress this warning.
+
+ The following variable evaluations were encountered:
+
+ Evaluated directory INCLUDE_DIRECTORIES
+
+ /usr/include/\${VAR_INCLUDE};/usr/include/normal
+
+ as
+
+ /usr/include/VAL_INCLUDE;/usr/include/normal
+
+ Evaluated target some_target INCLUDE_DIRECTORIES
+
+ /usr/include/\${VAR_INCLUDE};/usr/include/normal
+
+ as
+
+ /usr/include/VAL_INCLUDE;/usr/include/normal
+
+ Evaluated link directory
+
+ /usr/lib/\${VAR_LINK_DIRS}
+
+ as
+
+ /usr/lib/VAL_LINK_DIRS
+
+ Evaluated link library
+
+ \${VAR_LINK_LIBS}
+
+ as
+
+ VAL_LINK_LIBS
+
+This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/CMP0019/CMP0019-WARN.cmake b/Tests/RunCMake/CMP0019/CMP0019-WARN.cmake
new file mode 100644
index 0000000000..a419f309e3
--- /dev/null
+++ b/Tests/RunCMake/CMP0019/CMP0019-WARN.cmake
@@ -0,0 +1 @@
+include(CMP0019-code.cmake)
diff --git a/Tests/RunCMake/CMP0019/CMP0019-code.cmake b/Tests/RunCMake/CMP0019/CMP0019-code.cmake
new file mode 100644
index 0000000000..26c0e5b27e
--- /dev/null
+++ b/Tests/RunCMake/CMP0019/CMP0019-code.cmake
@@ -0,0 +1,9 @@
+set(VAR_INCLUDE "VAL_INCLUDE")
+set(VAR_LINK_DIRS "VAL_LINK_DIRS")
+set(VAR_LINK_LIBS "VAL_LINK_LIBS")
+add_custom_target(some_target)
+include_directories("/usr/include/\${VAR_INCLUDE}" /usr/include/normal)
+link_directories("/usr/lib/\${VAR_LINK_DIRS}" /usr/lib/normal)
+link_libraries("\${VAR_LINK_LIBS}" normal)
+add_custom_target(other_target)
+set_property(TARGET other_target PROPERTY INCLUDE_DIRECTORIES "")
diff --git a/Tests/RunCMake/CMP0019/CMakeLists.txt b/Tests/RunCMake/CMP0019/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/CMP0019/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0019/RunCMakeTest.cmake b/Tests/RunCMake/CMP0019/RunCMakeTest.cmake
new file mode 100644
index 0000000000..119fc2b300
--- /dev/null
+++ b/Tests/RunCMake/CMP0019/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0019-WARN)
+run_cmake(CMP0019-OLD)
+run_cmake(CMP0019-NEW)
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-exe-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-exe-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-exe-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-exe.cmake b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-exe.cmake
new file mode 100644
index 0000000000..b0268c8428
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-exe.cmake
@@ -0,0 +1,7 @@
+enable_language(CXX)
+
+add_library(testLib empty_vs6_1.cpp)
+add_executable(testExe empty_vs6_2.cpp)
+target_link_libraries(testExe testLib)
+
+export(TARGETS testExe FILE "${CMAKE_CURRENT_BINARY_DIR}/cmp0022NOWARN-exe.cmake")
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-shared-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-shared-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-shared-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-shared.cmake b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-shared.cmake
new file mode 100644
index 0000000000..2e76ee0df0
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-shared.cmake
@@ -0,0 +1,10 @@
+enable_language(CXX)
+
+cmake_policy(SET CMP0042 NEW)
+
+add_library(foo SHARED empty_vs6_1.cpp)
+add_library(bar SHARED empty_vs6_2.cpp)
+target_link_libraries(bar foo)
+
+add_executable(zot empty.cpp)
+target_link_libraries(zot bar)
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-NEW-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-NEW-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-NEW-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-NEW.cmake b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-NEW.cmake
new file mode 100644
index 0000000000..3fee15d8b9
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-NEW.cmake
@@ -0,0 +1,14 @@
+
+project(CMP0022-NOWARN-static-NEW)
+
+cmake_policy(SET CMP0022 NEW)
+
+add_library(foo STATIC empty_vs6_1.cpp)
+add_library(bar STATIC empty_vs6_2.cpp)
+add_library(bat STATIC empty_vs6_3.cpp)
+target_link_libraries(foo bar)
+# The last element here needs to contain a space so that it is a single
+# element which is not a valid target name. As bar is a STATIC library,
+# this tests that the LINK_ONLY generator expression is not used for
+# that element, creating an error.
+target_link_libraries(bar LINK_PRIVATE bat "-lz -lm")
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-link_libraries-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-link_libraries-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-link_libraries-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-link_libraries.cmake b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-link_libraries.cmake
new file mode 100644
index 0000000000..42c4084a6f
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-link_libraries.cmake
@@ -0,0 +1,9 @@
+
+enable_language(CXX)
+
+add_subdirectory(dep1)
+add_subdirectory(dep2)
+add_subdirectory(dep3)
+
+add_library(somelib empty.cpp)
+target_link_libraries(somelib dep3)
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static.cmake b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static.cmake
new file mode 100644
index 0000000000..3e4144fcd5
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-NOWARN-static.cmake
@@ -0,0 +1,8 @@
+
+project(CMP0022-NOWARN-static)
+
+add_library(foo STATIC empty_vs6_1.cpp)
+add_library(bar STATIC empty_vs6_2.cpp)
+add_library(bat STATIC empty_vs6_3.cpp)
+target_link_libraries(foo bar)
+target_link_libraries(bar bat)
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-result.txt b/Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-stderr.txt
new file mode 100644
index 0000000000..6a6a0c782c
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-stderr.txt
@@ -0,0 +1,19 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+ Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
+ interface. Run "cmake --help-policy CMP0022" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "bar" has an INTERFACE_LINK_LIBRARIES property. This should be
+ preferred as the source of the link interface for this library but because
+ CMP0022 is not set CMake is ignoring the property and using the link
+ implementation as the link interface instead.
+
+ INTERFACE_LINK_LIBRARIES:
+
+ foo
+
+ Link implementation:
+
+ \(empty\)
+
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old.cmake b/Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old.cmake
new file mode 100644
index 0000000000..c5d3c29d9f
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old.cmake
@@ -0,0 +1,10 @@
+
+project(CMP0022-WARN-empty-old)
+
+add_library(foo SHARED empty_vs6_1.cpp)
+add_library(bar SHARED empty_vs6_2.cpp)
+
+set_property(TARGET bar PROPERTY INTERFACE_LINK_LIBRARIES foo)
+
+add_library(user empty.cpp)
+target_link_libraries(user bar)
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-static-result.txt b/Tests/RunCMake/CMP0022/CMP0022-WARN-static-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-static-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-static-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-WARN-static-stderr.txt
new file mode 100644
index 0000000000..1370c5ebe7
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-static-stderr.txt
@@ -0,0 +1,19 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+ Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
+ interface. Run "cmake --help-policy CMP0022" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "bar" has an INTERFACE_LINK_LIBRARIES property. This should be
+ preferred as the source of the link interface for this library but because
+ CMP0022 is not set CMake is ignoring the property and using the link
+ implementation as the link interface instead.
+
+ INTERFACE_LINK_LIBRARIES:
+
+ foo
+
+ Link implementation:
+
+ bat
+
+This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-static.cmake b/Tests/RunCMake/CMP0022/CMP0022-WARN-static.cmake
new file mode 100644
index 0000000000..b3cb13160a
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-static.cmake
@@ -0,0 +1,11 @@
+
+project(CMP0022-WARN)
+
+add_library(foo STATIC empty_vs6_1.cpp)
+add_library(bar STATIC empty_vs6_2.cpp)
+add_library(bat STATIC empty_vs6_3.cpp)
+set_property(TARGET bar PROPERTY INTERFACE_LINK_LIBRARIES foo)
+set_property(TARGET bar PROPERTY LINK_LIBRARIES bat)
+
+add_library(user empty.cpp)
+target_link_libraries(user bar)
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-WARN-stderr.txt
new file mode 100644
index 0000000000..2f7dfbfb7f
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-stderr.txt
@@ -0,0 +1,17 @@
+^CMake Warning \(dev\) in CMakeLists.txt:
+ Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
+ interface. Run "cmake --help-policy CMP0022" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "bar" has an INTERFACE_LINK_LIBRARIES property which differs from
+ its LINK_INTERFACE_LIBRARIES properties.
+
+ INTERFACE_LINK_LIBRARIES:
+
+ foo
+
+ LINK_INTERFACE_LIBRARIES:
+
+ bat
+
+This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-tll-result.txt b/Tests/RunCMake/CMP0022/CMP0022-WARN-tll-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-tll-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-tll-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-WARN-tll-stderr.txt
new file mode 100644
index 0000000000..f6722853a5
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-tll-stderr.txt
@@ -0,0 +1,17 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+ Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
+ interface. Run "cmake --help-policy CMP0022" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "bar" has an INTERFACE_LINK_LIBRARIES property which differs from
+ its LINK_INTERFACE_LIBRARIES properties.
+
+ INTERFACE_LINK_LIBRARIES:
+
+ foo
+
+ LINK_INTERFACE_LIBRARIES:
+
+ bat
+
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN-tll.cmake b/Tests/RunCMake/CMP0022/CMP0022-WARN-tll.cmake
new file mode 100644
index 0000000000..11b4e22a99
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN-tll.cmake
@@ -0,0 +1,11 @@
+
+project(CMP0022-WARN-tll)
+
+add_library(foo SHARED empty_vs6_1.cpp)
+add_library(bar SHARED empty_vs6_2.cpp)
+add_library(bat SHARED empty_vs6_3.cpp)
+target_link_libraries(bar LINK_PUBLIC foo)
+set_property(TARGET bar PROPERTY LINK_INTERFACE_LIBRARIES bat)
+
+add_library(user SHARED empty.cpp)
+target_link_libraries(user bar)
diff --git a/Tests/RunCMake/CMP0022/CMP0022-WARN.cmake b/Tests/RunCMake/CMP0022/CMP0022-WARN.cmake
new file mode 100644
index 0000000000..e3552b2f04
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-WARN.cmake
@@ -0,0 +1,18 @@
+
+project(CMP0022-WARN)
+
+cmake_policy(SET CMP0042 NEW)
+
+add_library(foo SHARED empty_vs6_1.cpp)
+add_library(bar SHARED empty_vs6_2.cpp)
+add_library(bat SHARED empty_vs6_3.cpp)
+set_property(TARGET bar PROPERTY INTERFACE_LINK_LIBRARIES foo)
+set_property(TARGET bar PROPERTY LINK_INTERFACE_LIBRARIES bat)
+
+add_library(user empty.cpp)
+target_link_libraries(user bar)
+
+# Use "bar" again with a different "head" target to check
+# that the warning does not appear again.
+add_library(user2 empty_vs6_3.cpp)
+target_link_libraries(user2 bar)
diff --git a/Tests/RunCMake/CMP0022/CMP0022-export-exe-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-export-exe-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-export-exe-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0022/CMP0022-export-exe.cmake b/Tests/RunCMake/CMP0022/CMP0022-export-exe.cmake
new file mode 100644
index 0000000000..d832faceb5
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-export-exe.cmake
@@ -0,0 +1,9 @@
+enable_language(CXX)
+
+cmake_policy(SET CMP0022 NEW)
+
+add_library(testLib empty_vs6_1.cpp)
+add_executable(testExe empty_vs6_2.cpp)
+target_link_libraries(testExe testLib)
+
+export(TARGETS testExe FILE "${CMAKE_CURRENT_BINARY_DIR}/cmp0022NEW-exe.cmake")
diff --git a/Tests/RunCMake/CMP0022/CMP0022-export-result.txt b/Tests/RunCMake/CMP0022/CMP0022-export-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-export-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0022/CMP0022-export-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-export-stderr.txt
new file mode 100644
index 0000000000..405dd8dc8a
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-export-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error in CMakeLists.txt:
+ Target "cmp0022NEW" 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
diff --git a/Tests/RunCMake/CMP0022/CMP0022-export.cmake b/Tests/RunCMake/CMP0022/CMP0022-export.cmake
new file mode 100644
index 0000000000..06147f39ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-export.cmake
@@ -0,0 +1,11 @@
+
+project(cmp0022NEW)
+
+cmake_policy(SET CMP0022 NEW)
+
+add_library(cmp0022NEW SHARED empty_vs6_1.cpp)
+add_library(testLib SHARED empty_vs6_2.cpp)
+
+set_property(TARGET cmp0022NEW APPEND PROPERTY LINK_INTERFACE_LIBRARIES testLib)
+
+export(TARGETS cmp0022NEW testLib FILE "${CMAKE_CURRENT_BINARY_DIR}/cmp0022NEW.cmake")
diff --git a/Tests/RunCMake/CMP0022/CMP0022-install-export-result.txt b/Tests/RunCMake/CMP0022/CMP0022-install-export-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-install-export-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0022/CMP0022-install-export-stderr.txt b/Tests/RunCMake/CMP0022/CMP0022-install-export-stderr.txt
new file mode 100644
index 0000000000..405dd8dc8a
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-install-export-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error in CMakeLists.txt:
+ Target "cmp0022NEW" 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
diff --git a/Tests/RunCMake/CMP0022/CMP0022-install-export.cmake b/Tests/RunCMake/CMP0022/CMP0022-install-export.cmake
new file mode 100644
index 0000000000..171febe3a6
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMP0022-install-export.cmake
@@ -0,0 +1,12 @@
+
+project(cmp0022NEW)
+
+cmake_policy(SET CMP0022 NEW)
+
+add_library(cmp0022NEW SHARED empty_vs6_1.cpp)
+add_library(testLib SHARED empty_vs6_2.cpp)
+
+set_property(TARGET cmp0022NEW APPEND PROPERTY LINK_INTERFACE_LIBRARIES testLib)
+
+install(TARGETS cmp0022NEW testLib EXPORT exp DESTINATION lib)
+install(EXPORT exp FILE expTargets.cmake DESTINATION lib/cmake/exp)
diff --git a/Tests/RunCMake/CMP0022/CMakeLists.txt b/Tests/RunCMake/CMP0022/CMakeLists.txt
new file mode 100644
index 0000000000..72abfc8099
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0022/RunCMakeTest.cmake b/Tests/RunCMake/CMP0022/RunCMakeTest.cmake
new file mode 100644
index 0000000000..4c1099607a
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/RunCMakeTest.cmake
@@ -0,0 +1,14 @@
+include(RunCMake)
+
+run_cmake(CMP0022-WARN)
+run_cmake(CMP0022-WARN-tll)
+run_cmake(CMP0022-WARN-static)
+run_cmake(CMP0022-WARN-empty-old)
+run_cmake(CMP0022-NOWARN-exe)
+run_cmake(CMP0022-NOWARN-shared)
+run_cmake(CMP0022-NOWARN-static)
+run_cmake(CMP0022-NOWARN-static-NEW)
+run_cmake(CMP0022-NOWARN-static-link_libraries)
+run_cmake(CMP0022-export)
+run_cmake(CMP0022-export-exe)
+run_cmake(CMP0022-install-export)
diff --git a/Tests/RunCMake/CMP0022/dep1/CMakeLists.txt b/Tests/RunCMake/CMP0022/dep1/CMakeLists.txt
new file mode 100644
index 0000000000..f0a8179237
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/dep1/CMakeLists.txt
@@ -0,0 +1,2 @@
+
+add_library(dep1 ../empty_vs6_1.cpp)
diff --git a/Tests/RunCMake/CMP0022/dep2/CMakeLists.txt b/Tests/RunCMake/CMP0022/dep2/CMakeLists.txt
new file mode 100644
index 0000000000..4f90162f84
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/dep2/CMakeLists.txt
@@ -0,0 +1,2 @@
+
+add_library(dep2 ../empty_vs6_2.cpp)
diff --git a/Tests/RunCMake/CMP0022/dep3/CMakeLists.txt b/Tests/RunCMake/CMP0022/dep3/CMakeLists.txt
new file mode 100644
index 0000000000..e85cb5431b
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/dep3/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+link_libraries(dep1)
+
+add_library(dep3 ../empty_vs6_3.cpp)
+target_link_libraries(dep3 dep2)
diff --git a/Tests/RunCMake/CMP0022/empty.cpp b/Tests/RunCMake/CMP0022/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0022/empty_vs6_1.cpp b/Tests/RunCMake/CMP0022/empty_vs6_1.cpp
new file mode 100644
index 0000000000..7efedabfa3
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/empty_vs6_1.cpp
@@ -0,0 +1 @@
+#include "empty.cpp"
diff --git a/Tests/RunCMake/CMP0022/empty_vs6_2.cpp b/Tests/RunCMake/CMP0022/empty_vs6_2.cpp
new file mode 100644
index 0000000000..7efedabfa3
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/empty_vs6_2.cpp
@@ -0,0 +1 @@
+#include "empty.cpp"
diff --git a/Tests/RunCMake/CMP0022/empty_vs6_3.cpp b/Tests/RunCMake/CMP0022/empty_vs6_3.cpp
new file mode 100644
index 0000000000..7efedabfa3
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/empty_vs6_3.cpp
@@ -0,0 +1 @@
+#include "empty.cpp"
diff --git a/Tests/RunCMake/CMP0022/empty_vs6_4.cpp b/Tests/RunCMake/CMP0022/empty_vs6_4.cpp
new file mode 100644
index 0000000000..7efedabfa3
--- /dev/null
+++ b/Tests/RunCMake/CMP0022/empty_vs6_4.cpp
@@ -0,0 +1 @@
+#include "empty.cpp"
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-result.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt
new file mode 100644
index 0000000000..05b021746b
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error at CMP0026-CONFIG-LOCATION-NEW.cmake:7 \(get_target_property\):
+ The LOCATION property may not be read from target "somelib". Use the
+ target name directly with add_custom_command, or use the generator
+ expression \$<TARGET_FILE>, as appropriate.
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW.cmake b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW.cmake
new file mode 100644
index 0000000000..1b373e75df
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW.cmake
@@ -0,0 +1,7 @@
+
+enable_language(CXX)
+
+cmake_policy(SET CMP0026 NEW)
+
+add_library(somelib empty.cpp)
+get_target_property(_loc somelib Debug_LOCATION)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-result.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD.cmake b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD.cmake
new file mode 100644
index 0000000000..4166828797
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD.cmake
@@ -0,0 +1,7 @@
+
+enable_language(CXX)
+
+cmake_policy(SET CMP0026 OLD)
+
+add_library(somelib empty.cpp)
+get_target_property(_loc somelib Debug_LOCATION)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-result.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-stderr.txt
new file mode 100644
index 0000000000..d44dcb48d9
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0026-CONFIG-LOCATION-WARN.cmake:5 \(get_target_property\):
+ Policy CMP0026 is not set: Disallow use of the LOCATION target property.
+ Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ The LOCATION property should not be read from target "somelib". Use the
+ target name directly with add_custom_command, or use the generator
+ expression \$<TARGET_FILE>, as appropriate.
+
+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/CMP0026/CMP0026-CONFIG-LOCATION-WARN.cmake b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN.cmake
new file mode 100644
index 0000000000..511056fefe
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN.cmake
@@ -0,0 +1,5 @@
+
+enable_language(CXX)
+
+add_library(somelib empty.cpp)
+get_target_property(_loc somelib Debug_LOCATION)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-result.txt b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0026/CMP0026-IMPORTED.cmake b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED.cmake
new file mode 100644
index 0000000000..650c8a5c79
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED.cmake
@@ -0,0 +1,6 @@
+
+enable_language(CXX)
+
+add_library(someimportedlib SHARED IMPORTED)
+
+get_target_property(_loc someimportedlib LOCATION)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-result.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt
new file mode 100644
index 0000000000..fec9dfb4d1
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error at CMP0026-LOCATION-CONFIG-NEW.cmake:7 \(get_target_property\):
+ The LOCATION property may not be read from target "somelib". Use the
+ target name directly with add_custom_command, or use the generator
+ expression \$<TARGET_FILE>, as appropriate.
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW.cmake b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW.cmake
new file mode 100644
index 0000000000..e6aa509afd
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW.cmake
@@ -0,0 +1,7 @@
+
+enable_language(CXX)
+
+cmake_policy(SET CMP0026 NEW)
+
+add_library(somelib empty.cpp)
+get_target_property(_loc somelib LOCATION_Debug)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-result.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD.cmake b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD.cmake
new file mode 100644
index 0000000000..482373df2d
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD.cmake
@@ -0,0 +1,7 @@
+
+enable_language(CXX)
+
+cmake_policy(SET CMP0026 OLD)
+
+add_library(somelib empty.cpp)
+get_target_property(_loc somelib LOCATION_Debug)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-result.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-stderr.txt
new file mode 100644
index 0000000000..cd6f3d095d
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0026-LOCATION-CONFIG-WARN.cmake:5 \(get_target_property\):
+ Policy CMP0026 is not set: Disallow use of the LOCATION target property.
+ Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ The LOCATION property should not be read from target "somelib". Use the
+ target name directly with add_custom_command, or use the generator
+ expression \$<TARGET_FILE>, as appropriate.
+
+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/CMP0026/CMP0026-LOCATION-CONFIG-WARN.cmake b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN.cmake
new file mode 100644
index 0000000000..85711c34b1
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN.cmake
@@ -0,0 +1,5 @@
+
+enable_language(CXX)
+
+add_library(somelib empty.cpp)
+get_target_property(_loc somelib LOCATION_Debug)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-NEW-result.txt b/Tests/RunCMake/CMP0026/CMP0026-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt
new file mode 100644
index 0000000000..fa025129fb
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error at CMP0026-NEW.cmake:7 \(get_target_property\):
+ The LOCATION property may not be read from target "somelib". Use the
+ target name directly with add_custom_command, or use the generator
+ expression \$<TARGET_FILE>, as appropriate.
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-NEW.cmake b/Tests/RunCMake/CMP0026/CMP0026-NEW.cmake
new file mode 100644
index 0000000000..1659ffc524
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-NEW.cmake
@@ -0,0 +1,7 @@
+
+enable_language(CXX)
+
+cmake_policy(SET CMP0026 NEW)
+
+add_library(somelib empty.cpp)
+get_target_property(_loc somelib LOCATION)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-WARN-Dir/CMakeLists.txt b/Tests/RunCMake/CMP0026/CMP0026-WARN-Dir/CMakeLists.txt
new file mode 100644
index 0000000000..17a7db043a
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-WARN-Dir/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(otherlib ../empty.cpp)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-WARN-result.txt b/Tests/RunCMake/CMP0026/CMP0026-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt
new file mode 100644
index 0000000000..d122c4a2eb
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt
@@ -0,0 +1,25 @@
+CMake Warning \(dev\) at CMP0026-WARN.cmake:5 \(get_target_property\):
+ Policy CMP0026 is not set: Disallow use of the LOCATION target property.
+ Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ The LOCATION property should not be read from target "somelib". Use the
+ target name directly with add_custom_command, or use the generator
+ expression \$<TARGET_FILE>, as appropriate.
+
+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 CMP0026-WARN.cmake:8 \(get_target_property\):
+ Policy CMP0026 is not set: Disallow use of the LOCATION target property.
+ Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ The LOCATION property should not be read from target "otherlib". Use the
+ target name directly with add_custom_command, or use the generator
+ expression \$<TARGET_FILE>, as appropriate.
+
+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/CMP0026/CMP0026-WARN.cmake b/Tests/RunCMake/CMP0026/CMP0026-WARN.cmake
new file mode 100644
index 0000000000..bfc9203af9
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMP0026-WARN.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(somelib empty.cpp)
+get_target_property(_loc somelib LOCATION)
+
+add_subdirectory(CMP0026-WARN-Dir)
+get_target_property(_loc otherlib LOCATION)
diff --git a/Tests/RunCMake/CMP0026/CMakeLists.txt b/Tests/RunCMake/CMP0026/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0026/ObjlibNotDefined-result.txt b/Tests/RunCMake/CMP0026/ObjlibNotDefined-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/ObjlibNotDefined-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0026/ObjlibNotDefined-stderr.txt b/Tests/RunCMake/CMP0026/ObjlibNotDefined-stderr.txt
new file mode 100644
index 0000000000..87d198d00f
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/ObjlibNotDefined-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at ObjlibNotDefined.cmake:[0-9]+ \(get_target_property\):
+ Policy CMP0026 is not set: Disallow use of the LOCATION target property.
+ Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ The LOCATION property should not be read from target "objlibuser". Use the
+ target name directly with add_custom_command, or use the generator
+ expression \$<TARGET_FILE>, as appropriate.
+
+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/CMP0026/ObjlibNotDefined.cmake b/Tests/RunCMake/CMP0026/ObjlibNotDefined.cmake
new file mode 100644
index 0000000000..194760cd46
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/ObjlibNotDefined.cmake
@@ -0,0 +1,13 @@
+
+enable_language(CXX)
+
+add_executable(objlibuser
+ empty.cpp
+ $<TARGET_OBJECTS:bar>
+)
+
+get_target_property(_location objlibuser LOCATION)
+
+add_library(bar OBJECT
+ empty.cpp
+)
diff --git a/Tests/RunCMake/CMP0026/RunCMakeTest.cmake b/Tests/RunCMake/CMP0026/RunCMakeTest.cmake
new file mode 100644
index 0000000000..7c2582f7aa
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/RunCMakeTest.cmake
@@ -0,0 +1,12 @@
+include(RunCMake)
+
+run_cmake(CMP0026-WARN)
+run_cmake(CMP0026-NEW)
+run_cmake(CMP0026-IMPORTED)
+run_cmake(CMP0026-CONFIG-LOCATION-NEW)
+run_cmake(CMP0026-CONFIG-LOCATION-OLD)
+run_cmake(CMP0026-CONFIG-LOCATION-WARN)
+run_cmake(CMP0026-LOCATION-CONFIG-NEW)
+run_cmake(CMP0026-LOCATION-CONFIG-OLD)
+run_cmake(CMP0026-LOCATION-CONFIG-WARN)
+run_cmake(ObjlibNotDefined)
diff --git a/Tests/RunCMake/CMP0026/empty.cpp b/Tests/RunCMake/CMP0026/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0026/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0027/CMP0027-NEW-result.txt b/Tests/RunCMake/CMP0027/CMP0027-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMP0027-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0027/CMP0027-NEW-stderr.txt b/Tests/RunCMake/CMP0027/CMP0027-NEW-stderr.txt
new file mode 100644
index 0000000000..5948ec837a
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMP0027-NEW-stderr.txt
@@ -0,0 +1,13 @@
+CMake Error in CMakeLists.txt:
+ Imported target "testTarget" includes non-existent path
+
+ "/does/not/exist"
+
+ in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
+
+ \* The path was deleted, renamed, or moved to another location.
+
+ \* An install or uninstall procedure did not complete successfully.
+
+ \* The installation package was faulty and references files it does not
+ provide.
diff --git a/Tests/RunCMake/CMP0027/CMP0027-NEW.cmake b/Tests/RunCMake/CMP0027/CMP0027-NEW.cmake
new file mode 100644
index 0000000000..8245085495
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMP0027-NEW.cmake
@@ -0,0 +1,10 @@
+
+enable_language(CXX)
+
+cmake_policy(SET CMP0027 NEW)
+
+add_library(testTarget UNKNOWN IMPORTED)
+set_property(TARGET testTarget PROPERTY INTERFACE_INCLUDE_DIRECTORIES "/does/not/exist")
+
+add_library(userTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+target_link_libraries(userTarget PRIVATE $<1:testTarget>)
diff --git a/Tests/RunCMake/CMP0027/CMP0027-OLD-result.txt b/Tests/RunCMake/CMP0027/CMP0027-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMP0027-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0027/CMP0027-OLD-stderr.txt b/Tests/RunCMake/CMP0027/CMP0027-OLD-stderr.txt
new file mode 100644
index 0000000000..4c2b300b41
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMP0027-OLD-stderr.txt
@@ -0,0 +1,13 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+ Imported target "testTarget" includes non-existent path
+
+ "/does/not/exist"
+
+ in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
+
+ \* The path was deleted, renamed, or moved to another location.
+
+ \* An install or uninstall procedure did not complete successfully.
+
+ \* The installation package was faulty and references files it does not
+ provide.
diff --git a/Tests/RunCMake/CMP0027/CMP0027-OLD.cmake b/Tests/RunCMake/CMP0027/CMP0027-OLD.cmake
new file mode 100644
index 0000000000..404217de7a
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMP0027-OLD.cmake
@@ -0,0 +1,10 @@
+
+enable_language(CXX)
+
+cmake_policy(SET CMP0027 OLD)
+
+add_library(testTarget UNKNOWN IMPORTED)
+set_property(TARGET testTarget PROPERTY INTERFACE_INCLUDE_DIRECTORIES "/does/not/exist")
+
+add_library(userTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+target_link_libraries(userTarget PRIVATE $<1:testTarget>)
diff --git a/Tests/RunCMake/CMP0027/CMP0027-WARN-result.txt b/Tests/RunCMake/CMP0027/CMP0027-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMP0027-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0027/CMP0027-WARN-stderr.txt b/Tests/RunCMake/CMP0027/CMP0027-WARN-stderr.txt
new file mode 100644
index 0000000000..9bcec3c442
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMP0027-WARN-stderr.txt
@@ -0,0 +1,18 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+ Policy CMP0027 is not set: Conditionally linked imported targets with
+ missing include directories. Run "cmake --help-policy CMP0027" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ Imported target "testTarget" includes non-existent path
+
+ "/does/not/exist"
+
+ in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
+
+ \* The path was deleted, renamed, or moved to another location.
+
+ \* An install or uninstall procedure did not complete successfully.
+
+ \* The installation package was faulty and references files it does not
+ provide.
diff --git a/Tests/RunCMake/CMP0027/CMP0027-WARN.cmake b/Tests/RunCMake/CMP0027/CMP0027-WARN.cmake
new file mode 100644
index 0000000000..8e5f9b5181
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMP0027-WARN.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(testTarget UNKNOWN IMPORTED)
+set_property(TARGET testTarget PROPERTY INTERFACE_INCLUDE_DIRECTORIES "/does/not/exist")
+
+add_library(userTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+target_link_libraries(userTarget PRIVATE $<1:testTarget>)
diff --git a/Tests/RunCMake/CMP0027/CMakeLists.txt b/Tests/RunCMake/CMP0027/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0027/RunCMakeTest.cmake b/Tests/RunCMake/CMP0027/RunCMakeTest.cmake
new file mode 100644
index 0000000000..1017f01f49
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0027-NEW)
+run_cmake(CMP0027-OLD)
+run_cmake(CMP0027-WARN)
diff --git a/Tests/RunCMake/CMP0027/empty.cpp b/Tests/RunCMake/CMP0027/empty.cpp
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/CMP0027/empty.cpp
diff --git a/Tests/RunCMake/CMP0028/CMP0028-NEW-iface-result.txt b/Tests/RunCMake/CMP0028/CMP0028-NEW-iface-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-NEW-iface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0028/CMP0028-NEW-iface-stderr.txt b/Tests/RunCMake/CMP0028/CMP0028-NEW-iface-stderr.txt
new file mode 100644
index 0000000000..e2108f46c0
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-NEW-iface-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMP0028-NEW-iface.cmake:6 \(add_library\):
+ Target "foo" links to target "External::Library" but the target was not
+ found. Perhaps a find_package\(\) call is missing for an IMPORTED target, or
+ an ALIAS target is missing\?
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0028/CMP0028-NEW-iface.cmake b/Tests/RunCMake/CMP0028/CMP0028-NEW-iface.cmake
new file mode 100644
index 0000000000..1a71433065
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-NEW-iface.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0028 NEW)
+
+add_library(iface INTERFACE)
+target_link_libraries(iface INTERFACE External::Library)
+add_library(foo empty.cpp)
+target_link_libraries(foo iface)
diff --git a/Tests/RunCMake/CMP0028/CMP0028-NEW-result.txt b/Tests/RunCMake/CMP0028/CMP0028-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0028/CMP0028-NEW-stderr.txt b/Tests/RunCMake/CMP0028/CMP0028-NEW-stderr.txt
new file mode 100644
index 0000000000..711ad0e725
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-NEW-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMP0028-NEW.cmake:4 \(add_library\):
+ Target "foo" links to target "External::Library" but the target was not
+ found. Perhaps a find_package\(\) call is missing for an IMPORTED target, or
+ an ALIAS target is missing\?
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0028/CMP0028-NEW.cmake b/Tests/RunCMake/CMP0028/CMP0028-NEW.cmake
new file mode 100644
index 0000000000..a0a6ae81cc
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-NEW.cmake
@@ -0,0 +1,5 @@
+
+cmake_policy(SET CMP0028 NEW)
+
+add_library(foo empty.cpp)
+target_link_libraries(foo PRIVATE External::Library)
diff --git a/Tests/RunCMake/CMP0028/CMP0028-OLD-iface-result.txt b/Tests/RunCMake/CMP0028/CMP0028-OLD-iface-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-OLD-iface-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0028/CMP0028-OLD-iface-stderr.txt b/Tests/RunCMake/CMP0028/CMP0028-OLD-iface-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-OLD-iface-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0028/CMP0028-OLD-iface.cmake b/Tests/RunCMake/CMP0028/CMP0028-OLD-iface.cmake
new file mode 100644
index 0000000000..d7bd60e4b7
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-OLD-iface.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0028 OLD)
+
+add_library(iface INTERFACE)
+target_link_libraries(iface INTERFACE External::Library)
+add_library(foo empty.cpp)
+target_link_libraries(foo iface)
diff --git a/Tests/RunCMake/CMP0028/CMP0028-OLD-result.txt b/Tests/RunCMake/CMP0028/CMP0028-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0028/CMP0028-OLD-stderr.txt b/Tests/RunCMake/CMP0028/CMP0028-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0028/CMP0028-OLD.cmake b/Tests/RunCMake/CMP0028/CMP0028-OLD.cmake
new file mode 100644
index 0000000000..d4a870b230
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-OLD.cmake
@@ -0,0 +1,5 @@
+
+cmake_policy(SET CMP0028 OLD)
+
+add_library(foo empty.cpp)
+target_link_libraries(foo PRIVATE External::Library)
diff --git a/Tests/RunCMake/CMP0028/CMP0028-WARN-iface-result.txt b/Tests/RunCMake/CMP0028/CMP0028-WARN-iface-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-WARN-iface-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0028/CMP0028-WARN-iface-stderr.txt b/Tests/RunCMake/CMP0028/CMP0028-WARN-iface-stderr.txt
new file mode 100644
index 0000000000..0c5c65378e
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-WARN-iface-stderr.txt
@@ -0,0 +1,11 @@
+CMake Warning \(dev\) at CMP0028-WARN-iface.cmake:4 \(add_library\):
+ Policy CMP0028 is not set: Double colon in target name means ALIAS or
+ IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
+ Use the cmake_policy command to set the policy and suppress this warning.
+
+ Target "foo" links to target "External::Library" but the target was not
+ found. Perhaps a find_package\(\) call is missing for an IMPORTED target, or
+ an ALIAS target is missing\?
+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/CMP0028/CMP0028-WARN-iface.cmake b/Tests/RunCMake/CMP0028/CMP0028-WARN-iface.cmake
new file mode 100644
index 0000000000..9270023408
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-WARN-iface.cmake
@@ -0,0 +1,5 @@
+
+add_library(iface INTERFACE)
+target_link_libraries(iface INTERFACE External::Library)
+add_library(foo empty.cpp)
+target_link_libraries(foo iface)
diff --git a/Tests/RunCMake/CMP0028/CMP0028-WARN-result.txt b/Tests/RunCMake/CMP0028/CMP0028-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0028/CMP0028-WARN-stderr.txt b/Tests/RunCMake/CMP0028/CMP0028-WARN-stderr.txt
new file mode 100644
index 0000000000..41d7560d8b
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-WARN-stderr.txt
@@ -0,0 +1,11 @@
+CMake Warning \(dev\) at CMP0028-WARN.cmake:2 \(add_library\):
+ Policy CMP0028 is not set: Double colon in target name means ALIAS or
+ IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
+ Use the cmake_policy command to set the policy and suppress this warning.
+
+ Target "foo" links to target "External::Library" but the target was not
+ found. Perhaps a find_package\(\) call is missing for an IMPORTED target, or
+ an ALIAS target is missing\?
+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/CMP0028/CMP0028-WARN.cmake b/Tests/RunCMake/CMP0028/CMP0028-WARN.cmake
new file mode 100644
index 0000000000..70a6cc6c47
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMP0028-WARN.cmake
@@ -0,0 +1,3 @@
+
+add_library(foo empty.cpp)
+target_link_libraries(foo PRIVATE External::Library)
diff --git a/Tests/RunCMake/CMP0028/CMakeLists.txt b/Tests/RunCMake/CMP0028/CMakeLists.txt
new file mode 100644
index 0000000000..144cdb4ee3
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE) # policy used at end of dir
diff --git a/Tests/RunCMake/CMP0028/RunCMakeTest.cmake b/Tests/RunCMake/CMP0028/RunCMakeTest.cmake
new file mode 100644
index 0000000000..0c72ca2961
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/RunCMakeTest.cmake
@@ -0,0 +1,8 @@
+include(RunCMake)
+
+run_cmake(CMP0028-NEW)
+run_cmake(CMP0028-OLD)
+run_cmake(CMP0028-WARN)
+run_cmake(CMP0028-NEW-iface)
+run_cmake(CMP0028-OLD-iface)
+run_cmake(CMP0028-WARN-iface)
diff --git a/Tests/RunCMake/CMP0028/empty.cpp b/Tests/RunCMake/CMP0028/empty.cpp
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/CMP0028/empty.cpp
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-result.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-stderr.txt
new file mode 100644
index 0000000000..ec2315f186
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-stderr.txt
@@ -0,0 +1,20 @@
+CMake Error at CMP0037-NEW-colon.cmake:4 \(add_library\):
+ The target name "lib:colon" is reserved or not valid for certain CMake
+ features, such as generator expressions, and may result in undefined
+ behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at CMP0037-NEW-colon.cmake:5 \(add_executable\):
+ The target name "exe:colon" is reserved or not valid for certain CMake
+ features, such as generator expressions, and may result in undefined
+ behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at CMP0037-NEW-colon.cmake:6 \(add_custom_target\):
+ The target name "custom:colon" is reserved or not valid for certain CMake
+ features, such as generator expressions, and may result in undefined
+ behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake
new file mode 100644
index 0000000000..f4c070d7a2
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake
@@ -0,0 +1,6 @@
+
+cmake_policy(SET CMP0037 NEW)
+
+add_library("lib:colon" empty.cpp)
+add_executable("exe:colon" empty.cpp)
+add_custom_target("custom:colon")
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-result.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-stderr.txt
new file mode 100644
index 0000000000..5789e383aa
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-stderr.txt
@@ -0,0 +1,18 @@
+CMake Error at CMP0037-NEW-reserved.cmake:4 \(add_library\):
+ The target name "all" is reserved or not valid for certain CMake features,
+ such as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at CMP0037-NEW-reserved.cmake:5 \(add_executable\):
+ The target name "clean" is reserved or not valid for certain CMake
+ features, such as generator expressions, and may result in undefined
+ behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at CMP0037-NEW-reserved.cmake:6 \(add_custom_target\):
+ The target name "help" is reserved or not valid for certain CMake features,
+ such as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake
new file mode 100644
index 0000000000..e9f6404693
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake
@@ -0,0 +1,6 @@
+
+cmake_policy(SET CMP0037 NEW)
+
+add_library(all empty.cpp)
+add_executable(clean empty.cpp)
+add_custom_target(help)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-space-result.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-space-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-space-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-space-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-space-stderr.txt
new file mode 100644
index 0000000000..e14cec0009
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-space-stderr.txt
@@ -0,0 +1,20 @@
+CMake Error at CMP0037-NEW-space.cmake:4 \(add_library\):
+ The target name "lib with spaces" is reserved or not valid for certain
+ CMake features, such as generator expressions, and may result in undefined
+ behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at CMP0037-NEW-space.cmake:5 \(add_executable\):
+ The target name "exe with spaces" is reserved or not valid for certain
+ CMake features, such as generator expressions, and may result in undefined
+ behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at CMP0037-NEW-space.cmake:6 \(add_custom_target\):
+ The target name "custom with spaces" is reserved or not valid for certain
+ CMake features, such as generator expressions, and may result in undefined
+ behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake
new file mode 100644
index 0000000000..9227986e95
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake
@@ -0,0 +1,6 @@
+
+cmake_policy(SET CMP0037 NEW)
+
+add_library("lib with spaces" empty.cpp)
+add_executable("exe with spaces" empty.cpp)
+add_custom_target("custom with spaces")
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved-result.txt b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake
new file mode 100644
index 0000000000..870a286725
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake
@@ -0,0 +1,6 @@
+
+cmake_policy(SET CMP0037 OLD)
+
+add_library(all empty.cpp)
+add_executable(clean empty.cpp)
+add_custom_target(help)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-space-result.txt b/Tests/RunCMake/CMP0037/CMP0037-OLD-space-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-space-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-space-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-OLD-space-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-space-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake b/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake
new file mode 100644
index 0000000000..46193a1fa8
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake
@@ -0,0 +1,6 @@
+
+cmake_policy(SET CMP0037 OLD)
+
+add_library("lib with spaces" empty.cpp)
+add_executable("exe with spaces" empty.cpp)
+add_custom_target("custom with spaces")
diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-colon-result.txt b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-colon-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon-stderr.txt
new file mode 100644
index 0000000000..d3b0e172f5
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon-stderr.txt
@@ -0,0 +1,38 @@
+CMake Warning \(dev\) at CMP0037-WARN-colon.cmake:2 \(add_library\):
+ Policy CMP0037 is not set: Target names should not be reserved and should
+ match a validity pattern. Run "cmake --help-policy CMP0037" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The target name "lib:colon" is reserved or not valid for certain CMake
+ features, such as generator expressions, and may result in undefined
+ behavior.
+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 CMP0037-WARN-colon.cmake:3 \(add_executable\):
+ Policy CMP0037 is not set: Target names should not be reserved and should
+ match a validity pattern. Run "cmake --help-policy CMP0037" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The target name "exe:colon" is reserved or not valid for certain CMake
+ features, such as generator expressions, and may result in undefined
+ behavior.
+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 CMP0037-WARN-colon.cmake:4 \(add_custom_target\):
+ Policy CMP0037 is not set: Target names should not be reserved and should
+ match a validity pattern. Run "cmake --help-policy CMP0037" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The target name "custom:colon" is reserved or not valid for certain CMake
+ features, such as generator expressions, and may result in undefined
+ behavior.
+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/CMP0037/CMP0037-WARN-colon.cmake b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake
new file mode 100644
index 0000000000..445e3b23e0
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake
@@ -0,0 +1,4 @@
+
+add_library("lib:colon" empty.cpp)
+add_executable("exe:colon" empty.cpp)
+add_custom_target("custom:colon")
diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-space-result.txt b/Tests/RunCMake/CMP0037/CMP0037-WARN-space-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-space-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-space-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-WARN-space-stderr.txt
new file mode 100644
index 0000000000..e39477a91b
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-space-stderr.txt
@@ -0,0 +1,37 @@
+CMake Warning \(dev\) at CMP0037-WARN-space.cmake:2 \(add_library\):
+ Policy CMP0037 is not set: Target names should not be reserved and should
+ match a validity pattern. Run "cmake --help-policy CMP0037" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The target name "lib with spaces" is reserved or not valid for certain
+ CMake features, such as generator expressions, and may result in undefined
+ behavior.
+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 CMP0037-WARN-space.cmake:3 \(add_executable\):
+ Policy CMP0037 is not set: Target names should not be reserved and should
+ match a validity pattern. Run "cmake --help-policy CMP0037" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The target name "exe with spaces" is reserved or not valid for certain
+ CMake features, such as generator expressions, and may result in undefined
+ behavior.
+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 CMP0037-WARN-space.cmake:4 \(add_custom_target\):
+ Policy CMP0037 is not set: Target names should not be reserved and should
+ match a validity pattern. Run "cmake --help-policy CMP0037" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The target name "custom with spaces" is reserved or not valid for certain
+ CMake features, such as generator expressions, and may result in undefined
+ behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake b/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake
new file mode 100644
index 0000000000..e50a64dcf8
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake
@@ -0,0 +1,4 @@
+
+add_library("lib with spaces" empty.cpp)
+add_executable("exe with spaces" empty.cpp)
+add_custom_target("custom with spaces")
diff --git a/Tests/RunCMake/CMP0037/CMakeLists.txt b/Tests/RunCMake/CMP0037/CMakeLists.txt
new file mode 100644
index 0000000000..f452db1770
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
new file mode 100644
index 0000000000..b7d8d7bb46
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
@@ -0,0 +1,13 @@
+include(RunCMake)
+
+run_cmake(CMP0037-OLD-space)
+run_cmake(CMP0037-NEW-space)
+run_cmake(CMP0037-WARN-space)
+run_cmake(CMP0037-NEW-colon)
+
+if(NOT (WIN32 AND "${RunCMake_GENERATOR}" MATCHES "Make"))
+ run_cmake(CMP0037-WARN-colon)
+endif()
+
+run_cmake(CMP0037-OLD-reserved)
+run_cmake(CMP0037-NEW-reserved)
diff --git a/Tests/RunCMake/CMP0037/empty.cpp b/Tests/RunCMake/CMP0037/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0038/CMP0038-NEW-result.txt b/Tests/RunCMake/CMP0038/CMP0038-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0038/CMP0038-NEW-stderr.txt b/Tests/RunCMake/CMP0038/CMP0038-NEW-stderr.txt
new file mode 100644
index 0000000000..3d0a428e18
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0038-NEW.cmake:3 \(add_library\):
+ Target "self_link" links to itself.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0038/CMP0038-NEW.cmake b/Tests/RunCMake/CMP0038/CMP0038-NEW.cmake
new file mode 100644
index 0000000000..6296b839a2
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-NEW.cmake
@@ -0,0 +1,4 @@
+
+cmake_policy(SET CMP0038 NEW)
+add_library(self_link empty.cpp)
+target_link_libraries(self_link self_link)
diff --git a/Tests/RunCMake/CMP0038/CMP0038-OLD-result.txt b/Tests/RunCMake/CMP0038/CMP0038-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0038/CMP0038-OLD-stderr.txt b/Tests/RunCMake/CMP0038/CMP0038-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0038/CMP0038-OLD.cmake b/Tests/RunCMake/CMP0038/CMP0038-OLD.cmake
new file mode 100644
index 0000000000..37528218ca
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-OLD.cmake
@@ -0,0 +1,4 @@
+
+cmake_policy(SET CMP0038 OLD)
+add_library(self_link empty.cpp)
+target_link_libraries(self_link self_link)
diff --git a/Tests/RunCMake/CMP0038/CMP0038-WARN-result.txt b/Tests/RunCMake/CMP0038/CMP0038-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0038/CMP0038-WARN-stderr.txt b/Tests/RunCMake/CMP0038/CMP0038-WARN-stderr.txt
new file mode 100644
index 0000000000..64631e7ffd
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-WARN-stderr.txt
@@ -0,0 +1,9 @@
+CMake Warning \(dev\) at CMP0038-WARN.cmake:2 \(add_library\):
+ Policy CMP0038 is not set: Targets may not link directly to themselves.
+ Run "cmake --help-policy CMP0038" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ Target "self_link" links to itself.
+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/CMP0038/CMP0038-WARN.cmake b/Tests/RunCMake/CMP0038/CMP0038-WARN.cmake
new file mode 100644
index 0000000000..5b92d09518
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-WARN.cmake
@@ -0,0 +1,3 @@
+
+add_library(self_link empty.cpp)
+target_link_libraries(self_link self_link)
diff --git a/Tests/RunCMake/CMP0038/CMakeLists.txt b/Tests/RunCMake/CMP0038/CMakeLists.txt
new file mode 100644
index 0000000000..a06591c31f
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0038/RunCMakeTest.cmake b/Tests/RunCMake/CMP0038/RunCMakeTest.cmake
new file mode 100644
index 0000000000..fc3500addd
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0038-WARN)
+run_cmake(CMP0038-NEW)
+run_cmake(CMP0038-OLD)
diff --git a/Tests/RunCMake/CMP0038/empty.cpp b/Tests/RunCMake/CMP0038/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0039/CMP0039-NEW-result.txt b/Tests/RunCMake/CMP0039/CMP0039-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt b/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt
new file mode 100644
index 0000000000..3d9d22537d
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at CMP0039-NEW.cmake:7 \(target_link_libraries\):
+ Utility target "utility" must not be used as the target of a
+ target_link_libraries call.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0039/CMP0039-NEW.cmake b/Tests/RunCMake/CMP0039/CMP0039-NEW.cmake
new file mode 100644
index 0000000000..2032d64d45
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-NEW.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0039 NEW)
+
+add_custom_target(utility
+ COMMAND ${CMAKE_COMMAND} -E echo test
+)
+target_link_libraries(utility m)
diff --git a/Tests/RunCMake/CMP0039/CMP0039-OLD-result.txt b/Tests/RunCMake/CMP0039/CMP0039-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0039/CMP0039-OLD-stderr.txt b/Tests/RunCMake/CMP0039/CMP0039-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0039/CMP0039-OLD.cmake b/Tests/RunCMake/CMP0039/CMP0039-OLD.cmake
new file mode 100644
index 0000000000..9a513f4447
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-OLD.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0039 OLD)
+
+add_custom_target(utility
+ COMMAND ${CMAKE_COMMAND} -E echo test
+)
+target_link_libraries(utility m)
diff --git a/Tests/RunCMake/CMP0039/CMP0039-WARN-result.txt b/Tests/RunCMake/CMP0039/CMP0039-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0039/CMP0039-WARN-stderr.txt b/Tests/RunCMake/CMP0039/CMP0039-WARN-stderr.txt
new file mode 100644
index 0000000000..a8e6c70aff
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-WARN-stderr.txt
@@ -0,0 +1,10 @@
+CMake Warning \(dev\) at CMP0039-WARN.cmake:5 \(target_link_libraries\):
+ Policy CMP0039 is not set: Utility targets may not have link dependencies.
+ Run "cmake --help-policy CMP0039" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ Utility target "utility" should not be used as the target of a
+ target_link_libraries call.
+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/CMP0039/CMP0039-WARN.cmake b/Tests/RunCMake/CMP0039/CMP0039-WARN.cmake
new file mode 100644
index 0000000000..62499938d5
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-WARN.cmake
@@ -0,0 +1,5 @@
+
+add_custom_target(utility
+ COMMAND ${CMAKE_COMMAND} -E echo test
+)
+target_link_libraries(utility m)
diff --git a/Tests/RunCMake/CMP0039/CMakeLists.txt b/Tests/RunCMake/CMP0039/CMakeLists.txt
new file mode 100644
index 0000000000..a06591c31f
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0039/RunCMakeTest.cmake b/Tests/RunCMake/CMP0039/RunCMakeTest.cmake
new file mode 100644
index 0000000000..58e8ea91eb
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0039-WARN)
+run_cmake(CMP0039-NEW)
+run_cmake(CMP0039-OLD)
diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-result.txt b/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target.cmake
new file mode 100644
index 0000000000..f9c8afdf5f
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target.cmake
@@ -0,0 +1,7 @@
+cmake_policy(SET CMP0040 NEW)
+
+add_library(foobar empty.cpp)
+
+add_custom_command(TARGET foobar PRE_BUILD
+ COMMAND "${CMAKE_COMMAND} -E echo hello world"
+)
diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-result.txt b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt
new file mode 100644
index 0000000000..3f82d8c3d2
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0040-NEW-missing-target.cmake:3 \(add_custom_command\):
+ The target name "foobar" is unknown in this context.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target.cmake
new file mode 100644
index 0000000000..276863d7be
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0040 NEW)
+
+add_custom_command(TARGET foobar PRE_BUILD
+ COMMAND "${CMAKE_COMMAND} -E hello world"
+)
diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-result.txt b/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target.cmake
new file mode 100644
index 0000000000..d7ec50daa9
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target.cmake
@@ -0,0 +1,7 @@
+cmake_policy(SET CMP0040 OLD)
+
+add_library(foobar empty.cpp)
+
+add_custom_command(TARGET foobar PRE_BUILD
+ COMMAND "${CMAKE_COMMAND} -E echo hello world"
+)
diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-result.txt b/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target.cmake
new file mode 100644
index 0000000000..ef7a0f731b
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0040 OLD)
+
+add_custom_command(TARGET foobar PRE_BUILD
+ COMMAND "${CMAKE_COMMAND} -E echo hello world"
+)
diff --git a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-result.txt b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt
new file mode 100644
index 0000000000..e791f0a727
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt
@@ -0,0 +1,10 @@
+CMake Warning \(dev\) at CMP0040-WARN-missing-target.cmake:2 \(add_custom_command\):
+ Policy CMP0040 is not set: The target in the TARGET signature of
+ add_custom_command\(\) must exist. Run "cmake --help-policy CMP0040" for
+ policy details. Use the cmake_policy command to set the policy and
+ suppress this warning.
++
+ The target name "foobar" is unknown in this context.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target.cmake
new file mode 100644
index 0000000000..2c3e401492
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target.cmake
@@ -0,0 +1,4 @@
+
+add_custom_command(TARGET foobar PRE_BUILD
+ COMMAND "${CMAKE_COMMAND} -E hello world"
+)
diff --git a/Tests/RunCMake/CMP0040/CMakeLists.txt b/Tests/RunCMake/CMP0040/CMakeLists.txt
new file mode 100644
index 0000000000..a06591c31f
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0040/RunCMakeTest.cmake b/Tests/RunCMake/CMP0040/RunCMakeTest.cmake
new file mode 100644
index 0000000000..13160e3a40
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/RunCMakeTest.cmake
@@ -0,0 +1,8 @@
+include(RunCMake)
+
+run_cmake(CMP0040-OLD-missing-target)
+run_cmake(CMP0040-NEW-missing-target)
+run_cmake(CMP0040-WARN-missing-target)
+
+run_cmake(CMP0040-OLD-existing-target)
+run_cmake(CMP0040-NEW-existing-target)
diff --git a/Tests/RunCMake/CMP0040/empty.cpp b/Tests/RunCMake/CMP0040/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0040/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0041/CMP0041-NEW-result.txt b/Tests/RunCMake/CMP0041/CMP0041-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0041/CMP0041-NEW-stderr.txt b/Tests/RunCMake/CMP0041/CMP0041-NEW-stderr.txt
new file mode 100644
index 0000000000..2ec3aef203
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-NEW-stderr.txt
@@ -0,0 +1,20 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains relative path:
+
+ "include/\$<TARGET_PROPERTY:NAME>"
+
+
+CMake Error in CMakeLists.txt:
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the source directory.
+
+
+CMake Error in CMakeLists.txt:
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/CMP0041-NEW-build/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the build directory.
diff --git a/Tests/RunCMake/CMP0041/CMP0041-NEW.cmake b/Tests/RunCMake/CMP0041/CMP0041-NEW.cmake
new file mode 100644
index 0000000000..605b79a008
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-NEW.cmake
@@ -0,0 +1,12 @@
+
+cmake_policy(SET CMP0041 NEW)
+
+add_library(foo empty.cpp)
+set_property(TARGET foo
+ PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_BINARY_DIR}/include/$<TARGET_PROPERTY:NAME>
+)
+install(TARGETS foo EXPORT FooExport DESTINATION lib)
+install(EXPORT FooExport DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/CMP0041/CMP0041-OLD-result.txt b/Tests/RunCMake/CMP0041/CMP0041-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0041/CMP0041-OLD-stderr.txt b/Tests/RunCMake/CMP0041/CMP0041-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0041/CMP0041-OLD.cmake b/Tests/RunCMake/CMP0041/CMP0041-OLD.cmake
new file mode 100644
index 0000000000..16cbced52b
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-OLD.cmake
@@ -0,0 +1,12 @@
+
+cmake_policy(SET CMP0041 OLD)
+
+add_library(foo empty.cpp)
+set_property(TARGET foo
+ PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_BINARY_DIR}/include/$<TARGET_PROPERTY:NAME>
+)
+install(TARGETS foo EXPORT FooExport DESTINATION lib)
+install(EXPORT FooExport DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/CMP0041/CMP0041-WARN-result.txt b/Tests/RunCMake/CMP0041/CMP0041-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0041/CMP0041-WARN-stderr.txt b/Tests/RunCMake/CMP0041/CMP0041-WARN-stderr.txt
new file mode 100644
index 0000000000..a7d303e4de
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-WARN-stderr.txt
@@ -0,0 +1,32 @@
+CMake Warning in CMakeLists.txt:
+ Policy CMP0041 is not set: Error on relative include with generator
+ expression. Run "cmake --help-policy CMP0041" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains relative path:
+
+ "include/\$<TARGET_PROPERTY:NAME>"
+
+
+CMake Warning in CMakeLists.txt:
+ Policy CMP0041 is not set: Error on relative include with generator
+ expression. Run "cmake --help-policy CMP0041" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the source directory.
+
+
+CMake Warning in CMakeLists.txt:
+ Policy CMP0041 is not set: Error on relative include with generator
+ expression. Run "cmake --help-policy CMP0041" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/CMP0041-WARN-build/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the build directory.
diff --git a/Tests/RunCMake/CMP0041/CMP0041-WARN.cmake b/Tests/RunCMake/CMP0041/CMP0041-WARN.cmake
new file mode 100644
index 0000000000..873cbc7084
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-WARN.cmake
@@ -0,0 +1,10 @@
+
+add_library(foo empty.cpp)
+set_property(TARGET foo
+ PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_BINARY_DIR}/include/$<TARGET_PROPERTY:NAME>
+)
+install(TARGETS foo EXPORT FooExport DESTINATION lib)
+install(EXPORT FooExport DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/CMP0041/CMP0041-tid-NEW-result.txt b/Tests/RunCMake/CMP0041/CMP0041-tid-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-tid-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0041/CMP0041-tid-NEW-stderr.txt b/Tests/RunCMake/CMP0041/CMP0041-tid-NEW-stderr.txt
new file mode 100644
index 0000000000..9b0a214318
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-tid-NEW-stderr.txt
@@ -0,0 +1,22 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the source directory.
+
+
+CMake Error in CMakeLists.txt:
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the source directory.
+
+
+CMake Error in CMakeLists.txt:
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/CMP0041-tid-NEW-build/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the build directory.
diff --git a/Tests/RunCMake/CMP0041/CMP0041-tid-NEW.cmake b/Tests/RunCMake/CMP0041/CMP0041-tid-NEW.cmake
new file mode 100644
index 0000000000..3005108aa4
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-tid-NEW.cmake
@@ -0,0 +1,11 @@
+
+cmake_policy(SET CMP0041 NEW)
+
+add_library(foo empty.cpp)
+target_include_directories(foo INTERFACE
+ include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_BINARY_DIR}/include/$<TARGET_PROPERTY:NAME>
+)
+install(TARGETS foo EXPORT FooExport DESTINATION lib)
+install(EXPORT FooExport DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/CMP0041/CMP0041-tid-OLD-result.txt b/Tests/RunCMake/CMP0041/CMP0041-tid-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-tid-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0041/CMP0041-tid-OLD-stderr.txt b/Tests/RunCMake/CMP0041/CMP0041-tid-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-tid-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0041/CMP0041-tid-OLD.cmake b/Tests/RunCMake/CMP0041/CMP0041-tid-OLD.cmake
new file mode 100644
index 0000000000..b5c4e7f857
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-tid-OLD.cmake
@@ -0,0 +1,11 @@
+
+cmake_policy(SET CMP0041 OLD)
+
+add_library(foo empty.cpp)
+target_include_directories(foo INTERFACE
+ include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_BINARY_DIR}/include/$<TARGET_PROPERTY:NAME>
+)
+install(TARGETS foo EXPORT FooExport DESTINATION lib)
+install(EXPORT FooExport DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/CMP0041/CMP0041-tid-WARN-result.txt b/Tests/RunCMake/CMP0041/CMP0041-tid-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-tid-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0041/CMP0041-tid-WARN-stderr.txt b/Tests/RunCMake/CMP0041/CMP0041-tid-WARN-stderr.txt
new file mode 100644
index 0000000000..aae2c7a17c
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-tid-WARN-stderr.txt
@@ -0,0 +1,34 @@
+CMake Warning in CMakeLists.txt:
+ Policy CMP0041 is not set: Error on relative include with generator
+ expression. Run "cmake --help-policy CMP0041" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the source directory.
+
+
+CMake Warning in CMakeLists.txt:
+ Policy CMP0041 is not set: Error on relative include with generator
+ expression. Run "cmake --help-policy CMP0041" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the source directory.
+
+
+CMake Warning in CMakeLists.txt:
+ Policy CMP0041 is not set: Error on relative include with generator
+ expression. Run "cmake --help-policy CMP0041" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Target "foo" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*/Tests/RunCMake/CMP0041/CMP0041-tid-WARN-build/include/\$<TARGET_PROPERTY:NAME>"
+
+ which is prefixed in the build directory.
diff --git a/Tests/RunCMake/CMP0041/CMP0041-tid-WARN.cmake b/Tests/RunCMake/CMP0041/CMP0041-tid-WARN.cmake
new file mode 100644
index 0000000000..ee4c2a6210
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMP0041-tid-WARN.cmake
@@ -0,0 +1,9 @@
+
+add_library(foo empty.cpp)
+target_include_directories(foo INTERFACE
+ include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/$<TARGET_PROPERTY:NAME>
+ ${CMAKE_CURRENT_BINARY_DIR}/include/$<TARGET_PROPERTY:NAME>
+)
+install(TARGETS foo EXPORT FooExport DESTINATION lib)
+install(EXPORT FooExport DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/CMP0041/CMakeLists.txt b/Tests/RunCMake/CMP0041/CMakeLists.txt
new file mode 100644
index 0000000000..f452db1770
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0041/RunCMakeTest.cmake b/Tests/RunCMake/CMP0041/RunCMakeTest.cmake
new file mode 100644
index 0000000000..a5e2114cbc
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/RunCMakeTest.cmake
@@ -0,0 +1,8 @@
+include(RunCMake)
+
+run_cmake(CMP0041-OLD)
+run_cmake(CMP0041-NEW)
+run_cmake(CMP0041-WARN)
+run_cmake(CMP0041-tid-OLD)
+run_cmake(CMP0041-tid-NEW)
+run_cmake(CMP0041-tid-WARN)
diff --git a/Tests/RunCMake/CMP0041/empty.cpp b/Tests/RunCMake/CMP0041/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0041/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0042/CMP0042-NEW-result.txt b/Tests/RunCMake/CMP0042/CMP0042-NEW-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMP0042-NEW-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0042/CMP0042-NEW-stderr.txt b/Tests/RunCMake/CMP0042/CMP0042-NEW-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMP0042-NEW-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0042/CMP0042-NEW.cmake b/Tests/RunCMake/CMP0042/CMP0042-NEW.cmake
new file mode 100644
index 0000000000..778a444311
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMP0042-NEW.cmake
@@ -0,0 +1,4 @@
+
+cmake_policy(SET CMP0042 NEW)
+
+add_library(foo SHARED empty.cpp)
diff --git a/Tests/RunCMake/CMP0042/CMP0042-OLD-result.txt b/Tests/RunCMake/CMP0042/CMP0042-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMP0042-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0042/CMP0042-OLD-stderr.txt b/Tests/RunCMake/CMP0042/CMP0042-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMP0042-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0042/CMP0042-OLD.cmake b/Tests/RunCMake/CMP0042/CMP0042-OLD.cmake
new file mode 100644
index 0000000000..1aede967c2
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMP0042-OLD.cmake
@@ -0,0 +1,4 @@
+
+cmake_policy(SET CMP0042 OLD)
+
+add_library(foo SHARED empty.cpp)
diff --git a/Tests/RunCMake/CMP0042/CMP0042-WARN-result.txt b/Tests/RunCMake/CMP0042/CMP0042-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMP0042-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0042/CMP0042-WARN-stderr.txt b/Tests/RunCMake/CMP0042/CMP0042-WARN-stderr.txt
new file mode 100644
index 0000000000..f3574a1a56
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMP0042-WARN-stderr.txt
@@ -0,0 +1,10 @@
+CMake Warning \(dev\):
+ Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
+ --help-policy CMP0042" for policy details. Use the cmake_policy command to
+ set the policy and suppress this warning.
+
+ MACOSX_RPATH is not specified for the following targets:
+
+ foo
+
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0042/CMP0042-WARN.cmake b/Tests/RunCMake/CMP0042/CMP0042-WARN.cmake
new file mode 100644
index 0000000000..3fa32b16ff
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMP0042-WARN.cmake
@@ -0,0 +1,9 @@
+
+add_library(foo SHARED empty.cpp)
+add_library(foo-static STATIC empty.cpp)
+add_library(foo2 SHARED empty.cpp)
+set_target_properties(foo2 PROPERTIES MACOSX_RPATH 1)
+add_library(foo3 SHARED empty.cpp)
+set_target_properties(foo3 PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@loader_path")
+add_library(foo4 SHARED empty.cpp)
+set_target_properties(foo4 PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@rpath")
diff --git a/Tests/RunCMake/CMP0042/CMakeLists.txt b/Tests/RunCMake/CMP0042/CMakeLists.txt
new file mode 100644
index 0000000000..f452db1770
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0042/RunCMakeTest.cmake b/Tests/RunCMake/CMP0042/RunCMakeTest.cmake
new file mode 100644
index 0000000000..3b226d74cb
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0042-OLD)
+run_cmake(CMP0042-NEW)
+run_cmake(CMP0042-WARN)
diff --git a/Tests/RunCMake/CMP0042/empty.cpp b/Tests/RunCMake/CMP0042/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0042/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0043/CMP0043-NEW-result.txt b/Tests/RunCMake/CMP0043/CMP0043-NEW-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMP0043-NEW-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0043/CMP0043-NEW-stderr.txt b/Tests/RunCMake/CMP0043/CMP0043-NEW-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMP0043-NEW-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0043/CMP0043-NEW.cmake b/Tests/RunCMake/CMP0043/CMP0043-NEW.cmake
new file mode 100644
index 0000000000..857153def8
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMP0043-NEW.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0043 NEW)
+
+add_library(foo empty.cpp)
+set_property(TARGET foo
+ PROPERTY COMPILE_DEFINITIONS_DEBUG "DEBUG_MODE"
+)
diff --git a/Tests/RunCMake/CMP0043/CMP0043-OLD-result.txt b/Tests/RunCMake/CMP0043/CMP0043-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMP0043-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0043/CMP0043-OLD-stderr.txt b/Tests/RunCMake/CMP0043/CMP0043-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMP0043-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0043/CMP0043-OLD.cmake b/Tests/RunCMake/CMP0043/CMP0043-OLD.cmake
new file mode 100644
index 0000000000..f379430c5e
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMP0043-OLD.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0043 OLD)
+
+add_library(foo empty.cpp)
+set_property(TARGET foo
+ PROPERTY COMPILE_DEFINITIONS_DEBUG "DEBUG_MODE"
+)
diff --git a/Tests/RunCMake/CMP0043/CMP0043-WARN-result.txt b/Tests/RunCMake/CMP0043/CMP0043-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMP0043-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0043/CMP0043-WARN-stderr.txt b/Tests/RunCMake/CMP0043/CMP0043-WARN-stderr.txt
new file mode 100644
index 0000000000..4769a63d12
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMP0043-WARN-stderr.txt
@@ -0,0 +1,5 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+ Policy CMP0043 is not set: Ignore COMPILE_DEFINITIONS_<Config> properties.
+ Run "cmake --help-policy CMP0043" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0043/CMP0043-WARN.cmake b/Tests/RunCMake/CMP0043/CMP0043-WARN.cmake
new file mode 100644
index 0000000000..161a60d0ec
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMP0043-WARN.cmake
@@ -0,0 +1,5 @@
+
+add_library(foo empty.cpp)
+set_property(TARGET foo
+ PROPERTY COMPILE_DEFINITIONS_DEBUG "DEBUG_MODE"
+)
diff --git a/Tests/RunCMake/CMP0043/CMakeLists.txt b/Tests/RunCMake/CMP0043/CMakeLists.txt
new file mode 100644
index 0000000000..d027f3e0ef
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE) # policy used at end of dir
+
+if(CMAKE_BUILD_TYPE)
+ # Dummy variable use
+endif()
diff --git a/Tests/RunCMake/CMP0043/RunCMakeTest.cmake b/Tests/RunCMake/CMP0043/RunCMakeTest.cmake
new file mode 100644
index 0000000000..7f9572e5af
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/RunCMakeTest.cmake
@@ -0,0 +1,7 @@
+include(RunCMake)
+
+list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+
+run_cmake(CMP0043-OLD)
+run_cmake(CMP0043-NEW)
+run_cmake(CMP0043-WARN)
diff --git a/Tests/RunCMake/CMP0043/empty.cpp b/Tests/RunCMake/CMP0043/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0043/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0045/CMP0045-NEW-result.txt b/Tests/RunCMake/CMP0045/CMP0045-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMP0045-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0045/CMP0045-NEW-stderr.txt b/Tests/RunCMake/CMP0045/CMP0045-NEW-stderr.txt
new file mode 100644
index 0000000000..805a85ed39
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMP0045-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0045-NEW.cmake:4 \(get_target_property\):
+ get_target_property\(\) called with non-existent target "tgt".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0045/CMP0045-NEW.cmake b/Tests/RunCMake/CMP0045/CMP0045-NEW.cmake
new file mode 100644
index 0000000000..7b2a3cd611
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMP0045-NEW.cmake
@@ -0,0 +1,4 @@
+
+cmake_policy(SET CMP0045 NEW)
+
+get_target_property(result tgt TYPE)
diff --git a/Tests/RunCMake/CMP0045/CMP0045-OLD-result.txt b/Tests/RunCMake/CMP0045/CMP0045-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMP0045-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0045/CMP0045-OLD-stderr.txt b/Tests/RunCMake/CMP0045/CMP0045-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMP0045-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0045/CMP0045-OLD.cmake b/Tests/RunCMake/CMP0045/CMP0045-OLD.cmake
new file mode 100644
index 0000000000..90201a3256
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMP0045-OLD.cmake
@@ -0,0 +1,4 @@
+
+cmake_policy(SET CMP0045 OLD)
+
+get_target_property(result tgt TYPE)
diff --git a/Tests/RunCMake/CMP0045/CMP0045-WARN-result.txt b/Tests/RunCMake/CMP0045/CMP0045-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMP0045-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0045/CMP0045-WARN-stderr.txt b/Tests/RunCMake/CMP0045/CMP0045-WARN-stderr.txt
new file mode 100644
index 0000000000..4c532249fd
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMP0045-WARN-stderr.txt
@@ -0,0 +1,9 @@
+CMake Warning \(dev\) at CMP0045-WARN.cmake:2 \(get_target_property\):
+ Policy CMP0045 is not set: Error on non-existent target in
+ get_target_property. Run "cmake --help-policy CMP0045" for policy details.
+ Use the cmake_policy command to set the policy and suppress this warning.
+
+ get_target_property\(\) called with non-existent target "tgt".
+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/CMP0045/CMP0045-WARN.cmake b/Tests/RunCMake/CMP0045/CMP0045-WARN.cmake
new file mode 100644
index 0000000000..86a99a0033
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMP0045-WARN.cmake
@@ -0,0 +1,2 @@
+
+get_target_property(result tgt TYPE)
diff --git a/Tests/RunCMake/CMP0045/CMakeLists.txt b/Tests/RunCMake/CMP0045/CMakeLists.txt
new file mode 100644
index 0000000000..f452db1770
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0045/RunCMakeTest.cmake b/Tests/RunCMake/CMP0045/RunCMakeTest.cmake
new file mode 100644
index 0000000000..7c0e8a2151
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0045-OLD)
+run_cmake(CMP0045-NEW)
+run_cmake(CMP0045-WARN)
diff --git a/Tests/RunCMake/CMP0045/empty.cpp b/Tests/RunCMake/CMP0045/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0045/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0046/CMP0046-Duplicate-result.txt b/Tests/RunCMake/CMP0046/CMP0046-Duplicate-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-Duplicate-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0046/CMP0046-Duplicate-stderr.txt b/Tests/RunCMake/CMP0046/CMP0046-Duplicate-stderr.txt
new file mode 100644
index 0000000000..fb31d6d6e2
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-Duplicate-stderr.txt
@@ -0,0 +1,10 @@
+CMake Warning \(dev\) at CMP0046-Duplicate.cmake:5 \(add_dependencies\):
+ Policy CMP0046 is not set: Error on non-existent dependency in
+ add_dependencies. Run "cmake --help-policy CMP0046" for policy details.
+ Use the cmake_policy command to set the policy and suppress this warning.
+
+ The dependency target "ctgt_no_exist" of target "dummy" does not exist.
+Call Stack \(most recent call first\):
+ CMP0046-Duplicate.cmake:8 \(add_dep\)
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0046/CMP0046-Duplicate.cmake b/Tests/RunCMake/CMP0046/CMP0046-Duplicate.cmake
new file mode 100644
index 0000000000..26e640b9df
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-Duplicate.cmake
@@ -0,0 +1,9 @@
+
+add_library(dummy empty.cpp)
+
+macro(add_dep)
+ add_dependencies(dummy ctgt_no_exist)
+endmacro()
+
+add_dep()
+add_dep()
diff --git a/Tests/RunCMake/CMP0046/CMP0046-NEW-existing-dependency-stderr.txt b/Tests/RunCMake/CMP0046/CMP0046-NEW-existing-dependency-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-NEW-existing-dependency-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0046/CMP0046-NEW-existing-dependency.cmake b/Tests/RunCMake/CMP0046/CMP0046-NEW-existing-dependency.cmake
new file mode 100644
index 0000000000..0be290a8d8
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-NEW-existing-dependency.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0046 NEW)
+
+add_custom_target(foo)
+add_custom_target(bar)
+add_dependencies(foo bar)
diff --git a/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-result.txt b/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-stderr.txt b/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-stderr.txt
new file mode 100644
index 0000000000..381647ff88
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0046-NEW-missing-dependency.cmake:4 \(add_dependencies\):
+ The dependency target "bar" of target "foo" does not exist.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency.cmake b/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency.cmake
new file mode 100644
index 0000000000..9bb6b90c8e
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency.cmake
@@ -0,0 +1,4 @@
+cmake_policy(SET CMP0046 NEW)
+
+add_custom_target(foo)
+add_dependencies(foo bar)
diff --git a/Tests/RunCMake/CMP0046/CMP0046-OLD-existing-dependency-stderr.txt b/Tests/RunCMake/CMP0046/CMP0046-OLD-existing-dependency-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-OLD-existing-dependency-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0046/CMP0046-OLD-existing-dependency.cmake b/Tests/RunCMake/CMP0046/CMP0046-OLD-existing-dependency.cmake
new file mode 100644
index 0000000000..b22ab4fb97
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-OLD-existing-dependency.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0046 OLD)
+
+add_custom_target(foo)
+add_custom_target(bar)
+add_dependencies(foo bar)
diff --git a/Tests/RunCMake/CMP0046/CMP0046-OLD-missing-dependency-stderr.txt b/Tests/RunCMake/CMP0046/CMP0046-OLD-missing-dependency-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-OLD-missing-dependency-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0046/CMP0046-OLD-missing-dependency.cmake b/Tests/RunCMake/CMP0046/CMP0046-OLD-missing-dependency.cmake
new file mode 100644
index 0000000000..5ee3cb75eb
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-OLD-missing-dependency.cmake
@@ -0,0 +1,4 @@
+cmake_policy(SET CMP0046 OLD)
+
+add_custom_target(foo)
+add_dependencies(foo bar)
diff --git a/Tests/RunCMake/CMP0046/CMP0046-WARN-missing-dependency-stderr.txt b/Tests/RunCMake/CMP0046/CMP0046-WARN-missing-dependency-stderr.txt
new file mode 100644
index 0000000000..fed36f16eb
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-WARN-missing-dependency-stderr.txt
@@ -0,0 +1,9 @@
+CMake Warning \(dev\) at CMP0046-WARN-missing-dependency.cmake:2 \(add_dependencies\):
+ Policy CMP0046 is not set: Error on non-existent dependency in
+ add_dependencies. Run "cmake --help-policy CMP0046" for policy details.
+ Use the cmake_policy command to set the policy and suppress this warning.
++
+ The dependency target "bar" of target "foo" does not exist.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0046/CMP0046-WARN-missing-dependency.cmake b/Tests/RunCMake/CMP0046/CMP0046-WARN-missing-dependency.cmake
new file mode 100644
index 0000000000..896fa40f66
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMP0046-WARN-missing-dependency.cmake
@@ -0,0 +1,2 @@
+add_custom_target(foo)
+add_dependencies(foo bar)
diff --git a/Tests/RunCMake/CMP0046/CMakeLists.txt b/Tests/RunCMake/CMP0046/CMakeLists.txt
new file mode 100644
index 0000000000..a06591c31f
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0046/RunCMakeTest.cmake b/Tests/RunCMake/CMP0046/RunCMakeTest.cmake
new file mode 100644
index 0000000000..0a39c76596
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/RunCMakeTest.cmake
@@ -0,0 +1,9 @@
+include(RunCMake)
+
+run_cmake(CMP0046-OLD-missing-dependency)
+run_cmake(CMP0046-NEW-missing-dependency)
+run_cmake(CMP0046-WARN-missing-dependency)
+
+run_cmake(CMP0046-OLD-existing-dependency)
+run_cmake(CMP0046-NEW-existing-dependency)
+run_cmake(CMP0046-Duplicate)
diff --git a/Tests/RunCMake/CMP0046/empty.cpp b/Tests/RunCMake/CMP0046/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0046/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0049/CMP0049-NEW-result.txt b/Tests/RunCMake/CMP0049/CMP0049-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMP0049-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0049/CMP0049-NEW-stderr.txt b/Tests/RunCMake/CMP0049/CMP0049-NEW-stderr.txt
new file mode 100644
index 0000000000..ff787e8476
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMP0049-NEW-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMP0049-NEW.cmake:5 \(add_library\):
+ Legacy variable expansion in source file "\${tgt_srcs}" expanded to
+ "empty.cpp" in target "tgt". This behavior will be removed in a future
+ version of CMake.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0049/CMP0049-NEW.cmake b/Tests/RunCMake/CMP0049/CMP0049-NEW.cmake
new file mode 100644
index 0000000000..85b5aa8546
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMP0049-NEW.cmake
@@ -0,0 +1,5 @@
+
+cmake_policy(SET CMP0049 NEW)
+
+set(tgt_srcs empty.cpp)
+add_library(tgt \${tgt_srcs})
diff --git a/Tests/RunCMake/CMP0049/CMP0049-OLD-result.txt b/Tests/RunCMake/CMP0049/CMP0049-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMP0049-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0049/CMP0049-OLD-stderr.txt b/Tests/RunCMake/CMP0049/CMP0049-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMP0049-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0049/CMP0049-OLD.cmake b/Tests/RunCMake/CMP0049/CMP0049-OLD.cmake
new file mode 100644
index 0000000000..ae6fd3bcdf
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMP0049-OLD.cmake
@@ -0,0 +1,5 @@
+
+cmake_policy(SET CMP0049 OLD)
+
+set(tgt_srcs empty.cpp)
+add_library(tgt \${tgt_srcs})
diff --git a/Tests/RunCMake/CMP0049/CMP0049-WARN-result.txt b/Tests/RunCMake/CMP0049/CMP0049-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMP0049-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0049/CMP0049-WARN-stderr.txt b/Tests/RunCMake/CMP0049/CMP0049-WARN-stderr.txt
new file mode 100644
index 0000000000..0cf5ce354a
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMP0049-WARN-stderr.txt
@@ -0,0 +1,11 @@
+CMake Warning \(dev\) at CMP0049-WARN.cmake:3 \(add_library\):
+ Policy CMP0049 is not set: Do not expand variables in target source
+ entries. Run "cmake --help-policy CMP0049" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ Legacy variable expansion in source file "\${tgt_srcs}" expanded to
+ "empty.cpp" in target "tgt". This behavior will be removed in a future
+ version of CMake.
+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/CMP0049/CMP0049-WARN.cmake b/Tests/RunCMake/CMP0049/CMP0049-WARN.cmake
new file mode 100644
index 0000000000..ada082e610
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMP0049-WARN.cmake
@@ -0,0 +1,3 @@
+
+set(tgt_srcs empty.cpp)
+add_library(tgt \${tgt_srcs})
diff --git a/Tests/RunCMake/CMP0049/CMakeLists.txt b/Tests/RunCMake/CMP0049/CMakeLists.txt
new file mode 100644
index 0000000000..a06591c31f
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0049/RunCMakeTest.cmake b/Tests/RunCMake/CMP0049/RunCMakeTest.cmake
new file mode 100644
index 0000000000..a8aa9d9650
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0049-OLD)
+run_cmake(CMP0049-NEW)
+run_cmake(CMP0049-WARN)
diff --git a/Tests/RunCMake/CMP0049/empty.cpp b/Tests/RunCMake/CMP0049/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0049/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0050/CMP0050-NEW-result.txt b/Tests/RunCMake/CMP0050/CMP0050-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMP0050-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0050/CMP0050-NEW-stderr.txt b/Tests/RunCMake/CMP0050/CMP0050-NEW-stderr.txt
new file mode 100644
index 0000000000..e913b3fa90
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMP0050-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0050-NEW.cmake:5 \(add_custom_command\):
+ The SOURCE signatures of add_custom_command are no longer supported.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0050/CMP0050-NEW.cmake b/Tests/RunCMake/CMP0050/CMP0050-NEW.cmake
new file mode 100644
index 0000000000..cdc65b897c
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMP0050-NEW.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0050 NEW)
+
+add_library(empty empty.cpp)
+add_custom_command(
+ TARGET empty
+ SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/input.h
+ OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/input.h
+ DEPENDS ${CMAKE_COMMAND}
+)
diff --git a/Tests/RunCMake/CMP0050/CMP0050-OLD-result.txt b/Tests/RunCMake/CMP0050/CMP0050-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMP0050-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0050/CMP0050-OLD-stderr.txt b/Tests/RunCMake/CMP0050/CMP0050-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMP0050-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0050/CMP0050-OLD.cmake b/Tests/RunCMake/CMP0050/CMP0050-OLD.cmake
new file mode 100644
index 0000000000..efb37e55b7
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMP0050-OLD.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0050 OLD)
+
+add_library(empty empty.cpp)
+add_custom_command(
+ TARGET empty
+ SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/input.h
+ OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/input.h
+ DEPENDS ${CMAKE_COMMAND}
+)
diff --git a/Tests/RunCMake/CMP0050/CMP0050-WARN-result.txt b/Tests/RunCMake/CMP0050/CMP0050-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMP0050-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0050/CMP0050-WARN-stderr.txt b/Tests/RunCMake/CMP0050/CMP0050-WARN-stderr.txt
new file mode 100644
index 0000000000..c88d59523e
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMP0050-WARN-stderr.txt
@@ -0,0 +1,9 @@
+CMake Warning \(dev\) at CMP0050-WARN.cmake:3 \(add_custom_command\):
+ Policy CMP0050 is not set: Disallow add_custom_command SOURCE signatures.
+ Run "cmake --help-policy CMP0050" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ The SOURCE signatures of add_custom_command are no longer supported.
+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/CMP0050/CMP0050-WARN.cmake b/Tests/RunCMake/CMP0050/CMP0050-WARN.cmake
new file mode 100644
index 0000000000..e57230e5b9
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMP0050-WARN.cmake
@@ -0,0 +1,11 @@
+
+add_library(empty empty.cpp)
+add_custom_command(
+ TARGET empty
+ SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/input.h
+ OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/input.h
+ DEPENDS ${CMAKE_COMMAND}
+)
diff --git a/Tests/RunCMake/CMP0050/CMakeLists.txt b/Tests/RunCMake/CMP0050/CMakeLists.txt
new file mode 100644
index 0000000000..a06591c31f
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0050/RunCMakeTest.cmake b/Tests/RunCMake/CMP0050/RunCMakeTest.cmake
new file mode 100644
index 0000000000..b7de28491d
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0050-OLD)
+run_cmake(CMP0050-NEW)
+run_cmake(CMP0050-WARN)
diff --git a/Tests/RunCMake/CMP0050/empty.cpp b/Tests/RunCMake/CMP0050/empty.cpp
new file mode 100644
index 0000000000..182ea29c9f
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/empty.cpp
@@ -0,0 +1,10 @@
+
+#include "input.h"
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0050/input.h.in b/Tests/RunCMake/CMP0050/input.h.in
new file mode 100644
index 0000000000..d8c5d26a8b
--- /dev/null
+++ b/Tests/RunCMake/CMP0050/input.h.in
@@ -0,0 +1,2 @@
+
+#define INPUT
diff --git a/Tests/RunCMake/CMP0051/CMP0051-NEW-result.txt b/Tests/RunCMake/CMP0051/CMP0051-NEW-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-NEW-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0051/CMP0051-NEW-stderr.txt b/Tests/RunCMake/CMP0051/CMP0051-NEW-stderr.txt
new file mode 100644
index 0000000000..e5578ba98d
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-NEW-stderr.txt
@@ -0,0 +1 @@
+^Sources: "empty.cpp;\$<TARGET_OBJECTS:objects>"$
diff --git a/Tests/RunCMake/CMP0051/CMP0051-NEW.cmake b/Tests/RunCMake/CMP0051/CMP0051-NEW.cmake
new file mode 100644
index 0000000000..f304bf186c
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-NEW.cmake
@@ -0,0 +1,10 @@
+
+cmake_policy(SET CMP0051 NEW)
+
+add_library(objects OBJECT empty.cpp)
+
+add_library(empty empty.cpp $<TARGET_OBJECTS:objects>)
+
+get_target_property(srcs empty SOURCES)
+
+message("Sources: \"${srcs}\"")
diff --git a/Tests/RunCMake/CMP0051/CMP0051-OLD-result.txt b/Tests/RunCMake/CMP0051/CMP0051-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt b/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt
new file mode 100644
index 0000000000..cc17f3371d
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt
@@ -0,0 +1 @@
+^Sources: "empty.cpp"$
diff --git a/Tests/RunCMake/CMP0051/CMP0051-OLD.cmake b/Tests/RunCMake/CMP0051/CMP0051-OLD.cmake
new file mode 100644
index 0000000000..0243e944cf
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-OLD.cmake
@@ -0,0 +1,10 @@
+
+cmake_policy(SET CMP0051 OLD)
+
+add_library(objects OBJECT empty.cpp)
+
+add_library(empty empty.cpp $<TARGET_OBJECTS:objects>)
+
+get_target_property(srcs empty SOURCES)
+
+message("Sources: \"${srcs}\"")
diff --git a/Tests/RunCMake/CMP0051/CMP0051-WARN-Dir/CMakeLists.txt b/Tests/RunCMake/CMP0051/CMP0051-WARN-Dir/CMakeLists.txt
new file mode 100644
index 0000000000..77cbad53ef
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-WARN-Dir/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(empty2 ../empty.cpp $<TARGET_OBJECTS:objects>)
diff --git a/Tests/RunCMake/CMP0051/CMP0051-WARN-result.txt b/Tests/RunCMake/CMP0051/CMP0051-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt b/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt
new file mode 100644
index 0000000000..ae2e468482
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt
@@ -0,0 +1,31 @@
+CMake Warning \(dev\) at CMP0051-WARN.cmake:6 \(get_target_property\):
+ Policy CMP0051 is not set: List TARGET_OBJECTS in SOURCES target property.
+ Run "cmake --help-policy CMP0051" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ Target "empty" contains \$<TARGET_OBJECTS> generator expression in its
+ sources list. This content was not previously part of the SOURCES property
+ when that property was read at configure time. Code reading that property
+ needs to be adapted to ignore the generator expression using the
+ string\(GENEX_STRIP\) command.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+Sources: "empty.cpp"
+*
+CMake Warning \(dev\) at CMP0051-WARN.cmake:12 \(get_target_property\):
+ Policy CMP0051 is not set: List TARGET_OBJECTS in SOURCES target property.
+ Run "cmake --help-policy CMP0051" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ Target "empty2" contains \$<TARGET_OBJECTS> generator expression in its
+ sources list. This content was not previously part of the SOURCES property
+ when that property was read at configure time. Code reading that property
+ needs to be adapted to ignore the generator expression using the
+ string\(GENEX_STRIP\) command.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+Sources: "../empty.cpp"$
diff --git a/Tests/RunCMake/CMP0051/CMP0051-WARN.cmake b/Tests/RunCMake/CMP0051/CMP0051-WARN.cmake
new file mode 100644
index 0000000000..744598fcbf
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMP0051-WARN.cmake
@@ -0,0 +1,14 @@
+
+add_library(objects OBJECT empty.cpp)
+
+add_library(empty empty.cpp $<TARGET_OBJECTS:objects>)
+
+get_target_property(srcs empty SOURCES)
+
+message("Sources: \"${srcs}\"")
+
+add_subdirectory(CMP0051-WARN-Dir)
+
+get_target_property(srcs empty2 SOURCES)
+
+message("Sources: \"${srcs}\"")
diff --git a/Tests/RunCMake/CMP0051/CMakeLists.txt b/Tests/RunCMake/CMP0051/CMakeLists.txt
new file mode 100644
index 0000000000..3482e6baf2
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0051/RunCMakeTest.cmake b/Tests/RunCMake/CMP0051/RunCMakeTest.cmake
new file mode 100644
index 0000000000..621192d9f6
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0051-OLD)
+run_cmake(CMP0051-NEW)
+run_cmake(CMP0051-WARN)
diff --git a/Tests/RunCMake/CMP0051/empty.cpp b/Tests/RunCMake/CMP0051/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CMP0051/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CMP0053/CMP0053-NEW-stderr.txt b/Tests/RunCMake/CMP0053/CMP0053-NEW-stderr.txt
new file mode 100644
index 0000000000..836b0ffe92
--- /dev/null
+++ b/Tests/RunCMake/CMP0053/CMP0053-NEW-stderr.txt
@@ -0,0 +1,2 @@
+^called
+--><--$
diff --git a/Tests/RunCMake/CMP0053/CMP0053-NEW.cmake b/Tests/RunCMake/CMP0053/CMP0053-NEW.cmake
new file mode 100644
index 0000000000..6ffedc63b5
--- /dev/null
+++ b/Tests/RunCMake/CMP0053/CMP0053-NEW.cmake
@@ -0,0 +1,8 @@
+cmake_policy(SET CMP0053 NEW)
+
+function (watch_callback)
+ message("called")
+endfunction ()
+
+variable_watch(test watch_callback)
+message("-->${test}<--")
diff --git a/Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt b/Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt
new file mode 100644
index 0000000000..836b0ffe92
--- /dev/null
+++ b/Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt
@@ -0,0 +1,2 @@
+^called
+--><--$
diff --git a/Tests/RunCMake/CMP0053/CMP0053-OLD.cmake b/Tests/RunCMake/CMP0053/CMP0053-OLD.cmake
new file mode 100644
index 0000000000..41f534746b
--- /dev/null
+++ b/Tests/RunCMake/CMP0053/CMP0053-OLD.cmake
@@ -0,0 +1,8 @@
+cmake_policy(SET CMP0053 OLD)
+
+function (watch_callback)
+ message("called")
+endfunction ()
+
+variable_watch(test watch_callback)
+message("-->${test}<--")
diff --git a/Tests/RunCMake/CMP0053/CMP0053-WARN-stderr.txt b/Tests/RunCMake/CMP0053/CMP0053-WARN-stderr.txt
new file mode 100644
index 0000000000..836b0ffe92
--- /dev/null
+++ b/Tests/RunCMake/CMP0053/CMP0053-WARN-stderr.txt
@@ -0,0 +1,2 @@
+^called
+--><--$
diff --git a/Tests/RunCMake/CMP0053/CMP0053-WARN.cmake b/Tests/RunCMake/CMP0053/CMP0053-WARN.cmake
new file mode 100644
index 0000000000..b010d1319e
--- /dev/null
+++ b/Tests/RunCMake/CMP0053/CMP0053-WARN.cmake
@@ -0,0 +1,6 @@
+function (watch_callback)
+ message("called")
+endfunction ()
+
+variable_watch(test watch_callback)
+message("-->${test}<--")
diff --git a/Tests/RunCMake/CMP0053/CMakeLists.txt b/Tests/RunCMake/CMP0053/CMakeLists.txt
new file mode 100644
index 0000000000..3482e6baf2
--- /dev/null
+++ b/Tests/RunCMake/CMP0053/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0053/RunCMakeTest.cmake b/Tests/RunCMake/CMP0053/RunCMakeTest.cmake
new file mode 100644
index 0000000000..6521ac074d
--- /dev/null
+++ b/Tests/RunCMake/CMP0053/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0053-OLD)
+run_cmake(CMP0053-NEW)
+run_cmake(CMP0053-WARN)
diff --git a/Tests/RunCMake/CMP0054/CMP0054-NEW-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-NEW-stderr.txt
new file mode 100644
index 0000000000..f5a8fbe6e9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-NEW-stderr.txt
@@ -0,0 +1 @@
+$^
diff --git a/Tests/RunCMake/CMP0054/CMP0054-NEW.cmake b/Tests/RunCMake/CMP0054/CMP0054-NEW.cmake
new file mode 100644
index 0000000000..23a9124760
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-NEW.cmake
@@ -0,0 +1,47 @@
+cmake_policy(SET CMP0054 NEW)
+
+set(FOO "BAR")
+set(BAZ "ZZZ")
+set(MYTRUE ON)
+set(MYNUMBER 3)
+set(MYVERSION 3.0)
+
+function(assert_unquoted PREFIX FIRST)
+ string(REPLACE ";" " " ARGN_SP "${ARGN}")
+ if(${PREFIX} ${FIRST} ${ARGN})
+ message(FATAL_ERROR "Assertion failed [${PREFIX} ${FIRST} ${ARGN_SP}]")
+ endif()
+endfunction()
+
+function(assert_quoted PREFIX FIRST)
+ string(REPLACE ";" " " ARGN_SP "${ARGN}")
+ if(${PREFIX} "${FIRST}" ${ARGN})
+ message(FATAL_ERROR "Assertion failed [${PREFIX} \"${FIRST}\" ${ARGN_SP}]")
+ endif()
+endfunction()
+
+function(assert FIRST)
+ assert_unquoted(NOT ${FIRST} ${ARGN})
+ assert_quoted("" ${FIRST} ${ARGN})
+endfunction()
+
+assert(MYTRUE)
+
+assert(FOO MATCHES "^BAR$")
+
+assert(MYNUMBER LESS 4)
+assert(MYNUMBER GREATER 2)
+assert(MYNUMBER EQUAL 3)
+
+assert(FOO STRLESS CCC)
+assert(BAZ STRGREATER CCC)
+assert(FOO STREQUAL BAR)
+
+assert_unquoted(NOT MYVERSION VERSION_LESS 3.1)
+assert_unquoted("" MYVERSION VERSION_LESS 2.9)
+
+assert_quoted(NOT MYVERSION VERSION_LESS 2.9)
+assert_quoted(NOT MYVERSION VERSION_LESS 3.1)
+
+assert(MYVERSION VERSION_GREATER 2.9)
+assert(MYVERSION VERSION_EQUAL 3.0)
diff --git a/Tests/RunCMake/CMP0054/CMP0054-OLD-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-OLD-stderr.txt
new file mode 100644
index 0000000000..f5a8fbe6e9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-OLD-stderr.txt
@@ -0,0 +1 @@
+$^
diff --git a/Tests/RunCMake/CMP0054/CMP0054-OLD.cmake b/Tests/RunCMake/CMP0054/CMP0054-OLD.cmake
new file mode 100644
index 0000000000..0c4cede6ba
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-OLD.cmake
@@ -0,0 +1,47 @@
+cmake_policy(SET CMP0054 OLD)
+
+set(FOO "BAR")
+set(BAZ "ZZZ")
+set(MYTRUE ON)
+set(MYNUMBER 3)
+set(MYVERSION 3.0)
+
+function(assert_unquoted PREFIX FIRST)
+ string(REPLACE ";" " " ARGN_SP "${ARGN}")
+ if(${PREFIX} ${FIRST} ${ARGN})
+ message(FATAL_ERROR "Assertion failed [${PREFIX} ${FIRST} ${ARGN_SP}]")
+ endif()
+endfunction()
+
+function(assert_quoted PREFIX FIRST)
+ string(REPLACE ";" " " ARGN_SP "${ARGN}")
+ if(${PREFIX} "${FIRST}" ${ARGN})
+ message(FATAL_ERROR "Assertion failed [${PREFIX} \"${FIRST}\" ${ARGN_SP}]")
+ endif()
+endfunction()
+
+function(assert FIRST)
+ assert_unquoted(NOT ${FIRST} ${ARGN})
+ assert_quoted(NOT ${FIRST} ${ARGN})
+endfunction()
+
+assert(MYTRUE)
+
+assert(FOO MATCHES "^BAR$")
+
+assert(MYNUMBER LESS 4)
+assert(MYNUMBER GREATER 2)
+assert(MYNUMBER EQUAL 3)
+
+assert(FOO STRLESS CCC)
+assert(BAZ STRGREATER CCC)
+assert(FOO STREQUAL BAR)
+
+assert_unquoted(NOT MYVERSION VERSION_LESS 3.1)
+assert_unquoted("" MYVERSION VERSION_LESS 2.9)
+
+assert_quoted("" MYVERSION VERSION_LESS 2.9)
+assert_quoted(NOT MYVERSION VERSION_LESS 3.1)
+
+assert(MYVERSION VERSION_GREATER 2.9)
+assert(MYVERSION VERSION_EQUAL 3.0)
diff --git a/Tests/RunCMake/CMP0054/CMP0054-WARN-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-WARN-stderr.txt
new file mode 100644
index 0000000000..3d875ae1b9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-WARN-stderr.txt
@@ -0,0 +1,11 @@
+CMake Warning \(dev\) at CMP0054-WARN.cmake:3 \(if\):
+ Policy CMP0054 is not set: Only interpret if\(\) arguments as variables or
+ keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ Quoted variables like "FOO" will no longer be dereferenced when the policy
+ is set to NEW. Since the policy is not set the OLD behavior will be used.
+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/CMP0054/CMP0054-WARN.cmake b/Tests/RunCMake/CMP0054/CMP0054-WARN.cmake
new file mode 100644
index 0000000000..37855fc26a
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-WARN.cmake
@@ -0,0 +1,5 @@
+set(FOO "BAR")
+
+if(NOT "FOO" STREQUAL "BAR")
+ message(FATAL_ERROR "The given literals should match")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings-stderr.txt
new file mode 100644
index 0000000000..485db527da
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings-stderr.txt
@@ -0,0 +1,24 @@
+CMake Warning \(dev\) at CMP0054-duplicate-warnings.cmake:4 \(if\):
+ Policy CMP0054 is not set: Only interpret if\(\) arguments as variables or
+ keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ Quoted variables like "FOO" will no longer be dereferenced when the policy
+ is set to NEW. Since the policy is not set the OLD behavior will be used.
+Call Stack \(most recent call first\):
+ CMP0054-duplicate-warnings.cmake:8 \(generate_warning\)
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Warning \(dev\) at CMP0054-duplicate-warnings.cmake:11 \(if\):
+ Policy CMP0054 is not set: Only interpret if\(\) arguments as variables or
+ keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ Quoted variables like "FOO" will no longer be dereferenced when the policy
+ is set to NEW. Since the policy is not set the OLD behavior will be used.
+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/CMP0054/CMP0054-duplicate-warnings.cmake b/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings.cmake
new file mode 100644
index 0000000000..04fbe14e64
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings.cmake
@@ -0,0 +1,12 @@
+set(FOO "BAR")
+
+function(generate_warning)
+ if("FOO" STREQUAL "BAR")
+ endif()
+endfunction()
+
+generate_warning()
+generate_warning()
+
+if("FOO" STREQUAL "BAR")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-result.txt b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-stderr.txt
new file mode 100644
index 0000000000..f44468449d
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at CMP0054-keywords-NEW.cmake:23 \(if\):
+ if given arguments:
+
+ "NOT" "1"
+
+ Unknown arguments specified
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW.cmake b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW.cmake
new file mode 100644
index 0000000000..b957658b01
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW.cmake
@@ -0,0 +1,25 @@
+cmake_policy(SET CMP0054 NEW)
+
+function(assert KEYWORD)
+ if("${KEYWORD}" STREQUAL "${KEYWORD}")
+ else()
+ message(FATAL_ERROR
+ "Assertion failed [\"${KEYWORD}\" STREQUAL \"${KEYWORD}\"]")
+ endif()
+endfunction()
+
+assert("NOT")
+assert("COMMAND")
+assert("POLICY")
+assert("TARGET")
+assert("EXISTS")
+assert("IS_DIRECTORY")
+assert("IS_SYMLINK")
+assert("IS_ABSOLUTE")
+assert("DEFINED")
+assert("(")
+assert(")")
+
+if("NOT" 1)
+ message(FATAL_ERROR "[\"NOT\" 1] evaluated true")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt
new file mode 100644
index 0000000000..f5a8fbe6e9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt
@@ -0,0 +1 @@
+$^
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD.cmake b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD.cmake
new file mode 100644
index 0000000000..a2a7f51833
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD.cmake
@@ -0,0 +1,9 @@
+cmake_policy(SET CMP0054 OLD)
+
+if(NOT 1)
+ message(FATAL_ERROR "[NOT 1] evaluated true")
+endif()
+
+if("NOT" 1)
+ message(FATAL_ERROR "[\"NOT\" 1] evaluated true")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN-stderr.txt
new file mode 100644
index 0000000000..b1ebd49de3
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0054-keywords-WARN.cmake:1 \(if\):
+ Policy CMP0054 is not set: Only interpret if\(\) arguments as variables or
+ keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ Quoted keywords like "NOT" will no longer be interpreted as keywords when
+ the policy is set to NEW. Since the policy is not set the OLD behavior
+ will be used.
+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/CMP0054/CMP0054-keywords-WARN.cmake b/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN.cmake
new file mode 100644
index 0000000000..ee0a623159
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN.cmake
@@ -0,0 +1,3 @@
+if("NOT" 1)
+ message(FATAL_ERROR "[\"NOT\" 1] evaluated true")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt
new file mode 100644
index 0000000000..f5a8fbe6e9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt
@@ -0,0 +1 @@
+$^
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope.cmake b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope.cmake
new file mode 100644
index 0000000000..b6b243caa2
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope.cmake
@@ -0,0 +1,53 @@
+set(FOO BAR)
+
+cmake_policy(SET CMP0054 NEW)
+
+function(function_defined_new_called_old)
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+ endif()
+endfunction()
+
+macro(macro_defined_new_called_old)
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+ endif()
+endmacro()
+
+cmake_policy(SET CMP0054 OLD)
+
+function_defined_new_called_old()
+macro_defined_new_called_old()
+
+function(function_defined_old_called_new)
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+ endif()
+endfunction()
+
+macro(macro_defined_old_called_new)
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+ endif()
+endmacro()
+
+cmake_policy(SET CMP0054 NEW)
+
+function_defined_old_called_new()
+macro_defined_old_called_new()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope-stderr.txt
new file mode 100644
index 0000000000..f5a8fbe6e9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope-stderr.txt
@@ -0,0 +1 @@
+$^
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope.cmake b/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope.cmake
new file mode 100644
index 0000000000..87c968a06d
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope.cmake
@@ -0,0 +1,49 @@
+set(FOO BAR)
+
+cmake_policy(SET CMP0054 NEW)
+
+foreach(loop_var arg1 arg2)
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+ endif()
+
+ cmake_policy(SET CMP0054 OLD)
+
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+ endif()
+
+ cmake_policy(SET CMP0054 NEW)
+endforeach()
+
+cmake_policy(SET CMP0054 OLD)
+
+foreach(loop_var arg1 arg2)
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+ endif()
+
+ cmake_policy(SET CMP0054 NEW)
+
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+ endif()
+
+ cmake_policy(SET CMP0054 OLD)
+endforeach()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if-stderr.txt
new file mode 100644
index 0000000000..f5a8fbe6e9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if-stderr.txt
@@ -0,0 +1 @@
+$^
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if.cmake b/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if.cmake
new file mode 100644
index 0000000000..dd7434d730
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if.cmake
@@ -0,0 +1,41 @@
+set(FOO BAR)
+
+cmake_policy(SET CMP0054 NEW)
+
+if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+
+ if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+ endif()
+
+ cmake_policy(SET CMP0054 OLD)
+
+ if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+ endif()
+endif()
+
+if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+endif()
+
+cmake_policy(SET CMP0054 OLD)
+
+if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+
+ if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+ endif()
+
+ cmake_policy(SET CMP0054 NEW)
+
+ if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+ endif()
+endif()
+
+if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope-stderr.txt
new file mode 100644
index 0000000000..f5a8fbe6e9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope-stderr.txt
@@ -0,0 +1 @@
+$^
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope.cmake b/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope.cmake
new file mode 100644
index 0000000000..2b22778b5d
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope.cmake
@@ -0,0 +1,65 @@
+set(FOO BAR)
+
+set(LOOP_VAR "")
+
+cmake_policy(SET CMP0054 NEW)
+
+while(NOT LOOP_VAR STREQUAL "xx")
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+ endif()
+
+ cmake_policy(SET CMP0054 OLD)
+
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+ endif()
+
+ cmake_policy(SET CMP0054 NEW)
+
+ set(LOOP_VAR "${LOOP_VAR}x")
+endwhile()
+
+while("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+endwhile()
+
+set(LOOP_VAR "")
+
+cmake_policy(SET CMP0054 OLD)
+
+while(NOT LOOP_VAR STREQUAL "xx")
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+ endif()
+
+ cmake_policy(SET CMP0054 NEW)
+
+ if(NOT FOO STREQUAL BAR)
+ message(FATAL_ERROR "The variable should match the string")
+ endif()
+
+ if("FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The strings should not match")
+ endif()
+
+ cmake_policy(SET CMP0054 OLD)
+
+ set(LOOP_VAR "${LOOP_VAR}x")
+endwhile()
+
+if(NOT "FOO" STREQUAL BAR)
+ message(FATAL_ERROR "The quoted variable should match the string")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMakeLists.txt b/Tests/RunCMake/CMP0054/CMakeLists.txt
new file mode 100644
index 0000000000..2897109554
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0054/RunCMakeTest.cmake b/Tests/RunCMake/CMP0054/RunCMakeTest.cmake
new file mode 100644
index 0000000000..2f2fb765da
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/RunCMakeTest.cmake
@@ -0,0 +1,13 @@
+include(RunCMake)
+
+run_cmake(CMP0054-OLD)
+run_cmake(CMP0054-NEW)
+run_cmake(CMP0054-WARN)
+run_cmake(CMP0054-keywords-NEW)
+run_cmake(CMP0054-keywords-OLD)
+run_cmake(CMP0054-keywords-WARN)
+run_cmake(CMP0054-duplicate-warnings)
+run_cmake(CMP0054-policy-command-scope)
+run_cmake(CMP0054-policy-foreach-scope)
+run_cmake(CMP0054-policy-while-scope)
+run_cmake(CMP0054-policy-nested-if)
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
new file mode 100644
index 0000000000..fd3bb03208
--- /dev/null
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -0,0 +1,155 @@
+# See adjacent README.rst for documentation of this test infrastructure.
+
+macro(add_RunCMake_test test)
+ add_test(RunCMake.${test} ${CMAKE_CMAKE_COMMAND}
+ -DCMAKE_MODULE_PATH=${CMAKE_CURRENT_SOURCE_DIR}
+ -DRunCMake_GENERATOR=${CMAKE_GENERATOR}
+ -DRunCMake_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
+ -DRunCMake_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
+ -DRunCMake_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/${test}
+ -DRunCMake_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/${test}
+ ${${test}_ARGS}
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/${test}/RunCMakeTest.cmake"
+ )
+endmacro()
+
+if(XCODE_VERSION AND "${XCODE_VERSION}" VERSION_LESS 3)
+ set(GeneratorToolset_ARGS -DXCODE_BELOW_3=1)
+endif()
+
+if(XCODE_VERSION AND "${XCODE_VERSION}" VERSION_LESS 2)
+ set(TargetSources_ARGS -DXCODE_BELOW_2=1)
+ set(File_Generate_ARGS -DXCODE_BELOW_2=1)
+endif()
+
+# Test MSVC for older host CMake versions, and test
+# WIN32/CMAKE_C_COMPILER_ID to fix check on Intel for Windows.
+if(MSVC OR (WIN32 AND CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel"))
+ set(GeneratorExpression_ARGS -DLINKER_SUPPORTS_PDB=1)
+endif()
+
+add_RunCMake_test(CMP0019)
+add_RunCMake_test(CMP0022)
+add_RunCMake_test(CMP0026)
+add_RunCMake_test(CMP0027)
+add_RunCMake_test(CMP0028)
+add_RunCMake_test(CMP0037)
+add_RunCMake_test(CMP0038)
+add_RunCMake_test(CMP0039)
+add_RunCMake_test(CMP0040)
+add_RunCMake_test(CMP0041)
+if(CMAKE_SYSTEM_NAME MATCHES Darwin AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
+ add_RunCMake_test(CMP0042)
+endif()
+add_RunCMake_test(CMP0043)
+add_RunCMake_test(CMP0045)
+add_RunCMake_test(CMP0046)
+add_RunCMake_test(CMP0049)
+add_RunCMake_test(CMP0050)
+add_RunCMake_test(CMP0051)
+add_RunCMake_test(CMP0053)
+add_RunCMake_test(CMP0054)
+add_RunCMake_test(CTest)
+if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
+ add_RunCMake_test(CompilerChange)
+endif()
+add_RunCMake_test(CompilerNotFound)
+add_RunCMake_test(Configure)
+add_RunCMake_test(DisallowedCommands)
+add_RunCMake_test(ExternalData)
+add_RunCMake_test(FeatureSummary)
+add_RunCMake_test(FPHSA)
+add_RunCMake_test(GeneratorExpression)
+add_RunCMake_test(GeneratorPlatform)
+add_RunCMake_test(GeneratorToolset)
+add_RunCMake_test(TargetPropertyGeneratorExpressions)
+add_RunCMake_test(Languages)
+add_RunCMake_test(ObjectLibrary)
+add_RunCMake_test(TargetObjects)
+add_RunCMake_test(TargetSources)
+add_RunCMake_test(find_dependency)
+add_RunCMake_test(CompileFeatures)
+add_RunCMake_test(WriteCompilerDetectionHeader)
+if(NOT WIN32)
+ add_RunCMake_test(PositionIndependentCode)
+ set(SKIP_VISIBILITY 0)
+ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 4.2)
+ set(SKIP_VISIBILITY 1)
+ endif()
+
+ if (CMAKE_CXX_COMPILER_ID MATCHES Watcom
+ OR CMAKE_SYSTEM_NAME MATCHES IRIX64
+ OR CMAKE_CXX_COMPILER_ID MATCHES HP
+ OR CMAKE_CXX_COMPILER_ID MATCHES XL
+ OR CMAKE_CXX_COMPILER_ID MATCHES SunPro)
+ set(SKIP_VISIBILITY 1)
+ endif()
+
+ if (NOT SKIP_VISIBILITY)
+ add_RunCMake_test(VisibilityPreset)
+ endif()
+endif()
+if (QT4_FOUND)
+ set(CompatibleInterface_ARGS -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE})
+endif()
+add_RunCMake_test(CompatibleInterface)
+add_RunCMake_test(Syntax)
+
+add_RunCMake_test(add_dependencies)
+add_RunCMake_test(build_command)
+add_RunCMake_test(export)
+add_RunCMake_test(cmake_minimum_required)
+add_RunCMake_test(file)
+add_RunCMake_test(find_package)
+add_RunCMake_test(get_filename_component)
+add_RunCMake_test(if)
+add_RunCMake_test(include)
+add_RunCMake_test(include_directories)
+add_RunCMake_test(list)
+add_RunCMake_test(message)
+add_RunCMake_test(project)
+add_RunCMake_test(string)
+add_RunCMake_test(try_compile)
+add_RunCMake_test(set)
+add_RunCMake_test(variable_watch)
+add_RunCMake_test(CMP0004)
+add_RunCMake_test(TargetPolicies)
+add_RunCMake_test(alias_targets)
+add_RunCMake_test(interface_library)
+add_RunCMake_test(no_install_prefix)
+add_RunCMake_test(configure_file)
+
+find_package(Qt4 QUIET)
+find_package(Qt5Core QUIET)
+if (QT4_FOUND AND Qt5Core_FOUND AND NOT Qt5Core_VERSION VERSION_LESS 5.1.0)
+ add_RunCMake_test(IncompatibleQt)
+endif()
+if (QT4_FOUND)
+ set(ObsoleteQtMacros_ARGS -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE})
+ add_RunCMake_test(ObsoleteQtMacros)
+endif()
+
+find_package(PkgConfig QUIET)
+if(PKG_CONFIG_FOUND)
+ add_RunCMake_test(FindPkgConfig)
+endif()
+
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio [^6]")
+ add_RunCMake_test(include_external_msproject)
+ add_RunCMake_test(SolutionGlobalSections)
+endif()
+
+if(XCODE_VERSION AND NOT "${XCODE_VERSION}" VERSION_LESS 3)
+ add_RunCMake_test(XcodeProject)
+endif()
+
+add_RunCMake_test(File_Generate)
+add_RunCMake_test(ExportWithoutLanguage)
+add_RunCMake_test(target_link_libraries)
+
+add_RunCMake_test(target_compile_features)
+add_RunCMake_test(CheckModules)
+add_RunCMake_test(CommandLine)
+
+add_RunCMake_test(install)
+add_RunCMake_test(CPackInstallProperties)
diff --git a/Tests/RunCMake/CPackInstallProperties/Append-check.cmake b/Tests/RunCMake/CPackInstallProperties/Append-check.cmake
new file mode 100644
index 0000000000..017b30d7d5
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/Append-check.cmake
@@ -0,0 +1,3 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+
+test_property("append.txt" CPACK_TEST_PROP "value1;value2;value3")
diff --git a/Tests/RunCMake/CPackInstallProperties/Append.cmake b/Tests/RunCMake/CPackInstallProperties/Append.cmake
new file mode 100644
index 0000000000..cecc45f316
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/Append.cmake
@@ -0,0 +1,2 @@
+set_property(INSTALL append.txt PROPERTY CPACK_TEST_PROP value1)
+set_property(INSTALL append.txt PROPERTY CPACK_TEST_PROP value2 value3 APPEND)
diff --git a/Tests/RunCMake/CPackInstallProperties/CMakeLists.txt b/Tests/RunCMake/CPackInstallProperties/CMakeLists.txt
new file mode 100644
index 0000000000..89ff7c49fe
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 3.0)
+
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
+
+include(CPack)
diff --git a/Tests/RunCMake/CPackInstallProperties/FilenameGenex-check.cmake b/Tests/RunCMake/CPackInstallProperties/FilenameGenex-check.cmake
new file mode 100644
index 0000000000..8c9e967c3c
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/FilenameGenex-check.cmake
@@ -0,0 +1,3 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+
+test_property(${EXPECTED_MYTEST_NAME} CPACK_TEST_PROP2 PROP_VALUE2)
diff --git a/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake b/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake
new file mode 100644
index 0000000000..1a373b9281
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake
@@ -0,0 +1,7 @@
+add_executable(mytest test.cpp)
+
+file(GENERATE OUTPUT runtest_info.cmake CONTENT [[
+set(EXPECTED_MYTEST_NAME "$<TARGET_FILE_NAME:mytest>")
+]])
+
+set_property(INSTALL $<TARGET_FILE_NAME:mytest> PROPERTY CPACK_TEST_PROP2 PROP_VALUE2)
diff --git a/Tests/RunCMake/CPackInstallProperties/MultipleValues-check.cmake b/Tests/RunCMake/CPackInstallProperties/MultipleValues-check.cmake
new file mode 100644
index 0000000000..91278ba4a0
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/MultipleValues-check.cmake
@@ -0,0 +1,3 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+
+test_property("multiple_values.txt" CPACK_TEST_PROP "value1;value2;value3")
diff --git a/Tests/RunCMake/CPackInstallProperties/MultipleValues.cmake b/Tests/RunCMake/CPackInstallProperties/MultipleValues.cmake
new file mode 100644
index 0000000000..26db52acd4
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/MultipleValues.cmake
@@ -0,0 +1 @@
+set_property(INSTALL multiple_values.txt PROPERTY CPACK_TEST_PROP value1 value2 value3)
diff --git a/Tests/RunCMake/CPackInstallProperties/PerConfigValue-check.cmake b/Tests/RunCMake/CPackInstallProperties/PerConfigValue-check.cmake
new file mode 100644
index 0000000000..2966d88c9e
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/PerConfigValue-check.cmake
@@ -0,0 +1,13 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+
+file(GLOB INFO_FILES ${RunCMake_TEST_BINARY_DIR}/runtest_info_*.cmake)
+
+if(NOT INFO_FILES)
+ message(FATAL_ERROR "missing expected info files")
+endif()
+
+foreach(INFO_FILE IN LISTS INFO_FILES)
+ include(${INFO_FILE})
+ include(${RunCMake_TEST_BINARY_DIR}/CPackProperties.cmake)
+ test_property("config.cpp" FOO ${EXPECTED_MYTEST_NAME})
+endforeach()
diff --git a/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake b/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake
new file mode 100644
index 0000000000..77fe8ed5d8
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake
@@ -0,0 +1,14 @@
+add_executable(mytest test.cpp)
+
+foreach(CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES)
+ string(TOUPPER ${CONFIG} UPPER_CONFIG)
+ set_property(TARGET mytest PROPERTY
+ OUTPUT_NAME_${UPPER_CONFIG} bar_${CONFIG})
+endforeach()
+
+file(GENERATE OUTPUT runtest_info_$<CONFIG>.cmake CONTENT [[
+set(CPACK_BUILD_CONFIG "$<CONFIG>")
+set(EXPECTED_MYTEST_NAME "$<TARGET_FILE_NAME:mytest>")
+]])
+
+set_property(INSTALL config.cpp PROPERTY FOO $<TARGET_FILE_NAME:mytest>)
diff --git a/Tests/RunCMake/CPackInstallProperties/Replace-check.cmake b/Tests/RunCMake/CPackInstallProperties/Replace-check.cmake
new file mode 100644
index 0000000000..6e492e72d8
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/Replace-check.cmake
@@ -0,0 +1,3 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+
+test_property("replace.txt" CPACK_TEST_PROP "value2")
diff --git a/Tests/RunCMake/CPackInstallProperties/Replace.cmake b/Tests/RunCMake/CPackInstallProperties/Replace.cmake
new file mode 100644
index 0000000000..104d5a41f0
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/Replace.cmake
@@ -0,0 +1,2 @@
+set_property(INSTALL replace.txt PROPERTY CPACK_TEST_PROP value1)
+set_property(INSTALL replace.txt PROPERTY CPACK_TEST_PROP value2)
diff --git a/Tests/RunCMake/CPackInstallProperties/RunCMakeTest.cmake b/Tests/RunCMake/CPackInstallProperties/RunCMakeTest.cmake
new file mode 100644
index 0000000000..d244ac5a17
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/RunCMakeTest.cmake
@@ -0,0 +1,9 @@
+include(RunCMake)
+
+run_cmake(Simple)
+run_cmake(FilenameGenex)
+run_cmake(ValueGenex)
+run_cmake(MultipleValues)
+run_cmake(Append)
+run_cmake(Replace)
+run_cmake(PerConfigValue)
diff --git a/Tests/RunCMake/CPackInstallProperties/Simple-check.cmake b/Tests/RunCMake/CPackInstallProperties/Simple-check.cmake
new file mode 100644
index 0000000000..6a7ee2aa49
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/Simple-check.cmake
@@ -0,0 +1,3 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+
+test_property("foo/test.cpp" CPACK_TEST_PROP PROP_VALUE)
diff --git a/Tests/RunCMake/CPackInstallProperties/Simple.cmake b/Tests/RunCMake/CPackInstallProperties/Simple.cmake
new file mode 100644
index 0000000000..2eb87553ae
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/Simple.cmake
@@ -0,0 +1 @@
+set_property(INSTALL foo/test.cpp PROPERTY CPACK_TEST_PROP PROP_VALUE)
diff --git a/Tests/RunCMake/CPackInstallProperties/ValueGenex-check.cmake b/Tests/RunCMake/CPackInstallProperties/ValueGenex-check.cmake
new file mode 100644
index 0000000000..cdfbcda22c
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/ValueGenex-check.cmake
@@ -0,0 +1,3 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+
+test_property("bar/test.cpp" CPACK_TEST_PROP ${EXPECTED_MYTEST_NAME})
diff --git a/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake b/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake
new file mode 100644
index 0000000000..2e1d4656cb
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake
@@ -0,0 +1,7 @@
+add_executable(mytest test.cpp)
+
+file(GENERATE OUTPUT runtest_info.cmake CONTENT [[
+set(EXPECTED_MYTEST_NAME "$<TARGET_FILE_NAME:mytest>")
+]])
+
+set_property(INSTALL bar/test.cpp PROPERTY CPACK_TEST_PROP $<TARGET_FILE_NAME:mytest>)
diff --git a/Tests/RunCMake/CPackInstallProperties/check.cmake b/Tests/RunCMake/CPackInstallProperties/check.cmake
new file mode 100644
index 0000000000..65aa467bd8
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/check.cmake
@@ -0,0 +1,12 @@
+function(test_property FILE NAME EXPECTED_VALUE)
+ get_property(ACTUAL_VALUE INSTALL "${FILE}" PROPERTY "${NAME}")
+
+ if(NOT "${ACTUAL_VALUE}" STREQUAL "${EXPECTED_VALUE}")
+ message(FATAL_ERROR "${NAME}@${FILE}: property mismatch expected [${EXPECTED_VALUE}] actual [${ACTUAL_VALUE}] (Config:${CPACK_BUILD_CONFIG})")
+ endif()
+endfunction()
+
+set(CPACK_BUILD_CONFIG Debug)
+include(${RunCMake_TEST_BINARY_DIR}/CPackProperties.cmake)
+
+include(${RunCMake_TEST_BINARY_DIR}/runtest_info.cmake OPTIONAL)
diff --git a/Tests/RunCMake/CPackInstallProperties/test.cpp b/Tests/RunCMake/CPackInstallProperties/test.cpp
new file mode 100644
index 0000000000..237c8ce181
--- /dev/null
+++ b/Tests/RunCMake/CPackInstallProperties/test.cpp
@@ -0,0 +1 @@
+int main() {}
diff --git a/Tests/RunCMake/CTest/BeforeProject-result.txt b/Tests/RunCMake/CTest/BeforeProject-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CTest/BeforeProject-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CTest/BeforeProject-stderr.txt b/Tests/RunCMake/CTest/BeforeProject-stderr.txt
new file mode 100644
index 0000000000..2d934a4209
--- /dev/null
+++ b/Tests/RunCMake/CTest/BeforeProject-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*/Modules/CTestTargets.cmake:20 \(message\):
+ Do not include\(CTest\) before calling project\(\).
+Call Stack \(most recent call first\):
+ .*/Modules/CTest.cmake:297 \(include\)
+ BeforeProject.cmake:1 \(include\)
+ CMakeLists.txt:5 \(include\)
diff --git a/Tests/RunCMake/CTest/BeforeProject.cmake b/Tests/RunCMake/CTest/BeforeProject.cmake
new file mode 100644
index 0000000000..903ca69332
--- /dev/null
+++ b/Tests/RunCMake/CTest/BeforeProject.cmake
@@ -0,0 +1,2 @@
+include(CTest)
+project(${RunCMake_TEST} NONE)
diff --git a/Tests/RunCMake/CTest/CMakeLists.txt b/Tests/RunCMake/CTest/CMakeLists.txt
new file mode 100644
index 0000000000..73e6a785a4
--- /dev/null
+++ b/Tests/RunCMake/CTest/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.4)
+if(NOT NoProject)
+ project(${RunCMake_TEST} NONE)
+endif()
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CTest/RunCMakeTest.cmake b/Tests/RunCMake/CTest/RunCMakeTest.cmake
new file mode 100644
index 0000000000..a6f684224f
--- /dev/null
+++ b/Tests/RunCMake/CTest/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+set(RunCMake_TEST_OPTIONS -DNoProject=1)
+run_cmake(BeforeProject)
+unset(RunCMake_TEST_OPTIONS)
diff --git a/Tests/RunCMake/CheckModules/CMakeLists.txt b/Tests/RunCMake/CheckModules/CMakeLists.txt
new file mode 100644
index 0000000000..72abfc8099
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey-result.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey-stderr.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey-stderr.txt
new file mode 100644
index 0000000000..1b8603a836
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at .*/Modules/CheckStructHasMember.cmake:[0-9]+. \(message\):
+ Unknown arguments:
+
+ C
+
+Call Stack \(most recent call first\):
+ CheckStructHasMemberMissingKey.cmake:[0-9]+ \(check_struct_has_member\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey.cmake b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey.cmake
new file mode 100644
index 0000000000..49f51ceca4
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingKey.cmake
@@ -0,0 +1,2 @@
+include(CheckStructHasMember)
+check_struct_has_member("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC_K C)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage-result.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage-stderr.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage-stderr.txt
new file mode 100644
index 0000000000..8fceab0df0
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at .*/Modules/CheckStructHasMember.cmake:[0-9]+. \(message\):
+ Unknown arguments:
+
+ LANGUAGE
+
+Call Stack \(most recent call first\):
+ CheckStructHasMemberMissingLanguage.cmake:[0-9]+ \(check_struct_has_member\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage.cmake b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage.cmake
new file mode 100644
index 0000000000..b404d665b3
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberMissingLanguage.cmake
@@ -0,0 +1,2 @@
+include(CheckStructHasMember)
+check_struct_has_member("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC_K LANGUAGE)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberOk.cmake b/Tests/RunCMake/CheckModules/CheckStructHasMemberOk.cmake
new file mode 100644
index 0000000000..4c064c5010
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberOk.cmake
@@ -0,0 +1,6 @@
+enable_language(C)
+enable_language(CXX)
+include(CheckStructHasMember)
+check_struct_has_member("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC)
+check_struct_has_member("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC_C LANGUAGE C)
+check_struct_has_member("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC_CXX LANGUAGE CXX)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments-result.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments-stderr.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments-stderr.txt
new file mode 100644
index 0000000000..4598867441
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at .*/Modules/CheckStructHasMember.cmake:[0-9]+. \(message\):
+ Unknown arguments:
+
+ LANGUAGE;C;CXX
+
+Call Stack \(most recent call first\):
+ CheckStructHasMemberTooManyArguments.cmake:[0-9]+ \(check_struct_has_member\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments.cmake b/Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments.cmake
new file mode 100644
index 0000000000..12f81582dc
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberTooManyArguments.cmake
@@ -0,0 +1,2 @@
+include(CheckStructHasMember)
+check_struct_has_member("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC_K LANGUAGE C CXX)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage-result.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage-stderr.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage-stderr.txt
new file mode 100644
index 0000000000..ba9e31312a
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at .*/Modules/CheckStructHasMember.cmake:[0-9]+. \(message\):
+ Unknown language:
+
+ FORTRAN
+
+ Supported languages: C, CXX.
+
+Call Stack \(most recent call first\):
+ CheckStructHasMemberUnknownLanguage.cmake:[0-9]+ \(check_struct_has_member\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage.cmake b/Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage.cmake
new file mode 100644
index 0000000000..183058ddce
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberUnknownLanguage.cmake
@@ -0,0 +1,2 @@
+include(CheckStructHasMember)
+check_struct_has_member("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC_K LANGUAGE FORTRAN)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey-result.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey-stderr.txt b/Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey-stderr.txt
new file mode 100644
index 0000000000..b9fbd38cf8
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at .*/Modules/CheckStructHasMember.cmake:[0-9]+. \(message\):
+ Unknown arguments:
+
+ LANGUAG;C
+
+Call Stack \(most recent call first\):
+ CheckStructHasMemberWrongKey.cmake:[0-9]+ \(check_struct_has_member\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey.cmake b/Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey.cmake
new file mode 100644
index 0000000000..900eb0a75e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckStructHasMemberWrongKey.cmake
@@ -0,0 +1,2 @@
+include(CheckStructHasMember)
+check_struct_has_member("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC_K LANGUAG C)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage-result.txt b/Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage-stderr.txt b/Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage-stderr.txt
new file mode 100644
index 0000000000..07ec8e6a41
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at .*/Modules/CheckTypeSize.cmake:[0-9]+ \(message\):
+ Missing argument:
+
+ LANGUAGE arguments requires a value
+
+Call Stack \(most recent call first\):
+ CheckTypeSizeMissingLanguage.cmake:[0-9]+ \(check_type_size\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage.cmake b/Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage.cmake
new file mode 100644
index 0000000000..3fae6c4dbc
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeMissingLanguage.cmake
@@ -0,0 +1,2 @@
+include(CheckTypeSize)
+check_type_size(int SIZEOF_INT LANGUAGE)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs-result.txt b/Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs-stderr.txt b/Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs-stderr.txt
new file mode 100644
index 0000000000..a2d2fc0411
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at .*/Modules/CheckTypeSize.cmake:[0-9]+. \(message\):
+ Unknown language:
+
+ .
+
+ Supported languages: C, CXX.
+
+Call Stack \(most recent call first\):
+ CheckTypeSizeMixedArgs.cmake:[0-9]+ \(check_type_size\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs.cmake b/Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs.cmake
new file mode 100644
index 0000000000..d2ccc0fad1
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeMixedArgs.cmake
@@ -0,0 +1,2 @@
+include(CheckTypeSize)
+check_type_size(int SIZEOF_INT LANGUAGE BUILTIN_TYPES_ONLY)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeOk.cmake b/Tests/RunCMake/CheckModules/CheckTypeSizeOk.cmake
new file mode 100644
index 0000000000..45a4978fcf
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeOk.cmake
@@ -0,0 +1,12 @@
+enable_language(C)
+enable_language(CXX)
+include(CheckTypeSize)
+check_type_size(int SIZEOF_INT)
+check_type_size(int SIZEOF_INT BUILTIN_TYPES_ONLY)
+check_type_size(int SIZEOF_INT LANGUAGE C)
+check_type_size(int SIZEOF_INT LANGUAGE CXX)
+check_type_size(int SIZEOF_INT BUILTIN_TYPES_ONLY LANGUAGE C)
+
+# Weird but ok... only last value is considered
+check_type_size(int SIZEOF_INT BUILTIN_TYPES_ONLY BUILTIN_TYPES_ONLY)
+check_type_size(int SIZEOF_INT LANGUAGE C LANGUAGE CXX)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeOkNoC.cmake b/Tests/RunCMake/CheckModules/CheckTypeSizeOkNoC.cmake
new file mode 100644
index 0000000000..b2dcd7f9b9
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeOkNoC.cmake
@@ -0,0 +1,4 @@
+enable_language(CXX)
+include(CheckTypeSize)
+check_type_size(int SIZEOF_INT LANGUAGE CXX)
+check_type_size(int SIZEOF_INT BUILTIN_TYPES_ONLY LANGUAGE CXX)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument-result.txt b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument-stderr.txt b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument-stderr.txt
new file mode 100644
index 0000000000..085488e739
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at .*/Modules/CheckTypeSize.cmake:[0-9]+. \(message\):
+ Unknown argument:
+
+ LANGUAG
+
+Call Stack \(most recent call first\):
+ CheckTypeSizeUnknownArgument.cmake:[0-9]+ \(check_type_size\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument.cmake b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument.cmake
new file mode 100644
index 0000000000..6f24ee16c1
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownArgument.cmake
@@ -0,0 +1,2 @@
+include(CheckTypeSize)
+check_type_size(int SIZEOF_INT BUILTIN_TYPES_ONLY LANGUAG CXX)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage-result.txt b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage-stderr.txt b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage-stderr.txt
new file mode 100644
index 0000000000..502a7172c4
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at .*/Modules/CheckTypeSize.cmake:[0-9]+. \(message\):
+ Unknown language:
+
+ FORTRAN.
+
+ Supported languages: C, CXX.
+
+Call Stack \(most recent call first\):
+ CheckTypeSizeUnknownLanguage.cmake:[0-9]+ \(check_type_size\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage.cmake b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage.cmake
new file mode 100644
index 0000000000..2d5184cd69
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/CheckTypeSizeUnknownLanguage.cmake
@@ -0,0 +1,2 @@
+include(CheckTypeSize)
+check_type_size(int SIZEOF_INT LANGUAGE FORTRAN)
diff --git a/Tests/RunCMake/CheckModules/RunCMakeTest.cmake b/Tests/RunCMake/CheckModules/RunCMakeTest.cmake
new file mode 100644
index 0000000000..5b4e57edc6
--- /dev/null
+++ b/Tests/RunCMake/CheckModules/RunCMakeTest.cmake
@@ -0,0 +1,16 @@
+include(RunCMake)
+
+run_cmake(CheckStructHasMemberOk)
+run_cmake(CheckStructHasMemberUnknownLanguage)
+run_cmake(CheckStructHasMemberMissingLanguage)
+run_cmake(CheckStructHasMemberMissingKey)
+run_cmake(CheckStructHasMemberTooManyArguments)
+run_cmake(CheckStructHasMemberWrongKey)
+
+run_cmake(CheckTypeSizeOk)
+run_cmake(CheckTypeSizeUnknownLanguage)
+run_cmake(CheckTypeSizeMissingLanguage)
+run_cmake(CheckTypeSizeUnknownArgument)
+run_cmake(CheckTypeSizeMixedArgs)
+
+run_cmake(CheckTypeSizeOkNoC)
diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake b/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake
new file mode 100644
index 0000000000..d7e652de73
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake
@@ -0,0 +1,6 @@
+if(NOT IS_SYMLINK ${RunCMake_TEST_BINARY_DIR}/L)
+ set(RunCMake_TEST_FAILED "Symlink 'L' incorrectly not created!")
+endif()
+if(EXISTS ${RunCMake_TEST_BINARY_DIR}/L)
+ set(RunCMake_TEST_FAILED "Symlink 'L' not broken!")
+endif()
diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake b/Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake
new file mode 100644
index 0000000000..c078ae8fc2
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake
@@ -0,0 +1,3 @@
+if(NOT IS_DIRECTORY ${RunCMake_TEST_BINARY_DIR}/L)
+ set(RunCMake_TEST_FAILED "Symlink 'L' not replaced correctly!")
+endif()
diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-missing-dir-result.txt b/Tests/RunCMake/CommandLine/E_create_symlink-missing-dir-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_create_symlink-missing-dir-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-missing-dir-stderr.txt b/Tests/RunCMake/CommandLine/E_create_symlink-missing-dir-stderr.txt
new file mode 100644
index 0000000000..7a6d84b2c1
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_create_symlink-missing-dir-stderr.txt
@@ -0,0 +1 @@
+failed to create symbolic link 'missing-dir/L':
diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-no-replace-dir-result.txt b/Tests/RunCMake/CommandLine/E_create_symlink-no-replace-dir-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_create_symlink-no-replace-dir-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-no-replace-dir-stderr.txt b/Tests/RunCMake/CommandLine/E_create_symlink-no-replace-dir-stderr.txt
new file mode 100644
index 0000000000..ebed0d67c9
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_create_symlink-no-replace-dir-stderr.txt
@@ -0,0 +1 @@
+failed to create symbolic link '\.' because existing path cannot be removed:
diff --git a/Tests/RunCMake/CommandLine/E_env-bad-arg1-result.txt b/Tests/RunCMake/CommandLine/E_env-bad-arg1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-bad-arg1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_env-bad-arg1-stderr.txt b/Tests/RunCMake/CommandLine/E_env-bad-arg1-stderr.txt
new file mode 100644
index 0000000000..2143ba417b
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-bad-arg1-stderr.txt
@@ -0,0 +1 @@
+^cmake -E env: unknown option '-bad-arg1'$
diff --git a/Tests/RunCMake/CommandLine/E_env-no-command0-result.txt b/Tests/RunCMake/CommandLine/E_env-no-command0-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-no-command0-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_env-no-command0-stderr.txt b/Tests/RunCMake/CommandLine/E_env-no-command0-stderr.txt
new file mode 100644
index 0000000000..d2efa53673
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-no-command0-stderr.txt
@@ -0,0 +1 @@
+^cmake -E env: no command given$
diff --git a/Tests/RunCMake/CommandLine/E_env-no-command1-result.txt b/Tests/RunCMake/CommandLine/E_env-no-command1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-no-command1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_env-no-command1-stderr.txt b/Tests/RunCMake/CommandLine/E_env-no-command1-stderr.txt
new file mode 100644
index 0000000000..d2efa53673
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-no-command1-stderr.txt
@@ -0,0 +1 @@
+^cmake -E env: no command given$
diff --git a/Tests/RunCMake/CommandLine/E_env-set-stdout.txt b/Tests/RunCMake/CommandLine/E_env-set-stdout.txt
new file mode 100644
index 0000000000..feff1176ea
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-set-stdout.txt
@@ -0,0 +1 @@
+^-- TEST_ENV is correctly set in environment: 1$
diff --git a/Tests/RunCMake/CommandLine/E_env-set.cmake b/Tests/RunCMake/CommandLine/E_env-set.cmake
new file mode 100644
index 0000000000..c2639b6634
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-set.cmake
@@ -0,0 +1,5 @@
+if(DEFINED ENV{TEST_ENV})
+ message(STATUS "TEST_ENV is correctly set in environment: $ENV{TEST_ENV}")
+else()
+ message(FATAL_ERROR "TEST_ENV is incorrectly not set in environment")
+endif()
diff --git a/Tests/RunCMake/CommandLine/E_env-unset-stdout.txt b/Tests/RunCMake/CommandLine/E_env-unset-stdout.txt
new file mode 100644
index 0000000000..a1d5c01083
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-unset-stdout.txt
@@ -0,0 +1 @@
+^-- TEST_ENV is correctly not set in environment$
diff --git a/Tests/RunCMake/CommandLine/E_env-unset.cmake b/Tests/RunCMake/CommandLine/E_env-unset.cmake
new file mode 100644
index 0000000000..04976fb40a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_env-unset.cmake
@@ -0,0 +1,5 @@
+if(DEFINED ENV{TEST_ENV})
+ message(FATAL_ERROR "TEST_ENV is incorrectly set in environment")
+else()
+ message(STATUS "TEST_ENV is correctly not set in environment")
+endif()
diff --git a/Tests/RunCMake/CommandLine/E_sleep-bad-arg1-result.txt b/Tests/RunCMake/CommandLine/E_sleep-bad-arg1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_sleep-bad-arg1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_sleep-bad-arg1-stderr.txt b/Tests/RunCMake/CommandLine/E_sleep-bad-arg1-stderr.txt
new file mode 100644
index 0000000000..45e6ebc3f4
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_sleep-bad-arg1-stderr.txt
@@ -0,0 +1 @@
+^Unknown sleep time format "x"\.$
diff --git a/Tests/RunCMake/CommandLine/E_sleep-bad-arg2-result.txt b/Tests/RunCMake/CommandLine/E_sleep-bad-arg2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_sleep-bad-arg2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_sleep-bad-arg2-stderr.txt b/Tests/RunCMake/CommandLine/E_sleep-bad-arg2-stderr.txt
new file mode 100644
index 0000000000..399d47fbf9
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_sleep-bad-arg2-stderr.txt
@@ -0,0 +1 @@
+^Unknown sleep time format "-1"\.$
diff --git a/Tests/RunCMake/CommandLine/E_sleep-no-args-result.txt b/Tests/RunCMake/CommandLine/E_sleep-no-args-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_sleep-no-args-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_sleep-no-args-stderr.cmake b/Tests/RunCMake/CommandLine/E_sleep-no-args-stderr.cmake
new file mode 100644
index 0000000000..977f1efe85
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_sleep-no-args-stderr.cmake
@@ -0,0 +1,2 @@
+Usage: .*/cmake -E \[command\] \[arguments \.\.\.\]
+Available commands:
diff --git a/Tests/RunCMake/CommandLine/P_directory-result.txt b/Tests/RunCMake/CommandLine/P_directory-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/P_directory-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/P_directory-stderr.txt b/Tests/RunCMake/CommandLine/P_directory-stderr.txt
new file mode 100644
index 0000000000..b8319a1fe7
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/P_directory-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: Error processing file: .*/Tests/RunCMake/CommandLine$
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
new file mode 100644
index 0000000000..5622a5ba8c
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -0,0 +1,45 @@
+include(RunCMake)
+
+run_cmake_command(build-no-cache
+ ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR})
+run_cmake_command(build-no-generator
+ ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-no-generator)
+run_cmake_command(build-bad-generator
+ ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-generator)
+
+if(UNIX)
+ run_cmake_command(E_create_symlink-missing-dir
+ ${CMAKE_COMMAND} -E create_symlink T missing-dir/L
+ )
+
+ # Use a single build tree for a few tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR
+ ${RunCMake_BINARY_DIR}/E_create_symlink-broken-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake_command(E_create_symlink-broken-create
+ ${CMAKE_COMMAND} -E create_symlink T L
+ )
+ run_cmake_command(E_create_symlink-broken-replace
+ ${CMAKE_COMMAND} -E create_symlink . L
+ )
+ unset(RunCMake_TEST_BINARY_DIR)
+ unset(RunCMake_TEST_NO_CLEAN)
+
+ run_cmake_command(E_create_symlink-no-replace-dir
+ ${CMAKE_COMMAND} -E create_symlink T .
+ )
+endif()
+
+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)
+run_cmake_command(E_env-set ${CMAKE_COMMAND} -E env TEST_ENV=1 ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_env-set.cmake)
+run_cmake_command(E_env-unset ${CMAKE_COMMAND} -E env TEST_ENV=1 ${CMAKE_COMMAND} -E env --unset=TEST_ENV ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_env-unset.cmake)
+
+run_cmake_command(E_sleep-no-args ${CMAKE_COMMAND} -E sleep)
+run_cmake_command(E_sleep-bad-arg1 ${CMAKE_COMMAND} -E sleep x)
+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})
diff --git a/Tests/RunCMake/CommandLine/build-bad-generator-result.txt b/Tests/RunCMake/CommandLine/build-bad-generator-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/build-bad-generator-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/build-bad-generator-stderr.txt b/Tests/RunCMake/CommandLine/build-bad-generator-stderr.txt
new file mode 100644
index 0000000000..110340749e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/build-bad-generator-stderr.txt
@@ -0,0 +1 @@
+^Error: could create CMAKE_GENERATOR "Bad Generator"$
diff --git a/Tests/RunCMake/CommandLine/build-no-cache-result.txt b/Tests/RunCMake/CommandLine/build-no-cache-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/build-no-cache-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt b/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt
new file mode 100644
index 0000000000..40dd3c0979
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt
@@ -0,0 +1 @@
+^Error: could not load cache$
diff --git a/Tests/RunCMake/CommandLine/build-no-generator-result.txt b/Tests/RunCMake/CommandLine/build-no-generator-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/build-no-generator-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/build-no-generator-stderr.txt b/Tests/RunCMake/CommandLine/build-no-generator-stderr.txt
new file mode 100644
index 0000000000..40ad030be3
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/build-no-generator-stderr.txt
@@ -0,0 +1 @@
+^Error: could not find CMAKE_GENERATOR in Cache$
diff --git a/Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt b/Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt
new file mode 100644
index 0000000000..e34af4432f
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt
@@ -0,0 +1 @@
+CMAKE_GENERATOR:INTERNAL=Bad Generator
diff --git a/Tests/RunCMake/CommandLine/cache-no-generator/CMakeCache.txt b/Tests/RunCMake/CommandLine/cache-no-generator/CMakeCache.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cache-no-generator/CMakeCache.txt
diff --git a/Tests/RunCMake/CompatibleInterface/AutoUic-result.txt b/Tests/RunCMake/CompatibleInterface/AutoUic-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/AutoUic-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/AutoUic-stderr.txt b/Tests/RunCMake/CompatibleInterface/AutoUic-stderr.txt
new file mode 100644
index 0000000000..09f9461daa
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/AutoUic-stderr.txt
@@ -0,0 +1,11 @@
+CMake Error: The INTERFACE_AUTOUIC_OPTIONS property of "OtherI18n" does
+not agree with the value of AUTOUIC_OPTIONS already determined
+for "LibWidget".
+
+CMake Debug Log:
+ String compatibility of property "AUTOUIC_OPTIONS" for target "LibWidget"
+ \(result: "-tr;ki18n"\):
+
+ \* Target "LibWidget" property not set.
+ \* Target "KI18n" property value "-tr;ki18n" \(Interface set\)
+ \* Target "OtherI18n" property value "-tr;otheri18n" \(Disagree\)
diff --git a/Tests/RunCMake/CompatibleInterface/AutoUic.cmake b/Tests/RunCMake/CompatibleInterface/AutoUic.cmake
new file mode 100644
index 0000000000..03635e2a5f
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/AutoUic.cmake
@@ -0,0 +1,19 @@
+
+find_package(Qt4 REQUIRED)
+
+set(CMAKE_AUTOUIC ON)
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES AUTOUIC_OPTIONS)
+
+add_library(KI18n INTERFACE)
+set_property(TARGET KI18n APPEND PROPERTY
+ INTERFACE_AUTOUIC_OPTIONS -tr ki18n
+)
+
+add_library(OtherI18n INTERFACE)
+set_property(TARGET OtherI18n APPEND PROPERTY
+ INTERFACE_AUTOUIC_OPTIONS -tr otheri18n
+)
+
+add_library(LibWidget empty.cpp)
+target_link_libraries(LibWidget KI18n OtherI18n Qt4::QtGui)
diff --git a/Tests/RunCMake/CompatibleInterface/CMakeLists.txt b/Tests/RunCMake/CompatibleInterface/CMakeLists.txt
new file mode 100644
index 0000000000..f452db1770
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CompatibleInterface/DebugProperties-result.txt b/Tests/RunCMake/CompatibleInterface/DebugProperties-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/DebugProperties-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CompatibleInterface/DebugProperties-stderr.txt b/Tests/RunCMake/CompatibleInterface/DebugProperties-stderr.txt
new file mode 100644
index 0000000000..17b8a5cfeb
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/DebugProperties-stderr.txt
@@ -0,0 +1,101 @@
+CMake Debug Log:
+ Boolean compatibility of property "BOOL_PROP1" for target
+ "CompatibleInterface" \(result: "TRUE"\):
+
+ \* Target "CompatibleInterface" property not set.
+ \* Target "iface1" property value "TRUE" \(Interface set\)
++
+CMake Debug Log:
+ Boolean compatibility of property "BOOL_PROP2" for target
+ "CompatibleInterface" \(result: "TRUE"\):
+
+ \* Target "CompatibleInterface" has property content "TRUE"
+ \* Target "iface1" property value "TRUE" \(Agree\)
++
+CMake Debug Log:
+ Boolean compatibility of property "BOOL_PROP3" for target
+ "CompatibleInterface" \(result: "TRUE"\):
+
+ \* Target "CompatibleInterface" has property content "TRUE"
++
+CMake Debug Log:
+ Boolean compatibility of property "BOOL_PROP4" for target
+ "CompatibleInterface" \(result: "FALSE"\):
+
+ \* Target "CompatibleInterface" property not set.
++
+CMake Debug Log:
+ Boolean compatibility of property "BOOL_PROP5" for target
+ "CompatibleInterface" \(result: "FALSE"\):
+
+ \* Target "CompatibleInterface" property not set.
+ \* Target "iface1" property value "FALSE" \(Interface set\)
++
+CMake Debug Log:
+ Boolean compatibility of property "BOOL_PROP6" for target
+ "CompatibleInterface" \(result: "FALSE"\):
+
+ \* Target "CompatibleInterface" property not set.
+ \* Target "iface1" property value "FALSE" \(Interface set\)
+ \* Target "iface2" property value "FALSE" \(Agree\)
++
+CMake Debug Log:
+ Boolean compatibility of property "BOOL_PROP7" for target
+ "CompatibleInterface" \(result: "FALSE"\):
+
+ \* Target "CompatibleInterface" property is implied by use.
+ \* Target "iface1" property value "FALSE" \(Agree\)
++
+CMake Debug Log:
+ String compatibility of property "STRING_PROP1" for target
+ "CompatibleInterface" \(result: "prop1"\):
+
+ \* Target "CompatibleInterface" property not set.
+ \* Target "iface1" property value "prop1" \(Interface set\)
++
+CMake Debug Log:
+ String compatibility of property "STRING_PROP2" for target
+ "CompatibleInterface" \(result: "prop2"\):
+
+ \* Target "CompatibleInterface" has property content "prop2"
+ \* Target "iface1" property value "prop2" \(Agree\)
++
+CMake Debug Log:
+ String compatibility of property "STRING_PROP3" for target
+ "CompatibleInterface" \(result: "prop3"\):
+
+ \* Target "CompatibleInterface" has property content "prop3"
++
+CMake Debug Log:
+ String compatibility of property "STRING_PROP4" for target
+ "CompatibleInterface" \(result: "\(unset\)"\):
+
+ \* Target "CompatibleInterface" property not set.
++
+CMake Debug Log:
+ Numeric minimum compatibility of property "NUMBER_MIN_PROP1" for target
+ "CompatibleInterface" \(result: "50"\):
+
+ \* Target "CompatibleInterface" has property content "50"
+ \* Target "iface1" property value "100" \(Ignored\)
++
+CMake Debug Log:
+ Numeric minimum compatibility of property "NUMBER_MIN_PROP2" for target
+ "CompatibleInterface" \(result: "200"\):
+
+ \* Target "CompatibleInterface" has property content "250"
+ \* Target "iface1" property value "200" \(Dominant\)
++
+CMake Debug Log:
+ Numeric maximum compatibility of property "NUMBER_MAX_PROP1" for target
+ "CompatibleInterface" \(result: "100"\):
+
+ \* Target "CompatibleInterface" has property content "50"
+ \* Target "iface1" property value "100" \(Dominant\)
++
+CMake Debug Log:
+ Numeric maximum compatibility of property "NUMBER_MAX_PROP2" for target
+ "CompatibleInterface" \(result: "250"\):
+
+ \* Target "CompatibleInterface" has property content "250"
+ \* Target "iface1" property value "200" \(Ignored\)
diff --git a/Tests/RunCMake/CompatibleInterface/DebugProperties.cmake b/Tests/RunCMake/CompatibleInterface/DebugProperties.cmake
new file mode 100644
index 0000000000..0196611ca3
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/DebugProperties.cmake
@@ -0,0 +1,74 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(CompatibleInterface)
+
+include(GenerateExportHeader)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_library(iface1 INTERFACE)
+set_property(TARGET iface1 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_BOOL
+ BOOL_PROP1
+ BOOL_PROP2
+ BOOL_PROP3
+ BOOL_PROP4
+ BOOL_PROP5
+ BOOL_PROP6
+ BOOL_PROP7
+)
+set_property(TARGET iface1 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_STRING
+ STRING_PROP1
+ STRING_PROP2
+ STRING_PROP3
+ STRING_PROP4 # Not set.
+)
+set_property(TARGET iface1 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_NUMBER_MIN
+ NUMBER_MIN_PROP1
+ NUMBER_MIN_PROP2
+)
+set_property(TARGET iface1 APPEND PROPERTY
+ COMPATIBLE_INTERFACE_NUMBER_MAX
+ NUMBER_MAX_PROP1
+ NUMBER_MAX_PROP2
+)
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES
+ BOOL_PROP1 BOOL_PROP2 BOOL_PROP3 BOOL_PROP4 BOOL_PROP5 BOOL_PROP6 BOOL_PROP7
+ STRING_PROP1 STRING_PROP2 STRING_PROP3 STRING_PROP4
+ NUMBER_MIN_PROP1 NUMBER_MIN_PROP2
+ NUMBER_MAX_PROP1 NUMBER_MAX_PROP2
+)
+
+set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP1 ON)
+set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP2 ON)
+set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP5 OFF)
+set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP6 OFF)
+set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP7 OFF)
+set_property(TARGET iface1 PROPERTY INTERFACE_STRING_PROP1 prop1)
+set_property(TARGET iface1 PROPERTY INTERFACE_STRING_PROP2 prop2)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP1 100)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP2 200)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP1 100)
+set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP2 200)
+
+add_library(iface2 INTERFACE)
+set_property(TARGET iface2 PROPERTY INTERFACE_BOOL_PROP6 OFF)
+
+add_library(iface3 INTERFACE)
+
+add_executable(CompatibleInterface empty.cpp)
+target_link_libraries(CompatibleInterface iface1 iface2
+ $<$<BOOL:$<TARGET_PROPERTY:BOOL_PROP7>>:iface3>
+)
+
+set_property(TARGET CompatibleInterface PROPERTY BOOL_PROP2 ON)
+set_property(TARGET CompatibleInterface PROPERTY BOOL_PROP3 ON)
+set_property(TARGET CompatibleInterface PROPERTY STRING_PROP2 prop2)
+set_property(TARGET CompatibleInterface PROPERTY STRING_PROP3 prop3)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP1 50)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP2 250)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MAX_PROP1 50)
+set_property(TARGET CompatibleInterface PROPERTY NUMBER_MAX_PROP2 250)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop-stderr.txt
new file mode 100644
index 0000000000..1a925b602d
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" has property "INCLUDE_DIRECTORIES" listed in its
+ COMPATIBLE_INTERFACE_BOOL property. This is not allowed. Only
+ user-defined properties may appear listed in the COMPATIBLE_INTERFACE_BOOL
+ property.
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop.cmake
new file mode 100644
index 0000000000..5feb4d5cc2
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-builtin-prop.cmake
@@ -0,0 +1,11 @@
+
+add_library(foo UNKNOWN IMPORTED)
+add_library(bar UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL INCLUDE_DIRECTORIES)
+set_property(TARGET foo PROPERTY INTERFACE_INCLUDE_DIRECTORIES ON)
+set_property(TARGET bar PROPERTY INTERFACE_INCLUDE_DIRECTORIES ON)
+
+add_executable(user main.cpp)
+set_property(TARGET user PROPERTY INCLUDE_DIRECTORIES OFF)
+target_link_libraries(user foo bar)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self-stderr.txt
new file mode 100644
index 0000000000..0476da97d2
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error: Property SOMEPROP on target "user" does
+not match the INTERFACE_SOMEPROP property requirement
+of dependency "foo".
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self.cmake
new file mode 100644
index 0000000000..90543e8d3f
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depend-self.cmake
@@ -0,0 +1,11 @@
+
+add_library(foo UNKNOWN IMPORTED)
+add_library(bar UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SOMEPROP)
+set_property(TARGET foo PROPERTY INTERFACE_SOMEPROP ON)
+set_property(TARGET bar PROPERTY INTERFACE_SOMEPROP ON)
+
+add_executable(user main.cpp)
+set_property(TARGET user PROPERTY SOMEPROP OFF)
+target_link_libraries(user foo bar)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends-stderr.txt
new file mode 100644
index 0000000000..d885c09d95
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error: The INTERFACE_SOMEPROP property of "bar" does
+not agree with the value of SOMEPROP already determined
+for "user".
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends.cmake
new file mode 100644
index 0000000000..69be796327
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatch-depends.cmake
@@ -0,0 +1,10 @@
+
+add_library(foo UNKNOWN IMPORTED)
+add_library(bar UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SOMEPROP)
+set_property(TARGET foo PROPERTY INTERFACE_SOMEPROP ON)
+set_property(TARGET bar PROPERTY INTERFACE_SOMEPROP OFF)
+
+add_executable(user main.cpp)
+target_link_libraries(user foo bar)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use-stderr.txt
new file mode 100644
index 0000000000..8556ee0b66
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error: Property SOMEPROP on target "user" is
+implied to be FALSE because it was used to determine the link libraries
+already. The INTERFACE_SOMEPROP property on
+dependency "foo" is in conflict.
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use.cmake
new file mode 100644
index 0000000000..ccfad0ac74
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceBool-mismatched-use.cmake
@@ -0,0 +1,9 @@
+
+add_library(foo UNKNOWN IMPORTED)
+add_library(bar UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SOMEPROP)
+set_property(TARGET foo PROPERTY INTERFACE_SOMEPROP ON)
+
+add_executable(user main.cpp)
+target_link_libraries(user foo $<$<STREQUAL:$<TARGET_PROPERTY:SOMEPROP>,prop>:bar>)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use-stderr.txt
new file mode 100644
index 0000000000..723daec098
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error: Property SOMEPROP on target "user" is
+implied to be empty because it was used to determine the link libraries
+already. The INTERFACE_SOMEPROP property on
+dependency "foo" is in conflict.
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use.cmake
new file mode 100644
index 0000000000..a064d7683b
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceNumber-mismatched-use.cmake
@@ -0,0 +1,9 @@
+
+add_library(foo UNKNOWN IMPORTED)
+add_library(bar UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_NUMBER_MIN SOMEPROP)
+set_property(TARGET foo PROPERTY INTERFACE_SOMEPROP 42)
+
+add_executable(user main.cpp)
+target_link_libraries(user foo $<$<STREQUAL:$<TARGET_PROPERTY:SOMEPROP>,42>:bar>)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict-stderr.txt
new file mode 100644
index 0000000000..900e3f89e5
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error in CMakeLists.txt:
+ Property "SOMETHING" appears in both the COMPATIBLE_INTERFACE_BOOL and the
+ COMPATIBLE_INTERFACE_STRING property in the dependencies of target "user".
+ This is not allowed. A property may only require compatibility in a
+ boolean interpretation, a numeric minimum, a numeric maximum or a string
+ interpretation, but not a mixture.
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict.cmake
new file mode 100644
index 0000000000..4bae8042d7
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Conflict.cmake
@@ -0,0 +1,8 @@
+
+add_library(foo UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SOMETHING)
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_STRING SOMETHING)
+
+add_executable(user main.cpp)
+target_link_libraries(user foo)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict-stderr.txt
new file mode 100644
index 0000000000..2cfbae4766
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error in CMakeLists.txt:
+ Property "OTHER" appears in both the COMPATIBLE_INTERFACE_BOOL,
+ COMPATIBLE_INTERFACE_NUMBER_MIN and the COMPATIBLE_INTERFACE_STRING
+ property in the dependencies of target "user". This is not allowed. A
+ property may only require compatibility in a boolean interpretation, a
+ numeric minimum, a numeric maximum or a string interpretation, but not a
+ mixture.
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict.cmake
new file mode 100644
index 0000000000..164ffd9fc6
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-Bool-Min-Conflict.cmake
@@ -0,0 +1,9 @@
+
+add_library(foo UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL OTHER)
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_STRING OTHER)
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_NUMBER_MIN OTHER)
+
+add_executable(user main.cpp)
+target_link_libraries(user foo)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop-stderr.txt
new file mode 100644
index 0000000000..6a293b4f11
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" has property "INCLUDE_DIRECTORIES" listed in its
+ COMPATIBLE_INTERFACE_STRING property. This is not allowed. Only
+ user-defined properties may appear listed in the
+ COMPATIBLE_INTERFACE_STRING property.
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop.cmake
new file mode 100644
index 0000000000..5772856cc6
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-builtin-prop.cmake
@@ -0,0 +1,9 @@
+
+add_library(foo UNKNOWN IMPORTED)
+add_library(bar UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_STRING INCLUDE_DIRECTORIES)
+
+add_executable(user main.cpp)
+set_property(TARGET user PROPERTY INCLUDE_DIRECTORIES bar_inc)
+target_link_libraries(user foo bar)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self-stderr.txt
new file mode 100644
index 0000000000..0476da97d2
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error: Property SOMEPROP on target "user" does
+not match the INTERFACE_SOMEPROP property requirement
+of dependency "foo".
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self.cmake
new file mode 100644
index 0000000000..187f29f796
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depend-self.cmake
@@ -0,0 +1,11 @@
+
+add_library(foo UNKNOWN IMPORTED)
+add_library(bar UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_STRING SOMEPROP)
+set_property(TARGET foo PROPERTY INTERFACE_SOMEPROP prop)
+set_property(TARGET bar PROPERTY INTERFACE_SOMEPROP prop)
+
+add_executable(user main.cpp)
+set_property(TARGET user PROPERTY SOMEPROP different)
+target_link_libraries(user foo bar)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends-stderr.txt
new file mode 100644
index 0000000000..d885c09d95
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error: The INTERFACE_SOMEPROP property of "bar" does
+not agree with the value of SOMEPROP already determined
+for "user".
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends.cmake
new file mode 100644
index 0000000000..73cc3fc55b
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatch-depends.cmake
@@ -0,0 +1,10 @@
+
+add_library(foo UNKNOWN IMPORTED)
+add_library(bar UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_STRING SOMEPROP)
+set_property(TARGET foo PROPERTY INTERFACE_SOMEPROP foo)
+set_property(TARGET bar PROPERTY INTERFACE_SOMEPROP bar)
+
+add_executable(user main.cpp)
+target_link_libraries(user foo bar)
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use-result.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use-stderr.txt b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use-stderr.txt
new file mode 100644
index 0000000000..723daec098
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error: Property SOMEPROP on target "user" is
+implied to be empty because it was used to determine the link libraries
+already. The INTERFACE_SOMEPROP property on
+dependency "foo" is in conflict.
diff --git a/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use.cmake b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use.cmake
new file mode 100644
index 0000000000..af3ce8fbc8
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/InterfaceString-mismatched-use.cmake
@@ -0,0 +1,9 @@
+
+add_library(foo UNKNOWN IMPORTED)
+add_library(bar UNKNOWN IMPORTED)
+
+set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_STRING SOMEPROP)
+set_property(TARGET foo PROPERTY INTERFACE_SOMEPROP prop)
+
+add_executable(user main.cpp)
+target_link_libraries(user foo $<$<STREQUAL:$<TARGET_PROPERTY:SOMEPROP>,prop>:bar>)
diff --git a/Tests/RunCMake/CompatibleInterface/RunCMakeTest.cmake b/Tests/RunCMake/CompatibleInterface/RunCMakeTest.cmake
new file mode 100644
index 0000000000..0b9729bf29
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/RunCMakeTest.cmake
@@ -0,0 +1,19 @@
+include(RunCMake)
+
+run_cmake(InterfaceBool-mismatch-depends)
+run_cmake(InterfaceBool-mismatch-depend-self)
+run_cmake(InterfaceBool-mismatched-use)
+run_cmake(InterfaceBool-builtin-prop)
+run_cmake(InterfaceString-mismatch-depends)
+run_cmake(InterfaceString-mismatch-depend-self)
+run_cmake(InterfaceString-mismatched-use)
+run_cmake(InterfaceNumber-mismatched-use)
+run_cmake(InterfaceString-builtin-prop)
+run_cmake(InterfaceString-Bool-Conflict)
+run_cmake(InterfaceString-Bool-Min-Conflict)
+run_cmake(DebugProperties)
+
+if (QT_QMAKE_EXECUTABLE})
+ set(RunCMake_TEST_OPTIONS -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE})
+ run_cmake(AutoUic)
+endif()
diff --git a/Tests/RunCMake/CompatibleInterface/empty.cpp b/Tests/RunCMake/CompatibleInterface/empty.cpp
new file mode 100644
index 0000000000..00323299cb
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/empty.cpp
@@ -0,0 +1 @@
+// no content
diff --git a/Tests/RunCMake/CompatibleInterface/main.cpp b/Tests/RunCMake/CompatibleInterface/main.cpp
new file mode 100644
index 0000000000..65eddcf847
--- /dev/null
+++ b/Tests/RunCMake/CompatibleInterface/main.cpp
@@ -0,0 +1,5 @@
+
+int main(int argc, char **argv)
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CompileFeatures/CMakeLists.txt b/Tests/RunCMake/CompileFeatures/CMakeLists.txt
new file mode 100644
index 0000000000..3482e6baf2
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-result.txt b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-stderr.txt b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-stderr.txt
new file mode 100644
index 0000000000..a584d7d8e5
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error in CMakeLists.txt:
+ The COMPILE_FEATURES property of target "empty1" was evaluated when
+ computing the link implementation, and the "CXX_STANDARD" was "98" for that
+ computation. Computing the COMPILE_FEATURES based on the link
+ implementation resulted in a higher "CXX_STANDARD" "11". This is not
+ permitted. The COMPILE_FEATURES may not both depend on and be depended on
+ by the link implementation.
diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake
new file mode 100644
index 0000000000..9d56bc0982
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake
@@ -0,0 +1,15 @@
+
+add_library(empty1 empty.cpp)
+
+add_library(empty2 INTERFACE)
+add_library(empty3 INTERFACE)
+target_compile_features(empty3 INTERFACE cxx_constexpr)
+
+target_link_libraries(empty1
+ # When starting, $<COMPILE_FEATURES:cxx_final> is '0', so 'freeze' the
+ # CXX_STANDARD at 98 during computation.
+ $<$<COMPILE_FEATURES:cxx_final>:empty2>
+ # This would add cxx_constexpr, but that would require CXX_STANDARD = 11,
+ # which is not allowed after freeze. Report an error.
+ empty3
+)
diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-result.txt b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-stderr.txt b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved.cmake b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved.cmake
new file mode 100644
index 0000000000..0df548b7ef
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved.cmake
@@ -0,0 +1,14 @@
+
+add_library(empty1 empty.cpp)
+
+add_library(empty2 INTERFACE)
+add_library(empty3 INTERFACE)
+target_compile_features(empty3 INTERFACE cxx_constexpr)
+
+target_link_libraries(empty1
+ $<$<COMPILE_FEATURES:cxx_final>:empty2>
+ empty3
+)
+# This, or populating the COMPILE_FEATURES property with a feature in the
+# same standard as cxx_final, solves the cycle above.
+set_property(TARGET empty1 PROPERTY CXX_STANDARD 11)
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCFeatures-result.txt b/Tests/RunCMake/CompileFeatures/NoSupportedCFeatures-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCFeatures-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCFeatures-stderr.txt b/Tests/RunCMake/CompileFeatures/NoSupportedCFeatures-stderr.txt
new file mode 100644
index 0000000000..fd18c885bb
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCFeatures-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at NoSupportedCFeatures.cmake:[0-9]+ \(target_compile_features\):
+ target_compile_features no known features for C compiler
+
+ "[^"]*"
+
+ version *[.0-9]+\.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCFeatures.cmake b/Tests/RunCMake/CompileFeatures/NoSupportedCFeatures.cmake
new file mode 100644
index 0000000000..3624d4b9fd
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCFeatures.cmake
@@ -0,0 +1,5 @@
+
+enable_language(C)
+
+add_library(no_features empty.c)
+target_compile_features(no_features PRIVATE c_static_assert)
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex-result.txt b/Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex-stderr.txt b/Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex-stderr.txt
new file mode 100644
index 0000000000..df647e8b3d
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error in CMakeLists.txt:
+ No known features for C compiler
+
+ "[^"]*"
+
+ version *[.0-9]+\.
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex.cmake b/Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex.cmake
new file mode 100644
index 0000000000..b6053aaf1a
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCFeaturesGenex.cmake
@@ -0,0 +1,5 @@
+
+enable_language(C)
+
+add_library(no_features empty.c)
+target_compile_features(no_features PRIVATE $<1:c_static_assert>)
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures-result.txt b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures-stderr.txt b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures-stderr.txt
new file mode 100644
index 0000000000..fc882cb1e2
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at NoSupportedCxxFeatures.cmake:3 \(target_compile_features\):
+ target_compile_features no known features for CXX compiler
+
+ "[^"]*"
+
+ version *[.0-9]+\.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures.cmake b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures.cmake
new file mode 100644
index 0000000000..512194879c
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeatures.cmake
@@ -0,0 +1,3 @@
+
+add_library(no_features empty.cpp)
+target_compile_features(no_features PRIVATE cxx_constexpr)
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex-result.txt b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex-stderr.txt b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex-stderr.txt
new file mode 100644
index 0000000000..66d0d4148c
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error in CMakeLists.txt:
+ No known features for CXX compiler
+
+ "[^"]*"
+
+ version *[.0-9]+\.
diff --git a/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex.cmake b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex.cmake
new file mode 100644
index 0000000000..490f187f57
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NoSupportedCxxFeaturesGenex.cmake
@@ -0,0 +1,3 @@
+
+add_library(no_features empty.cpp)
+target_compile_features(no_features PRIVATE $<1:cxx_constexpr>)
diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget1-result.txt b/Tests/RunCMake/CompileFeatures/NonValidTarget1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NonValidTarget1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget1-stderr.txt b/Tests/RunCMake/CompileFeatures/NonValidTarget1-stderr.txt
new file mode 100644
index 0000000000..7f3b43b339
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NonValidTarget1-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at NonValidTarget1.cmake:[0-9]+ \(add_custom_command\):
+ Error evaluating generator expression:
+
+ \$<COMPILE_FEATURES:cxx_final>
+
+ \$<COMPILE_FEATURE> may only be used with binary targets. It may not be
+ used with add_custom_command or add_custom_target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget1.cmake b/Tests/RunCMake/CompileFeatures/NonValidTarget1.cmake
new file mode 100644
index 0000000000..c6707c1b5a
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NonValidTarget1.cmake
@@ -0,0 +1,17 @@
+
+set(genexvar $<COMPILE_FEATURES:cxx_final>)
+
+if (HAVE_FINAL)
+ set(expected_result 1)
+else()
+ set(expected_result 0)
+endif()
+
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file${HAVE_FINAL}.cpp"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file${genexvar}.cpp"
+)
+
+add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file${genexvar}.cpp")
+if (HAVE_FINAL)
+ target_compile_features(empty PRIVATE cxx_final)
+endif()
diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget2-result.txt b/Tests/RunCMake/CompileFeatures/NonValidTarget2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NonValidTarget2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget2-stderr.txt b/Tests/RunCMake/CompileFeatures/NonValidTarget2-stderr.txt
new file mode 100644
index 0000000000..635150c254
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NonValidTarget2-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at NonValidTarget2.cmake:4 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<COMPILE_FEATURES:cxx_final>
+
+ \$<COMPILE_FEATURE> may only be used with binary targets. It may not be
+ used with add_custom_command or add_custom_target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget2.cmake b/Tests/RunCMake/CompileFeatures/NonValidTarget2.cmake
new file mode 100644
index 0000000000..eb84692cb9
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NonValidTarget2.cmake
@@ -0,0 +1,8 @@
+
+set(genexvar $<COMPILE_FEATURES:cxx_final>)
+
+add_custom_target(copy_target
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file${genexvar}.txt"
+)
+
+add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file${genexvar}.cpp")
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature-result.txt b/Tests/RunCMake/CompileFeatures/NotAFeature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAFeature-stderr.txt
new file mode 100644
index 0000000000..ff60e50a59
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error in CMakeLists.txt:
+ Specified unknown feature "not_a_feature" for target "somelib".
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature.cmake b/Tests/RunCMake/CompileFeatures/NotAFeature.cmake
new file mode 100644
index 0000000000..35246c8bdc
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature.cmake
@@ -0,0 +1,3 @@
+
+add_library(somelib STATIC empty.cpp)
+set_property(TARGET somelib PROPERTY COMPILE_FEATURES "not_a_feature")
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-result.txt b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt
new file mode 100644
index 0000000000..ff60e50a59
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error in CMakeLists.txt:
+ Specified unknown feature "not_a_feature" for target "somelib".
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake
new file mode 100644
index 0000000000..ad2bd371d1
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake
@@ -0,0 +1,3 @@
+
+add_library(somelib STATIC empty.cpp)
+set_property(TARGET somelib PROPERTY COMPILE_FEATURES "$<1:not_a_feature>")
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeatureTransitive-result.txt b/Tests/RunCMake/CompileFeatures/NotAFeatureTransitive-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeatureTransitive-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeatureTransitive-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAFeatureTransitive-stderr.txt
new file mode 100644
index 0000000000..ff60e50a59
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeatureTransitive-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error in CMakeLists.txt:
+ Specified unknown feature "not_a_feature" for target "somelib".
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeatureTransitive.cmake b/Tests/RunCMake/CompileFeatures/NotAFeatureTransitive.cmake
new file mode 100644
index 0000000000..7311aecd8e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeatureTransitive.cmake
@@ -0,0 +1,6 @@
+
+add_library(iface INTERFACE)
+set_property(TARGET iface PROPERTY INTERFACE_COMPILE_FEATURES "not_a_feature")
+
+add_library(somelib STATIC empty.cpp)
+target_link_libraries(somelib iface)
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug-result.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug-stderr.txt
new file mode 100644
index 0000000000..60a8e51cea
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug-stderr.txt
@@ -0,0 +1,11 @@
+CMake Debug Log at NotAFeature_OriginDebug.cmake:4 \(set_property\):
+ Used compile features for target somelib:
+
+ \* not_a_feature
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Error in CMakeLists.txt:
+ Specified unknown feature "not_a_feature" for target "somelib".
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug.cmake b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug.cmake
new file mode 100644
index 0000000000..350c2eaa9a
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug.cmake
@@ -0,0 +1,4 @@
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES COMPILE_FEATURES)
+add_library(somelib STATIC empty.cpp)
+set_property(TARGET somelib PROPERTY COMPILE_FEATURES "not_a_feature")
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex-result.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex-stderr.txt
new file mode 100644
index 0000000000..08e20a856e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex-stderr.txt
@@ -0,0 +1,11 @@
+CMake Debug Log at NotAFeature_OriginDebugGenex.cmake:4 \(set_property\):
+ Used compile features for target somelib:
+
+ \* not_a_feature
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Error in CMakeLists.txt:
+ Specified unknown feature "not_a_feature" for target "somelib".
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex.cmake b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex.cmake
new file mode 100644
index 0000000000..2122981bf8
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugGenex.cmake
@@ -0,0 +1,4 @@
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES COMPILE_FEATURES)
+add_library(somelib STATIC empty.cpp)
+set_property(TARGET somelib PROPERTY COMPILE_FEATURES "$<1:not_a_feature>")
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive-result.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive-stderr.txt
new file mode 100644
index 0000000000..23c3305a78
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive-stderr.txt
@@ -0,0 +1,11 @@
+CMake Debug Log at NotAFeature_OriginDebugTransitive.cmake:6 \(target_link_libraries\):
+ Used compile features for target somelib:
+
+ \* not_a_feature
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Error in CMakeLists.txt:
+ Specified unknown feature "not_a_feature" for target "somelib".
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive.cmake b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive.cmake
new file mode 100644
index 0000000000..05d00736df
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebugTransitive.cmake
@@ -0,0 +1,6 @@
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES COMPILE_FEATURES)
+add_library(iface INTERFACE)
+set_property(TARGET iface PROPERTY INTERFACE_COMPILE_FEATURES "not_a_feature")
+add_library(somelib STATIC empty.cpp)
+target_link_libraries(somelib iface)
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-result.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-stderr.txt
new file mode 100644
index 0000000000..d819d150d7
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at NotAFeature_OriginDebug_target_compile_features.cmake:4 \(target_compile_features\):
+ target_compile_features specified unknown feature "not_a_feature" for
+ target "somelib".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features.cmake b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features.cmake
new file mode 100644
index 0000000000..467d9a17e4
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features.cmake
@@ -0,0 +1,4 @@
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES COMPILE_FEATURES)
+add_library(somelib STATIC empty.cpp)
+target_compile_features(somelib PRIVATE not_a_feature)
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11-stderr.txt
new file mode 100644
index 0000000000..0fc9112f8b
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" requires the language dialect "CXX11" , but CMake does not
+ know the compile flags to use to enable it.
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX11.cmake
new file mode 100644
index 0000000000..f60504f93f
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11.cmake
@@ -0,0 +1,5 @@
+
+add_library(foo empty.cpp)
+set_property(TARGET foo PROPERTY CXX_STANDARD 11)
+set_property(TARGET foo PROPERTY CXX_EXTENSIONS FALSE)
+set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED TRUE)
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-stderr.txt
new file mode 100644
index 0000000000..5c68a1cf78
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" requires the language dialect "CXX11" \(with compiler
+ extensions\), but CMake does not know the compile flags to use to enable it.
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Ext.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext.cmake
new file mode 100644
index 0000000000..10b251aa43
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext.cmake
@@ -0,0 +1,4 @@
+
+add_library(foo empty.cpp)
+set_property(TARGET foo PROPERTY CXX_STANDARD 11)
+set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED TRUE)
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-stderr.txt
new file mode 100644
index 0000000000..5c68a1cf78
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" requires the language dialect "CXX11" \(with compiler
+ extensions\), but CMake does not know the compile flags to use to enable it.
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable.cmake
new file mode 100644
index 0000000000..29703db68a
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable.cmake
@@ -0,0 +1,4 @@
+
+set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
+add_library(foo empty.cpp)
+set_property(TARGET foo PROPERTY CXX_STANDARD 11)
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-stderr.txt
new file mode 100644
index 0000000000..0fc9112f8b
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" requires the language dialect "CXX11" , but CMake does not
+ know the compile flags to use to enable it.
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Variable.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable.cmake
new file mode 100644
index 0000000000..c480997d48
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable.cmake
@@ -0,0 +1,5 @@
+
+set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
+add_library(foo empty.cpp)
+set_property(TARGET foo PROPERTY CXX_STANDARD 11)
+set_property(TARGET foo PROPERTY CXX_EXTENSIONS FALSE)
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98-stderr.txt
new file mode 100644
index 0000000000..47c86889fe
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" requires the language dialect "CXX98" , but CMake does not
+ know the compile flags to use to enable it.
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX98.cmake
new file mode 100644
index 0000000000..fd9fb60052
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98.cmake
@@ -0,0 +1,5 @@
+
+add_library(foo empty.cpp)
+set_property(TARGET foo PROPERTY CXX_STANDARD 98)
+set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED TRUE)
+set_property(TARGET foo PROPERTY CXX_EXTENSIONS FALSE)
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-stderr.txt
new file mode 100644
index 0000000000..b4fdf8a455
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" requires the language dialect "CXX98" \(with compiler
+ extensions\), but CMake does not know the compile flags to use to enable it.
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Ext.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext.cmake
new file mode 100644
index 0000000000..4ea595edb3
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext.cmake
@@ -0,0 +1,4 @@
+
+add_library(foo empty.cpp)
+set_property(TARGET foo PROPERTY CXX_STANDARD 98)
+set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED TRUE)
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-stderr.txt
new file mode 100644
index 0000000000..b4fdf8a455
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" requires the language dialect "CXX98" \(with compiler
+ extensions\), but CMake does not know the compile flags to use to enable it.
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable.cmake
new file mode 100644
index 0000000000..0e3ef8dfb9
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable.cmake
@@ -0,0 +1,4 @@
+
+set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
+add_library(foo empty.cpp)
+set_property(TARGET foo PROPERTY CXX_STANDARD 98)
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-stderr.txt
new file mode 100644
index 0000000000..47c86889fe
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" requires the language dialect "CXX98" , but CMake does not
+ know the compile flags to use to enable it.
diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Variable.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable.cmake
new file mode 100644
index 0000000000..75622645b8
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable.cmake
@@ -0,0 +1,5 @@
+
+set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
+add_library(foo empty.cpp)
+set_property(TARGET foo PROPERTY CXX_STANDARD 98)
+set_property(TARGET foo PROPERTY CXX_EXTENSIONS FALSE)
diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake
new file mode 100644
index 0000000000..1892a5cf48
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake
@@ -0,0 +1,54 @@
+include(RunCMake)
+
+run_cmake(NotAFeature)
+run_cmake(NotAFeatureGenex)
+run_cmake(NotAFeatureTransitive)
+run_cmake(NotAFeature_OriginDebug)
+run_cmake(NotAFeature_OriginDebugGenex)
+run_cmake(NotAFeature_OriginDebugTransitive)
+run_cmake(NotAFeature_OriginDebug_target_compile_features)
+
+run_cmake(generate_feature_list)
+file(READ
+ "${RunCMake_BINARY_DIR}/generate_feature_list-build/c_features.txt"
+ C_FEATURES
+)
+file(READ
+ "${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx_features.txt"
+ CXX_FEATURES
+)
+
+if (NOT C_FEATURES)
+ run_cmake(NoSupportedCFeatures)
+ run_cmake(NoSupportedCFeaturesGenex)
+endif()
+
+if (NOT CXX_FEATURES)
+ run_cmake(NoSupportedCxxFeatures)
+ run_cmake(NoSupportedCxxFeaturesGenex)
+else()
+ run_cmake(LinkImplementationFeatureCycle)
+ run_cmake(LinkImplementationFeatureCycleSolved)
+
+ if (";${CXX_FEATURES};" MATCHES ";cxx_final;")
+ set(RunCMake_TEST_OPTIONS "-DHAVE_FINAL=1")
+ endif()
+ run_cmake(NonValidTarget1)
+ run_cmake(NonValidTarget2)
+ unset(RunCMake_TEST_OPTIONS)
+endif()
+
+foreach(standard 98 11)
+ file(READ
+ "${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx${standard}_flag.txt"
+ CXX${standard}_FLAG
+ )
+ if (CXX${standard}_FLAG STREQUAL NOTFOUND)
+ run_cmake(RequireCXX${standard})
+ run_cmake(RequireCXX${standard}Variable)
+ endif()
+ if (CXX${standard}EXT_FLAG STREQUAL NOTFOUND)
+ run_cmake(RequireCXX${standard}Ext)
+ run_cmake(RequireCXX${standard}ExtVariable)
+ endif()
+endforeach()
diff --git a/Tests/RunCMake/CompileFeatures/empty.c b/Tests/RunCMake/CompileFeatures/empty.c
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/empty.c
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CompileFeatures/empty.cpp b/Tests/RunCMake/CompileFeatures/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake b/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake
new file mode 100644
index 0000000000..09e17b114d
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake
@@ -0,0 +1,29 @@
+
+enable_language(C)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/c_features.txt"
+ "${CMAKE_C_COMPILE_FEATURES}"
+)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx_features.txt"
+ "${CMAKE_CXX_COMPILE_FEATURES}"
+)
+
+foreach(standard 98 11)
+ set(CXX${standard}_FLAG NOTFOUND)
+ if (DEFINED CMAKE_CXX${standard}_STANDARD_COMPILE_OPTION)
+ set(CXX${standard}_FLAG ${CMAKE_CXX${standard}_STANDARD_COMPILE_OPTION})
+ endif()
+
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx${standard}_flag.txt"
+ "${CXX${standard}_FLAG}"
+ )
+ set(CXX${standard}EXT_FLAG NOTFOUND)
+ if (DEFINED CMAKE_CXX${standard}_EXTENSION_COMPILE_OPTION)
+ set(CXX${standard}EXT_FLAG ${CMAKE_CXX${standard}_EXTENSION_COMPILE_OPTION})
+ endif()
+
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx${standard}ext_flag.txt"
+ "${CXX${standard}EXT_FLAG}"
+ )
+endforeach()
diff --git a/Tests/RunCMake/CompilerChange/CMakeLists.txt b/Tests/RunCMake/CompilerChange/CMakeLists.txt
new file mode 100644
index 0000000000..b4b30165f0
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.8.4)
+if(NOT RunCMake_TEST)
+ set(RunCMake_TEST "$ENV{RunCMake_TEST}") # needed when cache is deleted
+endif()
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CompilerChange/EmptyCompiler-override.cmake b/Tests/RunCMake/CompilerChange/EmptyCompiler-override.cmake
new file mode 100644
index 0000000000..28d29e03ee
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/EmptyCompiler-override.cmake
@@ -0,0 +1,2 @@
+message(STATUS "CMAKE_C_COMPILER is \"${CMAKE_C_COMPILER}\"")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cc.cmake" "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n")
diff --git a/Tests/RunCMake/CompilerChange/EmptyCompiler-result.txt b/Tests/RunCMake/CompilerChange/EmptyCompiler-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/EmptyCompiler-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompilerChange/EmptyCompiler-stderr.txt b/Tests/RunCMake/CompilerChange/EmptyCompiler-stderr.txt
new file mode 100644
index 0000000000..cf3b1b346a
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/EmptyCompiler-stderr.txt
@@ -0,0 +1,13 @@
+You have changed variables that require your cache to be deleted.
+Configure will be re-run and you may have to reset some variables.
+The following variables have changed:
+CMAKE_C_COMPILER= *
++
+CMake Error at EmptyCompiler.cmake:2 \(enable_language\):
+ No CMAKE_C_COMPILER could be found.
+
+ Tell CMake where to find the compiler by setting either the environment
+ variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
+ the compiler, or to the compiler name if it is in the PATH.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:6 \(include\)$
diff --git a/Tests/RunCMake/CompilerChange/EmptyCompiler.cmake b/Tests/RunCMake/CompilerChange/EmptyCompiler.cmake
new file mode 100644
index 0000000000..06e9e033bf
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/EmptyCompiler.cmake
@@ -0,0 +1,2 @@
+set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_LIST_DIR}/EmptyCompiler-override.cmake)
+enable_language(C)
diff --git a/Tests/RunCMake/CompilerChange/FindCompiler.cmake b/Tests/RunCMake/CompilerChange/FindCompiler.cmake
new file mode 100644
index 0000000000..297ab2fa50
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/FindCompiler.cmake
@@ -0,0 +1,2 @@
+enable_language(C)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cc.cmake" "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n")
diff --git a/Tests/RunCMake/CompilerChange/FirstCompiler-stdout.txt b/Tests/RunCMake/CompilerChange/FirstCompiler-stdout.txt
new file mode 100644
index 0000000000..17621b7e5c
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/FirstCompiler-stdout.txt
@@ -0,0 +1 @@
+-- CMAKE_C_COMPILER is ".*/Tests/RunCMake/CompilerChange/cc1.sh"
diff --git a/Tests/RunCMake/CompilerChange/FirstCompiler.cmake b/Tests/RunCMake/CompilerChange/FirstCompiler.cmake
new file mode 100644
index 0000000000..c87ec49522
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/FirstCompiler.cmake
@@ -0,0 +1,3 @@
+enable_language(C)
+message(STATUS "CMAKE_C_COMPILER is \"${CMAKE_C_COMPILER}\"")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cc.cmake" "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n")
diff --git a/Tests/RunCMake/CompilerChange/RunCMakeTest.cmake b/Tests/RunCMake/CompilerChange/RunCMakeTest.cmake
new file mode 100644
index 0000000000..5bb2821d9f
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/RunCMakeTest.cmake
@@ -0,0 +1,58 @@
+include(RunCMake)
+
+# Detect the compiler in use in the current environment.
+run_cmake(FindCompiler)
+include(${RunCMake_BINARY_DIR}/FindCompiler-build/cc.cmake)
+if(NOT CMAKE_C_COMPILER)
+ message(FATAL_ERROR "FindCompiler provided no compiler!")
+endif()
+if(NOT IS_ABSOLUTE "${CMAKE_C_COMPILER}")
+ message(FATAL_ERROR "FindCompiler provided non-absolute path \"${CMAKE_C_COMPILER}\"!")
+endif()
+if(NOT EXISTS "${CMAKE_C_COMPILER}")
+ message(FATAL_ERROR "FindCompiler provided non-existing path \"${CMAKE_C_COMPILER}\"!")
+endif()
+
+# Now that we have the full compiler path, hide CC.
+unset(ENV{CC})
+
+# Wrap around the real compiler so we can change the compiler
+# path without changing the underlying compiler.
+set(ccIn ${RunCMake_SOURCE_DIR}/cc.sh.in)
+set(cc1 ${RunCMake_BINARY_DIR}/cc1.sh)
+set(cc2 ${RunCMake_BINARY_DIR}/cc2.sh)
+set(cc3 CMAKE_C_COMPILER-NOTFOUND)
+configure_file(${ccIn} ${cc1} @ONLY)
+configure_file(${ccIn} ${cc2} @ONLY)
+
+# Use a single build tree for remaining tests without cleaning.
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ChangeCompiler-build)
+set(RunCMake_TEST_NO_CLEAN 1)
+file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+
+# Check build with compiler wrapper 1.
+set(RunCMake_TEST_OPTIONS -DCMAKE_C_COMPILER=${cc1})
+set(ENV{RunCMake_TEST} "FirstCompiler")
+run_cmake(FirstCompiler)
+include(${RunCMake_TEST_BINARY_DIR}/cc.cmake)
+if(NOT "${CMAKE_C_COMPILER}" STREQUAL "${cc1}")
+ message(FATAL_ERROR "FirstCompiler built with compiler:\n ${CMAKE_C_COMPILER}\nand not with:\n ${cc1}")
+endif()
+
+# Check rebuild with compiler wrapper 2.
+set(RunCMake_TEST_OPTIONS -DCMAKE_C_COMPILER=${cc2})
+set(ENV{RunCMake_TEST} "SecondCompiler")
+run_cmake(SecondCompiler)
+include(${RunCMake_TEST_BINARY_DIR}/cc.cmake)
+if(NOT "${CMAKE_C_COMPILER}" STREQUAL "${cc2}")
+ message(FATAL_ERROR "SecondCompiler built with compiler:\n ${CMAKE_C_COMPILER}\nand not with:\n ${cc2}")
+endif()
+
+# Check failure with an empty compiler string.
+set(RunCMake_TEST_OPTIONS -DCMAKE_C_COMPILER=)
+set(ENV{RunCMake_TEST} "EmptyCompiler")
+run_cmake(EmptyCompiler)
+include(${RunCMake_TEST_BINARY_DIR}/cc.cmake)
+if(NOT "${CMAKE_C_COMPILER}" STREQUAL "${cc3}")
+ message(FATAL_ERROR "Empty built with compiler:\n ${CMAKE_C_COMPILER}\nand not with:\n ${cc3}")
+endif()
diff --git a/Tests/RunCMake/CompilerChange/SecondCompiler-stderr.txt b/Tests/RunCMake/CompilerChange/SecondCompiler-stderr.txt
new file mode 100644
index 0000000000..3a01c53f1f
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/SecondCompiler-stderr.txt
@@ -0,0 +1,4 @@
+You have changed variables that require your cache to be deleted.
+Configure will be re-run and you may have to reset some variables.
+The following variables have changed:
+CMAKE_C_COMPILER=.*/Tests/RunCMake/CompilerChange/cc2.sh
diff --git a/Tests/RunCMake/CompilerChange/SecondCompiler-stdout.txt b/Tests/RunCMake/CompilerChange/SecondCompiler-stdout.txt
new file mode 100644
index 0000000000..26ca964386
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/SecondCompiler-stdout.txt
@@ -0,0 +1 @@
+-- CMAKE_C_COMPILER is ".*/Tests/RunCMake/CompilerChange/cc2.sh"
diff --git a/Tests/RunCMake/CompilerChange/SecondCompiler.cmake b/Tests/RunCMake/CompilerChange/SecondCompiler.cmake
new file mode 100644
index 0000000000..c87ec49522
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/SecondCompiler.cmake
@@ -0,0 +1,3 @@
+enable_language(C)
+message(STATUS "CMAKE_C_COMPILER is \"${CMAKE_C_COMPILER}\"")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cc.cmake" "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n")
diff --git a/Tests/RunCMake/CompilerChange/cc.sh.in b/Tests/RunCMake/CompilerChange/cc.sh.in
new file mode 100755
index 0000000000..1d400e6baf
--- /dev/null
+++ b/Tests/RunCMake/CompilerChange/cc.sh.in
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec "@CMAKE_C_COMPILER@" "$@"
diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerC-result.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerC-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/BadCompilerC-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr.txt
new file mode 100644
index 0000000000..c98842d976
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/BadCompilerC-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at BadCompilerC.cmake:2 \(enable_language\):
+ The CMAKE_C_COMPILER:
+
+ no-C-compiler
+
+ is not a full path and was not found in the PATH.
+
+ Tell CMake where to find the compiler by setting either the environment
+ variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
+ the compiler, or to the compiler name if it is in the PATH.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerC.cmake b/Tests/RunCMake/CompilerNotFound/BadCompilerC.cmake
new file mode 100644
index 0000000000..10fe59aaba
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/BadCompilerC.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_C_COMPILER "no-C-compiler")
+enable_language(C)
+message(FATAL_ERROR "This error should not be reached.")
diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-result.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr.txt
new file mode 100644
index 0000000000..7ef4f5e7c9
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at BadCompilerCXX.cmake:2 \(enable_language\):
+ The CMAKE_CXX_COMPILER:
+
+ no-CXX-compiler
+
+ is not a full path and was not found in the PATH.
+
+ Tell CMake where to find the compiler by setting either the environment
+ variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
+ to the compiler, or to the compiler name if it is in the PATH.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCXX.cmake b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX.cmake
new file mode 100644
index 0000000000..3b1e8900a8
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCXX.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_CXX_COMPILER "no-CXX-compiler")
+enable_language(CXX)
+message(FATAL_ERROR "This error should not be reached.")
diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-result.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr.txt b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr.txt
new file mode 100644
index 0000000000..eecff54fd6
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX-stderr.txt
@@ -0,0 +1,25 @@
+CMake Error at BadCompilerCandCXX.cmake:3 \(project\):
+ The CMAKE_C_COMPILER:
+
+ no-C-compiler
+
+ is not a full path and was not found in the PATH.
+
+ Tell CMake where to find the compiler by setting either the environment
+ variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
+ the compiler, or to the compiler name if it is in the PATH.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadCompilerCandCXX.cmake:3 \(project\):
+ The CMAKE_CXX_COMPILER:
+
+ no-CXX-compiler
+
+ is not a full path and was not found in the PATH.
+
+ Tell CMake where to find the compiler by setting either the environment
+ variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
+ to the compiler, or to the compiler name if it is in the PATH.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX.cmake b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX.cmake
new file mode 100644
index 0000000000..2b6fa6126d
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/BadCompilerCandCXX.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_C_COMPILER "no-C-compiler")
+set(CMAKE_CXX_COMPILER "no-CXX-compiler")
+project(BadCompilerCandCXXInner C CXX)
+message(FATAL_ERROR "This error should not be reached.")
diff --git a/Tests/RunCMake/CompilerNotFound/CMakeLists.txt b/Tests/RunCMake/CompilerNotFound/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE-result.txt b/Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE-stderr.txt b/Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE-stderr.txt
new file mode 100644
index 0000000000..88bb95e49f
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at NoCompilerC-IDE.cmake:2 \(enable_language\):
+ No CMAKE_C_COMPILER could be found.
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE.cmake b/Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE.cmake
new file mode 100644
index 0000000000..45e1a68c4d
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/NoCompilerC-IDE.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_C_COMPILER_ID_ERROR_FOR_TEST "#error NoCompilerC-IDE")
+enable_language(C)
+message(FATAL_ERROR "This error should not be reached.")
diff --git a/Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE-result.txt b/Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE-stderr.txt b/Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE-stderr.txt
new file mode 100644
index 0000000000..4c92323e26
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at NoCompilerCXX-IDE.cmake:2 \(enable_language\):
+ No CMAKE_CXX_COMPILER could be found.
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE.cmake b/Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE.cmake
new file mode 100644
index 0000000000..85025a06b1
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/NoCompilerCXX-IDE.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_CXX_COMPILER_ID_ERROR_FOR_TEST "#error NoCompilerCXX-IDE")
+enable_language(CXX)
+message(FATAL_ERROR "This error should not be reached.")
diff --git a/Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE-result.txt b/Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE-stderr.txt b/Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE-stderr.txt
new file mode 100644
index 0000000000..21c69f5791
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE-stderr.txt
@@ -0,0 +1,11 @@
+CMake Error at NoCompilerCandCXX-IDE.cmake:3 \(project\):
+ No CMAKE_C_COMPILER could be found.
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at NoCompilerCandCXX-IDE.cmake:3 \(project\):
+ No CMAKE_CXX_COMPILER could be found.
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE.cmake b/Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE.cmake
new file mode 100644
index 0000000000..78256a9638
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/NoCompilerCandCXX-IDE.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_C_COMPILER_ID_ERROR_FOR_TEST "#error NoCompilerCandCXX-IDE")
+set(CMAKE_CXX_COMPILER_ID_ERROR_FOR_TEST "#error NoCompilerCandCXX-IDE")
+project(NoCompilerCandCXXInner C CXX)
+message(FATAL_ERROR "This error should not be reached.")
diff --git a/Tests/RunCMake/CompilerNotFound/RunCMakeTest.cmake b/Tests/RunCMake/CompilerNotFound/RunCMakeTest.cmake
new file mode 100644
index 0000000000..8b84f39dd0
--- /dev/null
+++ b/Tests/RunCMake/CompilerNotFound/RunCMakeTest.cmake
@@ -0,0 +1,11 @@
+include(RunCMake)
+
+if("${RunCMake_GENERATOR}" MATCHES "Visual Studio|Xcode")
+ run_cmake(NoCompilerC-IDE)
+ run_cmake(NoCompilerCXX-IDE)
+ run_cmake(NoCompilerCandCXX-IDE)
+else()
+ run_cmake(BadCompilerC)
+ run_cmake(BadCompilerCXX)
+ run_cmake(BadCompilerCandCXX)
+endif()
diff --git a/Tests/RunCMake/Configure/CMakeLists.txt b/Tests/RunCMake/Configure/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/Configure/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/Configure/CustomTargetAfterError-result.txt b/Tests/RunCMake/Configure/CustomTargetAfterError-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Configure/CustomTargetAfterError-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Configure/CustomTargetAfterError-stderr.txt b/Tests/RunCMake/Configure/CustomTargetAfterError-stderr.txt
new file mode 100644
index 0000000000..7ce7daf6f5
--- /dev/null
+++ b/Tests/RunCMake/Configure/CustomTargetAfterError-stderr.txt
@@ -0,0 +1,9 @@
+^CMake Error at CustomTargetAfterError.cmake:1 \(message\):
+ Error before add_custom_target
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at CustomTargetAfterError.cmake:3 \(message\):
+ Error after add_custom_target
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Configure/CustomTargetAfterError.cmake b/Tests/RunCMake/Configure/CustomTargetAfterError.cmake
new file mode 100644
index 0000000000..3e264553ba
--- /dev/null
+++ b/Tests/RunCMake/Configure/CustomTargetAfterError.cmake
@@ -0,0 +1,3 @@
+message(SEND_ERROR "Error before add_custom_target")
+add_custom_target(foo COMMAND echo)
+message(SEND_ERROR "Error after add_custom_target")
diff --git a/Tests/RunCMake/Configure/ErrorLogs-result.txt b/Tests/RunCMake/Configure/ErrorLogs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Configure/ErrorLogs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Configure/ErrorLogs-stderr.txt b/Tests/RunCMake/Configure/ErrorLogs-stderr.txt
new file mode 100644
index 0000000000..4eee45dbc4
--- /dev/null
+++ b/Tests/RunCMake/Configure/ErrorLogs-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at ErrorLogs.cmake:3 \(message\):
+ Some error!
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Configure/ErrorLogs-stdout.txt b/Tests/RunCMake/Configure/ErrorLogs-stdout.txt
new file mode 100644
index 0000000000..c467b6204f
--- /dev/null
+++ b/Tests/RunCMake/Configure/ErrorLogs-stdout.txt
@@ -0,0 +1,3 @@
+-- Configuring incomplete, errors occurred!
+See also ".*/Tests/RunCMake/Configure/ErrorLogs-build/CMakeFiles/CMakeOutput\.log"\.
+See also ".*/Tests/RunCMake/Configure/ErrorLogs-build/CMakeFiles/CMakeError\.log"\.
diff --git a/Tests/RunCMake/Configure/ErrorLogs.cmake b/Tests/RunCMake/Configure/ErrorLogs.cmake
new file mode 100644
index 0000000000..e8cf062668
--- /dev/null
+++ b/Tests/RunCMake/Configure/ErrorLogs.cmake
@@ -0,0 +1,3 @@
+file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Some detailed error information!\n")
+message(SEND_ERROR "Some error!")
diff --git a/Tests/RunCMake/Configure/FailCopyFileABI-check.cmake b/Tests/RunCMake/Configure/FailCopyFileABI-check.cmake
new file mode 100644
index 0000000000..db0cb0a346
--- /dev/null
+++ b/Tests/RunCMake/Configure/FailCopyFileABI-check.cmake
@@ -0,0 +1,14 @@
+set(log "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/CMakeError.log")
+if(EXISTS "${log}")
+ file(READ "${log}" error_log)
+else()
+ set(error_log "")
+endif()
+string(REPLACE "\r\n" "\n" regex "Cannot copy output executable.*
+to destination specified by COPY_FILE:.*
+Unable to find the executable at any of:
+ .*\\.missing")
+if(NOT error_log MATCHES "${regex}")
+ string(REGEX REPLACE "\n" "\n " error_log " ${error_log}")
+ set(RunCMake_TEST_FAILED "Log file:\n ${log}\ndoes not have expected COPY_FILE failure message:\n${error_log}")
+endif()
diff --git a/Tests/RunCMake/Configure/FailCopyFileABI-override.cmake b/Tests/RunCMake/Configure/FailCopyFileABI-override.cmake
new file mode 100644
index 0000000000..c633555b64
--- /dev/null
+++ b/Tests/RunCMake/Configure/FailCopyFileABI-override.cmake
@@ -0,0 +1,6 @@
+# Change the executable suffix that try_compile will use for
+# COPY_FILE but not inside the test project. This forces failure.
+get_property(in_try_compile GLOBAL PROPERTY IN_TRY_COMPILE)
+if(NOT in_try_compile)
+ set(CMAKE_EXECUTABLE_SUFFIX .missing)
+endif()
diff --git a/Tests/RunCMake/Configure/FailCopyFileABI-stdout.txt b/Tests/RunCMake/Configure/FailCopyFileABI-stdout.txt
new file mode 100644
index 0000000000..92fe2330af
--- /dev/null
+++ b/Tests/RunCMake/Configure/FailCopyFileABI-stdout.txt
@@ -0,0 +1,4 @@
+-- Detecting C compiler ABI info
+-- Detecting C compiler ABI info - failed.*
+-- Configuring done
+-- Generating done
diff --git a/Tests/RunCMake/Configure/FailCopyFileABI.cmake b/Tests/RunCMake/Configure/FailCopyFileABI.cmake
new file mode 100644
index 0000000000..74efd9720d
--- /dev/null
+++ b/Tests/RunCMake/Configure/FailCopyFileABI.cmake
@@ -0,0 +1,2 @@
+set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_SOURCE_DIR}/FailCopyFileABI-override.cmake)
+enable_language(C)
diff --git a/Tests/RunCMake/Configure/RerunCMake-build1-check.cmake b/Tests/RunCMake/Configure/RerunCMake-build1-check.cmake
new file mode 100644
index 0000000000..dbf8f67504
--- /dev/null
+++ b/Tests/RunCMake/Configure/RerunCMake-build1-check.cmake
@@ -0,0 +1,9 @@
+file(READ ${stamp} content)
+if(NOT content STREQUAL 1)
+ set(RunCMake_TEST_FAILED "Expected stamp '1' but got: '${content}'")
+endif()
+
+file(READ ${output} content)
+if(NOT content STREQUAL 1)
+ set(RunCMake_TEST_FAILED "Expected output '1' but got: '${content}'")
+endif()
diff --git a/Tests/RunCMake/Configure/RerunCMake-build2-check.cmake b/Tests/RunCMake/Configure/RerunCMake-build2-check.cmake
new file mode 100644
index 0000000000..a4897e539c
--- /dev/null
+++ b/Tests/RunCMake/Configure/RerunCMake-build2-check.cmake
@@ -0,0 +1,9 @@
+file(READ ${stamp} content)
+if(NOT content STREQUAL 2)
+ set(RunCMake_TEST_FAILED "Expected stamp '2' but got: '${content}'")
+endif()
+
+file(READ ${output} content)
+if(NOT content STREQUAL 2)
+ set(RunCMake_TEST_FAILED "Expected output '2' but got: '${content}'")
+endif()
diff --git a/Tests/RunCMake/Configure/RerunCMake.cmake b/Tests/RunCMake/Configure/RerunCMake.cmake
new file mode 100644
index 0000000000..5a561bf450
--- /dev/null
+++ b/Tests/RunCMake/Configure/RerunCMake.cmake
@@ -0,0 +1,11 @@
+set(input ${CMAKE_CURRENT_BINARY_DIR}/CustomCMakeInput.txt)
+set(stamp ${CMAKE_CURRENT_BINARY_DIR}/CustomCMakeStamp.txt)
+file(READ ${input} content)
+file(WRITE ${stamp} "${content}")
+
+set(depend ${CMAKE_CURRENT_BINARY_DIR}/CustomCMakeDepend.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/CustomCMakeOutput.txt)
+set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${depend})
+file(READ ${depend} content)
+file(WRITE ${output} "${content}")
+set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS RerunCMake.txt)
diff --git a/Tests/RunCMake/Configure/RerunCMake.txt b/Tests/RunCMake/Configure/RerunCMake.txt
new file mode 100644
index 0000000000..15598c112c
--- /dev/null
+++ b/Tests/RunCMake/Configure/RerunCMake.txt
@@ -0,0 +1 @@
+Source-tree dependency for "RerunCMake.cmake".
diff --git a/Tests/RunCMake/Configure/RunCMakeTest.cmake b/Tests/RunCMake/Configure/RunCMakeTest.cmake
new file mode 100644
index 0000000000..58e1a2a988
--- /dev/null
+++ b/Tests/RunCMake/Configure/RunCMakeTest.cmake
@@ -0,0 +1,25 @@
+include(RunCMake)
+
+run_cmake(CustomTargetAfterError)
+run_cmake(ErrorLogs)
+run_cmake(FailCopyFileABI)
+
+# Use a single build tree for a few tests without cleaning.
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/RerunCMake-build)
+set(RunCMake_TEST_NO_CLEAN 1)
+file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+set(input "${RunCMake_TEST_BINARY_DIR}/CustomCMakeInput.txt")
+set(stamp "${RunCMake_TEST_BINARY_DIR}/CustomCMakeStamp.txt")
+set(depend "${RunCMake_TEST_BINARY_DIR}/CustomCMakeDepend.txt")
+set(output "${RunCMake_TEST_BINARY_DIR}/CustomCMakeOutput.txt")
+file(WRITE "${input}" "1")
+file(WRITE "${depend}" "1")
+run_cmake(RerunCMake)
+execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1) # handle 1s resolution
+file(WRITE "${input}" "2")
+run_cmake_command(RerunCMake-build1 ${CMAKE_COMMAND} --build .)
+file(WRITE "${depend}" "2")
+run_cmake_command(RerunCMake-build2 ${CMAKE_COMMAND} --build .)
+unset(RunCMake_TEST_BINARY_DIR)
+unset(RunCMake_TEST_NO_CLEAN)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0029-NEW-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0029-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0029-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0029-NEW-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0029-NEW-stderr.txt
new file mode 100644
index 0000000000..e147081127
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0029-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0029-NEW.cmake:2 \(subdir_depends\):
+ The subdir_depends command should not be called; see CMP0029.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0029-NEW.cmake b/Tests/RunCMake/DisallowedCommands/CMP0029-NEW.cmake
new file mode 100644
index 0000000000..392b9d409d
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0029-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0029 NEW)
+subdir_depends()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0029-OLD-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0029-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0029-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0029-OLD.cmake b/Tests/RunCMake/DisallowedCommands/CMP0029-OLD.cmake
new file mode 100644
index 0000000000..099fd90d36
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0029-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0029 OLD)
+subdir_depends()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0029-WARN-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0029-WARN-stderr.txt
new file mode 100644
index 0000000000..32a452a742
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0029-WARN-stderr.txt
@@ -0,0 +1,7 @@
+CMake Warning \(dev\) at CMP0029-WARN.cmake:1 \(subdir_depends\):
+ Policy CMP0029 is not set: The subdir_depends command should not be called.
+ Run "cmake --help-policy CMP0029" for policy details. Use the cmake_policy
+ command to set the policy and suppress this 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/DisallowedCommands/CMP0029-WARN.cmake b/Tests/RunCMake/DisallowedCommands/CMP0029-WARN.cmake
new file mode 100644
index 0000000000..1ceb1f85ea
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0029-WARN.cmake
@@ -0,0 +1 @@
+subdir_depends()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0030-NEW-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0030-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0030-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0030-NEW-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0030-NEW-stderr.txt
new file mode 100644
index 0000000000..cb380dbc54
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0030-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0030-NEW.cmake:2 \(use_mangled_mesa\):
+ The use_mangled_mesa command should not be called; see CMP0030.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0030-NEW.cmake b/Tests/RunCMake/DisallowedCommands/CMP0030-NEW.cmake
new file mode 100644
index 0000000000..73365a71bf
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0030-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0030 NEW)
+use_mangled_mesa()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0030-OLD-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0030-OLD-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0030-OLD-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0030-OLD-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0030-OLD-stderr.txt
new file mode 100644
index 0000000000..e95e16f869
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0030-OLD-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at CMP0030-OLD.cmake:2 \(use_mangled_mesa\):
+ use_mangled_mesa called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0030-OLD.cmake b/Tests/RunCMake/DisallowedCommands/CMP0030-OLD.cmake
new file mode 100644
index 0000000000..efbb852dd0
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0030-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0030 OLD)
+use_mangled_mesa()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0030-WARN-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0030-WARN-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0030-WARN-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0030-WARN-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0030-WARN-stderr.txt
new file mode 100644
index 0000000000..db3c23f132
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0030-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0030-WARN.cmake:1 \(use_mangled_mesa\):
+ Policy CMP0030 is not set: The use_mangled_mesa command should not be
+ called. Run "cmake --help-policy CMP0030" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Error at CMP0030-WARN.cmake:1 \(use_mangled_mesa\):
+ use_mangled_mesa called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0030-WARN.cmake b/Tests/RunCMake/DisallowedCommands/CMP0030-WARN.cmake
new file mode 100644
index 0000000000..cbe0ff0abb
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0030-WARN.cmake
@@ -0,0 +1 @@
+use_mangled_mesa()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0031-NEW-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0031-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0031-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0031-NEW-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0031-NEW-stderr.txt
new file mode 100644
index 0000000000..78c2236989
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0031-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0031-NEW.cmake:2 \(load_command\):
+ The load_command command should not be called; see CMP0031.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0031-NEW.cmake b/Tests/RunCMake/DisallowedCommands/CMP0031-NEW.cmake
new file mode 100644
index 0000000000..3d9caf21a8
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0031-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0031 NEW)
+load_command()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0031-OLD-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0031-OLD-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0031-OLD-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0031-OLD-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0031-OLD-stderr.txt
new file mode 100644
index 0000000000..ba198d6142
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0031-OLD-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0031-OLD.cmake:2 \(load_command\):
+ load_command Attempt to load command failed from file.*bogus_command.*
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0031-OLD.cmake b/Tests/RunCMake/DisallowedCommands/CMP0031-OLD.cmake
new file mode 100644
index 0000000000..8fedf98c75
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0031-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0031 OLD)
+load_command(bogus_command)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0031-WARN-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0031-WARN-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0031-WARN-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0031-WARN-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0031-WARN-stderr.txt
new file mode 100644
index 0000000000..4cb65b3b3e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0031-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0031-WARN.cmake:1 \(load_command\):
+ Policy CMP0031 is not set: The load_command command should not be called.
+ Run "cmake --help-policy CMP0031" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Error at CMP0031-WARN.cmake:1 \(load_command\):
+ load_command Attempt to load command failed from file.*bogus_command.*
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0031-WARN.cmake b/Tests/RunCMake/DisallowedCommands/CMP0031-WARN.cmake
new file mode 100644
index 0000000000..c9d99fcbe5
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0031-WARN.cmake
@@ -0,0 +1 @@
+load_command(bogus_command)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0032-NEW-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0032-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0032-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0032-NEW-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0032-NEW-stderr.txt
new file mode 100644
index 0000000000..c7ac16ecaf
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0032-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0032-NEW.cmake:2 \(output_required_files\):
+ The output_required_files command should not be called; see CMP0032.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0032-NEW.cmake b/Tests/RunCMake/DisallowedCommands/CMP0032-NEW.cmake
new file mode 100644
index 0000000000..c6fb5e8f02
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0032-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0032 NEW)
+output_required_files()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0032-OLD-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0032-OLD-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0032-OLD-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0032-OLD-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0032-OLD-stderr.txt
new file mode 100644
index 0000000000..2223c420c7
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0032-OLD-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0032-OLD.cmake:2 \(output_required_files\):
+ output_required_files called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0032-OLD.cmake b/Tests/RunCMake/DisallowedCommands/CMP0032-OLD.cmake
new file mode 100644
index 0000000000..6585110eae
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0032-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0032 OLD)
+output_required_files()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0032-WARN-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0032-WARN-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0032-WARN-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0032-WARN-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0032-WARN-stderr.txt
new file mode 100644
index 0000000000..0cf3f94d69
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0032-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0032-WARN.cmake:1 \(output_required_files\):
+ Policy CMP0032 is not set: The output_required_files command should not be
+ called. Run "cmake --help-policy CMP0032" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Error at CMP0032-WARN.cmake:1 \(output_required_files\):
+ output_required_files called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0032-WARN.cmake b/Tests/RunCMake/DisallowedCommands/CMP0032-WARN.cmake
new file mode 100644
index 0000000000..7411e48cae
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0032-WARN.cmake
@@ -0,0 +1 @@
+output_required_files()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0033-NEW-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0033-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0033-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0033-NEW-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0033-NEW-stderr.txt
new file mode 100644
index 0000000000..8d210aa689
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0033-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0033-NEW.cmake:2 \(export_library_dependencies\):
+ The export_library_dependencies command should not be called; see CMP0033.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0033-NEW.cmake b/Tests/RunCMake/DisallowedCommands/CMP0033-NEW.cmake
new file mode 100644
index 0000000000..6f90f29e80
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0033-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0033 NEW)
+export_library_dependencies()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0033-OLD-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0033-OLD-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0033-OLD-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0033-OLD-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0033-OLD-stderr.txt
new file mode 100644
index 0000000000..e5dd2dd79b
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0033-OLD-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0033-OLD.cmake:2 \(export_library_dependencies\):
+ export_library_dependencies called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0033-OLD.cmake b/Tests/RunCMake/DisallowedCommands/CMP0033-OLD.cmake
new file mode 100644
index 0000000000..a3504b67d3
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0033-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0033 OLD)
+export_library_dependencies()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0033-WARN-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0033-WARN-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0033-WARN-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0033-WARN-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0033-WARN-stderr.txt
new file mode 100644
index 0000000000..e561dacafe
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0033-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0033-WARN.cmake:1 \(export_library_dependencies\):
+ Policy CMP0033 is not set: The export_library_dependencies command should
+ not be called. Run "cmake --help-policy CMP0033" for policy details. Use
+ the cmake_policy command to set the policy and suppress this warning.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Error at CMP0033-WARN.cmake:1 \(export_library_dependencies\):
+ export_library_dependencies called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0033-WARN.cmake b/Tests/RunCMake/DisallowedCommands/CMP0033-WARN.cmake
new file mode 100644
index 0000000000..f897dddf51
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0033-WARN.cmake
@@ -0,0 +1 @@
+export_library_dependencies()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0034-NEW-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0034-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0034-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0034-NEW-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0034-NEW-stderr.txt
new file mode 100644
index 0000000000..1dd279b8c6
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0034-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0034-NEW.cmake:2 \(utility_source\):
+ The utility_source command should not be called; see CMP0034.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0034-NEW.cmake b/Tests/RunCMake/DisallowedCommands/CMP0034-NEW.cmake
new file mode 100644
index 0000000000..48724a97e6
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0034-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0034 NEW)
+utility_source()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0034-OLD-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0034-OLD-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0034-OLD-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0034-OLD-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0034-OLD-stderr.txt
new file mode 100644
index 0000000000..3358628a63
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0034-OLD-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0034-OLD.cmake:2 \(utility_source\):
+ utility_source called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0034-OLD.cmake b/Tests/RunCMake/DisallowedCommands/CMP0034-OLD.cmake
new file mode 100644
index 0000000000..a2c9798dc5
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0034-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0034 OLD)
+utility_source()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0034-WARN-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0034-WARN-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0034-WARN-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0034-WARN-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0034-WARN-stderr.txt
new file mode 100644
index 0000000000..ea3831f9b7
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0034-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0034-WARN.cmake:1 \(utility_source\):
+ Policy CMP0034 is not set: The utility_source command should not be called.
+ Run "cmake --help-policy CMP0034" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Error at CMP0034-WARN.cmake:1 \(utility_source\):
+ utility_source called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0034-WARN.cmake b/Tests/RunCMake/DisallowedCommands/CMP0034-WARN.cmake
new file mode 100644
index 0000000000..b4ae045661
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0034-WARN.cmake
@@ -0,0 +1 @@
+utility_source()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0035-NEW-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0035-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0035-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0035-NEW-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0035-NEW-stderr.txt
new file mode 100644
index 0000000000..0604829ae5
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0035-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0035-NEW.cmake:2 \(variable_requires\):
+ The variable_requires command should not be called; see CMP0035.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0035-NEW.cmake b/Tests/RunCMake/DisallowedCommands/CMP0035-NEW.cmake
new file mode 100644
index 0000000000..27eb32e183
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0035-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0035 NEW)
+variable_requires()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0035-OLD-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0035-OLD-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0035-OLD-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0035-OLD-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0035-OLD-stderr.txt
new file mode 100644
index 0000000000..86eda438c7
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0035-OLD-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0035-OLD.cmake:2 \(variable_requires\):
+ variable_requires called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0035-OLD.cmake b/Tests/RunCMake/DisallowedCommands/CMP0035-OLD.cmake
new file mode 100644
index 0000000000..74252628b4
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0035-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0035 OLD)
+variable_requires()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0035-WARN-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0035-WARN-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0035-WARN-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0035-WARN-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0035-WARN-stderr.txt
new file mode 100644
index 0000000000..4d4fc8e84f
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0035-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0035-WARN.cmake:1 \(variable_requires\):
+ Policy CMP0035 is not set: The variable_requires command should not be
+ called. Run "cmake --help-policy CMP0035" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Error at CMP0035-WARN.cmake:1 \(variable_requires\):
+ variable_requires called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0035-WARN.cmake b/Tests/RunCMake/DisallowedCommands/CMP0035-WARN.cmake
new file mode 100644
index 0000000000..3af4de177a
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0035-WARN.cmake
@@ -0,0 +1 @@
+variable_requires()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0036-NEW-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0036-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0036-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0036-NEW-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0036-NEW-stderr.txt
new file mode 100644
index 0000000000..11aabd0980
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0036-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0036-NEW.cmake:2 \(build_name\):
+ The build_name command should not be called; see CMP0036.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0036-NEW.cmake b/Tests/RunCMake/DisallowedCommands/CMP0036-NEW.cmake
new file mode 100644
index 0000000000..5341db2a06
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0036-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0036 NEW)
+build_name()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0036-OLD-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0036-OLD-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0036-OLD-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0036-OLD-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0036-OLD-stderr.txt
new file mode 100644
index 0000000000..fef195f405
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0036-OLD-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0036-OLD.cmake:2 \(build_name\):
+ build_name called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0036-OLD.cmake b/Tests/RunCMake/DisallowedCommands/CMP0036-OLD.cmake
new file mode 100644
index 0000000000..fdd840f940
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0036-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0036 OLD)
+build_name()
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0036-WARN-result.txt b/Tests/RunCMake/DisallowedCommands/CMP0036-WARN-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0036-WARN-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0036-WARN-stderr.txt b/Tests/RunCMake/DisallowedCommands/CMP0036-WARN-stderr.txt
new file mode 100644
index 0000000000..b9b7c5a9ce
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0036-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0036-WARN.cmake:1 \(build_name\):
+ Policy CMP0036 is not set: The build_name command should not be called.
+ Run "cmake --help-policy CMP0036" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Error at CMP0036-WARN.cmake:1 \(build_name\):
+ build_name called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/DisallowedCommands/CMP0036-WARN.cmake b/Tests/RunCMake/DisallowedCommands/CMP0036-WARN.cmake
new file mode 100644
index 0000000000..9556687ab8
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMP0036-WARN.cmake
@@ -0,0 +1 @@
+build_name()
diff --git a/Tests/RunCMake/DisallowedCommands/CMakeLists.txt b/Tests/RunCMake/DisallowedCommands/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/DisallowedCommands/RunCMakeTest.cmake b/Tests/RunCMake/DisallowedCommands/RunCMakeTest.cmake
new file mode 100644
index 0000000000..208ea20855
--- /dev/null
+++ b/Tests/RunCMake/DisallowedCommands/RunCMakeTest.cmake
@@ -0,0 +1,16 @@
+include(RunCMake)
+
+foreach(p
+ CMP0029
+ CMP0030
+ CMP0031
+ CMP0032
+ CMP0033
+ CMP0034
+ CMP0035
+ CMP0036
+ )
+ run_cmake(${p}-WARN)
+ run_cmake(${p}-OLD)
+ run_cmake(${p}-NEW)
+endforeach()
diff --git a/Tests/RunCMake/ExportWithoutLanguage/CMakeLists.txt b/Tests/RunCMake/ExportWithoutLanguage/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/ExportWithoutLanguage/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/ExportWithoutLanguage/NoLanguage-result.txt b/Tests/RunCMake/ExportWithoutLanguage/NoLanguage-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExportWithoutLanguage/NoLanguage-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExportWithoutLanguage/NoLanguage-stderr.txt b/Tests/RunCMake/ExportWithoutLanguage/NoLanguage-stderr.txt
new file mode 100644
index 0000000000..5658d85d49
--- /dev/null
+++ b/Tests/RunCMake/ExportWithoutLanguage/NoLanguage-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error: CMake can not determine linker language for target: NoLanguage
+CMake Error in CMakeLists.txt:
+ Exporting the target "NoLanguage" is not allowed since its linker language
+ cannot be determined
diff --git a/Tests/RunCMake/ExportWithoutLanguage/NoLanguage.cmake b/Tests/RunCMake/ExportWithoutLanguage/NoLanguage.cmake
new file mode 100644
index 0000000000..2ede85431f
--- /dev/null
+++ b/Tests/RunCMake/ExportWithoutLanguage/NoLanguage.cmake
@@ -0,0 +1,2 @@
+add_library(NoLanguage header.h)
+export(TARGETS NoLanguage FILE "${CMAKE_CURRENT_BINARY_DIR}/export.cmake")
diff --git a/Tests/RunCMake/ExportWithoutLanguage/RunCMakeTest.cmake b/Tests/RunCMake/ExportWithoutLanguage/RunCMakeTest.cmake
new file mode 100644
index 0000000000..f77f4eba01
--- /dev/null
+++ b/Tests/RunCMake/ExportWithoutLanguage/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake(NoLanguage)
diff --git a/Tests/RunCMake/ExportWithoutLanguage/header.h b/Tests/RunCMake/ExportWithoutLanguage/header.h
new file mode 100644
index 0000000000..0c803ed036
--- /dev/null
+++ b/Tests/RunCMake/ExportWithoutLanguage/header.h
@@ -0,0 +1,2 @@
+
+enum some_compilers { need_more_than_nothing };
diff --git a/Tests/RunCMake/ExternalData/BadHashAlgo1-result.txt b/Tests/RunCMake/ExternalData/BadHashAlgo1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadHashAlgo1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/BadHashAlgo1-stderr.txt b/Tests/RunCMake/ExternalData/BadHashAlgo1-stderr.txt
new file mode 100644
index 0000000000..f68f0be6b1
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadHashAlgo1-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Unknown hash algorithm specified by ExternalData_LINK_CONTENT:
+
+ BAD
+Call Stack \(most recent call first\):
+ .*
+ BadHashAlgo1.cmake:3 \(ExternalData_Expand_Arguments\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadHashAlgo1.cmake b/Tests/RunCMake/ExternalData/BadHashAlgo1.cmake
new file mode 100644
index 0000000000..19e2e412dc
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadHashAlgo1.cmake
@@ -0,0 +1,3 @@
+include(ExternalData)
+set(ExternalData_LINK_CONTENT BAD)
+ExternalData_Expand_Arguments(Data args DATA{BadHashAlgo1.txt})
diff --git a/Tests/RunCMake/ExternalData/BadHashAlgo1.txt b/Tests/RunCMake/ExternalData/BadHashAlgo1.txt
new file mode 100644
index 0000000000..bfa2818c23
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadHashAlgo1.txt
@@ -0,0 +1 @@
+Sample input file that should not be transformed.
diff --git a/Tests/RunCMake/ExternalData/BadOption1-result.txt b/Tests/RunCMake/ExternalData/BadOption1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadOption1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/BadOption1-stderr.txt b/Tests/RunCMake/ExternalData/BadOption1-stderr.txt
new file mode 100644
index 0000000000..b63d098c0b
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadOption1-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Unknown option "Bad/Option" in argument
+
+ DATA{Data.txt,Bad/Option}
+
+Call Stack \(most recent call first\):
+ .*
+ BadOption1.cmake:2 \(ExternalData_Add_Test\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadOption1.cmake b/Tests/RunCMake/ExternalData/BadOption1.cmake
new file mode 100644
index 0000000000..1303d7f1a1
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadOption1.cmake
@@ -0,0 +1,5 @@
+include(ExternalData)
+ExternalData_Add_Test(Data
+ NAME Test
+ COMMAND ${CMAKE_COMMAND} -E echo DATA{Data.txt,Bad/Option}
+ )
diff --git a/Tests/RunCMake/ExternalData/BadOption2-result.txt b/Tests/RunCMake/ExternalData/BadOption2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadOption2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/BadOption2-stderr.txt b/Tests/RunCMake/ExternalData/BadOption2-stderr.txt
new file mode 100644
index 0000000000..d114c8aa9b
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadOption2-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Unknown option "Bad:Option" in argument
+
+ DATA{Data.txt,Bad:Option}
+
+Call Stack \(most recent call first\):
+ .*
+ BadOption2.cmake:2 \(ExternalData_Add_Test\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadOption2.cmake b/Tests/RunCMake/ExternalData/BadOption2.cmake
new file mode 100644
index 0000000000..6269b064c1
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadOption2.cmake
@@ -0,0 +1,5 @@
+include(ExternalData)
+ExternalData_Add_Test(Data
+ NAME Test
+ COMMAND ${CMAKE_COMMAND} -E echo DATA{Data.txt,Bad:Option}
+ )
diff --git a/Tests/RunCMake/ExternalData/BadSeries1-result.txt b/Tests/RunCMake/ExternalData/BadSeries1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadSeries1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/BadSeries1-stderr.txt b/Tests/RunCMake/ExternalData/BadSeries1-stderr.txt
new file mode 100644
index 0000000000..3099be579c
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadSeries1-stderr.txt
@@ -0,0 +1,19 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ ExternalData_SERIES_PARSE is set to
+
+ NotASeriesRegex
+
+ which is not of the form
+
+ \(<number>\)\(<suffix>\)\$
+
+ Fix the regular expression or set variables
+
+ ExternalData_SERIES_PARSE_PREFIX = <prefix> regex group number, if any
+ ExternalData_SERIES_PARSE_NUMBER = <number> regex group number
+ ExternalData_SERIES_PARSE_SUFFIX = <suffix> regex group number
+
+Call Stack \(most recent call first\):
+ .*
+ BadSeries1.cmake:3 \(ExternalData_Expand_Arguments\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadSeries1.cmake b/Tests/RunCMake/ExternalData/BadSeries1.cmake
new file mode 100644
index 0000000000..7d712106f1
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadSeries1.cmake
@@ -0,0 +1,3 @@
+include(ExternalData)
+set(ExternalData_SERIES_PARSE NotASeriesRegex)
+ExternalData_Expand_Arguments(Data args DATA{Data.txt,:})
diff --git a/Tests/RunCMake/ExternalData/BadSeries2-result.txt b/Tests/RunCMake/ExternalData/BadSeries2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadSeries2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/BadSeries2-stderr.txt b/Tests/RunCMake/ExternalData/BadSeries2-stderr.txt
new file mode 100644
index 0000000000..3a02c25e94
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadSeries2-stderr.txt
@@ -0,0 +1,16 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Data file referenced by argument
+
+ DATA{Data.txt,:}
+
+ corresponds to path
+
+ Data.txt
+
+ that does not match regular expression
+
+ \(x\)\(y\)\$
+Call Stack \(most recent call first\):
+ .*
+ BadSeries2.cmake:3 \(ExternalData_Expand_Arguments\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadSeries2.cmake b/Tests/RunCMake/ExternalData/BadSeries2.cmake
new file mode 100644
index 0000000000..e81993b8fd
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadSeries2.cmake
@@ -0,0 +1,3 @@
+include(ExternalData)
+set(ExternalData_SERIES_PARSE "(x)(y)$")
+ExternalData_Expand_Arguments(Data args DATA{Data.txt,:})
diff --git a/Tests/RunCMake/ExternalData/BadSeries3-result.txt b/Tests/RunCMake/ExternalData/BadSeries3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadSeries3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/BadSeries3-stderr.txt b/Tests/RunCMake/ExternalData/BadSeries3-stderr.txt
new file mode 100644
index 0000000000..594cb6f6a4
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadSeries3-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Series option ":" not allowed with associated files.
+Call Stack \(most recent call first\):
+ .*
+ BadSeries3.cmake:2 \(ExternalData_Expand_Arguments\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadSeries3.cmake b/Tests/RunCMake/ExternalData/BadSeries3.cmake
new file mode 100644
index 0000000000..b640df8781
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/BadSeries3.cmake
@@ -0,0 +1,2 @@
+include(ExternalData)
+ExternalData_Expand_Arguments(Data args DATA{PairA.txt,PairB.txt,:})
diff --git a/Tests/RunCMake/ExternalData/CMakeLists.txt b/Tests/RunCMake/ExternalData/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/ExternalData/Data.txt.md5 b/Tests/RunCMake/ExternalData/Data.txt.md5
new file mode 100644
index 0000000000..93b3485e94
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Data.txt.md5
@@ -0,0 +1 @@
+e8bb14af900b998b5a3df7e21dd07d58
diff --git a/Tests/RunCMake/ExternalData/Directory1-result.txt b/Tests/RunCMake/ExternalData/Directory1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/Directory1-stderr.txt b/Tests/RunCMake/ExternalData/Directory1-stderr.txt
new file mode 100644
index 0000000000..2bc3c601d1
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory1-stderr.txt
@@ -0,0 +1,14 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Data file referenced by argument
+
+ DATA{Directory1}
+
+ corresponds to source tree path
+
+ Directory1
+
+ that is directory instead of a file!
+Call Stack \(most recent call first\):
+ .*
+ Directory1.cmake:3 \(ExternalData_Add_Test\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/Directory1.cmake b/Tests/RunCMake/ExternalData/Directory1.cmake
new file mode 100644
index 0000000000..68f1b54bea
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory1.cmake
@@ -0,0 +1,6 @@
+include(CTest)
+include(ExternalData)
+ExternalData_Add_Test(Data
+ NAME Test
+ COMMAND ${CMAKE_COMMAND} -E echo DATA{Directory1}
+ )
diff --git a/Tests/RunCMake/ExternalData/Directory1/DirData1.txt b/Tests/RunCMake/ExternalData/Directory1/DirData1.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory1/DirData1.txt
diff --git a/Tests/RunCMake/ExternalData/Directory2-result.txt b/Tests/RunCMake/ExternalData/Directory2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/Directory2-stderr.txt b/Tests/RunCMake/ExternalData/Directory2-stderr.txt
new file mode 100644
index 0000000000..92c9a2ff59
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory2-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Data directory referenced by argument
+
+ DATA{Directory2/}
+
+ must list associated files.
+Call Stack \(most recent call first\):
+ .*
+ Directory2.cmake:3 \(ExternalData_Add_Test\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/Directory2.cmake b/Tests/RunCMake/ExternalData/Directory2.cmake
new file mode 100644
index 0000000000..30b992e6eb
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory2.cmake
@@ -0,0 +1,6 @@
+include(CTest)
+include(ExternalData)
+ExternalData_Add_Test(Data
+ NAME Test
+ COMMAND ${CMAKE_COMMAND} -E echo DATA{Directory2/}
+ )
diff --git a/Tests/RunCMake/ExternalData/Directory2.md5 b/Tests/RunCMake/ExternalData/Directory2.md5
new file mode 100644
index 0000000000..93b3485e94
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory2.md5
@@ -0,0 +1 @@
+e8bb14af900b998b5a3df7e21dd07d58
diff --git a/Tests/RunCMake/ExternalData/Directory2/DirData2.txt b/Tests/RunCMake/ExternalData/Directory2/DirData2.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory2/DirData2.txt
diff --git a/Tests/RunCMake/ExternalData/Directory3-stderr.txt b/Tests/RunCMake/ExternalData/Directory3-stderr.txt
new file mode 100644
index 0000000000..ceed2a04d7
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory3-stderr.txt
@@ -0,0 +1,15 @@
+CMake Warning \(dev\) at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Data file referenced by argument
+
+ DATA{Directory3/\*}
+
+ corresponds to source tree path
+
+ Directory3/.
+
+ that does not exist as a file \(with or without an extension\)!
+Call Stack \(most recent call first\):
+ .*
+ Directory3.cmake:3 \(ExternalData_Add_Test\)
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/ExternalData/Directory3.cmake b/Tests/RunCMake/ExternalData/Directory3.cmake
new file mode 100644
index 0000000000..55d8be9dd3
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory3.cmake
@@ -0,0 +1,6 @@
+include(CTest)
+include(ExternalData)
+ExternalData_Add_Test(Data
+ NAME Test
+ COMMAND ${CMAKE_COMMAND} -E echo DATA{Directory3/*}
+ )
diff --git a/Tests/RunCMake/ExternalData/Directory3/DirData3.txt b/Tests/RunCMake/ExternalData/Directory3/DirData3.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory3/DirData3.txt
diff --git a/Tests/RunCMake/ExternalData/Directory4-result.txt b/Tests/RunCMake/ExternalData/Directory4-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory4-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/Directory4-stderr.txt b/Tests/RunCMake/ExternalData/Directory4-stderr.txt
new file mode 100644
index 0000000000..dcb8522f88
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory4-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Series option ":" not allowed with directories.
+Call Stack \(most recent call first\):
+ .*
+ Directory4.cmake:3 \(ExternalData_Add_Test\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/Directory4.cmake b/Tests/RunCMake/ExternalData/Directory4.cmake
new file mode 100644
index 0000000000..7d3d6384d6
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory4.cmake
@@ -0,0 +1,6 @@
+include(CTest)
+include(ExternalData)
+ExternalData_Add_Test(Data
+ NAME Test
+ COMMAND ${CMAKE_COMMAND} -E echo DATA{Directory4/,:}
+ )
diff --git a/Tests/RunCMake/ExternalData/Directory4/DirData4.txt b/Tests/RunCMake/ExternalData/Directory4/DirData4.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory4/DirData4.txt
diff --git a/Tests/RunCMake/ExternalData/Directory5-result.txt b/Tests/RunCMake/ExternalData/Directory5-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory5-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/Directory5-stderr.txt b/Tests/RunCMake/ExternalData/Directory5-stderr.txt
new file mode 100644
index 0000000000..8e54aecd2a
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory5-stderr.txt
@@ -0,0 +1,14 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Data directory referenced by argument
+
+ DATA{Directory5/}
+
+ corresponds to source tree path
+
+ Directory5
+
+ that does not exist as a directory!
+Call Stack \(most recent call first\):
+ .*
+ Directory5.cmake:3 \(ExternalData_Add_Test\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/Directory5.cmake b/Tests/RunCMake/ExternalData/Directory5.cmake
new file mode 100644
index 0000000000..931589e4e4
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Directory5.cmake
@@ -0,0 +1,6 @@
+include(CTest)
+include(ExternalData)
+ExternalData_Add_Test(Data
+ NAME Test
+ COMMAND ${CMAKE_COMMAND} -E echo DATA{Directory5/}
+ )
diff --git a/Tests/RunCMake/ExternalData/LinkContentMD5-stdout.txt b/Tests/RunCMake/ExternalData/LinkContentMD5-stdout.txt
new file mode 100644
index 0000000000..f77fca9b51
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/LinkContentMD5-stdout.txt
@@ -0,0 +1,3 @@
+-- Linked ToLink.txt.md5 to ExternalData MD5/c18ff9804c8deec9eaeb17063cda8b7b
+-- Raw data correctly transformed to content link!
+-- Staged content exists!
diff --git a/Tests/RunCMake/ExternalData/LinkContentMD5.cmake b/Tests/RunCMake/ExternalData/LinkContentMD5.cmake
new file mode 100644
index 0000000000..41b4deebfd
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/LinkContentMD5.cmake
@@ -0,0 +1,22 @@
+include(ExternalData)
+set(ExternalData_LINK_CONTENT MD5)
+set(ExternalData_SOURCE_ROOT ${CMAKE_CURRENT_BINARY_DIR})
+set(ExternalData_BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR}/ExternalData)
+set(input ${CMAKE_CURRENT_BINARY_DIR}/ToLink.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/ExternalData/ToLink.txt)
+set(staged "${CMAKE_CURRENT_BINARY_DIR}/.ExternalData_MD5_c18ff9804c8deec9eaeb17063cda8b7b")
+file(REMOVE ${staged})
+file(REMOVE ${input}.md5)
+file(WRITE ${input} "To be transformed into a content link.")
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Raw data correctly transformed to content link!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
+if(EXISTS "${staged}")
+ message(STATUS "Staged content exists!")
+else()
+ message(FATAL_ERROR "Staged content missing!")
+endif()
diff --git a/Tests/RunCMake/ExternalData/LinkContentSHA1-stdout.txt b/Tests/RunCMake/ExternalData/LinkContentSHA1-stdout.txt
new file mode 100644
index 0000000000..9a8eb2e3db
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/LinkContentSHA1-stdout.txt
@@ -0,0 +1,3 @@
+-- Linked ToLink.txt.sha1 to ExternalData SHA1/114ee5dda251457fd2df63bec91d3b8db43aba58
+-- Raw data correctly transformed to content link!
+-- Staged content exists!
diff --git a/Tests/RunCMake/ExternalData/LinkContentSHA1.cmake b/Tests/RunCMake/ExternalData/LinkContentSHA1.cmake
new file mode 100644
index 0000000000..f78501cf57
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/LinkContentSHA1.cmake
@@ -0,0 +1,22 @@
+include(ExternalData)
+set(ExternalData_LINK_CONTENT SHA1)
+set(ExternalData_SOURCE_ROOT ${CMAKE_CURRENT_BINARY_DIR})
+set(ExternalData_BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR}/ExternalData)
+set(input ${CMAKE_CURRENT_BINARY_DIR}/ToLink.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/ExternalData/ToLink.txt)
+set(staged "${CMAKE_CURRENT_BINARY_DIR}/.ExternalData_SHA1_114ee5dda251457fd2df63bec91d3b8db43aba58")
+file(REMOVE ${staged})
+file(REMOVE ${input}.sha1)
+file(WRITE ${input} "To be transformed into a content link.")
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Raw data correctly transformed to content link!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
+if(EXISTS "${staged}")
+ message(STATUS "Staged content exists!")
+else()
+ message(FATAL_ERROR "Staged content missing!")
+endif()
diff --git a/Tests/RunCMake/ExternalData/LinkDirectory1-stdout.txt b/Tests/RunCMake/ExternalData/LinkDirectory1-stdout.txt
new file mode 100644
index 0000000000..953ea68547
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/LinkDirectory1-stdout.txt
@@ -0,0 +1,5 @@
+-- Linked Dir/ToLink.txt.md5 to ExternalData MD5/c18ff9804c8deec9eaeb17063cda8b7b
+-- Raw data correctly transformed to content link!
+-- Staged content exists!
+-- Staged content is correct!
+-- Staged content was correctly not re-staged!
diff --git a/Tests/RunCMake/ExternalData/LinkDirectory1.cmake b/Tests/RunCMake/ExternalData/LinkDirectory1.cmake
new file mode 100644
index 0000000000..541fc79b49
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/LinkDirectory1.cmake
@@ -0,0 +1,37 @@
+include(ExternalData)
+set(ExternalData_LINK_CONTENT MD5)
+set(ExternalData_SOURCE_ROOT ${CMAKE_CURRENT_BINARY_DIR})
+set(ExternalData_BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR}/ExternalData)
+set(input ${CMAKE_CURRENT_BINARY_DIR}/Dir)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/ExternalData/Dir)
+set(staged "${input}/.ExternalData_MD5_c18ff9804c8deec9eaeb17063cda8b7b")
+set(content "To be transformed into a content link.")
+file(REMOVE ${staged})
+file(REMOVE_RECURSE ${input})
+file(WRITE ${input}/ToLink.txt "${content}")
+ExternalData_Expand_Arguments(Data args "DATA{${input}/,REGEX:.*}")
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Raw data correctly transformed to content link!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
+if(EXISTS "${staged}")
+ message(STATUS "Staged content exists!")
+else()
+ message(FATAL_ERROR "Staged content missing!")
+endif()
+
+# Expand again to check whether staged content is ignored.
+ExternalData_Expand_Arguments(Data args "DATA{${input}/,REGEX:.*}")
+file(STRINGS "${staged}" staged_content LIMIT_INPUT 1024)
+if("${content}" STREQUAL "${staged_content}")
+ message(STATUS "Staged content is correct!")
+else()
+ message(STATUS "Staged content is incorrect!")
+endif()
+if(EXISTS "${staged}.md5")
+ message(FATAL_ERROR "Staged content was incorrectly re-staged!")
+else()
+ message(STATUS "Staged content was correctly not re-staged!")
+endif()
diff --git a/Tests/RunCMake/ExternalData/MissingData-stderr.txt b/Tests/RunCMake/ExternalData/MissingData-stderr.txt
new file mode 100644
index 0000000000..39ed2f15f2
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/MissingData-stderr.txt
@@ -0,0 +1,15 @@
+CMake Warning \(dev\) at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Data file referenced by argument
+
+ DATA{MissingData.txt}
+
+ corresponds to source tree path
+
+ MissingData.txt
+
+ that does not exist as a file \(with or without an extension\)!
+Call Stack \(most recent call first\):
+ .*
+ MissingData.cmake:4 \(ExternalData_Expand_Arguments\)
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/ExternalData/MissingData-stdout.txt b/Tests/RunCMake/ExternalData/MissingData-stdout.txt
new file mode 100644
index 0000000000..addd40eaa4
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/MissingData-stdout.txt
@@ -0,0 +1 @@
+-- Missing data reference correctly transformed!
diff --git a/Tests/RunCMake/ExternalData/MissingData.cmake b/Tests/RunCMake/ExternalData/MissingData.cmake
new file mode 100644
index 0000000000..f5fefd5cca
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/MissingData.cmake
@@ -0,0 +1,10 @@
+include(ExternalData)
+
+set(output "${CMAKE_SOURCE_DIR}/MissingData.txt")
+ExternalData_Expand_Arguments(Data args DATA{MissingData.txt})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Missing data reference correctly transformed!")
+else()
+ message(FATAL_ERROR "Missing data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stderr.txt b/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stderr.txt
new file mode 100644
index 0000000000..315af5e492
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stderr.txt
@@ -0,0 +1,15 @@
+CMake Warning \(dev\) at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Data file referenced by argument
+
+ DATA{MissingData.txt,Data.txt}
+
+ corresponds to source tree path
+
+ MissingData.txt
+
+ that does not exist as a file \(with or without an extension\)!
+Call Stack \(most recent call first\):
+ .*
+ MissingDataWithAssociated.cmake:4 \(ExternalData_Expand_Arguments\)
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stdout.txt b/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stdout.txt
new file mode 100644
index 0000000000..addd40eaa4
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stdout.txt
@@ -0,0 +1 @@
+-- Missing data reference correctly transformed!
diff --git a/Tests/RunCMake/ExternalData/MissingDataWithAssociated.cmake b/Tests/RunCMake/ExternalData/MissingDataWithAssociated.cmake
new file mode 100644
index 0000000000..a4c4638b0b
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/MissingDataWithAssociated.cmake
@@ -0,0 +1,10 @@
+include(ExternalData)
+
+set(output "${CMAKE_BINARY_DIR}/MissingData.txt")
+ExternalData_Expand_Arguments(Data args DATA{MissingData.txt,Data.txt})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Missing data reference correctly transformed!")
+else()
+ message(FATAL_ERROR "Missing data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/NoLinkInSource-stderr.txt b/Tests/RunCMake/ExternalData/NoLinkInSource-stderr.txt
new file mode 100644
index 0000000000..496ad8ae4e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NoLinkInSource-stderr.txt
@@ -0,0 +1,6 @@
+CMake Warning at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ ExternalData_LINK_CONTENT cannot be used in-source
+Call Stack \(most recent call first\):
+ .*
+ NoLinkInSource.cmake:8 \(ExternalData_Expand_Arguments\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/NoLinkInSource-stdout.txt b/Tests/RunCMake/ExternalData/NoLinkInSource-stdout.txt
new file mode 100644
index 0000000000..18946f0ecb
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NoLinkInSource-stdout.txt
@@ -0,0 +1 @@
+-- Data reference correctly not transformed!
diff --git a/Tests/RunCMake/ExternalData/NoLinkInSource.cmake b/Tests/RunCMake/ExternalData/NoLinkInSource.cmake
new file mode 100644
index 0000000000..cbf45ebbf7
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NoLinkInSource.cmake
@@ -0,0 +1,14 @@
+include(ExternalData)
+set(ExternalData_LINK_CONTENT MD5)
+set(ExternalData_SOURCE_ROOT ${CMAKE_CURRENT_BINARY_DIR})
+set(ExternalData_BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR})
+set(input ${CMAKE_CURRENT_BINARY_DIR}/ToLink.txt)
+file(REMOVE ${input}.md5)
+file(WRITE ${input} "To be transformed into a content link.")
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${input}")
+ message(STATUS "Data reference correctly not transformed!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected no transformation.")
+endif()
diff --git a/Tests/RunCMake/ExternalData/NoURLTemplates-result.txt b/Tests/RunCMake/ExternalData/NoURLTemplates-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NoURLTemplates-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/NoURLTemplates-stderr.txt b/Tests/RunCMake/ExternalData/NoURLTemplates-stderr.txt
new file mode 100644
index 0000000000..ccbaf5af31
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NoURLTemplates-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Neither ExternalData_URL_TEMPLATES nor ExternalData_OBJECT_STORES is set!
+Call Stack \(most recent call first\):
+ NoURLTemplates.cmake:2 \(ExternalData_Add_Target\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ExternalData/NoURLTemplates.cmake b/Tests/RunCMake/ExternalData/NoURLTemplates.cmake
new file mode 100644
index 0000000000..8f0e069c22
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NoURLTemplates.cmake
@@ -0,0 +1,2 @@
+include(ExternalData)
+ExternalData_Add_Target(Data)
diff --git a/Tests/RunCMake/ExternalData/NormalData1-stdout.txt b/Tests/RunCMake/ExternalData/NormalData1-stdout.txt
new file mode 100644
index 0000000000..2f2c770cbf
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NormalData1-stdout.txt
@@ -0,0 +1 @@
+-- Data reference correctly transformed!
diff --git a/Tests/RunCMake/ExternalData/NormalData1.cmake b/Tests/RunCMake/ExternalData/NormalData1.cmake
new file mode 100644
index 0000000000..d6cc384c85
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NormalData1.cmake
@@ -0,0 +1,13 @@
+include(ExternalData)
+set(ExternalData_URL_TEMPLATES
+ "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
+ )
+set(input Data.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/Data.txt)
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Data reference correctly transformed!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/NormalData2-stdout.txt b/Tests/RunCMake/ExternalData/NormalData2-stdout.txt
new file mode 100644
index 0000000000..2f2c770cbf
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NormalData2-stdout.txt
@@ -0,0 +1 @@
+-- Data reference correctly transformed!
diff --git a/Tests/RunCMake/ExternalData/NormalData2.cmake b/Tests/RunCMake/ExternalData/NormalData2.cmake
new file mode 100644
index 0000000000..c979b48ea9
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NormalData2.cmake
@@ -0,0 +1,14 @@
+include(ExternalData)
+set(ExternalData_URL_TEMPLATES
+ "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
+ )
+set(ExternalData_BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR}/ExternalData)
+set(input Data.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/ExternalData/Data.txt)
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Data reference correctly transformed!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/NormalData3-stdout.txt b/Tests/RunCMake/ExternalData/NormalData3-stdout.txt
new file mode 100644
index 0000000000..2f2c770cbf
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NormalData3-stdout.txt
@@ -0,0 +1 @@
+-- Data reference correctly transformed!
diff --git a/Tests/RunCMake/ExternalData/NormalData3.cmake b/Tests/RunCMake/ExternalData/NormalData3.cmake
new file mode 100644
index 0000000000..e99112267a
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NormalData3.cmake
@@ -0,0 +1,14 @@
+include(ExternalData)
+set(ExternalData_URL_TEMPLATES
+ "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
+ )
+set(ExternalData_BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR}/ExternalData)
+set(input ${CMAKE_CURRENT_SOURCE_DIR}/Data.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/ExternalData/Data.txt)
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Data reference correctly transformed!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/NormalDataSub1-stdout.txt b/Tests/RunCMake/ExternalData/NormalDataSub1-stdout.txt
new file mode 100644
index 0000000000..2f2c770cbf
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NormalDataSub1-stdout.txt
@@ -0,0 +1 @@
+-- Data reference correctly transformed!
diff --git a/Tests/RunCMake/ExternalData/NormalDataSub1.cmake b/Tests/RunCMake/ExternalData/NormalDataSub1.cmake
new file mode 100644
index 0000000000..015e94c0a7
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NormalDataSub1.cmake
@@ -0,0 +1,13 @@
+include(ExternalData)
+set(ExternalData_URL_TEMPLATES
+ "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
+ )
+set(input SubDirectory1/Data.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/SubDirectory1/Data.txt)
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Data reference correctly transformed!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/NotUnderRoot-result.txt b/Tests/RunCMake/ExternalData/NotUnderRoot-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NotUnderRoot-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExternalData/NotUnderRoot-stderr.txt b/Tests/RunCMake/ExternalData/NotUnderRoot-stderr.txt
new file mode 100644
index 0000000000..1f2eb1c7af
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NotUnderRoot-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
+ Data file referenced by argument
+
+ DATA{../NotUnderRoot.txt}
+
+ does not lie under the top-level source directory
+
+ .*/Tests/RunCMake/ExternalData
+
+Call Stack \(most recent call first\):
+ .*
+ NotUnderRoot.cmake:2 \(ExternalData_Add_Test\)
diff --git a/Tests/RunCMake/ExternalData/NotUnderRoot.cmake b/Tests/RunCMake/ExternalData/NotUnderRoot.cmake
new file mode 100644
index 0000000000..c7942d678d
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/NotUnderRoot.cmake
@@ -0,0 +1,5 @@
+include(ExternalData)
+ExternalData_Add_Test(Data
+ NAME Test
+ COMMAND ${CMAKE_COMMAND} -E echo DATA{../NotUnderRoot.txt}
+ )
diff --git a/Tests/RunCMake/ExternalData/ObjectStoreOnly.cmake b/Tests/RunCMake/ExternalData/ObjectStoreOnly.cmake
new file mode 100644
index 0000000000..5e66101442
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/ObjectStoreOnly.cmake
@@ -0,0 +1,3 @@
+include(ExternalData)
+set(ExternalData_OBJECT_STORES "${CMAKE_CURRENT_BINARY_DIR}")
+ExternalData_Add_Target(Data)
diff --git a/Tests/RunCMake/ExternalData/RunCMakeTest.cmake b/Tests/RunCMake/ExternalData/RunCMakeTest.cmake
new file mode 100644
index 0000000000..04e3d593f8
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/RunCMakeTest.cmake
@@ -0,0 +1,30 @@
+include(RunCMake)
+
+run_cmake(BadHashAlgo1)
+run_cmake(BadOption1)
+run_cmake(BadOption2)
+run_cmake(BadSeries1)
+run_cmake(BadSeries2)
+run_cmake(BadSeries3)
+run_cmake(Directory1)
+run_cmake(Directory2)
+run_cmake(Directory3)
+run_cmake(Directory4)
+run_cmake(Directory5)
+run_cmake(LinkContentMD5)
+run_cmake(LinkContentSHA1)
+run_cmake(LinkDirectory1)
+run_cmake(MissingData)
+run_cmake(MissingDataWithAssociated)
+run_cmake(NoLinkInSource)
+run_cmake(NoURLTemplates)
+run_cmake(NormalData1)
+run_cmake(NormalData2)
+run_cmake(NormalData3)
+run_cmake(NormalDataSub1)
+run_cmake(NotUnderRoot)
+run_cmake(ObjectStoreOnly)
+run_cmake(Semicolon1)
+run_cmake(Semicolon2)
+run_cmake(Semicolon3)
+run_cmake(SubDirectory1)
diff --git a/Tests/RunCMake/ExternalData/Semicolon1-stdout.txt b/Tests/RunCMake/ExternalData/Semicolon1-stdout.txt
new file mode 100644
index 0000000000..361baebba4
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Semicolon1-stdout.txt
@@ -0,0 +1 @@
+-- Data arguments correctly transformed!
diff --git a/Tests/RunCMake/ExternalData/Semicolon1.cmake b/Tests/RunCMake/ExternalData/Semicolon1.cmake
new file mode 100644
index 0000000000..c832860825
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Semicolon1.cmake
@@ -0,0 +1,14 @@
+include(ExternalData)
+set(ExternalData_URL_TEMPLATES
+ "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
+ )
+set(input Data.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/Data.txt)
+ExternalData_Expand_Arguments(Data args DATA{${input}} "a\\;b" "c;d" DATA{${input}})
+set(expect "${output};a\\;b;c;d;${output}")
+if("x${args}" STREQUAL "x${expect}")
+ message(STATUS "Data arguments correctly transformed!")
+else()
+ message(FATAL_ERROR "Data arguments transformed to:\n ${args}\n"
+ "but we expected:\n ${expect}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/Semicolon2-stdout.txt b/Tests/RunCMake/ExternalData/Semicolon2-stdout.txt
new file mode 100644
index 0000000000..361baebba4
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Semicolon2-stdout.txt
@@ -0,0 +1 @@
+-- Data arguments correctly transformed!
diff --git a/Tests/RunCMake/ExternalData/Semicolon2.cmake b/Tests/RunCMake/ExternalData/Semicolon2.cmake
new file mode 100644
index 0000000000..1a1ae5f3ff
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Semicolon2.cmake
@@ -0,0 +1,14 @@
+include(ExternalData)
+set(ExternalData_URL_TEMPLATES
+ "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
+ )
+set(input Data.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/Data.txt)
+ExternalData_Expand_Arguments(Data args "DATA{${input}};a\\;b;c;d;DATA{${input}}")
+set(expect "${output};a\\;b;c;d;${output}")
+if("x${args}" STREQUAL "x${expect}")
+ message(STATUS "Data arguments correctly transformed!")
+else()
+ message(FATAL_ERROR "Data arguments transformed to:\n ${args}\n"
+ "but we expected:\n ${expect}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/Semicolon3-stdout.txt b/Tests/RunCMake/ExternalData/Semicolon3-stdout.txt
new file mode 100644
index 0000000000..ca4a360029
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Semicolon3-stdout.txt
@@ -0,0 +1 @@
+-- Data arguments correctly not transformed!
diff --git a/Tests/RunCMake/ExternalData/Semicolon3.cmake b/Tests/RunCMake/ExternalData/Semicolon3.cmake
new file mode 100644
index 0000000000..2ae99da98e
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/Semicolon3.cmake
@@ -0,0 +1,12 @@
+include(ExternalData)
+set(ExternalData_URL_TEMPLATES
+ "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
+ )
+set(input "DATA{a;b}")
+ExternalData_Expand_Arguments(Data args "${input}")
+if("x${args}" STREQUAL "x${input}")
+ message(STATUS "Data arguments correctly not transformed!")
+else()
+ message(FATAL_ERROR "Data arguments transformed to:\n ${args}\n"
+ "but we expected:\n ${input}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/SubDirectory1-stdout.txt b/Tests/RunCMake/ExternalData/SubDirectory1-stdout.txt
new file mode 100644
index 0000000000..03924cb5b7
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/SubDirectory1-stdout.txt
@@ -0,0 +1,3 @@
+-- Data reference correctly transformed in parent dir 1!
+-- Data reference correctly transformed in parent dir 2!
+-- Data reference correctly transformed in current dir!
diff --git a/Tests/RunCMake/ExternalData/SubDirectory1.cmake b/Tests/RunCMake/ExternalData/SubDirectory1.cmake
new file mode 100644
index 0000000000..29894710ac
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/SubDirectory1.cmake
@@ -0,0 +1,5 @@
+include(ExternalData)
+set(ExternalData_URL_TEMPLATES
+ "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
+ )
+add_subdirectory(SubDirectory1)
diff --git a/Tests/RunCMake/ExternalData/SubDirectory1/CMakeLists.txt b/Tests/RunCMake/ExternalData/SubDirectory1/CMakeLists.txt
new file mode 100644
index 0000000000..881ff5c2c0
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/SubDirectory1/CMakeLists.txt
@@ -0,0 +1,29 @@
+set(input ../Data.txt)
+set(output ${CMAKE_BINARY_DIR}/Data.txt)
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Data reference correctly transformed in parent dir 1!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
+
+set(input ${CMAKE_CURRENT_SOURCE_DIR}/../Data.txt)
+set(output ${CMAKE_BINARY_DIR}/Data.txt)
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Data reference correctly transformed in parent dir 2!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
+
+set(input Data.txt)
+set(output ${CMAKE_CURRENT_BINARY_DIR}/Data.txt)
+ExternalData_Expand_Arguments(Data args DATA{${input}})
+if("x${args}" STREQUAL "x${output}")
+ message(STATUS "Data reference correctly transformed in current dir!")
+else()
+ message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
+ "but we expected:\n ${output}")
+endif()
diff --git a/Tests/RunCMake/ExternalData/SubDirectory1/Data.txt.md5 b/Tests/RunCMake/ExternalData/SubDirectory1/Data.txt.md5
new file mode 100644
index 0000000000..93b3485e94
--- /dev/null
+++ b/Tests/RunCMake/ExternalData/SubDirectory1/Data.txt.md5
@@ -0,0 +1 @@
+e8bb14af900b998b5a3df7e21dd07d58
diff --git a/Tests/RunCMake/FPHSA/BadFoundVar-result.txt b/Tests/RunCMake/FPHSA/BadFoundVar-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/BadFoundVar-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FPHSA/BadFoundVar-stderr.txt b/Tests/RunCMake/FPHSA/BadFoundVar-stderr.txt
new file mode 100644
index 0000000000..4c739d89b2
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/BadFoundVar-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error at .*/Modules/FindPackageHandleStandardArgs.cmake:[0-9]+ \(message\):
+ The argument for FOUND_VAR is "badfoundvar_FOUND", but only
+ "BadFoundVar_FOUND" and "BADFOUNDVAR_FOUND" are valid names.
+Call Stack \(most recent call first\):
+ FindBadFoundVar.cmake:5 \(find_package_handle_standard_args\)
+ BadFoundVar.cmake:3 \(find_package\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/FPHSA/BadFoundVar.cmake b/Tests/RunCMake/FPHSA/BadFoundVar.cmake
new file mode 100644
index 0000000000..07d4322e45
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/BadFoundVar.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
+
+find_package(BadFoundVar REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/CMakeLists.txt b/Tests/RunCMake/FPHSA/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/FPHSA/FindBadFoundVar.cmake b/Tests/RunCMake/FPHSA/FindBadFoundVar.cmake
new file mode 100644
index 0000000000..152df5cd87
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/FindBadFoundVar.cmake
@@ -0,0 +1,6 @@
+set(BFV_FOO TRUE)
+
+include(FindPackageHandleStandardArgs)
+
+find_package_handle_standard_args(BadFoundVar REQUIRED_VARS BFV_FOO
+ FOUND_VAR badfoundvar_FOUND )
diff --git a/Tests/RunCMake/FPHSA/FindPseudo.cmake b/Tests/RunCMake/FPHSA/FindPseudo.cmake
new file mode 100644
index 0000000000..dc3558bd4a
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/FindPseudo.cmake
@@ -0,0 +1,6 @@
+# pseudo find_module
+
+set(FOOBAR TRUE)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Pseudo REQUIRED_VARS FOOBAR VERSION_VAR Pseudo_VERSION)
diff --git a/Tests/RunCMake/FPHSA/RunCMakeTest.cmake b/Tests/RunCMake/FPHSA/RunCMakeTest.cmake
new file mode 100644
index 0000000000..bb7743c0fa
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/RunCMakeTest.cmake
@@ -0,0 +1,28 @@
+include(RunCMake)
+
+run_cmake(BadFoundVar)
+
+# The pseudo module will "find" a package with the given version. Check if the
+# version selection code in FPHSA works correctly.
+set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=1.2.3.4.5")
+run_cmake(any_version)
+
+# test EXACT mode with every subcomponent
+run_cmake(exact_1)
+run_cmake(exact_1.2)
+run_cmake(exact_1.2.3)
+run_cmake(exact_1.2.3.4)
+
+# now test every component with an invalid version
+run_cmake(exact_0)
+run_cmake(exact_2)
+run_cmake(exact_1.1)
+run_cmake(exact_1.3)
+run_cmake(exact_1.2.2)
+run_cmake(exact_1.2.4)
+run_cmake(exact_1.2.3.3)
+run_cmake(exact_1.2.3.5)
+
+# check if searching for a version 0 works
+list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=0")
+run_cmake(exact_0_matching)
diff --git a/Tests/RunCMake/FPHSA/any_version.cmake b/Tests/RunCMake/FPHSA/any_version.cmake
new file mode 100644
index 0000000000..b34a540c91
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/any_version.cmake
@@ -0,0 +1 @@
+find_package(Pseudo REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_0-result.txt b/Tests/RunCMake/FPHSA/exact_0-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_0-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FPHSA/exact_0.cmake b/Tests/RunCMake/FPHSA/exact_0.cmake
new file mode 100644
index 0000000000..432887bad0
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_0.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 0 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_0_matching.cmake b/Tests/RunCMake/FPHSA/exact_0_matching.cmake
new file mode 100644
index 0000000000..432887bad0
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_0_matching.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 0 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.1-result.txt b/Tests/RunCMake/FPHSA/exact_1.1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FPHSA/exact_1.1.cmake b/Tests/RunCMake/FPHSA/exact_1.1.cmake
new file mode 100644
index 0000000000..d967da9277
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.1.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1.1 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.2-result.txt b/Tests/RunCMake/FPHSA/exact_1.2.2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.2.cmake b/Tests/RunCMake/FPHSA/exact_1.2.2.cmake
new file mode 100644
index 0000000000..e959f610e1
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.2.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1.2.2 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.3.3-result.txt b/Tests/RunCMake/FPHSA/exact_1.2.3.3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.3.3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.3.3.cmake b/Tests/RunCMake/FPHSA/exact_1.2.3.3.cmake
new file mode 100644
index 0000000000..af53cc8da2
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.3.3.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1.2.3.3 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.3.4.cmake b/Tests/RunCMake/FPHSA/exact_1.2.3.4.cmake
new file mode 100644
index 0000000000..1e2baa64eb
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.3.4.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1.2.3.4 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.3.5-result.txt b/Tests/RunCMake/FPHSA/exact_1.2.3.5-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.3.5-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.3.5.cmake b/Tests/RunCMake/FPHSA/exact_1.2.3.5.cmake
new file mode 100644
index 0000000000..ddb0d1378a
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.3.5.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1.2.3.5 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.3.cmake b/Tests/RunCMake/FPHSA/exact_1.2.3.cmake
new file mode 100644
index 0000000000..bf9b2a316b
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.3.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1.2.3 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.4-result.txt b/Tests/RunCMake/FPHSA/exact_1.2.4-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.4-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.4.cmake b/Tests/RunCMake/FPHSA/exact_1.2.4.cmake
new file mode 100644
index 0000000000..548a07956b
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.4.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1.2.4 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.2.cmake b/Tests/RunCMake/FPHSA/exact_1.2.cmake
new file mode 100644
index 0000000000..080d96108b
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.2.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1.2 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.3-result.txt b/Tests/RunCMake/FPHSA/exact_1.3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FPHSA/exact_1.3.cmake b/Tests/RunCMake/FPHSA/exact_1.3.cmake
new file mode 100644
index 0000000000..e36b0c5680
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.3.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1.3 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_1.cmake b/Tests/RunCMake/FPHSA/exact_1.cmake
new file mode 100644
index 0000000000..adadbc4cf1
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_1.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 1 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FPHSA/exact_2-result.txt b/Tests/RunCMake/FPHSA/exact_2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FPHSA/exact_2.cmake b/Tests/RunCMake/FPHSA/exact_2.cmake
new file mode 100644
index 0000000000..55353a8b8a
--- /dev/null
+++ b/Tests/RunCMake/FPHSA/exact_2.cmake
@@ -0,0 +1 @@
+find_package(Pseudo 2 EXACT REQUIRED)
diff --git a/Tests/RunCMake/FeatureSummary/CMakeLists.txt b/Tests/RunCMake/FeatureSummary/CMakeLists.txt
new file mode 100644
index 0000000000..72abfc8099
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatAll-stdout.txt b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatAll-stdout.txt
new file mode 100644
index 0000000000..9a3f023872
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatAll-stdout.txt
@@ -0,0 +1,7 @@
+-- The following features have been enabled:
+
+ \* Foo , Foo\.
+
+-- The following features have been disabled:
+
+ \* Bar , Bar\.
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatAll.cmake b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatAll.cmake
new file mode 100644
index 0000000000..ec5ebcb5fc
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatAll.cmake
@@ -0,0 +1,9 @@
+include(FeatureSummary)
+
+set(WITH_FOO 1)
+set(WITH_BAR 0)
+
+add_feature_info(Foo WITH_FOO "Foo.")
+add_feature_info(Bar WITH_BAR "Bar.")
+
+feature_summary(WHAT ALL)
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatList-stdout.txt b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatList-stdout.txt
new file mode 100644
index 0000000000..4d8f25f5e3
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatList-stdout.txt
@@ -0,0 +1,7 @@
+-- The following features have been disabled:
+
+ \* Bar , Bar\.
+
+-- The following features have been enabled:
+
+ \* Foo , Foo\.
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatList.cmake b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatList.cmake
new file mode 100644
index 0000000000..d04ba885ab
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatList.cmake
@@ -0,0 +1,9 @@
+include(FeatureSummary)
+
+set(WITH_FOO 1)
+set(WITH_BAR 0)
+
+add_feature_info(Foo WITH_FOO "Foo.")
+add_feature_info(Bar WITH_BAR "Bar.")
+
+feature_summary(WHAT DISABLED_FEATURES ENABLED_FEATURES)
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll-result.txt b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll-stderr.txt b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll-stderr.txt
new file mode 100644
index 0000000000..18d9ebdee9
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*/Modules/FeatureSummary\.cmake:[0-9]+. \(message\):
+ The WHAT argument of FEATURE_SUMMARY\(\) contains ALL, which cannot be
+ combined with other values\.
+Call Stack \(most recent call first\):
+ FeatureSummaryWhatListAll\.cmake:[0-9]+ \(feature_summary\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll.cmake b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll.cmake
new file mode 100644
index 0000000000..1877ea5a26
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListAll.cmake
@@ -0,0 +1,9 @@
+include(FeatureSummary)
+
+set(WITH_FOO 1)
+set(WITH_BAR 0)
+
+add_feature_info(Foo WITH_FOO "Foo.")
+add_feature_info(Bar WITH_BAR "Bar.")
+
+feature_summary(WHAT ENABLED_FEATURES ALL)
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown-result.txt b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown-stderr.txt b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown-stderr.txt
new file mode 100644
index 0000000000..3ad3750309
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*/Modules/FeatureSummary\.cmake:[0-9]+. \(message\):
+ The WHAT argument of FEATURE_SUMMARY\(\) contains FOO, which is not a valid
+ value\.
+Call Stack \(most recent call first\):
+ FeatureSummaryWhatListUnknown\.cmake:[0-9]+ \(feature_summary\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown.cmake b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown.cmake
new file mode 100644
index 0000000000..46088d4179
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatListUnknown.cmake
@@ -0,0 +1,9 @@
+include(FeatureSummary)
+
+set(WITH_FOO 1)
+set(WITH_BAR 0)
+
+add_feature_info(Foo WITH_FOO "Foo.")
+add_feature_info(Bar WITH_BAR "Bar.")
+
+feature_summary(WHAT ENABLED_FEATURES FOO)
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingle-stdout.txt b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingle-stdout.txt
new file mode 100644
index 0000000000..240632dda9
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingle-stdout.txt
@@ -0,0 +1 @@
+ \* Foo , Foo\.
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingle.cmake b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingle.cmake
new file mode 100644
index 0000000000..593dfb6a1c
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingle.cmake
@@ -0,0 +1,9 @@
+include(FeatureSummary)
+
+set(WITH_FOO 1)
+set(WITH_BAR 0)
+
+add_feature_info(Foo WITH_FOO "Foo.")
+add_feature_info(Bar WITH_BAR "Bar.")
+
+feature_summary(WHAT ENABLED_FEATURES)
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown-result.txt b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown-stderr.txt b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown-stderr.txt
new file mode 100644
index 0000000000..c78853c751
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*/Modules/FeatureSummary\.cmake:[0-9]+. \(message\):
+ The WHAT argument of FEATURE_SUMMARY\(\) contains FOO, which is not a valid
+ value\.
+Call Stack \(most recent call first\):
+ FeatureSummaryWhatSingleUnknown\.cmake:[0-9]+ \(feature_summary\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown.cmake b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown.cmake
new file mode 100644
index 0000000000..c2d6d2ee43
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/FeatureSummaryWhatSingleUnknown.cmake
@@ -0,0 +1,9 @@
+include(FeatureSummary)
+
+set(WITH_FOO 1)
+set(WITH_BAR 0)
+
+add_feature_info(Foo WITH_FOO "Foo.")
+add_feature_info(Bar WITH_BAR "Bar.")
+
+feature_summary(WHAT FOO)
diff --git a/Tests/RunCMake/FeatureSummary/RunCMakeTest.cmake b/Tests/RunCMake/FeatureSummary/RunCMakeTest.cmake
new file mode 100644
index 0000000000..1417338ed1
--- /dev/null
+++ b/Tests/RunCMake/FeatureSummary/RunCMakeTest.cmake
@@ -0,0 +1,8 @@
+include(RunCMake)
+
+run_cmake(FeatureSummaryWhatAll)
+run_cmake(FeatureSummaryWhatSingle)
+run_cmake(FeatureSummaryWhatSingleUnknown)
+run_cmake(FeatureSummaryWhatList)
+run_cmake(FeatureSummaryWhatListUnknown)
+run_cmake(FeatureSummaryWhatListAll)
diff --git a/Tests/RunCMake/File_Generate/BadCondition-result.txt b/Tests/RunCMake/File_Generate/BadCondition-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/BadCondition-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/BadCondition-stderr.txt b/Tests/RunCMake/File_Generate/BadCondition-stderr.txt
new file mode 100644
index 0000000000..bab8368438
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/BadCondition-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ Evaluation file condition \"\$<1:Bad>\" did not evaluate to valid content.
+ Got \"Bad\".
diff --git a/Tests/RunCMake/File_Generate/BadCondition.cmake b/Tests/RunCMake/File_Generate/BadCondition.cmake
new file mode 100644
index 0000000000..82ad672adc
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/BadCondition.cmake
@@ -0,0 +1,5 @@
+
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ CONDITION $<1:Bad>
+)
diff --git a/Tests/RunCMake/File_Generate/CMakeLists.txt b/Tests/RunCMake/File_Generate/CMakeLists.txt
new file mode 100644
index 0000000000..bc0cf5d164
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+if(NOT TEST_FILE)
+ set(TEST_FILE ${RunCMake_TEST}.cmake)
+endif()
+include(${TEST_FILE})
diff --git a/Tests/RunCMake/File_Generate/CommandConflict-result.txt b/Tests/RunCMake/File_Generate/CommandConflict-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CommandConflict-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/CommandConflict-stderr.txt b/Tests/RunCMake/File_Generate/CommandConflict-stderr.txt
new file mode 100644
index 0000000000..da97ba4769
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CommandConflict-stderr.txt
@@ -0,0 +1 @@
+CMake Error: File to be generated by multiple different commands: .*CommandConflict-build/output_.*.txt
diff --git a/Tests/RunCMake/File_Generate/CommandConflict.cmake b/Tests/RunCMake/File_Generate/CommandConflict.cmake
new file mode 100644
index 0000000000..d57bc1284e
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CommandConflict.cmake
@@ -0,0 +1,9 @@
+
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output_$<CONFIGURATION>.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ CONDITION $<CONFIG:$<CONFIGURATION>>
+)
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output_$<CONFIGURATION>.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ CONDITION $<CONFIG:$<CONFIGURATION>>
+)
diff --git a/Tests/RunCMake/File_Generate/DebugEvaluate.cmake b/Tests/RunCMake/File_Generate/DebugEvaluate.cmake
new file mode 100644
index 0000000000..1fa9b62bbc
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/DebugEvaluate.cmake
@@ -0,0 +1,5 @@
+
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ CONDITION $<CONFIG:Debug>
+)
diff --git a/Tests/RunCMake/File_Generate/EmptyCondition1-result.txt b/Tests/RunCMake/File_Generate/EmptyCondition1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/EmptyCondition1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/EmptyCondition1-stderr.txt b/Tests/RunCMake/File_Generate/EmptyCondition1-stderr.txt
new file mode 100644
index 0000000000..e823b25dd8
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/EmptyCondition1-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at EmptyCondition1.cmake:2 \(file\):
+ file Incorrect arguments to GENERATE subcommand.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/EmptyCondition1.cmake b/Tests/RunCMake/File_Generate/EmptyCondition1.cmake
new file mode 100644
index 0000000000..8574a5f7dc
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/EmptyCondition1.cmake
@@ -0,0 +1,5 @@
+
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ CONDITION
+)
diff --git a/Tests/RunCMake/File_Generate/EmptyCondition2-result.txt b/Tests/RunCMake/File_Generate/EmptyCondition2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/EmptyCondition2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/EmptyCondition2-stderr.txt b/Tests/RunCMake/File_Generate/EmptyCondition2-stderr.txt
new file mode 100644
index 0000000000..b042946f3f
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/EmptyCondition2-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at EmptyCondition2.cmake:2 \(file\):
+ file CONDITION of sub-command GENERATE must not be empty if specified.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/EmptyCondition2.cmake b/Tests/RunCMake/File_Generate/EmptyCondition2.cmake
new file mode 100644
index 0000000000..626bfb4c4d
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/EmptyCondition2.cmake
@@ -0,0 +1,5 @@
+
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ CONDITION ""
+)
diff --git a/Tests/RunCMake/File_Generate/OutputConflict-result.txt b/Tests/RunCMake/File_Generate/OutputConflict-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/OutputConflict-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/OutputConflict-stderr.txt b/Tests/RunCMake/File_Generate/OutputConflict-stderr.txt
new file mode 100644
index 0000000000..dbd39de502
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/OutputConflict-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error in CMakeLists.txt:
+ Evaluation file to be written multiple times for different configurations
+ with different content:
+
+ .*output.txt
diff --git a/Tests/RunCMake/File_Generate/OutputConflict.cmake b/Tests/RunCMake/File_Generate/OutputConflict.cmake
new file mode 100644
index 0000000000..7f3e8c7c75
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/OutputConflict.cmake
@@ -0,0 +1,4 @@
+
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+)
diff --git a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
new file mode 100644
index 0000000000..dee0692628
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
@@ -0,0 +1,37 @@
+include(RunCMake)
+
+run_cmake(CommandConflict)
+if("${RunCMake_GENERATOR}" MATCHES "Visual Studio|Xcode" AND NOT XCODE_BELOW_2)
+ run_cmake(OutputConflict)
+endif()
+run_cmake(EmptyCondition1)
+run_cmake(EmptyCondition2)
+run_cmake(BadCondition)
+run_cmake(DebugEvaluate)
+
+set(timeformat "%Y%j%H%M%S")
+
+file(REMOVE "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt")
+set(RunCMake_TEST_OPTIONS "-DTEST_FILE=WriteIfDifferent.cmake")
+set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/WriteIfDifferent-build")
+run_cmake(WriteIfDifferent-prepare)
+unset(RunCMake_TEST_OPTIONS)
+unset(RunCMake_TEST_BINARY_DIR)
+file(TIMESTAMP "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt" timestamp ${timeformat})
+if(NOT timestamp)
+ message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt\"")
+endif()
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
+
+set(RunCMake_TEST_NO_CLEAN ON)
+run_cmake(WriteIfDifferent)
+file(TIMESTAMP "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt" timestamp_after ${timeformat})
+if(NOT timestamp_after)
+ message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt\"")
+endif()
+unset(RunCMake_TEST_NO_CLEAN)
+
+if (NOT timestamp_after STREQUAL timestamp)
+ message(SEND_ERROR "WriteIfDifferent changed output file.")
+endif()
diff --git a/Tests/RunCMake/File_Generate/WriteIfDifferent-result.txt b/Tests/RunCMake/File_Generate/WriteIfDifferent-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/WriteIfDifferent-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/File_Generate/WriteIfDifferent-stderr.txt b/Tests/RunCMake/File_Generate/WriteIfDifferent-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/WriteIfDifferent-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake b/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake
new file mode 100644
index 0000000000..d1d832a111
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake
@@ -0,0 +1,5 @@
+
+file(GENERATE
+ OUTPUT output_file.txt
+ CONTENT "123"
+)
diff --git a/Tests/RunCMake/File_Generate/input.txt b/Tests/RunCMake/File_Generate/input.txt
new file mode 100644
index 0000000000..3db429d216
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/input.txt
@@ -0,0 +1 @@
+Some $<$<CONFIG:Debug>:conflicting> $<$<NOT:$<CONFIG:Debug>>:content>
diff --git a/Tests/RunCMake/FindPkgConfig/CMakeLists.txt b/Tests/RunCMake/FindPkgConfig/CMakeLists.txt
new file mode 100644
index 0000000000..72abfc8099
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_NO_PKGCONFIG_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_NO_PKGCONFIG_PATH.cmake
new file mode 100644
index 0000000000..89ce4c6d86
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_NO_PKGCONFIG_PATH.cmake
@@ -0,0 +1,41 @@
+# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
+enable_language(C)
+
+# Prepare environment and variables
+set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH FALSE)
+set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pc-foo")
+if(WIN32)
+ set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}\\dummy-pkg-config.bat")
+ set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}\\pc-bar;X:\\this\\directory\\should\\not\\exist\\in\\the\\filesystem")
+ set(ENV{PKG_CONFIG_PATH} "C:\\baz")
+else()
+ set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/dummy-pkg-config.sh")
+ set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/pc-bar:/this/directory/should/not/exist/in/the/filesystem")
+ set(ENV{PKG_CONFIG_PATH} "/baz")
+endif()
+
+
+find_package(PkgConfig)
+
+if(WIN32)
+ set(expected_path "C:\\baz")
+else()
+ set(expected_path "/baz")
+endif()
+
+
+pkg_check_modules(FOO "${expected_path}")
+
+if(NOT FOO_FOUND)
+ message(FATAL_ERROR "Expected PKG_CONFIG_PATH: \"${expected_path}\".")
+endif()
+
+
+
+set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
+
+pkg_check_modules(BAR "${expected_path}" NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH)
+
+if(NOT BAR_FOUND)
+ message(FATAL_ERROR "Expected PKG_CONFIG_PATH: \"${expected_path}\".")
+endif()
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake
new file mode 100644
index 0000000000..c903279554
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake
@@ -0,0 +1,51 @@
+# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
+enable_language(C)
+
+# Prepare environment and variables
+set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
+set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pc-foo")
+if(WIN32)
+ set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}\\dummy-pkg-config.bat")
+ set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}\\pc-bar;X:\\this\\directory\\should\\not\\exist\\in\\the\\filesystem")
+ set(ENV{PKG_CONFIG_PATH} "C:\\baz")
+else()
+ set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/dummy-pkg-config.sh")
+ set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/pc-bar:/this/directory/should/not/exist/in/the/filesystem")
+ set(ENV{PKG_CONFIG_PATH} "/baz")
+endif()
+
+
+find_package(PkgConfig)
+
+
+if(NOT DEFINED CMAKE_SYSTEM_NAME
+ OR (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$"
+ AND NOT CMAKE_CROSSCOMPILING))
+ if(EXISTS "/etc/debian_version") # is this a debian system ?
+ if(CMAKE_LIBRARY_ARCHITECTURE MATCHES "^(i386-linux-gnu|x86_64-linux-gnu)$")
+ # Cannot create directories for all the existing architectures...
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
+ else()
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
+ endif()
+ else()
+ # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
+ get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
+ if(uselib64)
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
+ endif()
+ endif()
+else()
+ if(WIN32)
+ set(expected_path "C:\\baz;${CMAKE_CURRENT_SOURCE_DIR}\\pc-foo\\lib\\pkgconfig;${CMAKE_CURRENT_SOURCE_DIR}\\pc-bar\\lib\\pkgconfig")
+ else()
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
+ endif()
+endif()
+
+
+pkg_check_modules(FOO "${expected_path}")
+
+if(NOT FOO_FOUND)
+ message(FATAL_ERROR "Expected PKG_CONFIG_PATH: \"${expected_path}\".")
+endif()
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake
new file mode 100644
index 0000000000..a52bcbf813
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake
@@ -0,0 +1,51 @@
+# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
+enable_language(C)
+
+# Prepare environment and variables
+set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
+set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pc-foo")
+if(WIN32)
+ set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}\\dummy-pkg-config.bat")
+ set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}\\pc-bar;X:\\this\\directory\\should\\not\\exist\\in\\the\\filesystem")
+ set(ENV{PKG_CONFIG_PATH} "C:\\baz")
+else()
+ set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/dummy-pkg-config.sh")
+ set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/pc-bar:/this/directory/should/not/exist/in/the/filesystem")
+ set(ENV{PKG_CONFIG_PATH} "/baz")
+endif()
+
+
+find_package(PkgConfig)
+
+
+if(NOT DEFINED CMAKE_SYSTEM_NAME
+ OR (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$"
+ AND NOT CMAKE_CROSSCOMPILING))
+ if(EXISTS "/etc/debian_version") # is this a debian system ?
+ if(CMAKE_LIBRARY_ARCHITECTURE MATCHES "^(i386-linux-gnu|x86_64-linux-gnu)$")
+ # Cannot create directories for all the existing architectures...
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig")
+ else()
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig")
+ endif()
+ else()
+ # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
+ get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
+ if(uselib64)
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig")
+ endif()
+ endif()
+else()
+ if(WIN32)
+ set(expected_path "C:\\baz;${CMAKE_CURRENT_SOURCE_DIR}\\pc-foo\\lib\\pkgconfig")
+ else()
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig")
+ endif()
+endif()
+
+
+pkg_check_modules(FOO "${expected_path}" NO_CMAKE_ENVIRONMENT_PATH)
+
+if(NOT FOO_FOUND)
+ message(FATAL_ERROR "Expected PKG_CONFIG_PATH: \"${expected_path}\".")
+endif()
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake
new file mode 100644
index 0000000000..2fabe5b430
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake
@@ -0,0 +1,51 @@
+# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
+enable_language(C)
+
+# Prepare environment and variables
+set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
+set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pc-foo")
+if(WIN32)
+ set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}\\dummy-pkg-config.bat")
+ set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}\\pc-bar;X:\\this\\directory\\should\\not\\exist\\in\\the\\filesystem")
+ set(ENV{PKG_CONFIG_PATH} "C:\\baz")
+else()
+ set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/dummy-pkg-config.sh")
+ set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/pc-bar:/this/directory/should/not/exist/in/the/filesystem")
+ set(ENV{PKG_CONFIG_PATH} "/baz")
+endif()
+
+
+find_package(PkgConfig)
+
+
+if(NOT DEFINED CMAKE_SYSTEM_NAME
+ OR (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$"
+ AND NOT CMAKE_CROSSCOMPILING))
+ if(EXISTS "/etc/debian_version") # is this a debian system ?
+ if(CMAKE_LIBRARY_ARCHITECTURE MATCHES "^(i386-linux-gnu|x86_64-linux-gnu)$")
+ # Cannot create directories for all the existing architectures...
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
+ else()
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
+ endif()
+ else()
+ # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
+ get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
+ if(uselib64)
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
+ endif()
+ endif()
+else()
+ if(WIN32)
+ set(expected_path "C:\\baz;${CMAKE_CURRENT_SOURCE_DIR}\\pc-bar\\lib\\pkgconfig")
+ else()
+ set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
+ endif()
+endif()
+
+
+pkg_check_modules(FOO "${expected_path}" NO_CMAKE_PATH)
+
+if(NOT FOO_FOUND)
+ message(FATAL_ERROR "Expected PKG_CONFIG_PATH: \"${expected_path}\".")
+endif()
diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
new file mode 100644
index 0000000000..bca93bb644
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
@@ -0,0 +1,6 @@
+include(RunCMake)
+
+run_cmake(FindPkgConfig_NO_PKGCONFIG_PATH)
+run_cmake(FindPkgConfig_PKGCONFIG_PATH)
+run_cmake(FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH)
+run_cmake(FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH)
diff --git a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat
new file mode 100755
index 0000000000..f2f86b0a6c
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat
@@ -0,0 +1,18 @@
+@ECHO OFF
+IF "%1"=="" (
+ EXIT /B 255
+)
+IF "%1"=="--version" (
+ ECHO 0.0-cmake-dummy
+ EXIT /B 0
+)
+
+IF "%1"=="--exists" (
+ SHIFT
+ ECHO Expected: %*
+ ECHO Found: %PKG_CONFIG_PATH%
+ IF NOT "%*"=="%PKG_CONFIG_PATH%" (
+ EXIT /B 1
+ )
+)
+EXIT /B 0
diff --git a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh
new file mode 100755
index 0000000000..852e841ad6
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# This is a replacement for pkg-config that compares the string passed
+# to the --exists argument with the PKG_CONFIG_PATH environment variable
+# and returns 1 if they are different.
+
+case $1 in
+ --version)
+ echo "0.0-cmake-dummy"
+ ;;
+ --exists)
+ shift
+ echo "Expected: $@"
+ echo "Found: ${PKG_CONFIG_PATH}"
+ [ "$@" = "${PKG_CONFIG_PATH}" ] || exit 1
+ ;;
+ *)
+ exit 255
+ ;;
+esac
diff --git a/Tests/RunCMake/FindPkgConfig/pc-bar/lib/i386-linux-gnu/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-bar/lib/i386-linux-gnu/pkgconfig/.placeholder
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/pc-bar/lib/i386-linux-gnu/pkgconfig/.placeholder
diff --git a/Tests/RunCMake/FindPkgConfig/pc-bar/lib/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-bar/lib/pkgconfig/.placeholder
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/pc-bar/lib/pkgconfig/.placeholder
diff --git a/Tests/RunCMake/FindPkgConfig/pc-bar/lib/x86_64-linux-gnu/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-bar/lib/x86_64-linux-gnu/pkgconfig/.placeholder
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/pc-bar/lib/x86_64-linux-gnu/pkgconfig/.placeholder
diff --git a/Tests/RunCMake/FindPkgConfig/pc-bar/lib64/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-bar/lib64/pkgconfig/.placeholder
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/pc-bar/lib64/pkgconfig/.placeholder
diff --git a/Tests/RunCMake/FindPkgConfig/pc-foo/lib/i386-linux-gnu/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-foo/lib/i386-linux-gnu/pkgconfig/.placeholder
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/pc-foo/lib/i386-linux-gnu/pkgconfig/.placeholder
diff --git a/Tests/RunCMake/FindPkgConfig/pc-foo/lib/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-foo/lib/pkgconfig/.placeholder
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/pc-foo/lib/pkgconfig/.placeholder
diff --git a/Tests/RunCMake/FindPkgConfig/pc-foo/lib/x86_64-linux-gnu/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-foo/lib/x86_64-linux-gnu/pkgconfig/.placeholder
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/pc-foo/lib/x86_64-linux-gnu/pkgconfig/.placeholder
diff --git a/Tests/RunCMake/FindPkgConfig/pc-foo/lib64/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-foo/lib64/pkgconfig/.placeholder
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/pc-foo/lib64/pkgconfig/.placeholder
diff --git a/Tests/RunCMake/GeneratorExpression/BadAND-result.txt b/Tests/RunCMake/GeneratorExpression/BadAND-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadAND-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadAND-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadAND-stderr.txt
new file mode 100644
index 0000000000..0e48ba423b
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadAND-stderr.txt
@@ -0,0 +1,53 @@
+CMake Error at BadAND.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<AND>
+
+ \$<AND> expression requires at least one parameter.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadAND.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<AND:>
+
+ Parameters to \$<AND> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadAND.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<AND:,>
+
+ Parameters to \$<AND> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadAND.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<AND:01>
+
+ Parameters to \$<AND> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadAND.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<AND:nothing>
+
+ Parameters to \$<AND> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadAND.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<AND:1,nothing>
+
+ Parameters to \$<AND> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/GeneratorExpression/BadAND.cmake b/Tests/RunCMake/GeneratorExpression/BadAND.cmake
new file mode 100644
index 0000000000..8a7993f53d
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadAND.cmake
@@ -0,0 +1,8 @@
+add_custom_target(check ALL COMMAND check
+ $<AND>
+ $<AND:>
+ $<AND:,>
+ $<AND:01>
+ $<AND:nothing>
+ $<AND:1,nothing>
+ VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/BadCONFIG-result.txt b/Tests/RunCMake/GeneratorExpression/BadCONFIG-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadCONFIG-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt
new file mode 100644
index 0000000000..964ea4d4e9
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt
@@ -0,0 +1,35 @@
+CMake Error at BadCONFIG.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<CONFIG:.>
+
+ Expression syntax not recognized.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadCONFIG.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<CONFIG:Foo,Bar>
+
+ \$<CONFIG> expression requires one or zero parameters.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadCONFIG.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<CONFIG:Foo-Bar>
+
+ Expression syntax not recognized.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadCONFIG.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<CONFIG:Foo-Nested>
+
+ Expression syntax not recognized.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake b/Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake
new file mode 100644
index 0000000000..5c22aaabe4
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake
@@ -0,0 +1,6 @@
+add_custom_target(check ALL COMMAND check
+ $<CONFIG:.>
+ $<CONFIG:Foo,Bar>
+ $<CONFIG:Foo-Bar>
+ $<$<CONFIG:Foo-Nested>:foo>
+ VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/BadInstallPrefix-result.txt b/Tests/RunCMake/GeneratorExpression/BadInstallPrefix-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadInstallPrefix-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadInstallPrefix-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadInstallPrefix-stderr.txt
new file mode 100644
index 0000000000..271eb6e6fb
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadInstallPrefix-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at BadInstallPrefix.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<INSTALL_PREFIX>
+
+ INSTALL_PREFIX is a marker for install\(EXPORT\) only. It should never be
+ evaluated.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/BadInstallPrefix.cmake b/Tests/RunCMake/GeneratorExpression/BadInstallPrefix.cmake
new file mode 100644
index 0000000000..fcfc3ebaae
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadInstallPrefix.cmake
@@ -0,0 +1,3 @@
+add_custom_target(check ALL COMMAND check
+ $<INSTALL_PREFIX>/include
+ VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/BadNOT-result.txt b/Tests/RunCMake/GeneratorExpression/BadNOT-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadNOT-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt
new file mode 100644
index 0000000000..e5e628c304
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt
@@ -0,0 +1,52 @@
+CMake Error at BadNOT.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<NOT>
+
+ \$<NOT> expression requires exactly one parameter.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++CMake Error at BadNOT.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<NOT:>
+
+ \$<NOT> parameter must resolve to exactly one '0' or '1' value.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadNOT.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<NOT:,>
+
+ \$<NOT> expression requires exactly one parameter.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadNOT.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<NOT:0,1>
+
+ \$<NOT> expression requires exactly one parameter.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadNOT.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<NOT:01>
+
+ \$<NOT> parameter must resolve to exactly one '0' or '1' value.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadNOT.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<NOT:nothing>
+
+ \$<NOT> parameter must resolve to exactly one '0' or '1' value.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/GeneratorExpression/BadNOT.cmake b/Tests/RunCMake/GeneratorExpression/BadNOT.cmake
new file mode 100644
index 0000000000..c2dada3c20
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadNOT.cmake
@@ -0,0 +1,8 @@
+add_custom_target(check ALL COMMAND check
+ $<NOT>
+ $<NOT:>
+ $<NOT:,>
+ $<NOT:0,1>
+ $<NOT:01>
+ $<NOT:nothing>
+ VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/BadOR-result.txt b/Tests/RunCMake/GeneratorExpression/BadOR-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadOR-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadOR-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadOR-stderr.txt
new file mode 100644
index 0000000000..eb263286e7
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadOR-stderr.txt
@@ -0,0 +1,53 @@
+CMake Error at BadOR.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<OR>
+
+ \$<OR> expression requires at least one parameter.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadOR.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<OR:>
+
+ Parameters to \$<OR> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadOR.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<OR:,>
+
+ Parameters to \$<OR> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadOR.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<OR:01>
+
+ Parameters to \$<OR> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadOR.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<OR:nothing>
+
+ Parameters to \$<OR> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadOR.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<OR:0,nothing>
+
+ Parameters to \$<OR> must resolve to either '0' or '1'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/GeneratorExpression/BadOR.cmake b/Tests/RunCMake/GeneratorExpression/BadOR.cmake
new file mode 100644
index 0000000000..c0309da258
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadOR.cmake
@@ -0,0 +1,8 @@
+add_custom_target(check ALL COMMAND check
+ $<OR>
+ $<OR:>
+ $<OR:,>
+ $<OR:01>
+ $<OR:nothing>
+ $<OR:0,nothing>
+ VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/BadStrEqual-result.txt b/Tests/RunCMake/GeneratorExpression/BadStrEqual-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadStrEqual-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt
new file mode 100644
index 0000000000..dd0d931bea
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt
@@ -0,0 +1,38 @@
+CMake Error at BadStrEqual.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<STREQUAL>
+
+ \$<STREQUAL> expression requires 2 comma separated parameters, but got 0
+ instead.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++CMake Error at BadStrEqual.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<STREQUAL:>
+
+ \$<STREQUAL> expression requires 2 comma separated parameters, but got 1
+ instead.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadStrEqual.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<STREQUAL:,,>
+
+ \$<STREQUAL> expression requires 2 comma separated parameters, but got 3
+ instead.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadStrEqual.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<STREQUAL:something,,>
+
+ \$<STREQUAL> expression requires 2 comma separated parameters, but got 3
+ instead.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/GeneratorExpression/BadStrEqual.cmake b/Tests/RunCMake/GeneratorExpression/BadStrEqual.cmake
new file mode 100644
index 0000000000..56eb458531
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadStrEqual.cmake
@@ -0,0 +1,6 @@
+add_custom_target(check ALL COMMAND check
+ $<STREQUAL>
+ $<STREQUAL:>
+ $<STREQUAL:,,>
+ $<STREQUAL:something,,>
+ VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/BadTargetName-result.txt b/Tests/RunCMake/GeneratorExpression/BadTargetName-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadTargetName-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadTargetName-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadTargetName-stderr.txt
new file mode 100644
index 0000000000..969393acc6
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadTargetName-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadTargetName.cmake:1 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<TARGET_NAME:\$<1:tgt>>
+
+ \$<TARGET_NAME> expression requires literal input.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/GeneratorExpression/BadTargetName.cmake b/Tests/RunCMake/GeneratorExpression/BadTargetName.cmake
new file mode 100644
index 0000000000..e125cab422
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadTargetName.cmake
@@ -0,0 +1,3 @@
+add_custom_target(check ALL COMMAND check
+ $<TARGET_NAME:$<1:tgt>>
+ VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-result.txt b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-stderr.txt
new file mode 100644
index 0000000000..533d38cef7
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-stderr.txt
@@ -0,0 +1,26 @@
+CMake Error at BadTargetTypeObject.cmake:3 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<TARGET_FILE:objlib>
+
+ Target "objlib" is not an executable or library.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadTargetTypeObject.cmake:3 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<TARGET_SONAME_FILE:objlib>
+
+ Target "objlib" is not an executable or library.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadTargetTypeObject.cmake:3 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<TARGET_LINKER_FILE:objlib>
+
+ Target "objlib" is not an executable or library.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject.cmake b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject.cmake
new file mode 100644
index 0000000000..c47ee2bec4
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject.cmake
@@ -0,0 +1,7 @@
+enable_language(C)
+add_library(objlib OBJECT empty.c)
+add_custom_target(check ALL COMMAND echo
+ $<TARGET_FILE:objlib>
+ $<TARGET_SONAME_FILE:objlib>
+ $<TARGET_LINKER_FILE:objlib>
+ )
diff --git a/Tests/RunCMake/GeneratorExpression/BadZero-result.txt b/Tests/RunCMake/GeneratorExpression/BadZero-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadZero-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt
new file mode 100644
index 0000000000..40db4ae888
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt
@@ -0,0 +1,17 @@
+CMake Error at BadZero.cmake:2 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<0>
+
+ \$<0> expression requires a parameter.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at BadZero.cmake:2 \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<0,>
+
+ Expression did not evaluate to a known generator expression
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/BadZero.cmake b/Tests/RunCMake/GeneratorExpression/BadZero.cmake
new file mode 100644
index 0000000000..559a9fa3dd
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadZero.cmake
@@ -0,0 +1,5 @@
+
+add_custom_target(check ALL COMMAND check
+ $<0>
+ $<0,>
+ VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/CMP0044-WARN-result.txt b/Tests/RunCMake/GeneratorExpression/CMP0044-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/CMP0044-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/GeneratorExpression/CMP0044-WARN-stderr.txt b/Tests/RunCMake/GeneratorExpression/CMP0044-WARN-stderr.txt
new file mode 100644
index 0000000000..2079c125cd
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/CMP0044-WARN-stderr.txt
@@ -0,0 +1,7 @@
+CMake Warning \(dev\) at CMP0044-WARN.cmake:13 \(target_compile_definitions\):
+ Policy CMP0044 is not set: Case sensitive <LANG>_COMPILER_ID generator
+ expressions. Run "cmake --help-policy CMP0044" for policy details. Use
+ the cmake_policy command to set the policy and suppress this 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/GeneratorExpression/CMP0044-WARN.cmake b/Tests/RunCMake/GeneratorExpression/CMP0044-WARN.cmake
new file mode 100644
index 0000000000..d5b85c9361
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/CMP0044-WARN.cmake
@@ -0,0 +1,17 @@
+
+project(CMP0044-WARN)
+
+string(TOLOWER ${CMAKE_C_COMPILER_ID} lc_test)
+if (lc_test STREQUAL CMAKE_C_COMPILER_ID)
+ string(TOUPPER ${CMAKE_C_COMPILER_ID} lc_test)
+ if (lc_test STREQUAL CMAKE_C_COMPILER_ID)
+ message(SEND_ERROR "Try harder.")
+ endif()
+endif()
+
+add_library(cmp0044-check empty.c)
+target_compile_definitions(cmp0044-check
+ PRIVATE
+ Result=$<C_COMPILER_ID:${lc_test}>
+ Type_Is_${CMP0044_TYPE}
+)
diff --git a/Tests/RunCMake/GeneratorExpression/CMakeLists.txt b/Tests/RunCMake/GeneratorExpression/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE-stderr.txt
new file mode 100644
index 0000000000..831edadcf2
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at NonValidCompiler-TARGET_PDB_FILE.cmake:6 \(file\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PDB_FILE:empty>
+
+ TARGET_PDB_FILE is not supported by the target linker.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE.cmake b/Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE.cmake
new file mode 100644
index 0000000000..84a2b2e8b2
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidCompiler-TARGET_PDB_FILE.cmake
@@ -0,0 +1,9 @@
+
+enable_language(C)
+
+add_library(empty STATIC empty.c)
+
+file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
+ CONTENT "[$<TARGET_PDB_FILE:empty>]"
+)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt
new file mode 100644
index 0000000000..dd7a18304d
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at NonValidTarget-CXX_COMPILER_ID.cmake:4 \(add_custom_command\):
+ Error evaluating generator expression:
+
+ \$<CXX_COMPILER_ID>
+
+ \$<CXX_COMPILER_ID> may only be used with binary targets. It may not be
+ used with add_custom_command or add_custom_target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake
new file mode 100644
index 0000000000..7dd38da4a1
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<CXX_COMPILER_ID>.cpp"
+)
+
+add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt
new file mode 100644
index 0000000000..d4a064af1e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at NonValidTarget-CXX_COMPILER_VERSION.cmake:4 \(add_custom_command\):
+ Error evaluating generator expression:
+
+ \$<CXX_COMPILER_VERSION>
+
+ \$<CXX_COMPILER_VERSION> may only be used with binary targets. It may not
+ be used with add_custom_command or add_custom_target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake
new file mode 100644
index 0000000000..1afb2b56f4
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<CXX_COMPILER_VERSION>.cpp"
+)
+
+add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt
new file mode 100644
index 0000000000..b8e53ed91d
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at NonValidTarget-C_COMPILER_ID.cmake:4 \(add_custom_command\):
+ Error evaluating generator expression:
+
+ \$<C_COMPILER_ID>
+
+ \$<C_COMPILER_ID> may only be used with binary targets. It may not be used
+ with add_custom_command or add_custom_target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake
new file mode 100644
index 0000000000..2d92ee39e2
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<C_COMPILER_ID>.cpp"
+)
+
+add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt
new file mode 100644
index 0000000000..551efe9634
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at NonValidTarget-C_COMPILER_VERSION.cmake:4 \(add_custom_command\):
+ Error evaluating generator expression:
+
+ \$<C_COMPILER_VERSION>
+
+ \$<C_COMPILER_VERSION> may only be used with binary targets. It may not be
+ used with add_custom_command or add_custom_target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake
new file mode 100644
index 0000000000..9b8a531502
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<C_COMPILER_VERSION>.cpp"
+)
+
+add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE-stderr.txt
new file mode 100644
index 0000000000..e5f21e2e35
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at NonValidTarget-TARGET_PDB_FILE.cmake:6 \(file\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PDB_FILE:empty>
+
+ TARGET_PDB_FILE is allowed only for targets with linker created artifacts.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE.cmake
new file mode 100644
index 0000000000..84a2b2e8b2
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PDB_FILE.cmake
@@ -0,0 +1,9 @@
+
+enable_language(C)
+
+add_library(empty STATIC empty.c)
+
+file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
+ CONTENT "[$<TARGET_PDB_FILE:empty>]"
+)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt
new file mode 100644
index 0000000000..0e87538c69
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at NonValidTarget-TARGET_POLICY.cmake:4 \(add_custom_command\):
+ Error evaluating generator expression:
+
+ \$<TARGET_POLICY:CMP0004>
+
+ \$<TARGET_POLICY:prop> may only be used with binary targets. It may not be
+ used with add_custom_command or add_custom_target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake
new file mode 100644
index 0000000000..10b37b5a4b
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<TARGET_POLICY:CMP0004>.cpp"
+)
+
+add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt
new file mode 100644
index 0000000000..08ad3c2d83
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt
@@ -0,0 +1,11 @@
+CMake Error at NonValidTarget-TARGET_PROPERTY.cmake:4 \(add_custom_command\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:NotAProperty>
+
+ \$<TARGET_PROPERTY:prop> may only be used with binary targets. It may not
+ be used with add_custom_command or add_custom_target. Specify the target
+ to read a property from using the \$<TARGET_PROPERTY:tgt,prop> signature
+ instead.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake
new file mode 100644
index 0000000000..64abc5f905
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<TARGET_PROPERTY:NotAProperty>.cpp"
+)
+
+add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
new file mode 100644
index 0000000000..6c32393fc8
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
@@ -0,0 +1,25 @@
+include(RunCMake)
+
+run_cmake(BadCONFIG)
+run_cmake(BadOR)
+run_cmake(BadAND)
+run_cmake(BadNOT)
+run_cmake(BadStrEqual)
+run_cmake(BadZero)
+run_cmake(BadTargetName)
+run_cmake(BadTargetTypeObject)
+run_cmake(BadInstallPrefix)
+run_cmake(CMP0044-WARN)
+run_cmake(NonValidTarget-C_COMPILER_ID)
+run_cmake(NonValidTarget-CXX_COMPILER_ID)
+run_cmake(NonValidTarget-C_COMPILER_VERSION)
+run_cmake(NonValidTarget-CXX_COMPILER_VERSION)
+run_cmake(NonValidTarget-TARGET_PROPERTY)
+run_cmake(NonValidTarget-TARGET_POLICY)
+
+if(LINKER_SUPPORTS_PDB)
+ run_cmake(NonValidTarget-TARGET_PDB_FILE)
+ run_cmake(ValidTarget-TARGET_PDB_FILE)
+else()
+ run_cmake(NonValidCompiler-TARGET_PDB_FILE)
+endif()
diff --git a/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE-check.cmake b/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE-check.cmake
new file mode 100644
index 0000000000..748d14f85a
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE-check.cmake
@@ -0,0 +1,17 @@
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/test.txt TEST_TXT)
+
+list(GET TEST_TXT 0 PDB_PATH)
+list(GET TEST_TXT 1 PDB_NAME)
+list(GET TEST_TXT 2 PDB_DIR)
+
+if(NOT PDB_PATH MATCHES "empty\\.pdb")
+ message(FATAL_ERROR "unexpected PDB_PATH [${PDB_PATH}]")
+endif()
+
+if(NOT PDB_NAME STREQUAL "empty.pdb")
+ message(FATAL_ERROR "unexpected PDB_NAME [${PDB_NAME}]")
+endif()
+
+if(PDB_DIR MATCHES "empty\\.pdb")
+ message(FATAL_ERROR "unexpected PDB_DIR [${PDB_DIR}]")
+endif()
diff --git a/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE-stderr.txt b/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE.cmake b/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE.cmake
new file mode 100644
index 0000000000..38e47f91fc
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE.cmake
@@ -0,0 +1,19 @@
+
+enable_language(C)
+
+add_library(empty SHARED empty.c)
+
+if(CMAKE_CONFIGURATION_TYPES)
+ list(GET CMAKE_CONFIGURATION_TYPES 0 FIRST_CONFIG)
+ set(GENERATE_CONDITION CONDITION $<CONFIG:${FIRST_CONFIG}>)
+endif()
+
+file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
+ CONTENT
+[[$<TARGET_PDB_FILE:empty>
+$<TARGET_PDB_FILE_NAME:empty>
+$<TARGET_PDB_FILE_DIR:empty>
+]]
+ ${GENERATE_CONDITION}
+)
diff --git a/Tests/RunCMake/GeneratorExpression/empty.c b/Tests/RunCMake/GeneratorExpression/empty.c
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/empty.c
diff --git a/Tests/RunCMake/GeneratorPlatform/BadPlatform-result.txt b/Tests/RunCMake/GeneratorPlatform/BadPlatform-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/BadPlatform-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorPlatform/BadPlatform-stderr.txt b/Tests/RunCMake/GeneratorPlatform/BadPlatform-stderr.txt
new file mode 100644
index 0000000000..e31571451c
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/BadPlatform-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at CMakeLists.txt:[0-9]+ \(project\):
+ Generator
+
+ .*
+
+ does not support platform specification, but platform
+
+ Bad Platform
+
+ was specified.$
diff --git a/Tests/RunCMake/GeneratorPlatform/BadPlatform-toolchain.cmake b/Tests/RunCMake/GeneratorPlatform/BadPlatform-toolchain.cmake
new file mode 100644
index 0000000000..1c544b0d42
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/BadPlatform-toolchain.cmake
@@ -0,0 +1 @@
+set(CMAKE_GENERATOR_PLATFORM "Bad Platform")
diff --git a/Tests/RunCMake/GeneratorPlatform/BadPlatform.cmake b/Tests/RunCMake/GeneratorPlatform/BadPlatform.cmake
new file mode 100644
index 0000000000..2fc38e5c59
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/BadPlatform.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "This should not be reached!")
diff --git a/Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain-result.txt b/Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain-stderr.txt b/Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain-stderr.txt
new file mode 100644
index 0000000000..e31571451c
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at CMakeLists.txt:[0-9]+ \(project\):
+ Generator
+
+ .*
+
+ does not support platform specification, but platform
+
+ Bad Platform
+
+ was specified.$
diff --git a/Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain.cmake b/Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain.cmake
new file mode 100644
index 0000000000..2fc38e5c59
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/BadPlatformToolchain.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "This should not be reached!")
diff --git a/Tests/RunCMake/GeneratorPlatform/CMakeLists.txt b/Tests/RunCMake/GeneratorPlatform/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/GeneratorPlatform/NoPlatform-result.txt b/Tests/RunCMake/GeneratorPlatform/NoPlatform-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/NoPlatform-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorPlatform/NoPlatform-stderr.txt b/Tests/RunCMake/GeneratorPlatform/NoPlatform-stderr.txt
new file mode 100644
index 0000000000..e1c0da4c54
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/NoPlatform-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoPlatform.cmake:2 \(message\):
+ CMAKE_GENERATOR_PLATFORM is empty as expected.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorPlatform/NoPlatform.cmake b/Tests/RunCMake/GeneratorPlatform/NoPlatform.cmake
new file mode 100644
index 0000000000..1e0ca6deb0
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/NoPlatform.cmake
@@ -0,0 +1,7 @@
+if("x${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x")
+ message(FATAL_ERROR "CMAKE_GENERATOR_PLATFORM is empty as expected.")
+else()
+ message(FATAL_ERROR
+ "CMAKE_GENERATOR_PLATFORM is \"${CMAKE_GENERATOR_PLATFORM}\" "
+ "but should be empty!")
+endif()
diff --git a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake
new file mode 100644
index 0000000000..4d0a0a1a1b
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake
@@ -0,0 +1,28 @@
+include(RunCMake)
+
+set(RunCMake_GENERATOR_PLATFORM "")
+run_cmake(NoPlatform)
+
+if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio ([89]|1[0124])( 20[0-9][0-9])?$")
+ set(RunCMake_GENERATOR_PLATFORM "x64")
+ run_cmake(x64Platform)
+else()
+ set(RunCMake_GENERATOR_PLATFORM "Bad Platform")
+ run_cmake(BadPlatform)
+endif()
+
+set(RunCMake_GENERATOR_TOOLSET "")
+
+set(RunCMake_TEST_OPTIONS -A "Extra Platform")
+run_cmake(TwoPlatforms)
+unset(RunCMake_TEST_OPTIONS)
+
+if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio ([89]|1[0124])( 20[0-9][0-9])?$")
+ set(RunCMake_TEST_OPTIONS -DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/TestPlatform-toolchain.cmake)
+ run_cmake(TestPlatformToolchain)
+ unset(RunCMake_TEST_OPTIONS)
+else()
+ set(RunCMake_TEST_OPTIONS -DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/BadPlatform-toolchain.cmake)
+ run_cmake(BadPlatformToolchain)
+ unset(RunCMake_TEST_OPTIONS)
+endif()
diff --git a/Tests/RunCMake/GeneratorPlatform/TestPlatform-toolchain.cmake b/Tests/RunCMake/GeneratorPlatform/TestPlatform-toolchain.cmake
new file mode 100644
index 0000000000..763478cc52
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/TestPlatform-toolchain.cmake
@@ -0,0 +1 @@
+set(CMAKE_GENERATOR_PLATFORM "Test Platform")
diff --git a/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-result.txt b/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-stderr.txt b/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-stderr.txt
new file mode 100644
index 0000000000..b9bb3b2316
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at TestPlatformToolchain.cmake:[0-9]+ \(message\):
+ CMAKE_GENERATOR_PLATFORM is "Test Platform" as expected.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at TestPlatformToolchain.cmake:[0-9]+ \(message\):
+ CMAKE_VS_PLATFORM_NAME is "Test Platform" as expected.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain.cmake b/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain.cmake
new file mode 100644
index 0000000000..c4430a5982
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain.cmake
@@ -0,0 +1,16 @@
+if("x${CMAKE_GENERATOR_PLATFORM}" STREQUAL "xTest Platform")
+ message(SEND_ERROR "CMAKE_GENERATOR_PLATFORM is \"Test Platform\" as expected.")
+else()
+ message(FATAL_ERROR
+ "CMAKE_GENERATOR_PLATFORM is \"${CMAKE_GENERATOR_PLATFORM}\" "
+ "but should be \"Test Platform\"!")
+endif()
+if(CMAKE_GENERATOR MATCHES "Visual Studio")
+ if("x${CMAKE_VS_PLATFORM_NAME}" STREQUAL "xTest Platform")
+ message(SEND_ERROR "CMAKE_VS_PLATFORM_NAME is \"Test Platform\" as expected.")
+ else()
+ message(FATAL_ERROR
+ "CMAKE_VS_PLATFORM_NAME is \"${CMAKE_VS_PLATFORM_NAME}\" "
+ "but should be \"Test Platform\"!")
+ endif()
+endif()
diff --git a/Tests/RunCMake/GeneratorPlatform/TwoPlatforms-result.txt b/Tests/RunCMake/GeneratorPlatform/TwoPlatforms-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/TwoPlatforms-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorPlatform/TwoPlatforms-stderr.txt b/Tests/RunCMake/GeneratorPlatform/TwoPlatforms-stderr.txt
new file mode 100644
index 0000000000..90e4ecad8d
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/TwoPlatforms-stderr.txt
@@ -0,0 +1 @@
+CMake Error: Multiple -A options not allowed
diff --git a/Tests/RunCMake/GeneratorPlatform/TwoPlatforms.cmake b/Tests/RunCMake/GeneratorPlatform/TwoPlatforms.cmake
new file mode 100644
index 0000000000..2fc38e5c59
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/TwoPlatforms.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "This should not be reached!")
diff --git a/Tests/RunCMake/GeneratorPlatform/x64Platform-stdout.txt b/Tests/RunCMake/GeneratorPlatform/x64Platform-stdout.txt
new file mode 100644
index 0000000000..05a83ff7cf
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/x64Platform-stdout.txt
@@ -0,0 +1,2 @@
+-- CMAKE_GENERATOR_PLATFORM is 'x64' as expected.
+-- CMAKE_VS_PLATFORM_NAME is 'x64' as expected.
diff --git a/Tests/RunCMake/GeneratorPlatform/x64Platform.cmake b/Tests/RunCMake/GeneratorPlatform/x64Platform.cmake
new file mode 100644
index 0000000000..a23bdc74b7
--- /dev/null
+++ b/Tests/RunCMake/GeneratorPlatform/x64Platform.cmake
@@ -0,0 +1,7 @@
+foreach(v CMAKE_GENERATOR_PLATFORM CMAKE_VS_PLATFORM_NAME)
+ if("x${${v}}" STREQUAL "xx64")
+ message(STATUS "${v} is 'x64' as expected.")
+ else()
+ message(FATAL_ERROR "${v} is '${${v}}' but should be 'x64'!")
+ endif()
+endforeach()
diff --git a/Tests/RunCMake/GeneratorToolset/BadToolset-result.txt b/Tests/RunCMake/GeneratorToolset/BadToolset-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/BadToolset-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorToolset/BadToolset-stderr.txt b/Tests/RunCMake/GeneratorToolset/BadToolset-stderr.txt
new file mode 100644
index 0000000000..d0d526c688
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/BadToolset-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at CMakeLists.txt:[0-9]+ \(project\):
+ Generator
+
+ .*
+
+ does not support toolset specification, but toolset
+
+ Bad Toolset
+
+ was specified.$
diff --git a/Tests/RunCMake/GeneratorToolset/BadToolset-toolchain.cmake b/Tests/RunCMake/GeneratorToolset/BadToolset-toolchain.cmake
new file mode 100644
index 0000000000..7bbf327577
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/BadToolset-toolchain.cmake
@@ -0,0 +1 @@
+set(CMAKE_GENERATOR_TOOLSET "Bad Toolset")
diff --git a/Tests/RunCMake/GeneratorToolset/BadToolset.cmake b/Tests/RunCMake/GeneratorToolset/BadToolset.cmake
new file mode 100644
index 0000000000..2fc38e5c59
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/BadToolset.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "This should not be reached!")
diff --git a/Tests/RunCMake/GeneratorToolset/BadToolsetToolchain-result.txt b/Tests/RunCMake/GeneratorToolset/BadToolsetToolchain-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/BadToolsetToolchain-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorToolset/BadToolsetToolchain-stderr.txt b/Tests/RunCMake/GeneratorToolset/BadToolsetToolchain-stderr.txt
new file mode 100644
index 0000000000..d0d526c688
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/BadToolsetToolchain-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at CMakeLists.txt:[0-9]+ \(project\):
+ Generator
+
+ .*
+
+ does not support toolset specification, but toolset
+
+ Bad Toolset
+
+ was specified.$
diff --git a/Tests/RunCMake/GeneratorToolset/BadToolsetToolchain.cmake b/Tests/RunCMake/GeneratorToolset/BadToolsetToolchain.cmake
new file mode 100644
index 0000000000..2fc38e5c59
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/BadToolsetToolchain.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "This should not be reached!")
diff --git a/Tests/RunCMake/GeneratorToolset/CMakeLists.txt b/Tests/RunCMake/GeneratorToolset/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/GeneratorToolset/NoToolset-result.txt b/Tests/RunCMake/GeneratorToolset/NoToolset-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/NoToolset-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorToolset/NoToolset-stderr.txt b/Tests/RunCMake/GeneratorToolset/NoToolset-stderr.txt
new file mode 100644
index 0000000000..bc6f741938
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/NoToolset-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoToolset.cmake:2 \(message\):
+ CMAKE_GENERATOR_TOOLSET is empty as expected.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorToolset/NoToolset.cmake b/Tests/RunCMake/GeneratorToolset/NoToolset.cmake
new file mode 100644
index 0000000000..f1f1ecd265
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/NoToolset.cmake
@@ -0,0 +1,7 @@
+if("x${CMAKE_GENERATOR_TOOLSET}" STREQUAL "x")
+ message(FATAL_ERROR "CMAKE_GENERATOR_TOOLSET is empty as expected.")
+else()
+ message(FATAL_ERROR
+ "CMAKE_GENERATOR_TOOLSET is \"${CMAKE_GENERATOR_TOOLSET}\" "
+ "but should be empty!")
+endif()
diff --git a/Tests/RunCMake/GeneratorToolset/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorToolset/RunCMakeTest.cmake
new file mode 100644
index 0000000000..62206575c5
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/RunCMakeTest.cmake
@@ -0,0 +1,28 @@
+include(RunCMake)
+
+set(RunCMake_GENERATOR_TOOLSET "")
+run_cmake(NoToolset)
+
+if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[0124]|Xcode" AND NOT XCODE_BELOW_3)
+ set(RunCMake_GENERATOR_TOOLSET "Test Toolset")
+ run_cmake(TestToolset)
+else()
+ set(RunCMake_GENERATOR_TOOLSET "Bad Toolset")
+ run_cmake(BadToolset)
+endif()
+
+set(RunCMake_GENERATOR_TOOLSET "")
+
+set(RunCMake_TEST_OPTIONS -T "Extra Toolset")
+run_cmake(TwoToolsets)
+unset(RunCMake_TEST_OPTIONS)
+
+if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[0124]|Xcode" AND NOT XCODE_BELOW_3)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/TestToolset-toolchain.cmake)
+ run_cmake(TestToolsetToolchain)
+ unset(RunCMake_TEST_OPTIONS)
+else()
+ set(RunCMake_TEST_OPTIONS -DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/BadToolset-toolchain.cmake)
+ run_cmake(BadToolsetToolchain)
+ unset(RunCMake_TEST_OPTIONS)
+endif()
diff --git a/Tests/RunCMake/GeneratorToolset/TestToolset-result.txt b/Tests/RunCMake/GeneratorToolset/TestToolset-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TestToolset-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorToolset/TestToolset-stderr.txt b/Tests/RunCMake/GeneratorToolset/TestToolset-stderr.txt
new file mode 100644
index 0000000000..d5726af5f9
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TestToolset-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at TestToolset.cmake:2 \(message\):
+ CMAKE_GENERATOR_TOOLSET is "Test Toolset" as expected.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorToolset/TestToolset-toolchain.cmake b/Tests/RunCMake/GeneratorToolset/TestToolset-toolchain.cmake
new file mode 100644
index 0000000000..bee2ae4bb7
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TestToolset-toolchain.cmake
@@ -0,0 +1 @@
+set(CMAKE_GENERATOR_TOOLSET "Test Toolset")
diff --git a/Tests/RunCMake/GeneratorToolset/TestToolset.cmake b/Tests/RunCMake/GeneratorToolset/TestToolset.cmake
new file mode 100644
index 0000000000..6f83bef281
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TestToolset.cmake
@@ -0,0 +1,7 @@
+if("x${CMAKE_GENERATOR_TOOLSET}" STREQUAL "xTest Toolset")
+ message(FATAL_ERROR "CMAKE_GENERATOR_TOOLSET is \"Test Toolset\" as expected.")
+else()
+ message(FATAL_ERROR
+ "CMAKE_GENERATOR_TOOLSET is \"${CMAKE_GENERATOR_TOOLSET}\" "
+ "but should be \"Test Toolset\"!")
+endif()
diff --git a/Tests/RunCMake/GeneratorToolset/TestToolsetToolchain-result.txt b/Tests/RunCMake/GeneratorToolset/TestToolsetToolchain-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TestToolsetToolchain-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorToolset/TestToolsetToolchain-stderr.txt b/Tests/RunCMake/GeneratorToolset/TestToolsetToolchain-stderr.txt
new file mode 100644
index 0000000000..0623e90c72
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TestToolsetToolchain-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at TestToolsetToolchain.cmake:[0-9]+ \(message\):
+ CMAKE_GENERATOR_TOOLSET is "Test Toolset" as expected.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at TestToolsetToolchain.cmake:[0-9]+ \(message\):
+ CMAKE_(VS|XCODE)_PLATFORM_TOOLSET is "Test Toolset" as expected.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorToolset/TestToolsetToolchain.cmake b/Tests/RunCMake/GeneratorToolset/TestToolsetToolchain.cmake
new file mode 100644
index 0000000000..7c1c415189
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TestToolsetToolchain.cmake
@@ -0,0 +1,25 @@
+if("x${CMAKE_GENERATOR_TOOLSET}" STREQUAL "xTest Toolset")
+ message(SEND_ERROR "CMAKE_GENERATOR_TOOLSET is \"Test Toolset\" as expected.")
+else()
+ message(FATAL_ERROR
+ "CMAKE_GENERATOR_TOOLSET is \"${CMAKE_GENERATOR_TOOLSET}\" "
+ "but should be \"Test Toolset\"!")
+endif()
+if(CMAKE_GENERATOR MATCHES "Visual Studio")
+ if("x${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "xTest Toolset")
+ message(SEND_ERROR "CMAKE_VS_PLATFORM_TOOLSET is \"Test Toolset\" as expected.")
+ else()
+ message(FATAL_ERROR
+ "CMAKE_VS_PLATFORM_TOOLSET is \"${CMAKE_VS_PLATFORM_TOOLSET}\" "
+ "but should be \"Test Toolset\"!")
+ endif()
+endif()
+if(CMAKE_GENERATOR MATCHES "Xcode")
+ if("x${CMAKE_XCODE_PLATFORM_TOOLSET}" STREQUAL "xTest Toolset")
+ message(SEND_ERROR "CMAKE_XCODE_PLATFORM_TOOLSET is \"Test Toolset\" as expected.")
+ else()
+ message(FATAL_ERROR
+ "CMAKE_XCODE_PLATFORM_TOOLSET is \"${CMAKE_XCODE_PLATFORM_TOOLSET}\" "
+ "but should be \"Test Toolset\"!")
+ endif()
+endif()
diff --git a/Tests/RunCMake/GeneratorToolset/TwoToolsets-result.txt b/Tests/RunCMake/GeneratorToolset/TwoToolsets-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TwoToolsets-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorToolset/TwoToolsets-stderr.txt b/Tests/RunCMake/GeneratorToolset/TwoToolsets-stderr.txt
new file mode 100644
index 0000000000..9fa817ff52
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TwoToolsets-stderr.txt
@@ -0,0 +1 @@
+CMake Error: Multiple -T options not allowed
diff --git a/Tests/RunCMake/GeneratorToolset/TwoToolsets.cmake b/Tests/RunCMake/GeneratorToolset/TwoToolsets.cmake
new file mode 100644
index 0000000000..2fc38e5c59
--- /dev/null
+++ b/Tests/RunCMake/GeneratorToolset/TwoToolsets.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "This should not be reached!")
diff --git a/Tests/RunCMake/IncompatibleQt/CMakeLists.txt b/Tests/RunCMake/IncompatibleQt/CMakeLists.txt
new file mode 100644
index 0000000000..f452db1770
--- /dev/null
+++ b/Tests/RunCMake/IncompatibleQt/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/IncompatibleQt/IncompatibleQt-result.txt b/Tests/RunCMake/IncompatibleQt/IncompatibleQt-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/IncompatibleQt/IncompatibleQt-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/IncompatibleQt/IncompatibleQt-stderr.txt b/Tests/RunCMake/IncompatibleQt/IncompatibleQt-stderr.txt
new file mode 100644
index 0000000000..4eaaa95f13
--- /dev/null
+++ b/Tests/RunCMake/IncompatibleQt/IncompatibleQt-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error: The INTERFACE_QT_MAJOR_VERSION property of "Qt5::Core" does
+not agree with the value of QT_MAJOR_VERSION already determined
+for "mainexe".
diff --git a/Tests/RunCMake/IncompatibleQt/IncompatibleQt.cmake b/Tests/RunCMake/IncompatibleQt/IncompatibleQt.cmake
new file mode 100644
index 0000000000..4fccdc418f
--- /dev/null
+++ b/Tests/RunCMake/IncompatibleQt/IncompatibleQt.cmake
@@ -0,0 +1,6 @@
+
+find_package(Qt4 REQUIRED)
+find_package(Qt5Core REQUIRED)
+
+add_executable(mainexe main.cpp)
+target_link_libraries(mainexe Qt4::QtCore Qt5::Core)
diff --git a/Tests/RunCMake/IncompatibleQt/RunCMakeTest.cmake b/Tests/RunCMake/IncompatibleQt/RunCMakeTest.cmake
new file mode 100644
index 0000000000..322c291b74
--- /dev/null
+++ b/Tests/RunCMake/IncompatibleQt/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake(IncompatibleQt)
diff --git a/Tests/RunCMake/IncompatibleQt/main.cpp b/Tests/RunCMake/IncompatibleQt/main.cpp
new file mode 100644
index 0000000000..140a7c1a6d
--- /dev/null
+++ b/Tests/RunCMake/IncompatibleQt/main.cpp
@@ -0,0 +1,8 @@
+
+#include <QCoreApplication>
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+ return app.exec();
+}
diff --git a/Tests/RunCMake/Languages/CMakeLists.txt b/Tests/RunCMake/Languages/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/Languages/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-result.txt b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-stderr.txt b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-stderr.txt
new file mode 100644
index 0000000000..3a7f4806cb
--- /dev/null
+++ b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at LINK_LANGUAGE-genex.cmake:[0-9]+ \(target_link_libraries\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:LINKER_LANGUAGE>
+
+ LINKER_LANGUAGE target property can not be used while evaluating link
+ libraries for a static library
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Languages/LINK_LANGUAGE-genex.cmake b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex.cmake
new file mode 100644
index 0000000000..64f394c116
--- /dev/null
+++ b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex.cmake
@@ -0,0 +1,4 @@
+
+add_library(foo STATIC empty.cpp)
+add_library(bar STATIC empty.cpp)
+target_link_libraries(foo $<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,anything>:bar>)
diff --git a/Tests/RunCMake/Languages/NoLangSHARED-result.txt b/Tests/RunCMake/Languages/NoLangSHARED-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Languages/NoLangSHARED-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Languages/NoLangSHARED-stderr.txt b/Tests/RunCMake/Languages/NoLangSHARED-stderr.txt
new file mode 100644
index 0000000000..983129a215
--- /dev/null
+++ b/Tests/RunCMake/Languages/NoLangSHARED-stderr.txt
@@ -0,0 +1 @@
+CMake Error: CMake can not determine linker language for target: NoLang
diff --git a/Tests/RunCMake/Languages/NoLangSHARED.cmake b/Tests/RunCMake/Languages/NoLangSHARED.cmake
new file mode 100644
index 0000000000..de6adf7cbf
--- /dev/null
+++ b/Tests/RunCMake/Languages/NoLangSHARED.cmake
@@ -0,0 +1 @@
+add_library(NoLang SHARED foo.nolang)
diff --git a/Tests/RunCMake/Languages/RunCMakeTest.cmake b/Tests/RunCMake/Languages/RunCMakeTest.cmake
new file mode 100644
index 0000000000..6517a8105b
--- /dev/null
+++ b/Tests/RunCMake/Languages/RunCMakeTest.cmake
@@ -0,0 +1,6 @@
+include(RunCMake)
+
+run_cmake(NoLangSHARED)
+run_cmake(LINK_LANGUAGE-genex)
+run_cmake(link-libraries-TARGET_FILE-genex)
+run_cmake(link-libraries-TARGET_FILE-genex-ok)
diff --git a/Tests/RunCMake/Languages/empty.cpp b/Tests/RunCMake/Languages/empty.cpp
new file mode 100644
index 0000000000..7279c5e0b9
--- /dev/null
+++ b/Tests/RunCMake/Languages/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty(void)
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/Languages/foo.nolang b/Tests/RunCMake/Languages/foo.nolang
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/Languages/foo.nolang
diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok-result.txt b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok.cmake b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok.cmake
new file mode 100644
index 0000000000..f0fd6e5aaa
--- /dev/null
+++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok.cmake
@@ -0,0 +1,6 @@
+
+enable_language(CXX)
+
+add_library(foo SHARED empty.cpp)
+add_library(bar SHARED empty.cpp)
+target_link_libraries(foo $<$<STREQUAL:$<TARGET_FILE:bar>,anything>:bar>)
diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-result.txt b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-stderr.txt b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-stderr.txt
new file mode 100644
index 0000000000..d8bc2387b4
--- /dev/null
+++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at link-libraries-TARGET_FILE-genex.cmake:[0-9]+ \(target_link_libraries\):
+ Error evaluating generator expression:
+
+ \$<TARGET_FILE:foo>
+
+ Expressions which require the linker language may not be used while
+ evaluating link libraries
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex.cmake b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex.cmake
new file mode 100644
index 0000000000..eca73e977b
--- /dev/null
+++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex.cmake
@@ -0,0 +1,4 @@
+
+add_library(foo SHARED empty.cpp)
+add_library(bar SHARED empty.cpp)
+target_link_libraries(foo $<$<STREQUAL:$<TARGET_FILE:foo>,anything>:bar>)
diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt
new file mode 100644
index 0000000000..a09552b763
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at BadObjSource1.cmake:1 \(add_library\):
+ OBJECT library "A" contains:
+
+ bad.def
+
+ but may contain only sources that compile, header files, and other files
+ that would not affect linking of a normal library.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake b/Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake
new file mode 100644
index 0000000000..aa3514d90c
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake
@@ -0,0 +1 @@
+add_library(A OBJECT a.c bad.def)
diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt
new file mode 100644
index 0000000000..b91ffd0682
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at BadObjSource2.cmake:1 \(add_library\):
+ OBJECT library "A" contains:
+
+ bad.obj
+
+ but may contain only sources that compile, header files, and other files
+ that would not affect linking of a normal library.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake b/Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake
new file mode 100644
index 0000000000..7957c99f2e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake
@@ -0,0 +1 @@
+add_library(A OBJECT a.c bad.obj)
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt
new file mode 100644
index 0000000000..859dc3f8cb
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadSourceExpression1.cmake:1 \(add_library\):
+ Error evaluating generator expression:
+
+ \$<BAD_EXPRESSION>
+
+ Expression did not evaluate to a known generator expression
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake
new file mode 100644
index 0000000000..020c9a00f6
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake
@@ -0,0 +1 @@
+add_library(A STATIC a.c $<BAD_EXPRESSION>)
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt
new file mode 100644
index 0000000000..7060c615e0
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadSourceExpression2.cmake:1 \(add_library\):
+ Error evaluating generator expression:
+
+ \$<TARGET_OBJECTS:DoesNotExist>
+
+ Objects of target "DoesNotExist" referenced but no such target exists.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake
new file mode 100644
index 0000000000..ed5dc43350
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake
@@ -0,0 +1 @@
+add_library(A STATIC a.c $<TARGET_OBJECTS:DoesNotExist>)
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt
new file mode 100644
index 0000000000..838b3d8c43
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadSourceExpression3.cmake:2 \(add_library\):
+ Error evaluating generator expression:
+
+ \$<TARGET_OBJECTS:NotObjLib>
+
+ Objects of target "NotObjLib" referenced but is not an OBJECT library.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake
new file mode 100644
index 0000000000..c3d9a622d0
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake
@@ -0,0 +1,2 @@
+add_library(NotObjLib STATIC a.c)
+add_library(A STATIC a.c $<TARGET_OBJECTS:NotObjLib>)
diff --git a/Tests/RunCMake/ObjectLibrary/CMakeLists.txt b/Tests/RunCMake/ObjectLibrary/CMakeLists.txt
new file mode 100644
index 0000000000..a17c8cd139
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} C)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/ObjectLibrary/Export-result.txt b/Tests/RunCMake/ObjectLibrary/Export-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/Export-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/Export-stderr.txt b/Tests/RunCMake/ObjectLibrary/Export-stderr.txt
new file mode 100644
index 0000000000..bdadca488a
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/Export-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at Export.cmake:2 \(export\):
+ export given OBJECT library "A" which may not be exported.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/Export.cmake b/Tests/RunCMake/ObjectLibrary/Export.cmake
new file mode 100644
index 0000000000..a3f104e297
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/Export.cmake
@@ -0,0 +1,2 @@
+add_library(A OBJECT a.c)
+export(TARGETS A FILE AExport.cmake)
diff --git a/Tests/RunCMake/ObjectLibrary/Import-result.txt b/Tests/RunCMake/ObjectLibrary/Import-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/Import-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/Import-stderr.txt b/Tests/RunCMake/ObjectLibrary/Import-stderr.txt
new file mode 100644
index 0000000000..74b496ab89
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/Import-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at Import.cmake:1 \(add_library\):
+ The OBJECT library type may not be used for IMPORTED libraries.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/Import.cmake b/Tests/RunCMake/ObjectLibrary/Import.cmake
new file mode 100644
index 0000000000..806b44a25e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/Import.cmake
@@ -0,0 +1 @@
+add_library(A OBJECT IMPORTED)
diff --git a/Tests/RunCMake/ObjectLibrary/Install-result.txt b/Tests/RunCMake/ObjectLibrary/Install-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/Install-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/Install-stderr.txt b/Tests/RunCMake/ObjectLibrary/Install-stderr.txt
new file mode 100644
index 0000000000..d2f9f4a37a
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/Install-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at Install.cmake:2 \(install\):
+ install TARGETS given OBJECT library "A" which may not be installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/Install.cmake b/Tests/RunCMake/ObjectLibrary/Install.cmake
new file mode 100644
index 0000000000..c1d214bd4b
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/Install.cmake
@@ -0,0 +1,2 @@
+add_library(A OBJECT a.c)
+install(TARGETS A DESTINATION lib)
diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt
new file mode 100644
index 0000000000..90e828bdb1
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at LinkObjLHS.cmake:2 \(target_link_libraries\):
+ Object library target "AnObjLib" may not link to anything.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake
new file mode 100644
index 0000000000..5d7831a23c
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake
@@ -0,0 +1,2 @@
+add_library(AnObjLib OBJECT a.c)
+target_link_libraries(AnObjLib OtherLib)
diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt
new file mode 100644
index 0000000000..8809f8933b
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at LinkObjRHS1.cmake:3 \(target_link_libraries\):
+ Target "AnObjLib" of type OBJECT_LIBRARY 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.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake
new file mode 100644
index 0000000000..113d6a841a
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake
@@ -0,0 +1,3 @@
+add_library(A STATIC a.c)
+add_library(AnObjLib OBJECT a.c)
+target_link_libraries(A AnObjLib)
diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt
new file mode 100644
index 0000000000..3295fcac30
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at LinkObjRHS2.cmake:1 \(add_library\):
+ Target "A" links to OBJECT library "AnObjLib" but this is not allowed. One
+ may link only to STATIC or SHARED libraries, or to executables with the
+ ENABLE_EXPORTS property set.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake
new file mode 100644
index 0000000000..616372949b
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake
@@ -0,0 +1,3 @@
+add_library(A SHARED a.c)
+target_link_libraries(A AnObjLib)
+add_library(AnObjLib OBJECT a.c)
diff --git a/Tests/RunCMake/ObjectLibrary/MissingSource-result.txt b/Tests/RunCMake/ObjectLibrary/MissingSource-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/MissingSource-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/MissingSource-stderr.txt b/Tests/RunCMake/ObjectLibrary/MissingSource-stderr.txt
new file mode 100644
index 0000000000..411cd7cb76
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/MissingSource-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at MissingSource.cmake:1 \(add_library\):
+ Cannot find source file:
+
+ missing.c
+
+ Tried extensions( \.[A-Za-z+]+|
+ )*
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/MissingSource.cmake b/Tests/RunCMake/ObjectLibrary/MissingSource.cmake
new file mode 100644
index 0000000000..258eaedb2f
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/MissingSource.cmake
@@ -0,0 +1 @@
+add_library(A OBJECT missing.c)
diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt b/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt b/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt
new file mode 100644
index 0000000000..d67b4ae320
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at ObjWithObj.cmake:2 \(add_library\):
+ Only executables and non-OBJECT libraries may reference target objects.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake b/Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake
new file mode 100644
index 0000000000..d0ef34bfe7
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake
@@ -0,0 +1,2 @@
+add_library(A OBJECT a.c)
+add_library(B OBJECT $<TARGET_OBJECTS:A>)
diff --git a/Tests/RunCMake/ObjectLibrary/PostBuild-result.txt b/Tests/RunCMake/ObjectLibrary/PostBuild-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/PostBuild-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt b/Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt
new file mode 100644
index 0000000000..4b067bbc33
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at PostBuild.cmake:2 \(add_custom_command\):
+ Target "A" is an OBJECT library that may not have PRE_BUILD, PRE_LINK, or
+ POST_BUILD commands.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/PostBuild.cmake b/Tests/RunCMake/ObjectLibrary/PostBuild.cmake
new file mode 100644
index 0000000000..dea9a099e8
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/PostBuild.cmake
@@ -0,0 +1,4 @@
+add_library(A OBJECT a.c)
+add_custom_command(TARGET A POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E echo "A post-build"
+ )
diff --git a/Tests/RunCMake/ObjectLibrary/PreBuild-result.txt b/Tests/RunCMake/ObjectLibrary/PreBuild-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/PreBuild-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt b/Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt
new file mode 100644
index 0000000000..3b27a6da52
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at PreBuild.cmake:2 \(add_custom_command\):
+ Target "A" is an OBJECT library that may not have PRE_BUILD, PRE_LINK, or
+ POST_BUILD commands.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/PreBuild.cmake b/Tests/RunCMake/ObjectLibrary/PreBuild.cmake
new file mode 100644
index 0000000000..e4424c100a
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/PreBuild.cmake
@@ -0,0 +1,4 @@
+add_library(A OBJECT a.c)
+add_custom_command(TARGET A PRE_BUILD
+ COMMAND ${CMAKE_COMMAND} -E echo "A pre-build"
+ )
diff --git a/Tests/RunCMake/ObjectLibrary/PreLink-result.txt b/Tests/RunCMake/ObjectLibrary/PreLink-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/PreLink-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt b/Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt
new file mode 100644
index 0000000000..947b9f177f
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at PreLink.cmake:2 \(add_custom_command\):
+ Target "A" is an OBJECT library that may not have PRE_BUILD, PRE_LINK, or
+ POST_BUILD commands.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/PreLink.cmake b/Tests/RunCMake/ObjectLibrary/PreLink.cmake
new file mode 100644
index 0000000000..b889055112
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/PreLink.cmake
@@ -0,0 +1,4 @@
+add_library(A OBJECT a.c)
+add_custom_command(TARGET A PRE_LINK
+ COMMAND ${CMAKE_COMMAND} -E echo "A pre-link"
+ )
diff --git a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake
new file mode 100644
index 0000000000..42973f8af2
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake
@@ -0,0 +1,18 @@
+include(RunCMake)
+
+run_cmake(BadSourceExpression1)
+run_cmake(BadSourceExpression2)
+run_cmake(BadSourceExpression3)
+run_cmake(BadObjSource1)
+run_cmake(BadObjSource2)
+run_cmake(Export)
+run_cmake(Import)
+run_cmake(Install)
+run_cmake(LinkObjLHS)
+run_cmake(LinkObjRHS1)
+run_cmake(LinkObjRHS2)
+run_cmake(MissingSource)
+run_cmake(ObjWithObj)
+run_cmake(PostBuild)
+run_cmake(PreBuild)
+run_cmake(PreLink)
diff --git a/Tests/RunCMake/ObjectLibrary/a.c b/Tests/RunCMake/ObjectLibrary/a.c
new file mode 100644
index 0000000000..af20d3ff65
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/a.c
@@ -0,0 +1 @@
+int a(void) { return 0; }
diff --git a/Tests/RunCMake/ObjectLibrary/bad.def b/Tests/RunCMake/ObjectLibrary/bad.def
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/bad.def
diff --git a/Tests/RunCMake/ObjectLibrary/bad.obj b/Tests/RunCMake/ObjectLibrary/bad.obj
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/ObjectLibrary/bad.obj
diff --git a/Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN-result.txt b/Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN-stderr.txt b/Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN-stderr.txt
new file mode 100644
index 0000000000..f358cc4bea
--- /dev/null
+++ b/Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN-stderr.txt
@@ -0,0 +1,5 @@
+CMake Deprecation Warning at .*/Modules/Qt4Macros.cmake:[^ ]+ \(message\):
+ The qt4_automoc macro is obsolete. Use the CMAKE_AUTOMOC feature instead.
+Call Stack \(most recent call first\):
+ AutomocMacro-WARN.cmake:7 \(qt4_automoc\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN.cmake b/Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN.cmake
new file mode 100644
index 0000000000..c0c64a5b74
--- /dev/null
+++ b/Tests/RunCMake/ObsoleteQtMacros/AutomocMacro-WARN.cmake
@@ -0,0 +1,7 @@
+
+find_package(Qt4 REQUIRED)
+
+set(CMAKE_WARN_DEPRECATED 1)
+
+add_library(foo SHARED empty.cpp)
+qt4_automoc(foo_moc_srcs empty.cpp)
diff --git a/Tests/RunCMake/ObsoleteQtMacros/CMakeLists.txt b/Tests/RunCMake/ObsoleteQtMacros/CMakeLists.txt
new file mode 100644
index 0000000000..65ac8e8db3
--- /dev/null
+++ b/Tests/RunCMake/ObsoleteQtMacros/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(${RunCMake_TEST})
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/ObsoleteQtMacros/RunCMakeTest.cmake b/Tests/RunCMake/ObsoleteQtMacros/RunCMakeTest.cmake
new file mode 100644
index 0000000000..eee2cc3999
--- /dev/null
+++ b/Tests/RunCMake/ObsoleteQtMacros/RunCMakeTest.cmake
@@ -0,0 +1,6 @@
+include(RunCMake)
+
+set(RunCMake_TEST_OPTIONS -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE})
+
+run_cmake(UseModulesMacro-WARN)
+run_cmake(AutomocMacro-WARN)
diff --git a/Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN-result.txt b/Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN-stderr.txt b/Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN-stderr.txt
new file mode 100644
index 0000000000..c69af65121
--- /dev/null
+++ b/Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN-stderr.txt
@@ -0,0 +1,6 @@
+CMake Deprecation Warning at .*/Modules/Qt4Macros.cmake:[^ ]+ \(message\):
+ The qt4_use_modules function is obsolete. Use target_link_libraries with
+ IMPORTED targets instead.
+Call Stack \(most recent call first\):
+ UseModulesMacro-WARN.cmake:[^ ]+ \(qt4_use_modules\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN.cmake b/Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN.cmake
new file mode 100644
index 0000000000..e86a3723be
--- /dev/null
+++ b/Tests/RunCMake/ObsoleteQtMacros/UseModulesMacro-WARN.cmake
@@ -0,0 +1,7 @@
+
+find_package(Qt4 REQUIRED)
+
+set(CMAKE_WARN_DEPRECATED 1)
+
+add_library(foo SHARED empty.cpp)
+qt4_use_modules(foo LINK_PRIVATE Core)
diff --git a/Tests/RunCMake/ObsoleteQtMacros/empty.cpp b/Tests/RunCMake/ObsoleteQtMacros/empty.cpp
new file mode 100644
index 0000000000..7279c5e0b9
--- /dev/null
+++ b/Tests/RunCMake/ObsoleteQtMacros/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty(void)
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/PositionIndependentCode/CMakeLists.txt b/Tests/RunCMake/PositionIndependentCode/CMakeLists.txt
new file mode 100644
index 0000000000..90afc127ed
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/CMakeLists.txt
@@ -0,0 +1,8 @@
+
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+
+# MSVC creates extra targets which pollute the stderr unless we set this.
+set(CMAKE_SUPPRESS_REGENERATION TRUE)
+
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict1-result.txt b/Tests/RunCMake/PositionIndependentCode/Conflict1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict1-stderr.txt b/Tests/RunCMake/PositionIndependentCode/Conflict1-stderr.txt
new file mode 100644
index 0000000000..cb07109869
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict1-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error: Property POSITION_INDEPENDENT_CODE on target "conflict" does
+not match the INTERFACE_POSITION_INDEPENDENT_CODE property requirement
+of dependency "piciface".
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict1.cmake b/Tests/RunCMake/PositionIndependentCode/Conflict1.cmake
new file mode 100644
index 0000000000..242bec37a5
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict1.cmake
@@ -0,0 +1,7 @@
+
+add_library(piciface UNKNOWN IMPORTED)
+set_property(TARGET piciface PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+add_executable(conflict "main.cpp")
+set_property(TARGET conflict PROPERTY POSITION_INDEPENDENT_CODE OFF)
+target_link_libraries(conflict piciface)
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict2-result.txt b/Tests/RunCMake/PositionIndependentCode/Conflict2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict2-stderr.txt b/Tests/RunCMake/PositionIndependentCode/Conflict2-stderr.txt
new file mode 100644
index 0000000000..ecd04928d3
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict2-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error: The INTERFACE_POSITION_INDEPENDENT_CODE property of "picoff" does
+not agree with the value of POSITION_INDEPENDENT_CODE already determined
+for "conflict".
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict2.cmake b/Tests/RunCMake/PositionIndependentCode/Conflict2.cmake
new file mode 100644
index 0000000000..215d08dae5
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict2.cmake
@@ -0,0 +1,9 @@
+
+add_library(picon UNKNOWN IMPORTED)
+set_property(TARGET picon PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+add_library(picoff UNKNOWN IMPORTED)
+set_property(TARGET picoff PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE OFF)
+
+add_executable(conflict "main.cpp")
+target_link_libraries(conflict picon picoff)
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict3-result.txt b/Tests/RunCMake/PositionIndependentCode/Conflict3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict3-stderr.txt b/Tests/RunCMake/PositionIndependentCode/Conflict3-stderr.txt
new file mode 100644
index 0000000000..0254e55575
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict3-stderr.txt
@@ -0,0 +1,4 @@
+Property POSITION_INDEPENDENT_CODE on target "conflict" is
+implied to be FALSE because it was used to determine the link libraries
+already. The INTERFACE_POSITION_INDEPENDENT_CODE property on
+dependency "picon" is in conflict.
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict3.cmake b/Tests/RunCMake/PositionIndependentCode/Conflict3.cmake
new file mode 100644
index 0000000000..bf669bf4fc
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict3.cmake
@@ -0,0 +1,12 @@
+
+add_library(picoff UNKNOWN IMPORTED)
+
+add_library(picon UNKNOWN IMPORTED)
+set_property(TARGET picon PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+add_executable(conflict "main.cpp")
+target_link_libraries(conflict picon)
+set_property(TARGET conflict APPEND PROPERTY
+ LINK_LIBRARIES
+ $<$<NOT:$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>>:picoff>
+)
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict4-result.txt b/Tests/RunCMake/PositionIndependentCode/Conflict4-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict4-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict4-stderr.txt b/Tests/RunCMake/PositionIndependentCode/Conflict4-stderr.txt
new file mode 100644
index 0000000000..76d5ea08a4
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict4-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error: Property POSITION_INDEPENDENT_CODE on target "conflict" is
+implied to be FALSE because it was used to determine the link libraries
+already. The INTERFACE_POSITION_INDEPENDENT_CODE property on
+dependency "picon" is in conflict.
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict4.cmake b/Tests/RunCMake/PositionIndependentCode/Conflict4.cmake
new file mode 100644
index 0000000000..ff5dfb353c
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict4.cmake
@@ -0,0 +1,8 @@
+
+add_library(piciface INTERFACE)
+
+add_library(picon INTERFACE)
+set_property(TARGET picon PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+add_executable(conflict "main.cpp")
+target_link_libraries(conflict picon $<$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>:piciface>)
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict5-result.txt b/Tests/RunCMake/PositionIndependentCode/Conflict5-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict5-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict5-stderr.txt b/Tests/RunCMake/PositionIndependentCode/Conflict5-stderr.txt
new file mode 100644
index 0000000000..ecd04928d3
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict5-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error: The INTERFACE_POSITION_INDEPENDENT_CODE property of "picoff" does
+not agree with the value of POSITION_INDEPENDENT_CODE already determined
+for "conflict".
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict5.cmake b/Tests/RunCMake/PositionIndependentCode/Conflict5.cmake
new file mode 100644
index 0000000000..e6055f4508
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict5.cmake
@@ -0,0 +1,9 @@
+
+add_library(picon INTERFACE)
+set_property(TARGET picon PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+add_library(picoff INTERFACE)
+set_property(TARGET picoff PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE OFF)
+
+add_executable(conflict "main.cpp")
+target_link_libraries(conflict picon picoff)
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict6-result.txt b/Tests/RunCMake/PositionIndependentCode/Conflict6-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict6-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict6-stderr.txt b/Tests/RunCMake/PositionIndependentCode/Conflict6-stderr.txt
new file mode 100644
index 0000000000..0254e55575
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict6-stderr.txt
@@ -0,0 +1,4 @@
+Property POSITION_INDEPENDENT_CODE on target "conflict" is
+implied to be FALSE because it was used to determine the link libraries
+already. The INTERFACE_POSITION_INDEPENDENT_CODE property on
+dependency "picon" is in conflict.
diff --git a/Tests/RunCMake/PositionIndependentCode/Conflict6.cmake b/Tests/RunCMake/PositionIndependentCode/Conflict6.cmake
new file mode 100644
index 0000000000..7ea7c5f731
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Conflict6.cmake
@@ -0,0 +1,8 @@
+
+add_library(picoff INTERFACE)
+
+add_library(picon INTERFACE)
+set_property(TARGET picon PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+add_executable(conflict "main.cpp")
+target_link_libraries(conflict picon $<$<NOT:$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>>:picoff>)
diff --git a/Tests/RunCMake/PositionIndependentCode/Debug-result.txt b/Tests/RunCMake/PositionIndependentCode/Debug-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Debug-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/PositionIndependentCode/Debug-stderr.txt b/Tests/RunCMake/PositionIndependentCode/Debug-stderr.txt
new file mode 100644
index 0000000000..774445b2be
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Debug-stderr.txt
@@ -0,0 +1,6 @@
+CMake Debug Log:
+ Boolean compatibility of property "POSITION_INDEPENDENT_CODE" for target
+ "foo" \(result: "TRUE"\):
+
+ \* Target "foo" has property content "TRUE"
+ \* Target "iface" property value "TRUE" \(Agree\)
diff --git a/Tests/RunCMake/PositionIndependentCode/Debug.cmake b/Tests/RunCMake/PositionIndependentCode/Debug.cmake
new file mode 100644
index 0000000000..4a8fbacba4
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/Debug.cmake
@@ -0,0 +1,8 @@
+
+add_library(iface INTERFACE)
+set_property(TARGET iface PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES POSITION_INDEPENDENT_CODE)
+add_library(foo main.cpp)
+target_link_libraries(foo iface)
+set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE ON)
diff --git a/Tests/RunCMake/PositionIndependentCode/RunCMakeTest.cmake b/Tests/RunCMake/PositionIndependentCode/RunCMakeTest.cmake
new file mode 100644
index 0000000000..6a67e3cad1
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/RunCMakeTest.cmake
@@ -0,0 +1,9 @@
+include(RunCMake)
+
+run_cmake(Conflict1)
+run_cmake(Conflict2)
+run_cmake(Conflict3)
+run_cmake(Conflict4)
+run_cmake(Conflict5)
+run_cmake(Conflict6)
+run_cmake(Debug)
diff --git a/Tests/RunCMake/PositionIndependentCode/main.cpp b/Tests/RunCMake/PositionIndependentCode/main.cpp
new file mode 100644
index 0000000000..31ba482802
--- /dev/null
+++ b/Tests/RunCMake/PositionIndependentCode/main.cpp
@@ -0,0 +1,5 @@
+
+int main(int,char**)
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/README.rst b/Tests/RunCMake/README.rst
new file mode 100644
index 0000000000..536cff2e26
--- /dev/null
+++ b/Tests/RunCMake/README.rst
@@ -0,0 +1,57 @@
+This directory contains tests that run CMake to configure a project
+but do not actually build anything. To add a test:
+
+1. Add a subdirectory named for the test, say ``<Test>/``.
+
+2. In ``./CMakeLists.txt`` call ``add_RunCMake_test`` and pass the
+ test directory name ``<Test>``.
+
+3. Create script ``<Test>/RunCMakeTest.cmake`` in the directory containing::
+
+ include(RunCMake)
+ run_cmake(SubTest1)
+ ...
+ run_cmake(SubTestN)
+
+ where ``SubTest1`` through ``SubTestN`` are sub-test names each
+ corresponding to an independent CMake run and project configuration.
+
+ One may also add calls of the form::
+
+ run_cmake_command(SubTestI ${CMAKE_COMMAND} ...)
+
+ to fully customize the test case command-line.
+
+4. Create file ``<Test>/CMakeLists.txt`` in the directory containing::
+
+ cmake_minimum_required(...)
+ project(${RunCMake_TEST} NONE) # or languages needed
+ include(${RunCMake_TEST}.cmake)
+
+ where ``${RunCMake_TEST}`` is literal. A value for ``RunCMake_TEST``
+ will be passed to CMake by the ``run_cmake`` macro when running each
+ sub-test.
+
+5. Create a ``<Test>/<SubTest>.cmake`` file for each sub-test named
+ above containing the actual test code. Optionally create files
+ containing expected test results:
+
+ ``<SubTest>-result.txt``
+ Process result expected if not "0"
+ ``<SubTest>-stdout.txt``
+ Regex matching expected stdout content
+ ``<SubTest>-stderr.txt``
+ Regex matching expected stderr content
+ ``<SubTest>-check.cmake``
+ Custom result check.
+
+ Note that trailing newlines will be stripped from actual and expected
+ test output before matching against the stdout and stderr expressions.
+ The code in ``<SubTest>-check.cmake`` may use variables
+
+ ``RunCMake_TEST_SOURCE_DIR``
+ Top of test source tree
+ ``RunCMake_TEST_BINARY_DIR``
+ Top of test binary tree
+
+ and an failure must store a message in ``RunCMake_TEST_FAILED``.
diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake
new file mode 100644
index 0000000000..56d69c846b
--- /dev/null
+++ b/Tests/RunCMake/RunCMake.cmake
@@ -0,0 +1,107 @@
+foreach(arg
+ RunCMake_GENERATOR
+ RunCMake_SOURCE_DIR
+ RunCMake_BINARY_DIR
+ )
+ if(NOT DEFINED ${arg})
+ message(FATAL_ERROR "${arg} not given!")
+ endif()
+endforeach()
+
+function(run_cmake test)
+ set(top_src "${RunCMake_SOURCE_DIR}")
+ set(top_bin "${RunCMake_BINARY_DIR}")
+ if(EXISTS ${top_src}/${test}-result.txt)
+ file(READ ${top_src}/${test}-result.txt expect_result)
+ string(REGEX REPLACE "\n+$" "" expect_result "${expect_result}")
+ else()
+ set(expect_result 0)
+ endif()
+ foreach(o out err)
+ if(EXISTS ${top_src}/${test}-std${o}.txt)
+ file(READ ${top_src}/${test}-std${o}.txt expect_std${o})
+ string(REGEX REPLACE "\n+$" "" expect_std${o} "${expect_std${o}}")
+ else()
+ unset(expect_std${o})
+ endif()
+ endforeach()
+ if (NOT RunCMake_TEST_SOURCE_DIR)
+ set(RunCMake_TEST_SOURCE_DIR "${top_src}")
+ endif()
+ if(NOT RunCMake_TEST_BINARY_DIR)
+ set(RunCMake_TEST_BINARY_DIR "${top_bin}/${test}-build")
+ endif()
+ if(NOT RunCMake_TEST_NO_CLEAN)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ endif()
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ if(NOT DEFINED RunCMake_TEST_OPTIONS)
+ set(RunCMake_TEST_OPTIONS "")
+ endif()
+ if(APPLE)
+ list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0025=NEW)
+ endif()
+ if(RunCMake_TEST_COMMAND)
+ execute_process(
+ COMMAND ${RunCMake_TEST_COMMAND}
+ WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}"
+ OUTPUT_VARIABLE actual_stdout
+ ERROR_VARIABLE actual_stderr
+ RESULT_VARIABLE actual_result
+ )
+ else()
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} "${RunCMake_TEST_SOURCE_DIR}"
+ -G "${RunCMake_GENERATOR}"
+ -A "${RunCMake_GENERATOR_PLATFORM}"
+ -T "${RunCMake_GENERATOR_TOOLSET}"
+ -DRunCMake_TEST=${test}
+ --no-warn-unused-cli
+ ${RunCMake_TEST_OPTIONS}
+ WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}"
+ OUTPUT_VARIABLE actual_stdout
+ ERROR_VARIABLE actual_stderr
+ RESULT_VARIABLE actual_result
+ )
+ endif()
+ set(msg "")
+ if(NOT "${actual_result}" STREQUAL "${expect_result}")
+ set(msg "${msg}Result is [${actual_result}], not [${expect_result}].\n")
+ endif()
+ foreach(o out err)
+ string(REGEX REPLACE "(^|\n)(==[0-9]+==[^\n]*\n)+" "\\1" actual_std${o} "${actual_std${o}}")
+ string(REGEX REPLACE "\n+$" "" actual_std${o} "${actual_std${o}}")
+ set(expect_${o} "")
+ if(DEFINED expect_std${o})
+ if(NOT "${actual_std${o}}" MATCHES "${expect_std${o}}")
+ string(REGEX REPLACE "\n" "\n expect-${o}> " expect_${o}
+ " expect-${o}> ${expect_std${o}}")
+ set(expect_${o} "Expected std${o} to match:\n${expect_${o}}\n")
+ set(msg "${msg}std${o} does not match that expected.\n")
+ endif()
+ endif()
+ endforeach()
+ unset(RunCMake_TEST_FAILED)
+ include(${top_src}/${test}-check.cmake OPTIONAL)
+ if(RunCMake_TEST_FAILED)
+ set(msg "${RunCMake_TEST_FAILED}\n${msg}")
+ endif()
+ if(msg)
+ string(REGEX REPLACE "\n" "\n actual-out> " actual_out " actual-out> ${actual_stdout}")
+ string(REGEX REPLACE "\n" "\n actual-err> " actual_err " actual-err> ${actual_stderr}")
+ message(SEND_ERROR "${test} - FAILED:\n"
+ "${msg}"
+ "${expect_out}"
+ "Actual stdout:\n${actual_out}\n"
+ "${expect_err}"
+ "Actual stderr:\n${actual_err}\n"
+ )
+ else()
+ message(STATUS "${test} - PASSED")
+ endif()
+endfunction()
+
+function(run_cmake_command test)
+ set(RunCMake_TEST_COMMAND "${ARGN}")
+ run_cmake(${test})
+endfunction()
diff --git a/Tests/RunCMake/SolutionGlobalSections/CMakeLists.txt b/Tests/RunCMake/SolutionGlobalSections/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/SolutionGlobalSections/MorePost-check.cmake b/Tests/RunCMake/SolutionGlobalSections/MorePost-check.cmake
new file mode 100644
index 0000000000..0f7e37084c
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/MorePost-check.cmake
@@ -0,0 +1,5 @@
+parseGlobalSections(pre post MorePost)
+testGlobalSection(post TestSec2 Key1=Value1 "Key2=Value with spaces")
+testGlobalSection(post TestSec4 Key6=Value1 "Key7=Value with spaces" Key8=ValueWithoutSpaces)
+testGlobalSection(post ExtensibilityGlobals)
+testGlobalSection(post ExtensibilityAddIns)
diff --git a/Tests/RunCMake/SolutionGlobalSections/MorePost.cmake b/Tests/RunCMake/SolutionGlobalSections/MorePost.cmake
new file mode 100644
index 0000000000..2eb3f60af5
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/MorePost.cmake
@@ -0,0 +1,2 @@
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_POST_TestSec2 Key1=Value1 "Key2=Value with spaces")
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_POST_TestSec4 Key6=Value1 "Key7=Value with spaces" "Key8 =ValueWithoutSpaces")
diff --git a/Tests/RunCMake/SolutionGlobalSections/MorePre-check.cmake b/Tests/RunCMake/SolutionGlobalSections/MorePre-check.cmake
new file mode 100644
index 0000000000..45e7419f95
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/MorePre-check.cmake
@@ -0,0 +1,5 @@
+parseGlobalSections(pre post MorePre)
+testGlobalSection(pre TestSec1 Key1=Value1 "Key2=Value with spaces")
+testGlobalSection(pre TestSec3 Key3=Value1 "Key4=Value with spaces" Key5=ValueWithoutSpaces)
+testGlobalSection(post ExtensibilityGlobals)
+testGlobalSection(post ExtensibilityAddIns)
diff --git a/Tests/RunCMake/SolutionGlobalSections/MorePre.cmake b/Tests/RunCMake/SolutionGlobalSections/MorePre.cmake
new file mode 100644
index 0000000000..07f4eb8fcd
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/MorePre.cmake
@@ -0,0 +1,2 @@
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_PRE_TestSec1 Key1=Value1 "Key2=Value with spaces")
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_PRE_TestSec3 Key3=Value1 "Key4=Value with spaces" "Key5 = ValueWithoutSpaces")
diff --git a/Tests/RunCMake/SolutionGlobalSections/OnePost-check.cmake b/Tests/RunCMake/SolutionGlobalSections/OnePost-check.cmake
new file mode 100644
index 0000000000..6af51561be
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/OnePost-check.cmake
@@ -0,0 +1,4 @@
+parseGlobalSections(pre post OnePost)
+testGlobalSection(post TestSec2 Key1=Value1 "Key2=Value with spaces")
+testGlobalSection(post ExtensibilityGlobals)
+testGlobalSection(post ExtensibilityAddIns)
diff --git a/Tests/RunCMake/SolutionGlobalSections/OnePost.cmake b/Tests/RunCMake/SolutionGlobalSections/OnePost.cmake
new file mode 100644
index 0000000000..2295cfb017
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/OnePost.cmake
@@ -0,0 +1 @@
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_POST_TestSec2 Key1=Value1 "Key2=Value with spaces")
diff --git a/Tests/RunCMake/SolutionGlobalSections/OnePre-check.cmake b/Tests/RunCMake/SolutionGlobalSections/OnePre-check.cmake
new file mode 100644
index 0000000000..70b18b272c
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/OnePre-check.cmake
@@ -0,0 +1,4 @@
+parseGlobalSections(pre post OnePre)
+testGlobalSection(pre TestSec1 Key1=Value1 "Key2=Value with spaces")
+testGlobalSection(post ExtensibilityGlobals)
+testGlobalSection(post ExtensibilityAddIns)
diff --git a/Tests/RunCMake/SolutionGlobalSections/OnePre.cmake b/Tests/RunCMake/SolutionGlobalSections/OnePre.cmake
new file mode 100644
index 0000000000..1499b4780f
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/OnePre.cmake
@@ -0,0 +1 @@
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_PRE_TestSec1 Key1=Value1 "Key2=Value with spaces")
diff --git a/Tests/RunCMake/SolutionGlobalSections/Override1-check.cmake b/Tests/RunCMake/SolutionGlobalSections/Override1-check.cmake
new file mode 100644
index 0000000000..a19e2e1fe5
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/Override1-check.cmake
@@ -0,0 +1,4 @@
+parseGlobalSections(pre post Override1)
+testGlobalSection(post TestSec Key2=Value2 Key3=Value3)
+testGlobalSection(post ExtensibilityGlobals Key1=Value1)
+testGlobalSection(post ExtensibilityAddIns)
diff --git a/Tests/RunCMake/SolutionGlobalSections/Override1.cmake b/Tests/RunCMake/SolutionGlobalSections/Override1.cmake
new file mode 100644
index 0000000000..a726c9fd2c
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/Override1.cmake
@@ -0,0 +1,2 @@
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_POST_ExtensibilityGlobals Key1=Value1)
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_POST_TestSec Key2=Value2 Key3=Value3)
diff --git a/Tests/RunCMake/SolutionGlobalSections/Override2-check.cmake b/Tests/RunCMake/SolutionGlobalSections/Override2-check.cmake
new file mode 100644
index 0000000000..d9656e15eb
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/Override2-check.cmake
@@ -0,0 +1,4 @@
+parseGlobalSections(pre post Override2)
+testGlobalSection(pre TestSec Key2=Value2 Key3=Value3)
+testGlobalSection(post ExtensibilityGlobals)
+testGlobalSection(post ExtensibilityAddIns Key1=Value1)
diff --git a/Tests/RunCMake/SolutionGlobalSections/Override2.cmake b/Tests/RunCMake/SolutionGlobalSections/Override2.cmake
new file mode 100644
index 0000000000..0ce43cc0e3
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/Override2.cmake
@@ -0,0 +1,2 @@
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_POST_ExtensibilityAddIns Key1=Value1)
+set_property(DIRECTORY PROPERTY VS_GLOBAL_SECTION_PRE_TestSec Key2=Value2 Key3=Value3)
diff --git a/Tests/RunCMake/SolutionGlobalSections/PrePost-check.cmake b/Tests/RunCMake/SolutionGlobalSections/PrePost-check.cmake
new file mode 100644
index 0000000000..322a68931e
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/PrePost-check.cmake
@@ -0,0 +1,6 @@
+parseGlobalSections(pre post PrePost)
+testGlobalSection(post Postsec Key1=Value2)
+testGlobalSection(pre Presec Key1=Value1 "Key2=Value with some spaces")
+testGlobalSection(post Emptysec)
+testGlobalSection(post ExtensibilityGlobals)
+testGlobalSection(post ExtensibilityAddIns)
diff --git a/Tests/RunCMake/SolutionGlobalSections/PrePost.cmake b/Tests/RunCMake/SolutionGlobalSections/PrePost.cmake
new file mode 100644
index 0000000000..976c341ed9
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/PrePost.cmake
@@ -0,0 +1,4 @@
+set_directory_properties(PROPERTIES
+ VS_GLOBAL_SECTION_POST_Postsec Key1=Value2
+ VS_GLOBAL_SECTION_PRE_Presec "Key1=Value1;Key2= Value with some spaces"
+ VS_GLOBAL_SECTION_POST_Emptysec "")
diff --git a/Tests/RunCMake/SolutionGlobalSections/RunCMakeTest.cmake b/Tests/RunCMake/SolutionGlobalSections/RunCMakeTest.cmake
new file mode 100644
index 0000000000..6ae158d29e
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/RunCMakeTest.cmake
@@ -0,0 +1,10 @@
+include(RunCMake)
+include(${CMAKE_CURRENT_LIST_DIR}/solution_parsing.cmake)
+
+run_cmake(OnePre)
+run_cmake(OnePost)
+run_cmake(MorePre)
+run_cmake(MorePost)
+run_cmake(PrePost)
+run_cmake(Override1)
+run_cmake(Override2)
diff --git a/Tests/RunCMake/SolutionGlobalSections/solution_parsing.cmake b/Tests/RunCMake/SolutionGlobalSections/solution_parsing.cmake
new file mode 100644
index 0000000000..dd158efe97
--- /dev/null
+++ b/Tests/RunCMake/SolutionGlobalSections/solution_parsing.cmake
@@ -0,0 +1,60 @@
+macro(error text)
+ set(RunCMake_TEST_FAILED "${text}")
+ return()
+endmacro()
+
+
+macro(parseGlobalSections arg_out_pre arg_out_post testName)
+ set(out_pre ${arg_out_pre})
+ set(out_post ${arg_out_post})
+ set(sln "${RunCMake_TEST_BINARY_DIR}/${testName}.sln")
+ if(NOT EXISTS "${sln}")
+ error("Expected solution file ${sln} does not exist")
+ endif()
+ file(STRINGS "${sln}" lines)
+ set(sectionLines "")
+ set(store FALSE)
+ foreach(line IN LISTS lines)
+ if(line MATCHES "^\t*Global\n?$")
+ set(store TRUE)
+ elseif(line MATCHES "^\t*EndGlobal\n?$")
+ set(store FALSE)
+ elseif(store)
+ list(APPEND sectionLines "${line}")
+ endif()
+ endforeach()
+ set(sectionName "")
+ set(sectionType "")
+ foreach(line IN LISTS sectionLines)
+ if(line MATCHES "^\t*GlobalSection\\((.*)\\) *= *(pre|post)Solution\n?$")
+ set(sectionName "${CMAKE_MATCH_1}")
+ set(sectionType ${CMAKE_MATCH_2})
+ list(APPEND ${out_${sectionType}} "${sectionName}")
+ if(DEFINED ${out_${sectionType}}_${sectionName})
+ error("Section ${sectionName} defined twice")
+ endif()
+ set(${out_${sectionType}}_${sectionName} "")
+ elseif(line MATCHES "\t*EndGlobalSection\n?$")
+ set(sectionName "")
+ set(sectionType "")
+ elseif(sectionName)
+ string(REGEX MATCH "^\t*([^=]*)=([^\n]*)\n?$" matches "${line}")
+ if(NOT matches)
+ error("Bad syntax in solution file: '${line}'")
+ endif()
+ string(STRIP "${CMAKE_MATCH_1}" key)
+ string(STRIP "${CMAKE_MATCH_2}" value)
+ list(APPEND ${out_${sectionType}}_${sectionName} "${key}=${value}")
+ endif()
+ endforeach()
+endmacro()
+
+
+macro(testGlobalSection prefix sectionName)
+ if(NOT DEFINED ${prefix}_${sectionName})
+ error("Section ${sectionName} does not exist")
+ endif()
+ if(NOT "${${prefix}_${sectionName}}" STREQUAL "${ARGN}")
+ error("Section ${sectionName} content mismatch\n expected: ${ARGN}\n actual: ${${prefix}_${sectionName}}")
+ endif()
+endmacro()
diff --git a/Tests/RunCMake/Syntax/.gitattributes b/Tests/RunCMake/Syntax/.gitattributes
new file mode 100644
index 0000000000..35a9eaf2bc
--- /dev/null
+++ b/Tests/RunCMake/Syntax/.gitattributes
@@ -0,0 +1,3 @@
+CommandTabs.cmake whitespace=-tab-in-indent
+StringCRLF.cmake whitespace=cr-at-eol -crlf
+BracketCRLF.cmake whitespace=cr-at-eol -crlf
diff --git a/Tests/RunCMake/Syntax/AtWithVariable-stderr.txt b/Tests/RunCMake/Syntax/AtWithVariable-stderr.txt
new file mode 100644
index 0000000000..5dcd4d7a13
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariable-stderr.txt
@@ -0,0 +1 @@
+-->wrong<--
diff --git a/Tests/RunCMake/Syntax/AtWithVariable.cmake b/Tests/RunCMake/Syntax/AtWithVariable.cmake
new file mode 100644
index 0000000000..2bbf61db39
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariable.cmake
@@ -0,0 +1,9 @@
+set(right "wrong")
+set(var "\${right}")
+# Expanded here.
+set(ref "@var@")
+
+# 'right' is dereferenced because 'var' was dereferenced when
+# assigning to 'ref' above.
+string(CONFIGURE "${ref}" output)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/AtWithVariableAtOnly-stderr.txt b/Tests/RunCMake/Syntax/AtWithVariableAtOnly-stderr.txt
new file mode 100644
index 0000000000..cbd1be4722
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableAtOnly-stderr.txt
@@ -0,0 +1 @@
+-->\${right}<--
diff --git a/Tests/RunCMake/Syntax/AtWithVariableAtOnly.cmake b/Tests/RunCMake/Syntax/AtWithVariableAtOnly.cmake
new file mode 100644
index 0000000000..e06484c226
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableAtOnly.cmake
@@ -0,0 +1,8 @@
+set(right "wrong")
+set(var "\${right}")
+# Expanded here.
+set(ref "@var@")
+
+# No dereference done at all.
+string(CONFIGURE "${ref}" output @ONLY)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/AtWithVariableAtOnlyFile-stderr.txt b/Tests/RunCMake/Syntax/AtWithVariableAtOnlyFile-stderr.txt
new file mode 100644
index 0000000000..90bffb6c81
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableAtOnlyFile-stderr.txt
@@ -0,0 +1,5 @@
+-->==>\${right}<==
+==><==
+==>\${var}<==
+==>\${empty}<==
+<--
diff --git a/Tests/RunCMake/Syntax/AtWithVariableAtOnlyFile.cmake b/Tests/RunCMake/Syntax/AtWithVariableAtOnlyFile.cmake
new file mode 100644
index 0000000000..bdd7bcd252
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableAtOnlyFile.cmake
@@ -0,0 +1,9 @@
+set(right "wrong")
+set(var "\${right}")
+
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/atfile.txt.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/atfile.txt"
+ @ONLY)
+file(READ "${CMAKE_CURRENT_BINARY_DIR}/atfile.txt" output)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansion-stderr.txt b/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansion-stderr.txt
new file mode 100644
index 0000000000..cbd1be4722
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansion-stderr.txt
@@ -0,0 +1 @@
+-->\${right}<--
diff --git a/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansion.cmake b/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansion.cmake
new file mode 100644
index 0000000000..840c7f0d6b
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansion.cmake
@@ -0,0 +1,8 @@
+# Literal since 'var' is not defined.
+set(ref "@var@")
+set(right "wrong")
+set(var "\${right}")
+
+# 'var' is dereferenced here.
+string(CONFIGURE "${ref}" output)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansionAtOnly-stderr.txt b/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansionAtOnly-stderr.txt
new file mode 100644
index 0000000000..cbd1be4722
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansionAtOnly-stderr.txt
@@ -0,0 +1 @@
+-->\${right}<--
diff --git a/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansionAtOnly.cmake b/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansionAtOnly.cmake
new file mode 100644
index 0000000000..b657506be7
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableEmptyExpansionAtOnly.cmake
@@ -0,0 +1,8 @@
+# Literal since 'var' is not defined.
+set(ref "@var@")
+set(right "wrong")
+set(var "\${right}")
+
+# 'var' is dereferenced, but now 'right'
+string(CONFIGURE "${ref}" output @ONLY)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/AtWithVariableFile-stderr.txt b/Tests/RunCMake/Syntax/AtWithVariableFile-stderr.txt
new file mode 100644
index 0000000000..43f029fe01
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableFile-stderr.txt
@@ -0,0 +1,5 @@
+-->==>\${right}<==
+==><==
+==>\${right}<==
+==><==
+<--
diff --git a/Tests/RunCMake/Syntax/AtWithVariableFile.cmake b/Tests/RunCMake/Syntax/AtWithVariableFile.cmake
new file mode 100644
index 0000000000..c709099287
--- /dev/null
+++ b/Tests/RunCMake/Syntax/AtWithVariableFile.cmake
@@ -0,0 +1,8 @@
+set(right "wrong")
+set(var "\${right}")
+
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/atfile.txt.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/atfile.txt")
+file(READ "${CMAKE_CURRENT_BINARY_DIR}/atfile.txt" output)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt
new file mode 100644
index 0000000000..b3f1e47d14
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ File
+
+ .*/Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake
+
+ starts with a Byte-Order-Mark that is not UTF-8.
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake b/Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake
new file mode 100644
index 0000000000..c51f6e6027
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake
Binary files differ
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-LE-result.txt b/Tests/RunCMake/Syntax/BOM-UTF-16-LE-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-16-LE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt b/Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt
new file mode 100644
index 0000000000..c08c9020d2
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ File
+
+ .*/Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake
+
+ starts with a Byte-Order-Mark that is not UTF-8.
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake b/Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake
new file mode 100644
index 0000000000..b57446f25d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake
Binary files differ
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-32-BE-result.txt b/Tests/RunCMake/Syntax/BOM-UTF-32-BE-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-32-BE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt b/Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt
new file mode 100644
index 0000000000..5dde4e3333
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ File
+
+ .*/Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake
+
+ starts with a Byte-Order-Mark that is not UTF-8.
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake b/Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake
new file mode 100644
index 0000000000..23c57f3e8f
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake
Binary files differ
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-32-LE-result.txt b/Tests/RunCMake/Syntax/BOM-UTF-32-LE-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-32-LE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt b/Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt
new file mode 100644
index 0000000000..eb054ec881
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ File
+
+ .*/Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake
+
+ starts with a Byte-Order-Mark that is not UTF-8.
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake b/Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake
new file mode 100644
index 0000000000..c330f5bcb5
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake
Binary files differ
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt b/Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt
new file mode 100644
index 0000000000..5776d6e818
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt
@@ -0,0 +1 @@
+-- message
diff --git a/Tests/RunCMake/Syntax/BOM-UTF-8.cmake b/Tests/RunCMake/Syntax/BOM-UTF-8.cmake
new file mode 100644
index 0000000000..bdff83be80
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BOM-UTF-8.cmake
@@ -0,0 +1 @@
+message(STATUS "message")
diff --git a/Tests/RunCMake/Syntax/Bracket0-stderr.txt b/Tests/RunCMake/Syntax/Bracket0-stderr.txt
new file mode 100644
index 0000000000..39cc2bc814
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Bracket0-stderr.txt
@@ -0,0 +1 @@
+^1 \${var} \\n 4$
diff --git a/Tests/RunCMake/Syntax/Bracket0.cmake b/Tests/RunCMake/Syntax/Bracket0.cmake
new file mode 100644
index 0000000000..4bc017212b
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Bracket0.cmake
@@ -0,0 +1 @@
+message([[1 ${var} \n 4]])
diff --git a/Tests/RunCMake/Syntax/Bracket1-stderr.txt b/Tests/RunCMake/Syntax/Bracket1-stderr.txt
new file mode 100644
index 0000000000..e1e13c1947
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Bracket1-stderr.txt
@@ -0,0 +1 @@
+^1 \${var} \\n 4\]==$
diff --git a/Tests/RunCMake/Syntax/Bracket1.cmake b/Tests/RunCMake/Syntax/Bracket1.cmake
new file mode 100644
index 0000000000..587a57525f
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Bracket1.cmake
@@ -0,0 +1,2 @@
+message([==[1 ]==] [=[
+${var} \n 4]==]=])
diff --git a/Tests/RunCMake/Syntax/Bracket2-stdout.txt b/Tests/RunCMake/Syntax/Bracket2-stdout.txt
new file mode 100644
index 0000000000..0f8aa2fbb5
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Bracket2-stdout.txt
@@ -0,0 +1,2 @@
+-- Bracket Argument 1
+-- Bracket Argument 2
diff --git a/Tests/RunCMake/Syntax/Bracket2.cmake b/Tests/RunCMake/Syntax/Bracket2.cmake
new file mode 100644
index 0000000000..5c5feed1ac
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Bracket2.cmake
@@ -0,0 +1,2 @@
+message(STATUS [[Bracket Argument 1]] #[[Bracket Comment 1]])
+message(STATUS #[[Bracket Comment 2]] [[Bracket Argument 2]])
diff --git a/Tests/RunCMake/Syntax/BracketBackslash-result.txt b/Tests/RunCMake/Syntax/BracketBackslash-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketBackslash-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketBackslash-stderr.txt b/Tests/RunCMake/Syntax/BracketBackslash-stderr.txt
new file mode 100644
index 0000000000..b746953fc4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketBackslash-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at BracketBackslash.cmake:1 \(message\):
+ a\\
+
+ b
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/BracketBackslash.cmake b/Tests/RunCMake/Syntax/BracketBackslash.cmake
new file mode 100644
index 0000000000..5478e5d766
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketBackslash.cmake
@@ -0,0 +1,2 @@
+message(FATAL_ERROR [==[a\
+b]==])
diff --git a/Tests/RunCMake/Syntax/BracketCRLF-stderr.txt b/Tests/RunCMake/Syntax/BracketCRLF-stderr.txt
new file mode 100644
index 0000000000..7aef26ecac
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketCRLF-stderr.txt
@@ -0,0 +1 @@
+CRLF->LF worked
diff --git a/Tests/RunCMake/Syntax/BracketCRLF.cmake b/Tests/RunCMake/Syntax/BracketCRLF.cmake
new file mode 100644
index 0000000000..bda0e17efd
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketCRLF.cmake
@@ -0,0 +1,8 @@
+if([[
+]] STREQUAL "" AND
+[[a
+b]] STREQUAL "a\nb")
+ message("CRLF->LF worked")
+else()
+ message(FATAL_ERROR "CRLF->LF failed")
+endif()
diff --git a/Tests/RunCMake/Syntax/BracketComment0-stdout.txt b/Tests/RunCMake/Syntax/BracketComment0-stdout.txt
new file mode 100644
index 0000000000..c9c0be43b3
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment0-stdout.txt
@@ -0,0 +1 @@
+-- The above FATAL_ERROR did not occur.
diff --git a/Tests/RunCMake/Syntax/BracketComment0.cmake b/Tests/RunCMake/Syntax/BracketComment0.cmake
new file mode 100644
index 0000000000..0ee95de88d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment0.cmake
@@ -0,0 +1,5 @@
+#[=[
+#]]
+message(FATAL_ERROR "This is commented out.")
+#]==]=]
+message(STATUS "The above FATAL_ERROR did not occur.")
diff --git a/Tests/RunCMake/Syntax/BracketComment1-result.txt b/Tests/RunCMake/Syntax/BracketComment1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketComment1-stderr.txt b/Tests/RunCMake/Syntax/BracketComment1-stderr.txt
new file mode 100644
index 0000000000..a9373deccc
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment1-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at BracketComment1.cmake:2 \(message\):
+ This is not commented out.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/BracketComment1.cmake b/Tests/RunCMake/Syntax/BracketComment1.cmake
new file mode 100644
index 0000000000..2ec9d20167
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment1.cmake
@@ -0,0 +1,3 @@
+##[[
+message(FATAL_ERROR "This is not commented out.")
+#]]
diff --git a/Tests/RunCMake/Syntax/BracketComment2-result.txt b/Tests/RunCMake/Syntax/BracketComment2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketComment2-stderr.txt b/Tests/RunCMake/Syntax/BracketComment2-stderr.txt
new file mode 100644
index 0000000000..7e982229af
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment2-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at BracketComment2.cmake:2 \(message\):
+ This is not commented out.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/BracketComment2.cmake b/Tests/RunCMake/Syntax/BracketComment2.cmake
new file mode 100644
index 0000000000..3eda32d34c
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment2.cmake
@@ -0,0 +1,3 @@
+# [[
+message(FATAL_ERROR "This is not commented out.")
+#]]
diff --git a/Tests/RunCMake/Syntax/BracketComment3-stdout.txt b/Tests/RunCMake/Syntax/BracketComment3-stdout.txt
new file mode 100644
index 0000000000..c9c0be43b3
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment3-stdout.txt
@@ -0,0 +1 @@
+-- The above FATAL_ERROR did not occur.
diff --git a/Tests/RunCMake/Syntax/BracketComment3.cmake b/Tests/RunCMake/Syntax/BracketComment3.cmake
new file mode 100644
index 0000000000..ffd03a9311
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment3.cmake
@@ -0,0 +1,4 @@
+#[[Text on opening line
+message(FATAL_ERROR "This is commented out.")
+#]=]]
+message(STATUS "The above FATAL_ERROR did not occur.")
diff --git a/Tests/RunCMake/Syntax/BracketComment4-result.txt b/Tests/RunCMake/Syntax/BracketComment4-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment4-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketComment4-stderr.txt b/Tests/RunCMake/Syntax/BracketComment4-stderr.txt
new file mode 100644
index 0000000000..8ba32c22cd
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment4-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error: Error in cmake code at
+.*/Tests/RunCMake/Syntax/BracketComment4.cmake:3:
+Parse error. Expected a newline, got identifier with text "message".
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ BracketComment4.cmake
diff --git a/Tests/RunCMake/Syntax/BracketComment4.cmake b/Tests/RunCMake/Syntax/BracketComment4.cmake
new file mode 100644
index 0000000000..9d586f1149
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment4.cmake
@@ -0,0 +1,3 @@
+#[[
+message(FATAL_ERROR "This is commented out.")
+#]] message(STATUS "This command not allowed here")
diff --git a/Tests/RunCMake/Syntax/BracketComment5-stdout.txt b/Tests/RunCMake/Syntax/BracketComment5-stdout.txt
new file mode 100644
index 0000000000..c9c0be43b3
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment5-stdout.txt
@@ -0,0 +1 @@
+-- The above FATAL_ERROR did not occur.
diff --git a/Tests/RunCMake/Syntax/BracketComment5.cmake b/Tests/RunCMake/Syntax/BracketComment5.cmake
new file mode 100644
index 0000000000..dc9e6b48d3
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketComment5.cmake
@@ -0,0 +1,11 @@
+#[[
+message(FATAL_ERROR "This is commented out.")
+#]] #[[
+message(FATAL_ERROR "This is commented out.")
+#]]#[[
+message(FATAL_ERROR "This is commented out.")
+#]] #message(FATAL_ERROR "This is commented out.")
+#[[
+message(FATAL_ERROR "This is commented out.")
+#]]#message(FATAL_ERROR "This is commented out.")
+message(STATUS "The above FATAL_ERROR did not occur.")
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace0-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace0-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace0-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt
new file mode 100644
index 0000000000..afd91f9f2d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ Syntax Error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/BracketNoSpace0.cmake:1:27
+
+ Argument not separated from preceding token by whitespace.
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace0.cmake b/Tests/RunCMake/Syntax/BracketNoSpace0.cmake
new file mode 100644
index 0000000000..1de1450552
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace0.cmake
@@ -0,0 +1 @@
+message(STATUS [[bracket]]unquoted)
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace1-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt
new file mode 100644
index 0000000000..826e511256
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ Syntax Error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/BracketNoSpace1.cmake:1:24
+
+ Argument not separated from preceding token by whitespace.
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace1.cmake b/Tests/RunCMake/Syntax/BracketNoSpace1.cmake
new file mode 100644
index 0000000000..7982bf3c63
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace1.cmake
@@ -0,0 +1 @@
+message(STATUS "string"[[bracket]])
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace2-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt
new file mode 100644
index 0000000000..23ecdcddc1
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ Syntax Error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/BracketNoSpace2.cmake:1:44
+
+ Argument not separated from preceding token by whitespace.
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace2.cmake b/Tests/RunCMake/Syntax/BracketNoSpace2.cmake
new file mode 100644
index 0000000000..f1507f3ace
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace2.cmake
@@ -0,0 +1 @@
+message(STATUS "string"#[[bracket comment]][[bracket]])
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace3-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt
new file mode 100644
index 0000000000..906d6fc3ec
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ Syntax Error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/BracketNoSpace3.cmake:1:45
+
+ Argument not separated from preceding token by whitespace.
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace3.cmake b/Tests/RunCMake/Syntax/BracketNoSpace3.cmake
new file mode 100644
index 0000000000..45dc900ea7
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace3.cmake
@@ -0,0 +1 @@
+message(STATUS "string" #[[bracket comment]][[bracket]])
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace4-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace4-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace4-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt
new file mode 100644
index 0000000000..a461e93f7d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ Syntax Error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/BracketNoSpace4.cmake:1:44
+
+ Argument not separated from preceding token by whitespace.
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace4.cmake b/Tests/RunCMake/Syntax/BracketNoSpace4.cmake
new file mode 100644
index 0000000000..cb4ddbec87
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace4.cmake
@@ -0,0 +1 @@
+message(STATUS "string"#[[bracket comment]]"string")
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace5-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace5-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace5-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt
new file mode 100644
index 0000000000..ff8bf1c40e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+ Syntax Error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/BracketNoSpace5.cmake:1:45
+
+ Argument not separated from preceding token by whitespace.
diff --git a/Tests/RunCMake/Syntax/BracketNoSpace5.cmake b/Tests/RunCMake/Syntax/BracketNoSpace5.cmake
new file mode 100644
index 0000000000..c68452322a
--- /dev/null
+++ b/Tests/RunCMake/Syntax/BracketNoSpace5.cmake
@@ -0,0 +1 @@
+message(STATUS "string" #[[bracket comment]]"string")
diff --git a/Tests/RunCMake/Syntax/CMP0053-At-NEW-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-At-NEW-stderr.txt
new file mode 100644
index 0000000000..e3e533218c
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-At-NEW-stderr.txt
@@ -0,0 +1 @@
+^-->\${right}<--$
diff --git a/Tests/RunCMake/Syntax/CMP0053-At-NEW.cmake b/Tests/RunCMake/Syntax/CMP0053-At-NEW.cmake
new file mode 100644
index 0000000000..40dbe46c59
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-At-NEW.cmake
@@ -0,0 +1,9 @@
+cmake_policy(SET CMP0053 NEW)
+
+set(right "wrong")
+set(var "\${right}")
+# Not expanded here with the new policy.
+set(ref "@var@")
+
+string(CONFIGURE "${ref}" output)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/CMP0053-At-OLD-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-At-OLD-stderr.txt
new file mode 100644
index 0000000000..acfa30a250
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-At-OLD-stderr.txt
@@ -0,0 +1 @@
+^-->wrong<--$
diff --git a/Tests/RunCMake/Syntax/CMP0053-At-OLD.cmake b/Tests/RunCMake/Syntax/CMP0053-At-OLD.cmake
new file mode 100644
index 0000000000..666f107b8d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-At-OLD.cmake
@@ -0,0 +1,9 @@
+cmake_policy(SET CMP0053 OLD)
+
+set(right "wrong")
+set(var "\${right}")
+# Expanded here with the old policy.
+set(ref "@var@")
+
+string(CONFIGURE "${ref}" output)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/CMP0053-At-WARN-newlines-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-At-WARN-newlines-stderr.txt
new file mode 100644
index 0000000000..ec3702115d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-At-WARN-newlines-stderr.txt
@@ -0,0 +1,27 @@
+^CMake Warning \(dev\) at CMP0053-At-WARN-newlines.cmake:4 \(set\):
+ Policy CMP0053 is not set: Simplify variable reference and escape sequence
+ evaluation. Run "cmake --help-policy CMP0053" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ For input:
+
+ '
+ @var@
+ '
+
+ the old evaluation rules produce:
+
+ '
+ \${right}
+ '
+
+ but the new evaluation rules produce:
+
+ '
+ @var@
+ '
+
+ Using the old result for compatibility since the policy is not set.
+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/Syntax/CMP0053-At-WARN-newlines.cmake b/Tests/RunCMake/Syntax/CMP0053-At-WARN-newlines.cmake
new file mode 100644
index 0000000000..c493505b1a
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-At-WARN-newlines.cmake
@@ -0,0 +1,6 @@
+set(right "wrong")
+set(var "\${right}")
+# Expanded here with the old policy.
+set(ref "
+@var@
+")
diff --git a/Tests/RunCMake/Syntax/CMP0053-At-WARN-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-At-WARN-stderr.txt
new file mode 100644
index 0000000000..697b7b38ab
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-At-WARN-stderr.txt
@@ -0,0 +1,21 @@
+^CMake Warning \(dev\) at CMP0053-At-WARN.cmake:4 \(set\):
+ Policy CMP0053 is not set: Simplify variable reference and escape sequence
+ evaluation. Run "cmake --help-policy CMP0053" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ For input:
+
+ '@var@'
+
+ the old evaluation rules produce:
+
+ '\${right}'
+
+ but the new evaluation rules produce:
+
+ '@var@'
+
+ Using the old result for compatibility since the policy is not set.
+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/Syntax/CMP0053-At-WARN.cmake b/Tests/RunCMake/Syntax/CMP0053-At-WARN.cmake
new file mode 100644
index 0000000000..19c7f53394
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-At-WARN.cmake
@@ -0,0 +1,4 @@
+set(right "wrong")
+set(var "\${right}")
+# Expanded here with the old policy.
+set(ref "@var@")
diff --git a/Tests/RunCMake/Syntax/CMP0053-NUL-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-NUL-stderr.txt
new file mode 100644
index 0000000000..09c7e7c7c6
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NUL-stderr.txt
@@ -0,0 +1,56 @@
+^CMake Warning \(dev\) at CMP0053-NUL.cmake:1 \(set\):
+ Policy CMP0053 is not set: Simplify variable reference and escape sequence
+ evaluation. Run "cmake --help-policy CMP0053" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ For input:
+
+ '\\0'
+
+ the old evaluation rules produce:
+
+ ''
+
+ but the new evaluation rules produce an error:
+
+ Syntax error in cmake code at
+ .*/Tests/RunCMake/Syntax/CMP0053-NUL.cmake:1
+ when parsing string
+ \\0
+ Invalid character escape '\\0'.
+
+ Using the old result for compatibility since the policy is not set.
+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 CMP0053-NUL.cmake:2 \(set\):
+ Policy CMP0053 is not set: Simplify variable reference and escape sequence
+ evaluation. Run "cmake --help-policy CMP0053" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ For input:
+
+ '\\0'
+
+ the old evaluation rules produce:
+
+ ''
+
+ but the new evaluation rules produce an error:
+
+ Syntax error in cmake code at
+ .*/Tests/RunCMake/Syntax/CMP0053-NUL.cmake:2
+ when parsing string
+ \\0
+ Invalid character escape '\\0'.
+
+ Using the old result for compatibility since the policy is not set.
+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/Syntax/CMP0053-NUL.cmake b/Tests/RunCMake/Syntax/CMP0053-NUL.cmake
new file mode 100644
index 0000000000..9ae0906802
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NUL.cmake
@@ -0,0 +1,6 @@
+set(qnul "\0")
+set(nul \0)
+message(-->${nul}<--)
+message(-->${qnul}<--)
+message("-->${nul}<--")
+message("-->${qnul}<--")
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn-result.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn-stderr.txt
new file mode 100644
index 0000000000..9575778513
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at CMP0053-NameWithCarriageReturn.cmake:2 \(message\):
+ message called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn.cmake
new file mode 100644
index 0000000000..b8a403d181
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturn.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message(${var\rwith\rcarriagereturn})
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturnQuoted.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturnQuoted.cmake
new file mode 100644
index 0000000000..bb0d93f09d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithCarriageReturnQuoted.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message("${var\rwith\rcarriagereturn}")
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces-result.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces-stderr.txt
new file mode 100644
index 0000000000..df67d37fe8
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at CMP0053-NameWithEscapedSpaces.cmake:2 \(message\):
+ message called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces.cmake
new file mode 100644
index 0000000000..805b2ca6f6
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpaces.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message(${var\ with\ escaped\ space})
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpacesQuoted.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpacesQuoted.cmake
new file mode 100644
index 0000000000..58d8e8ff72
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedSpacesQuoted.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message("${var\ with\ escaped\ space}")
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs-result.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs-stderr.txt
new file mode 100644
index 0000000000..059044fb8c
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at CMP0053-NameWithEscapedTabs.cmake:2 \(message\):
+ message called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs.cmake
new file mode 100644
index 0000000000..214ab5de2e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabs.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message(${var\ with\ escaped\ tab})
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabsQuoted.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabsQuoted.cmake
new file mode 100644
index 0000000000..aa5123f56e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithEscapedTabsQuoted.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message("${var\ with\ escaped\ tab}")
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithNewline-result.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithNewline-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithNewline-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithNewline-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithNewline-stderr.txt
new file mode 100644
index 0000000000..41f86e69bd
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithNewline-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at CMP0053-NameWithNewline.cmake:2 \(message\):
+ message called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithNewline.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithNewline.cmake
new file mode 100644
index 0000000000..45b532e103
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithNewline.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message(${var\nwith\nnewline})
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithNewlineQuoted.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithNewlineQuoted.cmake
new file mode 100644
index 0000000000..6fe568db27
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithNewlineQuoted.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message("${var\nwith\nnewline}")
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces-result.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces-stderr.txt
new file mode 100644
index 0000000000..95e8684c9a
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at CMP0053-NameWithSpaces.cmake:2 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces.cmake:2
+
+ when parsing string
+
+ \${var
+
+ There is an unterminated variable reference.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces.cmake
new file mode 100644
index 0000000000..dae7d25489
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithSpaces.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message(${var with space})
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted-result.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted-stderr.txt
new file mode 100644
index 0000000000..c4f3cfe913
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at CMP0053-NameWithSpacesQuoted.cmake:2 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted.cmake:2
+
+ when parsing string
+
+ \${var with space}
+
+ Invalid character \(' '\) in a variable name: 'var'
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted.cmake
new file mode 100644
index 0000000000..e252cff574
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithSpacesQuoted.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message("${var with space}")
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithTabs-result.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithTabs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithTabs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithTabs-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithTabs-stderr.txt
new file mode 100644
index 0000000000..b1678b3831
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithTabs-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at CMP0053-NameWithTabs.cmake:2 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/CMP0053-NameWithTabs.cmake:2
+
+ when parsing string
+
+ \${var
+
+ There is an unterminated variable reference.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithTabs.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithTabs.cmake
new file mode 100644
index 0000000000..45e30457fd
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithTabs.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message(${var with tab})
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted-result.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted-stderr.txt
new file mode 100644
index 0000000000..78adb5e21f
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at CMP0053-NameWithTabsQuoted.cmake:2 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted.cmake:2
+
+ when parsing string
+
+ \${var with tab}
+
+ Invalid character \(' '\) in a variable name: 'var'
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted.cmake b/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted.cmake
new file mode 100644
index 0000000000..498675fe48
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-NameWithTabsQuoted.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0053 NEW)
+message("${var with tab}")
diff --git a/Tests/RunCMake/Syntax/CMP0053-ParenInENV-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-ParenInENV-stderr.txt
new file mode 100644
index 0000000000..7020c7e738
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-ParenInENV-stderr.txt
@@ -0,0 +1 @@
+-->value<--
diff --git a/Tests/RunCMake/Syntax/CMP0053-ParenInENV.cmake b/Tests/RunCMake/Syntax/CMP0053-ParenInENV.cmake
new file mode 100644
index 0000000000..b5cdf0fd1d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-ParenInENV.cmake
@@ -0,0 +1,3 @@
+cmake_policy(SET CMP0053 NEW)
+set("ENV{e(x)}" value)
+message(-->$ENV{e\(x\)}<--)
diff --git a/Tests/RunCMake/Syntax/CMP0053-ParenInQuotedENV-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-ParenInQuotedENV-stderr.txt
new file mode 100644
index 0000000000..7020c7e738
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-ParenInQuotedENV-stderr.txt
@@ -0,0 +1 @@
+-->value<--
diff --git a/Tests/RunCMake/Syntax/CMP0053-ParenInQuotedENV.cmake b/Tests/RunCMake/Syntax/CMP0053-ParenInQuotedENV.cmake
new file mode 100644
index 0000000000..5559d4b9d8
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-ParenInQuotedENV.cmake
@@ -0,0 +1,3 @@
+cmake_policy(SET CMP0053 NEW)
+set("ENV{e(x)}" value)
+message("-->$ENV{e\(x\)}<--")
diff --git a/Tests/RunCMake/Syntax/CMP0053-WARN-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-WARN-stderr.txt
new file mode 100644
index 0000000000..c7069390da
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-WARN-stderr.txt
@@ -0,0 +1,28 @@
+^CMake Warning \(dev\) at CMP0053-WARN.cmake:2 \(message\):
+ Policy CMP0053 is not set: Simplify variable reference and escape sequence
+ evaluation. Run "cmake --help-policy CMP0053" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
+ For input:
+
+ '\\'
+
+ the old evaluation rules produce:
+
+ '\\'
+
+ but the new evaluation rules produce an error:
+
+ Syntax error in cmake code at
+ .*/Tests/RunCMake/Syntax/CMP0053-WARN.cmake:2
+ when parsing string
+ \\
+ Invalid character escape '\\' \(at end of input\).
+
+ Using the old result for compatibility since the policy is not set.
+Call Stack \(most recent call first\):
+ CMP0053-WARN.cmake:5 \(escape\)
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+\\$
diff --git a/Tests/RunCMake/Syntax/CMP0053-WARN.cmake b/Tests/RunCMake/Syntax/CMP0053-WARN.cmake
new file mode 100644
index 0000000000..6e8b07bbee
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMP0053-WARN.cmake
@@ -0,0 +1,5 @@
+macro (escape str)
+ message("${str}")
+endmacro ()
+
+escape("\\")
diff --git a/Tests/RunCMake/Syntax/CMakeLists.txt b/Tests/RunCMake/Syntax/CMakeLists.txt
new file mode 100644
index 0000000000..4b3de84d94
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/Syntax/CommandComments-stderr.txt b/Tests/RunCMake/Syntax/CommandComments-stderr.txt
new file mode 100644
index 0000000000..df72cc5b9c
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandComments-stderr.txt
@@ -0,0 +1,4 @@
+Example Message
+Example Message
+Example Message
+Second Line of Example
diff --git a/Tests/RunCMake/Syntax/CommandComments.cmake b/Tests/RunCMake/Syntax/CommandComments.cmake
new file mode 100644
index 0000000000..0fd748452d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandComments.cmake
@@ -0,0 +1,6 @@
+message("Example Message"#)
+ )
+message ("Example Message" # )
+ )
+message( "Example Message\n" # "Commented" )
+ "Second Line of Example")
diff --git a/Tests/RunCMake/Syntax/CommandError0-result.txt b/Tests/RunCMake/Syntax/CommandError0-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandError0-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CommandError0-stderr.txt b/Tests/RunCMake/Syntax/CommandError0-stderr.txt
new file mode 100644
index 0000000000..24d7997adb
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandError0-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error: Error in cmake code at
+.*/Tests/RunCMake/Syntax/CommandError0.cmake:2:
+Parse error. Expected "\(", got newline with text "
+".
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ CommandError0.cmake
diff --git a/Tests/RunCMake/Syntax/CommandError0.cmake b/Tests/RunCMake/Syntax/CommandError0.cmake
new file mode 100644
index 0000000000..3222a9765a
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandError0.cmake
@@ -0,0 +1,2 @@
+message
+ ("Example Message")
diff --git a/Tests/RunCMake/Syntax/CommandError1-result.txt b/Tests/RunCMake/Syntax/CommandError1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandError1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CommandError1-stderr.txt b/Tests/RunCMake/Syntax/CommandError1-stderr.txt
new file mode 100644
index 0000000000..599f60021d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandError1-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error: Error in cmake code at
+.*/Tests/RunCMake/Syntax/CommandError1.cmake:1:
+Parse error. Expected a newline, got identifier with text "message".
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ CommandError1.cmake
diff --git a/Tests/RunCMake/Syntax/CommandError1.cmake b/Tests/RunCMake/Syntax/CommandError1.cmake
new file mode 100644
index 0000000000..f8661a198a
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandError1.cmake
@@ -0,0 +1 @@
+message("Example Message") message("Second Message")
diff --git a/Tests/RunCMake/Syntax/CommandError2-result.txt b/Tests/RunCMake/Syntax/CommandError2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandError2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/CommandError2-stderr.txt b/Tests/RunCMake/Syntax/CommandError2-stderr.txt
new file mode 100644
index 0000000000..f4dfc77494
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandError2-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error: Error in cmake code at
+.*/Tests/RunCMake/Syntax/CommandError2.cmake:1:
+Parse error. Expected a command name, got bracket argument with text "oops-not-a-comment".
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ CommandError2.cmake
diff --git a/Tests/RunCMake/Syntax/CommandError2.cmake b/Tests/RunCMake/Syntax/CommandError2.cmake
new file mode 100644
index 0000000000..a269682a03
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandError2.cmake
@@ -0,0 +1 @@
+message("Example Message") [[oops-not-a-comment]]
diff --git a/Tests/RunCMake/Syntax/CommandNewlines-stderr.txt b/Tests/RunCMake/Syntax/CommandNewlines-stderr.txt
new file mode 100644
index 0000000000..571b15227e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandNewlines-stderr.txt
@@ -0,0 +1,3 @@
+Example Message
+Example Message
+Example Message
diff --git a/Tests/RunCMake/Syntax/CommandNewlines.cmake b/Tests/RunCMake/Syntax/CommandNewlines.cmake
new file mode 100644
index 0000000000..0587afb31d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandNewlines.cmake
@@ -0,0 +1,10 @@
+message(
+ "Example Message")
+message (
+ "Example Message"
+ )
+message(
+
+ "Example Message"
+
+ )
diff --git a/Tests/RunCMake/Syntax/CommandSpaces-stderr.txt b/Tests/RunCMake/Syntax/CommandSpaces-stderr.txt
new file mode 100644
index 0000000000..54a8b38649
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandSpaces-stderr.txt
@@ -0,0 +1,6 @@
+Example Message
+Example Message
+Example Message
+Example Message
+Example Message
+Example Message
diff --git a/Tests/RunCMake/Syntax/CommandSpaces.cmake b/Tests/RunCMake/Syntax/CommandSpaces.cmake
new file mode 100644
index 0000000000..5bd42945f9
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandSpaces.cmake
@@ -0,0 +1,6 @@
+message("Example Message")
+message ("Example Message")
+message( "Example Message" )
+message( "Example Message")
+ message ( "Example Message")
+message ( Example " " Message )
diff --git a/Tests/RunCMake/Syntax/CommandTabs-stderr.txt b/Tests/RunCMake/Syntax/CommandTabs-stderr.txt
new file mode 100644
index 0000000000..54a8b38649
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandTabs-stderr.txt
@@ -0,0 +1,6 @@
+Example Message
+Example Message
+Example Message
+Example Message
+Example Message
+Example Message
diff --git a/Tests/RunCMake/Syntax/CommandTabs.cmake b/Tests/RunCMake/Syntax/CommandTabs.cmake
new file mode 100644
index 0000000000..93876f862c
--- /dev/null
+++ b/Tests/RunCMake/Syntax/CommandTabs.cmake
@@ -0,0 +1,6 @@
+message("Example Message")
+message ("Example Message")
+message( "Example Message" )
+message( "Example Message")
+ message ( "Example Message")
+message ( Example " " Message )
diff --git a/Tests/RunCMake/Syntax/Escape1-stderr.txt b/Tests/RunCMake/Syntax/Escape1-stderr.txt
new file mode 100644
index 0000000000..6601ce764f
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Escape1-stderr.txt
@@ -0,0 +1,3 @@
+^\\##\[\[#\]\]#\[\[\]\]x#\\"
+\$\@\^\\; \(\)#\\"
+\$\@\^; \(\)$
diff --git a/Tests/RunCMake/Syntax/Escape1.cmake b/Tests/RunCMake/Syntax/Escape1.cmake
new file mode 100644
index 0000000000..3bf801e642
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Escape1.cmake
@@ -0,0 +1,3 @@
+message([[\#]] \#[[ \#]] "#[[]]" x#comment
+ "\#\\\"\n\$\@\^\;\ \t\(\)"#comment
+ \#\\\"\n\$\@\^\;\ \t\(\))
diff --git a/Tests/RunCMake/Syntax/Escape2-result.txt b/Tests/RunCMake/Syntax/Escape2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Escape2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/Escape2-stderr.txt b/Tests/RunCMake/Syntax/Escape2-stderr.txt
new file mode 100644
index 0000000000..cc3bdf07b0
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Escape2-stderr.txt
@@ -0,0 +1,13 @@
+CMake Error at Escape2.cmake:4 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/Escape2.cmake:4
+
+ when parsing string
+
+ \\
+
+ Invalid character escape '\\' \(at end of input\).
+Call Stack \(most recent call first\):
+ Escape2.cmake:7 \(escape\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/Escape2.cmake b/Tests/RunCMake/Syntax/Escape2.cmake
new file mode 100644
index 0000000000..078a822892
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Escape2.cmake
@@ -0,0 +1,7 @@
+cmake_policy(SET CMP0053 NEW)
+
+macro (escape str)
+ message("${str}")
+endmacro ()
+
+escape("\\")
diff --git a/Tests/RunCMake/Syntax/EscapeChar-char-result.txt b/Tests/RunCMake/Syntax/EscapeChar-char-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapeChar-char-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/EscapeChar-char-stderr.txt.in b/Tests/RunCMake/Syntax/EscapeChar-char-stderr.txt.in
new file mode 100644
index 0000000000..d1d908cbbc
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapeChar-char-stderr.txt.in
@@ -0,0 +1,12 @@
+CMake Error at EscapeChar-@char@-@testnum@.cmake:3 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/EscapeChar-@char@-@testnum@.cmake:3
+
+ when parsing string
+
+ -->\\@char@<--
+
+ Invalid character escape '\\@char@'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/EscapeChar-char.cmake.in b/Tests/RunCMake/Syntax/EscapeChar-char.cmake.in
new file mode 100644
index 0000000000..6f265e5b22
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapeChar-char.cmake.in
@@ -0,0 +1,3 @@
+cmake_policy(SET CMP0053 NEW)
+
+message("-->\@char@<--")
diff --git a/Tests/RunCMake/Syntax/EscapeCharsAllowed-stderr.txt b/Tests/RunCMake/Syntax/EscapeCharsAllowed-stderr.txt
new file mode 100644
index 0000000000..e658de7c8a
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapeCharsAllowed-stderr.txt
@@ -0,0 +1,12 @@
+^-->semicolon<--
+-->dollar<--
+-->brace<--
+-->bracket<--
+-->newline<--
+-->octothorpe<--
+-->splat<--
+-->caret<--
+-->paren<--
+-->dquote<--
+-->top-levelsemicolon<--
+-->top-level;escaped;semicolon<--$
diff --git a/Tests/RunCMake/Syntax/EscapeCharsAllowed.cmake b/Tests/RunCMake/Syntax/EscapeCharsAllowed.cmake
new file mode 100644
index 0000000000..e9c568da05
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapeCharsAllowed.cmake
@@ -0,0 +1,26 @@
+cmake_policy(SET CMP0053 NEW)
+
+set("semicolon;in;name" semicolon)
+set("dollar$in$name" dollar)
+set("brace{in}name" brace)
+set("bracket[in]name" bracket)
+set("newline\nin\nname" newline)
+set("octothorpe\#in\#name" octothorpe)
+set("splat\@in\@name" splat)
+set("caret\^in\^name" caret)
+set("paren\(in\)name" paren)
+set("dquote\"in\"name" dquote)
+
+message("-->${semicolon\;in\;name}<--")
+message("-->${dollar\$in\$name}<--")
+message("-->${brace\{in\}name}<--")
+message("-->${bracket\[in\]name}<--")
+message("-->${newline\nin\nname}<--")
+message("-->${octothorpe\#in\#name}<--")
+message("-->${splat\@in\@name}<--")
+message("-->${caret\^in\^name}<--")
+message("-->${paren\(in\)name}<--")
+message("-->${dquote\"in\"name}<--")
+
+message(-->top-level;semicolon<--)
+message(-->top-level\;escaped\;semicolon<--)
diff --git a/Tests/RunCMake/Syntax/EscapeCharsDisallowed.cmake b/Tests/RunCMake/Syntax/EscapeCharsDisallowed.cmake
new file mode 100644
index 0000000000..eef01a082c
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapeCharsDisallowed.cmake
@@ -0,0 +1,42 @@
+set(disallowed_chars
+ a b c d e f g h i j l m o p q s u v w x y z
+ A B C D E F G H I J L M N O P Q R S T U V W X Y Z
+ 0 1 2 3 4 5 6 6 7 8 9)
+set(testnum 0)
+
+configure_file(
+ "${RunCMake_SOURCE_DIR}/CMakeLists.txt"
+ "${RunCMake_BINARY_DIR}/CMakeLists.txt"
+ COPYONLY)
+
+foreach (char IN LISTS disallowed_chars)
+ configure_file(
+ "${RunCMake_SOURCE_DIR}/EscapeChar-char.cmake.in"
+ "${RunCMake_BINARY_DIR}/EscapeChar-${char}-${testnum}.cmake"
+ @ONLY)
+ configure_file(
+ "${RunCMake_SOURCE_DIR}/EscapeChar-char-stderr.txt.in"
+ "${RunCMake_BINARY_DIR}/EscapeChar-${char}-${testnum}-stderr.txt"
+ @ONLY)
+ configure_file(
+ "${RunCMake_SOURCE_DIR}/EscapeChar-char-result.txt"
+ "${RunCMake_BINARY_DIR}/EscapeChar-${char}-${testnum}-result.txt"
+ COPYONLY)
+
+ math(EXPR testnum "${testnum} + 1")
+endforeach ()
+
+function (run_tests)
+ set(GENERATED_RUNCMAKE_TESTS TRUE)
+ # Find the tests in the binary directory.
+ set(RunCMake_SOURCE_DIR "${RunCMake_BINARY_DIR}")
+
+ set(testnum 0)
+ foreach (char IN LISTS disallowed_chars)
+ run_cmake("EscapeChar-${char}-${testnum}")
+
+ math(EXPR testnum "${testnum} + 1")
+ endforeach ()
+endfunction ()
+
+run_tests()
diff --git a/Tests/RunCMake/Syntax/EscapeQuotes-stderr.txt b/Tests/RunCMake/Syntax/EscapeQuotes-stderr.txt
new file mode 100644
index 0000000000..077272d4b4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapeQuotes-stderr.txt
@@ -0,0 +1 @@
+-->"<--
diff --git a/Tests/RunCMake/Syntax/EscapeQuotes.cmake b/Tests/RunCMake/Syntax/EscapeQuotes.cmake
new file mode 100644
index 0000000000..46d2b6f47e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapeQuotes.cmake
@@ -0,0 +1,9 @@
+set(var "\"")
+set(ref "@var@")
+set(rref "\${var}")
+
+string(CONFIGURE "${ref}" output ESCAPE_QUOTES)
+message("-->${output}<--")
+
+string(CONFIGURE "${rref}" output ESCAPE_QUOTES)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/EscapedAt-stderr.txt b/Tests/RunCMake/Syntax/EscapedAt-stderr.txt
new file mode 100644
index 0000000000..a51c0d3fa8
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapedAt-stderr.txt
@@ -0,0 +1 @@
+-->\\n<--
diff --git a/Tests/RunCMake/Syntax/EscapedAt.cmake b/Tests/RunCMake/Syntax/EscapedAt.cmake
new file mode 100644
index 0000000000..1ced62085b
--- /dev/null
+++ b/Tests/RunCMake/Syntax/EscapedAt.cmake
@@ -0,0 +1,5 @@
+set(var "n")
+set(ref "\\@var@")
+
+string(CONFIGURE "${ref}" output)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/ExpandInAt-stderr.txt b/Tests/RunCMake/Syntax/ExpandInAt-stderr.txt
new file mode 100644
index 0000000000..5da8b60c52
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ExpandInAt-stderr.txt
@@ -0,0 +1 @@
+-->@foo@<--
diff --git a/Tests/RunCMake/Syntax/ExpandInAt.cmake b/Tests/RunCMake/Syntax/ExpandInAt.cmake
new file mode 100644
index 0000000000..98f0277daf
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ExpandInAt.cmake
@@ -0,0 +1,6 @@
+set("\${varname}" bar)
+set(var foo)
+set(ref "@\${var}@")
+
+string(CONFIGURE "${ref}" output)
+message("-->${output}<--")
diff --git a/Tests/RunCMake/Syntax/ForEachBracket1-stderr.txt b/Tests/RunCMake/Syntax/ForEachBracket1-stderr.txt
new file mode 100644
index 0000000000..93c31cf058
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ForEachBracket1-stderr.txt
@@ -0,0 +1,2 @@
+^\${x}:a
+\${x}:b$
diff --git a/Tests/RunCMake/Syntax/ForEachBracket1.cmake b/Tests/RunCMake/Syntax/ForEachBracket1.cmake
new file mode 100644
index 0000000000..a55e21f07c
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ForEachBracket1.cmake
@@ -0,0 +1,3 @@
+foreach(x a b)
+ message([[${x}:]] "${x}")
+endforeach()
diff --git a/Tests/RunCMake/Syntax/FunctionBracket1-stderr.txt b/Tests/RunCMake/Syntax/FunctionBracket1-stderr.txt
new file mode 100644
index 0000000000..9ba6179a38
--- /dev/null
+++ b/Tests/RunCMake/Syntax/FunctionBracket1-stderr.txt
@@ -0,0 +1,2 @@
+^\${x},\${ARGN},\${ARGC},\${ARGV},\${ARGV0},\${ARGV1},\${ARGV2}:a,n,2,a;n,a,n,
+\${x},\${ARGN},\${ARGC},\${ARGV},\${ARGV0},\${ARGV1},\${ARGV2}:b,n,2,b;n,b,n,$
diff --git a/Tests/RunCMake/Syntax/FunctionBracket1.cmake b/Tests/RunCMake/Syntax/FunctionBracket1.cmake
new file mode 100644
index 0000000000..8ed4f6506b
--- /dev/null
+++ b/Tests/RunCMake/Syntax/FunctionBracket1.cmake
@@ -0,0 +1,6 @@
+function(fun x)
+ message([[${x},${ARGN},${ARGC},${ARGV},${ARGV0},${ARGV1},${ARGV2}:]]
+ "${x},${ARGN},${ARGC},${ARGV},${ARGV0},${ARGV1},${ARGV2}")
+endfunction(fun)
+fun(a n)
+fun(b n)
diff --git a/Tests/RunCMake/Syntax/MacroBracket1-stderr.txt b/Tests/RunCMake/Syntax/MacroBracket1-stderr.txt
new file mode 100644
index 0000000000..9ba6179a38
--- /dev/null
+++ b/Tests/RunCMake/Syntax/MacroBracket1-stderr.txt
@@ -0,0 +1,2 @@
+^\${x},\${ARGN},\${ARGC},\${ARGV},\${ARGV0},\${ARGV1},\${ARGV2}:a,n,2,a;n,a,n,
+\${x},\${ARGN},\${ARGC},\${ARGV},\${ARGV0},\${ARGV1},\${ARGV2}:b,n,2,b;n,b,n,$
diff --git a/Tests/RunCMake/Syntax/MacroBracket1.cmake b/Tests/RunCMake/Syntax/MacroBracket1.cmake
new file mode 100644
index 0000000000..ef6de20abb
--- /dev/null
+++ b/Tests/RunCMake/Syntax/MacroBracket1.cmake
@@ -0,0 +1,6 @@
+macro(mac x)
+ message([[${x},${ARGN},${ARGC},${ARGV},${ARGV0},${ARGV1},${ARGV2}:]]
+ "${x},${ARGN},${ARGC},${ARGV},${ARGV0},${ARGV1},${ARGV2}")
+endmacro(mac)
+mac(a n)
+mac(b n)
diff --git a/Tests/RunCMake/Syntax/NameWithCarriageReturn-result.txt b/Tests/RunCMake/Syntax/NameWithCarriageReturn-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithCarriageReturn-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithCarriageReturn-stderr.txt b/Tests/RunCMake/Syntax/NameWithCarriageReturn-stderr.txt
new file mode 100644
index 0000000000..7448b59cc1
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithCarriageReturn-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithCarriageReturn.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithCarriageReturn.cmake:1
+
+ when parsing string
+
+ \${var\\rwith\\rcarriagereturn}
+
+ syntax error, unexpected cal_SYMBOL, expecting } \(7\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithCarriageReturn.cmake b/Tests/RunCMake/Syntax/NameWithCarriageReturn.cmake
new file mode 100644
index 0000000000..614f554bf8
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithCarriageReturn.cmake
@@ -0,0 +1 @@
+message(${var\rwith\rcarriagereturn})
diff --git a/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted-result.txt b/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted-stderr.txt b/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted-stderr.txt
new file mode 100644
index 0000000000..f5e03edb27
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithCarriageReturnQuoted.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted.cmake:1
+
+ when parsing string
+
+ \${var\\rwith\\rcarriagereturn}
+
+ syntax error, unexpected cal_SYMBOL, expecting } \(7\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted.cmake b/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted.cmake
new file mode 100644
index 0000000000..bac69e4ee4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithCarriageReturnQuoted.cmake
@@ -0,0 +1 @@
+message("${var\rwith\rcarriagereturn}")
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedSpaces-result.txt b/Tests/RunCMake/Syntax/NameWithEscapedSpaces-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedSpaces-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedSpaces-stderr.txt b/Tests/RunCMake/Syntax/NameWithEscapedSpaces-stderr.txt
new file mode 100644
index 0000000000..fa16a8a5fb
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedSpaces-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithEscapedSpaces.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithEscapedSpaces.cmake:1
+
+ when parsing string
+
+ \${var\\ with\\ escaped\\ space}
+
+ syntax error, unexpected cal_SYMBOL, expecting } \(7\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedSpaces.cmake b/Tests/RunCMake/Syntax/NameWithEscapedSpaces.cmake
new file mode 100644
index 0000000000..6cb84014d6
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedSpaces.cmake
@@ -0,0 +1 @@
+message(${var\ with\ escaped\ space})
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted-result.txt b/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted-stderr.txt b/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted-stderr.txt
new file mode 100644
index 0000000000..07cbf24c54
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithEscapedSpacesQuoted.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted.cmake:1
+
+ when parsing string
+
+ \${var\\ with\\ escaped\\ space}
+
+ syntax error, unexpected cal_SYMBOL, expecting } \(7\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted.cmake b/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted.cmake
new file mode 100644
index 0000000000..2bd4bfd7ac
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedSpacesQuoted.cmake
@@ -0,0 +1 @@
+message("${var\ with\ escaped\ space}")
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedTabs-result.txt b/Tests/RunCMake/Syntax/NameWithEscapedTabs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedTabs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedTabs-stderr.txt b/Tests/RunCMake/Syntax/NameWithEscapedTabs-stderr.txt
new file mode 100644
index 0000000000..d7fc38a0a6
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedTabs-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithEscapedTabs.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithEscapedTabs.cmake:1
+
+ when parsing string
+
+ \${var\\ with\\ escaped\\ tab}
+
+ Invalid escape sequence \\.?
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedTabs.cmake b/Tests/RunCMake/Syntax/NameWithEscapedTabs.cmake
new file mode 100644
index 0000000000..c6faa7ab46
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedTabs.cmake
@@ -0,0 +1 @@
+message(${var\ with\ escaped\ tab})
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted-result.txt b/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted-stderr.txt b/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted-stderr.txt
new file mode 100644
index 0000000000..915dbaa477
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithEscapedTabsQuoted.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted.cmake:1
+
+ when parsing string
+
+ \${var\\ with\\ escaped\\ tab}
+
+ Invalid escape sequence \\.?
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted.cmake b/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted.cmake
new file mode 100644
index 0000000000..d9be7634a5
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithEscapedTabsQuoted.cmake
@@ -0,0 +1 @@
+message("${var\ with\ escaped\ tab}")
diff --git a/Tests/RunCMake/Syntax/NameWithNewline-result.txt b/Tests/RunCMake/Syntax/NameWithNewline-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithNewline-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithNewline-stderr.txt b/Tests/RunCMake/Syntax/NameWithNewline-stderr.txt
new file mode 100644
index 0000000000..5cc111b5c0
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithNewline-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithNewline.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithNewline.cmake:1
+
+ when parsing string
+
+ \${var\\nwith\\nnewline}
+
+ syntax error, unexpected cal_SYMBOL, expecting } \(7\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithNewline.cmake b/Tests/RunCMake/Syntax/NameWithNewline.cmake
new file mode 100644
index 0000000000..583bcb05fa
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithNewline.cmake
@@ -0,0 +1 @@
+message(${var\nwith\nnewline})
diff --git a/Tests/RunCMake/Syntax/NameWithNewlineQuoted-result.txt b/Tests/RunCMake/Syntax/NameWithNewlineQuoted-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithNewlineQuoted-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithNewlineQuoted-stderr.txt b/Tests/RunCMake/Syntax/NameWithNewlineQuoted-stderr.txt
new file mode 100644
index 0000000000..0067c2f3a1
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithNewlineQuoted-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithNewlineQuoted.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithNewlineQuoted.cmake:1
+
+ when parsing string
+
+ \${var\\nwith\\nnewline}
+
+ syntax error, unexpected cal_SYMBOL, expecting } \(7\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithNewlineQuoted.cmake b/Tests/RunCMake/Syntax/NameWithNewlineQuoted.cmake
new file mode 100644
index 0000000000..da6d2cf8d9
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithNewlineQuoted.cmake
@@ -0,0 +1 @@
+message("${var\nwith\nnewline}")
diff --git a/Tests/RunCMake/Syntax/NameWithSpaces-result.txt b/Tests/RunCMake/Syntax/NameWithSpaces-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithSpaces-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithSpaces-stderr.txt b/Tests/RunCMake/Syntax/NameWithSpaces-stderr.txt
new file mode 100644
index 0000000000..04bc2260aa
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithSpaces-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithSpaces.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithSpaces.cmake:1
+
+ when parsing string
+
+ \${var
+
+ syntax error, unexpected \$end, expecting } \(5\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithSpaces.cmake b/Tests/RunCMake/Syntax/NameWithSpaces.cmake
new file mode 100644
index 0000000000..01febe9ee0
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithSpaces.cmake
@@ -0,0 +1 @@
+message(${var with space})
diff --git a/Tests/RunCMake/Syntax/NameWithSpacesQuoted-result.txt b/Tests/RunCMake/Syntax/NameWithSpacesQuoted-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithSpacesQuoted-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithSpacesQuoted-stderr.txt b/Tests/RunCMake/Syntax/NameWithSpacesQuoted-stderr.txt
new file mode 100644
index 0000000000..66cf9a26ad
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithSpacesQuoted-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithSpacesQuoted.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithSpacesQuoted.cmake:1
+
+ when parsing string
+
+ \${var with space}
+
+ syntax error, unexpected cal_SYMBOL, expecting } \(17\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithSpacesQuoted.cmake b/Tests/RunCMake/Syntax/NameWithSpacesQuoted.cmake
new file mode 100644
index 0000000000..3fba53f54e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithSpacesQuoted.cmake
@@ -0,0 +1 @@
+message("${var with space}")
diff --git a/Tests/RunCMake/Syntax/NameWithTabs-result.txt b/Tests/RunCMake/Syntax/NameWithTabs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithTabs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithTabs-stderr.txt b/Tests/RunCMake/Syntax/NameWithTabs-stderr.txt
new file mode 100644
index 0000000000..e8880965b8
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithTabs-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithTabs.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithTabs.cmake:1
+
+ when parsing string
+
+ \${var
+
+ syntax error, unexpected \$end, expecting } \(5\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithTabs.cmake b/Tests/RunCMake/Syntax/NameWithTabs.cmake
new file mode 100644
index 0000000000..c3b1bea5a4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithTabs.cmake
@@ -0,0 +1 @@
+message(${var with tab})
diff --git a/Tests/RunCMake/Syntax/NameWithTabsQuoted-result.txt b/Tests/RunCMake/Syntax/NameWithTabsQuoted-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithTabsQuoted-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/NameWithTabsQuoted-stderr.txt b/Tests/RunCMake/Syntax/NameWithTabsQuoted-stderr.txt
new file mode 100644
index 0000000000..b020074848
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithTabsQuoted-stderr.txt
@@ -0,0 +1,12 @@
+^CMake Error at NameWithTabsQuoted.cmake:1 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/NameWithTabsQuoted.cmake:1
+
+ when parsing string
+
+ \${var with tab}
+
+ syntax error, unexpected cal_SYMBOL, expecting } \(15\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/Syntax/NameWithTabsQuoted.cmake b/Tests/RunCMake/Syntax/NameWithTabsQuoted.cmake
new file mode 100644
index 0000000000..8ddb85dcd5
--- /dev/null
+++ b/Tests/RunCMake/Syntax/NameWithTabsQuoted.cmake
@@ -0,0 +1 @@
+message("${var with tab}")
diff --git a/Tests/RunCMake/Syntax/OneLetter-stderr.txt b/Tests/RunCMake/Syntax/OneLetter-stderr.txt
new file mode 100644
index 0000000000..87c01c71c4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/OneLetter-stderr.txt
@@ -0,0 +1 @@
+message
diff --git a/Tests/RunCMake/Syntax/OneLetter.cmake b/Tests/RunCMake/Syntax/OneLetter.cmake
new file mode 100644
index 0000000000..3c341fab02
--- /dev/null
+++ b/Tests/RunCMake/Syntax/OneLetter.cmake
@@ -0,0 +1,7 @@
+function(f)
+ g(${ARGN})
+endfunction()
+macro(g)
+ message(${ARGN})
+endmacro()
+f(message)
diff --git a/Tests/RunCMake/Syntax/ParenInENV-result.txt b/Tests/RunCMake/Syntax/ParenInENV-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInENV-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/ParenInENV-stderr.txt b/Tests/RunCMake/Syntax/ParenInENV-stderr.txt
new file mode 100644
index 0000000000..7ecfe1124b
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInENV-stderr.txt
@@ -0,0 +1,20 @@
+CMake Warning \(dev\) at CMakeLists.txt:3 \(include\):
+ Syntax Warning in cmake code at
+
+ .*/Tests/RunCMake/Syntax/ParenInENV.cmake:2:21
+
+ Argument not separated from preceding token by whitespace.
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Error at ParenInENV.cmake:2 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/ParenInENV.cmake:2
+
+ when parsing string
+
+ -->\$ENV{e
+
+ syntax error, unexpected \$end, expecting } \(9\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/ParenInENV.cmake b/Tests/RunCMake/Syntax/ParenInENV.cmake
new file mode 100644
index 0000000000..148f7266d9
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInENV.cmake
@@ -0,0 +1,2 @@
+set("ENV{e(x)}" value)
+message(-->$ENV{e(x)}<--)
diff --git a/Tests/RunCMake/Syntax/ParenInQuotedENV-stderr.txt b/Tests/RunCMake/Syntax/ParenInQuotedENV-stderr.txt
new file mode 100644
index 0000000000..7020c7e738
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInQuotedENV-stderr.txt
@@ -0,0 +1 @@
+-->value<--
diff --git a/Tests/RunCMake/Syntax/ParenInQuotedENV.cmake b/Tests/RunCMake/Syntax/ParenInQuotedENV.cmake
new file mode 100644
index 0000000000..6333717406
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInQuotedENV.cmake
@@ -0,0 +1,2 @@
+set("ENV{e(x)}" value)
+message("-->$ENV{e(x)}<--")
diff --git a/Tests/RunCMake/Syntax/ParenInVarName0-result.txt b/Tests/RunCMake/Syntax/ParenInVarName0-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInVarName0-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/ParenInVarName0-stderr.txt b/Tests/RunCMake/Syntax/ParenInVarName0-stderr.txt
new file mode 100644
index 0000000000..0a6b60fb9e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInVarName0-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at ParenInVarName0.cmake:4 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/ParenInVarName0.cmake:4
+
+ when parsing string
+
+ -->\${e\(x\)}<--
+
+ Invalid character \('\('\) in a variable name: 'e'
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/ParenInVarName0.cmake b/Tests/RunCMake/Syntax/ParenInVarName0.cmake
new file mode 100644
index 0000000000..f863d20c62
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInVarName0.cmake
@@ -0,0 +1,4 @@
+cmake_policy(SET CMP0053 NEW)
+
+set("e(x)" value)
+message("-->${e(x)}<--")
diff --git a/Tests/RunCMake/Syntax/ParenInVarName1-result.txt b/Tests/RunCMake/Syntax/ParenInVarName1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInVarName1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/ParenInVarName1-stderr.txt b/Tests/RunCMake/Syntax/ParenInVarName1-stderr.txt
new file mode 100644
index 0000000000..81b17174bf
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInVarName1-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at ParenInVarName1.cmake:4 \(message\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/ParenInVarName1.cmake:4
+
+ when parsing string
+
+ -->\${e\(x\)}<--
+
+ syntax error, unexpected cal_SYMBOL, expecting } \(10\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/ParenInVarName1.cmake b/Tests/RunCMake/Syntax/ParenInVarName1.cmake
new file mode 100644
index 0000000000..9fdc87bbfc
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenInVarName1.cmake
@@ -0,0 +1,4 @@
+cmake_policy(SET CMP0053 OLD)
+
+set("{e(x)}" value)
+message("-->${e(x)}<--")
diff --git a/Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt b/Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt
new file mode 100644
index 0000000000..5c4076f67e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt
@@ -0,0 +1,3 @@
+-- \(unquoted\)
+-- \(quoted\)
+-- \(bracket\)
diff --git a/Tests/RunCMake/Syntax/ParenNoSpace0.cmake b/Tests/RunCMake/Syntax/ParenNoSpace0.cmake
new file mode 100644
index 0000000000..175fe4a80c
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenNoSpace0.cmake
@@ -0,0 +1,3 @@
+message(STATUS (unquoted))
+message(STATUS ("quoted"))
+message(STATUS ([[bracket]]))
diff --git a/Tests/RunCMake/Syntax/ParenNoSpace1-result.txt b/Tests/RunCMake/Syntax/ParenNoSpace1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenNoSpace1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt b/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt
new file mode 100644
index 0000000000..64ef8b1317
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt
@@ -0,0 +1,22 @@
+CMake Warning \(dev\) at CMakeLists.txt:3 \(include\):
+ Syntax Warning in cmake code at
+
+ .*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:1:26
+
+ Argument not separated from preceding token by whitespace.
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Warning \(dev\) at CMakeLists.txt:3 \(include\):
+ Syntax Warning in cmake code at
+
+ .*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:2:26
+
+ Argument not separated from preceding token by whitespace.
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Error at CMakeLists.txt:3 \(include\):
+ Syntax Error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:3:29
+
+ Argument not separated from preceding token by whitespace.
diff --git a/Tests/RunCMake/Syntax/ParenNoSpace1.cmake b/Tests/RunCMake/Syntax/ParenNoSpace1.cmake
new file mode 100644
index 0000000000..550339a2f5
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenNoSpace1.cmake
@@ -0,0 +1,3 @@
+message(STATUS (unquoted)unquoted)
+message(STATUS ("quoted")"quoted")
+message(STATUS ([[bracket]])[[bracket]])
diff --git a/Tests/RunCMake/Syntax/ParenNoSpace2-stderr.txt b/Tests/RunCMake/Syntax/ParenNoSpace2-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenNoSpace2-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/Syntax/ParenNoSpace2-stdout.txt b/Tests/RunCMake/Syntax/ParenNoSpace2-stdout.txt
new file mode 100644
index 0000000000..0e657b92f5
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenNoSpace2-stdout.txt
@@ -0,0 +1,3 @@
+-- unquoted\(unquoted\)
+-- quoted\(quoted\)
+-- bracket\(bracket\)
diff --git a/Tests/RunCMake/Syntax/ParenNoSpace2.cmake b/Tests/RunCMake/Syntax/ParenNoSpace2.cmake
new file mode 100644
index 0000000000..c46a887473
--- /dev/null
+++ b/Tests/RunCMake/Syntax/ParenNoSpace2.cmake
@@ -0,0 +1,3 @@
+message(STATUS unquoted(unquoted))
+message(STATUS "quoted"("quoted"))
+message(STATUS [[bracket]]([[bracket]]))
diff --git a/Tests/RunCMake/Syntax/RunCMakeTest.cmake b/Tests/RunCMake/Syntax/RunCMakeTest.cmake
new file mode 100644
index 0000000000..cecd33832f
--- /dev/null
+++ b/Tests/RunCMake/Syntax/RunCMakeTest.cmake
@@ -0,0 +1,110 @@
+include(RunCMake)
+
+run_cmake(BOM-UTF-8)
+run_cmake(BOM-UTF-16-LE)
+run_cmake(BOM-UTF-16-BE)
+run_cmake(BOM-UTF-32-LE)
+run_cmake(BOM-UTF-32-BE)
+run_cmake(CMP0053-At-OLD)
+run_cmake(CMP0053-At-NEW)
+run_cmake(CMP0053-At-WARN)
+run_cmake(CMP0053-At-WARN-newlines)
+run_cmake(CMP0053-WARN)
+run_cmake(CMP0053-NUL)
+run_cmake(CMP0053-ParenInENV)
+run_cmake(CMP0053-ParenInQuotedENV)
+run_cmake(CommandSpaces)
+run_cmake(CommandTabs)
+run_cmake(CommandNewlines)
+run_cmake(CommandComments)
+run_cmake(CommandError0)
+run_cmake(CommandError1)
+run_cmake(CommandError2)
+run_cmake(ForEachBracket1)
+run_cmake(FunctionBracket1)
+run_cmake(MacroBracket1)
+run_cmake(String0)
+run_cmake(String1)
+run_cmake(StringBackslash)
+run_cmake(StringCRLF)
+run_cmake(StringContinuation1)
+run_cmake(StringContinuation2)
+run_cmake(StringNoSpace)
+run_cmake(OneLetter)
+run_cmake(Unquoted0)
+run_cmake(Unquoted1)
+run_cmake(Unquoted2)
+run_cmake(Bracket0)
+run_cmake(Bracket1)
+run_cmake(Bracket2)
+run_cmake(BracketBackslash)
+run_cmake(BracketCRLF)
+run_cmake(BracketComment0)
+run_cmake(BracketComment1)
+run_cmake(BracketComment2)
+run_cmake(BracketComment3)
+run_cmake(BracketComment4)
+run_cmake(BracketComment5)
+run_cmake(BracketNoSpace0)
+run_cmake(BracketNoSpace1)
+run_cmake(BracketNoSpace2)
+run_cmake(BracketNoSpace3)
+run_cmake(BracketNoSpace4)
+run_cmake(BracketNoSpace5)
+run_cmake(Escape1)
+run_cmake(Escape2)
+run_cmake(EscapeCharsAllowed)
+include("${RunCMake_SOURCE_DIR}/EscapeCharsDisallowed.cmake")
+run_cmake(ParenNoSpace0)
+run_cmake(ParenNoSpace1)
+run_cmake(ParenNoSpace2)
+run_cmake(ParenInVarName0)
+run_cmake(ParenInVarName1)
+run_cmake(UnterminatedCall1)
+run_cmake(UnterminatedCall2)
+run_cmake(UnterminatedString)
+run_cmake(UnterminatedBrace0)
+run_cmake(UnterminatedBrace1)
+run_cmake(UnterminatedBrace2)
+run_cmake(UnterminatedBracket0)
+run_cmake(UnterminatedBracket1)
+run_cmake(UnterminatedBracketComment)
+
+# Variable expansion tests
+run_cmake(ExpandInAt)
+run_cmake(EscapedAt)
+run_cmake(EscapeQuotes)
+run_cmake(AtWithVariable)
+run_cmake(AtWithVariableEmptyExpansion)
+run_cmake(AtWithVariableAtOnly)
+run_cmake(AtWithVariableEmptyExpansionAtOnly)
+run_cmake(AtWithVariableFile)
+run_cmake(AtWithVariableAtOnlyFile)
+run_cmake(ParenInENV)
+run_cmake(ParenInQuotedENV)
+
+# Variable name tests
+run_cmake(NameWithSpaces)
+run_cmake(NameWithTabs)
+run_cmake(NameWithNewline)
+run_cmake(NameWithCarriageReturn)
+run_cmake(NameWithEscapedSpaces)
+run_cmake(NameWithEscapedTabs)
+run_cmake(NameWithSpacesQuoted)
+run_cmake(NameWithTabsQuoted)
+run_cmake(NameWithNewlineQuoted)
+run_cmake(NameWithCarriageReturnQuoted)
+run_cmake(NameWithEscapedSpacesQuoted)
+run_cmake(NameWithEscapedTabsQuoted)
+run_cmake(CMP0053-NameWithSpaces)
+run_cmake(CMP0053-NameWithTabs)
+run_cmake(CMP0053-NameWithNewline)
+run_cmake(CMP0053-NameWithCarriageReturn)
+run_cmake(CMP0053-NameWithEscapedSpaces)
+run_cmake(CMP0053-NameWithEscapedTabs)
+run_cmake(CMP0053-NameWithSpacesQuoted)
+run_cmake(CMP0053-NameWithTabsQuoted)
+run_cmake(CMP0053-NameWithNewlineQuoted)
+run_cmake(CMP0053-NameWithCarriageReturnQuoted)
+run_cmake(CMP0053-NameWithEscapedSpacesQuoted)
+run_cmake(CMP0053-NameWithEscapedTabsQuoted)
diff --git a/Tests/RunCMake/Syntax/String0-stderr.txt b/Tests/RunCMake/Syntax/String0-stderr.txt
new file mode 100644
index 0000000000..8eea0695c4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/String0-stderr.txt
@@ -0,0 +1 @@
+^1 2;3 4$
diff --git a/Tests/RunCMake/Syntax/String0.cmake b/Tests/RunCMake/Syntax/String0.cmake
new file mode 100644
index 0000000000..95281d73f3
--- /dev/null
+++ b/Tests/RunCMake/Syntax/String0.cmake
@@ -0,0 +1,2 @@
+set(var 2 3)
+message("1 ${var} 4")
diff --git a/Tests/RunCMake/Syntax/String1-stderr.txt b/Tests/RunCMake/Syntax/String1-stderr.txt
new file mode 100644
index 0000000000..07e98dae04
--- /dev/null
+++ b/Tests/RunCMake/Syntax/String1-stderr.txt
@@ -0,0 +1,3 @@
+^
+ 1 \${var} 4
+ $
diff --git a/Tests/RunCMake/Syntax/String1.cmake b/Tests/RunCMake/Syntax/String1.cmake
new file mode 100644
index 0000000000..a94c9ffdb4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/String1.cmake
@@ -0,0 +1,3 @@
+message("
+ 1 \${var} 4
+ ")
diff --git a/Tests/RunCMake/Syntax/StringBackslash-result.txt b/Tests/RunCMake/Syntax/StringBackslash-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringBackslash-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/StringBackslash-stderr.txt b/Tests/RunCMake/Syntax/StringBackslash-stderr.txt
new file mode 100644
index 0000000000..214f91439b
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringBackslash-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at StringBackslash.cmake:1 \(message\):
+ a\\
+
+ b
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/StringBackslash.cmake b/Tests/RunCMake/Syntax/StringBackslash.cmake
new file mode 100644
index 0000000000..066be965d4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringBackslash.cmake
@@ -0,0 +1,2 @@
+message(FATAL_ERROR "a\\
+b")
diff --git a/Tests/RunCMake/Syntax/StringCRLF-stderr.txt b/Tests/RunCMake/Syntax/StringCRLF-stderr.txt
new file mode 100644
index 0000000000..7aef26ecac
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringCRLF-stderr.txt
@@ -0,0 +1 @@
+CRLF->LF worked
diff --git a/Tests/RunCMake/Syntax/StringCRLF.cmake b/Tests/RunCMake/Syntax/StringCRLF.cmake
new file mode 100644
index 0000000000..d20cfea7e4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringCRLF.cmake
@@ -0,0 +1,6 @@
+if("a
+b" STREQUAL "a\nb")
+ message("CRLF->LF worked")
+else()
+ message(FATAL_ERROR "CRLF->LF failed")
+endif()
diff --git a/Tests/RunCMake/Syntax/StringContinuation1-result.txt b/Tests/RunCMake/Syntax/StringContinuation1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringContinuation1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/StringContinuation1-stderr.txt b/Tests/RunCMake/Syntax/StringContinuation1-stderr.txt
new file mode 100644
index 0000000000..05771da2ab
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringContinuation1-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at StringContinuation1.cmake:1 \(message\):
+ ab
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/StringContinuation1.cmake b/Tests/RunCMake/Syntax/StringContinuation1.cmake
new file mode 100644
index 0000000000..ae86bb22cb
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringContinuation1.cmake
@@ -0,0 +1,2 @@
+message(FATAL_ERROR "a\
+b")
diff --git a/Tests/RunCMake/Syntax/StringContinuation2-result.txt b/Tests/RunCMake/Syntax/StringContinuation2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringContinuation2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/StringContinuation2-stderr.txt b/Tests/RunCMake/Syntax/StringContinuation2-stderr.txt
new file mode 100644
index 0000000000..2f4964ca90
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringContinuation2-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at StringContinuation2.cmake:1 \(message\):
+ a\\b
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/StringContinuation2.cmake b/Tests/RunCMake/Syntax/StringContinuation2.cmake
new file mode 100644
index 0000000000..490a408900
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringContinuation2.cmake
@@ -0,0 +1,2 @@
+message(FATAL_ERROR "a\\\
+b")
diff --git a/Tests/RunCMake/Syntax/StringNoSpace-stderr.txt b/Tests/RunCMake/Syntax/StringNoSpace-stderr.txt
new file mode 100644
index 0000000000..89c2d2ae57
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringNoSpace-stderr.txt
@@ -0,0 +1,19 @@
+CMake Warning \(dev\) at CMakeLists.txt:3 \(include\):
+ Syntax Warning in cmake code at
+
+ .*/Tests/RunCMake/Syntax/StringNoSpace.cmake:2:28
+
+ Argument not separated from preceding token by whitespace.
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Warning \(dev\) at CMakeLists.txt:3 \(include\):
+ Syntax Warning in cmake code at
+
+ .*/Tests/RunCMake/Syntax/StringNoSpace.cmake:2:31
+
+ Argument not separated from preceding token by whitespace.
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+\[1 \${var} \\n 4\]
+\[x\]
+\[y\]$
diff --git a/Tests/RunCMake/Syntax/StringNoSpace.cmake b/Tests/RunCMake/Syntax/StringNoSpace.cmake
new file mode 100644
index 0000000000..76f22db9ae
--- /dev/null
+++ b/Tests/RunCMake/Syntax/StringNoSpace.cmake
@@ -0,0 +1,4 @@
+# Quoted arguments may be immediately followed by another argument.
+foreach(x "1 \${var} \\n 4""x"y)
+ message("[${x}]")
+endforeach()
diff --git a/Tests/RunCMake/Syntax/Unquoted0-stderr.txt b/Tests/RunCMake/Syntax/Unquoted0-stderr.txt
new file mode 100644
index 0000000000..ea68ebfa95
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Unquoted0-stderr.txt
@@ -0,0 +1 @@
+^1234$
diff --git a/Tests/RunCMake/Syntax/Unquoted0.cmake b/Tests/RunCMake/Syntax/Unquoted0.cmake
new file mode 100644
index 0000000000..c5314c9f0b
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Unquoted0.cmake
@@ -0,0 +1,2 @@
+set(var 2 3)
+message(1 ${var} 4)
diff --git a/Tests/RunCMake/Syntax/Unquoted1-stderr.txt b/Tests/RunCMake/Syntax/Unquoted1-stderr.txt
new file mode 100644
index 0000000000..85a7a9de6f
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Unquoted1-stderr.txt
@@ -0,0 +1 @@
+^\[\]\[=\]\[\$\$\(MV\)-DSTR=" \[="\[;\]\]\[$
diff --git a/Tests/RunCMake/Syntax/Unquoted1.cmake b/Tests/RunCMake/Syntax/Unquoted1.cmake
new file mode 100644
index 0000000000..515161f2b6
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Unquoted1.cmake
@@ -0,0 +1 @@
+message([] [=] [$ $(MV) -DSTR=" [=" [;] ] [)
diff --git a/Tests/RunCMake/Syntax/Unquoted2-stderr.txt b/Tests/RunCMake/Syntax/Unquoted2-stderr.txt
new file mode 100644
index 0000000000..eb8883e3f0
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Unquoted2-stderr.txt
@@ -0,0 +1 @@
+^\[\[UnquotedBracketArgument1\]\]$
diff --git a/Tests/RunCMake/Syntax/Unquoted2.cmake b/Tests/RunCMake/Syntax/Unquoted2.cmake
new file mode 100644
index 0000000000..d94057d903
--- /dev/null
+++ b/Tests/RunCMake/Syntax/Unquoted2.cmake
@@ -0,0 +1,3 @@
+cmake_policy(SET CMP0053 NEW)
+
+message(\[[Unquoted Bracket Argument 1]])
diff --git a/Tests/RunCMake/Syntax/UnterminatedBrace0-result.txt b/Tests/RunCMake/Syntax/UnterminatedBrace0-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBrace0-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/UnterminatedBrace0-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedBrace0-stderr.txt
new file mode 100644
index 0000000000..1e0ce493b4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBrace0-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at UnterminatedBrace0.cmake:2 \(set\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/UnterminatedBrace0.cmake:2
+
+ when parsing string
+
+ \${
+
+ syntax error, unexpected \$end, expecting } \(2\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/UnterminatedBrace0.cmake b/Tests/RunCMake/Syntax/UnterminatedBrace0.cmake
new file mode 100644
index 0000000000..0da12902a9
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBrace0.cmake
@@ -0,0 +1,2 @@
+cmake_minimum_required(VERSION 3.0)
+set(var "${")
diff --git a/Tests/RunCMake/Syntax/UnterminatedBrace1-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedBrace1-stderr.txt
new file mode 100644
index 0000000000..4e3c2b5639
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBrace1-stderr.txt
@@ -0,0 +1,13 @@
+CMake Warning \(dev\) at UnterminatedBrace1.cmake:3 \(set\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/UnterminatedBrace1.cmake:3
+
+ when parsing string
+
+ \${
+
+ syntax error, unexpected \$end, expecting } \(2\)
+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/Syntax/UnterminatedBrace1.cmake b/Tests/RunCMake/Syntax/UnterminatedBrace1.cmake
new file mode 100644
index 0000000000..93fba3413e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBrace1.cmake
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+cmake_policy(SET CMP0010 OLD)
+set(var "${")
diff --git a/Tests/RunCMake/Syntax/UnterminatedBrace2-result.txt b/Tests/RunCMake/Syntax/UnterminatedBrace2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBrace2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/UnterminatedBrace2-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedBrace2-stderr.txt
new file mode 100644
index 0000000000..b332d34b20
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBrace2-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at UnterminatedBrace2.cmake:4 \(set\):
+ Syntax error in cmake code at
+
+ .*/Tests/RunCMake/Syntax/UnterminatedBrace2.cmake:4
+
+ when parsing string
+
+ \${
+
+ There is an unterminated variable reference.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/UnterminatedBrace2.cmake b/Tests/RunCMake/Syntax/UnterminatedBrace2.cmake
new file mode 100644
index 0000000000..a650e5b728
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBrace2.cmake
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.0)
+cmake_policy(SET CMP0010 OLD)
+cmake_policy(SET CMP0053 NEW)
+set(var "${")
diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt b/Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket0-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedBracket0-stderr.txt
new file mode 100644
index 0000000000..3559c1893d
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBracket0-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error: Error in cmake code at
+.*/Syntax/UnterminatedBracket0.cmake:2:
+Parse error. Function missing ending "\)". Instead found unterminated bracket with text "\)
+".
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ UnterminatedBracket0.cmake$
diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket0.cmake b/Tests/RunCMake/Syntax/UnterminatedBracket0.cmake
new file mode 100644
index 0000000000..98cd906e0e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBracket0.cmake
@@ -0,0 +1 @@
+set(var [[)
diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt b/Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket1-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedBracket1-stderr.txt
new file mode 100644
index 0000000000..55d458ba2b
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBracket1-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error: Error in cmake code at
+.*/Syntax/UnterminatedBracket1.cmake:2:
+Parse error. Function missing ending "\)". Instead found unterminated bracket with text "\]\]\)
+".
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ UnterminatedBracket1.cmake$
diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket1.cmake b/Tests/RunCMake/Syntax/UnterminatedBracket1.cmake
new file mode 100644
index 0000000000..706f7a3212
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBracket1.cmake
@@ -0,0 +1 @@
+set(var [=[]])
diff --git a/Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt b/Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/UnterminatedBracketComment-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedBracketComment-stderr.txt
new file mode 100644
index 0000000000..0a799eb5a4
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBracketComment-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error: Error in cmake code at
+.*/Syntax/UnterminatedBracketComment.cmake:1:
+Parse error. Expected a command name, got unterminated bracket with text "#\]\]
+".
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ UnterminatedBracketComment.cmake
diff --git a/Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake b/Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake
new file mode 100644
index 0000000000..ad71f3c513
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake
@@ -0,0 +1,2 @@
+#[=[
+#]]
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall1-result.txt b/Tests/RunCMake/Syntax/UnterminatedCall1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedCall1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt
new file mode 100644
index 0000000000..281ce0da84
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error: Error in cmake code at
+.*/Syntax/UnterminatedCall1.cmake:2:
+Parse error. Function missing ending "\)". End of file reached.
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ UnterminatedCall1.cmake
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall1.cmake b/Tests/RunCMake/Syntax/UnterminatedCall1.cmake
new file mode 100644
index 0000000000..1166109c9f
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedCall1.cmake
@@ -0,0 +1 @@
+message(
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall2-result.txt b/Tests/RunCMake/Syntax/UnterminatedCall2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedCall2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt
new file mode 100644
index 0000000000..065de30fc3
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error: Error in cmake code at
+.*/Syntax/UnterminatedCall2.cmake:4:
+Parse error. Function missing ending "\)". End of file reached.
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ UnterminatedCall2.cmake
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall2.cmake b/Tests/RunCMake/Syntax/UnterminatedCall2.cmake
new file mode 100644
index 0000000000..26e9e62230
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedCall2.cmake
@@ -0,0 +1,3 @@
+set(var "\
+")
+message(
diff --git a/Tests/RunCMake/Syntax/UnterminatedString-result.txt b/Tests/RunCMake/Syntax/UnterminatedString-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedString-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/UnterminatedString-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedString-stderr.txt
new file mode 100644
index 0000000000..d9250328d1
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedString-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error: Error in cmake code at
+.*/Syntax/UnterminatedString.cmake:2:
+Parse error. Function missing ending "\)". Instead found unterminated string with text "\)
+".
+CMake Error at CMakeLists.txt:3 \(include\):
+ include could not find load file:
+
+ UnterminatedString.cmake$
diff --git a/Tests/RunCMake/Syntax/UnterminatedString.cmake b/Tests/RunCMake/Syntax/UnterminatedString.cmake
new file mode 100644
index 0000000000..721ae7510a
--- /dev/null
+++ b/Tests/RunCMake/Syntax/UnterminatedString.cmake
@@ -0,0 +1 @@
+set(var ")
diff --git a/Tests/RunCMake/Syntax/atfile.txt.in b/Tests/RunCMake/Syntax/atfile.txt.in
new file mode 100644
index 0000000000..3775919f65
--- /dev/null
+++ b/Tests/RunCMake/Syntax/atfile.txt.in
@@ -0,0 +1,4 @@
+==>@var@<==
+==>@empty@<==
+==>${var}<==
+==>${empty}<==
diff --git a/Tests/RunCMake/TargetObjects/BadContext-result.txt b/Tests/RunCMake/TargetObjects/BadContext-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetObjects/BadContext-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetObjects/BadContext-stderr.txt b/Tests/RunCMake/TargetObjects/BadContext-stderr.txt
new file mode 100644
index 0000000000..b78189eeaa
--- /dev/null
+++ b/Tests/RunCMake/TargetObjects/BadContext-stderr.txt
@@ -0,0 +1,27 @@
+(CMake Error at BadContext.cmake:4 \(file\):
+ Error evaluating generator expression:
+
+ \$<TARGET_OBJECTS:NoTarget>
+
+ The evaluation of the TARGET_OBJECTS generator expression is only suitable
+ for consumption by CMake. It is not suitable for writing out elsewhere.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+*)+
+(CMake Error at BadContext.cmake:5 \(file\):
+ Error evaluating generator expression:
+
+ \$<TARGET_OBJECTS:NoTarget>
+
+ The evaluation of the TARGET_OBJECTS generator expression is only suitable
+ for consumption by CMake. It is not suitable for writing out elsewhere.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+*)+
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_OBJECTS:NoTarget>
+
+ The evaluation of the TARGET_OBJECTS generator expression is only suitable
+ for consumption by CMake. It is not suitable for writing out elsewhere.
diff --git a/Tests/RunCMake/TargetObjects/BadContext.cmake b/Tests/RunCMake/TargetObjects/BadContext.cmake
new file mode 100644
index 0000000000..5d7e33e792
--- /dev/null
+++ b/Tests/RunCMake/TargetObjects/BadContext.cmake
@@ -0,0 +1,7 @@
+add_library(iface INTERFACE)
+target_sources(iface INTERFACE $<TARGET_OBJECTS:NoTarget>)
+
+file(GENERATE OUTPUT test_output CONTENT $<TARGET_OBJECTS:NoTarget>)
+file(GENERATE OUTPUT test_output2 CONTENT $<TARGET_PROPERTY:iface,INTERFACE_SOURCES>)
+
+install(FILES $<TARGET_OBJECTS:NoTarget> DESTINATION objects)
diff --git a/Tests/RunCMake/TargetObjects/CMakeLists.txt b/Tests/RunCMake/TargetObjects/CMakeLists.txt
new file mode 100644
index 0000000000..be9d4038db
--- /dev/null
+++ b/Tests/RunCMake/TargetObjects/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST})
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake
new file mode 100644
index 0000000000..85c76e240c
--- /dev/null
+++ b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake(BadContext)
diff --git a/Tests/RunCMake/TargetPolicies/CMakeLists.txt b/Tests/RunCMake/TargetPolicies/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/TargetPolicies/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/TargetPolicies/PolicyList-result.txt b/Tests/RunCMake/TargetPolicies/PolicyList-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPolicies/PolicyList-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
new file mode 100644
index 0000000000..f4b744b4b1
--- /dev/null
+++ b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
@@ -0,0 +1,22 @@
+ Error evaluating generator expression:
+
+ \$<TARGET_POLICY:NOT_A_POLICY>
+
+ \$<TARGET_POLICY:prop> may only be used with a limited number of policies.
+ Currently it may be used with the following policies:
+
+ \* CMP0003
+ \* CMP0004
+ \* CMP0008
+ \* CMP0020
+ \* CMP0021
+ \* CMP0022
+ \* CMP0027
+ \* CMP0038
+ \* CMP0041
+ \* CMP0042
+ \* CMP0046
+ \* CMP0052
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/TargetPolicies/PolicyList.cmake b/Tests/RunCMake/TargetPolicies/PolicyList.cmake
new file mode 100644
index 0000000000..c290b65a61
--- /dev/null
+++ b/Tests/RunCMake/TargetPolicies/PolicyList.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(empty empty.cpp)
+target_compile_definitions(empty
+ PRIVATE
+ $<$<TARGET_POLICY:NOT_A_POLICY>:SOME_DEFINE>
+)
diff --git a/Tests/RunCMake/TargetPolicies/RunCMakeTest.cmake b/Tests/RunCMake/TargetPolicies/RunCMakeTest.cmake
new file mode 100644
index 0000000000..7a9463050c
--- /dev/null
+++ b/Tests/RunCMake/TargetPolicies/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake(PolicyList)
diff --git a/Tests/RunCMake/TargetPolicies/empty.cpp b/Tests/RunCMake/TargetPolicies/empty.cpp
new file mode 100644
index 0000000000..7279c5e0b9
--- /dev/null
+++ b/Tests/RunCMake/TargetPolicies/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty(void)
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-stderr.txt
new file mode 100644
index 0000000000..9c146e057b
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadInvalidName1.cmake:7 \(include_directories\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:Invali/dTarget,INCLUDE_DIRECTORIES>
+
+ Target name not supported.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1.cmake
new file mode 100644
index 0000000000..d5f661d600
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1.cmake
@@ -0,0 +1,7 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:Invali/dTarget,INCLUDE_DIRECTORIES>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-stderr.txt
new file mode 100644
index 0000000000..451888cc61
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadInvalidName2.cmake:7 \(include_directories\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:Invali/dTarget,Invali/dProperty>
+
+ Target name and property name not supported.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2.cmake
new file mode 100644
index 0000000000..6e4c1d0d39
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2.cmake
@@ -0,0 +1,7 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:Invali/dTarget,Invali/dProperty>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-stderr.txt
new file mode 100644
index 0000000000..39692c4eff
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadInvalidName3.cmake:7 \(include_directories\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:Invali/dProperty>
+
+ Property name not supported.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3.cmake
new file mode 100644
index 0000000000..3f75aa3821
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3.cmake
@@ -0,0 +1,7 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:Invali/dProperty>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-stderr.txt
new file mode 100644
index 0000000000..c3aa1b1a9f
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadInvalidName4.cmake:9 \(include_directories\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:foo,Invali/dProperty>
+
+ Property name not supported.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4.cmake
new file mode 100644
index 0000000000..b616c31063
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4.cmake
@@ -0,0 +1,9 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(foo "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:foo,Invali/dProperty>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-stderr.txt
new file mode 100644
index 0000000000..1c6fad4b03
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at BadInvalidName5.cmake:7 \(include_directories\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:,>
+
+ \$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty target name and
+ property name.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5.cmake
new file mode 100644
index 0000000000..11cb6fa520
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5.cmake
@@ -0,0 +1,7 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:,>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-stderr.txt
new file mode 100644
index 0000000000..8b147dca66
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadInvalidName6.cmake:7 \(include_directories\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:,ValidProperty>
+
+ \$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty target name.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6.cmake
new file mode 100644
index 0000000000..bf868a5012
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6.cmake
@@ -0,0 +1,7 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:,ValidProperty>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-stderr.txt
new file mode 100644
index 0000000000..dad6bf86a5
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadInvalidName7.cmake:9 \(include_directories\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:foo,>
+
+ \$<TARGET_PROPERTY:...> expression requires a non-empty property name.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7.cmake
new file mode 100644
index 0000000000..36d1a79033
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7.cmake
@@ -0,0 +1,9 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(foo "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:foo,>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-stderr.txt
new file mode 100644
index 0000000000..4e8c14c990
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadInvalidName8.cmake:7 \(include_directories\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:>
+
+ \$<TARGET_PROPERTY:...> expression requires a non-empty property name.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8.cmake
new file mode 100644
index 0000000000..f059288c6d
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8.cmake
@@ -0,0 +1,7 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-stderr.txt
new file mode 100644
index 0000000000..3adf73ea0f
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at BadNonTarget.cmake:7 \(include_directories\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:NonExistent,INCLUDE_DIRECTORIES>
+
+ Target "NonExistent" not found.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget.cmake
new file mode 100644
index 0000000000..97d81e9f17
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget.cmake
@@ -0,0 +1,7 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:NonExistent,INCLUDE_DIRECTORIES>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-stderr.txt
new file mode 100644
index 0000000000..791c4a9b3c
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>
+
+ Self reference on target "TargetPropertyGeneratorExpressions".$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1.cmake
new file mode 100644
index 0000000000..a85731ecfc
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1.cmake
@@ -0,0 +1,7 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories("$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-stderr.txt
new file mode 100644
index 0000000000..791c4a9b3c
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>
+
+ Self reference on target "TargetPropertyGeneratorExpressions".$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2.cmake
new file mode 100644
index 0000000000..f1459b8cba
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2.cmake
@@ -0,0 +1,9 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+set_property(TARGET TargetPropertyGeneratorExpressions PROPERTY
+ INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>"
+)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-stderr.txt
new file mode 100644
index 0000000000..f60d726327
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES>
+
+ Self reference on target "TargetPropertyGeneratorExpressions".$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3.cmake
new file mode 100644
index 0000000000..433b730115
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3.cmake
@@ -0,0 +1,8 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+include_directories(
+ "$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES>")
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-stderr.txt
new file mode 100644
index 0000000000..f60d726327
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES>
+
+ Self reference on target "TargetPropertyGeneratorExpressions".$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4.cmake
new file mode 100644
index 0000000000..4b6445916b
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4.cmake
@@ -0,0 +1,10 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+set_property(TARGET TargetPropertyGeneratorExpressions PROPERTY
+INCLUDE_DIRECTORIES
+ "$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES>"
+)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-stderr.txt
new file mode 100644
index 0000000000..2b22d0fc3b
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:COMPILE_DEFINITIONS>
+
+ Self reference on target "TargetPropertyGeneratorExpressions".$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5.cmake
new file mode 100644
index 0000000000..74fff674d6
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5.cmake
@@ -0,0 +1,10 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+set_property(TARGET TargetPropertyGeneratorExpressions
+PROPERTY
+ COMPILE_DEFINITIONS "$<TARGET_PROPERTY:COMPILE_DEFINITIONS>"
+)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-stderr.txt
new file mode 100644
index 0000000000..fe7caa3c3a
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,COMPILE_DEFINITIONS>
+
+ Self reference on target "TargetPropertyGeneratorExpressions".$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6.cmake
new file mode 100644
index 0000000000..d6650d3a5f
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6.cmake
@@ -0,0 +1,10 @@
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main(int, char **) { return 0; }\n")
+
+add_executable(TargetPropertyGeneratorExpressions
+ "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+set_property(TARGET TargetPropertyGeneratorExpressions PROPERTY
+COMPILE_DEFINITIONS
+ "$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,COMPILE_DEFINITIONS>"
+)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/CMakeLists.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/CMakeLists.txt
new file mode 100644
index 0000000000..90afc127ed
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/CMakeLists.txt
@@ -0,0 +1,8 @@
+
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+
+# MSVC creates extra targets which pollute the stderr unless we set this.
+set(CMAKE_SUPPRESS_REGENERATION TRUE)
+
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-stderr.txt
new file mode 100644
index 0000000000..7e002f5479
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at LinkImplementationCycle1.cmake:5 \(target_link_libraries\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>
+
+ \$<TARGET_PROPERTY:...> expression in link libraries evaluation depends on
+ target property which is transitive over the link libraries, creating a
+ recursion.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1.cmake
new file mode 100644
index 0000000000..4b60214f42
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1.cmake
@@ -0,0 +1,8 @@
+
+add_library(empty1 empty.cpp)
+add_library(empty2 empty.cpp)
+
+target_link_libraries(empty1
+ LINK_PUBLIC
+ $<$<STREQUAL:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>,/foo/bar>:empty2>
+)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-stderr.txt
new file mode 100644
index 0000000000..2f72de6eca
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at LinkImplementationCycle2.cmake:5 \(target_link_libraries\):
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES>
+
+ \$<TARGET_PROPERTY:...> expression in link libraries evaluation depends on
+ target property which is transitive over the link libraries, creating a
+ recursion.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:8 \(include\)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2.cmake
new file mode 100644
index 0000000000..557eac1232
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2.cmake
@@ -0,0 +1,8 @@
+
+add_library(empty1 empty.cpp)
+add_library(empty2 empty.cpp)
+
+target_link_libraries(empty1
+ LINK_PUBLIC
+ $<$<STREQUAL:$<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES>,/foo/bar>:empty2>
+)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3.cmake
new file mode 100644
index 0000000000..0f921d457a
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle3.cmake
@@ -0,0 +1,10 @@
+
+add_library(empty1 empty.cpp)
+add_library(empty2 empty.cpp)
+
+# This is OK, because evaluating the INCLUDE_DIRECTORIES is not affected by
+# the content of the INTERFACE_LINK_LIBRARIES.
+target_link_libraries(empty1
+ INTERFACE
+ $<$<STREQUAL:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>,/foo/bar>:empty2>
+)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4-stderr.txt
new file mode 100644
index 0000000000..5cfeb0a9db
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES>
+
+ \$<TARGET_PROPERTY:...> expression in link libraries evaluation depends on
+ target property which is transitive over the link libraries, creating a
+ recursion.
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4.cmake
new file mode 100644
index 0000000000..ab6d0b2652
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle4.cmake
@@ -0,0 +1,14 @@
+
+add_library(empty1 empty.cpp)
+add_library(empty2 empty.cpp)
+
+# The INTERFACE_INCLUDE_DIRECTORIES do not depend on the link interface.
+# On its own, this is fine. It is only when used by empty3 that an error
+# is appropriately issued.
+target_link_libraries(empty1
+ INTERFACE
+ $<$<STREQUAL:$<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES>,/foo/bar>:empty2>
+)
+
+add_library(empty3 empty.cpp)
+target_link_libraries(empty3 empty1)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5-stderr.txt
new file mode 100644
index 0000000000..5cfeb0a9db
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES>
+
+ \$<TARGET_PROPERTY:...> expression in link libraries evaluation depends on
+ target property which is transitive over the link libraries, creating a
+ recursion.
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5.cmake
new file mode 100644
index 0000000000..dc180e3916
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle5.cmake
@@ -0,0 +1,10 @@
+
+add_library(empty1 INTERFACE IMPORTED)
+add_library(empty2 INTERFACE IMPORTED)
+
+set_property(TARGET empty1 PROPERTY INTERFACE_LINK_LIBRARIES
+ $<$<STREQUAL:$<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES>,/foo/bar>:empty2>
+)
+
+add_library(empty3 empty.cpp)
+target_link_libraries(empty3 empty1)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6-stderr.txt
new file mode 100644
index 0000000000..5cfeb0a9db
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES>
+
+ \$<TARGET_PROPERTY:...> expression in link libraries evaluation depends on
+ target property which is transitive over the link libraries, creating a
+ recursion.
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6.cmake
new file mode 100644
index 0000000000..91252d0740
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle6.cmake
@@ -0,0 +1,14 @@
+
+add_library(empty1 SHARED empty.cpp)
+add_library(empty2 SHARED empty.cpp)
+
+# The INTERFACE_INCLUDE_DIRECTORIES do not depend on the link interface.
+# On its own, this is fine. It is only when used by empty3 that an error
+# is appropriately issued.
+target_link_libraries(empty1
+ INTERFACE
+ $<$<STREQUAL:$<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES>,/foo/bar>:empty2>
+)
+
+add_library(empty3 SHARED empty.cpp)
+target_link_libraries(empty3 empty1)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake
new file mode 100644
index 0000000000..645a57d5f4
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake
@@ -0,0 +1,23 @@
+include(RunCMake)
+
+run_cmake(BadSelfReference1)
+run_cmake(BadSelfReference2)
+run_cmake(BadSelfReference3)
+run_cmake(BadSelfReference4)
+run_cmake(BadSelfReference5)
+run_cmake(BadSelfReference6)
+run_cmake(BadNonTarget)
+run_cmake(BadInvalidName1)
+run_cmake(BadInvalidName2)
+run_cmake(BadInvalidName3)
+run_cmake(BadInvalidName4)
+run_cmake(BadInvalidName5)
+run_cmake(BadInvalidName6)
+run_cmake(BadInvalidName7)
+run_cmake(BadInvalidName8)
+run_cmake(LinkImplementationCycle1)
+run_cmake(LinkImplementationCycle2)
+run_cmake(LinkImplementationCycle3)
+run_cmake(LinkImplementationCycle4)
+run_cmake(LinkImplementationCycle5)
+run_cmake(LinkImplementationCycle6)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/empty.cpp b/Tests/RunCMake/TargetPropertyGeneratorExpressions/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/TargetSources/CMP0026-LOCATION-result.txt b/Tests/RunCMake/TargetSources/CMP0026-LOCATION-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/CMP0026-LOCATION-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/TargetSources/CMP0026-LOCATION-stderr.txt b/Tests/RunCMake/TargetSources/CMP0026-LOCATION-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/CMP0026-LOCATION-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/TargetSources/CMP0026-LOCATION.cmake b/Tests/RunCMake/TargetSources/CMP0026-LOCATION.cmake
new file mode 100644
index 0000000000..464df36821
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/CMP0026-LOCATION.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0026 OLD)
+
+add_library(objlib OBJECT
+ empty_1.cpp
+)
+
+add_executable(my_exe
+ empty_2.cpp
+ $<TARGET_OBJECTS:objlib>
+)
+
+get_target_property( loc my_exe LOCATION)
diff --git a/Tests/RunCMake/TargetSources/CMakeLists.txt b/Tests/RunCMake/TargetSources/CMakeLists.txt
new file mode 100644
index 0000000000..f452db1770
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/TargetSources/ConfigNotAllowed-result.txt b/Tests/RunCMake/TargetSources/ConfigNotAllowed-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/ConfigNotAllowed-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetSources/ConfigNotAllowed-stderr.txt b/Tests/RunCMake/TargetSources/ConfigNotAllowed-stderr.txt
new file mode 100644
index 0000000000..1de5dd72e7
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/ConfigNotAllowed-stderr.txt
@@ -0,0 +1,14 @@
+CMake Error in CMakeLists.txt:
+ Target "somelib" has source files which vary by configuration. This is not
+ supported by the "[^"]+" generator.
+
+ Config "Debug":
+
+ .*/Tests/RunCMake/TargetSources/empty_1.cpp
+ .*/Tests/RunCMake/TargetSources/empty_2.cpp
+ .*/Tests/RunCMake/TargetSources/CMakeLists.txt
+
+ Config "Release":
+
+ .*/Tests/RunCMake/TargetSources/empty_1.cpp
+ .*/Tests/RunCMake/TargetSources/CMakeLists.txt
diff --git a/Tests/RunCMake/TargetSources/ConfigNotAllowed.cmake b/Tests/RunCMake/TargetSources/ConfigNotAllowed.cmake
new file mode 100644
index 0000000000..02af379722
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/ConfigNotAllowed.cmake
@@ -0,0 +1,2 @@
+
+add_library(somelib empty_1.cpp $<$<CONFIG:Debug>:empty_2.cpp>)
diff --git a/Tests/RunCMake/TargetSources/OriginDebug-result.txt b/Tests/RunCMake/TargetSources/OriginDebug-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/OriginDebug-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt
new file mode 100644
index 0000000000..11bc96cf98
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt
@@ -0,0 +1,31 @@
+CMake Debug Log at OriginDebug.cmake:13 \(add_library\):
+ Used sources for target OriginDebug:
+
+ \* .*Tests/RunCMake/TargetSources/empty_2.cpp
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+.*
+CMake Debug Log at OriginDebug.cmake:16 \(set_property\):
+ Used sources for target OriginDebug:
+
+ \* .*Tests/RunCMake/TargetSources/empty_3.cpp
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+.*
+CMake Debug Log at OriginDebug.cmake:20 \(target_sources\):
+ Used sources for target OriginDebug:
+
+ \* .*Tests/RunCMake/TargetSources/empty_4.cpp
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+.*
+CMake Debug Log at OriginDebug.cmake:14 \(target_link_libraries\):
+ Used sources for target OriginDebug:
+
+ \* .*Tests/RunCMake/TargetSources/empty_1.cpp
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/TargetSources/OriginDebug.cmake b/Tests/RunCMake/TargetSources/OriginDebug.cmake
new file mode 100644
index 0000000000..5fe9ba75b2
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/OriginDebug.cmake
@@ -0,0 +1,20 @@
+
+cmake_minimum_required(VERSION 3.0)
+
+project(OriginDebug)
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES SOURCES)
+
+add_library(iface INTERFACE)
+set_property(TARGET iface PROPERTY INTERFACE_SOURCES
+ empty_1.cpp
+)
+
+add_library(OriginDebug empty_2.cpp)
+target_link_libraries(OriginDebug iface)
+
+set_property(TARGET OriginDebug APPEND PROPERTY SOURCES
+ empty_3.cpp
+)
+
+target_sources(OriginDebug PRIVATE empty_4.cpp)
diff --git a/Tests/RunCMake/TargetSources/OriginDebugIDE-result.txt b/Tests/RunCMake/TargetSources/OriginDebugIDE-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/OriginDebugIDE-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt b/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt
new file mode 100644
index 0000000000..fad7073c65
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt
@@ -0,0 +1,40 @@
+CMake Debug Log at OriginDebug.cmake:13 \(add_library\):
+ Used sources for target OriginDebug:
+
+ \* .*Tests/RunCMake/TargetSources/empty_2.cpp
+
+Call Stack \(most recent call first\):
+ OriginDebugIDE.cmake:4 \(include\)
+ CMakeLists.txt:3 \(include\)
++
+CMake Debug Log at OriginDebug.cmake:16 \(set_property\):
+ Used sources for target OriginDebug:
+
+ \* .*Tests/RunCMake/TargetSources/empty_3.cpp
+
+Call Stack \(most recent call first\):
+ OriginDebugIDE.cmake:4 \(include\)
+ CMakeLists.txt:3 \(include\)
++
+CMake Debug Log at OriginDebug.cmake:20 \(target_sources\):
+ Used sources for target OriginDebug:
+
+ \* .*Tests/RunCMake/TargetSources/empty_4.cpp
+
+Call Stack \(most recent call first\):
+ OriginDebugIDE.cmake:4 \(include\)
+ CMakeLists.txt:3 \(include\)
++
+CMake Debug Log:
+ Used sources for target OriginDebug:
+
+ * .*CMakeLists.txt
++
+CMake Debug Log at OriginDebug.cmake:14 \(target_link_libraries\):
+ Used sources for target OriginDebug:
+
+ \* .*Tests/RunCMake/TargetSources/empty_1.cpp
+
+Call Stack \(most recent call first\):
+ OriginDebugIDE.cmake:4 \(include\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/TargetSources/OriginDebugIDE.cmake b/Tests/RunCMake/TargetSources/OriginDebugIDE.cmake
new file mode 100644
index 0000000000..a3cc3a8ed0
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/OriginDebugIDE.cmake
@@ -0,0 +1,4 @@
+
+# Separate test for the IDEs, because they show the CMakeLists.txt file
+# as a source file.
+include(${CMAKE_CURRENT_LIST_DIR}/OriginDebug.cmake)
diff --git a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake b/Tests/RunCMake/TargetSources/RunCMakeTest.cmake
new file mode 100644
index 0000000000..1d2eaec669
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/RunCMakeTest.cmake
@@ -0,0 +1,10 @@
+include(RunCMake)
+
+if(RunCMake_GENERATOR MATCHES "Visual Studio|Xcode" AND NOT XCODE_BELOW_2)
+ run_cmake(ConfigNotAllowed)
+ run_cmake(OriginDebugIDE)
+else()
+ run_cmake(OriginDebug)
+endif()
+
+run_cmake(CMP0026-LOCATION)
diff --git a/Tests/RunCMake/TargetSources/empty_1.cpp b/Tests/RunCMake/TargetSources/empty_1.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/empty_1.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/TargetSources/empty_2.cpp b/Tests/RunCMake/TargetSources/empty_2.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/empty_2.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/TargetSources/empty_3.cpp b/Tests/RunCMake/TargetSources/empty_3.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/empty_3.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/TargetSources/empty_4.cpp b/Tests/RunCMake/TargetSources/empty_4.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/empty_4.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/VisibilityPreset/CMakeLists.txt b/Tests/RunCMake/VisibilityPreset/CMakeLists.txt
new file mode 100644
index 0000000000..90afc127ed
--- /dev/null
+++ b/Tests/RunCMake/VisibilityPreset/CMakeLists.txt
@@ -0,0 +1,8 @@
+
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+
+# MSVC creates extra targets which pollute the stderr unless we set this.
+set(CMAKE_SUPPRESS_REGENERATION TRUE)
+
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/VisibilityPreset/PropertyTypo-result.txt b/Tests/RunCMake/VisibilityPreset/PropertyTypo-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/VisibilityPreset/PropertyTypo-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt b/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt
new file mode 100644
index 0000000000..ca8c33f363
--- /dev/null
+++ b/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt
@@ -0,0 +1 @@
+CMake Error: Target visibility_preset uses unsupported value \"hiden\" for CXX_VISIBILITY_PRESET
diff --git a/Tests/RunCMake/VisibilityPreset/PropertyTypo.cmake b/Tests/RunCMake/VisibilityPreset/PropertyTypo.cmake
new file mode 100644
index 0000000000..03c0ed9a2d
--- /dev/null
+++ b/Tests/RunCMake/VisibilityPreset/PropertyTypo.cmake
@@ -0,0 +1,3 @@
+
+add_library(visibility_preset SHARED lib.cpp)
+set_property(TARGET visibility_preset PROPERTY CXX_VISIBILITY_PRESET hiden)
diff --git a/Tests/RunCMake/VisibilityPreset/RunCMakeTest.cmake b/Tests/RunCMake/VisibilityPreset/RunCMakeTest.cmake
new file mode 100644
index 0000000000..2d78832084
--- /dev/null
+++ b/Tests/RunCMake/VisibilityPreset/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake(PropertyTypo)
diff --git a/Tests/RunCMake/VisibilityPreset/lib.cpp b/Tests/RunCMake/VisibilityPreset/lib.cpp
new file mode 100644
index 0000000000..06b3472f2a
--- /dev/null
+++ b/Tests/RunCMake/VisibilityPreset/lib.cpp
@@ -0,0 +1,5 @@
+
+int foo(void)
+{
+ return 42;
+}
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/CMakeLists.txt
new file mode 100644
index 0000000000..872338d3c6
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-stderr.txt
new file mode 100644
index 0000000000..cf8578e265
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*/Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ A prefix must be specified
+Call Stack \(most recent call first\):
+ EmptyPrefix.cmake:[0-9]+ \(write_compiler_detection_header\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix.cmake
new file mode 100644
index 0000000000..eda6b185aa
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX ""
+ VERSION 3.1
+ COMPILERS GNU
+ FEATURES cxx_final
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs-stderr.txt
new file mode 100644
index 0000000000..62c4ff1da7
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ Unparsed arguments: GarbageArg
+Call Stack \(most recent call first\):
+ ExtraArgs.cmake:4 \(write_compiler_detection_header\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs.cmake
new file mode 100644
index 0000000000..c2a21af990
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/ExtraArgs.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX Pref
+ GarbageArg
+ COMPILERS GNU
+ FEATURES cxx_final
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo-stderr.txt
new file mode 100644
index 0000000000..3c0c07689c
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ write_compiler_detection_header: FILE parameter missing.
+Call Stack \(most recent call first\):
+ FileTypo.cmake:4 \(write_compiler_detection_header\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo.cmake
new file mode 100644
index 0000000000..c90eda21e8
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/FileTypo.cmake
@@ -0,0 +1,7 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE_TYPO "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX Pref
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs-stderr.txt
new file mode 100644
index 0000000000..b4d7e08eb7
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs-stderr.txt
@@ -0,0 +1,11 @@
+CMake Error at InvalidArgs.cmake:4 \(write_compiler_detection_header\):
+ write_compiler_detection_header Function invoked with incorrect arguments
+ for function named: write_compiler_detection_header
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at InvalidArgs.cmake:6 \(write_compiler_detection_header\):
+ write_compiler_detection_header Function invoked with incorrect arguments
+ for function named: write_compiler_detection_header
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs.cmake
new file mode 100644
index 0000000000..cfebae13ed
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidArgs.cmake
@@ -0,0 +1,6 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header()
+
+write_compiler_detection_header(FILE)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature-stderr.txt
new file mode 100644
index 0000000000..f34c9e1987
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ Unsupported feature cxx_not_a_feature.
+Call Stack \(most recent call first\):
+ InvalidCXXFeature.cmake:4 \(write_compiler_detection_header\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature.cmake
new file mode 100644
index 0000000000..da870fa82d
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCXXFeature.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX PREF_
+ COMPILERS GNU
+ FEATURES cxx_not_a_feature
+ VERSION 3.1
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler-stderr.txt
new file mode 100644
index 0000000000..f35f9f9699
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ Unsupported compiler NOT_A_COMPILER.
+Call Stack \(most recent call first\):
+ InvalidCompiler.cmake:4 \(write_compiler_detection_header\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler.cmake
new file mode 100644
index 0000000000..ecd09571b5
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidCompiler.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX PREF_
+ COMPILERS NOT_A_COMPILER
+ FEATURES cxx_final
+ VERSION 3.1
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-stderr.txt
new file mode 100644
index 0000000000..0445744040
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ Unsupported feature not_a_feature.
+Call Stack \(most recent call first\):
+ InvalidFeature.cmake:4 \(write_compiler_detection_header\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature.cmake
new file mode 100644
index 0000000000..cd839686a9
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX PREF_
+ COMPILERS GNU
+ FEATURES not_a_feature
+ VERSION 3.1
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-stderr.txt
new file mode 100644
index 0000000000..ea1bf6703e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*/Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ The prefix must be a valid C identifier.
+Call Stack \(most recent call first\):
+ InvalidPrefix.cmake:[0-9]+ \(write_compiler_detection_header\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix.cmake
new file mode 100644
index 0000000000..6599f35a9e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX "0compile"
+ VERSION 3.1
+ COMPILERS GNU
+ FEATURES cxx_final
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler-stderr.txt
new file mode 100644
index 0000000000..9451348b2b
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ Invalid arguments. write_compiler_detection_header requires at least one
+ compiler.
+Call Stack \(most recent call first\):
+ NoCompiler.cmake:4 \(write_compiler_detection_header\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler.cmake
new file mode 100644
index 0000000000..2dc14e9a69
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/NoCompiler.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX PREF_
+ # COMPILERS
+ FEATURES cxx_final
+ VERSION 3.1
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature-stderr.txt
new file mode 100644
index 0000000000..193f297d23
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ Invalid arguments. write_compiler_detection_header requires at least one
+ feature.
+Call Stack \(most recent call first\):
+ NoFeature.cmake:4 \(write_compiler_detection_header\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature.cmake
new file mode 100644
index 0000000000..1fbc1292a9
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/NoFeature.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX PREF_
+ COMPILERS GNU
+ # FEATURES
+ VERSION 3.1
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion-stderr.txt
new file mode 100644
index 0000000000..8d4db34313
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ VERSION compatibility for write_compiler_detection_header is set to 3.0,
+ which is too low. It must be set to at least 3.1.0. Either set the
+ VERSION parameter to the write_compiler_detection_header function, or
+ update your minimum required CMake version with the cmake_minimum_required
+ command.
+Call Stack \(most recent call first\):
+ OldVersion.cmake:4 \(write_compiler_detection_header\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion.cmake
new file mode 100644
index 0000000000..a6e30224cc
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/OldVersion.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX Pref
+ VERSION 3.0
+ COMPILERS GNU
+ FEATURES cxx_final
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo-stderr.txt
new file mode 100644
index 0000000000..5fdcdb83f8
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ write_compiler_detection_header: PREFIX parameter missing.
+Call Stack \(most recent call first\):
+ PrefixTypo.cmake:4 \(write_compiler_detection_header\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo.cmake
new file mode 100644
index 0000000000..8b6774c44a
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/PrefixTypo.cmake
@@ -0,0 +1,7 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX_TYPO Pref
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/RunCMakeTest.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/RunCMakeTest.cmake
new file mode 100644
index 0000000000..6dded44a6b
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/RunCMakeTest.cmake
@@ -0,0 +1,14 @@
+include(RunCMake)
+
+run_cmake(InvalidArgs)
+run_cmake(NoCompiler)
+run_cmake(NoFeature)
+run_cmake(FileTypo)
+run_cmake(PrefixTypo)
+run_cmake(ExtraArgs)
+run_cmake(OldVersion)
+run_cmake(InvalidCompiler)
+run_cmake(InvalidFeature)
+run_cmake(InvalidCXXFeature)
+run_cmake(EmptyPrefix)
+run_cmake(InvalidPrefix)
diff --git a/Tests/RunCMake/XcodeProject/CMakeLists.txt b/Tests/RunCMake/XcodeProject/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
new file mode 100644
index 0000000000..8e4026ba0b
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake(XcodeFileType)
diff --git a/Tests/RunCMake/XcodeProject/XcodeFileType-check.cmake b/Tests/RunCMake/XcodeProject/XcodeFileType-check.cmake
new file mode 100644
index 0000000000..7882d7f13b
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeFileType-check.cmake
@@ -0,0 +1,10 @@
+set(expect-default "explicitFileType = sourcecode")
+set(expect-explicit "explicitFileType = \"sourcecode.c.h\"")
+set(expect-lastKnown "lastKnownFileType = \"sourcecode.c.h\"")
+foreach(src default explicit lastKnown)
+ file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodeFileType.xcodeproj/project.pbxproj actual-${src}
+ REGEX "PBXFileReference.*src-${src}")
+ if(NOT actual-${src} MATCHES "${expect-${src}}")
+ message(SEND_ERROR "src-${src} does not match '${expect-${src}}':\n ${actual-${src}}")
+ endif()
+endforeach()
diff --git a/Tests/RunCMake/XcodeProject/XcodeFileType.cmake b/Tests/RunCMake/XcodeProject/XcodeFileType.cmake
new file mode 100644
index 0000000000..7faa781518
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeFileType.cmake
@@ -0,0 +1,4 @@
+enable_language(C)
+add_executable(main main.c src-default src-explicit src-lastKnown)
+set_property(SOURCE src-explicit PROPERTY XCODE_EXPLICIT_FILE_TYPE sourcecode.c.h)
+set_property(SOURCE src-lastKnown PROPERTY XCODE_LAST_KNOWN_FILE_TYPE sourcecode.c.h)
diff --git a/Tests/RunCMake/XcodeProject/main.c b/Tests/RunCMake/XcodeProject/main.c
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/main.c
diff --git a/Tests/RunCMake/XcodeProject/src-default b/Tests/RunCMake/XcodeProject/src-default
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/src-default
diff --git a/Tests/RunCMake/XcodeProject/src-explicit b/Tests/RunCMake/XcodeProject/src-explicit
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/src-explicit
diff --git a/Tests/RunCMake/XcodeProject/src-lastKnown b/Tests/RunCMake/XcodeProject/src-lastKnown
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/src-lastKnown
diff --git a/Tests/RunCMake/add_dependencies/CMakeLists.txt b/Tests/RunCMake/add_dependencies/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/add_dependencies/NoTarget-result.txt b/Tests/RunCMake/add_dependencies/NoTarget-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/NoTarget-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/add_dependencies/NoTarget-stderr.txt b/Tests/RunCMake/add_dependencies/NoTarget-stderr.txt
new file mode 100644
index 0000000000..6af27074f5
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/NoTarget-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at NoTarget.cmake:1 \(add_dependencies\):
+ Cannot add target-level dependencies to non-existent target "foo".
+
+ The add_dependencies works for top-level logical targets created by the
+ add_executable, add_library, or add_custom_target commands. If you want to
+ add file-level dependencies see the DEPENDS option of the add_custom_target
+ and add_custom_command commands.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/add_dependencies/NoTarget.cmake b/Tests/RunCMake/add_dependencies/NoTarget.cmake
new file mode 100644
index 0000000000..9037694170
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/NoTarget.cmake
@@ -0,0 +1 @@
+add_dependencies(foo bar)
diff --git a/Tests/RunCMake/add_dependencies/RunCMakeTest.cmake b/Tests/RunCMake/add_dependencies/RunCMakeTest.cmake
new file mode 100644
index 0000000000..30b7e674f8
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake(NoTarget)
diff --git a/Tests/RunCMake/alias_targets/CMakeLists.txt b/Tests/RunCMake/alias_targets/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
new file mode 100644
index 0000000000..9a5eaaf1c5
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
@@ -0,0 +1,20 @@
+include(RunCMake)
+
+run_cmake(no-targets)
+run_cmake(multiple-targets)
+run_cmake(exclude-from-all)
+run_cmake(imported)
+run_cmake(invalid-name)
+run_cmake(invalid-target)
+run_cmake(imported-target)
+run_cmake(alias-target)
+run_cmake(set_property)
+run_cmake(set_target_properties)
+run_cmake(target_link_libraries)
+run_cmake(target_include_directories)
+run_cmake(export)
+run_cmake(install-export)
+run_cmake(name-conflict)
+run_cmake(add_dependencies)
+run_cmake(add_executable-library)
+run_cmake(add_library-executable)
diff --git a/Tests/RunCMake/alias_targets/add_dependencies-result.txt b/Tests/RunCMake/alias_targets/add_dependencies-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/add_dependencies-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/add_dependencies-stderr.txt b/Tests/RunCMake/alias_targets/add_dependencies-stderr.txt
new file mode 100644
index 0000000000..53f248741f
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/add_dependencies-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at add_dependencies.cmake:9 \(add_dependencies\):
+ Cannot add target-level dependencies to alias target "alias".
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/add_dependencies.cmake b/Tests/RunCMake/alias_targets/add_dependencies.cmake
new file mode 100644
index 0000000000..7436371a22
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/add_dependencies.cmake
@@ -0,0 +1,9 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+add_library(bar empty.cpp)
+
+add_library(alias ALIAS foo)
+
+add_dependencies(alias bar)
diff --git a/Tests/RunCMake/alias_targets/add_executable-library-result.txt b/Tests/RunCMake/alias_targets/add_executable-library-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/add_executable-library-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/add_executable-library-stderr.txt b/Tests/RunCMake/alias_targets/add_executable-library-stderr.txt
new file mode 100644
index 0000000000..eb22b3dbec
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/add_executable-library-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at add_executable-library.cmake:6 \(add_executable\):
+ add_executable cannot create ALIAS target "alias" because target "foo" is
+ not an executable.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/add_executable-library.cmake b/Tests/RunCMake/alias_targets/add_executable-library.cmake
new file mode 100644
index 0000000000..e30f112d84
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/add_executable-library.cmake
@@ -0,0 +1,6 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_executable(alias ALIAS foo)
diff --git a/Tests/RunCMake/alias_targets/add_library-executable-result.txt b/Tests/RunCMake/alias_targets/add_library-executable-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/add_library-executable-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/add_library-executable-stderr.txt b/Tests/RunCMake/alias_targets/add_library-executable-stderr.txt
new file mode 100644
index 0000000000..ee290e4411
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/add_library-executable-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at add_library-executable.cmake:6 \(add_library\):
+ add_library cannot create ALIAS target "alias" because target "foo" is not
+ a library.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/add_library-executable.cmake b/Tests/RunCMake/alias_targets/add_library-executable.cmake
new file mode 100644
index 0000000000..22457a9b73
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/add_library-executable.cmake
@@ -0,0 +1,6 @@
+
+enable_language(CXX)
+
+add_executable(foo empty.cpp)
+
+add_library(alias ALIAS foo)
diff --git a/Tests/RunCMake/alias_targets/alias-target-result.txt b/Tests/RunCMake/alias_targets/alias-target-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/alias-target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/alias-target-stderr.txt b/Tests/RunCMake/alias_targets/alias-target-stderr.txt
new file mode 100644
index 0000000000..eae227a256
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/alias-target-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at alias-target.cmake:8 \(add_library\):
+ add_library cannot create ALIAS target "next_alias" because target "alias"
+ is itself an ALIAS.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/alias-target.cmake b/Tests/RunCMake/alias_targets/alias-target.cmake
new file mode 100644
index 0000000000..0b8da6014b
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/alias-target.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_library(alias ALIAS foo)
+
+add_library(next_alias ALIAS alias)
diff --git a/Tests/RunCMake/alias_targets/empty.cpp b/Tests/RunCMake/alias_targets/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/alias_targets/exclude-from-all-result.txt b/Tests/RunCMake/alias_targets/exclude-from-all-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/exclude-from-all-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/exclude-from-all-stderr.txt b/Tests/RunCMake/alias_targets/exclude-from-all-stderr.txt
new file mode 100644
index 0000000000..fce15d3847
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/exclude-from-all-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at exclude-from-all.cmake:6 \(add_library\):
+ add_library EXCLUDE_FROM_ALL with ALIAS makes no sense.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/exclude-from-all.cmake b/Tests/RunCMake/alias_targets/exclude-from-all.cmake
new file mode 100644
index 0000000000..0091918fe3
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/exclude-from-all.cmake
@@ -0,0 +1,6 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_library(alias ALIAS EXCLUDE_FROM_ALL foo)
diff --git a/Tests/RunCMake/alias_targets/export-result.txt b/Tests/RunCMake/alias_targets/export-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/export-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/export-stderr.txt b/Tests/RunCMake/alias_targets/export-stderr.txt
new file mode 100644
index 0000000000..848b9840c7
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/export-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at export.cmake:8 \(export\):
+ export given ALIAS target "alias" which may not be exported.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/export.cmake b/Tests/RunCMake/alias_targets/export.cmake
new file mode 100644
index 0000000000..dd84a80da2
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/export.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_library(alias ALIAS foo)
+
+export(TARGETS alias FILE someFile.cmake)
diff --git a/Tests/RunCMake/alias_targets/imported-result.txt b/Tests/RunCMake/alias_targets/imported-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/imported-stderr.txt b/Tests/RunCMake/alias_targets/imported-stderr.txt
new file mode 100644
index 0000000000..b905847f25
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at imported.cmake:2 \(add_library\):
+ add_library IMPORTED with ALIAS is not allowed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/imported-target-result.txt b/Tests/RunCMake/alias_targets/imported-target-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported-target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/imported-target-stderr.txt b/Tests/RunCMake/alias_targets/imported-target-stderr.txt
new file mode 100644
index 0000000000..bbff29a804
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported-target-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at imported-target.cmake:6 \(add_library\):
+ add_library cannot create ALIAS target "alias" because target "foo" is
+ IMPORTED.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/imported-target.cmake b/Tests/RunCMake/alias_targets/imported-target.cmake
new file mode 100644
index 0000000000..7259ab0912
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported-target.cmake
@@ -0,0 +1,6 @@
+
+enable_language(CXX)
+
+add_library(foo SHARED IMPORTED)
+
+add_library(alias ALIAS foo)
diff --git a/Tests/RunCMake/alias_targets/imported.cmake b/Tests/RunCMake/alias_targets/imported.cmake
new file mode 100644
index 0000000000..6a605911a7
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported.cmake
@@ -0,0 +1,2 @@
+
+add_library(alias IMPORTED ALIAS)
diff --git a/Tests/RunCMake/alias_targets/install-export-result.txt b/Tests/RunCMake/alias_targets/install-export-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/install-export-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/install-export-stderr.txt b/Tests/RunCMake/alias_targets/install-export-stderr.txt
new file mode 100644
index 0000000000..3c3c0edd63
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/install-export-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at install-export.cmake:8 \(install\):
+ install TARGETS given target "alias" which is an alias.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/install-export.cmake b/Tests/RunCMake/alias_targets/install-export.cmake
new file mode 100644
index 0000000000..b1c6a4f4d4
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/install-export.cmake
@@ -0,0 +1,9 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_library(alias ALIAS foo)
+
+install(TARGETS alias EXPORT theTargets DESTINATION prefix)
+install(EXPORT theTargets DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/alias_targets/invalid-name-result.txt b/Tests/RunCMake/alias_targets/invalid-name-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/invalid-name-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/invalid-name-stderr.txt b/Tests/RunCMake/alias_targets/invalid-name-stderr.txt
new file mode 100644
index 0000000000..d33b57c105
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/invalid-name-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at invalid-name.cmake:6 \(add_library\):
+ add_library Invalid name for ALIAS: invalid\$name
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/invalid-name.cmake b/Tests/RunCMake/alias_targets/invalid-name.cmake
new file mode 100644
index 0000000000..bbd39e3b6f
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/invalid-name.cmake
@@ -0,0 +1,6 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_library(invalid$name ALIAS foo)
diff --git a/Tests/RunCMake/alias_targets/invalid-target-result.txt b/Tests/RunCMake/alias_targets/invalid-target-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/invalid-target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/invalid-target-stderr.txt b/Tests/RunCMake/alias_targets/invalid-target-stderr.txt
new file mode 100644
index 0000000000..342d488b90
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/invalid-target-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at invalid-target.cmake:2 \(add_library\):
+ add_library cannot create ALIAS target "alias" because target "foo" does
+ not already exist.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/invalid-target.cmake b/Tests/RunCMake/alias_targets/invalid-target.cmake
new file mode 100644
index 0000000000..c43da61623
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/invalid-target.cmake
@@ -0,0 +1,2 @@
+
+add_library(alias ALIAS foo)
diff --git a/Tests/RunCMake/alias_targets/multiple-targets-result.txt b/Tests/RunCMake/alias_targets/multiple-targets-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/multiple-targets-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/multiple-targets-stderr.txt b/Tests/RunCMake/alias_targets/multiple-targets-stderr.txt
new file mode 100644
index 0000000000..596f404e40
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/multiple-targets-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at multiple-targets.cmake:7 \(add_library\):
+ add_library ALIAS requires exactly one target argument.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/multiple-targets.cmake b/Tests/RunCMake/alias_targets/multiple-targets.cmake
new file mode 100644
index 0000000000..811eb7a534
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/multiple-targets.cmake
@@ -0,0 +1,7 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+add_library(bar empty.cpp)
+
+add_library(alias ALIAS foo bar)
diff --git a/Tests/RunCMake/alias_targets/name-conflict-result.txt b/Tests/RunCMake/alias_targets/name-conflict-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/name-conflict-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/name-conflict-stderr.txt b/Tests/RunCMake/alias_targets/name-conflict-stderr.txt
new file mode 100644
index 0000000000..3c0faa9df8
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/name-conflict-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at name-conflict.cmake:8 \(add_library\):
+ add_library cannot create target "bar" because an alias with the same name
+ already exists.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/name-conflict.cmake b/Tests/RunCMake/alias_targets/name-conflict.cmake
new file mode 100644
index 0000000000..d21a092489
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/name-conflict.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_library(bar ALIAS foo)
+
+add_library(bar empty.cpp)
diff --git a/Tests/RunCMake/alias_targets/no-targets-result.txt b/Tests/RunCMake/alias_targets/no-targets-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/no-targets-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/no-targets-stderr.txt b/Tests/RunCMake/alias_targets/no-targets-stderr.txt
new file mode 100644
index 0000000000..cdf7e577c1
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/no-targets-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at no-targets.cmake:4 \(add_library\):
+ add_library ALIAS requires exactly one target argument.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/no-targets.cmake b/Tests/RunCMake/alias_targets/no-targets.cmake
new file mode 100644
index 0000000000..a5c5ee501d
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/no-targets.cmake
@@ -0,0 +1,4 @@
+
+enable_language(CXX)
+
+add_library(alias ALIAS)
diff --git a/Tests/RunCMake/alias_targets/set_property-result.txt b/Tests/RunCMake/alias_targets/set_property-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/set_property-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/set_property-stderr.txt b/Tests/RunCMake/alias_targets/set_property-stderr.txt
new file mode 100644
index 0000000000..e85aa568ce
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/set_property-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at set_property.cmake:8 \(set_property\):
+ set_property can not be used on an ALIAS target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/set_property.cmake b/Tests/RunCMake/alias_targets/set_property.cmake
new file mode 100644
index 0000000000..1f5e475c4a
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/set_property.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_library(alias ALIAS foo)
+
+set_property(TARGET alias PROPERTY ANYTHING 1)
diff --git a/Tests/RunCMake/alias_targets/set_target_properties-result.txt b/Tests/RunCMake/alias_targets/set_target_properties-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/set_target_properties-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/set_target_properties-stderr.txt b/Tests/RunCMake/alias_targets/set_target_properties-stderr.txt
new file mode 100644
index 0000000000..8922c0d3e2
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/set_target_properties-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at set_target_properties.cmake:8 \(set_target_properties\):
+ set_target_properties can not be used on an ALIAS target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/set_target_properties.cmake b/Tests/RunCMake/alias_targets/set_target_properties.cmake
new file mode 100644
index 0000000000..ee44d4595a
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/set_target_properties.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_library(alias ALIAS foo)
+
+set_target_properties(alias PROPERTIES ANYTHING 1)
diff --git a/Tests/RunCMake/alias_targets/target_include_directories-result.txt b/Tests/RunCMake/alias_targets/target_include_directories-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/target_include_directories-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/target_include_directories-stderr.txt b/Tests/RunCMake/alias_targets/target_include_directories-stderr.txt
new file mode 100644
index 0000000000..b8903b2454
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/target_include_directories-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at target_include_directories.cmake:8 \(target_include_directories\):
+ target_include_directories can not be used on an ALIAS target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/target_include_directories.cmake b/Tests/RunCMake/alias_targets/target_include_directories.cmake
new file mode 100644
index 0000000000..c26830e119
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/target_include_directories.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+
+add_library(alias ALIAS foo)
+
+target_include_directories(alias PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
diff --git a/Tests/RunCMake/alias_targets/target_link_libraries-result.txt b/Tests/RunCMake/alias_targets/target_link_libraries-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/target_link_libraries-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/alias_targets/target_link_libraries-stderr.txt b/Tests/RunCMake/alias_targets/target_link_libraries-stderr.txt
new file mode 100644
index 0000000000..2d7ff20da4
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/target_link_libraries-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at target_link_libraries.cmake:9 \(target_link_libraries\):
+ target_link_libraries can not be used on an ALIAS target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/alias_targets/target_link_libraries.cmake b/Tests/RunCMake/alias_targets/target_link_libraries.cmake
new file mode 100644
index 0000000000..b7b9e60185
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/target_link_libraries.cmake
@@ -0,0 +1,9 @@
+
+enable_language(CXX)
+
+add_library(foo empty.cpp)
+add_library(bar empty.cpp)
+
+add_library(alias ALIAS foo)
+
+target_link_libraries(alias bar)
diff --git a/Tests/RunCMake/build_command/BeforeProject-stderr.txt b/Tests/RunCMake/build_command/BeforeProject-stderr.txt
new file mode 100644
index 0000000000..2ae0ed180b
--- /dev/null
+++ b/Tests/RunCMake/build_command/BeforeProject-stderr.txt
@@ -0,0 +1,7 @@
+CMake Warning \(dev\) at BeforeProject.cmake:2 \(message\):
+ build_command\(\) returned:
+
+ .*cmake.* --build \..*
+Call Stack \(most recent call first\):
+ CMakeLists.txt:5 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/build_command/BeforeProject.cmake b/Tests/RunCMake/build_command/BeforeProject.cmake
new file mode 100644
index 0000000000..a2175c4695
--- /dev/null
+++ b/Tests/RunCMake/build_command/BeforeProject.cmake
@@ -0,0 +1,3 @@
+build_command(MAKECOMMAND_DEFAULT_VALUE)
+message(AUTHOR_WARNING "build_command() returned:\n ${MAKECOMMAND_DEFAULT_VALUE}")
+project(${RunCMake_TEST} NONE)
diff --git a/Tests/RunCMake/build_command/CMakeLists.txt b/Tests/RunCMake/build_command/CMakeLists.txt
new file mode 100644
index 0000000000..73e6a785a4
--- /dev/null
+++ b/Tests/RunCMake/build_command/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.4)
+if(NOT NoProject)
+ project(${RunCMake_TEST} NONE)
+endif()
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/build_command/ErrorsCommon.cmake b/Tests/RunCMake/build_command/ErrorsCommon.cmake
new file mode 100644
index 0000000000..f007b8875a
--- /dev/null
+++ b/Tests/RunCMake/build_command/ErrorsCommon.cmake
@@ -0,0 +1,55 @@
+# This CMakeLists file is *sometimes expected* to result in a configure error.
+#
+# expect this to succeed:
+# ../bin/Release/cmake -G Xcode
+# ../../CMake/Tests/CMakeCommands/build_command
+#
+# expect this to fail:
+# ../bin/Release/cmake -DTEST_ERROR_CONDITIONS:BOOL=ON -G Xcode
+# ../../CMake/Tests/CMakeCommands/build_command
+#
+# This project exists merely to test the CMake command 'build_command'...
+# ...even purposefully calling it with known-bad argument lists to cover
+# error handling code.
+#
+
+set(cmd "initial")
+
+message("0. begin")
+
+if(TEST_ERROR_CONDITIONS)
+ # Test with no arguments (an error):
+ build_command()
+ message("1. cmd='${cmd}'")
+
+ # Test with unknown arguments (also an error):
+ build_command(cmd BOGUS STUFF)
+ message("2. cmd='${cmd}'")
+
+ build_command(cmd STUFF BOGUS)
+ message("3. cmd='${cmd}'")
+else()
+ message("(skipping cases 1, 2 and 3 because TEST_ERROR_CONDITIONS is OFF)")
+endif()
+
+# Test the one arg signature with none of the optional KEYWORD arguments:
+build_command(cmd)
+message("4. cmd='${cmd}'")
+
+# Test the two-arg legacy signature:
+build_command(legacy_cmd ${CMAKE_MAKE_PROGRAM})
+message("5. legacy_cmd='${legacy_cmd}'")
+message(" CMAKE_MAKE_PROGRAM='${CMAKE_MAKE_PROGRAM}'")
+
+# Test the optional KEYWORDs:
+build_command(cmd CONFIGURATION hoohaaConfig)
+message("6. cmd='${cmd}'")
+
+build_command(cmd PROJECT_NAME hoohaaProject)
+message("7. cmd='${cmd}'")
+
+build_command(cmd TARGET hoohaaTarget)
+message("8. cmd='${cmd}'")
+
+set(cmd "final")
+message("9. cmd='${cmd}'")
diff --git a/Tests/RunCMake/build_command/ErrorsOFF-stderr.txt b/Tests/RunCMake/build_command/ErrorsOFF-stderr.txt
new file mode 100644
index 0000000000..331885b943
--- /dev/null
+++ b/Tests/RunCMake/build_command/ErrorsOFF-stderr.txt
@@ -0,0 +1 @@
+skipping cases 1, 2 and 3 because TEST_ERROR_CONDITIONS is OFF
diff --git a/Tests/RunCMake/build_command/ErrorsOFF-stdout.txt b/Tests/RunCMake/build_command/ErrorsOFF-stdout.txt
new file mode 100644
index 0000000000..cf66a9d7a4
--- /dev/null
+++ b/Tests/RunCMake/build_command/ErrorsOFF-stdout.txt
@@ -0,0 +1 @@
+Build files have been written to:
diff --git a/Tests/RunCMake/build_command/ErrorsOFF.cmake b/Tests/RunCMake/build_command/ErrorsOFF.cmake
new file mode 100644
index 0000000000..7b9cac6473
--- /dev/null
+++ b/Tests/RunCMake/build_command/ErrorsOFF.cmake
@@ -0,0 +1,2 @@
+set(TEST_ERROR_CONDITIONS OFF)
+include(ErrorsCommon.cmake)
diff --git a/Tests/RunCMake/build_command/ErrorsON-result.txt b/Tests/RunCMake/build_command/ErrorsON-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/build_command/ErrorsON-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/build_command/ErrorsON-stderr.txt b/Tests/RunCMake/build_command/ErrorsON-stderr.txt
new file mode 100644
index 0000000000..47a84d6743
--- /dev/null
+++ b/Tests/RunCMake/build_command/ErrorsON-stderr.txt
@@ -0,0 +1,21 @@
+CMake Error at ErrorsCommon.cmake:[0-9]+ \(build_command\):
+ build_command requires at least one argument naming a CMake variable
+Call Stack \(most recent call first\):
+ ErrorsON.cmake:[0-9]+ \(include\)
+ CMakeLists.txt:[0-9]+ \(include\)
+
++
+1. cmd='initial'
+CMake Error at ErrorsCommon.cmake:[0-9]+ \(build_command\):
+ build_command unknown argument "BOGUS"
+Call Stack \(most recent call first\):
+ ErrorsON.cmake:[0-9]+ \(include\)
+ CMakeLists.txt:[0-9]+ \(include\)
+
++
+2. cmd='initial'
+CMake Error at ErrorsCommon.cmake:[0-9]+ \(build_command\):
+ build_command unknown argument "STUFF"
+Call Stack \(most recent call first\):
+ ErrorsON.cmake:[0-9]+ \(include\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/build_command/ErrorsON-stdout.txt b/Tests/RunCMake/build_command/ErrorsON-stdout.txt
new file mode 100644
index 0000000000..841dd0d881
--- /dev/null
+++ b/Tests/RunCMake/build_command/ErrorsON-stdout.txt
@@ -0,0 +1 @@
+Configuring incomplete, errors occurred!
diff --git a/Tests/RunCMake/build_command/ErrorsON.cmake b/Tests/RunCMake/build_command/ErrorsON.cmake
new file mode 100644
index 0000000000..d7b709b87f
--- /dev/null
+++ b/Tests/RunCMake/build_command/ErrorsON.cmake
@@ -0,0 +1,2 @@
+set(TEST_ERROR_CONDITIONS ON)
+include(ErrorsCommon.cmake)
diff --git a/Tests/RunCMake/build_command/RunCMakeTest.cmake b/Tests/RunCMake/build_command/RunCMakeTest.cmake
new file mode 100644
index 0000000000..eaa1d77d83
--- /dev/null
+++ b/Tests/RunCMake/build_command/RunCMakeTest.cmake
@@ -0,0 +1,8 @@
+include(RunCMake)
+
+run_cmake(ErrorsOFF)
+run_cmake(ErrorsON)
+
+set(RunCMake_TEST_OPTIONS -DNoProject=1)
+run_cmake(BeforeProject)
+unset(RunCMake_TEST_OPTIONS)
diff --git a/Tests/RunCMake/cmake_minimum_required/Before24-stderr.txt b/Tests/RunCMake/cmake_minimum_required/Before24-stderr.txt
new file mode 100644
index 0000000000..4a6f16dc30
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/Before24-stderr.txt
@@ -0,0 +1,5 @@
+CMake Warning \(dev\) at Before24.cmake:1 \(cmake_minimum_required\):
+ Compatibility with CMake < 2.4 is not supported by CMake >= 3.0.
+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/cmake_minimum_required/Before24.cmake b/Tests/RunCMake/cmake_minimum_required/Before24.cmake
new file mode 100644
index 0000000000..c28fc8a9d2
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/Before24.cmake
@@ -0,0 +1 @@
+cmake_minimum_required(VERSION 2.2)
diff --git a/Tests/RunCMake/cmake_minimum_required/CMakeLists.txt b/Tests/RunCMake/cmake_minimum_required/CMakeLists.txt
new file mode 100644
index 0000000000..e8db6b05be
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/cmake_minimum_required/CompatBefore24-result.txt b/Tests/RunCMake/cmake_minimum_required/CompatBefore24-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/CompatBefore24-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/cmake_minimum_required/CompatBefore24-stderr.txt b/Tests/RunCMake/cmake_minimum_required/CompatBefore24-stderr.txt
new file mode 100644
index 0000000000..a874466d33
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/CompatBefore24-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error in CMakeLists.txt:
+ You have set CMAKE_BACKWARDS_COMPATIBILITY to a CMake version less than
+ 2.4. This version of CMake only supports backwards compatibility with
+ CMake 2.4 or later. For compatibility with older versions please use any
+ CMake 2.8.x release or lower.
diff --git a/Tests/RunCMake/cmake_minimum_required/CompatBefore24.cmake b/Tests/RunCMake/cmake_minimum_required/CompatBefore24.cmake
new file mode 100644
index 0000000000..ca0cb1ded8
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/CompatBefore24.cmake
@@ -0,0 +1,2 @@
+cmake_minimum_required(VERSION 2.4)
+set(CMAKE_BACKWARDS_COMPATIBILITY 2.2)
diff --git a/Tests/RunCMake/cmake_minimum_required/PolicyBefore24-result.txt b/Tests/RunCMake/cmake_minimum_required/PolicyBefore24-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/PolicyBefore24-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/cmake_minimum_required/PolicyBefore24-stderr.txt b/Tests/RunCMake/cmake_minimum_required/PolicyBefore24-stderr.txt
new file mode 100644
index 0000000000..840211a3b9
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/PolicyBefore24-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at PolicyBefore24.cmake:2 \(cmake_policy\):
+ Compatibility with CMake < 2.4 is not supported by CMake >= 3.0. For
+ compatibility with older versions please use any CMake 2.8.x release or
+ lower.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/cmake_minimum_required/PolicyBefore24.cmake b/Tests/RunCMake/cmake_minimum_required/PolicyBefore24.cmake
new file mode 100644
index 0000000000..62d3836132
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/PolicyBefore24.cmake
@@ -0,0 +1,2 @@
+cmake_minimum_required(VERSION 2.4)
+cmake_policy(VERSION 2.2)
diff --git a/Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake b/Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake
new file mode 100644
index 0000000000..e4c65e3b6b
--- /dev/null
+++ b/Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(Before24)
+run_cmake(CompatBefore24)
+run_cmake(PolicyBefore24)
diff --git a/Tests/RunCMake/configure_file/CMakeLists.txt b/Tests/RunCMake/configure_file/CMakeLists.txt
new file mode 100644
index 0000000000..2897109554
--- /dev/null
+++ b/Tests/RunCMake/configure_file/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/configure_file/NO-BOM.cmake b/Tests/RunCMake/configure_file/NO-BOM.cmake
new file mode 100644
index 0000000000..003d526632
--- /dev/null
+++ b/Tests/RunCMake/configure_file/NO-BOM.cmake
@@ -0,0 +1,2 @@
+
+configure_file(NO-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/NO-BOM.txt)
diff --git a/Tests/RunCMake/configure_file/NO-BOM.txt.in b/Tests/RunCMake/configure_file/NO-BOM.txt.in
new file mode 100644
index 0000000000..557db03de9
--- /dev/null
+++ b/Tests/RunCMake/configure_file/NO-BOM.txt.in
@@ -0,0 +1 @@
+Hello World
diff --git a/Tests/RunCMake/configure_file/RunCMakeTest.cmake b/Tests/RunCMake/configure_file/RunCMakeTest.cmake
new file mode 100644
index 0000000000..c8bfa570df
--- /dev/null
+++ b/Tests/RunCMake/configure_file/RunCMakeTest.cmake
@@ -0,0 +1,8 @@
+include(RunCMake)
+
+run_cmake(NO-BOM)
+run_cmake(UTF8-BOM)
+run_cmake(UTF16LE-BOM)
+run_cmake(UTF16BE-BOM)
+run_cmake(UTF32LE-BOM)
+run_cmake(UTF32BE-BOM)
diff --git a/Tests/RunCMake/configure_file/UTF16BE-BOM-result.txt b/Tests/RunCMake/configure_file/UTF16BE-BOM-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF16BE-BOM-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/configure_file/UTF16BE-BOM-stderr.txt b/Tests/RunCMake/configure_file/UTF16BE-BOM-stderr.txt
new file mode 100644
index 0000000000..5132c4ddb4
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF16BE-BOM-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at UTF16BE-BOM.cmake:2 \(configure_file\):
+ File starts with a Byte-Order-Mark that is not UTF-8:
+
+ .*/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/configure_file/UTF16BE-BOM.cmake b/Tests/RunCMake/configure_file/UTF16BE-BOM.cmake
new file mode 100644
index 0000000000..c5707425aa
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF16BE-BOM.cmake
@@ -0,0 +1,2 @@
+
+configure_file(UTF16BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16BE-BOM.txt)
diff --git a/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in b/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in
new file mode 100644
index 0000000000..70fd9cbf7d
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in
Binary files differ
diff --git a/Tests/RunCMake/configure_file/UTF16LE-BOM-result.txt b/Tests/RunCMake/configure_file/UTF16LE-BOM-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF16LE-BOM-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/configure_file/UTF16LE-BOM-stderr.txt b/Tests/RunCMake/configure_file/UTF16LE-BOM-stderr.txt
new file mode 100644
index 0000000000..8f997bc717
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF16LE-BOM-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at UTF16LE-BOM.cmake:2 \(configure_file\):
+ File starts with a Byte-Order-Mark that is not UTF-8:
+
+ .*/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/configure_file/UTF16LE-BOM.cmake b/Tests/RunCMake/configure_file/UTF16LE-BOM.cmake
new file mode 100644
index 0000000000..05c9cd7577
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF16LE-BOM.cmake
@@ -0,0 +1,2 @@
+
+configure_file(UTF16LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16LE-BOM.txt)
diff --git a/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in b/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in
new file mode 100644
index 0000000000..036f8c5360
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in
Binary files differ
diff --git a/Tests/RunCMake/configure_file/UTF32BE-BOM-result.txt b/Tests/RunCMake/configure_file/UTF32BE-BOM-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF32BE-BOM-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/configure_file/UTF32BE-BOM-stderr.txt b/Tests/RunCMake/configure_file/UTF32BE-BOM-stderr.txt
new file mode 100644
index 0000000000..12811aaa21
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF32BE-BOM-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at UTF32BE-BOM.cmake:2 \(configure_file\):
+ File starts with a Byte-Order-Mark that is not UTF-8:
+
+ .*/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/configure_file/UTF32BE-BOM.cmake b/Tests/RunCMake/configure_file/UTF32BE-BOM.cmake
new file mode 100644
index 0000000000..0c6ea87531
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF32BE-BOM.cmake
@@ -0,0 +1,2 @@
+
+configure_file(UTF32BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32BE-BOM.txt)
diff --git a/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in b/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in
new file mode 100644
index 0000000000..c87cfd5ca6
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in
Binary files differ
diff --git a/Tests/RunCMake/configure_file/UTF32LE-BOM-result.txt b/Tests/RunCMake/configure_file/UTF32LE-BOM-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF32LE-BOM-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/configure_file/UTF32LE-BOM-stderr.txt b/Tests/RunCMake/configure_file/UTF32LE-BOM-stderr.txt
new file mode 100644
index 0000000000..fa9e01a2b3
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF32LE-BOM-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at UTF32LE-BOM.cmake:2 \(configure_file\):
+ File starts with a Byte-Order-Mark that is not UTF-8:
+
+ .*/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/configure_file/UTF32LE-BOM.cmake b/Tests/RunCMake/configure_file/UTF32LE-BOM.cmake
new file mode 100644
index 0000000000..b6351b0077
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF32LE-BOM.cmake
@@ -0,0 +1,2 @@
+
+configure_file(UTF32LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32LE-BOM.txt)
diff --git a/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in b/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in
new file mode 100644
index 0000000000..27c8183bd7
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in
Binary files differ
diff --git a/Tests/RunCMake/configure_file/UTF8-BOM.cmake b/Tests/RunCMake/configure_file/UTF8-BOM.cmake
new file mode 100644
index 0000000000..af2adae4a7
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF8-BOM.cmake
@@ -0,0 +1,2 @@
+
+configure_file(UTF8-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF8-BOM.txt)
diff --git a/Tests/RunCMake/configure_file/UTF8-BOM.txt.in b/Tests/RunCMake/configure_file/UTF8-BOM.txt.in
new file mode 100644
index 0000000000..abc0acab2d
--- /dev/null
+++ b/Tests/RunCMake/configure_file/UTF8-BOM.txt.in
@@ -0,0 +1 @@
+Hello World
diff --git a/Tests/RunCMake/export/AppendExport-result.txt b/Tests/RunCMake/export/AppendExport-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/export/AppendExport-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/export/AppendExport-stderr.txt b/Tests/RunCMake/export/AppendExport-stderr.txt
new file mode 100644
index 0000000000..6e385d495a
--- /dev/null
+++ b/Tests/RunCMake/export/AppendExport-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at AppendExport.cmake:8 \(export\):
+ export EXPORT signature does not recognise the APPEND option.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/export/AppendExport.cmake b/Tests/RunCMake/export/AppendExport.cmake
new file mode 100644
index 0000000000..f36010b6ae
--- /dev/null
+++ b/Tests/RunCMake/export/AppendExport.cmake
@@ -0,0 +1,8 @@
+add_library(foo empty.cpp)
+export(TARGETS foo FILE "${CMAKE_CURRENT_BINARY_DIR}/foo.cmake")
+install(TARGETS foo EXPORT fooExport
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+)
+export(EXPORT fooExport APPEND FILE "${CMAKE_CURRENT_BINARY_DIR}/foo.cmake")
diff --git a/Tests/RunCMake/export/CMakeLists.txt b/Tests/RunCMake/export/CMakeLists.txt
new file mode 100644
index 0000000000..be9d4038db
--- /dev/null
+++ b/Tests/RunCMake/export/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST})
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/export/NoExportSet-result.txt b/Tests/RunCMake/export/NoExportSet-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/export/NoExportSet-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/export/NoExportSet-stderr.txt b/Tests/RunCMake/export/NoExportSet-stderr.txt
new file mode 100644
index 0000000000..9d27805e00
--- /dev/null
+++ b/Tests/RunCMake/export/NoExportSet-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoExportSet.cmake:2 \(export\):
+ export Export set "fooExport" not found.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/export/NoExportSet.cmake b/Tests/RunCMake/export/NoExportSet.cmake
new file mode 100644
index 0000000000..72390e822a
--- /dev/null
+++ b/Tests/RunCMake/export/NoExportSet.cmake
@@ -0,0 +1,2 @@
+
+export(EXPORT fooExport)
diff --git a/Tests/RunCMake/export/OldIface-result.txt b/Tests/RunCMake/export/OldIface-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/export/OldIface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/export/OldIface-stderr.txt b/Tests/RunCMake/export/OldIface-stderr.txt
new file mode 100644
index 0000000000..afb4ae3ac6
--- /dev/null
+++ b/Tests/RunCMake/export/OldIface-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at OldIface.cmake:8 \(export\):
+ export EXPORT signature does not recognise the
+ EXPORT_LINK_INTERFACE_LIBRARIES option.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/export/OldIface.cmake b/Tests/RunCMake/export/OldIface.cmake
new file mode 100644
index 0000000000..5fb8e259da
--- /dev/null
+++ b/Tests/RunCMake/export/OldIface.cmake
@@ -0,0 +1,10 @@
+add_library(foo empty.cpp)
+export(TARGETS foo FILE "${CMAKE_CURRENT_BINARY_DIR}/foo.cmake")
+install(TARGETS foo EXPORT fooExport
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+)
+export(EXPORT fooExport
+ EXPORT_LINK_INTERFACE_LIBRARIES
+)
diff --git a/Tests/RunCMake/export/RunCMakeTest.cmake b/Tests/RunCMake/export/RunCMakeTest.cmake
new file mode 100644
index 0000000000..4b04f18589
--- /dev/null
+++ b/Tests/RunCMake/export/RunCMakeTest.cmake
@@ -0,0 +1,6 @@
+include(RunCMake)
+
+run_cmake(TargetNotFound)
+run_cmake(AppendExport)
+run_cmake(OldIface)
+run_cmake(NoExportSet)
diff --git a/Tests/RunCMake/export/TargetNotFound-result.txt b/Tests/RunCMake/export/TargetNotFound-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/export/TargetNotFound-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/export/TargetNotFound-stderr.txt b/Tests/RunCMake/export/TargetNotFound-stderr.txt
new file mode 100644
index 0000000000..944a68e0ea
--- /dev/null
+++ b/Tests/RunCMake/export/TargetNotFound-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at TargetNotFound.cmake:1 \(export\):
+ export given target "nonexistenttarget" which is not built by this project.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/export/TargetNotFound.cmake b/Tests/RunCMake/export/TargetNotFound.cmake
new file mode 100644
index 0000000000..a7c398daf0
--- /dev/null
+++ b/Tests/RunCMake/export/TargetNotFound.cmake
@@ -0,0 +1 @@
+export(TARGETS nonexistenttarget FILE somefile.cmake)
diff --git a/Tests/RunCMake/file/CMakeLists.txt b/Tests/RunCMake/file/CMakeLists.txt
new file mode 100644
index 0000000000..2897109554
--- /dev/null
+++ b/Tests/RunCMake/file/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/file/FileOpenFailRead-result.txt b/Tests/RunCMake/file/FileOpenFailRead-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/file/FileOpenFailRead-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/FileOpenFailRead-stderr.txt b/Tests/RunCMake/file/FileOpenFailRead-stderr.txt
new file mode 100644
index 0000000000..23d4337f4e
--- /dev/null
+++ b/Tests/RunCMake/file/FileOpenFailRead-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at FileOpenFailRead.cmake:[0-9]+ \(file\):
+ file failed to open for reading \(.*\):
+
+ .*/Tests/RunCMake/file/does_not_exist/file.txt
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/file/FileOpenFailRead.cmake b/Tests/RunCMake/file/FileOpenFailRead.cmake
new file mode 100644
index 0000000000..4d4c6dc16d
--- /dev/null
+++ b/Tests/RunCMake/file/FileOpenFailRead.cmake
@@ -0,0 +1 @@
+file(READ "${CMAKE_CURRENT_SOURCE_DIR}/does_not_exist/file.txt" content)
diff --git a/Tests/RunCMake/file/INSTALL-DIRECTORY-stdout.txt b/Tests/RunCMake/file/INSTALL-DIRECTORY-stdout.txt
new file mode 100644
index 0000000000..561a6b1a50
--- /dev/null
+++ b/Tests/RunCMake/file/INSTALL-DIRECTORY-stdout.txt
@@ -0,0 +1,8 @@
+-- Before Installing
+-- Installing: .*/Tests/RunCMake/file/INSTALL-DIRECTORY-build/dir
+-- Installing: .*/Tests/RunCMake/file/INSTALL-DIRECTORY-build/dir/empty.txt
+-- Up-to-date: .*/Tests/RunCMake/file/INSTALL-DIRECTORY-build/dir
+-- Up-to-date: .*/Tests/RunCMake/file/INSTALL-DIRECTORY-build/dir/empty.txt
+-- Up-to-date: .*/Tests/RunCMake/file/INSTALL-DIRECTORY-build/dir
+-- Up-to-date: .*/Tests/RunCMake/file/INSTALL-DIRECTORY-build/dir/empty.txt
+-- After Installing
diff --git a/Tests/RunCMake/file/INSTALL-DIRECTORY.cmake b/Tests/RunCMake/file/INSTALL-DIRECTORY.cmake
new file mode 100644
index 0000000000..0bc1d18a93
--- /dev/null
+++ b/Tests/RunCMake/file/INSTALL-DIRECTORY.cmake
@@ -0,0 +1,10 @@
+set(src ${CMAKE_CURRENT_SOURCE_DIR}/dir)
+set(dst ${CMAKE_CURRENT_BINARY_DIR}/dir)
+file(REMOVE RECURSE ${dst})
+message(STATUS "Before Installing")
+file(INSTALL FILES ${src}/ DESTINATION ${dst} TYPE DIRECTORY)
+file(INSTALL FILES ${src}/ DESTINATION ${dst} TYPE DIRECTORY)
+file(INSTALL FILES ${src}/ DESTINATION ${dst} TYPE DIRECTORY MESSAGE_NEVER)
+file(INSTALL FILES ${src}/ DESTINATION ${dst} TYPE DIRECTORY MESSAGE_LAZY)
+file(INSTALL FILES ${src}/ DESTINATION ${dst} TYPE DIRECTORY MESSAGE_ALWAYS)
+message(STATUS "After Installing")
diff --git a/Tests/RunCMake/file/INSTALL-MESSAGE-bad-result.txt b/Tests/RunCMake/file/INSTALL-MESSAGE-bad-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/file/INSTALL-MESSAGE-bad-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/INSTALL-MESSAGE-bad-stderr.txt b/Tests/RunCMake/file/INSTALL-MESSAGE-bad-stderr.txt
new file mode 100644
index 0000000000..557b817bb0
--- /dev/null
+++ b/Tests/RunCMake/file/INSTALL-MESSAGE-bad-stderr.txt
@@ -0,0 +1,32 @@
+CMake Error at INSTALL-MESSAGE-bad.cmake:1 \(file\):
+ file INSTALL options MESSAGE_ALWAYS, MESSAGE_LAZY, and MESSAGE_NEVER are
+ mutually exclusive.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at INSTALL-MESSAGE-bad.cmake:2 \(file\):
+ file INSTALL options MESSAGE_ALWAYS, MESSAGE_LAZY, and MESSAGE_NEVER are
+ mutually exclusive.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at INSTALL-MESSAGE-bad.cmake:3 \(file\):
+ file INSTALL options MESSAGE_ALWAYS, MESSAGE_LAZY, and MESSAGE_NEVER are
+ mutually exclusive.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at INSTALL-MESSAGE-bad.cmake:4 \(file\):
+ file option MESSAGE_ALWAYS may not appear after PATTERN or REGEX.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at INSTALL-MESSAGE-bad.cmake:5 \(file\):
+ file option MESSAGE_LAZY may not appear after PATTERN or REGEX.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at INSTALL-MESSAGE-bad.cmake:6 \(file\):
+ file option MESSAGE_NEVER may not appear after PATTERN or REGEX.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/file/INSTALL-MESSAGE-bad.cmake b/Tests/RunCMake/file/INSTALL-MESSAGE-bad.cmake
new file mode 100644
index 0000000000..f878c69197
--- /dev/null
+++ b/Tests/RunCMake/file/INSTALL-MESSAGE-bad.cmake
@@ -0,0 +1,6 @@
+file(INSTALL DESTINATION dir MESSAGE_ALWAYS MESSAGE_LAZY)
+file(INSTALL DESTINATION dir MESSAGE_ALWAYS MESSAGE_NEVER)
+file(INSTALL DESTINATION dir MESSAGE_LAZY MESSAGE_NEVER)
+file(INSTALL DESTINATION dir PATTERN *.txt MESSAGE_ALWAYS)
+file(INSTALL DESTINATION dir PATTERN *.txt MESSAGE_LAZY)
+file(INSTALL DESTINATION dir PATTERN *.txt MESSAGE_NEVER)
diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake b/Tests/RunCMake/file/RunCMakeTest.cmake
new file mode 100644
index 0000000000..bf14263b46
--- /dev/null
+++ b/Tests/RunCMake/file/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(INSTALL-DIRECTORY)
+run_cmake(INSTALL-MESSAGE-bad)
+run_cmake(FileOpenFailRead)
diff --git a/Tests/RunCMake/file/dir/empty.txt b/Tests/RunCMake/file/dir/empty.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/file/dir/empty.txt
diff --git a/Tests/RunCMake/find_dependency/CMakeLists.txt b/Tests/RunCMake/find_dependency/CMakeLists.txt
new file mode 100644
index 0000000000..04d09f2adf
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/find_dependency/EXACT-no-version-result.txt b/Tests/RunCMake/find_dependency/EXACT-no-version-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/EXACT-no-version-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_dependency/EXACT-no-version-stderr.txt b/Tests/RunCMake/find_dependency/EXACT-no-version-stderr.txt
new file mode 100644
index 0000000000..348f8bb25d
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/EXACT-no-version-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(message\):
+ Invalid arguments to find_dependency. EXACT may only be specified if a
+ VERSION is specified
+Call Stack \(most recent call first\):
+ EXACT-no-version.cmake:4 \(find_dependency\)
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/find_dependency/EXACT-no-version.cmake b/Tests/RunCMake/find_dependency/EXACT-no-version.cmake
new file mode 100644
index 0000000000..b05665b7e1
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/EXACT-no-version.cmake
@@ -0,0 +1,4 @@
+
+include(CMakeFindDependencyMacro)
+
+find_dependency(Pack1 EXACT)
diff --git a/Tests/RunCMake/find_dependency/Pack1/Pack1Config.cmake b/Tests/RunCMake/find_dependency/Pack1/Pack1Config.cmake
new file mode 100644
index 0000000000..7d55ef61d9
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/Pack1/Pack1Config.cmake
@@ -0,0 +1,2 @@
+
+add_library(Pack1::Lib INTERFACE IMPORTED)
diff --git a/Tests/RunCMake/find_dependency/Pack1/Pack1ConfigVersion.cmake b/Tests/RunCMake/find_dependency/Pack1/Pack1ConfigVersion.cmake
new file mode 100644
index 0000000000..dfb7b6c847
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/Pack1/Pack1ConfigVersion.cmake
@@ -0,0 +1,11 @@
+
+set(PACKAGE_VERSION "1.3")
+
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
diff --git a/Tests/RunCMake/find_dependency/RunCMakeTest.cmake b/Tests/RunCMake/find_dependency/RunCMakeTest.cmake
new file mode 100644
index 0000000000..9403136b71
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/RunCMakeTest.cmake
@@ -0,0 +1,7 @@
+include(RunCMake)
+
+run_cmake(EXACT-no-version)
+run_cmake(empty-version)
+run_cmake(empty-arg-3)
+run_cmake(invalid-arg-3)
+run_cmake(extra-args)
diff --git a/Tests/RunCMake/find_dependency/empty-arg-3-result.txt b/Tests/RunCMake/find_dependency/empty-arg-3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/empty-arg-3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_dependency/empty-arg-3-stderr.txt b/Tests/RunCMake/find_dependency/empty-arg-3-stderr.txt
new file mode 100644
index 0000000000..bf9b02b43c
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/empty-arg-3-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(message\):
+ Invalid arguments to find_dependency
+Call Stack \(most recent call first\):
+ empty-arg-3.cmake:4 \(find_dependency\)
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/find_dependency/empty-arg-3.cmake b/Tests/RunCMake/find_dependency/empty-arg-3.cmake
new file mode 100644
index 0000000000..b08200a5a5
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/empty-arg-3.cmake
@@ -0,0 +1,4 @@
+
+include(CMakeFindDependencyMacro)
+
+find_dependency(Pack1 1.2 "")
diff --git a/Tests/RunCMake/find_dependency/empty-version-result.txt b/Tests/RunCMake/find_dependency/empty-version-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/empty-version-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_dependency/empty-version-stderr.txt b/Tests/RunCMake/find_dependency/empty-version-stderr.txt
new file mode 100644
index 0000000000..b5e9f46439
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/empty-version-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*/Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(message\):
+ Invalid arguments to find_dependency. VERSION is empty
+Call Stack \(most recent call first\):
+ empty-version.cmake:4 \(find_dependency\)
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/find_dependency/empty-version.cmake b/Tests/RunCMake/find_dependency/empty-version.cmake
new file mode 100644
index 0000000000..e6f17cd139
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/empty-version.cmake
@@ -0,0 +1,4 @@
+
+include(CMakeFindDependencyMacro)
+
+find_dependency(Pack1 "")
diff --git a/Tests/RunCMake/find_dependency/extra-args-result.txt b/Tests/RunCMake/find_dependency/extra-args-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/extra-args-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_dependency/extra-args-stderr.txt b/Tests/RunCMake/find_dependency/extra-args-stderr.txt
new file mode 100644
index 0000000000..83a7f02661
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/extra-args-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(message\):
+ Invalid arguments to find_dependency
+Call Stack \(most recent call first\):
+ extra-args.cmake:4 \(find_dependency\)
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/find_dependency/extra-args.cmake b/Tests/RunCMake/find_dependency/extra-args.cmake
new file mode 100644
index 0000000000..209645a5d5
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/extra-args.cmake
@@ -0,0 +1,4 @@
+
+include(CMakeFindDependencyMacro)
+
+find_dependency(Pack1 1.2 EXACT PATHS "${CMAKE_BINARY_DIR}")
diff --git a/Tests/RunCMake/find_dependency/invalid-arg-3-result.txt b/Tests/RunCMake/find_dependency/invalid-arg-3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/invalid-arg-3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_dependency/invalid-arg-3-stderr.txt b/Tests/RunCMake/find_dependency/invalid-arg-3-stderr.txt
new file mode 100644
index 0000000000..fee8d5db7a
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/invalid-arg-3-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(message\):
+ Invalid arguments to find_dependency
+Call Stack \(most recent call first\):
+ invalid-arg-3.cmake:4 \(find_dependency\)
+ CMakeLists.txt:4 \(include\)
diff --git a/Tests/RunCMake/find_dependency/invalid-arg-3.cmake b/Tests/RunCMake/find_dependency/invalid-arg-3.cmake
new file mode 100644
index 0000000000..40ede07f48
--- /dev/null
+++ b/Tests/RunCMake/find_dependency/invalid-arg-3.cmake
@@ -0,0 +1,4 @@
+
+include(CMakeFindDependencyMacro)
+
+find_dependency(Pack1 1.2 EXACTYPO)
diff --git a/Tests/RunCMake/find_package/CMakeLists.txt b/Tests/RunCMake/find_package/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/find_package/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/find_package/ComponentRequiredAndOptional-result.txt b/Tests/RunCMake/find_package/ComponentRequiredAndOptional-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_package/ComponentRequiredAndOptional-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_package/ComponentRequiredAndOptional-stderr.txt b/Tests/RunCMake/find_package/ComponentRequiredAndOptional-stderr.txt
new file mode 100644
index 0000000000..db8f512226
--- /dev/null
+++ b/Tests/RunCMake/find_package/ComponentRequiredAndOptional-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at ComponentRequiredAndOptional.cmake:1 \(find_package\):
+ find_package called with components that are both required and optional:
+
+ CompA
+ CompB
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/find_package/ComponentRequiredAndOptional.cmake b/Tests/RunCMake/find_package/ComponentRequiredAndOptional.cmake
new file mode 100644
index 0000000000..0355f5af36
--- /dev/null
+++ b/Tests/RunCMake/find_package/ComponentRequiredAndOptional.cmake
@@ -0,0 +1 @@
+find_package(NotHere REQUIRED CompA CompB CompC OPTIONAL_COMPONENTS CompA CompB CompD)
diff --git a/Tests/RunCMake/find_package/MissingConfig-stderr.txt b/Tests/RunCMake/find_package/MissingConfig-stderr.txt
new file mode 100644
index 0000000000..1eae0bb0b1
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingConfig-stderr.txt
@@ -0,0 +1,19 @@
+CMake Warning at MissingConfig.cmake:1 \(find_package\):
+ Could not find a package configuration file provided by "NotHere" with any
+ of the following names:
+
+ NotHereConfig.cmake
+ nothere-config.cmake
+
+ Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set
+ "NotHere_DIR" to a directory containing one of the above files. If
+ "NotHere" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Warning at MissingConfig.cmake:2 \(message\):
+ This warning must be reachable.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/find_package/MissingConfig.cmake b/Tests/RunCMake/find_package/MissingConfig.cmake
new file mode 100644
index 0000000000..238e7e4988
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingConfig.cmake
@@ -0,0 +1,2 @@
+find_package(NotHere CONFIG)
+message(WARNING "This warning must be reachable.")
diff --git a/Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt b/Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt
new file mode 100644
index 0000000000..10e71faa30
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt
@@ -0,0 +1,10 @@
+CMake Warning at MissingConfigOneName.cmake:1 \(find_package\):
+ Could not find a package configuration file named "NotHereConfig.cmake"
+ provided by package "NotHere".
+
+ Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set
+ "NotHere_DIR" to a directory containing one of the above files. If
+ "NotHere" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/find_package/MissingConfigOneName.cmake b/Tests/RunCMake/find_package/MissingConfigOneName.cmake
new file mode 100644
index 0000000000..11676a9abe
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingConfigOneName.cmake
@@ -0,0 +1 @@
+find_package(NotHere CONFIGS NotHereConfig.cmake)
diff --git a/Tests/RunCMake/find_package/MissingConfigRequired-result.txt b/Tests/RunCMake/find_package/MissingConfigRequired-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingConfigRequired-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_package/MissingConfigRequired-stderr.txt b/Tests/RunCMake/find_package/MissingConfigRequired-stderr.txt
new file mode 100644
index 0000000000..2ba774aa2e
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingConfigRequired-stderr.txt
@@ -0,0 +1,13 @@
+CMake Error at MissingConfigRequired.cmake:1 \(find_package\):
+ Could not find a package configuration file provided by "NotHere" with any
+ of the following names:
+
+ NotHereConfig.cmake
+ nothere-config.cmake
+
+ Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set
+ "NotHere_DIR" to a directory containing one of the above files. If
+ "NotHere" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/find_package/MissingConfigRequired.cmake b/Tests/RunCMake/find_package/MissingConfigRequired.cmake
new file mode 100644
index 0000000000..0ae67023a8
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingConfigRequired.cmake
@@ -0,0 +1,2 @@
+find_package(NotHere CONFIG REQUIRED)
+message(FATAL_ERROR "This error must not be reachable.")
diff --git a/Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt b/Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt
new file mode 100644
index 0000000000..2f5086ea88
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt
@@ -0,0 +1,13 @@
+CMake Warning at MissingConfigVersion.cmake:1 \(find_package\):
+ Could not find a package configuration file provided by "NotHere"
+ \(requested version 1\.2\) with any of the following names:
+
+ NotHereConfig.cmake
+ nothere-config.cmake
+
+ Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set
+ "NotHere_DIR" to a directory containing one of the above files. If
+ "NotHere" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/find_package/MissingConfigVersion.cmake b/Tests/RunCMake/find_package/MissingConfigVersion.cmake
new file mode 100644
index 0000000000..ac35a79e48
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingConfigVersion.cmake
@@ -0,0 +1 @@
+find_package(NotHere 1.2 CONFIG)
diff --git a/Tests/RunCMake/find_package/MissingModule-stderr.txt b/Tests/RunCMake/find_package/MissingModule-stderr.txt
new file mode 100644
index 0000000000..2ad460f58c
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingModule-stderr.txt
@@ -0,0 +1,26 @@
+CMake Warning at MissingModule.cmake:1 \(find_package\):
+ No "FindNotHere.cmake" found in CMAKE_MODULE_PATH.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Warning \(dev\) at MissingModule.cmake:1 \(find_package\):
+ FindNotHere.cmake must either be part of this project itself, in this case
+ adjust CMAKE_MODULE_PATH so that it points to the correct location inside
+ its source tree.
+
+ Or it must be installed by a package which has already been found via
+ find_package\(\). In this case make sure that package has indeed been found
+ and adjust CMAKE_MODULE_PATH to contain the location where that package has
+ installed FindNotHere.cmake. This must be a location provided by that
+ package. This error in general means that the buildsystem of this project
+ is relying on a Find-module without ensuring that it is actually available.
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Warning at MissingModule.cmake:2 \(message\):
+ This warning must be reachable.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/find_package/MissingModule.cmake b/Tests/RunCMake/find_package/MissingModule.cmake
new file mode 100644
index 0000000000..76bcef293e
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingModule.cmake
@@ -0,0 +1,2 @@
+find_package(NotHere MODULE)
+message(WARNING "This warning must be reachable.")
diff --git a/Tests/RunCMake/find_package/MissingModuleRequired-result.txt b/Tests/RunCMake/find_package/MissingModuleRequired-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingModuleRequired-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_package/MissingModuleRequired-stderr.txt b/Tests/RunCMake/find_package/MissingModuleRequired-stderr.txt
new file mode 100644
index 0000000000..fec05f1834
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingModuleRequired-stderr.txt
@@ -0,0 +1,21 @@
+CMake Error at MissingModuleRequired.cmake:1 \(find_package\):
+ No "FindNotHere.cmake" found in CMAKE_MODULE_PATH.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Warning \(dev\) at MissingModuleRequired.cmake:1 \(find_package\):
+ FindNotHere.cmake must either be part of this project itself, in this case
+ adjust CMAKE_MODULE_PATH so that it points to the correct location inside
+ its source tree.
+
+ Or it must be installed by a package which has already been found via
+ find_package\(\). In this case make sure that package has indeed been found
+ and adjust CMAKE_MODULE_PATH to contain the location where that package has
+ installed FindNotHere.cmake. This must be a location provided by that
+ package. This error in general means that the buildsystem of this project
+ is relying on a Find-module without ensuring that it is actually available.
+
+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/find_package/MissingModuleRequired.cmake b/Tests/RunCMake/find_package/MissingModuleRequired.cmake
new file mode 100644
index 0000000000..897eda6886
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingModuleRequired.cmake
@@ -0,0 +1,2 @@
+find_package(NotHere MODULE REQUIRED)
+message(FATAL_ERROR "This error must not be reachable.")
diff --git a/Tests/RunCMake/find_package/MissingNormal-stderr.txt b/Tests/RunCMake/find_package/MissingNormal-stderr.txt
new file mode 100644
index 0000000000..f4c6fbafd2
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormal-stderr.txt
@@ -0,0 +1,23 @@
+CMake Warning at MissingNormal.cmake:1 \(find_package\):
+ By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has
+ asked CMake to find a package configuration file provided by "NotHere", but
+ CMake did not find one.
+
+ Could not find a package configuration file provided by "NotHere" with any
+ of the following names:
+
+ NotHereConfig.cmake
+ nothere-config.cmake
+
+ Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set
+ "NotHere_DIR" to a directory containing one of the above files. If
+ "NotHere" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Warning at MissingNormal.cmake:2 \(message\):
+ This warning must be reachable.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/find_package/MissingNormal.cmake b/Tests/RunCMake/find_package/MissingNormal.cmake
new file mode 100644
index 0000000000..fb90e01281
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormal.cmake
@@ -0,0 +1,2 @@
+find_package(NotHere)
+message(WARNING "This warning must be reachable.")
diff --git a/Tests/RunCMake/find_package/MissingNormalRequired-result.txt b/Tests/RunCMake/find_package/MissingNormalRequired-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormalRequired-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_package/MissingNormalRequired-stderr.txt b/Tests/RunCMake/find_package/MissingNormalRequired-stderr.txt
new file mode 100644
index 0000000000..7bb7902b6a
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormalRequired-stderr.txt
@@ -0,0 +1,17 @@
+CMake Error at MissingNormalRequired.cmake:1 \(find_package\):
+ By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has
+ asked CMake to find a package configuration file provided by "NotHere", but
+ CMake did not find one.
+
+ Could not find a package configuration file provided by "NotHere" with any
+ of the following names:
+
+ NotHereConfig.cmake
+ nothere-config.cmake
+
+ Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set
+ "NotHere_DIR" to a directory containing one of the above files. If
+ "NotHere" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/find_package/MissingNormalRequired.cmake b/Tests/RunCMake/find_package/MissingNormalRequired.cmake
new file mode 100644
index 0000000000..33353d8cda
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormalRequired.cmake
@@ -0,0 +1,2 @@
+find_package(NotHere REQUIRED)
+message(FATAL_ERROR "This error must not be reachable.")
diff --git a/Tests/RunCMake/find_package/MissingNormalVersion-stderr.txt b/Tests/RunCMake/find_package/MissingNormalVersion-stderr.txt
new file mode 100644
index 0000000000..36de8009e3
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormalVersion-stderr.txt
@@ -0,0 +1,17 @@
+CMake Warning at MissingNormalVersion.cmake:1 \(find_package\):
+ By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has
+ asked CMake to find a package configuration file provided by "NotHere", but
+ CMake did not find one.
+
+ Could not find a package configuration file provided by "NotHere"
+ \(requested version 1\.2\) with any of the following names:
+
+ NotHereConfig.cmake
+ nothere-config.cmake
+
+ Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set
+ "NotHere_DIR" to a directory containing one of the above files. If
+ "NotHere" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/find_package/MissingNormalVersion.cmake b/Tests/RunCMake/find_package/MissingNormalVersion.cmake
new file mode 100644
index 0000000000..2d9ce4ea52
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormalVersion.cmake
@@ -0,0 +1 @@
+find_package(NotHere 1.2)
diff --git a/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew-stderr.txt b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew-stderr.txt
new file mode 100644
index 0000000000..d34f23c8f1
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew-stderr.txt
@@ -0,0 +1,30 @@
+CMake Warning \(dev\) at MissingNormalWarnNoModuleNew.cmake:3 \(find_package\):
+ find_package called without either MODULE or CONFIG option and no
+ FindNotHere.cmake module is in CMAKE_MODULE_PATH. Add MODULE to
+ exclusively request Module mode and fail if FindNotHere.cmake is missing.
+ Add CONFIG to exclusively request Config mode and search for a package
+ configuration file provided by NotHere \(NotHereConfig.cmake or
+ nothere-config.cmake\).
+
+ \(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this 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 at MissingNormalWarnNoModuleNew.cmake:3 \(find_package\):
+ By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has
+ asked CMake to find a package configuration file provided by "NotHere", but
+ CMake did not find one.
+
+ Could not find a package configuration file provided by "NotHere" with any
+ of the following names:
+
+ NotHereConfig.cmake
+ nothere-config.cmake
+
+ Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set
+ "NotHere_DIR" to a directory containing one of the above files. If
+ "NotHere" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew.cmake b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew.cmake
new file mode 100644
index 0000000000..0211249c6f
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_FIND_PACKAGE_WARN_NO_MODULE 1)
+set(CMAKE_MINIMUM_REQUIRED_VERSION 2.8.8)
+find_package(NotHere)
diff --git a/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld-stderr.txt b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld-stderr.txt
new file mode 100644
index 0000000000..b336b5621e
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld-stderr.txt
@@ -0,0 +1,29 @@
+CMake Warning \(dev\) at MissingNormalWarnNoModuleOld.cmake:2 \(find_package\):
+ find_package called without NO_MODULE option and no FindNotHere.cmake
+ module is in CMAKE_MODULE_PATH. Add NO_MODULE to exclusively request
+ Config mode and search for a package configuration file provided by NotHere
+ \(NotHereConfig.cmake or nothere-config.cmake\). Otherwise make
+ FindNotHere.cmake available in CMAKE_MODULE_PATH.
+
+ \(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this 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 at MissingNormalWarnNoModuleOld.cmake:2 \(find_package\):
+ By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has
+ asked CMake to find a package configuration file provided by "NotHere", but
+ CMake did not find one.
+
+ Could not find a package configuration file provided by "NotHere" with any
+ of the following names:
+
+ NotHereConfig.cmake
+ nothere-config.cmake
+
+ Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set
+ "NotHere_DIR" to a directory containing one of the above files. If
+ "NotHere" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld.cmake b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld.cmake
new file mode 100644
index 0000000000..1c4a77599d
--- /dev/null
+++ b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld.cmake
@@ -0,0 +1,2 @@
+set(CMAKE_FIND_PACKAGE_WARN_NO_MODULE 1)
+find_package(NotHere)
diff --git a/Tests/RunCMake/find_package/MixedModeOptions-result.txt b/Tests/RunCMake/find_package/MixedModeOptions-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/find_package/MixedModeOptions-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/find_package/MixedModeOptions-stderr.txt b/Tests/RunCMake/find_package/MixedModeOptions-stderr.txt
new file mode 100644
index 0000000000..b8670221b3
--- /dev/null
+++ b/Tests/RunCMake/find_package/MixedModeOptions-stderr.txt
@@ -0,0 +1,14 @@
+CMake Error at MixedModeOptions.cmake:1 \(find_package\):
+ find_package given options exclusive to Module mode:
+
+ MODULE
+
+ and options exclusive to Config mode:
+
+ CONFIG
+ CONFIGS
+ NO_DEFAULT_PATH
+
+ The options are incompatible.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/find_package/MixedModeOptions.cmake b/Tests/RunCMake/find_package/MixedModeOptions.cmake
new file mode 100644
index 0000000000..7f78ee05f5
--- /dev/null
+++ b/Tests/RunCMake/find_package/MixedModeOptions.cmake
@@ -0,0 +1 @@
+find_package(NotHere MODULE CONFIG CONFIGS NotHereConfig.cmake NO_DEFAULT_PATH)
diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake
new file mode 100644
index 0000000000..42705b77a1
--- /dev/null
+++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake
@@ -0,0 +1,16 @@
+include(RunCMake)
+
+run_cmake(ComponentRequiredAndOptional)
+run_cmake(MissingNormal)
+run_cmake(MissingNormalRequired)
+run_cmake(MissingNormalVersion)
+run_cmake(MissingNormalWarnNoModuleOld)
+run_cmake(MissingNormalWarnNoModuleNew)
+run_cmake(MissingModule)
+run_cmake(MissingModuleRequired)
+run_cmake(MissingConfig)
+run_cmake(MissingConfigOneName)
+run_cmake(MissingConfigRequired)
+run_cmake(MissingConfigVersion)
+run_cmake(MixedModeOptions)
+run_cmake(SetFoundFALSE)
diff --git a/Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt b/Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt
new file mode 100644
index 0000000000..695f6450d3
--- /dev/null
+++ b/Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt
@@ -0,0 +1,9 @@
+CMake Warning at SetFoundFALSE.cmake:2 \(find_package\):
+ Found package configuration file:
+
+ .*/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake
+
+ but it set SetFoundFALSE_FOUND to FALSE so package "SetFoundFALSE" is
+ considered to be NOT FOUND.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/find_package/SetFoundFALSE.cmake b/Tests/RunCMake/find_package/SetFoundFALSE.cmake
new file mode 100644
index 0000000000..fbcec3c56b
--- /dev/null
+++ b/Tests/RunCMake/find_package/SetFoundFALSE.cmake
@@ -0,0 +1,2 @@
+set(SetFoundFALSE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+find_package(SetFoundFALSE CONFIG)
diff --git a/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake b/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake
new file mode 100644
index 0000000000..ae6bd14540
--- /dev/null
+++ b/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake
@@ -0,0 +1 @@
+set(SetFoundFALSE_FOUND FALSE)
diff --git a/Tests/RunCMake/get_filename_component/CMakeLists.txt b/Tests/RunCMake/get_filename_component/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/get_filename_component/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/get_filename_component/KnownComponents.cmake b/Tests/RunCMake/get_filename_component/KnownComponents.cmake
new file mode 100644
index 0000000000..9d7cf9079b
--- /dev/null
+++ b/Tests/RunCMake/get_filename_component/KnownComponents.cmake
@@ -0,0 +1,38 @@
+macro(check desc actual expect)
+ if(NOT "x${actual}" STREQUAL "x${expect}")
+ message(SEND_ERROR "${desc}: got \"${actual}\", not \"${expect}\"")
+ endif()
+endmacro()
+
+set(filename "/path/to/filename.ext.in")
+set(expect_DIRECTORY "/path/to")
+set(expect_NAME "filename.ext.in")
+set(expect_EXT ".ext.in")
+set(expect_NAME_WE "filename")
+set(expect_PATH "/path/to")
+foreach(c DIRECTORY NAME EXT NAME_WE PATH)
+ get_filename_component(actual_${c} "${filename}" ${c})
+ check("${c}" "${actual_${c}}" "${expect_${c}}")
+endforeach()
+
+get_filename_component(test_slashes "c:\\path\\to\\filename.ext.in" DIRECTORY)
+check("DIRECTORY from backslashes" "${test_slashes}" "c:/path/to")
+
+get_filename_component(test_winroot "c:\\filename.ext.in" DIRECTORY)
+check("DIRECTORY in windows root" "${test_winroot}" "c:/")
+
+get_filename_component(test_absolute "/path/to/a/../filename.ext.in" ABSOLUTE)
+check("ABSOLUTE" "${test_absolute}" "/path/to/filename.ext.in")
+
+get_filename_component(test_absolute "/../path/to/filename.ext.in" ABSOLUTE)
+check("ABSOLUTE .. in root" "${test_absolute}" "/path/to/filename.ext.in")
+get_filename_component(test_absolute "c:/../path/to/filename.ext.in" ABSOLUTE)
+check("ABSOLUTE .. in windows root" "${test_absolute}" "c:/path/to/filename.ext.in")
+
+get_filename_component(test_cache "/path/to/filename.ext.in" DIRECTORY CACHE)
+check("CACHE 1" "${test_cache}" "/path/to")
+get_filename_component(test_cache "/path/to/other/filename.ext.in" DIRECTORY CACHE)
+check("CACHE 2" "${test_cache}" "/path/to")
+unset(test_cache CACHE)
+get_filename_component(test_cache "/path/to/other/filename.ext.in" DIRECTORY CACHE)
+check("CACHE 3" "${test_cache}" "/path/to/other")
diff --git a/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake b/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake
new file mode 100644
index 0000000000..156fc8f3cc
--- /dev/null
+++ b/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake
@@ -0,0 +1,4 @@
+include(RunCMake)
+
+run_cmake(KnownComponents)
+run_cmake(UnknownComponent)
diff --git a/Tests/RunCMake/get_filename_component/UnknownComponent-result.txt b/Tests/RunCMake/get_filename_component/UnknownComponent-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/get_filename_component/UnknownComponent-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt b/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt
new file mode 100644
index 0000000000..b146e5b4bf
--- /dev/null
+++ b/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at UnknownComponent.cmake:1 \(get_filename_component\):
+ get_filename_component unknown component BOGUS
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/get_filename_component/UnknownComponent.cmake b/Tests/RunCMake/get_filename_component/UnknownComponent.cmake
new file mode 100644
index 0000000000..06abc51e62
--- /dev/null
+++ b/Tests/RunCMake/get_filename_component/UnknownComponent.cmake
@@ -0,0 +1 @@
+get_filename_component(var "/path/to/filename.ext.in" BOGUS)
diff --git a/Tests/RunCMake/if/CMakeLists.txt b/Tests/RunCMake/if/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/if/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/if/IsDirectory-stdout.txt b/Tests/RunCMake/if/IsDirectory-stdout.txt
new file mode 100644
index 0000000000..b89446a655
--- /dev/null
+++ b/Tests/RunCMake/if/IsDirectory-stdout.txt
@@ -0,0 +1 @@
+CMAKE_CURRENT_SOURCE_DIR exists, tested with trailing slash
diff --git a/Tests/RunCMake/if/IsDirectory.cmake b/Tests/RunCMake/if/IsDirectory.cmake
new file mode 100644
index 0000000000..23d126dd46
--- /dev/null
+++ b/Tests/RunCMake/if/IsDirectory.cmake
@@ -0,0 +1,5 @@
+if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/")
+ message(STATUS "CMAKE_CURRENT_SOURCE_DIR exists, tested with trailing slash")
+else()
+ message(FATAL_ERROR "CMAKE_CURRENT_SOURCE_DIR does not exist!")
+endif()
diff --git a/Tests/RunCMake/if/IsDirectoryLong-stdout.txt b/Tests/RunCMake/if/IsDirectoryLong-stdout.txt
new file mode 100644
index 0000000000..5e6275429b
--- /dev/null
+++ b/Tests/RunCMake/if/IsDirectoryLong-stdout.txt
@@ -0,0 +1 @@
+Directory path with length 94208 correctly does not exist.
diff --git a/Tests/RunCMake/if/IsDirectoryLong.cmake b/Tests/RunCMake/if/IsDirectoryLong.cmake
new file mode 100644
index 0000000000..0e93be7449
--- /dev/null
+++ b/Tests/RunCMake/if/IsDirectoryLong.cmake
@@ -0,0 +1,10 @@
+set(d "/long/path/to/directory")
+foreach(i RANGE 11)
+ set(d "${d}${d}")
+endforeach()
+string(LENGTH "${d}" dl)
+if(IS_DIRECTORY "${d}/")
+ message(FATAL_ERROR "Directory should not exist!")
+else()
+ message(STATUS "Directory path with length ${dl} correctly does not exist.")
+endif()
diff --git a/Tests/RunCMake/if/RunCMakeTest.cmake b/Tests/RunCMake/if/RunCMakeTest.cmake
new file mode 100644
index 0000000000..6b6b74b546
--- /dev/null
+++ b/Tests/RunCMake/if/RunCMakeTest.cmake
@@ -0,0 +1,4 @@
+include(RunCMake)
+
+run_cmake(IsDirectory)
+run_cmake(IsDirectoryLong)
diff --git a/Tests/RunCMake/include/CMP0024-NEW-result.txt b/Tests/RunCMake/include/CMP0024-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include/CMP0024-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include/CMP0024-NEW-stderr.txt b/Tests/RunCMake/include/CMP0024-NEW-stderr.txt
new file mode 100644
index 0000000000..0fdb3ca7f1
--- /dev/null
+++ b/Tests/RunCMake/include/CMP0024-NEW-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at subdir2/CMakeLists.txt:2 \(include\):
+ The file
+
+ .*/Tests/RunCMake/include/CMP0024-NEW-build/subdir1/theTargets.cmake
+
+ was generated by the export\(\) command. It may not be used as the argument
+ to the include\(\) command. Use ALIAS targets instead to refer to targets by
+ alternative names.
diff --git a/Tests/RunCMake/include/CMP0024-NEW.cmake b/Tests/RunCMake/include/CMP0024-NEW.cmake
new file mode 100644
index 0000000000..0e03d2af85
--- /dev/null
+++ b/Tests/RunCMake/include/CMP0024-NEW.cmake
@@ -0,0 +1,9 @@
+
+enable_language(CXX)
+
+cmake_policy(SET CMP0024 NEW)
+
+add_library(foo SHARED empty.cpp)
+
+add_subdirectory(subdir1)
+add_subdirectory(subdir2)
diff --git a/Tests/RunCMake/include/CMP0024-WARN-result.txt b/Tests/RunCMake/include/CMP0024-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include/CMP0024-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include/CMP0024-WARN-stderr.txt b/Tests/RunCMake/include/CMP0024-WARN-stderr.txt
new file mode 100644
index 0000000000..9c79007058
--- /dev/null
+++ b/Tests/RunCMake/include/CMP0024-WARN-stderr.txt
@@ -0,0 +1,14 @@
+CMake Warning \(dev\) at subdir2/CMakeLists.txt:2 \(include\):
+ Policy CMP0024 is not set: Disallow include export result. Run "cmake
+ --help-policy CMP0024" for policy details. Use the cmake_policy command to
+ set the policy and suppress this warning.
+
+ The file
+
+ .*/Tests/RunCMake/include/CMP0024-WARN-build/subdir1/theTargets.cmake
+
+ was generated by the export\(\) command. It should not be used as the
+ argument to the include\(\) command. Use ALIAS targets instead to refer to
+ targets by alternative names.
+
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/include/CMP0024-WARN.cmake b/Tests/RunCMake/include/CMP0024-WARN.cmake
new file mode 100644
index 0000000000..783cf78e5d
--- /dev/null
+++ b/Tests/RunCMake/include/CMP0024-WARN.cmake
@@ -0,0 +1,7 @@
+
+enable_language(CXX)
+
+add_library(foo SHARED empty.cpp)
+
+add_subdirectory(subdir1)
+add_subdirectory(subdir2)
diff --git a/Tests/RunCMake/include/CMakeLists.txt b/Tests/RunCMake/include/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/include/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/include/EmptyString-stderr.txt b/Tests/RunCMake/include/EmptyString-stderr.txt
new file mode 100644
index 0000000000..006c647c66
--- /dev/null
+++ b/Tests/RunCMake/include/EmptyString-stderr.txt
@@ -0,0 +1,5 @@
+CMake Warning \(dev\) at EmptyString.cmake:1 \(include\):
+ include\(\) given empty file name \(ignored\).
+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/include/EmptyString.cmake b/Tests/RunCMake/include/EmptyString.cmake
new file mode 100644
index 0000000000..4285cb3d5d
--- /dev/null
+++ b/Tests/RunCMake/include/EmptyString.cmake
@@ -0,0 +1 @@
+include("")
diff --git a/Tests/RunCMake/include/EmptyStringOptional-stderr.txt b/Tests/RunCMake/include/EmptyStringOptional-stderr.txt
new file mode 100644
index 0000000000..b61c679128
--- /dev/null
+++ b/Tests/RunCMake/include/EmptyStringOptional-stderr.txt
@@ -0,0 +1,5 @@
+CMake Warning \(dev\) at EmptyStringOptional.cmake:1 \(include\):
+ include\(\) given empty file name \(ignored\).
+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/include/EmptyStringOptional.cmake b/Tests/RunCMake/include/EmptyStringOptional.cmake
new file mode 100644
index 0000000000..549d46b3db
--- /dev/null
+++ b/Tests/RunCMake/include/EmptyStringOptional.cmake
@@ -0,0 +1 @@
+include("" OPTIONAL)
diff --git a/Tests/RunCMake/include/ExportExportInclude-result.txt b/Tests/RunCMake/include/ExportExportInclude-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include/ExportExportInclude-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include/ExportExportInclude-stderr.txt b/Tests/RunCMake/include/ExportExportInclude-stderr.txt
new file mode 100644
index 0000000000..70d013cfd6
--- /dev/null
+++ b/Tests/RunCMake/include/ExportExportInclude-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at ExportExportInclude.cmake:6 \(include\):
+ include could not find load file:
+
+ .*/Tests/RunCMake/include/ExportExportInclude-build/theTargets.cmake
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/include/ExportExportInclude.cmake b/Tests/RunCMake/include/ExportExportInclude.cmake
new file mode 100644
index 0000000000..14e5d913f1
--- /dev/null
+++ b/Tests/RunCMake/include/ExportExportInclude.cmake
@@ -0,0 +1,6 @@
+
+add_library(iface INTERFACE)
+install(TARGETS iface EXPORT ifaceExport)
+
+export(EXPORT ifaceExport FILE "${CMAKE_CURRENT_BINARY_DIR}/theTargets.cmake")
+include("${CMAKE_CURRENT_BINARY_DIR}/theTargets.cmake")
diff --git a/Tests/RunCMake/include/RunCMakeTest.cmake b/Tests/RunCMake/include/RunCMakeTest.cmake
new file mode 100644
index 0000000000..bea7d5cc48
--- /dev/null
+++ b/Tests/RunCMake/include/RunCMakeTest.cmake
@@ -0,0 +1,7 @@
+include(RunCMake)
+
+run_cmake(EmptyString)
+run_cmake(EmptyStringOptional)
+run_cmake(CMP0024-WARN)
+run_cmake(CMP0024-NEW)
+run_cmake(ExportExportInclude)
diff --git a/Tests/RunCMake/include/empty.cpp b/Tests/RunCMake/include/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/include/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/include/subdir1/CMakeLists.txt b/Tests/RunCMake/include/subdir1/CMakeLists.txt
new file mode 100644
index 0000000000..11a76d1dd3
--- /dev/null
+++ b/Tests/RunCMake/include/subdir1/CMakeLists.txt
@@ -0,0 +1,2 @@
+
+export(TARGETS foo FILE "${CMAKE_CURRENT_BINARY_DIR}/theTargets.cmake")
diff --git a/Tests/RunCMake/include/subdir2/CMakeLists.txt b/Tests/RunCMake/include/subdir2/CMakeLists.txt
new file mode 100644
index 0000000000..7361f9cb11
--- /dev/null
+++ b/Tests/RunCMake/include/subdir2/CMakeLists.txt
@@ -0,0 +1,2 @@
+
+include("${CMAKE_CURRENT_BINARY_DIR}/../subdir1/theTargets.cmake")
diff --git a/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-NEW-result.txt b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-NEW-stderr.txt b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-NEW-stderr.txt
new file mode 100644
index 0000000000..f0adc9f39f
--- /dev/null
+++ b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-NEW-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error in CMakeLists.txt:
+ Target "testTarget" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*Tests/RunCMake/include_directories/prefix/BinInInstallPrefix-CMP0052-NEW-build/foo"
+
+ which is prefixed in the build directory.
diff --git a/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-OLD-result.txt b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-OLD-stderr.txt b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-WARN-result.txt b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-WARN-stderr.txt b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-WARN-stderr.txt
new file mode 100644
index 0000000000..054bff5959
--- /dev/null
+++ b/Tests/RunCMake/include_directories/BinInInstallPrefix-CMP0052-WARN-stderr.txt
@@ -0,0 +1,20 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+ Policy CMP0052 is not set: Reject source and build dirs in installed
+ INTERFACE_INCLUDE_DIRECTORIES. Run "cmake --help-policy CMP0052" for
+ policy details. Use the cmake_policy command to set the policy and
+ suppress this warning.
+
+ Directory:
+
+ ".*Tests/RunCMake/include_directories/prefix/BinInInstallPrefix-CMP0052-WARN-build/foo"
+
+ in INTERFACE_INCLUDE_DIRECTORIES of target "testTarget" is a subdirectory
+ of the install directory:
+
+ ".*Tests/RunCMake/include_directories/prefix"
+
+ however it is also a subdirectory of the build tree:
+
+ ".*Tests/RunCMake/include_directories/prefix/BinInInstallPrefix-CMP0052-WARN-build"
+
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/include_directories/BinaryDirectoryInInterface-result.txt b/Tests/RunCMake/include_directories/BinaryDirectoryInInterface-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/BinaryDirectoryInInterface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/BinaryDirectoryInInterface-stderr.txt b/Tests/RunCMake/include_directories/BinaryDirectoryInInterface-stderr.txt
new file mode 100644
index 0000000000..0d4379eb0e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/BinaryDirectoryInInterface-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error in CMakeLists.txt:
+ Target "testTarget" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*RunCMake/include_directories/BinaryDirectoryInInterface-build/foo"
+
+ which is prefixed in the build directory.
diff --git a/Tests/RunCMake/include_directories/BinaryDirectoryInInterface.cmake b/Tests/RunCMake/include_directories/BinaryDirectoryInInterface.cmake
new file mode 100644
index 0000000000..67ee7de84a
--- /dev/null
+++ b/Tests/RunCMake/include_directories/BinaryDirectoryInInterface.cmake
@@ -0,0 +1,11 @@
+
+enable_language(CXX)
+
+add_library(testTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+target_include_directories(testTarget INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/foo")
+
+install(TARGETS testTarget EXPORT testTargets
+ DESTINATION lib
+)
+
+install(EXPORT testTargets DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/include_directories/CMP0021-result.txt b/Tests/RunCMake/include_directories/CMP0021-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/CMP0021-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/CMP0021-stderr.txt b/Tests/RunCMake/include_directories/CMP0021-stderr.txt
new file mode 100644
index 0000000000..c0781e7cf6
--- /dev/null
+++ b/Tests/RunCMake/include_directories/CMP0021-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error in CMakeLists.txt:
+ Found relative path while evaluating include directories of "userTarget":
+
+ "foo"
diff --git a/Tests/RunCMake/include_directories/CMP0021.cmake b/Tests/RunCMake/include_directories/CMP0021.cmake
new file mode 100644
index 0000000000..f18666b076
--- /dev/null
+++ b/Tests/RunCMake/include_directories/CMP0021.cmake
@@ -0,0 +1,9 @@
+enable_language(CXX)
+
+cmake_policy(SET CMP0021 NEW)
+
+add_library(testTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+set_property(TARGET testTarget PROPERTY INTERFACE_INCLUDE_DIRECTORIES "$<1:foo>")
+
+add_library(userTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+target_include_directories(userTarget PRIVATE $<TARGET_PROPERTY:testTarget,INTERFACE_INCLUDE_DIRECTORIES>)
diff --git a/Tests/RunCMake/include_directories/CMakeLists.txt b/Tests/RunCMake/include_directories/CMakeLists.txt
new file mode 100644
index 0000000000..5cd4825e66
--- /dev/null
+++ b/Tests/RunCMake/include_directories/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} NONE)
+if(NOT TEST_FILE)
+ set(TEST_FILE ${RunCMake_TEST}.cmake)
+endif()
+include(${TEST_FILE})
diff --git a/Tests/RunCMake/include_directories/DebugIncludes-result.txt b/Tests/RunCMake/include_directories/DebugIncludes-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/DebugIncludes-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt b/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt
new file mode 100644
index 0000000000..8dff90f726
--- /dev/null
+++ b/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt
@@ -0,0 +1,53 @@
+CMake Debug Log at DebugIncludes.cmake:8 \(include_directories\):
+ Used includes for target lll:
+
+ \* .*/Tests/RunCMake/include_directories/one
+ \* .*/Tests/RunCMake/include_directories/two
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
++
+CMake Debug Log at DebugIncludes.cmake:13 \(set_property\):
+ Used includes for target lll:
+
+ \* .*/Tests/RunCMake/include_directories/three
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
++
+CMake Debug Log at DebugIncludes.cmake:18 \(include_directories\):
+ Used includes for target lll:
+
+ \* .*/Tests/RunCMake/include_directories/four
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
++
+CMake Debug Log at DebugIncludes.cmake:33 \(set_property\):
+ Used includes for target lll:
+
+ \* .*/Tests/RunCMake/include_directories/five
+ \* .*/Tests/RunCMake/include_directories/six
+ \* .*/Tests/RunCMake/include_directories/seven
+
+Call Stack \(most recent call first\):
+ DebugIncludes.cmake:44 \(some_macro\)
+ DebugIncludes.cmake:47 \(some_function\)
+ CMakeLists.txt:[0-9]+ \(include\)
++
+CMake Debug Log at DebugIncludes.cmake:30 \(target_link_libraries\):
+ Used includes for target lll:
+
+ \* .*/Tests/RunCMake/include_directories/eight
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
++
+CMake Debug Log at DebugIncludes.cmake:55 \(set_property\):
+ Used includes for target lll:
+
+ \* .*/Tests/RunCMake/include_directories/nine
+ \* .*/Tests/RunCMake/include_directories/ten
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/include_directories/DebugIncludes.cmake b/Tests/RunCMake/include_directories/DebugIncludes.cmake
new file mode 100644
index 0000000000..10a4c50206
--- /dev/null
+++ b/Tests/RunCMake/include_directories/DebugIncludes.cmake
@@ -0,0 +1,55 @@
+
+enable_language(CXX)
+
+set(CMAKE_DEBUG_TARGET_PROPERTIES INCLUDE_DIRECTORIES)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/DebugIncludes.cpp" "enum { dummy };\n")
+
+include_directories(
+ "${CMAKE_CURRENT_SOURCE_DIR}/one"
+ "${CMAKE_CURRENT_SOURCE_DIR}/two"
+)
+
+set_property(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES
+ "${CMAKE_CURRENT_SOURCE_DIR}/three")
+
+add_library(lll "${CMAKE_CURRENT_BINARY_DIR}/DebugIncludes.cpp")
+
+include_directories(
+ "${CMAKE_CURRENT_SOURCE_DIR}/two"
+ "${CMAKE_CURRENT_SOURCE_DIR}/three"
+ "${CMAKE_CURRENT_SOURCE_DIR}/four"
+)
+
+add_library(foo "${CMAKE_CURRENT_BINARY_DIR}/DebugIncludes.cpp")
+target_include_directories(foo
+ INTERFACE
+ "${CMAKE_CURRENT_SOURCE_DIR}/seven"
+ "${CMAKE_CURRENT_SOURCE_DIR}/eight"
+)
+target_link_libraries(lll foo)
+
+macro(some_macro)
+ set_property(TARGET lll APPEND PROPERTY
+ INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/one"
+ "${CMAKE_CURRENT_SOURCE_DIR}/three"
+ "${CMAKE_CURRENT_SOURCE_DIR}/four"
+ "${CMAKE_CURRENT_SOURCE_DIR}/five"
+ "${CMAKE_CURRENT_SOURCE_DIR}/six"
+ "${CMAKE_CURRENT_SOURCE_DIR}/seven"
+ )
+endmacro()
+
+function(some_function)
+ some_macro()
+endfunction()
+
+some_function()
+
+add_library(bar "${CMAKE_CURRENT_BINARY_DIR}/DebugIncludes.cpp")
+target_include_directories(bar
+ INTERFACE
+ "${CMAKE_CURRENT_SOURCE_DIR}/nine"
+ "${CMAKE_CURRENT_SOURCE_DIR}/ten"
+)
+set_property(TARGET lll APPEND PROPERTY LINK_LIBRARIES bar)
diff --git a/Tests/RunCMake/include_directories/DirInInstallPrefix-result.txt b/Tests/RunCMake/include_directories/DirInInstallPrefix-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/DirInInstallPrefix-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/DirInInstallPrefix-stderr.txt b/Tests/RunCMake/include_directories/DirInInstallPrefix-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/include_directories/DirInInstallPrefix-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/include_directories/DirInInstallPrefix.cmake b/Tests/RunCMake/include_directories/DirInInstallPrefix.cmake
new file mode 100644
index 0000000000..fab771718b
--- /dev/null
+++ b/Tests/RunCMake/include_directories/DirInInstallPrefix.cmake
@@ -0,0 +1,9 @@
+enable_language(CXX)
+add_library(testTarget empty.cpp)
+target_include_directories(testTarget INTERFACE "${CMAKE_INSTALL_PREFIX}/dir")
+
+install(TARGETS testTarget EXPORT testTargets
+ DESTINATION lib
+)
+
+install(EXPORT testTargets DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/include_directories/ImportedTarget-result.txt b/Tests/RunCMake/include_directories/ImportedTarget-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/ImportedTarget-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/ImportedTarget-stderr.txt b/Tests/RunCMake/include_directories/ImportedTarget-stderr.txt
new file mode 100644
index 0000000000..da26052977
--- /dev/null
+++ b/Tests/RunCMake/include_directories/ImportedTarget-stderr.txt
@@ -0,0 +1,13 @@
+CMake Error in CMakeLists.txt:
+ Imported target "imported" includes non-existent path
+
+ "/does/not/exist"
+
+ in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
+
+ \* The path was deleted, renamed, or moved to another location.
+
+ \* An install or uninstall procedure did not complete successfully.
+
+ \* The installation package was faulty and references files it does not
+ provide.
diff --git a/Tests/RunCMake/include_directories/ImportedTarget.cmake b/Tests/RunCMake/include_directories/ImportedTarget.cmake
new file mode 100644
index 0000000000..f752f98e95
--- /dev/null
+++ b/Tests/RunCMake/include_directories/ImportedTarget.cmake
@@ -0,0 +1,9 @@
+
+enable_language(CXX)
+
+add_library(testTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+
+add_library(imported UNKNOWN IMPORTED)
+set_property(TARGET imported PROPERTY INTERFACE_INCLUDE_DIRECTORIES "/does/not/exist")
+
+target_link_libraries(testTarget imported)
diff --git a/Tests/RunCMake/include_directories/InstallInBinDir-result.txt b/Tests/RunCMake/include_directories/InstallInBinDir-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallInBinDir-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/InstallInBinDir-stderr.txt b/Tests/RunCMake/include_directories/InstallInBinDir-stderr.txt
new file mode 100644
index 0000000000..254fae15eb
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallInBinDir-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error in CMakeLists.txt:
+ Target "testTarget" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*Tests/RunCMake/include_directories/InstallInBinDir-build/foo"
+
+ which is prefixed in the build directory.
diff --git a/Tests/RunCMake/include_directories/InstallInSrcDir-result.txt b/Tests/RunCMake/include_directories/InstallInSrcDir-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallInSrcDir-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/InstallInSrcDir-stderr.txt b/Tests/RunCMake/include_directories/InstallInSrcDir-stderr.txt
new file mode 100644
index 0000000000..7be3044add
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallInSrcDir-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error in CMakeLists.txt:
+ Target "testTarget" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*Tests/RunCMake/include_directories/copy/foo"
+
+ which is prefixed in the source directory.
diff --git a/Tests/RunCMake/include_directories/InstallPrefixInInterface-result.txt b/Tests/RunCMake/include_directories/InstallPrefixInInterface-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallPrefixInInterface-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/InstallPrefixInInterface-stderr.txt b/Tests/RunCMake/include_directories/InstallPrefixInInterface-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallPrefixInInterface-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/include_directories/InstallPrefixInInterface.cmake b/Tests/RunCMake/include_directories/InstallPrefixInInterface.cmake
new file mode 100644
index 0000000000..8d777f53cc
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallPrefixInInterface.cmake
@@ -0,0 +1,11 @@
+
+enable_language(CXX)
+
+add_library(testTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+target_include_directories(testTarget INTERFACE "${CMAKE_INSTALL_PREFIX}/foo")
+
+install(TARGETS testTarget EXPORT testTargets
+ DESTINATION lib
+)
+
+install(EXPORT testTargets DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirInSource-result.txt b/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirInSource-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirInSource-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirInSource-stderr.txt b/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirInSource-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirInSource-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirOutOfSource-result.txt b/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirOutOfSource-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirOutOfSource-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirOutOfSource-stderr.txt b/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirOutOfSource-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/include_directories/InstallToPrefixInSrcDirOutOfSource-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/include_directories/NotFoundContent-result.txt b/Tests/RunCMake/include_directories/NotFoundContent-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/NotFoundContent-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/NotFoundContent-stderr.txt b/Tests/RunCMake/include_directories/NotFoundContent-stderr.txt
new file mode 100644
index 0000000000..f608d633fe
--- /dev/null
+++ b/Tests/RunCMake/include_directories/NotFoundContent-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
+Please set them or make sure they are set and tested correctly in the CMake files:
+NotThere1
+ used as include directory in directory .*
+NotThere2
+ used as include directory in directory .*
diff --git a/Tests/RunCMake/include_directories/NotFoundContent.cmake b/Tests/RunCMake/include_directories/NotFoundContent.cmake
new file mode 100644
index 0000000000..9677e0c43a
--- /dev/null
+++ b/Tests/RunCMake/include_directories/NotFoundContent.cmake
@@ -0,0 +1,9 @@
+
+include_directories(NotThere1-NOTFOUND)
+
+include_directories($<1:There1-NOTFOUND>)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp" "int main(int,char**) { return 0; }\n")
+add_executable(dummy "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp")
+set_property(TARGET dummy APPEND PROPERTY INCLUDE_DIRECTORIES "NotThere2-NOTFOUND")
+set_property(TARGET dummy APPEND PROPERTY INCLUDE_DIRECTORIES "$<1:There2-NOTFOUND>")
diff --git a/Tests/RunCMake/include_directories/RelativePathInGenex-result.txt b/Tests/RunCMake/include_directories/RelativePathInGenex-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/RelativePathInGenex-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/RelativePathInGenex-stderr.txt b/Tests/RunCMake/include_directories/RelativePathInGenex-stderr.txt
new file mode 100644
index 0000000000..490c700f86
--- /dev/null
+++ b/Tests/RunCMake/include_directories/RelativePathInGenex-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error in CMakeLists.txt:
+ Target "testTarget" contains relative path in its
+ INTERFACE_INCLUDE_DIRECTORIES:
+
+ "foo"
diff --git a/Tests/RunCMake/include_directories/RelativePathInGenex.cmake b/Tests/RunCMake/include_directories/RelativePathInGenex.cmake
new file mode 100644
index 0000000000..070a381d27
--- /dev/null
+++ b/Tests/RunCMake/include_directories/RelativePathInGenex.cmake
@@ -0,0 +1,8 @@
+
+enable_language(CXX)
+
+add_library(testTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+set_property(TARGET testTarget PROPERTY INTERFACE_INCLUDE_DIRECTORIES "$<1:foo>")
+
+add_library(userTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+target_link_libraries(userTarget testTarget)
diff --git a/Tests/RunCMake/include_directories/RelativePathInInterface-result.txt b/Tests/RunCMake/include_directories/RelativePathInInterface-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/RelativePathInInterface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/RelativePathInInterface-stderr.txt b/Tests/RunCMake/include_directories/RelativePathInInterface-stderr.txt
new file mode 100644
index 0000000000..f6cdb532e1
--- /dev/null
+++ b/Tests/RunCMake/include_directories/RelativePathInInterface-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error in CMakeLists.txt:
+ Target "testTarget" INTERFACE_INCLUDE_DIRECTORIES property contains
+ relative path:
+
+ "foo"
diff --git a/Tests/RunCMake/include_directories/RelativePathInInterface.cmake b/Tests/RunCMake/include_directories/RelativePathInInterface.cmake
new file mode 100644
index 0000000000..4c4727d42f
--- /dev/null
+++ b/Tests/RunCMake/include_directories/RelativePathInInterface.cmake
@@ -0,0 +1,11 @@
+
+enable_language(CXX)
+
+add_library(testTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+set_property(TARGET testTarget PROPERTY INTERFACE_INCLUDE_DIRECTORIES "foo")
+
+install(TARGETS testTarget EXPORT testTargets
+ DESTINATION lib
+)
+
+install(EXPORT testTargets DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/include_directories/RunCMakeTest.cmake b/Tests/RunCMake/include_directories/RunCMakeTest.cmake
new file mode 100644
index 0000000000..fa76f24354
--- /dev/null
+++ b/Tests/RunCMake/include_directories/RunCMakeTest.cmake
@@ -0,0 +1,150 @@
+include(RunCMake)
+
+run_cmake(NotFoundContent)
+run_cmake(DebugIncludes)
+run_cmake(TID-bad-target)
+run_cmake(SourceDirectoryInInterface)
+run_cmake(BinaryDirectoryInInterface)
+run_cmake(RelativePathInInterface)
+run_cmake(ImportedTarget)
+run_cmake(RelativePathInGenex)
+run_cmake(CMP0021)
+run_cmake(install_config)
+run_cmake(incomplete-genex)
+run_cmake(export-NOWARN)
+
+set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/DirInInstallPrefix/prefix")
+run_cmake(DirInInstallPrefix)
+
+configure_file(
+ "${RunCMake_SOURCE_DIR}/CMakeLists.txt"
+ "${RunCMake_BINARY_DIR}/copy/CMakeLists.txt"
+ COPYONLY
+)
+configure_file(
+ "${RunCMake_SOURCE_DIR}/empty.cpp"
+ "${RunCMake_BINARY_DIR}/copy/empty.cpp"
+ COPYONLY
+)
+configure_file(
+ "${RunCMake_SOURCE_DIR}/SourceDirectoryInInterface.cmake"
+ "${RunCMake_BINARY_DIR}/copy/SourceDirectoryInInterface.cmake"
+ COPYONLY
+)
+set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/copy/SourceDirectoryInInterface/prefix"
+ "-DTEST_FILE=${RunCMake_BINARY_DIR}/copy/SourceDirectoryInInterface.cmake"
+ )
+set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/copy")
+run_cmake(InstallInSrcDir)
+unset(RunCMake_TEST_SOURCE_DIR)
+
+set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/InstallInBinDir-build/prefix")
+set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/InstallInBinDir-build/prefix"
+ "-DTEST_FILE=${RunCMake_SOURCE_DIR}/BinaryDirectoryInInterface.cmake"
+ )
+set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/InstallInBinDir-build")
+run_cmake(InstallInBinDir)
+unset(RunCMake_TEST_BINARY_DIR)
+
+configure_file(
+ "${RunCMake_SOURCE_DIR}/CMakeLists.txt"
+ "${RunCMake_BINARY_DIR}/prefix/src/CMakeLists.txt"
+ COPYONLY
+)
+configure_file(
+ "${RunCMake_SOURCE_DIR}/empty.cpp"
+ "${RunCMake_BINARY_DIR}/prefix/src/empty.cpp"
+ COPYONLY
+)
+configure_file(
+ "${RunCMake_SOURCE_DIR}/SourceDirectoryInInterface.cmake"
+ "${RunCMake_BINARY_DIR}/prefix/src/SourceDirectoryInInterface.cmake"
+ COPYONLY
+)
+
+foreach(policyStatus "" NEW OLD)
+ if (NOT "${policyStatus}" STREQUAL "")
+ set(policyOption -DCMAKE_POLICY_DEFAULT_CMP0052=${policyStatus})
+ else()
+ unset(policyOption)
+ set(policyStatus WARN)
+ endif()
+ set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/prefix" ${policyOption}
+ "-DTEST_FILE=${RunCMake_SOURCE_DIR}/BinaryDirectoryInInterface.cmake"
+ )
+ # Set the RunCMake_TEST_SOURCE_DIR here to the copy too. This is needed to run
+ # the test suite in-source properly. Otherwise the install directory would be
+ # a subdirectory or the source directory, which is allowed and tested separately
+ # below.
+ set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/prefix/src")
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/prefix/BinInInstallPrefix-CMP0052-${policyStatus}-build")
+ run_cmake(BinInInstallPrefix-CMP0052-${policyStatus})
+ unset(RunCMake_TEST_BINARY_DIR)
+
+ set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/prefix" ${policyOption}
+ "-DTEST_FILE=${RunCMake_BINARY_DIR}/prefix/src/SourceDirectoryInInterface.cmake"
+ )
+ run_cmake(SrcInInstallPrefix-CMP0052-${policyStatus})
+ unset(RunCMake_TEST_SOURCE_DIR)
+endforeach()
+
+set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/InstallPrefixInInterface-build/prefix")
+run_cmake(InstallPrefixInInterface)
+
+configure_file(
+ "${RunCMake_SOURCE_DIR}/CMakeLists.txt"
+ "${RunCMake_BINARY_DIR}/installToSrc/CMakeLists.txt"
+ COPYONLY
+)
+configure_file(
+ "${RunCMake_SOURCE_DIR}/empty.cpp"
+ "${RunCMake_BINARY_DIR}/installToSrc/empty.cpp"
+ COPYONLY
+)
+configure_file(
+ "${RunCMake_SOURCE_DIR}/InstallPrefixInInterface.cmake"
+ "${RunCMake_BINARY_DIR}/installToSrc/InstallPrefixInInterface.cmake"
+ COPYONLY
+)
+set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/installToSrc/InstallPrefixInInterface/prefix"
+ "-DTEST_FILE=${RunCMake_BINARY_DIR}/installToSrc/InstallPrefixInInterface.cmake"
+ )
+set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/installToSrc")
+run_cmake(InstallToPrefixInSrcDirOutOfSource)
+unset(RunCMake_TEST_SOURCE_DIR)
+
+
+file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}/installToSrcInSrc")
+set(RunCMake_TEST_NO_CLEAN ON)
+
+configure_file(
+ "${RunCMake_SOURCE_DIR}/CMakeLists.txt"
+ "${RunCMake_BINARY_DIR}/installToSrcInSrc/CMakeLists.txt"
+ COPYONLY
+)
+configure_file(
+ "${RunCMake_SOURCE_DIR}/empty.cpp"
+ "${RunCMake_BINARY_DIR}/installToSrcInSrc/empty.cpp"
+ COPYONLY
+)
+configure_file(
+ "${RunCMake_SOURCE_DIR}/InstallPrefixInInterface.cmake"
+ "${RunCMake_BINARY_DIR}/installToSrcInSrc/InstallPrefixInInterface.cmake"
+ COPYONLY
+)
+
+set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/installToSrcInSrc/InstallPrefixInInterface/prefix"
+ "-DTEST_FILE=${RunCMake_BINARY_DIR}/installToSrcInSrc/InstallPrefixInInterface.cmake"
+ )
+set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/installToSrcInSrc")
+set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/installToSrcInSrc")
+run_cmake(InstallToPrefixInSrcDirInSource)
+unset(RunCMake_TEST_SOURCE_DIR)
+unset(RunCMake_TEST_BINARY_DIR)
+unset(RunCMake_TEST_NO_CLEAN)
diff --git a/Tests/RunCMake/include_directories/SourceDirectoryInInterface-result.txt b/Tests/RunCMake/include_directories/SourceDirectoryInInterface-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/SourceDirectoryInInterface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/SourceDirectoryInInterface-stderr.txt b/Tests/RunCMake/include_directories/SourceDirectoryInInterface-stderr.txt
new file mode 100644
index 0000000000..9346b994f7
--- /dev/null
+++ b/Tests/RunCMake/include_directories/SourceDirectoryInInterface-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error in CMakeLists.txt:
+ Target "testTarget" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*RunCMake/include_directories/foo"
+
+ which is prefixed in the source directory.
diff --git a/Tests/RunCMake/include_directories/SourceDirectoryInInterface.cmake b/Tests/RunCMake/include_directories/SourceDirectoryInInterface.cmake
new file mode 100644
index 0000000000..f814a3ca39
--- /dev/null
+++ b/Tests/RunCMake/include_directories/SourceDirectoryInInterface.cmake
@@ -0,0 +1,11 @@
+
+enable_language(CXX)
+
+add_library(testTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
+target_include_directories(testTarget INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/foo")
+
+install(TARGETS testTarget EXPORT testTargets
+ DESTINATION lib
+)
+
+install(EXPORT testTargets DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-NEW-result.txt b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-NEW-stderr.txt b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-NEW-stderr.txt
new file mode 100644
index 0000000000..afa43e08de
--- /dev/null
+++ b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-NEW-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error in CMakeLists.txt:
+ Target "testTarget" INTERFACE_INCLUDE_DIRECTORIES property contains path:
+
+ ".*Tests/RunCMake/include_directories/prefix/src/foo"
+
+ which is prefixed in the source directory.
diff --git a/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-OLD-result.txt b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-OLD-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-OLD-stderr.txt b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-OLD-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-WARN-result.txt b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-WARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-WARN-stderr.txt b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-WARN-stderr.txt
new file mode 100644
index 0000000000..0b13fd899a
--- /dev/null
+++ b/Tests/RunCMake/include_directories/SrcInInstallPrefix-CMP0052-WARN-stderr.txt
@@ -0,0 +1,20 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+ Policy CMP0052 is not set: Reject source and build dirs in installed
+ INTERFACE_INCLUDE_DIRECTORIES. Run "cmake --help-policy CMP0052" for
+ policy details. Use the cmake_policy command to set the policy and
+ suppress this warning.
+
+ Directory:
+
+ ".*Tests/RunCMake/include_directories/prefix/src/foo"
+
+ in INTERFACE_INCLUDE_DIRECTORIES of target "testTarget" is a subdirectory
+ of the install directory:
+
+ ".*Tests/RunCMake/include_directories/prefix"
+
+ however it is also a subdirectory of the source tree:
+
+ ".*Tests/RunCMake/include_directories/prefix/src"
+
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/include_directories/TID-bad-target-result.txt b/Tests/RunCMake/include_directories/TID-bad-target-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/TID-bad-target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/TID-bad-target-stderr.txt b/Tests/RunCMake/include_directories/TID-bad-target-stderr.txt
new file mode 100644
index 0000000000..4e15de1475
--- /dev/null
+++ b/Tests/RunCMake/include_directories/TID-bad-target-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at TID-bad-target.cmake:6 \(target_include_directories\):
+ target_include_directories called with non-compilable target type
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/include_directories/TID-bad-target.cmake b/Tests/RunCMake/include_directories/TID-bad-target.cmake
new file mode 100644
index 0000000000..32201c1fb4
--- /dev/null
+++ b/Tests/RunCMake/include_directories/TID-bad-target.cmake
@@ -0,0 +1,6 @@
+
+add_custom_target(check ALL
+ COMMAND ${CMAKE_COMMAND} -E echo check
+)
+
+target_include_directories(check PRIVATE somedir)
diff --git a/Tests/RunCMake/include_directories/empty.cpp b/Tests/RunCMake/include_directories/empty.cpp
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/include_directories/empty.cpp
diff --git a/Tests/RunCMake/include_directories/export-NOWARN-result.txt b/Tests/RunCMake/include_directories/export-NOWARN-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/include_directories/export-NOWARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/include_directories/export-NOWARN-stderr.txt b/Tests/RunCMake/include_directories/export-NOWARN-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/include_directories/export-NOWARN-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/include_directories/export-NOWARN.cmake b/Tests/RunCMake/include_directories/export-NOWARN.cmake
new file mode 100644
index 0000000000..50720a0c8c
--- /dev/null
+++ b/Tests/RunCMake/include_directories/export-NOWARN.cmake
@@ -0,0 +1,62 @@
+enable_language(CXX)
+add_library(foo empty.cpp)
+set_property(TARGET foo APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<0:>/include/subdir)
+set_property(TARGET foo APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_PREFIX>/include/subdir)
+
+set_property(TARGET foo APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/subdir>)
+set_property(TARGET foo APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:include/subdir>)
+set_property(TARGET foo APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:include/$<0:>>)
+set_property(TARGET foo APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:$<0:>/include>)
+
+# target_include_directories(foo INTERFACE include/subdir) # Does and should warn. INSTALL_INTERFACE must not list src dir paths.
+target_include_directories(foo INTERFACE $<0:>/include/subdir) # Does not and should not should warn, because it starts with a genex.
+target_include_directories(foo INTERFACE $<INSTALL_PREFIX>/include/subdir)
+
+target_include_directories(foo INTERFACE $<INSTALL_INTERFACE:include/subdir>)
+target_include_directories(foo INTERFACE $<INSTALL_INTERFACE:include/$<0:>>)
+
+install(TARGETS foo EXPORT FooTargets DESTINATION lib)
+install(EXPORT FooTargets DESTINATION lib/cmake)
+
+install(TARGETS foo EXPORT FooTargets2
+ DESTINATION lib
+ INCLUDES DESTINATION include # No warning. Implicit install prefix.
+)
+install(EXPORT FooTargets2 DESTINATION lib/cmake)
+
+install(TARGETS foo EXPORT FooTargets3
+ DESTINATION lib
+ INCLUDES DESTINATION $<INSTALL_PREFIX>include
+)
+install(EXPORT FooTargets3 DESTINATION lib/cmake)
+
+install(TARGETS foo EXPORT FooTargets4
+ DESTINATION lib
+ INCLUDES DESTINATION $<INSTALL_INTERFACE:include>
+)
+install(EXPORT FooTargets4 DESTINATION lib/cmake)
+
+install(TARGETS foo EXPORT FooTargets5
+ DESTINATION lib
+ # The $<0:> is evaluated at export time, leaving 'include' behind, which should be treated as above.
+ INCLUDES DESTINATION $<INSTALL_INTERFACE:$<0:>include>
+)
+install(EXPORT FooTargets5 DESTINATION lib/cmake)
+
+install(TARGETS foo EXPORT FooTargets6
+ DESTINATION lib
+ INCLUDES DESTINATION $<INSTALL_INTERFACE:include$<0:>>
+)
+install(EXPORT FooTargets6 DESTINATION lib/cmake)
+
+install(TARGETS foo EXPORT FooTargets7
+ DESTINATION lib
+ INCLUDES DESTINATION include$<0:>
+)
+install(EXPORT FooTargets7 DESTINATION lib/cmake)
+
+install(TARGETS foo EXPORT FooTargets8
+ DESTINATION lib
+ INCLUDES DESTINATION $<0:>include
+)
+install(EXPORT FooTargets8 DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/include_directories/incomplete-genex.cmake b/Tests/RunCMake/include_directories/incomplete-genex.cmake
new file mode 100644
index 0000000000..976695a648
--- /dev/null
+++ b/Tests/RunCMake/include_directories/incomplete-genex.cmake
@@ -0,0 +1,23 @@
+enable_language(CXX)
+
+cmake_policy(SET CMP0022 NEW)
+cmake_policy(SET CMP0023 NEW)
+
+add_library(somelib empty.cpp)
+
+# This test ensures that some internal mechanisms of cmGeneratorExpression
+# do not segfault (#14410).
+
+# Test that cmGeneratorExpression::Preprocess(StripAllGeneratorExpressions)
+# does not segfault
+target_include_directories(somelib PUBLIC
+ "/include;/include/$<BUILD_INTERFACE:subdir"
+)
+
+# Test that cmGeneratorExpression::Preprocess(BuildInterface) does not segfault
+export(TARGETS somelib FILE somelibTargets.cmake)
+
+install(TARGETS somelib EXPORT someExport DESTINATION prefix)
+# Test that cmGeneratorExpression::Preprocess(InstallInterface)
+# and cmGeneratorExpression::Split do not segfault
+install(EXPORT someExport DESTINATION prefix)
diff --git a/Tests/RunCMake/include_directories/install_config-result.txt b/Tests/RunCMake/include_directories/install_config-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/include_directories/install_config-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include_directories/install_config-stderr.txt b/Tests/RunCMake/include_directories/install_config-stderr.txt
new file mode 100644
index 0000000000..ac7b7b0ecc
--- /dev/null
+++ b/Tests/RunCMake/include_directories/install_config-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error in CMakeLists.txt:
+ Target "foo" 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.
diff --git a/Tests/RunCMake/include_directories/install_config.cmake b/Tests/RunCMake/include_directories/install_config.cmake
new file mode 100644
index 0000000000..46c626c70c
--- /dev/null
+++ b/Tests/RunCMake/include_directories/install_config.cmake
@@ -0,0 +1,6 @@
+
+enable_language(CXX)
+
+add_executable(foo empty.cpp)
+install(TARGETS foo EXPORT fooTargets DESTINATION . INCLUDES DESTINATION include/$<CONFIGURATION>)
+install(EXPORT fooTargets DESTINATION lib/cmake)
diff --git a/Tests/RunCMake/include_external_msproject/CMakeLists.txt b/Tests/RunCMake/include_external_msproject/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/include_external_msproject/CustomGuid-check.cmake b/Tests/RunCMake/include_external_msproject/CustomGuid-check.cmake
new file mode 100644
index 0000000000..68dec4c08d
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/CustomGuid-check.cmake
@@ -0,0 +1 @@
+check_project(CustomGuid external "aaa-bbb-ccc-000" "" "")
diff --git a/Tests/RunCMake/include_external_msproject/CustomGuid.cmake b/Tests/RunCMake/include_external_msproject/CustomGuid.cmake
new file mode 100644
index 0000000000..1dbe7da057
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/CustomGuid.cmake
@@ -0,0 +1,2 @@
+include_external_msproject(external external.project
+ GUID aaa-bbb-ccc-000)
diff --git a/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform-check.cmake b/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform-check.cmake
new file mode 100644
index 0000000000..614712ee67
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform-check.cmake
@@ -0,0 +1 @@
+check_project(CustomGuidTypePlatform external "aaa-bbb-ccc-111" "aaa-bbb-ccc-ddd-eee" "Custom Platform")
diff --git a/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform.cmake b/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform.cmake
new file mode 100644
index 0000000000..ee4db655f2
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform.cmake
@@ -0,0 +1,5 @@
+# Test all optional parameters are set.
+include_external_msproject(external external.project
+ GUID aaa-bbb-ccc-111
+ TYPE aaa-bbb-ccc-ddd-eee
+ PLATFORM "Custom Platform")
diff --git a/Tests/RunCMake/include_external_msproject/CustomTypePlatform-check.cmake b/Tests/RunCMake/include_external_msproject/CustomTypePlatform-check.cmake
new file mode 100644
index 0000000000..054eeb0374
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/CustomTypePlatform-check.cmake
@@ -0,0 +1 @@
+check_project(CustomTypePlatform external "" "aaa-bbb-ccc-ddd-eee" "Custom Platform")
diff --git a/Tests/RunCMake/include_external_msproject/CustomTypePlatform.cmake b/Tests/RunCMake/include_external_msproject/CustomTypePlatform.cmake
new file mode 100644
index 0000000000..8c76adbc84
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/CustomTypePlatform.cmake
@@ -0,0 +1,3 @@
+include_external_msproject(external external.project
+ TYPE aaa-bbb-ccc-ddd-eee
+ PLATFORM "Custom Platform")
diff --git a/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake b/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake
new file mode 100644
index 0000000000..90710f9bf3
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake
@@ -0,0 +1,6 @@
+include(RunCMake)
+include(${CMAKE_CURRENT_LIST_DIR}/check_utils.cmake)
+
+run_cmake(CustomGuid)
+run_cmake(CustomTypePlatform)
+run_cmake(CustomGuidTypePlatform)
diff --git a/Tests/RunCMake/include_external_msproject/check_utils.cmake b/Tests/RunCMake/include_external_msproject/check_utils.cmake
new file mode 100644
index 0000000000..408cadb787
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/check_utils.cmake
@@ -0,0 +1,111 @@
+# Check that file contains line that matches regular expression.
+# Sets IS_FOUND variable to TRUE if found and to FALSE otherwise.
+macro(check_line_exists TARGET_FILE REG_EXP_REF)
+ set(IS_FOUND "FALSE")
+
+ file(STRINGS ${TARGET_FILE} FOUND_LINE LIMIT_COUNT 1 REGEX "${${REG_EXP_REF}}")
+ list(LENGTH FOUND_LINE _VAR_LEN)
+
+ if(_VAR_LEN GREATER 0)
+ set(IS_FOUND "TRUE")
+ endif()
+endmacro()
+
+# Search and parse project section line by project name.
+# If search was successful stores found type and guid into FOUND_TYPE and FOUND_GUID variables respectively.
+# Sets IS_FOUND variable to TRUE if found and to FALSE otherwise.
+macro(parse_project_section TARGET_FILE PROJECT_NAME)
+ set(REG_EXP "^Project\\(\\\"{(.+)}\\\"\\) = \\\"${PROJECT_NAME}\\\", \\\".+\\..+\\\", \\\"{(.+)}\\\"$")
+
+ check_line_exists(${TARGET_FILE} REG_EXP)
+ if(NOT IS_FOUND)
+ return()
+ endif()
+
+ string(REGEX REPLACE "${REG_EXP}" "\\1;\\2" _GUIDS "${FOUND_LINE}")
+
+ list(GET _GUIDS 0 FOUND_TYPE)
+ list(GET _GUIDS 1 FOUND_GUID)
+endmacro()
+
+# Search project section line by project name and type.
+# Returns TRUE if found and FALSE otherwise
+function(check_project_type TARGET_FILE PROJECT_NAME PROJECT_TYPE RESULT)
+ set(${RESULT} "FALSE" PARENT_SCOPE)
+
+ parse_project_section(${TARGET_FILE} ${PROJECT_NAME})
+ if(IS_FOUND AND FOUND_TYPE STREQUAL PROJECT_TYPE)
+ set(${RESULT} "TRUE" PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+# Search project section line by project name and id.
+# Returns TRUE if found and FALSE otherwise
+function(check_project_guid TARGET_FILE PROJECT_NAME PROJECT_GUID RESULT)
+ set(${RESULT} "FALSE" PARENT_SCOPE)
+
+ parse_project_section(${TARGET_FILE} ${PROJECT_NAME})
+ if(IS_FOUND AND FOUND_GUID STREQUAL PROJECT_GUID)
+ set(${RESULT} "TRUE" PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+# Search project's build configuration line by project name and target platform name.
+# Returns TRUE if found and FALSE otherwise
+function(check_custom_platform TARGET_FILE PROJECT_NAME PLATFORM_NAME RESULT)
+ set(${RESULT} "FALSE" PARENT_SCOPE)
+
+ # extract project guid
+ parse_project_section(${TARGET_FILE} ${PROJECT_NAME})
+ if(NOT IS_FOUND)
+ return()
+ endif()
+
+ # probably whould be better to use configuration name
+ # extracted from CMAKE_CONFIGURATION_TYPES than just hardcoded "Debug" instead
+ set(REG_EXP "^(\t)*\\{${FOUND_GUID}\\}\\.Debug[^ ]*\\.ActiveCfg = Debug\\|${PLATFORM_NAME}$")
+ check_line_exists(${TARGET_FILE} REG_EXP)
+
+ set(${RESULT} ${IS_FOUND} PARENT_SCOPE)
+endfunction()
+
+# RunCMake test check helper
+function(check_project test name guid type platform)
+ set(sln "${RunCMake_TEST_BINARY_DIR}/${test}.sln")
+ set(sep "")
+ set(failed "")
+ if(NOT type)
+ set(type 8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942)
+ endif()
+ if(NOT platform)
+ if(RunCMake_GENERATOR_PLATFORM)
+ set(platform "${RunCMake_GENERATOR_PLATFORM}")
+ elseif("${RunCMake_GENERATOR}" MATCHES "Win64")
+ set(platform "x64")
+ else()
+ set(platform "Win32")
+ endif()
+ endif()
+ if(guid)
+ check_project_guid("${sln}" "${name}" "${guid}" passed_guid)
+ if(NOT passed_guid)
+ set(failed "${failed}${sep}${name} solution has no project with expected GUID=${guid}")
+ set(sep "\n")
+ endif()
+ else()
+ set(passed_guid 1)
+ endif()
+ check_project_type("${sln}" "${name}" "${type}" passed_type)
+ if(NOT passed_type)
+ set(failed "${failed}${sep}${name} solution has no project with expected TYPE=${type}")
+ set(sep "\n")
+ endif()
+ check_custom_platform("${sln}" "${name}" "${platform}" passed_platform)
+ if(NOT passed_platform)
+ set(failed "${failed}${sep}${name} solution has no project with expected PLATFORM=${platform}")
+ set(sep "\n")
+ endif()
+ set(RunCMake_TEST_FAILED "${failed}" PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/include_external_msproject/main.cpp b/Tests/RunCMake/include_external_msproject/main.cpp
new file mode 100644
index 0000000000..919810306a
--- /dev/null
+++ b/Tests/RunCMake/include_external_msproject/main.cpp
@@ -0,0 +1,3 @@
+void main()
+{
+}
diff --git a/Tests/RunCMake/install/CMakeLists.txt b/Tests/RunCMake/install/CMakeLists.txt
new file mode 100644
index 0000000000..4b3de84d94
--- /dev/null
+++ b/Tests/RunCMake/install/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/install/DIRECTORY-MESSAGE_NEVER-check.cmake b/Tests/RunCMake/install/DIRECTORY-MESSAGE_NEVER-check.cmake
new file mode 100644
index 0000000000..2c716e1e28
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-MESSAGE_NEVER-check.cmake
@@ -0,0 +1,13 @@
+file(REMOVE_RECURSE ${RunCMake_TEST_BINARY_DIR}/prefix)
+execute_process(COMMAND ${CMAKE_COMMAND} -P ${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake
+ OUTPUT_VARIABLE out ERROR_VARIABLE err)
+if(out MATCHES "-- Installing: [^\n]*prefix/dir")
+ string(REGEX REPLACE "\n" "\n " out " ${out}")
+ set(RunCMake_TEST_FAILED
+ "${RunCMake_TEST_FAILED}Installation output was not quiet:\n${out}")
+endif()
+set(f ${RunCMake_TEST_BINARY_DIR}/prefix/dir/empty.txt)
+if(NOT EXISTS "${f}")
+ set(RunCMake_TEST_FAILED
+ "${RunCMake_TEST_FAILED}File was not installed:\n ${f}\n")
+endif()
diff --git a/Tests/RunCMake/install/DIRECTORY-MESSAGE_NEVER.cmake b/Tests/RunCMake/install/DIRECTORY-MESSAGE_NEVER.cmake
new file mode 100644
index 0000000000..eefb8374f9
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-MESSAGE_NEVER.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_INSTALL_MESSAGE "ALWAYS")
+set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/prefix")
+install(DIRECTORY dir/ DESTINATION dir MESSAGE_NEVER)
diff --git a/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-result.txt b/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-stderr.txt b/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-stderr.txt
new file mode 100644
index 0000000000..166ba6f04e
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at DIRECTORY-PATTERN-MESSAGE_NEVER.cmake:[0-9]+ \(install\):
+ install DIRECTORY does not allow "MESSAGE_NEVER" after PATTERN or REGEX.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER.cmake b/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER.cmake
new file mode 100644
index 0000000000..de844f7d43
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER.cmake
@@ -0,0 +1 @@
+install(DIRECTORY src DESTINATION src PATTERN *.txt MESSAGE_NEVER)
diff --git a/Tests/RunCMake/install/DIRECTORY-message-check.cmake b/Tests/RunCMake/install/DIRECTORY-message-check.cmake
new file mode 100644
index 0000000000..857681fbc1
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-message-check.cmake
@@ -0,0 +1,28 @@
+file(REMOVE_RECURSE ${RunCMake_TEST_BINARY_DIR}/prefix)
+execute_process(COMMAND ${CMAKE_COMMAND} -P ${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake
+ OUTPUT_VARIABLE out ERROR_VARIABLE err)
+set(expect "
+-- Installing: [^\n]*/prefix/dir\r?
+-- Installing: [^\n]*/prefix/dir/empty.txt\r?
+")
+if(NOT out MATCHES "${expect}")
+ string(REGEX REPLACE "\n" "\n " out " ${out}")
+ set(RunCMake_TEST_FAILED
+ "${RunCMake_TEST_FAILED}First install did not say 'Installing' as expected:\n${out}")
+endif()
+set(f ${RunCMake_TEST_BINARY_DIR}/prefix/dir/empty.txt)
+if(NOT EXISTS "${f}")
+ set(RunCMake_TEST_FAILED
+ "${RunCMake_TEST_FAILED}File was not installed:\n ${f}\n")
+endif()
+execute_process(COMMAND ${CMAKE_COMMAND} -P ${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake
+ OUTPUT_VARIABLE out ERROR_VARIABLE err)
+set(expect "
+-- Up-to-date: [^\n]*/prefix/dir\r?
+-- Up-to-date: [^\n]*/prefix/dir/empty.txt\r?
+")
+if(NOT out MATCHES "${expect}")
+ string(REGEX REPLACE "\n" "\n " out " ${out}")
+ set(RunCMake_TEST_FAILED
+ "${RunCMake_TEST_FAILED}Second install did not say 'Up-to-date' as expected:\n${out}")
+endif()
diff --git a/Tests/RunCMake/install/DIRECTORY-message-lazy-check.cmake b/Tests/RunCMake/install/DIRECTORY-message-lazy-check.cmake
new file mode 100644
index 0000000000..c7e6018803
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-message-lazy-check.cmake
@@ -0,0 +1,24 @@
+file(REMOVE_RECURSE ${RunCMake_TEST_BINARY_DIR}/prefix)
+execute_process(COMMAND ${CMAKE_COMMAND} -P ${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake
+ OUTPUT_VARIABLE out ERROR_VARIABLE err)
+set(expect "
+-- Installing: [^\n]*/prefix/dir\r?
+-- Installing: [^\n]*/prefix/dir/empty.txt\r?
+")
+if(NOT out MATCHES "${expect}")
+ string(REGEX REPLACE "\n" "\n " out " ${out}")
+ set(RunCMake_TEST_FAILED
+ "${RunCMake_TEST_FAILED}First install did not say 'Installing' as expected:\n${out}")
+endif()
+set(f ${RunCMake_TEST_BINARY_DIR}/prefix/dir/empty.txt)
+if(NOT EXISTS "${f}")
+ set(RunCMake_TEST_FAILED
+ "${RunCMake_TEST_FAILED}File was not installed:\n ${f}\n")
+endif()
+execute_process(COMMAND ${CMAKE_COMMAND} -P ${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake
+ OUTPUT_VARIABLE out ERROR_VARIABLE err)
+if(out MATCHES "(Installing|Up-to-date)")
+ string(REGEX REPLACE "\n" "\n " out " ${out}")
+ set(RunCMake_TEST_FAILED
+ "${RunCMake_TEST_FAILED}Second install was not silent as expected:\n${out}")
+endif()
diff --git a/Tests/RunCMake/install/DIRECTORY-message-lazy.cmake b/Tests/RunCMake/install/DIRECTORY-message-lazy.cmake
new file mode 100644
index 0000000000..ed4356714a
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-message-lazy.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_INSTALL_MESSAGE "LAZY")
+set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/prefix")
+install(DIRECTORY dir/ DESTINATION dir)
diff --git a/Tests/RunCMake/install/DIRECTORY-message.cmake b/Tests/RunCMake/install/DIRECTORY-message.cmake
new file mode 100644
index 0000000000..913ed157de
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-message.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_INSTALL_MESSAGE "ALWAYS")
+set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/prefix")
+install(DIRECTORY dir/ DESTINATION dir)
diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake
new file mode 100644
index 0000000000..53b91f3966
--- /dev/null
+++ b/Tests/RunCMake/install/RunCMakeTest.cmake
@@ -0,0 +1,8 @@
+include(RunCMake)
+run_cmake(DIRECTORY-MESSAGE_NEVER)
+run_cmake(DIRECTORY-PATTERN-MESSAGE_NEVER)
+run_cmake(DIRECTORY-message)
+run_cmake(DIRECTORY-message-lazy)
+run_cmake(SkipInstallRulesWarning)
+run_cmake(SkipInstallRulesNoWarning1)
+run_cmake(SkipInstallRulesNoWarning2)
diff --git a/Tests/RunCMake/install/SkipInstallRulesNoWarning1-check.cmake b/Tests/RunCMake/install/SkipInstallRulesNoWarning1-check.cmake
new file mode 100644
index 0000000000..28076983d6
--- /dev/null
+++ b/Tests/RunCMake/install/SkipInstallRulesNoWarning1-check.cmake
@@ -0,0 +1,9 @@
+if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/CMakeCache.txt")
+ message(FATAL_ERROR "missing test prerequisite CMakeCache.txt")
+endif()
+
+set(CMAKE_INSTALL_CMAKE "${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake")
+
+if(EXISTS ${CMAKE_INSTALL_CMAKE})
+ message(FATAL_ERROR "${CMAKE_INSTALL_CMAKE} should not exist")
+endif()
diff --git a/Tests/RunCMake/install/SkipInstallRulesNoWarning1-stderr.txt b/Tests/RunCMake/install/SkipInstallRulesNoWarning1-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/install/SkipInstallRulesNoWarning1-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/install/SkipInstallRulesNoWarning1.cmake b/Tests/RunCMake/install/SkipInstallRulesNoWarning1.cmake
new file mode 100644
index 0000000000..22c7f8ca8a
--- /dev/null
+++ b/Tests/RunCMake/install/SkipInstallRulesNoWarning1.cmake
@@ -0,0 +1 @@
+set(CMAKE_SKIP_INSTALL_RULES ON)
diff --git a/Tests/RunCMake/install/SkipInstallRulesNoWarning2-check.cmake b/Tests/RunCMake/install/SkipInstallRulesNoWarning2-check.cmake
new file mode 100644
index 0000000000..4372b77c0e
--- /dev/null
+++ b/Tests/RunCMake/install/SkipInstallRulesNoWarning2-check.cmake
@@ -0,0 +1,9 @@
+if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/CMakeCache.txt")
+ message(FATAL_ERROR "missing test prerequisite CMakeCache.txt")
+endif()
+
+set(CMAKE_INSTALL_CMAKE "${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake")
+
+if(NOT EXISTS ${CMAKE_INSTALL_CMAKE})
+ message(FATAL_ERROR "${CMAKE_INSTALL_CMAKE} should exist")
+endif()
diff --git a/Tests/RunCMake/install/SkipInstallRulesNoWarning2-stderr.txt b/Tests/RunCMake/install/SkipInstallRulesNoWarning2-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/install/SkipInstallRulesNoWarning2-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/install/SkipInstallRulesNoWarning2.cmake b/Tests/RunCMake/install/SkipInstallRulesNoWarning2.cmake
new file mode 100644
index 0000000000..2f5f03af06
--- /dev/null
+++ b/Tests/RunCMake/install/SkipInstallRulesNoWarning2.cmake
@@ -0,0 +1 @@
+install(FILES CMakeLists.txt DESTINATION src)
diff --git a/Tests/RunCMake/install/SkipInstallRulesWarning-check.cmake b/Tests/RunCMake/install/SkipInstallRulesWarning-check.cmake
new file mode 100644
index 0000000000..28076983d6
--- /dev/null
+++ b/Tests/RunCMake/install/SkipInstallRulesWarning-check.cmake
@@ -0,0 +1,9 @@
+if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/CMakeCache.txt")
+ message(FATAL_ERROR "missing test prerequisite CMakeCache.txt")
+endif()
+
+set(CMAKE_INSTALL_CMAKE "${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake")
+
+if(EXISTS ${CMAKE_INSTALL_CMAKE})
+ message(FATAL_ERROR "${CMAKE_INSTALL_CMAKE} should not exist")
+endif()
diff --git a/Tests/RunCMake/install/SkipInstallRulesWarning-stderr.txt b/Tests/RunCMake/install/SkipInstallRulesWarning-stderr.txt
new file mode 100644
index 0000000000..9130526f12
--- /dev/null
+++ b/Tests/RunCMake/install/SkipInstallRulesWarning-stderr.txt
@@ -0,0 +1,3 @@
+CMake Warning in CMakeLists.txt:
+ CMAKE_SKIP_INSTALL_RULES was enabled even though installation rules have
+ been specified
diff --git a/Tests/RunCMake/install/SkipInstallRulesWarning.cmake b/Tests/RunCMake/install/SkipInstallRulesWarning.cmake
new file mode 100644
index 0000000000..b621d9b54f
--- /dev/null
+++ b/Tests/RunCMake/install/SkipInstallRulesWarning.cmake
@@ -0,0 +1,2 @@
+set(CMAKE_SKIP_INSTALL_RULES ON)
+install(FILES CMakeLists.txt DESTINATION src)
diff --git a/Tests/RunCMake/install/dir/empty.txt b/Tests/RunCMake/install/dir/empty.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/RunCMake/install/dir/empty.txt
diff --git a/Tests/RunCMake/interface_library/CMakeLists.txt b/Tests/RunCMake/interface_library/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/interface_library/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/interface_library/RunCMakeTest.cmake b/Tests/RunCMake/interface_library/RunCMakeTest.cmake
new file mode 100644
index 0000000000..08e81c6c87
--- /dev/null
+++ b/Tests/RunCMake/interface_library/RunCMakeTest.cmake
@@ -0,0 +1,11 @@
+include(RunCMake)
+
+run_cmake(invalid_name)
+run_cmake(target_commands)
+run_cmake(no_shared_libs)
+run_cmake(whitelist)
+run_cmake(invalid_signature)
+run_cmake(global-interface)
+run_cmake(genex_link)
+run_cmake(add_dependencies)
+run_cmake(add_custom_command-TARGET)
diff --git a/Tests/RunCMake/interface_library/add_custom_command-TARGET-result.txt b/Tests/RunCMake/interface_library/add_custom_command-TARGET-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/interface_library/add_custom_command-TARGET-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/interface_library/add_custom_command-TARGET-stderr.txt b/Tests/RunCMake/interface_library/add_custom_command-TARGET-stderr.txt
new file mode 100644
index 0000000000..c095262652
--- /dev/null
+++ b/Tests/RunCMake/interface_library/add_custom_command-TARGET-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at add_custom_command-TARGET.cmake:4 \(add_custom_command\):
+ Target "iface" is an INTERFACE library that may not have PRE_BUILD,
+ PRE_LINK, or POST_BUILD commands.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/interface_library/add_custom_command-TARGET.cmake b/Tests/RunCMake/interface_library/add_custom_command-TARGET.cmake
new file mode 100644
index 0000000000..a5136eff83
--- /dev/null
+++ b/Tests/RunCMake/interface_library/add_custom_command-TARGET.cmake
@@ -0,0 +1,6 @@
+
+add_library(iface INTERFACE)
+
+add_custom_command(TARGET iface
+ COMMAND "${CMAKE_COMMAND}" -E echo test
+)
diff --git a/Tests/RunCMake/interface_library/add_dependencies-result.txt b/Tests/RunCMake/interface_library/add_dependencies-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/interface_library/add_dependencies-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/interface_library/add_dependencies-stderr.txt b/Tests/RunCMake/interface_library/add_dependencies-stderr.txt
new file mode 100644
index 0000000000..c550b6869b
--- /dev/null
+++ b/Tests/RunCMake/interface_library/add_dependencies-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at add_dependencies.cmake:4 \(add_dependencies\):
+ add_dependencies Cannot add target-level dependencies to INTERFACE library
+ target "iface".
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/interface_library/add_dependencies.cmake b/Tests/RunCMake/interface_library/add_dependencies.cmake
new file mode 100644
index 0000000000..12cdfb4fff
--- /dev/null
+++ b/Tests/RunCMake/interface_library/add_dependencies.cmake
@@ -0,0 +1,4 @@
+
+add_library(foo empty.cpp)
+add_library(iface INTERFACE)
+add_dependencies(iface foo)
diff --git a/Tests/RunCMake/interface_library/genex_link-result.txt b/Tests/RunCMake/interface_library/genex_link-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/interface_library/genex_link-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/interface_library/genex_link-stderr.txt b/Tests/RunCMake/interface_library/genex_link-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/interface_library/genex_link-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/interface_library/genex_link.cmake b/Tests/RunCMake/interface_library/genex_link.cmake
new file mode 100644
index 0000000000..0dbf029fea
--- /dev/null
+++ b/Tests/RunCMake/interface_library/genex_link.cmake
@@ -0,0 +1,22 @@
+
+cmake_minimum_required(VERSION 2.8.12.20131125 FATAL_ERROR)
+
+project(genex_link)
+
+set(_main_cpp ${CMAKE_CURRENT_BINARY_DIR}/main.cpp)
+file(WRITE ${_main_cpp}
+ "int main(int argc, char** argv) { return 0; }\n"
+)
+
+add_library(foo::bar INTERFACE IMPORTED)
+set_target_properties(foo::bar
+ PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}"
+ # When not using a generator expression here, no error is generated
+ INTERFACE_LINK_LIBRARIES "$<$<NOT:$<CONFIG:DEBUG>>:foo_bar.lib>"
+)
+
+add_executable(main ${_main_cpp})
+target_include_directories(main PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
+
+target_link_libraries(main foo::bar)
diff --git a/Tests/RunCMake/interface_library/global-interface-result.txt b/Tests/RunCMake/interface_library/global-interface-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/interface_library/global-interface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/interface_library/global-interface-stderr.txt b/Tests/RunCMake/interface_library/global-interface-stderr.txt
new file mode 100644
index 0000000000..24edd0f898
--- /dev/null
+++ b/Tests/RunCMake/interface_library/global-interface-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at global-interface.cmake:2 \(add_library\):
+ Cannot find source file:
+
+ GLOBAL
+
+ Tried extensions \.c \.C \.c\+\+ \.cc \.cpp \.cxx \.m \.M \.mm \.h \.hh \.h\+\+ \.hm \.hpp
+ \.hxx \.in \.txx
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/interface_library/global-interface.cmake b/Tests/RunCMake/interface_library/global-interface.cmake
new file mode 100644
index 0000000000..d2bfc64ed9
--- /dev/null
+++ b/Tests/RunCMake/interface_library/global-interface.cmake
@@ -0,0 +1,2 @@
+
+add_library(iface GLOBAL INTERFACE)
diff --git a/Tests/RunCMake/interface_library/invalid_name-result.txt b/Tests/RunCMake/interface_library/invalid_name-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/interface_library/invalid_name-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/interface_library/invalid_name-stderr.txt b/Tests/RunCMake/interface_library/invalid_name-stderr.txt
new file mode 100644
index 0000000000..e14fcdedb0
--- /dev/null
+++ b/Tests/RunCMake/interface_library/invalid_name-stderr.txt
@@ -0,0 +1,15 @@
+CMake Error at invalid_name.cmake:2 \(add_library\):
+ add_library Invalid name for INTERFACE library target: if\$ace
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_name.cmake:4 \(add_library\):
+ add_library Invalid name for INTERFACE library target: iface::target
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_name.cmake:6 \(add_library\):
+ add_library Invalid name for IMPORTED INTERFACE library target:
+ if\$target_imported
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/interface_library/invalid_name.cmake b/Tests/RunCMake/interface_library/invalid_name.cmake
new file mode 100644
index 0000000000..9a965aa8a0
--- /dev/null
+++ b/Tests/RunCMake/interface_library/invalid_name.cmake
@@ -0,0 +1,6 @@
+
+add_library(if$ace INTERFACE)
+
+add_library(iface::target INTERFACE)
+
+add_library(if$target_imported INTERFACE IMPORTED)
diff --git a/Tests/RunCMake/interface_library/invalid_signature-result.txt b/Tests/RunCMake/interface_library/invalid_signature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/interface_library/invalid_signature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/interface_library/invalid_signature-stderr.txt b/Tests/RunCMake/interface_library/invalid_signature-stderr.txt
new file mode 100644
index 0000000000..6374b3392b
--- /dev/null
+++ b/Tests/RunCMake/interface_library/invalid_signature-stderr.txt
@@ -0,0 +1,89 @@
+CMake Error at invalid_signature.cmake:2 \(add_library\):
+ add_library INTERFACE library requires no source arguments.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:3 \(add_library\):
+ add_library INTERFACE library specified with conflicting/multiple types.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:4 \(add_library\):
+ add_library INTERFACE library specified with conflicting/multiple types.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:5 \(add_library\):
+ add_library INTERFACE library specified with conflicting/multiple types.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:6 \(add_library\):
+ add_library INTERFACE library specified with conflicting/multiple types.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:7 \(add_library\):
+ add_library INTERFACE library specified with conflicting/multiple types.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:8 \(add_library\):
+ add_library INTERFACE library specified with conflicting/multiple types.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:9 \(add_library\):
+ add_library INTERFACE library specified with conflicting STATIC type.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:10 \(add_library\):
+ add_library INTERFACE library specified with conflicting SHARED type.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:11 \(add_library\):
+ add_library INTERFACE library specified with conflicting MODULE type.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:12 \(add_library\):
+ add_library INTERFACE library specified with conflicting OBJECT type.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:13 \(add_library\):
+ add_library INTERFACE library specified with conflicting UNKNOWN type.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:14 \(add_library\):
+ add_library INTERFACE library specified with conflicting ALIAS type.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:15 \(add_library\):
+ add_library INTERFACE library specified with conflicting ALIAS type.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:16 \(add_library\):
+ add_library INTERFACE library specified with conflicting/multiple types.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:17 \(add_library\):
+ add_library INTERFACE library may not be used with EXCLUDE_FROM_ALL.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:18 \(add_library\):
+ add_library INTERFACE library may not be used with EXCLUDE_FROM_ALL.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at invalid_signature.cmake:20 \(add_library\):
+ add_library GLOBAL option may only be used with IMPORTED libraries.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/interface_library/invalid_signature.cmake b/Tests/RunCMake/interface_library/invalid_signature.cmake
new file mode 100644
index 0000000000..4e53534b28
--- /dev/null
+++ b/Tests/RunCMake/interface_library/invalid_signature.cmake
@@ -0,0 +1,20 @@
+
+add_library(iface1 INTERFACE empty.cpp)
+add_library(iface3 STATIC INTERFACE)
+add_library(iface4 STATIC INTERFACE empty.cpp)
+add_library(iface5 SHARED INTERFACE)
+add_library(iface6 MODULE INTERFACE)
+add_library(iface7 OBJECT INTERFACE)
+add_library(iface8 UNKNOWN INTERFACE)
+add_library(iface9 INTERFACE STATIC)
+add_library(iface10 INTERFACE SHARED)
+add_library(iface11 INTERFACE MODULE)
+add_library(iface12 INTERFACE OBJECT)
+add_library(iface13 INTERFACE UNKNOWN)
+add_library(iface14 INTERFACE ALIAS)
+add_library(iface15 ALIAS INTERFACE)
+add_library(iface16 INTERFACE INTERFACE)
+add_library(iface17 INTERFACE EXCLUDE_FROM_ALL)
+add_library(iface18 EXCLUDE_FROM_ALL INTERFACE)
+# add_library(iface19 GLOBAL INTERFACE) Tested separately
+add_library(iface20 INTERFACE GLOBAL)
diff --git a/Tests/RunCMake/interface_library/no_shared_libs-stderr.txt b/Tests/RunCMake/interface_library/no_shared_libs-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/interface_library/no_shared_libs-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/interface_library/no_shared_libs.cmake b/Tests/RunCMake/interface_library/no_shared_libs.cmake
new file mode 100644
index 0000000000..ed81878cbe
--- /dev/null
+++ b/Tests/RunCMake/interface_library/no_shared_libs.cmake
@@ -0,0 +1,5 @@
+
+cmake_minimum_required(VERSION 2.8.12.20131009)
+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
+add_library(foo INTERFACE)
+target_compile_definitions(foo INTERFACE FOO_DEFINE)
diff --git a/Tests/RunCMake/interface_library/target_commands-result.txt b/Tests/RunCMake/interface_library/target_commands-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/interface_library/target_commands-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/interface_library/target_commands-stderr.txt b/Tests/RunCMake/interface_library/target_commands-stderr.txt
new file mode 100644
index 0000000000..be11b77545
--- /dev/null
+++ b/Tests/RunCMake/interface_library/target_commands-stderr.txt
@@ -0,0 +1,47 @@
+CMake Error at target_commands.cmake:4 \(target_link_libraries\):
+ INTERFACE library can only be used with the INTERFACE keyword of
+ target_link_libraries
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at target_commands.cmake:5 \(target_link_libraries\):
+ INTERFACE library can only be used with the INTERFACE keyword of
+ target_link_libraries
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at target_commands.cmake:6 \(target_link_libraries\):
+ INTERFACE library can only be used with the INTERFACE keyword of
+ target_link_libraries
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at target_commands.cmake:7 \(target_link_libraries\):
+ INTERFACE library can only be used with the INTERFACE keyword of
+ target_link_libraries
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at target_commands.cmake:9 \(target_include_directories\):
+ target_include_directories may only be set INTERFACE properties on
+ INTERFACE targets
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at target_commands.cmake:10 \(target_include_directories\):
+ target_include_directories may only be set INTERFACE properties on
+ INTERFACE targets
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at target_commands.cmake:12 \(target_compile_definitions\):
+ target_compile_definitions may only be set INTERFACE properties on
+ INTERFACE targets
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error at target_commands.cmake:13 \(target_compile_definitions\):
+ target_compile_definitions may only be set INTERFACE properties on
+ INTERFACE targets
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/interface_library/target_commands.cmake b/Tests/RunCMake/interface_library/target_commands.cmake
new file mode 100644
index 0000000000..3182e8933e
--- /dev/null
+++ b/Tests/RunCMake/interface_library/target_commands.cmake
@@ -0,0 +1,13 @@
+
+add_library(iface INTERFACE)
+
+target_link_libraries(iface PRIVATE foo)
+target_link_libraries(iface PUBLIC foo)
+target_link_libraries(iface foo)
+target_link_libraries(iface LINK_INTERFACE_LIBRARIES foo)
+
+target_include_directories(iface PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
+target_include_directories(iface PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
+
+target_compile_definitions(iface PRIVATE SOME_DEFINE)
+target_compile_definitions(iface PUBLIC SOME_DEFINE)
diff --git a/Tests/RunCMake/interface_library/whitelist-result.txt b/Tests/RunCMake/interface_library/whitelist-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/interface_library/whitelist-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/interface_library/whitelist-stderr.txt b/Tests/RunCMake/interface_library/whitelist-stderr.txt
new file mode 100644
index 0000000000..577c0cc5d5
--- /dev/null
+++ b/Tests/RunCMake/interface_library/whitelist-stderr.txt
@@ -0,0 +1,19 @@
+CMake Error at whitelist.cmake:4 \(set_property\):
+ INTERFACE_LIBRARY targets may only have whitelisted properties. The
+ property "OUTPUT_NAME" is not allowed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Error at whitelist.cmake:5 \(set_property\):
+ INTERFACE_LIBRARY targets may only have whitelisted properties. The
+ property "OUTPUT_NAME" is not allowed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Error at whitelist.cmake:6 \(get_target_property\):
+ INTERFACE_LIBRARY targets may only have whitelisted properties. The
+ property "OUTPUT_NAME" is not allowed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/interface_library/whitelist.cmake b/Tests/RunCMake/interface_library/whitelist.cmake
new file mode 100644
index 0000000000..98ef05c0ff
--- /dev/null
+++ b/Tests/RunCMake/interface_library/whitelist.cmake
@@ -0,0 +1,6 @@
+
+add_library(iface INTERFACE)
+
+set_property(TARGET iface PROPERTY OUTPUT_NAME output)
+set_property(TARGET iface APPEND PROPERTY OUTPUT_NAME append)
+get_target_property(outname iface OUTPUT_NAME)
diff --git a/Tests/RunCMake/list/CMakeLists.txt b/Tests/RunCMake/list/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/list/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/list/EmptyGet0-result.txt b/Tests/RunCMake/list/EmptyGet0-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/list/EmptyGet0-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/list/EmptyGet0-stderr.txt b/Tests/RunCMake/list/EmptyGet0-stderr.txt
new file mode 100644
index 0000000000..0c61b011f9
--- /dev/null
+++ b/Tests/RunCMake/list/EmptyGet0-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at EmptyGet0.cmake:2 \(list\):
+ list GET given empty list
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/list/EmptyGet0.cmake b/Tests/RunCMake/list/EmptyGet0.cmake
new file mode 100644
index 0000000000..494710825f
--- /dev/null
+++ b/Tests/RunCMake/list/EmptyGet0.cmake
@@ -0,0 +1,2 @@
+set(mylist "")
+list(GET mylist 0 result)
diff --git a/Tests/RunCMake/list/EmptyInsert-1-result.txt b/Tests/RunCMake/list/EmptyInsert-1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/list/EmptyInsert-1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/list/EmptyInsert-1-stderr.txt b/Tests/RunCMake/list/EmptyInsert-1-stderr.txt
new file mode 100644
index 0000000000..0900ff9411
--- /dev/null
+++ b/Tests/RunCMake/list/EmptyInsert-1-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at EmptyInsert-1.cmake:2 \(list\):
+ list index: -1 out of range \(0, 0\)
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/list/EmptyInsert-1.cmake b/Tests/RunCMake/list/EmptyInsert-1.cmake
new file mode 100644
index 0000000000..140da5d07a
--- /dev/null
+++ b/Tests/RunCMake/list/EmptyInsert-1.cmake
@@ -0,0 +1,2 @@
+set(mylist "")
+list(INSERT mylist -1 x)
diff --git a/Tests/RunCMake/list/EmptyRemoveAt0-result.txt b/Tests/RunCMake/list/EmptyRemoveAt0-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/list/EmptyRemoveAt0-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt b/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt
new file mode 100644
index 0000000000..b24a0ed0b8
--- /dev/null
+++ b/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at EmptyRemoveAt0.cmake:2 \(list\):
+ list REMOVE_AT given empty list
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/list/EmptyRemoveAt0.cmake b/Tests/RunCMake/list/EmptyRemoveAt0.cmake
new file mode 100644
index 0000000000..d6a3e85c6a
--- /dev/null
+++ b/Tests/RunCMake/list/EmptyRemoveAt0.cmake
@@ -0,0 +1,2 @@
+set(mylist "")
+list(REMOVE_AT mylist 0)
diff --git a/Tests/RunCMake/list/RunCMakeTest.cmake b/Tests/RunCMake/list/RunCMakeTest.cmake
new file mode 100644
index 0000000000..555051de0c
--- /dev/null
+++ b/Tests/RunCMake/list/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(EmptyGet0)
+run_cmake(EmptyRemoveAt0)
+run_cmake(EmptyInsert-1)
diff --git a/Tests/RunCMake/message/CMakeLists.txt b/Tests/RunCMake/message/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/message/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/message/RunCMakeTest.cmake b/Tests/RunCMake/message/RunCMakeTest.cmake
new file mode 100644
index 0000000000..d2bc0c3549
--- /dev/null
+++ b/Tests/RunCMake/message/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(nomessage)
+run_cmake(warnmessage)
+run_cmake(errormessage)
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/message/errormessage-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/message/errormessage-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/message/errormessage-stderr.txt b/Tests/RunCMake/message/errormessage-stderr.txt
new file mode 100644
index 0000000000..49e7ca9130
--- /dev/null
+++ b/Tests/RunCMake/message/errormessage-stderr.txt
@@ -0,0 +1,4 @@
+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
new file mode 100644
index 0000000000..7d3b7792be
--- /dev/null
+++ b/Tests/RunCMake/message/errormessage.cmake
@@ -0,0 +1,4 @@
+
+set(CMAKE_ERROR_DEPRECATED ON)
+
+message(DEPRECATION "This is an error")
diff --git a/Tests/RunCMake/message/nomessage-result.txt b/Tests/RunCMake/message/nomessage-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/message/nomessage-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/message/nomessage-stderr.txt b/Tests/RunCMake/message/nomessage-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/message/nomessage-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/message/nomessage.cmake b/Tests/RunCMake/message/nomessage.cmake
new file mode 100644
index 0000000000..bcc97be656
--- /dev/null
+++ b/Tests/RunCMake/message/nomessage.cmake
@@ -0,0 +1,2 @@
+
+message(DEPRECATION "This is not issued")
diff --git a/Tests/RunCMake/message/warnmessage-result.txt b/Tests/RunCMake/message/warnmessage-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/message/warnmessage-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/message/warnmessage-stderr.txt b/Tests/RunCMake/message/warnmessage-stderr.txt
new file mode 100644
index 0000000000..5c44566372
--- /dev/null
+++ b/Tests/RunCMake/message/warnmessage-stderr.txt
@@ -0,0 +1,4 @@
+CMake Deprecation Warning at warnmessage.cmake:4 \(message\):
+ This is a warning
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/message/warnmessage.cmake b/Tests/RunCMake/message/warnmessage.cmake
new file mode 100644
index 0000000000..4c421a1299
--- /dev/null
+++ b/Tests/RunCMake/message/warnmessage.cmake
@@ -0,0 +1,4 @@
+
+set(CMAKE_WARN_DEPRECATED ON)
+
+message(DEPRECATION "This is a warning")
diff --git a/Tests/RunCMake/no_install_prefix/CMakeLists.txt b/Tests/RunCMake/no_install_prefix/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/no_install_prefix/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/no_install_prefix/RunCMakeTest.cmake b/Tests/RunCMake/no_install_prefix/RunCMakeTest.cmake
new file mode 100644
index 0000000000..292344999b
--- /dev/null
+++ b/Tests/RunCMake/no_install_prefix/RunCMakeTest.cmake
@@ -0,0 +1,15 @@
+include(RunCMake)
+
+set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/prefix")
+
+file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/prefix")
+file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/prefix/NoPrefix")
+file(WRITE "${RunCMake_BINARY_DIR}/prefix/NoPrefix/NoPrefixConfig.cmake" "")
+set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_BINARY_DIR}/prefix")
+run_cmake(with_install_prefix)
+
+file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/prefix")
+file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/prefix/NoPrefix")
+file(WRITE "${RunCMake_BINARY_DIR}/prefix/NoPrefix/NoPrefixConfig.cmake" "")
+list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_FIND_NO_INSTALL_PREFIX=1")
+run_cmake(no_install_prefix)
diff --git a/Tests/RunCMake/no_install_prefix/do_test.cmake b/Tests/RunCMake/no_install_prefix/do_test.cmake
new file mode 100644
index 0000000000..340c7dcc9e
--- /dev/null
+++ b/Tests/RunCMake/no_install_prefix/do_test.cmake
@@ -0,0 +1,2 @@
+
+find_package(NoPrefix REQUIRED)
diff --git a/Tests/RunCMake/no_install_prefix/no_install_prefix-result.txt b/Tests/RunCMake/no_install_prefix/no_install_prefix-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/no_install_prefix/no_install_prefix-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/no_install_prefix/no_install_prefix-stderr.txt b/Tests/RunCMake/no_install_prefix/no_install_prefix-stderr.txt
new file mode 100644
index 0000000000..66c624123c
--- /dev/null
+++ b/Tests/RunCMake/no_install_prefix/no_install_prefix-stderr.txt
@@ -0,0 +1,18 @@
+CMake Error at do_test.cmake:2 \(find_package\):
+ By not providing "FindNoPrefix.cmake" in CMAKE_MODULE_PATH this project has
+ asked CMake to find a package configuration file provided by "NoPrefix",
+ but CMake did not find one.
+
+ Could not find a package configuration file provided by "NoPrefix" with any
+ of the following names:
+
+ NoPrefixConfig.cmake
+ noprefix-config.cmake
+
+ Add the installation prefix of "NoPrefix" to CMAKE_PREFIX_PATH or set
+ "NoPrefix_DIR" to a directory containing one of the above files. If
+ "NoPrefix" provides a separate development package or SDK, be sure it has
+ been installed.
+Call Stack \(most recent call first\):
+ no_install_prefix.cmake:2 \(include\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/no_install_prefix/no_install_prefix.cmake b/Tests/RunCMake/no_install_prefix/no_install_prefix.cmake
new file mode 100644
index 0000000000..c7d28daa8c
--- /dev/null
+++ b/Tests/RunCMake/no_install_prefix/no_install_prefix.cmake
@@ -0,0 +1,2 @@
+
+include(do_test.cmake)
diff --git a/Tests/RunCMake/no_install_prefix/with_install_prefix-result.txt b/Tests/RunCMake/no_install_prefix/with_install_prefix-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/no_install_prefix/with_install_prefix-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/no_install_prefix/with_install_prefix-stderr.txt b/Tests/RunCMake/no_install_prefix/with_install_prefix-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/no_install_prefix/with_install_prefix-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/no_install_prefix/with_install_prefix.cmake b/Tests/RunCMake/no_install_prefix/with_install_prefix.cmake
new file mode 100644
index 0000000000..c7d28daa8c
--- /dev/null
+++ b/Tests/RunCMake/no_install_prefix/with_install_prefix.cmake
@@ -0,0 +1,2 @@
+
+include(do_test.cmake)
diff --git a/Tests/RunCMake/project/CMP0048-NEW-stderr.txt b/Tests/RunCMake/project/CMP0048-NEW-stderr.txt
new file mode 100644
index 0000000000..10f32932ee
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-NEW-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/project/CMP0048-NEW-stdout.txt b/Tests/RunCMake/project/CMP0048-NEW-stdout.txt
new file mode 100644
index 0000000000..38261e50ce
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-NEW-stdout.txt
@@ -0,0 +1,30 @@
+-- PROJECT_VERSION='1.2.3.4'
+-- ProjectA_VERSION='1.2.3.4'
+-- PROJECT_VERSION_MAJOR='1'
+-- ProjectA_VERSION_MAJOR='1'
+-- PROJECT_VERSION_MINOR='2'
+-- ProjectA_VERSION_MINOR='2'
+-- PROJECT_VERSION_PATCH='3'
+-- ProjectA_VERSION_PATCH='3'
+-- PROJECT_VERSION_TWEAK='4'
+-- ProjectA_VERSION_TWEAK='4'
+-- PROJECT_VERSION='0.1.2'
+-- ProjectB_VERSION='0.1.2'
+-- PROJECT_VERSION_MAJOR='0'
+-- ProjectB_VERSION_MAJOR='0'
+-- PROJECT_VERSION_MINOR='1'
+-- ProjectB_VERSION_MINOR='1'
+-- PROJECT_VERSION_PATCH='2'
+-- ProjectB_VERSION_PATCH='2'
+-- PROJECT_VERSION_TWEAK=''
+-- ProjectB_VERSION_TWEAK=''
+-- PROJECT_VERSION=''
+-- ProjectC_VERSION=''
+-- PROJECT_VERSION_MAJOR=''
+-- ProjectC_VERSION_MAJOR=''
+-- PROJECT_VERSION_MINOR=''
+-- ProjectC_VERSION_MINOR=''
+-- PROJECT_VERSION_PATCH=''
+-- ProjectC_VERSION_PATCH=''
+-- PROJECT_VERSION_TWEAK=''
+-- ProjectC_VERSION_TWEAK=''
diff --git a/Tests/RunCMake/project/CMP0048-NEW.cmake b/Tests/RunCMake/project/CMP0048-NEW.cmake
new file mode 100644
index 0000000000..7e16b70818
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-NEW.cmake
@@ -0,0 +1,19 @@
+macro(print_versions name)
+ foreach(v "" _MAJOR _MINOR _PATCH _TWEAK)
+ message(STATUS "PROJECT_VERSION${v}='${PROJECT_VERSION${v}}'")
+ message(STATUS "${name}_VERSION${v}='${${name}_VERSION${v}}'")
+ endforeach()
+endmacro()
+
+cmake_policy(SET CMP0048 NEW)
+
+project(ProjectA VERSION 1.2.3.4 LANGUAGES NONE)
+print_versions(ProjectA)
+
+project(ProjectB VERSION 0.1.2 LANGUAGES NONE)
+print_versions(ProjectB)
+
+set(PROJECT_VERSION 1)
+set(ProjectC_VERSION 1)
+project(ProjectC NONE)
+print_versions(ProjectC)
diff --git a/Tests/RunCMake/project/CMP0048-OLD-VERSION-result.txt b/Tests/RunCMake/project/CMP0048-OLD-VERSION-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-OLD-VERSION-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/project/CMP0048-OLD-VERSION-stderr.txt b/Tests/RunCMake/project/CMP0048-OLD-VERSION-stderr.txt
new file mode 100644
index 0000000000..3a13d32620
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-OLD-VERSION-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0048-OLD-VERSION.cmake:1 \(project\):
+ VERSION not allowed unless CMP0048 is set to NEW
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/project/CMP0048-OLD-VERSION.cmake b/Tests/RunCMake/project/CMP0048-OLD-VERSION.cmake
new file mode 100644
index 0000000000..6fbbe0a276
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-OLD-VERSION.cmake
@@ -0,0 +1,2 @@
+project(MyProject VERSION 1 LANGUAGES NONE)
+message("This line not reached.")
diff --git a/Tests/RunCMake/project/CMP0048-OLD-stdout.txt b/Tests/RunCMake/project/CMP0048-OLD-stdout.txt
new file mode 100644
index 0000000000..1a25c7bca4
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-OLD-stdout.txt
@@ -0,0 +1,2 @@
+-- PROJECT_VERSION='1'
+-- MyProject_VERSION_TWEAK='0'
diff --git a/Tests/RunCMake/project/CMP0048-OLD.cmake b/Tests/RunCMake/project/CMP0048-OLD.cmake
new file mode 100644
index 0000000000..6c32d2cc4f
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-OLD.cmake
@@ -0,0 +1,6 @@
+cmake_policy(SET CMP0048 OLD)
+set(PROJECT_VERSION 1)
+set(MyProject_VERSION_TWEAK 0)
+project(MyProject NONE)
+message(STATUS "PROJECT_VERSION='${PROJECT_VERSION}'")
+message(STATUS "MyProject_VERSION_TWEAK='${MyProject_VERSION_TWEAK}'")
diff --git a/Tests/RunCMake/project/CMP0048-WARN-stderr.txt b/Tests/RunCMake/project/CMP0048-WARN-stderr.txt
new file mode 100644
index 0000000000..6d29ad260c
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0048-WARN.cmake:3 \(project\):
+ Policy CMP0048 is not set: project\(\) command manages VERSION variables.
+ Run "cmake --help-policy CMP0048" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ The following variable\(s\) would be set to empty:
+
+ PROJECT_VERSION
+ MyProject_VERSION_TWEAK
+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/project/CMP0048-WARN.cmake b/Tests/RunCMake/project/CMP0048-WARN.cmake
new file mode 100644
index 0000000000..97359e64fd
--- /dev/null
+++ b/Tests/RunCMake/project/CMP0048-WARN.cmake
@@ -0,0 +1,3 @@
+set(PROJECT_VERSION 1)
+set(MyProject_VERSION_TWEAK 0)
+project(MyProject NONE)
diff --git a/Tests/RunCMake/project/CMakeLists.txt b/Tests/RunCMake/project/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/project/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/project/LanguagesEmpty-stdout.txt b/Tests/RunCMake/project/LanguagesEmpty-stdout.txt
new file mode 100644
index 0000000000..fb9c7e87dc
--- /dev/null
+++ b/Tests/RunCMake/project/LanguagesEmpty-stdout.txt
@@ -0,0 +1 @@
+ENABLED_LANGUAGES='NONE'
diff --git a/Tests/RunCMake/project/LanguagesEmpty.cmake b/Tests/RunCMake/project/LanguagesEmpty.cmake
new file mode 100644
index 0000000000..4de2ccabd3
--- /dev/null
+++ b/Tests/RunCMake/project/LanguagesEmpty.cmake
@@ -0,0 +1,3 @@
+project(ProjectA LANGUAGES)
+get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
+message(STATUS "ENABLED_LANGUAGES='${langs}'")
diff --git a/Tests/RunCMake/project/LanguagesImplicit-stdout.txt b/Tests/RunCMake/project/LanguagesImplicit-stdout.txt
new file mode 100644
index 0000000000..fb9c7e87dc
--- /dev/null
+++ b/Tests/RunCMake/project/LanguagesImplicit-stdout.txt
@@ -0,0 +1 @@
+ENABLED_LANGUAGES='NONE'
diff --git a/Tests/RunCMake/project/LanguagesImplicit.cmake b/Tests/RunCMake/project/LanguagesImplicit.cmake
new file mode 100644
index 0000000000..e40845488d
--- /dev/null
+++ b/Tests/RunCMake/project/LanguagesImplicit.cmake
@@ -0,0 +1,3 @@
+project(ProjectA NONE)
+get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
+message(STATUS "ENABLED_LANGUAGES='${langs}'")
diff --git a/Tests/RunCMake/project/LanguagesNONE-stdout.txt b/Tests/RunCMake/project/LanguagesNONE-stdout.txt
new file mode 100644
index 0000000000..fb9c7e87dc
--- /dev/null
+++ b/Tests/RunCMake/project/LanguagesNONE-stdout.txt
@@ -0,0 +1 @@
+ENABLED_LANGUAGES='NONE'
diff --git a/Tests/RunCMake/project/LanguagesNONE.cmake b/Tests/RunCMake/project/LanguagesNONE.cmake
new file mode 100644
index 0000000000..2c0125f227
--- /dev/null
+++ b/Tests/RunCMake/project/LanguagesNONE.cmake
@@ -0,0 +1,3 @@
+project(ProjectA LANGUAGES NONE)
+get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
+message(STATUS "ENABLED_LANGUAGES='${langs}'")
diff --git a/Tests/RunCMake/project/LanguagesTwice-result.txt b/Tests/RunCMake/project/LanguagesTwice-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/project/LanguagesTwice-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/project/LanguagesTwice-stderr.txt b/Tests/RunCMake/project/LanguagesTwice-stderr.txt
new file mode 100644
index 0000000000..9c69dd003e
--- /dev/null
+++ b/Tests/RunCMake/project/LanguagesTwice-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at LanguagesTwice.cmake:1 \(project\):
+ LANGUAGES may be specified at most once.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/project/LanguagesTwice.cmake b/Tests/RunCMake/project/LanguagesTwice.cmake
new file mode 100644
index 0000000000..6c4a3dc959
--- /dev/null
+++ b/Tests/RunCMake/project/LanguagesTwice.cmake
@@ -0,0 +1,2 @@
+project(ProjectA LANGUAGES NONE LANGUAGES)
+message("This line not reached.")
diff --git a/Tests/RunCMake/project/RunCMakeTest.cmake b/Tests/RunCMake/project/RunCMakeTest.cmake
new file mode 100644
index 0000000000..6ab0fc9571
--- /dev/null
+++ b/Tests/RunCMake/project/RunCMakeTest.cmake
@@ -0,0 +1,17 @@
+include(RunCMake)
+
+run_cmake(LanguagesImplicit)
+run_cmake(LanguagesEmpty)
+run_cmake(LanguagesNONE)
+run_cmake(LanguagesTwice)
+run_cmake(VersionAndLanguagesEmpty)
+run_cmake(VersionEmpty)
+run_cmake(VersionInvalid)
+run_cmake(VersionMissingLanguages)
+run_cmake(VersionMissingValueOkay)
+run_cmake(VersionTwice)
+
+run_cmake(CMP0048-OLD)
+run_cmake(CMP0048-OLD-VERSION)
+run_cmake(CMP0048-WARN)
+run_cmake(CMP0048-NEW)
diff --git a/Tests/RunCMake/project/VersionAndLanguagesEmpty-stdout.txt b/Tests/RunCMake/project/VersionAndLanguagesEmpty-stdout.txt
new file mode 100644
index 0000000000..eae7da73bf
--- /dev/null
+++ b/Tests/RunCMake/project/VersionAndLanguagesEmpty-stdout.txt
@@ -0,0 +1,2 @@
+-- ENABLED_LANGUAGES='NONE'
+-- PROJECT_VERSION='1'
diff --git a/Tests/RunCMake/project/VersionAndLanguagesEmpty.cmake b/Tests/RunCMake/project/VersionAndLanguagesEmpty.cmake
new file mode 100644
index 0000000000..d6056ce1b7
--- /dev/null
+++ b/Tests/RunCMake/project/VersionAndLanguagesEmpty.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0048 NEW)
+project(ProjectA VERSION 1 LANGUAGES NONE)
+get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
+message(STATUS "ENABLED_LANGUAGES='${langs}'")
+message(STATUS "PROJECT_VERSION='${PROJECT_VERSION}'")
diff --git a/Tests/RunCMake/project/VersionEmpty-stdout.txt b/Tests/RunCMake/project/VersionEmpty-stdout.txt
new file mode 100644
index 0000000000..3ae42e02de
--- /dev/null
+++ b/Tests/RunCMake/project/VersionEmpty-stdout.txt
@@ -0,0 +1,2 @@
+-- ENABLED_LANGUAGES='NONE'
+-- PROJECT_VERSION=''
diff --git a/Tests/RunCMake/project/VersionEmpty.cmake b/Tests/RunCMake/project/VersionEmpty.cmake
new file mode 100644
index 0000000000..0cfb29140f
--- /dev/null
+++ b/Tests/RunCMake/project/VersionEmpty.cmake
@@ -0,0 +1,6 @@
+cmake_policy(SET CMP0048 NEW)
+set(PROJECT_VERSION 1)
+project(ProjectA VERSION "" LANGUAGES NONE)
+get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
+message(STATUS "ENABLED_LANGUAGES='${langs}'")
+message(STATUS "PROJECT_VERSION='${PROJECT_VERSION}'")
diff --git a/Tests/RunCMake/project/VersionInvalid-result.txt b/Tests/RunCMake/project/VersionInvalid-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/project/VersionInvalid-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/project/VersionInvalid-stderr.txt b/Tests/RunCMake/project/VersionInvalid-stderr.txt
new file mode 100644
index 0000000000..48358d1d71
--- /dev/null
+++ b/Tests/RunCMake/project/VersionInvalid-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at VersionInvalid.cmake:2 \(project\):
+ VERSION "NONE" format invalid.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/project/VersionInvalid.cmake b/Tests/RunCMake/project/VersionInvalid.cmake
new file mode 100644
index 0000000000..8d5dd7f255
--- /dev/null
+++ b/Tests/RunCMake/project/VersionInvalid.cmake
@@ -0,0 +1,3 @@
+cmake_policy(SET CMP0048 NEW)
+project(ProjectA VERSION NONE)
+message("This line not reached.")
diff --git a/Tests/RunCMake/project/VersionMissingLanguages-result.txt b/Tests/RunCMake/project/VersionMissingLanguages-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/project/VersionMissingLanguages-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/project/VersionMissingLanguages-stderr.txt b/Tests/RunCMake/project/VersionMissingLanguages-stderr.txt
new file mode 100644
index 0000000000..52433bcc08
--- /dev/null
+++ b/Tests/RunCMake/project/VersionMissingLanguages-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at VersionMissingLanguages.cmake:2 \(project\):
+ project with VERSION must use LANGUAGES before language names.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/project/VersionMissingLanguages.cmake b/Tests/RunCMake/project/VersionMissingLanguages.cmake
new file mode 100644
index 0000000000..dc415141c8
--- /dev/null
+++ b/Tests/RunCMake/project/VersionMissingLanguages.cmake
@@ -0,0 +1,3 @@
+cmake_policy(SET CMP0048 NEW)
+project(ProjectA VERSION 1 NONE)
+message("This line not reached.")
diff --git a/Tests/RunCMake/project/VersionMissingValueOkay-stdout.txt b/Tests/RunCMake/project/VersionMissingValueOkay-stdout.txt
new file mode 100644
index 0000000000..3ae42e02de
--- /dev/null
+++ b/Tests/RunCMake/project/VersionMissingValueOkay-stdout.txt
@@ -0,0 +1,2 @@
+-- ENABLED_LANGUAGES='NONE'
+-- PROJECT_VERSION=''
diff --git a/Tests/RunCMake/project/VersionMissingValueOkay.cmake b/Tests/RunCMake/project/VersionMissingValueOkay.cmake
new file mode 100644
index 0000000000..1fb1437501
--- /dev/null
+++ b/Tests/RunCMake/project/VersionMissingValueOkay.cmake
@@ -0,0 +1,6 @@
+cmake_policy(SET CMP0048 NEW)
+set(PROJECT_VERSION 1)
+project(ProjectA VERSION LANGUAGES NONE)
+get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
+message(STATUS "ENABLED_LANGUAGES='${langs}'")
+message(STATUS "PROJECT_VERSION='${PROJECT_VERSION}'")
diff --git a/Tests/RunCMake/project/VersionTwice-result.txt b/Tests/RunCMake/project/VersionTwice-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/project/VersionTwice-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/project/VersionTwice-stderr.txt b/Tests/RunCMake/project/VersionTwice-stderr.txt
new file mode 100644
index 0000000000..ec07ead0f5
--- /dev/null
+++ b/Tests/RunCMake/project/VersionTwice-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at VersionTwice.cmake:2 \(project\):
+ VERSION may be specified at most once.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/project/VersionTwice.cmake b/Tests/RunCMake/project/VersionTwice.cmake
new file mode 100644
index 0000000000..dc0c996cfa
--- /dev/null
+++ b/Tests/RunCMake/project/VersionTwice.cmake
@@ -0,0 +1,3 @@
+cmake_policy(SET CMP0048 NEW)
+project(ProjectA VERSION 1 VERSION)
+message("This line not reached.")
diff --git a/Tests/RunCMake/set/CMakeLists.txt b/Tests/RunCMake/set/CMakeLists.txt
new file mode 100644
index 0000000000..4b3de84d94
--- /dev/null
+++ b/Tests/RunCMake/set/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/set/ParentScope-result.txt b/Tests/RunCMake/set/ParentScope-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/set/ParentScope-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/set/ParentScope.cmake b/Tests/RunCMake/set/ParentScope.cmake
new file mode 100644
index 0000000000..9bd6bcace2
--- /dev/null
+++ b/Tests/RunCMake/set/ParentScope.cmake
@@ -0,0 +1,33 @@
+set(FOO )
+set(BAR "bar")
+set(BAZ "baz")
+set(BOO "boo")
+
+function(_parent_scope)
+ set(FOO "foo" PARENT_SCOPE)
+ set(BAR "" PARENT_SCOPE)
+ set(BAZ PARENT_SCOPE)
+ unset(BOO PARENT_SCOPE)
+endfunction()
+
+_parent_scope()
+
+if(NOT DEFINED FOO)
+ message(FATAL_ERROR "FOO not defined")
+elseif(NOT "${FOO}" STREQUAL "foo")
+ message(FATAL_ERROR "FOO should be \"foo\", not \"${FOO}\"")
+endif()
+
+if(NOT DEFINED BAR)
+ message(FATAL_ERROR "BAR not defined")
+elseif(NOT "${BAR}" STREQUAL "")
+ message(FATAL_ERROR "BAR should be an empty string, not \"${BAR}\"")
+endif()
+
+if(DEFINED BAZ)
+ message(FATAL_ERROR "BAZ defined")
+endif()
+
+if(DEFINED BOO)
+ message(FATAL_ERROR "BOO defined")
+endif()
diff --git a/Tests/RunCMake/set/RunCMakeTest.cmake b/Tests/RunCMake/set/RunCMakeTest.cmake
new file mode 100644
index 0000000000..1b51ea27cd
--- /dev/null
+++ b/Tests/RunCMake/set/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake(ParentScope)
diff --git a/Tests/RunCMake/string/CMakeLists.txt b/Tests/RunCMake/string/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/string/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/string/Concat.cmake b/Tests/RunCMake/string/Concat.cmake
new file mode 100644
index 0000000000..7260c95dd2
--- /dev/null
+++ b/Tests/RunCMake/string/Concat.cmake
@@ -0,0 +1,19 @@
+set(b b)
+set(out x)
+string(CONCAT out)
+if(NOT out STREQUAL "")
+ message(FATAL_ERROR "\"string(CONCAT out)\" set out to \"${out}\"")
+endif()
+string(CONCAT out a)
+if(NOT out STREQUAL "a")
+ message(FATAL_ERROR "\"string(CONCAT out a)\" set out to \"${out}\"")
+endif()
+string(CONCAT out a "b")
+if(NOT out STREQUAL "ab")
+ message(FATAL_ERROR "\"string(CONCAT out a \"b\")\" set out to \"${out}\"")
+endif()
+string(CONCAT out a "${b}" [[
+${c}]])
+if(NOT out STREQUAL "ab\${c}")
+ message(FATAL_ERROR "\"string(CONCAT out a \"\${b}\" [[\${c}]])\" set out to \"${out}\"")
+endif()
diff --git a/Tests/RunCMake/string/ConcatNoArgs-result.txt b/Tests/RunCMake/string/ConcatNoArgs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/string/ConcatNoArgs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/string/ConcatNoArgs-stderr.txt b/Tests/RunCMake/string/ConcatNoArgs-stderr.txt
new file mode 100644
index 0000000000..efea5f1d86
--- /dev/null
+++ b/Tests/RunCMake/string/ConcatNoArgs-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at ConcatNoArgs.cmake:1 \(string\):
+ string sub-command CONCAT requires at least one argument.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/string/ConcatNoArgs.cmake b/Tests/RunCMake/string/ConcatNoArgs.cmake
new file mode 100644
index 0000000000..ba21136621
--- /dev/null
+++ b/Tests/RunCMake/string/ConcatNoArgs.cmake
@@ -0,0 +1 @@
+string(CONCAT)
diff --git a/Tests/RunCMake/string/RunCMakeTest.cmake b/Tests/RunCMake/string/RunCMakeTest.cmake
new file mode 100644
index 0000000000..e83db274d6
--- /dev/null
+++ b/Tests/RunCMake/string/RunCMakeTest.cmake
@@ -0,0 +1,12 @@
+include(RunCMake)
+
+run_cmake(Concat)
+run_cmake(ConcatNoArgs)
+
+run_cmake(Uuid)
+run_cmake(UuidMissingNamespace)
+run_cmake(UuidMissingNamespaceValue)
+run_cmake(UuidBadNamespace)
+run_cmake(UuidMissingNameValue)
+run_cmake(UuidMissingTypeValue)
+run_cmake(UuidBadType)
diff --git a/Tests/RunCMake/string/Uuid.cmake b/Tests/RunCMake/string/Uuid.cmake
new file mode 100644
index 0000000000..2613d2682c
--- /dev/null
+++ b/Tests/RunCMake/string/Uuid.cmake
@@ -0,0 +1,17 @@
+set(UUID_DNS_NAMESPACE 6ba7b810-9dad-11d1-80b4-00c04fd430c8)
+
+string(UUID WWW_EXAMPLE_COM_MD5_UUID
+ NAMESPACE ${UUID_DNS_NAMESPACE} NAME www.example.com TYPE MD5)
+
+if(NOT WWW_EXAMPLE_COM_MD5_UUID STREQUAL "5df41881-3aed-3515-88a7-2f4a814cf09e")
+ message(SEND_ERROR
+ "UUID did not create the expected MD5 result: ${WWW_EXAMPLE_COM_MD5_UUID}")
+endif()
+
+string(UUID WWW_EXAMPLE_COM_SHA1_UUID
+ NAMESPACE ${UUID_DNS_NAMESPACE} NAME www.example.com TYPE SHA1 UPPER)
+
+if(NOT WWW_EXAMPLE_COM_SHA1_UUID STREQUAL "2ED6657D-E927-568B-95E1-2665A8AEA6A2")
+ message(SEND_ERROR
+ "UUID did not create the expected SHA1 result: ${WWW_EXAMPLE_COM_SHA1_UUID}")
+endif()
diff --git a/Tests/RunCMake/string/UuidBadNamespace-result.txt b/Tests/RunCMake/string/UuidBadNamespace-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/string/UuidBadNamespace-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/string/UuidBadNamespace-stderr.txt b/Tests/RunCMake/string/UuidBadNamespace-stderr.txt
new file mode 100644
index 0000000000..cb12903e13
--- /dev/null
+++ b/Tests/RunCMake/string/UuidBadNamespace-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at UuidBadNamespace.cmake:3 \(string\):
+ string UUID sub-command, malformed NAMESPACE UUID.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/string/UuidBadNamespace.cmake b/Tests/RunCMake/string/UuidBadNamespace.cmake
new file mode 100644
index 0000000000..f6079252b9
--- /dev/null
+++ b/Tests/RunCMake/string/UuidBadNamespace.cmake
@@ -0,0 +1,4 @@
+set(UUID_DNS_NAMESPACE 6ba7b810-9dad-fooo-80b4-00c04fd430c8)
+
+string(UUID WWW_EXAMPLE_COM_MD5_UUID
+ NAMESPACE ${UUID_DNS_NAMESPACE} NAME www.example.com TYPE MD5)
diff --git a/Tests/RunCMake/string/UuidBadType-result.txt b/Tests/RunCMake/string/UuidBadType-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/string/UuidBadType-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/string/UuidBadType-stderr.txt b/Tests/RunCMake/string/UuidBadType-stderr.txt
new file mode 100644
index 0000000000..1993c044a3
--- /dev/null
+++ b/Tests/RunCMake/string/UuidBadType-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at UuidBadType.cmake:3 \(string\):
+ string UUID sub-command, unknown TYPE 'FOO'.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/string/UuidBadType.cmake b/Tests/RunCMake/string/UuidBadType.cmake
new file mode 100644
index 0000000000..bf4909e9ce
--- /dev/null
+++ b/Tests/RunCMake/string/UuidBadType.cmake
@@ -0,0 +1,4 @@
+set(UUID_DNS_NAMESPACE 6ba7b810-9dad-11d1-80b4-00c04fd430c8)
+
+string(UUID WWW_EXAMPLE_COM_MD5_UUID
+ NAMESPACE ${UUID_DNS_NAMESPACE} NAME www.example.com TYPE FOO)
diff --git a/Tests/RunCMake/string/UuidMissingNameValue-result.txt b/Tests/RunCMake/string/UuidMissingNameValue-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingNameValue-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/string/UuidMissingNameValue-stderr.txt b/Tests/RunCMake/string/UuidMissingNameValue-stderr.txt
new file mode 100644
index 0000000000..0b7cde4633
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingNameValue-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at UuidMissingNameValue.cmake:3 \(string\):
+ string UUID sub-command, NAME requires a value.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/string/UuidMissingNameValue.cmake b/Tests/RunCMake/string/UuidMissingNameValue.cmake
new file mode 100644
index 0000000000..407a1d7f8f
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingNameValue.cmake
@@ -0,0 +1,4 @@
+set(UUID_DNS_NAMESPACE 6ba7b810-9dad-11d1-80b4-00c04fd430c8)
+
+string(UUID WWW_EXAMPLE_COM_MD5_UUID
+ NAMESPACE ${UUID_DNS_NAMESPACE} TYPE MD5 NAME)
diff --git a/Tests/RunCMake/string/UuidMissingNamespace-result.txt b/Tests/RunCMake/string/UuidMissingNamespace-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingNamespace-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/string/UuidMissingNamespace-stderr.txt b/Tests/RunCMake/string/UuidMissingNamespace-stderr.txt
new file mode 100644
index 0000000000..dfcfe42b2b
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingNamespace-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at UuidMissingNamespace.cmake:3 \(string\):
+ string UUID sub-command, malformed NAMESPACE UUID.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/string/UuidMissingNamespace.cmake b/Tests/RunCMake/string/UuidMissingNamespace.cmake
new file mode 100644
index 0000000000..5a71e4f70a
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingNamespace.cmake
@@ -0,0 +1,4 @@
+set(UUID_DNS_NAMESPACE 6ba7b810-9dad-11d1-80b4-00c04fd430c8)
+
+string(UUID WWW_EXAMPLE_COM_MD5_UUID
+ NAME www.example.com TYPE MD5)
diff --git a/Tests/RunCMake/string/UuidMissingNamespaceValue-result.txt b/Tests/RunCMake/string/UuidMissingNamespaceValue-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingNamespaceValue-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/string/UuidMissingNamespaceValue-stderr.txt b/Tests/RunCMake/string/UuidMissingNamespaceValue-stderr.txt
new file mode 100644
index 0000000000..86585ad404
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingNamespaceValue-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at UuidMissingNamespaceValue.cmake:3 \(string\):
+ string UUID sub-command, NAMESPACE requires a value.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/string/UuidMissingNamespaceValue.cmake b/Tests/RunCMake/string/UuidMissingNamespaceValue.cmake
new file mode 100644
index 0000000000..f2219c0ffb
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingNamespaceValue.cmake
@@ -0,0 +1,4 @@
+set(UUID_DNS_NAMESPACE 6ba7b810-9dad-11d1-80b4-00c04fd430c8)
+
+string(UUID WWW_EXAMPLE_COM_MD5_UUID
+ NAME www.example.com TYPE MD5 NAMESPACE)
diff --git a/Tests/RunCMake/string/UuidMissingTypeValue-result.txt b/Tests/RunCMake/string/UuidMissingTypeValue-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingTypeValue-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/string/UuidMissingTypeValue-stderr.txt b/Tests/RunCMake/string/UuidMissingTypeValue-stderr.txt
new file mode 100644
index 0000000000..70252f8cd8
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingTypeValue-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at UuidMissingTypeValue.cmake:3 \(string\):
+ string UUID sub-command, TYPE requires a value.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/string/UuidMissingTypeValue.cmake b/Tests/RunCMake/string/UuidMissingTypeValue.cmake
new file mode 100644
index 0000000000..6678a4658f
--- /dev/null
+++ b/Tests/RunCMake/string/UuidMissingTypeValue.cmake
@@ -0,0 +1,4 @@
+set(UUID_DNS_NAMESPACE 6ba7b810-9dad-11d1-80b4-00c04fd430c8)
+
+string(UUID WWW_EXAMPLE_COM_MD5_UUID
+ NAMESPACE ${UUID_DNS_NAMESPACE} NAME www.example.com TYPE)
diff --git a/Tests/RunCMake/target_compile_features/CMakeLists.txt b/Tests/RunCMake/target_compile_features/CMakeLists.txt
new file mode 100644
index 0000000000..3482e6baf2
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
new file mode 100644
index 0000000000..33faf2bbb8
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
@@ -0,0 +1,13 @@
+include(RunCMake)
+
+run_cmake(not_enough_args)
+run_cmake(alias_target)
+run_cmake(utility_target)
+run_cmake(invalid_args)
+run_cmake(invalid_args_on_interface)
+run_cmake(imported_target)
+run_cmake(no_target)
+run_cmake(not_a_cxx_feature)
+run_cmake(no_matching_cxx_feature)
+run_cmake(not_a_c_feature)
+run_cmake(no_matching_c_feature)
diff --git a/Tests/RunCMake/target_compile_features/alias_target-result.txt b/Tests/RunCMake/target_compile_features/alias_target-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/alias_target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/alias_target-stderr.txt b/Tests/RunCMake/target_compile_features/alias_target-stderr.txt
new file mode 100644
index 0000000000..417bf62aae
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/alias_target-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at alias_target.cmake:4 \(target_compile_features\):
+ target_compile_features can not be used on an ALIAS target.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/alias_target.cmake b/Tests/RunCMake/target_compile_features/alias_target.cmake
new file mode 100644
index 0000000000..d35ddba541
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/alias_target.cmake
@@ -0,0 +1,4 @@
+
+add_executable(main empty.cpp)
+add_executable(Alias::Main ALIAS main)
+target_compile_features(Alias::Main PRIVATE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/empty.c b/Tests/RunCMake/target_compile_features/empty.c
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/empty.c
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/target_compile_features/empty.cpp b/Tests/RunCMake/target_compile_features/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/target_compile_features/imported_target-result.txt b/Tests/RunCMake/target_compile_features/imported_target-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/imported_target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/imported_target-stderr.txt b/Tests/RunCMake/target_compile_features/imported_target-stderr.txt
new file mode 100644
index 0000000000..c6ff5ec216
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/imported_target-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at imported_target.cmake:3 \(target_compile_features\):
+ Cannot specify compile features for imported target "main".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/imported_target.cmake b/Tests/RunCMake/target_compile_features/imported_target.cmake
new file mode 100644
index 0000000000..e248c2feea
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/imported_target.cmake
@@ -0,0 +1,3 @@
+
+add_library(main INTERFACE IMPORTED)
+target_compile_features(main INTERFACE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/invalid_args-result.txt b/Tests/RunCMake/target_compile_features/invalid_args-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt b/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt
new file mode 100644
index 0000000000..bd5b7b9d54
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at invalid_args.cmake:3 \(target_compile_features\):
+ target_compile_features called with invalid arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/invalid_args.cmake b/Tests/RunCMake/target_compile_features/invalid_args.cmake
new file mode 100644
index 0000000000..1a7fb3749a
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args.cmake
@@ -0,0 +1,3 @@
+
+add_executable(main empty.cpp)
+target_compile_features(main INVALID cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt
new file mode 100644
index 0000000000..c30209a28b
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at invalid_args_on_interface.cmake:3 \(target_compile_features\):
+ target_compile_features may only be set INTERFACE properties on INTERFACE
+ targets
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake b/Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake
new file mode 100644
index 0000000000..324d0f3846
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake
@@ -0,0 +1,3 @@
+
+add_library(main INTERFACE)
+target_compile_features(main PRIVATE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/no_matching_c_feature-result.txt b/Tests/RunCMake/target_compile_features/no_matching_c_feature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_matching_c_feature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/no_matching_c_feature-stderr.txt b/Tests/RunCMake/target_compile_features/no_matching_c_feature-stderr.txt
new file mode 100644
index 0000000000..96b959cf52
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_matching_c_feature-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at no_matching_c_feature.cmake:[0-9][0-9]? \((target_compile_features|message)\):
+ The compiler feature "gnu_c_dummy" is not known to C compiler
+
+ "GNU"
+
+ version 4.8.1.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/no_matching_c_feature.cmake b/Tests/RunCMake/target_compile_features/no_matching_c_feature.cmake
new file mode 100644
index 0000000000..a44caf29a3
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_matching_c_feature.cmake
@@ -0,0 +1,15 @@
+
+if (NOT ";${CMAKE_C_COMPILE_FEATURES};" MATCHES ";gnu_c_typeof;")
+ # Simulate passing the test.
+ message(SEND_ERROR
+ "The compiler feature \"gnu_c_dummy\" is not known to C compiler\n\"GNU\"\nversion 4.8.1."
+ )
+ return()
+endif()
+
+add_executable(main empty.c)
+
+target_compile_features(main
+ PRIVATE
+ gnu_c_typeof
+)
diff --git a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt
new file mode 100644
index 0000000000..f976dfeab7
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at no_matching_cxx_feature.cmake:[0-9][0-9]? \((target_compile_features|message)\):
+ The compiler feature "[^"]+" is not known to CXX compiler
+
+ "[^"]*"
+
+ version *[.0-9]+\.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake
new file mode 100644
index 0000000000..ab1fd76088
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake
@@ -0,0 +1,26 @@
+
+if (NOT ";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";gnu_cxx_typeof;"
+ AND NOT ";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";msvc_cxx_sealed;" )
+ # Simulate passing the test.
+ message(SEND_ERROR
+ "The compiler feature \"gnu_cxx_dummy\" is not known to CXX compiler\n\"GNU\"\nversion 4.8.1."
+ )
+ return()
+endif()
+
+if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";gnu_cxx_typeof;")
+ set(feature msvc_cxx_sealed)
+ if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";msvc_cxx_sealed;")
+ # If a compiler supports both extensions, remove one of them.
+ list(REMOVE_ITEM CMAKE_CXX_COMPILE_FEATURES msvc_cxx_sealed)
+ endif()
+else()
+ set(feature gnu_cxx_typeof)
+endif()
+
+add_executable(main empty.cpp)
+
+target_compile_features(main
+ PRIVATE
+ ${feature}
+)
diff --git a/Tests/RunCMake/target_compile_features/no_target-result.txt b/Tests/RunCMake/target_compile_features/no_target-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/no_target-stderr.txt b/Tests/RunCMake/target_compile_features/no_target-stderr.txt
new file mode 100644
index 0000000000..323ba7a901
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_target-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at no_target.cmake:2 \(target_compile_features\):
+ Cannot specify compile features for target "main" which is not built by
+ this project.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/no_target.cmake b/Tests/RunCMake/target_compile_features/no_target.cmake
new file mode 100644
index 0000000000..3f0afe273f
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/no_target.cmake
@@ -0,0 +1,2 @@
+
+target_compile_features(main INTERFACE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/not_a_c_feature-result.txt b/Tests/RunCMake/target_compile_features/not_a_c_feature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_a_c_feature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/not_a_c_feature-stderr.txt b/Tests/RunCMake/target_compile_features/not_a_c_feature-stderr.txt
new file mode 100644
index 0000000000..6dd00f359a
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_a_c_feature-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at not_a_c_feature.cmake:3 \(target_compile_features\):
+ target_compile_features specified unknown feature "c_not_a_feature" for
+ target "main".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/not_a_c_feature.cmake b/Tests/RunCMake/target_compile_features/not_a_c_feature.cmake
new file mode 100644
index 0000000000..0420698bc9
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_a_c_feature.cmake
@@ -0,0 +1,6 @@
+
+add_executable(main empty.c)
+target_compile_features(main
+ PRIVATE
+ c_not_a_feature
+)
diff --git a/Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt
new file mode 100644
index 0000000000..efa2bad5f8
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at not_a_cxx_feature.cmake:3 \(target_compile_features\):
+ target_compile_features specified unknown feature "cxx_not_a_feature" for
+ target "main".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake b/Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake
new file mode 100644
index 0000000000..0207b724de
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake
@@ -0,0 +1,6 @@
+
+add_executable(main empty.cpp)
+target_compile_features(main
+ PRIVATE
+ cxx_not_a_feature
+)
diff --git a/Tests/RunCMake/target_compile_features/not_enough_args-result.txt b/Tests/RunCMake/target_compile_features/not_enough_args-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_enough_args-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt b/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt
new file mode 100644
index 0000000000..2f8d812431
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at not_enough_args.cmake:3 \(target_compile_features\):
+ target_compile_features called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/not_enough_args.cmake b/Tests/RunCMake/target_compile_features/not_enough_args.cmake
new file mode 100644
index 0000000000..95612300ad
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/not_enough_args.cmake
@@ -0,0 +1,3 @@
+
+add_executable(main empty.cpp)
+target_compile_features(main)
diff --git a/Tests/RunCMake/target_compile_features/utility_target-result.txt b/Tests/RunCMake/target_compile_features/utility_target-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/utility_target-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/utility_target-stderr.txt b/Tests/RunCMake/target_compile_features/utility_target-stderr.txt
new file mode 100644
index 0000000000..d23905995e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/utility_target-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at utility_target.cmake:4 \(target_compile_features\):
+ target_compile_features called with non-compilable target type
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_compile_features/utility_target.cmake b/Tests/RunCMake/target_compile_features/utility_target.cmake
new file mode 100644
index 0000000000..8919056518
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/utility_target.cmake
@@ -0,0 +1,4 @@
+
+add_custom_target(utility)
+
+target_compile_features(utility PRIVATE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-result.txt b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt
new file mode 100644
index 0000000000..8e3f3153bc
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt
@@ -0,0 +1,11 @@
+CMake Error at CMP0023-NEW-2.cmake:11 \(target_link_libraries\):
+ The plain signature for target_link_libraries has already been used with
+ the target "foo". All uses of target_link_libraries with a target must be
+ either all-keyword or all-plain.
+
+ The uses of the plain signature are here:
+
+ \* CMP0023-NEW-2.cmake:10 \(target_link_libraries\)
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2.cmake b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2.cmake
new file mode 100644
index 0000000000..f8b354690c
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2.cmake
@@ -0,0 +1,11 @@
+
+project(CMP0022-WARN)
+
+cmake_policy(SET CMP0023 NEW)
+
+add_library(foo SHARED empty_vs6_1.cpp)
+add_library(bar SHARED empty_vs6_2.cpp)
+add_library(bat SHARED empty_vs6_3.cpp)
+
+target_link_libraries(foo bar)
+target_link_libraries(foo LINK_PRIVATE bat)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-result.txt b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt
new file mode 100644
index 0000000000..2ef2290344
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt
@@ -0,0 +1,11 @@
+CMake Error at CMP0023-NEW.cmake:11 \(target_link_libraries\):
+ The plain signature for target_link_libraries has already been used with
+ the target "foo". All uses of target_link_libraries with a target must be
+ either all-keyword or all-plain.
+
+ The uses of the plain signature are here:
+
+ \* CMP0023-NEW.cmake:10 \(target_link_libraries\)
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW.cmake b/Tests/RunCMake/target_link_libraries/CMP0023-NEW.cmake
new file mode 100644
index 0000000000..f0aa63fbd4
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW.cmake
@@ -0,0 +1,11 @@
+
+project(CMP0022-WARN)
+
+cmake_policy(SET CMP0023 NEW)
+
+add_library(foo SHARED empty_vs6_1.cpp)
+add_library(bar SHARED empty_vs6_2.cpp)
+add_library(bat SHARED empty_vs6_3.cpp)
+
+target_link_libraries(foo bar)
+target_link_libraries(foo PRIVATE bat)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2-stderr.txt
new file mode 100644
index 0000000000..5147861540
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2-stderr.txt
@@ -0,0 +1,16 @@
+CMake Warning \(dev\) at CMP0023-WARN-2.cmake:9 \(target_link_libraries\):
+ Policy CMP0023 is not set: Plain and keyword target_link_libraries
+ signatures cannot be mixed. Run "cmake --help-policy CMP0023" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The plain signature for target_link_libraries has already been used with
+ the target "foo". All uses of target_link_libraries with a target should
+ be either all-keyword or all-plain.
+
+ The uses of the plain signature are here:
+
+ \* CMP0023-WARN-2.cmake:8 \(target_link_libraries\)
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2.cmake b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2.cmake
new file mode 100644
index 0000000000..2e9cba82c3
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2.cmake
@@ -0,0 +1,9 @@
+
+project(CMP0022-WARN)
+
+add_library(foo SHARED empty_vs6_1.cpp)
+add_library(bar SHARED empty_vs6_2.cpp)
+add_library(bat SHARED empty_vs6_3.cpp)
+
+target_link_libraries(foo bar)
+target_link_libraries(foo LINK_PRIVATE bat)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-WARN-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-stderr.txt
new file mode 100644
index 0000000000..a7474fac9d
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-stderr.txt
@@ -0,0 +1,16 @@
+CMake Warning \(dev\) at CMP0023-WARN.cmake:9 \(target_link_libraries\):
+ Policy CMP0023 is not set: Plain and keyword target_link_libraries
+ signatures cannot be mixed. Run "cmake --help-policy CMP0023" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The plain signature for target_link_libraries has already been used with
+ the target "foo". All uses of target_link_libraries with a target should
+ be either all-keyword or all-plain.
+
+ The uses of the plain signature are here:
+
+ \* CMP0023-WARN.cmake:8 \(target_link_libraries\)
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-WARN.cmake b/Tests/RunCMake/target_link_libraries/CMP0023-WARN.cmake
new file mode 100644
index 0000000000..fcc8da03e9
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-WARN.cmake
@@ -0,0 +1,9 @@
+
+project(CMP0022-WARN)
+
+add_library(foo SHARED empty_vs6_1.cpp)
+add_library(bar SHARED empty_vs6_2.cpp)
+add_library(bat SHARED empty_vs6_3.cpp)
+
+target_link_libraries(foo bar)
+target_link_libraries(foo PRIVATE bat)
diff --git a/Tests/RunCMake/target_link_libraries/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/target_link_libraries/MixedSignature-result.txt b/Tests/RunCMake/target_link_libraries/MixedSignature-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/MixedSignature-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_link_libraries/MixedSignature-stderr.txt b/Tests/RunCMake/target_link_libraries/MixedSignature-stderr.txt
new file mode 100644
index 0000000000..a0c66dbe2a
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/MixedSignature-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at MixedSignature.cmake:6 \(target_link_libraries\):
+ The PUBLIC or PRIVATE option must appear as the second argument, just after
+ the target name.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/MixedSignature.cmake b/Tests/RunCMake/target_link_libraries/MixedSignature.cmake
new file mode 100644
index 0000000000..fa70685848
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/MixedSignature.cmake
@@ -0,0 +1,6 @@
+
+add_library(foo empty_vs6_1.cpp)
+add_library(bar empty_vs6_2.cpp)
+add_library(bat empty_vs6_3.cpp)
+
+target_link_libraries(foo LINK_PUBLIC bar PRIVATE bat)
diff --git a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
new file mode 100644
index 0000000000..f97022e1b4
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
@@ -0,0 +1,8 @@
+include(RunCMake)
+
+run_cmake(CMP0023-WARN)
+run_cmake(CMP0023-NEW)
+run_cmake(CMP0023-WARN-2)
+run_cmake(CMP0023-NEW-2)
+run_cmake(MixedSignature)
+run_cmake(Separate-PRIVATE-LINK_PRIVATE-uses)
diff --git a/Tests/RunCMake/target_link_libraries/Separate-PRIVATE-LINK_PRIVATE-uses-result.txt b/Tests/RunCMake/target_link_libraries/Separate-PRIVATE-LINK_PRIVATE-uses-result.txt
new file mode 100644
index 0000000000..573541ac97
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/Separate-PRIVATE-LINK_PRIVATE-uses-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/target_link_libraries/Separate-PRIVATE-LINK_PRIVATE-uses.cmake b/Tests/RunCMake/target_link_libraries/Separate-PRIVATE-LINK_PRIVATE-uses.cmake
new file mode 100644
index 0000000000..e32891d6dd
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/Separate-PRIVATE-LINK_PRIVATE-uses.cmake
@@ -0,0 +1,9 @@
+
+enable_language(CXX)
+
+add_library(foo empty_vs6_1.cpp)
+add_library(bar empty_vs6_2.cpp)
+add_library(bat empty_vs6_3.cpp)
+
+target_link_libraries(foo LINK_PRIVATE bar)
+target_link_libraries(foo PRIVATE bat)
diff --git a/Tests/RunCMake/target_link_libraries/empty.cpp b/Tests/RunCMake/target_link_libraries/empty.cpp
new file mode 100644
index 0000000000..bfbbddeb90
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/target_link_libraries/empty_vs6_1.cpp b/Tests/RunCMake/target_link_libraries/empty_vs6_1.cpp
new file mode 100644
index 0000000000..7efedabfa3
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/empty_vs6_1.cpp
@@ -0,0 +1 @@
+#include "empty.cpp"
diff --git a/Tests/RunCMake/target_link_libraries/empty_vs6_2.cpp b/Tests/RunCMake/target_link_libraries/empty_vs6_2.cpp
new file mode 100644
index 0000000000..7efedabfa3
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/empty_vs6_2.cpp
@@ -0,0 +1 @@
+#include "empty.cpp"
diff --git a/Tests/RunCMake/target_link_libraries/empty_vs6_3.cpp b/Tests/RunCMake/target_link_libraries/empty_vs6_3.cpp
new file mode 100644
index 0000000000..7efedabfa3
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/empty_vs6_3.cpp
@@ -0,0 +1 @@
+#include "empty.cpp"
diff --git a/Tests/RunCMake/try_compile/BadLinkLibraries-result.txt b/Tests/RunCMake/try_compile/BadLinkLibraries-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/BadLinkLibraries-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt b/Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt
new file mode 100644
index 0000000000..eceffecc86
--- /dev/null
+++ b/Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at BadLinkLibraries.cmake:2 \(try_compile\):
+ Only libraries may be used as try_compile IMPORTED LINK_LIBRARIES. Got
+ not_a_library of type UTILITY.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/BadLinkLibraries.cmake b/Tests/RunCMake/try_compile/BadLinkLibraries.cmake
new file mode 100644
index 0000000000..e8b5add873
--- /dev/null
+++ b/Tests/RunCMake/try_compile/BadLinkLibraries.cmake
@@ -0,0 +1,3 @@
+add_custom_target(not_a_library)
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ LINK_LIBRARIES not_a_library)
diff --git a/Tests/RunCMake/try_compile/BadSources1-result.txt b/Tests/RunCMake/try_compile/BadSources1-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/BadSources1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/BadSources1-stderr.txt b/Tests/RunCMake/try_compile/BadSources1-stderr.txt
new file mode 100644
index 0000000000..864a2942ce
--- /dev/null
+++ b/Tests/RunCMake/try_compile/BadSources1-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at BadSources1.cmake:1 \(try_compile\):
+ Unknown extension ".c" for file
+
+ .*/Tests/RunCMake/try_compile/src.c
+
+ try_compile\(\) works only for enabled languages. Currently these are:
+
+ NONE
+
+ See project\(\) command to enable other languages.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/BadSources1.cmake b/Tests/RunCMake/try_compile/BadSources1.cmake
new file mode 100644
index 0000000000..aa4dc5ee5e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/BadSources1.cmake
@@ -0,0 +1 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c)
diff --git a/Tests/RunCMake/try_compile/BadSources2-result.txt b/Tests/RunCMake/try_compile/BadSources2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/BadSources2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/BadSources2-stderr.txt b/Tests/RunCMake/try_compile/BadSources2-stderr.txt
new file mode 100644
index 0000000000..3313f99331
--- /dev/null
+++ b/Tests/RunCMake/try_compile/BadSources2-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at BadSources2.cmake:2 \(try_compile\):
+ Unknown extension ".cxx" for file
+
+ .*/Tests/RunCMake/try_compile/src.cxx
+
+ try_compile\(\) works only for enabled languages. Currently these are:
+
+ C NONE( RC)?
+
+ See project\(\) command to enable other languages.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/BadSources2.cmake b/Tests/RunCMake/try_compile/BadSources2.cmake
new file mode 100644
index 0000000000..ed2b0364d2
--- /dev/null
+++ b/Tests/RunCMake/try_compile/BadSources2.cmake
@@ -0,0 +1,5 @@
+enable_language(C)
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
+ SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src.cxx
+ )
diff --git a/Tests/RunCMake/try_compile/CMakeLists.txt b/Tests/RunCMake/try_compile/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/try_compile/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-result.txt b/Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-stderr.txt b/Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-stderr.txt
new file mode 100644
index 0000000000..5d09c0c610
--- /dev/null
+++ b/Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CopyFileErrorNoCopyFile.cmake:1 \(try_compile\):
+ COPY_FILE_ERROR may be used only with COPY_FILE
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile.cmake b/Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile.cmake
new file mode 100644
index 0000000000..8d7cb0e7f0
--- /dev/null
+++ b/Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile.cmake
@@ -0,0 +1,2 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ COPY_FILE_ERROR _copied)
diff --git a/Tests/RunCMake/try_compile/NoArgs-result.txt b/Tests/RunCMake/try_compile/NoArgs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoArgs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/NoArgs-stderr.txt b/Tests/RunCMake/try_compile/NoArgs-stderr.txt
new file mode 100644
index 0000000000..8808fd19a9
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoArgs-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoArgs.cmake:1 \(try_compile\):
+ try_compile unknown error.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/NoArgs.cmake b/Tests/RunCMake/try_compile/NoArgs.cmake
new file mode 100644
index 0000000000..8f751d9a22
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoArgs.cmake
@@ -0,0 +1 @@
+try_compile()
diff --git a/Tests/RunCMake/try_compile/NoCopyFile-result.txt b/Tests/RunCMake/try_compile/NoCopyFile-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoCopyFile-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/NoCopyFile-stderr.txt b/Tests/RunCMake/try_compile/NoCopyFile-stderr.txt
new file mode 100644
index 0000000000..d65d94883f
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoCopyFile-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoCopyFile.cmake:1 \(try_compile\):
+ COPY_FILE must be followed by a file path
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/NoCopyFile.cmake b/Tests/RunCMake/try_compile/NoCopyFile.cmake
new file mode 100644
index 0000000000..8c648ff328
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoCopyFile.cmake
@@ -0,0 +1,2 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ COPY_FILE)
diff --git a/Tests/RunCMake/try_compile/NoCopyFile2-result.txt b/Tests/RunCMake/try_compile/NoCopyFile2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoCopyFile2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/NoCopyFile2-stderr.txt b/Tests/RunCMake/try_compile/NoCopyFile2-stderr.txt
new file mode 100644
index 0000000000..e88952475a
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoCopyFile2-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoCopyFile2.cmake:1 \(try_compile\):
+ COPY_FILE must be followed by a file path
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/NoCopyFile2.cmake b/Tests/RunCMake/try_compile/NoCopyFile2.cmake
new file mode 100644
index 0000000000..04b7f68829
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoCopyFile2.cmake
@@ -0,0 +1,2 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ COPY_FILE CMAKE_FLAGS -DA=B)
diff --git a/Tests/RunCMake/try_compile/NoCopyFileError-result.txt b/Tests/RunCMake/try_compile/NoCopyFileError-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoCopyFileError-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/NoCopyFileError-stderr.txt b/Tests/RunCMake/try_compile/NoCopyFileError-stderr.txt
new file mode 100644
index 0000000000..ed552fd8e4
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoCopyFileError-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoCopyFileError.cmake:1 \(try_compile\):
+ COPY_FILE_ERROR must be followed by a variable name
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/NoCopyFileError.cmake b/Tests/RunCMake/try_compile/NoCopyFileError.cmake
new file mode 100644
index 0000000000..d4d69ee018
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoCopyFileError.cmake
@@ -0,0 +1,2 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/copied.bin COPY_FILE_ERROR)
diff --git a/Tests/RunCMake/try_compile/NoOutputVariable-result.txt b/Tests/RunCMake/try_compile/NoOutputVariable-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoOutputVariable-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/NoOutputVariable-stderr.txt b/Tests/RunCMake/try_compile/NoOutputVariable-stderr.txt
new file mode 100644
index 0000000000..18ad751cf3
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoOutputVariable-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoOutputVariable.cmake:1 \(try_compile\):
+ OUTPUT_VARIABLE must be followed by a variable name
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/NoOutputVariable.cmake b/Tests/RunCMake/try_compile/NoOutputVariable.cmake
new file mode 100644
index 0000000000..3b9cb345b2
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoOutputVariable.cmake
@@ -0,0 +1,2 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ OUTPUT_VARIABLE)
diff --git a/Tests/RunCMake/try_compile/NoOutputVariable2-result.txt b/Tests/RunCMake/try_compile/NoOutputVariable2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoOutputVariable2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/NoOutputVariable2-stderr.txt b/Tests/RunCMake/try_compile/NoOutputVariable2-stderr.txt
new file mode 100644
index 0000000000..8b2cc254c7
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoOutputVariable2-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoOutputVariable2.cmake:1 \(try_compile\):
+ OUTPUT_VARIABLE must be followed by a variable name
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/NoOutputVariable2.cmake b/Tests/RunCMake/try_compile/NoOutputVariable2.cmake
new file mode 100644
index 0000000000..ad9ac9ac5f
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoOutputVariable2.cmake
@@ -0,0 +1,2 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ OUTPUT_VARIABLE CMAKE_FLAGS -DA=B)
diff --git a/Tests/RunCMake/try_compile/NoSources-result.txt b/Tests/RunCMake/try_compile/NoSources-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoSources-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/NoSources-stderr.txt b/Tests/RunCMake/try_compile/NoSources-stderr.txt
new file mode 100644
index 0000000000..023032b604
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoSources-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NoSources.cmake:1 \(try_compile\):
+ SOURCES must be followed by at least one source file
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/NoSources.cmake b/Tests/RunCMake/try_compile/NoSources.cmake
new file mode 100644
index 0000000000..8a73af42c5
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NoSources.cmake
@@ -0,0 +1 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} SOURCES)
diff --git a/Tests/RunCMake/try_compile/NonSourceCompileDefinitions-result.txt b/Tests/RunCMake/try_compile/NonSourceCompileDefinitions-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NonSourceCompileDefinitions-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/NonSourceCompileDefinitions-stderr.txt b/Tests/RunCMake/try_compile/NonSourceCompileDefinitions-stderr.txt
new file mode 100644
index 0000000000..025e65868a
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NonSourceCompileDefinitions-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NonSourceCompileDefinitions.cmake:1 \(try_compile\):
+ COMPILE_DEFINITIONS specified on a srcdir type TRY_COMPILE
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/NonSourceCompileDefinitions.cmake b/Tests/RunCMake/try_compile/NonSourceCompileDefinitions.cmake
new file mode 100644
index 0000000000..8eb0d47a0a
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NonSourceCompileDefinitions.cmake
@@ -0,0 +1,2 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/proj
+ TestProject COMPILE_DEFINITIONS DEF)
diff --git a/Tests/RunCMake/try_compile/NonSourceCopyFile-result.txt b/Tests/RunCMake/try_compile/NonSourceCopyFile-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NonSourceCopyFile-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/NonSourceCopyFile-stderr.txt b/Tests/RunCMake/try_compile/NonSourceCopyFile-stderr.txt
new file mode 100644
index 0000000000..f5893e19f7
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NonSourceCopyFile-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NonSourceCopyFile.cmake:1 \(try_compile\):
+ COPY_FILE specified on a srcdir type TRY_COMPILE
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/NonSourceCopyFile.cmake b/Tests/RunCMake/try_compile/NonSourceCopyFile.cmake
new file mode 100644
index 0000000000..c44192f9e3
--- /dev/null
+++ b/Tests/RunCMake/try_compile/NonSourceCopyFile.cmake
@@ -0,0 +1,2 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/proj
+ TestProject COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/result)
diff --git a/Tests/RunCMake/try_compile/OneArg-result.txt b/Tests/RunCMake/try_compile/OneArg-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/OneArg-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/OneArg-stderr.txt b/Tests/RunCMake/try_compile/OneArg-stderr.txt
new file mode 100644
index 0000000000..12835bed65
--- /dev/null
+++ b/Tests/RunCMake/try_compile/OneArg-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at OneArg.cmake:1 \(try_compile\):
+ try_compile unknown error.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/OneArg.cmake b/Tests/RunCMake/try_compile/OneArg.cmake
new file mode 100644
index 0000000000..e60a46207a
--- /dev/null
+++ b/Tests/RunCMake/try_compile/OneArg.cmake
@@ -0,0 +1 @@
+try_compile(RESULT)
diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
new file mode 100644
index 0000000000..c93445876e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
@@ -0,0 +1,17 @@
+include(RunCMake)
+
+run_cmake(CopyFileErrorNoCopyFile)
+run_cmake(NoArgs)
+run_cmake(OneArg)
+run_cmake(TwoArgs)
+run_cmake(NoCopyFile)
+run_cmake(NoCopyFile2)
+run_cmake(NoCopyFileError)
+run_cmake(NoOutputVariable)
+run_cmake(NoOutputVariable2)
+run_cmake(NoSources)
+run_cmake(BadLinkLibraries)
+run_cmake(BadSources1)
+run_cmake(BadSources2)
+run_cmake(NonSourceCopyFile)
+run_cmake(NonSourceCompileDefinitions)
diff --git a/Tests/RunCMake/try_compile/TwoArgs-result.txt b/Tests/RunCMake/try_compile/TwoArgs-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/TwoArgs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_compile/TwoArgs-stderr.txt b/Tests/RunCMake/try_compile/TwoArgs-stderr.txt
new file mode 100644
index 0000000000..b9c08fc9d8
--- /dev/null
+++ b/Tests/RunCMake/try_compile/TwoArgs-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at TwoArgs.cmake:1 \(try_compile\):
+ try_compile unknown error.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_compile/TwoArgs.cmake b/Tests/RunCMake/try_compile/TwoArgs.cmake
new file mode 100644
index 0000000000..7f2212d62d
--- /dev/null
+++ b/Tests/RunCMake/try_compile/TwoArgs.cmake
@@ -0,0 +1 @@
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR})
diff --git a/Tests/RunCMake/try_compile/proj/CMakeLists.txt b/Tests/RunCMake/try_compile/proj/CMakeLists.txt
new file mode 100644
index 0000000000..78a87c016e
--- /dev/null
+++ b/Tests/RunCMake/try_compile/proj/CMakeLists.txt
@@ -0,0 +1,2 @@
+cmake_minimum_required(VERSION 2.8.10)
+project(TestProject NONE)
diff --git a/Tests/RunCMake/try_compile/src.c b/Tests/RunCMake/try_compile/src.c
new file mode 100644
index 0000000000..78f2de106c
--- /dev/null
+++ b/Tests/RunCMake/try_compile/src.c
@@ -0,0 +1 @@
+int main(void) { return 0; }
diff --git a/Tests/RunCMake/variable_watch/CMakeLists.txt b/Tests/RunCMake/variable_watch/CMakeLists.txt
new file mode 100644
index 0000000000..12cd3c7757
--- /dev/null
+++ b/Tests/RunCMake/variable_watch/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/variable_watch/ModifiedAccess-stderr.txt b/Tests/RunCMake/variable_watch/ModifiedAccess-stderr.txt
new file mode 100644
index 0000000000..3ff96fcc35
--- /dev/null
+++ b/Tests/RunCMake/variable_watch/ModifiedAccess-stderr.txt
@@ -0,0 +1,4 @@
+CMake Debug Log at ModifiedAccess.cmake:3 \(set\):
+ Variable "b" was accessed using MODIFIED_ACCESS with value "b".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/variable_watch/ModifiedAccess.cmake b/Tests/RunCMake/variable_watch/ModifiedAccess.cmake
new file mode 100644
index 0000000000..87943b39f1
--- /dev/null
+++ b/Tests/RunCMake/variable_watch/ModifiedAccess.cmake
@@ -0,0 +1,3 @@
+set(b "a")
+variable_watch(b)
+set(b "b")
diff --git a/Tests/RunCMake/variable_watch/NoWatcher-stderr.txt b/Tests/RunCMake/variable_watch/NoWatcher-stderr.txt
new file mode 100644
index 0000000000..d2994297da
--- /dev/null
+++ b/Tests/RunCMake/variable_watch/NoWatcher-stderr.txt
@@ -0,0 +1,5 @@
+my_func
+CMake Debug Log at NoWatcher.cmake:8 \(set\):
+ Variable "b" was accessed using MODIFIED_ACCESS with value "".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/variable_watch/NoWatcher.cmake b/Tests/RunCMake/variable_watch/NoWatcher.cmake
new file mode 100644
index 0000000000..8a68efbe42
--- /dev/null
+++ b/Tests/RunCMake/variable_watch/NoWatcher.cmake
@@ -0,0 +1,8 @@
+function(my_func)
+ message("my_func")
+endfunction()
+variable_watch(a my_func)
+set(a "")
+
+variable_watch(b)
+set(b "")
diff --git a/Tests/RunCMake/variable_watch/RunCMakeTest.cmake b/Tests/RunCMake/variable_watch/RunCMakeTest.cmake
new file mode 100644
index 0000000000..9becb4cd7f
--- /dev/null
+++ b/Tests/RunCMake/variable_watch/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(ModifiedAccess)
+run_cmake(NoWatcher)
+run_cmake(WatchTwice)
diff --git a/Tests/RunCMake/variable_watch/WatchTwice-stderr.txt b/Tests/RunCMake/variable_watch/WatchTwice-stderr.txt
new file mode 100644
index 0000000000..fa7d3472a8
--- /dev/null
+++ b/Tests/RunCMake/variable_watch/WatchTwice-stderr.txt
@@ -0,0 +1,2 @@
+From watch1
+From watch2
diff --git a/Tests/RunCMake/variable_watch/WatchTwice.cmake b/Tests/RunCMake/variable_watch/WatchTwice.cmake
new file mode 100644
index 0000000000..540cfc160c
--- /dev/null
+++ b/Tests/RunCMake/variable_watch/WatchTwice.cmake
@@ -0,0 +1,11 @@
+function (watch1)
+ message("From watch1")
+endfunction ()
+
+function (watch2)
+ message("From watch2")
+endfunction ()
+
+variable_watch(watched watch1)
+variable_watch(watched watch2)
+set(access "${watched}")
diff --git a/Tests/RuntimePath/CMakeLists.txt b/Tests/RuntimePath/CMakeLists.txt
new file mode 100644
index 0000000000..6583a87128
--- /dev/null
+++ b/Tests/RuntimePath/CMakeLists.txt
@@ -0,0 +1,33 @@
+cmake_minimum_required (VERSION 2.6)
+project(RuntimePath C)
+
+# Add a simple chain of shared libraries that must be found.
+add_library(foo1 SHARED foo1.c)
+set_property(TARGET foo1 PROPERTY OUTPUT_NAME foo)
+set_property(TARGET foo1 PROPERTY LIBRARY_OUTPUT_DIRECTORY A)
+
+add_library(bar1 SHARED bar1.c)
+set_property(TARGET bar1 PROPERTY OUTPUT_NAME bar)
+set_property(TARGET bar1 PROPERTY VERSION 1)
+set_property(TARGET bar1 PROPERTY LIBRARY_OUTPUT_DIRECTORY B)
+target_link_libraries(bar1 foo1)
+
+add_executable(RuntimePath main.c)
+target_link_libraries(RuntimePath bar1)
+
+# Add a library that provides a conflicting location to make sure
+# rpath ordering works.
+add_library(foo2 SHARED foo2.c)
+set_property(TARGET foo2 PROPERTY OUTPUT_NAME foo)
+set_property(TARGET foo2 PROPERTY LIBRARY_OUTPUT_DIRECTORY B)
+
+# Add a library that would provide a conflicting location if not for
+# soname analysis in rpath ordering. This will also break the old
+# link directory ordering to make sure files are linked with full
+# paths.
+if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG)
+ add_library(bar2 SHARED bar2.c)
+ set_property(TARGET bar2 PROPERTY OUTPUT_NAME bar)
+ set_property(TARGET bar2 PROPERTY LIBRARY_OUTPUT_DIRECTORY A)
+ target_link_libraries(bar2 foo2)
+endif()
diff --git a/Tests/RuntimePath/bar1.c b/Tests/RuntimePath/bar1.c
new file mode 100644
index 0000000000..ebad8d20c0
--- /dev/null
+++ b/Tests/RuntimePath/bar1.c
@@ -0,0 +1,2 @@
+extern int foo1();
+int bar1() { return foo1(); }
diff --git a/Tests/RuntimePath/bar2.c b/Tests/RuntimePath/bar2.c
new file mode 100644
index 0000000000..60d5e686a7
--- /dev/null
+++ b/Tests/RuntimePath/bar2.c
@@ -0,0 +1,2 @@
+extern int foo2();
+int bar2() { return foo2(); }
diff --git a/Tests/RuntimePath/foo1.c b/Tests/RuntimePath/foo1.c
new file mode 100644
index 0000000000..27cd9125b3
--- /dev/null
+++ b/Tests/RuntimePath/foo1.c
@@ -0,0 +1 @@
+int foo1() { return 0; }
diff --git a/Tests/RuntimePath/foo2.c b/Tests/RuntimePath/foo2.c
new file mode 100644
index 0000000000..40b4f56a94
--- /dev/null
+++ b/Tests/RuntimePath/foo2.c
@@ -0,0 +1 @@
+int foo2() { return 0; }
diff --git a/Tests/RuntimePath/main.c b/Tests/RuntimePath/main.c
new file mode 100644
index 0000000000..c71ee0639e
--- /dev/null
+++ b/Tests/RuntimePath/main.c
@@ -0,0 +1,5 @@
+extern int bar1();
+int main()
+{
+ return bar1();
+}
diff --git a/Tests/SBCS/CMakeLists.txt b/Tests/SBCS/CMakeLists.txt
new file mode 100644
index 0000000000..b3c3c2cfcb
--- /dev/null
+++ b/Tests/SBCS/CMakeLists.txt
@@ -0,0 +1,6 @@
+# a SBCS test case
+project (SBCS)
+
+add_definitions(-D_SBCS)
+
+add_executable (SBCS SBCS.cxx)
diff --git a/Tests/SBCS/SBCS.cxx b/Tests/SBCS/SBCS.cxx
new file mode 100644
index 0000000000..6ce2c9f25a
--- /dev/null
+++ b/Tests/SBCS/SBCS.cxx
@@ -0,0 +1,22 @@
+// Test to verify that _SBCS being defined causes CharacterSet to be set to 0 (Single Byte Character Set)
+
+int main ()
+{
+#ifdef _UNICODE
+ bool UnicodeSet=true;
+#else
+ bool UnicodeSet=false;
+#endif
+
+#ifdef _MBCS
+ bool MBCSSet=true;
+#else
+ bool MBCSSet=false;
+#endif
+
+ // if neither _UNICODE nor _MBCS is set, CharacterSet must be set to SBCS.
+ bool SBCSSet=(!UnicodeSet && !MBCSSet);
+
+ // Reverse boolean to indicate error case correctly
+ return !SBCSSet;
+}
diff --git a/Tests/SameName/CMakeLists.txt b/Tests/SameName/CMakeLists.txt
new file mode 100644
index 0000000000..d78879dd95
--- /dev/null
+++ b/Tests/SameName/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required (VERSION 2.6)
+project(SameName C)
+
+add_subdirectory(Lib1)
+
+include_directories(${PROJECT_SOURCE_DIR}/Lib1)
+add_subdirectory(Exe1)
diff --git a/Tests/SameName/Exe1/CMakeLists.txt b/Tests/SameName/Exe1/CMakeLists.txt
new file mode 100644
index 0000000000..b9182f2097
--- /dev/null
+++ b/Tests/SameName/Exe1/CMakeLists.txt
@@ -0,0 +1,11 @@
+# a target with the same name as a target in a different dir
+add_executable(mytest_exe conly.c)
+set_target_properties(mytest_exe PROPERTIES OUTPUT_NAME mytest)
+target_link_libraries(mytest_exe mytest)
+
+# and two targets in the same dir with the same name
+add_library(mytest2 ../Lib1/libc1.c)
+
+add_executable(mytest2_exe conly.c)
+set_target_properties(mytest2_exe PROPERTIES OUTPUT_NAME mytest2)
+target_link_libraries(mytest2_exe mytest2)
diff --git a/Tests/SameName/Exe1/conly.c b/Tests/SameName/Exe1/conly.c
new file mode 100644
index 0000000000..eb62c301a5
--- /dev/null
+++ b/Tests/SameName/Exe1/conly.c
@@ -0,0 +1,12 @@
+#include "libc1.h"
+#include <stdio.h>
+
+int main ()
+{
+ if ( LibC1Func() != 2.0 )
+ {
+ printf("Problem with libc1\n");
+ return 1;
+ }
+ return 0;
+}
diff --git a/Tests/SameName/Lib1/CMakeLists.txt b/Tests/SameName/Lib1/CMakeLists.txt
new file mode 100644
index 0000000000..40fa15422e
--- /dev/null
+++ b/Tests/SameName/Lib1/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(mytest libc1.c)
diff --git a/Tests/SameName/Lib1/libc1.c b/Tests/SameName/Lib1/libc1.c
new file mode 100644
index 0000000000..b01e1e1b54
--- /dev/null
+++ b/Tests/SameName/Lib1/libc1.c
@@ -0,0 +1,4 @@
+float LibC1Func()
+{
+ return 2.0;
+}
diff --git a/Tests/SameName/Lib1/libc1.h b/Tests/SameName/Lib1/libc1.h
new file mode 100644
index 0000000000..84c94a9cb9
--- /dev/null
+++ b/Tests/SameName/Lib1/libc1.h
@@ -0,0 +1 @@
+extern float LibC1Func();
diff --git a/Tests/SetLang/CMakeLists.txt b/Tests/SetLang/CMakeLists.txt
new file mode 100644
index 0000000000..f24e5cb5df
--- /dev/null
+++ b/Tests/SetLang/CMakeLists.txt
@@ -0,0 +1,10 @@
+# test forcing a source file language to c++ from c
+cmake_minimum_required (VERSION 2.6)
+project(SetLang)
+# force this to be verbose so I can debug a dashboard entry
+set(CMAKE_VERBOSE_MAKEFILE 1)
+add_library(foo foo.c)
+add_executable(SetLang bar.c)
+set_source_files_properties(foo.c bar.c PROPERTIES LANGUAGE CXX)
+target_link_libraries(SetLang foo)
+set_target_properties(SetLang PROPERTIES LINKER_LANGUAGE CXX)
diff --git a/Tests/SetLang/bar.c b/Tests/SetLang/bar.c
new file mode 100644
index 0000000000..f59c318b18
--- /dev/null
+++ b/Tests/SetLang/bar.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int foo();
+class A
+{
+public:
+ A() {this->i = foo();}
+ int i;
+};
+
+int main()
+{
+ A a;
+ if(a.i == 21)
+ {
+ printf("passed foo is 21\n");
+ return 0;
+ }
+ printf("Failed foo is not 21\n");
+ return -1;
+}
diff --git a/Tests/SetLang/foo.c b/Tests/SetLang/foo.c
new file mode 100644
index 0000000000..e7918af587
--- /dev/null
+++ b/Tests/SetLang/foo.c
@@ -0,0 +1,7 @@
+int foo()
+{
+ int r = 10;
+ r++;
+ int ret = r+10;
+ return ret;
+}
diff --git a/Tests/Simple/CMakeLists.txt b/Tests/Simple/CMakeLists.txt
new file mode 100644
index 0000000000..a951c2da21
--- /dev/null
+++ b/Tests/Simple/CMakeLists.txt
@@ -0,0 +1,17 @@
+# a simple test case
+project (Simple)
+
+add_executable (Simple simple.cxx)
+
+add_library (simpleLib STATIC
+ simpleLib.cxx
+ simpleCLib.c
+ simpleWe.cpp
+ )
+
+target_link_libraries (Simple simpleLib)
+
+# make sure optimized libs are not used by debug builds
+if(CMAKE_BUILD_TYPE MATCHES Debug)
+ target_link_libraries(Simple optimized c:/not/here.lib )
+endif()
diff --git a/Tests/Simple/simple.cxx b/Tests/Simple/simple.cxx
new file mode 100644
index 0000000000..7bee7c074b
--- /dev/null
+++ b/Tests/Simple/simple.cxx
@@ -0,0 +1,11 @@
+extern void simpleLib();
+extern "C" int FooBar();
+extern int bar();
+extern int bar1();
+int main ()
+{
+ FooBar();
+ bar();
+ simpleLib();
+ return 0;
+}
diff --git a/Tests/Simple/simpleCLib.c b/Tests/Simple/simpleCLib.c
new file mode 100644
index 0000000000..88fc33efc2
--- /dev/null
+++ b/Tests/Simple/simpleCLib.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+int FooBar()
+{
+ int class;
+ int private = 10;
+ for ( class = 0; class < private; class ++ )
+ {
+ printf("Count: %d/%d\n", class, private);
+ }
+ return 0;
+}
diff --git a/Tests/Simple/simpleLib.cxx b/Tests/Simple/simpleLib.cxx
new file mode 100644
index 0000000000..281d8885a8
--- /dev/null
+++ b/Tests/Simple/simpleLib.cxx
@@ -0,0 +1,3 @@
+void simpleLib()
+{
+}
diff --git a/Tests/Simple/simpleWe.cpp b/Tests/Simple/simpleWe.cpp
new file mode 100644
index 0000000000..e0f22ef8d4
--- /dev/null
+++ b/Tests/Simple/simpleWe.cpp
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+class Foo
+{
+public:
+ Foo()
+ {
+ printf("This one has nonstandard extension\n");
+ }
+ int getnum() { return 0; }
+};
+
+int bar()
+{
+ Foo f;
+ return f.getnum();
+}
diff --git a/Tests/SimpleCOnly/CMakeLists.txt b/Tests/SimpleCOnly/CMakeLists.txt
new file mode 100644
index 0000000000..fb247790f0
--- /dev/null
+++ b/Tests/SimpleCOnly/CMakeLists.txt
@@ -0,0 +1,17 @@
+# this enables only C, i.e. disables C++
+project(SimpleCOnly C)
+
+add_library(SimpleCLib STATIC bar.c foo.c)
+
+add_executable(SimpleC main.c)
+target_link_libraries(SimpleC SimpleCLib)
+
+# and some check, just to make sure it works:
+include(CheckTypeSize)
+check_type_size(float SIZE_FLOAT)
+message(STATUS "sizeof(float): ${SIZE_FLOAT}")
+
+# make sure optimized libs are not used by debug builds
+if(CMAKE_BUILD_TYPE MATCHES Debug)
+ target_link_libraries(Simple optimized c:/not/here.lib )
+endif()
diff --git a/Tests/SimpleCOnly/bar.c b/Tests/SimpleCOnly/bar.c
new file mode 100644
index 0000000000..5d8eac09ff
--- /dev/null
+++ b/Tests/SimpleCOnly/bar.c
@@ -0,0 +1 @@
+int bar() {return 5;}
diff --git a/Tests/SimpleCOnly/foo.c b/Tests/SimpleCOnly/foo.c
new file mode 100644
index 0000000000..b8cdea4274
--- /dev/null
+++ b/Tests/SimpleCOnly/foo.c
@@ -0,0 +1 @@
+int foo() { return 12;}
diff --git a/Tests/SimpleCOnly/main.c b/Tests/SimpleCOnly/main.c
new file mode 100644
index 0000000000..022a8e88d0
--- /dev/null
+++ b/Tests/SimpleCOnly/main.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+extern int foo();
+extern int bar();
+
+int main()
+{
+ int i=foo();
+ int k=bar();
+ i=i*k;
+ return i;
+}
diff --git a/Tests/SimpleExclude/CMakeLists.txt b/Tests/SimpleExclude/CMakeLists.txt
new file mode 100644
index 0000000000..baca23e39b
--- /dev/null
+++ b/Tests/SimpleExclude/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required (VERSION 2.6)
+project(SimpleExclude C)
+
+set(EXECUTABLE_OUTPUT_PATH "${SimpleExclude_BINARY_DIR}" CACHE INTERNAL "" FORCE)
+set(LIBRARY_OUTPUT_PATH "${SimpleExclude_BINARY_DIR}" CACHE INTERNAL "" FORCE)
+
+add_subdirectory(dirC EXCLUDE_FROM_ALL)
+add_subdirectory(dirD)
+
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/run.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/run.cmake" @ONLY)
diff --git a/Tests/SimpleExclude/dirC/CMakeLists.txt b/Tests/SimpleExclude/dirC/CMakeLists.txt
new file mode 100644
index 0000000000..9b59fdaffc
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_subdirectory(dirA EXCLUDE_FROM_ALL)
+add_subdirectory(dirB)
+
diff --git a/Tests/SimpleExclude/dirC/dirA/CMakeLists.txt b/Tests/SimpleExclude/dirC/dirA/CMakeLists.txt
new file mode 100644
index 0000000000..52fac81833
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/dirA/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_library(t1 STATIC t1.c)
+
+add_library(t2 STATIC t2.c)
+
+add_executable(t3 t3.c)
+
+add_executable(t4 t4.c)
+
+add_executable(t5 t5.c)
+target_link_libraries(t5 t1)
diff --git a/Tests/SimpleExclude/dirC/dirA/t1.c b/Tests/SimpleExclude/dirC/dirA/t1.c
new file mode 100644
index 0000000000..67fe06fee3
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/dirA/t1.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int tlib1func()
+{
+ Should not be build unless target directory A, B, or C are build;
+ printf("This is T1\n");
+ return 5;
+}
diff --git a/Tests/SimpleExclude/dirC/dirA/t2.c b/Tests/SimpleExclude/dirC/dirA/t2.c
new file mode 100644
index 0000000000..6aaf40675d
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/dirA/t2.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int tlib2func()
+{
+ printf("This is T2\n");
+ return 2;
+}
diff --git a/Tests/SimpleExclude/dirC/dirA/t3.c b/Tests/SimpleExclude/dirC/dirA/t3.c
new file mode 100644
index 0000000000..1366dc0a6c
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/dirA/t3.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char* argv[])
+{
+ Should not be build unless target directory A, B, or C are build;
+ return 0;
+}
diff --git a/Tests/SimpleExclude/dirC/dirA/t4.c b/Tests/SimpleExclude/dirC/dirA/t4.c
new file mode 100644
index 0000000000..7c36ca927a
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/dirA/t4.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+#ifdef __CLASSIC_C__
+int main()
+{
+ int ac;
+ char*av[];
+#else
+ int main(int ac, char*av[])
+ {
+#endif
+ if(ac > 1000){return *av[0];}
+ printf("This is T4. This one should work.\n");
+ return 0;
+ }
+
+
diff --git a/Tests/SimpleExclude/dirC/dirA/t5.c b/Tests/SimpleExclude/dirC/dirA/t5.c
new file mode 100644
index 0000000000..1fba2127ca
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/dirA/t5.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char* argv[])
+{
+ Should not be build unless target directory A, B, or C are build;
+ return 5;
+}
diff --git a/Tests/SimpleExclude/dirC/dirB/CMakeLists.txt b/Tests/SimpleExclude/dirC/dirB/CMakeLists.txt
new file mode 100644
index 0000000000..ea4650c4a3
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/dirB/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_library(t6 STATIC t6.c)
+
+add_library(t7 STATIC t7.c)
+target_link_libraries(t7 t2)
+
diff --git a/Tests/SimpleExclude/dirC/dirB/t6.c b/Tests/SimpleExclude/dirC/dirB/t6.c
new file mode 100644
index 0000000000..e8877df606
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/dirB/t6.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int tlib6func()
+{
+ Should not be build unless target directory B, or C are build;
+ printf("This is T6\n");
+ return 6;
+}
diff --git a/Tests/SimpleExclude/dirC/dirB/t7.c b/Tests/SimpleExclude/dirC/dirB/t7.c
new file mode 100644
index 0000000000..b95d3ec43b
--- /dev/null
+++ b/Tests/SimpleExclude/dirC/dirB/t7.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+extern int tlib2func();
+
+int tlib7func()
+{
+ printf("This is T7\n");
+
+ if ( tlib2func() != 2 )
+ {
+ fprintf(stderr, "Something wrong with T2\n");
+ return 1;
+ }
+
+ return 7;
+}
diff --git a/Tests/SimpleExclude/dirD/CMakeLists.txt b/Tests/SimpleExclude/dirD/CMakeLists.txt
new file mode 100644
index 0000000000..44b8c27b68
--- /dev/null
+++ b/Tests/SimpleExclude/dirD/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_library(t8 STATIC t8.c)
+
+add_executable(t9 t9.c)
+target_link_libraries(t9 t7)
+
+add_custom_target(t4_custom ALL)
+add_dependencies(t4_custom t4)
diff --git a/Tests/SimpleExclude/dirD/t8.c b/Tests/SimpleExclude/dirD/t8.c
new file mode 100644
index 0000000000..bddec6f7e5
--- /dev/null
+++ b/Tests/SimpleExclude/dirD/t8.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int tlib8func()
+{
+ printf("This is T8\n");
+ return 8;
+}
diff --git a/Tests/SimpleExclude/dirD/t9.c b/Tests/SimpleExclude/dirD/t9.c
new file mode 100644
index 0000000000..321014b179
--- /dev/null
+++ b/Tests/SimpleExclude/dirD/t9.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+extern int tlib7func();
+
+#ifdef __CLASSIC_C__
+int main()
+{
+ int ac;
+ char*av[];
+#else
+ int main(int ac, char*av[])
+ {
+#endif
+ if(ac > 1000){return *av[0];}
+ printf("This is T9. This one should work.\n");
+
+ if ( tlib7func() != 7 )
+ {
+ fprintf(stderr, "Something wrong with T7\n");
+ return 1;
+ }
+ return 0;
+ }
+
diff --git a/Tests/SimpleExclude/run.cmake.in b/Tests/SimpleExclude/run.cmake.in
new file mode 100644
index 0000000000..d31d2e51b4
--- /dev/null
+++ b/Tests/SimpleExclude/run.cmake.in
@@ -0,0 +1,13 @@
+set(t4_name "\"@CMAKE_CURRENT_BINARY_DIR@${CFG_DIR}/t4\"")
+exec_program("${t4_name}" RETURN_VALUE "t4_var")
+message("T4 ${t4_name} resulted ${t4_var}")
+
+set(t9_name "\"@CMAKE_CURRENT_BINARY_DIR@${CFG_DIR}/t9\"")
+exec_program("${t9_name}" RETURN_VALUE "t9_var")
+message("T9 ${t9_name} resulted ${t9_var}")
+
+if ( "${t4_var}" EQUAL "0" AND "${t9_var}" EQUAL "0" )
+ message("Everything is good, Yoshimi won...")
+else ()
+ message(FATAL_ERROR "Yoshimi lost... The evil pink robots will take over the world")
+endif ()
diff --git a/Tests/SimpleInstall/CMakeLists.txt b/Tests/SimpleInstall/CMakeLists.txt
new file mode 100644
index 0000000000..cc3c3be61d
--- /dev/null
+++ b/Tests/SimpleInstall/CMakeLists.txt
@@ -0,0 +1,395 @@
+cmake_minimum_required (VERSION 2.6)
+project (TestSimpleInstall)
+set(CMAKE_VERBOSE_MAKEFILE 1)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
+ "${TestSimpleInstall_BINARY_DIR}/bin")
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
+ "${TestSimpleInstall_BINARY_DIR}/lib/static")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
+ "${TestSimpleInstall_BINARY_DIR}/lib")
+
+# Skip generating the rpath pointing at the build tree to make sure
+# the executable is installed with the proper rpath in the install
+# tree.
+set(CMAKE_SKIP_BUILD_RPATH 1)
+
+# Make sure the executable can run from the install tree.
+set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+
+# Skip the dependency that causes a build when installing. This
+# avoids infinite loops when the post-build rule below installs.
+set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY 1)
+set(CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY 1)
+
+set(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
+
+set(EXTRA_INSTALL_FLAGS)
+message("Extra install: ${EXTRA_INSTALL_FLAGS}")
+
+if(STAGE2)
+ set(LIBPATHS
+ ${CMAKE_INSTALL_PREFIX}/MyTest/lib/static
+ ${CMAKE_INSTALL_PREFIX}/MyTest/lib
+ )
+ set(t1NAMES test1 test1${CMAKE_DEBUG_POSTFIX} test1rel)
+ set(t2NAMES test2 test2${CMAKE_DEBUG_POSTFIX})
+ set(t4NAMES test4out test4out${CMAKE_DEBUG_POSTFIX})
+
+ # Make sure the install script ran.
+ set(CMAKE_INSTALL_SCRIPT_DID_RUN 0)
+ include(${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake OPTIONAL)
+ if(CMAKE_INSTALL_SCRIPT_DID_RUN)
+ message(STATUS "Stage 1 did run install script 2.")
+ else()
+ message(SEND_ERROR "Stage 1 did not run install script 2.")
+ endif()
+
+ if(CYGWIN OR MINGW)
+ set(LIBPATHS ${LIBPATHS} "${CMAKE_INSTALL_PREFIX}/MyTest/bin")
+ endif()
+ message("Search for library in: ${LIBPATHS}")
+
+ set(TEST1_LIBRARY "TEST1_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
+ set(TEST2_LIBRARY "TEST2_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
+ set(TEST4_LIBRARY "TEST4_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
+
+ find_library(TEST1_LIBRARY
+ NAMES ${t1NAMES}
+ PATHS ${LIBPATHS}
+ DOC "First library")
+ find_library(TEST2_LIBRARY
+ NAMES ${t2NAMES}
+ PATHS ${LIBPATHS}
+ DOC "Second library")
+ find_library(TEST4_LIBRARY
+ NAMES ${t4NAMES}
+ PATHS ${LIBPATHS}
+ DOC "Fourth library")
+
+ # Test importing a library found on disk.
+ add_library(lib_test4 UNKNOWN IMPORTED)
+ set_property(TARGET lib_test4 PROPERTY IMPORTED_LOCATION ${TEST4_LIBRARY})
+
+ include_directories(${CMAKE_INSTALL_PREFIX}/MyTest/include)
+ add_executable (SimpleInstExeS2 inst2.cxx foo.c foo.h)
+ target_link_libraries(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} lib_test4)
+ set(install_target SimpleInstExeS2)
+
+ if("${TEST1_LIBRARY}" MATCHES "static")
+ message(STATUS "test1 correctly found in lib/static")
+ else()
+ message(SEND_ERROR "test1 not found in lib/static!")
+ endif()
+
+ # Check for failure of configuration-specific installation.
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
+ message(FATAL_ERROR "Debug-configuration file installed for Release!")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
+ message(FATAL_ERROR "Release-configuration file installed for Debug!")
+ endif()
+
+ # Check for failure of directory installation.
+ if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
+ message(FATAL_ERROR "Directory installation did not install TSD.h")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
+ message(FATAL_ERROR "Directory installation installed CVS directory.")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
+ message(FATAL_ERROR "Directory installation installed CVS directory.")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
+ message(FATAL_ERROR "Directory installation installed CMakeLists.txt.")
+ endif()
+ if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.h")
+ message(FATAL_ERROR "Directory installation did not install alternate TSD.h")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.cxx")
+ message(FATAL_ERROR "Directory installation installed alternate TSD.cxx")
+ endif()
+
+ # Check that scripts properly installed.
+ if(WIN32 AND NOT CYGWIN)
+ set(BAT .bat)
+ else()
+ set(BAT)
+ endif()
+ foreach(loc share share/old1 share/old2 share/old3 share/alt)
+ set(CUR_SCRIPT "${CMAKE_INSTALL_PREFIX}/MyTest/${loc}/sample_script${BAT}")
+ execute_process(
+ COMMAND ${CUR_SCRIPT}
+ RESULT_VARIABLE SAMPLE_SCRIPT_RESULT
+ OUTPUT_VARIABLE SAMPLE_SCRIPT_OUTPUT
+ )
+ if(NOT "${SAMPLE_SCRIPT_RESULT}" STREQUAL "0")
+ message(FATAL_ERROR
+ "Sample script [${CUR_SCRIPT}] failed: [${SAMPLE_SCRIPT_RESULT}]")
+ endif()
+ if(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
+ message(FATAL_ERROR
+ "Bad sample script [${CUR_SCRIPT}] output: [${SAMPLE_SCRIPT_OUTPUT}]")
+ endif()
+ endforeach()
+
+ # Check for failure of empty directory installation.
+ if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
+ message(FATAL_ERROR "Empty directory installation did not install.")
+ endif()
+ file(GLOB EMPTY_FILES "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty/*")
+ if(EMPTY_FILES)
+ message(FATAL_ERROR "Empty directory installed [${EMPTY_FILES}].")
+ endif()
+
+ # Make sure the test executable can run from the install tree.
+ set_target_properties(SimpleInstExeS2 PROPERTIES
+ INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+
+ install_targets(/MyTest/bin SimpleInstExeS2)
+
+# try to import the exported targets again
+ set(SimpleInstallS1_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+ find_package(SimpleInstallS1 REQUIRED)
+ get_target_property(simpleInstallImported S1_SimpleInstall IMPORTED)
+ if(NOT simpleInstallImported)
+ message(FATAL_ERROR "Target S1_SimpleInstall could not be imported")
+ endif()
+
+else()
+ # Wipe out the install directory to do a fresh test.
+ file(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/MyTest)
+
+ # this is stage 1, so create libraries and modules and install everything
+ add_library(test1 STATIC lib1.cxx)
+ add_library(test2 SHARED lib2.cxx)
+ add_library(test3 MODULE lib3.cxx)
+ add_library(test4 SHARED lib4.cxx)
+
+ # Test <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME properties.
+ set_property(TARGET test4 PROPERTY ARCHIVE_OUTPUT_NAME test4out)
+ set_property(TARGET test4 PROPERTY LIBRARY_OUTPUT_NAME test4out)
+
+ add_executable (SimpleInstall inst.cxx foo.c foo.h)
+ target_link_libraries(SimpleInstall test1 test2 test4)
+ set(install_target SimpleInstall)
+
+ set_target_properties(SimpleInstall PROPERTIES OUTPUT_NAME SimpleInstExe)
+ # Disable VERSION test until it is implemented in the Xcode generator.
+ if(NOT XCODE)
+ set_target_properties(SimpleInstall PROPERTIES VERSION 1.2)
+ endif()
+
+ # Make sure the test executable can run from the install tree.
+ set_target_properties(SimpleInstall PROPERTIES
+ INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+
+ # Test per-configuration output name.
+ set_target_properties(test1 PROPERTIES RELEASE_OUTPUT_NAME test1rel)
+ set_target_properties(test2 PROPERTIES PUBLIC_HEADER foo.h)
+
+ if(CMAKE_GENERATOR MATCHES "Makefiles")
+ add_subdirectory(TestSubDir)
+ add_dependencies(SimpleInstall TSD)
+ endif()
+
+ add_dependencies(SimpleInstall test3)
+ add_dependencies(test2 test3)
+ add_dependencies(test4 test2)
+
+ install(TARGETS SimpleInstall test1 test2 test3 EXPORT SimpleInstallS1
+ RUNTIME DESTINATION MyTest/bin COMPONENT Runtime # .exe, .dll
+ LIBRARY DESTINATION MyTest/lib COMPONENT Runtime # .so, mod.dll
+ ARCHIVE DESTINATION MyTest/lib/static COMPONENT Development # .a, .lib
+ PUBLIC_HEADER DESTINATION MyTest/include COMPONENT Development
+ )
+
+ install(TARGETS test4 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ RUNTIME DESTINATION MyTest/bin
+ LIBRARY DESTINATION MyTest/lib
+ ARCHIVE DESTINATION MyTest/lib/static
+ OPTIONAL # for coverage...target should always exist
+ )
+ install(FILES lib1.h DESTINATION MyTest/include/foo)
+ install(FILES lib2.h
+ DESTINATION MyTest/include/foo
+ COMPONENT Development
+ PERMISSIONS OWNER_READ OWNER_WRITE
+ RENAME lib2renamed.h
+ )
+
+ # Test old-style install commands.
+ install_files(/MyTest/include FILES lib3.h)
+ install_files(/MyTest/include/old .h lib3)
+ install_files(/MyTest/include/old "^lib2.h$")
+ install_programs(/MyTest/share/old1 FILES
+ scripts/sample_script scripts/sample_script.bat)
+ install_programs(/MyTest/share/old2
+ scripts/sample_script scripts/sample_script.bat)
+
+# "export" the targets collected in "SimpleInstallS1"
+ install(EXPORT SimpleInstallS1 FILE SimpleInstallS1Config.cmake
+ DESTINATION MyTest/lib
+ NAMESPACE S1_ )
+
+ export(TARGETS SimpleInstall test1 test2 test3
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/SimpleInstallS1Config.cmake"
+ NAMESPACE S2_ )
+
+ add_subdirectory(scripts)
+
+ # Test optional installation.
+ install(FILES does_not_exist.h DESTINATION MyTest/include/foo OPTIONAL)
+
+ # Test configuration-specific installation.
+ install(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
+ DESTINATION MyTest/include/Release
+ )
+ install(FILES lib1.h RENAME lib1debug.h CONFIGURATIONS Debug
+ DESTINATION MyTest/include/Debug
+ )
+
+ # Test directory installation.
+ file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
+ file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
+ install(
+ DIRECTORY TestSubDir scripts/ DESTINATION MyTest/share
+ FILE_PERMISSIONS OWNER_READ OWNER_WRITE
+ DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE
+ PATTERN "CVS" EXCLUDE
+ REGEX "\\.txt$" EXCLUDE
+ PATTERN "scripts/*" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
+ )
+
+ # Alternate directory installation for coverage.
+ install(
+ DIRECTORY scripts/ DESTINATION MyTest/share/alt
+ COMPONENT Development
+ USE_SOURCE_PERMISSIONS
+ PATTERN "CVS" EXCLUDE
+ REGEX "\\.txt$" EXCLUDE
+ )
+ install(
+ DIRECTORY TestSubDir DESTINATION MyTest/share/alt
+ FILE_PERMISSIONS OWNER_READ OWNER_WRITE
+ DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE
+ FILES_MATCHING PATTERN "*.h"
+ )
+
+ # Test empty directory installation.
+ install(DIRECTORY DESTINATION MyTest/share/empty)
+
+ # Test optional directory installation.
+ install(DIRECTORY does-not-exist DESTINATION MyTest/share OPTIONAL)
+
+ # Test user-specified install scripts, with and without COMPONENT.
+ install(
+ SCRIPT InstallScript1.cmake
+ CODE "set(INSTALL_CODE_DID_RUN 1)"
+ SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
+ )
+ install(
+ SCRIPT InstallScript3.cmake
+ CODE "set(INSTALL_CODE_WITH_COMPONENT_DID_RUN 1)"
+ SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript4.cmake
+ COMPONENT Development
+ )
+ set_directory_properties(PROPERTIES
+ ADDITIONAL_MAKE_CLEAN_FILES
+ "${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake;${CMAKE_INSTALL_PREFIX}/InstallScript4Out.cmake")
+
+ set_target_properties(SimpleInstall PROPERTIES PRE_INSTALL_SCRIPT
+ ${CMAKE_CURRENT_SOURCE_DIR}/PreInstall.cmake)
+ set_target_properties(SimpleInstall PROPERTIES POST_INSTALL_SCRIPT
+ ${CMAKE_CURRENT_SOURCE_DIR}/PostInstall.cmake)
+ set_target_properties(test4 PROPERTIES VERSION 1.2 SOVERSION 3
+ INSTALL_NAME_DIR @executable_path/../lib)
+endif()
+
+if(CMAKE_CONFIGURATION_TYPES)
+ set(SI_CONFIG --config $<CONFIGURATION>)
+else()
+ set(SI_CONFIG)
+endif()
+
+# Dummy test of CPack
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test of packaging with cpack")
+set(CPACK_PACKAGE_VENDOR "Kitware")
+set(CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/PackageScript.cmake")
+
+if(WIN32 AND NOT UNIX)
+ find_program(NSIS_MAKENSIS NAMES makensis
+ PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
+ DOC "Where is makensis.exe located"
+ )
+ if(NOT NSIS_MAKENSIS)
+ set(CPACK_GENERATOR TGZ)
+ endif()
+endif()
+if(UNIX AND NOT APPLE)
+ set(CPACK_GENERATOR "TGZ;STGZ;TZ")
+ # find_program(found_compress
+ # NAMES compress)
+ # if(found_compress)
+ # find_program(file_command NAMES file)
+ # if(NOT file_command)
+ # set(file_command file)
+ # endif()
+ # execute_process(COMMAND ${file_command} ${found_compress}
+ # OUTPUT_VARIABLE output)
+ # set(SKIP_TZ FALSE)
+ # if("${output}" MATCHES "script")
+ # set(SKIP_TZ TRUE)
+ # endif()
+ # if("${output}" MATCHES "dummy.sh")
+ # set(SKIP_TZ TRUE)
+ # endif()
+ # if(NOT SKIP_TZ)
+ # message("compress found and it was not a script")
+ # message("output from file command: [${output}]")
+ # set(CPACK_GENERATOR "${CPACK_GENERATOR};TZ")
+ # else()
+ # message("compress found, but it was a script so dont use it")
+ # message("output from file command: [${output}]")
+ # endif()
+ # endif()
+ find_program(found_bz2
+ NAMES bzip2)
+ if(found_bz2)
+ set(CPACK_GENERATOR "${CPACK_GENERATOR};TBZ2")
+ endif()
+endif()
+
+set(CPACK_PACKAGE_EXECUTABLES "SimpleInstall" "Simple Install")
+set(CMAKE_INSTALL_MFC_LIBRARIES 1)
+set(CMAKE_INSTALL_DEBUG_LIBRARIES 1)
+include(InstallRequiredSystemLibraries)
+
+if(CTEST_TEST_CPACK)
+ set(package_command COMMAND
+ ${CMAKE_COMMAND} --build . --target package ${SI_CONFIG}
+ )
+
+ # Avoid settings that require the .zip file command line tools...
+ # (just build an NSIS installer without component support)
+ #
+ set(CPACK_BINARY_ZIP OFF)
+ set(CPACK_MONOLITHIC_INSTALL ON)
+else()
+ set(package_command)
+endif()
+
+include(CPack)
+
+set(install_command COMMAND
+ ${CMAKE_COMMAND} --build . --target install ${SI_CONFIG}
+ )
+
+add_custom_command(
+ TARGET ${install_target}
+ POST_BUILD
+ ${install_command}
+ ${package_command}
+ COMMENT "Install Project"
+ )
diff --git a/Tests/SimpleInstall/InstallScript1.cmake b/Tests/SimpleInstall/InstallScript1.cmake
new file mode 100644
index 0000000000..ef9da5761c
--- /dev/null
+++ b/Tests/SimpleInstall/InstallScript1.cmake
@@ -0,0 +1,5 @@
+message("This is install script 1.")
+set(INSTALL_SCRIPT_1_DID_RUN 1)
+if(INSTALL_CODE_DID_RUN)
+ message(FATAL_ERROR "Install script 1 did not run before install code.")
+endif()
diff --git a/Tests/SimpleInstall/InstallScript2.cmake b/Tests/SimpleInstall/InstallScript2.cmake
new file mode 100644
index 0000000000..c1d20a3a67
--- /dev/null
+++ b/Tests/SimpleInstall/InstallScript2.cmake
@@ -0,0 +1,14 @@
+message("This is install script 2.")
+if(INSTALL_SCRIPT_1_DID_RUN)
+ message("Install script ordering works.")
+else()
+ message(FATAL_ERROR "Install script 1 did not run before install script 2.")
+endif()
+if(INSTALL_CODE_DID_RUN)
+ message("Install code ordering works.")
+else()
+ message(FATAL_ERROR "Install script 2 did not run after install code.")
+endif()
+file(WRITE "${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake"
+ "set(CMAKE_INSTALL_SCRIPT_DID_RUN 1)\n"
+ )
diff --git a/Tests/SimpleInstall/InstallScript3.cmake b/Tests/SimpleInstall/InstallScript3.cmake
new file mode 100644
index 0000000000..64851564d0
--- /dev/null
+++ b/Tests/SimpleInstall/InstallScript3.cmake
@@ -0,0 +1,12 @@
+message("This is install script 3.")
+set(INSTALL_SCRIPT_3_DID_RUN 1)
+if(INSTALL_CODE_WITH_COMPONENT_DID_RUN)
+ message(FATAL_ERROR "Install script 3 did not run before install code with component.")
+endif()
+
+if(CMAKE_INSTALL_COMPONENT)
+if(NOT "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Development")
+ message("CMAKE_INSTALL_COMPONENT=\"${CMAKE_INSTALL_COMPONENT}\"")
+ message(FATAL_ERROR "Install script 3 should only run for \"Development\" INSTALL COMPONENT.")
+endif()
+endif()
diff --git a/Tests/SimpleInstall/InstallScript4.cmake b/Tests/SimpleInstall/InstallScript4.cmake
new file mode 100644
index 0000000000..34d0a73bb8
--- /dev/null
+++ b/Tests/SimpleInstall/InstallScript4.cmake
@@ -0,0 +1,22 @@
+message("This is install script 4.")
+if(INSTALL_SCRIPT_3_DID_RUN)
+ message("Install script ordering works.")
+else()
+ message(FATAL_ERROR "Install script 3 did not run before install script 4.")
+endif()
+if(INSTALL_CODE_WITH_COMPONENT_DID_RUN)
+ message("Install code ordering works.")
+else()
+ message(FATAL_ERROR "Install script 4 did not run after install with component code.")
+endif()
+
+if(CMAKE_INSTALL_COMPONENT)
+if(NOT "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Development")
+ message("CMAKE_INSTALL_COMPONENT=\"${CMAKE_INSTALL_COMPONENT}\"")
+ message(FATAL_ERROR "Install script 4 should only run for \"Development\" INSTALL COMPONENT.")
+endif()
+endif()
+
+file(WRITE "${CMAKE_INSTALL_PREFIX}/MyTest/InstallScript4Out.cmake"
+ "set(CMAKE_INSTALL_SCRIPT_4_DID_RUN 1)\n"
+ )
diff --git a/Tests/SimpleInstall/PackageScript.cmake b/Tests/SimpleInstall/PackageScript.cmake
new file mode 100644
index 0000000000..53b790932b
--- /dev/null
+++ b/Tests/SimpleInstall/PackageScript.cmake
@@ -0,0 +1,10 @@
+message("This is packaging script")
+message("It writes a file with all variables available in ${CMAKE_INSTALL_PREFIX}/AllVariables.txt")
+
+file(WRITE ${CMAKE_INSTALL_PREFIX}/AllVariables.txt "")
+get_cmake_property(res VARIABLES)
+foreach(var ${res})
+ file(APPEND ${CMAKE_INSTALL_PREFIX}/AllVariables.txt
+ "${var} \"${${var}}\"\n")
+endforeach()
+
diff --git a/Tests/SimpleInstall/PostInstall.cmake b/Tests/SimpleInstall/PostInstall.cmake
new file mode 100644
index 0000000000..d616221ef3
--- /dev/null
+++ b/Tests/SimpleInstall/PostInstall.cmake
@@ -0,0 +1,6 @@
+message("In post install")
+if(PRE_INSTALL_DID_RUN)
+ message("Pre and post install work fine")
+else()
+ message(FATAL_ERROR "Pre install did not run before post install")
+endif()
diff --git a/Tests/SimpleInstall/PreInstall.cmake b/Tests/SimpleInstall/PreInstall.cmake
new file mode 100644
index 0000000000..7a9851e1d8
--- /dev/null
+++ b/Tests/SimpleInstall/PreInstall.cmake
@@ -0,0 +1,2 @@
+message("This is in pre install")
+set(PRE_INSTALL_DID_RUN 1)
diff --git a/Tests/SimpleInstall/TestSubDir/CMakeLists.txt b/Tests/SimpleInstall/TestSubDir/CMakeLists.txt
new file mode 100644
index 0000000000..860e10425f
--- /dev/null
+++ b/Tests/SimpleInstall/TestSubDir/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_executable(TSD TSD.cxx TSD_utils.cxx)
+install_files(/MyTest/include FILES TSD.h)
+install_targets(/MyTest/bin TSD)
diff --git a/Tests/SimpleInstall/TestSubDir/TSD.cxx b/Tests/SimpleInstall/TestSubDir/TSD.cxx
new file mode 100644
index 0000000000..8fc38787ac
--- /dev/null
+++ b/Tests/SimpleInstall/TestSubDir/TSD.cxx
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+#include "TSD.h"
+
+int main()
+{
+ int res = TSD("TEST");
+ printf("Hello from TSD\n");
+ return res;
+}
diff --git a/Tests/SimpleInstall/TestSubDir/TSD.h b/Tests/SimpleInstall/TestSubDir/TSD.h
new file mode 100644
index 0000000000..6a3c1affaa
--- /dev/null
+++ b/Tests/SimpleInstall/TestSubDir/TSD.h
@@ -0,0 +1 @@
+int TSD(const char*);
diff --git a/Tests/SimpleInstall/TestSubDir/TSD_utils.cxx b/Tests/SimpleInstall/TestSubDir/TSD_utils.cxx
new file mode 100644
index 0000000000..0277f05aec
--- /dev/null
+++ b/Tests/SimpleInstall/TestSubDir/TSD_utils.cxx
@@ -0,0 +1,10 @@
+#include <string.h>
+
+int TSD(const char* foo)
+{
+ if ( strcmp(foo, "TEST") == 0 )
+ {
+ return 0;
+ }
+ return 1;
+}
diff --git a/Tests/SimpleInstall/foo.c b/Tests/SimpleInstall/foo.c
new file mode 100644
index 0000000000..45d5b2bf22
--- /dev/null
+++ b/Tests/SimpleInstall/foo.c
@@ -0,0 +1,6 @@
+char* foo = "Foo";
+
+int SomeFunctionInFoo()
+{
+ return 5;
+}
diff --git a/Tests/SimpleInstall/foo.h b/Tests/SimpleInstall/foo.h
new file mode 100644
index 0000000000..2708baffe9
--- /dev/null
+++ b/Tests/SimpleInstall/foo.h
@@ -0,0 +1,11 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char* foo;
+extern int SomeFunctionInFoo();
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/Tests/SimpleInstall/inst.cxx b/Tests/SimpleInstall/inst.cxx
new file mode 100644
index 0000000000..7f2962d00b
--- /dev/null
+++ b/Tests/SimpleInstall/inst.cxx
@@ -0,0 +1,37 @@
+#include "foo.h"
+
+#ifdef STAGE_2
+# include <foo/lib1.h>
+# include <foo/lib2renamed.h>
+# include <lib3.h>
+# include <old/lib2.h>
+# include <old/lib3.h>
+#else
+# include "lib1.h"
+# include "lib2.h"
+#endif
+
+#include "lib4.h"
+
+#include <stdio.h>
+
+int main ()
+{
+ if ( Lib1Func() != 2.0 )
+ {
+ printf("Problem with lib1\n");
+ return 1;
+ }
+ if ( Lib2Func() != 1.0 )
+ {
+ printf("Problem with lib2\n");
+ return 1;
+ }
+ if ( Lib4Func() != 4.0 )
+ {
+ printf("Problem with lib4\n");
+ return 1;
+ }
+ printf("The value of Foo: %s\n", foo);
+ return SomeFunctionInFoo()-5;
+}
diff --git a/Tests/SimpleInstall/inst2.cxx b/Tests/SimpleInstall/inst2.cxx
new file mode 100644
index 0000000000..c70b93af1d
--- /dev/null
+++ b/Tests/SimpleInstall/inst2.cxx
@@ -0,0 +1,2 @@
+#define STAGE_2
+#include "inst.cxx"
diff --git a/Tests/SimpleInstall/lib1.cxx b/Tests/SimpleInstall/lib1.cxx
new file mode 100644
index 0000000000..7aa905205f
--- /dev/null
+++ b/Tests/SimpleInstall/lib1.cxx
@@ -0,0 +1,6 @@
+#include "lib1.h"
+
+float Lib1Func()
+{
+ return 2.0;
+}
diff --git a/Tests/SimpleInstall/lib1.h b/Tests/SimpleInstall/lib1.h
new file mode 100644
index 0000000000..0d64e76bc4
--- /dev/null
+++ b/Tests/SimpleInstall/lib1.h
@@ -0,0 +1 @@
+extern float Lib1Func();
diff --git a/Tests/SimpleInstall/lib2.cxx b/Tests/SimpleInstall/lib2.cxx
new file mode 100644
index 0000000000..dccc48b789
--- /dev/null
+++ b/Tests/SimpleInstall/lib2.cxx
@@ -0,0 +1,6 @@
+#include "lib2.h"
+
+float Lib2Func()
+{
+ return 1.0;
+}
diff --git a/Tests/SimpleInstall/lib2.h b/Tests/SimpleInstall/lib2.h
new file mode 100644
index 0000000000..d69b786131
--- /dev/null
+++ b/Tests/SimpleInstall/lib2.h
@@ -0,0 +1,11 @@
+#ifdef _WIN32
+# ifdef test2_EXPORTS
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+# else
+# define CM_TEST_LIB_EXPORT __declspec( dllimport )
+# endif
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+
+CM_TEST_LIB_EXPORT float Lib2Func();
diff --git a/Tests/SimpleInstall/lib3.cxx b/Tests/SimpleInstall/lib3.cxx
new file mode 100644
index 0000000000..da8dbf942c
--- /dev/null
+++ b/Tests/SimpleInstall/lib3.cxx
@@ -0,0 +1,6 @@
+#include "lib3.h"
+
+float Lib3Func()
+{
+ return 2.0;
+}
diff --git a/Tests/SimpleInstall/lib3.h b/Tests/SimpleInstall/lib3.h
new file mode 100644
index 0000000000..66bc52a7fc
--- /dev/null
+++ b/Tests/SimpleInstall/lib3.h
@@ -0,0 +1,11 @@
+#ifdef _WIN32
+# ifdef test3_EXPORTS
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+# else
+# define CM_TEST_LIB_EXPORT __declspec( dllimport )
+# endif
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+
+CM_TEST_LIB_EXPORT float Lib3Func();
diff --git a/Tests/SimpleInstall/lib4.cxx b/Tests/SimpleInstall/lib4.cxx
new file mode 100644
index 0000000000..fbfa23aa43
--- /dev/null
+++ b/Tests/SimpleInstall/lib4.cxx
@@ -0,0 +1,7 @@
+#include "lib4.h"
+
+float Lib4Func()
+{
+ return 4.0;
+}
+
diff --git a/Tests/SimpleInstall/lib4.h b/Tests/SimpleInstall/lib4.h
new file mode 100644
index 0000000000..11c127247b
--- /dev/null
+++ b/Tests/SimpleInstall/lib4.h
@@ -0,0 +1,12 @@
+#ifdef _WIN32
+# ifdef test4_EXPORTS
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+# else
+# define CM_TEST_LIB_EXPORT __declspec( dllimport )
+# endif
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+
+CM_TEST_LIB_EXPORT float Lib4Func();
+
diff --git a/Tests/SimpleInstall/scripts/.gitattributes b/Tests/SimpleInstall/scripts/.gitattributes
new file mode 100644
index 0000000000..5e3db2fb3a
--- /dev/null
+++ b/Tests/SimpleInstall/scripts/.gitattributes
@@ -0,0 +1 @@
+sample_script crlf=input
diff --git a/Tests/SimpleInstall/scripts/CMakeLists.txt b/Tests/SimpleInstall/scripts/CMakeLists.txt
new file mode 100644
index 0000000000..ec34e8c500
--- /dev/null
+++ b/Tests/SimpleInstall/scripts/CMakeLists.txt
@@ -0,0 +1 @@
+install_programs(/MyTest/share/old3 "^sample_script(\\.bat)?$")
diff --git a/Tests/SimpleInstall/scripts/sample_script b/Tests/SimpleInstall/scripts/sample_script
new file mode 100755
index 0000000000..81f9f53153
--- /dev/null
+++ b/Tests/SimpleInstall/scripts/sample_script
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "Sample Script Output"
diff --git a/Tests/SimpleInstall/scripts/sample_script.bat b/Tests/SimpleInstall/scripts/sample_script.bat
new file mode 100755
index 0000000000..64a77b5b0f
--- /dev/null
+++ b/Tests/SimpleInstall/scripts/sample_script.bat
@@ -0,0 +1 @@
+@echo Sample Script Output
diff --git a/Tests/SimpleInstallS2/CMakeLists.txt b/Tests/SimpleInstallS2/CMakeLists.txt
new file mode 100644
index 0000000000..cc3c3be61d
--- /dev/null
+++ b/Tests/SimpleInstallS2/CMakeLists.txt
@@ -0,0 +1,395 @@
+cmake_minimum_required (VERSION 2.6)
+project (TestSimpleInstall)
+set(CMAKE_VERBOSE_MAKEFILE 1)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
+ "${TestSimpleInstall_BINARY_DIR}/bin")
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
+ "${TestSimpleInstall_BINARY_DIR}/lib/static")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
+ "${TestSimpleInstall_BINARY_DIR}/lib")
+
+# Skip generating the rpath pointing at the build tree to make sure
+# the executable is installed with the proper rpath in the install
+# tree.
+set(CMAKE_SKIP_BUILD_RPATH 1)
+
+# Make sure the executable can run from the install tree.
+set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+
+# Skip the dependency that causes a build when installing. This
+# avoids infinite loops when the post-build rule below installs.
+set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY 1)
+set(CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY 1)
+
+set(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
+
+set(EXTRA_INSTALL_FLAGS)
+message("Extra install: ${EXTRA_INSTALL_FLAGS}")
+
+if(STAGE2)
+ set(LIBPATHS
+ ${CMAKE_INSTALL_PREFIX}/MyTest/lib/static
+ ${CMAKE_INSTALL_PREFIX}/MyTest/lib
+ )
+ set(t1NAMES test1 test1${CMAKE_DEBUG_POSTFIX} test1rel)
+ set(t2NAMES test2 test2${CMAKE_DEBUG_POSTFIX})
+ set(t4NAMES test4out test4out${CMAKE_DEBUG_POSTFIX})
+
+ # Make sure the install script ran.
+ set(CMAKE_INSTALL_SCRIPT_DID_RUN 0)
+ include(${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake OPTIONAL)
+ if(CMAKE_INSTALL_SCRIPT_DID_RUN)
+ message(STATUS "Stage 1 did run install script 2.")
+ else()
+ message(SEND_ERROR "Stage 1 did not run install script 2.")
+ endif()
+
+ if(CYGWIN OR MINGW)
+ set(LIBPATHS ${LIBPATHS} "${CMAKE_INSTALL_PREFIX}/MyTest/bin")
+ endif()
+ message("Search for library in: ${LIBPATHS}")
+
+ set(TEST1_LIBRARY "TEST1_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
+ set(TEST2_LIBRARY "TEST2_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
+ set(TEST4_LIBRARY "TEST4_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
+
+ find_library(TEST1_LIBRARY
+ NAMES ${t1NAMES}
+ PATHS ${LIBPATHS}
+ DOC "First library")
+ find_library(TEST2_LIBRARY
+ NAMES ${t2NAMES}
+ PATHS ${LIBPATHS}
+ DOC "Second library")
+ find_library(TEST4_LIBRARY
+ NAMES ${t4NAMES}
+ PATHS ${LIBPATHS}
+ DOC "Fourth library")
+
+ # Test importing a library found on disk.
+ add_library(lib_test4 UNKNOWN IMPORTED)
+ set_property(TARGET lib_test4 PROPERTY IMPORTED_LOCATION ${TEST4_LIBRARY})
+
+ include_directories(${CMAKE_INSTALL_PREFIX}/MyTest/include)
+ add_executable (SimpleInstExeS2 inst2.cxx foo.c foo.h)
+ target_link_libraries(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} lib_test4)
+ set(install_target SimpleInstExeS2)
+
+ if("${TEST1_LIBRARY}" MATCHES "static")
+ message(STATUS "test1 correctly found in lib/static")
+ else()
+ message(SEND_ERROR "test1 not found in lib/static!")
+ endif()
+
+ # Check for failure of configuration-specific installation.
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
+ message(FATAL_ERROR "Debug-configuration file installed for Release!")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
+ message(FATAL_ERROR "Release-configuration file installed for Debug!")
+ endif()
+
+ # Check for failure of directory installation.
+ if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
+ message(FATAL_ERROR "Directory installation did not install TSD.h")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
+ message(FATAL_ERROR "Directory installation installed CVS directory.")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
+ message(FATAL_ERROR "Directory installation installed CVS directory.")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
+ message(FATAL_ERROR "Directory installation installed CMakeLists.txt.")
+ endif()
+ if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.h")
+ message(FATAL_ERROR "Directory installation did not install alternate TSD.h")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.cxx")
+ message(FATAL_ERROR "Directory installation installed alternate TSD.cxx")
+ endif()
+
+ # Check that scripts properly installed.
+ if(WIN32 AND NOT CYGWIN)
+ set(BAT .bat)
+ else()
+ set(BAT)
+ endif()
+ foreach(loc share share/old1 share/old2 share/old3 share/alt)
+ set(CUR_SCRIPT "${CMAKE_INSTALL_PREFIX}/MyTest/${loc}/sample_script${BAT}")
+ execute_process(
+ COMMAND ${CUR_SCRIPT}
+ RESULT_VARIABLE SAMPLE_SCRIPT_RESULT
+ OUTPUT_VARIABLE SAMPLE_SCRIPT_OUTPUT
+ )
+ if(NOT "${SAMPLE_SCRIPT_RESULT}" STREQUAL "0")
+ message(FATAL_ERROR
+ "Sample script [${CUR_SCRIPT}] failed: [${SAMPLE_SCRIPT_RESULT}]")
+ endif()
+ if(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
+ message(FATAL_ERROR
+ "Bad sample script [${CUR_SCRIPT}] output: [${SAMPLE_SCRIPT_OUTPUT}]")
+ endif()
+ endforeach()
+
+ # Check for failure of empty directory installation.
+ if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
+ message(FATAL_ERROR "Empty directory installation did not install.")
+ endif()
+ file(GLOB EMPTY_FILES "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty/*")
+ if(EMPTY_FILES)
+ message(FATAL_ERROR "Empty directory installed [${EMPTY_FILES}].")
+ endif()
+
+ # Make sure the test executable can run from the install tree.
+ set_target_properties(SimpleInstExeS2 PROPERTIES
+ INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+
+ install_targets(/MyTest/bin SimpleInstExeS2)
+
+# try to import the exported targets again
+ set(SimpleInstallS1_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+ find_package(SimpleInstallS1 REQUIRED)
+ get_target_property(simpleInstallImported S1_SimpleInstall IMPORTED)
+ if(NOT simpleInstallImported)
+ message(FATAL_ERROR "Target S1_SimpleInstall could not be imported")
+ endif()
+
+else()
+ # Wipe out the install directory to do a fresh test.
+ file(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/MyTest)
+
+ # this is stage 1, so create libraries and modules and install everything
+ add_library(test1 STATIC lib1.cxx)
+ add_library(test2 SHARED lib2.cxx)
+ add_library(test3 MODULE lib3.cxx)
+ add_library(test4 SHARED lib4.cxx)
+
+ # Test <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME properties.
+ set_property(TARGET test4 PROPERTY ARCHIVE_OUTPUT_NAME test4out)
+ set_property(TARGET test4 PROPERTY LIBRARY_OUTPUT_NAME test4out)
+
+ add_executable (SimpleInstall inst.cxx foo.c foo.h)
+ target_link_libraries(SimpleInstall test1 test2 test4)
+ set(install_target SimpleInstall)
+
+ set_target_properties(SimpleInstall PROPERTIES OUTPUT_NAME SimpleInstExe)
+ # Disable VERSION test until it is implemented in the Xcode generator.
+ if(NOT XCODE)
+ set_target_properties(SimpleInstall PROPERTIES VERSION 1.2)
+ endif()
+
+ # Make sure the test executable can run from the install tree.
+ set_target_properties(SimpleInstall PROPERTIES
+ INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+
+ # Test per-configuration output name.
+ set_target_properties(test1 PROPERTIES RELEASE_OUTPUT_NAME test1rel)
+ set_target_properties(test2 PROPERTIES PUBLIC_HEADER foo.h)
+
+ if(CMAKE_GENERATOR MATCHES "Makefiles")
+ add_subdirectory(TestSubDir)
+ add_dependencies(SimpleInstall TSD)
+ endif()
+
+ add_dependencies(SimpleInstall test3)
+ add_dependencies(test2 test3)
+ add_dependencies(test4 test2)
+
+ install(TARGETS SimpleInstall test1 test2 test3 EXPORT SimpleInstallS1
+ RUNTIME DESTINATION MyTest/bin COMPONENT Runtime # .exe, .dll
+ LIBRARY DESTINATION MyTest/lib COMPONENT Runtime # .so, mod.dll
+ ARCHIVE DESTINATION MyTest/lib/static COMPONENT Development # .a, .lib
+ PUBLIC_HEADER DESTINATION MyTest/include COMPONENT Development
+ )
+
+ install(TARGETS test4 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ RUNTIME DESTINATION MyTest/bin
+ LIBRARY DESTINATION MyTest/lib
+ ARCHIVE DESTINATION MyTest/lib/static
+ OPTIONAL # for coverage...target should always exist
+ )
+ install(FILES lib1.h DESTINATION MyTest/include/foo)
+ install(FILES lib2.h
+ DESTINATION MyTest/include/foo
+ COMPONENT Development
+ PERMISSIONS OWNER_READ OWNER_WRITE
+ RENAME lib2renamed.h
+ )
+
+ # Test old-style install commands.
+ install_files(/MyTest/include FILES lib3.h)
+ install_files(/MyTest/include/old .h lib3)
+ install_files(/MyTest/include/old "^lib2.h$")
+ install_programs(/MyTest/share/old1 FILES
+ scripts/sample_script scripts/sample_script.bat)
+ install_programs(/MyTest/share/old2
+ scripts/sample_script scripts/sample_script.bat)
+
+# "export" the targets collected in "SimpleInstallS1"
+ install(EXPORT SimpleInstallS1 FILE SimpleInstallS1Config.cmake
+ DESTINATION MyTest/lib
+ NAMESPACE S1_ )
+
+ export(TARGETS SimpleInstall test1 test2 test3
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/SimpleInstallS1Config.cmake"
+ NAMESPACE S2_ )
+
+ add_subdirectory(scripts)
+
+ # Test optional installation.
+ install(FILES does_not_exist.h DESTINATION MyTest/include/foo OPTIONAL)
+
+ # Test configuration-specific installation.
+ install(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
+ DESTINATION MyTest/include/Release
+ )
+ install(FILES lib1.h RENAME lib1debug.h CONFIGURATIONS Debug
+ DESTINATION MyTest/include/Debug
+ )
+
+ # Test directory installation.
+ file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
+ file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
+ install(
+ DIRECTORY TestSubDir scripts/ DESTINATION MyTest/share
+ FILE_PERMISSIONS OWNER_READ OWNER_WRITE
+ DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE
+ PATTERN "CVS" EXCLUDE
+ REGEX "\\.txt$" EXCLUDE
+ PATTERN "scripts/*" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
+ )
+
+ # Alternate directory installation for coverage.
+ install(
+ DIRECTORY scripts/ DESTINATION MyTest/share/alt
+ COMPONENT Development
+ USE_SOURCE_PERMISSIONS
+ PATTERN "CVS" EXCLUDE
+ REGEX "\\.txt$" EXCLUDE
+ )
+ install(
+ DIRECTORY TestSubDir DESTINATION MyTest/share/alt
+ FILE_PERMISSIONS OWNER_READ OWNER_WRITE
+ DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE
+ FILES_MATCHING PATTERN "*.h"
+ )
+
+ # Test empty directory installation.
+ install(DIRECTORY DESTINATION MyTest/share/empty)
+
+ # Test optional directory installation.
+ install(DIRECTORY does-not-exist DESTINATION MyTest/share OPTIONAL)
+
+ # Test user-specified install scripts, with and without COMPONENT.
+ install(
+ SCRIPT InstallScript1.cmake
+ CODE "set(INSTALL_CODE_DID_RUN 1)"
+ SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
+ )
+ install(
+ SCRIPT InstallScript3.cmake
+ CODE "set(INSTALL_CODE_WITH_COMPONENT_DID_RUN 1)"
+ SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript4.cmake
+ COMPONENT Development
+ )
+ set_directory_properties(PROPERTIES
+ ADDITIONAL_MAKE_CLEAN_FILES
+ "${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake;${CMAKE_INSTALL_PREFIX}/InstallScript4Out.cmake")
+
+ set_target_properties(SimpleInstall PROPERTIES PRE_INSTALL_SCRIPT
+ ${CMAKE_CURRENT_SOURCE_DIR}/PreInstall.cmake)
+ set_target_properties(SimpleInstall PROPERTIES POST_INSTALL_SCRIPT
+ ${CMAKE_CURRENT_SOURCE_DIR}/PostInstall.cmake)
+ set_target_properties(test4 PROPERTIES VERSION 1.2 SOVERSION 3
+ INSTALL_NAME_DIR @executable_path/../lib)
+endif()
+
+if(CMAKE_CONFIGURATION_TYPES)
+ set(SI_CONFIG --config $<CONFIGURATION>)
+else()
+ set(SI_CONFIG)
+endif()
+
+# Dummy test of CPack
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test of packaging with cpack")
+set(CPACK_PACKAGE_VENDOR "Kitware")
+set(CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/PackageScript.cmake")
+
+if(WIN32 AND NOT UNIX)
+ find_program(NSIS_MAKENSIS NAMES makensis
+ PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
+ DOC "Where is makensis.exe located"
+ )
+ if(NOT NSIS_MAKENSIS)
+ set(CPACK_GENERATOR TGZ)
+ endif()
+endif()
+if(UNIX AND NOT APPLE)
+ set(CPACK_GENERATOR "TGZ;STGZ;TZ")
+ # find_program(found_compress
+ # NAMES compress)
+ # if(found_compress)
+ # find_program(file_command NAMES file)
+ # if(NOT file_command)
+ # set(file_command file)
+ # endif()
+ # execute_process(COMMAND ${file_command} ${found_compress}
+ # OUTPUT_VARIABLE output)
+ # set(SKIP_TZ FALSE)
+ # if("${output}" MATCHES "script")
+ # set(SKIP_TZ TRUE)
+ # endif()
+ # if("${output}" MATCHES "dummy.sh")
+ # set(SKIP_TZ TRUE)
+ # endif()
+ # if(NOT SKIP_TZ)
+ # message("compress found and it was not a script")
+ # message("output from file command: [${output}]")
+ # set(CPACK_GENERATOR "${CPACK_GENERATOR};TZ")
+ # else()
+ # message("compress found, but it was a script so dont use it")
+ # message("output from file command: [${output}]")
+ # endif()
+ # endif()
+ find_program(found_bz2
+ NAMES bzip2)
+ if(found_bz2)
+ set(CPACK_GENERATOR "${CPACK_GENERATOR};TBZ2")
+ endif()
+endif()
+
+set(CPACK_PACKAGE_EXECUTABLES "SimpleInstall" "Simple Install")
+set(CMAKE_INSTALL_MFC_LIBRARIES 1)
+set(CMAKE_INSTALL_DEBUG_LIBRARIES 1)
+include(InstallRequiredSystemLibraries)
+
+if(CTEST_TEST_CPACK)
+ set(package_command COMMAND
+ ${CMAKE_COMMAND} --build . --target package ${SI_CONFIG}
+ )
+
+ # Avoid settings that require the .zip file command line tools...
+ # (just build an NSIS installer without component support)
+ #
+ set(CPACK_BINARY_ZIP OFF)
+ set(CPACK_MONOLITHIC_INSTALL ON)
+else()
+ set(package_command)
+endif()
+
+include(CPack)
+
+set(install_command COMMAND
+ ${CMAKE_COMMAND} --build . --target install ${SI_CONFIG}
+ )
+
+add_custom_command(
+ TARGET ${install_target}
+ POST_BUILD
+ ${install_command}
+ ${package_command}
+ COMMENT "Install Project"
+ )
diff --git a/Tests/SimpleInstallS2/InstallScript1.cmake b/Tests/SimpleInstallS2/InstallScript1.cmake
new file mode 100644
index 0000000000..ef9da5761c
--- /dev/null
+++ b/Tests/SimpleInstallS2/InstallScript1.cmake
@@ -0,0 +1,5 @@
+message("This is install script 1.")
+set(INSTALL_SCRIPT_1_DID_RUN 1)
+if(INSTALL_CODE_DID_RUN)
+ message(FATAL_ERROR "Install script 1 did not run before install code.")
+endif()
diff --git a/Tests/SimpleInstallS2/InstallScript2.cmake b/Tests/SimpleInstallS2/InstallScript2.cmake
new file mode 100644
index 0000000000..c1d20a3a67
--- /dev/null
+++ b/Tests/SimpleInstallS2/InstallScript2.cmake
@@ -0,0 +1,14 @@
+message("This is install script 2.")
+if(INSTALL_SCRIPT_1_DID_RUN)
+ message("Install script ordering works.")
+else()
+ message(FATAL_ERROR "Install script 1 did not run before install script 2.")
+endif()
+if(INSTALL_CODE_DID_RUN)
+ message("Install code ordering works.")
+else()
+ message(FATAL_ERROR "Install script 2 did not run after install code.")
+endif()
+file(WRITE "${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake"
+ "set(CMAKE_INSTALL_SCRIPT_DID_RUN 1)\n"
+ )
diff --git a/Tests/SimpleInstallS2/InstallScript3.cmake b/Tests/SimpleInstallS2/InstallScript3.cmake
new file mode 100644
index 0000000000..64851564d0
--- /dev/null
+++ b/Tests/SimpleInstallS2/InstallScript3.cmake
@@ -0,0 +1,12 @@
+message("This is install script 3.")
+set(INSTALL_SCRIPT_3_DID_RUN 1)
+if(INSTALL_CODE_WITH_COMPONENT_DID_RUN)
+ message(FATAL_ERROR "Install script 3 did not run before install code with component.")
+endif()
+
+if(CMAKE_INSTALL_COMPONENT)
+if(NOT "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Development")
+ message("CMAKE_INSTALL_COMPONENT=\"${CMAKE_INSTALL_COMPONENT}\"")
+ message(FATAL_ERROR "Install script 3 should only run for \"Development\" INSTALL COMPONENT.")
+endif()
+endif()
diff --git a/Tests/SimpleInstallS2/InstallScript4.cmake b/Tests/SimpleInstallS2/InstallScript4.cmake
new file mode 100644
index 0000000000..34d0a73bb8
--- /dev/null
+++ b/Tests/SimpleInstallS2/InstallScript4.cmake
@@ -0,0 +1,22 @@
+message("This is install script 4.")
+if(INSTALL_SCRIPT_3_DID_RUN)
+ message("Install script ordering works.")
+else()
+ message(FATAL_ERROR "Install script 3 did not run before install script 4.")
+endif()
+if(INSTALL_CODE_WITH_COMPONENT_DID_RUN)
+ message("Install code ordering works.")
+else()
+ message(FATAL_ERROR "Install script 4 did not run after install with component code.")
+endif()
+
+if(CMAKE_INSTALL_COMPONENT)
+if(NOT "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Development")
+ message("CMAKE_INSTALL_COMPONENT=\"${CMAKE_INSTALL_COMPONENT}\"")
+ message(FATAL_ERROR "Install script 4 should only run for \"Development\" INSTALL COMPONENT.")
+endif()
+endif()
+
+file(WRITE "${CMAKE_INSTALL_PREFIX}/MyTest/InstallScript4Out.cmake"
+ "set(CMAKE_INSTALL_SCRIPT_4_DID_RUN 1)\n"
+ )
diff --git a/Tests/SimpleInstallS2/PackageScript.cmake b/Tests/SimpleInstallS2/PackageScript.cmake
new file mode 100644
index 0000000000..53b790932b
--- /dev/null
+++ b/Tests/SimpleInstallS2/PackageScript.cmake
@@ -0,0 +1,10 @@
+message("This is packaging script")
+message("It writes a file with all variables available in ${CMAKE_INSTALL_PREFIX}/AllVariables.txt")
+
+file(WRITE ${CMAKE_INSTALL_PREFIX}/AllVariables.txt "")
+get_cmake_property(res VARIABLES)
+foreach(var ${res})
+ file(APPEND ${CMAKE_INSTALL_PREFIX}/AllVariables.txt
+ "${var} \"${${var}}\"\n")
+endforeach()
+
diff --git a/Tests/SimpleInstallS2/PostInstall.cmake b/Tests/SimpleInstallS2/PostInstall.cmake
new file mode 100644
index 0000000000..d616221ef3
--- /dev/null
+++ b/Tests/SimpleInstallS2/PostInstall.cmake
@@ -0,0 +1,6 @@
+message("In post install")
+if(PRE_INSTALL_DID_RUN)
+ message("Pre and post install work fine")
+else()
+ message(FATAL_ERROR "Pre install did not run before post install")
+endif()
diff --git a/Tests/SimpleInstallS2/PreInstall.cmake b/Tests/SimpleInstallS2/PreInstall.cmake
new file mode 100644
index 0000000000..7a9851e1d8
--- /dev/null
+++ b/Tests/SimpleInstallS2/PreInstall.cmake
@@ -0,0 +1,2 @@
+message("This is in pre install")
+set(PRE_INSTALL_DID_RUN 1)
diff --git a/Tests/SimpleInstallS2/TestSubDir/CMakeLists.txt b/Tests/SimpleInstallS2/TestSubDir/CMakeLists.txt
new file mode 100644
index 0000000000..860e10425f
--- /dev/null
+++ b/Tests/SimpleInstallS2/TestSubDir/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_executable(TSD TSD.cxx TSD_utils.cxx)
+install_files(/MyTest/include FILES TSD.h)
+install_targets(/MyTest/bin TSD)
diff --git a/Tests/SimpleInstallS2/TestSubDir/TSD.cxx b/Tests/SimpleInstallS2/TestSubDir/TSD.cxx
new file mode 100644
index 0000000000..8fc38787ac
--- /dev/null
+++ b/Tests/SimpleInstallS2/TestSubDir/TSD.cxx
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+#include "TSD.h"
+
+int main()
+{
+ int res = TSD("TEST");
+ printf("Hello from TSD\n");
+ return res;
+}
diff --git a/Tests/SimpleInstallS2/TestSubDir/TSD.h b/Tests/SimpleInstallS2/TestSubDir/TSD.h
new file mode 100644
index 0000000000..6a3c1affaa
--- /dev/null
+++ b/Tests/SimpleInstallS2/TestSubDir/TSD.h
@@ -0,0 +1 @@
+int TSD(const char*);
diff --git a/Tests/SimpleInstallS2/TestSubDir/TSD_utils.cxx b/Tests/SimpleInstallS2/TestSubDir/TSD_utils.cxx
new file mode 100644
index 0000000000..0277f05aec
--- /dev/null
+++ b/Tests/SimpleInstallS2/TestSubDir/TSD_utils.cxx
@@ -0,0 +1,10 @@
+#include <string.h>
+
+int TSD(const char* foo)
+{
+ if ( strcmp(foo, "TEST") == 0 )
+ {
+ return 0;
+ }
+ return 1;
+}
diff --git a/Tests/SimpleInstallS2/foo.c b/Tests/SimpleInstallS2/foo.c
new file mode 100644
index 0000000000..45d5b2bf22
--- /dev/null
+++ b/Tests/SimpleInstallS2/foo.c
@@ -0,0 +1,6 @@
+char* foo = "Foo";
+
+int SomeFunctionInFoo()
+{
+ return 5;
+}
diff --git a/Tests/SimpleInstallS2/foo.h b/Tests/SimpleInstallS2/foo.h
new file mode 100644
index 0000000000..2708baffe9
--- /dev/null
+++ b/Tests/SimpleInstallS2/foo.h
@@ -0,0 +1,11 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char* foo;
+extern int SomeFunctionInFoo();
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/Tests/SimpleInstallS2/inst.cxx b/Tests/SimpleInstallS2/inst.cxx
new file mode 100644
index 0000000000..7f2962d00b
--- /dev/null
+++ b/Tests/SimpleInstallS2/inst.cxx
@@ -0,0 +1,37 @@
+#include "foo.h"
+
+#ifdef STAGE_2
+# include <foo/lib1.h>
+# include <foo/lib2renamed.h>
+# include <lib3.h>
+# include <old/lib2.h>
+# include <old/lib3.h>
+#else
+# include "lib1.h"
+# include "lib2.h"
+#endif
+
+#include "lib4.h"
+
+#include <stdio.h>
+
+int main ()
+{
+ if ( Lib1Func() != 2.0 )
+ {
+ printf("Problem with lib1\n");
+ return 1;
+ }
+ if ( Lib2Func() != 1.0 )
+ {
+ printf("Problem with lib2\n");
+ return 1;
+ }
+ if ( Lib4Func() != 4.0 )
+ {
+ printf("Problem with lib4\n");
+ return 1;
+ }
+ printf("The value of Foo: %s\n", foo);
+ return SomeFunctionInFoo()-5;
+}
diff --git a/Tests/SimpleInstallS2/inst2.cxx b/Tests/SimpleInstallS2/inst2.cxx
new file mode 100644
index 0000000000..c70b93af1d
--- /dev/null
+++ b/Tests/SimpleInstallS2/inst2.cxx
@@ -0,0 +1,2 @@
+#define STAGE_2
+#include "inst.cxx"
diff --git a/Tests/SimpleInstallS2/lib1.cxx b/Tests/SimpleInstallS2/lib1.cxx
new file mode 100644
index 0000000000..7aa905205f
--- /dev/null
+++ b/Tests/SimpleInstallS2/lib1.cxx
@@ -0,0 +1,6 @@
+#include "lib1.h"
+
+float Lib1Func()
+{
+ return 2.0;
+}
diff --git a/Tests/SimpleInstallS2/lib1.h b/Tests/SimpleInstallS2/lib1.h
new file mode 100644
index 0000000000..0d64e76bc4
--- /dev/null
+++ b/Tests/SimpleInstallS2/lib1.h
@@ -0,0 +1 @@
+extern float Lib1Func();
diff --git a/Tests/SimpleInstallS2/lib2.cxx b/Tests/SimpleInstallS2/lib2.cxx
new file mode 100644
index 0000000000..dccc48b789
--- /dev/null
+++ b/Tests/SimpleInstallS2/lib2.cxx
@@ -0,0 +1,6 @@
+#include "lib2.h"
+
+float Lib2Func()
+{
+ return 1.0;
+}
diff --git a/Tests/SimpleInstallS2/lib2.h b/Tests/SimpleInstallS2/lib2.h
new file mode 100644
index 0000000000..d69b786131
--- /dev/null
+++ b/Tests/SimpleInstallS2/lib2.h
@@ -0,0 +1,11 @@
+#ifdef _WIN32
+# ifdef test2_EXPORTS
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+# else
+# define CM_TEST_LIB_EXPORT __declspec( dllimport )
+# endif
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+
+CM_TEST_LIB_EXPORT float Lib2Func();
diff --git a/Tests/SimpleInstallS2/lib3.cxx b/Tests/SimpleInstallS2/lib3.cxx
new file mode 100644
index 0000000000..da8dbf942c
--- /dev/null
+++ b/Tests/SimpleInstallS2/lib3.cxx
@@ -0,0 +1,6 @@
+#include "lib3.h"
+
+float Lib3Func()
+{
+ return 2.0;
+}
diff --git a/Tests/SimpleInstallS2/lib3.h b/Tests/SimpleInstallS2/lib3.h
new file mode 100644
index 0000000000..66bc52a7fc
--- /dev/null
+++ b/Tests/SimpleInstallS2/lib3.h
@@ -0,0 +1,11 @@
+#ifdef _WIN32
+# ifdef test3_EXPORTS
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+# else
+# define CM_TEST_LIB_EXPORT __declspec( dllimport )
+# endif
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+
+CM_TEST_LIB_EXPORT float Lib3Func();
diff --git a/Tests/SimpleInstallS2/lib4.cxx b/Tests/SimpleInstallS2/lib4.cxx
new file mode 100644
index 0000000000..fbfa23aa43
--- /dev/null
+++ b/Tests/SimpleInstallS2/lib4.cxx
@@ -0,0 +1,7 @@
+#include "lib4.h"
+
+float Lib4Func()
+{
+ return 4.0;
+}
+
diff --git a/Tests/SimpleInstallS2/lib4.h b/Tests/SimpleInstallS2/lib4.h
new file mode 100644
index 0000000000..11c127247b
--- /dev/null
+++ b/Tests/SimpleInstallS2/lib4.h
@@ -0,0 +1,12 @@
+#ifdef _WIN32
+# ifdef test4_EXPORTS
+# define CM_TEST_LIB_EXPORT __declspec( dllexport )
+# else
+# define CM_TEST_LIB_EXPORT __declspec( dllimport )
+# endif
+#else
+# define CM_TEST_LIB_EXPORT
+#endif
+
+CM_TEST_LIB_EXPORT float Lib4Func();
+
diff --git a/Tests/SimpleInstallS2/scripts/.gitattributes b/Tests/SimpleInstallS2/scripts/.gitattributes
new file mode 100644
index 0000000000..5e3db2fb3a
--- /dev/null
+++ b/Tests/SimpleInstallS2/scripts/.gitattributes
@@ -0,0 +1 @@
+sample_script crlf=input
diff --git a/Tests/SimpleInstallS2/scripts/CMakeLists.txt b/Tests/SimpleInstallS2/scripts/CMakeLists.txt
new file mode 100644
index 0000000000..ec34e8c500
--- /dev/null
+++ b/Tests/SimpleInstallS2/scripts/CMakeLists.txt
@@ -0,0 +1 @@
+install_programs(/MyTest/share/old3 "^sample_script(\\.bat)?$")
diff --git a/Tests/SimpleInstallS2/scripts/sample_script b/Tests/SimpleInstallS2/scripts/sample_script
new file mode 100755
index 0000000000..81f9f53153
--- /dev/null
+++ b/Tests/SimpleInstallS2/scripts/sample_script
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "Sample Script Output"
diff --git a/Tests/SimpleInstallS2/scripts/sample_script.bat b/Tests/SimpleInstallS2/scripts/sample_script.bat
new file mode 100755
index 0000000000..64a77b5b0f
--- /dev/null
+++ b/Tests/SimpleInstallS2/scripts/sample_script.bat
@@ -0,0 +1 @@
+@echo Sample Script Output
diff --git a/Tests/SourceGroups/CMakeLists.txt b/Tests/SourceGroups/CMakeLists.txt
new file mode 100644
index 0000000000..6573c8241b
--- /dev/null
+++ b/Tests/SourceGroups/CMakeLists.txt
@@ -0,0 +1,35 @@
+cmake_minimum_required (VERSION 2.6)
+project(SourceGroups)
+
+# this is not really a test which can fail
+# it is more an example with several source_group()
+# commands.
+# The created projects have to be loaded manually
+# in Visual Studio/Xcode/Eclipse/...
+# to see whether the correct groups have been created.
+
+source_group(Base FILES main.c)
+
+# a sub group
+source_group(Base\\Sub1 FILES sub1/foo.c)
+
+# a sub sub group
+source_group(Base\\Sub1\\Sub2 FILES sub1/foobar.c)
+
+# a group with empty name
+source_group("" FILES foo.c)
+
+# a group, whose name consists only of the delimiter
+#should be handled the same way as an empty name
+source_group("\\" FILES baz.c)
+
+# a sub sub group whose last component has the same name
+# as an already existing group
+source_group(Base\\Sub1\\Base FILES bar.c)
+
+# a group without files, is currently not created
+source_group(EmptyGroup)
+
+
+add_executable(SourceGroups main.c bar.c foo.c sub1/foo.c sub1/foobar.c baz.c README.txt)
+
diff --git a/Tests/SourceGroups/README.txt b/Tests/SourceGroups/README.txt
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/Tests/SourceGroups/README.txt
@@ -0,0 +1 @@
+
diff --git a/Tests/SourceGroups/bar.c b/Tests/SourceGroups/bar.c
new file mode 100644
index 0000000000..a2fcad5e95
--- /dev/null
+++ b/Tests/SourceGroups/bar.c
@@ -0,0 +1,4 @@
+int barbar(void)
+{
+ return 2;
+}
diff --git a/Tests/SourceGroups/baz.c b/Tests/SourceGroups/baz.c
new file mode 100644
index 0000000000..477f4fa6e7
--- /dev/null
+++ b/Tests/SourceGroups/baz.c
@@ -0,0 +1,4 @@
+int baz(void)
+{
+ return 13;
+}
diff --git a/Tests/SourceGroups/foo.c b/Tests/SourceGroups/foo.c
new file mode 100644
index 0000000000..3bebc4d22d
--- /dev/null
+++ b/Tests/SourceGroups/foo.c
@@ -0,0 +1,4 @@
+int bar(void)
+{
+ return 42;
+}
diff --git a/Tests/SourceGroups/main.c b/Tests/SourceGroups/main.c
new file mode 100644
index 0000000000..212e64baaa
--- /dev/null
+++ b/Tests/SourceGroups/main.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+extern int foo(void);
+extern int bar(void);
+extern int foobar(void);
+extern int barbar(void);
+extern int baz(void);
+
+int main()
+{
+ printf("foo: %d bar: %d foobar: %d barbar: %d baz: %d\n", foo(), bar(), foobar(), barbar(), baz());
+ return 0;
+}
diff --git a/Tests/SourceGroups/sub1/foo.c b/Tests/SourceGroups/sub1/foo.c
new file mode 100644
index 0000000000..39912a7481
--- /dev/null
+++ b/Tests/SourceGroups/sub1/foo.c
@@ -0,0 +1,4 @@
+int foo(void)
+{
+ return 17;
+}
diff --git a/Tests/SourceGroups/sub1/foobar.c b/Tests/SourceGroups/sub1/foobar.c
new file mode 100644
index 0000000000..32588b5e1a
--- /dev/null
+++ b/Tests/SourceGroups/sub1/foobar.c
@@ -0,0 +1,4 @@
+int foobar(void)
+{
+ return 1477;
+}
diff --git a/Tests/SourcesProperty/CMakeLists.txt b/Tests/SourcesProperty/CMakeLists.txt
new file mode 100644
index 0000000000..6c99e00745
--- /dev/null
+++ b/Tests/SourcesProperty/CMakeLists.txt
@@ -0,0 +1,12 @@
+
+cmake_minimum_required(VERSION 3.0)
+
+project(SourcesProperty)
+
+add_library(iface INTERFACE)
+set_property(TARGET iface PROPERTY INTERFACE_SOURCES iface.cpp)
+
+add_executable(SourcesProperty main.cpp)
+target_link_libraries(SourcesProperty iface)
+
+set_property(TARGET SourcesProperty APPEND PROPERTY SOURCES prop.cpp)
diff --git a/Tests/SourcesProperty/iface.cpp b/Tests/SourcesProperty/iface.cpp
new file mode 100644
index 0000000000..e38ac3778b
--- /dev/null
+++ b/Tests/SourcesProperty/iface.cpp
@@ -0,0 +1,5 @@
+
+int iface()
+{
+ return 0;
+}
diff --git a/Tests/SourcesProperty/iface.h b/Tests/SourcesProperty/iface.h
new file mode 100644
index 0000000000..6da80a4edf
--- /dev/null
+++ b/Tests/SourcesProperty/iface.h
@@ -0,0 +1,4 @@
+
+int iface();
+
+int prop();
diff --git a/Tests/SourcesProperty/main.cpp b/Tests/SourcesProperty/main.cpp
new file mode 100644
index 0000000000..33a97f4bea
--- /dev/null
+++ b/Tests/SourcesProperty/main.cpp
@@ -0,0 +1,7 @@
+
+#include "iface.h"
+
+int main(int argc, char** argv)
+{
+ return iface() + prop();
+}
diff --git a/Tests/SourcesProperty/prop.cpp b/Tests/SourcesProperty/prop.cpp
new file mode 100644
index 0000000000..e343431751
--- /dev/null
+++ b/Tests/SourcesProperty/prop.cpp
@@ -0,0 +1,5 @@
+
+int prop()
+{
+ return 0;
+}
diff --git a/Tests/StagingPrefix/CMakeLists.txt b/Tests/StagingPrefix/CMakeLists.txt
new file mode 100644
index 0000000000..49ff7fee76
--- /dev/null
+++ b/Tests/StagingPrefix/CMakeLists.txt
@@ -0,0 +1,91 @@
+
+cmake_minimum_required(VERSION 2.8.12)
+project(StagingPrefix)
+
+# Wipe out the install tree
+add_custom_command(
+ OUTPUT ${CMAKE_BINARY_DIR}/CleanupProject
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/ConsumerBuild
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/ProducerBuild
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/stage
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/prefix
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/ignored
+ )
+add_custom_target(CleanupTarget ALL DEPENDS ${CMAKE_BINARY_DIR}/CleanupProject)
+set_property(
+ SOURCE ${CMAKE_BINARY_DIR}/CleanupProject
+ PROPERTY SYMBOLIC 1
+ )
+
+if(CMAKE_CONFIGURATION_TYPES)
+ set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
+else()
+ if(CMAKE_BUILD_TYPE)
+ set(NESTED_CONFIG_TYPE -C "${CMAKE_BUILD_TYPE}")
+ else()
+ set(NESTED_CONFIG_TYPE)
+ endif()
+endif()
+
+# Build and install the producer.
+add_custom_command(
+ OUTPUT ${CMAKE_BINARY_DIR}/ProducerProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
+ --build-and-test
+ ${CMAKE_SOURCE_DIR}/Producer
+ ${CMAKE_BINARY_DIR}/ProducerBuild
+ --build-noclean
+ --build-project Producer
+ --build-target install
+ --build-generator ${CMAKE_GENERATOR}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-options
+ -DCMAKE_VERBOSE_MAKEFILE=1
+ "-DCMAKE_STAGING_PREFIX=${CMAKE_BINARY_DIR}/stage"
+ "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/prefix"
+ VERBATIM
+ )
+
+add_custom_target(ProducerTarget ALL DEPENDS ${CMAKE_BINARY_DIR}/ProducerProject)
+add_dependencies(ProducerTarget CleanupTarget)
+set_property(
+ SOURCE ${CMAKE_BINARY_DIR}/ProducerProject
+ PROPERTY SYMBOLIC 1
+ )
+
+if(NOT WIN32)
+ file(WRITE
+ "${CMAKE_BINARY_DIR}/ignored/${CMAKE_BINARY_DIR}/stage/include/ignored.h"
+ "#define IGNORED\n"
+ )
+endif()
+
+# Build and install the consumer.
+add_custom_command(
+ OUTPUT ${CMAKE_BINARY_DIR}/ConsumerProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
+ --build-and-test
+ ${CMAKE_SOURCE_DIR}/Consumer
+ ${CMAKE_BINARY_DIR}/ConsumerBuild
+ --build-noclean
+ --build-project Consumer
+ --build-target install
+ --build-generator ${CMAKE_GENERATOR}
+ --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
+ --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
+ --build-options
+ "-DCMAKE_FIND_ROOT_PATH=${CMAKE_BINARY_DIR}/ignored"
+ "-DCMAKE_STAGING_PREFIX=${CMAKE_BINARY_DIR}/stage"
+ -DCMAKE_VERBOSE_MAKEFILE=1
+ VERBATIM
+ )
+add_custom_target(ConsumerTarget ALL DEPENDS ${CMAKE_BINARY_DIR}/ConsumerProject)
+add_dependencies(ConsumerTarget ProducerTarget)
+set_property(
+ SOURCE ${CMAKE_BINARY_DIR}/ConsumerProject
+ PROPERTY SYMBOLIC 1
+ )
+
+add_executable(StagingPrefix main.cpp)
+add_dependencies(StagingPrefix ConsumerTarget)
diff --git a/Tests/StagingPrefix/Consumer/CMakeLists.txt b/Tests/StagingPrefix/Consumer/CMakeLists.txt
new file mode 100644
index 0000000000..a230441e64
--- /dev/null
+++ b/Tests/StagingPrefix/Consumer/CMakeLists.txt
@@ -0,0 +1,22 @@
+
+cmake_minimum_required (VERSION 2.8.12)
+project(Consumer)
+
+
+add_executable(executable main.cpp)
+find_package(Foo CONFIG REQUIRED)
+target_link_libraries(executable Foo::foo)
+
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
+find_package(Bar MODULE REQUIRED)
+include_directories(${Bar_INCLUDE_DIRS})
+target_link_libraries(executable ${Bar_LIBRARIES})
+
+install(TARGETS executable DESTINATION bin)
+
+if(NOT WIN32)
+ find_path(IGNORED_INCLUDE_DIR ignored.h)
+ if (IGNORED_INCLUDE_DIR)
+ message(SEND_ERROR "Should not find this file. The search path should be excluded.")
+ endif()
+endif()
diff --git a/Tests/StagingPrefix/Consumer/cmake/FindBar.cmake b/Tests/StagingPrefix/Consumer/cmake/FindBar.cmake
new file mode 100644
index 0000000000..29e4478aed
--- /dev/null
+++ b/Tests/StagingPrefix/Consumer/cmake/FindBar.cmake
@@ -0,0 +1,6 @@
+
+find_path(_inc_prefix bar.h PATH_SUFFIXES bar)
+set(Bar_INCLUDE_DIRS ${_inc_prefix})
+
+find_library(Bar_LIBRARY bar)
+set(Bar_LIBRARIES ${Bar_LIBRARY})
diff --git a/Tests/StagingPrefix/Consumer/main.cpp b/Tests/StagingPrefix/Consumer/main.cpp
new file mode 100644
index 0000000000..612ee05a91
--- /dev/null
+++ b/Tests/StagingPrefix/Consumer/main.cpp
@@ -0,0 +1,10 @@
+
+#include "foo.h"
+#include "bar.h"
+
+int main(int, char **)
+{
+ Foo f;
+ Bar b;
+ return f.foo() + b.bar();
+}
diff --git a/Tests/StagingPrefix/Producer/CMakeLists.txt b/Tests/StagingPrefix/Producer/CMakeLists.txt
new file mode 100644
index 0000000000..eb3d98f2e6
--- /dev/null
+++ b/Tests/StagingPrefix/Producer/CMakeLists.txt
@@ -0,0 +1,26 @@
+
+cmake_minimum_required (VERSION 2.8.12)
+project(Producer)
+
+add_library(foo SHARED foo.cpp)
+
+install(TARGETS foo EXPORT fooTargets
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+ INCLUDES DESTINATION include/foo
+)
+install(FILES foo.h DESTINATION include/foo)
+install(EXPORT fooTargets
+ FILE FooConfig.cmake
+ NAMESPACE Foo::
+ DESTINATION lib/cmake/Foo
+)
+
+add_library(bar SHARED bar.cpp)
+install(TARGETS bar
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+)
+install(FILES bar.h DESTINATION include/bar)
diff --git a/Tests/StagingPrefix/Producer/bar.cpp b/Tests/StagingPrefix/Producer/bar.cpp
new file mode 100644
index 0000000000..6bb8abecd6
--- /dev/null
+++ b/Tests/StagingPrefix/Producer/bar.cpp
@@ -0,0 +1,7 @@
+
+#include "bar.h"
+
+int Bar::bar()
+{
+ return 0;
+}
diff --git a/Tests/StagingPrefix/Producer/bar.h b/Tests/StagingPrefix/Producer/bar.h
new file mode 100644
index 0000000000..acd1fae023
--- /dev/null
+++ b/Tests/StagingPrefix/Producer/bar.h
@@ -0,0 +1,10 @@
+
+class
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+Bar
+{
+public:
+ int bar();
+};
diff --git a/Tests/StagingPrefix/Producer/foo.cpp b/Tests/StagingPrefix/Producer/foo.cpp
new file mode 100644
index 0000000000..64ad7cd0ee
--- /dev/null
+++ b/Tests/StagingPrefix/Producer/foo.cpp
@@ -0,0 +1,7 @@
+
+#include "foo.h"
+
+int Foo::foo()
+{
+ return 0;
+}
diff --git a/Tests/StagingPrefix/Producer/foo.h b/Tests/StagingPrefix/Producer/foo.h
new file mode 100644
index 0000000000..614093db8b
--- /dev/null
+++ b/Tests/StagingPrefix/Producer/foo.h
@@ -0,0 +1,10 @@
+
+class
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+Foo
+{
+public:
+ int foo();
+};
diff --git a/Tests/StagingPrefix/main.cpp b/Tests/StagingPrefix/main.cpp
new file mode 100644
index 0000000000..341aaafa0a
--- /dev/null
+++ b/Tests/StagingPrefix/main.cpp
@@ -0,0 +1,5 @@
+
+int main(int, char **)
+{
+ return 0;
+}
diff --git a/Tests/StringFileTest/CMakeLists.txt b/Tests/StringFileTest/CMakeLists.txt
new file mode 100644
index 0000000000..e6c61522d0
--- /dev/null
+++ b/Tests/StringFileTest/CMakeLists.txt
@@ -0,0 +1,291 @@
+cmake_minimum_required (VERSION 2.6)
+project(StringFileTest)
+include_directories(${StringFileTest_BINARY_DIR})
+
+# Read file test
+file(READ "${CMAKE_CURRENT_SOURCE_DIR}/InputFile.h.in" infile)
+
+# Test reading a binary file into hex representation
+file(READ "${CMAKE_CURRENT_SOURCE_DIR}/test.bin" hexContents HEX)
+
+if("${hexContents}" STREQUAL "0001027700")
+ message("file(READ HEX) correctly read [${hexContents}]")
+else()
+ message(SEND_ERROR "file(READ HEX) incorrectly read [${hexContents}], but expected was [0001027700]")
+endif()
+
+# file(STRINGS) test
+file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/InputFile.h.in" infile_strings
+ LIMIT_COUNT 1 LIMIT_INPUT 1024 LIMIT_OUTPUT 1024
+ LENGTH_MINIMUM 10 LENGTH_MAXIMUM 23 REGEX include NEWLINE_CONSUME)
+set(infile_strings_goal "#include \"includefile\"\n")
+if("${infile_strings}" STREQUAL "${infile_strings_goal}")
+ message("file(STRINGS) correctly read [${infile_strings}]")
+else()
+ message(SEND_ERROR
+ "file(STRINGS) incorrectly read [${infile_strings}]")
+endif()
+
+# test reading a file and getting its binary data as hex string
+file(READ "${CMAKE_CURRENT_SOURCE_DIR}/main.srec" infilehex LIMIT 4 HEX)
+if(NOT "${infilehex}" STREQUAL "53313036")
+ message(SEND_ERROR
+ "file(READ ... HEX) error, read: \"${infilehex}\", expected \"53313036\"")
+endif()
+
+
+# test that file(STRINGS) also work with Intel hex and Motorola S-record files
+# this file has been created with "sdcc main.c"
+file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/main.ihx" infile_strings REGEX INFO)
+set(infile_strings_goal "INFO:compiler\\[SDCC-HEX\\]")
+if("${infile_strings}" MATCHES "${infile_strings_goal}")
+ message("file(STRINGS) correctly read from hex file [${infile_strings}]")
+else()
+ message(SEND_ERROR
+ "file(STRINGS) incorrectly read from hex file [${infile_strings}]")
+endif()
+
+# this file has been created with "sdcc main.c --out-fmt-s19"
+file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/main.srec" infile_strings REGEX INFO)
+set(infile_strings_goal "INFO:compiler\\[SDCC-SREC\\]")
+if("${infile_strings}" MATCHES "${infile_strings_goal}")
+ message("file(STRINGS) correctly read from srec file [${infile_strings}]")
+else()
+ message(SEND_ERROR
+ "file(STRINGS) incorrectly read from srec file [${infile_strings}]")
+endif()
+
+#this file has utf-8 content
+file(STRINGS test.utf8 infile_strings ENCODING UTF-8)
+list(LENGTH infile_strings content_len)
+if(content_len MATCHES "3")
+ message("file(STRINGS) correctly read from utf8 file [${infile_strings}]")
+else()
+ message(SEND_ERROR
+ "file(STRINGS) incorrectly read from utf8 file [${infile_strings}]")
+endif()
+
+# String test
+string(REGEX MATCH "[cC][mM][aA][kK][eE]" rmvar "CMake is great")
+string(REGEX MATCHALL "[cC][mM][aA][kK][eE]" rmallvar "CMake is better than cmake or CMake")
+string(REGEX REPLACE "[Aa][uU][tT][oO]([cC][oO][nN][fF]|[mM][aA][kK][eE])"
+ "CMake" rrepvar "People should use Autoconf and Automake")
+string(COMPARE EQUAL "CMake" "Autoconf" nceqvar)
+string(COMPARE EQUAL "CMake" "CMake" ceqvar)
+string(COMPARE NOTEQUAL "CMake" "Autoconf" cneqvar)
+string(COMPARE NOTEQUAL "CMake" "CMake" ncneqvar)
+string(COMPARE LESS "before" "after" nclvar)
+string(COMPARE LESS "max" "min" clvar)
+string(COMPARE GREATER "before" "after" cgvar)
+string(COMPARE GREATER "max" "min" ncgvar)
+string(ASCII 67 109 97 107 101 savar)
+string(TOUPPER "CMake" tuvar)
+string(TOLOWER "CMake" tlvar)
+string(REPLACE "Autoconf" "CMake" repvar "People should use Autoconf")
+
+if("abc" STREQUAL "xyz")
+ message(SEND_ERROR "Problem with the if(STREQUAL), \"abc\" and \"xyz\" considered equal")
+endif()
+
+if("CMake is cool" MATCHES "(CMake) (is).+")
+ if(NOT "${CMAKE_MATCH_0}" STREQUAL "CMake is cool")
+ message(SEND_ERROR "CMAKE_MATCH_0 wrong: \"${CMAKE_MATCH_0}\", expected \"CMake is cool\"")
+ endif()
+ if(NOT "${CMAKE_MATCH_1}" STREQUAL "CMake")
+ message(SEND_ERROR "CMAKE_MATCH_1 wrong: \"${CMAKE_MATCH_1}\", expected \"CMake\"")
+ endif()
+ if(NOT "${CMAKE_MATCH_2}" STREQUAL "is")
+ message(SEND_ERROR "CMAKE_MATCH_2 wrong: \"${CMAKE_MATCH_2}\", expected \"is\"")
+ endif()
+else()
+ message(SEND_ERROR "Problem with the if(MATCHES), no match found")
+endif()
+
+string(REGEX MATCH "(People).+CMake" matchResultVar "People should use CMake")
+if(NOT "${matchResultVar}" STREQUAL "People should use CMake")
+ message(SEND_ERROR "string(REGEX MATCH) problem: \"${matchResultVar}\", expected \"People should use CMake\"")
+endif()
+if(NOT "${CMAKE_MATCH_0}" STREQUAL "People should use CMake")
+ message(SEND_ERROR "CMAKE_MATCH_0 wrong: \"${CMAKE_MATCH_0}\", expected \"People should use CMake\"")
+endif()
+if(NOT "${CMAKE_MATCH_1}" STREQUAL "People")
+ message(SEND_ERROR "CMAKE_MATCH_1 wrong: \"${CMAKE_MATCH_1}\", expected \"People\"")
+endif()
+if(NOT "${CMAKE_MATCH_2}" STREQUAL "")
+ message(SEND_ERROR "CMAKE_MATCH_2 wrong: \"${CMAKE_MATCH_2}\", expected empty string")
+endif()
+
+
+string(STRIP "
+ ST1
+ " ST1)
+string(STRIP "ST2 " ST2)
+string(STRIP " ST3" ST3)
+
+foreach(var ST1 ST2 ST3)
+ if("x${var}" STREQUAL "x${${var}}")
+ message("[${var}] == [${${var}}]")
+ else()
+ message(SEND_ERROR "Problem with the STRIP command for ${var}: [${${var}}]")
+ endif()
+endforeach()
+
+string(SUBSTRING "People should use Autoconf" 7 10 substringres)
+set(substringres "Everybody ${substringres} CMake")
+
+string(LENGTH ${substringres} lengthres)
+
+file(RELATIVE_PATH relpath "/usr/local/bin" "/usr/X11R6/bin/xnest")
+
+# Make-style unquoted argument test
+set(var $(VAR1)$(VAR2)/$(VAR3))
+message("Output: [${var}]")
+string(COMPARE EQUAL "${var}" "$(VAR1)$(VAR2)/$(VAR3)" result)
+if(NOT result)
+ message(SEND_ERROR "Unquoted $(VAR) syntax is broken.")
+endif()
+
+# Make directories test
+file(MAKE_DIRECTORY
+ "${CMAKE_CURRENT_BINARY_DIR}/Includes"
+ "${CMAKE_CURRENT_BINARY_DIR}/Directory1"
+ "${CMAKE_CURRENT_BINARY_DIR}/Directory2"
+ )
+
+# Write results to the file (test write file)
+set(file "${CMAKE_CURRENT_BINARY_DIR}/Includes/Values.h")
+file(WRITE "${file}" "/* this file is generated */\n")
+foreach(var
+ rmvar
+ rmallvar
+ rrepvar
+ repvar
+ relpath
+ substringres
+ lengthres
+ nceqvar
+ ceqvar
+ cneqvar
+ ncneqvar
+ nclvar
+ clvar
+ cgvar
+ ncgvar
+ savar
+ tuvar
+ tlvar)
+ file(APPEND "${file}" "#define ${var} \"${${var}}\"\n")
+endforeach()
+
+# Verify that the file was created recently.
+if(NOT "${file}" IS_NEWER_THAN "${CMAKE_CURRENT_SOURCE_DIR}/InputFile.h.in")
+ message(FATAL_ERROR "if(FILE_IS_NEWER) does not seem to work.")
+endif()
+
+# Test configuration of the string
+set(TEST_DEFINED 123)
+set(TEST_NOT_DEFINED)
+string(CONFIGURE "${infile}" infile+-/out @ONLY)
+set(infile "${infile+-/out}")
+
+# Write include file to a file
+string(REGEX REPLACE "includefile" "${file}" outfile "${infile}")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h-tmp" "${outfile}")
+file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h-tmp"
+ "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h")
+
+# Test file copy with relative paths
+file(COPY .
+ DESTINATION src
+ FILE_PERMISSIONS OWNER_READ # test no OWNER_WRITE
+ DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ FILES_MATCHING PATTERN *.cxx # Only copy the main source file
+ REGEX /src$ EXCLUDE # Block recursion for in-source build
+ )
+
+# Test file glob
+file(GLOB_RECURSE src_files "${CMAKE_CURRENT_SOURCE_DIR}/*")
+message("Files in ${CMAKE_CURRENT_SOURCE_DIR} are ${src_files}")
+set(expr "${CMAKE_CURRENT_BINARY_DIR}/src/[sS][!a-su-zA-Z0-9][^a-qs-zA-Z0-9]ing?ile*.cxx")
+message("Glob expression is [${expr}].")
+file(GLOB src_files "${expr}")
+message("Globbed files [${src_files}].")
+add_executable(StringFileTest ${src_files})
+
+set(expr "${CMAKE_CURRENT_SOURCE_DIR}/../*.cxx")
+file(GLOB_RECURSE rel_src_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/.." "${expr}")
+message("Globbed files [${rel_src_files}].")
+
+# Test FOREACH range
+message("Cheack if FOREACH with RANGE works")
+macro(TEST_RANGE ARGS CHECK)
+ set(r)
+ foreach(a RANGE ${ARGS})
+ set(r ${r} ${a})
+ endforeach()
+ message("FOREACH with RANGE ${ARGS} produces ${r}")
+ if("x${r}x" MATCHES "^x${CHECK}x$")
+ else()
+ message(SEND_ERROR "The range resulted in: ${r} should be ${CHECK}")
+ endif()
+endmacro()
+TEST_RANGE("5" "0;1;2;3;4;5")
+TEST_RANGE("3;5" "3;4;5")
+TEST_RANGE("5;3" "5;4;3")
+TEST_RANGE("3;10;2" "3;5;7;9")
+TEST_RANGE("10;0;-3" "10;7;4;1")
+
+# Test FOREACH IN signature
+set(list1 "" a "")
+set(list2 a "" b)
+set(var_)
+set(var_a)
+set(var_b)
+foreach(item IN LISTS list1 list2 ITEMS "" a "")
+ set(var_${item} "${var_${item}}x")
+endforeach()
+if(NOT "${var_}" STREQUAL "xxxxx")
+ message(FATAL_ERROR "count incorrect for \"\": [${var_}]")
+endif()
+if(NOT "${var_a}" STREQUAL "xxx")
+ message(FATAL_ERROR "count incorrect for \"a\": [${var_a}]")
+endif()
+if(NOT "${var_b}" STREQUAL "x")
+ message(FATAL_ERROR "count incorrect \"b\": [${var_b}]")
+endif()
+
+# Test SUBSTRING command
+set(ST_INPUTSTRING "0123456789")
+string(SUBSTRING ${ST_INPUTSTRING} 3 0 ST_EMPTY)
+string(SUBSTRING ${ST_INPUTSTRING} 1 1 ST_ONE)
+string(SUBSTRING ${ST_INPUTSTRING} 0 10 ST_ALL)
+string(SUBSTRING ${ST_INPUTSTRING} 0 -1 ST_ALL_MINUS)
+string(SUBSTRING ${ST_INPUTSTRING} 9 -1 ST_NINE)
+
+if(ST_EMPTY)
+ message(SEND_ERROR "SUBSTRING with length 0 does not return an empty string")
+endif()
+if(NOT ST_ONE STREQUAL "1")
+ message(SEND_ERROR "SUBSTING command does not cut the correct selected character, was \"" ${ST_ONE} "\", should be \"1\"")
+endif()
+if(NOT ST_INPUTSTRING STREQUAL ST_ALL)
+ message(SEND_ERROR "SUBSTRING does not return the whole string when selected with length")
+endif()
+if(NOT ST_INPUTSTRING STREQUAL ST_ALL_MINUS)
+ message(SEND_ERROR "SUBSTRING does not return the whole string when selected with -1")
+endif()
+if(NOT ST_NINE STREQUAL "9")
+ message(SEND_ERROR "SUBSTRING does not return the tail when selected with -1")
+endif()
+
+string(MAKE_C_IDENTIFIER "1one-two$" MCI_1)
+
+if(NOT MCI_1 STREQUAL _1one_two_)
+ message(SEND_ERROR "MAKE_C_IDENTIFIER did not create expected result.")
+endif()
+
+string(GENEX_STRIP "one;$<1:two;three>;four;$<TARGET_OBJECTS:some_target>" strip_result)
+
+if (NOT strip_result STREQUAL "one;four")
+ message(SEND_ERROR "GENEX_STRIP did not create expected result: ${strip_result}")
+endif()
diff --git a/Tests/StringFileTest/InputFile.h.in b/Tests/StringFileTest/InputFile.h.in
new file mode 100644
index 0000000000..0f01ccfc60
--- /dev/null
+++ b/Tests/StringFileTest/InputFile.h.in
@@ -0,0 +1,38 @@
+#include "includefile"
+
+/* This should be configured to a define. */
+#cmakedefine TEST_DEFINED @TEST_DEFINED@
+/* This should be configured to a commented undef with the curlies in place */
+#cmakedefine TEST_NOT_DEFINED ${TEST_NOT_DEFINED}
+
+/* This complicated line should be configured unchanged: */
+static const char* configvar =
+"@$@$junk =~ s/#$xyz#/$foo_bar{$wibble}->{$xyz}/;@@";
+
+int CheckMethod(const char* var, const char* val )
+{
+ if ( !var )
+ {
+ printf("Var not specified\n");
+ return 1;
+ }
+ if ( !val )
+ {
+ printf("Val not specified\n");
+ return 1;
+ }
+ if ( strcmp(var, val) != 0)
+ {
+ printf("Var (%s) and Val (%s) are not the same...\n", var, val);
+ return 1;
+ }
+#if !defined(TEST_DEFINED) || TEST_DEFINED != 123
+ printf("TEST_DEFINED is not defined to 123\n");
+ return 1;
+#elif defined(TEST_NOT_DEFINED)
+ printf("TEST_NOT_DEFINED is defined\n");
+ return 1;
+#else
+ return 0;
+#endif
+}
diff --git a/Tests/StringFileTest/StringFile.cxx b/Tests/StringFileTest/StringFile.cxx
new file mode 100644
index 0000000000..9eba6bff97
--- /dev/null
+++ b/Tests/StringFileTest/StringFile.cxx
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <string.h>
+#include "OutputFile.h"
+
+int main(int, char*[])
+{
+ int res = 0;
+
+ res += CheckMethod(rmvar, "CMake");
+ res += CheckMethod(rmallvar, "CMake;cmake;CMake");
+ res += CheckMethod(rrepvar, "People should use CMake and CMake");
+ res += CheckMethod(repvar, "People should use CMake");
+ res += CheckMethod(substringres, "Everybody should use CMake");
+ res += CheckMethod(nceqvar, "0");
+ res += CheckMethod(lengthres, "26");
+ res += CheckMethod(ceqvar, "1");
+ res += CheckMethod(cneqvar, "1");
+ res += CheckMethod(ncneqvar, "0");
+ res += CheckMethod(nclvar, "0");
+ res += CheckMethod(clvar, "1");
+ res += CheckMethod(cgvar, "1");
+ res += CheckMethod(ncgvar, "0");
+ res += CheckMethod(savar, "Cmake");
+ res += CheckMethod(tuvar, "CMAKE");
+ res += CheckMethod(tlvar, "cmake");
+ res += CheckMethod(relpath, "../../X11R6/bin/xnest");
+ res += CheckMethod(configvar,
+ "@$@$junk =~ s/#$xyz#/$foo_bar{$wibble}->{$xyz}/;@@");
+
+ return res;
+}
diff --git a/Tests/StringFileTest/main.ihx b/Tests/StringFileTest/main.ihx
new file mode 100644
index 0000000000..c1d1dd2b3d
--- /dev/null
+++ b/Tests/StringFileTest/main.ihx
@@ -0,0 +1,21 @@
+:03000000020003F8
+:03005C0002005F40
+:05005F0012006480FEA8
+:010064002279
+:0E006900494E464F3A636F6D70696C65725B6D
+:0A007700534443432D4845585D00F3
+:06003200E478FFF6D8FDA2
+:080010007900E94400601B7A4D
+:0500180000900081785A
+:03001D000075A0CB
+:0A00200000E493F2A308B800020503
+:08002A00A0D9F4DAF275A0FF81
+:080038007800E84400600A7939
+:030040000075A0A8
+:0600430000E4F309D8FC03
+:080049007800E84400600C7926
+:0B00510000900000E4F0A3D8FCD9FAF6
+:03000300758107FD
+:0A000600120065E582600302005F4E
+:04006500758200227E
+:00000001FF
diff --git a/Tests/StringFileTest/main.srec b/Tests/StringFileTest/main.srec
new file mode 100644
index 0000000000..bd47c29cc1
--- /dev/null
+++ b/Tests/StringFileTest/main.srec
@@ -0,0 +1,21 @@
+S1060000020003F4
+S106005C02005F3C
+S108005F12006480FEA4
+S10400642275
+S1110069494E464F3A636F6D70696C65725B69
+S10E0077534443432D535245435D00A6
+S1090032E478FFF6D8FD9E
+S10B00107900E94400601B7A49
+S1080018009000827855
+S106001D0075A0C7
+S10D002000E493F2A308B8000205FF
+S10B002AA0D9F4DAF275A0FF7D
+S10B00387800E84400600A7935
+S10600400075A0A4
+S109004300E4F309D8FCFF
+S10B00497800E84400600C7922
+S10E005100900000E4F0A3D8FCD9FAF2
+S1060003758107F9
+S10D0006120065E582600302005F4A
+S1070065758200227A
+S9030000FC
diff --git a/Tests/StringFileTest/test.bin b/Tests/StringFileTest/test.bin
new file mode 100644
index 0000000000..18d62a1446
--- /dev/null
+++ b/Tests/StringFileTest/test.bin
Binary files differ
diff --git a/Tests/StringFileTest/test.utf8 b/Tests/StringFileTest/test.utf8
new file mode 100644
index 0000000000..6c29170740
--- /dev/null
+++ b/Tests/StringFileTest/test.utf8
@@ -0,0 +1,3 @@
+The value of π (pi) is 3.141593
+Line mixed with binary partially matches valid utf8: Ï€ is à93.1593
+à \ No newline at end of file
diff --git a/Tests/SubDir/AnotherSubdir/pair+int.int.c b/Tests/SubDir/AnotherSubdir/pair+int.int.c
new file mode 100644
index 0000000000..b7a6237818
--- /dev/null
+++ b/Tests/SubDir/AnotherSubdir/pair+int.int.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_stuff()
+{
+ printf("Placeholder for a strange file in subdirectory\n");
+}
diff --git a/Tests/SubDir/AnotherSubdir/pair_int.int.c b/Tests/SubDir/AnotherSubdir/pair_int.int.c
new file mode 100644
index 0000000000..b7a6237818
--- /dev/null
+++ b/Tests/SubDir/AnotherSubdir/pair_int.int.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_stuff()
+{
+ printf("Placeholder for a strange file in subdirectory\n");
+}
diff --git a/Tests/SubDir/AnotherSubdir/secondone.c b/Tests/SubDir/AnotherSubdir/secondone.c
new file mode 100644
index 0000000000..3e9e5afe6b
--- /dev/null
+++ b/Tests/SubDir/AnotherSubdir/secondone.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void secondone()
+{
+ printf("Hello again\n");
+}
diff --git a/Tests/SubDir/AnotherSubdir/testfromsubdir.c b/Tests/SubDir/AnotherSubdir/testfromsubdir.c
new file mode 100644
index 0000000000..34b6e7a88d
--- /dev/null
+++ b/Tests/SubDir/AnotherSubdir/testfromsubdir.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+void secondone();
+void pair_stuff();
+void vcl_stuff();
+
+int main()
+{
+ printf("Hello from subdirectory\n");
+ secondone();
+ pair_stuff();
+ vcl_stuff();
+ return 0;
+}
diff --git a/Tests/SubDir/CMakeLists.txt b/Tests/SubDir/CMakeLists.txt
new file mode 100644
index 0000000000..6822e6bd9a
--- /dev/null
+++ b/Tests/SubDir/CMakeLists.txt
@@ -0,0 +1,46 @@
+cmake_minimum_required (VERSION 2.6)
+project(SUBDIR)
+subdirs(Executable EXCLUDE_FROM_ALL Examples)
+write_file(${SUBDIR_BINARY_DIR}/ShouldBeHere "This file should exist.")
+#WATCOM WMAKE does not support + in the name of a file!
+if(WATCOM)
+ set(PLUS_NAME_FILES
+ AnotherSubdir/pair_int.int.c
+ vcl_algorithm_vcl_pair_double.foo.c)
+else()
+ set(PLUS_NAME_FILES
+ AnotherSubdir/pair+int.int.c
+ vcl_algorithm+vcl_pair+double.foo.c)
+endif()
+
+add_executable(TestFromSubdir
+ AnotherSubdir/testfromsubdir.c
+ AnotherSubdir/secondone
+ ${PLUS_NAME_FILES}
+ )
+
+aux_source_directory(ThirdSubDir SOURCES)
+if(WATCOM)
+ foreach(f ${SOURCES})
+ if("${f}" STREQUAL "ThirdSubDir/pair+int.int1.c")
+ else()
+ set(SOURCES2 ${f} ${SOURCES2})
+ endif()
+ endforeach()
+ set(SOURCES ${SOURCES2})
+ set(SOURCES ${SOURCES}
+ vcl_algorithm_vcl_pair_double.foo.c)
+else()
+ foreach(f ${SOURCES})
+ if("${f}" STREQUAL "ThirdSubDir/pair_int.int1.c")
+ else()
+ set(SOURCES2 ${f} ${SOURCES2})
+ message("${f}")
+ endif()
+ endforeach()
+ set(SOURCES ${SOURCES2})
+ set(SOURCES ${SOURCES}
+ vcl_algorithm+vcl_pair+double.foo.c)
+endif()
+message("Sources: ${SOURCES}")
+add_executable(TestWithAuxSourceDir ${SOURCES})
diff --git a/Tests/SubDir/Examples/CMakeLists.txt b/Tests/SubDir/Examples/CMakeLists.txt
new file mode 100644
index 0000000000..8cd7e24e16
--- /dev/null
+++ b/Tests/SubDir/Examples/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required (VERSION 2.6)
+project(Examples)
+subdirs(example1 example2)
diff --git a/Tests/SubDir/Examples/example1/CMakeLists.txt b/Tests/SubDir/Examples/example1/CMakeLists.txt
new file mode 100644
index 0000000000..20d065e542
--- /dev/null
+++ b/Tests/SubDir/Examples/example1/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required (VERSION 2.6)
+project(example1)
+add_executable(example1 example1.cxx)
+
+add_custom_command(TARGET example1 POST_BUILD
+ COMMAND "${CMAKE_COMMAND}" ARGS -E remove ${SUBDIR_BINARY_DIR}/ShouldBeHere
+ COMMENT "Remove marker file that should exist because this should not be run")
diff --git a/Tests/SubDir/Examples/example1/example1.cxx b/Tests/SubDir/Examples/example1/example1.cxx
new file mode 100644
index 0000000000..3c4819415c
--- /dev/null
+++ b/Tests/SubDir/Examples/example1/example1.cxx
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("example1\n");
+ return 0;
+}
diff --git a/Tests/SubDir/Examples/example2/CMakeLists.txt b/Tests/SubDir/Examples/example2/CMakeLists.txt
new file mode 100644
index 0000000000..388e33c3d7
--- /dev/null
+++ b/Tests/SubDir/Examples/example2/CMakeLists.txt
@@ -0,0 +1,2 @@
+project(example2)
+add_executable(example2 example2.cxx)
diff --git a/Tests/SubDir/Examples/example2/example2.cxx b/Tests/SubDir/Examples/example2/example2.cxx
new file mode 100644
index 0000000000..60ef3c940e
--- /dev/null
+++ b/Tests/SubDir/Examples/example2/example2.cxx
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("example2\n");
+ return 0;
+}
diff --git a/Tests/SubDir/Executable/CMakeLists.txt b/Tests/SubDir/Executable/CMakeLists.txt
new file mode 100644
index 0000000000..77e6751cdb
--- /dev/null
+++ b/Tests/SubDir/Executable/CMakeLists.txt
@@ -0,0 +1 @@
+add_executable(test test.cxx)
diff --git a/Tests/SubDir/Executable/test.cxx b/Tests/SubDir/Executable/test.cxx
new file mode 100644
index 0000000000..c528fb1664
--- /dev/null
+++ b/Tests/SubDir/Executable/test.cxx
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef _WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+// return true if the file exists
+int FileExists(const char* filename)
+{
+#ifdef _MSC_VER
+# define access _access
+#endif
+#ifndef F_OK
+#define F_OK 0
+#endif
+ if ( access(filename, F_OK) != 0 )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+}
+
+
+int main(int ac, char** av)
+{
+ if(ac <= 1)
+ {
+ printf("Usage: %s <file>\n", av[0]);
+ return 1;
+ }
+ if(!FileExists(av[1]))
+ {
+ printf("Missing file %s\n", av[1]);
+ return 1;
+ }
+ if(FileExists(av[2]))
+ {
+ printf("File %s should be in subdirectory\n", av[2]);
+ return 1;
+ }
+ printf("%s is not there! Good.", av[2]);
+ printf("%s is there! Good.", av[1]);
+ return 0;
+}
diff --git a/Tests/SubDir/ThirdSubDir/pair+int.int1.c b/Tests/SubDir/ThirdSubDir/pair+int.int1.c
new file mode 100644
index 0000000000..b7a6237818
--- /dev/null
+++ b/Tests/SubDir/ThirdSubDir/pair+int.int1.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_stuff()
+{
+ printf("Placeholder for a strange file in subdirectory\n");
+}
diff --git a/Tests/SubDir/ThirdSubDir/pair_int.int1.c b/Tests/SubDir/ThirdSubDir/pair_int.int1.c
new file mode 100644
index 0000000000..b7a6237818
--- /dev/null
+++ b/Tests/SubDir/ThirdSubDir/pair_int.int1.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_stuff()
+{
+ printf("Placeholder for a strange file in subdirectory\n");
+}
diff --git a/Tests/SubDir/ThirdSubDir/pair_p_int.int1.c b/Tests/SubDir/ThirdSubDir/pair_p_int.int1.c
new file mode 100644
index 0000000000..95a66eee69
--- /dev/null
+++ b/Tests/SubDir/ThirdSubDir/pair_p_int.int1.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_p_stuff()
+{
+ printf("Placeholder for another strange file in subdirectory\n");
+}
diff --git a/Tests/SubDir/ThirdSubDir/testfromauxsubdir.c b/Tests/SubDir/ThirdSubDir/testfromauxsubdir.c
new file mode 100644
index 0000000000..d1620845f1
--- /dev/null
+++ b/Tests/SubDir/ThirdSubDir/testfromauxsubdir.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+void secondone();
+void pair_stuff();
+void pair_p_stuff();
+void vcl_stuff();
+
+int main()
+{
+ printf("Hello from subdirectory\n");
+ secondone();
+ pair_stuff();
+ pair_p_stuff();
+ vcl_stuff();
+ return 0;
+}
diff --git a/Tests/SubDir/ThirdSubDir/thirdone.c b/Tests/SubDir/ThirdSubDir/thirdone.c
new file mode 100644
index 0000000000..3e9e5afe6b
--- /dev/null
+++ b/Tests/SubDir/ThirdSubDir/thirdone.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void secondone()
+{
+ printf("Hello again\n");
+}
diff --git a/Tests/SubDir/vcl_algorithm+vcl_pair+double.foo.c b/Tests/SubDir/vcl_algorithm+vcl_pair+double.foo.c
new file mode 100644
index 0000000000..a0c60f75aa
--- /dev/null
+++ b/Tests/SubDir/vcl_algorithm+vcl_pair+double.foo.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void vcl_stuff()
+{
+ printf("Placeholder for a file with strange name\n");
+}
diff --git a/Tests/SubDir/vcl_algorithm_vcl_pair_double.foo.c b/Tests/SubDir/vcl_algorithm_vcl_pair_double.foo.c
new file mode 100644
index 0000000000..a0c60f75aa
--- /dev/null
+++ b/Tests/SubDir/vcl_algorithm_vcl_pair_double.foo.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void vcl_stuff()
+{
+ printf("Placeholder for a file with strange name\n");
+}
diff --git a/Tests/SubDirSpaces/Another Subdir/pair+int.int.c b/Tests/SubDirSpaces/Another Subdir/pair+int.int.c
new file mode 100644
index 0000000000..b7a6237818
--- /dev/null
+++ b/Tests/SubDirSpaces/Another Subdir/pair+int.int.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_stuff()
+{
+ printf("Placeholder for a strange file in subdirectory\n");
+}
diff --git a/Tests/SubDirSpaces/Another Subdir/pair_int.int.c b/Tests/SubDirSpaces/Another Subdir/pair_int.int.c
new file mode 100644
index 0000000000..b7a6237818
--- /dev/null
+++ b/Tests/SubDirSpaces/Another Subdir/pair_int.int.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_stuff()
+{
+ printf("Placeholder for a strange file in subdirectory\n");
+}
diff --git a/Tests/SubDirSpaces/Another Subdir/secondone.c b/Tests/SubDirSpaces/Another Subdir/secondone.c
new file mode 100644
index 0000000000..3e9e5afe6b
--- /dev/null
+++ b/Tests/SubDirSpaces/Another Subdir/secondone.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void secondone()
+{
+ printf("Hello again\n");
+}
diff --git a/Tests/SubDirSpaces/Another Subdir/testfromsubdir.c b/Tests/SubDirSpaces/Another Subdir/testfromsubdir.c
new file mode 100644
index 0000000000..34b6e7a88d
--- /dev/null
+++ b/Tests/SubDirSpaces/Another Subdir/testfromsubdir.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+void secondone();
+void pair_stuff();
+void vcl_stuff();
+
+int main()
+{
+ printf("Hello from subdirectory\n");
+ secondone();
+ pair_stuff();
+ vcl_stuff();
+ return 0;
+}
diff --git a/Tests/SubDirSpaces/CMakeLists.txt b/Tests/SubDirSpaces/CMakeLists.txt
new file mode 100644
index 0000000000..40c265e5f9
--- /dev/null
+++ b/Tests/SubDirSpaces/CMakeLists.txt
@@ -0,0 +1,77 @@
+cmake_minimum_required (VERSION 2.6)
+project(SUBDIR)
+
+# Some systems do not seem to support rpath with spaces.
+if(CMAKE_SYSTEM_NAME MATCHES "IRIX|QNX")
+ set(CMAKE_SKIP_BUILD_RPATH 1)
+endif()
+
+# be able to see output from make on dashboards
+set(CMAKE_VERBOSE_MAKEFILE 1)
+message("${CMAKE_MAKE_PROGRAM}")
+set(CMAKE_PAREN TRUE)
+if("${CMAKE_MAKE_PROGRAM}" MATCHES "wmake")
+ message("wmake does not support () in path")
+ set(CMAKE_PAREN FALSE)
+elseif("${CMAKE_MAKE_PROGRAM}" MATCHES "make")
+ execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} no_such_target --version
+ RESULT_VARIABLE res OUTPUT_VARIABLE out ERROR_VARIABLE out)
+ if("${out}" MATCHES "GNU Make 3.82")
+ # GNU Make 3.82 fails on parens: http://savannah.gnu.org/bugs/?30612
+ message(STATUS "GNU Make 3.82 sometimes fails on () in path")
+ set(CMAKE_PAREN FALSE)
+ endif()
+endif()
+
+if(CMAKE_PAREN)
+ add_definitions(-DCMAKE_PAREN=1)
+ subdirs("Executable Sources" "Some(x86) Sources" EXCLUDE_FROM_ALL "Some Examples")
+else()
+ subdirs("Executable Sources" EXCLUDE_FROM_ALL "Some Examples")
+endif()
+
+write_file(${SUBDIR_BINARY_DIR}/ShouldBeHere "This file should exist.")
+#WATCOM WMAKE does not support + in the name of a file!
+if(WATCOM)
+ set(PLUS_NAME_FILES
+ "Another Subdir/pair_int.int.c"
+ vcl_algorithm_vcl_pair_double.foo.c)
+else()
+ set(PLUS_NAME_FILES
+ "Another Subdir/pair+int.int.c"
+ vcl_algorithm+vcl_pair+double.foo.c)
+endif()
+
+add_executable(TestFromSubdir
+ "Another Subdir/testfromsubdir.c"
+ "Another Subdir/secondone"
+ ${PLUS_NAME_FILES}
+ )
+
+aux_source_directory(ThirdSubDir SOURCES)
+if(WATCOM)
+ foreach(f ${SOURCES})
+ if("${f}" STREQUAL "ThirdSubDir/pair+int.int1.c")
+ else()
+ set(SOURCES2 ${f} ${SOURCES2})
+ endif()
+ endforeach()
+ set(SOURCES ${SOURCES2})
+ set(SOURCES ${SOURCES}
+ vcl_algorithm_vcl_pair_double.foo.c)
+else()
+ foreach(f ${SOURCES})
+ if("${f}" STREQUAL "ThirdSubDir/pair_int.int1.c")
+ else()
+ set(SOURCES2 ${f} ${SOURCES2})
+ endif()
+ endforeach()
+ set(SOURCES ${SOURCES2})
+ set(SOURCES ${SOURCES}
+ vcl_algorithm+vcl_pair+double.foo.c)
+endif()
+add_executable(TestWithAuxSourceDir ${SOURCES})
+if(CMAKE_PAREN)
+ target_link_libraries(TestWithAuxSourceDir testOddPath)
+endif()
+
diff --git a/Tests/SubDirSpaces/Executable Sources/CMakeLists.txt b/Tests/SubDirSpaces/Executable Sources/CMakeLists.txt
new file mode 100644
index 0000000000..77e6751cdb
--- /dev/null
+++ b/Tests/SubDirSpaces/Executable Sources/CMakeLists.txt
@@ -0,0 +1 @@
+add_executable(test test.cxx)
diff --git a/Tests/SubDirSpaces/Executable Sources/test.cxx b/Tests/SubDirSpaces/Executable Sources/test.cxx
new file mode 100644
index 0000000000..c528fb1664
--- /dev/null
+++ b/Tests/SubDirSpaces/Executable Sources/test.cxx
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef _WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+// return true if the file exists
+int FileExists(const char* filename)
+{
+#ifdef _MSC_VER
+# define access _access
+#endif
+#ifndef F_OK
+#define F_OK 0
+#endif
+ if ( access(filename, F_OK) != 0 )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+}
+
+
+int main(int ac, char** av)
+{
+ if(ac <= 1)
+ {
+ printf("Usage: %s <file>\n", av[0]);
+ return 1;
+ }
+ if(!FileExists(av[1]))
+ {
+ printf("Missing file %s\n", av[1]);
+ return 1;
+ }
+ if(FileExists(av[2]))
+ {
+ printf("File %s should be in subdirectory\n", av[2]);
+ return 1;
+ }
+ printf("%s is not there! Good.", av[2]);
+ printf("%s is there! Good.", av[1]);
+ return 0;
+}
diff --git a/Tests/SubDirSpaces/Executable/CMakeLists.txt b/Tests/SubDirSpaces/Executable/CMakeLists.txt
new file mode 100644
index 0000000000..77e6751cdb
--- /dev/null
+++ b/Tests/SubDirSpaces/Executable/CMakeLists.txt
@@ -0,0 +1 @@
+add_executable(test test.cxx)
diff --git a/Tests/SubDirSpaces/Executable/test.cxx b/Tests/SubDirSpaces/Executable/test.cxx
new file mode 100644
index 0000000000..c528fb1664
--- /dev/null
+++ b/Tests/SubDirSpaces/Executable/test.cxx
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef _WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+// return true if the file exists
+int FileExists(const char* filename)
+{
+#ifdef _MSC_VER
+# define access _access
+#endif
+#ifndef F_OK
+#define F_OK 0
+#endif
+ if ( access(filename, F_OK) != 0 )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+}
+
+
+int main(int ac, char** av)
+{
+ if(ac <= 1)
+ {
+ printf("Usage: %s <file>\n", av[0]);
+ return 1;
+ }
+ if(!FileExists(av[1]))
+ {
+ printf("Missing file %s\n", av[1]);
+ return 1;
+ }
+ if(FileExists(av[2]))
+ {
+ printf("File %s should be in subdirectory\n", av[2]);
+ return 1;
+ }
+ printf("%s is not there! Good.", av[2]);
+ printf("%s is there! Good.", av[1]);
+ return 0;
+}
diff --git a/Tests/SubDirSpaces/Some Examples/CMakeLists.txt b/Tests/SubDirSpaces/Some Examples/CMakeLists.txt
new file mode 100644
index 0000000000..8cd7e24e16
--- /dev/null
+++ b/Tests/SubDirSpaces/Some Examples/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required (VERSION 2.6)
+project(Examples)
+subdirs(example1 example2)
diff --git a/Tests/SubDirSpaces/Some Examples/example1/CMakeLists.txt b/Tests/SubDirSpaces/Some Examples/example1/CMakeLists.txt
new file mode 100644
index 0000000000..20d065e542
--- /dev/null
+++ b/Tests/SubDirSpaces/Some Examples/example1/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required (VERSION 2.6)
+project(example1)
+add_executable(example1 example1.cxx)
+
+add_custom_command(TARGET example1 POST_BUILD
+ COMMAND "${CMAKE_COMMAND}" ARGS -E remove ${SUBDIR_BINARY_DIR}/ShouldBeHere
+ COMMENT "Remove marker file that should exist because this should not be run")
diff --git a/Tests/SubDirSpaces/Some Examples/example1/example1.cxx b/Tests/SubDirSpaces/Some Examples/example1/example1.cxx
new file mode 100644
index 0000000000..3c4819415c
--- /dev/null
+++ b/Tests/SubDirSpaces/Some Examples/example1/example1.cxx
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("example1\n");
+ return 0;
+}
diff --git a/Tests/SubDirSpaces/Some Examples/example2/CMakeLists.txt b/Tests/SubDirSpaces/Some Examples/example2/CMakeLists.txt
new file mode 100644
index 0000000000..388e33c3d7
--- /dev/null
+++ b/Tests/SubDirSpaces/Some Examples/example2/CMakeLists.txt
@@ -0,0 +1,2 @@
+project(example2)
+add_executable(example2 example2.cxx)
diff --git a/Tests/SubDirSpaces/Some Examples/example2/example2.cxx b/Tests/SubDirSpaces/Some Examples/example2/example2.cxx
new file mode 100644
index 0000000000..60ef3c940e
--- /dev/null
+++ b/Tests/SubDirSpaces/Some Examples/example2/example2.cxx
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("example2\n");
+ return 0;
+}
diff --git a/Tests/SubDirSpaces/Some(x86) Sources/CMakeLists.txt b/Tests/SubDirSpaces/Some(x86) Sources/CMakeLists.txt
new file mode 100644
index 0000000000..cfba9169c8
--- /dev/null
+++ b/Tests/SubDirSpaces/Some(x86) Sources/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(testOddPath test.c)
diff --git a/Tests/SubDirSpaces/Some(x86) Sources/test.c b/Tests/SubDirSpaces/Some(x86) Sources/test.c
new file mode 100644
index 0000000000..66568d4c23
--- /dev/null
+++ b/Tests/SubDirSpaces/Some(x86) Sources/test.c
@@ -0,0 +1,3 @@
+void testOdd()
+{
+}
diff --git a/Tests/SubDirSpaces/ThirdSubDir/pair+int.int1.c b/Tests/SubDirSpaces/ThirdSubDir/pair+int.int1.c
new file mode 100644
index 0000000000..b7a6237818
--- /dev/null
+++ b/Tests/SubDirSpaces/ThirdSubDir/pair+int.int1.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_stuff()
+{
+ printf("Placeholder for a strange file in subdirectory\n");
+}
diff --git a/Tests/SubDirSpaces/ThirdSubDir/pair_int.int1.c b/Tests/SubDirSpaces/ThirdSubDir/pair_int.int1.c
new file mode 100644
index 0000000000..b7a6237818
--- /dev/null
+++ b/Tests/SubDirSpaces/ThirdSubDir/pair_int.int1.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_stuff()
+{
+ printf("Placeholder for a strange file in subdirectory\n");
+}
diff --git a/Tests/SubDirSpaces/ThirdSubDir/pair_p_int.int1.c b/Tests/SubDirSpaces/ThirdSubDir/pair_p_int.int1.c
new file mode 100644
index 0000000000..95a66eee69
--- /dev/null
+++ b/Tests/SubDirSpaces/ThirdSubDir/pair_p_int.int1.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void pair_p_stuff()
+{
+ printf("Placeholder for another strange file in subdirectory\n");
+}
diff --git a/Tests/SubDirSpaces/ThirdSubDir/testfromauxsubdir.c b/Tests/SubDirSpaces/ThirdSubDir/testfromauxsubdir.c
new file mode 100644
index 0000000000..fa6c33ced6
--- /dev/null
+++ b/Tests/SubDirSpaces/ThirdSubDir/testfromauxsubdir.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+void secondone();
+void pair_stuff();
+void pair_p_stuff();
+void vcl_stuff();
+#ifdef CMAKE_PAREN
+void testOdd();
+#endif
+int main()
+{
+ printf("Hello from subdirectory\n");
+ secondone();
+#ifdef CMAKE_PAREN
+ testOdd();
+#endif
+ pair_stuff();
+ pair_p_stuff();
+ vcl_stuff();
+ return 0;
+}
diff --git a/Tests/SubDirSpaces/ThirdSubDir/thirdone.c b/Tests/SubDirSpaces/ThirdSubDir/thirdone.c
new file mode 100644
index 0000000000..3e9e5afe6b
--- /dev/null
+++ b/Tests/SubDirSpaces/ThirdSubDir/thirdone.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void secondone()
+{
+ printf("Hello again\n");
+}
diff --git a/Tests/SubDirSpaces/vcl_algorithm+vcl_pair+double.foo.c b/Tests/SubDirSpaces/vcl_algorithm+vcl_pair+double.foo.c
new file mode 100644
index 0000000000..a0c60f75aa
--- /dev/null
+++ b/Tests/SubDirSpaces/vcl_algorithm+vcl_pair+double.foo.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void vcl_stuff()
+{
+ printf("Placeholder for a file with strange name\n");
+}
diff --git a/Tests/SubDirSpaces/vcl_algorithm_vcl_pair_double.foo.c b/Tests/SubDirSpaces/vcl_algorithm_vcl_pair_double.foo.c
new file mode 100644
index 0000000000..a0c60f75aa
--- /dev/null
+++ b/Tests/SubDirSpaces/vcl_algorithm_vcl_pair_double.foo.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+void vcl_stuff()
+{
+ printf("Placeholder for a file with strange name\n");
+}
diff --git a/Tests/SubProject/CMakeLists.txt b/Tests/SubProject/CMakeLists.txt
new file mode 100644
index 0000000000..b2bada9110
--- /dev/null
+++ b/Tests/SubProject/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required (VERSION 2.6)
+project(SubProject)
+file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/gen.cxx) # require generation
+add_custom_command(
+ OUTPUT gen.cxx
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gen.cxx.in
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/gen.cxx.in gen.cxx
+ )
+add_custom_target(gen DEPENDS gen.cxx)
+add_library(bar bar.cxx)
+target_include_directories(bar PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+add_dependencies(bar gen)
+add_executable(car car.cxx)
+add_subdirectory(foo)
diff --git a/Tests/SubProject/bar.cxx b/Tests/SubProject/bar.cxx
new file mode 100644
index 0000000000..c8b8743560
--- /dev/null
+++ b/Tests/SubProject/bar.cxx
@@ -0,0 +1 @@
+#include "gen.cxx"
diff --git a/Tests/SubProject/car.cxx b/Tests/SubProject/car.cxx
new file mode 100644
index 0000000000..95de4a3277
--- /dev/null
+++ b/Tests/SubProject/car.cxx
@@ -0,0 +1,6 @@
+int main(int ac, char** av)
+{
+ (void) ac;
+ (void) av;
+ return 0;
+}
diff --git a/Tests/SubProject/foo/CMakeLists.txt b/Tests/SubProject/foo/CMakeLists.txt
new file mode 100644
index 0000000000..011178b264
--- /dev/null
+++ b/Tests/SubProject/foo/CMakeLists.txt
@@ -0,0 +1,3 @@
+project(foo)
+add_executable(foo foo.cxx)
+target_link_libraries(foo bar)
diff --git a/Tests/SubProject/foo/foo.cxx b/Tests/SubProject/foo/foo.cxx
new file mode 100644
index 0000000000..68fa363760
--- /dev/null
+++ b/Tests/SubProject/foo/foo.cxx
@@ -0,0 +1,15 @@
+int bar();
+#include <stdio.h>
+
+int main(int ac, char** av)
+{
+ (void)ac;
+ (void)av;
+ int ret = bar();
+ printf("bar = %d\n", ret);
+ if(ret == 10)
+ {
+ return 0;
+ }
+ return -1;
+}
diff --git a/Tests/SubProject/gen.cxx.in b/Tests/SubProject/gen.cxx.in
new file mode 100644
index 0000000000..c3f6a181ad
--- /dev/null
+++ b/Tests/SubProject/gen.cxx.in
@@ -0,0 +1,4 @@
+int bar()
+{
+ return 10;
+}
diff --git a/Tests/SwigTest/CMakeLists.txt b/Tests/SwigTest/CMakeLists.txt
new file mode 100644
index 0000000000..17a502d7e5
--- /dev/null
+++ b/Tests/SwigTest/CMakeLists.txt
@@ -0,0 +1,50 @@
+set(language "python")
+
+cmake_minimum_required (VERSION 2.6)
+
+project(example_${language}_class)
+
+find_package(SWIG REQUIRED)
+include(${SWIG_USE_FILE})
+
+if(${language} MATCHES python)
+ find_package(PythonLibs)
+ include_directories(${PYTHON_INCLUDE_PATH})
+ set(SWIG_LANG_LIBRARIES ${PYTHON_LIBRARIES})
+endif()
+if(${language} MATCHES perl)
+ find_package(PerlLibs)
+ include_directories(${PERL_INCLUDE_PATH})
+ add_definitions(${PERL_EXTRA_C_FLAGS})
+ set(SWIG_LANG_LIBRARIES ${PERL_LIBRARY})
+endif()
+if(${language} MATCHES tcl)
+ find_package(TCL)
+ include_directories(${TCL_INCLUDE_PATH})
+ set(SWIG_LANG_LIBRARIES ${TCL_LIBRARY})
+endif()
+if(${language} MATCHES ruby)
+ find_package(Ruby)
+ include_directories(${RUBY_INCLUDE_PATH})
+ set(SWIG_LANG_LIBRARIES ${RUBY_LIBRARY})
+endif()
+if(${language} MATCHES php4)
+ find_package(PHP4)
+ include_directories(${PHP4_INCLUDE_PATH})
+ set(SWIG_LANG_LIBRARIES ${PHP4_LIBRARY})
+endif()
+if(${language} MATCHES pike)
+ find_package(Pike)
+ include_directories(${PIKE_INCLUDE_PATH})
+ set(SWIG_LANG_LIBRARIES ${PIKE_LIBRARY})
+endif()
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+set(CMAKE_SWIG_FLAGS "")
+
+set_source_files_properties(example.i PROPERTIES CPLUSPLUS ON)
+set_source_files_properties(example.i PROPERTIES SWIG_FLAGS "-includeall")
+SWIG_ADD_MODULE(example "${language}"
+ example.i example.cxx)
+SWIG_LINK_LIBRARIES(example ${SWIG_LANG_LIBRARIES})
diff --git a/Tests/SwigTest/example.cxx b/Tests/SwigTest/example.cxx
new file mode 100644
index 0000000000..1e8e203ddd
--- /dev/null
+++ b/Tests/SwigTest/example.cxx
@@ -0,0 +1,28 @@
+/* File : example.c */
+
+#include "example.h"
+#define M_PI 3.14159265358979323846
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
diff --git a/Tests/SwigTest/example.h b/Tests/SwigTest/example.h
new file mode 100644
index 0000000000..c9d59f22bb
--- /dev/null
+++ b/Tests/SwigTest/example.h
@@ -0,0 +1,39 @@
+/* File : example.h */
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ };
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area(void) = 0;
+ virtual double perimeter(void) = 0;
+ static int nshapes;
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+
+
+
+
diff --git a/Tests/SwigTest/example.i b/Tests/SwigTest/example.i
new file mode 100644
index 0000000000..75700b3054
--- /dev/null
+++ b/Tests/SwigTest/example.i
@@ -0,0 +1,10 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Tests/SwigTest/runme.php4 b/Tests/SwigTest/runme.php4
new file mode 100644
index 0000000000..653ced2561
--- /dev/null
+++ b/Tests/SwigTest/runme.php4
@@ -0,0 +1,58 @@
+<?php
+
+# This file illustrates the low-level C++ interface
+# created by SWIG. In this case, all of our C++ classes
+# get converted into function calls.
+
+require("example.php");
+
+# ----- Object creation -----
+
+print "Creating some objects:\n";
+$c = new_Circle(10);
+print " Created circle $c\n";
+$s = new_Square(10);
+print " Created square $s\n";
+
+# ----- Access a static member -----
+
+print "\nA total of " . nshapes() . " shapes were created\n";
+
+# ----- Member data access -----
+
+# Set the location of the object.
+# Note: methods in the base class Shape are used since
+# x and y are defined there.
+
+Shape_x_set($c, 20);
+Shape_y_set($c, 30);
+Shape_x_set($s,-10);
+Shape_y_set($s,5);
+
+print "\nHere is their current position:\n";
+print " Circle = (" . Shape_x_get($c) . "," . Shape_y_get($c) . ")\n";
+print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n";
+
+# ----- Call some methods -----
+
+print "\nHere are some properties of the shapes:\n";
+foreach (array($c,$s) as $o) {
+ print " $o\n";
+ print " area = " . Shape_area($o) . "\n";
+ print " perimeter = " . Shape_perimeter($o) . "\n";
+ }
+# Notice how the Shape_area() and Shape_perimeter() functions really
+# invoke the appropriate virtual method on each object.
+
+# ----- Delete everything -----
+
+print "\nGuess I'll clean up now\n";
+
+# Note: this invokes the virtual destructor
+delete_Shape($c);
+delete_Shape($s);
+
+print nshapes() . " shapes remain\n";
+print "Goodbye\n";
+
+?>
diff --git a/Tests/SwigTest/runme.pike b/Tests/SwigTest/runme.pike
new file mode 100755
index 0000000000..ec28dd70e1
--- /dev/null
+++ b/Tests/SwigTest/runme.pike
@@ -0,0 +1,53 @@
+import .example;
+
+int main()
+{
+ // ----- Object creation -----
+
+ write("Creating some objects:\n");
+ Circle c = Circle(10.0);
+ write(" Created circle.\n");
+ Square s = Square(10.0);
+ write(" Created square.\n");
+
+ // ----- Access a static member -----
+
+ write("\nA total of " + Shape_nshapes_get() + " shapes were created\n");
+
+ // ----- Member data access -----
+
+ // Set the location of the object
+
+ c->x_set(20.0);
+ c->y_set(30.0);
+
+ s->x_set(-10.0);
+ s->y_set(5.0);
+
+ write("\nHere is their current position:\n");
+ write(" Circle = (%f, %f)\n", c->x_get(), c->y_get());
+ write(" Square = (%f, %f)\n", s->x_get(), s->y_get());
+
+ // ----- Call some methods -----
+
+ write("\nHere are some properties of the shapes:\n");
+ write(" The circle:\n");
+ write(" area = %f.\n", c->area());
+ write(" perimeter = %f.\n", c->perimeter());
+ write(" The square:\n");
+ write(" area = %f.\n", s->area());
+ write(" perimeter = %f.\n", s->perimeter());
+
+ write("\nGuess I'll clean up now\n");
+
+ /* See if we can force 's' to be garbage-collected */
+ s = 0;
+
+ /* Now we should be down to only 1 shape */
+ write("%d shapes remain\n", Shape_nshapes_get());
+
+ /* Done */
+ write("Goodbye\n");
+
+ return 0;
+}
diff --git a/Tests/SwigTest/runme.pl b/Tests/SwigTest/runme.pl
new file mode 100644
index 0000000000..5bfb3d83a8
--- /dev/null
+++ b/Tests/SwigTest/runme.pl
@@ -0,0 +1,57 @@
+# file: runme.pl
+
+# This file illustrates the low-level C++ interface
+# created by SWIG. In this case, all of our C++ classes
+# get converted into function calls.
+
+use example;
+
+# ----- Object creation -----
+
+print "Creating some objects:\n";
+$c = examplec::new_Circle(10);
+print " Created circle $c\n";
+$s = examplec::new_Square(10);
+print " Created square $s\n";
+
+# ----- Access a static member -----
+
+print "\nA total of $examplec::Shape_nshapes shapes were created\n";
+
+# ----- Member data access -----
+
+# Set the location of the object.
+# Note: methods in the base class Shape are used since
+# x and y are defined there.
+
+examplec::Shape_x_set($c, 20);
+examplec::Shape_y_set($c, 30);
+examplec::Shape_x_set($s,-10);
+examplec::Shape_y_set($s,5);
+
+print "\nHere is their current position:\n";
+print " Circle = (",examplec::Shape_x_get($c),",", examplec::Shape_y_get($c),")\n";
+print " Square = (",examplec::Shape_x_get($s),",", examplec::Shape_y_get($s),")\n";
+
+# ----- Call some methods -----
+
+print "\nHere are some properties of the shapes:\n";
+foreach $o ($c,$s) {
+ print " $o\n";
+ print " area = ", examplec::Shape_area($o), "\n";
+ print " perimeter = ", examplec::Shape_perimeter($o), "\n";
+ }
+# Notice how the Shape_area() and Shape_perimeter() functions really
+# invoke the appropriate virtual method on each object.
+
+# ----- Delete everything -----
+
+print "\nGuess I'll clean up now\n";
+
+# Note: this invokes the virtual destructor
+examplec::delete_Shape($c);
+examplec::delete_Shape($s);
+
+print $examplec::Shape_nshapes," shapes remain\n";
+print "Goodbye\n";
+
diff --git a/Tests/SwigTest/runme.py b/Tests/SwigTest/runme.py
new file mode 100644
index 0000000000..ed3909e302
--- /dev/null
+++ b/Tests/SwigTest/runme.py
@@ -0,0 +1,51 @@
+# file: runme.py
+
+# This file illustrates the shadow-class C++ interface generated
+# by SWIG.
+
+import example
+
+# ----- Object creation -----
+
+print "Creating some objects:"
+c = example.Circle(10)
+print " Created circle", c
+s = example.Square(10)
+print " Created square", s
+
+# ----- Access a static member -----
+
+print "\nA total of", example.cvar.Shape_nshapes,"shapes were created"
+
+# ----- Member data access -----
+
+# Set the location of the object
+
+c.x = 20
+c.y = 30
+
+s.x = -10
+s.y = 5
+
+print "\nHere is their current position:"
+print " Circle = (%f, %f)" % (c.x,c.y)
+print " Square = (%f, %f)" % (s.x,s.y)
+
+# ----- Call some methods -----
+
+print "\nHere are some properties of the shapes:"
+for o in [c,s]:
+ print " ", o
+ print " area = ", o.area()
+ print " perimeter = ", o.perimeter()
+
+print "\nGuess I'll clean up now"
+
+# Note: this invokes the virtual destructor
+del c
+del s
+
+s = 3
+print example.cvar.Shape_nshapes,"shapes remain"
+print "Goodbye"
+
diff --git a/Tests/SwigTest/runme.rb b/Tests/SwigTest/runme.rb
new file mode 100644
index 0000000000..de73bcd46f
--- /dev/null
+++ b/Tests/SwigTest/runme.rb
@@ -0,0 +1,49 @@
+# file: runme.rb
+
+# This file illustrates the C++ interface created by SWIG.
+# All of our C++ classes get converted into Ruby classes.
+
+require 'example'
+
+# ----- Object creation -----
+
+print "Creating some objects:\n"
+c = Example::Circle.new(10)
+print " Created circle #{c}\n"
+s = Example::Square.new(10)
+print " Created square #{s}\n"
+
+# ----- Access a static member -----
+
+print "\nA total of #{Example::Shape.nshapes} shapes were created\n"
+
+# ----- Member data access -----
+
+# Set the location of the object
+
+# Notice how we can do this using functions specific to
+# the 'Circle' class.
+c.x = 20
+c.y = 30
+
+# Now use the same functions in the base class
+s.x = -10
+s.y = 5
+
+print "\nHere is their current position:\n"
+print " Circle = (", c.x, ",", c.y, ")\n"
+print " Square = (", s.x, ",", s.y, ")\n"
+
+# ----- Call some methods -----
+
+print "\nHere are some properties of the shapes:\n"
+for o in [c, s]
+ print " #{o}\n"
+ print " area = ", o.area, "\n"
+ print " perimeter = ", o.perimeter, "\n"
+end
+# Notice how the Shape#area() and Shape#perimeter() functions really
+# invoke the appropriate virtual method on each object.
+
+print "\n", Example::Shape.nshapes," shapes remain\n"
+print "Goodbye\n"
diff --git a/Tests/SwigTest/runme.tcl b/Tests/SwigTest/runme.tcl
new file mode 100644
index 0000000000..c7f4725603
--- /dev/null
+++ b/Tests/SwigTest/runme.tcl
@@ -0,0 +1,50 @@
+# file: runme.tcl
+
+# This file illustrates the high level C++ interface.
+# In this case C++ classes work kind of like Tk widgets
+
+catch { load ./example[info sharedlibextension] example}
+
+# ----- Object creation -----
+
+puts "Creating some objects:"
+Circle c 10
+puts " Created circle [c cget -this]"
+Square s 10
+puts " Created square [s cget -this]"
+
+# ----- Access a static member -----
+
+puts "\nA total of $Shape_nshapes shapes were created"
+
+# ----- Member data access -----
+
+# Set the location of the object
+
+c configure -x 20 -y 30
+s configure -x -10 -y 5
+
+puts "\nHere is their current position:"
+puts " Circle = ([c cget -x], [c cget -y])"
+puts " Square = ([s cget -x], [s cget -y])"
+
+# ----- Call some methods -----
+
+puts "\nHere are some properties of the shapes:"
+foreach o "c s" {
+ puts " [$o cget -this]"
+ puts " area = [$o area]"
+ puts " perimeter = [$o perimeter]"
+}
+
+# ----- Delete everything -----
+
+puts "\nGuess I'll clean up now"
+
+# Note: this invokes the virtual destructor
+rename c ""
+rename s ""
+
+puts "$Shape_nshapes shapes remain"
+puts "Goodbye"
+
diff --git a/Tests/SwigTest/runme2.tcl b/Tests/SwigTest/runme2.tcl
new file mode 100644
index 0000000000..88ec2f678d
--- /dev/null
+++ b/Tests/SwigTest/runme2.tcl
@@ -0,0 +1,70 @@
+# file: runme2.tcl
+
+# This file illustrates the low-level C++ interface
+# created by SWIG. In this case, all of our C++ classes
+# get converted into function calls.
+
+catch { load ./example[info sharedlibextension] example}
+
+# ----- Object creation -----
+
+puts "Creating some objects:"
+set c [new_Circle 10]
+puts " Created circle $c"
+set s [new_Square 10]
+puts " Created square $s"
+
+# ----- Access a static member -----
+
+puts "\nA total of $Shape_nshapes shapes were created"
+
+# ----- Member data access -----
+
+# Set the location of the object
+# Note: the base class must be used since that's where x and y
+# were declared.
+
+Shape_x_set $c 20
+Shape_y_set $c 30
+Shape_x_set $s -10
+Shape_y_set $s 5
+
+puts "\nHere is their current position:"
+puts " Circle = ([Shape_x_get $c], [Shape_y_get $c])"
+puts " Square = ([Shape_x_get $s], [Shape_y_get $s])"
+
+# ----- Call some methods -----
+
+puts "\nHere are some properties of the shapes:"
+foreach o "$c $s" {
+ puts " $o"
+ puts " area = [Shape_area $o]"
+ puts " perimeter = [Shape_perimeter $o]"
+}
+# Notice how the Shape_area() and Shape_perimeter() functions really
+# invoke the appropriate virtual method on each object.
+
+# ----- Try to cause a type error -----
+
+puts "\nI'm going to try and break the type system"
+
+if { [catch {
+ # Bad script!
+ Square_area $c # Try to invoke Square method on a Circle
+ puts " Bad bad SWIG!"
+
+}]} {
+ puts " Well, it didn't work. Good SWIG."
+}
+
+# ----- Delete everything -----
+
+puts "\nGuess I'll clean up now"
+
+# Note: this invokes the virtual destructor
+delete_Shape $c
+delete_Shape $s
+
+puts "$Shape_nshapes shapes remain"
+puts "Goodbye"
+
diff --git a/Tests/SystemInformation/CMakeLists.txt b/Tests/SystemInformation/CMakeLists.txt
new file mode 100644
index 0000000000..db54612454
--- /dev/null
+++ b/Tests/SystemInformation/CMakeLists.txt
@@ -0,0 +1,59 @@
+cmake_minimum_required (VERSION 3.0)
+project(SystemInformation)
+
+include_directories("This does not exists")
+get_directory_property(incl INCLUDE_DIRECTORIES)
+set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${SystemInformation_BINARY_DIR};${SystemInformation_SOURCE_DIR}")
+
+message("To prevent CTest from stripping output, you have to display: CTEST_FULL_OUTPUT")
+
+
+configure_file(${SystemInformation_SOURCE_DIR}/SystemInformation.in
+${SystemInformation_BINARY_DIR}/SystemInformation.out)
+configure_file(${SystemInformation_SOURCE_DIR}/DumpInformation.h.in
+${SystemInformation_BINARY_DIR}/DumpInformation.h)
+add_executable(SystemInformation DumpInformation.cxx)
+
+macro(FOO args)
+ message("Test macro")
+endmacro()
+
+FOO(lala)
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AllVariables.txt "")
+get_cmake_property(res VARIABLES)
+foreach(var ${res})
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AllVariables.txt
+ "${var} \"${${var}}\"\n")
+endforeach()
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AllCommands.txt "")
+get_cmake_property(res COMMANDS)
+foreach(var ${res})
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AllCommands.txt
+ "${var}\n")
+endforeach()
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AllMacros.txt "")
+get_cmake_property(res MACROS)
+foreach(var ${res})
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AllMacros.txt
+ "${var}\n")
+endforeach()
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/OtherProperties.txt "")
+get_directory_property(res INCLUDE_DIRECTORIES)
+foreach(var ${res})
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/OtherProperties.txt
+ "INCLUDE_DIRECTORY: ${var}\n")
+endforeach()
+
+get_directory_property(res LINK_DIRECTORIES)
+foreach(var ${res})
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/OtherProperties.txt
+ "LINK_DIRECTORIES: ${var}\n")
+endforeach()
+
+get_directory_property(res INCLUDE_REGULAR_EXPRESSION)
+file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/OtherProperties.txt
+ "INCLUDE_REGULAR_EXPRESSION: ${res}\n")
diff --git a/Tests/SystemInformation/DumpInformation.cxx b/Tests/SystemInformation/DumpInformation.cxx
new file mode 100644
index 0000000000..acafa874d9
--- /dev/null
+++ b/Tests/SystemInformation/DumpInformation.cxx
@@ -0,0 +1,80 @@
+#include "DumpInformation.h"
+#include <stdio.h>
+#include <sys/stat.h>
+
+void cmDumpInformationPrintFile(const char* name, FILE* fout)
+{
+ fprintf(fout,
+ "Avoid ctest truncation of output: CTEST_FULL_OUTPUT\n");
+ fprintf(fout,
+ "================================================================\n");
+ struct stat fs;
+ if(stat(name, &fs) != 0)
+ {
+ fprintf(fout, "The file \"%s\" does not exist.\n", name);
+ fflush(fout);
+ return;
+ }
+
+ FILE* fin = fopen(name, "r");
+ if(fin)
+ {
+ fprintf(fout,
+ "Contents of \"%s\":\n"
+ "----------------------------------------------------------------\n",
+ name);
+ const int bufferSize = 4096;
+ char buffer[bufferSize];
+ int n;
+ while((n = fread(buffer, 1, bufferSize, fin)) > 0)
+ {
+ for(char* c = buffer; c < buffer+n; ++c)
+ {
+ switch(*c)
+ {
+ case '<': fprintf(fout, "&lt;"); break;
+ case '>': fprintf(fout, "&gt;"); break;
+ case '&': fprintf(fout, "&amp;"); break;
+ default: putc(*c, fout); break;
+ }
+ }
+ fflush(fout);
+ }
+ fclose(fin);
+ }
+ else
+ {
+ fprintf(fout, "Error opening \"%s\" for reading.\n", name);
+ fflush(fout);
+ }
+}
+
+int main(int,char *[])
+{
+ const char* files[] =
+ {
+ DumpInformation_BINARY_DIR "/SystemInformation.out",
+ DumpInformation_BINARY_DIR "/AllVariables.txt",
+ DumpInformation_BINARY_DIR "/AllCommands.txt",
+ DumpInformation_BINARY_DIR "/AllMacros.txt",
+ DumpInformation_BINARY_DIR "/OtherProperties.txt",
+ DumpInformation_BINARY_DIR "/../../Source/cmConfigure.h",
+ DumpInformation_BINARY_DIR "/../../CMakeCache.txt",
+ DumpInformation_BINARY_DIR "/../../CMakeFiles/CMakeOutput.log",
+ DumpInformation_BINARY_DIR "/../../CMakeFiles/CMakeError.log",
+ DumpInformation_BINARY_DIR "/../../Bootstrap.cmk/cmake_bootstrap.log",
+ DumpInformation_BINARY_DIR "/../../Source/cmsys/Configure.hxx",
+ DumpInformation_BINARY_DIR "/../../Source/cmsys/Configure.h",
+ DumpInformation_BINARY_DIR "/CMakeFiles/CMakeOutput.log",
+ DumpInformation_BINARY_DIR "/CMakeFiles/CMakeError.log",
+ 0
+ };
+
+ const char** f;
+ for(f = files; *f; ++f)
+ {
+ cmDumpInformationPrintFile(*f, stdout);
+ }
+
+ return 0;
+}
diff --git a/Tests/SystemInformation/DumpInformation.h.in b/Tests/SystemInformation/DumpInformation.h.in
new file mode 100644
index 0000000000..72d5cd1792
--- /dev/null
+++ b/Tests/SystemInformation/DumpInformation.h.in
@@ -0,0 +1,6 @@
+#ifndef _DumpInformation_h
+#define _DumpInformation_h
+
+#define DumpInformation_BINARY_DIR "@SystemInformation_BINARY_DIR@"
+
+#endif
diff --git a/Tests/SystemInformation/SystemInformation.in b/Tests/SystemInformation/SystemInformation.in
new file mode 100644
index 0000000000..f7e81e625e
--- /dev/null
+++ b/Tests/SystemInformation/SystemInformation.in
@@ -0,0 +1,122 @@
+CMAKE_STATIC_LIBRARY_PREFIX == "${CMAKE_STATIC_LIBRARY_PREFIX}"
+CMAKE_STATIC_LIBRARY_SUFFIX == "${CMAKE_STATIC_LIBRARY_SUFFIX}"
+CMAKE_SHARED_LIBRARY_PREFIX == "${CMAKE_SHARED_LIBRARY_PREFIX}"
+CMAKE_SHARED_LIBRARY_SUFFIX == "${CMAKE_SHARED_LIBRARY_SUFFIX}"
+CMAKE_SHARED_MODULE_PREFIX == "${CMAKE_SHARED_MODULE_PREFIX}"
+CMAKE_SHARED_MODULE_SUFFIX == "${CMAKE_SHARED_MODULE_SUFFIX}"
+
+
+CMAKE_DL_LIBS == "${CMAKE_DL_LIBS}"
+CMAKE_LIBRARY_PATH_FLAG == "${CMAKE_LIBRARY_PATH_FLAG}"
+CMAKE_LINK_LIBRARY_FLAG == "${CMAKE_LINK_LIBRARY_FLAG}"
+CMAKE_SKIP_RPATH == "${CMAKE_SKIP_RPATH}"
+CMAKE_SYSTEM_INFO_FILE == "${CMAKE_SYSTEM_INFO_FILE}"
+CMAKE_SYSTEM_NAME == "${CMAKE_SYSTEM_NAME}"
+CMAKE_SYSTEM == "${CMAKE_SYSTEM}"
+CMAKE_CXX_COMPILER == "${CMAKE_CXX_COMPILER}"
+CMAKE_C_COMPILER == "${CMAKE_C_COMPILER}"
+CMAKE_COMPILER_IS_GNUCC == "${CMAKE_COMPILER_IS_GNUCC}"
+CMAKE_COMPILER_IS_GNUCXX == "${CMAKE_COMPILER_IS_GNUCXX}"
+CMAKE_C_COMPILER_ID == "${CMAKE_C_COMPILER_ID}"
+CMAKE_C_COMPILER_VERSION == "${CMAKE_C_COMPILER_VERSION}"
+CMAKE_C90_STANDARD_COMPILE_OPTION == "${CMAKE_C90_STANDARD_COMPILE_OPTION}"
+CMAKE_C99_STANDARD_COMPILE_OPTION == "${CMAKE_C99_STANDARD_COMPILE_OPTION}"
+CMAKE_C11_STANDARD_COMPILE_OPTION == "${CMAKE_C11_STANDARD_COMPILE_OPTION}"
+CMAKE_C90_EXTENSION_COMPILE_OPTION == "${CMAKE_C90_EXTENSION_COMPILE_OPTION}"
+CMAKE_C99_EXTENSION_COMPILE_OPTION == "${CMAKE_C99_EXTENSION_COMPILE_OPTION}"
+CMAKE_C11_EXTENSION_COMPILE_OPTION == "${CMAKE_C11_EXTENSION_COMPILE_OPTION}"
+CMAKE_C_COMPILE_FEATURES == "${CMAKE_C_COMPILE_FEATURES}"
+CMAKE_C90_COMPILE_FEATURES == "${CMAKE_C90_COMPILE_FEATURES}"
+CMAKE_C99_COMPILE_FEATURES == "${CMAKE_C99_COMPILE_FEATURES}"
+CMAKE_C11_COMPILE_FEATURES == "${CMAKE_C11_COMPILE_FEATURES}"
+CMAKE_CXX_COMPILER_ID == "${CMAKE_CXX_COMPILER_ID}"
+CMAKE_CXX_COMPILER_VERSION == "${CMAKE_CXX_COMPILER_VERSION}"
+CMAKE_CXX98_STANDARD_COMPILE_OPTION == "${CMAKE_CXX98_STANDARD_COMPILE_OPTION}"
+CMAKE_CXX11_STANDARD_COMPILE_OPTION == "${CMAKE_CXX11_STANDARD_COMPILE_OPTION}"
+CMAKE_CXX98_EXTENSION_COMPILE_OPTION == "${CMAKE_CXX98_EXTENSION_COMPILE_OPTION}"
+CMAKE_CXX11_EXTENSION_COMPILE_OPTION == "${CMAKE_CXX11_EXTENSION_COMPILE_OPTION}"
+CMAKE_CXX_COMPILE_FEATURES == "${CMAKE_CXX_COMPILE_FEATURES}"
+CMAKE_CXX98_COMPILE_FEATURES == "${CMAKE_CXX98_COMPILE_FEATURES}"
+CMAKE_CXX11_COMPILE_FEATURES == "${CMAKE_CXX11_COMPILE_FEATURES}"
+CMAKE_CXX14_COMPILE_FEATURES == "${CMAKE_CXX14_COMPILE_FEATURES}"
+
+// C shared library flag
+CMAKE_SHARED_LIBRARY_C_FLAGS == "${CMAKE_SHARED_LIBRARY_C_FLAGS}"
+CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS == "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}"
+CMAKE_SHARED_LIBRARY_LINK_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_FLAGS}"
+CMAKE_SHARED_LIBRARY_RUNTIME_FLAG == "${CMAKE_SHARED_LIBRARY_RUNTIME_FLAG}"
+CMAKE_SHARED_LIBRARY_RUNTIME_FLAG_SEP == "${CMAKE_SHARED_LIBRARY_RUNTIME_FLAG_SEP}"
+CMAKE_SHARED_LIBRARY_LINK_STATIC_C_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_STATIC_C_FLAGS}"
+CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_C_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_C_FLAGS}"
+CMAKE_C_COMPILE_OPTIONS_PIC == "${CMAKE_C_COMPILE_OPTIONS_PIC}"
+CMAKE_C_COMPILE_OPTIONS_PIE == "${CMAKE_C_COMPILE_OPTIONS_PIE}"
+CMAKE_C_COMPILE_OPTIONS_DLL == "${CMAKE_C_COMPILE_OPTIONS_DLL}"
+
+// C shared module flags
+CMAKE_SHARED_MODULE_C_FLAGS == "${CMAKE_SHARED_MODULE_C_FLAGS}"
+CMAKE_SHARED_MODULE_CREATE_C_FLAGS == "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS}"
+CMAKE_SHARED_MODULE_LINK_STATIC_C_FLAGS == "${CMAKE_SHARED_MODULE_LINK_STATIC_C_FLAGS}"
+CMAKE_SHARED_MODULE_LINK_DYNAMIC_C_FLAGS == "${CMAKE_SHARED_MODULE_LINK_DYNAMIC_C_FLAGS}"
+
+// C exe flags
+CMAKE_EXE_LINK_STATIC_C_FLAGS == "${CMAKE_EXE_LINK_STATIC_C_FLAGS}"
+CMAKE_EXE_LINK_DYNAMIC_C_FLAGS == "${CMAKE_EXE_LINK_DYNAMIC_C_FLAGS}"
+
+// CXX shared library flags
+CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}"
+CMAKE_SHARED_LIBRARY_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
+CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}"
+CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG == "${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG}"
+CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP == "${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP}"
+CMAKE_SHARED_LIBRARY_LINK_STATIC_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_STATIC_CXX_FLAGS}"
+CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_CXX_FLAGS}"
+CMAKE_CXX_COMPILE_OPTIONS_PIC == "${CMAKE_CXX_COMPILE_OPTIONS_PIC}"
+CMAKE_CXX_COMPILE_OPTIONS_PIE == "${CMAKE_CXX_COMPILE_OPTIONS_PIE}"
+CMAKE_CXX_COMPILE_OPTIONS_DLL == "${CMAKE_CXX_COMPILE_OPTIONS_DLL}"
+
+// CXX shared module flags
+CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS == "${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS}"
+CMAKE_SHARED_MODULE_CXX_FLAGS == "${CMAKE_SHARED_MODULE_CXX_FLAGS}"
+CMAKE_SHARED_MODULE_LINK_STATIC_CXX_FLAGS == "${CMAKE_SHARED_MODULE_LINK_STATIC_CXX_FLAGS}"
+CMAKE_SHARED_MODULE_LINK_DYNAMIC_CXX_FLAGS == "${CMAKE_SHARED_MODULE_LINK_DYNAMIC_CXX_FLAGS}"
+
+// CXX exe flags
+CMAKE_EXE_LINK_STATIC_CXX_FLAGS == "${CMAKE_EXE_LINK_STATIC_CXX_FLAGS}"
+CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS == "${CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS}"
+
+CMAKE_USER_MAKE_RULES_OVERRIDE == "${CMAKE_USER_MAKE_RULES_OVERRIDE}"
+CMAKE_VERBOSE_MAKEFILE == "${CMAKE_VERBOSE_MAKEFILE}"
+CMAKE_BUILD_TYPE == "${CMAKE_BUILD_TYPE}"
+CMAKE_CXX_FLAGS == "${CMAKE_CXX_FLAGS}"
+CMAKE_CXX_FLAGS_DEBUG == "${CMAKE_CXX_FLAGS_DEBUG}"
+CMAKE_CXX_FLAGS_MINSIZEREL == "${CMAKE_CXX_FLAGS_MINSIZEREL}"
+CMAKE_CXX_FLAGS_RELEASE == "${CMAKE_CXX_FLAGS_RELEASE}"
+CMAKE_CXX_FLAGS_RELWITHDEBINFO == "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
+
+CMAKE_C_FLAGS == "${CMAKE_C_FLAGS}"
+CMAKE_C_FLAGS_DEBUG == "${CMAKE_C_FLAGS_DEBUG}"
+CMAKE_C_FLAGS_MINSIZEREL == "${CMAKE_C_FLAGS_MINSIZEREL}"
+CMAKE_C_FLAGS_RELEASE == "${CMAKE_C_FLAGS_RELEASE}"
+CMAKE_C_FLAGS_RELWITHDEBINFO == "${CMAKE_C_FLAGS_RELWITHDEBINFO}"
+
+// build rules
+CMAKE_CXX_CREATE_SHARED_LIBRARY == "${CMAKE_CXX_CREATE_SHARED_LIBRARY}"
+CMAKE_CXX_CREATE_SHARED_MODULE == "${CMAKE_CXX_CREATE_SHARED_MODULE}"
+CMAKE_C_CREATE_SHARED_LIBRARY == "${CMAKE_C_CREATE_SHARED_LIBRARY}"
+CMAKE_C_CREATE_SHARED_MODULE == "${CMAKE_C_CREATE_SHARED_MODULE}"
+CMAKE_CXX_CREATE_STATIC_LIBRARY == "${CMAKE_CXX_CREATE_STATIC_LIBRARY}"
+CMAKE_C_CREATE_STATIC_LIBRARY == "${CMAKE_C_CREATE_STATIC_LIBRARY}"
+CMAKE_CXX_COMPILE_OBJECT == "${CMAKE_CXX_COMPILE_OBJECT}"
+CMAKE_C_COMPILE_OBJECT == "${CMAKE_C_COMPILE_OBJECT}"
+CMAKE_C_LINK_EXECUTABLE == "${CMAKE_C_LINK_EXECUTABLE}"
+CMAKE_CXX_LINK_EXECUTABLE == "${CMAKE_CXX_LINK_EXECUTABLE}"
+
+// implicit link info
+CMAKE_C_IMPLICIT_LINK_LIBRARIES == "${CMAKE_C_IMPLICIT_LINK_LIBRARIES}"
+CMAKE_C_IMPLICIT_LINK_DIRECTORIES == "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}"
+CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES == "${CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES}"
+CMAKE_CXX_IMPLICIT_LINK_LIBRARIES == "${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}"
+CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES == "${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}"
+CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES == "${CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES}"
+
+XCODE_VERSION == "${XCODE_VERSION}"
diff --git a/Tests/TarTest/CMakeLists.txt b/Tests/TarTest/CMakeLists.txt
new file mode 100644
index 0000000000..bcc340bb3f
--- /dev/null
+++ b/Tests/TarTest/CMakeLists.txt
@@ -0,0 +1,69 @@
+cmake_minimum_required (VERSION 2.6)
+project(TarTest)
+
+# this is macro that we will be running
+macro(EXEC_TAR_COMMAND DIR ARGS)
+ exec_program("${CMAKE_COMMAND}" "${DIR}" ARGS "-E tar ${ARGS}" RETURN_VALUE RET)
+ if(${RET})
+ message(FATAL_ERROR "CMake tar command failed with arguments \"${ARGS}\"")
+ endif()
+endmacro()
+
+# Create a directory structure
+set(CHECK_FILES)
+macro(COPY F1 F2)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${F1}" "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${F2}" COPYONLY)
+ set(CHECK_FILES ${CHECK_FILES} "${F2}")
+endmacro()
+COPY("CMakeLists.txt" "f1.txt")
+COPY("CMakeLists.txt" "d1/f1.txt")
+COPY("CMakeLists.txt" "d 2/f1.txt")
+COPY("CMakeLists.txt" "d + 3/f1.txt")
+COPY("CMakeLists.txt" "d_4/f1.txt")
+COPY("CMakeLists.txt" "d-4/f1.txt")
+COPY("CMakeLists.txt" "My Special Directory/f1.txt")
+
+if(UNIX)
+ exec_program("ln" ARGS "-sf f1.txt \"${CMAKE_CURRENT_BINARY_DIR}/tar_dir/d1/f2.txt\"")
+ set(CHECK_FILES ${CHECK_FILES} "d1/f2.txt")
+endif()
+
+# cleanup first in case there are files left from previous runs
+# if the umask is odd on the machine it might create files that
+# are not automatically over written. These tests are run
+# each time the configure step is run.
+file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar")
+file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz")
+file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/test_output_tar")
+file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz")
+
+make_directory("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar")
+make_directory("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz")
+
+
+# Run tests
+EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\" tar_dir")
+EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\" tar_dir")
+
+EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar" "xvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\"")
+EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz" "xvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\"")
+
+macro(CHECK_DIR_STRUCTURE DIR)
+ foreach(file ${CHECK_FILES})
+ set(sfile "${DIR}/${file}")
+ set(rfile "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${file}")
+ if(NOT EXISTS "${sfile}")
+ message(SEND_ERROR "Cannot find file ${sfile}")
+ else()
+ exec_program("${CMAKE_COMMAND}" ARGS "-E compare_files \"${sfile}\" \"${rfile}\"" RETURN_VALUE ret)
+ if(${ret})
+ message(SEND_ERROR "Files \"${sfile}\" \"${rfile}\" are different")
+ endif()
+ endif()
+ endforeach()
+endmacro()
+
+CHECK_DIR_STRUCTURE("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar/tar_dir")
+
+add_executable(TarTest TestTarExec.cxx)
+
diff --git a/Tests/TarTest/TestTarExec.cxx b/Tests/TarTest/TestTarExec.cxx
new file mode 100644
index 0000000000..86f2cd170b
--- /dev/null
+++ b/Tests/TarTest/TestTarExec.cxx
@@ -0,0 +1,5 @@
+int main()
+{
+ return 0;
+}
+
diff --git a/Tests/TargetName/CMakeLists.txt b/Tests/TargetName/CMakeLists.txt
new file mode 100644
index 0000000000..9729d21ffd
--- /dev/null
+++ b/Tests/TargetName/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required (VERSION 2.6)
+project(TargetName)
+
+add_subdirectory(executables)
+add_subdirectory(scripts)
diff --git a/Tests/TargetName/executables/CMakeLists.txt b/Tests/TargetName/executables/CMakeLists.txt
new file mode 100644
index 0000000000..2671e3e900
--- /dev/null
+++ b/Tests/TargetName/executables/CMakeLists.txt
@@ -0,0 +1 @@
+add_executable(hello_world hello_world.c)
diff --git a/Tests/TargetName/executables/hello_world.c b/Tests/TargetName/executables/hello_world.c
new file mode 100644
index 0000000000..539d867e01
--- /dev/null
+++ b/Tests/TargetName/executables/hello_world.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+main()
+{
+ printf("hello, world\n");
+}
diff --git a/Tests/TargetName/scripts/.gitattributes b/Tests/TargetName/scripts/.gitattributes
new file mode 100644
index 0000000000..51b8ce901a
--- /dev/null
+++ b/Tests/TargetName/scripts/.gitattributes
@@ -0,0 +1 @@
+hello_world crlf=input
diff --git a/Tests/TargetName/scripts/CMakeLists.txt b/Tests/TargetName/scripts/CMakeLists.txt
new file mode 100644
index 0000000000..58af64d65f
--- /dev/null
+++ b/Tests/TargetName/scripts/CMakeLists.txt
@@ -0,0 +1,13 @@
+if(NOT CMAKE_BINARY_DIR STREQUAL "${CMAKE_SOURCE_DIR}")
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/hello_world
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/hello_world ${CMAKE_CURRENT_BINARY_DIR}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/hello_world
+ )
+ add_custom_target(
+ hello_world_copy ALL
+ DEPENDS #hello_world
+ ${CMAKE_CURRENT_BINARY_DIR}/hello_world
+ )
+endif()
diff --git a/Tests/TargetName/scripts/hello_world b/Tests/TargetName/scripts/hello_world
new file mode 100755
index 0000000000..ea3a72c1ce
--- /dev/null
+++ b/Tests/TargetName/scripts/hello_world
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "hello, world"
diff --git a/Tests/TestDriver/CMakeLists.txt b/Tests/TestDriver/CMakeLists.txt
new file mode 100644
index 0000000000..663ecab551
--- /dev/null
+++ b/Tests/TestDriver/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required (VERSION 2.6)
+project(TestDriverTest)
+
+set(Extra_SRCS testExtraStuff.cxx testExtraStuff2.cxx )
+set(Extra_SRCS ${Extra_SRCS};testExtraStuff3.cxx )
+include_directories(${TestDriverTest_SOURCE_DIR})
+create_test_sourcelist(testSrcs
+ TestDriverTest.cxx
+ test1.cxx
+ test2.cxx
+ subdir/test3.cxx
+ EXTRA_INCLUDE testArgs.h FUNCTION testProccessArgs)
+
+add_executable(TestDriverTest ${testSrcs} ${Extra_SRCS})
+
diff --git a/Tests/TestDriver/subdir/test3.cxx b/Tests/TestDriver/subdir/test3.cxx
new file mode 100644
index 0000000000..976d6ebaa2
--- /dev/null
+++ b/Tests/TestDriver/subdir/test3.cxx
@@ -0,0 +1,8 @@
+#include <stdio.h>
+int subdir_test3(int ac, char*av[])
+{
+ printf("test3\n");
+ for(int i =0; i < ac; i++)
+ printf("arg %d is %s\n", ac, av[i]);
+ return 0;
+}
diff --git a/Tests/TestDriver/test1.cxx b/Tests/TestDriver/test1.cxx
new file mode 100644
index 0000000000..b998fdae6d
--- /dev/null
+++ b/Tests/TestDriver/test1.cxx
@@ -0,0 +1,25 @@
+#include <stdio.h>
+int testExtraStuff3();
+int testExtraStuff();
+int testExtraStuff2();
+
+int test1(int ac, char* av[])
+{
+ if(!testExtraStuff2())
+ {
+ return -1;
+ }
+ if(!testExtraStuff())
+ {
+ return -1;
+ }
+ if(!testExtraStuff3())
+ {
+ return -1;
+ }
+
+ printf("test1\n");
+ for(int i =0; i < ac; i++)
+ printf("arg %d is %s\n", ac, av[i]);
+ return 0;
+}
diff --git a/Tests/TestDriver/test2.cxx b/Tests/TestDriver/test2.cxx
new file mode 100644
index 0000000000..69f0fff174
--- /dev/null
+++ b/Tests/TestDriver/test2.cxx
@@ -0,0 +1,8 @@
+#include <stdio.h>
+int test2(int ac, char*av[])
+{
+ printf("test2\n");
+ for(int i =0; i < ac; i++)
+ printf("arg %d is %s\n", ac, av[i]);
+ return 0;
+}
diff --git a/Tests/TestDriver/testArgs.h b/Tests/TestDriver/testArgs.h
new file mode 100644
index 0000000000..04893660ba
--- /dev/null
+++ b/Tests/TestDriver/testArgs.h
@@ -0,0 +1,20 @@
+void testProccessArgs(int* ac, char***av)
+{
+ char** argv = *av;
+ if(*ac < 2)
+ {
+ return;
+ }
+ if(strcmp(argv[1], "--with-threads") == 0)
+ {
+ printf("number of threads is %s\n", argv[2]);
+ *av +=2;
+ *ac -=2;
+ }
+ else if (strcmp(argv[1], "--without-threads") == 0)
+ {
+ printf("no threads\n");
+ *av += 1;
+ *ac -= 1;
+ }
+}
diff --git a/Tests/TestDriver/testExtraStuff.cxx b/Tests/TestDriver/testExtraStuff.cxx
new file mode 100644
index 0000000000..bfd073c9a9
--- /dev/null
+++ b/Tests/TestDriver/testExtraStuff.cxx
@@ -0,0 +1,4 @@
+int testExtraStuff()
+{
+ return 1;
+}
diff --git a/Tests/TestDriver/testExtraStuff2.cxx b/Tests/TestDriver/testExtraStuff2.cxx
new file mode 100644
index 0000000000..e755dbe024
--- /dev/null
+++ b/Tests/TestDriver/testExtraStuff2.cxx
@@ -0,0 +1,4 @@
+int testExtraStuff2()
+{
+ return 1;
+}
diff --git a/Tests/TestDriver/testExtraStuff3.cxx b/Tests/TestDriver/testExtraStuff3.cxx
new file mode 100644
index 0000000000..9c239d42a0
--- /dev/null
+++ b/Tests/TestDriver/testExtraStuff3.cxx
@@ -0,0 +1,4 @@
+int testExtraStuff3()
+{
+ return 1;
+}
diff --git a/Tests/Testing/CMakeLists.txt b/Tests/Testing/CMakeLists.txt
new file mode 100644
index 0000000000..8f69cbe442
--- /dev/null
+++ b/Tests/Testing/CMakeLists.txt
@@ -0,0 +1,59 @@
+#
+# Testing
+#
+cmake_minimum_required (VERSION 2.7)
+project (Testing)
+
+#
+# Lib and exe path
+#
+set (LIBRARY_OUTPUT_PATH
+ ${Testing_BINARY_DIR}/bin/ CACHE PATH
+ "Single output directory for building all libraries.")
+
+set (EXECUTABLE_OUTPUT_PATH
+ ${Testing_BINARY_DIR}/bin/ CACHE PATH
+ "Single output directory for building all executables.")
+
+#
+# Where will executable tests be written ?
+#
+if (EXECUTABLE_OUTPUT_PATH)
+ set (CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
+else ()
+ set (CXX_TEST_PATH .)
+endif ()
+
+#
+# Include Dart
+# (will also set NSLOOKUP, HOSTNAME, etc.)
+#
+include (${CMAKE_ROOT}/Modules/Dart.cmake)
+
+#
+# Extra coverage
+#
+build_command(BUILD_COMMAND_VAR ${CMAKE_MAKE_PROGRAM})
+build_name(BUILD_NAME_VAR)
+site_name(SITE_NAME_VAR)
+
+#
+# Enable testing
+#
+enable_testing()
+
+#
+# Add test
+#
+add_executable(testing testing.cxx)
+add_test(testing.1 ${Testing_BINARY_DIR}/bin/testing)
+
+#
+# skip level test
+#
+add_subdirectory(Sub/Sub2)
+
+# Per-config target name and generator expressions.
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../PerConfig PerConfig)
+add_test(NAME testing.perconfig COMMAND perconfig)
+add_test(NAME testing.driver COMMAND ${PerConfig_COMMAND})
diff --git a/Tests/Testing/DartConfig.cmake b/Tests/Testing/DartConfig.cmake
new file mode 100644
index 0000000000..de6ea4b412
--- /dev/null
+++ b/Tests/Testing/DartConfig.cmake
@@ -0,0 +1,24 @@
+# Dashboard is opened for submissions for a 24 hour period starting at
+# the specified NIGHLY_START_TIME. Time is specified in 24 hour format.
+set (NIGHTLY_START_TIME "23:00:00 EST")
+
+# Dart server to submit results (used by client)
+set (DROP_SITE "")
+set (DROP_LOCATION "")
+set (DROP_SITE_USER "")
+set (DROP_SITE_PASSWORD "")
+set (TRIGGER_SITE "")
+
+# Dart server configuration
+# set (CVS_WEB_URL "")
+# set (CVS_WEB_CVSROOT "")
+# set (USE_DOXYGEN "Off")
+# set (DOXYGEN_URL "")
+# set (GNATS_WEB_URL "")
+
+# Continuous email delivery variables
+# set (CONTINUOUS_FROM "")
+# set (SMTP_MAILHOST "")
+# set (CONTINUOUS_MONITOR_LIST "")
+# set (CONTINUOUS_BASE_URL "")
+
diff --git a/Tests/Testing/Sub/Sub2/CMakeLists.txt b/Tests/Testing/Sub/Sub2/CMakeLists.txt
new file mode 100644
index 0000000000..78f4d1a951
--- /dev/null
+++ b/Tests/Testing/Sub/Sub2/CMakeLists.txt
@@ -0,0 +1,17 @@
+#
+# Add test
+#
+add_executable(testing2 testing2.cxx)
+add_test(testing.2 ${Testing_BINARY_DIR}/bin/testing2)
+
+add_test(NotCycle.a ${CMAKE_COMMAND} -E echo a)
+add_test(NotCycle.test1 ${CMAKE_COMMAND} -E echo test1)
+set_property(TEST NotCycle.test1 PROPERTY DEPENDS NotCycle.a)
+
+add_test(NotCycle.b ${CMAKE_COMMAND} -E echo b)
+add_test(NotCycle.test2 ${CMAKE_COMMAND} -E echo test2)
+set_property(TEST NotCycle.test2 PROPERTY DEPENDS NotCycle.b NotCycle.test1)
+
+add_test(NotCycle.c ${CMAKE_COMMAND} -E echo c)
+add_test(NotCycle.test3 ${CMAKE_COMMAND} -E echo test3)
+set_property(TEST NotCycle.test3 PROPERTY DEPENDS NotCycle.c NotCycle.test1 NotCycle.test2)
diff --git a/Tests/Testing/Sub/Sub2/testing2.cxx b/Tests/Testing/Sub/Sub2/testing2.cxx
new file mode 100644
index 0000000000..1482f27e53
--- /dev/null
+++ b/Tests/Testing/Sub/Sub2/testing2.cxx
@@ -0,0 +1,4 @@
+int main ()
+{
+ return 0;
+}
diff --git a/Tests/Testing/testing.cxx b/Tests/Testing/testing.cxx
new file mode 100644
index 0000000000..1482f27e53
--- /dev/null
+++ b/Tests/Testing/testing.cxx
@@ -0,0 +1,4 @@
+int main ()
+{
+ return 0;
+}
diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt
new file mode 100644
index 0000000000..6a6e9b6c7c
--- /dev/null
+++ b/Tests/TestsWorkingDirectory/CMakeLists.txt
@@ -0,0 +1,42 @@
+cmake_minimum_required(VERSION 2.6)
+project(TestsWorkingDirectoryProj)
+
+add_executable(WorkingDirectory main.c)
+
+enable_testing()
+
+set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
+
+add_test(NAME WorkingDirectory0 COMMAND WorkingDirectory "${CMAKE_BINARY_DIR}")
+
+add_test(NAME WorkingDirectory1 COMMAND WorkingDirectory "${CMAKE_BINARY_DIR}")
+set_tests_properties(WorkingDirectory1 PROPERTIES
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
+)
+
+string(REGEX REPLACE "/[^/]*$" "" _parent_dir "${CMAKE_BINARY_DIR}")
+
+add_test(NAME WorkingDirectory2 COMMAND WorkingDirectory "${_parent_dir}")
+set_tests_properties(WorkingDirectory2 PROPERTIES
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/.."
+)
+
+set(_default_cwd "${CMAKE_BINARY_DIR}")
+
+# FIXME: How to deal with /debug, /release, etc. with VS or Xcode?
+if(${CMAKE_GENERATOR} MATCHES "Makefiles")
+add_test(WorkingDirectory3 ${EXECUTABLE_OUTPUT_PATH}/WorkingDirectory ${_default_cwd})
+endif()
+
+add_test(NAME WorkingDirectory4 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND WorkingDirectory ${CMAKE_BINARY_DIR})
+
+string(REGEX REPLACE "/[^/]*$" "" _parent_dir "${CMAKE_BINARY_DIR}")
+
+add_test(NAME WorkingDirectory5 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/.. COMMAND WorkingDirectory ${_parent_dir})
+
+# FIXME: How to deal with /debug, /release, etc. with VS or Xcode?
+if(${CMAKE_GENERATOR} MATCHES "Makefiles")
+add_test(WorkingDirectory6 ${EXECUTABLE_OUTPUT_PATH}/WorkingDirectory ${_default_cwd} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..)
+endif()
+
+add_subdirectory(subdir)
diff --git a/Tests/TestsWorkingDirectory/main.c b/Tests/TestsWorkingDirectory/main.c
new file mode 100644
index 0000000000..19f2f14afd
--- /dev/null
+++ b/Tests/TestsWorkingDirectory/main.c
@@ -0,0 +1,64 @@
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__))
+
+#include <io.h>
+#include <direct.h>
+
+#if defined(__WATCOMC__)
+#include <direct.h>
+#define _getcwd getcwd
+#endif
+
+static const char* Getcwd(char* buf, unsigned int len)
+{
+ const char* ret = _getcwd(buf, len);
+ char* p = NULL;
+ if(!ret)
+ {
+ fprintf(stderr, "No current working directory.\n");
+ abort();
+ }
+ // make sure the drive letter is capital
+ if(strlen(buf) > 1 && buf[1] == ':')
+ {
+ buf[0] = toupper(buf[0]);
+ }
+ for(p = buf; *p; ++p)
+ {
+ if(*p == '\\')
+ {
+ *p = '/';
+ }
+ }
+ return ret;
+}
+
+#else
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+static const char* Getcwd(char* buf, unsigned int len)
+{
+ const char* ret = getcwd(buf, len);
+ if(!ret)
+ {
+ fprintf(stderr, "No current working directory\n");
+ abort();
+ }
+ return ret;
+}
+
+#endif
+
+int main(int argc, char *argv[])
+{
+ char buf[2048];
+ const char *cwd = Getcwd(buf, sizeof(buf));
+
+ return strcmp(cwd, argv[1]);
+}
diff --git a/Tests/TestsWorkingDirectory/subdir/CMakeLists.txt b/Tests/TestsWorkingDirectory/subdir/CMakeLists.txt
new file mode 100644
index 0000000000..c16b1db43a
--- /dev/null
+++ b/Tests/TestsWorkingDirectory/subdir/CMakeLists.txt
@@ -0,0 +1,31 @@
+add_test(NAME WorkingDirectory-Subdir0 COMMAND WorkingDirectory "${CMAKE_CURRENT_BINARY_DIR}")
+
+add_test(NAME WorkingDirectory-Subdir1 COMMAND WorkingDirectory "${CMAKE_CURRENT_BINARY_DIR}")
+set_tests_properties(WorkingDirectory-Subdir1 PROPERTIES
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+)
+
+string(REGEX REPLACE "/[^/]*$" "" _parent_dir "${CMAKE_CURRENT_BINARY_DIR}")
+
+add_test(NAME WorkingDirectory-Subdir2 COMMAND WorkingDirectory "${_parent_dir}")
+set_tests_properties(WorkingDirectory-Subdir2 PROPERTIES
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/.."
+)
+
+set(_default_cwd "${CMAKE_CURRENT_BINARY_DIR}")
+
+# FIXME: How to deal with /debug, /release, etc. with VS or Xcode?
+if(${CMAKE_GENERATOR} MATCHES "Makefiles")
+add_test(WorkingDirectory-Subdir3 ${EXECUTABLE_OUTPUT_PATH}/WorkingDirectory ${_default_cwd})
+endif()
+
+add_test(NAME WorkingDirectory-Subdir4 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND WorkingDirectory ${CMAKE_CURRENT_BINARY_DIR})
+
+string(REGEX REPLACE "/[^/]*$" "" _parent_dir "${CMAKE_CURRENT_BINARY_DIR}")
+
+add_test(NAME WorkingDirectory-Subdir5 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/.. COMMAND WorkingDirectory ${_parent_dir})
+
+# FIXME: How to deal with /debug, /release, etc. with VS or Xcode?
+if(${CMAKE_GENERATOR} MATCHES "Makefiles")
+add_test(WorkingDirectory-Subdir6 ${EXECUTABLE_OUTPUT_PATH}/WorkingDirectory ${_default_cwd} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..)
+endif()
diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt
new file mode 100644
index 0000000000..a4d949006f
--- /dev/null
+++ b/Tests/TryCompile/CMakeLists.txt
@@ -0,0 +1,300 @@
+cmake_minimum_required (VERSION 2.6)
+project(TryCompile)
+
+macro(TEST_ASSERT value msg)
+ if (NOT ${value})
+ message (SEND_ERROR "Assertion failure:" ${msg} )
+ endif ()
+endmacro()
+
+macro(TEST_FAIL value msg)
+ if (${value})
+ message (SEND_ERROR "Failing test succeeded:" ${msg} )
+ endif ()
+endmacro()
+
+macro(TEST_EXPECT_EXACT command expected)
+ if(NOT "x${result}" STREQUAL "x${expected}")
+ message(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
+ endif()
+endmacro()
+
+macro(TEST_EXPECT_CONTAINS command expected)
+ if(NOT "${result}" MATCHES "${expected}")
+ message(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
+ endif()
+endmacro()
+
+
+# try to compile a file that should compile
+# also check that COPY_FILE works
+try_compile(SHOULD_PASS
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/pass.c
+ OUTPUT_VARIABLE TRY_OUT
+ COPY_FILE ${TryCompile_BINARY_DIR}/CopyOfPass
+ )
+
+if(NOT SHOULD_PASS)
+ message(SEND_ERROR "should pass failed ${TRY_OUT}")
+endif()
+if(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfPass")
+ message(SEND_ERROR "COPY_FILE to \"${TryCompile_BINARY_DIR}/CopyOfPass\" failed")
+else()
+ file(REMOVE "${TryCompile_BINARY_DIR}/CopyOfPass")
+endif()
+
+# try to compile a file that should compile
+# also check that COPY_FILE_ERROR works
+file(WRITE ${TryCompile_BINARY_DIR}/invalid "")
+try_compile(SHOULD_PASS
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/pass.c
+ OUTPUT_VARIABLE TRY_OUT
+ COPY_FILE ${TryCompile_BINARY_DIR}/invalid/path
+ COPY_FILE_ERROR _captured
+ )
+if(NOT SHOULD_PASS)
+ message(SEND_ERROR "should pass failed ${TRY_OUT}")
+endif()
+if(NOT _captured MATCHES "Cannot copy output executable.*/invalid/path")
+ message(SEND_ERROR "COPY_FILE_ERROR did not capture expected message")
+endif()
+
+# try to compile a file that should not compile
+try_compile(SHOULD_FAIL
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/fail.c
+ OUTPUT_VARIABLE TRY_OUT)
+if(SHOULD_FAIL)
+ message(SEND_ERROR "Should fail passed ${TRY_OUT}")
+endif()
+
+# try to compile a file that should compile
+try_compile(SHOULD_PASS
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/pass.c
+ OUTPUT_VARIABLE TRY_OUT)
+if(NOT SHOULD_PASS)
+ message(SEND_ERROR "should pass failed ${TRY_OUT}")
+endif()
+
+# try to compile a file that should not compile
+try_compile(SHOULD_FAIL
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/fail.c
+ OUTPUT_VARIABLE TRY_OUT)
+if(SHOULD_FAIL)
+ message(SEND_ERROR "Should fail passed ${TRY_OUT}")
+endif()
+
+# try to compile two files that should compile
+try_compile(SHOULD_PASS
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ SOURCES ${TryCompile_SOURCE_DIR}/pass2a.c ${TryCompile_SOURCE_DIR}/pass2b.cxx
+ OUTPUT_VARIABLE TRY_OUT)
+if(NOT SHOULD_PASS)
+ message(SEND_ERROR "should pass failed ${TRY_OUT}")
+endif()
+
+# try to compile two files that should not compile
+try_compile(SHOULD_FAIL
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ SOURCES ${TryCompile_SOURCE_DIR}/fail2a.c ${TryCompile_SOURCE_DIR}/fail2b.c
+ OUTPUT_VARIABLE TRY_OUT)
+if(SHOULD_FAIL)
+ message(SEND_ERROR "Should fail passed ${TRY_OUT}")
+endif()
+
+# try to compile a file that should compile
+set(_c_flags "${CMAKE_C_FLAGS}")
+if(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D \"TESTDEF\"")
+elseif(WATCOM)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -dTESTDEF")
+else()
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \"-DTESTDEF\"")
+endif()
+try_compile(SHOULD_PASS
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/testdef.c
+ OUTPUT_VARIABLE TRY_OUT)
+if(NOT SHOULD_PASS)
+ message(SEND_ERROR "should pass failed ${TRY_OUT}")
+endif()
+set(CMAKE_C_FLAGS "${_c_flags}")
+
+if(NOT SHOULD_FAIL)
+ if(SHOULD_PASS)
+ message("All Tests passed, ignore all previous output.")
+ else()
+ message("Test failed")
+ endif()
+else()
+ message("Test failed")
+endif()
+try_compile(CMAKE_ANSI_FOR_SCOPE
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
+if (CMAKE_ANSI_FOR_SCOPE)
+ message("Compiler supports ansi for")
+else()
+ message("Compiler does not support ansi for scope")
+endif()
+
+try_compile(CMAKE_ANSI_FOR_SCOPE
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
+if (CMAKE_ANSI_FOR_SCOPE)
+ message("Compiler supports ansi for")
+else()
+ message("Compiler does not support ansi for scope")
+endif()
+
+message("use the module now")
+include(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
+if (CMAKE_ANSI_FOR_SCOPE)
+ message("Compiler supports ansi for")
+else()
+ message("Compiler does not support ansi for scope")
+endif()
+
+message("Testing try_compile project mode")
+try_compile(TEST_INNER
+ ${TryCompile_BINARY_DIR}/CMakeFiles/Inner
+ ${TryCompile_SOURCE_DIR}/Inner
+ TryCompileInner innerexe
+ OUTPUT_VARIABLE output)
+TEST_ASSERT(TEST_INNER "try_compile project mode failed:\n${output}")
+
+add_executable(TryCompile pass.c)
+
+######################################
+
+# now two tests for TRY_RUN
+
+# try to run a file that should compile and run without error
+# also check that OUTPUT_VARIABLE contains both the compile output
+# and the run output
+try_run(SHOULD_RUN SHOULD_COMPILE
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/exit_success.c
+ OUTPUT_VARIABLE TRY_OUT)
+if(NOT SHOULD_COMPILE)
+ message(SEND_ERROR "exit_success failed compiling: ${TRY_OUT}")
+endif()
+if(NOT "${SHOULD_RUN}" STREQUAL "0")
+ message(SEND_ERROR "exit_success failed running with exit code ${SHOULD_RUN}")
+endif()
+# check the compile output for the filename
+if(NOT "${TRY_OUT}" MATCHES "exit_success")
+ message(SEND_ERROR " TRY_OUT didn't contain \"exit_success\": \"${TRY_OUT}\"")
+endif()
+# check the run output
+if(NOT "${TRY_OUT}" MATCHES "hello world")
+ message(SEND_ERROR " TRY_OUT didn't contain \"hello world\": \"${TRY_OUT}\"")
+endif()
+
+try_run(ARG_TEST_RUN ARG_TEST_COMPILE
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/expect_arg.c
+ OUTPUT_VARIABLE TRY_OUT
+ ARGS arg1 arg2)
+if(NOT ARG_TEST_COMPILE)
+ message(SEND_ERROR "expect_arg failed compiling: ${TRY_OUT}")
+endif()
+if(NOT "${ARG_TEST_RUN}" STREQUAL "0")
+ message(SEND_ERROR "expect_arg failed running with exit code ${ARG_TEST_RUN} ${TRY_OUT}")
+endif()
+
+# try to run a file that should compile and run, but return an error
+try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/exit_with_error.c
+ COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
+ RUN_OUTPUT_VARIABLE RUN_OUTPUT)
+
+if(NOT SHOULD_COMPILE)
+ message(STATUS " exit_with_error failed compiling: ${COMPILE_OUTPUT}")
+endif()
+if("${SHOULD_EXIT_WITH_ERROR}" STREQUAL "0")
+ message(SEND_ERROR " exit_with_error passed with exit code ${SHOULD_EXIT_WITH_ERROR}")
+endif()
+
+# check the compile output, it should contain the filename
+if(NOT "${COMPILE_OUTPUT}" MATCHES "exit_with_error")
+ message(SEND_ERROR " COMPILE_OUT didn't contain \"exit_with_error\": \"${COMPILE_OUTPUT}\"")
+endif()
+#... but not the run time output
+if("${COMPILE_OUTPUT}" MATCHES "hello world")
+ message(SEND_ERROR " COMPILE_OUT contains the run output: \"${COMPILE_OUTPUT}\"")
+endif()
+# check the run output, it should stdout
+if(NOT "${RUN_OUTPUT}" MATCHES "hello world")
+ message(SEND_ERROR " RUN_OUTPUT didn't contain \"hello world\": \"${RUN_OUTPUT}\"")
+endif()
+
+#######################################################################
+#
+# also test that the CHECK_C_SOURCE_COMPILES, CHECK_CXX_SOURCE_COMPILES
+# CHECK_C_SOURCE_RUNS and CHECK_CXX_SOURCE_RUNS macros work
+
+include(CheckCSourceCompiles)
+include(CheckCXXSourceCompiles)
+include(CheckCSourceRuns)
+include(CheckCXXSourceRuns)
+
+CHECK_C_SOURCE_COMPILES("I dont build" C_BUILD_SHOULD_FAIL)
+CHECK_C_SOURCE_COMPILES("int main() {return 0;}" C_BUILD_SHOULD_WORK)
+CHECK_C_SOURCE_RUNS("int main() {return 1;}" C_RUN_SHOULD_FAIL)
+CHECK_C_SOURCE_RUNS("int main() {return 0;}" C_RUN_SHOULD_WORK)
+
+TEST_FAIL(C_BUILD_SHOULD_FAIL "CHECK_C_SOURCE_COMPILES() succeeded, but should have failed")
+TEST_ASSERT(C_BUILD_SHOULD_WORK "CHECK_C_SOURCE_COMPILES() failed")
+TEST_FAIL(C_RUN_SHOULD_FAIL "CHECK_C_SOURCE_RUNS() succeeded, but should have failed")
+TEST_ASSERT(C_RUN_SHOULD_WORK "CHECK_C_SOURCE_RUNS() failed")
+
+CHECK_CXX_SOURCE_COMPILES("I dont build" CXX_BUILD_SHOULD_FAIL)
+CHECK_CXX_SOURCE_COMPILES("int main() {return 0;}" CXX_BUILD_SHOULD_WORK)
+CHECK_CXX_SOURCE_RUNS("int main() {return 2;}" CXX_RUN_SHOULD_FAIL)
+CHECK_CXX_SOURCE_RUNS("int main() {return 0;}" CXX_RUN_SHOULD_WORK)
+
+TEST_FAIL(CXX_BUILD_SHOULD_FAIL "CHECK_CXX_SOURCE_COMPILES() succeeded, but should have failed")
+TEST_ASSERT(CXX_BUILD_SHOULD_WORK "CHECK_CXX_SOURCE_COMPILES() failed")
+TEST_FAIL(CXX_RUN_SHOULD_FAIL "CHECK_CXX_SOURCE_RUNS() succeeded, but should have failed")
+TEST_ASSERT(CXX_RUN_SHOULD_WORK "CHECK_CXX_SOURCE_RUNS() failed")
+
+foreach(lang C CXX)
+ if(NOT "${CMAKE_${lang}_COMPILER_ID}" MATCHES "^(PathScale)$")
+ set(${lang}_DD --)
+ endif()
+endforeach()
+
+unset(C_BOGUS_FLAG CACHE)
+include(CheckCCompilerFlag)
+CHECK_C_COMPILER_FLAG(${C_DD}-_this_is_not_a_flag_ C_BOGUS_FLAG)
+TEST_FAIL(C_BOGUS_FLAG "CHECK_C_COMPILER_FLAG() succeeded, but should have failed")
+
+unset(CXX_BOGUS_FLAG CACHE)
+include(CheckCXXCompilerFlag)
+CHECK_CXX_COMPILER_FLAG(${CXX_DD}-_this_is_not_a_flag_ CXX_BOGUS_FLAG)
+TEST_FAIL(CXX_BOGUS_FLAG "CHECK_CXX_COMPILER_FLAG() succeeded, but should have failed")
+
+if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
+ unset(C_STRICT_PROTOTYPES CACHE)
+ CHECK_C_COMPILER_FLAG("-Werror;-Wstrict-prototypes" C_STRICT_PROTOTYPES)
+ TEST_ASSERT(C_STRICT_PROTOTYPES "CHECK_C_COMPILER_FLAG failed -Werror -Wstrict-prototypes")
+endif()
+
+#######################################################################
+#
+# also test that the check_prototype_definition macro works
+
+include(CheckPrototypeDefinition)
+
+check_prototype_definition(remove
+ "int remove(const char *pathname)"
+ "0"
+ "stdio.h"
+ TEST_REMOVE_PROTO)
+test_assert(TEST_REMOVE_PROTO "check_prototype_definition for remove() failed")
diff --git a/Tests/TryCompile/Inner/CMakeLists.txt b/Tests/TryCompile/Inner/CMakeLists.txt
new file mode 100644
index 0000000000..d62bcc4dd2
--- /dev/null
+++ b/Tests/TryCompile/Inner/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.6)
+project(TryCompileInner C)
+
+try_compile(SHOULD_PASS
+ ${TryCompileInner_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompileInner_SOURCE_DIR}/../pass.c
+ OUTPUT_VARIABLE TRY_OUT
+ )
+if(NOT SHOULD_PASS)
+ message(FATAL_ERROR "Inner try-compile SHOULD_PASS failed!")
+endif()
+
+add_library(innerlib innerlib.c)
+add_executable(innerexe innerexe.c)
+target_link_libraries(innerexe innerlib)
diff --git a/Tests/TryCompile/Inner/innerexe.c b/Tests/TryCompile/Inner/innerexe.c
new file mode 100644
index 0000000000..9b121a17d7
--- /dev/null
+++ b/Tests/TryCompile/Inner/innerexe.c
@@ -0,0 +1,2 @@
+extern int innerlib(void);
+int main() { return innerlib(); }
diff --git a/Tests/TryCompile/Inner/innerlib.c b/Tests/TryCompile/Inner/innerlib.c
new file mode 100644
index 0000000000..0ce11799be
--- /dev/null
+++ b/Tests/TryCompile/Inner/innerlib.c
@@ -0,0 +1 @@
+int innerlib(void) { return 0; }
diff --git a/Tests/TryCompile/exit_success.c b/Tests/TryCompile/exit_success.c
new file mode 100644
index 0000000000..82f5b5f825
--- /dev/null
+++ b/Tests/TryCompile/exit_success.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("hello world\n");
+ return 0;
+}
diff --git a/Tests/TryCompile/exit_with_error.c b/Tests/TryCompile/exit_with_error.c
new file mode 100644
index 0000000000..f3c523d378
--- /dev/null
+++ b/Tests/TryCompile/exit_with_error.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("hello world\n");
+ return -1;
+}
diff --git a/Tests/TryCompile/expect_arg.c b/Tests/TryCompile/expect_arg.c
new file mode 100644
index 0000000000..f18e03f60b
--- /dev/null
+++ b/Tests/TryCompile/expect_arg.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <string.h>
+int main(int ac, char*av[])
+{
+ int i;
+ printf("ac = [%d]\n", ac);
+ for(i =0; i < ac; i++)
+ {
+ printf("arg[%d] = %s\n", i, av[i]);
+ }
+ if(ac == 3)
+ {
+ if(strcmp(av[1], "arg1") ==0
+ && strcmp(av[2], "arg2") ==0)
+ {
+ printf("arg1 and arg2 present and accounted for!\n");
+ return 0;
+ }
+ }
+ printf("arg1 and arg2 missing!\n");
+ return -1;
+}
diff --git a/Tests/TryCompile/fail.c b/Tests/TryCompile/fail.c
new file mode 100644
index 0000000000..b915ebe4cb
--- /dev/null
+++ b/Tests/TryCompile/fail.c
@@ -0,0 +1 @@
+asdflkjasdlj
diff --git a/Tests/TryCompile/fail2a.c b/Tests/TryCompile/fail2a.c
new file mode 100644
index 0000000000..78f2de106c
--- /dev/null
+++ b/Tests/TryCompile/fail2a.c
@@ -0,0 +1 @@
+int main(void) { return 0; }
diff --git a/Tests/TryCompile/fail2b.c b/Tests/TryCompile/fail2b.c
new file mode 100644
index 0000000000..5ee809c047
--- /dev/null
+++ b/Tests/TryCompile/fail2b.c
@@ -0,0 +1 @@
+does_not_compile
diff --git a/Tests/TryCompile/pass.c b/Tests/TryCompile/pass.c
new file mode 100644
index 0000000000..43e8a7ee03
--- /dev/null
+++ b/Tests/TryCompile/pass.c
@@ -0,0 +1,6 @@
+int main()
+{
+ return 0;
+}
+
+
diff --git a/Tests/TryCompile/pass2a.c b/Tests/TryCompile/pass2a.c
new file mode 100644
index 0000000000..bbfe6d5814
--- /dev/null
+++ b/Tests/TryCompile/pass2a.c
@@ -0,0 +1,2 @@
+extern int pass2b(void);
+int main() { return pass2b(); }
diff --git a/Tests/TryCompile/pass2b.cxx b/Tests/TryCompile/pass2b.cxx
new file mode 100644
index 0000000000..4c539e21d0
--- /dev/null
+++ b/Tests/TryCompile/pass2b.cxx
@@ -0,0 +1 @@
+extern "C" int pass2b(void) { return 0; }
diff --git a/Tests/TryCompile/testdef.c b/Tests/TryCompile/testdef.c
new file mode 100644
index 0000000000..5401e7183a
--- /dev/null
+++ b/Tests/TryCompile/testdef.c
@@ -0,0 +1,4 @@
+#ifndef TESTDEF
+# error "TESTDEF should be defined!"
+#endif
+int main(void) { return 0; }
diff --git a/Tests/Tutorial/Step1/CMakeLists.txt b/Tests/Tutorial/Step1/CMakeLists.txt
new file mode 100644
index 0000000000..e461d3c8b3
--- /dev/null
+++ b/Tests/Tutorial/Step1/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required (VERSION 2.6)
+project (Tutorial)
+
+# The version number.
+set (Tutorial_VERSION_MAJOR 1)
+set (Tutorial_VERSION_MINOR 0)
+
+# configure a header file to pass some of the CMake settings
+# to the source code
+configure_file (
+ "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
+ "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ )
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+include_directories("${PROJECT_BINARY_DIR}")
+
+# add the executable
+add_executable(Tutorial tutorial.cxx)
diff --git a/Tests/Tutorial/Step1/TutorialConfig.h.in b/Tests/Tutorial/Step1/TutorialConfig.h.in
new file mode 100644
index 0000000000..5395a06710
--- /dev/null
+++ b/Tests/Tutorial/Step1/TutorialConfig.h.in
@@ -0,0 +1,4 @@
+// the configured options and settings for Tutorial
+#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
+#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
+
diff --git a/Tests/Tutorial/Step1/tutorial.cxx b/Tests/Tutorial/Step1/tutorial.cxx
new file mode 100644
index 0000000000..8ab6dc3067
--- /dev/null
+++ b/Tests/Tutorial/Step1/tutorial.cxx
@@ -0,0 +1,23 @@
+// A simple program that computes the square root of a number
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "TutorialConfig.h"
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf(stdout,"%s Version %d.%d\n",
+ argv[0],
+ Tutorial_VERSION_MAJOR,
+ Tutorial_VERSION_MINOR);
+ fprintf(stdout,"Usage: %s number\n",argv[0]);
+ return 1;
+ }
+ double inputValue = atof(argv[1]);
+ double outputValue = sqrt(inputValue);
+ fprintf(stdout,"The square root of %g is %g\n",
+ inputValue, outputValue);
+ return 0;
+}
diff --git a/Tests/Tutorial/Step2/CMakeLists.txt b/Tests/Tutorial/Step2/CMakeLists.txt
new file mode 100644
index 0000000000..cf1d30ee29
--- /dev/null
+++ b/Tests/Tutorial/Step2/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required (VERSION 2.6)
+project (Tutorial)
+
+# The version number.
+set (Tutorial_VERSION_MAJOR 1)
+set (Tutorial_VERSION_MINOR 0)
+
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
+# configure a header file to pass some of the CMake settings
+# to the source code
+configure_file (
+ "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
+ "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ )
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+include_directories ("${PROJECT_BINARY_DIR}")
+
+# add the MathFunctions library?
+if (USE_MYMATH)
+ include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
+ add_subdirectory (MathFunctions)
+ set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
+endif ()
+
+# add the executable
+add_executable (Tutorial tutorial.cxx)
+target_link_libraries (Tutorial ${EXTRA_LIBS})
diff --git a/Tests/Tutorial/Step2/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step2/MathFunctions/CMakeLists.txt
new file mode 100644
index 0000000000..8b443a6599
--- /dev/null
+++ b/Tests/Tutorial/Step2/MathFunctions/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(MathFunctions mysqrt.cxx)
diff --git a/Tests/Tutorial/Step2/MathFunctions/MathFunctions.h b/Tests/Tutorial/Step2/MathFunctions/MathFunctions.h
new file mode 100644
index 0000000000..cd36bccffd
--- /dev/null
+++ b/Tests/Tutorial/Step2/MathFunctions/MathFunctions.h
@@ -0,0 +1 @@
+double mysqrt(double x);
diff --git a/Tests/Tutorial/Step2/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step2/MathFunctions/mysqrt.cxx
new file mode 100644
index 0000000000..62523f69fb
--- /dev/null
+++ b/Tests/Tutorial/Step2/MathFunctions/mysqrt.cxx
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include "MathFunctions.h"
+
+// a hack square root calculation using simple operations
+double mysqrt(double x)
+{
+ if (x <= 0)
+ {
+ return 0;
+ }
+
+ double result;
+ double delta;
+ result = x;
+
+ // do ten iterations
+ int i;
+ for (i = 0; i < 10; ++i)
+ {
+ if (result <= 0)
+ {
+ result = 0.1;
+ }
+ delta = x - (result*result);
+ result = result + 0.5*delta/result;
+ fprintf(stdout,"Computing sqrt of %g to be %g\n",x,result);
+ }
+ return result;
+}
diff --git a/Tests/Tutorial/Step2/TutorialConfig.h.in b/Tests/Tutorial/Step2/TutorialConfig.h.in
new file mode 100644
index 0000000000..25a06020ac
--- /dev/null
+++ b/Tests/Tutorial/Step2/TutorialConfig.h.in
@@ -0,0 +1,5 @@
+// the configured options and settings for Tutorial
+#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
+#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
+#cmakedefine USE_MYMATH
+
diff --git a/Tests/Tutorial/Step2/tutorial.cxx b/Tests/Tutorial/Step2/tutorial.cxx
new file mode 100644
index 0000000000..82b416f11b
--- /dev/null
+++ b/Tests/Tutorial/Step2/tutorial.cxx
@@ -0,0 +1,34 @@
+// A simple program that computes the square root of a number
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "TutorialConfig.h"
+
+#ifdef USE_MYMATH
+#include "MathFunctions.h"
+#endif
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf(stdout,"%s Version %d.%d\n",
+ argv[0],
+ Tutorial_VERSION_MAJOR,
+ Tutorial_VERSION_MINOR);
+ fprintf(stdout,"Usage: %s number\n",argv[0]);
+ return 1;
+ }
+
+ double inputValue = atof(argv[1]);
+
+#ifdef USE_MYMATH
+ double outputValue = mysqrt(inputValue);
+#else
+ double outputValue = sqrt(inputValue);
+#endif
+
+ fprintf(stdout,"The square root of %g is %g\n",
+ inputValue, outputValue);
+ return 0;
+}
diff --git a/Tests/Tutorial/Step3/CMakeLists.txt b/Tests/Tutorial/Step3/CMakeLists.txt
new file mode 100644
index 0000000000..762302bc57
--- /dev/null
+++ b/Tests/Tutorial/Step3/CMakeLists.txt
@@ -0,0 +1,68 @@
+cmake_minimum_required (VERSION 2.6)
+project (Tutorial)
+
+# The version number.
+set (Tutorial_VERSION_MAJOR 1)
+set (Tutorial_VERSION_MINOR 0)
+
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
+# configure a header file to pass some of the CMake settings
+# to the source code
+configure_file (
+ "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
+ "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ )
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+include_directories ("${PROJECT_BINARY_DIR}")
+
+# add the MathFunctions library?
+if (USE_MYMATH)
+ include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
+ add_subdirectory (MathFunctions)
+ set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
+endif ()
+
+# add the executable
+add_executable (Tutorial tutorial.cxx)
+target_link_libraries (Tutorial ${EXTRA_LIBS})
+
+# add the install targets
+install (TARGETS Tutorial DESTINATION bin)
+install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ DESTINATION include)
+
+
+# enable testing
+enable_testing ()
+
+# does the application run
+add_test (TutorialRuns Tutorial 25)
+
+# does it sqrt of 25
+add_test (TutorialComp25 Tutorial 25)
+set_tests_properties (TutorialComp25
+ PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5"
+ )
+
+# does it handle negative numbers
+add_test (TutorialNegative Tutorial -25)
+set_tests_properties (TutorialNegative
+ PROPERTIES PASS_REGULAR_EXPRESSION "-25 is 0"
+ )
+
+# does it handle small numbers
+add_test (TutorialSmall Tutorial 0.0001)
+set_tests_properties (TutorialSmall
+ PROPERTIES PASS_REGULAR_EXPRESSION "0.0001 is 0.01"
+ )
+
+# does the usage message work?
+add_test (TutorialUsage Tutorial)
+set_tests_properties (TutorialUsage
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION "Usage:.*number"
+ )
diff --git a/Tests/Tutorial/Step3/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step3/MathFunctions/CMakeLists.txt
new file mode 100644
index 0000000000..f386036c3a
--- /dev/null
+++ b/Tests/Tutorial/Step3/MathFunctions/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_library(MathFunctions mysqrt.cxx)
+
+install (TARGETS MathFunctions DESTINATION bin)
+install (FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Step3/MathFunctions/MathFunctions.h b/Tests/Tutorial/Step3/MathFunctions/MathFunctions.h
new file mode 100644
index 0000000000..cd36bccffd
--- /dev/null
+++ b/Tests/Tutorial/Step3/MathFunctions/MathFunctions.h
@@ -0,0 +1 @@
+double mysqrt(double x);
diff --git a/Tests/Tutorial/Step3/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step3/MathFunctions/mysqrt.cxx
new file mode 100644
index 0000000000..62523f69fb
--- /dev/null
+++ b/Tests/Tutorial/Step3/MathFunctions/mysqrt.cxx
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include "MathFunctions.h"
+
+// a hack square root calculation using simple operations
+double mysqrt(double x)
+{
+ if (x <= 0)
+ {
+ return 0;
+ }
+
+ double result;
+ double delta;
+ result = x;
+
+ // do ten iterations
+ int i;
+ for (i = 0; i < 10; ++i)
+ {
+ if (result <= 0)
+ {
+ result = 0.1;
+ }
+ delta = x - (result*result);
+ result = result + 0.5*delta/result;
+ fprintf(stdout,"Computing sqrt of %g to be %g\n",x,result);
+ }
+ return result;
+}
diff --git a/Tests/Tutorial/Step3/TutorialConfig.h.in b/Tests/Tutorial/Step3/TutorialConfig.h.in
new file mode 100644
index 0000000000..25a06020ac
--- /dev/null
+++ b/Tests/Tutorial/Step3/TutorialConfig.h.in
@@ -0,0 +1,5 @@
+// the configured options and settings for Tutorial
+#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
+#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
+#cmakedefine USE_MYMATH
+
diff --git a/Tests/Tutorial/Step3/tutorial.cxx b/Tests/Tutorial/Step3/tutorial.cxx
new file mode 100644
index 0000000000..82b416f11b
--- /dev/null
+++ b/Tests/Tutorial/Step3/tutorial.cxx
@@ -0,0 +1,34 @@
+// A simple program that computes the square root of a number
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "TutorialConfig.h"
+
+#ifdef USE_MYMATH
+#include "MathFunctions.h"
+#endif
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf(stdout,"%s Version %d.%d\n",
+ argv[0],
+ Tutorial_VERSION_MAJOR,
+ Tutorial_VERSION_MINOR);
+ fprintf(stdout,"Usage: %s number\n",argv[0]);
+ return 1;
+ }
+
+ double inputValue = atof(argv[1]);
+
+#ifdef USE_MYMATH
+ double outputValue = mysqrt(inputValue);
+#else
+ double outputValue = sqrt(inputValue);
+#endif
+
+ fprintf(stdout,"The square root of %g is %g\n",
+ inputValue, outputValue);
+ return 0;
+}
diff --git a/Tests/Tutorial/Step4/CMakeLists.txt b/Tests/Tutorial/Step4/CMakeLists.txt
new file mode 100644
index 0000000000..6994aa1ceb
--- /dev/null
+++ b/Tests/Tutorial/Step4/CMakeLists.txt
@@ -0,0 +1,68 @@
+cmake_minimum_required (VERSION 2.6)
+project (Tutorial)
+
+# The version number.
+set (Tutorial_VERSION_MAJOR 1)
+set (Tutorial_VERSION_MINOR 0)
+
+# does this system provide the log and exp functions?
+include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
+check_function_exists (log HAVE_LOG)
+check_function_exists (exp HAVE_EXP)
+
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
+# configure a header file to pass some of the CMake settings
+# to the source code
+configure_file (
+ "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
+ "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ )
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+include_directories ("${PROJECT_BINARY_DIR}")
+
+# add the MathFunctions library?
+if (USE_MYMATH)
+ include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
+ add_subdirectory (MathFunctions)
+ set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
+endif ()
+
+# add the executable
+add_executable (Tutorial tutorial.cxx)
+target_link_libraries (Tutorial ${EXTRA_LIBS})
+
+# add the install targets
+install (TARGETS Tutorial DESTINATION bin)
+install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ DESTINATION include)
+
+# enable testing
+enable_testing ()
+
+# does the application run
+add_test (TutorialRuns Tutorial 25)
+
+# does the usage message work?
+add_test (TutorialUsage Tutorial)
+set_tests_properties (TutorialUsage
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION "Usage:.*number"
+ )
+
+#define a macro to simplify adding tests
+macro (do_test arg result)
+ add_test (TutorialComp${arg} Tutorial ${arg})
+ set_tests_properties (TutorialComp${arg}
+ PROPERTIES PASS_REGULAR_EXPRESSION ${result}
+ )
+endmacro ()
+
+# do a bunch of result based tests
+do_test (25 "25 is 5")
+do_test (-25 "-25 is 0")
+do_test (0.0001 "0.0001 is 0.01")
+
diff --git a/Tests/Tutorial/Step4/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step4/MathFunctions/CMakeLists.txt
new file mode 100644
index 0000000000..f386036c3a
--- /dev/null
+++ b/Tests/Tutorial/Step4/MathFunctions/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_library(MathFunctions mysqrt.cxx)
+
+install (TARGETS MathFunctions DESTINATION bin)
+install (FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Step4/MathFunctions/MathFunctions.h b/Tests/Tutorial/Step4/MathFunctions/MathFunctions.h
new file mode 100644
index 0000000000..cd36bccffd
--- /dev/null
+++ b/Tests/Tutorial/Step4/MathFunctions/MathFunctions.h
@@ -0,0 +1 @@
+double mysqrt(double x);
diff --git a/Tests/Tutorial/Step4/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step4/MathFunctions/mysqrt.cxx
new file mode 100644
index 0000000000..d081d11d20
--- /dev/null
+++ b/Tests/Tutorial/Step4/MathFunctions/mysqrt.cxx
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include "MathFunctions.h"
+#include "TutorialConfig.h"
+
+#include <math.h>
+
+// a hack square root calculation using simple operations
+double mysqrt(double x)
+{
+ if (x <= 0)
+ {
+ return 0;
+ }
+
+ double result;
+
+ // if we have both log and exp then use them
+#if defined(HAVE_LOG) && defined (HAVE_EXP)
+ result = exp(log(x)*0.5);
+ fprintf(stdout,"Computing sqrt of %g to be %g using log\n",x,result);
+#else
+ double delta;
+ result = x;
+
+ // do ten iterations
+ int i;
+ for (i = 0; i < 10; ++i)
+ {
+ if (result <= 0)
+ {
+ result = 0.1;
+ }
+ delta = x - (result*result);
+ result = result + 0.5*delta/result;
+ fprintf(stdout,"Computing sqrt of %g to be %g\n",x,result);
+ }
+#endif
+ return result;
+}
diff --git a/Tests/Tutorial/Step4/TutorialConfig.h.in b/Tests/Tutorial/Step4/TutorialConfig.h.in
new file mode 100644
index 0000000000..a0912656a6
--- /dev/null
+++ b/Tests/Tutorial/Step4/TutorialConfig.h.in
@@ -0,0 +1,9 @@
+// the configured options and settings for Tutorial
+#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
+#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
+#cmakedefine USE_MYMATH
+
+// does the platform provide exp and log functions?
+#cmakedefine HAVE_LOG
+#cmakedefine HAVE_EXP
+
diff --git a/Tests/Tutorial/Step4/tutorial.cxx b/Tests/Tutorial/Step4/tutorial.cxx
new file mode 100644
index 0000000000..82b416f11b
--- /dev/null
+++ b/Tests/Tutorial/Step4/tutorial.cxx
@@ -0,0 +1,34 @@
+// A simple program that computes the square root of a number
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "TutorialConfig.h"
+
+#ifdef USE_MYMATH
+#include "MathFunctions.h"
+#endif
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf(stdout,"%s Version %d.%d\n",
+ argv[0],
+ Tutorial_VERSION_MAJOR,
+ Tutorial_VERSION_MINOR);
+ fprintf(stdout,"Usage: %s number\n",argv[0]);
+ return 1;
+ }
+
+ double inputValue = atof(argv[1]);
+
+#ifdef USE_MYMATH
+ double outputValue = mysqrt(inputValue);
+#else
+ double outputValue = sqrt(inputValue);
+#endif
+
+ fprintf(stdout,"The square root of %g is %g\n",
+ inputValue, outputValue);
+ return 0;
+}
diff --git a/Tests/Tutorial/Step5/CMakeLists.txt b/Tests/Tutorial/Step5/CMakeLists.txt
new file mode 100644
index 0000000000..e40b676b49
--- /dev/null
+++ b/Tests/Tutorial/Step5/CMakeLists.txt
@@ -0,0 +1,72 @@
+cmake_minimum_required (VERSION 2.6)
+project (Tutorial)
+
+# The version number.
+set (Tutorial_VERSION_MAJOR 1)
+set (Tutorial_VERSION_MINOR 0)
+
+# does this system provide the log and exp functions?
+include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
+check_function_exists (log HAVE_LOG)
+check_function_exists (exp HAVE_EXP)
+
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
+# configure a header file to pass some of the CMake settings
+# to the source code
+configure_file (
+ "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
+ "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ )
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+include_directories ("${PROJECT_BINARY_DIR}")
+
+# add the MathFunctions library?
+if (USE_MYMATH)
+ include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
+ add_subdirectory (MathFunctions)
+ set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
+endif ()
+
+# add the executable
+add_executable (Tutorial tutorial.cxx)
+target_link_libraries (Tutorial ${EXTRA_LIBS})
+
+# add the install targets
+install (TARGETS Tutorial DESTINATION bin)
+install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ DESTINATION include)
+
+# enable testing
+enable_testing ()
+
+# does the application run
+add_test (TutorialRuns Tutorial 25)
+
+# does the usage message work?
+add_test (TutorialUsage Tutorial)
+set_tests_properties (TutorialUsage
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION "Usage:.*number"
+ )
+
+#define a macro to simplify adding tests
+macro (do_test arg result)
+ add_test (TutorialComp${arg} Tutorial ${arg})
+ set_tests_properties (TutorialComp${arg}
+ PROPERTIES PASS_REGULAR_EXPRESSION ${result}
+ )
+endmacro ()
+
+# do a bunch of result based tests
+do_test (4 "4 is 2")
+do_test (9 "9 is 3")
+do_test (5 "5 is 2.236")
+do_test (7 "7 is 2.645")
+do_test (25 "25 is 5")
+do_test (-25 "-25 is 0")
+do_test (0.0001 "0.0001 is 0.01")
+
diff --git a/Tests/Tutorial/Step5/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step5/MathFunctions/CMakeLists.txt
new file mode 100644
index 0000000000..453a46332e
--- /dev/null
+++ b/Tests/Tutorial/Step5/MathFunctions/CMakeLists.txt
@@ -0,0 +1,17 @@
+# first we add the executable that generates the table
+# add the binary tree directory to the search path for include files
+include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
+
+add_executable(MakeTable MakeTable.cxx )
+# add the command to generate the source code
+add_custom_command (
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ DEPENDS MakeTable
+ )
+
+# add the main library
+add_library(MathFunctions mysqrt.cxx ${CMAKE_CURRENT_BINARY_DIR}/Table.h )
+
+install (TARGETS MathFunctions DESTINATION bin)
+install (FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Step5/MathFunctions/MakeTable.cxx b/Tests/Tutorial/Step5/MathFunctions/MakeTable.cxx
new file mode 100644
index 0000000000..ef98d5fdcb
--- /dev/null
+++ b/Tests/Tutorial/Step5/MathFunctions/MakeTable.cxx
@@ -0,0 +1,35 @@
+// A simple program that builds a sqrt table
+#include <stdio.h>
+#include <math.h>
+
+int main (int argc, char *argv[])
+{
+ int i;
+ double result;
+
+ // make sure we have enough arguments
+ if (argc < 2)
+ {
+ return 1;
+ }
+
+ // open the output file
+ FILE *fout = fopen(argv[1],"w");
+ if (!fout)
+ {
+ return 1;
+ }
+
+ // create a source file with a table of square roots
+ fprintf(fout,"double sqrtTable[] = {\n");
+ for (i = 0; i < 10; ++i)
+ {
+ result = sqrt(static_cast<double>(i));
+ fprintf(fout,"%g,\n",result);
+ }
+
+ // close the table with a zero
+ fprintf(fout,"0};\n");
+ fclose(fout);
+ return 0;
+}
diff --git a/Tests/Tutorial/Step5/MathFunctions/MathFunctions.h b/Tests/Tutorial/Step5/MathFunctions/MathFunctions.h
new file mode 100644
index 0000000000..cd36bccffd
--- /dev/null
+++ b/Tests/Tutorial/Step5/MathFunctions/MathFunctions.h
@@ -0,0 +1 @@
+double mysqrt(double x);
diff --git a/Tests/Tutorial/Step5/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step5/MathFunctions/mysqrt.cxx
new file mode 100644
index 0000000000..1f9b887191
--- /dev/null
+++ b/Tests/Tutorial/Step5/MathFunctions/mysqrt.cxx
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include "MathFunctions.h"
+#include "TutorialConfig.h"
+
+// include the generated table
+#include "Table.h"
+
+#include <math.h>
+
+// a hack square root calculation using simple operations
+double mysqrt(double x)
+{
+ if (x <= 0)
+ {
+ return 0;
+ }
+
+ double result;
+
+ // if we have both log and exp then use them
+ double delta;
+
+ // use the table to help find an initial value
+ result = x;
+ if (x >= 1 && x < 10)
+ {
+ result = sqrtTable[static_cast<int>(x)];
+ }
+
+ // do ten iterations
+ int i;
+ for (i = 0; i < 10; ++i)
+ {
+ if (result <= 0)
+ {
+ result = 0.1;
+ }
+ delta = x - (result*result);
+ result = result + 0.5*delta/result;
+ fprintf(stdout,"Computing sqrt of %g to be %g\n",x,result);
+ }
+
+ return result;
+}
diff --git a/Tests/Tutorial/Step5/TutorialConfig.h.in b/Tests/Tutorial/Step5/TutorialConfig.h.in
new file mode 100644
index 0000000000..a0912656a6
--- /dev/null
+++ b/Tests/Tutorial/Step5/TutorialConfig.h.in
@@ -0,0 +1,9 @@
+// the configured options and settings for Tutorial
+#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
+#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
+#cmakedefine USE_MYMATH
+
+// does the platform provide exp and log functions?
+#cmakedefine HAVE_LOG
+#cmakedefine HAVE_EXP
+
diff --git a/Tests/Tutorial/Step5/tutorial.cxx b/Tests/Tutorial/Step5/tutorial.cxx
new file mode 100644
index 0000000000..82b416f11b
--- /dev/null
+++ b/Tests/Tutorial/Step5/tutorial.cxx
@@ -0,0 +1,34 @@
+// A simple program that computes the square root of a number
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "TutorialConfig.h"
+
+#ifdef USE_MYMATH
+#include "MathFunctions.h"
+#endif
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf(stdout,"%s Version %d.%d\n",
+ argv[0],
+ Tutorial_VERSION_MAJOR,
+ Tutorial_VERSION_MINOR);
+ fprintf(stdout,"Usage: %s number\n",argv[0]);
+ return 1;
+ }
+
+ double inputValue = atof(argv[1]);
+
+#ifdef USE_MYMATH
+ double outputValue = mysqrt(inputValue);
+#else
+ double outputValue = sqrt(inputValue);
+#endif
+
+ fprintf(stdout,"The square root of %g is %g\n",
+ inputValue, outputValue);
+ return 0;
+}
diff --git a/Tests/Tutorial/Step6/CMakeLists.txt b/Tests/Tutorial/Step6/CMakeLists.txt
new file mode 100644
index 0000000000..0fb7cac5f7
--- /dev/null
+++ b/Tests/Tutorial/Step6/CMakeLists.txt
@@ -0,0 +1,78 @@
+cmake_minimum_required (VERSION 2.6)
+project (Tutorial)
+
+# The version number.
+set (Tutorial_VERSION_MAJOR 1)
+set (Tutorial_VERSION_MINOR 0)
+
+# does this system provide the log and exp functions?
+include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
+check_function_exists (log HAVE_LOG)
+check_function_exists (exp HAVE_EXP)
+
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
+# configure a header file to pass some of the CMake settings
+# to the source code
+configure_file (
+ "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
+ "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ )
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+include_directories ("${PROJECT_BINARY_DIR}")
+
+# add the MathFunctions library?
+if (USE_MYMATH)
+ include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
+ add_subdirectory (MathFunctions)
+ set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
+endif ()
+
+# add the executable
+add_executable (Tutorial tutorial.cxx)
+target_link_libraries (Tutorial ${EXTRA_LIBS})
+
+# add the install targets
+install (TARGETS Tutorial DESTINATION bin)
+install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ DESTINATION include)
+
+# enable testing
+enable_testing ()
+
+# does the application run
+add_test (TutorialRuns Tutorial 25)
+
+# does the usage message work?
+add_test (TutorialUsage Tutorial)
+set_tests_properties (TutorialUsage
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION "Usage:.*number"
+ )
+
+#define a macro to simplify adding tests
+macro (do_test arg result)
+ add_test (TutorialComp${arg} Tutorial ${arg})
+ set_tests_properties (TutorialComp${arg}
+ PROPERTIES PASS_REGULAR_EXPRESSION ${result}
+ )
+endmacro ()
+
+# do a bunch of result based tests
+do_test (4 "4 is 2")
+do_test (9 "9 is 3")
+do_test (5 "5 is 2.236")
+do_test (7 "7 is 2.645")
+do_test (25 "25 is 5")
+do_test (-25 "-25 is 0")
+do_test (0.0001 "0.0001 is 0.01")
+
+# build a CPack driven installer package
+include (InstallRequiredSystemLibraries)
+set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
+set (CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
+set (CPACK_PACKAGE_VERSION_MINOR "${Tutorial_VERSION_MINOR}")
+include (CPack)
diff --git a/Tests/Tutorial/Step6/License.txt b/Tests/Tutorial/Step6/License.txt
new file mode 100644
index 0000000000..673d724537
--- /dev/null
+++ b/Tests/Tutorial/Step6/License.txt
@@ -0,0 +1,2 @@
+This is the open source License.txt file introduced in
+CMake/Tests/Tutorial/Step6...
diff --git a/Tests/Tutorial/Step6/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step6/MathFunctions/CMakeLists.txt
new file mode 100644
index 0000000000..70a35f662e
--- /dev/null
+++ b/Tests/Tutorial/Step6/MathFunctions/CMakeLists.txt
@@ -0,0 +1,24 @@
+# first we add the executable that generates the table
+add_executable(MakeTable MakeTable.cxx)
+
+# add the command to generate the source code
+add_custom_command (
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ DEPENDS MakeTable
+ COMMAND MakeTable
+ ARGS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ )
+
+set_source_files_properties (
+ mysqrt.cxx PROPERTIES
+ OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ )
+
+# add the binary tree directory to the search path for include files
+include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
+
+# add the main library
+add_library(MathFunctions mysqrt.cxx)
+
+install (TARGETS MathFunctions DESTINATION bin)
+install (FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Step6/MathFunctions/MakeTable.cxx b/Tests/Tutorial/Step6/MathFunctions/MakeTable.cxx
new file mode 100644
index 0000000000..ef98d5fdcb
--- /dev/null
+++ b/Tests/Tutorial/Step6/MathFunctions/MakeTable.cxx
@@ -0,0 +1,35 @@
+// A simple program that builds a sqrt table
+#include <stdio.h>
+#include <math.h>
+
+int main (int argc, char *argv[])
+{
+ int i;
+ double result;
+
+ // make sure we have enough arguments
+ if (argc < 2)
+ {
+ return 1;
+ }
+
+ // open the output file
+ FILE *fout = fopen(argv[1],"w");
+ if (!fout)
+ {
+ return 1;
+ }
+
+ // create a source file with a table of square roots
+ fprintf(fout,"double sqrtTable[] = {\n");
+ for (i = 0; i < 10; ++i)
+ {
+ result = sqrt(static_cast<double>(i));
+ fprintf(fout,"%g,\n",result);
+ }
+
+ // close the table with a zero
+ fprintf(fout,"0};\n");
+ fclose(fout);
+ return 0;
+}
diff --git a/Tests/Tutorial/Step6/MathFunctions/MathFunctions.h b/Tests/Tutorial/Step6/MathFunctions/MathFunctions.h
new file mode 100644
index 0000000000..cd36bccffd
--- /dev/null
+++ b/Tests/Tutorial/Step6/MathFunctions/MathFunctions.h
@@ -0,0 +1 @@
+double mysqrt(double x);
diff --git a/Tests/Tutorial/Step6/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step6/MathFunctions/mysqrt.cxx
new file mode 100644
index 0000000000..1f9b887191
--- /dev/null
+++ b/Tests/Tutorial/Step6/MathFunctions/mysqrt.cxx
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include "MathFunctions.h"
+#include "TutorialConfig.h"
+
+// include the generated table
+#include "Table.h"
+
+#include <math.h>
+
+// a hack square root calculation using simple operations
+double mysqrt(double x)
+{
+ if (x <= 0)
+ {
+ return 0;
+ }
+
+ double result;
+
+ // if we have both log and exp then use them
+ double delta;
+
+ // use the table to help find an initial value
+ result = x;
+ if (x >= 1 && x < 10)
+ {
+ result = sqrtTable[static_cast<int>(x)];
+ }
+
+ // do ten iterations
+ int i;
+ for (i = 0; i < 10; ++i)
+ {
+ if (result <= 0)
+ {
+ result = 0.1;
+ }
+ delta = x - (result*result);
+ result = result + 0.5*delta/result;
+ fprintf(stdout,"Computing sqrt of %g to be %g\n",x,result);
+ }
+
+ return result;
+}
diff --git a/Tests/Tutorial/Step6/TutorialConfig.h.in b/Tests/Tutorial/Step6/TutorialConfig.h.in
new file mode 100644
index 0000000000..a0912656a6
--- /dev/null
+++ b/Tests/Tutorial/Step6/TutorialConfig.h.in
@@ -0,0 +1,9 @@
+// the configured options and settings for Tutorial
+#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
+#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
+#cmakedefine USE_MYMATH
+
+// does the platform provide exp and log functions?
+#cmakedefine HAVE_LOG
+#cmakedefine HAVE_EXP
+
diff --git a/Tests/Tutorial/Step6/tutorial.cxx b/Tests/Tutorial/Step6/tutorial.cxx
new file mode 100644
index 0000000000..82b416f11b
--- /dev/null
+++ b/Tests/Tutorial/Step6/tutorial.cxx
@@ -0,0 +1,34 @@
+// A simple program that computes the square root of a number
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "TutorialConfig.h"
+
+#ifdef USE_MYMATH
+#include "MathFunctions.h"
+#endif
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf(stdout,"%s Version %d.%d\n",
+ argv[0],
+ Tutorial_VERSION_MAJOR,
+ Tutorial_VERSION_MINOR);
+ fprintf(stdout,"Usage: %s number\n",argv[0]);
+ return 1;
+ }
+
+ double inputValue = atof(argv[1]);
+
+#ifdef USE_MYMATH
+ double outputValue = mysqrt(inputValue);
+#else
+ double outputValue = sqrt(inputValue);
+#endif
+
+ fprintf(stdout,"The square root of %g is %g\n",
+ inputValue, outputValue);
+ return 0;
+}
diff --git a/Tests/Tutorial/Step7/CMakeLists.txt b/Tests/Tutorial/Step7/CMakeLists.txt
new file mode 100644
index 0000000000..d9a92fbef0
--- /dev/null
+++ b/Tests/Tutorial/Step7/CMakeLists.txt
@@ -0,0 +1,82 @@
+cmake_minimum_required (VERSION 2.6)
+project (Tutorial)
+
+# The version number.
+set (Tutorial_VERSION_MAJOR 1)
+set (Tutorial_VERSION_MINOR 0)
+
+# does this system provide the log and exp functions?
+include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
+check_function_exists (log HAVE_LOG)
+check_function_exists (exp HAVE_EXP)
+
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
+# configure a header file to pass some of the CMake settings
+# to the source code
+configure_file (
+ "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
+ "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ )
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+include_directories ("${PROJECT_BINARY_DIR}")
+
+# add the MathFunctions library?
+if (USE_MYMATH)
+ include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
+ add_subdirectory (MathFunctions)
+ set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
+endif ()
+
+# add the executable
+add_executable (Tutorial tutorial.cxx)
+target_link_libraries (Tutorial ${EXTRA_LIBS})
+
+# add the install targets
+install (TARGETS Tutorial DESTINATION bin)
+install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ DESTINATION include)
+
+# enable testing
+enable_testing ()
+
+# does the application run
+add_test (TutorialRuns Tutorial 25)
+
+# does the usage message work?
+add_test (TutorialUsage Tutorial)
+set_tests_properties (TutorialUsage
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION "Usage:.*number"
+ )
+
+#define a macro to simplify adding tests
+macro (do_test arg result)
+ add_test (TutorialComp${arg} Tutorial ${arg})
+ set_tests_properties (TutorialComp${arg}
+ PROPERTIES PASS_REGULAR_EXPRESSION ${result}
+ )
+endmacro ()
+
+# do a bunch of result based tests
+do_test (4 "4 is 2")
+do_test (9 "9 is 3")
+do_test (5 "5 is 2.236")
+do_test (7 "7 is 2.645")
+do_test (25 "25 is 5")
+do_test (-25 "-25 is 0")
+do_test (0.0001 "0.0001 is 0.01")
+
+# build a CPack driven installer package
+include (InstallRequiredSystemLibraries)
+set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
+set (CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
+set (CPACK_PACKAGE_VERSION_MINOR "${Tutorial_VERSION_MINOR}")
+set (CPACK_PACKAGE_CONTACT "foo@bar.org")
+include (CPack)
+
+# enable dashboard scripting
+include (CTest)
diff --git a/Tests/Tutorial/Step7/CTestConfig.cmake b/Tests/Tutorial/Step7/CTestConfig.cmake
new file mode 100644
index 0000000000..d8f5c4491e
--- /dev/null
+++ b/Tests/Tutorial/Step7/CTestConfig.cmake
@@ -0,0 +1 @@
+set (CTEST_PROJECT_NAME "Tutorial")
diff --git a/Tests/Tutorial/Step7/License.txt b/Tests/Tutorial/Step7/License.txt
new file mode 100644
index 0000000000..673d724537
--- /dev/null
+++ b/Tests/Tutorial/Step7/License.txt
@@ -0,0 +1,2 @@
+This is the open source License.txt file introduced in
+CMake/Tests/Tutorial/Step6...
diff --git a/Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt
new file mode 100644
index 0000000000..70a35f662e
--- /dev/null
+++ b/Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt
@@ -0,0 +1,24 @@
+# first we add the executable that generates the table
+add_executable(MakeTable MakeTable.cxx)
+
+# add the command to generate the source code
+add_custom_command (
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ DEPENDS MakeTable
+ COMMAND MakeTable
+ ARGS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ )
+
+set_source_files_properties (
+ mysqrt.cxx PROPERTIES
+ OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ )
+
+# add the binary tree directory to the search path for include files
+include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
+
+# add the main library
+add_library(MathFunctions mysqrt.cxx)
+
+install (TARGETS MathFunctions DESTINATION bin)
+install (FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx b/Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx
new file mode 100644
index 0000000000..ef98d5fdcb
--- /dev/null
+++ b/Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx
@@ -0,0 +1,35 @@
+// A simple program that builds a sqrt table
+#include <stdio.h>
+#include <math.h>
+
+int main (int argc, char *argv[])
+{
+ int i;
+ double result;
+
+ // make sure we have enough arguments
+ if (argc < 2)
+ {
+ return 1;
+ }
+
+ // open the output file
+ FILE *fout = fopen(argv[1],"w");
+ if (!fout)
+ {
+ return 1;
+ }
+
+ // create a source file with a table of square roots
+ fprintf(fout,"double sqrtTable[] = {\n");
+ for (i = 0; i < 10; ++i)
+ {
+ result = sqrt(static_cast<double>(i));
+ fprintf(fout,"%g,\n",result);
+ }
+
+ // close the table with a zero
+ fprintf(fout,"0};\n");
+ fclose(fout);
+ return 0;
+}
diff --git a/Tests/Tutorial/Step7/MathFunctions/MathFunctions.h b/Tests/Tutorial/Step7/MathFunctions/MathFunctions.h
new file mode 100644
index 0000000000..cd36bccffd
--- /dev/null
+++ b/Tests/Tutorial/Step7/MathFunctions/MathFunctions.h
@@ -0,0 +1 @@
+double mysqrt(double x);
diff --git a/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx
new file mode 100644
index 0000000000..1f9b887191
--- /dev/null
+++ b/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include "MathFunctions.h"
+#include "TutorialConfig.h"
+
+// include the generated table
+#include "Table.h"
+
+#include <math.h>
+
+// a hack square root calculation using simple operations
+double mysqrt(double x)
+{
+ if (x <= 0)
+ {
+ return 0;
+ }
+
+ double result;
+
+ // if we have both log and exp then use them
+ double delta;
+
+ // use the table to help find an initial value
+ result = x;
+ if (x >= 1 && x < 10)
+ {
+ result = sqrtTable[static_cast<int>(x)];
+ }
+
+ // do ten iterations
+ int i;
+ for (i = 0; i < 10; ++i)
+ {
+ if (result <= 0)
+ {
+ result = 0.1;
+ }
+ delta = x - (result*result);
+ result = result + 0.5*delta/result;
+ fprintf(stdout,"Computing sqrt of %g to be %g\n",x,result);
+ }
+
+ return result;
+}
diff --git a/Tests/Tutorial/Step7/TutorialConfig.h.in b/Tests/Tutorial/Step7/TutorialConfig.h.in
new file mode 100644
index 0000000000..a0912656a6
--- /dev/null
+++ b/Tests/Tutorial/Step7/TutorialConfig.h.in
@@ -0,0 +1,9 @@
+// the configured options and settings for Tutorial
+#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
+#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
+#cmakedefine USE_MYMATH
+
+// does the platform provide exp and log functions?
+#cmakedefine HAVE_LOG
+#cmakedefine HAVE_EXP
+
diff --git a/Tests/Tutorial/Step7/build1.cmake b/Tests/Tutorial/Step7/build1.cmake
new file mode 100644
index 0000000000..baa475f287
--- /dev/null
+++ b/Tests/Tutorial/Step7/build1.cmake
@@ -0,0 +1,5 @@
+set(CTEST_SOURCE_DIRECTORY "$ENV{HOME}/Dashboards/My Tests/CMake/Tests/Tutorial/Step7")
+set(CTEST_BINARY_DIRECTORY "${CTEST_SOURCE_DIRECTORY}-build1")
+
+set(CTEST_CMAKE_COMMAND "cmake")
+set(CTEST_COMMAND "ctest -D Experimental")
diff --git a/Tests/Tutorial/Step7/build2.cmake b/Tests/Tutorial/Step7/build2.cmake
new file mode 100644
index 0000000000..c2f2e2e103
--- /dev/null
+++ b/Tests/Tutorial/Step7/build2.cmake
@@ -0,0 +1,9 @@
+set(CTEST_SOURCE_DIRECTORY "$ENV{HOME}/Dashboards/My Tests/CMake/Tests/Tutorial/Step7")
+set(CTEST_BINARY_DIRECTORY "${CTEST_SOURCE_DIRECTORY}-build2")
+set(CTEST_CMAKE_GENERATOR "Visual Studio 8 2005")
+
+CTEST_START("Experimental")
+CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}")
+CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}")
+CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}")
+CTEST_SUBMIT()
diff --git a/Tests/Tutorial/Step7/tutorial.cxx b/Tests/Tutorial/Step7/tutorial.cxx
new file mode 100644
index 0000000000..82b416f11b
--- /dev/null
+++ b/Tests/Tutorial/Step7/tutorial.cxx
@@ -0,0 +1,34 @@
+// A simple program that computes the square root of a number
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "TutorialConfig.h"
+
+#ifdef USE_MYMATH
+#include "MathFunctions.h"
+#endif
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf(stdout,"%s Version %d.%d\n",
+ argv[0],
+ Tutorial_VERSION_MAJOR,
+ Tutorial_VERSION_MINOR);
+ fprintf(stdout,"Usage: %s number\n",argv[0]);
+ return 1;
+ }
+
+ double inputValue = atof(argv[1]);
+
+#ifdef USE_MYMATH
+ double outputValue = mysqrt(inputValue);
+#else
+ double outputValue = sqrt(inputValue);
+#endif
+
+ fprintf(stdout,"The square root of %g is %g\n",
+ inputValue, outputValue);
+ return 0;
+}
diff --git a/Tests/Unset/CMakeLists.txt b/Tests/Unset/CMakeLists.txt
new file mode 100644
index 0000000000..07aa68e7ae
--- /dev/null
+++ b/Tests/Unset/CMakeLists.txt
@@ -0,0 +1,82 @@
+cmake_minimum_required(VERSION 2.6)
+project(Unset C)
+
+# Local variable
+set(x 42)
+if(NOT x EQUAL 42)
+ message(FATAL_ERROR "x!=42")
+endif()
+
+if(NOT DEFINED x)
+ message(FATAL_ERROR "x should be defined!")
+endif()
+
+unset(x)
+if(DEFINED x)
+ message(FATAL_ERROR "x should be undefined now!")
+endif()
+
+# Local variable test unset via set()
+set(x 43)
+if(NOT x EQUAL 43)
+ message(FATAL_ERROR "x!=43")
+endif()
+set(x)
+if(DEFINED x)
+ message(FATAL_ERROR "x should be undefined now!")
+endif()
+
+# Cache variable
+set(BAR "test" CACHE STRING "documentation")
+if(NOT DEFINED BAR)
+ message(FATAL_ERROR "BAR not defined")
+endif()
+
+# Test interaction of cache entries with variables.
+set(BAR "test-var")
+if(NOT "$CACHE{BAR}" STREQUAL "test")
+ message(FATAL_ERROR "\$CACHE{BAR} changed by variable BAR")
+endif()
+if(NOT "${BAR}" STREQUAL "test-var")
+ message(FATAL_ERROR "\${BAR} not separate from \$CACHE{BAR}")
+endif()
+unset(BAR)
+if(NOT "${BAR}" STREQUAL "test")
+ message(FATAL_ERROR "\${BAR} does not fall through to \$CACHE{BAR}")
+endif()
+
+# Test unsetting of CACHE entry.
+unset(BAR CACHE)
+if(DEFINED BAR)
+ message(FATAL_ERROR "BAR still defined")
+endif()
+
+# Test unset(... PARENT_SCOPE)
+function(unset_zots)
+ if(NOT DEFINED ZOT1)
+ message(FATAL_ERROR "ZOT1 is not defined inside function")
+ endif()
+ if(NOT DEFINED ZOT2)
+ message(FATAL_ERROR "ZOT2 is not defined inside function")
+ endif()
+ unset(ZOT1)
+ unset(ZOT2 PARENT_SCOPE)
+ if(DEFINED ZOT1)
+ message(FATAL_ERROR "ZOT1 is defined inside function after unset")
+ endif()
+ if(NOT DEFINED ZOT2)
+ message(FATAL_ERROR
+ "ZOT2 is not defined inside function after unset(... PARENT_SCOPE)")
+ endif()
+endfunction()
+set(ZOT1 1)
+set(ZOT2 2)
+unset_zots()
+if(NOT DEFINED ZOT1)
+ message(FATAL_ERROR "ZOT1 is not still defined after function")
+endif()
+if(DEFINED ZOT2)
+ message(FATAL_ERROR "ZOT2 is still defined after function unset PARENT_SCOPE")
+endif()
+
+add_executable(Unset unset.c)
diff --git a/Tests/Unset/unset.c b/Tests/Unset/unset.c
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/Unset/unset.c
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/VSExcludeFromDefaultBuild/CMakeLists.txt b/Tests/VSExcludeFromDefaultBuild/CMakeLists.txt
new file mode 100644
index 0000000000..d30414b4ba
--- /dev/null
+++ b/Tests/VSExcludeFromDefaultBuild/CMakeLists.txt
@@ -0,0 +1,32 @@
+cmake_minimum_required(VERSION 2.8.9)
+project(VSExcludeFromDefaultBuild)
+
+# First step is to clear all .exe files in output so that possible past
+# failures of this test do not prevent it from succeeding.
+add_custom_target(ClearExes ALL
+ COMMAND "${CMAKE_COMMAND}"
+ -Ddir=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/ClearExes.cmake
+ VERBATIM)
+
+# Make sure ClearExes is executed before other targets are built
+function(add_test_executable target)
+ add_executable("${target}" ${ARGN})
+ add_dependencies("${target}" ClearExes)
+endfunction()
+
+add_test_executable(DefaultBuilt main.c)
+
+add_test_executable(AlwaysBuilt main.c)
+set_target_properties(AlwaysBuilt PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD FALSE)
+
+add_test_executable(NeverBuilt main.c)
+set_target_properties(NeverBuilt PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE)
+
+foreach(config ${CMAKE_CONFIGURATION_TYPES})
+ string(TOUPPER ${config} Config)
+ add_test_executable(BuiltIn${config} main.c)
+ set_target_properties(BuiltIn${config} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE EXCLUDE_FROM_DEFAULT_BUILD_${Config} FALSE)
+ add_test_executable(ExcludedIn${config} main.c)
+ set_target_properties(ExcludedIn${config} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_${Config} TRUE)
+endforeach()
diff --git a/Tests/VSExcludeFromDefaultBuild/ClearExes.cmake b/Tests/VSExcludeFromDefaultBuild/ClearExes.cmake
new file mode 100644
index 0000000000..ece30ad00e
--- /dev/null
+++ b/Tests/VSExcludeFromDefaultBuild/ClearExes.cmake
@@ -0,0 +1,4 @@
+file(GLOB exeFiles "${dir}/*.exe")
+foreach(exeFile IN LISTS exeFiles)
+ file(REMOVE "${exeFile}")
+endforeach()
diff --git a/Tests/VSExcludeFromDefaultBuild/ResultTest.cmake b/Tests/VSExcludeFromDefaultBuild/ResultTest.cmake
new file mode 100644
index 0000000000..8fb00bfadb
--- /dev/null
+++ b/Tests/VSExcludeFromDefaultBuild/ResultTest.cmake
@@ -0,0 +1,23 @@
+message(STATUS "Testing configuration ${activeConfig}.")
+
+macro(TestExists exeName)
+ set(exeFile "${dir}/${activeConfig}/${exeName}.exe")
+ if(${ARGN} EXISTS "${exeFile}")
+ message(STATUS "File ${exeFile} was correctly found ${ARGN} to exist.")
+ else()
+ message(FATAL_ERROR "File ${exeFile} was expected ${ARGN} to exist!")
+ endif()
+endmacro()
+
+TestExists(DefaultBuilt)
+TestExists(AlwaysBuilt)
+TestExists(NeverBuilt NOT)
+foreach(config ${allConfigs})
+ if(config STREQUAL activeConfig)
+ TestExists(BuiltIn${config})
+ TestExists(ExcludedIn${config} NOT)
+ else()
+ TestExists(BuiltIn${config} NOT)
+ TestExists(ExcludedIn${config})
+ endif()
+endforeach()
diff --git a/Tests/VSExcludeFromDefaultBuild/main.c b/Tests/VSExcludeFromDefaultBuild/main.c
new file mode 100644
index 0000000000..8488f4e58f
--- /dev/null
+++ b/Tests/VSExcludeFromDefaultBuild/main.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/VSExternalInclude/CMakeLists.txt b/Tests/VSExternalInclude/CMakeLists.txt
new file mode 100644
index 0000000000..73ea05a299
--- /dev/null
+++ b/Tests/VSExternalInclude/CMakeLists.txt
@@ -0,0 +1,72 @@
+cmake_minimum_required (VERSION 2.6)
+project(VSExternalInclude)
+
+if(${CMAKE_GENERATOR} MATCHES "Visual Studio 6")
+ set(PROJECT_EXT dsp)
+else()
+ set(PROJECT_EXT vcproj)
+endif()
+if(${CMAKE_GENERATOR} MATCHES "Visual Studio 1[0124]")
+ set(PROJECT_EXT vcxproj)
+endif()
+
+# make sure directories exists
+set(LIB1_BINARY_DIR ${VSExternalInclude_BINARY_DIR}/Lib1)
+make_directory("${LIB1_BINARY_DIR}")
+
+set(LIB2_BINARY_DIR ${VSExternalInclude_BINARY_DIR}/Lib2)
+make_directory("${LIB2_BINARY_DIR}")
+
+# generate lib1
+execute_process(
+ COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
+ -A "${CMAKE_GENERATOR_PLATFORM}"
+ -T "${CMAKE_GENERATOR_TOOLSET}" "${VSExternalInclude_SOURCE_DIR}/Lib1"
+ WORKING_DIRECTORY ${LIB1_BINARY_DIR}
+ OUTPUT_VARIABLE OUT
+ ERROR_VARIABLE OUT
+ )
+message("CMAKE Ran with the following output:\n\"${OUT}\"")
+
+# generate lib2
+execute_process(
+ COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
+ -A "${CMAKE_GENERATOR_PLATFORM}"
+ -T "${CMAKE_GENERATOR_TOOLSET}" "${VSExternalInclude_SOURCE_DIR}/Lib2"
+ WORKING_DIRECTORY ${LIB2_BINARY_DIR}
+ OUTPUT_VARIABLE OUT
+ ERROR_VARIABLE OUT
+ )
+message("CMAKE Ran with the following output:\n\"${OUT}\"")
+
+
+include_external_msproject(lib1 ${VSExternalInclude_BINARY_DIR}/Lib1/LIB1.${PROJECT_EXT})
+# lib2 depends on lib1
+include_external_msproject(lib2 ${VSExternalInclude_BINARY_DIR}/Lib2/LIB2.${PROJECT_EXT} lib1)
+
+include_directories(${VSExternalInclude_SOURCE_DIR}/Lib2 ${VSExternalInclude_SOURCE_DIR}/Lib1)
+
+set(SOURCES main.cpp)
+
+add_executable(VSExternalInclude ${SOURCES})
+
+# target depends on lib2
+add_dependencies(VSExternalInclude lib2)
+# VS 10 vcxproj files have depends in them
+# Since lib1 and lib2 do not depend on each other
+# then the vcxproj files do not depend on each other
+# and the sln file can no longer be the only source
+# of that depend. So, for VS 10 make the executable
+# depend on lib1 and lib2
+if(${CMAKE_GENERATOR} MATCHES "Visual Studio 1[0124]")
+ add_dependencies(VSExternalInclude lib1)
+endif()
+
+# Interaction testing between the FOLDER target property and
+# INCLUDE_EXTERNAL_MSPROJECT targets:
+set_target_properties(VSExternalInclude PROPERTIES FOLDER folder1/folder2)
+set_target_properties(lib1 PROPERTIES FOLDER folder1/folder2)
+set_target_properties(lib2 PROPERTIES FOLDER folder1/folder2)
+add_custom_target(EmptyCustomTarget)
+set_target_properties(EmptyCustomTarget PROPERTIES FOLDER folder1/folder2)
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)
diff --git a/Tests/VSExternalInclude/Lib1/CMakeLists.txt b/Tests/VSExternalInclude/Lib1/CMakeLists.txt
new file mode 100644
index 0000000000..9dfac8616e
--- /dev/null
+++ b/Tests/VSExternalInclude/Lib1/CMakeLists.txt
@@ -0,0 +1,6 @@
+set(CMAKE_SUPPRESS_REGENERATION 1)
+project(LIB1)
+
+set(SOURCES lib1.cpp)
+
+add_library(lib1 ${SOURCES})
diff --git a/Tests/VSExternalInclude/Lib1/lib1.cpp b/Tests/VSExternalInclude/Lib1/lib1.cpp
new file mode 100644
index 0000000000..690eb740f3
--- /dev/null
+++ b/Tests/VSExternalInclude/Lib1/lib1.cpp
@@ -0,0 +1,7 @@
+
+#include "lib1.h"
+
+int add1(int num)
+{
+ return num + 1;
+}
diff --git a/Tests/VSExternalInclude/Lib1/lib1.h b/Tests/VSExternalInclude/Lib1/lib1.h
new file mode 100644
index 0000000000..543e71e028
--- /dev/null
+++ b/Tests/VSExternalInclude/Lib1/lib1.h
@@ -0,0 +1,8 @@
+
+#ifndef LIB1_HPP
+#define LIB1_HPP
+
+int add1(int num);
+
+
+#endif
diff --git a/Tests/VSExternalInclude/Lib2/CMakeLists.txt b/Tests/VSExternalInclude/Lib2/CMakeLists.txt
new file mode 100644
index 0000000000..f4513548dd
--- /dev/null
+++ b/Tests/VSExternalInclude/Lib2/CMakeLists.txt
@@ -0,0 +1,8 @@
+set(CMAKE_SUPPRESS_REGENERATION 1)
+project(VSEXTERNAL_LIB2)
+
+include_directories(${VSEXTERNAL_LIB2_SOURCE_DIR}/../Lib1)
+
+set(SOURCES lib2.cpp)
+
+add_library(lib2 ${SOURCES})
diff --git a/Tests/VSExternalInclude/Lib2/lib2.cpp b/Tests/VSExternalInclude/Lib2/lib2.cpp
new file mode 100644
index 0000000000..adc2d29afe
--- /dev/null
+++ b/Tests/VSExternalInclude/Lib2/lib2.cpp
@@ -0,0 +1,9 @@
+
+#include "lib2.h"
+#include "lib1.h"
+
+int add1_and_mult2(int num)
+{
+ int tmp = add1(num);
+ return tmp * 2;
+}
diff --git a/Tests/VSExternalInclude/Lib2/lib2.h b/Tests/VSExternalInclude/Lib2/lib2.h
new file mode 100644
index 0000000000..48bda468d7
--- /dev/null
+++ b/Tests/VSExternalInclude/Lib2/lib2.h
@@ -0,0 +1,10 @@
+
+
+#ifndef LIB2_HPP
+#define LIB2_HPP
+
+#include "lib1.h"
+
+int add1_and_mult2(int num);
+
+#endif
diff --git a/Tests/VSExternalInclude/main.cpp b/Tests/VSExternalInclude/main.cpp
new file mode 100644
index 0000000000..ea1047cb64
--- /dev/null
+++ b/Tests/VSExternalInclude/main.cpp
@@ -0,0 +1,9 @@
+
+#include "lib2.h"
+
+int main(int argc, char** argv)
+{
+ int num = add1_and_mult2(4);
+
+ return 0;
+}
diff --git a/Tests/VSGNUFortran/CMakeLists.txt b/Tests/VSGNUFortran/CMakeLists.txt
new file mode 100644
index 0000000000..229c3156c1
--- /dev/null
+++ b/Tests/VSGNUFortran/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.8)
+project(VSGNUFortran)
+
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
+
+# force the executable to be put out of Debug/Release dir
+# because gmake build of fortran will not be in a config
+# directory, and for easier testing we want the exe and .dll
+# to be in the same directory.
+if(CMAKE_CONFIGURATION_TYPES)
+ foreach(config ${CMAKE_CONFIGURATION_TYPES})
+ string(TOUPPER "${config}" config)
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config}
+ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
+ endforeach()
+endif()
+
+add_subdirectory(subdir)
+include_directories(${VSGNUFortran_BINARY_DIR}/subdir/fortran)
+add_subdirectory(c_code)
+# use a cmake script to run the executable so that PATH
+# can be set with the MinGW/bin in it, and the fortran
+# runtime libraries can be found.
+configure_file(runtest.cmake.in runtest.cmake @ONLY)
diff --git a/Tests/VSGNUFortran/c_code/CMakeLists.txt b/Tests/VSGNUFortran/c_code/CMakeLists.txt
new file mode 100644
index 0000000000..27d22fd356
--- /dev/null
+++ b/Tests/VSGNUFortran/c_code/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(c_using_fortran main.c)
+target_link_libraries(c_using_fortran hello)
diff --git a/Tests/VSGNUFortran/c_code/main.c b/Tests/VSGNUFortran/c_code/main.c
new file mode 100644
index 0000000000..9157cc5f3e
--- /dev/null
+++ b/Tests/VSGNUFortran/c_code/main.c
@@ -0,0 +1,7 @@
+#include <HelloWorldFCMangle.h> /* created by FortranCInterface */
+extern void FC_hello(void);
+int main()
+{
+ FC_hello();
+ return 0;
+}
diff --git a/Tests/VSGNUFortran/runtest.cmake.in b/Tests/VSGNUFortran/runtest.cmake.in
new file mode 100644
index 0000000000..987207bc48
--- /dev/null
+++ b/Tests/VSGNUFortran/runtest.cmake.in
@@ -0,0 +1,23 @@
+get_filename_component(MINGW_PATH "@MINGW_GFORTRAN@" PATH)
+if(NOT EXISTS "${MINGW_PATH}")
+ set(test_exe
+ "@VSGNUFortran_BINARY_DIR@/bin/c_using_fortran@CMAKE_EXECUTABLE_SUFFIX@")
+ message("run: ${test_exe}")
+ execute_process(COMMAND "${test_exe}"
+ RESULT_VARIABLE res)
+ if(NOT "${res}" EQUAL 0)
+ message(FATAL_ERROR "${test_exe} returned a non 0 value")
+ endif()
+ return()
+endif()
+file(TO_NATIVE_PATH "${MINGW_PATH}" MINGW_PATH)
+string(REPLACE "\\" "\\\\" MINGW_PATH "${MINGW_PATH}")
+message("${MINGW_PATH}")
+set(test_exe "@VSGNUFortran_BINARY_DIR@/bin/c_using_fortran.exe")
+set(ENV{PATH} "${MINGW_PATH}";$ENV{PATH})
+message("run ${test_exe}")
+execute_process(COMMAND "${test_exe}"
+ RESULT_VARIABLE res)
+if(NOT "${res}" EQUAL 0)
+ message(FATAL_ERROR "${test_exe} returned a non 0 value")
+endif()
diff --git a/Tests/VSGNUFortran/subdir/CMakeLists.txt b/Tests/VSGNUFortran/subdir/CMakeLists.txt
new file mode 100644
index 0000000000..0b99199539
--- /dev/null
+++ b/Tests/VSGNUFortran/subdir/CMakeLists.txt
@@ -0,0 +1,16 @@
+include(CMakeAddFortranSubdirectory)
+# add the fortran subdirectory as a fortran project
+# the subdir is fortran, the project is FortranHello
+cmake_add_fortran_subdirectory(fortran
+ PROJECT FortranHello # project name in toplevel CMakeLists.txt
+ ARCHIVE_DIR ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
+ RUNTIME_DIR bin # ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+ LIBRARIES hello world # target libraries created
+ CMAKE_COMMAND_LINE
+ -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+ -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
+ -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
+ LINK_LIBRARIES # link interface libraries
+ LINK_LIBS hello world # hello needs world to link
+ NO_EXTERNAL_INSTALL
+ )
diff --git a/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt
new file mode 100644
index 0000000000..3ee1855c33
--- /dev/null
+++ b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt
@@ -0,0 +1,46 @@
+cmake_minimum_required(VERSION 2.8)
+project(FortranHello Fortran C)
+
+# add a function to test for -lsunquad on sunpro sun systems.
+function(test_sunquad result)
+ set( TEST_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/sunq")
+ file(WRITE "${TEST_DIR}/testsunq.f" "
+ PROGRAM TEST
+ END
+ ")
+ file(WRITE ${TEST_DIR}/CMakeLists.txt "
+project(sunq Fortran)
+add_library(sunq SHARED testsunq.f)
+target_link_libraries(sunq sunquad)
+")
+ message(STATUS "looking for -lsunquad")
+ try_compile(RESULT "${TEST_DIR}" "${TEST_DIR}" sunq OUTPUT_VARIABLE OUT)
+ if("${RESULT}")
+ message(STATUS "-lsunquad found")
+ else()
+ message(STATUS "-lsunquad not found")
+ endif()
+ message(STATUS
+ "looking for sunquad:\nRESULT=[${RESULT}]\nOUTPUT=[\n${OUT}\n]")
+ set(${result} "${RESULT}" PARENT_SCOPE)
+endfunction()
+
+# check for the fortran c interface mangling
+include(FortranCInterface)
+FortranCInterface_HEADER(HelloWorldFCMangle.h
+ MACRO_NAMESPACE "FC_"
+ SYMBOL_NAMESPACE "FC_"
+ SYMBOLS hello world)
+add_library(hello SHARED hello.f)
+add_library(world SHARED world.f)
+target_link_libraries(hello world)
+if(CMAKE_Fortran_COMPILER_ID MATCHES SunPro)
+ target_link_libraries(hello fsu)
+ if(CMAKE_Fortran_PLATFORM_ID MATCHES SunOS)
+ target_link_libraries(hello sunmath m)
+ test_sunquad(CMAKE_HAS_SUNQUAD)
+ if(CMAKE_HAS_SUNQUAD)
+ target_link_libraries(hello sunquad)
+ endif()
+ endif()
+endif()
diff --git a/Tests/VSGNUFortran/subdir/fortran/hello.f b/Tests/VSGNUFortran/subdir/fortran/hello.f
new file mode 100644
index 0000000000..e52119add9
--- /dev/null
+++ b/Tests/VSGNUFortran/subdir/fortran/hello.f
@@ -0,0 +1,7 @@
+!DEC$ ATTRIBUTES DLLEXPORT :: HELLO
+ SUBROUTINE HELLO
+
+ PRINT *, 'Hello'
+ CALL WORLD
+
+ END
diff --git a/Tests/VSGNUFortran/subdir/fortran/world.f b/Tests/VSGNUFortran/subdir/fortran/world.f
new file mode 100644
index 0000000000..0598eeea66
--- /dev/null
+++ b/Tests/VSGNUFortran/subdir/fortran/world.f
@@ -0,0 +1,6 @@
+!DEC$ ATTRIBUTES DLLEXPORT :: WORLD
+ SUBROUTINE WORLD
+
+ PRINT *, 'World!'
+
+ END
diff --git a/Tests/VSMASM/CMakeLists.txt b/Tests/VSMASM/CMakeLists.txt
new file mode 100644
index 0000000000..f2570a3091
--- /dev/null
+++ b/Tests/VSMASM/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(VSMASM C ASM_MASM)
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ add_definitions(-DTESTx64)
+else()
+ add_definitions(-DTESTi386)
+ set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /safeseh")
+endif()
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
+add_executable(VSMASM main.c foo.asm)
diff --git a/Tests/VSMASM/foo.asm b/Tests/VSMASM/foo.asm
new file mode 100644
index 0000000000..51cb969314
--- /dev/null
+++ b/Tests/VSMASM/foo.asm
@@ -0,0 +1,7 @@
+ifndef TESTx64
+.386
+.model flat, c
+endif
+.code
+include <foo-proc.asm>
+end
diff --git a/Tests/VSMASM/include/foo-proc.asm b/Tests/VSMASM/include/foo-proc.asm
new file mode 100644
index 0000000000..e8ba5dcb44
--- /dev/null
+++ b/Tests/VSMASM/include/foo-proc.asm
@@ -0,0 +1,4 @@
+foo proc public
+ mov eax,0
+ ret
+foo endp
diff --git a/Tests/VSMASM/main.c b/Tests/VSMASM/main.c
new file mode 100644
index 0000000000..570ba161b3
--- /dev/null
+++ b/Tests/VSMASM/main.c
@@ -0,0 +1,2 @@
+extern int foo(void);
+int main(void) { return foo(); }
diff --git a/Tests/VSMidl/CMakeLists.txt b/Tests/VSMidl/CMakeLists.txt
new file mode 100644
index 0000000000..432506c3ba
--- /dev/null
+++ b/Tests/VSMidl/CMakeLists.txt
@@ -0,0 +1,81 @@
+# This CMakeLists.txt file exists solely to drive the one found in the "src"
+# subdir as an ExternalProject build. The project in "src" cannot build when
+# there is a space in the directory name, so we copy that directory to a place
+# guaranteed not to have a space in the name, build it there, and then copy the
+# resulting output directory back up here into this CMake test's build tree.
+#
+if(NOT DEFINED CMAKE_BUILDNAME)
+ string(REGEX REPLACE "^.*/([^/]+)/[^/]+/([^/]+)$" "\\1" CMAKE_BUILDNAME "${CMAKE_CURRENT_BINARY_DIR}")
+ string(REGEX REPLACE "^.*/([^/]+)/[^/]+/([^/]+)$" "\\2" THIS_TESTNAME "${CMAKE_CURRENT_BINARY_DIR}")
+ string(REPLACE " " "_" CMAKE_BUILDNAME "${CMAKE_BUILDNAME}")
+endif()
+message(STATUS "CMAKE_BUILDNAME='${CMAKE_BUILDNAME}'")
+message(STATUS "THIS_TESTNAME='${THIS_TESTNAME}'")
+
+cmake_minimum_required(VERSION 2.8)
+project(${THIS_TESTNAME})
+
+include(ExternalProject)
+
+if(NOT DEFINED HOME)
+ if(DEFINED ENV{CTEST_REAL_HOME})
+ set(HOME "$ENV{CTEST_REAL_HOME}")
+ else()
+ set(HOME "$ENV{HOME}")
+ endif()
+
+ if(NOT HOME AND WIN32)
+ # Try for USERPROFILE as HOME equivalent:
+ string(REPLACE "\\" "/" HOME "$ENV{USERPROFILE}")
+ endif()
+
+ # But just use root of SystemDrive if HOME contains any spaces:
+ # (Default on XP and earlier...)
+ if(HOME MATCHES " " AND WIN32)
+ string(REPLACE "\\" "/" HOME "$ENV{SystemDrive}")
+ endif()
+ if(HOME MATCHES " ")
+ set(HOME "")
+ endif()
+endif()
+message(STATUS "HOME='${HOME}'")
+
+if(NOT DEFINED url)
+ set(url "${CMAKE_CURRENT_SOURCE_DIR}/src")
+endif()
+message(STATUS "url='${url}'")
+
+set(base_dir "${HOME}/.cmake/Dashboards/${CMAKE_BUILDNAME}/${THIS_TESTNAME}")
+set(binary_dir "${base_dir}/build")
+set(source_dir "${base_dir}/src")
+
+# Source dir for this project exists in the CMake source tree, but we cannot
+# use it in-place since there might be a space in its directory name.
+# Source dir is therefore copied under a '.cmake/Dashboards'
+# dir in your HOME directory to give it a name with no spaces.
+#
+ExternalProject_Add(clean-${PROJECT_NAME}
+ DOWNLOAD_COMMAND ""
+ CONFIGURE_COMMAND ${CMAKE_COMMAND} -E remove_directory "${source_dir}"
+ BUILD_COMMAND ${CMAKE_COMMAND} -E remove_directory "${binary_dir}"
+ INSTALL_COMMAND ""
+ )
+
+ExternalProject_Add(download-${PROJECT_NAME}
+ URL "${url}"
+ SOURCE_DIR "${source_dir}"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ DEPENDS clean-${PROJECT_NAME}
+ )
+
+ExternalProject_Add(build-${PROJECT_NAME}
+ DOWNLOAD_COMMAND ""
+ SOURCE_DIR "${source_dir}"
+ BINARY_DIR "${binary_dir}"
+ INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
+ "${binary_dir}/${CMAKE_CFG_INTDIR}"
+ "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
+ DEPENDS download-${PROJECT_NAME}
+ )
diff --git a/Tests/VSMidl/src/CMakeLists.txt b/Tests/VSMidl/src/CMakeLists.txt
new file mode 100644
index 0000000000..86c04ed981
--- /dev/null
+++ b/Tests/VSMidl/src/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.8)
+project(VSMidl)
+
+if(MSVC_VERSION GREATER 1200)
+ include_directories("${CMAKE_CURRENT_BINARY_DIR}/\$(IntDir)")
+else()
+ # midl generated headers end up directly in CMAKE_CURRENT_BINARY_DIR with
+ # VS6 builds.
+ include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+endif()
+
+add_executable(VSMidl main.cpp test.idl)
diff --git a/Tests/VSMidl/src/main.cpp b/Tests/VSMidl/src/main.cpp
new file mode 100644
index 0000000000..6b78fcc7f5
--- /dev/null
+++ b/Tests/VSMidl/src/main.cpp
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <test.h>
+#include <test_i.c>
+
+int main(int argc, char** argv)
+{
+ IID libid = LIBID_CMakeMidlTestLib;
+ CLSID clsid = CLSID_CMakeMidlTest;
+ IID iid = IID_ICMakeMidlTest;
+
+ printf("Running '%s'\n", argv[0]);
+ printf(" libid starts with '0x%08lx'\n", (long) libid.Data1);
+ printf(" clsid starts with '0x%08lx'\n", (long) clsid.Data1);
+ printf(" iid starts with '0x%08lx'\n", (long) iid.Data1);
+
+ return 0;
+}
diff --git a/Tests/VSMidl/src/test.idl b/Tests/VSMidl/src/test.idl
new file mode 100644
index 0000000000..fd755c7890
--- /dev/null
+++ b/Tests/VSMidl/src/test.idl
@@ -0,0 +1,30 @@
+import "oaidl.idl";
+import "ocidl.idl";
+
+[
+ object,
+ uuid(258CCEBE-8EE4-4A48-B78C-AC53BCD59E28),
+ dual,
+ nonextensible,
+ helpstring("ICMakeTest Interface"),
+ pointer_default(unique)
+]
+interface ICMakeMidlTest : IUnknown
+{
+ [id(1), helpstring("method Method")] HRESULT Method();
+}
+
+[
+ uuid(0537BA59-7EEC-48F8-BD4B-369BC7D9807E),
+]
+library CMakeMidlTestLib
+{
+ [
+ uuid(D2A90807-019A-46E5-BF47-FF4FA4352D2A),
+ helpstring("CMakeMidlTest Class")
+ ]
+ coclass CMakeMidlTest
+ {
+ [default] interface ICMakeMidlTest;
+ };
+}
diff --git a/Tests/VSNsightTegra/AndroidManifest.xml b/Tests/VSNsightTegra/AndroidManifest.xml
new file mode 100644
index 0000000000..951e8f3082
--- /dev/null
+++ b/Tests/VSNsightTegra/AndroidManifest.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.twolibs"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <uses-sdk android:minSdkVersion="3" />
+ <application android:label="@string/app_name">
+ <activity android:name=".TwoLibs"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/Tests/VSNsightTegra/CMakeLists.txt b/Tests/VSNsightTegra/CMakeLists.txt
new file mode 100644
index 0000000000..570733b95d
--- /dev/null
+++ b/Tests/VSNsightTegra/CMakeLists.txt
@@ -0,0 +1,39 @@
+cmake_minimum_required(VERSION 3.0)
+project(VSNsightTegra C CXX)
+
+set(CMAKE_ANDROID_API 15)
+set(CMAKE_ANDROID_GUI 1)
+
+set(FIRST_C_FILES
+ jni/first.c
+ jni/first.h
+ )
+
+source_group(jni FILES ${FIRST_C_FILES})
+add_library(twolib-first ${FIRST_C_FILES})
+
+set(SECOND_C_FILES
+ jni/second.c
+ )
+set(SECOND_JAVA_FILES
+ src/com/example/twolibs/TwoLibs.java
+ )
+set(SECOND_RES_FILES
+ res/values/strings.xml
+ )
+set(SECOND_ANDROID_FILES
+ AndroidManifest.xml
+ )
+
+source_group(jni FILES ${SECOND_C_FILES})
+source_group(res\\values FILES ${SECOND_RES_FILES})
+source_group(src\\com\\example\\twolibs FILES ${SECOND_JAVA_FILES})
+add_executable(twolib-second
+ ${SECOND_C_FILES}
+ ${SECOND_JAVA_FILES}
+ ${SECOND_RES_FILES}
+ ${SECOND_ANDROID_FILES}
+ )
+target_include_directories(twolib-second PUBLIC jni)
+target_link_libraries(twolib-second twolib-first)
+target_link_libraries(twolib-second m) # test linking to library by name
diff --git a/Tests/VSNsightTegra/build.xml b/Tests/VSNsightTegra/build.xml
new file mode 100644
index 0000000000..17a2cc07b9
--- /dev/null
+++ b/Tests/VSNsightTegra/build.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="TwoLibs" default="help">
+ <import file="${sdk.dir}/tools/ant/build.xml" />
+</project>
diff --git a/Tests/VSNsightTegra/jni/first.c b/Tests/VSNsightTegra/jni/first.c
new file mode 100644
index 0000000000..f09e376de0
--- /dev/null
+++ b/Tests/VSNsightTegra/jni/first.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "first.h"
+
+int first(int x, int y)
+{
+ return x + y;
+}
diff --git a/Tests/VSNsightTegra/jni/first.h b/Tests/VSNsightTegra/jni/first.h
new file mode 100644
index 0000000000..d89348015b
--- /dev/null
+++ b/Tests/VSNsightTegra/jni/first.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef FIRST_H
+#define FIRST_H
+
+extern int first(int x, int y);
+
+#endif /* FIRST_H */
diff --git a/Tests/VSNsightTegra/jni/second.c b/Tests/VSNsightTegra/jni/second.c
new file mode 100644
index 0000000000..463184855b
--- /dev/null
+++ b/Tests/VSNsightTegra/jni/second.c
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "first.h"
+#include <jni.h>
+
+jint
+Java_com_example_twolibs_TwoLibs_add( JNIEnv* env,
+ jobject this,
+ jint x,
+ jint y )
+{
+ return first(x, y);
+}
diff --git a/Tests/VSNsightTegra/res/values/strings.xml b/Tests/VSNsightTegra/res/values/strings.xml
new file mode 100644
index 0000000000..858cdb40ee
--- /dev/null
+++ b/Tests/VSNsightTegra/res/values/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">TwoLibs</string>
+</resources>
diff --git a/Tests/VSNsightTegra/src/com/example/twolibs/TwoLibs.java b/Tests/VSNsightTegra/src/com/example/twolibs/TwoLibs.java
new file mode 100644
index 0000000000..ef9da01cf8
--- /dev/null
+++ b/Tests/VSNsightTegra/src/com/example/twolibs/TwoLibs.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.twolibs;
+
+import android.app.Activity;
+import android.widget.TextView;
+import android.os.Bundle;
+
+public class TwoLibs extends Activity
+{
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+
+ TextView tv = new TextView(this);
+ int x = 1000;
+ int y = 42;
+
+ // here, we dynamically load the library at runtime
+ // before calling the native method.
+ //
+ System.loadLibrary("twolib-second");
+
+ int z = add(x, y);
+
+ tv.setText( "The sum of " + x + " and " + y + " is " + z );
+ setContentView(tv);
+ }
+
+ public native int add(int x, int y);
+}
diff --git a/Tests/VSProjectInSubdir/CMakeLists.txt b/Tests/VSProjectInSubdir/CMakeLists.txt
new file mode 100644
index 0000000000..c164a97981
--- /dev/null
+++ b/Tests/VSProjectInSubdir/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.10)
+project(VSProjectInSubdir NONE)
+add_subdirectory(subdir)
diff --git a/Tests/VSProjectInSubdir/subdir/CMakeLists.txt b/Tests/VSProjectInSubdir/subdir/CMakeLists.txt
new file mode 100644
index 0000000000..6c1b6a11a8
--- /dev/null
+++ b/Tests/VSProjectInSubdir/subdir/CMakeLists.txt
@@ -0,0 +1 @@
+add_custom_target(test COMMAND ${CMAKE_COMMAND} -E echo test VERBATIM)
diff --git a/Tests/VSResource/CMakeLists.txt b/Tests/VSResource/CMakeLists.txt
new file mode 100644
index 0000000000..17eb04136d
--- /dev/null
+++ b/Tests/VSResource/CMakeLists.txt
@@ -0,0 +1,52 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(VSResource)
+
+string(REPLACE "/INCREMENTAL:YES" ""
+ CMAKE_EXE_LINKER_FLAGS_DEBUG
+ "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
+
+message(STATUS "CMAKE_RC_COMPILER='${CMAKE_RC_COMPILER}'")
+
+# Because of the following avoidance techniques required for windres and VS6,
+# we recommend using a configured header file, and defining preprocessor
+# symbols via #define code and including that header in the rc file. Using
+# add_definitions is fine for simple definitions (with no spaces and no
+# quoting), but requires avoidance or work-arounds beyond that...
+
+if(CMAKE_RC_COMPILER MATCHES windres)
+ # windres rc compiler does not properly define quoted /D values as strings
+ message(STATUS "CMAKE_RC_COMPILER MATCHES windres")
+ add_definitions(/DCMAKE_RCDEFINE=test.txt)
+ add_definitions(/DCMAKE_RCDEFINE_NO_QUOTED_STRINGS)
+ if(MSYS AND CMAKE_CURRENT_BINARY_DIR MATCHES " ")
+ # windres cannot handle spaces in include dir, and
+ # for the MSys shell we do not convert to shortpath.
+ set(CMAKE_RC_NO_INCLUDE 1)
+ endif()
+elseif(MSVC60)
+ # VS6 rc compiler does not deal well with spaces in a "/D" value, but it can
+ # handle the quoting
+ message(STATUS "MSVC60")
+ add_definitions(/DCMAKE_RCDEFINE="test.txt")
+else()
+ # expected case -- rc compiler is "capable enough"
+ message(STATUS
+ "rc compiler handles quoted strings with spaces in values via /D")
+ set(TEXTFILE_FROM_SOURCE_DIR "textfile, spaces in name, from binary dir")
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test.txt
+ "${CMAKE_CURRENT_BINARY_DIR}/test with spaces.txt" @ONLY)
+ add_definitions(/DCMAKE_RCDEFINE="test with spaces.txt")
+endif()
+
+if(CMAKE_RC_NO_INCLUDE)
+ add_definitions(/DCMAKE_RC_NO_INCLUDE)
+else()
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include.rc.in
+ "${CMAKE_CURRENT_BINARY_DIR}/include.rc" @ONLY)
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+endif()
+
+add_executable(VSResource main.cpp test.rc)
+
+set_property(TARGET VSResource
+ PROPERTY VS_GLOBAL_CMakeTestVsGlobalVariable "test val")
diff --git a/Tests/VSResource/include.rc.in b/Tests/VSResource/include.rc.in
new file mode 100644
index 0000000000..f0f6859800
--- /dev/null
+++ b/Tests/VSResource/include.rc.in
@@ -0,0 +1 @@
+// This file should be included.
diff --git a/Tests/VSResource/main.cpp b/Tests/VSResource/main.cpp
new file mode 100644
index 0000000000..7ee0c74fa3
--- /dev/null
+++ b/Tests/VSResource/main.cpp
@@ -0,0 +1,80 @@
+#include <windows.h>
+#include <stdio.h>
+
+struct x
+{
+ const char *txt;
+};
+
+int main(int argc, char** argv)
+{
+ int ret = 1;
+
+ fprintf(stdout, "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)\n");
+
+#ifdef CMAKE_RCDEFINE
+ fprintf(stdout, "CMAKE_RCDEFINE defined\n");
+#endif
+
+#ifdef CMAKE_RCDEFINE_NO_QUOTED_STRINGS
+ // Expect CMAKE_RCDEFINE to preprocess to exactly test.txt
+ x test;
+ test.txt = "*exactly* test.txt";
+ fprintf(stdout, "CMAKE_RCDEFINE_NO_QUOTED_STRINGS defined\n");
+ fprintf(stdout, "CMAKE_RCDEFINE is %s, and is *not* a string constant\n",
+ CMAKE_RCDEFINE);
+#else
+ // Expect CMAKE_RCDEFINE to be a string:
+ fprintf(stdout, "CMAKE_RCDEFINE='%s', and is a string constant\n",
+ CMAKE_RCDEFINE);
+#endif
+
+ HRSRC hello = ::FindResource(NULL, MAKEINTRESOURCE(1025), "TEXTFILE");
+ if(hello)
+ {
+ fprintf(stdout, "FindResource worked\n");
+ HGLOBAL hgbl = ::LoadResource(NULL, hello);
+ int datasize = (int) ::SizeofResource(NULL, hello);
+ if(hgbl && datasize>0)
+ {
+ fprintf(stdout, "LoadResource worked\n");
+ fprintf(stdout, "SizeofResource returned datasize='%d'\n", datasize);
+ void *data = ::LockResource(hgbl);
+ if (data)
+ {
+ fprintf(stdout, "LockResource worked\n");
+ char *str = (char *) malloc(datasize+4);
+ if (str)
+ {
+ memcpy(str, data, datasize);
+ str[datasize] = 'E';
+ str[datasize+1] = 'O';
+ str[datasize+2] = 'R';
+ str[datasize+3] = 0;
+ fprintf(stdout, "str='%s'\n", str);
+ free(str);
+
+ ret = 0;
+
+#ifdef CMAKE_RCDEFINE_NO_QUOTED_STRINGS
+ fprintf(stdout, "LoadString skipped\n");
+#else
+ char buf[256];
+ if (::LoadString(NULL, 1026, buf, sizeof(buf)) > 0)
+ {
+ fprintf(stdout, "LoadString worked\n");
+ fprintf(stdout, "buf='%s'\n", buf);
+ }
+ else
+ {
+ fprintf(stdout, "LoadString failed\n");
+ ret = 1;
+ }
+#endif
+ }
+ }
+ }
+ }
+
+ return ret;
+}
diff --git a/Tests/VSResource/test.rc b/Tests/VSResource/test.rc
new file mode 100644
index 0000000000..0de4683862
--- /dev/null
+++ b/Tests/VSResource/test.rc
@@ -0,0 +1,20 @@
+#ifdef CMAKE_RCDEFINE
+# ifndef CMAKE_RC_NO_INCLUDE
+# include <include.rc>
+# endif
+
+// This line can compile with either an unquoted or a quoted string
+1025 TEXTFILE CMAKE_RCDEFINE
+
+#ifndef CMAKE_RCDEFINE_NO_QUOTED_STRINGS
+// This block can only be compiled if CMAKE_RCDEFINE preprocesses
+// to a double quoted string
+STRINGTABLE
+BEGIN
+ 1026 CMAKE_RCDEFINE
+END
+#endif
+
+#else
+#error "resource compiler did not get defines from command line!"
+#endif
diff --git a/Tests/VSResource/test.txt b/Tests/VSResource/test.txt
new file mode 100644
index 0000000000..c27c68d1a3
--- /dev/null
+++ b/Tests/VSResource/test.txt
@@ -0,0 +1 @@
+Hello World! (@TEXTFILE_FROM_SOURCE_DIR@)
diff --git a/Tests/VSWinStorePhone/CMakeLists.txt b/Tests/VSWinStorePhone/CMakeLists.txt
new file mode 100644
index 0000000000..0041c75556
--- /dev/null
+++ b/Tests/VSWinStorePhone/CMakeLists.txt
@@ -0,0 +1,114 @@
+cmake_minimum_required(VERSION 3.0)
+project(VSWinStorePhone)
+
+if(MSVC_VERSION GREATER 1700)
+ set(COMPILER_VERSION "12")
+elseif(MSVC_VERSION GREATER 1600)
+ set(COMPILER_VERSION "11")
+endif()
+
+set (APP_MANIFEST_NAME Package.appxmanifest)
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsPhone")
+ set(PLATFORM WP)
+ add_definitions("-DPHONE")
+ if("${CMAKE_SYSTEM_VERSION}" STREQUAL "8.0")
+ set(APP_MANIFEST_NAME WMAppManifest.xml)
+ set(WINDOWS_PHONE8 1)
+ endif()
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
+ set(PLATFORM STORE)
+else()
+ set(PLATFORM DESKTOP)
+ message(FATAL_ERROR "This app supports Store / Phone only. Please edit the target platform.")
+endif()
+
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+
+set(EXE_NAME Direct3DApp1)
+set(SHORT_NAME ${EXE_NAME})
+set(PACKAGE_GUID "6514377e-dfd4-4cdb-80df-4e0366346efc")
+
+if (NOT "${PLATFORM}" STREQUAL "DESKTOP")
+ configure_file(
+ cmake/Package_vc${COMPILER_VERSION}.${PLATFORM}.appxmanifest.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${APP_MANIFEST_NAME}
+ @ONLY)
+endif()
+
+set(SOURCE_FILES
+ Direct3DApp1/CubeRenderer.cpp
+ Direct3DApp1/Direct3DApp1.cpp
+ Direct3DApp1/Direct3DBase.cpp
+ Direct3DApp1/pch.cpp
+ )
+
+set(HEADER_FILES
+ Direct3DApp1/BasicTimer.h
+ Direct3DApp1/CubeRenderer.h
+ Direct3DApp1/Direct3DApp1.h
+ Direct3DApp1/Direct3DBase.h
+ Direct3DApp1/DirectXHelper.h
+ Direct3DApp1/pch.h
+ )
+
+set(PIXELSHADER_FILES
+ Direct3DApp1/SimplePixelShader.hlsl
+ )
+
+set(VERTEXSHADER_FILES
+ Direct3DApp1/SimpleVertexShader.hlsl
+ )
+
+set(CONTENT_FILES ${PIXELSHADER_FILES} ${VERTEXSHADER_FILES})
+
+if (WINDOWS_PHONE8)
+ set(CONTENT_FILES ${CONTENT_FILES}
+ ${CMAKE_CURRENT_BINARY_DIR}/${APP_MANIFEST_NAME}
+ Direct3DApp1/Assets/Tiles/FlipCycleTileLarge.png
+ Direct3DApp1/Assets/Tiles/FlipCycleTileMedium.png
+ Direct3DApp1/Assets/Tiles/FlipCycleTileSmall.png
+ Direct3DApp1/Assets/Tiles/IconicTileMediumLarge.png
+ Direct3DApp1/Assets/Tiles/IconicTileSmall.png
+ Direct3DApp1/Assets/ApplicationIcon.png
+ )
+ # Windows Phone 8.0 needs to copy all the images.
+ # It doesn't know to use relative paths.
+ file(COPY
+ Direct3DApp1/Assets/Tiles/FlipCycleTileLarge.png
+ Direct3DApp1/Assets/Tiles/FlipCycleTileMedium.png
+ Direct3DApp1/Assets/Tiles/FlipCycleTileSmall.png
+ Direct3DApp1/Assets/Tiles/IconicTileMediumLarge.png
+ Direct3DApp1/Assets/Tiles/IconicTileSmall.png
+ Direct3DApp1/Assets/ApplicationIcon.png
+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
+ )
+
+elseif (NOT "${PLATFORM}" STREQUAL "DESKTOP")
+ set(CONTENT_FILES ${CONTENT_FILES}
+ ${CMAKE_CURRENT_BINARY_DIR}/${APP_MANIFEST_NAME}
+ Direct3DApp1/Assets/Logo.png
+ Direct3DApp1/Assets/SmallLogo.png
+ Direct3DApp1/Assets/SplashScreen.png
+ Direct3DApp1/Assets/StoreLogo.png
+ )
+endif()
+
+set(RESOURCE_FILES
+ ${CONTENT_FILES} ${DEBUG_CONTENT_FILES} ${RELEASE_CONTENT_FILES}
+ Direct3DApp1/Direct3DApp1_TemporaryKey.pfx)
+
+set_property(SOURCE ${CONTENT_FILES} PROPERTY VS_DEPLOYMENT_CONTENT 1)
+set_property(SOURCE ${DEBUG_CONTENT_FILES} PROPERTY VS_DEPLOYMENT_CONTENT $<CONFIG:Debug>)
+set_property(SOURCE ${RELEASE_CONTENT_FILES} PROPERTY
+ VS_DEPLOYMENT_CONTENT $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>)
+
+set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_TYPE Pixel)
+set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_TYPE Vertex)
+
+source_group("Source Files" FILES ${SOURCE_FILES})
+source_group("Header Files" FILES ${HEADER_FILES})
+source_group("Resource Files" FILES ${RESOURCE_FILES})
+
+add_executable(${EXE_NAME} WIN32 ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES})
+set_property(TARGET ${EXE_NAME} PROPERTY VS_WINRT_COMPONENT TRUE)
+target_link_libraries(${EXE_NAME} d3d11)
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/ApplicationIcon.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/ApplicationIcon.png
new file mode 100644
index 0000000000..7d95d4e081
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/ApplicationIcon.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Logo.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Logo.png
new file mode 100644
index 0000000000..e26771cb33
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Logo.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo.png
new file mode 100644
index 0000000000..1eb0d9d528
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/SplashScreen.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/SplashScreen.png
new file mode 100644
index 0000000000..c951e031bd
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/SplashScreen.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/StoreLogo.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/StoreLogo.png
new file mode 100644
index 0000000000..dcb672712c
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/StoreLogo.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileLarge.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileLarge.png
new file mode 100644
index 0000000000..e0c59ac014
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileLarge.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileMedium.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileMedium.png
new file mode 100644
index 0000000000..e93b89d600
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileMedium.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileSmall.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileSmall.png
new file mode 100644
index 0000000000..550b1b5e8d
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileSmall.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileMediumLarge.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileMediumLarge.png
new file mode 100644
index 0000000000..686e6b53f0
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileMediumLarge.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileSmall.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileSmall.png
new file mode 100644
index 0000000000..d4b5ede1b5
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileSmall.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/BasicTimer.h b/Tests/VSWinStorePhone/Direct3DApp1/BasicTimer.h
new file mode 100644
index 0000000000..b58c77d384
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/BasicTimer.h
@@ -0,0 +1,76 @@
+#pragma once
+
+#include <wrl.h>
+
+// Helper class for basic timing.
+ref class BasicTimer sealed
+{
+public:
+ // Initializes internal timer values.
+ BasicTimer()
+ {
+ if (!QueryPerformanceFrequency(&m_frequency))
+ {
+ throw ref new Platform::FailureException();
+ }
+ Reset();
+ }
+
+ // Reset the timer to initial values.
+ void Reset()
+ {
+ Update();
+ m_startTime = m_currentTime;
+ m_total = 0.0f;
+ m_delta = 1.0f / 60.0f;
+ }
+
+ // Update the timer's internal values.
+ void Update()
+ {
+ if (!QueryPerformanceCounter(&m_currentTime))
+ {
+ throw ref new Platform::FailureException();
+ }
+
+ m_total = static_cast<float>(
+ static_cast<double>(m_currentTime.QuadPart - m_startTime.QuadPart) /
+ static_cast<double>(m_frequency.QuadPart)
+ );
+
+ if (m_lastTime.QuadPart == m_startTime.QuadPart)
+ {
+ // If the timer was just reset, report a time delta equivalent to 60Hz frame time.
+ m_delta = 1.0f / 60.0f;
+ }
+ else
+ {
+ m_delta = static_cast<float>(
+ static_cast<double>(m_currentTime.QuadPart - m_lastTime.QuadPart) /
+ static_cast<double>(m_frequency.QuadPart)
+ );
+ }
+
+ m_lastTime = m_currentTime;
+ }
+
+ // Duration in seconds between the last call to Reset() and the last call to Update().
+ property float Total
+ {
+ float get() { return m_total; }
+ }
+
+ // Duration in seconds between the previous two calls to Update().
+ property float Delta
+ {
+ float get() { return m_delta; }
+ }
+
+private:
+ LARGE_INTEGER m_frequency;
+ LARGE_INTEGER m_currentTime;
+ LARGE_INTEGER m_startTime;
+ LARGE_INTEGER m_lastTime;
+ float m_total;
+ float m_delta;
+};
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp b/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp
new file mode 100644
index 0000000000..f4827f2d67
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp
@@ -0,0 +1,260 @@
+#include "pch.h"
+#include "CubeRenderer.h"
+
+using namespace DirectX;
+using namespace Microsoft::WRL;
+using namespace Windows::Foundation;
+using namespace Windows::UI::Core;
+
+CubeRenderer::CubeRenderer() :
+ m_loadingComplete(false),
+ m_indexCount(0)
+{
+}
+
+void CubeRenderer::CreateDeviceResources()
+{
+ Direct3DBase::CreateDeviceResources();
+
+ auto loadVSTask = DX::ReadDataAsync("SimpleVertexShader.cso");
+ auto loadPSTask = DX::ReadDataAsync("SimplePixelShader.cso");
+
+ auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
+ DX::ThrowIfFailed(
+ m_d3dDevice->CreateVertexShader(
+ fileData->Data,
+ fileData->Length,
+ nullptr,
+ &m_vertexShader
+ )
+ );
+
+ const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
+ {
+ { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
+ { "COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
+ };
+
+ DX::ThrowIfFailed(
+ m_d3dDevice->CreateInputLayout(
+ vertexDesc,
+ ARRAYSIZE(vertexDesc),
+ fileData->Data,
+ fileData->Length,
+ &m_inputLayout
+ )
+ );
+ });
+
+ auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
+ DX::ThrowIfFailed(
+ m_d3dDevice->CreatePixelShader(
+ fileData->Data,
+ fileData->Length,
+ nullptr,
+ &m_pixelShader
+ )
+ );
+
+ CD3D11_BUFFER_DESC constantBufferDesc(sizeof(ModelViewProjectionConstantBuffer), D3D11_BIND_CONSTANT_BUFFER);
+ DX::ThrowIfFailed(
+ m_d3dDevice->CreateBuffer(
+ &constantBufferDesc,
+ nullptr,
+ &m_constantBuffer
+ )
+ );
+ });
+
+ auto createCubeTask = (createPSTask && createVSTask).then([this] () {
+ VertexPositionColor cubeVertices[] =
+ {
+ {XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, 0.0f)},
+ {XMFLOAT3(-0.5f, -0.5f, 0.5f), XMFLOAT3(0.0f, 0.0f, 1.0f)},
+ {XMFLOAT3(-0.5f, 0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f)},
+ {XMFLOAT3(-0.5f, 0.5f, 0.5f), XMFLOAT3(0.0f, 1.0f, 1.0f)},
+ {XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT3(1.0f, 0.0f, 0.0f)},
+ {XMFLOAT3( 0.5f, -0.5f, 0.5f), XMFLOAT3(1.0f, 0.0f, 1.0f)},
+ {XMFLOAT3( 0.5f, 0.5f, -0.5f), XMFLOAT3(1.0f, 1.0f, 0.0f)},
+ {XMFLOAT3( 0.5f, 0.5f, 0.5f), XMFLOAT3(1.0f, 1.0f, 1.0f)},
+ };
+
+ D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
+ vertexBufferData.pSysMem = cubeVertices;
+ vertexBufferData.SysMemPitch = 0;
+ vertexBufferData.SysMemSlicePitch = 0;
+ CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(cubeVertices), D3D11_BIND_VERTEX_BUFFER);
+ DX::ThrowIfFailed(
+ m_d3dDevice->CreateBuffer(
+ &vertexBufferDesc,
+ &vertexBufferData,
+ &m_vertexBuffer
+ )
+ );
+
+ unsigned short cubeIndices[] =
+ {
+ 0,2,1, // -x
+ 1,2,3,
+
+ 4,5,6, // +x
+ 5,7,6,
+
+ 0,1,5, // -y
+ 0,5,4,
+
+ 2,6,7, // +y
+ 2,7,3,
+
+ 0,4,6, // -z
+ 0,6,2,
+
+ 1,3,7, // +z
+ 1,7,5,
+ };
+
+ m_indexCount = ARRAYSIZE(cubeIndices);
+
+ D3D11_SUBRESOURCE_DATA indexBufferData = {0};
+ indexBufferData.pSysMem = cubeIndices;
+ indexBufferData.SysMemPitch = 0;
+ indexBufferData.SysMemSlicePitch = 0;
+ CD3D11_BUFFER_DESC indexBufferDesc(sizeof(cubeIndices), D3D11_BIND_INDEX_BUFFER);
+ DX::ThrowIfFailed(
+ m_d3dDevice->CreateBuffer(
+ &indexBufferDesc,
+ &indexBufferData,
+ &m_indexBuffer
+ )
+ );
+ });
+
+ createCubeTask.then([this] () {
+ m_loadingComplete = true;
+ });
+}
+
+void CubeRenderer::CreateWindowSizeDependentResources()
+{
+ Direct3DBase::CreateWindowSizeDependentResources();
+
+ float aspectRatio = m_windowBounds.Width / m_windowBounds.Height;
+ float fovAngleY = 70.0f * XM_PI / 180.0f;
+ if (aspectRatio < 1.0f)
+ {
+ fovAngleY /= aspectRatio;
+ }
+
+ // Note that the m_orientationTransform3D matrix is post-multiplied here
+ // in order to correctly orient the scene to match the display orientation.
+ // This post-multiplication step is required for any draw calls that are
+ // made to the swap chain render target. For draw calls to other targets,
+ // this transform should not be applied.
+ XMStoreFloat4x4(
+ &m_constantBufferData.projection,
+ XMMatrixTranspose(
+ XMMatrixMultiply(
+ XMMatrixPerspectiveFovRH(
+ fovAngleY,
+ aspectRatio,
+ 0.01f,
+ 100.0f
+ ),
+ XMLoadFloat4x4(&m_orientationTransform3D)
+ )
+ )
+ );
+}
+
+void CubeRenderer::Update(float timeTotal, float timeDelta)
+{
+ (void) timeDelta; // Unused parameter.
+
+ XMVECTOR eye = XMVectorSet(0.0f, 0.7f, 1.5f, 0.0f);
+ XMVECTOR at = XMVectorSet(0.0f, -0.1f, 0.0f, 0.0f);
+ XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
+
+ XMStoreFloat4x4(&m_constantBufferData.view, XMMatrixTranspose(XMMatrixLookAtRH(eye, at, up)));
+ XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixTranspose(XMMatrixRotationY(timeTotal * XM_PIDIV4)));
+}
+
+void CubeRenderer::Render()
+{
+ const float midnightBlue[] = { 0.098f, 0.098f, 0.439f, 1.000f };
+ m_d3dContext->ClearRenderTargetView(
+ m_renderTargetView.Get(),
+ midnightBlue
+ );
+
+ m_d3dContext->ClearDepthStencilView(
+ m_depthStencilView.Get(),
+ D3D11_CLEAR_DEPTH,
+ 1.0f,
+ 0
+ );
+
+ // Only draw the cube once it is loaded (loading is asynchronous).
+ if (!m_loadingComplete)
+ {
+ return;
+ }
+
+ m_d3dContext->OMSetRenderTargets(
+ 1,
+ m_renderTargetView.GetAddressOf(),
+ m_depthStencilView.Get()
+ );
+
+ m_d3dContext->UpdateSubresource(
+ m_constantBuffer.Get(),
+ 0,
+ NULL,
+ &m_constantBufferData,
+ 0,
+ 0
+ );
+
+ UINT stride = sizeof(VertexPositionColor);
+ UINT offset = 0;
+ m_d3dContext->IASetVertexBuffers(
+ 0,
+ 1,
+ m_vertexBuffer.GetAddressOf(),
+ &stride,
+ &offset
+ );
+
+ m_d3dContext->IASetIndexBuffer(
+ m_indexBuffer.Get(),
+ DXGI_FORMAT_R16_UINT,
+ 0
+ );
+
+ m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+
+ m_d3dContext->IASetInputLayout(m_inputLayout.Get());
+
+ m_d3dContext->VSSetShader(
+ m_vertexShader.Get(),
+ nullptr,
+ 0
+ );
+
+ m_d3dContext->VSSetConstantBuffers(
+ 0,
+ 1,
+ m_constantBuffer.GetAddressOf()
+ );
+
+ m_d3dContext->PSSetShader(
+ m_pixelShader.Get(),
+ nullptr,
+ 0
+ );
+
+ m_d3dContext->DrawIndexed(
+ m_indexCount,
+ 0,
+ 0
+ );
+}
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.h b/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.h
new file mode 100644
index 0000000000..68cb188d16
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include "Direct3DBase.h"
+
+struct ModelViewProjectionConstantBuffer
+{
+ DirectX::XMFLOAT4X4 model;
+ DirectX::XMFLOAT4X4 view;
+ DirectX::XMFLOAT4X4 projection;
+};
+
+struct VertexPositionColor
+{
+ DirectX::XMFLOAT3 pos;
+ DirectX::XMFLOAT3 color;
+};
+
+// This class renders a simple spinning cube.
+ref class CubeRenderer sealed : public Direct3DBase
+{
+public:
+ CubeRenderer();
+
+ // Direct3DBase methods.
+ virtual void CreateDeviceResources() override;
+ virtual void CreateWindowSizeDependentResources() override;
+ virtual void Render() override;
+
+ // Method for updating time-dependent objects.
+ void Update(float timeTotal, float timeDelta);
+
+private:
+ bool m_loadingComplete;
+
+ Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
+ Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
+ Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer;
+ Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
+ Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
+ Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;
+
+ uint32 m_indexCount;
+ ModelViewProjectionConstantBuffer m_constantBufferData;
+};
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.cpp b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.cpp
new file mode 100644
index 0000000000..3dbb97f105
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.cpp
@@ -0,0 +1,153 @@
+#include "pch.h"
+#include "Direct3DApp1.h"
+#include "BasicTimer.h"
+
+using namespace Windows::ApplicationModel;
+using namespace Windows::ApplicationModel::Core;
+using namespace Windows::ApplicationModel::Activation;
+using namespace Windows::UI::Core;
+using namespace Windows::System;
+using namespace Windows::Foundation;
+using namespace Windows::Graphics::Display;
+using namespace concurrency;
+
+Direct3DApp1::Direct3DApp1() :
+ m_windowClosed(false),
+ m_windowVisible(true)
+{
+}
+
+void Direct3DApp1::Initialize(CoreApplicationView^ applicationView)
+{
+ applicationView->Activated +=
+ ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &Direct3DApp1::OnActivated);
+
+ CoreApplication::Suspending +=
+ ref new EventHandler<SuspendingEventArgs^>(this, &Direct3DApp1::OnSuspending);
+
+ CoreApplication::Resuming +=
+ ref new EventHandler<Platform::Object^>(this, &Direct3DApp1::OnResuming);
+
+ m_renderer = ref new CubeRenderer();
+}
+
+void Direct3DApp1::SetWindow(CoreWindow^ window)
+{
+ window->SizeChanged +=
+ ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &Direct3DApp1::OnWindowSizeChanged);
+
+ window->VisibilityChanged +=
+ ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &Direct3DApp1::OnVisibilityChanged);
+
+ window->Closed +=
+ ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &Direct3DApp1::OnWindowClosed);
+
+#ifndef PHONE
+ window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
+#endif
+
+ window->PointerPressed +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &Direct3DApp1::OnPointerPressed);
+
+ window->PointerMoved +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &Direct3DApp1::OnPointerMoved);
+
+ m_renderer->Initialize(CoreWindow::GetForCurrentThread());
+}
+
+void Direct3DApp1::Load(Platform::String^ entryPoint)
+{
+}
+
+void Direct3DApp1::Run()
+{
+ BasicTimer^ timer = ref new BasicTimer();
+
+ while (!m_windowClosed)
+ {
+ if (m_windowVisible)
+ {
+ timer->Update();
+ CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
+ m_renderer->Update(timer->Total, timer->Delta);
+ m_renderer->Render();
+ m_renderer->Present(); // This call is synchronized to the display frame rate.
+ }
+ else
+ {
+ CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
+ }
+ }
+}
+
+void Direct3DApp1::Uninitialize()
+{
+}
+
+void Direct3DApp1::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
+{
+ m_renderer->UpdateForWindowSizeChange();
+}
+
+void Direct3DApp1::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
+{
+ m_windowVisible = args->Visible;
+}
+
+void Direct3DApp1::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
+{
+ m_windowClosed = true;
+}
+
+void Direct3DApp1::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
+{
+ // Insert your code here.
+}
+
+void Direct3DApp1::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
+{
+ // Insert your code here.
+}
+
+void Direct3DApp1::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
+{
+ CoreWindow::GetForCurrentThread()->Activate();
+}
+
+void Direct3DApp1::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
+{
+ // Save app state asynchronously after requesting a deferral. Holding a deferral
+ // indicates that the application is busy performing suspending operations. Be
+ // aware that a deferral may not be held indefinitely. After about five seconds,
+ // the app will be forced to exit.
+ SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
+ m_renderer->ReleaseResourcesForSuspending();
+
+ create_task([this, deferral]()
+ {
+ // Insert your code here.
+
+ deferral->Complete();
+ });
+}
+
+void Direct3DApp1::OnResuming(Platform::Object^ sender, Platform::Object^ args)
+{
+ // Restore any data or state that was unloaded on suspend. By default, data
+ // and state are persisted when resuming from suspend. Note that this event
+ // does not occur if the app was previously terminated.
+ m_renderer->CreateWindowSizeDependentResources();
+}
+
+IFrameworkView^ Direct3DApplicationSource::CreateView()
+{
+ return ref new Direct3DApp1();
+}
+
+[Platform::MTAThread]
+int main(Platform::Array<Platform::String^>^)
+{
+ auto direct3DApplicationSource = ref new Direct3DApplicationSource();
+ CoreApplication::Run(direct3DApplicationSource);
+ return 0;
+}
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.h b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.h
new file mode 100644
index 0000000000..40b69a1734
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#include "pch.h"
+#include "CubeRenderer.h"
+
+ref class Direct3DApp1 sealed : public Windows::ApplicationModel::Core::IFrameworkView
+{
+public:
+ Direct3DApp1();
+
+ // IFrameworkView Methods.
+ virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
+ virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
+ virtual void Load(Platform::String^ entryPoint);
+ virtual void Run();
+ virtual void Uninitialize();
+
+protected:
+ // Event Handlers.
+ void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
+ void OnLogicalDpiChanged(Platform::Object^ sender);
+ void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
+ void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
+ void OnResuming(Platform::Object^ sender, Platform::Object^ args);
+ void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
+ void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
+ void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+ void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+
+private:
+ CubeRenderer^ m_renderer;
+ bool m_windowClosed;
+ bool m_windowVisible;
+};
+
+ref class Direct3DApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
+{
+public:
+ virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
+};
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1_TemporaryKey.pfx b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1_TemporaryKey.pfx
new file mode 100644
index 0000000000..1cad9993d6
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1_TemporaryKey.pfx
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp
new file mode 100644
index 0000000000..46727b5ff3
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp
@@ -0,0 +1,384 @@
+#include "pch.h"
+#include "Direct3DBase.h"
+
+using namespace DirectX;
+using namespace Microsoft::WRL;
+using namespace Windows::UI::Core;
+using namespace Windows::Foundation;
+using namespace Windows::Graphics::Display;
+
+// Constructor.
+Direct3DBase::Direct3DBase()
+{
+}
+
+// Initialize the Direct3D resources required to run.
+void Direct3DBase::Initialize(CoreWindow^ window)
+{
+ m_window = window;
+
+ CreateDeviceResources();
+ CreateWindowSizeDependentResources();
+}
+
+// Recreate all device resources and set them back to the current state.
+void Direct3DBase::HandleDeviceLost()
+{
+ // Reset these member variables to ensure that UpdateForWindowSizeChange recreates all resources.
+ m_windowBounds.Width = 0;
+ m_windowBounds.Height = 0;
+ m_swapChain = nullptr;
+
+ CreateDeviceResources();
+ UpdateForWindowSizeChange();
+}
+
+// These are the resources that depend on the device.
+void Direct3DBase::CreateDeviceResources()
+{
+ // This flag adds support for surfaces with a different color channel ordering
+ // than the API default. It is required for compatibility with Direct2D.
+ UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
+
+#if defined(_DEBUG)
+ // If the project is in a debug build, enable debugging via SDK Layers with this flag.
+ creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
+#endif
+
+ // This array defines the set of DirectX hardware feature levels this app will support.
+ // Note the ordering should be preserved.
+ // Don't forget to declare your application's minimum required feature level in its
+ // description. All applications are assumed to support 9.1 unless otherwise stated.
+ D3D_FEATURE_LEVEL featureLevels[] =
+ {
+ D3D_FEATURE_LEVEL_11_1,
+ D3D_FEATURE_LEVEL_11_0,
+ D3D_FEATURE_LEVEL_10_1,
+ D3D_FEATURE_LEVEL_10_0,
+ D3D_FEATURE_LEVEL_9_3,
+ D3D_FEATURE_LEVEL_9_2,
+ D3D_FEATURE_LEVEL_9_1
+ };
+
+ // Create the Direct3D 11 API device object and a corresponding context.
+ ComPtr<ID3D11Device> device;
+ ComPtr<ID3D11DeviceContext> context;
+ DX::ThrowIfFailed(
+ D3D11CreateDevice(
+ nullptr, // Specify nullptr to use the default adapter.
+ D3D_DRIVER_TYPE_HARDWARE,
+ nullptr,
+ creationFlags, // Set set debug and Direct2D compatibility flags.
+ featureLevels, // List of feature levels this app can support.
+ ARRAYSIZE(featureLevels),
+ D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
+ &device, // Returns the Direct3D device created.
+ &m_featureLevel, // Returns feature level of device created.
+ &context // Returns the device immediate context.
+ )
+ );
+
+ // Get the Direct3D 11.1 API device and context interfaces.
+ DX::ThrowIfFailed(
+ device.As(&m_d3dDevice)
+ );
+
+ DX::ThrowIfFailed(
+ context.As(&m_d3dContext)
+ );
+}
+
+// Allocate all memory resources that change on a window SizeChanged event.
+void Direct3DBase::CreateWindowSizeDependentResources()
+{
+ // Store the window bounds so the next time we get a SizeChanged event we can
+ // avoid rebuilding everything if the size is identical.
+ m_windowBounds = m_window->Bounds;
+
+ // Calculate the necessary swap chain and render target size in pixels.
+ float windowWidth = ConvertDipsToPixels(m_windowBounds.Width);
+ float windowHeight = ConvertDipsToPixels(m_windowBounds.Height);
+
+ // The width and height of the swap chain must be based on the window's
+ // landscape-oriented width and height. If the window is in a portrait
+ // orientation, the dimensions must be reversed.
+#if WINVER > 0x0602
+ m_orientation = DisplayInformation::GetForCurrentView()->CurrentOrientation;
+#else
+#if PHONE
+ // WP8 doesn't support rotations so always make it landscape
+ m_orientation = DisplayOrientations::Landscape;
+#else
+ m_orientation = DisplayProperties::CurrentOrientation;
+#endif
+#endif
+ bool swapDimensions =
+ m_orientation == DisplayOrientations::Portrait ||
+ m_orientation == DisplayOrientations::PortraitFlipped;
+ m_renderTargetSize.Width = swapDimensions ? windowHeight : windowWidth;
+ m_renderTargetSize.Height = swapDimensions ? windowWidth : windowHeight;
+
+ if(m_swapChain != nullptr)
+ {
+ // If the swap chain already exists, resize it.
+ DX::ThrowIfFailed(
+ m_swapChain->ResizeBuffers(
+ 2, // Double-buffered swap chain.
+ static_cast<UINT>(m_renderTargetSize.Width),
+ static_cast<UINT>(m_renderTargetSize.Height),
+ DXGI_FORMAT_B8G8R8A8_UNORM,
+ 0
+ )
+ );
+ }
+ else
+ {
+ // Otherwise, create a new one using the same adapter as the existing Direct3D device.
+ DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
+ swapChainDesc.Width = static_cast<UINT>(m_renderTargetSize.Width); // Match the size of the window.
+ swapChainDesc.Height = static_cast<UINT>(m_renderTargetSize.Height);
+ swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format.
+ swapChainDesc.Stereo = false;
+ swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
+ swapChainDesc.SampleDesc.Quality = 0;
+ swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+#if PHONE && WINVER <= 0x0602
+ swapChainDesc.BufferCount = 1; // Use double-buffering to minimize latency.
+ swapChainDesc.Scaling = DXGI_SCALING_STRETCH; // On phone, only stretch and aspect-ratio stretch scaling are allowed.
+ swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // On phone, no swap effects are supported.
+#else
+ swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency.
+ swapChainDesc.Scaling = DXGI_SCALING_NONE;
+ swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
+#endif
+ swapChainDesc.Flags = 0;
+
+ ComPtr<IDXGIDevice1> dxgiDevice;
+ DX::ThrowIfFailed(
+ m_d3dDevice.As(&dxgiDevice)
+ );
+
+ ComPtr<IDXGIAdapter> dxgiAdapter;
+ DX::ThrowIfFailed(
+ dxgiDevice->GetAdapter(&dxgiAdapter)
+ );
+
+ ComPtr<IDXGIFactory2> dxgiFactory;
+ DX::ThrowIfFailed(
+ dxgiAdapter->GetParent(
+ __uuidof(IDXGIFactory2),
+ &dxgiFactory
+ )
+ );
+
+ Windows::UI::Core::CoreWindow^ window = m_window.Get();
+ DX::ThrowIfFailed(
+ dxgiFactory->CreateSwapChainForCoreWindow(
+ m_d3dDevice.Get(),
+ reinterpret_cast<IUnknown*>(window),
+ &swapChainDesc,
+ nullptr, // Allow on all displays.
+ &m_swapChain
+ )
+ );
+
+ // Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and
+ // ensures that the application will only render after each VSync, minimizing power consumption.
+ DX::ThrowIfFailed(
+ dxgiDevice->SetMaximumFrameLatency(1)
+ );
+ }
+
+ // Set the proper orientation for the swap chain, and generate the
+ // 3D matrix transformation for rendering to the rotated swap chain.
+ DXGI_MODE_ROTATION rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
+ switch (m_orientation)
+ {
+ case DisplayOrientations::Landscape:
+ rotation = DXGI_MODE_ROTATION_IDENTITY;
+ m_orientationTransform3D = XMFLOAT4X4( // 0-degree Z-rotation
+ 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f
+ );
+ break;
+
+ case DisplayOrientations::Portrait:
+ rotation = DXGI_MODE_ROTATION_ROTATE270;
+ m_orientationTransform3D = XMFLOAT4X4( // 90-degree Z-rotation
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f
+ );
+ break;
+
+ case DisplayOrientations::LandscapeFlipped:
+ rotation = DXGI_MODE_ROTATION_ROTATE180;
+ m_orientationTransform3D = XMFLOAT4X4( // 180-degree Z-rotation
+ -1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f
+ );
+ break;
+
+ case DisplayOrientations::PortraitFlipped:
+ rotation = DXGI_MODE_ROTATION_ROTATE90;
+ m_orientationTransform3D = XMFLOAT4X4( // 270-degree Z-rotation
+ 0.0f, -1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f
+ );
+ break;
+
+ default:
+ throw ref new Platform::FailureException();
+ }
+
+#if !PHONE || WINVER > 0x0602
+ DX::ThrowIfFailed(
+ m_swapChain->SetRotation(rotation)
+ );
+#endif // !PHONE
+
+ // Create a render target view of the swap chain back buffer.
+ ComPtr<ID3D11Texture2D> backBuffer;
+ DX::ThrowIfFailed(
+ m_swapChain->GetBuffer(
+ 0,
+ __uuidof(ID3D11Texture2D),
+ &backBuffer
+ )
+ );
+
+ DX::ThrowIfFailed(
+ m_d3dDevice->CreateRenderTargetView(
+ backBuffer.Get(),
+ nullptr,
+ &m_renderTargetView
+ )
+ );
+
+ // Create a depth stencil view.
+ CD3D11_TEXTURE2D_DESC depthStencilDesc(
+ DXGI_FORMAT_D24_UNORM_S8_UINT,
+ static_cast<UINT>(m_renderTargetSize.Width),
+ static_cast<UINT>(m_renderTargetSize.Height),
+ 1,
+ 1,
+ D3D11_BIND_DEPTH_STENCIL
+ );
+
+ ComPtr<ID3D11Texture2D> depthStencil;
+ DX::ThrowIfFailed(
+ m_d3dDevice->CreateTexture2D(
+ &depthStencilDesc,
+ nullptr,
+ &depthStencil
+ )
+ );
+
+ CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
+ DX::ThrowIfFailed(
+ m_d3dDevice->CreateDepthStencilView(
+ depthStencil.Get(),
+ &depthStencilViewDesc,
+ &m_depthStencilView
+ )
+ );
+
+ // Set the rendering viewport to target the entire window.
+ CD3D11_VIEWPORT viewport(
+ 0.0f,
+ 0.0f,
+ m_renderTargetSize.Width,
+ m_renderTargetSize.Height
+ );
+
+ m_d3dContext->RSSetViewports(1, &viewport);
+}
+
+// This method is called in the event handler for the SizeChanged event.
+void Direct3DBase::UpdateForWindowSizeChange()
+{
+ if (m_window->Bounds.Width != m_windowBounds.Width ||
+ m_window->Bounds.Height != m_windowBounds.Height ||
+#if WINVER > 0x0602
+ m_orientation != DisplayInformation::GetForCurrentView()->CurrentOrientation)
+#else
+ m_orientation != DisplayProperties::CurrentOrientation)
+#endif
+ {
+ ID3D11RenderTargetView* nullViews[] = {nullptr};
+ m_d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
+ m_renderTargetView = nullptr;
+ m_depthStencilView = nullptr;
+ m_d3dContext->Flush();
+ CreateWindowSizeDependentResources();
+ }
+}
+
+void Direct3DBase::ReleaseResourcesForSuspending()
+{
+ // Phone applications operate in a memory-constrained environment, so when entering
+ // the background it is a good idea to free memory-intensive objects that will be
+ // easy to restore upon reactivation. The swapchain and backbuffer are good candidates
+ // here, as they consume a large amount of memory and can be reinitialized quickly.
+ m_swapChain = nullptr;
+ m_renderTargetView = nullptr;
+ m_depthStencilView = nullptr;
+}
+
+// Method to deliver the final image to the display.
+void Direct3DBase::Present()
+{
+ // The first argument instructs DXGI to block until VSync, putting the application
+ // to sleep until the next VSync. This ensures we don't waste any cycles rendering
+ // frames that will never be displayed to the screen.
+#if PHONE && WINVER <= 0x0602
+ HRESULT hr = m_swapChain->Present(1, 0);
+#else
+ // The application may optionally specify "dirty" or "scroll"
+ // rects to improve efficiency in certain scenarios.
+ DXGI_PRESENT_PARAMETERS parameters = { 0 };
+ parameters.DirtyRectsCount = 0;
+ parameters.pDirtyRects = nullptr;
+ parameters.pScrollRect = nullptr;
+ parameters.pScrollOffset = nullptr;
+
+ HRESULT hr = m_swapChain->Present1(1, 0 , &parameters);
+#endif
+
+ // Discard the contents of the render target.
+ // This is a valid operation only when the existing contents will be entirely
+ // overwritten. If dirty or scroll rects are used, this call should be removed.
+ m_d3dContext->DiscardView(m_renderTargetView.Get());
+
+ // Discard the contents of the depth stencil.
+ m_d3dContext->DiscardView(m_depthStencilView.Get());
+
+ // If the device was removed either by a disconnect or a driver upgrade, we
+ // must recreate all device resources.
+ if (hr == DXGI_ERROR_DEVICE_REMOVED)
+ {
+ HandleDeviceLost();
+ }
+ else
+ {
+ DX::ThrowIfFailed(hr);
+ }
+}
+
+// Method to convert a length in device-independent pixels (DIPs) to a length in physical pixels.
+float Direct3DBase::ConvertDipsToPixels(float dips)
+{
+ static const float dipsPerInch = 96.0f;
+#if WINVER > 0x0602
+ return floor(dips * DisplayInformation::GetForCurrentView()->LogicalDpi / dipsPerInch + 0.5f); // Round to nearest integer.
+#else
+ return floor(dips * DisplayProperties::LogicalDpi / dipsPerInch + 0.5f); // Round to nearest integer.
+#endif
+}
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.h b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.h
new file mode 100644
index 0000000000..bba9f16971
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include "DirectXHelper.h"
+
+// Helper class that initializes DirectX APIs for 3D rendering.
+ref class Direct3DBase abstract
+{
+internal:
+ Direct3DBase();
+
+public:
+ virtual void Initialize(Windows::UI::Core::CoreWindow^ window);
+ virtual void HandleDeviceLost();
+ virtual void CreateDeviceResources();
+ virtual void CreateWindowSizeDependentResources();
+ virtual void UpdateForWindowSizeChange();
+ virtual void ReleaseResourcesForSuspending();
+ virtual void Render() = 0;
+ virtual void Present();
+ virtual float ConvertDipsToPixels(float dips);
+
+protected private:
+ // Direct3D Objects.
+ Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
+ Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
+ Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
+ Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
+ Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depthStencilView;
+
+ // Cached renderer properties.
+ D3D_FEATURE_LEVEL m_featureLevel;
+ Windows::Foundation::Size m_renderTargetSize;
+ Windows::Foundation::Rect m_windowBounds;
+ Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
+ Windows::Graphics::Display::DisplayOrientations m_orientation;
+
+ // Transform used for display orientation.
+ DirectX::XMFLOAT4X4 m_orientationTransform3D;
+};
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h b/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h
new file mode 100644
index 0000000000..d411a9b815
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h
@@ -0,0 +1,45 @@
+#pragma once
+
+#include <wrl/client.h>
+#include <ppl.h>
+#include <ppltasks.h>
+
+namespace DX
+{
+ inline void ThrowIfFailed(HRESULT hr)
+ {
+ if (FAILED(hr))
+ {
+ // Set a breakpoint on this line to catch Win32 API errors.
+ throw Platform::Exception::CreateException(hr);
+ }
+ }
+
+ // Function that reads from a binary file asynchronously.
+ inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
+ {
+ using namespace Windows::Storage;
+ using namespace Concurrency;
+
+ auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
+
+ return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file)
+ {
+#if !PHONE
+ return FileIO::ReadBufferAsync(file);
+#else
+ return file->OpenReadAsync();
+ }).then([](Streams::IRandomAccessStreamWithContentType^ stream)
+ {
+ unsigned int bufferSize = static_cast<unsigned int>(stream->Size);
+ auto fileBuffer = ref new Streams::Buffer(bufferSize);
+ return stream->ReadAsync(fileBuffer, bufferSize, Streams::InputStreamOptions::None);
+#endif
+ }).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^
+ {
+ auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
+ Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
+ return fileData;
+ });
+ }
+}
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.cso b/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.cso
new file mode 100644
index 0000000000..56f9c17565
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.cso
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.hlsl b/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.hlsl
new file mode 100644
index 0000000000..d61e2c8f5a
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.hlsl
@@ -0,0 +1,10 @@
+struct PixelShaderInput
+{
+ float4 pos : SV_POSITION;
+ float3 color : COLOR0;
+};
+
+float4 main(PixelShaderInput input) : SV_TARGET
+{
+ return float4(input.color,1.0f);
+}
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.cso b/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.cso
new file mode 100644
index 0000000000..ea80258217
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.cso
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.hlsl b/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.hlsl
new file mode 100644
index 0000000000..65d60e5bd5
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.hlsl
@@ -0,0 +1,35 @@
+cbuffer ModelViewProjectionConstantBuffer : register(b0)
+{
+ matrix model;
+ matrix view;
+ matrix projection;
+};
+
+struct VertexShaderInput
+{
+ float3 pos : POSITION;
+ float3 color : COLOR0;
+};
+
+struct VertexShaderOutput
+{
+ float4 pos : SV_POSITION;
+ float3 color : COLOR0;
+};
+
+VertexShaderOutput main(VertexShaderInput input)
+{
+ VertexShaderOutput output;
+ float4 pos = float4(input.pos, 1.0f);
+
+ // Transform the vertex position into projected space.
+ pos = mul(pos, model);
+ pos = mul(pos, view);
+ pos = mul(pos, projection);
+ output.pos = pos;
+
+ // Pass through the color without modification.
+ output.color = input.color;
+
+ return output;
+}
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/pch.cpp b/Tests/VSWinStorePhone/Direct3DApp1/pch.cpp
new file mode 100644
index 0000000000..1d9f38c57d
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/pch.cpp
@@ -0,0 +1 @@
+#include "pch.h"
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/pch.h b/Tests/VSWinStorePhone/Direct3DApp1/pch.h
new file mode 100644
index 0000000000..2302e66ba7
--- /dev/null
+++ b/Tests/VSWinStorePhone/Direct3DApp1/pch.h
@@ -0,0 +1,7 @@
+#pragma once
+
+#include <wrl/client.h>
+#include <d3d11_1.h>
+#include <DirectXMath.h>
+#include <memory>
+#include <agile.h>
diff --git a/Tests/VSWinStorePhone/cmake/Package_vc11.store.appxmanifest.in b/Tests/VSWinStorePhone/cmake/Package_vc11.store.appxmanifest.in
new file mode 100644
index 0000000000..d3cb21fb03
--- /dev/null
+++ b/Tests/VSWinStorePhone/cmake/Package_vc11.store.appxmanifest.in
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
+ <Identity Name="@PACKAGE_GUID@" Publisher="CN=mgong" Version="1.0.0.0" />
+ <Properties>
+ <DisplayName>@SHORT_NAME@</DisplayName>
+ <PublisherDisplayName>mgong</PublisherDisplayName>
+ <Logo>StoreLogo.png</Logo>
+ </Properties>
+ <Prerequisites>
+ <OSMinVersion>6.2.1</OSMinVersion>
+ <OSMaxVersionTested>6.2.1</OSMaxVersionTested>
+ </Prerequisites>
+ <Resources>
+ <Resource Language="x-generate" />
+ </Resources>
+ <Applications>
+ <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="@SHORT_NAME@.App">
+ <VisualElements DisplayName="@SHORT_NAME@" Description="@SHORT_NAME@" BackgroundColor="#336699" ForegroundText="light" Logo="Logo.png" SmallLogo="SmallLogo.png">
+ <DefaultTile ShowName="allLogos" ShortName="@SHORT_NAME@" />
+ <SplashScreen Image="SplashScreen.png" />
+ </VisualElements>
+ </Application>
+ </Applications>
+</Package>
diff --git a/Tests/VSWinStorePhone/cmake/Package_vc11.wp.appxmanifest.in b/Tests/VSWinStorePhone/cmake/Package_vc11.wp.appxmanifest.in
new file mode 100644
index 0000000000..70f3abf794
--- /dev/null
+++ b/Tests/VSWinStorePhone/cmake/Package_vc11.wp.appxmanifest.in
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2012/deployment" AppPlatformVersion="8.0">
+ <DefaultLanguage xmlns="" code="en-US"/>
+ <App xmlns="" ProductID="{@PACKAGE_GUID@}" Title="@SHORT_NAME@" RuntimeType="Modern Native" Version="1.0.0.0" Genre="apps.normal" Author="mgong" Description="Simple Direct3D application" Publisher="@SHORT_NAME@" PublisherID="{c618991e-1d39-41c2-a881-d3310705a091}">
+ <IconPath IsRelative="true" IsResource="false">ApplicationIcon.png</IconPath>
+ <Capabilities>
+ <Capability Name="ID_CAP_NETWORKING" />
+ <Capability Name="ID_CAP_MEDIALIB_AUDIO" />
+ <Capability Name="ID_CAP_MEDIALIB_PLAYBACK" />
+ </Capabilities>
+ <Tasks>
+ <DefaultTask Name="_default" ImagePath="@SHORT_NAME@.exe" ImageParams="" />
+ </Tasks>
+ <Tokens>
+ <PrimaryToken TokenID="@SHORT_NAME@Token" TaskName="_default">
+ <TemplateFlip>
+ <SmallImageURI IsRelative="true" IsResource="false">FlipCycleTileSmall.png</SmallImageURI>
+ <Count>0</Count>
+ <BackgroundImageURI IsRelative="true" IsResource="false">FlipCycleTileMedium.png</BackgroundImageURI>
+ <Title>@SHORT_NAME@</Title>
+ <BackContent></BackContent>
+ <BackBackgroundImageURI></BackBackgroundImageURI>
+ <BackTitle></BackTitle>
+ <DeviceLockImageURI></DeviceLockImageURI>
+ <HasLarge></HasLarge>
+ </TemplateFlip>
+ </PrimaryToken>
+ </Tokens>
+ <ScreenResolutions>
+ <ScreenResolution Name="ID_RESOLUTION_WVGA" />
+ <ScreenResolution Name="ID_RESOLUTION_WXGA" />
+ <ScreenResolution Name="ID_RESOLUTION_HD720P" />
+ </ScreenResolutions>
+ </App>
+</Deployment>
diff --git a/Tests/VSWinStorePhone/cmake/Package_vc12.store.appxmanifest.in b/Tests/VSWinStorePhone/cmake/Package_vc12.store.appxmanifest.in
new file mode 100644
index 0000000000..495f18ed59
--- /dev/null
+++ b/Tests/VSWinStorePhone/cmake/Package_vc12.store.appxmanifest.in
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest">
+ <Identity Name="@PACKAGE_GUID@" Publisher="CN=mgong" Version="1.1.0.0" />
+ <Properties>
+ <DisplayName>@SHORT_NAME@</DisplayName>
+ <PublisherDisplayName>mgong</PublisherDisplayName>
+ <Logo>StoreLogo.png</Logo>
+ </Properties>
+ <Prerequisites>
+ <OSMinVersion>6.3</OSMinVersion>
+ <OSMaxVersionTested>6.3</OSMaxVersionTested>
+ </Prerequisites>
+ <Resources>
+ <Resource Language="x-generate" />
+ </Resources>
+ <Applications>
+ <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="@SHORT_NAME@.App">
+ <m2:VisualElements
+ DisplayName="@SHORT_NAME@"
+ Description="@SHORT_NAME@"
+ BackgroundColor="#336699"
+ ForegroundText="light"
+ Square150x150Logo="Logo.png"
+ Square30x30Logo="SmallLogo.png">
+ <m2:DefaultTile ShortName="@SHORT_NAME@">
+ <m2:ShowNameOnTiles>
+ <m2:ShowOn Tile="square150x150Logo" />
+ </m2:ShowNameOnTiles>
+ </m2:DefaultTile>
+ <m2:SplashScreen Image="SplashScreen.png" />
+ </m2:VisualElements>
+ </Application>
+ </Applications>
+</Package>
diff --git a/Tests/VSWinStorePhone/cmake/Package_vc12.wp.appxmanifest.in b/Tests/VSWinStorePhone/cmake/Package_vc12.wp.appxmanifest.in
new file mode 100644
index 0000000000..2d4d389c4a
--- /dev/null
+++ b/Tests/VSWinStorePhone/cmake/Package_vc12.wp.appxmanifest.in
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
+ <Identity Name="@PACKAGE_GUID@" Publisher="CN=mgong" Version="1.1.0.0" />
+ <mp:PhoneIdentity PhoneProductId="@PACKAGE_GUID@" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
+
+ <Properties>
+ <DisplayName>@SHORT_NAME@</DisplayName>
+ <PublisherDisplayName>mgong</PublisherDisplayName>
+ <Logo>StoreLogo.png</Logo>
+ </Properties>
+ <Prerequisites>
+ <OSMinVersion>6.3.1</OSMinVersion>
+ <OSMaxVersionTested>6.3.1</OSMaxVersionTested>
+ </Prerequisites>
+ <Resources>
+ <Resource Language="x-generate" />
+ </Resources>
+ <Applications>
+ <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="@SHORT_NAME@.App">
+ <m2:VisualElements
+ DisplayName="@SHORT_NAME@"
+ Description="@SHORT_NAME@"
+ BackgroundColor="#336699"
+ ForegroundText="light"
+ Square150x150Logo="Logo.png"
+ Square30x30Logo="SmallLogo.png">
+ <m2:DefaultTile ShortName="@SHORT_NAME@">
+ <m2:ShowNameOnTiles>
+ <m2:ShowOn Tile="square150x150Logo" />
+ </m2:ShowNameOnTiles>
+ </m2:DefaultTile>
+ <m2:SplashScreen Image="SplashScreen.png" />
+ </m2:VisualElements>
+ </Application>
+ </Applications>
+</Package>
diff --git a/Tests/VSWindowsFormsResx/CMakeLists.txt b/Tests/VSWindowsFormsResx/CMakeLists.txt
new file mode 100644
index 0000000000..4373810859
--- /dev/null
+++ b/Tests/VSWindowsFormsResx/CMakeLists.txt
@@ -0,0 +1,45 @@
+#
+# Example CMakeLists.txt file to demonstrate how to make a designable Windows Forms project with CMake.
+#
+# Code modifications and example by John Farrier, john.farrier@helleboreconsulting.com
+#
+
+cmake_minimum_required(VERSION 2.8.10)
+
+# Project Name
+project(VSWindowsFormsResx CXX)
+
+include(CheckFunctionExists)
+include(CheckCXXSourceCompiles)
+include(CheckIncludeFile)
+
+# Note: The designable form is assumed to have a .h extension as is default in Visual Studio.
+# Node: The designable form is assumed to have a .resx file with the same name and path (save extension) as is default in Visual Studio
+
+set(TARGET_H
+ WindowsFormsResx/MyForm.h
+ WindowsFormsResx/Header.h
+ )
+
+set(TARGET_SRC
+ WindowsFormsResx/MyForm.cpp
+ WindowsFormsResx/Source.cpp
+ )
+set_source_files_properties(${TARGET_SRC} PROPERTIES COMPILE_FLAGS "/clr")
+
+set(TARGET_RESX
+ WindowsFormsResx/MyForm.resx
+ )
+
+set(TARGET_LIBRARIES ${SYSLIBS})
+add_executable(${PROJECT_NAME} ${TARGET_SRC} ${TARGET_H} ${TARGET_RESX})
+
+# Note: The property VS_GLOBAL_KEYWORD must be set.
+set_property(TARGET ${PROJECT_NAME} PROPERTY VS_GLOBAL_KEYWORD "ManagedCProj")
+
+# Note: The property VS_DOTNET_REFERENCES must be set.
+set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES "System" "System.Data" "System.Drawing" "System.Windows.Forms" "System.Xml")
+
+# Note: Modification of compiler flags is required for CLR compatibility now that we are using .resx files.
+string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
diff --git a/Tests/VSWindowsFormsResx/WindowsFormsResx/Header.h b/Tests/VSWindowsFormsResx/WindowsFormsResx/Header.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/VSWindowsFormsResx/WindowsFormsResx/Header.h
diff --git a/Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.cpp b/Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.cpp
new file mode 100644
index 0000000000..154e268c70
--- /dev/null
+++ b/Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.cpp
@@ -0,0 +1 @@
+#include "MyForm.h" \ No newline at end of file
diff --git a/Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.h b/Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.h
new file mode 100644
index 0000000000..16222c5d4e
--- /dev/null
+++ b/Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.h
@@ -0,0 +1,78 @@
+#pragma once
+
+namespace Farrier {
+
+ using namespace System;
+ using namespace System::ComponentModel;
+ using namespace System::Collections;
+ using namespace System::Windows::Forms;
+ using namespace System::Data;
+ using namespace System::Drawing;
+
+ /// <summary>
+ /// Summary for MyForm
+ /// </summary>
+ public ref class MyForm : public System::Windows::Forms::Form
+ {
+ public:
+ MyForm(void)
+ {
+ InitializeComponent();
+ //
+ //TODO: Add the constructor code here
+ //
+ }
+
+ protected:
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ ~MyForm()
+ {
+ if (components)
+ {
+ delete components;
+ }
+ }
+ private: System::Windows::Forms::Button^ button1;
+ protected:
+
+ private:
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ System::ComponentModel::Container ^components;
+
+#pragma region Windows Form Designer generated code
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ void InitializeComponent(void)
+ {
+ this->button1 = (gcnew System::Windows::Forms::Button());
+ this->SuspendLayout();
+ //
+ // button1
+ //
+ this->button1->Location = System::Drawing::Point(13, 13);
+ this->button1->Name = L"button1";
+ this->button1->Size = System::Drawing::Size(75, 23);
+ this->button1->TabIndex = 0;
+ this->button1->Text = L"button1";
+ this->button1->UseVisualStyleBackColor = true;
+ //
+ // MyForm
+ //
+ this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
+ this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
+ this->ClientSize = System::Drawing::Size(284, 261);
+ this->Controls->Add(this->button1);
+ this->Name = L"MyForm";
+ this->Text = L"MyForm";
+ this->ResumeLayout(false);
+
+ }
+#pragma endregion
+ };
+}
diff --git a/Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.resx b/Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.resx
new file mode 100644
index 0000000000..e8ae276d99
--- /dev/null
+++ b/Tests/VSWindowsFormsResx/WindowsFormsResx/MyForm.resx
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root> \ No newline at end of file
diff --git a/Tests/VSWindowsFormsResx/WindowsFormsResx/Source.cpp b/Tests/VSWindowsFormsResx/WindowsFormsResx/Source.cpp
new file mode 100644
index 0000000000..aee9e2eb40
--- /dev/null
+++ b/Tests/VSWindowsFormsResx/WindowsFormsResx/Source.cpp
@@ -0,0 +1,4 @@
+int main(int argc, char **argv)
+{
+ return 0;
+}
diff --git a/Tests/VariableUnusedViaSet/CMakeLists.txt b/Tests/VariableUnusedViaSet/CMakeLists.txt
new file mode 100644
index 0000000000..0123ab2211
--- /dev/null
+++ b/Tests/VariableUnusedViaSet/CMakeLists.txt
@@ -0,0 +1,4 @@
+set(UNUSED_VARIABLE)
+# Warning should occur here
+set(UNUSED_VARIABLE "Usage")
+message(STATUS "${UNUSED_VARIABLE}")
diff --git a/Tests/VariableUnusedViaUnset/CMakeLists.txt b/Tests/VariableUnusedViaUnset/CMakeLists.txt
new file mode 100644
index 0000000000..4b4031da3f
--- /dev/null
+++ b/Tests/VariableUnusedViaUnset/CMakeLists.txt
@@ -0,0 +1,8 @@
+# NOTE: Changing lines in here changes the test results since the first
+# instance shouldn't warn, but the second should and they have the same message
+
+# A warning should NOT be issued for this line:
+set(UNUSED_VARIABLE)
+# Warning should occur here:
+set(UNUSED_VARIABLE)
+message(STATUS "${UNUSED_VARIABLE}")
diff --git a/Tests/VariableUsage/CMakeLists.txt b/Tests/VariableUsage/CMakeLists.txt
new file mode 100644
index 0000000000..4da1f56c7f
--- /dev/null
+++ b/Tests/VariableUsage/CMakeLists.txt
@@ -0,0 +1 @@
+message(STATUS "${USED_VARIABLE}")
diff --git a/Tests/VisibilityInlinesHidden/CMakeLists.txt b/Tests/VisibilityInlinesHidden/CMakeLists.txt
new file mode 100644
index 0000000000..8ebc39c756
--- /dev/null
+++ b/Tests/VisibilityInlinesHidden/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(VisibilityInlinesHidden)
+
+add_library(inlines_hidden SHARED foo.cpp bar.c)
+set_property(TARGET inlines_hidden PROPERTY VISIBILITY_INLINES_HIDDEN ON)
+target_compile_options(inlines_hidden PRIVATE -Werror)
+
+add_custom_command(TARGET inlines_hidden POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ -DCMAKE_NM=${CMAKE_NM}
+ -DTEST_LIBRARY_PATH=$<TARGET_FILE:inlines_hidden>
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/verify.cmake
+)
diff --git a/Tests/VisibilityInlinesHidden/bar.c b/Tests/VisibilityInlinesHidden/bar.c
new file mode 100644
index 0000000000..e425999867
--- /dev/null
+++ b/Tests/VisibilityInlinesHidden/bar.c
@@ -0,0 +1 @@
+void bar() {}
diff --git a/Tests/VisibilityInlinesHidden/foo.cpp b/Tests/VisibilityInlinesHidden/foo.cpp
new file mode 100644
index 0000000000..2b66b69be0
--- /dev/null
+++ b/Tests/VisibilityInlinesHidden/foo.cpp
@@ -0,0 +1,11 @@
+class Foo
+{
+public:
+ void bar() {}
+};
+
+void baz()
+{
+ Foo foo;
+ foo.bar();
+}
diff --git a/Tests/VisibilityInlinesHidden/verify.cmake b/Tests/VisibilityInlinesHidden/verify.cmake
new file mode 100644
index 0000000000..80dd13c4e6
--- /dev/null
+++ b/Tests/VisibilityInlinesHidden/verify.cmake
@@ -0,0 +1,14 @@
+execute_process(COMMAND ${CMAKE_NM} -D ${TEST_LIBRARY_PATH}
+ RESULT_VARIABLE RESULT
+ OUTPUT_VARIABLE OUTPUT
+ ERROR_VARIABLE ERROR
+)
+
+if(NOT "${RESULT}" STREQUAL "0")
+ message(FATAL_ERROR "nm failed [${RESULT}] [${OUTPUT}] [${ERROR}]")
+endif()
+
+if(${OUTPUT} MATCHES "Foo[^\\n]*bar")
+ message(FATAL_ERROR
+ "Found Foo::bar() which should have been hidden [${OUTPUT}]")
+endif()
diff --git a/Tests/WarnUnusedCliUnused/CMakeLists.txt b/Tests/WarnUnusedCliUnused/CMakeLists.txt
new file mode 100644
index 0000000000..7ed69bf3c8
--- /dev/null
+++ b/Tests/WarnUnusedCliUnused/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(WarnUnusedCliUnused)
+
+set_directory_properties(PROPERTIES
+ ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_BINARY_DIR}/CMakeCache.txt"
+)
+
+add_library(dummy empty.cpp)
diff --git a/Tests/WarnUnusedCliUnused/empty.cpp b/Tests/WarnUnusedCliUnused/empty.cpp
new file mode 100644
index 0000000000..7279c5e0b9
--- /dev/null
+++ b/Tests/WarnUnusedCliUnused/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty(void)
+{
+ return 0;
+}
diff --git a/Tests/Wrapping/CMakeLists.txt b/Tests/Wrapping/CMakeLists.txt
new file mode 100644
index 0000000000..cbb28a1b0d
--- /dev/null
+++ b/Tests/Wrapping/CMakeLists.txt
@@ -0,0 +1,106 @@
+#
+# Wrapping
+#
+cmake_minimum_required (VERSION 2.6)
+project (Wrapping)
+
+# Disable cleaning of custom command outputs to preserve the hacks
+# used to generate the files using CONFIGURE_FILE.
+set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1)
+
+#
+# Lib and exe path
+#
+set (LIBRARY_OUTPUT_PATH
+ ${Wrapping_BINARY_DIR}/bin/ CACHE INTERNAL
+ "Single output directory for building all libraries.")
+
+set (EXECUTABLE_OUTPUT_PATH
+ ${Wrapping_BINARY_DIR}/bin/ CACHE INTERNAL
+ "Single output directory for building all executables.")
+
+#
+# Where will executable tests be written ?
+#
+if (EXECUTABLE_OUTPUT_PATH)
+ set (CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
+else ()
+ set (CXX_TEST_PATH .)
+endif ()
+
+#
+# Add exe
+#
+add_executable (wrapping wrapping.cxx)
+
+add_executable (Wrap Wrap.c)
+if(WIN32)
+ set(EXE_EXT ".exe")
+endif()
+set(WRAP ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/Wrap${EXE_EXT})
+
+#
+# Qt Wrappers
+#
+
+set (QT_WRAP_CPP "On")
+set (QT_MOC_EXE "echo")
+include( FindQt3 )
+
+if (QT_FOUND AND QT_WRAP_UI)
+ message("found Qt 3 test it...")
+ include_directories( ${QT_INCLUDE_DIR} )
+ include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
+
+
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/foo.ui.in
+ ${CMAKE_CURRENT_BINARY_DIR}/foo.ui)
+
+ set (QT_WRAP_UI "On")
+ set (QT_UIC_EXE "${QT_UIC_EXECUTABLE}")
+
+
+ set (QTUI_SRCS
+ qtwrapping.ui
+ ${CMAKE_CURRENT_BINARY_DIR}/foo.ui
+ )
+ qt_wrap_ui (myqtlib QTUI_H_SRCS QTUI_S_SRCS ${QTUI_SRCS})
+ qt_wrap_cpp (myqtlib QT_MOC_SRCS ${SRCS} vtkTestMoc.h)
+
+ message("Qt files are ${QTUI_S_SRCS}")
+ message("Qt other files are ${QTUI_H_SRCS}")
+ add_definitions(${QT_DEFINITIONS})
+ add_library(myqtlib ${QTUI_S_SRCS} ${QT_MOC_SRCS})
+ add_executable (qtwrapping qtwrappingmain.cxx)
+ target_link_libraries(qtwrapping myqtlib)
+
+ target_link_libraries( qtwrapping ${QT_LIBRARIES} )
+else ()
+ add_executable (qtwrapping qtnoqtmain.cxx)
+endif ()
+
+#
+# FLTK Wrappers
+#
+# 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})
+add_library(wraplibFLTK ${wraplibFLTK_FLTK_UI_SRCS})
+add_dependencies(wraplibFLTK fakefluid)
+add_dependencies(fakefluid Wrap)
+#
+# Mangled Mesa
+#
+configure_file(
+ ${Wrapping_SOURCE_DIR}/dummy
+ ${Wrapping_BINARY_DIR}/gl.h
+ COPYONLY)
+use_mangled_mesa (${Wrapping_BINARY_DIR} ${Wrapping_BINARY_DIR}/mangled_mesa)
+
diff --git a/Tests/Wrapping/Wrap.c b/Tests/Wrapping/Wrap.c
new file mode 100644
index 0000000000..0a1ff501e8
--- /dev/null
+++ b/Tests/Wrapping/Wrap.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+#ifdef __CLASSIC_C__
+int main(argc, argv)
+ int argc;
+ char ** argv;
+#else
+int main(int argc, const char* argv[])
+#endif
+{
+ FILE* fout = fopen(argv[argc-1], "w");
+ printf("Wrap creating \"%s\"\n", argv[argc-1]);
+ if(fout)
+ {
+ fprintf(fout, "int foo() { return 0; }\n");
+ fclose(fout);
+ }
+ else
+ {
+ return -1;
+ }
+ return 0;
+}
diff --git a/Tests/Wrapping/dummy b/Tests/Wrapping/dummy
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/Wrapping/dummy
diff --git a/Tests/Wrapping/fakefluid.cxx b/Tests/Wrapping/fakefluid.cxx
new file mode 100644
index 0000000000..af4467997c
--- /dev/null
+++ b/Tests/Wrapping/fakefluid.cxx
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <string.h>
+int main(int ac, char** av)
+{
+ for(int i =0; i < ac; ++i)
+ {
+ if(strcmp(av[i], "-o") == 0 ||
+ strcmp(av[i], "-h") == 0)
+ {
+ fprintf(stdout, "fakefluid is creating file \"%s\"\n", av[i+1]);
+ FILE* file = fopen(av[i+1], "w");
+ fprintf(file, "// hello\n");
+ fclose(file);
+ }
+ }
+ return 0;
+}
diff --git a/Tests/Wrapping/fltk1.fl b/Tests/Wrapping/fltk1.fl
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/Wrapping/fltk1.fl
diff --git a/Tests/Wrapping/foo.ui.in b/Tests/Wrapping/foo.ui.in
new file mode 100644
index 0000000000..4f57b5db12
--- /dev/null
+++ b/Tests/Wrapping/foo.ui.in
@@ -0,0 +1,44 @@
+<!DOCTYPE UI><UI>
+<class>foo</class>
+<widget>
+ <class>QDialog</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>qtwrapping</cstring>
+ </property>
+ <property stdset="1">
+ <name>geometry</name>
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>229</width>
+ <height>38</height>
+ </rect>
+ </property>
+ <property stdset="1">
+ <name>caption</name>
+ <string>QTWrapUI Test program</string>
+ </property>
+ <vbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>11</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget>
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TextLabel1</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>This is a test for QTWrapUI.</string>
+ </property>
+ </widget>
+ </vbox>
+</widget>
+</UI>
diff --git a/Tests/Wrapping/hints b/Tests/Wrapping/hints
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/Wrapping/hints
diff --git a/Tests/Wrapping/itkWrapperConfig.cxx b/Tests/Wrapping/itkWrapperConfig.cxx
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/Wrapping/itkWrapperConfig.cxx
diff --git a/Tests/Wrapping/qtnoqtmain.cxx b/Tests/Wrapping/qtnoqtmain.cxx
new file mode 100644
index 0000000000..92594d52e0
--- /dev/null
+++ b/Tests/Wrapping/qtnoqtmain.cxx
@@ -0,0 +1,5 @@
+int main(int ac, char** av)
+{
+ return 0;
+}
+
diff --git a/Tests/Wrapping/qtwrapping.ui b/Tests/Wrapping/qtwrapping.ui
new file mode 100644
index 0000000000..67dcb9fbca
--- /dev/null
+++ b/Tests/Wrapping/qtwrapping.ui
@@ -0,0 +1,44 @@
+<!DOCTYPE UI><UI>
+<class>qtwrapping</class>
+<widget>
+ <class>QDialog</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>qtwrapping</cstring>
+ </property>
+ <property stdset="1">
+ <name>geometry</name>
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>229</width>
+ <height>38</height>
+ </rect>
+ </property>
+ <property stdset="1">
+ <name>caption</name>
+ <string>QTWrapUI Test program</string>
+ </property>
+ <vbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>11</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget>
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TextLabel1</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>This is a test for QTWrapUI.</string>
+ </property>
+ </widget>
+ </vbox>
+</widget>
+</UI>
diff --git a/Tests/Wrapping/qtwrappingmain.cxx b/Tests/Wrapping/qtwrappingmain.cxx
new file mode 100644
index 0000000000..fabecfc720
--- /dev/null
+++ b/Tests/Wrapping/qtwrappingmain.cxx
@@ -0,0 +1,29 @@
+#include <qapplication.h>
+#include "qtwrapping.h"
+
+#ifndef _WIN32
+# include <stdlib.h>
+# include <stdio.h>
+#endif
+
+int main(int argc, char *argv[])
+{
+#ifndef _WIN32
+ const char* display = getenv("DISPLAY");
+ if ( display && strlen(display)>0 )
+ {
+#endif
+ QApplication app(argc,argv);
+
+ qtwrapping qtw;
+ app.setMainWidget(&qtw);
+#ifndef _WIN32
+ }
+ else
+ {
+ printf("Environment variable DISPLAY is not set. I will pretend like the test passed, but you should really set it.\n");
+ }
+#endif
+
+ return 0;
+}
diff --git a/Tests/Wrapping/vtkExcluded.cxx b/Tests/Wrapping/vtkExcluded.cxx
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/Wrapping/vtkExcluded.cxx
diff --git a/Tests/Wrapping/vtkExcluded.h b/Tests/Wrapping/vtkExcluded.h
new file mode 100644
index 0000000000..835f61a3ed
--- /dev/null
+++ b/Tests/Wrapping/vtkExcluded.h
@@ -0,0 +1,2 @@
+// A comment
+// Another comment
diff --git a/Tests/Wrapping/vtkIncluded.cxx b/Tests/Wrapping/vtkIncluded.cxx
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Tests/Wrapping/vtkIncluded.cxx
diff --git a/Tests/Wrapping/vtkIncluded.h b/Tests/Wrapping/vtkIncluded.h
new file mode 100644
index 0000000000..a1c4aba26e
--- /dev/null
+++ b/Tests/Wrapping/vtkIncluded.h
@@ -0,0 +1,2 @@
+// A comment
+// Another comment (force coverage)
diff --git a/Tests/Wrapping/vtkTestMoc.h b/Tests/Wrapping/vtkTestMoc.h
new file mode 100644
index 0000000000..f11a927f0e
--- /dev/null
+++ b/Tests/Wrapping/vtkTestMoc.h
@@ -0,0 +1,8 @@
+#include <qapplication.h>
+
+class Foo : public QApplication
+{
+ Q_OBJECT
+public:
+ Foo();
+};
diff --git a/Tests/Wrapping/wrapping.cxx b/Tests/Wrapping/wrapping.cxx
new file mode 100644
index 0000000000..1482f27e53
--- /dev/null
+++ b/Tests/Wrapping/wrapping.cxx
@@ -0,0 +1,4 @@
+int main ()
+{
+ return 0;
+}
diff --git a/Tests/X11/CMakeLists.txt b/Tests/X11/CMakeLists.txt
new file mode 100644
index 0000000000..76ae58c741
--- /dev/null
+++ b/Tests/X11/CMakeLists.txt
@@ -0,0 +1,40 @@
+# a simple C only test case
+cmake_minimum_required (VERSION 2.6)
+project (UseX11 CXX C)
+
+include (${CMAKE_ROOT}/Modules/FindX11.cmake)
+message("X11_FOUND: ${X11_FOUND}")
+
+add_executable (UseX11 X11.c)
+install(TARGETS UseX11 DESTINATION bin)
+
+# so for universal binaries this test will fail if
+#
+if(APPLE)
+ list(LENGTH CMAKE_OSX_ARCHITECTURES NUMARCH)
+ if(NUMARCH GREATER 1)
+ if(NOT EXISTS /usr/X11R6/lib//libSM.6.dylib)
+ set(X11_FOUND FALSE)
+ message("disable X11, because of universal binary and sysroot")
+ endif()
+ endif()
+endif()
+
+if(X11_FOUND)
+ add_definitions(-DCMAKE_HAS_X)
+ include_directories(${X11_INCLUDE_DIR})
+ target_link_libraries(UseX11 ${X11_LIBRARIES})
+ if(APPLE)
+ add_executable(HelloWorldX11 HelloWorldX11.cxx)
+ target_link_libraries(HelloWorldX11 ${X11_LIBRARIES})
+ install(TARGETS HelloWorldX11 DESTINATION bin)
+
+ set(CPACK_BINARY_OSXX11 ON CACHE BOOL "" FORCE)
+ set(CPACK_BINARY_PACKAGEMAKER OFF CACHE BOOL "" FORCE )
+ set(CPACK_PACKAGE_NAME HelloWorldX11Package)
+ set(CPACK_PACKAGE_EXECUTABLES HelloWorldX11 HelloWorldX11)
+ endif()
+endif()
+
+# build a CPack driven installer package
+include(CPack)
diff --git a/Tests/X11/HelloWorldX11.cxx b/Tests/X11/HelloWorldX11.cxx
new file mode 100644
index 0000000000..f2b8bdd473
--- /dev/null
+++ b/Tests/X11/HelloWorldX11.cxx
@@ -0,0 +1,146 @@
+
+/*** START MAIN.H ***/
+/* http://www.geocities.com/jeff_louie/x11/helloworld.htm* */
+/*
+ * main.h
+ * TestX
+ *
+ * Created by Jeff Louie on Tue Feb 03 2004.
+ * Copyright (c) 2004 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+
+#ifndef MAIN_H
+#define MAIN_H 1
+
+#include <iostream>
+#include <stdlib.h>
+
+/* include the X library headers */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+
+class Main {
+
+public:
+ // constructor
+ Main(int argc, char * const argv[]);
+ //virtual ~Main();
+
+
+private:
+
+
+ /* here are our X variables */
+ Display *dis;
+ int screen;
+ Window win;
+ GC gc;
+
+ /* here are our X routines declared! */
+ void init_x();
+ void close_x();
+ void redraw();
+ int delay(int i);
+
+};
+
+#endif
+
+/*** END MAIN.H ***/
+
+/*** START MAIN.CPP ***/
+
+// modified from Brian Hammond's Howdy program at
+// http://www.insanityengine.com/doc/x11/xintro.html
+// jeff louie 02.05.2004
+
+
+
+int main (int argc, char * const argv[]) {
+ Main m(argc, argv);
+ return 0;
+}
+
+//Main::~Main() {;};
+Main::Main (int argc, char * const argv[]) {
+ XEvent event; // XEvent declaration
+ KeySym key; // KeyPress Events
+ char text[255]; // char buffer for KeyPress Events
+
+ init_x();
+
+ // event loop
+ while(1) {
+ // get the next event and stuff it into our event variable.
+ // Note: only events we set the mask for are detected!
+ XNextEvent(dis, &event);
+
+
+ switch (event.type) {
+ int x;
+ int y;
+ case Expose:
+ if (event.xexpose.count==0) {
+ redraw();
+ }
+ break;
+ case KeyPress:
+ if (XLookupString(&event.xkey,text,255,&key,0)==1) {
+ // use the XLookupString routine to convert the invent
+ // KeyPress data into regular text. Weird but necessary...
+ if ((text[0]=='q') || (text[0]=='Q')) {
+ close_x();
+ }
+ else {
+ // echo key press
+ printf("You pressed the %c key!\n",text[0]);
+ }
+ }
+ break;
+ case ButtonPress:
+ // get cursor position
+ x= event.xbutton.x;
+ y= event.xbutton.y;
+ strcpy(text,"X is FUN!");
+ XSetForeground(dis,gc,rand()%event.xbutton.x%255);
+ // draw text at cursor
+ XDrawString(dis,win,gc,x,y, text, strlen(text));
+ break;
+ default:
+ printf("Unhandled event.\n");
+ }
+ }
+}
+
+void Main::init_x() {
+ unsigned long black,white;
+
+ dis=XOpenDisplay(NULL);
+ screen=DefaultScreen(dis);
+ black=BlackPixel(dis,screen),
+ white=WhitePixel(dis, screen);
+ win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,
+ 300, 300, 5,black, white);
+ XSetStandardProperties(dis,win,"Hello World","Hi",None,NULL,0,NULL);
+ XSelectInput(dis, win, ExposureMask|ButtonPressMask|KeyPressMask);
+ // get Graphics Context
+ gc=XCreateGC(dis, win, 0,0);
+ XSetBackground(dis,gc,white);
+ XSetForeground(dis,gc,black);
+ XClearWindow(dis, win);
+ XMapRaised(dis, win);
+};
+
+void Main::close_x() {
+ XFreeGC(dis, gc);
+ XDestroyWindow(dis,win);
+ XCloseDisplay(dis);
+ exit(1);
+};
+
+void Main::redraw() {
+ XClearWindow(dis, win);
+};
diff --git a/Tests/X11/X11.c b/Tests/X11/X11.c
new file mode 100644
index 0000000000..b802ed8b9b
--- /dev/null
+++ b/Tests/X11/X11.c
@@ -0,0 +1,21 @@
+#include "stdio.h"
+#ifdef CMAKE_HAS_X
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+int main()
+{
+ printf("There is X on this computer\n");
+ return 0;
+}
+
+#else
+
+int main()
+{
+ printf("No X on this computer\n");
+ return 0;
+}
+
+#endif
diff --git a/Tests/bootstrap.bat.in b/Tests/bootstrap.bat.in
new file mode 100644
index 0000000000..aeb24b1ca8
--- /dev/null
+++ b/Tests/bootstrap.bat.in
@@ -0,0 +1,2 @@
+@echo off
+sh "@CMake_SOURCE_DIR@/bootstrap" %*
diff --git a/Tests/iOSNavApp/CMakeLists.txt b/Tests/iOSNavApp/CMakeLists.txt
new file mode 100644
index 0000000000..12c3ada357
--- /dev/null
+++ b/Tests/iOSNavApp/CMakeLists.txt
@@ -0,0 +1,38 @@
+cmake_minimum_required(VERSION 2.8.5)
+project(NavApp3)
+
+set(CMAKE_OSX_SYSROOT iphoneos4.3)
+set(CMAKE_OSX_ARCHITECTURES "armv6;armv7;i386")
+set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
+
+include_directories(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/Classes
+ )
+
+add_library(Functions STATIC TotalFunction.c TotalFunction.h)
+
+set(M_SRCS main.m Classes/NavApp3AppDelegate.m Classes/RootViewController.m)
+set(HEADERS Classes/NavApp3AppDelegate.h Classes/RootViewController.h)
+set(RESOURCES MainWindow.xib RootViewController.xib)
+
+add_executable(NavApp3 MACOSX_BUNDLE ${M_SRCS} ${HEADERS} ${RESOURCES})
+
+target_link_libraries(NavApp3
+ Functions
+ "-framework CoreGraphics"
+ "-framework Foundation"
+ "-framework UIKit"
+ )
+
+set_target_properties(NavApp3 PROPERTIES
+ MACOSX_BUNDLE_GUI_IDENTIFIER "com.yourcompany.NavApp3"
+ MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in
+ RESOURCE "${RESOURCES}"
+ XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
+ XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym"
+ XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER YES
+ XCODE_ATTRIBUTE_GCC_PREFIX_HEADER ${CMAKE_CURRENT_LIST_DIR}/NavApp3_Prefix.pch
+ XCODE_ATTRIBUTE_INFOPLIST_PREPROCESS YES
+ XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 3.0
+ )
diff --git a/Tests/iOSNavApp/Classes/NavApp3AppDelegate.h b/Tests/iOSNavApp/Classes/NavApp3AppDelegate.h
new file mode 100644
index 0000000000..f1234fe8b4
--- /dev/null
+++ b/Tests/iOSNavApp/Classes/NavApp3AppDelegate.h
@@ -0,0 +1,20 @@
+//
+// NavApp3AppDelegate.h
+// NavApp3
+//
+// Created by David Cole on 6/23/11.
+// Copyright 2011 Kitware, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface NavApp3AppDelegate : NSObject <UIApplicationDelegate> {
+
+ UIWindow *window;
+ UINavigationController *navigationController;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
+
+@end
diff --git a/Tests/iOSNavApp/Classes/NavApp3AppDelegate.m b/Tests/iOSNavApp/Classes/NavApp3AppDelegate.m
new file mode 100644
index 0000000000..c82204c111
--- /dev/null
+++ b/Tests/iOSNavApp/Classes/NavApp3AppDelegate.m
@@ -0,0 +1,88 @@
+//
+// NavApp3AppDelegate.m
+// NavApp3
+//
+// Created by David Cole on 6/23/11.
+// Copyright 2011 Kitware, Inc. All rights reserved.
+//
+
+#import "NavApp3AppDelegate.h"
+#import "RootViewController.h"
+
+
+@implementation NavApp3AppDelegate
+
+@synthesize window;
+@synthesize navigationController;
+
+
+#pragma mark -
+#pragma mark Application lifecycle
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+
+ // Override point for customization after application launch.
+ // Add the navigation controller's view to the window and display.
+ [self.window addSubview:navigationController.view];
+ [self.window makeKeyAndVisible];
+
+ return YES;
+}
+
+
+- (void)applicationWillResignActive:(UIApplication *)application {
+ /*
+ Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+ */
+}
+
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ /*
+ Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
+ */
+}
+
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+ /*
+ Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
+ */
+}
+
+
+- (void)applicationDidBecomeActive:(UIApplication *)application {
+ /*
+ Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+ */
+}
+
+
+- (void)applicationWillTerminate:(UIApplication *)application {
+ /*
+ Called when the application is about to terminate.
+ See also applicationDidEnterBackground:.
+ */
+}
+
+
+#pragma mark -
+#pragma mark Memory management
+
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
+ /*
+ Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
+ */
+}
+
+
+- (void)dealloc {
+ [navigationController release];
+ [window release];
+ [super dealloc];
+}
+
+
+@end
diff --git a/Tests/iOSNavApp/Classes/RootViewController.h b/Tests/iOSNavApp/Classes/RootViewController.h
new file mode 100644
index 0000000000..c5e9c1148a
--- /dev/null
+++ b/Tests/iOSNavApp/Classes/RootViewController.h
@@ -0,0 +1,14 @@
+//
+// RootViewController.h
+// NavApp3
+//
+// Created by David Cole on 6/23/11.
+// Copyright 2011 Kitware, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface RootViewController : UITableViewController {
+}
+
+@end
diff --git a/Tests/iOSNavApp/Classes/RootViewController.m b/Tests/iOSNavApp/Classes/RootViewController.m
new file mode 100644
index 0000000000..8a20d89db4
--- /dev/null
+++ b/Tests/iOSNavApp/Classes/RootViewController.m
@@ -0,0 +1,168 @@
+//
+// RootViewController.m
+// NavApp3
+//
+// Created by David Cole on 6/23/11.
+// Copyright 2011 Kitware, Inc. All rights reserved.
+//
+
+#import "RootViewController.h"
+
+#include "TotalFunction.h"
+
+
+@implementation RootViewController
+
+
+#pragma mark -
+#pragma mark View lifecycle
+
+/*
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+ // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+*/
+
+/*
+- (void)viewWillAppear:(BOOL)animated {
+ [super viewWillAppear:animated];
+}
+*/
+/*
+- (void)viewDidAppear:(BOOL)animated {
+ [super viewDidAppear:animated];
+}
+*/
+/*
+- (void)viewWillDisappear:(BOOL)animated {
+ [super viewWillDisappear:animated];
+}
+*/
+/*
+- (void)viewDidDisappear:(BOOL)animated {
+ [super viewDidDisappear:animated];
+}
+*/
+
+/*
+ // Override to allow orientations other than the default portrait orientation.
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
+ // Return YES for supported orientations.
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+ */
+
+
+#pragma mark -
+#pragma mark Table view data source
+
+// Customize the number of sections in the table view.
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ return 1;
+}
+
+
+// Customize the number of rows in the table view.
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ int n = Total("numberOfRows");
+ return n;
+}
+
+
+// Customize the appearance of table view cells.
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ static NSString *CellIdentifier = @"Cell";
+
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ if (cell == nil) {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
+ }
+
+ // Configure the cell.
+ cell.textLabel.text = [NSString stringWithFormat:@"%d", [indexPath row]];
+
+ return cell;
+}
+
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
+ // Return NO if you do not want the specified item to be editable.
+ return YES;
+}
+*/
+
+
+/*
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ // Delete the row from the data source.
+ [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ }
+ else if (editingStyle == UITableViewCellEditingStyleInsert) {
+ // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
+ }
+}
+*/
+
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
+}
+*/
+
+
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
+ // Return NO if you do not want the item to be re-orderable.
+ return YES;
+}
+*/
+
+
+#pragma mark -
+#pragma mark Table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ /*
+ <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
+ // ...
+ // Pass the selected object to the new view controller.
+ [self.navigationController pushViewController:detailViewController animated:YES];
+ [detailViewController release];
+ */
+}
+
+
+#pragma mark -
+#pragma mark Memory management
+
+- (void)didReceiveMemoryWarning {
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+
+ // Relinquish ownership any cached data, images, etc that aren't in use.
+}
+
+- (void)viewDidUnload {
+ // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
+ // For example: self.myOutlet = nil;
+}
+
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+
+@end
diff --git a/Tests/iOSNavApp/Info.plist.in b/Tests/iOSNavApp/Info.plist.in
new file mode 100644
index 0000000000..6ea0f00eee
--- /dev/null
+++ b/Tests/iOSNavApp/Info.plist.in
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleDisplayName</key>
+ <string>NavApp3</string>
+ <key>CFBundleExecutable</key>
+ <string>NavApp3</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.NavApp3</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>NavApp3</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>NSMainNibFile</key>
+ <string>MainWindow</string>
+ <key>UISupportedInterfaceOrientations</key>
+ <array/>
+</dict>
+</plist>
diff --git a/Tests/iOSNavApp/MainWindow.xib b/Tests/iOSNavApp/MainWindow.xib
new file mode 100644
index 0000000000..1ff5f67fc1
--- /dev/null
+++ b/Tests/iOSNavApp/MainWindow.xib
@@ -0,0 +1,542 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
+ <data>
+ <int key="IBDocument.SystemTarget">1024</int>
+ <string key="IBDocument.SystemVersion">10D571</string>
+ <string key="IBDocument.InterfaceBuilderVersion">786</string>
+ <string key="IBDocument.AppKitVersion">1038.29</string>
+ <string key="IBDocument.HIToolboxVersion">460.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="NS.object.0">112</string>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="13"/>
+ </object>
+ <object class="NSArray" key="IBDocument.PluginDependencies">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </object>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys" id="0">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBProxyObject" id="841351856">
+ <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBProxyObject" id="302016328">
+ <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUICustomObject" id="664661524">
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUIWindow" id="380026005">
+ <nil key="NSNextResponder"/>
+ <int key="NSvFlags">1316</int>
+ <object class="NSPSMatrix" key="NSFrameMatrix"/>
+ <string key="NSFrameSize">{320, 480}</string>
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MSAxIDEAA</bytes>
+ </object>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClearsContextBeforeDrawing">NO</bool>
+ <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBUIResizesToFullScreen">YES</bool>
+ </object>
+ <object class="IBUINavigationController" id="701001926">
+ <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
+ <object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
+ <int key="interfaceOrientation">1</int>
+ </object>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBUIHorizontal">NO</bool>
+ <object class="IBUINavigationBar" key="IBUINavigationBar" id="207850653">
+ <nil key="NSNextResponder"/>
+ <int key="NSvFlags">256</int>
+ <string key="NSFrameSize">{0, 0}</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <bool key="IBUIMultipleTouchEnabled">YES</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="NSMutableArray" key="IBUIViewControllers">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBUIViewController" id="619226028">
+ <object class="IBUINavigationItem" key="IBUINavigationItem" id="394667715">
+ <reference key="IBUINavigationBar"/>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <reference key="IBUIParentViewController" ref="701001926"/>
+ <string key="IBUINibName">RootViewController</string>
+ <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
+ <object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
+ <int key="interfaceOrientation">1</int>
+ </object>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBUIHorizontal">NO</bool>
+ </object>
+ </object>
+ </object>
+ </object>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <object class="NSMutableArray" key="connectionRecords">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="841351856"/>
+ <reference key="destination" ref="664661524"/>
+ </object>
+ <int key="connectionID">4</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">window</string>
+ <reference key="source" ref="664661524"/>
+ <reference key="destination" ref="380026005"/>
+ </object>
+ <int key="connectionID">5</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">navigationController</string>
+ <reference key="source" ref="664661524"/>
+ <reference key="destination" ref="701001926"/>
+ </object>
+ <int key="connectionID">15</int>
+ </object>
+ </object>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <object class="NSArray" key="orderedObjects">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <reference key="object" ref="0"/>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">2</int>
+ <reference key="object" ref="380026005"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="841351856"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">3</int>
+ <reference key="object" ref="664661524"/>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="302016328"/>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">9</int>
+ <reference key="object" ref="701001926"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="207850653"/>
+ <reference ref="619226028"/>
+ </object>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">11</int>
+ <reference key="object" ref="207850653"/>
+ <reference key="parent" ref="701001926"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">13</int>
+ <reference key="object" ref="619226028"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="394667715"/>
+ </object>
+ <reference key="parent" ref="701001926"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">14</int>
+ <reference key="object" ref="394667715"/>
+ <reference key="parent" ref="619226028"/>
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="flattenedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-1.CustomClassName</string>
+ <string>-2.CustomClassName</string>
+ <string>11.IBPluginDependency</string>
+ <string>13.CustomClassName</string>
+ <string>13.IBPluginDependency</string>
+ <string>2.IBAttributePlaceholdersKey</string>
+ <string>2.IBEditorWindowLastContentRect</string>
+ <string>2.IBPluginDependency</string>
+ <string>3.CustomClassName</string>
+ <string>3.IBPluginDependency</string>
+ <string>9.IBEditorWindowLastContentRect</string>
+ <string>9.IBPluginDependency</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>UIApplication</string>
+ <string>UIResponder</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>RootViewController</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <object class="NSMutableDictionary">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <string>{{673, 376}, {320, 480}}</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>NavApp3AppDelegate</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>{{186, 376}, {320, 480}}</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="unlocalizedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="activeLocalization"/>
+ <object class="NSMutableDictionary" key="localizations">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="sourceID"/>
+ <int key="maxID">16</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <object class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">RootViewController</string>
+ <string key="superclassName">UITableViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">Classes/RootViewController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIWindow</string>
+ <string key="superclassName">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBUserSource</string>
+ <string key="minorKey"/>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NavApp3AppDelegate</string>
+ <string key="superclassName">NSObject</string>
+ <object class="NSMutableDictionary" key="outlets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>navigationController</string>
+ <string>window</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>UINavigationController</string>
+ <string>UIWindow</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>navigationController</string>
+ <string>window</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBToOneOutletInfo">
+ <string key="name">navigationController</string>
+ <string key="candidateClassName">UINavigationController</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">window</string>
+ <string key="candidateClassName">UIWindow</string>
+ </object>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">Classes/NavApp3AppDelegate.h</string>
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSError.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSFileManager.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSKeyValueCoding.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSKeyValueObserving.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSKeyedArchiver.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSObject.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSRunLoop.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSThread.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSURL.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSURLConnection.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIAccessibility.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UINibLoading.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier" id="48103097">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIResponder.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIApplication</string>
+ <string key="superclassName">UIResponder</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIApplication.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIBarButtonItem</string>
+ <string key="superclassName">UIBarItem</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIBarButtonItem.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIBarItem</string>
+ <string key="superclassName">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIBarItem.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UINavigationBar</string>
+ <string key="superclassName">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier" id="193736137">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UINavigationBar.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UINavigationController</string>
+ <string key="superclassName">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier" id="720195805">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UINavigationController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UINavigationItem</string>
+ <string key="superclassName">NSObject</string>
+ <reference key="sourceIdentifier" ref="193736137"/>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIResponder</string>
+ <string key="superclassName">NSObject</string>
+ <reference key="sourceIdentifier" ref="48103097"/>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UISearchBar</string>
+ <string key="superclassName">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UISearchBar.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UISearchDisplayController</string>
+ <string key="superclassName">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UISearchDisplayController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UITableViewController</string>
+ <string key="superclassName">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UITableViewController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UITextField.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIView</string>
+ <string key="superclassName">UIResponder</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIView.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIViewController</string>
+ <reference key="sourceIdentifier" ref="720195805"/>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIPopoverController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UISplitViewController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UITabBarController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIViewController</string>
+ <string key="superclassName">UIResponder</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIViewController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIWindow</string>
+ <string key="superclassName">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIWindow.h</string>
+ </object>
+ </object>
+ </object>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
+ <integer value="1024" key="NS.object.0"/>
+ </object>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
+ <integer value="3100" key="NS.object.0"/>
+ </object>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <string key="IBDocument.LastKnownRelativeProjectPath">NavApp3.xcodeproj</string>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ <string key="IBCocoaTouchPluginVersion">112</string>
+ </data>
+</archive>
diff --git a/Tests/iOSNavApp/NavApp3_Prefix.pch b/Tests/iOSNavApp/NavApp3_Prefix.pch
new file mode 100644
index 0000000000..9919f30765
--- /dev/null
+++ b/Tests/iOSNavApp/NavApp3_Prefix.pch
@@ -0,0 +1,14 @@
+//
+// Prefix header for all source files of the 'NavApp3' target in the 'NavApp3' project
+//
+#import <Availability.h>
+
+#ifndef __IPHONE_3_0
+#warning "This project uses features only available in iPhone SDK 3.0 and later."
+#endif
+
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+ #import <UIKit/UIKit.h>
+#endif
diff --git a/Tests/iOSNavApp/RootViewController.xib b/Tests/iOSNavApp/RootViewController.xib
new file mode 100644
index 0000000000..12a4831f20
--- /dev/null
+++ b/Tests/iOSNavApp/RootViewController.xib
@@ -0,0 +1,384 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
+ <data>
+ <int key="IBDocument.SystemTarget">784</int>
+ <string key="IBDocument.SystemVersion">10D541</string>
+ <string key="IBDocument.InterfaceBuilderVersion">760</string>
+ <string key="IBDocument.AppKitVersion">1038.29</string>
+ <string key="IBDocument.HIToolboxVersion">460.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="NS.object.0">81</string>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="2"/>
+ </object>
+ <object class="NSArray" key="IBDocument.PluginDependencies">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </object>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys" id="0">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBProxyObject" id="841351856">
+ <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBProxyObject" id="371349661">
+ <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUITableView" id="709618507">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">274</int>
+ <string key="NSFrameSize">{320, 247}</string>
+ <reference key="NSSuperview"/>
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ </object>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <bool key="IBUIClearsContextBeforeDrawing">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBUIBouncesZoom">NO</bool>
+ <int key="IBUISeparatorStyle">1</int>
+ <int key="IBUISectionIndexMinimumDisplayRowCount">0</int>
+ <bool key="IBUIShowsSelectionImmediatelyOnTouchBegin">YES</bool>
+ <float key="IBUIRowHeight">44</float>
+ <float key="IBUISectionHeaderHeight">22</float>
+ <float key="IBUISectionFooterHeight">22</float>
+ </object>
+ </object>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <object class="NSMutableArray" key="connectionRecords">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">view</string>
+ <reference key="source" ref="841351856"/>
+ <reference key="destination" ref="709618507"/>
+ </object>
+ <int key="connectionID">3</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">dataSource</string>
+ <reference key="source" ref="709618507"/>
+ <reference key="destination" ref="841351856"/>
+ </object>
+ <int key="connectionID">4</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="709618507"/>
+ <reference key="destination" ref="841351856"/>
+ </object>
+ <int key="connectionID">5</int>
+ </object>
+ </object>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <object class="NSArray" key="orderedObjects">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <reference key="object" ref="0"/>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="841351856"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="371349661"/>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">2</int>
+ <reference key="object" ref="709618507"/>
+ <reference key="parent" ref="0"/>
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="flattenedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-1.CustomClassName</string>
+ <string>-2.CustomClassName</string>
+ <string>2.IBEditorWindowLastContentRect</string>
+ <string>2.IBPluginDependency</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>RootViewController</string>
+ <string>UIResponder</string>
+ <string>{{144, 609}, {320, 247}}</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="unlocalizedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="activeLocalization"/>
+ <object class="NSMutableDictionary" key="localizations">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="sourceID"/>
+ <int key="maxID">5</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <object class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">RootViewController</string>
+ <string key="superclassName">UITableViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">Classes/RootViewController.h</string>
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSError.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSFileManager.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSKeyValueCoding.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSKeyValueObserving.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSKeyedArchiver.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSNetServices.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSObject.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSPort.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSRunLoop.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSStream.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSThread.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSURL.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSURLConnection.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Foundation.framework/Headers/NSXMLParser.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIAccessibility.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UINibLoading.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier" id="654420027">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIResponder.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIResponder</string>
+ <string key="superclassName">NSObject</string>
+ <reference key="sourceIdentifier" ref="654420027"/>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIScrollView</string>
+ <string key="superclassName">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIScrollView.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UISearchBar</string>
+ <string key="superclassName">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UISearchBar.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UISearchDisplayController</string>
+ <string key="superclassName">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UISearchDisplayController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UITableView</string>
+ <string key="superclassName">UIScrollView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UITableView.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UITableViewController</string>
+ <string key="superclassName">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UITableViewController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UITextField.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIView</string>
+ <string key="superclassName">UIResponder</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIView.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UINavigationController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UITabBarController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIViewController</string>
+ <string key="superclassName">UIResponder</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIViewController.h</string>
+ </object>
+ </object>
+ </object>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
+ <integer value="784" key="NS.object.0"/>
+ </object>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
+ <integer value="3100" key="NS.object.0"/>
+ </object>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <string key="IBDocument.LastKnownRelativeProjectPath">NavApp3.xcodeproj</string>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ <string key="IBCocoaTouchPluginVersion">81</string>
+ </data>
+</archive>
diff --git a/Tests/iOSNavApp/TotalFunction.c b/Tests/iOSNavApp/TotalFunction.c
new file mode 100644
index 0000000000..0965a88ac2
--- /dev/null
+++ b/Tests/iOSNavApp/TotalFunction.c
@@ -0,0 +1,14 @@
+//
+// TotalFunction.c
+// NavApp3
+//
+// Created by David Cole on 8/10/11.
+// Copyright 2011 Kitware, Inc. All rights reserved.
+//
+
+#include "TotalFunction.h"
+
+int Total(const char *context)
+{
+ return 22;
+}
diff --git a/Tests/iOSNavApp/TotalFunction.h b/Tests/iOSNavApp/TotalFunction.h
new file mode 100644
index 0000000000..1301c3d64b
--- /dev/null
+++ b/Tests/iOSNavApp/TotalFunction.h
@@ -0,0 +1,14 @@
+//
+// TotalFunction.h
+// NavApp3
+//
+// Created by David Cole on 8/10/11.
+// Copyright 2011 Kitware, Inc. All rights reserved.
+//
+
+#ifndef NavApp3_TotalFunction_h
+#define NavApp3_TotalFunction_h
+
+int Total(const char *context);
+
+#endif
diff --git a/Tests/iOSNavApp/main.m b/Tests/iOSNavApp/main.m
new file mode 100644
index 0000000000..8070c47272
--- /dev/null
+++ b/Tests/iOSNavApp/main.m
@@ -0,0 +1,17 @@
+//
+// main.m
+// NavApp3
+//
+// Created by David Cole on 6/23/11.
+// Copyright 2011 Kitware, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+int main(int argc, char *argv[]) {
+
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ int retVal = UIApplicationMain(argc, argv, nil, nil);
+ [pool release];
+ return retVal;
+}
diff --git a/Tests/test_clean.cmake.in b/Tests/test_clean.cmake.in
new file mode 100644
index 0000000000..d700749ca4
--- /dev/null
+++ b/Tests/test_clean.cmake.in
@@ -0,0 +1,2 @@
+set(TEST_BUILD_DIRS "@TEST_BUILD_DIRS@")
+file(REMOVE_RECURSE ${TEST_BUILD_DIRS})
diff --git a/Utilities/.NoDartCoverage b/Utilities/.NoDartCoverage
new file mode 100644
index 0000000000..3c99729386
--- /dev/null
+++ b/Utilities/.NoDartCoverage
@@ -0,0 +1 @@
+# do not do coverage in this directory
diff --git a/Utilities/.gitattributes b/Utilities/.gitattributes
new file mode 100644
index 0000000000..e3a9e6105b
--- /dev/null
+++ b/Utilities/.gitattributes
@@ -0,0 +1,2 @@
+/Git export-ignore
+SetupForDevelopment.sh export-ignore
diff --git a/Utilities/CMakeLists.txt b/Utilities/CMakeLists.txt
new file mode 100644
index 0000000000..8b3e325fa0
--- /dev/null
+++ b/Utilities/CMakeLists.txt
@@ -0,0 +1,35 @@
+#=============================================================================
+# 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.
+#=============================================================================
+subdirs(Doxygen KWStyle)
+
+if(CMAKE_DOC_TARBALL)
+ # Undocumented option to extract and install pre-built documentation.
+ # This is intended for use during packaging of CMake itself.
+ if(CMAKE_DOC_TARBALL MATCHES "/([^/]+)\\.tar\\.gz$")
+ set(dir "${CMAKE_MATCH_1}")
+ else()
+ message(FATAL_ERROR "CMAKE_DOC_TARBALL must end in .tar.gz")
+ endif()
+ add_custom_command(
+ OUTPUT ${dir}.stamp
+ COMMAND cmake -E remove_directory ${dir}
+ COMMAND cmake -E tar xf ${CMAKE_DOC_TARBALL}
+ COMMAND cmake -E touch ${dir}.stamp
+ DEPENDS ${CMAKE_DOC_TARBALL}
+ )
+ add_custom_target(documentation ALL DEPENDS ${dir}.stamp)
+ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${dir}/
+ DESTINATION . USE_SOURCE_PERMISSIONS)
+else()
+ # Normal documentation build.
+ add_subdirectory(Sphinx)
+endif()
diff --git a/Utilities/Doxygen/CMakeLists.txt b/Utilities/Doxygen/CMakeLists.txt
new file mode 100644
index 0000000000..813e34daf2
--- /dev/null
+++ b/Utilities/Doxygen/CMakeLists.txt
@@ -0,0 +1,39 @@
+#=============================================================================
+# 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.
+#=============================================================================
+
+#
+# Build the documentation
+#
+include (${CMAKE_ROOT}/Modules/Documentation.cmake OPTIONAL)
+
+if (BUILD_DOCUMENTATION)
+
+ #
+ # Configure the script and the doxyfile, then add target
+ #
+ if(NOT DOT_PATH)
+ get_filename_component(DOT_PATH ${DOT} PATH)
+ endif()
+
+ configure_file(
+ ${CMake_SOURCE_DIR}/Utilities/Doxygen/doxyfile.in
+ ${CMake_BINARY_DIR}/Utilities/Doxygen/doxyfile)
+
+ configure_file(
+ ${CMake_SOURCE_DIR}/Utilities/Doxygen/doc_makeall.sh.in
+ ${CMake_BINARY_DIR}/Utilities/Doxygen/doc_makeall.sh)
+
+ add_custom_target(DoxygenDoc
+ ${BASH}
+ ${CMake_BINARY_DIR}/Utilities/Doxygen/doc_makeall.sh)
+
+endif ()
diff --git a/Utilities/Doxygen/authors.txt b/Utilities/Doxygen/authors.txt
new file mode 100644
index 0000000000..9ba6ccac40
--- /dev/null
+++ b/Utilities/Doxygen/authors.txt
@@ -0,0 +1,17 @@
+andy: Cedilnik, Andy (andy.cedilnik@kitware.com)
+barre: Barre, Sebastien (sebastien.barre@kitware.com)
+berk: Geveci, Berk (berk.geveci@kitware.com)
+bettingf: Bettinger, Franck (bettingf@cs.man.ac.uk)
+biddi: Biddiscombe, John (jbiddiscombe@skippingmouse.co.uk)
+blezek: Blezek, Dan (blezek@crd.ge.com)
+geoff: Cross, Geoffrey (geoff@robots.ox.ac.uk)
+hoffman: Hoffman, Bill (bill.hoffman@kitware.com)
+ibanez: Ibanez, Luis (luis.ibanez@kitware.com)
+iscott: Scott, Ian (ian.m.scott@stud.man.ac.uk)
+king: King, Brad (brad.king@kitware.com)
+lorensen: Lorensen, Bill (lorensen@crd.ge.com)
+martink, lymbdemo: Martin, Ken (ken.martin@kitware.com)
+millerjv: Miller, Jim (millerjv@crd.ge.com)
+perera: Perera, Amitha (perera@cs.rpi.edu)
+starreveld: Starreveld, Yves (ystarrev@julian.uwo.ca)
+will, schroede: Schroeder, Will (will.schroeder@kitware.com)
diff --git a/Utilities/Doxygen/doc_makeall.sh.in b/Utilities/Doxygen/doc_makeall.sh.in
new file mode 100755
index 0000000000..ed7b521e45
--- /dev/null
+++ b/Utilities/Doxygen/doc_makeall.sh.in
@@ -0,0 +1,248 @@
+# -------------------------------------------------------------------------
+# Doxygen documentation batch
+# modified by S. Barre (Time-stamp: <2003-01-16 14:04:41 barre>
+# -------------------------------------------------------------------------
+
+# Path to several tools (_PROG to avoid the typical GZIP env var pb)
+# Example:
+# DOXYGEN_PROG=@DOXYGEN@ (INCLUDE(${CMAKE_ROOT}/Modules/FindDoxygen.cmake))
+# GZIP_PROG=@GZIP@ (INCLUDE(${CMAKE_ROOT}/Modules/FindCygwin.cmake))
+# HHC_PROG=@HHC@ (INCLUDE(${CMAKE_ROOT}/Modules/FindHhc.cmake))
+# MV_PROG=@MV@ (INCLUDE(${CMAKE_ROOT}/Modules/FindCygwin.cmake))
+# PERL_PROG=@PERL@ (INCLUDE(${CMAKE_ROOT}/Modules/FindPerl.cmake))
+# RM_PROG=@RM@ (INCLUDE(${CMAKE_ROOT}/Modules/FindCygwin.cmake))
+# TAR_PROG=@TAR@ (INCLUDE(${CMAKE_ROOT}/Modules/FindCygwin.cmake))
+# WGET_PROG=@WGET@ (INCLUDE(${CMAKE_ROOT}/Modules/FindWget.cmake))
+#
+export DOXYGEN_PROG="@DOXYGEN@" # Doxygen
+export GZIP_PROG="@GZIP@" # gzip (Unix-like 'gzip compressor')
+export GNUPLOT_PROG="@GNUPLOT@" # gnuplot (data plotting program)
+export HHC_PROG="@HTML_HELP_COMPILER@" # HTML Help Compiler
+export MV_PROG="@MV@" # mv (Unix-like 'move/rename files')
+export PERL_PROG="@PERL@" # Perl
+export RM_PROG="@RM@" # rm (Unix-like 'remove files')
+export TAR_PROG="@TAR@" # tar (Unix-like 'archiver')
+export WGET_PROG="@WGET@" # wget (remote file retrieval)
+
+# PROJECT_NAME:
+# Documentation/project name. Used in some of the resulting file names and
+# xrefs to uniquify two or more projects linked together through their
+# Doxygen's tag files. Mandatory for each documentation set.
+# Note: might be the same as the doxyfile's PROJECT_NAME
+# Example:
+# PROJECT_NAME=VTK
+#
+export PROJECT_NAME=CMake
+
+# PATH_TO_VTK_DOX_SCRIPTS:
+# Path to the directory holding the Perl scripts used to produce the VTK doc
+# in Doxygen format. You need the VTK source files or a local copy of
+# these scripts.
+# Example:
+# PATH_TO_VTK_DOX_SCRIPTS=@VTK_SOURCE_DIR@/Utilities/Doxygen
+#
+export PATH_TO_VTK_DOX_SCRIPTS="@VTK_SOURCE_DIR@/Utilities/Doxygen"
+
+# SOURCE_DIR:
+# Source directory. The top directory of the source files.
+# Example:
+# SOURCE_DIR=@VTK_SOURCE_DIR@
+#
+export SOURCE_DIR="@CMake_SOURCE_DIR@"
+
+# REL_PATH_TO_TOP:
+# Relative path from the top directory of the source files to the directory
+# (or top directory) holding the files to document. Useful if several parts
+# of the same source directory should be documented separately.
+# Example:
+# REL_PATH_TO_TOP=.
+# REL_PATH_TO_TOP=framework/src
+#
+# export REL_PATH_TO_TOP=Source
+export REL_PATH_TO_TOP=.
+
+# INTERMEDIATE_DOX_DIR:
+# Directory where the intermediate Doxygen files should be stored (mainly
+# these headers files converted from the VTK format to the Doxygen format).
+# This directory is erased at the end of this script, unless you comment
+# the corresponding line.
+# DOXTEMP might be used to simplify the syntax.
+# Example:
+# DOXTEMP=DOXTEMP=@VTK_BINARY_DIR@/Utilities/Doxygen
+# INTERMEDIATE_DOX_DIR=$DOXTEMP/dox
+#
+export DOXTEMP="@CMake_BINARY_DIR@/Utilities/Doxygen"
+export INTERMEDIATE_DOX_DIR="$DOXTEMP/dox"
+
+# DOXYFILE:
+# Path to the Doxygen configuration file (i.e. doxyfile).
+# Example:
+# DOXYFILE=$DOXTEMP/doxyfile
+#
+export DOXYFILE="$DOXTEMP/doxyfile"
+
+# OUTPUT_DIRECTORY ALLOW_ERASE_OUTPUT_DIRECTORY:
+# Path to the Doxygen output directory (where the resulting doc is stored).
+# Note: should be the same as your doxyfile's OUTPUT_DIRECTORY
+# If ON, allows the output directory to be erased when some advanced output
+# file have been produced (HTML Help, or TAR archive for example).
+# Example:
+# OUTPUT_DIRECTORY=$DOXTEMP/doc
+# ALLOW_ERASE_OUTPUT_DIRECTORY=ON
+#
+export OUTPUT_DIRECTORY="$DOXTEMP/doc"
+export ALLOW_ERASE_OUTPUT_DIRECTORY=ON
+
+# COMPILE_HTML_HELP RESULTING_HTML_HELP_FILE:
+# Compile the CHM (Compressed HTML) HTML Help file, name of the resulting
+# file. If set to ON and name is non-empty these options will actually
+# trigger the HTML-Help compiler to create the CHM. The resulting
+# file (usually index.chm) will be renamed to this name.
+# Note: if ON, the whole $OUTPUT_DIRECTORY will be erased at the end of
+# this script, since this file is considered to be one of the
+# advanced final output, unless ALLOW_ERASE_OUTPUT_DIRECTORY is OFF
+# Note: your doxyfile should be configured to enable HTML Help creation
+# (using GENERATE_HTML = YES, GENERATE_HTMLHELP = YES)
+# Example:
+# COMPILE_HTML_HELP=ON
+# COMPILE_HTML_HELP=@DOCUMENTATION_HTML_HELP@
+# RESULTING_HTML_HELP_FILE=$DOXTEMP/vtk4.chm
+#
+export COMPILE_HTML_HELP=@DOCUMENTATION_HTML_HELP@
+export RESULTING_HTML_HELP_FILE="$DOXTEMP/$PROJECT_NAME.chm"
+
+# CREATE_HTML_TARZ_ARCHIVE RESULTING_HTML_TARZ_ARCHIVE_FILE:
+# Create a compressed (gzip) tar archive of the html directory (located
+# under the OUTPUT_DIRECTORY), and name of the resulting archive file.
+# Note: your doxyfile should be configured to enable HTML creation
+# (using GENERATE_HTML = YES)
+# Example:
+# CREATE_HTML_TARZ_ARCHIVE=ON
+# CREATE_HTML_TARZ_ARCHIVE=@DOCUMENTATION_HTML_TARZ@
+# RESULTING_HTML_TARZ_ARCHIVE_FILE=$DOXTEMP/vtk4-html.tar.gz
+# RESULTING_HTML_TARZ_ARCHIVE_FILE=$DOXTEMP/$PROJECT_NAME-html.tar.gz
+#
+export CREATE_HTML_TARZ_ARCHIVE=@DOCUMENTATION_HTML_TARZ@
+export RESULTING_HTML_TARZ_ARCHIVE_FILE="$DOXTEMP/$PROJECT_NAME-html.tar.gz"
+
+# ----------------------------------------------------------------------------
+# Build the contributors list.
+
+if test "x@VTK_SOURCE_DIR@" != "x" ; then
+ if test "x$PERL_PROG" != "xNOTFOUND" ; then
+ $PERL_PROG "$PATH_TO_VTK_DOX_SCRIPTS/doc_contributors.pl" \
+ --authors "$SOURCE_DIR/Utilities/Doxygen/authors.txt" \
+ --cachedir "$DOXTEMP/cache" \
+ --class_group '^(cm[A-Z0-9][A-Za-z0-9]+)\.(?:c|cpp|cxx|h|fl)$' \
+ --files_in '(?:^hints|dummy|README|^Makefile\.borland|\.(?:c|cmake|cpp|cxx|h|html|in|java|fl|pl|py|tcl|txt))$' \
+ --files_out '(?:^ChangeLog\.txt)$' \
+ --gnuplot_file "$DOXTEMP/contrib/history.plt" \
+ --history_img "|lines|$DOXTEMP/contrib/history.png" \
+ --history_img "365|lines|$DOXTEMP/contrib/history2y.png" \
+ --history_img "180|linespoints|$DOXTEMP/contrib/history6m.png" \
+ --history_dir "$DOXTEMP/contrib" \
+ --history_max_nb 10 \
+ --lines_add 1.0 \
+ --lines_rem 0.5 \
+ --massive 50 \
+ --max_class_nb 10 \
+ --max_file_nb 5 \
+ --min_class 0.02 \
+ --min_file 0.01 \
+ --min_contrib 0.05 \
+ --min_gcontrib 0.0001 \
+ --store "doc_""$PROJECT_NAME""_contributors.dox" \
+ --relativeto "$SOURCE_DIR/$REL_PATH_TO_TOP" \
+ --to "$INTERMEDIATE_DOX_DIR" \
+ "$SOURCE_DIR/$REL_PATH_TO_TOP"
+ fi
+
+ if test "x$GNUPLOT_PROG" != "xNOTFOUND" ; then
+ $GNUPLOT_PROG "$DOXTEMP/contrib/history.plt"
+ fi
+fi
+
+# ----------------------------------------------------------------------------
+# Create the Doxygen doc.
+
+if test "x$DOXYGEN_PROG" != "xNOTFOUND" ; then
+
+ if test "x$RM_PROG" != "xNOTFOUND" ; then
+ $RM_PROG -fr "$OUTPUT_DIRECTORY"
+ fi
+
+ "$DOXYGEN_PROG" "$DOXYFILE"
+
+ # yes, a second time, to get the contrib, I don't know why
+ "$DOXYGEN_PROG" "$DOXYFILE"
+fi
+
+# ----------------------------------------------------------------------------
+# Clean the HTML pages to remove the path to the intermediate Doxygen dir.
+
+if test "x@VTK_SOURCE_DIR@" != "x" ; then
+ if test "x$PERL_PROG" != "xNOTFOUND" ; then
+ $PERL_PROG "$PATH_TO_VTK_DOX_SCRIPTS/doc_rmpath.pl" \
+ --verbose \
+ --to "$INTERMEDIATE_DOX_DIR" \
+ --html "$OUTPUT_DIRECTORY/html"
+ fi
+fi
+
+# ----------------------------------------------------------------------------
+# Create the CHM HTML HELP doc.
+
+if test "x$COMPILE_HTML_HELP" == "xON" ; then
+ if test "x$RESULTING_HTML_HELP_FILE" != "x" ; then
+ cd $OUTPUT_DIRECTORY/html
+ if test "x$HHC_PROG" != "xNOTFOUND" ; then
+ "$HHC_PROG" index.hhp
+ if test "x$MV_PROG" != "xNOTFOUND" ; then
+ $MV_PROG -f index.chm "$RESULTING_HTML_HELP_FILE"
+ fi
+ fi
+ fi
+fi
+
+# ----------------------------------------------------------------------------
+# Create the compressed tar archive.
+
+if test "x$CREATE_HTML_TARZ_ARCHIVE" == "xON" ; then
+ if test "x$RESULTING_HTML_TARZ_ARCHIVE_FILE" != "x" ; then
+ cd "$OUTPUT_DIRECTORY"
+ if test "x$TAR_PROG" != "xNOTFOUND" ; then
+ if test "x$RM_PROG" != "xNOTFOUND" ; then
+ $RM_PROG -f html.tar
+ fi
+ $TAR_PROG -cf html.tar html
+ if test "x$GZIP_PROG" != "xNOTFOUND" ; then
+ if test "x$RM_PROG" != "xNOTFOUND" ; then
+ $RM_PROG -f html.tar.gz
+ fi
+ $GZIP_PROG html.tar
+ $MV_PROG -f html.tar.gz "$RESULTING_HTML_TARZ_ARCHIVE_FILE"
+ fi
+ fi
+ fi
+fi
+
+# ----------------------------------------------------------------------------
+# Clean-up.
+
+if test "x$RM_PROG" != "xNOTFOUND" ; then
+ $RM_PROG -fr "$INTERMEDIATE_DOX_DIR"
+
+ if test "x$DOWNLOAD_VTK_TAGFILE" == "xON" ; then
+ if test "x$VTK_TAGFILE" != "x" ; then
+ $RM_PROG -f "$VTK_TAGFILE_DEST_DIR/$VTK_TAGFILE"
+ fi
+ fi
+
+ if test "x$COMPILE_HTML_HELP" == "xON" ; then
+ if test "x$RESULTING_HTML_HELP_FILE" != "x" ; then
+ if test "x$ALLOW_ERASE_OUTPUT_DIRECTORY" == "xON" ; then
+ $RM_PROG -fr "$OUTPUT_DIRECTORY"
+ fi
+ fi
+ fi
+fi
diff --git a/Utilities/Doxygen/doxyfile.in b/Utilities/Doxygen/doxyfile.in
new file mode 100644
index 0000000000..2c131f50b2
--- /dev/null
+++ b/Utilities/Doxygen/doxyfile.in
@@ -0,0 +1,84 @@
+# -------------------------------------------------------------------------
+# doxyfile for CMake
+# modified by S. Barre (Time-stamp: <2002-02-13 18:24:35 barre>
+# -------------------------------------------------------------------------
+
+PROJECT_NAME = CMake
+
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH = \
+ "@CMake_SOURCE_DIR@/Source/" \
+ "@CMake_BINARY_DIR@/Source/"
+
+WARN_IF_UNDOCUMENTED = NO
+
+GENERATE_TREEVIEW = NO
+GENERATE_TODOLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_HTML = YES
+GENERATE_HTMLHELP = YES
+GENERATE_LATEX = NO
+GENERATE_MAN = NO
+GENERATE_RTF = NO
+
+HAVE_DOT = YES
+#HAVE_DOT = NO
+DOT_PATH = "@DOT_PATH@"
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+TEMPLATE_RELATIONS = YES
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CLASS_DIAGRAMS = YES
+GENERATE_LEGEND = YES
+GRAPHICAL_HIERARCHY = YES
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION = YES
+
+ALLEXTERNALS = NO
+
+IMAGE_PATH = "@CMake_BINARY_DIR@/Utilities/Doxygen/contrib"
+
+OUTPUT_DIRECTORY = "@CMake_BINARY_DIR@/Utilities/Doxygen/doc"
+
+INPUT = \
+ "@CMake_SOURCE_DIR@/Source" \
+ "@CMake_SOURCE_DIR@/Source/CPack" \
+ "@CMake_SOURCE_DIR@/Source/CPack/IFW" \
+ "@CMake_SOURCE_DIR@/Source/CTest" \
+ "@CMake_SOURCE_DIR@/Source/CursesDialog" \
+ "@CMake_SOURCE_DIR@/Source/MFCDialog" \
+ "@CMake_BINARY_DIR@/Source/kwsys" \
+ "@CMake_BINARY_DIR@/Source/cmsys" \
+ "@CMake_BINARY_DIR@/Utilities/Doxygen/dox/doc_CMake_contributors.dox" \
+
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = NO
+EXTRACT_STATIC = YES
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = YES
+ALWAYS_DETAILED_SEC = NO
+SOURCE_BROWSER = YES
+INLINE_SOURCES = NO
+CASE_SENSE_NAMES = YES
+VERBATIM_HEADERS = NO
+SHOW_INCLUDE_FILES = YES
+JAVADOC_AUTOBRIEF = YES
+SORT_MEMBER_DOCS = NO
+DISTRIBUTE_GROUP_DOC = YES
+TAB_SIZE = 3
+
+FILE_PATTERNS = *.h *.hxx *.cxx
+RECURSIVE = NO
+EXCLUDE_PATTERNS =
+
+HTML_ALIGN_MEMBERS = YES
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 3
+IGNORE_PREFIX = cm
+
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = YES
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+EXPAND_ONLY_PREDEF = YES
diff --git a/Utilities/Git/commit-msg b/Utilities/Git/commit-msg
new file mode 100755
index 0000000000..9a5d1c1b39
--- /dev/null
+++ b/Utilities/Git/commit-msg
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+#=============================================================================
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2011 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.
+#=============================================================================
+
+die() {
+ echo 'commit-msg hook failure' 1>&2
+ echo '-----------------------' 1>&2
+ echo '' 1>&2
+ echo "$@" 1>&2
+ exit 1
+}
+
+# This is a placeholder for future commit-msg checks.
+exit 0
diff --git a/Utilities/Git/pre-commit b/Utilities/Git/pre-commit
new file mode 100755
index 0000000000..a35d111025
--- /dev/null
+++ b/Utilities/Git/pre-commit
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+#=============================================================================
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2011 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.
+#=============================================================================
+
+die() {
+ echo 'pre-commit hook failure' 1>&2
+ echo '-----------------------' 1>&2
+ echo '' 1>&2
+ echo "$@" 1>&2
+ exit 1
+}
+
+#-------------------------------------------------------------------------------
+line_too_long=80
+bad=$(regex=".{$line_too_long}" &&
+git diff-index --cached HEAD --name-only --diff-filter=AM \
+ --pickaxe-regex -S"$regex" -- 'Source/*.h' 'Source/*.cxx' |
+while read file; do
+ lines_too_long=$(git diff-index -p --cached HEAD \
+ --pickaxe-regex -S"$regex" -- "$file")
+ if echo "$lines_too_long" | egrep -q '^\+'"$regex"; then
+ echo "$lines_too_long"
+ fi
+done)
+test -z "$bad" ||
+die 'The following changes add lines too long for our C++ style:
+
+'"$bad"'
+
+Use lines strictly less than '"$line_too_long"' characters in C++ code.'
+
+#-------------------------------------------------------------------------------
+if test -z "$HOOKS_ALLOW_KWSYS"; then
+ # Disallow changes to KWSys
+ files=$(git diff-index --name-only --cached HEAD -- Source/kwsys) &&
+ if test -n "$files"; then
+ die 'Changes to KWSys files
+
+'"$(echo "$files" | sed 's/^/ /')"'
+
+should not be made directly in CMake. KWSys is kept in its own Git
+repository and shared by several projects. Please visit
+
+ http://public.kitware.com/Wiki/KWSys/Git
+
+to contribute changes directly to KWSys. Run
+
+ git reset HEAD -- Source/kwsys
+
+to unstage these changes. Alternatively, set environment variable
+
+ HOOKS_ALLOW_KWSYS=1
+
+to disable this check and commit the changes locally.'
+ fi
+fi
diff --git a/Utilities/Git/prepare-commit-msg b/Utilities/Git/prepare-commit-msg
new file mode 100755
index 0000000000..1517bb2db6
--- /dev/null
+++ b/Utilities/Git/prepare-commit-msg
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+#=============================================================================
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2011 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.
+#=============================================================================
+
+# This is a placeholder for future prepare-commit-msg hooks.
+exit 0
diff --git a/Utilities/GitSetup/.gitattributes b/Utilities/GitSetup/.gitattributes
new file mode 100644
index 0000000000..facbbb21cc
--- /dev/null
+++ b/Utilities/GitSetup/.gitattributes
@@ -0,0 +1,7 @@
+.git* export-ignore
+
+# Exclude from source archives files specific to Git work tree.
+* export-ignore
+
+tips eol=lf whitespace=indent-with-non-tab
+setup-* eol=lf whitespace=indent-with-non-tab
diff --git a/Utilities/GitSetup/LICENSE b/Utilities/GitSetup/LICENSE
new file mode 100644
index 0000000000..d645695673
--- /dev/null
+++ b/Utilities/GitSetup/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/Utilities/GitSetup/NOTICE b/Utilities/GitSetup/NOTICE
new file mode 100644
index 0000000000..0d32c02eb6
--- /dev/null
+++ b/Utilities/GitSetup/NOTICE
@@ -0,0 +1,5 @@
+Kitware Local Git Setup Scripts
+Copyright 2010-2012 Kitware, Inc.
+
+This product includes software developed at Kitware, Inc.
+(http://www.kitware.com/).
diff --git a/Utilities/GitSetup/README b/Utilities/GitSetup/README
new file mode 100644
index 0000000000..cf468fb68b
--- /dev/null
+++ b/Utilities/GitSetup/README
@@ -0,0 +1,80 @@
+Kitware Local Git Setup Scripts
+
+
+Introduction
+------------
+
+This is a collection of local Git development setup scripts meant for
+inclusion in project source trees to aid their development workflow.
+Project-specific information needed by the scripts may be configured
+in a "config" file added next to them in the project.
+
+
+Import
+------
+
+A project may import these scripts into their source tree by
+initializing a subtree merge. Bring up a Git prompt and set the
+current working directory inside a clone of the target project.
+Fetch the "setup" branch from the GitSetup repository:
+
+ $ git fetch ../GitSetup setup:setup
+
+Prepare to merge the branch but place the content in a subdirectory.
+Any prefix (with trailing '/') may be chosen so long as it is used
+consistently within a project through the rest of these instructions:
+
+ $ git merge -s ours --no-commit setup
+ $ git read-tree -u --prefix=Utilities/GitSetup/ setup
+
+Commit the merge with an informative message:
+
+ $ git commit
+ ------------------------------------------------------------------------
+ Merge branch 'setup'
+
+ Add Utilities/GitSetup/ directory using subtree merge from
+ the general GitSetup repository "setup" branch.
+ ------------------------------------------------------------------------
+
+
+Configuration
+-------------
+
+Read the "Project configuration instructions" comment in each script.
+Add a "config" file next to the scripts with desired configuration
+(optionally copy and modify "config.sample"). For example, to
+configure the "setup-hooks" script:
+
+ $ git config -f Utilities/GitSetup/config hooks.url "$url"
+
+where "$url" is the project repository publishing the "hooks" branch.
+When finished, add and commit the configuration file:
+
+ $ git add Utilities/GitSetup/config
+ $ git commit
+
+
+Update
+------
+
+A project may update these scripts from the GitSetup repository.
+Bring up a Git prompt and set the current working directory inside a
+clone of the target project. Fetch the "setup" branch from the
+GitSetup repository:
+
+ $ git fetch ../GitSetup setup:setup
+
+Merge the "setup" branch into the subtree:
+
+ $ git merge -X subtree=Utilities/GitSetup setup
+
+where "Utilities/GitSetup" is the same prefix used during the import
+setup, but without a trailing '/'.
+
+
+License
+-------
+
+Distributed under the Apache License 2.0.
+See LICENSE and NOTICE for details.
diff --git a/Utilities/GitSetup/config b/Utilities/GitSetup/config
new file mode 100644
index 0000000000..b7d54235c7
--- /dev/null
+++ b/Utilities/GitSetup/config
@@ -0,0 +1,9 @@
+[hooks]
+ url = http://cmake.org/cmake.git
+[ssh]
+ host = cmake.org
+ key = id_git_cmake
+ request-url = https://www.kitware.com/Admin/SendPassword.cgi
+[stage]
+ url = git://cmake.org/stage/cmake.git
+ pushurl = git@cmake.org:stage/cmake.git
diff --git a/Utilities/GitSetup/config.sample b/Utilities/GitSetup/config.sample
new file mode 100644
index 0000000000..bba2382c3c
--- /dev/null
+++ b/Utilities/GitSetup/config.sample
@@ -0,0 +1,22 @@
+# Kitware Local Git Setup Scripts - Sample Project Configuration
+#
+# Copy to "config" and edit as necessary.
+
+[hooks]
+ url = http://public.kitware.com/GitSetup.git
+ #branch = hooks
+
+[ssh]
+ host = public.kitware.com
+ key = id_git_public
+ request-url = https://www.kitware.com/Admin/SendPassword.cgi
+
+[stage]
+ #url = git://public.kitware.com/stage/Project.git
+ #pushurl = git@public.kitware.com:stage/Project.git
+
+[gerrit]
+ #project = Project
+ site = http://review.source.kitware.com
+ # pushurl placeholder "$username" is literal
+ pushurl = $username@review.source.kitware.com:Project
diff --git a/Utilities/GitSetup/setup-gerrit b/Utilities/GitSetup/setup-gerrit
new file mode 100755
index 0000000000..9e8fa62375
--- /dev/null
+++ b/Utilities/GitSetup/setup-gerrit
@@ -0,0 +1,142 @@
+#!/usr/bin/env bash
+#=============================================================================
+# Copyright 2010-2012 Kitware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#=============================================================================
+
+# Run this script to set up the local Git repository to push to
+# a Gerrit Code Review instance for this project.
+
+# Project configuration instructions:
+#
+# - Run a Gerrit Code Review server
+#
+# - Populate adjacent "config" file with:
+# gerrit.site = Top Gerrit URL (not project-specific)
+# gerrit.project = Name of project in Gerrit
+# gerrit.pushurl = Review site push URL with "$username" placeholder
+# gerrit.remote = Gerrit remote name, if not "gerrit"
+# gerrit.url = Gerrit project URL, if not "$site/p/$project"
+
+die() {
+ echo 1>&2 "$@" ; exit 1
+}
+
+# Make sure we are inside the repository.
+cd "${BASH_SOURCE%/*}" &&
+
+# Load the project configuration.
+site=$(git config -f config --get gerrit.site) &&
+project=$(git config -f config --get gerrit.project) &&
+pushurl_=$(git config -f config --get gerrit.pushurl) &&
+remote=$(git config -f config --get gerrit.remote ||
+ echo "gerrit") &&
+fetchurl=$(git config -f config --get gerrit.url ||
+ echo "$site/p/$project") ||
+die 'This project is not configured to use Gerrit.'
+
+# Get current gerrit push URL.
+pushurl=$(git config --get remote."$remote".pushurl ||
+ git config --get remote."$remote".url || echo '') &&
+
+# Tell user about current configuration.
+if test -n "$pushurl"; then
+ echo 'Remote "'"$remote"'" is currently configured to push to
+
+ '"$pushurl"'
+' &&
+ read -ep 'Reconfigure Gerrit? [y/N]: ' ans &&
+ if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then
+ setup=1
+ else
+ setup=''
+ fi
+else
+ echo 'Remote "'"$remote"'" is not yet configured.
+
+'"$project"' changes must be pushed to our Gerrit Code Review site:
+
+ '"$fetchurl"'
+
+Register a Gerrit account and select a username (used below).
+You will need an OpenID:
+
+ http://openid.net/get-an-openid/
+' &&
+ read -ep 'Configure Gerrit? [Y/n]: ' ans &&
+ if [ "$ans" == "n" ] || [ "$ans" == "N" ]; then
+ exit 0
+ else
+ setup=1
+ fi
+fi &&
+
+# Perform setup if necessary.
+if test -n "$setup"; then
+ echo 'Sign-in to Gerrit to get/set your username at
+
+ '"$site"'/#/settings
+
+Add your SSH public keys at
+
+ '"$site"'/#/settings/ssh-keys
+' &&
+ read -ep "Gerrit username? [$USER]: " gu &&
+ if test -z "$gu"; then
+ gu="$USER"
+ fi &&
+ if test -z "$pushurl"; then
+ git remote add "$remote" "$fetchurl"
+ else
+ git config remote."$remote".url "$fetchurl"
+ fi &&
+ pushurl="${pushurl_/\$username/$gu}" &&
+ git config remote."$remote".pushurl "$pushurl" &&
+ echo 'Remote "'"$remote"'" is now configured to push to
+
+ '"$pushurl"'
+'
+fi &&
+
+# Optionally test Gerrit access.
+if test -n "$pushurl"; then
+ read -ep 'Test access to Gerrit (SSH)? [y/N]: ' ans &&
+ if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then
+ echo -n 'Testing Gerrit access by SSH...'
+ if git ls-remote --heads "$pushurl" >/dev/null; then
+ echo 'passed.'
+ else
+ echo 'failed.' &&
+ die 'Could not access Gerrit. Add your SSH public keys at
+
+ '"$site"'/#/settings/ssh-keys
+'
+ fi
+ fi
+fi &&
+
+# Set up GerritId hook.
+hook=$(git config --get hooks.GerritId || echo '') &&
+if test -z "$hook"; then
+ echo '
+Enabling GerritId hook to add a "Change-Id" footer to commit
+messages for interaction with Gerrit. Run
+
+ git config hooks.GerritId false
+
+to disable this feature (but you will be on your own).' &&
+ git config hooks.GerritId true
+else
+ echo 'GerritId hook already configured to "'"$hook"'".'
+fi
diff --git a/Utilities/GitSetup/setup-hooks b/Utilities/GitSetup/setup-hooks
new file mode 100755
index 0000000000..c07985ae56
--- /dev/null
+++ b/Utilities/GitSetup/setup-hooks
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+#=============================================================================
+# Copyright 2010-2012 Kitware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#=============================================================================
+
+# Run this script to set up local Git hooks for this project.
+
+# Project configuration instructions:
+#
+# - Publish a "hooks" branch in the project repository such that
+# clones will have "refs/remotes/origin/hooks".
+#
+# - Populate adjacent "config" file with:
+# hooks.url = Repository URL publishing "hooks" branch
+# hooks.branch = Repository branch instead of "hooks"
+
+egrep-q() {
+ egrep "$@" >/dev/null 2>/dev/null
+}
+
+die() {
+ echo 1>&2 "$@" ; exit 1
+}
+
+# Make sure we are inside the repository.
+cd "${BASH_SOURCE%/*}" &&
+
+# Select a hooks branch.
+if url=$(git config --get hooks.url); then
+ # Fetch hooks from locally configured repository.
+ branch=$(git config hooks.branch || echo hooks)
+elif git for-each-ref refs/remotes/origin/hooks 2>/dev/null |
+ egrep-q 'refs/remotes/origin/hooks$'; then
+ # Use hooks cloned from origin.
+ url=.. && branch=remotes/origin/hooks
+elif url=$(git config -f config --get hooks.url); then
+ # Fetch hooks from project-configured repository.
+ branch=$(git config -f config hooks.branch || echo hooks)
+else
+ die 'This project is not configured to install local hooks.'
+fi &&
+
+# Populate ".git/hooks".
+echo 'Setting up git hooks...' &&
+git_dir=$(git rev-parse --git-dir) &&
+cd "$git_dir/hooks" &&
+if ! test -e .git; then
+ git init -q || die 'Could not run git init for hooks.'
+fi &&
+git fetch -q "$url" "$branch" &&
+git reset -q --hard FETCH_HEAD || die 'Failed to install hooks'
diff --git a/Utilities/GitSetup/setup-ssh b/Utilities/GitSetup/setup-ssh
new file mode 100755
index 0000000000..8920a5bd33
--- /dev/null
+++ b/Utilities/GitSetup/setup-ssh
@@ -0,0 +1,111 @@
+#!/usr/bin/env bash
+#=============================================================================
+# Copyright 2010-2012 Kitware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#=============================================================================
+
+# Run this script to set up ssh push access to the repository host.
+
+# Project configuration instructions:
+#
+# - Populate adjacent "config" file with:
+# ssh.host = Repository host name
+# ssh.user = Username on host, if not "git"
+# ssh.key = Local ssh key name
+# ssh.request-url = Web page URL to request ssh access
+
+egrep-q() {
+ egrep "$@" >/dev/null 2>/dev/null
+}
+
+die() {
+ echo 1>&2 "$@" ; exit 1
+}
+
+# Make sure we are inside the repository.
+cd "${BASH_SOURCE%/*}" &&
+
+# Load the project configuration.
+host=$(git config -f config --get ssh.host) &&
+user=$(git config -f config --get ssh.user || echo git) &&
+key=$(git config -f config --get ssh.key) &&
+request_url=$(git config -f config --get ssh.request-url) ||
+die 'This project is not configured for ssh push access.'
+
+# Check for existing configuration.
+if test -r ~/.ssh/config &&
+ egrep-q 'Host[= ]'"${host//\./\\.}" ~/.ssh/config; then
+ echo 'Host "'"$host"'" is already in ~/.ssh/config' &&
+ setup= &&
+ question='Test'
+else
+ echo 'Host "'"$host"'" not found in ~/.ssh/config' &&
+ setup=1 &&
+ question='Setup and test'
+fi &&
+
+# Ask the user whether to make changes.
+echo '' &&
+read -ep "${question} push access by ssh to $user@$host? [y/N]: " access &&
+if test "$access" != "y" -a "$access" != "Y"; then
+ exit 0
+fi &&
+
+# Setup host configuration if necessary.
+if test -n "$setup"; then
+ if ! test -d ~/.ssh; then
+ mkdir -p ~/.ssh &&
+ chmod 700 ~/.ssh
+ fi &&
+ if ! test -f ~/.ssh/config; then
+ touch ~/.ssh/config &&
+ chmod 600 ~/.ssh/config
+ fi &&
+ ssh_config='Host='"$host"'
+ IdentityFile ~/.ssh/'"$key" &&
+ echo "Adding to ~/.ssh/config:
+
+$ssh_config
+" &&
+ echo "$ssh_config" >> ~/.ssh/config &&
+ if ! test -e ~/.ssh/"$key"; then
+ if test -f ~/.ssh/id_rsa; then
+ # Take care of the common case.
+ ln -s id_rsa ~/.ssh/"$key"
+ echo '
+Assuming ~/.ssh/id_rsa is the private key corresponding to the public key for
+
+ '"$user@$host"'
+
+If this is incorrect place private key at "~/.ssh/'"$key"'".'
+ else
+ echo '
+Place the private key corresponding to the public key registered for
+
+ '"$user@$host"'
+
+at "~/.ssh/'"$key"'".'
+ fi
+ read -e -n 1 -p 'Press any key to continue...'
+ fi
+fi || exit 1
+
+# Test access configuration.
+echo 'Testing ssh push access to "'"$user@$host"'"...' &&
+if ! ssh "$user@$host" info; then
+ die 'No ssh push access to "'"$user@$host"'". You may need to request access at
+
+ '"$request_url"'
+'
+fi
diff --git a/Utilities/GitSetup/setup-stage b/Utilities/GitSetup/setup-stage
new file mode 100755
index 0000000000..323e47aea6
--- /dev/null
+++ b/Utilities/GitSetup/setup-stage
@@ -0,0 +1,79 @@
+#!/usr/bin/env bash
+#=============================================================================
+# Copyright 2010-2012 Kitware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#=============================================================================
+
+# Run this script to set up the topic stage for pushing changes.
+
+# Project configuration instructions:
+#
+# - Run a Topic Stage repository next to the main project repository.
+#
+# - Populate adjacent "config" file with:
+# stage.url = Topic Stage repository URL
+# stage.pushurl = Topic Stage push URL if not "$url"
+
+egrep-q() {
+ egrep "$@" >/dev/null 2>/dev/null
+}
+
+die() {
+ echo 1>&2 "$@" ; exit 1
+}
+
+# Make sure we are inside the repository.
+cd "${BASH_SOURCE%/*}" &&
+
+# Load the project configuration.
+fetchurl=$(git config -f config --get stage.url) &&
+pushurl_=$(git config -f config --get stage.pushurl || echo '') &&
+remote=$(git config -f config --get stage.remote || echo 'stage') ||
+die 'This project is not configured to use a topic stage.'
+
+# Get current stage push URL.
+pushurl=$(git config --get remote."$remote".pushurl ||
+ git config --get remote."$remote".url || echo '') &&
+
+# Tell user about current configuration.
+if test -n "$pushurl"; then
+ echo 'Remote "'"$remote"'" is currently configured to push to
+
+ '"$pushurl"'
+' &&
+ read -ep 'Reconfigure Topic Stage? [y/N]: ' ans &&
+ if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then
+ setup=1
+ else
+ setup=''
+ fi
+else
+ setup=1
+fi
+
+# Perform setup if necessary.
+if test -n "$setup"; then
+ echo 'Setting up the topic stage...' &&
+ if test -z "$pushurl"; then
+ git remote add "$remote" "$fetchurl"
+ else
+ git config remote."$remote".url "$fetchurl"
+ fi &&
+ pushurl="${pushurl_}" &&
+ git config remote."$remote".pushurl "$pushurl" &&
+ echo 'Remote "'"$remote"'" is now configured to push to
+
+ '"$pushurl"'
+'
+fi || die 'Could not configure the topic stage remote.'
diff --git a/Utilities/GitSetup/setup-user b/Utilities/GitSetup/setup-user
new file mode 100755
index 0000000000..1af439c45e
--- /dev/null
+++ b/Utilities/GitSetup/setup-user
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+#=============================================================================
+# Copyright 2010-2012 Kitware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#=============================================================================
+
+# Run this script to configure Git user info in this repository.
+
+# Project configuration instructions: NONE
+
+for (( ; ; )); do
+ user_name=$(git config user.name || echo '') &&
+ user_email=$(git config user.email || echo '') &&
+ if test -n "$user_name" -a -n "$user_email"; then
+ echo 'Your commits will record as Author:
+
+ '"$user_name <$user_email>"'
+' &&
+ read -ep 'Is the author name and email address above correct? [Y/n] ' correct &&
+ if test "$correct" != "n" -a "$correct" != "N"; then
+ break
+ fi
+ fi &&
+ read -ep 'Enter your full name e.g. "John Doe": ' name &&
+ read -ep 'Enter your email address e.g. "john@gmail.com": ' email &&
+ git config user.name "$name" &&
+ git config user.email "$email"
+done
diff --git a/Utilities/GitSetup/tips b/Utilities/GitSetup/tips
new file mode 100755
index 0000000000..784e1ed890
--- /dev/null
+++ b/Utilities/GitSetup/tips
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+#=============================================================================
+# Copyright 2010-2012 Kitware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#=============================================================================
+
+# This script makes optional suggestions for working with Git.
+
+# Project configuration instructions: NONE
+
+egrep-q() {
+ egrep "$@" >/dev/null 2>/dev/null
+}
+
+# Suggest color configuration.
+if test -z "$(git config --get color.ui)"; then
+ echo '
+One may enable color output from Git commands with
+
+ git config --global color.ui auto
+'
+fi
+
+# Suggest bash completion.
+if ! bash -i -c 'echo $PS1' | egrep-q '__git_ps1'; then
+ echo '
+A dynamic, informative Git shell prompt can be obtained by sourcing
+the git bash-completion script in your "~/.bashrc". Set the PS1
+environmental variable as suggested in the comments at the top of the
+bash-completion script. You may need to install the bash-completion
+package from your distribution to obtain it.
+'
+fi
+
+# Suggest merge tool.
+if test -z "$(git config --get merge.tool)"; then
+ echo '
+One may configure Git to load a merge tool with
+
+ git config merge.tool <toolname>
+
+See "git help mergetool" for more information.
+'
+fi
diff --git a/ABI.h.in b/Utilities/KWIML/ABI.h.in
index 21c9139c0a..21c9139c0a 100644
--- a/ABI.h.in
+++ b/Utilities/KWIML/ABI.h.in
diff --git a/Utilities/KWIML/CMakeLists.txt b/Utilities/KWIML/CMakeLists.txt
new file mode 100644
index 0000000000..62b6fffb76
--- /dev/null
+++ b/Utilities/KWIML/CMakeLists.txt
@@ -0,0 +1,79 @@
+#=============================================================================
+# 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.
+#=============================================================================
+
+# 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)
+ project(KWIML)
+ include(CTest)
+ mark_as_advanced(BUILD_TESTING)
+endif()
+
+#-----------------------------------------------------------------------------
+get_property(KWIML_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
+foreach(lang ${KWIML_LANGUAGES})
+ set(KWIML_LANGUAGE_${lang} 1)
+endforeach()
+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}")
+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)
+ add_subdirectory(test)
+endif()
diff --git a/Utilities/KWIML/Copyright.txt b/Utilities/KWIML/Copyright.txt
new file mode 100644
index 0000000000..c1e5ebc3fa
--- /dev/null
+++ b/Utilities/KWIML/Copyright.txt
@@ -0,0 +1,30 @@
+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.
diff --git a/INT.h.in b/Utilities/KWIML/INT.h.in
index d2eda63879..d2eda63879 100644
--- a/INT.h.in
+++ b/Utilities/KWIML/INT.h.in
diff --git a/README.txt b/Utilities/KWIML/README.txt
index 6bdf859d98..6bdf859d98 100644
--- a/README.txt
+++ b/Utilities/KWIML/README.txt
diff --git a/test/CMakeLists.txt b/Utilities/KWIML/test/CMakeLists.txt
index a16b5cddad..a16b5cddad 100644
--- a/test/CMakeLists.txt
+++ b/Utilities/KWIML/test/CMakeLists.txt
diff --git a/test/test.c b/Utilities/KWIML/test/test.c
index 131c81f925..131c81f925 100644
--- a/test/test.c
+++ b/Utilities/KWIML/test/test.c
diff --git a/test/test.cxx b/Utilities/KWIML/test/test.cxx
index bf614218a2..bf614218a2 100644
--- a/test/test.cxx
+++ b/Utilities/KWIML/test/test.cxx
diff --git a/test/test.h b/Utilities/KWIML/test/test.h
index b87a0e7e95..b87a0e7e95 100644
--- a/test/test.h
+++ b/Utilities/KWIML/test/test.h
diff --git a/test/test_ABI_C.c b/Utilities/KWIML/test/test_ABI_C.c
index 3ca4ad3903..3ca4ad3903 100644
--- a/test/test_ABI_C.c
+++ b/Utilities/KWIML/test/test_ABI_C.c
diff --git a/test/test_ABI_CXX.cxx b/Utilities/KWIML/test/test_ABI_CXX.cxx
index 7ede20e09f..7ede20e09f 100644
--- a/test/test_ABI_CXX.cxx
+++ b/Utilities/KWIML/test/test_ABI_CXX.cxx
diff --git a/test/test_ABI_endian.h.in b/Utilities/KWIML/test/test_ABI_endian.h.in
index 992baeaebe..992baeaebe 100644
--- a/test/test_ABI_endian.h.in
+++ b/Utilities/KWIML/test/test_ABI_endian.h.in
diff --git a/test/test_INT_C.c b/Utilities/KWIML/test/test_INT_C.c
index 5513a0bd8f..5513a0bd8f 100644
--- a/test/test_INT_C.c
+++ b/Utilities/KWIML/test/test_INT_C.c
diff --git a/test/test_INT_CXX.cxx b/Utilities/KWIML/test/test_INT_CXX.cxx
index 9f74e96802..9f74e96802 100644
--- a/test/test_INT_CXX.cxx
+++ b/Utilities/KWIML/test/test_INT_CXX.cxx
diff --git a/test/test_INT_format.h.in b/Utilities/KWIML/test/test_INT_format.h.in
index 71b443d6ec..71b443d6ec 100644
--- a/test/test_INT_format.h.in
+++ b/Utilities/KWIML/test/test_INT_format.h.in
diff --git a/test/test_include_C.c b/Utilities/KWIML/test/test_include_C.c
index fb3e4cf7fe..fb3e4cf7fe 100644
--- a/test/test_include_C.c
+++ b/Utilities/KWIML/test/test_include_C.c
diff --git a/test/test_include_CXX.cxx b/Utilities/KWIML/test/test_include_CXX.cxx
index 111311a84e..111311a84e 100644
--- a/test/test_include_CXX.cxx
+++ b/Utilities/KWIML/test/test_include_CXX.cxx
diff --git a/Utilities/KWStyle/CMake.kws.xml.in b/Utilities/KWStyle/CMake.kws.xml.in
new file mode 100644
index 0000000000..c2b442940f
--- /dev/null
+++ b/Utilities/KWStyle/CMake.kws.xml.in
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<Description>
+<LineLength>79</LineLength>
+<!--
+<Header>"@CMake_SOURCE_DIR@/Utilities/KWStyle/Headers",false,true</Header>
+<Functions>
+<regex>[A-Z]</regex>
+<length>100</length>
+</Functions>
+-->
+</Description>
diff --git a/Utilities/KWStyle/CMakeFiles.txt.in b/Utilities/KWStyle/CMakeFiles.txt.in
new file mode 100644
index 0000000000..a95aac655d
--- /dev/null
+++ b/Utilities/KWStyle/CMakeFiles.txt.in
@@ -0,0 +1,15 @@
+"@CMake_SOURCE_DIR@/Source/*.txx"
+"@CMake_SOURCE_DIR@/Source/*.cxx"
+"@CMake_SOURCE_DIR@/Source/*.h*"
+"@CMake_SOURCE_DIR@/Source/CPack/*.txx"
+"@CMake_SOURCE_DIR@/Source/CPack/*.cxx"
+"@CMake_SOURCE_DIR@/Source/CPack/*.h*"
+"@CMake_SOURCE_DIR@/Source/CTest/*.txx"
+"@CMake_SOURCE_DIR@/Source/CTest/*.cxx"
+"@CMake_SOURCE_DIR@/Source/CTest/*.h*"
+"@CMake_SOURCE_DIR@/Source/CurseDialog/*.h*"
+"@CMake_SOURCE_DIR@/Source/CurseDialog/*.cxx"
+"@CMake_SOURCE_DIR@/Source/CurseDialog/*.txx"
+-f (Lexer\.h)
+-f (Lexer\.cxx)
+-f (Parser\.cxx)
diff --git a/Utilities/KWStyle/CMakeLists.txt b/Utilities/KWStyle/CMakeLists.txt
new file mode 100644
index 0000000000..b2c798c0f4
--- /dev/null
+++ b/Utilities/KWStyle/CMakeLists.txt
@@ -0,0 +1,78 @@
+#=============================================================================
+# 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.
+#=============================================================================
+
+#-----------------------------------------------------------------------------
+# CMake uses KWStyle for checking the coding style
+
+# Search for a built-from-source KWStyle under Dashboards/Support on a typical
+# dashboard machines:
+#
+set(home "$ENV{HOME}")
+if(NOT home)
+ string(REPLACE "\\" "/" home "$ENV{USERPROFILE}")
+endif()
+
+find_program(KWSTYLE_EXECUTABLE
+ NAMES KWStyle
+ PATHS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware Inc.\\KWStyle 1.0.0]/bin"
+ "${home}/Dashboards/Support/KWStyle/bin"
+ )
+mark_as_advanced(KWSTYLE_EXECUTABLE)
+
+set(CMAKE_USE_KWSTYLE_DEFAULT OFF)
+if(KWSTYLE_EXECUTABLE)
+ set(CMAKE_USE_KWSTYLE_DEFAULT ON)
+endif()
+
+option(CMAKE_USE_KWSTYLE
+ "Add StyleCheck target and KWStyle test: run KWStyle to check for coding standard violations."
+ ${CMAKE_USE_KWSTYLE_DEFAULT})
+mark_as_advanced(CMAKE_USE_KWSTYLE)
+
+if(CMAKE_USE_KWSTYLE)
+ option(KWSTYLE_USE_VIM_FORMAT "Set KWStyle to generate errors with a VIM-compatible format." OFF)
+ option(KWSTYLE_USE_MSVC_FORMAT "Set KWStyle to generate errors with a VisualStudio-compatible format." OFF)
+ mark_as_advanced(KWSTYLE_USE_VIM_FORMAT)
+ mark_as_advanced(KWSTYLE_USE_MSVC_FORMAT)
+
+ if(KWSTYLE_USE_VIM_FORMAT)
+ set(KWSTYLE_ARGUMENTS -vim ${KWSTYLE_ARGUMENTS})
+ endif()
+
+ if(KWSTYLE_USE_MSVC_FORMAT)
+ set(KWSTYLE_ARGUMENTS -msvc ${KWSTYLE_ARGUMENTS})
+ endif()
+
+ configure_file(${CMake_SOURCE_DIR}/Utilities/KWStyle/CMake.kws.xml.in
+ ${CMake_BINARY_DIR}/CMake.kws.xml)
+ configure_file(${CMake_SOURCE_DIR}/Utilities/KWStyle/CMakeMoreChecks.kws.xml.in
+ ${CMake_BINARY_DIR}/CMakeMoreChecks.kws.xml)
+
+ configure_file(${CMake_SOURCE_DIR}/Utilities/KWStyle/CMakeFiles.txt.in
+ ${CMake_BINARY_DIR}/CMakeKWSFiles.txt)
+
+ add_custom_command(
+ OUTPUT ${CMake_BINARY_DIR}/KWStyleReport.txt
+ COMMAND ${KWSTYLE_EXECUTABLE}
+ ARGS -xml ${CMake_BINARY_DIR}/CMake.kws.xml -o ${CMake_SOURCE_DIR}/Utilities/KWStyle/CMakeOverwrite.txt -v ${KWSTYLE_ARGUMENTS} -D ${CMake_BINARY_DIR}/CMakeKWSFiles.txt
+ COMMENT "Coding Style Checker"
+ )
+
+ add_custom_target(MoreStyleChecks
+ COMMAND ${KWSTYLE_EXECUTABLE}
+ -xml ${CMake_BINARY_DIR}/CMakeMoreChecks.kws.xml -html ${CMake_BINARY_DIR}/html -o ${CMake_SOURCE_DIR}/Utilities/KWStyle/CMakeOverwrite.txt -v ${KWSTYLE_ARGUMENTS} -D ${CMake_BINARY_DIR}/CMakeKWSFiles.txt
+ COMMENT "Coding Style Checker, more checks enabled"
+ )
+
+ add_custom_target(StyleCheck DEPENDS ${CMake_BINARY_DIR}/KWStyleReport.txt)
+endif()
diff --git a/Utilities/KWStyle/CMakeMoreChecks.kws.xml.in b/Utilities/KWStyle/CMakeMoreChecks.kws.xml.in
new file mode 100644
index 0000000000..c48e92f77d
--- /dev/null
+++ b/Utilities/KWStyle/CMakeMoreChecks.kws.xml.in
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<Description>
+ <ErrorThreshold>10</ErrorThreshold>
+ <LineLength>79</LineLength>
+ <Header>"@CMake_SOURCE_DIR@/Utilities/KWStyle/Headers",false,true</Header>
+ <Functions>
+ <regex>^(cm)?[A-Z]</regex>
+ <length>200</length>
+ </Functions>
+ <InternalVariables>
+ <regex>^[A-Z]</regex>
+ <alignment>0</alignment>
+ </InternalVariables>
+ <SemicolonSpace>0</SemicolonSpace>
+ <DeclarationOrder>
+ <public>0</public>
+ <protected>1</protected>
+ <private>2</private>
+ </DeclarationOrder>
+ <Tabs>1</Tabs>
+ <EmptyLines>4</EmptyLines>
+ <StatementPerLine>
+ <maxNumber>1</maxNumber>
+ <checkInline>0</checkInline>
+ </StatementPerLine>
+ <VariablePerLine>
+ <maxNumber>1</maxNumber>
+ </VariablePerLine>
+ <BadCharacters>true</BadCharacters>
+</Description>
diff --git a/Utilities/KWStyle/CMakeOverwrite.txt b/Utilities/KWStyle/CMakeOverwrite.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Utilities/KWStyle/CMakeOverwrite.txt
diff --git a/Utilities/KWStyle/Headers/CMakeHeader.h b/Utilities/KWStyle/Headers/CMakeHeader.h
new file mode 100644
index 0000000000..3d7702e1a7
--- /dev/null
+++ b/Utilities/KWStyle/Headers/CMakeHeader.h
@@ -0,0 +1,11 @@
+/*============================================================================
+ 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.
+============================================================================*/
diff --git a/Utilities/Release/CMakeInstall.bmp b/Utilities/Release/CMakeInstall.bmp
new file mode 100644
index 0000000000..0d4c1a5e71
--- /dev/null
+++ b/Utilities/Release/CMakeInstall.bmp
Binary files differ
diff --git a/Utilities/Release/CMakeLogo.ico b/Utilities/Release/CMakeLogo.ico
new file mode 100644
index 0000000000..e13bb156f4
--- /dev/null
+++ b/Utilities/Release/CMakeLogo.ico
Binary files differ
diff --git a/Utilities/Release/Cygwin/CMakeLists.txt b/Utilities/Release/Cygwin/CMakeLists.txt
new file mode 100644
index 0000000000..73a8220b98
--- /dev/null
+++ b/Utilities/Release/Cygwin/CMakeLists.txt
@@ -0,0 +1,25 @@
+file(GLOB INSTALLED_CURSES /usr/bin/cygncurses-*.dll)
+set(MAX 0)
+foreach(f ${INSTALLED_CURSES})
+ if(NOT "${f}" MATCHES "\\+")
+ string(REGEX REPLACE ".*-([0-9]*).dll" "\\1" NUMBER "${f}")
+ if(NUMBER GREATER MAX)
+ set(MAX ${NUMBER})
+ endif()
+ endif()
+endforeach()
+string(REGEX REPLACE "/usr/bin/" "\\1" NUMBER "${f}")
+set(CMAKE_NCURSES_VERSION "libncurses${MAX}")
+message(STATUS "Using curses version: libncurses${MAX}")
+configure_file("${CMake_SOURCE_DIR}/Utilities/Release/Cygwin/cygwin-setup.hint.in"
+ "${CMake_BINARY_DIR}/setup.hint")
+configure_file("${CMake_SOURCE_DIR}/Utilities/Release/Cygwin/README.cygwin.in"
+ "${CMake_BINARY_DIR}/Docs/${CPACK_PACKAGE_FILE_NAME}-${CPACK_CYGWIN_PATCH_NUMBER}.README")
+install_files(/share/doc/Cygwin FILES
+ ${CMake_BINARY_DIR}/Docs/${CPACK_PACKAGE_FILE_NAME}-${CPACK_CYGWIN_PATCH_NUMBER}.README
+ )
+configure_file("${CMake_SOURCE_DIR}/Utilities/Release/Cygwin/cygwin-package.sh.in"
+ ${CPACK_CYGWIN_BUILD_SCRIPT})
+configure_file("${CMake_SOURCE_DIR}/Utilities/Release/Cygwin/cygwin-patch.diff.in"
+ ${CPACK_CYGWIN_PATCH_FILE})
+
diff --git a/Utilities/Release/Cygwin/README.cygwin.in b/Utilities/Release/Cygwin/README.cygwin.in
new file mode 100644
index 0000000000..6c42a4c20e
--- /dev/null
+++ b/Utilities/Release/Cygwin/README.cygwin.in
@@ -0,0 +1,42 @@
+cmake
+--------------------------------------
+Runtime requirements:
+ cygwin-1.5.21(0.156/4/2) or newer
+
+Build requirements
+ cygwin-1.5.21(0.156/4/2) or newer
+ make
+
+Canonical homepage:
+ http://www.cmake.org
+
+Canonical download:
+ ftp://www.cmake.org/pub/cmake/
+
+------------------------------------
+
+Build instructions:
+ unpack @CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@-src.tar.bz2
+ if you use setup to install this src package, it will be
+ unpacked under /usr/src automatically
+ cd /usr/src
+ ./@CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@.sh all
+
+This will create:
+ /usr/src/@CPACK_PACKAGE_FILE_NAME@.tar.bz2
+ /usr/src/@CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@-src.tar.bz2
+
+-------------------------------------------
+
+Port Notes:
+
+The directory /usr/share/@CPACK_PACKAGE_FILE_NAME@/include is purposely not
+located at /usr/include/@CPACK_PACKAGE_FILE_NAME@ or /usr/include/cmake. The
+files it contains are not meant for inclusion in any C or C++ program.
+They are used for compiling dynamically loadable CMake commands inside
+projects that provide them. CMake will automatically provide the
+proper include path when the files are needed.
+
+------------------
+
+Cygwin port maintained by: CMake Developers <cmake@www.cmake.org>
diff --git a/Utilities/Release/Cygwin/cygwin-package.sh.in b/Utilities/Release/Cygwin/cygwin-package.sh.in
new file mode 100755
index 0000000000..dff27f14db
--- /dev/null
+++ b/Utilities/Release/Cygwin/cygwin-package.sh.in
@@ -0,0 +1,90 @@
+TOP_DIR=`cd \`echo "$0" | sed -n '/\//{s/\/[^\/]*$//;p;}'\`;pwd`
+
+# create build directory
+mkdirs()
+{
+ (
+ mkdir -p "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build"
+ )
+}
+
+# cd into
+# untar source tree and apply patch
+prep()
+{
+ (
+ cd "$TOP_DIR" &&
+ tar xvfj @CPACK_PACKAGE_FILE_NAME@.tar.bz2
+ patch -p0 < "@CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@.patch" &&
+ mkdirs
+ )
+}
+
+conf()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ ../bootstrap --parallel=2
+ )
+}
+
+build()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ make -j2 &&
+ make test
+ )
+}
+
+clean()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ make clean
+ )
+}
+
+pkg()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ ./bin/cpack &&
+ mv @CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@.tar.bz2 "$TOP_DIR"
+ )
+}
+
+spkg()
+{
+ (
+ cd "$TOP_DIR/@CPACK_PACKAGE_FILE_NAME@/.build" &&
+ ./bin/cpack --config CPackSourceConfig.cmake &&
+ mv @CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@-src.tar.bz2 "$TOP_DIR"
+ )
+}
+
+finish()
+{
+ (
+ rm -rf "@CPACK_PACKAGE_FILE_NAME@"
+ )
+}
+
+case $1 in
+ prep) prep ; STATUS=$? ;;
+ mkdirs) mkdirs ; STATUS=$? ;;
+ conf) conf ; STATUS=$? ;;
+ build) build ; STATUS=$? ;;
+ clean) clean ; STATUS=$? ;;
+ package) pkg ; STATUS=$? ;;
+ pkg) pkg ; STATUS=$? ;;
+ src-package) spkg ; STATUS=$? ;;
+ spkg) spkg ; STATUS=$? ;;
+ finish) finish ; STATUS=$? ;;
+ all) (
+ prep && conf && build && pkg && spkg && finish ;
+ STATUS=$?
+ ) ;;
+ *) echo "Error: bad argument (all or one of these: prep mkdirs conf build clean package pkg src-package spkg finish)" ; exit 1 ;;
+esac
+exit ${STATUS}
diff --git a/Utilities/Release/Cygwin/cygwin-patch.diff.in b/Utilities/Release/Cygwin/cygwin-patch.diff.in
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Utilities/Release/Cygwin/cygwin-patch.diff.in
diff --git a/Utilities/Release/Cygwin/cygwin-setup.hint.in b/Utilities/Release/Cygwin/cygwin-setup.hint.in
new file mode 100644
index 0000000000..a2532fc68b
--- /dev/null
+++ b/Utilities/Release/Cygwin/cygwin-setup.hint.in
@@ -0,0 +1,5 @@
+# CMake setup.hint file for cygwin setup.exe program
+category: Devel
+requires: libgcc1 libidn11 @CMAKE_NCURSES_VERSION@ libstdc++6
+sdesc: "A cross platform build manager"
+ldesc: "CMake is a cross platform build manager. It allows you to specify build parameters for C and C++ programs in a cross platform manner. For cygwin Makefiles will be generated. CMake is also capable of generating microsoft project files, nmake, and borland makefiles. CMake can also perform system inspection operations like finding installed libraries and header files."
diff --git a/Utilities/Release/README b/Utilities/Release/README
new file mode 100644
index 0000000000..12eafe18f9
--- /dev/null
+++ b/Utilities/Release/README
@@ -0,0 +1,21 @@
+To create a cmake release, make sure the "release" tag is pointing to the
+expected git commit:
+
+http://cmake.org/gitweb?p=cmake.git;a=shortlog;h=refs/heads/release
+
+Then as kitware@hythloth, using an up-to-date CMake:
+
+ cd ~/CMakeReleases/cmake/Utilities/Release
+ mkdir 283rc1
+ cd 283rc1
+ ~/CMakeReleases/build/bin/cmake -DCMAKE_CREATE_VERSION=release -P ../create-cmake-release.cmake
+ ./create-release.sh
+
+
+create-cmake-release.cmake: script to run to create release sh scripts
+Add or remove machines in create-cmake-release.cmake.
+
+Cygwin -> directory that contains cpack cygwin package files used in
+ CMakeCPack.cmake
+
+machine_release.cmake : config files for each machine
diff --git a/Utilities/Release/create-cmake-release.cmake b/Utilities/Release/create-cmake-release.cmake
new file mode 100644
index 0000000000..a3f7032d11
--- /dev/null
+++ b/Utilities/Release/create-cmake-release.cmake
@@ -0,0 +1,78 @@
+if(NOT DEFINED CMAKE_CREATE_VERSION)
+ set(CMAKE_CREATE_VERSION "release")
+ message("Using default value of 'release' for CMAKE_CREATE_VERSION")
+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
+ magrathea_release.cmake # Linux
+ ibm_aix_release.cmake # AIX
+)
+
+set(RELEASE_SCRIPTS_BATCH_2
+ dash2win64_cygwin.cmake # Cygwin
+)
+
+function(write_batch_shell_script filename)
+ set(scripts ${ARGN})
+ set(i 0)
+ file(WRITE ${filename} "#!/bin/bash")
+ foreach(f ${scripts})
+ math(EXPR x "420*(${i}/4)")
+ math(EXPR y "160*(${i}%4)")
+ file(APPEND ${filename}
+ "
+\"${CMAKE_COMMAND}\" -DCMAKE_CREATE_VERSION=${CMAKE_CREATE_VERSION} -DCMAKE_DOC_TARBALL=\"${CMAKE_DOC_TARBALL}\" -P \"${CMAKE_ROOT}/Utilities/Release/${f}\" < /dev/null >& \"${CMAKE_CURRENT_SOURCE_DIR}/logs/${f}-${CMAKE_CREATE_VERSION}.log\" &
+xterm -geometry 64x6+${x}+${y} -sb -sl 2000 -T ${f}-${CMAKE_CREATE_VERSION}.log -e tail -f \"${CMAKE_CURRENT_SOURCE_DIR}/logs/${f}-${CMAKE_CREATE_VERSION}.log\" &
+")
+ math(EXPR i "${i}+1")
+ endforeach()
+ execute_process(COMMAND chmod a+x ${filename})
+endfunction()
+
+function(write_docs_shell_script filename)
+ find_program(SPHINX_EXECUTABLE
+ NAMES sphinx-build sphinx-build.py
+ DOC "Sphinx Documentation Builder (sphinx-doc.org)"
+ )
+ if(NOT SPHINX_EXECUTABLE)
+ message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
+ endif()
+
+ set(name cmake-${CMAKE_CREATE_VERSION}-docs)
+ file(WRITE "${filename}" "#!/usr/bin/env bash
+
+name=${name} &&
+inst=\"\$PWD/\$name\"
+(GIT_WORK_TREE=x git archive --prefix=\${name}-src/ ${CMAKE_CREATE_VERSION}) | tar x &&
+rm -rf \${name}-build &&
+mkdir \${name}-build &&
+cd \${name}-build &&
+\"${CMAKE_COMMAND}\" ../\${name}-src/Utilities/Sphinx \\
+ -DCMAKE_INSTALL_PREFIX=\"\$inst/\" \\
+ -DSPHINX_EXECUTABLE=\"${SPHINX_EXECUTABLE}\" \\
+ -DSPHINX_HTML=ON -DSPHINX_MAN=ON &&
+make install &&
+cd .. &&
+tar czf \${name}.tar.gz \${name} ||
+echo 'Failed to create \${name}.tar.gz'
+")
+ execute_process(COMMAND chmod a+x ${filename})
+ set(CMAKE_DOC_TARBALL "${name}.tar.gz" PARENT_SCOPE)
+endfunction()
+
+write_docs_shell_script("create-${CMAKE_CREATE_VERSION}-docs.sh")
+write_batch_shell_script("create-${CMAKE_CREATE_VERSION}-batch1.sh" ${RELEASE_SCRIPTS_BATCH_1})
+unset(CMAKE_DOC_TARBALL) # No pre-built docs in second batch.
+write_batch_shell_script("create-${CMAKE_CREATE_VERSION}-batch2.sh" ${RELEASE_SCRIPTS_BATCH_2})
+
+message("Run one at a time:
+ ./create-${CMAKE_CREATE_VERSION}-docs.sh &&
+ ./create-${CMAKE_CREATE_VERSION}-batch1.sh &&
+ ./create-${CMAKE_CREATE_VERSION}-batch2.sh &&
+ echo done
+")
diff --git a/Utilities/Release/dash2win64_cygwin.cmake b/Utilities/Release/dash2win64_cygwin.cmake
new file mode 100644
index 0000000000..ac3c527aa1
--- /dev/null
+++ b/Utilities/Release/dash2win64_cygwin.cmake
@@ -0,0 +1,29 @@
+set(CMAKE_RELEASE_DIRECTORY "c:/cygwin/home/dashboard/CMakeReleaseCygwin")
+set(PROCESSORS 9)
+set(MAKE_PROGRAM "make")
+set(MAKE "${MAKE_PROGRAM} -j8")
+set(HOST dash2win64)
+set(CPACK_BINARY_GENERATORS "CygwinBinary")
+set(CPACK_SOURCE_GENERATORS "CygwinSource")
+set(MAKE_PROGRAM "make")
+set(INITIAL_CACHE "CMAKE_BUILD_TYPE:STRING=Release
+CMAKE_Fortran_COMPILER_FULLPATH:FILEPATH=FALSE
+CTEST_TEST_TIMEOUT:STRING=7200
+DART_TESTING_TIMEOUT:STRING=7200
+SPHINX_HTML:BOOL=ON
+SPHINX_MAN:BOOL=ON
+")
+set(CXX g++)
+set(CC gcc)
+set(SCRIPT_NAME dash2win64cygwin)
+set(GIT_EXTRA "git config core.autocrlf false")
+get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+# WARNING: Temporary fix!! This exclusion of the ExternalProject test
+# is temporary until we can set up a new cygwin build machine.
+# It only fails because of cygwin/non-cygwin "svn" mismatches in this
+# particular environment. This is less than ideal, but at least it
+# allows us to produce cygwin builds in the short term.
+set(EXTRA_CTEST_ARGS "-E ExternalProject")
+
+include(${path}/release_cmake.cmake)
diff --git a/Utilities/Release/dash2win64_release.cmake b/Utilities/Release/dash2win64_release.cmake
new file mode 100644
index 0000000000..848e2f4cfa
--- /dev/null
+++ b/Utilities/Release/dash2win64_release.cmake
@@ -0,0 +1,21 @@
+set(CMAKE_RELEASE_DIRECTORY "c:/cygwin/home/dashboard/CMakeReleaseDirectory")
+set(CONFIGURE_WITH_CMAKE TRUE)
+set(CMAKE_CONFIGURE_PATH "c:/Program\\ Files\\ \\(x86\\)/CMake\\ 2.8/bin/cmake.exe")
+set(PROCESSORS 8)
+set(HOST dash2win64)
+set(CPACK_BINARY_GENERATORS "NSIS ZIP")
+set(CPACK_SOURCE_GENERATORS "ZIP")
+set(MAKE_PROGRAM "make")
+set(MAKE "${MAKE_PROGRAM} -j8")
+set(INITIAL_CACHE "CMAKE_BUILD_TYPE:STRING=Release
+CMAKE_USE_OPENSSL:BOOL=ON
+CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
+CMAKE_Fortran_COMPILER:FILEPATH=FALSE
+CMAKE_GENERATOR:INTERNAL=Unix Makefiles
+BUILD_QtDialog:BOOL:=TRUE
+CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:BOOL=TRUE
+QT_QMAKE_EXECUTABLE:FILEPATH=c:/Dashboards/Support/qt-build/Qt/bin/qmake.exe
+")
+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
new file mode 100644
index 0000000000..ba82aab7fb
--- /dev/null
+++ b/Utilities/Release/dashmacmini2_release.cmake
@@ -0,0 +1,24 @@
+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(INSTALL_PREFIX /)
+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
+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/dashmacmini5_release.cmake b/Utilities/Release/dashmacmini5_release.cmake
new file mode 100644
index 0000000000..6c9b8f4088
--- /dev/null
+++ b/Utilities/Release/dashmacmini5_release.cmake
@@ -0,0 +1,26 @@
+set(PROCESSORS 4)
+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(INSTALL_PREFIX /)
+set(HOST dashmacmini5)
+set(MAKE_PROGRAM "make")
+set(MAKE "${MAKE_PROGRAM} -j5")
+set(CPACK_BINARY_GENERATORS "DragNDrop TGZ TZ")
+set(CPACK_SOURCE_GENERATORS "TGZ TZ")
+set(CPACK_DMG_FORMAT "UDBZ") #build using bzip2 for smaller package size
+set(INITIAL_CACHE "
+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_BUILD_TYPE:STRING=Release
+CMAKE_OSX_ARCHITECTURES:STRING=x86_64
+CMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.5
+CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
+CPACK_SYSTEM_NAME:STRING=Darwin64-universal
+BUILD_QtDialog:BOOL=TRUE
+CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:BOOL=TRUE
+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/hythloth_release.cmake b/Utilities/Release/hythloth_release.cmake
new file mode 100644
index 0000000000..d2f4ba58ca
--- /dev/null
+++ b/Utilities/Release/hythloth_release.cmake
@@ -0,0 +1,10 @@
+set(PROCESSORS 2)
+set(HOST hythloth)
+set(MAKE_PROGRAM "make")
+set(MAKE "${MAKE_PROGRAM} -j2")
+set(INITIAL_CACHE "
+CMAKE_BUILD_TYPE:STRING=Release
+CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
+")
+get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH)
+include(${path}/release_cmake.cmake)
diff --git a/Utilities/Release/ibm_aix_release.cmake b/Utilities/Release/ibm_aix_release.cmake
new file mode 100644
index 0000000000..5a6efe6121
--- /dev/null
+++ b/Utilities/Release/ibm_aix_release.cmake
@@ -0,0 +1,15 @@
+set(CMAKE_RELEASE_DIRECTORY "/bench1/noibm34/CMakeReleaseDirectory")
+set(PROCESSORS 64)
+set(HOST "ibm-backend")
+set(SCRIPT_NAME aix)
+set(MAKE_PROGRAM "make")
+set(CC "xlc_r")
+set(CXX "xlC_r")
+set(FC "xlf")
+set(LDFLAGS "-Wl,-bmaxdata:0x80000000") # Push "Segmentation fault in extend_brk" over horizon
+set(INITIAL_CACHE "
+CMAKE_BUILD_TYPE:STRING=Release
+CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
+")
+get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH)
+include(${path}/release_cmake.cmake)
diff --git a/Utilities/Release/magrathea_release.cmake b/Utilities/Release/magrathea_release.cmake
new file mode 100644
index 0000000000..1bf75dd0af
--- /dev/null
+++ b/Utilities/Release/magrathea_release.cmake
@@ -0,0 +1,23 @@
+set(PROCESSORS 1)
+set(HOST magrathea)
+set(MAKE_PROGRAM "make")
+set(CC gcc332s)
+set(CXX c++332s)
+set(CFLAGS -DDT_RUNPATH=29)
+set(CXXFLAGS -DDT_RUNPATH=29)
+set(INITIAL_CACHE "
+CMAKE_BUILD_TYPE:STRING=Release
+CURSES_LIBRARY:FILEPATH=/usr/i686-gcc-332s/lib/libncurses.a
+CURSES_INCLUDE_PATH:PATH=/usr/i686-gcc-332s/include/ncurses
+FORM_LIBRARY:FILEPATH=/usr/i686-gcc-332s/lib/libform.a
+CMAKE_USE_OPENSSL:BOOL=ON
+OPENSSL_CRYPTO_LIBRARY:FILEPATH=/home/kitware/openssl-1.0.1g-install/lib/libcrypto.a
+OPENSSL_INCLUDE_DIR:PATH=/home/kitware/openssl-1.0.1g-install/include
+OPENSSL_SSL_LIBRARY:FILEPATH=/home/kitware/openssl-1.0.1g-install/lib/libssl.a
+CPACK_SYSTEM_NAME:STRING=Linux-i386
+BUILD_QtDialog:BOOL:=TRUE
+CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:BOOL=TRUE
+QT_QMAKE_EXECUTABLE:FILEPATH=/home/kitware/qt-4.43-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
new file mode 100644
index 0000000000..4c4dd8a5b0
--- /dev/null
+++ b/Utilities/Release/release_cmake.cmake
@@ -0,0 +1,145 @@
+get_filename_component(SCRIPT_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+# default to self extracting tgz, tgz, and tar.Z
+if(NOT DEFINED CPACK_BINARY_GENERATORS)
+ set(CPACK_BINARY_GENERATORS "STGZ TGZ TZ")
+endif()
+if(NOT DEFINED CMAKE_RELEASE_DIRECTORY)
+ set(CMAKE_RELEASE_DIRECTORY "~/CMakeReleaseDirectory")
+endif()
+if(NOT DEFINED SCRIPT_NAME)
+ set(SCRIPT_NAME "${HOST}")
+endif()
+if(NOT DEFINED MAKE_PROGRAM)
+ message(FATAL_ERROR "MAKE_PROGRAM must be set")
+endif()
+if(NOT DEFINED MAKE)
+ set(MAKE "${MAKE_PROGRAM}")
+endif()
+if(NOT DEFINED RUN_SHELL)
+ set(RUN_SHELL "/bin/sh")
+endif()
+if(NOT DEFINED PROCESSORS)
+ set(PROCESSORS 1)
+endif()
+if(NOT DEFINED CMAKE_CREATE_VERSION)
+ message(FATAL_ERROR "CMAKE_CREATE_VERSION not defined")
+endif()
+if(NOT DEFINED GIT_COMMAND)
+ set(GIT_COMMAND git)
+endif()
+
+if(${CMAKE_CREATE_VERSION} MATCHES "^(release|maint|next|nightly)$")
+ set(GIT_BRANCH origin/${CMAKE_CREATE_VERSION})
+else()
+ set(GIT_BRANCH ${CMAKE_CREATE_VERSION})
+endif()
+
+if(NOT DEFINED FINAL_PATH )
+ set(FINAL_PATH ${CMAKE_RELEASE_DIRECTORY}/${CMAKE_CREATE_VERSION}-build)
+endif()
+
+if(NOT HOST)
+ message(FATAL_ERROR "HOST must be specified with -DHOST=host")
+endif()
+if(NOT DEFINED MAKE)
+ message(FATAL_ERROR "MAKE must be specified with -DMAKE=\"make -j2\"")
+endif()
+
+message("Creating CMake release ${CMAKE_CREATE_VERSION} on ${HOST} with parallel = ${PROCESSORS}")
+
+# define a macro to run a remote command
+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})
+ else()
+ message("ssh ${HOST} ${command}")
+ execute_process(COMMAND ssh ${HOST} ${command} RESULT_VARIABLE result)
+ endif()
+ if(${result} GREATER 0)
+ message(FATAL_ERROR "Error running command: ${command}, return value = ${result}")
+ endif()
+endmacro()
+
+if(CMAKE_DOC_TARBALL)
+ get_filename_component(CMAKE_DOC_TARBALL_NAME "${CMAKE_DOC_TARBALL}" NAME)
+ string(REPLACE ".tar.gz" "-${SCRIPT_NAME}.tar.gz" CMAKE_DOC_TARBALL_STAGED "${CMAKE_DOC_TARBALL_NAME}")
+ message("scp '${CMAKE_DOC_TARBALL}' '${HOST}:${CMAKE_DOC_TARBALL_STAGED}'")
+ execute_process(COMMAND
+ scp ${CMAKE_DOC_TARBALL} ${HOST}:${CMAKE_DOC_TARBALL_STAGED}
+ RESULT_VARIABLE result)
+ if(${result} GREATER 0)
+ message("error sending doc tarball with scp '${CMAKE_DOC_TARBALL}' '${HOST}:${CMAKE_DOC_TARBALL_STAGED}'")
+ endif()
+endif()
+
+# set this so configure file will work from script mode
+# create the script specific for the given host
+set(SCRIPT_FILE release_cmake-${SCRIPT_NAME}.sh)
+configure_file(${SCRIPT_PATH}/release_cmake.sh.in ${SCRIPT_FILE} @ONLY)
+
+# run the script by starting a shell on the remote machine
+# then using the script file as input to the shell
+if(RUN_LOCAL)
+ message(FATAL_ERROR "run this command: ${RUN_SHELL} ${SCRIPT_FILE}")
+else()
+ remote_command("run release_cmake-${HOST}.sh on server"
+ "${RUN_SHELL}" ${SCRIPT_FILE})
+endif()
+
+# now figure out which types of packages were created
+set(generators ${CPACK_BINARY_GENERATORS} ${CPACK_SOURCE_GENERATORS})
+separate_arguments(generators)
+foreach(gen ${generators})
+ if("${gen}" STREQUAL "TGZ")
+ set(SUFFIXES ${SUFFIXES} "*.tar.gz")
+ endif()
+ if("${gen}" STREQUAL "STGZ")
+ set(SUFFIXES ${SUFFIXES} "*.sh")
+ endif()
+ if("${gen}" STREQUAL "DragNDrop")
+ set(SUFFIXES ${SUFFIXES} "*.dmg")
+ endif()
+ if("${gen}" STREQUAL "TBZ2")
+ set(SUFFIXES ${SUFFIXES} "*.tar.bz2")
+ endif()
+ if("${gen}" MATCHES "Cygwin")
+ set(SUFFIXES ${SUFFIXES} "*.tar.bz2")
+ set(extra_files setup.hint)
+ endif()
+ if("${gen}" STREQUAL "TZ")
+ set(SUFFIXES ${SUFFIXES} "*.tar.Z")
+ endif()
+ if("${gen}" STREQUAL "ZIP")
+ set(SUFFIXES ${SUFFIXES} "*.zip")
+ endif()
+ if("${gen}" STREQUAL "NSIS")
+ set(SUFFIXES ${SUFFIXES} "*.exe")
+ endif()
+endforeach()
+# copy all the files over from the remote machine
+set(PROJECT_PREFIX cmake-)
+foreach(suffix ${SUFFIXES})
+ message("scp ${HOST}:${FINAL_PATH}/${PROJECT_PREFIX}${suffix} .")
+ execute_process(COMMAND
+ scp ${HOST}:${FINAL_PATH}/${PROJECT_PREFIX}${suffix} .
+ RESULT_VARIABLE result)
+ if(${result} GREATER 0)
+ message("error getting file back scp ${HOST}:${FINAL_PATH}/${PROJECT_PREFIX}${suffix} .")
+ 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} .")
+ execute_process(COMMAND
+ scp ${HOST}:${FINAL_PATH}/${f} .
+ RESULT_VARIABLE result)
+ if(${result} GREATER 0)
+ message("error getting file back scp ${HOST}:${FINAL_PATH}/${f} .")
+ endif()
+ endforeach()
+endif()
diff --git a/Utilities/Release/release_cmake.sh.in b/Utilities/Release/release_cmake.sh.in
new file mode 100755
index 0000000000..76fdb3a7f5
--- /dev/null
+++ b/Utilities/Release/release_cmake.sh.in
@@ -0,0 +1,161 @@
+#!/bin/sh
+echo "Start release"
+date
+echo ""
+echo "remove and create working directory @CMAKE_RELEASE_DIRECTORY@"
+rm -rf @CMAKE_RELEASE_DIRECTORY@
+mkdir @CMAKE_RELEASE_DIRECTORY@
+
+check_exit_value()
+{
+ VALUE="$1"
+ if [ "$VALUE" != "0" ]; then
+ echo "error in $2"
+ exit 1
+ fi
+}
+
+CMAKE_DOC_TARBALL=""
+if [ ! -z "@CMAKE_DOC_TARBALL_NAME@" ] ; then
+ CMAKE_DOC_TARBALL=@CMAKE_RELEASE_DIRECTORY@/@CMAKE_DOC_TARBALL_NAME@
+ mv "$HOME/@CMAKE_DOC_TARBALL_STAGED@" "$CMAKE_DOC_TARBALL"
+ check_exit_value $? "mv doc tarball" || exit 1
+fi
+
+if [ ! -z "@CC@" ]; then
+ export CC="@CC@"
+ check_exit_value $? "set CC compiler env var" || exit 1
+fi
+
+if [ ! -z "@FC@" ]; then
+ export FC="@FC@"
+ check_exit_value $? "set FC compiler env var" || exit 1
+fi
+
+if [ ! -z "@CXX@" ]; then
+ export CXX="@CXX@"
+ check_exit_value $? "set CC compiler env var" || exit 1
+fi
+
+if [ ! -z "@LDFLAGS@" ]; then
+ export LDFLAGS="@LDFLAGS@"
+ check_exit_value $? "set LDFLAGS env var" || exit 1
+fi
+
+if [ ! -z "@FFLAGS@" ]; then
+ export FFLAGS="@FFLAGS@"
+ check_exit_value $? "set FFLAGS env var" || exit 1
+fi
+
+if [ ! -z "@CFLAGS@" ]; then
+ export CFLAGS="@CFLAGS@"
+ check_exit_value $? "set CFLAGS env var" || exit 1
+fi
+
+if [ ! -z "@CXXFLAGS@" ]; then
+ export CXXFLAGS="@CXXFLAGS@"
+ check_exit_value $? "setCXXFLAGS env var" || exit 1
+fi
+
+if [ ! -z "@USER_MAKE_RULE_FILE_CONTENTS@" ]; then
+ echo "@USER_MAKE_RULE_FILE_CONTENTS@" > "@USER_MAKE_RULE_FILE@"
+ check_exit_value $? "Create User Rule file" || exit 1
+fi
+echo "Create a directory to build in"
+rm -rf @CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build
+check_exit_value $? "Remove build tree" || exit 1
+mkdir @CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build
+check_exit_value $? "Create build directory" || exit 1
+# make sure directory was created
+if [ ! -d @CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build ]; then
+ echo "Could not create @CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build"
+ exit -1
+fi
+
+echo "Create initial cache"
+echo "@INITIAL_CACHE@" > @CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build/CMakeCache.txt
+check_exit_value $? "Create initial cache" || exit 1
+
+# create a user override file user.txt if USER_OVERRIDE is set,
+# and append the cache variable to the cache
+if [ ! -z "@USER_OVERRIDE@" ]; then
+ echo "@USER_OVERRIDE@" > @CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build/user.txt
+ echo "CMAKE_USER_MAKE_RULES_OVERRIDE:FILEPATH=@CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build/user.txt" >> @CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build/CMakeCache.txt
+fi
+
+# Point build at pre-built documentation tarball, if any.
+if [ ! -z "$CMAKE_DOC_TARBALL" ]; then
+ echo "CMAKE_DOC_TARBALL:FILEPATH=$CMAKE_DOC_TARBALL" >> @CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build/CMakeCache.txt
+fi
+
+echo "Checkout the source for @CMAKE_CREATE_VERSION@"
+cd @CMAKE_RELEASE_DIRECTORY@
+if [ ! -z "@GIT_COMMAND@" ]; then
+ # clone the repo without creating any source files in the directory
+ # matching the branch being built (i.e. master CMake-2-8, etc)
+ @GIT_COMMAND@ clone -n git://cmake.org/cmake.git @CMAKE_CREATE_VERSION@
+ check_exit_value $? "Checkout git cmake source" || exit 1
+ # go into the git directory
+ cd @CMAKE_CREATE_VERSION@
+ # run any extra commands if they exist
+ @GIT_EXTRA@
+ check_exit_value $? "git extra cmake source" || exit 1
+ # now checkout a copy on the local branch working
+ @GIT_COMMAND@ checkout -b working @GIT_BRANCH@
+ check_exit_value $? "git checkout" || exit 1
+ cd ..
+else
+ echo GIT_COMMAND does not exist
+ exit 1
+fi
+
+cd @CMAKE_RELEASE_DIRECTORY@/@CMAKE_CREATE_VERSION@-build
+
+if [ ! -z "@CONFIGURE_WITH_CMAKE@" ]; then
+ echo "Run cmake to configure cmake"
+ @CMAKE_CONFIGURE_PATH@ ../@CMAKE_CREATE_VERSION@
+ check_exit_value $? "Configure cmake" || exit 1
+else
+ if [ -z "@INSTALL_PREFIX@" ]; then
+ echo "Run cmake bootstrap --parallel=@PROCESSORS@"
+ ../@CMAKE_CREATE_VERSION@/bootstrap --parallel=@PROCESSORS@
+ check_exit_value $? "Bootstrap cmake" || exit 1
+ else
+ echo "Run cmake bootstrap --prefix=@INSTALL_PREFIX@ --parallel=@PROCESSORS@"
+ ../@CMAKE_CREATE_VERSION@/bootstrap --prefix=@INSTALL_PREFIX@ --parallel=@PROCESSORS@
+ check_exit_value $? "Bootstrap cmake" || exit 1
+ fi
+fi
+
+echo "Build cmake with @MAKE@"
+@MAKE@
+check_exit_value $? "Build cmake" || exit 1
+
+if [ -z "@SKIP_TESTS@" ]; then
+ echo "Run cmake tests"
+ ./bin/ctest --output-on-failure -j @PROCESSORS@ @EXTRA_CTEST_ARGS@
+ check_exit_value $? "Test cmake" || exit 1
+fi
+
+# loop over binary generators
+generators="@CPACK_BINARY_GENERATORS@"
+for GEN in $generators; do
+ echo "Create $GEN package"
+ ./bin/cpack -D CMAKE_MAKE_PROGRAM=@MAKE_PROGRAM@ -G $GEN
+ check_exit_value $? "Create $GEN package" || exit 1
+done
+
+# loop over source generators
+generators="@CPACK_SOURCE_GENERATORS@"
+for GEN in $generators; do
+ echo "Create $GEN package"
+ ./bin/cpack -D CMAKE_MAKE_PROGRAM=@MAKE_PROGRAM@ -G $GEN --config CPackSourceConfig.cmake
+ check_exit_value $? "Create $GEN package" || exit 1
+done
+
+
+
+echo "End release"
+date
+echo ""
+exit 0
diff --git a/Utilities/Release/upload_release.cmake b/Utilities/Release/upload_release.cmake
new file mode 100644
index 0000000000..5f4da8f0e6
--- /dev/null
+++ b/Utilities/Release/upload_release.cmake
@@ -0,0 +1,39 @@
+set(CTEST_RUN_CURRENT_SCRIPT 0)
+if(NOT VERSION)
+ set(VERSION 3.0)
+endif()
+if(NOT DEFINED PROJECT_PREFIX)
+ set(PROJECT_PREFIX cmake-${VERSION})
+endif()
+if(NOT DEFINED DIR)
+ set(DIR "v${VERSION}")
+endif()
+file(GLOB FILES ${CMAKE_CURRENT_SOURCE_DIR} "${PROJECT_PREFIX}*")
+list(SORT FILES)
+list(REVERSE FILES)
+message("${FILES}")
+set(UPLOAD_LOC
+ "kitware@www.cmake.org:/projects/FTP/pub/cmake/${DIR}")
+set(count 0)
+foreach(file ${FILES})
+ if(NOT IS_DIRECTORY ${file})
+ message("upload ${file} ${UPLOAD_LOC}")
+ execute_process(COMMAND
+ scp ${file} ${UPLOAD_LOC}
+ RESULT_VARIABLE result)
+ if("${result}" GREATER 0)
+ message(FATAL_ERROR "failed to upload file to ${UPLOAD_LOC}")
+ endif()
+
+ # Pause to give each upload a distinct (to the nearest second)
+ # time stamp
+ if(COMMAND ctest_sleep)
+ ctest_sleep(2)
+ endif()
+
+ math(EXPR count "${count} + 1")
+ endif()
+endforeach()
+if(${count} EQUAL 0)
+ message(FATAL_ERROR "Error no files uploaded.")
+endif()
diff --git a/Utilities/SetupForDevelopment.sh b/Utilities/SetupForDevelopment.sh
new file mode 100755
index 0000000000..0a9df7e836
--- /dev/null
+++ b/Utilities/SetupForDevelopment.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+cd "${BASH_SOURCE%/*}/.." &&
+Utilities/GitSetup/setup-user && echo &&
+Utilities/GitSetup/setup-hooks && echo &&
+Utilities/GitSetup/setup-stage && echo &&
+(Utilities/GitSetup/setup-ssh ||
+ echo 'Failed to setup SSH. Run this again to retry.') && echo &&
+Utilities/GitSetup/tips
+
+# Rebase master by default
+git config rebase.stat true
+git config branch.master.rebase true
diff --git a/Utilities/Sphinx/.gitignore b/Utilities/Sphinx/.gitignore
new file mode 100644
index 0000000000..0d20b6487c
--- /dev/null
+++ b/Utilities/Sphinx/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/Utilities/Sphinx/CMakeLists.txt b/Utilities/Sphinx/CMakeLists.txt
new file mode 100644
index 0000000000..a58604ece8
--- /dev/null
+++ b/Utilities/Sphinx/CMakeLists.txt
@@ -0,0 +1,178 @@
+#=============================================================================
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2013 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.
+#=============================================================================
+if(NOT CMake_SOURCE_DIR)
+ set(CMakeHelp_STANDALONE 1)
+ cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
+ get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH)
+ get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH)
+ include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake)
+ include(${CMake_SOURCE_DIR}/Source/CMakeVersionCompute.cmake)
+ include(${CMake_SOURCE_DIR}/Source/CMakeInstallDestinations.cmake)
+ unset(CMAKE_DATA_DIR)
+ unset(CMAKE_DATA_DIR CACHE)
+endif()
+project(CMakeHelp NONE)
+
+option(SPHINX_MAN "Build man pages with Sphinx" OFF)
+option(SPHINX_HTML "Build html help with Sphinx" OFF)
+option(SPHINX_SINGLEHTML "Build html single page help with Sphinx" OFF)
+option(SPHINX_QTHELP "Build Qt help with Sphinx" OFF)
+option(SPHINX_TEXT "Build text help with Sphinx (not installed)" OFF)
+find_program(SPHINX_EXECUTABLE
+ NAMES sphinx-build
+ DOC "Sphinx Documentation Builder (sphinx-doc.org)"
+ )
+
+mark_as_advanced(SPHINX_TEXT)
+
+if(NOT SPHINX_MAN AND NOT SPHINX_HTML AND NOT SPHINX_SINGLEHTML AND NOT SPHINX_QTHELP AND NOT SPHINX_TEXT)
+ return()
+elseif(NOT SPHINX_EXECUTABLE)
+ message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
+endif()
+
+set(copyright_line_regex "^Copyright (2000-20[0-9][0-9] Kitware.*)")
+file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
+ LIMIT_COUNT 1 REGEX "${copyright_line_regex}")
+if(copyright_line MATCHES "${copyright_line_regex}")
+ set(conf_copyright "${CMAKE_MATCH_1}")
+else()
+ set(conf_copyright "Kitware, Inc.")
+endif()
+
+set(conf_docs "${CMake_SOURCE_DIR}/Help")
+set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}")
+set(conf_version "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
+set(conf_release "${CMake_VERSION}")
+configure_file(conf.py.in conf.py @ONLY)
+
+set(doc_formats "")
+if(SPHINX_HTML)
+ list(APPEND doc_formats html)
+endif()
+if(SPHINX_MAN)
+ list(APPEND doc_formats man)
+endif()
+if(SPHINX_SINGLEHTML)
+ list(APPEND doc_formats singlehtml)
+endif()
+if(SPHINX_TEXT)
+ list(APPEND doc_formats text)
+endif()
+if(SPHINX_QTHELP)
+ find_package(PythonInterp REQUIRED)
+
+ find_program(QCOLLECTIONGENERATOR_EXECUTABLE
+ NAMES qcollectiongenerator
+ DOC "qcollectiongenerator tool"
+ )
+ if (NOT QCOLLECTIONGENERATOR_EXECUTABLE)
+ message(FATAL_ERROR "QCOLLECTIONGENERATOR_EXECUTABLE (qcollectiongenerator) not found!")
+ endif()
+ list(APPEND doc_formats qthelp)
+
+ set(qthelp_extra_commands
+ # Workaround for assistant prior to
+ # https://codereview.qt-project.org/#change,82250 in Qt 4.
+ COMMAND ${CMAKE_COMMAND} "-DCSS_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/_static"
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/apply_qthelp_css_workaround.cmake"
+ # Workaround sphinx configurability:
+ # https://bitbucket.org/birkenfeld/sphinx/issue/1448/make-qthelp-more-configurable
+ COMMAND ${CMAKE_COMMAND} "-DQTHELP_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
+ "-DCMake_VERSION=${CMake_VERSION_MAJOR}${CMake_VERSION_MINOR}${CMake_VERSION_PATCH}"
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/fixup_qthelp_names.cmake"
+
+ # Create proper identifiers. Workaround for
+ # https://bitbucket.org/birkenfeld/sphinx/issue/1491/qthelp-should-generate-identifiers-for
+ COMMAND "${PYTHON_EXECUTABLE}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/create_identifiers.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
+
+ COMMAND ${QCOLLECTIONGENERATOR_EXECUTABLE}
+ ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qhcp
+ )
+endif()
+
+
+set(doc_format_outputs "")
+set(doc_format_last "")
+foreach(format ${doc_formats})
+ set(doc_format_output "doc_format_${format}")
+ set(doc_format_log "build-${format}.log")
+ add_custom_command(
+ OUTPUT ${doc_format_output}
+ COMMAND ${SPHINX_EXECUTABLE}
+ -c ${CMAKE_CURRENT_BINARY_DIR}
+ -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
+ -b ${format}
+ ${CMake_SOURCE_DIR}/Help
+ ${CMAKE_CURRENT_BINARY_DIR}/${format}
+ > ${doc_format_log} # log stdout, pass stderr
+ ${${format}_extra_commands}
+ DEPENDS ${doc_format_last}
+ COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
+ VERBATIM
+ )
+ set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
+ list(APPEND doc_format_outputs ${doc_format_output})
+ set(doc_format_last ${doc_format_output})
+endforeach()
+
+add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
+
+foreach(t
+ cmake
+ ccmake
+ cmake-gui
+ cpack
+ ctest
+ )
+ if(TARGET ${t})
+ # Build documentation after main executables.
+ add_dependencies(documentation ${t})
+ endif()
+endforeach()
+
+if(SPHINX_MAN)
+ file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
+ ${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
+ foreach(m ${man_rst})
+ if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
+ set(name "${CMAKE_MATCH_1}")
+ set(sec "${CMAKE_MATCH_2}")
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
+ DESTINATION ${CMAKE_MAN_DIR}/man${sec})
+ endif()
+ endforeach()
+endif()
+
+if(SPHINX_HTML)
+ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
+ DESTINATION ${CMAKE_DOC_DIR}
+ PATTERN .buildinfo EXCLUDE
+ PATTERN objects.inv EXCLUDE
+ )
+endif()
+
+if(SPHINX_SINGLEHTML)
+ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml
+ DESTINATION ${CMAKE_DOC_DIR}
+ PATTERN .buildinfo EXCLUDE
+ PATTERN objects.inv EXCLUDE
+ )
+endif()
+
+if(SPHINX_QTHELP)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake-${CMake_VERSION_MAJOR}${CMake_VERSION_MINOR}${CMake_VERSION_PATCH}.qch
+ DESTINATION ${CMAKE_DOC_DIR}
+ )
+endif()
diff --git a/Utilities/Sphinx/apply_qthelp_css_workaround.cmake b/Utilities/Sphinx/apply_qthelp_css_workaround.cmake
new file mode 100644
index 0000000000..8b74d12bb7
--- /dev/null
+++ b/Utilities/Sphinx/apply_qthelp_css_workaround.cmake
@@ -0,0 +1,15 @@
+
+file(READ "${CSS_DIR}/basic.css" BasicCssContent)
+
+file(READ "${CSS_DIR}/default.css" DefaultCssContent)
+string(REPLACE
+ "@import url(\"basic.css\")" "${BasicCssContent}"
+ DefaultCssContent "${DefaultCssContent}"
+)
+
+file(READ "${CSS_DIR}/cmake.css" CMakeCssContent)
+string(REPLACE
+ "@import url(\"default.css\")" "${DefaultCssContent}"
+ CMakeCssContent "${CMakeCssContent}"
+)
+file(WRITE "${CSS_DIR}/cmake.css" "${CMakeCssContent}")
diff --git a/Utilities/Sphinx/cmake.py b/Utilities/Sphinx/cmake.py
new file mode 100644
index 0000000000..2629bb33c7
--- /dev/null
+++ b/Utilities/Sphinx/cmake.py
@@ -0,0 +1,339 @@
+#=============================================================================
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2013 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.
+#=============================================================================
+import os
+import re
+
+# Monkey patch for pygments reporting an error when generator expressions are
+# used.
+# https://bitbucket.org/birkenfeld/pygments-main/issue/942/cmake-generator-expressions-not-handled
+from pygments.lexers import CMakeLexer
+from pygments.token import Name, Operator
+from pygments.lexer import bygroups
+CMakeLexer.tokens["args"].append(('(\\$<)(.+?)(>)',
+ bygroups(Operator, Name.Variable, Operator)))
+
+# Monkey patch for sphinx generating invalid content for qcollectiongenerator
+# https://bitbucket.org/birkenfeld/sphinx/issue/1435/qthelp-builder-should-htmlescape-keywords
+from sphinx.util.pycompat import htmlescape
+from sphinx.builders.qthelp import QtHelpBuilder
+old_build_keywords = QtHelpBuilder.build_keywords
+def new_build_keywords(self, title, refs, subitems):
+ old_items = old_build_keywords(self, title, refs, subitems)
+ new_items = []
+ for item in old_items:
+ before, rest = item.split("ref=\"", 1)
+ ref, after = rest.split("\"")
+ if ("<" in ref and ">" in ref):
+ new_items.append(before + "ref=\"" + htmlescape(ref) + "\"" + after)
+ else:
+ new_items.append(item)
+ return new_items
+QtHelpBuilder.build_keywords = new_build_keywords
+
+
+from docutils.parsers.rst import Directive, directives
+from docutils.transforms import Transform
+try:
+ from docutils.utils.error_reporting import SafeString, ErrorString
+except ImportError:
+ # error_reporting was not in utils before version 0.11:
+ from docutils.error_reporting import SafeString, ErrorString
+
+from docutils import io, nodes
+
+from sphinx.directives import ObjectDescription
+from sphinx.domains import Domain, ObjType
+from sphinx.roles import XRefRole
+from sphinx.util.nodes import make_refnode
+from sphinx import addnodes
+
+class CMakeModule(Directive):
+ required_arguments = 1
+ optional_arguments = 0
+ final_argument_whitespace = True
+ option_spec = {'encoding': directives.encoding}
+
+ def __init__(self, *args, **keys):
+ self.re_start = re.compile(r'^#\[(?P<eq>=*)\[\.rst:$')
+ Directive.__init__(self, *args, **keys)
+
+ def run(self):
+ settings = self.state.document.settings
+ if not settings.file_insertion_enabled:
+ raise self.warning('"%s" directive disabled.' % self.name)
+
+ env = self.state.document.settings.env
+ rel_path, path = env.relfn2path(self.arguments[0])
+ path = os.path.normpath(path)
+ encoding = self.options.get('encoding', settings.input_encoding)
+ e_handler = settings.input_encoding_error_handler
+ try:
+ settings.record_dependencies.add(path)
+ f = io.FileInput(source_path=path, encoding=encoding,
+ error_handler=e_handler)
+ except UnicodeEncodeError as error:
+ raise self.severe('Problems with "%s" directive path:\n'
+ 'Cannot encode input file path "%s" '
+ '(wrong locale?).' %
+ (self.name, SafeString(path)))
+ except IOError as error:
+ raise self.severe('Problems with "%s" directive path:\n%s.' %
+ (self.name, ErrorString(error)))
+ raw_lines = f.read().splitlines()
+ f.close()
+ rst = None
+ lines = []
+ for line in raw_lines:
+ if rst is not None and rst != '#':
+ # Bracket mode: check for end bracket
+ pos = line.find(rst)
+ if pos >= 0:
+ if line[0] == '#':
+ line = ''
+ else:
+ line = line[0:pos]
+ rst = None
+ else:
+ # Line mode: check for .rst start (bracket or line)
+ m = self.re_start.match(line)
+ if m:
+ rst = ']%s]' % m.group('eq')
+ line = ''
+ elif line == '#.rst:':
+ rst = '#'
+ line = ''
+ elif rst == '#':
+ if line == '#' or line[:2] == '# ':
+ line = line[2:]
+ else:
+ rst = None
+ line = ''
+ elif rst is None:
+ line = ''
+ lines.append(line)
+ if rst is not None and rst != '#':
+ raise self.warning('"%s" found unclosed bracket "#[%s[.rst:" in %s' %
+ (self.name, rst[1:-1], path))
+ self.state_machine.insert_input(lines, path)
+ return []
+
+class _cmake_index_entry:
+ def __init__(self, desc):
+ self.desc = desc
+
+ def __call__(self, title, targetid):
+ return ('pair', u'%s ; %s' % (self.desc, title), targetid, 'main')
+
+_cmake_index_objs = {
+ 'command': _cmake_index_entry('command'),
+ 'generator': _cmake_index_entry('generator'),
+ 'manual': _cmake_index_entry('manual'),
+ 'module': _cmake_index_entry('module'),
+ 'policy': _cmake_index_entry('policy'),
+ 'prop_cache': _cmake_index_entry('cache property'),
+ 'prop_dir': _cmake_index_entry('directory property'),
+ 'prop_gbl': _cmake_index_entry('global property'),
+ 'prop_inst': _cmake_index_entry('installed file property'),
+ 'prop_sf': _cmake_index_entry('source file property'),
+ 'prop_test': _cmake_index_entry('test property'),
+ 'prop_tgt': _cmake_index_entry('target property'),
+ 'variable': _cmake_index_entry('variable'),
+ }
+
+def _cmake_object_inventory(env, document, line, objtype, targetid):
+ inv = env.domaindata['cmake']['objects']
+ if targetid in inv:
+ document.reporter.warning(
+ 'CMake object "%s" also described in "%s".' %
+ (targetid, env.doc2path(inv[targetid][0])), line=line)
+ inv[targetid] = (env.docname, objtype)
+
+class CMakeTransform(Transform):
+
+ # Run this transform early since we insert nodes we want
+ # treated as if they were written in the documents.
+ default_priority = 210
+
+ def __init__(self, document, startnode):
+ Transform.__init__(self, document, startnode)
+ self.titles = {}
+
+ def parse_title(self, docname):
+ """Parse a document title as the first line starting in [A-Za-z0-9<]
+ or fall back to the document basename if no such line exists.
+ The cmake --help-*-list commands also depend on this convention.
+ Return the title or False if the document file does not exist.
+ """
+ env = self.document.settings.env
+ title = self.titles.get(docname)
+ if title is None:
+ fname = os.path.join(env.srcdir, docname+'.rst')
+ try:
+ f = open(fname, 'r')
+ except IOError:
+ title = False
+ else:
+ for line in f:
+ if len(line) > 0 and (line[0].isalnum() or line[0] == '<'):
+ title = line.rstrip()
+ break
+ f.close()
+ if title is None:
+ title = os.path.basename(docname)
+ self.titles[docname] = title
+ return title
+
+ def apply(self):
+ env = self.document.settings.env
+
+ # Treat some documents as cmake domain objects.
+ objtype, sep, tail = env.docname.rpartition('/')
+ make_index_entry = _cmake_index_objs.get(objtype)
+ if make_index_entry:
+ title = self.parse_title(env.docname)
+ # Insert the object link target.
+ targetid = '%s:%s' % (objtype, title)
+ targetnode = nodes.target('', '', ids=[targetid])
+ self.document.insert(0, targetnode)
+ # Insert the object index entry.
+ indexnode = addnodes.index()
+ indexnode['entries'] = [make_index_entry(title, targetid)]
+ self.document.insert(0, indexnode)
+ # Add to cmake domain object inventory
+ _cmake_object_inventory(env, self.document, 1, objtype, targetid)
+
+class CMakeObject(ObjectDescription):
+
+ def handle_signature(self, sig, signode):
+ # called from sphinx.directives.ObjectDescription.run()
+ signode += addnodes.desc_name(sig, sig)
+ return sig
+
+ def add_target_and_index(self, name, sig, signode):
+ targetid = '%s:%s' % (self.objtype, name)
+ if targetid not in self.state.document.ids:
+ signode['names'].append(targetid)
+ signode['ids'].append(targetid)
+ signode['first'] = (not self.names)
+ self.state.document.note_explicit_target(signode)
+ _cmake_object_inventory(self.env, self.state.document,
+ self.lineno, self.objtype, targetid)
+
+ make_index_entry = _cmake_index_objs.get(self.objtype)
+ if make_index_entry:
+ self.indexnode['entries'].append(make_index_entry(name, targetid))
+
+class CMakeXRefRole(XRefRole):
+
+ # See sphinx.util.nodes.explicit_title_re; \x00 escapes '<'.
+ _re = re.compile(r'^(.+?)(\s*)(?<!\x00)<(.*?)>$', re.DOTALL)
+ _re_sub = re.compile(r'^([^()\s]+)\s*\(([^()]*)\)$', re.DOTALL)
+
+ def __call__(self, typ, rawtext, text, *args, **keys):
+ # Translate CMake command cross-references of the form:
+ # `command_name(SUB_COMMAND)`
+ # to have an explicit target:
+ # `command_name(SUB_COMMAND) <command_name>`
+ if typ == 'cmake:command':
+ m = CMakeXRefRole._re_sub.match(text)
+ if m:
+ text = '%s <%s>' % (text, m.group(1))
+ # CMake cross-reference targets frequently contain '<' so escape
+ # any explicit `<target>` with '<' not preceded by whitespace.
+ while True:
+ m = CMakeXRefRole._re.match(text)
+ if m and len(m.group(2)) == 0:
+ text = '%s\x00<%s>' % (m.group(1), m.group(3))
+ else:
+ break
+ return XRefRole.__call__(self, typ, rawtext, text, *args, **keys)
+
+class CMakeDomain(Domain):
+ """CMake domain."""
+ name = 'cmake'
+ label = 'CMake'
+ object_types = {
+ 'command': ObjType('command', 'command'),
+ 'generator': ObjType('generator', 'generator'),
+ 'variable': ObjType('variable', 'variable'),
+ 'module': ObjType('module', 'module'),
+ 'policy': ObjType('policy', 'policy'),
+ 'prop_cache': ObjType('prop_cache', 'prop_cache'),
+ 'prop_dir': ObjType('prop_dir', 'prop_dir'),
+ 'prop_gbl': ObjType('prop_gbl', 'prop_gbl'),
+ 'prop_inst': ObjType('prop_inst', 'prop_inst'),
+ 'prop_sf': ObjType('prop_sf', 'prop_sf'),
+ 'prop_test': ObjType('prop_test', 'prop_test'),
+ 'prop_tgt': ObjType('prop_tgt', 'prop_tgt'),
+ 'manual': ObjType('manual', 'manual'),
+ }
+ directives = {
+ 'command': CMakeObject,
+ 'variable': CMakeObject,
+ # Other object types cannot be created except by the CMakeTransform
+ # 'generator': CMakeObject,
+ # 'module': CMakeObject,
+ # 'policy': CMakeObject,
+ # 'prop_cache': CMakeObject,
+ # 'prop_dir': CMakeObject,
+ # 'prop_gbl': CMakeObject,
+ # 'prop_inst': CMakeObject,
+ # 'prop_sf': CMakeObject,
+ # 'prop_test': CMakeObject,
+ # 'prop_tgt': CMakeObject,
+ # 'manual': CMakeObject,
+ }
+ roles = {
+ 'command': CMakeXRefRole(fix_parens = True, lowercase = True),
+ 'generator': CMakeXRefRole(),
+ 'variable': CMakeXRefRole(),
+ 'module': CMakeXRefRole(),
+ 'policy': CMakeXRefRole(),
+ 'prop_cache': CMakeXRefRole(),
+ 'prop_dir': CMakeXRefRole(),
+ 'prop_gbl': CMakeXRefRole(),
+ 'prop_inst': CMakeXRefRole(),
+ 'prop_sf': CMakeXRefRole(),
+ 'prop_test': CMakeXRefRole(),
+ 'prop_tgt': CMakeXRefRole(),
+ 'manual': CMakeXRefRole(),
+ }
+ initial_data = {
+ 'objects': {}, # fullname -> docname, objtype
+ }
+
+ def clear_doc(self, docname):
+ to_clear = set()
+ for fullname, (fn, _) in self.data['objects'].items():
+ if fn == docname:
+ to_clear.add(fullname)
+ for fullname in to_clear:
+ del self.data['objects'][fullname]
+
+ def resolve_xref(self, env, fromdocname, builder,
+ typ, target, node, contnode):
+ targetid = '%s:%s' % (typ, target)
+ obj = self.data['objects'].get(targetid)
+ if obj is None:
+ # TODO: warn somehow?
+ return None
+ return make_refnode(builder, fromdocname, obj[0], targetid,
+ contnode, target)
+
+ def get_objects(self):
+ for refname, (docname, type) in self.data['objects'].items():
+ yield (refname, refname, type, docname, refname, 1)
+
+def setup(app):
+ app.add_directive('cmake-module', CMakeModule)
+ app.add_transform(CMakeTransform)
+ app.add_domain(CMakeDomain)
diff --git a/Utilities/Sphinx/conf.py.in b/Utilities/Sphinx/conf.py.in
new file mode 100644
index 0000000000..d81bbcf76b
--- /dev/null
+++ b/Utilities/Sphinx/conf.py.in
@@ -0,0 +1,67 @@
+#=============================================================================
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2013 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.
+#=============================================================================
+import sys
+import os
+import re
+import glob
+
+sys.path.insert(0, r'@conf_path@')
+
+source_suffix = '.rst'
+master_doc = 'index'
+
+project = 'CMake'
+copyright = '@conf_copyright@'
+version = '@conf_version@' # feature version
+release = '@conf_release@' # full version string
+
+primary_domain = 'cmake'
+
+exclude_patterns = []
+
+extensions = ['cmake']
+templates_path = ['@conf_path@/templates']
+
+cmake_manuals = sorted(glob.glob(r'@conf_docs@/manual/*.rst'))
+cmake_manual_description = re.compile('^\.\. cmake-manual-description:(.*)$')
+man_pages = []
+for fpath in cmake_manuals:
+ try:
+ name, sec, rst = os.path.basename(fpath).split('.')
+ desc = None
+ f = open(fpath, 'r')
+ for l in f:
+ m = cmake_manual_description.match(l)
+ if m:
+ desc = m.group(1).strip()
+ break
+ f.close()
+ if desc:
+ man_pages.append(('manual/%s.%s' % (name, sec),
+ name, desc, [], int(sec)))
+ else:
+ sys.stderr.write("ERROR: No cmake-manual-description in '%s'\n" % fpath)
+ except Exception as e:
+ sys.stderr.write("ERROR: %s\n" % str(e))
+man_show_urls = False
+
+html_show_sourcelink = True
+html_static_path = ['@conf_path@/static']
+html_style = 'cmake.css'
+html_theme = 'default'
+html_title = 'CMake %s Documentation' % release
+html_short_title = '%s Documentation' % release
+html_favicon = 'cmake-favicon.ico'
+# Not supported yet by sphinx:
+# https://bitbucket.org/birkenfeld/sphinx/issue/1448/make-qthelp-more-configurable
+# qthelp_namespace = "org.cmake"
+# qthelp_qch_name = "CMake-300.qch"
diff --git a/Utilities/Sphinx/create_identifiers.py b/Utilities/Sphinx/create_identifiers.py
new file mode 100755
index 0000000000..7715e534ae
--- /dev/null
+++ b/Utilities/Sphinx/create_identifiers.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+import sys, os
+
+if len(sys.argv) != 2:
+ sys.exit(-1)
+name = sys.argv[1] + "/CMake.qhp"
+
+f = open(name)
+
+if not f:
+ sys.exit(-1)
+
+lines = f.read().splitlines()
+
+if not lines:
+ sys.exit(-1)
+
+newlines = []
+
+for line in lines:
+
+ mapping = (("command", "command"),
+ ("variable", "variable"),
+ ("target property", "prop_tgt"),
+ ("test property", "prop_test"),
+ ("source file property", "prop_sf"),
+ ("global property", "prop_gbl"),
+ ("module", "module"),
+ ("directory property", "prop_dir"),
+ ("cache property", "prop_cache"),
+ ("policy", "policy"),
+ ("installed file property", "prop_inst"))
+
+ for domain_object_string, domain_object_type in mapping:
+ if "<keyword name=\"" + domain_object_string + "\"" in line:
+ if not "id=\"" in line:
+ prefix = "<keyword name=\"" + domain_object_string + "\" "
+ part1, part2 = line.split(prefix)
+ head, tail = part2.split("#" + domain_object_type + ":")
+ domain_object, rest = tail.split("\"")
+ line = part1 + prefix + "id=\"" + domain_object_type + "/" + domain_object + "\" " + part2
+ newlines.append(line + "\n")
+
+f = open(name, "w")
+f.writelines(newlines)
diff --git a/Utilities/Sphinx/fixup_qthelp_names.cmake b/Utilities/Sphinx/fixup_qthelp_names.cmake
new file mode 100644
index 0000000000..e35ef25bef
--- /dev/null
+++ b/Utilities/Sphinx/fixup_qthelp_names.cmake
@@ -0,0 +1,32 @@
+
+file(READ "${QTHELP_DIR}/CMake.qhcp" QHCP_CONTENT)
+
+string(REPLACE
+ "<homePage>qthelp://org.sphinx.cmake" "<homePage>qthelp://org.cmake"
+ QHCP_CONTENT "${QHCP_CONTENT}"
+)
+string(REPLACE
+ "<startPage>qthelp://org.sphinx.cmake" "<startPage>qthelp://org.cmake"
+ QHCP_CONTENT "${QHCP_CONTENT}"
+)
+
+string(REPLACE
+ "<output>CMake.qch" "<output>CMake-${CMake_VERSION}.qch"
+ QHCP_CONTENT "${QHCP_CONTENT}"
+)
+string(REPLACE
+ "<file>CMake.qch" "<file>CMake-${CMake_VERSION}.qch"
+ QHCP_CONTENT "${QHCP_CONTENT}"
+)
+
+file(WRITE "${QTHELP_DIR}/CMake.qhcp" "${QHCP_CONTENT}")
+
+
+file(READ "${QTHELP_DIR}/CMake.qhp" QHP_CONTENT)
+
+string(REPLACE
+ "<namespace>org.sphinx.cmake" "<namespace>org.cmake"
+ QHP_CONTENT "${QHP_CONTENT}"
+)
+
+file(WRITE "${QTHELP_DIR}/CMake.qhp" "${QHP_CONTENT}")
diff --git a/Utilities/Sphinx/static/cmake-favicon.ico b/Utilities/Sphinx/static/cmake-favicon.ico
new file mode 100644
index 0000000000..fce8f922fb
--- /dev/null
+++ b/Utilities/Sphinx/static/cmake-favicon.ico
Binary files differ
diff --git a/Utilities/Sphinx/static/cmake-logo-16.png b/Utilities/Sphinx/static/cmake-logo-16.png
new file mode 100644
index 0000000000..2039c25b04
--- /dev/null
+++ b/Utilities/Sphinx/static/cmake-logo-16.png
Binary files differ
diff --git a/Utilities/Sphinx/static/cmake.css b/Utilities/Sphinx/static/cmake.css
new file mode 100644
index 0000000000..2a326d47dd
--- /dev/null
+++ b/Utilities/Sphinx/static/cmake.css
@@ -0,0 +1,8 @@
+/* Import the Sphinx theme style. */
+@import url("default.css");
+
+/* Wrap sidebar content even within words so that long
+ document names do not escape sidebar borders. */
+div.sphinxsidebarwrapper {
+ word-wrap: break-word;
+}
diff --git a/Utilities/Sphinx/templates/layout.html b/Utilities/Sphinx/templates/layout.html
new file mode 100644
index 0000000000..1c5728c704
--- /dev/null
+++ b/Utilities/Sphinx/templates/layout.html
@@ -0,0 +1,19 @@
+{% extends "!layout.html" %}
+{% block rootrellink %}
+ <li>
+ <img src="{{ pathto('_static/cmake-logo-16.png', 1) }}" alt=""
+ style="vertical-align: middle; margin-top: -2px" />
+ </li>
+ <li>
+ <a href="http://www.cmake.org/">CMake</a>{{ reldelim1 }}
+ </li>
+ <li>
+ <a href="{{ pathto(master_doc) }}">{{ shorttitle|e }}</a>{{ reldelim1 }}
+ </li>
+{% endblock %}
+
+{# Put some context in the html title element. Workaround for #}
+{# https://bitbucket.org/birkenfeld/sphinx/issue/1492/qthelp-generate-html-title-element-should #}
+{% block htmltitle %}
+ <title>{{ title|striptags|e }} {{ "&mdash;"|safe }} {{ docstitle|e }}</title>
+{% endblock %}
diff --git a/Utilities/cmThirdParty.h.in b/Utilities/cmThirdParty.h.in
new file mode 100644
index 0000000000..b0b5779224
--- /dev/null
+++ b/Utilities/cmThirdParty.h.in
@@ -0,0 +1,24 @@
+/*============================================================================
+ 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 __cmThirdParty_h
+#define __cmThirdParty_h
+
+/* Whether CMake is using its own utility libraries. */
+#cmakedefine CMAKE_USE_SYSTEM_CURL
+#cmakedefine CMAKE_USE_SYSTEM_EXPAT
+#cmakedefine CMAKE_USE_SYSTEM_ZLIB
+#cmakedefine CMAKE_USE_SYSTEM_BZIP2
+#cmakedefine CMAKE_USE_SYSTEM_LIBARCHIVE
+#cmakedefine CMAKE_USE_SYSTEM_LIBLZMA
+#cmakedefine CTEST_USE_XMLRPC
+
+#endif
diff --git a/Utilities/cm_bzlib.h b/Utilities/cm_bzlib.h
new file mode 100644
index 0000000000..d1fffa1aa2
--- /dev/null
+++ b/Utilities/cm_bzlib.h
@@ -0,0 +1,23 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2012 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 __cm_bzlib_h
+#define __cm_bzlib_h
+
+/* Use the bzip2 library configured for CMake. */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_BZIP2
+# include <bzlib.h>
+#else
+# include <cmbzip2/bzlib.h>
+#endif
+
+#endif
diff --git a/Utilities/cm_curl.h b/Utilities/cm_curl.h
new file mode 100644
index 0000000000..43944a3f46
--- /dev/null
+++ b/Utilities/cm_curl.h
@@ -0,0 +1,23 @@
+/*============================================================================
+ 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 __cm_curl_h
+#define __cm_curl_h
+
+/* Use the curl library configured for CMake. */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_CURL
+# include <curl/curl.h>
+#else
+# include <cmcurl/curl/curl.h>
+#endif
+
+#endif
diff --git a/Utilities/cm_expat.h b/Utilities/cm_expat.h
new file mode 100644
index 0000000000..91f4a7b527
--- /dev/null
+++ b/Utilities/cm_expat.h
@@ -0,0 +1,23 @@
+/*============================================================================
+ 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 __cm_expat_h
+#define __cm_expat_h
+
+/* Use the expat library configured for CMake. */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_EXPAT
+# include <expat.h>
+#else
+# include <cmexpat/expat.h>
+#endif
+
+#endif
diff --git a/Utilities/cm_libarchive.h b/Utilities/cm_libarchive.h
new file mode 100644
index 0000000000..1469baeb46
--- /dev/null
+++ b/Utilities/cm_libarchive.h
@@ -0,0 +1,25 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2010 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 __cm_libarchive_h
+#define __cm_libarchive_h
+
+/* Use the libarchive configured for CMake. */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_LIBARCHIVE
+# include <archive.h>
+# include <archive_entry.h>
+#else
+# include <cmlibarchive/libarchive/archive.h>
+# include <cmlibarchive/libarchive/archive_entry.h>
+#endif
+
+#endif
diff --git a/Utilities/cm_lzma.h b/Utilities/cm_lzma.h
new file mode 100644
index 0000000000..c11c916f40
--- /dev/null
+++ b/Utilities/cm_lzma.h
@@ -0,0 +1,23 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 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 __cm_lzma_h
+#define __cm_lzma_h
+
+/* Use the liblzma configured for CMake. */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_LIBLZMA
+# include <lzma.h>
+#else
+# include <cmliblzma/liblzma/api/lzma.h>
+#endif
+
+#endif
diff --git a/Utilities/cm_xmlrpc.h b/Utilities/cm_xmlrpc.h
new file mode 100644
index 0000000000..a6b375da81
--- /dev/null
+++ b/Utilities/cm_xmlrpc.h
@@ -0,0 +1,22 @@
+/*============================================================================
+ 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 __cm_xmlrpc_h
+#define __cm_xmlrpc_h
+
+/* Use the xmlrpc library configured for CMake. */
+#include "cmThirdParty.h"
+#ifdef CTEST_USE_XMLRPC
+# include <xmlrpc.h>
+# include <xmlrpc_client.h>
+#endif
+
+#endif
diff --git a/Utilities/cm_zlib.h b/Utilities/cm_zlib.h
new file mode 100644
index 0000000000..fb5832e35b
--- /dev/null
+++ b/Utilities/cm_zlib.h
@@ -0,0 +1,23 @@
+/*============================================================================
+ 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 __cm_zlib_h
+#define __cm_zlib_h
+
+/* Use the zlib library configured for CMake. */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_ZLIB
+# include <zlib.h>
+#else
+# include <cmzlib/zlib.h>
+#endif
+
+#endif
diff --git a/Utilities/cmbzip2/CHANGES b/Utilities/cmbzip2/CHANGES
new file mode 100644
index 0000000000..6e4f65e2e0
--- /dev/null
+++ b/Utilities/cmbzip2/CHANGES
@@ -0,0 +1,319 @@
+ ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------
+
+
+0.9.0
+~~~~~
+First version.
+
+
+0.9.0a
+~~~~~~
+Removed 'ranlib' from Makefile, since most modern Unix-es
+don't need it, or even know about it.
+
+
+0.9.0b
+~~~~~~
+Fixed a problem with error reporting in bzip2.c. This does not effect
+the library in any way. Problem is: versions 0.9.0 and 0.9.0a (of the
+program proper) compress and decompress correctly, but give misleading
+error messages (internal panics) when an I/O error occurs, instead of
+reporting the problem correctly. This shouldn't give any data loss
+(as far as I can see), but is confusing.
+
+Made the inline declarations disappear for non-GCC compilers.
+
+
+0.9.0c
+~~~~~~
+Fixed some problems in the library pertaining to some boundary cases.
+This makes the library behave more correctly in those situations. The
+fixes apply only to features (calls and parameters) not used by
+bzip2.c, so the non-fixedness of them in previous versions has no
+effect on reliability of bzip2.c.
+
+In bzlib.c:
+ * made zero-length BZ_FLUSH work correctly in bzCompress().
+ * fixed bzWrite/bzRead to ignore zero-length requests.
+ * fixed bzread to correctly handle read requests after EOF.
+ * wrong parameter order in call to bzDecompressInit in
+ bzBuffToBuffDecompress. Fixed.
+
+In compress.c:
+ * changed setting of nGroups in sendMTFValues() so as to
+ do a bit better on small files. This _does_ effect
+ bzip2.c.
+
+
+0.9.5a
+~~~~~~
+Major change: add a fallback sorting algorithm (blocksort.c)
+to give reasonable behaviour even for very repetitive inputs.
+Nuked --repetitive-best and --repetitive-fast since they are
+no longer useful.
+
+Minor changes: mostly a whole bunch of small changes/
+bugfixes in the driver (bzip2.c). Changes pertaining to the
+user interface are:
+
+ allow decompression of symlink'd files to stdout
+ decompress/test files even without .bz2 extension
+ give more accurate error messages for I/O errors
+ when compressing/decompressing to stdout, don't catch control-C
+ read flags from BZIP2 and BZIP environment variables
+ decline to break hard links to a file unless forced with -f
+ allow -c flag even with no filenames
+ preserve file ownerships as far as possible
+ make -s -1 give the expected block size (100k)
+ add a flag -q --quiet to suppress nonessential warnings
+ stop decoding flags after --, so files beginning in - can be handled
+ resolved inconsistent naming: bzcat or bz2cat ?
+ bzip2 --help now returns 0
+
+Programming-level changes are:
+
+ fixed syntax error in GET_LL4 for Borland C++ 5.02
+ let bzBuffToBuffDecompress return BZ_DATA_ERROR{_MAGIC}
+ fix overshoot of mode-string end in bzopen_or_bzdopen
+ wrapped bzlib.h in #ifdef __cplusplus ... extern "C" { ... }
+ close file handles under all error conditions
+ added minor mods so it compiles with DJGPP out of the box
+ fixed Makefile so it doesn't give problems with BSD make
+ fix uninitialised memory reads in dlltest.c
+
+0.9.5b
+~~~~~~
+Open stdin/stdout in binary mode for DJGPP.
+
+0.9.5c
+~~~~~~
+Changed BZ_N_OVERSHOOT to be ... + 2 instead of ... + 1. The + 1
+version could cause the sorted order to be wrong in some extremely
+obscure cases. Also changed setting of quadrant in blocksort.c.
+
+0.9.5d
+~~~~~~
+The only functional change is to make bzlibVersion() in the library
+return the correct string. This has no effect whatsoever on the
+functioning of the bzip2 program or library. Added a couple of casts
+so the library compiles without warnings at level 3 in MS Visual
+Studio 6.0. Included a Y2K statement in the file Y2K_INFO. All other
+changes are minor documentation changes.
+
+1.0
+~~~
+Several minor bugfixes and enhancements:
+
+* Large file support. The library uses 64-bit counters to
+ count the volume of data passing through it. bzip2.c
+ is now compiled with -D_FILE_OFFSET_BITS=64 to get large
+ file support from the C library. -v correctly prints out
+ file sizes greater than 4 gigabytes. All these changes have
+ been made without assuming a 64-bit platform or a C compiler
+ which supports 64-bit ints, so, except for the C library
+ aspect, they are fully portable.
+
+* Decompression robustness. The library/program should be
+ robust to any corruption of compressed data, detecting and
+ handling _all_ corruption, instead of merely relying on
+ the CRCs. What this means is that the program should
+ never crash, given corrupted data, and the library should
+ always return BZ_DATA_ERROR.
+
+* Fixed an obscure race-condition bug only ever observed on
+ Solaris, in which, if you were very unlucky and issued
+ control-C at exactly the wrong time, both input and output
+ files would be deleted.
+
+* Don't run out of file handles on test/decompression when
+ large numbers of files have invalid magic numbers.
+
+* Avoid library namespace pollution. Prefix all exported
+ symbols with BZ2_.
+
+* Minor sorting enhancements from my DCC2000 paper.
+
+* Advance the version number to 1.0, so as to counteract the
+ (false-in-this-case) impression some people have that programs
+ with version numbers less than 1.0 are in some way, experimental,
+ pre-release versions.
+
+* Create an initial Makefile-libbz2_so to build a shared library.
+ Yes, I know I should really use libtool et al ...
+
+* Make the program exit with 2 instead of 0 when decompression
+ fails due to a bad magic number (ie, an invalid bzip2 header).
+ Also exit with 1 (as the manual claims :-) whenever a diagnostic
+ message would have been printed AND the corresponding operation
+ is aborted, for example
+ bzip2: Output file xx already exists.
+ When a diagnostic message is printed but the operation is not
+ aborted, for example
+ bzip2: Can't guess original name for wurble -- using wurble.out
+ then the exit value 0 is returned, unless some other problem is
+ also detected.
+
+ I think it corresponds more closely to what the manual claims now.
+
+
+1.0.1
+~~~~~
+* Modified dlltest.c so it uses the new BZ2_ naming scheme.
+* Modified makefile-msc to fix minor build probs on Win2k.
+* Updated README.COMPILATION.PROBLEMS.
+
+There are no functionality changes or bug fixes relative to version
+1.0.0. This is just a documentation update + a fix for minor Win32
+build problems. For almost everyone, upgrading from 1.0.0 to 1.0.1 is
+utterly pointless. Don't bother.
+
+
+1.0.2
+~~~~~
+A bug fix release, addressing various minor issues which have appeared
+in the 18 or so months since 1.0.1 was released. Most of the fixes
+are to do with file-handling or documentation bugs. To the best of my
+knowledge, there have been no data-loss-causing bugs reported in the
+compression/decompression engine of 1.0.0 or 1.0.1.
+
+Note that this release does not improve the rather crude build system
+for Unix platforms. The general plan here is to autoconfiscate/
+libtoolise 1.0.2 soon after release, and release the result as 1.1.0
+or perhaps 1.2.0. That, however, is still just a plan at this point.
+
+Here are the changes in 1.0.2. Bug-reporters and/or patch-senders in
+parentheses.
+
+* Fix an infinite segfault loop in 1.0.1 when a directory is
+ encountered in -f (force) mode.
+ (Trond Eivind Glomsrod, Nicholas Nethercote, Volker Schmidt)
+
+* Avoid double fclose() of output file on certain I/O error paths.
+ (Solar Designer)
+
+* Don't fail with internal error 1007 when fed a long stream (> 48MB)
+ of byte 251. Also print useful message suggesting that 1007s may be
+ caused by bad memory.
+ (noticed by Juan Pedro Vallejo, fixed by me)
+
+* Fix uninitialised variable silly bug in demo prog dlltest.c.
+ (Jorj Bauer)
+
+* Remove 512-MB limitation on recovered file size for bzip2recover
+ on selected platforms which support 64-bit ints. At the moment
+ all GCC supported platforms, and Win32.
+ (me, Alson van der Meulen)
+
+* Hard-code header byte values, to give correct operation on platforms
+ using EBCDIC as their native character set (IBM's OS/390).
+ (Leland Lucius)
+
+* Copy file access times correctly.
+ (Marty Leisner)
+
+* Add distclean and check targets to Makefile.
+ (Michael Carmack)
+
+* Parameterise use of ar and ranlib in Makefile. Also add $(LDFLAGS).
+ (Rich Ireland, Bo Thorsen)
+
+* Pass -p (create parent dirs as needed) to mkdir during make install.
+ (Jeremy Fusco)
+
+* Dereference symlinks when copying file permissions in -f mode.
+ (Volker Schmidt)
+
+* Majorly simplify implementation of uInt64_qrm10.
+ (Bo Lindbergh)
+
+* Check the input file still exists before deleting the output one,
+ when aborting in cleanUpAndFail().
+ (Joerg Prante, Robert Linden, Matthias Krings)
+
+Also a bunch of patches courtesy of Philippe Troin, the Debian maintainer
+of bzip2:
+
+* Wrapper scripts (with manpages): bzdiff, bzgrep, bzmore.
+
+* Spelling changes and minor enhancements in bzip2.1.
+
+* Avoid race condition between creating the output file and setting its
+ interim permissions safely, by using fopen_output_safely().
+ No changes to bzip2recover since there is no issue with file
+ permissions there.
+
+* do not print senseless report with -v when compressing an empty
+ file.
+
+* bzcat -f works on non-bzip2 files.
+
+* do not try to escape shell meta-characters on unix (the shell takes
+ care of these).
+
+* added --fast and --best aliases for -1 -9 for gzip compatibility.
+
+
+1.0.3 (15 Feb 05)
+~~~~~~~~~~~~~~~~~
+Fixes some minor bugs since the last version, 1.0.2.
+
+* Further robustification against corrupted compressed data.
+ There are currently no known bitstreams which can cause the
+ decompressor to crash, loop or access memory which does not
+ belong to it. If you are using bzip2 or the library to
+ decompress bitstreams from untrusted sources, an upgrade
+ to 1.0.3 is recommended. This fixes CAN-2005-1260.
+
+* The documentation has been converted to XML, from which html
+ and pdf can be derived.
+
+* Various minor bugs in the documentation have been fixed.
+
+* Fixes for various compilation warnings with newer versions of
+ gcc, and on 64-bit platforms.
+
+* The BZ_NO_STDIO cpp symbol was not properly observed in 1.0.2.
+ This has been fixed.
+
+
+1.0.4 (20 Dec 06)
+~~~~~~~~~~~~~~~~~
+Fixes some minor bugs since the last version, 1.0.3.
+
+* Fix file permissions race problem (CAN-2005-0953).
+
+* Avoid possible segfault in BZ2_bzclose. From Coverity's NetBSD
+ scan.
+
+* 'const'/prototype cleanups in the C code.
+
+* Change default install location to /usr/local, and handle multiple
+ 'make install's without error.
+
+* Sanitise file names more carefully in bzgrep. Fixes CAN-2005-0758
+ to the extent that applies to bzgrep.
+
+* Use 'mktemp' rather than 'tempfile' in bzdiff.
+
+* Tighten up a couple of assertions in blocksort.c following automated
+ analysis.
+
+* Fix minor doc/comment bugs.
+
+
+1.0.5 (10 Dec 07)
+~~~~~~~~~~~~~~~~~
+Security fix only. Fixes CERT-FI 20469 as it applies to bzip2.
+
diff --git a/Utilities/cmbzip2/CMakeLists.txt b/Utilities/cmbzip2/CMakeLists.txt
new file mode 100644
index 0000000000..2aff69c08b
--- /dev/null
+++ b/Utilities/cmbzip2/CMakeLists.txt
@@ -0,0 +1,4 @@
+project(bzip2)
+add_definitions(-D_FILE_OFFSET_BITS=64)
+add_library(cmbzip2
+ blocksort.c huffman.c crctable.c randtable.c compress.c decompress.c bzlib.c)
diff --git a/Utilities/cmbzip2/LICENSE b/Utilities/cmbzip2/LICENSE
new file mode 100644
index 0000000000..f420cffb67
--- /dev/null
+++ b/Utilities/cmbzip2/LICENSE
@@ -0,0 +1,42 @@
+
+--------------------------------------------------------------------------
+
+This program, "bzip2", the associated library "libbzip2", and all
+documentation, are copyright (C) 1996-2007 Julian R Seward. 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. The origin of this software must not be misrepresented; you must
+ not claim that you wrote the original software. If you use this
+ software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+3. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+
+4. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+
+Julian Seward, jseward@bzip.org
+bzip2/libbzip2 version 1.0.5 of 10 December 2007
+
+--------------------------------------------------------------------------
diff --git a/Utilities/cmbzip2/Makefile-libbz2_so b/Utilities/cmbzip2/Makefile-libbz2_so
new file mode 100644
index 0000000000..83708871c2
--- /dev/null
+++ b/Utilities/cmbzip2/Makefile-libbz2_so
@@ -0,0 +1,59 @@
+
+# This Makefile builds a shared version of the library,
+# libbz2.so.1.0.4, with soname libbz2.so.1.0,
+# at least on x86-Linux (RedHat 7.2),
+# with gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98).
+# Please see the README file for some important info
+# about building the library like this.
+
+# ------------------------------------------------------------------
+# This file is part of bzip2/libbzip2, a program and library for
+# lossless, block-sorting data compression.
+#
+# bzip2/libbzip2 version 1.0.5 of 10 December 2007
+# Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+#
+# Please read the WARNING, DISCLAIMER and PATENTS sections in the
+# README file.
+#
+# This program is released under the terms of the license contained
+# in the file LICENSE.
+# ------------------------------------------------------------------
+
+
+SHELL=/bin/sh
+CC=gcc
+BIGFILES=-D_FILE_OFFSET_BITS=64
+CFLAGS=-fpic -fPIC -Wall -Winline -O2 -g $(BIGFILES)
+
+OBJS= blocksort.o \
+ huffman.o \
+ crctable.o \
+ randtable.o \
+ compress.o \
+ decompress.o \
+ bzlib.o
+
+all: $(OBJS)
+ $(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.4 $(OBJS)
+ $(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.4
+ rm -f libbz2.so.1.0
+ ln -s libbz2.so.1.0.4 libbz2.so.1.0
+
+clean:
+ rm -f $(OBJS) bzip2.o libbz2.so.1.0.4 libbz2.so.1.0 bzip2-shared
+
+blocksort.o: blocksort.c
+ $(CC) $(CFLAGS) -c blocksort.c
+huffman.o: huffman.c
+ $(CC) $(CFLAGS) -c huffman.c
+crctable.o: crctable.c
+ $(CC) $(CFLAGS) -c crctable.c
+randtable.o: randtable.c
+ $(CC) $(CFLAGS) -c randtable.c
+compress.o: compress.c
+ $(CC) $(CFLAGS) -c compress.c
+decompress.o: decompress.c
+ $(CC) $(CFLAGS) -c decompress.c
+bzlib.o: bzlib.c
+ $(CC) $(CFLAGS) -c bzlib.c
diff --git a/Utilities/cmbzip2/README b/Utilities/cmbzip2/README
new file mode 100644
index 0000000000..e17a84e049
--- /dev/null
+++ b/Utilities/cmbzip2/README
@@ -0,0 +1,210 @@
+
+This is the README for bzip2/libzip2.
+This version is fully compatible with the previous public releases.
+
+------------------------------------------------------------------
+This file is part of bzip2/libbzip2, a program and library for
+lossless, block-sorting data compression.
+
+bzip2/libbzip2 version 1.0.5 of 10 December 2007
+Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+Please read the WARNING, DISCLAIMER and PATENTS sections in this file.
+
+This program is released under the terms of the license contained
+in the file LICENSE.
+------------------------------------------------------------------
+
+Complete documentation is available in Postscript form (manual.ps),
+PDF (manual.pdf) or html (manual.html). A plain-text version of the
+manual page is available as bzip2.txt.
+
+
+HOW TO BUILD -- UNIX
+
+Type 'make'. This builds the library libbz2.a and then the programs
+bzip2 and bzip2recover. Six self-tests are run. If the self-tests
+complete ok, carry on to installation:
+
+To install in /usr/local/bin, /usr/local/lib, /usr/local/man and
+/usr/local/include, type
+
+ make install
+
+To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type
+
+ make install PREFIX=/xxx/yyy
+
+If you are (justifiably) paranoid and want to see what 'make install'
+is going to do, you can first do
+
+ make -n install or
+ make -n install PREFIX=/xxx/yyy respectively.
+
+The -n instructs make to show the commands it would execute, but not
+actually execute them.
+
+
+HOW TO BUILD -- UNIX, shared library libbz2.so.
+
+Do 'make -f Makefile-libbz2_so'. This Makefile seems to work for
+Linux-ELF (RedHat 7.2 on an x86 box), with gcc. I make no claims
+that it works for any other platform, though I suspect it probably
+will work for most platforms employing both ELF and gcc.
+
+bzip2-shared, a client of the shared library, is also built, but not
+self-tested. So I suggest you also build using the normal Makefile,
+since that conducts a self-test. A second reason to prefer the
+version statically linked to the library is that, on x86 platforms,
+building shared objects makes a valuable register (%ebx) unavailable
+to gcc, resulting in a slowdown of 10%-20%, at least for bzip2.
+
+Important note for people upgrading .so's from 0.9.0/0.9.5 to version
+1.0.X. All the functions in the library have been renamed, from (eg)
+bzCompress to BZ2_bzCompress, to avoid namespace pollution.
+Unfortunately this means that the libbz2.so created by
+Makefile-libbz2_so will not work with any program which used an older
+version of the library. I do encourage library clients to make the
+effort to upgrade to use version 1.0, since it is both faster and more
+robust than previous versions.
+
+
+HOW TO BUILD -- Windows 95, NT, DOS, Mac, etc.
+
+It's difficult for me to support compilation on all these platforms.
+My approach is to collect binaries for these platforms, and put them
+on the master web site (http://www.bzip.org). Look there. However
+(FWIW), bzip2-1.0.X is very standard ANSI C and should compile
+unmodified with MS Visual C. If you have difficulties building, you
+might want to read README.COMPILATION.PROBLEMS.
+
+At least using MS Visual C++ 6, you can build from the unmodified
+sources by issuing, in a command shell:
+
+ nmake -f makefile.msc
+
+(you may need to first run the MSVC-provided script VCVARS32.BAT
+ so as to set up paths to the MSVC tools correctly).
+
+
+VALIDATION
+
+Correct operation, in the sense that a compressed file can always be
+decompressed to reproduce the original, is obviously of paramount
+importance. To validate bzip2, I used a modified version of Mark
+Nelson's churn program. Churn is an automated test driver which
+recursively traverses a directory structure, using bzip2 to compress
+and then decompress each file it encounters, and checking that the
+decompressed data is the same as the original.
+
+
+
+Please read and be aware of the following:
+
+WARNING:
+
+ This program and library (attempts to) compress data by
+ performing several non-trivial transformations on it.
+ Unless you are 100% familiar with *all* the algorithms
+ contained herein, and with the consequences of modifying them,
+ you should NOT meddle with the compression or decompression
+ machinery. Incorrect changes can and very likely *will*
+ lead to disastrous loss of data.
+
+
+DISCLAIMER:
+
+ I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
+ USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED.
+
+ Every compression of a file implies an assumption that the
+ compressed file can be decompressed to reproduce the original.
+ Great efforts in design, coding and testing have been made to
+ ensure that this program works correctly. However, the complexity
+ of the algorithms, and, in particular, the presence of various
+ special cases in the code which occur with very low but non-zero
+ probability make it impossible to rule out the possibility of bugs
+ remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS
+ PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
+ SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
+
+ That is not to say this program is inherently unreliable.
+ Indeed, I very much hope the opposite is true. bzip2/libbzip2
+ has been carefully constructed and extensively tested.
+
+
+PATENTS:
+
+ To the best of my knowledge, bzip2/libbzip2 does not use any
+ patented algorithms. However, I do not have the resources
+ to carry out a patent search. Therefore I cannot give any
+ guarantee of the above statement.
+
+
+
+WHAT'S NEW IN 0.9.0 (as compared to 0.1pl2) ?
+
+ * Approx 10% faster compression, 30% faster decompression
+ * -t (test mode) is a lot quicker
+ * Can decompress concatenated compressed files
+ * Programming interface, so programs can directly read/write .bz2 files
+ * Less restrictive (BSD-style) licensing
+ * Flag handling more compatible with GNU gzip
+ * Much more documentation, i.e., a proper user manual
+ * Hopefully, improved portability (at least of the library)
+
+WHAT'S NEW IN 0.9.5 ?
+
+ * Compression speed is much less sensitive to the input
+ data than in previous versions. Specifically, the very
+ slow performance caused by repetitive data is fixed.
+ * Many small improvements in file and flag handling.
+ * A Y2K statement.
+
+WHAT'S NEW IN 1.0.0 ?
+
+ See the CHANGES file.
+
+WHAT'S NEW IN 1.0.2 ?
+
+ See the CHANGES file.
+
+WHAT'S NEW IN 1.0.3 ?
+
+ See the CHANGES file.
+
+WHAT'S NEW IN 1.0.4 ?
+
+ See the CHANGES file.
+
+WHAT'S NEW IN 1.0.5 ?
+
+ See the CHANGES file.
+
+
+I hope you find bzip2 useful. Feel free to contact me at
+ jseward@bzip.org
+if you have any suggestions or queries. Many people mailed me with
+comments, suggestions and patches after the releases of bzip-0.15,
+bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
+1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this
+feedback. I thank you for your comments.
+
+bzip2's "home" is http://www.bzip.org/
+
+Julian Seward
+jseward@bzip.org
+Cambridge, UK.
+
+18 July 1996 (version 0.15)
+25 August 1996 (version 0.21)
+ 7 August 1997 (bzip2, version 0.1)
+29 August 1997 (bzip2, version 0.1pl2)
+23 August 1998 (bzip2, version 0.9.0)
+ 8 June 1999 (bzip2, version 0.9.5)
+ 4 Sept 1999 (bzip2, version 0.9.5d)
+ 5 May 2000 (bzip2, version 1.0pre8)
+30 December 2001 (bzip2, version 1.0.2pre1)
+15 February 2005 (bzip2, version 1.0.3)
+20 December 2006 (bzip2, version 1.0.4)
+10 December 2007 (bzip2, version 1.0.5)
diff --git a/Utilities/cmbzip2/README.COMPILATION.PROBLEMS b/Utilities/cmbzip2/README.COMPILATION.PROBLEMS
new file mode 100644
index 0000000000..22b95c6cb6
--- /dev/null
+++ b/Utilities/cmbzip2/README.COMPILATION.PROBLEMS
@@ -0,0 +1,58 @@
+------------------------------------------------------------------
+This file is part of bzip2/libbzip2, a program and library for
+lossless, block-sorting data compression.
+
+bzip2/libbzip2 version 1.0.5 of 10 December 2007
+Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+Please read the WARNING, DISCLAIMER and PATENTS sections in the
+README file.
+
+This program is released under the terms of the license contained
+in the file LICENSE.
+------------------------------------------------------------------
+
+bzip2-1.0.5 should compile without problems on the vast majority of
+platforms. Using the supplied Makefile, I've built and tested it
+myself for x86-linux and amd64-linux. With makefile.msc, Visual C++
+6.0 and nmake, you can build a native Win32 version too. Large file
+support seems to work correctly on at least on amd64-linux.
+
+When I say "large file" I mean a file of size 2,147,483,648 (2^31)
+bytes or above. Many older OSs can't handle files above this size,
+but many newer ones can. Large files are pretty huge -- most files
+you'll encounter are not Large Files.
+
+Early versions of bzip2 (0.1, 0.9.0, 0.9.5) compiled on a wide variety
+of platforms without difficulty, and I hope this version will continue
+in that tradition. However, in order to support large files, I've had
+to include the define -D_FILE_OFFSET_BITS=64 in the Makefile. This
+can cause problems.
+
+The technique of adding -D_FILE_OFFSET_BITS=64 to get large file
+support is, as far as I know, the Recommended Way to get correct large
+file support. For more details, see the Large File Support
+Specification, published by the Large File Summit, at
+
+ http://ftp.sas.com/standards/large.file
+
+As a general comment, if you get compilation errors which you think
+are related to large file support, try removing the above define from
+the Makefile, ie, delete the line
+
+ BIGFILES=-D_FILE_OFFSET_BITS=64
+
+from the Makefile, and do 'make clean ; make'. This will give you a
+version of bzip2 without large file support, which, for most
+applications, is probably not a problem.
+
+Alternatively, try some of the platform-specific hints listed below.
+
+You can use the spewG.c program to generate huge files to test bzip2's
+large file support, if you are feeling paranoid. Be aware though that
+any compilation problems which affect bzip2 will also affect spewG.c,
+alas.
+
+AIX: I have reports that for large file support, you need to specify
+-D_LARGE_FILES rather than -D_FILE_OFFSET_BITS=64. I have not tested
+this myself.
diff --git a/Utilities/cmbzip2/README.XML.STUFF b/Utilities/cmbzip2/README.XML.STUFF
new file mode 100644
index 0000000000..1a5b4c55a5
--- /dev/null
+++ b/Utilities/cmbzip2/README.XML.STUFF
@@ -0,0 +1,45 @@
+ ----------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ----------------------------------------------------------------
+
+The script xmlproc.sh takes an xml file as input,
+and processes it to create .pdf, .html or .ps output.
+It uses format.pl, a perl script to format <pre> blocks nicely,
+ and add CDATA tags so writers do not have to use eg. &lt;
+
+The file "entities.xml" must be edited to reflect current
+version, year, etc.
+
+
+Usage:
+
+ ./xmlproc.sh -v manual.xml
+ Validates an xml file to ensure no dtd-compliance errors
+
+ ./xmlproc.sh -html manual.xml
+ Output: manual.html
+
+ ./xmlproc.sh -pdf manual.xml
+ Output: manual.pdf
+
+ ./xmlproc.sh -ps manual.xml
+ Output: manual.ps
+
+
+Notum bene:
+- pdfxmltex barfs if given a filename with an underscore in it
+
+- xmltex won't work yet - there's a bug in passivetex
+ which we are all waiting for Sebastian to fix.
+ So we are going the xml -> pdf -> ps route for the time being,
+ using pdfxmltex.
diff --git a/Utilities/cmbzip2/blocksort.c b/Utilities/cmbzip2/blocksort.c
new file mode 100644
index 0000000000..95adb5ef3d
--- /dev/null
+++ b/Utilities/cmbzip2/blocksort.c
@@ -0,0 +1,1094 @@
+
+/*-------------------------------------------------------------*/
+/*--- Block sorting machinery ---*/
+/*--- blocksort.c ---*/
+/*-------------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#include "bzlib_private.h"
+
+/*---------------------------------------------*/
+/*--- Fallback O(N log(N)^2) sorting ---*/
+/*--- algorithm, for repetitive blocks ---*/
+/*---------------------------------------------*/
+
+/*---------------------------------------------*/
+static
+__inline__
+void fallbackSimpleSort ( UInt32* fmap,
+ UInt32* eclass,
+ Int32 lo,
+ Int32 hi )
+{
+ Int32 i, j, tmp;
+ UInt32 ec_tmp;
+
+ if (lo == hi) return;
+
+ if (hi - lo > 3) {
+ for ( i = hi-4; i >= lo; i-- ) {
+ tmp = fmap[i];
+ ec_tmp = eclass[tmp];
+ for ( j = i+4; j <= hi && ec_tmp > eclass[fmap[j]]; j += 4 )
+ fmap[j-4] = fmap[j];
+ fmap[j-4] = tmp;
+ }
+ }
+
+ for ( i = hi-1; i >= lo; i-- ) {
+ tmp = fmap[i];
+ ec_tmp = eclass[tmp];
+ for ( j = i+1; j <= hi && ec_tmp > eclass[fmap[j]]; j++ )
+ fmap[j-1] = fmap[j];
+ fmap[j-1] = tmp;
+ }
+}
+
+
+/*---------------------------------------------*/
+#define fswap(zz1, zz2) \
+ { Int32 zztmp = zz1; zz1 = zz2; zz2 = zztmp; }
+
+#define fvswap(zzp1, zzp2, zzn) \
+{ \
+ Int32 yyp1 = (zzp1); \
+ Int32 yyp2 = (zzp2); \
+ Int32 yyn = (zzn); \
+ while (yyn > 0) { \
+ fswap(fmap[yyp1], fmap[yyp2]); \
+ yyp1++; yyp2++; yyn--; \
+ } \
+}
+
+
+#define fmin(a,b) ((a) < (b)) ? (a) : (b)
+
+#define fpush(lz,hz) { stackLo[sp] = lz; \
+ stackHi[sp] = hz; \
+ sp++; }
+
+#define fpop(lz,hz) { sp--; \
+ lz = stackLo[sp]; \
+ hz = stackHi[sp]; }
+
+#define FALLBACK_QSORT_SMALL_THRESH 10
+#define FALLBACK_QSORT_STACK_SIZE 100
+
+
+static
+void fallbackQSort3 ( UInt32* fmap,
+ UInt32* eclass,
+ Int32 loSt,
+ Int32 hiSt )
+{
+ Int32 unLo, unHi, ltLo, gtHi, n, m;
+ Int32 sp, lo, hi;
+ UInt32 med, r, r3;
+ Int32 stackLo[FALLBACK_QSORT_STACK_SIZE];
+ Int32 stackHi[FALLBACK_QSORT_STACK_SIZE];
+
+ r = 0;
+
+ sp = 0;
+ fpush ( loSt, hiSt );
+
+ while (sp > 0) {
+
+ AssertH ( sp < FALLBACK_QSORT_STACK_SIZE - 1, 1004 );
+
+ fpop ( lo, hi );
+ if (hi - lo < FALLBACK_QSORT_SMALL_THRESH) {
+ fallbackSimpleSort ( fmap, eclass, lo, hi );
+ continue;
+ }
+
+ /* Random partitioning. Median of 3 sometimes fails to
+ avoid bad cases. Median of 9 seems to help but
+ looks rather expensive. This too seems to work but
+ is cheaper. Guidance for the magic constants
+ 7621 and 32768 is taken from Sedgewick's algorithms
+ book, chapter 35.
+ */
+ r = ((r * 7621) + 1) % 32768;
+ r3 = r % 3;
+ if (r3 == 0) med = eclass[fmap[lo]]; else
+ if (r3 == 1) med = eclass[fmap[(lo+hi)>>1]]; else
+ med = eclass[fmap[hi]];
+
+ unLo = ltLo = lo;
+ unHi = gtHi = hi;
+
+ while (1) {
+ while (1) {
+ if (unLo > unHi) break;
+ n = (Int32)eclass[fmap[unLo]] - (Int32)med;
+ if (n == 0) {
+ fswap(fmap[unLo], fmap[ltLo]);
+ ltLo++; unLo++;
+ continue;
+ };
+ if (n > 0) break;
+ unLo++;
+ }
+ while (1) {
+ if (unLo > unHi) break;
+ n = (Int32)eclass[fmap[unHi]] - (Int32)med;
+ if (n == 0) {
+ fswap(fmap[unHi], fmap[gtHi]);
+ gtHi--; unHi--;
+ continue;
+ };
+ if (n < 0) break;
+ unHi--;
+ }
+ if (unLo > unHi) break;
+ fswap(fmap[unLo], fmap[unHi]); unLo++; unHi--;
+ }
+
+ AssertD ( unHi == unLo-1, "fallbackQSort3(2)" );
+
+ if (gtHi < ltLo) continue;
+
+ n = fmin(ltLo-lo, unLo-ltLo); fvswap(lo, unLo-n, n);
+ m = fmin(hi-gtHi, gtHi-unHi); fvswap(unLo, hi-m+1, m);
+
+ n = lo + unLo - ltLo - 1;
+ m = hi - (gtHi - unHi) + 1;
+
+ if (n - lo > hi - m) {
+ fpush ( lo, n );
+ fpush ( m, hi );
+ } else {
+ fpush ( m, hi );
+ fpush ( lo, n );
+ }
+ }
+}
+
+#undef fmin
+#undef fpush
+#undef fpop
+#undef fswap
+#undef fvswap
+#undef FALLBACK_QSORT_SMALL_THRESH
+#undef FALLBACK_QSORT_STACK_SIZE
+
+
+/*---------------------------------------------*/
+/* Pre:
+ nblock > 0
+ eclass exists for [0 .. nblock-1]
+ ((UChar*)eclass) [0 .. nblock-1] holds block
+ ptr exists for [0 .. nblock-1]
+
+ Post:
+ ((UChar*)eclass) [0 .. nblock-1] holds block
+ All other areas of eclass destroyed
+ fmap [0 .. nblock-1] holds sorted order
+ bhtab [ 0 .. 2+(nblock/32) ] destroyed
+*/
+
+#define SET_BH(zz) bhtab[(zz) >> 5] |= (1 << ((zz) & 31))
+#define CLEAR_BH(zz) bhtab[(zz) >> 5] &= ~(1 << ((zz) & 31))
+#define ISSET_BH(zz) (bhtab[(zz) >> 5] & (1 << ((zz) & 31)))
+#define WORD_BH(zz) bhtab[(zz) >> 5]
+#define UNALIGNED_BH(zz) ((zz) & 0x01f)
+
+static
+void fallbackSort ( UInt32* fmap,
+ UInt32* eclass,
+ UInt32* bhtab,
+ Int32 nblock,
+ Int32 verb )
+{
+ Int32 ftab[257];
+ Int32 ftabCopy[256];
+ Int32 H, i, j, k, l, r, cc, cc1;
+ Int32 nNotDone;
+ Int32 nBhtab;
+ UChar* eclass8 = (UChar*)eclass;
+
+ /*--
+ Initial 1-char radix sort to generate
+ initial fmap and initial BH bits.
+ --*/
+ if (verb >= 4)
+ VPrintf0 ( " bucket sorting ...\n" );
+ for (i = 0; i < 257; i++) ftab[i] = 0;
+ for (i = 0; i < nblock; i++) ftab[eclass8[i]]++;
+ for (i = 0; i < 256; i++) ftabCopy[i] = ftab[i];
+ for (i = 1; i < 257; i++) ftab[i] += ftab[i-1];
+
+ for (i = 0; i < nblock; i++) {
+ j = eclass8[i];
+ k = ftab[j] - 1;
+ ftab[j] = k;
+ fmap[k] = i;
+ }
+
+ nBhtab = 2 + (nblock / 32);
+ for (i = 0; i < nBhtab; i++) bhtab[i] = 0;
+ for (i = 0; i < 256; i++) SET_BH(ftab[i]);
+
+ /*--
+ Inductively refine the buckets. Kind-of an
+ "exponential radix sort" (!), inspired by the
+ Manber-Myers suffix array construction algorithm.
+ --*/
+
+ /*-- set sentinel bits for block-end detection --*/
+ for (i = 0; i < 32; i++) {
+ SET_BH(nblock + 2*i);
+ CLEAR_BH(nblock + 2*i + 1);
+ }
+
+ /*-- the log(N) loop --*/
+ H = 1;
+ while (1) {
+
+ if (verb >= 4)
+ VPrintf1 ( " depth %6d has ", H );
+
+ j = 0;
+ for (i = 0; i < nblock; i++) {
+ if (ISSET_BH(i)) j = i;
+ k = fmap[i] - H; if (k < 0) k += nblock;
+ eclass[k] = j;
+ }
+
+ nNotDone = 0;
+ r = -1;
+ while (1) {
+
+ /*-- find the next non-singleton bucket --*/
+ k = r + 1;
+ while (ISSET_BH(k) && UNALIGNED_BH(k)) k++;
+ if (ISSET_BH(k)) {
+ while (WORD_BH(k) == 0xffffffff) k += 32;
+ while (ISSET_BH(k)) k++;
+ }
+ l = k - 1;
+ if (l >= nblock) break;
+ while (!ISSET_BH(k) && UNALIGNED_BH(k)) k++;
+ if (!ISSET_BH(k)) {
+ while (WORD_BH(k) == 0x00000000) k += 32;
+ while (!ISSET_BH(k)) k++;
+ }
+ r = k - 1;
+ if (r >= nblock) break;
+
+ /*-- now [l, r] bracket current bucket --*/
+ if (r > l) {
+ nNotDone += (r - l + 1);
+ fallbackQSort3 ( fmap, eclass, l, r );
+
+ /*-- scan bucket and generate header bits-- */
+ cc = -1;
+ for (i = l; i <= r; i++) {
+ cc1 = eclass[fmap[i]];
+ if (cc != cc1) { SET_BH(i); cc = cc1; };
+ }
+ }
+ }
+
+ if (verb >= 4)
+ VPrintf1 ( "%6d unresolved strings\n", nNotDone );
+
+ H *= 2;
+ if (H > nblock || nNotDone == 0) break;
+ }
+
+ /*--
+ Reconstruct the original block in
+ eclass8 [0 .. nblock-1], since the
+ previous phase destroyed it.
+ --*/
+ if (verb >= 4)
+ VPrintf0 ( " reconstructing block ...\n" );
+ j = 0;
+ for (i = 0; i < nblock; i++) {
+ while (ftabCopy[j] == 0) j++;
+ ftabCopy[j]--;
+ eclass8[fmap[i]] = (UChar)j;
+ }
+ AssertH ( j < 256, 1005 );
+}
+
+#undef SET_BH
+#undef CLEAR_BH
+#undef ISSET_BH
+#undef WORD_BH
+#undef UNALIGNED_BH
+
+
+/*---------------------------------------------*/
+/*--- The main, O(N^2 log(N)) sorting ---*/
+/*--- algorithm. Faster for "normal" ---*/
+/*--- non-repetitive blocks. ---*/
+/*---------------------------------------------*/
+
+/*---------------------------------------------*/
+static
+__inline__
+Bool mainGtU ( UInt32 i1,
+ UInt32 i2,
+ UChar* block,
+ UInt16* quadrant,
+ UInt32 nblock,
+ Int32* budget )
+{
+ Int32 k;
+ UChar c1, c2;
+ UInt16 s1, s2;
+
+ AssertD ( i1 != i2, "mainGtU" );
+ /* 1 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 2 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 3 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 4 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 5 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 6 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 7 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 8 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 9 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 10 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 11 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+ /* 12 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ i1++; i2++;
+
+ k = nblock + 8;
+
+ do {
+ /* 1 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ s1 = quadrant[i1]; s2 = quadrant[i2];
+ if (s1 != s2) return (s1 > s2);
+ i1++; i2++;
+ /* 2 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ s1 = quadrant[i1]; s2 = quadrant[i2];
+ if (s1 != s2) return (s1 > s2);
+ i1++; i2++;
+ /* 3 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ s1 = quadrant[i1]; s2 = quadrant[i2];
+ if (s1 != s2) return (s1 > s2);
+ i1++; i2++;
+ /* 4 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ s1 = quadrant[i1]; s2 = quadrant[i2];
+ if (s1 != s2) return (s1 > s2);
+ i1++; i2++;
+ /* 5 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ s1 = quadrant[i1]; s2 = quadrant[i2];
+ if (s1 != s2) return (s1 > s2);
+ i1++; i2++;
+ /* 6 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ s1 = quadrant[i1]; s2 = quadrant[i2];
+ if (s1 != s2) return (s1 > s2);
+ i1++; i2++;
+ /* 7 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ s1 = quadrant[i1]; s2 = quadrant[i2];
+ if (s1 != s2) return (s1 > s2);
+ i1++; i2++;
+ /* 8 */
+ c1 = block[i1]; c2 = block[i2];
+ if (c1 != c2) return (c1 > c2);
+ s1 = quadrant[i1]; s2 = quadrant[i2];
+ if (s1 != s2) return (s1 > s2);
+ i1++; i2++;
+
+ if (i1 >= nblock) i1 -= nblock;
+ if (i2 >= nblock) i2 -= nblock;
+
+ k -= 8;
+ (*budget)--;
+ }
+ while (k >= 0);
+
+ return False;
+}
+
+
+/*---------------------------------------------*/
+/*--
+ Knuth's increments seem to work better
+ than Incerpi-Sedgewick here. Possibly
+ because the number of elems to sort is
+ usually small, typically <= 20.
+--*/
+static
+Int32 incs[14] = { 1, 4, 13, 40, 121, 364, 1093, 3280,
+ 9841, 29524, 88573, 265720,
+ 797161, 2391484 };
+
+static
+void mainSimpleSort ( UInt32* ptr,
+ UChar* block,
+ UInt16* quadrant,
+ Int32 nblock,
+ Int32 lo,
+ Int32 hi,
+ Int32 d,
+ Int32* budget )
+{
+ Int32 i, j, h, bigN, hp;
+ UInt32 v;
+
+ bigN = hi - lo + 1;
+ if (bigN < 2) return;
+
+ hp = 0;
+ while (incs[hp] < bigN) hp++;
+ hp--;
+
+ for (; hp >= 0; hp--) {
+ h = incs[hp];
+
+ i = lo + h;
+ while (True) {
+
+ /*-- copy 1 --*/
+ if (i > hi) break;
+ v = ptr[i];
+ j = i;
+ while ( mainGtU (
+ ptr[j-h]+d, v+d, block, quadrant, nblock, budget
+ ) ) {
+ ptr[j] = ptr[j-h];
+ j = j - h;
+ if (j <= (lo + h - 1)) break;
+ }
+ ptr[j] = v;
+ i++;
+
+ /*-- copy 2 --*/
+ if (i > hi) break;
+ v = ptr[i];
+ j = i;
+ while ( mainGtU (
+ ptr[j-h]+d, v+d, block, quadrant, nblock, budget
+ ) ) {
+ ptr[j] = ptr[j-h];
+ j = j - h;
+ if (j <= (lo + h - 1)) break;
+ }
+ ptr[j] = v;
+ i++;
+
+ /*-- copy 3 --*/
+ if (i > hi) break;
+ v = ptr[i];
+ j = i;
+ while ( mainGtU (
+ ptr[j-h]+d, v+d, block, quadrant, nblock, budget
+ ) ) {
+ ptr[j] = ptr[j-h];
+ j = j - h;
+ if (j <= (lo + h - 1)) break;
+ }
+ ptr[j] = v;
+ i++;
+
+ if (*budget < 0) return;
+ }
+ }
+}
+
+
+/*---------------------------------------------*/
+/*--
+ The following is an implementation of
+ an elegant 3-way quicksort for strings,
+ described in a paper "Fast Algorithms for
+ Sorting and Searching Strings", by Robert
+ Sedgewick and Jon L. Bentley.
+--*/
+
+#define mswap(zz1, zz2) \
+ { Int32 zztmp = zz1; zz1 = zz2; zz2 = zztmp; }
+
+#define mvswap(zzp1, zzp2, zzn) \
+{ \
+ Int32 yyp1 = (zzp1); \
+ Int32 yyp2 = (zzp2); \
+ Int32 yyn = (zzn); \
+ while (yyn > 0) { \
+ mswap(ptr[yyp1], ptr[yyp2]); \
+ yyp1++; yyp2++; yyn--; \
+ } \
+}
+
+static
+__inline__
+UChar mmed3 ( UChar a, UChar b, UChar c )
+{
+ UChar t;
+ if (a > b) { t = a; a = b; b = t; };
+ if (b > c) {
+ b = c;
+ if (a > b) b = a;
+ }
+ return b;
+}
+
+#define mmin(a,b) ((a) < (b)) ? (a) : (b)
+
+#define mpush(lz,hz,dz) { stackLo[sp] = lz; \
+ stackHi[sp] = hz; \
+ stackD [sp] = dz; \
+ sp++; }
+
+#define mpop(lz,hz,dz) { sp--; \
+ lz = stackLo[sp]; \
+ hz = stackHi[sp]; \
+ dz = stackD [sp]; }
+
+
+#define mnextsize(az) (nextHi[az]-nextLo[az])
+
+#define mnextswap(az,bz) \
+ { Int32 tz; \
+ tz = nextLo[az]; nextLo[az] = nextLo[bz]; nextLo[bz] = tz; \
+ tz = nextHi[az]; nextHi[az] = nextHi[bz]; nextHi[bz] = tz; \
+ tz = nextD [az]; nextD [az] = nextD [bz]; nextD [bz] = tz; }
+
+
+#define MAIN_QSORT_SMALL_THRESH 20
+#define MAIN_QSORT_DEPTH_THRESH (BZ_N_RADIX + BZ_N_QSORT)
+#define MAIN_QSORT_STACK_SIZE 100
+
+static
+void mainQSort3 ( UInt32* ptr,
+ UChar* block,
+ UInt16* quadrant,
+ Int32 nblock,
+ Int32 loSt,
+ Int32 hiSt,
+ Int32 dSt,
+ Int32* budget )
+{
+ Int32 unLo, unHi, ltLo, gtHi, n, m, med;
+ Int32 sp, lo, hi, d;
+
+ Int32 stackLo[MAIN_QSORT_STACK_SIZE];
+ Int32 stackHi[MAIN_QSORT_STACK_SIZE];
+ Int32 stackD [MAIN_QSORT_STACK_SIZE];
+
+ Int32 nextLo[3];
+ Int32 nextHi[3];
+ Int32 nextD [3];
+
+ sp = 0;
+ mpush ( loSt, hiSt, dSt );
+
+ while (sp > 0) {
+
+ AssertH ( sp < MAIN_QSORT_STACK_SIZE - 2, 1001 );
+
+ mpop ( lo, hi, d );
+ if (hi - lo < MAIN_QSORT_SMALL_THRESH ||
+ d > MAIN_QSORT_DEPTH_THRESH) {
+ mainSimpleSort ( ptr, block, quadrant, nblock, lo, hi, d, budget );
+ if (*budget < 0) return;
+ continue;
+ }
+
+ med = (Int32)
+ mmed3 ( block[ptr[ lo ]+d],
+ block[ptr[ hi ]+d],
+ block[ptr[ (lo+hi)>>1 ]+d] );
+
+ unLo = ltLo = lo;
+ unHi = gtHi = hi;
+
+ while (True) {
+ while (True) {
+ if (unLo > unHi) break;
+ n = ((Int32)block[ptr[unLo]+d]) - med;
+ if (n == 0) {
+ mswap(ptr[unLo], ptr[ltLo]);
+ ltLo++; unLo++; continue;
+ };
+ if (n > 0) break;
+ unLo++;
+ }
+ while (True) {
+ if (unLo > unHi) break;
+ n = ((Int32)block[ptr[unHi]+d]) - med;
+ if (n == 0) {
+ mswap(ptr[unHi], ptr[gtHi]);
+ gtHi--; unHi--; continue;
+ };
+ if (n < 0) break;
+ unHi--;
+ }
+ if (unLo > unHi) break;
+ mswap(ptr[unLo], ptr[unHi]); unLo++; unHi--;
+ }
+
+ AssertD ( unHi == unLo-1, "mainQSort3(2)" );
+
+ if (gtHi < ltLo) {
+ mpush(lo, hi, d+1 );
+ continue;
+ }
+
+ n = mmin(ltLo-lo, unLo-ltLo); mvswap(lo, unLo-n, n);
+ m = mmin(hi-gtHi, gtHi-unHi); mvswap(unLo, hi-m+1, m);
+
+ n = lo + unLo - ltLo - 1;
+ m = hi - (gtHi - unHi) + 1;
+
+ nextLo[0] = lo; nextHi[0] = n; nextD[0] = d;
+ nextLo[1] = m; nextHi[1] = hi; nextD[1] = d;
+ nextLo[2] = n+1; nextHi[2] = m-1; nextD[2] = d+1;
+
+ if (mnextsize(0) < mnextsize(1)) mnextswap(0,1);
+ if (mnextsize(1) < mnextsize(2)) mnextswap(1,2);
+ if (mnextsize(0) < mnextsize(1)) mnextswap(0,1);
+
+ AssertD (mnextsize(0) >= mnextsize(1), "mainQSort3(8)" );
+ AssertD (mnextsize(1) >= mnextsize(2), "mainQSort3(9)" );
+
+ mpush (nextLo[0], nextHi[0], nextD[0]);
+ mpush (nextLo[1], nextHi[1], nextD[1]);
+ mpush (nextLo[2], nextHi[2], nextD[2]);
+ }
+}
+
+#undef mswap
+#undef mvswap
+#undef mpush
+#undef mpop
+#undef mmin
+#undef mnextsize
+#undef mnextswap
+#undef MAIN_QSORT_SMALL_THRESH
+#undef MAIN_QSORT_DEPTH_THRESH
+#undef MAIN_QSORT_STACK_SIZE
+
+
+/*---------------------------------------------*/
+/* Pre:
+ nblock > N_OVERSHOOT
+ block32 exists for [0 .. nblock-1 +N_OVERSHOOT]
+ ((UChar*)block32) [0 .. nblock-1] holds block
+ ptr exists for [0 .. nblock-1]
+
+ Post:
+ ((UChar*)block32) [0 .. nblock-1] holds block
+ All other areas of block32 destroyed
+ ftab [0 .. 65536 ] destroyed
+ ptr [0 .. nblock-1] holds sorted order
+ if (*budget < 0), sorting was abandoned
+*/
+
+#define BIGFREQ(b) (ftab[((b)+1) << 8] - ftab[(b) << 8])
+#define SETMASK (1 << 21)
+#define CLEARMASK (~(SETMASK))
+
+static
+void mainSort ( UInt32* ptr,
+ UChar* block,
+ UInt16* quadrant,
+ UInt32* ftab,
+ Int32 nblock,
+ Int32 verb,
+ Int32* budget )
+{
+ Int32 i, j, k, ss, sb;
+ Int32 runningOrder[256];
+ Bool bigDone[256];
+ Int32 copyStart[256];
+ Int32 copyEnd [256];
+ UChar c1;
+ Int32 numQSorted;
+ UInt16 s;
+ if (verb >= 4) VPrintf0 ( " main sort initialise ...\n" );
+
+ /*-- set up the 2-byte frequency table --*/
+ for (i = 65536; i >= 0; i--) ftab[i] = 0;
+
+ j = block[0] << 8;
+ i = nblock-1;
+ for (; i >= 3; i -= 4) {
+ quadrant[i] = 0;
+ j = (j >> 8) | ( ((UInt16)block[i]) << 8);
+ ftab[j]++;
+ quadrant[i-1] = 0;
+ j = (j >> 8) | ( ((UInt16)block[i-1]) << 8);
+ ftab[j]++;
+ quadrant[i-2] = 0;
+ j = (j >> 8) | ( ((UInt16)block[i-2]) << 8);
+ ftab[j]++;
+ quadrant[i-3] = 0;
+ j = (j >> 8) | ( ((UInt16)block[i-3]) << 8);
+ ftab[j]++;
+ }
+ for (; i >= 0; i--) {
+ quadrant[i] = 0;
+ j = (j >> 8) | ( ((UInt16)block[i]) << 8);
+ ftab[j]++;
+ }
+
+ /*-- (emphasises close relationship of block & quadrant) --*/
+ for (i = 0; i < BZ_N_OVERSHOOT; i++) {
+ block [nblock+i] = block[i];
+ quadrant[nblock+i] = 0;
+ }
+
+ if (verb >= 4) VPrintf0 ( " bucket sorting ...\n" );
+
+ /*-- Complete the initial radix sort --*/
+ for (i = 1; i <= 65536; i++) ftab[i] += ftab[i-1];
+
+ s = block[0] << 8;
+ i = nblock-1;
+ for (; i >= 3; i -= 4) {
+ s = (s >> 8) | (block[i] << 8);
+ j = ftab[s] -1;
+ ftab[s] = j;
+ ptr[j] = i;
+ s = (s >> 8) | (block[i-1] << 8);
+ j = ftab[s] -1;
+ ftab[s] = j;
+ ptr[j] = i-1;
+ s = (s >> 8) | (block[i-2] << 8);
+ j = ftab[s] -1;
+ ftab[s] = j;
+ ptr[j] = i-2;
+ s = (s >> 8) | (block[i-3] << 8);
+ j = ftab[s] -1;
+ ftab[s] = j;
+ ptr[j] = i-3;
+ }
+ for (; i >= 0; i--) {
+ s = (s >> 8) | (block[i] << 8);
+ j = ftab[s] -1;
+ ftab[s] = j;
+ ptr[j] = i;
+ }
+
+ /*--
+ Now ftab contains the first loc of every small bucket.
+ Calculate the running order, from smallest to largest
+ big bucket.
+ --*/
+ for (i = 0; i <= 255; i++) {
+ bigDone [i] = False;
+ runningOrder[i] = i;
+ }
+
+ {
+ Int32 vv;
+ Int32 h = 1;
+ do h = 3 * h + 1; while (h <= 256);
+ do {
+ h = h / 3;
+ for (i = h; i <= 255; i++) {
+ vv = runningOrder[i];
+ j = i;
+ while ( BIGFREQ(runningOrder[j-h]) > BIGFREQ(vv) ) {
+ runningOrder[j] = runningOrder[j-h];
+ j = j - h;
+ if (j <= (h - 1)) goto zero;
+ }
+ zero:
+ runningOrder[j] = vv;
+ }
+ } while (h != 1);
+ }
+
+ /*--
+ The main sorting loop.
+ --*/
+
+ numQSorted = 0;
+
+ for (i = 0; i <= 255; i++) {
+
+ /*--
+ Process big buckets, starting with the least full.
+ Basically this is a 3-step process in which we call
+ mainQSort3 to sort the small buckets [ss, j], but
+ also make a big effort to avoid the calls if we can.
+ --*/
+ ss = runningOrder[i];
+
+ /*--
+ Step 1:
+ Complete the big bucket [ss] by quicksorting
+ any unsorted small buckets [ss, j], for j != ss.
+ Hopefully previous pointer-scanning phases have already
+ completed many of the small buckets [ss, j], so
+ we don't have to sort them at all.
+ --*/
+ for (j = 0; j <= 255; j++) {
+ if (j != ss) {
+ sb = (ss << 8) + j;
+ if ( ! (ftab[sb] & SETMASK) ) {
+ Int32 lo = ftab[sb] & CLEARMASK;
+ Int32 hi = (ftab[sb+1] & CLEARMASK) - 1;
+ if (hi > lo) {
+ if (verb >= 4)
+ VPrintf4 ( " qsort [0x%x, 0x%x] "
+ "done %d this %d\n",
+ ss, j, numQSorted, hi - lo + 1 );
+ mainQSort3 (
+ ptr, block, quadrant, nblock,
+ lo, hi, BZ_N_RADIX, budget
+ );
+ numQSorted += (hi - lo + 1);
+ if (*budget < 0) return;
+ }
+ }
+ ftab[sb] |= SETMASK;
+ }
+ }
+
+ AssertH ( !bigDone[ss], 1006 );
+
+ /*--
+ Step 2:
+ Now scan this big bucket [ss] so as to synthesise the
+ sorted order for small buckets [t, ss] for all t,
+ including, magically, the bucket [ss,ss] too.
+ This will avoid doing Real Work in subsequent Step 1's.
+ --*/
+ {
+ for (j = 0; j <= 255; j++) {
+ copyStart[j] = ftab[(j << 8) + ss] & CLEARMASK;
+ copyEnd [j] = (ftab[(j << 8) + ss + 1] & CLEARMASK) - 1;
+ }
+ for (j = ftab[ss << 8] & CLEARMASK; j < copyStart[ss]; j++) {
+ k = ptr[j]-1; if (k < 0) k += nblock;
+ c1 = block[k];
+ if (!bigDone[c1])
+ ptr[ copyStart[c1]++ ] = k;
+ }
+ for (j = (ftab[(ss+1) << 8] & CLEARMASK) - 1; j > copyEnd[ss]; j--) {
+ k = ptr[j]-1; if (k < 0) k += nblock;
+ c1 = block[k];
+ if (!bigDone[c1])
+ ptr[ copyEnd[c1]-- ] = k;
+ }
+ }
+
+ AssertH ( (copyStart[ss]-1 == copyEnd[ss])
+ ||
+ /* Extremely rare case missing in bzip2-1.0.0 and 1.0.1.
+ Necessity for this case is demonstrated by compressing
+ a sequence of approximately 48.5 million of character
+ 251; 1.0.0/1.0.1 will then die here. */
+ (copyStart[ss] == 0 && copyEnd[ss] == nblock-1),
+ 1007 )
+
+ for (j = 0; j <= 255; j++) ftab[(j << 8) + ss] |= SETMASK;
+
+ /*--
+ Step 3:
+ The [ss] big bucket is now done. Record this fact,
+ and update the quadrant descriptors. Remember to
+ update quadrants in the overshoot area too, if
+ necessary. The "if (i < 255)" test merely skips
+ this updating for the last bucket processed, since
+ updating for the last bucket is pointless.
+
+ The quadrant array provides a way to incrementally
+ cache sort orderings, as they appear, so as to
+ make subsequent comparisons in fullGtU() complete
+ faster. For repetitive blocks this makes a big
+ difference (but not big enough to be able to avoid
+ the fallback sorting mechanism, exponential radix sort).
+
+ The precise meaning is: at all times:
+
+ for 0 <= i < nblock and 0 <= j <= nblock
+
+ if block[i] != block[j],
+
+ then the relative values of quadrant[i] and
+ quadrant[j] are meaningless.
+
+ else {
+ if quadrant[i] < quadrant[j]
+ then the string starting at i lexicographically
+ precedes the string starting at j
+
+ else if quadrant[i] > quadrant[j]
+ then the string starting at j lexicographically
+ precedes the string starting at i
+
+ else
+ the relative ordering of the strings starting
+ at i and j has not yet been determined.
+ }
+ --*/
+ bigDone[ss] = True;
+
+ if (i < 255) {
+ Int32 bbStart = ftab[ss << 8] & CLEARMASK;
+ Int32 bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
+ Int32 shifts = 0;
+
+ while ((bbSize >> shifts) > 65534) shifts++;
+
+ for (j = bbSize-1; j >= 0; j--) {
+ Int32 a2update = ptr[bbStart + j];
+ UInt16 qVal = (UInt16)(j >> shifts);
+ quadrant[a2update] = qVal;
+ if (a2update < BZ_N_OVERSHOOT)
+ quadrant[a2update + nblock] = qVal;
+ }
+ AssertH ( ((bbSize-1) >> shifts) <= 65535, 1002 );
+ }
+
+ }
+
+ if (verb >= 4)
+ VPrintf3 ( " %d pointers, %d sorted, %d scanned\n",
+ nblock, numQSorted, nblock - numQSorted );
+}
+
+#undef BIGFREQ
+#undef SETMASK
+#undef CLEARMASK
+
+
+/*---------------------------------------------*/
+/* Pre:
+ nblock > 0
+ arr2 exists for [0 .. nblock-1 +N_OVERSHOOT]
+ ((UChar*)arr2) [0 .. nblock-1] holds block
+ arr1 exists for [0 .. nblock-1]
+
+ Post:
+ ((UChar*)arr2) [0 .. nblock-1] holds block
+ All other areas of block destroyed
+ ftab [ 0 .. 65536 ] destroyed
+ arr1 [0 .. nblock-1] holds sorted order
+*/
+void BZ2_blockSort ( EState* s )
+{
+ UInt32* ptr = s->ptr;
+ UChar* block = s->block;
+ UInt32* ftab = s->ftab;
+ Int32 nblock = s->nblock;
+ Int32 verb = s->verbosity;
+ Int32 wfact = s->workFactor;
+ UInt16* quadrant;
+ Int32 budget;
+ Int32 budgetInit;
+ Int32 i;
+
+ if (nblock < 10000) {
+ fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
+ } else {
+ /* Calculate the location for quadrant, remembering to get
+ the alignment right. Assumes that &(block[0]) is at least
+ 2-byte aligned -- this should be ok since block is really
+ the first section of arr2.
+ */
+ i = nblock+BZ_N_OVERSHOOT;
+ if (i & 1) i++;
+ quadrant = (UInt16*)(&(block[i]));
+
+ /* (wfact-1) / 3 puts the default-factor-30
+ transition point at very roughly the same place as
+ with v0.1 and v0.9.0.
+ Not that it particularly matters any more, since the
+ resulting compressed stream is now the same regardless
+ of whether or not we use the main sort or fallback sort.
+ */
+ if (wfact < 1 ) wfact = 1;
+ if (wfact > 100) wfact = 100;
+ budgetInit = nblock * ((wfact-1) / 3);
+ budget = budgetInit;
+
+ mainSort ( ptr, block, quadrant, ftab, nblock, verb, &budget );
+ if (verb >= 3)
+ VPrintf3 ( " %d work, %d block, ratio %5.2f\n",
+ budgetInit - budget,
+ nblock,
+ (float)(budgetInit - budget) /
+ (float)(nblock==0 ? 1 : nblock) );
+ if (budget < 0) {
+ if (verb >= 2)
+ VPrintf0 ( " too repetitive; using fallback"
+ " sorting algorithm\n" );
+ fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
+ }
+ }
+
+ s->origPtr = -1;
+ for (i = 0; i < s->nblock; i++)
+ if (ptr[i] == 0)
+ { s->origPtr = i; break; };
+
+ AssertH( s->origPtr != -1, 1003 );
+}
+
+
+/*-------------------------------------------------------------*/
+/*--- end blocksort.c ---*/
+/*-------------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/bz-common.xsl b/Utilities/cmbzip2/bz-common.xsl
new file mode 100644
index 0000000000..66fcd6fe0b
--- /dev/null
+++ b/Utilities/cmbzip2/bz-common.xsl
@@ -0,0 +1,39 @@
+<?xml version="1.0"?> <!-- -*- sgml -*- -->
+<xsl:stylesheet
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+<!-- we like '1.2 Title' -->
+<xsl:param name="section.autolabel" select="'1'"/>
+<xsl:param name="section.label.includes.component.label" select="'1'"/>
+
+<!-- Do not put 'Chapter' at the start of eg 'Chapter 1. Doing This' -->
+<xsl:param name="local.l10n.xml" select="document('')"/>
+<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
+ <l:l10n language="en">
+ <l:context name="title-numbered">
+ <l:template name="chapter" text="%n.&#160;%t"/>
+ </l:context>
+ </l:l10n>
+</l:i18n>
+
+<!-- don't generate sub-tocs for qanda sets -->
+<xsl:param name="generate.toc">
+set toc,title
+book toc,title,figure,table,example,equation
+chapter toc,title
+section toc
+sect1 toc
+sect2 toc
+sect3 toc
+sect4 nop
+sect5 nop
+qandaset toc
+qandadiv nop
+appendix toc,title
+article/appendix nop
+article toc,title
+preface toc,title
+reference toc,title
+</xsl:param>
+
+</xsl:stylesheet>
diff --git a/Utilities/cmbzip2/bz-fo.xsl b/Utilities/cmbzip2/bz-fo.xsl
new file mode 100644
index 0000000000..ba3e30123f
--- /dev/null
+++ b/Utilities/cmbzip2/bz-fo.xsl
@@ -0,0 +1,276 @@
+<?xml version="1.0" encoding="UTF-8"?> <!-- -*- sgml -*- -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
+
+<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
+<xsl:import href="bz-common.xsl"/>
+
+<!-- set indent = yes while debugging, then change to NO -->
+<xsl:output method="xml" indent="yes"/>
+
+<!-- ensure only passivetex extensions are on -->
+<xsl:param name="stylesheet.result.type" select="'fo'"/>
+<!-- fo extensions: PDF bookmarks and index terms -->
+<xsl:param name="use.extensions" select="'1'"/>
+<xsl:param name="xep.extensions" select="0"/>
+<xsl:param name="fop.extensions" select="0"/>
+<xsl:param name="saxon.extensions" select="0"/>
+<xsl:param name="passivetex.extensions" select="1"/>
+<xsl:param name="tablecolumns.extension" select="'1'"/>
+
+<!-- ensure we are using single sided -->
+<xsl:param name="double.sided" select="'0'"/>
+
+<!-- insert cross references to page numbers -->
+<xsl:param name="insert.xref.page.number" select="1"/>
+
+<!-- <?custom-pagebreak?> inserts a page break at this point -->
+<xsl:template match="processing-instruction('custom-pagebreak')">
+ <fo:block break-before='page'/>
+</xsl:template>
+
+<!-- show links in color -->
+<xsl:attribute-set name="xref.properties">
+ <xsl:attribute name="color">blue</xsl:attribute>
+</xsl:attribute-set>
+
+<!-- make pre listings indented a bit + a bg colour -->
+<xsl:template match="programlisting | screen">
+ <fo:block start-indent="0.25in" wrap-option="no-wrap"
+ white-space-collapse="false" text-align="start"
+ font-family="monospace" background-color="#f2f2f9"
+ linefeed-treatment="preserve"
+ xsl:use-attribute-sets="normal.para.spacing">
+ <xsl:apply-templates/>
+ </fo:block>
+</xsl:template>
+<!-- make verbatim output prettier -->
+<xsl:template match="literallayout">
+ <fo:block start-indent="0.25in" wrap-option="no-wrap"
+ white-space-collapse="false" text-align="start"
+ font-family="monospace" background-color="#edf7f4"
+ linefeed-treatment="preserve"
+ space-before="0em" space-after="0em">
+ <xsl:apply-templates/>
+ </fo:block>
+</xsl:template>
+
+<!-- workaround bug in passivetex fo output for itemizedlist -->
+<xsl:template match="itemizedlist/listitem">
+ <xsl:variable name="id">
+ <xsl:call-template name="object.id"/></xsl:variable>
+ <xsl:variable name="itemsymbol">
+ <xsl:call-template name="list.itemsymbol">
+ <xsl:with-param name="node" select="parent::itemizedlist"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="item.contents">
+ <fo:list-item-label end-indent="label-end()">
+ <fo:block>
+ <xsl:choose>
+ <xsl:when test="$itemsymbol='disc'">&#x2022;</xsl:when>
+ <xsl:when test="$itemsymbol='bullet'">&#x2022;</xsl:when>
+ <xsl:otherwise>&#x2022;</xsl:otherwise>
+ </xsl:choose>
+ </fo:block>
+ </fo:list-item-label>
+ <fo:list-item-body start-indent="body-start()">
+ <xsl:apply-templates/> <!-- removed extra block wrapper -->
+ </fo:list-item-body>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="parent::*/@spacing = 'compact'">
+ <fo:list-item id="{$id}"
+ xsl:use-attribute-sets="compact.list.item.spacing">
+ <xsl:copy-of select="$item.contents"/>
+ </fo:list-item>
+ </xsl:when>
+ <xsl:otherwise>
+ <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
+ <xsl:copy-of select="$item.contents"/>
+ </fo:list-item>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- workaround bug in passivetex fo output for orderedlist -->
+<xsl:template match="orderedlist/listitem">
+ <xsl:variable name="id">
+ <xsl:call-template name="object.id"/></xsl:variable>
+ <xsl:variable name="item.contents">
+ <fo:list-item-label end-indent="label-end()">
+ <fo:block>
+ <xsl:apply-templates select="." mode="item-number"/>
+ </fo:block>
+ </fo:list-item-label>
+ <fo:list-item-body start-indent="body-start()">
+ <xsl:apply-templates/> <!-- removed extra block wrapper -->
+ </fo:list-item-body>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="parent::*/@spacing = 'compact'">
+ <fo:list-item id="{$id}"
+ xsl:use-attribute-sets="compact.list.item.spacing">
+ <xsl:copy-of select="$item.contents"/>
+ </fo:list-item>
+ </xsl:when>
+ <xsl:otherwise>
+ <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
+ <xsl:copy-of select="$item.contents"/>
+ </fo:list-item>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- workaround bug in passivetex fo output for variablelist -->
+<xsl:param name="variablelist.as.blocks" select="1"/>
+<xsl:template match="varlistentry" mode="vl.as.blocks">
+ <xsl:variable name="id">
+ <xsl:call-template name="object.id"/></xsl:variable>
+ <fo:block id="{$id}" xsl:use-attribute-sets="list.item.spacing"
+ keep-together.within-column="always"
+ keep-with-next.within-column="always">
+ <xsl:apply-templates select="term"/>
+ </fo:block>
+ <fo:block start-indent="0.5in" end-indent="0in"
+ space-after.minimum="0.2em"
+ space-after.optimum="0.4em"
+ space-after.maximum="0.6em">
+ <fo:block>
+ <xsl:apply-templates select="listitem"/>
+ </fo:block>
+ </fo:block>
+</xsl:template>
+
+
+<!-- workaround bug in footers: force right-align w/two 80|30 cols -->
+<xsl:template name="footer.table">
+ <xsl:param name="pageclass" select="''"/>
+ <xsl:param name="sequence" select="''"/>
+ <xsl:param name="gentext-key" select="''"/>
+ <xsl:choose>
+ <xsl:when test="$pageclass = 'index'">
+ <xsl:attribute name="margin-left">0pt</xsl:attribute>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:variable name="candidate">
+ <fo:table table-layout="fixed" width="100%">
+ <fo:table-column column-number="1" column-width="80%"/>
+ <fo:table-column column-number="2" column-width="20%"/>
+ <fo:table-body>
+ <fo:table-row height="14pt">
+ <fo:table-cell text-align="left" display-align="after">
+ <xsl:attribute name="relative-align">baseline</xsl:attribute>
+ <fo:block>
+ <fo:block> </fo:block><!-- empty cell -->
+ </fo:block>
+ </fo:table-cell>
+ <fo:table-cell text-align="center" display-align="after">
+ <xsl:attribute name="relative-align">baseline</xsl:attribute>
+ <fo:block>
+ <xsl:call-template name="footer.content">
+ <xsl:with-param name="pageclass" select="$pageclass"/>
+ <xsl:with-param name="sequence" select="$sequence"/>
+ <xsl:with-param name="position" select="'center'"/>
+ <xsl:with-param name="gentext-key" select="$gentext-key"/>
+ </xsl:call-template>
+ </fo:block>
+ </fo:table-cell>
+ </fo:table-row>
+ </fo:table-body>
+ </fo:table>
+ </xsl:variable>
+ <!-- Really output a footer? -->
+ <xsl:choose>
+ <xsl:when test="$pageclass='titlepage' and $gentext-key='book'
+ and $sequence='first'">
+ <!-- no, book titlepages have no footers at all -->
+ </xsl:when>
+ <xsl:when test="$sequence = 'blank' and $footers.on.blank.pages = 0">
+ <!-- no output -->
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="$candidate"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+
+<!-- fix bug in headers: force right-align w/two 40|60 cols -->
+<xsl:template name="header.table">
+ <xsl:param name="pageclass" select="''"/>
+ <xsl:param name="sequence" select="''"/>
+ <xsl:param name="gentext-key" select="''"/>
+ <xsl:choose>
+ <xsl:when test="$pageclass = 'index'">
+ <xsl:attribute name="margin-left">0pt</xsl:attribute>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:variable name="candidate">
+ <fo:table table-layout="fixed" width="100%">
+ <xsl:call-template name="head.sep.rule">
+ <xsl:with-param name="pageclass" select="$pageclass"/>
+ <xsl:with-param name="sequence" select="$sequence"/>
+ <xsl:with-param name="gentext-key" select="$gentext-key"/>
+ </xsl:call-template>
+ <fo:table-column column-number="1" column-width="40%"/>
+ <fo:table-column column-number="2" column-width="60%"/>
+ <fo:table-body>
+ <fo:table-row height="14pt">
+ <fo:table-cell text-align="left" display-align="before">
+ <xsl:attribute name="relative-align">baseline</xsl:attribute>
+ <fo:block>
+ <fo:block> </fo:block><!-- empty cell -->
+ </fo:block>
+ </fo:table-cell>
+ <fo:table-cell text-align="center" display-align="before">
+ <xsl:attribute name="relative-align">baseline</xsl:attribute>
+ <fo:block>
+ <xsl:call-template name="header.content">
+ <xsl:with-param name="pageclass" select="$pageclass"/>
+ <xsl:with-param name="sequence" select="$sequence"/>
+ <xsl:with-param name="position" select="'center'"/>
+ <xsl:with-param name="gentext-key" select="$gentext-key"/>
+ </xsl:call-template>
+ </fo:block>
+ </fo:table-cell>
+ </fo:table-row>
+ </fo:table-body>
+ </fo:table>
+ </xsl:variable>
+ <!-- Really output a header? -->
+ <xsl:choose>
+ <xsl:when test="$pageclass = 'titlepage' and $gentext-key = 'book'
+ and $sequence='first'">
+ <!-- no, book titlepages have no headers at all -->
+ </xsl:when>
+ <xsl:when test="$sequence = 'blank' and $headers.on.blank.pages = 0">
+ <!-- no output -->
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="$candidate"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+
+<!-- Bug-fix for Suse 10 PassiveTex version -->
+<!-- Precompute attribute values 'cos PassiveTex is too stupid: -->
+<xsl:attribute-set name="component.title.properties">
+ <xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
+ <xsl:attribute name="space-before.optimum">
+ <xsl:value-of select="concat($body.font.master, 'pt')"/>
+ </xsl:attribute>
+ <xsl:attribute name="space-before.minimum">
+ <xsl:value-of select="$body.font.master * 0.8"/>
+ <xsl:text>pt</xsl:text>
+ </xsl:attribute>
+ <xsl:attribute name="space-before.maximum">
+ <xsl:value-of select="$body.font.master * 1.2"/>
+ <xsl:text>pt</xsl:text>
+ </xsl:attribute>
+ <xsl:attribute name="hyphenate">false</xsl:attribute>
+</xsl:attribute-set>
+
+
+</xsl:stylesheet>
diff --git a/Utilities/cmbzip2/bz-html.xsl b/Utilities/cmbzip2/bz-html.xsl
new file mode 100644
index 0000000000..1785fffbc9
--- /dev/null
+++ b/Utilities/cmbzip2/bz-html.xsl
@@ -0,0 +1,20 @@
+<?xml version="1.0"?> <!-- -*- sgml -*- -->
+<!DOCTYPE xsl:stylesheet [ <!ENTITY bz-css SYSTEM "./bzip.css"> ]>
+
+<xsl:stylesheet
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"/>
+<xsl:import href="bz-common.xsl"/>
+
+<!-- use 8859-1 encoding -->
+<xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
+
+<!-- we include the css directly when generating one large file -->
+<xsl:template name="user.head.content">
+ <style type="text/css" media="screen">
+ <xsl:text>&bz-css;</xsl:text>
+ </style>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/Utilities/cmbzip2/bzdiff b/Utilities/cmbzip2/bzdiff
new file mode 100644
index 0000000000..c4c9964900
--- /dev/null
+++ b/Utilities/cmbzip2/bzdiff
@@ -0,0 +1,76 @@
+#!/bin/sh
+# sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
+
+# Bzcmp/diff wrapped for bzip2,
+# adapted from zdiff by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
+
+# Bzcmp and bzdiff are used to invoke the cmp or the diff pro-
+# gram on compressed files. All options specified are passed
+# directly to cmp or diff. If only 1 file is specified, then
+# the files compared are file1 and an uncompressed file1.gz.
+# If two files are specified, then they are uncompressed (if
+# necessary) and fed to cmp or diff. The exit status from cmp
+# or diff is preserved.
+
+PATH="/usr/bin:/bin:$PATH"; export PATH
+prog=`echo $0 | sed 's|.*/||'`
+case "$prog" in
+ *cmp) comp=${CMP-cmp} ;;
+ *) comp=${DIFF-diff} ;;
+esac
+
+OPTIONS=
+FILES=
+for ARG
+do
+ case "$ARG" in
+ -*) OPTIONS="$OPTIONS $ARG";;
+ *) if test -f "$ARG"; then
+ FILES="$FILES $ARG"
+ else
+ echo "${prog}: $ARG not found or not a regular file"
+ exit 1
+ fi ;;
+ esac
+done
+if test -z "$FILES"; then
+ echo "Usage: $prog [${comp}_options] file [file]"
+ exit 1
+fi
+tmp=`mktemp ${TMPDIR:-/tmp}/bzdiff.XXXXXXXXXX` || {
+ echo 'cannot create a temporary file' >&2
+ exit 1
+}
+set $FILES
+if test $# -eq 1; then
+ FILE=`echo "$1" | sed 's/.bz2$//'`
+ bzip2 -cd "$FILE.bz2" | $comp $OPTIONS - "$FILE"
+ STAT="$?"
+
+elif test $# -eq 2; then
+ case "$1" in
+ *.bz2)
+ case "$2" in
+ *.bz2)
+ F=`echo "$2" | sed 's|.*/||;s|.bz2$||'`
+ bzip2 -cdfq "$2" > $tmp
+ bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp
+ STAT="$?"
+ /bin/rm -f $tmp;;
+
+ *) bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
+ STAT="$?";;
+ esac;;
+ *) case "$2" in
+ *.bz2)
+ bzip2 -cdfq "$2" | $comp $OPTIONS "$1" -
+ STAT="$?";;
+ *) $comp $OPTIONS "$1" "$2"
+ STAT="$?";;
+ esac;;
+ esac
+ exit "$STAT"
+else
+ echo "Usage: $prog [${comp}_options] file [file]"
+ exit 1
+fi
diff --git a/Utilities/cmbzip2/bzdiff.1 b/Utilities/cmbzip2/bzdiff.1
new file mode 100644
index 0000000000..adb7a8e724
--- /dev/null
+++ b/Utilities/cmbzip2/bzdiff.1
@@ -0,0 +1,47 @@
+\"Shamelessly copied from zmore.1 by Philippe Troin <phil@fifi.org>
+\"for Debian GNU/Linux
+.TH BZDIFF 1
+.SH NAME
+bzcmp, bzdiff \- compare bzip2 compressed files
+.SH SYNOPSIS
+.B bzcmp
+[ cmp_options ] file1
+[ file2 ]
+.br
+.B bzdiff
+[ diff_options ] file1
+[ file2 ]
+.SH DESCRIPTION
+.I Bzcmp
+and
+.I bzdiff
+are used to invoke the
+.I cmp
+or the
+.I diff
+program on bzip2 compressed files. All options specified are passed
+directly to
+.I cmp
+or
+.IR diff "."
+If only 1 file is specified, then the files compared are
+.I file1
+and an uncompressed
+.IR file1 ".bz2."
+If two files are specified, then they are uncompressed if necessary and fed to
+.I cmp
+or
+.IR diff "."
+The exit status from
+.I cmp
+or
+.I diff
+is preserved.
+.SH "SEE ALSO"
+cmp(1), diff(1), bzmore(1), bzless(1), bzgrep(1), bzip2(1)
+.SH BUGS
+Messages from the
+.I cmp
+or
+.I diff
+programs refer to temporary filenames instead of those specified.
diff --git a/Utilities/cmbzip2/bzgrep b/Utilities/cmbzip2/bzgrep
new file mode 100644
index 0000000000..8ccf919ac7
--- /dev/null
+++ b/Utilities/cmbzip2/bzgrep
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+# Bzgrep wrapped for bzip2,
+# adapted from zgrep by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
+## zgrep notice:
+## zgrep -- a wrapper around a grep program that decompresses files as needed
+## Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
+
+PATH="/usr/bin:$PATH"; export PATH
+
+prog=`echo $0 | sed 's|.*/||'`
+case "$prog" in
+ *egrep) grep=${EGREP-egrep} ;;
+ *fgrep) grep=${FGREP-fgrep} ;;
+ *) grep=${GREP-grep} ;;
+esac
+pat=""
+while test $# -ne 0; do
+ case "$1" in
+ -e | -f) opt="$opt $1"; shift; pat="$1"
+ if test "$grep" = grep; then # grep is buggy with -e on SVR4
+ grep=egrep
+ fi;;
+ -A | -B) opt="$opt $1 $2"; shift;;
+ -*) opt="$opt $1";;
+ *) if test -z "$pat"; then
+ pat="$1"
+ else
+ break;
+ fi;;
+ esac
+ shift
+done
+
+if test -z "$pat"; then
+ echo "grep through bzip2 files"
+ echo "usage: $prog [grep_options] pattern [files]"
+ exit 1
+fi
+
+list=0
+silent=0
+op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
+case "$op" in
+ *l*) list=1
+esac
+case "$op" in
+ *h*) silent=1
+esac
+
+if test $# -eq 0; then
+ bzip2 -cdfq | $grep $opt "$pat"
+ exit $?
+fi
+
+res=0
+for i do
+ if test -f "$i"; then :; else if test -f "$i.bz2"; then i="$i.bz2"; fi; fi
+ if test $list -eq 1; then
+ bzip2 -cdfq "$i" | $grep $opt "$pat" 2>&1 > /dev/null && echo $i
+ r=$?
+ elif test $# -eq 1 -o $silent -eq 1; then
+ bzip2 -cdfq "$i" | $grep $opt "$pat"
+ r=$?
+ else
+ j=${i//\\/\\\\}
+ j=${j//|/\\|}
+ j=${j//&/\\&}
+ j=`printf "%s" "$j" | tr '\n' ' '`
+ bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
+ r=$?
+ fi
+ test "$r" -ne 0 && res="$r"
+done
+exit $res
diff --git a/Utilities/cmbzip2/bzgrep.1 b/Utilities/cmbzip2/bzgrep.1
new file mode 100644
index 0000000000..930af8c7fc
--- /dev/null
+++ b/Utilities/cmbzip2/bzgrep.1
@@ -0,0 +1,56 @@
+\"Shamelessly copied from zmore.1 by Philippe Troin <phil@fifi.org>
+\"for Debian GNU/Linux
+.TH BZGREP 1
+.SH NAME
+bzgrep, bzfgrep, bzegrep \- search possibly bzip2 compressed files for a regular expression
+.SH SYNOPSIS
+.B bzgrep
+[ grep_options ]
+.BI [\ -e\ ] " pattern"
+.IR filename ".\|.\|."
+.br
+.B bzegrep
+[ egrep_options ]
+.BI [\ -e\ ] " pattern"
+.IR filename ".\|.\|."
+.br
+.B bzfgrep
+[ fgrep_options ]
+.BI [\ -e\ ] " pattern"
+.IR filename ".\|.\|."
+.SH DESCRIPTION
+.IR Bzgrep
+is used to invoke the
+.I grep
+on bzip2-compressed files. All options specified are passed directly to
+.I grep.
+If no file is specified, then the standard input is decompressed
+if necessary and fed to grep.
+Otherwise the given files are uncompressed if necessary and fed to
+.I grep.
+.PP
+If
+.I bzgrep
+is invoked as
+.I bzegrep
+or
+.I bzfgrep
+then
+.I egrep
+or
+.I fgrep
+is used instead of
+.I grep.
+If the GREP environment variable is set,
+.I bzgrep
+uses it as the
+.I grep
+program to be invoked. For example:
+
+ for sh: GREP=fgrep bzgrep string files
+ for csh: (setenv GREP fgrep; bzgrep string files)
+.SH AUTHOR
+Charles Levert (charles@comm.polymtl.ca). Adapted to bzip2 by Philippe
+Troin <phil@fifi.org> for Debian GNU/Linux.
+.SH "SEE ALSO"
+grep(1), egrep(1), fgrep(1), bzdiff(1), bzmore(1), bzless(1), bzip2(1)
diff --git a/Utilities/cmbzip2/bzip.css b/Utilities/cmbzip2/bzip.css
new file mode 100644
index 0000000000..4feb40165c
--- /dev/null
+++ b/Utilities/cmbzip2/bzip.css
@@ -0,0 +1,74 @@
+/* Colours:
+#74240f dark brown h1, h2, h3, h4
+#336699 medium blue links
+#339999 turquoise link hover colour
+#202020 almost black general text
+#761596 purple md5sum text
+#626262 dark gray pre border
+#eeeeee very light gray pre background
+#f2f2f9 very light blue nav table background
+#3366cc medium blue nav table border
+*/
+
+a, a:link, a:visited, a:active { color: #336699; }
+a:hover { color: #339999; }
+
+body { font: 80%/126% sans-serif; }
+h1, h2, h3, h4 { color: #74240f; }
+
+dt { color: #336699; font-weight: bold }
+dd {
+ margin-left: 1.5em;
+ padding-bottom: 0.8em;
+}
+
+/* -- ruler -- */
+div.hr_blue {
+ height: 3px;
+ background:#ffffff url("/images/hr_blue.png") repeat-x; }
+div.hr_blue hr { display:none; }
+
+/* release styles */
+#release p { margin-top: 0.4em; }
+#release .md5sum { color: #761596; }
+
+
+/* ------ styles for docs|manuals|howto ------ */
+/* -- lists -- */
+ul {
+ margin: 0px 4px 16px 16px;
+ padding: 0px;
+ list-style: url("/images/li-blue.png");
+}
+ul li {
+ margin-bottom: 10px;
+}
+ul ul {
+ list-style-type: none;
+ list-style-image: none;
+ margin-left: 0px;
+}
+
+/* header / footer nav tables */
+table.nav {
+ border: solid 1px #3366cc;
+ background: #f2f2f9;
+ background-color: #f2f2f9;
+ margin-bottom: 0.5em;
+}
+/* don't have underlined links in chunked nav menus */
+table.nav a { text-decoration: none; }
+table.nav a:hover { text-decoration: underline; }
+table.nav td { font-size: 85%; }
+
+code, tt, pre { font-size: 120%; }
+code, tt { color: #761596; }
+
+div.literallayout, pre.programlisting, pre.screen {
+ color: #000000;
+ padding: 0.5em;
+ background: #eeeeee;
+ border: 1px solid #626262;
+ background-color: #eeeeee;
+ margin: 4px 0px 4px 0px;
+}
diff --git a/Utilities/cmbzip2/bzip2.1 b/Utilities/cmbzip2/bzip2.1
new file mode 100644
index 0000000000..a313f2d5be
--- /dev/null
+++ b/Utilities/cmbzip2/bzip2.1
@@ -0,0 +1,454 @@
+.PU
+.TH bzip2 1
+.SH NAME
+bzip2, bunzip2 \- a block-sorting file compressor, v1.0.4
+.br
+bzcat \- decompresses files to stdout
+.br
+bzip2recover \- recovers data from damaged bzip2 files
+
+.SH SYNOPSIS
+.ll +8
+.B bzip2
+.RB [ " \-cdfkqstvzVL123456789 " ]
+[
+.I "filenames \&..."
+]
+.ll -8
+.br
+.B bunzip2
+.RB [ " \-fkvsVL " ]
+[
+.I "filenames \&..."
+]
+.br
+.B bzcat
+.RB [ " \-s " ]
+[
+.I "filenames \&..."
+]
+.br
+.B bzip2recover
+.I "filename"
+
+.SH DESCRIPTION
+.I bzip2
+compresses files using the Burrows-Wheeler block sorting
+text compression algorithm, and Huffman coding. Compression is
+generally considerably better than that achieved by more conventional
+LZ77/LZ78-based compressors, and approaches the performance of the PPM
+family of statistical compressors.
+
+The command-line options are deliberately very similar to
+those of
+.I GNU gzip,
+but they are not identical.
+
+.I bzip2
+expects a list of file names to accompany the
+command-line flags. Each file is replaced by a compressed version of
+itself, with the name "original_name.bz2".
+Each compressed file
+has the same modification date, permissions, and, when possible,
+ownership as the corresponding original, so that these properties can
+be correctly restored at decompression time. File name handling is
+naive in the sense that there is no mechanism for preserving original
+file names, permissions, ownerships or dates in filesystems which lack
+these concepts, or have serious file name length restrictions, such as
+MS-DOS.
+
+.I bzip2
+and
+.I bunzip2
+will by default not overwrite existing
+files. If you want this to happen, specify the \-f flag.
+
+If no file names are specified,
+.I bzip2
+compresses from standard
+input to standard output. In this case,
+.I bzip2
+will decline to
+write compressed output to a terminal, as this would be entirely
+incomprehensible and therefore pointless.
+
+.I bunzip2
+(or
+.I bzip2 \-d)
+decompresses all
+specified files. Files which were not created by
+.I bzip2
+will be detected and ignored, and a warning issued.
+.I bzip2
+attempts to guess the filename for the decompressed file
+from that of the compressed file as follows:
+
+ filename.bz2 becomes filename
+ filename.bz becomes filename
+ filename.tbz2 becomes filename.tar
+ filename.tbz becomes filename.tar
+ anyothername becomes anyothername.out
+
+If the file does not end in one of the recognised endings,
+.I .bz2,
+.I .bz,
+.I .tbz2
+or
+.I .tbz,
+.I bzip2
+complains that it cannot
+guess the name of the original file, and uses the original name
+with
+.I .out
+appended.
+
+As with compression, supplying no
+filenames causes decompression from
+standard input to standard output.
+
+.I bunzip2
+will correctly decompress a file which is the
+concatenation of two or more compressed files. The result is the
+concatenation of the corresponding uncompressed files. Integrity
+testing (\-t)
+of concatenated
+compressed files is also supported.
+
+You can also compress or decompress files to the standard output by
+giving the \-c flag. Multiple files may be compressed and
+decompressed like this. The resulting outputs are fed sequentially to
+stdout. Compression of multiple files
+in this manner generates a stream
+containing multiple compressed file representations. Such a stream
+can be decompressed correctly only by
+.I bzip2
+version 0.9.0 or
+later. Earlier versions of
+.I bzip2
+will stop after decompressing
+the first file in the stream.
+
+.I bzcat
+(or
+.I bzip2 -dc)
+decompresses all specified files to
+the standard output.
+
+.I bzip2
+will read arguments from the environment variables
+.I BZIP2
+and
+.I BZIP,
+in that order, and will process them
+before any arguments read from the command line. This gives a
+convenient way to supply default arguments.
+
+Compression is always performed, even if the compressed
+file is slightly
+larger than the original. Files of less than about one hundred bytes
+tend to get larger, since the compression mechanism has a constant
+overhead in the region of 50 bytes. Random data (including the output
+of most file compressors) is coded at about 8.05 bits per byte, giving
+an expansion of around 0.5%.
+
+As a self-check for your protection,
+.I
+bzip2
+uses 32-bit CRCs to
+make sure that the decompressed version of a file is identical to the
+original. This guards against corruption of the compressed data, and
+against undetected bugs in
+.I bzip2
+(hopefully very unlikely). The
+chances of data corruption going undetected is microscopic, about one
+chance in four billion for each file processed. Be aware, though, that
+the check occurs upon decompression, so it can only tell you that
+something is wrong. It can't help you
+recover the original uncompressed
+data. You can use
+.I bzip2recover
+to try to recover data from
+damaged files.
+
+Return values: 0 for a normal exit, 1 for environmental problems (file
+not found, invalid flags, I/O errors, &c), 2 to indicate a corrupt
+compressed file, 3 for an internal consistency error (eg, bug) which
+caused
+.I bzip2
+to panic.
+
+.SH OPTIONS
+.TP
+.B \-c --stdout
+Compress or decompress to standard output.
+.TP
+.B \-d --decompress
+Force decompression.
+.I bzip2,
+.I bunzip2
+and
+.I bzcat
+are
+really the same program, and the decision about what actions to take is
+done on the basis of which name is used. This flag overrides that
+mechanism, and forces
+.I bzip2
+to decompress.
+.TP
+.B \-z --compress
+The complement to \-d: forces compression, regardless of the
+invocation name.
+.TP
+.B \-t --test
+Check integrity of the specified file(s), but don't decompress them.
+This really performs a trial decompression and throws away the result.
+.TP
+.B \-f --force
+Force overwrite of output files. Normally,
+.I bzip2
+will not overwrite
+existing output files. Also forces
+.I bzip2
+to break hard links
+to files, which it otherwise wouldn't do.
+
+bzip2 normally declines to decompress files which don't have the
+correct magic header bytes. If forced (-f), however, it will pass
+such files through unmodified. This is how GNU gzip behaves.
+.TP
+.B \-k --keep
+Keep (don't delete) input files during compression
+or decompression.
+.TP
+.B \-s --small
+Reduce memory usage, for compression, decompression and testing. Files
+are decompressed and tested using a modified algorithm which only
+requires 2.5 bytes per block byte. This means any file can be
+decompressed in 2300k of memory, albeit at about half the normal speed.
+
+During compression, \-s selects a block size of 200k, which limits
+memory use to around the same figure, at the expense of your compression
+ratio. In short, if your machine is low on memory (8 megabytes or
+less), use \-s for everything. See MEMORY MANAGEMENT below.
+.TP
+.B \-q --quiet
+Suppress non-essential warning messages. Messages pertaining to
+I/O errors and other critical events will not be suppressed.
+.TP
+.B \-v --verbose
+Verbose mode -- show the compression ratio for each file processed.
+Further \-v's increase the verbosity level, spewing out lots of
+information which is primarily of interest for diagnostic purposes.
+.TP
+.B \-L --license -V --version
+Display the software version, license terms and conditions.
+.TP
+.B \-1 (or \-\-fast) to \-9 (or \-\-best)
+Set the block size to 100 k, 200 k .. 900 k when compressing. Has no
+effect when decompressing. See MEMORY MANAGEMENT below.
+The \-\-fast and \-\-best aliases are primarily for GNU gzip
+compatibility. In particular, \-\-fast doesn't make things
+significantly faster.
+And \-\-best merely selects the default behaviour.
+.TP
+.B \--
+Treats all subsequent arguments as file names, even if they start
+with a dash. This is so you can handle files with names beginning
+with a dash, for example: bzip2 \-- \-myfilename.
+.TP
+.B \--repetitive-fast --repetitive-best
+These flags are redundant in versions 0.9.5 and above. They provided
+some coarse control over the behaviour of the sorting algorithm in
+earlier versions, which was sometimes useful. 0.9.5 and above have an
+improved algorithm which renders these flags irrelevant.
+
+.SH MEMORY MANAGEMENT
+.I bzip2
+compresses large files in blocks. The block size affects
+both the compression ratio achieved, and the amount of memory needed for
+compression and decompression. The flags \-1 through \-9
+specify the block size to be 100,000 bytes through 900,000 bytes (the
+default) respectively. At decompression time, the block size used for
+compression is read from the header of the compressed file, and
+.I bunzip2
+then allocates itself just enough memory to decompress
+the file. Since block sizes are stored in compressed files, it follows
+that the flags \-1 to \-9 are irrelevant to and so ignored
+during decompression.
+
+Compression and decompression requirements,
+in bytes, can be estimated as:
+
+ Compression: 400k + ( 8 x block size )
+
+ Decompression: 100k + ( 4 x block size ), or
+ 100k + ( 2.5 x block size )
+
+Larger block sizes give rapidly diminishing marginal returns. Most of
+the compression comes from the first two or three hundred k of block
+size, a fact worth bearing in mind when using
+.I bzip2
+on small machines.
+It is also important to appreciate that the decompression memory
+requirement is set at compression time by the choice of block size.
+
+For files compressed with the default 900k block size,
+.I bunzip2
+will require about 3700 kbytes to decompress. To support decompression
+of any file on a 4 megabyte machine,
+.I bunzip2
+has an option to
+decompress using approximately half this amount of memory, about 2300
+kbytes. Decompression speed is also halved, so you should use this
+option only where necessary. The relevant flag is -s.
+
+In general, try and use the largest block size memory constraints allow,
+since that maximises the compression achieved. Compression and
+decompression speed are virtually unaffected by block size.
+
+Another significant point applies to files which fit in a single block
+-- that means most files you'd encounter using a large block size. The
+amount of real memory touched is proportional to the size of the file,
+since the file is smaller than a block. For example, compressing a file
+20,000 bytes long with the flag -9 will cause the compressor to
+allocate around 7600k of memory, but only touch 400k + 20000 * 8 = 560
+kbytes of it. Similarly, the decompressor will allocate 3700k but only
+touch 100k + 20000 * 4 = 180 kbytes.
+
+Here is a table which summarises the maximum memory usage for different
+block sizes. Also recorded is the total compressed size for 14 files of
+the Calgary Text Compression Corpus totalling 3,141,622 bytes. This
+column gives some feel for how compression varies with block size.
+These figures tend to understate the advantage of larger block sizes for
+larger files, since the Corpus is dominated by smaller files.
+
+ Compress Decompress Decompress Corpus
+ Flag usage usage -s usage Size
+
+ -1 1200k 500k 350k 914704
+ -2 2000k 900k 600k 877703
+ -3 2800k 1300k 850k 860338
+ -4 3600k 1700k 1100k 846899
+ -5 4400k 2100k 1350k 845160
+ -6 5200k 2500k 1600k 838626
+ -7 6100k 2900k 1850k 834096
+ -8 6800k 3300k 2100k 828642
+ -9 7600k 3700k 2350k 828642
+
+.SH RECOVERING DATA FROM DAMAGED FILES
+.I bzip2
+compresses files in blocks, usually 900kbytes long. Each
+block is handled independently. If a media or transmission error causes
+a multi-block .bz2
+file to become damaged, it may be possible to
+recover data from the undamaged blocks in the file.
+
+The compressed representation of each block is delimited by a 48-bit
+pattern, which makes it possible to find the block boundaries with
+reasonable certainty. Each block also carries its own 32-bit CRC, so
+damaged blocks can be distinguished from undamaged ones.
+
+.I bzip2recover
+is a simple program whose purpose is to search for
+blocks in .bz2 files, and write each block out into its own .bz2
+file. You can then use
+.I bzip2
+\-t
+to test the
+integrity of the resulting files, and decompress those which are
+undamaged.
+
+.I bzip2recover
+takes a single argument, the name of the damaged file,
+and writes a number of files "rec00001file.bz2",
+"rec00002file.bz2", etc, containing the extracted blocks.
+The output filenames are designed so that the use of
+wildcards in subsequent processing -- for example,
+"bzip2 -dc rec*file.bz2 > recovered_data" -- processes the files in
+the correct order.
+
+.I bzip2recover
+should be of most use dealing with large .bz2
+files, as these will contain many blocks. It is clearly
+futile to use it on damaged single-block files, since a
+damaged block cannot be recovered. If you wish to minimise
+any potential data loss through media or transmission errors,
+you might consider compressing with a smaller
+block size.
+
+.SH PERFORMANCE NOTES
+The sorting phase of compression gathers together similar strings in the
+file. Because of this, files containing very long runs of repeated
+symbols, like "aabaabaabaab ..." (repeated several hundred times) may
+compress more slowly than normal. Versions 0.9.5 and above fare much
+better than previous versions in this respect. The ratio between
+worst-case and average-case compression time is in the region of 10:1.
+For previous versions, this figure was more like 100:1. You can use the
+\-vvvv option to monitor progress in great detail, if you want.
+
+Decompression speed is unaffected by these phenomena.
+
+.I bzip2
+usually allocates several megabytes of memory to operate
+in, and then charges all over it in a fairly random fashion. This means
+that performance, both for compressing and decompressing, is largely
+determined by the speed at which your machine can service cache misses.
+Because of this, small changes to the code to reduce the miss rate have
+been observed to give disproportionately large performance improvements.
+I imagine
+.I bzip2
+will perform best on machines with very large caches.
+
+.SH CAVEATS
+I/O error messages are not as helpful as they could be.
+.I bzip2
+tries hard to detect I/O errors and exit cleanly, but the details of
+what the problem is sometimes seem rather misleading.
+
+This manual page pertains to version 1.0.4 of
+.I bzip2.
+Compressed data created by this version is entirely forwards and
+backwards compatible with the previous public releases, versions
+0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1, 1.0.2 and 1.0.3, but with the following
+exception: 0.9.0 and above can correctly decompress multiple
+concatenated compressed files. 0.1pl2 cannot do this; it will stop
+after decompressing just the first file in the stream.
+
+.I bzip2recover
+versions prior to 1.0.2 used 32-bit integers to represent
+bit positions in compressed files, so they could not handle compressed
+files more than 512 megabytes long. Versions 1.0.2 and above use
+64-bit ints on some platforms which support them (GNU supported
+targets, and Windows). To establish whether or not bzip2recover was
+built with such a limitation, run it without arguments. In any event
+you can build yourself an unlimited version if you can recompile it
+with MaybeUInt64 set to be an unsigned 64-bit integer.
+
+
+
+.SH AUTHOR
+Julian Seward, jsewardbzip.org.
+
+http://www.bzip.org
+
+The ideas embodied in
+.I bzip2
+are due to (at least) the following
+people: Michael Burrows and David Wheeler (for the block sorting
+transformation), David Wheeler (again, for the Huffman coder), Peter
+Fenwick (for the structured coding model in the original
+.I bzip,
+and many refinements), and Alistair Moffat, Radford Neal and Ian Witten
+(for the arithmetic coder in the original
+.I bzip).
+I am much
+indebted for their help, support and advice. See the manual in the
+source distribution for pointers to sources of documentation. Christian
+von Roques encouraged me to look for faster sorting algorithms, so as to
+speed up compression. Bela Lubkin encouraged me to improve the
+worst-case compression performance.
+Donna Robinson XMLised the documentation.
+The bz* scripts are derived from those of GNU gzip.
+Many people sent patches, helped
+with portability problems, lent machines, gave advice and were generally
+helpful.
diff --git a/Utilities/cmbzip2/bzip2.1.preformatted b/Utilities/cmbzip2/bzip2.1.preformatted
new file mode 100644
index 0000000000..15e16e50ab
--- /dev/null
+++ b/Utilities/cmbzip2/bzip2.1.preformatted
@@ -0,0 +1,399 @@
+bzip2(1) bzip2(1)
+
+
+
+NNAAMMEE
+ bzip2, bunzip2 − a blockâ€sorting file compressor, v1.0.4
+ bzcat − decompresses files to stdout
+ bzip2recover − recovers data from damaged bzip2 files
+
+
+SSYYNNOOPPSSIISS
+ bbzziipp22 [ −−ccddffkkqqssttvvzzVVLL112233445566778899 ] [ _f_i_l_e_n_a_m_e_s _._._. ]
+ bbuunnzziipp22 [ −−ffkkvvssVVLL ] [ _f_i_l_e_n_a_m_e_s _._._. ]
+ bbzzccaatt [ −−ss ] [ _f_i_l_e_n_a_m_e_s _._._. ]
+ bbzziipp22rreeccoovveerr _f_i_l_e_n_a_m_e
+
+
+DDEESSCCRRIIPPTTIIOONN
+ _b_z_i_p_2 compresses files using the Burrowsâ€Wheeler block
+ sorting text compression algorithm, and Huffman coding.
+ Compression is generally considerably better than that
+ achieved by more conventional LZ77/LZ78â€based compressors,
+ and approaches the performance of the PPM family of sta­
+ tistical compressors.
+
+ The commandâ€line options are deliberately very similar to
+ those of _G_N_U _g_z_i_p_, but they are not identical.
+
+ _b_z_i_p_2 expects a list of file names to accompany the com­
+ mandâ€line flags. Each file is replaced by a compressed
+ version of itself, with the name "original_name.bz2".
+ Each compressed file has the same modification date, per­
+ missions, and, when possible, ownership as the correspond­
+ ing original, so that these properties can be correctly
+ restored at decompression time. File name handling is
+ naive in the sense that there is no mechanism for preserv­
+ ing original file names, permissions, ownerships or dates
+ in filesystems which lack these concepts, or have serious
+ file name length restrictions, such as MSâ€DOS.
+
+ _b_z_i_p_2 and _b_u_n_z_i_p_2 will by default not overwrite existing
+ files. If you want this to happen, specify the −f flag.
+
+ If no file names are specified, _b_z_i_p_2 compresses from
+ standard input to standard output. In this case, _b_z_i_p_2
+ will decline to write compressed output to a terminal, as
+ this would be entirely incomprehensible and therefore
+ pointless.
+
+ _b_u_n_z_i_p_2 (or _b_z_i_p_2 _−_d_) decompresses all specified files.
+ Files which were not created by _b_z_i_p_2 will be detected and
+ ignored, and a warning issued. _b_z_i_p_2 attempts to guess
+ the filename for the decompressed file from that of the
+ compressed file as follows:
+
+ filename.bz2 becomes filename
+ filename.bz becomes filename
+ filename.tbz2 becomes filename.tar
+ filename.tbz becomes filename.tar
+ anyothername becomes anyothername.out
+
+ If the file does not end in one of the recognised endings,
+ _._b_z_2_, _._b_z_, _._t_b_z_2 or _._t_b_z_, _b_z_i_p_2 complains that it cannot
+ guess the name of the original file, and uses the original
+ name with _._o_u_t appended.
+
+ As with compression, supplying no filenames causes decom­
+ pression from standard input to standard output.
+
+ _b_u_n_z_i_p_2 will correctly decompress a file which is the con­
+ catenation of two or more compressed files. The result is
+ the concatenation of the corresponding uncompressed files.
+ Integrity testing (−t) of concatenated compressed files is
+ also supported.
+
+ You can also compress or decompress files to the standard
+ output by giving the −c flag. Multiple files may be com­
+ pressed and decompressed like this. The resulting outputs
+ are fed sequentially to stdout. Compression of multiple
+ files in this manner generates a stream containing multi­
+ ple compressed file representations. Such a stream can be
+ decompressed correctly only by _b_z_i_p_2 version 0.9.0 or
+ later. Earlier versions of _b_z_i_p_2 will stop after decom­
+ pressing the first file in the stream.
+
+ _b_z_c_a_t (or _b_z_i_p_2 _â€_d_c_) decompresses all specified files to
+ the standard output.
+
+ _b_z_i_p_2 will read arguments from the environment variables
+ _B_Z_I_P_2 and _B_Z_I_P_, in that order, and will process them
+ before any arguments read from the command line. This
+ gives a convenient way to supply default arguments.
+
+ Compression is always performed, even if the compressed
+ file is slightly larger than the original. Files of less
+ than about one hundred bytes tend to get larger, since the
+ compression mechanism has a constant overhead in the
+ region of 50 bytes. Random data (including the output of
+ most file compressors) is coded at about 8.05 bits per
+ byte, giving an expansion of around 0.5%.
+
+ As a selfâ€check for your protection, _b_z_i_p_2 uses 32â€bit
+ CRCs to make sure that the decompressed version of a file
+ is identical to the original. This guards against corrup­
+ tion of the compressed data, and against undetected bugs
+ in _b_z_i_p_2 (hopefully very unlikely). The chances of data
+ corruption going undetected is microscopic, about one
+ chance in four billion for each file processed. Be aware,
+ though, that the check occurs upon decompression, so it
+ can only tell you that something is wrong. It can’t help
+ you recover the original uncompressed data. You can use
+ _b_z_i_p_2_r_e_c_o_v_e_r to try to recover data from damaged files.
+
+ Return values: 0 for a normal exit, 1 for environmental
+ problems (file not found, invalid flags, I/O errors, &c),
+ 2 to indicate a corrupt compressed file, 3 for an internal
+ consistency error (eg, bug) which caused _b_z_i_p_2 to panic.
+
+
+OOPPTTIIOONNSS
+ −−cc â€â€â€â€ssttddoouutt
+ Compress or decompress to standard output.
+
+ −−dd â€â€â€â€ddeeccoommpprreessss
+ Force decompression. _b_z_i_p_2_, _b_u_n_z_i_p_2 and _b_z_c_a_t are
+ really the same program, and the decision about
+ what actions to take is done on the basis of which
+ name is used. This flag overrides that mechanism,
+ and forces _b_z_i_p_2 to decompress.
+
+ −−zz â€â€â€â€ccoommpprreessss
+ The complement to −d: forces compression,
+ regardless of the invocation name.
+
+ −−tt â€â€â€â€tteesstt
+ Check integrity of the specified file(s), but don’t
+ decompress them. This really performs a trial
+ decompression and throws away the result.
+
+ −−ff â€â€â€â€ffoorrccee
+ Force overwrite of output files. Normally, _b_z_i_p_2
+ will not overwrite existing output files. Also
+ forces _b_z_i_p_2 to break hard links to files, which it
+ otherwise wouldn’t do.
+
+ bzip2 normally declines to decompress files which
+ don’t have the correct magic header bytes. If
+ forced (â€f), however, it will pass such files
+ through unmodified. This is how GNU gzip behaves.
+
+ −−kk â€â€â€â€kkeeeepp
+ Keep (don’t delete) input files during compression
+ or decompression.
+
+ −−ss â€â€â€â€ssmmaallll
+ Reduce memory usage, for compression, decompression
+ and testing. Files are decompressed and tested
+ using a modified algorithm which only requires 2.5
+ bytes per block byte. This means any file can be
+ decompressed in 2300k of memory, albeit at about
+ half the normal speed.
+
+ During compression, −s selects a block size of
+ 200k, which limits memory use to around the same
+ figure, at the expense of your compression ratio.
+ In short, if your machine is low on memory (8
+ megabytes or less), use −s for everything. See
+ MEMORY MANAGEMENT below.
+
+ −−qq â€â€â€â€qquuiieett
+ Suppress nonâ€essential warning messages. Messages
+ pertaining to I/O errors and other critical events
+ will not be suppressed.
+
+ −−vv â€â€â€â€vveerrbboossee
+ Verbose mode â€â€ show the compression ratio for each
+ file processed. Further −v’s increase the ver­
+ bosity level, spewing out lots of information which
+ is primarily of interest for diagnostic purposes.
+
+ −−LL â€â€â€â€lliicceennssee â€â€VV â€â€â€â€vveerrssiioonn
+ Display the software version, license terms and
+ conditions.
+
+ −−11 ((oorr −−−−ffaasstt)) ttoo −−99 ((oorr −−−−bbeesstt))
+ Set the block size to 100 k, 200 k .. 900 k when
+ compressing. Has no effect when decompressing.
+ See MEMORY MANAGEMENT below. The −−fast and −−best
+ aliases are primarily for GNU gzip compatibility.
+ In particular, −−fast doesn’t make things signifi­
+ cantly faster. And −−best merely selects the
+ default behaviour.
+
+ −− Treats all subsequent arguments as file names, even
+ if they start with a dash. This is so you can han­
+ dle files with names beginning with a dash, for
+ example: bzip2 −†−myfilename.
+
+ −−â€â€rreeppeettiittiivveeâ€â€ffaasstt â€â€â€â€rreeppeettiittiivveeâ€â€bbeesstt
+ These flags are redundant in versions 0.9.5 and
+ above. They provided some coarse control over the
+ behaviour of the sorting algorithm in earlier ver­
+ sions, which was sometimes useful. 0.9.5 and above
+ have an improved algorithm which renders these
+ flags irrelevant.
+
+
+MMEEMMOORRYY MMAANNAAGGEEMMEENNTT
+ _b_z_i_p_2 compresses large files in blocks. The block size
+ affects both the compression ratio achieved, and the
+ amount of memory needed for compression and decompression.
+ The flags −1 through −9 specify the block size to be
+ 100,000 bytes through 900,000 bytes (the default) respec­
+ tively. At decompression time, the block size used for
+ compression is read from the header of the compressed
+ file, and _b_u_n_z_i_p_2 then allocates itself just enough memory
+ to decompress the file. Since block sizes are stored in
+ compressed files, it follows that the flags −1 to −9 are
+ irrelevant to and so ignored during decompression.
+
+ Compression and decompression requirements, in bytes, can
+ be estimated as:
+
+ Compression: 400k + ( 8 x block size )
+
+ Decompression: 100k + ( 4 x block size ), or
+ 100k + ( 2.5 x block size )
+
+ Larger block sizes give rapidly diminishing marginal
+ returns. Most of the compression comes from the first two
+ or three hundred k of block size, a fact worth bearing in
+ mind when using _b_z_i_p_2 on small machines. It is also
+ important to appreciate that the decompression memory
+ requirement is set at compression time by the choice of
+ block size.
+
+ For files compressed with the default 900k block size,
+ _b_u_n_z_i_p_2 will require about 3700 kbytes to decompress. To
+ support decompression of any file on a 4 megabyte machine,
+ _b_u_n_z_i_p_2 has an option to decompress using approximately
+ half this amount of memory, about 2300 kbytes. Decompres­
+ sion speed is also halved, so you should use this option
+ only where necessary. The relevant flag is â€s.
+
+ In general, try and use the largest block size memory con­
+ straints allow, since that maximises the compression
+ achieved. Compression and decompression speed are virtu­
+ ally unaffected by block size.
+
+ Another significant point applies to files which fit in a
+ single block â€â€ that means most files you’d encounter
+ using a large block size. The amount of real memory
+ touched is proportional to the size of the file, since the
+ file is smaller than a block. For example, compressing a
+ file 20,000 bytes long with the flag â€9 will cause the
+ compressor to allocate around 7600k of memory, but only
+ touch 400k + 20000 * 8 = 560 kbytes of it. Similarly, the
+ decompressor will allocate 3700k but only touch 100k +
+ 20000 * 4 = 180 kbytes.
+
+ Here is a table which summarises the maximum memory usage
+ for different block sizes. Also recorded is the total
+ compressed size for 14 files of the Calgary Text Compres­
+ sion Corpus totalling 3,141,622 bytes. This column gives
+ some feel for how compression varies with block size.
+ These figures tend to understate the advantage of larger
+ block sizes for larger files, since the Corpus is domi­
+ nated by smaller files.
+
+ Compress Decompress Decompress Corpus
+ Flag usage usage â€s usage Size
+
+ â€1 1200k 500k 350k 914704
+ â€2 2000k 900k 600k 877703
+ â€3 2800k 1300k 850k 860338
+ â€4 3600k 1700k 1100k 846899
+ â€5 4400k 2100k 1350k 845160
+ â€6 5200k 2500k 1600k 838626
+ â€7 6100k 2900k 1850k 834096
+ â€8 6800k 3300k 2100k 828642
+ â€9 7600k 3700k 2350k 828642
+
+
+RREECCOOVVEERRIINNGG DDAATTAA FFRROOMM DDAAMMAAGGEEDD FFIILLEESS
+ _b_z_i_p_2 compresses files in blocks, usually 900kbytes long.
+ Each block is handled independently. If a media or trans­
+ mission error causes a multiâ€block .bz2 file to become
+ damaged, it may be possible to recover data from the
+ undamaged blocks in the file.
+
+ The compressed representation of each block is delimited
+ by a 48â€bit pattern, which makes it possible to find the
+ block boundaries with reasonable certainty. Each block
+ also carries its own 32â€bit CRC, so damaged blocks can be
+ distinguished from undamaged ones.
+
+ _b_z_i_p_2_r_e_c_o_v_e_r is a simple program whose purpose is to
+ search for blocks in .bz2 files, and write each block out
+ into its own .bz2 file. You can then use _b_z_i_p_2 −t to test
+ the integrity of the resulting files, and decompress those
+ which are undamaged.
+
+ _b_z_i_p_2_r_e_c_o_v_e_r takes a single argument, the name of the dam­
+ aged file, and writes a number of files
+ "rec00001file.bz2", "rec00002file.bz2", etc, containing
+ the extracted blocks. The output filenames are
+ designed so that the use of wildcards in subsequent pro­
+ cessing â€â€ for example, "bzip2 â€dc rec*file.bz2 > recov­
+ ered_data" â€â€ processes the files in the correct order.
+
+ _b_z_i_p_2_r_e_c_o_v_e_r should be of most use dealing with large .bz2
+ files, as these will contain many blocks. It is clearly
+ futile to use it on damaged singleâ€block files, since a
+ damaged block cannot be recovered. If you wish to min­
+ imise any potential data loss through media or transmis­
+ sion errors, you might consider compressing with a smaller
+ block size.
+
+
+PPEERRFFOORRMMAANNCCEE NNOOTTEESS
+ The sorting phase of compression gathers together similar
+ strings in the file. Because of this, files containing
+ very long runs of repeated symbols, like "aabaabaabaab
+ ..." (repeated several hundred times) may compress more
+ slowly than normal. Versions 0.9.5 and above fare much
+ better than previous versions in this respect. The ratio
+ between worstâ€case and averageâ€case compression time is in
+ the region of 10:1. For previous versions, this figure
+ was more like 100:1. You can use the −vvvv option to mon­
+ itor progress in great detail, if you want.
+
+ Decompression speed is unaffected by these phenomena.
+
+ _b_z_i_p_2 usually allocates several megabytes of memory to
+ operate in, and then charges all over it in a fairly ran­
+ dom fashion. This means that performance, both for com­
+ pressing and decompressing, is largely determined by the
+ speed at which your machine can service cache misses.
+ Because of this, small changes to the code to reduce the
+ miss rate have been observed to give disproportionately
+ large performance improvements. I imagine _b_z_i_p_2 will per­
+ form best on machines with very large caches.
+
+
+CCAAVVEEAATTSS
+ I/O error messages are not as helpful as they could be.
+ _b_z_i_p_2 tries hard to detect I/O errors and exit cleanly,
+ but the details of what the problem is sometimes seem
+ rather misleading.
+
+ This manual page pertains to version 1.0.4 of _b_z_i_p_2_. Com­
+ pressed data created by this version is entirely forwards
+ and backwards compatible with the previous public
+ releases, versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
+ 1.0.2 and 1.0.3, but with the following exception: 0.9.0
+ and above can correctly decompress multiple concatenated
+ compressed files. 0.1pl2 cannot do this; it will stop
+ after decompressing just the first file in the stream.
+
+ _b_z_i_p_2_r_e_c_o_v_e_r versions prior to 1.0.2 used 32â€bit integers
+ to represent bit positions in compressed files, so they
+ could not handle compressed files more than 512 megabytes
+ long. Versions 1.0.2 and above use 64â€bit ints on some
+ platforms which support them (GNU supported targets, and
+ Windows). To establish whether or not bzip2recover was
+ built with such a limitation, run it without arguments.
+ In any event you can build yourself an unlimited version
+ if you can recompile it with MaybeUInt64 set to be an
+ unsigned 64â€bit integer.
+
+
+
+
+AAUUTTHHOORR
+ Julian Seward, jsewardbzip.org.
+
+ http://www.bzip.org
+
+ The ideas embodied in _b_z_i_p_2 are due to (at least) the fol­
+ lowing people: Michael Burrows and David Wheeler (for the
+ block sorting transformation), David Wheeler (again, for
+ the Huffman coder), Peter Fenwick (for the structured cod­
+ ing model in the original _b_z_i_p_, and many refinements), and
+ Alistair Moffat, Radford Neal and Ian Witten (for the
+ arithmetic coder in the original _b_z_i_p_)_. I am much
+ indebted for their help, support and advice. See the man­
+ ual in the source distribution for pointers to sources of
+ documentation. Christian von Roques encouraged me to look
+ for faster sorting algorithms, so as to speed up compres­
+ sion. Bela Lubkin encouraged me to improve the worstâ€case
+ compression performance. Donna Robinson XMLised the docu­
+ mentation. The bz* scripts are derived from those of GNU
+ gzip. Many people sent patches, helped with portability
+ problems, lent machines, gave advice and were generally
+ helpful.
+
+
+
+ bzip2(1)
diff --git a/Utilities/cmbzip2/bzip2.c b/Utilities/cmbzip2/bzip2.c
new file mode 100644
index 0000000000..88e5f0936a
--- /dev/null
+++ b/Utilities/cmbzip2/bzip2.c
@@ -0,0 +1,2034 @@
+
+/*-----------------------------------------------------------*/
+/*--- A block-sorting, lossless compressor bzip2.c ---*/
+/*-----------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+/* Place a 1 beside your platform, and 0 elsewhere.
+ Generic 32-bit Unix.
+ Also works on 64-bit Unix boxes.
+ This is the default.
+*/
+#define BZ_UNIX 1
+
+/*--
+ Win32, as seen by Jacob Navia's excellent
+ port of (Chris Fraser & David Hanson)'s excellent
+ lcc compiler. Or with MS Visual C.
+ This is selected automatically if compiled by a compiler which
+ defines _WIN32, not including the Cygwin GCC.
+--*/
+#define BZ_LCCWIN32 0
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#undef BZ_LCCWIN32
+#define BZ_LCCWIN32 1
+#undef BZ_UNIX
+#define BZ_UNIX 0
+#endif
+
+
+/*---------------------------------------------*/
+/*--
+ Some stuff for all platforms.
+--*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <math.h>
+#include <errno.h>
+#include <ctype.h>
+#include "bzlib.h"
+
+#define ERROR_IF_EOF(i) { if ((i) == EOF) ioError(); }
+#define ERROR_IF_NOT_ZERO(i) { if ((i) != 0) ioError(); }
+#define ERROR_IF_MINUS_ONE(i) { if ((i) == (-1)) ioError(); }
+
+
+/*---------------------------------------------*/
+/*--
+ Platform-specific stuff.
+--*/
+
+#if BZ_UNIX
+# include <fcntl.h>
+# include <sys/types.h>
+# include <utime.h>
+# include <unistd.h>
+# include <sys/stat.h>
+# include <sys/times.h>
+
+# define PATH_SEP '/'
+# define MY_LSTAT lstat
+# define MY_STAT stat
+# define MY_S_ISREG S_ISREG
+# define MY_S_ISDIR S_ISDIR
+
+# define APPEND_FILESPEC(root, name) \
+ root=snocString((root), (name))
+
+# define APPEND_FLAG(root, name) \
+ root=snocString((root), (name))
+
+# define SET_BINARY_MODE(fd) /**/
+
+# ifdef __GNUC__
+# define NORETURN __attribute__ ((noreturn))
+# else
+# define NORETURN /**/
+# endif
+
+# ifdef __DJGPP__
+# include <io.h>
+# include <fcntl.h>
+# undef MY_LSTAT
+# undef MY_STAT
+# define MY_LSTAT stat
+# define MY_STAT stat
+# undef SET_BINARY_MODE
+# define SET_BINARY_MODE(fd) \
+ do { \
+ int retVal = setmode ( fileno ( fd ), \
+ O_BINARY ); \
+ ERROR_IF_MINUS_ONE ( retVal ); \
+ } while ( 0 )
+# endif
+
+# ifdef __CYGWIN__
+# include <io.h>
+# include <fcntl.h>
+# undef SET_BINARY_MODE
+# define SET_BINARY_MODE(fd) \
+ do { \
+ int retVal = setmode ( fileno ( fd ), \
+ O_BINARY ); \
+ ERROR_IF_MINUS_ONE ( retVal ); \
+ } while ( 0 )
+# endif
+#endif /* BZ_UNIX */
+
+
+
+#if BZ_LCCWIN32
+# include <io.h>
+# include <fcntl.h>
+# include <sys\stat.h>
+
+# define NORETURN /**/
+# define PATH_SEP '\\'
+# define MY_LSTAT _stat
+# define MY_STAT _stat
+# define MY_S_ISREG(x) ((x) & _S_IFREG)
+# define MY_S_ISDIR(x) ((x) & _S_IFDIR)
+
+# define APPEND_FLAG(root, name) \
+ root=snocString((root), (name))
+
+# define APPEND_FILESPEC(root, name) \
+ root = snocString ((root), (name))
+
+# define SET_BINARY_MODE(fd) \
+ do { \
+ int retVal = setmode ( fileno ( fd ), \
+ O_BINARY ); \
+ ERROR_IF_MINUS_ONE ( retVal ); \
+ } while ( 0 )
+
+#endif /* BZ_LCCWIN32 */
+
+
+/*---------------------------------------------*/
+/*--
+ Some more stuff for all platforms :-)
+--*/
+
+typedef char Char;
+typedef unsigned char Bool;
+typedef unsigned char UChar;
+typedef int Int32;
+typedef unsigned int UInt32;
+typedef short Int16;
+typedef unsigned short UInt16;
+
+#define True ((Bool)1)
+#define False ((Bool)0)
+
+/*--
+ IntNative is your platform's `native' int size.
+ Only here to avoid probs with 64-bit platforms.
+--*/
+typedef int IntNative;
+
+
+/*---------------------------------------------------*/
+/*--- Misc (file handling) data decls ---*/
+/*---------------------------------------------------*/
+
+Int32 verbosity;
+Bool keepInputFiles, smallMode, deleteOutputOnInterrupt;
+Bool forceOverwrite, testFailsExist, unzFailsExist, noisy;
+Int32 numFileNames, numFilesProcessed, blockSize100k;
+Int32 exitValue;
+
+/*-- source modes; F==file, I==stdin, O==stdout --*/
+#define SM_I2O 1
+#define SM_F2O 2
+#define SM_F2F 3
+
+/*-- operation modes --*/
+#define OM_Z 1
+#define OM_UNZ 2
+#define OM_TEST 3
+
+Int32 opMode;
+Int32 srcMode;
+
+#define FILE_NAME_LEN 1034
+
+Int32 longestFileName;
+Char inName [FILE_NAME_LEN];
+Char outName[FILE_NAME_LEN];
+Char tmpName[FILE_NAME_LEN];
+Char *progName;
+Char progNameReally[FILE_NAME_LEN];
+FILE *outputHandleJustInCase;
+Int32 workFactor;
+
+static void panic ( const Char* ) NORETURN;
+static void ioError ( void ) NORETURN;
+static void outOfMemory ( void ) NORETURN;
+static void configError ( void ) NORETURN;
+static void crcError ( void ) NORETURN;
+static void cleanUpAndFail ( Int32 ) NORETURN;
+static void compressedStreamEOF ( void ) NORETURN;
+
+static void copyFileName ( Char*, Char* );
+static void* myMalloc ( Int32 );
+static void applySavedFileAttrToOutputFile ( IntNative fd );
+
+
+
+/*---------------------------------------------------*/
+/*--- An implementation of 64-bit ints. Sigh. ---*/
+/*--- Roll on widespread deployment of ANSI C9X ! ---*/
+/*---------------------------------------------------*/
+
+typedef
+ struct { UChar b[8]; }
+ UInt64;
+
+
+static
+void uInt64_from_UInt32s ( UInt64* n, UInt32 lo32, UInt32 hi32 )
+{
+ n->b[7] = (UChar)((hi32 >> 24) & 0xFF);
+ n->b[6] = (UChar)((hi32 >> 16) & 0xFF);
+ n->b[5] = (UChar)((hi32 >> 8) & 0xFF);
+ n->b[4] = (UChar) (hi32 & 0xFF);
+ n->b[3] = (UChar)((lo32 >> 24) & 0xFF);
+ n->b[2] = (UChar)((lo32 >> 16) & 0xFF);
+ n->b[1] = (UChar)((lo32 >> 8) & 0xFF);
+ n->b[0] = (UChar) (lo32 & 0xFF);
+}
+
+
+static
+double uInt64_to_double ( UInt64* n )
+{
+ Int32 i;
+ double base = 1.0;
+ double sum = 0.0;
+ for (i = 0; i < 8; i++) {
+ sum += base * (double)(n->b[i]);
+ base *= 256.0;
+ }
+ return sum;
+}
+
+
+static
+Bool uInt64_isZero ( UInt64* n )
+{
+ Int32 i;
+ for (i = 0; i < 8; i++)
+ if (n->b[i] != 0) return 0;
+ return 1;
+}
+
+
+/* Divide *n by 10, and return the remainder. */
+static
+Int32 uInt64_qrm10 ( UInt64* n )
+{
+ UInt32 rem, tmp;
+ Int32 i;
+ rem = 0;
+ for (i = 7; i >= 0; i--) {
+ tmp = rem * 256 + n->b[i];
+ n->b[i] = tmp / 10;
+ rem = tmp % 10;
+ }
+ return rem;
+}
+
+
+/* ... and the Whole Entire Point of all this UInt64 stuff is
+ so that we can supply the following function.
+*/
+static
+void uInt64_toAscii ( char* outbuf, UInt64* n )
+{
+ Int32 i, q;
+ UChar buf[32];
+ Int32 nBuf = 0;
+ UInt64 n_copy = *n;
+ do {
+ q = uInt64_qrm10 ( &n_copy );
+ buf[nBuf] = q + '0';
+ nBuf++;
+ } while (!uInt64_isZero(&n_copy));
+ outbuf[nBuf] = 0;
+ for (i = 0; i < nBuf; i++)
+ outbuf[i] = buf[nBuf-i-1];
+}
+
+
+/*---------------------------------------------------*/
+/*--- Processing of complete files and streams ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------*/
+static
+Bool myfeof ( FILE* f )
+{
+ Int32 c = fgetc ( f );
+ if (c == EOF) return True;
+ ungetc ( c, f );
+ return False;
+}
+
+
+/*---------------------------------------------*/
+static
+void compressStream ( FILE *stream, FILE *zStream )
+{
+ BZFILE* bzf = NULL;
+ UChar ibuf[5000];
+ Int32 nIbuf;
+ UInt32 nbytes_in_lo32, nbytes_in_hi32;
+ UInt32 nbytes_out_lo32, nbytes_out_hi32;
+ Int32 bzerr, bzerr_dummy, ret;
+
+ SET_BINARY_MODE(stream);
+ SET_BINARY_MODE(zStream);
+
+ if (ferror(stream)) goto errhandler_io;
+ if (ferror(zStream)) goto errhandler_io;
+
+ bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
+ blockSize100k, verbosity, workFactor );
+ if (bzerr != BZ_OK) goto errhandler;
+
+ if (verbosity >= 2) fprintf ( stderr, "\n" );
+
+ while (True) {
+
+ if (myfeof(stream)) break;
+ nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream );
+ if (ferror(stream)) goto errhandler_io;
+ if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
+ if (bzerr != BZ_OK) goto errhandler;
+
+ }
+
+ BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
+ &nbytes_in_lo32, &nbytes_in_hi32,
+ &nbytes_out_lo32, &nbytes_out_hi32 );
+ if (bzerr != BZ_OK) goto errhandler;
+
+ if (ferror(zStream)) goto errhandler_io;
+ ret = fflush ( zStream );
+ if (ret == EOF) goto errhandler_io;
+ if (zStream != stdout) {
+ Int32 fd = fileno ( zStream );
+ if (fd < 0) goto errhandler_io;
+ applySavedFileAttrToOutputFile ( fd );
+ ret = fclose ( zStream );
+ outputHandleJustInCase = NULL;
+ if (ret == EOF) goto errhandler_io;
+ }
+ outputHandleJustInCase = NULL;
+ if (ferror(stream)) goto errhandler_io;
+ ret = fclose ( stream );
+ if (ret == EOF) goto errhandler_io;
+
+ if (verbosity >= 1) {
+ if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
+ fprintf ( stderr, " no data compressed.\n");
+ } else {
+ Char buf_nin[32], buf_nout[32];
+ UInt64 nbytes_in, nbytes_out;
+ double nbytes_in_d, nbytes_out_d;
+ uInt64_from_UInt32s ( &nbytes_in,
+ nbytes_in_lo32, nbytes_in_hi32 );
+ uInt64_from_UInt32s ( &nbytes_out,
+ nbytes_out_lo32, nbytes_out_hi32 );
+ nbytes_in_d = uInt64_to_double ( &nbytes_in );
+ nbytes_out_d = uInt64_to_double ( &nbytes_out );
+ uInt64_toAscii ( buf_nin, &nbytes_in );
+ uInt64_toAscii ( buf_nout, &nbytes_out );
+ fprintf ( stderr, "%6.3f:1, %6.3f bits/byte, "
+ "%5.2f%% saved, %s in, %s out.\n",
+ nbytes_in_d / nbytes_out_d,
+ (8.0 * nbytes_out_d) / nbytes_in_d,
+ 100.0 * (1.0 - nbytes_out_d / nbytes_in_d),
+ buf_nin,
+ buf_nout
+ );
+ }
+ }
+
+ return;
+
+ errhandler:
+ BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1,
+ &nbytes_in_lo32, &nbytes_in_hi32,
+ &nbytes_out_lo32, &nbytes_out_hi32 );
+ switch (bzerr) {
+ case BZ_CONFIG_ERROR:
+ configError(); break;
+ case BZ_MEM_ERROR:
+ outOfMemory (); break;
+ case BZ_IO_ERROR:
+ errhandler_io:
+ ioError(); break;
+ default:
+ panic ( "compress:unexpected error" );
+ }
+
+ panic ( "compress:end" );
+ /*notreached*/
+}
+
+
+
+/*---------------------------------------------*/
+static
+Bool uncompressStream ( FILE *zStream, FILE *stream )
+{
+ BZFILE* bzf = NULL;
+ Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
+ UChar obuf[5000];
+ UChar unused[BZ_MAX_UNUSED];
+ Int32 nUnused;
+ void* unusedTmpV;
+ UChar* unusedTmp;
+
+ nUnused = 0;
+ streamNo = 0;
+
+ SET_BINARY_MODE(stream);
+ SET_BINARY_MODE(zStream);
+
+ if (ferror(stream)) goto errhandler_io;
+ if (ferror(zStream)) goto errhandler_io;
+
+ while (True) {
+
+ bzf = BZ2_bzReadOpen (
+ &bzerr, zStream, verbosity,
+ (int)smallMode, unused, nUnused
+ );
+ if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
+ streamNo++;
+
+ while (bzerr == BZ_OK) {
+ nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
+ if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat;
+ if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
+ fwrite ( obuf, sizeof(UChar), nread, stream );
+ if (ferror(stream)) goto errhandler_io;
+ }
+ if (bzerr != BZ_STREAM_END) goto errhandler;
+
+ BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
+ if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
+
+ unusedTmp = (UChar*)unusedTmpV;
+ for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
+
+ BZ2_bzReadClose ( &bzerr, bzf );
+ if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
+
+ if (nUnused == 0 && myfeof(zStream)) break;
+ }
+
+ closeok:
+ if (ferror(zStream)) goto errhandler_io;
+ if (stream != stdout) {
+ Int32 fd = fileno ( stream );
+ if (fd < 0) goto errhandler_io;
+ applySavedFileAttrToOutputFile ( fd );
+ }
+ ret = fclose ( zStream );
+ if (ret == EOF) goto errhandler_io;
+
+ if (ferror(stream)) goto errhandler_io;
+ ret = fflush ( stream );
+ if (ret != 0) goto errhandler_io;
+ if (stream != stdout) {
+ ret = fclose ( stream );
+ outputHandleJustInCase = NULL;
+ if (ret == EOF) goto errhandler_io;
+ }
+ outputHandleJustInCase = NULL;
+ if (verbosity >= 2) fprintf ( stderr, "\n " );
+ return True;
+
+ trycat:
+ if (forceOverwrite) {
+ rewind(zStream);
+ while (True) {
+ if (myfeof(zStream)) break;
+ nread = fread ( obuf, sizeof(UChar), 5000, zStream );
+ if (ferror(zStream)) goto errhandler_io;
+ if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
+ if (ferror(stream)) goto errhandler_io;
+ }
+ goto closeok;
+ }
+
+ errhandler:
+ BZ2_bzReadClose ( &bzerr_dummy, bzf );
+ switch (bzerr) {
+ case BZ_CONFIG_ERROR:
+ configError(); break;
+ case BZ_IO_ERROR:
+ errhandler_io:
+ ioError(); break;
+ case BZ_DATA_ERROR:
+ crcError();
+ case BZ_MEM_ERROR:
+ outOfMemory();
+ case BZ_UNEXPECTED_EOF:
+ compressedStreamEOF();
+ case BZ_DATA_ERROR_MAGIC:
+ if (zStream != stdin) fclose(zStream);
+ if (stream != stdout) fclose(stream);
+ if (streamNo == 1) {
+ return False;
+ } else {
+ if (noisy)
+ fprintf ( stderr,
+ "\n%s: %s: trailing garbage after EOF ignored\n",
+ progName, inName );
+ return True;
+ }
+ default:
+ panic ( "decompress:unexpected error" );
+ }
+
+ panic ( "decompress:end" );
+ return True; /*notreached*/
+}
+
+
+/*---------------------------------------------*/
+static
+Bool testStream ( FILE *zStream )
+{
+ BZFILE* bzf = NULL;
+ Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
+ UChar obuf[5000];
+ UChar unused[BZ_MAX_UNUSED];
+ Int32 nUnused;
+ void* unusedTmpV;
+ UChar* unusedTmp;
+
+ nUnused = 0;
+ streamNo = 0;
+
+ SET_BINARY_MODE(zStream);
+ if (ferror(zStream)) goto errhandler_io;
+
+ while (True) {
+
+ bzf = BZ2_bzReadOpen (
+ &bzerr, zStream, verbosity,
+ (int)smallMode, unused, nUnused
+ );
+ if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
+ streamNo++;
+
+ while (bzerr == BZ_OK) {
+ nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
+ if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler;
+ }
+ if (bzerr != BZ_STREAM_END) goto errhandler;
+
+ BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
+ if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
+
+ unusedTmp = (UChar*)unusedTmpV;
+ for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
+
+ BZ2_bzReadClose ( &bzerr, bzf );
+ if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
+ if (nUnused == 0 && myfeof(zStream)) break;
+
+ }
+
+ if (ferror(zStream)) goto errhandler_io;
+ ret = fclose ( zStream );
+ if (ret == EOF) goto errhandler_io;
+
+ if (verbosity >= 2) fprintf ( stderr, "\n " );
+ return True;
+
+ errhandler:
+ BZ2_bzReadClose ( &bzerr_dummy, bzf );
+ if (verbosity == 0)
+ fprintf ( stderr, "%s: %s: ", progName, inName );
+ switch (bzerr) {
+ case BZ_CONFIG_ERROR:
+ configError(); break;
+ case BZ_IO_ERROR:
+ errhandler_io:
+ ioError(); break;
+ case BZ_DATA_ERROR:
+ fprintf ( stderr,
+ "data integrity (CRC) error in data\n" );
+ return False;
+ case BZ_MEM_ERROR:
+ outOfMemory();
+ case BZ_UNEXPECTED_EOF:
+ fprintf ( stderr,
+ "file ends unexpectedly\n" );
+ return False;
+ case BZ_DATA_ERROR_MAGIC:
+ if (zStream != stdin) fclose(zStream);
+ if (streamNo == 1) {
+ fprintf ( stderr,
+ "bad magic number (file not created by bzip2)\n" );
+ return False;
+ } else {
+ if (noisy)
+ fprintf ( stderr,
+ "trailing garbage after EOF ignored\n" );
+ return True;
+ }
+ default:
+ panic ( "test:unexpected error" );
+ }
+
+ panic ( "test:end" );
+ return True; /*notreached*/
+}
+
+
+/*---------------------------------------------------*/
+/*--- Error [non-] handling grunge ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------*/
+static
+void setExit ( Int32 v )
+{
+ if (v > exitValue) exitValue = v;
+}
+
+
+/*---------------------------------------------*/
+static
+void cadvise ( void )
+{
+ if (noisy)
+ fprintf (
+ stderr,
+ "\nIt is possible that the compressed file(s) have become corrupted.\n"
+ "You can use the -tvv option to test integrity of such files.\n\n"
+ "You can use the `bzip2recover' program to attempt to recover\n"
+ "data from undamaged sections of corrupted files.\n\n"
+ );
+}
+
+
+/*---------------------------------------------*/
+static
+void showFileNames ( void )
+{
+ if (noisy)
+ fprintf (
+ stderr,
+ "\tInput file = %s, output file = %s\n",
+ inName, outName
+ );
+}
+
+
+/*---------------------------------------------*/
+static
+void cleanUpAndFail ( Int32 ec )
+{
+ IntNative retVal;
+ struct MY_STAT statBuf;
+
+ if ( srcMode == SM_F2F
+ && opMode != OM_TEST
+ && deleteOutputOnInterrupt ) {
+
+ /* Check whether input file still exists. Delete output file
+ only if input exists to avoid loss of data. Joerg Prante, 5
+ January 2002. (JRS 06-Jan-2002: other changes in 1.0.2 mean
+ this is less likely to happen. But to be ultra-paranoid, we
+ do the check anyway.) */
+ retVal = MY_STAT ( inName, &statBuf );
+ if (retVal == 0) {
+ if (noisy)
+ fprintf ( stderr,
+ "%s: Deleting output file %s, if it exists.\n",
+ progName, outName );
+ if (outputHandleJustInCase != NULL)
+ fclose ( outputHandleJustInCase );
+ retVal = remove ( outName );
+ if (retVal != 0)
+ fprintf ( stderr,
+ "%s: WARNING: deletion of output file "
+ "(apparently) failed.\n",
+ progName );
+ } else {
+ fprintf ( stderr,
+ "%s: WARNING: deletion of output file suppressed\n",
+ progName );
+ fprintf ( stderr,
+ "%s: since input file no longer exists. Output file\n",
+ progName );
+ fprintf ( stderr,
+ "%s: `%s' may be incomplete.\n",
+ progName, outName );
+ fprintf ( stderr,
+ "%s: I suggest doing an integrity test (bzip2 -tv)"
+ " of it.\n",
+ progName );
+ }
+ }
+
+ if (noisy && numFileNames > 0 && numFilesProcessed < numFileNames) {
+ fprintf ( stderr,
+ "%s: WARNING: some files have not been processed:\n"
+ "%s: %d specified on command line, %d not processed yet.\n\n",
+ progName, progName,
+ numFileNames, numFileNames - numFilesProcessed );
+ }
+ setExit(ec);
+ exit(exitValue);
+}
+
+
+/*---------------------------------------------*/
+static
+void panic ( const Char* s )
+{
+ fprintf ( stderr,
+ "\n%s: PANIC -- internal consistency error:\n"
+ "\t%s\n"
+ "\tThis is a BUG. Please report it to me at:\n"
+ "\tjseward@bzip.org\n",
+ progName, s );
+ showFileNames();
+ cleanUpAndFail( 3 );
+}
+
+
+/*---------------------------------------------*/
+static
+void crcError ( void )
+{
+ fprintf ( stderr,
+ "\n%s: Data integrity error when decompressing.\n",
+ progName );
+ showFileNames();
+ cadvise();
+ cleanUpAndFail( 2 );
+}
+
+
+/*---------------------------------------------*/
+static
+void compressedStreamEOF ( void )
+{
+ if (noisy) {
+ fprintf ( stderr,
+ "\n%s: Compressed file ends unexpectedly;\n\t"
+ "perhaps it is corrupted? *Possible* reason follows.\n",
+ progName );
+ perror ( progName );
+ showFileNames();
+ cadvise();
+ }
+ cleanUpAndFail( 2 );
+}
+
+
+/*---------------------------------------------*/
+static
+void ioError ( void )
+{
+ fprintf ( stderr,
+ "\n%s: I/O or other error, bailing out. "
+ "Possible reason follows.\n",
+ progName );
+ perror ( progName );
+ showFileNames();
+ cleanUpAndFail( 1 );
+}
+
+
+/*---------------------------------------------*/
+static
+void mySignalCatcher ( IntNative n )
+{
+ fprintf ( stderr,
+ "\n%s: Control-C or similar caught, quitting.\n",
+ progName );
+ cleanUpAndFail(1);
+}
+
+
+/*---------------------------------------------*/
+static
+void mySIGSEGVorSIGBUScatcher ( IntNative n )
+{
+ if (opMode == OM_Z)
+ fprintf (
+ stderr,
+ "\n%s: Caught a SIGSEGV or SIGBUS whilst compressing.\n"
+ "\n"
+ " Possible causes are (most likely first):\n"
+ " (1) This computer has unreliable memory or cache hardware\n"
+ " (a surprisingly common problem; try a different machine.)\n"
+ " (2) A bug in the compiler used to create this executable\n"
+ " (unlikely, if you didn't compile bzip2 yourself.)\n"
+ " (3) A real bug in bzip2 -- I hope this should never be the case.\n"
+ " The user's manual, Section 4.3, has more info on (1) and (2).\n"
+ " \n"
+ " If you suspect this is a bug in bzip2, or are unsure about (1)\n"
+ " or (2), feel free to report it to me at: jseward@bzip.org.\n"
+ " Section 4.3 of the user's manual describes the info a useful\n"
+ " bug report should have. If the manual is available on your\n"
+ " system, please try and read it before mailing me. If you don't\n"
+ " have the manual or can't be bothered to read it, mail me anyway.\n"
+ "\n",
+ progName );
+ else
+ fprintf (
+ stderr,
+ "\n%s: Caught a SIGSEGV or SIGBUS whilst decompressing.\n"
+ "\n"
+ " Possible causes are (most likely first):\n"
+ " (1) The compressed data is corrupted, and bzip2's usual checks\n"
+ " failed to detect this. Try bzip2 -tvv my_file.bz2.\n"
+ " (2) This computer has unreliable memory or cache hardware\n"
+ " (a surprisingly common problem; try a different machine.)\n"
+ " (3) A bug in the compiler used to create this executable\n"
+ " (unlikely, if you didn't compile bzip2 yourself.)\n"
+ " (4) A real bug in bzip2 -- I hope this should never be the case.\n"
+ " The user's manual, Section 4.3, has more info on (2) and (3).\n"
+ " \n"
+ " If you suspect this is a bug in bzip2, or are unsure about (2)\n"
+ " or (3), feel free to report it to me at: jseward@bzip.org.\n"
+ " Section 4.3 of the user's manual describes the info a useful\n"
+ " bug report should have. If the manual is available on your\n"
+ " system, please try and read it before mailing me. If you don't\n"
+ " have the manual or can't be bothered to read it, mail me anyway.\n"
+ "\n",
+ progName );
+
+ showFileNames();
+ if (opMode == OM_Z)
+ cleanUpAndFail( 3 ); else
+ { cadvise(); cleanUpAndFail( 2 ); }
+}
+
+
+/*---------------------------------------------*/
+static
+void outOfMemory ( void )
+{
+ fprintf ( stderr,
+ "\n%s: couldn't allocate enough memory\n",
+ progName );
+ showFileNames();
+ cleanUpAndFail(1);
+}
+
+
+/*---------------------------------------------*/
+static
+void configError ( void )
+{
+ fprintf ( stderr,
+ "bzip2: I'm not configured correctly for this platform!\n"
+ "\tI require Int32, Int16 and Char to have sizes\n"
+ "\tof 4, 2 and 1 bytes to run properly, and they don't.\n"
+ "\tProbably you can fix this by defining them correctly,\n"
+ "\tand recompiling. Bye!\n" );
+ setExit(3);
+ exit(exitValue);
+}
+
+
+/*---------------------------------------------------*/
+/*--- The main driver machinery ---*/
+/*---------------------------------------------------*/
+
+/* All rather crufty. The main problem is that input files
+ are stat()d multiple times before use. This should be
+ cleaned up.
+*/
+
+/*---------------------------------------------*/
+static
+void pad ( Char *s )
+{
+ Int32 i;
+ if ( (Int32)strlen(s) >= longestFileName ) return;
+ for (i = 1; i <= longestFileName - (Int32)strlen(s); i++)
+ fprintf ( stderr, " " );
+}
+
+
+/*---------------------------------------------*/
+static
+void copyFileName ( Char* to, Char* from )
+{
+ if ( strlen(from) > FILE_NAME_LEN-10 ) {
+ fprintf (
+ stderr,
+ "bzip2: file name\n`%s'\n"
+ "is suspiciously (more than %d chars) long.\n"
+ "Try using a reasonable file name instead. Sorry! :-)\n",
+ from, FILE_NAME_LEN-10
+ );
+ setExit(1);
+ exit(exitValue);
+ }
+
+ strncpy(to,from,FILE_NAME_LEN-10);
+ to[FILE_NAME_LEN-10]='\0';
+}
+
+
+/*---------------------------------------------*/
+static
+Bool fileExists ( Char* name )
+{
+ FILE *tmp = fopen ( name, "rb" );
+ Bool exists = (tmp != NULL);
+ if (tmp != NULL) fclose ( tmp );
+ return exists;
+}
+
+
+/*---------------------------------------------*/
+/* Open an output file safely with O_EXCL and good permissions.
+ This avoids a race condition in versions < 1.0.2, in which
+ the file was first opened and then had its interim permissions
+ set safely. We instead use open() to create the file with
+ the interim permissions required. (--- --- rw-).
+
+ For non-Unix platforms, if we are not worrying about
+ security issues, simple this simply behaves like fopen.
+*/
+static
+FILE* fopen_output_safely ( Char* name, const char* mode )
+{
+# if BZ_UNIX
+ FILE* fp;
+ IntNative fh;
+ fh = open(name, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR);
+ if (fh == -1) return NULL;
+ fp = fdopen(fh, mode);
+ if (fp == NULL) close(fh);
+ return fp;
+# else
+ return fopen(name, mode);
+# endif
+}
+
+
+/*---------------------------------------------*/
+/*--
+ if in doubt, return True
+--*/
+static
+Bool notAStandardFile ( Char* name )
+{
+ IntNative i;
+ struct MY_STAT statBuf;
+
+ i = MY_LSTAT ( name, &statBuf );
+ if (i != 0) return True;
+ if (MY_S_ISREG(statBuf.st_mode)) return False;
+ return True;
+}
+
+
+/*---------------------------------------------*/
+/*--
+ rac 11/21/98 see if file has hard links to it
+--*/
+static
+Int32 countHardLinks ( Char* name )
+{
+ IntNative i;
+ struct MY_STAT statBuf;
+
+ i = MY_LSTAT ( name, &statBuf );
+ if (i != 0) return 0;
+ return (statBuf.st_nlink - 1);
+}
+
+
+/*---------------------------------------------*/
+/* Copy modification date, access date, permissions and owner from the
+ source to destination file. We have to copy this meta-info off
+ into fileMetaInfo before starting to compress / decompress it,
+ because doing it afterwards means we get the wrong access time.
+
+ To complicate matters, in compress() and decompress() below, the
+ sequence of tests preceding the call to saveInputFileMetaInfo()
+ involves calling fileExists(), which in turn establishes its result
+ by attempting to fopen() the file, and if successful, immediately
+ fclose()ing it again. So we have to assume that the fopen() call
+ does not cause the access time field to be updated.
+
+ Reading of the man page for stat() (man 2 stat) on RedHat 7.2 seems
+ to imply that merely doing open() will not affect the access time.
+ Therefore we merely need to hope that the C library only does
+ open() as a result of fopen(), and not any kind of read()-ahead
+ cleverness.
+
+ It sounds pretty fragile to me. Whether this carries across
+ robustly to arbitrary Unix-like platforms (or even works robustly
+ on this one, RedHat 7.2) is unknown to me. Nevertheless ...
+*/
+#if BZ_UNIX
+static
+struct MY_STAT fileMetaInfo;
+#endif
+
+static
+void saveInputFileMetaInfo ( Char *srcName )
+{
+# if BZ_UNIX
+ IntNative retVal;
+ /* Note use of stat here, not lstat. */
+ retVal = MY_STAT( srcName, &fileMetaInfo );
+ ERROR_IF_NOT_ZERO ( retVal );
+# endif
+}
+
+
+static
+void applySavedTimeInfoToOutputFile ( Char *dstName )
+{
+# if BZ_UNIX
+ IntNative retVal;
+ struct utimbuf uTimBuf;
+
+ uTimBuf.actime = fileMetaInfo.st_atime;
+ uTimBuf.modtime = fileMetaInfo.st_mtime;
+
+ retVal = utime ( dstName, &uTimBuf );
+ ERROR_IF_NOT_ZERO ( retVal );
+# endif
+}
+
+static
+void applySavedFileAttrToOutputFile ( IntNative fd )
+{
+# if BZ_UNIX
+ IntNative retVal;
+
+ retVal = fchmod ( fd, fileMetaInfo.st_mode );
+ ERROR_IF_NOT_ZERO ( retVal );
+
+ (void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
+ /* chown() will in many cases return with EPERM, which can
+ be safely ignored.
+ */
+# endif
+}
+
+
+/*---------------------------------------------*/
+static
+Bool containsDubiousChars ( Char* name )
+{
+# if BZ_UNIX
+ /* On unix, files can contain any characters and the file expansion
+ * is performed by the shell.
+ */
+ return False;
+# else /* ! BZ_UNIX */
+ /* On non-unix (Win* platforms), wildcard characters are not allowed in
+ * filenames.
+ */
+ for (; *name != '\0'; name++)
+ if (*name == '?' || *name == '*') return True;
+ return False;
+# endif /* BZ_UNIX */
+}
+
+
+/*---------------------------------------------*/
+#define BZ_N_SUFFIX_PAIRS 4
+
+const Char* zSuffix[BZ_N_SUFFIX_PAIRS]
+ = { ".bz2", ".bz", ".tbz2", ".tbz" };
+const Char* unzSuffix[BZ_N_SUFFIX_PAIRS]
+ = { "", "", ".tar", ".tar" };
+
+static
+Bool hasSuffix ( Char* s, const Char* suffix )
+{
+ Int32 ns = strlen(s);
+ Int32 nx = strlen(suffix);
+ if (ns < nx) return False;
+ if (strcmp(s + ns - nx, suffix) == 0) return True;
+ return False;
+}
+
+static
+Bool mapSuffix ( Char* name,
+ const Char* oldSuffix,
+ const Char* newSuffix )
+{
+ if (!hasSuffix(name,oldSuffix)) return False;
+ name[strlen(name)-strlen(oldSuffix)] = 0;
+ strcat ( name, newSuffix );
+ return True;
+}
+
+
+/*---------------------------------------------*/
+static
+void compress ( Char *name )
+{
+ FILE *inStr;
+ FILE *outStr;
+ Int32 n, i;
+ struct MY_STAT statBuf;
+
+ deleteOutputOnInterrupt = False;
+
+ if (name == NULL && srcMode != SM_I2O)
+ panic ( "compress: bad modes\n" );
+
+ switch (srcMode) {
+ case SM_I2O:
+ copyFileName ( inName, (Char*)"(stdin)" );
+ copyFileName ( outName, (Char*)"(stdout)" );
+ break;
+ case SM_F2F:
+ copyFileName ( inName, name );
+ copyFileName ( outName, name );
+ strcat ( outName, ".bz2" );
+ break;
+ case SM_F2O:
+ copyFileName ( inName, name );
+ copyFileName ( outName, (Char*)"(stdout)" );
+ break;
+ }
+
+ if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
+ if (noisy)
+ fprintf ( stderr, "%s: There are no files matching `%s'.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ }
+ for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++) {
+ if (hasSuffix(inName, zSuffix[i])) {
+ if (noisy)
+ fprintf ( stderr,
+ "%s: Input file %s already has %s suffix.\n",
+ progName, inName, zSuffix[i] );
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
+ MY_STAT(inName, &statBuf);
+ if ( MY_S_ISDIR(statBuf.st_mode) ) {
+ fprintf( stderr,
+ "%s: Input file %s is a directory.\n",
+ progName,inName);
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
+ if (noisy)
+ fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( srcMode == SM_F2F && fileExists ( outName ) ) {
+ if (forceOverwrite) {
+ remove(outName);
+ } else {
+ fprintf ( stderr, "%s: Output file %s already exists.\n",
+ progName, outName );
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F && !forceOverwrite &&
+ (n=countHardLinks ( inName )) > 0) {
+ fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
+ progName, inName, n, n > 1 ? "s" : "" );
+ setExit(1);
+ return;
+ }
+
+ if ( srcMode == SM_F2F ) {
+ /* Save the file's meta-info before we open it. Doing it later
+ means we mess up the access times. */
+ saveInputFileMetaInfo ( inName );
+ }
+
+ switch ( srcMode ) {
+
+ case SM_I2O:
+ inStr = stdin;
+ outStr = stdout;
+ if ( isatty ( fileno ( stdout ) ) ) {
+ fprintf ( stderr,
+ "%s: I won't write compressed data to a terminal.\n",
+ progName );
+ fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
+ progName, progName );
+ setExit(1);
+ return;
+ };
+ break;
+
+ case SM_F2O:
+ inStr = fopen ( inName, "rb" );
+ outStr = stdout;
+ if ( isatty ( fileno ( stdout ) ) ) {
+ fprintf ( stderr,
+ "%s: I won't write compressed data to a terminal.\n",
+ progName );
+ fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
+ progName, progName );
+ if ( inStr != NULL ) fclose ( inStr );
+ setExit(1);
+ return;
+ };
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ };
+ break;
+
+ case SM_F2F:
+ inStr = fopen ( inName, "rb" );
+ outStr = fopen_output_safely ( outName, "wb" );
+ if ( outStr == NULL) {
+ fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
+ progName, outName, strerror(errno) );
+ if ( inStr != NULL ) fclose ( inStr );
+ setExit(1);
+ return;
+ }
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ if ( outStr != NULL ) fclose ( outStr );
+ setExit(1);
+ return;
+ };
+ break;
+
+ default:
+ panic ( "compress: bad srcMode" );
+ break;
+ }
+
+ if (verbosity >= 1) {
+ fprintf ( stderr, " %s: ", inName );
+ pad ( inName );
+ fflush ( stderr );
+ }
+
+ /*--- Now the input and output handles are sane. Do the Biz. ---*/
+ outputHandleJustInCase = outStr;
+ deleteOutputOnInterrupt = True;
+ compressStream ( inStr, outStr );
+ outputHandleJustInCase = NULL;
+
+ /*--- If there was an I/O error, we won't get here. ---*/
+ if ( srcMode == SM_F2F ) {
+ applySavedTimeInfoToOutputFile ( outName );
+ deleteOutputOnInterrupt = False;
+ if ( !keepInputFiles ) {
+ IntNative retVal = remove ( inName );
+ ERROR_IF_NOT_ZERO ( retVal );
+ }
+ }
+
+ deleteOutputOnInterrupt = False;
+}
+
+
+/*---------------------------------------------*/
+static
+void uncompress ( Char *name )
+{
+ FILE *inStr;
+ FILE *outStr;
+ Int32 n, i;
+ Bool magicNumberOK;
+ Bool cantGuess;
+ struct MY_STAT statBuf;
+
+ deleteOutputOnInterrupt = False;
+
+ if (name == NULL && srcMode != SM_I2O)
+ panic ( "uncompress: bad modes\n" );
+
+ cantGuess = False;
+ switch (srcMode) {
+ case SM_I2O:
+ copyFileName ( inName, (Char*)"(stdin)" );
+ copyFileName ( outName, (Char*)"(stdout)" );
+ break;
+ case SM_F2F:
+ copyFileName ( inName, name );
+ copyFileName ( outName, name );
+ for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
+ if (mapSuffix(outName,zSuffix[i],unzSuffix[i]))
+ goto zzz;
+ cantGuess = True;
+ strcat ( outName, ".out" );
+ break;
+ case SM_F2O:
+ copyFileName ( inName, name );
+ copyFileName ( outName, (Char*)"(stdout)" );
+ break;
+ }
+
+ zzz:
+ if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
+ if (noisy)
+ fprintf ( stderr, "%s: There are no files matching `%s'.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ }
+ if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
+ MY_STAT(inName, &statBuf);
+ if ( MY_S_ISDIR(statBuf.st_mode) ) {
+ fprintf( stderr,
+ "%s: Input file %s is a directory.\n",
+ progName,inName);
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
+ if (noisy)
+ fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( /* srcMode == SM_F2F implied && */ cantGuess ) {
+ if (noisy)
+ fprintf ( stderr,
+ "%s: Can't guess original name for %s -- using %s\n",
+ progName, inName, outName );
+ /* just a warning, no return */
+ }
+ if ( srcMode == SM_F2F && fileExists ( outName ) ) {
+ if (forceOverwrite) {
+ remove(outName);
+ } else {
+ fprintf ( stderr, "%s: Output file %s already exists.\n",
+ progName, outName );
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F && !forceOverwrite &&
+ (n=countHardLinks ( inName ) ) > 0) {
+ fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
+ progName, inName, n, n > 1 ? "s" : "" );
+ setExit(1);
+ return;
+ }
+
+ if ( srcMode == SM_F2F ) {
+ /* Save the file's meta-info before we open it. Doing it later
+ means we mess up the access times. */
+ saveInputFileMetaInfo ( inName );
+ }
+
+ switch ( srcMode ) {
+
+ case SM_I2O:
+ inStr = stdin;
+ outStr = stdout;
+ if ( isatty ( fileno ( stdin ) ) ) {
+ fprintf ( stderr,
+ "%s: I won't read compressed data from a terminal.\n",
+ progName );
+ fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
+ progName, progName );
+ setExit(1);
+ return;
+ };
+ break;
+
+ case SM_F2O:
+ inStr = fopen ( inName, "rb" );
+ outStr = stdout;
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
+ progName, inName, strerror(errno) );
+ if ( inStr != NULL ) fclose ( inStr );
+ setExit(1);
+ return;
+ };
+ break;
+
+ case SM_F2F:
+ inStr = fopen ( inName, "rb" );
+ outStr = fopen_output_safely ( outName, "wb" );
+ if ( outStr == NULL) {
+ fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
+ progName, outName, strerror(errno) );
+ if ( inStr != NULL ) fclose ( inStr );
+ setExit(1);
+ return;
+ }
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ if ( outStr != NULL ) fclose ( outStr );
+ setExit(1);
+ return;
+ };
+ break;
+
+ default:
+ panic ( "uncompress: bad srcMode" );
+ break;
+ }
+
+ if (verbosity >= 1) {
+ fprintf ( stderr, " %s: ", inName );
+ pad ( inName );
+ fflush ( stderr );
+ }
+
+ /*--- Now the input and output handles are sane. Do the Biz. ---*/
+ outputHandleJustInCase = outStr;
+ deleteOutputOnInterrupt = True;
+ magicNumberOK = uncompressStream ( inStr, outStr );
+ outputHandleJustInCase = NULL;
+
+ /*--- If there was an I/O error, we won't get here. ---*/
+ if ( magicNumberOK ) {
+ if ( srcMode == SM_F2F ) {
+ applySavedTimeInfoToOutputFile ( outName );
+ deleteOutputOnInterrupt = False;
+ if ( !keepInputFiles ) {
+ IntNative retVal = remove ( inName );
+ ERROR_IF_NOT_ZERO ( retVal );
+ }
+ }
+ } else {
+ unzFailsExist = True;
+ deleteOutputOnInterrupt = False;
+ if ( srcMode == SM_F2F ) {
+ IntNative retVal = remove ( outName );
+ ERROR_IF_NOT_ZERO ( retVal );
+ }
+ }
+ deleteOutputOnInterrupt = False;
+
+ if ( magicNumberOK ) {
+ if (verbosity >= 1)
+ fprintf ( stderr, "done\n" );
+ } else {
+ setExit(2);
+ if (verbosity >= 1)
+ fprintf ( stderr, "not a bzip2 file.\n" ); else
+ fprintf ( stderr,
+ "%s: %s is not a bzip2 file.\n",
+ progName, inName );
+ }
+
+}
+
+
+/*---------------------------------------------*/
+static
+void testf ( Char *name )
+{
+ FILE *inStr;
+ Bool allOK;
+ struct MY_STAT statBuf;
+
+ deleteOutputOnInterrupt = False;
+
+ if (name == NULL && srcMode != SM_I2O)
+ panic ( "testf: bad modes\n" );
+
+ copyFileName ( outName, (Char*)"(none)" );
+ switch (srcMode) {
+ case SM_I2O: copyFileName ( inName, (Char*)"(stdin)" ); break;
+ case SM_F2F: copyFileName ( inName, name ); break;
+ case SM_F2O: copyFileName ( inName, name ); break;
+ }
+
+ if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
+ if (noisy)
+ fprintf ( stderr, "%s: There are no files matching `%s'.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
+ fprintf ( stderr, "%s: Can't open input %s: %s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ }
+ if ( srcMode != SM_I2O ) {
+ MY_STAT(inName, &statBuf);
+ if ( MY_S_ISDIR(statBuf.st_mode) ) {
+ fprintf( stderr,
+ "%s: Input file %s is a directory.\n",
+ progName,inName);
+ setExit(1);
+ return;
+ }
+ }
+
+ switch ( srcMode ) {
+
+ case SM_I2O:
+ if ( isatty ( fileno ( stdin ) ) ) {
+ fprintf ( stderr,
+ "%s: I won't read compressed data from a terminal.\n",
+ progName );
+ fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
+ progName, progName );
+ setExit(1);
+ return;
+ };
+ inStr = stdin;
+ break;
+
+ case SM_F2O: case SM_F2F:
+ inStr = fopen ( inName, "rb" );
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ };
+ break;
+
+ default:
+ panic ( "testf: bad srcMode" );
+ break;
+ }
+
+ if (verbosity >= 1) {
+ fprintf ( stderr, " %s: ", inName );
+ pad ( inName );
+ fflush ( stderr );
+ }
+
+ /*--- Now the input handle is sane. Do the Biz. ---*/
+ outputHandleJustInCase = NULL;
+ allOK = testStream ( inStr );
+
+ if (allOK && verbosity >= 1) fprintf ( stderr, "ok\n" );
+ if (!allOK) testFailsExist = True;
+}
+
+
+/*---------------------------------------------*/
+static
+void license ( void )
+{
+ fprintf ( stderr,
+
+ "bzip2, a block-sorting file compressor. "
+ "Version %s.\n"
+ " \n"
+ " Copyright (C) 1996-2007 by Julian Seward.\n"
+ " \n"
+ " This program is free software; you can redistribute it and/or modify\n"
+ " it under the terms set out in the LICENSE file, which is included\n"
+ " in the bzip2-1.0.5 source distribution.\n"
+ " \n"
+ " This program is distributed in the hope that it will be useful,\n"
+ " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+ " LICENSE file for more details.\n"
+ " \n",
+ BZ2_bzlibVersion()
+ );
+}
+
+
+/*---------------------------------------------*/
+static
+void usage ( Char *fullProgName )
+{
+ fprintf (
+ stderr,
+ "bzip2, a block-sorting file compressor. "
+ "Version %s.\n"
+ "\n usage: %s [flags and input files in any order]\n"
+ "\n"
+ " -h --help print this message\n"
+ " -d --decompress force decompression\n"
+ " -z --compress force compression\n"
+ " -k --keep keep (don't delete) input files\n"
+ " -f --force overwrite existing output files\n"
+ " -t --test test compressed file integrity\n"
+ " -c --stdout output to standard out\n"
+ " -q --quiet suppress noncritical error messages\n"
+ " -v --verbose be verbose (a 2nd -v gives more)\n"
+ " -L --license display software version & license\n"
+ " -V --version display software version & license\n"
+ " -s --small use less memory (at most 2500k)\n"
+ " -1 .. -9 set block size to 100k .. 900k\n"
+ " --fast alias for -1\n"
+ " --best alias for -9\n"
+ "\n"
+ " If invoked as `bzip2', default action is to compress.\n"
+ " as `bunzip2', default action is to decompress.\n"
+ " as `bzcat', default action is to decompress to stdout.\n"
+ "\n"
+ " If no file names are given, bzip2 compresses or decompresses\n"
+ " from standard input to standard output. You can combine\n"
+ " short flags, so `-v -4' means the same as -v4 or -4v, &c.\n"
+# if BZ_UNIX
+ "\n"
+# endif
+ ,
+
+ BZ2_bzlibVersion(),
+ fullProgName
+ );
+}
+
+
+/*---------------------------------------------*/
+static
+void redundant ( Char* flag )
+{
+ fprintf (
+ stderr,
+ "%s: %s is redundant in versions 0.9.5 and above\n",
+ progName, flag );
+}
+
+
+/*---------------------------------------------*/
+/*--
+ All the garbage from here to main() is purely to
+ implement a linked list of command-line arguments,
+ into which main() copies argv[1 .. argc-1].
+
+ The purpose of this exercise is to facilitate
+ the expansion of wildcard characters * and ? in
+ filenames for OSs which don't know how to do it
+ themselves, like MSDOS, Windows 95 and NT.
+
+ The actual Dirty Work is done by the platform-
+ specific macro APPEND_FILESPEC.
+--*/
+
+typedef
+ struct zzzz {
+ Char *name;
+ struct zzzz *link;
+ }
+ Cell;
+
+
+/*---------------------------------------------*/
+static
+void *myMalloc ( Int32 n )
+{
+ void* p;
+
+ p = malloc ( (size_t)n );
+ if (p == NULL) outOfMemory ();
+ return p;
+}
+
+
+/*---------------------------------------------*/
+static
+Cell *mkCell ( void )
+{
+ Cell *c;
+
+ c = (Cell*) myMalloc ( sizeof ( Cell ) );
+ c->name = NULL;
+ c->link = NULL;
+ return c;
+}
+
+
+/*---------------------------------------------*/
+static
+Cell *snocString ( Cell *root, Char *name )
+{
+ if (root == NULL) {
+ Cell *tmp = mkCell();
+ tmp->name = (Char*) myMalloc ( 5 + strlen(name) );
+ strcpy ( tmp->name, name );
+ return tmp;
+ } else {
+ Cell *tmp = root;
+ while (tmp->link != NULL) tmp = tmp->link;
+ tmp->link = snocString ( tmp->link, name );
+ return root;
+ }
+}
+
+
+/*---------------------------------------------*/
+static
+void addFlagsFromEnvVar ( Cell** argList, Char* varName )
+{
+ Int32 i, j, k;
+ Char *envbase, *p;
+
+ envbase = getenv(varName);
+ if (envbase != NULL) {
+ p = envbase;
+ i = 0;
+ while (True) {
+ if (p[i] == 0) break;
+ p += i;
+ i = 0;
+ while (isspace((Int32)(p[0]))) p++;
+ while (p[i] != 0 && !isspace((Int32)(p[i]))) i++;
+ if (i > 0) {
+ k = i; if (k > FILE_NAME_LEN-10) k = FILE_NAME_LEN-10;
+ for (j = 0; j < k; j++) tmpName[j] = p[j];
+ tmpName[k] = 0;
+ APPEND_FLAG(*argList, tmpName);
+ }
+ }
+ }
+}
+
+
+/*---------------------------------------------*/
+#define ISFLAG(s) (strcmp(aa->name, (s))==0)
+
+IntNative main ( IntNative argc, Char *argv[] )
+{
+ Int32 i, j;
+ Char *tmp;
+ Cell *argList;
+ Cell *aa;
+ Bool decode;
+
+ /*-- Be really really really paranoid :-) --*/
+ if (sizeof(Int32) != 4 || sizeof(UInt32) != 4 ||
+ sizeof(Int16) != 2 || sizeof(UInt16) != 2 ||
+ sizeof(Char) != 1 || sizeof(UChar) != 1)
+ configError();
+
+ /*-- Initialise --*/
+ outputHandleJustInCase = NULL;
+ smallMode = False;
+ keepInputFiles = False;
+ forceOverwrite = False;
+ noisy = True;
+ verbosity = 0;
+ blockSize100k = 9;
+ testFailsExist = False;
+ unzFailsExist = False;
+ numFileNames = 0;
+ numFilesProcessed = 0;
+ workFactor = 30;
+ deleteOutputOnInterrupt = False;
+ exitValue = 0;
+ i = j = 0; /* avoid bogus warning from egcs-1.1.X */
+
+ /*-- Set up signal handlers for mem access errors --*/
+ signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
+# if BZ_UNIX
+# ifndef __DJGPP__
+ signal (SIGBUS, mySIGSEGVorSIGBUScatcher);
+# endif
+# endif
+
+ copyFileName ( inName, (Char*)"(none)" );
+ copyFileName ( outName, (Char*)"(none)" );
+
+ copyFileName ( progNameReally, argv[0] );
+ progName = &progNameReally[0];
+ for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
+ if (*tmp == PATH_SEP) progName = tmp + 1;
+
+
+ /*-- Copy flags from env var BZIP2, and
+ expand filename wildcards in arg list.
+ --*/
+ argList = NULL;
+ addFlagsFromEnvVar ( &argList, (Char*)"BZIP2" );
+ addFlagsFromEnvVar ( &argList, (Char*)"BZIP" );
+ for (i = 1; i <= argc-1; i++)
+ APPEND_FILESPEC(argList, argv[i]);
+
+
+ /*-- Find the length of the longest filename --*/
+ longestFileName = 7;
+ numFileNames = 0;
+ decode = True;
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) { decode = False; continue; }
+ if (aa->name[0] == '-' && decode) continue;
+ numFileNames++;
+ if (longestFileName < (Int32)strlen(aa->name) )
+ longestFileName = (Int32)strlen(aa->name);
+ }
+
+
+ /*-- Determine source modes; flag handling may change this too. --*/
+ if (numFileNames == 0)
+ srcMode = SM_I2O; else srcMode = SM_F2F;
+
+
+ /*-- Determine what to do (compress/uncompress/test/cat). --*/
+ /*-- Note that subsequent flag handling may change this. --*/
+ opMode = OM_Z;
+
+ if ( (strstr ( progName, "unzip" ) != 0) ||
+ (strstr ( progName, "UNZIP" ) != 0) )
+ opMode = OM_UNZ;
+
+ if ( (strstr ( progName, "z2cat" ) != 0) ||
+ (strstr ( progName, "Z2CAT" ) != 0) ||
+ (strstr ( progName, "zcat" ) != 0) ||
+ (strstr ( progName, "ZCAT" ) != 0) ) {
+ opMode = OM_UNZ;
+ srcMode = (numFileNames == 0) ? SM_I2O : SM_F2O;
+ }
+
+
+ /*-- Look at the flags. --*/
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) break;
+ if (aa->name[0] == '-' && aa->name[1] != '-') {
+ for (j = 1; aa->name[j] != '\0'; j++) {
+ switch (aa->name[j]) {
+ case 'c': srcMode = SM_F2O; break;
+ case 'd': opMode = OM_UNZ; break;
+ case 'z': opMode = OM_Z; break;
+ case 'f': forceOverwrite = True; break;
+ case 't': opMode = OM_TEST; break;
+ case 'k': keepInputFiles = True; break;
+ case 's': smallMode = True; break;
+ case 'q': noisy = False; break;
+ case '1': blockSize100k = 1; break;
+ case '2': blockSize100k = 2; break;
+ case '3': blockSize100k = 3; break;
+ case '4': blockSize100k = 4; break;
+ case '5': blockSize100k = 5; break;
+ case '6': blockSize100k = 6; break;
+ case '7': blockSize100k = 7; break;
+ case '8': blockSize100k = 8; break;
+ case '9': blockSize100k = 9; break;
+ case 'V':
+ case 'L': license(); break;
+ case 'v': verbosity++; break;
+ case 'h': usage ( progName );
+ exit ( 0 );
+ break;
+ default: fprintf ( stderr, "%s: Bad flag `%s'\n",
+ progName, aa->name );
+ usage ( progName );
+ exit ( 1 );
+ break;
+ }
+ }
+ }
+ }
+
+ /*-- And again ... --*/
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) break;
+ if (ISFLAG("--stdout")) srcMode = SM_F2O; else
+ if (ISFLAG("--decompress")) opMode = OM_UNZ; else
+ if (ISFLAG("--compress")) opMode = OM_Z; else
+ if (ISFLAG("--force")) forceOverwrite = True; else
+ if (ISFLAG("--test")) opMode = OM_TEST; else
+ if (ISFLAG("--keep")) keepInputFiles = True; else
+ if (ISFLAG("--small")) smallMode = True; else
+ if (ISFLAG("--quiet")) noisy = False; else
+ if (ISFLAG("--version")) license(); else
+ if (ISFLAG("--license")) license(); else
+ if (ISFLAG("--exponential")) workFactor = 1; else
+ if (ISFLAG("--repetitive-best")) redundant(aa->name); else
+ if (ISFLAG("--repetitive-fast")) redundant(aa->name); else
+ if (ISFLAG("--fast")) blockSize100k = 1; else
+ if (ISFLAG("--best")) blockSize100k = 9; else
+ if (ISFLAG("--verbose")) verbosity++; else
+ if (ISFLAG("--help")) { usage ( progName ); exit ( 0 ); }
+ else
+ if (strncmp ( aa->name, "--", 2) == 0) {
+ fprintf ( stderr, "%s: Bad flag `%s'\n", progName, aa->name );
+ usage ( progName );
+ exit ( 1 );
+ }
+ }
+
+ if (verbosity > 4) verbosity = 4;
+ if (opMode == OM_Z && smallMode && blockSize100k > 2)
+ blockSize100k = 2;
+
+ if (opMode == OM_TEST && srcMode == SM_F2O) {
+ fprintf ( stderr, "%s: -c and -t cannot be used together.\n",
+ progName );
+ exit ( 1 );
+ }
+
+ if (srcMode == SM_F2O && numFileNames == 0)
+ srcMode = SM_I2O;
+
+ if (opMode != OM_Z) blockSize100k = 0;
+
+ if (srcMode == SM_F2F) {
+ signal (SIGINT, mySignalCatcher);
+ signal (SIGTERM, mySignalCatcher);
+# if BZ_UNIX
+ signal (SIGHUP, mySignalCatcher);
+# endif
+ }
+
+ if (opMode == OM_Z) {
+ if (srcMode == SM_I2O) {
+ compress ( NULL );
+ } else {
+ decode = True;
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) { decode = False; continue; }
+ if (aa->name[0] == '-' && decode) continue;
+ numFilesProcessed++;
+ compress ( aa->name );
+ }
+ }
+ }
+ else
+
+ if (opMode == OM_UNZ) {
+ unzFailsExist = False;
+ if (srcMode == SM_I2O) {
+ uncompress ( NULL );
+ } else {
+ decode = True;
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) { decode = False; continue; }
+ if (aa->name[0] == '-' && decode) continue;
+ numFilesProcessed++;
+ uncompress ( aa->name );
+ }
+ }
+ if (unzFailsExist) {
+ setExit(2);
+ exit(exitValue);
+ }
+ }
+
+ else {
+ testFailsExist = False;
+ if (srcMode == SM_I2O) {
+ testf ( NULL );
+ } else {
+ decode = True;
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) { decode = False; continue; }
+ if (aa->name[0] == '-' && decode) continue;
+ numFilesProcessed++;
+ testf ( aa->name );
+ }
+ }
+ if (testFailsExist && noisy) {
+ fprintf ( stderr,
+ "\n"
+ "You can use the `bzip2recover' program to attempt to recover\n"
+ "data from undamaged sections of corrupted files.\n\n"
+ );
+ setExit(2);
+ exit(exitValue);
+ }
+ }
+
+ /* Free the argument list memory to mollify leak detectors
+ (eg) Purify, Checker. Serves no other useful purpose.
+ */
+ aa = argList;
+ while (aa != NULL) {
+ Cell* aa2 = aa->link;
+ if (aa->name != NULL) free(aa->name);
+ free(aa);
+ aa = aa2;
+ }
+
+ return exitValue;
+}
+
+
+/*-----------------------------------------------------------*/
+/*--- end bzip2.c ---*/
+/*-----------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/bzip2.txt b/Utilities/cmbzip2/bzip2.txt
new file mode 100644
index 0000000000..4fb9c7435e
--- /dev/null
+++ b/Utilities/cmbzip2/bzip2.txt
@@ -0,0 +1,391 @@
+
+NAME
+ bzip2, bunzip2 - a block-sorting file compressor, v1.0.4
+ bzcat - decompresses files to stdout
+ bzip2recover - recovers data from damaged bzip2 files
+
+
+SYNOPSIS
+ bzip2 [ -cdfkqstvzVL123456789 ] [ filenames ... ]
+ bunzip2 [ -fkvsVL ] [ filenames ... ]
+ bzcat [ -s ] [ filenames ... ]
+ bzip2recover filename
+
+
+DESCRIPTION
+ bzip2 compresses files using the Burrows-Wheeler block
+ sorting text compression algorithm, and Huffman coding.
+ Compression is generally considerably better than that
+ achieved by more conventional LZ77/LZ78-based compressors,
+ and approaches the performance of the PPM family of sta-
+ tistical compressors.
+
+ The command-line options are deliberately very similar to
+ those of GNU gzip, but they are not identical.
+
+ bzip2 expects a list of file names to accompany the com-
+ mand-line flags. Each file is replaced by a compressed
+ version of itself, with the name "original_name.bz2".
+ Each compressed file has the same modification date, per-
+ missions, and, when possible, ownership as the correspond-
+ ing original, so that these properties can be correctly
+ restored at decompression time. File name handling is
+ naive in the sense that there is no mechanism for preserv-
+ ing original file names, permissions, ownerships or dates
+ in filesystems which lack these concepts, or have serious
+ file name length restrictions, such as MS-DOS.
+
+ bzip2 and bunzip2 will by default not overwrite existing
+ files. If you want this to happen, specify the -f flag.
+
+ If no file names are specified, bzip2 compresses from
+ standard input to standard output. In this case, bzip2
+ will decline to write compressed output to a terminal, as
+ this would be entirely incomprehensible and therefore
+ pointless.
+
+ bunzip2 (or bzip2 -d) decompresses all specified files.
+ Files which were not created by bzip2 will be detected and
+ ignored, and a warning issued. bzip2 attempts to guess
+ the filename for the decompressed file from that of the
+ compressed file as follows:
+
+ filename.bz2 becomes filename
+ filename.bz becomes filename
+ filename.tbz2 becomes filename.tar
+ filename.tbz becomes filename.tar
+ anyothername becomes anyothername.out
+
+ If the file does not end in one of the recognised endings,
+ .bz2, .bz, .tbz2 or .tbz, bzip2 complains that it cannot
+ guess the name of the original file, and uses the original
+ name with .out appended.
+
+ As with compression, supplying no filenames causes decom-
+ pression from standard input to standard output.
+
+ bunzip2 will correctly decompress a file which is the con-
+ catenation of two or more compressed files. The result is
+ the concatenation of the corresponding uncompressed files.
+ Integrity testing (-t) of concatenated compressed files is
+ also supported.
+
+ You can also compress or decompress files to the standard
+ output by giving the -c flag. Multiple files may be com-
+ pressed and decompressed like this. The resulting outputs
+ are fed sequentially to stdout. Compression of multiple
+ files in this manner generates a stream containing multi-
+ ple compressed file representations. Such a stream can be
+ decompressed correctly only by bzip2 version 0.9.0 or
+ later. Earlier versions of bzip2 will stop after decom-
+ pressing the first file in the stream.
+
+ bzcat (or bzip2 -dc) decompresses all specified files to
+ the standard output.
+
+ bzip2 will read arguments from the environment variables
+ BZIP2 and BZIP, in that order, and will process them
+ before any arguments read from the command line. This
+ gives a convenient way to supply default arguments.
+
+ Compression is always performed, even if the compressed
+ file is slightly larger than the original. Files of less
+ than about one hundred bytes tend to get larger, since the
+ compression mechanism has a constant overhead in the
+ region of 50 bytes. Random data (including the output of
+ most file compressors) is coded at about 8.05 bits per
+ byte, giving an expansion of around 0.5%.
+
+ As a self-check for your protection, bzip2 uses 32-bit
+ CRCs to make sure that the decompressed version of a file
+ is identical to the original. This guards against corrup-
+ tion of the compressed data, and against undetected bugs
+ in bzip2 (hopefully very unlikely). The chances of data
+ corruption going undetected is microscopic, about one
+ chance in four billion for each file processed. Be aware,
+ though, that the check occurs upon decompression, so it
+ can only tell you that something is wrong. It can't help
+ you recover the original uncompressed data. You can use
+ bzip2recover to try to recover data from damaged files.
+
+ Return values: 0 for a normal exit, 1 for environmental
+ problems (file not found, invalid flags, I/O errors, &c),
+ 2 to indicate a corrupt compressed file, 3 for an internal
+ consistency error (eg, bug) which caused bzip2 to panic.
+
+
+OPTIONS
+ -c --stdout
+ Compress or decompress to standard output.
+
+ -d --decompress
+ Force decompression. bzip2, bunzip2 and bzcat are
+ really the same program, and the decision about
+ what actions to take is done on the basis of which
+ name is used. This flag overrides that mechanism,
+ and forces bzip2 to decompress.
+
+ -z --compress
+ The complement to -d: forces compression,
+ regardless of the invocation name.
+
+ -t --test
+ Check integrity of the specified file(s), but don't
+ decompress them. This really performs a trial
+ decompression and throws away the result.
+
+ -f --force
+ Force overwrite of output files. Normally, bzip2
+ will not overwrite existing output files. Also
+ forces bzip2 to break hard links to files, which it
+ otherwise wouldn't do.
+
+ bzip2 normally declines to decompress files which
+ don't have the correct magic header bytes. If
+ forced (-f), however, it will pass such files
+ through unmodified. This is how GNU gzip behaves.
+
+ -k --keep
+ Keep (don't delete) input files during compression
+ or decompression.
+
+ -s --small
+ Reduce memory usage, for compression, decompression
+ and testing. Files are decompressed and tested
+ using a modified algorithm which only requires 2.5
+ bytes per block byte. This means any file can be
+ decompressed in 2300k of memory, albeit at about
+ half the normal speed.
+
+ During compression, -s selects a block size of
+ 200k, which limits memory use to around the same
+ figure, at the expense of your compression ratio.
+ In short, if your machine is low on memory (8
+ megabytes or less), use -s for everything. See
+ MEMORY MANAGEMENT below.
+
+ -q --quiet
+ Suppress non-essential warning messages. Messages
+ pertaining to I/O errors and other critical events
+ will not be suppressed.
+
+ -v --verbose
+ Verbose mode -- show the compression ratio for each
+ file processed. Further -v's increase the ver-
+ bosity level, spewing out lots of information which
+ is primarily of interest for diagnostic purposes.
+
+ -L --license -V --version
+ Display the software version, license terms and
+ conditions.
+
+ -1 (or --fast) to -9 (or --best)
+ Set the block size to 100 k, 200 k .. 900 k when
+ compressing. Has no effect when decompressing.
+ See MEMORY MANAGEMENT below. The --fast and --best
+ aliases are primarily for GNU gzip compatibility.
+ In particular, --fast doesn't make things signifi-
+ cantly faster. And --best merely selects the
+ default behaviour.
+
+ -- Treats all subsequent arguments as file names, even
+ if they start with a dash. This is so you can han-
+ dle files with names beginning with a dash, for
+ example: bzip2 -- -myfilename.
+
+ --repetitive-fast --repetitive-best
+ These flags are redundant in versions 0.9.5 and
+ above. They provided some coarse control over the
+ behaviour of the sorting algorithm in earlier ver-
+ sions, which was sometimes useful. 0.9.5 and above
+ have an improved algorithm which renders these
+ flags irrelevant.
+
+
+MEMORY MANAGEMENT
+ bzip2 compresses large files in blocks. The block size
+ affects both the compression ratio achieved, and the
+ amount of memory needed for compression and decompression.
+ The flags -1 through -9 specify the block size to be
+ 100,000 bytes through 900,000 bytes (the default) respec-
+ tively. At decompression time, the block size used for
+ compression is read from the header of the compressed
+ file, and bunzip2 then allocates itself just enough memory
+ to decompress the file. Since block sizes are stored in
+ compressed files, it follows that the flags -1 to -9 are
+ irrelevant to and so ignored during decompression.
+
+ Compression and decompression requirements, in bytes, can
+ be estimated as:
+
+ Compression: 400k + ( 8 x block size )
+
+ Decompression: 100k + ( 4 x block size ), or
+ 100k + ( 2.5 x block size )
+
+ Larger block sizes give rapidly diminishing marginal
+ returns. Most of the compression comes from the first two
+ or three hundred k of block size, a fact worth bearing in
+ mind when using bzip2 on small machines. It is also
+ important to appreciate that the decompression memory
+ requirement is set at compression time by the choice of
+ block size.
+
+ For files compressed with the default 900k block size,
+ bunzip2 will require about 3700 kbytes to decompress. To
+ support decompression of any file on a 4 megabyte machine,
+ bunzip2 has an option to decompress using approximately
+ half this amount of memory, about 2300 kbytes. Decompres-
+ sion speed is also halved, so you should use this option
+ only where necessary. The relevant flag is -s.
+
+ In general, try and use the largest block size memory con-
+ straints allow, since that maximises the compression
+ achieved. Compression and decompression speed are virtu-
+ ally unaffected by block size.
+
+ Another significant point applies to files which fit in a
+ single block -- that means most files you'd encounter
+ using a large block size. The amount of real memory
+ touched is proportional to the size of the file, since the
+ file is smaller than a block. For example, compressing a
+ file 20,000 bytes long with the flag -9 will cause the
+ compressor to allocate around 7600k of memory, but only
+ touch 400k + 20000 * 8 = 560 kbytes of it. Similarly, the
+ decompressor will allocate 3700k but only touch 100k +
+ 20000 * 4 = 180 kbytes.
+
+ Here is a table which summarises the maximum memory usage
+ for different block sizes. Also recorded is the total
+ compressed size for 14 files of the Calgary Text Compres-
+ sion Corpus totalling 3,141,622 bytes. This column gives
+ some feel for how compression varies with block size.
+ These figures tend to understate the advantage of larger
+ block sizes for larger files, since the Corpus is domi-
+ nated by smaller files.
+
+ Compress Decompress Decompress Corpus
+ Flag usage usage -s usage Size
+
+ -1 1200k 500k 350k 914704
+ -2 2000k 900k 600k 877703
+ -3 2800k 1300k 850k 860338
+ -4 3600k 1700k 1100k 846899
+ -5 4400k 2100k 1350k 845160
+ -6 5200k 2500k 1600k 838626
+ -7 6100k 2900k 1850k 834096
+ -8 6800k 3300k 2100k 828642
+ -9 7600k 3700k 2350k 828642
+
+
+RECOVERING DATA FROM DAMAGED FILES
+ bzip2 compresses files in blocks, usually 900kbytes long.
+ Each block is handled independently. If a media or trans-
+ mission error causes a multi-block .bz2 file to become
+ damaged, it may be possible to recover data from the
+ undamaged blocks in the file.
+
+ The compressed representation of each block is delimited
+ by a 48-bit pattern, which makes it possible to find the
+ block boundaries with reasonable certainty. Each block
+ also carries its own 32-bit CRC, so damaged blocks can be
+ distinguished from undamaged ones.
+
+ bzip2recover is a simple program whose purpose is to
+ search for blocks in .bz2 files, and write each block out
+ into its own .bz2 file. You can then use bzip2 -t to test
+ the integrity of the resulting files, and decompress those
+ which are undamaged.
+
+ bzip2recover takes a single argument, the name of the dam-
+ aged file, and writes a number of files
+ "rec00001file.bz2", "rec00002file.bz2", etc, containing
+ the extracted blocks. The output filenames are
+ designed so that the use of wildcards in subsequent pro-
+ cessing -- for example, "bzip2 -dc rec*file.bz2 > recov-
+ ered_data" -- processes the files in the correct order.
+
+ bzip2recover should be of most use dealing with large .bz2
+ files, as these will contain many blocks. It is clearly
+ futile to use it on damaged single-block files, since a
+ damaged block cannot be recovered. If you wish to min-
+ imise any potential data loss through media or transmis-
+ sion errors, you might consider compressing with a smaller
+ block size.
+
+
+PERFORMANCE NOTES
+ The sorting phase of compression gathers together similar
+ strings in the file. Because of this, files containing
+ very long runs of repeated symbols, like "aabaabaabaab
+ ..." (repeated several hundred times) may compress more
+ slowly than normal. Versions 0.9.5 and above fare much
+ better than previous versions in this respect. The ratio
+ between worst-case and average-case compression time is in
+ the region of 10:1. For previous versions, this figure
+ was more like 100:1. You can use the -vvvv option to mon-
+ itor progress in great detail, if you want.
+
+ Decompression speed is unaffected by these phenomena.
+
+ bzip2 usually allocates several megabytes of memory to
+ operate in, and then charges all over it in a fairly ran-
+ dom fashion. This means that performance, both for com-
+ pressing and decompressing, is largely determined by the
+ speed at which your machine can service cache misses.
+ Because of this, small changes to the code to reduce the
+ miss rate have been observed to give disproportionately
+ large performance improvements. I imagine bzip2 will per-
+ form best on machines with very large caches.
+
+
+CAVEATS
+ I/O error messages are not as helpful as they could be.
+ bzip2 tries hard to detect I/O errors and exit cleanly,
+ but the details of what the problem is sometimes seem
+ rather misleading.
+
+ This manual page pertains to version 1.0.4 of bzip2. Com-
+ pressed data created by this version is entirely forwards
+ and backwards compatible with the previous public
+ releases, versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
+ 1.0.2 and 1.0.3, but with the following exception: 0.9.0
+ and above can correctly decompress multiple concatenated
+ compressed files. 0.1pl2 cannot do this; it will stop
+ after decompressing just the first file in the stream.
+
+ bzip2recover versions prior to 1.0.2 used 32-bit integers
+ to represent bit positions in compressed files, so they
+ could not handle compressed files more than 512 megabytes
+ long. Versions 1.0.2 and above use 64-bit ints on some
+ platforms which support them (GNU supported targets, and
+ Windows). To establish whether or not bzip2recover was
+ built with such a limitation, run it without arguments.
+ In any event you can build yourself an unlimited version
+ if you can recompile it with MaybeUInt64 set to be an
+ unsigned 64-bit integer.
+
+
+AUTHOR
+ Julian Seward, jsewardbzip.org.
+
+ http://www.bzip.org
+
+ The ideas embodied in bzip2 are due to (at least) the fol-
+ lowing people: Michael Burrows and David Wheeler (for the
+ block sorting transformation), David Wheeler (again, for
+ the Huffman coder), Peter Fenwick (for the structured cod-
+ ing model in the original bzip, and many refinements), and
+ Alistair Moffat, Radford Neal and Ian Witten (for the
+ arithmetic coder in the original bzip). I am much
+ indebted for their help, support and advice. See the man-
+ ual in the source distribution for pointers to sources of
+ documentation. Christian von Roques encouraged me to look
+ for faster sorting algorithms, so as to speed up compres-
+ sion. Bela Lubkin encouraged me to improve the worst-case
+ compression performance. Donna Robinson XMLised the docu-
+ mentation. The bz* scripts are derived from those of GNU
+ gzip. Many people sent patches, helped with portability
+ problems, lent machines, gave advice and were generally
+ helpful.
+
diff --git a/Utilities/cmbzip2/bzip2recover.c b/Utilities/cmbzip2/bzip2recover.c
new file mode 100644
index 0000000000..6e47b603b1
--- /dev/null
+++ b/Utilities/cmbzip2/bzip2recover.c
@@ -0,0 +1,514 @@
+/*-----------------------------------------------------------*/
+/*--- Block recoverer program for bzip2 ---*/
+/*--- bzip2recover.c ---*/
+/*-----------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+/* This program is a complete hack and should be rewritten properly.
+ It isn't very complicated. */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/* This program records bit locations in the file to be recovered.
+ That means that if 64-bit ints are not supported, we will not
+ be able to recover .bz2 files over 512MB (2^32 bits) long.
+ On GNU supported platforms, we take advantage of the 64-bit
+ int support to circumvent this problem. Ditto MSVC.
+
+ This change occurred in version 1.0.2; all prior versions have
+ the 512MB limitation.
+*/
+#ifdef __GNUC__
+ typedef unsigned long long int MaybeUInt64;
+# define MaybeUInt64_FMT "%Lu"
+#else
+#ifdef _MSC_VER
+ typedef unsigned __int64 MaybeUInt64;
+# define MaybeUInt64_FMT "%I64u"
+#else
+ typedef unsigned int MaybeUInt64;
+# define MaybeUInt64_FMT "%u"
+#endif
+#endif
+
+typedef unsigned int UInt32;
+typedef int Int32;
+typedef unsigned char UChar;
+typedef char Char;
+typedef unsigned char Bool;
+#define True ((Bool)1)
+#define False ((Bool)0)
+
+
+#define BZ_MAX_FILENAME 2000
+
+Char inFileName[BZ_MAX_FILENAME];
+Char outFileName[BZ_MAX_FILENAME];
+Char progName[BZ_MAX_FILENAME];
+
+MaybeUInt64 bytesOut = 0;
+MaybeUInt64 bytesIn = 0;
+
+
+/*---------------------------------------------------*/
+/*--- Header bytes ---*/
+/*---------------------------------------------------*/
+
+#define BZ_HDR_B 0x42 /* 'B' */
+#define BZ_HDR_Z 0x5a /* 'Z' */
+#define BZ_HDR_h 0x68 /* 'h' */
+#define BZ_HDR_0 0x30 /* '0' */
+
+
+/*---------------------------------------------------*/
+/*--- I/O errors ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------*/
+static void readError ( void )
+{
+ fprintf ( stderr,
+ "%s: I/O error reading `%s', possible reason follows.\n",
+ progName, inFileName );
+ perror ( progName );
+ fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
+ progName );
+ exit ( 1 );
+}
+
+
+/*---------------------------------------------*/
+static void writeError ( void )
+{
+ fprintf ( stderr,
+ "%s: I/O error reading `%s', possible reason follows.\n",
+ progName, inFileName );
+ perror ( progName );
+ fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
+ progName );
+ exit ( 1 );
+}
+
+
+/*---------------------------------------------*/
+static void mallocFail ( Int32 n )
+{
+ fprintf ( stderr,
+ "%s: malloc failed on request for %d bytes.\n",
+ progName, n );
+ fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
+ progName );
+ exit ( 1 );
+}
+
+
+/*---------------------------------------------*/
+static void tooManyBlocks ( Int32 max_handled_blocks )
+{
+ fprintf ( stderr,
+ "%s: `%s' appears to contain more than %d blocks\n",
+ progName, inFileName, max_handled_blocks );
+ fprintf ( stderr,
+ "%s: and cannot be handled. To fix, increase\n",
+ progName );
+ fprintf ( stderr,
+ "%s: BZ_MAX_HANDLED_BLOCKS in bzip2recover.c, and recompile.\n",
+ progName );
+ exit ( 1 );
+}
+
+
+
+/*---------------------------------------------------*/
+/*--- Bit stream I/O ---*/
+/*---------------------------------------------------*/
+
+typedef
+ struct {
+ FILE* handle;
+ Int32 buffer;
+ Int32 buffLive;
+ Char mode;
+ }
+ BitStream;
+
+
+/*---------------------------------------------*/
+static BitStream* bsOpenReadStream ( FILE* stream )
+{
+ BitStream *bs = malloc ( sizeof(BitStream) );
+ if (bs == NULL) mallocFail ( sizeof(BitStream) );
+ bs->handle = stream;
+ bs->buffer = 0;
+ bs->buffLive = 0;
+ bs->mode = 'r';
+ return bs;
+}
+
+
+/*---------------------------------------------*/
+static BitStream* bsOpenWriteStream ( FILE* stream )
+{
+ BitStream *bs = malloc ( sizeof(BitStream) );
+ if (bs == NULL) mallocFail ( sizeof(BitStream) );
+ bs->handle = stream;
+ bs->buffer = 0;
+ bs->buffLive = 0;
+ bs->mode = 'w';
+ return bs;
+}
+
+
+/*---------------------------------------------*/
+static void bsPutBit ( BitStream* bs, Int32 bit )
+{
+ if (bs->buffLive == 8) {
+ Int32 retVal = putc ( (UChar) bs->buffer, bs->handle );
+ if (retVal == EOF) writeError();
+ bytesOut++;
+ bs->buffLive = 1;
+ bs->buffer = bit & 0x1;
+ } else {
+ bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) );
+ bs->buffLive++;
+ };
+}
+
+
+/*---------------------------------------------*/
+/*--
+ Returns 0 or 1, or 2 to indicate EOF.
+--*/
+static Int32 bsGetBit ( BitStream* bs )
+{
+ if (bs->buffLive > 0) {
+ bs->buffLive --;
+ return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
+ } else {
+ Int32 retVal = getc ( bs->handle );
+ if ( retVal == EOF ) {
+ if (errno != 0) readError();
+ return 2;
+ }
+ bs->buffLive = 7;
+ bs->buffer = retVal;
+ return ( ((bs->buffer) >> 7) & 0x1 );
+ }
+}
+
+
+/*---------------------------------------------*/
+static void bsClose ( BitStream* bs )
+{
+ Int32 retVal;
+
+ if ( bs->mode == 'w' ) {
+ while ( bs->buffLive < 8 ) {
+ bs->buffLive++;
+ bs->buffer <<= 1;
+ };
+ retVal = putc ( (UChar) (bs->buffer), bs->handle );
+ if (retVal == EOF) writeError();
+ bytesOut++;
+ retVal = fflush ( bs->handle );
+ if (retVal == EOF) writeError();
+ }
+ retVal = fclose ( bs->handle );
+ if (retVal == EOF) {
+ if (bs->mode == 'w') writeError(); else readError();
+ }
+ free ( bs );
+}
+
+
+/*---------------------------------------------*/
+static void bsPutUChar ( BitStream* bs, UChar c )
+{
+ Int32 i;
+ for (i = 7; i >= 0; i--)
+ bsPutBit ( bs, (((UInt32) c) >> i) & 0x1 );
+}
+
+
+/*---------------------------------------------*/
+static void bsPutUInt32 ( BitStream* bs, UInt32 c )
+{
+ Int32 i;
+
+ for (i = 31; i >= 0; i--)
+ bsPutBit ( bs, (c >> i) & 0x1 );
+}
+
+
+/*---------------------------------------------*/
+static Bool endsInBz2 ( Char* name )
+{
+ Int32 n = strlen ( name );
+ if (n <= 4) return False;
+ return
+ (name[n-4] == '.' &&
+ name[n-3] == 'b' &&
+ name[n-2] == 'z' &&
+ name[n-1] == '2');
+}
+
+
+/*---------------------------------------------------*/
+/*--- ---*/
+/*---------------------------------------------------*/
+
+/* This logic isn't really right when it comes to Cygwin. */
+#ifdef _WIN32
+# define BZ_SPLIT_SYM '\\' /* path splitter on Windows platform */
+#else
+# define BZ_SPLIT_SYM '/' /* path splitter on Unix platform */
+#endif
+
+#define BLOCK_HEADER_HI 0x00003141UL
+#define BLOCK_HEADER_LO 0x59265359UL
+
+#define BLOCK_ENDMARK_HI 0x00001772UL
+#define BLOCK_ENDMARK_LO 0x45385090UL
+
+/* Increase if necessary. However, a .bz2 file with > 50000 blocks
+ would have an uncompressed size of at least 40GB, so the chances
+ are low you'll need to up this.
+*/
+#define BZ_MAX_HANDLED_BLOCKS 50000
+
+MaybeUInt64 bStart [BZ_MAX_HANDLED_BLOCKS];
+MaybeUInt64 bEnd [BZ_MAX_HANDLED_BLOCKS];
+MaybeUInt64 rbStart[BZ_MAX_HANDLED_BLOCKS];
+MaybeUInt64 rbEnd [BZ_MAX_HANDLED_BLOCKS];
+
+Int32 main ( Int32 argc, Char** argv )
+{
+ FILE* inFile;
+ FILE* outFile;
+ BitStream* bsIn, *bsWr;
+ Int32 b, wrBlock, currBlock, rbCtr;
+ MaybeUInt64 bitsRead;
+
+ UInt32 buffHi, buffLo, blockCRC;
+ Char* p;
+
+ strcpy ( progName, argv[0] );
+ inFileName[0] = outFileName[0] = 0;
+
+ fprintf ( stderr,
+ "bzip2recover 1.0.5: extracts blocks from damaged .bz2 files.\n" );
+
+ if (argc != 2) {
+ fprintf ( stderr, "%s: usage is `%s damaged_file_name'.\n",
+ progName, progName );
+ switch (sizeof(MaybeUInt64)) {
+ case 8:
+ fprintf(stderr,
+ "\trestrictions on size of recovered file: None\n");
+ break;
+ case 4:
+ fprintf(stderr,
+ "\trestrictions on size of recovered file: 512 MB\n");
+ fprintf(stderr,
+ "\tto circumvent, recompile with MaybeUInt64 as an\n"
+ "\tunsigned 64-bit int.\n");
+ break;
+ default:
+ fprintf(stderr,
+ "\tsizeof(MaybeUInt64) is not 4 or 8 -- "
+ "configuration error.\n");
+ break;
+ }
+ exit(1);
+ }
+
+ if (strlen(argv[1]) >= BZ_MAX_FILENAME-20) {
+ fprintf ( stderr,
+ "%s: supplied filename is suspiciously (>= %d chars) long. Bye!\n",
+ progName, (int)strlen(argv[1]) );
+ exit(1);
+ }
+
+ strcpy ( inFileName, argv[1] );
+
+ inFile = fopen ( inFileName, "rb" );
+ if (inFile == NULL) {
+ fprintf ( stderr, "%s: can't read `%s'\n", progName, inFileName );
+ exit(1);
+ }
+
+ bsIn = bsOpenReadStream ( inFile );
+ fprintf ( stderr, "%s: searching for block boundaries ...\n", progName );
+
+ bitsRead = 0;
+ buffHi = buffLo = 0;
+ currBlock = 0;
+ bStart[currBlock] = 0;
+
+ rbCtr = 0;
+
+ while (True) {
+ b = bsGetBit ( bsIn );
+ bitsRead++;
+ if (b == 2) {
+ if (bitsRead >= bStart[currBlock] &&
+ (bitsRead - bStart[currBlock]) >= 40) {
+ bEnd[currBlock] = bitsRead-1;
+ if (currBlock > 0)
+ fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
+ " to " MaybeUInt64_FMT " (incomplete)\n",
+ currBlock, bStart[currBlock], bEnd[currBlock] );
+ } else
+ currBlock--;
+ break;
+ }
+ buffHi = (buffHi << 1) | (buffLo >> 31);
+ buffLo = (buffLo << 1) | (b & 1);
+ if ( ( (buffHi & 0x0000ffff) == BLOCK_HEADER_HI
+ && buffLo == BLOCK_HEADER_LO)
+ ||
+ ( (buffHi & 0x0000ffff) == BLOCK_ENDMARK_HI
+ && buffLo == BLOCK_ENDMARK_LO)
+ ) {
+ if (bitsRead > 49) {
+ bEnd[currBlock] = bitsRead-49;
+ } else {
+ bEnd[currBlock] = 0;
+ }
+ if (currBlock > 0 &&
+ (bEnd[currBlock] - bStart[currBlock]) >= 130) {
+ fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
+ " to " MaybeUInt64_FMT "\n",
+ rbCtr+1, bStart[currBlock], bEnd[currBlock] );
+ rbStart[rbCtr] = bStart[currBlock];
+ rbEnd[rbCtr] = bEnd[currBlock];
+ rbCtr++;
+ }
+ if (currBlock >= BZ_MAX_HANDLED_BLOCKS)
+ tooManyBlocks(BZ_MAX_HANDLED_BLOCKS);
+ currBlock++;
+
+ bStart[currBlock] = bitsRead;
+ }
+ }
+
+ bsClose ( bsIn );
+
+ /*-- identified blocks run from 1 to rbCtr inclusive. --*/
+
+ if (rbCtr < 1) {
+ fprintf ( stderr,
+ "%s: sorry, I couldn't find any block boundaries.\n",
+ progName );
+ exit(1);
+ };
+
+ fprintf ( stderr, "%s: splitting into blocks\n", progName );
+
+ inFile = fopen ( inFileName, "rb" );
+ if (inFile == NULL) {
+ fprintf ( stderr, "%s: can't open `%s'\n", progName, inFileName );
+ exit(1);
+ }
+ bsIn = bsOpenReadStream ( inFile );
+
+ /*-- placate gcc's dataflow analyser --*/
+ blockCRC = 0; bsWr = 0;
+
+ bitsRead = 0;
+ outFile = NULL;
+ wrBlock = 0;
+ while (True) {
+ b = bsGetBit(bsIn);
+ if (b == 2) break;
+ buffHi = (buffHi << 1) | (buffLo >> 31);
+ buffLo = (buffLo << 1) | (b & 1);
+ if (bitsRead == 47+rbStart[wrBlock])
+ blockCRC = (buffHi << 16) | (buffLo >> 16);
+
+ if (outFile != NULL && bitsRead >= rbStart[wrBlock]
+ && bitsRead <= rbEnd[wrBlock]) {
+ bsPutBit ( bsWr, b );
+ }
+
+ bitsRead++;
+
+ if (bitsRead == rbEnd[wrBlock]+1) {
+ if (outFile != NULL) {
+ bsPutUChar ( bsWr, 0x17 ); bsPutUChar ( bsWr, 0x72 );
+ bsPutUChar ( bsWr, 0x45 ); bsPutUChar ( bsWr, 0x38 );
+ bsPutUChar ( bsWr, 0x50 ); bsPutUChar ( bsWr, 0x90 );
+ bsPutUInt32 ( bsWr, blockCRC );
+ bsClose ( bsWr );
+ }
+ if (wrBlock >= rbCtr) break;
+ wrBlock++;
+ } else
+ if (bitsRead == rbStart[wrBlock]) {
+ /* Create the output file name, correctly handling leading paths.
+ (31.10.2001 by Sergey E. Kusikov) */
+ Char* split;
+ Int32 ofs, k;
+ for (k = 0; k < BZ_MAX_FILENAME; k++)
+ outFileName[k] = 0;
+ strcpy (outFileName, inFileName);
+ split = strrchr (outFileName, BZ_SPLIT_SYM);
+ if (split == NULL) {
+ split = outFileName;
+ } else {
+ ++split;
+ }
+ /* Now split points to the start of the basename. */
+ ofs = split - outFileName;
+ sprintf (split, "rec%5d", wrBlock+1);
+ for (p = split; *p != 0; p++) if (*p == ' ') *p = '0';
+ strcat (outFileName, inFileName + ofs);
+
+ if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
+
+ fprintf ( stderr, " writing block %d to `%s' ...\n",
+ wrBlock+1, outFileName );
+
+ outFile = fopen ( outFileName, "wb" );
+ if (outFile == NULL) {
+ fprintf ( stderr, "%s: can't write `%s'\n",
+ progName, outFileName );
+ exit(1);
+ }
+ bsWr = bsOpenWriteStream ( outFile );
+ bsPutUChar ( bsWr, BZ_HDR_B );
+ bsPutUChar ( bsWr, BZ_HDR_Z );
+ bsPutUChar ( bsWr, BZ_HDR_h );
+ bsPutUChar ( bsWr, BZ_HDR_0 + 9 );
+ bsPutUChar ( bsWr, 0x31 ); bsPutUChar ( bsWr, 0x41 );
+ bsPutUChar ( bsWr, 0x59 ); bsPutUChar ( bsWr, 0x26 );
+ bsPutUChar ( bsWr, 0x53 ); bsPutUChar ( bsWr, 0x59 );
+ }
+ }
+
+ fprintf ( stderr, "%s: finished\n", progName );
+ return 0;
+}
+
+
+
+/*-----------------------------------------------------------*/
+/*--- end bzip2recover.c ---*/
+/*-----------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/bzlib.c b/Utilities/cmbzip2/bzlib.c
new file mode 100644
index 0000000000..aeecef10f7
--- /dev/null
+++ b/Utilities/cmbzip2/bzlib.c
@@ -0,0 +1,1575 @@
+
+/*-------------------------------------------------------------*/
+/*--- Library top-level functions. ---*/
+/*--- bzlib.c ---*/
+/*-------------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+/* CHANGES
+ 0.9.0 -- original version.
+ 0.9.0a/b -- no changes in this file.
+ 0.9.0c -- made zero-length BZ_FLUSH work correctly in bzCompress().
+ fixed bzWrite/bzRead to ignore zero-length requests.
+ fixed bzread to correctly handle read requests after EOF.
+ wrong parameter order in call to bzDecompressInit in
+ bzBuffToBuffDecompress. Fixed.
+*/
+
+#include "bzlib_private.h"
+
+
+/*---------------------------------------------------*/
+/*--- Compression stuff ---*/
+/*---------------------------------------------------*/
+
+
+/*---------------------------------------------------*/
+#ifndef BZ_NO_STDIO
+void BZ2_bz__AssertH__fail ( int errcode )
+{
+ fprintf(stderr,
+ "\n\nbzip2/libbzip2: internal error number %d.\n"
+ "This is a bug in bzip2/libbzip2, %s.\n"
+ "Please report it to me at: jseward@bzip.org. If this happened\n"
+ "when you were using some program which uses libbzip2 as a\n"
+ "component, you should also report this bug to the author(s)\n"
+ "of that program. Please make an effort to report this bug;\n"
+ "timely and accurate bug reports eventually lead to higher\n"
+ "quality software. Thanks. Julian Seward, 10 December 2007.\n\n",
+ errcode,
+ BZ2_bzlibVersion()
+ );
+
+ if (errcode == 1007) {
+ fprintf(stderr,
+ "\n*** A special note about internal error number 1007 ***\n"
+ "\n"
+ "Experience suggests that a common cause of i.e. 1007\n"
+ "is unreliable memory or other hardware. The 1007 assertion\n"
+ "just happens to cross-check the results of huge numbers of\n"
+ "memory reads/writes, and so acts (unintendedly) as a stress\n"
+ "test of your memory system.\n"
+ "\n"
+ "I suggest the following: try compressing the file again,\n"
+ "possibly monitoring progress in detail with the -vv flag.\n"
+ "\n"
+ "* If the error cannot be reproduced, and/or happens at different\n"
+ " points in compression, you may have a flaky memory system.\n"
+ " Try a memory-test program. I have used Memtest86\n"
+ " (www.memtest86.com). At the time of writing it is free (GPLd).\n"
+ " Memtest86 tests memory much more thorougly than your BIOSs\n"
+ " power-on test, and may find failures that the BIOS doesn't.\n"
+ "\n"
+ "* If the error can be repeatably reproduced, this is a bug in\n"
+ " bzip2, and I would very much like to hear about it. Please\n"
+ " let me know, and, ideally, save a copy of the file causing the\n"
+ " problem -- without which I will be unable to investigate it.\n"
+ "\n"
+ );
+ }
+
+ exit(3);
+}
+#endif
+
+
+/*---------------------------------------------------*/
+static
+int bz_config_ok ( void )
+{
+ if (sizeof(int) != 4) return 0;
+ if (sizeof(short) != 2) return 0;
+ if (sizeof(char) != 1) return 0;
+ return 1;
+}
+
+
+/*---------------------------------------------------*/
+static
+void* default_bzalloc ( void* opaque, Int32 items, Int32 size )
+{
+ void* v = malloc ( items * size );
+ (void)opaque;
+ return v;
+}
+
+static
+void default_bzfree ( void* opaque, void* addr )
+{
+ if (addr != NULL) free ( addr );
+ (void)opaque;
+}
+
+
+/*---------------------------------------------------*/
+static
+void prepare_new_block ( EState* s )
+{
+ Int32 i;
+ s->nblock = 0;
+ s->numZ = 0;
+ s->state_out_pos = 0;
+ BZ_INITIALISE_CRC ( s->blockCRC );
+ for (i = 0; i < 256; i++) s->inUse[i] = False;
+ s->blockNo++;
+}
+
+
+/*---------------------------------------------------*/
+static
+void init_RL ( EState* s )
+{
+ s->state_in_ch = 256;
+ s->state_in_len = 0;
+}
+
+
+static
+Bool isempty_RL ( EState* s )
+{
+ if (s->state_in_ch < 256 && s->state_in_len > 0)
+ return False; else
+ return True;
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzCompressInit)
+ ( bz_stream* strm,
+ int blockSize100k,
+ int verbosity,
+ int workFactor )
+{
+ Int32 n;
+ EState* s;
+
+ if (!bz_config_ok()) return BZ_CONFIG_ERROR;
+
+ if (strm == NULL ||
+ blockSize100k < 1 || blockSize100k > 9 ||
+ workFactor < 0 || workFactor > 250)
+ return BZ_PARAM_ERROR;
+
+ if (workFactor == 0) workFactor = 30;
+ if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
+ if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
+
+ s = BZALLOC( sizeof(EState) );
+ if (s == NULL) return BZ_MEM_ERROR;
+ s->strm = strm;
+
+ s->arr1 = NULL;
+ s->arr2 = NULL;
+ s->ftab = NULL;
+
+ n = 100000 * blockSize100k;
+ s->arr1 = BZALLOC( n * sizeof(UInt32) );
+ s->arr2 = BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) );
+ s->ftab = BZALLOC( 65537 * sizeof(UInt32) );
+
+ if (s->arr1 == NULL || s->arr2 == NULL || s->ftab == NULL) {
+ if (s->arr1 != NULL) BZFREE(s->arr1);
+ if (s->arr2 != NULL) BZFREE(s->arr2);
+ if (s->ftab != NULL) BZFREE(s->ftab);
+ if (s != NULL) BZFREE(s);
+ return BZ_MEM_ERROR;
+ }
+
+ s->blockNo = 0;
+ s->state = BZ_S_INPUT;
+ s->mode = BZ_M_RUNNING;
+ s->combinedCRC = 0;
+ s->blockSize100k = blockSize100k;
+ s->nblockMAX = 100000 * blockSize100k - 19;
+ s->verbosity = verbosity;
+ s->workFactor = workFactor;
+
+ s->block = (UChar*)s->arr2;
+ s->mtfv = (UInt16*)s->arr1;
+ s->zbits = NULL;
+ s->ptr = (UInt32*)s->arr1;
+
+ strm->state = s;
+ strm->total_in_lo32 = 0;
+ strm->total_in_hi32 = 0;
+ strm->total_out_lo32 = 0;
+ strm->total_out_hi32 = 0;
+ init_RL ( s );
+ prepare_new_block ( s );
+ return BZ_OK;
+}
+
+
+/*---------------------------------------------------*/
+static
+void add_pair_to_block ( EState* s )
+{
+ Int32 i;
+ UChar ch = (UChar)(s->state_in_ch);
+ for (i = 0; i < s->state_in_len; i++) {
+ BZ_UPDATE_CRC( s->blockCRC, ch );
+ }
+ s->inUse[s->state_in_ch] = True;
+ switch (s->state_in_len) {
+ case 1:
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ break;
+ case 2:
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ break;
+ case 3:
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ break;
+ default:
+ s->inUse[s->state_in_len-4] = True;
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ s->block[s->nblock] = (UChar)ch; s->nblock++;
+ s->block[s->nblock] = ((UChar)(s->state_in_len-4));
+ s->nblock++;
+ break;
+ }
+}
+
+
+/*---------------------------------------------------*/
+static
+void flush_RL ( EState* s )
+{
+ if (s->state_in_ch < 256) add_pair_to_block ( s );
+ init_RL ( s );
+}
+
+
+/*---------------------------------------------------*/
+#define ADD_CHAR_TO_BLOCK(zs,zchh0) \
+{ \
+ UInt32 zchh = (UInt32)(zchh0); \
+ /*-- fast track the common case --*/ \
+ if (zchh != zs->state_in_ch && \
+ zs->state_in_len == 1) { \
+ UChar ch = (UChar)(zs->state_in_ch); \
+ BZ_UPDATE_CRC( zs->blockCRC, ch ); \
+ zs->inUse[zs->state_in_ch] = True; \
+ zs->block[zs->nblock] = (UChar)ch; \
+ zs->nblock++; \
+ zs->state_in_ch = zchh; \
+ } \
+ else \
+ /*-- general, uncommon cases --*/ \
+ if (zchh != zs->state_in_ch || \
+ zs->state_in_len == 255) { \
+ if (zs->state_in_ch < 256) \
+ add_pair_to_block ( zs ); \
+ zs->state_in_ch = zchh; \
+ zs->state_in_len = 1; \
+ } else { \
+ zs->state_in_len++; \
+ } \
+}
+
+
+/*---------------------------------------------------*/
+static
+Bool copy_input_until_stop ( EState* s )
+{
+ Bool progress_in = False;
+
+ if (s->mode == BZ_M_RUNNING) {
+
+ /*-- fast track the common case --*/
+ while (True) {
+ /*-- block full? --*/
+ if (s->nblock >= s->nblockMAX) break;
+ /*-- no input? --*/
+ if (s->strm->avail_in == 0) break;
+ progress_in = True;
+ ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) );
+ s->strm->next_in++;
+ s->strm->avail_in--;
+ s->strm->total_in_lo32++;
+ if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++;
+ }
+
+ } else {
+
+ /*-- general, uncommon case --*/
+ while (True) {
+ /*-- block full? --*/
+ if (s->nblock >= s->nblockMAX) break;
+ /*-- no input? --*/
+ if (s->strm->avail_in == 0) break;
+ /*-- flush/finish end? --*/
+ if (s->avail_in_expect == 0) break;
+ progress_in = True;
+ ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) );
+ s->strm->next_in++;
+ s->strm->avail_in--;
+ s->strm->total_in_lo32++;
+ if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++;
+ s->avail_in_expect--;
+ }
+ }
+ return progress_in;
+}
+
+
+/*---------------------------------------------------*/
+static
+Bool copy_output_until_stop ( EState* s )
+{
+ Bool progress_out = False;
+
+ while (True) {
+
+ /*-- no output space? --*/
+ if (s->strm->avail_out == 0) break;
+
+ /*-- block done? --*/
+ if (s->state_out_pos >= s->numZ) break;
+
+ progress_out = True;
+ *(s->strm->next_out) = s->zbits[s->state_out_pos];
+ s->state_out_pos++;
+ s->strm->avail_out--;
+ s->strm->next_out++;
+ s->strm->total_out_lo32++;
+ if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
+ }
+
+ return progress_out;
+}
+
+
+/*---------------------------------------------------*/
+static
+Bool handle_compress ( bz_stream* strm )
+{
+ Bool progress_in = False;
+ Bool progress_out = False;
+ EState* s = strm->state;
+
+ while (True) {
+
+ if (s->state == BZ_S_OUTPUT) {
+ progress_out |= copy_output_until_stop ( s );
+ if (s->state_out_pos < s->numZ) break;
+ if (s->mode == BZ_M_FINISHING &&
+ s->avail_in_expect == 0 &&
+ isempty_RL(s)) break;
+ prepare_new_block ( s );
+ s->state = BZ_S_INPUT;
+ if (s->mode == BZ_M_FLUSHING &&
+ s->avail_in_expect == 0 &&
+ isempty_RL(s)) break;
+ }
+
+ if (s->state == BZ_S_INPUT) {
+ progress_in |= copy_input_until_stop ( s );
+ if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) {
+ flush_RL ( s );
+ BZ2_compressBlock ( s, (Bool)(s->mode == BZ_M_FINISHING) );
+ s->state = BZ_S_OUTPUT;
+ }
+ else
+ if (s->nblock >= s->nblockMAX) {
+ BZ2_compressBlock ( s, False );
+ s->state = BZ_S_OUTPUT;
+ }
+ else
+ if (s->strm->avail_in == 0) {
+ break;
+ }
+ }
+
+ }
+
+ return progress_in || progress_out;
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
+{
+ Bool progress;
+ EState* s;
+ if (strm == NULL) return BZ_PARAM_ERROR;
+ s = strm->state;
+ if (s == NULL) return BZ_PARAM_ERROR;
+ if (s->strm != strm) return BZ_PARAM_ERROR;
+
+ preswitch:
+ switch (s->mode) {
+
+ case BZ_M_IDLE:
+ return BZ_SEQUENCE_ERROR;
+
+ case BZ_M_RUNNING:
+ if (action == BZ_RUN) {
+ progress = handle_compress ( strm );
+ return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;
+ }
+ else
+ if (action == BZ_FLUSH) {
+ s->avail_in_expect = strm->avail_in;
+ s->mode = BZ_M_FLUSHING;
+ goto preswitch;
+ }
+ else
+ if (action == BZ_FINISH) {
+ s->avail_in_expect = strm->avail_in;
+ s->mode = BZ_M_FINISHING;
+ goto preswitch;
+ }
+ else
+ return BZ_PARAM_ERROR;
+
+ case BZ_M_FLUSHING:
+ if (action != BZ_FLUSH) return BZ_SEQUENCE_ERROR;
+ if (s->avail_in_expect != s->strm->avail_in)
+ return BZ_SEQUENCE_ERROR;
+ progress = handle_compress ( strm );
+ if (s->avail_in_expect > 0 || !isempty_RL(s) ||
+ s->state_out_pos < s->numZ) return BZ_FLUSH_OK;
+ s->mode = BZ_M_RUNNING;
+ return BZ_RUN_OK;
+
+ case BZ_M_FINISHING:
+ if (action != BZ_FINISH) return BZ_SEQUENCE_ERROR;
+ if (s->avail_in_expect != s->strm->avail_in)
+ return BZ_SEQUENCE_ERROR;
+ progress = handle_compress ( strm );
+ if (!progress) return BZ_SEQUENCE_ERROR;
+ if (s->avail_in_expect > 0 || !isempty_RL(s) ||
+ s->state_out_pos < s->numZ) return BZ_FINISH_OK;
+ s->mode = BZ_M_IDLE;
+ return BZ_STREAM_END;
+ }
+ return BZ_OK; /*--not reached--*/
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzCompressEnd) ( bz_stream *strm )
+{
+ EState* s;
+ if (strm == NULL) return BZ_PARAM_ERROR;
+ s = strm->state;
+ if (s == NULL) return BZ_PARAM_ERROR;
+ if (s->strm != strm) return BZ_PARAM_ERROR;
+
+ if (s->arr1 != NULL) BZFREE(s->arr1);
+ if (s->arr2 != NULL) BZFREE(s->arr2);
+ if (s->ftab != NULL) BZFREE(s->ftab);
+ BZFREE(strm->state);
+
+ strm->state = NULL;
+
+ return BZ_OK;
+}
+
+
+/*---------------------------------------------------*/
+/*--- Decompression stuff ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzDecompressInit)
+ ( bz_stream* strm,
+ int verbosity,
+ int small )
+{
+ DState* s;
+
+ if (!bz_config_ok()) return BZ_CONFIG_ERROR;
+
+ if (strm == NULL) return BZ_PARAM_ERROR;
+ if (small != 0 && small != 1) return BZ_PARAM_ERROR;
+ if (verbosity < 0 || verbosity > 4) return BZ_PARAM_ERROR;
+
+ if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
+ if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
+
+ s = BZALLOC( sizeof(DState) );
+ if (s == NULL) return BZ_MEM_ERROR;
+ s->strm = strm;
+ strm->state = s;
+ s->state = BZ_X_MAGIC_1;
+ s->bsLive = 0;
+ s->bsBuff = 0;
+ s->calculatedCombinedCRC = 0;
+ strm->total_in_lo32 = 0;
+ strm->total_in_hi32 = 0;
+ strm->total_out_lo32 = 0;
+ strm->total_out_hi32 = 0;
+ s->smallDecompress = (Bool)small;
+ s->ll4 = NULL;
+ s->ll16 = NULL;
+ s->tt = NULL;
+ s->currBlockNo = 0;
+ s->verbosity = verbosity;
+
+ return BZ_OK;
+}
+
+
+/*---------------------------------------------------*/
+/* Return True iff data corruption is discovered.
+ Returns False if there is no problem.
+*/
+static
+Bool unRLE_obuf_to_output_FAST ( DState* s )
+{
+ UChar k1;
+
+ if (s->blockRandomised) {
+
+ while (True) {
+ /* try to finish existing run */
+ while (True) {
+ if (s->strm->avail_out == 0) return False;
+ if (s->state_out_len == 0) break;
+ *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
+ BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
+ s->state_out_len--;
+ s->strm->next_out++;
+ s->strm->avail_out--;
+ s->strm->total_out_lo32++;
+ if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
+ }
+
+ /* can a new run be started? */
+ if (s->nblock_used == s->save_nblock+1) return False;
+
+ /* Only caused by corrupt data stream? */
+ if (s->nblock_used > s->save_nblock+1)
+ return True;
+
+ s->state_out_len = 1;
+ s->state_out_ch = s->k0;
+ BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
+ k1 ^= BZ_RAND_MASK; s->nblock_used++;
+ if (s->nblock_used == s->save_nblock+1) continue;
+ if (k1 != s->k0) { s->k0 = k1; continue; };
+
+ s->state_out_len = 2;
+ BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
+ k1 ^= BZ_RAND_MASK; s->nblock_used++;
+ if (s->nblock_used == s->save_nblock+1) continue;
+ if (k1 != s->k0) { s->k0 = k1; continue; };
+
+ s->state_out_len = 3;
+ BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
+ k1 ^= BZ_RAND_MASK; s->nblock_used++;
+ if (s->nblock_used == s->save_nblock+1) continue;
+ if (k1 != s->k0) { s->k0 = k1; continue; };
+
+ BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
+ k1 ^= BZ_RAND_MASK; s->nblock_used++;
+ s->state_out_len = ((Int32)k1) + 4;
+ BZ_GET_FAST(s->k0); BZ_RAND_UPD_MASK;
+ s->k0 ^= BZ_RAND_MASK; s->nblock_used++;
+ }
+
+ } else {
+
+ /* restore */
+ UInt32 c_calculatedBlockCRC = s->calculatedBlockCRC;
+ UChar c_state_out_ch = s->state_out_ch;
+ Int32 c_state_out_len = s->state_out_len;
+ Int32 c_nblock_used = s->nblock_used;
+ Int32 c_k0 = s->k0;
+ UInt32* c_tt = s->tt;
+ UInt32 c_tPos = s->tPos;
+ char* cs_next_out = s->strm->next_out;
+ unsigned int cs_avail_out = s->strm->avail_out;
+ Int32 ro_blockSize100k = s->blockSize100k;
+ /* end restore */
+
+ UInt32 avail_out_INIT = cs_avail_out;
+ Int32 s_save_nblockPP = s->save_nblock+1;
+ unsigned int total_out_lo32_old;
+
+ while (True) {
+
+ /* try to finish existing run */
+ if (c_state_out_len > 0) {
+ while (True) {
+ if (cs_avail_out == 0) goto return_notr;
+ if (c_state_out_len == 1) break;
+ *( (UChar*)(cs_next_out) ) = c_state_out_ch;
+ BZ_UPDATE_CRC ( c_calculatedBlockCRC, c_state_out_ch );
+ c_state_out_len--;
+ cs_next_out++;
+ cs_avail_out--;
+ }
+ s_state_out_len_eq_one:
+ {
+ if (cs_avail_out == 0) {
+ c_state_out_len = 1; goto return_notr;
+ };
+ *( (UChar*)(cs_next_out) ) = c_state_out_ch;
+ BZ_UPDATE_CRC ( c_calculatedBlockCRC, c_state_out_ch );
+ cs_next_out++;
+ cs_avail_out--;
+ }
+ }
+ /* Only caused by corrupt data stream? */
+ if (c_nblock_used > s_save_nblockPP)
+ return True;
+
+ /* can a new run be started? */
+ if (c_nblock_used == s_save_nblockPP) {
+ c_state_out_len = 0; goto return_notr;
+ };
+ c_state_out_ch = c_k0;
+ BZ_GET_FAST_C(k1); c_nblock_used++;
+ if (k1 != c_k0) {
+ c_k0 = k1; goto s_state_out_len_eq_one;
+ };
+ if (c_nblock_used == s_save_nblockPP)
+ goto s_state_out_len_eq_one;
+
+ c_state_out_len = 2;
+ BZ_GET_FAST_C(k1); c_nblock_used++;
+ if (c_nblock_used == s_save_nblockPP) continue;
+ if (k1 != c_k0) { c_k0 = k1; continue; };
+
+ c_state_out_len = 3;
+ BZ_GET_FAST_C(k1); c_nblock_used++;
+ if (c_nblock_used == s_save_nblockPP) continue;
+ if (k1 != c_k0) { c_k0 = k1; continue; };
+
+ BZ_GET_FAST_C(k1); c_nblock_used++;
+ c_state_out_len = ((Int32)k1) + 4;
+ BZ_GET_FAST_C(c_k0); c_nblock_used++;
+ }
+
+ return_notr:
+ total_out_lo32_old = s->strm->total_out_lo32;
+ s->strm->total_out_lo32 += (avail_out_INIT - cs_avail_out);
+ if (s->strm->total_out_lo32 < total_out_lo32_old)
+ s->strm->total_out_hi32++;
+
+ /* save */
+ s->calculatedBlockCRC = c_calculatedBlockCRC;
+ s->state_out_ch = c_state_out_ch;
+ s->state_out_len = c_state_out_len;
+ s->nblock_used = c_nblock_used;
+ s->k0 = c_k0;
+ s->tt = c_tt;
+ s->tPos = c_tPos;
+ s->strm->next_out = cs_next_out;
+ s->strm->avail_out = cs_avail_out;
+ /* end save */
+ }
+ return False;
+}
+
+
+
+/*---------------------------------------------------*/
+__inline__ Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
+{
+ Int32 nb, na, mid;
+ nb = 0;
+ na = 256;
+ do {
+ mid = (nb + na) >> 1;
+ if (indx >= cftab[mid]) nb = mid; else na = mid;
+ }
+ while (na - nb != 1);
+ return nb;
+}
+
+
+/*---------------------------------------------------*/
+/* Return True iff data corruption is discovered.
+ Returns False if there is no problem.
+*/
+static
+Bool unRLE_obuf_to_output_SMALL ( DState* s )
+{
+ UChar k1;
+
+ if (s->blockRandomised) {
+
+ while (True) {
+ /* try to finish existing run */
+ while (True) {
+ if (s->strm->avail_out == 0) return False;
+ if (s->state_out_len == 0) break;
+ *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
+ BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
+ s->state_out_len--;
+ s->strm->next_out++;
+ s->strm->avail_out--;
+ s->strm->total_out_lo32++;
+ if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
+ }
+
+ /* can a new run be started? */
+ if (s->nblock_used == s->save_nblock+1) return False;
+
+ /* Only caused by corrupt data stream? */
+ if (s->nblock_used > s->save_nblock+1)
+ return True;
+
+ s->state_out_len = 1;
+ s->state_out_ch = s->k0;
+ BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
+ k1 ^= BZ_RAND_MASK; s->nblock_used++;
+ if (s->nblock_used == s->save_nblock+1) continue;
+ if (k1 != s->k0) { s->k0 = k1; continue; };
+
+ s->state_out_len = 2;
+ BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
+ k1 ^= BZ_RAND_MASK; s->nblock_used++;
+ if (s->nblock_used == s->save_nblock+1) continue;
+ if (k1 != s->k0) { s->k0 = k1; continue; };
+
+ s->state_out_len = 3;
+ BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
+ k1 ^= BZ_RAND_MASK; s->nblock_used++;
+ if (s->nblock_used == s->save_nblock+1) continue;
+ if (k1 != s->k0) { s->k0 = k1; continue; };
+
+ BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
+ k1 ^= BZ_RAND_MASK; s->nblock_used++;
+ s->state_out_len = ((Int32)k1) + 4;
+ BZ_GET_SMALL(s->k0); BZ_RAND_UPD_MASK;
+ s->k0 ^= BZ_RAND_MASK; s->nblock_used++;
+ }
+
+ } else {
+
+ while (True) {
+ /* try to finish existing run */
+ while (True) {
+ if (s->strm->avail_out == 0) return False;
+ if (s->state_out_len == 0) break;
+ *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
+ BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
+ s->state_out_len--;
+ s->strm->next_out++;
+ s->strm->avail_out--;
+ s->strm->total_out_lo32++;
+ if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
+ }
+
+ /* can a new run be started? */
+ if (s->nblock_used == s->save_nblock+1) return False;
+
+ /* Only caused by corrupt data stream? */
+ if (s->nblock_used > s->save_nblock+1)
+ return True;
+
+ s->state_out_len = 1;
+ s->state_out_ch = s->k0;
+ BZ_GET_SMALL(k1); s->nblock_used++;
+ if (s->nblock_used == s->save_nblock+1) continue;
+ if (k1 != s->k0) { s->k0 = k1; continue; };
+
+ s->state_out_len = 2;
+ BZ_GET_SMALL(k1); s->nblock_used++;
+ if (s->nblock_used == s->save_nblock+1) continue;
+ if (k1 != s->k0) { s->k0 = k1; continue; };
+
+ s->state_out_len = 3;
+ BZ_GET_SMALL(k1); s->nblock_used++;
+ if (s->nblock_used == s->save_nblock+1) continue;
+ if (k1 != s->k0) { s->k0 = k1; continue; };
+
+ BZ_GET_SMALL(k1); s->nblock_used++;
+ s->state_out_len = ((Int32)k1) + 4;
+ BZ_GET_SMALL(s->k0); s->nblock_used++;
+ }
+
+ }
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzDecompress) ( bz_stream *strm )
+{
+ Bool corrupt;
+ DState* s;
+ if (strm == NULL) return BZ_PARAM_ERROR;
+ s = strm->state;
+ if (s == NULL) return BZ_PARAM_ERROR;
+ if (s->strm != strm) return BZ_PARAM_ERROR;
+
+ while (True) {
+ if (s->state == BZ_X_IDLE) return BZ_SEQUENCE_ERROR;
+ if (s->state == BZ_X_OUTPUT) {
+ if (s->smallDecompress)
+ corrupt = unRLE_obuf_to_output_SMALL ( s ); else
+ corrupt = unRLE_obuf_to_output_FAST ( s );
+ if (corrupt) return BZ_DATA_ERROR;
+ if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
+ BZ_FINALISE_CRC ( s->calculatedBlockCRC );
+ if (s->verbosity >= 3)
+ VPrintf2 ( " {0x%08x, 0x%08x}", s->storedBlockCRC,
+ s->calculatedBlockCRC );
+ if (s->verbosity >= 2) VPrintf0 ( "]" );
+ if (s->calculatedBlockCRC != s->storedBlockCRC)
+ return BZ_DATA_ERROR;
+ s->calculatedCombinedCRC
+ = (s->calculatedCombinedCRC << 1) |
+ (s->calculatedCombinedCRC >> 31);
+ s->calculatedCombinedCRC ^= s->calculatedBlockCRC;
+ s->state = BZ_X_BLKHDR_1;
+ } else {
+ return BZ_OK;
+ }
+ }
+ if (s->state >= BZ_X_MAGIC_1) {
+ Int32 r = BZ2_decompress ( s );
+ if (r == BZ_STREAM_END) {
+ if (s->verbosity >= 3)
+ VPrintf2 ( "\n combined CRCs: stored = 0x%08x, computed = 0x%08x",
+ s->storedCombinedCRC, s->calculatedCombinedCRC );
+ if (s->calculatedCombinedCRC != s->storedCombinedCRC)
+ return BZ_DATA_ERROR;
+ return r;
+ }
+ if (s->state != BZ_X_OUTPUT) return r;
+ }
+ }
+
+ AssertH ( 0, 6001 );
+
+ return 0; /*NOTREACHED*/
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzDecompressEnd) ( bz_stream *strm )
+{
+ DState* s;
+ if (strm == NULL) return BZ_PARAM_ERROR;
+ s = strm->state;
+ if (s == NULL) return BZ_PARAM_ERROR;
+ if (s->strm != strm) return BZ_PARAM_ERROR;
+
+ if (s->tt != NULL) BZFREE(s->tt);
+ if (s->ll16 != NULL) BZFREE(s->ll16);
+ if (s->ll4 != NULL) BZFREE(s->ll4);
+
+ BZFREE(strm->state);
+ strm->state = NULL;
+
+ return BZ_OK;
+}
+
+
+#ifndef BZ_NO_STDIO
+/*---------------------------------------------------*/
+/*--- File I/O stuff ---*/
+/*---------------------------------------------------*/
+
+#define BZ_SETERR(eee) \
+{ \
+ if (bzerror != NULL) *bzerror = eee; \
+ if (bzf != NULL) bzf->lastErr = eee; \
+}
+
+typedef
+ struct {
+ FILE* handle;
+ Char buf[BZ_MAX_UNUSED];
+ Int32 bufN;
+ Bool writing;
+ bz_stream strm;
+ Int32 lastErr;
+ Bool initialisedOk;
+ }
+ bzFile;
+
+
+/*---------------------------------------------*/
+static Bool myfeof ( FILE* f )
+{
+ Int32 c = fgetc ( f );
+ if (c == EOF) return True;
+ ungetc ( c, f );
+ return False;
+}
+
+
+/*---------------------------------------------------*/
+BZFILE* BZ_API(BZ2_bzWriteOpen)
+ ( int* bzerror,
+ FILE* f,
+ int blockSize100k,
+ int verbosity,
+ int workFactor )
+{
+ Int32 ret;
+ bzFile* bzf = NULL;
+
+ BZ_SETERR(BZ_OK);
+
+ if (f == NULL ||
+ (blockSize100k < 1 || blockSize100k > 9) ||
+ (workFactor < 0 || workFactor > 250) ||
+ (verbosity < 0 || verbosity > 4))
+ { BZ_SETERR(BZ_PARAM_ERROR); return NULL; };
+
+ if (ferror(f))
+ { BZ_SETERR(BZ_IO_ERROR); return NULL; };
+
+ bzf = malloc ( sizeof(bzFile) );
+ if (bzf == NULL)
+ { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
+
+ BZ_SETERR(BZ_OK);
+ bzf->initialisedOk = False;
+ bzf->bufN = 0;
+ bzf->handle = f;
+ bzf->writing = True;
+ bzf->strm.bzalloc = NULL;
+ bzf->strm.bzfree = NULL;
+ bzf->strm.opaque = NULL;
+
+ if (workFactor == 0) workFactor = 30;
+ ret = BZ2_bzCompressInit ( &(bzf->strm), blockSize100k,
+ verbosity, workFactor );
+ if (ret != BZ_OK)
+ { BZ_SETERR(ret); free(bzf); return NULL; };
+
+ bzf->strm.avail_in = 0;
+ bzf->initialisedOk = True;
+ return bzf;
+}
+
+
+
+/*---------------------------------------------------*/
+void BZ_API(BZ2_bzWrite)
+ ( int* bzerror,
+ BZFILE* b,
+ void* buf,
+ int len )
+{
+ Int32 n, n2, ret;
+ bzFile* bzf = (bzFile*)b;
+
+ BZ_SETERR(BZ_OK);
+ if (bzf == NULL || buf == NULL || len < 0)
+ { BZ_SETERR(BZ_PARAM_ERROR); return; };
+ if (!(bzf->writing))
+ { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
+ if (ferror(bzf->handle))
+ { BZ_SETERR(BZ_IO_ERROR); return; };
+
+ if (len == 0)
+ { BZ_SETERR(BZ_OK); return; };
+
+ bzf->strm.avail_in = len;
+ bzf->strm.next_in = buf;
+
+ while (True) {
+ bzf->strm.avail_out = BZ_MAX_UNUSED;
+ bzf->strm.next_out = bzf->buf;
+ ret = BZ2_bzCompress ( &(bzf->strm), BZ_RUN );
+ if (ret != BZ_RUN_OK)
+ { BZ_SETERR(ret); return; };
+
+ if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
+ n = BZ_MAX_UNUSED - bzf->strm.avail_out;
+ n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar),
+ n, bzf->handle );
+ if (n != n2 || ferror(bzf->handle))
+ { BZ_SETERR(BZ_IO_ERROR); return; };
+ }
+
+ if (bzf->strm.avail_in == 0)
+ { BZ_SETERR(BZ_OK); return; };
+ }
+}
+
+
+/*---------------------------------------------------*/
+void BZ_API(BZ2_bzWriteClose)
+ ( int* bzerror,
+ BZFILE* b,
+ int abandon,
+ unsigned int* nbytes_in,
+ unsigned int* nbytes_out )
+{
+ BZ2_bzWriteClose64 ( bzerror, b, abandon,
+ nbytes_in, NULL, nbytes_out, NULL );
+}
+
+
+void BZ_API(BZ2_bzWriteClose64)
+ ( int* bzerror,
+ BZFILE* b,
+ int abandon,
+ unsigned int* nbytes_in_lo32,
+ unsigned int* nbytes_in_hi32,
+ unsigned int* nbytes_out_lo32,
+ unsigned int* nbytes_out_hi32 )
+{
+ Int32 n, n2, ret;
+ bzFile* bzf = (bzFile*)b;
+
+ if (bzf == NULL)
+ { BZ_SETERR(BZ_OK); return; };
+ if (!(bzf->writing))
+ { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
+ if (ferror(bzf->handle))
+ { BZ_SETERR(BZ_IO_ERROR); return; };
+
+ if (nbytes_in_lo32 != NULL) *nbytes_in_lo32 = 0;
+ if (nbytes_in_hi32 != NULL) *nbytes_in_hi32 = 0;
+ if (nbytes_out_lo32 != NULL) *nbytes_out_lo32 = 0;
+ if (nbytes_out_hi32 != NULL) *nbytes_out_hi32 = 0;
+
+ if ((!abandon) && bzf->lastErr == BZ_OK) {
+ while (True) {
+ bzf->strm.avail_out = BZ_MAX_UNUSED;
+ bzf->strm.next_out = bzf->buf;
+ ret = BZ2_bzCompress ( &(bzf->strm), BZ_FINISH );
+ if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
+ { BZ_SETERR(ret); return; };
+
+ if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
+ n = BZ_MAX_UNUSED - bzf->strm.avail_out;
+ n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar),
+ n, bzf->handle );
+ if (n != n2 || ferror(bzf->handle))
+ { BZ_SETERR(BZ_IO_ERROR); return; };
+ }
+
+ if (ret == BZ_STREAM_END) break;
+ }
+ }
+
+ if ( !abandon && !ferror ( bzf->handle ) ) {
+ fflush ( bzf->handle );
+ if (ferror(bzf->handle))
+ { BZ_SETERR(BZ_IO_ERROR); return; };
+ }
+
+ if (nbytes_in_lo32 != NULL)
+ *nbytes_in_lo32 = bzf->strm.total_in_lo32;
+ if (nbytes_in_hi32 != NULL)
+ *nbytes_in_hi32 = bzf->strm.total_in_hi32;
+ if (nbytes_out_lo32 != NULL)
+ *nbytes_out_lo32 = bzf->strm.total_out_lo32;
+ if (nbytes_out_hi32 != NULL)
+ *nbytes_out_hi32 = bzf->strm.total_out_hi32;
+
+ BZ_SETERR(BZ_OK);
+ BZ2_bzCompressEnd ( &(bzf->strm) );
+ free ( bzf );
+}
+
+
+/*---------------------------------------------------*/
+BZFILE* BZ_API(BZ2_bzReadOpen)
+ ( int* bzerror,
+ FILE* f,
+ int verbosity,
+ int small,
+ void* unused,
+ int nUnused )
+{
+ bzFile* bzf = NULL;
+ int ret;
+
+ BZ_SETERR(BZ_OK);
+
+ if (f == NULL ||
+ (small != 0 && small != 1) ||
+ (verbosity < 0 || verbosity > 4) ||
+ (unused == NULL && nUnused != 0) ||
+ (unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED)))
+ { BZ_SETERR(BZ_PARAM_ERROR); return NULL; };
+
+ if (ferror(f))
+ { BZ_SETERR(BZ_IO_ERROR); return NULL; };
+
+ bzf = malloc ( sizeof(bzFile) );
+ if (bzf == NULL)
+ { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
+
+ BZ_SETERR(BZ_OK);
+
+ bzf->initialisedOk = False;
+ bzf->handle = f;
+ bzf->bufN = 0;
+ bzf->writing = False;
+ bzf->strm.bzalloc = NULL;
+ bzf->strm.bzfree = NULL;
+ bzf->strm.opaque = NULL;
+
+ while (nUnused > 0) {
+ bzf->buf[bzf->bufN] = *((UChar*)(unused)); bzf->bufN++;
+ unused = ((void*)( 1 + ((UChar*)(unused)) ));
+ nUnused--;
+ }
+
+ ret = BZ2_bzDecompressInit ( &(bzf->strm), verbosity, small );
+ if (ret != BZ_OK)
+ { BZ_SETERR(ret); free(bzf); return NULL; };
+
+ bzf->strm.avail_in = bzf->bufN;
+ bzf->strm.next_in = bzf->buf;
+
+ bzf->initialisedOk = True;
+ return bzf;
+}
+
+
+/*---------------------------------------------------*/
+void BZ_API(BZ2_bzReadClose) ( int *bzerror, BZFILE *b )
+{
+ bzFile* bzf = (bzFile*)b;
+
+ BZ_SETERR(BZ_OK);
+ if (bzf == NULL)
+ { BZ_SETERR(BZ_OK); return; };
+
+ if (bzf->writing)
+ { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
+
+ if (bzf->initialisedOk)
+ (void)BZ2_bzDecompressEnd ( &(bzf->strm) );
+ free ( bzf );
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzRead)
+ ( int* bzerror,
+ BZFILE* b,
+ void* buf,
+ int len )
+{
+ Int32 n, ret;
+ bzFile* bzf = (bzFile*)b;
+
+ BZ_SETERR(BZ_OK);
+
+ if (bzf == NULL || buf == NULL || len < 0)
+ { BZ_SETERR(BZ_PARAM_ERROR); return 0; };
+
+ if (bzf->writing)
+ { BZ_SETERR(BZ_SEQUENCE_ERROR); return 0; };
+
+ if (len == 0)
+ { BZ_SETERR(BZ_OK); return 0; };
+
+ bzf->strm.avail_out = len;
+ bzf->strm.next_out = buf;
+
+ while (True) {
+
+ if (ferror(bzf->handle))
+ { BZ_SETERR(BZ_IO_ERROR); return 0; };
+
+ if (bzf->strm.avail_in == 0 && !myfeof(bzf->handle)) {
+ n = fread ( bzf->buf, sizeof(UChar),
+ BZ_MAX_UNUSED, bzf->handle );
+ if (ferror(bzf->handle))
+ { BZ_SETERR(BZ_IO_ERROR); return 0; };
+ bzf->bufN = n;
+ bzf->strm.avail_in = bzf->bufN;
+ bzf->strm.next_in = bzf->buf;
+ }
+
+ ret = BZ2_bzDecompress ( &(bzf->strm) );
+
+ if (ret != BZ_OK && ret != BZ_STREAM_END)
+ { BZ_SETERR(ret); return 0; };
+
+ if (ret == BZ_OK && myfeof(bzf->handle) &&
+ bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0)
+ { BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; };
+
+ if (ret == BZ_STREAM_END)
+ { BZ_SETERR(BZ_STREAM_END);
+ return len - bzf->strm.avail_out; };
+ if (bzf->strm.avail_out == 0)
+ { BZ_SETERR(BZ_OK); return len; };
+
+ }
+
+ return 0; /*not reached*/
+}
+
+
+/*---------------------------------------------------*/
+void BZ_API(BZ2_bzReadGetUnused)
+ ( int* bzerror,
+ BZFILE* b,
+ void** unused,
+ int* nUnused )
+{
+ bzFile* bzf = (bzFile*)b;
+ if (bzf == NULL)
+ { BZ_SETERR(BZ_PARAM_ERROR); return; };
+ if (bzf->lastErr != BZ_STREAM_END)
+ { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
+ if (unused == NULL || nUnused == NULL)
+ { BZ_SETERR(BZ_PARAM_ERROR); return; };
+
+ BZ_SETERR(BZ_OK);
+ *nUnused = bzf->strm.avail_in;
+ *unused = bzf->strm.next_in;
+}
+#endif
+
+
+/*---------------------------------------------------*/
+/*--- Misc convenience stuff ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzBuffToBuffCompress)
+ ( char* dest,
+ unsigned int* destLen,
+ char* source,
+ unsigned int sourceLen,
+ int blockSize100k,
+ int verbosity,
+ int workFactor )
+{
+ bz_stream strm;
+ int ret;
+
+ if (dest == NULL || destLen == NULL ||
+ source == NULL ||
+ blockSize100k < 1 || blockSize100k > 9 ||
+ verbosity < 0 || verbosity > 4 ||
+ workFactor < 0 || workFactor > 250)
+ return BZ_PARAM_ERROR;
+
+ if (workFactor == 0) workFactor = 30;
+ strm.bzalloc = NULL;
+ strm.bzfree = NULL;
+ strm.opaque = NULL;
+ ret = BZ2_bzCompressInit ( &strm, blockSize100k,
+ verbosity, workFactor );
+ if (ret != BZ_OK) return ret;
+
+ strm.next_in = source;
+ strm.next_out = dest;
+ strm.avail_in = sourceLen;
+ strm.avail_out = *destLen;
+
+ ret = BZ2_bzCompress ( &strm, BZ_FINISH );
+ if (ret == BZ_FINISH_OK) goto output_overflow;
+ if (ret != BZ_STREAM_END) goto errhandler;
+
+ /* normal termination */
+ *destLen -= strm.avail_out;
+ BZ2_bzCompressEnd ( &strm );
+ return BZ_OK;
+
+ output_overflow:
+ BZ2_bzCompressEnd ( &strm );
+ return BZ_OUTBUFF_FULL;
+
+ errhandler:
+ BZ2_bzCompressEnd ( &strm );
+ return ret;
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzBuffToBuffDecompress)
+ ( char* dest,
+ unsigned int* destLen,
+ char* source,
+ unsigned int sourceLen,
+ int small,
+ int verbosity )
+{
+ bz_stream strm;
+ int ret;
+
+ if (dest == NULL || destLen == NULL ||
+ source == NULL ||
+ (small != 0 && small != 1) ||
+ verbosity < 0 || verbosity > 4)
+ return BZ_PARAM_ERROR;
+
+ strm.bzalloc = NULL;
+ strm.bzfree = NULL;
+ strm.opaque = NULL;
+ ret = BZ2_bzDecompressInit ( &strm, verbosity, small );
+ if (ret != BZ_OK) return ret;
+
+ strm.next_in = source;
+ strm.next_out = dest;
+ strm.avail_in = sourceLen;
+ strm.avail_out = *destLen;
+
+ ret = BZ2_bzDecompress ( &strm );
+ if (ret == BZ_OK) goto output_overflow_or_eof;
+ if (ret != BZ_STREAM_END) goto errhandler;
+
+ /* normal termination */
+ *destLen -= strm.avail_out;
+ BZ2_bzDecompressEnd ( &strm );
+ return BZ_OK;
+
+ output_overflow_or_eof:
+ if (strm.avail_out > 0) {
+ BZ2_bzDecompressEnd ( &strm );
+ return BZ_UNEXPECTED_EOF;
+ } else {
+ BZ2_bzDecompressEnd ( &strm );
+ return BZ_OUTBUFF_FULL;
+ };
+
+ errhandler:
+ BZ2_bzDecompressEnd ( &strm );
+ return ret;
+}
+
+
+/*---------------------------------------------------*/
+/*--
+ Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
+ to support better zlib compatibility.
+ This code is not _officially_ part of libbzip2 (yet);
+ I haven't tested it, documented it, or considered the
+ threading-safeness of it.
+ If this code breaks, please contact both Yoshioka and me.
+--*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------------*/
+/*--
+ return version like "0.9.5d, 4-Sept-1999".
+--*/
+const char * BZ_API(BZ2_bzlibVersion)(void)
+{
+ return BZ_VERSION;
+}
+
+
+#ifndef BZ_NO_STDIO
+/*---------------------------------------------------*/
+
+#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
+# include <fcntl.h>
+# include <io.h>
+# define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)
+#else
+# define SET_BINARY_MODE(file)
+#endif
+static
+BZFILE * bzopen_or_bzdopen
+ ( const char *path, /* no use when bzdopen */
+ int fd, /* no use when bzdopen */
+ const char *mode,
+ int open_mode) /* bzopen: 0, bzdopen:1 */
+{
+ int bzerr;
+ char unused[BZ_MAX_UNUSED];
+ int blockSize100k = 9;
+ int writing = 0;
+ char mode2[10] = "";
+ FILE *fp = NULL;
+ BZFILE *bzfp = NULL;
+ int verbosity = 0;
+ int workFactor = 30;
+ int smallMode = 0;
+ int nUnused = 0;
+
+ if (mode == NULL) return NULL;
+ while (*mode) {
+ switch (*mode) {
+ case 'r':
+ writing = 0; break;
+ case 'w':
+ writing = 1; break;
+ case 's':
+ smallMode = 1; break;
+ default:
+ if (isdigit((int)(*mode))) {
+ blockSize100k = *mode-BZ_HDR_0;
+ }
+ }
+ mode++;
+ }
+ strcat(mode2, writing ? "w" : "r" );
+ strcat(mode2,"b"); /* binary mode */
+
+ if (open_mode==0) {
+ if (path==NULL || strcmp(path,"")==0) {
+ fp = (writing ? stdout : stdin);
+ SET_BINARY_MODE(fp);
+ } else {
+ fp = fopen(path,mode2);
+ }
+ } else {
+#ifdef BZ_STRICT_ANSI
+ fp = NULL;
+#else
+ fp = fdopen(fd,mode2);
+#endif
+ }
+ if (fp == NULL) return NULL;
+
+ if (writing) {
+ /* Guard against total chaos and anarchy -- JRS */
+ if (blockSize100k < 1) blockSize100k = 1;
+ if (blockSize100k > 9) blockSize100k = 9;
+ bzfp = BZ2_bzWriteOpen(&bzerr,fp,blockSize100k,
+ verbosity,workFactor);
+ } else {
+ bzfp = BZ2_bzReadOpen(&bzerr,fp,verbosity,smallMode,
+ unused,nUnused);
+ }
+ if (bzfp == NULL) {
+ if (fp != stdin && fp != stdout) fclose(fp);
+ return NULL;
+ }
+ return bzfp;
+}
+
+
+/*---------------------------------------------------*/
+/*--
+ open file for read or write.
+ ex) bzopen("file","w9")
+ case path="" or NULL => use stdin or stdout.
+--*/
+BZFILE * BZ_API(BZ2_bzopen)
+ ( const char *path,
+ const char *mode )
+{
+ return bzopen_or_bzdopen(path,-1,mode,/*bzopen*/0);
+}
+
+
+/*---------------------------------------------------*/
+BZFILE * BZ_API(BZ2_bzdopen)
+ ( int fd,
+ const char *mode )
+{
+ return bzopen_or_bzdopen(NULL,fd,mode,/*bzdopen*/1);
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzread) (BZFILE* b, void* buf, int len )
+{
+ int bzerr, nread;
+ if (((bzFile*)b)->lastErr == BZ_STREAM_END) return 0;
+ nread = BZ2_bzRead(&bzerr,b,buf,len);
+ if (bzerr == BZ_OK || bzerr == BZ_STREAM_END) {
+ return nread;
+ } else {
+ return -1;
+ }
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzwrite) (BZFILE* b, void* buf, int len )
+{
+ int bzerr;
+
+ BZ2_bzWrite(&bzerr,b,buf,len);
+ if(bzerr == BZ_OK){
+ return len;
+ }else{
+ return -1;
+ }
+}
+
+
+/*---------------------------------------------------*/
+int BZ_API(BZ2_bzflush) (BZFILE *b)
+{
+ (void) b;
+ /* do nothing now... */
+ return 0;
+}
+
+
+/*---------------------------------------------------*/
+void BZ_API(BZ2_bzclose) (BZFILE* b)
+{
+ int bzerr;
+ FILE *fp;
+
+ if (b==NULL) {return;}
+ fp = ((bzFile *)b)->handle;
+ if(((bzFile*)b)->writing){
+ BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL);
+ if(bzerr != BZ_OK){
+ BZ2_bzWriteClose(NULL,b,1,NULL,NULL);
+ }
+ }else{
+ BZ2_bzReadClose(&bzerr,b);
+ }
+ if(fp!=stdin && fp!=stdout){
+ fclose(fp);
+ }
+}
+
+
+/*---------------------------------------------------*/
+/*--
+ return last error code
+--*/
+static const char *bzerrorstrings[] = {
+ "OK"
+ ,"SEQUENCE_ERROR"
+ ,"PARAM_ERROR"
+ ,"MEM_ERROR"
+ ,"DATA_ERROR"
+ ,"DATA_ERROR_MAGIC"
+ ,"IO_ERROR"
+ ,"UNEXPECTED_EOF"
+ ,"OUTBUFF_FULL"
+ ,"CONFIG_ERROR"
+ ,"???" /* for future */
+ ,"???" /* for future */
+ ,"???" /* for future */
+ ,"???" /* for future */
+ ,"???" /* for future */
+ ,"???" /* for future */
+};
+
+
+const char * BZ_API(BZ2_bzerror) (BZFILE *b, int *errnum)
+{
+ int err = ((bzFile *)b)->lastErr;
+
+ if(err>0) err = 0;
+ *errnum = err;
+ return bzerrorstrings[err*-1];
+}
+#endif
+
+
+/*-------------------------------------------------------------*/
+/*--- end bzlib.c ---*/
+/*-------------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/bzlib.h b/Utilities/cmbzip2/bzlib.h
new file mode 100644
index 0000000000..c5b75d6d8f
--- /dev/null
+++ b/Utilities/cmbzip2/bzlib.h
@@ -0,0 +1,282 @@
+
+/*-------------------------------------------------------------*/
+/*--- Public header file for the library. ---*/
+/*--- bzlib.h ---*/
+/*-------------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#ifndef _BZLIB_H
+#define _BZLIB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BZ_RUN 0
+#define BZ_FLUSH 1
+#define BZ_FINISH 2
+
+#define BZ_OK 0
+#define BZ_RUN_OK 1
+#define BZ_FLUSH_OK 2
+#define BZ_FINISH_OK 3
+#define BZ_STREAM_END 4
+#define BZ_SEQUENCE_ERROR (-1)
+#define BZ_PARAM_ERROR (-2)
+#define BZ_MEM_ERROR (-3)
+#define BZ_DATA_ERROR (-4)
+#define BZ_DATA_ERROR_MAGIC (-5)
+#define BZ_IO_ERROR (-6)
+#define BZ_UNEXPECTED_EOF (-7)
+#define BZ_OUTBUFF_FULL (-8)
+#define BZ_CONFIG_ERROR (-9)
+
+typedef
+ struct {
+ char *next_in;
+ unsigned int avail_in;
+ unsigned int total_in_lo32;
+ unsigned int total_in_hi32;
+
+ char *next_out;
+ unsigned int avail_out;
+ unsigned int total_out_lo32;
+ unsigned int total_out_hi32;
+
+ void *state;
+
+ void *(*bzalloc)(void *,int,int);
+ void (*bzfree)(void *,void *);
+ void *opaque;
+ }
+ bz_stream;
+
+
+#ifndef BZ_IMPORT
+#define BZ_EXPORT
+#endif
+
+#ifndef BZ_NO_STDIO
+/* Need a definitition for FILE */
+#include <stdio.h>
+#endif
+
+#ifdef _WIN32
+# include <windows.h>
+# ifdef small
+ /* windows.h define small to char */
+# undef small
+# endif
+# ifdef BZ_EXPORT
+# define BZ_API(func) WINAPI func
+# define BZ_EXTERN extern
+# else
+ /* import windows dll dynamically */
+# define BZ_API(func) (WINAPI * func)
+# define BZ_EXTERN
+# endif
+#else
+# define BZ_API(func) func
+# define BZ_EXTERN extern
+#endif
+
+
+/*-- Core (low-level) library functions --*/
+
+BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
+ bz_stream* strm,
+ int blockSize100k,
+ int verbosity,
+ int workFactor
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzCompress) (
+ bz_stream* strm,
+ int action
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
+ bz_stream* strm
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
+ bz_stream *strm,
+ int verbosity,
+ int small
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
+ bz_stream* strm
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
+ bz_stream *strm
+ );
+
+
+
+/*-- High(er) level library functions --*/
+
+#ifndef BZ_NO_STDIO
+#define BZ_MAX_UNUSED 5000
+
+typedef void BZFILE;
+
+BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
+ int* bzerror,
+ FILE* f,
+ int verbosity,
+ int small,
+ void* unused,
+ int nUnused
+ );
+
+BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
+ int* bzerror,
+ BZFILE* b
+ );
+
+BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
+ int* bzerror,
+ BZFILE* b,
+ void** unused,
+ int* nUnused
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzRead) (
+ int* bzerror,
+ BZFILE* b,
+ void* buf,
+ int len
+ );
+
+BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
+ int* bzerror,
+ FILE* f,
+ int blockSize100k,
+ int verbosity,
+ int workFactor
+ );
+
+BZ_EXTERN void BZ_API(BZ2_bzWrite) (
+ int* bzerror,
+ BZFILE* b,
+ void* buf,
+ int len
+ );
+
+BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
+ int* bzerror,
+ BZFILE* b,
+ int abandon,
+ unsigned int* nbytes_in,
+ unsigned int* nbytes_out
+ );
+
+BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
+ int* bzerror,
+ BZFILE* b,
+ int abandon,
+ unsigned int* nbytes_in_lo32,
+ unsigned int* nbytes_in_hi32,
+ unsigned int* nbytes_out_lo32,
+ unsigned int* nbytes_out_hi32
+ );
+#endif
+
+
+/*-- Utility functions --*/
+
+BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
+ char* dest,
+ unsigned int* destLen,
+ char* source,
+ unsigned int sourceLen,
+ int blockSize100k,
+ int verbosity,
+ int workFactor
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
+ char* dest,
+ unsigned int* destLen,
+ char* source,
+ unsigned int sourceLen,
+ int small,
+ int verbosity
+ );
+
+
+/*--
+ Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
+ to support better zlib compatibility.
+ This code is not _officially_ part of libbzip2 (yet);
+ I haven't tested it, documented it, or considered the
+ threading-safeness of it.
+ If this code breaks, please contact both Yoshioka and me.
+--*/
+
+BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
+ void
+ );
+
+#ifndef BZ_NO_STDIO
+BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
+ const char *path,
+ const char *mode
+ );
+
+BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
+ int fd,
+ const char *mode
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzread) (
+ BZFILE* b,
+ void* buf,
+ int len
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzwrite) (
+ BZFILE* b,
+ void* buf,
+ int len
+ );
+
+BZ_EXTERN int BZ_API(BZ2_bzflush) (
+ BZFILE* b
+ );
+
+BZ_EXTERN void BZ_API(BZ2_bzclose) (
+ BZFILE* b
+ );
+
+BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
+ BZFILE *b,
+ int *errnum
+ );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/*-------------------------------------------------------------*/
+/*--- end bzlib.h ---*/
+/*-------------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/bzlib_private.h b/Utilities/cmbzip2/bzlib_private.h
new file mode 100644
index 0000000000..02a667f499
--- /dev/null
+++ b/Utilities/cmbzip2/bzlib_private.h
@@ -0,0 +1,526 @@
+
+/*-------------------------------------------------------------*/
+/*--- Private header file for the library. ---*/
+/*--- bzlib_private.h ---*/
+/*-------------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#ifndef _BZLIB_PRIVATE_H
+#define _BZLIB_PRIVATE_H
+
+#include <stdlib.h>
+
+#ifndef BZ_NO_STDIO
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#endif
+
+#include "bzlib.h"
+
+
+#if defined(__BORLANDC__)
+# pragma warn -8004 /* Assigned value never used. */
+# pragma warn -8008 /* Condition is always true/false. */
+# pragma warn -8066 /* Unreachable code. */
+# pragma warn -8057 /* Unused parameter. */
+#endif
+#if defined(_MSC_VER)
+/* 'integral size mismatch in argument; conversion supplied */
+# pragma warning(disable:4244)
+/* conversion from 'size_t' to 'off_t', possible loss of data */
+# pragma warning(disable:4267)
+/* warning C4127: conditional expression is constant*/
+# pragma warning(disable:4127)
+#endif
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+
+/*-- General stuff. --*/
+
+#define BZ_VERSION "1.0.5, 10-Dec-2007"
+
+typedef char Char;
+typedef unsigned char Bool;
+typedef unsigned char UChar;
+typedef int Int32;
+typedef unsigned int UInt32;
+typedef short Int16;
+typedef unsigned short UInt16;
+
+#define True ((Bool)1)
+#define False ((Bool)0)
+
+#ifndef __GNUC__
+#define __inline__ /* */
+#endif
+
+#ifndef BZ_NO_STDIO
+
+extern void BZ2_bz__AssertH__fail ( int errcode );
+#define AssertH(cond,errcode) \
+ { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); }
+
+#if BZ_DEBUG
+#define AssertD(cond,msg) \
+ { if (!(cond)) { \
+ fprintf ( stderr, \
+ "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\
+ exit(1); \
+ }}
+#else
+#define AssertD(cond,msg) /* */
+#endif
+
+#define VPrintf0(zf) \
+ fprintf(stderr,zf)
+#define VPrintf1(zf,za1) \
+ fprintf(stderr,zf,za1)
+#define VPrintf2(zf,za1,za2) \
+ fprintf(stderr,zf,za1,za2)
+#define VPrintf3(zf,za1,za2,za3) \
+ fprintf(stderr,zf,za1,za2,za3)
+#define VPrintf4(zf,za1,za2,za3,za4) \
+ fprintf(stderr,zf,za1,za2,za3,za4)
+#define VPrintf5(zf,za1,za2,za3,za4,za5) \
+ fprintf(stderr,zf,za1,za2,za3,za4,za5)
+
+#else
+
+extern void bz_internal_error ( int errcode );
+#define AssertH(cond,errcode) \
+ { if (!(cond)) bz_internal_error ( errcode ); }
+#define AssertD(cond,msg) do { } while (0)
+#define VPrintf0(zf) do { } while (0)
+#define VPrintf1(zf,za1) do { } while (0)
+#define VPrintf2(zf,za1,za2) do { } while (0)
+#define VPrintf3(zf,za1,za2,za3) do { } while (0)
+#define VPrintf4(zf,za1,za2,za3,za4) do { } while (0)
+#define VPrintf5(zf,za1,za2,za3,za4,za5) do { } while (0)
+
+#endif
+
+
+#define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1)
+#define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp))
+
+
+/*-- Header bytes. --*/
+
+#define BZ_HDR_B 0x42 /* 'B' */
+#define BZ_HDR_Z 0x5a /* 'Z' */
+#define BZ_HDR_h 0x68 /* 'h' */
+#define BZ_HDR_0 0x30 /* '0' */
+
+/*-- Constants for the back end. --*/
+
+#define BZ_MAX_ALPHA_SIZE 258
+#define BZ_MAX_CODE_LEN 23
+
+#define BZ_RUNA 0
+#define BZ_RUNB 1
+
+#define BZ_N_GROUPS 6
+#define BZ_G_SIZE 50
+#define BZ_N_ITERS 4
+
+#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
+
+
+
+/*-- Stuff for randomising repetitive blocks. --*/
+
+extern Int32 BZ2_rNums[512];
+
+#define BZ_RAND_DECLS \
+ Int32 rNToGo; \
+ Int32 rTPos \
+
+#define BZ_RAND_INIT_MASK \
+ s->rNToGo = 0; \
+ s->rTPos = 0 \
+
+#define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0)
+
+#define BZ_RAND_UPD_MASK \
+ if (s->rNToGo == 0) { \
+ s->rNToGo = BZ2_rNums[s->rTPos]; \
+ s->rTPos++; \
+ if (s->rTPos == 512) s->rTPos = 0; \
+ } \
+ s->rNToGo--;
+
+
+
+/*-- Stuff for doing CRCs. --*/
+
+extern UInt32 BZ2_crc32Table[256];
+
+#define BZ_INITIALISE_CRC(crcVar) \
+{ \
+ crcVar = 0xffffffffL; \
+}
+
+#define BZ_FINALISE_CRC(crcVar) \
+{ \
+ crcVar = ~(crcVar); \
+}
+
+#define BZ_UPDATE_CRC(crcVar,cha) \
+{ \
+ crcVar = (crcVar << 8) ^ \
+ BZ2_crc32Table[(crcVar >> 24) ^ \
+ ((UChar)cha)]; \
+}
+
+
+
+/*-- States and modes for compression. --*/
+
+#define BZ_M_IDLE 1
+#define BZ_M_RUNNING 2
+#define BZ_M_FLUSHING 3
+#define BZ_M_FINISHING 4
+
+#define BZ_S_OUTPUT 1
+#define BZ_S_INPUT 2
+
+#define BZ_N_RADIX 2
+#define BZ_N_QSORT 12
+#define BZ_N_SHELL 18
+#define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
+
+
+
+
+/*-- Structure holding all the compression-side stuff. --*/
+
+typedef
+ struct {
+ /* pointer back to the struct bz_stream */
+ bz_stream* strm;
+
+ /* mode this stream is in, and whether inputting */
+ /* or outputting data */
+ Int32 mode;
+ Int32 state;
+
+ /* remembers avail_in when flush/finish requested */
+ UInt32 avail_in_expect;
+
+ /* for doing the block sorting */
+ UInt32* arr1;
+ UInt32* arr2;
+ UInt32* ftab;
+ Int32 origPtr;
+
+ /* aliases for arr1 and arr2 */
+ UInt32* ptr;
+ UChar* block;
+ UInt16* mtfv;
+ UChar* zbits;
+
+ /* for deciding when to use the fallback sorting algorithm */
+ Int32 workFactor;
+
+ /* run-length-encoding of the input */
+ UInt32 state_in_ch;
+ Int32 state_in_len;
+ BZ_RAND_DECLS;
+
+ /* input and output limits and current posns */
+ Int32 nblock;
+ Int32 nblockMAX;
+ Int32 numZ;
+ Int32 state_out_pos;
+
+ /* map of bytes used in block */
+ Int32 nInUse;
+ Bool inUse[256];
+ UChar unseqToSeq[256];
+
+ /* the buffer for bit stream creation */
+ UInt32 bsBuff;
+ Int32 bsLive;
+
+ /* block and combined CRCs */
+ UInt32 blockCRC;
+ UInt32 combinedCRC;
+
+ /* misc administratium */
+ Int32 verbosity;
+ Int32 blockNo;
+ Int32 blockSize100k;
+
+ /* stuff for coding the MTF values */
+ Int32 nMTF;
+ Int32 mtfFreq [BZ_MAX_ALPHA_SIZE];
+ UChar selector [BZ_MAX_SELECTORS];
+ UChar selectorMtf[BZ_MAX_SELECTORS];
+
+ UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+ Int32 code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+ Int32 rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+ /* second dimension: only 3 needed; 4 makes index calculations faster */
+ UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4];
+
+ }
+ EState;
+
+
+
+/*-- externs for compression. --*/
+
+extern void
+BZ2_blockSort ( EState* );
+
+extern void
+BZ2_compressBlock ( EState*, Bool );
+
+extern void
+BZ2_bsInitWrite ( EState* );
+
+extern void
+BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
+
+extern void
+BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
+
+
+
+/*-- states for decompression. --*/
+
+#define BZ_X_IDLE 1
+#define BZ_X_OUTPUT 2
+
+#define BZ_X_MAGIC_1 10
+#define BZ_X_MAGIC_2 11
+#define BZ_X_MAGIC_3 12
+#define BZ_X_MAGIC_4 13
+#define BZ_X_BLKHDR_1 14
+#define BZ_X_BLKHDR_2 15
+#define BZ_X_BLKHDR_3 16
+#define BZ_X_BLKHDR_4 17
+#define BZ_X_BLKHDR_5 18
+#define BZ_X_BLKHDR_6 19
+#define BZ_X_BCRC_1 20
+#define BZ_X_BCRC_2 21
+#define BZ_X_BCRC_3 22
+#define BZ_X_BCRC_4 23
+#define BZ_X_RANDBIT 24
+#define BZ_X_ORIGPTR_1 25
+#define BZ_X_ORIGPTR_2 26
+#define BZ_X_ORIGPTR_3 27
+#define BZ_X_MAPPING_1 28
+#define BZ_X_MAPPING_2 29
+#define BZ_X_SELECTOR_1 30
+#define BZ_X_SELECTOR_2 31
+#define BZ_X_SELECTOR_3 32
+#define BZ_X_CODING_1 33
+#define BZ_X_CODING_2 34
+#define BZ_X_CODING_3 35
+#define BZ_X_MTF_1 36
+#define BZ_X_MTF_2 37
+#define BZ_X_MTF_3 38
+#define BZ_X_MTF_4 39
+#define BZ_X_MTF_5 40
+#define BZ_X_MTF_6 41
+#define BZ_X_ENDHDR_2 42
+#define BZ_X_ENDHDR_3 43
+#define BZ_X_ENDHDR_4 44
+#define BZ_X_ENDHDR_5 45
+#define BZ_X_ENDHDR_6 46
+#define BZ_X_CCRC_1 47
+#define BZ_X_CCRC_2 48
+#define BZ_X_CCRC_3 49
+#define BZ_X_CCRC_4 50
+
+
+
+/*-- Constants for the fast MTF decoder. --*/
+
+#define MTFA_SIZE 4096
+#define MTFL_SIZE 16
+
+
+
+/*-- Structure holding all the decompression-side stuff. --*/
+
+typedef
+ struct {
+ /* pointer back to the struct bz_stream */
+ bz_stream* strm;
+
+ /* state indicator for this stream */
+ Int32 state;
+
+ /* for doing the final run-length decoding */
+ UChar state_out_ch;
+ Int32 state_out_len;
+ Bool blockRandomised;
+ BZ_RAND_DECLS;
+
+ /* the buffer for bit stream reading */
+ UInt32 bsBuff;
+ Int32 bsLive;
+
+ /* misc administratium */
+ Int32 blockSize100k;
+ Bool smallDecompress;
+ Int32 currBlockNo;
+ Int32 verbosity;
+
+ /* for undoing the Burrows-Wheeler transform */
+ Int32 origPtr;
+ UInt32 tPos;
+ Int32 k0;
+ Int32 unzftab[256];
+ Int32 nblock_used;
+ Int32 cftab[257];
+ Int32 cftabCopy[257];
+
+ /* for undoing the Burrows-Wheeler transform (FAST) */
+ UInt32 *tt;
+
+ /* for undoing the Burrows-Wheeler transform (SMALL) */
+ UInt16 *ll16;
+ UChar *ll4;
+
+ /* stored and calculated CRCs */
+ UInt32 storedBlockCRC;
+ UInt32 storedCombinedCRC;
+ UInt32 calculatedBlockCRC;
+ UInt32 calculatedCombinedCRC;
+
+ /* map of bytes used in block */
+ Int32 nInUse;
+ Bool inUse[256];
+ Bool inUse16[16];
+ UChar seqToUnseq[256];
+
+ /* for decoding the MTF values */
+ UChar mtfa [MTFA_SIZE];
+ Int32 mtfbase[256 / MTFL_SIZE];
+ UChar selector [BZ_MAX_SELECTORS];
+ UChar selectorMtf[BZ_MAX_SELECTORS];
+ UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+
+ Int32 limit [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+ Int32 base [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+ Int32 perm [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+ Int32 minLens[BZ_N_GROUPS];
+
+ /* save area for scalars in the main decompress code */
+ Int32 save_i;
+ Int32 save_j;
+ Int32 save_t;
+ Int32 save_alphaSize;
+ Int32 save_nGroups;
+ Int32 save_nSelectors;
+ Int32 save_EOB;
+ Int32 save_groupNo;
+ Int32 save_groupPos;
+ Int32 save_nextSym;
+ Int32 save_nblockMAX;
+ Int32 save_nblock;
+ Int32 save_es;
+ Int32 save_N;
+ Int32 save_curr;
+ Int32 save_zt;
+ Int32 save_zn;
+ Int32 save_zvec;
+ Int32 save_zj;
+ Int32 save_gSel;
+ Int32 save_gMinlen;
+ Int32* save_gLimit;
+ Int32* save_gBase;
+ Int32* save_gPerm;
+
+ }
+ DState;
+
+
+
+/*-- Macros for decompression. --*/
+
+#define BZ_GET_FAST(cccc) \
+ /* c_tPos is unsigned, hence test < 0 is pointless. */ \
+ if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
+ s->tPos = s->tt[s->tPos]; \
+ cccc = (UChar)(s->tPos & 0xff); \
+ s->tPos >>= 8;
+
+#define BZ_GET_FAST_C(cccc) \
+ /* c_tPos is unsigned, hence test < 0 is pointless. */ \
+ if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \
+ c_tPos = c_tt[c_tPos]; \
+ cccc = (UChar)(c_tPos & 0xff); \
+ c_tPos >>= 8;
+
+#define SET_LL4(i,n) \
+ { if (((i) & 0x1) == 0) \
+ s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \
+ s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \
+ }
+
+#define GET_LL4(i) \
+ ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF)
+
+#define SET_LL(i,n) \
+ { s->ll16[i] = (UInt16)(n & 0x0000ffff); \
+ SET_LL4(i, n >> 16); \
+ }
+
+#define GET_LL(i) \
+ (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
+
+#define BZ_GET_SMALL(cccc) \
+ /* c_tPos is unsigned, hence test < 0 is pointless. */ \
+ if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
+ cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \
+ s->tPos = GET_LL(s->tPos);
+
+
+/*-- externs for decompression. --*/
+
+extern Int32
+BZ2_indexIntoF ( Int32, Int32* );
+
+extern Int32
+BZ2_decompress ( DState* );
+
+extern void
+BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
+ Int32, Int32, Int32 );
+
+
+#endif
+
+
+/*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/
+
+#ifdef BZ_NO_STDIO
+#ifndef NULL
+#define NULL 0
+#endif
+#endif
+
+
+/*-------------------------------------------------------------*/
+/*--- end bzlib_private.h ---*/
+/*-------------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/bzmore b/Utilities/cmbzip2/bzmore
new file mode 100644
index 0000000000..21b1de61c5
--- /dev/null
+++ b/Utilities/cmbzip2/bzmore
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+# Bzmore wrapped for bzip2,
+# adapted from zmore by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
+
+PATH="/usr/bin:$PATH"; export PATH
+
+prog=`echo $0 | sed 's|.*/||'`
+case "$prog" in
+ *less) more=less ;;
+ *) more=more ;;
+esac
+
+if test "`echo -n a`" = "-n a"; then
+ # looks like a SysV system:
+ n1=''; n2='\c'
+else
+ n1='-n'; n2=''
+fi
+oldtty=`stty -g 2>/dev/null`
+if stty -cbreak 2>/dev/null; then
+ cb='cbreak'; ncb='-cbreak'
+else
+ # 'stty min 1' resets eof to ^a on both SunOS and SysV!
+ cb='min 1 -icanon'; ncb='icanon eof ^d'
+fi
+if test $? -eq 0 -a -n "$oldtty"; then
+ trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
+else
+ trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
+fi
+
+if test $# = 0; then
+ if test -t 0; then
+ echo usage: $prog files...
+ else
+ bzip2 -cdfq | eval $more
+ fi
+else
+ FIRST=1
+ for FILE
+ do
+ if test $FIRST -eq 0; then
+ echo $n1 "--More--(Next file: $FILE)$n2"
+ stty $cb -echo 2>/dev/null
+ ANS=`dd bs=1 count=1 2>/dev/null`
+ stty $ncb echo 2>/dev/null
+ echo " "
+ if test "$ANS" = 'e' -o "$ANS" = 'q'; then
+ exit
+ fi
+ fi
+ if test "$ANS" != 's'; then
+ echo "------> $FILE <------"
+ bzip2 -cdfq "$FILE" | eval $more
+ fi
+ if test -t; then
+ FIRST=0
+ fi
+ done
+fi
diff --git a/Utilities/cmbzip2/bzmore.1 b/Utilities/cmbzip2/bzmore.1
new file mode 100644
index 0000000000..c6868ed5cf
--- /dev/null
+++ b/Utilities/cmbzip2/bzmore.1
@@ -0,0 +1,152 @@
+.\"Shamelessly copied from zmore.1 by Philippe Troin <phil@fifi.org>
+.\"for Debian GNU/Linux
+.TH BZMORE 1
+.SH NAME
+bzmore, bzless \- file perusal filter for crt viewing of bzip2 compressed text
+.SH SYNOPSIS
+.B bzmore
+[ name ... ]
+.br
+.B bzless
+[ name ... ]
+.SH NOTE
+In the following description,
+.I bzless
+and
+.I less
+can be used interchangeably with
+.I bzmore
+and
+.I more.
+.SH DESCRIPTION
+.I Bzmore
+is a filter which allows examination of compressed or plain text files
+one screenful at a time on a soft-copy terminal.
+.I bzmore
+works on files compressed with
+.I bzip2
+and also on uncompressed files.
+If a file does not exist,
+.I bzmore
+looks for a file of the same name with the addition of a .bz2 suffix.
+.PP
+.I Bzmore
+normally pauses after each screenful, printing --More--
+at the bottom of the screen.
+If the user then types a carriage return, one more line is displayed.
+If the user hits a space,
+another screenful is displayed. Other possibilities are enumerated later.
+.PP
+.I Bzmore
+looks in the file
+.I /etc/termcap
+to determine terminal characteristics,
+and to determine the default window size.
+On a terminal capable of displaying 24 lines,
+the default window size is 22 lines.
+Other sequences which may be typed when
+.I bzmore
+pauses, and their effects, are as follows (\fIi\fP is an optional integer
+argument, defaulting to 1) :
+.PP
+.IP \fIi\|\fP<space>
+display
+.I i
+more lines, (or another screenful if no argument is given)
+.PP
+.IP ^D
+display 11 more lines (a ``scroll'').
+If
+.I i
+is given, then the scroll size is set to \fIi\|\fP.
+.PP
+.IP d
+same as ^D (control-D)
+.PP
+.IP \fIi\|\fPz
+same as typing a space except that \fIi\|\fP, if present, becomes the new
+window size. Note that the window size reverts back to the default at the
+end of the current file.
+.PP
+.IP \fIi\|\fPs
+skip \fIi\|\fP lines and print a screenful of lines
+.PP
+.IP \fIi\|\fPf
+skip \fIi\fP screenfuls and print a screenful of lines
+.PP
+.IP "q or Q"
+quit reading the current file; go on to the next (if any)
+.PP
+.IP "e or q"
+When the prompt --More--(Next file:
+.IR file )
+is printed, this command causes bzmore to exit.
+.PP
+.IP s
+When the prompt --More--(Next file:
+.IR file )
+is printed, this command causes bzmore to skip the next file and continue.
+.PP
+.IP =
+Display the current line number.
+.PP
+.IP \fIi\|\fP/expr
+search for the \fIi\|\fP-th occurrence of the regular expression \fIexpr.\fP
+If the pattern is not found,
+.I bzmore
+goes on to the next file (if any).
+Otherwise, a screenful is displayed, starting two lines before the place
+where the expression was found.
+The user's erase and kill characters may be used to edit the regular
+expression.
+Erasing back past the first column cancels the search command.
+.PP
+.IP \fIi\|\fPn
+search for the \fIi\|\fP-th occurrence of the last regular expression entered.
+.PP
+.IP !command
+invoke a shell with \fIcommand\|\fP.
+The character `!' in "command" are replaced with the
+previous shell command. The sequence "\\!" is replaced by "!".
+.PP
+.IP ":q or :Q"
+quit reading the current file; go on to the next (if any)
+(same as q or Q).
+.PP
+.IP .
+(dot) repeat the previous command.
+.PP
+The commands take effect immediately, i.e., it is not necessary to
+type a carriage return.
+Up to the time when the command character itself is given,
+the user may hit the line kill character to cancel the numerical
+argument being formed.
+In addition, the user may hit the erase character to redisplay the
+--More-- message.
+.PP
+At any time when output is being sent to the terminal, the user can
+hit the quit key (normally control\-\\).
+.I Bzmore
+will stop sending output, and will display the usual --More--
+prompt.
+The user may then enter one of the above commands in the normal manner.
+Unfortunately, some output is lost when this is done, due to the
+fact that any characters waiting in the terminal's output queue
+are flushed when the quit signal occurs.
+.PP
+The terminal is set to
+.I noecho
+mode by this program so that the output can be continuous.
+What you type will thus not show on your terminal, except for the / and !
+commands.
+.PP
+If the standard output is not a teletype, then
+.I bzmore
+acts just like
+.I bzcat,
+except that a header is printed before each file.
+.SH FILES
+.DT
+/etc/termcap Terminal data base
+.SH "SEE ALSO"
+more(1), less(1), bzip2(1), bzdiff(1), bzgrep(1)
diff --git a/Utilities/cmbzip2/compress.c b/Utilities/cmbzip2/compress.c
new file mode 100644
index 0000000000..feea233c28
--- /dev/null
+++ b/Utilities/cmbzip2/compress.c
@@ -0,0 +1,672 @@
+
+/*-------------------------------------------------------------*/
+/*--- Compression machinery (not incl block sorting) ---*/
+/*--- compress.c ---*/
+/*-------------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+/* CHANGES
+ 0.9.0 -- original version.
+ 0.9.0a/b -- no changes in this file.
+ 0.9.0c -- changed setting of nGroups in sendMTFValues()
+ so as to do a bit better on small files
+*/
+
+#include "bzlib_private.h"
+
+
+/*---------------------------------------------------*/
+/*--- Bit stream I/O ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------------*/
+void BZ2_bsInitWrite ( EState* s )
+{
+ s->bsLive = 0;
+ s->bsBuff = 0;
+}
+
+
+/*---------------------------------------------------*/
+static
+void bsFinishWrite ( EState* s )
+{
+ while (s->bsLive > 0) {
+ s->zbits[s->numZ] = (UChar)(s->bsBuff >> 24);
+ s->numZ++;
+ s->bsBuff <<= 8;
+ s->bsLive -= 8;
+ }
+}
+
+
+/*---------------------------------------------------*/
+#define bsNEEDW(nz) \
+{ \
+ while (s->bsLive >= 8) { \
+ s->zbits[s->numZ] \
+ = (UChar)(s->bsBuff >> 24); \
+ s->numZ++; \
+ s->bsBuff <<= 8; \
+ s->bsLive -= 8; \
+ } \
+}
+
+
+/*---------------------------------------------------*/
+static
+__inline__
+void bsW ( EState* s, Int32 n, UInt32 v )
+{
+ bsNEEDW ( n );
+ s->bsBuff |= (v << (32 - s->bsLive - n));
+ s->bsLive += n;
+}
+
+
+/*---------------------------------------------------*/
+static
+void bsPutUInt32 ( EState* s, UInt32 u )
+{
+ bsW ( s, 8, (u >> 24) & 0xffL );
+ bsW ( s, 8, (u >> 16) & 0xffL );
+ bsW ( s, 8, (u >> 8) & 0xffL );
+ bsW ( s, 8, u & 0xffL );
+}
+
+
+/*---------------------------------------------------*/
+static
+void bsPutUChar ( EState* s, UChar c )
+{
+ bsW( s, 8, (UInt32)c );
+}
+
+
+/*---------------------------------------------------*/
+/*--- The back end proper ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------------*/
+static
+void makeMaps_e ( EState* s )
+{
+ Int32 i;
+ s->nInUse = 0;
+ for (i = 0; i < 256; i++)
+ if (s->inUse[i]) {
+ s->unseqToSeq[i] = s->nInUse;
+ s->nInUse++;
+ }
+}
+
+
+/*---------------------------------------------------*/
+static
+void generateMTFValues ( EState* s )
+{
+ UChar yy[256];
+ Int32 i, j;
+ Int32 zPend;
+ Int32 wr;
+ Int32 EOB;
+
+ /*
+ After sorting (eg, here),
+ s->arr1 [ 0 .. s->nblock-1 ] holds sorted order,
+ and
+ ((UChar*)s->arr2) [ 0 .. s->nblock-1 ]
+ holds the original block data.
+
+ The first thing to do is generate the MTF values,
+ and put them in
+ ((UInt16*)s->arr1) [ 0 .. s->nblock-1 ].
+ Because there are strictly fewer or equal MTF values
+ than block values, ptr values in this area are overwritten
+ with MTF values only when they are no longer needed.
+
+ The final compressed bitstream is generated into the
+ area starting at
+ (UChar*) (&((UChar*)s->arr2)[s->nblock])
+
+ These storage aliases are set up in bzCompressInit(),
+ except for the last one, which is arranged in
+ compressBlock().
+ */
+ UInt32* ptr = s->ptr;
+ UChar* block = s->block;
+ UInt16* mtfv = s->mtfv;
+
+ makeMaps_e ( s );
+ EOB = s->nInUse+1;
+
+ for (i = 0; i <= EOB; i++) s->mtfFreq[i] = 0;
+
+ wr = 0;
+ zPend = 0;
+ for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i;
+
+ for (i = 0; i < s->nblock; i++) {
+ UChar ll_i;
+ AssertD ( wr <= i, "generateMTFValues(1)" );
+ j = ptr[i]-1; if (j < 0) j += s->nblock;
+ ll_i = s->unseqToSeq[block[j]];
+ AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" );
+
+ if (yy[0] == ll_i) {
+ zPend++;
+ } else {
+
+ if (zPend > 0) {
+ zPend--;
+ while (True) {
+ if (zPend & 1) {
+ mtfv[wr] = BZ_RUNB; wr++;
+ s->mtfFreq[BZ_RUNB]++;
+ } else {
+ mtfv[wr] = BZ_RUNA; wr++;
+ s->mtfFreq[BZ_RUNA]++;
+ }
+ if (zPend < 2) break;
+ zPend = (zPend - 2) / 2;
+ };
+ zPend = 0;
+ }
+ {
+ register UChar rtmp;
+ register UChar* ryy_j;
+ register UChar rll_i;
+ rtmp = yy[1];
+ yy[1] = yy[0];
+ ryy_j = &(yy[1]);
+ rll_i = ll_i;
+ while ( rll_i != rtmp ) {
+ register UChar rtmp2;
+ ryy_j++;
+ rtmp2 = rtmp;
+ rtmp = *ryy_j;
+ *ryy_j = rtmp2;
+ };
+ yy[0] = rtmp;
+ j = ryy_j - &(yy[0]);
+ mtfv[wr] = j+1; wr++; s->mtfFreq[j+1]++;
+ }
+
+ }
+ }
+
+ if (zPend > 0) {
+ zPend--;
+ while (True) {
+ if (zPend & 1) {
+ mtfv[wr] = BZ_RUNB; wr++;
+ s->mtfFreq[BZ_RUNB]++;
+ } else {
+ mtfv[wr] = BZ_RUNA; wr++;
+ s->mtfFreq[BZ_RUNA]++;
+ }
+ if (zPend < 2) break;
+ zPend = (zPend - 2) / 2;
+ };
+ zPend = 0;
+ }
+
+ mtfv[wr] = EOB; wr++; s->mtfFreq[EOB]++;
+
+ s->nMTF = wr;
+}
+
+
+/*---------------------------------------------------*/
+#define BZ_LESSER_ICOST 0
+#define BZ_GREATER_ICOST 15
+
+static
+void sendMTFValues ( EState* s )
+{
+ Int32 v, t, i, j, gs, ge, totc, bt, bc, iter;
+ Int32 nSelectors = 0, alphaSize, minLen, maxLen, selCtr;
+ Int32 nGroups, nBytes;
+
+ /*--
+ UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+ is a global since the decoder also needs it.
+
+ Int32 code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+ Int32 rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
+ are also globals only used in this proc.
+ Made global to keep stack frame size small.
+ --*/
+
+
+ UInt16 cost[BZ_N_GROUPS];
+ Int32 fave[BZ_N_GROUPS];
+
+ UInt16* mtfv = s->mtfv;
+
+ if (s->verbosity >= 3)
+ VPrintf3( " %d in block, %d after MTF & 1-2 coding, "
+ "%d+2 syms in use\n",
+ s->nblock, s->nMTF, s->nInUse );
+
+ alphaSize = s->nInUse+2;
+ for (t = 0; t < BZ_N_GROUPS; t++)
+ for (v = 0; v < alphaSize; v++)
+ s->len[t][v] = BZ_GREATER_ICOST;
+
+ /*--- Decide how many coding tables to use ---*/
+ AssertH ( s->nMTF > 0, 3001 );
+ if (s->nMTF < 200) nGroups = 2; else
+ if (s->nMTF < 600) nGroups = 3; else
+ if (s->nMTF < 1200) nGroups = 4; else
+ if (s->nMTF < 2400) nGroups = 5; else
+ nGroups = 6;
+
+ /*--- Generate an initial set of coding tables ---*/
+ {
+ Int32 nPart, remF, tFreq, aFreq;
+
+ nPart = nGroups;
+ remF = s->nMTF;
+ gs = 0;
+ while (nPart > 0) {
+ tFreq = remF / nPart;
+ ge = gs-1;
+ aFreq = 0;
+ while (aFreq < tFreq && ge < alphaSize-1) {
+ ge++;
+ aFreq += s->mtfFreq[ge];
+ }
+
+ if (ge > gs
+ && nPart != nGroups && nPart != 1
+ && ((nGroups-nPart) % 2 == 1)) {
+ aFreq -= s->mtfFreq[ge];
+ ge--;
+ }
+
+ if (s->verbosity >= 3)
+ VPrintf5( " initial group %d, [%d .. %d], "
+ "has %d syms (%4.1f%%)\n",
+ nPart, gs, ge, aFreq,
+ (100.0 * (float)aFreq) / (float)(s->nMTF) );
+
+ for (v = 0; v < alphaSize; v++)
+ if (v >= gs && v <= ge)
+ s->len[nPart-1][v] = BZ_LESSER_ICOST; else
+ s->len[nPart-1][v] = BZ_GREATER_ICOST;
+
+ nPart--;
+ gs = ge+1;
+ remF -= aFreq;
+ }
+ }
+
+ /*---
+ Iterate up to BZ_N_ITERS times to improve the tables.
+ ---*/
+ for (iter = 0; iter < BZ_N_ITERS; iter++) {
+
+ for (t = 0; t < nGroups; t++) fave[t] = 0;
+
+ for (t = 0; t < nGroups; t++)
+ for (v = 0; v < alphaSize; v++)
+ s->rfreq[t][v] = 0;
+
+ /*---
+ Set up an auxiliary length table which is used to fast-track
+ the common case (nGroups == 6).
+ ---*/
+ if (nGroups == 6) {
+ for (v = 0; v < alphaSize; v++) {
+ s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
+ s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
+ s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v];
+ }
+ }
+
+ nSelectors = 0;
+ totc = 0;
+ gs = 0;
+ while (True) {
+
+ /*--- Set group start & end marks. --*/
+ if (gs >= s->nMTF) break;
+ ge = gs + BZ_G_SIZE - 1;
+ if (ge >= s->nMTF) ge = s->nMTF-1;
+
+ /*--
+ Calculate the cost of this group as coded
+ by each of the coding tables.
+ --*/
+ for (t = 0; t < nGroups; t++) cost[t] = 0;
+
+ if (nGroups == 6 && 50 == ge-gs+1) {
+ /*--- fast track the common case ---*/
+ register UInt32 cost01, cost23, cost45;
+ register UInt16 icv;
+ cost01 = cost23 = cost45 = 0;
+
+# define BZ_ITER(nn) \
+ icv = mtfv[gs+(nn)]; \
+ cost01 += s->len_pack[icv][0]; \
+ cost23 += s->len_pack[icv][1]; \
+ cost45 += s->len_pack[icv][2]; \
+
+ BZ_ITER(0); BZ_ITER(1); BZ_ITER(2); BZ_ITER(3); BZ_ITER(4);
+ BZ_ITER(5); BZ_ITER(6); BZ_ITER(7); BZ_ITER(8); BZ_ITER(9);
+ BZ_ITER(10); BZ_ITER(11); BZ_ITER(12); BZ_ITER(13); BZ_ITER(14);
+ BZ_ITER(15); BZ_ITER(16); BZ_ITER(17); BZ_ITER(18); BZ_ITER(19);
+ BZ_ITER(20); BZ_ITER(21); BZ_ITER(22); BZ_ITER(23); BZ_ITER(24);
+ BZ_ITER(25); BZ_ITER(26); BZ_ITER(27); BZ_ITER(28); BZ_ITER(29);
+ BZ_ITER(30); BZ_ITER(31); BZ_ITER(32); BZ_ITER(33); BZ_ITER(34);
+ BZ_ITER(35); BZ_ITER(36); BZ_ITER(37); BZ_ITER(38); BZ_ITER(39);
+ BZ_ITER(40); BZ_ITER(41); BZ_ITER(42); BZ_ITER(43); BZ_ITER(44);
+ BZ_ITER(45); BZ_ITER(46); BZ_ITER(47); BZ_ITER(48); BZ_ITER(49);
+
+# undef BZ_ITER
+
+ cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
+ cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
+ cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
+
+ } else {
+ /*--- slow version which correctly handles all situations ---*/
+ for (i = gs; i <= ge; i++) {
+ UInt16 icv = mtfv[i];
+ for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv];
+ }
+ }
+
+ /*--
+ Find the coding table which is best for this group,
+ and record its identity in the selector table.
+ --*/
+ bc = 999999999; bt = -1;
+ for (t = 0; t < nGroups; t++)
+ if (cost[t] < bc) { bc = cost[t]; bt = t; };
+ totc += bc;
+ fave[bt]++;
+ s->selector[nSelectors] = bt;
+ nSelectors++;
+
+ /*--
+ Increment the symbol frequencies for the selected table.
+ --*/
+ if (nGroups == 6 && 50 == ge-gs+1) {
+ /*--- fast track the common case ---*/
+
+# define BZ_ITUR(nn) s->rfreq[bt][ mtfv[gs+(nn)] ]++
+
+ BZ_ITUR(0); BZ_ITUR(1); BZ_ITUR(2); BZ_ITUR(3); BZ_ITUR(4);
+ BZ_ITUR(5); BZ_ITUR(6); BZ_ITUR(7); BZ_ITUR(8); BZ_ITUR(9);
+ BZ_ITUR(10); BZ_ITUR(11); BZ_ITUR(12); BZ_ITUR(13); BZ_ITUR(14);
+ BZ_ITUR(15); BZ_ITUR(16); BZ_ITUR(17); BZ_ITUR(18); BZ_ITUR(19);
+ BZ_ITUR(20); BZ_ITUR(21); BZ_ITUR(22); BZ_ITUR(23); BZ_ITUR(24);
+ BZ_ITUR(25); BZ_ITUR(26); BZ_ITUR(27); BZ_ITUR(28); BZ_ITUR(29);
+ BZ_ITUR(30); BZ_ITUR(31); BZ_ITUR(32); BZ_ITUR(33); BZ_ITUR(34);
+ BZ_ITUR(35); BZ_ITUR(36); BZ_ITUR(37); BZ_ITUR(38); BZ_ITUR(39);
+ BZ_ITUR(40); BZ_ITUR(41); BZ_ITUR(42); BZ_ITUR(43); BZ_ITUR(44);
+ BZ_ITUR(45); BZ_ITUR(46); BZ_ITUR(47); BZ_ITUR(48); BZ_ITUR(49);
+
+# undef BZ_ITUR
+
+ } else {
+ /*--- slow version which correctly handles all situations ---*/
+ for (i = gs; i <= ge; i++)
+ s->rfreq[bt][ mtfv[i] ]++;
+ }
+
+ gs = ge+1;
+ }
+ if (s->verbosity >= 3) {
+ VPrintf2 ( " pass %d: size is %d, grp uses are ",
+ iter+1, totc/8 );
+ for (t = 0; t < nGroups; t++)
+ VPrintf1 ( "%d ", fave[t] );
+ VPrintf0 ( "\n" );
+ }
+
+ /*--
+ Recompute the tables based on the accumulated frequencies.
+ --*/
+ /* maxLen was changed from 20 to 17 in bzip2-1.0.3. See
+ comment in huffman.c for details. */
+ for (t = 0; t < nGroups; t++)
+ BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
+ alphaSize, 17 /*20*/ );
+ }
+
+
+ AssertH( nGroups < 8, 3002 );
+ AssertH( nSelectors < 32768 &&
+ nSelectors <= (2 + (900000 / BZ_G_SIZE)),
+ 3003 );
+
+
+ /*--- Compute MTF values for the selectors. ---*/
+ {
+ UChar pos[BZ_N_GROUPS], ll_i, tmp2, tmp;
+ for (i = 0; i < nGroups; i++) pos[i] = i;
+ for (i = 0; i < nSelectors; i++) {
+ ll_i = s->selector[i];
+ j = 0;
+ tmp = pos[j];
+ while ( ll_i != tmp ) {
+ j++;
+ tmp2 = tmp;
+ tmp = pos[j];
+ pos[j] = tmp2;
+ };
+ pos[0] = tmp;
+ s->selectorMtf[i] = j;
+ }
+ };
+
+ /*--- Assign actual codes for the tables. --*/
+ for (t = 0; t < nGroups; t++) {
+ minLen = 32;
+ maxLen = 0;
+ for (i = 0; i < alphaSize; i++) {
+ if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
+ if (s->len[t][i] < minLen) minLen = s->len[t][i];
+ }
+ AssertH ( !(maxLen > 17 /*20*/ ), 3004 );
+ AssertH ( !(minLen < 1), 3005 );
+ BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]),
+ minLen, maxLen, alphaSize );
+ }
+
+ /*--- Transmit the mapping table. ---*/
+ {
+ Bool inUse16[16];
+ for (i = 0; i < 16; i++) {
+ inUse16[i] = False;
+ for (j = 0; j < 16; j++)
+ if (s->inUse[i * 16 + j]) inUse16[i] = True;
+ }
+
+ nBytes = s->numZ;
+ for (i = 0; i < 16; i++)
+ if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0);
+
+ for (i = 0; i < 16; i++)
+ if (inUse16[i])
+ for (j = 0; j < 16; j++) {
+ if (s->inUse[i * 16 + j]) bsW(s,1,1); else bsW(s,1,0);
+ }
+
+ if (s->verbosity >= 3)
+ VPrintf1( " bytes: mapping %d, ", s->numZ-nBytes );
+ }
+
+ /*--- Now the selectors. ---*/
+ nBytes = s->numZ;
+ bsW ( s, 3, nGroups );
+ bsW ( s, 15, nSelectors );
+ for (i = 0; i < nSelectors; i++) {
+ for (j = 0; j < s->selectorMtf[i]; j++) bsW(s,1,1);
+ bsW(s,1,0);
+ }
+ if (s->verbosity >= 3)
+ VPrintf1( "selectors %d, ", s->numZ-nBytes );
+
+ /*--- Now the coding tables. ---*/
+ nBytes = s->numZ;
+
+ for (t = 0; t < nGroups; t++) {
+ Int32 curr = s->len[t][0];
+ bsW ( s, 5, curr );
+ for (i = 0; i < alphaSize; i++) {
+ while (curr < s->len[t][i]) { bsW(s,2,2); curr++; /* 10 */ };
+ while (curr > s->len[t][i]) { bsW(s,2,3); curr--; /* 11 */ };
+ bsW ( s, 1, 0 );
+ }
+ }
+
+ if (s->verbosity >= 3)
+ VPrintf1 ( "code lengths %d, ", s->numZ-nBytes );
+
+ /*--- And finally, the block data proper ---*/
+ nBytes = s->numZ;
+ selCtr = 0;
+ gs = 0;
+ while (True) {
+ if (gs >= s->nMTF) break;
+ ge = gs + BZ_G_SIZE - 1;
+ if (ge >= s->nMTF) ge = s->nMTF-1;
+ AssertH ( s->selector[selCtr] < nGroups, 3006 );
+
+ if (nGroups == 6 && 50 == ge-gs+1) {
+ /*--- fast track the common case ---*/
+ UInt16 mtfv_i;
+ UChar* s_len_sel_selCtr
+ = &(s->len[s->selector[selCtr]][0]);
+ Int32* s_code_sel_selCtr
+ = &(s->code[s->selector[selCtr]][0]);
+
+# define BZ_ITAH(nn) \
+ mtfv_i = mtfv[gs+(nn)]; \
+ bsW ( s, \
+ s_len_sel_selCtr[mtfv_i], \
+ s_code_sel_selCtr[mtfv_i] )
+
+ BZ_ITAH(0); BZ_ITAH(1); BZ_ITAH(2); BZ_ITAH(3); BZ_ITAH(4);
+ BZ_ITAH(5); BZ_ITAH(6); BZ_ITAH(7); BZ_ITAH(8); BZ_ITAH(9);
+ BZ_ITAH(10); BZ_ITAH(11); BZ_ITAH(12); BZ_ITAH(13); BZ_ITAH(14);
+ BZ_ITAH(15); BZ_ITAH(16); BZ_ITAH(17); BZ_ITAH(18); BZ_ITAH(19);
+ BZ_ITAH(20); BZ_ITAH(21); BZ_ITAH(22); BZ_ITAH(23); BZ_ITAH(24);
+ BZ_ITAH(25); BZ_ITAH(26); BZ_ITAH(27); BZ_ITAH(28); BZ_ITAH(29);
+ BZ_ITAH(30); BZ_ITAH(31); BZ_ITAH(32); BZ_ITAH(33); BZ_ITAH(34);
+ BZ_ITAH(35); BZ_ITAH(36); BZ_ITAH(37); BZ_ITAH(38); BZ_ITAH(39);
+ BZ_ITAH(40); BZ_ITAH(41); BZ_ITAH(42); BZ_ITAH(43); BZ_ITAH(44);
+ BZ_ITAH(45); BZ_ITAH(46); BZ_ITAH(47); BZ_ITAH(48); BZ_ITAH(49);
+
+# undef BZ_ITAH
+
+ } else {
+ /*--- slow version which correctly handles all situations ---*/
+ for (i = gs; i <= ge; i++) {
+ bsW ( s,
+ s->len [s->selector[selCtr]] [mtfv[i]],
+ s->code [s->selector[selCtr]] [mtfv[i]] );
+ }
+ }
+
+
+ gs = ge+1;
+ selCtr++;
+ }
+ AssertH( selCtr == nSelectors, 3007 );
+
+ if (s->verbosity >= 3)
+ VPrintf1( "codes %d\n", s->numZ-nBytes );
+}
+
+
+/*---------------------------------------------------*/
+void BZ2_compressBlock ( EState* s, Bool is_last_block )
+{
+ if (s->nblock > 0) {
+
+ BZ_FINALISE_CRC ( s->blockCRC );
+ s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
+ s->combinedCRC ^= s->blockCRC;
+ if (s->blockNo > 1) s->numZ = 0;
+
+ if (s->verbosity >= 2)
+ VPrintf4( " block %d: crc = 0x%08x, "
+ "combined CRC = 0x%08x, size = %d\n",
+ s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
+
+ BZ2_blockSort ( s );
+ }
+
+ s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]);
+
+ /*-- If this is the first block, create the stream header. --*/
+ if (s->blockNo == 1) {
+ BZ2_bsInitWrite ( s );
+ bsPutUChar ( s, BZ_HDR_B );
+ bsPutUChar ( s, BZ_HDR_Z );
+ bsPutUChar ( s, BZ_HDR_h );
+ bsPutUChar ( s, (UChar)(BZ_HDR_0 + s->blockSize100k) );
+ }
+
+ if (s->nblock > 0) {
+
+ bsPutUChar ( s, 0x31 ); bsPutUChar ( s, 0x41 );
+ bsPutUChar ( s, 0x59 ); bsPutUChar ( s, 0x26 );
+ bsPutUChar ( s, 0x53 ); bsPutUChar ( s, 0x59 );
+
+ /*-- Now the block's CRC, so it is in a known place. --*/
+ bsPutUInt32 ( s, s->blockCRC );
+
+ /*--
+ Now a single bit indicating (non-)randomisation.
+ As of version 0.9.5, we use a better sorting algorithm
+ which makes randomisation unnecessary. So always set
+ the randomised bit to 'no'. Of course, the decoder
+ still needs to be able to handle randomised blocks
+ so as to maintain backwards compatibility with
+ older versions of bzip2.
+ --*/
+ bsW(s,1,0);
+
+ bsW ( s, 24, s->origPtr );
+ generateMTFValues ( s );
+ sendMTFValues ( s );
+ }
+
+
+ /*-- If this is the last block, add the stream trailer. --*/
+ if (is_last_block) {
+
+ bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 );
+ bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 );
+ bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
+ bsPutUInt32 ( s, s->combinedCRC );
+ if (s->verbosity >= 2)
+ VPrintf1( " final combined CRC = 0x%08x\n ", s->combinedCRC );
+ bsFinishWrite ( s );
+ }
+}
+
+
+/*-------------------------------------------------------------*/
+/*--- end compress.c ---*/
+/*-------------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/crctable.c b/Utilities/cmbzip2/crctable.c
new file mode 100644
index 0000000000..215687b2c0
--- /dev/null
+++ b/Utilities/cmbzip2/crctable.c
@@ -0,0 +1,104 @@
+
+/*-------------------------------------------------------------*/
+/*--- Table for doing CRCs ---*/
+/*--- crctable.c ---*/
+/*-------------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#include "bzlib_private.h"
+
+/*--
+ I think this is an implementation of the AUTODIN-II,
+ Ethernet & FDDI 32-bit CRC standard. Vaguely derived
+ from code by Rob Warnock, in Section 51 of the
+ comp.compression FAQ.
+--*/
+
+UInt32 BZ2_crc32Table[256] = {
+
+ /*-- Ugly, innit? --*/
+
+ 0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
+ 0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
+ 0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
+ 0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
+ 0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
+ 0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
+ 0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
+ 0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
+ 0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
+ 0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
+ 0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
+ 0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
+ 0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
+ 0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
+ 0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
+ 0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
+ 0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
+ 0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
+ 0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
+ 0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
+ 0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
+ 0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
+ 0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
+ 0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
+ 0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
+ 0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
+ 0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
+ 0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
+ 0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
+ 0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
+ 0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
+ 0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
+ 0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
+ 0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
+ 0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
+ 0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
+ 0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
+ 0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
+ 0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
+ 0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
+ 0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
+ 0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
+ 0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
+ 0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
+ 0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
+ 0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
+ 0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
+ 0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
+ 0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
+ 0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
+ 0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
+ 0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
+ 0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
+ 0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
+ 0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
+ 0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
+ 0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
+ 0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
+ 0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
+ 0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
+ 0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
+ 0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
+ 0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
+ 0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
+};
+
+
+/*-------------------------------------------------------------*/
+/*--- end crctable.c ---*/
+/*-------------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/decompress.c b/Utilities/cmbzip2/decompress.c
new file mode 100644
index 0000000000..bba5e0fa36
--- /dev/null
+++ b/Utilities/cmbzip2/decompress.c
@@ -0,0 +1,626 @@
+
+/*-------------------------------------------------------------*/
+/*--- Decompression machinery ---*/
+/*--- decompress.c ---*/
+/*-------------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#include "bzlib_private.h"
+
+
+/*---------------------------------------------------*/
+static
+void makeMaps_d ( DState* s )
+{
+ Int32 i;
+ s->nInUse = 0;
+ for (i = 0; i < 256; i++)
+ if (s->inUse[i]) {
+ s->seqToUnseq[s->nInUse] = i;
+ s->nInUse++;
+ }
+}
+
+
+/*---------------------------------------------------*/
+#define RETURN(rrr) \
+ { retVal = rrr; goto save_state_and_return; };
+
+#define GET_BITS(lll,vvv,nnn) \
+ case lll: s->state = lll; \
+ while (True) { \
+ if (s->bsLive >= nnn) { \
+ UInt32 v; \
+ v = (s->bsBuff >> \
+ (s->bsLive-nnn)) & ((1 << nnn)-1); \
+ s->bsLive -= nnn; \
+ vvv = v; \
+ break; \
+ } \
+ if (s->strm->avail_in == 0) RETURN(BZ_OK); \
+ s->bsBuff \
+ = (s->bsBuff << 8) | \
+ ((UInt32) \
+ (*((UChar*)(s->strm->next_in)))); \
+ s->bsLive += 8; \
+ s->strm->next_in++; \
+ s->strm->avail_in--; \
+ s->strm->total_in_lo32++; \
+ if (s->strm->total_in_lo32 == 0) \
+ s->strm->total_in_hi32++; \
+ }
+
+#define GET_UCHAR(lll,uuu) \
+ GET_BITS(lll,uuu,8)
+
+#define GET_BIT(lll,uuu) \
+ GET_BITS(lll,uuu,1)
+
+/*---------------------------------------------------*/
+#define GET_MTF_VAL(label1,label2,lval) \
+{ \
+ if (groupPos == 0) { \
+ groupNo++; \
+ if (groupNo >= nSelectors) \
+ RETURN(BZ_DATA_ERROR); \
+ groupPos = BZ_G_SIZE; \
+ gSel = s->selector[groupNo]; \
+ gMinlen = s->minLens[gSel]; \
+ gLimit = &(s->limit[gSel][0]); \
+ gPerm = &(s->perm[gSel][0]); \
+ gBase = &(s->base[gSel][0]); \
+ } \
+ groupPos--; \
+ zn = gMinlen; \
+ GET_BITS(label1, zvec, zn); \
+ while (1) { \
+ if (zn > 20 /* the longest code */) \
+ RETURN(BZ_DATA_ERROR); \
+ if (zvec <= gLimit[zn]) break; \
+ zn++; \
+ GET_BIT(label2, zj); \
+ zvec = (zvec << 1) | zj; \
+ }; \
+ if (zvec - gBase[zn] < 0 \
+ || zvec - gBase[zn] >= BZ_MAX_ALPHA_SIZE) \
+ RETURN(BZ_DATA_ERROR); \
+ lval = gPerm[zvec - gBase[zn]]; \
+}
+
+
+/*---------------------------------------------------*/
+Int32 BZ2_decompress ( DState* s )
+{
+ UChar uc;
+ Int32 retVal;
+ Int32 minLen, maxLen;
+ bz_stream* strm = s->strm;
+
+ /* stuff that needs to be saved/restored */
+ Int32 i;
+ Int32 j;
+ Int32 t;
+ Int32 alphaSize;
+ Int32 nGroups;
+ Int32 nSelectors;
+ Int32 EOB;
+ Int32 groupNo;
+ Int32 groupPos;
+ Int32 nextSym;
+ Int32 nblockMAX;
+ Int32 nblock;
+ Int32 es;
+ Int32 N;
+ Int32 curr;
+ Int32 zt;
+ Int32 zn;
+ Int32 zvec;
+ Int32 zj;
+ Int32 gSel;
+ Int32 gMinlen;
+ Int32* gLimit;
+ Int32* gBase;
+ Int32* gPerm;
+
+ if (s->state == BZ_X_MAGIC_1) {
+ /*initialise the save area*/
+ s->save_i = 0;
+ s->save_j = 0;
+ s->save_t = 0;
+ s->save_alphaSize = 0;
+ s->save_nGroups = 0;
+ s->save_nSelectors = 0;
+ s->save_EOB = 0;
+ s->save_groupNo = 0;
+ s->save_groupPos = 0;
+ s->save_nextSym = 0;
+ s->save_nblockMAX = 0;
+ s->save_nblock = 0;
+ s->save_es = 0;
+ s->save_N = 0;
+ s->save_curr = 0;
+ s->save_zt = 0;
+ s->save_zn = 0;
+ s->save_zvec = 0;
+ s->save_zj = 0;
+ s->save_gSel = 0;
+ s->save_gMinlen = 0;
+ s->save_gLimit = NULL;
+ s->save_gBase = NULL;
+ s->save_gPerm = NULL;
+ }
+
+ /*restore from the save area*/
+ i = s->save_i;
+ j = s->save_j;
+ t = s->save_t;
+ alphaSize = s->save_alphaSize;
+ nGroups = s->save_nGroups;
+ nSelectors = s->save_nSelectors;
+ EOB = s->save_EOB;
+ groupNo = s->save_groupNo;
+ groupPos = s->save_groupPos;
+ nextSym = s->save_nextSym;
+ nblockMAX = s->save_nblockMAX;
+ nblock = s->save_nblock;
+ es = s->save_es;
+ N = s->save_N;
+ curr = s->save_curr;
+ zt = s->save_zt;
+ zn = s->save_zn;
+ zvec = s->save_zvec;
+ zj = s->save_zj;
+ gSel = s->save_gSel;
+ gMinlen = s->save_gMinlen;
+ gLimit = s->save_gLimit;
+ gBase = s->save_gBase;
+ gPerm = s->save_gPerm;
+
+ retVal = BZ_OK;
+
+ switch (s->state) {
+
+ GET_UCHAR(BZ_X_MAGIC_1, uc);
+ if (uc != BZ_HDR_B) RETURN(BZ_DATA_ERROR_MAGIC);
+
+ GET_UCHAR(BZ_X_MAGIC_2, uc);
+ if (uc != BZ_HDR_Z) RETURN(BZ_DATA_ERROR_MAGIC);
+
+ GET_UCHAR(BZ_X_MAGIC_3, uc)
+ if (uc != BZ_HDR_h) RETURN(BZ_DATA_ERROR_MAGIC);
+
+ GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
+ if (s->blockSize100k < (BZ_HDR_0 + 1) ||
+ s->blockSize100k > (BZ_HDR_0 + 9)) RETURN(BZ_DATA_ERROR_MAGIC);
+ s->blockSize100k -= BZ_HDR_0;
+
+ if (s->smallDecompress) {
+ s->ll16 = BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
+ s->ll4 = BZALLOC(
+ ((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar)
+ );
+ if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR);
+ } else {
+ s->tt = BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) );
+ if (s->tt == NULL) RETURN(BZ_MEM_ERROR);
+ }
+
+ GET_UCHAR(BZ_X_BLKHDR_1, uc);
+
+ if (uc == 0x17) goto endhdr_2;
+ if (uc != 0x31) RETURN(BZ_DATA_ERROR);
+ GET_UCHAR(BZ_X_BLKHDR_2, uc);
+ if (uc != 0x41) RETURN(BZ_DATA_ERROR);
+ GET_UCHAR(BZ_X_BLKHDR_3, uc);
+ if (uc != 0x59) RETURN(BZ_DATA_ERROR);
+ GET_UCHAR(BZ_X_BLKHDR_4, uc);
+ if (uc != 0x26) RETURN(BZ_DATA_ERROR);
+ GET_UCHAR(BZ_X_BLKHDR_5, uc);
+ if (uc != 0x53) RETURN(BZ_DATA_ERROR);
+ GET_UCHAR(BZ_X_BLKHDR_6, uc);
+ if (uc != 0x59) RETURN(BZ_DATA_ERROR);
+
+ s->currBlockNo++;
+ if (s->verbosity >= 2)
+ VPrintf1 ( "\n [%d: huff+mtf ", s->currBlockNo );
+
+ s->storedBlockCRC = 0;
+ GET_UCHAR(BZ_X_BCRC_1, uc);
+ s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
+ GET_UCHAR(BZ_X_BCRC_2, uc);
+ s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
+ GET_UCHAR(BZ_X_BCRC_3, uc);
+ s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
+ GET_UCHAR(BZ_X_BCRC_4, uc);
+ s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
+
+ GET_BITS(BZ_X_RANDBIT, s->blockRandomised, 1);
+
+ s->origPtr = 0;
+ GET_UCHAR(BZ_X_ORIGPTR_1, uc);
+ s->origPtr = (s->origPtr << 8) | ((Int32)uc);
+ GET_UCHAR(BZ_X_ORIGPTR_2, uc);
+ s->origPtr = (s->origPtr << 8) | ((Int32)uc);
+ GET_UCHAR(BZ_X_ORIGPTR_3, uc);
+ s->origPtr = (s->origPtr << 8) | ((Int32)uc);
+
+ if (s->origPtr < 0)
+ RETURN(BZ_DATA_ERROR);
+ if (s->origPtr > 10 + 100000*s->blockSize100k)
+ RETURN(BZ_DATA_ERROR);
+
+ /*--- Receive the mapping table ---*/
+ for (i = 0; i < 16; i++) {
+ GET_BIT(BZ_X_MAPPING_1, uc);
+ if (uc == 1)
+ s->inUse16[i] = True; else
+ s->inUse16[i] = False;
+ }
+
+ for (i = 0; i < 256; i++) s->inUse[i] = False;
+
+ for (i = 0; i < 16; i++)
+ if (s->inUse16[i])
+ for (j = 0; j < 16; j++) {
+ GET_BIT(BZ_X_MAPPING_2, uc);
+ if (uc == 1) s->inUse[i * 16 + j] = True;
+ }
+ makeMaps_d ( s );
+ if (s->nInUse == 0) RETURN(BZ_DATA_ERROR);
+ alphaSize = s->nInUse+2;
+
+ /*--- Now the selectors ---*/
+ GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
+ if (nGroups < 2 || nGroups > 6) RETURN(BZ_DATA_ERROR);
+ GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
+ if (nSelectors < 1) RETURN(BZ_DATA_ERROR);
+ for (i = 0; i < nSelectors; i++) {
+ j = 0;
+ while (True) {
+ GET_BIT(BZ_X_SELECTOR_3, uc);
+ if (uc == 0) break;
+ j++;
+ if (j >= nGroups) RETURN(BZ_DATA_ERROR);
+ }
+ s->selectorMtf[i] = j;
+ }
+
+ /*--- Undo the MTF values for the selectors. ---*/
+ {
+ UChar pos[BZ_N_GROUPS], tmp, v;
+ for (v = 0; v < nGroups; v++) pos[v] = v;
+
+ for (i = 0; i < nSelectors; i++) {
+ v = s->selectorMtf[i];
+ tmp = pos[v];
+ while (v > 0) { pos[v] = pos[v-1]; v--; }
+ pos[0] = tmp;
+ s->selector[i] = tmp;
+ }
+ }
+
+ /*--- Now the coding tables ---*/
+ for (t = 0; t < nGroups; t++) {
+ GET_BITS(BZ_X_CODING_1, curr, 5);
+ for (i = 0; i < alphaSize; i++) {
+ while (True) {
+ if (curr < 1 || curr > 20) RETURN(BZ_DATA_ERROR);
+ GET_BIT(BZ_X_CODING_2, uc);
+ if (uc == 0) break;
+ GET_BIT(BZ_X_CODING_3, uc);
+ if (uc == 0) curr++; else curr--;
+ }
+ s->len[t][i] = curr;
+ }
+ }
+
+ /*--- Create the Huffman decoding tables ---*/
+ for (t = 0; t < nGroups; t++) {
+ minLen = 32;
+ maxLen = 0;
+ for (i = 0; i < alphaSize; i++) {
+ if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
+ if (s->len[t][i] < minLen) minLen = s->len[t][i];
+ }
+ BZ2_hbCreateDecodeTables (
+ &(s->limit[t][0]),
+ &(s->base[t][0]),
+ &(s->perm[t][0]),
+ &(s->len[t][0]),
+ minLen, maxLen, alphaSize
+ );
+ s->minLens[t] = minLen;
+ }
+
+ /*--- Now the MTF values ---*/
+
+ EOB = s->nInUse+1;
+ nblockMAX = 100000 * s->blockSize100k;
+ groupNo = -1;
+ groupPos = 0;
+
+ for (i = 0; i <= 255; i++) s->unzftab[i] = 0;
+
+ /*-- MTF init --*/
+ {
+ Int32 ii, jj, kk;
+ kk = MTFA_SIZE-1;
+ for (ii = 256 / MTFL_SIZE - 1; ii >= 0; ii--) {
+ for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
+ s->mtfa[kk] = (UChar)(ii * MTFL_SIZE + jj);
+ kk--;
+ }
+ s->mtfbase[ii] = kk + 1;
+ }
+ }
+ /*-- end MTF init --*/
+
+ nblock = 0;
+ GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
+
+ while (True) {
+
+ if (nextSym == EOB) break;
+
+ if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
+
+ es = -1;
+ N = 1;
+ do {
+ if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
+ if (nextSym == BZ_RUNB) es = es + (1+1) * N;
+ N = N * 2;
+ GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
+ }
+ while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
+
+ es++;
+ uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ];
+ s->unzftab[uc] += es;
+
+ if (s->smallDecompress)
+ while (es > 0) {
+ if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
+ s->ll16[nblock] = (UInt16)uc;
+ nblock++;
+ es--;
+ }
+ else
+ while (es > 0) {
+ if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
+ s->tt[nblock] = (UInt32)uc;
+ nblock++;
+ es--;
+ };
+
+ continue;
+
+ } else {
+
+ if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
+
+ /*-- uc = MTF ( nextSym-1 ) --*/
+ {
+ Int32 ii, jj, kk, pp, lno, off;
+ UInt32 nn;
+ nn = (UInt32)(nextSym - 1);
+
+ if (nn < MTFL_SIZE) {
+ /* avoid general-case expense */
+ pp = s->mtfbase[0];
+ uc = s->mtfa[pp+nn];
+ while (nn > 3) {
+ Int32 z = pp+nn;
+ s->mtfa[(z) ] = s->mtfa[(z)-1];
+ s->mtfa[(z)-1] = s->mtfa[(z)-2];
+ s->mtfa[(z)-2] = s->mtfa[(z)-3];
+ s->mtfa[(z)-3] = s->mtfa[(z)-4];
+ nn -= 4;
+ }
+ while (nn > 0) {
+ s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--;
+ };
+ s->mtfa[pp] = uc;
+ } else {
+ /* general case */
+ lno = nn / MTFL_SIZE;
+ off = nn % MTFL_SIZE;
+ pp = s->mtfbase[lno] + off;
+ uc = s->mtfa[pp];
+ while (pp > s->mtfbase[lno]) {
+ s->mtfa[pp] = s->mtfa[pp-1]; pp--;
+ };
+ s->mtfbase[lno]++;
+ while (lno > 0) {
+ s->mtfbase[lno]--;
+ s->mtfa[s->mtfbase[lno]]
+ = s->mtfa[s->mtfbase[lno-1] + MTFL_SIZE - 1];
+ lno--;
+ }
+ s->mtfbase[0]--;
+ s->mtfa[s->mtfbase[0]] = uc;
+ if (s->mtfbase[0] == 0) {
+ kk = MTFA_SIZE-1;
+ for (ii = 256 / MTFL_SIZE-1; ii >= 0; ii--) {
+ for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
+ s->mtfa[kk] = s->mtfa[s->mtfbase[ii] + jj];
+ kk--;
+ }
+ s->mtfbase[ii] = kk + 1;
+ }
+ }
+ }
+ }
+ /*-- end uc = MTF ( nextSym-1 ) --*/
+
+ s->unzftab[s->seqToUnseq[uc]]++;
+ if (s->smallDecompress)
+ s->ll16[nblock] = (UInt16)(s->seqToUnseq[uc]); else
+ s->tt[nblock] = (UInt32)(s->seqToUnseq[uc]);
+ nblock++;
+
+ GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
+ continue;
+ }
+ }
+
+ /* Now we know what nblock is, we can do a better sanity
+ check on s->origPtr.
+ */
+ if (s->origPtr < 0 || s->origPtr >= nblock)
+ RETURN(BZ_DATA_ERROR);
+
+ /*-- Set up cftab to facilitate generation of T^(-1) --*/
+ s->cftab[0] = 0;
+ for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
+ for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
+ for (i = 0; i <= 256; i++) {
+ if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
+ /* s->cftab[i] can legitimately be == nblock */
+ RETURN(BZ_DATA_ERROR);
+ }
+ }
+
+ s->state_out_len = 0;
+ s->state_out_ch = 0;
+ BZ_INITIALISE_CRC ( s->calculatedBlockCRC );
+ s->state = BZ_X_OUTPUT;
+ if (s->verbosity >= 2) VPrintf0 ( "rt+rld" );
+
+ if (s->smallDecompress) {
+
+ /*-- Make a copy of cftab, used in generation of T --*/
+ for (i = 0; i <= 256; i++) s->cftabCopy[i] = s->cftab[i];
+
+ /*-- compute the T vector --*/
+ for (i = 0; i < nblock; i++) {
+ uc = (UChar)(s->ll16[i]);
+ SET_LL(i, s->cftabCopy[uc]);
+ s->cftabCopy[uc]++;
+ }
+
+ /*-- Compute T^(-1) by pointer reversal on T --*/
+ i = s->origPtr;
+ j = GET_LL(i);
+ do {
+ Int32 tmp = GET_LL(j);
+ SET_LL(j, i);
+ i = j;
+ j = tmp;
+ }
+ while (i != s->origPtr);
+
+ s->tPos = s->origPtr;
+ s->nblock_used = 0;
+ if (s->blockRandomised) {
+ BZ_RAND_INIT_MASK;
+ BZ_GET_SMALL(s->k0); s->nblock_used++;
+ BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
+ } else {
+ BZ_GET_SMALL(s->k0); s->nblock_used++;
+ }
+
+ } else {
+
+ /*-- compute the T^(-1) vector --*/
+ for (i = 0; i < nblock; i++) {
+ uc = (UChar)(s->tt[i] & 0xff);
+ s->tt[s->cftab[uc]] |= (i << 8);
+ s->cftab[uc]++;
+ }
+
+ s->tPos = s->tt[s->origPtr] >> 8;
+ s->nblock_used = 0;
+ if (s->blockRandomised) {
+ BZ_RAND_INIT_MASK;
+ BZ_GET_FAST(s->k0); s->nblock_used++;
+ BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
+ } else {
+ BZ_GET_FAST(s->k0); s->nblock_used++;
+ }
+
+ }
+
+ RETURN(BZ_OK);
+
+
+
+ endhdr_2:
+
+ GET_UCHAR(BZ_X_ENDHDR_2, uc);
+ if (uc != 0x72) RETURN(BZ_DATA_ERROR);
+ GET_UCHAR(BZ_X_ENDHDR_3, uc);
+ if (uc != 0x45) RETURN(BZ_DATA_ERROR);
+ GET_UCHAR(BZ_X_ENDHDR_4, uc);
+ if (uc != 0x38) RETURN(BZ_DATA_ERROR);
+ GET_UCHAR(BZ_X_ENDHDR_5, uc);
+ if (uc != 0x50) RETURN(BZ_DATA_ERROR);
+ GET_UCHAR(BZ_X_ENDHDR_6, uc);
+ if (uc != 0x90) RETURN(BZ_DATA_ERROR);
+
+ s->storedCombinedCRC = 0;
+ GET_UCHAR(BZ_X_CCRC_1, uc);
+ s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
+ GET_UCHAR(BZ_X_CCRC_2, uc);
+ s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
+ GET_UCHAR(BZ_X_CCRC_3, uc);
+ s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
+ GET_UCHAR(BZ_X_CCRC_4, uc);
+ s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
+
+ s->state = BZ_X_IDLE;
+ RETURN(BZ_STREAM_END);
+
+ default: AssertH ( False, 4001 );
+ }
+
+ AssertH ( False, 4002 );
+
+ save_state_and_return:
+
+ s->save_i = i;
+ s->save_j = j;
+ s->save_t = t;
+ s->save_alphaSize = alphaSize;
+ s->save_nGroups = nGroups;
+ s->save_nSelectors = nSelectors;
+ s->save_EOB = EOB;
+ s->save_groupNo = groupNo;
+ s->save_groupPos = groupPos;
+ s->save_nextSym = nextSym;
+ s->save_nblockMAX = nblockMAX;
+ s->save_nblock = nblock;
+ s->save_es = es;
+ s->save_N = N;
+ s->save_curr = curr;
+ s->save_zt = zt;
+ s->save_zn = zn;
+ s->save_zvec = zvec;
+ s->save_zj = zj;
+ s->save_gSel = gSel;
+ s->save_gMinlen = gMinlen;
+ s->save_gLimit = gLimit;
+ s->save_gBase = gBase;
+ s->save_gPerm = gPerm;
+
+ return retVal;
+}
+
+
+/*-------------------------------------------------------------*/
+/*--- end decompress.c ---*/
+/*-------------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/dlltest.c b/Utilities/cmbzip2/dlltest.c
new file mode 100644
index 0000000000..4e27da2800
--- /dev/null
+++ b/Utilities/cmbzip2/dlltest.c
@@ -0,0 +1,175 @@
+/*
+ minibz2
+ libbz2.dll test program.
+ by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
+ This file is Public Domain. Welcome any email to me.
+
+ usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]
+*/
+
+#define BZ_IMPORT
+#include <stdio.h>
+#include <stdlib.h>
+#include "bzlib.h"
+#ifdef _WIN32
+#include <io.h>
+#endif
+
+
+#ifdef _WIN32
+
+#define BZ2_LIBNAME "libbz2-1.0.2.DLL"
+
+#include <windows.h>
+static int BZ2DLLLoaded = 0;
+static HINSTANCE BZ2DLLhLib;
+int BZ2DLLLoadLibrary(void)
+{
+ HINSTANCE hLib;
+
+ if(BZ2DLLLoaded==1){return 0;}
+ hLib=LoadLibrary(BZ2_LIBNAME);
+ if(hLib == NULL){
+ fprintf(stderr,"Can't load %s\n",BZ2_LIBNAME);
+ return -1;
+ }
+ BZ2_bzlibVersion=GetProcAddress(hLib,"BZ2_bzlibVersion");
+ BZ2_bzopen=GetProcAddress(hLib,"BZ2_bzopen");
+ BZ2_bzdopen=GetProcAddress(hLib,"BZ2_bzdopen");
+ BZ2_bzread=GetProcAddress(hLib,"BZ2_bzread");
+ BZ2_bzwrite=GetProcAddress(hLib,"BZ2_bzwrite");
+ BZ2_bzflush=GetProcAddress(hLib,"BZ2_bzflush");
+ BZ2_bzclose=GetProcAddress(hLib,"BZ2_bzclose");
+ BZ2_bzerror=GetProcAddress(hLib,"BZ2_bzerror");
+
+ if (!BZ2_bzlibVersion || !BZ2_bzopen || !BZ2_bzdopen
+ || !BZ2_bzread || !BZ2_bzwrite || !BZ2_bzflush
+ || !BZ2_bzclose || !BZ2_bzerror) {
+ fprintf(stderr,"GetProcAddress failed.\n");
+ return -1;
+ }
+ BZ2DLLLoaded=1;
+ BZ2DLLhLib=hLib;
+ return 0;
+
+}
+int BZ2DLLFreeLibrary(void)
+{
+ if(BZ2DLLLoaded==0){return 0;}
+ FreeLibrary(BZ2DLLhLib);
+ BZ2DLLLoaded=0;
+}
+#endif /* WIN32 */
+
+void usage(void)
+{
+ puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]");
+}
+
+int main(int argc,char *argv[])
+{
+ int decompress = 0;
+ int level = 9;
+ char *fn_r = NULL;
+ char *fn_w = NULL;
+
+#ifdef _WIN32
+ if(BZ2DLLLoadLibrary()<0){
+ fprintf(stderr,"Loading of %s failed. Giving up.\n", BZ2_LIBNAME);
+ exit(1);
+ }
+ printf("Loading of %s succeeded. Library version is %s.\n",
+ BZ2_LIBNAME, BZ2_bzlibVersion() );
+#endif
+ while(++argv,--argc){
+ if(**argv =='-' || **argv=='/'){
+ char *p;
+
+ for(p=*argv+1;*p;p++){
+ if(*p=='d'){
+ decompress = 1;
+ }else if('1'<=*p && *p<='9'){
+ level = *p - '0';
+ }else{
+ usage();
+ exit(1);
+ }
+ }
+ }else{
+ break;
+ }
+ }
+ if(argc>=1){
+ fn_r = *argv;
+ argc--;argv++;
+ }else{
+ fn_r = NULL;
+ }
+ if(argc>=1){
+ fn_w = *argv;
+ argc--;argv++;
+ }else{
+ fn_w = NULL;
+ }
+ {
+ int len;
+ char buff[0x1000];
+ char mode[10];
+
+ if(decompress){
+ BZFILE *BZ2fp_r = NULL;
+ FILE *fp_w = NULL;
+
+ if(fn_w){
+ if((fp_w = fopen(fn_w,"wb"))==NULL){
+ printf("can't open [%s]\n",fn_w);
+ perror("reason:");
+ exit(1);
+ }
+ }else{
+ fp_w = stdout;
+ }
+ if((fn_r == NULL && (BZ2fp_r = BZ2_bzdopen(fileno(stdin),"rb"))==NULL)
+ || (fn_r != NULL && (BZ2fp_r = BZ2_bzopen(fn_r,"rb"))==NULL)){
+ printf("can't bz2openstream\n");
+ exit(1);
+ }
+ while((len=BZ2_bzread(BZ2fp_r,buff,0x1000))>0){
+ fwrite(buff,1,len,fp_w);
+ }
+ BZ2_bzclose(BZ2fp_r);
+ if(fp_w != stdout) fclose(fp_w);
+ }else{
+ BZFILE *BZ2fp_w = NULL;
+ FILE *fp_r = NULL;
+
+ if(fn_r){
+ if((fp_r = fopen(fn_r,"rb"))==NULL){
+ printf("can't open [%s]\n",fn_r);
+ perror("reason:");
+ exit(1);
+ }
+ }else{
+ fp_r = stdin;
+ }
+ mode[0]='w';
+ mode[1] = '0' + level;
+ mode[2] = '\0';
+
+ if((fn_w == NULL && (BZ2fp_w = BZ2_bzdopen(fileno(stdout),mode))==NULL)
+ || (fn_w !=NULL && (BZ2fp_w = BZ2_bzopen(fn_w,mode))==NULL)){
+ printf("can't bz2openstream\n");
+ exit(1);
+ }
+ while((len=fread(buff,1,0x1000,fp_r))>0){
+ BZ2_bzwrite(BZ2fp_w,buff,len);
+ }
+ BZ2_bzclose(BZ2fp_w);
+ if(fp_r!=stdin)fclose(fp_r);
+ }
+ }
+#ifdef _WIN32
+ BZ2DLLFreeLibrary();
+#endif
+ return 0;
+}
diff --git a/Utilities/cmbzip2/dlltest.dsp b/Utilities/cmbzip2/dlltest.dsp
new file mode 100644
index 0000000000..4b1615edcd
--- /dev/null
+++ b/Utilities/cmbzip2/dlltest.dsp
@@ -0,0 +1,93 @@
+# Microsoft Developer Studio Project File - Name="dlltest" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 5.00
+# ** •ÒW‚µ‚È‚¢‚Å‚­‚¾‚³‚¢ **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=dlltest - Win32 Debug
+!MESSAGE ‚±‚ê‚Í—LŒø‚ÈÒ²¸Ì§²Ù‚Å‚Í‚ ‚è‚Ü‚¹‚ñB ‚±‚ÌÌßÛ¼Þª¸Ä‚ðËÞÙÄÞ‚·‚邽‚ß‚É‚Í NMAKE ‚ðŽg—p‚µ‚Ä‚­‚¾‚³‚¢B
+!MESSAGE [Ò²¸Ì§²Ù‚Ì´¸½Îß°Ä] ºÏÝÄÞ‚ðŽg—p‚µ‚ÄŽÀs‚µ‚Ä‚­‚¾‚³‚¢
+!MESSAGE
+!MESSAGE NMAKE /f "dlltest.mak".
+!MESSAGE
+!MESSAGE NMAKE ‚ÌŽÀsŽž‚É\¬‚ðŽw’è‚Å‚«‚Ü‚·
+!MESSAGE ºÏÝÄÞ ×²Ýã‚ÅϸۂÌÝ’è‚ð’è‹`‚µ‚Ü‚·B—á:
+!MESSAGE
+!MESSAGE NMAKE /f "dlltest.mak" CFG="dlltest - Win32 Debug"
+!MESSAGE
+!MESSAGE ‘I‘ð‰Â”\‚ÈËÞÙÄÞ Ó°ÄÞ:
+!MESSAGE
+!MESSAGE "dlltest - Win32 Release" ("Win32 (x86) Console Application" —p)
+!MESSAGE "dlltest - Win32 Debug" ("Win32 (x86) Console Application" —p)
+!MESSAGE
+
+# Begin Project
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "dlltest - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x411 /d "NDEBUG"
+# ADD RSC /l 0x411 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"minibz2.exe"
+
+!ELSEIF "$(CFG)" == "dlltest - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "dlltest_"
+# PROP BASE Intermediate_Dir "dlltest_"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "dlltest_"
+# PROP Intermediate_Dir "dlltest_"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x411 /d "_DEBUG"
+# ADD RSC /l 0x411 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"minibz2.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "dlltest - Win32 Release"
+# Name "dlltest - Win32 Debug"
+# Begin Source File
+
+SOURCE=.\bzlib.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\dlltest.c
+# End Source File
+# End Target
+# End Project
diff --git a/Utilities/cmbzip2/entities.xml b/Utilities/cmbzip2/entities.xml
new file mode 100644
index 0000000000..e9e0553b7d
--- /dev/null
+++ b/Utilities/cmbzip2/entities.xml
@@ -0,0 +1,9 @@
+<!-- misc. strings -->
+<!ENTITY bz-url "http://www.bzip.org">
+<!ENTITY bz-email "jseward@bzip.org">
+<!ENTITY bz-lifespan "1996-2007">
+
+<!ENTITY bz-version "1.0.5">
+<!ENTITY bz-date "10 December 2007">
+
+<!ENTITY manual-title "bzip2 Manual">
diff --git a/Utilities/cmbzip2/format.pl b/Utilities/cmbzip2/format.pl
new file mode 100755
index 0000000000..2b391dad64
--- /dev/null
+++ b/Utilities/cmbzip2/format.pl
@@ -0,0 +1,68 @@
+#!/usr/bin/perl -w
+#
+# ------------------------------------------------------------------
+# This file is part of bzip2/libbzip2, a program and library for
+# lossless, block-sorting data compression.
+#
+# bzip2/libbzip2 version 1.0.5 of 10 December 2007
+# Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+#
+# Please read the WARNING, DISCLAIMER and PATENTS sections in the
+# README file.
+#
+# This program is released under the terms of the license contained
+# in the file LICENSE.
+# ------------------------------------------------------------------
+#
+use strict;
+
+# get command line values:
+if ( $#ARGV !=1 ) {
+ die "Usage: $0 xml_infile xml_outfile\n";
+}
+
+my $infile = shift;
+# check infile exists
+die "Can't find file \"$infile\""
+ unless -f $infile;
+# check we can read infile
+if (! -r $infile) {
+ die "Can't read input $infile\n";
+}
+# check we can open infile
+open( INFILE,"<$infile" ) or
+ die "Can't input $infile $!";
+
+#my $outfile = 'fmt-manual.xml';
+my $outfile = shift;
+#print "Infile: $infile, Outfile: $outfile\n";
+# check we can write to outfile
+open( OUTFILE,">$outfile" ) or
+ die "Can't output $outfile $! for writing";
+
+my ($prev, $curr, $str);
+$prev = ''; $curr = '';
+while ( <INFILE> ) {
+
+ print OUTFILE $prev;
+ $prev = $curr;
+ $curr = $_;
+ $str = '';
+
+ if ( $prev =~ /<programlisting>$|<screen>$/ ) {
+ chomp $prev;
+ $curr = join( '', $prev, "<![CDATA[", $curr );
+ $prev = '';
+ next;
+ }
+ elsif ( $curr =~ /<\/programlisting>|<\/screen>/ ) {
+ chomp $prev;
+ $curr = join( '', $prev, "]]>", $curr );
+ $prev = '';
+ next;
+ }
+}
+print OUTFILE $curr;
+close INFILE;
+close OUTFILE;
+exit;
diff --git a/Utilities/cmbzip2/huffman.c b/Utilities/cmbzip2/huffman.c
new file mode 100644
index 0000000000..87e79e38af
--- /dev/null
+++ b/Utilities/cmbzip2/huffman.c
@@ -0,0 +1,205 @@
+
+/*-------------------------------------------------------------*/
+/*--- Huffman coding low-level stuff ---*/
+/*--- huffman.c ---*/
+/*-------------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#include "bzlib_private.h"
+
+/*---------------------------------------------------*/
+#define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
+#define DEPTHOF(zz1) ((zz1) & 0x000000ff)
+#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
+
+#define ADDWEIGHTS(zw1,zw2) \
+ (WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
+ (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
+
+#define UPHEAP(z) \
+{ \
+ Int32 zz, tmp; \
+ zz = z; tmp = heap[zz]; \
+ while (weight[tmp] < weight[heap[zz >> 1]]) { \
+ heap[zz] = heap[zz >> 1]; \
+ zz >>= 1; \
+ } \
+ heap[zz] = tmp; \
+}
+
+#define DOWNHEAP(z) \
+{ \
+ Int32 zz, yy, tmp; \
+ zz = z; tmp = heap[zz]; \
+ while (True) { \
+ yy = zz << 1; \
+ if (yy > nHeap) break; \
+ if (yy < nHeap && \
+ weight[heap[yy+1]] < weight[heap[yy]]) \
+ yy++; \
+ if (weight[tmp] < weight[heap[yy]]) break; \
+ heap[zz] = heap[yy]; \
+ zz = yy; \
+ } \
+ heap[zz] = tmp; \
+}
+
+
+/*---------------------------------------------------*/
+void BZ2_hbMakeCodeLengths ( UChar *len,
+ Int32 *freq,
+ Int32 alphaSize,
+ Int32 maxLen )
+{
+ /*--
+ Nodes and heap entries run from 1. Entry 0
+ for both the heap and nodes is a sentinel.
+ --*/
+ Int32 nNodes, nHeap, n1, n2, i, j, k;
+ Bool tooLong;
+
+ Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ];
+ Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
+ Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
+
+ for (i = 0; i < alphaSize; i++)
+ weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
+
+ while (True) {
+
+ nNodes = alphaSize;
+ nHeap = 0;
+
+ heap[0] = 0;
+ weight[0] = 0;
+ parent[0] = -2;
+
+ for (i = 1; i <= alphaSize; i++) {
+ parent[i] = -1;
+ nHeap++;
+ heap[nHeap] = i;
+ UPHEAP(nHeap);
+ }
+
+ AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
+
+ while (nHeap > 1) {
+ n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
+ n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
+ nNodes++;
+ parent[n1] = parent[n2] = nNodes;
+ weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
+ parent[nNodes] = -1;
+ nHeap++;
+ heap[nHeap] = nNodes;
+ UPHEAP(nHeap);
+ }
+
+ AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
+
+ tooLong = False;
+ for (i = 1; i <= alphaSize; i++) {
+ j = 0;
+ k = i;
+ while (parent[k] >= 0) { k = parent[k]; j++; }
+ len[i-1] = j;
+ if (j > maxLen) tooLong = True;
+ }
+
+ if (! tooLong) break;
+
+ /* 17 Oct 04: keep-going condition for the following loop used
+ to be 'i < alphaSize', which missed the last element,
+ theoretically leading to the possibility of the compressor
+ looping. However, this count-scaling step is only needed if
+ one of the generated Huffman code words is longer than
+ maxLen, which up to and including version 1.0.2 was 20 bits,
+ which is extremely unlikely. In version 1.0.3 maxLen was
+ changed to 17 bits, which has minimal effect on compression
+ ratio, but does mean this scaling step is used from time to
+ time, enough to verify that it works.
+
+ This means that bzip2-1.0.3 and later will only produce
+ Huffman codes with a maximum length of 17 bits. However, in
+ order to preserve backwards compatibility with bitstreams
+ produced by versions pre-1.0.3, the decompressor must still
+ handle lengths of up to 20. */
+
+ for (i = 1; i <= alphaSize; i++) {
+ j = weight[i] >> 8;
+ j = 1 + (j / 2);
+ weight[i] = j << 8;
+ }
+ }
+}
+
+
+/*---------------------------------------------------*/
+void BZ2_hbAssignCodes ( Int32 *code,
+ UChar *length,
+ Int32 minLen,
+ Int32 maxLen,
+ Int32 alphaSize )
+{
+ Int32 n, vec, i;
+
+ vec = 0;
+ for (n = minLen; n <= maxLen; n++) {
+ for (i = 0; i < alphaSize; i++)
+ if (length[i] == n) { code[i] = vec; vec++; };
+ vec <<= 1;
+ }
+}
+
+
+/*---------------------------------------------------*/
+void BZ2_hbCreateDecodeTables ( Int32 *limit,
+ Int32 *base,
+ Int32 *perm,
+ UChar *length,
+ Int32 minLen,
+ Int32 maxLen,
+ Int32 alphaSize )
+{
+ Int32 pp, i, j, vec;
+
+ pp = 0;
+ for (i = minLen; i <= maxLen; i++)
+ for (j = 0; j < alphaSize; j++)
+ if (length[j] == i) { perm[pp] = j; pp++; };
+
+ for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
+ for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
+
+ for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
+
+ for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
+ vec = 0;
+
+ for (i = minLen; i <= maxLen; i++) {
+ vec += (base[i+1] - base[i]);
+ limit[i] = vec-1;
+ vec <<= 1;
+ }
+ for (i = minLen + 1; i <= maxLen; i++)
+ base[i] = ((limit[i-1] + 1) << 1) - base[i];
+}
+
+
+/*-------------------------------------------------------------*/
+/*--- end huffman.c ---*/
+/*-------------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/libbz2.def b/Utilities/cmbzip2/libbz2.def
new file mode 100644
index 0000000000..69fef54bc7
--- /dev/null
+++ b/Utilities/cmbzip2/libbz2.def
@@ -0,0 +1,27 @@
+LIBRARY LIBBZ2
+DESCRIPTION "libbzip2: library for data compression"
+EXPORTS
+ BZ2_bzCompressInit
+ BZ2_bzCompress
+ BZ2_bzCompressEnd
+ BZ2_bzDecompressInit
+ BZ2_bzDecompress
+ BZ2_bzDecompressEnd
+ BZ2_bzReadOpen
+ BZ2_bzReadClose
+ BZ2_bzReadGetUnused
+ BZ2_bzRead
+ BZ2_bzWriteOpen
+ BZ2_bzWrite
+ BZ2_bzWriteClose
+ BZ2_bzWriteClose64
+ BZ2_bzBuffToBuffCompress
+ BZ2_bzBuffToBuffDecompress
+ BZ2_bzlibVersion
+ BZ2_bzopen
+ BZ2_bzdopen
+ BZ2_bzread
+ BZ2_bzwrite
+ BZ2_bzflush
+ BZ2_bzclose
+ BZ2_bzerror
diff --git a/Utilities/cmbzip2/libbz2.dsp b/Utilities/cmbzip2/libbz2.dsp
new file mode 100644
index 0000000000..a21a20f75f
--- /dev/null
+++ b/Utilities/cmbzip2/libbz2.dsp
@@ -0,0 +1,130 @@
+# Microsoft Developer Studio Project File - Name="libbz2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 5.00
+# ** •ÒW‚µ‚È‚¢‚Å‚­‚¾‚³‚¢ **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=libbz2 - Win32 Debug
+!MESSAGE ‚±‚ê‚Í—LŒø‚ÈÒ²¸Ì§²Ù‚Å‚Í‚ ‚è‚Ü‚¹‚ñB ‚±‚ÌÌßÛ¼Þª¸Ä‚ðËÞÙÄÞ‚·‚邽‚ß‚É‚Í NMAKE ‚ðŽg—p‚µ‚Ä‚­‚¾‚³‚¢B
+!MESSAGE [Ò²¸Ì§²Ù‚Ì´¸½Îß°Ä] ºÏÝÄÞ‚ðŽg—p‚µ‚ÄŽÀs‚µ‚Ä‚­‚¾‚³‚¢
+!MESSAGE
+!MESSAGE NMAKE /f "libbz2.mak".
+!MESSAGE
+!MESSAGE NMAKE ‚ÌŽÀsŽž‚É\¬‚ðŽw’è‚Å‚«‚Ü‚·
+!MESSAGE ºÏÝÄÞ ×²Ýã‚ÅϸۂÌÝ’è‚ð’è‹`‚µ‚Ü‚·B—á:
+!MESSAGE
+!MESSAGE NMAKE /f "libbz2.mak" CFG="libbz2 - Win32 Debug"
+!MESSAGE
+!MESSAGE ‘I‘ð‰Â”\‚ÈËÞÙÄÞ Ó°ÄÞ:
+!MESSAGE
+!MESSAGE "libbz2 - Win32 Release" ("Win32 (x86) Dynamic-Link Library" —p)
+!MESSAGE "libbz2 - Win32 Debug" ("Win32 (x86) Dynamic-Link Library" —p)
+!MESSAGE
+
+# Begin Project
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "libbz2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
+# ADD BASE RSC /l 0x411 /d "NDEBUG"
+# ADD RSC /l 0x411 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /out:"libbz2.dll"
+
+!ELSEIF "$(CFG)" == "libbz2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
+# ADD BASE RSC /l 0x411 /d "_DEBUG"
+# ADD RSC /l 0x411 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"libbz2.dll" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "libbz2 - Win32 Release"
+# Name "libbz2 - Win32 Debug"
+# Begin Source File
+
+SOURCE=.\blocksort.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\bzlib.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\bzlib.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\bzlib_private.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\compress.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\crctable.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\decompress.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\huffman.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\libbz2.def
+# End Source File
+# Begin Source File
+
+SOURCE=.\randtable.c
+# End Source File
+# End Target
+# End Project
diff --git a/Utilities/cmbzip2/libbz2.lib b/Utilities/cmbzip2/libbz2.lib
new file mode 100644
index 0000000000..9a97a75e24
--- /dev/null
+++ b/Utilities/cmbzip2/libbz2.lib
Binary files differ
diff --git a/Utilities/cmbzip2/makefile.msc b/Utilities/cmbzip2/makefile.msc
new file mode 100644
index 0000000000..d5f2e59303
--- /dev/null
+++ b/Utilities/cmbzip2/makefile.msc
@@ -0,0 +1,63 @@
+# Makefile for Microsoft Visual C++ 6.0
+# usage: nmake -f makefile.msc
+# K.M. Syring (syring@gsf.de)
+# Fixed up by JRS for bzip2-0.9.5d release.
+
+CC=cl
+CFLAGS= -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo
+
+OBJS= blocksort.obj \
+ huffman.obj \
+ crctable.obj \
+ randtable.obj \
+ compress.obj \
+ decompress.obj \
+ bzlib.obj
+
+all: lib bzip2 test
+
+bzip2: lib
+ $(CC) $(CFLAGS) -o bzip2 bzip2.c libbz2.lib setargv.obj
+ $(CC) $(CFLAGS) -o bzip2recover bzip2recover.c
+
+lib: $(OBJS)
+ lib /out:libbz2.lib $(OBJS)
+
+test: bzip2
+ type words1
+ .\\bzip2 -1 < sample1.ref > sample1.rb2
+ .\\bzip2 -2 < sample2.ref > sample2.rb2
+ .\\bzip2 -3 < sample3.ref > sample3.rb2
+ .\\bzip2 -d < sample1.bz2 > sample1.tst
+ .\\bzip2 -d < sample2.bz2 > sample2.tst
+ .\\bzip2 -ds < sample3.bz2 > sample3.tst
+ @echo All six of the fc's should find no differences.
+ @echo If fc finds an error on sample3.bz2, this could be
+ @echo because WinZip's 'TAR file smart CR/LF conversion'
+ @echo is too clever for its own good. Disable this option.
+ @echo The correct size for sample3.ref is 120,244. If it
+ @echo is 150,251, WinZip has messed it up.
+ fc sample1.bz2 sample1.rb2
+ fc sample2.bz2 sample2.rb2
+ fc sample3.bz2 sample3.rb2
+ fc sample1.tst sample1.ref
+ fc sample2.tst sample2.ref
+ fc sample3.tst sample3.ref
+
+
+
+clean:
+ del *.obj
+ del libbz2.lib
+ del bzip2.exe
+ del bzip2recover.exe
+ del sample1.rb2
+ del sample2.rb2
+ del sample3.rb2
+ del sample1.tst
+ del sample2.tst
+ del sample3.tst
+
+.c.obj:
+ $(CC) $(CFLAGS) -c $*.c -o $*.obj
+
diff --git a/Utilities/cmbzip2/manual.html b/Utilities/cmbzip2/manual.html
new file mode 100644
index 0000000000..bb4495385b
--- /dev/null
+++ b/Utilities/cmbzip2/manual.html
@@ -0,0 +1,2540 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>bzip2 and libbzip2, version 1.0.5</title>
+<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
+<style type="text/css" media="screen">/* Colours:
+#74240f dark brown h1, h2, h3, h4
+#336699 medium blue links
+#339999 turquoise link hover colour
+#202020 almost black general text
+#761596 purple md5sum text
+#626262 dark gray pre border
+#eeeeee very light gray pre background
+#f2f2f9 very light blue nav table background
+#3366cc medium blue nav table border
+*/
+
+a, a:link, a:visited, a:active { color: #336699; }
+a:hover { color: #339999; }
+
+body { font: 80%/126% sans-serif; }
+h1, h2, h3, h4 { color: #74240f; }
+
+dt { color: #336699; font-weight: bold }
+dd {
+ margin-left: 1.5em;
+ padding-bottom: 0.8em;
+}
+
+/* -- ruler -- */
+div.hr_blue {
+ height: 3px;
+ background:#ffffff url("/images/hr_blue.png") repeat-x; }
+div.hr_blue hr { display:none; }
+
+/* release styles */
+#release p { margin-top: 0.4em; }
+#release .md5sum { color: #761596; }
+
+
+/* ------ styles for docs|manuals|howto ------ */
+/* -- lists -- */
+ul {
+ margin: 0px 4px 16px 16px;
+ padding: 0px;
+ list-style: url("/images/li-blue.png");
+}
+ul li {
+ margin-bottom: 10px;
+}
+ul ul {
+ list-style-type: none;
+ list-style-image: none;
+ margin-left: 0px;
+}
+
+/* header / footer nav tables */
+table.nav {
+ border: solid 1px #3366cc;
+ background: #f2f2f9;
+ background-color: #f2f2f9;
+ margin-bottom: 0.5em;
+}
+/* don't have underlined links in chunked nav menus */
+table.nav a { text-decoration: none; }
+table.nav a:hover { text-decoration: underline; }
+table.nav td { font-size: 85%; }
+
+code, tt, pre { font-size: 120%; }
+code, tt { color: #761596; }
+
+div.literallayout, pre.programlisting, pre.screen {
+ color: #000000;
+ padding: 0.5em;
+ background: #eeeeee;
+ border: 1px solid #626262;
+ background-color: #eeeeee;
+ margin: 4px 0px 4px 0px;
+}
+</style>
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" lang="en">
+<div class="titlepage">
+<div>
+<div><h1 class="title">
+<a name="userman"></a>bzip2 and libbzip2, version 1.0.5</h1></div>
+<div><h2 class="subtitle">A program and library for data compression</h2></div>
+<div><div class="authorgroup"><div class="author">
+<h3 class="author">
+<span class="firstname">Julian</span> <span class="surname">Seward</span>
+</h3>
+<div class="affiliation"><span class="orgname">http://www.bzip.org<br></span></div>
+</div></div></div>
+<div><p class="releaseinfo">Version 1.0.5 of 10 December 2007</p></div>
+<div><p class="copyright">Copyright © 1996-2007 Julian Seward</p></div>
+<div><div class="legalnotice">
+<a name="id2499833"></a><p>This program, <code class="computeroutput">bzip2</code>, the
+ associated library <code class="computeroutput">libbzip2</code>, and
+ all documentation, are copyright © 1996-2007 Julian Seward.
+ All rights reserved.</p>
+<p>Redistribution and use in source and binary forms, with
+ or without modification, are permitted provided that the
+ following conditions are met:</p>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc"><p>Redistributions of source code must retain the
+ above copyright notice, this list of conditions and the
+ following disclaimer.</p></li>
+<li style="list-style-type: disc"><p>The origin of this software must not be
+ misrepresented; you must not claim that you wrote the original
+ software. If you use this software in a product, an
+ acknowledgment in the product documentation would be
+ appreciated but is not required.</p></li>
+<li style="list-style-type: disc"><p>Altered source versions must be plainly marked
+ as such, and must not be misrepresented as being the original
+ software.</p></li>
+<li style="list-style-type: disc"><p>The name of the author may not be used to
+ endorse or promote products derived from this software without
+ specific prior written permission.</p></li>
+</ul></div>
+<p>THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 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.</p>
+<p>PATENTS: To the best of my knowledge,
+ <code class="computeroutput">bzip2</code> and
+ <code class="computeroutput">libbzip2</code> do not use any patented
+ algorithms. However, I do not have the resources to carry
+ out a patent search. Therefore I cannot give any guarantee of
+ the above statement.
+ </p>
+</div></div>
+</div>
+<hr>
+</div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="chapter"><a href="#intro">1. Introduction</a></span></dt>
+<dt><span class="chapter"><a href="#using">2. How to use bzip2</a></span></dt>
+<dd><dl>
+<dt><span class="sect1"><a href="#name">2.1. NAME</a></span></dt>
+<dt><span class="sect1"><a href="#synopsis">2.2. SYNOPSIS</a></span></dt>
+<dt><span class="sect1"><a href="#description">2.3. DESCRIPTION</a></span></dt>
+<dt><span class="sect1"><a href="#options">2.4. OPTIONS</a></span></dt>
+<dt><span class="sect1"><a href="#memory-management">2.5. MEMORY MANAGEMENT</a></span></dt>
+<dt><span class="sect1"><a href="#recovering">2.6. RECOVERING DATA FROM DAMAGED FILES</a></span></dt>
+<dt><span class="sect1"><a href="#performance">2.7. PERFORMANCE NOTES</a></span></dt>
+<dt><span class="sect1"><a href="#caveats">2.8. CAVEATS</a></span></dt>
+<dt><span class="sect1"><a href="#author">2.9. AUTHOR</a></span></dt>
+</dl></dd>
+<dt><span class="chapter"><a href="#libprog">3.
+Programming with <code class="computeroutput">libbzip2</code>
+</a></span></dt>
+<dd><dl>
+<dt><span class="sect1"><a href="#top-level">3.1. Top-level structure</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#ll-summary">3.1.1. Low-level summary</a></span></dt>
+<dt><span class="sect2"><a href="#hl-summary">3.1.2. High-level summary</a></span></dt>
+<dt><span class="sect2"><a href="#util-fns-summary">3.1.3. Utility functions summary</a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#err-handling">3.2. Error handling</a></span></dt>
+<dt><span class="sect1"><a href="#low-level">3.3. Low-level interface</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#bzcompress-init">3.3.1. <code class="computeroutput">BZ2_bzCompressInit</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzCompress">3.3.2. <code class="computeroutput">BZ2_bzCompress</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzCompress-end">3.3.3. <code class="computeroutput">BZ2_bzCompressEnd</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzDecompress-init">3.3.4. <code class="computeroutput">BZ2_bzDecompressInit</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzDecompress">3.3.5. <code class="computeroutput">BZ2_bzDecompress</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzDecompress-end">3.3.6. <code class="computeroutput">BZ2_bzDecompressEnd</code></a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#hl-interface">3.4. High-level interface</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#bzreadopen">3.4.1. <code class="computeroutput">BZ2_bzReadOpen</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzread">3.4.2. <code class="computeroutput">BZ2_bzRead</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzreadgetunused">3.4.3. <code class="computeroutput">BZ2_bzReadGetUnused</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzreadclose">3.4.4. <code class="computeroutput">BZ2_bzReadClose</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzwriteopen">3.4.5. <code class="computeroutput">BZ2_bzWriteOpen</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzwrite">3.4.6. <code class="computeroutput">BZ2_bzWrite</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzwriteclose">3.4.7. <code class="computeroutput">BZ2_bzWriteClose</code></a></span></dt>
+<dt><span class="sect2"><a href="#embed">3.4.8. Handling embedded compressed data streams</a></span></dt>
+<dt><span class="sect2"><a href="#std-rdwr">3.4.9. Standard file-reading/writing code</a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#util-fns">3.5. Utility functions</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#bzbufftobuffcompress">3.5.1. <code class="computeroutput">BZ2_bzBuffToBuffCompress</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzbufftobuffdecompress">3.5.2. <code class="computeroutput">BZ2_bzBuffToBuffDecompress</code></a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#zlib-compat">3.6. <code class="computeroutput">zlib</code> compatibility functions</a></span></dt>
+<dt><span class="sect1"><a href="#stdio-free">3.7. Using the library in a <code class="computeroutput">stdio</code>-free environment</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#stdio-bye">3.7.1. Getting rid of <code class="computeroutput">stdio</code></a></span></dt>
+<dt><span class="sect2"><a href="#critical-error">3.7.2. Critical error handling</a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#win-dll">3.8. Making a Windows DLL</a></span></dt>
+</dl></dd>
+<dt><span class="chapter"><a href="#misc">4. Miscellanea</a></span></dt>
+<dd><dl>
+<dt><span class="sect1"><a href="#limits">4.1. Limitations of the compressed file format</a></span></dt>
+<dt><span class="sect1"><a href="#port-issues">4.2. Portability issues</a></span></dt>
+<dt><span class="sect1"><a href="#bugs">4.3. Reporting bugs</a></span></dt>
+<dt><span class="sect1"><a href="#package">4.4. Did you get the right package?</a></span></dt>
+<dt><span class="sect1"><a href="#reading">4.5. Further Reading</a></span></dt>
+</dl></dd>
+</dl>
+</div>
+<div class="chapter" lang="en">
+<div class="titlepage"><div><div><h2 class="title">
+<a name="intro"></a>1. Introduction</h2></div></div></div>
+<p><code class="computeroutput">bzip2</code> compresses files
+using the Burrows-Wheeler block-sorting text compression
+algorithm, and Huffman coding. Compression is generally
+considerably better than that achieved by more conventional
+LZ77/LZ78-based compressors, and approaches the performance of
+the PPM family of statistical compressors.</p>
+<p><code class="computeroutput">bzip2</code> is built on top of
+<code class="computeroutput">libbzip2</code>, a flexible library for
+handling compressed data in the
+<code class="computeroutput">bzip2</code> format. This manual
+describes both how to use the program and how to work with the
+library interface. Most of the manual is devoted to this
+library, not the program, which is good news if your interest is
+only in the program.</p>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc"><p><a href="#using">How to use bzip2</a> describes how to use
+ <code class="computeroutput">bzip2</code>; this is the only part
+ you need to read if you just want to know how to operate the
+ program.</p></li>
+<li style="list-style-type: disc"><p><a href="#libprog">Programming with libbzip2</a> describes the
+ programming interfaces in detail, and</p></li>
+<li style="list-style-type: disc"><p><a href="#misc">Miscellanea</a> records some
+ miscellaneous notes which I thought ought to be recorded
+ somewhere.</p></li>
+</ul></div>
+</div>
+<div class="chapter" lang="en">
+<div class="titlepage"><div><div><h2 class="title">
+<a name="using"></a>2. How to use bzip2</h2></div></div></div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="sect1"><a href="#name">2.1. NAME</a></span></dt>
+<dt><span class="sect1"><a href="#synopsis">2.2. SYNOPSIS</a></span></dt>
+<dt><span class="sect1"><a href="#description">2.3. DESCRIPTION</a></span></dt>
+<dt><span class="sect1"><a href="#options">2.4. OPTIONS</a></span></dt>
+<dt><span class="sect1"><a href="#memory-management">2.5. MEMORY MANAGEMENT</a></span></dt>
+<dt><span class="sect1"><a href="#recovering">2.6. RECOVERING DATA FROM DAMAGED FILES</a></span></dt>
+<dt><span class="sect1"><a href="#performance">2.7. PERFORMANCE NOTES</a></span></dt>
+<dt><span class="sect1"><a href="#caveats">2.8. CAVEATS</a></span></dt>
+<dt><span class="sect1"><a href="#author">2.9. AUTHOR</a></span></dt>
+</dl>
+</div>
+<p>This chapter contains a copy of the
+<code class="computeroutput">bzip2</code> man page, and nothing
+else.</p>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="name"></a>2.1. NAME</h2></div></div></div>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc"><p><code class="computeroutput">bzip2</code>,
+ <code class="computeroutput">bunzip2</code> - a block-sorting file
+ compressor, v1.0.4</p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">bzcat</code> -
+ decompresses files to stdout</p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">bzip2recover</code> -
+ recovers data from damaged bzip2 files</p></li>
+</ul></div>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="synopsis"></a>2.2. SYNOPSIS</h2></div></div></div>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc"><p><code class="computeroutput">bzip2</code> [
+ -cdfkqstvzVL123456789 ] [ filenames ... ]</p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">bunzip2</code> [
+ -fkvsVL ] [ filenames ... ]</p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">bzcat</code> [ -s ] [
+ filenames ... ]</p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">bzip2recover</code>
+ filename</p></li>
+</ul></div>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="description"></a>2.3. DESCRIPTION</h2></div></div></div>
+<p><code class="computeroutput">bzip2</code> compresses files
+using the Burrows-Wheeler block sorting text compression
+algorithm, and Huffman coding. Compression is generally
+considerably better than that achieved by more conventional
+LZ77/LZ78-based compressors, and approaches the performance of
+the PPM family of statistical compressors.</p>
+<p>The command-line options are deliberately very similar to
+those of GNU <code class="computeroutput">gzip</code>, but they are
+not identical.</p>
+<p><code class="computeroutput">bzip2</code> expects a list of
+file names to accompany the command-line flags. Each file is
+replaced by a compressed version of itself, with the name
+<code class="computeroutput">original_name.bz2</code>. Each
+compressed file has the same modification date, permissions, and,
+when possible, ownership as the corresponding original, so that
+these properties can be correctly restored at decompression time.
+File name handling is naive in the sense that there is no
+mechanism for preserving original file names, permissions,
+ownerships or dates in filesystems which lack these concepts, or
+have serious file name length restrictions, such as
+MS-DOS.</p>
+<p><code class="computeroutput">bzip2</code> and
+<code class="computeroutput">bunzip2</code> will by default not
+overwrite existing files. If you want this to happen, specify
+the <code class="computeroutput">-f</code> flag.</p>
+<p>If no file names are specified,
+<code class="computeroutput">bzip2</code> compresses from standard
+input to standard output. In this case,
+<code class="computeroutput">bzip2</code> will decline to write
+compressed output to a terminal, as this would be entirely
+incomprehensible and therefore pointless.</p>
+<p><code class="computeroutput">bunzip2</code> (or
+<code class="computeroutput">bzip2 -d</code>) decompresses all
+specified files. Files which were not created by
+<code class="computeroutput">bzip2</code> will be detected and
+ignored, and a warning issued.
+<code class="computeroutput">bzip2</code> attempts to guess the
+filename for the decompressed file from that of the compressed
+file as follows:</p>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc"><p><code class="computeroutput">filename.bz2 </code>
+ becomes
+ <code class="computeroutput">filename</code></p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">filename.bz </code>
+ becomes
+ <code class="computeroutput">filename</code></p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">filename.tbz2</code>
+ becomes
+ <code class="computeroutput">filename.tar</code></p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">filename.tbz </code>
+ becomes
+ <code class="computeroutput">filename.tar</code></p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">anyothername </code>
+ becomes
+ <code class="computeroutput">anyothername.out</code></p></li>
+</ul></div>
+<p>If the file does not end in one of the recognised endings,
+<code class="computeroutput">.bz2</code>,
+<code class="computeroutput">.bz</code>,
+<code class="computeroutput">.tbz2</code> or
+<code class="computeroutput">.tbz</code>,
+<code class="computeroutput">bzip2</code> complains that it cannot
+guess the name of the original file, and uses the original name
+with <code class="computeroutput">.out</code> appended.</p>
+<p>As with compression, supplying no filenames causes
+decompression from standard input to standard output.</p>
+<p><code class="computeroutput">bunzip2</code> will correctly
+decompress a file which is the concatenation of two or more
+compressed files. The result is the concatenation of the
+corresponding uncompressed files. Integrity testing
+(<code class="computeroutput">-t</code>) of concatenated compressed
+files is also supported.</p>
+<p>You can also compress or decompress files to the standard
+output by giving the <code class="computeroutput">-c</code> flag.
+Multiple files may be compressed and decompressed like this. The
+resulting outputs are fed sequentially to stdout. Compression of
+multiple files in this manner generates a stream containing
+multiple compressed file representations. Such a stream can be
+decompressed correctly only by
+<code class="computeroutput">bzip2</code> version 0.9.0 or later.
+Earlier versions of <code class="computeroutput">bzip2</code> will
+stop after decompressing the first file in the stream.</p>
+<p><code class="computeroutput">bzcat</code> (or
+<code class="computeroutput">bzip2 -dc</code>) decompresses all
+specified files to the standard output.</p>
+<p><code class="computeroutput">bzip2</code> will read arguments
+from the environment variables
+<code class="computeroutput">BZIP2</code> and
+<code class="computeroutput">BZIP</code>, in that order, and will
+process them before any arguments read from the command line.
+This gives a convenient way to supply default arguments.</p>
+<p>Compression is always performed, even if the compressed
+file is slightly larger than the original. Files of less than
+about one hundred bytes tend to get larger, since the compression
+mechanism has a constant overhead in the region of 50 bytes.
+Random data (including the output of most file compressors) is
+coded at about 8.05 bits per byte, giving an expansion of around
+0.5%.</p>
+<p>As a self-check for your protection,
+<code class="computeroutput">bzip2</code> uses 32-bit CRCs to make
+sure that the decompressed version of a file is identical to the
+original. This guards against corruption of the compressed data,
+and against undetected bugs in
+<code class="computeroutput">bzip2</code> (hopefully very unlikely).
+The chances of data corruption going undetected is microscopic,
+about one chance in four billion for each file processed. Be
+aware, though, that the check occurs upon decompression, so it
+can only tell you that something is wrong. It can't help you
+recover the original uncompressed data. You can use
+<code class="computeroutput">bzip2recover</code> to try to recover
+data from damaged files.</p>
+<p>Return values: 0 for a normal exit, 1 for environmental
+problems (file not found, invalid flags, I/O errors, etc.), 2
+to indicate a corrupt compressed file, 3 for an internal
+consistency error (eg, bug) which caused
+<code class="computeroutput">bzip2</code> to panic.</p>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="options"></a>2.4. OPTIONS</h2></div></div></div>
+<div class="variablelist"><dl>
+<dt><span class="term"><code class="computeroutput">-c --stdout</code></span></dt>
+<dd><p>Compress or decompress to standard
+ output.</p></dd>
+<dt><span class="term"><code class="computeroutput">-d --decompress</code></span></dt>
+<dd><p>Force decompression.
+ <code class="computeroutput">bzip2</code>,
+ <code class="computeroutput">bunzip2</code> and
+ <code class="computeroutput">bzcat</code> are really the same
+ program, and the decision about what actions to take is done on
+ the basis of which name is used. This flag overrides that
+ mechanism, and forces bzip2 to decompress.</p></dd>
+<dt><span class="term"><code class="computeroutput">-z --compress</code></span></dt>
+<dd><p>The complement to
+ <code class="computeroutput">-d</code>: forces compression,
+ regardless of the invokation name.</p></dd>
+<dt><span class="term"><code class="computeroutput">-t --test</code></span></dt>
+<dd><p>Check integrity of the specified file(s), but
+ don't decompress them. This really performs a trial
+ decompression and throws away the result.</p></dd>
+<dt><span class="term"><code class="computeroutput">-f --force</code></span></dt>
+<dd>
+<p>Force overwrite of output files. Normally,
+ <code class="computeroutput">bzip2</code> will not overwrite
+ existing output files. Also forces
+ <code class="computeroutput">bzip2</code> to break hard links to
+ files, which it otherwise wouldn't do.</p>
+<p><code class="computeroutput">bzip2</code> normally declines
+ to decompress files which don't have the correct magic header
+ bytes. If forced (<code class="computeroutput">-f</code>),
+ however, it will pass such files through unmodified. This is
+ how GNU <code class="computeroutput">gzip</code> behaves.</p>
+</dd>
+<dt><span class="term"><code class="computeroutput">-k --keep</code></span></dt>
+<dd><p>Keep (don't delete) input files during
+ compression or decompression.</p></dd>
+<dt><span class="term"><code class="computeroutput">-s --small</code></span></dt>
+<dd>
+<p>Reduce memory usage, for compression,
+ decompression and testing. Files are decompressed and tested
+ using a modified algorithm which only requires 2.5 bytes per
+ block byte. This means any file can be decompressed in 2300k
+ of memory, albeit at about half the normal speed.</p>
+<p>During compression, <code class="computeroutput">-s</code>
+ selects a block size of 200k, which limits memory use to around
+ the same figure, at the expense of your compression ratio. In
+ short, if your machine is low on memory (8 megabytes or less),
+ use <code class="computeroutput">-s</code> for everything. See
+ <a href="#memory-management">MEMORY MANAGEMENT</a> below.</p>
+</dd>
+<dt><span class="term"><code class="computeroutput">-q --quiet</code></span></dt>
+<dd><p>Suppress non-essential warning messages.
+ Messages pertaining to I/O errors and other critical events
+ will not be suppressed.</p></dd>
+<dt><span class="term"><code class="computeroutput">-v --verbose</code></span></dt>
+<dd><p>Verbose mode -- show the compression ratio for
+ each file processed. Further
+ <code class="computeroutput">-v</code>'s increase the verbosity
+ level, spewing out lots of information which is primarily of
+ interest for diagnostic purposes.</p></dd>
+<dt><span class="term"><code class="computeroutput">-L --license -V --version</code></span></dt>
+<dd><p>Display the software version, license terms and
+ conditions.</p></dd>
+<dt><span class="term"><code class="computeroutput">-1</code> (or
+ <code class="computeroutput">--fast</code>) to
+ <code class="computeroutput">-9</code> (or
+ <code class="computeroutput">-best</code>)</span></dt>
+<dd><p>Set the block size to 100 k, 200 k ... 900 k
+ when compressing. Has no effect when decompressing. See <a href="#memory-management">MEMORY MANAGEMENT</a> below. The
+ <code class="computeroutput">--fast</code> and
+ <code class="computeroutput">--best</code> aliases are primarily
+ for GNU <code class="computeroutput">gzip</code> compatibility.
+ In particular, <code class="computeroutput">--fast</code> doesn't
+ make things significantly faster. And
+ <code class="computeroutput">--best</code> merely selects the
+ default behaviour.</p></dd>
+<dt><span class="term"><code class="computeroutput">--</code></span></dt>
+<dd><p>Treats all subsequent arguments as file names,
+ even if they start with a dash. This is so you can handle
+ files with names beginning with a dash, for example:
+ <code class="computeroutput">bzip2 --
+ -myfilename</code>.</p></dd>
+<dt>
+<span class="term"><code class="computeroutput">--repetitive-fast</code>, </span><span class="term"><code class="computeroutput">--repetitive-best</code></span>
+</dt>
+<dd><p>These flags are redundant in versions 0.9.5 and
+ above. They provided some coarse control over the behaviour of
+ the sorting algorithm in earlier versions, which was sometimes
+ useful. 0.9.5 and above have an improved algorithm which
+ renders these flags irrelevant.</p></dd>
+</dl></div>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="memory-management"></a>2.5. MEMORY MANAGEMENT</h2></div></div></div>
+<p><code class="computeroutput">bzip2</code> compresses large
+files in blocks. The block size affects both the compression
+ratio achieved, and the amount of memory needed for compression
+and decompression. The flags <code class="computeroutput">-1</code>
+through <code class="computeroutput">-9</code> specify the block
+size to be 100,000 bytes through 900,000 bytes (the default)
+respectively. At decompression time, the block size used for
+compression is read from the header of the compressed file, and
+<code class="computeroutput">bunzip2</code> then allocates itself
+just enough memory to decompress the file. Since block sizes are
+stored in compressed files, it follows that the flags
+<code class="computeroutput">-1</code> to
+<code class="computeroutput">-9</code> are irrelevant to and so
+ignored during decompression.</p>
+<p>Compression and decompression requirements, in bytes, can be
+estimated as:</p>
+<pre class="programlisting">Compression: 400k + ( 8 x block size )
+
+Decompression: 100k + ( 4 x block size ), or
+ 100k + ( 2.5 x block size )</pre>
+<p>Larger block sizes give rapidly diminishing marginal
+returns. Most of the compression comes from the first two or
+three hundred k of block size, a fact worth bearing in mind when
+using <code class="computeroutput">bzip2</code> on small machines.
+It is also important to appreciate that the decompression memory
+requirement is set at compression time by the choice of block
+size.</p>
+<p>For files compressed with the default 900k block size,
+<code class="computeroutput">bunzip2</code> will require about 3700
+kbytes to decompress. To support decompression of any file on a
+4 megabyte machine, <code class="computeroutput">bunzip2</code> has
+an option to decompress using approximately half this amount of
+memory, about 2300 kbytes. Decompression speed is also halved,
+so you should use this option only where necessary. The relevant
+flag is <code class="computeroutput">-s</code>.</p>
+<p>In general, try and use the largest block size memory
+constraints allow, since that maximises the compression achieved.
+Compression and decompression speed are virtually unaffected by
+block size.</p>
+<p>Another significant point applies to files which fit in a
+single block -- that means most files you'd encounter using a
+large block size. The amount of real memory touched is
+proportional to the size of the file, since the file is smaller
+than a block. For example, compressing a file 20,000 bytes long
+with the flag <code class="computeroutput">-9</code> will cause the
+compressor to allocate around 7600k of memory, but only touch
+400k + 20000 * 8 = 560 kbytes of it. Similarly, the decompressor
+will allocate 3700k but only touch 100k + 20000 * 4 = 180
+kbytes.</p>
+<p>Here is a table which summarises the maximum memory usage
+for different block sizes. Also recorded is the total compressed
+size for 14 files of the Calgary Text Compression Corpus
+totalling 3,141,622 bytes. This column gives some feel for how
+compression varies with block size. These figures tend to
+understate the advantage of larger block sizes for larger files,
+since the Corpus is dominated by smaller files.</p>
+<pre class="programlisting"> Compress Decompress Decompress Corpus
+Flag usage usage -s usage Size
+
+ -1 1200k 500k 350k 914704
+ -2 2000k 900k 600k 877703
+ -3 2800k 1300k 850k 860338
+ -4 3600k 1700k 1100k 846899
+ -5 4400k 2100k 1350k 845160
+ -6 5200k 2500k 1600k 838626
+ -7 6100k 2900k 1850k 834096
+ -8 6800k 3300k 2100k 828642
+ -9 7600k 3700k 2350k 828642</pre>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="recovering"></a>2.6. RECOVERING DATA FROM DAMAGED FILES</h2></div></div></div>
+<p><code class="computeroutput">bzip2</code> compresses files in
+blocks, usually 900kbytes long. Each block is handled
+independently. If a media or transmission error causes a
+multi-block <code class="computeroutput">.bz2</code> file to become
+damaged, it may be possible to recover data from the undamaged
+blocks in the file.</p>
+<p>The compressed representation of each block is delimited by
+a 48-bit pattern, which makes it possible to find the block
+boundaries with reasonable certainty. Each block also carries
+its own 32-bit CRC, so damaged blocks can be distinguished from
+undamaged ones.</p>
+<p><code class="computeroutput">bzip2recover</code> is a simple
+program whose purpose is to search for blocks in
+<code class="computeroutput">.bz2</code> files, and write each block
+out into its own <code class="computeroutput">.bz2</code> file. You
+can then use <code class="computeroutput">bzip2 -t</code> to test
+the integrity of the resulting files, and decompress those which
+are undamaged.</p>
+<p><code class="computeroutput">bzip2recover</code> takes a
+single argument, the name of the damaged file, and writes a
+number of files <code class="computeroutput">rec0001file.bz2</code>,
+<code class="computeroutput">rec0002file.bz2</code>, etc, containing
+the extracted blocks. The output filenames are designed so that
+the use of wildcards in subsequent processing -- for example,
+<code class="computeroutput">bzip2 -dc rec*file.bz2 &gt;
+recovered_data</code> -- lists the files in the correct
+order.</p>
+<p><code class="computeroutput">bzip2recover</code> should be of
+most use dealing with large <code class="computeroutput">.bz2</code>
+files, as these will contain many blocks. It is clearly futile
+to use it on damaged single-block files, since a damaged block
+cannot be recovered. If you wish to minimise any potential data
+loss through media or transmission errors, you might consider
+compressing with a smaller block size.</p>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="performance"></a>2.7. PERFORMANCE NOTES</h2></div></div></div>
+<p>The sorting phase of compression gathers together similar
+strings in the file. Because of this, files containing very long
+runs of repeated symbols, like "aabaabaabaab ..." (repeated
+several hundred times) may compress more slowly than normal.
+Versions 0.9.5 and above fare much better than previous versions
+in this respect. The ratio between worst-case and average-case
+compression time is in the region of 10:1. For previous
+versions, this figure was more like 100:1. You can use the
+<code class="computeroutput">-vvvv</code> option to monitor progress
+in great detail, if you want.</p>
+<p>Decompression speed is unaffected by these
+phenomena.</p>
+<p><code class="computeroutput">bzip2</code> usually allocates
+several megabytes of memory to operate in, and then charges all
+over it in a fairly random fashion. This means that performance,
+both for compressing and decompressing, is largely determined by
+the speed at which your machine can service cache misses.
+Because of this, small changes to the code to reduce the miss
+rate have been observed to give disproportionately large
+performance improvements. I imagine
+<code class="computeroutput">bzip2</code> will perform best on
+machines with very large caches.</p>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="caveats"></a>2.8. CAVEATS</h2></div></div></div>
+<p>I/O error messages are not as helpful as they could be.
+<code class="computeroutput">bzip2</code> tries hard to detect I/O
+errors and exit cleanly, but the details of what the problem is
+sometimes seem rather misleading.</p>
+<p>This manual page pertains to version 1.0.5 of
+<code class="computeroutput">bzip2</code>. Compressed data created by
+this version is entirely forwards and backwards compatible with the
+previous public releases, versions 0.1pl2, 0.9.0 and 0.9.5, 1.0.0,
+1.0.1, 1.0.2 and 1.0.3, but with the following exception: 0.9.0 and
+above can correctly decompress multiple concatenated compressed files.
+0.1pl2 cannot do this; it will stop after decompressing just the first
+file in the stream.</p>
+<p><code class="computeroutput">bzip2recover</code> versions
+prior to 1.0.2 used 32-bit integers to represent bit positions in
+compressed files, so it could not handle compressed files more
+than 512 megabytes long. Versions 1.0.2 and above use 64-bit ints
+on some platforms which support them (GNU supported targets, and
+Windows). To establish whether or not
+<code class="computeroutput">bzip2recover</code> was built with such
+a limitation, run it without arguments. In any event you can
+build yourself an unlimited version if you can recompile it with
+<code class="computeroutput">MaybeUInt64</code> set to be an
+unsigned 64-bit integer.</p>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="author"></a>2.9. AUTHOR</h2></div></div></div>
+<p>Julian Seward,
+<code class="computeroutput">jseward@bzip.org</code></p>
+<p>The ideas embodied in
+<code class="computeroutput">bzip2</code> are due to (at least) the
+following people: Michael Burrows and David Wheeler (for the
+block sorting transformation), David Wheeler (again, for the
+Huffman coder), Peter Fenwick (for the structured coding model in
+the original <code class="computeroutput">bzip</code>, and many
+refinements), and Alistair Moffat, Radford Neal and Ian Witten
+(for the arithmetic coder in the original
+<code class="computeroutput">bzip</code>). I am much indebted for
+their help, support and advice. See the manual in the source
+distribution for pointers to sources of documentation. Christian
+von Roques encouraged me to look for faster sorting algorithms,
+so as to speed up compression. Bela Lubkin encouraged me to
+improve the worst-case compression performance.
+Donna Robinson XMLised the documentation.
+Many people sent
+patches, helped with portability problems, lent machines, gave
+advice and were generally helpful.</p>
+</div>
+</div>
+<div class="chapter" lang="en">
+<div class="titlepage"><div><div><h2 class="title">
+<a name="libprog"></a>3. 
+Programming with <code class="computeroutput">libbzip2</code>
+</h2></div></div></div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="sect1"><a href="#top-level">3.1. Top-level structure</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#ll-summary">3.1.1. Low-level summary</a></span></dt>
+<dt><span class="sect2"><a href="#hl-summary">3.1.2. High-level summary</a></span></dt>
+<dt><span class="sect2"><a href="#util-fns-summary">3.1.3. Utility functions summary</a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#err-handling">3.2. Error handling</a></span></dt>
+<dt><span class="sect1"><a href="#low-level">3.3. Low-level interface</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#bzcompress-init">3.3.1. <code class="computeroutput">BZ2_bzCompressInit</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzCompress">3.3.2. <code class="computeroutput">BZ2_bzCompress</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzCompress-end">3.3.3. <code class="computeroutput">BZ2_bzCompressEnd</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzDecompress-init">3.3.4. <code class="computeroutput">BZ2_bzDecompressInit</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzDecompress">3.3.5. <code class="computeroutput">BZ2_bzDecompress</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzDecompress-end">3.3.6. <code class="computeroutput">BZ2_bzDecompressEnd</code></a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#hl-interface">3.4. High-level interface</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#bzreadopen">3.4.1. <code class="computeroutput">BZ2_bzReadOpen</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzread">3.4.2. <code class="computeroutput">BZ2_bzRead</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzreadgetunused">3.4.3. <code class="computeroutput">BZ2_bzReadGetUnused</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzreadclose">3.4.4. <code class="computeroutput">BZ2_bzReadClose</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzwriteopen">3.4.5. <code class="computeroutput">BZ2_bzWriteOpen</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzwrite">3.4.6. <code class="computeroutput">BZ2_bzWrite</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzwriteclose">3.4.7. <code class="computeroutput">BZ2_bzWriteClose</code></a></span></dt>
+<dt><span class="sect2"><a href="#embed">3.4.8. Handling embedded compressed data streams</a></span></dt>
+<dt><span class="sect2"><a href="#std-rdwr">3.4.9. Standard file-reading/writing code</a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#util-fns">3.5. Utility functions</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#bzbufftobuffcompress">3.5.1. <code class="computeroutput">BZ2_bzBuffToBuffCompress</code></a></span></dt>
+<dt><span class="sect2"><a href="#bzbufftobuffdecompress">3.5.2. <code class="computeroutput">BZ2_bzBuffToBuffDecompress</code></a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#zlib-compat">3.6. <code class="computeroutput">zlib</code> compatibility functions</a></span></dt>
+<dt><span class="sect1"><a href="#stdio-free">3.7. Using the library in a <code class="computeroutput">stdio</code>-free environment</a></span></dt>
+<dd><dl>
+<dt><span class="sect2"><a href="#stdio-bye">3.7.1. Getting rid of <code class="computeroutput">stdio</code></a></span></dt>
+<dt><span class="sect2"><a href="#critical-error">3.7.2. Critical error handling</a></span></dt>
+</dl></dd>
+<dt><span class="sect1"><a href="#win-dll">3.8. Making a Windows DLL</a></span></dt>
+</dl>
+</div>
+<p>This chapter describes the programming interface to
+<code class="computeroutput">libbzip2</code>.</p>
+<p>For general background information, particularly about
+memory use and performance aspects, you'd be well advised to read
+<a href="#using">How to use bzip2</a> as well.</p>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="top-level"></a>3.1. Top-level structure</h2></div></div></div>
+<p><code class="computeroutput">libbzip2</code> is a flexible
+library for compressing and decompressing data in the
+<code class="computeroutput">bzip2</code> data format. Although
+packaged as a single entity, it helps to regard the library as
+three separate parts: the low level interface, and the high level
+interface, and some utility functions.</p>
+<p>The structure of
+<code class="computeroutput">libbzip2</code>'s interfaces is similar
+to that of Jean-loup Gailly's and Mark Adler's excellent
+<code class="computeroutput">zlib</code> library.</p>
+<p>All externally visible symbols have names beginning
+<code class="computeroutput">BZ2_</code>. This is new in version
+1.0. The intention is to minimise pollution of the namespaces of
+library clients.</p>
+<p>To use any part of the library, you need to
+<code class="computeroutput">#include &lt;bzlib.h&gt;</code>
+into your sources.</p>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="ll-summary"></a>3.1.1. Low-level summary</h3></div></div></div>
+<p>This interface provides services for compressing and
+decompressing data in memory. There's no provision for dealing
+with files, streams or any other I/O mechanisms, just straight
+memory-to-memory work. In fact, this part of the library can be
+compiled without inclusion of
+<code class="computeroutput">stdio.h</code>, which may be helpful
+for embedded applications.</p>
+<p>The low-level part of the library has no global variables
+and is therefore thread-safe.</p>
+<p>Six routines make up the low level interface:
+<code class="computeroutput">BZ2_bzCompressInit</code>,
+<code class="computeroutput">BZ2_bzCompress</code>, and
+<code class="computeroutput">BZ2_bzCompressEnd</code> for
+compression, and a corresponding trio
+<code class="computeroutput">BZ2_bzDecompressInit</code>,
+<code class="computeroutput">BZ2_bzDecompress</code> and
+<code class="computeroutput">BZ2_bzDecompressEnd</code> for
+decompression. The <code class="computeroutput">*Init</code>
+functions allocate memory for compression/decompression and do
+other initialisations, whilst the
+<code class="computeroutput">*End</code> functions close down
+operations and release memory.</p>
+<p>The real work is done by
+<code class="computeroutput">BZ2_bzCompress</code> and
+<code class="computeroutput">BZ2_bzDecompress</code>. These
+compress and decompress data from a user-supplied input buffer to
+a user-supplied output buffer. These buffers can be any size;
+arbitrary quantities of data are handled by making repeated calls
+to these functions. This is a flexible mechanism allowing a
+consumer-pull style of activity, or producer-push, or a mixture
+of both.</p>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="hl-summary"></a>3.1.2. High-level summary</h3></div></div></div>
+<p>This interface provides some handy wrappers around the
+low-level interface to facilitate reading and writing
+<code class="computeroutput">bzip2</code> format files
+(<code class="computeroutput">.bz2</code> files). The routines
+provide hooks to facilitate reading files in which the
+<code class="computeroutput">bzip2</code> data stream is embedded
+within some larger-scale file structure, or where there are
+multiple <code class="computeroutput">bzip2</code> data streams
+concatenated end-to-end.</p>
+<p>For reading files,
+<code class="computeroutput">BZ2_bzReadOpen</code>,
+<code class="computeroutput">BZ2_bzRead</code>,
+<code class="computeroutput">BZ2_bzReadClose</code> and
+<code class="computeroutput">BZ2_bzReadGetUnused</code> are
+supplied. For writing files,
+<code class="computeroutput">BZ2_bzWriteOpen</code>,
+<code class="computeroutput">BZ2_bzWrite</code> and
+<code class="computeroutput">BZ2_bzWriteFinish</code> are
+available.</p>
+<p>As with the low-level library, no global variables are used
+so the library is per se thread-safe. However, if I/O errors
+occur whilst reading or writing the underlying compressed files,
+you may have to consult <code class="computeroutput">errno</code> to
+determine the cause of the error. In that case, you'd need a C
+library which correctly supports
+<code class="computeroutput">errno</code> in a multithreaded
+environment.</p>
+<p>To make the library a little simpler and more portable,
+<code class="computeroutput">BZ2_bzReadOpen</code> and
+<code class="computeroutput">BZ2_bzWriteOpen</code> require you to
+pass them file handles (<code class="computeroutput">FILE*</code>s)
+which have previously been opened for reading or writing
+respectively. That avoids portability problems associated with
+file operations and file attributes, whilst not being much of an
+imposition on the programmer.</p>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="util-fns-summary"></a>3.1.3. Utility functions summary</h3></div></div></div>
+<p>For very simple needs,
+<code class="computeroutput">BZ2_bzBuffToBuffCompress</code> and
+<code class="computeroutput">BZ2_bzBuffToBuffDecompress</code> are
+provided. These compress data in memory from one buffer to
+another buffer in a single function call. You should assess
+whether these functions fulfill your memory-to-memory
+compression/decompression requirements before investing effort in
+understanding the more general but more complex low-level
+interface.</p>
+<p>Yoshioka Tsuneo
+(<code class="computeroutput">tsuneo@rr.iij4u.or.jp</code>) has
+contributed some functions to give better
+<code class="computeroutput">zlib</code> compatibility. These
+functions are <code class="computeroutput">BZ2_bzopen</code>,
+<code class="computeroutput">BZ2_bzread</code>,
+<code class="computeroutput">BZ2_bzwrite</code>,
+<code class="computeroutput">BZ2_bzflush</code>,
+<code class="computeroutput">BZ2_bzclose</code>,
+<code class="computeroutput">BZ2_bzerror</code> and
+<code class="computeroutput">BZ2_bzlibVersion</code>. You may find
+these functions more convenient for simple file reading and
+writing, than those in the high-level interface. These functions
+are not (yet) officially part of the library, and are minimally
+documented here. If they break, you get to keep all the pieces.
+I hope to document them properly when time permits.</p>
+<p>Yoshioka also contributed modifications to allow the
+library to be built as a Windows DLL.</p>
+</div>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="err-handling"></a>3.2. Error handling</h2></div></div></div>
+<p>The library is designed to recover cleanly in all
+situations, including the worst-case situation of decompressing
+random data. I'm not 100% sure that it can always do this, so
+you might want to add a signal handler to catch segmentation
+violations during decompression if you are feeling especially
+paranoid. I would be interested in hearing more about the
+robustness of the library to corrupted compressed data.</p>
+<p>Version 1.0.3 more robust in this respect than any
+previous version. Investigations with Valgrind (a tool for detecting
+problems with memory management) indicate
+that, at least for the few files I tested, all single-bit errors
+in the decompressed data are caught properly, with no
+segmentation faults, no uses of uninitialised data, no out of
+range reads or writes, and no infinite looping in the decompressor.
+So it's certainly pretty robust, although
+I wouldn't claim it to be totally bombproof.</p>
+<p>The file <code class="computeroutput">bzlib.h</code> contains
+all definitions needed to use the library. In particular, you
+should definitely not include
+<code class="computeroutput">bzlib_private.h</code>.</p>
+<p>In <code class="computeroutput">bzlib.h</code>, the various
+return values are defined. The following list is not intended as
+an exhaustive description of the circumstances in which a given
+value may be returned -- those descriptions are given later.
+Rather, it is intended to convey the rough meaning of each return
+value. The first five actions are normal and not intended to
+denote an error situation.</p>
+<div class="variablelist"><dl>
+<dt><span class="term"><code class="computeroutput">BZ_OK</code></span></dt>
+<dd><p>The requested action was completed
+ successfully.</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_RUN_OK, BZ_FLUSH_OK,
+ BZ_FINISH_OK</code></span></dt>
+<dd><p>In
+ <code class="computeroutput">BZ2_bzCompress</code>, the requested
+ flush/finish/nothing-special action was completed
+ successfully.</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_STREAM_END</code></span></dt>
+<dd><p>Compression of data was completed, or the
+ logical stream end was detected during
+ decompression.</p></dd>
+</dl></div>
+<p>The following return values indicate an error of some
+kind.</p>
+<div class="variablelist"><dl>
+<dt><span class="term"><code class="computeroutput">BZ_CONFIG_ERROR</code></span></dt>
+<dd><p>Indicates that the library has been improperly
+ compiled on your platform -- a major configuration error.
+ Specifically, it means that
+ <code class="computeroutput">sizeof(char)</code>,
+ <code class="computeroutput">sizeof(short)</code> and
+ <code class="computeroutput">sizeof(int)</code> are not 1, 2 and
+ 4 respectively, as they should be. Note that the library
+ should still work properly on 64-bit platforms which follow
+ the LP64 programming model -- that is, where
+ <code class="computeroutput">sizeof(long)</code> and
+ <code class="computeroutput">sizeof(void*)</code> are 8. Under
+ LP64, <code class="computeroutput">sizeof(int)</code> is still 4,
+ so <code class="computeroutput">libbzip2</code>, which doesn't
+ use the <code class="computeroutput">long</code> type, is
+ OK.</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_SEQUENCE_ERROR</code></span></dt>
+<dd><p>When using the library, it is important to call
+ the functions in the correct sequence and with data structures
+ (buffers etc) in the correct states.
+ <code class="computeroutput">libbzip2</code> checks as much as it
+ can to ensure this is happening, and returns
+ <code class="computeroutput">BZ_SEQUENCE_ERROR</code> if not.
+ Code which complies precisely with the function semantics, as
+ detailed below, should never receive this value; such an event
+ denotes buggy code which you should
+ investigate.</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_PARAM_ERROR</code></span></dt>
+<dd><p>Returned when a parameter to a function call is
+ out of range or otherwise manifestly incorrect. As with
+ <code class="computeroutput">BZ_SEQUENCE_ERROR</code>, this
+ denotes a bug in the client code. The distinction between
+ <code class="computeroutput">BZ_PARAM_ERROR</code> and
+ <code class="computeroutput">BZ_SEQUENCE_ERROR</code> is a bit
+ hazy, but still worth making.</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_MEM_ERROR</code></span></dt>
+<dd><p>Returned when a request to allocate memory
+ failed. Note that the quantity of memory needed to decompress
+ a stream cannot be determined until the stream's header has
+ been read. So
+ <code class="computeroutput">BZ2_bzDecompress</code> and
+ <code class="computeroutput">BZ2_bzRead</code> may return
+ <code class="computeroutput">BZ_MEM_ERROR</code> even though some
+ of the compressed data has been read. The same is not true
+ for compression; once
+ <code class="computeroutput">BZ2_bzCompressInit</code> or
+ <code class="computeroutput">BZ2_bzWriteOpen</code> have
+ successfully completed,
+ <code class="computeroutput">BZ_MEM_ERROR</code> cannot
+ occur.</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_DATA_ERROR</code></span></dt>
+<dd><p>Returned when a data integrity error is
+ detected during decompression. Most importantly, this means
+ when stored and computed CRCs for the data do not match. This
+ value is also returned upon detection of any other anomaly in
+ the compressed data.</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_DATA_ERROR_MAGIC</code></span></dt>
+<dd><p>As a special case of
+ <code class="computeroutput">BZ_DATA_ERROR</code>, it is
+ sometimes useful to know when the compressed stream does not
+ start with the correct magic bytes (<code class="computeroutput">'B' 'Z'
+ 'h'</code>).</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_IO_ERROR</code></span></dt>
+<dd><p>Returned by
+ <code class="computeroutput">BZ2_bzRead</code> and
+ <code class="computeroutput">BZ2_bzWrite</code> when there is an
+ error reading or writing in the compressed file, and by
+ <code class="computeroutput">BZ2_bzReadOpen</code> and
+ <code class="computeroutput">BZ2_bzWriteOpen</code> for attempts
+ to use a file for which the error indicator (viz,
+ <code class="computeroutput">ferror(f)</code>) is set. On
+ receipt of <code class="computeroutput">BZ_IO_ERROR</code>, the
+ caller should consult <code class="computeroutput">errno</code>
+ and/or <code class="computeroutput">perror</code> to acquire
+ operating-system specific information about the
+ problem.</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_UNEXPECTED_EOF</code></span></dt>
+<dd><p>Returned by
+ <code class="computeroutput">BZ2_bzRead</code> when the
+ compressed file finishes before the logical end of stream is
+ detected.</p></dd>
+<dt><span class="term"><code class="computeroutput">BZ_OUTBUFF_FULL</code></span></dt>
+<dd><p>Returned by
+ <code class="computeroutput">BZ2_bzBuffToBuffCompress</code> and
+ <code class="computeroutput">BZ2_bzBuffToBuffDecompress</code> to
+ indicate that the output data will not fit into the output
+ buffer provided.</p></dd>
+</dl></div>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="low-level"></a>3.3. Low-level interface</h2></div></div></div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzcompress-init"></a>3.3.1. <code class="computeroutput">BZ2_bzCompressInit</code></h3></div></div></div>
+<pre class="programlisting">typedef struct {
+ char *next_in;
+ unsigned int avail_in;
+ unsigned int total_in_lo32;
+ unsigned int total_in_hi32;
+
+ char *next_out;
+ unsigned int avail_out;
+ unsigned int total_out_lo32;
+ unsigned int total_out_hi32;
+
+ void *state;
+
+ void *(*bzalloc)(void *,int,int);
+ void (*bzfree)(void *,void *);
+ void *opaque;
+} bz_stream;
+
+int BZ2_bzCompressInit ( bz_stream *strm,
+ int blockSize100k,
+ int verbosity,
+ int workFactor );</pre>
+<p>Prepares for compression. The
+<code class="computeroutput">bz_stream</code> structure holds all
+data pertaining to the compression activity. A
+<code class="computeroutput">bz_stream</code> structure should be
+allocated and initialised prior to the call. The fields of
+<code class="computeroutput">bz_stream</code> comprise the entirety
+of the user-visible data. <code class="computeroutput">state</code>
+is a pointer to the private data structures required for
+compression.</p>
+<p>Custom memory allocators are supported, via fields
+<code class="computeroutput">bzalloc</code>,
+<code class="computeroutput">bzfree</code>, and
+<code class="computeroutput">opaque</code>. The value
+<code class="computeroutput">opaque</code> is passed to as the first
+argument to all calls to <code class="computeroutput">bzalloc</code>
+and <code class="computeroutput">bzfree</code>, but is otherwise
+ignored by the library. The call <code class="computeroutput">bzalloc (
+opaque, n, m )</code> is expected to return a pointer
+<code class="computeroutput">p</code> to <code class="computeroutput">n *
+m</code> bytes of memory, and <code class="computeroutput">bzfree (
+opaque, p )</code> should free that memory.</p>
+<p>If you don't want to use a custom memory allocator, set
+<code class="computeroutput">bzalloc</code>,
+<code class="computeroutput">bzfree</code> and
+<code class="computeroutput">opaque</code> to
+<code class="computeroutput">NULL</code>, and the library will then
+use the standard <code class="computeroutput">malloc</code> /
+<code class="computeroutput">free</code> routines.</p>
+<p>Before calling
+<code class="computeroutput">BZ2_bzCompressInit</code>, fields
+<code class="computeroutput">bzalloc</code>,
+<code class="computeroutput">bzfree</code> and
+<code class="computeroutput">opaque</code> should be filled
+appropriately, as just described. Upon return, the internal
+state will have been allocated and initialised, and
+<code class="computeroutput">total_in_lo32</code>,
+<code class="computeroutput">total_in_hi32</code>,
+<code class="computeroutput">total_out_lo32</code> and
+<code class="computeroutput">total_out_hi32</code> will have been
+set to zero. These four fields are used by the library to inform
+the caller of the total amount of data passed into and out of the
+library, respectively. You should not try to change them. As of
+version 1.0, 64-bit counts are maintained, even on 32-bit
+platforms, using the <code class="computeroutput">_hi32</code>
+fields to store the upper 32 bits of the count. So, for example,
+the total amount of data in is <code class="computeroutput">(total_in_hi32
+&lt;&lt; 32) + total_in_lo32</code>.</p>
+<p>Parameter <code class="computeroutput">blockSize100k</code>
+specifies the block size to be used for compression. It should
+be a value between 1 and 9 inclusive, and the actual block size
+used is 100000 x this figure. 9 gives the best compression but
+takes most memory.</p>
+<p>Parameter <code class="computeroutput">verbosity</code> should
+be set to a number between 0 and 4 inclusive. 0 is silent, and
+greater numbers give increasingly verbose monitoring/debugging
+output. If the library has been compiled with
+<code class="computeroutput">-DBZ_NO_STDIO</code>, no such output
+will appear for any verbosity setting.</p>
+<p>Parameter <code class="computeroutput">workFactor</code>
+controls how the compression phase behaves when presented with
+worst case, highly repetitive, input data. If compression runs
+into difficulties caused by repetitive data, the library switches
+from the standard sorting algorithm to a fallback algorithm. The
+fallback is slower than the standard algorithm by perhaps a
+factor of three, but always behaves reasonably, no matter how bad
+the input.</p>
+<p>Lower values of <code class="computeroutput">workFactor</code>
+reduce the amount of effort the standard algorithm will expend
+before resorting to the fallback. You should set this parameter
+carefully; too low, and many inputs will be handled by the
+fallback algorithm and so compress rather slowly, too high, and
+your average-to-worst case compression times can become very
+large. The default value of 30 gives reasonable behaviour over a
+wide range of circumstances.</p>
+<p>Allowable values range from 0 to 250 inclusive. 0 is a
+special case, equivalent to using the default value of 30.</p>
+<p>Note that the compressed output generated is the same
+regardless of whether or not the fallback algorithm is
+used.</p>
+<p>Be aware also that this parameter may disappear entirely in
+future versions of the library. In principle it should be
+possible to devise a good way to automatically choose which
+algorithm to use. Such a mechanism would render the parameter
+obsolete.</p>
+<p>Possible return values:</p>
+<pre class="programlisting">BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if strm is NULL
+ or blockSize &lt; 1 or blockSize &gt; 9
+ or verbosity &lt; 0 or verbosity &gt; 4
+ or workFactor &lt; 0 or workFactor &gt; 250
+BZ_MEM_ERROR
+ if not enough memory is available
+BZ_OK
+ otherwise</pre>
+<p>Allowable next actions:</p>
+<pre class="programlisting">BZ2_bzCompress
+ if BZ_OK is returned
+ no specific action needed in case of error</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzCompress"></a>3.3.2. <code class="computeroutput">BZ2_bzCompress</code></h3></div></div></div>
+<pre class="programlisting">int BZ2_bzCompress ( bz_stream *strm, int action );</pre>
+<p>Provides more input and/or output buffer space for the
+library. The caller maintains input and output buffers, and
+calls <code class="computeroutput">BZ2_bzCompress</code> to transfer
+data between them.</p>
+<p>Before each call to
+<code class="computeroutput">BZ2_bzCompress</code>,
+<code class="computeroutput">next_in</code> should point at the data
+to be compressed, and <code class="computeroutput">avail_in</code>
+should indicate how many bytes the library may read.
+<code class="computeroutput">BZ2_bzCompress</code> updates
+<code class="computeroutput">next_in</code>,
+<code class="computeroutput">avail_in</code> and
+<code class="computeroutput">total_in</code> to reflect the number
+of bytes it has read.</p>
+<p>Similarly, <code class="computeroutput">next_out</code> should
+point to a buffer in which the compressed data is to be placed,
+with <code class="computeroutput">avail_out</code> indicating how
+much output space is available.
+<code class="computeroutput">BZ2_bzCompress</code> updates
+<code class="computeroutput">next_out</code>,
+<code class="computeroutput">avail_out</code> and
+<code class="computeroutput">total_out</code> to reflect the number
+of bytes output.</p>
+<p>You may provide and remove as little or as much data as you
+like on each call of
+<code class="computeroutput">BZ2_bzCompress</code>. In the limit,
+it is acceptable to supply and remove data one byte at a time,
+although this would be terribly inefficient. You should always
+ensure that at least one byte of output space is available at
+each call.</p>
+<p>A second purpose of
+<code class="computeroutput">BZ2_bzCompress</code> is to request a
+change of mode of the compressed stream.</p>
+<p>Conceptually, a compressed stream can be in one of four
+states: IDLE, RUNNING, FLUSHING and FINISHING. Before
+initialisation
+(<code class="computeroutput">BZ2_bzCompressInit</code>) and after
+termination (<code class="computeroutput">BZ2_bzCompressEnd</code>),
+a stream is regarded as IDLE.</p>
+<p>Upon initialisation
+(<code class="computeroutput">BZ2_bzCompressInit</code>), the stream
+is placed in the RUNNING state. Subsequent calls to
+<code class="computeroutput">BZ2_bzCompress</code> should pass
+<code class="computeroutput">BZ_RUN</code> as the requested action;
+other actions are illegal and will result in
+<code class="computeroutput">BZ_SEQUENCE_ERROR</code>.</p>
+<p>At some point, the calling program will have provided all
+the input data it wants to. It will then want to finish up -- in
+effect, asking the library to process any data it might have
+buffered internally. In this state,
+<code class="computeroutput">BZ2_bzCompress</code> will no longer
+attempt to read data from
+<code class="computeroutput">next_in</code>, but it will want to
+write data to <code class="computeroutput">next_out</code>. Because
+the output buffer supplied by the user can be arbitrarily small,
+the finishing-up operation cannot necessarily be done with a
+single call of
+<code class="computeroutput">BZ2_bzCompress</code>.</p>
+<p>Instead, the calling program passes
+<code class="computeroutput">BZ_FINISH</code> as an action to
+<code class="computeroutput">BZ2_bzCompress</code>. This changes
+the stream's state to FINISHING. Any remaining input (ie,
+<code class="computeroutput">next_in[0 .. avail_in-1]</code>) is
+compressed and transferred to the output buffer. To do this,
+<code class="computeroutput">BZ2_bzCompress</code> must be called
+repeatedly until all the output has been consumed. At that
+point, <code class="computeroutput">BZ2_bzCompress</code> returns
+<code class="computeroutput">BZ_STREAM_END</code>, and the stream's
+state is set back to IDLE.
+<code class="computeroutput">BZ2_bzCompressEnd</code> should then be
+called.</p>
+<p>Just to make sure the calling program does not cheat, the
+library makes a note of <code class="computeroutput">avail_in</code>
+at the time of the first call to
+<code class="computeroutput">BZ2_bzCompress</code> which has
+<code class="computeroutput">BZ_FINISH</code> as an action (ie, at
+the time the program has announced its intention to not supply
+any more input). By comparing this value with that of
+<code class="computeroutput">avail_in</code> over subsequent calls
+to <code class="computeroutput">BZ2_bzCompress</code>, the library
+can detect any attempts to slip in more data to compress. Any
+calls for which this is detected will return
+<code class="computeroutput">BZ_SEQUENCE_ERROR</code>. This
+indicates a programming mistake which should be corrected.</p>
+<p>Instead of asking to finish, the calling program may ask
+<code class="computeroutput">BZ2_bzCompress</code> to take all the
+remaining input, compress it and terminate the current
+(Burrows-Wheeler) compression block. This could be useful for
+error control purposes. The mechanism is analogous to that for
+finishing: call <code class="computeroutput">BZ2_bzCompress</code>
+with an action of <code class="computeroutput">BZ_FLUSH</code>,
+remove output data, and persist with the
+<code class="computeroutput">BZ_FLUSH</code> action until the value
+<code class="computeroutput">BZ_RUN</code> is returned. As with
+finishing, <code class="computeroutput">BZ2_bzCompress</code>
+detects any attempt to provide more input data once the flush has
+begun.</p>
+<p>Once the flush is complete, the stream returns to the
+normal RUNNING state.</p>
+<p>This all sounds pretty complex, but isn't really. Here's a
+table which shows which actions are allowable in each state, what
+action will be taken, what the next state is, and what the
+non-error return values are. Note that you can't explicitly ask
+what state the stream is in, but nor do you need to -- it can be
+inferred from the values returned by
+<code class="computeroutput">BZ2_bzCompress</code>.</p>
+<pre class="programlisting">IDLE/any
+ Illegal. IDLE state only exists after BZ2_bzCompressEnd or
+ before BZ2_bzCompressInit.
+ Return value = BZ_SEQUENCE_ERROR
+
+RUNNING/BZ_RUN
+ Compress from next_in to next_out as much as possible.
+ Next state = RUNNING
+ Return value = BZ_RUN_OK
+
+RUNNING/BZ_FLUSH
+ Remember current value of next_in. Compress from next_in
+ to next_out as much as possible, but do not accept any more input.
+ Next state = FLUSHING
+ Return value = BZ_FLUSH_OK
+
+RUNNING/BZ_FINISH
+ Remember current value of next_in. Compress from next_in
+ to next_out as much as possible, but do not accept any more input.
+ Next state = FINISHING
+ Return value = BZ_FINISH_OK
+
+FLUSHING/BZ_FLUSH
+ Compress from next_in to next_out as much as possible,
+ but do not accept any more input.
+ If all the existing input has been used up and all compressed
+ output has been removed
+ Next state = RUNNING; Return value = BZ_RUN_OK
+ else
+ Next state = FLUSHING; Return value = BZ_FLUSH_OK
+
+FLUSHING/other
+ Illegal.
+ Return value = BZ_SEQUENCE_ERROR
+
+FINISHING/BZ_FINISH
+ Compress from next_in to next_out as much as possible,
+ but to not accept any more input.
+ If all the existing input has been used up and all compressed
+ output has been removed
+ Next state = IDLE; Return value = BZ_STREAM_END
+ else
+ Next state = FINISHING; Return value = BZ_FINISH_OK
+
+FINISHING/other
+ Illegal.
+ Return value = BZ_SEQUENCE_ERROR</pre>
+<p>That still looks complicated? Well, fair enough. The
+usual sequence of calls for compressing a load of data is:</p>
+<div class="orderedlist"><ol type="1">
+<li><p>Get started with
+ <code class="computeroutput">BZ2_bzCompressInit</code>.</p></li>
+<li><p>Shovel data in and shlurp out its compressed form
+ using zero or more calls of
+ <code class="computeroutput">BZ2_bzCompress</code> with action =
+ <code class="computeroutput">BZ_RUN</code>.</p></li>
+<li><p>Finish up. Repeatedly call
+ <code class="computeroutput">BZ2_bzCompress</code> with action =
+ <code class="computeroutput">BZ_FINISH</code>, copying out the
+ compressed output, until
+ <code class="computeroutput">BZ_STREAM_END</code> is
+ returned.</p></li>
+<li><p>Close up and go home. Call
+ <code class="computeroutput">BZ2_bzCompressEnd</code>.</p></li>
+</ol></div>
+<p>If the data you want to compress fits into your input
+buffer all at once, you can skip the calls of
+<code class="computeroutput">BZ2_bzCompress ( ..., BZ_RUN )</code>
+and just do the <code class="computeroutput">BZ2_bzCompress ( ..., BZ_FINISH
+)</code> calls.</p>
+<p>All required memory is allocated by
+<code class="computeroutput">BZ2_bzCompressInit</code>. The
+compression library can accept any data at all (obviously). So
+you shouldn't get any error return values from the
+<code class="computeroutput">BZ2_bzCompress</code> calls. If you
+do, they will be
+<code class="computeroutput">BZ_SEQUENCE_ERROR</code>, and indicate
+a bug in your programming.</p>
+<p>Trivial other possible return values:</p>
+<pre class="programlisting">BZ_PARAM_ERROR
+ if strm is NULL, or strm-&gt;s is NULL</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzCompress-end"></a>3.3.3. <code class="computeroutput">BZ2_bzCompressEnd</code></h3></div></div></div>
+<pre class="programlisting">int BZ2_bzCompressEnd ( bz_stream *strm );</pre>
+<p>Releases all memory associated with a compression
+stream.</p>
+<p>Possible return values:</p>
+<pre class="programlisting">BZ_PARAM_ERROR if strm is NULL or strm-&gt;s is NULL
+BZ_OK otherwise</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzDecompress-init"></a>3.3.4. <code class="computeroutput">BZ2_bzDecompressInit</code></h3></div></div></div>
+<pre class="programlisting">int BZ2_bzDecompressInit ( bz_stream *strm, int verbosity, int small );</pre>
+<p>Prepares for decompression. As with
+<code class="computeroutput">BZ2_bzCompressInit</code>, a
+<code class="computeroutput">bz_stream</code> record should be
+allocated and initialised before the call. Fields
+<code class="computeroutput">bzalloc</code>,
+<code class="computeroutput">bzfree</code> and
+<code class="computeroutput">opaque</code> should be set if a custom
+memory allocator is required, or made
+<code class="computeroutput">NULL</code> for the normal
+<code class="computeroutput">malloc</code> /
+<code class="computeroutput">free</code> routines. Upon return, the
+internal state will have been initialised, and
+<code class="computeroutput">total_in</code> and
+<code class="computeroutput">total_out</code> will be zero.</p>
+<p>For the meaning of parameter
+<code class="computeroutput">verbosity</code>, see
+<code class="computeroutput">BZ2_bzCompressInit</code>.</p>
+<p>If <code class="computeroutput">small</code> is nonzero, the
+library will use an alternative decompression algorithm which
+uses less memory but at the cost of decompressing more slowly
+(roughly speaking, half the speed, but the maximum memory
+requirement drops to around 2300k). See <a href="#using">How to use bzip2</a>
+for more information on memory management.</p>
+<p>Note that the amount of memory needed to decompress a
+stream cannot be determined until the stream's header has been
+read, so even if
+<code class="computeroutput">BZ2_bzDecompressInit</code> succeeds, a
+subsequent <code class="computeroutput">BZ2_bzDecompress</code>
+could fail with
+<code class="computeroutput">BZ_MEM_ERROR</code>.</p>
+<p>Possible return values:</p>
+<pre class="programlisting">BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if ( small != 0 &amp;&amp; small != 1 )
+ or (verbosity &lt;; 0 || verbosity &gt; 4)
+BZ_MEM_ERROR
+ if insufficient memory is available</pre>
+<p>Allowable next actions:</p>
+<pre class="programlisting">BZ2_bzDecompress
+ if BZ_OK was returned
+ no specific action required in case of error</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzDecompress"></a>3.3.5. <code class="computeroutput">BZ2_bzDecompress</code></h3></div></div></div>
+<pre class="programlisting">int BZ2_bzDecompress ( bz_stream *strm );</pre>
+<p>Provides more input and/out output buffer space for the
+library. The caller maintains input and output buffers, and uses
+<code class="computeroutput">BZ2_bzDecompress</code> to transfer
+data between them.</p>
+<p>Before each call to
+<code class="computeroutput">BZ2_bzDecompress</code>,
+<code class="computeroutput">next_in</code> should point at the
+compressed data, and <code class="computeroutput">avail_in</code>
+should indicate how many bytes the library may read.
+<code class="computeroutput">BZ2_bzDecompress</code> updates
+<code class="computeroutput">next_in</code>,
+<code class="computeroutput">avail_in</code> and
+<code class="computeroutput">total_in</code> to reflect the number
+of bytes it has read.</p>
+<p>Similarly, <code class="computeroutput">next_out</code> should
+point to a buffer in which the uncompressed output is to be
+placed, with <code class="computeroutput">avail_out</code>
+indicating how much output space is available.
+<code class="computeroutput">BZ2_bzCompress</code> updates
+<code class="computeroutput">next_out</code>,
+<code class="computeroutput">avail_out</code> and
+<code class="computeroutput">total_out</code> to reflect the number
+of bytes output.</p>
+<p>You may provide and remove as little or as much data as you
+like on each call of
+<code class="computeroutput">BZ2_bzDecompress</code>. In the limit,
+it is acceptable to supply and remove data one byte at a time,
+although this would be terribly inefficient. You should always
+ensure that at least one byte of output space is available at
+each call.</p>
+<p>Use of <code class="computeroutput">BZ2_bzDecompress</code> is
+simpler than
+<code class="computeroutput">BZ2_bzCompress</code>.</p>
+<p>You should provide input and remove output as described
+above, and repeatedly call
+<code class="computeroutput">BZ2_bzDecompress</code> until
+<code class="computeroutput">BZ_STREAM_END</code> is returned.
+Appearance of <code class="computeroutput">BZ_STREAM_END</code>
+denotes that <code class="computeroutput">BZ2_bzDecompress</code>
+has detected the logical end of the compressed stream.
+<code class="computeroutput">BZ2_bzDecompress</code> will not
+produce <code class="computeroutput">BZ_STREAM_END</code> until all
+output data has been placed into the output buffer, so once
+<code class="computeroutput">BZ_STREAM_END</code> appears, you are
+guaranteed to have available all the decompressed output, and
+<code class="computeroutput">BZ2_bzDecompressEnd</code> can safely
+be called.</p>
+<p>If case of an error return value, you should call
+<code class="computeroutput">BZ2_bzDecompressEnd</code> to clean up
+and release memory.</p>
+<p>Possible return values:</p>
+<pre class="programlisting">BZ_PARAM_ERROR
+ if strm is NULL or strm-&gt;s is NULL
+ or strm-&gt;avail_out &lt; 1
+BZ_DATA_ERROR
+ if a data integrity error is detected in the compressed stream
+BZ_DATA_ERROR_MAGIC
+ if the compressed stream doesn't begin with the right magic bytes
+BZ_MEM_ERROR
+ if there wasn't enough memory available
+BZ_STREAM_END
+ if the logical end of the data stream was detected and all
+ output in has been consumed, eg s--&gt;avail_out &gt; 0
+BZ_OK
+ otherwise</pre>
+<p>Allowable next actions:</p>
+<pre class="programlisting">BZ2_bzDecompress
+ if BZ_OK was returned
+BZ2_bzDecompressEnd
+ otherwise</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzDecompress-end"></a>3.3.6. <code class="computeroutput">BZ2_bzDecompressEnd</code></h3></div></div></div>
+<pre class="programlisting">int BZ2_bzDecompressEnd ( bz_stream *strm );</pre>
+<p>Releases all memory associated with a decompression
+stream.</p>
+<p>Possible return values:</p>
+<pre class="programlisting">BZ_PARAM_ERROR
+ if strm is NULL or strm-&gt;s is NULL
+BZ_OK
+ otherwise</pre>
+<p>Allowable next actions:</p>
+<pre class="programlisting"> None.</pre>
+</div>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="hl-interface"></a>3.4. High-level interface</h2></div></div></div>
+<p>This interface provides functions for reading and writing
+<code class="computeroutput">bzip2</code> format files. First, some
+general points.</p>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc"><p>All of the functions take an
+ <code class="computeroutput">int*</code> first argument,
+ <code class="computeroutput">bzerror</code>. After each call,
+ <code class="computeroutput">bzerror</code> should be consulted
+ first to determine the outcome of the call. If
+ <code class="computeroutput">bzerror</code> is
+ <code class="computeroutput">BZ_OK</code>, the call completed
+ successfully, and only then should the return value of the
+ function (if any) be consulted. If
+ <code class="computeroutput">bzerror</code> is
+ <code class="computeroutput">BZ_IO_ERROR</code>, there was an
+ error reading/writing the underlying compressed file, and you
+ should then consult <code class="computeroutput">errno</code> /
+ <code class="computeroutput">perror</code> to determine the cause
+ of the difficulty. <code class="computeroutput">bzerror</code>
+ may also be set to various other values; precise details are
+ given on a per-function basis below.</p></li>
+<li style="list-style-type: disc"><p>If <code class="computeroutput">bzerror</code> indicates
+ an error (ie, anything except
+ <code class="computeroutput">BZ_OK</code> and
+ <code class="computeroutput">BZ_STREAM_END</code>), you should
+ immediately call
+ <code class="computeroutput">BZ2_bzReadClose</code> (or
+ <code class="computeroutput">BZ2_bzWriteClose</code>, depending on
+ whether you are attempting to read or to write) to free up all
+ resources associated with the stream. Once an error has been
+ indicated, behaviour of all calls except
+ <code class="computeroutput">BZ2_bzReadClose</code>
+ (<code class="computeroutput">BZ2_bzWriteClose</code>) is
+ undefined. The implication is that (1)
+ <code class="computeroutput">bzerror</code> should be checked
+ after each call, and (2) if
+ <code class="computeroutput">bzerror</code> indicates an error,
+ <code class="computeroutput">BZ2_bzReadClose</code>
+ (<code class="computeroutput">BZ2_bzWriteClose</code>) should then
+ be called to clean up.</p></li>
+<li style="list-style-type: disc"><p>The <code class="computeroutput">FILE*</code> arguments
+ passed to <code class="computeroutput">BZ2_bzReadOpen</code> /
+ <code class="computeroutput">BZ2_bzWriteOpen</code> should be set
+ to binary mode. Most Unix systems will do this by default, but
+ other platforms, including Windows and Mac, will not. If you
+ omit this, you may encounter problems when moving code to new
+ platforms.</p></li>
+<li style="list-style-type: disc"><p>Memory allocation requests are handled by
+ <code class="computeroutput">malloc</code> /
+ <code class="computeroutput">free</code>. At present there is no
+ facility for user-defined memory allocators in the file I/O
+ functions (could easily be added, though).</p></li>
+</ul></div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzreadopen"></a>3.4.1. <code class="computeroutput">BZ2_bzReadOpen</code></h3></div></div></div>
+<pre class="programlisting">typedef void BZFILE;
+
+BZFILE *BZ2_bzReadOpen( int *bzerror, FILE *f,
+ int verbosity, int small,
+ void *unused, int nUnused );</pre>
+<p>Prepare to read compressed data from file handle
+<code class="computeroutput">f</code>.
+<code class="computeroutput">f</code> should refer to a file which
+has been opened for reading, and for which the error indicator
+(<code class="computeroutput">ferror(f)</code>)is not set. If
+<code class="computeroutput">small</code> is 1, the library will try
+to decompress using less memory, at the expense of speed.</p>
+<p>For reasons explained below,
+<code class="computeroutput">BZ2_bzRead</code> will decompress the
+<code class="computeroutput">nUnused</code> bytes starting at
+<code class="computeroutput">unused</code>, before starting to read
+from the file <code class="computeroutput">f</code>. At most
+<code class="computeroutput">BZ_MAX_UNUSED</code> bytes may be
+supplied like this. If this facility is not required, you should
+pass <code class="computeroutput">NULL</code> and
+<code class="computeroutput">0</code> for
+<code class="computeroutput">unused</code> and
+n<code class="computeroutput">Unused</code> respectively.</p>
+<p>For the meaning of parameters
+<code class="computeroutput">small</code> and
+<code class="computeroutput">verbosity</code>, see
+<code class="computeroutput">BZ2_bzDecompressInit</code>.</p>
+<p>The amount of memory needed to decompress a file cannot be
+determined until the file's header has been read. So it is
+possible that <code class="computeroutput">BZ2_bzReadOpen</code>
+returns <code class="computeroutput">BZ_OK</code> but a subsequent
+call of <code class="computeroutput">BZ2_bzRead</code> will return
+<code class="computeroutput">BZ_MEM_ERROR</code>.</p>
+<p>Possible assignments to
+<code class="computeroutput">bzerror</code>:</p>
+<pre class="programlisting">BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if f is NULL
+ or small is neither 0 nor 1
+ or ( unused == NULL &amp;&amp; nUnused != 0 )
+ or ( unused != NULL &amp;&amp; !(0 &lt;= nUnused &lt;= BZ_MAX_UNUSED) )
+BZ_IO_ERROR
+ if ferror(f) is nonzero
+BZ_MEM_ERROR
+ if insufficient memory is available
+BZ_OK
+ otherwise.</pre>
+<p>Possible return values:</p>
+<pre class="programlisting">Pointer to an abstract BZFILE
+ if bzerror is BZ_OK
+NULL
+ otherwise</pre>
+<p>Allowable next actions:</p>
+<pre class="programlisting">BZ2_bzRead
+ if bzerror is BZ_OK
+BZ2_bzClose
+ otherwise</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzread"></a>3.4.2. <code class="computeroutput">BZ2_bzRead</code></h3></div></div></div>
+<pre class="programlisting">int BZ2_bzRead ( int *bzerror, BZFILE *b, void *buf, int len );</pre>
+<p>Reads up to <code class="computeroutput">len</code>
+(uncompressed) bytes from the compressed file
+<code class="computeroutput">b</code> into the buffer
+<code class="computeroutput">buf</code>. If the read was
+successful, <code class="computeroutput">bzerror</code> is set to
+<code class="computeroutput">BZ_OK</code> and the number of bytes
+read is returned. If the logical end-of-stream was detected,
+<code class="computeroutput">bzerror</code> will be set to
+<code class="computeroutput">BZ_STREAM_END</code>, and the number of
+bytes read is returned. All other
+<code class="computeroutput">bzerror</code> values denote an
+error.</p>
+<p><code class="computeroutput">BZ2_bzRead</code> will supply
+<code class="computeroutput">len</code> bytes, unless the logical
+stream end is detected or an error occurs. Because of this, it
+is possible to detect the stream end by observing when the number
+of bytes returned is less than the number requested.
+Nevertheless, this is regarded as inadvisable; you should instead
+check <code class="computeroutput">bzerror</code> after every call
+and watch out for
+<code class="computeroutput">BZ_STREAM_END</code>.</p>
+<p>Internally, <code class="computeroutput">BZ2_bzRead</code>
+copies data from the compressed file in chunks of size
+<code class="computeroutput">BZ_MAX_UNUSED</code> bytes before
+decompressing it. If the file contains more bytes than strictly
+needed to reach the logical end-of-stream,
+<code class="computeroutput">BZ2_bzRead</code> will almost certainly
+read some of the trailing data before signalling
+<code class="computeroutput">BZ_SEQUENCE_END</code>. To collect the
+read but unused data once
+<code class="computeroutput">BZ_SEQUENCE_END</code> has appeared,
+call <code class="computeroutput">BZ2_bzReadGetUnused</code>
+immediately before
+<code class="computeroutput">BZ2_bzReadClose</code>.</p>
+<p>Possible assignments to
+<code class="computeroutput">bzerror</code>:</p>
+<pre class="programlisting">BZ_PARAM_ERROR
+ if b is NULL or buf is NULL or len &lt; 0
+BZ_SEQUENCE_ERROR
+ if b was opened with BZ2_bzWriteOpen
+BZ_IO_ERROR
+ if there is an error reading from the compressed file
+BZ_UNEXPECTED_EOF
+ if the compressed file ended before
+ the logical end-of-stream was detected
+BZ_DATA_ERROR
+ if a data integrity error was detected in the compressed stream
+BZ_DATA_ERROR_MAGIC
+ if the stream does not begin with the requisite header bytes
+ (ie, is not a bzip2 data file). This is really
+ a special case of BZ_DATA_ERROR.
+BZ_MEM_ERROR
+ if insufficient memory was available
+BZ_STREAM_END
+ if the logical end of stream was detected.
+BZ_OK
+ otherwise.</pre>
+<p>Possible return values:</p>
+<pre class="programlisting">number of bytes read
+ if bzerror is BZ_OK or BZ_STREAM_END
+undefined
+ otherwise</pre>
+<p>Allowable next actions:</p>
+<pre class="programlisting">collect data from buf, then BZ2_bzRead or BZ2_bzReadClose
+ if bzerror is BZ_OK
+collect data from buf, then BZ2_bzReadClose or BZ2_bzReadGetUnused
+ if bzerror is BZ_SEQUENCE_END
+BZ2_bzReadClose
+ otherwise</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzreadgetunused"></a>3.4.3. <code class="computeroutput">BZ2_bzReadGetUnused</code></h3></div></div></div>
+<pre class="programlisting">void BZ2_bzReadGetUnused( int* bzerror, BZFILE *b,
+ void** unused, int* nUnused );</pre>
+<p>Returns data which was read from the compressed file but
+was not needed to get to the logical end-of-stream.
+<code class="computeroutput">*unused</code> is set to the address of
+the data, and <code class="computeroutput">*nUnused</code> to the
+number of bytes. <code class="computeroutput">*nUnused</code> will
+be set to a value between <code class="computeroutput">0</code> and
+<code class="computeroutput">BZ_MAX_UNUSED</code> inclusive.</p>
+<p>This function may only be called once
+<code class="computeroutput">BZ2_bzRead</code> has signalled
+<code class="computeroutput">BZ_STREAM_END</code> but before
+<code class="computeroutput">BZ2_bzReadClose</code>.</p>
+<p>Possible assignments to
+<code class="computeroutput">bzerror</code>:</p>
+<pre class="programlisting">BZ_PARAM_ERROR
+ if b is NULL
+ or unused is NULL or nUnused is NULL
+BZ_SEQUENCE_ERROR
+ if BZ_STREAM_END has not been signalled
+ or if b was opened with BZ2_bzWriteOpen
+BZ_OK
+ otherwise</pre>
+<p>Allowable next actions:</p>
+<pre class="programlisting">BZ2_bzReadClose</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzreadclose"></a>3.4.4. <code class="computeroutput">BZ2_bzReadClose</code></h3></div></div></div>
+<pre class="programlisting">void BZ2_bzReadClose ( int *bzerror, BZFILE *b );</pre>
+<p>Releases all memory pertaining to the compressed file
+<code class="computeroutput">b</code>.
+<code class="computeroutput">BZ2_bzReadClose</code> does not call
+<code class="computeroutput">fclose</code> on the underlying file
+handle, so you should do that yourself if appropriate.
+<code class="computeroutput">BZ2_bzReadClose</code> should be called
+to clean up after all error situations.</p>
+<p>Possible assignments to
+<code class="computeroutput">bzerror</code>:</p>
+<pre class="programlisting">BZ_SEQUENCE_ERROR
+ if b was opened with BZ2_bzOpenWrite
+BZ_OK
+ otherwise</pre>
+<p>Allowable next actions:</p>
+<pre class="programlisting">none</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzwriteopen"></a>3.4.5. <code class="computeroutput">BZ2_bzWriteOpen</code></h3></div></div></div>
+<pre class="programlisting">BZFILE *BZ2_bzWriteOpen( int *bzerror, FILE *f,
+ int blockSize100k, int verbosity,
+ int workFactor );</pre>
+<p>Prepare to write compressed data to file handle
+<code class="computeroutput">f</code>.
+<code class="computeroutput">f</code> should refer to a file which
+has been opened for writing, and for which the error indicator
+(<code class="computeroutput">ferror(f)</code>)is not set.</p>
+<p>For the meaning of parameters
+<code class="computeroutput">blockSize100k</code>,
+<code class="computeroutput">verbosity</code> and
+<code class="computeroutput">workFactor</code>, see
+<code class="computeroutput">BZ2_bzCompressInit</code>.</p>
+<p>All required memory is allocated at this stage, so if the
+call completes successfully,
+<code class="computeroutput">BZ_MEM_ERROR</code> cannot be signalled
+by a subsequent call to
+<code class="computeroutput">BZ2_bzWrite</code>.</p>
+<p>Possible assignments to
+<code class="computeroutput">bzerror</code>:</p>
+<pre class="programlisting">BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if f is NULL
+ or blockSize100k &lt; 1 or blockSize100k &gt; 9
+BZ_IO_ERROR
+ if ferror(f) is nonzero
+BZ_MEM_ERROR
+ if insufficient memory is available
+BZ_OK
+ otherwise</pre>
+<p>Possible return values:</p>
+<pre class="programlisting">Pointer to an abstract BZFILE
+ if bzerror is BZ_OK
+NULL
+ otherwise</pre>
+<p>Allowable next actions:</p>
+<pre class="programlisting">BZ2_bzWrite
+ if bzerror is BZ_OK
+ (you could go directly to BZ2_bzWriteClose, but this would be pretty pointless)
+BZ2_bzWriteClose
+ otherwise</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzwrite"></a>3.4.6. <code class="computeroutput">BZ2_bzWrite</code></h3></div></div></div>
+<pre class="programlisting">void BZ2_bzWrite ( int *bzerror, BZFILE *b, void *buf, int len );</pre>
+<p>Absorbs <code class="computeroutput">len</code> bytes from the
+buffer <code class="computeroutput">buf</code>, eventually to be
+compressed and written to the file.</p>
+<p>Possible assignments to
+<code class="computeroutput">bzerror</code>:</p>
+<pre class="programlisting">BZ_PARAM_ERROR
+ if b is NULL or buf is NULL or len &lt; 0
+BZ_SEQUENCE_ERROR
+ if b was opened with BZ2_bzReadOpen
+BZ_IO_ERROR
+ if there is an error writing the compressed file.
+BZ_OK
+ otherwise</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzwriteclose"></a>3.4.7. <code class="computeroutput">BZ2_bzWriteClose</code></h3></div></div></div>
+<pre class="programlisting">void BZ2_bzWriteClose( int *bzerror, BZFILE* f,
+ int abandon,
+ unsigned int* nbytes_in,
+ unsigned int* nbytes_out );
+
+void BZ2_bzWriteClose64( int *bzerror, BZFILE* f,
+ int abandon,
+ unsigned int* nbytes_in_lo32,
+ unsigned int* nbytes_in_hi32,
+ unsigned int* nbytes_out_lo32,
+ unsigned int* nbytes_out_hi32 );</pre>
+<p>Compresses and flushes to the compressed file all data so
+far supplied by <code class="computeroutput">BZ2_bzWrite</code>.
+The logical end-of-stream markers are also written, so subsequent
+calls to <code class="computeroutput">BZ2_bzWrite</code> are
+illegal. All memory associated with the compressed file
+<code class="computeroutput">b</code> is released.
+<code class="computeroutput">fflush</code> is called on the
+compressed file, but it is not
+<code class="computeroutput">fclose</code>'d.</p>
+<p>If <code class="computeroutput">BZ2_bzWriteClose</code> is
+called to clean up after an error, the only action is to release
+the memory. The library records the error codes issued by
+previous calls, so this situation will be detected automatically.
+There is no attempt to complete the compression operation, nor to
+<code class="computeroutput">fflush</code> the compressed file. You
+can force this behaviour to happen even in the case of no error,
+by passing a nonzero value to
+<code class="computeroutput">abandon</code>.</p>
+<p>If <code class="computeroutput">nbytes_in</code> is non-null,
+<code class="computeroutput">*nbytes_in</code> will be set to be the
+total volume of uncompressed data handled. Similarly,
+<code class="computeroutput">nbytes_out</code> will be set to the
+total volume of compressed data written. For compatibility with
+older versions of the library,
+<code class="computeroutput">BZ2_bzWriteClose</code> only yields the
+lower 32 bits of these counts. Use
+<code class="computeroutput">BZ2_bzWriteClose64</code> if you want
+the full 64 bit counts. These two functions are otherwise
+absolutely identical.</p>
+<p>Possible assignments to
+<code class="computeroutput">bzerror</code>:</p>
+<pre class="programlisting">BZ_SEQUENCE_ERROR
+ if b was opened with BZ2_bzReadOpen
+BZ_IO_ERROR
+ if there is an error writing the compressed file
+BZ_OK
+ otherwise</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="embed"></a>3.4.8. Handling embedded compressed data streams</h3></div></div></div>
+<p>The high-level library facilitates use of
+<code class="computeroutput">bzip2</code> data streams which form
+some part of a surrounding, larger data stream.</p>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc"><p>For writing, the library takes an open file handle,
+ writes compressed data to it,
+ <code class="computeroutput">fflush</code>es it but does not
+ <code class="computeroutput">fclose</code> it. The calling
+ application can write its own data before and after the
+ compressed data stream, using that same file handle.</p></li>
+<li style="list-style-type: disc"><p>Reading is more complex, and the facilities are not as
+ general as they could be since generality is hard to reconcile
+ with efficiency. <code class="computeroutput">BZ2_bzRead</code>
+ reads from the compressed file in blocks of size
+ <code class="computeroutput">BZ_MAX_UNUSED</code> bytes, and in
+ doing so probably will overshoot the logical end of compressed
+ stream. To recover this data once decompression has ended,
+ call <code class="computeroutput">BZ2_bzReadGetUnused</code> after
+ the last call of <code class="computeroutput">BZ2_bzRead</code>
+ (the one returning
+ <code class="computeroutput">BZ_STREAM_END</code>) but before
+ calling
+ <code class="computeroutput">BZ2_bzReadClose</code>.</p></li>
+</ul></div>
+<p>This mechanism makes it easy to decompress multiple
+<code class="computeroutput">bzip2</code> streams placed end-to-end.
+As the end of one stream, when
+<code class="computeroutput">BZ2_bzRead</code> returns
+<code class="computeroutput">BZ_STREAM_END</code>, call
+<code class="computeroutput">BZ2_bzReadGetUnused</code> to collect
+the unused data (copy it into your own buffer somewhere). That
+data forms the start of the next compressed stream. To start
+uncompressing that next stream, call
+<code class="computeroutput">BZ2_bzReadOpen</code> again, feeding in
+the unused data via the <code class="computeroutput">unused</code> /
+<code class="computeroutput">nUnused</code> parameters. Keep doing
+this until <code class="computeroutput">BZ_STREAM_END</code> return
+coincides with the physical end of file
+(<code class="computeroutput">feof(f)</code>). In this situation
+<code class="computeroutput">BZ2_bzReadGetUnused</code> will of
+course return no data.</p>
+<p>This should give some feel for how the high-level interface
+can be used. If you require extra flexibility, you'll have to
+bite the bullet and get to grips with the low-level
+interface.</p>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="std-rdwr"></a>3.4.9. Standard file-reading/writing code</h3></div></div></div>
+<p>Here's how you'd write data to a compressed file:</p>
+<pre class="programlisting">FILE* f;
+BZFILE* b;
+int nBuf;
+char buf[ /* whatever size you like */ ];
+int bzerror;
+int nWritten;
+
+f = fopen ( "myfile.bz2", "w" );
+if ( !f ) {
+ /* handle error */
+}
+b = BZ2_bzWriteOpen( &amp;bzerror, f, 9 );
+if (bzerror != BZ_OK) {
+ BZ2_bzWriteClose ( b );
+ /* handle error */
+}
+
+while ( /* condition */ ) {
+ /* get data to write into buf, and set nBuf appropriately */
+ nWritten = BZ2_bzWrite ( &amp;bzerror, b, buf, nBuf );
+ if (bzerror == BZ_IO_ERROR) {
+ BZ2_bzWriteClose ( &amp;bzerror, b );
+ /* handle error */
+ }
+}
+
+BZ2_bzWriteClose( &amp;bzerror, b );
+if (bzerror == BZ_IO_ERROR) {
+ /* handle error */
+}</pre>
+<p>And to read from a compressed file:</p>
+<pre class="programlisting">FILE* f;
+BZFILE* b;
+int nBuf;
+char buf[ /* whatever size you like */ ];
+int bzerror;
+int nWritten;
+
+f = fopen ( "myfile.bz2", "r" );
+if ( !f ) {
+ /* handle error */
+}
+b = BZ2_bzReadOpen ( &amp;bzerror, f, 0, NULL, 0 );
+if ( bzerror != BZ_OK ) {
+ BZ2_bzReadClose ( &amp;bzerror, b );
+ /* handle error */
+}
+
+bzerror = BZ_OK;
+while ( bzerror == BZ_OK &amp;&amp; /* arbitrary other conditions */) {
+ nBuf = BZ2_bzRead ( &amp;bzerror, b, buf, /* size of buf */ );
+ if ( bzerror == BZ_OK ) {
+ /* do something with buf[0 .. nBuf-1] */
+ }
+}
+if ( bzerror != BZ_STREAM_END ) {
+ BZ2_bzReadClose ( &amp;bzerror, b );
+ /* handle error */
+} else {
+ BZ2_bzReadClose ( &amp;bzerror, b );
+}</pre>
+</div>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="util-fns"></a>3.5. Utility functions</h2></div></div></div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzbufftobuffcompress"></a>3.5.1. <code class="computeroutput">BZ2_bzBuffToBuffCompress</code></h3></div></div></div>
+<pre class="programlisting">int BZ2_bzBuffToBuffCompress( char* dest,
+ unsigned int* destLen,
+ char* source,
+ unsigned int sourceLen,
+ int blockSize100k,
+ int verbosity,
+ int workFactor );</pre>
+<p>Attempts to compress the data in <code class="computeroutput">source[0
+.. sourceLen-1]</code> into the destination buffer,
+<code class="computeroutput">dest[0 .. *destLen-1]</code>. If the
+destination buffer is big enough,
+<code class="computeroutput">*destLen</code> is set to the size of
+the compressed data, and <code class="computeroutput">BZ_OK</code>
+is returned. If the compressed data won't fit,
+<code class="computeroutput">*destLen</code> is unchanged, and
+<code class="computeroutput">BZ_OUTBUFF_FULL</code> is
+returned.</p>
+<p>Compression in this manner is a one-shot event, done with a
+single call to this function. The resulting compressed data is a
+complete <code class="computeroutput">bzip2</code> format data
+stream. There is no mechanism for making additional calls to
+provide extra input data. If you want that kind of mechanism,
+use the low-level interface.</p>
+<p>For the meaning of parameters
+<code class="computeroutput">blockSize100k</code>,
+<code class="computeroutput">verbosity</code> and
+<code class="computeroutput">workFactor</code>, see
+<code class="computeroutput">BZ2_bzCompressInit</code>.</p>
+<p>To guarantee that the compressed data will fit in its
+buffer, allocate an output buffer of size 1% larger than the
+uncompressed data, plus six hundred extra bytes.</p>
+<p><code class="computeroutput">BZ2_bzBuffToBuffDecompress</code>
+will not write data at or beyond
+<code class="computeroutput">dest[*destLen]</code>, even in case of
+buffer overflow.</p>
+<p>Possible return values:</p>
+<pre class="programlisting">BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if dest is NULL or destLen is NULL
+ or blockSize100k &lt; 1 or blockSize100k &gt; 9
+ or verbosity &lt; 0 or verbosity &gt; 4
+ or workFactor &lt; 0 or workFactor &gt; 250
+BZ_MEM_ERROR
+ if insufficient memory is available
+BZ_OUTBUFF_FULL
+ if the size of the compressed data exceeds *destLen
+BZ_OK
+ otherwise</pre>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="bzbufftobuffdecompress"></a>3.5.2. <code class="computeroutput">BZ2_bzBuffToBuffDecompress</code></h3></div></div></div>
+<pre class="programlisting">int BZ2_bzBuffToBuffDecompress( char* dest,
+ unsigned int* destLen,
+ char* source,
+ unsigned int sourceLen,
+ int small,
+ int verbosity );</pre>
+<p>Attempts to decompress the data in <code class="computeroutput">source[0
+.. sourceLen-1]</code> into the destination buffer,
+<code class="computeroutput">dest[0 .. *destLen-1]</code>. If the
+destination buffer is big enough,
+<code class="computeroutput">*destLen</code> is set to the size of
+the uncompressed data, and <code class="computeroutput">BZ_OK</code>
+is returned. If the compressed data won't fit,
+<code class="computeroutput">*destLen</code> is unchanged, and
+<code class="computeroutput">BZ_OUTBUFF_FULL</code> is
+returned.</p>
+<p><code class="computeroutput">source</code> is assumed to hold
+a complete <code class="computeroutput">bzip2</code> format data
+stream.
+<code class="computeroutput">BZ2_bzBuffToBuffDecompress</code> tries
+to decompress the entirety of the stream into the output
+buffer.</p>
+<p>For the meaning of parameters
+<code class="computeroutput">small</code> and
+<code class="computeroutput">verbosity</code>, see
+<code class="computeroutput">BZ2_bzDecompressInit</code>.</p>
+<p>Because the compression ratio of the compressed data cannot
+be known in advance, there is no easy way to guarantee that the
+output buffer will be big enough. You may of course make
+arrangements in your code to record the size of the uncompressed
+data, but such a mechanism is beyond the scope of this
+library.</p>
+<p><code class="computeroutput">BZ2_bzBuffToBuffDecompress</code>
+will not write data at or beyond
+<code class="computeroutput">dest[*destLen]</code>, even in case of
+buffer overflow.</p>
+<p>Possible return values:</p>
+<pre class="programlisting">BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if dest is NULL or destLen is NULL
+ or small != 0 &amp;&amp; small != 1
+ or verbosity &lt; 0 or verbosity &gt; 4
+BZ_MEM_ERROR
+ if insufficient memory is available
+BZ_OUTBUFF_FULL
+ if the size of the compressed data exceeds *destLen
+BZ_DATA_ERROR
+ if a data integrity error was detected in the compressed data
+BZ_DATA_ERROR_MAGIC
+ if the compressed data doesn't begin with the right magic bytes
+BZ_UNEXPECTED_EOF
+ if the compressed data ends unexpectedly
+BZ_OK
+ otherwise</pre>
+</div>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="zlib-compat"></a>3.6. <code class="computeroutput">zlib</code> compatibility functions</h2></div></div></div>
+<p>Yoshioka Tsuneo has contributed some functions to give
+better <code class="computeroutput">zlib</code> compatibility.
+These functions are <code class="computeroutput">BZ2_bzopen</code>,
+<code class="computeroutput">BZ2_bzread</code>,
+<code class="computeroutput">BZ2_bzwrite</code>,
+<code class="computeroutput">BZ2_bzflush</code>,
+<code class="computeroutput">BZ2_bzclose</code>,
+<code class="computeroutput">BZ2_bzerror</code> and
+<code class="computeroutput">BZ2_bzlibVersion</code>. These
+functions are not (yet) officially part of the library. If they
+break, you get to keep all the pieces. Nevertheless, I think
+they work ok.</p>
+<pre class="programlisting">typedef void BZFILE;
+
+const char * BZ2_bzlibVersion ( void );</pre>
+<p>Returns a string indicating the library version.</p>
+<pre class="programlisting">BZFILE * BZ2_bzopen ( const char *path, const char *mode );
+BZFILE * BZ2_bzdopen ( int fd, const char *mode );</pre>
+<p>Opens a <code class="computeroutput">.bz2</code> file for
+reading or writing, using either its name or a pre-existing file
+descriptor. Analogous to <code class="computeroutput">fopen</code>
+and <code class="computeroutput">fdopen</code>.</p>
+<pre class="programlisting">int BZ2_bzread ( BZFILE* b, void* buf, int len );
+int BZ2_bzwrite ( BZFILE* b, void* buf, int len );</pre>
+<p>Reads/writes data from/to a previously opened
+<code class="computeroutput">BZFILE</code>. Analogous to
+<code class="computeroutput">fread</code> and
+<code class="computeroutput">fwrite</code>.</p>
+<pre class="programlisting">int BZ2_bzflush ( BZFILE* b );
+void BZ2_bzclose ( BZFILE* b );</pre>
+<p>Flushes/closes a <code class="computeroutput">BZFILE</code>.
+<code class="computeroutput">BZ2_bzflush</code> doesn't actually do
+anything. Analogous to <code class="computeroutput">fflush</code>
+and <code class="computeroutput">fclose</code>.</p>
+<pre class="programlisting">const char * BZ2_bzerror ( BZFILE *b, int *errnum )</pre>
+<p>Returns a string describing the more recent error status of
+<code class="computeroutput">b</code>, and also sets
+<code class="computeroutput">*errnum</code> to its numerical
+value.</p>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="stdio-free"></a>3.7. Using the library in a <code class="computeroutput">stdio</code>-free environment</h2></div></div></div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="stdio-bye"></a>3.7.1. Getting rid of <code class="computeroutput">stdio</code></h3></div></div></div>
+<p>In a deeply embedded application, you might want to use
+just the memory-to-memory functions. You can do this
+conveniently by compiling the library with preprocessor symbol
+<code class="computeroutput">BZ_NO_STDIO</code> defined. Doing this
+gives you a library containing only the following eight
+functions:</p>
+<p><code class="computeroutput">BZ2_bzCompressInit</code>,
+<code class="computeroutput">BZ2_bzCompress</code>,
+<code class="computeroutput">BZ2_bzCompressEnd</code>
+<code class="computeroutput">BZ2_bzDecompressInit</code>,
+<code class="computeroutput">BZ2_bzDecompress</code>,
+<code class="computeroutput">BZ2_bzDecompressEnd</code>
+<code class="computeroutput">BZ2_bzBuffToBuffCompress</code>,
+<code class="computeroutput">BZ2_bzBuffToBuffDecompress</code></p>
+<p>When compiled like this, all functions will ignore
+<code class="computeroutput">verbosity</code> settings.</p>
+</div>
+<div class="sect2" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="critical-error"></a>3.7.2. Critical error handling</h3></div></div></div>
+<p><code class="computeroutput">libbzip2</code> contains a number
+of internal assertion checks which should, needless to say, never
+be activated. Nevertheless, if an assertion should fail,
+behaviour depends on whether or not the library was compiled with
+<code class="computeroutput">BZ_NO_STDIO</code> set.</p>
+<p>For a normal compile, an assertion failure yields the
+message:</p>
+<div class="blockquote"><blockquote class="blockquote">
+<p>bzip2/libbzip2: internal error number N.</p>
+<p>This is a bug in bzip2/libbzip2, 1.0.5 of 10 December 2007.
+Please report it to me at: jseward@bzip.org. If this happened
+when you were using some program which uses libbzip2 as a
+component, you should also report this bug to the author(s)
+of that program. Please make an effort to report this bug;
+timely and accurate bug reports eventually lead to higher
+quality software. Thanks. Julian Seward, 10 December 2007.
+</p>
+</blockquote></div>
+<p>where <code class="computeroutput">N</code> is some error code
+number. If <code class="computeroutput">N == 1007</code>, it also
+prints some extra text advising the reader that unreliable memory
+is often associated with internal error 1007. (This is a
+frequently-observed-phenomenon with versions 1.0.0/1.0.1).</p>
+<p><code class="computeroutput">exit(3)</code> is then
+called.</p>
+<p>For a <code class="computeroutput">stdio</code>-free library,
+assertion failures result in a call to a function declared
+as:</p>
+<pre class="programlisting">extern void bz_internal_error ( int errcode );</pre>
+<p>The relevant code is passed as a parameter. You should
+supply such a function.</p>
+<p>In either case, once an assertion failure has occurred, any
+<code class="computeroutput">bz_stream</code> records involved can
+be regarded as invalid. You should not attempt to resume normal
+operation with them.</p>
+<p>You may, of course, change critical error handling to suit
+your needs. As I said above, critical errors indicate bugs in
+the library and should not occur. All "normal" error situations
+are indicated via error return codes from functions, and can be
+recovered from.</p>
+</div>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="win-dll"></a>3.8. Making a Windows DLL</h2></div></div></div>
+<p>Everything related to Windows has been contributed by
+Yoshioka Tsuneo
+(<code class="computeroutput">tsuneo@rr.iij4u.or.jp</code>), so
+you should send your queries to him (but perhaps Cc: me,
+<code class="computeroutput">jseward@bzip.org</code>).</p>
+<p>My vague understanding of what to do is: using Visual C++
+5.0, open the project file
+<code class="computeroutput">libbz2.dsp</code>, and build. That's
+all.</p>
+<p>If you can't open the project file for some reason, make a
+new one, naming these files:
+<code class="computeroutput">blocksort.c</code>,
+<code class="computeroutput">bzlib.c</code>,
+<code class="computeroutput">compress.c</code>,
+<code class="computeroutput">crctable.c</code>,
+<code class="computeroutput">decompress.c</code>,
+<code class="computeroutput">huffman.c</code>,
+<code class="computeroutput">randtable.c</code> and
+<code class="computeroutput">libbz2.def</code>. You will also need
+to name the header files <code class="computeroutput">bzlib.h</code>
+and <code class="computeroutput">bzlib_private.h</code>.</p>
+<p>If you don't use VC++, you may need to define the
+proprocessor symbol
+<code class="computeroutput">_WIN32</code>.</p>
+<p>Finally, <code class="computeroutput">dlltest.c</code> is a
+sample program using the DLL. It has a project file,
+<code class="computeroutput">dlltest.dsp</code>.</p>
+<p>If you just want a makefile for Visual C, have a look at
+<code class="computeroutput">makefile.msc</code>.</p>
+<p>Be aware that if you compile
+<code class="computeroutput">bzip2</code> itself on Win32, you must
+set <code class="computeroutput">BZ_UNIX</code> to 0 and
+<code class="computeroutput">BZ_LCCWIN32</code> to 1, in the file
+<code class="computeroutput">bzip2.c</code>, before compiling.
+Otherwise the resulting binary won't work correctly.</p>
+<p>I haven't tried any of this stuff myself, but it all looks
+plausible.</p>
+</div>
+</div>
+<div class="chapter" lang="en">
+<div class="titlepage"><div><div><h2 class="title">
+<a name="misc"></a>4. Miscellanea</h2></div></div></div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="sect1"><a href="#limits">4.1. Limitations of the compressed file format</a></span></dt>
+<dt><span class="sect1"><a href="#port-issues">4.2. Portability issues</a></span></dt>
+<dt><span class="sect1"><a href="#bugs">4.3. Reporting bugs</a></span></dt>
+<dt><span class="sect1"><a href="#package">4.4. Did you get the right package?</a></span></dt>
+<dt><span class="sect1"><a href="#reading">4.5. Further Reading</a></span></dt>
+</dl>
+</div>
+<p>These are just some random thoughts of mine. Your mileage
+may vary.</p>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="limits"></a>4.1. Limitations of the compressed file format</h2></div></div></div>
+<p><code class="computeroutput">bzip2-1.0.X</code>,
+<code class="computeroutput">0.9.5</code> and
+<code class="computeroutput">0.9.0</code> use exactly the same file
+format as the original version,
+<code class="computeroutput">bzip2-0.1</code>. This decision was
+made in the interests of stability. Creating yet another
+incompatible compressed file format would create further
+confusion and disruption for users.</p>
+<p>Nevertheless, this is not a painless decision. Development
+work since the release of
+<code class="computeroutput">bzip2-0.1</code> in August 1997 has
+shown complexities in the file format which slow down
+decompression and, in retrospect, are unnecessary. These
+are:</p>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc"><p>The run-length encoder, which is the first of the
+ compression transformations, is entirely irrelevant. The
+ original purpose was to protect the sorting algorithm from the
+ very worst case input: a string of repeated symbols. But
+ algorithm steps Q6a and Q6b in the original Burrows-Wheeler
+ technical report (SRC-124) show how repeats can be handled
+ without difficulty in block sorting.</p></li>
+<li style="list-style-type: disc">
+<p>The randomisation mechanism doesn't really need to be
+ there. Udi Manber and Gene Myers published a suffix array
+ construction algorithm a few years back, which can be employed
+ to sort any block, no matter how repetitive, in O(N log N)
+ time. Subsequent work by Kunihiko Sadakane has produced a
+ derivative O(N (log N)^2) algorithm which usually outperforms
+ the Manber-Myers algorithm.</p>
+<p>I could have changed to Sadakane's algorithm, but I find
+ it to be slower than <code class="computeroutput">bzip2</code>'s
+ existing algorithm for most inputs, and the randomisation
+ mechanism protects adequately against bad cases. I didn't
+ think it was a good tradeoff to make. Partly this is due to
+ the fact that I was not flooded with email complaints about
+ <code class="computeroutput">bzip2-0.1</code>'s performance on
+ repetitive data, so perhaps it isn't a problem for real
+ inputs.</p>
+<p>Probably the best long-term solution, and the one I have
+ incorporated into 0.9.5 and above, is to use the existing
+ sorting algorithm initially, and fall back to a O(N (log N)^2)
+ algorithm if the standard algorithm gets into
+ difficulties.</p>
+</li>
+<li style="list-style-type: disc"><p>The compressed file format was never designed to be
+ handled by a library, and I have had to jump though some hoops
+ to produce an efficient implementation of decompression. It's
+ a bit hairy. Try passing
+ <code class="computeroutput">decompress.c</code> through the C
+ preprocessor and you'll see what I mean. Much of this
+ complexity could have been avoided if the compressed size of
+ each block of data was recorded in the data stream.</p></li>
+<li style="list-style-type: disc"><p>An Adler-32 checksum, rather than a CRC32 checksum,
+ would be faster to compute.</p></li>
+</ul></div>
+<p>It would be fair to say that the
+<code class="computeroutput">bzip2</code> format was frozen before I
+properly and fully understood the performance consequences of
+doing so.</p>
+<p>Improvements which I was able to incorporate into 0.9.0,
+despite using the same file format, are:</p>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc"><p>Single array implementation of the inverse BWT. This
+ significantly speeds up decompression, presumably because it
+ reduces the number of cache misses.</p></li>
+<li style="list-style-type: disc"><p>Faster inverse MTF transform for large MTF values.
+ The new implementation is based on the notion of sliding blocks
+ of values.</p></li>
+<li style="list-style-type: disc"><p><code class="computeroutput">bzip2-0.9.0</code> now reads
+ and writes files with <code class="computeroutput">fread</code>
+ and <code class="computeroutput">fwrite</code>; version 0.1 used
+ <code class="computeroutput">putc</code> and
+ <code class="computeroutput">getc</code>. Duh! Well, you live
+ and learn.</p></li>
+</ul></div>
+<p>Further ahead, it would be nice to be able to do random
+access into files. This will require some careful design of
+compressed file formats.</p>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="port-issues"></a>4.2. Portability issues</h2></div></div></div>
+<p>After some consideration, I have decided not to use GNU
+<code class="computeroutput">autoconf</code> to configure 0.9.5 or
+1.0.</p>
+<p><code class="computeroutput">autoconf</code>, admirable and
+wonderful though it is, mainly assists with portability problems
+between Unix-like platforms. But
+<code class="computeroutput">bzip2</code> doesn't have much in the
+way of portability problems on Unix; most of the difficulties
+appear when porting to the Mac, or to Microsoft's operating
+systems. <code class="computeroutput">autoconf</code> doesn't help
+in those cases, and brings in a whole load of new
+complexity.</p>
+<p>Most people should be able to compile the library and
+program under Unix straight out-of-the-box, so to speak,
+especially if you have a version of GNU C available.</p>
+<p>There are a couple of
+<code class="computeroutput">__inline__</code> directives in the
+code. GNU C (<code class="computeroutput">gcc</code>) should be
+able to handle them. If you're not using GNU C, your C compiler
+shouldn't see them at all. If your compiler does, for some
+reason, see them and doesn't like them, just
+<code class="computeroutput">#define</code>
+<code class="computeroutput">__inline__</code> to be
+<code class="computeroutput">/* */</code>. One easy way to do this
+is to compile with the flag
+<code class="computeroutput">-D__inline__=</code>, which should be
+understood by most Unix compilers.</p>
+<p>If you still have difficulties, try compiling with the
+macro <code class="computeroutput">BZ_STRICT_ANSI</code> defined.
+This should enable you to build the library in a strictly ANSI
+compliant environment. Building the program itself like this is
+dangerous and not supported, since you remove
+<code class="computeroutput">bzip2</code>'s checks against
+compressing directories, symbolic links, devices, and other
+not-really-a-file entities. This could cause filesystem
+corruption!</p>
+<p>One other thing: if you create a
+<code class="computeroutput">bzip2</code> binary for public distribution,
+please consider linking it statically (<code class="computeroutput">gcc
+-static</code>). This avoids all sorts of library-version
+issues that others may encounter later on.</p>
+<p>If you build <code class="computeroutput">bzip2</code> on
+Win32, you must set <code class="computeroutput">BZ_UNIX</code> to 0
+and <code class="computeroutput">BZ_LCCWIN32</code> to 1, in the
+file <code class="computeroutput">bzip2.c</code>, before compiling.
+Otherwise the resulting binary won't work correctly.</p>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="bugs"></a>4.3. Reporting bugs</h2></div></div></div>
+<p>I tried pretty hard to make sure
+<code class="computeroutput">bzip2</code> is bug free, both by
+design and by testing. Hopefully you'll never need to read this
+section for real.</p>
+<p>Nevertheless, if <code class="computeroutput">bzip2</code> dies
+with a segmentation fault, a bus error or an internal assertion
+failure, it will ask you to email me a bug report. Experience from
+years of feedback of bzip2 users indicates that almost all these
+problems can be traced to either compiler bugs or hardware
+problems.</p>
+<div class="itemizedlist"><ul type="bullet">
+<li style="list-style-type: disc">
+<p>Recompile the program with no optimisation, and
+ see if it works. And/or try a different compiler. I heard all
+ sorts of stories about various flavours of GNU C (and other
+ compilers) generating bad code for
+ <code class="computeroutput">bzip2</code>, and I've run across two
+ such examples myself.</p>
+<p>2.7.X versions of GNU C are known to generate bad code
+ from time to time, at high optimisation levels. If you get
+ problems, try using the flags
+ <code class="computeroutput">-O2</code>
+ <code class="computeroutput">-fomit-frame-pointer</code>
+ <code class="computeroutput">-fno-strength-reduce</code>. You
+ should specifically <span class="emphasis"><em>not</em></span> use
+ <code class="computeroutput">-funroll-loops</code>.</p>
+<p>You may notice that the Makefile runs six tests as part
+ of the build process. If the program passes all of these, it's
+ a pretty good (but not 100%) indication that the compiler has
+ done its job correctly.</p>
+</li>
+<li style="list-style-type: disc">
+<p>If <code class="computeroutput">bzip2</code>
+ crashes randomly, and the crashes are not repeatable, you may
+ have a flaky memory subsystem.
+ <code class="computeroutput">bzip2</code> really hammers your
+ memory hierarchy, and if it's a bit marginal, you may get these
+ problems. Ditto if your disk or I/O subsystem is slowly
+ failing. Yup, this really does happen.</p>
+<p>Try using a different machine of the same type, and see
+ if you can repeat the problem.</p>
+</li>
+<li style="list-style-type: disc"><p>This isn't really a bug, but ... If
+ <code class="computeroutput">bzip2</code> tells you your file is
+ corrupted on decompression, and you obtained the file via FTP,
+ there is a possibility that you forgot to tell FTP to do a
+ binary mode transfer. That absolutely will cause the file to
+ be non-decompressible. You'll have to transfer it
+ again.</p></li>
+</ul></div>
+<p>If you've incorporated
+<code class="computeroutput">libbzip2</code> into your own program
+and are getting problems, please, please, please, check that the
+parameters you are passing in calls to the library, are correct,
+and in accordance with what the documentation says is allowable.
+I have tried to make the library robust against such problems,
+but I'm sure I haven't succeeded.</p>
+<p>Finally, if the above comments don't help, you'll have to
+send me a bug report. Now, it's just amazing how many people
+will send me a bug report saying something like:</p>
+<pre class="programlisting">bzip2 crashed with segmentation fault on my machine</pre>
+<p>and absolutely nothing else. Needless to say, a such a
+report is <span class="emphasis"><em>totally, utterly, completely and
+comprehensively 100% useless; a waste of your time, my time, and
+net bandwidth</em></span>. With no details at all, there's no way
+I can possibly begin to figure out what the problem is.</p>
+<p>The rules of the game are: facts, facts, facts. Don't omit
+them because "oh, they won't be relevant". At the bare
+minimum:</p>
+<pre class="programlisting">Machine type. Operating system version.
+Exact version of bzip2 (do bzip2 -V).
+Exact version of the compiler used.
+Flags passed to the compiler.</pre>
+<p>However, the most important single thing that will help me
+is the file that you were trying to compress or decompress at the
+time the problem happened. Without that, my ability to do
+anything more than speculate about the cause, is limited.</p>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="package"></a>4.4. Did you get the right package?</h2></div></div></div>
+<p><code class="computeroutput">bzip2</code> is a resource hog.
+It soaks up large amounts of CPU cycles and memory. Also, it
+gives very large latencies. In the worst case, you can feed many
+megabytes of uncompressed data into the library before getting
+any compressed output, so this probably rules out applications
+requiring interactive behaviour.</p>
+<p>These aren't faults of my implementation, I hope, but more
+an intrinsic property of the Burrows-Wheeler transform
+(unfortunately). Maybe this isn't what you want.</p>
+<p>If you want a compressor and/or library which is faster,
+uses less memory but gets pretty good compression, and has
+minimal latency, consider Jean-loup Gailly's and Mark Adler's
+work, <code class="computeroutput">zlib-1.2.1</code> and
+<code class="computeroutput">gzip-1.2.4</code>. Look for them at
+<a href="http://www.zlib.org" target="_top">http://www.zlib.org</a> and
+<a href="http://www.gzip.org" target="_top">http://www.gzip.org</a>
+respectively.</p>
+<p>For something faster and lighter still, you might try Markus F
+X J Oberhumer's <code class="computeroutput">LZO</code> real-time
+compression/decompression library, at
+<a href="http://www.oberhumer.com/opensource" target="_top">http://www.oberhumer.com/opensource</a>.</p>
+</div>
+<div class="sect1" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="reading"></a>4.5. Further Reading</h2></div></div></div>
+<p><code class="computeroutput">bzip2</code> is not research
+work, in the sense that it doesn't present any new ideas.
+Rather, it's an engineering exercise based on existing
+ideas.</p>
+<p>Four documents describe essentially all the ideas behind
+<code class="computeroutput">bzip2</code>:</p>
+<div class="literallayout"><p>Michael Burrows and D. J. Wheeler:<br>
+  "A block-sorting lossless data compression algorithm"<br>
+   10th May 1994. <br>
+   Digital SRC Research Report 124.<br>
+   ftp://ftp.digital.com/pub/DEC/SRC/research-reports/SRC-124.ps.gz<br>
+   If you have trouble finding it, try searching at the<br>
+   New Zealand Digital Library, http://www.nzdl.org.<br>
+<br>
+Daniel S. Hirschberg and Debra A. LeLewer<br>
+  "Efficient Decoding of Prefix Codes"<br>
+   Communications of the ACM, April 1990, Vol 33, Number 4.<br>
+   You might be able to get an electronic copy of this<br>
+   from the ACM Digital Library.<br>
+<br>
+David J. Wheeler<br>
+   Program bred3.c and accompanying document bred3.ps.<br>
+   This contains the idea behind the multi-table Huffman coding scheme.<br>
+   ftp://ftp.cl.cam.ac.uk/users/djw3/<br>
+<br>
+Jon L. Bentley and Robert Sedgewick<br>
+  "Fast Algorithms for Sorting and Searching Strings"<br>
+   Available from Sedgewick's web page,<br>
+   www.cs.princeton.edu/~rs<br>
+</p></div>
+<p>The following paper gives valuable additional insights into
+the algorithm, but is not immediately the basis of any code used
+in bzip2.</p>
+<div class="literallayout"><p>Peter Fenwick:<br>
+   Block Sorting Text Compression<br>
+   Proceedings of the 19th Australasian Computer Science Conference,<br>
+     Melbourne, Australia.  Jan 31 - Feb 2, 1996.<br>
+   ftp://ftp.cs.auckland.ac.nz/pub/peter-f/ACSC96paper.ps</p></div>
+<p>Kunihiko Sadakane's sorting algorithm, mentioned above, is
+available from:</p>
+<div class="literallayout"><p>http://naomi.is.s.u-tokyo.ac.jp/~sada/papers/Sada98b.ps.gz<br>
+</p></div>
+<p>The Manber-Myers suffix array construction algorithm is
+described in a paper available from:</p>
+<div class="literallayout"><p>http://www.cs.arizona.edu/people/gene/PAPERS/suffix.ps<br>
+</p></div>
+<p>Finally, the following papers document some
+investigations I made into the performance of sorting
+and decompression algorithms:</p>
+<div class="literallayout"><p>Julian Seward<br>
+   On the Performance of BWT Sorting Algorithms<br>
+   Proceedings of the IEEE Data Compression Conference 2000<br>
+     Snowbird, Utah.  28-30 March 2000.<br>
+<br>
+Julian Seward<br>
+   Space-time Tradeoffs in the Inverse B-W Transform<br>
+   Proceedings of the IEEE Data Compression Conference 2001<br>
+     Snowbird, Utah.  27-29 March 2001.<br>
+</p></div>
+</div>
+</div>
+</div></body>
+</html>
diff --git a/Utilities/cmbzip2/manual.pdf b/Utilities/cmbzip2/manual.pdf
new file mode 100644
index 0000000000..10c10de7ac
--- /dev/null
+++ b/Utilities/cmbzip2/manual.pdf
Binary files differ
diff --git a/Utilities/cmbzip2/manual.ps b/Utilities/cmbzip2/manual.ps
new file mode 100644
index 0000000000..b8b610c812
--- /dev/null
+++ b/Utilities/cmbzip2/manual.ps
@@ -0,0 +1,82900 @@
+%!PS-Adobe-3.0
+%%Creator: xpdf/pdftops 3.01
+%%LanguageLevel: 2
+%%DocumentSuppliedResources: (atend)
+%%DocumentMedia: plain 612 792 0 () ()
+%%BoundingBox: 0 0 612 792
+%%Pages: 38
+%%EndComments
+%%BeginDefaults
+%%PageMedia: plain
+%%EndDefaults
+%%BeginProlog
+%%BeginResource: procset xpdf 3.01 0
+/xpdf 75 dict def xpdf begin
+% PDF special state
+/pdfDictSize 15 def
+/pdfSetup {
+ 3 1 roll 2 array astore
+ /setpagedevice where {
+ pop 3 dict begin
+ /PageSize exch def
+ /ImagingBBox null def
+ /Policies 1 dict dup begin /PageSize 3 def end def
+ { /Duplex true def } if
+ currentdict end setpagedevice
+ } {
+ pop pop
+ } ifelse
+} def
+/pdfStartPage {
+ pdfDictSize dict begin
+ /pdfFillCS [] def
+ /pdfFillXform {} def
+ /pdfStrokeCS [] def
+ /pdfStrokeXform {} def
+ /pdfFill [0] def
+ /pdfStroke [0] def
+ /pdfFillOP false def
+ /pdfStrokeOP false def
+ /pdfLastFill false def
+ /pdfLastStroke false def
+ /pdfTextMat [1 0 0 1 0 0] def
+ /pdfFontSize 0 def
+ /pdfCharSpacing 0 def
+ /pdfTextRender 0 def
+ /pdfTextRise 0 def
+ /pdfWordSpacing 0 def
+ /pdfHorizScaling 1 def
+ /pdfTextClipPath [] def
+} def
+/pdfEndPage { end } def
+% PDF color state
+/cs { /pdfFillXform exch def dup /pdfFillCS exch def
+ setcolorspace } def
+/CS { /pdfStrokeXform exch def dup /pdfStrokeCS exch def
+ setcolorspace } def
+/sc { pdfLastFill not { pdfFillCS setcolorspace } if
+ dup /pdfFill exch def aload pop pdfFillXform setcolor
+ /pdfLastFill true def /pdfLastStroke false def } def
+/SC { pdfLastStroke not { pdfStrokeCS setcolorspace } if
+ dup /pdfStroke exch def aload pop pdfStrokeXform setcolor
+ /pdfLastStroke true def /pdfLastFill false def } def
+/op { /pdfFillOP exch def
+ pdfLastFill { pdfFillOP setoverprint } if } def
+/OP { /pdfStrokeOP exch def
+ pdfLastStroke { pdfStrokeOP setoverprint } if } def
+/fCol {
+ pdfLastFill not {
+ pdfFillCS setcolorspace
+ pdfFill aload pop pdfFillXform setcolor
+ pdfFillOP setoverprint
+ /pdfLastFill true def /pdfLastStroke false def
+ } if
+} def
+/sCol {
+ pdfLastStroke not {
+ pdfStrokeCS setcolorspace
+ pdfStroke aload pop pdfStrokeXform setcolor
+ pdfStrokeOP setoverprint
+ /pdfLastStroke true def /pdfLastFill false def
+ } if
+} def
+% build a font
+/pdfMakeFont {
+ 4 3 roll findfont
+ 4 2 roll matrix scale makefont
+ dup length dict begin
+ { 1 index /FID ne { def } { pop pop } ifelse } forall
+ /Encoding exch def
+ currentdict
+ end
+ definefont pop
+} def
+/pdfMakeFont16 {
+ exch findfont
+ dup length dict begin
+ { 1 index /FID ne { def } { pop pop } ifelse } forall
+ /WMode exch def
+ currentdict
+ end
+ definefont pop
+} def
+% graphics state operators
+/q { gsave pdfDictSize dict begin } def
+/Q {
+ end grestore
+ /pdfLastFill where {
+ pop
+ pdfLastFill {
+ pdfFillOP setoverprint
+ } {
+ pdfStrokeOP setoverprint
+ } ifelse
+ } if
+} def
+/cm { concat } def
+/d { setdash } def
+/i { setflat } def
+/j { setlinejoin } def
+/J { setlinecap } def
+/M { setmiterlimit } def
+/w { setlinewidth } def
+% path segment operators
+/m { moveto } def
+/l { lineto } def
+/c { curveto } def
+/re { 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto
+ neg 0 rlineto closepath } def
+/h { closepath } def
+% path painting operators
+/S { sCol stroke } def
+/Sf { fCol stroke } def
+/f { fCol fill } def
+/f* { fCol eofill } def
+% clipping operators
+/W { clip newpath } def
+/W* { eoclip newpath } def
+% text state operators
+/Tc { /pdfCharSpacing exch def } def
+/Tf { dup /pdfFontSize exch def
+ dup pdfHorizScaling mul exch matrix scale
+ pdfTextMat matrix concatmatrix dup 4 0 put dup 5 0 put
+ exch findfont exch makefont setfont } def
+/Tr { /pdfTextRender exch def } def
+/Ts { /pdfTextRise exch def } def
+/Tw { /pdfWordSpacing exch def } def
+/Tz { /pdfHorizScaling exch def } def
+% text positioning operators
+/Td { pdfTextMat transform moveto } def
+/Tm { /pdfTextMat exch def } def
+% text string operators
+/cshow where {
+ pop
+ /cshow2 {
+ dup {
+ pop pop
+ 1 string dup 0 3 index put 3 index exec
+ } exch cshow
+ pop pop
+ } def
+}{
+ /cshow2 {
+ currentfont /FontType get 0 eq {
+ 0 2 2 index length 1 sub {
+ 2 copy get exch 1 add 2 index exch get
+ 2 copy exch 256 mul add
+ 2 string dup 0 6 5 roll put dup 1 5 4 roll put
+ 3 index exec
+ } for
+ } {
+ dup {
+ 1 string dup 0 3 index put 3 index exec
+ } forall
+ } ifelse
+ pop pop
+ } def
+} ifelse
+/awcp {
+ exch {
+ false charpath
+ 5 index 5 index rmoveto
+ 6 index eq { 7 index 7 index rmoveto } if
+ } exch cshow2
+ 6 {pop} repeat
+} def
+/Tj {
+ fCol
+ 1 index stringwidth pdfTextMat idtransform pop
+ sub 1 index length dup 0 ne { div } { pop pop 0 } ifelse
+ pdfWordSpacing pdfHorizScaling mul 0 pdfTextMat dtransform 32
+ 4 3 roll pdfCharSpacing pdfHorizScaling mul add 0
+ pdfTextMat dtransform
+ 6 5 roll Tj1
+} def
+/Tj16 {
+ fCol
+ 2 index stringwidth pdfTextMat idtransform pop
+ sub exch div
+ pdfWordSpacing pdfHorizScaling mul 0 pdfTextMat dtransform 32
+ 4 3 roll pdfCharSpacing pdfHorizScaling mul add 0
+ pdfTextMat dtransform
+ 6 5 roll Tj1
+} def
+/Tj16V {
+ fCol
+ 2 index stringwidth pdfTextMat idtransform exch pop
+ sub exch div
+ 0 pdfWordSpacing pdfTextMat dtransform 32
+ 4 3 roll pdfCharSpacing add 0 exch
+ pdfTextMat dtransform
+ 6 5 roll Tj1
+} def
+/Tj1 {
+ 0 pdfTextRise pdfTextMat dtransform rmoveto
+ currentpoint 8 2 roll
+ pdfTextRender 1 and 0 eq {
+ 6 copy awidthshow
+ } if
+ pdfTextRender 3 and dup 1 eq exch 2 eq or {
+ 7 index 7 index moveto
+ 6 copy
+ currentfont /FontType get 3 eq { fCol } { sCol } ifelse
+ false awcp currentpoint stroke moveto
+ } if
+ pdfTextRender 4 and 0 ne {
+ 8 6 roll moveto
+ false awcp
+ /pdfTextClipPath [ pdfTextClipPath aload pop
+ {/moveto cvx}
+ {/lineto cvx}
+ {/curveto cvx}
+ {/closepath cvx}
+ pathforall ] def
+ currentpoint newpath moveto
+ } {
+ 8 {pop} repeat
+ } ifelse
+ 0 pdfTextRise neg pdfTextMat dtransform rmoveto
+} def
+/TJm { pdfFontSize 0.001 mul mul neg 0
+ pdfTextMat dtransform rmoveto } def
+/TJmV { pdfFontSize 0.001 mul mul neg 0 exch
+ pdfTextMat dtransform rmoveto } def
+/Tclip { pdfTextClipPath cvx exec clip newpath
+ /pdfTextClipPath [] def } def
+% Level 2 image operators
+/pdfImBuf 100 string def
+/pdfIm {
+ image
+ { currentfile pdfImBuf readline
+ not { pop exit } if
+ (%-EOD-) eq { exit } if } loop
+} def
+/pdfImM {
+ fCol imagemask
+ { currentfile pdfImBuf readline
+ not { pop exit } if
+ (%-EOD-) eq { exit } if } loop
+} def
+/pdfImClip {
+ gsave
+ 0 2 4 index length 1 sub {
+ dup 4 index exch 2 copy
+ get 5 index div put
+ 1 add 3 index exch 2 copy
+ get 3 index div put
+ } for
+ pop pop rectclip
+} def
+/pdfImClipEnd { grestore } def
+% shading operators
+/colordelta {
+ false 0 1 3 index length 1 sub {
+ dup 4 index exch get 3 index 3 2 roll get sub abs 0.004 gt {
+ pop true
+ } if
+ } for
+ exch pop exch pop
+} def
+/funcCol { func n array astore } def
+/funcSH {
+ dup 0 eq {
+ true
+ } {
+ dup 6 eq {
+ false
+ } {
+ 4 index 4 index funcCol dup
+ 6 index 4 index funcCol dup
+ 3 1 roll colordelta 3 1 roll
+ 5 index 5 index funcCol dup
+ 3 1 roll colordelta 3 1 roll
+ 6 index 8 index funcCol dup
+ 3 1 roll colordelta 3 1 roll
+ colordelta or or or
+ } ifelse
+ } ifelse
+ {
+ 1 add
+ 4 index 3 index add 0.5 mul exch 4 index 3 index add 0.5 mul exch
+ 6 index 6 index 4 index 4 index 4 index funcSH
+ 2 index 6 index 6 index 4 index 4 index funcSH
+ 6 index 2 index 4 index 6 index 4 index funcSH
+ 5 3 roll 3 2 roll funcSH pop pop
+ } {
+ pop 3 index 2 index add 0.5 mul 3 index 2 index add 0.5 mul
+ funcCol sc
+ dup 4 index exch mat transform m
+ 3 index 3 index mat transform l
+ 1 index 3 index mat transform l
+ mat transform l pop pop h f*
+ } ifelse
+} def
+/axialCol {
+ dup 0 lt {
+ pop t0
+ } {
+ dup 1 gt {
+ pop t1
+ } {
+ dt mul t0 add
+ } ifelse
+ } ifelse
+ func n array astore
+} def
+/axialSH {
+ dup 0 eq {
+ true
+ } {
+ dup 8 eq {
+ false
+ } {
+ 2 index axialCol 2 index axialCol colordelta
+ } ifelse
+ } ifelse
+ {
+ 1 add 3 1 roll 2 copy add 0.5 mul
+ dup 4 3 roll exch 4 index axialSH
+ exch 3 2 roll axialSH
+ } {
+ pop 2 copy add 0.5 mul axialCol sc
+ exch dup dx mul x0 add exch dy mul y0 add
+ 3 2 roll dup dx mul x0 add exch dy mul y0 add
+ dx abs dy abs ge {
+ 2 copy yMin sub dy mul dx div add yMin m
+ yMax sub dy mul dx div add yMax l
+ 2 copy yMax sub dy mul dx div add yMax l
+ yMin sub dy mul dx div add yMin l
+ h f*
+ } {
+ exch 2 copy xMin sub dx mul dy div add xMin exch m
+ xMax sub dx mul dy div add xMax exch l
+ exch 2 copy xMax sub dx mul dy div add xMax exch l
+ xMin sub dx mul dy div add xMin exch l
+ h f*
+ } ifelse
+ } ifelse
+} def
+/radialCol {
+ dup t0 lt {
+ pop t0
+ } {
+ dup t1 gt {
+ pop t1
+ } if
+ } ifelse
+ func n array astore
+} def
+/radialSH {
+ dup 0 eq {
+ true
+ } {
+ dup 8 eq {
+ false
+ } {
+ 2 index dt mul t0 add radialCol
+ 2 index dt mul t0 add radialCol colordelta
+ } ifelse
+ } ifelse
+ {
+ 1 add 3 1 roll 2 copy add 0.5 mul
+ dup 4 3 roll exch 4 index radialSH
+ exch 3 2 roll radialSH
+ } {
+ pop 2 copy add 0.5 mul dt mul t0 add axialCol sc
+ exch dup dx mul x0 add exch dup dy mul y0 add exch dr mul r0 add
+ 0 360 arc h
+ dup dx mul x0 add exch dup dy mul y0 add exch dr mul r0 add
+ 0 360 arc h f*
+ } ifelse
+} def
+end
+%%EndResource
+%%EndProlog
+%%BeginSetup
+xpdf begin
+%%BeginResource: font DTUUHP+NimbusSanL-Bold
+%!PS-AdobeFont-1.0: NimbusSanL-Bold 1.05
+%%CreationDate: Wed Dec 22 1999
+% Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development
+% (URW)++,Copyright 1999 by (URW)++ Design & Development
+% See the file COPYING (GNU General Public License) for license conditions.
+% As a special exception, permission is granted to include this font
+% program in a Postscript or PDF file that consists of a document that
+% contains text to be displayed or printed using this font, regardless
+% of the conditions or license applying to the document itself.
+12 dict begin
+/FontInfo 10 dict dup begin
+/version (1.05) readonly def
+/Notice ((URW)++,Copyright 1999 by (URW)++ Design & Development. See the file COPYING (GNU General Public License) for license conditions. As a special exception, permission is granted to include this font program in a Postscript or PDF file that consists of a document that contains text to be displayed or printed using this font, regardless of the conditions or license applying to the document itself.) readonly def
+/Copyright (Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development) readonly def
+/FullName (Nimbus Sans L Bold) readonly def
+/FamilyName (Nimbus Sans L) readonly def
+/Weight (Bold) readonly def
+/ItalicAngle 0.0 def
+/isFixedPitch false def
+/UnderlinePosition -155 def
+/UnderlineThickness 69 def
+end readonly def
+/FontName /DTUUHP+NimbusSanL-Bold def
+/PaintType 0 def
+/WMode 0 def
+/FontBBox {-173 -307 1003 949} readonly def
+/FontType 1 def
+/FontMatrix [0.001 0.0 0.0 0.001 0.0 0.0] readonly def
+/Encoding StandardEncoding def
+currentdict end
+currentfile eexec
+d9d66f633b846a989b9974b0179fc6cc445bc2c03103c68570a7b354a4a280ae
+6fbf7f9888e039ab60fcaf852eb4ce3afeb979d5ea70fde44a2ae5c8c0166c27
+bf9665eea11c7d2329c1a211dd26bb372be5822f5ea70d99eb578c7befd44cdf
+045a363056e5e1cc51525ea6fc061dcebb337208eff729802376a2801424f670
+0e7e6397b28f15bc10b40012b0a3eaeb2693e8f7f627c4c9c7c6c5bff105c1e4
+1b2b9e8f09253b76040d268b80719e1b3f5a55ab7b8d62a63193c4ae94c086c1
+552833ddd8f116b5df33205ae709b3aa63da7bebb165b67281827b48fb5edbed
+02a1a5c0784fc57d3487daa59520bada1be3fb9795669924321ce4f466cd8e3f
+7e8ec2494aee80e2dd7a48a6861af5b9f0ccaa4a2fe2b03498eacacd6b9c39c6
+a8f2e39e06bbb061cf2ec380a32efad0b790974bb5cc3daf0992471456967362
+77de34813f27abe99302f86bb4d293a37f84667e7f3dfee4cfe9d1a676a5728c
+aeb5222ff50da97e74b2cdebf725fbca7015a188891c8a376b9dd8a642c4b184
+b1bbf3f376a6d6e31ef1c8354ddf8039cb20faabcb34d4749b3c8c8d6972ceb1
+06b8a5aae3ae40a91f1f2b1155681a9cc933f87528c99a2b0268b43a3e829e7f
+3bd863cb52950773bd9b0731dc4992541d7de7a055ca65ddd2317f1705c20d1f
+93291bcc254cbaba425c032b3b15050d41da14ffe1b3d684eea428095a01e931
+98d4f849b239ad9d79f4502f0271affb0c297f2f347bfb9c137782646f648f77
+0076b85f5a929fcdea2703333f6918b8f125627f8b505c688e30f258ded1aecf
+2c86edcd88c29249a8081731737195fab7adbb54743bd66511194dee2516959b
+a20701e2d97342248297425491f6c9471ec9a98e630d734dac19721f0b324432
+c8d7a0b751453f89f7008ba37bc48e0831ee3ecbd8a0a292d63cfc890b28f695
+9e29ac3b4ddb78a6883b9272ce34a012a82adec0b6b641e3940a438a098ccfbf
+c50544b94facfd9d7ae09ad0632015f81d2f77fc6d80a42ec11d67d8a91c376c
+13c8e3444cdfde4d2a1ed021410f4d6a4e97804ae949bd913094d23108c9d384
+56f11025e2d24939114b6bcf579a0315c52f3ca1bcc2860fc1a0b9fb8a37ae2f
+c20c0fd44d215fc2af737fd0339b070d54e664021240071c665de4170dfa182d
+4e385685fb41a2d85888b1149e9a766cb4f309b4e2baa28cf1f8cc12c4b19e33
+f046ce97b53deb549fea96cf6ce66357c4904b7932f5b1ce03cfe3a10c976b9c
+c9ad11d7a02816f8e11666ca8b3ee1411df2ca94172659bad929e3e3e5248f48
+0690cec6d8f7061608cf2672f65abdc96b4fca84d5c847440cf9523d3bf23f6b
+d4365582e4b187b6a1a0282ed323bf221edd0a4ce11ce7eda738d1af48b2e19f
+eb3da1664de99c447c35dfd45069fded1fcd70b4a6855e91ffbd7146efe88012
+0bff1d6d1acb53d5e07fb5795f561a4a3e953bba7c03a9762adae18e58dce6b3
+b1a703122ef3b16963ac7cb9682ce60e17947e7e675d19901c7e8272ce4c9fdf
+536abdffa429b820a82aee9a73d7dcf77dde4d8e251cb3b3a5b0a91c0fcd7fbb
+ead7a812ff194fd049f28b82f4c2d73e41cc73c1c9f668931a2c7eba5400a1b9
+0902efe6792f207136e1e16b41794e6cbf7316889a602d35c37ef36dec95af26
+e9bb0900456f2ebf2705ecce7b2ed90343d23e006ecb282d4b3629bb0c3892f3
+ff9c17fe6c5fab68358e1cd44aff021948ac9fb8410a3de22e0a01e367c52470
+2a8cfd284cf9e8f505d5dbd7bbe242fe071fea0094a55ed1cd7c9be6b7c56c98
+16ad1985fb7624f5e48cf6c0c2ed85b466f64c52f017b20cdabb85d24452e086
+3942362e764a2bda0f6c1b24426e302ddc4403a087efb2850cf3275c7b24275a
+ae270f212831f4c4a5d95deab61923ca126e587e8f5ed4f2d5738f06e8c4f911
+b346b8ecdac481dedd2f546305a7cd63cb67d40093c618fbbdf498c8d7ead8c7
+1f5f022d0bbcfaa8670e3b3b999a1697c947af38d7e1a360e3f0825a9aa77840
+d7a9dfd575ce2f04d308f7c553ebf569ac84f2c12aa0869ce107c713a3cce624
+5059bfb3f5aa27d10e337086144ab09286be3825a3482c5422454c6a9cbbf205
+833316780eb88302796fc427a0fb9e53a7bf24577feb3fa5d85cb6344f908007
+183522d3c760c11fc7da8d14bb5dd800576a6b4d1b991c1bf3db0f9ca2ac5d22
+91079a199f2f6e6dc68213d33ea893b74f6aff30ed1b51f8b53a015ffd4d2076
+b71f73225b151cfcf11e2a2917cf1b3f60e2b4d442307c394e1625f7e60eb12a
+f2eb9ca7b17b082f1664d09cb7a3f38aea99a13f659089426126f47fad5b6dc7
+64101cd437da3c22bc43e7a8de07253eb371470ee1e4e42a5d1fa2c4db5565ad
+79d6271ae28e8fde5d4cb24064c145de44ed486a1e7df2df921f2b1be5fdb120
+d8b781c3655ea72dc22a2a2d37579f0af60b42320ab25c8d769124352448a154
+7a381b388a4d9a54e82f199ba35f1a3981823ab698e3f87d38d32addd4f13832
+77fcc9acee7fbd3285f689a85b76d0feb9e70f09bad0ce144770a6cc203ce40e
+15912de0e3465dbc7918e3ea49ade57ee8c48c75937f5d25498c45170693067e
+6902937c9b43ab6080111663d5dc6d88f72a39c5e7bad677229498323a3e7a22
+2fe2552b00cb91ce2848a1a53538b7af2503a3671903e10df0e9641dbb70577a
+e828dd3cae98fa9e1a74f4377f908d3cd79461408ed29832bc4c9865550ccb00
+45359282255057a4bd4859915cf1e45ecdb7329f90bbf63e0a22a54b05c5acd1
+9c7c4dfc25482a27a20c7ab908546c3577e87ade93ea46436314a0a7c524b892
+4b012239e77cd65ae2949bbf7e46a5a2269b7ffb1cf8a5bc7eea1944d2b0bf37
+bfc36adad9a599fa133f77935f24ef518819d054345df144731dd2332b0f7f5e
+84c46af486941cf1293e86ee719c9bab6263470c7009c3933f1857b0a863e36c
+288d37e6ac85e6a1b4e6e91c0a9fe367bec427ea3713e8d1f0523ecff6067717
+244ca21c177968583815f023420a660f7aa4cdc8bf25ac3b3e429942b9f5123d
+84234c186d9226487c76dfef5d26165771c0e75f0ace7e3882e49de831b46c12
+e30dc37395241d7619c05abc40f5a36f8042b461fb6c3a5181f77b14e9e6d978
+37356b4b31fac3850df1869063724316104c799b6a2f42c361a375e4d29eba7f
+850fe29efbc2cef627a25db549a4d4c48f9fc9a2f32fa50c1ce6b5a545a95f7e
+bf2e9ed710ae91ace1281a44e49aee4133ccc04926a6dba24b721c21188c89a5
+2a49745501cfaa4364cf49e3ec2a59d9ee46f33362634f9758827b199fd07dba
+939bd7387124656831862f70a97c5a05959572c74865f5902e95093fecdbea3b
+bba9b47dace807262de0c7ef04843259f58a323471237cd573298c5d0a0650ad
+2acabd71cb44c63675192845e3d01b3b28af871f347d4a460cc28d9e94409443
+30e893d27b06132063ab727a38f447a2a4633d29adac01bdccc7634e64dfdc55
+9141f69e1202c4a0fd48479b0ed95a7605c94901373e1100a6cbfc113fcce445
+e0317cc94a8507dd637c37676954b9d34c6727aacf17285876db16dd0e11384c
+2b996e85e82fd8fd2b8f9b83bccb398b997364f0ddb71e60ccc50cdd5d122eec
+c36b86a89fbbb5bfb227fba3a7b7de7c907e58780fc276c24ff066982691a97a
+50d14362d27d790375a47162decc53c5c11e8a7499788dfd86aefffe7e674aed
+26706e2d079e9a571c6a32accc8c0dcf23508f58477d05f9a1fc679c0da64254
+27ae33293d02c9eca01daf2d0a1b07e5515d36e18caa3ab1b6c5736dfdefe384
+dbcd244f0c11087a873c4501c6de2a5a57e346fd3f92a0451e63fff6b99c6dfc
+64ed8673dc54ef6509d0d043925bce39072fc64ddf2c49b8602d1a51ee822f19
+d7b2135aa84626bfe3ff321a6bec3a003ad97e7699cfa34bf41f9c2b38df4794
+cb5ae36c95f42b44212de67a96ca9d047587998636673a031c4eb03cf1a55326
+f5d94dde75086b44f095ede0068fb6b9d256759041cda04ecacbd8d7784159af
+ae31a9c637d9a5c0c6840dd9e30eacc66d4d6fd6f12a603aa2db3e9866693070
+0d69cddc416d4b76cf6b835c7bebf914816b87edcd5a24e346eba2dded30f5a0
+dc033e93b040a6ee7f8ab3c44c61017c758c11c2e2fe3c4f18996287a48fa9f8
+fd068c42d0d3384ff27c5a88ef630125562663ee95a66b7b588b417b20d3ae84
+6ecf2693940d4733f9e70b0455b6097e73553eed34df8da712c29d76326670b7
+13f19d4b5ada1833d46fd6cfb92b85eb946cc74252718cc5e605cd6c3c5a46e8
+51536cddcc3cb244c78e629fab784fd76372ca9417fa67f292a7e780b78186d7
+f391cd91b6222e88c0bcff66208814965511967b2ed0d075c77b57701608b647
+b4e462d3e56e06c0403f858582a754dcbf8841fe81d39359d8c5a77c8ae6b795
+c11b84f702de09f22498a189a4c69d726a63260784066562a50544e5d07aebb5
+8265c1c6607bfc6008f2edfc9d0de71646548e59bb374996a4412ac22ab47dc8
+357153c7c9061e95952a729a80fb45f3650fb0c84a07c1956dcc0856d7b0fa71
+3f09c1b995b0c48c57c9367c0601a46cdaefd0460735682d5aafe8545cba587b
+ca6e8144ff14a25b2fce9b23d8ebf715c5a544bd646d5460d2f8cbd44b6d8203
+54e4b7377db351ff26b7b9336a7dca3a610d3a92541054c544064447ac6d1a15
+cf1d1a3797cfe85fb55b56ac01fbb6f47e9c8e5c2929bdc7ee14f6d868464493
+df4759cc80405ef270a816607f248c5c1d5c56035a8ffc1fc1b5f69aabe2f964
+cba4c0ed5416a20f102c82bdfe59ddb4a16140c85d55af2aa52c92ee85c37881
+9c95865704b3cc39da6270dfaca8c3611edbb6da767bb50a03d6a06ed9890104
+da2a575ea45e16da2e1fdcd603c91af6beb934ea33023152c25c27c3c771b553
+1a9aa1ae684e1539e549972c97321fa0710759b6d4b9e55ef1b41bda01d77786
+87c22cb79310a9000bade74a8ac97b3eb2ff024bfd60c0ad7fdedb23c805f64e
+fd139e015e0d1d3591be5930c356e6b8c1a4f0ad9af94eded4ee9aaa436d4cf9
+58c5897d06b7c97cdec22745c46e7b37695a8c66140f7f8421138892f4851c3f
+d355b1de1d32145d39243d0590a90f1c4ec2c246d3f3779b319c38d4221576be
+fd17d8bc8819cf8ec30075305f8637d1ddf0f7255ad456cc290f10ec39ddc2f5
+290092718e7d268531aaeb377701dafa933b94ce763c1954ef0cce19d77c9208
+157c38b279c578c56b7e523afccc91fe6819483de18ceebbe74b81844ddb84c6
+22d4f29661e89e5417ce43c28028e9e1c54063afd716088b6e8fe0cd1702c2c3
+31273573f5c3d760c8a2c7cbb362ed650ea8ff54f19e097f14af9739885af15b
+46ed31cdef73db671b22efd41ff3f6bbd29625fae7571f9542fc06c77e28d2f6
+3ba2c9cf89da564de3a6fb3f0ff981c5c482a1e1de730041b7f1c890c4528bf1
+8e79f2fa4ed8a738f09a68a5b53edf6cbcf8861003917a89989146af7ab2e5a2
+836279643900c27a90463679a22f0ca5077728f6ae8a28324f9adcc19fa493b5
+e2465c6d98cb608f8dc52cdd6c52bad1a1502779b638df9336e12f035b3c310c
+b92b3add047365f2d25b0ec7e05cc46f31c0575eaf4ebea0b660aa20d9e7edf9
+0aa077e3000e25176038ccc92d4f9fdbae6b05aa2e17ad004e13308464a20cdd
+0271ed0f964e73cb11f18c2b795dba31c3ffd5648c63dab395238ba7c0cc7db6
+b206e6179c6ad7c2534c46a2b9c1d7fe6bc693df35118b708933677ab3a76cee
+9ac0303c2c0967d718a1691f6a922abb6b37625fc01908c10242731b79a1a82c
+fce9efbd1c6bd483fd867bc2938609ee52c0271a7ed1fde1b8667b98e22fd450
+86f515fd2ac2c11c50fce95f3e506ac6518dd4e532ddb100d87a9240bdcdafc2
+0c8bec467d76261165e9d8bdac9197ec798c81cfe80e3619f432674cadf44ff4
+3f61089abeb13d665e7901f4a1ba84115333210009d55e051b692aebee9d9bf3
+d0219c290191c17f7317aaf402b88ba353c25f126e2d32bef73d528c65af0840
+3ed4086daff574762531794fdbf637b765273911297b75338691e9ef4d2ad452
+22454c6a9cbbf205039d6d35c09a0ce284e9a776773a98e09e6a816dd71d80c3
+d80abcb006353b4b7c48c76bd9c1ed9db78bf62e9ad2222e5bee9fde0281f0e6
+11fd6f899938cee729a184be7cbdb0b84fc9c380d6c69cdd6e0f3f6780af684b
+cec6361673853b400f47e00177ff1ee7f9eb8c285a49e137e08d5d7663df71ab
+71ca71adc0857055686a04777a2e1408ce629e018c97524af5588991be92e4fa
+4a27745aa950a72d479c48d6f8c30d4258a882f199b4359f92a963fc650230c5
+79edf743f2cfe86a197296dd675bf05f25ed969de77bfdd0b518cbb5c30b4e42
+27c5117f235b34f7fc32413a980a38968ff9b8151280a0259214790e421d0f39
+eeebe98adba820401c2d47d4132cc68cae0f59b049d7489f62259bfc55091c81
+89e2480dcb77f689965151b7f6706af675a871370d2195b07457af8809f7abfe
+7d3672d76a74f55ec749ef40f755a3eed96cce000644ca0c497afaab7294afdc
+13c3239f54f3eeee809bcd936ff447277d2f3613936e7b39e683f25b60505f2b
+f4343ed0902badeb62495cef53789b9e74baf866be33efe66c1c5faa95f60ac9
+156a26bb9f72cb73e891ee4b905f72845b3ae05e025879f07a7b91fd06204148
+60832d64b6bd5abe0472aa7aff07fa05d23a01238b6f624ae8db25bb71ddd893
+1fc6003f23292a428a5a99df5861e0ae858c398d66d027a32a71d6e62d62b6a1
+a1db86b1ea3005a201618f22899cb1e7d70f65fdcfbf7962ee0d0d15412d006c
+cfebd0e0892888f26238bd1f7f090de03c41ee4ba53548f469fda2d94f6b3da8
+a606fcc3554e3f261b8490a3b8cde3ee846542668ce3b371318f9864c45a4223
+fa2a86e12034bba867c4abeb461c609c8d47e184703bd6c891f39076ee06bfd3
+bffa679de07d8c8eed9b4b24ff74c6db2cf84108f28e4f0fdb78e0e726a9bd3f
+2a1b94daee18fd20f2c902cbeba13c1b281d0a11a96b20800e4cf939dd32bda8
+25aa63d9f86f380af4dd379d80441dc4fbc0719a69ebc16e1617940a19eb0b44
+96581982d45b08e512000e3915490a1a79b908e1e63ae129750fa45dd33c0e9e
+2e767a89c6f11e33f193da18dc6c820dbed8d370492c19ad9d6407e50cb62446
+d3ab009d9e8f3c51eac2139ab64ffa19b70405813652fbbe33fbe5bc95d40b5f
+9ef833a4b1b51e56065abfef1036eeab8e04f096aac0d2813c2e721e0db97368
+c17f0cc971c9ca18a2db11745f67d42ce5148e2e8b2c0e13e4bb16a2789f0c4c
+e7b65be454ea623212bb2ce5afc6b5b3ad5bfed65063354becbc1531389977e4
+6599896d9ddbdf3ad6fdd8a44b14ec8cc9f131d73cba91e28cb54b37655e4b44
+db0457ae7bfd3c6b73bacf09861a7fe4b664928230fa03cb99ebb763703ff8d2
+68877c3a3b1cf915891578aec60c1f7d1e447fc777d8eb3573ba2a9ce47c99ca
+a9d52f2f12b101fe48658edc7543ef85dfe01b72dc4dda597951ea4298fd444a
+ee33b14ff2f91b7297922daa7e346493080868f56aaa2176c9f2c1284e4b2672
+a3b75face39df1c8b7a825a3a5c25871d190e48574e1d03a5fb094d418c47ac1
+687e8347036cc44fed3d84fe5d4b84a61fac9968b8d004c28539a3681476ac45
+56538901ff2764c1c46f5ffe048cd3a7eafc6a9fe98ff9b3cfdf3ac035a9d3f6
+8d75440d43a1842cc1e8b6b9b6d49a9bd093620735c9c7c11c21652a5262a86f
+c10413a373a9e02a488bd9a16a51fb51b027b2c5cde35cb1aed91ce58703e1e9
+ebdc1a161d754ee437412182f7d532426841e2455add22c031a2171426881bbe
+4090d1cbfc498ef46749308b73ebf4dc5a06adde6f83bfb368388bf7c2d900cf
+57932ba4c9db0f15faff7cbd701050a1db98bdc9a5f9f428980ecfb1e999f460
+231e59b5c62c7879278f10f6a61f79cc9da24d35a2d26996d8a4a106e081b8c8
+3fcc015b775acb00f78953a834018c146c65cd715bfb5f90c03feac01839c6ba
+156e327c97350d2851dd77e8263b967742472dc1e3b8f0e980de9f1815007cea
+51619d84375b777d5cf32a144affd8ef0f4fee2df1f839b2a5d900ec8e76363d
+c829f1d03d211175ab982226616b19c51800e4b5d4b28aba82980eaac6131940
+026e3c2297e197fb8f130fb15d2c4098b97c84074d4e50b5c6606bb0f3230931
+52b39a58964b4ca44caf45f63af49b330ab3dd863f5ebfa8ab0db6cc37838a64
+72c601c215037e94ac89420fea13d52174ed5c933e8c8525f88e6ce482661861
+58b904ba7fdb864cfe04bd7ce6070fc5ef576b1de985a8c4eeca7fe32b90d320
+9091d8931bc21c6f969288b1cab44bc53755d8d8f257466803dfd5725dbb5830
+4be6c784fb6f8c5e66802028759c0597246fc103eb63b58f361b144668713570
+8c6be071b51fde425a0aa5724986ca67e87eacb8f517fb3103e52595ba002e02
+82e54cb82b04c993d991d70b5eaac7a639213ec0f82a1d7750f3f6e94d8ac7a0
+8a586b816a9fbe78ff96bf1e3cd52798089f279a0a0d93e0314883988bba0f78
+7ce5745f8b07eb3b750c1d0a13fa4b0338346220ff9ff10cfe04f29e2c24aef0
+f77f6748b63b0c6d53461536034450820c73116cc66feb9c7f7d08e0a47d4c92
+ec61c5342099c27d93a79d9c9f278142ba03b51d6e1e03944abe063baac32629
+1b5dc30de8512f0cb3a973cc43afc2be532ed012c3eb58266cbeebf611f91aa1
+489d0174e713b976f3a0b36c575df597a3d8b12d4c5441e3a478f0933eb129ea
+e44484e084bdde7d2d9ba23a6bf1bbdd51d96ba4a5207af1044e917186b7e66d
+accde1295b615f37f1395827e29e3a1711fb2b6c50374df468be421cc531eae4
+b3cd2473c979d11c11beaf14aa9b6cce4acc8208f22f9fbb6713bb8306e5b5a4
+d46d11e604114d9a5a4be0615a843d10de54ad62d582302fffcfab7f785b11c4
+83081286cfa04302f7b92f64dbb42f3f97cde0c047662be6a3e58986c54b7c3e
+2ac1b0d19bc1490311150931aed3497abaa74303d3f0a3f3af8667c4b0b91385
+cdc9bd2ae98ac32a2d943e0583a0f3c74fcb803559fea211098b48385d3d8d32
+9e2cda61d7589e5383fa32abfcac50355549f1e819eb31531dadc47f5e759790
+d355444f1efa6b1dfc7713d446008225808fffbdc81a3b1b374c7f2901e27e2c
+41c477de0e52e9005288b7175117b32c326b3ad2b9f9342865d0bdd0ba6044ac
+395c2c69bf82a7aa9b77842a3bc7b4a675b0c32a4e4504d2a9fe8762170f54c3
+4dc3620cdea9d1877f274559ac6d37aa83f90346130472775858c18746db4558
+4f2fa7698926c4fb2eef0951579dae63c2d3c7b9e1fc811ee5dda4dc5b5e61fd
+c0ed21724902532087dbef11b1fd0d71eca9f271a3d1bf8ded5df19db6761547
+97d0a12f94147d64bade52704f880d0fcb89f4958547c6839c9e111892797f29
+4e65f7a54e14ea3d3f50712979f84852e57b9c1d70474a3593d53f21603e00e0
+e79ff355914f9a3d4ab1e14410eac9926928e714248535b178d6fe9e0e84ce99
+59f66fb52f37a4e3dfa5488b76d9ae2f62d4495bca11cc148dc20e29a694fabd
+e65c7629ebc40ff0c0fa109631655d3ef9848e16aa7c73cfd4aed02f8f125ab5
+0d628ce52fcae577c7ef0ab688a2f4fa9a0e2a9b10b93130f0b357f4679c1f7c
+9bd270f34f0bfd86459b402c74224a621dfad6ed316d05e15d31707fae7a9b62
+f8f75537326742f1e9d0c7483489f4f4fa38e0f327f24fbfb26307ead2720bd9
+678f45875eb05036341ba38660630b7d005304d4388ff7eb3be9c2635c21af0a
+02d12fd19a4e52181a9c7f2356b2a16eae4e8ed5b1ea0c01565c26856787fdfc
+2aaaf11958ff3414ab62ca19e947db6b78030e2c528f3d1c0215cadbb0c34f72
+6751da03c604bae7b97f379864bb54be9799bd387e88d6c7053f83dbae1cfb04
+f2ac87d12dcbe17a5183780fab4589e8b0d70934e856f11629a91e6d13da7704
+73cc80e0b80bdd42a71eee5f43a4dab994ee7cfeff83d08169aa298c98a85477
+dfc729ed6db098b4ae47a25b8ae7587b8cb2d59cc0989c06129fc201e7c9b763
+f8b3f651a5c735edc975cec4ce461e81ac9d5e3b08a708fc536b46b9566a58c3
+0402aafd2b6018dd063877b880f85e09895dd4c9d89b5f264ad72cbea438c153
+054e1a5ece2091e1d4105f46b047b75ff3be86491e694c1e2e03bff36812d148
+d9923f5d89a28fbc4f45fbc3db74cc37bf3cf41b070d72a4cd571524fa6df788
+3153e77818641287ae22b1c72331fbff019ccecbc1709615ad749dc77cb6b331
+30ca3d0fa05cc47447c17d96cf6ded782ff6b505193915aebe31f1f7b95dc9fd
+91a124f9551224117174ae1e05754dedcec813a8aa4934b73de1b20d7c10a20d
+83a8b085cc2d431b87397e5f8286c0a80704101475ec9845b2bf7ecb9ae457fd
+abad09e4e8ee411d4a20518597b08d5dd66afebba03f632ff2ed520270893f00
+35cf0716f4a092faf8a0c2a3f73ca46afd2a825eee041bbc2b649330fe821807
+707a06ed91847b434d34742844947d54e80422f5b5b56f6dbda934089c32ad12
+375b31af9aa91329c253fafd3cff4858c39ae5efbed4d590819d2f5963b7e08a
+99e157ca1c18b20c62a8f7bd278f560e871b6126d9cdcec52c6839417bc70dd2
+49fa373ca6dd557540906729f2fc5476c38595d958ab2b6c14629f9e16a2a9ce
+9f6e2dd760e55a38a3432e74126135364cec00a7b6dbf0cd48555df9f31e71aa
+9d573bb077085030aa3146d0693fe683884ab380f052c38b31b0e3483d122c4d
+d15a6a93eafec3523f4b2744935de9d1660fb4d8a76d82045862b59ea2183961
+f9868bf03e4a71db61e03fae93bea1092ac5ec83d71dad123d5663149d4bd0be
+e643435aabc919942bbc60d4ab56ecdecad30d270589775a3ff718cef0e2ea46
+b8c75fa911752ef13410185e5cea25aee6fae74489355d3328e0cbe8d4c55d46
+4114b4a4c85309dff4f2a5c2b14fc4f4779f4e3a8bd29076baec35cd59ecadca
+09e93d8dd4786052d970484ea3cb45b37c4a6f74249e9f5eb7583b018dcdabfe
+67259769ae1a904f20b3ef352cd191bbed998f4b2c06465d7355e82ffa718e08
+9dfa5c8fdaac95d8e05cf8b5a899b8484c5ea104eef3e5b21436ed396662222c
+8cfd00b5a854ba9338da205f16e5c0f451bc1c6cf34f0da069af5ccfb460cccb
+b6f393a99f6138e0ece299e0c0f7f1d0c83e0b936cac2dc38f08292245e7afdc
+6538c4fecc7d712ef83997088f73ae6ff0ab83d0ae76a7811cc07b41a57d1d34
+04681526d327b489094dd961f2f60a0c6c275f09f0a171e88056f58735d2f502
+65a167d12ff3395df58c3b901a68f0d96f8ef54ac5548086229adac495fbc256
+afe832991f1839aeddf1a87abc217835e58af4199823165fb9899fc831b47bfe
+4c3c1f5a2696e9a5f310afb8138eea06fda0688e0d0d7cd1ceff93a72c57289d
+332525c3bc60e51ab25526a4876affb2c64657caf14b34fca46a78e41b0c1955
+01fa1a0c0d77d5f7026234af489b316872e64b4d449efc540fb0da553063a71b
+d8ee44b0f9a20adb9f60b99803f1760c0cde357784e87042133aa085e9a37a5b
+b5685e73354ca0e9a48d886fd12841674bc0713d43301883f1c2f6190b47a4b9
+996c0e528b6572c96232ecbc57c57073463ae36b5b2974163cff75828a20c47f
+926e99faab51f19fdbe0f89bb71ffba9eb95a82b3a712b54578f665a89edf193
+d575ed95bb883f9d6797029ff0cc8a75459fac0cca4530e17d93c9834a8d9c9b
+376d3e40f3e44e6e895f25c90a803cf8b0f3056037809e3ed618475c199f43cb
+a7eeff84d38f49aafa4e469aa78cddb87ea76a87da1b888c38e225499d1bb089
+32d599918227c97b1e4de521460f1a175ff2fc500bb95574d9eac64cd00896f6
+27589fe5351f46a46d1fe8ae16fdc945decb08c0b7d841c5516535ab65b84724
+04796bd7b7083a606977316dffaeec0e8681c10df4deef6335403e5b08889558
+48bfb1b8708a5c41c5147fbed3942ac26ce66357c4904b79147dca55f039b648
+ae18d0d6d330a621301e3c1d6e478fc6fcee4c3382d463491a167596ff51f17d
+1afdd4ee7ab8f1b27b4ef2b665cb6818637b5e982447f6d7ab2806f769d254f9
+f5981812a9458a39f51366773a8980c7c6dced448d878af3bc088237815d2727
+40093cb7c3a4e6e86ec6cd61fa8ad13b20e270f97ee5be1799f2966a0ca2a7c9
+32de08bb021adf9466f1b88ffef315b818954057877d3d59f173c1b1874fffdd
+e3749a0dba7d62d70483b1a7c7720c1e95c59faeed0c8be1913177c6dbaa6905
+a6bd1a153906aa1b6919ebd1befb9a54d9b84cd9d548b1abe83933670ea719b8
+6337d01283b95306db92fe059da52d107ec47819bd163b3830c989df4052614a
+9866b057aeaed455fc9864df1960e97806cf95011394e2052861152024969836
+77be8008c246f14aea1c26e620fb331f96cd32a23b1c87d534d678181a198758
+4bffe069fb5a0c6b63ca8a9cfb6c3fd6ecf07c5bc59712ec7d02a5b988c3fbbf
+695fc7068a644d8885ccd88987532539e5cefc64fb97ec1376ef0a97970db510
+4c19b7a64a1b4f7eedfec2515996238dadbbfa8afd8004f12867de20912c2774
+1ceca6f2956b340ccb5e30f2b1f5f6376e6d3a272be05c29125f6d74bbee7879
+8836ee673971ab724dc89867d5a939da0cb41678fbb8d8ed35efa28de86728f7
+953c9c5896b867e4b7df3322563aff8a31cca8901b5542af2c7254547c7c09d0
+15baa7cbdc7352960ac650a543f05e290341d245ddd331a556ac7fc0ee7eb246
+718b71073b9a32776f6215fd8fa2297a2e9be23728cbb24c53ea10a4544ddfb5
+7d6292640840c77bf03728c3e5d2665ed7db7410c9ecb32c249a45664f72f8f4
+2e81a2e086b535f6473b1a3319d134317edbd1864cba7b79f89ef99d16c8871a
+28fbc4cb45f982bac6de81ef637a7e1022a5579f73867e40e31ec8903632e33f
+b24abe53b1f3a3097779b977bbeb41c21857909d3e25f7bc88e6d3fe6f183da0
+0133a99ae39080012df8498b9ce322ea9b76343c2e8be3676f08602470da2761
+ed9de407fba38be82de624e1552be40a0e10b55ad74367b91c80b8bc5cf59f64
+b79072369d9e492ee6b9f9df0b91ae608a44020ed6874038974ccc9afa88d6b7
+8114af4de09e77e4b0a1a1fb27e226a62385b969bbebb657ea927fd86e050ff1
+3ebd001a022333f8caca13c54f9b345cd5b6553c90b4f7fb949d7d65d9bf9fd9
+46a3c7c531f6a6479aab0d5a7015b56959777892feea7990edbd2b423f6e9ce4
+583caac124c268628a9cb703dd96aacd35b1031e08a741d02adfd579267df790
+5ef26af14b2bbdc22a1eb33b58719a1e8463f28784f4c15cb3c25cfb2e20a508
+7854a53f4ab398b02177de500a049d6c9faa13fd40c19178e878f1cc26221c59
+b40545f5f4442abba06656ead5afd938adeb3ea50c699862d48e767c223c1f22
+246e58c5694d1e23511710817a9fd18a1620cc651345e6d3302d85139f7a5734
+7e423be145e165baf46019fe831f97602ec87b3cdfb8fea12869c98f115d1b66
+5aa588fa82484acded7ca2c13a17bda305f63ee226ee1f37cf247f1aea9ff92e
+2fa4c1e0448a5dde45294699a9490a5ea94cf81c53491fc19e2ade5af005c300
+a5fc99b893ed1d469788e94de823006f8848dc9d021f19b934278d44e8c73da9
+3728f389563e10ae6017c5caf3b4b340be1d7d2b7f24a8cfcc1ed1eb920cd366
+6fa12f35e45673fb12b45a6ed7e84937576e5327c82d7f27f6c0255f75ef4b02
+cd492b23ec1f346bdf8e007042a82ab730ab2805569d7b978a4b114577514548
+0d426dc4a8ad86de85b23ab5aa8a50a30bbdd8ef5e9ff8e7954a69987fb5401e
+a9d039d5e05ef245e3c70a85236969f32bd1e5d29d71a2013493945e803838dc
+7241a73c4c1f14548eaadcba64aebc29fd2253fa59b6b039bb2edc9e4a7c8e83
+317ec39a07b8c8297e4b08d4e6f01a53e3d690f1d1db49f19640c16441be6ae8
+d1cbdf853394cf665f741938733fbc700e8d82c4cf1d72456008a0fe55c8b677
+a4f3e197aac9b976343923dd4c5a181454319fc509d499bf14740ef1387f354d
+d71c3bc5b9d4d2d9e0e7a3bc60c79c8e6d344bebeb3b2dc2c3605fdf1002f061
+d52f718b57d1f6c1406b1fdf2ce37ee45693ba72284c5652b2d88b29ad55d9bd
+78032a76ae6427c19749ca1503fdfa6eda4861f0b0c72684589efe6c01d9c964
+1201b79c5ce03520510e13bc5461fa3d2897e2b7c65ebb571e2d0ce319248d4a
+fcde6d70c38d25f6bbf0c09b64553c3fdadc64c293deda6e2ed8c191d7f432ac
+5bcc1ac3183c92d545abbd4da7e768140b9f5a5077b08dc8eae64727eade3e5c
+05e07036b08c31ba5ae366c642f816b5fa60e148795d3d4ce050f09c443d6fe0
+d44f8859d43da39643d4fb8c5e2e34f1b32142ddef07b1c02c09f4cc9509eabe
+99350ccd3a9d2d6fb809016dbe0c1a29fd1d25cc83125ba7d0143e09203f9e34
+99c6d07cc78bfdb82f72c577aff1045cd2ce2e3de0300283ae5ac540d498e467
+0e3718e3dac6dcdf1c7ab2d5f75c5b6e56bc32d8ddace4ce7f9272aae188f3b7
+d6d31b380592cfc0de45eabdd87cfaa15143cce738ede40bd9a06db0b3d5f570
+be5b21b328b3ac4ff46abb190ec17e73d31af389dc8e887280f84caf7b317c27
+38593005aa586b3c4918fa95a9435e45db40bb52d2f6034686463c87280b8085
+877297a871dd11fa1d782568fe813cbdab6daba828c1c264c3db809cb9da6635
+640c3e991dc41cb1841ea1556b7560d47526bdc012a8f1dacb30f38ed0f4721b
+b98b107526258d66804fb0dd4c52d827850d8f0a764a53cd81f66269a8cc114c
+06482a5b2b752416707d28e88291bca02b7746161794437f61e7e3353ecc92c4
+151af9a2f0b0e0e7b8be3106fa8b455e60d1b8e7a30a45922fe00f7ac9031be3
+b9e1dcae83017ffa27f196e1b8da6cff1bc25c0d776dbf675838c24c57a3078c
+d2f6dad8722aa8997078f22bfab7e8f995538174d577c28d1660e5484270e63b
+90ff29111a71bcfdda204034ad6df026ba9fe61c02bc99e0553cae82fc1f84a6
+f8c744cf34a92b3fa239b23fa2aa469c5765c02abeea272fc928d24714c14ea1
+2dc6871a82973f1b57a2063379dc471f0dd0684ab5ce9ab8088512b548c0e96c
+59f314ee81f9ba0a793072325d5b2a478eca04739746
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+cleartomark
+%%EndResource
+/F122_0 /DTUUHP+NimbusSanL-Bold 1 1
+[ /.notdef/dotaccent/fi/fl/fraction/hungarumlaut/Lslash/lslash
+ /ogonek/ring/.notdef/breve/minus/.notdef/Zcaron/zcaron
+ /caron/dotlessi/dotlessj/ff/ffi/ffl/notequal/infinity
+ /lessequal/greaterequal/partialdiff/summation/product/pi/grave/quotesingle
+ /space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright
+ /parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
+ /zero/one/two/three/four/five/six/seven
+ /eight/nine/colon/semicolon/less/equal/greater/question
+ /at/A/B/C/D/E/F/G
+ /H/I/J/K/L/M/N/O
+ /P/Q/R/S/T/U/V/W
+ /X/Y/Z/bracketleft/backslash/bracketright/asciicircum/underscore
+ /quoteleft/a/b/c/d/e/f/g
+ /h/i/j/k/l/m/n/o
+ /p/q/r/s/t/u/v/w
+ /x/y/z/braceleft/bar/braceright/asciitilde/.notdef
+ /Euro/integral/quotesinglbase/florin/quotedblbase/ellipsis/dagger/daggerdbl
+ /circumflex/perthousand/Scaron/guilsinglleft/OE/Omega/radical/approxequal
+ /.notdef/.notdef/.notdef/quotedblleft/quotedblright/bullet/endash/emdash
+ /tilde/trademark/scaron/guilsinglright/oe/Delta/lozenge/Ydieresis
+ /.notdef/exclamdown/cent/sterling/currency/yen/brokenbar/section
+ /dieresis/copyright/ordfeminine/guillemotleft/logicalnot/hyphen/registered/macron
+ /degree/plusminus/twosuperior/threesuperior/acute/mu/paragraph/periodcentered
+ /cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown
+ /Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
+ /Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis
+ /Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply
+ /Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
+ /agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
+ /egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
+ /eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide
+ /oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]
+pdfMakeFont
+%%BeginResource: font VXAMRV+NimbusRomNo9L-Regu
+%!PS-AdobeFont-1.0: NimbusRomNo9L-Regu 1.05
+%%CreationDate: Wed Dec 22 1999
+% Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development
+% (URW)++,Copyright 1999 by (URW)++ Design & Development
+% See the file COPYING (GNU General Public License) for license conditions.
+% As a special exception, permission is granted to include this font
+% program in a Postscript or PDF file that consists of a document that
+% contains text to be displayed or printed using this font, regardless
+% of the conditions or license applying to the document itself.
+12 dict begin
+/FontInfo 10 dict dup begin
+/version (1.05) readonly def
+/Notice ((URW)++,Copyright 1999 by (URW)++ Design & Development. See the file COPYING (GNU General Public License) for license conditions. As a special exception, permission is granted to include this font program in a Postscript or PDF file that consists of a document that contains text to be displayed or printed using this font, regardless of the conditions or license applying to the document itself.) readonly def
+/Copyright (Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development) readonly def
+/FullName (Nimbus Roman No9 L Regular) readonly def
+/FamilyName (Nimbus Roman No9 L) readonly def
+/Weight (Regular) readonly def
+/ItalicAngle 0.0 def
+/isFixedPitch false def
+/UnderlinePosition -100 def
+/UnderlineThickness 50 def
+end readonly def
+/FontName /VXAMRV+NimbusRomNo9L-Regu def
+/PaintType 0 def
+/WMode 0 def
+/FontBBox {-168 -281 1000 924} readonly def
+/FontType 1 def
+/FontMatrix [0.001 0.0 0.0 0.001 0.0 0.0] readonly def
+/Encoding StandardEncoding def
+currentdict end
+currentfile eexec
+d9d66f633b846a989b9974b0179fc6cc445bc2c03103c68570a7b354a4a280ae
+6fbf7f9888e039ab60fcaf852eb4ce3afeb979d5ea70fde44a2ae5c8c0166c27
+bf9665eea11c7d2329c1a211dd26bb372be5822f5ea70d99eb578c7befd44cdf
+045a363056e5e1cc51525ea6fc061dcebb337208eff729802376a2801424f670
+0e7e6397b28f15bc10b40012b0a3eaeb2693e8f7f627c4c9c7c6c5bff105c1e4
+1b2b9e8f09253b76040d268b80719e1b3f5a55ab7b8e152a40e590419249f2e4
+c36159f8e54b532468e36965a38646781ab0b7f6a3e851fd10caa49adfc1e546
+2fd2ec6150dc6e19523050f6148348a561ad8d2e2721eff8a570cb33460a745b
+926c889304c09753c2d78fb0ca95dc6de5b8c524752c83601e7e9f73df660674
+f05ad83a166da9be89f22feabd4b2665960f6fb5bc32928e1230c212e5d69cee
+0b3311a1738a11747ae263106916d8e95f25b25b4bc6afb03b79abb95dda518b
+41a49458111d2a1433c043627ef9460d324ffe22935f4f6da88b8b91ae95b34e
+08408a34ec8eac3f65b6ae3e3e2524867ee9d29068f81e4372f4470beeb4d6be
+ee4df956becc0cb77f8490117b22b2fb75c938ed0a5e208d88bc38b2ab8b9cfb
+f1d53084b6f43df336481eca0aa2d5317bc83fc0e1d4db01d0b7707eef217e94
+a7f985102ded27d8e8b009f7ef6db91b91e78bfae7bd688e10b3dc9ac77cdee8
+47aa4dc8ec78241e593d26ec7a60696151a2ae5325d736e99e01bdcbde69579f
+92eeec224b6757eedc64a75455bb665df42a0e4ce7b99bf3e7d66f8ffc8c13f9
+d7a1ff7a9d5ff7ac43396779f11c9b008c33a2043d48b61b88b03104b1425f09
+675b559ca4302c001ee80d2b739cc0fd1023bf4f1ff9c01e892e59cca7c26011
+b8e0b6d29cc29fc72792fda5e7d5d88ef98f9dba960c96534c399c54865eab86
+0fa2e0d6c7c44b553eac1574d55e7970744d4792fffbdce6fb4365bdbc2965bb
+2e9edad9e0ebf0b620db415ad98297f5ae83d9c710436657e74d26e83957c745
+89834337035a7501803947f6880b70e56a3a404c62d57b849d28804cbe0f5884
+435a0e12dcc9ba414abb732bfbae237001f557dea5e972ba0838a3c7c9eb75aa
+4a050da0a529bdffbf9011c360564fd17a02c18860af6b86efd4e2c125686c9a
+5e114e95c71fc89a5de9c589bfe5ac0480cff716345265d2435edae67cfc4801
+5bc08e7a48d683acdb91e05f469c0c8919d73a5d07a1ccb173e30e76680acb09
+02a40a3e11916198bd69f1a26e88330f50692d0d5917e99e7a01b327413e24aa
+e98ea484e45897e6ae4d6997b6e8bbf61c9406e916d56985cb2bd297e8acfc6e
+cf2d2281ad84696b7c6cb584bd85cc20ba14add3bc3e25db91124c0acf22e902
+3cfbf04cc40de331991e9075d22ab5ee0e849b340050e6c417c664a782d05549
+db2ef572f193b1c12b4635c2b358747046de5858ec32b3b2e79d42750657977f
+acdd2ee5a7c9320d907438dba63aa05ed410fc7000f53549091be71be45da4ab
+a315f95b724a60f17c70833e889cfe7ea206a7abc4393cb6ef47be3700ba5638
+6831391809ef8384aea8c22735e8062a9f9101add125a321fb65399cbcd9c9e6
+0f46fbf271b2b1ec80832cc054bab5ca80d4561da0a380d56d5cb3d90ae89a19
+48cd824eb1e7ac6127a6dba3e8ea40f00add89749d77ec0eebe26fd6ea5d8cce
+f7239681b3d94898236ae92ff3912e0afe84b6c7e08134c158b640b4aecab5f2
+a90028e67d33df31b461a2846f83d90979bb22618e2a17c5d159fb59d5177e12
+edf1320f596e7a4c379329adb367f92bf2869a9a97398e0c20f5f017ca9db7ba
+b3bab72b87a7b6bf4febd03132f9075c271f2054078396df8403dc91461325f6
+12cf1421f3099ccd799c2c099492c4f071336d985c0c360b2f5a5877fd00b6f9
+2e5911dddfb31d17a60124ee8da6cbda94196d7ed42804610e4f730daf2f2d5a
+b767c320c62543e26534314facae006ba2064623902c8ac479eeebb609e8c3e4
+1516ce412cb410bd026231e22a9cd0f664d769e4e45cbb75b7341f06d8e37285
+beaa9ab71aabe3cbfe5a348681aa246047ca29ca6b442feade254c7582d32d3c
+71b5e645c82e92f057eb5f859bee23daa95c575edaaf9896d6c10980a09db34e
+084c8a754e31b618c6991baa856cb86877044e10c2f189b284e3195a2db6b910
+2574e2461d2fae65b7321c0093a2a34996c0b77123503e9edc623dd02c44fb76
+3c550840bdf969582d226510ebf89944e59684eb2e2c463e69702266fbcf8d1d
+4c0be400495e227b9cb21c8086f328782ca7294dcf3ecdc1a62714143a4c1b98
+e5de1dd554fba60571188a58f0354a6b9ef580689b78a0c8515ca05a35832616
+7e0a90f68f3c306ab60aab20872fb167673f41e8e87ff0111f579cbd0da68b56
+3e35d2ebf9f28b104082e36187373efc7a33f62d3fe4a390b63a76e9b2531871
+6bd59861f51b561dcc115192a6fc22d15a5af03ba09cdfa66b660cf4288e9d79
+26e797256659b0ff64bb5d900990c3cb588e1e18810bcb009a91e5f4f8d9db1a
+f2a063bdabd9c3332f4bdb701bb94b4fd24570b440ae74b8d924e48e7c2defb0
+53a19e5b4df39abf4f6fc6160b5fcca00608422a3091cd03e726b1ea1d203b3f
+c44173460b490498eda3121881ebd21cb5b571d21a6228cc0a1b035ebe97f26b
+0b58179bd22ac950ec3a98458051a874297cd6bfe731c5b413819503111f1f6e
+ebfb5628c955f5fcaed76f2402ce351f77e471d1c9821dad627ff25131590577
+5ff9335dd28d85a11bf155765632b34a3aa1df9c01134bd8fe927e0064319951
+e2c1d374c9acfc30932712a5c3e0fe3c7e355e3356e9135a143f1b4e2738e208
+8f44633dd9300bafc770625a64b2bd20d4f672701310e5d1d5b2dd502802539a
+65344601924c473b7618f9b87bf6eb49474fe62891097b9b381dfc9dd22f6ceb
+340efd950b74e614a2908eea7b0d395e15943d0a9072e2c0e6c91d9141c84281
+6a59f02111333723db78c2c287675d73152ee3c63397f5ea6203c707568137e0
+12438b86ead16d71a0a56d00e6ace9d80aff646b05d829dcf08dce2fed1a17d3
+83a7c9e7c2a5caeb38bda802e6696bab17a5d1e5d6c51b6371c642d5588a2945
+1f3c8b0cd56806531579f7c0d10a9fbe254ea910522d955c86ddd693b8660bbd
+17b2b23fea57af15b1720e42c6de537074c071c50c114ac54c45ba2fee00d13a
+2573bb9243648a1be2569cf68ff78e4cacacdb34dad918a30005c31f17781633
+6b74af8b9931bec0c1892780020c1a92470e3ad7f1bb6ef26c835f13a9c56ded
+51df4a7847c993b88b9fda9a8955d8bdbf6ba773d06645e292ce26d9df4bbd4f
+3d20f52161853827837c837f33425990818b958adcc3ae79b5791ff04daa32fe
+54050aa9d34606f16c7763de770cc33c9acb60e5354d5a27a687ca6e0fd74a4b
+5cffeadf6ad0ba87b906c09201ff65ce6c3f620bbfaaccbe54da884b87e906b5
+f5285d3841ecf78f0a1ee4a80724da3a4fd49ffbaa66be3402a2480a6f8fc164
+343a369e2b8947fd5f58a4697234c742685421ce3d57398c5ed6f6b049fdf39f
+6870236751d9ef2210e680b4d8a6daab758bd7fa7da9680604e5bf85d1826611
+2ca08e8922a1d46ac853f4bdca37f7fe80d2d27854012e4a8f70bd854ea4c189
+ea6939096b56168aeb971aaafe1bca667137a76761cba2fbffceafe3e98d5590
+db3dbc44b3f9d4ef0419cae23086898bb25a222eea19c1a760389672933ea7c2
+8b31025619bd108b79d51d54e23f401f42165f0d513bb2409ce66ba3e83fc000
+4372873eb8b4405a8f5bd88cc2f21d2d60fa4024707869c5fd40d94028ed13b2
+5762cc7924d100d3ce0dd32cfca124ec1fce4cce8c137070a18f05cd73809449
+bcdeb0ac24dcf63679d46aa8b3a4a5d0dbfa9342716619cd3683dfa7a9d6683e
+5a7a03ddb47833fdff8935f2f004f58ede6447adce4fda1b734c75c52d16c406
+9428cdf68855946014584f7fe49b03f896e0054cffff5da4728bf4ce1d892052
+701b48b81f58f5ea344e8ebfe13baa70cb43ce4a979d8225ed78417648672e61
+07eb7b31f81cf52b4136288200e640654e83534eadf05301faf2f3a859772c3a
+545fc20429119ff00c259aa582af4e3cde1c99769f4e433d9b178edcecf142ad
+ffaa6da004a90f53e70048aa8d15a26bfcf7b02ed70bc262d165e99f87ca7424
+0eb98f3d7fc0d4926ae43c8d322bb9eca24a4c45f7dbb0feaa9a900e3521d6b3
+87b52a30acb29c914b06793f19a1efbe3be7d0b8e20cad99d292c315b12376d5
+655121189a833132715762ca7118685814f71aaa08b89e466c7468bca01bd98b
+63ec7cc3ac41dd06c5bbda86227afcc1f7796b5f878946c135bfa75a98db1b57
+0f38c49770ae23986ffaedbf6644df58a252c29ac821f4584b96b5ddafa9b3a1
+aa0ef6d17fc1e75916753bc8c799497e1279ec783ea86df307cd54b58c2b3ebb
+fd722006d127834b089670e5f1e7ba8bc4a0f6181bb4efbb8f99e4475181449f
+2fcb255da4233f7ab097ef0108ba3fc12cda0618870eacb9fe4195dfab182242
+bae0956d09e388d10da2f940186e25c9926886e9806c70105dc75259fb1e5da2
+675e4e114f84862e6b822a10a9d364b1cd13dca3d385b83499c715ecd7598766
+b215910f002358d592fc36d0bd482ee9cc338378ea1566839526a5783f250818
+078b97d73b1d62a1aad3d5a9753bfef23f7b3e6d5bd318c463aa04490b9063a0
+e83e3e68109b182720d2b1c13b498f8f495661c0f4e6455b96a6a92ff806f1cb
+3b1c6eac82d9a687b83c572c42df22beae31d1239719186f14ef637fe4e7c7b1
+fe8f4f1bd8367d76d467be95c394a818198d922bcaeeee371fe17e396b27cec5
+f0554778587fc7d78acdf317a8efdfc82c2f57b6411b3ab68f96e3e7cd321a6d
+4783435056ab5a0095726435be6885bf2784fb2cbeffc0f8248dcd594d34b21c
+98e67de50b6876c3d6d4d4ca7ce0b9013ebe754b104dcfc0719a10cdd9985e19
+2cdf4e88876c2dd4e79e23afa70ab5b4758af32ee87b8415b881ac15c5c3e1bc
+d17a5b961efb3a8dc987deded6f28a240d66f004ad05ce1c551e29b45668db2b
+305c9b1af5cd5388a0802d80f18e0f4bc8065baf393ffab9a4d674312c2033d2
+7c78b5e9461fb09b9b2caaab70ceb3afa574c89bc620328211c85656f63a8ddd
+97c827297327b7980c2fe0acb1c34866aa3c5d7408e257eba3c53de8338bdf96
+cb7ba55fe31bddbf7807148c0a132bdbbe8a2c21a23e11889da13e429914f7f5
+7132936359a0cc65e5993caf52902f76f75d6cb46dd20a3c0be80d45f2c746bf
+236733462080fbdc8c5c1dbe9781f45aba74af8033a6ef2bdb16f7b0930d6b6e
+7ca7fac8cfb2dfab8c063d961077585d24e8fbb5e0b0bee9c4509b23361dd06a
+dd25767833b9a770780b311f608cae7adde000297a2672211f0de8cf7f5fbc62
+78faba25d035fe3a7cc3a4743c0efe1c4a5e9cadf1e05bc7982648d5c9fb2992
+4a9ee1570ba2ab068cce168552299361d62a2bc2c0da48ee94d1cedf1e2d29bb
+43864ab5b770a14c98a432ab76c17998904f052a50ef845100533ba5cfb24c84
+da53581ec4f2201ca9fdae76ef365515188ace4cfc939ad6d193413ca7ee225b
+0137f4637f09952213be725cc7aec579b2fe85f7c6af18d70c4fda0557567e64
+d430f09aca7bf28984977ba0f5849a5a86729d5640bbe4c30b17ab03262a02bd
+8ee077ead7fdaefd37af16007d83714aca07fcf882adc4792583aabb279579df
+6741f637cdf8598fb5827528771444b0aa82dd5e00e70edefa7405a1d8a7797b
+ef021a53ba68c7ff6780c94f1393d1745ab1fd7c728c6112766a3c2e21dff002
+9e45a5c5668f8b084f22cd6a6cfb056cf0f402a73b2c02118259352eff6d680b
+877ce3024c37d532c186f3d4a97603704cc0ddb25cac00aeb4cf601f6fb45655
+8939ab962cb9e16a2400938d226056535ebe5707cf0a8678b54e6e3a103b2eff
+0bb7306d7c7c3f523b2aec267a5f1e3f99208d8ec9ab27d658c26f635c2984ab
+5a4d214768c6dc775bcc616838159aa10d5bd93cfc8b2d836eae5ed480fb6ddb
+24253a62a1b798bfa51b068b6888b76d2233b6fb11794f166254cb3ac8cfb650
+429866dbeb8d09e6d03889899a4e8bfc9a855ea4660f928d0aae8247eec1668c
+8e798398d53e52a5684caa59c47cb38c8f1009a8aa12a269a587593874c2dc78
+0ba989078910f3d70211147751e9f7264d6e64f1b05410ed3427bb7d0704443e
+f2baeb0fb9e3f1c1c14b178e716feb4644240447a3f02211350e36e1a586a042
+9ab336c6b44c0d2977294e704e8695b6daf079bca033b6bd3485eb7a78582fb9
+373716136c63eadbab3a2577738f553f81135829f9118f4bfe20cd51190bd7c5
+17035ebe97f26b0b58973ea9b5e0d111d9eacf2fa54b223c4f40c139ab891a41
+c7d5ba5338bfd58090ea727c3fd9d0c0217c05798787881d07cefe019518ccdd
+a7ad72305f06a98717cda80c5daaafc50e3c6d78d2b5d851beec46731a6c29ed
+ddcb9089de5cc2ddb696d3b7de3b67f066527ae22cc1ae6285dd1ad42e0809ee
+65812268d28e7105859262e9368a3aa7fd0207d47de5ea5591927f5e568386d3
+a61fcbe872945a272c75384be1e85b26aa094704715f1957de37a2fde2577ba3
+85000d0708fc918d52360cda828cedd17cb7d625155ceb6931a29025b44ec8fc
+3678fa08027b20fb9649d07f01484f2fd2e1746f290e32434fcd4d15acf0708b
+ee3fe9948d3ae141749b47810558d71d592735c1c86ee375be7413b2cf462660
+0b115cd043ede5612ab895cee0909da8d165408cd5c4c34114ee4d7fab4c37b6
+a31cb829c4bab2dd04b1a7097dec24c6429c13482667116522f94edc99de551c
+a693362be4d277e12829bc466e13d09841b5d9af504be4ea59e9c2459eea5ac2
+c678e3fa30cdfc5ab855d56c1ad8374f9769a6b575a1dee5aaaab4f716dcebe0
+0fab8b0b5522294ce3164f8446679fcc7aff5bf49062cea58f5c661a895ae753
+8891536066f8416ff5e357fc34cc34d6b68abe2fb2c540a7123bbf90d2671f65
+90515b96cdd1bd2c1396bc15503caa4ccd3ce28e0361801bdc5da98887b2c39d
+b84a0a4de7859c7da394acc497641ece12ad8a7d62ac5f8e6bda0577fe64d581
+35390a37a1570cb25b23b747b236f3f2606a3ff6e487a78069a068e7af13a8e9
+315016ebb2552f644065408a69f1bb6fed50486b2a05d403cd56ec5d3671c9ce
+091995d384491b65eeaf33078529238342c32a4b81788c31e62ba0614bafcf9c
+3c1cd422c605740a8939487e26bb9233d4cde68afe7a0cadc3aecd739c9c425d
+09cb50b4b4be28115ba7fc59b541513cd6fd08039cf40a1f5b90a8bd1263806f
+ec35aaa4100ecc05416ece2f061cfdbc321cf3324f1eda91976cabb8d2d9acc9
+b93c575c363fa691e18215311431841de8187a20d6664348c7a8adb06e867d02
+07bd48fe8067168c4412fc80cdba62f8b9209f5407670a26db1f7f5d67c4d227
+90bcd0f1e8640e5f9288c410487290808b88f9421d506386ac95cd959fd1ed07
+778de2f62958ff409d37332aa4ba88c735f2a56e4e746ee98b9667072874b21a
+5f98225aeecabf5cc818f3fa54edde178b40a1b1d6e2f900365e2b503346b213
+ddb43a269c5a973d303dbf615ac3caabfc39fe2144681e7cd633056bc77d95a9
+16f54291575aff7a3a4c13eca61a8d261b3a74307aac38b50c0e55222626e717
+db6e122547b3b8a766fb877deeea52ece2e74ba02ca7676f0e037cffaf287340
+c19bbfd9378d8e898225eda3fbf814ad51f976241a7285dbcc62610fe998ebc9
+7dc5961af9d70a6786e8922e7932a539f1606101440c6855f2284eb34a895cae
+44637b6a0b1c6386c21f11f2e7ee2adf012ea6ff35314981226505bd4b0ea25d
+371be9fb6fc0425d8f374cc51fcb15600ff7a49a4104bc29a369c8336438bd4a
+45b7c8fd52577a49acdb394cbbc16c844ad99f85b5af1e8018900d50862d7c7b
+045ee4bf7972eb05aa5696a004f3ec9be95c4c14180c7c8098a3a0443c0dfaad
+91e9c3a37509b29066af112db77107b9daf2e45e72dcd78660d5d56018cdf1e4
+ca787593c31a2d6ef925e37e4ee77e687e149bf506664975ccbf5fdc20b5c306
+984208ffb9ec2f79e76a7a029cf5981fd2d07176083d7fa0d9fa7b1e6c6da9fe
+423bf29011478ba39fbdc7e77ba230ee7b89728c9312602dda359f1ee65ba362
+d1f36657943255d62f0c84fe8a630204a8e64d8f940e9ddaf3c2ddc16fd131c7
+f302a2f9fb65ecccad4616977b2ec724fc6a4c39417962e0de1dcfa69aec8a02
+07179266935b655d20af3d45228ac3796fd2b7b6e0580904a27fe0c8023f4fa0
+fd70e469e5f309690c6ab737e9e0dd1db57fb312362b64ff1955401395b42086
+07e7f9449a8953149f324b4d5785c2a0a4c28eb487fd0bfd65462a1a4a741be1
+b1876330912edefcace1dfacea7628d16a4716d3989e1b31830cbc2bf9fce144
+9f0e80bdcbcfcf477a2c30a72ec227b20a0af16fcb8356bc205f18c6088c1d6d
+c579f1dcd23ffa147d72821b7a63fc011d5718fed41b16ea1d83ecd8d2ade289
+54eaa105f82f777b6635c160d0e3d67fbff2080db2a99d489a070d865c39ac9d
+2a88ab5fbce010919edc0ab213a09038fac6d3c81a4972e3c5683f49480fa5fe
+b8cd3279398028dab63ef7e8e1df85a63f93273f187f8f8619c14ab824c97c3c
+70d06fbc0a1b4be1b2b7f11ef469adef71617b304b51c462ab3c6c0e831c9ad3
+cb80c5e0d0fafd079d7f4f245d542ea892c6fe3c3d6d1ac2c92371b7a33aab5a
+ab8375b4cae9661c9d314999093b2a04ea1cb671c9f07ecefba615e023cb0f72
+b6eed231ad31b1f4d03e807e56c1e1663986eed65e3ee47a2dd11c1211236973
+4b4607a6570f534debc72ac06dbb2149f9efb793a917b3b604271fb764fab871
+f7aa5a5fcc54533951454fe7afa29cddef96e951aaa9b8eeb3f9b418bd132974
+c601b6fa29471dc34814fc81a1e1a5155951c12022aadce5826302220b18dfc3
+d30b2277d08e7cc7a87bf1b8ec4507b43cefb117119d86de3be51bf870390ea3
+d8daa3f74ccd3712d1c00261e853dc3078dd411189872a50d85d58cee8fffb1f
+0288029490412f3e58f83dada08fa695b18efd0a4f289705385a411fcb2d7a47
+ffe38977fce18188c0043c448d27e160ee752be0d44d0f83b6bf642c694aa530
+e223aefa3fdb17ee7aeaba75b9a86d7cb0f50ad4d5ce68d4ed48cb0c188f9dc4
+34548b48403078f63079bce8529f910ab280ebcae7df9f824dca756f9d647dc4
+d42da412230a6231307e7495424f98c9f129cc4a326a3dd8e476e18d666f94fe
+53edc87e47f6d84abb643ff3b4084437da26b4a298f819f4b6823eddac11bc85
+b9f5c5d0aa1e7b0ddca82c8e01944b3ea48978c1b8f4ff47779a5523f600d33b
+896b659c31f4f6f7decbae0fe1f83dde18f77f53db140a36b0f6f4b883ebcbb2
+b6d353bf2ca6102173b6dfba0f452d011f6cf7d661a470c3c5dd189c1e83fc4b
+9372ed67ef4ed9a5b98f85c8d73d490133b7362ab976a385cec705a2eb89d7f3
+2fbd60c08b86a30219aa2988f79e6386062be839c1f9d30affde82cade3494ee
+13041755e76cc07ccb3a4a701461290b5b79728eddfc63b2ed5cd4bbe0c4c365
+75488d590258ce2084f898d7c58b3f65b09dea2f8d4f71e80b2a2f8f31d5fcef
+7a7744b64d7baa701e473b85c65814b0a93e3ffbd7b2af85e00ffbfab9bb7766
+f444709a47902c919bd2a4becdce07b64053aea1058e26024b46153d6bb92c0b
+59861b2ddaf3d38dbea5bfedcc49938eb98188a3c4dceefa1f308559f7712ccf
+288219c6a3d4eefb81a2c5f154990fd8f09713a0531017d74b47e1f97aa6f0f3
+92ce5bb7475c676247d57bb14ff676f11a4b5b564ac26bfa9d85c9cb0414fafb
+c35b46eacf74dd964fbddab28fd7bb304b9bf4e12cd15b3bbb163dd66e89f24e
+6485c6ea63365d29907f6ba96d313f9b2ab7d175d549f4235653ef979a5c63cb
+6ee50cc333387a0ed88d30d9fd2197d31a0894ed0a47b15d92dca463a8c84b3a
+986d396e6530b2e9ba127bb5662ca948a8f0c563b9c868644b8d01064db6aa72
+090dda0521e6d778192a8c6d4d4639e80e309194cb76fc5d4615f396dd85b06f
+71dfc7f39a259e322c5e7d28646310eac92e5f6afdd6071b21e6664e1cdd3848
+c864ce0e380fdc48b251d52b5094ead64d380b6818e2c8b1a4eb8f9c18adde6d
+6e4ce1def2ae8f2649f1e5aaa05720a358a74e181568a10b536f68b7a0292787
+12c34acfa5bbafc4aa3eaa4d8ebb26e20bb00d228b4eac4a163e0b72899874a3
+f85e82c396d9e2891d8e0d6e5571d4ef116879cd2f5485dde4b9d40f638a3a95
+de5ddd14adbe72f5bbadf0d9950a195f64fd3209c6d47b46b7708f855da96cb5
+e9e1260f6699d945a611a7ea348db3c86be4b32fc2687f15c4c86957018d428d
+f6244a1fb6a99122bf89d7add01c80f2b2bb2c7168b02c400bfc98d65394948d
+c736741f9e0244fe096571f087c5d6d7d022c726a4cecf37cf2ddeb1e9d77098
+60c5d43121bc2e4b72a2d895a5ad2f449196aefe8c01784323de3804363b88c9
+1c86124f431e6dd0744c3d073fff4bbc2b98bdef713bdefc2da4e0e22eda76d0
+34424ce13529bc04c078dfbf8b3efd96cf662c4e151f15d4f8ea52641689d4a0
+5f7c9ec4efa5119db9e3a61e4a669c29348a1e71382c093499cd35d7d1227a5f
+5bc3db96823c167100074c70040a55142148196567c20c7eecbb25ed6e31f563
+9add24d52aceea4b88114eb6dba9461c2e5262fb9529e9f6f0bde20d3e209a8f
+0c9fd81b99b00d268f764593baa894f7ae50634766c922f751ed183aacaec03d
+b7d96d012cd0d111904245be9537edb0f8769ad1a8abbd8d1cbbe5e79c53c00d
+983c69d8865e93b6495a2f15ad9ab1da7503bd5b85ebe27aba01f71e56482be9
+d4342ac2562d8e6d1e4146447561ef5068d17306d66a52fa41644897a9b161c8
+5dd4161aa3d956e7961aa8020467e76a833e01c974e32aa2b8cf27d62fc81ee4
+d74649bf9530306481f430a539a95dcc2502f712947f6a68dda00589ef404132
+1dbc8b94afd827bbd5f77820353fddec5d98fdd256e858581054789781ab090a
+816e65ad3dc4a68b4ef2356e7cd2f906a859dad680d649457bae159f91805d52
+fb6dcfa5d0ac6373fa8325a817563bc9ed89a17d8cdee9b7516f38908e426f05
+1517eec7941cbadb22390e3e2e17d62ca67f37d01377c5a1e09bef5b795b4446
+54b383193351e05ed8bbd8b0b138cf62a428c78744582eec90a41c3bd44a4e73
+c9b32ea4936c211269ba5f883d45b16681f8afa0646a4031ef69cf4936305336
+5758f50534e6974342f4d232b5024dba0eb297e3aa3e9ef0935bd47998370420
+ead844c7e336288356715ceb8cb8492ecdc8fd8f1183360fa32850051442f4d7
+c0250d658c633de21048f4676a1875df6a8a61f0fc7c25dd5acd0220798ca70e
+f09a72b19595172afb9085b9a5971ad1b9a3a2508884a3bce88c984f58389620
+95584866c59f89120c7f491cde35b9d179f11db0d3c30370138852050cf14b18
+c06dadc218335bb465dd88304f1c1cd11062ca72649491fdc62d571c082cc816
+261444906d399760159f6b1e6df4b42a7a84750aa61c034b11a6e7eddcdeb54d
+e1f5151042a8e9f6a23a81a235fbc3908a85a6b05d8162bbdf3a672715b6fcce
+554e98df1f4583e03e456469890f07f83bc0a8954fc5edc7898f21f6917d30fa
+36faee98f622ef313cc8431931d83d271cef880dba07b832a01384994e964233
+f2e29de305c3863191f877dfba44214da68bdbfbde1e3b8b9659d7800df5bd19
+28bb1425a51abc317efdda09d29e04ec8b17bd3b78085595120b58fb421916c6
+af4b92776ef8a8211cc376a37566422bf2e2a840be57a357ab9b9adaa20600d5
+c49f228d2f7bb606fcfa867342884fcd426a72ca4c5d09612bbe26a2d9d3c8fe
+15a55e095b6705f2a2f2a00c9f1cbae16b91e13798b96d5ae66b5a8d1cd751cc
+9747bd951a55ec3fcc11f58f8afb40913166ab60a01b697507fe0753d085e5a8
+8153cfcbb70e29b7073ab33f7be2b6bd070ed974d0cfe4d41f7f57f05cef38c4
+251aa826e4a1d37459212c1b411b6b51faa564da0ff48ee6402b3c9fb77d502f
+61feeb32602da2b5fa880c537f60e1394571392c3fba4d110ff47a42d923c153
+f7a83bc1ffe67cd11ff1a763950f2d7b6d9575f45562c3a9de6d4ebf59482d7a
+716f39eca97fd68be71aa73987d570ce2ddf953c6ec97cbb76b147ceb8973564
+7ee159434e3af6588f47ff9722b7e90f4d9fd0c5b9e9f3a14f9bfba60ca6556b
+0473dc073a961731d322161500e15ada373d503552c0b76fc6576088e630cf29
+b9b0c82cb348259edd482520a84965a53cd673138aa57c32e41fcf50fe24a447
+4ed23401f43f5206de7fb3b6d1750223115919d85b54eae8298a19212e5c66e0
+c05c6dd7d7f8dd877123205b7e391a189e11fc30fdc6532fca87770985b357a4
+fbf9c5d261a4c998e2fe8eb96e27dac9daf1d3f0ec7422a85d9c7b241857209c
+f372c03c1100d8ebf3ce4ab3c0efc1f979c5999bac6d4abb6abab1d059c53f7e
+34f972f56df329bdb8485e39cc98cbf20ccb70a2a3cfdad4deb3267578b02f0b
+0340f42bac749465951198d2ea2bf7995852a50b5876597e55e1a1977b9e2f0b
+8a8fb0f03839dcf6bd5542827208d443ed4b9c0145e4522274a02e4420f738e7
+962c6d9fee17520ecf6d6772e5e77d6ed395304699dd65d7a610d793e38ce3dc
+e461843d5af1e27bed5652bb84d5e85622b48bec72e1622ab11506ade702cb2e
+8ca3ffb8add5c2470207bed74f2b34faf8cb61dd5e0bf54f2b8e1c7ea1fee81e
+0e0a16747443630b04990ee1be9db5764a580222b27332072e74a60ab7b789da
+aee741eb538e3ac7e38b333c7f6dadcad5b9383ab433359862dcb30ba53a413b
+5e9947eb637e78eedc4b8b17cec6b82f4cb8d2d71a37921e69d428723823ec95
+0f683a6bfb55d22dfb161e1d6b6db49dacece6e43ad2c51a70e6342a85169fde
+f8060d7da7e20b4db176bb862c29749077d7104bcb313e5c886a01cb16f11f62
+984c5f853516c1419df929d29eaf4490a3aebd24358eac006a594afcb839778f
+d0925e2daabe74c7ddcce9a4f454633b52b445fea99105fb0699485956fc737f
+25625d53dcf0b9e2386bbf0900e0e011e8adfe162d5876a850a6507512690d2d
+d1f00992f4dbbca2c63cd70b16dce15d1c128b9d6881f3f7ffeb68d7174ae769
+3b6f5e02523c7f046de294e18255b689d2ef529e6dfe489956afc909284a4d43
+b0ca1d9f8b9be4e4da535522cd9b6e64841c81138ee358ef6768e7f78af8033a
+6885457da6ba42cb4bdd4f35233b8e5ac02b7d8fbf2092bb8ce890decb6e99ca
+152d2aa56c5ab4179ba7936c74dd6c342a392131fb96c14c3b24d9f0e4d8b1cb
+862ea5e7b13e204c914bf95f55ff32e4308fe5b2949fa454560e8dec474ef52b
+65bbbed017d5eaed0d89a3c86fc63bf01d3a6a10a5fe389b1af013ebcbff2a17
+7f6e854dfec5dbf19d4e977a07a42287a2dbd42a78e589a002cca47eb865bd5e
+601a98bb3a8572f20ef1c0a2b3500f615b1b8f9b04215f91acec454312ec1dce
+08f413b9e2ddddcfd2bd85125dc5a043a45c0b9d3c86ac30b21f34cae2d347a1
+e93586eb95fdd3d1db7157b21b7ed1702d31876a1cfce58d619a66df8ccc3116
+319854a57965fe23d2d2d7e02f4d95d810e8a13d29872274fa6f48b7333b743c
+7af418c1fdaf467acd5483a47c5e99a7bd81e18ef98763ecc08820176a109145
+af183870faf171a3c24f603654896e2d1b0ac6224cfc765bf747e194cd18c740
+6c61fd10b6b7dce9c0a6577a87ae840e88f99cbf1c1d6cc83623d2fe80bd710c
+ec79256f89f26b45f75281d3de9636a134f63e244df4a623c63a895fe66e1464
+1959655f235bd056d65e3a50f55a041447594422eeffacce6af7cc9768f72158
+18ed408e47358ad45fce20e4848cc38f70943755e9233ac711e663f2c7d77b46
+c878e70669ad30ed18b6f832e4d7f54a23c837ed440ae97883348a0b5fe95232
+779187e429b6f855ed7cffccc8d6784d8bcd92548e3257ac87231c36f119ddfb
+f28ab8dc8b253a1fa09f016887fc29b6659b40bf3dd9db6ead8c8c3e504b10f8
+37dac82a816e06722397867df32fa25da0713e92ede9e4d41577ef58ac70b402
+a4427a7c86f7c1d7f378b62db43ca4bc3a8669f6e924d719f18799d1a9e5969d
+76bde4fc976074f2d623721d38e3f5c73428d6824049dea9416a450be02dcb55
+908e37faf4a56a36519311ddb3d1cb66837c2964a2dd0d34a23dde43eb30c88d
+b6ea541956b904db911d009f0b209bfdc139f48878c811ec38a21692f9b866c0
+a59d9d736d429de0db4b0526463d0348157019a262b2c3e0bf54095d06110593
+3646fcd24134d6b3a2a906a891187692967e93f69a54ff3ab8050418585ed1f5
+9822b134f8841589fe146d05ab00c8e22651c43723216c053851a5d1f9bdfaf8
+59c55523acf1e394d27500a1cdd551c773c9a6d7b3882f31f29c281fb6c6250d
+8a1c3c8dd110c1910014da6fd1d57b8ae102b261fb65a3019bd75e81ccebde3f
+3e23764e9a5dbe640ca98585da2a4af9de5a5045598a905ee7b82bbaabdd0d92
+bb5351d3a0b3071e8666fce45202af6000790c1c1d0a5bf0c4623b9815b8d3b7
+7c39970a509db6a4a0fface38a60e2dccab7f5b7ad1c0f42a74da16147589a2d
+3dadde9bb1a63a4047ea20dde1109f8856bb81184f4256994b5005d654e49086
+7bb8396fc8d807ebdefbb74e9894bf0ec793699f0e68263885581a17c87d7082
+371d3d4884b50e1295c517fc56b91ebb6b4c23b150d542cd0768924232a5ac00
+8a98f5ce9adc8dd3e65f085b35640919767237d0f9703cbd691a987a0aa0444a
+5ea0d887837482a7248865cd78b6f665301cb67cceb1f689198821227c1acd81
+3d0a50674832bd33b2672756d5186c89528180e190d1525c3e806caddc1e4157
+46055910cee4f60f40b1065f435be8a39eb454d88f5bc45ba818e5b006e5a38d
+29974f68ee1962448f7a9fd83c7f107c7788eb8975dedee759a2bbca40c811b9
+d857cf8e510376d48abd60567f307d6ec471f99b03cc7b5e8140dc0450af3832
+242a353515b5b347774f32b8b6c033adc43b2bf7185480e47c868308f3906bee
+e44131b11b2b14e77f33686307842337cd1f9695491bbbdf271b5345c44d6a75
+58c59d6d5bf8b24af38248368644e331a88cf73d0eba9dfa6f80f11af0293bb8
+40d9755540afd18fb03e0b26b6432277434166123d80044808f6f1115ca55b87
+60f82520eb81166f8363b150bac7f45983d1f4ea0b503fa8d041261e2fd14caa
+c7db8e5b1bdb04a65cbb660526d8b21eeff68105486474803acc96e7b882bc9f
+5a1d5f1e333b2b2aacf4272a05a41aea04b2c18a82b1c66a40753a3690aef089
+b9fe83dd0d86fb7b7045f041b690928b7b2b67162a1f5564117652fa7899a444
+bccc231189c60ceb72abb4038d7d0ab5a027bea7ee75542416b12a16ee00900c
+db94b2c89b2345d209cd68307e101cd06dbb79e76c725dc7180becca0eab9f8c
+ae1714c57bee7e7f54c84e7a2ab9a2b1ddd4d160cb4825b69c1bf5ee26b18391
+acd6fab3f890d8cbff5ba3666b8d7853652da2bd5db79ad8de358e55a5e02270
+e1a2d09adfed75088a71593ff0f54d5c527518cc767584e4380b8fce58b04ca2
+05a69ee280da655169029a16a3df3b86fc4ab635300397767c7d9ec3b3fbd60a
+bbf51ad4a3cb348539fb9b7eb072ece9afb2b3c00e2b91bb40a82d2ddfa58e9d
+f40699038c9a7bf930a83996afe9580c5338405108ac04fd713bb22ca2024475
+f540fe14290ab1818d9bb19483aba2f39a958ea417ec73792233ab538cb70e0a
+455c6b7e0bc86eab1df73eec1e16a6f95cd23b8f695fd2b919dd282bd1129baa
+93fb68080d90c29776bf27fa42dc0721e380ecf88286484417664e41c5b257ca
+bd4835c1d64318507de5dc2f1060644b2b125f17aff1b95a37b9b667906d48c0
+9fa7d875d59cb6f7fef2e37ec418540f8f13c2d70cbe9566299dfb80c06df99e
+b045dd3baefd87b24316700fa1c9f72157b927052cda3fd2b480df750298d645
+7c412ca39f6325d66c77be38bd8e491d8f710c5f91f432e13f89056940029532
+db065329782579b79d9f6ba60552dbd6a302e628f75e0d3582d25eb03e7deb33
+54790b02521553eb0c286cb415cde225b5d65cb79db060d13afe862d5885b567
+2430481620475f50546ac782370e3ea1c95600a524d288b5d4028be7cfbea855
+528953e607721b7488f7d7f9dd5ad14332b32bbef72240036a3e1646fe5418a7
+1fd206ad3fc75b7dcd9813caf5d29ddbb12d7ff94e37bccd72ba1086dc431b5b
+713ed14ab7e9f1bff7dddfa9bf22624e4caf3cc0d4194f0b6a36b1c67e43f117
+4bb23054ed01209d28bc55224028648a4a3073d56835afa9e004fb999372f29a
+d76db663c2a29b5638567058904a4933be88e75ca1f365739a65c27bdc195e7e
+09cfb2426fa829ca3859306b556d1bfadb5d9493c66e34dd7f63583e4532a075
+532cee2d8976f785d7909093787e8aa5fc7912ca8fa89d346634ef71f98c9fa3
+cdfd931ccc699caa314c402ebcd6bbcfcd3ef7ede19e6c8b5ea9bbe73ae35b72
+e214974b2bbb26a115750327d20732b6f6795c25e4c0b1a63b5054383d428d2b
+85ac1f719ce35a18de6f4753cb615aec6212a272d89b3750863536fcf5f791db
+3b7b39a66ebbe9fb1876bb089ec2cba092d291aac88f09c720aac4dd8fdc22d6
+4367c4c5330d4e0ed7d454728af2b4801618edada4fa3e5357fb91458dc13288
+7650401bbca16d73bea8cd5127797f92c8b5314663e02cefabd1edd89e4486ba
+4d371138ea6a07ce358d31bc9ecae64f409546e9101fff7ec710b45f910510aa
+b51eb2374992009a28262a370d42109a0aa5ebbc16d2ec5d58e0a5e7e6f80a02
+5cf8a581f3bbf98752edf64feba585fbeb56b27a79384a22c868693c05084423
+f7cd396cb48e68f76bab6512f76da2772f3d137881ebaf1d3ca6e1c98d54732a
+fc24bfe29efcd703c489dd8dcc69da4b86b5650788bfeab8bf66c5c1df7697af
+ab33d0c14caf16b9810ea74c32ccb5bbac2613c6a3d946436ccf934a20b81cfe
+5e712765d1983bd77cc45612a31c893a5583238c944f91f2d6d1069386621108
+108b0e65b4f6d76bfd0e1158005e8ba53ab48e865e9f6d07835d4e9e124b01b6
+41baaa6cff413e7ef8eed73f1cccaef55a87d71afb309ba162d3e15dda6f04da
+2de8db583beabac1e5680df43bc063095de043b2ad4c8600ef63a8090b64785e
+5288892b63a87d8c805d1000b6524109a41e05e517e07f0a76466125650b3d97
+008057de3d3380b0c352e70ac04fcc21108e619a707fbf7f59869cc9a2d571c9
+f77114250c1c41dcd527323edb2fb883dabf371dccf42389a260fbf53464bd24
+d5ae5be48163f142733b205e110d77de5cc07117d7d6d347cc8b035fa387b249
+fde3beeeac843c89bbb871114f5313437a784c051e021da4f80adb2d5e392f0e
+46068df67f46afeca052378d97597f21c39db6a2ca7c10c57421499da8d5bdec
+128109432f86a0ce63ca2be7fd64e29e8392bdd0013d4990884f7cf49e7b88ad
+846af39a3aa1ec3c85f21db07952d1b45cfc20d6848536b63d2572f44ff718ad
+c2cfacaf395cc64b34290bf19a19d756b38142c6a7471ab436c6b81abed86fbf
+8553dd8d5a052f4d53d6124ea4ddf235f4a792f8aa485fb068d39c682eda37c3
+2fcc58da51f74c24bac8db5cf825407f88daba78f41d8ba078fceb0236c2deff
+e61cc0abbdbec3bfa099b49cd1218dbff85cc705730ea545cdff4421ee5a5355
+9ccea2cf6257b757e4c6b853a476f0c97ece80a41fee4994b05eec575f87bba6
+9066eceb28ac92e1f4483f8744ede06a05ea038565096458785453b2462d103f
+300aff3783f7a2ee1a27cb223e7145b6b74fb5a95a5445b5800d0b7e4451be83
+8a7679e3a29c9bd79be0ce900f8cede4f5fbfcf46b6354268087bb020914f246
+fe06d18cc7e9cb1003bc96fb5961043d919c9298e61dc5c7cb39886e65939fc9
+037e0484b62d1ee35842b3ddb879a7fe175f07451c4456361bb646e5dd87ad6d
+ded8388fa78806f8c993bf16f539a4526503d8baf83d1f0a594db7fb1a11e7da
+d2f9db98c5d8206ea4a44ed134d784b05ac0ca245b2a5adbd93efa4a566e93c4
+84fac7ef0ad46254101b308dc4e39c549942af85c96a5dd31e5d9a99149f49ff
+99cfc5783d2cf9c320640a5029bbd61c86d4a6ae9fee690c5ac5e92d6b07aea0
+31c6110df41e63bd7039d6ba8ea9ef33beb3cdb415f4497245606963da60194a
+8383663ba3f3be2d6e0b4865ddddb484f625beb57eadfc694125ee35480efadd
+70248037bf40187f54cb53a51fd0a916d0b1a54311f43cb39856b5e4e17ddf0e
+54466ad34cdbed8fee17c87f00bfe4832eea2acaf9e93aa5091b62febfba9b01
+5960618d7135ad546cf4d00c8c725c6da697406891b75361c81cfc2d13a03836
+8f2bc045495a1d24628606990f351b6f6f197ec7b52169495bc0047335c4a3d6
+1a7aaa63fba1aca730ba1fa90ca04a0fab27b145b2dd0b4c03f01c79bb77758b
+fa630d02a5200c48499964fdac705d1f6b0aaddc58b47a35077f5ee2fbcab957
+919e5bf614a1468207592bfc36bdd62ea9389142350d0835243f485c99a49ee0
+b6fce33e9f1ca586f704d27c59621206abe70ac31608ca67a512dd60f07510cc
+e0ab7715f3a662f824a011ec47e60f84664e474a255712aad0bbb1c7c1488a49
+0a75447e9feaba451fcd1106d7da535ad82757494620a195b2f0b1622c62351d
+89b62f4f9bb812fed256952928d864147176ff0e03bdd2ba75977cbd0b5ec371
+4478c47d97601280566d937243a0c8b0b33450773897ed5535bea6d7eafd5413
+5c4a4976ee0153f4eb913aed8a1497b743e5e1ace625936b3da74119b49bb536
+1a6fefc0eb959394bd745cea919b1e62c8cac77754c59b725a26c606a7c5b3c1
+45fa3e24e5fd96e230497a0178f21cdd53c733a6bf29605879f61cd4b7ad1117
+1412b03ef42e4f8261df1544138958b3e96ac45e3a45c1bbd0a6d3f1fc4df057
+d0013bd3dea861453e54eb4721124ee277fa0eed1bdb6ca37e30dff04e91b88f
+308edd43cb7dd7e9722e57dcc7f3633209505409a1f98a133874895e00b32c01
+85baefdb0b4e97f75488ea0f76424d9196a2437fc9f67fe2933ff34232768eac
+722a84a7fc52fdf3ad248c69fd7d4c45fc33ffc6a04b562ce367d96b03c0ff8d
+75174dbdc09bdb35a9f4840a6adc555f42d20bf5e2d3da34a991f63648ebe86f
+3e155514afb82c1b3e37fcdcf8c594acf65fdfcf5965f42cb35543ffb1a1e40f
+622e6ed20b4979a37835cf08e40b8bcb015db8eb1a044dced8f6bf6360d0fa20
+e656d90efbf461da451852f58439db9281f60edf5de4af016f8715eee83eb666
+d48784d39764e33008e5d9195ef62439f3af1b989bd952fe0a0d30a85708bb1b
+a353efd6594a3ca201115b3659dc1a80619f155c6649f944dfa3e543971f8dd2
+b0a30afe77658ab82e630bcd4fcc33af8810da1360730055255aacc77fbe09dd
+9b13d44a41e0a1d3789d94bd78494a33ae60b9ad7290e4d1ed6924820140e2a8
+ae5137fe7c2570af124263b99d11ece45cf80a6e11f56dc6d77e50fab50608fa
+09eb1520f22ec16571e92a193f1699f81e352bcd9e0c838a8c1d5bfe80d76957
+7129c9c46fda7235dcc34f604171a75f069f9e00adf56e84ab1f74f093bb6995
+743f9e027fc4d9e6bcd647b2ec7f0d7af2e2efd2dbbb68c83ceb1c760fa71ed5
+0394d38963fdcbf3891934a4cbdab80107778a63f1101017becd233ba0c2e602
+e9075c5e509f2ace7b7d5c346dfb58d0ba3e005e38ea7428dfd0100b7e1fddb2
+7fe8cca96b04f9b349693acba904d44e143e03e82d16158beb36dfa21f57a039
+d6bb9bdd1a787fb9df968004388f8655e9d8b6f435117836bc910697aa1737d0
+55c73fcf23f8b56b58b09195b7cbff574a2418b1ab9f74dc607066fcb798b880
+5fb0d761cd5cca51f9ff0d2e67cabdb026f2a9b292fa472b97ab89af60cba974
+71fdef1417b14e6ff5440867aced2ff9837c1cd1e1aea23bc3cf3444e35f7cb5
+97c2f8d5576ffeaa83e06a9e6383e9225ffe0db4b1575e1f87f28b373716b668
+4f3e9e694d6d56495d21673d165cfae5c6ca112d16a40247216da4debabb7e8d
+34fcb858707d82cb8868dcd8e956d1ddf8bbf6cd57c293f8e3427f14c99e910d
+a7bef26c09e31ca66550496574c0c8f70e7efc9f74bb45fb1ff13b31d8982b44
+038c1218b874ac95ab907d01bca78f00fdec53773064be453a82efa3ce336c46
+69345e172763413f021d75570ddb0a16c806e444d8b9895af997ee7425d2ae29
+1d57d9aa91a5d9e992a7275381ac332a2396900e4d821f69a349d48a5197f98f
+3534ab2a47926edacfc5281c09ea8ddff7ccbdec5b95857c9b2d82829376bec9
+79a6ed53c42f6be0c80a9fe6b90c06624a29adc0e268241e145b18dea609cf8e
+e79720d031691f5912c7b4c1fd4358a6ed07abe23973f5b296ea3e36d8081d64
+50835e84fe95a56764117785baf8b08ac40dcf7453f4c67100445ea6a77ab755
+e3b4882dd0a9d74332f72322d36ab9dbf2199028eb6c6d0f43e79065e0fa47a7
+68bfe8609fe6ad82e7a1fadbe827d86ab6f3db8d0650c31e80c7b5ae24c703da
+104ebb4cbf0d63b0248ac1c47a8ef14a095d902bb390c48760ba7da6fe56fb44
+df02ee166b522a550efab2006e814f4053d0f21f3ee790ca6d17e8ea5ae31083
+5889c2ca6b3fcd267131d33f3f71bbaa5d414479fd6c9e84ae481defa4eacf99
+93a6fe4ff57f5e09fb99b8fce71b958080971e61bf0ccbdd2a86448782aa9871
+0cb686013548fb3f691436501545d2ddb46a3424b643590da9b3069d76eefeda
+946b6ae4a531f7d8b3bf98ab35d37ca5b36729548c06d230b597ab2cfd12dd01
+7fd2398830db4b4f2dd298e945659a564470b22656e28a2defb63714b5dcec1a
+5cca4f9f3a07077c87c06bcc145edea8424d9f44ef8e73fa98fd216cf3fd8408
+52ec5988a7749f0d6923f6c0ef50e9b2a7a61c006316b49c51a0127004566d81
+066e7f1ed02f5f570cef07df070ee98d836ad6048fa77c8888dadea64b72d4ef
+1404634b59cb590e5113d384e43ddcea459dec60c3f1cbec10e33100bc7eb8bc
+7e339177105ad6a478ed9e096477601347e97c3916a3981920b16bf4d64d8fb8
+694341db499b9ca3cf34e140d7db4d6c5c291f100c2d419752e89ba7fac3e8f7
+5b4a63616197bcacae3e0170b7467670f67acd1acab2e0502f02f416b851a5cf
+6f83c3cd9992dc925b388cf75b423edf1d5d234a341adf12cff88bec1da95ad5
+dcff92b3cca7418cc86ab1f1969ea85824d243bc5cf4fafd8f426556dd9017ee
+0242046f909acaed3ff2a91564303d13c8df20ff52e25e60cb7168902daac679
+b794ef58e0ec9a5b5a97a1143b09157c97f9946d98077de28e8908b84f73a018
+e0c3bc6f4a6ee088edde6f1e0f568799d86765d843965381467a99c8b91632e5
+eed53fdeb8673bd6c9b3757773febbf86ee428d4b386985e810db8124f5bf974
+df99afad632f03e338642c9312787ac47a9d2f4a10fc5399b6ae9029a0336d89
+2aabb090e581b749473ff20815277881f985146a028f6dfb0acd19954a0bdbb8
+b4ed1a65d3b9866dac29c6aa8aed39d956433ba649f283aaea848f6cf8f96268
+cc669613981e4705d9220970608e67028de79d0b3668b4a3db70f61c9fc01078
+37ec51eab70d92a017d96cd8893eccbe23081dafeaf81ca2c9d45d38cf554c84
+99a6b479ebfbd96be8f7f4599b10dd45b4ac860ea6aa410f161df2b33c08586d
+87218a790509800164b41e3cd0a7d30d9584813c42fe3935ee56c6f22cde9fd4
+05615ab2abac9dfcac550140c4540d6dff9ed67f530570744d0be3e56041e1d8
+ceb5a6925b3bc52c206f6dd87f2c4de70ec19487d2ddaf20ef6b26fcd60631ba
+b1677d0ab695dd68b2a3b27a70b0b48fcc872991bd0b9688a966e72239b58d3b
+2e58862eb4db390e169100e539c238299449bda356a0968c866ba0e0bf3b88f7
+6cfd39fe10ae30eb6ca7149b41e412cf556969b4c816a1945c0878e2a79e7ece
+7e52754c8dfa755d79fb15e5576a8846307527460b6d9182154e23b84ea9d443
+7fcbb470e9833d2f3f90aa88d0e44b175a9358ad0d846ae6744c4b69a5e24692
+eb37b5b9678729be88cb9f84d2773ba99b29ad2056420328116840ccb475ab76
+27bc7efd2dbe6dcdf596e94c09aa959f2d43d48a80ce2faa7c30be324d18b8f8
+70f77be72199e931d5d5f3acf48ff8060e168b48d066b2354fea58713c1a5367
+330c9491fdb6fe9654a8fd66803fdb1990bcf5bf2d8665980d162f1be17663f6
+857563371b1056144cf54ad30f1fae5707f7bbe87fae41d2c683e8a02931de24
+29e66f35188ff3594f37f7ec5021e8ccf00248be459f80ef9a46d0344e153789
+69729194731a49135ae771aac663c0037db67200c9677bf1f39abbbc54802741
+23d36a35f128c1c35dfac1a29a9c1a488f6d7df23933488c858667bfe24948db
+86bd0087f94b0c6325a403de4a434bf767c137f248c85257a72e39b51351d401
+8b530913ea8be8bfbeb039233bc3432db0b61aa281a0ce2f01b0399b066fde7e
+abcafdd46c4d6bcf2924de2ed3972c01ae0213dc1553928895c2b541b1b254e7
+a1ae46069a110c55de12f66358815cfb07cf0de59865be85f1a8f2b61d0ebae2
+7d341bdc37eab342af148a05d0fa415b86cda706746c75e0fb71a610e455a64a
+d8515705ec8d265f3e4ed9c0203744c86a1fe55ff52b6c8f4ba71e0a26651cd5
+fc38d93b2370b1e38c29343c96dd9b3d4a39b78f7bc7f2eed735f46bb46f96b1
+becbcaa7cd99ef23d16bcb3f38a605dbb908b28b1039d2ea1fc5d7afc11f1aa3
+798b407ec236421ccca18fc1f27a12d7e0b253039827104461c51ccb2283c9e2
+6fcb819b656a1aaf1b29821bcecc50b911d1a05330c43a0c6025ec90dc134042
+77ad9424c2d2e642a1223dc74ff16f70b54c0ff578157f0c701279facaeb2563
+cb3855872d3933c0a7be7b633e7e3ef053e1213e4cd7e1c57804eccd8026e581
+beb4c2fc59cacb4c1e7696d165316d7f3391ede443873c7ac48277e47eebc64e
+3023d06ffccb05a1a71b64b7da4ce1b6256c4970b179c91e1b5d6ade81c151d4
+dc3cccff1d6ebd118285d56ff7631f2c7e2b89cd70b2ef7a3894366fd177c06a
+39e3971747f671898a0109008e3190b0aef909597ffe91d7c7c2069b5680298e
+eee7c04e58cd328c1bafac2a8bcb63f6d9a6a56f29f3551ce1d2512b5885d1b7
+8397e464b5f81f4803eebfc0cc632fb653f52fc7ebe2f64ab5ce16e840bd0577
+cdfa24a928e2888ef6171e43aedaf88616344cd64b3a2c0873dbbf8eb1fdc08c
+cd86f324775672bc550241d139bdeca9e6ee36d49fbb117eb5eb456d99258067
+94ba27cc50585d2544b2f1f16c19ba41b0cb308c4f50039a843e66b20e04db1e
+b0e99faa3556d8e95f4526f0a105d4b761df415148051c604077ce2025732152
+e6db72d810bb8d81c733ba78c0deb8799abaa20d3d77152b2dd109d70efb2bdd
+7f17c1b79bcecf6b30cf0f852ac61197e0f601d2602205bc37708fb4306a782b
+1f2a39bb03554a1d10100221f99ccb45b538bf2a94ddf8c4e0b10c62f4af712c
+a44387b0038bf2474dbd2242c735db0d79246d73a43137d535eee525502ee440
+9021ae2414e9f443740cdacdaabcfaa0084a60ac34303dd559269eb088e2925c
+632bdaae44dae0ae57f3080be448c56aa549b620d1729b6cc2974e571a5697b0
+4ff3e6f6542c4fcb2abc9261d97d6e6e60538d69b36c8189491a978a7d00b9b6
+3e62a1f51d6002e12d0604d53af0188e565ceec8ba572bfde122249dacc9d9d7
+75047c69ef0485adf9f0dcec0f0c926ab91b551ebd9b8f4aa03817c25ca92395
+518304be94b5d56bbdb833cee92c32b792c6a31f37448b319880e4cac35d2edf
+dff530d0f7773e5148d41ae56e02633781cb2abb15ec2d94ae52d3c8fcfd3097
+45d95f67b560165f57393a42fc7474b5284c7cc0b893f84f8733768264ffa8dd
+0bed83d99c035bd1a83597f0d614797c583ec8c5b96b9739f304edfe1e00ab42
+38f353a82e7c71d74877d8519add9b8c78f611174599512f11c22c10cb360307
+b262f1f78c7f9a85f1fd21e94d72abd413650ea6a69b057e021ada9787d06185
+c57c0947f9a2a81822054e855f802160649e25ddc82969d94c052c289f35bb57
+c77de5dfc63716c5b0a87bc7ed859663c457f080089e3d729b9bb1299050788a
+79ada19db21011b01a47b278615be5359e71ecec7c06a67c4943e6106e152824
+ccb1fd39c485e90efebb1b2192d93c8bc52e356e51e5fc805cd7e43543e9c500
+d0ac85b7230350f9f403340a16bbdbbc3bdf0f7a571aaec4d6fdbecb288c210f
+b7c244f1908305a0b1632a8123001175e36124b543ff92c16576d373b9bdece7
+67889128ffa3497ff846f8befaf5de3b7c339f049adc9116c9a7bb8bae435798
+08dca2d9c151d9329c345919930e8437054501bba38c2bd5102a20e4291203f6
+eece2f70bff3df08aeb8ddf1806e9657ee4a5e3fd5a8fd979d90d45734f14f71
+5d339ac91b7fa18a17be81583c08544a8a32729c17975014d629b139c0b3c236
+bc9a99231ffb339b7761a2586eac564be734ef37992cec6c06c2c93de2b340fb
+3a27a52dabe69d9178d9a544430cff229335edd6f817bc52c690917fbf322852
+d4a7a709a593704568cf142b45eff164d817880cc93782c223247c65fa99aca3
+5c66a26093f9ffbc25ca9b3cf6b8ba478695c68212e80e3868a0db1a1c84bcdc
+df05fe054733a1b794ed1cc483a57b97ca2e97fcb1ceb9cc2ae7d5e0e064cc8e
+01cc628180359749622ac1cfbb57d51b25974ecb15dc83f99dbfba2d779adaf9
+6a9307bf3faef5d2ba5135a15d13c4215570e772376a4a4a3a5ec4028ef11004
+b93acaf38128de94531c23f114fec41cb2e2027e8ee138aef6ad017f5d97a600
+1063be706b65da0eda2234e7e9a9c27c084c4564b362ffa93ec9127cbc9366ce
+7b74805943c9961be5a5b5ec87675b02f756af1b70074d03374ae931cff31757
+4145af416a9098bba84ed2d3ed44019257c0f34e7f94dbd10fd04fd15ffd1b64
+f65b2c02e581175436150a074de43f8e11fbc56e806486665cedbcf387504d6f
+0687a13d668c69dddbc37adf91ad0091a770ee23850ae2fcbd6b9de9d8a8c8b8
+eccde66b7122c7b9602dbd0f6b7f7e4890933451c7a3904382d7801bcd992f76
+4cd41d74bc8723eba2647db7f813b465d11052e0f4ef593049942915c614ede3
+4f8f2b77bedec635eb3461d66cbfd4be1689a839b1feaa41c0f0fa23669806bb
+52fea1fa5ab524a447ef3cfea4583a7790baa418ff8917388daadc5a3d1a9fcc
+7f4a826c912eba5d4b82d4c29b639d56532b37ee9aed6bf06137a3af899c70a1
+ce4c9940e6ea87b6e274696c4a15d6aa3c17f9334aa84fcf1edb48e306640e57
+892b25e67c6f87e4e4cdf1a9cf12f69c0028b5fb768e839e1b8f75f3ab2d9763
+6e1be8c5a73bfa8675853695ee32887dd6df5f03f88e637d45f752d22f6c76b3
+71b9a514078c3200ddd2e998f33f1ae5c0a5fdc932f7c4727512caec232a681f
+bbdec1a919bddaebf5efbd06869bcfe0637b72cefaac13f915f25cd3a926c0a5
+4875435ee6a413e2554fe4ecfcb96c1b5d8719e84dd34939dfd7795eedecbceb
+786df32b6360bffed553a74b444a35e0ab0517cf7aa9c4e420e5bea4a5aac950
+54cfb55d1a1e57b58b8fb382e8ea2acbfb9b43d1ab67e0c1450ed3091758c1b3
+8155fd6996500a55fa5d134f17e55978d930425e0c03748364c46d3bef68a390
+649e09e48c2fab92108eef8603c70a977a388d4d24971296aaabcb932bc96033
+f648a6ada265aca938a6512f456fdc194f7186808deb3c16769d3faa850f78fb
+58610c776c2ef3f208404def2940e484a801cdc45aeac88fa9852d1319159340
+3478b1b7f204ff297b67bddf1d38e256f864d3a83d6919ca7db1bbb1f5b8f6e7
+8ba272d1fb28d760618dac6f5633b9481645c9b8eb3a3384518103cc68aceb05
+5a91dd8def04b49d363b0c6daf63aef5d85b1e79504c23b3bb50a4b7194838d6
+b417b0ccbcd95a46834f9bbb2ac30fb2d9b9c31cf4b608e1379399a95f8dfa94
+53998a743c5a5bf33ed1e10177dc4a2a347f5fa4d09470cb5d71b07bf459c800
+0119a2164b143f03fce36c19384a01cec5b9080491b82b9ff115f795d969f480
+b7232d0375a9d46faff31fecc9351b42923e9ab6207d2723915d7843db279505
+280d70d9c80a1821a257aec764b7e85a1e8da7c40d42a0f77385ea66a7643435
+e20af708470f645046bbeac12d840fe3260ce75e20563014d9e2ebdaa57ef06c
+0ddb55fdf6ec3e064312d13e25299b153169788e8a4decc095eb37eaf8e8ce2c
+cd7174f44ee8f3875c5a3de3c7ce22296e99c44628f52cd3d18eb9215c34e563
+0ba85b5fcf3a211021a19945510c7e39ab56d977f74fd50ba8a70def82fa6777
+6930390700b4636330a998b535126d610e8a1cb63f618d69896fb47576857f5f
+8926ddb4833966695a26402aecc48bbcadc04c2833afcedeee14254a9e77603a
+5bb7b9de3c97007901143a7901c00b77a13e72940a6507a76164989e71d91eb2
+3080c585be2f8734909fa1efa7fc6a2464d95e4c5051fb8d6065a7d9a453cbdd
+033626544b72108e4c4c087b4e4dd972893371ba7b8e8291ea4f98d03c61ce6d
+d56734f17a66697f2260af9b3f8b9a36717b490e1ce649d839a66133da7742d2
+dbcaa22ff915fcadffa0383cf34c2290fa42fe23128e29e7bb1c59e55b7ac347
+fe66481f485d7bd09f55cb51d208d0765a510d5f6958fcd3ff5a5ed27d06a02a
+f7ecadce4b4ac5f1d0210c5637f07382193d77945e249d2c4973aa43dea41dc0
+51cd72643bda4f749dd5846a9d3a7346d39f78eaad738d2d255df0f0cab5fb10
+96a0ac86bb013980dedfc84ddfef081700fc3c66b6d5a125c9e83df17d92658c
+10d79a8aaa222004c20aaae6128132c64f96a7a7c869489a63860c15d53f958b
+d6fb81cd165bf253d996c15295f7c2fc52c13b51aded1c774cb35a0ab258bca3
+ab438786ff7e648f42ab568fdd9cd598c52b5748b0c44458d4e0b8080ad19cbc
+55d8aa1a78cafed7bd41a864488d8ab0bc12f6689027c65c70a2b26bd2590026
+3e80ba6189672adfe377e9fb516cc6bbb0f2e341dc9e2f34a8bb00b4079ea28f
+7c8138c415306e00bdd8e71176faf06fac92e38e8e15dc6ec6cdb389d1a15310
+ca67408a9686f21bf6fbbfa7ce032974e2b860a3a72561508bcf22ede4122185
+b83532444134af2bac5ced1932c9cc06b70160d0cefc8f76ed1108b629e81060
+ce6c30e0bc9ac232fef7ab1c99e21792921bddc20f2afd3b083dba29641458a1
+1ba80613610b01543d336ebc45ae15c276c9ff18fecdc0cde3be18e044497217
+b9a812d926538fc42871f439282c1717833170bdbffbd7e2034d794eee9177ed
+28045b2dc45959426e35d30fde
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+cleartomark
+%%EndResource
+/F130_0 /VXAMRV+NimbusRomNo9L-Regu 1 1
+[ /.notdef/dotaccent/fi/fl/fraction/hungarumlaut/Lslash/lslash
+ /ogonek/ring/.notdef/breve/minus/.notdef/Zcaron/zcaron
+ /caron/dotlessi/dotlessj/ff/ffi/ffl/notequal/infinity
+ /lessequal/greaterequal/partialdiff/summation/product/pi/grave/quotesingle
+ /space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright
+ /parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
+ /zero/one/two/three/four/five/six/seven
+ /eight/nine/colon/semicolon/less/equal/greater/question
+ /at/A/B/C/D/E/F/G
+ /H/I/J/K/L/M/N/O
+ /P/Q/R/S/T/U/V/W
+ /X/Y/Z/bracketleft/backslash/bracketright/asciicircum/underscore
+ /quoteleft/a/b/c/d/e/f/g
+ /h/i/j/k/l/m/n/o
+ /p/q/r/s/t/u/v/w
+ /x/y/z/braceleft/bar/braceright/asciitilde/.notdef
+ /Euro/integral/quotesinglbase/florin/quotedblbase/ellipsis/dagger/daggerdbl
+ /circumflex/perthousand/Scaron/guilsinglleft/OE/Omega/radical/approxequal
+ /.notdef/.notdef/.notdef/quotedblleft/quotedblright/bullet/endash/emdash
+ /tilde/trademark/scaron/guilsinglright/oe/Delta/lozenge/Ydieresis
+ /.notdef/exclamdown/cent/sterling/currency/yen/brokenbar/section
+ /dieresis/copyright/ordfeminine/guillemotleft/logicalnot/hyphen/registered/macron
+ /degree/plusminus/twosuperior/threesuperior/acute/mu/paragraph/periodcentered
+ /cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown
+ /Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
+ /Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis
+ /Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply
+ /Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
+ /agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
+ /egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
+ /eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide
+ /oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]
+pdfMakeFont
+%%BeginResource: font MFECUR+NimbusMonL-Regu
+%!PS-AdobeFont-1.0: NimbusMonL-Regu 1.05
+%%CreationDate: Wed Dec 22 1999
+% Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development
+% (URW)++,Copyright 1999 by (URW)++ Design & Development
+% See the file COPYING (GNU General Public License) for license conditions.
+% As a special exception, permission is granted to include this font
+% program in a Postscript or PDF file that consists of a document that
+% contains text to be displayed or printed using this font, regardless
+% of the conditions or license applying to the document itself.
+12 dict begin
+/FontInfo 10 dict dup begin
+/version (1.05) readonly def
+/Notice ((URW)++,Copyright 1999 by (URW)++ Design & Development. See the file COPYING (GNU General Public License) for license conditions. As a special exception, permission is granted to include this font program in a Postscript or PDF file that consists of a document that contains text to be displayed or printed using this font, regardless of the conditions or license applying to the document itself.) readonly def
+/Copyright (Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development) readonly def
+/FullName (Nimbus Mono L Regular) readonly def
+/FamilyName (Nimbus Mono L) readonly def
+/Weight (Regular) readonly def
+/ItalicAngle 0.0 def
+/isFixedPitch false def
+/UnderlinePosition -100 def
+/UnderlineThickness 50 def
+end readonly def
+/FontName /MFECUR+NimbusMonL-Regu def
+/PaintType 0 def
+/WMode 0 def
+/FontBBox {-12 -237 650 811} readonly def
+/FontType 1 def
+/FontMatrix [0.001 0.0 0.0 0.001 0.0 0.0] readonly def
+/Encoding StandardEncoding def
+currentdict end
+currentfile eexec
+d9d66f633b846a989b9974b0179fc6cc445bc2c03103c68570a7b354a4a280ae
+6fbf7f9888e039ab60fcaf852eb4ce3afeb979d5ea70fde44a2ae5c8c0166c27
+bf9665eea11c7d2329c1a211dd26bb372be5822f5ea70d99eb578c7befd44cdf
+045a363056e5e1cc51525ea6fc061dcebb337208eff729802376a2801424f670
+0e7e6397b28f15bc10b40012b0a3eaeb2693e8f7f627c4c9c7c6c5bff105c1e4
+1b2b9e8f09253b76040d268b80719e1b3f5a55ab7b89290699b50c1bf1baeffe
+1f57be7b5ea025241a248a6d4cfa5067a1da6eba4cfc940599ba3f3c934d7248
+b8e4ac5816f0d2ce8b3c4193ce39d19fffdb75254573173cb51ccd83c2f2d06b
+2483cf9b07b21ec6f502f028c273887bb06dae2afac10e9fd3c7cf51bca7b277
+b706e425302dc78975ac0e43b87073257a5cd7424b6865fca89d886e8f95c4f6
+d457623dbbc0d16bafeb4c649f5d72b09b18502eeab687e915e9b536a361b4f1
+44c3cd4cc683b5f05a4ecb4823a5eb5179bb7eee8b76c21b2491a97808f6318b
+585b0bad98f42fb4a755bcb74cd354f794c8bea5b90fb9681bd5849d45247e39
+930c882490230e1662d39cca875bffeac3e79a78de6e1298abe9817ae98675c4
+16220ad0d3a36580ee2f2a17aaa1246c416d58a4c52fbb26aaf3b6f75833af8e
+3aa996218dafa571fbc7cad90ece9c883c813d8f168c5e86bbfa0f0a5cb36e35
+2de4caa0f8d3227f72c5056bfb5bca6bf9c60e037a0e44670a8d3cbc9a19f379
+ca8db30b711f518a8c7569211ac70c46eed2af62a37f238bd0bd12d60332e673
+c6e784b3eba3f2e71e9993b97e8a38f85048937e958f1cd8fc6e661048546135
+56b810fa1ff611b96495081c04542df7fef085dec619dc8c84cc57683d212813
+9d14728aa32723e1d15f2af8f03422cfafd8ea4c92dabfe00e6110bca39fc555
+bc066ef848e437b50688daf26d001aed7e74605ddf9c0ed36be45455aef92689
+8cf32baf2418e02118593f54fe1857807bfa0b93b5cdccd81d28bede22cda6ee
+2e32422c1e8da8866e526300f9059e85ca54122ecbffdc011460913e0d28f7f5
+fbc9d7f9f6934b3d8efc1a91cba4128f6bbc5eb55e5e7b73647bff70662bafbb
+145cfa65df3db858bc3fc577b1bd8bc74fb8a61bfa71b8304aeeb36d8efe12fa
+6f5eee0eae0830e5177dc745250fc362f78231fc3ac9864559dba92dda2feb96
+2629293435bf4a89f913fd15702cf325981ca3a08b327f7ee35794a9e88326e0
+24559b547fc6da61b7a3b9357f72c767baa9c79c4e7b77f70ec01ac0b8596425
+5f7346dc8cedc702d3d57b09ef89cdd33756619af59acb9d17a3abeaa6c65218
+6d6855348a1095746b34af15df313091c59e5bf9e79b156cd7903c1c42e115e9
+c5203037c808bd295195e074fc4a46fbb1ff01c814878f0c177f552bdc9bb698
+349d73aec17997374ec90b69293a064442141a44c6fe8e3c283c02a4655c579b
+f21b53d1fd37996c682745600785c7b52c4eeb47fa5fd640739e1f09d5c5dd2b
+b7515a4cce0a21281d315563895972bee88bbc7401be9e20cb160b6bc81ed469
+6d66169bdc648aaae8a9495b072911cc814c19d53b95de0071e3a439d3c09c3c
+1cd422c605740a8939487e26bb9233d4cdefcca49bbeb1b913570a51b2f96d30
+2ef8913c6bb60b54f7ea4b8ca16ad3b4194dcba28439eb31a9443caf061c4d88
+c22cec8d9d8d85d7aa225fd64bfae7376abd40f822ba1ecc9339e09403195752
+fc03a5c4742ad93064d975906ed63acb495aae324403d3bca118179e10256543
+1bc84d47e0c016234eec0c52255ae783417941cc884efadb63f8269876f00a8e
+1e1f19eafffa00453203a0752750f8c876aaf87826baf77b81d336ffc29249c9
+a6a44f40381294447840632ee59a3c4530391f35da45c16a001f793782be488b
+5e01d7f75dbd53fb31f956f16202d3d94a300866814ba44c79764cc25acb57f2
+333dfcf3d97a98fca949b1da71ab27885183d8baafc9bc743143f2f1002ad752
+1e55d207de23e97d1760cd918a55148e37e05f6347e8cc299eed28d7319abcdf
+a4a279d5f64cc2151f91a0be9e8382a35b535a6b5f41f3708169881c243391c6
+67d9121ba21f6bb22be1ec9933d9af1dde9693d7704c1141ce2b977ff5181299
+6a57f7806814440a28b1dfb62c4dedb82f0ebaabef3367bebcd43246d54d8eb6
+7af07b164374998f06a0b7e271ad6ea974698a806002374d270c6dd5c9dfd5db
+e056fe1b3d58482a0cc98d4d5603c59ec2e13b446023692b9ac2dd7cf767d2dc
+a7c62bb3578847085cab79f139bd312cb07ce13e38c3fb8f695bcf4021c282b0
+9b20ba67f378cbb8832751b8f3eed370a572139431b9187893b592529fb1b6c5
+19f51798bce9e56ca50185d42fbd85819c3a1153d65997511b19acf87e69c07d
+2ca1a7401c2b23f99c19f95da0df136472f9fb574b21aebbf0c2f892b9260001
+9a9173f108e72c3eb4a93719293e8be026b833cd709c7c05c1a2e7250cad2586
+ca70fb7d927e36a2e4a6f34e754c8dd8ea2571cd82054700d386cdf3420f37bc
+b6a70b9a92e46cebee13f6641c67bc40979f9b86e052164612d3dce7be67fa71
+b26ee9f425b54b3577cb4acf3dad02f2e55d2986dea88a5a1955b78c0cd5decd
+213c55c9c57183a7dd5832d49ee81724a19abb7da0779f1aa6a77d5d31434a09
+c6f53b7e27123dac042f58dc27653d940358bb8100b416b920aee20672559f62
+8b20c687d77ff83cca449e94fcf4f06614fc539802340619e3a791a18581ffb6
+9bb5961d1e70e55615cce5c9e1466d77435e486f15175cf87fff65e58127b5c3
+024b93c1c296aab24f29483aeba00736ed30be5bb5284d7afc43294b927bec1b
+86814a5ac25a3b9cd1f25c813cae791f937375e013159624a360955a58e8fa94
+e49593a97150702c71dd8dbfc3774094df930414ffc68cbd4b4a25041cb3b657
+a54c9bf780142d2586eb5dd9ecc1eb5ea69245d5d9c2af868974ae5d46e3a544
+74e96780ae66023778659d9a45853c24da18dd5ca0489ccceff253b009c06cf5
+826adbd0e8fcf23edd75c3d3de8a4c789a895e06d20606e4f8e3c1bd77976e71
+de409203ef1342bdbf2c11bbab4af5a709f0462aa8fa3a02cbed6f23fb4d5e3d
+1751acbd41eecd8571518a9e13889c221ba5568cadf730f9da026fb38e30a25e
+87ef6a13484d6ee31c174bfa4b80cc38134d7b18c85c83b4f14d3c7b0a0b7069
+7baa1a397252ac47b67306e45d64061535d05540c86b9599df909e105bb55100
+3a0271c25bc5d596da2a446e35c019b5dead7b289614bd5085d49ecd0464b494
+cd1ab564a93ac9cbf438fa558bbef71c2fe003573a03979a10fe8bd54a053724
+a529f46ffe55cec8d6bbaf1f57d16185595c82a1ef42e3c81cbc55bf50587630
+404b2090df6d9d25468c1eb7a4b2b3da7f5b718157ef8b5f23af088301e46411
+b51e6e0d464096ce22bbc2028488d9af49792b4a17cbbba8ace8fc51e1de01b0
+97e6db05466bf66978305642b6790c08e59a7055f9442cc2cfc23095df2c27ea
+decc1ba54d6b81ecc873a9c71796a1ece75765b878d12e4da9e19d026ac44dfa
+2dc7e540506546aac70e7b82ae7fa98bf36549f4d540fffd53abaf7ed9044ca5
+6b4e9044a2b23c3e7c70152e96f4e64f6b1918946789d4f703675f3dd6e8e5a8
+f0add5f7e442c35cc782c92db2007596ec1a76d2d22ca5b00f7f9aa9819327a4
+db8d0b03369a05de96b8c4eaec254cba0f39ef6ca005c53afd0ec32f1c092367
+efd9f773bd00b95a60523bc0392b050b15ad70f7cb42f6d36587144cae2447ab
+aa4b4d9377a7e86ac489685833e1c14c3e17638b00884a46c1efa2b158f6239b
+1bbed6fc68ff606278fd4216c2a6d7888f0f0e5dfc9950962d4964901a47d6cc
+2e3243e1dde9ce7f435a7dfb19349a3017ce44b87dc6baec18354a2042c87ed6
+c1e3a1a505cc679e32789f75780f84082cc653a010d14dba84da0191a510359c
+1d24d700c58e54718f1d85396e7c5d3a365637085b6f79c061df17bfcd260ea0
+6b8416c9042c2831eb041346a22bc54f9d7ba43f8c4487fc240baec20ad4aaa8
+c03f180b614c59db6e5ec1531aefc908c46b93419b9f5b2d4eba0a67ba43d685
+1ad44d4b43b7796de5c9a11f726a90fb1a389a342143f98f49237fb451c43eb5
+981562d923d684923dcaee71b52ab4ce6269169a35f545e74584fa440c41eb82
+41ab194c78a5b980d021b3eb7994846d963b78eb6e149cca7713c12f77023002
+b8a797c9ccd0c2bd70dbe44f81f9d274a5ff3824ee34cb4317fa4971d67d90a2
+f3d1b1b84960f0fbee40e6341c5271b5b945b9098f3095986ab7db2e0714cca0
+301f6b8378559d86f0b0d95c2dfe94ac8e10df0c8c16dba12505a0d467dccb84
+16bfeb18784bdc10624f15da1a880ffbcbafbed0e1c7360962478006db59c78b
+ddcee524b6f9b15a8849ee19aa00fa3f71a3c2c96e68dd0248a94ecc43a60ac3
+88e49e005250706880485df109ce1506c0a4edc40f5ae5fe347d52ff63b26c7c
+185a698e171244aa1095620494949d526276175a7e120340d3247cbca4e3df53
+641d6d392abc61c85a22e06cdbc89cf37bffdf8a79361c6dd69e6774772f699b
+92f7a7184a00fdd7f36fb8a08ccde5bbcab3731366c3b74072044d3ef2ebc1cb
+33118b8c09c04174baef8df1bb4a1e1f848c1a5178ec58ea621f6f8a63d0fcf3
+13db79f885ac659c881ab7e40798a4339e6a78ba27cd9e6803c3d4df196c462b
+d08555bed51d7cf5821204728356cf813f554517ac5e28e6c4047c0100610635
+7d25c33330758f71bd1043365bda5d1d9214c8b159d0f8fb69e40e6fb4ef4668
+a228938436dd209dda5925597151f8633297862799152b0317bf21f9572f503b
+b10826aa7f8d15f5d780ea27f1b8ca0ba3dd732d3e3effcfad6e6ad8769db6c1
+df22ace8467481d16e8af6f56032c90c8f2500ce66afb94d378d893e84208048
+ec0cf900507f02e40da3e99386f939e05d9737b0b11b7dfae473496d056be5e0
+7f1cd25454f4b290cc43d936450c3d675ceef5da533db25ec07addc7e8355d8b
+8abb095ddd61c91da2dbeac0574e9ec9d316ed13df03c997d7a4a9c7a6a3a165
+ec1ce316e820e13291132ae91660d5d1812146abfa137726e8700395b4274502
+7d53b1e5cba817beb577bddcb956e89aa2d1ab24128b9ae8e06d9f0a6dab93bd
+f7ee8e2ff918255c3722a8b0e8520dd02ba7c92aba13ebad9ce0ad0f16f728d0
+ad49bcb12b429811d8ca1b5ae29b7d5393401eb5802db4d4497cad43ead218ec
+c674f42143bc174c525bd736b77dc28bfc7e107366eb9091eeda60664a771782
+cb41506406dfd29c974c5a18da88b473ae58a2f1fbe5680a40138a9d2fb7955b
+3fdda23b2cbe7e27c1dc4aea3069b1e7e25068c9051672b8c9a3a37d6e6fdb24
+3bc20d303198f9b8ad8154b3f4a4f2acb17c31a0489c1366eb8a13012c6b8cca
+4d416b911de781563e26c08538e038dd8ef92435a054348add815687ddb99dda
+88f1e2c5887707cd4be47f71ab81a3d6cc3e039bd09697734840f8bd0b88aac6
+191c6db089943f99ee4174e5fab3baf3a8429e273c4d1a5140e0073f86105402
+3f60df69e65809b7a1a5a8aee4d25bdde9fd6d05a3fcf4be5f253e41fc49e121
+df89f259ba981d2617209b53ebd92e430a69668995961177b159933501771905
+08f625b26b5085c04b325e7fb6bb45eebe3bc9f5c5114eb37f19937635d71a72
+39a0039003764d10cb403b58c61bf411aa8f5d717bcff23fb338da58d13ca81f
+acb3316d2b5b675e86a95cfb525199a21af248a1245c92ee37688c6e76a95187
+3b411697a1ea6694e6ccaddef3d57114cfde70609de67972edd1db95d923e077
+4bce7cc77605f9ba5226fb792829b1b8eaa15361ff78f190a0563fd61aac4452
+ee1b0d293e695416c667735dd886d10e4467b613dd9bb899f2bd75f2f13193f0
+481fcd3b4e2aaec6cf2829b1521dd4b6471ba31aa0aa4d63a6456203896a111b
+89c106f1ea85bfe0c0104b1292a1f8d49334578375b55deae2d7381f5cfcc023
+5ddfb3d8546054a0e6d5d81e4254383385ba593a7d3a8e0beb34285dd95d97ca
+3eb598b643834644b611e6db4b8b4360c847120038768e218031e097ba0bdea7
+732f7e460155a496b91b3241c74f9ee0c99ec7adf6a87b701a0ceb07fef5fa44
+44e127de3e777c23a8d938f9879df1dabb7adb31247a53174f919a2a5a4f920c
+9415f3976a8f4b739e114b2c49d67bcedc1852686cb041e3ee94ef94d9f2096e
+76f1c558f40812444c6f0f4dac3a4bd22b82e32d8bbf1504f8232ef00dd2f3ff
+5c4b8349a9d1becb8c59a9f4763f2566a7a513a6c11f54d1fdc1867ab741f3c6
+e2b44aa95479e4e9813350473bc7897b9ec592f01f97697a17967d344a4bc9a5
+62786f28f87e3639d091922f4994671b22efd41ff3f6b8a651117d0a2a97ccfc
+80a69c974fb2ccb36dd6a4897bf88ebc67bfd892e35e6940e94893e1cdfd2799
+8cfcf2b3737a6232e4783eb4a8ae56b83ed7661377b30225a75a1b90b73079e2
+6aa33fd37b81f7d60de62931b6be9d16367a5fab1d14d281d3e8d09dc525f549
+ed03a449df4655802bc3265010f286df86602740d8a86aaa228b9c47e3e78c0b
+22d2600d5cd55a3116058daa7e34174144f78a8f72e0dcb8cc64addcc52df0df
+3f8c21d9cc04e187be53f8fed4f33633ba03afa178fa5ce769a7eb0e1b9bf5bd
+de0ea74dc99598a66696bf6d5071da995a30b8144acdea116cfc447255a99cce
+4ec01bc8a0b355c0881f6e9eb48725d61ee0b245e0f7cc35b9e76fe11f681017
+f794ed8d4c4c7a02e17bd16a02347f28318ccaafe0575734058121e3ad8064ec
+a0086a58f216020a2dca29376981a2595bfac2a0394d448949b52ffb47e5c5e0
+d6371cb4a417ac834d6c9fa0018c5efb16e39e32c85088b266d74af5630b2544
+d4cf403482c490f86d35f81cc44b34200400c10c6dff035423e725d41d2b5ee0
+c3f03a603a161713216af97036ed38ff8d9b09f189ad191a0d03369c3fcd5a3a
+f88a57338971d7bcb5f3fbf8735ad8459524d93a92eac1c2bf5f0e6e1cf675f1
+6d72b35ceaf34d8fac178a1dd823ca0448ee1fa2f616b803c38b89238aaa1ae7
+cb057ecdbad28147da46a34b8a1f1d389e082cc3e8eb1a7e5c0c932341824c21
+570e003d8c11c87d7082371d3d4804da32fde118c6c5b5b08828e5783200c6ea
+0a7ab73343f5fd681a3116fd818c7054a5199212eb0f3a9a0d87bc364670ee2f
+7a5081a1e48a58748d297e014dd5db7faaf7a27459f115741bf4facfa1b395e3
+e97452bdaff906af9c52c5908748f1e13cc85d165bc893c1eba728458b708f8a
+9e8990a6f258bda0989aad0959e7326d1d6bccb50c4fab15a6ea3cbe94724fc2
+8f174df93fbff41adbb9d4fac0124d33151d06753d4d879ac4f15aec5d1cc0b7
+a9e861f790a16eb0821b2a7b7b42d6f3e389c51a1d7c652859ffbe66646d4199
+a62ed28a30c8932dc4d2855e7e6311d79cedba8beefe2cd529f4b45382f3e6e6
+a7659da9b786fe7bc2e431ee3f11873ab2709200b715343cc25c5365d06be9ac
+829458ff77f4d509d9c3917237d759da6775e09c2eaf4ce966a14157ea2780bc
+e3249446573c82b33ec5ca150022a83301f00f41eea3694059b14b2a9abcea30
+65cfd06b9dce3823477bf80938d355427666a8287a65e231a2357aed80d27a61
+58140c2cdb1f44caefd6b629fa661440c361dde7817154052436a36bbc1bf382
+e30285979c4568b180417740a17150952e3eb4091f583083d75a05a2d91009de
+46da396794dbb5288e2a2e6191d3f22e335f0275f33e9af2154cddbcc99b149c
+6d7aad7fdedb23c805f09725b60b5ec77e8ac9953a3578b23c6023a196f35333
+a36fab2ca195e397fc82318434e9f2844d17bbdc177989fd8af61ddb46512d2c
+f5d7821941b18b7c1f1be16df6e6bed4a1655edcaf6300fa8765e903b03a95a7
+0a7e6d55457f451a8177e0e9c9f3aec8d174843e3a99ed698689019e96cb4683
+bb24c71e22f4895656acc67ecd671963abeffef53724a645b98e5d2680297fe5
+2d43ddfdfd5536f7c239a5092076512a2a9821f12338e388bd5115ff4f4d2c01
+d741f821874380838988c17bd975fc388a253c8c006c67963ce3c4404baa0750
+c56760e367b566ed129911eb056bee42f12bec9980177f1b3713068073cf34c3
+70d6ee202c49b42809afd1f8786e14a6c63794eb2ddf49d5a06f34de23356260
+96ea26d57b94a928e5312147ecc40bbc6a204c4b3ee9d4f4361f8df9e1c1ae68
+ef60fbeb99339842e652479362b19d33de080f9625b5c167bf2b11775929b12c
+fa9e9a89cf84f249a1078f5584425e2ad8ac82adc298867ebea1ec6c0428fdc5
+01dccde39e5fc147959ea254217153c0b550ef96c229664c22286a7827ebbf15
+c7fcdc57dbb5914bb0460b6e0c0f58c98b264925d9996d9e0d31fb70e66eb9e4
+d928015f2c12acdb7d77a66408f2767c05f93292fae45492e5dcea337cbab346
+da82c905ddb016bba5d31e740b813c3d709d78d7ac50326f90d2e4af4c1dd893
+e26f9767db437b52a758d6237e52c4a2a71624d2b1f79dbe83b6b7839deb413b
+f34b91b3dfbc88b7b0b78ab579594ac3d57471074f78e59a64d75b4e6ed3cf22
+33f6ebc86e289402dea3907b0a2406188246e8e44054f81854dae0fedaef8952
+c05c8f5c4591673102a0f24f7deea7e19e27863a27c00b510690b331413df839
+5ae5a37f8c6b25082073bcede7c8ecdbbba2c09467afcebb48f4a4e25cb069c2
+b7acc265f988955a79ba95b3f4d8c6cf94164941723601923409e9d81ba8aeea
+64e8f1f09794779a1262020bc301b1966a789fa2f37d7521db536c0c8da36b7d
+906398a8a41230cda975088fa5a6070d88882dd8dee7af696ef5ba2c5a525d61
+d35a6834907c4846cfc69b17edf77c58e501a0600a04ab4b36d9007ac54ccfb5
+14a47193ed01d4fd5e3c8cf04b3e38c4895de3eee14dfbe6351bbbea6530046f
+89e913d022c0cafe528a33c4e84d465fe6fb031b48d904c5120d452a6c1fdfb9
+08e242a05d015a9ab2536dbadf0ffd0190d355edcd3174cfdda0974e2a33cbfb
+2a3d557ed2f6f284cb3c990c3071b7efc678a5d27518ec1912cbaa890dd6bbc8
+824eb1e7ac6127a67e68428ffd67e650fd44c9ec448a309056ce45e4a4a2b769
+8183ac418981f617dc469a566e713aedce2bbc7cdddf1f7affc6d11e94757130
+c4ec7b55dba7356b21e5267c5ed99f427a19daf476e48993e856c852d35ca1bb
+b32d59ce688ed184fa9ea1622c306cd788d6372c5b4a94b001f198e33209bb59
+46af1ef7b066d049825bb78318a38ca23ec9a93bc4b4b12806c1a0e5be179e3d
+0c0e5bda654e506e74e0ef1a8b12c18bc3f041d5e61a8f03436f146e4daae3b9
+6b8c7ae139f42e8dcf772cb5742104aaf776f3dd19bad920df77b42aac654d32
+2de3779c42639b50059d13b81c3904df76a0ab47046a0132378f9201359f71c8
+12eb4837bcbf3f1498bf8c7b2298e6b2e528f9898ddfaf75b5358a73a67e6307
+707fb13b2360ffdc5659ed8e70ecbab711d89f8c6558622d67737b1108ad5139
+b126a6c7be8b25709fa7cc2a625a0796b7d08b11f098edb80f8aa08a5668ae91
+4ff1c470dbcc7775a73fbd857cdb9a5d0c122d4765caa8d9d35514390c9b339a
+c04a78342e186e5c49dba4cd9ab165b4c139e76b88c807cc4b5db7b5063c2f81
+16721670497a0183c643c5a70ab2405d5d8b6773a4a2d39b3cd0d763c12ec296
+9b3c3ab916656fcca5d715e7dac796937b2b6d4adb251fb79b183e6eab23796a
+0bd0bf5bcab03529467a265781716b0186573b862b2a2057c427d85d7b547c7a
+9e7fdf7a674587df709ffd0a63d0852ea0d02c13e8038762de82362739de9ede
+0db4296421d462d8286e2152aa67298c9ff511e8de1a26089d383bdbbf27066b
+f322738cd2cf198bdefe566ced1808dafc015c8ae972117776594e9c506a3223
+d4ced495d6229c9bec17c47071415f80482f9ecaaeba6a135d2173254dde6be3
+f0ce9a7a81ec2e9af4add855b08309d34e780adf0f7c9029d2ce0d5f807ef0ee
+531217450c82b7f3643456772549acc2ba6a5938c517fd775114ed44ec69a45f
+d9110c969edd9e6f8b4bfb953aed79a1daf47c7238871e4d537100c4d8981d82
+a2344eb7df5baebad28e34870d52d97a66dfc75740cda6b403c1964c0feb034d
+d3e5c8b4a37acb9f5718f7b6a3d267694df8baaabd38154d16c162ebe43b473f
+ec1f060846ee8402d67942ee080dac9b18eb8b09d384ac24f85d287ea3e2c59a
+0f2c1d6bad36e262e031acd399a2b9a7940908d65f142fb209416e891a6abeeb
+389e2df002436d43fa1161b71382d1842788af1a9e6f39ed56e8bf63991fa790
+a52ce312aaede90df1be57e3c1151dd0350ffe7e476cac5f34cf8505bcbd25f3
+29aeed3a52bfe1f10366dfc4a15fe212b1cc9da76c8272d7ce85c2930d797b82
+4a67de55c50d45cb3640db2a79ecb647a2fd2d948114eea9bad6312319f8db5a
+a29d60b22439d45760751904f5de5d8c5c9d0211ac9d30b9459dd05eeea240f0
+97f0c239068c514b8213609014e6bc50633d0ecf774c210aee7c75a5bac24e62
+813181e4d040ad1bd4bd4ec7b99b8a37abd694cb67483d1c5dd5c17f54ea7f20
+50d0ea8ce1cbfa5395e62e10c5d17a423ac76bfba25a38fd474b5b4117ccfccd
+30a2ffa484af429168b1b5679b67542755e989b39387fcd9b1d8f8ba313a758c
+58641f34ccbc8f2556ad1b17c33f601ea76ac75ee6b681aef12c0712a14e7b8e
+a8a5bd316223d5142e8b53a6f81a8a608a3dc32f20c5e417a6aff0f725dd7867
+429fdcdc16a22ef6112fdfc5282c61a1aa9b134c1b420de7b359be8373cf3716
+d7b3ae832ec15e305ff6c8e9d4197f8b0150b30e1b9e7f15275b4b7a65dfc611
+97c0e5f91561f3e6203950edfd6cea20d0649071442b2916ebce5f4d3da73914
+5a2bfe6d055580af134b7dddbb9baf9477454eee8abc7b33eea500102e395212
+78d08c08ae455bc0fc5bf5a0a577e5f5fc71490add5a623ccca134b62c19d3a6
+4019415ecee0168621be2b4856ef3b3944c0db9aef7d3e933a034184934bfd4e
+3fe21d4d2625e6464e9ff9cc25e793eb7b8701d3fa07ff9a3020f76d668d083f
+59c6f6751179d60eb17b9c4e35f3815aa5ed3793a2030d317f1610215fa920a5
+5ff29a67e8e6f186f00b5ce164677eb1961eeee35b5a7891d4296967a9d096bc
+76b0d072eabab7ea758da89fbdc25b8261d9fa08099b6e84494fe034c3edd5f0
+c45e67ffe588b2532efb3dd1c34be9ce299712eac0e4c4cbee6f30e958c9dea0
+15c5c4fef7cd440ea982f91c07928463807fe07f27ef61a5deefa47879847835
+d4e50aa1dd0ad2b3d01069cc7b4741b3f680131f7d5cafc6b3978c3c1d608ac9
+d24342092746628cb71fa01e3c675f14463f9edd4c339ada41ba4b6a0faa5117
+204463bc7b94d01edc1b3d5781898c85516617f29b4dce2d32c2686ddbfdb838
+f67b097be600f6aeefb6eca5f729b45be307232f92731c10c3330672c9584141
+7192e62a0ebae828fadd77bfc2ecdc1e562daf5660354e0edd5b7177bd8e9d24
+f77e526e649044cfd49633d48cea64de714e59438ad980e0b1ffd51ee19692ed
+665e2ff332bb54bdbf75316c4b1a39c538312fd649e8c462994dc8f14bf056ff
+0804de76474d0ee084e363c8b7081b1c08e252e05e49679e6c7ac81f42e9372d
+e5af64f59c4fb62f3e2e7b16ff53bbbc006e3d9b0f29434db5a63210944053da
+ab56b1075a0c3832220752d104fa1770d3acfbc31704a1b7852c077058f616e0
+a4373c1c92c7b60566691573502e9a92d583a3163bf31fc100c92e6405ee4d54
+09d23a83225bf6d1de2c7bead011ad64547d6835ac9a7378033c85592a0c3497
+a03c16190ebdabb792ca0bf803dcbc3bdf0f7a571aae00f596ee01eb476bad97
+3a27a219aafcc0fa245c6731a2e8e561c63b7bc3147b9433a8203fddb7138b0c
+1611c7e62375f2a114f7bfab36cb1a94b9e10ca63833ab245af595217779bc7f
+d12e68a65919eca4fae72f755669580ab0009452bf086ea835f91a0d5b384b40
+82bd515f006865bbee2c50db43b4457a793693806b86f68a2b2419fc3e937a72
+c6f414de148d2a62a71ee9fcab710d6dc08ad6c4ac443365e7a78843f80cd769
+c56efecc2d63487b5fcead1aaaf9481a7361723388f5b51c2d9cea90486cb9f9
+79f6f5ee718d4a49ed91cb091adcbd0e7b3ad963368c9cde877666a742cf5073
+aaf79428b3095f989fc1fa6f5ab1d724d92c33c1325c05a39423b8a83bba9359
+97793fda280740aeb6be3193be5f4feeca2a8f28efa9c8e016f0fc87c8f3392d
+5715b9b9a7aa3c61ac84461e2c3220372568aaed851f1cc40481e326197ecab1
+f3cd792fbeb27a58a5f889a5f6321473148c6d311ca89be96039ac9423700d87
+ab0d7e8b89717d1a62ca14e01f51bd77832bb6dbf76b201a04d222852050cc5c
+c6a4996789a0bfd6ce364592300282f102e66f4ae9e50d60d886cacb099df960
+c42e2213017c567f27326e677bbd04a239631950b566eb39e4f675d2e989f56f
+74da3a0469d988ea0122ecc3670d458ad82bcf7ad04bf3ca9b00d76ee569f98b
+a375285a1abbff253b8f179f71f496286330e364049c72ecad4d82a933af0189
+03de5e4abcfc637803167e56911f826735a7c41e7936f4bea148397bcfb18cda
+fb03182ed7c511aa9de0c6e6c80b24cb535f03ee16bbcb514d65ca9ac2ef15c1
+aa1825759fc4ecafc7c0d9401f139b3f20ee915955268578a933b184a86f2017
+03cbf4db79be18c09c8cb07d85739b8653ad37b8c0b647161e5cac746b3c0b94
+2ae2a0540f38dbee122cad0cf739ef1b49b6dbbd5d08c97c04dca33030f18718
+583337a015395e1fa932df0328c7ddd9546b7812ba06d82a35f8110d55fa377d
+fa6880f52645890d58478e4ee3b72f08b2d7113b2453729b37e4fffad13c5f62
+06b3c767a45c80bd479d1e24df660e46c83c48166fccec13b9cc4e62a6aaa813
+7c424885f83d7647b80849c0a77bed562f134034cda9fd6e8d7dec9e43f0c018
+9287de759676f20005556cedc67c31509a8bf56a5c972b5d247f21d8b6a58953
+7d92101841166d7781d4d80cdc35ca382d8c2dac3ea3a34f93dce0ff8c76ef12
+390d5d57d88f3bc00d46513f0358c43a22c413d9a6ba6b3e13913474b9e53bf5
+31136a5edf9192965aca98e06316c05fd3d6e88fe09cc08e327ed027b81eb146
+63e3073ea5d1d59b74149c5f5242d3cb253c36a84cc837d76b2ba36104aef0d8
+f9f4404d63c42f3d635dc9195ea582b589cb5b54ab01af9ae53f3ec95992c09f
+a5bfe86e6ef6948bc387730a9cff0cdd365650aeaa5e1d52d8f88dd49d36e6f0
+786c7f4ef8c2a5a242e84cfd4dc50adfea0c2ac27839699b92fa8feb6436f2aa
+d02710777083723ca7e481f83b637f19ffb7511de223a0a261324189edb38d88
+6ff5cb1356e8d567afe76f96cb72f88016e39e99af6aad499ac60c8a3205f253
+82c0312e1f2b6ee7b37d178bd4e67550276a7421b4f514fd293ad32bb1121234
+bff93d2297dd32dfdd7e7ba91c0544f79dfea965f4f67494f3ddd97d7881fcfb
+20ed71f6b5cd27b12d04098a9293e273148590fbb65f6fba63e7bcf14dfe6f0b
+51f870be20174f991329a5ef3d3c9fce206799a01ca102ee7999c2a97a19e796
+bb5f88922b76f922d302dd833ec532022b13ec573b375cf75e49718b2278f2b2
+4ce9865f20902d6358440efc9eab6e0e069ac7c193c88a044cf33f6a39388f6a
+296f42c637533cc503adfc71c5f898c408a7e5479868ebd29c9ed02939ffd49a
+2812baa355be429858e0c6aac60817d684778b71fb9a73e7ac4fcb078bb1a75a
+b425ea09ad8585ab3fad79429321a8f96e2e1f02ad70e2fdbeee625bb434b0be
+f8eb957f817c5699c7293e47daa4ead6d47f00fbb6c8674ef1f7729cdb19749a
+ca9cd399a4abcf28ff71edececb2a955ffbe9ebf4bdab56256e7cd66304ed4ab
+1b3fddf6431296aa641a8795a4006a049fd3b35074a865c901636b70619ec26d
+aaaa8c8c9060938337144209f3e3de01e92293ca89583cbb4c2edec074bb4c05
+15130c3ebfd78dc687f0ad0981c0d27fcaeb28f470193ca13d98277dbfcfbf38
+f8353dbd04380abef7176b0b4199d7319ebfd88ece219ba6edec59fd158987e8
+9adc035b8fb2141be0e0f25d56e077e5992e4f95640abca7aeac3d929be02d40
+9a86dbcc043637c5e0f1a5a12579e57b042b386be96c9a8b3c4e79c8dd28a52b
+a1159728785a75f2e579b8669a36a9f9e7807ff9d5aa0d8652609a47264a2003
+fd202bc8fe9cf80e2ef05ea5e5fbae676a77bbdc4308ab92eb0dd9a960f4865b
+8305eef47abc2353287f52c766ea1c1b86fdacf0986e56a87462ac820e61051e
+7f22cd8ea7dcc7838a45a08ea3fec105d80fe5ee5e87732bfc2e9d664a7ab43b
+05321557d69ceed6b679797a67a0c38b9d101bbe870d746568325c52d4ca255b
+b23f9672ce2b4e3fe944f5dbc388e575abd897d969ac2a81915e3fec3d7409ed
+14de1e4cf7737b6e46f6c71142db06a799a7208539c649244ce73a58f2247e81
+4f241aba74d6ae593d47c227137ccddcf1f523a730a234c91ac3ae8a456cad1e
+91a9480c438b047be40bb2e4038f8ebc34ecc3a8037454b7342c317871fc1d97
+42f26e3d956da7679a072cab96b27fb2ddf480d2f40ed88b2e5b0b82892c8314
+cec9bdc12433159714891b8591a051cf2cce7580af74d5096f53a65347488bcb
+948fb028f310575d3429123ebecd9b09d83f30ab8c8ab65d49d691fac27e3612
+66ea08634f4c7d3a648ec068c2cf31f116951934864dca2755daacb6d22803f0
+9488117ef66e9b12663da9d00a3eb0280ba412e4b6f6397ee7800f250fbfa023
+3162addcca4dc23190a52397cda3285291842a2b269c4e07f17a0035fcbe785b
+6a570e4b75692658ed47b6dbf297adf1b3b164740d1e851f08deca9c05a263a8
+3364c544cece706e77a32f6d5d10f8d4170d5246d92c2c9fae457e0f5e4ecd4d
+08b4edfd42a1791cca41078d5e520807817206193d8a649eb39b64c80e126feb
+240e1784da3c66378196828104c49e5fb86475a80c21de71e0aa36ac5e529ade
+427c03c2236db0deca99c7c486ff463a72723efb519263916e73c25da625d0fb
+e45258ad2abf3445b72cbf3e7e64d507198f666edec002e233cc0af6a8c1095c
+3cd232e2ec50b2ede3e09b61e25996b4a64c0eec9d55025b1f47e53e0b128bef
+a34646b4e2c13699d112c958590058e6b606cbd978cbb0ef69eee350bbf71ff1
+8213a42d135e77e2c53a8121aa3dd1e903dc0e961810d103bd70a2b448f29ec5
+c3d907d7243d76c6ae04c22a8fbc6c1a05f9b9ec97cbb0e76928f4aa26c913e0
+3f8c371efb61f370751eea6af25a3df4ab3da3e4aa263c2477343e4b19915219
+c4c52cf43dbf373c316b80619f479d9b531e62f26ef9fc6da13e9cf0bce74d13
+c2832f1c9d9432437d253dccf73cd699342521a3cfe8f85ccdcd23e9b240c961
+fce15ef77fad8438674b55da638df2492b29fc1a003859f382a776260ae5067f
+93dd176181c10c4a45e8f237c5c9781e01d2e1e0890e1a6e75e2bbfda4d29613
+efdcdfb21317d770fa6c1ac3800f328bdb82b48b7320ddcf64add23374971af1
+50470fd002c01ef412c5bb4984737840da5c9e0e4d4b2b7747056a3865af6db4
+f4b9cd84d27dd2e45aa0d9f32d0cf58a5f1baa374359223cfdd07c18017660a2
+9227404eef0abbd0e29bd8698752e85448a5c3cf596dc805a87ff903ff890e48
+b7971764fcd8f921eefcc55b2d20cd5908a6fa35d56bea96a39ab521d985c50c
+4e0213b30325d295a00d32d97e95646867122dbef37a3c866fd72e2f29ed8758
+a362a4f17875cba8be23d04a35714d4c27c4417039fc8bcd25365c8a4bb41815
+ce1f74949d6b6aa58fef0c4cbb8d54ce92d65d0a65f13ac6063de4a55ba5561d
+509f2fec155b2181a169ecf14f1fab587569f260c0cacded8021ed8d7cae5ad1
+332f1061e166686b41277495597c16e728d6a8ff49f824df503a63322b442182
+665a12900dd48d1361342575fdd5c9d9ddd7bc73a937b2ac6257255414029a65
+9001199e9e1f16cf3cf876bee000302935493ae997e3f112420d7d3f06739b79
+eddc1bf7ecfc5316549d2ff228a4e28b522d6cfaae3148bea2755a45bc27dfc5
+128a9a38777cd3b07f91edacedba2565b55218d7891da863243cf68e7800b82f
+0341740a1f5dc6dcf0125cda844867fe4945326f13a954430753a28ea8491bdd
+c545e71e4d52cabc3f05dce434101d36a62328c5fe6b5df3864f9f5aec22f399
+43f72fed081d3724306477a06eb9b6fcc9faeb77e62ee4e20cc51600b1bb081a
+1c5a00e064d5755838b251807ae57c85675cf04b69a66bef0c19c364969d3547
+55efcf31f8ae346582462e986e3a1d653c205e5d58d21de4553832c885e543bd
+11eea2d3c08f883000966c99281251fbc2920917700037278d4934f3441dd535
+bdd3c52111ed0b282ca23cfa97ab25c8726acb13d50599245e532432572c35ac
+b9391685d9e1deed1f95fcb151594cd63e79691b5972ba2c3a0c0a2ffaf3c9fa
+5ac47d9177a691742e4634db6631c8696d0a30bce1d86a4fb737ab85296ea479
+fe90c51cce54d64087bfc80ae56abb5d04f5516bffb681e6b39f480767f2120e
+97d1e8488f1f540e2ebf63eb74596670f5892f4c327971f697c7530778c3676f
+2792289cb12486935c447d4eaf4afec65fe6c6962306449e33fb19fb9806f87a
+8b91874ddf3e3138481fdc711f0954d73f11fba39efdeb55ed13b16b932525e9
+9f3c86ae60f9096efd4968759def8d629ff2838decbe4c68833ba0d64d1d3330
+b84cfe8ceb23f4b5d55aa5a9b51ee595aee0cd668b20c687d77ff83c803ab994
+c743b43d9882837c42a58cf704490fddcb5646d48cfd2e30464d710c1440513f
+4417dfd66d39e0fa6c596e17d07964ebf2caecd0a9fd78e003541ba53468e719
+b7dac2685ccb9b7d857aff1d4432a72f61829010924781f5d15ffcf8d504e361
+6f86c6638469db4ad281d8ec365848b6f7ae1047114a2cd3cf3d1e46e0b4f40e
+1a8d3e1df1c1b677702d7fbd5a5924f91c726de2e37b436250eb71610dd82cd5
+5c049fd044b4407784fd83387eb6a788103430fab4f682294b287dac43f3061e
+d99c74309ae973bb998bbb2a691402843a1a28ee62ae8e8baf4d645d156b94ab
+34680095425ad8b4dc27289e3c6818d6032f91535459d7595b2b9bfc2f44e782
+30f0af49c0a2223e1cee9e1289f682ed5e8ea7db99663a234719667bcffa8077
+e0118b0b9702538421dfada01d97d7a8f232464b9fc209cf278bd5fef80c14be
+011a9f6fc78dd20ab012a30780db2507f4d5e1e493f30814ab1c70cda75ce959
+b5d515b2ee8640dd4bcda6710703a9e5670abadae856b86ef8e4143a5f03fc16
+a6c57ac7c3a96c50e45191b0b1c4f6acd622c400cd0f2ae9e9d51236f1b945d3
+71adc5feab8aa8422a28755b63978aaff787158a68c26fd29ab6e849b076b852
+2190caef1a86663f4e12cdf25ba7bf882ef2e0e21c77c14fdf940792d7bb28f8
+892a9ca0bbabe1c70c152f30f366bc86b5bb1eb3b54425617682a5463238c999
+aba3a7bf788a297d2a555dbb218b19ce501aac43d94a0bb6ae290628821efb0c
+84ceecb30c140917a458db6fd011f3cbfb4a1cb5ea019db628c106e2a55f1c13
+448edd4a9a159ebb369d509da296da724f729fc7560c00c41f4309e32ea6fb71
+16f62325a5af317f106a8d8c2c01ecce6775d45fdbefdf6925e9a44604dda13b
+27cc9a960a21eea2af9bdf6b3cd357d6097ad40df7403005746a30833e814eac
+8db72c383fa42ba9fd007a263ce3b74c1356bd522d2611e4e960c9ff5204d46f
+ee332f9f134e75c791a6d20923ece8d4dfedcf96ab45dfd751739dbd47b4863a
+f0fda172848cd279afd9fac3cc5744c1fa8a5fb4955c6c1c952f56da06430aee
+084507664f93c71d881b63041cdec58306100a0e8c77421d75679ce33e2a0a63
+ac2f813006cea69e00352ffd5f5914b63dbad5905a590ce0903ed9b9679779e2
+d9da62f478768776a173832a8f3cd66b6b62484d190baf2d834241000b0eec79
+f1e53b42a74b159bf781ee4415ab6acff86c5b0593cf463bf95d8fa82293a548
+84bb226f40f24591e5ad463ae4b672905e7a4222edf976e8ad889e71986b3818
+bd3eeb6a0c96787c6fdf3a4faed94f0ba0269fd082ac451531e3b0c01f996090
+3f821dcd64642868f07aa0feada34088a85e6644ef07f4402b4b293073e9d308
+bb298b0e44be36bdda218259b4f48f1b638f5007d3aa8ece802b485e7e9075d2
+6ec881fbdecb3cf58c8a3afe0d9835e7b468c648e52b2eddb81dcba4e9678bf4
+b173541dbec382423e80877ba2df94a605bbc2cdca2b76f74d2eb425d8191958
+804617f21172f397bb762aa7dfd0485cd020397a5d3e9fc9405ec7edccbcbdf4
+295a0057b7684a701bb7ea01e8978fb3367ecd089be19aab2828f6825d275d3f
+60662c1e2ec5e98ecb99a96d6fe379e2fd158a7106b2190902f0ed71969b6daf
+3f9e460f16f1b40cc2aa08330b9fc2e24802bed034b71de445a14bb33f642989
+4f76319eddee328319ee9577740fc803b81714a99bf0a5722981427ba0858546
+c0f77f3919070060704c3bd991d94909d2012146b88c0d35fba7c2de864e35b7
+caf0099c4630443625be3769b01526f3f0c8c821da9d546bc258c004a4d2b46b
+886f1ef916f50d3f5fd139e0570b4151dd41f1f1b5dab0db7787105c77b86901
+73c562d3eef6ef741078659467f333450d7d80c67c91a26ba8c77adcee6f4c56
+c7f248dd92520db35768e703f7bd171f9e663b9daebeb9611cf48425b6b35c1e
+8bc7a0b45441ad3854ac9b37061839f578256a8e41766d1a6b29a99a0195620f
+a090d0ef4120667902b0587946206f294b78775d60ebec668f6e4fb9ca897e85
+76151b245aff8232a90f97a5a93e935c88579dc0f2e9da7cbd02426b3b15ed50
+30acf50107f7b4d4e2c32dd75d6d8c4539176a2244e761ebf1ffbf97d336fdd6
+ef9cf138326e10bdb57638235348eef8ffd33c84b426ec1c81fd8d4a3907d52d
+1ba7e9b64dd56b8fbc2362e30f2451b69b0d7cbea1f3101afcd44242d3ff5b66
+89a7c05449b281035e983c6b8c68859734b232a73996a19d116ac4a94f7b482e
+1f984371e7e9919c312250c35f6f7fee25ec23e562dcc25cb29ea79dff0e7c8c
+fa19280288c26dd5c32f4aeb98c85afda533191809267f0555498da5688b7c20
+219a058efaa597125535871922ff9b20cfbf4c4b35bdfa4bde73ca8ce6abf14c
+510ed2072a01c8adfada0064777509d4f97bd2baf66e7151ade76e407066efdd
+2e08a15790c81d545b340019bd350c7b90b36adc8658c1848020a77f918e1527
+b3974710af503a79d7947dce93bd81161cd7e0b1125d2fe0edaeb91baf1279e7
+312fbed646472b352310fdfbefdcc4c20ccfed0d6626083b0261d7c47d966984
+8dca4298b9ddb58fe21bb391c7d45d9b562d38c4dc23acb5aa87e3ddf59ee238
+c91318db2491a24110af90539a16940141d1efdf4a13d202f9b9401bc89d7297
+5269cd5515f9a6186a6ef866cfa03730f726d7a4075e0bc6f094e9584a84cf1e
+78489bb68dc09ee3f1356f4e45b8621e06078a6727eb72c36fca805213c1675d
+4365255d90164f33ce6b2231113f64fdcf5a789cd61002b2a38d2ca5bf1f5361
+c9ae0f4efb51337e344fb7ce15f8edbdc9ec82a9435175f59b6c19ae2dd0b10a
+944565e4b14bd1dcda02d42be27fb9f0330636091228e3b89709c8148932a5f8
+c5ba5bfecfef6de83eb414adc613d8534c4e4528d934c37e768d08e103b8ed2a
+e1e49bb1b3e6cbcdc3ff63dac7994b8c09203d82a99710449277c20a34e01538
+67c5d5e6abebba650c441d3fe56de997e928193682e5f1faa93a5bc800862132
+ed3b6c005cc0e604231e3e61d17214ca38148c875c268a861a14b54e659dd932
+cbe6ea7109b273975d6ceed351f0b0876a0b647946d29097dd98b5f6bda7b43a
+e6481f17743fda503b34a120c8c06f4798c1fcd4e521a30d76f2340df562b63d
+dd4b27da8b583547d285f3848bb9fddb60d0ed22a4cb27a2784e8d7662e84ffa
+eea50afc03b0815b72bbe9558c8959d0ccc00a8c8c9f740f95b671a66dfdfc68
+77fac12c1995d977495c9ccacd924e45a66f8739de156ee6962c7930f8aac374
+894f8bc396ff69f2249392c7c4248f9cf9ffff9eaf635e66a34511f39a066b88
+4866e776b8d6eca0319f23ca604ead742bb6f6f3b046454a1c0fc242551112b5
+c745e9b8f12723867b2b895c0f93c99df1d542b86c1c9db47390f2d6c3b57ecc
+66b1a6ab514a47fd9aa6240b46c54a92fdf80fc44eeed4b8a136fb88b1fa5b9c
+a2fe682cca4d0c5a3e994cfebdc270f48e3af91ae6bc9172bd9c73053a761364
+6ef9e68ef58c718a478e7d81e57f34a791c26269819c78574d7cc12632684219
+a1f8e1c5ce8b358d6fbf23984e59d9533ad310d158ab5baa9feda08717a7f5e0
+57684c455a7e3d833f82b4e13e9a92b0b8fba5cdd72a7e46709074ddc82e449a
+c906474441066fdd9cb7f341f3a2ee9f2fbf5e4e1a350a45fcad6b2e05825b6c
+89077d742619cf1f8434a3b5cc44998176667cfd5c5f4ee51326d1ee3e449915
+00bdaf57c88a107ac49c14cebf18d010c5b3206ec88fd06e3c5114581ee5a5e8
+c4ee5a5c3d48653fb23d28f26862c433ed083af01ed3df8e147548f9cdd882f8
+ca3088106b9c73b9e28786ffa643c343a940bf850f312666e635b8db95c6f70b
+83d645fd947f6df322d26f8f9081cae71ba8b9d0de67d535b61146c956801d6b
+ff9a69365bda9bc97d8d93142d4c367d5255587ada25e4fb061f8e430f73d2a9
+7142d9e4c17435b78805946e4fde624ea5d9b5c511c9afe2cfaf447cf08235b8
+575ddab8af93588e0c8206f08f883170ed4463da31a53cef67f01aab8f645acc
+c2c764f24bf831dcf005833ccd1296025368b3d51a04efd095fd1355e93de563
+e71dd047ef49f5bf8c17b01b2884872257d743ac6fdd8f54e27a241d7c75b387
+a8841d8cede676e35d4f01acba2acebd8b22113bfbef80d5eab1e8cf56f649a4
+516ec097872a597e83519fc1397c7d4a4f6db7daf044835b17d085578f5a3776
+fd5ed9235c018354e801fac338aa7ee581e97d91df0196ea4bcb09f0e6f2e2bf
+b5470827f1b6bb0b7133c19bf43bbe824ebdaf9526ab15ff8ae8848bf0decb3f
+cfa7d3f5ed71191894c705a27cd9aa30fd384ce6a5f0bc51c5651dd2510a3481
+d086aa87595f885c4c0afcb02b1837cedf85c5e64d440e36581874a117043b75
+78da94a069cf2bd57ae70c230e8d1a0d4637223d14a9868835d8923feb404323
+43c22d0f0e8201c20247c78abf9267915069d6471862c2a0c51ee3ce3153e305
+4a4ec6ea52dcb55df358d1a0d8aafa79fe08ebe4d22e9ecb9d2e50a7f367cded
+7169f84285c482fc1effbde6feea424ecdda2494127c7b896dd05f5e62f5fd1c
+031de960d6ec59954e8405081601df741edd97f227fd426e0998ca7b9b498beb
+4cda9a16715cb699c46d1386469958079ddf5ff174d70338206208f0b9ade386
+03e8dcf31e09f44976c1ad762896a615d9bfe54978b7c3914458c8af4d33dc62
+9f9af5171df3b9e548b24011ec5f02e31dc379582e16f3c999f047b82e7f27f0
+4bfdd827c9a1d19e4230695d4ec499afdb6147146cb6f5a8a26efbd6d0c5f205
+34cb9c37fa4c4b6122f55bacb756173282abd6a2e5219c25b86a5181021f0bac
+6f17f89f3b8f74c281aeea7c1d4ffac602c2364c9e1ec8b0a623bd3541765cf7
+aa5febbb6e857810a564850259ac4ce6d641f7b765dd46584c43c8113c8583f9
+e7763d3f4f83649e12e15557f48dcb0a637140b2f7479f78f1f64bcf8a07acc0
+43b9d9ac1f8b2c3b00c36b46d8e514c998fcd47354b364e8c2434e774ac7098b
+24c3bfadbaab5bdb8ab0a6b9773aea4175615241249a2a58222df8c53c32d01d
+6adc5fb4a933605fff98c7d011266380b305403a79867936156240a5c555105b
+95cec3873530fa6d37e8cfc286118a9618c60d6282412d0ccc5a8e3af47a42ec
+29cee0176d1c4802144619a5bf1cdf9ec5b8d6f87c379c476ab941da24420a86
+04a0b1ad7884b5e05136139afccf0b7101cae4b8f0bfdbe276aad1b95e2c0d57
+3902bfdee651a202b99189cada176a22facd053bbc73af1c90cbda10635798e9
+8de05c338e90b3dc4afb8d29010590b641db4a9ab707294e55e44c97e275b52f
+b88f52a6c7e545cdc73de46da699c8c3d895880368aa035a137fa8686ef4f64e
+09167b9e523312b175a166de5e1297c60db361d9505c12b48c1780a00be2a9a1
+43bc6362c731eb26a61097c62c28d2cc8d75ba3c63e31a49b9cb5b8b7fe1fbbb
+6153bc87b4538ef5cd4919811329ae933d86ef556883323ed5a6db5c98c11b2c
+cc04c4f937289590e5f7ee8d57940f21373a81b8b92eb7ca978c1a07af7b1065
+3e6498a6e2fa734269d61cf0dedd647eddbbe395e1e8190552f9a4332082bee0
+87f28fd6bb19e48de8ad662f41b4a5de657511f2329fe6b541f50ec43be24d5e
+e7336712535ece6a590426e10422d130f4fd8b0fe314c9fe068c6a45835994ae
+7bfda8ae49fab23905e4d8b374fc654f336b36b2080df61abc288b26b9ca7b42
+68e46f120b82cdcb74715e6d09aac096fd117ace3383beaca52aa248cfe307ca
+8930a34b7062fb153d968c93169dd223449ca68765480cfdc5df39be45055d37
+8ba14daa5a4745a9f7b76ab664ef3d5b2fba29c60a06d1a088c05eec6d95c080
+1974ec344b24dfd892db7874e3e9df0fd61ef8f59b525f92f2b374999f923f34
+668e55cc90ff2890107a7528853f44177fa52a071f0ce997ae94b590289411e4
+c0669c936d4b885de8427b60b2f8820bc9d6781bf275a95921d8cf4f55cc8cc7
+73ff7d001f4fc5c41ea1c755ee48c5550677755aee061a3ac85bc0d9c1e5b410
+f38ddb877fef4ad4142c87c42b6fead87f1daa99ee0fbe7e7eee948672373a3f
+7ace2444607921c61cefa7360f3194685acf836165e19395c2b2c9cb5778d9a2
+6f35f91d61e5e4838aa23909b46a899a1e02e27ebfb5368f1080272f6ae9adc5
+44f512191bf17dba3eb22d98b9b934f359fc86c9e451d2d4194632a7db5b1270
+6a58cea47392fa8cc24f6b4ec5d172e9e5601617d8e22e837c0b35b4281364e5
+81757e2fccb98fa88879d7ccc568fa9b183504b491329320c968b5611eb1f337
+a6e50d6faac591da994aa47761865ab84651c328bf259be59bd752f110f89081
+7553823cc67e36721e95f1c4e2e372e020f2b2ffb045aa70ca4dd6d55d88e32d
+c8a17492ef28a44d4a536fca8bd75b3dc392fc296377b2c4743897c32eb65283
+e776e8f8fd97c661c67c3f0d97343af141bf6b77499a13af4605e36d3f4c3fab
+12bc5daa5db1d12dfe5915acf14409e9302b1bbc8c5861948eae329ea31132df
+8494560e564bc16073c7a777fefb30cac6f4b8943c70195289946a60f06d4306
+4536c2740995b7247451c9e1619f7e277af4bcbfff6b68553ae23eef7b179c16
+cab6aae7b6f5fc72e0d7cac34611d1353716580948ba69dc534a3fa592984244
+c1bbd0a6d3f1fc4d9c8ff48e770f5c65be3b5a961e2ab8931e73c8222e6eb481
+86e92906bf2b44fef5a59b460bc88ad1837730515d82c337c349cd087329ffff
+0718e22bd3f09fede7042992a191575008890c5966f1230ab186f019f1794671
+8e619ce8706fd94bf0fb1d6ec22513150c1b9496742a94e048df079bde5d7bf3
+9db82668e5f5453962990f4e3e0245cd2e767c5cf3754c1371bb37bb7e14db75
+a90fcd5de1a7d75748289177ebe65a397762b5b1dbd468e7cbb3fec66a6b3f2e
+8e9a1802bb2cc4506b3ad1632d674f1d54a0c1c08787f274b48d60e9111d8035
+be3af44a3a12e16175ebbafdee5cfce2a9a26cb9826c86207f8ea895e5c2fd66
+216be83f81fa47f39dbaff3789865b1bef63bae463b7d166dfba5e3e9967697d
+f6c91c7dbb765bdb91f4ee5920567a94199416484e75cb6b1c0d1bdd62e831f2
+4b6d7b1009bea14c78ca6b8f1020cb05c9bfd13076d5f335d0b8ae417fa26c75
+d04a28a778d8858e64736fa0a5ba789b58b4d05540ecdf28ee044ea18704076f
+c3c92090d119bc67594021aaa4e89a063ac0e64f2198c5cdb3951c7681ababbf
+6e96666f467a0fdc729efcd2f1d94e193d8fd56802063840696f3eca394c2841
+6b7e6bd4759aaceebdf82bb473d49256e653943469db71794ae96b3d130bf97d
+752a9b3bc4449bb756039609a4f9fcc63c637d8672f2f24dbd49a5f9f5139c54
+23c4a1cba345784f28b7933dd3d2c9938b35e63678b045ec314fd9e9188f1b18
+ca034a26f5d7e2e779cfe4d16560ed2e4f3ac2bf1b5324c6b342e29b5ba3c9e0
+7bf1bff519f91bd9cbd4c198f0b98431d83d7309d0a4b62bcd450d62649e5b41
+335d87c297d288942a637999c2dbdaaaeda4f68d166265a37df001b1a4a5f561
+64a9a7af810851d98af3e01b0e4bbcdf33d3035b98118b48c6452da0caecca10
+228a308a0a3844d57628b2dfd7189f1fd252ea1ce3cbbab7e71329b886cc36ef
+b40f642aa54698e87f4ce8b310f0ee29968ae04de003fbaff84d866e4220b607
+3b3c5fdfef88354a54d4318dd852ffeb9be81630c673e425fd3bb6ddec9f298f
+a9982f8a5859b983bcc09b989f4a71ee4a54d38a220c3ce7491e7d996d8b0e11
+b085acb8f217be35f3eb7fa08bd8ea8c66df8ad00e329ae732ce12801aa8b1a9
+40db1a7b303967c185b90229a1188eeda3a1565dad1c08181fb35ba03667d513
+9f2b6a71dd27e11c7db9a7eced6404cb09250fa0ae2f0fe7fa61147039cb8685
+e7a1566e25b40b1f23ffda5515c107e3487ede0a148f2d8500f102b4f517c956
+87b2e0399387f4a9067ecc725bcb327ba5e98d5c68fb54ac99834146bbd7e91c
+b04d9576bb16e39608c14c25aae446d250b388610b2714757631c18feb700057
+c0022456c9ea28140a150dc6fea0333ecf9c291d95505de3c053c1f957f76a06
+a5e96f792200eb5f1811e86d70c9bf1e0d28da28b8c6042555a27ddd0aa168b0
+0f3c113217d990f6ead0a6ecc4ff4c92c577121d2b1dcbff547c03184360a6b6
+3788919d20302f0c35541b48cb6e926be087b1f7308041dc8cb8f161d8a8bd32
+ecc861efd6ebe16568dd47b82fd1a02200733fef4176a7477185d79e44c128fd
+c54f4f28cee76dcded7399bcfebbfa620a6f5e4df5350fe6005f84541a6e77cd
+97ddcf704455f96435edb3666d9cb57521f35e258eeb2163944c90cbdb3d4a70
+c94b9d3905fff429f16560c6bc44aa27bb481e24d03f29f135eef38d973d12e9
+c251de1d9b976d4d7bb7b4f62dc7a6093d186d240db797432dfb5e71f8fa09d1
+b9b6cbde7b4674bb3f38967091b8b375c0e7dfddc0a206b0d8908707521254a3
+35be48528674c8597822a0a9e9ca84f0b3d2a44ec9deca0db51fa2ef3db16851
+7939ebef52b5af799ff6fe86b0cc459be94187af479e95651233f2515e01ccc9
+57130b01e6e97df375396f8499535a1fcc0dae920db25db41477263a847b578e
+8ac94e59fcb69b97a1ebf8d84e2fab6925bd16077d5a58403539acb40adbb89a
+55623d7e09a8481e71b47416751f01881ece4d94ea9cff6dabb3546ff2cde4cf
+1ba77ecadcd4499637e26c5064a342d71cf50d725c40286ad352bf97e0da521d
+58055ff97c68768b4435db372f0b3d23845d7709ac47b2a965327f62573a8fe9
+e9c5c435ddf12478bcdfde41c0e4303b03949446ec9291c553eebd9add6bfb9a
+45165ce3820af4264dd3b54ac41e4b2df6ede1286973660e37281c7540beb69d
+16a86ae03b8c5ce7ac142585f72a0cba8cfa3c71a54db60d1305790ffbaeee1f
+f31774926a1da96a37574c9a5b66daad0a68adf9f104123941ac4d3342c13bac
+b9b124ec9db917032e3f495107f3cab93d57751e88a5369e27358ecf4f9348ea
+543fb55c0492862ce28cfb1f28e0e5ffaa32df8fdca241db555619583fad76d5
+04ef599f233c424359768f6e8f0cea95774901577277dfd8f90418598e
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+cleartomark
+%%EndResource
+/F134_0 /MFECUR+NimbusMonL-Regu 1 1
+[ /.notdef/dotaccent/fi/fl/fraction/hungarumlaut/Lslash/lslash
+ /ogonek/ring/.notdef/breve/minus/.notdef/Zcaron/zcaron
+ /caron/dotlessi/dotlessj/ff/ffi/ffl/notequal/infinity
+ /lessequal/greaterequal/partialdiff/summation/product/pi/grave/quotesingle
+ /space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright
+ /parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
+ /zero/one/two/three/four/five/six/seven
+ /eight/nine/colon/semicolon/less/equal/greater/question
+ /at/A/B/C/D/E/F/G
+ /H/I/J/K/L/M/N/O
+ /P/Q/R/S/T/U/V/W
+ /X/Y/Z/bracketleft/backslash/bracketright/asciicircum/underscore
+ /quoteleft/a/b/c/d/e/f/g
+ /h/i/j/k/l/m/n/o
+ /p/q/r/s/t/u/v/w
+ /x/y/z/braceleft/bar/braceright/asciitilde/.notdef
+ /Euro/integral/quotesinglbase/florin/quotedblbase/ellipsis/dagger/daggerdbl
+ /circumflex/perthousand/Scaron/guilsinglleft/OE/Omega/radical/approxequal
+ /.notdef/.notdef/.notdef/quotedblleft/quotedblright/bullet/endash/emdash
+ /tilde/trademark/scaron/guilsinglright/oe/Delta/lozenge/Ydieresis
+ /.notdef/exclamdown/cent/sterling/currency/yen/brokenbar/section
+ /dieresis/copyright/ordfeminine/guillemotleft/logicalnot/hyphen/registered/macron
+ /degree/plusminus/twosuperior/threesuperior/acute/mu/paragraph/periodcentered
+ /cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown
+ /Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
+ /Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis
+ /Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply
+ /Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
+ /agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
+ /egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
+ /eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide
+ /oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]
+pdfMakeFont
+%%BeginResource: font ZOVMRD+CMMI10
+%!PS-AdobeFont-1.1: CMMI10 1.100
+%%CreationDate: 1996 Jul 23 07:53:57
+% Copyright (C) 1997 American Mathematical Society. All Rights Reserved.
+11 dict begin
+/FontInfo 7 dict dup begin
+/version (1.100) readonly def
+/Notice (Copyright (C) 1997 American Mathematical Society. All Rights Reserved) readonly def
+/FullName (CMMI10) readonly def
+/FamilyName (Computer Modern) readonly def
+/Weight (Medium) readonly def
+/ItalicAngle -14.04 def
+/isFixedPitch false def
+end readonly def
+/FontName /ZOVMRD+CMMI10 def
+/PaintType 0 def
+/FontType 1 def
+/FontMatrix [0.001 0 0 0.001 0 0] readonly def
+/Encoding 256 array
+0 1 255 {1 index exch /.notdef put} for
+dup 45 /arrowhookright put
+dup 58 /period put
+readonly def
+/FontBBox{-32 -250 1048 750}readonly def
+currentdict end
+currentfile eexec
+d9d66f633b846a97b686a97e45a3d0aa0529731c99a784ccbe85b4993b2eebde
+3b12d472b7cf54651ef21185116a69ab1096ed4bad2f646635e019b6417cc77b
+532f85d811c70d1429a19a5307ef63eb5c5e02c89fc6c20f6d9d89e7d91fe470
+b72befda23f5df76be05af4ce93137a219ed8a04a9d7d6fdf37e6b7fcde0d90b
+986423e5960a5d9fbb4c956556e8df90cbfaec476fa36fd9a5c8175c9af513fe
+d919c2ddd26bdc0d99398b9f4d03d5993dfc0930297866e1cd0a319b6b1fd958
+9e394a533a081c36d456a09920001a3d2199583eb9b84b4dee08e3d12939e321
+990cd249827d9648574955f61baaa11263a91b6c3d47a5190165b0c25abf6d3e
+6ec187e4b05182126bb0d0323d943170b795255260f9fd25f2248d04f45dfbfb
+def7ff8b19bfef637b210018ae02572b389b3f76282beb29cc301905d388c721
+59616893e774413f48de0b408bc66dce3fe17cb9f84d205839d58014d6a88823
+d9320ae93af96d97a02c4d5a2bb2b8c7925c4578003959c46e3ce1a2f0eac4bf
+8b9b325e46435bde60bc54d72bc8acb5c0a34413ac87045dc7b84646a324b808
+6fd8e34217213e131c3b1510415ce45420688ed9c1d27890ec68bd7c1235faf9
+1dab3a369dd2fc3be5cf9655c7b7eda7361d7e05e5831b6b8e2eec542a7b38ee
+03be4bac6079d038acb3c7c916279764547c2d51976baba94ba9866d79f13909
+95aa39b0f03103a07cbdf441b8c5669f729020af284b7ff52a29c6255fcaacf1
+74109050fba2602e72593fbcbfc26e726ee4aef97b7632bc4f5f353b5c67fed2
+3ea752a4a57b8f7feff1d7341d895f0a3a0be1d8e3391970457a967eff84f6d8
+47750b1145b8cc5bd96ee7aa99ddc9e06939e383bda41175233d58ad263ebf19
+afc0e2f840512d321166547b306c592b8a01e1fa2564b9a26dac14256414e4c8
+42616728d918c74d13c349f4186ec7b9708b86467425a6fdb3a396562f7ee4d8
+40b43621744cf8a23a6e532649b66c2a0002dd04f8f39618e4f572819dd34837
+b5a08e643fdca1505af6a1fa3ddfd1fa758013caed8acddbbb334d664dff5b53
+95601766777978d01677b8d19e1b10a078432d2884bb42d1f224976325883657
+05acb022d1e9cb556e37af91917c78e98229e3a4dbf03ae741998542977ad6df
+1760fc1f1a479464922afda2cba7961e9da696b71205e19c542c97f25419c43c
+fa1a042ba0cf5622ffbd3e775d0d564135d99b9ffba011eebc4066b003ce2f88
+825936d7393d05d3804601cee9d123120fdf73624a9d4e361a28e998acec53f8
+7a62a0aee33be2e96542534a8af24497d1c377cd7f723767b44857d94c6cda7a
+c3d6f0087fa36655dd2b81eaecb31fe4f4a2fb1ea9fbe8b83d35826ac93fbb4f
+2bee014f41f8f276510cf5ce35c3954e8cafc521d0c3ab80ea8c7fc29427a1d4
+42d6f6c1800919e58de9ae12304d718ad80febbb412da54153469cd51a288628
+ad109baa77981525b3d9b0efe593537fcbb8520d38cccbd5db171a0385a432c1
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+cleartomark
+%%EndResource
+/F147_0 /ZOVMRD+CMMI10 1 1
+[ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/arrowhookright/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/period/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef]
+pdfMakeFont
+%%BeginResource: font ERVBFT+NimbusMonL-Bold
+%!PS-AdobeFont-1.0: NimbusMonL-Bold 1.05
+%%CreationDate: Wed Dec 22 1999
+% Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development
+% (URW)++,Copyright 1999 by (URW)++ Design & Development
+% See the file COPYING (GNU General Public License) for license conditions.
+% As a special exception, permission is granted to include this font
+% program in a Postscript or PDF file that consists of a document that
+% contains text to be displayed or printed using this font, regardless
+% of the conditions or license applying to the document itself.
+12 dict begin
+/FontInfo 10 dict dup begin
+/version (1.05) readonly def
+/Notice ((URW)++,Copyright 1999 by (URW)++ Design & Development. See the file COPYING (GNU General Public License) for license conditions. As a special exception, permission is granted to include this font program in a Postscript or PDF file that consists of a document that contains text to be displayed or printed using this font, regardless of the conditions or license applying to the document itself.) readonly def
+/Copyright (Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development) readonly def
+/FullName (Nimbus Mono L Bold) readonly def
+/FamilyName (Nimbus Mono L) readonly def
+/Weight (Bold) readonly def
+/ItalicAngle 0.0 def
+/isFixedPitch false def
+/UnderlinePosition -100 def
+/UnderlineThickness 50 def
+end readonly def
+/FontName /ERVBFT+NimbusMonL-Bold def
+/PaintType 0 def
+/WMode 0 def
+/FontBBox {-43 -278 681 871} readonly def
+/FontType 1 def
+/FontMatrix [0.001 0.0 0.0 0.001 0.0 0.0] readonly def
+/Encoding StandardEncoding def
+currentdict end
+currentfile eexec
+d9d66f633b846a989b9974b0179fc6cc445bc2c03103c68570a7b354a4a280ae
+6fbf7f9888e039ab60fcaf852eb4ce3afeb979d5ea70fde44a2ae5c8c0166c27
+bf9665eea11c7d2329c1a211dd26bb372be5822f5ea70d99eb578c7befd44cdf
+045a363056e5e1cc51525ea6fc061dcebb337208eff729802376a2801424f670
+0e7e6397b28f15bc10b40012b0a3eaeb2693e8f7f627c4c9c7c6c5bff105c1e4
+1b2b9e8f09253b76040d268b80719e1b3f5a55ab7b892ad5e69acacc6c1640eb
+3067bfc64938f41636db8831883bddabc6777dee17f2e84f1d530bc76f51c621
+75ec6b727a82c193d1c0801ac492bbe281b46626bd21f2adbbfd144793ef754a
+ea5f1cda3310e83d78a098160c66d6b0c68d4976898d9dc1a08d01740ac3e7f6
+8d3ce0a7e109104248cb86318400bd82ef894efd9c9456e97055286c144d3efc
+d2625110f1ae76241079bec19939ac962e0ba813359c15b07c74d5e9868e2167
+ea1199d21ca8827cddf1be8357261bd32e79fea6bc475577c5f6848345bce58d
+f5435281572ae6b33b53607ebee6f862d4c752aee43c00cdbfd258c7765b1358
+5d6165ee034e5815de79cc26c4a720607bafa6049710ee3782bc2cd84fe2473f
+1335d20a3b6e9e8355af36673cdbe63c27d4f0e183fedab10031b1ee33b9573a
+2e1961b7c6baa41f7c3ee707fe86071ede5756a00d7b3bf0a21b7c3cf41093cd
+66eccccc22f4534912cb900b08e69574b07f246305dcbc238780278aeb8c9e55
+3d096a944ec7aa9f697f354aa137df90a9547efec1cbd568cb999979f5aec6af
+a84edaee1564d178541cf4631081781608fd38964257cf89b1c8e0120b3f6af0
+793597ad553cee5cccd5c4f09cb0b4e998e6e76243191af7e93833d067833f0e
+53670d7e996ed67cfe6699a6e3815932ad272af4829c2ee08a30d3938c928d1c
+e89af71192ec1247ca233093aafa54ffa58f4aaf3fe9c62302e598f4ff8cc32c
+4d318391f7a36d0d8b416dd36d776b301425cbaf82d520141238781111a14cce
+7927e2af21ef837558002539aaeb170fa7e7e37efd447c37db455d2f08533155
+53f3c5c3be4817680efd0ba3a114db6aaba6c4d0d57b09ef8baad463996718c1
+9d155a62d7ae82eae4c82760c594a6ba3c7ee4290f0d898bb3e404ccaa91fea4
+eaa2146ac6a23f6c5a8aae834a0587d990024bbe8de485c71b916ad96dd66792
+a732a188e6a57c459ebbd7756cfd54770e2a8d81bd4618d916a30ec7084b2492
+5f77ab14169547eedfefb6f03c7d5365cef512df194628d5fbea6cf56d0f5346
+b6b6c1da1dd8d8321b88807b579bb6a0c8f69cd919e311b6ade903b470f4e0a3
+dd5015c6432452ecec048dcd14814e47def4a53c5ca6fa9e91d8a28c719f9348
+509c0e17d632f8cb3f7468bb0e7f7f6525c086dc7efb997a60e059d3d4938489
+23e60f7c67fa6aa8062594f122a48c54aa7c049859928a3dfc72752acad074aa
+416c667fcd176da4d7d31a9f6be6f146d4a9dc78f419fab7c9e6c74d40ea659c
+24098088bea26bf5a725fe56025d1fcf8465ed7103702aef74973f6fb697e645
+e902d65354a44bb3489007c555a6a08bb057eca27c93bfcee9de42e2782fed4d
+664ad7f2d238b7eda1ca4ad473bb9559e11a9f214e258ce1a2a60512975b112b
+336864238a36732c3adacbfd52c85a0dc809ff955f9c81401f72107f3d263999
+a69836d76d228ab4f954b00da07bc4a4e165f2dc5ecd8138cc408ac22217b15d
+8baf04408d4b47e55129b0e596c93d10cd42372292e1ff483868e8510076f7f1
+ed8ead1bdee2b49533f87ddbef2abdcbca432307f7ad0b3c3d4721f3e67e609b
+b06f8b7e66af7c843aa1f71bdadf0f4fb6baac84815c8154a0023cfb68282b4c
+8e24e478f81f8d26ef82d6d0e1da4a65478f4a1f65a7dfb4d1700207850c33f8
+148158a784b452ac6874080039e2259431c05c4522f1d67522e273b443ae9820
+adb5303cd0d839ffd17eb1fc6957159a569f64873b4b3bf99349c486a3af2b20
+b6b9c41263300ab0844d24daf780b4f324eda854d4e210daedc0e34f4b67fca2
+1265ea3764f8f755007b62e9e18e80bd30f3b96124065198c0a5985ba2172550
+8c8eabe77b26df4451f5068956fce111041a7d23f681ff2c1b93344fe688708b
+61a47674c318d078fc4bf79217659987dcd1bda1e1b74068960036c472906152
+cafe4a8a702d271a02c790ea3e440e4f415556ec703a23b7aaf7bc50c5a32f7f
+fee6426433e945c28be038cbe5ee0e7933945f052757d480c58d4d7dc4ab924f
+985e054fd553d1c037beaba29b14e823a4091b08ed602a69d1c3eb0fd63faa93
+36db22e6588d3d2fa727916163030958cc89b3ce99ddeda6190f97e039f9821d
+ab4e4d9a15cb5094041790b995d8950412bbf049bd1d8afeb8bddafc6aef748a
+f2523b8313e13f90f966c134e39d52e10b63e30aadca42bbac5962e4e3f71337
+bc2fd40679beb44e111250352f04cb0404158bad9f74416c94003bd12c88d9e9
+5cac3a3eb575733eb44a3c32946dacdb3405f5b4a2513fdf9e6bb2e6e21c5385
+6c527ccc120eaf95d400847dfc9e6a40806330442e1895b53a6188e57c65b466
+da203785fc322efd64f2e6f66f996bf7ca035bb2117648a8857f1b10469aee10
+dd22d785de27f01f1d725b56b380917004a06afc0046335f97a2ff20ea44f794
+c1dfd6b107549e39247a5cb3f9c37af849e9c5f06214a570113d91ad4e14d9cb
+aadf8ef93a933795c0cbfb7204dc605b4b3b95b9fed0372d8df634f7293298a3
+6aa4abd1f212ecd5d4ac49d467567385f80e163b9464f6554e48ff78d45aa402
+b5ee093a8f96da45504e41bfb1a72f579031efa801690a32f4e248a5f773027d
+da3f3721d4fb481fd1b8e81054aa4a700e9964a87871e01f03fe80ac4215cdf2
+7a4944cf89a893638730631261114f8aab967fe29e280124fa8d51fc94b1c552
+db58e038097172d5f634ceafb877d7caca03436cf6bf40afe4dc99ce08d3605a
+78e2c90ffe766fd3ac0e8b2ab247c3f689a55e350cbe80a9a452bf8666d5710a
+6fbbc45e4690afc625bb7a8a29bc17aa582b6e200bd5123e26b2d445992a3a5f
+7aa128c3f6230588c41c6c456655961b823e65d7471ad16f9aea07c2b3d39c45
+726f023ea4780719a3656ae18670daa3bc084e60fdf2ba1ff0204f285d72d9a8
+269430e406cd36741bb227a1aa28cedf9484689a78dd5495337bde66b5a790fe
+4af761c0b505ff974e4c7f67348eb1887b5b9315a7b3455d3677bc77b61d48ec
+f5ebdc73b25eeaf12a6c896a54b499ba5f2897b7da9465c34561b23e0e740eec
+fc7adf944329e003f5266b94a425f3864b167a34d0b9d259fcd8d741c9dc0fb5
+bffb8c8cef470f923d7962cb5806c67763358a9f6ccf78220f28e45a84b0ff35
+c585c18b19c61b51cbe58007fb852e0a92ed6d704f15ff0f863528db72ea3dd4
+3ea0af466fa5b60ac4490aa5db18a649c442a60b4f824e914915376a127dbe30
+85a3c56ef4233579b756eb62e04fea0a55503f88bfdf011436d9d5088e027c26
+daa8165842a4ddd43fc3ab8dadbb4d53c5ba9a5b51f33d505fe3ed168109f1f3
+9ac5c3357e48cd9e3adccf2daaad831000e27307d6cb2aa6ecf5f92cff39b266
+73b1d3587e029313101a9075ab35de260f23f3d3bab5f7a6134fd07c076dcd99
+7bf2e7c40ff0c0fa1096312b791d638b0038138ed5c578e51309444691c1b182
+8b346fe0286e13e3907beda13044177c788b4948a4dd398aa9fc317665b250a1
+3570a783821db58159b825b14c2a639f62995a049eeeb8904226a8f8e14a7959
+731a74dc4b215d7ec095ebe86a3bf07080cdb0dce6d06fcc2e3a57bb04944f90
+8f395bd65117984c1596303c2781e3997bbfb6ab9f354ebcea7404785d8dfb04
+b19a3a6792807fe5debd6eeec1ba9ba9a37473d6c435bdefd5b2ea9c21d9ec79
+0043b5ad1b0a50f9a24594d00f8fd155681c33df8f0c0b3cd5a4fc275da65dfc
+6c65ed8713956bb94b6281a4f39c8ef72b932adf3f6ecfa697ff7d84f93e7a29
+8fab7b48172e32ba7b3135f4a2501961f4a1c50403fc38c715743b55095ecc1a
+38f11f1475521fa00f950776279e8a377fb4ca4870c8daa4fc67efe4db8e37c0
+d56ad93cd334ebe18dd6d92a3ea48b29e7e76eec5e8aa0db20ad690869053422
+8567c4b72be2093426677988f8ac9f7fcde0dac8bae175066a485f3b1d0c2129
+9e38a93996a0eb7a3357ee43bcdf8749bcfd7e7e0a23c7d9e118c4da7fff5661
+07454fc1ab28a875af7e512b2432256c401ea462d9aeb0a2f97270cf2aa8ec53
+1e5248ad52b1b74a376faaf7772e948f433cea2f0ed4dabec00855a394fedb83
+1daff1d977e9b816ebd27801505dcaa51f9ab531e6c1358b275d3a6ba38f4f4c
+528f2dceea3a404a6362e3cfef9d904b573571a4e634d4852f3b922495af19c3
+c63c736d1e8a5b15cfc4da58f26f22be233b4579377227110f8fe5b0df57b495
+2c14d2011b6215b855c36d901f001e24261089f5edd39f7e5bbb2bf90c6f5c5e
+7ba8928434f52689365ed48123414ead2e00f8860e60afb5f59d2715c4ee2b3b
+2b10399ca1c3f70259c63762f64a5a1cb6b1995030a7d775a04cd77a95436e4b
+c3b1f3d1959ded9f35fdd7fcde9b051245446dcac11fb3d0228ce4c012a2f201
+81ec3dd2aa1bd66ec02c93e4784268f754c9f0eba42d27b755bc58ad00e09e04
+e05fd21ed0c160353d2f5467b5903b4e1d1b8666acce06ada99c063c684d8738
+3d338c579595d1e2ab301c4236183cf2c3be0320ee83cde4ea050160b58787f2
+bad8154825c9b29cc14682e15db5f53aba109799c10f25fa2e54560fdafe6c91
+c246ae56edebe0aa30e152b61fa64e517f6cc41ac7b3c25ecada33e3f6d6ee5f
+562542e0e66d9c07aa9889505d51452cc2ee73e3683e3fabe26f003b87d9fbdc
+a376e85ad9547c23e463fa073429d32ca0e58326385a89106d5b72cde3c00c11
+c5f40d1e8b61e6cb1cc6416e28afa6caa469682ec8365081a21d77a8b1df7167
+6344226bb9a7533c0fdfe153878a3af3088e520b94933d0099c2ff89974bf795
+d871b9e5d40cd7aac72a99f351d824f86d33cc89bd70dd41f1a866657bac3a58
+a4eedf997eb49f8d967e148f381e753d5e67080d2843d44a3585e078615bea47
+6c882773d995f4154fdb773a7d9e29fe46e464e602cd206063c96fc51c30ffed
+cecdfa28a951dd5211acd684ed3efd9feaa5aa98b091aece8681999d7c8ce708
+1c64f09e18e64198b841d7824e03de11101493975ecb1b7d556714725a14bdb4
+5d9237ecf693202198964c1554a04ab3485bbf9ff863441da3511d8fe6363e32
+a38a11f4dc6a1ee18bfa3a1c2c93a90675b0c21959054b17b1af4d533c87ac69
+08d0c344fe817d6817a74fdb46f35d3b48b9128784f43a68d809425c6570c600
+9a76199111e88a1c9802de558332000dbb9d1211929d509af5915b7ae8ea1c3d
+d2598f5007de8e7383f7453fc6a9c0b91c80e9b1742bf6418dca69450785fb73
+12dd228889cfbc3f6711a26022b29f9295ee1ca8459305fbf2b93cb3fff5b6e7
+2b5c1d2c4d453f0b9a53b6f361136b1048b30e7c90e0de8edda423e55ccb2e2e
+ee7b502af2baf30a92af542869b8f26ee28509dc01492095e0c27ccaa30e0db6
+3f02f11dc0ce8a94b8a8a7ef735e4fab04830ef077a8d788b224c184339274fd
+5f7b547b77f81bad985c73b05a79d3c8661a9c2b71c7313d8b9cb50ae03aee95
+2dbf1afc9ddfc00d59e6f99021dffbb66acddaedf48df5462fc528dfdafa5e5b
+a039d6bb9bdd1a78e47684a3c53ca307abd566093c2a4f6b9f0be52d4f1f2758
+ec48370eab4e1e6ab393a23358bae52fed3b270124639dd0a56ca6afce77494b
+34f46433cac90eb63e7e0d25de6c8a0670b14e83d08a531cf2148002f9a6df19
+7f87c989b831c509df23057b3ec569eb5f5f530edd047a53b5b59f483703bdcf
+b578fdc44ca7487e3d39479ca4760457e7018af01116b29bbdf7c3e0f5c07a8f
+7f502c15059d9635b7ce630194962e4183c3838d9401260a743d8ebae1665ce8
+73bcfe5d090a8984e98030fe6b21dbcb49398b6905ec04ed310e37cd069a85d3
+7cd9e3a02dd8e036b2a79192ec036cf7e10653e08928cb8bf4911122d27e195f
+48d3dfaa34122ef2df8e023c9ea1f246af2879f5df632719bf7a91f266d823aa
+caefce067bf74ee0d625cf128c3930ab83521380e0ceb5daa2384da4ab23c34d
+0db8a4acce1a33b6deea3581efe521279147ac1b36e4f6b2c08df2b2dbab051d
+264a250a06ed06aa906c2682ad2ecdccbfd880941bd824d021f086560bfbb359
+e2519a2708a4976f42913465e18872a93cda809a85730a4930ef1e3e733292c8
+06c80c8865645c6a69b128b1333c3ac8c616d3e3a0163aba54c7a51a063fbce1
+4018cabe1b1ebdafaefc27d2b22afc96449cd515cced671baa88d51c5c778bfe
+00208127f1fc35db9c6afe4fc91dd0bb1277181508d7b9868a055025c65394e9
+ab7a95494118d20fbdd7ce0b5f11492df5e8c54c1ce1ecd2e7279e07fe6a62d5
+63d7ffd38f04ba75057cf190319634f57aa246f03f5f904ff952d7b1006d43bc
+ce88d89ade52e861aefad538b644942b6b97e778000de2f2ac2b2280d85a823a
+176d8387ca420a441980d3e866604325917f78572ec9ba14a0944e37480ad3ff
+9c10590c0705840d09c8bb076a5aae81b5e315ca901e262b773143a554360fda
+3dc799fd07482666f47c17d8a5bad6efa53f20707869c5fd40d940a885310cd6
+d5ca9c351731fa69fdf0bfb148e17ac26ff43bfbb38c101867ed95d789ed2b0f
+61820249b398fac0c5eee32032984302eb1804b82bad515d721213732ad43b95
+d4a02e17b22159ca29e300042804b75807782b9bda49255cccf4e35c461ff59b
+65e36f6c6345dbb2e8c2f5445031999c2d8f0444cf4198ac17db48199c3b3fec
+02a130d230aba456406e1070178bdaafc422343ed9edbf471c965d2b891586db
+a34bb2d66f98f716e605799f3800c68000941a52d691640583cce11b94cb5599
+29fd0d5e8a9307831fe15fcd232eb361721d0da9e7ce111ff1ebc256a407372a
+253180e51f1800ffb0313c2c3f3c4fcddd59f824dcd0eaa1e59837487288b558
+7f8e6d27954208fb815ed1d54a36476a95c660751a2ce7d475c72ff1784c363f
+a641595eb92e65d9e7bfe18eeffeddfe82d9f6f0cee37e6a9e60b44939263272
+4816df40ed24551f0d07d813aba49a80bd3560188e5d0170385fd15c34b45465
+3d5d59bf7624ab116452ac28dc9217b11c75a08d68e55b10e9567a9d3d8d5da8
+89116318aff25efab611da69e132ba2ff888d68c84c056544c0fe9137faa8344
+4008487c34ff2c2376558ce20108f76582965fb06c2129e607a0e60889d97fac
+2c71a026299b071ea7f9995a542b7e31efede8a4d341210a37f7b4bb96aa7c31
+c873cc0c3edff7b23d8a22e7e601ffbbab0f671b02ba487cf6b588ebecd26f9b
+b7e8de0cbda870662bcca90716c0ff768a9c7c69c1dcb4086f1e881c6dd5b3f5
+0ac517ca096f28b1c7ac9195f99e44d444017a3bd54a68f4588f0a7562553053
+8bfaf7788a7243c30446213bc987e3383913f24b36b33e4b082e507cae63358c
+9675599f6d746305a417fe8848f37bf85f4535e28ddbc5868dd6dbd3148cdc1f
+2c2d224f00c3af4c1ddbfd88bf79eec76e45ef546cae548825a0bca6bf93b0b1
+373af60a7b24a75079d6645d0908a9f55ed0fe7397100a730a6f4e55678714bd
+90c887e46a2c7703b13b1dda74a819b97abfe6275a24e73901540168737a8b32
+ca1902b7577b8761b3c4a6b60dfad490e35d71c5f35d8ef382fe66433336951d
+e4ee981f980168853438755f135c333b8723d5778e2e3067dc73b7fd99aafbe1
+d5a2d1cf443905fb45730ce8fff14674abded9f94b45756a646b4cb1f789c7e8
+0748f3641a22c01b10adbdc77760c0e2a0b9055c4f9107d935f5c2fb2fdd2845
+6d6d2d2096e4baf14bcc8d716adf053bfe40845f02c0d18fccc453f3f8e45458
+69f802f506ca21d0fab24d7f3d6d6c219637a2dcbc58614c1456a9c6b0b0f57d
+09cce675fff4f626b1b68c0a63fb9a16145d58176cf27ff5d3513dbec6014f3a
+2b5de7ce69c8ac2fc184bad23950b28cf0414801764967ff97022cd4865d994e
+585ff2c992d480de31f549f26a18e4721133f3d88316976bdae41431d44ec8d7
+4eacb29aeb132ff49e3c646ef025eb541dcc54f38b8aeb562887ed6cdd07ffa6
+cf3b2f89e4b0fbb5226702068b8043b6e2f284e4350c97a7498e6440bc3c8d2d
+27d8aa1eac980e960613180ae4224624b2c6f92ed4666e391ae5e159c0ce207a
+7433e462cd92aeb67eb89fdcd20e46f17f3d15ee679c064176a2db0ad5c38eed
+7595cf6ab9750fca76e8e5ea2443b9d13da375ca2a2dc87fbd3d81ed58e366ef
+94952cbd918134ea08f90516854207a2fd92799c410ed1fb6a9c36877d0b777e
+ef59b03f19bc6b8fda91ab8ae21c89d117825a1595466da10f20b86d6d223cdb
+6976312c7fb7bffb58feadfcd019bacedce96ec239b5a799005e94bdefb9ec40
+e717a597326b5330f38fbf708d002c9eb8d8ea0834241a35e3a07a58a030e678
+5812bb5de1cb511426cf49ff39647db65d8a7f2f87ca5e903eb1478984abcc17
+c7ee0b1f7d1e9e3b81c663abcce77a90f1cff1b01f116d2995e65cba0b3f1a3e
+80079ece2fc25e0f5cf24507c99e5b6e87a417cdf29a1a8c58aa747afa962c25
+14671fbe467e22931a723a236aedff5676acde6ee71dc9eec11301af96927274
+a732813a49a473edb7e9886b6c45605681a563f32745d60cb4a26a7064406756
+c9add724e9b400097377258e81cfe085b1abdb3a00354353b50c9bd11a6e655a
+d264a203708f739a46e4322a1a8204e32ae385d4f7694d6ad63f975986ffd869
+355b7ea9c0feef8f6d7bcce3128a0e45853de0a5f442bb805166c7906c9f1023
+df70bca683907a0bbc11249670f81c522441aa6fc4e7889a38d15ead8cad4ccf
+e95ff5438d0edc450e6399f0228ea318dc2979e7e5a36eb76f9d81061ec8c615
+217d9dc7a1d0924dd953ad2b741e48357953d43186da75f340c58b7d2a6c7eaa
+3038fa4b66b0ccea51af9610e5558d82bf79a301d73d57b6feaef32d6f19e801
+e37a3c1ea341bee088e322faf9ab5ab1934b70f894853984abd5f34c4d3fea05
+5ab4fc70179cc9f1379f98b3d1f529f3c2aa4ae63b8d2bfd46afdbcda8ea11be
+f32c93eb4d435fc37486a1cbaadc3c98de581ebad18f35175d7b3e67c9194d5b
+bb3cd1918e86daacb86055a548fab07ce7c933bd984eb713405d2b3f48124432
+a88e10b97f7be3a270405594d3e06c17b47719e2678f0f069ff1abfe7d3672d7
+6a748a9e277ffdd25f5477d0c9d60d7e8da9e0ef30e5fd6c70d47d31637bc0cd
+4d67f5ed2b103889a61fd11075aabce9f2517ec9b53d7db5b27790d9bb1e19c3
+d7c3a7e1b95516ee38062d4ea759151e4de0449e6aae79500c42b4efe4936d0d
+000fb3391330c035d9d6b9e25671f9ac599a40c37b2439c06fdfd988abcbaf77
+0e42d324e8ca78613f35ea64aa88c3c43e51cebe8ed1067cad94ea0387783e03
+e76af474f739b9249d1e95eef85ab528e8cd2da99e33c7ef0ee9df694db43f3d
+fe467e6fd1b5291ecbf6b1ac7a25c002dee8be0727ec5439715bfd8f854843ea
+1d080677f64889d70165f1bad110a8baf3885629f8ddbc3d3b09c57dea28b4f6
+7a3c042ce64d636d0bdef920ab5ef9544f52ad533837867c4930fd4dd3213e18
+ae2ca622e0e218b1bd54bd60e01d4cddfc2e9b64c6c99e79ab2c3e52cbefa598
+434213d475b6292190b89be95b3c6660133e1b498bd7ff2fd14aab2aca0dffaf
+62d9df30c19ca0e949007dcf8453e70e60a519674d305523d33bfc3119037236
+19cc4ab1707db2c4984c6d4fb4310932e9ede7808cfc7d343a7fda08068966d4
+7877d7de7c0f5ffbfaae5666be3bdb48de31c5ab6bcfa7d35816e5862bc4a13c
+ecf2355935040fac37141f7bef7e58f7b025e187df3950edfd6cea20d0649071
+442b2916ebce5f4d3ce055efdabf1c2dc348ac0ae6777f679e2f62a0a3ee9124
+7fc855bfc6f0c337a74c44ea1f5dd32ce6183a4c80a6b967861f6101c28b72da
+d6aa1128f196627e24179c18f384e27cf7f81f43138381d177f93f8082cc9d56
+1b3c99f1bea073a1a81f8bcea131e3587b397937c4029d486fe6842a709558f7
+43cd16c8f0a5e4fbb3e522663b82e2544a6fecefd3d8a2b222301fd4988c0136
+859e86087fad63292bc4187412731a966710ca9ccb86329560d64be31ca4b526
+82245c1a487046ad21dd9a270e3fae72fecdcf9608784f649a25474034ac744d
+44e14e72d02ff17b2252aa5273de3ba3cd71a95070a9fed0dff80653b3d346c7
+56119529e5bcb6011d341e368827cddf22d4f99f1781829df808507e2b4ceb13
+211b08f55444e75a005639a20c33706f8985f3308c08f77e72dbfbe049ae8177
+c2da2e62eb58f0fbb369f5bab0fff49f9d4765f931fe66f8aa107d8116becdfb
+466d282527bab6fa29721678837cb46d60148a7fd9cae63d6aa634d23ee21161
+ef9e834520f367903a65bef7996ab77d37ba97aeb2a7a8c3502aac988e7a0430
+9d67a06db4a90714fd1a933402df0830026920bf1f71cb0379bda8714415c9bc
+e7795fa4ebc37e819b3d8ee65375bfdd6b36bda41b7791864389e9b589919ee6
+2872bac2e221b28150d3024a984033899e5372ab474b9b4494f7bb4331b6213e
+7953565f35d2ea6da212956dab01571cbeeef86293c58a259860e294f69730e6
+f141680cf75d40e829f9679e98341fd1e0817cb8e40cd6c4fa691ac691fb59df
+b78e87add951eac41ad1b4f4fa45d2e346e0fa73157a7d2b2df89ea56a80e885
+9e0d0331d216db4f1b95d662bad40e472f21bbe05576ce4a2d27af01880f438a
+30c17bc65fb460ac1b3e01aa43aa3677ba05a437fcca3ce4c2864d99c701d79e
+3a199dbc7e2f00be8d4347f96b61ba0f88e90b49d412d0ed162e82715ea04c27
+af3feb0a7b3e4dd17c875a51e9bbed3c9e10eaabeec0f029d94fa90d60605b52
+2dcff539fbc323e7f0e1cbfc1a192a44345efc070bd5d5939d9f4383897704f0
+e785126abd9f582f1afe88a727784afdac3dca49892c6beb52cb1adee18034e8
+e88a441890175575951fd87594b63751e69165496d566bd23c8db4b9239bbaa9
+ef5058f5b51c74cf70632f88f1a05e1b40078c183ea8433427f63a5f68a1b81c
+bd46625b8ba2cf713c001cca4c74a186f93aaa3869a517dd64f1e81c71823239
+1934faea604cf4d9ddf974fb09c5786bde05978bb25209b5c7648602dd62c32c
+61ec4b5ce1177185354dd5cdf15540121b6d82457ff3111db1aab1889fb0e3c8
+38cbc7a671ba16a4bc567d9cdd427205e8f4de7edc64c00bb6080071130b43d3
+6e7919a5b7c29c68ac505ff107d1e2ab66a3417612ba2f461548f1e72c702a19
+7a6311dae649e46768d85d759281429b97a35379b84c763d35cfd434a4e3bbb8
+4c6e5ee8dff3a7449bec14c785bce1d4c617217ee6315fda000f0c54d1054e80
+c8f9f452daaa465f633ffc3eeda9c76e7a77024eaf39bd5bc9562fa44f3da9ae
+7e665a33bd22aae6dbc1d9efab63741e30775eeffb819ff933342c8e6b978f8a
+2aa20c2f2810072c4f2437e7cc13861002ab6d5ee84a6f80549683a34da3cec9
+e3471d112332ea260153836fa24e22eec0cdb0a5b3b0773cfd237daa67c55aa4
+cbf1cc30f43183a93bf7d7068ead32ac8064bb1f0a8bb61cf5472bcab360cf71
+b61c3443eae4f1ec7fc0d883559f8a2ff2522dcd7dad5f395e9ab2454cca6dad
+07bb58bdeb1e54f75816dabea8d170974909b2fad53f9a69d97eb11ff20c6aef
+eb6d76e9fa93c317115602db90359be638da383d9e01f6bdacb5ac5bd7c77d42
+d80646ace9f2384774610f63f97d70c4e81a2871be0a5b028c88afd82a3b6376
+5d5064a6786a829a6e6320120395b1541bfd6e3ec182d50982d7bec4140f146a
+06890a79b85a6f20f9bf616f5f56e02752c5d177a48aa2f8ecb67e42e2314850
+d2109c0965a55d1e0f470371443991f9b8859ac70bd6f049dbf57ccc8e2e3c67
+eb8d1b4f36c660746008460ebc0f7284c802925206b968477a503dfa6879794e
+7ed82fcc58443fa1d95fd561bc9d3a2ccb2bfa19916d8a88e6f7eff0ce0a7d4d
+90c77f63bc75f3368f7a97dea9d9392e3f499ae4b8e53602636cd53ebdb42213
+c2668a3c618a76f6f5a96fc33c0e41ef620a63e3c52512c66b59f810c6b85923
+d81ff8618f42ee19b10d4d088bd6b784e4f9bd6bffe083161181b2f79b374fd4
+b846650d4b95b6c3e58449d8f0a201aec72d87588c54fbb3112045040109a3d2
+d98c778ed3fe07f54010773b628baf29ad3b91072fbdef7cde0b969d0b695bf2
+5d386c6b8647bfd55c169374c57d5bd8fb29af5c5a6718d7cee318a06ad35d96
+fbf879929e28bd43b583aff2769688e087b00ea95b28629a71c6ea847f988357
+da9e23422fe2ebc4c33f183679233e0d1d8150ec58ca6ca0bda2a529e6f6d146
+92010b1eda6360aac940ed23410455209383b68c3a1fd68a0ef92d16cd4deda9
+9dbedb1ce18a79817fb3d043f919f1b98c62ecc70dc27886b258428ae2d1075e
+ef8c1225f96be5ee3c1b4e127d26bc2abc6d457333a0d5cce99dff00f3f41e0b
+a9fd7bac9e96691cd316abe913a6edf95c6c5d37086cf3cb960b82684ce473ed
+574fd8c6ca059bd679441c22e6c39376d3a33c8011361c834bbd7b87c345a9f0
+c6cc1328b5af926f763bebc13be92238da171124de119a097d65e5d623cbf157
+a4e93e250a6bc34bc54feb2889da3f5993eff0bf38ef6e440d0bdb405746aa70
+4e5de570b0347d52b25ae9e0ffd758b8d6da1a57e47289a26d0ed30e31474273
+c2315c74a39e6b26f558dec140d384cd3bbd7246bf46a0f7becce45fe0c343ce
+78016204e814dccc58061d48ffc808423452985b12d28c94eaba89eda793f7b2
+8d9fde11f30434bdf73c48484a814ebe541f4e6eb817de43146ae4e04fa7129a
+ec0e4b92ae22a1d2344375f68314d839aade59c4ac1d556538fd7a9f7ee9a139
+f3620952c6c45f7181a6448a807a1bf62cb59f440199297cbc8a360d0168c153
+7c6b3ba56dd0f7f104271138846a6f305f2c8a7536512c54a1c46232606a6649
+81a8083d59a4b5e8ca2cd0b70dd0b44bef1c2ae9ebcbaeecbc7c4bfb2ce309f7
+830ba06f3c8e79fddf737451a67d8c4425c51e11f832d99198c16dee864b4c9a
+e48863f5a3cd0e6f3c5b31a6bff527bce260aefbc40b1d8065d2f88f97dd9ff4
+8b21d069ae8cebaa511f0d00c1da76207821859bb191d5f9261adff3e6417788
+5b493db49420f472496a8207d3f2d64fa3304de0e78d6259a626d8fdf81c51d0
+f81ef8c619507f0544ebd3aa8d1f200a5ce240a1171441438d6bbb19c0850bdf
+4a0147baf4787513752e4e052a09d6b94bec96107e64f6b2692bedf2a38863e1
+15ac2564c0eb10fb923ef3d505f750bfb6407856406cc92e9b2a3a810fb49ef8
+e8f445c2e32b30d352fba6fe345c8af241307e76c13ed376554b857b23f2b10e
+9f4f1d6b25ee850d744332fb73349790426bc3adf811998f84f4721247ed9dc2
+cb33d343ed9fcbdd001d97708408a4885ef05908333546167859788124f50eaf
+7f9cd5b7a9f4a77b2337f51569fe3fb45e41dc50394ec963851fef76ed67592c
+bac68e378043d77137974cb61772228d63d46d92821662203dcc0dd1db375bd6
+95c9153c7226202ee545aa36b0bfba49bba59e918e3bcad377cb461d52442b9c
+d159764090efaa0a887a12b0c9884d4eb0cbae8b2b5fe1d68b8b13abcde73223
+234063907a8012134dc42337f131ce012a98e582fcc50c9507c1f87b83d62dfc
+bb951dd48c3fb078aaebfa25ae1908f87d97915d86bea53e23c2c4fd426210cb
+a517ee3681183d327a5ab42c02977c3221213e76ed5f986ad6bcc14f50651367
+f142a4dc6379213974fb90a7be
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+cleartomark
+%%EndResource
+/F392_0 /ERVBFT+NimbusMonL-Bold 1 1
+[ /.notdef/dotaccent/fi/fl/fraction/hungarumlaut/Lslash/lslash
+ /ogonek/ring/.notdef/breve/minus/.notdef/Zcaron/zcaron
+ /caron/dotlessi/dotlessj/ff/ffi/ffl/notequal/infinity
+ /lessequal/greaterequal/partialdiff/summation/product/pi/grave/quotesingle
+ /space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright
+ /parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
+ /zero/one/two/three/four/five/six/seven
+ /eight/nine/colon/semicolon/less/equal/greater/question
+ /at/A/B/C/D/E/F/G
+ /H/I/J/K/L/M/N/O
+ /P/Q/R/S/T/U/V/W
+ /X/Y/Z/bracketleft/backslash/bracketright/asciicircum/underscore
+ /quoteleft/a/b/c/d/e/f/g
+ /h/i/j/k/l/m/n/o
+ /p/q/r/s/t/u/v/w
+ /x/y/z/braceleft/bar/braceright/asciitilde/.notdef
+ /Euro/integral/quotesinglbase/florin/quotedblbase/ellipsis/dagger/daggerdbl
+ /circumflex/perthousand/Scaron/guilsinglleft/OE/Omega/radical/approxequal
+ /.notdef/.notdef/.notdef/quotedblleft/quotedblright/bullet/endash/emdash
+ /tilde/trademark/scaron/guilsinglright/oe/Delta/lozenge/Ydieresis
+ /.notdef/exclamdown/cent/sterling/currency/yen/brokenbar/section
+ /dieresis/copyright/ordfeminine/guillemotleft/logicalnot/hyphen/registered/macron
+ /degree/plusminus/twosuperior/threesuperior/acute/mu/paragraph/periodcentered
+ /cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown
+ /Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
+ /Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis
+ /Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply
+ /Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
+ /agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
+ /egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
+ /eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide
+ /oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]
+pdfMakeFont
+%%BeginResource: font BZXIEB+CMSY10
+%!PS-AdobeFont-1.1: CMSY10 1.0
+%%CreationDate: 1991 Aug 15 07:20:57
+% Copyright (C) 1997 American Mathematical Society. All Rights Reserved.
+11 dict begin
+/FontInfo 7 dict dup begin
+/version (1.0) readonly def
+/Notice (Copyright (C) 1997 American Mathematical Society. All Rights Reserved) readonly def
+/FullName (CMSY10) readonly def
+/FamilyName (Computer Modern) readonly def
+/Weight (Medium) readonly def
+/ItalicAngle -14.035 def
+/isFixedPitch false def
+end readonly def
+/FontName /BZXIEB+CMSY10 def
+/PaintType 0 def
+/FontType 1 def
+/FontMatrix [0.001 0 0 0.001 0 0] readonly def
+/Encoding 256 array
+0 1 255 {1 index exch /.notdef put} for
+dup 32 /arrowleft put
+readonly def
+/FontBBox{-29 -960 1116 775}readonly def
+currentdict end
+currentfile eexec
+d9d66f633b846a97b686a97e45a3d0aa052f09f9c8ade9d907c058b87e9b6964
+7d53359e51216774a4eaa1e2b58ec3176bd1184a633b951372b4198d4e8c5ef4
+a213acb58aa0a658908035bf2ed8531779838a960dfe2b27ea49c37156989c85
+e21b3abf72e39a89232cd9f4237fc80c9e64e8425aa3bef7ded60b122a52922a
+221a37d9a807dd01161779dde7d31ff2b87f97c73d63eecdda4c49501773468a
+27d1663e0b62f461f6e40a5d6676d1d12b51e641c1d4e8e2771864fc104f8cbf
+5b78ec1d88228725f1c453a678f58a7e1b7bd7ca700717d288eb8da1f57c4f09
+0abf1d42c5ddd0c384c7e22f8f8047be1d4c1cc8e33368fb1ac82b4e96146730
+de3302b2e6b819cb6ae455b1af3187ffe8071aa57ef8a6616b9cb7941d44ec7a
+71a7bb3df755178d7d2e4bb69859efa4bbc30bd6bb1531133fd4d9438ff99f09
+4ecc068a324d75b5f696b8688eeb2f17e5ed34ccd6d047a4e3806d000c199d7c
+515db70a8d4f6146fe068dc1e5de8bc5703711da090312ba3fc00a08c453c609
+c627a8bd98d9e826f964721e92bbdc978e88eea0a9c14802ebcc41f810428fa8
+b9972032a01769a7c72d1a65276f414deedaf1d22be23f4705bf5ef31b6a3b69
+0c896320f09e9875b50220a5bdbbd57c041b5ea97f421685a7256b0d9755edbe
+d05190dabf1c3dbf558258163c8231d89167a816bba55fb1f14ad04320ae381d
+f783a9eacee8ae5c1838775fe2380bdd1f3afcccc96d2a2dfc999b52a6689c51
+af82b8d63205b339103134dac7e3c45e6693940276041bb07ebdb9b729e8ef0d
+ee8bf450fa42551be65217fea902e28decc09580b504f0f52f1e8fc5ce7ac28d
+c4e47f908fdaeba23827a97a0aa741aa7708f7bbfec6fa69cc4f7c3bd4
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+cleartomark
+%%EndResource
+/F564_0 /BZXIEB+CMSY10 1 1
+[ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /arrowleft/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef]
+pdfMakeFont
+%%BeginResource: font WWWUTU+NimbusRomNo9L-ReguItal
+%!PS-AdobeFont-1.0: NimbusRomNo9L-ReguItal 1.05
+%%CreationDate: Wed Dec 22 1999
+% Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development
+% (URW)++,Copyright 1999 by (URW)++ Design & Development
+% See the file COPYING (GNU General Public License) for license conditions.
+% As a special exception, permission is granted to include this font
+% program in a Postscript or PDF file that consists of a document that
+% contains text to be displayed or printed using this font, regardless
+% of the conditions or license applying to the document itself.
+12 dict begin
+/FontInfo 10 dict dup begin
+/version (1.05) readonly def
+/Notice ((URW)++,Copyright 1999 by (URW)++ Design & Development. See the file COPYING (GNU General Public License) for license conditions. As a special exception, permission is granted to include this font program in a Postscript or PDF file that consists of a document that contains text to be displayed or printed using this font, regardless of the conditions or license applying to the document itself.) readonly def
+/Copyright (Copyright (URW)++,Copyright 1999 by (URW)++ Design & Development) readonly def
+/FullName (Nimbus Roman No9 L Regular Italic) readonly def
+/FamilyName (Nimbus Roman No9 L) readonly def
+/Weight (Regular) readonly def
+/ItalicAngle -15.5 def
+/isFixedPitch false def
+/UnderlinePosition -100 def
+/UnderlineThickness 50 def
+end readonly def
+/FontName /WWWUTU+NimbusRomNo9L-ReguItal def
+/PaintType 0 def
+/WMode 0 def
+/FontBBox {-169 -270 1010 924} readonly def
+/FontType 1 def
+/FontMatrix [0.001 0.0 0.0 0.001 0.0 0.0] readonly def
+/Encoding StandardEncoding def
+currentdict end
+currentfile eexec
+d9d66f633b846a989b9974b0179fc6cc445bc2c03103c68570a7b354a4a280ae
+6fbf7f9888e039ab60fcaf852eb4ce3afeb979d5ea70fde44a2ae5c8c0166c27
+bf9665eea11c7d2329c1a211dd26bb372be5822f5ea70d99eb578c7befd44cdf
+045a363056e5e1cc51525ea6fc061dcebb337208eff729802376a2801424f670
+0e7e6397b28f15bc10b40012b0a3eaeb2693e8f7f627c4c9c7c6c5bff105c1e4
+1b2b9e8f09253b76040d268b80719e1b3f5a55ab7b8e134d4cb5abced39ac635
+da001e9934c198a7f9b9ed0028a85e9ae00421dfd8eaa3bb3b4b4ce45d209303
+237bd51809fe4d880900b1eeb236aca87b9ff6ebe6b994a60af5d67ccc42bd56
+77295c346eb4c62bdc1ef22ee07daad928dfb73455f091f32408ed6430b97417
+683af27a03718a156e3f6e7b6e4f2e8177503cd82ddbf4557a3ccff4c858ae7a
+f7efed6cc521a28342436b953e4650b5792be85ea2f989eb6d986905a61fa38b
+96e1bbc830b74469150fb0b598a794fd80d10870084a877273a9502c3456e5ef
+74350e6e3be5863e8ba185eb59fb87b36566af71200b6ed389d1287d4e925e33
+b2383ed05d87d48586e698fbc5d562ed9d8a09ec3eaa1b1f300224af20c23f26
+a2eadc74562571da84b3914d1d80b127c6ff4706c7046bbb372a0013e0ab94f0
+c27946583871d272bf4f20fa84e89d745de7bba885cc09ba72e0f530ed4ef7d1
+864b3c67007ed98800284235372f0a70c912e21e851afbf812165b8df912cd1a
+013e271f0b347967876c68ae4c4107ef8ad1f170916210034c66394a9d971b68
+fbfc1131e37fc178eb97c1b2a0f573add9d7c0bf944e6529734df8a7ef54485b
+a3375cc30e9e328943733cbd352bc15b06c85bfb4a96994291c72a0eae84fb01
+0f1b24d0125fb8c16d60561df8bb7aa7ddfe9549afb70c1e89424214609fde41
+9a142892e30f02754fd234ceb3c59a2a04c06bab7ae40e8fdec50559b8347684
+391c750987802d5452c47c1e0b5f222de9a0eeafee19d796ff375a1e1ef0aeed
+1bcac4f485fcaee18aec585d1a9d80f41871dda45fef1eae82c5893118987beb
+4d9e345c27c7419fe65e4853b40537d822e34ff1e0bd2819d21ef607981259e8
+9f1040a2d708d7463858aa5381759ac49df4dddeb209a278fe60bd2508aca0f4
+6a249a05b652e4c7bf1b676943cdc4602910fa3ea7636985a10f637832a5abab
+9c7a580d605929d6d7154506217252a755beb8462d30a798ffa9b26e500eab24
+7e9fd612c776ae60423995dc1852686cb041e66357a9acd4b6a4e9846b1dc803
+23dab6b7765205d82b50cc6394e725c19df00f7db427341d514047e4bc594efb
+a262eb2c414e43d8acc9cb195d12f3b2a9748f38edb3ac3447d27d20d1e62bbe
+22f6378e508f0cd6f17ef1c500407f6d442e92ef2e00b8de78660d87fd1c7209
+ea67cdb37076e1eaaed128814a948e27e1f2fa81fe54be6c57ef8c2b2e460f08
+6ff1bb529c9100b1d878dc9a077d21805e89d8b0fbc2a074e4b55a869c96fca7
+8117347b9cfa480ff4a37b34b040a99fba99942bd86ce4b46ff5c69babca7a3a
+f5018da05556bff71ecc844b2b718598f0825cda3d19d714fb66472621113ad7
+bb240de7dfbd1f17ffd8f2ef4b85a8eb6e1bfdf26c7f98168197c02c4aa535c2
+0f9ef9b7cb7f1d174b2e94953f541c3b84d43366e0e00a028b98f990b4d01515
+3ccc2e1853473bb9b25857e4b8f9d6695ef332bd3baa9ee551a4b142defb7f03
+97cd075ef9cd41082ccbf63e849c48835e105923e725d41d2b5ee0c3f03a603a
+161713216af97bd21aa87e3a80d75383603152011530b8abd2294d041e90a040
+f61baf86be97f8daa8326eb1a2b4511425785f35f75835683515af6cd0e73194
+2b25d5fa8c7e12ccde33aa193d61a35eba7f7e101843e35dfdf3e07a1442b0eb
+f2a9084634736a21128843df49c84b1061d0826777a754076c4c3d0a68b32dba
+ed4b5c0746ddecdd79fbcc7a4425eddaa7f49257148f05ff52ff6bac71cb65ca
+8ad5869cc9fd7c4c194ae8d5d20a730a035234d8f9a6363e7a49fc22bbd34d08
+eb7fd43a678be52b95eccf029a6b18a512d30ceb0b6adf80ff1232dfda1a5752
+b5222edd9012b45cf0df0644b2e713afef21255a08232efbd5d5f7506bfd050a
+f0daf55b5db595d29361f8253c26c37e09b4f87056edd8c90e0df4fc74072541
+8ad8ccea562e4ce72acc8e9f39284fca274c572ffec24ba30ef9db07054965bd
+2205d717c9b3b0723061cd74ec688b915ab6689904d5762629c891f2fc0cdfb1
+8d8a4d2260dc93d7ac1107b197d7e8418bbacfc660d888697296b7cc6581024c
+e583b0114ffe3b3a960d601ff23c0f633e2b85300042f717c4718c0547fd9b19
+e74d0e18f6908e4528065888c136dc8767b74025ef5faf470a272f57f548d738
+c5d2ff6def4366c1c08e0b09855e04ec3bbd8cb6b770f638ac7d852b7b2250f6
+cfbb5669c9112fbf73546a9c1e968a1e1a06128efee6422e41df1519c7346635
+31fea419bba8067c6d0e964143a0906762197b8de95502ae9bb54ced17de5ce8
+9d628716bf1e306aad09bd7f8cb2b7dae5bfa9ef53e716d5aa2ca014eae837c6
+c0f2d5f535ae93682e855b1bdd6ce955627284a4712f67c1d6de9f80d4dda43a
+9fe34fe4fab544459a1dfa0d1383c50bb3e6c3df078acb88db37ecb38aaabbb3
+cc59d3fbe6a84f1f9521b6e05d0a0b2e0fceae8eeea4f41976945501f32bb383
+455467d21777796688e57ae9b7b392d167b63bfdc1102565649b53694f1eb3e8
+5ec2f094ab06d427b5e1e7412b3369336c766a7fc778190dd5aeebef9b6a034e
+133314cb512667f1a4eef90a1251ca9e8aaf7966ec96004c09c4dfacbb0d4c45
+60d8df4183d3598fb9584a4433c9131f8602474f27e4916b43de80ed1d02f6e4
+d208b014c0a44d94ef709930eca646b2f07d8358d48d0a768b6f13492e3cb877
+fe38c58a7f5468af52ffc11b8c02bd91484cdc022abe678a7f2e298a7fad967a
+2ea7dc427e6ac154766ca4ae15fd414a76064823f3145724184e30ec4f1494c8
+78f7f63edea60daf2448de8a79801ecfd86a06ef122451dd2380bb1a4256a7ea
+806d131e66d5a6e3079f7c2d7c143e2879f5316ffebb1bfa166a088b8fa9cb7f
+4a5f0875a8ff5d378e9e8205c6155ea85756475ca5149eb72643b4ae1f907c0c
+fc8f63150cdc6209b1951af23ff68188360939501770eac39ed55dadc4dfb1c5
+b2ef39c93d0326a804f62e8f187a224444098835ff670ad55b49f3cd0aba2901
+293ae04427916ee14c81f4044a05d9c8ad14ad4b5567e8e0147780a0bd294c5a
+10a50a5cc7656f901588419108d2570e804a5e590004008776c8cf20b56d5ef1
+fa32538c480bcc1955321f954008871ba180177dea952fefec536f6522582647
+bc205dd139a18d2a41956baa4b002169cf042ab2ebf91ff203dc2e2559171910
+2119e94673a275d73f3909d0834b170e2b62beedcca27afb44a35ac51dcb5719
+82706f101b216b4af3523974378a05c327702b132335ff288adf62578f30cdcc
+cf826898361bd49238f368ae2182fbb631e375e903ed9efb911a047119b40830
+a39909494e86aee21694223df1a57ac8e5b4f0465d0868939ac77ccb448d3f58
+36631cebdc06bf2865c58437568cd734efbfa870214853232ccb48cc57c8c32e
+97cdeb89cf5e0c032e81de377b368f7d57187f0828675a52382d41de6cd9fb52
+2a1ccfde3192c650fcd7d1f86db03c401e6eebd0d40bf23c10e021ed66bc5b7c
+ae57d0905bd24925c8573f069139883bbde13df3ae05bec1771eddb9b003555f
+9d69657ac718c065a32ef7ca8a1ff5880fc66196e8123050a47ebe4dd5c1a4a7
+40ce1cf340bf08021fceef8172d9cdeb063f4e4c2205ae4503c71aec1836f9bf
+96ccd0a712e33407446ceab96221d7b3f4342fc74aafa802481acecee7243807
+390b2d12c844193560738e576d27b0f5a90b25e1b5a27de8a2c74b3303526191
+5ee0251065475f26bf0bbca5549f13e1357797a5728b46ba9570c095d938112c
+b3ba212c26cd6bb569ea276e1d8397569f8d4c78528490187a172d2e30dd0228
+d69fdaa25fbdb477c88d52f0ba137280d68656036c17b8852b03c21621d0b21c
+6c016f18cacfa9a998e972f40eda07278da54fe5119babf0145d6824f051cd63
+91bc93472f780f00e261dc74d6673da37d8d9291e25af279829f8d47bb524c19
+8b598ce1c576ac8542b5ead99b039ac2996a6d791a22a5d5bb0fa3eb65d1fa01
+401d5c7d44a9cfe082e9314ada6f4ac8ecea5be8e5a1cb6a1dba1c615e69ec9b
+0f231b64ac31c545859f0195bb9b403121df7be1ea1488b413825d8e1d7afbfc
+e5a8e1e52d9c3ea6de3ce75d013cb7396e825bac3a50d0bffd2d30c6f1c5dc0d
+83c1b68dd8b6042382285812093db4c5d7f6eaa8a4acbeba794f63610456a641
+42fdfd0c4c5f0c4486a6170b7701ca64cd1408f686fbd2afb56ba307722b2bba
+c542123f766171b43aae5ac053094a04ac4faa3cbdadcec81ab5aaac58d3a7b7
+1dbedcfe63d062b11dbcacefea89c6f8916389d3f7d93da89ebd8c37414c7db6
+d6512a4e8c76145ac170faf136a023b3c31cbae9775e436d6cb2835b77b56458
+6905d558a3cfab0f1f3426557a66bf775292df056cfaaca8c087b4c0bcc2aae1
+fa49f346602384f743be6b1aa26134ba2872366c17f1dd356221838a40be3a4d
+0b8502a964d360ea9bc58e4ffbf283c8294679197faf5d23aad1c89c3da84902
+c95619fa0ab76ca0c7ae725a1c5d9c40e84cc84eba8fc95361f3a738ddbcb593
+b3110db2f69ecf9da21d788d36a1bf986e2dd78c9e62f643e6677f80991f90a0
+8bd35484fc4aef3243bc3b460f57bf6f0a503b57f84723738e1b94c3029520c1
+f8d787f99305ef87fe64293b5fbf0a378306459c022f4127f2e2207ba818aac4
+1c860b70833b92cb7228ab2c8f68d03b6ecb67d4f83cb160c170298e1bff339f
+306505ea4fe86929f115b3c55c7fbdb7f09eb38f7c8ca86c9c89d9b92dae37a9
+5839a181e6e55835da3e81c8846980ec5c16646a31bbffe54a8505e005c9200c
+cb2b476083d7e55e63648146e8e615d349ed779b787232605beb38346e3578bf
+d043797edc00f6df91c9a02958ea01f55f00d576c8a8d236e81b59eaf96bdfe3
+4de4125a3893acea97aa8d6373b736d4cc0166095bbb75b7341f06d8e3fb732a
+5539fa8a27abc1d82f1a86a76870450fdebbe889dd048cbf2f184dcca5377649
+9ca0053aa9a88ab4d6f279f8a3ba704ed057dc2a361d07e5af6c9c8ce4b08c05
+d06635afce1cd7fb1288df9ca1f9a556d1a120691297d8134214da14db45cdbf
+5545abb75134d45257b1e373eaf23fb600370cf8e7de02e7211639b11f8fa0d5
+6627c5718f554ca3351ac95c04dbe894e20692065af2c7a9e239449df4a65917
+2e0fa2bd3ebffbffd9093569851a31db46c8c30c1fb8339a7f742a2c89212831
+15459844298972b8b06e2c699d6acaaf331a023047e5b2041fc39d830b0851a5
+8ef1e329b688034f9c91927cbaae2ec2c84f8502127055ade448d6dd7eea3aae
+392dce03347141b3b85f3018b3396b9fb1e4a59c50d9e8b82610088575eec663
+5686e7234e72e4690ce386fcf9d16b54c9c692e9324427dee7e096b6d4c45501
+da2d0eda66a1f29e90c00fd2c62ae43a97f611794c4704d179ce0bd63ffc4f50
+ab3ca7086bf942283fb0d175888a13e5278aaaa25a26e3df4fbf13e64519ad94
+44af171207f3f89b369ccd6162c0ba1320d30d3a596d9f58976f94434c1fb773
+e70be87528a9bd5fb7e494e6cdba0a3cabab8dc2073ea7f5b956bf5d5ca1b258
+25a73e0824ce8d00f4c945c0afdc4b57f7c0162a14b30154b61ab030a73679af
+d43e322a04fc7b3c814f3b2d07585eae6a5254b43bc836c6000bf23a56fbfbfe
+8478f1cd00150ee39f0aad2c7ae3313b8d619b84ddd8cd3878a4b306950873da
+9a592f520b7d7e0cf9b9c97d35139eef9c329763869e64d89a52fed016e1cd40
+4497359d9d4d6bb70222418282cd9ed7f12c16cc1aa6b3eea9c812b7c3910209
+2831b0f05e644f58e878c1eaa3d587c89b26db8b9952e0bead12c7db6aa5a042
+9e33012db0551fe6a589baa800905a7cb35d220efbb675a96444edd18ad89dbc
+ebc4087162e977b4cc680a0e3490bfaf28a556c3bb9299935097e3e048679849
+a85ce906f55bdf564f3cca2b0a70b404d02520b77614e577231cb2310dde1ba5
+cea1ef926ad191c98a21ed76ebb8f407ea2ae2ff56014216abb118c0218590f5
+f3284f9a187a85b3f5091f05b21d747f6fe7384a27ae6a8ddb923df4f61900e9
+adb8be5d338613e1486d710e892b5b733061951d164ae233023a69e02457e90d
+dfb6d8a53ea0a57f3c9e27614633ace3c6cf57dc8c81d0c079642c4a0745d281
+2bc6ac4587a56e65d6955e50f4380d94f9628c130102e2a3325d694865a0dd90
+01ab118f393fd86d01aedb5612fcb49e8b81fa6fadf7b69650fcef45a0a724d9
+ecf8ced5cf56913fb68a39c71350acd855433cc25b25ade198cda46bfccf1fac
+f1c841a1e6058a73e26e580cb46384885c417799d92822689c2f58bc1e0a040a
+9d7d3d73de3c18688d62581d54a0eadf9deffb3db34a9f052bce33d5fe8e8ae9
+78e4b0bdcc2a8ffdcaa5b4c0f4a0256d94364e70e1749dbc2b147d69ec539b47
+ef868ac4807f7ac1f01c93b3361942915581efc754453f221f4a70bb903ec310
+62cca7ac392f6f70b61f49822cfd65c668070babc1102322e4cf224902f0cc6e
+26bb2c119c3c66434f4a85164c49ed51084a1f0795eb631f6d38123619cc5ced
+c8c6908f380a4a3f7939d0b03187e448fa44333ed8d8c2504c3fce0235795d86
+f7a7bb423d1a7ca81b27b4f81c93ac95ba336a0d8e6bb90c96ae775ee34c07da
+5cd019a73b7944424d242dd7d96ea0349307ed426fe0c7fb8b5cbe3d295a3069
+b975fafbe78109cab35ac2fa5154f66af9b9ea522cd4847408d1ce24cf7fc770
+4f222fedc962ff21d09aa2ae6cc1b14cfbcab5d0016607362d3c8f6347f7a54e
+821327ddd475396b465b1bf5894703c6de1e9947e64867e68efb2620c7f46367
+c0c345f294b781943f0c96500688a08347b0272c60e5d6a7810a44c4e5654d09
+05931a57e1fe6ff7edd1e77a1e1c39070b49e4d72a62f06340f9a76d0553905b
+35e5711434d25cc3b14557bbaf66a82a6ef543bbfd14c314ddee0ee99090482f
+c1dd06eecf203ec9511a3ad6ccecdd1139ccf31dc72e407853d159c1622131df
+f560bd84c30c58439b06aef79bf53ffaa90ab3727e59f164271a69c5bf36f0d8
+3f9c0099933b6bdfc2f613d4f3565dfbd0c85e8723491ead13697f8945f63a6a
+612990613b54bb7a19c1d3a13c14f19694e3b1293293a51c64ebe436738eb61e
+2ccef09ca77eeb35c7bf10db2a9b1eabbe4fb88ccefeae6359bf5e136ee974ea
+a1a5c7152d54de8dfab89422943ad50e5884f330ad4078763ea071c6265e555d
+a610d246133435db11c37e786302e3e8889ece1d9ec3670d82babfed7be2fb7e
+fdb78e1b6e1c682b930f48bf0a28301b463a5ca77c368f7d57187f0828675a52
+382d41de6cd9fb522cf52d8792796fccac48d9528d6ba65cca775eea0d9e272c
+084f8017bb4ff779b615a46518b256b2c43b27e28b988bf6b60d783d56905a5d
+7794904c0cb95e2aa83512f47d2c393b778b7611053d31bbc4670c6ffe45ff25
+2b7064e4740e8895169607d57c89956b526a664b28a2a9f7c42d6a40c4a95aa6
+6be98967f52a855db02c498f141fd6afffc0a69b14bbd009a0c0f023d4d6706c
+cc05401aa96d550b6ce0190281ba4cebf16acfa4fd94730cd977d6c120c124ba
+ef8489e22a13c30552196e99046201ccff11cb3aff92a63e47a10a3a6433bfc0
+e77047453b71527f209c939d8516182ca5f0966ccbf971fede25e3fefd92cf8b
+fd11ac59dff36c25aaa8c771a83d9cbb7dccb37f4f7572f11f702bc27ea9510b
+a2d4baa94f5953beb927aaf2426421f0093c603bd63827e28f17d57cef476577
+c1f13eb8beeada42a1eb221cac3dccd5d84a6f74fa2b289c3cab6e2fc94dd92b
+d96a015b218ca7facbe18f9c7a580610905847a649e4477773b87686f7f28b33
+24148f4213ccaac483b43be2a9763fdbbdbbd50a0f9d59fc31f5b7b2ac0f915a
+89abd64d84faa62a4c3167fbbf651a6236ead6ad931c11435921cbdc4ed66f67
+fe83bc059fa0c625001ad5b3bf638293646d33076f3afafa8b8fd7307da5c53b
+5845999c1624e9ed30cd48483403f9afdabbcbe80fa5025bea2cbc081e2b32c7
+42685421ce3d574a414b340075cb02e80d7427d4cc503ee02f5b33e509d76e0b
+21b5d5a252757c4b7893dd9870f9371eca57ae78ac688ee28c31d597bc018496
+3fa54a8e160a77dc8b0627d7319885fb2ae0e2e2c9fbcde4b5a7acb04bf1e611
+b73b0dee3ac8f44c4ca15dbeca20c35a7a8805f3c22e6fba8e9b22722dd25ae3
+ba2dec2a0c9a13509f4c9fd3dba03ef6e49a632bf7de5ec45b64a1f4e3a36976
+1b7a9c7b95bd29b09b930b0d82f2c39f9bc3c24d99c58a664d4adedf7b74e13e
+6d85e03e615a60a2aee9f790c6d0a2e6e82e6840e51b38c4579fb95337423fba
+437d97ab42bafb1097b2e2952e86c88e94ba7020e83163b5d810de8f57625819
+d86d7ae834d7135e30f2e21dd061ff15f22de6c9243d2caaa5abf67abee3a6f5
+306273037adcd10e8f00818ee88ad2ea98d6b7f1ee7e3d1db49a57fa350664d6
+021078ee1ebfbdbe5aee9efab2acd9809ccfb180f8017a84ba6bfc1ba5940eca
+3076c863f8d9df3e4afb32361acab13bacd3e465d094b64bece987be66fa501d
+5deba893368ea3fdd3b3a4201d3bd68b3464ead10c6f0ddf513a630e0133fec8
+08630e4b3c8b0aad1bbeed508e7e03d41b3d060a92b1958407843e4cabd78d79
+ff72fc0e92f4903cfd05856f457dd15b1aab99c1d29804d2f3134c9817f45fd2
+efebb92545f056f4ca76ea74ad464cd041b7cbb8892f2dba833118b83e20c039
+99939ffc6cc50503bb871565797ec537e26eb622fd30303273748af2afd97e07
+a9c2a96f4ef8754dc3ea8f3348cb30d76bdaa84d2e933c94c99d13e74f19970f
+5d2bd19712926e230dd02aeae6461edd83ac935ec2f420649f82d4160a072700
+10141602c3a6572740d8e97fd08e56b987062bb57237bbb3056a36e97e399a7a
+cf9653743a9984ef36254d60772a0eedca800923461a3e4443a5ef469aefceec
+aa1831e56b0d8ea6ccb76bb9dbb6ab7584ee268bdd0f5f0d57eddba9b97d74a2
+910f178f388a50fa32aad7b87b3235efcabd4b5009190d12e8c770f6e70dbe10
+e747e1984a1c41d701e6220b001fe25b9a677c996f8fd91bd40fa7e07f57e8bd
+5d2381442b337924e56de4d18cdc352314caebf065f610b00b50302bae3ad612
+dad9059a3d7f3bd63827e28f17d57cef4a8cb8af1f080a993c3c74871e4b7bdb
+2602d07587aed02aa783d80234b6eecc77d163847e63d3c9aa412d10acea7a5c
+5ece5b893bb3031facee72701acd225d6b6a752cb2f84de3ceab2b97b606a0bf
+c6874869a86e3a55a4e1d7abd94719f604ea68b1108ebb5bebc3ef465bdd2cdb
+864ecfe0d6959d5114eaaf1612c970caa2c94729178e6af130a1df211a3795a9
+b5fb934e47f6c48155a19acce788036b4867f90d40c1e4ff7460399f1f08f98a
+0aa3e0d8e354195a2563759dfe0183c8d67b449516ed8f5cf3288f7298d62092
+922f07027352bc7c9612cfca46f1cf2ed1417ab863c2615f2d26ee13d7a04a18
+8336ec9961e76af2f506e3db3d67a2a4fb2dbbb0ca34be6db9789a1cda607d9b
+35f0eac47f488bbe74f8f04b49dc492ec8f096e6710ad59d248a0c98497541d8
+5f9134d5215b0a05fc29db1aa71e432a2c0b00106bf3124df0b72c144375a280
+9cc5ed8335b3e970eaad9178f43011b55d7f3e11d89be1058361893016254440
+353b88162a4e7913721092e05573497ed693f3120176dc08253d2356559041d8
+741a6b9c41f8eb695369633632ffc35a1e2e4ed6258f0a8eef0bf6bb028efed8
+a679be4bc197cc868255f748ca953312eef556d8fdae4e9706c3116e76140587
+db18492730a14e96c211fcd0aeb0d4324b1b4abd0150637c6c135fcca1823fde
+20482dbbab536f87e1d3f0ac4b5154e33bfaade3ac4af8b8d2082658d35a251e
+a0d718f702ed8d957555331c9593abbf64b2194dac9f098773ef4313cd8a48e7
+4d60513d6ee1c132e59ebf5dce2359b61efd16fb4cce810172abb3939e874792
+a862462c72895461ed4dd265abbf52c11c50e607fd3bebeff0397398f656066c
+5f64fc4e67cf5f984fe818c9500cb10beadc1ac513c0c8e60701144b949ce67d
+08cec1adeb70fb01f48abfea22412f4b07b710a8d774228ae156bfdd556c0f49
+bda072c0926a08150f77ee338b3b4303bd2186da21b89df804cd531c499ef953
+9b1ed325e5ef952af05cf67a9fe64b1af975c18348809161ad382debfde45495
+5b32472edf5098b6d1f8fc8807f81ee5be3659bd0f47542ee81e20cbaef168dd
+4b991069cda2f850b1faa40e74fad79ed5f74a0fde1c060996a2280e9c9d21f5
+d23174d3ef4d9eb6e337d443cfccaeab8b0015e6427f9439c8473a1364faf782
+f58bd8bd775899092844ba570c427dff47b8cc4859fd9042ce78aa27ffea8b5a
+c52be0d97cd01c7250a6eda489b5a17e23167239e0d7fd8f3429529ef02548e9
+b7bc1dcfc729600ff98d9f9b33ecdd10ff78baa313b7e35c51dfe8c6a17568fd
+bfbd434860a8ef3821b336783fa328279c05b05aba37f8d26da43391c9cfbd71
+6b240148995a005448afbe45ef2c2853aa3c1cf3ba6434ec79e8dbacef443569
+8e6ef17bdf960e9a37f0b34f4aa39641492bcce95afe55d168e510f934288da7
+c61eb3e1a42f18abc608995cd8c9afcc591751bcd9759387d3924751b1a2c79a
+0cf18b53d3ed8096e2c559dd001e8bf6824b3eedafedd8b89fa23f4aeed14435
+a7d05da7b0607edf2aab0816e866f6791e834bff5f5c6699edb97df199549d54
+3d039671a481d094352ec76d2f7e5119887ee3ad1117f749a85b3b6f37e3d25f
+25397d1d019da9c5c6fbbfbaeb4fdf0a423f6394968f2eabc560f76e75b07b54
+a6d87328604fc86be37a1e8e5790eb845cca88bbc2e01eab28a6d6615229658b
+7554a85064aacf698949e4f56f2bd61bd5af31bd6012ef0c1bb627cbeec71b52
+e99af95f699617a8462e14e144424a64e4c1cda80a13cf7b20929041b2df6686
+15c2f77a73f9cdbca33cd11188a9a608b240b27e7cfc5234fdad6db5d6565787
+d99f45709674690ee704de4ce6accc37343eaac02dd8ca368221d607c4ea24dc
+05aaa5162120301a8fb4c3166ef0e813aab536200a8d54d3e0679cbad59cae0d
+d9c251016336c63243b42f4a439af0f1b4d4cc3ee9c24dae5ec87c10b4b046eb
+3877eae636101c3231319957690cf7cd562fb48e44abd46bfd8640de5348a01d
+8389dbe26165729c3ea1023b354cc6b6928922cffb2df9ea60d853a74067b442
+a7d4938296e2ffdeee8b33dae2ecf5be2451fbe3829f9c1d45820c9849176a43
+22694f059367670d68ad12080a84603821f867ca37dc727c3c5254103af21cd9
+034f679aea5d4bc81366245725fa46cd671ac9251817e8abbe9f06f182b738e9
+05769b0d6a504170334d09bb7b809c249ca9678658b36fef98a0f8936cc9167f
+31837fb2e92319b8e4df5168494fe90a12a88b93bae098fac2f3af2c087759cf
+0fdc3d901e921222a19e53c654d13e52a6f272bd65e3deee14e3e59c6dd9b794
+dbd476ccd4deb50e94d207123a5bb6276e40177c13adee9227e283b51bdc8e50
+2af8d9f3d4cdf61a9bffdb5047aa305f7c61fbb49440b70993c9620020fadf15
+4b5248e8e2a6fd5638a447a593b320039eb53a709e992a481c0de5f19640c17f
+cdcfacfbf7b5252c0274c53f6de78a11db640076e01a11be6a63c3a8be0e3fb0
+f0c1f40b379b80399771b0b23aa0fb934ee3184f0c18d5cb40285510a4eb92f1
+6f089ce3cf32b52add23b0f6a436637a17a71f90e8c91adeaff7eb97220a17b7
+354ea80c678e158c1ecd586f0e2e6d7ab5a179500d404e19a65db6c9568b0799
+330d69b254d29e704196964553817ab428be257c5d51aac61ee9cffcd3ec4615
+1d6e9992ad91a791d1c2465df24757dcbc64f3788b15868b905e53ccd04625c7
+f04fa267d68a6aeb59443ead9bc171f845b2b0d7ac7e788c21411a1d4b3935d6
+ef2093333ce092da5d06fcf6c1f1afc68db00cc1d0090f21046b54694f5162cc
+cb07ac6e81a3b657871db0692cd70edcfb645c335167e08eb15caa6cbf6419b0
+1cb28d3beb8c5ab6c8f77663a2c258177a1feb9abb560e903b45a1d14644a08d
+778a0db918b36ed5a2d6d409adf41a21b13211679094cf290c4652633d861e1e
+2cf20b69ccdcf17ac7d4bc15febe037998b98c176369d225995e578f62f6e548
+049da929686caf8b58bf1baf99bfd7196c8084419d381078ad0bc6bffbe163de
+15a4d0e6fb53208aff06f08967882b17c0696f060218ae037682036cb39365b7
+33d8c2b0f2414f3c919473a6abc8d419f70b541a62082602990c3c35a55217d5
+96fea82048181950779a3fc5f67bdad8df84e5433fa67bccd05ec886d857b789
+18ffbf083fa0b9f98cf5cfc9ae29d607d2ed11fa02131fd7c258431b20f7b113
+c316b7163644fdef029d33366200e9c4b5727940490a81aa139dddf9493f6b32
+0ee84950a6a549460032d0ba7fb3b2ded2e4028bd3ef456005bfc1456c681f25
+82dad6da15127a1ef14550d9557b86c2bc37440d538ee5146f320c9db07aed68
+70f6fa748a5b87fde0e3ef4cf1567e743eea26076ba668b46f3f7ad99f4df367
+fd40d87cca35267a09a3a33f8212655b747323e9d5f184cde766906f6f85ef2b
+3ad0dc0edcd150e589dae9c0e19d464ad618c32e14a5dbcaa6ecbcd990cc49ad
+c6de19129debd2de99b506adf4dbdea4ff1364e300447c9c0deda2cdf1d3648b
+1a83bd4be46e1797fb5b6216077a54f12c7ace9c28320026a19492e58193d082
+c0b5473a5a603ce22ea377511b725ad9c23b1a1b906b465fa02d0fb620e23074
+66c9d077730916850cd2abcc2412a364f4a0efde3fb741dea91fbba138e74dcb
+809627282be317d8f1dbb22220c9696bf39a27fc38aff90eaf458151a00a8a88
+9d4f5d933b1eee63054c65798ad32079ce573d53c620b6a0f81fd931b5a24707
+ebb30cf01b0c63b55ee8c08b805a9a45aea8aacf49982ce6d3e8726c6a122437
+1b9b116a56de605482449dabbb83d353ebdf355fcb8cde5658c699b8a55718a8
+6e051b42221dda48257e9f56d09f31a77630930abb0fce0d49ec9cb27c6ce480
+4c3b36d45ec195e7f78dc930370ed66cd4b6763085ec4c626693e69b39e993b1
+70b2289f29dcf94d5d2763a8211a92c40442371aa2f4297c9958c833421ee693
+a74b256e425979afe86b286bbda0983e14194250d9fecd03a8ba1fe615e93ae1
+d60d43f6858ea9cd47ddf88a1bfb5e90b60a28cdb269d9e1e43b0cf470a95b48
+aa5299e7159e7ccb18200914b93c3b0df79f181789fdfd6693613d0d42778883
+88847927f59d40f0cb5334f62eafe4f380076cfb7720174eceab1eb5050ea12c
+e4293db115c4f9bd4d21910a69d566a706f5c0e1bcb344203503855e6643b125
+17b6db03c41f13a347ad39e47a46d626f8a31a163bda6d23264657b412bdec99
+c87a103d26
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000
+cleartomark
+%%EndResource
+/F637_0 /WWWUTU+NimbusRomNo9L-ReguItal 1 1
+[ /.notdef/dotaccent/fi/fl/fraction/hungarumlaut/Lslash/lslash
+ /ogonek/ring/.notdef/breve/minus/.notdef/Zcaron/zcaron
+ /caron/dotlessi/dotlessj/ff/ffi/ffl/notequal/infinity
+ /lessequal/greaterequal/partialdiff/summation/product/pi/grave/quotesingle
+ /space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright
+ /parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
+ /zero/one/two/three/four/five/six/seven
+ /eight/nine/colon/semicolon/less/equal/greater/question
+ /at/A/B/C/D/E/F/G
+ /H/I/J/K/L/M/N/O
+ /P/Q/R/S/T/U/V/W
+ /X/Y/Z/bracketleft/backslash/bracketright/asciicircum/underscore
+ /quoteleft/a/b/c/d/e/f/g
+ /h/i/j/k/l/m/n/o
+ /p/q/r/s/t/u/v/w
+ /x/y/z/braceleft/bar/braceright/asciitilde/.notdef
+ /Euro/integral/quotesinglbase/florin/quotedblbase/ellipsis/dagger/daggerdbl
+ /circumflex/perthousand/Scaron/guilsinglleft/OE/Omega/radical/approxequal
+ /.notdef/.notdef/.notdef/quotedblleft/quotedblright/bullet/endash/emdash
+ /tilde/trademark/scaron/guilsinglright/oe/Delta/lozenge/Ydieresis
+ /.notdef/exclamdown/cent/sterling/currency/yen/brokenbar/section
+ /dieresis/copyright/ordfeminine/guillemotleft/logicalnot/hyphen/registered/macron
+ /degree/plusminus/twosuperior/threesuperior/acute/mu/paragraph/periodcentered
+ /cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown
+ /Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
+ /Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis
+ /Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply
+ /Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
+ /agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
+ /egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
+ /eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide
+ /oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]
+pdfMakeFont
+612 792 false pdfSetup
+%%EndSetup
+%%Page: 1 1
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 756] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 463.019 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -36] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+117.436 701.916 Td
+/F122_0 24.7902 Tf
+(bzip2) 63.3638 Tj
+-278 TJm
+(and) 44.077 Tj
+-278 TJm
+(libbzip2,) 99.1856 Tj
+-278 TJm
+(ver) 37.2101 Tj
+15 TJm
+(sion) 50.9687 Tj
+-278 TJm
+(1.0.5) 55.1334 Tj
+[1 0 0 1 72 696.784] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -15.4939] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -681.29] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90.4929 661.631 Td
+/F122_0 20.6585 Tf
+(A) 14.9154 Tj
+-278 TJm
+(pr) 20.6585 Tj
+20 TJm
+(ogram) 63.1324 Tj
+-278 TJm
+(and) 36.7308 Tj
+-278 TJm
+(librar) 51.6669 Tj
+-10 TJm
+(y) 11.4861 Tj
+-278 TJm
+(f) 6.87928 Tj
+20 TJm
+(or) 20.6585 Tj
+-278 TJm
+(data) 42.4739 Tj
+-278 TJm
+(compression) 128.579 Tj
+[1 0 0 1 72 657.035] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -144] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -513.035] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+207.676 503.285 Td
+/F122_0 11.9552 Tf
+(J) 6.64709 Tj
+20 TJm
+(ulian) 27.9034 Tj
+-278 TJm
+(Se) 14.6212 Tj
+15 TJm
+(war) 20.5988 Tj
+20 TJm
+(d,) 10.6282 Tj
+-278 TJm
+(http://www) 61.103 Tj
+40 TJm
+(.bzip.or) 42.5127 Tj
+15 TJm
+(g) 7.30463 Tj
+[1 0 0 1 72 500.625] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -435.826] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 463.019 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 2 2
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -13.9477] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 709.534 Td
+/F122_0 14.3462 Tf
+(bzip2) 36.6689 Tj
+-489 TJm
+(and) 25.5075 Tj
+-488 TJm
+(libbzip2,) 57.3991 Tj
+-542 TJm
+(ver) 21.5336 Tj
+15 TJm
+(sion) 29.4958 Tj
+-488 TJm
+(1.0.5:) 36.6832 Tj
+-766 TJm
+(A) 10.358 Tj
+-488 TJm
+(pr) 14.3462 Tj
+20 TJm
+(ogram) 43.842 Tj
+-489 TJm
+(and) 25.5075 Tj
+-489 TJm
+(librar) 35.8798 Tj
+-10 TJm
+(y) 7.97649 Tj
+-488 TJm
+(f) 4.77728 Tj
+20 TJm
+(or) 14.3462 Tj
+-489 TJm
+(data) 29.4958 Tj
+72 692.319 Td
+(compression) 89.2907 Tj
+[1 0 0 1 72 689.349] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -689.349] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 680.364 Td
+/F130_0 9.9626 Tf
+(by) 9.9626 Tj
+-250 TJm
+(Julian) 23.8007 Tj
+-250 TJm
+(Se) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(ard) 12.7222 Tj
+[1 0 0 1 72 678.207] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -678.207] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 668.409 Td
+/F130_0 9.9626 Tf
+(Cop) 16.6077 Tj
+10 TJm
+(yright) 23.8007 Tj
+[1 0 0 1 114.799 668.409] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -114.799 -668.409] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+114.799 668.409 Td
+/F130_0 9.9626 Tf
+(\251) 7.57158 Tj
+[1 0 0 1 122.371 668.409] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -122.371 -668.409] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+124.861 668.409 Td
+/F130_0 9.9626 Tf
+(1996-2007) 43.1679 Tj
+-250 TJm
+(Julian) 23.8007 Tj
+-250 TJm
+(Se) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(ard) 12.7222 Tj
+[1 0 0 1 72 666.252] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -7.9701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -658.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 650.875 Td
+/F130_0 7.9701 Tf
+(This) 14.1708 Tj
+-250 TJm
+(program,) 28.9952 Tj
+[1 0 0 1 119.151 650.875] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.151 -650.875] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.151 650.875 Td
+/F134_0 7.9701 Tf
+(bzip2) 23.9103 Tj
+[1 0 0 1 143.061 650.875] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.061 -650.875] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+143.061 650.875 Td
+/F130_0 7.9701 Tf
+(,) 1.99253 Tj
+-250 TJm
+(the) 9.73946 Tj
+-250 TJm
+(associated) 32.7571 Tj
+-250 TJm
+(library) 21.2483 Tj
+[1 0 0 1 216.768 650.875] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -216.768 -650.875] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+216.768 650.875 Td
+/F134_0 7.9701 Tf
+(libbzip2) 38.2565 Tj
+[1 0 0 1 255.024 650.875] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -255.024 -650.875] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+255.024 650.875 Td
+/F130_0 7.9701 Tf
+(,) 1.99253 Tj
+-250 TJm
+(and) 11.5088 Tj
+-250 TJm
+(all) 7.9701 Tj
+-250 TJm
+(documentation,) 49.3668 Tj
+-250 TJm
+(are) 9.73149 Tj
+-250 TJm
+(cop) 11.5088 Tj
+10 TJm
+(yright) 19.0406 Tj
+-250 TJm
+(\251) 6.05728 Tj
+-250 TJm
+(1996-2007) 34.5344 Tj
+-250 TJm
+(Julian) 19.0406 Tj
+-250 TJm
+(Se) 7.9701 Tj
+25 TJm
+(w) 5.75441 Tj
+10 TJm
+(ard.) 12.1703 Tj
+-310 TJm
+(All) 10.1858 Tj
+-250 TJm
+(rights) 18.1559 Tj
+-250 TJm
+(reserv) 19.471 Tj
+15 TJm
+(ed.) 9.5163 Tj
+[1 0 0 1 72 649.149] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -7.9701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -641.179] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 633.34 Td
+/F130_0 7.9701 Tf
+(Redistrib) 29.2264 Tj
+20 TJm
+(ution) 16.3865 Tj
+-250 TJm
+(and) 11.5088 Tj
+-250 TJm
+(use) 10.6241 Tj
+-250 TJm
+(in) 6.20074 Tj
+-250 TJm
+(source) 20.802 Tj
+-250 TJm
+(and) 11.5088 Tj
+-250 TJm
+(binary) 20.3636 Tj
+-250 TJm
+(forms,) 20.5868 Tj
+-250 TJm
+(with) 14.1708 Tj
+-250 TJm
+(or) 6.63909 Tj
+-250 TJm
+(without) 24.3566 Tj
+-250 TJm
+(modi\002cation,) 42.2894 Tj
+-250 TJm
+(are) 9.73149 Tj
+-250 TJm
+(permitted) 30.5494 Tj
+-250 TJm
+(pro) 10.6241 Tj
+15 TJm
+(vided) 17.7096 Tj
+-250 TJm
+(that) 11.9551 Tj
+-250 TJm
+(the) 9.73946 Tj
+-250 TJm
+(follo) 15.0555 Tj
+25 TJm
+(wing) 15.9402 Tj
+-250 TJm
+(conditions) 33.2114 Tj
+-250 TJm
+(are) 9.73149 Tj
+-250 TJm
+(met:) 14.1708 Tj
+[1 0 0 1 72 631.615] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -23.7789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 5.5791 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -77.5791 -607.836] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+77.5791 607.836 Td
+/F130_0 7.9701 Tf
+(\225) 2.78954 Tj
+[1 0 0 1 80.3686 607.836] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9926 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.594 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -83.9552 -607.836] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+83.9552 607.836 Td
+/F130_0 7.9701 Tf
+(Redistrib) 29.2264 Tj
+20 TJm
+(utions) 19.4869 Tj
+-250 TJm
+(of) 6.63909 Tj
+-250 TJm
+(source) 20.802 Tj
+-250 TJm
+(code) 15.0475 Tj
+-250 TJm
+(must) 15.5018 Tj
+-250 TJm
+(retain) 18.1479 Tj
+-250 TJm
+(the) 9.73946 Tj
+-250 TJm
+(abo) 11.5088 Tj
+15 TJm
+(v) 3.98505 Tj
+15 TJm
+(e) 3.53872 Tj
+-250 TJm
+(cop) 11.5088 Tj
+10 TJm
+(yright) 19.0406 Tj
+-250 TJm
+(notice,) 21.4714 Tj
+-250 TJm
+(this) 11.5168 Tj
+-250 TJm
+(list) 9.74743 Tj
+-250 TJm
+(of) 6.63909 Tj
+-250 TJm
+(conditions) 33.2114 Tj
+-250 TJm
+(and) 11.5088 Tj
+-250 TJm
+(the) 9.73946 Tj
+-250 TJm
+(follo) 15.0555 Tj
+25 TJm
+(wing) 15.9402 Tj
+-250 TJm
+(disclaimer) 33.2034 Tj
+55 TJm
+(.) 1.99253 Tj
+[1 0 0 1 470.908 607.836] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -398.908 -17.5343] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 5.5791 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -77.5791 -590.302] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+77.5791 590.302 Td
+/F130_0 7.9701 Tf
+(\225) 2.78954 Tj
+[1 0 0 1 80.3686 590.302] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9926 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.594 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -83.9552 -590.302] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+83.9552 590.302 Td
+/F130_0 7.9701 Tf
+(The) 12.3935 Tj
+-270 TJm
+(origin) 19.0406 Tj
+-270 TJm
+(of) 6.63909 Tj
+-270 TJm
+(this) 11.5168 Tj
+-270 TJm
+(softw) 17.7096 Tj
+10 TJm
+(are) 9.73149 Tj
+-270 TJm
+(must) 15.5018 Tj
+-270 TJm
+(not) 10.1858 Tj
+-270 TJm
+(be) 7.52377 Tj
+-270 TJm
+(misrepresented;) 50.4667 Tj
+-279 TJm
+(you) 11.9551 Tj
+-270 TJm
+(must) 15.5018 Tj
+-270 TJm
+(not) 10.1858 Tj
+-270 TJm
+(claim) 17.7096 Tj
+-270 TJm
+(that) 11.9551 Tj
+-270 TJm
+(you) 11.9551 Tj
+-270 TJm
+(wrote) 18.1479 Tj
+-270 TJm
+(the) 9.73946 Tj
+-270 TJm
+(original) 24.795 Tj
+-270 TJm
+(softw) 17.7096 Tj
+10 TJm
+(are.) 11.724 Tj
+-740 TJm
+(If) 5.30809 Tj
+-270 TJm
+(you) 11.9551 Tj
+-270 TJm
+(use) 10.6241 Tj
+-270 TJm
+(this) 11.5168 Tj
+-270 TJm
+(softw) 17.7096 Tj
+10 TJm
+(are) 9.73149 Tj
+-270 TJm
+(in) 6.20074 Tj
+-269 TJm
+(a) 3.53872 Tj
+83.9552 580.737 Td
+(product,) 26.3412 Tj
+-250 TJm
+(an) 7.52377 Tj
+-250 TJm
+(ackno) 19.0326 Tj
+25 TJm
+(wledgment) 35.4191 Tj
+-250 TJm
+(in) 6.20074 Tj
+-250 TJm
+(the) 9.73946 Tj
+-250 TJm
+(product) 24.3487 Tj
+-250 TJm
+(documentation) 47.3743 Tj
+-250 TJm
+(w) 5.75441 Tj
+10 TJm
+(ould) 14.1708 Tj
+-250 TJm
+(be) 7.52377 Tj
+-250 TJm
+(appreciated) 36.7342 Tj
+-250 TJm
+(b) 3.98505 Tj
+20 TJm
+(ut) 6.20074 Tj
+-250 TJm
+(is) 5.31606 Tj
+-250 TJm
+(not) 10.1858 Tj
+-250 TJm
+(required.) 28.5489 Tj
+[1 0 0 1 403.817 580.737] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -331.817 -17.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 5.5791 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -77.5791 -563.203] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+77.5791 563.203 Td
+/F130_0 7.9701 Tf
+(\225) 2.78954 Tj
+[1 0 0 1 80.3686 563.203] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9926 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.594 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -83.9552 -563.203] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+83.9552 563.203 Td
+/F130_0 7.9701 Tf
+(Altered) 23.9023 Tj
+-250 TJm
+(source) 20.802 Tj
+-250 TJm
+(v) 3.98505 Tj
+15 TJm
+(ersions) 22.5793 Tj
+-250 TJm
+(must) 15.5018 Tj
+-250 TJm
+(be) 7.52377 Tj
+-250 TJm
+(plainly) 22.1409 Tj
+-250 TJm
+(mark) 16.3786 Tj
+10 TJm
+(ed) 7.52377 Tj
+-250 TJm
+(as) 6.63909 Tj
+-250 TJm
+(such,) 16.6017 Tj
+-250 TJm
+(and) 11.5088 Tj
+-250 TJm
+(must) 15.5018 Tj
+-250 TJm
+(not) 10.1858 Tj
+-250 TJm
+(be) 7.52377 Tj
+-250 TJm
+(misrepresented) 48.251 Tj
+-250 TJm
+(as) 6.63909 Tj
+-250 TJm
+(being) 17.7096 Tj
+-250 TJm
+(the) 9.73946 Tj
+-250 TJm
+(original) 24.795 Tj
+-250 TJm
+(softw) 17.7096 Tj
+10 TJm
+(are.) 11.724 Tj
+[1 0 0 1 464.405 563.203] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -392.405 -17.5343] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 5.5791 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -77.5791 -545.669] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+77.5791 545.669 Td
+/F130_0 7.9701 Tf
+(\225) 2.78954 Tj
+[1 0 0 1 80.3686 545.669] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9926 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.594 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -83.9552 -545.669] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+83.9552 545.669 Td
+/F130_0 7.9701 Tf
+(The) 12.3935 Tj
+-250 TJm
+(name) 17.2632 Tj
+-250 TJm
+(of) 6.63909 Tj
+-250 TJm
+(the) 9.73946 Tj
+-250 TJm
+(author) 20.3636 Tj
+-250 TJm
+(may) 13.7245 Tj
+-250 TJm
+(not) 10.1858 Tj
+-250 TJm
+(be) 7.52377 Tj
+-250 TJm
+(used) 14.6092 Tj
+-250 TJm
+(to) 6.20074 Tj
+-250 TJm
+(endorse) 24.787 Tj
+-250 TJm
+(or) 6.63909 Tj
+-250 TJm
+(promote) 26.5643 Tj
+-250 TJm
+(products) 27.449 Tj
+-250 TJm
+(deri) 12.3935 Tj
+25 TJm
+(v) 3.98505 Tj
+15 TJm
+(ed) 7.52377 Tj
+-250 TJm
+(from) 15.4939 Tj
+-250 TJm
+(this) 11.5168 Tj
+-250 TJm
+(softw) 17.7096 Tj
+10 TJm
+(are) 9.73149 Tj
+-250 TJm
+(without) 24.3566 Tj
+-250 TJm
+(speci\002c) 24.3487 Tj
+-250 TJm
+(prior) 15.4939 Tj
+-250 TJm
+(written) 22.5793 Tj
+-250 TJm
+(permission.) 36.9733 Tj
+[1 0 0 1 533.577 545.669] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -461.577 -9.6956] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -535.973] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 528.135 Td
+/F130_0 7.9701 Tf
+(THIS) 17.7096 Tj
+-401 TJm
+(SOFTW) 27.0107 Tj
+120 TJm
+(ARE) 15.9402 Tj
+-401 TJm
+(IS) 7.08542 Tj
+-400 TJm
+(PR) 9.74743 Tj
+40 TJm
+(O) 5.75441 Tj
+50 TJm
+(VIDED) 24.787 Tj
+-401 TJm
+(BY) 11.0705 Tj
+-401 TJm
+(THE) 15.4939 Tj
+-401 TJm
+(A) 5.75441 Tj
+55 TJm
+(UTHOR) 27.449 Tj
+-401 TJm
+("AS) 13.4376 Tj
+-401 TJm
+(IS") 10.3372 Tj
+-401 TJm
+(AND) 17.2632 Tj
+-400 TJm
+(ANY) 17.2632 Tj
+-401 TJm
+(EXPRESS) 34.1041 Tj
+-401 TJm
+(OR) 11.0705 Tj
+-401 TJm
+(IMPLIED) 32.3188 Tj
+-401 TJm
+(W) 7.52377 Tj
+120 TJm
+(ARRANTIES,) 46.7128 Tj
+-401 TJm
+(INCLUDING,) 46.2585 Tj
+-400 TJm
+(B) 5.31606 Tj
+10 TJm
+(UT) 10.6241 Tj
+72 518.571 Td
+(NO) 11.5088 Tj
+40 TJm
+(T) 4.86973 Tj
+-304 TJm
+(LIMITED) 32.7571 Tj
+-304 TJm
+(T) 4.86973 Tj
+18 TJm
+(O,) 7.74694 Tj
+-305 TJm
+(THE) 15.4939 Tj
+-304 TJm
+(IMPLIED) 32.3188 Tj
+-304 TJm
+(W) 7.52377 Tj
+120 TJm
+(ARRANTIES) 44.7202 Tj
+-304 TJm
+(OF) 10.1858 Tj
+-304 TJm
+(MERCHANT) 44.7202 Tj
+93 TJm
+(ABILITY) 31.8724 Tj
+-304 TJm
+(AND) 17.2632 Tj
+-305 TJm
+(FITNESS) 31.442 Tj
+-304 TJm
+(FOR) 15.5018 Tj
+-304 TJm
+(A) 5.75441 Tj
+-304 TJm
+(P) 4.43138 Tj
+92 TJm
+(AR) 11.0705 Tj
+60 TJm
+(TICULAR) 34.5344 Tj
+-304 TJm
+(PURPOSE) 34.9887 Tj
+-304 TJm
+(ARE) 15.9402 Tj
+-305 TJm
+(DI) 8.40846 Tj
+1 TJm
+(S-) 7.08542 Tj
+72 509.006 Td
+(CLAIMED.) 38.2963 Tj
+-576 TJm
+(IN) 8.40846 Tj
+-287 TJm
+(NO) 11.5088 Tj
+-288 TJm
+(EVENT) 26.118 Tj
+-288 TJm
+(SHALL) 25.6797 Tj
+-288 TJm
+(THE) 15.4939 Tj
+-287 TJm
+(A) 5.75441 Tj
+55 TJm
+(UTHOR) 27.449 Tj
+-288 TJm
+(BE) 10.1858 Tj
+-288 TJm
+(LIABLE) 28.3337 Tj
+-288 TJm
+(FOR) 15.5018 Tj
+-288 TJm
+(ANY) 17.2632 Tj
+-287 TJm
+(DIRECT) 28.78 Tj
+74 TJm
+(,) 1.99253 Tj
+-288 TJm
+(INDIRECT) 37.1885 Tj
+74 TJm
+(,) 1.99253 Tj
+-288 TJm
+(INCIDENT) 37.6268 Tj
+93 TJm
+(AL,) 12.6167 Tj
+-288 TJm
+(SPECIAL,) 34.3193 Tj
+-288 TJm
+(EXEMPLAR) 42.9509 Tj
+65 TJm
+(Y) 5.75441 Tj
+129 TJm
+(,) 1.99253 Tj
+72 499.442 Td
+(OR) 11.0705 Tj
+-299 TJm
+(CONSEQ) 31.8804 Tj
+10 TJm
+(UENTIAL) 34.5265 Tj
+-300 TJm
+(D) 5.75441 Tj
+40 TJm
+(AMA) 18.5942 Tj
+40 TJm
+(GES) 15.0555 Tj
+-299 TJm
+(\(INCLUDING,) 48.9125 Tj
+-299 TJm
+(B) 5.31606 Tj
+10 TJm
+(UT) 10.6241 Tj
+-299 TJm
+(NO) 11.5088 Tj
+40 TJm
+(T) 4.86973 Tj
+-300 TJm
+(LIMITED) 32.7571 Tj
+-299 TJm
+(T) 4.86973 Tj
+18 TJm
+(O,) 7.74694 Tj
+-299 TJm
+(PR) 9.74743 Tj
+40 TJm
+(OCUREMENT) 49.59 Tj
+-299 TJm
+(OF) 10.1858 Tj
+-300 TJm
+(SUBSTITUTE) 47.8206 Tj
+-299 TJm
+(GOODS) 27.449 Tj
+-299 TJm
+(OR) 11.0705 Tj
+-300 TJm
+(SER) 14.6172 Tj
+80 TJm
+(VICES) 23.0256 Tj
+1 TJm
+(;) 2.21569 Tj
+72 489.878 Td
+(LOSS) 19.4869 Tj
+-360 TJm
+(OF) 10.1858 Tj
+-360 TJm
+(USE,) 17.048 Tj
+-360 TJm
+(D) 5.75441 Tj
+40 TJm
+(A) 5.75441 Tj
+111 TJm
+(T) 4.86973 Tj
+93 TJm
+(A,) 7.74694 Tj
+-360 TJm
+(OR) 11.0705 Tj
+-359 TJm
+(PR) 9.74743 Tj
+40 TJm
+(OFITS;) 24.3566 Tj
+-360 TJm
+(OR) 11.0705 Tj
+-360 TJm
+(B) 5.31606 Tj
+10 TJm
+(USINESS) 32.3267 Tj
+-360 TJm
+(INTERR) 28.78 Tj
+40 TJm
+(UPTION\)) 31.8724 Tj
+-360 TJm
+(HO) 11.5088 Tj
+35 TJm
+(WEVER) 28.3337 Tj
+-360 TJm
+(CA) 11.0705 Tj
+55 TJm
+(USED) 20.8099 Tj
+-359 TJm
+(AND) 17.2632 Tj
+-360 TJm
+(ON) 11.5088 Tj
+-360 TJm
+(ANY) 17.2632 Tj
+-360 TJm
+(THEOR) 26.5643 Tj
+65 TJm
+(Y) 5.75441 Tj
+-360 TJm
+(OF) 10.1858 Tj
+-360 TJm
+(LIAB) 18.5942 Tj
+1 TJm
+(ILITY) 20.802 Tj
+128 TJm
+(,) 1.99253 Tj
+72 480.314 Td
+(WHETHER) 38.9578 Tj
+-247 TJm
+(IN) 8.40846 Tj
+-247 TJm
+(CONTRA) 32.7651 Tj
+40 TJm
+(CT) 10.1858 Tj
+74 TJm
+(,) 1.99253 Tj
+-247 TJm
+(STRICT) 27.457 Tj
+-247 TJm
+(LIABILITY) 39.3962 Tj
+129 TJm
+(,) 1.99253 Tj
+-246 TJm
+(OR) 11.0705 Tj
+-247 TJm
+(T) 4.86973 Tj
+18 TJm
+(OR) 11.0705 Tj
+60 TJm
+(T) 4.86973 Tj
+-247 TJm
+(\(INCLUDING) 46.92 Tj
+-247 TJm
+(NEGLIGENCE) 50.4667 Tj
+-247 TJm
+(OR) 11.0705 Tj
+-247 TJm
+(O) 5.75441 Tj
+40 TJm
+(THER) 20.8099 Tj
+55 TJm
+(WISE\)) 22.133 Tj
+-247 TJm
+(ARISING) 32.3188 Tj
+-247 TJm
+(IN) 8.40846 Tj
+-247 TJm
+(ANY) 17.2632 Tj
+-247 TJm
+(W) 7.52377 Tj
+120 TJm
+(A) 5.75441 Tj
+105 TJm
+(Y) 5.75441 Tj
+-247 TJm
+(OUT) 16.3786 Tj
+72 470.75 Td
+(OF) 10.1858 Tj
+-250 TJm
+(THE) 15.4939 Tj
+-250 TJm
+(USE) 15.0555 Tj
+-250 TJm
+(OF) 10.1858 Tj
+-250 TJm
+(THIS) 17.7096 Tj
+-250 TJm
+(SOFTW) 27.0107 Tj
+120 TJm
+(ARE,) 17.9327 Tj
+-250 TJm
+(EVEN) 21.2483 Tj
+-250 TJm
+(IF) 7.08542 Tj
+-250 TJm
+(AD) 11.5088 Tj
+40 TJm
+(VISED) 23.464 Tj
+-250 TJm
+(OF) 10.1858 Tj
+-250 TJm
+(THE) 15.4939 Tj
+-250 TJm
+(POSSIBILITY) 47.8206 Tj
+-250 TJm
+(OF) 10.1858 Tj
+-250 TJm
+(SUCH) 21.2563 Tj
+-250 TJm
+(D) 5.75441 Tj
+40 TJm
+(AMA) 18.5942 Tj
+40 TJm
+(GE.) 12.6167 Tj
+[1 0 0 1 72 469.598] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -7.9701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -461.628] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 453.216 Td
+/F130_0 7.9701 Tf
+(P) 4.43138 Tj
+92 TJm
+(A) 5.75441 Tj
+111 TJm
+(TENTS:) 27.0107 Tj
+-296 TJm
+(T) 4.86973 Tj
+80 TJm
+(o) 3.98505 Tj
+-295 TJm
+(the) 9.73946 Tj
+-296 TJm
+(best) 12.8398 Tj
+-295 TJm
+(of) 6.63909 Tj
+-296 TJm
+(my) 10.1858 Tj
+-295 TJm
+(kno) 11.9551 Tj
+25 TJm
+(wledge,) 25.0102 Tj
+[1 0 0 1 208.544 453.216] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -208.544 -453.216] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+208.544 453.216 Td
+/F134_0 7.9701 Tf
+(bzip2) 23.9103 Tj
+[1 0 0 1 232.454 453.216] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -232.454 -453.216] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+234.81 453.216 Td
+/F130_0 7.9701 Tf
+(and) 11.5088 Tj
+[1 0 0 1 248.674 453.216] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -248.674 -453.216] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+248.674 453.216 Td
+/F134_0 7.9701 Tf
+(libbzip2) 38.2565 Tj
+[1 0 0 1 286.931 453.216] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -286.931 -453.216] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+289.286 453.216 Td
+/F130_0 7.9701 Tf
+(do) 7.9701 Tj
+-296 TJm
+(not) 10.1858 Tj
+-295 TJm
+(use) 10.6241 Tj
+-296 TJm
+(an) 7.52377 Tj
+15 TJm
+(y) 3.98505 Tj
+-295 TJm
+(patented) 27.0027 Tj
+-296 TJm
+(algorithms.) 36.0886 Tj
+-893 TJm
+(Ho) 9.73946 Tj
+25 TJm
+(we) 9.29314 Tj
+25 TJm
+(v) 3.98505 Tj
+15 TJm
+(er) 6.19277 Tj
+40 TJm
+(,) 1.99253 Tj
+-307 TJm
+(I) 2.65404 Tj
+-295 TJm
+(do) 7.9701 Tj
+-296 TJm
+(not) 10.1858 Tj
+-295 TJm
+(ha) 7.52377 Tj
+20 TJm
+(v) 3.98505 Tj
+15 TJm
+(e) 3.53872 Tj
+-296 TJm
+(the) 9.73946 Tj
+-295 TJm
+(resources) 30.0951 Tj
+-296 TJm
+(to) 6.20074 Tj
+72 443.652 Td
+(carry) 16.3706 Tj
+-250 TJm
+(out) 10.1858 Tj
+-250 TJm
+(a) 3.53872 Tj
+-250 TJm
+(patent) 19.4789 Tj
+-250 TJm
+(search.) 22.3482 Tj
+-620 TJm
+(Therefore) 31.4181 Tj
+-250 TJm
+(I) 2.65404 Tj
+-250 TJm
+(cannot) 21.2483 Tj
+-250 TJm
+(gi) 6.20074 Tj
+25 TJm
+(v) 3.98505 Tj
+15 TJm
+(e) 3.53872 Tj
+-250 TJm
+(an) 7.52377 Tj
+15 TJm
+(y) 3.98505 Tj
+-250 TJm
+(guarantee) 30.9798 Tj
+-250 TJm
+(of) 6.63909 Tj
+-250 TJm
+(the) 9.73946 Tj
+-250 TJm
+(abo) 11.5088 Tj
+15 TJm
+(v) 3.98505 Tj
+15 TJm
+(e) 3.53872 Tj
+-250 TJm
+(statement.) 32.5419 Tj
+[1 0 0 1 72 441.926] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -391.074] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 46.7993 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -46.7993 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5986 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 3 3
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -13.9477] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 707.441 Td
+/F122_0 17.2154 Tf
+(T) 10.5186 Tj
+80 TJm
+(ab) 20.0904 Tj
+10 TJm
+(le) 14.3576 Tj
+-278 TJm
+(of) 16.2513 Tj
+-278 TJm
+(Contents) 74.5943 Tj
+[1 0 0 1 72 698.619] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.7401] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -686.879] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 686.879 Td
+/F130_0 9.9626 Tf
+(1.) 7.47195 Tj
+-310 TJm
+(Introduction) 49.2551 Tj
+[1 0 0 1 131.815 686.879] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -136.796 -686.879] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+145.733 686.879 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 686.879] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -686.879] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 686.879 Td
+/F130_0 9.9626 Tf
+(1) 4.9813 Tj
+[1 0 0 1 516.09 686.879] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -674.923] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 674.923 Td
+/F130_0 9.9626 Tf
+(2.) 7.47195 Tj
+-310 TJm
+(Ho) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+[1 0 0 1 152.318 674.923] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -157.3 -674.923] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+167.054 674.923 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 674.923] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -674.923] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 674.923 Td
+/F130_0 9.9626 Tf
+(2) 4.9813 Tj
+[1 0 0 1 516.09 674.923] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -662.968] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 662.968 Td
+/F130_0 9.9626 Tf
+(2.1.) 14.9439 Tj
+-310 TJm
+(N) 7.193 Tj
+35 TJm
+(AME) 22.1369 Tj
+[1 0 0 1 119.014 662.968] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -123.995 -662.968] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+132.691 662.968 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 662.968] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -662.968] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 662.968 Td
+/F130_0 9.9626 Tf
+(2) 4.9813 Tj
+[1 0 0 1 516.09 662.968] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -651.013] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 651.013 Td
+/F130_0 9.9626 Tf
+(2.2.) 14.9439 Tj
+-310 TJm
+(SYNOPSIS) 47.0534 Tj
+[1 0 0 1 137.085 651.013] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -142.067 -651.013] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+150.582 651.013 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 651.013] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -651.013] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 651.013 Td
+/F130_0 9.9626 Tf
+(2) 4.9813 Tj
+[1 0 0 1 516.09 651.013] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -639.058] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 639.058 Td
+/F130_0 9.9626 Tf
+(2.3.) 14.9439 Tj
+-310 TJm
+(DESCRIPTION) 64.7569 Tj
+[1 0 0 1 154.789 639.058] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -159.77 -639.058] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+168.29 639.058 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 639.058] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -639.058] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 639.058 Td
+/F130_0 9.9626 Tf
+(3) 4.9813 Tj
+[1 0 0 1 516.09 639.058] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8557] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -627.103] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 627.103 Td
+/F130_0 9.9626 Tf
+(2.4.) 14.9439 Tj
+-310 TJm
+(OPTIONS) 42.0621 Tj
+[1 0 0 1 132.094 627.103] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.076 -627.103] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+145.873 627.103 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 627.103] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -627.103] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 627.103 Td
+/F130_0 9.9626 Tf
+(4) 4.9813 Tj
+[1 0 0 1 516.09 627.103] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -615.147] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 615.147 Td
+/F130_0 9.9626 Tf
+(2.5.) 14.9439 Tj
+-310 TJm
+(MEMOR) 37.6387 Tj
+65 TJm
+(Y) 7.193 Tj
+-250 TJm
+(MAN) 23.2427 Tj
+35 TJm
+(A) 7.193 Tj
+40 TJm
+(GEMENT) 41.5042 Tj
+[1 0 0 1 207.9 615.147] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -212.881 -615.147] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+221.412 615.147 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 615.147] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -615.147] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 615.147 Td
+/F130_0 9.9626 Tf
+(5) 4.9813 Tj
+[1 0 0 1 516.09 615.147] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -603.192] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 603.192 Td
+/F130_0 9.9626 Tf
+(2.6.) 14.9439 Tj
+-310 TJm
+(RECO) 26.5703 Tj
+50 TJm
+(VERING) 37.6287 Tj
+-250 TJm
+(D) 7.193 Tj
+40 TJm
+(A) 7.193 Tj
+111 TJm
+(T) 6.08715 Tj
+93 TJm
+(A) 7.193 Tj
+-250 TJm
+(FR) 12.1843 Tj
+40 TJm
+(OM) 16.0497 Tj
+-250 TJm
+(D) 7.193 Tj
+40 TJm
+(AMA) 23.2427 Tj
+40 TJm
+(GED) 20.4731 Tj
+-250 TJm
+(FILES) 26.5703 Tj
+[1 0 0 1 293.449 603.192] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -298.43 -603.192] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+308.464 603.192 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 603.192] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -603.192] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 603.192 Td
+/F130_0 9.9626 Tf
+(6) 4.9813 Tj
+[1 0 0 1 516.09 603.192] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8557] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -591.237] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 591.237 Td
+/F130_0 9.9626 Tf
+(2.7.) 14.9439 Tj
+-310 TJm
+(PERFORMANCE) 73.6236 Tj
+-250 TJm
+(NO) 14.386 Tj
+40 TJm
+(TES) 17.7135 Tj
+[1 0 0 1 197.847 591.237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -202.829 -591.237] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+211.958 591.237 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 591.237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -591.237] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 591.237 Td
+/F130_0 9.9626 Tf
+(6) 4.9813 Tj
+[1 0 0 1 516.09 591.237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8557] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -579.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 579.282 Td
+/F130_0 9.9626 Tf
+(2.8.) 14.9439 Tj
+-310 TJm
+(CA) 13.8381 Tj
+135 TJm
+(VEA) 20.4731 Tj
+111 TJm
+(TS) 11.6264 Tj
+[1 0 0 1 133.519 579.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -138.5 -579.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+148.799 579.282 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 579.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -579.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 579.282 Td
+/F130_0 9.9626 Tf
+(7) 4.9813 Tj
+[1 0 0 1 516.09 579.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -567.327] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 567.327 Td
+/F130_0 9.9626 Tf
+(2.9.) 14.9439 Tj
+-310 TJm
+(A) 7.193 Tj
+55 TJm
+(UTHOR) 34.3112 Tj
+[1 0 0 1 130.989 567.327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -135.97 -567.327] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+145.32 567.327 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 567.327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -567.327] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 567.327 Td
+/F130_0 9.9626 Tf
+(7) 4.9813 Tj
+[1 0 0 1 516.09 567.327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.2192] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.736] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -555.372] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 555.372 Td
+/F130_0 9.9626 Tf
+(3.) 7.47195 Tj
+-310 TJm
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 160.049 555.372] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -160.049 -555.372] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+160.049 555.372 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 207.87 555.372] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -215.342 -555.372] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+224.856 555.372 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 555.372] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -555.372] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 555.372 Td
+/F130_0 9.9626 Tf
+(8) 4.9813 Tj
+[1 0 0 1 516.09 555.372] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -543.416] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 543.416 Td
+/F130_0 9.9626 Tf
+(3.1.) 14.9439 Tj
+-310 TJm
+(T) 6.08715 Tj
+80 TJm
+(op-le) 20.4731 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(structure) 34.8591 Tj
+[1 0 0 1 164.921 543.416] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.902 -543.416] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+179.997 543.416 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 543.416] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -543.416] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 543.416 Td
+/F130_0 9.9626 Tf
+(8) 4.9813 Tj
+[1 0 0 1 516.09 543.416] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -531.461] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 531.461 Td
+/F130_0 9.9626 Tf
+(3.1.1.) 22.4159 Tj
+-310 TJm
+(Lo) 11.0684 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(summary) 37.0808 Tj
+[1 0 0 1 177.374 531.461] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -182.355 -531.461] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+192.866 531.461 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 531.461] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -531.461] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 531.461 Td
+/F130_0 9.9626 Tf
+(9) 4.9813 Tj
+[1 0 0 1 516.09 531.461] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -519.506] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 519.506 Td
+/F130_0 9.9626 Tf
+(3.1.2.) 22.4159 Tj
+-310 TJm
+(High-le) 30.4357 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(summary) 37.0808 Tj
+[1 0 0 1 179.287 519.506] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -184.268 -519.506] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+193.822 519.506 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 519.506] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -519.506] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 519.506 Td
+/F130_0 9.9626 Tf
+(9) 4.9813 Tj
+[1 0 0 1 516.09 519.506] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -507.551] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 507.551 Td
+/F130_0 9.9626 Tf
+(3.1.3.) 22.4159 Tj
+-310 TJm
+(Utility) 26.0223 Tj
+-250 TJm
+(functions) 37.0808 Tj
+-250 TJm
+(summary) 37.0808 Tj
+[1 0 0 1 202.669 507.551] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -207.65 -507.551] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+216.582 507.551 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 507.551] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -507.551] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 507.551 Td
+/F130_0 9.9626 Tf
+(9) 4.9813 Tj
+[1 0 0 1 516.09 507.551] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -495.596] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 495.596 Td
+/F130_0 9.9626 Tf
+(3.2.) 14.9439 Tj
+-310 TJm
+(Error) 21.0211 Tj
+-250 TJm
+(handling) 34.8691 Tj
+[1 0 0 1 148.413 495.596] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -153.394 -495.596] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+162.611 495.596 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 495.596] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -495.596] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 495.596 Td
+/F130_0 9.9626 Tf
+(10) 9.9626 Tj
+[1 0 0 1 516.09 495.596] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -483.641] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 483.641 Td
+/F130_0 9.9626 Tf
+(3.3.) 14.9439 Tj
+-310 TJm
+(Lo) 11.0684 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+[1 0 0 1 167.571 483.641] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -172.552 -483.641] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+181.045 483.641 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 483.641] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -483.641] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 483.641 Td
+/F130_0 9.9626 Tf
+(11) 9.9626 Tj
+[1 0 0 1 516.09 483.641] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8557] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -471.685] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 471.685 Td
+/F130_0 9.9626 Tf
+(3.3.1.) 22.4159 Tj
+[1 0 0 1 97.5043 471.685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -471.685] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 471.685 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 205.101 471.685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.082 -471.685] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+219.736 471.685 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 471.685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -471.685] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 471.685 Td
+/F130_0 9.9626 Tf
+(11) 9.9626 Tj
+[1 0 0 1 516.09 471.685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -459.73] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 459.73 Td
+/F130_0 9.9626 Tf
+(3.3.2.) 22.4159 Tj
+[1 0 0 1 97.5043 459.73] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -459.73] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 459.73 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 181.19 459.73] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -186.172 -459.73] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+194.497 459.73 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 459.73] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -459.73] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 459.73 Td
+/F130_0 9.9626 Tf
+(13) 9.9626 Tj
+[1 0 0 1 516.09 459.73] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -447.775] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 447.775 Td
+/F130_0 9.9626 Tf
+(3.3.3.) 22.4159 Tj
+[1 0 0 1 97.5043 447.775] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -447.775] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 447.775 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressEnd) 101.619 Tj
+[1 0 0 1 199.123 447.775] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.105 -447.775] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+214.533 447.775 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 447.775] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -447.775] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 447.775 Td
+/F130_0 9.9626 Tf
+(16) 9.9626 Tj
+[1 0 0 1 516.09 447.775] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -435.82] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 435.82 Td
+/F130_0 9.9626 Tf
+(3.3.4.) 22.4159 Tj
+[1 0 0 1 97.5043 435.82] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -435.82] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 435.82 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressInit) 119.551 Tj
+[1 0 0 1 217.056 435.82] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -222.037 -435.82] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+232.355 435.82 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 435.82] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -435.82] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 435.82 Td
+/F130_0 9.9626 Tf
+(16) 9.9626 Tj
+[1 0 0 1 516.09 435.82] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -423.865] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 423.865 Td
+/F130_0 9.9626 Tf
+(3.3.5.) 22.4159 Tj
+[1 0 0 1 97.5043 423.865] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -423.865] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 423.865 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 193.146 423.865] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -198.127 -423.865] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+207.116 423.865 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 423.865] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -423.865] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 423.865 Td
+/F130_0 9.9626 Tf
+(17) 9.9626 Tj
+[1 0 0 1 516.09 423.865] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -411.91] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 411.91 Td
+/F130_0 9.9626 Tf
+(3.3.6.) 22.4159 Tj
+[1 0 0 1 97.5043 411.91] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -411.91] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 411.91 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressEnd) 113.574 Tj
+[1 0 0 1 211.078 411.91] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -216.06 -411.91] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+224.938 411.91 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 411.91] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -411.91] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 411.91 Td
+/F130_0 9.9626 Tf
+(18) 9.9626 Tj
+[1 0 0 1 516.09 411.91] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -399.954] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 399.954 Td
+/F130_0 9.9626 Tf
+(3.4.) 14.9439 Tj
+-310 TJm
+(High-le) 30.4357 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+[1 0 0 1 169.483 399.954] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -174.465 -399.954] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+184.216 399.954 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 399.954] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -399.954] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 399.954 Td
+/F130_0 9.9626 Tf
+(18) 9.9626 Tj
+[1 0 0 1 516.09 399.954] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -387.999] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 387.999 Td
+/F130_0 9.9626 Tf
+(3.4.1.) 22.4159 Tj
+[1 0 0 1 97.5043 387.999] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -387.999] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 387.999 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadOpen) 83.6858 Tj
+[1 0 0 1 181.19 387.999] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -186.172 -387.999] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+194.497 387.999 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 387.999] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -387.999] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 387.999 Td
+/F130_0 9.9626 Tf
+(19) 9.9626 Tj
+[1 0 0 1 516.09 387.999] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -376.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 376.044 Td
+/F130_0 9.9626 Tf
+(3.4.2.) 22.4159 Tj
+[1 0 0 1 97.5043 376.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -376.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 376.044 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 157.28 376.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -162.261 -376.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+171.472 376.044 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 376.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -376.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 376.044 Td
+/F130_0 9.9626 Tf
+(20) 9.9626 Tj
+[1 0 0 1 516.09 376.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6452] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -364.089] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 364.089 Td
+/F130_0 9.9626 Tf
+(3.4.3.) 22.4159 Tj
+[1 0 0 1 97.5043 364.089] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -364.089] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 364.089 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadGetUnused) 113.574 Tj
+[1 0 0 1 211.078 364.089] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -216.06 -364.089] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+224.938 364.089 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 364.089] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -364.089] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 364.089 Td
+/F130_0 9.9626 Tf
+(21) 9.9626 Tj
+[1 0 0 1 516.09 364.089] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6452] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -352.134] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 352.134 Td
+/F130_0 9.9626 Tf
+(3.4.4.) 22.4159 Tj
+[1 0 0 1 97.5043 352.134] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -352.134] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 352.134 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 187.168 352.134] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -192.149 -352.134] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+201.914 352.134 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 352.134] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -352.134] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 352.134 Td
+/F130_0 9.9626 Tf
+(22) 9.9626 Tj
+[1 0 0 1 516.09 352.134] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6451] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -340.179] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 340.179 Td
+/F130_0 9.9626 Tf
+(3.4.5.) 22.4159 Tj
+[1 0 0 1 97.5043 340.179] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -340.179] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 340.179 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteOpen) 89.6634 Tj
+[1 0 0 1 187.168 340.179] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -192.149 -340.179] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+201.914 340.179 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 340.179] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -340.179] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 340.179 Td
+/F130_0 9.9626 Tf
+(22) 9.9626 Tj
+[1 0 0 1 516.09 340.179] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -328.223] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 328.223 Td
+/F130_0 9.9626 Tf
+(3.4.6.) 22.4159 Tj
+[1 0 0 1 97.5043 328.223] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -328.223] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 328.223 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWrite) 65.7532 Tj
+[1 0 0 1 163.258 328.223] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -168.239 -328.223] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+176.675 328.223 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 328.223] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -328.223] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 328.223 Td
+/F130_0 9.9626 Tf
+(23) 9.9626 Tj
+[1 0 0 1 516.09 328.223] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6452] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -316.268] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 316.268 Td
+/F130_0 9.9626 Tf
+(3.4.7.) 22.4159 Tj
+[1 0 0 1 97.5043 316.268] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -316.268] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 316.268 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteClose) 95.641 Tj
+[1 0 0 1 193.146 316.268] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -198.127 -316.268] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+207.116 316.268 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 316.268] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -316.268] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 316.268 Td
+/F130_0 9.9626 Tf
+(23) 9.9626 Tj
+[1 0 0 1 516.09 316.268] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6451] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -304.313] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 304.313 Td
+/F130_0 9.9626 Tf
+(3.4.8.) 22.4159 Tj
+-310 TJm
+(Handling) 37.0808 Tj
+-250 TJm
+(embedded) 40.9463 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(streams) 30.4357 Tj
+[1 0 0 1 279.56 304.313] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -284.541 -304.313] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+294.601 304.313 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 304.313] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -304.313] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 304.313 Td
+/F130_0 9.9626 Tf
+(24) 9.9626 Tj
+[1 0 0 1 516.09 304.313] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -292.358] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 292.358 Td
+/F130_0 9.9626 Tf
+(3.4.9.) 22.4159 Tj
+-310 TJm
+(Standard) 35.417 Tj
+-250 TJm
+(\002le-reading/writing) 77.4791 Tj
+-250 TJm
+(code) 18.8094 Tj
+[1 0 0 1 234.19 292.358] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -239.172 -292.358] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+247.564 292.358 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 292.358] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -292.358] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 292.358 Td
+/F130_0 9.9626 Tf
+(25) 9.9626 Tj
+[1 0 0 1 516.09 292.358] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -280.403] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 280.403 Td
+/F130_0 9.9626 Tf
+(3.5.) 14.9439 Tj
+-310 TJm
+(Utility) 26.0223 Tj
+-250 TJm
+(functions) 37.0808 Tj
+[1 0 0 1 155.625 280.403] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -160.607 -280.403] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+170.645 280.403 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 280.403] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -280.403] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 280.403 Td
+/F130_0 9.9626 Tf
+(26) 9.9626 Tj
+[1 0 0 1 516.09 280.403] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -268.448] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 268.448 Td
+/F130_0 9.9626 Tf
+(3.5.1.) 22.4159 Tj
+[1 0 0 1 97.5043 268.448] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -268.448] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 268.448 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffCompress) 143.461 Tj
+[1 0 0 1 240.966 268.448] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -245.948 -268.448] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+255.38 268.448 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 268.448] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -268.448] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 268.448 Td
+/F130_0 9.9626 Tf
+(26) 9.9626 Tj
+[1 0 0 1 516.09 268.448] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -256.492] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 256.492 Td
+/F130_0 9.9626 Tf
+(3.5.2.) 22.4159 Tj
+[1 0 0 1 97.5043 256.492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -256.492] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 256.492 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffDecompress) 155.417 Tj
+[1 0 0 1 252.922 256.492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -257.903 -256.492] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+267.999 256.492 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 256.492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -256.492] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 256.492 Td
+/F130_0 9.9626 Tf
+(27) 9.9626 Tj
+[1 0 0 1 516.09 256.492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -244.537] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 244.537 Td
+/F130_0 9.9626 Tf
+(3.6.) 14.9439 Tj
+[1 0 0 1 90.0324 244.537] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90.0324 -244.537] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90.0324 244.537 Td
+/F134_0 9.9626 Tf
+(zlib) 23.9102 Tj
+[1 0 0 1 113.943 244.537] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.943 -244.537] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+116.433 244.537 Td
+/F130_0 9.9626 Tf
+(compatibility) 53.1405 Tj
+-250 TJm
+(functions) 37.0808 Tj
+[1 0 0 1 209.144 244.537] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -214.126 -244.537] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+223.971 244.537 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 244.537] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -244.537] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 244.537 Td
+/F130_0 9.9626 Tf
+(28) 9.9626 Tj
+[1 0 0 1 516.09 244.537] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -232.582] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 232.582 Td
+/F130_0 9.9626 Tf
+(3.7.) 14.9439 Tj
+-310 TJm
+(Using) 23.8007 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(library) 26.5603 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(a) 4.42339 Tj
+[1 0 0 1 177.195 232.582] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -177.195 -232.582] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+177.195 232.582 Td
+/F134_0 9.9626 Tf
+(stdio) 29.8878 Tj
+[1 0 0 1 207.083 232.582] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -207.083 -232.582] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+207.083 232.582 Td
+/F130_0 9.9626 Tf
+(-free) 18.7994 Tj
+-250 TJm
+(en) 9.40469 Tj
+40 TJm
+(vironment) 40.9562 Tj
+[1 0 0 1 278.335 232.582] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -283.316 -232.582] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+291.775 232.582 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 232.582] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -232.582] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 232.582 Td
+/F130_0 9.9626 Tf
+(28) 9.9626 Tj
+[1 0 0 1 516.09 232.582] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -220.627] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 220.627 Td
+/F130_0 9.9626 Tf
+(3.7.1.) 22.4159 Tj
+-310 TJm
+(Getting) 29.8878 Tj
+-250 TJm
+(rid) 11.0684 Tj
+-250 TJm
+(of) 8.29885 Tj
+[1 0 0 1 154.231 220.627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -154.231 -220.627] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+154.231 220.627 Td
+/F134_0 9.9626 Tf
+(stdio) 29.8878 Tj
+[1 0 0 1 184.119 220.627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -189.1 -220.627] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+198.175 220.627 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 220.627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -220.627] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 220.627 Td
+/F130_0 9.9626 Tf
+(29) 9.9626 Tj
+[1 0 0 1 516.09 220.627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -208.672] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 208.672 Td
+/F130_0 9.9626 Tf
+(3.7.2.) 22.4159 Tj
+-310 TJm
+(Critical) 29.8878 Tj
+-250 TJm
+(error) 19.3573 Tj
+-250 TJm
+(handling) 34.8691 Tj
+[1 0 0 1 186.599 208.672] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -191.58 -208.672] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+201.629 208.672 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 208.672] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -208.672] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 208.672 Td
+/F130_0 9.9626 Tf
+(29) 9.9626 Tj
+[1 0 0 1 516.09 208.672] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -196.717] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 196.717 Td
+/F130_0 9.9626 Tf
+(3.8.) 14.9439 Tj
+-310 TJm
+(Making) 30.9936 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(W) 9.40469 Tj
+40 TJm
+(indo) 17.7135 Tj
+25 TJm
+(ws) 11.0684 Tj
+-250 TJm
+(DLL) 19.3673 Tj
+[1 0 0 1 189.828 196.717] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -194.809 -196.717] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+203.243 196.717 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 196.717] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -196.717] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 196.717 Td
+/F130_0 9.9626 Tf
+(29) 9.9626 Tj
+[1 0 0 1 516.09 196.717] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1569] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -184.761] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 184.761 Td
+/F130_0 9.9626 Tf
+(4.) 7.47195 Tj
+-310 TJm
+(Miscellanea) 48.1393 Tj
+[1 0 0 1 130.699 184.761] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -135.68 -184.761] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+144.898 184.761 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 184.761] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -184.761] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 184.761 Td
+/F130_0 9.9626 Tf
+(31) 9.9626 Tj
+[1 0 0 1 516.09 184.761] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8557] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -172.806] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 172.806 Td
+/F130_0 9.9626 Tf
+(4.1.) 14.9439 Tj
+-310 TJm
+(Limitations) 45.9475 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(format) 26.5603 Tj
+[1 0 0 1 255.231 172.806] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -260.212 -172.806] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+269.154 172.806 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 172.806] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -172.806] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 172.806 Td
+/F130_0 9.9626 Tf
+(31) 9.9626 Tj
+[1 0 0 1 516.09 172.806] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -160.851] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 160.851 Td
+/F130_0 9.9626 Tf
+(4.2.) 14.9439 Tj
+-310 TJm
+(Portability) 42.0721 Tj
+-250 TJm
+(issues) 23.8007 Tj
+[1 0 0 1 158.395 160.851] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -163.376 -160.851] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+172.03 160.851 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 160.851] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -160.851] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 160.851 Td
+/F130_0 9.9626 Tf
+(32) 9.9626 Tj
+[1 0 0 1 516.09 160.851] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1569] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -148.896] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 148.896 Td
+/F130_0 9.9626 Tf
+(4.3.) 14.9439 Tj
+-310 TJm
+(Reporting) 39.8504 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ugs) 13.8381 Tj
+[1 0 0 1 150.993 148.896] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.975 -148.896] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+166.115 148.896 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 148.896] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -148.896] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 148.896 Td
+/F130_0 9.9626 Tf
+(32) 9.9626 Tj
+[1 0 0 1 516.09 148.896] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -136.941] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 136.941 Td
+/F130_0 9.9626 Tf
+(4.4.) 14.9439 Tj
+-310 TJm
+(Did) 14.9439 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(get) 12.1743 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(right) 18.8194 Tj
+-250 TJm
+(package?) 37.0609 Tj
+[1 0 0 1 212.602 136.941] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 3.0884 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 3.0884 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -218.778 -136.941] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+229.109 136.941 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 136.941] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -136.941] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 136.941 Td
+/F130_0 9.9626 Tf
+(33) 9.9626 Tj
+[1 0 0 1 516.09 136.941] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -124.986] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 124.986 Td
+/F130_0 9.9626 Tf
+(4.5.) 14.9439 Tj
+-310 TJm
+(Further) 29.3299 Tj
+-250 TJm
+(Reading) 33.2053 Tj
+[1 0 0 1 155.058 124.986] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -160.039 -124.986] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+170.361 124.986 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 124.986] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -124.986] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 124.986 Td
+/F130_0 9.9626 Tf
+(34) 9.9626 Tj
+[1 0 0 1 516.09 124.986] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1569] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -62.0143] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 41.3997 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -494.668 -50.8518] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+536.068 50.8518 Td
+/F130_0 9.9626 Tf
+(iii) 8.30881 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 4 4
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -13.9477] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 701.916 Td
+/F122_0 24.7902 Tf
+(1.) 20.675 Tj
+-278 TJm
+(Intr) 39.937 Tj
+20 TJm
+(oduction) 104.664 Tj
+[1 0 0 1 72 701.606] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -691.643] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 679.998 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 679.998] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -679.998] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.507 679.998 Td
+/F130_0 9.9626 Tf
+(compresses) 45.9276 Tj
+-263 TJm
+(\002les) 16.6077 Tj
+-263 TJm
+(using) 21.589 Tj
+-263 TJm
+(the) 12.1743 Tj
+-262 TJm
+(Burro) 23.2427 Tj
+25 TJm
+(ws-Wheeler) 48.1293 Tj
+-263 TJm
+(block-sorting) 53.1305 Tj
+-263 TJm
+(te) 7.193 Tj
+15 TJm
+(xt) 7.7509 Tj
+-263 TJm
+(compression) 50.3609 Tj
+-263 TJm
+(algorithm,) 41.2352 Tj
+-266 TJm
+(and) 14.386 Tj
+-263 TJm
+(Huf) 15.4918 Tj
+25 TJm
+(fman) 20.4731 Tj
+-263 TJm
+(coding.) 29.6088 Tj
+72 668.043 Td
+(Compression) 52.5826 Tj
+-203 TJm
+(is) 6.64505 Tj
+-204 TJm
+(generally) 37.0708 Tj
+-203 TJm
+(considerably) 50.9089 Tj
+-203 TJm
+(better) 22.6848 Tj
+-204 TJm
+(t) 2.7696 Tj
+1 TJm
+(han) 14.386 Tj
+-204 TJm
+(that) 14.9439 Tj
+-203 TJm
+(achie) 21.0211 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ed) 9.40469 Tj
+-203 TJm
+(by) 9.9626 Tj
+-204 TJm
+(more) 20.4731 Tj
+-203 TJm
+(con) 14.386 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(entional) 32.0995 Tj
+-203 TJm
+(LZ77/LZ78-based) 73.0458 Tj
+-204 TJm
+(compressors,) 52.2937 Tj
+72 656.087 Td
+(and) 14.386 Tj
+-250 TJm
+(approaches) 44.8118 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(performance) 50.341 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(PPM) 19.9352 Tj
+-250 TJm
+(f) 3.31755 Tj
+10 TJm
+(amily) 22.6948 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(statistical) 37.6387 Tj
+-250 TJm
+(compressors.) 52.2937 Tj
+[1 0 0 1 72 653.931] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -643.968] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 634.17 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 634.17] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -634.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+105.073 634.17 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-320 TJm
+(b) 4.9813 Tj
+20 TJm
+(uilt) 13.2901 Tj
+-319 TJm
+(on) 9.9626 Tj
+-320 TJm
+(top) 12.7322 Tj
+-320 TJm
+(of) 8.29885 Tj
+[1 0 0 1 176.712 634.17] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -176.712 -634.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+176.712 634.17 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 224.533 634.17] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -224.533 -634.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+224.533 634.17 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-337 TJm
+(a) 4.42339 Tj
+-320 TJm
+(\003e) 9.9626 Tj
+15 TJm
+(xible) 19.9252 Tj
+-320 TJm
+(library) 26.5603 Tj
+-319 TJm
+(for) 11.6164 Tj
+-320 TJm
+(handling) 34.8691 Tj
+-320 TJm
+(compressed) 47.0334 Tj
+-320 TJm
+(data) 16.5977 Tj
+-319 TJm
+(in) 7.7509 Tj
+-320 TJm
+(the) 12.1743 Tj
+[1 0 0 1 449.816 634.17] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -449.816 -634.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+449.816 634.17 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 479.704 634.17] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -479.704 -634.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+482.889 634.17 Td
+/F130_0 9.9626 Tf
+(format.) 29.0509 Tj
+-1039 TJm
+(This) 17.7135 Tj
+72 622.214 Td
+(manual) 29.3299 Tj
+-316 TJm
+(describes) 37.0708 Tj
+-316 TJm
+(both) 17.7135 Tj
+-317 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-316 TJm
+(to) 7.7509 Tj
+-316 TJm
+(use) 13.2801 Tj
+-316 TJm
+(the) 12.1743 Tj
+-316 TJm
+(program) 33.7533 Tj
+-316 TJm
+(and) 14.386 Tj
+-317 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-316 TJm
+(to) 7.7509 Tj
+-316 TJm
+(w) 7.193 Tj
+10 TJm
+(ork) 13.2801 Tj
+-316 TJm
+(with) 17.7135 Tj
+-316 TJm
+(the) 12.1743 Tj
+-317 TJm
+(library) 26.5603 Tj
+-316 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace.) 15.7608 Tj
+-1017 TJm
+(Most) 20.4831 Tj
+-316 TJm
+(of) 8.29885 Tj
+-316 TJm
+(the) 12.1743 Tj
+-317 TJm
+(manual) 29.3299 Tj
+-316 TJm
+(is) 6.64505 Tj
+72 610.259 Td
+(de) 9.40469 Tj
+25 TJm
+(v) 4.9813 Tj
+20 TJm
+(oted) 17.1556 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(not) 12.7322 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(program,) 36.2439 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(good) 19.9252 Tj
+-250 TJm
+(ne) 9.40469 Tj
+25 TJm
+(ws) 11.0684 Tj
+-250 TJm
+(if) 6.08715 Tj
+-250 TJm
+(your) 18.2614 Tj
+-250 TJm
+(interest) 29.3299 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(only) 17.7135 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(program.) 36.2439 Tj
+[1 0 0 1 72 608.102] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -29.7236] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -578.379] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 578.379 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 578.379] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -86.944 -578.379] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 578.379 Td
+/F130_0 9.9626 Tf
+(Ho) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+-259 TJm
+(to) 7.7509 Tj
+-260 TJm
+(use) 13.2801 Tj
+-259 TJm
+(bzip2) 22.1369 Tj
+[1 0 0 1 156.985 578.379] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -156.985 -578.379] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+159.57 578.379 Td
+/F130_0 9.9626 Tf
+([2]) 11.6164 Tj
+[1 0 0 1 171.186 578.379] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -171.186 -578.379] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+173.771 578.379 Td
+/F130_0 9.9626 Tf
+(describes) 37.0708 Tj
+-259 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-260 TJm
+(to) 7.7509 Tj
+-259 TJm
+(use) 13.2801 Tj
+[1 0 0 1 259.119 578.379] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -259.119 -578.379] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+259.119 578.379 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 289.007 578.379] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -289.007 -578.379] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+289.007 578.379 Td
+/F130_0 9.9626 Tf
+(;) 2.7696 Tj
+-264 TJm
+(this) 14.396 Tj
+-260 TJm
+(is) 6.64505 Tj
+-259 TJm
+(the) 12.1743 Tj
+-260 TJm
+(only) 17.7135 Tj
+-259 TJm
+(part) 15.4918 Tj
+-259 TJm
+(you) 14.9439 Tj
+-260 TJm
+(need) 18.8094 Tj
+-259 TJm
+(to) 7.7509 Tj
+-260 TJm
+(read) 17.1456 Tj
+-259 TJm
+(if) 6.08715 Tj
+-260 TJm
+(you) 14.9439 Tj
+-259 TJm
+(just) 14.396 Tj
+-260 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-259 TJm
+(to) 7.7509 Tj
+-260 TJm
+(kno) 14.9439 Tj
+25 TJm
+(w) 7.193 Tj
+86.944 566.424 Td
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(operate) 29.3199 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(program.) 36.2439 Tj
+[1 0 0 1 199.302 566.424] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -127.302 -21.9178] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -544.506] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 544.506 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 544.506] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -86.944 -544.506] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 544.506 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+-250 TJm
+(libbzip2) 32.6574 Tj
+[1 0 0 1 197.09 544.506] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -197.09 -544.506] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+199.58 544.506 Td
+/F130_0 9.9626 Tf
+([8]) 11.6164 Tj
+[1 0 0 1 211.197 544.506] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -211.197 -544.506] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+213.687 544.506 Td
+/F130_0 9.9626 Tf
+(describes) 37.0708 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(programming) 54.2364 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(aces) 17.1456 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(detail,) 24.6275 Tj
+-250 TJm
+(and) 14.386 Tj
+[1 0 0 1 417.501 544.506] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -345.501 -21.9178] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -522.588] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 522.588 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 522.588] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -86.944 -522.588] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 522.588 Td
+/F130_0 9.9626 Tf
+(Miscellanea) 48.1393 Tj
+[1 0 0 1 135.083 522.588] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -135.083 -522.588] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+137.573 522.588 Td
+/F130_0 9.9626 Tf
+([31]) 16.5977 Tj
+[1 0 0 1 154.171 522.588] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -154.171 -522.588] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+156.662 522.588 Td
+/F130_0 9.9626 Tf
+(records) 29.3199 Tj
+-250 TJm
+(some) 21.031 Tj
+-250 TJm
+(miscellaneous) 56.4481 Tj
+-250 TJm
+(notes) 21.031 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(I) 3.31755 Tj
+-250 TJm
+(thought) 30.4457 Tj
+-250 TJm
+(ought) 22.6948 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(recorded) 34.8492 Tj
+-250 TJm
+(some) 21.031 Tj
+25 TJm
+(where.) 26.8293 Tj
+[1 0 0 1 492.31 522.588] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -420.31 -471.736] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 43.0633 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.332 -50.8518] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+539.395 50.8518 Td
+/F130_0 9.9626 Tf
+(1) 4.9813 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 5 5
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -13.9477] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 701.916 Td
+/F122_0 24.7902 Tf
+(2.) 20.675 Tj
+-278 TJm
+(Ho) 33.0453 Tj
+15 TJm
+(w) 19.2868 Tj
+-278 TJm
+(to) 23.4019 Tj
+-278 TJm
+(use) 42.7135 Tj
+-278 TJm
+(bzip2) 63.3638 Tj
+[1 0 0 1 72 696.784] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -14.944] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -671.877] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 656.35 Td
+/F122_0 17.2154 Tf
+(T) 10.5186 Tj
+80 TJm
+(ab) 20.0904 Tj
+10 TJm
+(le) 14.3576 Tj
+-278 TJm
+(of) 16.2513 Tj
+-278 TJm
+(Contents) 74.5943 Tj
+[1 0 0 1 72 647.528] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.7401] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -635.788] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 635.788 Td
+/F130_0 9.9626 Tf
+(2.1.) 14.9439 Tj
+-310 TJm
+(N) 7.193 Tj
+35 TJm
+(AME) 22.1369 Tj
+[1 0 0 1 119.014 635.788] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -123.995 -635.788] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+132.691 635.788 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 635.788] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -635.788] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 635.788 Td
+/F130_0 9.9626 Tf
+(2) 4.9813 Tj
+[1 0 0 1 516.09 635.788] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -623.832] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 623.832 Td
+/F130_0 9.9626 Tf
+(2.2.) 14.9439 Tj
+-310 TJm
+(SYNOPSIS) 47.0534 Tj
+[1 0 0 1 137.085 623.832] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -142.067 -623.832] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+150.582 623.832 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 623.832] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -623.832] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 623.832 Td
+/F130_0 9.9626 Tf
+(2) 4.9813 Tj
+[1 0 0 1 516.09 623.832] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -611.877] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 611.877 Td
+/F130_0 9.9626 Tf
+(2.3.) 14.9439 Tj
+-310 TJm
+(DESCRIPTION) 64.7569 Tj
+[1 0 0 1 154.789 611.877] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -159.77 -611.877] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+168.29 611.877 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 611.877] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -611.877] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 611.877 Td
+/F130_0 9.9626 Tf
+(3) 4.9813 Tj
+[1 0 0 1 516.09 611.877] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8557] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -599.922] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 599.922 Td
+/F130_0 9.9626 Tf
+(2.4.) 14.9439 Tj
+-310 TJm
+(OPTIONS) 42.0621 Tj
+[1 0 0 1 132.094 599.922] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.076 -599.922] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+145.873 599.922 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 599.922] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -599.922] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 599.922 Td
+/F130_0 9.9626 Tf
+(4) 4.9813 Tj
+[1 0 0 1 516.09 599.922] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -587.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 587.967 Td
+/F130_0 9.9626 Tf
+(2.5.) 14.9439 Tj
+-310 TJm
+(MEMOR) 37.6387 Tj
+65 TJm
+(Y) 7.193 Tj
+-250 TJm
+(MAN) 23.2427 Tj
+35 TJm
+(A) 7.193 Tj
+40 TJm
+(GEMENT) 41.5042 Tj
+[1 0 0 1 207.9 587.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -212.881 -587.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+221.412 587.967 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 587.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -587.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 587.967 Td
+/F130_0 9.9626 Tf
+(5) 4.9813 Tj
+[1 0 0 1 516.09 587.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -576.012] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 576.012 Td
+/F130_0 9.9626 Tf
+(2.6.) 14.9439 Tj
+-310 TJm
+(RECO) 26.5703 Tj
+50 TJm
+(VERING) 37.6287 Tj
+-250 TJm
+(D) 7.193 Tj
+40 TJm
+(A) 7.193 Tj
+111 TJm
+(T) 6.08715 Tj
+93 TJm
+(A) 7.193 Tj
+-250 TJm
+(FR) 12.1843 Tj
+40 TJm
+(OM) 16.0497 Tj
+-250 TJm
+(D) 7.193 Tj
+40 TJm
+(AMA) 23.2427 Tj
+40 TJm
+(GED) 20.4731 Tj
+-250 TJm
+(FILES) 26.5703 Tj
+[1 0 0 1 293.449 576.012] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -298.43 -576.012] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+308.464 576.012 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 576.012] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -576.012] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 576.012 Td
+/F130_0 9.9626 Tf
+(6) 4.9813 Tj
+[1 0 0 1 516.09 576.012] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8557] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -564.056] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 564.056 Td
+/F130_0 9.9626 Tf
+(2.7.) 14.9439 Tj
+-310 TJm
+(PERFORMANCE) 73.6236 Tj
+-250 TJm
+(NO) 14.386 Tj
+40 TJm
+(TES) 17.7135 Tj
+[1 0 0 1 197.847 564.056] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -202.829 -564.056] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+211.958 564.056 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 564.056] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -564.056] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 564.056 Td
+/F130_0 9.9626 Tf
+(6) 4.9813 Tj
+[1 0 0 1 516.09 564.056] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -552.101] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 552.101 Td
+/F130_0 9.9626 Tf
+(2.8.) 14.9439 Tj
+-310 TJm
+(CA) 13.8381 Tj
+135 TJm
+(VEA) 20.4731 Tj
+111 TJm
+(TS) 11.6264 Tj
+[1 0 0 1 133.519 552.101] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -138.5 -552.101] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+148.799 552.101 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 552.101] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -552.101] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 552.101 Td
+/F130_0 9.9626 Tf
+(7) 4.9813 Tj
+[1 0 0 1 516.09 552.101] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8556] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -540.146] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 540.146 Td
+/F130_0 9.9626 Tf
+(2.9.) 14.9439 Tj
+-310 TJm
+(A) 7.193 Tj
+55 TJm
+(UTHOR) 34.3112 Tj
+[1 0 0 1 130.989 540.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -135.97 -540.146] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+145.32 540.146 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 540.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -540.146] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 540.146 Td
+/F130_0 9.9626 Tf
+(7) 4.9813 Tj
+[1 0 0 1 516.09 540.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.2191] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -520.002] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 508.266 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-250 TJm
+(chapter) 29.3199 Tj
+-250 TJm
+(contains) 33.2053 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(cop) 14.386 Tj
+10 TJm
+(y) 4.9813 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+[1 0 0 1 213.837 508.266] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -213.837 -508.266] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+213.837 508.266 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 243.725 508.266] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -243.725 -508.266] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+246.215 508.266 Td
+/F130_0 9.9626 Tf
+(man) 17.1556 Tj
+-250 TJm
+(page,) 21.3 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(nothing) 30.4457 Tj
+-250 TJm
+(else.) 17.9825 Tj
+[1 0 0 1 72 506.109] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -496.146] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 473.513 Td
+/F122_0 20.6585 Tf
+(2.1.) 34.4584 Tj
+-278 TJm
+(NAME) 60.8186 Tj
+[1 0 0 1 72 473.513] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -31.8804] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -441.632] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 441.632 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 441.632] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -441.632] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 441.632 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 116.832 441.632] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -116.832 -441.632] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+116.832 441.632 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 121.813 441.632] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -121.813 -441.632] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+121.813 441.632 Td
+/F134_0 9.9626 Tf
+(bunzip2) 41.8429 Tj
+[1 0 0 1 163.656 441.632] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -163.656 -441.632] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+166.147 441.632 Td
+/F130_0 9.9626 Tf
+(-) 3.31755 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(block-sorting) 53.1305 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(compressor) 45.9276 Tj
+40 TJm
+(,) 2.49065 Tj
+-250 TJm
+(v1.0.4) 24.9065 Tj
+[1 0 0 1 325.129 441.632] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -253.129 -21.9179] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -419.715] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 419.715 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 419.715] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -419.715] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 419.715 Td
+/F134_0 9.9626 Tf
+(bzcat) 29.8878 Tj
+[1 0 0 1 116.832 419.715] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -116.832 -419.715] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.322 419.715 Td
+/F130_0 9.9626 Tf
+(-) 3.31755 Tj
+-250 TJm
+(decompresses) 55.3323 Tj
+-250 TJm
+(\002les) 16.6077 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(stdout) 24.3586 Tj
+[1 0 0 1 236.651 419.715] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -164.651 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -397.797] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 397.797 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 397.797] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -397.797] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 397.797 Td
+/F134_0 9.9626 Tf
+(bzip2recover) 71.7307 Tj
+[1 0 0 1 158.675 397.797] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -158.675 -397.797] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+161.166 397.797 Td
+/F130_0 9.9626 Tf
+(-) 3.31755 Tj
+-250 TJm
+(reco) 17.1456 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(ers) 11.6164 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(from) 19.3673 Tj
+-250 TJm
+(damaged) 35.965 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+-250 TJm
+(\002les) 16.6077 Tj
+[1 0 0 1 323.545 397.797] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -251.545 -12.1195] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -375.715] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 353.081 Td
+/F122_0 20.6585 Tf
+(2.2.) 34.4584 Tj
+-278 TJm
+(SYNOPSIS) 105.627 Tj
+[1 0 0 1 72 352.823] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -31.6223] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -321.201] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 321.201 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 321.201] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -321.201] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 321.201 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 116.832 321.201] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -116.832 -321.201] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.322 321.201 Td
+/F130_0 9.9626 Tf
+([) 3.31755 Tj
+-250 TJm
+(-cdfkqstvzVL123456789) 100.164 Tj
+-250 TJm
+(]) 3.31755 Tj
+-250 TJm
+([) 3.31755 Tj
+-250 TJm
+(\002lenames) 38.1866 Tj
+-250 TJm
+(...) 7.47195 Tj
+-620 TJm
+(]) 3.31755 Tj
+[1 0 0 1 297.045 321.201] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -225.045 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -299.283] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 299.283 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 299.283] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -299.283] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 299.283 Td
+/F134_0 9.9626 Tf
+(bunzip2) 41.8429 Tj
+[1 0 0 1 128.787 299.283] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -128.787 -299.283] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+131.278 299.283 Td
+/F130_0 9.9626 Tf
+([) 3.31755 Tj
+-250 TJm
+(-fkvsVL) 33.7533 Tj
+-250 TJm
+(]) 3.31755 Tj
+-250 TJm
+([) 3.31755 Tj
+-250 TJm
+(\002lenames) 38.1866 Tj
+-250 TJm
+(...) 7.47195 Tj
+-620 TJm
+(]) 3.31755 Tj
+[1 0 0 1 242.589 299.283] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -170.589 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -277.365] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 277.365 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 277.365] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -277.365] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 277.365 Td
+/F134_0 9.9626 Tf
+(bzcat) 29.8878 Tj
+[1 0 0 1 116.832 277.365] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -116.832 -277.365] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.322 277.365 Td
+/F130_0 9.9626 Tf
+([) 3.31755 Tj
+-250 TJm
+(-s) 7.193 Tj
+-250 TJm
+(]) 3.31755 Tj
+-250 TJm
+([) 3.31755 Tj
+-250 TJm
+(\002lenames) 38.1866 Tj
+-250 TJm
+(...) 7.47195 Tj
+-620 TJm
+(]) 3.31755 Tj
+[1 0 0 1 204.074 277.365] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -132.074 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -255.447] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 255.447 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 255.447] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -255.447] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 255.447 Td
+/F134_0 9.9626 Tf
+(bzip2recover) 71.7307 Tj
+[1 0 0 1 158.675 255.447] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -158.675 -255.447] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+161.166 255.447 Td
+/F130_0 9.9626 Tf
+(\002lename) 34.3112 Tj
+[1 0 0 1 195.476 255.447] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -123.477 -204.596] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 43.0633 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.332 -50.8519] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+539.395 50.8519 Td
+/F130_0 9.9626 Tf
+(2) 4.9813 Tj
+[1 0 0 1 453.269 50.8519] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 6 6
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 105.519 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -371.59 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+477.109 749.245 Td
+/F130_0 9.9626 Tf
+(Ho) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+[1 0 0 1 266.071 747.089] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 704.93 Td
+/F122_0 20.6585 Tf
+(2.3.) 34.4584 Tj
+-278 TJm
+(DESCRIPTION) 141.18 Tj
+[1 0 0 1 72 704.672] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -694.709] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 683.012 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 683.012] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -683.012] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.56 683.012 Td
+/F130_0 9.9626 Tf
+(compresses) 45.9276 Tj
+-268 TJm
+(\002les) 16.6077 Tj
+-268 TJm
+(using) 21.589 Tj
+-268 TJm
+(the) 12.1743 Tj
+-269 TJm
+(Burro) 23.2427 Tj
+25 TJm
+(ws-Wheeler) 48.1293 Tj
+-268 TJm
+(block) 22.1369 Tj
+-268 TJm
+(sorting) 27.6761 Tj
+-268 TJm
+(te) 7.193 Tj
+15 TJm
+(xt) 7.7509 Tj
+-268 TJm
+(compression) 50.3609 Tj
+-268 TJm
+(algorithm,) 41.2352 Tj
+-273 TJm
+(and) 14.386 Tj
+-268 TJm
+(Huf) 15.4918 Tj
+25 TJm
+(fman) 20.4731 Tj
+-269 TJm
+(c) 4.42339 Tj
+1 TJm
+(od) 9.9626 Tj
+-1 TJm
+(i) 2.7696 Tj
+1 TJm
+(ng.) 12.4533 Tj
+72 671.057 Td
+(Compression) 52.5826 Tj
+-203 TJm
+(is) 6.64505 Tj
+-204 TJm
+(generally) 37.0708 Tj
+-203 TJm
+(considerably) 50.9089 Tj
+-203 TJm
+(better) 22.6848 Tj
+-204 TJm
+(t) 2.7696 Tj
+1 TJm
+(han) 14.386 Tj
+-204 TJm
+(that) 14.9439 Tj
+-203 TJm
+(achie) 21.0211 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ed) 9.40469 Tj
+-203 TJm
+(by) 9.9626 Tj
+-204 TJm
+(more) 20.4731 Tj
+-203 TJm
+(con) 14.386 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(entional) 32.0995 Tj
+-203 TJm
+(LZ77/LZ78-based) 73.0458 Tj
+-204 TJm
+(compressors,) 52.2937 Tj
+72 659.101 Td
+(and) 14.386 Tj
+-250 TJm
+(approaches) 44.8118 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(performance) 50.341 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(PPM) 19.9352 Tj
+-250 TJm
+(f) 3.31755 Tj
+10 TJm
+(amily) 22.6948 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(statistical) 37.6387 Tj
+-250 TJm
+(compressors.) 52.2937 Tj
+[1 0 0 1 72 656.945] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -646.982] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 637.184 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-250 TJm
+(command-line) 57.5539 Tj
+-250 TJm
+(options) 29.3399 Tj
+-250 TJm
+(are) 12.1643 Tj
+-250 TJm
+(deliberately) 47.0334 Tj
+-250 TJm
+(v) 4.9813 Tj
+15 TJm
+(ery) 12.7222 Tj
+-250 TJm
+(similar) 27.6761 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(those) 21.031 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(GNU) 21.579 Tj
+[1 0 0 1 364.869 637.184] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -364.869 -637.184] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+364.869 637.184 Td
+/F134_0 9.9626 Tf
+(gzip) 23.9102 Tj
+[1 0 0 1 388.779 637.184] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -388.779 -637.184] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+388.779 637.184 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-250 TJm
+(are) 12.1643 Tj
+-250 TJm
+(not) 12.7322 Tj
+-250 TJm
+(identical.) 36.8018 Tj
+[1 0 0 1 72 635.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -625.064] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 615.266 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 615.266] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -615.266] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+105.175 615.266 Td
+/F130_0 9.9626 Tf
+(e) 4.42339 Tj
+15 TJm
+(xpects) 25.4544 Tj
+-330 TJm
+(a) 4.42339 Tj
+-330 TJm
+(list) 12.1843 Tj
+-330 TJm
+(of) 8.29885 Tj
+-330 TJm
+(\002le) 12.7322 Tj
+-329 TJm
+(names) 25.4544 Tj
+-330 TJm
+(to) 7.7509 Tj
+-330 TJm
+(accompan) 40.3884 Tj
+15 TJm
+(y) 4.9813 Tj
+-330 TJm
+(the) 12.1743 Tj
+-330 TJm
+(command-line) 57.5539 Tj
+-330 TJm
+(\003ags.) 21.31 Tj
+-1099 TJm
+(Each) 19.9152 Tj
+-330 TJm
+(\002le) 12.7322 Tj
+-330 TJm
+(is) 6.64505 Tj
+-330 TJm
+(replaced) 33.7433 Tj
+-330 TJm
+(by) 9.9626 Tj
+-330 TJm
+(a) 4.42339 Tj
+-330 TJm
+(compressed) 47.0334 Tj
+72 603.311 Td
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-349 TJm
+(of) 8.29885 Tj
+-348 TJm
+(itself,) 22.4159 Tj
+-373 TJm
+(with) 17.7135 Tj
+-349 TJm
+(the) 12.1743 Tj
+-349 TJm
+(name) 21.579 Tj
+[1 0 0 1 204.444 603.311] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.444 -603.311] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+204.444 603.311 Td
+/F134_0 9.9626 Tf
+(original_name.bz2) 101.619 Tj
+[1 0 0 1 306.063 603.311] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -306.063 -603.311] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+306.063 603.311 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1212 TJm
+(Each) 19.9152 Tj
+-348 TJm
+(compressed) 47.0334 Tj
+-349 TJm
+(\002le) 12.7322 Tj
+-348 TJm
+(has) 13.2801 Tj
+-349 TJm
+(the) 12.1743 Tj
+-348 TJm
+(same) 20.4731 Tj
+-349 TJm
+(modi\002cation) 50.3709 Tj
+-349 TJm
+(date,) 19.0883 Tj
+72 591.356 Td
+(permissions,) 50.092 Tj
+-344 TJm
+(and,) 16.8766 Tj
+-344 TJm
+(when) 21.579 Tj
+-325 TJm
+(possible,) 35.1481 Tj
+-344 TJm
+(o) 4.9813 Tj
+25 TJm
+(wnership) 36.5229 Tj
+-325 TJm
+(as) 8.29885 Tj
+-325 TJm
+(the) 12.1743 Tj
+-326 TJm
+(corresponding) 56.996 Tj
+-325 TJm
+(original,) 33.4843 Tj
+-344 TJm
+(so) 8.85675 Tj
+-325 TJm
+(that) 14.9439 Tj
+-325 TJm
+(these) 20.4731 Tj
+-325 TJm
+(properties) 39.8404 Tj
+-325 TJm
+(can) 13.8281 Tj
+-326 TJm
+(be) 9.40469 Tj
+-325 TJm
+(correctly) 35.4071 Tj
+72 579.4 Td
+(restored) 32.0895 Tj
+-308 TJm
+(at) 7.193 Tj
+-308 TJm
+(decompression) 59.7656 Tj
+-307 TJm
+(time.) 20.2042 Tj
+-484 TJm
+(File) 15.5018 Tj
+-308 TJm
+(name) 21.579 Tj
+-308 TJm
+(handling) 34.8691 Tj
+-308 TJm
+(is) 6.64505 Tj
+-307 TJm
+(nai) 12.1743 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-308 TJm
+(in) 7.7509 Tj
+-308 TJm
+(the) 12.1743 Tj
+-308 TJm
+(sense) 21.579 Tj
+-308 TJm
+(that) 14.9439 Tj
+-308 TJm
+(there) 19.9152 Tj
+-307 TJm
+(is) 6.64505 Tj
+-308 TJm
+(no) 9.9626 Tj
+-308 TJm
+(mechanism) 45.3796 Tj
+-308 TJm
+(for) 11.6164 Tj
+-308 TJm
+(preserving) 42.0521 Tj
+72 567.445 Td
+(original) 30.9936 Tj
+-334 TJm
+(\002le) 12.7322 Tj
+-333 TJm
+(names,) 27.9451 Tj
+-355 TJm
+(permissions,) 50.092 Tj
+-355 TJm
+(o) 4.9813 Tj
+25 TJm
+(wnerships) 40.3983 Tj
+-333 TJm
+(or) 8.29885 Tj
+-334 TJm
+(dates) 20.4731 Tj
+-334 TJm
+(in) 7.7509 Tj
+-333 TJm
+(\002lesystems) 44.2838 Tj
+-334 TJm
+(which) 24.3486 Tj
+-334 TJm
+(lack) 16.5977 Tj
+-333 TJm
+(these) 20.4731 Tj
+-334 TJm
+(concepts,) 37.3498 Tj
+-355 TJm
+(or) 8.29885 Tj
+-333 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-334 TJm
+(serious) 28.224 Tj
+-334 TJm
+(\002le) 12.7322 Tj
+72 555.49 Td
+(name) 21.579 Tj
+-250 TJm
+(length) 24.9065 Tj
+-250 TJm
+(restrictions,) 46.7644 Tj
+-250 TJm
+(such) 18.2614 Tj
+-250 TJm
+(as) 8.29885 Tj
+-250 TJm
+(MS-DOS.) 40.1294 Tj
+[1 0 0 1 72 553.333] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -543.371] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 533.572 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 533.572] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -533.572] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.379 533.572 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 121.255 533.572] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -121.255 -533.572] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+121.255 533.572 Td
+/F134_0 9.9626 Tf
+(bunzip2) 41.8429 Tj
+[1 0 0 1 163.098 533.572] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -163.098 -533.572] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+165.589 533.572 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-250 TJm
+(by) 9.9626 Tj
+-250 TJm
+(def) 12.7222 Tj
+10 TJm
+(ault) 14.9439 Tj
+-250 TJm
+(not) 12.7322 Tj
+-250 TJm
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(erwrite) 28.2141 Tj
+-250 TJm
+(e) 4.42339 Tj
+15 TJm
+(xisting) 27.1282 Tj
+-250 TJm
+(\002les.) 19.0983 Tj
+-620 TJm
+(If) 6.63509 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(happen,) 31.2626 Tj
+-250 TJm
+(specify) 28.772 Tj
+-250 TJm
+(the) 12.1743 Tj
+[1 0 0 1 495.977 533.572] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -495.977 -533.572] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+495.977 533.572 Td
+/F134_0 9.9626 Tf
+(-f) 11.9551 Tj
+[1 0 0 1 507.932 533.572] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -507.932 -533.572] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+510.423 533.572 Td
+/F130_0 9.9626 Tf
+(\003ag.) 17.4346 Tj
+[1 0 0 1 72 531.415] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -521.453] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 511.654 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-284 TJm
+(no) 9.9626 Tj
+-285 TJm
+(\002le) 12.7322 Tj
+-284 TJm
+(names) 25.4544 Tj
+-284 TJm
+(are) 12.1643 Tj
+-284 TJm
+(speci\002ed,) 37.9077 Tj
+[1 0 0 1 193.935 511.654] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -193.935 -511.654] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+193.935 511.654 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 223.823 511.654] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -223.823 -511.654] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+226.655 511.654 Td
+/F130_0 9.9626 Tf
+(compresses) 45.9276 Tj
+-284 TJm
+(from) 19.3673 Tj
+-285 TJm
+(standard) 33.7533 Tj
+-284 TJm
+(input) 20.4831 Tj
+-284 TJm
+(to) 7.7509 Tj
+-284 TJm
+(standard) 33.7533 Tj
+-285 TJm
+(output.) 27.9551 Tj
+-825 TJm
+(In) 8.29885 Tj
+-285 TJm
+(this) 14.396 Tj
+-284 TJm
+(case,) 19.6363 Tj
+[1 0 0 1 491.778 511.654] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -491.778 -511.654] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+491.778 511.654 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 521.666 511.654] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -521.666 -511.654] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+524.499 511.654 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+72 499.699 Td
+(decline) 28.772 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(write) 20.4731 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(output) 25.4644 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(terminal,) 35.696 Tj
+-250 TJm
+(as) 8.29885 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ould) 17.7135 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(entirely) 30.4357 Tj
+-250 TJm
+(incomprehensible) 70.8341 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(therefore) 35.955 Tj
+-250 TJm
+(pointless.) 37.9177 Tj
+[1 0 0 1 72 497.542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -487.58] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 477.781 Td
+/F134_0 9.9626 Tf
+(bunzip2) 41.8429 Tj
+[1 0 0 1 113.843 477.781] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.843 -477.781] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+116.176 477.781 Td
+/F130_0 9.9626 Tf
+(\(or) 11.6164 Tj
+[1 0 0 1 130.125 477.781] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -130.125 -477.781] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+130.125 477.781 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+-600 TJm
+(-d) 11.9551 Tj
+[1 0 0 1 177.946 477.781] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -177.946 -477.781] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+177.946 477.781 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-234 TJm
+(decompresses) 55.3323 Tj
+-234 TJm
+(all) 9.9626 Tj
+-234 TJm
+(speci\002ed) 35.417 Tj
+-235 TJm
+(\002les.) 19.0983 Tj
+-609 TJm
+(Files) 19.3773 Tj
+-234 TJm
+(which) 24.3486 Tj
+-234 TJm
+(were) 19.3573 Tj
+-234 TJm
+(not) 12.7322 Tj
+-235 TJm
+(created) 28.762 Tj
+-234 TJm
+(by) 9.9626 Tj
+[1 0 0 1 445.012 477.781] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -445.012 -477.781] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+445.012 477.781 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 474.9 477.781] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -474.9 -477.781] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+477.233 477.781 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-234 TJm
+(be) 9.40469 Tj
+-234 TJm
+(detected) 33.1954 Tj
+72 465.826 Td
+(and) 14.386 Tj
+-280 TJm
+(i) 2.7696 Tj
+1 TJm
+(gnored,) 30.1568 Tj
+-287 TJm
+(and) 14.386 Tj
+-280 TJm
+(a) 4.42339 Tj
+-279 TJm
+(w) 7.193 Tj
+10 TJm
+(arning) 25.4544 Tj
+-280 TJm
+(issued.) 27.3972 Tj
+[1 0 0 1 216.033 465.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -216.033 -465.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+216.033 465.826 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 245.921 465.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -245.921 -465.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+248.705 465.826 Td
+/F130_0 9.9626 Tf
+(attempts) 33.7633 Tj
+-279 TJm
+(to) 7.7509 Tj
+-280 TJm
+(guess) 22.1369 Tj
+-279 TJm
+(the) 12.1743 Tj
+-280 TJm
+(\002lename) 34.3112 Tj
+-279 TJm
+(for) 11.6164 Tj
+-280 TJm
+(the) 12.1743 Tj
+-279 TJm
+(decompressed) 56.4381 Tj
+-280 TJm
+(\002le) 12.7322 Tj
+-279 TJm
+(from) 19.3673 Tj
+-280 TJm
+(that) 14.9439 Tj
+-279 TJm
+(of) 8.29885 Tj
+-280 TJm
+(the) 12.1743 Tj
+72 453.871 Td
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(as) 8.29885 Tj
+-250 TJm
+(follo) 18.8194 Tj
+25 TJm
+(ws:) 13.8381 Tj
+[1 0 0 1 72 451.714] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -29.7236] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -421.991] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 421.991 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 421.991] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -421.991] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 421.991 Td
+/F134_0 9.9626 Tf
+(filename.bz2) 71.7307 Tj
+[1 0 0 1 164.653 421.991] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -164.653 -421.991] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+167.143 421.991 Td
+/F130_0 9.9626 Tf
+(becomes) 34.8591 Tj
+[1 0 0 1 204.493 421.991] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.493 -421.991] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+204.493 421.991 Td
+/F134_0 9.9626 Tf
+(filename) 47.8205 Tj
+[1 0 0 1 252.313 421.991] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -180.313 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -400.073] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 400.073 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 400.073] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -400.073] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 400.073 Td
+/F134_0 9.9626 Tf
+(filename.bz) 65.7532 Tj
+[1 0 0 1 158.675 400.073] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -158.675 -400.073] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+161.166 400.073 Td
+/F130_0 9.9626 Tf
+(becomes) 34.8591 Tj
+[1 0 0 1 198.515 400.073] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -198.515 -400.073] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+198.515 400.073 Td
+/F134_0 9.9626 Tf
+(filename) 47.8205 Tj
+[1 0 0 1 246.336 400.073] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -174.336 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -378.155] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 378.155 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 378.155] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -378.155] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 378.155 Td
+/F134_0 9.9626 Tf
+(filename.tbz2) 77.7083 Tj
+[1 0 0 1 164.653 378.155] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -164.653 -378.155] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+167.143 378.155 Td
+/F130_0 9.9626 Tf
+(becomes) 34.8591 Tj
+[1 0 0 1 204.493 378.155] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.493 -378.155] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+204.493 378.155 Td
+/F134_0 9.9626 Tf
+(filename.tar) 71.7307 Tj
+[1 0 0 1 276.224 378.155] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.224 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -356.237] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 356.237 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 356.237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -356.237] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 356.237 Td
+/F134_0 9.9626 Tf
+(filename.tbz) 71.7307 Tj
+[1 0 0 1 164.653 356.237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -164.653 -356.237] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+167.143 356.237 Td
+/F130_0 9.9626 Tf
+(becomes) 34.8591 Tj
+[1 0 0 1 204.493 356.237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.493 -356.237] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+204.493 356.237 Td
+/F134_0 9.9626 Tf
+(filename.tar) 71.7307 Tj
+[1 0 0 1 276.224 356.237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.224 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -334.319] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 334.319 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 334.319] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -334.319] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 334.319 Td
+/F134_0 9.9626 Tf
+(anyothername) 71.7307 Tj
+[1 0 0 1 164.653 334.319] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -164.653 -334.319] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+167.143 334.319 Td
+/F130_0 9.9626 Tf
+(becomes) 34.8591 Tj
+[1 0 0 1 204.493 334.319] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.493 -334.319] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+204.493 334.319 Td
+/F134_0 9.9626 Tf
+(anyothername.out) 95.641 Tj
+[1 0 0 1 300.134 334.319] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -228.134 -11.4968] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -322.823] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 312.402 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-342 TJm
+(the) 12.1743 Tj
+-342 TJm
+(\002le) 12.7322 Tj
+-342 TJm
+(does) 18.2614 Tj
+-342 TJm
+(not) 12.7322 Tj
+-343 TJm
+(end) 14.386 Tj
+-342 TJm
+(in) 7.7509 Tj
+-342 TJm
+(one) 14.386 Tj
+-342 TJm
+(of) 8.29885 Tj
+-342 TJm
+(the) 12.1743 Tj
+-342 TJm
+(recognised) 43.158 Tj
+-342 TJm
+(endings,) 33.4843 Tj
+[1 0 0 1 309.305 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -309.305 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+309.305 312.402 Td
+/F134_0 9.9626 Tf
+(.bz2) 23.9102 Tj
+[1 0 0 1 333.215 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -333.215 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+333.215 312.402 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 339.344 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -339.344 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+339.344 312.402 Td
+/F134_0 9.9626 Tf
+(.bz) 17.9327 Tj
+[1 0 0 1 357.276 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -357.276 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+357.276 312.402 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 363.405 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -363.405 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+363.405 312.402 Td
+/F134_0 9.9626 Tf
+(.tbz2) 29.8878 Tj
+[1 0 0 1 393.293 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -393.293 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+396.701 312.402 Td
+/F130_0 9.9626 Tf
+(or) 8.29885 Tj
+[1 0 0 1 408.409 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -408.409 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+408.409 312.402 Td
+/F134_0 9.9626 Tf
+(.tbz) 23.9102 Tj
+[1 0 0 1 432.319 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -432.319 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+432.319 312.402 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 438.448 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -438.448 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+438.448 312.402 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 468.336 312.402] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468.336 -312.402] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+471.744 312.402 Td
+/F130_0 9.9626 Tf
+(complains) 40.9562 Tj
+-342 TJm
+(that) 14.9439 Tj
+-342 TJm
+(it) 5.53921 Tj
+72 300.446 Td
+(cannot) 26.5603 Tj
+-250 TJm
+(guess) 22.1369 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(name) 21.579 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(original) 30.9936 Tj
+-250 TJm
+(\002le,) 15.2229 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(uses) 17.1556 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(original) 30.9936 Tj
+-250 TJm
+(name) 21.579 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 370.009 300.446] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -370.009 -300.446] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+370.009 300.446 Td
+/F134_0 9.9626 Tf
+(.out) 23.9102 Tj
+[1 0 0 1 393.92 300.446] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -393.92 -300.446] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+396.41 300.446 Td
+/F130_0 9.9626 Tf
+(appended.) 40.6673 Tj
+[1 0 0 1 72 298.29] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -288.327] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 278.529 Td
+/F130_0 9.9626 Tf
+(As) 11.0684 Tj
+-250 TJm
+(with) 17.7135 Tj
+-250 TJm
+(compression,) 52.8516 Tj
+-250 TJm
+(supplying) 39.3025 Tj
+-250 TJm
+(no) 9.9626 Tj
+-250 TJm
+(\002lenames) 38.1866 Tj
+-250 TJm
+(causes) 26.0024 Tj
+-250 TJm
+(decompression) 59.7656 Tj
+-250 TJm
+(from) 19.3673 Tj
+-250 TJm
+(standard) 33.7533 Tj
+-250 TJm
+(input) 20.4831 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(standard) 33.7533 Tj
+-250 TJm
+(output.) 27.9551 Tj
+[1 0 0 1 72 276.372] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -266.409] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 256.611 Td
+/F134_0 9.9626 Tf
+(bunzip2) 41.8429 Tj
+[1 0 0 1 113.843 256.611] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.843 -256.611] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+116.409 256.611 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-257 TJm
+(correctly) 35.4071 Tj
+-258 TJm
+(decompress) 47.0334 Tj
+-257 TJm
+(a) 4.42339 Tj
+-258 TJm
+(\002le) 12.7322 Tj
+-257 TJm
+(which) 24.3486 Tj
+-258 TJm
+(is) 6.64505 Tj
+-258 TJm
+(the) 12.1743 Tj
+-257 TJm
+(concatenation) 55.3323 Tj
+-258 TJm
+(of) 8.29885 Tj
+-257 TJm
+(tw) 9.9626 Tj
+10 TJm
+(o) 4.9813 Tj
+-258 TJm
+(or) 8.29885 Tj
+-257 TJm
+(more) 20.4731 Tj
+-258 TJm
+(compressed) 47.0334 Tj
+-257 TJm
+(\002les.) 19.0983 Tj
+-665 TJm
+(The) 15.4918 Tj
+-258 TJm
+(result) 22.1369 Tj
+-257 TJm
+(is) 6.64505 Tj
+72 244.656 Td
+(the) 12.1743 Tj
+-239 TJm
+(concatenation) 55.3323 Tj
+-238 TJm
+(of) 8.29885 Tj
+-239 TJm
+(the) 12.1743 Tj
+-239 TJm
+(corresponding) 56.996 Tj
+-239 TJm
+(uncompressed) 56.996 Tj
+-238 TJm
+(\002les.) 19.0983 Tj
+-613 TJm
+(Inte) 15.4918 Tj
+15 TJm
+(grity) 18.8194 Tj
+-238 TJm
+(testing) 26.5703 Tj
+-239 TJm
+(\() 3.31755 Tj
+[1 0 0 1 382.247 244.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -382.247 -244.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+382.247 244.656 Td
+/F134_0 9.9626 Tf
+(-t) 11.9551 Tj
+[1 0 0 1 394.202 244.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -394.202 -244.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+394.202 244.656 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-239 TJm
+(of) 8.29885 Tj
+-238 TJm
+(concatenated) 52.0048 Tj
+-239 TJm
+(compressed) 47.0334 Tj
+-239 TJm
+(\002les) 16.6077 Tj
+-239 TJm
+(is) 6.64505 Tj
+72 232.7 Td
+(also) 16.0497 Tj
+-250 TJm
+(supported.) 41.7831 Tj
+[1 0 0 1 72 230.544] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -220.581] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 210.783 Td
+/F130_0 9.9626 Tf
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-399 TJm
+(can) 13.8281 Tj
+-399 TJm
+(also) 16.0497 Tj
+-399 TJm
+(compress) 37.6287 Tj
+-400 TJm
+(or) 8.29885 Tj
+-399 TJm
+(decompress) 47.0334 Tj
+-399 TJm
+(\002les) 16.6077 Tj
+-399 TJm
+(to) 7.7509 Tj
+-399 TJm
+(the) 12.1743 Tj
+-399 TJm
+(standard) 33.7533 Tj
+-399 TJm
+(output) 25.4644 Tj
+-399 TJm
+(by) 9.9626 Tj
+-400 TJm
+(gi) 7.7509 Tj
+25 TJm
+(ving) 17.7135 Tj
+-399 TJm
+(the) 12.1743 Tj
+[1 0 0 1 409.67 210.783] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -409.67 -210.783] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+409.67 210.783 Td
+/F134_0 9.9626 Tf
+(-c) 11.9551 Tj
+[1 0 0 1 421.625 210.783] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -421.625 -210.783] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+425.602 210.783 Td
+/F130_0 9.9626 Tf
+(\003ag.) 17.4346 Tj
+-757 TJm
+(Multiple) 34.3212 Tj
+-400 TJm
+(\002l) 8.30881 Tj
+1 TJm
+(es) 8.29885 Tj
+-400 TJm
+(may) 17.1556 Tj
+-399 TJm
+(be) 9.40469 Tj
+72 198.828 Td
+(compressed) 47.0334 Tj
+-367 TJm
+(and) 14.386 Tj
+-367 TJm
+(decompressed) 56.4381 Tj
+-367 TJm
+(lik) 10.5205 Tj
+10 TJm
+(e) 4.42339 Tj
+-367 TJm
+(this.) 16.8866 Tj
+-1321 TJm
+(The) 15.4918 Tj
+-367 TJm
+(resulting) 34.8691 Tj
+-367 TJm
+(outputs) 29.3399 Tj
+-367 TJm
+(are) 12.1643 Tj
+-367 TJm
+(fed) 12.7222 Tj
+-367 TJm
+(sequentially) 48.1492 Tj
+-366 TJm
+(to) 7.7509 Tj
+-367 TJm
+(stdout.) 26.8492 Tj
+-1322 TJm
+(Compression) 52.5826 Tj
+-367 TJm
+(of) 8.29885 Tj
+72 186.872 Td
+(multiple) 33.2153 Tj
+-289 TJm
+(\002les) 16.6077 Tj
+-289 TJm
+(in) 7.7509 Tj
+-289 TJm
+(this) 14.396 Tj
+-289 TJm
+(manner) 29.8778 Tj
+-288 TJm
+(generates) 37.6188 Tj
+-289 TJm
+(a) 4.42339 Tj
+-289 TJm
+(stream) 26.5603 Tj
+-289 TJm
+(containing) 42.0621 Tj
+-289 TJm
+(multiple) 33.2153 Tj
+-289 TJm
+(compressed) 47.0334 Tj
+-289 TJm
+(\002le) 12.7322 Tj
+-289 TJm
+(representations.) 62.8042 Tj
+-853 TJm
+(Such) 19.9252 Tj
+-289 TJm
+(a) 4.42339 Tj
+-289 TJm
+(stream) 26.5603 Tj
+72 174.917 Td
+(can) 13.8281 Tj
+-391 TJm
+(be) 9.40469 Tj
+-391 TJm
+(decompressed) 56.4381 Tj
+-390 TJm
+(correctly) 35.4071 Tj
+-391 TJm
+(only) 17.7135 Tj
+-391 TJm
+(by) 9.9626 Tj
+[1 0 0 1 238.116 174.917] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -238.116 -174.917] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+238.116 174.917 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 268.004 174.917] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -268.004 -174.917] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+271.897 174.917 Td
+/F130_0 9.9626 Tf
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-391 TJm
+(0.9.0) 19.9252 Tj
+-391 TJm
+(or) 8.29885 Tj
+-391 TJm
+(l) 2.7696 Tj
+1 TJm
+(ater) 14.9339 Tj
+55 TJm
+(.) 2.49065 Tj
+-733 TJm
+(Earlier) 27.1082 Tj
+-391 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions) 28.224 Tj
+-391 TJm
+(of) 8.29885 Tj
+[1 0 0 1 448.071 174.917] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -448.071 -174.917] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+448.071 174.917 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 477.958 174.917] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -477.958 -174.917] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+481.852 174.917 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-391 TJm
+(stop) 16.6077 Tj
+-391 TJm
+(after) 18.2515 Tj
+72 162.962 Td
+(decompressing) 59.7656 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(\002rst) 15.5018 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(stream.) 29.0509 Tj
+[1 0 0 1 72 160.805] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -150.843] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 141.044 Td
+/F134_0 9.9626 Tf
+(bzcat) 29.8878 Tj
+[1 0 0 1 101.888 141.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -141.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.379 141.044 Td
+/F130_0 9.9626 Tf
+(\(or) 11.6164 Tj
+[1 0 0 1 118.486 141.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -118.486 -141.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+118.486 141.044 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+-600 TJm
+(-dc) 17.9327 Tj
+[1 0 0 1 172.284 141.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -172.284 -141.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+172.284 141.044 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-250 TJm
+(decompresses) 55.3323 Tj
+-250 TJm
+(all) 9.9626 Tj
+-250 TJm
+(speci\002ed) 35.417 Tj
+-250 TJm
+(\002les) 16.6077 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(standard) 33.7533 Tj
+-250 TJm
+(output.) 27.9551 Tj
+[1 0 0 1 72 138.887] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -128.925] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 119.126 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 119.126] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -119.126] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.866 119.126 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-299 TJm
+(read) 17.1456 Tj
+-299 TJm
+(ar) 7.74094 Tj
+18 TJm
+(guments) 33.7633 Tj
+-299 TJm
+(from) 19.3673 Tj
+-299 TJm
+(the) 12.1743 Tj
+-299 TJm
+(en) 9.40469 Tj
+40 TJm
+(vironment) 40.9562 Tj
+-298 TJm
+(v) 4.9813 Tj
+25 TJm
+(ariables) 30.9837 Tj
+[1 0 0 1 316.903 119.126] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -316.903 -119.126] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+316.903 119.126 Td
+/F134_0 9.9626 Tf
+(BZIP2) 29.8878 Tj
+[1 0 0 1 346.791 119.126] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -346.791 -119.126] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+349.769 119.126 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 367.133 119.126] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -367.133 -119.126] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+367.133 119.126 Td
+/F134_0 9.9626 Tf
+(BZIP) 23.9102 Tj
+[1 0 0 1 391.043 119.126] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -391.043 -119.126] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+391.043 119.126 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-299 TJm
+(in) 7.7509 Tj
+-299 TJm
+(that) 14.9439 Tj
+-299 TJm
+(order) 21.0211 Tj
+40 TJm
+(,) 2.49065 Tj
+-311 TJm
+(and) 14.386 Tj
+-299 TJm
+(will) 15.5018 Tj
+-299 TJm
+(process) 29.8778 Tj
+-299 TJm
+(them) 19.9252 Tj
+72 107.171 Td
+(before) 25.4445 Tj
+-250 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-250 TJm
+(ar) 7.74094 Tj
+18 TJm
+(guments) 33.7633 Tj
+-250 TJm
+(read) 17.1456 Tj
+-250 TJm
+(from) 19.3673 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(command) 39.2925 Tj
+-250 TJm
+(line.) 17.4346 Tj
+-310 TJm
+(This) 17.7135 Tj
+-250 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(con) 14.386 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(enient) 24.3486 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ay) 9.40469 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(supply) 26.5703 Tj
+-250 TJm
+(def) 12.7222 Tj
+10 TJm
+(ault) 14.9439 Tj
+-250 TJm
+(ar) 7.74094 Tj
+18 TJm
+(guments.) 36.2539 Tj
+[1 0 0 1 72 105.014] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -95.0517] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 85.2534 Td
+/F130_0 9.9626 Tf
+(Compression) 52.5826 Tj
+-294 TJm
+(is) 6.64505 Tj
+-294 TJm
+(al) 7.193 Tj
+10 TJm
+(w) 7.193 Tj
+10 TJm
+(ays) 13.2801 Tj
+-294 TJm
+(performed,) 43.9849 Tj
+-305 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-294 TJm
+(if) 6.08715 Tj
+-294 TJm
+(the) 12.1743 Tj
+-294 TJm
+(compressed) 47.0334 Tj
+-294 TJm
+(\002le) 12.7322 Tj
+-293 TJm
+(is) 6.64505 Tj
+-294 TJm
+(slightly) 29.8978 Tj
+-294 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ger) 12.7222 Tj
+-294 TJm
+(than) 17.1556 Tj
+-294 TJm
+(the) 12.1743 Tj
+-294 TJm
+(original.) 33.4843 Tj
+-884 TJm
+(Files) 19.3773 Tj
+-294 TJm
+(of) 8.29885 Tj
+-294 TJm
+(less) 14.9439 Tj
+-294 TJm
+(than) 17.1556 Tj
+72 73.2982 Td
+(about) 22.1369 Tj
+-246 TJm
+(one) 14.386 Tj
+-246 TJm
+(hundred) 32.6474 Tj
+-245 TJm
+(bytes) 21.031 Tj
+-246 TJm
+(tend) 17.1556 Tj
+-246 TJm
+(to) 7.7509 Tj
+-246 TJm
+(get) 12.1743 Tj
+-246 TJm
+(l) 2.7696 Tj
+1 TJm
+(ar) 7.74094 Tj
+18 TJm
+(ger) 12.7222 Tj
+40 TJm
+(,) 2.49065 Tj
+-247 TJm
+(since) 20.4731 Tj
+-246 TJm
+(the) 12.1743 Tj
+-246 TJm
+(compression) 50.3609 Tj
+-245 TJm
+(mechanism) 45.3796 Tj
+-246 TJm
+(has) 13.2801 Tj
+-246 TJm
+(a) 4.42339 Tj
+-246 TJm
+(constant) 33.2053 Tj
+-246 TJm
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(erhead) 26.5503 Tj
+-245 TJm
+(in) 7.7509 Tj
+-246 TJm
+(the) 12.1743 Tj
+-246 TJm
+(re) 7.74094 Tj
+15 TJm
+(gion) 17.7135 Tj
+-246 TJm
+(of) 8.29885 Tj
+[1 0 0 1 72 50.8518] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 43.0633 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.332 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+539.395 50.9514 Td
+/F130_0 9.9626 Tf
+(3) 4.9813 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 7 7
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 105.519 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -371.59 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+477.109 749.245 Td
+/F130_0 9.9626 Tf
+(Ho) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+[1 0 0 1 266.071 747.089] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -741.554] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(50) 9.9626 Tj
+-264 TJm
+(bytes.) 23.5217 Tj
+-351 TJm
+(Random) 33.7633 Tj
+-264 TJm
+(dat) 12.1743 Tj
+1 TJm
+(a) 4.42339 Tj
+-264 TJm
+(\(including) 40.9562 Tj
+-264 TJm
+(the) 12.1743 Tj
+-264 TJm
+(output) 25.4644 Tj
+-263 TJm
+(of) 8.29885 Tj
+-264 TJm
+(most) 19.3773 Tj
+-264 TJm
+(\002le) 12.7322 Tj
+-263 TJm
+(compressors\)) 53.1206 Tj
+-264 TJm
+(is) 6.64505 Tj
+-264 TJm
+(coded) 23.7907 Tj
+-263 TJm
+(at) 7.193 Tj
+-264 TJm
+(about) 22.1369 Tj
+-264 TJm
+(8.05) 17.4346 Tj
+-263 TJm
+(bits) 14.396 Tj
+-264 TJm
+(per) 12.7222 Tj
+-264 TJm
+(byte,) 19.6462 Tj
+-267 TJm
+(gi) 7.7509 Tj
+25 TJm
+(ving) 17.7135 Tj
+-264 TJm
+(an) 9.40469 Tj
+72 698.082 Td
+(e) 4.42339 Tj
+15 TJm
+(xpansion) 35.9749 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(around) 27.6661 Tj
+-250 TJm
+(0.5%.) 23.2427 Tj
+[1 0 0 1 72 695.925] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -686.081] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 676.283 Td
+/F130_0 9.9626 Tf
+(As) 11.0684 Tj
+-268 TJm
+(a) 4.42339 Tj
+-268 TJm
+(self-check) 40.9363 Tj
+-269 TJm
+(for) 11.6164 Tj
+-268 TJm
+(your) 18.2614 Tj
+-268 TJm
+(protection,) 42.889 Tj
+[1 0 0 1 217.273 676.283] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -217.273 -676.283] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+217.273 676.283 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 247.161 676.283] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -247.161 -676.283] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+249.833 676.283 Td
+/F130_0 9.9626 Tf
+(uses) 17.1556 Tj
+-268 TJm
+(32-bit) 23.8007 Tj
+-268 TJm
+(CRCs) 23.8106 Tj
+-269 TJm
+(to) 7.7509 Tj
+-268 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-268 TJm
+(sure) 16.5977 Tj
+-268 TJm
+(that) 14.9439 Tj
+-268 TJm
+(the) 12.1743 Tj
+-269 TJm
+(decompressed) 56.4381 Tj
+-268 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-268 TJm
+(of) 8.29885 Tj
+-268 TJm
+(a) 4.42339 Tj
+-268 TJm
+(\002le) 12.7322 Tj
+-269 TJm
+(is) 6.64505 Tj
+72 664.328 Td
+(identical) 34.3112 Tj
+-200 TJm
+(to) 7.7509 Tj
+-199 TJm
+(the) 12.1743 Tj
+-200 TJm
+(original.) 33.4843 Tj
+-586 TJm
+(This) 17.7135 Tj
+-200 TJm
+(guards) 26.5603 Tj
+-199 TJm
+(ag) 9.40469 Tj
+5 TJm
+(ainst) 18.8194 Tj
+-200 TJm
+(corruption) 41.5042 Tj
+-199 TJm
+(of) 8.29885 Tj
+-200 TJm
+(the) 12.1743 Tj
+-200 TJm
+(compressed) 47.0334 Tj
+-199 TJm
+(data,) 19.0883 Tj
+-210 TJm
+(and) 14.386 Tj
+-199 TJm
+(ag) 9.40469 Tj
+5 TJm
+(ainst) 18.8194 Tj
+-200 TJm
+(undetected) 43.158 Tj
+-200 TJm
+(b) 4.9813 Tj
+20 TJm
+(ugs) 13.8381 Tj
+-199 TJm
+(in) 7.7509 Tj
+[1 0 0 1 510.112 664.328] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -510.112 -664.328] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+510.112 664.328 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 540 664.328] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -664.328] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 652.373 Td
+/F130_0 9.9626 Tf
+(\(hopefully) 41.5042 Tj
+-275 TJm
+(v) 4.9813 Tj
+15 TJm
+(ery) 12.7222 Tj
+-274 TJm
+(unlik) 20.4831 Tj
+10 TJm
+(ely\).) 17.9825 Tj
+-384 TJm
+(The) 15.4918 Tj
+-275 TJm
+(chances) 31.5316 Tj
+-275 TJm
+(of) 8.29885 Tj
+-275 TJm
+(data) 16.5977 Tj
+-274 TJm
+(corruption) 41.5042 Tj
+-275 TJm
+(going) 22.6948 Tj
+-275 TJm
+(undetected) 43.158 Tj
+-274 TJm
+(is) 6.64505 Tj
+-275 TJm
+(microscopic,) 51.1878 Tj
+-281 TJm
+(about) 22.1369 Tj
+-275 TJm
+(one) 14.386 Tj
+-274 TJm
+(chance) 27.6562 Tj
+-275 TJm
+(in) 7.7509 Tj
+-275 TJm
+(four) 16.5977 Tj
+72 640.417 Td
+(billion) 26.0223 Tj
+-279 TJm
+(for) 11.6164 Tj
+-279 TJm
+(each) 18.2515 Tj
+-279 TJm
+(\002le) 12.7322 Tj
+-280 TJm
+(processed.) 41.7732 Tj
+-795 TJm
+(Be) 11.0684 Tj
+-279 TJm
+(a) 4.42339 Tj
+15 TJm
+(w) 7.193 Tj
+10 TJm
+(are,) 14.655 Tj
+-286 TJm
+(though,) 30.1668 Tj
+-287 TJm
+(that) 14.9439 Tj
+-279 TJm
+(the) 12.1743 Tj
+-279 TJm
+(check) 23.2328 Tj
+-279 TJm
+(occurs) 26.0024 Tj
+-279 TJm
+(upon) 19.9252 Tj
+-279 TJm
+(decompression,) 62.2563 Tj
+-287 TJm
+(so) 8.85675 Tj
+-279 TJm
+(it) 5.53921 Tj
+-279 TJm
+(can) 13.8281 Tj
+-279 TJm
+(only) 17.7135 Tj
+-280 TJm
+(tell) 12.7322 Tj
+-279 TJm
+(you) 14.9439 Tj
+72 628.462 Td
+(that) 14.9439 Tj
+-237 TJm
+(something) 41.5142 Tj
+-236 TJm
+(is) 6.64505 Tj
+-237 TJm
+(wrong.) 27.9451 Tj
+-611 TJm
+(It) 6.08715 Tj
+-237 TJm
+(can') 17.1456 Tj
+18 TJm
+(t) 2.7696 Tj
+-237 TJm
+(help) 17.1556 Tj
+-237 TJm
+(you) 14.9439 Tj
+-236 TJm
+(reco) 17.1456 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-237 TJm
+(the) 12.1743 Tj
+-237 TJm
+(original) 30.9936 Tj
+-237 TJm
+(uncompressed) 56.996 Tj
+-236 TJm
+(data.) 19.0883 Tj
+-612 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-236 TJm
+(can) 13.8281 Tj
+-237 TJm
+(use) 13.2801 Tj
+[1 0 0 1 458.159 628.462] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -458.159 -628.462] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+458.159 628.462 Td
+/F134_0 9.9626 Tf
+(bzip2recover) 71.7307 Tj
+[1 0 0 1 529.89 628.462] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -529.89 -628.462] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+532.249 628.462 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+72 616.507 Td
+(try) 11.0684 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(reco) 17.1456 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(from) 19.3673 Tj
+-250 TJm
+(damaged) 35.965 Tj
+-250 TJm
+(\002les.) 19.0983 Tj
+[1 0 0 1 72 614.35] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -604.506] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 594.708 Td
+/F130_0 9.9626 Tf
+(Return) 27.1182 Tj
+-298 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+-406 TJm
+(0) 4.9813 Tj
+-298 TJm
+(for) 11.6164 Tj
+-298 TJm
+(a) 4.42339 Tj
+-298 TJm
+(normal) 28.224 Tj
+-298 TJm
+(e) 4.42339 Tj
+15 TJm
+(xit,) 13.0112 Tj
+-310 TJm
+(1) 4.9813 Tj
+-298 TJm
+(for) 11.6164 Tj
+-297 TJm
+(en) 9.40469 Tj
+40 TJm
+(vironmental) 48.1492 Tj
+-298 TJm
+(problems) 37.0808 Tj
+-298 TJm
+(\(\002le) 16.0497 Tj
+-298 TJm
+(not) 12.7322 Tj
+-298 TJm
+(found,) 25.7334 Tj
+-310 TJm
+(in) 7.7509 Tj
+40 TJm
+(v) 4.9813 Tj
+25 TJm
+(alid) 14.9439 Tj
+-298 TJm
+(\003ags,) 21.31 Tj
+-310 TJm
+(I/O) 13.2801 Tj
+-298 TJm
+(errors,) 25.7234 Tj
+-310 TJm
+(etc.\),) 19.9152 Tj
+-310 TJm
+(2) 4.9813 Tj
+-298 TJm
+(to) 7.7509 Tj
+72 582.753 Td
+(indicate) 31.5416 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(corrupt) 28.772 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le,) 15.2229 Tj
+-250 TJm
+(3) 4.9813 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(an) 9.40469 Tj
+-250 TJm
+(internal) 30.4357 Tj
+-250 TJm
+(consistenc) 41.5042 Tj
+15 TJm
+(y) 4.9813 Tj
+-250 TJm
+(error) 19.3573 Tj
+-250 TJm
+(\(e) 7.74094 Tj
+15 TJm
+(g,) 7.47195 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug\)) 13.2801 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(caused) 27.1082 Tj
+[1 0 0 1 443.065 582.753] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -443.065 -582.753] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+443.065 582.753 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 472.953 582.753] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.953 -582.753] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+475.444 582.753 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(panic.) 24.0696 Tj
+[1 0 0 1 72 580.596] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -570.752] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 548.118 Td
+/F122_0 20.6585 Tf
+(2.4.) 34.4584 Tj
+-278 TJm
+(OPTIONS) 92.9839 Tj
+[1 0 0 1 72 547.86] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -528.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 516.475 Td
+/F134_0 9.9626 Tf
+(-c) 11.9551 Tj
+-600 TJm
+(--stdout) 47.8205 Tj
+[1 0 0 1 137.753 516.475] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -68.2441 -0.1544] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -516.32] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 504.52 Td
+/F130_0 9.9626 Tf
+(Compress) 39.8504 Tj
+-250 TJm
+(or) 8.29885 Tj
+-250 TJm
+(decompress) 47.0334 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(standard) 33.7533 Tj
+-250 TJm
+(output.) 27.9551 Tj
+[1 0 0 1 72 502.363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.8664] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -488.652] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 478.854 Td
+/F134_0 9.9626 Tf
+(-d) 11.9551 Tj
+-600 TJm
+(--decompress) 71.7307 Tj
+[1 0 0 1 161.664 478.854] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -92.1544 -1.5341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -477.32] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 466.899 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(orce) 17.1456 Tj
+-296 TJm
+(decompression.) 62.2563 Tj
+[1 0 0 1 200.214 466.899] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -200.214 -466.899] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+200.214 466.899 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 230.102 466.899] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -230.102 -466.899] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+230.102 466.899 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 235.659 466.899] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -235.659 -466.899] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+235.659 466.899 Td
+/F134_0 9.9626 Tf
+(bunzip2) 41.8429 Tj
+[1 0 0 1 277.502 466.899] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -277.502 -466.899] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+280.454 466.899 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 297.791 466.899] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -297.791 -466.899] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+297.791 466.899 Td
+/F134_0 9.9626 Tf
+(bzcat) 29.8878 Tj
+[1 0 0 1 327.679 466.899] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -327.679 -466.899] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+330.631 466.899 Td
+/F130_0 9.9626 Tf
+(are) 12.1643 Tj
+-296 TJm
+(really) 22.6848 Tj
+-296 TJm
+(the) 12.1743 Tj
+-297 TJm
+(same) 20.4731 Tj
+-296 TJm
+(program,) 36.2439 Tj
+-308 TJm
+(and) 14.386 Tj
+-296 TJm
+(the) 12.1743 Tj
+-296 TJm
+(decision) 33.2053 Tj
+-297 TJm
+(about) 22.1369 Tj
+108 454.944 Td
+(what) 19.3673 Tj
+-303 TJm
+(actions) 28.224 Tj
+-303 TJm
+(to) 7.7509 Tj
+-303 TJm
+(tak) 12.1743 Tj
+10 TJm
+(e) 4.42339 Tj
+-303 TJm
+(is) 6.64505 Tj
+-303 TJm
+(done) 19.3673 Tj
+-303 TJm
+(on) 9.9626 Tj
+-304 TJm
+(the) 12.1743 Tj
+-303 TJm
+(basis) 19.9252 Tj
+-303 TJm
+(of) 8.29885 Tj
+-303 TJm
+(which) 24.3486 Tj
+-303 TJm
+(name) 21.579 Tj
+-303 TJm
+(is) 6.64505 Tj
+-303 TJm
+(used.) 20.7521 Tj
+-939 TJm
+(This) 17.7135 Tj
+-303 TJm
+(\003ag) 14.9439 Tj
+-303 TJm
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(errides) 27.1082 Tj
+-303 TJm
+(that) 14.9439 Tj
+-303 TJm
+(mechanism,) 47.8703 Tj
+-316 TJm
+(and) 14.386 Tj
+108 442.988 Td
+(forces) 24.3386 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(decompress.) 49.5241 Tj
+[1 0 0 1 72 440.832] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.8665] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -427.121] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 417.323 Td
+/F134_0 9.9626 Tf
+(-z) 11.9551 Tj
+-600 TJm
+(--compress) 59.7756 Tj
+[1 0 0 1 149.709 417.323] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -80.1993 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -415.789] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 405.368 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-250 TJm
+(complement) 49.2551 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 187.969 405.368] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -187.969 -405.368] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+187.969 405.368 Td
+/F134_0 9.9626 Tf
+(-d) 11.9551 Tj
+[1 0 0 1 199.924 405.368] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -199.924 -405.368] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+199.924 405.368 Td
+/F130_0 9.9626 Tf
+(:) 2.7696 Tj
+-310 TJm
+(forces) 24.3386 Tj
+-250 TJm
+(compression,) 52.8516 Tj
+-250 TJm
+(re) 7.74094 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(ardless) 27.6661 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(in) 7.7509 Tj
+40 TJm
+(v) 4.9813 Tj
+20 TJm
+(okation) 29.8878 Tj
+-250 TJm
+(name.) 24.0696 Tj
+[1 0 0 1 72 403.211] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.8665] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -389.5] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 379.702 Td
+/F134_0 9.9626 Tf
+(-t) 11.9551 Tj
+-600 TJm
+(--test) 35.8654 Tj
+[1 0 0 1 125.798 379.702] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -56.2889 -0.1544] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -379.548] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 367.747 Td
+/F130_0 9.9626 Tf
+(Check) 25.4544 Tj
+-270 TJm
+(inte) 14.9439 Tj
+15 TJm
+(grity) 18.8194 Tj
+-271 TJm
+(of) 8.29885 Tj
+-270 TJm
+(the) 12.1743 Tj
+-271 TJm
+(speci\002ed) 35.417 Tj
+-270 TJm
+(\002le\(s\),) 25.7334 Tj
+-276 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-270 TJm
+(don') 18.2614 Tj
+18 TJm
+(t) 2.7696 Tj
+-270 TJm
+(decompress) 47.0334 Tj
+-271 TJm
+(them.) 22.4159 Tj
+-742 TJm
+(This) 17.7135 Tj
+-271 TJm
+(really) 22.6848 Tj
+-270 TJm
+(performs) 35.965 Tj
+-270 TJm
+(a) 4.42339 Tj
+-271 TJm
+(trial) 16.0497 Tj
+-270 TJm
+(decompres-) 46.4755 Tj
+108 355.791 Td
+(sion) 16.6077 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(thro) 16.0497 Tj
+25 TJm
+(ws) 11.0684 Tj
+-250 TJm
+(a) 4.42339 Tj
+15 TJm
+(w) 7.193 Tj
+10 TJm
+(ay) 9.40469 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(result.) 24.6275 Tj
+[1 0 0 1 72 353.635] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.8664] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -339.924] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 330.126 Td
+/F134_0 9.9626 Tf
+(-f) 11.9551 Tj
+-600 TJm
+(--force) 41.8429 Tj
+[1 0 0 1 131.776 330.126] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -62.2665 -0.1544] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -329.971] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 318.171 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(orce) 17.1456 Tj
+-338 TJm
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(erwrite) 28.2141 Tj
+-339 TJm
+(of) 8.29885 Tj
+-338 TJm
+(output) 25.4644 Tj
+-338 TJm
+(\002les.) 19.0983 Tj
+-1150 TJm
+(Normally) 38.1866 Tj
+65 TJm
+(,) 2.49065 Tj
+[1 0 0 1 289.831 318.171] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -289.831 -318.171] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+289.831 318.171 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 319.719 318.171] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -319.719 -318.171] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+323.089 318.171 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-338 TJm
+(not) 12.7322 Tj
+-339 TJm
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(erwrite) 28.2141 Tj
+-338 TJm
+(e) 4.42339 Tj
+15 TJm
+(xisting) 27.1282 Tj
+-338 TJm
+(output) 25.4644 Tj
+-338 TJm
+(\002les.) 19.0983 Tj
+-1150 TJm
+(Also) 18.8194 Tj
+-339 TJm
+(forces) 24.3386 Tj
+[1 0 0 1 108 306.215] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -108 -306.215] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 306.215 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 137.888 306.215] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.888 -306.215] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+140.379 306.215 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(break) 22.1269 Tj
+-250 TJm
+(hard) 17.7035 Tj
+-250 TJm
+(links) 19.3773 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(\002les,) 19.0983 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(otherwise) 38.7346 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ouldn') 26.0123 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(do.) 12.4533 Tj
+[1 0 0 1 72 304.681] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -294.837] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 284.416 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 137.888 284.416] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.888 -284.416] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+141.211 284.416 Td
+/F130_0 9.9626 Tf
+(normally) 35.9749 Tj
+-334 TJm
+(declines) 32.6474 Tj
+-333 TJm
+(to) 7.7509 Tj
+-334 TJm
+(decompress) 47.0334 Tj
+-333 TJm
+(\002les) 16.6077 Tj
+-334 TJm
+(which) 24.3486 Tj
+-333 TJm
+(don') 18.2614 Tj
+18 TJm
+(t) 2.7696 Tj
+-334 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-333 TJm
+(the) 12.1743 Tj
+-334 TJm
+(correct) 27.6562 Tj
+-333 TJm
+(magic) 24.3486 Tj
+-334 TJm
+(header) 26.5503 Tj
+-333 TJm
+(bytes.) 23.5217 Tj
+-561 TJm
+(If) 6.63509 Tj
+-334 TJm
+(forced) 25.4445 Tj
+108 272.461 Td
+(\() 3.31755 Tj
+[1 0 0 1 111.318 272.461] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -111.318 -272.461] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+111.318 272.461 Td
+/F134_0 9.9626 Tf
+(-f) 11.9551 Tj
+[1 0 0 1 123.273 272.461] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -123.273 -272.461] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+123.273 272.461 Td
+/F130_0 9.9626 Tf
+(\),) 5.8082 Tj
+-250 TJm
+(ho) 9.9626 Tj
+25 TJm
+(we) 11.6164 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+40 TJm
+(,) 2.49065 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(will) 15.5018 Tj
+-250 TJm
+(pass) 17.1556 Tj
+-250 TJm
+(such) 18.2614 Tj
+-250 TJm
+(\002les) 16.6077 Tj
+-250 TJm
+(through) 30.9936 Tj
+-250 TJm
+(unmodi\002ed.) 47.8803 Tj
+-310 TJm
+(This) 17.7135 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(GNU) 21.579 Tj
+[1 0 0 1 412.585 272.461] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -412.585 -272.461] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+412.585 272.461 Td
+/F134_0 9.9626 Tf
+(gzip) 23.9102 Tj
+[1 0 0 1 436.496 272.461] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -436.496 -272.461] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+438.986 272.461 Td
+/F130_0 9.9626 Tf
+(beha) 18.8094 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(es.) 10.7895 Tj
+[1 0 0 1 72 270.304] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.8665] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -256.594] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 246.795 Td
+/F134_0 9.9626 Tf
+(-k) 11.9551 Tj
+-600 TJm
+(--keep) 35.8654 Tj
+[1 0 0 1 125.798 246.795] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -56.2889 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -245.261] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 234.84 Td
+/F130_0 9.9626 Tf
+(K) 7.193 Tj
+25 TJm
+(eep) 13.8281 Tj
+-250 TJm
+(\(don') 21.579 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(delete\)) 27.1082 Tj
+-250 TJm
+(input) 20.4831 Tj
+-250 TJm
+(\002les) 16.6077 Tj
+-250 TJm
+(during) 26.0123 Tj
+-250 TJm
+(compression) 50.3609 Tj
+-250 TJm
+(or) 8.29885 Tj
+-250 TJm
+(decompression.) 62.2563 Tj
+[1 0 0 1 72 232.683] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.8665] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -218.973] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 209.174 Td
+/F134_0 9.9626 Tf
+(-s) 11.9551 Tj
+-600 TJm
+(--small) 41.8429 Tj
+[1 0 0 1 131.776 209.174] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -62.2665 -0.1544] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -209.02] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 197.219 Td
+/F130_0 9.9626 Tf
+(Reduce) 29.8778 Tj
+-347 TJm
+(memory) 33.2053 Tj
+-347 TJm
+(usage,) 25.1755 Tj
+-371 TJm
+(for) 11.6164 Tj
+-346 TJm
+(compression,) 52.8516 Tj
+-371 TJm
+(decompression) 59.7656 Tj
+-347 TJm
+(and) 14.386 Tj
+-347 TJm
+(testing.) 29.0609 Tj
+-1201 TJm
+(Files) 19.3773 Tj
+-347 TJm
+(are) 12.1643 Tj
+-347 TJm
+(decompressed) 56.4381 Tj
+-346 TJm
+(and) 14.386 Tj
+-347 TJm
+(tested) 23.2427 Tj
+108 185.264 Td
+(using) 21.589 Tj
+-388 TJm
+(a) 4.42339 Tj
+-388 TJm
+(modi\002ed) 35.427 Tj
+-388 TJm
+(algorithm) 38.7446 Tj
+-389 TJm
+(which) 24.3486 Tj
+-388 TJm
+(only) 17.7135 Tj
+-388 TJm
+(requires) 32.0895 Tj
+-388 TJm
+(2.5) 12.4533 Tj
+-388 TJm
+(bytes) 21.031 Tj
+-388 TJm
+(per) 12.7222 Tj
+-388 TJm
+(block) 22.1369 Tj
+-389 TJm
+(byte.) 19.6462 Tj
+-1448 TJm
+(This) 17.7135 Tj
+-389 TJm
+(means) 25.4544 Tj
+-388 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-388 TJm
+(\002le) 12.7322 Tj
+-388 TJm
+(can) 13.8281 Tj
+-388 TJm
+(be) 9.40469 Tj
+108 173.309 Td
+(decompressed) 56.4381 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(2300k) 24.9065 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(memory) 33.2053 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(albeit) 22.1369 Tj
+-250 TJm
+(at) 7.193 Tj
+-250 TJm
+(about) 22.1369 Tj
+-250 TJm
+(half) 15.4918 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(normal) 28.224 Tj
+-250 TJm
+(speed.) 25.1755 Tj
+[1 0 0 1 72 171.152] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -161.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 151.51 Td
+/F130_0 9.9626 Tf
+(During) 28.224 Tj
+-252 TJm
+(compr) 25.4544 Tj
+1 TJm
+(ession,) 27.3972 Tj
+[1 0 0 1 194.09 151.51] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -194.09 -151.51] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+194.09 151.51 Td
+/F134_0 9.9626 Tf
+(-s) 11.9551 Tj
+[1 0 0 1 206.046 151.51] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -206.046 -151.51] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+208.551 151.51 Td
+/F130_0 9.9626 Tf
+(selects) 26.5603 Tj
+-251 TJm
+(a) 4.42339 Tj
+-252 TJm
+(block) 22.1369 Tj
+-251 TJm
+(size) 15.4918 Tj
+-252 TJm
+(of) 8.29885 Tj
+-252 TJm
+(200k,) 22.4159 Tj
+-251 TJm
+(which) 24.3486 Tj
+-252 TJm
+(limits) 22.7048 Tj
+-251 TJm
+(memory) 33.2053 Tj
+-252 TJm
+(use) 13.2801 Tj
+-251 TJm
+(to) 7.7509 Tj
+-252 TJm
+(around) 27.6661 Tj
+-251 TJm
+(the) 12.1743 Tj
+-252 TJm
+(same) 20.4731 Tj
+-251 TJm
+(\002gure,) 25.7334 Tj
+-252 TJm
+(at) 7.193 Tj
+108 139.554 Td
+(the) 12.1743 Tj
+-287 TJm
+(e) 4.42339 Tj
+15 TJm
+(xpense) 27.6661 Tj
+-287 TJm
+(of) 8.29885 Tj
+-288 TJm
+(your) 18.2614 Tj
+-287 TJm
+(compression) 50.3609 Tj
+-287 TJm
+(ratio.) 20.7521 Tj
+-843 TJm
+(In) 8.29885 Tj
+-287 TJm
+(short,) 22.4159 Tj
+-297 TJm
+(if) 6.08715 Tj
+-287 TJm
+(your) 18.2614 Tj
+-287 TJm
+(machine) 33.7533 Tj
+-287 TJm
+(is) 6.64505 Tj
+-287 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w) 7.193 Tj
+-287 TJm
+(on) 9.9626 Tj
+-288 TJm
+(memory) 33.2053 Tj
+-287 TJm
+(\(8) 8.29885 Tj
+-287 TJm
+(me) 12.1743 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(abytes) 25.4544 Tj
+-287 TJm
+(or) 8.29885 Tj
+-287 TJm
+(less\),) 20.7521 Tj
+108 127.599 Td
+(use) 13.2801 Tj
+[1 0 0 1 123.771 127.599] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -123.771 -127.599] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+123.771 127.599 Td
+/F134_0 9.9626 Tf
+(-s) 11.9551 Tj
+[1 0 0 1 135.726 127.599] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -135.726 -127.599] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+138.216 127.599 Td
+/F130_0 9.9626 Tf
+(for) 11.6164 Tj
+-250 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(erything.) 35.696 Tj
+-620 TJm
+(See) 14.386 Tj
+[1 0 0 1 220.079 127.599] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -220.079 -127.599] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+220.079 127.599 Td
+/F130_0 9.9626 Tf
+(MEMOR) 37.6387 Tj
+65 TJm
+(Y) 7.193 Tj
+-250 TJm
+(MAN) 23.2427 Tj
+35 TJm
+(A) 7.193 Tj
+40 TJm
+(GEMENT) 41.5042 Tj
+[1 0 0 1 337.946 127.599] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -337.946 -127.599] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+340.437 127.599 Td
+/F130_0 9.9626 Tf
+([5]) 11.6164 Tj
+[1 0 0 1 352.053 127.599] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -352.053 -127.599] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+354.544 127.599 Td
+/F130_0 9.9626 Tf
+(belo) 17.1556 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 125.443] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.8665] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -111.732] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 101.934 Td
+/F134_0 9.9626 Tf
+(-q) 11.9551 Tj
+-600 TJm
+(--quiet) 41.8429 Tj
+[1 0 0 1 131.776 101.934] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -62.2665 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -100.399] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 89.9784 Td
+/F130_0 9.9626 Tf
+(Suppress) 35.9749 Tj
+-221 TJm
+(non-essential) 52.5726 Tj
+-220 TJm
+(w) 7.193 Tj
+10 TJm
+(arning) 25.4544 Tj
+-221 TJm
+(messages.) 40.1194 Tj
+-300 TJm
+(Messages) 38.7346 Tj
+-221 TJm
+(pertaining) 40.3983 Tj
+-221 TJm
+(to) 7.7509 Tj
+-220 TJm
+(I/O) 13.2801 Tj
+-221 TJm
+(errors) 23.2328 Tj
+-221 TJm
+(and) 14.386 Tj
+-220 TJm
+(other) 20.4731 Tj
+-221 TJm
+(critical) 27.6661 Tj
+-221 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ents) 16.0497 Tj
+-221 TJm
+(wi) 9.9626 Tj
+1 TJm
+(ll) 5.53921 Tj
+-221 TJm
+(not) 12.7322 Tj
+108 78.0232 Td
+(be) 9.40469 Tj
+-250 TJm
+(suppressed.) 46.2065 Tj
+[1 0 0 1 72 75.8664] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.8664] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -21.1482] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 43.0633 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.332 -50.8518] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+539.395 50.8518 Td
+/F130_0 9.9626 Tf
+(4) 4.9813 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 8 8
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 105.519 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -371.59 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+477.109 749.245 Td
+/F130_0 9.9626 Tf
+(Ho) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+[1 0 0 1 266.071 747.089] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F134_0 9.9626 Tf
+(-v) 11.9551 Tj
+-600 TJm
+(--verbose) 53.798 Tj
+[1 0 0 1 143.731 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -74.2217 -0.1544] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -709.883] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 698.082 Td
+/F130_0 9.9626 Tf
+(V) 7.193 Tj
+111 TJm
+(erbose) 26.0024 Tj
+-323 TJm
+(mode) 22.1369 Tj
+-322 TJm
+(--) 6.63509 Tj
+-323 TJm
+(sho) 13.8381 Tj
+25 TJm
+(w) 7.193 Tj
+-322 TJm
+(the) 12.1743 Tj
+-323 TJm
+(compression) 50.3609 Tj
+-323 TJm
+(ratio) 18.2614 Tj
+-322 TJm
+(for) 11.6164 Tj
+-323 TJm
+(each) 18.2515 Tj
+-322 TJm
+(\002le) 12.7322 Tj
+-323 TJm
+(processed.) 41.7732 Tj
+-1056 TJm
+(Further) 29.3299 Tj
+[1 0 0 1 430.015 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -430.015 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+430.015 698.082 Td
+/F134_0 9.9626 Tf
+(-v) 11.9551 Tj
+[1 0 0 1 441.97 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -441.97 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+441.97 698.082 Td
+/F130_0 9.9626 Tf
+(') 3.31755 Tj
+55 TJm
+(s) 3.87545 Tj
+-323 TJm
+(increase) 32.6375 Tj
+-322 TJm
+(the) 12.1743 Tj
+-323 TJm
+(v) 4.9813 Tj
+15 TJm
+(erbosity) 32.0995 Tj
+108 686.127 Td
+(le) 7.193 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el,) 9.68365 Tj
+-250 TJm
+(spe) 13.2801 Tj
+25 TJm
+(wing) 19.9252 Tj
+-250 TJm
+(out) 12.7322 Tj
+-250 TJm
+(lots) 14.396 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(information) 47.0434 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(primarily) 37.0808 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(interest) 29.3299 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(diagnostic) 40.9562 Tj
+-250 TJm
+(purposes.) 37.9077 Tj
+[1 0 0 1 72 683.97] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -670.023] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 660.224 Td
+/F134_0 9.9626 Tf
+(-L) 11.9551 Tj
+-600 TJm
+(--license) 53.798 Tj
+-600 TJm
+(-V) 11.9551 Tj
+-600 TJm
+(--version) 53.798 Tj
+[1 0 0 1 221.44 660.224] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -151.93 -0.1544] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -660.07] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 648.269 Td
+/F130_0 9.9626 Tf
+(Display) 30.9936 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(softw) 22.1369 Tj
+10 TJm
+(are) 12.1643 Tj
+-250 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion,) 26.8392 Tj
+-250 TJm
+(license) 27.6661 Tj
+-250 TJm
+(terms) 22.1369 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(conditions.) 44.0048 Tj
+[1 0 0 1 72 646.112] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -632.165] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 622.366 Td
+/F134_0 9.9626 Tf
+(-1) 11.9551 Tj
+[1 0 0 1 83.9552 622.366] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -83.9552 -622.366] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.4458 622.366 Td
+/F130_0 9.9626 Tf
+(\(or) 11.6164 Tj
+[1 0 0 1 100.553 622.366] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -100.553 -622.366] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+100.553 622.366 Td
+/F134_0 9.9626 Tf
+(--fast) 35.8654 Tj
+[1 0 0 1 136.418 622.366] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -136.418 -622.366] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+136.418 622.366 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 152.468 622.366] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -152.468 -622.366] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+152.468 622.366 Td
+/F134_0 9.9626 Tf
+(-9) 11.9551 Tj
+[1 0 0 1 164.423 622.366] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -164.423 -622.366] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+166.914 622.366 Td
+/F130_0 9.9626 Tf
+(\(or) 11.6164 Tj
+[1 0 0 1 181.021 622.366] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -181.021 -622.366] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+181.021 622.366 Td
+/F134_0 9.9626 Tf
+(-best) 29.8878 Tj
+[1 0 0 1 210.909 622.366] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.909 -622.366] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.909 622.366 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+[1 0 0 1 214.226 622.366] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -142.226 -1.7832] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -620.583] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 610.411 Td
+/F130_0 9.9626 Tf
+(Set) 12.7322 Tj
+-288 TJm
+(the) 12.1743 Tj
+-289 TJm
+(block) 22.1369 Tj
+-288 TJm
+(size) 15.4918 Tj
+-288 TJm
+(to) 7.7509 Tj
+-288 TJm
+(100) 14.9439 Tj
+-289 TJm
+(k,) 7.47195 Tj
+-298 TJm
+(200) 14.9439 Tj
+-288 TJm
+(k) 4.9813 Tj
+-288 TJm
+(...) 7.47195 Tj
+-850 TJm
+(900) 14.9439 Tj
+-288 TJm
+(k) 4.9813 Tj
+-288 TJm
+(when) 21.579 Tj
+-289 TJm
+(compressing.) 52.8516 Tj
+-849 TJm
+(Has) 15.4918 Tj
+-289 TJm
+(no) 9.9626 Tj
+-288 TJm
+(ef) 7.74094 Tj
+25 TJm
+(fect) 14.9339 Tj
+-288 TJm
+(when) 21.579 Tj
+-288 TJm
+(decompressing.) 62.2563 Tj
+-850 TJm
+(See) 14.386 Tj
+[1 0 0 1 108 598.456] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -108 -598.456] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 598.456 Td
+/F130_0 9.9626 Tf
+(MEMOR) 37.6387 Tj
+65 TJm
+(Y) 7.193 Tj
+-297 TJm
+(MAN) 23.2427 Tj
+35 TJm
+(A) 7.193 Tj
+40 TJm
+(GEMENT) 41.5042 Tj
+[1 0 0 1 226.338 598.456] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -226.338 -598.456] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+229.3 598.456 Td
+/F130_0 9.9626 Tf
+([5]) 11.6164 Tj
+[1 0 0 1 240.916 598.456] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -240.916 -598.456] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+243.878 598.456 Td
+/F130_0 9.9626 Tf
+(belo) 17.1556 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(.) 2.49065 Tj
+-904 TJm
+(The) 15.4918 Tj
+[1 0 0 1 297.278 598.456] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -297.278 -598.456] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+297.278 598.456 Td
+/F134_0 9.9626 Tf
+(--fast) 35.8654 Tj
+[1 0 0 1 333.144 598.456] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -333.144 -598.456] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+336.106 598.456 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 353.454 598.456] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -353.454 -598.456] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+353.454 598.456 Td
+/F134_0 9.9626 Tf
+(--best) 35.8654 Tj
+[1 0 0 1 389.319 598.456] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -389.319 -598.456] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+392.281 598.456 Td
+/F130_0 9.9626 Tf
+(aliases) 26.5603 Tj
+-297 TJm
+(are) 12.1643 Tj
+-298 TJm
+(primarily) 37.0808 Tj
+-297 TJm
+(for) 11.6164 Tj
+-297 TJm
+(GNU) 21.579 Tj
+[1 0 0 1 516.09 598.456] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -516.09 -598.456] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+516.09 598.456 Td
+/F134_0 9.9626 Tf
+(gzip) 23.9102 Tj
+[1 0 0 1 540 598.456] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -598.456] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 586.501 Td
+/F130_0 9.9626 Tf
+(compatibility) 53.1405 Tj
+65 TJm
+(.) 2.49065 Tj
+-356 TJm
+(In) 8.29885 Tj
+-265 TJm
+(particular) 38.1767 Tj
+40 TJm
+(,) 2.49065 Tj
+[1 0 0 1 220.423 586.501] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -220.423 -586.501] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+220.423 586.501 Td
+/F134_0 9.9626 Tf
+(--fast) 35.8654 Tj
+[1 0 0 1 256.288 586.501] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -256.288 -586.501] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+258.932 586.501 Td
+/F130_0 9.9626 Tf
+(doesn') 26.5603 Tj
+18 TJm
+(t) 2.7696 Tj
+-265 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-266 TJm
+(things) 24.3586 Tj
+-265 TJm
+(signi\002cantly) 49.2651 Tj
+-265 TJm
+(f) 3.31755 Tj
+10 TJm
+(aster) 18.8094 Tj
+55 TJm
+(.) 2.49065 Tj
+-712 TJm
+(And) 17.1556 Tj
+[1 0 0 1 444.622 586.501] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.622 -586.501] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+444.622 586.501 Td
+/F134_0 9.9626 Tf
+(--best) 35.8654 Tj
+[1 0 0 1 480.487 586.501] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -480.487 -586.501] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+483.131 586.501 Td
+/F130_0 9.9626 Tf
+(merely) 27.6661 Tj
+-265 TJm
+(selects) 26.5603 Tj
+108 574.546 Td
+(the) 12.1743 Tj
+-250 TJm
+(def) 12.7222 Tj
+10 TJm
+(ault) 14.9439 Tj
+-250 TJm
+(beha) 18.8094 Tj
+20 TJm
+(viour) 21.031 Tj
+55 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 574.446] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -560.498] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 548.643 Td
+/F134_0 9.9626 Tf
+(--) 11.9551 Tj
+[1 0 0 1 83.9552 548.643] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -14.4458 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -548.643] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 536.688 Td
+/F130_0 9.9626 Tf
+(T) 6.08715 Tj
+35 TJm
+(reats) 18.8094 Tj
+-261 TJm
+(all) 9.9626 Tj
+-261 TJm
+(subsequent) 44.2738 Tj
+-260 TJm
+(ar) 7.74094 Tj
+18 TJm
+(guments) 33.7633 Tj
+-261 TJm
+(as) 8.29885 Tj
+-261 TJm
+(\002le) 12.7322 Tj
+-261 TJm
+(names,) 27.9451 Tj
+-263 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-261 TJm
+(if) 6.08715 Tj
+-261 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-260 TJm
+(start) 17.1556 Tj
+-261 TJm
+(with) 17.7135 Tj
+-261 TJm
+(a) 4.42339 Tj
+-261 TJm
+(dash.) 20.7521 Tj
+-685 TJm
+(This) 17.7135 Tj
+-260 TJm
+(is) 6.64505 Tj
+-261 TJm
+(so) 8.85675 Tj
+-261 TJm
+(you) 14.9439 Tj
+-261 TJm
+(can) 13.8281 Tj
+-260 TJm
+(handle) 26.5603 Tj
+-261 TJm
+(\002les) 16.6077 Tj
+108 524.732 Td
+(with) 17.7135 Tj
+-250 TJm
+(names) 25.4544 Tj
+-250 TJm
+(be) 9.40469 Tj
+15 TJm
+(ginning) 30.4457 Tj
+-250 TJm
+(with) 17.7135 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(dash,) 20.7521 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(e) 4.42339 Tj
+15 TJm
+(xample:) 32.0995 Tj
+[1 0 0 1 302.27 524.732] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -302.27 -524.732] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+302.27 524.732 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+-600 TJm
+(--) 11.9551 Tj
+-600 TJm
+(-myfilename) 65.7532 Tj
+[1 0 0 1 421.821 524.732] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -421.821 -524.732] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+421.821 524.732 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 522.576] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -508.628] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 498.83 Td
+/F134_0 9.9626 Tf
+(--repetitive-fast) 101.619 Tj
+[1 0 0 1 173.619 498.83] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -173.619 -498.83] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+173.619 498.83 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 178.6 498.83] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -183.582 -498.83] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+183.582 498.83 Td
+/F134_0 9.9626 Tf
+(--repetitive-best) 101.619 Tj
+[1 0 0 1 285.2 498.83] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -215.691 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -497.295] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 486.874 Td
+/F130_0 9.9626 Tf
+(These) 23.7907 Tj
+-207 TJm
+(\003ags) 18.8194 Tj
+-206 TJm
+(are) 12.1643 Tj
+-207 TJm
+(redundant) 39.8404 Tj
+-207 TJm
+(in) 7.7509 Tj
+-206 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions) 28.224 Tj
+-207 TJm
+(0.9.5) 19.9252 Tj
+-207 TJm
+(and) 14.386 Tj
+-206 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e.) 6.91404 Tj
+-591 TJm
+(The) 15.4918 Tj
+15 TJm
+(y) 4.9813 Tj
+-207 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vided) 22.1369 Tj
+-207 TJm
+(some) 21.031 Tj
+-207 TJm
+(c) 4.42339 Tj
+1 TJm
+(o) 4.9813 Tj
+-1 TJm
+(a) 4.42339 Tj
+1 TJm
+(rse) 11.6164 Tj
+-207 TJm
+(control) 28.224 Tj
+-207 TJm
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-207 TJm
+(the) 12.1743 Tj
+-206 TJm
+(beha) 18.8094 Tj
+20 TJm
+(viour) 21.031 Tj
+108 474.919 Td
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-251 TJm
+(sorting) 27.6761 Tj
+-250 TJm
+(algorithm) 38.7446 Tj
+-250 TJm
+(in) 7.7509 Tj
+-251 TJm
+(earlier) 25.4445 Tj
+-250 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions,) 30.7147 Tj
+-250 TJm
+(which) 24.3486 Tj
+-251 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-250 TJm
+(sometimes) 42.62 Tj
+-250 TJm
+(useful.) 26.8392 Tj
+-622 TJm
+(0.9.5) 19.9252 Tj
+-251 TJm
+(and) 14.386 Tj
+-250 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-251 TJm
+(an) 9.40469 Tj
+-250 TJm
+(impro) 23.8007 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(ed) 9.40469 Tj
+108 462.964 Td
+(algorithm) 38.7446 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(renders) 29.3199 Tj
+-250 TJm
+(these) 20.4731 Tj
+-250 TJm
+(\003ags) 18.8194 Tj
+-250 TJm
+(irrele) 21.0211 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(ant.) 14.6649 Tj
+[1 0 0 1 72 460.807] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -436.897] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 414.264 Td
+/F122_0 20.6585 Tf
+(2.5.) 34.4584 Tj
+-278 TJm
+(MEMOR) 79.184 Tj
+50 TJm
+(Y) 13.7792 Tj
+-278 TJm
+(MANA) 61.9548 Tj
+50 TJm
+(GEMENT) 88.3771 Tj
+[1 0 0 1 72 414.005] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -404.043] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 392.346 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 392.346] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -392.346] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.454 392.346 Td
+/F130_0 9.9626 Tf
+(compresses) 45.9276 Tj
+-258 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ge) 9.40469 Tj
+-257 TJm
+(\002les) 16.6077 Tj
+-258 TJm
+(in) 7.7509 Tj
+-257 TJm
+(blocks.) 28.503 Tj
+-666 TJm
+(The) 15.4918 Tj
+-257 TJm
+(block) 22.1369 Tj
+-258 TJm
+(size) 15.4918 Tj
+-258 TJm
+(af) 7.74094 Tj
+25 TJm
+(fects) 18.8094 Tj
+-257 TJm
+(both) 17.7135 Tj
+-258 TJm
+(the) 12.1743 Tj
+-257 TJm
+(compression) 50.3609 Tj
+-258 TJm
+(ratio) 18.2614 Tj
+-257 TJm
+(achie) 21.0211 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ed,) 11.8953 Tj
+-260 TJm
+(and) 14.386 Tj
+-258 TJm
+(the) 12.1743 Tj
+-257 TJm
+(amount) 29.8878 Tj
+72 380.391 Td
+(of) 8.29885 Tj
+-215 TJm
+(memory) 33.2053 Tj
+-215 TJm
+(needed) 28.2141 Tj
+-215 TJm
+(for) 11.6164 Tj
+-215 TJm
+(compression) 50.3609 Tj
+-214 TJm
+(and) 14.386 Tj
+-215 TJm
+(decompression.) 62.2563 Tj
+-597 TJm
+(The) 15.4918 Tj
+-215 TJm
+(\003ags) 18.8194 Tj
+[1 0 0 1 337.719 380.391] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -337.719 -380.391] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+337.719 380.391 Td
+/F134_0 9.9626 Tf
+(-1) 11.9551 Tj
+[1 0 0 1 349.674 380.391] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -349.674 -380.391] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+351.815 380.391 Td
+/F130_0 9.9626 Tf
+(through) 30.9936 Tj
+[1 0 0 1 384.95 380.391] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -384.95 -380.391] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+384.95 380.391 Td
+/F134_0 9.9626 Tf
+(-9) 11.9551 Tj
+[1 0 0 1 396.905 380.391] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -396.905 -380.391] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+399.046 380.391 Td
+/F130_0 9.9626 Tf
+(specify) 28.772 Tj
+-215 TJm
+(the) 12.1743 Tj
+-215 TJm
+(block) 22.1369 Tj
+-215 TJm
+(size) 15.4918 Tj
+-215 TJm
+(to) 7.7509 Tj
+-214 TJm
+(be) 9.40469 Tj
+-215 TJm
+(100,000) 32.3785 Tj
+72 368.435 Td
+(bytes) 21.031 Tj
+-278 TJm
+(through) 30.9936 Tj
+-277 TJm
+(900,000) 32.3785 Tj
+-278 TJm
+(bytes) 21.031 Tj
+-278 TJm
+(\(the) 15.4918 Tj
+-277 TJm
+(def) 12.7222 Tj
+10 TJm
+(ault\)) 18.2614 Tj
+-278 TJm
+(respecti) 30.9837 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ely) 12.1743 Tj
+65 TJm
+(.) 2.49065 Tj
+-786 TJm
+(At) 9.9626 Tj
+-278 TJm
+(decompression) 59.7656 Tj
+-278 TJm
+(time,) 20.2042 Tj
+-284 TJm
+(the) 12.1743 Tj
+-278 TJm
+(block) 22.1369 Tj
+-278 TJm
+(size) 15.4918 Tj
+-277 TJm
+(used) 18.2614 Tj
+-278 TJm
+(for) 11.6164 Tj
+-278 TJm
+(compression) 50.3609 Tj
+72 356.48 Td
+(is) 6.64505 Tj
+-243 TJm
+(read) 17.1456 Tj
+-242 TJm
+(from) 19.3673 Tj
+-243 TJm
+(the) 12.1743 Tj
+-242 TJm
+(header) 26.5503 Tj
+-243 TJm
+(of) 8.29885 Tj
+-242 TJm
+(the) 12.1743 Tj
+-243 TJm
+(compressed) 47.0334 Tj
+-242 TJm
+(\002le,) 15.2229 Tj
+-244 TJm
+(and) 14.386 Tj
+[1 0 0 1 275.174 356.48] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -275.174 -356.48] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+275.174 356.48 Td
+/F134_0 9.9626 Tf
+(bunzip2) 41.8429 Tj
+[1 0 0 1 317.017 356.48] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -317.017 -356.48] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+319.433 356.48 Td
+/F130_0 9.9626 Tf
+(then) 17.1556 Tj
+-243 TJm
+(all) 9.9626 Tj
+1 TJm
+(o) 4.9813 Tj
+-1 TJm
+(c) 4.42339 Tj
+1 TJm
+(ates) 15.4918 Tj
+-243 TJm
+(itself) 19.9252 Tj
+-242 TJm
+(just) 14.396 Tj
+-243 TJm
+(enough) 29.3299 Tj
+-243 TJm
+(memory) 33.2053 Tj
+-242 TJm
+(to) 7.7509 Tj
+-243 TJm
+(decompress) 47.0334 Tj
+72 344.525 Td
+(the) 12.1743 Tj
+-303 TJm
+(\002le.) 15.2229 Tj
+-940 TJm
+(Since) 22.1369 Tj
+-304 TJm
+(block) 22.1369 Tj
+-303 TJm
+(sizes) 19.3673 Tj
+-303 TJm
+(are) 12.1643 Tj
+-303 TJm
+(stored) 24.3486 Tj
+-304 TJm
+(in) 7.7509 Tj
+-303 TJm
+(compressed) 47.0334 Tj
+-303 TJm
+(\002les,) 19.0983 Tj
+-317 TJm
+(it) 5.53921 Tj
+-303 TJm
+(follo) 18.8194 Tj
+25 TJm
+(ws) 11.0684 Tj
+-304 TJm
+(that) 14.9439 Tj
+-303 TJm
+(the) 12.1743 Tj
+-303 TJm
+(\003ags) 18.8194 Tj
+[1 0 0 1 406.35 344.525] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -406.35 -344.525] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+406.35 344.525 Td
+/F134_0 9.9626 Tf
+(-1) 11.9551 Tj
+[1 0 0 1 418.305 344.525] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -418.305 -344.525] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+421.327 344.525 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+[1 0 0 1 432.1 344.525] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -432.1 -344.525] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+432.1 344.525 Td
+/F134_0 9.9626 Tf
+(-9) 11.9551 Tj
+[1 0 0 1 444.055 344.525] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.055 -344.525] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+447.077 344.525 Td
+/F130_0 9.9626 Tf
+(are) 12.1643 Tj
+-303 TJm
+(irrele) 21.0211 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(ant) 12.1743 Tj
+-304 TJm
+(to) 7.7509 Tj
+-303 TJm
+(and) 14.386 Tj
+-303 TJm
+(so) 8.85675 Tj
+72 332.57 Td
+(ignored) 30.4357 Tj
+-250 TJm
+(during) 26.0123 Tj
+-250 TJm
+(decompression.) 62.2563 Tj
+[1 0 0 1 72 330.413] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -320.45] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 310.652 Td
+/F130_0 9.9626 Tf
+(Compression) 52.5826 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(decompression) 59.7656 Tj
+-250 TJm
+(requirements,) 54.5054 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(bytes,) 23.5217 Tj
+-250 TJm
+(can) 13.8281 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(estimated) 38.1866 Tj
+-250 TJm
+(as:) 11.0684 Tj
+[1 0 0 1 72 308.495] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -60.7721] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 59.7758 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 56.1893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -299.13] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 299.13 Td
+/F134_0 9.9626 Tf
+(Compression:) 71.7307 Tj
+-1278 TJm
+(400k) 23.9102 Tj
+-426 TJm
+(+) 5.97756 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(8) 5.97756 Tj
+-426 TJm
+(x) 5.97756 Tj
+-426 TJm
+(block) 29.8878 Tj
+-426 TJm
+(size) 23.9102 Tj
+-426 TJm
+(\)) 5.97756 Tj
+90 275.22 Td
+(Decompression:) 83.6858 Tj
+-426 TJm
+(100k) 23.9102 Tj
+-426 TJm
+(+) 5.97756 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(4) 5.97756 Tj
+-426 TJm
+(x) 5.97756 Tj
+-426 TJm
+(block) 29.8878 Tj
+-426 TJm
+(size) 23.9102 Tj
+-426 TJm
+(\),) 11.9551 Tj
+-426 TJm
+(or) 11.9551 Tj
+153.66 263.265 Td
+(100k) 23.9102 Tj
+-426 TJm
+(+) 5.97756 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(2.5) 17.9327 Tj
+-426 TJm
+(x) 5.97756 Tj
+-426 TJm
+(block) 29.8878 Tj
+-426 TJm
+(size) 23.9102 Tj
+-426 TJm
+(\)) 5.97756 Tj
+[1 0 0 1 72 247.723] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -237.761] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 225.805 Td
+/F130_0 9.9626 Tf
+(Lar) 13.8281 Tj
+18 TJm
+(ger) 12.7222 Tj
+-292 TJm
+(block) 22.1369 Tj
+-292 TJm
+(sizes) 19.3673 Tj
+-291 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-292 TJm
+(rapidly) 28.224 Tj
+-292 TJm
+(diminishing) 47.6113 Tj
+-292 TJm
+(mar) 15.4918 Tj
+18 TJm
+(ginal) 19.9252 Tj
+-291 TJm
+(returns.) 30.1568 Tj
+-871 TJm
+(Most) 20.4831 Tj
+-292 TJm
+(of) 8.29885 Tj
+-291 TJm
+(the) 12.1743 Tj
+-292 TJm
+(compression) 50.3609 Tj
+-292 TJm
+(comes) 25.4544 Tj
+-292 TJm
+(from) 19.3673 Tj
+-291 TJm
+(the) 12.1743 Tj
+-292 TJm
+(\002rst) 15.5018 Tj
+-292 TJm
+(tw) 9.9626 Tj
+10 TJm
+(o) 4.9813 Tj
+-292 TJm
+(or) 8.29885 Tj
+72 213.85 Td
+(three) 19.9152 Tj
+-232 TJm
+(hundred) 32.6474 Tj
+-232 TJm
+(k) 4.9813 Tj
+-232 TJm
+(of) 8.29885 Tj
+-232 TJm
+(block) 22.1369 Tj
+-232 TJm
+(size,) 17.9825 Tj
+-235 TJm
+(a) 4.42339 Tj
+-232 TJm
+(f) 3.31755 Tj
+10 TJm
+(act) 11.6164 Tj
+-232 TJm
+(w) 7.193 Tj
+10 TJm
+(orth) 16.0497 Tj
+-232 TJm
+(bearing) 29.8778 Tj
+-232 TJm
+(in) 7.7509 Tj
+-232 TJm
+(mind) 20.4831 Tj
+-232 TJm
+(when) 21.579 Tj
+-231 TJm
+(using) 21.589 Tj
+[1 0 0 1 354.025 213.85] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -354.025 -213.85] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+354.025 213.85 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 383.913 213.85] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -383.913 -213.85] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+386.223 213.85 Td
+/F130_0 9.9626 Tf
+(on) 9.9626 Tj
+-232 TJm
+(small) 21.589 Tj
+-232 TJm
+(machines.) 40.1194 Tj
+-304 TJm
+(It) 6.08715 Tj
+-232 TJm
+(is) 6.64505 Tj
+-232 TJm
+(also) 16.0497 Tj
+-231 TJm
+(important) 38.7446 Tj
+72 201.895 Td
+(to) 7.7509 Tj
+-250 TJm
+(appreciate) 40.9363 Tj
+-250 TJm
+(that) 14.9439 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(decompression) 59.7656 Tj
+-250 TJm
+(memory) 33.2053 Tj
+-250 TJm
+(requirement) 48.1393 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(set) 11.0684 Tj
+-250 TJm
+(at) 7.193 Tj
+-250 TJm
+(compression) 50.3609 Tj
+-250 TJm
+(time) 17.7135 Tj
+-250 TJm
+(by) 9.9626 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(choice) 26.0024 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(block) 22.1369 Tj
+-250 TJm
+(size.) 17.9825 Tj
+[1 0 0 1 72 199.738] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -189.776] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 179.977 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-388 TJm
+(\002les) 16.6077 Tj
+-389 TJm
+(compressed) 47.0334 Tj
+-388 TJm
+(with) 17.7135 Tj
+-389 TJm
+(the) 12.1743 Tj
+-388 TJm
+(def) 12.7222 Tj
+10 TJm
+(ault) 14.9439 Tj
+-389 TJm
+(900k) 19.9252 Tj
+-388 TJm
+(block) 22.1369 Tj
+-389 TJm
+(size,) 17.9825 Tj
+[1 0 0 1 302.002 179.977] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -302.002 -179.977] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+302.002 179.977 Td
+/F134_0 9.9626 Tf
+(bunzip2) 41.8429 Tj
+[1 0 0 1 343.846 179.977] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -343.846 -179.977] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+347.715 179.977 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-388 TJm
+(require) 28.2141 Tj
+-389 TJm
+(about) 22.1369 Tj
+-388 TJm
+(3700) 19.9252 Tj
+-389 TJm
+(kbytes) 26.0123 Tj
+-388 TJm
+(to) 7.7509 Tj
+-389 TJm
+(decompress.) 49.5241 Tj
+72 168.022 Td
+(T) 6.08715 Tj
+80 TJm
+(o) 4.9813 Tj
+-424 TJm
+(support) 29.8878 Tj
+-425 TJm
+(decompression) 59.7656 Tj
+-424 TJm
+(of) 8.29885 Tj
+-424 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-425 TJm
+(\002l) 8.30881 Tj
+1 TJm
+(e) 4.42339 Tj
+-425 TJm
+(on) 9.9626 Tj
+-424 TJm
+(a) 4.42339 Tj
+-424 TJm
+(4) 4.9813 Tj
+-425 TJm
+(me) 12.1743 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(abyte) 21.579 Tj
+-424 TJm
+(machine,) 36.2439 Tj
+[1 0 0 1 348.272 168.022] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -348.272 -168.022] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+348.272 168.022 Td
+/F134_0 9.9626 Tf
+(bunzip2) 41.8429 Tj
+[1 0 0 1 390.115 168.022] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -390.115 -168.022] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+394.342 168.022 Td
+/F130_0 9.9626 Tf
+(has) 13.2801 Tj
+-424 TJm
+(an) 9.40469 Tj
+-425 TJm
+(option) 25.4644 Tj
+-424 TJm
+(to) 7.7509 Tj
+-424 TJm
+(decompress) 47.0334 Tj
+-424 TJm
+(using) 21.589 Tj
+72 156.067 Td
+(approximately) 57.5539 Tj
+-281 TJm
+(half) 15.4918 Tj
+-281 TJm
+(this) 14.396 Tj
+-280 TJm
+(amount) 29.8878 Tj
+-281 TJm
+(of) 8.29885 Tj
+-281 TJm
+(memory) 33.2053 Tj
+65 TJm
+(,) 2.49065 Tj
+-288 TJm
+(about) 22.1369 Tj
+-281 TJm
+(2300) 19.9252 Tj
+-281 TJm
+(kbytes.) 28.503 Tj
+-805 TJm
+(Decompression) 61.9773 Tj
+-280 TJm
+(speed) 22.6848 Tj
+-281 TJm
+(is) 6.64505 Tj
+-281 TJm
+(also) 16.0497 Tj
+-281 TJm
+(halv) 17.1556 Tj
+15 TJm
+(ed,) 11.8953 Tj
+-288 TJm
+(so) 8.85675 Tj
+-281 TJm
+(you) 14.9439 Tj
+-281 TJm
+(should) 26.5703 Tj
+72 144.112 Td
+(use) 13.2801 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(option) 25.4644 Tj
+-250 TJm
+(only) 17.7135 Tj
+-250 TJm
+(where) 24.3386 Tj
+-250 TJm
+(necessary) 38.7246 Tj
+65 TJm
+(.) 2.49065 Tj
+-620 TJm
+(The) 15.4918 Tj
+-250 TJm
+(rele) 14.9339 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(ant) 12.1743 Tj
+-250 TJm
+(\003ag) 14.9439 Tj
+-250 TJm
+(is) 6.64505 Tj
+[1 0 0 1 305.024 144.112] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -305.024 -144.112] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+305.024 144.112 Td
+/F134_0 9.9626 Tf
+(-s) 11.9551 Tj
+[1 0 0 1 316.979 144.112] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -316.979 -144.112] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+316.979 144.112 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 141.955] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -131.992] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 122.194 Td
+/F130_0 9.9626 Tf
+(In) 8.29885 Tj
+-204 TJm
+(general,) 31.8106 Tj
+-214 TJm
+(try) 11.0684 Tj
+-204 TJm
+(and) 14.386 Tj
+-205 TJm
+(use) 13.2801 Tj
+-204 TJm
+(the) 12.1743 Tj
+-204 TJm
+(lar) 10.5105 Tj
+18 TJm
+(gest) 16.0497 Tj
+-205 TJm
+(block) 22.1369 Tj
+-204 TJm
+(size) 15.4918 Tj
+-205 TJm
+(memory) 33.2053 Tj
+-204 TJm
+(constraints) 43.1679 Tj
+-204 TJm
+(allo) 14.9439 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(,) 2.49065 Tj
+-214 TJm
+(since) 20.4731 Tj
+-204 TJm
+(that) 14.9439 Tj
+-205 TJm
+(maximises) 42.62 Tj
+-204 TJm
+(the) 12.1743 Tj
+-204 TJm
+(compression) 50.3609 Tj
+-205 TJm
+(achie) 21.0211 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ed.) 11.8953 Tj
+72 110.239 Td
+(Compression) 52.5826 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(decompression) 59.7656 Tj
+-250 TJm
+(speed) 22.6848 Tj
+-250 TJm
+(are) 12.1643 Tj
+-250 TJm
+(virtually) 33.7633 Tj
+-250 TJm
+(unaf) 17.7035 Tj
+25 TJm
+(fected) 24.3386 Tj
+-250 TJm
+(by) 9.9626 Tj
+-250 TJm
+(block) 22.1369 Tj
+-250 TJm
+(size.) 17.9825 Tj
+[1 0 0 1 72 108.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -98.1193] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 88.321 Td
+/F130_0 9.9626 Tf
+(Another) 32.6474 Tj
+-296 TJm
+(signi\002cant) 41.5142 Tj
+-296 TJm
+(point) 20.4831 Tj
+-295 TJm
+(applies) 28.224 Tj
+-296 TJm
+(to) 7.7509 Tj
+-296 TJm
+(\002les) 16.6077 Tj
+-296 TJm
+(which) 24.3486 Tj
+-296 TJm
+(\002t) 8.30881 Tj
+-296 TJm
+(in) 7.7509 Tj
+-296 TJm
+(a) 4.42339 Tj
+-295 TJm
+(single) 23.8007 Tj
+-296 TJm
+(block) 22.1369 Tj
+-296 TJm
+(--) 6.63509 Tj
+-296 TJm
+(that) 14.9439 Tj
+-296 TJm
+(means) 25.4544 Tj
+-296 TJm
+(most) 19.3773 Tj
+-295 TJm
+(\002les) 16.6077 Tj
+-296 TJm
+(you') 18.2614 Tj
+50 TJm
+(d) 4.9813 Tj
+-296 TJm
+(encounter) 39.2825 Tj
+-296 TJm
+(using) 21.589 Tj
+-296 TJm
+(a) 4.42339 Tj
+72 76.3658 Td
+(lar) 10.5105 Tj
+18 TJm
+(ge) 9.40469 Tj
+-290 TJm
+(block) 22.1369 Tj
+-290 TJm
+(size.) 17.9825 Tj
+-859 TJm
+(The) 15.4918 Tj
+-290 TJm
+(amount) 29.8878 Tj
+-290 TJm
+(of) 8.29885 Tj
+-290 TJm
+(real) 14.9339 Tj
+-290 TJm
+(memory) 33.2053 Tj
+-289 TJm
+(touched) 31.5416 Tj
+-290 TJm
+(is) 6.64505 Tj
+-290 TJm
+(proportional) 49.2551 Tj
+-290 TJm
+(to) 7.7509 Tj
+-290 TJm
+(the) 12.1743 Tj
+-290 TJm
+(size) 15.4918 Tj
+-290 TJm
+(of) 8.29885 Tj
+-290 TJm
+(the) 12.1743 Tj
+-289 TJm
+(\002le,) 15.2229 Tj
+-300 TJm
+(since) 20.4731 Tj
+-290 TJm
+(the) 12.1743 Tj
+-290 TJm
+(\002le) 12.7322 Tj
+-290 TJm
+(is) 6.64505 Tj
+-290 TJm
+(smaller) 29.3299 Tj
+[1 0 0 1 72 50.8518] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 43.0633 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.332 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+539.395 50.9514 Td
+/F130_0 9.9626 Tf
+(5) 4.9813 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 9 9
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 105.519 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -371.59 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+477.109 749.245 Td
+/F130_0 9.9626 Tf
+(Ho) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+[1 0 0 1 266.071 747.089] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -741.554] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(than) 17.1556 Tj
+-362 TJm
+(a) 4.42339 Tj
+-362 TJm
+(block.) 24.6275 Tj
+-1293 TJm
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-362 TJm
+(e) 4.42339 Tj
+15 TJm
+(xample,) 31.8205 Tj
+-390 TJm
+(compressing) 50.3609 Tj
+-362 TJm
+(a) 4.42339 Tj
+-362 TJm
+(\002le) 12.7322 Tj
+-362 TJm
+(20,000) 27.3972 Tj
+-362 TJm
+(bytes) 21.031 Tj
+-362 TJm
+(long) 17.7135 Tj
+-362 TJm
+(with) 17.7135 Tj
+-362 TJm
+(the) 12.1743 Tj
+-362 TJm
+(\003ag) 14.9439 Tj
+[1 0 0 1 406.528 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -406.528 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+406.528 710.037 Td
+/F134_0 9.9626 Tf
+(-9) 11.9551 Tj
+[1 0 0 1 418.483 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -418.483 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+422.09 710.037 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-362 TJm
+(cause) 22.1269 Tj
+-362 TJm
+(the) 12.1743 Tj
+-362 TJm
+(compressor) 45.9276 Tj
+-362 TJm
+(to) 7.7509 Tj
+72 698.082 Td
+(allocate) 30.9837 Tj
+-271 TJm
+(around) 27.6661 Tj
+-272 TJm
+(7600k) 24.9065 Tj
+-271 TJm
+(of) 8.29885 Tj
+-272 TJm
+(memory) 33.2053 Tj
+65 TJm
+(,) 2.49065 Tj
+-277 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-271 TJm
+(only) 17.7135 Tj
+-272 TJm
+(touch) 22.1369 Tj
+-271 TJm
+(400k) 19.9252 Tj
+-272 TJm
+(+) 5.61891 Tj
+-271 TJm
+(20000) 24.9065 Tj
+-272 TJm
+(*) 4.9813 Tj
+-271 TJm
+(8) 4.9813 Tj
+-272 TJm
+(=) 5.61891 Tj
+-271 TJm
+(560) 14.9439 Tj
+-272 TJm
+(kbytes) 26.0123 Tj
+-271 TJm
+(of) 8.29885 Tj
+-272 TJm
+(it.) 8.02986 Tj
+-748 TJm
+(Similarly) 37.0908 Tj
+65 TJm
+(,) 2.49065 Tj
+-277 TJm
+(the) 12.1743 Tj
+-272 TJm
+(decompressor) 55.3323 Tj
+72 686.127 Td
+(will) 15.5018 Tj
+-250 TJm
+(allocate) 30.9837 Tj
+-250 TJm
+(3700k) 24.9065 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(only) 17.7135 Tj
+-250 TJm
+(touch) 22.1369 Tj
+-250 TJm
+(100k) 19.9252 Tj
+-250 TJm
+(+) 5.61891 Tj
+-250 TJm
+(20000) 24.9065 Tj
+-250 TJm
+(*) 4.9813 Tj
+-250 TJm
+(4) 4.9813 Tj
+-250 TJm
+(=) 5.61891 Tj
+-250 TJm
+(180) 14.9439 Tj
+-250 TJm
+(kbytes.) 28.503 Tj
+[1 0 0 1 72 683.97] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -674.008] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 664.209 Td
+/F130_0 9.9626 Tf
+(Here) 19.3573 Tj
+-293 TJm
+(is) 6.64505 Tj
+-294 TJm
+(a) 4.42339 Tj
+-293 TJm
+(table) 19.3673 Tj
+-294 TJm
+(which) 24.3486 Tj
+-293 TJm
+(summarises) 47.0434 Tj
+-294 TJm
+(the) 12.1743 Tj
+-293 TJm
+(maximum) 40.4083 Tj
+-294 TJm
+(memory) 33.2053 Tj
+-293 TJm
+(usage) 22.6848 Tj
+-294 TJm
+(for) 11.6164 Tj
+-293 TJm
+(dif) 11.0684 Tj
+25 TJm
+(ferent) 23.2328 Tj
+-294 TJm
+(block) 22.1369 Tj
+-293 TJm
+(sizes.) 21.8579 Tj
+-881 TJm
+(Also) 18.8194 Tj
+-293 TJm
+(recorded) 34.8492 Tj
+-294 TJm
+(is) 6.64505 Tj
+-293 TJm
+(the) 12.1743 Tj
+-294 TJm
+(total) 17.7135 Tj
+72 652.254 Td
+(compressed) 47.0334 Tj
+-289 TJm
+(size) 15.4918 Tj
+-289 TJm
+(for) 11.6164 Tj
+-289 TJm
+(14) 9.9626 Tj
+-289 TJm
+(\002les) 16.6077 Tj
+-290 TJm
+(of) 8.29885 Tj
+-289 TJm
+(the) 12.1743 Tj
+-289 TJm
+(Calg) 18.8194 Tj
+5 TJm
+(ary) 12.7222 Tj
+-289 TJm
+(T) 6.08715 Tj
+70 TJm
+(e) 4.42339 Tj
+15 TJm
+(xt) 7.7509 Tj
+-289 TJm
+(Compression) 52.5826 Tj
+-289 TJm
+(Corpus) 28.782 Tj
+-289 TJm
+(totalling) 33.2153 Tj
+-289 TJm
+(3,141,622) 39.8504 Tj
+-290 TJm
+(bytes.) 23.5217 Tj
+-854 TJm
+(This) 17.7135 Tj
+-290 TJm
+(column) 29.8878 Tj
+-289 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+72 640.299 Td
+(some) 21.031 Tj
+-253 TJm
+(feel) 14.9339 Tj
+-253 TJm
+(for) 11.6164 Tj
+-253 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-253 TJm
+(compression) 50.3609 Tj
+-253 TJm
+(v) 4.9813 Tj
+25 TJm
+(aries) 18.8094 Tj
+-253 TJm
+(with) 17.7135 Tj
+-253 TJm
+(block) 22.1369 Tj
+-253 TJm
+(size.) 17.9825 Tj
+-638 TJm
+(These) 23.7907 Tj
+-253 TJm
+(\002gures) 27.1182 Tj
+-253 TJm
+(tend) 17.1556 Tj
+-254 TJm
+(to) 7.7509 Tj
+-253 TJm
+(understate) 40.9463 Tj
+-253 TJm
+(the) 12.1743 Tj
+-253 TJm
+(adv) 14.386 Tj
+25 TJm
+(antage) 26.0024 Tj
+-253 TJm
+(of) 8.29885 Tj
+-253 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ger) 12.7222 Tj
+-253 TJm
+(block) 22.1369 Tj
+72 628.344 Td
+(sizes) 19.3673 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ger) 12.7222 Tj
+-250 TJm
+(\002les,) 19.0983 Tj
+-250 TJm
+(since) 20.4731 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(Corpus) 28.782 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(dominated) 42.0621 Tj
+-250 TJm
+(by) 9.9626 Tj
+-250 TJm
+(smaller) 29.3299 Tj
+-250 TJm
+(\002les.) 19.0983 Tj
+[1 0 0 1 72 626.187] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -156.413] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 155.417 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5865] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 151.831] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -616.822] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+123.952 616.822 Td
+/F134_0 9.9626 Tf
+(Compress) 47.8205 Tj
+-1278 TJm
+(Decompress) 59.7756 Tj
+-1278 TJm
+(Decompress) 59.7756 Tj
+-1278 TJm
+(Corpus) 35.8654 Tj
+90 604.867 Td
+(Flag) 23.9102 Tj
+-2130 TJm
+(usage) 29.8878 Tj
+-2556 TJm
+(usage) 29.8878 Tj
+-2982 TJm
+(-s) 11.9551 Tj
+-426 TJm
+(usage) 29.8878 Tj
+-2130 TJm
+(Size) 23.9102 Tj
+94.244 580.956 Td
+(-1) 11.9551 Tj
+-2556 TJm
+(1200k) 29.8878 Tj
+-2982 TJm
+(500k) 23.9102 Tj
+-3834 TJm
+(350k) 23.9102 Tj
+-2556 TJm
+(914704) 35.8654 Tj
+94.244 569.001 Td
+(-2) 11.9551 Tj
+-2556 TJm
+(2000k) 29.8878 Tj
+-2982 TJm
+(900k) 23.9102 Tj
+-3834 TJm
+(600k) 23.9102 Tj
+-2556 TJm
+(877703) 35.8654 Tj
+94.244 557.046 Td
+(-3) 11.9551 Tj
+-2556 TJm
+(2800k) 29.8878 Tj
+-2556 TJm
+(1300k) 29.8878 Tj
+-3834 TJm
+(850k) 23.9102 Tj
+-2556 TJm
+(860338) 35.8654 Tj
+94.244 545.091 Td
+(-4) 11.9551 Tj
+-2556 TJm
+(3600k) 29.8878 Tj
+-2556 TJm
+(1700k) 29.8878 Tj
+-3408 TJm
+(1100k) 29.8878 Tj
+-2556 TJm
+(846899) 35.8654 Tj
+94.244 533.136 Td
+(-5) 11.9551 Tj
+-2556 TJm
+(4400k) 29.8878 Tj
+-2556 TJm
+(2100k) 29.8878 Tj
+-3408 TJm
+(1350k) 29.8878 Tj
+-2556 TJm
+(845160) 35.8654 Tj
+94.244 521.181 Td
+(-6) 11.9551 Tj
+-2556 TJm
+(5200k) 29.8878 Tj
+-2556 TJm
+(2500k) 29.8878 Tj
+-3408 TJm
+(1600k) 29.8878 Tj
+-2556 TJm
+(838626) 35.8654 Tj
+94.244 509.225 Td
+(-7) 11.9551 Tj
+-2556 TJm
+(6100k) 29.8878 Tj
+-2556 TJm
+(2900k) 29.8878 Tj
+-3408 TJm
+(1850k) 29.8878 Tj
+-2556 TJm
+(834096) 35.8654 Tj
+94.244 497.27 Td
+(-8) 11.9551 Tj
+-2556 TJm
+(6800k) 29.8878 Tj
+-2556 TJm
+(3300k) 29.8878 Tj
+-3408 TJm
+(2100k) 29.8878 Tj
+-2556 TJm
+(828642) 35.8654 Tj
+94.244 485.315 Td
+(-9) 11.9551 Tj
+-2556 TJm
+(7600k) 29.8878 Tj
+-2556 TJm
+(3700k) 29.8878 Tj
+-3408 TJm
+(2350k) 29.8878 Tj
+-2556 TJm
+(828642) 35.8654 Tj
+[1 0 0 1 72 469.773] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -459.811] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 435.021 Td
+/F122_0 20.6585 Tf
+(2.6.) 34.4584 Tj
+-278 TJm
+(RECO) 59.6824 Tj
+50 TJm
+(VERING) 79.2047 Tj
+-278 TJm
+(D) 14.9154 Tj
+40 TJm
+(A) 14.9154 Tj
+90 TJm
+(T) 12.6223 Tj
+90 TJm
+(A) 14.9154 Tj
+-278 TJm
+(FR) 27.5378 Tj
+20 TJm
+(OM) 33.2808 Tj
+-278 TJm
+(D) 14.9154 Tj
+40 TJm
+(AMA) 47.0394 Tj
+50 TJm
+(GED) 44.767 Tj
+72 410.23 Td
+(FILES) 58.5462 Tj
+[1 0 0 1 72 409.972] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -400.01] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 388.312 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 388.312] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -388.312] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+105.138 388.312 Td
+/F130_0 9.9626 Tf
+(compresses) 45.9276 Tj
+-326 TJm
+(\002les) 16.6077 Tj
+-326 TJm
+(in) 7.7509 Tj
+-326 TJm
+(blocks,) 28.503 Tj
+-346 TJm
+(usually) 28.782 Tj
+-326 TJm
+(900kbytes) 40.9562 Tj
+-326 TJm
+(long.) 20.2042 Tj
+-1077 TJm
+(Each) 19.9152 Tj
+-326 TJm
+(block) 22.1369 Tj
+-327 TJm
+(is) 6.64505 Tj
+-326 TJm
+(handled) 31.5416 Tj
+-326 TJm
+(independently) 56.4481 Tj
+65 TJm
+(.) 2.49065 Tj
+-1077 TJm
+(If) 6.63509 Tj
+-326 TJm
+(a) 4.42339 Tj
+-326 TJm
+(media) 24.3486 Tj
+-326 TJm
+(or) 8.29885 Tj
+72 376.357 Td
+(transmission) 50.3709 Tj
+-319 TJm
+(error) 19.3573 Tj
+-318 TJm
+(causes) 26.0024 Tj
+-319 TJm
+(a) 4.42339 Tj
+-318 TJm
+(multi-block) 46.4955 Tj
+[1 0 0 1 234.518 376.357] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -234.518 -376.357] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+234.518 376.357 Td
+/F134_0 9.9626 Tf
+(.bz2) 23.9102 Tj
+[1 0 0 1 258.429 376.357] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -258.429 -376.357] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+261.603 376.357 Td
+/F130_0 9.9626 Tf
+(\002le) 12.7322 Tj
+-319 TJm
+(to) 7.7509 Tj
+-318 TJm
+(become) 30.9837 Tj
+-319 TJm
+(damaged,) 38.4556 Tj
+-336 TJm
+(it) 5.53921 Tj
+-318 TJm
+(may) 17.1556 Tj
+-319 TJm
+(be) 9.40469 Tj
+-318 TJm
+(possible) 32.6574 Tj
+-319 TJm
+(to) 7.7509 Tj
+-318 TJm
+(reco) 17.1456 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-319 TJm
+(data) 16.5977 Tj
+-319 TJm
+(from) 19.3673 Tj
+-318 TJm
+(the) 12.1743 Tj
+72 364.402 Td
+(undamaged) 45.9276 Tj
+-250 TJm
+(blocks) 26.0123 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(\002le.) 15.2229 Tj
+[1 0 0 1 72 362.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -352.283] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 342.484 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-358 TJm
+(compressed) 47.0334 Tj
+-357 TJm
+(representation) 56.4381 Tj
+-358 TJm
+(of) 8.29885 Tj
+-357 TJm
+(each) 18.2515 Tj
+-358 TJm
+(block) 22.1369 Tj
+-358 TJm
+(is) 6.64505 Tj
+-357 TJm
+(delimited) 37.6387 Tj
+-358 TJm
+(by) 9.9626 Tj
+-357 TJm
+(a) 4.42339 Tj
+-358 TJm
+(48-bit) 23.8007 Tj
+-358 TJm
+(pattern,) 30.1568 Tj
+-384 TJm
+(which) 24.3486 Tj
+-358 TJm
+(mak) 17.1556 Tj
+10 TJm
+(es) 8.29885 Tj
+-357 TJm
+(it) 5.53921 Tj
+-358 TJm
+(possible) 32.6574 Tj
+-357 TJm
+(to) 7.7509 Tj
+-358 TJm
+(\002nd) 15.5018 Tj
+-358 TJm
+(the) 12.1743 Tj
+72 330.529 Td
+(block) 22.1369 Tj
+-286 TJm
+(boundaries) 43.7159 Tj
+-286 TJm
+(wit) 12.7322 Tj
+1 TJm
+(h) 4.9813 Tj
+-286 TJm
+(reasonable) 42.6001 Tj
+-286 TJm
+(certainty) 34.8591 Tj
+65 TJm
+(.) 2.49065 Tj
+-835 TJm
+(Each) 19.9152 Tj
+-285 TJm
+(block) 22.1369 Tj
+-286 TJm
+(also) 16.0497 Tj
+-286 TJm
+(carries) 26.5503 Tj
+-286 TJm
+(its) 9.41466 Tj
+-285 TJm
+(o) 4.9813 Tj
+25 TJm
+(wn) 12.1743 Tj
+-286 TJm
+(32-bit) 23.8007 Tj
+-286 TJm
+(CRC,) 22.4258 Tj
+-286 TJm
+(so) 8.85675 Tj
+-285 TJm
+(damaged) 35.965 Tj
+-286 TJm
+(blocks) 26.0123 Tj
+-286 TJm
+(can) 13.8281 Tj
+-286 TJm
+(be) 9.40469 Tj
+72 318.574 Td
+(distinguished) 53.1405 Tj
+-250 TJm
+(from) 19.3673 Tj
+-250 TJm
+(undamaged) 45.9276 Tj
+-250 TJm
+(ones.) 20.7521 Tj
+[1 0 0 1 72 316.417] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -306.455] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 296.656 Td
+/F134_0 9.9626 Tf
+(bzip2recover) 71.7307 Tj
+[1 0 0 1 143.731 296.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.731 -296.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+146.448 296.656 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-273 TJm
+(a) 4.42339 Tj
+-272 TJm
+(simple) 26.5703 Tj
+-273 TJm
+(program) 33.7533 Tj
+-273 TJm
+(whose) 25.4544 Tj
+-272 TJm
+(purpose) 31.5416 Tj
+-273 TJm
+(is) 6.64505 Tj
+-273 TJm
+(to) 7.7509 Tj
+-272 TJm
+(search) 25.4445 Tj
+-273 TJm
+(for) 11.6164 Tj
+-273 TJm
+(blocks) 26.0123 Tj
+-272 TJm
+(in) 7.7509 Tj
+[1 0 0 1 392.655 296.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -392.655 -296.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+392.655 296.656 Td
+/F134_0 9.9626 Tf
+(.bz2) 23.9102 Tj
+[1 0 0 1 416.566 296.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -416.566 -296.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.282 296.656 Td
+/F130_0 9.9626 Tf
+(\002les,) 19.0983 Tj
+-278 TJm
+(and) 14.386 Tj
+-273 TJm
+(write) 20.4731 Tj
+-273 TJm
+(each) 18.2515 Tj
+-272 TJm
+(block) 22.1369 Tj
+-273 TJm
+(out) 12.7322 Tj
+72 284.701 Td
+(into) 15.5018 Tj
+-254 TJm
+(its) 9.41466 Tj
+-255 TJm
+(o) 4.9813 Tj
+25 TJm
+(wn) 12.1743 Tj
+[1 0 0 1 121.43 284.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -121.43 -284.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+121.43 284.701 Td
+/F134_0 9.9626 Tf
+(.bz2) 23.9102 Tj
+[1 0 0 1 145.34 284.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -145.34 -284.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+147.875 284.701 Td
+/F130_0 9.9626 Tf
+(\002le.) 15.2229 Tj
+-647 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-255 TJm
+(can) 13.8281 Tj
+-254 TJm
+(then) 17.1556 Tj
+-255 TJm
+(use) 13.2801 Tj
+[1 0 0 1 240.01 284.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -240.01 -284.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+240.01 284.701 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+-600 TJm
+(-t) 11.9551 Tj
+[1 0 0 1 287.831 284.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -287.831 -284.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+290.367 284.701 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-255 TJm
+(t) 2.7696 Tj
+1 TJm
+(est) 11.0684 Tj
+-255 TJm
+(the) 12.1743 Tj
+-254 TJm
+(inte) 14.9439 Tj
+15 TJm
+(grity) 18.8194 Tj
+-255 TJm
+(of) 8.29885 Tj
+-254 TJm
+(the) 12.1743 Tj
+-255 TJm
+(resulting) 34.8691 Tj
+-254 TJm
+(\002les,) 19.0983 Tj
+-256 TJm
+(and) 14.386 Tj
+-255 TJm
+(decompress) 47.0334 Tj
+-254 TJm
+(those) 21.031 Tj
+72 272.746 Td
+(which) 24.3486 Tj
+-250 TJm
+(are) 12.1643 Tj
+-250 TJm
+(undamaged.) 48.4182 Tj
+[1 0 0 1 72 270.589] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -260.626] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 250.828 Td
+/F134_0 9.9626 Tf
+(bzip2recover) 71.7307 Tj
+[1 0 0 1 143.731 250.828] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.731 -250.828] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+150.099 250.828 Td
+/F130_0 9.9626 Tf
+(tak) 12.1743 Tj
+10 TJm
+(es) 8.29885 Tj
+-639 TJm
+(a) 4.42339 Tj
+-639 TJm
+(single) 23.8007 Tj
+-639 TJm
+(ar) 7.74094 Tj
+18 TJm
+(gument,) 32.3785 Tj
+-737 TJm
+(the) 12.1743 Tj
+-639 TJm
+(name) 21.579 Tj
+-639 TJm
+(of) 8.29885 Tj
+-639 TJm
+(the) 12.1743 Tj
+-639 TJm
+(damaged) 35.965 Tj
+-639 TJm
+(\002le,) 15.2229 Tj
+-737 TJm
+(and) 14.386 Tj
+-639 TJm
+(writes) 24.3486 Tj
+-639 TJm
+(a) 4.42339 Tj
+-639 TJm
+(number) 30.4357 Tj
+-639 TJm
+(of) 8.29885 Tj
+-640 TJm
+(\002les) 16.6077 Tj
+[1 0 0 1 72 238.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -238.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 238.873 Td
+/F134_0 9.9626 Tf
+(rec0001file.bz2) 89.6634 Tj
+[1 0 0 1 161.664 238.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.664 -238.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+161.664 238.873 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 169.072 238.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.072 -238.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+169.072 238.873 Td
+/F134_0 9.9626 Tf
+(rec0002file.bz2) 89.6634 Tj
+[1 0 0 1 258.736 238.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -258.736 -238.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+258.736 238.873 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-494 TJm
+(etc,) 14.107 Tj
+-493 TJm
+(containing) 42.0621 Tj
+-445 TJm
+(the) 12.1743 Tj
+-445 TJm
+(e) 4.42339 Tj
+15 TJm
+(xtracted) 32.0895 Tj
+-445 TJm
+(blocks.) 28.503 Tj
+-1789 TJm
+(The) 15.4918 Tj
+-445 TJm
+(output) 25.4644 Tj
+-445 TJm
+(\002lenames) 38.1866 Tj
+-445 TJm
+(are) 12.1643 Tj
+72 226.918 Td
+(designed) 35.417 Tj
+-337 TJm
+(so) 8.85675 Tj
+-337 TJm
+(that) 14.9439 Tj
+-337 TJm
+(the) 12.1743 Tj
+-337 TJm
+(use) 13.2801 Tj
+-337 TJm
+(of) 8.29885 Tj
+-337 TJm
+(wildc) 22.1369 Tj
+1 TJm
+(ards) 16.5977 Tj
+-337 TJm
+(in) 7.7509 Tj
+-337 TJm
+(subsequent) 44.2738 Tj
+-337 TJm
+(processing) 42.61 Tj
+-337 TJm
+(--) 6.63509 Tj
+-337 TJm
+(for) 11.6164 Tj
+-337 TJm
+(e) 4.42339 Tj
+15 TJm
+(xample,) 31.8205 Tj
+[1 0 0 1 396.538 226.918] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -396.538 -226.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+396.538 226.918 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+-600 TJm
+(-dc) 17.9327 Tj
+-600 TJm
+(rec) 17.9327 Tj
+474.247 225.174 Td
+(*) 5.97756 Tj
+480.224 226.918 Td
+(file.bz2) 47.8205 Tj
+-600 TJm
+(>) 5.97756 Tj
+72 214.963 Td
+(recovered_data) 83.6858 Tj
+[1 0 0 1 155.686 214.963] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.686 -214.963] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+158.177 214.963 Td
+/F130_0 9.9626 Tf
+(--) 6.63509 Tj
+-250 TJm
+(lists) 16.0597 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(\002les) 16.6077 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(correct) 27.6562 Tj
+-250 TJm
+(order) 21.0211 Tj
+55 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 213.653] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -203.69] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 193.045 Td
+/F134_0 9.9626 Tf
+(bzip2recover) 71.7307 Tj
+[1 0 0 1 143.731 193.045] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.731 -193.045] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+145.93 193.045 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-221 TJm
+(be) 9.40469 Tj
+-220 TJm
+(of) 8.29885 Tj
+-221 TJm
+(most) 19.3773 Tj
+-221 TJm
+(use) 13.2801 Tj
+-220 TJm
+(dealing) 29.3299 Tj
+-221 TJm
+(with) 17.7135 Tj
+-221 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ge) 9.40469 Tj
+[1 0 0 1 307.229 193.045] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -307.229 -193.045] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+307.229 193.045 Td
+/F134_0 9.9626 Tf
+(.bz2) 23.9102 Tj
+[1 0 0 1 331.14 193.045] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -331.14 -193.045] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+333.338 193.045 Td
+/F130_0 9.9626 Tf
+(\002les,) 19.0983 Tj
+-227 TJm
+(as) 8.29885 Tj
+-220 TJm
+(these) 20.4731 Tj
+-221 TJm
+(will) 15.5018 Tj
+-221 TJm
+(contain) 29.3299 Tj
+-220 TJm
+(man) 17.1556 Tj
+15 TJm
+(y) 4.9813 Tj
+-221 TJm
+(blocks.) 28.503 Tj
+-600 TJm
+(It) 6.08715 Tj
+-221 TJm
+(is) 6.64505 Tj
+-221 TJm
+(clearly) 27.1082 Tj
+72 181.09 Td
+(futile) 21.031 Tj
+-289 TJm
+(to) 7.7509 Tj
+-289 TJm
+(use) 13.2801 Tj
+-289 TJm
+(it) 5.53921 Tj
+-289 TJm
+(on) 9.9626 Tj
+-289 TJm
+(damaged) 35.965 Tj
+-289 TJm
+(single-block) 49.2551 Tj
+-290 TJm
+(\002les) 16.6077 Tj
+1 TJm
+(,) 2.49065 Tj
+-299 TJm
+(since) 20.4731 Tj
+-289 TJm
+(a) 4.42339 Tj
+-290 TJm
+(damaged) 35.965 Tj
+-289 TJm
+(block) 22.1369 Tj
+-289 TJm
+(cannot) 26.5603 Tj
+-289 TJm
+(be) 9.40469 Tj
+-289 TJm
+(reco) 17.1456 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(ered.) 19.6363 Tj
+-854 TJm
+(If) 6.63509 Tj
+-289 TJm
+(you) 14.9439 Tj
+-290 TJm
+(wish) 18.8194 Tj
+-289 TJm
+(to) 7.7509 Tj
+-289 TJm
+(minimise) 37.0908 Tj
+72 169.135 Td
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-320 TJm
+(potential) 34.8691 Tj
+-320 TJm
+(data) 16.5977 Tj
+-319 TJm
+(loss) 15.5018 Tj
+-320 TJm
+(through) 30.9936 Tj
+-320 TJm
+(media) 24.3486 Tj
+-320 TJm
+(or) 8.29885 Tj
+-319 TJm
+(transmission) 50.3709 Tj
+-320 TJm
+(errors,) 25.7234 Tj
+-337 TJm
+(you) 14.9439 Tj
+-320 TJm
+(might) 23.2527 Tj
+-320 TJm
+(consider) 33.7533 Tj
+-320 TJm
+(compressing) 50.3609 Tj
+-319 TJm
+(with) 17.7135 Tj
+-320 TJm
+(a) 4.42339 Tj
+-320 TJm
+(smaller) 29.3299 Tj
+-320 TJm
+(block) 22.1369 Tj
+72 157.179 Td
+(size.) 17.9825 Tj
+[1 0 0 1 72 157.08] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -147.117] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 122.426 Td
+/F122_0 20.6585 Tf
+(2.7.) 34.4584 Tj
+-278 TJm
+(PERFORMANCE) 161.818 Tj
+-278 TJm
+(NO) 30.9877 Tj
+40 TJm
+(TES) 40.1808 Tj
+[1 0 0 1 72 122.168] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -112.206] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 100.509 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-305 TJm
+(sorting) 27.6761 Tj
+-304 TJm
+(phase) 22.6848 Tj
+-305 TJm
+(of) 8.29885 Tj
+-304 TJm
+(compression) 50.3609 Tj
+-305 TJm
+(g) 4.9813 Tj
+5 TJm
+(athers) 23.7907 Tj
+-304 TJm
+(together) 32.6474 Tj
+-305 TJm
+(similar) 27.6761 Tj
+-304 TJm
+(strings) 26.5703 Tj
+-305 TJm
+(in) 7.7509 Tj
+-304 TJm
+(the) 12.1743 Tj
+-305 TJm
+(\002le.) 15.2229 Tj
+-947 TJm
+(Because) 33.1954 Tj
+-305 TJm
+(of) 8.29885 Tj
+-304 TJm
+(this,) 16.8866 Tj
+-319 TJm
+(\002les) 16.6077 Tj
+-304 TJm
+(containing) 42.0621 Tj
+-305 TJm
+(v) 4.9813 Tj
+15 TJm
+(ery) 12.7222 Tj
+72 88.5534 Td
+(long) 17.7135 Tj
+-286 TJm
+(runs) 17.1556 Tj
+-285 TJm
+(of) 8.29885 Tj
+-286 TJm
+(repeated) 33.7433 Tj
+-285 TJm
+(symbols,) 35.706 Tj
+-295 TJm
+(lik) 10.5205 Tj
+10 TJm
+(e) 4.42339 Tj
+-286 TJm
+("aabaabaabaab) 59.3771 Tj
+-285 TJm
+(...") 11.5367 Tj
+-571 TJm
+(\(repeated) 37.0609 Tj
+-286 TJm
+(se) 8.29885 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(eral) 14.9339 Tj
+-286 TJm
+(hundred) 32.6474 Tj
+-285 TJm
+(times\)) 24.9065 Tj
+-286 TJm
+(may) 17.1556 Tj
+-286 TJm
+(com) 17.1556 Tj
+1 TJm
+(press) 20.4731 Tj
+-286 TJm
+(more) 20.4731 Tj
+-286 TJm
+(slo) 11.6264 Tj
+25 TJm
+(wly) 14.9439 Tj
+72 76.5983 Td
+(than) 17.1556 Tj
+-322 TJm
+(normal.) 30.7147 Tj
+-524 TJm
+(V) 7.193 Tj
+111 TJm
+(ersions) 28.224 Tj
+-322 TJm
+(0.9.5) 19.9252 Tj
+-321 TJm
+(and) 14.386 Tj
+-322 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-322 TJm
+(f) 3.31755 Tj
+10 TJm
+(are) 12.1643 Tj
+-321 TJm
+(much) 22.1369 Tj
+-322 TJm
+(better) 22.6848 Tj
+-321 TJm
+(than) 17.1556 Tj
+-322 TJm
+(pre) 12.7222 Tj
+25 TJm
+(vious) 21.589 Tj
+-321 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions) 28.224 Tj
+-322 TJm
+(in) 7.7509 Tj
+-322 TJm
+(this) 14.396 Tj
+-321 TJm
+(respect.) 30.7047 Tj
+-1050 TJm
+(The) 15.4918 Tj
+-321 TJm
+(ratio) 18.2614 Tj
+-322 TJm
+(between) 33.1954 Tj
+[1 0 0 1 72 50.8518] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 43.0633 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.332 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+539.395 50.9514 Td
+/F130_0 9.9626 Tf
+(6) 4.9813 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 10 10
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 105.519 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -371.59 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+477.109 749.245 Td
+/F130_0 9.9626 Tf
+(Ho) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+[1 0 0 1 266.071 747.089] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -540 -741.554] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(w) 7.193 Tj
+10 TJm
+(orst-case) 35.4071 Tj
+-289 TJm
+(and) 14.386 Tj
+-290 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(erage-case) 42.0322 Tj
+-289 TJm
+(compression) 50.3609 Tj
+-290 TJm
+(time) 17.7135 Tj
+-289 TJm
+(is) 6.64505 Tj
+-290 TJm
+(in) 7.7509 Tj
+-289 TJm
+(the) 12.1743 Tj
+-290 TJm
+(re) 7.74094 Tj
+15 TJm
+(gion) 17.7135 Tj
+-289 TJm
+(of) 8.29885 Tj
+-289 TJm
+(10:1.) 20.2042 Tj
+-857 TJm
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-290 TJm
+(pre) 12.7222 Tj
+25 TJm
+(vious) 21.589 Tj
+-289 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions,) 30.7147 Tj
+-299 TJm
+(this) 14.396 Tj
+-290 TJm
+(\002gure) 23.2427 Tj
+-289 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-290 TJm
+(more) 20.4731 Tj
+72 698.082 Td
+(lik) 10.5205 Tj
+10 TJm
+(e) 4.42339 Tj
+-250 TJm
+(100:1.) 25.1855 Tj
+-620 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-250 TJm
+(can) 13.8281 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(the) 12.1743 Tj
+[1 0 0 1 186.002 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -186.002 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+186.002 698.082 Td
+/F134_0 9.9626 Tf
+(-vvvv) 29.8878 Tj
+[1 0 0 1 215.889 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -215.889 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+218.38 698.082 Td
+/F130_0 9.9626 Tf
+(option) 25.4644 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(monitor) 31.5516 Tj
+-250 TJm
+(progress) 33.7533 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(great) 19.9152 Tj
+-250 TJm
+(detail,) 24.6275 Tj
+-250 TJm
+(if) 6.08715 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ant.) 14.6649 Tj
+[1 0 0 1 72 695.925] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -685.963] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 676.164 Td
+/F130_0 9.9626 Tf
+(Decompression) 61.9773 Tj
+-250 TJm
+(speed) 22.6848 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(unaf) 17.7035 Tj
+25 TJm
+(fected) 24.3386 Tj
+-250 TJm
+(by) 9.9626 Tj
+-250 TJm
+(these) 20.4731 Tj
+-250 TJm
+(phenomena.) 48.4182 Tj
+[1 0 0 1 72 674.007] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -664.045] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 654.247 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 654.247] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -654.247] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.863 654.247 Td
+/F130_0 9.9626 Tf
+(usually) 28.782 Tj
+-299 TJm
+(allocates) 34.8591 Tj
+-298 TJm
+(se) 8.29885 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(eral) 14.9339 Tj
+-299 TJm
+(me) 12.1743 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(abytes) 25.4544 Tj
+-298 TJm
+(of) 8.29885 Tj
+-299 TJm
+(memory) 33.2053 Tj
+-299 TJm
+(to) 7.7509 Tj
+-298 TJm
+(operate) 29.3199 Tj
+-299 TJm
+(in,) 10.2416 Tj
+-311 TJm
+(and) 14.386 Tj
+-298 TJm
+(then) 17.1556 Tj
+-299 TJm
+(char) 17.1456 Tj
+18 TJm
+(ges) 13.2801 Tj
+-298 TJm
+(all) 9.9626 Tj
+-299 TJm
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-299 TJm
+(it) 5.53921 Tj
+-298 TJm
+(in) 7.7509 Tj
+-299 TJm
+(a) 4.42339 Tj
+-298 TJm
+(f) 3.31755 Tj
+10 TJm
+(airly) 18.2614 Tj
+-299 TJm
+(random) 30.4357 Tj
+72 642.291 Td
+(f) 3.31755 Tj
+10 TJm
+(ashion.) 28.503 Tj
+-743 TJm
+(This) 17.7135 Tj
+-270 TJm
+(means) 25.4544 Tj
+-271 TJm
+(that) 14.9439 Tj
+-270 TJm
+(performance,) 52.8317 Tj
+-276 TJm
+(both) 17.7135 Tj
+-270 TJm
+(for) 11.6164 Tj
+-271 TJm
+(compressing) 50.3609 Tj
+-270 TJm
+(and) 14.386 Tj
+-271 TJm
+(decompressing,) 62.2563 Tj
+-275 TJm
+(is) 6.64505 Tj
+-271 TJm
+(lar) 10.5105 Tj
+18 TJm
+(gely) 17.1556 Tj
+-270 TJm
+(determined) 44.8217 Tj
+-271 TJm
+(by) 9.9626 Tj
+-270 TJm
+(the) 12.1743 Tj
+-271 TJm
+(speed) 22.6848 Tj
+72 630.336 Td
+(at) 7.193 Tj
+-294 TJm
+(which) 24.3486 Tj
+-294 TJm
+(your) 18.2614 Tj
+-294 TJm
+(machine) 33.7533 Tj
+-295 TJm
+(ca) 8.84679 Tj
+1 TJm
+(n) 4.9813 Tj
+-295 TJm
+(service) 28.2141 Tj
+-294 TJm
+(cache) 22.6749 Tj
+-294 TJm
+(misses.) 29.0609 Tj
+-442 TJm
+(Because) 33.1954 Tj
+-294 TJm
+(of) 8.29885 Tj
+-294 TJm
+(this,) 16.8866 Tj
+-306 TJm
+(small) 21.589 Tj
+-294 TJm
+(changes) 32.0895 Tj
+-294 TJm
+(to) 7.7509 Tj
+-294 TJm
+(the) 12.1743 Tj
+-294 TJm
+(code) 18.8094 Tj
+-294 TJm
+(to) 7.7509 Tj
+-294 TJm
+(reduce) 26.5503 Tj
+-294 TJm
+(the) 12.1743 Tj
+-295 TJm
+(miss) 18.2714 Tj
+-294 TJm
+(rate) 14.9339 Tj
+72 618.381 Td
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-253 TJm
+(been) 18.8094 Tj
+-253 TJm
+(observ) 26.5603 Tj
+15 TJm
+(ed) 9.40469 Tj
+-253 TJm
+(to) 7.7509 Tj
+-253 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-253 TJm
+(disproportionately) 73.0557 Tj
+-253 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ge) 9.40469 Tj
+-253 TJm
+(performance) 50.341 Tj
+-253 TJm
+(impro) 23.8007 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(ements.) 30.7147 Tj
+-639 TJm
+(I) 3.31755 Tj
+-253 TJm
+(imagine) 32.0995 Tj
+[1 0 0 1 438.909 618.381] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -438.909 -618.381] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+438.909 618.381 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 468.796 618.381] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468.796 -618.381] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+471.318 618.381 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-253 TJm
+(perform) 32.0895 Tj
+-253 TJm
+(best) 16.0497 Tj
+72 606.426 Td
+(on) 9.9626 Tj
+-250 TJm
+(machines) 37.6287 Tj
+-250 TJm
+(with) 17.7135 Tj
+-250 TJm
+(v) 4.9813 Tj
+15 TJm
+(ery) 12.7222 Tj
+-250 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ge) 9.40469 Tj
+-250 TJm
+(caches.) 29.041 Tj
+[1 0 0 1 72 604.269] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -594.306] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 571.673 Td
+/F122_0 20.6585 Tf
+(2.8.) 34.4584 Tj
+-278 TJm
+(CA) 29.8309 Tj
+80 TJm
+(VEA) 42.4739 Tj
+90 TJm
+(TS) 26.4016 Tj
+[1 0 0 1 72 571.415] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -561.452] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 549.755 Td
+/F130_0 9.9626 Tf
+(I/O) 13.2801 Tj
+-268 TJm
+(error) 19.3573 Tj
+-267 TJm
+(messages) 37.6287 Tj
+-268 TJm
+(are) 12.1643 Tj
+-268 TJm
+(not) 12.7322 Tj
+-268 TJm
+(as) 8.29885 Tj
+-267 TJm
+(helpful) 28.224 Tj
+-268 TJm
+(as) 8.29885 Tj
+-268 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-267 TJm
+(could) 22.1369 Tj
+-268 TJm
+(be.) 11.8953 Tj
+[1 0 0 1 293.313 549.755] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -293.313 -549.755] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+293.313 549.755 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 323.201 549.755] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -323.201 -549.755] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+325.868 549.755 Td
+/F130_0 9.9626 Tf
+(tries) 17.1556 Tj
+-268 TJm
+(hard) 17.7035 Tj
+-267 TJm
+(to) 7.7509 Tj
+-268 TJm
+(detect) 23.7907 Tj
+-268 TJm
+(I/O) 13.2801 Tj
+-268 TJm
+(errors) 23.2328 Tj
+-267 TJm
+(and) 14.386 Tj
+-268 TJm
+(e) 4.42339 Tj
+15 TJm
+(xit) 10.5205 Tj
+-268 TJm
+(cleanly) 28.772 Tj
+65 TJm
+(,) 2.49065 Tj
+-272 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-268 TJm
+(the) 12.1743 Tj
+72 537.8 Td
+(details) 26.0123 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(what) 19.3673 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(problem) 33.2053 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(sometimes) 42.62 Tj
+-250 TJm
+(seem) 20.4731 Tj
+-250 TJm
+(rather) 23.2328 Tj
+-250 TJm
+(misleading.) 46.2165 Tj
+[1 0 0 1 72 535.643] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -525.681] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 515.882 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-280 TJm
+(manual) 29.3299 Tj
+-279 TJm
+(page) 18.8094 Tj
+-280 TJm
+(pertains) 31.5416 Tj
+-280 TJm
+(to) 7.7509 Tj
+-279 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-280 TJm
+(1.0.5) 19.9252 Tj
+-280 TJm
+(of) 8.29885 Tj
+[1 0 0 1 256.84 515.882] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -256.84 -515.882] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+256.84 515.882 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 286.728 515.882] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -286.728 -515.882] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+286.728 515.882 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-798 TJm
+(Compressed) 49.2551 Tj
+-280 TJm
+(data) 16.5977 Tj
+-279 TJm
+(created) 28.762 Tj
+-280 TJm
+(by) 9.9626 Tj
+-280 TJm
+(this) 14.396 Tj
+-279 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-280 TJm
+(is) 6.64505 Tj
+-280 TJm
+(entirely) 30.4357 Tj
+-279 TJm
+(forw) 18.8094 Tj
+10 TJm
+(ards) 16.5977 Tj
+72 503.927 Td
+(and) 14.386 Tj
+-294 TJm
+(backw) 26.0024 Tj
+10 TJm
+(ards) 16.5977 Tj
+-293 TJm
+(compatible) 44.2738 Tj
+-294 TJm
+(with) 17.7135 Tj
+-294 TJm
+(the) 12.1743 Tj
+-293 TJm
+(pre) 12.7222 Tj
+25 TJm
+(vious) 21.589 Tj
+-294 TJm
+(public) 24.9065 Tj
+-294 TJm
+(releases,) 34.0223 Tj
+-304 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions) 28.224 Tj
+-294 TJm
+(0.1pl2,) 27.6761 Tj
+-305 TJm
+(0.9.0) 19.9252 Tj
+-293 TJm
+(and) 14.386 Tj
+-294 TJm
+(0.9.5,) 22.4159 Tj
+-305 TJm
+(1.0.0,) 22.4159 Tj
+-304 TJm
+(1.0.1,) 22.4159 Tj
+-305 TJm
+(1.0.2) 19.9252 Tj
+-294 TJm
+(and) 14.386 Tj
+72 491.972 Td
+(1.0.3,) 22.4159 Tj
+-263 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-260 TJm
+(with) 17.7135 Tj
+-260 TJm
+(the) 12.1743 Tj
+-260 TJm
+(follo) 18.8194 Tj
+25 TJm
+(wing) 19.9252 Tj
+-260 TJm
+(e) 4.42339 Tj
+15 TJm
+(xception:) 37.0808 Tj
+-330 TJm
+(0.9.0) 19.9252 Tj
+-260 TJm
+(and) 14.386 Tj
+-260 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-260 TJm
+(can) 13.8281 Tj
+-260 TJm
+(correctly) 35.4071 Tj
+-260 TJm
+(decompress) 47.0334 Tj
+-260 TJm
+(multiple) 33.2153 Tj
+-260 TJm
+(concatenated) 52.0048 Tj
+-260 TJm
+(compressed) 47.0334 Tj
+72 480.017 Td
+(\002les.) 19.0983 Tj
+-310 TJm
+(0.1pl2) 25.1855 Tj
+-250 TJm
+(cannot) 26.5603 Tj
+-250 TJm
+(do) 9.9626 Tj
+-250 TJm
+(this;) 17.1656 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(will) 15.5018 Tj
+-250 TJm
+(stop) 16.6077 Tj
+-250 TJm
+(after) 18.2515 Tj
+-250 TJm
+(decompressing) 59.7656 Tj
+-250 TJm
+(just) 14.396 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(\002rst) 15.5018 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(stream.) 29.0509 Tj
+[1 0 0 1 72 477.86] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -467.897] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 458.099 Td
+/F134_0 9.9626 Tf
+(bzip2recover) 71.7307 Tj
+[1 0 0 1 143.731 458.099] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.731 -458.099] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+146.174 458.099 Td
+/F130_0 9.9626 Tf
+(v) 4.9813 Tj
+15 TJm
+(ersions) 28.224 Tj
+-245 TJm
+(prior) 19.3673 Tj
+-245 TJm
+(to) 7.7509 Tj
+-245 TJm
+(1.0.2) 19.9252 Tj
+-246 TJm
+(used) 18.2614 Tj
+-245 TJm
+(32-bit) 23.8007 Tj
+-245 TJm
+(inte) 14.9439 Tj
+15 TJm
+(gers) 16.5977 Tj
+-245 TJm
+(to) 7.7509 Tj
+-245 TJm
+(represent) 36.5129 Tj
+-245 TJm
+(bit) 10.5205 Tj
+-246 TJm
+(positions) 35.9849 Tj
+-245 TJm
+(in) 7.7509 Tj
+-245 TJm
+(compressed) 47.0334 Tj
+-245 TJm
+(\002les,) 19.0983 Tj
+-246 TJm
+(so) 8.85675 Tj
+-245 TJm
+(it) 5.53921 Tj
+-245 TJm
+(could) 22.1369 Tj
+72 446.144 Td
+(not) 12.7322 Tj
+-384 TJm
+(handle) 26.5603 Tj
+-383 TJm
+(compressed) 47.0334 Tj
+-384 TJm
+(\002les) 16.6077 Tj
+-383 TJm
+(more) 20.4731 Tj
+-384 TJm
+(than) 17.1556 Tj
+-383 TJm
+(512) 14.9439 Tj
+-384 TJm
+(me) 12.1743 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(abytes) 25.4544 Tj
+-383 TJm
+(long.) 20.2042 Tj
+-1421 TJm
+(V) 7.193 Tj
+111 TJm
+(ersions) 28.224 Tj
+-384 TJm
+(1.0.2) 19.9252 Tj
+-383 TJm
+(and) 14.386 Tj
+-384 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-384 TJm
+(use) 13.2801 Tj
+-383 TJm
+(64-bit) 23.8007 Tj
+-384 TJm
+(ints) 14.396 Tj
+-383 TJm
+(on) 9.9626 Tj
+-384 TJm
+(some) 21.031 Tj
+72 434.189 Td
+(platforms) 38.1866 Tj
+-245 TJm
+(which) 24.3486 Tj
+-246 TJm
+(support) 29.8878 Tj
+-245 TJm
+(them) 19.9252 Tj
+-246 TJm
+(\(GNU) 24.8965 Tj
+-245 TJm
+(supported) 39.2925 Tj
+-245 TJm
+(tar) 10.5105 Tj
+18 TJm
+(gets,) 18.5404 Tj
+-247 TJm
+(and) 14.386 Tj
+-245 TJm
+(W) 9.40469 Tj
+40 TJm
+(indo) 17.7135 Tj
+25 TJm
+(ws\).) 16.8766 Tj
+-309 TJm
+(T) 6.08715 Tj
+80 TJm
+(o) 4.9813 Tj
+-245 TJm
+(establish) 34.8691 Tj
+-245 TJm
+(whether) 32.0895 Tj
+-246 TJm
+(or) 8.29885 Tj
+-245 TJm
+(not) 12.7322 Tj
+[1 0 0 1 468.269 434.189] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468.269 -434.189] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+468.269 434.189 Td
+/F134_0 9.9626 Tf
+(bzip2recover) 71.7307 Tj
+[1 0 0 1 540 434.189] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -434.189] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 422.233 Td
+/F130_0 9.9626 Tf
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-255 TJm
+(b) 4.9813 Tj
+20 TJm
+(uilt) 13.2901 Tj
+-255 TJm
+(with) 17.7135 Tj
+-255 TJm
+(such) 18.2614 Tj
+-255 TJm
+(a) 4.42339 Tj
+-255 TJm
+(limitation,) 41.2452 Tj
+-256 TJm
+(run) 13.2801 Tj
+-255 TJm
+(it) 5.53921 Tj
+-255 TJm
+(without) 30.4457 Tj
+-255 TJm
+(ar) 7.74094 Tj
+18 TJm
+(guments.) 36.2539 Tj
+-325 TJm
+(In) 8.29885 Tj
+-255 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-256 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ent) 12.1743 Tj
+-255 TJm
+(you) 14.9439 Tj
+-255 TJm
+(can) 13.8281 Tj
+-255 TJm
+(b) 4.9813 Tj
+20 TJm
+(uild) 15.5018 Tj
+-255 TJm
+(yourself) 32.6474 Tj
+-255 TJm
+(an) 9.40469 Tj
+-255 TJm
+(unlimited) 38.1966 Tj
+-255 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-255 TJm
+(if) 6.08715 Tj
+72 410.278 Td
+(you) 14.9439 Tj
+-250 TJm
+(can) 13.8281 Tj
+-250 TJm
+(recompile) 39.8404 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 176.318 410.278] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -176.318 -410.278] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+176.318 410.278 Td
+/F134_0 9.9626 Tf
+(MaybeUInt64) 65.7532 Tj
+[1 0 0 1 242.071 410.278] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -242.071 -410.278] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+244.562 410.278 Td
+/F130_0 9.9626 Tf
+(set) 11.0684 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(an) 9.40469 Tj
+-250 TJm
+(unsigned) 35.9749 Tj
+-250 TJm
+(64-bit) 23.8007 Tj
+-250 TJm
+(inte) 14.9439 Tj
+15 TJm
+(ger) 12.7222 Tj
+55 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 408.121] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -398.159] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 375.525 Td
+/F122_0 20.6585 Tf
+(2.9.) 34.4584 Tj
+-278 TJm
+(A) 14.9154 Tj
+50 TJm
+(UTHOR) 73.441 Tj
+[1 0 0 1 72 375.267] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -365.305] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 353.608 Td
+/F130_0 9.9626 Tf
+(Julian) 23.8007 Tj
+-250 TJm
+(Se) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(ard,) 15.2129 Tj
+[1 0 0 1 132.801 353.608] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -132.801 -353.608] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+132.801 353.608 Td
+/F134_0 9.9626 Tf
+(jseward@bzip.org) 95.641 Tj
+[1 0 0 1 228.443 353.608] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -156.443 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -342.111] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 331.69 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-299 TJm
+(ideas) 20.4731 Tj
+-300 TJm
+(embodied) 39.2925 Tj
+-299 TJm
+(in) 7.7509 Tj
+[1 0 0 1 166.942 331.69] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -166.942 -331.69] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+166.942 331.69 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 196.83 331.69] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -196.83 -331.69] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+199.813 331.69 Td
+/F130_0 9.9626 Tf
+(are) 12.1643 Tj
+-299 TJm
+(due) 14.386 Tj
+-300 TJm
+(to) 7.7509 Tj
+-299 TJm
+(\(at) 10.5105 Tj
+-300 TJm
+(least\)) 21.579 Tj
+-299 TJm
+(the) 12.1743 Tj
+-300 TJm
+(follo) 18.8194 Tj
+25 TJm
+(wing) 19.9252 Tj
+-299 TJm
+(people:) 29.3299 Tj
+-409 TJm
+(Michael) 32.6474 Tj
+-300 TJm
+(Burro) 23.2427 Tj
+25 TJm
+(ws) 11.0684 Tj
+-299 TJm
+(and) 14.386 Tj
+-299 TJm
+(Da) 11.6164 Tj
+20 TJm
+(vid) 12.7322 Tj
+-300 TJm
+(Wheeler) 33.7433 Tj
+-299 TJm
+(\(for) 14.9339 Tj
+72 319.735 Td
+(the) 12.1743 Tj
+-312 TJm
+(block) 22.1369 Tj
+-313 TJm
+(sorting) 27.6761 Tj
+-312 TJm
+(transformation\),) 64.468 Tj
+-328 TJm
+(Da) 11.6164 Tj
+20 TJm
+(vid) 12.7322 Tj
+-312 TJm
+(Wheeler) 33.7433 Tj
+-313 TJm
+(\(ag) 12.7222 Tj
+5 TJm
+(ain,) 14.6649 Tj
+-327 TJm
+(for) 11.6164 Tj
+-313 TJm
+(the) 12.1743 Tj
+-312 TJm
+(Huf) 15.4918 Tj
+25 TJm
+(fman) 20.4731 Tj
+-312 TJm
+(coder\),) 27.9351 Tj
+-328 TJm
+(Peter) 20.4731 Tj
+-313 TJm
+(Fenwick) 34.3112 Tj
+-312 TJm
+(\(for) 14.9339 Tj
+-312 TJm
+(the) 12.1743 Tj
+-313 TJm
+(structured) 39.8404 Tj
+72 307.78 Td
+(coding) 27.1182 Tj
+-325 TJm
+(model) 24.9065 Tj
+-326 TJm
+(in) 7.7509 Tj
+-325 TJm
+(the) 12.1743 Tj
+-326 TJm
+(original) 30.9936 Tj
+[1 0 0 1 191.156 307.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -191.156 -307.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+191.156 307.779 Td
+/F134_0 9.9626 Tf
+(bzip) 23.9102 Tj
+[1 0 0 1 215.067 307.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -215.067 -307.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+215.067 307.779 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-344 TJm
+(and) 14.386 Tj
+-326 TJm
+(man) 17.1556 Tj
+15 TJm
+(y) 4.9813 Tj
+-325 TJm
+(re\002nements\),) 52.2937 Tj
+-345 TJm
+(and) 14.386 Tj
+-325 TJm
+(Alistair) 29.8878 Tj
+-326 TJm
+(Mof) 17.1556 Tj
+25 TJm
+(f) 3.31755 Tj
+10 TJm
+(at,) 9.68365 Tj
+-344 TJm
+(Radford) 32.6474 Tj
+-325 TJm
+(Neal) 18.8094 Tj
+-326 TJm
+(and) 14.386 Tj
+-325 TJm
+(Ian) 12.7222 Tj
+-326 TJm
+(W) 9.40469 Tj
+40 TJm
+(itten) 17.7135 Tj
+-325 TJm
+(\(for) 14.9339 Tj
+72 295.824 Td
+(the) 12.1743 Tj
+-277 TJm
+(arithmetic) 40.3983 Tj
+-277 TJm
+(coder) 22.1269 Tj
+-277 TJm
+(in) 7.7509 Tj
+-277 TJm
+(the) 12.1743 Tj
+-277 TJm
+(original) 30.9936 Tj
+[1 0 0 1 214.171 295.824] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -214.171 -295.824] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+214.171 295.824 Td
+/F134_0 9.9626 Tf
+(bzip) 23.9102 Tj
+[1 0 0 1 238.082 295.824] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -238.082 -295.824] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+238.082 295.824 Td
+/F130_0 9.9626 Tf
+(\).) 5.8082 Tj
+-782 TJm
+(I) 3.31755 Tj
+-277 TJm
+(am) 12.1743 Tj
+-276 TJm
+(much) 22.1369 Tj
+-277 TJm
+(indebted) 34.3112 Tj
+-277 TJm
+(for) 11.6164 Tj
+-277 TJm
+(their) 18.2614 Tj
+-277 TJm
+(help,) 19.6462 Tj
+-284 TJm
+(support) 29.8878 Tj
+-277 TJm
+(and) 14.386 Tj
+-277 TJm
+(advice.) 28.493 Tj
+-781 TJm
+(See) 14.386 Tj
+-277 TJm
+(the) 12.1743 Tj
+-277 TJm
+(manual) 29.3299 Tj
+72 283.869 Td
+(in) 7.7509 Tj
+-330 TJm
+(the) 12.1743 Tj
+-330 TJm
+(source) 26.0024 Tj
+-330 TJm
+(distrib) 25.4644 Tj
+20 TJm
+(ution) 20.4831 Tj
+-330 TJm
+(for) 11.6164 Tj
+-329 TJm
+(pointers) 32.0995 Tj
+-330 TJm
+(to) 7.7509 Tj
+-330 TJm
+(sources) 29.8778 Tj
+-330 TJm
+(of) 8.29885 Tj
+-330 TJm
+(documentation.) 61.7083 Tj
+-1099 TJm
+(Christian) 36.5329 Tj
+-330 TJm
+(v) 4.9813 Tj
+20 TJm
+(on) 9.9626 Tj
+-330 TJm
+(Roques) 29.8878 Tj
+-330 TJm
+(encouraged) 45.9176 Tj
+-330 TJm
+(me) 12.1743 Tj
+-330 TJm
+(to) 7.7509 Tj
+-330 TJm
+(look) 17.7135 Tj
+72 271.914 Td
+(for) 11.6164 Tj
+-271 TJm
+(f) 3.31755 Tj
+10 TJm
+(aster) 18.8094 Tj
+-271 TJm
+(sorting) 27.6761 Tj
+-271 TJm
+(algorithms,) 45.1107 Tj
+-276 TJm
+(so) 8.85675 Tj
+-272 TJm
+(as) 8.29885 Tj
+-271 TJm
+(to) 7.7509 Tj
+-271 TJm
+(speed) 22.6848 Tj
+-271 TJm
+(up) 9.9626 Tj
+-271 TJm
+(compression.) 52.8516 Tj
+-746 TJm
+(Bela) 18.2614 Tj
+-271 TJm
+(Lubkin) 28.782 Tj
+-271 TJm
+(encouraged) 45.9176 Tj
+-271 TJm
+(me) 12.1743 Tj
+-272 TJm
+(to) 7.7509 Tj
+-271 TJm
+(impro) 23.8007 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-271 TJm
+(the) 12.1743 Tj
+-271 TJm
+(w) 7.193 Tj
+10 TJm
+(orst-case) 35.4071 Tj
+72 259.959 Td
+(compression) 50.3609 Tj
+-340 TJm
+(performance.) 52.8317 Tj
+-580 TJm
+(Donna) 26.5603 Tj
+-339 TJm
+(Robinson) 38.1966 Tj
+-340 TJm
+(XMLised) 38.1866 Tj
+-340 TJm
+(the) 12.1743 Tj
+-340 TJm
+(documentation.) 61.7083 Tj
+-580 TJm
+(Man) 18.2614 Tj
+15 TJm
+(y) 4.9813 Tj
+-340 TJm
+(people) 26.5603 Tj
+-340 TJm
+(sent) 16.0497 Tj
+-339 TJm
+(patches,) 32.3685 Tj
+-363 TJm
+(helped) 26.5603 Tj
+-340 TJm
+(with) 17.7135 Tj
+72 248.004 Td
+(portability) 41.5142 Tj
+-250 TJm
+(problems,) 39.5714 Tj
+-250 TJm
+(lent) 14.9439 Tj
+-250 TJm
+(machines,) 40.1194 Tj
+-250 TJm
+(g) 4.9813 Tj
+5 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(advice) 26.0024 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(were) 19.3573 Tj
+-250 TJm
+(generally) 37.0708 Tj
+-250 TJm
+(helpful.) 30.7147 Tj
+[1 0 0 1 72 245.847] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -194.995] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.5851] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 43.0633 -6.4855] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.332 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+539.395 50.9514 Td
+/F130_0 9.9626 Tf
+(7) 4.9813 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 11 11
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 4.3836 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 141.643 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -141.643 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -13.9477] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -15.0365 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 701.916 Td
+/F122_0 24.7902 Tf
+(3.) 20.675 Tj
+-556 TJm
+(Pr) 26.1785 Tj
+20 TJm
+(ogramming) 134.983 Tj
+-278 TJm
+(with) 49.5804 Tj
+[1 0 0 1 330.484 701.916] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -330.484 -701.916] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+330.484 701.916 Td
+/F392_0 24.7902 Tf
+(libbzip2) 118.993 Tj
+[1 0 0 1 449.477 701.916] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -377.477 -5.5156] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -14.9439] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -671.493] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 656.35 Td
+/F122_0 17.2154 Tf
+(T) 10.5186 Tj
+80 TJm
+(ab) 20.0904 Tj
+10 TJm
+(le) 14.3576 Tj
+-278 TJm
+(of) 16.2513 Tj
+-278 TJm
+(Contents) 74.5943 Tj
+[1 0 0 1 72 647.528] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.7401] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -635.788] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 635.788 Td
+/F130_0 9.9626 Tf
+(3.1.) 14.9439 Tj
+-310 TJm
+(T) 6.08715 Tj
+80 TJm
+(op-le) 20.4731 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(structure) 34.8591 Tj
+[1 0 0 1 164.921 635.788] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.902 -635.788] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+179.997 635.788 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 635.788] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -635.788] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 635.788 Td
+/F130_0 9.9626 Tf
+(8) 4.9813 Tj
+[1 0 0 1 516.09 635.788] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -623.832] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 623.832 Td
+/F130_0 9.9626 Tf
+(3.1.1.) 22.4159 Tj
+-310 TJm
+(Lo) 11.0684 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(summary) 37.0808 Tj
+[1 0 0 1 177.374 623.832] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -182.355 -623.832] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+192.866 623.832 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 623.832] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -623.832] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 623.832 Td
+/F130_0 9.9626 Tf
+(9) 4.9813 Tj
+[1 0 0 1 516.09 623.832] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1569] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -611.877] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 611.877 Td
+/F130_0 9.9626 Tf
+(3.1.2.) 22.4159 Tj
+-310 TJm
+(High-le) 30.4357 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(summary) 37.0808 Tj
+[1 0 0 1 179.287 611.877] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -184.268 -611.877] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+193.822 611.877 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 611.877] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -611.877] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 611.877 Td
+/F130_0 9.9626 Tf
+(9) 4.9813 Tj
+[1 0 0 1 516.09 611.877] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -599.922] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 599.922 Td
+/F130_0 9.9626 Tf
+(3.1.3.) 22.4159 Tj
+-310 TJm
+(Utility) 26.0223 Tj
+-250 TJm
+(functions) 37.0808 Tj
+-250 TJm
+(summary) 37.0808 Tj
+[1 0 0 1 202.669 599.922] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -207.65 -599.922] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+216.582 599.922 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 511.108 599.922] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.108 -599.922] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.108 599.922 Td
+/F130_0 9.9626 Tf
+(9) 4.9813 Tj
+[1 0 0 1 516.09 599.922] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -587.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 587.967 Td
+/F130_0 9.9626 Tf
+(3.2.) 14.9439 Tj
+-310 TJm
+(Error) 21.0211 Tj
+-250 TJm
+(handling) 34.8691 Tj
+[1 0 0 1 148.413 587.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -153.394 -587.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+162.611 587.967 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 587.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -587.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 587.967 Td
+/F130_0 9.9626 Tf
+(10) 9.9626 Tj
+[1 0 0 1 516.09 587.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1569] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -576.012] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 576.012 Td
+/F130_0 9.9626 Tf
+(3.3.) 14.9439 Tj
+-310 TJm
+(Lo) 11.0684 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+[1 0 0 1 167.571 576.012] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -172.552 -576.012] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+181.045 576.012 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 576.012] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -576.012] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 576.012 Td
+/F130_0 9.9626 Tf
+(11) 9.9626 Tj
+[1 0 0 1 516.09 576.012] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -0.0995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.8557] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -564.056] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 564.056 Td
+/F130_0 9.9626 Tf
+(3.3.1.) 22.4159 Tj
+[1 0 0 1 97.5043 564.056] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -564.056] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 564.056 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 205.101 564.056] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.082 -564.056] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+219.736 564.056 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 564.056] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -564.056] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 564.056 Td
+/F130_0 9.9626 Tf
+(11) 9.9626 Tj
+[1 0 0 1 516.09 564.056] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -552.101] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 552.101 Td
+/F130_0 9.9626 Tf
+(3.3.2.) 22.4159 Tj
+[1 0 0 1 97.5043 552.101] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -552.101] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 552.101 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 181.19 552.101] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -186.172 -552.101] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+194.497 552.101 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 552.101] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -552.101] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 552.101 Td
+/F130_0 9.9626 Tf
+(13) 9.9626 Tj
+[1 0 0 1 516.09 552.101] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -540.146] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 540.146 Td
+/F130_0 9.9626 Tf
+(3.3.3.) 22.4159 Tj
+[1 0 0 1 97.5043 540.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -540.146] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 540.146 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressEnd) 101.619 Tj
+[1 0 0 1 199.123 540.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.105 -540.146] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+214.533 540.146 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 540.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -540.146] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 540.146 Td
+/F130_0 9.9626 Tf
+(16) 9.9626 Tj
+[1 0 0 1 516.09 540.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -528.191] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 528.191 Td
+/F130_0 9.9626 Tf
+(3.3.4.) 22.4159 Tj
+[1 0 0 1 97.5043 528.191] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -528.191] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 528.191 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressInit) 119.551 Tj
+[1 0 0 1 217.056 528.191] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -222.037 -528.191] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+232.355 528.191 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 528.191] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -528.191] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 528.191 Td
+/F130_0 9.9626 Tf
+(16) 9.9626 Tj
+[1 0 0 1 516.09 528.191] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -516.236] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 516.236 Td
+/F130_0 9.9626 Tf
+(3.3.5.) 22.4159 Tj
+[1 0 0 1 97.5043 516.236] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -516.236] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 516.236 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 193.146 516.236] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -198.127 -516.236] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+207.116 516.236 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 516.236] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -516.236] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 516.236 Td
+/F130_0 9.9626 Tf
+(17) 9.9626 Tj
+[1 0 0 1 516.09 516.236] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -504.281] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 504.281 Td
+/F130_0 9.9626 Tf
+(3.3.6.) 22.4159 Tj
+[1 0 0 1 97.5043 504.281] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -504.281] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 504.281 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressEnd) 113.574 Tj
+[1 0 0 1 211.078 504.281] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -216.06 -504.281] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+224.938 504.281 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 504.281] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -504.281] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 504.281 Td
+/F130_0 9.9626 Tf
+(18) 9.9626 Tj
+[1 0 0 1 516.09 504.281] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -492.325] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 492.325 Td
+/F130_0 9.9626 Tf
+(3.4.) 14.9439 Tj
+-310 TJm
+(High-le) 30.4357 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+[1 0 0 1 169.483 492.325] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -174.465 -492.325] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+184.216 492.325 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 492.325] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -492.325] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 492.325 Td
+/F130_0 9.9626 Tf
+(18) 9.9626 Tj
+[1 0 0 1 516.09 492.325] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -480.37] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 480.37 Td
+/F130_0 9.9626 Tf
+(3.4.1.) 22.4159 Tj
+[1 0 0 1 97.5043 480.37] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -480.37] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 480.37 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadOpen) 83.6858 Tj
+[1 0 0 1 181.19 480.37] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -186.172 -480.37] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+194.497 480.37 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 480.37] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -480.37] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 480.37 Td
+/F130_0 9.9626 Tf
+(19) 9.9626 Tj
+[1 0 0 1 516.09 480.37] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -468.415] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 468.415 Td
+/F130_0 9.9626 Tf
+(3.4.2.) 22.4159 Tj
+[1 0 0 1 97.5043 468.415] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -468.415] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 468.415 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 157.28 468.415] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -162.261 -468.415] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+171.472 468.415 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 468.415] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -468.415] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 468.415 Td
+/F130_0 9.9626 Tf
+(20) 9.9626 Tj
+[1 0 0 1 516.09 468.415] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6452] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -456.46] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 456.46 Td
+/F130_0 9.9626 Tf
+(3.4.3.) 22.4159 Tj
+[1 0 0 1 97.5043 456.46] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -456.46] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 456.46 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadGetUnused) 113.574 Tj
+[1 0 0 1 211.078 456.46] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -216.06 -456.46] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+224.938 456.46 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 456.46] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -456.46] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 456.46 Td
+/F130_0 9.9626 Tf
+(21) 9.9626 Tj
+[1 0 0 1 516.09 456.46] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6452] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -444.505] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 444.505 Td
+/F130_0 9.9626 Tf
+(3.4.4.) 22.4159 Tj
+[1 0 0 1 97.5043 444.505] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -444.505] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 444.505 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 187.168 444.505] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -192.149 -444.505] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+201.914 444.505 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 444.505] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -444.505] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 444.505 Td
+/F130_0 9.9626 Tf
+(22) 9.9626 Tj
+[1 0 0 1 516.09 444.505] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6451] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -432.55] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 432.55 Td
+/F130_0 9.9626 Tf
+(3.4.5.) 22.4159 Tj
+[1 0 0 1 97.5043 432.55] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -432.55] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 432.55 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteOpen) 89.6634 Tj
+[1 0 0 1 187.168 432.55] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -192.149 -432.55] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+201.914 432.55 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 432.55] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -432.55] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 432.55 Td
+/F130_0 9.9626 Tf
+(22) 9.9626 Tj
+[1 0 0 1 516.09 432.55] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -420.594] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 420.594 Td
+/F130_0 9.9626 Tf
+(3.4.6.) 22.4159 Tj
+[1 0 0 1 97.5043 420.594] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -420.594] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 420.594 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWrite) 65.7532 Tj
+[1 0 0 1 163.258 420.594] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -168.239 -420.594] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+176.675 420.594 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 420.594] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -420.594] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 420.594 Td
+/F130_0 9.9626 Tf
+(23) 9.9626 Tj
+[1 0 0 1 516.09 420.594] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6452] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -408.639] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 408.639 Td
+/F130_0 9.9626 Tf
+(3.4.7.) 22.4159 Tj
+[1 0 0 1 97.5043 408.639] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -408.639] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 408.639 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteClose) 95.641 Tj
+[1 0 0 1 193.146 408.639] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -198.127 -408.639] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+207.116 408.639 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 408.639] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -408.639] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 408.639 Td
+/F130_0 9.9626 Tf
+(23) 9.9626 Tj
+[1 0 0 1 516.09 408.639] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.6451] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -396.684] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 396.684 Td
+/F130_0 9.9626 Tf
+(3.4.8.) 22.4159 Tj
+-310 TJm
+(Handling) 37.0808 Tj
+-250 TJm
+(embedded) 40.9463 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(streams) 30.4357 Tj
+[1 0 0 1 279.56 396.684] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -284.541 -396.684] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+294.601 396.684 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 396.684] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -396.684] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 396.684 Td
+/F130_0 9.9626 Tf
+(24) 9.9626 Tj
+[1 0 0 1 516.09 396.684] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -384.729] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 384.729 Td
+/F130_0 9.9626 Tf
+(3.4.9.) 22.4159 Tj
+-310 TJm
+(Standard) 35.417 Tj
+-250 TJm
+(\002le-reading/writing) 77.4791 Tj
+-250 TJm
+(code) 18.8094 Tj
+[1 0 0 1 234.19 384.729] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -239.172 -384.729] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+247.564 384.729 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 384.729] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -384.729] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 384.729 Td
+/F130_0 9.9626 Tf
+(25) 9.9626 Tj
+[1 0 0 1 516.09 384.729] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -372.774] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 372.774 Td
+/F130_0 9.9626 Tf
+(3.5.) 14.9439 Tj
+-310 TJm
+(Utility) 26.0223 Tj
+-250 TJm
+(functions) 37.0808 Tj
+[1 0 0 1 155.625 372.774] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -160.607 -372.774] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+170.645 372.774 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 372.774] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -372.774] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 372.774 Td
+/F130_0 9.9626 Tf
+(26) 9.9626 Tj
+[1 0 0 1 516.09 372.774] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -360.819] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 360.819 Td
+/F130_0 9.9626 Tf
+(3.5.1.) 22.4159 Tj
+[1 0 0 1 97.5043 360.819] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -360.819] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 360.819 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffCompress) 143.461 Tj
+[1 0 0 1 240.966 360.819] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -245.948 -360.819] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+255.38 360.819 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 360.819] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -360.819] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 360.819 Td
+/F130_0 9.9626 Tf
+(26) 9.9626 Tj
+[1 0 0 1 516.09 360.819] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -348.863] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 348.863 Td
+/F130_0 9.9626 Tf
+(3.5.2.) 22.4159 Tj
+[1 0 0 1 97.5043 348.863] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -97.5043 -348.863] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+97.5043 348.863 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffDecompress) 155.417 Tj
+[1 0 0 1 252.922 348.863] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -257.903 -348.863] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+267.999 348.863 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 348.863] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -348.863] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 348.863 Td
+/F130_0 9.9626 Tf
+(27) 9.9626 Tj
+[1 0 0 1 516.09 348.863] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -1.5342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -10.421] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -336.908] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 336.908 Td
+/F130_0 9.9626 Tf
+(3.6.) 14.9439 Tj
+[1 0 0 1 90.0324 336.908] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90.0324 -336.908] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90.0324 336.908 Td
+/F134_0 9.9626 Tf
+(zlib) 23.9102 Tj
+[1 0 0 1 113.943 336.908] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.943 -336.908] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+116.433 336.908 Td
+/F130_0 9.9626 Tf
+(compatibility) 53.1405 Tj
+-250 TJm
+(functions) 37.0808 Tj
+[1 0 0 1 209.144 336.908] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -214.126 -336.908] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+223.971 336.908 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 336.908] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -336.908] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 336.908 Td
+/F130_0 9.9626 Tf
+(28) 9.9626 Tj
+[1 0 0 1 516.09 336.908] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -324.953] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 324.953 Td
+/F130_0 9.9626 Tf
+(3.7.) 14.9439 Tj
+-310 TJm
+(Using) 23.8007 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(library) 26.5603 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(a) 4.42339 Tj
+[1 0 0 1 177.195 324.953] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -177.195 -324.953] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+177.195 324.953 Td
+/F134_0 9.9626 Tf
+(stdio) 29.8878 Tj
+[1 0 0 1 207.083 324.953] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -207.083 -324.953] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+207.083 324.953 Td
+/F130_0 9.9626 Tf
+(-free) 18.7994 Tj
+-250 TJm
+(en) 9.40469 Tj
+40 TJm
+(vironment) 40.9562 Tj
+[1 0 0 1 278.335 324.953] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -283.316 -324.953] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+291.775 324.953 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 324.953] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -324.953] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 324.953 Td
+/F130_0 9.9626 Tf
+(28) 9.9626 Tj
+[1 0 0 1 516.09 324.953] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1569] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -312.998] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 312.998 Td
+/F130_0 9.9626 Tf
+(3.7.1.) 22.4159 Tj
+-310 TJm
+(Getting) 29.8878 Tj
+-250 TJm
+(rid) 11.0684 Tj
+-250 TJm
+(of) 8.29885 Tj
+[1 0 0 1 154.231 312.998] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -154.231 -312.998] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+154.231 312.998 Td
+/F134_0 9.9626 Tf
+(stdio) 29.8878 Tj
+[1 0 0 1 184.119 312.998] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -189.1 -312.998] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+198.175 312.998 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 312.998] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -312.998] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 312.998 Td
+/F130_0 9.9626 Tf
+(29) 9.9626 Tj
+[1 0 0 1 516.09 312.998] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -301.043] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 301.043 Td
+/F130_0 9.9626 Tf
+(3.7.2.) 22.4159 Tj
+-310 TJm
+(Critical) 29.8878 Tj
+-250 TJm
+(error) 19.3573 Tj
+-250 TJm
+(handling) 34.8691 Tj
+[1 0 0 1 186.599 301.043] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -191.58 -301.043] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+201.629 301.043 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 301.043] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -301.043] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 301.043 Td
+/F130_0 9.9626 Tf
+(29) 9.9626 Tj
+[1 0 0 1 516.09 301.043] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -289.088] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 289.088 Td
+/F130_0 9.9626 Tf
+(3.8.) 14.9439 Tj
+-310 TJm
+(Making) 30.9936 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(W) 9.40469 Tj
+40 TJm
+(indo) 17.7135 Tj
+25 TJm
+(ws) 11.0684 Tj
+-250 TJm
+(DLL) 19.3673 Tj
+[1 0 0 1 189.828 289.088] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -194.809 -289.088] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+203.243 289.088 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 289.088] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -289.088] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 289.088 Td
+/F130_0 9.9626 Tf
+(29) 9.9626 Tj
+[1 0 0 1 516.09 289.088] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1569] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -267.006] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 257.207 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-250 TJm
+(chapter) 29.3199 Tj
+-250 TJm
+(describes) 37.0708 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(programming) 54.2364 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 282.448 257.207] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -282.448 -257.207] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+282.448 257.207 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 330.269 257.207] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -330.269 -257.207] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+330.269 257.207 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 255.05] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -245.088] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 235.289 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-273 TJm
+(general) 29.3199 Tj
+-272 TJm
+(background) 47.0334 Tj
+-273 TJm
+(information,) 49.534 Tj
+-278 TJm
+(particularly) 45.9276 Tj
+-273 TJm
+(about) 22.1369 Tj
+-273 TJm
+(memory) 33.2053 Tj
+-272 TJm
+(use) 13.2801 Tj
+-273 TJm
+(and) 14.386 Tj
+-273 TJm
+(performance) 50.341 Tj
+-272 TJm
+(aspects,) 31.2626 Tj
+-279 TJm
+(you') 18.2614 Tj
+50 TJm
+(d) 4.9813 Tj
+-272 TJm
+(be) 9.40469 Tj
+-273 TJm
+(well) 17.1556 Tj
+-273 TJm
+(advised) 30.4357 Tj
+72 223.334 Td
+(to) 7.7509 Tj
+-250 TJm
+(read) 17.1456 Tj
+[1 0 0 1 101.878 223.334] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -101.878 -223.334] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+101.878 223.334 Td
+/F130_0 9.9626 Tf
+(Ho) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+[1 0 0 1 171.636 223.334] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -171.636 -223.334] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+174.126 223.334 Td
+/F130_0 9.9626 Tf
+([2]) 11.6164 Tj
+[1 0 0 1 185.743 223.334] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -185.743 -223.334] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+188.233 223.334 Td
+/F130_0 9.9626 Tf
+(as) 8.29885 Tj
+-250 TJm
+(well.) 19.6462 Tj
+[1 0 0 1 72 221.177] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -211.215] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 188.581 Td
+/F122_0 20.6585 Tf
+(3.1.) 34.4584 Tj
+-278 TJm
+(T) 12.6223 Tj
+80 TJm
+(op-le) 49.3532 Tj
+15 TJm
+(vel) 28.7153 Tj
+-278 TJm
+(structure) 89.5339 Tj
+[1 0 0 1 72 184.305] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -174.343] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 166.664 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 119.821 166.664] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.821 -166.664] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+123.608 166.664 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-380 TJm
+(a) 4.42339 Tj
+-380 TJm
+(\003e) 9.9626 Tj
+15 TJm
+(xible) 19.9252 Tj
+-381 TJm
+(library) 26.5603 Tj
+-380 TJm
+(for) 11.6164 Tj
+-380 TJm
+(compressing) 50.3609 Tj
+-380 TJm
+(and) 14.386 Tj
+-380 TJm
+(decompressing) 59.7656 Tj
+-380 TJm
+(data) 16.5977 Tj
+-381 TJm
+(in) 7.7509 Tj
+-380 TJm
+(the) 12.1743 Tj
+[1 0 0 1 405.291 166.664] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -405.291 -166.664] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+405.291 166.664 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 435.178 166.664] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -435.178 -166.664] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+438.966 166.664 Td
+/F130_0 9.9626 Tf
+(data) 16.5977 Tj
+-380 TJm
+(format.) 29.0509 Tj
+-1401 TJm
+(Although) 37.6387 Tj
+72 154.708 Td
+(packaged) 37.6188 Tj
+-285 TJm
+(as) 8.29885 Tj
+-284 TJm
+(a) 4.42339 Tj
+-285 TJm
+(single) 23.8007 Tj
+-285 TJm
+(entity) 22.6948 Tj
+65 TJm
+(,) 2.49065 Tj
+-293 TJm
+(it) 5.53921 Tj
+-285 TJm
+(helps) 21.031 Tj
+-285 TJm
+(to) 7.7509 Tj
+-284 TJm
+(re) 7.74094 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(ard) 12.7222 Tj
+-285 TJm
+(the) 12.1743 Tj
+-285 TJm
+(library) 26.5603 Tj
+-284 TJm
+(as) 8.29885 Tj
+-285 TJm
+(three) 19.9152 Tj
+-285 TJm
+(separate) 32.6375 Tj
+-284 TJm
+(parts:) 22.1369 Tj
+-380 TJm
+(the) 12.1743 Tj
+-285 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w) 7.193 Tj
+-284 TJm
+(le) 7.193 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-285 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace,) 15.7608 Tj
+-293 TJm
+(and) 14.386 Tj
+-285 TJm
+(the) 12.1743 Tj
+-285 TJm
+(high) 17.7135 Tj
+72 142.753 Td
+(le) 7.193 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace,) 15.7608 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(some) 21.031 Tj
+-250 TJm
+(utility) 23.8106 Tj
+-250 TJm
+(functions.) 39.5714 Tj
+[1 0 0 1 72 140.596] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -130.634] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 120.835 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-349 TJm
+(structure) 34.8591 Tj
+-349 TJm
+(of) 8.29885 Tj
+[1 0 0 1 141.082 120.835] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -141.082 -120.835] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+141.082 120.835 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 188.903 120.835] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -188.903 -120.835] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+188.903 120.835 Td
+/F130_0 9.9626 Tf
+(') 3.31755 Tj
+55 TJm
+(s) 3.87545 Tj
+-349 TJm
+(interf) 21.579 Tj
+10 TJm
+(aces) 17.1456 Tj
+-349 TJm
+(is) 6.64505 Tj
+-349 TJm
+(similar) 27.6761 Tj
+-349 TJm
+(to) 7.7509 Tj
+-349 TJm
+(that) 14.9439 Tj
+-349 TJm
+(of) 8.29885 Tj
+-349 TJm
+(Jean-loup) 38.7346 Tj
+-349 TJm
+(Gailly') 28.224 Tj
+55 TJm
+(s) 3.87545 Tj
+-349 TJm
+(and) 14.386 Tj
+-349 TJm
+(Mark) 21.579 Tj
+-349 TJm
+(Adler') 26.0024 Tj
+55 TJm
+(s) 3.87545 Tj
+-349 TJm
+(e) 4.42339 Tj
+15 TJm
+(xcellent) 31.5416 Tj
+[1 0 0 1 516.09 120.835] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -516.09 -120.835] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+516.09 120.835 Td
+/F134_0 9.9626 Tf
+(zlib) 23.9102 Tj
+[1 0 0 1 540 120.835] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -120.835] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 108.88 Td
+/F130_0 9.9626 Tf
+(library) 26.5603 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 106.723] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -96.7608] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 86.9624 Td
+/F130_0 9.9626 Tf
+(All) 12.7322 Tj
+-242 TJm
+(e) 4.42339 Tj
+15 TJm
+(xternally) 35.417 Tj
+-242 TJm
+(visible) 26.5703 Tj
+-241 TJm
+(symbols) 33.2153 Tj
+-242 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-242 TJm
+(names) 25.4544 Tj
+-242 TJm
+(be) 9.40469 Tj
+15 TJm
+(ginning) 30.4457 Tj
+[1 0 0 1 284.687 86.9624] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -284.687 -86.9624] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+284.687 86.9624 Td
+/F134_0 9.9626 Tf
+(BZ2_) 23.9102 Tj
+[1 0 0 1 308.597 86.9624] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -308.597 -86.9624] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+308.597 86.9624 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-615 TJm
+(This) 17.7135 Tj
+-241 TJm
+(is) 6.64505 Tj
+-242 TJm
+(ne) 9.40469 Tj
+25 TJm
+(w) 7.193 Tj
+-242 TJm
+(in) 7.7509 Tj
+-242 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-242 TJm
+(1.0.) 14.9439 Tj
+-614 TJm
+(The) 15.4918 Tj
+-242 TJm
+(intention) 35.427 Tj
+-242 TJm
+(is) 6.64505 Tj
+-241 TJm
+(to) 7.7509 Tj
+-242 TJm
+(minimise) 37.0908 Tj
+72 75.0073 Td
+(pollution) 35.9849 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(namespaces) 47.5814 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(library) 26.5603 Tj
+-250 TJm
+(clients.) 28.503 Tj
+[1 0 0 1 72 72.8505] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -21.9987] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 4.3836 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 43.0633 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -498.225 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+541.288 50.9514 Td
+/F130_0 9.9626 Tf
+(8) 4.9813 Tj
+[1 0 0 1 455.161 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5986 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -15.0366 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 12 12
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 4.3836 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -344.462 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+420.96 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 498.449 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -498.449 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+498.449 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 546.269 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -15.0365 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(T) 6.08715 Tj
+80 TJm
+(o) 4.9813 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-250 TJm
+(part) 15.4918 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(need) 18.8094 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 240.567 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -240.567 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+240.567 710.037 Td
+/F134_0 9.9626 Tf
+(#include) 47.8205 Tj
+-600 TJm
+(<bzlib.h>) 53.798 Tj
+[1 0 0 1 348.163 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -348.163 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+350.654 710.037 Td
+/F130_0 9.9626 Tf
+(into) 15.5018 Tj
+-250 TJm
+(your) 18.2614 Tj
+-250 TJm
+(sources.) 32.3685 Tj
+[1 0 0 1 72 707.88] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -697.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 679.416 Td
+/F122_0 17.2154 Tf
+(3.1.1.) 43.0729 Tj
+-278 TJm
+(Lo) 21.0372 Tj
+15 TJm
+(w-le) 33.484 Tj
+15 TJm
+(vel) 23.9294 Tj
+-278 TJm
+(summar) 66.9679 Tj
+-10 TJm
+(y) 9.57176 Tj
+[1 0 0 1 72 675.853] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -665.89] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 657.498 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-212 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+-212 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vides) 21.031 Tj
+-212 TJm
+(services) 32.0895 Tj
+-212 TJm
+(for) 11.6164 Tj
+-212 TJm
+(compressing) 50.3609 Tj
+-212 TJm
+(and) 14.386 Tj
+-212 TJm
+(decompress) 47.0334 Tj
+1 TJm
+(ing) 12.7322 Tj
+-212 TJm
+(data) 16.5977 Tj
+-212 TJm
+(in) 7.7509 Tj
+-212 TJm
+(memory) 33.2053 Tj
+65 TJm
+(.) 2.49065 Tj
+-595 TJm
+(There') 26.5503 Tj
+55 TJm
+(s) 3.87545 Tj
+-212 TJm
+(no) 9.9626 Tj
+-212 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vision) 24.3586 Tj
+-212 TJm
+(for) 11.6164 Tj
+-212 TJm
+(dealing) 29.3299 Tj
+72 645.543 Td
+(with) 17.7135 Tj
+-213 TJm
+(\002les,) 19.0983 Tj
+-220 TJm
+(streams) 30.4357 Tj
+-213 TJm
+(or) 8.29885 Tj
+-213 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-213 TJm
+(other) 20.4731 Tj
+-213 TJm
+(I/O) 13.2801 Tj
+-213 TJm
+(mechanisms,) 51.7457 Tj
+-221 TJm
+(just) 14.396 Tj
+-213 TJm
+(straight) 29.8878 Tj
+-213 TJm
+(memory-to-memory) 80.7967 Tj
+-213 TJm
+(w) 7.193 Tj
+10 TJm
+(ork.) 15.7708 Tj
+-595 TJm
+(In) 8.29885 Tj
+-213 TJm
+(f) 3.31755 Tj
+10 TJm
+(act,) 14.107 Tj
+-221 TJm
+(this) 14.396 Tj
+-213 TJm
+(part) 15.4918 Tj
+-213 TJm
+(of) 8.29885 Tj
+-213 TJm
+(the) 12.1743 Tj
+-213 TJm
+(library) 26.5603 Tj
+72 633.588 Td
+(can) 13.8281 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(compiled) 37.0808 Tj
+-250 TJm
+(without) 30.4457 Tj
+-250 TJm
+(inclusion) 36.5329 Tj
+-250 TJm
+(of) 8.29885 Tj
+[1 0 0 1 222.534 633.588] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -222.534 -633.588] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+222.534 633.588 Td
+/F134_0 9.9626 Tf
+(stdio.h) 41.8429 Tj
+[1 0 0 1 264.377 633.588] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -264.377 -633.588] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+264.377 633.588 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(may) 17.1556 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(helpful) 28.224 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(embedded) 40.9463 Tj
+-250 TJm
+(applications.) 50.6399 Tj
+[1 0 0 1 72 631.431] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -621.469] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 611.67 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-250 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(part) 15.4918 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(library) 26.5603 Tj
+-250 TJm
+(has) 13.2801 Tj
+-250 TJm
+(no) 9.9626 Tj
+-250 TJm
+(global) 24.9065 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(ariables) 30.9837 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(therefore) 35.955 Tj
+-250 TJm
+(thread-safe.) 46.7445 Tj
+[1 0 0 1 72 609.513] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -599.551] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 589.752 Td
+/F130_0 9.9626 Tf
+(Six) 13.2901 Tj
+-875 TJm
+(routines) 32.0995 Tj
+-876 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-875 TJm
+(up) 9.9626 Tj
+-876 TJm
+(the) 12.1743 Tj
+-875 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w) 7.193 Tj
+-876 TJm
+(le) 7.193 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-875 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace:) 16.0398 Tj
+[1 0 0 1 308.791 589.752] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -308.791 -589.752] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+308.791 589.752 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 416.387 589.752] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -416.387 -589.752] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+416.387 589.752 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 429.158 589.752] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -429.158 -589.752] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+429.158 589.752 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 512.844 589.752] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -512.844 -589.752] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+512.844 589.752 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-1032 TJm
+(and) 14.386 Tj
+[1 0 0 1 72 577.797] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -577.797] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 577.797 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressEnd) 101.619 Tj
+[1 0 0 1 173.619 577.797] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -173.619 -577.797] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+186.15 577.797 Td
+/F130_0 9.9626 Tf
+(for) 11.6164 Tj
+-1258 TJm
+(compression,) 52.8516 Tj
+-1510 TJm
+(and) 14.386 Tj
+-1257 TJm
+(a) 4.42339 Tj
+-1258 TJm
+(corresponding) 56.996 Tj
+-1258 TJm
+(trio) 13.8381 Tj
+[1 0 0 1 417.958 577.797] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -417.958 -577.797] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+417.958 577.797 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressInit) 119.551 Tj
+[1 0 0 1 537.509 577.797] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -537.509 -577.797] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+537.509 577.797 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 72 565.842] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -565.842] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 565.842 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 167.641 565.842] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -167.641 -565.842] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+172.707 565.842 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 192.158 565.842] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -192.158 -565.842] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+192.158 565.842 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressEnd) 113.574 Tj
+[1 0 0 1 305.732 565.842] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -305.732 -565.842] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+310.798 565.842 Td
+/F130_0 9.9626 Tf
+(for) 11.6164 Tj
+-508 TJm
+(decompression.) 62.2563 Tj
+-2171 TJm
+(The) 15.4918 Tj
+[1 0 0 1 431.918 565.842] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -431.918 -565.842] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+431.918 564.099 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+437.895 565.842 Td
+(Init) 23.9102 Tj
+[1 0 0 1 461.805 565.842] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -461.805 -565.842] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+466.871 565.842 Td
+/F130_0 9.9626 Tf
+(functions) 37.0808 Tj
+-508 TJm
+(allocate) 30.9837 Tj
+72 553.887 Td
+(memory) 33.2053 Tj
+-574 TJm
+(for) 11.6164 Tj
+-573 TJm
+(compression/decompression) 112.896 Tj
+-574 TJm
+(and) 14.386 Tj
+-574 TJm
+(do) 9.9626 Tj
+-573 TJm
+(other) 20.4731 Tj
+-574 TJm
+(initialisations,) 56.1891 Tj
+-654 TJm
+(whilst) 24.3586 Tj
+-574 TJm
+(the) 12.1743 Tj
+[1 0 0 1 419.502 553.887] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -419.502 -553.887] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.502 552.144 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+425.48 553.887 Td
+(End) 17.9327 Tj
+[1 0 0 1 443.413 553.887] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -443.413 -553.887] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+449.128 553.887 Td
+/F130_0 9.9626 Tf
+(functions) 37.0808 Tj
+-574 TJm
+(close) 20.4731 Tj
+-573 TJm
+(do) 9.9626 Tj
+25 TJm
+(wn) 12.1743 Tj
+72 541.932 Td
+(operations) 41.5042 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(release) 27.6562 Tj
+-250 TJm
+(memory) 33.2053 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 539.775] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -529.812] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 520.014 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-303 TJm
+(real) 14.9339 Tj
+-303 TJm
+(w) 7.193 Tj
+10 TJm
+(ork) 13.2801 Tj
+-303 TJm
+(is) 6.64505 Tj
+-303 TJm
+(done) 19.3673 Tj
+-303 TJm
+(by) 9.9626 Tj
+[1 0 0 1 176.892 520.014] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -176.892 -520.014] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+176.892 520.014 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 260.578 520.014] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -260.578 -520.014] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+263.598 520.014 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 281.003 520.014] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -281.003 -520.014] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+281.003 520.014 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 376.645 520.014] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -376.645 -520.014] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+376.645 520.014 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-939 TJm
+(These) 23.7907 Tj
+-303 TJm
+(compress) 37.6287 Tj
+-303 TJm
+(and) 14.386 Tj
+-303 TJm
+(decompress) 47.0334 Tj
+-303 TJm
+(data) 16.5977 Tj
+72 508.059 Td
+(from) 19.3673 Tj
+-205 TJm
+(a) 4.42339 Tj
+-205 TJm
+(user) 16.5977 Tj
+20 TJm
+(-supplied) 37.0808 Tj
+-205 TJm
+(input) 20.4831 Tj
+-206 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-205 TJm
+(to) 7.7509 Tj
+-205 TJm
+(a) 4.42339 Tj
+-205 TJm
+(user) 16.5977 Tj
+20 TJm
+(-supplied) 37.0808 Tj
+-205 TJm
+(output) 25.4644 Tj
+-205 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+55 TJm
+(.) 2.49065 Tj
+-591 TJm
+(These) 23.7907 Tj
+-205 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fers) 14.9339 Tj
+-205 TJm
+(can) 13.8281 Tj
+-205 TJm
+(be) 9.40469 Tj
+-205 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-205 TJm
+(size;) 18.2614 Tj
+-220 TJm
+(arbitrary) 34.3012 Tj
+-206 TJm
+(quantities) 38.7446 Tj
+-205 TJm
+(of) 8.29885 Tj
+72 496.104 Td
+(data) 16.5977 Tj
+-258 TJm
+(are) 12.1643 Tj
+-258 TJm
+(handled) 31.5416 Tj
+-258 TJm
+(by) 9.9626 Tj
+-257 TJm
+(making) 29.8878 Tj
+-258 TJm
+(repeated) 33.7433 Tj
+-258 TJm
+(calls) 18.2614 Tj
+-258 TJm
+(to) 7.7509 Tj
+-258 TJm
+(these) 20.4731 Tj
+-258 TJm
+(functions.) 39.5714 Tj
+-667 TJm
+(This) 17.7135 Tj
+-258 TJm
+(is) 6.64505 Tj
+-258 TJm
+(a) 4.42339 Tj
+-257 TJm
+(\003e) 9.9626 Tj
+15 TJm
+(xible) 19.9252 Tj
+-258 TJm
+(mechanism) 45.3796 Tj
+-258 TJm
+(allo) 14.9439 Tj
+25 TJm
+(wing) 19.9252 Tj
+-258 TJm
+(a) 4.42339 Tj
+-258 TJm
+(consumer) 38.7346 Tj
+20 TJm
+(-pull) 18.8194 Tj
+72 484.148 Td
+(style) 18.8194 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(acti) 14.386 Tj
+25 TJm
+(vity) 15.5018 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(or) 8.29885 Tj
+-250 TJm
+(producer) 35.4071 Tj
+20 TJm
+(-push,) 24.6275 Tj
+-250 TJm
+(or) 8.29885 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(mixture) 30.9936 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(both.) 20.2042 Tj
+[1 0 0 1 72 481.992] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -472.029] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 453.527 Td
+/F122_0 17.2154 Tf
+(3.1.2.) 43.0729 Tj
+-278 TJm
+(High-le) 58.343 Tj
+15 TJm
+(vel) 23.9294 Tj
+-278 TJm
+(summar) 66.9679 Tj
+-10 TJm
+(y) 9.57176 Tj
+[1 0 0 1 72 449.697] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -439.734] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 431.61 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-284 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+-284 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vides) 21.031 Tj
+-285 TJm
+(some) 21.031 Tj
+-284 TJm
+(handy) 24.3486 Tj
+-284 TJm
+(wrappers) 36.5129 Tj
+-284 TJm
+(around) 27.6661 Tj
+-284 TJm
+(the) 12.1743 Tj
+-284 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-285 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+-284 TJm
+(to) 7.7509 Tj
+-284 TJm
+(f) 3.31755 Tj
+10 TJm
+(acilitate) 31.5416 Tj
+-284 TJm
+(reading) 29.8778 Tj
+-284 TJm
+(and) 14.386 Tj
+-285 TJm
+(writ) 16.0497 Tj
+1 TJm
+(ing) 12.7322 Tj
+[1 0 0 1 510.112 431.61] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -510.112 -431.61] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+510.112 431.61 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 540 431.61] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -431.61] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 419.654 Td
+/F130_0 9.9626 Tf
+(format) 26.5603 Tj
+-347 TJm
+(\002les) 16.6077 Tj
+-346 TJm
+(\() 3.31755 Tj
+[1 0 0 1 125.391 419.654] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -125.391 -419.654] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+125.391 419.654 Td
+/F134_0 9.9626 Tf
+(.bz2) 23.9102 Tj
+[1 0 0 1 149.301 419.654] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -149.301 -419.654] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+152.754 419.654 Td
+/F130_0 9.9626 Tf
+(\002les\).) 22.4159 Tj
+-1200 TJm
+(The) 15.4918 Tj
+-346 TJm
+(routines) 32.0995 Tj
+-347 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vide) 17.1556 Tj
+-346 TJm
+(hooks) 23.8007 Tj
+-347 TJm
+(to) 7.7509 Tj
+-346 TJm
+(f) 3.31755 Tj
+10 TJm
+(acilitate) 31.5416 Tj
+-347 TJm
+(reading) 29.8778 Tj
+-347 TJm
+(\002les) 16.6077 Tj
+-346 TJm
+(in) 7.7509 Tj
+-347 TJm
+(which) 24.3486 Tj
+-346 TJm
+(the) 12.1743 Tj
+[1 0 0 1 460.049 419.654] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -460.049 -419.654] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+460.049 419.654 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 489.937 419.654] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -489.937 -419.654] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+493.39 419.654 Td
+/F130_0 9.9626 Tf
+(data) 16.5977 Tj
+-347 TJm
+(stream) 26.5603 Tj
+72 407.699 Td
+(is) 6.64505 Tj
+-339 TJm
+(embedded) 40.9463 Tj
+-339 TJm
+(within) 25.4644 Tj
+-339 TJm
+(some) 21.031 Tj
+-339 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ger) 12.7222 Tj
+20 TJm
+(-scale) 23.2328 Tj
+-339 TJm
+(\002le) 12.7322 Tj
+-339 TJm
+(structure,) 37.3498 Tj
+-361 TJm
+(or) 8.29885 Tj
+-339 TJm
+(wh) 12.1743 Tj
+-1 TJm
+(e) 4.42339 Tj
+1 TJm
+(re) 7.74094 Tj
+-340 TJm
+(there) 19.9152 Tj
+-339 TJm
+(are) 12.1643 Tj
+-339 TJm
+(multiple) 33.2153 Tj
+[1 0 0 1 400.941 407.699] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -400.941 -407.699] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+400.941 407.699 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 430.829 407.699] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -430.829 -407.699] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+434.207 407.699 Td
+/F130_0 9.9626 Tf
+(data) 16.5977 Tj
+-339 TJm
+(streams) 30.4357 Tj
+-339 TJm
+(concatenated) 52.0048 Tj
+72 395.744 Td
+(end-to-end.) 45.6486 Tj
+[1 0 0 1 72 395.644] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -385.682] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 373.826 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-332 TJm
+(reading) 29.8778 Tj
+-333 TJm
+(\002les,) 19.0983 Tj
+[1 0 0 1 144.803 373.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -144.803 -373.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+144.803 373.826 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadOpen) 83.6858 Tj
+[1 0 0 1 228.489 373.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -228.489 -373.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+228.489 373.826 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 234.496 373.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -234.496 -373.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+234.496 373.826 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 294.272 373.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -294.272 -373.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+294.272 373.826 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 300.279 373.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -300.279 -373.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+300.279 373.826 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 389.942 373.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -389.942 -373.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+393.253 373.826 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 410.951 373.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -410.951 -373.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+410.951 373.826 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadGetUnused) 113.574 Tj
+[1 0 0 1 524.525 373.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -524.525 -373.826] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+527.836 373.826 Td
+/F130_0 9.9626 Tf
+(are) 12.1643 Tj
+72 361.871 Td
+(supplied.) 36.2539 Tj
+-620 TJm
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-250 TJm
+(writing) 28.782 Tj
+-250 TJm
+(\002les,) 19.0983 Tj
+[1 0 0 1 183.471 361.871] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -183.471 -361.871] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+183.471 361.871 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteOpen) 89.6634 Tj
+[1 0 0 1 273.135 361.871] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -273.135 -361.871] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+273.135 361.871 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 278.116 361.871] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.116 -361.871] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+278.116 361.871 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWrite) 65.7532 Tj
+[1 0 0 1 343.869 361.871] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -343.869 -361.871] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+346.36 361.871 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 363.237 361.871] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -363.237 -361.871] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+363.237 361.871 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteFinish) 101.619 Tj
+[1 0 0 1 464.856 361.871] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -464.856 -361.871] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+467.346 361.871 Td
+/F130_0 9.9626 Tf
+(are) 12.1643 Tj
+-250 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+25 TJm
+(ailable.) 29.0509 Tj
+[1 0 0 1 72 359.714] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -349.751] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 339.953 Td
+/F130_0 9.9626 Tf
+(As) 11.0684 Tj
+-374 TJm
+(with) 17.7135 Tj
+-374 TJm
+(the) 12.1743 Tj
+-375 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-374 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-405 TJm
+(no) 9.9626 Tj
+-374 TJm
+(global) 24.9065 Tj
+-374 TJm
+(v) 4.9813 Tj
+25 TJm
+(ariables) 30.9837 Tj
+-375 TJm
+(are) 12.1643 Tj
+-374 TJm
+(used) 18.2614 Tj
+-374 TJm
+(so) 8.85675 Tj
+-374 TJm
+(the) 12.1743 Tj
+-374 TJm
+(library) 26.5603 Tj
+-375 TJm
+(is) 6.64505 Tj
+-374 TJm
+(per) 12.7222 Tj
+-374 TJm
+(se) 8.29885 Tj
+-374 TJm
+(thread-safe.) 46.7445 Tj
+-1365 TJm
+(Ho) 12.1743 Tj
+25 TJm
+(we) 11.6164 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+40 TJm
+(,) 2.49065 Tj
+-406 TJm
+(if) 6.08715 Tj
+-374 TJm
+(I/O) 13.2801 Tj
+72 327.998 Td
+(errors) 23.2328 Tj
+-267 TJm
+(occur) 22.1269 Tj
+-267 TJm
+(whilst) 24.3586 Tj
+-267 TJm
+(reading) 29.8778 Tj
+-267 TJm
+(or) 8.29885 Tj
+-267 TJm
+(writing) 28.782 Tj
+-267 TJm
+(the) 12.1743 Tj
+-268 TJm
+(underlying) 43.1679 Tj
+-267 TJm
+(compressed) 47.0334 Tj
+-267 TJm
+(\002les,) 19.0983 Tj
+-271 TJm
+(you) 14.9439 Tj
+-267 TJm
+(may) 17.1556 Tj
+-267 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-267 TJm
+(to) 7.7509 Tj
+-267 TJm
+(consult) 28.782 Tj
+[1 0 0 1 457.199 327.998] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -457.199 -327.998] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+457.199 327.998 Td
+/F134_0 9.9626 Tf
+(errno) 29.8878 Tj
+[1 0 0 1 487.087 327.998] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -487.087 -327.998] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+489.748 327.998 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-267 TJm
+(determine) 39.8404 Tj
+72 316.043 Td
+(the) 12.1743 Tj
+-366 TJm
+(cause) 22.1269 Tj
+-365 TJm
+(of) 8.29885 Tj
+-366 TJm
+(the) 12.1743 Tj
+-365 TJm
+(error) 19.3573 Tj
+55 TJm
+(.) 2.49065 Tj
+-1314 TJm
+(In) 8.29885 Tj
+-366 TJm
+(that) 14.9439 Tj
+-365 TJm
+(case,) 19.6363 Tj
+-395 TJm
+(you') 18.2614 Tj
+50 TJm
+(d) 4.9813 Tj
+-366 TJm
+(need) 18.8094 Tj
+-365 TJm
+(a) 4.42339 Tj
+-366 TJm
+(C) 6.64505 Tj
+-365 TJm
+(library) 26.5603 Tj
+-366 TJm
+(which) 24.3486 Tj
+-366 TJm
+(correctly) 35.4071 Tj
+-365 TJm
+(supports) 33.7633 Tj
+[1 0 0 1 431.668 316.043] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -431.668 -316.043] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+431.668 316.043 Td
+/F134_0 9.9626 Tf
+(errno) 29.8878 Tj
+[1 0 0 1 461.556 316.043] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -461.556 -316.043] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+465.199 316.043 Td
+/F130_0 9.9626 Tf
+(in) 7.7509 Tj
+-366 TJm
+(a) 4.42339 Tj
+-365 TJm
+(multithreaded) 55.3422 Tj
+72 304.088 Td
+(en) 9.40469 Tj
+40 TJm
+(vironment.) 43.4469 Tj
+[1 0 0 1 72 303.988] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -294.025] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 282.17 Td
+/F130_0 9.9626 Tf
+(T) 6.08715 Tj
+80 TJm
+(o) 4.9813 Tj
+-243 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-243 TJm
+(the) 12.1743 Tj
+-242 TJm
+(library) 26.5603 Tj
+-243 TJm
+(a) 4.42339 Tj
+-243 TJm
+(little) 18.2714 Tj
+-242 TJm
+(simpler) 29.8878 Tj
+-243 TJm
+(and) 14.386 Tj
+-243 TJm
+(more) 20.4731 Tj
+-243 TJm
+(portable,) 35.1381 Tj
+[1 0 0 1 289.263 282.17] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -289.263 -282.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+289.263 282.17 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadOpen) 83.6858 Tj
+[1 0 0 1 372.949 282.17] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -372.949 -282.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+375.368 282.17 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 392.172 282.17] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -392.172 -282.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+392.172 282.17 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteOpen) 89.6634 Tj
+[1 0 0 1 481.836 282.17] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -481.836 -282.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+484.254 282.17 Td
+/F130_0 9.9626 Tf
+(require) 28.2141 Tj
+-243 TJm
+(you) 14.9439 Tj
+-242 TJm
+(to) 7.7509 Tj
+72 270.215 Td
+(pass) 17.1556 Tj
+-247 TJm
+(them) 19.9252 Tj
+-248 TJm
+(\002le) 12.7322 Tj
+-247 TJm
+(handles) 30.4357 Tj
+-247 TJm
+(\() 3.31755 Tj
+[1 0 0 1 165.421 270.215] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -165.421 -270.215] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+165.421 270.215 Td
+/F134_0 9.9626 Tf
+(FILE) 23.9102 Tj
+189.331 268.471 Td
+(*) 5.97756 Tj
+[1 0 0 1 195.309 270.215] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -195.309 -270.215] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+195.309 270.215 Td
+/F130_0 9.9626 Tf
+(s\)) 7.193 Tj
+-247 TJm
+(which) 24.3486 Tj
+-248 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-247 TJm
+(pre) 12.7222 Tj
+25 TJm
+(viously) 29.3399 Tj
+-247 TJm
+(been) 18.8094 Tj
+-248 TJm
+(opened) 28.772 Tj
+-247 TJm
+(for) 11.6164 Tj
+-247 TJm
+(reading) 29.8778 Tj
+-247 TJm
+(or) 8.29885 Tj
+-248 TJm
+(writing) 28.782 Tj
+-247 TJm
+(respecti) 30.9837 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ely) 12.1743 Tj
+65 TJm
+(.) 2.49065 Tj
+-618 TJm
+(That) 18.2614 Tj
+-248 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+20 TJm
+(oids) 16.6077 Tj
+72 258.26 Td
+(portability) 41.5142 Tj
+-272 TJm
+(problems) 37.0808 Tj
+-273 TJm
+(associated) 40.9463 Tj
+-272 TJm
+(with) 17.7135 Tj
+-272 TJm
+(\002le) 12.7322 Tj
+-273 TJm
+(operations) 41.5042 Tj
+-272 TJm
+(and) 14.386 Tj
+-272 TJm
+(\002le) 12.7322 Tj
+-273 TJm
+(attrib) 21.031 Tj
+20 TJm
+(utes,) 18.5404 Tj
+-278 TJm
+(whilst) 24.3586 Tj
+-272 TJm
+(not) 12.7322 Tj
+-272 TJm
+(being) 22.1369 Tj
+-273 TJm
+(much) 22.1369 Tj
+-272 TJm
+(of) 8.29885 Tj
+-273 TJm
+(an) 9.40469 Tj
+-272 TJm
+(imposition) 42.63 Tj
+-272 TJm
+(on) 9.9626 Tj
+-273 TJm
+(the) 12.1743 Tj
+72 246.304 Td
+(programmer) 49.2451 Tj
+55 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 244.147] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -234.185] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 215.683 Td
+/F122_0 17.2154 Tf
+(3.1.3.) 43.0729 Tj
+-278 TJm
+(Utility) 47.8244 Tj
+-278 TJm
+(functions) 77.4693 Tj
+-278 TJm
+(summar) 66.9679 Tj
+-10 TJm
+(y) 9.57176 Tj
+[1 0 0 1 72 212.12] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -202.157] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 193.765 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-273 TJm
+(v) 4.9813 Tj
+15 TJm
+(ery) 12.7222 Tj
+-273 TJm
+(simple) 26.5703 Tj
+-273 TJm
+(needs,) 25.1755 Tj
+[1 0 0 1 165.929 193.765] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -165.929 -193.765] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+165.929 193.765 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffCompress) 143.461 Tj
+[1 0 0 1 309.391 193.765] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -309.391 -193.765] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+312.112 193.765 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 329.219 193.765] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -329.219 -193.765] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+329.219 193.765 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffDecompress) 155.417 Tj
+[1 0 0 1 484.636 193.765] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -484.636 -193.765] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+487.357 193.765 Td
+/F130_0 9.9626 Tf
+(are) 12.1643 Tj
+-273 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vided.) 24.6275 Tj
+72 181.81 Td
+(These) 23.7907 Tj
+-374 TJm
+(compress) 37.6287 Tj
+-373 TJm
+(data) 16.5977 Tj
+-374 TJm
+(in) 7.7509 Tj
+-373 TJm
+(memory) 33.2053 Tj
+-374 TJm
+(from) 19.3673 Tj
+-373 TJm
+(one) 14.386 Tj
+-374 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-373 TJm
+(to) 7.7509 Tj
+-374 TJm
+(another) 29.8778 Tj
+-374 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-373 TJm
+(in) 7.7509 Tj
+-374 TJm
+(a) 4.42339 Tj
+-373 TJm
+(single) 23.8007 Tj
+-374 TJm
+(function) 33.2053 Tj
+-373 TJm
+(call.) 16.8766 Tj
+-1362 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-373 TJm
+(should) 26.5703 Tj
+-374 TJm
+(assess) 24.3486 Tj
+72 169.855 Td
+(whether) 32.0895 Tj
+-344 TJm
+(these) 20.4731 Tj
+-343 TJm
+(functions) 37.0808 Tj
+-344 TJm
+(ful\002ll) 22.1469 Tj
+-344 TJm
+(your) 18.2614 Tj
+-343 TJm
+(memory-to-memory) 80.7967 Tj
+-344 TJm
+(compression/decompression) 112.896 Tj
+-343 TJm
+(requirements) 52.0147 Tj
+-344 TJm
+(before) 25.4445 Tj
+-344 TJm
+(in) 7.7509 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(esting) 23.8007 Tj
+72 157.9 Td
+(ef) 7.74094 Tj
+25 TJm
+(fort) 14.386 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(understanding) 56.4481 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(more) 20.4731 Tj
+-250 TJm
+(general) 29.3199 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(more) 20.4731 Tj
+-250 TJm
+(comple) 29.3299 Tj
+15 TJm
+(x) 4.9813 Tj
+-250 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace.) 15.7608 Tj
+[1 0 0 1 72 155.743] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -145.78] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 135.982 Td
+/F130_0 9.9626 Tf
+(Y) 7.193 Tj
+110 TJm
+(oshioka) 30.9936 Tj
+-423 TJm
+(Tsuneo) 29.3299 Tj
+-422 TJm
+(\() 3.31755 Tj
+[1 0 0 1 150.16 135.982] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -150.16 -135.982] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+150.16 135.982 Td
+/F134_0 9.9626 Tf
+(tsuneo@rr.iij4u.or.jp) 125.529 Tj
+[1 0 0 1 275.69 135.982] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -275.69 -135.982] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+275.69 135.982 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-423 TJm
+(has) 13.2801 Tj
+-422 TJm
+(contrib) 28.224 Tj
+20 TJm
+(uted) 17.1556 Tj
+-423 TJm
+(some) 21.031 Tj
+-423 TJm
+(functions) 37.0808 Tj
+-422 TJm
+(to) 7.7509 Tj
+-423 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-423 TJm
+(better) 22.6848 Tj
+[1 0 0 1 476.462 135.982] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -476.462 -135.982] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+476.462 135.982 Td
+/F134_0 9.9626 Tf
+(zlib) 23.9102 Tj
+[1 0 0 1 500.372 135.982] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -500.372 -135.982] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+504.583 135.982 Td
+/F130_0 9.9626 Tf
+(compati-) 35.417 Tj
+72 124.027 Td
+(bility) 21.041 Tj
+65 TJm
+(.) 2.49065 Tj
+-1446 TJm
+(These) 23.7907 Tj
+-388 TJm
+(functions) 37.0808 Tj
+-387 TJm
+(are) 12.1643 Tj
+[1 0 0 1 193.913 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -193.913 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+193.913 124.027 Td
+/F134_0 9.9626 Tf
+(BZ2_bzopen) 59.7756 Tj
+[1 0 0 1 253.689 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -253.689 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+253.689 124.027 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 260.385 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -260.385 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+260.385 124.027 Td
+/F134_0 9.9626 Tf
+(BZ2_bzread) 59.7756 Tj
+[1 0 0 1 320.161 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -320.161 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+320.161 124.027 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 326.857 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -326.857 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+326.857 124.027 Td
+/F134_0 9.9626 Tf
+(BZ2_bzwrite) 65.7532 Tj
+[1 0 0 1 392.611 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -392.611 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+392.611 124.027 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 399.306 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -399.306 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+399.306 124.027 Td
+/F134_0 9.9626 Tf
+(BZ2_bzflush) 65.7532 Tj
+[1 0 0 1 465.06 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -465.06 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+465.06 124.027 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 471.756 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -471.756 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+471.756 124.027 Td
+/F134_0 9.9626 Tf
+(BZ2_bzclose) 65.7532 Tj
+[1 0 0 1 537.509 124.027] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -537.509 -124.027] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+537.509 124.027 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 72 112.072] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -112.072] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 112.072 Td
+/F134_0 9.9626 Tf
+(BZ2_bzerror) 65.7532 Tj
+[1 0 0 1 137.753 112.072] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.753 -112.072] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+140.408 112.072 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 157.449 112.072] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -157.449 -112.072] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+157.449 112.072 Td
+/F134_0 9.9626 Tf
+(BZ2_bzlibVersion) 95.641 Tj
+[1 0 0 1 253.091 112.072] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -253.091 -112.072] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+253.091 112.072 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-719 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-266 TJm
+(may) 17.1556 Tj
+-267 TJm
+(\002nd) 15.5018 Tj
+-266 TJm
+(these) 20.4731 Tj
+-267 TJm
+(functions) 37.0808 Tj
+-266 TJm
+(more) 20.4731 Tj
+-267 TJm
+(con) 14.386 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(enient) 24.3486 Tj
+-266 TJm
+(for) 11.6164 Tj
+-267 TJm
+(simple) 26.5703 Tj
+-266 TJm
+(\002le) 12.7322 Tj
+-267 TJm
+(reading) 29.8778 Tj
+72 100.117 Td
+(and) 14.386 Tj
+-270 TJm
+(wri) 13.2801 Tj
+1 TJm
+(ting,) 17.9925 Tj
+-275 TJm
+(than) 17.1556 Tj
+-269 TJm
+(those) 21.031 Tj
+-270 TJm
+(in) 7.7509 Tj
+-269 TJm
+(the) 12.1743 Tj
+-270 TJm
+(high-le) 28.224 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-269 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace.) 15.7608 Tj
+-737 TJm
+(These) 23.7907 Tj
+-270 TJm
+(functions) 37.0808 Tj
+-269 TJm
+(are) 12.1643 Tj
+-270 TJm
+(not) 12.7322 Tj
+-269 TJm
+(\(yet\)) 18.8094 Tj
+-270 TJm
+(of) 8.29885 Tj
+25 TJm
+(\002cially) 27.6761 Tj
+-269 TJm
+(part) 15.4918 Tj
+-270 TJm
+(of) 8.29885 Tj
+-269 TJm
+(the) 12.1743 Tj
+-270 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-274 TJm
+(and) 14.386 Tj
+-270 TJm
+(are) 12.1643 Tj
+72 88.1614 Td
+(minimally) 40.9662 Tj
+-291 TJm
+(documented) 48.6972 Tj
+-291 TJm
+(here.) 19.6363 Tj
+-867 TJm
+(If) 6.63509 Tj
+-291 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-291 TJm
+(break,) 24.6176 Tj
+-301 TJm
+(you) 14.9439 Tj
+-291 TJm
+(get) 12.1743 Tj
+-292 TJm
+(to) 7.7509 Tj
+-291 TJm
+(k) 4.9813 Tj
+10 TJm
+(eep) 13.8281 Tj
+-291 TJm
+(all) 9.9626 Tj
+-291 TJm
+(the) 12.1743 Tj
+-291 TJm
+(pieces.) 27.3872 Tj
+-433 TJm
+(I) 3.31755 Tj
+-291 TJm
+(hope) 19.3673 Tj
+-291 TJm
+(to) 7.7509 Tj
+-291 TJm
+(document) 39.2925 Tj
+-292 TJm
+(them) 19.9252 Tj
+-291 TJm
+(properly) 33.7533 Tj
+-291 TJm
+(when) 21.579 Tj
+72 76.2062 Td
+(time) 17.7135 Tj
+-250 TJm
+(permits.) 32.3785 Tj
+[1 0 0 1 72 74.0494] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -23.1976] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 4.3836 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.9737] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 43.0633 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -498.225 -51.071] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+541.288 51.071 Td
+/F130_0 9.9626 Tf
+(9) 4.9813 Tj
+[1 0 0 1 455.161 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5986 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -15.0366 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 13 13
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(Y) 7.193 Tj
+110 TJm
+(oshioka) 30.9936 Tj
+-250 TJm
+(also) 16.0497 Tj
+-250 TJm
+(contrib) 28.224 Tj
+20 TJm
+(uted) 17.1556 Tj
+-250 TJm
+(modi\002cations) 54.2464 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(allo) 14.9439 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(library) 26.5603 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(uilt) 13.2901 Tj
+-250 TJm
+(as) 8.29885 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(W) 9.40469 Tj
+40 TJm
+(indo) 17.7135 Tj
+25 TJm
+(ws) 11.0684 Tj
+-250 TJm
+(DLL.) 21.8579 Tj
+[1 0 0 1 72 707.88] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -698.137] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 675.504 Td
+/F122_0 20.6585 Tf
+(3.2.) 34.4584 Tj
+-278 TJm
+(Err) 29.8515 Tj
+20 TJm
+(or) 20.6585 Tj
+-278 TJm
+(handling) 86.084 Tj
+[1 0 0 1 72 670.907] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -661.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 653.805 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-214 TJm
+(library) 26.5603 Tj
+-215 TJm
+(is) 6.64505 Tj
+-214 TJm
+(designed) 35.417 Tj
+-215 TJm
+(to) 7.7509 Tj
+-214 TJm
+(reco) 17.1456 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-215 TJm
+(cleanly) 28.772 Tj
+-214 TJm
+(in) 7.7509 Tj
+-215 TJm
+(all) 9.9626 Tj
+-214 TJm
+(situations,) 40.6873 Tj
+-222 TJm
+(including) 37.6387 Tj
+-214 TJm
+(the) 12.1743 Tj
+-215 TJm
+(w) 7.193 Tj
+10 TJm
+(orst-case) 35.4071 Tj
+-214 TJm
+(situation) 34.3212 Tj
+-215 TJm
+(of) 8.29885 Tj
+-214 TJm
+(decompressing) 59.7656 Tj
+-215 TJm
+(random) 30.4357 Tj
+72 641.85 Td
+(data.) 19.0883 Tj
+-764 TJm
+(I'm) 14.386 Tj
+-274 TJm
+(not) 12.7322 Tj
+-275 TJm
+(100%) 23.2427 Tj
+-274 TJm
+(sure) 16.5977 Tj
+-274 TJm
+(that) 14.9439 Tj
+-274 TJm
+(it) 5.53921 Tj
+-274 TJm
+(can) 13.8281 Tj
+-274 TJm
+(al) 7.193 Tj
+10 TJm
+(w) 7.193 Tj
+10 TJm
+(ays) 13.2801 Tj
+-274 TJm
+(do) 9.9626 Tj
+-274 TJm
+(this,) 16.8866 Tj
+-280 TJm
+(so) 8.85675 Tj
+-274 TJm
+(you) 14.9439 Tj
+-274 TJm
+(might) 23.2527 Tj
+-274 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-274 TJm
+(to) 7.7509 Tj
+-274 TJm
+(add) 14.386 Tj
+-274 TJm
+(a) 4.42339 Tj
+-275 TJm
+(s) 3.87545 Tj
+1 TJm
+(ignal) 19.9252 Tj
+-275 TJm
+(handler) 29.8778 Tj
+-274 TJm
+(to) 7.7509 Tj
+-274 TJm
+(catch) 21.0211 Tj
+-274 TJm
+(se) 8.29885 Tj
+15 TJm
+(gmentation) 44.8317 Tj
+72 629.894 Td
+(violations) 39.3025 Tj
+-273 TJm
+(during) 26.0123 Tj
+-273 TJm
+(decompression) 59.7656 Tj
+-273 TJm
+(if) 6.08715 Tj
+-273 TJm
+(you) 14.9439 Tj
+-273 TJm
+(are) 12.1643 Tj
+-273 TJm
+(feeling) 27.6661 Tj
+-274 TJm
+(especiall) 34.8591 Tj
+1 TJm
+(y) 4.9813 Tj
+-274 TJm
+(paranoid.) 37.3498 Tj
+-758 TJm
+(I) 3.31755 Tj
+-273 TJm
+(w) 7.193 Tj
+10 TJm
+(ould) 17.7135 Tj
+-273 TJm
+(be) 9.40469 Tj
+-273 TJm
+(interested) 38.7346 Tj
+-273 TJm
+(in) 7.7509 Tj
+-274 TJm
+(hearing) 29.8778 Tj
+-273 TJm
+(more) 20.4731 Tj
+-273 TJm
+(about) 22.1369 Tj
+72 617.939 Td
+(the) 12.1743 Tj
+-250 TJm
+(rob) 13.2801 Tj
+20 TJm
+(ustness) 28.782 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(library) 26.5603 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(corrupted) 38.1767 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(data.) 19.0883 Tj
+[1 0 0 1 72 615.783] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -606.039] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 596.241 Td
+/F130_0 9.9626 Tf
+(V) 7.193 Tj
+111 TJm
+(ersion) 24.3486 Tj
+-251 TJm
+(1.0.3) 19.9252 Tj
+-251 TJm
+(more) 20.4731 Tj
+-251 TJm
+(rob) 13.2801 Tj
+20 TJm
+(ust) 11.6264 Tj
+-251 TJm
+(in) 7.7509 Tj
+-251 TJm
+(this) 14.396 Tj
+-251 TJm
+(respect) 28.2141 Tj
+-252 TJm
+(than) 17.1556 Tj
+-251 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-251 TJm
+(pre) 12.7222 Tj
+25 TJm
+(vious) 21.589 Tj
+-251 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion.) 26.8392 Tj
+-626 TJm
+(In) 8.29885 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(estig) 18.8194 Tj
+5 TJm
+(ations) 23.8007 Tj
+-251 TJm
+(with) 17.7135 Tj
+-251 TJm
+(V) 7.193 Tj
+111 TJm
+(algrind) 28.224 Tj
+-251 TJm
+(\(a) 7.74094 Tj
+-252 TJm
+(tool) 15.5018 Tj
+-251 TJm
+(for) 11.6164 Tj
+-251 TJm
+(detecting) 36.5229 Tj
+72 584.285 Td
+(problems) 37.0808 Tj
+-422 TJm
+(with) 17.7135 Tj
+-421 TJm
+(memory) 33.2053 Tj
+-422 TJm
+(management\)) 54.2264 Tj
+-421 TJm
+(indicate) 31.5416 Tj
+-422 TJm
+(that,) 17.4346 Tj
+-464 TJm
+(at) 7.193 Tj
+-422 TJm
+(least) 18.2614 Tj
+-421 TJm
+(for) 11.6164 Tj
+-422 TJm
+(the) 12.1743 Tj
+-422 TJm
+(f) 3.31755 Tj
+1 TJm
+(e) 4.42339 Tj
+25 TJm
+(w) 7.193 Tj
+-422 TJm
+(\002les) 16.6077 Tj
+-422 TJm
+(I) 3.31755 Tj
+-421 TJm
+(tested,) 25.7334 Tj
+-464 TJm
+(all) 9.9626 Tj
+-422 TJm
+(single-bit) 37.6387 Tj
+-422 TJm
+(errors) 23.2328 Tj
+-421 TJm
+(in) 7.7509 Tj
+-422 TJm
+(the) 12.1743 Tj
+72 572.33 Td
+(decompressed) 56.4381 Tj
+-342 TJm
+(data) 16.5977 Tj
+-341 TJm
+(are) 12.1643 Tj
+-342 TJm
+(caught) 26.5603 Tj
+-342 TJm
+(properly) 33.7533 Tj
+65 TJm
+(,) 2.49065 Tj
+-365 TJm
+(with) 17.7135 Tj
+-341 TJm
+(no) 9.9626 Tj
+-342 TJm
+(se) 8.29885 Tj
+15 TJm
+(gmentation) 44.8317 Tj
+-342 TJm
+(f) 3.31755 Tj
+10 TJm
+(aults,) 21.31 Tj
+-365 TJm
+(no) 9.9626 Tj
+-341 TJm
+(uses) 17.1556 Tj
+-342 TJm
+(of) 8.29885 Tj
+-342 TJm
+(uninitialised) 49.2651 Tj
+-342 TJm
+(data,) 19.0883 Tj
+-364 TJm
+(no) 9.9626 Tj
+-342 TJm
+(out) 12.7322 Tj
+-342 TJm
+(of) 8.29885 Tj
+-342 TJm
+(range) 22.1269 Tj
+72 560.375 Td
+(reads) 21.0211 Tj
+-261 TJm
+(or) 8.29885 Tj
+-260 TJm
+(writes,) 26.8392 Tj
+-263 TJm
+(and) 14.386 Tj
+-261 TJm
+(no) 9.9626 Tj
+-261 TJm
+(in\002nit) 23.8106 Tj
+1 TJm
+(e) 4.42339 Tj
+-261 TJm
+(looping) 30.4457 Tj
+-261 TJm
+(in) 7.7509 Tj
+-260 TJm
+(the) 12.1743 Tj
+-261 TJm
+(decompressor) 55.3323 Tj
+55 TJm
+(.) 2.49065 Tj
+-342 TJm
+(So) 10.5205 Tj
+-260 TJm
+(it') 8.85675 Tj
+55 TJm
+(s) 3.87545 Tj
+-261 TJm
+(certainly) 34.8591 Tj
+-260 TJm
+(pretty) 23.2427 Tj
+-261 TJm
+(rob) 13.2801 Tj
+20 TJm
+(ust,) 14.117 Tj
+-263 TJm
+(although) 34.8691 Tj
+-261 TJm
+(I) 3.31755 Tj
+-260 TJm
+(w) 7.193 Tj
+10 TJm
+(ouldn') 26.0123 Tj
+18 TJm
+(t) 2.7696 Tj
+-261 TJm
+(claim) 22.1369 Tj
+72 548.42 Td
+(it) 5.53921 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(totally) 25.4644 Tj
+-250 TJm
+(bombproof.) 46.7644 Tj
+[1 0 0 1 72 546.263] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -536.519] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 526.721 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-282 TJm
+(\002le) 12.7322 Tj
+[1 0 0 1 105.84 526.721] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -105.84 -526.721] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+105.84 526.721 Td
+/F134_0 9.9626 Tf
+(bzlib.h) 41.8429 Tj
+[1 0 0 1 147.683 526.721] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -147.683 -526.721] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+150.491 526.721 Td
+/F130_0 9.9626 Tf
+(contains) 33.2053 Tj
+-282 TJm
+(all) 9.9626 Tj
+-282 TJm
+(de\002nitions) 42.0721 Tj
+-282 TJm
+(nee) 13.8281 Tj
+1 TJm
+(ded) 14.386 Tj
+-282 TJm
+(to) 7.7509 Tj
+-282 TJm
+(use) 13.2801 Tj
+-282 TJm
+(the) 12.1743 Tj
+-282 TJm
+(library) 26.5603 Tj
+65 TJm
+(.) 2.49065 Tj
+-811 TJm
+(In) 8.29885 Tj
+-282 TJm
+(particular) 38.1767 Tj
+40 TJm
+(,) 2.49065 Tj
+-290 TJm
+(you) 14.9439 Tj
+-282 TJm
+(should) 26.5703 Tj
+-281 TJm
+(de\002nitely) 37.6387 Tj
+-282 TJm
+(not) 12.7322 Tj
+-282 TJm
+(include) 29.3299 Tj
+[1 0 0 1 72 514.766] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -514.766] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 514.766 Td
+/F134_0 9.9626 Tf
+(bzlib_private.h) 89.6634 Tj
+[1 0 0 1 161.664 514.766] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.664 -514.766] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+161.664 514.766 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 513.232] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -503.488] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 493.067 Td
+/F130_0 9.9626 Tf
+(In) 8.29885 Tj
+[1 0 0 1 82.8075 493.067] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -82.8075 -493.067] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+82.8075 493.067 Td
+/F134_0 9.9626 Tf
+(bzlib.h) 41.8429 Tj
+[1 0 0 1 124.651 493.067] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -124.651 -493.067] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+124.651 493.067 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-252 TJm
+(the) 12.1743 Tj
+-252 TJm
+(v) 4.9813 Tj
+25 TJm
+(arious) 24.3486 Tj
+-252 TJm
+(return) 23.7907 Tj
+-252 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues) 20.4731 Tj
+-251 TJm
+(are) 12.1643 Tj
+-252 TJm
+(de\002ned.) 31.8205 Tj
+-631 TJm
+(The) 15.4918 Tj
+-252 TJm
+(follo) 18.8194 Tj
+25 TJm
+(wing) 19.9252 Tj
+-252 TJm
+(list) 12.1843 Tj
+-251 TJm
+(is) 6.64505 Tj
+-252 TJm
+(not) 12.7322 Tj
+-252 TJm
+(intended) 34.3112 Tj
+-252 TJm
+(as) 8.29885 Tj
+-252 TJm
+(an) 9.40469 Tj
+-251 TJm
+(e) 4.42339 Tj
+15 TJm
+(xhausti) 28.782 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-252 TJm
+(description) 44.2738 Tj
+-252 TJm
+(of) 8.29885 Tj
+72 481.112 Td
+(the) 12.1743 Tj
+-236 TJm
+(circumstances) 56.4381 Tj
+-236 TJm
+(in) 7.7509 Tj
+-237 TJm
+(which) 24.3486 Tj
+-236 TJm
+(a) 4.42339 Tj
+-236 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-236 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+-236 TJm
+(may) 17.1556 Tj
+-237 TJm
+(be) 9.40469 Tj
+-236 TJm
+(returned) 33.1954 Tj
+-236 TJm
+(--) 6.63509 Tj
+-236 TJm
+(those) 21.031 Tj
+-236 TJm
+(descriptions) 48.1492 Tj
+-236 TJm
+(are) 12.1643 Tj
+-237 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-236 TJm
+(later) 17.7035 Tj
+55 TJm
+(.) 2.49065 Tj
+-305 TJm
+(Rather) 26.5603 Tj
+40 TJm
+(,) 2.49065 Tj
+-239 TJm
+(it) 5.53921 Tj
+-236 TJm
+(is) 6.64505 Tj
+-237 TJm
+(intended) 34.3112 Tj
+-236 TJm
+(to) 7.7509 Tj
+72 469.157 Td
+(con) 14.386 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+15 TJm
+(y) 4.9813 Tj
+-266 TJm
+(the) 12.1743 Tj
+-265 TJm
+(rough) 23.2427 Tj
+-266 TJm
+(meaning) 34.3112 Tj
+-265 TJm
+(of) 8.29885 Tj
+-266 TJm
+(each) 18.2515 Tj
+-266 TJm
+(return) 23.7907 Tj
+-265 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue.) 19.0883 Tj
+-714 TJm
+(The) 15.4918 Tj
+-265 TJm
+(\002rst) 15.5018 Tj
+-266 TJm
+(\002) 5.53921 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-265 TJm
+(actions) 28.224 Tj
+-266 TJm
+(are) 12.1643 Tj
+-266 TJm
+(normal) 28.224 Tj
+-265 TJm
+(and) 14.386 Tj
+-266 TJm
+(not) 12.7322 Tj
+-265 TJm
+(intended) 34.3112 Tj
+-266 TJm
+(to) 7.7509 Tj
+-266 TJm
+(denote) 26.5603 Tj
+-265 TJm
+(an) 9.40469 Tj
+-266 TJm
+(error) 19.3573 Tj
+72 457.202 Td
+(situation.) 36.8118 Tj
+[1 0 0 1 72 457.102] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7435] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -437.615] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 425.76 Td
+/F134_0 9.9626 Tf
+(BZ_OK) 29.8878 Tj
+[1 0 0 1 101.888 425.76] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -32.3786 -1.3101] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -424.449] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 413.804 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-250 TJm
+(requested) 38.1767 Tj
+-250 TJm
+(action) 24.3486 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-250 TJm
+(completed) 41.5042 Tj
+-250 TJm
+(successfully) 48.6972 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 411.648] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.766] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -398.138] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 388.34 Td
+/F134_0 9.9626 Tf
+(BZ_RUN_OK,) 59.7756 Tj
+-600 TJm
+(BZ_FLUSH_OK,) 71.7307 Tj
+-600 TJm
+(BZ_FINISH_OK) 71.7307 Tj
+[1 0 0 1 287.193 388.34] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -217.684 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -387.03] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 376.384 Td
+/F130_0 9.9626 Tf
+(In) 8.29885 Tj
+[1 0 0 1 118.79 376.384] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -118.79 -376.384] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+118.79 376.384 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 202.476 376.384] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -202.476 -376.384] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+202.476 376.384 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(requested) 38.1767 Tj
+-250 TJm
+(\003ush/\002nish/nothing-special) 108.493 Tj
+-250 TJm
+(action) 24.3486 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-250 TJm
+(completed) 41.5042 Tj
+-250 TJm
+(successfully) 48.6972 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 374.228] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.7659] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -360.718] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 350.92 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 149.709 350.92] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -80.1993 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -349.61] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 338.965 Td
+/F130_0 9.9626 Tf
+(Compression) 52.5826 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-250 TJm
+(completed,) 43.9948 Tj
+-250 TJm
+(or) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(logical) 27.1182 Tj
+-250 TJm
+(stream) 26.5603 Tj
+-250 TJm
+(end) 14.386 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-250 TJm
+(detected) 33.1954 Tj
+-250 TJm
+(during) 26.0123 Tj
+-250 TJm
+(decompression.) 62.2563 Tj
+[1 0 0 1 72 336.808] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.7659] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -313.555] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 303.756 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-250 TJm
+(follo) 18.8194 Tj
+25 TJm
+(wing) 19.9252 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues) 20.4731 Tj
+-250 TJm
+(indicate) 31.5416 Tj
+-250 TJm
+(an) 9.40469 Tj
+-250 TJm
+(error) 19.3573 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(some) 21.031 Tj
+-250 TJm
+(kind.) 20.2042 Tj
+[1 0 0 1 72 301.6] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -282.112] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 272.314 Td
+/F134_0 9.9626 Tf
+(BZ_CONFIG_ERROR) 89.6634 Tj
+[1 0 0 1 161.664 272.314] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -92.1544 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -271.004] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 260.359 Td
+/F130_0 9.9626 Tf
+(Indicates) 35.965 Tj
+-386 TJm
+(that) 14.9439 Tj
+-385 TJm
+(the) 12.1743 Tj
+-386 TJm
+(library) 26.5603 Tj
+-386 TJm
+(has) 13.2801 Tj
+-386 TJm
+(been) 18.8094 Tj
+-385 TJm
+(improperly) 44.2738 Tj
+-386 TJm
+(compiled) 37.0808 Tj
+-386 TJm
+(on) 9.9626 Tj
+-386 TJm
+(your) 18.2614 Tj
+-385 TJm
+(platform) 34.3112 Tj
+-386 TJm
+(--) 6.63509 Tj
+-386 TJm
+(a) 4.42339 Tj
+-386 TJm
+(major) 23.2427 Tj
+-385 TJm
+(con\002guration) 53.1305 Tj
+-386 TJm
+(error) 19.3573 Tj
+55 TJm
+(.) 2.49065 Tj
+108 248.404 Td
+(Speci\002cally) 47.0434 Tj
+65 TJm
+(,) 2.49065 Tj
+-481 TJm
+(it) 5.53921 Tj
+-435 TJm
+(means) 25.4544 Tj
+-435 TJm
+(that) 14.9439 Tj
+[1 0 0 1 220.614 248.404] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -220.614 -248.404] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+220.614 248.404 Td
+/F134_0 9.9626 Tf
+(sizeof\(char\)) 71.7307 Tj
+[1 0 0 1 292.345 248.404] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -292.345 -248.404] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+292.345 248.404 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 299.628 248.404] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -299.628 -248.404] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+299.628 248.404 Td
+/F134_0 9.9626 Tf
+(sizeof\(short\)) 77.7083 Tj
+[1 0 0 1 377.337 248.404] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -377.337 -248.404] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+381.669 248.404 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 400.388 248.404] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -400.388 -248.404] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+400.388 248.404 Td
+/F134_0 9.9626 Tf
+(sizeof\(int\)) 65.7532 Tj
+[1 0 0 1 466.141 248.404] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -466.141 -248.404] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+470.474 248.404 Td
+/F130_0 9.9626 Tf
+(are) 12.1643 Tj
+-435 TJm
+(not) 12.7322 Tj
+-435 TJm
+(1,) 7.47195 Tj
+-481 TJm
+(2) 4.9813 Tj
+-435 TJm
+(and) 14.386 Tj
+108 236.449 Td
+(4) 4.9813 Tj
+-389 TJm
+(respecti) 30.9837 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ely) 12.1743 Tj
+65 TJm
+(,) 2.49065 Tj
+-424 TJm
+(as) 8.29885 Tj
+-390 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-389 TJm
+(should) 26.5703 Tj
+-389 TJm
+(be.) 11.8953 Tj
+-1456 TJm
+(Note) 19.3673 Tj
+-389 TJm
+(that) 14.9439 Tj
+-389 TJm
+(the) 12.1743 Tj
+-389 TJm
+(library) 26.5603 Tj
+-390 TJm
+(should) 26.5703 Tj
+-389 TJm
+(still) 14.9539 Tj
+-389 TJm
+(w) 7.193 Tj
+10 TJm
+(ork) 13.2801 Tj
+-389 TJm
+(properly) 33.7533 Tj
+-390 TJm
+(on) 9.9626 Tj
+-389 TJm
+(64-bit) 23.8007 Tj
+-389 TJm
+(platforms) 38.1866 Tj
+108 224.493 Td
+(which) 24.3486 Tj
+-292 TJm
+(follo) 18.8194 Tj
+25 TJm
+(w) 7.193 Tj
+-292 TJm
+(the) 12.1743 Tj
+-292 TJm
+(LP64) 21.589 Tj
+-292 TJm
+(programming) 54.2364 Tj
+-293 TJm
+(model) 24.9065 Tj
+-292 TJm
+(--) 6.63509 Tj
+-292 TJm
+(that) 14.9439 Tj
+-292 TJm
+(is,) 9.1357 Tj
+-303 TJm
+(where) 24.3386 Tj
+[1 0 0 1 355.279 224.493] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -355.279 -224.493] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+355.279 224.493 Td
+/F134_0 9.9626 Tf
+(sizeof\(long\)) 71.7307 Tj
+[1 0 0 1 427.01 224.493] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -427.01 -224.493] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+429.92 224.493 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 447.217 224.493] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -447.217 -224.493] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+447.217 224.493 Td
+/F134_0 9.9626 Tf
+(sizeof\(void) 65.7532 Tj
+512.97 222.75 Td
+(*) 5.97756 Tj
+518.948 224.493 Td
+(\)) 5.97756 Tj
+[1 0 0 1 524.925 224.493] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -524.925 -224.493] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+527.836 224.493 Td
+/F130_0 9.9626 Tf
+(are) 12.1643 Tj
+108 212.538 Td
+(8.) 7.47195 Tj
+-620 TJm
+(Under) 24.8965 Tj
+-250 TJm
+(LP64,) 24.0796 Tj
+[1 0 0 1 175.606 212.538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -175.606 -212.538] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+175.606 212.538 Td
+/F134_0 9.9626 Tf
+(sizeof\(int\)) 65.7532 Tj
+[1 0 0 1 241.36 212.538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -241.36 -212.538] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+243.85 212.538 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(still) 14.9539 Tj
+-250 TJm
+(4,) 7.47195 Tj
+-250 TJm
+(so) 8.85675 Tj
+[1 0 0 1 291.74 212.538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -291.74 -212.538] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+291.74 212.538 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 339.56 212.538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -339.56 -212.538] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+339.56 212.538 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(doesn') 26.5603 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(the) 12.1743 Tj
+[1 0 0 1 433.458 212.538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -433.458 -212.538] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+433.458 212.538 Td
+/F134_0 9.9626 Tf
+(long) 23.9102 Tj
+[1 0 0 1 457.368 212.538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -457.368 -212.538] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+459.859 212.538 Td
+/F130_0 9.9626 Tf
+(type,) 19.6462 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(OK.) 16.8766 Tj
+[1 0 0 1 72 210.381] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.7659] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -196.872] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 187.074 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+[1 0 0 1 173.619 187.074] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -104.11 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -185.764] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 175.118 Td
+/F130_0 9.9626 Tf
+(When) 23.7907 Tj
+-291 TJm
+(using) 21.589 Tj
+-290 TJm
+(the) 12.1743 Tj
+-291 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-300 TJm
+(it) 5.53921 Tj
+-291 TJm
+(is) 6.64505 Tj
+-290 TJm
+(important) 38.7446 Tj
+-291 TJm
+(to) 7.7509 Tj
+-290 TJm
+(call) 14.386 Tj
+-291 TJm
+(the) 12.1743 Tj
+-290 TJm
+(functions) 37.0808 Tj
+-291 TJm
+(in) 7.7509 Tj
+-290 TJm
+(the) 12.1743 Tj
+-291 TJm
+(correct) 27.6562 Tj
+-290 TJm
+(sequence) 36.5129 Tj
+-291 TJm
+(and) 14.386 Tj
+-290 TJm
+(with) 17.7135 Tj
+-291 TJm
+(data) 16.5977 Tj
+-290 TJm
+(structures) 38.7346 Tj
+108 163.163 Td
+(\(b) 8.29885 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fers) 14.9339 Tj
+-206 TJm
+(etc\)) 14.9339 Tj
+-205 TJm
+(in) 7.7509 Tj
+-206 TJm
+(the) 12.1743 Tj
+-205 TJm
+(correct) 27.6562 Tj
+-206 TJm
+(states.) 24.6275 Tj
+[1 0 0 1 239.409 163.163] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -239.409 -163.163] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+239.409 163.163 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 287.23 163.163] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -287.23 -163.163] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+289.278 163.163 Td
+/F130_0 9.9626 Tf
+(checks) 27.1082 Tj
+-206 TJm
+(as) 8.29885 Tj
+-205 TJm
+(much) 22.1369 Tj
+-206 TJm
+(as) 8.29885 Tj
+-205 TJm
+(it) 5.53921 Tj
+-206 TJm
+(can) 13.8281 Tj
+-206 TJm
+(to) 7.7509 Tj
+-205 TJm
+(ensure) 26.0024 Tj
+-206 TJm
+(this) 14.396 Tj
+-206 TJm
+(is) 6.64505 Tj
+-205 TJm
+(happening,) 43.9948 Tj
+-215 TJm
+(and) 14.386 Tj
+-205 TJm
+(returns) 27.6661 Tj
+[1 0 0 1 108 151.208] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -108 -151.208] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 151.208 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+[1 0 0 1 209.619 151.208] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -209.619 -151.208] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+213.27 151.208 Td
+/F130_0 9.9626 Tf
+(if) 6.08715 Tj
+-367 TJm
+(not.) 15.2229 Tj
+-659 TJm
+(Code) 21.031 Tj
+-367 TJm
+(which) 24.3486 Tj
+-367 TJm
+(complies) 35.9749 Tj
+-366 TJm
+(precisely) 35.965 Tj
+-367 TJm
+(with) 17.7135 Tj
+-366 TJm
+(the) 12.1743 Tj
+-367 TJm
+(function) 33.2053 Tj
+-366 TJm
+(semantics,) 41.7831 Tj
+-396 TJm
+(as) 8.29885 Tj
+-367 TJm
+(detailed) 31.5416 Tj
+108 139.253 Td
+(belo) 17.1556 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(should) 26.5703 Tj
+-250 TJm
+(ne) 9.40469 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-250 TJm
+(recei) 19.3573 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue;) 19.3673 Tj
+-250 TJm
+(such) 18.2614 Tj
+-250 TJm
+(an) 9.40469 Tj
+-250 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ent) 12.1743 Tj
+-250 TJm
+(denotes) 30.4357 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(uggy) 19.9252 Tj
+-250 TJm
+(code) 18.8094 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(should) 26.5703 Tj
+-250 TJm
+(in) 7.7509 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(estig) 18.8194 Tj
+5 TJm
+(ate.) 14.107 Tj
+[1 0 0 1 72 137.096] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.7659] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7436] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -123.587] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 113.788 Td
+/F134_0 9.9626 Tf
+(BZ_PARAM_ERROR) 83.6858 Tj
+[1 0 0 1 155.686 113.788] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.1768 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -112.478] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 101.833 Td
+/F130_0 9.9626 Tf
+(Returned) 36.5229 Tj
+-434 TJm
+(when) 21.579 Tj
+-434 TJm
+(a) 4.42339 Tj
+-434 TJm
+(parameter) 39.8305 Tj
+-434 TJm
+(to) 7.7509 Tj
+-434 TJm
+(a) 4.42339 Tj
+-433 TJm
+(function) 33.2053 Tj
+-434 TJm
+(call) 14.386 Tj
+-434 TJm
+(is) 6.64505 Tj
+-434 TJm
+(out) 12.7322 Tj
+-434 TJm
+(of) 8.29885 Tj
+-434 TJm
+(range) 22.1269 Tj
+-434 TJm
+(or) 8.29885 Tj
+-434 TJm
+(otherwise) 38.7346 Tj
+-434 TJm
+(manifestly) 42.0621 Tj
+-434 TJm
+(incorrect.) 37.8977 Tj
+-1723 TJm
+(As) 11.0684 Tj
+108 89.8778 Td
+(with) 17.7135 Tj
+[1 0 0 1 131.644 89.8778] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -131.644 -89.8778] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+131.644 89.8778 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+[1 0 0 1 233.263 89.8778] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -233.263 -89.8778] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+233.263 89.8778 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-595 TJm
+(this) 14.396 Tj
+-596 TJm
+(denotes) 30.4357 Tj
+-595 TJm
+(a) 4.42339 Tj
+-595 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug) 9.9626 Tj
+-596 TJm
+(in) 7.7509 Tj
+-595 TJm
+(the) 12.1743 Tj
+-595 TJm
+(client) 22.1369 Tj
+-595 TJm
+(code.) 21.3 Tj
+-2692 TJm
+(The) 15.4918 Tj
+-596 TJm
+(distinction) 42.0721 Tj
+-595 TJm
+(between) 33.1954 Tj
+[1 0 0 1 108 77.9227] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -108 -77.9227] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 77.9227 Td
+/F134_0 9.9626 Tf
+(BZ_PARAM_ERROR) 83.6858 Tj
+[1 0 0 1 191.686 77.9227] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -191.686 -77.9227] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+194.177 77.9227 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 211.053 77.9227] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -211.053 -77.9227] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+211.053 77.9227 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+[1 0 0 1 312.672 77.9227] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -312.672 -77.9227] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+315.163 77.9227 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(bit) 10.5205 Tj
+-250 TJm
+(hazy) 18.8094 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(still) 14.9539 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(orth) 16.0497 Tj
+-250 TJm
+(making.) 32.3785 Tj
+[1 0 0 1 72 75.7659] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.7659] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -21.1482] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(10) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 14 14
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F134_0 9.9626 Tf
+(BZ_MEM_ERROR) 71.7307 Tj
+[1 0 0 1 143.731 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -74.2217 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -708.727] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 698.082 Td
+/F130_0 9.9626 Tf
+(Returned) 36.5229 Tj
+-228 TJm
+(when) 21.579 Tj
+-227 TJm
+(a) 4.42339 Tj
+-228 TJm
+(request) 28.772 Tj
+-227 TJm
+(to) 7.7509 Tj
+-228 TJm
+(allocate) 30.9837 Tj
+-228 TJm
+(memory) 33.2053 Tj
+-227 TJm
+(f) 3.31755 Tj
+10 TJm
+(ailed.) 21.8579 Tj
+-605 TJm
+(Note) 19.3673 Tj
+-228 TJm
+(that) 14.9439 Tj
+-228 TJm
+(the) 12.1743 Tj
+-227 TJm
+(quantity) 32.6574 Tj
+-228 TJm
+(of) 8.29885 Tj
+-227 TJm
+(memory) 33.2053 Tj
+-228 TJm
+(needed) 28.2141 Tj
+-228 TJm
+(to) 7.7509 Tj
+-227 TJm
+(decompress) 47.0334 Tj
+108 686.127 Td
+(a) 4.42339 Tj
+-351 TJm
+(stream) 26.5603 Tj
+-352 TJm
+(cannot) 26.5603 Tj
+-351 TJm
+(be) 9.40469 Tj
+-352 TJm
+(determined) 44.8217 Tj
+-351 TJm
+(until) 18.2714 Tj
+-352 TJm
+(the) 12.1743 Tj
+-351 TJm
+(stream') 29.8778 Tj
+55 TJm
+(s) 3.87545 Tj
+-351 TJm
+(header) 26.5503 Tj
+-352 TJm
+(has) 13.2801 Tj
+-351 TJm
+(been) 18.8094 Tj
+-352 TJm
+(read.) 19.6363 Tj
+-1228 TJm
+(So) 10.5205 Tj
+[1 0 0 1 426.471 686.127] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -426.471 -686.127] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+426.471 686.127 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 522.113 686.127] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -522.113 -686.127] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+525.614 686.127 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 108 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -108 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 674.172 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 167.776 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -167.776 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+172.13 674.172 Td
+/F130_0 9.9626 Tf
+(may) 17.1556 Tj
+-437 TJm
+(return) 23.7907 Tj
+[1 0 0 1 221.784 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -221.784 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+221.784 674.172 Td
+/F134_0 9.9626 Tf
+(BZ_MEM_ERROR) 71.7307 Tj
+[1 0 0 1 293.515 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -293.515 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+297.867 674.172 Td
+/F130_0 9.9626 Tf
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-437 TJm
+(though) 27.6761 Tj
+-437 TJm
+(some) 21.031 Tj
+-437 TJm
+(of) 8.29885 Tj
+-437 TJm
+(the) 12.1743 Tj
+-437 TJm
+(compressed) 47.0334 Tj
+-437 TJm
+(data) 16.5977 Tj
+-437 TJm
+(has) 13.2801 Tj
+-437 TJm
+(been) 18.8094 Tj
+-437 TJm
+(read.) 19.6363 Tj
+108 662.217 Td
+(The) 15.4918 Tj
+-479 TJm
+(same) 20.4731 Tj
+-478 TJm
+(is) 6.64505 Tj
+-479 TJm
+(not) 12.7322 Tj
+-478 TJm
+(true) 15.4918 Tj
+-479 TJm
+(for) 11.6164 Tj
+-479 TJm
+(compression;) 53.1305 Tj
+-593 TJm
+(once) 18.8094 Tj
+[1 0 0 1 301.675 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -301.675 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+301.675 662.217 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 409.271 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -409.271 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+414.04 662.217 Td
+/F130_0 9.9626 Tf
+(or) 8.29885 Tj
+[1 0 0 1 427.107 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -427.107 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+427.107 662.217 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteOpen) 89.6634 Tj
+[1 0 0 1 516.771 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -516.771 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+521.539 662.217 Td
+/F130_0 9.9626 Tf
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+108 650.262 Td
+(successfully) 48.6972 Tj
+-250 TJm
+(completed,) 43.9948 Tj
+[1 0 0 1 205.672 650.261] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -205.672 -650.261] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+205.672 650.261 Td
+/F134_0 9.9626 Tf
+(BZ_MEM_ERROR) 71.7307 Tj
+[1 0 0 1 277.403 650.261] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -277.403 -650.261] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+279.894 650.261 Td
+/F130_0 9.9626 Tf
+(cannot) 26.5603 Tj
+-250 TJm
+(occur) 22.1269 Tj
+55 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 648.105] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -634.157] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 624.359 Td
+/F134_0 9.9626 Tf
+(BZ_DATA_ERROR) 77.7083 Tj
+[1 0 0 1 149.709 624.359] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -80.1993 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -623.049] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 612.404 Td
+/F130_0 9.9626 Tf
+(Returned) 36.5229 Tj
+-266 TJm
+(when) 21.579 Tj
+-265 TJm
+(a) 4.42339 Tj
+-266 TJm
+(data) 16.5977 Tj
+-265 TJm
+(inte) 14.9439 Tj
+15 TJm
+(grity) 18.8194 Tj
+-266 TJm
+(error) 19.3573 Tj
+-266 TJm
+(is) 6.64505 Tj
+-265 TJm
+(detected) 33.1954 Tj
+-266 TJm
+(during) 26.0123 Tj
+-265 TJm
+(decompression.) 62.2563 Tj
+-714 TJm
+(Most) 20.4831 Tj
+-266 TJm
+(importantl) 41.5142 Tj
+1 TJm
+(y) 4.9813 Tj
+64 TJm
+(,) 2.49065 Tj
+-269 TJm
+(this) 14.396 Tj
+-266 TJm
+(means) 25.4544 Tj
+-265 TJm
+(when) 21.579 Tj
+108 600.448 Td
+(stored) 24.3486 Tj
+-222 TJm
+(and) 14.386 Tj
+-223 TJm
+(computed) 39.2925 Tj
+-222 TJm
+(CRCs) 23.8106 Tj
+-222 TJm
+(for) 11.6164 Tj
+-222 TJm
+(the) 12.1743 Tj
+-223 TJm
+(data) 16.5977 Tj
+-222 TJm
+(do) 9.9626 Tj
+-222 TJm
+(not) 12.7322 Tj
+-222 TJm
+(match.) 26.8392 Tj
+-602 TJm
+(This) 17.7135 Tj
+-222 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+-222 TJm
+(is) 6.64505 Tj
+-223 TJm
+(also) 16.0497 Tj
+-222 TJm
+(returned) 33.1954 Tj
+-222 TJm
+(upon) 19.9252 Tj
+-222 TJm
+(detection) 36.5229 Tj
+-223 TJm
+(of) 8.29885 Tj
+-222 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-222 TJm
+(other) 20.4731 Tj
+108 588.493 Td
+(anomaly) 34.3112 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(data.) 19.0883 Tj
+[1 0 0 1 72 586.336] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -572.389] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 562.59 Td
+/F134_0 9.9626 Tf
+(BZ_DATA_ERROR_MAGIC) 113.574 Tj
+[1 0 0 1 185.574 562.59] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -116.065 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -561.28] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 550.635 Td
+/F130_0 9.9626 Tf
+(As) 11.0684 Tj
+-306 TJm
+(a) 4.42339 Tj
+-306 TJm
+(special) 27.6661 Tj
+-306 TJm
+(case) 17.1456 Tj
+-307 TJm
+(of) 8.29885 Tj
+[1 0 0 1 191.852 550.635] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -191.852 -550.635] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+191.852 550.635 Td
+/F134_0 9.9626 Tf
+(BZ_DATA_ERROR) 77.7083 Tj
+[1 0 0 1 269.561 550.635] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -269.561 -550.635] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+269.561 550.635 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-306 TJm
+(it) 5.53921 Tj
+-306 TJm
+(is) 6.64505 Tj
+-306 TJm
+(sometimes) 42.62 Tj
+-307 TJm
+(usef) 16.5977 Tj
+1 TJm
+(ul) 7.7509 Tj
+-307 TJm
+(to) 7.7509 Tj
+-306 TJm
+(kno) 14.9439 Tj
+25 TJm
+(w) 7.193 Tj
+-306 TJm
+(when) 21.579 Tj
+-306 TJm
+(the) 12.1743 Tj
+-306 TJm
+(compressed) 47.0334 Tj
+-306 TJm
+(stream) 26.5603 Tj
+-306 TJm
+(does) 18.2614 Tj
+108 538.68 Td
+(not) 12.7322 Tj
+-250 TJm
+(start) 17.1556 Tj
+-250 TJm
+(with) 17.7135 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(correct) 27.6562 Tj
+-250 TJm
+(magic) 24.3486 Tj
+-250 TJm
+(bytes) 21.031 Tj
+-250 TJm
+(\() 3.31755 Tj
+[1 0 0 1 261.562 538.68] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -261.562 -538.68] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+261.562 538.68 Td
+/F134_0 9.9626 Tf
+('B') 17.9327 Tj
+-600 TJm
+('Z') 17.9327 Tj
+-600 TJm
+('h') 17.9327 Tj
+[1 0 0 1 327.316 538.68] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -327.316 -538.68] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+327.316 538.68 Td
+/F130_0 9.9626 Tf
+(\).) 5.8082 Tj
+[1 0 0 1 72 536.523] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -522.576] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 512.777 Td
+/F134_0 9.9626 Tf
+(BZ_IO_ERROR) 65.7532 Tj
+[1 0 0 1 137.753 512.777] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -68.2441 -1.3101] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -511.467] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 500.822 Td
+/F130_0 9.9626 Tf
+(Returned) 36.5229 Tj
+-233 TJm
+(by) 9.9626 Tj
+[1 0 0 1 159.123 500.822] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -159.123 -500.822] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+159.123 500.822 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 218.899 500.822] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -218.899 -500.822] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+221.218 500.822 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 237.923 500.822] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -237.923 -500.822] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+237.923 500.822 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWrite) 65.7532 Tj
+[1 0 0 1 303.676 500.822] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -303.676 -500.822] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+305.995 500.822 Td
+/F130_0 9.9626 Tf
+(when) 21.579 Tj
+-233 TJm
+(there) 19.9152 Tj
+-232 TJm
+(is) 6.64505 Tj
+-233 TJm
+(an) 9.40469 Tj
+-233 TJm
+(error) 19.3573 Tj
+-233 TJm
+(reading) 29.8778 Tj
+-232 TJm
+(or) 8.29885 Tj
+-233 TJm
+(writing) 28.782 Tj
+-233 TJm
+(in) 7.7509 Tj
+-233 TJm
+(the) 12.1743 Tj
+-232 TJm
+(compressed) 47.0334 Tj
+108 488.867 Td
+(\002le,) 15.2229 Tj
+-384 TJm
+(and) 14.386 Tj
+-357 TJm
+(by) 9.9626 Tj
+[1 0 0 1 158.511 488.867] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -158.511 -488.867] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+158.511 488.867 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadOpen) 83.6858 Tj
+[1 0 0 1 242.197 488.867] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -242.197 -488.867] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+245.755 488.867 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 263.698 488.867] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -263.698 -488.867] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+263.698 488.867 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteOpen) 89.6634 Tj
+[1 0 0 1 353.362 488.867] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -353.362 -488.867] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+356.92 488.867 Td
+/F130_0 9.9626 Tf
+(for) 11.6164 Tj
+-357 TJm
+(attempts) 33.7633 Tj
+-357 TJm
+(to) 7.7509 Tj
+-357 TJm
+(use) 13.2801 Tj
+-357 TJm
+(a) 4.42339 Tj
+-357 TJm
+(\002le) 12.7322 Tj
+-357 TJm
+(for) 11.6164 Tj
+-358 TJm
+(which) 24.3486 Tj
+-357 TJm
+(the) 12.1743 Tj
+-357 TJm
+(error) 19.3573 Tj
+108 476.912 Td
+(indicator) 35.417 Tj
+-260 TJm
+(\(viz,) 17.9825 Tj
+[1 0 0 1 166.603 476.912] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -166.603 -476.912] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+166.603 476.912 Td
+/F134_0 9.9626 Tf
+(ferror\(f\)) 53.798 Tj
+[1 0 0 1 220.401 476.912] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -220.401 -476.912] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+220.401 476.912 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-260 TJm
+(is) 6.64505 Tj
+-260 TJm
+(set.) 13.5591 Tj
+-679 TJm
+(On) 12.1743 Tj
+-260 TJm
+(receipt) 27.1082 Tj
+-260 TJm
+(of) 8.29885 Tj
+[1 0 0 1 311.223 476.912] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -311.223 -476.912] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+311.223 476.912 Td
+/F134_0 9.9626 Tf
+(BZ_IO_ERROR) 65.7532 Tj
+[1 0 0 1 376.976 476.912] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -376.976 -476.912] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+376.976 476.912 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-260 TJm
+(the) 12.1743 Tj
+-260 TJm
+(caller) 22.1269 Tj
+-260 TJm
+(should) 26.5703 Tj
+-260 TJm
+(consult) 28.782 Tj
+[1 0 0 1 482.068 476.912] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -482.068 -476.912] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+482.068 476.912 Td
+/F134_0 9.9626 Tf
+(errno) 29.8878 Tj
+[1 0 0 1 511.956 476.912] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.956 -476.912] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+514.546 476.912 Td
+/F130_0 9.9626 Tf
+(and/or) 25.4544 Tj
+[1 0 0 1 108 464.957] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -108 -464.957] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 464.957 Td
+/F134_0 9.9626 Tf
+(perror) 35.8654 Tj
+[1 0 0 1 143.865 464.957] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.865 -464.957] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+146.356 464.957 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(acquire) 29.3199 Tj
+-250 TJm
+(operating-system) 68.6224 Tj
+-250 TJm
+(speci\002c) 30.4357 Tj
+-250 TJm
+(information) 47.0434 Tj
+-250 TJm
+(about) 22.1369 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(problem.) 35.696 Tj
+[1 0 0 1 72 462.8] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.9849] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -448.852] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 439.054 Td
+/F134_0 9.9626 Tf
+(BZ_UNEXPECTED_EOF) 101.619 Tj
+[1 0 0 1 173.619 439.054] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -104.11 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -437.744] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 427.099 Td
+/F130_0 9.9626 Tf
+(Returned) 36.5229 Tj
+-250 TJm
+(by) 9.9626 Tj
+[1 0 0 1 159.467 427.099] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -159.467 -427.099] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+159.467 427.099 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 219.242 427.099] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -219.242 -427.099] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+221.733 427.099 Td
+/F130_0 9.9626 Tf
+(when) 21.579 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(\002nishes) 30.4457 Tj
+-250 TJm
+(before) 25.4445 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(logical) 27.1182 Tj
+-250 TJm
+(end) 14.386 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(stream) 26.5603 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(detected.) 35.686 Tj
+[1 0 0 1 72 424.942] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -410.994] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 401.196 Td
+/F134_0 9.9626 Tf
+(BZ_OUTBUFF_FULL) 89.6634 Tj
+[1 0 0 1 161.664 401.196] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -92.1544 -1.31] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -399.886] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+108 389.241 Td
+/F130_0 9.9626 Tf
+(Returned) 36.5229 Tj
+-258 TJm
+(by) 9.9626 Tj
+[1 0 0 1 159.632 389.241] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -159.632 -389.241] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+159.632 389.241 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffCompress) 143.461 Tj
+[1 0 0 1 303.094 389.241] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -303.094 -389.241] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+305.668 389.241 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 322.627 389.241] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -322.627 -389.241] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+322.627 389.241 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffDecompress) 155.417 Tj
+[1 0 0 1 478.044 389.241] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -478.044 -389.241] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+480.618 389.241 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-258 TJm
+(indicate) 31.5416 Tj
+-259 TJm
+(that) 14.9439 Tj
+108 377.286 Td
+(the) 12.1743 Tj
+-250 TJm
+(output) 25.4644 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(will) 15.5018 Tj
+-250 TJm
+(not) 12.7322 Tj
+-250 TJm
+(\002t) 8.30881 Tj
+-250 TJm
+(into) 15.5018 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(output) 25.4644 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-250 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vided.) 24.6275 Tj
+[1 0 0 1 72 375.129] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -3.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -351.218] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 328.585 Td
+/F122_0 20.6585 Tf
+(3.3.) 34.4584 Tj
+-278 TJm
+(Lo) 25.2447 Tj
+15 TJm
+(w-le) 40.1808 Tj
+15 TJm
+(vel) 28.7153 Tj
+-278 TJm
+(interface) 86.1046 Tj
+[1 0 0 1 72 328.327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -318.364] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 297.964 Td
+/F122_0 17.2154 Tf
+(3.3.1.) 43.0729 Tj
+[1 0 0 1 119.858 297.964] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -297.964] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 297.964 Td
+/F392_0 17.2154 Tf
+(BZ2_bzCompressInit) 185.926 Tj
+[1 0 0 1 305.785 297.964] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -233.785 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -244.779] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.8518] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.8518 Td
+/F130_0 9.9626 Tf
+(11) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 15 15
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -296.523] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 274.969 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 271.382] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(typedef) 41.8429 Tj
+-426 TJm
+(struct) 35.8654 Tj
+-426 TJm
+({) 5.97756 Tj
+98.4879 699.676 Td
+(char) 23.9102 Tj
+126.642 697.933 Td
+(*) 5.97756 Tj
+132.62 699.676 Td
+(next_in;) 47.8205 Tj
+98.4879 687.721 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(avail_in;) 53.798 Tj
+98.4879 675.766 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(total_in_lo32;) 83.6858 Tj
+98.4879 663.811 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(total_in_hi32;) 83.6858 Tj
+98.4879 639.9 Td
+(char) 23.9102 Tj
+126.642 638.157 Td
+(*) 5.97756 Tj
+132.62 639.9 Td
+(next_out;) 53.798 Tj
+98.4879 627.945 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(avail_out;) 59.7756 Tj
+98.4879 615.99 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(total_out_lo32;) 89.6634 Tj
+98.4879 604.035 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(total_out_hi32;) 89.6634 Tj
+98.4879 580.125 Td
+(void) 23.9102 Tj
+126.642 578.381 Td
+(*) 5.97756 Tj
+132.62 580.125 Td
+(state;) 35.8654 Tj
+98.4879 556.214 Td
+(void) 23.9102 Tj
+126.642 554.471 Td
+(*) 5.97756 Tj
+132.62 556.214 Td
+(\() 5.97756 Tj
+138.597 554.471 Td
+(*) 5.97756 Tj
+144.575 556.214 Td
+(bzalloc\)\(void) 77.7083 Tj
+226.527 554.471 Td
+(*) 5.97756 Tj
+232.505 556.214 Td
+(,int,int\);) 59.7756 Tj
+98.4879 544.259 Td
+(void) 23.9102 Tj
+-426 TJm
+(\() 5.97756 Tj
+132.62 542.516 Td
+(*) 5.97756 Tj
+138.597 544.259 Td
+(bzfree\)\(void) 71.7307 Tj
+214.572 542.516 Td
+(*) 5.97756 Tj
+220.55 544.259 Td
+(,void) 29.8878 Tj
+254.682 542.516 Td
+(*) 5.97756 Tj
+260.659 544.259 Td
+(\);) 11.9551 Tj
+98.4879 532.304 Td
+(void) 23.9102 Tj
+126.642 530.56 Td
+(*) 5.97756 Tj
+132.62 532.304 Td
+(opaque;) 41.8429 Tj
+89.9999 520.349 Td
+(}) 5.97756 Tj
+-426 TJm
+(bz_stream;) 59.7756 Tj
+89.9999 496.438 Td
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzCompressInit) 107.596 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bz_stream) 53.798 Tj
+292.281 494.695 Td
+(*) 5.97756 Tj
+298.258 496.438 Td
+(strm,) 29.8878 Tj
+196.099 484.483 Td
+(int) 17.9327 Tj
+-426 TJm
+(blockSize100k,) 83.6858 Tj
+196.099 472.528 Td
+(int) 17.9327 Tj
+-426 TJm
+(verbosity,) 59.7756 Tj
+196.099 460.573 Td
+(int) 17.9327 Tj
+-426 TJm
+(workFactor) 59.7756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 445.031] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -435.068] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 423.113 Td
+/F130_0 9.9626 Tf
+(Prepares) 34.3012 Tj
+-356 TJm
+(for) 11.6164 Tj
+-356 TJm
+(compression.) 52.8516 Tj
+-1256 TJm
+(The) 15.4918 Tj
+[1 0 0 1 209.409 423.113] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -209.409 -423.113] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+209.409 423.113 Td
+/F134_0 9.9626 Tf
+(bz_stream) 53.798 Tj
+[1 0 0 1 263.208 423.113] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -263.208 -423.113] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+266.754 423.113 Td
+/F130_0 9.9626 Tf
+(structure) 34.8591 Tj
+-356 TJm
+(holds) 21.589 Tj
+-356 TJm
+(all) 9.9626 Tj
+-356 TJm
+(data) 16.5977 Tj
+-356 TJm
+(pertaining) 40.3983 Tj
+-356 TJm
+(to) 7.7509 Tj
+-356 TJm
+(the) 12.1743 Tj
+-356 TJm
+(compression) 50.3609 Tj
+-355 TJm
+(acti) 14.386 Tj
+25 TJm
+(vity) 15.5018 Tj
+65 TJm
+(.) 2.49065 Tj
+-1256 TJm
+(A) 7.193 Tj
+[1 0 0 1 72 411.158] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -411.158] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 411.158 Td
+/F134_0 9.9626 Tf
+(bz_stream) 53.798 Tj
+[1 0 0 1 125.798 411.158] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -125.798 -411.158] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+128.581 411.158 Td
+/F130_0 9.9626 Tf
+(structure) 34.8591 Tj
+-279 TJm
+(should) 26.5703 Tj
+-280 TJm
+(be) 9.40469 Tj
+-279 TJm
+(allocated) 35.965 Tj
+-279 TJm
+(and) 14.386 Tj
+-280 TJm
+(initialised) 39.3025 Tj
+-279 TJm
+(prior) 19.3673 Tj
+-279 TJm
+(to) 7.7509 Tj
+-279 TJm
+(the) 12.1743 Tj
+-280 TJm
+(call.) 16.8766 Tj
+-796 TJm
+(The) 15.4918 Tj
+-279 TJm
+(\002elds) 21.589 Tj
+-279 TJm
+(of) 8.29885 Tj
+[1 0 0 1 431.939 411.158] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -431.939 -411.158] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+431.939 411.158 Td
+/F134_0 9.9626 Tf
+(bz_stream) 53.798 Tj
+[1 0 0 1 485.738 411.158] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -485.738 -411.158] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+488.52 411.158 Td
+/F130_0 9.9626 Tf
+(comprise) 36.5229 Tj
+-279 TJm
+(the) 12.1743 Tj
+72 399.203 Td
+(entirety) 30.4357 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(user) 16.5977 Tj
+20 TJm
+(-visible) 29.8878 Tj
+-250 TJm
+(data.) 19.0883 Tj
+[1 0 0 1 204.422 399.203] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.422 -399.203] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+204.422 399.203 Td
+/F134_0 9.9626 Tf
+(state) 29.8878 Tj
+[1 0 0 1 234.31 399.203] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -234.31 -399.203] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+236.8 399.203 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(pointer) 28.224 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(pri) 11.0684 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(ate) 11.6164 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(structures) 38.7346 Tj
+-250 TJm
+(required) 33.1954 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(compression.) 52.8516 Tj
+[1 0 0 1 72 397.046] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -387.083] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 377.285 Td
+/F130_0 9.9626 Tf
+(Custom) 31.0036 Tj
+-372 TJm
+(memory) 33.2053 Tj
+-372 TJm
+(allocators) 38.7346 Tj
+-372 TJm
+(are) 12.1643 Tj
+-372 TJm
+(supported,) 41.7831 Tj
+-403 TJm
+(via) 12.1743 Tj
+-372 TJm
+(\002elds) 21.589 Tj
+[1 0 0 1 288.908 377.285] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -288.908 -377.285] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+288.908 377.285 Td
+/F134_0 9.9626 Tf
+(bzalloc) 41.8429 Tj
+[1 0 0 1 330.751 377.285] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -330.751 -377.285] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+330.751 377.285 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 337.253 377.285] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -337.253 -377.285] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+337.253 377.285 Td
+/F134_0 9.9626 Tf
+(bzfree) 35.8654 Tj
+[1 0 0 1 373.118 377.285] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -373.118 -377.285] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+373.118 377.285 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-403 TJm
+(and) 14.386 Tj
+[1 0 0 1 397.714 377.285] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -397.714 -377.285] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+397.714 377.285 Td
+/F134_0 9.9626 Tf
+(opaque) 35.8654 Tj
+[1 0 0 1 433.579 377.285] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -433.579 -377.285] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+433.579 377.285 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1353 TJm
+(The) 15.4918 Tj
+-372 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+[1 0 0 1 493.782 377.285] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.782 -377.285] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+493.782 377.285 Td
+/F134_0 9.9626 Tf
+(opaque) 35.8654 Tj
+[1 0 0 1 529.648 377.285] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -529.648 -377.285] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+533.355 377.285 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+72 365.33 Td
+(passed) 26.5603 Tj
+-306 TJm
+(to) 7.7509 Tj
+-306 TJm
+(as) 8.29885 Tj
+-306 TJm
+(the) 12.1743 Tj
+-306 TJm
+(\002rst) 15.5018 Tj
+-306 TJm
+(ar) 7.74094 Tj
+18 TJm
+(gument) 29.8878 Tj
+-306 TJm
+(to) 7.7509 Tj
+-306 TJm
+(all) 9.9626 Tj
+-306 TJm
+(calls) 18.2614 Tj
+-305 TJm
+(to) 7.7509 Tj
+[1 0 0 1 253.941 365.33] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -253.941 -365.33] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+253.941 365.33 Td
+/F134_0 9.9626 Tf
+(bzalloc) 41.8429 Tj
+[1 0 0 1 295.784 365.33] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -295.784 -365.33] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+298.832 365.33 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 316.266 365.33] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -316.266 -365.33] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+316.266 365.33 Td
+/F134_0 9.9626 Tf
+(bzfree) 35.8654 Tj
+[1 0 0 1 352.132 365.33] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -352.132 -365.33] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+352.132 365.33 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-320 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-306 TJm
+(is) 6.64505 Tj
+-306 TJm
+(otherwise) 38.7346 Tj
+-306 TJm
+(ignored) 30.4357 Tj
+-306 TJm
+(by) 9.9626 Tj
+-306 TJm
+(the) 12.1743 Tj
+-306 TJm
+(library) 26.5603 Tj
+65 TJm
+(.) 2.49065 Tj
+-955 TJm
+(The) 15.4918 Tj
+72 353.375 Td
+(call) 14.386 Tj
+[1 0 0 1 89.4309 353.375] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -89.4309 -353.375] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+89.4309 353.375 Td
+/F134_0 9.9626 Tf
+(bzalloc) 41.8429 Tj
+-600 TJm
+(\() 5.97756 Tj
+-600 TJm
+(opaque,) 41.8429 Tj
+-600 TJm
+(n,) 11.9551 Tj
+-600 TJm
+(m) 5.97756 Tj
+-600 TJm
+(\)) 5.97756 Tj
+[1 0 0 1 232.893 353.375] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -232.893 -353.375] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+235.938 353.375 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-306 TJm
+(e) 4.42339 Tj
+15 TJm
+(xpected) 30.9837 Tj
+-305 TJm
+(to) 7.7509 Tj
+-306 TJm
+(return) 23.7907 Tj
+-306 TJm
+(a) 4.42339 Tj
+-305 TJm
+(pointer) 28.224 Tj
+[1 0 0 1 360.3 353.375] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -360.3 -353.375] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+360.3 353.375 Td
+/F134_0 9.9626 Tf
+(p) 5.97756 Tj
+[1 0 0 1 366.277 353.375] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -366.277 -353.375] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+369.322 353.375 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+[1 0 0 1 380.118 353.375] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -380.118 -353.375] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+380.118 353.375 Td
+/F134_0 9.9626 Tf
+(n) 5.97756 Tj
+392.073 351.631 Td
+(*) 5.97756 Tj
+404.029 353.375 Td
+(m) 5.97756 Tj
+[1 0 0 1 410.006 353.375] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -410.006 -353.375] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+413.051 353.375 Td
+/F130_0 9.9626 Tf
+(bytes) 21.031 Tj
+-306 TJm
+(of) 8.29885 Tj
+-305 TJm
+(memory) 33.2053 Tj
+65 TJm
+(,) 2.49065 Tj
+-320 TJm
+(and) 14.386 Tj
+[1 0 0 1 504.135 353.375] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -504.135 -353.375] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+504.135 353.375 Td
+/F134_0 9.9626 Tf
+(bzfree) 35.8654 Tj
+72 341.42 Td
+(\() 5.97756 Tj
+-600 TJm
+(opaque,) 41.8429 Tj
+-600 TJm
+(p) 5.97756 Tj
+-600 TJm
+(\)) 5.97756 Tj
+[1 0 0 1 149.709 341.42] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -149.709 -341.42] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+152.199 341.42 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-250 TJm
+(free) 15.4819 Tj
+-250 TJm
+(that) 14.9439 Tj
+-250 TJm
+(memory) 33.2053 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 339.263] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -329.3] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 319.502 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-280 TJm
+(you) 14.9439 Tj
+-280 TJm
+(don') 18.2614 Tj
+18 TJm
+(t) 2.7696 Tj
+-280 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-279 TJm
+(to) 7.7509 Tj
+-280 TJm
+(use) 13.2801 Tj
+-280 TJm
+(a) 4.42339 Tj
+-280 TJm
+(custom) 28.782 Tj
+-280 TJm
+(memory) 33.2053 Tj
+-279 TJm
+(allocator) 34.8591 Tj
+40 TJm
+(,) 2.49065 Tj
+-288 TJm
+(set) 11.0684 Tj
+[1 0 0 1 299.9 319.502] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -299.9 -319.502] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+299.9 319.502 Td
+/F134_0 9.9626 Tf
+(bzalloc) 41.8429 Tj
+[1 0 0 1 341.743 319.502] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -341.743 -319.502] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+341.743 319.502 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 347.096 319.502] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -347.096 -319.502] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+347.096 319.502 Td
+/F134_0 9.9626 Tf
+(bzfree) 35.8654 Tj
+[1 0 0 1 382.961 319.502] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -382.961 -319.502] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+385.749 319.502 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 402.923 319.502] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -402.923 -319.502] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+402.923 319.502 Td
+/F134_0 9.9626 Tf
+(opaque) 35.8654 Tj
+[1 0 0 1 438.788 319.502] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -438.788 -319.502] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+441.576 319.502 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+[1 0 0 1 452.115 319.502] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -452.115 -319.502] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+452.115 319.502 Td
+/F134_0 9.9626 Tf
+(NULL) 23.9102 Tj
+[1 0 0 1 476.025 319.502] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -476.025 -319.502] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+476.025 319.502 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-280 TJm
+(and) 14.386 Tj
+-280 TJm
+(the) 12.1743 Tj
+-279 TJm
+(library) 26.5603 Tj
+72 307.547 Td
+(will) 15.5018 Tj
+-250 TJm
+(then) 17.1556 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(standard) 33.7533 Tj
+[1 0 0 1 176.318 307.547] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -176.318 -307.547] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+176.318 307.547 Td
+/F134_0 9.9626 Tf
+(malloc) 35.8654 Tj
+[1 0 0 1 212.183 307.547] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -212.183 -307.547] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+214.674 307.547 Td
+/F130_0 9.9626 Tf
+(/) 2.7696 Tj
+[1 0 0 1 219.934 307.547] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -219.934 -307.547] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+219.934 307.547 Td
+/F134_0 9.9626 Tf
+(free) 23.9102 Tj
+[1 0 0 1 243.844 307.547] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -243.844 -307.547] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+246.335 307.547 Td
+/F130_0 9.9626 Tf
+(routines.) 34.5901 Tj
+[1 0 0 1 72 307.392] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -297.43] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 285.629 Td
+/F130_0 9.9626 Tf
+(Before) 27.1082 Tj
+-362 TJm
+(calling) 27.1182 Tj
+[1 0 0 1 133.438 285.629] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -133.438 -285.629] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+133.438 285.629 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 241.035 285.629] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -241.035 -285.629] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+241.035 285.629 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-390 TJm
+(\002elds) 21.589 Tj
+[1 0 0 1 272.606 285.629] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -272.606 -285.629] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+272.606 285.629 Td
+/F134_0 9.9626 Tf
+(bzalloc) 41.8429 Tj
+[1 0 0 1 314.449 285.629] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -314.449 -285.629] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+314.449 285.629 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 320.825 285.629] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -320.825 -285.629] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+320.825 285.629 Td
+/F134_0 9.9626 Tf
+(bzfree) 35.8654 Tj
+[1 0 0 1 356.69 285.629] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -356.69 -285.629] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+360.296 285.629 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 378.288 285.629] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -378.288 -285.629] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+378.288 285.629 Td
+/F134_0 9.9626 Tf
+(opaque) 35.8654 Tj
+[1 0 0 1 414.154 285.629] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -414.154 -285.629] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+417.76 285.629 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-362 TJm
+(be) 9.40469 Tj
+-362 TJm
+(\002lled) 20.4831 Tj
+-362 TJm
+(appropriately) 53.1206 Tj
+65 TJm
+(,) 2.49065 Tj
+72 273.674 Td
+(as) 8.29885 Tj
+-322 TJm
+(just) 14.396 Tj
+-323 TJm
+(described.) 40.6673 Tj
+-1055 TJm
+(Upon) 22.1369 Tj
+-322 TJm
+(return,) 26.2813 Tj
+-341 TJm
+(the) 12.1743 Tj
+-322 TJm
+(internal) 30.4357 Tj
+-323 TJm
+(state) 18.2614 Tj
+-322 TJm
+(will) 15.5018 Tj
+-323 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-322 TJm
+(been) 18.8094 Tj
+-323 TJm
+(allocated) 35.965 Tj
+-322 TJm
+(and) 14.386 Tj
+-323 TJm
+(initialised,) 41.7931 Tj
+-340 TJm
+(and) 14.386 Tj
+[1 0 0 1 459.801 273.674] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -459.801 -273.674] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+459.801 273.674 Td
+/F134_0 9.9626 Tf
+(total_in_lo32) 77.7083 Tj
+[1 0 0 1 537.509 273.674] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -537.509 -273.674] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+537.509 273.674 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 72 261.718] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -261.718] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 261.718 Td
+/F134_0 9.9626 Tf
+(total_in_hi32) 77.7083 Tj
+[1 0 0 1 149.709 261.718] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -149.709 -261.718] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+149.709 261.718 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 155.006 261.718] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.006 -261.718] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+155.006 261.718 Td
+/F134_0 9.9626 Tf
+(total_out_lo32) 83.6858 Tj
+[1 0 0 1 238.692 261.718] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -238.692 -261.718] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+241.435 261.718 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 258.564 261.718] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -258.564 -261.718] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+258.564 261.718 Td
+/F134_0 9.9626 Tf
+(total_out_hi32) 83.6858 Tj
+[1 0 0 1 342.25 261.718] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.25 -261.718] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+344.994 261.718 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-275 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-276 TJm
+(been) 18.8094 Tj
+-275 TJm
+(set) 11.0684 Tj
+-275 TJm
+(to) 7.7509 Tj
+-276 TJm
+(zero.) 19.6363 Tj
+-772 TJm
+(These) 23.7907 Tj
+-275 TJm
+(four) 16.5977 Tj
+-276 TJm
+(\002elds) 21.589 Tj
+-275 TJm
+(are) 12.1643 Tj
+72 249.763 Td
+(used) 18.2614 Tj
+-340 TJm
+(by) 9.9626 Tj
+-339 TJm
+(the) 12.1743 Tj
+-340 TJm
+(library) 26.5603 Tj
+-339 TJm
+(to) 7.7509 Tj
+-340 TJm
+(inform) 27.1182 Tj
+-339 TJm
+(the) 12.1743 Tj
+-340 TJm
+(caller) 22.1269 Tj
+-339 TJm
+(of) 8.29885 Tj
+-340 TJm
+(the) 12.1743 Tj
+-339 TJm
+(total) 17.7135 Tj
+-340 TJm
+(amount) 29.8878 Tj
+-339 TJm
+(of) 8.29885 Tj
+-340 TJm
+(data) 16.5977 Tj
+-340 TJm
+(passed) 26.5603 Tj
+-339 TJm
+(into) 15.5018 Tj
+-340 TJm
+(and) 14.386 Tj
+-339 TJm
+(out) 12.7322 Tj
+-340 TJm
+(of) 8.29885 Tj
+-339 TJm
+(the) 12.1743 Tj
+-340 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-362 TJm
+(respecti) 30.9837 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ely) 12.1743 Tj
+65 TJm
+(.) 2.49065 Tj
+72 237.808 Td
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-376 TJm
+(should) 26.5703 Tj
+-377 TJm
+(not) 12.7322 Tj
+-376 TJm
+(try) 11.0684 Tj
+-376 TJm
+(to) 7.7509 Tj
+-377 TJm
+(change) 28.2141 Tj
+-376 TJm
+(them.) 22.4159 Tj
+-1378 TJm
+(As) 11.0684 Tj
+-377 TJm
+(of) 8.29885 Tj
+-376 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-377 TJm
+(1.0,) 14.9439 Tj
+-408 TJm
+(64-bit) 23.8007 Tj
+-376 TJm
+(counts) 26.0123 Tj
+-376 TJm
+(are) 12.1643 Tj
+-377 TJm
+(maintained,) 46.7644 Tj
+-408 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-376 TJm
+(on) 9.9626 Tj
+-376 TJm
+(32-bit) 23.8007 Tj
+-377 TJm
+(platforms,) 40.6773 Tj
+72 225.853 Td
+(using) 21.589 Tj
+-371 TJm
+(the) 12.1743 Tj
+[1 0 0 1 113.148 225.853] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.148 -225.853] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+113.148 225.853 Td
+/F134_0 9.9626 Tf
+(_hi32) 29.8878 Tj
+[1 0 0 1 143.036 225.853] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.036 -225.853] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+146.729 225.853 Td
+/F130_0 9.9626 Tf
+(\002elds) 21.589 Tj
+-371 TJm
+(to) 7.7509 Tj
+-370 TJm
+(store) 19.3673 Tj
+-371 TJm
+(the) 12.1743 Tj
+-371 TJm
+(upper) 22.6848 Tj
+-370 TJm
+(32) 9.9626 Tj
+-371 TJm
+(bits) 14.396 Tj
+-370 TJm
+(of) 8.29885 Tj
+-371 TJm
+(the) 12.1743 Tj
+-371 TJm
+(count.) 24.6275 Tj
+-1344 TJm
+(So,) 13.0112 Tj
+-400 TJm
+(for) 11.6164 Tj
+-371 TJm
+(e) 4.42339 Tj
+15 TJm
+(xample,) 31.8205 Tj
+-401 TJm
+(the) 12.1743 Tj
+-371 TJm
+(total) 17.7135 Tj
+-370 TJm
+(amount) 29.8878 Tj
+-371 TJm
+(of) 8.29885 Tj
+-370 TJm
+(data) 16.5977 Tj
+-371 TJm
+(in) 7.7509 Tj
+-371 TJm
+(is) 6.64505 Tj
+[1 0 0 1 72 213.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -213.898] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 213.898 Td
+/F134_0 9.9626 Tf
+(\(total_in_hi32) 83.6858 Tj
+-600 TJm
+(<<) 11.9551 Tj
+-600 TJm
+(32\)) 17.9327 Tj
+-600 TJm
+(+) 5.97756 Tj
+-600 TJm
+(total_in_lo32) 77.7083 Tj
+[1 0 0 1 293.171 213.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -293.171 -213.898] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+293.171 213.898 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 212.588] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -202.625] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 191.98 Td
+/F130_0 9.9626 Tf
+(P) 5.53921 Tj
+15 TJm
+(arameter) 34.8492 Tj
+[1 0 0 1 115.367 191.98] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -115.367 -191.98] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+115.367 191.98 Td
+/F134_0 9.9626 Tf
+(blockSize100k) 77.7083 Tj
+[1 0 0 1 193.076 191.98] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -193.076 -191.98] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+196.204 191.98 Td
+/F130_0 9.9626 Tf
+(speci\002es) 34.3112 Tj
+-314 TJm
+(the) 12.1743 Tj
+-314 TJm
+(block) 22.1369 Tj
+-314 TJm
+(size) 15.4918 Tj
+-314 TJm
+(to) 7.7509 Tj
+-314 TJm
+(be) 9.40469 Tj
+-314 TJm
+(used) 18.2614 Tj
+-314 TJm
+(for) 11.6164 Tj
+-314 TJm
+(compression.) 52.8516 Tj
+-1004 TJm
+(It) 6.08715 Tj
+-314 TJm
+(should) 26.5703 Tj
+-314 TJm
+(be) 9.40469 Tj
+-315 TJm
+(a) 4.42339 Tj
+-314 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+-314 TJm
+(between) 33.1954 Tj
+-314 TJm
+(1) 4.9813 Tj
+72 180.025 Td
+(and) 14.386 Tj
+-289 TJm
+(9) 4.9813 Tj
+-289 TJm
+(inclusi) 26.5703 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e,) 6.91404 Tj
+-299 TJm
+(and) 14.386 Tj
+-289 TJm
+(the) 12.1743 Tj
+-289 TJm
+(actual) 23.7907 Tj
+-289 TJm
+(block) 22.1369 Tj
+-289 TJm
+(size) 15.4918 Tj
+-289 TJm
+(used) 18.2614 Tj
+-289 TJm
+(is) 6.64505 Tj
+-289 TJm
+(100000) 29.8878 Tj
+-289 TJm
+(x) 4.9813 Tj
+-289 TJm
+(this) 14.396 Tj
+-289 TJm
+(\002gure.) 25.7334 Tj
+-854 TJm
+(9) 4.9813 Tj
+-290 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+-289 TJm
+(the) 12.1743 Tj
+-289 TJm
+(best) 16.0497 Tj
+-289 TJm
+(compression) 50.3609 Tj
+-289 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-289 TJm
+(tak) 12.1743 Tj
+10 TJm
+(es) 8.29885 Tj
+-289 TJm
+(most) 19.3773 Tj
+72 168.07 Td
+(memory) 33.2053 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 165.913] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -155.95] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 146.152 Td
+/F130_0 9.9626 Tf
+(P) 5.53921 Tj
+15 TJm
+(arameter) 34.8492 Tj
+[1 0 0 1 115.095 146.152] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -115.095 -146.152] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+115.095 146.152 Td
+/F134_0 9.9626 Tf
+(verbosity) 53.798 Tj
+[1 0 0 1 168.893 146.152] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -168.893 -146.152] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+171.75 146.152 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-287 TJm
+(be) 9.40469 Tj
+-286 TJm
+(set) 11.0684 Tj
+-287 TJm
+(to) 7.7509 Tj
+-287 TJm
+(a) 4.42339 Tj
+-287 TJm
+(number) 30.4357 Tj
+-286 TJm
+(between) 33.1954 Tj
+-287 TJm
+(0) 4.9813 Tj
+-287 TJm
+(and) 14.386 Tj
+-287 TJm
+(4) 4.9813 Tj
+-286 TJm
+(inclusi) 26.5703 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e.) 6.91404 Tj
+-841 TJm
+(0) 4.9813 Tj
+-286 TJm
+(is) 6.64505 Tj
+-287 TJm
+(silent,) 24.0796 Tj
+-296 TJm
+(and) 14.386 Tj
+-287 TJm
+(greater) 27.6562 Tj
+-287 TJm
+(numbers) 34.3112 Tj
+-286 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+72 134.197 Td
+(increasingly) 48.6972 Tj
+-342 TJm
+(v) 4.9813 Tj
+15 TJm
+(erbose) 26.0024 Tj
+-342 TJm
+(monitoring/deb) 61.4394 Tj
+20 TJm
+(ugging) 27.6761 Tj
+-342 TJm
+(output.) 27.9551 Tj
+-1173 TJm
+(If) 6.63509 Tj
+-343 TJm
+(the) 12.1743 Tj
+-342 TJm
+(library) 26.5603 Tj
+-342 TJm
+(has) 13.2801 Tj
+-342 TJm
+(been) 18.8094 Tj
+-342 TJm
+(compiled) 37.0808 Tj
+-342 TJm
+(with) 17.7135 Tj
+[1 0 0 1 446.429 134.197] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -446.429 -134.197] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+446.429 134.197 Td
+/F134_0 9.9626 Tf
+(-DBZ_NO_STDIO) 77.7083 Tj
+[1 0 0 1 524.138 134.197] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -524.138 -134.197] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+524.138 134.197 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-342 TJm
+(no) 9.9626 Tj
+72 122.242 Td
+(such) 18.2614 Tj
+-250 TJm
+(output) 25.4644 Tj
+-250 TJm
+(will) 15.5018 Tj
+-250 TJm
+(appear) 26.5503 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-250 TJm
+(v) 4.9813 Tj
+15 TJm
+(erbosity) 32.0995 Tj
+-250 TJm
+(setting.) 29.0609 Tj
+[1 0 0 1 72 120.085] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -110.122] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 100.324 Td
+/F130_0 9.9626 Tf
+(P) 5.53921 Tj
+15 TJm
+(arameter) 34.8492 Tj
+[1 0 0 1 116.619 100.324] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -116.619 -100.324] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+116.619 100.324 Td
+/F134_0 9.9626 Tf
+(workFactor) 59.7756 Tj
+[1 0 0 1 176.394 100.324] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -176.394 -100.324] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+180.775 100.324 Td
+/F130_0 9.9626 Tf
+(controls) 32.0995 Tj
+-440 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-439 TJm
+(the) 12.1743 Tj
+-440 TJm
+(compression) 50.3609 Tj
+-440 TJm
+(phase) 22.6848 Tj
+-439 TJm
+(beha) 18.8094 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+-440 TJm
+(when) 21.579 Tj
+-439 TJm
+(presented) 38.1767 Tj
+-440 TJm
+(with) 17.7135 Tj
+-440 TJm
+(w) 7.193 Tj
+10 TJm
+(orst) 14.9439 Tj
+-439 TJm
+(case,) 19.6363 Tj
+-487 TJm
+(highly) 25.4644 Tj
+72 88.3686 Td
+(repetiti) 28.224 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e,) 6.91404 Tj
+-433 TJm
+(input) 20.4831 Tj
+-396 TJm
+(data.) 19.0883 Tj
+-1496 TJm
+(If) 6.63509 Tj
+-396 TJm
+(compression) 50.3609 Tj
+-396 TJm
+(runs) 17.1556 Tj
+-397 TJm
+(i) 2.7696 Tj
+1 TJm
+(nto) 12.7322 Tj
+-397 TJm
+(dif) 11.0684 Tj
+25 TJm
+(\002culties) 31.5516 Tj
+-396 TJm
+(caused) 27.1082 Tj
+-396 TJm
+(by) 9.9626 Tj
+-396 TJm
+(repetiti) 28.224 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-396 TJm
+(data,) 19.0883 Tj
+-432 TJm
+(the) 12.1743 Tj
+-397 TJm
+(library) 26.5603 Tj
+-396 TJm
+(switches) 34.3112 Tj
+-396 TJm
+(from) 19.3673 Tj
+[1 0 0 1 72 50.8518] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.8518] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.8518 Td
+/F130_0 9.9626 Tf
+(12) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 16 16
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -741.554] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(the) 12.1743 Tj
+-255 TJm
+(standard) 33.7533 Tj
+-254 TJm
+(sorting) 27.6761 Tj
+-255 TJm
+(algorithm) 38.7446 Tj
+-254 TJm
+(to) 7.7509 Tj
+-255 TJm
+(a) 4.42339 Tj
+-255 TJm
+(f) 3.31755 Tj
+10 TJm
+(allback) 28.772 Tj
+-254 TJm
+(algorithm.) 41.2352 Tj
+-648 TJm
+(The) 15.4918 Tj
+-255 TJm
+(f) 3.31755 Tj
+10 TJm
+(allback) 28.772 Tj
+-254 TJm
+(is) 6.64505 Tj
+-255 TJm
+(slo) 11.6264 Tj
+25 TJm
+(wer) 14.9339 Tj
+-255 TJm
+(than) 17.1556 Tj
+-254 TJm
+(the) 12.1743 Tj
+-255 TJm
+(standard) 33.7533 Tj
+-254 TJm
+(algorithm) 38.7446 Tj
+-255 TJm
+(by) 9.9626 Tj
+-255 TJm
+(perhaps) 30.9837 Tj
+72 698.082 Td
+(a) 4.42339 Tj
+-250 TJm
+(f) 3.31755 Tj
+10 TJm
+(actor) 19.9152 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(three,) 22.4059 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(al) 7.193 Tj
+10 TJm
+(w) 7.193 Tj
+10 TJm
+(ays) 13.2801 Tj
+-250 TJm
+(beha) 18.8094 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+-250 TJm
+(reasonably) 43.158 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(no) 9.9626 Tj
+-250 TJm
+(matter) 25.4544 Tj
+-250 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(bad) 14.386 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(input.) 22.9738 Tj
+[1 0 0 1 72 695.925] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9617] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -685.964] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 676.165 Td
+/F130_0 9.9626 Tf
+(Lo) 11.0684 Tj
+25 TJm
+(wer) 14.9339 Tj
+-240 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues) 20.4731 Tj
+-239 TJm
+(of) 8.29885 Tj
+[1 0 0 1 138.421 676.165] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -138.421 -676.165] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+138.421 676.165 Td
+/F134_0 9.9626 Tf
+(workFactor) 59.7756 Tj
+[1 0 0 1 198.197 676.165] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -198.197 -676.165] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+200.585 676.165 Td
+/F130_0 9.9626 Tf
+(reduce) 26.5503 Tj
+-240 TJm
+(the) 12.1743 Tj
+-239 TJm
+(amount) 29.8878 Tj
+-240 TJm
+(of) 8.29885 Tj
+-240 TJm
+(ef) 7.74094 Tj
+25 TJm
+(fort) 14.386 Tj
+-239 TJm
+(the) 12.1743 Tj
+-240 TJm
+(standard) 33.7533 Tj
+-240 TJm
+(algorithm) 38.7446 Tj
+-239 TJm
+(will) 15.5018 Tj
+-240 TJm
+(e) 4.42339 Tj
+15 TJm
+(xpend) 24.3486 Tj
+-240 TJm
+(before) 25.4445 Tj
+-240 TJm
+(resorting) 35.417 Tj
+-239 TJm
+(to) 7.7509 Tj
+-240 TJm
+(the) 12.1743 Tj
+72 664.21 Td
+(f) 3.31755 Tj
+10 TJm
+(allback.) 31.2626 Tj
+-618 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-248 TJm
+(should) 26.5703 Tj
+-247 TJm
+(set) 11.0684 Tj
+-248 TJm
+(this) 14.396 Tj
+-247 TJm
+(parameter) 39.8305 Tj
+-248 TJm
+(carefully;) 38.1767 Tj
+-248 TJm
+(too) 12.7322 Tj
+-248 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(,) 2.49065 Tj
+-248 TJm
+(and) 14.386 Tj
+-247 TJm
+(man) 17.1556 Tj
+15 TJm
+(y) 4.9813 Tj
+-248 TJm
+(inputs) 24.3586 Tj
+-248 TJm
+(will) 15.5018 Tj
+-247 TJm
+(be) 9.40469 Tj
+-248 TJm
+(handled) 31.5416 Tj
+-247 TJm
+(by) 9.9626 Tj
+-248 TJm
+(the) 12.1743 Tj
+-247 TJm
+(f) 3.31755 Tj
+10 TJm
+(allback) 28.772 Tj
+-248 TJm
+(algorithm) 38.7446 Tj
+72 652.255 Td
+(and) 14.386 Tj
+-308 TJm
+(so) 8.85675 Tj
+-308 TJm
+(compress) 37.6287 Tj
+-308 TJm
+(rather) 23.2328 Tj
+-309 TJm
+(slo) 11.6264 Tj
+25 TJm
+(wly) 14.9439 Tj
+65 TJm
+(,) 2.49065 Tj
+-322 TJm
+(too) 12.7322 Tj
+-309 TJm
+(high,) 20.2042 Tj
+-322 TJm
+(and) 14.386 Tj
+-308 TJm
+(your) 18.2614 Tj
+-309 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(erage-to-w) 43.148 Tj
+10 TJm
+(orst) 14.9439 Tj
+-308 TJm
+(case) 17.1456 Tj
+-308 TJm
+(compression) 50.3609 Tj
+-308 TJm
+(times) 21.589 Tj
+-308 TJm
+(can) 13.8281 Tj
+-308 TJm
+(become) 30.9837 Tj
+-309 TJm
+(v) 4.9813 Tj
+15 TJm
+(ery) 12.7222 Tj
+-308 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ge.) 11.8953 Tj
+72 640.3 Td
+(The) 15.4918 Tj
+-250 TJm
+(def) 12.7222 Tj
+10 TJm
+(ault) 14.9439 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(30) 9.9626 Tj
+-250 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+-250 TJm
+(reasonable) 42.6001 Tj
+-250 TJm
+(beha) 18.8094 Tj
+20 TJm
+(viour) 21.031 Tj
+-250 TJm
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(wide) 19.3673 Tj
+-250 TJm
+(range) 22.1269 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(circumstances.) 58.9288 Tj
+[1 0 0 1 72 638.143] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9617] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -628.181] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 618.383 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues) 20.4731 Tj
+-250 TJm
+(range) 22.1269 Tj
+-250 TJm
+(from) 19.3673 Tj
+-250 TJm
+(0) 4.9813 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(250) 14.9439 Tj
+-250 TJm
+(inclusi) 26.5703 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e.) 6.91404 Tj
+-620 TJm
+(0) 4.9813 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(special) 27.6661 Tj
+-250 TJm
+(case,) 19.6363 Tj
+-250 TJm
+(equi) 17.1556 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(alent) 19.3673 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(using) 21.589 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(def) 12.7222 Tj
+10 TJm
+(ault) 14.9439 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(30.) 12.4533 Tj
+[1 0 0 1 72 616.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9617] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -606.265] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 596.466 Td
+/F130_0 9.9626 Tf
+(Note) 19.3673 Tj
+-250 TJm
+(that) 14.9439 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(output) 25.4644 Tj
+-250 TJm
+(generated) 38.7246 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(same) 20.4731 Tj
+-250 TJm
+(re) 7.74094 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(ardless) 27.6661 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(whether) 32.0895 Tj
+-250 TJm
+(or) 8.29885 Tj
+-250 TJm
+(not) 12.7322 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(f) 3.31755 Tj
+10 TJm
+(allback) 28.772 Tj
+-250 TJm
+(algorithm) 38.7446 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(used.) 20.7521 Tj
+[1 0 0 1 72 594.309] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9617] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -584.348] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 574.549 Td
+/F130_0 9.9626 Tf
+(Be) 11.0684 Tj
+-303 TJm
+(a) 4.42339 Tj
+15 TJm
+(w) 7.193 Tj
+10 TJm
+(are) 12.1643 Tj
+-303 TJm
+(also) 16.0497 Tj
+-303 TJm
+(that) 14.9439 Tj
+-303 TJm
+(this) 14.396 Tj
+-304 TJm
+(parameter) 39.8305 Tj
+-303 TJm
+(may) 17.1556 Tj
+-303 TJm
+(disappear) 38.1767 Tj
+-303 TJm
+(entirely) 30.4357 Tj
+-303 TJm
+(in) 7.7509 Tj
+-303 TJm
+(future) 23.7907 Tj
+-303 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions) 28.224 Tj
+-303 TJm
+(of) 8.29885 Tj
+-303 TJm
+(the) 12.1743 Tj
+-304 TJm
+(library) 26.5603 Tj
+65 TJm
+(.) 2.49065 Tj
+-938 TJm
+(In) 8.29885 Tj
+-303 TJm
+(principle) 35.417 Tj
+-303 TJm
+(it) 5.53921 Tj
+-304 TJm
+(should) 26.5703 Tj
+-303 TJm
+(be) 9.40469 Tj
+72 562.594 Td
+(possible) 32.6574 Tj
+-270 TJm
+(to) 7.7509 Tj
+-270 TJm
+(de) 9.40469 Tj
+25 TJm
+(vise) 16.0497 Tj
+-270 TJm
+(a) 4.42339 Tj
+-270 TJm
+(good) 19.9252 Tj
+-270 TJm
+(w) 7.193 Tj
+10 TJm
+(ay) 9.40469 Tj
+-270 TJm
+(to) 7.7509 Tj
+-271 TJm
+(automat) 32.0995 Tj
+1 TJm
+(ically) 22.1369 Tj
+-271 TJm
+(choose) 27.6661 Tj
+-270 TJm
+(which) 24.3486 Tj
+-270 TJm
+(algorithm) 38.7446 Tj
+-270 TJm
+(to) 7.7509 Tj
+-270 TJm
+(use.) 15.7708 Tj
+-740 TJm
+(Such) 19.9252 Tj
+-270 TJm
+(a) 4.42339 Tj
+-271 TJm
+(m) 7.7509 Tj
+1 TJm
+(echanism) 37.6287 Tj
+-271 TJm
+(w) 7.193 Tj
+10 TJm
+(ould) 17.7135 Tj
+-270 TJm
+(render) 25.4445 Tj
+-270 TJm
+(the) 12.1743 Tj
+72 550.639 Td
+(parameter) 39.8305 Tj
+-250 TJm
+(obsolete.) 35.696 Tj
+[1 0 0 1 72 548.482] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9616] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -538.521] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 528.722 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 528.623] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -144.458] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 143.462 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 139.875] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -519.258] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 519.258 Td
+/F134_0 9.9626 Tf
+(BZ_CONFIG_ERROR) 89.6634 Tj
+98.4879 507.303 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(library) 41.8429 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(mis-compiled) 71.7307 Tj
+90 495.348 Td
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 483.392 Td
+(if) 11.9551 Tj
+-426 TJm
+(strm) 23.9102 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+98.4879 471.437 Td
+(or) 11.9551 Tj
+-426 TJm
+(blockSize) 53.798 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(1) 5.97756 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(blockSize) 53.798 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(9) 5.97756 Tj
+98.4879 459.482 Td
+(or) 11.9551 Tj
+-426 TJm
+(verbosity) 53.798 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(verbosity) 53.798 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(4) 5.97756 Tj
+98.4879 447.527 Td
+(or) 11.9551 Tj
+-426 TJm
+(workFactor) 59.7756 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(workFactor) 59.7756 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(250) 17.9327 Tj
+90 435.572 Td
+(BZ_MEM_ERROR) 71.7307 Tj
+98.4879 423.617 Td
+(if) 11.9551 Tj
+-426 TJm
+(not) 17.9327 Tj
+-426 TJm
+(enough) 35.8654 Tj
+-426 TJm
+(memory) 35.8654 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(available) 53.798 Tj
+90 411.661 Td
+(BZ_OK) 29.8878 Tj
+98.4879 399.706 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 384.165] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5482] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -374.203] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 362.248 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(actions:) 30.9936 Tj
+[1 0 0 1 72 362.148] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -48.8169] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 47.8207 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 44.2341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -352.783] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 352.783 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+98.4879 340.828 Td
+(if) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(returned) 47.8205 Tj
+98.4879 328.873 Td
+(no) 11.9551 Tj
+-426 TJm
+(specific) 47.8205 Tj
+-426 TJm
+(action) 35.8654 Tj
+-426 TJm
+(needed) 35.8654 Tj
+-426 TJm
+(in) 11.9551 Tj
+-426 TJm
+(case) 23.9102 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(error) 29.8878 Tj
+[1 0 0 1 72 313.331] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9616] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -303.37] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 282.711 Td
+/F122_0 17.2154 Tf
+(3.3.2.) 43.0729 Tj
+[1 0 0 1 119.858 282.711] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -282.711] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 282.711 Td
+/F392_0 17.2154 Tf
+(BZ2_bzCompress) 144.609 Tj
+[1 0 0 1 264.468 282.711] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -192.468 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -271.014] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 271.014 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzCompress) 83.6858 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bz_stream) 53.798 Tj
+268.371 269.27 Td
+(*) 5.97756 Tj
+274.348 271.014 Td
+(strm,) 29.8878 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(action) 35.8654 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 255.472] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5482] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -245.51] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 233.555 Td
+/F130_0 9.9626 Tf
+(Pro) 13.8381 Tj
+15 TJm
+(vides) 21.031 Tj
+-222 TJm
+(more) 20.4731 Tj
+-221 TJm
+(input) 20.4831 Tj
+-222 TJm
+(and/or) 25.4544 Tj
+-222 TJm
+(output) 25.4644 Tj
+-222 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-221 TJm
+(space) 22.1269 Tj
+-222 TJm
+(for) 11.6164 Tj
+-222 TJm
+(the) 12.1743 Tj
+-221 TJm
+(library) 26.5603 Tj
+65 TJm
+(.) 2.49065 Tj
+-601 TJm
+(The) 15.4918 Tj
+-222 TJm
+(caller) 22.1269 Tj
+-222 TJm
+(maintains) 38.7446 Tj
+-222 TJm
+(input) 20.4831 Tj
+-221 TJm
+(and) 14.386 Tj
+-222 TJm
+(output) 25.4644 Tj
+-222 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fers,) 17.4246 Tj
+-227 TJm
+(and) 14.386 Tj
+-222 TJm
+(calls) 18.2614 Tj
+[1 0 0 1 72 221.6] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -221.6] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 221.6 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 155.686 221.6] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.686 -221.6] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+158.177 221.6 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(transfer) 30.4258 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(between) 33.1954 Tj
+-250 TJm
+(them.) 22.4159 Tj
+[1 0 0 1 72 220.066] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9617] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -210.104] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 199.683 Td
+/F130_0 9.9626 Tf
+(Before) 27.1082 Tj
+-212 TJm
+(each) 18.2515 Tj
+-213 TJm
+(call) 14.386 Tj
+-212 TJm
+(to) 7.7509 Tj
+[1 0 0 1 147.961 199.683] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -147.961 -199.683] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+147.961 199.683 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 231.647 199.683] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -231.647 -199.683] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+231.647 199.683 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 236.329 199.683] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -236.329 -199.683] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+236.329 199.683 Td
+/F134_0 9.9626 Tf
+(next_in) 41.8429 Tj
+[1 0 0 1 278.172 199.683] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.172 -199.683] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+280.288 199.683 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-212 TJm
+(point) 20.4831 Tj
+-213 TJm
+(at) 7.193 Tj
+-212 TJm
+(the) 12.1743 Tj
+-213 TJm
+(data) 16.5977 Tj
+-212 TJm
+(to) 7.7509 Tj
+-212 TJm
+(be) 9.40469 Tj
+-213 TJm
+(compressed,) 49.5241 Tj
+-220 TJm
+(and) 14.386 Tj
+[1 0 0 1 463.493 199.683] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -463.493 -199.683] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+463.493 199.683 Td
+/F134_0 9.9626 Tf
+(avail_in) 47.8205 Tj
+[1 0 0 1 511.314 199.683] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.314 -199.683] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+513.43 199.683 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+72 187.728 Td
+(indicate) 31.5416 Tj
+-246 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-247 TJm
+(m) 7.7509 Tj
+1 TJm
+(an) 9.40469 Tj
+14 TJm
+(y) 4.9813 Tj
+-246 TJm
+(bytes) 21.031 Tj
+-246 TJm
+(the) 12.1743 Tj
+-246 TJm
+(library) 26.5603 Tj
+-247 TJm
+(may) 17.1556 Tj
+-246 TJm
+(read.) 19.6363 Tj
+[1 0 0 1 259.242 187.728] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -259.242 -187.728] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+259.242 187.728 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 342.929 187.728] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.929 -187.728] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+345.382 187.728 Td
+/F130_0 9.9626 Tf
+(updates) 30.4357 Tj
+[1 0 0 1 378.271 187.728] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -378.271 -187.728] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+378.271 187.728 Td
+/F134_0 9.9626 Tf
+(next_in) 41.8429 Tj
+[1 0 0 1 420.114 187.728] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -420.114 -187.728] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+420.114 187.728 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 425.066 187.728] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -425.066 -187.728] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+425.066 187.728 Td
+/F134_0 9.9626 Tf
+(avail_in) 47.8205 Tj
+[1 0 0 1 472.886 187.728] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.886 -187.728] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+475.34 187.728 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 492.179 187.728] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -492.179 -187.728] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+492.179 187.728 Td
+/F134_0 9.9626 Tf
+(total_in) 47.8205 Tj
+[1 0 0 1 540 187.728] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -187.728] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 175.773 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(re\003ect) 24.8965 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(number) 30.4357 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(bytes) 21.031 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(has) 13.2801 Tj
+-250 TJm
+(read.) 19.6363 Tj
+[1 0 0 1 72 173.616] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9616] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -163.654] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 153.856 Td
+/F130_0 9.9626 Tf
+(Similarly) 37.0908 Tj
+65 TJm
+(,) 2.49065 Tj
+[1 0 0 1 113.611 153.856] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.611 -153.856] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+113.611 153.856 Td
+/F134_0 9.9626 Tf
+(next_out) 47.8205 Tj
+[1 0 0 1 161.432 153.856] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.432 -153.856] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+164.072 153.856 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-265 TJm
+(point) 20.4831 Tj
+-265 TJm
+(to) 7.7509 Tj
+-265 TJm
+(a) 4.42339 Tj
+-265 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-265 TJm
+(in) 7.7509 Tj
+-265 TJm
+(which) 24.3486 Tj
+-265 TJm
+(the) 12.1743 Tj
+-265 TJm
+(compressed) 47.0334 Tj
+-265 TJm
+(data) 16.5977 Tj
+-265 TJm
+(is) 6.64505 Tj
+-265 TJm
+(to) 7.7509 Tj
+-265 TJm
+(be) 9.40469 Tj
+-265 TJm
+(placed,) 28.493 Tj
+-269 TJm
+(with) 17.7135 Tj
+[1 0 0 1 464.742 153.856] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -464.742 -153.856] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+464.742 153.856 Td
+/F134_0 9.9626 Tf
+(avail_out) 53.798 Tj
+[1 0 0 1 518.54 153.856] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -518.54 -153.856] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+521.181 153.856 Td
+/F130_0 9.9626 Tf
+(indi-) 18.8194 Tj
+72 141.901 Td
+(cating) 24.3486 Tj
+-209 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-209 TJm
+(much) 22.1369 Tj
+-209 TJm
+(output) 25.4644 Tj
+-209 TJm
+(space) 22.1269 Tj
+-209 TJm
+(is) 6.64505 Tj
+-210 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+25 TJm
+(ailable.) 29.0509 Tj
+[1 0 0 1 243.087 141.901] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -243.087 -141.901] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+243.087 141.901 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 326.773 141.901] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -326.773 -141.901] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+328.856 141.901 Td
+/F130_0 9.9626 Tf
+(updates) 30.4357 Tj
+[1 0 0 1 361.375 141.901] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -361.375 -141.901] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+361.375 141.901 Td
+/F134_0 9.9626 Tf
+(next_out) 47.8205 Tj
+[1 0 0 1 409.196 141.901] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -409.196 -141.901] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+409.196 141.901 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 413.851 141.901] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -413.851 -141.901] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+413.851 141.901 Td
+/F134_0 9.9626 Tf
+(avail_out) 53.798 Tj
+[1 0 0 1 467.649 141.901] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -467.649 -141.901] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+469.732 141.901 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 486.202 141.901] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -486.202 -141.901] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+486.202 141.901 Td
+/F134_0 9.9626 Tf
+(total_out) 53.798 Tj
+[1 0 0 1 540 141.901] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -141.901] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 129.946 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(re\003ect) 24.8965 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(number) 30.4357 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(bytes) 21.031 Tj
+-250 TJm
+(output.) 27.9551 Tj
+[1 0 0 1 72 127.789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9617] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -117.827] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 108.029 Td
+/F130_0 9.9626 Tf
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-272 TJm
+(may) 17.1556 Tj
+-272 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vide) 17.1556 Tj
+-272 TJm
+(and) 14.386 Tj
+-272 TJm
+(remo) 20.4731 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-272 TJm
+(as) 8.29885 Tj
+-272 TJm
+(little) 18.2714 Tj
+-272 TJm
+(or) 8.29885 Tj
+-272 TJm
+(as) 8.29885 Tj
+-272 TJm
+(much) 22.1369 Tj
+-271 TJm
+(data) 16.5977 Tj
+-272 TJm
+(as) 8.29885 Tj
+-272 TJm
+(you) 14.9439 Tj
+-272 TJm
+(lik) 10.5205 Tj
+10 TJm
+(e) 4.42339 Tj
+-272 TJm
+(on) 9.9626 Tj
+-272 TJm
+(each) 18.2515 Tj
+-272 TJm
+(call) 14.386 Tj
+-272 TJm
+(of) 8.29885 Tj
+[1 0 0 1 399.123 108.029] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -399.123 -108.029] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+399.123 108.029 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 482.809 108.029] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -482.809 -108.029] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+482.809 108.029 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-752 TJm
+(In) 8.29885 Tj
+-272 TJm
+(the) 12.1743 Tj
+-272 TJm
+(limit,) 21.32 Tj
+72 96.0736 Td
+(it) 5.53921 Tj
+-266 TJm
+(is) 6.64505 Tj
+-265 TJm
+(acceptable) 42.0422 Tj
+-266 TJm
+(to) 7.7509 Tj
+-266 TJm
+(supply) 26.5703 Tj
+-266 TJm
+(and) 14.386 Tj
+-265 TJm
+(remo) 20.4731 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-266 TJm
+(data) 16.5977 Tj
+-266 TJm
+(one) 14.386 Tj
+-265 TJm
+(byte) 17.1556 Tj
+-266 TJm
+(at) 7.193 Tj
+-266 TJm
+(a) 4.42339 Tj
+-266 TJm
+(time,) 20.2042 Tj
+-269 TJm
+(although) 34.8691 Tj
+-266 TJm
+(this) 14.396 Tj
+-266 TJm
+(w) 7.193 Tj
+10 TJm
+(ould) 17.7135 Tj
+-265 TJm
+(be) 9.40469 Tj
+-266 TJm
+(terribly) 29.3299 Tj
+-266 TJm
+(inef) 15.4918 Tj
+25 TJm
+(\002cient.) 27.3972 Tj
+-714 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-266 TJm
+(should) 26.5703 Tj
+72 84.1184 Td
+(al) 7.193 Tj
+10 TJm
+(w) 7.193 Tj
+10 TJm
+(ays) 13.2801 Tj
+-250 TJm
+(ensure) 26.0024 Tj
+-250 TJm
+(that) 14.9439 Tj
+-250 TJm
+(at) 7.193 Tj
+-250 TJm
+(least) 18.2614 Tj
+-250 TJm
+(one) 14.386 Tj
+-250 TJm
+(byte) 17.1556 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(output) 25.4644 Tj
+-250 TJm
+(space) 22.1269 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+25 TJm
+(ailable) 26.5603 Tj
+-250 TJm
+(at) 7.193 Tj
+-250 TJm
+(each) 18.2515 Tj
+-250 TJm
+(call.) 16.8766 Tj
+[1 0 0 1 72 81.9616] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9616] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -21.1482] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(13) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 17 17
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -741.554] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(A) 7.193 Tj
+-250 TJm
+(second) 27.6661 Tj
+-250 TJm
+(purpose) 31.5416 Tj
+-250 TJm
+(of) 8.29885 Tj
+[1 0 0 1 156.662 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -156.662 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+156.662 710.037 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 240.348 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -240.348 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+242.839 710.037 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(request) 28.772 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(change) 28.2141 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(mode) 22.1369 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(stream.) 29.0509 Tj
+[1 0 0 1 72 707.88] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -697.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 688.12 Td
+/F130_0 9.9626 Tf
+(Conceptually) 53.1305 Tj
+65 TJm
+(,) 2.49065 Tj
+-217 TJm
+(a) 4.42339 Tj
+-210 TJm
+(compressed) 47.0334 Tj
+-209 TJm
+(stream) 26.5603 Tj
+-209 TJm
+(can) 13.8281 Tj
+-209 TJm
+(be) 9.40469 Tj
+-210 TJm
+(in) 7.7509 Tj
+-209 TJm
+(one) 14.386 Tj
+-209 TJm
+(of) 8.29885 Tj
+-209 TJm
+(four) 16.5977 Tj
+-210 TJm
+(states:) 24.9065 Tj
+-289 TJm
+(IDLE,) 25.1755 Tj
+-209 TJm
+(R) 6.64505 Tj
+40 TJm
+(UNNING,) 41.7732 Tj
+-210 TJm
+(FLUSHING) 49.2551 Tj
+-209 TJm
+(and) 14.386 Tj
+-209 TJm
+(FINISHING.) 52.2937 Tj
+-419 TJm
+(Be-) 14.386 Tj
+72 676.164 Td
+(fore) 16.0398 Tj
+-264 TJm
+(initialisation) 49.823 Tj
+-263 TJm
+(\() 3.31755 Tj
+[1 0 0 1 146.434 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -146.434 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+146.434 676.164 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 254.031 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -254.031 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+254.031 676.164 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-264 TJm
+(and) 14.386 Tj
+-263 TJm
+(after) 18.2515 Tj
+-264 TJm
+(termination) 45.9375 Tj
+-264 TJm
+(\() 3.31755 Tj
+[1 0 0 1 349.75 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -349.75 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+349.75 676.164 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressEnd) 101.619 Tj
+[1 0 0 1 451.369 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -451.369 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+451.369 676.164 Td
+/F130_0 9.9626 Tf
+(\),) 5.8082 Tj
+-267 TJm
+(a) 4.42339 Tj
+-264 TJm
+(stream) 26.5603 Tj
+-264 TJm
+(is) 6.64505 Tj
+-263 TJm
+(re) 7.74094 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(arded) 22.1269 Tj
+72 664.209 Td
+(as) 8.29885 Tj
+-250 TJm
+(IDLE.) 25.1755 Tj
+[1 0 0 1 72 664.11] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -654.147] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 642.291 Td
+/F130_0 9.9626 Tf
+(Upon) 22.1369 Tj
+-389 TJm
+(initialisation) 49.823 Tj
+-390 TJm
+(\() 3.31755 Tj
+[1 0 0 1 155.036 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.036 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+155.036 642.291 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 262.632 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -262.632 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+262.632 642.291 Td
+/F130_0 9.9626 Tf
+(\),) 5.8082 Tj
+-424 TJm
+(the) 12.1743 Tj
+-390 TJm
+(stream) 26.5603 Tj
+-389 TJm
+(is) 6.64505 Tj
+-389 TJm
+(placed) 26.0024 Tj
+-390 TJm
+(in) 7.7509 Tj
+-389 TJm
+(the) 12.1743 Tj
+-390 TJm
+(R) 6.64505 Tj
+40 TJm
+(UNNING) 39.2825 Tj
+-389 TJm
+(state.) 20.7521 Tj
+-1457 TJm
+(Subsequent) 45.9375 Tj
+-389 TJm
+(calls) 18.2614 Tj
+72 630.336 Td
+(to) 7.7509 Tj
+[1 0 0 1 83.818 630.336] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -83.818 -630.336] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+83.818 630.336 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 167.504 630.336] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -167.504 -630.336] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+171.571 630.336 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-408 TJm
+(pass) 17.1556 Tj
+[1 0 0 1 223.431 630.336] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -223.431 -630.336] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+223.431 630.336 Td
+/F134_0 9.9626 Tf
+(BZ_RUN) 35.8654 Tj
+[1 0 0 1 259.297 630.336] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -259.297 -630.336] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+263.363 630.336 Td
+/F130_0 9.9626 Tf
+(as) 8.29885 Tj
+-408 TJm
+(the) 12.1743 Tj
+-408 TJm
+(requested) 38.1767 Tj
+-409 TJm
+(action;) 27.1182 Tj
+-487 TJm
+(other) 20.4731 Tj
+-408 TJm
+(actions) 28.224 Tj
+-408 TJm
+(are) 12.1643 Tj
+-409 TJm
+(ille) 12.7322 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(al) 7.193 Tj
+-408 TJm
+(and) 14.386 Tj
+-408 TJm
+(will) 15.5018 Tj
+-408 TJm
+(result) 22.1369 Tj
+-409 TJm
+(in) 7.7509 Tj
+[1 0 0 1 72 618.381] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -618.381] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 618.381 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+[1 0 0 1 173.619 618.381] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -173.619 -618.381] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+173.619 618.381 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 617.071] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -607.108] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 596.463 Td
+/F130_0 9.9626 Tf
+(At) 9.9626 Tj
+-279 TJm
+(some) 21.031 Tj
+-279 TJm
+(point,) 22.9738 Tj
+-286 TJm
+(the) 12.1743 Tj
+-279 TJm
+(calling) 27.1182 Tj
+-279 TJm
+(program) 33.7533 Tj
+-279 TJm
+(will) 15.5018 Tj
+-279 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-278 TJm
+(pro) 13.2801 Tj
+14 TJm
+(vi) 7.7509 Tj
+1 TJm
+(ded) 14.386 Tj
+-279 TJm
+(all) 9.9626 Tj
+-279 TJm
+(the) 12.1743 Tj
+-279 TJm
+(input) 20.4831 Tj
+-279 TJm
+(data) 16.5977 Tj
+-279 TJm
+(it) 5.53921 Tj
+-279 TJm
+(w) 7.193 Tj
+10 TJm
+(ants) 16.0497 Tj
+-279 TJm
+(to.) 10.2416 Tj
+-793 TJm
+(It) 6.08715 Tj
+-279 TJm
+(will) 15.5018 Tj
+-279 TJm
+(then) 17.1556 Tj
+-279 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-279 TJm
+(to) 7.7509 Tj
+-279 TJm
+(\002nish) 22.1469 Tj
+-279 TJm
+(up) 9.9626 Tj
+-279 TJm
+(--) 6.63509 Tj
+72 584.508 Td
+(in) 7.7509 Tj
+-287 TJm
+(ef) 7.74094 Tj
+25 TJm
+(fect,) 17.4246 Tj
+-297 TJm
+(asking) 26.0123 Tj
+-288 TJm
+(the) 12.1743 Tj
+-287 TJm
+(library) 26.5603 Tj
+-287 TJm
+(to) 7.7509 Tj
+-288 TJm
+(process) 29.8778 Tj
+-287 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-288 TJm
+(data) 16.5977 Tj
+-287 TJm
+(it) 5.53921 Tj
+-287 TJm
+(might) 23.2527 Tj
+-288 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-287 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fered) 20.4632 Tj
+-288 TJm
+(internally) 38.1866 Tj
+65 TJm
+(.) 2.49065 Tj
+-844 TJm
+(In) 8.29885 Tj
+-288 TJm
+(this) 14.396 Tj
+-287 TJm
+(state,) 20.7521 Tj
+[1 0 0 1 456.314 584.508] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -456.314 -584.508] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+456.314 584.508 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 540 584.508] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -584.508] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 572.553 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-258 TJm
+(no) 9.9626 Tj
+-257 TJm
+(longer) 25.4544 Tj
+-258 TJm
+(attempt) 29.8878 Tj
+-258 TJm
+(to) 7.7509 Tj
+-258 TJm
+(read) 17.1456 Tj
+-257 TJm
+(data) 16.5977 Tj
+-258 TJm
+(from) 19.3673 Tj
+[1 0 0 1 234.207 572.553] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -234.207 -572.553] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+234.207 572.553 Td
+/F134_0 9.9626 Tf
+(next_in) 41.8429 Tj
+[1 0 0 1 276.051 572.553] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -276.051 -572.553] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+276.051 572.553 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-260 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-257 TJm
+(it) 5.53921 Tj
+-258 TJm
+(will) 15.5018 Tj
+-258 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-257 TJm
+(to) 7.7509 Tj
+-258 TJm
+(write) 20.4731 Tj
+-258 TJm
+(data) 16.5977 Tj
+-258 TJm
+(to) 7.7509 Tj
+[1 0 0 1 407.082 572.553] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -407.082 -572.553] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+407.082 572.553 Td
+/F134_0 9.9626 Tf
+(next_out) 47.8205 Tj
+[1 0 0 1 454.902 572.553] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -454.902 -572.553] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+454.902 572.553 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-666 TJm
+(Because) 33.1954 Tj
+-258 TJm
+(the) 12.1743 Tj
+-258 TJm
+(output) 25.4644 Tj
+72 560.598 Td
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-228 TJm
+(supplied) 33.7633 Tj
+-228 TJm
+(by) 9.9626 Tj
+-229 TJm
+(the) 12.1743 Tj
+-228 TJm
+(user) 16.5977 Tj
+-228 TJm
+(can) 13.8281 Tj
+-228 TJm
+(be) 9.40469 Tj
+-228 TJm
+(arbitrarily) 39.8404 Tj
+-229 TJm
+(sma) 16.0497 Tj
+1 TJm
+(ll,) 8.02986 Tj
+-233 TJm
+(the) 12.1743 Tj
+-228 TJm
+(\002nishing-up) 48.1592 Tj
+-228 TJm
+(operation) 37.6287 Tj
+-229 TJm
+(cannot) 26.5603 Tj
+-228 TJm
+(necessarily) 44.2638 Tj
+-228 TJm
+(be) 9.40469 Tj
+-228 TJm
+(done) 19.3673 Tj
+-228 TJm
+(with) 17.7135 Tj
+-229 TJm
+(a) 4.42339 Tj
+-228 TJm
+(single) 23.8007 Tj
+72 548.643 Td
+(call) 14.386 Tj
+-250 TJm
+(of) 8.29885 Tj
+[1 0 0 1 99.6659 548.643] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -99.6659 -548.643] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+99.6659 548.643 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 183.352 548.643] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -183.352 -548.643] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+183.352 548.643 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 547.108] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -537.146] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 526.725 Td
+/F130_0 9.9626 Tf
+(Instead,) 31.2626 Tj
+-346 TJm
+(the) 12.1743 Tj
+-327 TJm
+(calling) 27.1182 Tj
+-326 TJm
+(program) 33.7533 Tj
+-327 TJm
+(passes) 25.4544 Tj
+[1 0 0 1 218.231 526.725] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -218.231 -526.725] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+218.231 526.725 Td
+/F134_0 9.9626 Tf
+(BZ_FINISH) 53.798 Tj
+[1 0 0 1 272.029 526.725] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -272.029 -526.725] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+275.284 526.725 Td
+/F130_0 9.9626 Tf
+(as) 8.29885 Tj
+-327 TJm
+(an) 9.40469 Tj
+-327 TJm
+(action) 24.3486 Tj
+-326 TJm
+(to) 7.7509 Tj
+[1 0 0 1 338.108 526.725] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -338.108 -526.725] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+338.108 526.725 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 421.795 526.725] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -421.795 -526.725] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+421.795 526.725 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1081 TJm
+(This) 17.7135 Tj
+-326 TJm
+(changes) 32.0895 Tj
+-327 TJm
+(the) 12.1743 Tj
+-327 TJm
+(stream') 29.8778 Tj
+55 TJm
+(s) 3.87545 Tj
+72 514.77 Td
+(state) 18.2614 Tj
+-291 TJm
+(to) 7.7509 Tj
+-290 TJm
+(FINISHING.) 52.2937 Tj
+-581 TJm
+(An) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-291 TJm
+(remaining) 40.3983 Tj
+-290 TJm
+(input) 20.4831 Tj
+-291 TJm
+(\(ie,) 13.0012 Tj
+[1 0 0 1 264.452 514.77] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -264.452 -514.77] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+264.452 514.77 Td
+/F134_0 9.9626 Tf
+(next_in[0) 53.798 Tj
+-600 TJm
+(..) 11.9551 Tj
+-1200 TJm
+(avail_in-1]) 65.7532 Tj
+[1 0 0 1 413.892 514.77] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -413.892 -514.77] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+413.892 514.77 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-291 TJm
+(is) 6.64505 Tj
+-290 TJm
+(compressed) 47.0334 Tj
+-291 TJm
+(and) 14.386 Tj
+-290 TJm
+(transferred) 43.148 Tj
+72 502.814 Td
+(to) 7.7509 Tj
+-421 TJm
+(the) 12.1743 Tj
+-421 TJm
+(output) 25.4644 Tj
+-421 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+55 TJm
+(.) 2.49065 Tj
+-1646 TJm
+(T) 6.08715 Tj
+80 TJm
+(o) 4.9813 Tj
+-421 TJm
+(do) 9.9626 Tj
+-422 TJm
+(this) 14.396 Tj
+1 TJm
+(,) 2.49065 Tj
+[1 0 0 1 222.339 502.814] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -222.339 -502.814] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+222.339 502.814 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 306.025 502.814] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -306.025 -502.814] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+310.22 502.814 Td
+/F130_0 9.9626 Tf
+(must) 19.3773 Tj
+-421 TJm
+(be) 9.40469 Tj
+-421 TJm
+(called) 23.7907 Tj
+-421 TJm
+(repeatedly) 41.4942 Tj
+-421 TJm
+(until) 18.2714 Tj
+-421 TJm
+(all) 9.9626 Tj
+-421 TJm
+(the) 12.1743 Tj
+-421 TJm
+(output) 25.4644 Tj
+-421 TJm
+(has) 13.2801 Tj
+-421 TJm
+(been) 18.8094 Tj
+72 490.859 Td
+(consumed.) 42.889 Tj
+-1397 TJm
+(At) 9.9626 Tj
+-379 TJm
+(that) 14.9439 Tj
+-380 TJm
+(point,) 22.9738 Tj
+[1 0 0 1 188.346 490.859] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -188.346 -490.859] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+188.346 490.859 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 272.033 490.859] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -272.033 -490.859] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+275.813 490.859 Td
+/F130_0 9.9626 Tf
+(returns) 27.6661 Tj
+[1 0 0 1 307.259 490.859] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -307.259 -490.859] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+307.259 490.859 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 384.968 490.859] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -384.968 -490.859] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+384.968 490.859 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-379 TJm
+(and) 14.386 Tj
+-380 TJm
+(the) 12.1743 Tj
+-379 TJm
+(stream') 29.8778 Tj
+55 TJm
+(s) 3.87545 Tj
+-380 TJm
+(state) 18.2614 Tj
+-379 TJm
+(is) 6.64505 Tj
+-380 TJm
+(set) 11.0684 Tj
+-379 TJm
+(back) 18.8094 Tj
+-379 TJm
+(to) 7.7509 Tj
+72 478.904 Td
+(IDLE.) 25.1755 Tj
+[1 0 0 1 99.6662 478.904] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -99.6662 -478.904] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+99.6662 478.904 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressEnd) 101.619 Tj
+[1 0 0 1 201.285 478.904] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -201.285 -478.904] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+203.776 478.904 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-250 TJm
+(then) 17.1556 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(called.) 26.2813 Tj
+[1 0 0 1 72 477.37] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -467.407] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 456.986 Td
+/F130_0 9.9626 Tf
+(Just) 15.5018 Tj
+-380 TJm
+(to) 7.7509 Tj
+-380 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-379 TJm
+(sure) 16.5977 Tj
+-380 TJm
+(the) 12.1743 Tj
+-380 TJm
+(calling) 27.1182 Tj
+-380 TJm
+(program) 33.7533 Tj
+-379 TJm
+(does) 18.2614 Tj
+-380 TJm
+(not) 12.7322 Tj
+-380 TJm
+(cheat,) 23.5117 Tj
+-412 TJm
+(the) 12.1743 Tj
+-380 TJm
+(library) 26.5603 Tj
+-380 TJm
+(mak) 17.1556 Tj
+10 TJm
+(es) 8.29885 Tj
+-379 TJm
+(a) 4.42339 Tj
+-380 TJm
+(note) 17.1556 Tj
+-380 TJm
+(of) 8.29885 Tj
+[1 0 0 1 415.708 456.986] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -415.708 -456.986] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+415.708 456.986 Td
+/F134_0 9.9626 Tf
+(avail_in) 47.8205 Tj
+[1 0 0 1 463.528 456.986] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -463.528 -456.986] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+467.312 456.986 Td
+/F130_0 9.9626 Tf
+(at) 7.193 Tj
+-380 TJm
+(the) 12.1743 Tj
+-380 TJm
+(time) 17.7135 Tj
+-379 TJm
+(of) 8.29885 Tj
+-380 TJm
+(the) 12.1743 Tj
+72 445.031 Td
+(\002rst) 15.5018 Tj
+-286 TJm
+(call) 14.386 Tj
+-286 TJm
+(t) 2.7696 Tj
+1 TJm
+(o) 4.9813 Tj
+[1 0 0 1 118.179 445.031] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -118.179 -445.031] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+118.179 445.031 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 201.865 445.031] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -201.865 -445.031] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+204.713 445.031 Td
+/F130_0 9.9626 Tf
+(which) 24.3486 Tj
+-286 TJm
+(has) 13.2801 Tj
+[1 0 0 1 248.035 445.031] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -248.035 -445.031] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+248.035 445.031 Td
+/F134_0 9.9626 Tf
+(BZ_FINISH) 53.798 Tj
+[1 0 0 1 301.833 445.031] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -301.833 -445.031] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+304.68 445.031 Td
+/F130_0 9.9626 Tf
+(as) 8.29885 Tj
+-286 TJm
+(an) 9.40469 Tj
+-286 TJm
+(action) 24.3486 Tj
+-285 TJm
+(\(ie,) 13.0012 Tj
+-295 TJm
+(at) 7.193 Tj
+-286 TJm
+(the) 12.1743 Tj
+-286 TJm
+(time) 17.7135 Tj
+-285 TJm
+(the) 12.1743 Tj
+-286 TJm
+(program) 33.7533 Tj
+-286 TJm
+(has) 13.2801 Tj
+-286 TJm
+(announced) 43.158 Tj
+-285 TJm
+(its) 9.41466 Tj
+72 433.076 Td
+(intention) 35.427 Tj
+-292 TJm
+(to) 7.7509 Tj
+-292 TJm
+(not) 12.7322 Tj
+-291 TJm
+(supply) 26.5703 Tj
+-292 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-292 TJm
+(more) 20.4731 Tj
+-292 TJm
+(input\).) 26.2913 Tj
+-870 TJm
+(By) 11.6264 Tj
+-292 TJm
+(comparing) 42.61 Tj
+-292 TJm
+(this) 14.396 Tj
+-292 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+-291 TJm
+(with) 17.7135 Tj
+-292 TJm
+(that) 14.9439 Tj
+-292 TJm
+(of) 8.29885 Tj
+[1 0 0 1 392.862 433.076] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -392.862 -433.076] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+392.862 433.076 Td
+/F134_0 9.9626 Tf
+(avail_in) 47.8205 Tj
+[1 0 0 1 440.682 433.076] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -440.682 -433.076] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+443.589 433.076 Td
+/F130_0 9.9626 Tf
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-292 TJm
+(subsequent) 44.2738 Tj
+-292 TJm
+(calls) 18.2614 Tj
+-291 TJm
+(to) 7.7509 Tj
+[1 0 0 1 72 421.121] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -421.121] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 421.121 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 155.686 421.121] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.686 -421.121] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+155.686 421.121 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-247 TJm
+(the) 12.1743 Tj
+-247 TJm
+(library) 26.5603 Tj
+-246 TJm
+(can) 13.8281 Tj
+-247 TJm
+(detect) 23.7907 Tj
+-246 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-247 TJm
+(att) 9.9626 Tj
+1 TJm
+(empts) 23.8007 Tj
+-247 TJm
+(to) 7.7509 Tj
+-246 TJm
+(slip) 14.396 Tj
+-247 TJm
+(in) 7.7509 Tj
+-246 TJm
+(more) 20.4731 Tj
+-247 TJm
+(data) 16.5977 Tj
+-246 TJm
+(to) 7.7509 Tj
+-247 TJm
+(compress.) 40.1194 Tj
+-617 TJm
+(An) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-247 TJm
+(calls) 18.2614 Tj
+-246 TJm
+(for) 11.6164 Tj
+-247 TJm
+(which) 24.3486 Tj
+-246 TJm
+(this) 14.396 Tj
+-247 TJm
+(is) 6.64505 Tj
+72 409.166 Td
+(detected) 33.1954 Tj
+-250 TJm
+(will) 15.5018 Tj
+-250 TJm
+(return) 23.7907 Tj
+[1 0 0 1 151.959 409.166] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -151.959 -409.166] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+151.959 409.166 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+[1 0 0 1 253.578 409.166] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -253.578 -409.166] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+253.578 409.166 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-500 TJm
+(This) 17.7135 Tj
+-250 TJm
+(indicates) 35.417 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(programming) 54.2364 Tj
+-250 TJm
+(mistak) 26.5703 Tj
+10 TJm
+(e) 4.42339 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(should) 26.5703 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(corrected.) 39.5515 Tj
+[1 0 0 1 72 407.009] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -397.046] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 387.248 Td
+/F130_0 9.9626 Tf
+(Instead) 28.772 Tj
+-224 TJm
+(of) 8.29885 Tj
+-223 TJm
+(asking) 26.0123 Tj
+-224 TJm
+(to) 7.7509 Tj
+-223 TJm
+(\002nish,) 24.6375 Tj
+-229 TJm
+(the) 12.1743 Tj
+-224 TJm
+(calling) 27.1182 Tj
+-223 TJm
+(program) 33.7533 Tj
+-224 TJm
+(may) 17.1556 Tj
+-224 TJm
+(ask) 13.2801 Tj
+[1 0 0 1 293.282 387.248] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -293.282 -387.248] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+293.282 387.248 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 376.968 387.248] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -376.968 -387.248] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+379.196 387.248 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-224 TJm
+(tak) 12.1743 Tj
+10 TJm
+(e) 4.42339 Tj
+-223 TJm
+(all) 9.9626 Tj
+-224 TJm
+(the) 12.1743 Tj
+-223 TJm
+(remaining) 40.3983 Tj
+-224 TJm
+(input,) 22.9738 Tj
+-229 TJm
+(compress) 37.6287 Tj
+72 375.293 Td
+(it) 5.53921 Tj
+-278 TJm
+(and) 14.386 Tj
+-278 TJm
+(terminate) 37.6287 Tj
+-278 TJm
+(the) 12.1743 Tj
+-278 TJm
+(current) 28.2141 Tj
+-277 TJm
+(\(Burro) 26.5603 Tj
+25 TJm
+(ws-Wheeler\)) 51.4469 Tj
+-278 TJm
+(compression) 50.3609 Tj
+-278 TJm
+(block.) 24.6275 Tj
+-787 TJm
+(Th) 11.0684 Tj
+-1 TJm
+(i) 2.7696 Tj
+1 TJm
+(s) 3.87545 Tj
+-278 TJm
+(could) 22.1369 Tj
+-278 TJm
+(be) 9.40469 Tj
+-278 TJm
+(useful) 24.3486 Tj
+-278 TJm
+(for) 11.6164 Tj
+-278 TJm
+(error) 19.3573 Tj
+-278 TJm
+(control) 28.224 Tj
+-278 TJm
+(purposes.) 37.9077 Tj
+72 363.338 Td
+(The) 15.4918 Tj
+-328 TJm
+(mechanism) 45.3796 Tj
+-328 TJm
+(is) 6.64505 Tj
+-328 TJm
+(analogous) 40.3983 Tj
+-328 TJm
+(to) 7.7509 Tj
+-328 TJm
+(that) 14.9439 Tj
+-328 TJm
+(for) 11.6164 Tj
+-328 TJm
+(\002nishing:) 37.6487 Tj
+-466 TJm
+(call) 14.386 Tj
+[1 0 0 1 297.049 363.337] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -297.049 -363.337] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+297.049 363.337 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 380.735 363.337] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -380.735 -363.337] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+384.003 363.337 Td
+/F130_0 9.9626 Tf
+(with) 17.7135 Tj
+-328 TJm
+(an) 9.40469 Tj
+-328 TJm
+(action) 24.3486 Tj
+-328 TJm
+(of) 8.29885 Tj
+[1 0 0 1 456.841 363.337] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -456.841 -363.337] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+456.841 363.337 Td
+/F134_0 9.9626 Tf
+(BZ_FLUSH) 47.8205 Tj
+[1 0 0 1 504.662 363.337] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -504.662 -363.337] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+504.662 363.337 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-328 TJm
+(remo) 20.4731 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+72 351.382 Td
+(output) 25.4644 Tj
+-445 TJm
+(data,) 19.0883 Tj
+-494 TJm
+(and) 14.386 Tj
+-446 TJm
+(persist) 26.0123 Tj
+-445 TJm
+(with) 17.7135 Tj
+-445 TJm
+(the) 12.1743 Tj
+[1 0 0 1 213.94 351.382] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -213.94 -351.382] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+213.94 351.382 Td
+/F134_0 9.9626 Tf
+(BZ_FLUSH) 47.8205 Tj
+[1 0 0 1 261.761 351.382] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -261.761 -351.382] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+266.195 351.382 Td
+/F130_0 9.9626 Tf
+(action) 24.3486 Tj
+-445 TJm
+(until) 18.2714 Tj
+-445 TJm
+(the) 12.1743 Tj
+-446 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+[1 0 0 1 360.062 351.382] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -360.062 -351.382] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+360.062 351.382 Td
+/F134_0 9.9626 Tf
+(BZ_RUN) 35.8654 Tj
+[1 0 0 1 395.928 351.382] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -395.928 -351.382] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+400.362 351.382 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-445 TJm
+(returned.) 35.686 Tj
+-1792 TJm
+(As) 11.0684 Tj
+-445 TJm
+(with) 17.7135 Tj
+-445 TJm
+(\002nishing,) 37.3697 Tj
+[1 0 0 1 72 339.427] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -339.427] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 339.427 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 155.686 339.427] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.686 -339.427] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+158.177 339.427 Td
+/F130_0 9.9626 Tf
+(detects) 27.6661 Tj
+-250 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-250 TJm
+(attempt) 29.8878 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vide) 17.1556 Tj
+-250 TJm
+(more) 20.4731 Tj
+-250 TJm
+(input) 20.4831 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(once) 18.8094 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(\003ush) 19.3773 Tj
+-250 TJm
+(has) 13.2801 Tj
+-250 TJm
+(be) 9.40469 Tj
+15 TJm
+(gun.) 17.4346 Tj
+[1 0 0 1 72 337.27] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -327.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 317.509 Td
+/F130_0 9.9626 Tf
+(Once) 21.0211 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(\003ush) 19.3773 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(complete,) 39.0135 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(stream) 26.5603 Tj
+-250 TJm
+(returns) 27.6661 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(normal) 28.224 Tj
+-250 TJm
+(R) 6.64505 Tj
+40 TJm
+(UNNING) 39.2825 Tj
+-250 TJm
+(state.) 20.7521 Tj
+[1 0 0 1 72 315.353] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -305.39] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 295.591 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-344 TJm
+(all) 9.9626 Tj
+-343 TJm
+(sounds) 27.6761 Tj
+-344 TJm
+(pretty) 23.2427 Tj
+-344 TJm
+(comple) 29.3299 Tj
+15 TJm
+(x,) 7.47195 Tj
+-367 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-344 TJm
+(isn') 14.9439 Tj
+18 TJm
+(t) 2.7696 Tj
+-344 TJm
+(really) 22.6848 Tj
+65 TJm
+(.) 2.49065 Tj
+-1182 TJm
+(Here') 22.6749 Tj
+55 TJm
+(s) 3.87545 Tj
+-344 TJm
+(a) 4.42339 Tj
+-344 TJm
+(table) 19.3673 Tj
+-343 TJm
+(which) 24.3486 Tj
+-344 TJm
+(sho) 13.8381 Tj
+25 TJm
+(ws) 11.0684 Tj
+-344 TJm
+(which) 24.3486 Tj
+-344 TJm
+(actions) 28.224 Tj
+-343 TJm
+(are) 12.1643 Tj
+-344 TJm
+(allo) 14.9439 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-344 TJm
+(in) 7.7509 Tj
+-344 TJm
+(each) 18.2515 Tj
+72 283.636 Td
+(state,) 20.7521 Tj
+-281 TJm
+(what) 19.3673 Tj
+-274 TJm
+(action) 24.3486 Tj
+-275 TJm
+(will) 15.5018 Tj
+-274 TJm
+(be) 9.40469 Tj
+-275 TJm
+(tak) 12.1743 Tj
+10 TJm
+(en,) 11.8953 Tj
+-280 TJm
+(what) 19.3673 Tj
+-275 TJm
+(the) 12.1743 Tj
+-274 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-275 TJm
+(state) 18.2614 Tj
+-274 TJm
+(is,) 9.1357 Tj
+-281 TJm
+(and) 14.386 Tj
+-274 TJm
+(what) 19.3673 Tj
+-275 TJm
+(the) 12.1743 Tj
+-275 TJm
+(non-error) 37.6188 Tj
+-274 TJm
+(return) 23.7907 Tj
+-275 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues) 20.4731 Tj
+-274 TJm
+(are.) 14.655 Tj
+-767 TJm
+(Note) 19.3673 Tj
+-275 TJm
+(that) 14.9439 Tj
+-274 TJm
+(you) 14.9439 Tj
+-275 TJm
+(can') 17.1456 Tj
+18 TJm
+(t) 2.7696 Tj
+72 271.681 Td
+(e) 4.42339 Tj
+15 TJm
+(xplicitly) 33.2153 Tj
+-347 TJm
+(ask) 13.2801 Tj
+-348 TJm
+(what) 19.3673 Tj
+-347 TJm
+(state) 18.2614 Tj
+-348 TJm
+(the) 12.1743 Tj
+-347 TJm
+(stream) 26.5603 Tj
+-348 TJm
+(is) 6.64505 Tj
+-347 TJm
+(in,) 10.2416 Tj
+-372 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-347 TJm
+(nor) 13.2801 Tj
+-348 TJm
+(do) 9.9626 Tj
+-347 TJm
+(you) 14.9439 Tj
+-348 TJm
+(need) 18.8094 Tj
+-347 TJm
+(to) 7.7509 Tj
+-348 TJm
+(--) 6.63509 Tj
+-347 TJm
+(it) 5.53921 Tj
+-348 TJm
+(can) 13.8281 Tj
+-347 TJm
+(be) 9.40469 Tj
+-347 TJm
+(inferred) 31.5316 Tj
+-348 TJm
+(from) 19.3673 Tj
+-347 TJm
+(the) 12.1743 Tj
+-348 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues) 20.4731 Tj
+-347 TJm
+(returned) 33.1954 Tj
+-348 TJm
+(by) 9.9626 Tj
+[1 0 0 1 72 259.726] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -259.726] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 259.726 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 155.686 259.726] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.686 -259.726] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+155.686 259.726 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 258.192] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -207.34] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.8518] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.8518 Td
+/F130_0 9.9626 Tf
+(14) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 18 18
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -595.402] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 573.848 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 570.261] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(IDLE/any) 47.8205 Tj
+98.4879 699.676 Td
+(Illegal.) 47.8205 Tj
+-852 TJm
+(IDLE) 23.9102 Tj
+-426 TJm
+(state) 29.8878 Tj
+-426 TJm
+(only) 23.9102 Tj
+-426 TJm
+(exists) 35.8654 Tj
+-426 TJm
+(after) 29.8878 Tj
+-426 TJm
+(BZ2_bzCompressEnd) 101.619 Tj
+-426 TJm
+(or) 11.9551 Tj
+98.4879 687.721 Td
+(before) 35.8654 Tj
+-426 TJm
+(BZ2_bzCompressInit.) 113.574 Tj
+98.4879 675.766 Td
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+90 651.856 Td
+(RUNNING/BZ_RUN) 83.6858 Tj
+98.4879 639.9 Td
+(Compress) 47.8205 Tj
+-426 TJm
+(from) 23.9102 Tj
+-426 TJm
+(next_in) 41.8429 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(next_out) 47.8205 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(much) 23.9102 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(possible.) 53.798 Tj
+98.4879 627.945 Td
+(Next) 23.9102 Tj
+-426 TJm
+(state) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(RUNNING) 41.8429 Tj
+98.4879 615.99 Td
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_RUN_OK) 53.798 Tj
+90 592.08 Td
+(RUNNING/BZ_FLUSH) 95.641 Tj
+98.4879 580.125 Td
+(Remember) 47.8205 Tj
+-426 TJm
+(current) 41.8429 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(next_in.) 47.8205 Tj
+-426 TJm
+(Compress) 47.8205 Tj
+-426 TJm
+(from) 23.9102 Tj
+-426 TJm
+(next_in) 41.8429 Tj
+98.4879 568.169 Td
+(to) 11.9551 Tj
+-426 TJm
+(next_out) 47.8205 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(much) 23.9102 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(possible,) 53.798 Tj
+-426 TJm
+(but) 17.9327 Tj
+-426 TJm
+(do) 11.9551 Tj
+-426 TJm
+(not) 17.9327 Tj
+-426 TJm
+(accept) 35.8654 Tj
+-426 TJm
+(any) 17.9327 Tj
+-426 TJm
+(more) 23.9102 Tj
+-426 TJm
+(input.) 35.8654 Tj
+98.4879 556.214 Td
+(Next) 23.9102 Tj
+-426 TJm
+(state) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(FLUSHING) 47.8205 Tj
+98.4879 544.259 Td
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_FLUSH_OK) 65.7532 Tj
+90 520.349 Td
+(RUNNING/BZ_FINISH) 101.619 Tj
+98.4879 508.394 Td
+(Remember) 47.8205 Tj
+-426 TJm
+(current) 41.8429 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(next_in.) 47.8205 Tj
+-426 TJm
+(Compress) 47.8205 Tj
+-426 TJm
+(from) 23.9102 Tj
+-426 TJm
+(next_in) 41.8429 Tj
+98.4879 496.438 Td
+(to) 11.9551 Tj
+-426 TJm
+(next_out) 47.8205 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(much) 23.9102 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(possible,) 53.798 Tj
+-426 TJm
+(but) 17.9327 Tj
+-426 TJm
+(do) 11.9551 Tj
+-426 TJm
+(not) 17.9327 Tj
+-426 TJm
+(accept) 35.8654 Tj
+-426 TJm
+(any) 17.9327 Tj
+-426 TJm
+(more) 23.9102 Tj
+-426 TJm
+(input.) 35.8654 Tj
+98.4879 484.483 Td
+(Next) 23.9102 Tj
+-426 TJm
+(state) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(FINISHING) 53.798 Tj
+98.4879 472.528 Td
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_FINISH_OK) 71.7307 Tj
+90 448.618 Td
+(FLUSHING/BZ_FLUSH) 101.619 Tj
+98.4879 436.663 Td
+(Compress) 47.8205 Tj
+-426 TJm
+(from) 23.9102 Tj
+-426 TJm
+(next_in) 41.8429 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(next_out) 47.8205 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(much) 23.9102 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(possible,) 53.798 Tj
+98.4879 424.707 Td
+(but) 17.9327 Tj
+-426 TJm
+(do) 11.9551 Tj
+-426 TJm
+(not) 17.9327 Tj
+-426 TJm
+(accept) 35.8654 Tj
+-426 TJm
+(any) 17.9327 Tj
+-426 TJm
+(more) 23.9102 Tj
+-426 TJm
+(input.) 35.8654 Tj
+98.4879 412.752 Td
+(If) 11.9551 Tj
+-426 TJm
+(all) 17.9327 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(existing) 47.8205 Tj
+-426 TJm
+(input) 29.8878 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(used) 23.9102 Tj
+-426 TJm
+(up) 11.9551 Tj
+-426 TJm
+(and) 17.9327 Tj
+-426 TJm
+(all) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+98.4879 400.797 Td
+(output) 35.8654 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(removed) 41.8429 Tj
+106.976 388.842 Td
+(Next) 23.9102 Tj
+-426 TJm
+(state) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(RUNNING;) 47.8205 Tj
+-426 TJm
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_RUN_OK) 53.798 Tj
+98.4879 376.887 Td
+(else) 23.9102 Tj
+106.976 364.932 Td
+(Next) 23.9102 Tj
+-426 TJm
+(state) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(FLUSHING;) 53.798 Tj
+-426 TJm
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_FLUSH_OK) 65.7532 Tj
+90 341.021 Td
+(FLUSHING/other) 83.6858 Tj
+98.4879 329.066 Td
+(Illegal.) 47.8205 Tj
+98.4879 317.111 Td
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+90 293.201 Td
+(FINISHING/BZ_FINISH) 113.574 Tj
+98.4879 281.245 Td
+(Compress) 47.8205 Tj
+-426 TJm
+(from) 23.9102 Tj
+-426 TJm
+(next_in) 41.8429 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(next_out) 47.8205 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(much) 23.9102 Tj
+-426 TJm
+(as) 11.9551 Tj
+-426 TJm
+(possible,) 53.798 Tj
+98.4879 269.29 Td
+(but) 17.9327 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(not) 17.9327 Tj
+-426 TJm
+(accept) 35.8654 Tj
+-426 TJm
+(any) 17.9327 Tj
+-426 TJm
+(more) 23.9102 Tj
+-426 TJm
+(input.) 35.8654 Tj
+98.4879 257.335 Td
+(If) 11.9551 Tj
+-426 TJm
+(all) 17.9327 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(existing) 47.8205 Tj
+-426 TJm
+(input) 29.8878 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(used) 23.9102 Tj
+-426 TJm
+(up) 11.9551 Tj
+-426 TJm
+(and) 17.9327 Tj
+-426 TJm
+(all) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+98.4879 245.38 Td
+(output) 35.8654 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(removed) 41.8429 Tj
+106.976 233.425 Td
+(Next) 23.9102 Tj
+-426 TJm
+(state) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(IDLE;) 29.8878 Tj
+-426 TJm
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_STREAM_END) 77.7083 Tj
+98.4879 221.47 Td
+(else) 23.9102 Tj
+106.976 209.514 Td
+(Next) 23.9102 Tj
+-426 TJm
+(state) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(FINISHING;) 59.7756 Tj
+-426 TJm
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_FINISH_OK) 71.7307 Tj
+90 185.604 Td
+(FINISHING/other) 89.6634 Tj
+98.4879 173.649 Td
+(Illegal.) 47.8205 Tj
+98.4879 161.694 Td
+(Return) 35.8654 Tj
+-426 TJm
+(value) 29.8878 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+[1 0 0 1 72 146.152] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -136.189] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 124.234 Td
+/F130_0 9.9626 Tf
+(That) 18.2614 Tj
+-250 TJm
+(still) 14.9539 Tj
+-250 TJm
+(looks) 21.589 Tj
+-250 TJm
+(complicated?) 53.1206 Tj
+-620 TJm
+(W) 9.40469 Tj
+80 TJm
+(ell,) 12.4533 Tj
+-250 TJm
+(f) 3.31755 Tj
+10 TJm
+(air) 10.5105 Tj
+-250 TJm
+(enough.) 31.8205 Tj
+-620 TJm
+(The) 15.4918 Tj
+-250 TJm
+(usual) 21.031 Tj
+-250 TJm
+(sequence) 36.5129 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(calls) 18.2614 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(compressing) 50.3609 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(load) 17.1556 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(is:) 9.41466 Tj
+[1 0 0 1 72 122.077] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -29.7236] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 7.3724 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -79.3724 -92.3537] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+79.3724 92.3537 Td
+/F130_0 9.9626 Tf
+(1.) 7.47195 Tj
+[1 0 0 1 86.8444 92.3537] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 3.0884 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -91.9253 -92.3537] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+91.9253 92.3537 Td
+/F130_0 9.9626 Tf
+(Get) 14.386 Tj
+-250 TJm
+(started) 26.5603 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 158.056 92.3537] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -158.056 -92.3537] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+158.056 92.3537 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 265.653 92.3537] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -265.653 -92.3537] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+265.653 92.3537 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 268.144 92.3537] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -196.144 -41.5019] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.893 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(15) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 19 19
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -31.5168] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 7.3724 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -79.3724 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+79.3724 710.037 Td
+/F130_0 9.9626 Tf
+(2.) 7.47195 Tj
+[1 0 0 1 86.8444 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 3.0884 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -91.9253 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+91.9253 710.037 Td
+/F130_0 9.9626 Tf
+(Sho) 15.5018 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-240 TJm
+(data) 16.5977 Tj
+-240 TJm
+(in) 7.7509 Tj
+-241 TJm
+(and) 14.386 Tj
+-240 TJm
+(shlurp) 24.9065 Tj
+-240 TJm
+(out) 12.7322 Tj
+-240 TJm
+(its) 9.41466 Tj
+-240 TJm
+(compressed) 47.0334 Tj
+-241 TJm
+(form) 19.3673 Tj
+-240 TJm
+(using) 21.589 Tj
+-240 TJm
+(zero) 17.1456 Tj
+-240 TJm
+(or) 8.29885 Tj
+-240 TJm
+(more) 20.4731 Tj
+-241 TJm
+(calls) 18.2614 Tj
+-240 TJm
+(of) 8.29885 Tj
+[1 0 0 1 401.454 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -401.454 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+401.454 710.037 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 485.14 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -485.14 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+487.533 710.037 Td
+/F130_0 9.9626 Tf
+(with) 17.7135 Tj
+-240 TJm
+(action) 24.3486 Tj
+-240 TJm
+(=) 5.61891 Tj
+[1 0 0 1 91.9253 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -91.9253 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+91.9253 698.082 Td
+/F134_0 9.9626 Tf
+(BZ_RUN) 35.8654 Tj
+[1 0 0 1 127.791 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -127.791 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+127.791 698.082 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 130.281 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -58.2814 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 7.3724 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -79.3724 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+79.3724 676.164 Td
+/F130_0 9.9626 Tf
+(3.) 7.47195 Tj
+[1 0 0 1 86.8444 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 3.0884 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -91.9253 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+91.9253 676.164 Td
+/F130_0 9.9626 Tf
+(Finish) 24.9165 Tj
+-242 TJm
+(up.) 12.4533 Tj
+-307 TJm
+(Repeatedly) 44.8217 Tj
+-241 TJm
+(call) 14.386 Tj
+[1 0 0 1 198.784 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -198.784 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+198.784 676.164 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 282.471 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -282.471 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+284.878 676.164 Td
+/F130_0 9.9626 Tf
+(with) 17.7135 Tj
+-242 TJm
+(action) 24.3486 Tj
+-241 TJm
+(=) 5.61891 Tj
+[1 0 0 1 339.78 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -339.78 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+339.78 676.164 Td
+/F134_0 9.9626 Tf
+(BZ_FINISH) 53.798 Tj
+[1 0 0 1 393.579 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -393.579 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+393.579 676.164 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-242 TJm
+(cop) 14.386 Tj
+10 TJm
+(ying) 17.7135 Tj
+-241 TJm
+(out) 12.7322 Tj
+-242 TJm
+(the) 12.1743 Tj
+-242 TJm
+(compres) 33.7533 Tj
+1 TJm
+(sed) 13.2801 Tj
+-242 TJm
+(output,) 27.9551 Tj
+91.9253 664.209 Td
+(until) 18.2714 Tj
+[1 0 0 1 112.687 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -112.687 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+112.687 664.209 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 190.396 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -190.396 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+192.886 664.209 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(returned.) 35.686 Tj
+[1 0 0 1 237.708 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -165.708 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 7.3724 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -79.3724 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+79.3724 642.291 Td
+/F130_0 9.9626 Tf
+(4.) 7.47195 Tj
+[1 0 0 1 86.8444 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 3.0884 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -91.9253 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+91.9253 642.291 Td
+/F130_0 9.9626 Tf
+(Close) 22.6948 Tj
+-250 TJm
+(up) 9.9626 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(go) 9.9626 Tj
+-250 TJm
+(home.) 24.6275 Tj
+-620 TJm
+(Call) 16.6077 Tj
+[1 0 0 1 208.796 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -208.796 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+208.796 642.291 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressEnd) 101.619 Tj
+[1 0 0 1 310.415 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -310.415 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+310.415 642.291 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 312.906 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -240.906 -12.1195] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -630.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 620.374 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-269 TJm
+(the) 12.1743 Tj
+-270 TJm
+(data) 16.5977 Tj
+-269 TJm
+(you) 14.9439 Tj
+-270 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-269 TJm
+(to) 7.7509 Tj
+-270 TJm
+(compress) 37.6287 Tj
+-269 TJm
+(\002ts) 12.1843 Tj
+-270 TJm
+(into) 15.5018 Tj
+-269 TJm
+(your) 18.2614 Tj
+-270 TJm
+(input) 20.4831 Tj
+-269 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-270 TJm
+(all) 9.9626 Tj
+-269 TJm
+(at) 7.193 Tj
+-270 TJm
+(once,) 21.3 Tj
+-274 TJm
+(you) 14.9439 Tj
+-269 TJm
+(can) 13.8281 Tj
+-270 TJm
+(skip) 16.6077 Tj
+-269 TJm
+(the) 12.1743 Tj
+-270 TJm
+(calls) 18.2614 Tj
+-269 TJm
+(of) 8.29885 Tj
+[1 0 0 1 456.314 620.374] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -456.314 -620.374] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+456.314 620.374 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+72 608.418 Td
+(\() 5.97756 Tj
+-600 TJm
+(...,) 23.9102 Tj
+-600 TJm
+(BZ_RUN) 35.8654 Tj
+-600 TJm
+(\)) 5.97756 Tj
+[1 0 0 1 161.664 608.418] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.664 -608.418] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+164.154 608.418 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+-250 TJm
+(just) 14.396 Tj
+-250 TJm
+(do) 9.9626 Tj
+-250 TJm
+(the) 12.1743 Tj
+[1 0 0 1 225.036 608.418] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -225.036 -608.418] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+225.036 608.418 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+-600 TJm
+(\() 5.97756 Tj
+-600 TJm
+(...,) 23.9102 Tj
+-600 TJm
+(BZ_FINISH) 53.798 Tj
+-600 TJm
+(\)) 5.97756 Tj
+[1 0 0 1 422.296 608.418] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -422.296 -608.418] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+424.786 608.418 Td
+/F130_0 9.9626 Tf
+(calls.) 20.7521 Tj
+[1 0 0 1 72 606.262] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -596.299] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 586.501 Td
+/F130_0 9.9626 Tf
+(All) 12.7322 Tj
+-278 TJm
+(required) 33.1954 Tj
+-277 TJm
+(memory) 33.2053 Tj
+-278 TJm
+(is) 6.64505 Tj
+-277 TJm
+(allocated) 35.965 Tj
+-278 TJm
+(by) 9.9626 Tj
+[1 0 0 1 220.295 586.501] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -220.295 -586.501] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+220.295 586.501 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 327.891 586.501] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -327.891 -586.501] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+327.891 586.501 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-785 TJm
+(The) 15.4918 Tj
+-278 TJm
+(compression) 50.3609 Tj
+-277 TJm
+(library) 26.5603 Tj
+-278 TJm
+(can) 13.8281 Tj
+-277 TJm
+(accept) 25.4445 Tj
+-278 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-277 TJm
+(data) 16.5977 Tj
+-278 TJm
+(at) 7.193 Tj
+-278 TJm
+(all) 9.9626 Tj
+72 574.545 Td
+(\(ob) 13.2801 Tj
+15 TJm
+(viously\).) 35.1481 Tj
+-612 TJm
+(So) 10.5205 Tj
+-238 TJm
+(you) 14.9439 Tj
+-237 TJm
+(shouldn') 34.8691 Tj
+18 TJm
+(t) 2.7696 Tj
+-238 TJm
+(get) 12.1743 Tj
+-238 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-237 TJm
+(error) 19.3573 Tj
+-238 TJm
+(return) 23.7907 Tj
+-238 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues) 20.4731 Tj
+-238 TJm
+(from) 19.3673 Tj
+-237 TJm
+(the) 12.1743 Tj
+[1 0 0 1 339.287 574.545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -339.287 -574.545] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+339.287 574.545 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 422.973 574.545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -422.973 -574.545] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+425.342 574.545 Td
+/F130_0 9.9626 Tf
+(calls.) 20.7521 Tj
+-612 TJm
+(If) 6.63509 Tj
+-238 TJm
+(you) 14.9439 Tj
+-237 TJm
+(do,) 12.4533 Tj
+-240 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-238 TJm
+(will) 15.5018 Tj
+-238 TJm
+(be) 9.40469 Tj
+[1 0 0 1 72 562.59] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -562.59] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 562.59 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+[1 0 0 1 173.619 562.59] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -173.619 -562.59] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+173.619 562.59 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(indicate) 31.5416 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug) 9.9626 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(your) 18.2614 Tj
+-250 TJm
+(programming.) 56.727 Tj
+[1 0 0 1 72 560.433] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -550.471] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 540.673 Td
+/F130_0 9.9626 Tf
+(T) 6.08715 Tj
+35 TJm
+(ri) 6.08715 Tj
+25 TJm
+(vial) 14.9439 Tj
+-250 TJm
+(other) 20.4731 Tj
+-250 TJm
+(possible) 32.6574 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 538.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -36.8617] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 35.8655 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 32.2789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -529.151] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 529.151 Td
+/F134_0 9.9626 Tf
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 517.196 Td
+(if) 11.9551 Tj
+-426 TJm
+(strm) 23.9102 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL,) 29.8878 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(strm->s) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+[1 0 0 1 72 501.654] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -491.691] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 471.033 Td
+/F122_0 17.2154 Tf
+(3.3.3.) 43.0729 Tj
+[1 0 0 1 119.858 471.033] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -471.033] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 471.033 Td
+/F392_0 17.2154 Tf
+(BZ2_bzCompressEnd) 175.597 Tj
+[1 0 0 1 295.455 471.033] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -223.455 -2.3326] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -459.335] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 459.335 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzCompressEnd) 101.619 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bz_stream) 53.798 Tj
+286.303 457.592 Td
+(*) 5.97756 Tj
+292.281 459.335 Td
+(strm) 23.9102 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 443.793] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5493] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -433.831] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 421.876 Td
+/F130_0 9.9626 Tf
+(Releases) 34.8591 Tj
+-250 TJm
+(all) 9.9626 Tj
+-250 TJm
+(memory) 33.2053 Tj
+-250 TJm
+(associated) 40.9463 Tj
+-250 TJm
+(with) 17.7135 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(compression) 50.3609 Tj
+-250 TJm
+(stream.) 29.0509 Tj
+[1 0 0 1 72 419.719] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -409.756] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 399.958 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 399.858] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -36.8618] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 35.8655 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 32.2789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -390.493] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 390.493 Td
+/F134_0 9.9626 Tf
+(BZ_PARAM_ERROR) 83.6858 Tj
+-852 TJm
+(if) 11.9551 Tj
+-426 TJm
+(strm) 23.9102 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(strm->s) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+90 378.538 Td
+(BZ_OK) 29.8878 Tj
+-4686 TJm
+(otherwise) 53.798 Tj
+[1 0 0 1 72 362.996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -353.034] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 332.375 Td
+/F122_0 17.2154 Tf
+(3.3.4.) 43.0729 Tj
+[1 0 0 1 119.858 332.375] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -332.375] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 332.375 Td
+/F392_0 17.2154 Tf
+(BZ2_bzDecompressInit) 206.585 Tj
+[1 0 0 1 326.443 332.375] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -254.443 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -320.678] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 320.678 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzDecompressInit) 119.551 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bz_stream) 53.798 Tj
+304.236 318.934 Td
+(*) 5.97756 Tj
+310.214 320.678 Td
+(strm,) 29.8878 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(verbosity,) 59.7756 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(small) 29.8878 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 305.136] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -295.173] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 283.218 Td
+/F130_0 9.9626 Tf
+(Prepares) 34.3012 Tj
+-351 TJm
+(for) 11.6164 Tj
+-351 TJm
+(decompression.) 62.2563 Tj
+-1228 TJm
+(As) 11.0684 Tj
+-351 TJm
+(with) 17.7135 Tj
+[1 0 0 1 235.177 283.218] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -235.177 -283.218] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+235.177 283.218 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 342.773 283.218] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.773 -283.218] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+342.773 283.218 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-377 TJm
+(a) 4.42339 Tj
+[1 0 0 1 356.937 283.218] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -356.937 -283.218] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+356.937 283.218 Td
+/F134_0 9.9626 Tf
+(bz_stream) 53.798 Tj
+[1 0 0 1 410.736 283.218] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -410.736 -283.218] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+414.235 283.218 Td
+/F130_0 9.9626 Tf
+(record) 25.4445 Tj
+-351 TJm
+(should) 26.5703 Tj
+-351 TJm
+(be) 9.40469 Tj
+-352 TJm
+(allocated) 35.965 Tj
+-351 TJm
+(and) 14.386 Tj
+72 271.263 Td
+(initialised) 39.3025 Tj
+-306 TJm
+(before) 25.4445 Tj
+-305 TJm
+(the) 12.1743 Tj
+-306 TJm
+(call.) 16.8766 Tj
+-953 TJm
+(Fields) 24.3586 Tj
+[1 0 0 1 211.833 271.263] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -211.833 -271.263] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+211.833 271.263 Td
+/F134_0 9.9626 Tf
+(bzalloc) 41.8429 Tj
+[1 0 0 1 253.676 271.263] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -253.676 -271.263] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+253.676 271.263 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 259.35 271.263] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -259.35 -271.263] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+259.35 271.263 Td
+/F134_0 9.9626 Tf
+(bzfree) 35.8654 Tj
+[1 0 0 1 295.215 271.263] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -295.215 -271.263] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+298.26 271.263 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 315.69 271.263] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -315.69 -271.263] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+315.69 271.263 Td
+/F134_0 9.9626 Tf
+(opaque) 35.8654 Tj
+[1 0 0 1 351.556 271.263] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -351.556 -271.263] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+354.6 271.263 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-306 TJm
+(be) 9.40469 Tj
+-305 TJm
+(set) 11.0684 Tj
+-306 TJm
+(if) 6.08715 Tj
+-305 TJm
+(a) 4.42339 Tj
+-306 TJm
+(custom) 28.782 Tj
+-305 TJm
+(memory) 33.2053 Tj
+-306 TJm
+(allocator) 34.8591 Tj
+-306 TJm
+(is) 6.64505 Tj
+72 259.308 Td
+(required,) 35.686 Tj
+-350 TJm
+(or) 8.29885 Tj
+-331 TJm
+(made) 21.579 Tj
+[1 0 0 1 147.635 259.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -147.635 -259.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+147.635 259.308 Td
+/F134_0 9.9626 Tf
+(NULL) 23.9102 Tj
+[1 0 0 1 171.546 259.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -171.546 -259.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+174.835 259.308 Td
+/F130_0 9.9626 Tf
+(for) 11.6164 Tj
+-330 TJm
+(the) 12.1743 Tj
+-331 TJm
+(normal) 28.224 Tj
+[1 0 0 1 236.722 259.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -236.722 -259.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+236.722 259.308 Td
+/F134_0 9.9626 Tf
+(malloc) 35.8654 Tj
+[1 0 0 1 272.587 259.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -272.587 -259.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+275.878 259.308 Td
+/F130_0 9.9626 Tf
+(/) 2.7696 Tj
+[1 0 0 1 281.938 259.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -281.938 -259.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+281.938 259.308 Td
+/F134_0 9.9626 Tf
+(free) 23.9102 Tj
+[1 0 0 1 305.848 259.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -305.848 -259.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+309.139 259.308 Td
+/F130_0 9.9626 Tf
+(routines.) 34.5901 Tj
+-1102 TJm
+(Upon) 22.1369 Tj
+-330 TJm
+(return,) 26.2813 Tj
+-350 TJm
+(the) 12.1743 Tj
+-331 TJm
+(internal) 30.4357 Tj
+-330 TJm
+(state) 18.2614 Tj
+-330 TJm
+(will) 15.5018 Tj
+-330 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-331 TJm
+(been) 18.8094 Tj
+72 247.353 Td
+(initialised,) 41.7931 Tj
+-250 TJm
+(and) 14.386 Tj
+[1 0 0 1 133.16 247.353] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -133.16 -247.353] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+133.16 247.353 Td
+/F134_0 9.9626 Tf
+(total_in) 47.8205 Tj
+[1 0 0 1 180.98 247.353] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -180.98 -247.353] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+183.471 247.353 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 200.348 247.353] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -200.348 -247.353] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+200.348 247.353 Td
+/F134_0 9.9626 Tf
+(total_out) 53.798 Tj
+[1 0 0 1 254.146 247.353] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -254.146 -247.353] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+256.637 247.353 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(zero.) 19.6363 Tj
+[1 0 0 1 72 245.913] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -235.951] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 225.435 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(meaning) 34.3112 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(parameter) 39.8305 Tj
+[1 0 0 1 192.756 225.435] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -192.756 -225.435] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+192.756 225.435 Td
+/F134_0 9.9626 Tf
+(verbosity) 53.798 Tj
+[1 0 0 1 246.554 225.435] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -246.554 -225.435] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+246.554 225.435 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(see) 12.7222 Tj
+[1 0 0 1 266.748 225.435] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -266.748 -225.435] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+266.748 225.435 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 374.345 225.435] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -374.345 -225.435] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+374.345 225.435 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 223.278] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -213.315] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 203.517 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+[1 0 0 1 81.4975 203.517] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -81.4975 -203.517] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+81.4975 203.517 Td
+/F134_0 9.9626 Tf
+(small) 29.8878 Tj
+[1 0 0 1 111.385 203.517] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -111.385 -203.517] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+114.248 203.517 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-287 TJm
+(nonzero,) 34.5802 Tj
+-297 TJm
+(the) 12.1743 Tj
+-287 TJm
+(library) 26.5603 Tj
+-288 TJm
+(will) 15.5018 Tj
+-287 TJm
+(use) 13.2801 Tj
+-287 TJm
+(an) 9.40469 Tj
+-287 TJm
+(alternati) 32.6474 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-288 TJm
+(decompression) 59.7656 Tj
+-287 TJm
+(algorithm) 38.7446 Tj
+-287 TJm
+(which) 24.3486 Tj
+-288 TJm
+(uses) 17.1556 Tj
+-287 TJm
+(less) 14.9439 Tj
+-287 TJm
+(memory) 33.2053 Tj
+-287 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-288 TJm
+(at) 7.193 Tj
+-287 TJm
+(the) 12.1743 Tj
+72 191.562 Td
+(cost) 16.0497 Tj
+-289 TJm
+(of) 8.29885 Tj
+-290 TJm
+(decompressing) 59.7656 Tj
+-289 TJm
+(more) 20.4731 Tj
+-289 TJm
+(slo) 11.6264 Tj
+25 TJm
+(wly) 14.9439 Tj
+-290 TJm
+(\(roughly) 34.3112 Tj
+-289 TJm
+(speaking,) 37.9077 Tj
+-299 TJm
+(half) 15.4918 Tj
+-290 TJm
+(the) 12.1743 Tj
+-289 TJm
+(speed,) 25.1755 Tj
+-299 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-289 TJm
+(the) 12.1743 Tj
+-290 TJm
+(maximum) 40.4083 Tj
+-289 TJm
+(memory) 33.2053 Tj
+-289 TJm
+(requirement) 48.1393 Tj
+-290 TJm
+(drops) 22.1369 Tj
+72 179.607 Td
+(to) 7.7509 Tj
+-250 TJm
+(around) 27.6661 Tj
+-250 TJm
+(2300k\).) 30.7147 Tj
+-620 TJm
+(See) 14.386 Tj
+[1 0 0 1 166.166 179.607] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -166.166 -179.607] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+166.166 179.607 Td
+/F130_0 9.9626 Tf
+(Ho) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(bzip2) 22.1369 Tj
+[1 0 0 1 235.924 179.607] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+[1 0 0 1 -235.924 -179.607] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+238.415 179.607 Td
+/F130_0 9.9626 Tf
+([2]) 11.6164 Tj
+[1 0 0 1 250.031 179.607] cm
+/DeviceRGB {} cs
+[0 0 1] sc
+/DeviceRGB {} CS
+[0 0 1] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -250.031 -179.607] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+252.522 179.607 Td
+/F130_0 9.9626 Tf
+(for) 11.6164 Tj
+-250 TJm
+(more) 20.4731 Tj
+-250 TJm
+(information) 47.0434 Tj
+-250 TJm
+(on) 9.9626 Tj
+-250 TJm
+(memory) 33.2053 Tj
+-250 TJm
+(management.) 53.3995 Tj
+[1 0 0 1 72 177.45] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -167.487] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 157.689 Td
+/F130_0 9.9626 Tf
+(Note) 19.3673 Tj
+-289 TJm
+(that) 14.9439 Tj
+-290 TJm
+(the) 12.1743 Tj
+-289 TJm
+(amount) 29.8878 Tj
+-289 TJm
+(of) 8.29885 Tj
+-289 TJm
+(memory) 33.2053 Tj
+-290 TJm
+(needed) 28.2141 Tj
+-289 TJm
+(to) 7.7509 Tj
+-289 TJm
+(decompress) 47.0334 Tj
+-289 TJm
+(a) 4.42339 Tj
+-290 TJm
+(stream) 26.5603 Tj
+-289 TJm
+(cannot) 26.5603 Tj
+-289 TJm
+(be) 9.40469 Tj
+-289 TJm
+(determined) 44.8217 Tj
+-290 TJm
+(until) 18.2714 Tj
+-289 TJm
+(the) 12.1743 Tj
+-289 TJm
+(stream') 29.8778 Tj
+55 TJm
+(s) 3.87545 Tj
+-289 TJm
+(header) 26.5503 Tj
+-290 TJm
+(has) 13.2801 Tj
+72 145.734 Td
+(been) 18.8094 Tj
+-342 TJm
+(read,) 19.6363 Tj
+-366 TJm
+(so) 8.85675 Tj
+-342 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-342 TJm
+(if) 6.08715 Tj
+[1 0 0 1 161.081 145.734] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.081 -145.734] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+161.081 145.734 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressInit) 119.551 Tj
+[1 0 0 1 280.633 145.734] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -280.633 -145.734] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+284.043 145.734 Td
+/F130_0 9.9626 Tf
+(succeeds,) 37.8977 Tj
+-365 TJm
+(a) 4.42339 Tj
+-343 TJm
+(subsequent) 44.2738 Tj
+[1 0 0 1 381.098 145.734] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -381.098 -145.734] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+381.098 145.734 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 476.739 145.734] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -476.739 -145.734] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+480.149 145.734 Td
+/F130_0 9.9626 Tf
+(could) 22.1369 Tj
+-342 TJm
+(f) 3.31755 Tj
+10 TJm
+(ail) 9.9626 Tj
+-343 TJm
+(with) 17.7135 Tj
+[1 0 0 1 72 133.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -133.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 133.779 Td
+/F134_0 9.9626 Tf
+(BZ_MEM_ERROR) 71.7307 Tj
+[1 0 0 1 143.731 133.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.731 -133.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+143.731 133.779 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 132.469] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -122.506] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 111.861 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 111.761] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -60.9095] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(16) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 20 20
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -117.195] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 95.6413 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 92.0547] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(BZ_CONFIG_ERROR) 89.6634 Tj
+98.4879 699.676 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(library) 41.8429 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(mis-compiled) 71.7307 Tj
+90 687.721 Td
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 675.766 Td
+(if) 11.9551 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(small) 29.8878 Tj
+-426 TJm
+(!=) 11.9551 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(&&) 11.9551 Tj
+-426 TJm
+(small) 29.8878 Tj
+-426 TJm
+(!=) 11.9551 Tj
+-426 TJm
+(1) 5.97756 Tj
+-426 TJm
+(\)) 5.97756 Tj
+98.4879 663.811 Td
+(or) 11.9551 Tj
+-426 TJm
+(\(verbosity) 59.7756 Tj
+-426 TJm
+(<;) 11.9551 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(||) 11.9551 Tj
+-426 TJm
+(verbosity) 53.798 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(4\)) 11.9551 Tj
+90 651.856 Td
+(BZ_MEM_ERROR) 71.7307 Tj
+98.4879 639.9 Td
+(if) 11.9551 Tj
+-426 TJm
+(insufficient) 71.7307 Tj
+-426 TJm
+(memory) 35.8654 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(available) 53.798 Tj
+[1 0 0 1 72 624.359] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5865] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -614.396] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 602.441 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(actions:) 30.9936 Tj
+[1 0 0 1 72 602.341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -48.8169] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 47.8207 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 44.2341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -592.976] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 592.976 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+98.4879 581.021 Td
+(if) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(returned) 47.8205 Tj
+98.4879 569.066 Td
+(no) 11.9551 Tj
+-426 TJm
+(specific) 47.8205 Tj
+-426 TJm
+(action) 35.8654 Tj
+-426 TJm
+(required) 47.8205 Tj
+-426 TJm
+(in) 11.9551 Tj
+-426 TJm
+(case) 23.9102 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(error) 29.8878 Tj
+[1 0 0 1 72 553.524] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -543.562] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 522.903 Td
+/F122_0 17.2154 Tf
+(3.3.5.) 43.0729 Tj
+[1 0 0 1 119.858 522.903] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -522.903] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 522.903 Td
+/F392_0 17.2154 Tf
+(BZ2_bzDecompress) 165.268 Tj
+[1 0 0 1 285.126 522.903] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -213.126 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -511.206] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 511.206 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzDecompress) 95.641 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bz_stream) 53.798 Tj
+280.326 509.462 Td
+(*) 5.97756 Tj
+286.303 511.206 Td
+(strm) 23.9102 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 495.664] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 473.746 Td
+/F130_0 9.9626 Tf
+(Pro) 13.8381 Tj
+15 TJm
+(vides) 21.031 Tj
+-301 TJm
+(more) 20.4731 Tj
+-302 TJm
+(input) 20.4831 Tj
+-301 TJm
+(and/out) 29.8878 Tj
+-302 TJm
+(output) 25.4644 Tj
+-301 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-301 TJm
+(space) 22.1269 Tj
+-302 TJm
+(for) 11.6164 Tj
+-301 TJm
+(the) 12.1743 Tj
+-302 TJm
+(library) 26.5603 Tj
+65 TJm
+(.) 2.49065 Tj
+-928 TJm
+(The) 15.4918 Tj
+-301 TJm
+(caller) 22.1269 Tj
+-302 TJm
+(maintains) 38.7446 Tj
+-301 TJm
+(input) 20.4831 Tj
+-302 TJm
+(and) 14.386 Tj
+-301 TJm
+(output) 25.4644 Tj
+-301 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fers,) 17.4246 Tj
+-315 TJm
+(and) 14.386 Tj
+72 461.791 Td
+(uses) 17.1556 Tj
+[1 0 0 1 91.6461 461.791] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -91.6461 -461.791] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+91.6461 461.791 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 187.287 461.791] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -187.287 -461.791] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+189.778 461.791 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(transfer) 30.4258 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(between) 33.1954 Tj
+-250 TJm
+(them.) 22.4159 Tj
+[1 0 0 1 72 460.257] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -450.294] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 439.873 Td
+/F130_0 9.9626 Tf
+(Before) 27.1082 Tj
+-498 TJm
+(each) 18.2515 Tj
+-499 TJm
+(call) 14.386 Tj
+-498 TJm
+(to) 7.7509 Tj
+[1 0 0 1 159.356 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -159.356 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+159.356 439.873 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 254.997 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -254.997 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+254.997 439.873 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 263.071 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -263.071 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+263.071 439.873 Td
+/F134_0 9.9626 Tf
+(next_in) 41.8429 Tj
+[1 0 0 1 304.914 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -304.914 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+309.879 439.873 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-498 TJm
+(point) 20.4831 Tj
+-499 TJm
+(at) 7.193 Tj
+-498 TJm
+(the) 12.1743 Tj
+-498 TJm
+(compressed) 47.0334 Tj
+-499 TJm
+(data,) 19.0883 Tj
+-560 TJm
+(and) 14.386 Tj
+[1 0 0 1 492.179 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -492.179 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+492.179 439.873 Td
+/F134_0 9.9626 Tf
+(avail_in) 47.8205 Tj
+[1 0 0 1 540 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 427.918 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-308 TJm
+(indicate) 31.5416 Tj
+-308 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-309 TJm
+(man) 17.1556 Tj
+15 TJm
+(y) 4.9813 Tj
+-308 TJm
+(bytes) 21.031 Tj
+-308 TJm
+(the) 12.1743 Tj
+-308 TJm
+(library) 26.5603 Tj
+-308 TJm
+(may) 17.1556 Tj
+-309 TJm
+(read.) 19.6363 Tj
+[1 0 0 1 294.955 427.918] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -294.955 -427.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+294.955 427.918 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 390.597 427.918] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -390.597 -427.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+393.667 427.918 Td
+/F130_0 9.9626 Tf
+(updates) 30.4357 Tj
+[1 0 0 1 427.173 427.918] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -427.173 -427.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+427.173 427.918 Td
+/F134_0 9.9626 Tf
+(next_in) 41.8429 Tj
+[1 0 0 1 469.016 427.918] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -469.016 -427.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+469.016 427.918 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 474.723 427.918] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -474.723 -427.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+474.723 427.918 Td
+/F134_0 9.9626 Tf
+(avail_in) 47.8205 Tj
+[1 0 0 1 522.543 427.918] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -522.543 -427.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+525.614 427.918 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 72 415.963] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -415.963] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 415.963 Td
+/F134_0 9.9626 Tf
+(total_in) 47.8205 Tj
+[1 0 0 1 119.821 415.963] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.821 -415.963] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+122.311 415.963 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(re\003ect) 24.8965 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(number) 30.4357 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(bytes) 21.031 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(has) 13.2801 Tj
+-250 TJm
+(read.) 19.6363 Tj
+[1 0 0 1 72 413.806] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -403.843] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 394.045 Td
+/F130_0 9.9626 Tf
+(Similarly) 37.0908 Tj
+65 TJm
+(,) 2.49065 Tj
+[1 0 0 1 113.799 394.045] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.799 -394.045] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+113.799 394.045 Td
+/F134_0 9.9626 Tf
+(next_out) 47.8205 Tj
+[1 0 0 1 161.62 394.045] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.62 -394.045] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+164.41 394.045 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-280 TJm
+(point) 20.4831 Tj
+-280 TJm
+(to) 7.7509 Tj
+-280 TJm
+(a) 4.42339 Tj
+-280 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-280 TJm
+(in) 7.7509 Tj
+-281 TJm
+(which) 24.3486 Tj
+-280 TJm
+(the) 12.1743 Tj
+-280 TJm
+(uncompressed) 56.996 Tj
+-280 TJm
+(output) 25.4644 Tj
+-280 TJm
+(is) 6.64505 Tj
+-280 TJm
+(to) 7.7509 Tj
+-280 TJm
+(be) 9.40469 Tj
+-280 TJm
+(placed,) 28.493 Tj
+-288 TJm
+(with) 17.7135 Tj
+[1 0 0 1 486.202 394.045] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -486.202 -394.045] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+486.202 394.045 Td
+/F134_0 9.9626 Tf
+(avail_out) 53.798 Tj
+[1 0 0 1 540 394.045] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -394.045] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 382.09 Td
+/F130_0 9.9626 Tf
+(indicating) 39.8504 Tj
+-525 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-524 TJm
+(much) 22.1369 Tj
+-525 TJm
+(output) 25.4644 Tj
+-524 TJm
+(space) 22.1269 Tj
+-525 TJm
+(is) 6.64505 Tj
+-525 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+25 TJm
+(ailable.) 29.0509 Tj
+[1 0 0 1 285.792 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -285.792 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+285.792 382.09 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 369.478 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -369.478 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+374.705 382.09 Td
+/F130_0 9.9626 Tf
+(updates) 30.4357 Tj
+[1 0 0 1 410.367 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -410.367 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+410.367 382.09 Td
+/F134_0 9.9626 Tf
+(next_out) 47.8205 Tj
+[1 0 0 1 458.188 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -458.188 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+458.188 382.09 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 466.589 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -466.589 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+466.589 382.09 Td
+/F134_0 9.9626 Tf
+(avail_out) 53.798 Tj
+[1 0 0 1 520.387 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -520.387 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+525.614 382.09 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 72 370.135] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -370.135] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 370.135 Td
+/F134_0 9.9626 Tf
+(total_out) 53.798 Tj
+[1 0 0 1 125.798 370.135] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -125.798 -370.135] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+128.289 370.135 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(re\003ect) 24.8965 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(number) 30.4357 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(bytes) 21.031 Tj
+-250 TJm
+(output.) 27.9551 Tj
+[1 0 0 1 72 367.978] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -358.015] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 348.217 Td
+/F130_0 9.9626 Tf
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-320 TJm
+(may) 17.1556 Tj
+-321 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vide) 17.1556 Tj
+-320 TJm
+(and) 14.386 Tj
+-321 TJm
+(remo) 20.4731 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-320 TJm
+(as) 8.29885 Tj
+-321 TJm
+(little) 18.2714 Tj
+-320 TJm
+(or) 8.29885 Tj
+-320 TJm
+(as) 8.29885 Tj
+-321 TJm
+(much) 22.1369 Tj
+-320 TJm
+(data) 16.5977 Tj
+-321 TJm
+(as) 8.29885 Tj
+-320 TJm
+(you) 14.9439 Tj
+-321 TJm
+(lik) 10.5205 Tj
+10 TJm
+(e) 4.42339 Tj
+-320 TJm
+(on) 9.9626 Tj
+-320 TJm
+(each) 18.2515 Tj
+-321 TJm
+(call) 14.386 Tj
+-320 TJm
+(of) 8.29885 Tj
+[1 0 0 1 407.816 348.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -407.816 -348.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+407.816 348.217 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 503.457 348.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -503.457 -348.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+503.457 348.217 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1043 TJm
+(In) 8.29885 Tj
+-320 TJm
+(the) 12.1743 Tj
+72 336.262 Td
+(limit,) 21.32 Tj
+-295 TJm
+(it) 5.53921 Tj
+-286 TJm
+(is) 6.64505 Tj
+-287 TJm
+(acceptable) 42.0422 Tj
+-286 TJm
+(to) 7.7509 Tj
+-286 TJm
+(supply) 26.5703 Tj
+-286 TJm
+(and) 14.386 Tj
+-287 TJm
+(remo) 20.4731 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-286 TJm
+(data) 16.5977 Tj
+-286 TJm
+(one) 14.386 Tj
+-286 TJm
+(byte) 17.1556 Tj
+-287 TJm
+(at) 7.193 Tj
+-286 TJm
+(a) 4.42339 Tj
+-286 TJm
+(time,) 20.2042 Tj
+-295 TJm
+(although) 34.8691 Tj
+-286 TJm
+(this) 14.396 Tj
+-287 TJm
+(w) 7.193 Tj
+10 TJm
+(ould) 17.7135 Tj
+-286 TJm
+(be) 9.40469 Tj
+-286 TJm
+(terribly) 29.3299 Tj
+-286 TJm
+(inef) 15.4918 Tj
+25 TJm
+(\002cient.) 27.3972 Tj
+-838 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+72 324.306 Td
+(should) 26.5703 Tj
+-250 TJm
+(al) 7.193 Tj
+10 TJm
+(w) 7.193 Tj
+10 TJm
+(ays) 13.2801 Tj
+-250 TJm
+(ensure) 26.0024 Tj
+-250 TJm
+(that) 14.9439 Tj
+-250 TJm
+(at) 7.193 Tj
+-250 TJm
+(least) 18.2614 Tj
+-250 TJm
+(one) 14.386 Tj
+-250 TJm
+(byte) 17.1556 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(output) 25.4644 Tj
+-250 TJm
+(space) 22.1269 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+25 TJm
+(ailable) 26.5603 Tj
+-250 TJm
+(at) 7.193 Tj
+-250 TJm
+(each) 18.2515 Tj
+-250 TJm
+(call.) 16.8766 Tj
+[1 0 0 1 72 322.15] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -312.187] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 302.389 Td
+/F130_0 9.9626 Tf
+(Use) 15.4918 Tj
+-250 TJm
+(of) 8.29885 Tj
+[1 0 0 1 100.772 302.389] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -100.772 -302.389] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+100.772 302.389 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 196.413 302.389] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -196.413 -302.389] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+198.904 302.389 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(simpler) 29.8878 Tj
+-250 TJm
+(than) 17.1556 Tj
+[1 0 0 1 260.064 302.389] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -260.064 -302.389] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+260.064 302.389 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 343.75 302.389] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -343.75 -302.389] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+343.75 302.389 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 300.232] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -290.269] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 280.471 Td
+/F130_0 9.9626 Tf
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-346 TJm
+(should) 26.5703 Tj
+-347 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vide) 17.1556 Tj
+-346 TJm
+(input) 20.4831 Tj
+-346 TJm
+(and) 14.386 Tj
+-346 TJm
+(remo) 20.4731 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-347 TJm
+(output) 25.4644 Tj
+-346 TJm
+(as) 8.29885 Tj
+-346 TJm
+(described) 38.1767 Tj
+-346 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e,) 6.91404 Tj
+-371 TJm
+(and) 14.386 Tj
+-346 TJm
+(repeatedly) 41.4942 Tj
+-346 TJm
+(call) 14.386 Tj
+[1 0 0 1 422.638 280.471] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -422.638 -280.471] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+422.638 280.471 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 518.279 280.471] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -518.279 -280.471] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+521.729 280.471 Td
+/F130_0 9.9626 Tf
+(until) 18.2714 Tj
+[1 0 0 1 72 268.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -268.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 268.516 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 149.709 268.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -149.709 -268.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+152.314 268.516 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-262 TJm
+(returned.) 35.686 Tj
+-344 TJm
+(Appearance) 47.5714 Tj
+-262 TJm
+(of) 8.29885 Tj
+[1 0 0 1 261.767 268.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -261.767 -268.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+261.767 268.516 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 339.475 268.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -339.475 -268.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+342.081 268.516 Td
+/F130_0 9.9626 Tf
+(denotes) 30.4357 Tj
+-262 TJm
+(that) 14.9439 Tj
+[1 0 0 1 392.672 268.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -392.672 -268.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+392.672 268.516 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 488.313 268.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -488.313 -268.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+490.919 268.516 Td
+/F130_0 9.9626 Tf
+(has) 13.2801 Tj
+-262 TJm
+(detected) 33.1954 Tj
+72 256.561 Td
+(the) 12.1743 Tj
+-212 TJm
+(logical) 27.1182 Tj
+-212 TJm
+(end) 14.386 Tj
+-211 TJm
+(of) 8.29885 Tj
+-212 TJm
+(the) 12.1743 Tj
+-212 TJm
+(compressed) 47.0334 Tj
+-212 TJm
+(stream.) 29.0509 Tj
+[1 0 0 1 237.858 256.561] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -237.858 -256.561] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+237.858 256.561 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 333.499 256.561] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -333.499 -256.561] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+335.609 256.561 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-212 TJm
+(not) 12.7322 Tj
+-212 TJm
+(produce) 32.0895 Tj
+[1 0 0 1 402.263 256.561] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -402.263 -256.561] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+402.263 256.561 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 479.972 256.561] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -479.972 -256.561] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+482.082 256.561 Td
+/F130_0 9.9626 Tf
+(until) 18.2714 Tj
+-212 TJm
+(all) 9.9626 Tj
+-212 TJm
+(output) 25.4644 Tj
+72 244.605 Td
+(data) 16.5977 Tj
+-256 TJm
+(has) 13.2801 Tj
+-256 TJm
+(been) 18.8094 Tj
+-255 TJm
+(placed) 26.0024 Tj
+-256 TJm
+(into) 15.5018 Tj
+-256 TJm
+(the) 12.1743 Tj
+-256 TJm
+(output) 25.4644 Tj
+-256 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+40 TJm
+(,) 2.49065 Tj
+-257 TJm
+(so) 8.85675 Tj
+-256 TJm
+(once) 18.8094 Tj
+[1 0 0 1 278.978 244.605] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.978 -244.605] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+278.978 244.605 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 356.687 244.605] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -356.687 -244.605] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+359.236 244.605 Td
+/F130_0 9.9626 Tf
+(appears,) 32.9164 Tj
+-257 TJm
+(you) 14.9439 Tj
+-256 TJm
+(are) 12.1643 Tj
+-256 TJm
+(guaranteed) 43.7059 Tj
+-256 TJm
+(to) 7.7509 Tj
+-256 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-255 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+25 TJm
+(ailable) 26.5603 Tj
+72 232.65 Td
+(all) 9.9626 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(decompressed) 56.4381 Tj
+-250 TJm
+(output,) 27.9551 Tj
+-250 TJm
+(and) 14.386 Tj
+[1 0 0 1 205.369 232.65] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -205.369 -232.65] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+205.369 232.65 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressEnd) 113.574 Tj
+[1 0 0 1 318.943 232.65] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -318.943 -232.65] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+321.433 232.65 Td
+/F130_0 9.9626 Tf
+(can) 13.8281 Tj
+-250 TJm
+(safely) 23.7907 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(called.) 26.2813 Tj
+[1 0 0 1 72 230.493] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -220.531] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 210.732 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-250 TJm
+(case) 17.1456 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(an) 9.40469 Tj
+-250 TJm
+(error) 19.3573 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue,) 19.0883 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(should) 26.5703 Tj
+-250 TJm
+(call) 14.386 Tj
+[1 0 0 1 261.259 210.732] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -261.259 -210.732] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+261.259 210.732 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressEnd) 113.574 Tj
+[1 0 0 1 374.833 210.732] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -374.833 -210.732] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+377.323 210.732 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(clean) 21.0211 Tj
+-250 TJm
+(up) 9.9626 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(release) 27.6562 Tj
+-250 TJm
+(memory) 33.2053 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 208.576] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -198.613] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 188.815 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 188.715] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -137.863] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(17) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 21 21
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -200.882] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 179.328 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 175.741] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 699.676 Td
+(if) 11.9551 Tj
+-426 TJm
+(strm) 23.9102 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(strm->s) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+98.4879 687.721 Td
+(or) 11.9551 Tj
+-426 TJm
+(strm->avail_out) 89.6634 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(1) 5.97756 Tj
+90 675.766 Td
+(BZ_DATA_ERROR) 77.7083 Tj
+98.4879 663.811 Td
+(if) 11.9551 Tj
+-426 TJm
+(a) 5.97756 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(integrity) 53.798 Tj
+-426 TJm
+(error) 29.8878 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(detected) 47.8205 Tj
+-426 TJm
+(in) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(stream) 35.8654 Tj
+90 651.856 Td
+(BZ_DATA_ERROR_MAGIC) 113.574 Tj
+98.4879 639.9 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(stream) 35.8654 Tj
+-426 TJm
+(doesn't) 41.8429 Tj
+-426 TJm
+(begin) 29.8878 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(right) 29.8878 Tj
+-426 TJm
+(magic) 29.8878 Tj
+-426 TJm
+(bytes) 29.8878 Tj
+90 627.945 Td
+(BZ_MEM_ERROR) 71.7307 Tj
+98.4879 615.99 Td
+(if) 11.9551 Tj
+-426 TJm
+(there) 29.8878 Tj
+-426 TJm
+(wasn't) 35.8654 Tj
+-426 TJm
+(enough) 35.8654 Tj
+-426 TJm
+(memory) 35.8654 Tj
+-426 TJm
+(available) 53.798 Tj
+90 604.035 Td
+(BZ_STREAM_END) 77.7083 Tj
+98.4879 592.08 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(logical) 41.8429 Tj
+-426 TJm
+(end) 17.9327 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(stream) 35.8654 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(detected) 47.8205 Tj
+-426 TJm
+(and) 17.9327 Tj
+-426 TJm
+(all) 17.9327 Tj
+98.4879 580.125 Td
+(output) 35.8654 Tj
+-426 TJm
+(in) 11.9551 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(consumed,) 53.798 Tj
+-426 TJm
+(eg) 11.9551 Tj
+-426 TJm
+(s-->avail_out) 77.7083 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(0) 5.97756 Tj
+90 568.169 Td
+(BZ_OK) 29.8878 Tj
+98.4879 556.214 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 540.673] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -530.71] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 518.755 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(actions:) 30.9936 Tj
+[1 0 0 1 72 518.655] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -60.7721] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 59.7758 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 56.1892] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -509.29] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 509.29 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+98.4879 497.335 Td
+(if) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(returned) 47.8205 Tj
+90 485.38 Td
+(BZ2_bzDecompressEnd) 113.574 Tj
+98.4879 473.425 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 457.883] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -447.92] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 427.262 Td
+/F122_0 17.2154 Tf
+(3.3.6.) 43.0729 Tj
+[1 0 0 1 119.858 427.262] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -427.262] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 427.262 Td
+/F392_0 17.2154 Tf
+(BZ2_bzDecompressEnd) 196.256 Tj
+[1 0 0 1 316.114 427.262] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -244.114 -2.3326] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -415.564] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 415.564 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzDecompressEnd) 113.574 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bz_stream) 53.798 Tj
+298.259 413.821 Td
+(*) 5.97756 Tj
+304.236 415.564 Td
+(strm) 23.9102 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 400.023] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -390.06] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 378.105 Td
+/F130_0 9.9626 Tf
+(Releases) 34.8591 Tj
+-250 TJm
+(all) 9.9626 Tj
+-250 TJm
+(memory) 33.2053 Tj
+-250 TJm
+(associated) 40.9463 Tj
+-250 TJm
+(with) 17.7135 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(decompression) 59.7656 Tj
+-250 TJm
+(stream.) 29.0509 Tj
+[1 0 0 1 72 375.948] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -365.985] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 356.187 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 356.087] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -60.7721] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 59.7758 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 56.1893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -346.723] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 346.723 Td
+/F134_0 9.9626 Tf
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 334.767 Td
+(if) 11.9551 Tj
+-426 TJm
+(strm) 23.9102 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(strm->s) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+90 322.812 Td
+(BZ_OK) 29.8878 Tj
+98.4879 310.857 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 295.315] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -285.353] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 273.397 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(actions:) 30.9936 Tj
+[1 0 0 1 72 273.298] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -263.933] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+98.4879 263.933 Td
+/F134_0 9.9626 Tf
+(None.) 29.8878 Tj
+[1 0 0 1 72 248.391] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -238.429] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 213.639 Td
+/F122_0 20.6585 Tf
+(3.4.) 34.4584 Tj
+-278 TJm
+(High-le) 70.0117 Tj
+15 TJm
+(vel) 28.7153 Tj
+-278 TJm
+(interface) 86.1046 Tj
+[1 0 0 1 72 209.042] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -199.08] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 191.721 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+-250 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vides) 21.031 Tj
+-250 TJm
+(functions) 37.0808 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(reading) 29.8778 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(writing) 28.782 Tj
+[1 0 0 1 300.292 191.721] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -300.292 -191.721] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+300.292 191.721 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 330.18 191.721] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -330.18 -191.721] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+332.67 191.721 Td
+/F130_0 9.9626 Tf
+(format) 26.5603 Tj
+-250 TJm
+(\002les.) 19.0983 Tj
+-620 TJm
+(First,) 20.7621 Tj
+-250 TJm
+(some) 21.031 Tj
+-250 TJm
+(general) 29.3199 Tj
+-250 TJm
+(points.) 26.8492 Tj
+[1 0 0 1 72 189.564] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -29.7236] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -159.84] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 159.84 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 159.84] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -159.84] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 159.84 Td
+/F130_0 9.9626 Tf
+(All) 12.7322 Tj
+-332 TJm
+(of) 8.29885 Tj
+-331 TJm
+(the) 12.1743 Tj
+-332 TJm
+(functions) 37.0808 Tj
+-332 TJm
+(tak) 12.1743 Tj
+10 TJm
+(e) 4.42339 Tj
+-331 TJm
+(an) 9.40469 Tj
+[1 0 0 1 202.958 159.84] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -202.958 -159.84] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+202.958 159.84 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+220.891 158.097 Td
+(*) 5.97756 Tj
+[1 0 0 1 226.868 159.84] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -226.868 -159.84] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+230.172 159.84 Td
+/F130_0 9.9626 Tf
+(\002rst) 15.5018 Tj
+-332 TJm
+(ar) 7.74094 Tj
+18 TJm
+(gument,) 32.3785 Tj
+[1 0 0 1 292.426 159.84] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -292.426 -159.84] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+292.426 159.84 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 334.269 159.84] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -334.269 -159.84] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+334.269 159.84 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1110 TJm
+(After) 21.0211 Tj
+-332 TJm
+(each) 18.2515 Tj
+-331 TJm
+(call,) 16.8766 Tj
+[1 0 0 1 414.083 159.84] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -414.083 -159.84] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+414.083 159.84 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 455.926 159.84] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -455.926 -159.84] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+459.23 159.84 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-332 TJm
+(be) 9.40469 Tj
+-331 TJm
+(consulted) 38.1866 Tj
+86.944 147.885 Td
+(\002rst) 15.5018 Tj
+-349 TJm
+(to) 7.7509 Tj
+-349 TJm
+(determine) 39.8404 Tj
+-348 TJm
+(the) 12.1743 Tj
+-349 TJm
+(outcome) 34.3112 Tj
+-349 TJm
+(of) 8.29885 Tj
+-349 TJm
+(the) 12.1743 Tj
+-348 TJm
+(call.) 16.8766 Tj
+-1213 TJm
+(If) 6.63509 Tj
+[1 0 0 1 280.386 147.885] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -280.386 -147.885] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+280.386 147.885 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 322.229 147.885] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -322.229 -147.885] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+325.704 147.885 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+[1 0 0 1 335.824 147.885] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -335.824 -147.885] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+335.824 147.885 Td
+/F134_0 9.9626 Tf
+(BZ_OK) 29.8878 Tj
+[1 0 0 1 365.711 147.885] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -365.711 -147.885] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+365.711 147.885 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-349 TJm
+(the) 12.1743 Tj
+-349 TJm
+(call) 14.386 Tj
+-348 TJm
+(completed) 41.5042 Tj
+-349 TJm
+(successfully) 48.6972 Tj
+65 TJm
+(,) 2.49065 Tj
+-374 TJm
+(and) 14.386 Tj
+-348 TJm
+(only) 17.7135 Tj
+86.944 135.93 Td
+(then) 17.1556 Tj
+-271 TJm
+(should) 26.5703 Tj
+-270 TJm
+(the) 12.1743 Tj
+-271 TJm
+(return) 23.7907 Tj
+-270 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+-271 TJm
+(of) 8.29885 Tj
+-271 TJm
+(the) 12.1743 Tj
+-270 TJm
+(function) 33.2053 Tj
+-271 TJm
+(\(if) 9.40469 Tj
+-270 TJm
+(an) 9.40469 Tj
+15 TJm
+(y\)) 8.29885 Tj
+-271 TJm
+(be) 9.40469 Tj
+-271 TJm
+(cons) 18.2614 Tj
+1 TJm
+(u) 4.9813 Tj
+-1 TJm
+(l) 2.7696 Tj
+1 TJm
+(ted.) 14.6649 Tj
+-744 TJm
+(If) 6.63509 Tj
+[1 0 0 1 365.077 135.93] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -365.077 -135.93] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+365.077 135.93 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 406.92 135.93] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -406.92 -135.93] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+409.616 135.93 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+[1 0 0 1 418.956 135.93] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -418.956 -135.93] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+418.956 135.93 Td
+/F134_0 9.9626 Tf
+(BZ_IO_ERROR) 65.7532 Tj
+[1 0 0 1 484.71 135.93] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -484.71 -135.93] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+484.71 135.93 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-271 TJm
+(there) 19.9152 Tj
+-270 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-271 TJm
+(an) 9.40469 Tj
+86.944 123.975 Td
+(error) 19.3573 Tj
+-246 TJm
+(reading/writing) 61.4294 Tj
+-245 TJm
+(the) 12.1743 Tj
+-246 TJm
+(underlying) 43.1679 Tj
+-246 TJm
+(compressed) 47.0334 Tj
+-245 TJm
+(\002le,) 15.2229 Tj
+-247 TJm
+(and) 14.386 Tj
+-245 TJm
+(you) 14.9439 Tj
+-246 TJm
+(should) 26.5703 Tj
+-246 TJm
+(then) 17.1556 Tj
+-245 TJm
+(consult) 28.782 Tj
+[1 0 0 1 414.096 123.975] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -414.096 -123.975] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+414.096 123.975 Td
+/F134_0 9.9626 Tf
+(errno) 29.8878 Tj
+[1 0 0 1 443.984 123.975] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -443.984 -123.975] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+446.432 123.975 Td
+/F130_0 9.9626 Tf
+(/) 2.7696 Tj
+[1 0 0 1 451.649 123.975] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -451.649 -123.975] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+451.649 123.975 Td
+/F134_0 9.9626 Tf
+(perror) 35.8654 Tj
+[1 0 0 1 487.514 123.975] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -487.514 -123.975] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+489.962 123.975 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-246 TJm
+(determine) 39.8404 Tj
+86.944 112.02 Td
+(the) 12.1743 Tj
+-356 TJm
+(cause) 22.1269 Tj
+-356 TJm
+(of) 8.29885 Tj
+-355 TJm
+(the) 12.1743 Tj
+-356 TJm
+(dif) 11.0684 Tj
+25 TJm
+(\002culty) 25.4644 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 206.528 112.02] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -206.528 -112.02] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+206.528 112.02 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 248.371 112.02] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -248.371 -112.02] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+251.916 112.02 Td
+/F130_0 9.9626 Tf
+(may) 17.1556 Tj
+-356 TJm
+(also) 16.0497 Tj
+-356 TJm
+(be) 9.40469 Tj
+-355 TJm
+(set) 11.0684 Tj
+-356 TJm
+(to) 7.7509 Tj
+-356 TJm
+(v) 4.9813 Tj
+25 TJm
+(arious) 24.3486 Tj
+-356 TJm
+(other) 20.4731 Tj
+-356 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues;) 23.2427 Tj
+-408 TJm
+(precise) 28.2141 Tj
+-356 TJm
+(details) 26.0123 Tj
+-356 TJm
+(are) 12.1643 Tj
+-356 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-356 TJm
+(on) 9.9626 Tj
+-356 TJm
+(a) 4.42339 Tj
+86.944 100.064 Td
+(per) 12.7222 Tj
+20 TJm
+(-function) 36.5229 Tj
+-250 TJm
+(basis) 19.9252 Tj
+-250 TJm
+(belo) 17.1556 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 186.839 100.064] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -114.838 -49.2126] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(18) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 22 22
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -31.5168] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 710.037 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 710.037 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+[1 0 0 1 95.9576 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -95.9576 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+95.9576 710.037 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 137.801 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.801 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+140.179 710.037 Td
+/F130_0 9.9626 Tf
+(indicates) 35.417 Tj
+-239 TJm
+(an) 9.40469 Tj
+-238 TJm
+(error) 19.3573 Tj
+-239 TJm
+(\(ie,) 13.0012 Tj
+-241 TJm
+(an) 9.40469 Tj
+15 TJm
+(ything) 25.4644 Tj
+-239 TJm
+(e) 4.42339 Tj
+15 TJm
+(xcept) 21.579 Tj
+[1 0 0 1 292.225 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -292.225 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+292.225 710.037 Td
+/F134_0 9.9626 Tf
+(BZ_OK) 29.8878 Tj
+[1 0 0 1 322.113 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -322.113 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+324.492 710.037 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 341.256 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -341.256 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+341.256 710.037 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 418.965 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -418.965 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+418.965 710.037 Td
+/F130_0 9.9626 Tf
+(\),) 5.8082 Tj
+-239 TJm
+(you) 14.9439 Tj
+-239 TJm
+(should) 26.5703 Tj
+-238 TJm
+(immediately) 49.813 Tj
+-239 TJm
+(call) 14.386 Tj
+[1 0 0 1 86.944 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 698.082 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 176.608 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -176.608 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+179.343 698.082 Td
+/F130_0 9.9626 Tf
+(\(or) 11.6164 Tj
+[1 0 0 1 193.695 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -193.695 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+193.695 698.082 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteClose) 95.641 Tj
+[1 0 0 1 289.337 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -289.337 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+289.337 698.082 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-281 TJm
+(depending) 41.5042 Tj
+-274 TJm
+(on) 9.9626 Tj
+-275 TJm
+(whether) 32.0895 Tj
+-274 TJm
+(you) 14.9439 Tj
+-275 TJm
+(are) 12.1643 Tj
+-275 TJm
+(attempting) 42.62 Tj
+-274 TJm
+(to) 7.7509 Tj
+-275 TJm
+(read) 17.1456 Tj
+-274 TJm
+(or) 8.29885 Tj
+-275 TJm
+(to) 7.7509 Tj
+-274 TJm
+(write\)) 23.7907 Tj
+86.944 686.127 Td
+(to) 7.7509 Tj
+-242 TJm
+(free) 15.4819 Tj
+-242 TJm
+(up) 9.9626 Tj
+-241 TJm
+(all) 9.9626 Tj
+-242 TJm
+(resources) 37.6188 Tj
+-242 TJm
+(associated) 40.9463 Tj
+-242 TJm
+(wi) 9.9626 Tj
+1 TJm
+(th) 7.7509 Tj
+-242 TJm
+(the) 12.1743 Tj
+-242 TJm
+(stream.) 29.0509 Tj
+-614 TJm
+(Once) 21.0211 Tj
+-242 TJm
+(an) 9.40469 Tj
+-242 TJm
+(error) 19.3573 Tj
+-242 TJm
+(has) 13.2801 Tj
+-242 TJm
+(been) 18.8094 Tj
+-241 TJm
+(indicated,) 39.0135 Tj
+-244 TJm
+(beha) 18.8094 Tj
+20 TJm
+(viour) 21.031 Tj
+-241 TJm
+(of) 8.29885 Tj
+-242 TJm
+(all) 9.9626 Tj
+-242 TJm
+(calls) 18.2614 Tj
+-242 TJm
+(e) 4.42339 Tj
+15 TJm
+(xcept) 21.579 Tj
+[1 0 0 1 86.944 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 674.172 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 176.608 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -176.608 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+179.705 674.172 Td
+/F130_0 9.9626 Tf
+(\() 3.31755 Tj
+[1 0 0 1 183.022 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -183.022 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+183.022 674.172 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteClose) 95.641 Tj
+[1 0 0 1 278.664 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.664 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+278.664 674.172 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-311 TJm
+(is) 6.64505 Tj
+-311 TJm
+(unde\002ned.) 41.7831 Tj
+-985 TJm
+(The) 15.4918 Tj
+-311 TJm
+(implication) 45.3896 Tj
+-310 TJm
+(is) 6.64505 Tj
+-311 TJm
+(that) 14.9439 Tj
+-311 TJm
+(\(1\)) 11.6164 Tj
+[1 0 0 1 455.988 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -455.988 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+455.988 674.172 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 497.831 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -497.831 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+500.928 674.172 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-311 TJm
+(be) 9.40469 Tj
+86.944 662.217 Td
+(check) 23.2328 Tj
+10 TJm
+(ed) 9.40469 Tj
+-291 TJm
+(after) 18.2515 Tj
+-291 TJm
+(each) 18.2515 Tj
+-291 TJm
+(call,) 16.8766 Tj
+-301 TJm
+(and) 14.386 Tj
+-291 TJm
+(\(2\)) 11.6164 Tj
+-291 TJm
+(if) 6.08715 Tj
+[1 0 0 1 225.347 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -225.347 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+225.347 662.217 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 267.19 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -267.19 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+270.09 662.217 Td
+/F130_0 9.9626 Tf
+(indicates) 35.417 Tj
+-291 TJm
+(an) 9.40469 Tj
+-291 TJm
+(error) 19.3573 Tj
+40 TJm
+(,) 2.49065 Tj
+[1 0 0 1 345.161 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -345.161 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+345.161 662.217 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 434.824 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -434.824 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+437.724 662.217 Td
+/F130_0 9.9626 Tf
+(\() 3.31755 Tj
+[1 0 0 1 441.041 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -441.041 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+441.041 662.217 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteClose) 95.641 Tj
+[1 0 0 1 536.683 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -536.683 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+536.683 662.217 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+86.944 650.262 Td
+(should) 26.5703 Tj
+-250 TJm
+(then) 17.1556 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(called) 23.7907 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(clean) 21.0211 Tj
+-250 TJm
+(up.) 12.4533 Tj
+[1 0 0 1 220.034 650.261] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -148.034 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -628.344] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 628.344 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 628.344] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -628.344] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 628.344 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+[1 0 0 1 106.362 628.344] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -106.362 -628.344] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+106.362 628.344 Td
+/F134_0 9.9626 Tf
+(FILE) 23.9102 Tj
+130.273 626.6 Td
+(*) 5.97756 Tj
+[1 0 0 1 136.25 628.344] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -136.25 -628.344] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+140.177 628.344 Td
+/F130_0 9.9626 Tf
+(ar) 7.74094 Tj
+18 TJm
+(guments) 33.7633 Tj
+-394 TJm
+(passed) 26.5603 Tj
+-394 TJm
+(to) 7.7509 Tj
+[1 0 0 1 227.592 628.344] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -227.592 -628.344] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+227.592 628.344 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadOpen) 83.6858 Tj
+[1 0 0 1 311.278 628.344] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -311.278 -628.344] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+315.205 628.344 Td
+/F130_0 9.9626 Tf
+(/) 2.7696 Tj
+[1 0 0 1 321.901 628.344] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -321.901 -628.344] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+321.901 628.344 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteOpen) 89.6634 Tj
+[1 0 0 1 411.565 628.344] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -411.565 -628.344] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+415.491 628.344 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-394 TJm
+(be) 9.40469 Tj
+-394 TJm
+(set) 11.0684 Tj
+-394 TJm
+(to) 7.7509 Tj
+-394 TJm
+(binary) 25.4544 Tj
+-395 TJm
+(mode.) 24.6275 Tj
+86.944 616.389 Td
+(Most) 20.4831 Tj
+-229 TJm
+(Unix) 19.9252 Tj
+-229 TJm
+(systems) 31.5516 Tj
+-228 TJm
+(will) 15.5018 Tj
+-229 TJm
+(do) 9.9626 Tj
+-229 TJm
+(this) 14.396 Tj
+-229 TJm
+(by) 9.9626 Tj
+-229 TJm
+(def) 12.7222 Tj
+10 TJm
+(ault,) 17.4346 Tj
+-233 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-229 TJm
+(other) 20.4731 Tj
+-229 TJm
+(platforms,) 40.6773 Tj
+-233 TJm
+(including) 37.6387 Tj
+-229 TJm
+(W) 9.40469 Tj
+40 TJm
+(indo) 17.7135 Tj
+25 TJm
+(ws) 11.0684 Tj
+-228 TJm
+(and) 14.386 Tj
+-229 TJm
+(Mac,) 20.1942 Tj
+-233 TJm
+(will) 15.5018 Tj
+-229 TJm
+(not.) 15.2229 Tj
+-606 TJm
+(If) 6.63509 Tj
+-229 TJm
+(you) 14.9439 Tj
+-229 TJm
+(omit) 18.2714 Tj
+86.944 604.433 Td
+(this,) 16.8866 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(may) 17.1556 Tj
+-250 TJm
+(encounter) 39.2825 Tj
+-250 TJm
+(problems) 37.0808 Tj
+-250 TJm
+(when) 21.579 Tj
+-250 TJm
+(mo) 12.7322 Tj
+15 TJm
+(ving) 17.7135 Tj
+-250 TJm
+(code) 18.8094 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(ne) 9.40469 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(platforms.) 40.6773 Tj
+[1 0 0 1 372.66 604.433] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -300.66 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -582.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 582.516 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 582.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -582.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 582.516 Td
+/F130_0 9.9626 Tf
+(Memory) 34.3112 Tj
+-348 TJm
+(allocation) 39.2925 Tj
+-348 TJm
+(requests) 32.6474 Tj
+-348 TJm
+(are) 12.1643 Tj
+-348 TJm
+(handled) 31.5416 Tj
+-348 TJm
+(by) 9.9626 Tj
+[1 0 0 1 267.67 582.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -267.67 -582.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+267.67 582.516 Td
+/F134_0 9.9626 Tf
+(malloc) 35.8654 Tj
+[1 0 0 1 303.535 582.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -303.535 -582.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+307.003 582.516 Td
+/F130_0 9.9626 Tf
+(/) 2.7696 Tj
+[1 0 0 1 313.241 582.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -313.241 -582.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+313.241 582.516 Td
+/F134_0 9.9626 Tf
+(free) 23.9102 Tj
+[1 0 0 1 337.151 582.516] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -337.151 -582.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+337.151 582.516 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1209 TJm
+(At) 9.9626 Tj
+-348 TJm
+(present) 28.772 Tj
+-348 TJm
+(there) 19.9152 Tj
+-348 TJm
+(is) 6.64505 Tj
+-348 TJm
+(no) 9.9626 Tj
+-348 TJm
+(f) 3.31755 Tj
+10 TJm
+(acility) 24.9065 Tj
+-348 TJm
+(for) 11.6164 Tj
+-348 TJm
+(user) 16.5977 Tj
+20 TJm
+(-de\002ned) 32.6474 Tj
+86.944 570.56 Td
+(memory) 33.2053 Tj
+-250 TJm
+(allocators) 38.7346 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(I/O) 13.2801 Tj
+-250 TJm
+(functions) 37.0808 Tj
+-250 TJm
+(\(could) 25.4544 Tj
+-250 TJm
+(easily) 23.2427 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(added,) 26.2813 Tj
+-250 TJm
+(though\).) 33.4843 Tj
+[1 0 0 1 387.165 570.56] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -315.165 -12.1195] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -548.478] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 529.977 Td
+/F122_0 17.2154 Tf
+(3.4.1.) 43.0729 Tj
+[1 0 0 1 119.858 529.977] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -529.977] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 529.977 Td
+/F392_0 17.2154 Tf
+(BZ2_bzReadOpen) 144.609 Tj
+[1 0 0 1 264.468 529.977] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -192.468 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -72.7272] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 71.731 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 68.1444] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -518.279] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 518.279 Td
+/F134_0 9.9626 Tf
+(typedef) 41.8429 Tj
+-426 TJm
+(void) 23.9102 Tj
+-426 TJm
+(BZFILE;) 41.8429 Tj
+90 494.369 Td
+(BZFILE) 35.8654 Tj
+130.109 492.625 Td
+(*) 5.97756 Tj
+136.087 494.369 Td
+(BZ2_bzReadOpen\() 89.6634 Tj
+-426 TJm
+(int) 17.9327 Tj
+252.171 492.625 Td
+(*) 5.97756 Tj
+258.149 494.369 Td
+(bzerror,) 47.8205 Tj
+-426 TJm
+(FILE) 23.9102 Tj
+338.368 492.625 Td
+(*) 5.97756 Tj
+344.346 494.369 Td
+(f,) 11.9551 Tj
+191.855 482.414 Td
+(int) 17.9327 Tj
+-426 TJm
+(verbosity,) 59.7756 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(small,) 35.8654 Tj
+191.855 470.458 Td
+(void) 23.9102 Tj
+220.01 468.715 Td
+(*) 5.97756 Tj
+225.987 470.458 Td
+(unused,) 41.8429 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(nUnused) 41.8429 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 454.917] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -444.954] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 432.999 Td
+/F130_0 9.9626 Tf
+(Prepare) 30.4258 Tj
+-290 TJm
+(to) 7.7509 Tj
+-289 TJm
+(read) 17.1456 Tj
+-290 TJm
+(compressed) 47.0334 Tj
+-290 TJm
+(data) 16.5977 Tj
+-289 TJm
+(from) 19.3673 Tj
+-290 TJm
+(\002le) 12.7322 Tj
+-289 TJm
+(handle) 26.5603 Tj
+[1 0 0 1 272.697 432.999] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -272.697 -432.999] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+272.697 432.999 Td
+/F134_0 9.9626 Tf
+(f) 5.97756 Tj
+[1 0 0 1 278.675 432.999] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.675 -432.999] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+278.675 432.999 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 285.439 432.999] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -285.439 -432.999] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+285.439 432.999 Td
+/F134_0 9.9626 Tf
+(f) 5.97756 Tj
+[1 0 0 1 291.417 432.999] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -291.417 -432.999] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+294.303 432.999 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-290 TJm
+(refer) 18.7994 Tj
+-289 TJm
+(to) 7.7509 Tj
+-290 TJm
+(a) 4.42339 Tj
+-290 TJm
+(\002le) 12.7322 Tj
+-289 TJm
+(which) 24.3486 Tj
+-290 TJm
+(has) 13.2801 Tj
+-289 TJm
+(been) 18.8094 Tj
+-290 TJm
+(opened) 28.772 Tj
+-290 TJm
+(for) 11.6164 Tj
+-289 TJm
+(reading,) 32.3685 Tj
+-300 TJm
+(and) 14.386 Tj
+72 421.044 Td
+(for) 11.6164 Tj
+-306 TJm
+(which) 24.3486 Tj
+-305 TJm
+(the) 12.1743 Tj
+-306 TJm
+(error) 19.3573 Tj
+-306 TJm
+(indicator) 35.417 Tj
+-305 TJm
+(\() 3.31755 Tj
+[1 0 0 1 193.457 421.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -193.457 -421.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+193.457 421.044 Td
+/F134_0 9.9626 Tf
+(ferror\(f\)) 53.798 Tj
+[1 0 0 1 247.255 421.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -247.255 -421.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+247.255 421.044 Td
+/F130_0 9.9626 Tf
+(\)is) 9.9626 Tj
+-306 TJm
+(not) 12.7322 Tj
+-305 TJm
+(set.) 13.5591 Tj
+-954 TJm
+(If) 6.63509 Tj
+[1 0 0 1 308.784 421.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -308.784 -421.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+308.784 421.044 Td
+/F134_0 9.9626 Tf
+(small) 29.8878 Tj
+[1 0 0 1 338.671 421.044] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -338.671 -421.044] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+341.717 421.044 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-306 TJm
+(1,) 7.47195 Tj
+-319 TJm
+(the) 12.1743 Tj
+-306 TJm
+(library) 26.5603 Tj
+-306 TJm
+(will) 15.5018 Tj
+-305 TJm
+(try) 11.0684 Tj
+-306 TJm
+(to) 7.7509 Tj
+-306 TJm
+(dec) 13.8281 Tj
+1 TJm
+(ompress) 33.2053 Tj
+-306 TJm
+(using) 21.589 Tj
+-306 TJm
+(less) 14.9439 Tj
+72 409.089 Td
+(memory) 33.2053 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(at) 7.193 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(e) 4.42339 Tj
+15 TJm
+(xpense) 27.6661 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(speed.) 25.1755 Tj
+[1 0 0 1 72 406.932] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -396.969] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 387.171 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-227 TJm
+(reasons) 29.8778 Tj
+-227 TJm
+(e) 4.42339 Tj
+15 TJm
+(xplained) 34.3112 Tj
+-228 TJm
+(belo) 17.1556 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(,) 2.49065 Tj
+[1 0 0 1 189.193 387.171] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -189.193 -387.171] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+189.193 387.171 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 248.969 387.171] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -248.969 -387.171] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+251.232 387.171 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-227 TJm
+(decompress) 47.0334 Tj
+-227 TJm
+(the) 12.1743 Tj
+[1 0 0 1 332.732 387.171] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -332.732 -387.171] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+332.732 387.171 Td
+/F134_0 9.9626 Tf
+(nUnused) 41.8429 Tj
+[1 0 0 1 374.575 387.171] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -374.575 -387.171] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+376.838 387.171 Td
+/F130_0 9.9626 Tf
+(bytes) 21.031 Tj
+-227 TJm
+(starting) 29.8878 Tj
+-227 TJm
+(at) 7.193 Tj
+[1 0 0 1 441.74 387.171] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -441.74 -387.171] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+441.74 387.171 Td
+/F134_0 9.9626 Tf
+(unused) 35.8654 Tj
+[1 0 0 1 477.605 387.171] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -477.605 -387.171] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+477.605 387.171 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-232 TJm
+(before) 25.4445 Tj
+-227 TJm
+(starting) 29.8878 Tj
+72 375.216 Td
+(to) 7.7509 Tj
+-280 TJm
+(read) 17.1456 Tj
+-279 TJm
+(from) 19.3673 Tj
+-280 TJm
+(the) 12.1743 Tj
+-279 TJm
+(\002le) 12.7322 Tj
+[1 0 0 1 155.094 375.215] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.094 -375.215] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+155.094 375.215 Td
+/F134_0 9.9626 Tf
+(f) 5.97756 Tj
+[1 0 0 1 161.072 375.215] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.072 -375.215] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+161.072 375.215 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-797 TJm
+(At) 9.9626 Tj
+-280 TJm
+(most) 19.3773 Tj
+[1 0 0 1 206.414 375.215] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -206.414 -375.215] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+206.414 375.215 Td
+/F134_0 9.9626 Tf
+(BZ_MAX_UNUSED) 77.7083 Tj
+[1 0 0 1 284.122 375.215] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -284.122 -375.215] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+286.907 375.215 Td
+/F130_0 9.9626 Tf
+(bytes) 21.031 Tj
+-280 TJm
+(may) 17.1556 Tj
+-279 TJm
+(be) 9.40469 Tj
+-280 TJm
+(supplied) 33.7633 Tj
+-279 TJm
+(lik) 10.5205 Tj
+10 TJm
+(e) 4.42339 Tj
+-280 TJm
+(this.) 16.8866 Tj
+-797 TJm
+(If) 6.63509 Tj
+-279 TJm
+(this) 14.396 Tj
+-280 TJm
+(f) 3.31755 Tj
+10 TJm
+(acility) 24.9065 Tj
+-279 TJm
+(is) 6.64505 Tj
+-280 TJm
+(not) 12.7322 Tj
+-279 TJm
+(required,) 35.686 Tj
+72 363.26 Td
+(you) 14.9439 Tj
+-250 TJm
+(should) 26.5703 Tj
+-250 TJm
+(pass) 17.1556 Tj
+[1 0 0 1 138.141 363.26] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -138.141 -363.26] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+138.141 363.26 Td
+/F134_0 9.9626 Tf
+(NULL) 23.9102 Tj
+[1 0 0 1 162.052 363.26] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -162.052 -363.26] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+164.542 363.26 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 181.419 363.26] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -181.419 -363.26] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+181.419 363.26 Td
+/F134_0 9.9626 Tf
+(0) 5.97756 Tj
+[1 0 0 1 187.397 363.26] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -187.397 -363.26] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+189.887 363.26 Td
+/F130_0 9.9626 Tf
+(for) 11.6164 Tj
+[1 0 0 1 203.994 363.26] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -203.994 -363.26] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+203.994 363.26 Td
+/F134_0 9.9626 Tf
+(unused) 35.8654 Tj
+[1 0 0 1 239.86 363.26] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -239.86 -363.26] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+242.351 363.26 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+-250 TJm
+(n) 4.9813 Tj
+[1 0 0 1 264.208 363.26] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -264.208 -363.26] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+264.208 363.26 Td
+/F134_0 9.9626 Tf
+(Unused) 35.8654 Tj
+[1 0 0 1 300.074 363.26] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -300.074 -363.26] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+302.565 363.26 Td
+/F130_0 9.9626 Tf
+(respecti) 30.9837 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ely) 12.1743 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 361.103] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -351.141] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 341.343 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(meaning) 34.3112 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(parameters) 43.7059 Tj
+[1 0 0 1 196.631 341.343] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -196.631 -341.343] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+196.631 341.343 Td
+/F134_0 9.9626 Tf
+(small) 29.8878 Tj
+[1 0 0 1 226.519 341.343] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -226.519 -341.343] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+229.01 341.343 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 245.887 341.343] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -245.887 -341.343] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+245.887 341.343 Td
+/F134_0 9.9626 Tf
+(verbosity) 53.798 Tj
+[1 0 0 1 299.685 341.343] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -299.685 -341.343] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+299.685 341.343 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(see) 12.7222 Tj
+[1 0 0 1 319.879 341.343] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -319.879 -341.343] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+319.879 341.343 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressInit) 119.551 Tj
+[1 0 0 1 439.431 341.343] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -439.431 -341.343] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+439.431 341.343 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 339.186] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -329.223] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 319.425 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-402 TJm
+(amount) 29.8878 Tj
+-402 TJm
+(of) 8.29885 Tj
+-402 TJm
+(memory) 33.2053 Tj
+-402 TJm
+(needed) 28.2141 Tj
+-402 TJm
+(to) 7.7509 Tj
+-402 TJm
+(decompress) 47.0334 Tj
+-402 TJm
+(a) 4.42339 Tj
+-401 TJm
+(\002le) 12.7322 Tj
+-402 TJm
+(cannot) 26.5603 Tj
+-402 TJm
+(be) 9.40469 Tj
+-402 TJm
+(determined) 44.8217 Tj
+-402 TJm
+(until) 18.2714 Tj
+-402 TJm
+(the) 12.1743 Tj
+-402 TJm
+(\002le') 16.0497 Tj
+55 TJm
+(s) 3.87545 Tj
+-402 TJm
+(header) 26.5503 Tj
+-402 TJm
+(has) 13.2801 Tj
+-402 TJm
+(been) 18.8094 Tj
+-402 TJm
+(read.) 19.6363 Tj
+72 307.47 Td
+(So) 10.5205 Tj
+-492 TJm
+(it) 5.53921 Tj
+-491 TJm
+(is) 6.64505 Tj
+-492 TJm
+(possible) 32.6574 Tj
+-492 TJm
+(that) 14.9439 Tj
+[1 0 0 1 166.797 307.47] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -166.797 -307.47] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+166.797 307.47 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadOpen) 83.6858 Tj
+[1 0 0 1 250.483 307.47] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -250.483 -307.47] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+255.381 307.47 Td
+/F130_0 9.9626 Tf
+(returns) 27.6661 Tj
+[1 0 0 1 287.945 307.47] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -287.945 -307.47] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+287.945 307.47 Td
+/F134_0 9.9626 Tf
+(BZ_OK) 29.8878 Tj
+[1 0 0 1 317.833 307.47] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -317.833 -307.47] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+322.729 307.47 Td
+/F130_0 9.9626 Tf
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-492 TJm
+(a) 4.42339 Tj
+-491 TJm
+(subsequent) 44.2738 Tj
+-492 TJm
+(call) 14.386 Tj
+-492 TJm
+(of) 8.29885 Tj
+[1 0 0 1 431.135 307.47] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -431.135 -307.47] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+431.135 307.47 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 490.911 307.47] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -490.911 -307.47] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+495.81 307.47 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-492 TJm
+(return) 23.7907 Tj
+[1 0 0 1 72 295.514] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -295.514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 295.514 Td
+/F134_0 9.9626 Tf
+(BZ_MEM_ERROR) 71.7307 Tj
+[1 0 0 1 143.731 295.514] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.731 -295.514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+143.731 295.514 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 294.204] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -284.242] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 273.597 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(assignments) 48.7072 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 169.144 273.597] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.144 -273.597] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+169.144 273.597 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 210.987 273.597] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.987 -273.597] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.987 273.597 Td
+/F130_0 9.9626 Tf
+(:) 2.7696 Tj
+[1 0 0 1 72 271.44] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -168.369] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 167.372 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 163.786] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -262.075] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 262.075 Td
+/F134_0 9.9626 Tf
+(BZ_CONFIG_ERROR) 89.6634 Tj
+98.4879 250.12 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(library) 41.8429 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(mis-compiled) 71.7307 Tj
+90 238.165 Td
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 226.209 Td
+(if) 11.9551 Tj
+-426 TJm
+(f) 5.97756 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+98.4879 214.254 Td
+(or) 11.9551 Tj
+-426 TJm
+(small) 29.8878 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(neither) 41.8429 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(nor) 17.9327 Tj
+-426 TJm
+(1) 5.97756 Tj
+98.4879 202.299 Td
+(or) 11.9551 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(unused) 35.8654 Tj
+-426 TJm
+(==) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(&&) 11.9551 Tj
+-426 TJm
+(nUnused) 41.8429 Tj
+-426 TJm
+(!=) 11.9551 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(\)) 5.97756 Tj
+98.4879 190.344 Td
+(or) 11.9551 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(unused) 35.8654 Tj
+-426 TJm
+(!=) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(&&) 11.9551 Tj
+-426 TJm
+(!\(0) 17.9327 Tj
+-426 TJm
+(<=) 11.9551 Tj
+-426 TJm
+(nUnused) 41.8429 Tj
+-426 TJm
+(<=) 11.9551 Tj
+-426 TJm
+(BZ_MAX_UNUSED\)) 83.6858 Tj
+-426 TJm
+(\)) 5.97756 Tj
+90 178.389 Td
+(BZ_IO_ERROR) 65.7532 Tj
+98.4879 166.434 Td
+(if) 11.9551 Tj
+-426 TJm
+(ferror\(f\)) 53.798 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(nonzero) 41.8429 Tj
+90 154.478 Td
+(BZ_MEM_ERROR) 71.7307 Tj
+98.4879 142.523 Td
+(if) 11.9551 Tj
+-426 TJm
+(insufficient) 71.7307 Tj
+-426 TJm
+(memory) 35.8654 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(available) 53.798 Tj
+90 130.568 Td
+(BZ_OK) 29.8878 Tj
+98.4879 118.613 Td
+(otherwise.) 59.7756 Tj
+[1 0 0 1 72 103.071] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -93.1085] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 81.1533 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 81.0538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -30.202] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.9737] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -51.071] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 51.071 Td
+/F130_0 9.9626 Tf
+(19) 9.9626 Tj
+[1 0 0 1 453.269 50.8519] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 23 23
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -81.33] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 59.7758 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 56.1892] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(Pointer) 41.8429 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(an) 11.9551 Tj
+-426 TJm
+(abstract) 47.8205 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+98.4879 699.676 Td
+(if) 11.9551 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+90 687.721 Td
+(NULL) 23.9102 Tj
+98.4879 675.766 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 660.224] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5493] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -650.261] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 638.306 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(actions:) 30.9936 Tj
+[1 0 0 1 72 638.207] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -60.7721] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 59.7758 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 56.1893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -628.842] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 628.842 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+98.4879 616.887 Td
+(if) 11.9551 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+90 604.932 Td
+(BZ2_bzClose) 65.7532 Tj
+98.4879 592.976 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 577.435] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -567.472] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 546.813 Td
+/F122_0 17.2154 Tf
+(3.4.2.) 43.0729 Tj
+[1 0 0 1 119.858 546.813] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -546.813] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 546.813 Td
+/F392_0 17.2154 Tf
+(BZ2_bzRead) 103.292 Tj
+[1 0 0 1 223.15 546.813] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -151.15 -2.3326] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -535.116] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 535.116 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzRead) 59.7756 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(int) 17.9327 Tj
+208.595 533.373 Td
+(*) 5.97756 Tj
+214.572 535.116 Td
+(bzerror,) 47.8205 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+306.747 533.373 Td
+(*) 5.97756 Tj
+312.724 535.116 Td
+(b,) 11.9551 Tj
+-426 TJm
+(void) 23.9102 Tj
+357.077 533.373 Td
+(*) 5.97756 Tj
+363.055 535.116 Td
+(buf,) 23.9102 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(len) 17.9327 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 519.574] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -509.612] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 497.656 Td
+/F130_0 9.9626 Tf
+(Reads) 24.3486 Tj
+-285 TJm
+(up) 9.9626 Tj
+-284 TJm
+(to) 7.7509 Tj
+[1 0 0 1 122.569 497.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -122.569 -497.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+122.569 497.656 Td
+/F134_0 9.9626 Tf
+(len) 17.9327 Tj
+[1 0 0 1 140.501 497.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -140.501 -497.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+143.337 497.656 Td
+/F130_0 9.9626 Tf
+(\(uncompressed\)) 63.6311 Tj
+-285 TJm
+(bytes) 21.031 Tj
+-284 TJm
+(from) 19.3673 Tj
+-285 TJm
+(the) 12.1743 Tj
+-284 TJm
+(compressed) 47.0334 Tj
+-285 TJm
+(\002le) 12.7322 Tj
+[1 0 0 1 336.319 497.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -336.319 -497.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+336.319 497.656 Td
+/F134_0 9.9626 Tf
+(b) 5.97756 Tj
+[1 0 0 1 342.296 497.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.296 -497.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+345.132 497.656 Td
+/F130_0 9.9626 Tf
+(into) 15.5018 Tj
+-285 TJm
+(the) 12.1743 Tj
+-284 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+[1 0 0 1 405.205 497.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -405.205 -497.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+405.205 497.656 Td
+/F134_0 9.9626 Tf
+(buf) 17.9327 Tj
+[1 0 0 1 423.137 497.656] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -423.137 -497.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+423.137 497.656 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-828 TJm
+(If) 6.63509 Tj
+-284 TJm
+(the) 12.1743 Tj
+-285 TJm
+(read) 17.1456 Tj
+-285 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-284 TJm
+(successful,) 43.4369 Tj
+[1 0 0 1 72 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 485.701 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 113.843 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.843 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+117.36 485.701 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-353 TJm
+(set) 11.0684 Tj
+-353 TJm
+(to) 7.7509 Tj
+[1 0 0 1 153.374 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -153.374 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+153.374 485.701 Td
+/F134_0 9.9626 Tf
+(BZ_OK) 29.8878 Tj
+[1 0 0 1 183.262 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -183.262 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+186.778 485.701 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+-353 TJm
+(the) 12.1743 Tj
+-353 TJm
+(number) 30.4357 Tj
+-353 TJm
+(of) 8.29885 Tj
+-353 TJm
+(bytes) 21.031 Tj
+-353 TJm
+(read) 17.1456 Tj
+-353 TJm
+(is) 6.64505 Tj
+-353 TJm
+(returned.) 35.686 Tj
+-1238 TJm
+(If) 6.63509 Tj
+-353 TJm
+(the) 12.1743 Tj
+-353 TJm
+(logical) 27.1182 Tj
+-353 TJm
+(end-of-stream) 55.8802 Tj
+-353 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-353 TJm
+(detected,) 35.686 Tj
+[1 0 0 1 72 473.746] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -473.746] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 473.746 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 113.843 473.746] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.843 -473.746] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+116.795 473.746 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-296 TJm
+(be) 9.40469 Tj
+-297 TJm
+(set) 11.0684 Tj
+-296 TJm
+(to) 7.7509 Tj
+[1 0 0 1 172.329 473.746] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -172.329 -473.746] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+172.329 473.746 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 250.037 473.746] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -250.037 -473.746] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+250.037 473.746 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-296 TJm
+(and) 14.386 Tj
+-297 TJm
+(the) 12.1743 Tj
+-296 TJm
+(number) 30.4357 Tj
+-296 TJm
+(of) 8.29885 Tj
+-297 TJm
+(bytes) 21.031 Tj
+-296 TJm
+(read) 17.1456 Tj
+-296 TJm
+(is) 6.64505 Tj
+-296 TJm
+(returned.) 35.686 Tj
+-898 TJm
+(All) 12.7322 Tj
+-297 TJm
+(other) 20.4731 Tj
+[1 0 0 1 470 473.746] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -470 -473.746] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+470 473.746 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 511.843 473.746] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -511.843 -473.746] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+514.795 473.746 Td
+/F130_0 9.9626 Tf
+(v) 4.9813 Tj
+25 TJm
+(alues) 20.4731 Tj
+72 461.791 Td
+(denote) 26.5603 Tj
+-250 TJm
+(an) 9.40469 Tj
+-250 TJm
+(error) 19.3573 Tj
+55 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 461.691] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -451.729] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 439.873 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 131.776 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -131.776 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+134.224 439.873 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-246 TJm
+(supply) 26.5703 Tj
+[1 0 0 1 181.193 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -181.193 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+181.193 439.873 Td
+/F134_0 9.9626 Tf
+(len) 17.9327 Tj
+[1 0 0 1 199.126 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -199.126 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+201.575 439.873 Td
+/F130_0 9.9626 Tf
+(bytes,) 23.5217 Tj
+-247 TJm
+(unless) 24.9065 Tj
+-245 TJm
+(the) 12.1743 Tj
+-246 TJm
+(logical) 27.1182 Tj
+-246 TJm
+(stream) 26.5603 Tj
+-246 TJm
+(end) 14.386 Tj
+-245 TJm
+(is) 6.64505 Tj
+-246 TJm
+(detected) 33.1954 Tj
+-246 TJm
+(or) 8.29885 Tj
+-246 TJm
+(an) 9.40469 Tj
+-246 TJm
+(error) 19.3573 Tj
+-245 TJm
+(occurs.) 28.493 Tj
+-617 TJm
+(Because) 33.1954 Tj
+-246 TJm
+(of) 8.29885 Tj
+-246 TJm
+(this,) 16.8866 Tj
+-247 TJm
+(it) 5.53921 Tj
+72 427.918 Td
+(is) 6.64505 Tj
+-231 TJm
+(possible) 32.6574 Tj
+-231 TJm
+(to) 7.7509 Tj
+-231 TJm
+(detect) 23.7907 Tj
+-231 TJm
+(the) 12.1743 Tj
+-231 TJm
+(stream) 26.5603 Tj
+-231 TJm
+(end) 14.386 Tj
+-232 TJm
+(by) 9.9626 Tj
+-231 TJm
+(observing) 39.2925 Tj
+-231 TJm
+(when) 21.579 Tj
+-231 TJm
+(the) 12.1743 Tj
+-231 TJm
+(number) 30.4357 Tj
+-231 TJm
+(of) 8.29885 Tj
+-231 TJm
+(bytes) 21.031 Tj
+-231 TJm
+(returned) 33.1954 Tj
+-231 TJm
+(is) 6.64505 Tj
+-231 TJm
+(less) 14.9439 Tj
+-231 TJm
+(than) 17.1556 Tj
+-232 TJm
+(the) 12.1743 Tj
+-231 TJm
+(number) 30.4357 Tj
+-231 TJm
+(requested.) 40.6673 Tj
+72 415.963 Td
+(Ne) 11.6164 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ertheless,) 37.3498 Tj
+-309 TJm
+(this) 14.396 Tj
+-297 TJm
+(is) 6.64505 Tj
+-298 TJm
+(re) 7.74094 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(arded) 22.1269 Tj
+-297 TJm
+(as) 8.29885 Tj
+-297 TJm
+(inadvisable;) 48.1492 Tj
+-321 TJm
+(you) 14.9439 Tj
+-298 TJm
+(should) 26.5703 Tj
+-297 TJm
+(instead) 28.224 Tj
+-297 TJm
+(check) 23.2328 Tj
+[1 0 0 1 360.631 415.963] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -360.631 -415.963] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+360.631 415.963 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 402.475 415.963] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -402.475 -415.963] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+405.437 415.963 Td
+/F130_0 9.9626 Tf
+(after) 18.2515 Tj
+-297 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ery) 12.7222 Tj
+-298 TJm
+(call) 14.386 Tj
+-297 TJm
+(and) 14.386 Tj
+-297 TJm
+(w) 7.193 Tj
+10 TJm
+(atch) 16.5977 Tj
+-298 TJm
+(out) 12.7322 Tj
+-297 TJm
+(for) 11.6164 Tj
+[1 0 0 1 72 404.008] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -404.008] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 404.008 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 149.709 404.008] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -149.709 -404.008] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+149.709 404.008 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 402.698] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -392.735] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 382.09 Td
+/F130_0 9.9626 Tf
+(Internally) 38.7346 Tj
+65 TJm
+(,) 2.49065 Tj
+[1 0 0 1 117.541 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -117.541 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+117.541 382.09 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 177.317 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -177.317 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+181.786 382.09 Td
+/F130_0 9.9626 Tf
+(copies) 25.4544 Tj
+-449 TJm
+(data) 16.5977 Tj
+-448 TJm
+(from) 19.3673 Tj
+-449 TJm
+(the) 12.1743 Tj
+-448 TJm
+(compressed) 47.0334 Tj
+-449 TJm
+(\002le) 12.7322 Tj
+-448 TJm
+(in) 7.7509 Tj
+-449 TJm
+(chunks) 28.224 Tj
+-449 TJm
+(of) 8.29885 Tj
+-448 TJm
+(size) 15.4918 Tj
+[1 0 0 1 419.602 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -419.602 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.602 382.09 Td
+/F134_0 9.9626 Tf
+(BZ_MAX_UNUSED) 77.7083 Tj
+[1 0 0 1 497.31 382.09] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -497.31 -382.09] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+501.778 382.09 Td
+/F130_0 9.9626 Tf
+(bytes) 21.031 Tj
+-449 TJm
+(be-) 12.7222 Tj
+72 370.135 Td
+(fore) 16.0398 Tj
+-414 TJm
+(decompressing) 59.7656 Tj
+-414 TJm
+(it.) 8.02986 Tj
+-1605 TJm
+(If) 6.63509 Tj
+-415 TJm
+(the) 12.1743 Tj
+-414 TJm
+(\002le) 12.7322 Tj
+-414 TJm
+(contains) 33.2053 Tj
+-414 TJm
+(more) 20.4731 Tj
+-414 TJm
+(bytes) 21.031 Tj
+-415 TJm
+(than) 17.1556 Tj
+-414 TJm
+(strictly) 27.6761 Tj
+-414 TJm
+(needed) 28.2141 Tj
+-414 TJm
+(to) 7.7509 Tj
+-414 TJm
+(reach) 21.569 Tj
+-414 TJm
+(the) 12.1743 Tj
+-415 TJm
+(logical) 27.1182 Tj
+-414 TJm
+(end-of-stream,) 58.3709 Tj
+[1 0 0 1 72 358.18] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -358.18] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 358.18 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 131.776 358.18] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -131.776 -358.18] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+134.749 358.18 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-298 TJm
+(almost) 26.5703 Tj
+-299 TJm
+(certainly) 34.8591 Tj
+-298 TJm
+(read) 17.1456 Tj
+-299 TJm
+(some) 21.031 Tj
+-298 TJm
+(of) 8.29885 Tj
+-299 TJm
+(the) 12.1743 Tj
+-298 TJm
+(trailing) 28.782 Tj
+-298 TJm
+(data) 16.5977 Tj
+-299 TJm
+(before) 25.4445 Tj
+-298 TJm
+(signalling) 39.3025 Tj
+[1 0 0 1 413.162 358.18] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -413.162 -358.18] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+413.162 358.18 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_END) 89.6634 Tj
+[1 0 0 1 502.826 358.18] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -502.826 -358.18] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+502.826 358.18 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-597 TJm
+(T) 6.08715 Tj
+80 TJm
+(o) 4.9813 Tj
+-298 TJm
+(col-) 15.4918 Tj
+72 346.224 Td
+(lect) 14.386 Tj
+-242 TJm
+(the) 12.1743 Tj
+-242 TJm
+(read) 17.1456 Tj
+-243 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-242 TJm
+(unused) 28.224 Tj
+-242 TJm
+(data) 16.5977 Tj
+-242 TJm
+(once) 18.8094 Tj
+[1 0 0 1 208.759 346.224] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -208.759 -346.224] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+208.759 346.224 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_END) 89.6634 Tj
+[1 0 0 1 298.423 346.224] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -298.423 -346.224] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+300.835 346.224 Td
+/F130_0 9.9626 Tf
+(has) 13.2801 Tj
+-242 TJm
+(appeared,) 38.4457 Tj
+-244 TJm
+(call) 14.386 Tj
+[1 0 0 1 374.201 346.224] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -374.201 -346.224] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+374.201 346.224 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadGetUnused) 113.574 Tj
+[1 0 0 1 487.775 346.224] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -487.775 -346.224] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+490.188 346.224 Td
+/F130_0 9.9626 Tf
+(immediately) 49.813 Tj
+72 334.269 Td
+(before) 25.4445 Tj
+[1 0 0 1 99.935 334.269] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -99.935 -334.269] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+99.935 334.269 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 189.599 334.269] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -189.599 -334.269] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+189.599 334.269 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 332.959] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -322.996] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 312.351 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(assignments) 48.7072 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 169.144 312.351] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.144 -312.351] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+169.144 312.351 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 210.987 312.351] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.987 -312.351] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.987 312.351 Td
+/F130_0 9.9626 Tf
+(:) 2.7696 Tj
+[1 0 0 1 72 310.195] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -259.343] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(20) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 24 24
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -284.568] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 263.014 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 259.427] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 699.676 Td
+(if) 11.9551 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(buf) 17.9327 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(len) 17.9327 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(0) 5.97756 Tj
+90 687.721 Td
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+98.4879 675.766 Td
+(if) 11.9551 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(opened) 35.8654 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(BZ2_bzWriteOpen) 89.6634 Tj
+90 663.811 Td
+(BZ_IO_ERROR) 65.7532 Tj
+98.4879 651.856 Td
+(if) 11.9551 Tj
+-426 TJm
+(there) 29.8878 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(an) 11.9551 Tj
+-426 TJm
+(error) 29.8878 Tj
+-426 TJm
+(reading) 41.8429 Tj
+-426 TJm
+(from) 23.9102 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(file) 23.9102 Tj
+90 639.9 Td
+(BZ_UNEXPECTED_EOF) 101.619 Tj
+98.4879 627.945 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(file) 23.9102 Tj
+-426 TJm
+(ended) 29.8878 Tj
+-426 TJm
+(before) 35.8654 Tj
+98.4879 615.99 Td
+(the) 17.9327 Tj
+-426 TJm
+(logical) 41.8429 Tj
+-426 TJm
+(end-of-stream) 77.7083 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(detected) 47.8205 Tj
+90 604.035 Td
+(BZ_DATA_ERROR) 77.7083 Tj
+98.4879 592.08 Td
+(if) 11.9551 Tj
+-426 TJm
+(a) 5.97756 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(integrity) 53.798 Tj
+-426 TJm
+(error) 29.8878 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(detected) 47.8205 Tj
+-426 TJm
+(in) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(stream) 35.8654 Tj
+90 580.125 Td
+(BZ_DATA_ERROR_MAGIC) 113.574 Tj
+98.4879 568.169 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(stream) 35.8654 Tj
+-426 TJm
+(does) 23.9102 Tj
+-426 TJm
+(not) 17.9327 Tj
+-426 TJm
+(begin) 29.8878 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(requisite) 53.798 Tj
+-426 TJm
+(header) 35.8654 Tj
+-426 TJm
+(bytes) 29.8878 Tj
+98.4879 556.214 Td
+(\(ie,) 23.9102 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(not) 17.9327 Tj
+-426 TJm
+(a) 5.97756 Tj
+-426 TJm
+(bzip2) 29.8878 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(file\).) 35.8654 Tj
+-852 TJm
+(This) 23.9102 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(really) 35.8654 Tj
+98.4879 544.259 Td
+(a) 5.97756 Tj
+-426 TJm
+(special) 41.8429 Tj
+-426 TJm
+(case) 23.9102 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(BZ_DATA_ERROR.) 83.6858 Tj
+90 532.304 Td
+(BZ_MEM_ERROR) 71.7307 Tj
+98.4879 520.349 Td
+(if) 11.9551 Tj
+-426 TJm
+(insufficient) 71.7307 Tj
+-426 TJm
+(memory) 35.8654 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(available) 53.798 Tj
+90 508.394 Td
+(BZ_STREAM_END) 77.7083 Tj
+98.4879 496.438 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(logical) 41.8429 Tj
+-426 TJm
+(end) 17.9327 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(stream) 35.8654 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(detected.) 53.798 Tj
+90 484.483 Td
+(BZ_OK) 29.8878 Tj
+98.4879 472.528 Td
+(otherwise.) 59.7756 Tj
+[1 0 0 1 72 456.986] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -447.024] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 435.068 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 434.969] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -60.7721] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 59.7758 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 56.1893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -425.604] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 425.604 Td
+/F134_0 9.9626 Tf
+(number) 35.8654 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(bytes) 29.8878 Tj
+-426 TJm
+(read) 23.9102 Tj
+98.4879 413.649 Td
+(if) 11.9551 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(BZ_STREAM_END) 77.7083 Tj
+90 401.694 Td
+(undefined) 53.798 Tj
+98.4879 389.739 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 374.197] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -364.234] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 352.279 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(actions:) 30.9936 Tj
+[1 0 0 1 72 352.18] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -84.6825] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 83.6862 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 80.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -342.815] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 342.815 Td
+/F134_0 9.9626 Tf
+(collect) 41.8429 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(from) 23.9102 Tj
+-426 TJm
+(buf,) 23.9102 Tj
+-426 TJm
+(then) 23.9102 Tj
+-426 TJm
+(BZ2_bzRead) 59.7756 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(BZ2_bzReadClose) 89.6634 Tj
+98.4879 330.859 Td
+(if) 11.9551 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+90 318.904 Td
+(collect) 41.8429 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(from) 23.9102 Tj
+-426 TJm
+(buf,) 23.9102 Tj
+-426 TJm
+(then) 23.9102 Tj
+-426 TJm
+(BZ2_bzReadClose) 89.6634 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(BZ2_bzReadGetUnused) 113.574 Tj
+98.4879 306.949 Td
+(if) 11.9551 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(BZ_SEQUENCE_END) 89.6634 Tj
+90 294.994 Td
+(BZ2_bzReadClose) 89.6634 Tj
+98.4879 283.039 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 267.497] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -257.534] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 236.876 Td
+/F122_0 17.2154 Tf
+(3.4.3.) 43.0729 Tj
+[1 0 0 1 119.858 236.876] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -236.876] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 236.876 Td
+/F392_0 17.2154 Tf
+(BZ2_bzReadGetUnused) 196.256 Tj
+[1 0 0 1 316.114 236.876] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -244.114 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -36.8617] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 35.8655 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 32.2789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -225.178] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 225.178 Td
+/F134_0 9.9626 Tf
+(void) 23.9102 Tj
+-426 TJm
+(BZ2_bzReadGetUnused\() 119.551 Tj
+-426 TJm
+(int) 17.9327 Tj
+259.883 223.435 Td
+(*) 5.97756 Tj
+270.104 225.178 Td
+(bzerror,) 47.8205 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+362.278 223.435 Td
+(*) 5.97756 Tj
+368.256 225.178 Td
+(b,) 11.9551 Tj
+200.343 213.223 Td
+(void) 23.9102 Tj
+224.254 211.48 Td
+(**) 11.9551 Tj
+240.453 213.223 Td
+(unused,) 41.8429 Tj
+-426 TJm
+(int) 17.9327 Tj
+304.473 211.48 Td
+(*) 5.97756 Tj
+314.694 213.223 Td
+(nUnused) 41.8429 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 197.681] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -187.719] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 175.764 Td
+/F130_0 9.9626 Tf
+(Returns) 30.9936 Tj
+-435 TJm
+(data) 16.5977 Tj
+-435 TJm
+(which) 24.3486 Tj
+-435 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-435 TJm
+(read) 17.1456 Tj
+-435 TJm
+(from) 19.3673 Tj
+-435 TJm
+(the) 12.1743 Tj
+-435 TJm
+(compressed) 47.0334 Tj
+-435 TJm
+(\002le) 12.7322 Tj
+-435 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-435 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-435 TJm
+(not) 12.7322 Tj
+-435 TJm
+(needed) 28.2141 Tj
+-435 TJm
+(to) 7.7509 Tj
+-435 TJm
+(get) 12.1743 Tj
+-435 TJm
+(to) 7.7509 Tj
+-435 TJm
+(the) 12.1743 Tj
+-435 TJm
+(logical) 27.1182 Tj
+-435 TJm
+(end-of-stream.) 58.3709 Tj
+[1 0 0 1 72 163.809] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -163.809] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 162.065 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+77.9776 163.809 Td
+(unused) 35.8654 Tj
+[1 0 0 1 113.843 163.809] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.843 -163.809] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+117.2 163.809 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-337 TJm
+(set) 11.0684 Tj
+-337 TJm
+(to) 7.7509 Tj
+-337 TJm
+(the) 12.1743 Tj
+-337 TJm
+(address) 29.8778 Tj
+-337 TJm
+(of) 8.29885 Tj
+-336 TJm
+(the) 12.1743 Tj
+-337 TJm
+(data,) 19.0883 Tj
+-359 TJm
+(and) 14.386 Tj
+[1 0 0 1 269.089 163.809] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -269.089 -163.809] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+269.089 162.065 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+275.067 163.809 Td
+(nUnused) 41.8429 Tj
+[1 0 0 1 316.91 163.809] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -316.91 -163.809] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+320.267 163.809 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-337 TJm
+(the) 12.1743 Tj
+-337 TJm
+(number) 30.4357 Tj
+-337 TJm
+(of) 8.29885 Tj
+-337 TJm
+(bytes.) 23.5217 Tj
+[1 0 0 1 427.247 163.809] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -427.247 -163.809] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+427.247 162.065 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+433.225 163.809 Td
+(nUnused) 41.8429 Tj
+[1 0 0 1 475.068 163.809] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -475.068 -163.809] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+478.425 163.809 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-337 TJm
+(be) 9.40469 Tj
+-337 TJm
+(set) 11.0684 Tj
+-337 TJm
+(to) 7.7509 Tj
+-337 TJm
+(a) 4.42339 Tj
+72 151.853 Td
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+-250 TJm
+(between) 33.1954 Tj
+[1 0 0 1 131.506 151.853] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -131.506 -151.853] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+131.506 151.853 Td
+/F134_0 9.9626 Tf
+(0) 5.97756 Tj
+[1 0 0 1 137.484 151.853] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.484 -151.853] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+139.975 151.853 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 156.851 151.853] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -156.851 -151.853] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+156.851 151.853 Td
+/F134_0 9.9626 Tf
+(BZ_MAX_UNUSED) 77.7083 Tj
+[1 0 0 1 234.56 151.853] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -234.56 -151.853] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+237.05 151.853 Td
+/F130_0 9.9626 Tf
+(inclusi) 26.5703 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e.) 6.91404 Tj
+[1 0 0 1 72 150.543] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -140.581] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 129.935 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-882 TJm
+(function) 33.2053 Tj
+-883 TJm
+(may) 17.1556 Tj
+-882 TJm
+(only) 17.7135 Tj
+-883 TJm
+(be) 9.40469 Tj
+-882 TJm
+(called) 23.7907 Tj
+-883 TJm
+(once) 18.8094 Tj
+[1 0 0 1 271.332 129.935] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -271.332 -129.935] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+271.332 129.935 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 331.108 129.935] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -331.108 -129.935] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+339.9 129.935 Td
+/F130_0 9.9626 Tf
+(has) 13.2801 Tj
+-882 TJm
+(signalled) 35.9749 Tj
+[1 0 0 1 406.737 129.935] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -406.737 -129.935] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+406.737 129.935 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 484.446 129.935] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -484.446 -129.935] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+493.231 129.935 Td
+/F130_0 9.9626 Tf
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-882 TJm
+(before) 25.4445 Tj
+[1 0 0 1 72 117.98] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -117.98] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 117.98 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 161.664 117.98] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.664 -117.98] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+161.664 117.98 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 116.67] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -106.708] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 96.0625 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(assignments) 48.7072 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 169.144 96.0625] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.144 -96.0625] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+169.144 96.0625 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 210.987 96.0625] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.987 -96.0625] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.987 96.0625 Td
+/F130_0 9.9626 Tf
+(:) 2.7696 Tj
+[1 0 0 1 72 93.9057] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -43.0539] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.8518] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.8518 Td
+/F130_0 9.9626 Tf
+(21) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 25 25
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -129.151] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 107.597 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 104.01] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 699.676 Td
+(if) 11.9551 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+98.4879 687.721 Td
+(or) 11.9551 Tj
+-426 TJm
+(unused) 35.8654 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(nUnused) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+90 675.766 Td
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+98.4879 663.811 Td
+(if) 11.9551 Tj
+-426 TJm
+(BZ_STREAM_END) 77.7083 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(not) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(signalled) 53.798 Tj
+98.4879 651.856 Td
+(or) 11.9551 Tj
+-426 TJm
+(if) 11.9551 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(opened) 35.8654 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(BZ2_bzWriteOpen) 89.6634 Tj
+90 639.9 Td
+(BZ_OK) 29.8878 Tj
+98.4879 627.945 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 612.404] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -602.441] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 590.486 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(actions:) 30.9936 Tj
+[1 0 0 1 72 590.386] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3238] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -581.021] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 581.021 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 72 565.48] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -555.517] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 534.858 Td
+/F122_0 17.2154 Tf
+(3.4.4.) 43.0729 Tj
+[1 0 0 1 119.858 534.858] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -534.858] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 534.858 Td
+/F392_0 17.2154 Tf
+(BZ2_bzReadClose) 154.939 Tj
+[1 0 0 1 274.797 534.858] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -202.797 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -523.161] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 523.161 Td
+/F134_0 9.9626 Tf
+(void) 23.9102 Tj
+-426 TJm
+(BZ2_bzReadClose) 89.6634 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(int) 17.9327 Tj
+244.46 521.417 Td
+(*) 5.97756 Tj
+250.438 523.161 Td
+(bzerror,) 47.8205 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+342.612 521.417 Td
+(*) 5.97756 Tj
+348.59 523.161 Td
+(b) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 507.619] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -497.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 485.701 Td
+/F130_0 9.9626 Tf
+(Releases) 34.8591 Tj
+-430 TJm
+(all) 9.9626 Tj
+-429 TJm
+(memory) 33.2053 Tj
+-430 TJm
+(pertaining) 40.3983 Tj
+-429 TJm
+(to) 7.7509 Tj
+-430 TJm
+(the) 12.1743 Tj
+-429 TJm
+(compressed) 47.0334 Tj
+-430 TJm
+(\002le) 12.7322 Tj
+[1 0 0 1 304.352 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -304.352 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+304.352 485.701 Td
+/F134_0 9.9626 Tf
+(b) 5.97756 Tj
+[1 0 0 1 310.33 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -310.33 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+310.33 485.701 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 321.276 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -321.276 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+321.276 485.701 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 410.94 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -410.94 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+415.22 485.701 Td
+/F130_0 9.9626 Tf
+(does) 18.2614 Tj
+-430 TJm
+(not) 12.7322 Tj
+-429 TJm
+(call) 14.386 Tj
+[1 0 0 1 473.438 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -473.438 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+473.438 485.701 Td
+/F134_0 9.9626 Tf
+(fclose) 35.8654 Tj
+[1 0 0 1 509.304 485.701] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -509.304 -485.701] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+513.584 485.701 Td
+/F130_0 9.9626 Tf
+(on) 9.9626 Tj
+-430 TJm
+(the) 12.1743 Tj
+72 473.746 Td
+(underlying) 43.1679 Tj
+-264 TJm
+(\002le) 12.7322 Tj
+-264 TJm
+(handle,) 29.0509 Tj
+-267 TJm
+(so) 8.85675 Tj
+-264 TJm
+(you) 14.9439 Tj
+-264 TJm
+(should) 26.5703 Tj
+-264 TJm
+(do) 9.9626 Tj
+-264 TJm
+(that) 14.9439 Tj
+-264 TJm
+(yourself) 32.6474 Tj
+-264 TJm
+(if) 6.08715 Tj
+-263 TJm
+(appropriate.) 47.8603 Tj
+[1 0 0 1 348.653 473.746] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -348.653 -473.746] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+348.653 473.746 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 438.317 473.746] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -438.317 -473.746] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+440.946 473.746 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-264 TJm
+(be) 9.40469 Tj
+-264 TJm
+(called) 23.7907 Tj
+-264 TJm
+(to) 7.7509 Tj
+-264 TJm
+(clean) 21.0211 Tj
+72 461.791 Td
+(up) 9.9626 Tj
+-250 TJm
+(after) 18.2515 Tj
+-250 TJm
+(all) 9.9626 Tj
+-250 TJm
+(error) 19.3573 Tj
+-250 TJm
+(situations.) 40.6873 Tj
+[1 0 0 1 72 459.634] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -449.671] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 439.873 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(assignments) 48.7072 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 169.144 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.144 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+169.144 439.873 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 210.987 439.873] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.987 -439.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.987 439.873 Td
+/F130_0 9.9626 Tf
+(:) 2.7696 Tj
+[1 0 0 1 72 437.716] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -60.7721] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 59.7758 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 56.1893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -428.351] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 428.351 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+98.4879 416.396 Td
+(if) 11.9551 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(opened) 35.8654 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(BZ2_bzOpenWrite) 89.6634 Tj
+90 404.441 Td
+(BZ_OK) 29.8878 Tj
+98.4879 392.486 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 376.944] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -366.982] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 355.026 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(actions:) 30.9936 Tj
+[1 0 0 1 72 354.927] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -345.562] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 345.562 Td
+/F134_0 9.9626 Tf
+(none) 23.9102 Tj
+[1 0 0 1 72 330.02] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -320.058] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 299.399 Td
+/F122_0 17.2154 Tf
+(3.4.5.) 43.0729 Tj
+[1 0 0 1 119.858 299.399] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -299.399] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 299.399 Td
+/F392_0 17.2154 Tf
+(BZ2_bzWriteOpen) 154.939 Tj
+[1 0 0 1 274.797 299.399] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -202.797 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -48.8169] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 47.8207 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 44.2341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -287.702] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 287.702 Td
+/F134_0 9.9626 Tf
+(BZFILE) 35.8654 Tj
+130.109 285.958 Td
+(*) 5.97756 Tj
+136.087 287.702 Td
+(BZ2_bzWriteOpen\() 95.641 Tj
+-426 TJm
+(int) 17.9327 Tj
+258.149 285.958 Td
+(*) 5.97756 Tj
+264.127 287.702 Td
+(bzerror,) 47.8205 Tj
+-426 TJm
+(FILE) 23.9102 Tj
+344.346 285.958 Td
+(*) 5.97756 Tj
+350.323 287.702 Td
+(f,) 11.9551 Tj
+196.099 275.746 Td
+(int) 17.9327 Tj
+-426 TJm
+(blockSize100k,) 83.6858 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(verbosity,) 59.7756 Tj
+196.099 263.791 Td
+(int) 17.9327 Tj
+-426 TJm
+(workFactor) 59.7756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 248.249] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -238.287] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 226.332 Td
+/F130_0 9.9626 Tf
+(Prepare) 30.4258 Tj
+-268 TJm
+(to) 7.7509 Tj
+-269 TJm
+(write) 20.4731 Tj
+-268 TJm
+(compressed) 47.0334 Tj
+-269 TJm
+(data) 16.5977 Tj
+-268 TJm
+(to) 7.7509 Tj
+-269 TJm
+(\002le) 12.7322 Tj
+-268 TJm
+(handle) 26.5603 Tj
+[1 0 0 1 262.72 226.332] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -262.72 -226.332] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+262.72 226.332 Td
+/F134_0 9.9626 Tf
+(f) 5.97756 Tj
+[1 0 0 1 268.698 226.332] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -268.698 -226.332] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+268.698 226.332 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 274.829 226.332] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -274.829 -226.332] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+274.829 226.332 Td
+/F134_0 9.9626 Tf
+(f) 5.97756 Tj
+[1 0 0 1 280.807 226.332] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -280.807 -226.332] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+283.481 226.332 Td
+/F130_0 9.9626 Tf
+(should) 26.5703 Tj
+-268 TJm
+(refer) 18.7994 Tj
+-269 TJm
+(to) 7.7509 Tj
+-268 TJm
+(a) 4.42339 Tj
+-269 TJm
+(\002le) 12.7322 Tj
+-268 TJm
+(which) 24.3486 Tj
+-269 TJm
+(has) 13.2801 Tj
+-268 TJm
+(been) 18.8094 Tj
+-269 TJm
+(opened) 28.772 Tj
+-268 TJm
+(for) 11.6164 Tj
+-269 TJm
+(writing,) 31.2726 Tj
+-273 TJm
+(and) 14.386 Tj
+-268 TJm
+(for) 11.6164 Tj
+72 214.377 Td
+(which) 24.3486 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(error) 19.3573 Tj
+-250 TJm
+(indicator) 35.417 Tj
+-250 TJm
+(\() 3.31755 Tj
+[1 0 0 1 176.577 214.376] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -176.577 -214.376] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+176.577 214.376 Td
+/F134_0 9.9626 Tf
+(ferror\(f\)) 53.798 Tj
+[1 0 0 1 230.375 214.376] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -230.375 -214.376] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+230.375 214.376 Td
+/F130_0 9.9626 Tf
+(\)is) 9.9626 Tj
+-250 TJm
+(not) 12.7322 Tj
+-250 TJm
+(set.) 13.5591 Tj
+[1 0 0 1 72 212.593] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -202.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 192.459 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-223 TJm
+(the) 12.1743 Tj
+-224 TJm
+(meaning) 34.3112 Tj
+-223 TJm
+(of) 8.29885 Tj
+-224 TJm
+(parameters) 43.7059 Tj
+[1 0 0 1 195.306 192.459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -195.306 -192.459] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+195.306 192.459 Td
+/F134_0 9.9626 Tf
+(blockSize100k) 77.7083 Tj
+[1 0 0 1 273.015 192.459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -273.015 -192.459] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+273.015 192.459 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 277.784 192.459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -277.784 -192.459] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+277.784 192.459 Td
+/F134_0 9.9626 Tf
+(verbosity) 53.798 Tj
+[1 0 0 1 331.583 192.459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -331.583 -192.459] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+333.808 192.459 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 350.42 192.459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -350.42 -192.459] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+350.42 192.459 Td
+/F134_0 9.9626 Tf
+(workFactor) 59.7756 Tj
+[1 0 0 1 410.196 192.459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -410.196 -192.459] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+410.196 192.459 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-229 TJm
+(see) 12.7222 Tj
+[1 0 0 1 429.913 192.459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -429.913 -192.459] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+429.913 192.459 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 537.509 192.459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -537.509 -192.459] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+537.509 192.459 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 190.302] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -180.339] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 170.541 Td
+/F130_0 9.9626 Tf
+(All) 12.7322 Tj
+-382 TJm
+(required) 33.1954 Tj
+-382 TJm
+(memory) 33.2053 Tj
+-382 TJm
+(is) 6.64505 Tj
+-382 TJm
+(allocated) 35.965 Tj
+-383 TJm
+(at) 7.193 Tj
+-382 TJm
+(this) 14.396 Tj
+-382 TJm
+(stage,) 22.9638 Tj
+-415 TJm
+(so) 8.85675 Tj
+-382 TJm
+(if) 6.08715 Tj
+-382 TJm
+(the) 12.1743 Tj
+-382 TJm
+(call) 14.386 Tj
+-382 TJm
+(completes) 40.3983 Tj
+-382 TJm
+(successfully) 48.6972 Tj
+65 TJm
+(,) 2.49065 Tj
+[1 0 0 1 424.691 170.541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -424.691 -170.541] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+424.691 170.541 Td
+/F134_0 9.9626 Tf
+(BZ_MEM_ERROR) 71.7307 Tj
+[1 0 0 1 496.422 170.541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.422 -170.541] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+500.228 170.541 Td
+/F130_0 9.9626 Tf
+(cannot) 26.5603 Tj
+-382 TJm
+(be) 9.40469 Tj
+72 158.586 Td
+(signalled) 35.9749 Tj
+-250 TJm
+(by) 9.9626 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(subsequent) 44.2738 Tj
+-250 TJm
+(call) 14.386 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 203.715 158.586] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -203.715 -158.586] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+203.715 158.586 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWrite) 65.7532 Tj
+[1 0 0 1 269.468 158.586] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -269.468 -158.586] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+269.468 158.586 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 156.429] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -146.466] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 136.668 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(assignments) 48.7072 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 169.144 136.668] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.144 -136.668] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+169.144 136.668 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 210.987 136.668] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.987 -136.668] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.987 136.668 Td
+/F130_0 9.9626 Tf
+(:) 2.7696 Tj
+[1 0 0 1 72 134.511] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -83.6593] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.8518] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.8518 Td
+/F130_0 9.9626 Tf
+(22) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 26 26
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -165.016] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 143.462 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 139.875] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(BZ_CONFIG_ERROR) 89.6634 Tj
+98.4879 699.676 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(library) 41.8429 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(mis-compiled) 71.7307 Tj
+90 687.721 Td
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 675.766 Td
+(if) 11.9551 Tj
+-426 TJm
+(f) 5.97756 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+98.4879 663.811 Td
+(or) 11.9551 Tj
+-426 TJm
+(blockSize100k) 77.7083 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(1) 5.97756 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(blockSize100k) 77.7083 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(9) 5.97756 Tj
+90 651.856 Td
+(BZ_IO_ERROR) 65.7532 Tj
+98.4879 639.9 Td
+(if) 11.9551 Tj
+-426 TJm
+(ferror\(f\)) 53.798 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(nonzero) 41.8429 Tj
+90 627.945 Td
+(BZ_MEM_ERROR) 71.7307 Tj
+98.4879 615.99 Td
+(if) 11.9551 Tj
+-426 TJm
+(insufficient) 71.7307 Tj
+-426 TJm
+(memory) 35.8654 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(available) 53.798 Tj
+90 604.035 Td
+(BZ_OK) 29.8878 Tj
+98.4879 592.08 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 576.538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -566.575] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 554.62 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 554.521] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -60.7721] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 59.7758 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 56.1892] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -545.156] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 545.156 Td
+/F134_0 9.9626 Tf
+(Pointer) 41.8429 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(an) 11.9551 Tj
+-426 TJm
+(abstract) 47.8205 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+98.4879 533.201 Td
+(if) 11.9551 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+90 521.245 Td
+(NULL) 23.9102 Tj
+98.4879 509.29 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 493.748] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -483.786] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 471.831 Td
+/F130_0 9.9626 Tf
+(Allo) 17.7135 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able) 16.5977 Tj
+-250 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(actions:) 30.9936 Tj
+[1 0 0 1 72 471.731] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -84.6825] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 83.6862 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 80.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -462.366] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 462.366 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWrite) 65.7532 Tj
+98.4879 450.411 Td
+(if) 11.9551 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+98.4879 438.456 Td
+(\(you) 23.9102 Tj
+-426 TJm
+(could) 29.8878 Tj
+-426 TJm
+(go) 11.9551 Tj
+-426 TJm
+(directly) 47.8205 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(BZ2_bzWriteClose,) 101.619 Tj
+-426 TJm
+(but) 17.9327 Tj
+-426 TJm
+(this) 23.9102 Tj
+-426 TJm
+(would) 29.8878 Tj
+-426 TJm
+(be) 11.9551 Tj
+-426 TJm
+(pretty) 35.8654 Tj
+485.505 434.212 Td
+/F564_0 9.9626 Tf
+( ) 9.9626 Tj
+493.808 434.212 Td
+/F147_0 9.9626 Tf
+(-) 2.7696 Tj
+90 426.501 Td
+/F134_0 9.9626 Tf
+(pointless\)) 59.7756 Tj
+90 414.546 Td
+(BZ2_bzWriteClose) 95.641 Tj
+98.4879 402.59 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 387.049] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -377.086] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 356.428 Td
+/F122_0 17.2154 Tf
+(3.4.6.) 43.0729 Tj
+[1 0 0 1 119.858 356.428] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -356.428] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 356.428 Td
+/F392_0 17.2154 Tf
+(BZ2_bzWrite) 113.622 Tj
+[1 0 0 1 233.48 356.428] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.48 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -344.73] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 344.73 Td
+/F134_0 9.9626 Tf
+(void) 23.9102 Tj
+-426 TJm
+(BZ2_bzWrite) 65.7532 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(int) 17.9327 Tj
+220.55 342.987 Td
+(*) 5.97756 Tj
+226.528 344.73 Td
+(bzerror,) 47.8205 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+318.702 342.987 Td
+(*) 5.97756 Tj
+324.679 344.73 Td
+(b,) 11.9551 Tj
+-426 TJm
+(void) 23.9102 Tj
+369.033 342.987 Td
+(*) 5.97756 Tj
+375.01 344.73 Td
+(buf,) 23.9102 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(len) 17.9327 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 329.188] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -319.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 307.27 Td
+/F130_0 9.9626 Tf
+(Absorbs) 33.2053 Tj
+[1 0 0 1 107.696 307.27] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -107.696 -307.27] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+107.696 307.27 Td
+/F134_0 9.9626 Tf
+(len) 17.9327 Tj
+[1 0 0 1 125.629 307.27] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -125.629 -307.27] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+128.119 307.27 Td
+/F130_0 9.9626 Tf
+(bytes) 21.031 Tj
+-250 TJm
+(from) 19.3673 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+[1 0 0 1 214.544 307.27] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -214.544 -307.27] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+214.544 307.27 Td
+/F134_0 9.9626 Tf
+(buf) 17.9327 Tj
+[1 0 0 1 232.477 307.27] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -232.477 -307.27] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+232.477 307.27 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(entually) 32.0995 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(written) 28.224 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(\002le.) 15.2229 Tj
+[1 0 0 1 72 305.114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -295.151] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 285.353 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(assignments) 48.7072 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 169.144 285.353] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.144 -285.353] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+169.144 285.353 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 210.987 285.353] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.987 -285.353] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.987 285.353 Td
+/F130_0 9.9626 Tf
+(:) 2.7696 Tj
+[1 0 0 1 72 283.196] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -108.593] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 107.597 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 104.01] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -273.831] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 273.831 Td
+/F134_0 9.9626 Tf
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 261.876 Td
+(if) 11.9551 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(buf) 17.9327 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(len) 17.9327 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(0) 5.97756 Tj
+90 249.921 Td
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+98.4879 237.965 Td
+(if) 11.9551 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(opened) 35.8654 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(BZ2_bzReadOpen) 83.6858 Tj
+90 226.01 Td
+(BZ_IO_ERROR) 65.7532 Tj
+98.4879 214.055 Td
+(if) 11.9551 Tj
+-426 TJm
+(there) 29.8878 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(an) 11.9551 Tj
+-426 TJm
+(error) 29.8878 Tj
+-426 TJm
+(writing) 41.8429 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(file.) 29.8878 Tj
+90 202.1 Td
+(BZ_OK) 29.8878 Tj
+98.4879 190.145 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 174.603] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -164.64] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 143.982 Td
+/F122_0 17.2154 Tf
+(3.4.7.) 43.0729 Tj
+[1 0 0 1 119.858 143.982] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -143.982] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 143.982 Td
+/F392_0 17.2154 Tf
+(BZ2_bzWriteClose) 165.268 Tj
+[1 0 0 1 285.126 143.982] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -213.126 -2.3326] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -90.7975] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(23) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 27 27
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -165.016] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 143.462 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 139.875] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(void) 23.9102 Tj
+-426 TJm
+(BZ2_bzWriteClose\() 101.619 Tj
+-426 TJm
+(int) 17.9327 Tj
+246.194 709.888 Td
+(*) 5.97756 Tj
+252.171 711.631 Td
+(bzerror,) 47.8205 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+340.102 709.888 Td
+(*) 5.97756 Tj
+350.323 711.631 Td
+(f,) 11.9551 Tj
+187.611 699.676 Td
+(int) 17.9327 Tj
+-426 TJm
+(abandon,) 47.8205 Tj
+187.611 687.721 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+257.609 685.978 Td
+(*) 5.97756 Tj
+267.83 687.721 Td
+(nbytes_in,) 59.7756 Tj
+187.611 675.766 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+257.609 674.023 Td
+(*) 5.97756 Tj
+267.83 675.766 Td
+(nbytes_out) 59.7756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 651.856 Td
+(void) 23.9102 Tj
+-426 TJm
+(BZ2_bzWriteClose64\() 113.574 Tj
+-426 TJm
+(int) 17.9327 Tj
+258.149 650.112 Td
+(*) 5.97756 Tj
+264.127 651.856 Td
+(bzerror,) 47.8205 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+352.057 650.112 Td
+(*) 5.97756 Tj
+362.278 651.856 Td
+(f,) 11.9551 Tj
+196.099 639.9 Td
+(int) 17.9327 Tj
+-426 TJm
+(abandon,) 47.8205 Tj
+196.099 627.945 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+266.097 626.202 Td
+(*) 5.97756 Tj
+276.318 627.945 Td
+(nbytes_in_lo32,) 89.6634 Tj
+196.099 615.99 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+266.097 614.247 Td
+(*) 5.97756 Tj
+276.318 615.99 Td
+(nbytes_in_hi32,) 89.6634 Tj
+196.099 604.035 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+266.097 602.292 Td
+(*) 5.97756 Tj
+276.318 604.035 Td
+(nbytes_out_lo32,) 95.641 Tj
+196.099 592.08 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+266.097 590.336 Td
+(*) 5.97756 Tj
+276.318 592.08 Td
+(nbytes_out_hi32) 89.6634 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 576.538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -566.575] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 554.62 Td
+/F130_0 9.9626 Tf
+(Compresses) 48.1492 Tj
+-403 TJm
+(and) 14.386 Tj
+-402 TJm
+(\003ushes) 27.6761 Tj
+-403 TJm
+(to) 7.7509 Tj
+-403 TJm
+(the) 12.1743 Tj
+-402 TJm
+(compressed) 47.0334 Tj
+-403 TJm
+(\002le) 12.7322 Tj
+-403 TJm
+(a) 4.42339 Tj
+1 TJm
+(ll) 5.53921 Tj
+-403 TJm
+(data) 16.5977 Tj
+-403 TJm
+(so) 8.85675 Tj
+-402 TJm
+(f) 3.31755 Tj
+10 TJm
+(ar) 7.74094 Tj
+-403 TJm
+(supplied) 33.7633 Tj
+-403 TJm
+(by) 9.9626 Tj
+[1 0 0 1 384.152 554.62] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -384.152 -554.62] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+384.152 554.62 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWrite) 65.7532 Tj
+[1 0 0 1 449.906 554.62] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -449.906 -554.62] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+449.906 554.62 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-768 TJm
+(The) 15.4918 Tj
+-403 TJm
+(logical) 27.1182 Tj
+-402 TJm
+(end-of-) 29.3199 Tj
+72 542.665 Td
+(stream) 26.5603 Tj
+-352 TJm
+(mark) 20.4731 Tj
+10 TJm
+(ers) 11.6164 Tj
+-352 TJm
+(are) 12.1643 Tj
+-353 TJm
+(also) 16.0497 Tj
+-352 TJm
+(written,) 30.7147 Tj
+-378 TJm
+(so) 8.85675 Tj
+-352 TJm
+(subsequent) 44.2738 Tj
+-352 TJm
+(calls) 18.2614 Tj
+-352 TJm
+(to) 7.7509 Tj
+[1 0 0 1 300.456 542.665] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -300.456 -542.665] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+300.456 542.665 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWrite) 65.7532 Tj
+[1 0 0 1 366.209 542.665] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -366.209 -542.665] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+369.718 542.665 Td
+/F130_0 9.9626 Tf
+(are) 12.1643 Tj
+-352 TJm
+(ille) 12.7322 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(al.) 9.68365 Tj
+-1234 TJm
+(All) 12.7322 Tj
+-352 TJm
+(memory) 33.2053 Tj
+-352 TJm
+(associated) 40.9463 Tj
+-352 TJm
+(with) 17.7135 Tj
+72 530.71 Td
+(the) 12.1743 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+[1 0 0 1 151.411 530.71] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -151.411 -530.71] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+151.411 530.71 Td
+/F134_0 9.9626 Tf
+(b) 5.97756 Tj
+[1 0 0 1 157.389 530.71] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -157.389 -530.71] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+159.879 530.71 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(released.) 35.1281 Tj
+[1 0 0 1 207.231 530.71] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -207.231 -530.71] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+207.231 530.71 Td
+/F134_0 9.9626 Tf
+(fflush) 35.8654 Tj
+[1 0 0 1 243.097 530.71] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -243.097 -530.71] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+245.587 530.71 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(called) 23.7907 Tj
+-250 TJm
+(on) 9.9626 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le,) 15.2229 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(not) 12.7322 Tj
+[1 0 0 1 422.771 530.71] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -422.771 -530.71] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+422.771 530.71 Td
+/F134_0 9.9626 Tf
+(fclose) 35.8654 Tj
+[1 0 0 1 458.636 530.71] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -458.636 -530.71] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+458.636 530.71 Td
+/F130_0 9.9626 Tf
+(') 3.31755 Tj
+50 TJm
+(d.) 7.47195 Tj
+[1 0 0 1 72 528.553] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -518.59] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 508.792 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+[1 0 0 1 81.5743 508.792] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -81.5743 -508.792] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+81.5743 508.792 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteClose) 95.641 Tj
+[1 0 0 1 177.216 508.792] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -177.216 -508.792] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+180.155 508.792 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-295 TJm
+(called) 23.7907 Tj
+-295 TJm
+(to) 7.7509 Tj
+-295 TJm
+(clean) 21.0211 Tj
+-295 TJm
+(up) 9.9626 Tj
+-295 TJm
+(after) 18.2515 Tj
+-295 TJm
+(an) 9.40469 Tj
+-295 TJm
+(error) 19.3573 Tj
+40 TJm
+(,) 2.49065 Tj
+-306 TJm
+(the) 12.1743 Tj
+-295 TJm
+(only) 17.7135 Tj
+-295 TJm
+(action) 24.3486 Tj
+-295 TJm
+(is) 6.64505 Tj
+-295 TJm
+(to) 7.7509 Tj
+-295 TJm
+(release) 27.6562 Tj
+-295 TJm
+(the) 12.1743 Tj
+-295 TJm
+(memory) 33.2053 Tj
+65 TJm
+(.) 2.49065 Tj
+-891 TJm
+(The) 15.4918 Tj
+-295 TJm
+(library) 26.5603 Tj
+72 496.837 Td
+(records) 29.3199 Tj
+-289 TJm
+(the) 12.1743 Tj
+-289 TJm
+(error) 19.3573 Tj
+-289 TJm
+(codes) 22.6848 Tj
+-289 TJm
+(issued) 24.9065 Tj
+-289 TJm
+(by) 9.9626 Tj
+-289 TJm
+(pre) 12.7222 Tj
+25 TJm
+(vious) 21.589 Tj
+-289 TJm
+(calls,) 20.7521 Tj
+-299 TJm
+(so) 8.85675 Tj
+-289 TJm
+(this) 14.396 Tj
+-289 TJm
+(situation) 34.3212 Tj
+-289 TJm
+(will) 15.5018 Tj
+-289 TJm
+(be) 9.40469 Tj
+-289 TJm
+(detected) 33.1954 Tj
+-289 TJm
+(automatically) 54.2364 Tj
+65 TJm
+(.) 2.49065 Tj
+-427 TJm
+(There) 23.2328 Tj
+-289 TJm
+(is) 6.64505 Tj
+-289 TJm
+(no) 9.9626 Tj
+-289 TJm
+(attempt) 29.8878 Tj
+72 484.882 Td
+(to) 7.7509 Tj
+-263 TJm
+(complete) 36.5229 Tj
+-262 TJm
+(the) 12.1743 Tj
+-263 TJm
+(compression) 50.3609 Tj
+-263 TJm
+(operation,) 40.1194 Tj
+-265 TJm
+(nor) 13.2801 Tj
+-263 TJm
+(to) 7.7509 Tj
+[1 0 0 1 258.308 484.882] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -258.308 -484.882] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+258.308 484.882 Td
+/F134_0 9.9626 Tf
+(fflush) 35.8654 Tj
+[1 0 0 1 294.173 484.882] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -294.173 -484.882] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+296.79 484.882 Td
+/F130_0 9.9626 Tf
+(the) 12.1743 Tj
+-263 TJm
+(compressed) 47.0334 Tj
+-262 TJm
+(\002le.) 15.2229 Tj
+-696 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-263 TJm
+(can) 13.8281 Tj
+-263 TJm
+(force) 20.4632 Tj
+-262 TJm
+(this) 14.396 Tj
+-263 TJm
+(beha) 18.8094 Tj
+20 TJm
+(viour) 21.031 Tj
+-263 TJm
+(to) 7.7509 Tj
+-262 TJm
+(happen) 28.772 Tj
+72 472.926 Td
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(case) 17.1456 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(no) 9.9626 Tj
+-250 TJm
+(error) 19.3573 Tj
+40 TJm
+(,) 2.49065 Tj
+-250 TJm
+(by) 9.9626 Tj
+-250 TJm
+(passing) 29.8878 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(nonzero) 32.0895 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue) 16.5977 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 305.014 472.926] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -305.014 -472.926] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+305.014 472.926 Td
+/F134_0 9.9626 Tf
+(abandon) 41.8429 Tj
+[1 0 0 1 346.858 472.926] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -346.858 -472.926] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+346.858 472.926 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 470.77] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -460.807] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 451.009 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+[1 0 0 1 80.5974 451.009] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -80.5974 -451.009] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+80.5974 451.009 Td
+/F134_0 9.9626 Tf
+(nbytes_in) 53.798 Tj
+[1 0 0 1 134.396 451.009] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -134.396 -451.009] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+136.358 451.009 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-197 TJm
+(non-null,) 36.2539 Tj
+[1 0 0 1 183.287 451.009] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -183.287 -451.009] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+183.287 449.265 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+189.265 451.009 Td
+(nbytes_in) 53.798 Tj
+[1 0 0 1 243.063 451.009] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -243.063 -451.009] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+245.025 451.009 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-197 TJm
+(be) 9.40469 Tj
+-197 TJm
+(set) 11.0684 Tj
+-197 TJm
+(to) 7.7509 Tj
+-197 TJm
+(be) 9.40469 Tj
+-197 TJm
+(the) 12.1743 Tj
+-197 TJm
+(total) 17.7135 Tj
+-197 TJm
+(v) 4.9813 Tj
+20 TJm
+(olume) 24.9065 Tj
+-197 TJm
+(of) 8.29885 Tj
+-197 TJm
+(uncompressed) 56.996 Tj
+-197 TJm
+(data) 16.5977 Tj
+-197 TJm
+(handled.) 34.0322 Tj
+-584 TJm
+(Similarly) 37.0908 Tj
+65 TJm
+(,) 2.49065 Tj
+[1 0 0 1 72 439.053] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -439.053] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 439.053 Td
+/F134_0 9.9626 Tf
+(nbytes_out) 59.7756 Tj
+[1 0 0 1 131.776 439.053] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -131.776 -439.053] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+134.716 439.053 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-295 TJm
+(be) 9.40469 Tj
+-295 TJm
+(set) 11.0684 Tj
+-295 TJm
+(to) 7.7509 Tj
+-295 TJm
+(the) 12.1743 Tj
+-295 TJm
+(total) 17.7135 Tj
+-295 TJm
+(v) 4.9813 Tj
+20 TJm
+(olume) 24.9065 Tj
+-296 TJm
+(of) 8.29885 Tj
+-295 TJm
+(compressed) 47.0334 Tj
+-295 TJm
+(data) 16.5977 Tj
+-295 TJm
+(written.) 30.7147 Tj
+-890 TJm
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-295 TJm
+(compatibility) 53.1405 Tj
+-295 TJm
+(with) 17.7135 Tj
+-295 TJm
+(older) 20.4731 Tj
+-296 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions) 28.224 Tj
+-295 TJm
+(of) 8.29885 Tj
+72 427.098 Td
+(the) 12.1743 Tj
+-283 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+[1 0 0 1 118.294 427.098] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -118.294 -427.098] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+118.294 427.098 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteClose) 95.641 Tj
+[1 0 0 1 213.936 427.098] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -213.936 -427.098] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+216.753 427.098 Td
+/F130_0 9.9626 Tf
+(only) 17.7135 Tj
+-283 TJm
+(yields) 23.8007 Tj
+-283 TJm
+(the) 12.1743 Tj
+-282 TJm
+(lo) 7.7509 Tj
+25 TJm
+(wer) 14.9339 Tj
+-283 TJm
+(32) 9.9626 Tj
+-283 TJm
+(bits) 14.396 Tj
+-283 TJm
+(of) 8.29885 Tj
+-283 TJm
+(these) 20.4731 Tj
+-282 TJm
+(counts.) 28.503 Tj
+-817 TJm
+(Use) 15.4918 Tj
+[1 0 0 1 423.499 427.098] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -423.499 -427.098] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+423.499 427.098 Td
+/F134_0 9.9626 Tf
+(BZ2_bzWriteClose64) 107.596 Tj
+[1 0 0 1 531.095 427.098] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -531.095 -427.098] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+533.913 427.098 Td
+/F130_0 9.9626 Tf
+(if) 6.08715 Tj
+72 415.143 Td
+(you) 14.9439 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(full) 13.8381 Tj
+-250 TJm
+(64) 9.9626 Tj
+-250 TJm
+(bit) 10.5205 Tj
+-250 TJm
+(counts.) 28.503 Tj
+-620 TJm
+(These) 23.7907 Tj
+-250 TJm
+(tw) 9.9626 Tj
+10 TJm
+(o) 4.9813 Tj
+-250 TJm
+(functions) 37.0808 Tj
+-250 TJm
+(are) 12.1643 Tj
+-250 TJm
+(otherwise) 38.7346 Tj
+-250 TJm
+(absolutely) 40.9562 Tj
+-250 TJm
+(identical.) 36.8018 Tj
+[1 0 0 1 72 412.986] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -403.024] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 393.225 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(assignments) 48.7072 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 169.144 393.225] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -169.144 -393.225] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+169.144 393.225 Td
+/F134_0 9.9626 Tf
+(bzerror) 41.8429 Tj
+[1 0 0 1 210.987 393.225] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.987 -393.225] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.987 393.225 Td
+/F130_0 9.9626 Tf
+(:) 2.7696 Tj
+[1 0 0 1 72 391.069] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -84.6825] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 83.6862 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 80.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -381.704] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 381.704 Td
+/F134_0 9.9626 Tf
+(BZ_SEQUENCE_ERROR) 101.619 Tj
+98.4879 369.748 Td
+(if) 11.9551 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(opened) 35.8654 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(BZ2_bzReadOpen) 83.6858 Tj
+90 357.793 Td
+(BZ_IO_ERROR) 65.7532 Tj
+98.4879 345.838 Td
+(if) 11.9551 Tj
+-426 TJm
+(there) 29.8878 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(an) 11.9551 Tj
+-426 TJm
+(error) 29.8878 Tj
+-426 TJm
+(writing) 41.8429 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(file) 23.9102 Tj
+90 333.883 Td
+(BZ_OK) 29.8878 Tj
+98.4879 321.928 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 306.386] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -296.423] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 275.765 Td
+/F122_0 17.2154 Tf
+(3.4.8.) 43.0729 Tj
+-278 TJm
+(Handling) 73.6475 Tj
+-278 TJm
+(embed) 55.4852 Tj
+10 TJm
+(ded) 30.609 Tj
+-278 TJm
+(compressed) 101.416 Tj
+-278 TJm
+(data) 35.3949 Tj
+-278 TJm
+(streams) 66.0211 Tj
+[1 0 0 1 72 271.935] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -261.972] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 253.847 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-203 TJm
+(high-le) 28.224 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-203 TJm
+(library) 26.5603 Tj
+-203 TJm
+(f) 3.31755 Tj
+10 TJm
+(acilitates) 35.417 Tj
+-203 TJm
+(use) 13.2801 Tj
+-203 TJm
+(of) 8.29885 Tj
+[1 0 0 1 226.404 253.847] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -226.404 -253.847] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+226.404 253.847 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 256.292 253.847] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -256.292 -253.847] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+258.316 253.847 Td
+/F130_0 9.9626 Tf
+(data) 16.5977 Tj
+-203 TJm
+(streams) 30.4357 Tj
+-203 TJm
+(which) 24.3486 Tj
+-203 TJm
+(form) 19.3673 Tj
+-203 TJm
+(some) 21.031 Tj
+-203 TJm
+(part) 15.4918 Tj
+-203 TJm
+(of) 8.29885 Tj
+-204 TJm
+(a) 4.42339 Tj
+-203 TJm
+(surrounding,) 50.6399 Tj
+-212 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ger) 12.7222 Tj
+-203 TJm
+(data) 16.5977 Tj
+-203 TJm
+(stream.) 29.0509 Tj
+[1 0 0 1 72 251.69] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -29.7236] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -221.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 221.967 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 221.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -221.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 221.967 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-240 TJm
+(writing,) 31.2726 Tj
+-243 TJm
+(the) 12.1743 Tj
+-240 TJm
+(library) 26.5603 Tj
+-241 TJm
+(tak) 12.1743 Tj
+10 TJm
+(es) 8.29885 Tj
+-240 TJm
+(an) 9.40469 Tj
+-241 TJm
+(open) 19.3673 Tj
+-240 TJm
+(\002le) 12.7322 Tj
+-241 TJm
+(handle,) 29.0509 Tj
+-242 TJm
+(writes) 24.3486 Tj
+-241 TJm
+(compres) 33.7533 Tj
+1 TJm
+(sed) 13.2801 Tj
+-241 TJm
+(data) 16.5977 Tj
+-240 TJm
+(to) 7.7509 Tj
+-241 TJm
+(it,) 8.02986 Tj
+[1 0 0 1 398.926 221.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -398.926 -221.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+398.926 221.967 Td
+/F134_0 9.9626 Tf
+(fflush) 35.8654 Tj
+[1 0 0 1 434.791 221.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -434.791 -221.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+434.791 221.967 Td
+/F130_0 9.9626 Tf
+(es) 8.29885 Tj
+-240 TJm
+(it) 5.53921 Tj
+-241 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-240 TJm
+(does) 18.2614 Tj
+-241 TJm
+(not) 12.7322 Tj
+[1 0 0 1 504.135 221.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -504.135 -221.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+504.135 221.967 Td
+/F134_0 9.9626 Tf
+(fclose) 35.8654 Tj
+[1 0 0 1 540 221.967] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -221.967] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 210.011 Td
+/F130_0 9.9626 Tf
+(it.) 8.02986 Tj
+-610 TJm
+(The) 15.4918 Tj
+-235 TJm
+(calling) 27.1182 Tj
+-235 TJm
+(application) 44.2738 Tj
+-235 TJm
+(can) 13.8281 Tj
+-235 TJm
+(write) 20.4731 Tj
+-235 TJm
+(its) 9.41466 Tj
+-235 TJm
+(o) 4.9813 Tj
+25 TJm
+(wn) 12.1743 Tj
+-235 TJm
+(data) 16.5977 Tj
+-235 TJm
+(before) 25.4445 Tj
+-235 TJm
+(and) 14.386 Tj
+-235 TJm
+(after) 18.2515 Tj
+-235 TJm
+(the) 12.1743 Tj
+-235 TJm
+(compressed) 47.0334 Tj
+-235 TJm
+(data) 16.5977 Tj
+-235 TJm
+(stream,) 29.0509 Tj
+-238 TJm
+(using) 21.589 Tj
+-235 TJm
+(that) 14.9439 Tj
+-235 TJm
+(same) 20.4731 Tj
+-235 TJm
+(\002le) 12.7322 Tj
+86.944 198.056 Td
+(handle.) 29.0509 Tj
+[1 0 0 1 115.995 198.056] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -43.9948 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -176.139] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 176.139 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 176.139] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -176.139] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 176.139 Td
+/F130_0 9.9626 Tf
+(Reading) 33.2053 Tj
+-236 TJm
+(is) 6.64505 Tj
+-236 TJm
+(more) 20.4731 Tj
+-236 TJm
+(comple) 29.3299 Tj
+15 TJm
+(x,) 7.47195 Tj
+-238 TJm
+(and) 14.386 Tj
+-236 TJm
+(the) 12.1743 Tj
+-236 TJm
+(f) 3.31755 Tj
+10 TJm
+(acilities) 30.9936 Tj
+-236 TJm
+(are) 12.1643 Tj
+-236 TJm
+(not) 12.7322 Tj
+-235 TJm
+(as) 8.29885 Tj
+-236 TJm
+(general) 29.3199 Tj
+-236 TJm
+(as) 8.29885 Tj
+-236 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-236 TJm
+(could) 22.1369 Tj
+-236 TJm
+(be) 9.40469 Tj
+-236 TJm
+(since) 20.4731 Tj
+-235 TJm
+(generality) 39.8404 Tj
+-236 TJm
+(is) 6.64505 Tj
+-236 TJm
+(hard) 17.7035 Tj
+-236 TJm
+(to) 7.7509 Tj
+-236 TJm
+(reconcile) 36.5129 Tj
+86.944 164.183 Td
+(with) 17.7135 Tj
+-404 TJm
+(ef) 7.74094 Tj
+25 TJm
+(\002cienc) 26.5603 Tj
+15 TJm
+(y) 4.9813 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 164.811 164.183] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -164.811 -164.183] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+164.811 164.183 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 224.587 164.183] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -224.587 -164.183] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+228.614 164.183 Td
+/F130_0 9.9626 Tf
+(reads) 21.0211 Tj
+-404 TJm
+(from) 19.3673 Tj
+-405 TJm
+(the) 12.1743 Tj
+-404 TJm
+(compressed) 47.0334 Tj
+-404 TJm
+(\002le) 12.7322 Tj
+-404 TJm
+(in) 7.7509 Tj
+-405 TJm
+(blocks) 26.0123 Tj
+-404 TJm
+(of) 8.29885 Tj
+-404 TJm
+(size) 15.4918 Tj
+[1 0 0 1 434.744 164.183] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -434.744 -164.183] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+434.744 164.183 Td
+/F134_0 9.9626 Tf
+(BZ_MAX_UNUSED) 77.7083 Tj
+[1 0 0 1 512.452 164.183] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -512.452 -164.183] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+516.479 164.183 Td
+/F130_0 9.9626 Tf
+(bytes,) 23.5217 Tj
+86.944 152.228 Td
+(and) 14.386 Tj
+-413 TJm
+(in) 7.7509 Tj
+-413 TJm
+(doing) 22.6948 Tj
+-413 TJm
+(so) 8.85675 Tj
+-413 TJm
+(probably) 35.417 Tj
+-413 TJm
+(will) 15.5018 Tj
+-413 TJm
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(ershoot) 29.3299 Tj
+-413 TJm
+(the) 12.1743 Tj
+-413 TJm
+(logical) 27.1182 Tj
+-413 TJm
+(end) 14.386 Tj
+-413 TJm
+(of) 8.29885 Tj
+-413 TJm
+(compressed) 47.0334 Tj
+-413 TJm
+(stream.) 29.0509 Tj
+-1598 TJm
+(T) 6.08715 Tj
+80 TJm
+(o) 4.9813 Tj
+-413 TJm
+(reco) 17.1456 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-413 TJm
+(this) 14.396 Tj
+-413 TJm
+(data) 16.5977 Tj
+-413 TJm
+(once) 18.8094 Tj
+86.944 140.273 Td
+(decompression) 59.7656 Tj
+-252 TJm
+(has) 13.2801 Tj
+-252 TJm
+(ended,) 26.2813 Tj
+-253 TJm
+(call) 14.386 Tj
+[1 0 0 1 210.705 140.273] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.705 -140.273] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.705 140.273 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadGetUnused) 113.574 Tj
+[1 0 0 1 324.279 140.273] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -324.279 -140.273] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+326.789 140.273 Td
+/F130_0 9.9626 Tf
+(after) 18.2515 Tj
+-252 TJm
+(the) 12.1743 Tj
+-252 TJm
+(last) 13.8381 Tj
+-252 TJm
+(call) 14.386 Tj
+-252 TJm
+(of) 8.29885 Tj
+[1 0 0 1 406.291 140.273] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -406.291 -140.273] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+406.291 140.273 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 466.067 140.273] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -466.067 -140.273] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+468.578 140.273 Td
+/F130_0 9.9626 Tf
+(\(the) 15.4918 Tj
+-252 TJm
+(one) 14.386 Tj
+-252 TJm
+(returning) 36.5229 Tj
+[1 0 0 1 86.944 128.318] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -128.318] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 128.318 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 164.653 128.318] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -164.653 -128.318] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+164.653 128.318 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(before) 25.4445 Tj
+-250 TJm
+(calling) 27.1182 Tj
+[1 0 0 1 243.028 128.318] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -243.028 -128.318] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+243.028 128.318 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadClose) 89.6634 Tj
+[1 0 0 1 332.692 128.318] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -332.692 -128.318] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+332.692 128.318 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 335.182 128.318] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -263.182 -77.466] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.8519] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.8518 Td
+/F130_0 9.9626 Tf
+(24) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 28 28
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-271 TJm
+(mechanism) 45.3796 Tj
+-272 TJm
+(mak) 17.1556 Tj
+10 TJm
+(es) 8.29885 Tj
+-271 TJm
+(it) 5.53921 Tj
+-271 TJm
+(easy) 17.7035 Tj
+-271 TJm
+(to) 7.7509 Tj
+-272 TJm
+(decompress) 47.0334 Tj
+-271 TJm
+(multiple) 33.2153 Tj
+[1 0 0 1 293.312 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -293.312 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+293.312 710.037 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 323.2 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -323.2 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+325.903 710.037 Td
+/F130_0 9.9626 Tf
+(streams) 30.4357 Tj
+-271 TJm
+(placed) 26.0024 Tj
+-272 TJm
+(end-to-end.) 45.6486 Tj
+-374 TJm
+(As) 11.0684 Tj
+-271 TJm
+(the) 12.1743 Tj
+-271 TJm
+(end) 14.386 Tj
+-271 TJm
+(of) 8.29885 Tj
+-272 TJm
+(one) 14.386 Tj
+-271 TJm
+(stream,) 29.0509 Tj
+72 698.082 Td
+(when) 21.579 Tj
+[1 0 0 1 96.1948 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -96.1948 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+96.1948 698.082 Td
+/F134_0 9.9626 Tf
+(BZ2_bzRead) 59.7756 Tj
+[1 0 0 1 155.971 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.971 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+158.586 698.082 Td
+/F130_0 9.9626 Tf
+(returns) 27.6661 Tj
+[1 0 0 1 188.868 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -188.868 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+188.868 698.082 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 266.577 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -266.577 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+266.577 698.082 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-263 TJm
+(call) 14.386 Tj
+[1 0 0 1 288.685 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -288.685 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+288.685 698.082 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadGetUnused) 113.574 Tj
+[1 0 0 1 402.259 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -402.259 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+404.875 698.082 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-263 TJm
+(collect) 26.5603 Tj
+-262 TJm
+(the) 12.1743 Tj
+-263 TJm
+(unused) 28.224 Tj
+-262 TJm
+(data) 16.5977 Tj
+-263 TJm
+(\(cop) 17.7035 Tj
+10 TJm
+(y) 4.9813 Tj
+-262 TJm
+(it) 5.53921 Tj
+72 686.127 Td
+(into) 15.5018 Tj
+-265 TJm
+(your) 18.2614 Tj
+-265 TJm
+(o) 4.9813 Tj
+25 TJm
+(wn) 12.1743 Tj
+-265 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-265 TJm
+(some) 21.031 Tj
+25 TJm
+(where\).) 30.1468 Tj
+-711 TJm
+(That) 18.2614 Tj
+-265 TJm
+(data) 16.5977 Tj
+-265 TJm
+(forms) 23.2427 Tj
+-265 TJm
+(the) 12.1743 Tj
+-265 TJm
+(start) 17.1556 Tj
+-265 TJm
+(of) 8.29885 Tj
+-265 TJm
+(the) 12.1743 Tj
+-265 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-265 TJm
+(compressed) 47.0334 Tj
+-265 TJm
+(stream.) 29.0509 Tj
+-711 TJm
+(T) 6.08715 Tj
+80 TJm
+(o) 4.9813 Tj
+-265 TJm
+(start) 17.1556 Tj
+-265 TJm
+(uncompressing) 60.3235 Tj
+72 674.172 Td
+(that) 14.9439 Tj
+-246 TJm
+(ne) 9.40469 Tj
+15 TJm
+(xt) 7.7509 Tj
+-246 TJm
+(stream,) 29.0509 Tj
+-247 TJm
+(call) 14.386 Tj
+[1 0 0 1 157.205 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -157.205 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+157.205 674.172 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadOpen) 83.6858 Tj
+[1 0 0 1 240.891 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -240.891 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+243.344 674.172 Td
+/F130_0 9.9626 Tf
+(ag) 9.40469 Tj
+5 TJm
+(ain,) 14.6649 Tj
+-247 TJm
+(feeding) 29.8778 Tj
+-246 TJm
+(in) 7.7509 Tj
+-246 TJm
+(the) 12.1743 Tj
+-247 TJm
+(unused) 28.224 Tj
+-246 TJm
+(data) 16.5977 Tj
+-246 TJm
+(via) 12.1743 Tj
+-246 TJm
+(the) 12.1743 Tj
+[1 0 0 1 405.967 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -405.967 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+405.967 674.172 Td
+/F134_0 9.9626 Tf
+(unused) 35.8654 Tj
+[1 0 0 1 441.833 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -441.833 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+444.286 674.172 Td
+/F130_0 9.9626 Tf
+(/) 2.7696 Tj
+[1 0 0 1 449.508 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -449.508 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+449.508 674.172 Td
+/F134_0 9.9626 Tf
+(nUnused) 41.8429 Tj
+[1 0 0 1 491.351 674.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -491.351 -674.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+493.804 674.172 Td
+/F130_0 9.9626 Tf
+(parameters.) 46.1966 Tj
+72 662.217 Td
+(K) 7.193 Tj
+25 TJm
+(eep) 13.8281 Tj
+-263 TJm
+(doing) 22.6948 Tj
+-263 TJm
+(this) 14.396 Tj
+-264 TJm
+(until) 18.2714 Tj
+[1 0 0 1 158.622 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -158.622 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+158.622 662.217 Td
+/F134_0 9.9626 Tf
+(BZ_STREAM_END) 77.7083 Tj
+[1 0 0 1 236.33 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -236.33 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+238.952 662.217 Td
+/F130_0 9.9626 Tf
+(return) 23.7907 Tj
+-263 TJm
+(coincides) 37.6287 Tj
+-263 TJm
+(with) 17.7135 Tj
+-263 TJm
+(the) 12.1743 Tj
+-264 TJm
+(ph) 9.9626 Tj
+5 TJm
+(ysical) 23.2427 Tj
+-263 TJm
+(end) 14.386 Tj
+-263 TJm
+(of) 8.29885 Tj
+-263 TJm
+(\002le) 12.7322 Tj
+-263 TJm
+(\() 3.31755 Tj
+[1 0 0 1 423.125 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -423.125 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+423.125 662.217 Td
+/F134_0 9.9626 Tf
+(feof\(f\)) 41.8429 Tj
+[1 0 0 1 464.968 662.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -464.968 -662.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+464.968 662.217 Td
+/F130_0 9.9626 Tf
+(\).) 5.8082 Tj
+-699 TJm
+(In) 8.29885 Tj
+-263 TJm
+(this) 14.396 Tj
+-263 TJm
+(situation) 34.3212 Tj
+[1 0 0 1 72 650.261] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -650.261] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 650.261 Td
+/F134_0 9.9626 Tf
+(BZ2_bzReadGetUnused) 113.574 Tj
+[1 0 0 1 185.574 650.261] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -185.574 -650.261] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+188.065 650.261 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(course) 26.0024 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(no) 9.9626 Tj
+-250 TJm
+(data.) 19.0883 Tj
+[1 0 0 1 72 648.951] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -638.989] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 628.344 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-240 TJm
+(should) 26.5703 Tj
+-241 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-240 TJm
+(some) 21.031 Tj
+-241 TJm
+(feel) 14.9339 Tj
+-240 TJm
+(for) 11.6164 Tj
+-241 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-240 TJm
+(the) 12.1743 Tj
+-240 TJm
+(high-le) 28.224 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-241 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace) 13.2702 Tj
+-240 TJm
+(can) 13.8281 Tj
+-241 TJm
+(be) 9.40469 Tj
+-240 TJm
+(used.) 20.7521 Tj
+-614 TJm
+(If) 6.63509 Tj
+-240 TJm
+(you) 14.9439 Tj
+-241 TJm
+(require) 28.2141 Tj
+-240 TJm
+(e) 4.42339 Tj
+15 TJm
+(xtra) 15.4918 Tj
+-241 TJm
+(\003e) 9.9626 Tj
+15 TJm
+(xibi) 15.5018 Tj
+1 TJm
+(lity) 13.2901 Tj
+65 TJm
+(,) 2.49065 Tj
+-243 TJm
+(you') 18.2614 Tj
+10 TJm
+(ll) 5.53921 Tj
+-240 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-241 TJm
+(to) 7.7509 Tj
+72 616.389 Td
+(bite) 14.9439 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ullet) 17.7135 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(get) 12.1743 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(grips) 19.9252 Tj
+-250 TJm
+(with) 17.7135 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace.) 15.7608 Tj
+[1 0 0 1 72 614.232] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -604.269] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 585.767 Td
+/F122_0 17.2154 Tf
+(3.4.9.) 43.0729 Tj
+-278 TJm
+(Standar) 64.0929 Tj
+20 TJm
+(d) 10.5186 Tj
+-278 TJm
+(\002le-reading/writing) 154.009 Tj
+-278 TJm
+(code) 40.1807 Tj
+[1 0 0 1 72 581.937] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -571.975] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 563.85 Td
+/F130_0 9.9626 Tf
+(Here') 22.6749 Tj
+55 TJm
+(s) 3.87545 Tj
+-250 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(you') 18.2614 Tj
+50 TJm
+(d) 4.9813 Tj
+-250 TJm
+(write) 20.4731 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le:) 15.5018 Tj
+[1 0 0 1 72 561.693] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -371.606] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 370.61 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 367.024] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -552.328] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 552.328 Td
+/F134_0 9.9626 Tf
+(FILE) 23.9102 Tj
+113.91 550.584 Td
+(*) 5.97756 Tj
+132.62 552.328 Td
+(f;) 11.9551 Tj
+90 540.373 Td
+(BZFILE) 35.8654 Tj
+125.865 538.629 Td
+(*) 5.97756 Tj
+136.087 540.373 Td
+(b;) 11.9551 Tj
+90 528.418 Td
+(int) 17.9327 Tj
+-2130 TJm
+(nBuf;) 29.8878 Tj
+90 516.462 Td
+(char) 23.9102 Tj
+-1704 TJm
+(buf[) 23.9102 Tj
+-426 TJm
+(/) 5.97756 Tj
+165.018 514.719 Td
+(*) 5.97756 Tj
+175.24 516.462 Td
+(whatever) 47.8205 Tj
+-426 TJm
+(size) 23.9102 Tj
+-426 TJm
+(you) 17.9327 Tj
+-426 TJm
+(like) 23.9102 Tj
+305.79 514.719 Td
+(*) 5.97756 Tj
+311.767 516.462 Td
+(/) 5.97756 Tj
+-426 TJm
+(];) 11.9551 Tj
+90 504.507 Td
+(int) 17.9327 Tj
+-2130 TJm
+(bzerror;) 47.8205 Tj
+90 492.552 Td
+(int) 17.9327 Tj
+-2130 TJm
+(nWritten;) 53.798 Tj
+90 468.642 Td
+(f) 5.97756 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(fopen) 29.8878 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+("myfile.bz2",) 77.7083 Tj
+-426 TJm
+("w") 17.9327 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 456.687 Td
+(if) 11.9551 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(!f) 11.9551 Tj
+-426 TJm
+(\)) 5.97756 Tj
+-426 TJm
+({) 5.97756 Tj
+94.244 444.731 Td
+(/) 5.97756 Tj
+100.222 442.988 Td
+(*) 5.97756 Tj
+110.443 444.731 Td
+(handle) 35.8654 Tj
+-426 TJm
+(error) 29.8878 Tj
+184.685 442.988 Td
+(*) 5.97756 Tj
+190.662 444.731 Td
+(/) 5.97756 Tj
+90 432.776 Td
+(}) 5.97756 Tj
+90 420.821 Td
+(b) 5.97756 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ2_bzWriteOpen\() 95.641 Tj
+-426 TJm
+(&bzerror,) 53.798 Tj
+-426 TJm
+(f,) 11.9551 Tj
+-426 TJm
+(9) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 408.866 Td
+(if) 11.9551 Tj
+-426 TJm
+(\(bzerror) 47.8205 Tj
+-426 TJm
+(!=) 11.9551 Tj
+-426 TJm
+(BZ_OK\)) 35.8654 Tj
+-426 TJm
+({) 5.97756 Tj
+94.244 396.911 Td
+(BZ2_bzWriteClose) 95.641 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+94.244 384.956 Td
+(/) 5.97756 Tj
+100.222 383.212 Td
+(*) 5.97756 Tj
+110.443 384.956 Td
+(handle) 35.8654 Tj
+-426 TJm
+(error) 29.8878 Tj
+184.685 383.212 Td
+(*) 5.97756 Tj
+190.662 384.956 Td
+(/) 5.97756 Tj
+90 373 Td
+(}) 5.97756 Tj
+90 349.09 Td
+(while) 29.8878 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(/) 5.97756 Tj
+140.331 347.347 Td
+(*) 5.97756 Tj
+150.553 349.09 Td
+(condition) 53.798 Tj
+208.595 347.347 Td
+(*) 5.97756 Tj
+214.572 349.09 Td
+(/) 5.97756 Tj
+-426 TJm
+(\)) 5.97756 Tj
+-426 TJm
+({) 5.97756 Tj
+94.244 337.135 Td
+(/) 5.97756 Tj
+100.222 335.391 Td
+(*) 5.97756 Tj
+110.443 337.135 Td
+(get) 17.9327 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(write) 29.8878 Tj
+-426 TJm
+(into) 23.9102 Tj
+-426 TJm
+(buf,) 23.9102 Tj
+-426 TJm
+(and) 17.9327 Tj
+-426 TJm
+(set) 17.9327 Tj
+-426 TJm
+(nBuf) 23.9102 Tj
+-426 TJm
+(appropriately) 77.7083 Tj
+421.874 335.391 Td
+(*) 5.97756 Tj
+427.852 337.135 Td
+(/) 5.97756 Tj
+94.2439 325.18 Td
+(nWritten) 47.8205 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ2_bzWrite) 65.7532 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(&bzerror,) 53.798 Tj
+-426 TJm
+(b,) 11.9551 Tj
+-426 TJm
+(buf,) 23.9102 Tj
+-426 TJm
+(nBuf) 23.9102 Tj
+-426 TJm
+(\);) 11.9551 Tj
+94.2439 313.225 Td
+(if) 11.9551 Tj
+-426 TJm
+(\(bzerror) 47.8205 Tj
+-426 TJm
+(==) 11.9551 Tj
+-426 TJm
+(BZ_IO_ERROR\)) 71.7307 Tj
+-426 TJm
+({) 5.97756 Tj
+102.732 301.269 Td
+(BZ2_bzWriteClose) 95.641 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(&bzerror,) 53.798 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+102.732 289.314 Td
+(/) 5.97756 Tj
+108.709 287.571 Td
+(*) 5.97756 Tj
+118.931 289.314 Td
+(handle) 35.8654 Tj
+-426 TJm
+(error) 29.8878 Tj
+193.172 287.571 Td
+(*) 5.97756 Tj
+199.15 289.314 Td
+(/) 5.97756 Tj
+94.2439 277.359 Td
+(}) 5.97756 Tj
+90 265.404 Td
+(}) 5.97756 Tj
+90 241.494 Td
+(BZ2_bzWriteClose\() 101.619 Tj
+-426 TJm
+(&bzerror,) 53.798 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 229.538 Td
+(if) 11.9551 Tj
+-426 TJm
+(\(bzerror) 47.8205 Tj
+-426 TJm
+(==) 11.9551 Tj
+-426 TJm
+(BZ_IO_ERROR\)) 71.7307 Tj
+-426 TJm
+({) 5.97756 Tj
+94.2439 217.583 Td
+(/) 5.97756 Tj
+100.221 215.84 Td
+(*) 5.97756 Tj
+110.443 217.583 Td
+(handle) 35.8654 Tj
+-426 TJm
+(error) 29.8878 Tj
+184.684 215.84 Td
+(*) 5.97756 Tj
+190.662 217.583 Td
+(/) 5.97756 Tj
+89.9999 205.628 Td
+(}) 5.97756 Tj
+[1 0 0 1 72 190.086] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -180.124] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 168.168 Td
+/F130_0 9.9626 Tf
+(And) 17.1556 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(read) 17.1456 Tj
+-250 TJm
+(from) 19.3673 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le:) 15.5018 Tj
+[1 0 0 1 72 166.012] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -115.16] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9513] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9513 Td
+/F130_0 9.9626 Tf
+(25) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 29 29
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -392.164] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 370.61 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 367.024] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(FILE) 23.9102 Tj
+113.91 709.888 Td
+(*) 5.97756 Tj
+132.62 711.631 Td
+(f;) 11.9551 Tj
+90 699.676 Td
+(BZFILE) 35.8654 Tj
+125.865 697.933 Td
+(*) 5.97756 Tj
+136.087 699.676 Td
+(b;) 11.9551 Tj
+90 687.721 Td
+(int) 17.9327 Tj
+-2130 TJm
+(nBuf;) 29.8878 Tj
+90 675.766 Td
+(char) 23.9102 Tj
+-1704 TJm
+(buf[) 23.9102 Tj
+-426 TJm
+(/) 5.97756 Tj
+165.018 674.023 Td
+(*) 5.97756 Tj
+175.24 675.766 Td
+(whatever) 47.8205 Tj
+-426 TJm
+(size) 23.9102 Tj
+-426 TJm
+(you) 17.9327 Tj
+-426 TJm
+(like) 23.9102 Tj
+305.79 674.023 Td
+(*) 5.97756 Tj
+311.767 675.766 Td
+(/) 5.97756 Tj
+-426 TJm
+(];) 11.9551 Tj
+90 663.811 Td
+(int) 17.9327 Tj
+-2130 TJm
+(bzerror;) 47.8205 Tj
+90 651.856 Td
+(int) 17.9327 Tj
+-2130 TJm
+(nWritten;) 53.798 Tj
+90 627.945 Td
+(f) 5.97756 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(fopen) 29.8878 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+("myfile.bz2",) 77.7083 Tj
+-426 TJm
+("r") 17.9327 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 615.99 Td
+(if) 11.9551 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(!f) 11.9551 Tj
+-426 TJm
+(\)) 5.97756 Tj
+-426 TJm
+({) 5.97756 Tj
+98.488 604.035 Td
+(/) 5.97756 Tj
+104.466 602.292 Td
+(*) 5.97756 Tj
+114.687 604.035 Td
+(handle) 35.8654 Tj
+-426 TJm
+(error) 29.8878 Tj
+188.929 602.292 Td
+(*) 5.97756 Tj
+194.906 604.035 Td
+(/) 5.97756 Tj
+90 592.08 Td
+(}) 5.97756 Tj
+90 580.125 Td
+(b) 5.97756 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ2_bzReadOpen) 83.6858 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(&bzerror,) 53.798 Tj
+-426 TJm
+(f,) 11.9551 Tj
+-426 TJm
+(0,) 11.9551 Tj
+-426 TJm
+(NULL,) 29.8878 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 568.169 Td
+(if) 11.9551 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(!=) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+-426 TJm
+(\)) 5.97756 Tj
+-426 TJm
+({) 5.97756 Tj
+98.488 556.214 Td
+(BZ2_bzReadClose) 89.6634 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(&bzerror,) 53.798 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+98.488 544.259 Td
+(/) 5.97756 Tj
+104.466 542.516 Td
+(*) 5.97756 Tj
+114.687 544.259 Td
+(handle) 35.8654 Tj
+-426 TJm
+(error) 29.8878 Tj
+188.929 542.516 Td
+(*) 5.97756 Tj
+194.906 544.259 Td
+(/) 5.97756 Tj
+90 532.304 Td
+(}) 5.97756 Tj
+90 508.394 Td
+(bzerror) 41.8429 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ_OK;) 35.8654 Tj
+90 496.438 Td
+(while) 29.8878 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(==) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+-426 TJm
+(&&) 11.9551 Tj
+-426 TJm
+(/) 5.97756 Tj
+252.948 494.695 Td
+(*) 5.97756 Tj
+263.17 496.438 Td
+(arbitrary) 53.798 Tj
+-426 TJm
+(other) 29.8878 Tj
+-426 TJm
+(conditions) 59.7756 Tj
+419.364 494.695 Td
+(*) 5.97756 Tj
+425.341 496.438 Td
+(/\)) 11.9551 Tj
+-426 TJm
+({) 5.97756 Tj
+98.488 484.483 Td
+(nBuf) 23.9102 Tj
+-426 TJm
+(=) 5.97756 Tj
+-426 TJm
+(BZ2_bzRead) 59.7756 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(&bzerror,) 53.798 Tj
+-426 TJm
+(b,) 11.9551 Tj
+-426 TJm
+(buf,) 23.9102 Tj
+-426 TJm
+(/) 5.97756 Tj
+319.478 482.74 Td
+(*) 5.97756 Tj
+329.7 484.483 Td
+(size) 23.9102 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(buf) 17.9327 Tj
+396.23 482.74 Td
+(*) 5.97756 Tj
+402.208 484.483 Td
+(/) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+98.488 472.528 Td
+(if) 11.9551 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(==) 11.9551 Tj
+-426 TJm
+(BZ_OK) 29.8878 Tj
+-426 TJm
+(\)) 5.97756 Tj
+-426 TJm
+({) 5.97756 Tj
+106.976 460.573 Td
+(/) 5.97756 Tj
+112.953 458.829 Td
+(*) 5.97756 Tj
+123.175 460.573 Td
+(do) 11.9551 Tj
+-426 TJm
+(something) 53.798 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(buf[0) 29.8878 Tj
+-426 TJm
+(..) 11.9551 Tj
+-426 TJm
+(nBuf-1]) 41.8429 Tj
+321.989 458.829 Td
+(*) 5.97756 Tj
+327.966 460.573 Td
+(/) 5.97756 Tj
+98.4879 448.618 Td
+(}) 5.97756 Tj
+90 436.663 Td
+(}) 5.97756 Tj
+90 424.707 Td
+(if) 11.9551 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(bzerror) 41.8429 Tj
+-426 TJm
+(!=) 11.9551 Tj
+-426 TJm
+(BZ_STREAM_END) 77.7083 Tj
+-426 TJm
+(\)) 5.97756 Tj
+-426 TJm
+({) 5.97756 Tj
+102.732 412.752 Td
+(BZ2_bzReadClose) 89.6634 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(&bzerror,) 53.798 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+102.732 400.797 Td
+(/) 5.97756 Tj
+108.709 399.054 Td
+(*) 5.97756 Tj
+118.931 400.797 Td
+(handle) 35.8654 Tj
+-426 TJm
+(error) 29.8878 Tj
+193.172 399.054 Td
+(*) 5.97756 Tj
+199.15 400.797 Td
+(/) 5.97756 Tj
+90 388.842 Td
+(}) 5.97756 Tj
+-426 TJm
+(else) 23.9102 Tj
+-426 TJm
+({) 5.97756 Tj
+102.732 376.887 Td
+(BZ2_bzReadClose) 89.6634 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(&bzerror,) 53.798 Tj
+-426 TJm
+(b) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 364.932 Td
+(}) 5.97756 Tj
+[1 0 0 1 72 349.39] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -339.427] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 314.637 Td
+/F122_0 20.6585 Tf
+(3.5.) 34.4584 Tj
+-278 TJm
+(Utility) 57.3893 Tj
+-278 TJm
+(functions) 92.9633 Tj
+[1 0 0 1 72 310.361] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -300.398] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 284.016 Td
+/F122_0 17.2154 Tf
+(3.5.1.) 43.0729 Tj
+[1 0 0 1 119.858 284.016] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -284.016] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 284.016 Td
+/F392_0 17.2154 Tf
+(BZ2_bzBuffToBuffCompress) 247.902 Tj
+[1 0 0 1 367.76 284.016] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -295.76 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -96.6376] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 95.6413 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 92.0548] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -272.318] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 272.318 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzBuffToBuffCompress\() 149.439 Tj
+-426 TJm
+(char) 23.9102 Tj
+289.771 270.575 Td
+(*) 5.97756 Tj
+333.944 272.318 Td
+(dest,) 29.8878 Tj
+217.319 260.363 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+287.317 258.62 Td
+(*) 5.97756 Tj
+297.538 260.363 Td
+(destLen,) 47.8205 Tj
+217.319 248.408 Td
+(char) 23.9102 Tj
+241.23 246.664 Td
+(*) 5.97756 Tj
+285.403 248.408 Td
+(source,) 41.8429 Tj
+217.319 236.453 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+-852 TJm
+(sourceLen,) 59.7756 Tj
+217.319 224.498 Td
+(int) 17.9327 Tj
+-4686 TJm
+(blockSize100k,) 83.6858 Tj
+217.319 212.542 Td
+(int) 17.9327 Tj
+-4686 TJm
+(verbosity,) 59.7756 Tj
+217.319 200.587 Td
+(int) 17.9327 Tj
+-4686 TJm
+(workFactor) 59.7756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 185.045] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -175.083] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 163.128 Td
+/F130_0 9.9626 Tf
+(Attempts) 36.5329 Tj
+-442 TJm
+(to) 7.7509 Tj
+-442 TJm
+(compress) 37.6287 Tj
+-443 TJm
+(the) 12.1743 Tj
+-442 TJm
+(data) 16.5977 Tj
+-442 TJm
+(in) 7.7509 Tj
+[1 0 0 1 216.87 163.128] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -216.87 -163.128] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+216.87 163.128 Td
+/F134_0 9.9626 Tf
+(source[0) 47.8205 Tj
+-600 TJm
+(..) 11.9551 Tj
+-1200 TJm
+(sourceLen-1]) 71.7307 Tj
+[1 0 0 1 366.31 163.128] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -366.31 -163.128] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+370.715 163.128 Td
+/F130_0 9.9626 Tf
+(into) 15.5018 Tj
+-442 TJm
+(the) 12.1743 Tj
+-442 TJm
+(destination) 43.7259 Tj
+-443 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+40 TJm
+(,) 2.49065 Tj
+[1 0 0 1 486.202 163.128] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -486.202 -163.128] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+486.202 163.128 Td
+/F134_0 9.9626 Tf
+(dest[0) 35.8654 Tj
+-600 TJm
+(..) 11.9551 Tj
+72 149.429 Td
+(*) 5.97756 Tj
+77.9776 151.173 Td
+(destLen-1]) 59.7756 Tj
+[1 0 0 1 137.753 151.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.753 -151.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+137.753 151.172 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1393 TJm
+(If) 6.63509 Tj
+-379 TJm
+(the) 12.1743 Tj
+-379 TJm
+(destination) 43.7259 Tj
+-379 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-378 TJm
+(is) 6.64505 Tj
+-379 TJm
+(big) 12.7322 Tj
+-379 TJm
+(enough,) 31.8205 Tj
+[1 0 0 1 318.486 151.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -318.486 -151.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+318.486 149.429 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+324.464 151.173 Td
+(destLen) 41.8429 Tj
+[1 0 0 1 366.307 151.172] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -366.307 -151.172] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+370.081 151.172 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-379 TJm
+(set) 11.0684 Tj
+-379 TJm
+(to) 7.7509 Tj
+-378 TJm
+(the) 12.1743 Tj
+-379 TJm
+(size) 15.4918 Tj
+-379 TJm
+(of) 8.29885 Tj
+-379 TJm
+(the) 12.1743 Tj
+-379 TJm
+(compressed) 47.0334 Tj
+-379 TJm
+(data,) 19.0883 Tj
+72 139.217 Td
+(and) 14.386 Tj
+[1 0 0 1 89.5273 139.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -89.5273 -139.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+89.5273 139.217 Td
+/F134_0 9.9626 Tf
+(BZ_OK) 29.8878 Tj
+[1 0 0 1 119.415 139.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.415 -139.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+122.556 139.217 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-315 TJm
+(returned.) 35.686 Tj
+-1012 TJm
+(If) 6.63509 Tj
+-315 TJm
+(the) 12.1743 Tj
+-316 TJm
+(compressed) 47.0334 Tj
+-315 TJm
+(data) 16.5977 Tj
+-315 TJm
+(w) 7.193 Tj
+10 TJm
+(on') 13.2801 Tj
+18 TJm
+(t) 2.7696 Tj
+-316 TJm
+(\002t,) 10.7995 Tj
+[1 0 0 1 313.322 139.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -313.322 -139.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+313.322 137.474 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+319.3 139.217 Td
+(destLen) 41.8429 Tj
+[1 0 0 1 361.143 139.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -361.143 -139.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+364.284 139.217 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-315 TJm
+(unchanged,) 45.6486 Tj
+-332 TJm
+(and) 14.386 Tj
+[1 0 0 1 440.551 139.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -440.551 -139.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+440.551 139.217 Td
+/F134_0 9.9626 Tf
+(BZ_OUTBUFF_FULL) 89.6634 Tj
+[1 0 0 1 530.215 139.217] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -530.215 -139.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+533.355 139.217 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+72 127.262 Td
+(returned.) 35.686 Tj
+[1 0 0 1 72 127.163] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -117.2] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 105.344 Td
+/F130_0 9.9626 Tf
+(Compression) 52.5826 Tj
+-297 TJm
+(in) 7.7509 Tj
+-297 TJm
+(this) 14.396 Tj
+-297 TJm
+(manner) 29.8778 Tj
+-297 TJm
+(is) 6.64505 Tj
+-297 TJm
+(a) 4.42339 Tj
+-297 TJm
+(one-shot) 34.3112 Tj
+-297 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ent,) 14.6649 Tj
+-309 TJm
+(done) 19.3673 Tj
+-297 TJm
+(with) 17.7135 Tj
+-297 TJm
+(a) 4.42339 Tj
+-297 TJm
+(single) 23.8007 Tj
+-297 TJm
+(call) 14.386 Tj
+-297 TJm
+(to) 7.7509 Tj
+-297 TJm
+(this) 14.396 Tj
+-297 TJm
+(function.) 35.696 Tj
+-903 TJm
+(The) 15.4918 Tj
+-297 TJm
+(resulting) 34.8691 Tj
+-297 TJm
+(compressed) 47.0334 Tj
+72 93.3892 Td
+(data) 16.5977 Tj
+-296 TJm
+(is) 6.64505 Tj
+-296 TJm
+(a) 4.42339 Tj
+-296 TJm
+(complete) 36.5229 Tj
+[1 0 0 1 147.988 93.3892] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -147.988 -93.3892] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+147.988 93.3892 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 177.875 93.3892] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -177.875 -93.3892] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+180.825 93.3892 Td
+/F130_0 9.9626 Tf
+(format) 26.5603 Tj
+-296 TJm
+(data) 16.5977 Tj
+-296 TJm
+(stream.) 29.0509 Tj
+-897 TJm
+(There) 23.2328 Tj
+-296 TJm
+(is) 6.64505 Tj
+-296 TJm
+(no) 9.9626 Tj
+-296 TJm
+(mechanism) 45.3796 Tj
+-296 TJm
+(for) 11.6164 Tj
+-296 TJm
+(making) 29.8878 Tj
+-296 TJm
+(additional) 39.8504 Tj
+-296 TJm
+(calls) 18.2614 Tj
+-296 TJm
+(to) 7.7509 Tj
+-296 TJm
+(pro) 13.2801 Tj
+15 TJm
+(vide) 17.1556 Tj
+-296 TJm
+(e) 4.42339 Tj
+15 TJm
+(xtra) 15.4918 Tj
+72 81.434 Td
+(input) 20.4831 Tj
+-250 TJm
+(data.) 19.0883 Tj
+-620 TJm
+(If) 6.63509 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-250 TJm
+(that) 14.9439 Tj
+-250 TJm
+(kind) 17.7135 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(mechanism,) 47.8703 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(lo) 7.7509 Tj
+25 TJm
+(w-le) 17.7035 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(el) 7.193 Tj
+-250 TJm
+(interf) 21.579 Tj
+10 TJm
+(ace.) 15.7608 Tj
+[1 0 0 1 72 79.2772] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -28.4254] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(26) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 30 30
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-223 TJm
+(the) 12.1743 Tj
+-224 TJm
+(meaning) 34.3112 Tj
+-223 TJm
+(of) 8.29885 Tj
+-224 TJm
+(parameters) 43.7059 Tj
+[1 0 0 1 195.306 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -195.306 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+195.306 710.037 Td
+/F134_0 9.9626 Tf
+(blockSize100k) 77.7083 Tj
+[1 0 0 1 273.015 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -273.015 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+273.015 710.037 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 277.784 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -277.784 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+277.784 710.037 Td
+/F134_0 9.9626 Tf
+(verbosity) 53.798 Tj
+[1 0 0 1 331.583 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -331.583 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+333.808 710.037 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 350.42 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -350.42 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+350.42 710.037 Td
+/F134_0 9.9626 Tf
+(workFactor) 59.7756 Tj
+[1 0 0 1 410.196 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -410.196 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+410.196 710.037 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-229 TJm
+(see) 12.7222 Tj
+[1 0 0 1 429.913 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -429.913 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+429.913 710.037 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 537.509 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -537.509 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+537.509 710.037 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 707.88] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -697.918] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 688.12 Td
+/F130_0 9.9626 Tf
+(T) 6.08715 Tj
+80 TJm
+(o) 4.9813 Tj
+-410 TJm
+(guarantee) 38.7246 Tj
+-410 TJm
+(that) 14.9439 Tj
+-410 TJm
+(the) 12.1743 Tj
+-410 TJm
+(compressed) 47.0334 Tj
+-410 TJm
+(data) 16.5977 Tj
+-410 TJm
+(will) 15.5018 Tj
+-410 TJm
+(\002t) 8.30881 Tj
+-410 TJm
+(in) 7.7509 Tj
+-410 TJm
+(its) 9.41466 Tj
+-410 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+40 TJm
+(,) 2.49065 Tj
+-450 TJm
+(allocate) 30.9837 Tj
+-410 TJm
+(an) 9.40469 Tj
+-410 TJm
+(output) 25.4644 Tj
+-410 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-411 TJm
+(of) 8.29885 Tj
+-410 TJm
+(size) 15.4918 Tj
+-410 TJm
+(1%) 13.2801 Tj
+-410 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ger) 12.7222 Tj
+-410 TJm
+(than) 17.1556 Tj
+-410 TJm
+(the) 12.1743 Tj
+72 676.164 Td
+(uncompressed) 56.996 Tj
+-250 TJm
+(data,) 19.0883 Tj
+-250 TJm
+(plus) 16.6077 Tj
+-250 TJm
+(six) 11.6264 Tj
+-250 TJm
+(hundred) 32.6474 Tj
+-250 TJm
+(e) 4.42339 Tj
+15 TJm
+(xtra) 15.4918 Tj
+-250 TJm
+(bytes.) 23.5217 Tj
+[1 0 0 1 72 674.007] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -664.045] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 654.247 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffDecompress) 155.417 Tj
+[1 0 0 1 227.417 654.247] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -227.417 -654.247] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+230.553 654.247 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-315 TJm
+(not) 12.7322 Tj
+-315 TJm
+(write) 20.4731 Tj
+-314 TJm
+(data) 16.5977 Tj
+-315 TJm
+(at) 7.193 Tj
+-315 TJm
+(or) 8.29885 Tj
+-315 TJm
+(be) 9.40469 Tj
+15 TJm
+(yond) 19.9252 Tj
+[1 0 0 1 362.484 654.247] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -362.484 -654.247] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+362.484 654.247 Td
+/F134_0 9.9626 Tf
+(dest[) 29.8878 Tj
+392.372 652.503 Td
+(*) 5.97756 Tj
+398.349 654.247 Td
+(destLen]) 47.8205 Tj
+[1 0 0 1 446.17 654.247] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -446.17 -654.247] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+446.17 654.247 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-331 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-315 TJm
+(in) 7.7509 Tj
+-315 TJm
+(case) 17.1456 Tj
+-314 TJm
+(of) 8.29885 Tj
+-315 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+72 642.291 Td
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er\003o) 18.2614 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 642.192] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -632.229] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 620.374 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 620.274] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -168.369] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 167.372 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 163.786] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -610.909] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 610.909 Td
+/F134_0 9.9626 Tf
+(BZ_CONFIG_ERROR) 89.6634 Tj
+98.4879 598.954 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(library) 41.8429 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(mis-compiled) 71.7307 Tj
+90 586.999 Td
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 575.044 Td
+(if) 11.9551 Tj
+-426 TJm
+(dest) 23.9102 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(destLen) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+98.4879 563.088 Td
+(or) 11.9551 Tj
+-426 TJm
+(blockSize100k) 77.7083 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(1) 5.97756 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(blockSize100k) 77.7083 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(9) 5.97756 Tj
+98.4879 551.133 Td
+(or) 11.9551 Tj
+-426 TJm
+(verbosity) 53.798 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(verbosity) 53.798 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(4) 5.97756 Tj
+98.4879 539.178 Td
+(or) 11.9551 Tj
+-426 TJm
+(workFactor) 59.7756 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(workFactor) 59.7756 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(250) 17.9327 Tj
+90 527.223 Td
+(BZ_MEM_ERROR) 71.7307 Tj
+98.4879 515.268 Td
+(if) 11.9551 Tj
+-426 TJm
+(insufficient) 71.7307 Tj
+-426 TJm
+(memory) 35.8654 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(available) 53.798 Tj
+90 503.313 Td
+(BZ_OUTBUFF_FULL) 89.6634 Tj
+98.4879 491.357 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(size) 23.9102 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(exceeds) 41.8429 Tj
+341.655 489.614 Td
+(*) 5.97756 Tj
+347.633 491.357 Td
+(destLen) 41.8429 Tj
+90 479.402 Td
+(BZ_OK) 29.8878 Tj
+98.4879 467.447 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 451.905] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -441.943] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 421.284 Td
+/F122_0 17.2154 Tf
+(3.5.2.) 43.0729 Tj
+[1 0 0 1 119.858 421.284] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.858 -421.284] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.858 421.284 Td
+/F392_0 17.2154 Tf
+(BZ2_bzBuffToBuffDecompress) 268.56 Tj
+[1 0 0 1 388.419 421.284] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -316.419 -2.3327] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -84.6824] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 83.6862 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 80.0996] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -409.587] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 409.587 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzBuffToBuffDecompress\() 161.394 Tj
+-426 TJm
+(char) 23.9102 Tj
+301.726 407.843 Td
+(*) 5.97756 Tj
+345.899 409.587 Td
+(dest,) 29.8878 Tj
+225.807 397.632 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+295.805 395.888 Td
+(*) 5.97756 Tj
+306.026 397.632 Td
+(destLen,) 47.8205 Tj
+225.807 385.676 Td
+(char) 23.9102 Tj
+249.718 383.933 Td
+(*) 5.97756 Tj
+293.891 385.676 Td
+(source,) 41.8429 Tj
+225.807 373.721 Td
+(unsigned) 47.8205 Tj
+-426 TJm
+(int) 17.9327 Tj
+-852 TJm
+(sourceLen,) 59.7756 Tj
+225.807 361.766 Td
+(int) 17.9327 Tj
+-4686 TJm
+(small,) 35.8654 Tj
+225.807 349.811 Td
+(int) 17.9327 Tj
+-4686 TJm
+(verbosity) 53.798 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 334.269] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -324.306] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 312.351 Td
+/F130_0 9.9626 Tf
+(Attempts) 36.5329 Tj
+-358 TJm
+(to) 7.7509 Tj
+-359 TJm
+(decompress) 47.0334 Tj
+-358 TJm
+(the) 12.1743 Tj
+-358 TJm
+(data) 16.5977 Tj
+-359 TJm
+(in) 7.7509 Tj
+[1 0 0 1 221.259 312.351] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -221.259 -312.351] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+221.259 312.351 Td
+/F134_0 9.9626 Tf
+(source[0) 47.8205 Tj
+-600 TJm
+(..) 11.9551 Tj
+-1200 TJm
+(sourceLen-1]) 71.7307 Tj
+[1 0 0 1 370.698 312.351] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -370.698 -312.351] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+374.268 312.351 Td
+/F130_0 9.9626 Tf
+(into) 15.5018 Tj
+-358 TJm
+(the) 12.1743 Tj
+-359 TJm
+(destination) 43.7259 Tj
+-358 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+40 TJm
+(,) 2.49065 Tj
+[1 0 0 1 486.202 312.351] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -486.202 -312.351] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+486.202 312.351 Td
+/F134_0 9.9626 Tf
+(dest[0) 35.8654 Tj
+-600 TJm
+(..) 11.9551 Tj
+72 298.653 Td
+(*) 5.97756 Tj
+77.9776 300.396 Td
+(destLen-1]) 59.7756 Tj
+[1 0 0 1 137.753 300.396] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.753 -300.396] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+137.753 300.396 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1123 TJm
+(If) 6.63509 Tj
+-334 TJm
+(the) 12.1743 Tj
+-334 TJm
+(destination) 43.7259 Tj
+-334 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-334 TJm
+(is) 6.64505 Tj
+-334 TJm
+(big) 12.7322 Tj
+-334 TJm
+(enough,) 31.8205 Tj
+[1 0 0 1 312.554 300.396] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -312.554 -300.396] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+312.554 298.653 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+318.531 300.396 Td
+(destLen) 41.8429 Tj
+[1 0 0 1 360.374 300.396] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -360.374 -300.396] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+363.701 300.396 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-334 TJm
+(set) 11.0684 Tj
+-334 TJm
+(to) 7.7509 Tj
+-334 TJm
+(the) 12.1743 Tj
+-334 TJm
+(size) 15.4918 Tj
+-333 TJm
+(of) 8.29885 Tj
+-334 TJm
+(the) 12.1743 Tj
+-334 TJm
+(uncompressed) 56.996 Tj
+-334 TJm
+(data,) 19.0883 Tj
+72 288.441 Td
+(and) 14.386 Tj
+[1 0 0 1 89.5273 288.441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -89.5273 -288.441] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+89.5273 288.441 Td
+/F134_0 9.9626 Tf
+(BZ_OK) 29.8878 Tj
+[1 0 0 1 119.415 288.441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.415 -288.441] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+122.556 288.441 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-315 TJm
+(returned.) 35.686 Tj
+-1012 TJm
+(If) 6.63509 Tj
+-315 TJm
+(the) 12.1743 Tj
+-316 TJm
+(compressed) 47.0334 Tj
+-315 TJm
+(data) 16.5977 Tj
+-315 TJm
+(w) 7.193 Tj
+10 TJm
+(on') 13.2801 Tj
+18 TJm
+(t) 2.7696 Tj
+-316 TJm
+(\002t,) 10.7995 Tj
+[1 0 0 1 313.322 288.441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -313.322 -288.441] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+313.322 286.698 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+319.3 288.441 Td
+(destLen) 41.8429 Tj
+[1 0 0 1 361.143 288.441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -361.143 -288.441] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+364.284 288.441 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-315 TJm
+(unchanged,) 45.6486 Tj
+-332 TJm
+(and) 14.386 Tj
+[1 0 0 1 440.551 288.441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -440.551 -288.441] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+440.551 288.441 Td
+/F134_0 9.9626 Tf
+(BZ_OUTBUFF_FULL) 89.6634 Tj
+[1 0 0 1 530.215 288.441] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -530.215 -288.441] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+533.355 288.441 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+72 276.486 Td
+(returned.) 35.686 Tj
+[1 0 0 1 72 276.386] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -266.424] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 254.568 Td
+/F134_0 9.9626 Tf
+(source) 35.8654 Tj
+[1 0 0 1 107.865 254.568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -107.865 -254.568] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+110.981 254.568 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-313 TJm
+(assumed) 34.3112 Tj
+-312 TJm
+(to) 7.7509 Tj
+-313 TJm
+(hold) 17.7135 Tj
+-313 TJm
+(a) 4.42339 Tj
+-313 TJm
+(complete) 36.5229 Tj
+[1 0 0 1 237.04 254.568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -237.04 -254.568] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+237.04 254.568 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 266.928 254.568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -266.928 -254.568] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+270.044 254.568 Td
+/F130_0 9.9626 Tf
+(format) 26.5603 Tj
+-313 TJm
+(data) 16.5977 Tj
+-312 TJm
+(stream.) 29.0509 Tj
+[1 0 0 1 353.446 254.568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -353.446 -254.568] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+353.446 254.568 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffDecompress) 155.417 Tj
+[1 0 0 1 508.863 254.568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -508.863 -254.568] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+511.978 254.568 Td
+/F130_0 9.9626 Tf
+(tries) 17.1556 Tj
+-313 TJm
+(to) 7.7509 Tj
+72 242.613 Td
+(decompress) 47.0334 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(entirety) 30.4357 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(stream) 26.5603 Tj
+-250 TJm
+(into) 15.5018 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(output) 25.4644 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+55 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 240.456] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -230.493] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 220.695 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(meaning) 34.3112 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(parameters) 43.7059 Tj
+[1 0 0 1 196.631 220.695] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -196.631 -220.695] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+196.631 220.695 Td
+/F134_0 9.9626 Tf
+(small) 29.8878 Tj
+[1 0 0 1 226.519 220.695] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -226.519 -220.695] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+229.01 220.695 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 245.887 220.695] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -245.887 -220.695] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+245.887 220.695 Td
+/F134_0 9.9626 Tf
+(verbosity) 53.798 Tj
+[1 0 0 1 299.685 220.695] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -299.685 -220.695] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+299.685 220.695 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(see) 12.7222 Tj
+[1 0 0 1 319.879 220.695] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -319.879 -220.695] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+319.879 220.695 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressInit) 119.551 Tj
+[1 0 0 1 439.431 220.695] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -439.431 -220.695] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+439.431 220.695 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 218.538] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -208.576] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 198.777 Td
+/F130_0 9.9626 Tf
+(Because) 33.1954 Tj
+-250 TJm
+(the) 12.1743 Tj
+-249 TJm
+(compression) 50.3609 Tj
+-250 TJm
+(ratio) 18.2614 Tj
+-249 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-249 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(data) 16.5977 Tj
+-249 TJm
+(cannot) 26.5603 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(kno) 14.9439 Tj
+25 TJm
+(wn) 12.1743 Tj
+-249 TJm
+(in) 7.7509 Tj
+-250 TJm
+(adv) 14.386 Tj
+25 TJm
+(ance,) 20.7421 Tj
+-249 TJm
+(there) 19.9152 Tj
+-250 TJm
+(is) 6.64505 Tj
+-249 TJm
+(no) 9.9626 Tj
+-250 TJm
+(easy) 17.7035 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ay) 9.40469 Tj
+-249 TJm
+(to) 7.7509 Tj
+-250 TJm
+(guarantee) 38.7246 Tj
+72 186.822 Td
+(that) 14.9439 Tj
+-286 TJm
+(the) 12.1743 Tj
+-287 TJm
+(output) 25.4644 Tj
+-286 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+-287 TJm
+(will) 15.5018 Tj
+-286 TJm
+(be) 9.40469 Tj
+-286 TJm
+(big) 12.7322 Tj
+-287 TJm
+(enough.) 31.8205 Tj
+-838 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-287 TJm
+(may) 17.1556 Tj
+-286 TJm
+(of) 8.29885 Tj
+-287 TJm
+(course) 26.0024 Tj
+-286 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-286 TJm
+(arrangements) 53.6685 Tj
+-287 TJm
+(in) 7.7509 Tj
+-286 TJm
+(your) 18.2614 Tj
+-287 TJm
+(code) 18.8094 Tj
+-286 TJm
+(to) 7.7509 Tj
+-286 TJm
+(record) 25.4445 Tj
+-287 TJm
+(the) 12.1743 Tj
+-286 TJm
+(size) 15.4918 Tj
+-287 TJm
+(of) 8.29885 Tj
+72 174.867 Td
+(the) 12.1743 Tj
+-250 TJm
+(uncompressed) 56.996 Tj
+-250 TJm
+(data,) 19.0883 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(such) 18.2614 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(mechanism) 45.3796 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(be) 9.40469 Tj
+15 TJm
+(yond) 19.9252 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(scope) 22.6848 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(library) 26.5603 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 172.71] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -162.747] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 152.949 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffDecompress) 155.417 Tj
+[1 0 0 1 227.417 152.949] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -227.417 -152.949] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+230.553 152.949 Td
+/F130_0 9.9626 Tf
+(will) 15.5018 Tj
+-315 TJm
+(not) 12.7322 Tj
+-315 TJm
+(write) 20.4731 Tj
+-314 TJm
+(data) 16.5977 Tj
+-315 TJm
+(at) 7.193 Tj
+-315 TJm
+(or) 8.29885 Tj
+-315 TJm
+(be) 9.40469 Tj
+15 TJm
+(yond) 19.9252 Tj
+[1 0 0 1 362.484 152.949] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -362.484 -152.949] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+362.484 152.949 Td
+/F134_0 9.9626 Tf
+(dest[) 29.8878 Tj
+392.372 151.206 Td
+(*) 5.97756 Tj
+398.349 152.949 Td
+(destLen]) 47.8205 Tj
+[1 0 0 1 446.17 152.949] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -446.17 -152.949] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+446.17 152.949 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-331 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(en) 9.40469 Tj
+-315 TJm
+(in) 7.7509 Tj
+-315 TJm
+(case) 17.1456 Tj
+-314 TJm
+(of) 8.29885 Tj
+-315 TJm
+(b) 4.9813 Tj
+20 TJm
+(uf) 8.29885 Tj
+25 TJm
+(fer) 11.0585 Tj
+72 140.994 Td
+(o) 4.9813 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(er\003o) 18.2614 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 140.894] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -130.932] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 119.076 Td
+/F130_0 9.9626 Tf
+(Possible) 33.2153 Tj
+-250 TJm
+(return) 23.7907 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues:) 23.2427 Tj
+[1 0 0 1 72 118.977] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -68.1248] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(27) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 31 31
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 4.3836 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -344.462 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+420.96 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 498.449 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -498.449 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+498.449 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 546.269 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -15.0365 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -248.702] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 227.148 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 223.562] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -711.631] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 711.631 Td
+/F134_0 9.9626 Tf
+(BZ_CONFIG_ERROR) 89.6634 Tj
+98.4879 699.676 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(library) 41.8429 Tj
+-426 TJm
+(has) 17.9327 Tj
+-426 TJm
+(been) 23.9102 Tj
+-426 TJm
+(mis-compiled) 71.7307 Tj
+90 687.721 Td
+(BZ_PARAM_ERROR) 83.6858 Tj
+98.4879 675.766 Td
+(if) 11.9551 Tj
+-426 TJm
+(dest) 23.9102 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(destLen) 41.8429 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(NULL) 23.9102 Tj
+98.4879 663.811 Td
+(or) 11.9551 Tj
+-426 TJm
+(small) 29.8878 Tj
+-426 TJm
+(!=) 11.9551 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(&&) 11.9551 Tj
+-426 TJm
+(small) 29.8878 Tj
+-426 TJm
+(!=) 11.9551 Tj
+-426 TJm
+(1) 5.97756 Tj
+98.4879 651.856 Td
+(or) 11.9551 Tj
+-426 TJm
+(verbosity) 53.798 Tj
+-426 TJm
+(<) 5.97756 Tj
+-426 TJm
+(0) 5.97756 Tj
+-426 TJm
+(or) 11.9551 Tj
+-426 TJm
+(verbosity) 53.798 Tj
+-426 TJm
+(>) 5.97756 Tj
+-426 TJm
+(4) 5.97756 Tj
+90 639.9 Td
+(BZ_MEM_ERROR) 71.7307 Tj
+98.4879 627.945 Td
+(if) 11.9551 Tj
+-426 TJm
+(insufficient) 71.7307 Tj
+-426 TJm
+(memory) 35.8654 Tj
+-426 TJm
+(is) 11.9551 Tj
+-426 TJm
+(available) 53.798 Tj
+90 615.99 Td
+(BZ_OUTBUFF_FULL) 89.6634 Tj
+98.4879 604.035 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(size) 23.9102 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(exceeds) 41.8429 Tj
+341.655 602.291 Td
+(*) 5.97756 Tj
+347.633 604.035 Td
+(destLen) 41.8429 Tj
+90 592.08 Td
+(BZ_DATA_ERROR) 77.7083 Tj
+98.4879 580.125 Td
+(if) 11.9551 Tj
+-426 TJm
+(a) 5.97756 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(integrity) 53.798 Tj
+-426 TJm
+(error) 29.8878 Tj
+-426 TJm
+(was) 17.9327 Tj
+-426 TJm
+(detected) 47.8205 Tj
+-426 TJm
+(in) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(data) 23.9102 Tj
+90 568.169 Td
+(BZ_DATA_ERROR_MAGIC) 113.574 Tj
+98.4879 556.214 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(doesn't) 41.8429 Tj
+-426 TJm
+(begin) 29.8878 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(right) 29.8878 Tj
+-426 TJm
+(magic) 29.8878 Tj
+-426 TJm
+(bytes) 29.8878 Tj
+90 544.259 Td
+(BZ_UNEXPECTED_EOF) 101.619 Tj
+98.4879 532.304 Td
+(if) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compressed) 59.7756 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(ends) 23.9102 Tj
+-426 TJm
+(unexpectedly) 71.7307 Tj
+90 520.349 Td
+(BZ_OK) 29.8878 Tj
+98.4879 508.394 Td
+(otherwise) 53.798 Tj
+[1 0 0 1 72 492.852] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -482.889] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 458.099 Td
+/F122_0 20.6585 Tf
+(3.6.) 34.4584 Tj
+[1 0 0 1 112.201 458.099] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -112.201 -458.099] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+112.201 458.099 Td
+/F392_0 20.6585 Tf
+(zlib) 49.5804 Tj
+[1 0 0 1 161.781 458.099] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -161.781 -458.099] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+167.524 458.099 Td
+/F122_0 20.6585 Tf
+(compatibility) 127.422 Tj
+-278 TJm
+(functions) 92.9633 Tj
+[1 0 0 1 72 453.823] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -443.86] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 436.181 Td
+/F130_0 9.9626 Tf
+(Y) 7.193 Tj
+110 TJm
+(oshioka) 30.9936 Tj
+-604 TJm
+(Tsuneo) 29.3299 Tj
+-604 TJm
+(has) 13.2801 Tj
+-604 TJm
+(contrib) 28.224 Tj
+20 TJm
+(uted) 17.1556 Tj
+-604 TJm
+(some) 21.031 Tj
+-604 TJm
+(functions) 37.0808 Tj
+-604 TJm
+(to) 7.7509 Tj
+-604 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-604 TJm
+(better) 22.6848 Tj
+[1 0 0 1 356.347 436.181] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -356.347 -436.181] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+356.347 436.181 Td
+/F134_0 9.9626 Tf
+(zlib) 23.9102 Tj
+[1 0 0 1 380.257 436.181] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -380.257 -436.181] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+386.275 436.181 Td
+/F130_0 9.9626 Tf
+(compatibility) 53.1405 Tj
+65 TJm
+(.) 2.49065 Tj
+-1372 TJm
+(These) 23.7907 Tj
+-604 TJm
+(functions) 37.0808 Tj
+-604 TJm
+(are) 12.1643 Tj
+[1 0 0 1 72 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 424.226 Td
+/F134_0 9.9626 Tf
+(BZ2_bzopen) 59.7756 Tj
+[1 0 0 1 131.776 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -131.776 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+131.776 424.226 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 144.283 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -144.283 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+144.283 424.226 Td
+/F134_0 9.9626 Tf
+(BZ2_bzread) 59.7756 Tj
+[1 0 0 1 204.059 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.059 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+204.059 424.226 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 216.566 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -216.566 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+216.566 424.226 Td
+/F134_0 9.9626 Tf
+(BZ2_bzwrite) 65.7532 Tj
+[1 0 0 1 282.32 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -282.32 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+282.32 424.226 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 294.827 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -294.827 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+294.827 424.226 Td
+/F134_0 9.9626 Tf
+(BZ2_bzflush) 65.7532 Tj
+[1 0 0 1 360.581 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -360.581 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+360.581 424.226 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 373.088 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -373.088 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+373.088 424.226 Td
+/F134_0 9.9626 Tf
+(BZ2_bzclose) 65.7532 Tj
+[1 0 0 1 438.842 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -438.842 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+438.842 424.226 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 451.349 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -451.349 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+451.349 424.226 Td
+/F134_0 9.9626 Tf
+(BZ2_bzerror) 65.7532 Tj
+[1 0 0 1 517.102 424.226] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -517.102 -424.226] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+525.614 424.226 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 72 412.271] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -412.271] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 412.271 Td
+/F134_0 9.9626 Tf
+(BZ2_bzlibVersion) 95.641 Tj
+[1 0 0 1 167.641 412.271] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -167.641 -412.271] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+167.641 412.271 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1420 TJm
+(Thes) 19.3673 Tj
+1 TJm
+(e) 4.42339 Tj
+-384 TJm
+(functions) 37.0808 Tj
+-383 TJm
+(are) 12.1643 Tj
+-383 TJm
+(not) 12.7322 Tj
+-383 TJm
+(\(yet\)) 18.8094 Tj
+-384 TJm
+(of) 8.29885 Tj
+25 TJm
+(\002cially) 27.6761 Tj
+-383 TJm
+(part) 15.4918 Tj
+-383 TJm
+(of) 8.29885 Tj
+-383 TJm
+(the) 12.1743 Tj
+-384 TJm
+(library) 26.5603 Tj
+65 TJm
+(.) 2.49065 Tj
+-1419 TJm
+(If) 6.63509 Tj
+-383 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-384 TJm
+(break,) 24.6176 Tj
+-416 TJm
+(you) 14.9439 Tj
+-383 TJm
+(get) 12.1743 Tj
+-384 TJm
+(to) 7.7509 Tj
+72 400.316 Td
+(k) 4.9813 Tj
+10 TJm
+(eep) 13.8281 Tj
+-250 TJm
+(all) 9.9626 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(pieces.) 27.3872 Tj
+-620 TJm
+(Ne) 11.6164 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ertheless,) 37.3498 Tj
+-250 TJm
+(I) 3.31755 Tj
+-250 TJm
+(think) 20.4831 Tj
+-250 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ork) 13.2801 Tj
+-250 TJm
+(ok.) 12.4533 Tj
+[1 0 0 1 72 398.159] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -48.8169] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 47.8207 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 44.2341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -388.794] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 388.794 Td
+/F134_0 9.9626 Tf
+(typedef) 41.8429 Tj
+-426 TJm
+(void) 23.9102 Tj
+-426 TJm
+(BZFILE;) 41.8429 Tj
+90 364.884 Td
+(const) 29.8878 Tj
+-426 TJm
+(char) 23.9102 Tj
+152.286 363.14 Td
+(*) 5.97756 Tj
+162.508 364.884 Td
+(BZ2_bzlibVersion) 95.641 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(void) 23.9102 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 349.342] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -339.379] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 327.424 Td
+/F130_0 9.9626 Tf
+(Returns) 30.9936 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(string) 22.6948 Tj
+-250 TJm
+(indicating) 39.8504 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(library) 26.5603 Tj
+-250 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion.) 26.8392 Tj
+[1 0 0 1 72 325.267] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -36.8618] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 35.8655 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 32.2789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -315.902] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 315.902 Td
+/F134_0 9.9626 Tf
+(BZFILE) 35.8654 Tj
+130.109 314.159 Td
+(*) 5.97756 Tj
+140.331 315.902 Td
+(BZ2_bzopen) 59.7756 Tj
+-852 TJm
+(\() 5.97756 Tj
+-426 TJm
+(const) 29.8878 Tj
+-426 TJm
+(char) 23.9102 Tj
+281.103 314.159 Td
+(*) 5.97756 Tj
+287.08 315.902 Td
+(path,) 29.8878 Tj
+-426 TJm
+(const) 29.8878 Tj
+-426 TJm
+(char) 23.9102 Tj
+383.498 314.159 Td
+(*) 5.97756 Tj
+389.476 315.902 Td
+(mode) 23.9102 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 303.947 Td
+(BZFILE) 35.8654 Tj
+130.109 302.204 Td
+(*) 5.97756 Tj
+140.331 303.947 Td
+(BZ2_bzdopen) 65.7532 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(int) 17.9327 Tj
+-3408 TJm
+(fd,) 17.9327 Tj
+-1704 TJm
+(const) 29.8878 Tj
+-426 TJm
+(char) 23.9102 Tj
+369.629 302.204 Td
+(*) 5.97756 Tj
+375.607 303.947 Td
+(mode) 23.9102 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 288.405] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -278.443] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 266.488 Td
+/F130_0 9.9626 Tf
+(Opens) 25.4544 Tj
+-243 TJm
+(a) 4.42339 Tj
+[1 0 0 1 106.713 266.488] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -106.713 -266.488] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+106.713 266.488 Td
+/F134_0 9.9626 Tf
+(.bz2) 23.9102 Tj
+[1 0 0 1 130.624 266.488] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -130.624 -266.488] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+133.041 266.488 Td
+/F130_0 9.9626 Tf
+(\002le) 12.7322 Tj
+-243 TJm
+(for) 11.6164 Tj
+-242 TJm
+(reading) 29.8778 Tj
+-243 TJm
+(or) 8.29885 Tj
+-243 TJm
+(writing,) 31.2726 Tj
+-244 TJm
+(using) 21.589 Tj
+-243 TJm
+(ei) 7.193 Tj
+1 TJm
+(ther) 15.4918 Tj
+-243 TJm
+(its) 9.41466 Tj
+-243 TJm
+(name) 21.579 Tj
+-242 TJm
+(o) 4.9813 Tj
+-1 TJm
+(r) 3.31755 Tj
+-242 TJm
+(a) 4.42339 Tj
+-243 TJm
+(pre-e) 20.4632 Tj
+15 TJm
+(xisting) 27.1282 Tj
+-243 TJm
+(\002le) 12.7322 Tj
+-242 TJm
+(descriptor) 39.8404 Tj
+55 TJm
+(.) 2.49065 Tj
+-615 TJm
+(Analogous) 43.1679 Tj
+-243 TJm
+(to) 7.7509 Tj
+[1 0 0 1 510.112 266.488] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -510.112 -266.488] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+510.112 266.488 Td
+/F134_0 9.9626 Tf
+(fopen) 29.8878 Tj
+[1 0 0 1 540 266.488] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -266.488] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 254.532 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 88.8767 254.532] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -88.8767 -254.532] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+88.8767 254.532 Td
+/F134_0 9.9626 Tf
+(fdopen) 35.8654 Tj
+[1 0 0 1 124.742 254.532] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -124.742 -254.532] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+124.742 254.532 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 252.998] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -36.8618] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 35.8655 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 32.2789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -243.633] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 243.633 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzread) 59.7756 Tj
+-852 TJm
+(\() 5.97756 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+226.528 241.89 Td
+(*) 5.97756 Tj
+236.749 243.633 Td
+(b,) 11.9551 Tj
+-426 TJm
+(void) 23.9102 Tj
+276.859 241.89 Td
+(*) 5.97756 Tj
+287.08 243.633 Td
+(buf,) 23.9102 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(len) 17.9327 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 231.678 Td
+(int) 17.9327 Tj
+-426 TJm
+(BZ2_bzwrite) 65.7532 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+228.261 229.935 Td
+(*) 5.97756 Tj
+238.483 231.678 Td
+(b,) 11.9551 Tj
+-426 TJm
+(void) 23.9102 Tj
+278.592 229.935 Td
+(*) 5.97756 Tj
+288.814 231.678 Td
+(buf,) 23.9102 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(len) 17.9327 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 216.136] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -206.174] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 194.219 Td
+/F130_0 9.9626 Tf
+(Reads/writes) 51.4668 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(from/to) 29.8878 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(pre) 12.7222 Tj
+25 TJm
+(viously) 29.3399 Tj
+-250 TJm
+(opened) 28.772 Tj
+[1 0 0 1 259.903 194.219] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -259.903 -194.219] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+259.903 194.219 Td
+/F134_0 9.9626 Tf
+(BZFILE) 35.8654 Tj
+[1 0 0 1 295.769 194.219] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -295.769 -194.219] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+295.769 194.219 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-500 TJm
+(Analogous) 43.1679 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 359.141 194.219] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -359.141 -194.219] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+359.141 194.219 Td
+/F134_0 9.9626 Tf
+(fread) 29.8878 Tj
+[1 0 0 1 389.029 194.219] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -389.029 -194.219] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+391.519 194.219 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 408.396 194.219] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -408.396 -194.219] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+408.396 194.219 Td
+/F134_0 9.9626 Tf
+(fwrite) 35.8654 Tj
+[1 0 0 1 444.261 194.219] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.261 -194.219] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+444.261 194.219 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 192.062] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -36.8618] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 35.8655 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 32.2789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -182.697] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 182.697 Td
+/F134_0 9.9626 Tf
+(int) 17.9327 Tj
+-852 TJm
+(BZ2_bzflush) 65.7532 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+232.505 180.954 Td
+(*) 5.97756 Tj
+242.727 182.697 Td
+(b) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+90 170.742 Td
+(void) 23.9102 Tj
+-426 TJm
+(BZ2_bzclose) 65.7532 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+234.239 168.998 Td
+(*) 5.97756 Tj
+244.46 170.742 Td
+(b) 5.97756 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 155.2] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -145.237] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 133.282 Td
+/F130_0 9.9626 Tf
+(Flushes/closes) 57.5639 Tj
+-250 TJm
+(a) 4.42339 Tj
+[1 0 0 1 138.968 133.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -138.968 -133.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+138.968 133.282 Td
+/F134_0 9.9626 Tf
+(BZFILE) 35.8654 Tj
+[1 0 0 1 174.833 133.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -174.833 -133.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+174.833 133.282 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 179.815 133.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -179.815 -133.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+179.815 133.282 Td
+/F134_0 9.9626 Tf
+(BZ2_bzflush) 65.7532 Tj
+[1 0 0 1 245.568 133.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -245.568 -133.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+248.059 133.282 Td
+/F130_0 9.9626 Tf
+(doesn') 26.5603 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(actually) 31.5416 Tj
+-250 TJm
+(do) 9.9626 Tj
+-250 TJm
+(an) 9.40469 Tj
+15 TJm
+(ything.) 27.9551 Tj
+-620 TJm
+(Analogous) 43.1679 Tj
+-250 TJm
+(to) 7.7509 Tj
+[1 0 0 1 425.472 133.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -425.472 -133.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+425.472 133.282 Td
+/F134_0 9.9626 Tf
+(fflush) 35.8654 Tj
+[1 0 0 1 461.338 133.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -461.338 -133.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+463.828 133.282 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 480.705 133.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -480.705 -133.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+480.705 133.282 Td
+/F134_0 9.9626 Tf
+(fclose) 35.8654 Tj
+[1 0 0 1 516.57 133.282] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -516.57 -133.282] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+516.57 133.282 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 131.125] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -121.761] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 121.761 Td
+/F134_0 9.9626 Tf
+(const) 29.8878 Tj
+-426 TJm
+(char) 23.9102 Tj
+152.286 120.017 Td
+(*) 5.97756 Tj
+162.508 121.761 Td
+(BZ2_bzerror) 65.7532 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(BZFILE) 35.8654 Tj
+282.836 120.017 Td
+(*) 5.97756 Tj
+288.814 121.761 Td
+(b,) 11.9551 Tj
+-426 TJm
+(int) 17.9327 Tj
+327.19 120.017 Td
+(*) 5.97756 Tj
+333.167 121.761 Td
+(errnum) 35.8654 Tj
+-426 TJm
+(\)) 5.97756 Tj
+[1 0 0 1 72 106.219] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -96.2563] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 84.3011 Td
+/F130_0 9.9626 Tf
+(Returns) 30.9936 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(string) 22.6948 Tj
+-250 TJm
+(describing) 41.5042 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(more) 20.4731 Tj
+-250 TJm
+(recent) 24.3386 Tj
+-250 TJm
+(error) 19.3573 Tj
+-250 TJm
+(status) 22.6948 Tj
+-250 TJm
+(of) 8.29885 Tj
+[1 0 0 1 303.858 84.3011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -303.858 -84.3011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+303.858 84.3011 Td
+/F134_0 9.9626 Tf
+(b) 5.97756 Tj
+[1 0 0 1 309.835 84.3011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -309.835 -84.3011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+309.835 84.3011 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(also) 16.0497 Tj
+-250 TJm
+(sets) 14.9439 Tj
+[1 0 0 1 367.668 84.3011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -367.668 -84.3011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+367.668 82.5576 Td
+/F134_0 9.9626 Tf
+(*) 5.97756 Tj
+373.645 84.3011 Td
+(errnum) 35.8654 Tj
+[1 0 0 1 409.511 84.3011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -409.511 -84.3011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+412.001 84.3011 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(its) 9.41466 Tj
+-250 TJm
+(numerical) 39.8404 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alue.) 19.0883 Tj
+[1 0 0 1 72 82.1443] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -21.3298] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 4.3836 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -495.734 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+536.307 50.9514 Td
+/F130_0 9.9626 Tf
+(28) 9.9626 Tj
+[1 0 0 1 455.161 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -15.0365 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 32 32
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -741.554] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 704.93 Td
+/F122_0 20.6585 Tf
+(3.7.) 34.4584 Tj
+-278 TJm
+(Using) 57.3893 Tj
+-278 TJm
+(the) 30.9877 Tj
+-278 TJm
+(librar) 51.6669 Tj
+-10 TJm
+(y) 11.4861 Tj
+-278 TJm
+(in) 18.3654 Tj
+-278 TJm
+(a) 11.4861 Tj
+[1 0 0 1 322.501 704.93] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -322.501 -704.93] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+322.501 704.93 Td
+/F392_0 20.6585 Tf
+(stdio) 61.9755 Tj
+[1 0 0 1 384.477 704.93] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -384.477 -704.93] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+384.477 704.93 Td
+/F122_0 20.6585 Tf
+(-free) 44.767 Tj
+72 680.139 Td
+(en) 24.1085 Tj
+40 TJm
+(vir) 25.2653 Tj
+20 TJm
+(onment) 74.5978 Tj
+[1 0 0 1 72 679.881] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -669.983] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 649.583 Td
+/F122_0 17.2154 Tf
+(3.7.1.) 43.0729 Tj
+-278 TJm
+(Getting) 60.2539 Tj
+-278 TJm
+(rid) 22.0013 Tj
+-278 TJm
+(of) 16.2513 Tj
+[1 0 0 1 232.721 649.583] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -232.721 -649.583] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+232.721 649.583 Td
+/F392_0 17.2154 Tf
+(stdio) 51.6462 Tj
+[1 0 0 1 284.367 649.583] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -212.367 -3.8303] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -635.855] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 627.73 Td
+/F130_0 9.9626 Tf
+(In) 8.29885 Tj
+-319 TJm
+(a) 4.42339 Tj
+-319 TJm
+(deeply) 26.5603 Tj
+-319 TJm
+(embedded) 40.9463 Tj
+-319 TJm
+(application,) 46.7644 Tj
+-336 TJm
+(you) 14.9439 Tj
+-319 TJm
+(might) 23.2527 Tj
+-319 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-319 TJm
+(to) 7.7509 Tj
+-319 TJm
+(use) 13.2801 Tj
+-319 TJm
+(just) 14.396 Tj
+-319 TJm
+(the) 12.1743 Tj
+-319 TJm
+(memory-to-memory) 80.7967 Tj
+-319 TJm
+(functions.) 39.5714 Tj
+-1035 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-319 TJm
+(can) 13.8281 Tj
+-319 TJm
+(do) 9.9626 Tj
+-319 TJm
+(this) 14.396 Tj
+72 615.775 Td
+(con) 14.386 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(eniently) 32.0995 Tj
+-327 TJm
+(by) 9.9626 Tj
+-327 TJm
+(compiling) 40.4083 Tj
+-327 TJm
+(the) 12.1743 Tj
+-327 TJm
+(library) 26.5603 Tj
+-327 TJm
+(with) 17.7135 Tj
+-328 TJm
+(preproces) 38.7246 Tj
+1 TJm
+(sor) 12.1743 Tj
+-328 TJm
+(symbol) 29.3399 Tj
+[1 0 0 1 336.046 615.775] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -336.046 -615.775] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+336.046 615.775 Td
+/F134_0 9.9626 Tf
+(BZ_NO_STDIO) 65.7532 Tj
+[1 0 0 1 401.799 615.775] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -401.799 -615.775] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+405.057 615.775 Td
+/F130_0 9.9626 Tf
+(de\002ned.) 31.8205 Tj
+-1083 TJm
+(Doing) 24.9065 Tj
+-327 TJm
+(this) 14.396 Tj
+-327 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+-327 TJm
+(you) 14.9439 Tj
+-327 TJm
+(a) 4.42339 Tj
+72 603.819 Td
+(library) 26.5603 Tj
+-250 TJm
+(containing) 42.0621 Tj
+-250 TJm
+(only) 17.7135 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(follo) 18.8194 Tj
+25 TJm
+(wing) 19.9252 Tj
+-250 TJm
+(eight) 19.9252 Tj
+-250 TJm
+(functions:) 39.8504 Tj
+[1 0 0 1 72 601.662] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -591.764] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 581.966 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressInit) 107.596 Tj
+[1 0 0 1 179.596 581.966] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -179.596 -581.966] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+179.596 581.966 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 199.079 581.966] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -199.079 -581.966] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+199.079 581.966 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompress) 83.6858 Tj
+[1 0 0 1 282.765 581.966] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -282.765 -581.966] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+282.765 581.966 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 302.247 581.966] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -302.247 -581.966] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+302.247 581.966 Td
+/F134_0 9.9626 Tf
+(BZ2_bzCompressEnd) 101.619 Tj
+[1 0 0 1 403.866 581.966] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 14.0915 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -417.958 -581.966] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+417.958 581.966 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressInit) 119.551 Tj
+[1 0 0 1 537.509 581.966] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -537.509 -581.966] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+537.509 581.966 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 72 570.011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -570.011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 570.011 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompress) 95.641 Tj
+[1 0 0 1 167.641 570.011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -167.641 -570.011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+167.641 570.011 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 172.144 570.011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -172.144 -570.011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+172.144 570.011 Td
+/F134_0 9.9626 Tf
+(BZ2_bzDecompressEnd) 113.574 Tj
+[1 0 0 1 285.719 570.011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -287.611 -570.011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+287.611 570.011 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffCompress) 143.461 Tj
+[1 0 0 1 431.073 570.011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -431.073 -570.011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+431.073 570.011 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 435.577 570.011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -435.577 -570.011] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+435.577 570.011 Td
+/F134_0 9.9626 Tf
+(BZ2_bzBuffToBuffDecompress) 155.417 Tj
+[1 0 0 1 590.994 570.011] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -518.994 -1.5341] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8981] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -558.579] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 548.158 Td
+/F130_0 9.9626 Tf
+(When) 23.7907 Tj
+-250 TJm
+(compiled) 37.0808 Tj
+-250 TJm
+(lik) 10.5205 Tj
+10 TJm
+(e) 4.42339 Tj
+-250 TJm
+(this,) 16.8866 Tj
+-250 TJm
+(all) 9.9626 Tj
+-250 TJm
+(functions) 37.0808 Tj
+-250 TJm
+(will) 15.5018 Tj
+-250 TJm
+(ignore) 25.4544 Tj
+[1 0 0 1 272.526 548.158] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -272.526 -548.158] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+272.526 548.158 Td
+/F134_0 9.9626 Tf
+(verbosity) 53.798 Tj
+[1 0 0 1 326.324 548.158] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -326.324 -548.158] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+328.815 548.158 Td
+/F130_0 9.9626 Tf
+(settings.) 32.9364 Tj
+[1 0 0 1 72 546.001] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -536.103] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 517.601 Td
+/F122_0 17.2154 Tf
+(3.7.2.) 43.0729 Tj
+-278 TJm
+(Critical) 58.3602 Tj
+-278 TJm
+(err) 22.9653 Tj
+20 TJm
+(or) 17.2154 Tj
+-278 TJm
+(handling) 71.7366 Tj
+[1 0 0 1 72 513.771] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -503.873] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 495.748 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 119.821 495.748] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.821 -495.748] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+124.529 495.748 Td
+/F130_0 9.9626 Tf
+(contains) 33.2053 Tj
+-473 TJm
+(a) 4.42339 Tj
+-472 TJm
+(number) 30.4357 Tj
+-473 TJm
+(of) 8.29885 Tj
+-472 TJm
+(internal) 30.4357 Tj
+-473 TJm
+(assertion) 35.417 Tj
+-472 TJm
+(checks) 27.1082 Tj
+-473 TJm
+(which) 24.3486 Tj
+-472 TJm
+(should,) 29.0609 Tj
+-529 TJm
+(needless) 33.7533 Tj
+-472 TJm
+(to) 7.7509 Tj
+-473 TJm
+(say) 13.2801 Tj
+65 TJm
+(,) 2.49065 Tj
+-528 TJm
+(ne) 9.40469 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-473 TJm
+(be) 9.40469 Tj
+-472 TJm
+(acti) 14.386 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(ated.) 19.0883 Tj
+72 483.793 Td
+(Ne) 11.6164 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ertheless,) 37.3498 Tj
+-533 TJm
+(if) 6.08715 Tj
+-476 TJm
+(an) 9.40469 Tj
+-476 TJm
+(assertion) 35.417 Tj
+-476 TJm
+(should) 26.5703 Tj
+-476 TJm
+(f) 3.31755 Tj
+10 TJm
+(ail,) 12.4533 Tj
+-532 TJm
+(beha) 18.8094 Tj
+20 TJm
+(viour) 21.031 Tj
+-476 TJm
+(depends) 32.6474 Tj
+-476 TJm
+(on) 9.9626 Tj
+-476 TJm
+(whether) 32.0895 Tj
+-476 TJm
+(or) 8.29885 Tj
+-477 TJm
+(not) 12.7322 Tj
+-476 TJm
+(the) 12.1743 Tj
+-476 TJm
+(library) 26.5603 Tj
+-476 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-476 TJm
+(compiled) 37.0808 Tj
+-476 TJm
+(with) 17.7135 Tj
+[1 0 0 1 72 471.838] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -471.838] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 471.838 Td
+/F134_0 9.9626 Tf
+(BZ_NO_STDIO) 65.7532 Tj
+[1 0 0 1 137.753 471.838] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.753 -471.838] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+140.244 471.838 Td
+/F130_0 9.9626 Tf
+(set.) 13.5591 Tj
+[1 0 0 1 72 470.528] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -460.63] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 449.985 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(normal) 28.224 Tj
+-250 TJm
+(compile,) 34.5901 Tj
+-250 TJm
+(an) 9.40469 Tj
+-250 TJm
+(assertion) 35.417 Tj
+-250 TJm
+(f) 3.31755 Tj
+10 TJm
+(ailure) 22.6848 Tj
+-250 TJm
+(yields) 23.8007 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(message:) 36.5229 Tj
+[1 0 0 1 72 447.828] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -437.93] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 428.131 Td
+/F130_0 9.9626 Tf
+(bzip2/libbzip2:) 60.3335 Tj
+-310 TJm
+(internal) 30.4357 Tj
+-250 TJm
+(error) 19.3573 Tj
+-250 TJm
+(number) 30.4357 Tj
+-250 TJm
+(N.) 9.68365 Tj
+[1 0 0 1 72 425.975] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -416.077] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 406.278 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-332 TJm
+(is) 6.64505 Tj
+-331 TJm
+(a) 4.42339 Tj
+-332 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug) 9.9626 Tj
+-332 TJm
+(in) 7.7509 Tj
+-331 TJm
+(bzip2/libbzip2,) 60.0546 Tj
+-352 TJm
+(1.0.5) 19.9252 Tj
+-332 TJm
+(of) 8.29885 Tj
+-332 TJm
+(10) 9.9626 Tj
+-332 TJm
+(December) 40.9363 Tj
+-331 TJm
+(2007.) 22.4159 Tj
+-555 TJm
+(Please) 25.4544 Tj
+-332 TJm
+(report) 23.7907 Tj
+-332 TJm
+(it) 5.53921 Tj
+-331 TJm
+(to) 7.7509 Tj
+-332 TJm
+(me) 12.1743 Tj
+-332 TJm
+(at:) 9.9626 Tj
+-473 TJm
+(jse) 11.0684 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(ard@bzip.or) 49.8429 Tj
+18 TJm
+(g.) 7.47195 Tj
+-1110 TJm
+(If) 6.63509 Tj
+-332 TJm
+(this) 14.396 Tj
+72 394.323 Td
+(happened) 38.1767 Tj
+-297 TJm
+(when) 21.579 Tj
+-298 TJm
+(you) 14.9439 Tj
+-297 TJm
+(were) 19.3573 Tj
+-297 TJm
+(using) 21.589 Tj
+-297 TJm
+(some) 21.031 Tj
+-298 TJm
+(program) 33.7533 Tj
+-297 TJm
+(which) 24.3486 Tj
+-297 TJm
+(uses) 17.1556 Tj
+-297 TJm
+(libbzip2) 32.6574 Tj
+-298 TJm
+(as) 8.29885 Tj
+-297 TJm
+(a) 4.42339 Tj
+-297 TJm
+(component,) 46.7644 Tj
+-309 TJm
+(you) 14.9439 Tj
+-298 TJm
+(should) 26.5703 Tj
+-297 TJm
+(also) 16.0497 Tj
+-297 TJm
+(report) 23.7907 Tj
+-297 TJm
+(this) 14.396 Tj
+-298 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug) 9.9626 Tj
+72 382.368 Td
+(to) 7.7509 Tj
+-264 TJm
+(the) 12.1743 Tj
+-264 TJm
+(author\(s\)) 35.965 Tj
+-264 TJm
+(of) 8.29885 Tj
+-264 TJm
+(that) 14.9439 Tj
+-264 TJm
+(program.) 36.2439 Tj
+-703 TJm
+(Please) 25.4544 Tj
+-264 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-264 TJm
+(an) 9.40469 Tj
+-264 TJm
+(ef) 7.74094 Tj
+25 TJm
+(fort) 14.386 Tj
+-264 TJm
+(to) 7.7509 Tj
+-264 TJm
+(report) 23.7907 Tj
+-263 TJm
+(this) 14.396 Tj
+-264 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug;) 12.7322 Tj
+-271 TJm
+(timely) 25.4644 Tj
+-264 TJm
+(and) 14.386 Tj
+-264 TJm
+(accurate) 33.1854 Tj
+-264 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug) 9.9626 Tj
+-264 TJm
+(reports) 27.6661 Tj
+-264 TJm
+(e) 4.42339 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(entually) 32.0995 Tj
+72 370.413 Td
+(lead) 16.5977 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(higher) 25.4544 Tj
+-250 TJm
+(quality) 27.6761 Tj
+-250 TJm
+(softw) 22.1369 Tj
+10 TJm
+(are.) 14.655 Tj
+-620 TJm
+(Thanks.) 31.8205 Tj
+-620 TJm
+(Julian) 23.8007 Tj
+-250 TJm
+(Se) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(ard,) 15.2129 Tj
+-250 TJm
+(10) 9.9626 Tj
+-250 TJm
+(December) 40.9363 Tj
+-250 TJm
+(2007.) 22.4159 Tj
+[1 0 0 1 72 368.256] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.801] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -348.557] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 338.758 Td
+/F130_0 9.9626 Tf
+(where) 24.3386 Tj
+[1 0 0 1 98.8312 338.758] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -98.8312 -338.758] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+98.8312 338.758 Td
+/F134_0 9.9626 Tf
+(N) 5.97756 Tj
+[1 0 0 1 104.809 338.758] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -104.809 -338.758] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+107.302 338.758 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(some) 21.031 Tj
+-250 TJm
+(error) 19.3573 Tj
+-251 TJm
+(code) 18.8094 Tj
+-250 TJm
+(number) 30.4357 Tj
+55 TJm
+(.) 2.49065 Tj
+-621 TJm
+(If) 6.63509 Tj
+[1 0 0 1 230.81 338.758] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -230.81 -338.758] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+230.81 338.758 Td
+/F134_0 9.9626 Tf
+(N) 5.97756 Tj
+-600 TJm
+(==) 11.9551 Tj
+-600 TJm
+(1007) 23.9102 Tj
+[1 0 0 1 284.608 338.758] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -284.608 -338.758] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+284.608 338.758 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(also) 16.0497 Tj
+-251 TJm
+(prints) 22.6948 Tj
+-250 TJm
+(some) 21.031 Tj
+-250 TJm
+(e) 4.42339 Tj
+15 TJm
+(xtra) 15.4918 Tj
+-250 TJm
+(te) 7.193 Tj
+15 TJm
+(xt) 7.7509 Tj
+-250 TJm
+(advising) 33.7633 Tj
+-251 TJm
+(the) 12.1743 Tj
+-250 TJm
+(reader) 24.8866 Tj
+-250 TJm
+(that) 14.9439 Tj
+-250 TJm
+(unreliable) 39.8404 Tj
+72 326.803 Td
+(memory) 33.2053 Tj
+-425 TJm
+(is) 6.64505 Tj
+-424 TJm
+(often) 20.4731 Tj
+-425 TJm
+(associated) 40.9463 Tj
+-425 TJm
+(with) 17.7135 Tj
+-424 TJm
+(internal) 30.4357 Tj
+-425 TJm
+(error) 19.3573 Tj
+-424 TJm
+(1007.) 22.4159 Tj
+-834 TJm
+(\(This) 21.031 Tj
+-425 TJm
+(is) 6.64505 Tj
+-425 TJm
+(a) 4.42339 Tj
+-424 TJm
+(frequently-observ) 70.8241 Tj
+15 TJm
+(ed-phenomenon) 64.189 Tj
+-425 TJm
+(with) 17.7135 Tj
+-425 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions) 28.224 Tj
+72 314.848 Td
+(1.0.0/1.0.1\).) 48.4282 Tj
+[1 0 0 1 72 313.065] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -303.167] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 292.995 Td
+/F134_0 9.9626 Tf
+(exit\(3\)) 41.8429 Tj
+[1 0 0 1 113.843 292.995] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.843 -292.995] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+116.334 292.995 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(then) 17.1556 Tj
+-250 TJm
+(called.) 26.2813 Tj
+[1 0 0 1 72 291.899] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.8981] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -282.001] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 271.142 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-250 TJm
+(a) 4.42339 Tj
+[1 0 0 1 95.0933 271.142] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -95.0933 -271.142] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+95.0933 271.142 Td
+/F134_0 9.9626 Tf
+(stdio) 29.8878 Tj
+[1 0 0 1 124.981 271.142] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -124.981 -271.142] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+124.981 271.142 Td
+/F130_0 9.9626 Tf
+(-free) 18.7994 Tj
+-250 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(assertion) 35.417 Tj
+-250 TJm
+(f) 3.31755 Tj
+10 TJm
+(ailures) 26.5603 Tj
+-250 TJm
+(result) 22.1369 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(call) 14.386 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(function) 33.2053 Tj
+-250 TJm
+(declared) 33.7433 Tj
+-250 TJm
+(as:) 11.0684 Tj
+[1 0 0 1 72 268.985] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -259.62] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 259.62 Td
+/F134_0 9.9626 Tf
+(extern) 35.8654 Tj
+-426 TJm
+(void) 23.9102 Tj
+-426 TJm
+(bz_internal_error) 101.619 Tj
+-426 TJm
+(\() 5.97756 Tj
+-426 TJm
+(int) 17.9327 Tj
+-426 TJm
+(errcode) 41.8429 Tj
+-426 TJm
+(\);) 11.9551 Tj
+[1 0 0 1 72 244.078] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.4846] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -234.18] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 222.225 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-250 TJm
+(rele) 14.9339 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(ant) 12.1743 Tj
+-250 TJm
+(code) 18.8094 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(passed) 26.5603 Tj
+-250 TJm
+(as) 8.29885 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(parameter) 39.8305 Tj
+55 TJm
+(.) 2.49065 Tj
+-620 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-250 TJm
+(should) 26.5703 Tj
+-250 TJm
+(supply) 26.5703 Tj
+-250 TJm
+(such) 18.2614 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(function.) 35.696 Tj
+[1 0 0 1 72 220.068] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -210.17] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 200.372 Td
+/F130_0 9.9626 Tf
+(In) 8.29885 Tj
+-294 TJm
+(either) 22.6848 Tj
+-294 TJm
+(case,) 19.6363 Tj
+-306 TJm
+(once) 18.8094 Tj
+-294 TJm
+(an) 9.40469 Tj
+-294 TJm
+(assertion) 35.417 Tj
+-294 TJm
+(f) 3.31755 Tj
+10 TJm
+(ailure) 22.6848 Tj
+-294 TJm
+(has) 13.2801 Tj
+-295 TJm
+(occurred,) 37.3398 Tj
+-305 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+[1 0 0 1 306.541 200.372] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -306.541 -200.372] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+306.541 200.372 Td
+/F134_0 9.9626 Tf
+(bz_stream) 53.798 Tj
+[1 0 0 1 360.339 200.372] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -360.339 -200.372] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+363.271 200.372 Td
+/F130_0 9.9626 Tf
+(records) 29.3199 Tj
+-294 TJm
+(in) 7.7509 Tj
+40 TJm
+(v) 4.9813 Tj
+20 TJm
+(olv) 12.7322 Tj
+15 TJm
+(ed) 9.40469 Tj
+-294 TJm
+(can) 13.8281 Tj
+-295 TJm
+(be) 9.40469 Tj
+-294 TJm
+(re) 7.74094 Tj
+15 TJm
+(g) 4.9813 Tj
+5 TJm
+(arded) 22.1269 Tj
+-294 TJm
+(as) 8.29885 Tj
+-294 TJm
+(in) 7.7509 Tj
+40 TJm
+(v) 4.9813 Tj
+25 TJm
+(alid.) 17.4346 Tj
+72 188.417 Td
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-250 TJm
+(should) 26.5703 Tj
+-250 TJm
+(not) 12.7322 Tj
+-250 TJm
+(attempt) 29.8878 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(resume) 28.772 Tj
+-250 TJm
+(normal) 28.224 Tj
+-250 TJm
+(operation) 37.6287 Tj
+-250 TJm
+(with) 17.7135 Tj
+-250 TJm
+(them.) 22.4159 Tj
+[1 0 0 1 72 186.26] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -176.362] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 166.564 Td
+/F130_0 9.9626 Tf
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-299 TJm
+(may) 17.1556 Tj
+65 TJm
+(,) 2.49065 Tj
+-310 TJm
+(of) 8.29885 Tj
+-299 TJm
+(course,) 28.493 Tj
+-311 TJm
+(change) 28.2141 Tj
+-298 TJm
+(critical) 27.6661 Tj
+-299 TJm
+(error) 19.3573 Tj
+-298 TJm
+(handling) 34.8691 Tj
+-299 TJm
+(to) 7.7509 Tj
+-298 TJm
+(suit) 14.396 Tj
+-299 TJm
+(your) 18.2614 Tj
+-298 TJm
+(needs.) 25.1755 Tj
+-912 TJm
+(As) 11.0684 Tj
+-298 TJm
+(I) 3.31755 Tj
+-299 TJm
+(said) 16.0497 Tj
+-298 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e,) 6.91404 Tj
+-311 TJm
+(critical) 27.6661 Tj
+-299 TJm
+(errors) 23.2328 Tj
+-298 TJm
+(indicate) 31.5416 Tj
+-299 TJm
+(b) 4.9813 Tj
+20 TJm
+(ugs) 13.8381 Tj
+72 154.608 Td
+(in) 7.7509 Tj
+-263 TJm
+(the) 12.1743 Tj
+-263 TJm
+(library) 26.5603 Tj
+-263 TJm
+(and) 14.386 Tj
+-263 TJm
+(should) 26.5703 Tj
+-263 TJm
+(not) 12.7322 Tj
+-263 TJm
+(occur) 22.1269 Tj
+55 TJm
+(.) 2.49065 Tj
+-697 TJm
+(All) 12.7322 Tj
+-263 TJm
+("normal") 36.3535 Tj
+-263 TJm
+(error) 19.3573 Tj
+-263 TJm
+(situations) 38.1966 Tj
+-263 TJm
+(are) 12.1643 Tj
+-263 TJm
+(indicated) 36.5229 Tj
+-263 TJm
+(via) 12.1743 Tj
+-263 TJm
+(error) 19.3573 Tj
+-263 TJm
+(return) 23.7907 Tj
+-263 TJm
+(codes) 22.6848 Tj
+-263 TJm
+(from) 19.3673 Tj
+-263 TJm
+(functions,) 39.5714 Tj
+72 142.653 Td
+(and) 14.386 Tj
+-250 TJm
+(can) 13.8281 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(reco) 17.1456 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(ered) 17.1456 Tj
+-250 TJm
+(from.) 21.8579 Tj
+[1 0 0 1 72 142.554] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -132.656] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 107.965 Td
+/F122_0 20.6585 Tf
+(3.8.) 34.4584 Tj
+-278 TJm
+(Making) 71.1685 Tj
+-278 TJm
+(a) 11.4861 Tj
+-278 TJm
+(Windo) 63.1117 Tj
+15 TJm
+(ws) 27.5584 Tj
+-278 TJm
+(DLL) 40.1601 Tj
+[1 0 0 1 72 103.369] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.898] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -93.4708] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 86.112 Td
+/F130_0 9.9626 Tf
+(Ev) 11.0684 Tj
+15 TJm
+(erything) 33.2053 Tj
+-328 TJm
+(related) 27.1082 Tj
+-327 TJm
+(to) 7.7509 Tj
+-328 TJm
+(W) 9.40469 Tj
+40 TJm
+(indo) 17.7135 Tj
+25 TJm
+(ws) 11.0684 Tj
+-328 TJm
+(has) 13.2801 Tj
+-327 TJm
+(been) 18.8094 Tj
+-328 TJm
+(contrib) 28.224 Tj
+20 TJm
+(uted) 17.1556 Tj
+-328 TJm
+(by) 9.9626 Tj
+-327 TJm
+(Y) 7.193 Tj
+110 TJm
+(oshioka) 30.9936 Tj
+-328 TJm
+(Tsuneo) 29.3299 Tj
+-328 TJm
+(\() 3.31755 Tj
+[1 0 0 1 378.139 86.112] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -378.139 -86.112] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+378.139 86.112 Td
+/F134_0 9.9626 Tf
+(tsuneo@rr.iij4u.or.jp) 125.529 Tj
+[1 0 0 1 503.668 86.112] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -503.668 -86.112] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+503.668 86.112 Td
+/F130_0 9.9626 Tf
+(\),) 5.8082 Tj
+-347 TJm
+(so) 8.85675 Tj
+-328 TJm
+(you) 14.9439 Tj
+72 74.1568 Td
+(should) 26.5703 Tj
+-250 TJm
+(send) 18.2614 Tj
+-250 TJm
+(your) 18.2614 Tj
+-250 TJm
+(queries) 28.772 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(him) 15.5018 Tj
+-250 TJm
+(\(b) 8.29885 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(perhaps) 30.9837 Tj
+-250 TJm
+(Cc:) 13.8381 Tj
+-310 TJm
+(me,) 14.6649 Tj
+[1 0 0 1 287.958 74.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -287.958 -74.1568] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+287.958 74.1568 Td
+/F134_0 9.9626 Tf
+(jseward@bzip.org) 95.641 Tj
+[1 0 0 1 383.6 74.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -383.6 -74.1568] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+383.6 74.1568 Td
+/F130_0 9.9626 Tf
+(\).) 5.8082 Tj
+[1 0 0 1 72 72] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -21.1482] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.9738] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -51.071] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 51.071 Td
+/F130_0 9.9626 Tf
+(29) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 33 33
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 8.9114] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 76.4979 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -342.569 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+419.067 749.245 Td
+/F130_0 9.9626 Tf
+(Programming) 54.7943 Tj
+-250 TJm
+(with) 17.7135 Tj
+[1 0 0 1 496.556 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -496.556 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.556 749.245 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 544.376 749.245] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -278.305 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -5.0363] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(My) 13.8381 Tj
+-367 TJm
+(v) 4.9813 Tj
+25 TJm
+(ague) 18.8094 Tj
+-367 TJm
+(understanding) 56.4481 Tj
+-367 TJm
+(of) 8.29885 Tj
+-367 TJm
+(what) 19.3673 Tj
+-368 TJm
+(to) 7.7509 Tj
+-367 TJm
+(do) 9.9626 Tj
+-367 TJm
+(is:) 9.41466 Tj
+-544 TJm
+(using) 21.589 Tj
+-367 TJm
+(V) 7.193 Tj
+60 TJm
+(isual) 18.8194 Tj
+-367 TJm
+(C++) 17.8829 Tj
+-367 TJm
+(5.0,) 14.9439 Tj
+-397 TJm
+(open) 19.3673 Tj
+-367 TJm
+(the) 12.1743 Tj
+-367 TJm
+(project) 27.6661 Tj
+-367 TJm
+(\002le) 12.7322 Tj
+[1 0 0 1 432.966 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -432.966 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+432.966 710.037 Td
+/F134_0 9.9626 Tf
+(libbz2.dsp) 59.7756 Tj
+[1 0 0 1 492.742 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -492.742 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+492.742 710.037 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-396 TJm
+(and) 14.386 Tj
+-368 TJm
+(b) 4.9813 Tj
+20 TJm
+(uild.) 17.9925 Tj
+72 698.082 Td
+(That') 21.579 Tj
+55 TJm
+(s) 3.87545 Tj
+-250 TJm
+(all.) 12.4533 Tj
+[1 0 0 1 72 697.983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -688.02] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 676.164 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-284 TJm
+(you) 14.9439 Tj
+-284 TJm
+(can') 17.1456 Tj
+18 TJm
+(t) 2.7696 Tj
+-285 TJm
+(open) 19.3673 Tj
+-284 TJm
+(the) 12.1743 Tj
+-284 TJm
+(project) 27.6661 Tj
+-284 TJm
+(\002le) 12.7322 Tj
+-284 TJm
+(for) 11.6164 Tj
+-285 TJm
+(some) 21.031 Tj
+-284 TJm
+(reason,) 28.493 Tj
+-293 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-284 TJm
+(a) 4.42339 Tj
+-284 TJm
+(ne) 9.40469 Tj
+25 TJm
+(w) 7.193 Tj
+-284 TJm
+(one,) 16.8766 Tj
+-293 TJm
+(naming) 29.8878 Tj
+-284 TJm
+(these) 20.4731 Tj
+-284 TJm
+(\002les:) 19.3773 Tj
+[1 0 0 1 424.505 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -424.505 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+424.505 676.164 Td
+/F134_0 9.9626 Tf
+(blocksort.c) 65.7532 Tj
+[1 0 0 1 490.259 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -490.259 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+490.259 676.164 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 495.666 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -495.666 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+495.666 676.164 Td
+/F134_0 9.9626 Tf
+(bzlib.c) 41.8429 Tj
+[1 0 0 1 537.509 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -537.509 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+537.509 676.164 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 72 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 664.209 Td
+/F134_0 9.9626 Tf
+(compress.c) 59.7756 Tj
+[1 0 0 1 131.776 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -131.776 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+131.776 664.209 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 136.436 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -136.436 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+136.436 664.209 Td
+/F134_0 9.9626 Tf
+(crctable.c) 59.7756 Tj
+[1 0 0 1 196.211 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -196.211 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+196.211 664.209 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 200.871 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -200.871 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+200.871 664.209 Td
+/F134_0 9.9626 Tf
+(decompress.c) 71.7307 Tj
+[1 0 0 1 272.602 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -272.602 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+272.602 664.209 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 277.262 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -277.262 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+277.262 664.209 Td
+/F134_0 9.9626 Tf
+(huffman.c) 53.798 Tj
+[1 0 0 1 331.06 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -331.06 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+331.06 664.209 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 335.72 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -335.72 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+335.72 664.209 Td
+/F134_0 9.9626 Tf
+(randtable.c) 65.7532 Tj
+[1 0 0 1 401.473 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -401.473 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+403.562 664.209 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 420.037 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -420.037 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+420.037 664.209 Td
+/F134_0 9.9626 Tf
+(libbz2.def) 59.7756 Tj
+[1 0 0 1 479.812 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -479.812 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+479.812 664.209 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-593 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-210 TJm
+(will) 15.5018 Tj
+-209 TJm
+(also) 16.0497 Tj
+72 652.254 Td
+(need) 18.8094 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(name) 21.579 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(header) 26.5503 Tj
+-250 TJm
+(\002les) 16.6077 Tj
+[1 0 0 1 190.415 652.254] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -190.415 -652.254] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+190.415 652.254 Td
+/F134_0 9.9626 Tf
+(bzlib.h) 41.8429 Tj
+[1 0 0 1 232.258 652.254] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -232.258 -652.254] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+234.748 652.254 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 251.625 652.254] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -251.625 -652.254] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+251.625 652.254 Td
+/F134_0 9.9626 Tf
+(bzlib_private.h) 89.6634 Tj
+[1 0 0 1 341.289 652.254] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -341.289 -652.254] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+341.289 652.254 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 650.72] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -640.757] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 630.336 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(don') 18.2614 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(VC++,) 27.5665 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(may) 17.1556 Tj
+-250 TJm
+(need) 18.8094 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(de\002ne) 24.3486 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(proprocessor) 51.4568 Tj
+-250 TJm
+(symbol) 29.3399 Tj
+[1 0 0 1 363.634 630.336] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -363.634 -630.336] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+363.634 630.336 Td
+/F134_0 9.9626 Tf
+(_WIN32) 35.8654 Tj
+[1 0 0 1 399.5 630.336] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -399.5 -630.336] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+399.5 630.336 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 628.179] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -618.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 608.418 Td
+/F130_0 9.9626 Tf
+(Finally) 28.234 Tj
+65 TJm
+(,) 2.49065 Tj
+[1 0 0 1 104.568 608.418] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -104.568 -608.418] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.568 608.418 Td
+/F134_0 9.9626 Tf
+(dlltest.c) 53.798 Tj
+[1 0 0 1 158.366 608.418] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -158.366 -608.418] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+160.856 608.418 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(sample) 28.224 Tj
+-250 TJm
+(program) 33.7533 Tj
+-250 TJm
+(using) 21.589 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(DLL.) 21.8579 Tj
+-500 TJm
+(It) 6.08715 Tj
+-250 TJm
+(has) 13.2801 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(project) 27.6661 Tj
+-250 TJm
+(\002le,) 15.2229 Tj
+[1 0 0 1 388.58 608.418] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -388.58 -608.418] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+388.58 608.418 Td
+/F134_0 9.9626 Tf
+(dlltest.dsp) 65.7532 Tj
+[1 0 0 1 454.333 608.418] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -454.333 -608.418] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+454.333 608.418 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 606.262] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -596.299] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 586.501 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(just) 14.396 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e\002le) 17.1556 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(V) 7.193 Tj
+60 TJm
+(isual) 18.8194 Tj
+-250 TJm
+(C,) 9.1357 Tj
+-250 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(look) 17.7135 Tj
+-250 TJm
+(at) 7.193 Tj
+[1 0 0 1 292.212 586.501] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -292.212 -586.501] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+292.212 586.501 Td
+/F134_0 9.9626 Tf
+(makefile.msc) 71.7307 Tj
+[1 0 0 1 363.943 586.501] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -363.943 -586.501] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+363.943 586.501 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 584.344] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -574.381] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 564.583 Td
+/F130_0 9.9626 Tf
+(Be) 11.0684 Tj
+-291 TJm
+(a) 4.42339 Tj
+15 TJm
+(w) 7.193 Tj
+10 TJm
+(are) 12.1643 Tj
+-291 TJm
+(that) 14.9439 Tj
+-291 TJm
+(if) 6.08715 Tj
+-291 TJm
+(you) 14.9439 Tj
+-291 TJm
+(compile) 32.0995 Tj
+[1 0 0 1 192.069 564.583] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -192.069 -564.583] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+192.069 564.583 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 221.958 564.583] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -221.958 -564.583] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+224.857 564.583 Td
+/F130_0 9.9626 Tf
+(itself) 19.9252 Tj
+-291 TJm
+(on) 9.9626 Tj
+-291 TJm
+(W) 9.40469 Tj
+40 TJm
+(in32,) 20.2042 Tj
+-301 TJm
+(you) 14.9439 Tj
+-291 TJm
+(must) 19.3773 Tj
+-291 TJm
+(set) 11.0684 Tj
+[1 0 0 1 346.841 564.583] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -346.841 -564.583] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+346.841 564.583 Td
+/F134_0 9.9626 Tf
+(BZ_UNIX) 41.8429 Tj
+[1 0 0 1 388.685 564.583] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -388.685 -564.583] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+391.583 564.583 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-291 TJm
+(0) 4.9813 Tj
+-291 TJm
+(and) 14.386 Tj
+[1 0 0 1 427.399 564.583] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -427.399 -564.583] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+427.399 564.583 Td
+/F134_0 9.9626 Tf
+(BZ_LCCWIN32) 65.7532 Tj
+[1 0 0 1 493.153 564.583] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.153 -564.583] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+496.052 564.583 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-291 TJm
+(1,) 7.47195 Tj
+-301 TJm
+(in) 7.7509 Tj
+-291 TJm
+(the) 12.1743 Tj
+72 552.628 Td
+(\002le) 12.7322 Tj
+[1 0 0 1 87.2227 552.628] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -87.2227 -552.628] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+87.2227 552.628 Td
+/F134_0 9.9626 Tf
+(bzip2.c) 41.8429 Tj
+[1 0 0 1 129.066 552.628] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -129.066 -552.628] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+129.066 552.628 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(before) 25.4445 Tj
+-250 TJm
+(compiling.) 42.899 Tj
+-310 TJm
+(Otherwise) 40.9463 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(resulting) 34.8691 Tj
+-250 TJm
+(binary) 25.4544 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(on') 13.2801 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ork) 13.2801 Tj
+-250 TJm
+(correctly) 35.4071 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 550.471] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -540.508] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 530.71 Td
+/F130_0 9.9626 Tf
+(I) 3.31755 Tj
+-250 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(en') 12.7222 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(tried) 18.2614 Tj
+-250 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(stuf) 14.9439 Tj
+25 TJm
+(f) 3.31755 Tj
+-250 TJm
+(myself,) 29.6088 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(all) 9.9626 Tj
+-250 TJm
+(looks) 21.589 Tj
+-250 TJm
+(plausible.) 38.4656 Tj
+[1 0 0 1 72 528.553] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -477.701] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(30) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 34 34
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -140.398 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -13.9477] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -21.5542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -720] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 701.916 Td
+/F122_0 24.7902 Tf
+(4.) 20.675 Tj
+-278 TJm
+(Miscellanea) 139.172 Tj
+[1 0 0 1 72 701.606] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -9.1347] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -14.1161] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -678.355] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 658.006 Td
+/F122_0 17.2154 Tf
+(T) 10.5186 Tj
+80 TJm
+(ab) 20.0904 Tj
+10 TJm
+(le) 14.3576 Tj
+-278 TJm
+(of) 16.2513 Tj
+-278 TJm
+(Contents) 74.5943 Tj
+[1 0 0 1 72 649.183] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -11.7401] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -637.443] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 637.443 Td
+/F130_0 9.9626 Tf
+(4.1.) 14.9439 Tj
+-310 TJm
+(Limitations) 45.9475 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(format) 26.5603 Tj
+[1 0 0 1 255.231 637.443] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -260.212 -637.443] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+269.154 637.443 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 637.443] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -637.443] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 637.443 Td
+/F130_0 9.9626 Tf
+(31) 9.9626 Tj
+[1 0 0 1 516.09 637.443] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -625.488] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 625.488 Td
+/F130_0 9.9626 Tf
+(4.2.) 14.9439 Tj
+-310 TJm
+(Portability) 42.0721 Tj
+-250 TJm
+(issues) 23.8007 Tj
+[1 0 0 1 158.395 625.488] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -163.376 -625.488] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+172.03 625.488 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 625.488] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -625.488] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 625.488 Td
+/F130_0 9.9626 Tf
+(32) 9.9626 Tj
+[1 0 0 1 516.09 625.488] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -613.533] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 613.533 Td
+/F130_0 9.9626 Tf
+(4.3.) 14.9439 Tj
+-310 TJm
+(Reporting) 39.8504 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ugs) 13.8381 Tj
+[1 0 0 1 150.993 613.533] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -155.975 -613.533] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+166.115 613.533 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 613.533] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -613.533] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 613.533 Td
+/F130_0 9.9626 Tf
+(32) 9.9626 Tj
+[1 0 0 1 516.09 613.533] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7983] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -601.578] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 601.578 Td
+/F130_0 9.9626 Tf
+(4.4.) 14.9439 Tj
+-310 TJm
+(Did) 14.9439 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(get) 12.1743 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(right) 18.8194 Tj
+-250 TJm
+(package?) 37.0609 Tj
+[1 0 0 1 212.602 601.578] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 3.0884 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 3.0884 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -218.778 -601.578] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+229.109 601.578 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 601.578] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -601.578] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 601.578 Td
+/F130_0 9.9626 Tf
+(33) 9.9626 Tj
+[1 0 0 1 516.09 601.578] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.7984] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -589.623] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 589.623 Td
+/F130_0 9.9626 Tf
+(4.5.) 14.9439 Tj
+-310 TJm
+(Further) 29.3299 Tj
+-250 TJm
+(Reading) 33.2053 Tj
+[1 0 0 1 155.058 589.623] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4906 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -160.039 -589.623] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+170.361 589.623 Td
+/F147_0 9.9626 Tf
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+-166 TJm
+(:) 2.7696 Tj
+-167 TJm
+(:) 2.7696 Tj
+[1 0 0 1 506.127 589.623] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -506.127 -589.623] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+506.127 589.623 Td
+/F130_0 9.9626 Tf
+(34) 9.9626 Tj
+[1 0 0 1 516.09 589.623] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -444.09 -2.1568] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.1348] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -9.6315] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -568.7] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 558.901 Td
+/F130_0 9.9626 Tf
+(These) 23.7907 Tj
+-250 TJm
+(are) 12.1643 Tj
+-250 TJm
+(just) 14.396 Tj
+-250 TJm
+(some) 21.031 Tj
+-250 TJm
+(random) 30.4357 Tj
+-250 TJm
+(thoughts) 34.3212 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(mine.) 22.4159 Tj
+-620 TJm
+(Y) 7.193 Tj
+110 TJm
+(our) 13.2801 Tj
+-250 TJm
+(mileage) 31.5416 Tj
+-250 TJm
+(may) 17.1556 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(ary) 12.7222 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 556.744] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.6315] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -547.113] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 524.48 Td
+/F122_0 20.6585 Tf
+(4.1.) 34.4584 Tj
+-278 TJm
+(Limitations) 110.192 Tj
+-278 TJm
+(of) 19.5016 Tj
+-278 TJm
+(the) 30.9877 Tj
+-278 TJm
+(compressed) 121.699 Tj
+-278 TJm
+(\002le) 29.8515 Tj
+-278 TJm
+(f) 6.87928 Tj
+20 TJm
+(ormat) 57.3893 Tj
+[1 0 0 1 72 520.203] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.6315] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -510.572] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 502.893 Td
+/F134_0 9.9626 Tf
+(bzip2-1.0.X) 65.7532 Tj
+[1 0 0 1 137.753 502.893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.753 -502.893] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+137.753 502.893 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+[1 0 0 1 143.405 502.893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -143.405 -502.893] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+143.405 502.893 Td
+/F134_0 9.9626 Tf
+(0.9.5) 29.8878 Tj
+[1 0 0 1 173.293 502.893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -173.293 -502.893] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+176.453 502.893 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 194 502.893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -194 -502.893] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+194 502.893 Td
+/F134_0 9.9626 Tf
+(0.9.0) 29.8878 Tj
+[1 0 0 1 223.888 502.893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -223.888 -502.893] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+227.048 502.893 Td
+/F130_0 9.9626 Tf
+(use) 13.2801 Tj
+-317 TJm
+(e) 4.42339 Tj
+15 TJm
+(xactly) 24.3486 Tj
+-317 TJm
+(the) 12.1743 Tj
+-318 TJm
+(same) 20.4731 Tj
+-317 TJm
+(\002le) 12.7322 Tj
+-317 TJm
+(format) 26.5603 Tj
+-317 TJm
+(as) 8.29885 Tj
+-318 TJm
+(the) 12.1743 Tj
+-317 TJm
+(original) 30.9936 Tj
+-317 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion,) 26.8392 Tj
+[1 0 0 1 455.801 502.893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -455.801 -502.893] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+455.801 502.893 Td
+/F134_0 9.9626 Tf
+(bzip2-0.1) 53.798 Tj
+[1 0 0 1 509.599 502.893] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -509.599 -502.893] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+509.599 502.893 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-1023 TJm
+(This) 17.7135 Tj
+72 490.938 Td
+(decision) 33.2053 Tj
+-222 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-222 TJm
+(made) 21.579 Tj
+-222 TJm
+(in) 7.7509 Tj
+-221 TJm
+(the) 12.1743 Tj
+-222 TJm
+(interests) 33.2053 Tj
+-222 TJm
+(of) 8.29885 Tj
+-222 TJm
+(stability) 32.1095 Tj
+65 TJm
+(.) 2.49065 Tj
+-601 TJm
+(Creating) 34.3112 Tj
+-222 TJm
+(yet) 12.1743 Tj
+-222 TJm
+(another) 29.8778 Tj
+-222 TJm
+(incompatible) 52.0247 Tj
+-221 TJm
+(compressed) 47.0334 Tj
+-222 TJm
+(\002le) 12.7322 Tj
+-222 TJm
+(format) 26.5603 Tj
+-222 TJm
+(w) 7.193 Tj
+10 TJm
+(ould) 17.7135 Tj
+-222 TJm
+(create) 23.7807 Tj
+72 478.983 Td
+(further) 27.1082 Tj
+-250 TJm
+(confusion) 39.2925 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(disruption) 40.4083 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(users.) 22.9638 Tj
+[1 0 0 1 72 476.826] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.6315] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -467.194] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 457.396 Td
+/F130_0 9.9626 Tf
+(Ne) 11.6164 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ertheless,) 37.3498 Tj
+-234 TJm
+(this) 14.396 Tj
+-229 TJm
+(is) 6.64505 Tj
+-230 TJm
+(not) 12.7322 Tj
+-229 TJm
+(a) 4.42339 Tj
+-230 TJm
+(painless) 32.0995 Tj
+-229 TJm
+(decision.) 35.696 Tj
+-606 TJm
+(De) 11.6164 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(elopment) 37.0808 Tj
+-230 TJm
+(w) 7.193 Tj
+10 TJm
+(ork) 13.2801 Tj
+-230 TJm
+(since) 20.4731 Tj
+-229 TJm
+(the) 12.1743 Tj
+-230 TJm
+(release) 27.6562 Tj
+-229 TJm
+(of) 8.29885 Tj
+[1 0 0 1 407.317 457.396] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -407.317 -457.396] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+407.317 457.396 Td
+/F134_0 9.9626 Tf
+(bzip2-0.1) 53.798 Tj
+[1 0 0 1 461.115 457.396] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -461.115 -457.396] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+463.402 457.396 Td
+/F130_0 9.9626 Tf
+(in) 7.7509 Tj
+-230 TJm
+(August) 28.782 Tj
+-229 TJm
+(1997) 19.9252 Tj
+-230 TJm
+(has) 13.2801 Tj
+72 445.441 Td
+(sho) 13.8381 Tj
+25 TJm
+(wn) 12.1743 Tj
+-226 TJm
+(comple) 29.3299 Tj
+15 TJm
+(xities) 21.589 Tj
+-226 TJm
+(in) 7.7509 Tj
+-225 TJm
+(the) 12.1743 Tj
+-226 TJm
+(\002le) 12.7322 Tj
+-226 TJm
+(format) 26.5603 Tj
+-226 TJm
+(which) 24.3486 Tj
+-226 TJm
+(slo) 11.6264 Tj
+25 TJm
+(w) 7.193 Tj
+-225 TJm
+(do) 9.9626 Tj
+25 TJm
+(wn) 12.1743 Tj
+-226 TJm
+(decompression) 59.7656 Tj
+-226 TJm
+(and,) 16.8766 Tj
+-231 TJm
+(in) 7.7509 Tj
+-226 TJm
+(retrospect,) 41.7732 Tj
+-230 TJm
+(are) 12.1643 Tj
+-226 TJm
+(unnecessary) 48.6872 Tj
+65 TJm
+(.) 2.49065 Tj
+-604 TJm
+(These) 23.7907 Tj
+-226 TJm
+(are:) 14.9339 Tj
+[1 0 0 1 72 443.284] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -29.0613] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -414.222] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 414.222 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 414.222] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -414.222] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 414.222 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-265 TJm
+(run-length) 41.5042 Tj
+-266 TJm
+(encoder) 31.5316 Tj
+40 TJm
+(,) 2.49065 Tj
+-269 TJm
+(which) 24.3486 Tj
+-265 TJm
+(is) 6.64505 Tj
+-265 TJm
+(the) 12.1743 Tj
+-266 TJm
+(\002rst) 15.5018 Tj
+-265 TJm
+(of) 8.29885 Tj
+-265 TJm
+(the) 12.1743 Tj
+-266 TJm
+(compression) 50.3609 Tj
+-265 TJm
+(transformations,) 65.0259 Tj
+-269 TJm
+(is) 6.64505 Tj
+-265 TJm
+(entirely) 30.4357 Tj
+-266 TJm
+(irrele) 21.0211 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(ant.) 14.6649 Tj
+-711 TJm
+(The) 15.4918 Tj
+-266 TJm
+(original) 30.9936 Tj
+86.944 402.267 Td
+(purpose) 31.5416 Tj
+-301 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-301 TJm
+(to) 7.7509 Tj
+-301 TJm
+(protect) 27.6661 Tj
+-301 TJm
+(the) 12.1743 Tj
+-301 TJm
+(sorting) 27.6761 Tj
+-301 TJm
+(algorithm) 38.7446 Tj
+-301 TJm
+(from) 19.3673 Tj
+-301 TJm
+(the) 12.1743 Tj
+-301 TJm
+(v) 4.9813 Tj
+15 TJm
+(ery) 12.7222 Tj
+-301 TJm
+(w) 7.193 Tj
+10 TJm
+(orst) 14.9439 Tj
+-301 TJm
+(case) 17.1456 Tj
+-301 TJm
+(input:) 23.2527 Tj
+-412 TJm
+(a) 4.42339 Tj
+-301 TJm
+(string) 22.6948 Tj
+-301 TJm
+(of) 8.29885 Tj
+-301 TJm
+(repeated) 33.7433 Tj
+-301 TJm
+(symbols.) 35.706 Tj
+-927 TJm
+(But) 14.396 Tj
+86.944 390.312 Td
+(algorithm) 38.7446 Tj
+-274 TJm
+(steps) 19.9252 Tj
+-275 TJm
+(Q6a) 16.5977 Tj
+-274 TJm
+(and) 14.386 Tj
+-274 TJm
+(Q6b) 17.1556 Tj
+-275 TJm
+(in) 7.7509 Tj
+-274 TJm
+(the) 12.1743 Tj
+-274 TJm
+(original) 30.9936 Tj
+-275 TJm
+(Burro) 23.2427 Tj
+25 TJm
+(ws-Wheel) 40.3884 Tj
+1 TJm
+(er) 7.74094 Tj
+-275 TJm
+(technical) 35.965 Tj
+-274 TJm
+(report) 23.7907 Tj
+-274 TJm
+(\(SRC-124\)) 43.7259 Tj
+-275 TJm
+(sho) 13.8381 Tj
+25 TJm
+(w) 7.193 Tj
+-274 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-274 TJm
+(repeats) 28.2141 Tj
+-275 TJm
+(can) 13.8281 Tj
+86.944 378.357 Td
+(be) 9.40469 Tj
+-250 TJm
+(handled) 31.5416 Tj
+-250 TJm
+(without) 30.4457 Tj
+-250 TJm
+(dif) 11.0684 Tj
+25 TJm
+(\002culty) 25.4644 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(block) 22.1369 Tj
+-250 TJm
+(sorting.) 30.1668 Tj
+[1 0 0 1 269.617 378.357] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -197.617 -21.5867] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -356.77] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 356.77 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 356.77] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -356.77] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 356.77 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-293 TJm
+(randomisation) 57.006 Tj
+-293 TJm
+(mechanism) 45.3796 Tj
+-293 TJm
+(doesn') 26.5603 Tj
+18 TJm
+(t) 2.7696 Tj
+-294 TJm
+(really) 22.6848 Tj
+-293 TJm
+(need) 18.8094 Tj
+-293 TJm
+(to) 7.7509 Tj
+-293 TJm
+(be) 9.40469 Tj
+-293 TJm
+(there.) 22.4059 Tj
+-879 TJm
+(Udi) 14.9439 Tj
+-294 TJm
+(Manber) 30.9837 Tj
+-293 TJm
+(and) 14.386 Tj
+-293 TJm
+(Gene) 21.0211 Tj
+-293 TJm
+(Myers) 25.4544 Tj
+-293 TJm
+(published) 38.7446 Tj
+-294 TJm
+(a) 4.42339 Tj
+-293 TJm
+(suf) 12.1743 Tj
+25 TJm
+(\002x) 10.5205 Tj
+86.944 344.815 Td
+(array) 20.4632 Tj
+-238 TJm
+(construction) 49.2551 Tj
+-239 TJm
+(algorithm) 38.7446 Tj
+-238 TJm
+(a) 4.42339 Tj
+-238 TJm
+(fe) 7.74094 Tj
+25 TJm
+(w) 7.193 Tj
+-239 TJm
+(years) 21.0211 Tj
+-238 TJm
+(back,) 21.3 Tj
+-241 TJm
+(which) 24.3486 Tj
+-238 TJm
+(can) 13.8281 Tj
+-238 TJm
+(be) 9.40469 Tj
+-239 TJm
+(emplo) 24.9065 Tj
+10 TJm
+(yed) 14.386 Tj
+-238 TJm
+(to) 7.7509 Tj
+-238 TJm
+(sort) 14.9439 Tj
+-239 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-238 TJm
+(block,) 24.6275 Tj
+-241 TJm
+(no) 9.9626 Tj
+-238 TJm
+(matter) 25.4544 Tj
+-238 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-239 TJm
+(repetiti) 28.224 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e,) 6.91404 Tj
+86.944 332.86 Td
+(in) 7.7509 Tj
+-229 TJm
+(O\(N) 17.7035 Tj
+-230 TJm
+(log) 12.7322 Tj
+-229 TJm
+(N\)) 10.5105 Tj
+-230 TJm
+(time.) 20.2042 Tj
+-606 TJm
+(Subsequent) 45.9375 Tj
+-230 TJm
+(w) 7.193 Tj
+10 TJm
+(ork) 13.2801 Tj
+-229 TJm
+(by) 9.9626 Tj
+-230 TJm
+(K) 7.193 Tj
+15 TJm
+(unihik) 25.4644 Tj
+10 TJm
+(o) 4.9813 Tj
+-229 TJm
+(Sadakane) 38.1767 Tj
+-229 TJm
+(has) 13.2801 Tj
+-230 TJm
+(produced) 37.0708 Tj
+-229 TJm
+(a) 4.42339 Tj
+-230 TJm
+(deri) 15.4918 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(ati) 9.9626 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-229 TJm
+(O\(N) 17.7035 Tj
+-230 TJm
+(\(log) 16.0497 Tj
+-229 TJm
+(N\)^2\)) 23.4818 Tj
+-230 TJm
+(algorithm) 38.7446 Tj
+86.944 320.905 Td
+(which) 24.3486 Tj
+-250 TJm
+(usually) 28.782 Tj
+-250 TJm
+(outperforms) 48.6972 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(Manber) 30.9837 Tj
+20 TJm
+(-Myers) 28.772 Tj
+-250 TJm
+(algorithm.) 41.2352 Tj
+[1 0 0 1 314.189 320.905] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -242.189 -11.7883] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -309.116] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 299.318 Td
+/F130_0 9.9626 Tf
+(I) 3.31755 Tj
+-248 TJm
+(could) 22.1369 Tj
+-248 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-248 TJm
+(changed) 33.1954 Tj
+-248 TJm
+(to) 7.7509 Tj
+-248 TJm
+(Sadakane') 41.4942 Tj
+55 TJm
+(s) 3.87545 Tj
+-248 TJm
+(algorithm,) 41.2352 Tj
+-249 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-248 TJm
+(I) 3.31755 Tj
+-248 TJm
+(\002nd) 15.5018 Tj
+-248 TJm
+(it) 5.53921 Tj
+-248 TJm
+(to) 7.7509 Tj
+-248 TJm
+(be) 9.40469 Tj
+-248 TJm
+(slo) 11.6264 Tj
+25 TJm
+(wer) 14.9339 Tj
+-248 TJm
+(than) 17.1556 Tj
+[1 0 0 1 392.444 299.318] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -392.444 -299.318] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+392.444 299.318 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 422.332 299.318] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -422.332 -299.318] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+422.332 299.318 Td
+/F130_0 9.9626 Tf
+(') 3.31755 Tj
+55 TJm
+(s) 3.87545 Tj
+-248 TJm
+(e) 4.42339 Tj
+15 TJm
+(xisting) 27.1282 Tj
+-248 TJm
+(algorithm) 38.7446 Tj
+-248 TJm
+(for) 11.6164 Tj
+-248 TJm
+(most) 19.3773 Tj
+86.944 287.363 Td
+(inputs,) 26.8492 Tj
+-370 TJm
+(and) 14.386 Tj
+-345 TJm
+(the) 12.1743 Tj
+-346 TJm
+(randomisation) 57.006 Tj
+-346 TJm
+(mechanism) 45.3796 Tj
+-345 TJm
+(protects) 31.5416 Tj
+-346 TJm
+(adequately) 43.158 Tj
+-345 TJm
+(ag) 9.40469 Tj
+5 TJm
+(ainst) 18.8194 Tj
+-346 TJm
+(bad) 14.386 Tj
+-346 TJm
+(cases.) 23.5117 Tj
+-1194 TJm
+(I) 3.31755 Tj
+-345 TJm
+(didn') 21.031 Tj
+18 TJm
+(t) 2.7696 Tj
+-346 TJm
+(think) 20.4831 Tj
+-346 TJm
+(it) 5.53921 Tj
+-345 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-346 TJm
+(a) 4.42339 Tj
+-346 TJm
+(good) 19.9252 Tj
+86.944 275.408 Td
+(tradeof) 28.2141 Tj
+25 TJm
+(f) 3.31755 Tj
+-262 TJm
+(to) 7.7509 Tj
+-261 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e.) 6.91404 Tj
+-690 TJm
+(P) 5.53921 Tj
+15 TJm
+(artly) 18.2614 Tj
+-262 TJm
+(this) 14.396 Tj
+-261 TJm
+(is) 6.64505 Tj
+-262 TJm
+(due) 14.386 Tj
+-261 TJm
+(to) 7.7509 Tj
+-262 TJm
+(the) 12.1743 Tj
+-262 TJm
+(f) 3.31755 Tj
+10 TJm
+(act) 11.6164 Tj
+-261 TJm
+(that) 14.9439 Tj
+-262 TJm
+(I) 3.31755 Tj
+-261 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-262 TJm
+(not) 12.7322 Tj
+-262 TJm
+(\003ooded) 29.8878 Tj
+-261 TJm
+(with) 17.7135 Tj
+-262 TJm
+(email) 22.1369 Tj
+-261 TJm
+(complaints) 43.7259 Tj
+-262 TJm
+(about) 22.1369 Tj
+[1 0 0 1 479.557 275.408] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -479.557 -275.408] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+479.557 275.408 Td
+/F134_0 9.9626 Tf
+(bzip2-0.1) 53.798 Tj
+[1 0 0 1 533.355 275.408] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -533.355 -275.408] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+533.355 275.408 Td
+/F130_0 9.9626 Tf
+(') 3.31755 Tj
+55 TJm
+(s) 3.87545 Tj
+86.944 263.453 Td
+(performance) 50.341 Tj
+-250 TJm
+(on) 9.9626 Tj
+-250 TJm
+(repetiti) 28.224 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(data,) 19.0883 Tj
+-250 TJm
+(so) 8.85675 Tj
+-250 TJm
+(perhaps) 30.9837 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(isn') 14.9439 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(problem) 33.2053 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(real) 14.9339 Tj
+-250 TJm
+(inputs.) 26.8492 Tj
+[1 0 0 1 72 261.296] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.6315] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -251.664] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 241.866 Td
+/F130_0 9.9626 Tf
+(Probably) 35.9749 Tj
+-289 TJm
+(the) 12.1743 Tj
+-288 TJm
+(best) 16.0497 Tj
+-289 TJm
+(long-term) 39.2925 Tj
+-289 TJm
+(solution,) 34.6001 Tj
+-298 TJm
+(and) 14.386 Tj
+-289 TJm
+(the) 12.1743 Tj
+-289 TJm
+(one) 14.386 Tj
+-288 TJm
+(I) 3.31755 Tj
+-289 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-289 TJm
+(incorporated) 50.351 Tj
+-288 TJm
+(into) 15.5018 Tj
+-289 TJm
+(0.9.5) 19.9252 Tj
+-289 TJm
+(and) 14.386 Tj
+-288 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+14 TJm
+(e,) 6.91404 Tj
+-298 TJm
+(is) 6.64505 Tj
+-289 TJm
+(to) 7.7509 Tj
+-288 TJm
+(use) 13.2801 Tj
+-289 TJm
+(the) 12.1743 Tj
+-289 TJm
+(e) 4.42339 Tj
+15 TJm
+(xisting) 27.1282 Tj
+86.944 229.911 Td
+(sorting) 27.6761 Tj
+-451 TJm
+(algorithm) 38.7446 Tj
+-452 TJm
+(initially) 31.0036 Tj
+65 TJm
+(,) 2.49065 Tj
+-501 TJm
+(and) 14.386 Tj
+-452 TJm
+(f) 3.31755 Tj
+10 TJm
+(all) 9.9626 Tj
+-451 TJm
+(back) 18.8094 Tj
+-452 TJm
+(to) 7.7509 Tj
+-451 TJm
+(a) 4.42339 Tj
+-451 TJm
+(O\(N) 17.7035 Tj
+-452 TJm
+(\(log) 16.0497 Tj
+-451 TJm
+(N\)^2\)) 23.4818 Tj
+-451 TJm
+(algorithm) 38.7446 Tj
+-452 TJm
+(if) 6.08715 Tj
+-451 TJm
+(the) 12.1743 Tj
+-452 TJm
+(standard) 33.7533 Tj
+-451 TJm
+(algorithm) 38.7446 Tj
+-451 TJm
+(gets) 16.0497 Tj
+-452 TJm
+(into) 15.5018 Tj
+86.944 217.956 Td
+(dif) 11.0684 Tj
+25 TJm
+(\002culties.) 34.0422 Tj
+[1 0 0 1 72 217.856] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -21.4871] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -196.369] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 196.369 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 196.369] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -196.369] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 196.369 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-299 TJm
+(compressed) 47.0334 Tj
+-299 TJm
+(\002le) 12.7322 Tj
+-299 TJm
+(format) 26.5603 Tj
+-299 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-300 TJm
+(ne) 9.40469 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-299 TJm
+(designed) 35.417 Tj
+-299 TJm
+(to) 7.7509 Tj
+-299 TJm
+(be) 9.40469 Tj
+-299 TJm
+(handled) 31.5416 Tj
+-299 TJm
+(by) 9.9626 Tj
+-299 TJm
+(a) 4.42339 Tj
+-299 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-312 TJm
+(and) 14.386 Tj
+-299 TJm
+(I) 3.31755 Tj
+-299 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-299 TJm
+(had) 14.386 Tj
+-299 TJm
+(to) 7.7509 Tj
+-299 TJm
+(jump) 20.4831 Tj
+-300 TJm
+(though) 27.6761 Tj
+-299 TJm
+(some) 21.031 Tj
+86.944 184.414 Td
+(hoops) 23.8007 Tj
+-278 TJm
+(to) 7.7509 Tj
+-277 TJm
+(produce) 32.0895 Tj
+-278 TJm
+(an) 9.40469 Tj
+-278 TJm
+(ef) 7.74094 Tj
+25 TJm
+(\002cient) 24.9065 Tj
+-277 TJm
+(implementation) 62.5452 Tj
+-278 TJm
+(of) 8.29885 Tj
+-278 TJm
+(decompression.) 62.2563 Tj
+-786 TJm
+(It') 9.40469 Tj
+55 TJm
+(s) 3.87545 Tj
+-278 TJm
+(a) 4.42339 Tj
+-277 TJm
+(bit) 10.5205 Tj
+-278 TJm
+(hairy) 20.4731 Tj
+65 TJm
+(.) 2.49065 Tj
+-786 TJm
+(T) 6.08715 Tj
+35 TJm
+(ry) 8.29885 Tj
+-278 TJm
+(passing) 29.8878 Tj
+[1 0 0 1 468.269 184.414] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468.269 -184.414] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+468.269 184.414 Td
+/F134_0 9.9626 Tf
+(decompress.c) 71.7307 Tj
+[1 0 0 1 540 184.414] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -184.414] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 172.459 Td
+/F130_0 9.9626 Tf
+(through) 30.9936 Tj
+-268 TJm
+(the) 12.1743 Tj
+-268 TJm
+(C) 6.64505 Tj
+-268 TJm
+(preprocessor) 50.8989 Tj
+-269 TJm
+(and) 14.386 Tj
+-268 TJm
+(you') 18.2614 Tj
+10 TJm
+(ll) 5.53921 Tj
+-268 TJm
+(see) 12.7222 Tj
+-268 TJm
+(what) 19.3673 Tj
+-268 TJm
+(I) 3.31755 Tj
+-268 TJm
+(mean.) 24.0696 Tj
+-729 TJm
+(Much) 23.2427 Tj
+-268 TJm
+(of) 8.29885 Tj
+-269 TJm
+(this) 14.396 Tj
+-268 TJm
+(comple) 29.3299 Tj
+15 TJm
+(xity) 15.5018 Tj
+-268 TJm
+(could) 22.1369 Tj
+-268 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-268 TJm
+(been) 18.8094 Tj
+-268 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+20 TJm
+(oided) 22.1369 Tj
+-269 TJm
+(if) 6.08715 Tj
+-268 TJm
+(the) 12.1743 Tj
+86.944 160.503 Td
+(compressed) 47.0334 Tj
+-250 TJm
+(size) 15.4918 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(each) 18.2515 Tj
+-250 TJm
+(block) 22.1369 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-250 TJm
+(recorded) 34.8492 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(data) 16.5977 Tj
+-250 TJm
+(stream.) 29.0509 Tj
+[1 0 0 1 368.754 160.503] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -296.754 -21.5867] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -138.917] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 138.917 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 138.917] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -138.917] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 138.917 Td
+/F130_0 9.9626 Tf
+(An) 12.1743 Tj
+-250 TJm
+(Adler) 22.6848 Tj
+20 TJm
+(-32) 13.2801 Tj
+-250 TJm
+(checksum,) 42.3311 Tj
+-250 TJm
+(rather) 23.2328 Tj
+-250 TJm
+(than) 17.1556 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(CRC32) 29.8978 Tj
+-250 TJm
+(checksum,) 42.3311 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ould) 17.7135 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(f) 3.31755 Tj
+10 TJm
+(aster) 18.8094 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(compute.) 36.8018 Tj
+[1 0 0 1 424.934 138.917] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -352.934 -11.7883] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -127.128] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 117.33 Td
+/F130_0 9.9626 Tf
+(It) 6.08715 Tj
+-349 TJm
+(w) 7.193 Tj
+10 TJm
+(ould) 17.7135 Tj
+-349 TJm
+(be) 9.40469 Tj
+-349 TJm
+(f) 3.31755 Tj
+10 TJm
+(air) 10.5105 Tj
+-348 TJm
+(to) 7.7509 Tj
+-349 TJm
+(say) 13.2801 Tj
+-349 TJm
+(that) 14.9439 Tj
+-349 TJm
+(the) 12.1743 Tj
+[1 0 0 1 201.979 117.33] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -201.979 -117.33] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+201.979 117.33 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 231.867 117.33] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -231.867 -117.33] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+235.342 117.33 Td
+/F130_0 9.9626 Tf
+(format) 26.5603 Tj
+-349 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-349 TJm
+(frozen) 25.4445 Tj
+-348 TJm
+(before) 25.4445 Tj
+-349 TJm
+(I) 3.31755 Tj
+-349 TJm
+(properly) 33.7533 Tj
+-349 TJm
+(and) 14.386 Tj
+-349 TJm
+(fully) 18.8194 Tj
+-349 TJm
+(understood) 44.2738 Tj
+-348 TJm
+(the) 12.1743 Tj
+-349 TJm
+(performance) 50.341 Tj
+72 105.375 Td
+(consequences) 54.7744 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(doing) 22.6948 Tj
+-250 TJm
+(so.) 11.3474 Tj
+[1 0 0 1 72 103.218] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.6315] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -93.5867] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 83.7883 Td
+/F130_0 9.9626 Tf
+(Impro) 24.3486 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(ements) 28.224 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(I) 3.31755 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(as) 8.29885 Tj
+-250 TJm
+(able) 16.5977 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(incorporate) 45.3697 Tj
+-250 TJm
+(into) 15.5018 Tj
+-250 TJm
+(0.9.0,) 22.4159 Tj
+-250 TJm
+(despite) 28.224 Tj
+-250 TJm
+(using) 21.589 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(same) 20.4731 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(format,) 29.0509 Tj
+-250 TJm
+(are:) 14.9339 Tj
+[1 0 0 1 72 81.6315] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -30.7796] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(31) 9.9626 Tj
+[1 0 0 1 453.269 50.8519] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 35 35
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 116.328 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -382.4 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+498.728 749.245 Td
+/F130_0 9.9626 Tf
+(Miscellanea) 48.1393 Tj
+[1 0 0 1 266.071 749.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -7.0936] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -31.5168] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 710.037 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 710.037 Td
+/F130_0 9.9626 Tf
+(Single) 25.4644 Tj
+-202 TJm
+(array) 20.4632 Tj
+-201 TJm
+(implementation) 62.5452 Tj
+-202 TJm
+(of) 8.29885 Tj
+-202 TJm
+(the) 12.1743 Tj
+-201 TJm
+(in) 7.7509 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(erse) 16.0398 Tj
+-202 TJm
+(BWT) 22.1369 Tj
+74 TJm
+(.) 2.49065 Tj
+-403 TJm
+(This) 17.7135 Tj
+-202 TJm
+(signi\002cantly) 49.2651 Tj
+-201 TJm
+(speeds) 26.5603 Tj
+-202 TJm
+(up) 9.9626 Tj
+-202 TJm
+(decompression,) 62.2563 Tj
+-211 TJm
+(presumably) 46.4855 Tj
+-202 TJm
+(because) 31.5316 Tj
+86.944 698.082 Td
+(it) 5.53921 Tj
+-250 TJm
+(reduces) 30.4258 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(number) 30.4357 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(cache) 22.6749 Tj
+-250 TJm
+(misses.) 29.0609 Tj
+[1 0 0 1 240.496 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -168.496 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 676.164 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 676.164] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -676.164] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 676.164 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(aster) 18.8094 Tj
+-314 TJm
+(in) 7.7509 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(erse) 16.0398 Tj
+-315 TJm
+(MTF) 20.4831 Tj
+-314 TJm
+(transform) 38.7346 Tj
+-315 TJm
+(for) 11.6164 Tj
+-314 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ge) 9.40469 Tj
+-315 TJm
+(MTF) 20.4831 Tj
+-314 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues.) 22.9638 Tj
+-504 TJm
+(The) 15.4918 Tj
+-314 TJm
+(ne) 9.40469 Tj
+25 TJm
+(w) 7.193 Tj
+-314 TJm
+(implementation) 62.5452 Tj
+-315 TJm
+(is) 6.64505 Tj
+-314 TJm
+(based) 22.6848 Tj
+-315 TJm
+(on) 9.9626 Tj
+-314 TJm
+(the) 12.1743 Tj
+-315 TJm
+(notion) 25.4644 Tj
+-314 TJm
+(of) 8.29885 Tj
+-315 TJm
+(sliding) 27.1282 Tj
+86.944 664.209 Td
+(blocks) 26.0123 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(v) 4.9813 Tj
+25 TJm
+(alues.) 22.9638 Tj
+[1 0 0 1 153.932 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -81.9321 -21.9178] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 642.291 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 642.291 Td
+/F134_0 9.9626 Tf
+(bzip2-0.9.0) 65.7532 Tj
+[1 0 0 1 152.697 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -152.697 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+155.412 642.291 Td
+/F130_0 9.9626 Tf
+(no) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-272 TJm
+(reads) 21.0211 Tj
+-273 TJm
+(and) 14.386 Tj
+-272 TJm
+(writes) 24.3486 Tj
+-273 TJm
+(\002les) 16.6077 Tj
+-272 TJm
+(with) 17.7135 Tj
+[1 0 0 1 282.68 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -282.68 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+282.68 642.291 Td
+/F134_0 9.9626 Tf
+(fread) 29.8878 Tj
+[1 0 0 1 312.568 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -312.568 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+315.282 642.291 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 332.383 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -332.383 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+332.383 642.291 Td
+/F134_0 9.9626 Tf
+(fwrite) 35.8654 Tj
+[1 0 0 1 368.248 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -368.248 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+368.248 642.291 Td
+/F130_0 9.9626 Tf
+(;) 2.7696 Tj
+-284 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-272 TJm
+(0.1) 12.4533 Tj
+-273 TJm
+(used) 18.2614 Tj
+[1 0 0 1 441.882 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -441.882 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+441.882 642.291 Td
+/F134_0 9.9626 Tf
+(putc) 23.9102 Tj
+[1 0 0 1 465.792 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -465.792 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+468.507 642.291 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 485.607 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -485.607 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+485.607 642.291 Td
+/F134_0 9.9626 Tf
+(getc) 23.9102 Tj
+[1 0 0 1 509.517 642.291] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -509.517 -642.291] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+509.517 642.291 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-755 TJm
+(Duh!) 20.4731 Tj
+86.944 630.336 Td
+(W) 9.40469 Tj
+80 TJm
+(ell,) 12.4533 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(li) 5.53921 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(learn.) 22.4059 Tj
+[1 0 0 1 184.248 630.336] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -112.248 -12.1195] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -618.217] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 608.418 Td
+/F130_0 9.9626 Tf
+(Further) 29.3299 Tj
+-304 TJm
+(ahead,) 25.7234 Tj
+-318 TJm
+(it) 5.53921 Tj
+-305 TJm
+(w) 7.193 Tj
+10 TJm
+(ould) 17.7135 Tj
+-304 TJm
+(be) 9.40469 Tj
+-305 TJm
+(nice) 16.5977 Tj
+-304 TJm
+(to) 7.7509 Tj
+-305 TJm
+(be) 9.40469 Tj
+-304 TJm
+(able) 16.5977 Tj
+-304 TJm
+(to) 7.7509 Tj
+-305 TJm
+(do) 9.9626 Tj
+-304 TJm
+(random) 30.4357 Tj
+-305 TJm
+(access) 25.4445 Tj
+-304 TJm
+(into) 15.5018 Tj
+-305 TJm
+(\002les.) 19.0983 Tj
+-946 TJm
+(This) 17.7135 Tj
+-305 TJm
+(will) 15.5018 Tj
+-304 TJm
+(require) 28.2141 Tj
+-304 TJm
+(some) 21.031 Tj
+-305 TJm
+(careful) 27.6562 Tj
+-304 TJm
+(design) 26.0123 Tj
+-305 TJm
+(of) 8.29885 Tj
+72 596.463 Td
+(compressed) 47.0334 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(formats.) 32.9264 Tj
+[1 0 0 1 72 594.306] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -584.344] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 561.71 Td
+/F122_0 20.6585 Tf
+(4.2.) 34.4584 Tj
+-278 TJm
+(P) 13.7792 Tj
+40 TJm
+(or) 20.6585 Tj
+-20 TJm
+(tability) 66.5823 Tj
+-278 TJm
+(issues) 64.3099 Tj
+[1 0 0 1 72 557.434] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -547.472] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 539.793 Td
+/F130_0 9.9626 Tf
+(After) 21.0211 Tj
+-250 TJm
+(some) 21.031 Tj
+-250 TJm
+(consideration,) 56.1691 Tj
+-250 TJm
+(I) 3.31755 Tj
+-250 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(decided) 30.9837 Tj
+-250 TJm
+(not) 12.7322 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(use) 13.2801 Tj
+-250 TJm
+(GNU) 21.579 Tj
+[1 0 0 1 303.231 539.793] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -303.231 -539.793] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+303.231 539.793 Td
+/F134_0 9.9626 Tf
+(autoconf) 47.8205 Tj
+[1 0 0 1 351.052 539.793] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -351.052 -539.793] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+353.542 539.793 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-250 TJm
+(con\002gure) 37.6287 Tj
+-250 TJm
+(0.9.5) 19.9252 Tj
+-250 TJm
+(or) 8.29885 Tj
+-250 TJm
+(1.0.) 14.9439 Tj
+[1 0 0 1 72 537.636] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -527.673] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 517.875 Td
+/F134_0 9.9626 Tf
+(autoconf) 47.8205 Tj
+[1 0 0 1 119.821 517.875] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -119.821 -517.875] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+119.821 517.875 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-502 TJm
+(admirable) 39.8404 Tj
+-452 TJm
+(and) 14.386 Tj
+-452 TJm
+(w) 7.193 Tj
+10 TJm
+(onderful) 33.7533 Tj
+-452 TJm
+(though) 27.6761 Tj
+-452 TJm
+(it) 5.53921 Tj
+-452 TJm
+(is,) 9.1357 Tj
+-502 TJm
+(mainly) 27.6761 Tj
+-452 TJm
+(assists) 25.4644 Tj
+-452 TJm
+(with) 17.7135 Tj
+-452 TJm
+(portability) 41.5142 Tj
+-452 TJm
+(problems) 37.0808 Tj
+-452 TJm
+(between) 33.1954 Tj
+-452 TJm
+(Unix-lik) 33.7633 Tj
+10 TJm
+(e) 4.42339 Tj
+72 505.92 Td
+(platforms.) 40.6773 Tj
+-1398 TJm
+(But) 14.396 Tj
+[1 0 0 1 144.784 505.92] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -144.784 -505.92] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+144.784 505.92 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 174.672 505.92] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -174.672 -505.92] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+178.455 505.92 Td
+/F130_0 9.9626 Tf
+(doesn') 26.5603 Tj
+18 TJm
+(t) 2.7696 Tj
+-380 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-379 TJm
+(much) 22.1369 Tj
+-380 TJm
+(in) 7.7509 Tj
+-380 TJm
+(the) 12.1743 Tj
+-379 TJm
+(w) 7.193 Tj
+10 TJm
+(ay) 9.40469 Tj
+-380 TJm
+(of) 8.29885 Tj
+-380 TJm
+(portability) 41.5142 Tj
+-379 TJm
+(problems) 37.0808 Tj
+-380 TJm
+(on) 9.9626 Tj
+-380 TJm
+(Unix;) 22.6948 Tj
+-444 TJm
+(most) 19.3773 Tj
+-380 TJm
+(of) 8.29885 Tj
+-380 TJm
+(the) 12.1743 Tj
+-379 TJm
+(dif) 11.0684 Tj
+25 TJm
+(\002culties) 31.5516 Tj
+72 493.964 Td
+(appear) 26.5503 Tj
+-297 TJm
+(when) 21.579 Tj
+-296 TJm
+(po) 9.9626 Tj
+-1 TJm
+(r) 3.31755 Tj
+1 TJm
+(ting) 15.5018 Tj
+-297 TJm
+(to) 7.7509 Tj
+-297 TJm
+(the) 12.1743 Tj
+-297 TJm
+(Mac,) 20.1942 Tj
+-308 TJm
+(or) 8.29885 Tj
+-297 TJm
+(to) 7.7509 Tj
+-297 TJm
+(Microsoft') 42.61 Tj
+55 TJm
+(s) 3.87545 Tj
+-296 TJm
+(operating) 37.6287 Tj
+-297 TJm
+(systems.) 34.0422 Tj
+[1 0 0 1 361.339 493.964] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -361.339 -493.964] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+361.339 493.964 Td
+/F134_0 9.9626 Tf
+(autoconf) 47.8205 Tj
+[1 0 0 1 409.16 493.964] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -409.16 -493.964] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+412.116 493.964 Td
+/F130_0 9.9626 Tf
+(doesn') 26.5603 Tj
+18 TJm
+(t) 2.7696 Tj
+-297 TJm
+(help) 17.1556 Tj
+-296 TJm
+(in) 7.7509 Tj
+-297 TJm
+(those) 21.031 Tj
+-297 TJm
+(cases,) 23.5117 Tj
+-308 TJm
+(and) 14.386 Tj
+72 482.009 Td
+(brings) 24.9065 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(whole) 24.3486 Tj
+-250 TJm
+(load) 17.1556 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(ne) 9.40469 Tj
+25 TJm
+(w) 7.193 Tj
+-250 TJm
+(comple) 29.3299 Tj
+15 TJm
+(xity) 15.5018 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 479.852] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -469.89] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 460.091 Td
+/F130_0 9.9626 Tf
+(Most) 20.4831 Tj
+-392 TJm
+(people) 26.5603 Tj
+-392 TJm
+(should) 26.5703 Tj
+-393 TJm
+(be) 9.40469 Tj
+-392 TJm
+(able) 16.5977 Tj
+-392 TJm
+(to) 7.7509 Tj
+-392 TJm
+(compile) 32.0995 Tj
+-393 TJm
+(the) 12.1743 Tj
+-392 TJm
+(library) 26.5603 Tj
+-392 TJm
+(and) 14.386 Tj
+-392 TJm
+(program) 33.7533 Tj
+-393 TJm
+(under) 22.6848 Tj
+-392 TJm
+(Unix) 19.9252 Tj
+-392 TJm
+(straight) 29.8878 Tj
+-392 TJm
+(out-of-the-box,) 60.5925 Tj
+-428 TJm
+(so) 8.85675 Tj
+-392 TJm
+(to) 7.7509 Tj
+-393 TJm
+(speak,) 25.1755 Tj
+72 448.136 Td
+(especially) 39.8404 Tj
+-250 TJm
+(if) 6.08715 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(GNU) 21.579 Tj
+-250 TJm
+(C) 6.64505 Tj
+-250 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+25 TJm
+(ailable.) 29.0509 Tj
+[1 0 0 1 72 445.979] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -436.017] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 426.218 Td
+/F130_0 9.9626 Tf
+(There) 23.2328 Tj
+-259 TJm
+(are) 12.1643 Tj
+-258 TJm
+(a) 4.42339 Tj
+-259 TJm
+(couple) 26.5603 Tj
+-258 TJm
+(of) 8.29885 Tj
+[1 0 0 1 159.561 426.218] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -159.561 -426.218] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+159.561 426.218 Td
+/F134_0 9.9626 Tf
+(__inline__) 59.7756 Tj
+[1 0 0 1 219.337 426.218] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -219.337 -426.218] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+221.913 426.218 Td
+/F130_0 9.9626 Tf
+(directi) 25.4544 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+-259 TJm
+(in) 7.7509 Tj
+-258 TJm
+(the) 12.1743 Tj
+-259 TJm
+(code.) 21.3 Tj
+-671 TJm
+(GNU) 21.579 Tj
+-259 TJm
+(C) 6.64505 Tj
+-258 TJm
+(\() 3.31755 Tj
+[1 0 0 1 352.587 426.218] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -352.587 -426.218] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+352.587 426.218 Td
+/F134_0 9.9626 Tf
+(gcc) 17.9327 Tj
+[1 0 0 1 370.52 426.218] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -370.52 -426.218] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+370.52 426.218 Td
+/F130_0 9.9626 Tf
+(\)) 3.31755 Tj
+-259 TJm
+(should) 26.5703 Tj
+-258 TJm
+(be) 9.40469 Tj
+-259 TJm
+(able) 16.5977 Tj
+-258 TJm
+(to) 7.7509 Tj
+-259 TJm
+(handle) 26.5603 Tj
+-259 TJm
+(them.) 22.4159 Tj
+-671 TJm
+(If) 6.63509 Tj
+-259 TJm
+(you') 18.2614 Tj
+50 TJm
+(re) 7.74094 Tj
+72 414.263 Td
+(not) 12.7322 Tj
+-279 TJm
+(using) 21.589 Tj
+-279 TJm
+(GNU) 21.579 Tj
+-279 TJm
+(C,) 9.1357 Tj
+-279 TJm
+(your) 18.2614 Tj
+-279 TJm
+(C) 6.64505 Tj
+-279 TJm
+(compiler) 35.417 Tj
+-279 TJm
+(shouldn') 34.8691 Tj
+18 TJm
+(t) 2.7696 Tj
+-279 TJm
+(see) 12.7222 Tj
+-279 TJm
+(them) 19.9252 Tj
+-279 TJm
+(at) 7.193 Tj
+-279 TJm
+(all.) 12.4533 Tj
+-794 TJm
+(If) 6.63509 Tj
+-279 TJm
+(your) 18.2614 Tj
+-279 TJm
+(compiler) 35.417 Tj
+-279 TJm
+(does,) 20.7521 Tj
+-286 TJm
+(for) 11.6164 Tj
+-279 TJm
+(some) 21.031 Tj
+-279 TJm
+(reason,) 28.493 Tj
+-287 TJm
+(see) 12.7222 Tj
+-279 TJm
+(them) 19.9252 Tj
+-279 TJm
+(and) 14.386 Tj
+72 402.308 Td
+(doesn') 26.5603 Tj
+18 TJm
+(t) 2.7696 Tj
+-283 TJm
+(lik) 10.5205 Tj
+10 TJm
+(e) 4.42339 Tj
+-283 TJm
+(them,) 22.4159 Tj
+-291 TJm
+(just) 14.396 Tj
+[1 0 0 1 164.167 402.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -164.167 -402.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+164.167 402.308 Td
+/F134_0 9.9626 Tf
+(#define) 41.8429 Tj
+[1 0 0 1 206.01 402.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.8196 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -208.829 -402.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+208.829 402.308 Td
+/F134_0 9.9626 Tf
+(__inline__) 59.7756 Tj
+[1 0 0 1 268.605 402.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -268.605 -402.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+271.425 402.308 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-283 TJm
+(be) 9.40469 Tj
+[1 0 0 1 294.22 402.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -294.22 -402.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+294.22 402.308 Td
+/F134_0 9.9626 Tf
+(/) 5.97756 Tj
+300.197 400.565 Td
+(*) 5.97756 Tj
+-600 TJm
+(*) 5.97756 Tj
+318.13 402.308 Td
+(/) 5.97756 Tj
+[1 0 0 1 324.108 402.308] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -324.108 -402.308] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+324.108 402.308 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-818 TJm
+(One) 16.5977 Tj
+-283 TJm
+(easy) 17.7035 Tj
+-283 TJm
+(w) 7.193 Tj
+10 TJm
+(ay) 9.40469 Tj
+-283 TJm
+(to) 7.7509 Tj
+-283 TJm
+(do) 9.9626 Tj
+-283 TJm
+(this) 14.396 Tj
+-283 TJm
+(is) 6.64505 Tj
+-283 TJm
+(to) 7.7509 Tj
+-283 TJm
+(compile) 32.0995 Tj
+-283 TJm
+(with) 17.7135 Tj
+-283 TJm
+(the) 12.1743 Tj
+-283 TJm
+(\003ag) 14.9439 Tj
+[1 0 0 1 72 390.353] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -390.353] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 390.353 Td
+/F134_0 9.9626 Tf
+(-D__inline__=) 77.7083 Tj
+[1 0 0 1 149.709 390.353] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -149.709 -390.353] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+149.709 390.353 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-250 TJm
+(which) 24.3486 Tj
+-250 TJm
+(should) 26.5703 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(understood) 44.2738 Tj
+-250 TJm
+(by) 9.9626 Tj
+-250 TJm
+(most) 19.3773 Tj
+-250 TJm
+(Unix) 19.9252 Tj
+-250 TJm
+(compilers.) 41.7831 Tj
+[1 0 0 1 72 388.196] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -378.233] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 368.435 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-321 TJm
+(you) 14.9439 Tj
+-321 TJm
+(still) 14.9539 Tj
+-322 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-321 TJm
+(dif) 11.0684 Tj
+25 TJm
+(\002culties,) 34.0422 Tj
+-339 TJm
+(try) 11.0684 Tj
+-321 TJm
+(compiling) 40.4083 Tj
+-321 TJm
+(with) 17.7135 Tj
+-322 TJm
+(t) 2.7696 Tj
+1 TJm
+(he) 9.40469 Tj
+-322 TJm
+(macro) 24.8965 Tj
+[1 0 0 1 310.295 368.435] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -310.295 -368.435] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+310.295 368.435 Td
+/F134_0 9.9626 Tf
+(BZ_STRICT_ANSI) 83.6858 Tj
+[1 0 0 1 393.981 368.435] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -393.981 -368.435] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+397.18 368.435 Td
+/F130_0 9.9626 Tf
+(de\002ned.) 31.8205 Tj
+-524 TJm
+(This) 17.7135 Tj
+-321 TJm
+(should) 26.5703 Tj
+-321 TJm
+(enable) 26.0024 Tj
+-321 TJm
+(you) 14.9439 Tj
+-322 TJm
+(to) 7.7509 Tj
+72 356.48 Td
+(b) 4.9813 Tj
+20 TJm
+(uild) 15.5018 Tj
+-321 TJm
+(the) 12.1743 Tj
+-321 TJm
+(library) 26.5603 Tj
+-322 TJm
+(in) 7.7509 Tj
+-321 TJm
+(a) 4.42339 Tj
+-321 TJm
+(strictly) 27.6761 Tj
+-321 TJm
+(ANSI) 23.2427 Tj
+-321 TJm
+(compliant) 39.8504 Tj
+-322 TJm
+(en) 9.40469 Tj
+40 TJm
+(vironment.) 43.4469 Tj
+-1047 TJm
+(Building) 34.8791 Tj
+-321 TJm
+(the) 12.1743 Tj
+-321 TJm
+(program) 33.7533 Tj
+-322 TJm
+(itself) 19.9252 Tj
+-321 TJm
+(lik) 10.5205 Tj
+10 TJm
+(e) 4.42339 Tj
+-321 TJm
+(this) 14.396 Tj
+-321 TJm
+(is) 6.64505 Tj
+-321 TJm
+(dangerous) 40.9463 Tj
+-322 TJm
+(and) 14.386 Tj
+72 344.525 Td
+(not) 12.7322 Tj
+-260 TJm
+(supported,) 41.7831 Tj
+-263 TJm
+(since) 20.4731 Tj
+-260 TJm
+(you) 14.9439 Tj
+-260 TJm
+(remo) 20.4731 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+[1 0 0 1 204.498 344.525] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -204.498 -344.525] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+204.498 344.525 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 234.386 344.525] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -234.386 -344.525] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+234.386 344.525 Td
+/F130_0 9.9626 Tf
+(') 3.31755 Tj
+55 TJm
+(s) 3.87545 Tj
+-260 TJm
+(checks) 27.1082 Tj
+-260 TJm
+(ag) 9.40469 Tj
+5 TJm
+(ainst) 18.8194 Tj
+-261 TJm
+(compressi) 40.3983 Tj
+1 TJm
+(ng) 9.9626 Tj
+-261 TJm
+(directories,) 44.5428 Tj
+-262 TJm
+(symbolic) 36.5329 Tj
+-261 TJm
+(links,) 21.8679 Tj
+-262 TJm
+(de) 9.40469 Tj
+25 TJm
+(vices,) 22.9638 Tj
+-263 TJm
+(and) 14.386 Tj
+-260 TJm
+(other) 20.4731 Tj
+72 332.57 Td
+(not-really-a-\002le) 62.5253 Tj
+-250 TJm
+(entities.) 31.2726 Tj
+-620 TJm
+(This) 17.7135 Tj
+-250 TJm
+(could) 22.1369 Tj
+-250 TJm
+(cause) 22.1269 Tj
+-250 TJm
+(\002lesystem) 40.4083 Tj
+-250 TJm
+(corruption!) 44.8217 Tj
+[1 0 0 1 72 330.413] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -320.45] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 310.652 Td
+/F130_0 9.9626 Tf
+(One) 16.5977 Tj
+-392 TJm
+(other) 20.4731 Tj
+-391 TJm
+(thing:) 23.2527 Tj
+-594 TJm
+(if) 6.08715 Tj
+-391 TJm
+(you) 14.9439 Tj
+-392 TJm
+(create) 23.7807 Tj
+-391 TJm
+(a) 4.42339 Tj
+[1 0 0 1 210.879 310.652] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.879 -310.652] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+210.879 310.652 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 240.767 310.652] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -240.767 -310.652] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+244.669 310.652 Td
+/F130_0 9.9626 Tf
+(binary) 25.4544 Tj
+-392 TJm
+(for) 11.6164 Tj
+-391 TJm
+(public) 24.9065 Tj
+-392 TJm
+(distrib) 25.4644 Tj
+20 TJm
+(ution,) 22.9738 Tj
+-427 TJm
+(please) 24.8965 Tj
+-392 TJm
+(consider) 33.7533 Tj
+-391 TJm
+(linking) 28.234 Tj
+-392 TJm
+(it) 5.53921 Tj
+-391 TJm
+(statically) 35.9749 Tj
+-392 TJm
+(\() 3.31755 Tj
+[1 0 0 1 522.067 310.652] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -522.067 -310.652] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+522.067 310.652 Td
+/F134_0 9.9626 Tf
+(gcc) 17.9327 Tj
+72 298.697 Td
+(-static) 41.8429 Tj
+[1 0 0 1 113.843 298.697] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -113.843 -298.697] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+113.843 298.697 Td
+/F130_0 9.9626 Tf
+(\).) 5.8082 Tj
+-620 TJm
+(This) 17.7135 Tj
+-250 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+20 TJm
+(oids) 16.6077 Tj
+-250 TJm
+(all) 9.9626 Tj
+-250 TJm
+(sorts) 18.8194 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(library-v) 34.8591 Tj
+15 TJm
+(ersion) 24.3486 Tj
+-250 TJm
+(issues) 23.8007 Tj
+-250 TJm
+(that) 14.9439 Tj
+-250 TJm
+(others) 24.3486 Tj
+-250 TJm
+(may) 17.1556 Tj
+-250 TJm
+(encounter) 39.2825 Tj
+-250 TJm
+(later) 17.7035 Tj
+-250 TJm
+(on.) 12.4533 Tj
+[1 0 0 1 72 296.54] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -286.577] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 276.779 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-296 TJm
+(you) 14.9439 Tj
+-296 TJm
+(b) 4.9813 Tj
+20 TJm
+(uild) 15.5018 Tj
+[1 0 0 1 122.709 276.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -122.709 -276.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+122.709 276.779 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 152.596 276.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -152.596 -276.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+155.545 276.779 Td
+/F130_0 9.9626 Tf
+(on) 9.9626 Tj
+-296 TJm
+(W) 9.40469 Tj
+40 TJm
+(in32,) 20.2042 Tj
+-307 TJm
+(you) 14.9439 Tj
+-296 TJm
+(must) 19.3773 Tj
+-296 TJm
+(set) 11.0684 Tj
+[1 0 0 1 254.965 276.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -254.965 -276.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+254.965 276.779 Td
+/F134_0 9.9626 Tf
+(BZ_UNIX) 41.8429 Tj
+[1 0 0 1 296.808 276.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -296.808 -276.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+299.756 276.779 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-296 TJm
+(0) 4.9813 Tj
+-296 TJm
+(and) 14.386 Tj
+[1 0 0 1 335.72 276.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -335.72 -276.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+335.72 276.779 Td
+/F134_0 9.9626 Tf
+(BZ_LCCWIN32) 65.7532 Tj
+[1 0 0 1 401.473 276.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -401.473 -276.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+404.422 276.779 Td
+/F130_0 9.9626 Tf
+(to) 7.7509 Tj
+-296 TJm
+(1,) 7.47195 Tj
+-307 TJm
+(in) 7.7509 Tj
+-296 TJm
+(the) 12.1743 Tj
+-296 TJm
+(\002le) 12.7322 Tj
+[1 0 0 1 467.159 276.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -467.159 -276.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+467.159 276.779 Td
+/F134_0 9.9626 Tf
+(bzip2.c) 41.8429 Tj
+[1 0 0 1 509.002 276.779] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -509.002 -276.779] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+509.002 276.779 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-307 TJm
+(before) 25.4445 Tj
+72 264.824 Td
+(compiling.) 42.899 Tj
+-310 TJm
+(Otherwise) 40.9463 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(resulting) 34.8691 Tj
+-250 TJm
+(binary) 25.4544 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(on') 13.2801 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ork) 13.2801 Tj
+-250 TJm
+(correctly) 35.4071 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 262.667] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -252.704] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 230.071 Td
+/F122_0 20.6585 Tf
+(4.3.) 34.4584 Tj
+-278 TJm
+(Repor) 59.6824 Tj
+-20 TJm
+(ting) 37.867 Tj
+-278 TJm
+(b) 12.6223 Tj
+20 TJm
+(ugs) 36.7308 Tj
+[1 0 0 1 72 225.474] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -215.512] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 208.153 Td
+/F130_0 9.9626 Tf
+(I) 3.31755 Tj
+-228 TJm
+(tried) 18.2614 Tj
+-228 TJm
+(pretty) 23.2427 Tj
+-228 TJm
+(hard) 17.7035 Tj
+-228 TJm
+(to) 7.7509 Tj
+-228 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-228 TJm
+(sure) 16.5977 Tj
+[1 0 0 1 196.25 208.153] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -196.25 -208.153] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+196.25 208.153 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 226.138 208.153] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -226.138 -208.153] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+228.409 208.153 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-228 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug) 9.9626 Tj
+-228 TJm
+(free,) 17.9725 Tj
+-232 TJm
+(both) 17.7135 Tj
+-228 TJm
+(by) 9.9626 Tj
+-228 TJm
+(design) 26.0123 Tj
+-228 TJm
+(and) 14.386 Tj
+-228 TJm
+(by) 9.9626 Tj
+-228 TJm
+(testing.) 29.0609 Tj
+-605 TJm
+(Hopefully) 40.3983 Tj
+-228 TJm
+(you') 18.2614 Tj
+10 TJm
+(ll) 5.53921 Tj
+-228 TJm
+(ne) 9.40469 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+-228 TJm
+(need) 18.8094 Tj
+-228 TJm
+(to) 7.7509 Tj
+-228 TJm
+(read) 17.1456 Tj
+72 196.198 Td
+(this) 14.396 Tj
+-250 TJm
+(section) 28.224 Tj
+-250 TJm
+(for) 11.6164 Tj
+-250 TJm
+(real.) 17.4246 Tj
+[1 0 0 1 72 196.098] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -186.136] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 174.28 Td
+/F130_0 9.9626 Tf
+(Ne) 11.6164 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ertheless,) 37.3498 Tj
+-313 TJm
+(if) 6.08715 Tj
+[1 0 0 1 137.751 174.28] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -137.751 -174.28] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+137.751 174.28 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 167.639 174.28] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -167.639 -174.28] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+170.634 174.28 Td
+/F130_0 9.9626 Tf
+(dies) 16.0497 Tj
+-301 TJm
+(with) 17.7135 Tj
+-300 TJm
+(a) 4.42339 Tj
+-301 TJm
+(se) 8.29885 Tj
+15 TJm
+(gmentation) 44.8317 Tj
+-300 TJm
+(f) 3.31755 Tj
+10 TJm
+(ault,) 17.4346 Tj
+-314 TJm
+(a) 4.42339 Tj
+-300 TJm
+(b) 4.9813 Tj
+20 TJm
+(us) 8.85675 Tj
+-301 TJm
+(error) 19.3573 Tj
+-300 TJm
+(or) 8.29885 Tj
+-301 TJm
+(an) 9.40469 Tj
+-301 TJm
+(internal) 30.4357 Tj
+-300 TJm
+(assertion) 35.417 Tj
+-301 TJm
+(f) 3.31755 Tj
+10 TJm
+(ailure,) 25.1755 Tj
+-313 TJm
+(it) 5.53921 Tj
+-301 TJm
+(wil) 12.7322 Tj
+1 TJm
+(l) 2.7696 Tj
+-301 TJm
+(ask) 13.2801 Tj
+-301 TJm
+(you) 14.9439 Tj
+-300 TJm
+(to) 7.7509 Tj
+72 162.325 Td
+(email) 22.1369 Tj
+-242 TJm
+(me) 12.1743 Tj
+-243 TJm
+(a) 4.42339 Tj
+-242 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug) 9.9626 Tj
+-243 TJm
+(report.) 26.2813 Tj
+-615 TJm
+(Experience) 44.8118 Tj
+-242 TJm
+(from) 19.3673 Tj
+-243 TJm
+(years) 21.0211 Tj
+-242 TJm
+(of) 8.29885 Tj
+-242 TJm
+(feedback) 35.955 Tj
+-243 TJm
+(of) 8.29885 Tj
+-242 TJm
+(bzip2) 22.1369 Tj
+-243 TJm
+(users) 20.4731 Tj
+-242 TJm
+(indicates) 35.417 Tj
+-243 TJm
+(that) 14.9439 Tj
+-242 TJm
+(almost) 26.5703 Tj
+-242 TJm
+(all) 9.9626 Tj
+-243 TJm
+(these) 20.4731 Tj
+-242 TJm
+(problems) 37.0808 Tj
+-243 TJm
+(can) 13.8281 Tj
+72 150.37 Td
+(be) 9.40469 Tj
+-250 TJm
+(traced) 24.3386 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(either) 22.6848 Tj
+-250 TJm
+(compiler) 35.417 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ugs) 13.8381 Tj
+-250 TJm
+(or) 8.29885 Tj
+-250 TJm
+(hardw) 24.8965 Tj
+10 TJm
+(are) 12.1643 Tj
+-250 TJm
+(problems.) 39.5714 Tj
+[1 0 0 1 72 148.213] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -97.3611] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(32) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 36 36
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 116.328 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -382.4 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+498.728 749.245 Td
+/F130_0 9.9626 Tf
+(Miscellanea) 48.1393 Tj
+[1 0 0 1 266.071 749.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -7.0936] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -31.5168] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 710.037 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 710.037] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -710.037] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 710.037 Td
+/F130_0 9.9626 Tf
+(Recompile) 43.1679 Tj
+-306 TJm
+(the) 12.1743 Tj
+-306 TJm
+(program) 33.7533 Tj
+-306 TJm
+(with) 17.7135 Tj
+-306 TJm
+(no) 9.9626 Tj
+-306 TJm
+(optimisation,) 52.3136 Tj
+-320 TJm
+(and) 14.386 Tj
+-306 TJm
+(see) 12.7222 Tj
+-306 TJm
+(if) 6.08715 Tj
+-306 TJm
+(it) 5.53921 Tj
+-306 TJm
+(w) 7.193 Tj
+10 TJm
+(orks.) 19.6462 Tj
+-956 TJm
+(And/or) 28.224 Tj
+-306 TJm
+(try) 11.0684 Tj
+-306 TJm
+(a) 4.42339 Tj
+-306 TJm
+(dif) 11.0684 Tj
+25 TJm
+(ferent) 23.2328 Tj
+-306 TJm
+(compiler) 35.417 Tj
+55 TJm
+(.) 2.49065 Tj
+-956 TJm
+(I) 3.31755 Tj
+-306 TJm
+(heard) 22.1269 Tj
+-306 TJm
+(all) 9.9626 Tj
+86.944 698.082 Td
+(sorts) 18.8194 Tj
+-282 TJm
+(of) 8.29885 Tj
+-282 TJm
+(stories) 26.0123 Tj
+-282 TJm
+(about) 22.1369 Tj
+-283 TJm
+(v) 4.9813 Tj
+25 TJm
+(arious) 24.3486 Tj
+-282 TJm
+(\003a) 9.9626 Tj
+20 TJm
+(v) 4.9813 Tj
+20 TJm
+(ours) 17.1556 Tj
+-282 TJm
+(of) 8.29885 Tj
+-282 TJm
+(GNU) 21.579 Tj
+-282 TJm
+(C) 6.64505 Tj
+-282 TJm
+(\(and) 17.7035 Tj
+-282 TJm
+(other) 20.4731 Tj
+-283 TJm
+(compilers\)) 42.61 Tj
+-282 TJm
+(generating) 42.0521 Tj
+-282 TJm
+(bad) 14.386 Tj
+-282 TJm
+(code) 18.8094 Tj
+-282 TJm
+(for) 11.6164 Tj
+[1 0 0 1 472.141 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.141 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+472.141 698.082 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 502.029 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -502.029 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+502.029 698.082 Td
+/F130_0 9.9626 Tf
+(,) 2.49065 Tj
+-290 TJm
+(and) 14.386 Tj
+-282 TJm
+(I') 6.63509 Tj
+50 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+86.944 686.127 Td
+(run) 13.2801 Tj
+-250 TJm
+(across) 24.8965 Tj
+-250 TJm
+(tw) 9.9626 Tj
+10 TJm
+(o) 4.9813 Tj
+-250 TJm
+(such) 18.2614 Tj
+-250 TJm
+(e) 4.42339 Tj
+15 TJm
+(xamples) 33.2053 Tj
+-250 TJm
+(myself.) 29.6088 Tj
+[1 0 0 1 237.767 686.127] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -165.767 -12.1195] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -674.007] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 664.209 Td
+/F130_0 9.9626 Tf
+(2.7.X) 22.1369 Tj
+-280 TJm
+(v) 4.9813 Tj
+15 TJm
+(ersions) 28.224 Tj
+-279 TJm
+(of) 8.29885 Tj
+-280 TJm
+(GNU) 21.579 Tj
+-279 TJm
+(C) 6.64505 Tj
+-280 TJm
+(are) 12.1643 Tj
+-279 TJm
+(kno) 14.9439 Tj
+25 TJm
+(wn) 12.1743 Tj
+-280 TJm
+(to) 7.7509 Tj
+-280 TJm
+(generate) 33.7433 Tj
+-279 TJm
+(bad) 14.386 Tj
+-280 TJm
+(code) 18.8094 Tj
+-279 TJm
+(from) 19.3673 Tj
+-280 TJm
+(time) 17.7135 Tj
+-279 TJm
+(to) 7.7509 Tj
+-280 TJm
+(time,) 20.2042 Tj
+-287 TJm
+(at) 7.193 Tj
+-280 TJm
+(high) 17.7135 Tj
+-279 TJm
+(optimisation) 49.823 Tj
+-280 TJm
+(le) 7.193 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(els.) 13.5591 Tj
+-797 TJm
+(If) 6.63509 Tj
+-280 TJm
+(you) 14.9439 Tj
+86.944 652.254 Td
+(get) 12.1743 Tj
+-295 TJm
+(problems,) 39.5714 Tj
+-307 TJm
+(try) 11.0684 Tj
+-296 TJm
+(using) 21.589 Tj
+-295 TJm
+(the) 12.1743 Tj
+-296 TJm
+(\003ags) 18.8194 Tj
+[1 0 0 1 220.116 652.254] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -220.116 -652.254] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+220.116 652.254 Td
+/F134_0 9.9626 Tf
+(-O2) 17.9327 Tj
+[1 0 0 1 238.049 652.254] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.9438 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -240.993 -652.254] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+240.993 652.254 Td
+/F134_0 9.9626 Tf
+(-fomit-frame-pointer) 119.551 Tj
+[1 0 0 1 360.544 652.254] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.9438 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -363.488 -652.254] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+363.488 652.254 Td
+/F134_0 9.9626 Tf
+(-fno-strength-reduce) 119.551 Tj
+[1 0 0 1 483.04 652.254] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -483.04 -652.254] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+483.04 652.254 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-893 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-295 TJm
+(should) 26.5703 Tj
+86.944 640.299 Td
+(speci\002cally) 45.3796 Tj
+[1 0 0 1 134.814 640.299] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -134.814 -640.299] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+134.814 640.299 Td
+/F637_0 9.9626 Tf
+(not) 12.7322 Tj
+[1 0 0 1 147.546 640.299] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -147.546 -640.299] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+150.036 640.299 Td
+/F130_0 9.9626 Tf
+(use) 13.2801 Tj
+[1 0 0 1 165.807 640.299] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -165.807 -640.299] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+165.807 640.299 Td
+/F134_0 9.9626 Tf
+(-funroll-loops) 83.6858 Tj
+[1 0 0 1 249.493 640.299] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -249.493 -640.299] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+249.493 640.299 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+[1 0 0 1 72 638.142] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -628.179] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 618.381 Td
+/F130_0 9.9626 Tf
+(Y) 7.193 Tj
+110 TJm
+(ou) 9.9626 Tj
+-249 TJm
+(may) 17.1556 Tj
+-249 TJm
+(notice) 24.3486 Tj
+-248 TJm
+(that) 14.9439 Tj
+-249 TJm
+(the) 12.1743 Tj
+-249 TJm
+(Mak) 18.2614 Tj
+10 TJm
+(e\002le) 17.1556 Tj
+-249 TJm
+(runs) 17.1556 Tj
+-248 TJm
+(six) 11.6264 Tj
+-249 TJm
+(tests) 17.7135 Tj
+-249 TJm
+(as) 8.29885 Tj
+-249 TJm
+(part) 15.4918 Tj
+-249 TJm
+(of) 8.29885 Tj
+-248 TJm
+(the) 12.1743 Tj
+-249 TJm
+(b) 4.9813 Tj
+20 TJm
+(uild) 15.5018 Tj
+-249 TJm
+(process.) 32.3685 Tj
+-619 TJm
+(If) 6.63509 Tj
+-249 TJm
+(the) 12.1743 Tj
+-249 TJm
+(program) 33.7533 Tj
+-248 TJm
+(passes) 25.4544 Tj
+-249 TJm
+(all) 9.9626 Tj
+-249 TJm
+(of) 8.29885 Tj
+-249 TJm
+(these,) 22.9638 Tj
+-249 TJm
+(it') 8.85675 Tj
+55 TJm
+(s) 3.87545 Tj
+86.944 606.426 Td
+(a) 4.42339 Tj
+-250 TJm
+(pretty) 23.2427 Tj
+-250 TJm
+(good) 19.9252 Tj
+-250 TJm
+(\(b) 8.29885 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(not) 12.7322 Tj
+-250 TJm
+(100%\)) 26.5603 Tj
+-250 TJm
+(indication) 39.8504 Tj
+-250 TJm
+(that) 14.9439 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(compiler) 35.417 Tj
+-250 TJm
+(has) 13.2801 Tj
+-250 TJm
+(done) 19.3673 Tj
+-250 TJm
+(its) 9.41466 Tj
+-250 TJm
+(job) 12.7322 Tj
+-250 TJm
+(correctly) 35.4071 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 604.269] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -19.761] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -584.508] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 584.508 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 584.508] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -584.508] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 584.508 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+[1 0 0 1 95.9558 584.508] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -95.9558 -584.508] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+95.9558 584.508 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 125.844 584.508] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -125.844 -584.508] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+128.22 584.508 Td
+/F130_0 9.9626 Tf
+(crashes) 29.3199 Tj
+-239 TJm
+(randomly) 38.1866 Tj
+65 TJm
+(,) 2.49065 Tj
+-240 TJm
+(and) 14.386 Tj
+-239 TJm
+(the) 12.1743 Tj
+-239 TJm
+(crashe) 25.4445 Tj
+1 TJm
+(s) 3.87545 Tj
+-239 TJm
+(are) 12.1643 Tj
+-239 TJm
+(not) 12.7322 Tj
+-238 TJm
+(repeatable,) 43.427 Tj
+-241 TJm
+(you) 14.9439 Tj
+-239 TJm
+(may) 17.1556 Tj
+-238 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-239 TJm
+(a) 4.42339 Tj
+-238 TJm
+(\003ak) 14.9439 Tj
+15 TJm
+(y) 4.9813 Tj
+-239 TJm
+(memory) 33.2053 Tj
+-238 TJm
+(subsystem.) 44.0048 Tj
+[1 0 0 1 510.112 584.508] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -510.112 -584.508] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+510.112 584.508 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 540 584.508] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -584.508] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 572.553 Td
+/F130_0 9.9626 Tf
+(really) 22.6848 Tj
+-254 TJm
+(hammers) 36.5229 Tj
+-253 TJm
+(your) 18.2614 Tj
+-254 TJm
+(memory) 33.2053 Tj
+-253 TJm
+(hierarch) 32.6375 Tj
+5 TJm
+(y) 4.9813 Tj
+65 TJm
+(,) 2.49065 Tj
+-255 TJm
+(and) 14.386 Tj
+-253 TJm
+(if) 6.08715 Tj
+-254 TJm
+(it') 8.85675 Tj
+55 TJm
+(s) 3.87545 Tj
+-254 TJm
+(a) 4.42339 Tj
+-253 TJm
+(bit) 10.5205 Tj
+-254 TJm
+(mar) 15.4918 Tj
+18 TJm
+(ginal,) 22.4159 Tj
+-254 TJm
+(you) 14.9439 Tj
+-254 TJm
+(may) 17.1556 Tj
+-253 TJm
+(get) 12.1743 Tj
+-254 TJm
+(these) 20.4731 Tj
+-253 TJm
+(problems.) 39.5714 Tj
+-642 TJm
+(Ditto) 20.4831 Tj
+-254 TJm
+(if) 6.08715 Tj
+-253 TJm
+(your) 18.2614 Tj
+-254 TJm
+(disk) 16.6077 Tj
+86.944 560.598 Td
+(or) 8.29885 Tj
+-250 TJm
+(I/O) 13.2801 Tj
+-250 TJm
+(subsystem) 41.5142 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(slo) 11.6264 Tj
+25 TJm
+(wly) 14.9439 Tj
+-250 TJm
+(f) 3.31755 Tj
+10 TJm
+(ailing.) 25.1855 Tj
+-620 TJm
+(Y) 7.193 Tj
+111 TJm
+(up,) 12.4533 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(really) 22.6848 Tj
+-250 TJm
+(does) 18.2614 Tj
+-250 TJm
+(happen.) 31.2626 Tj
+[1 0 0 1 345.143 560.598] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -273.143 -12.1195] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -548.478] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 538.68 Td
+/F130_0 9.9626 Tf
+(T) 6.08715 Tj
+35 TJm
+(ry) 8.29885 Tj
+-250 TJm
+(using) 21.589 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(dif) 11.0684 Tj
+25 TJm
+(ferent) 23.2328 Tj
+-250 TJm
+(machine) 33.7533 Tj
+-250 TJm
+(of) 8.29885 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(same) 20.4731 Tj
+-250 TJm
+(type,) 19.6462 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(see) 12.7222 Tj
+-250 TJm
+(if) 6.08715 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(can) 13.8281 Tj
+-250 TJm
+(repeat) 24.3386 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(problem.) 35.696 Tj
+[1 0 0 1 72 536.523] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -19.761] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.9739 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -78.9739 -516.762] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+78.9739 516.762 Td
+/F130_0 9.9626 Tf
+(\225) 3.48691 Tj
+[1 0 0 1 82.4608 516.762] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 1.9925 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -86.944 -516.762] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+86.944 516.762 Td
+/F130_0 9.9626 Tf
+(This) 17.7135 Tj
+-229 TJm
+(isn') 14.9439 Tj
+18 TJm
+(t) 2.7696 Tj
+-230 TJm
+(really) 22.6848 Tj
+-229 TJm
+(a) 4.42339 Tj
+-229 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug,) 12.4533 Tj
+-234 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-229 TJm
+(...) 7.47195 Tj
+-303 TJm
+(If) 6.63509 Tj
+[1 0 0 1 212.232 516.762] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -212.232 -516.762] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+212.232 516.762 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 242.12 516.762] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -242.12 -516.762] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+244.405 516.762 Td
+/F130_0 9.9626 Tf
+(tells) 16.6077 Tj
+-229 TJm
+(you) 14.9439 Tj
+-230 TJm
+(your) 18.2614 Tj
+-229 TJm
+(\002le) 12.7322 Tj
+-229 TJm
+(is) 6.64505 Tj
+-230 TJm
+(corrupted) 38.1767 Tj
+-229 TJm
+(on) 9.9626 Tj
+-230 TJm
+(decompression,) 62.2563 Tj
+-233 TJm
+(and) 14.386 Tj
+-229 TJm
+(you) 14.9439 Tj
+-230 TJm
+(obtained) 34.3112 Tj
+-229 TJm
+(the) 12.1743 Tj
+-229 TJm
+(\002le) 12.7322 Tj
+86.944 504.807 Td
+(via) 12.1743 Tj
+-262 TJm
+(FTP) 17.1656 Tj
+111 TJm
+(,) 2.49065 Tj
+-263 TJm
+(there) 19.9152 Tj
+-262 TJm
+(is) 6.64505 Tj
+-262 TJm
+(a) 4.42339 Tj
+-262 TJm
+(possibility) 41.5241 Tj
+-263 TJm
+(that) 14.9439 Tj
+-262 TJm
+(you) 14.9439 Tj
+-262 TJm
+(for) 11.6164 Tj
+18 TJm
+(got) 12.7322 Tj
+-263 TJm
+(to) 7.7509 Tj
+-262 TJm
+(tell) 12.7322 Tj
+-262 TJm
+(FTP) 17.1656 Tj
+-263 TJm
+(to) 7.7509 Tj
+-262 TJm
+(do) 9.9626 Tj
+-262 TJm
+(a) 4.42339 Tj
+-262 TJm
+(binary) 25.4544 Tj
+-263 TJm
+(mode) 22.1369 Tj
+-262 TJm
+(transfer) 30.4258 Tj
+55 TJm
+(.) 2.49065 Tj
+-694 TJm
+(That) 18.2614 Tj
+-262 TJm
+(absolutely) 40.9562 Tj
+-262 TJm
+(will) 15.5018 Tj
+-263 TJm
+(cause) 22.1269 Tj
+86.944 492.852 Td
+(the) 12.1743 Tj
+-250 TJm
+(\002le) 12.7322 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(be) 9.40469 Tj
+-250 TJm
+(non-decompressible.) 82.7294 Tj
+-620 TJm
+(Y) 7.193 Tj
+110 TJm
+(ou') 13.2801 Tj
+10 TJm
+(ll) 5.53921 Tj
+-250 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(transfer) 30.4258 Tj
+-250 TJm
+(it) 5.53921 Tj
+-250 TJm
+(ag) 9.40469 Tj
+5 TJm
+(ain.) 14.6649 Tj
+[1 0 0 1 351.34 492.852] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -279.34 -12.1195] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -480.732] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 470.934 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-235 TJm
+(you') 18.2614 Tj
+50 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-236 TJm
+(incor) 20.4731 Tj
+1 TJm
+(p) 4.9813 Tj
+-1 TJm
+(or) 8.29885 Tj
+1 TJm
+(ated) 16.5977 Tj
+[1 0 0 1 163.036 470.934] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -163.036 -470.934] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+163.036 470.934 Td
+/F134_0 9.9626 Tf
+(libbzip2) 47.8205 Tj
+[1 0 0 1 210.856 470.934] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -210.856 -470.934] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+213.2 470.934 Td
+/F130_0 9.9626 Tf
+(into) 15.5018 Tj
+-235 TJm
+(your) 18.2614 Tj
+-235 TJm
+(o) 4.9813 Tj
+25 TJm
+(wn) 12.1743 Tj
+-236 TJm
+(program) 33.7533 Tj
+-235 TJm
+(and) 14.386 Tj
+-235 TJm
+(are) 12.1643 Tj
+-236 TJm
+(get) 12.1743 Tj
+1 TJm
+(ting) 15.5018 Tj
+-236 TJm
+(problems,) 39.5714 Tj
+-238 TJm
+(please,) 27.3872 Tj
+-238 TJm
+(please,) 27.3872 Tj
+-238 TJm
+(please,) 27.3872 Tj
+-238 TJm
+(check) 23.2328 Tj
+-236 TJm
+(that) 14.9439 Tj
+72 458.979 Td
+(the) 12.1743 Tj
+-242 TJm
+(parameters) 43.7059 Tj
+-243 TJm
+(you) 14.9439 Tj
+-242 TJm
+(are) 12.1643 Tj
+-242 TJm
+(passing) 29.8878 Tj
+-243 TJm
+(in) 7.7509 Tj
+-242 TJm
+(calls) 18.2614 Tj
+-242 TJm
+(to) 7.7509 Tj
+-243 TJm
+(the) 12.1743 Tj
+-242 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-244 TJm
+(are) 12.1643 Tj
+-242 TJm
+(correct,) 30.1468 Tj
+-244 TJm
+(and) 14.386 Tj
+-243 TJm
+(in) 7.7509 Tj
+-242 TJm
+(accordance) 44.8018 Tj
+-242 TJm
+(with) 17.7135 Tj
+-243 TJm
+(what) 19.3673 Tj
+-242 TJm
+(the) 12.1743 Tj
+-242 TJm
+(documentation) 59.2177 Tj
+-243 TJm
+(says) 17.1556 Tj
+72 447.024 Td
+(is) 6.64505 Tj
+-250 TJm
+(allo) 14.9439 Tj
+25 TJm
+(w) 7.193 Tj
+10 TJm
+(able.) 19.0883 Tj
+-310 TJm
+(I) 3.31755 Tj
+-250 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(tried) 18.2614 Tj
+-250 TJm
+(to) 7.7509 Tj
+-250 TJm
+(mak) 17.1556 Tj
+10 TJm
+(e) 4.42339 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(library) 26.5603 Tj
+-250 TJm
+(rob) 13.2801 Tj
+20 TJm
+(ust) 11.6264 Tj
+-250 TJm
+(ag) 9.40469 Tj
+5 TJm
+(ainst) 18.8194 Tj
+-250 TJm
+(such) 18.2614 Tj
+-250 TJm
+(problems,) 39.5714 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-250 TJm
+(I'm) 14.386 Tj
+-250 TJm
+(sure) 16.5977 Tj
+-250 TJm
+(I) 3.31755 Tj
+-250 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(en') 12.7222 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(succeeded.) 43.427 Tj
+[1 0 0 1 72 444.867] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -434.904] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 425.106 Td
+/F130_0 9.9626 Tf
+(Finally) 28.234 Tj
+65 TJm
+(,) 2.49065 Tj
+-324 TJm
+(if) 6.08715 Tj
+-310 TJm
+(the) 12.1743 Tj
+-309 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-309 TJm
+(comments) 40.9562 Tj
+-310 TJm
+(don') 18.2614 Tj
+18 TJm
+(t) 2.7696 Tj
+-309 TJm
+(help,) 19.6462 Tj
+-324 TJm
+(you') 18.2614 Tj
+10 TJm
+(ll) 5.53921 Tj
+-310 TJm
+(ha) 9.40469 Tj
+20 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-309 TJm
+(to) 7.7509 Tj
+-309 TJm
+(send) 18.2614 Tj
+-310 TJm
+(me) 12.1743 Tj
+-309 TJm
+(a) 4.42339 Tj
+-309 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug) 9.9626 Tj
+-310 TJm
+(report.) 26.2813 Tj
+-976 TJm
+(No) 12.1743 Tj
+25 TJm
+(w) 7.193 Tj
+65 TJm
+(,) 2.49065 Tj
+-324 TJm
+(it') 8.85675 Tj
+55 TJm
+(s) 3.87545 Tj
+-310 TJm
+(just) 14.396 Tj
+-309 TJm
+(amazing) 33.7533 Tj
+-309 TJm
+(ho) 9.9626 Tj
+25 TJm
+(w) 7.193 Tj
+-310 TJm
+(man) 17.1556 Tj
+15 TJm
+(y) 4.9813 Tj
+72 413.151 Td
+(people) 26.5603 Tj
+-250 TJm
+(will) 15.5018 Tj
+-250 TJm
+(send) 18.2614 Tj
+-250 TJm
+(me) 12.1743 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(b) 4.9813 Tj
+20 TJm
+(ug) 9.9626 Tj
+-250 TJm
+(report) 23.7907 Tj
+-250 TJm
+(saying) 26.0123 Tj
+-250 TJm
+(something) 41.5142 Tj
+-250 TJm
+(lik) 10.5205 Tj
+10 TJm
+(e:) 7.193 Tj
+[1 0 0 1 72 410.994] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -24.9066] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 23.9103 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 20.3237] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -401.629] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 401.629 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+-426 TJm
+(crashed) 41.8429 Tj
+-426 TJm
+(with) 23.9102 Tj
+-426 TJm
+(segmentation) 71.7307 Tj
+-426 TJm
+(fault) 29.8878 Tj
+-426 TJm
+(on) 11.9551 Tj
+-426 TJm
+(my) 11.9551 Tj
+-426 TJm
+(machine) 41.8429 Tj
+[1 0 0 1 72 386.087] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -376.125] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 364.169 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+-241 TJm
+(absolutely) 40.9562 Tj
+-241 TJm
+(nothing) 30.4457 Tj
+-241 TJm
+(el) 7.193 Tj
+1 TJm
+(se.) 10.7895 Tj
+-614 TJm
+(Needless) 35.965 Tj
+-241 TJm
+(to) 7.7509 Tj
+-241 TJm
+(say) 13.2801 Tj
+65 TJm
+(,) 2.49065 Tj
+-243 TJm
+(a) 4.42339 Tj
+-241 TJm
+(such) 18.2614 Tj
+-240 TJm
+(a) 4.42339 Tj
+-241 TJm
+(report) 23.7907 Tj
+-241 TJm
+(is) 6.64505 Tj
+[1 0 0 1 324.681 364.169] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -324.681 -364.169] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+324.681 364.169 Td
+/F637_0 9.9626 Tf
+(totally) 25.4644 Tj
+55 TJm
+(,) 2.49065 Tj
+-243 TJm
+(utterly) 26.0123 Tj
+55 TJm
+(,) 2.49065 Tj
+-242 TJm
+(completely) 43.158 Tj
+-241 TJm
+(and) 14.9439 Tj
+-241 TJm
+(compr) 25.4544 Tj
+37 TJm
+(ehensively) 41.4942 Tj
+-241 TJm
+(100%) 23.2427 Tj
+72 352.214 Td
+(useless;) 31.5416 Tj
+-257 TJm
+(a) 4.9813 Tj
+-255 TJm
+(waste) 22.6948 Tj
+-255 TJm
+(of) 7.7509 Tj
+-255 TJm
+(your) 18.2614 Tj
+-255 TJm
+(time) 17.1556 Tj
+10 TJm
+(,) 2.49065 Tj
+-256 TJm
+(my) 11.6164 Tj
+-255 TJm
+(time) 17.1556 Tj
+10 TJm
+(,) 2.49065 Tj
+-256 TJm
+(and) 14.9439 Tj
+-255 TJm
+(net) 12.1743 Tj
+-255 TJm
+(bandwidth) 42.0721 Tj
+[1 0 0 1 302.574 352.214] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -302.574 -352.214] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+302.574 352.214 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-650 TJm
+(W) 9.40469 Tj
+40 TJm
+(ith) 10.5205 Tj
+-254 TJm
+(no) 9.9626 Tj
+-255 TJm
+(details) 26.0123 Tj
+-255 TJm
+(at) 7.193 Tj
+-255 TJm
+(all,) 12.4533 Tj
+-256 TJm
+(there') 23.2328 Tj
+55 TJm
+(s) 3.87545 Tj
+-255 TJm
+(no) 9.9626 Tj
+-255 TJm
+(w) 7.193 Tj
+10 TJm
+(ay) 9.40469 Tj
+-255 TJm
+(I) 3.31755 Tj
+-255 TJm
+(can) 13.8281 Tj
+-255 TJm
+(possibly) 33.2153 Tj
+-255 TJm
+(be) 9.40469 Tj
+15 TJm
+(gin) 12.7322 Tj
+72 340.259 Td
+(to) 7.7509 Tj
+-250 TJm
+(\002gure) 23.2427 Tj
+-250 TJm
+(out) 12.7322 Tj
+-250 TJm
+(what) 19.3673 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(problem) 33.2053 Tj
+-250 TJm
+(is.) 9.1357 Tj
+[1 0 0 1 72 338.102] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -328.14] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 318.341 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-309 TJm
+(rules) 19.3673 Tj
+-309 TJm
+(of) 8.29885 Tj
+-309 TJm
+(the) 12.1743 Tj
+-310 TJm
+(g) 4.9813 Tj
+5 TJm
+(ame) 16.5977 Tj
+-309 TJm
+(are:) 14.9339 Tj
+-428 TJm
+(f) 3.31755 Tj
+10 TJm
+(acts,) 17.9825 Tj
+-324 TJm
+(f) 3.31755 Tj
+10 TJm
+(acts,) 17.9825 Tj
+-324 TJm
+(f) 3.31755 Tj
+10 TJm
+(acts.) 17.9825 Tj
+-975 TJm
+(Don') 20.4731 Tj
+18 TJm
+(t) 2.7696 Tj
+-309 TJm
+(omit) 18.2714 Tj
+-309 TJm
+(them) 19.9252 Tj
+-309 TJm
+(because) 31.5316 Tj
+-309 TJm
+("oh,) 16.518 Tj
+-324 TJm
+(the) 12.1743 Tj
+15 TJm
+(y) 4.9813 Tj
+-309 TJm
+(w) 7.193 Tj
+10 TJm
+(on') 13.2801 Tj
+18 TJm
+(t) 2.7696 Tj
+-309 TJm
+(be) 9.40469 Tj
+-310 TJm
+(rele) 14.9339 Tj
+25 TJm
+(v) 4.9813 Tj
+25 TJm
+(ant".) 18.7297 Tj
+-974 TJm
+(At) 9.9626 Tj
+-310 TJm
+(the) 12.1743 Tj
+-309 TJm
+(bare) 17.1456 Tj
+72 306.386 Td
+(minimum:) 41.5241 Tj
+[1 0 0 1 72 306.287] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -60.7721] cm
+/DeviceRGB {} cs
+[0.94899 0.94899 0.976456] sc
+/DeviceRGB {} CS
+[0.94899 0.94899 0.976456] SC
+0 0 468 59.7758 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 56.1892] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -296.922] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 296.922 Td
+/F134_0 9.9626 Tf
+(Machine) 41.8429 Tj
+-426 TJm
+(type.) 29.8878 Tj
+-852 TJm
+(Operating) 53.798 Tj
+-426 TJm
+(system) 35.8654 Tj
+-426 TJm
+(version.) 47.8205 Tj
+90 284.967 Td
+(Exact) 29.8878 Tj
+-426 TJm
+(version) 41.8429 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(bzip2) 29.8878 Tj
+-426 TJm
+(\(do) 17.9327 Tj
+-426 TJm
+(bzip2) 29.8878 Tj
+-426 TJm
+(-V\).) 23.9102 Tj
+90 273.011 Td
+(Exact) 29.8878 Tj
+-426 TJm
+(version) 41.8429 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compiler) 47.8205 Tj
+-426 TJm
+(used.) 29.8878 Tj
+90 261.056 Td
+(Flags) 29.8878 Tj
+-426 TJm
+(passed) 35.8654 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(compiler.) 53.798 Tj
+[1 0 0 1 72 245.514] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -235.552] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 223.597 Td
+/F130_0 9.9626 Tf
+(Ho) 12.1743 Tj
+25 TJm
+(we) 11.6164 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(er) 7.74094 Tj
+40 TJm
+(,) 2.49065 Tj
+-254 TJm
+(the) 12.1743 Tj
+-252 TJm
+(most) 19.3773 Tj
+-253 TJm
+(important) 38.7446 Tj
+-253 TJm
+(single) 23.8007 Tj
+-253 TJm
+(thing) 20.4831 Tj
+-253 TJm
+(t) 2.7696 Tj
+1 TJm
+(hat) 12.1743 Tj
+-253 TJm
+(will) 15.5018 Tj
+-253 TJm
+(help) 17.1556 Tj
+-253 TJm
+(me) 12.1743 Tj
+-253 TJm
+(is) 6.64505 Tj
+-252 TJm
+(the) 12.1743 Tj
+-253 TJm
+(\002le) 12.7322 Tj
+-253 TJm
+(that) 14.9439 Tj
+-253 TJm
+(you) 14.9439 Tj
+-253 TJm
+(were) 19.3573 Tj
+-253 TJm
+(trying) 23.8007 Tj
+-252 TJm
+(to) 7.7509 Tj
+-253 TJm
+(compress) 37.6287 Tj
+-253 TJm
+(or) 8.29885 Tj
+-253 TJm
+(decompress) 47.0334 Tj
+72 211.641 Td
+(at) 7.193 Tj
+-304 TJm
+(the) 12.1743 Tj
+-305 TJm
+(time) 17.7135 Tj
+-304 TJm
+(the) 12.1743 Tj
+-304 TJm
+(problem) 33.2053 Tj
+-305 TJm
+(happened.) 40.6673 Tj
+-946 TJm
+(W) 9.40469 Tj
+40 TJm
+(ithout) 23.2527 Tj
+-304 TJm
+(that,) 17.4346 Tj
+-318 TJm
+(my) 12.7322 Tj
+-305 TJm
+(ability) 25.4644 Tj
+-304 TJm
+(to) 7.7509 Tj
+-304 TJm
+(do) 9.9626 Tj
+-305 TJm
+(an) 9.40469 Tj
+15 TJm
+(ything) 25.4644 Tj
+-304 TJm
+(more) 20.4731 Tj
+-304 TJm
+(than) 17.1556 Tj
+-305 TJm
+(speculate) 37.0708 Tj
+-304 TJm
+(about) 22.1369 Tj
+-304 TJm
+(the) 12.1743 Tj
+-305 TJm
+(cause,) 24.6176 Tj
+-318 TJm
+(is) 6.64505 Tj
+72 199.686 Td
+(limited.) 30.7247 Tj
+[1 0 0 1 72 199.587] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -189.624] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 164.933 Td
+/F122_0 20.6585 Tf
+(4.4.) 34.4584 Tj
+-278 TJm
+(Did) 33.2808 Tj
+-278 TJm
+(y) 11.4861 Tj
+25 TJm
+(ou) 25.2447 Tj
+-278 TJm
+(g) 12.6223 Tj
+-10 TJm
+(et) 18.3654 Tj
+-278 TJm
+(the) 30.9877 Tj
+-278 TJm
+(right) 45.9032 Tj
+-278 TJm
+(pac) 35.5946 Tj
+20 TJm
+(ka) 22.9723 Tj
+10 TJm
+(g) 12.6223 Tj
+-10 TJm
+(e?) 24.1085 Tj
+[1 0 0 1 72 160.337] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -150.374] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 143.016 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 143.016] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -143.016] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.603 143.016 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-272 TJm
+(a) 4.42339 Tj
+-273 TJm
+(resource) 33.7433 Tj
+-272 TJm
+(hog.) 17.4346 Tj
+-378 TJm
+(It) 6.08715 Tj
+-272 TJm
+(soaks) 22.1369 Tj
+-273 TJm
+(up) 9.9626 Tj
+-272 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ge) 9.40469 Tj
+-273 TJm
+(amounts) 33.7633 Tj
+-272 TJm
+(of) 8.29885 Tj
+-273 TJm
+(CPU) 19.3773 Tj
+-272 TJm
+(c) 4.42339 Tj
+15 TJm
+(ycles) 20.4731 Tj
+-273 TJm
+(and) 14.386 Tj
+-272 TJm
+(memory) 33.2053 Tj
+65 TJm
+(.) 2.49065 Tj
+-755 TJm
+(Also,) 21.31 Tj
+-278 TJm
+(it) 5.53921 Tj
+-273 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+-272 TJm
+(v) 4.9813 Tj
+15 TJm
+(ery) 12.7222 Tj
+-273 TJm
+(lar) 10.5105 Tj
+18 TJm
+(ge) 9.40469 Tj
+-272 TJm
+(latencies.) 37.3498 Tj
+72 131.06 Td
+(In) 8.29885 Tj
+-251 TJm
+(the) 12.1743 Tj
+-251 TJm
+(w) 7.193 Tj
+10 TJm
+(orst) 14.9439 Tj
+-251 TJm
+(case,) 19.6363 Tj
+-251 TJm
+(you) 14.9439 Tj
+-251 TJm
+(can) 13.8281 Tj
+-251 TJm
+(feed) 17.1456 Tj
+-251 TJm
+(man) 17.1556 Tj
+15 TJm
+(y) 4.9813 Tj
+-251 TJm
+(me) 12.1743 Tj
+15 TJm
+(g) 4.9813 Tj
+4 TJm
+(abyt) 17.1556 Tj
+1 TJm
+(es) 8.29885 Tj
+-252 TJm
+(of) 8.29885 Tj
+-251 TJm
+(uncompressed) 56.996 Tj
+-251 TJm
+(data) 16.5977 Tj
+-251 TJm
+(into) 15.5018 Tj
+-251 TJm
+(the) 12.1743 Tj
+-251 TJm
+(library) 26.5603 Tj
+-251 TJm
+(before) 25.4445 Tj
+-251 TJm
+(getting) 27.6761 Tj
+-251 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-251 TJm
+(compressed) 47.0334 Tj
+72 119.105 Td
+(output,) 27.9551 Tj
+-250 TJm
+(so) 8.85675 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(probably) 35.417 Tj
+-250 TJm
+(rules) 19.3673 Tj
+-250 TJm
+(out) 12.7322 Tj
+-250 TJm
+(applications) 48.1492 Tj
+-250 TJm
+(requiring) 36.5229 Tj
+-250 TJm
+(interacti) 32.6474 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(e) 4.42339 Tj
+-250 TJm
+(beha) 18.8094 Tj
+20 TJm
+(viour) 21.031 Tj
+55 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 116.949] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -106.986] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 97.1875 Td
+/F130_0 9.9626 Tf
+(These) 23.7907 Tj
+-304 TJm
+(aren') 20.4632 Tj
+18 TJm
+(t) 2.7696 Tj
+-304 TJm
+(f) 3.31755 Tj
+10 TJm
+(aults) 18.8194 Tj
+-304 TJm
+(of) 8.29885 Tj
+-304 TJm
+(my) 12.7322 Tj
+-304 TJm
+(implementation,) 65.0359 Tj
+-317 TJm
+(I) 3.31755 Tj
+-304 TJm
+(hope,) 21.8579 Tj
+-318 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-304 TJm
+(more) 20.4731 Tj
+-304 TJm
+(an) 9.40469 Tj
+-304 TJm
+(intrinsic) 32.6574 Tj
+-304 TJm
+(property) 33.7533 Tj
+-304 TJm
+(of) 8.29885 Tj
+-304 TJm
+(the) 12.1743 Tj
+-304 TJm
+(Burro) 23.2427 Tj
+25 TJm
+(ws-Wheeler) 48.1293 Tj
+-304 TJm
+(transform) 38.7346 Tj
+72 85.2323 Td
+(\(unfortunately\).) 62.8042 Tj
+-620 TJm
+(Maybe) 27.6661 Tj
+-250 TJm
+(this) 14.396 Tj
+-250 TJm
+(isn') 14.9439 Tj
+18 TJm
+(t) 2.7696 Tj
+-250 TJm
+(what) 19.3673 Tj
+-250 TJm
+(you) 14.9439 Tj
+-250 TJm
+(w) 7.193 Tj
+10 TJm
+(ant.) 14.6649 Tj
+[1 0 0 1 72 83.0755] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -22.2611] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7545] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(33) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 37 37
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 116.328 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -382.4 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+498.728 749.245 Td
+/F130_0 9.9626 Tf
+(Miscellanea) 48.1393 Tj
+[1 0 0 1 266.071 749.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -7.0936] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -540 -741.554] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(If) 6.63509 Tj
+-275 TJm
+(you) 14.9439 Tj
+-274 TJm
+(w) 7.193 Tj
+10 TJm
+(ant) 12.1743 Tj
+-275 TJm
+(a) 4.42339 Tj
+-274 TJm
+(compressor) 45.9276 Tj
+-275 TJm
+(and/or) 25.4544 Tj
+-275 TJm
+(library) 26.5603 Tj
+-274 TJm
+(which) 24.3486 Tj
+-275 TJm
+(is) 6.64505 Tj
+-274 TJm
+(f) 3.31755 Tj
+10 TJm
+(aster) 18.8094 Tj
+40 TJm
+(,) 2.49065 Tj
+-281 TJm
+(uses) 17.1556 Tj
+-275 TJm
+(less) 14.9439 Tj
+-274 TJm
+(memory) 33.2053 Tj
+-275 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-275 TJm
+(gets) 16.0497 Tj
+-274 TJm
+(pretty) 23.2427 Tj
+-275 TJm
+(good) 19.9252 Tj
+-274 TJm
+(compression,) 52.8516 Tj
+-281 TJm
+(and) 14.386 Tj
+-275 TJm
+(has) 13.2801 Tj
+72 698.082 Td
+(minimal) 33.2153 Tj
+-288 TJm
+(latenc) 23.7907 Tj
+15 TJm
+(y) 4.9813 Tj
+65 TJm
+(,) 2.49065 Tj
+-297 TJm
+(consider) 33.7533 Tj
+-288 TJm
+(Jean-loup) 38.7346 Tj
+-288 TJm
+(Gailly') 28.224 Tj
+55 TJm
+(s) 3.87545 Tj
+-288 TJm
+(and) 14.386 Tj
+-288 TJm
+(Mark) 21.579 Tj
+-288 TJm
+(Adl) 14.9439 Tj
+1 TJm
+(er') 11.0585 Tj
+55 TJm
+(s) 3.87545 Tj
+-288 TJm
+(w) 7.193 Tj
+10 TJm
+(ork,) 15.7708 Tj
+[1 0 0 1 353.879 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -353.879 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+353.879 698.082 Td
+/F134_0 9.9626 Tf
+(zlib-1.2.1) 59.7756 Tj
+[1 0 0 1 413.655 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -413.655 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+416.523 698.082 Td
+/F130_0 9.9626 Tf
+(and) 14.386 Tj
+[1 0 0 1 433.777 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -433.777 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+433.777 698.082 Td
+/F134_0 9.9626 Tf
+(gzip-1.2.4) 59.7756 Tj
+[1 0 0 1 493.553 698.082] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.553 -698.082] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+493.553 698.082 Td
+/F130_0 9.9626 Tf
+(.) 2.49065 Tj
+-847 TJm
+(Look) 21.031 Tj
+-288 TJm
+(for) 11.6164 Tj
+72 686.127 Td
+(them) 19.9252 Tj
+-250 TJm
+(at) 7.193 Tj
+-250 TJm
+(http://www) 45.3896 Tj
+65 TJm
+(.zlib) 17.4346 Tj
+40 TJm
+(.or) 10.7895 Tj
+18 TJm
+(g) 4.9813 Tj
+-250 TJm
+(and) 14.386 Tj
+-250 TJm
+(http://www) 45.3896 Tj
+65 TJm
+(.gzip.or) 30.4357 Tj
+18 TJm
+(g) 4.9813 Tj
+-250 TJm
+(respecti) 30.9837 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(ely) 12.1743 Tj
+65 TJm
+(.) 2.49065 Tj
+[1 0 0 1 72 683.97] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -674.008] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 664.209 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(or) 8.29885 Tj
+-582 TJm
+(something) 41.5142 Tj
+-583 TJm
+(f) 3.31755 Tj
+10 TJm
+(aster) 18.8094 Tj
+-582 TJm
+(and) 14.386 Tj
+-582 TJm
+(lighter) 26.0123 Tj
+-583 TJm
+(still,) 17.4445 Tj
+-665 TJm
+(you) 14.9439 Tj
+-582 TJm
+(might) 23.2527 Tj
+-583 TJm
+(try) 11.0684 Tj
+-582 TJm
+(Markus) 30.4357 Tj
+-582 TJm
+(F) 5.53921 Tj
+-582 TJm
+(X) 7.193 Tj
+-582 TJm
+(J) 3.87545 Tj
+-582 TJm
+(Oberhumer') 48.6872 Tj
+55 TJm
+(s) 3.87545 Tj
+[1 0 0 1 437.433 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -437.433 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+437.433 664.209 Td
+/F134_0 9.9626 Tf
+(LZO) 17.9327 Tj
+[1 0 0 1 455.365 664.209] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -455.365 -664.209] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+461.163 664.209 Td
+/F130_0 9.9626 Tf
+(real-time) 35.965 Tj
+-582 TJm
+(compres-) 37.0708 Tj
+72 652.254 Td
+(sion/decompression) 79.1429 Tj
+-250 TJm
+(library) 26.5603 Tj
+65 TJm
+(,) 2.49065 Tj
+-250 TJm
+(at) 7.193 Tj
+-250 TJm
+(http://www) 45.3896 Tj
+65 TJm
+(.oberhumer) 45.6486 Tj
+55 TJm
+(.com/opensource.) 70.2762 Tj
+[1 0 0 1 72 650.097] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -640.135] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 617.501 Td
+/F122_0 20.6585 Tf
+(4.5.) 34.4584 Tj
+-278 TJm
+(Fur) 33.2808 Tj
+-20 TJm
+(ther) 39.0239 Tj
+-278 TJm
+(Reading) 81.4978 Tj
+[1 0 0 1 72 612.905] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9626] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -602.942] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 595.583 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 101.888 595.583] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -101.888 -595.583] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+104.923 595.583 Td
+/F130_0 9.9626 Tf
+(is) 6.64505 Tj
+-305 TJm
+(not) 12.7322 Tj
+-304 TJm
+(research) 33.1854 Tj
+-305 TJm
+(w) 7.193 Tj
+10 TJm
+(ork,) 15.7708 Tj
+-318 TJm
+(in) 7.7509 Tj
+-305 TJm
+(the) 12.1743 Tj
+-304 TJm
+(sense) 21.579 Tj
+-305 TJm
+(that) 14.9439 Tj
+-304 TJm
+(it) 5.53921 Tj
+-305 TJm
+(doesn') 26.5603 Tj
+18 TJm
+(t) 2.7696 Tj
+-305 TJm
+(present) 28.772 Tj
+-304 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-305 TJm
+(ne) 9.40469 Tj
+25 TJm
+(w) 7.193 Tj
+-304 TJm
+(ideas.) 22.9638 Tj
+-474 TJm
+(Rather) 26.5603 Tj
+40 TJm
+(,) 2.49065 Tj
+-318 TJm
+(it') 8.85675 Tj
+55 TJm
+(s) 3.87545 Tj
+-305 TJm
+(an) 9.40469 Tj
+-305 TJm
+(engineeri) 37.0708 Tj
+1 TJm
+(ng) 9.9626 Tj
+-305 TJm
+(e) 4.42339 Tj
+15 TJm
+(x) 4.9813 Tj
+15 TJm
+(ercise) 23.2328 Tj
+72 583.628 Td
+(based) 22.6848 Tj
+-250 TJm
+(on) 9.9626 Tj
+-250 TJm
+(e) 4.42339 Tj
+15 TJm
+(xisting) 27.1282 Tj
+-250 TJm
+(ideas.) 22.9638 Tj
+[1 0 0 1 72 581.471] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -9.9627] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -571.509] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 561.71 Td
+/F130_0 9.9626 Tf
+(F) 5.53921 Tj
+15 TJm
+(our) 13.2801 Tj
+-250 TJm
+(documents) 43.1679 Tj
+-250 TJm
+(describe) 33.1954 Tj
+-250 TJm
+(essentially) 42.0621 Tj
+-250 TJm
+(all) 9.9626 Tj
+-250 TJm
+(the) 12.1743 Tj
+-250 TJm
+(ideas) 20.4731 Tj
+-250 TJm
+(behind) 27.1182 Tj
+[1 0 0 1 298.747 561.71] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -298.747 -561.71] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+298.747 561.71 Td
+/F134_0 9.9626 Tf
+(bzip2) 29.8878 Tj
+[1 0 0 1 328.635 561.71] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -328.635 -561.71] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+328.635 561.71 Td
+/F130_0 9.9626 Tf
+(:) 2.7696 Tj
+[1 0 0 1 72 559.554] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -299.875] cm
+/DeviceRGB {} cs
+[0.929398 0.968597 0.956848] sc
+/DeviceRGB {} CS
+[0.929398 0.968597 0.956848] SC
+0 0 468 298.879 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 295.293] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -550.189] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 550.189 Td
+/F134_0 9.9626 Tf
+(Michael) 41.8429 Tj
+-426 TJm
+(Burrows) 41.8429 Tj
+-426 TJm
+(and) 17.9327 Tj
+-426 TJm
+(D.) 11.9551 Tj
+-426 TJm
+(J.) 11.9551 Tj
+-426 TJm
+(Wheeler:) 47.8205 Tj
+98.4879 538.234 Td
+("A) 11.9551 Tj
+-426 TJm
+(block-sorting) 77.7083 Tj
+-426 TJm
+(lossless) 47.8205 Tj
+-426 TJm
+(data) 23.9102 Tj
+-426 TJm
+(compression) 65.7532 Tj
+-426 TJm
+(algorithm") 59.7756 Tj
+102.732 526.278 Td
+(10th) 23.9102 Tj
+-426 TJm
+(May) 17.9327 Tj
+-426 TJm
+(1994.) 29.8878 Tj
+102.732 514.323 Td
+(Digital) 41.8429 Tj
+-426 TJm
+(SRC) 17.9327 Tj
+-426 TJm
+(Research) 47.8205 Tj
+-426 TJm
+(Report) 35.8654 Tj
+-426 TJm
+(124.) 23.9102 Tj
+102.732 502.368 Td
+(ftp://ftp.digital.com/pub/DEC/SRC/research-reports/SRC-124.ps.g\
+z) 382.564 Tj
+102.732 490.413 Td
+(If) 11.9551 Tj
+-426 TJm
+(you) 17.9327 Tj
+-426 TJm
+(have) 23.9102 Tj
+-426 TJm
+(trouble) 41.8429 Tj
+-426 TJm
+(finding) 41.8429 Tj
+-426 TJm
+(it,) 17.9327 Tj
+-426 TJm
+(try) 17.9327 Tj
+-426 TJm
+(searching) 53.798 Tj
+-426 TJm
+(at) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+102.732 478.458 Td
+(New) 17.9327 Tj
+-426 TJm
+(Zealand) 41.8429 Tj
+-426 TJm
+(Digital) 41.8429 Tj
+-426 TJm
+(Library,) 47.8205 Tj
+-426 TJm
+(http://www.nzdl.org.) 119.551 Tj
+90 454.547 Td
+(Daniel) 35.8654 Tj
+-426 TJm
+(S.) 11.9551 Tj
+-426 TJm
+(Hirschberg) 59.7756 Tj
+-426 TJm
+(and) 17.9327 Tj
+-426 TJm
+(Debra) 29.8878 Tj
+-426 TJm
+(A.) 11.9551 Tj
+-426 TJm
+(LeLewer) 41.8429 Tj
+98.4879 442.592 Td
+("Efficient) 59.7756 Tj
+-426 TJm
+(Decoding) 47.8205 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(Prefix) 35.8654 Tj
+-426 TJm
+(Codes") 35.8654 Tj
+102.732 430.637 Td
+(Communications) 83.6858 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(ACM,) 23.9102 Tj
+-426 TJm
+(April) 29.8878 Tj
+-426 TJm
+(1990,) 29.8878 Tj
+-426 TJm
+(Vol) 17.9327 Tj
+-426 TJm
+(33,) 17.9327 Tj
+-426 TJm
+(Number) 35.8654 Tj
+-426 TJm
+(4.) 11.9551 Tj
+102.732 418.682 Td
+(You) 17.9327 Tj
+-426 TJm
+(might) 29.8878 Tj
+-426 TJm
+(be) 11.9551 Tj
+-426 TJm
+(able) 23.9102 Tj
+-426 TJm
+(to) 11.9551 Tj
+-426 TJm
+(get) 17.9327 Tj
+-426 TJm
+(an) 11.9551 Tj
+-426 TJm
+(electronic) 59.7756 Tj
+-426 TJm
+(copy) 23.9102 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(this) 23.9102 Tj
+102.732 406.727 Td
+(from) 23.9102 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(ACM) 17.9327 Tj
+-426 TJm
+(Digital) 41.8429 Tj
+-426 TJm
+(Library.) 47.8205 Tj
+90 382.816 Td
+(David) 29.8878 Tj
+-426 TJm
+(J.) 11.9551 Tj
+-426 TJm
+(Wheeler) 41.8429 Tj
+102.732 370.861 Td
+(Program) 41.8429 Tj
+-426 TJm
+(bred3.c) 41.8429 Tj
+-426 TJm
+(and) 17.9327 Tj
+-426 TJm
+(accompanying) 71.7307 Tj
+-426 TJm
+(document) 47.8205 Tj
+-426 TJm
+(bred3.ps.) 53.798 Tj
+102.732 358.906 Td
+(This) 23.9102 Tj
+-426 TJm
+(contains) 47.8205 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(idea) 23.9102 Tj
+-426 TJm
+(behind) 35.8654 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(multi-table) 65.7532 Tj
+-426 TJm
+(Huffman) 41.8429 Tj
+-426 TJm
+(coding) 35.8654 Tj
+-426 TJm
+(scheme.) 41.8429 Tj
+102.732 346.951 Td
+(ftp://ftp.cl.cam.ac.uk/users/djw3/) 203.237 Tj
+90 323.041 Td
+(Jon) 17.9327 Tj
+-426 TJm
+(L.) 11.9551 Tj
+-426 TJm
+(Bentley) 41.8429 Tj
+-426 TJm
+(and) 17.9327 Tj
+-426 TJm
+(Robert) 35.8654 Tj
+-426 TJm
+(Sedgewick) 53.798 Tj
+98.4879 311.085 Td
+("Fast) 29.8878 Tj
+-426 TJm
+(Algorithms) 59.7756 Tj
+-426 TJm
+(for) 17.9327 Tj
+-426 TJm
+(Sorting) 41.8429 Tj
+-426 TJm
+(and) 17.9327 Tj
+-426 TJm
+(Searching) 53.798 Tj
+-426 TJm
+(Strings") 47.8205 Tj
+102.732 299.13 Td
+(Available) 53.798 Tj
+-426 TJm
+(from) 23.9102 Tj
+-426 TJm
+(Sedgewick's) 65.7532 Tj
+-426 TJm
+(web) 17.9327 Tj
+-426 TJm
+(page,) 29.8878 Tj
+102.732 287.175 Td
+(www.cs.princeton.edu/~rs) 143.461 Tj
+[1 0 0 1 72 259.678] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -249.715] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 237.76 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-239 TJm
+(follo) 18.8194 Tj
+25 TJm
+(wing) 19.9252 Tj
+-238 TJm
+(paper) 22.1269 Tj
+-239 TJm
+(gi) 7.7509 Tj
+25 TJm
+(v) 4.9813 Tj
+15 TJm
+(es) 8.29885 Tj
+-239 TJm
+(v) 4.9813 Tj
+25 TJm
+(aluable) 28.772 Tj
+-238 TJm
+(additional) 39.8504 Tj
+-239 TJm
+(insights) 31.0036 Tj
+-238 TJm
+(into) 15.5018 Tj
+-239 TJm
+(the) 12.1743 Tj
+-239 TJm
+(algorithm,) 41.2352 Tj
+-241 TJm
+(b) 4.9813 Tj
+20 TJm
+(ut) 7.7509 Tj
+-238 TJm
+(is) 6.64505 Tj
+-239 TJm
+(not) 12.7322 Tj
+-239 TJm
+(immedi) 30.4457 Tj
+1 TJm
+(ately) 19.3673 Tj
+-239 TJm
+(the) 12.1743 Tj
+-239 TJm
+(basis) 19.9252 Tj
+-238 TJm
+(of) 8.29885 Tj
+-239 TJm
+(an) 9.40469 Tj
+15 TJm
+(y) 4.9813 Tj
+-239 TJm
+(code) 18.8094 Tj
+72 225.805 Td
+(used) 18.2614 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(bzip2.) 24.6275 Tj
+[1 0 0 1 72 223.648] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -72.7273] cm
+/DeviceRGB {} cs
+[0.929398 0.968597 0.956848] sc
+/DeviceRGB {} CS
+[0.929398 0.968597 0.956848] SC
+0 0 468 71.731 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 68.1444] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -214.283] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 214.283 Td
+/F134_0 9.9626 Tf
+(Peter) 29.8878 Tj
+-426 TJm
+(Fenwick:) 47.8205 Tj
+102.732 202.328 Td
+(Block) 29.8878 Tj
+-426 TJm
+(Sorting) 41.8429 Tj
+-426 TJm
+(Text) 23.9102 Tj
+-426 TJm
+(Compression) 65.7532 Tj
+102.732 190.373 Td
+(Proceedings) 65.7532 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(19th) 23.9102 Tj
+-426 TJm
+(Australasian) 71.7307 Tj
+-426 TJm
+(Computer) 47.8205 Tj
+-426 TJm
+(Science) 41.8429 Tj
+-426 TJm
+(Conference,) 65.7532 Tj
+111.22 178.418 Td
+(Melbourne,) 59.7756 Tj
+-426 TJm
+(Australia.) 59.7756 Tj
+-852 TJm
+(Jan) 17.9327 Tj
+-426 TJm
+(31) 11.9551 Tj
+-426 TJm
+(-) 5.97756 Tj
+-426 TJm
+(Feb) 17.9327 Tj
+-426 TJm
+(2,) 11.9551 Tj
+-426 TJm
+(1996.) 29.8878 Tj
+102.732 166.463 Td
+(ftp://ftp.cs.auckland.ac.nz/pub/peter-f/ACSC96paper.ps) 322.788 Tj
+[1 0 0 1 72 150.921] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -140.958] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 129.003 Td
+/F130_0 9.9626 Tf
+(K) 7.193 Tj
+15 TJm
+(unihik) 25.4644 Tj
+10 TJm
+(o) 4.9813 Tj
+-250 TJm
+(Sadakane') 41.4942 Tj
+55 TJm
+(s) 3.87545 Tj
+-250 TJm
+(sorting) 27.6761 Tj
+-250 TJm
+(algorithm,) 41.2352 Tj
+-250 TJm
+(mentioned) 42.0621 Tj
+-250 TJm
+(abo) 14.386 Tj
+15 TJm
+(v) 4.9813 Tj
+15 TJm
+(e,) 6.91404 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+25 TJm
+(ailable) 26.5603 Tj
+-250 TJm
+(from:) 22.1369 Tj
+[1 0 0 1 72 126.846] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -36.8618] cm
+/DeviceRGB {} cs
+[0.929398 0.968597 0.956848] sc
+/DeviceRGB {} CS
+[0.929398 0.968597 0.956848] SC
+0 0 468 35.8655 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 32.2789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -117.482] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 117.482 Td
+/F134_0 9.9626 Tf
+(http://naomi.is.s.u-tokyo.ac.jp/~sada/papers/Sada98b.ps.gz) 346.698 Tj
+[1 0 0 1 72 89.9846] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -29.1702] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8542] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9514] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9514 Td
+/F130_0 9.9626 Tf
+(34) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Page: 38 38
+%%BeginPageSetup
+%%PageOrientation: Portrait
+pdfStartPage
+0 0 612 792 re W
+%%EndPageSetup
+[] 0 d
+1 i
+0 j
+0 J
+10 M
+1 w
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+false op
+false OP
+0 0 612 792 re
+W
+q
+[1 0 0 1 72 741.554] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 14.4459] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 187.197 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 -6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 116.328 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -382.4 -749.245] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+498.728 749.245 Td
+/F130_0 9.9626 Tf
+(Miscellanea) 48.1393 Tj
+[1 0 0 1 266.071 749.146] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 280.796 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -472.974 -7.0936] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -0.4981] cm
+q
+[] 0 d
+0 J
+0.4981 w
+0 0.2491 m
+475.465 0.2491 l
+S
+Q
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 479.251 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -540 -741.554] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 710.037 Td
+/F130_0 9.9626 Tf
+(The) 15.4918 Tj
+-250 TJm
+(Manber) 30.9837 Tj
+20 TJm
+(-Myers) 28.772 Tj
+-250 TJm
+(suf) 12.1743 Tj
+25 TJm
+(\002x) 10.5205 Tj
+-250 TJm
+(array) 20.4632 Tj
+-250 TJm
+(construction) 49.2551 Tj
+-250 TJm
+(algorithm) 38.7446 Tj
+-250 TJm
+(is) 6.64505 Tj
+-250 TJm
+(described) 38.1767 Tj
+-250 TJm
+(in) 7.7509 Tj
+-250 TJm
+(a) 4.42339 Tj
+-250 TJm
+(paper) 22.1269 Tj
+-250 TJm
+(a) 4.42339 Tj
+20 TJm
+(v) 4.9813 Tj
+25 TJm
+(ailable) 26.5603 Tj
+-250 TJm
+(from:) 22.1369 Tj
+[1 0 0 1 72 707.88] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -36.8618] cm
+/DeviceRGB {} cs
+[0.929398 0.968597 0.956848] sc
+/DeviceRGB {} CS
+[0.929398 0.968597 0.956848] SC
+0 0 468 35.8655 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 32.2789] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3685] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -698.516] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 698.516 Td
+/F134_0 9.9626 Tf
+(http://www.cs.arizona.edu/people/gene/PAPERS/suffix.ps) 322.788 Tj
+[1 0 0 1 72 671.019] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -13.5492] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -72 -661.056] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+72 649.101 Td
+/F130_0 9.9626 Tf
+(Finally) 28.234 Tj
+65 TJm
+(,) 2.49065 Tj
+-227 TJm
+(the) 12.1743 Tj
+-221 TJm
+(follo) 18.8194 Tj
+25 TJm
+(wing) 19.9252 Tj
+-222 TJm
+(papers) 26.0024 Tj
+-221 TJm
+(document) 39.2925 Tj
+-221 TJm
+(some) 21.031 Tj
+-222 TJm
+(in) 7.7509 Tj
+40 TJm
+(v) 4.9813 Tj
+15 TJm
+(estig) 18.8194 Tj
+5 TJm
+(ations) 23.8007 Tj
+-221 TJm
+(I) 3.31755 Tj
+-221 TJm
+(made) 21.579 Tj
+-222 TJm
+(into) 15.5018 Tj
+-221 TJm
+(the) 12.1743 Tj
+-221 TJm
+(performance) 50.341 Tj
+-222 TJm
+(of) 8.29885 Tj
+-221 TJm
+(sorting) 27.6761 Tj
+-221 TJm
+(and) 14.386 Tj
+-222 TJm
+(decompression) 59.7656 Tj
+72 637.146 Td
+(algorithms:) 45.3896 Tj
+[1 0 0 1 72 634.989] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 -132.503] cm
+/DeviceRGB {} cs
+[0.929398 0.968597 0.956848] sc
+/DeviceRGB {} CS
+[0.929398 0.968597 0.956848] SC
+0 0 468 131.507 re
+f
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 127.92] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 18 -8.3686] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -90 -625.624] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+90 625.624 Td
+/F134_0 9.9626 Tf
+(Julian) 35.8654 Tj
+-426 TJm
+(Seward) 35.8654 Tj
+102.732 613.669 Td
+(On) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(Performance) 65.7532 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(BWT) 17.9327 Tj
+-426 TJm
+(Sorting) 41.8429 Tj
+-426 TJm
+(Algorithms) 59.7756 Tj
+102.732 601.714 Td
+(Proceedings) 65.7532 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(IEEE) 23.9102 Tj
+-426 TJm
+(Data) 23.9102 Tj
+-426 TJm
+(Compression) 65.7532 Tj
+-426 TJm
+(Conference) 59.7756 Tj
+-426 TJm
+(2000) 23.9102 Tj
+111.22 589.759 Td
+(Snowbird,) 53.798 Tj
+-426 TJm
+(Utah.) 29.8878 Tj
+-852 TJm
+(28-30) 29.8878 Tj
+-426 TJm
+(March) 29.8878 Tj
+-426 TJm
+(2000.) 29.8878 Tj
+90 565.848 Td
+(Julian) 35.8654 Tj
+-426 TJm
+(Seward) 35.8654 Tj
+102.732 553.893 Td
+(Space-time) 59.7756 Tj
+-426 TJm
+(Tradeoffs) 53.798 Tj
+-426 TJm
+(in) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(Inverse) 41.8429 Tj
+-426 TJm
+(B-W) 17.9327 Tj
+-426 TJm
+(Transform) 53.798 Tj
+102.732 541.938 Td
+(Proceedings) 65.7532 Tj
+-426 TJm
+(of) 11.9551 Tj
+-426 TJm
+(the) 17.9327 Tj
+-426 TJm
+(IEEE) 23.9102 Tj
+-426 TJm
+(Data) 23.9102 Tj
+-426 TJm
+(Compression) 65.7532 Tj
+-426 TJm
+(Conference) 59.7756 Tj
+-426 TJm
+(2001) 23.9102 Tj
+111.22 529.983 Td
+(Snowbird,) 53.798 Tj
+-426 TJm
+(Utah.) 29.8878 Tj
+-852 TJm
+(27-29) 29.8878 Tj
+-426 TJm
+(March) 29.8878 Tj
+-426 TJm
+(2001.) 29.8878 Tj
+[1 0 0 1 72 502.486] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 468 3.5866] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -468 -3.5866] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 0 -451.634] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 1.8929 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 374.394 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 2.4907 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 0 6.8541] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 40.5726 -6.7546] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 -493.841 -50.9513] cm
+[1 0 0 1 0 0] Tm
+0 0 Td
+534.414 50.9513 Td
+/F130_0 9.9626 Tf
+(35) 9.9626 Tj
+[1 0 0 1 453.269 50.8518] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 93.5985 0] cm
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+/DeviceRGB {} cs
+[0 0 0] sc
+/DeviceRGB {} CS
+[0 0 0] SC
+[1 0 0 1 6.2765 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+[1 0 0 1 -13.1436 0] cm
+/DeviceGray {} cs
+[0] sc
+/DeviceGray {} CS
+[0] SC
+Q
+showpage
+%%PageTrailer
+pdfEndPage
+%%Trailer
+end
+%%DocumentSuppliedResources:
+%%+ font DTUUHP+NimbusSanL-Bold
+%%+ font VXAMRV+NimbusRomNo9L-Regu
+%%+ font MFECUR+NimbusMonL-Regu
+%%+ font ZOVMRD+CMMI10
+%%+ font ERVBFT+NimbusMonL-Bold
+%%+ font BZXIEB+CMSY10
+%%+ font WWWUTU+NimbusRomNo9L-ReguItal
+%%EOF
diff --git a/Utilities/cmbzip2/manual.xml b/Utilities/cmbzip2/manual.xml
new file mode 100644
index 0000000000..f224136024
--- /dev/null
+++ b/Utilities/cmbzip2/manual.xml
@@ -0,0 +1,2964 @@
+<?xml version="1.0"?> <!-- -*- sgml -*- -->
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+ "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"[
+
+<!-- various strings, dates etc. common to all docs -->
+<!ENTITY % common-ents SYSTEM "entities.xml"> %common-ents;
+]>
+
+<book lang="en" id="userman" xreflabel="bzip2 Manual">
+
+ <bookinfo>
+ <title>bzip2 and libbzip2, version 1.0.5</title>
+ <subtitle>A program and library for data compression</subtitle>
+ <copyright>
+ <year>&bz-lifespan;</year>
+ <holder>Julian Seward</holder>
+ </copyright>
+ <releaseinfo>Version &bz-version; of &bz-date;</releaseinfo>
+
+ <authorgroup>
+ <author>
+ <firstname>Julian</firstname>
+ <surname>Seward</surname>
+ <affiliation>
+ <orgname>&bz-url;</orgname>
+ </affiliation>
+ </author>
+ </authorgroup>
+
+ <legalnotice>
+
+ <para>This program, <computeroutput>bzip2</computeroutput>, the
+ associated library <computeroutput>libbzip2</computeroutput>, and
+ all documentation, are copyright &copy; &bz-lifespan; Julian Seward.
+ All rights reserved.</para>
+
+ <para>Redistribution and use in source and binary forms, with
+ or without modification, are permitted provided that the
+ following conditions are met:</para>
+
+ <itemizedlist mark='bullet'>
+
+ <listitem><para>Redistributions of source code must retain the
+ above copyright notice, this list of conditions and the
+ following disclaimer.</para></listitem>
+
+ <listitem><para>The origin of this software must not be
+ misrepresented; you must not claim that you wrote the original
+ software. If you use this software in a product, an
+ acknowledgment in the product documentation would be
+ appreciated but is not required.</para></listitem>
+
+ <listitem><para>Altered source versions must be plainly marked
+ as such, and must not be misrepresented as being the original
+ software.</para></listitem>
+
+ <listitem><para>The name of the author may not be used to
+ endorse or promote products derived from this software without
+ specific prior written permission.</para></listitem>
+
+ </itemizedlist>
+
+ <para>THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 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.</para>
+
+ <para>PATENTS: To the best of my knowledge,
+ <computeroutput>bzip2</computeroutput> and
+ <computeroutput>libbzip2</computeroutput> do not use any patented
+ algorithms. However, I do not have the resources to carry
+ out a patent search. Therefore I cannot give any guarantee of
+ the above statement.
+ </para>
+
+</legalnotice>
+
+</bookinfo>
+
+
+
+<chapter id="intro" xreflabel="Introduction">
+<title>Introduction</title>
+
+<para><computeroutput>bzip2</computeroutput> compresses files
+using the Burrows-Wheeler block-sorting text compression
+algorithm, and Huffman coding. Compression is generally
+considerably better than that achieved by more conventional
+LZ77/LZ78-based compressors, and approaches the performance of
+the PPM family of statistical compressors.</para>
+
+<para><computeroutput>bzip2</computeroutput> is built on top of
+<computeroutput>libbzip2</computeroutput>, a flexible library for
+handling compressed data in the
+<computeroutput>bzip2</computeroutput> format. This manual
+describes both how to use the program and how to work with the
+library interface. Most of the manual is devoted to this
+library, not the program, which is good news if your interest is
+only in the program.</para>
+
+<itemizedlist mark='bullet'>
+
+ <listitem><para><xref linkend="using"/> describes how to use
+ <computeroutput>bzip2</computeroutput>; this is the only part
+ you need to read if you just want to know how to operate the
+ program.</para></listitem>
+
+ <listitem><para><xref linkend="libprog"/> describes the
+ programming interfaces in detail, and</para></listitem>
+
+ <listitem><para><xref linkend="misc"/> records some
+ miscellaneous notes which I thought ought to be recorded
+ somewhere.</para></listitem>
+
+</itemizedlist>
+
+</chapter>
+
+
+<chapter id="using" xreflabel="How to use bzip2">
+<title>How to use bzip2</title>
+
+<para>This chapter contains a copy of the
+<computeroutput>bzip2</computeroutput> man page, and nothing
+else.</para>
+
+<sect1 id="name" xreflabel="NAME">
+<title>NAME</title>
+
+<itemizedlist mark='bullet'>
+
+ <listitem><para><computeroutput>bzip2</computeroutput>,
+ <computeroutput>bunzip2</computeroutput> - a block-sorting file
+ compressor, v1.0.4</para></listitem>
+
+ <listitem><para><computeroutput>bzcat</computeroutput> -
+ decompresses files to stdout</para></listitem>
+
+ <listitem><para><computeroutput>bzip2recover</computeroutput> -
+ recovers data from damaged bzip2 files</para></listitem>
+
+</itemizedlist>
+
+</sect1>
+
+
+<sect1 id="synopsis" xreflabel="SYNOPSIS">
+<title>SYNOPSIS</title>
+
+<itemizedlist mark='bullet'>
+
+ <listitem><para><computeroutput>bzip2</computeroutput> [
+ -cdfkqstvzVL123456789 ] [ filenames ... ]</para></listitem>
+
+ <listitem><para><computeroutput>bunzip2</computeroutput> [
+ -fkvsVL ] [ filenames ... ]</para></listitem>
+
+ <listitem><para><computeroutput>bzcat</computeroutput> [ -s ] [
+ filenames ... ]</para></listitem>
+
+ <listitem><para><computeroutput>bzip2recover</computeroutput>
+ filename</para></listitem>
+
+</itemizedlist>
+
+</sect1>
+
+
+<sect1 id="description" xreflabel="DESCRIPTION">
+<title>DESCRIPTION</title>
+
+<para><computeroutput>bzip2</computeroutput> compresses files
+using the Burrows-Wheeler block sorting text compression
+algorithm, and Huffman coding. Compression is generally
+considerably better than that achieved by more conventional
+LZ77/LZ78-based compressors, and approaches the performance of
+the PPM family of statistical compressors.</para>
+
+<para>The command-line options are deliberately very similar to
+those of GNU <computeroutput>gzip</computeroutput>, but they are
+not identical.</para>
+
+<para><computeroutput>bzip2</computeroutput> expects a list of
+file names to accompany the command-line flags. Each file is
+replaced by a compressed version of itself, with the name
+<computeroutput>original_name.bz2</computeroutput>. Each
+compressed file has the same modification date, permissions, and,
+when possible, ownership as the corresponding original, so that
+these properties can be correctly restored at decompression time.
+File name handling is naive in the sense that there is no
+mechanism for preserving original file names, permissions,
+ownerships or dates in filesystems which lack these concepts, or
+have serious file name length restrictions, such as
+MS-DOS.</para>
+
+<para><computeroutput>bzip2</computeroutput> and
+<computeroutput>bunzip2</computeroutput> will by default not
+overwrite existing files. If you want this to happen, specify
+the <computeroutput>-f</computeroutput> flag.</para>
+
+<para>If no file names are specified,
+<computeroutput>bzip2</computeroutput> compresses from standard
+input to standard output. In this case,
+<computeroutput>bzip2</computeroutput> will decline to write
+compressed output to a terminal, as this would be entirely
+incomprehensible and therefore pointless.</para>
+
+<para><computeroutput>bunzip2</computeroutput> (or
+<computeroutput>bzip2 -d</computeroutput>) decompresses all
+specified files. Files which were not created by
+<computeroutput>bzip2</computeroutput> will be detected and
+ignored, and a warning issued.
+<computeroutput>bzip2</computeroutput> attempts to guess the
+filename for the decompressed file from that of the compressed
+file as follows:</para>
+
+<itemizedlist mark='bullet'>
+
+ <listitem><para><computeroutput>filename.bz2 </computeroutput>
+ becomes
+ <computeroutput>filename</computeroutput></para></listitem>
+
+ <listitem><para><computeroutput>filename.bz </computeroutput>
+ becomes
+ <computeroutput>filename</computeroutput></para></listitem>
+
+ <listitem><para><computeroutput>filename.tbz2</computeroutput>
+ becomes
+ <computeroutput>filename.tar</computeroutput></para></listitem>
+
+ <listitem><para><computeroutput>filename.tbz </computeroutput>
+ becomes
+ <computeroutput>filename.tar</computeroutput></para></listitem>
+
+ <listitem><para><computeroutput>anyothername </computeroutput>
+ becomes
+ <computeroutput>anyothername.out</computeroutput></para></listitem>
+
+</itemizedlist>
+
+<para>If the file does not end in one of the recognised endings,
+<computeroutput>.bz2</computeroutput>,
+<computeroutput>.bz</computeroutput>,
+<computeroutput>.tbz2</computeroutput> or
+<computeroutput>.tbz</computeroutput>,
+<computeroutput>bzip2</computeroutput> complains that it cannot
+guess the name of the original file, and uses the original name
+with <computeroutput>.out</computeroutput> appended.</para>
+
+<para>As with compression, supplying no filenames causes
+decompression from standard input to standard output.</para>
+
+<para><computeroutput>bunzip2</computeroutput> will correctly
+decompress a file which is the concatenation of two or more
+compressed files. The result is the concatenation of the
+corresponding uncompressed files. Integrity testing
+(<computeroutput>-t</computeroutput>) of concatenated compressed
+files is also supported.</para>
+
+<para>You can also compress or decompress files to the standard
+output by giving the <computeroutput>-c</computeroutput> flag.
+Multiple files may be compressed and decompressed like this. The
+resulting outputs are fed sequentially to stdout. Compression of
+multiple files in this manner generates a stream containing
+multiple compressed file representations. Such a stream can be
+decompressed correctly only by
+<computeroutput>bzip2</computeroutput> version 0.9.0 or later.
+Earlier versions of <computeroutput>bzip2</computeroutput> will
+stop after decompressing the first file in the stream.</para>
+
+<para><computeroutput>bzcat</computeroutput> (or
+<computeroutput>bzip2 -dc</computeroutput>) decompresses all
+specified files to the standard output.</para>
+
+<para><computeroutput>bzip2</computeroutput> will read arguments
+from the environment variables
+<computeroutput>BZIP2</computeroutput> and
+<computeroutput>BZIP</computeroutput>, in that order, and will
+process them before any arguments read from the command line.
+This gives a convenient way to supply default arguments.</para>
+
+<para>Compression is always performed, even if the compressed
+file is slightly larger than the original. Files of less than
+about one hundred bytes tend to get larger, since the compression
+mechanism has a constant overhead in the region of 50 bytes.
+Random data (including the output of most file compressors) is
+coded at about 8.05 bits per byte, giving an expansion of around
+0.5%.</para>
+
+<para>As a self-check for your protection,
+<computeroutput>bzip2</computeroutput> uses 32-bit CRCs to make
+sure that the decompressed version of a file is identical to the
+original. This guards against corruption of the compressed data,
+and against undetected bugs in
+<computeroutput>bzip2</computeroutput> (hopefully very unlikely).
+The chances of data corruption going undetected is microscopic,
+about one chance in four billion for each file processed. Be
+aware, though, that the check occurs upon decompression, so it
+can only tell you that something is wrong. It can't help you
+recover the original uncompressed data. You can use
+<computeroutput>bzip2recover</computeroutput> to try to recover
+data from damaged files.</para>
+
+<para>Return values: 0 for a normal exit, 1 for environmental
+problems (file not found, invalid flags, I/O errors, etc.), 2
+to indicate a corrupt compressed file, 3 for an internal
+consistency error (eg, bug) which caused
+<computeroutput>bzip2</computeroutput> to panic.</para>
+
+</sect1>
+
+
+<sect1 id="options" xreflabel="OPTIONS">
+<title>OPTIONS</title>
+
+<variablelist>
+
+ <varlistentry>
+ <term><computeroutput>-c --stdout</computeroutput></term>
+ <listitem><para>Compress or decompress to standard
+ output.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-d --decompress</computeroutput></term>
+ <listitem><para>Force decompression.
+ <computeroutput>bzip2</computeroutput>,
+ <computeroutput>bunzip2</computeroutput> and
+ <computeroutput>bzcat</computeroutput> are really the same
+ program, and the decision about what actions to take is done on
+ the basis of which name is used. This flag overrides that
+ mechanism, and forces bzip2 to decompress.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-z --compress</computeroutput></term>
+ <listitem><para>The complement to
+ <computeroutput>-d</computeroutput>: forces compression,
+ regardless of the invokation name.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-t --test</computeroutput></term>
+ <listitem><para>Check integrity of the specified file(s), but
+ don't decompress them. This really performs a trial
+ decompression and throws away the result.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-f --force</computeroutput></term>
+ <listitem><para>Force overwrite of output files. Normally,
+ <computeroutput>bzip2</computeroutput> will not overwrite
+ existing output files. Also forces
+ <computeroutput>bzip2</computeroutput> to break hard links to
+ files, which it otherwise wouldn't do.</para>
+ <para><computeroutput>bzip2</computeroutput> normally declines
+ to decompress files which don't have the correct magic header
+ bytes. If forced (<computeroutput>-f</computeroutput>),
+ however, it will pass such files through unmodified. This is
+ how GNU <computeroutput>gzip</computeroutput> behaves.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-k --keep</computeroutput></term>
+ <listitem><para>Keep (don't delete) input files during
+ compression or decompression.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-s --small</computeroutput></term>
+ <listitem><para>Reduce memory usage, for compression,
+ decompression and testing. Files are decompressed and tested
+ using a modified algorithm which only requires 2.5 bytes per
+ block byte. This means any file can be decompressed in 2300k
+ of memory, albeit at about half the normal speed.</para>
+ <para>During compression, <computeroutput>-s</computeroutput>
+ selects a block size of 200k, which limits memory use to around
+ the same figure, at the expense of your compression ratio. In
+ short, if your machine is low on memory (8 megabytes or less),
+ use <computeroutput>-s</computeroutput> for everything. See
+ <xref linkend="memory-management"/> below.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-q --quiet</computeroutput></term>
+ <listitem><para>Suppress non-essential warning messages.
+ Messages pertaining to I/O errors and other critical events
+ will not be suppressed.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-v --verbose</computeroutput></term>
+ <listitem><para>Verbose mode -- show the compression ratio for
+ each file processed. Further
+ <computeroutput>-v</computeroutput>'s increase the verbosity
+ level, spewing out lots of information which is primarily of
+ interest for diagnostic purposes.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-L --license -V --version</computeroutput></term>
+ <listitem><para>Display the software version, license terms and
+ conditions.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>-1</computeroutput> (or
+ <computeroutput>--fast</computeroutput>) to
+ <computeroutput>-9</computeroutput> (or
+ <computeroutput>-best</computeroutput>)</term>
+ <listitem><para>Set the block size to 100 k, 200 k ... 900 k
+ when compressing. Has no effect when decompressing. See <xref
+ linkend="memory-management" /> below. The
+ <computeroutput>--fast</computeroutput> and
+ <computeroutput>--best</computeroutput> aliases are primarily
+ for GNU <computeroutput>gzip</computeroutput> compatibility.
+ In particular, <computeroutput>--fast</computeroutput> doesn't
+ make things significantly faster. And
+ <computeroutput>--best</computeroutput> merely selects the
+ default behaviour.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>--</computeroutput></term>
+ <listitem><para>Treats all subsequent arguments as file names,
+ even if they start with a dash. This is so you can handle
+ files with names beginning with a dash, for example:
+ <computeroutput>bzip2 --
+ -myfilename</computeroutput>.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>--repetitive-fast</computeroutput></term>
+ <term><computeroutput>--repetitive-best</computeroutput></term>
+ <listitem><para>These flags are redundant in versions 0.9.5 and
+ above. They provided some coarse control over the behaviour of
+ the sorting algorithm in earlier versions, which was sometimes
+ useful. 0.9.5 and above have an improved algorithm which
+ renders these flags irrelevant.</para></listitem>
+ </varlistentry>
+
+</variablelist>
+
+</sect1>
+
+
+<sect1 id="memory-management" xreflabel="MEMORY MANAGEMENT">
+<title>MEMORY MANAGEMENT</title>
+
+<para><computeroutput>bzip2</computeroutput> compresses large
+files in blocks. The block size affects both the compression
+ratio achieved, and the amount of memory needed for compression
+and decompression. The flags <computeroutput>-1</computeroutput>
+through <computeroutput>-9</computeroutput> specify the block
+size to be 100,000 bytes through 900,000 bytes (the default)
+respectively. At decompression time, the block size used for
+compression is read from the header of the compressed file, and
+<computeroutput>bunzip2</computeroutput> then allocates itself
+just enough memory to decompress the file. Since block sizes are
+stored in compressed files, it follows that the flags
+<computeroutput>-1</computeroutput> to
+<computeroutput>-9</computeroutput> are irrelevant to and so
+ignored during decompression.</para>
+
+<para>Compression and decompression requirements, in bytes, can be
+estimated as:</para>
+<programlisting>
+Compression: 400k + ( 8 x block size )
+
+Decompression: 100k + ( 4 x block size ), or
+ 100k + ( 2.5 x block size )
+</programlisting>
+
+<para>Larger block sizes give rapidly diminishing marginal
+returns. Most of the compression comes from the first two or
+three hundred k of block size, a fact worth bearing in mind when
+using <computeroutput>bzip2</computeroutput> on small machines.
+It is also important to appreciate that the decompression memory
+requirement is set at compression time by the choice of block
+size.</para>
+
+<para>For files compressed with the default 900k block size,
+<computeroutput>bunzip2</computeroutput> will require about 3700
+kbytes to decompress. To support decompression of any file on a
+4 megabyte machine, <computeroutput>bunzip2</computeroutput> has
+an option to decompress using approximately half this amount of
+memory, about 2300 kbytes. Decompression speed is also halved,
+so you should use this option only where necessary. The relevant
+flag is <computeroutput>-s</computeroutput>.</para>
+
+<para>In general, try and use the largest block size memory
+constraints allow, since that maximises the compression achieved.
+Compression and decompression speed are virtually unaffected by
+block size.</para>
+
+<para>Another significant point applies to files which fit in a
+single block -- that means most files you'd encounter using a
+large block size. The amount of real memory touched is
+proportional to the size of the file, since the file is smaller
+than a block. For example, compressing a file 20,000 bytes long
+with the flag <computeroutput>-9</computeroutput> will cause the
+compressor to allocate around 7600k of memory, but only touch
+400k + 20000 * 8 = 560 kbytes of it. Similarly, the decompressor
+will allocate 3700k but only touch 100k + 20000 * 4 = 180
+kbytes.</para>
+
+<para>Here is a table which summarises the maximum memory usage
+for different block sizes. Also recorded is the total compressed
+size for 14 files of the Calgary Text Compression Corpus
+totalling 3,141,622 bytes. This column gives some feel for how
+compression varies with block size. These figures tend to
+understate the advantage of larger block sizes for larger files,
+since the Corpus is dominated by smaller files.</para>
+
+<programlisting>
+ Compress Decompress Decompress Corpus
+Flag usage usage -s usage Size
+
+ -1 1200k 500k 350k 914704
+ -2 2000k 900k 600k 877703
+ -3 2800k 1300k 850k 860338
+ -4 3600k 1700k 1100k 846899
+ -5 4400k 2100k 1350k 845160
+ -6 5200k 2500k 1600k 838626
+ -7 6100k 2900k 1850k 834096
+ -8 6800k 3300k 2100k 828642
+ -9 7600k 3700k 2350k 828642
+</programlisting>
+
+</sect1>
+
+
+<sect1 id="recovering" xreflabel="RECOVERING DATA FROM DAMAGED FILES">
+<title>RECOVERING DATA FROM DAMAGED FILES</title>
+
+<para><computeroutput>bzip2</computeroutput> compresses files in
+blocks, usually 900kbytes long. Each block is handled
+independently. If a media or transmission error causes a
+multi-block <computeroutput>.bz2</computeroutput> file to become
+damaged, it may be possible to recover data from the undamaged
+blocks in the file.</para>
+
+<para>The compressed representation of each block is delimited by
+a 48-bit pattern, which makes it possible to find the block
+boundaries with reasonable certainty. Each block also carries
+its own 32-bit CRC, so damaged blocks can be distinguished from
+undamaged ones.</para>
+
+<para><computeroutput>bzip2recover</computeroutput> is a simple
+program whose purpose is to search for blocks in
+<computeroutput>.bz2</computeroutput> files, and write each block
+out into its own <computeroutput>.bz2</computeroutput> file. You
+can then use <computeroutput>bzip2 -t</computeroutput> to test
+the integrity of the resulting files, and decompress those which
+are undamaged.</para>
+
+<para><computeroutput>bzip2recover</computeroutput> takes a
+single argument, the name of the damaged file, and writes a
+number of files <computeroutput>rec0001file.bz2</computeroutput>,
+<computeroutput>rec0002file.bz2</computeroutput>, etc, containing
+the extracted blocks. The output filenames are designed so that
+the use of wildcards in subsequent processing -- for example,
+<computeroutput>bzip2 -dc rec*file.bz2 &#62;
+recovered_data</computeroutput> -- lists the files in the correct
+order.</para>
+
+<para><computeroutput>bzip2recover</computeroutput> should be of
+most use dealing with large <computeroutput>.bz2</computeroutput>
+files, as these will contain many blocks. It is clearly futile
+to use it on damaged single-block files, since a damaged block
+cannot be recovered. If you wish to minimise any potential data
+loss through media or transmission errors, you might consider
+compressing with a smaller block size.</para>
+
+</sect1>
+
+
+<sect1 id="performance" xreflabel="PERFORMANCE NOTES">
+<title>PERFORMANCE NOTES</title>
+
+<para>The sorting phase of compression gathers together similar
+strings in the file. Because of this, files containing very long
+runs of repeated symbols, like "aabaabaabaab ..." (repeated
+several hundred times) may compress more slowly than normal.
+Versions 0.9.5 and above fare much better than previous versions
+in this respect. The ratio between worst-case and average-case
+compression time is in the region of 10:1. For previous
+versions, this figure was more like 100:1. You can use the
+<computeroutput>-vvvv</computeroutput> option to monitor progress
+in great detail, if you want.</para>
+
+<para>Decompression speed is unaffected by these
+phenomena.</para>
+
+<para><computeroutput>bzip2</computeroutput> usually allocates
+several megabytes of memory to operate in, and then charges all
+over it in a fairly random fashion. This means that performance,
+both for compressing and decompressing, is largely determined by
+the speed at which your machine can service cache misses.
+Because of this, small changes to the code to reduce the miss
+rate have been observed to give disproportionately large
+performance improvements. I imagine
+<computeroutput>bzip2</computeroutput> will perform best on
+machines with very large caches.</para>
+
+</sect1>
+
+
+
+<sect1 id="caveats" xreflabel="CAVEATS">
+<title>CAVEATS</title>
+
+<para>I/O error messages are not as helpful as they could be.
+<computeroutput>bzip2</computeroutput> tries hard to detect I/O
+errors and exit cleanly, but the details of what the problem is
+sometimes seem rather misleading.</para>
+
+<para>This manual page pertains to version &bz-version; of
+<computeroutput>bzip2</computeroutput>. Compressed data created by
+this version is entirely forwards and backwards compatible with the
+previous public releases, versions 0.1pl2, 0.9.0 and 0.9.5, 1.0.0,
+1.0.1, 1.0.2 and 1.0.3, but with the following exception: 0.9.0 and
+above can correctly decompress multiple concatenated compressed files.
+0.1pl2 cannot do this; it will stop after decompressing just the first
+file in the stream.</para>
+
+<para><computeroutput>bzip2recover</computeroutput> versions
+prior to 1.0.2 used 32-bit integers to represent bit positions in
+compressed files, so it could not handle compressed files more
+than 512 megabytes long. Versions 1.0.2 and above use 64-bit ints
+on some platforms which support them (GNU supported targets, and
+Windows). To establish whether or not
+<computeroutput>bzip2recover</computeroutput> was built with such
+a limitation, run it without arguments. In any event you can
+build yourself an unlimited version if you can recompile it with
+<computeroutput>MaybeUInt64</computeroutput> set to be an
+unsigned 64-bit integer.</para>
+
+</sect1>
+
+
+
+<sect1 id="author" xreflabel="AUTHOR">
+<title>AUTHOR</title>
+
+<para>Julian Seward,
+<computeroutput>&bz-email;</computeroutput></para>
+
+<para>The ideas embodied in
+<computeroutput>bzip2</computeroutput> are due to (at least) the
+following people: Michael Burrows and David Wheeler (for the
+block sorting transformation), David Wheeler (again, for the
+Huffman coder), Peter Fenwick (for the structured coding model in
+the original <computeroutput>bzip</computeroutput>, and many
+refinements), and Alistair Moffat, Radford Neal and Ian Witten
+(for the arithmetic coder in the original
+<computeroutput>bzip</computeroutput>). I am much indebted for
+their help, support and advice. See the manual in the source
+distribution for pointers to sources of documentation. Christian
+von Roques encouraged me to look for faster sorting algorithms,
+so as to speed up compression. Bela Lubkin encouraged me to
+improve the worst-case compression performance.
+Donna Robinson XMLised the documentation.
+Many people sent
+patches, helped with portability problems, lent machines, gave
+advice and were generally helpful.</para>
+
+</sect1>
+
+</chapter>
+
+
+
+<chapter id="libprog" xreflabel="Programming with libbzip2">
+<title>
+Programming with <computeroutput>libbzip2</computeroutput>
+</title>
+
+<para>This chapter describes the programming interface to
+<computeroutput>libbzip2</computeroutput>.</para>
+
+<para>For general background information, particularly about
+memory use and performance aspects, you'd be well advised to read
+<xref linkend="using"/> as well.</para>
+
+
+<sect1 id="top-level" xreflabel="Top-level structure">
+<title>Top-level structure</title>
+
+<para><computeroutput>libbzip2</computeroutput> is a flexible
+library for compressing and decompressing data in the
+<computeroutput>bzip2</computeroutput> data format. Although
+packaged as a single entity, it helps to regard the library as
+three separate parts: the low level interface, and the high level
+interface, and some utility functions.</para>
+
+<para>The structure of
+<computeroutput>libbzip2</computeroutput>'s interfaces is similar
+to that of Jean-loup Gailly's and Mark Adler's excellent
+<computeroutput>zlib</computeroutput> library.</para>
+
+<para>All externally visible symbols have names beginning
+<computeroutput>BZ2_</computeroutput>. This is new in version
+1.0. The intention is to minimise pollution of the namespaces of
+library clients.</para>
+
+<para>To use any part of the library, you need to
+<computeroutput>#include &lt;bzlib.h&gt;</computeroutput>
+into your sources.</para>
+
+
+
+<sect2 id="ll-summary" xreflabel="Low-level summary">
+<title>Low-level summary</title>
+
+<para>This interface provides services for compressing and
+decompressing data in memory. There's no provision for dealing
+with files, streams or any other I/O mechanisms, just straight
+memory-to-memory work. In fact, this part of the library can be
+compiled without inclusion of
+<computeroutput>stdio.h</computeroutput>, which may be helpful
+for embedded applications.</para>
+
+<para>The low-level part of the library has no global variables
+and is therefore thread-safe.</para>
+
+<para>Six routines make up the low level interface:
+<computeroutput>BZ2_bzCompressInit</computeroutput>,
+<computeroutput>BZ2_bzCompress</computeroutput>, and
+<computeroutput>BZ2_bzCompressEnd</computeroutput> for
+compression, and a corresponding trio
+<computeroutput>BZ2_bzDecompressInit</computeroutput>,
+<computeroutput>BZ2_bzDecompress</computeroutput> and
+<computeroutput>BZ2_bzDecompressEnd</computeroutput> for
+decompression. The <computeroutput>*Init</computeroutput>
+functions allocate memory for compression/decompression and do
+other initialisations, whilst the
+<computeroutput>*End</computeroutput> functions close down
+operations and release memory.</para>
+
+<para>The real work is done by
+<computeroutput>BZ2_bzCompress</computeroutput> and
+<computeroutput>BZ2_bzDecompress</computeroutput>. These
+compress and decompress data from a user-supplied input buffer to
+a user-supplied output buffer. These buffers can be any size;
+arbitrary quantities of data are handled by making repeated calls
+to these functions. This is a flexible mechanism allowing a
+consumer-pull style of activity, or producer-push, or a mixture
+of both.</para>
+
+</sect2>
+
+
+<sect2 id="hl-summary" xreflabel="High-level summary">
+<title>High-level summary</title>
+
+<para>This interface provides some handy wrappers around the
+low-level interface to facilitate reading and writing
+<computeroutput>bzip2</computeroutput> format files
+(<computeroutput>.bz2</computeroutput> files). The routines
+provide hooks to facilitate reading files in which the
+<computeroutput>bzip2</computeroutput> data stream is embedded
+within some larger-scale file structure, or where there are
+multiple <computeroutput>bzip2</computeroutput> data streams
+concatenated end-to-end.</para>
+
+<para>For reading files,
+<computeroutput>BZ2_bzReadOpen</computeroutput>,
+<computeroutput>BZ2_bzRead</computeroutput>,
+<computeroutput>BZ2_bzReadClose</computeroutput> and
+<computeroutput>BZ2_bzReadGetUnused</computeroutput> are
+supplied. For writing files,
+<computeroutput>BZ2_bzWriteOpen</computeroutput>,
+<computeroutput>BZ2_bzWrite</computeroutput> and
+<computeroutput>BZ2_bzWriteFinish</computeroutput> are
+available.</para>
+
+<para>As with the low-level library, no global variables are used
+so the library is per se thread-safe. However, if I/O errors
+occur whilst reading or writing the underlying compressed files,
+you may have to consult <computeroutput>errno</computeroutput> to
+determine the cause of the error. In that case, you'd need a C
+library which correctly supports
+<computeroutput>errno</computeroutput> in a multithreaded
+environment.</para>
+
+<para>To make the library a little simpler and more portable,
+<computeroutput>BZ2_bzReadOpen</computeroutput> and
+<computeroutput>BZ2_bzWriteOpen</computeroutput> require you to
+pass them file handles (<computeroutput>FILE*</computeroutput>s)
+which have previously been opened for reading or writing
+respectively. That avoids portability problems associated with
+file operations and file attributes, whilst not being much of an
+imposition on the programmer.</para>
+
+</sect2>
+
+
+<sect2 id="util-fns-summary" xreflabel="Utility functions summary">
+<title>Utility functions summary</title>
+
+<para>For very simple needs,
+<computeroutput>BZ2_bzBuffToBuffCompress</computeroutput> and
+<computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput> are
+provided. These compress data in memory from one buffer to
+another buffer in a single function call. You should assess
+whether these functions fulfill your memory-to-memory
+compression/decompression requirements before investing effort in
+understanding the more general but more complex low-level
+interface.</para>
+
+<para>Yoshioka Tsuneo
+(<computeroutput>tsuneo@rr.iij4u.or.jp</computeroutput>) has
+contributed some functions to give better
+<computeroutput>zlib</computeroutput> compatibility. These
+functions are <computeroutput>BZ2_bzopen</computeroutput>,
+<computeroutput>BZ2_bzread</computeroutput>,
+<computeroutput>BZ2_bzwrite</computeroutput>,
+<computeroutput>BZ2_bzflush</computeroutput>,
+<computeroutput>BZ2_bzclose</computeroutput>,
+<computeroutput>BZ2_bzerror</computeroutput> and
+<computeroutput>BZ2_bzlibVersion</computeroutput>. You may find
+these functions more convenient for simple file reading and
+writing, than those in the high-level interface. These functions
+are not (yet) officially part of the library, and are minimally
+documented here. If they break, you get to keep all the pieces.
+I hope to document them properly when time permits.</para>
+
+<para>Yoshioka also contributed modifications to allow the
+library to be built as a Windows DLL.</para>
+
+</sect2>
+
+</sect1>
+
+
+<sect1 id="err-handling" xreflabel="Error handling">
+<title>Error handling</title>
+
+<para>The library is designed to recover cleanly in all
+situations, including the worst-case situation of decompressing
+random data. I'm not 100% sure that it can always do this, so
+you might want to add a signal handler to catch segmentation
+violations during decompression if you are feeling especially
+paranoid. I would be interested in hearing more about the
+robustness of the library to corrupted compressed data.</para>
+
+<para>Version 1.0.3 more robust in this respect than any
+previous version. Investigations with Valgrind (a tool for detecting
+problems with memory management) indicate
+that, at least for the few files I tested, all single-bit errors
+in the decompressed data are caught properly, with no
+segmentation faults, no uses of uninitialised data, no out of
+range reads or writes, and no infinite looping in the decompressor.
+So it's certainly pretty robust, although
+I wouldn't claim it to be totally bombproof.</para>
+
+<para>The file <computeroutput>bzlib.h</computeroutput> contains
+all definitions needed to use the library. In particular, you
+should definitely not include
+<computeroutput>bzlib_private.h</computeroutput>.</para>
+
+<para>In <computeroutput>bzlib.h</computeroutput>, the various
+return values are defined. The following list is not intended as
+an exhaustive description of the circumstances in which a given
+value may be returned -- those descriptions are given later.
+Rather, it is intended to convey the rough meaning of each return
+value. The first five actions are normal and not intended to
+denote an error situation.</para>
+
+<variablelist>
+
+ <varlistentry>
+ <term><computeroutput>BZ_OK</computeroutput></term>
+ <listitem><para>The requested action was completed
+ successfully.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_RUN_OK, BZ_FLUSH_OK,
+ BZ_FINISH_OK</computeroutput></term>
+ <listitem><para>In
+ <computeroutput>BZ2_bzCompress</computeroutput>, the requested
+ flush/finish/nothing-special action was completed
+ successfully.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_STREAM_END</computeroutput></term>
+ <listitem><para>Compression of data was completed, or the
+ logical stream end was detected during
+ decompression.</para></listitem>
+ </varlistentry>
+
+</variablelist>
+
+<para>The following return values indicate an error of some
+kind.</para>
+
+<variablelist>
+
+ <varlistentry>
+ <term><computeroutput>BZ_CONFIG_ERROR</computeroutput></term>
+ <listitem><para>Indicates that the library has been improperly
+ compiled on your platform -- a major configuration error.
+ Specifically, it means that
+ <computeroutput>sizeof(char)</computeroutput>,
+ <computeroutput>sizeof(short)</computeroutput> and
+ <computeroutput>sizeof(int)</computeroutput> are not 1, 2 and
+ 4 respectively, as they should be. Note that the library
+ should still work properly on 64-bit platforms which follow
+ the LP64 programming model -- that is, where
+ <computeroutput>sizeof(long)</computeroutput> and
+ <computeroutput>sizeof(void*)</computeroutput> are 8. Under
+ LP64, <computeroutput>sizeof(int)</computeroutput> is still 4,
+ so <computeroutput>libbzip2</computeroutput>, which doesn't
+ use the <computeroutput>long</computeroutput> type, is
+ OK.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_SEQUENCE_ERROR</computeroutput></term>
+ <listitem><para>When using the library, it is important to call
+ the functions in the correct sequence and with data structures
+ (buffers etc) in the correct states.
+ <computeroutput>libbzip2</computeroutput> checks as much as it
+ can to ensure this is happening, and returns
+ <computeroutput>BZ_SEQUENCE_ERROR</computeroutput> if not.
+ Code which complies precisely with the function semantics, as
+ detailed below, should never receive this value; such an event
+ denotes buggy code which you should
+ investigate.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_PARAM_ERROR</computeroutput></term>
+ <listitem><para>Returned when a parameter to a function call is
+ out of range or otherwise manifestly incorrect. As with
+ <computeroutput>BZ_SEQUENCE_ERROR</computeroutput>, this
+ denotes a bug in the client code. The distinction between
+ <computeroutput>BZ_PARAM_ERROR</computeroutput> and
+ <computeroutput>BZ_SEQUENCE_ERROR</computeroutput> is a bit
+ hazy, but still worth making.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_MEM_ERROR</computeroutput></term>
+ <listitem><para>Returned when a request to allocate memory
+ failed. Note that the quantity of memory needed to decompress
+ a stream cannot be determined until the stream's header has
+ been read. So
+ <computeroutput>BZ2_bzDecompress</computeroutput> and
+ <computeroutput>BZ2_bzRead</computeroutput> may return
+ <computeroutput>BZ_MEM_ERROR</computeroutput> even though some
+ of the compressed data has been read. The same is not true
+ for compression; once
+ <computeroutput>BZ2_bzCompressInit</computeroutput> or
+ <computeroutput>BZ2_bzWriteOpen</computeroutput> have
+ successfully completed,
+ <computeroutput>BZ_MEM_ERROR</computeroutput> cannot
+ occur.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_DATA_ERROR</computeroutput></term>
+ <listitem><para>Returned when a data integrity error is
+ detected during decompression. Most importantly, this means
+ when stored and computed CRCs for the data do not match. This
+ value is also returned upon detection of any other anomaly in
+ the compressed data.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_DATA_ERROR_MAGIC</computeroutput></term>
+ <listitem><para>As a special case of
+ <computeroutput>BZ_DATA_ERROR</computeroutput>, it is
+ sometimes useful to know when the compressed stream does not
+ start with the correct magic bytes (<computeroutput>'B' 'Z'
+ 'h'</computeroutput>).</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_IO_ERROR</computeroutput></term>
+ <listitem><para>Returned by
+ <computeroutput>BZ2_bzRead</computeroutput> and
+ <computeroutput>BZ2_bzWrite</computeroutput> when there is an
+ error reading or writing in the compressed file, and by
+ <computeroutput>BZ2_bzReadOpen</computeroutput> and
+ <computeroutput>BZ2_bzWriteOpen</computeroutput> for attempts
+ to use a file for which the error indicator (viz,
+ <computeroutput>ferror(f)</computeroutput>) is set. On
+ receipt of <computeroutput>BZ_IO_ERROR</computeroutput>, the
+ caller should consult <computeroutput>errno</computeroutput>
+ and/or <computeroutput>perror</computeroutput> to acquire
+ operating-system specific information about the
+ problem.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_UNEXPECTED_EOF</computeroutput></term>
+ <listitem><para>Returned by
+ <computeroutput>BZ2_bzRead</computeroutput> when the
+ compressed file finishes before the logical end of stream is
+ detected.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><computeroutput>BZ_OUTBUFF_FULL</computeroutput></term>
+ <listitem><para>Returned by
+ <computeroutput>BZ2_bzBuffToBuffCompress</computeroutput> and
+ <computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput> to
+ indicate that the output data will not fit into the output
+ buffer provided.</para></listitem>
+ </varlistentry>
+
+</variablelist>
+
+</sect1>
+
+
+
+<sect1 id="low-level" xreflabel=">Low-level interface">
+<title>Low-level interface</title>
+
+
+<sect2 id="bzcompress-init" xreflabel="BZ2_bzCompressInit">
+<title><computeroutput>BZ2_bzCompressInit</computeroutput></title>
+
+<programlisting>
+typedef struct {
+ char *next_in;
+ unsigned int avail_in;
+ unsigned int total_in_lo32;
+ unsigned int total_in_hi32;
+
+ char *next_out;
+ unsigned int avail_out;
+ unsigned int total_out_lo32;
+ unsigned int total_out_hi32;
+
+ void *state;
+
+ void *(*bzalloc)(void *,int,int);
+ void (*bzfree)(void *,void *);
+ void *opaque;
+} bz_stream;
+
+int BZ2_bzCompressInit ( bz_stream *strm,
+ int blockSize100k,
+ int verbosity,
+ int workFactor );
+</programlisting>
+
+<para>Prepares for compression. The
+<computeroutput>bz_stream</computeroutput> structure holds all
+data pertaining to the compression activity. A
+<computeroutput>bz_stream</computeroutput> structure should be
+allocated and initialised prior to the call. The fields of
+<computeroutput>bz_stream</computeroutput> comprise the entirety
+of the user-visible data. <computeroutput>state</computeroutput>
+is a pointer to the private data structures required for
+compression.</para>
+
+<para>Custom memory allocators are supported, via fields
+<computeroutput>bzalloc</computeroutput>,
+<computeroutput>bzfree</computeroutput>, and
+<computeroutput>opaque</computeroutput>. The value
+<computeroutput>opaque</computeroutput> is passed to as the first
+argument to all calls to <computeroutput>bzalloc</computeroutput>
+and <computeroutput>bzfree</computeroutput>, but is otherwise
+ignored by the library. The call <computeroutput>bzalloc (
+opaque, n, m )</computeroutput> is expected to return a pointer
+<computeroutput>p</computeroutput> to <computeroutput>n *
+m</computeroutput> bytes of memory, and <computeroutput>bzfree (
+opaque, p )</computeroutput> should free that memory.</para>
+
+<para>If you don't want to use a custom memory allocator, set
+<computeroutput>bzalloc</computeroutput>,
+<computeroutput>bzfree</computeroutput> and
+<computeroutput>opaque</computeroutput> to
+<computeroutput>NULL</computeroutput>, and the library will then
+use the standard <computeroutput>malloc</computeroutput> /
+<computeroutput>free</computeroutput> routines.</para>
+
+<para>Before calling
+<computeroutput>BZ2_bzCompressInit</computeroutput>, fields
+<computeroutput>bzalloc</computeroutput>,
+<computeroutput>bzfree</computeroutput> and
+<computeroutput>opaque</computeroutput> should be filled
+appropriately, as just described. Upon return, the internal
+state will have been allocated and initialised, and
+<computeroutput>total_in_lo32</computeroutput>,
+<computeroutput>total_in_hi32</computeroutput>,
+<computeroutput>total_out_lo32</computeroutput> and
+<computeroutput>total_out_hi32</computeroutput> will have been
+set to zero. These four fields are used by the library to inform
+the caller of the total amount of data passed into and out of the
+library, respectively. You should not try to change them. As of
+version 1.0, 64-bit counts are maintained, even on 32-bit
+platforms, using the <computeroutput>_hi32</computeroutput>
+fields to store the upper 32 bits of the count. So, for example,
+the total amount of data in is <computeroutput>(total_in_hi32
+&#60;&#60; 32) + total_in_lo32</computeroutput>.</para>
+
+<para>Parameter <computeroutput>blockSize100k</computeroutput>
+specifies the block size to be used for compression. It should
+be a value between 1 and 9 inclusive, and the actual block size
+used is 100000 x this figure. 9 gives the best compression but
+takes most memory.</para>
+
+<para>Parameter <computeroutput>verbosity</computeroutput> should
+be set to a number between 0 and 4 inclusive. 0 is silent, and
+greater numbers give increasingly verbose monitoring/debugging
+output. If the library has been compiled with
+<computeroutput>-DBZ_NO_STDIO</computeroutput>, no such output
+will appear for any verbosity setting.</para>
+
+<para>Parameter <computeroutput>workFactor</computeroutput>
+controls how the compression phase behaves when presented with
+worst case, highly repetitive, input data. If compression runs
+into difficulties caused by repetitive data, the library switches
+from the standard sorting algorithm to a fallback algorithm. The
+fallback is slower than the standard algorithm by perhaps a
+factor of three, but always behaves reasonably, no matter how bad
+the input.</para>
+
+<para>Lower values of <computeroutput>workFactor</computeroutput>
+reduce the amount of effort the standard algorithm will expend
+before resorting to the fallback. You should set this parameter
+carefully; too low, and many inputs will be handled by the
+fallback algorithm and so compress rather slowly, too high, and
+your average-to-worst case compression times can become very
+large. The default value of 30 gives reasonable behaviour over a
+wide range of circumstances.</para>
+
+<para>Allowable values range from 0 to 250 inclusive. 0 is a
+special case, equivalent to using the default value of 30.</para>
+
+<para>Note that the compressed output generated is the same
+regardless of whether or not the fallback algorithm is
+used.</para>
+
+<para>Be aware also that this parameter may disappear entirely in
+future versions of the library. In principle it should be
+possible to devise a good way to automatically choose which
+algorithm to use. Such a mechanism would render the parameter
+obsolete.</para>
+
+<para>Possible return values:</para>
+
+<programlisting>
+BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if strm is NULL
+ or blockSize < 1 or blockSize > 9
+ or verbosity < 0 or verbosity > 4
+ or workFactor < 0 or workFactor > 250
+BZ_MEM_ERROR
+ if not enough memory is available
+BZ_OK
+ otherwise
+</programlisting>
+
+<para>Allowable next actions:</para>
+
+<programlisting>
+BZ2_bzCompress
+ if BZ_OK is returned
+ no specific action needed in case of error
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzCompress" xreflabel="BZ2_bzCompress">
+<title><computeroutput>BZ2_bzCompress</computeroutput></title>
+
+<programlisting>
+int BZ2_bzCompress ( bz_stream *strm, int action );
+</programlisting>
+
+<para>Provides more input and/or output buffer space for the
+library. The caller maintains input and output buffers, and
+calls <computeroutput>BZ2_bzCompress</computeroutput> to transfer
+data between them.</para>
+
+<para>Before each call to
+<computeroutput>BZ2_bzCompress</computeroutput>,
+<computeroutput>next_in</computeroutput> should point at the data
+to be compressed, and <computeroutput>avail_in</computeroutput>
+should indicate how many bytes the library may read.
+<computeroutput>BZ2_bzCompress</computeroutput> updates
+<computeroutput>next_in</computeroutput>,
+<computeroutput>avail_in</computeroutput> and
+<computeroutput>total_in</computeroutput> to reflect the number
+of bytes it has read.</para>
+
+<para>Similarly, <computeroutput>next_out</computeroutput> should
+point to a buffer in which the compressed data is to be placed,
+with <computeroutput>avail_out</computeroutput> indicating how
+much output space is available.
+<computeroutput>BZ2_bzCompress</computeroutput> updates
+<computeroutput>next_out</computeroutput>,
+<computeroutput>avail_out</computeroutput> and
+<computeroutput>total_out</computeroutput> to reflect the number
+of bytes output.</para>
+
+<para>You may provide and remove as little or as much data as you
+like on each call of
+<computeroutput>BZ2_bzCompress</computeroutput>. In the limit,
+it is acceptable to supply and remove data one byte at a time,
+although this would be terribly inefficient. You should always
+ensure that at least one byte of output space is available at
+each call.</para>
+
+<para>A second purpose of
+<computeroutput>BZ2_bzCompress</computeroutput> is to request a
+change of mode of the compressed stream.</para>
+
+<para>Conceptually, a compressed stream can be in one of four
+states: IDLE, RUNNING, FLUSHING and FINISHING. Before
+initialisation
+(<computeroutput>BZ2_bzCompressInit</computeroutput>) and after
+termination (<computeroutput>BZ2_bzCompressEnd</computeroutput>),
+a stream is regarded as IDLE.</para>
+
+<para>Upon initialisation
+(<computeroutput>BZ2_bzCompressInit</computeroutput>), the stream
+is placed in the RUNNING state. Subsequent calls to
+<computeroutput>BZ2_bzCompress</computeroutput> should pass
+<computeroutput>BZ_RUN</computeroutput> as the requested action;
+other actions are illegal and will result in
+<computeroutput>BZ_SEQUENCE_ERROR</computeroutput>.</para>
+
+<para>At some point, the calling program will have provided all
+the input data it wants to. It will then want to finish up -- in
+effect, asking the library to process any data it might have
+buffered internally. In this state,
+<computeroutput>BZ2_bzCompress</computeroutput> will no longer
+attempt to read data from
+<computeroutput>next_in</computeroutput>, but it will want to
+write data to <computeroutput>next_out</computeroutput>. Because
+the output buffer supplied by the user can be arbitrarily small,
+the finishing-up operation cannot necessarily be done with a
+single call of
+<computeroutput>BZ2_bzCompress</computeroutput>.</para>
+
+<para>Instead, the calling program passes
+<computeroutput>BZ_FINISH</computeroutput> as an action to
+<computeroutput>BZ2_bzCompress</computeroutput>. This changes
+the stream's state to FINISHING. Any remaining input (ie,
+<computeroutput>next_in[0 .. avail_in-1]</computeroutput>) is
+compressed and transferred to the output buffer. To do this,
+<computeroutput>BZ2_bzCompress</computeroutput> must be called
+repeatedly until all the output has been consumed. At that
+point, <computeroutput>BZ2_bzCompress</computeroutput> returns
+<computeroutput>BZ_STREAM_END</computeroutput>, and the stream's
+state is set back to IDLE.
+<computeroutput>BZ2_bzCompressEnd</computeroutput> should then be
+called.</para>
+
+<para>Just to make sure the calling program does not cheat, the
+library makes a note of <computeroutput>avail_in</computeroutput>
+at the time of the first call to
+<computeroutput>BZ2_bzCompress</computeroutput> which has
+<computeroutput>BZ_FINISH</computeroutput> as an action (ie, at
+the time the program has announced its intention to not supply
+any more input). By comparing this value with that of
+<computeroutput>avail_in</computeroutput> over subsequent calls
+to <computeroutput>BZ2_bzCompress</computeroutput>, the library
+can detect any attempts to slip in more data to compress. Any
+calls for which this is detected will return
+<computeroutput>BZ_SEQUENCE_ERROR</computeroutput>. This
+indicates a programming mistake which should be corrected.</para>
+
+<para>Instead of asking to finish, the calling program may ask
+<computeroutput>BZ2_bzCompress</computeroutput> to take all the
+remaining input, compress it and terminate the current
+(Burrows-Wheeler) compression block. This could be useful for
+error control purposes. The mechanism is analogous to that for
+finishing: call <computeroutput>BZ2_bzCompress</computeroutput>
+with an action of <computeroutput>BZ_FLUSH</computeroutput>,
+remove output data, and persist with the
+<computeroutput>BZ_FLUSH</computeroutput> action until the value
+<computeroutput>BZ_RUN</computeroutput> is returned. As with
+finishing, <computeroutput>BZ2_bzCompress</computeroutput>
+detects any attempt to provide more input data once the flush has
+begun.</para>
+
+<para>Once the flush is complete, the stream returns to the
+normal RUNNING state.</para>
+
+<para>This all sounds pretty complex, but isn't really. Here's a
+table which shows which actions are allowable in each state, what
+action will be taken, what the next state is, and what the
+non-error return values are. Note that you can't explicitly ask
+what state the stream is in, but nor do you need to -- it can be
+inferred from the values returned by
+<computeroutput>BZ2_bzCompress</computeroutput>.</para>
+
+<programlisting>
+IDLE/any
+ Illegal. IDLE state only exists after BZ2_bzCompressEnd or
+ before BZ2_bzCompressInit.
+ Return value = BZ_SEQUENCE_ERROR
+
+RUNNING/BZ_RUN
+ Compress from next_in to next_out as much as possible.
+ Next state = RUNNING
+ Return value = BZ_RUN_OK
+
+RUNNING/BZ_FLUSH
+ Remember current value of next_in. Compress from next_in
+ to next_out as much as possible, but do not accept any more input.
+ Next state = FLUSHING
+ Return value = BZ_FLUSH_OK
+
+RUNNING/BZ_FINISH
+ Remember current value of next_in. Compress from next_in
+ to next_out as much as possible, but do not accept any more input.
+ Next state = FINISHING
+ Return value = BZ_FINISH_OK
+
+FLUSHING/BZ_FLUSH
+ Compress from next_in to next_out as much as possible,
+ but do not accept any more input.
+ If all the existing input has been used up and all compressed
+ output has been removed
+ Next state = RUNNING; Return value = BZ_RUN_OK
+ else
+ Next state = FLUSHING; Return value = BZ_FLUSH_OK
+
+FLUSHING/other
+ Illegal.
+ Return value = BZ_SEQUENCE_ERROR
+
+FINISHING/BZ_FINISH
+ Compress from next_in to next_out as much as possible,
+ but to not accept any more input.
+ If all the existing input has been used up and all compressed
+ output has been removed
+ Next state = IDLE; Return value = BZ_STREAM_END
+ else
+ Next state = FINISHING; Return value = BZ_FINISH_OK
+
+FINISHING/other
+ Illegal.
+ Return value = BZ_SEQUENCE_ERROR
+</programlisting>
+
+
+<para>That still looks complicated? Well, fair enough. The
+usual sequence of calls for compressing a load of data is:</para>
+
+<orderedlist>
+
+ <listitem><para>Get started with
+ <computeroutput>BZ2_bzCompressInit</computeroutput>.</para></listitem>
+
+ <listitem><para>Shovel data in and shlurp out its compressed form
+ using zero or more calls of
+ <computeroutput>BZ2_bzCompress</computeroutput> with action =
+ <computeroutput>BZ_RUN</computeroutput>.</para></listitem>
+
+ <listitem><para>Finish up. Repeatedly call
+ <computeroutput>BZ2_bzCompress</computeroutput> with action =
+ <computeroutput>BZ_FINISH</computeroutput>, copying out the
+ compressed output, until
+ <computeroutput>BZ_STREAM_END</computeroutput> is
+ returned.</para></listitem> <listitem><para>Close up and go home. Call
+ <computeroutput>BZ2_bzCompressEnd</computeroutput>.</para></listitem>
+
+</orderedlist>
+
+<para>If the data you want to compress fits into your input
+buffer all at once, you can skip the calls of
+<computeroutput>BZ2_bzCompress ( ..., BZ_RUN )</computeroutput>
+and just do the <computeroutput>BZ2_bzCompress ( ..., BZ_FINISH
+)</computeroutput> calls.</para>
+
+<para>All required memory is allocated by
+<computeroutput>BZ2_bzCompressInit</computeroutput>. The
+compression library can accept any data at all (obviously). So
+you shouldn't get any error return values from the
+<computeroutput>BZ2_bzCompress</computeroutput> calls. If you
+do, they will be
+<computeroutput>BZ_SEQUENCE_ERROR</computeroutput>, and indicate
+a bug in your programming.</para>
+
+<para>Trivial other possible return values:</para>
+
+<programlisting>
+BZ_PARAM_ERROR
+ if strm is NULL, or strm->s is NULL
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzCompress-end" xreflabel="BZ2_bzCompressEnd">
+<title><computeroutput>BZ2_bzCompressEnd</computeroutput></title>
+
+<programlisting>
+int BZ2_bzCompressEnd ( bz_stream *strm );
+</programlisting>
+
+<para>Releases all memory associated with a compression
+stream.</para>
+
+<para>Possible return values:</para>
+
+<programlisting>
+BZ_PARAM_ERROR if strm is NULL or strm->s is NULL
+BZ_OK otherwise
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzDecompress-init" xreflabel="BZ2_bzDecompressInit">
+<title><computeroutput>BZ2_bzDecompressInit</computeroutput></title>
+
+<programlisting>
+int BZ2_bzDecompressInit ( bz_stream *strm, int verbosity, int small );
+</programlisting>
+
+<para>Prepares for decompression. As with
+<computeroutput>BZ2_bzCompressInit</computeroutput>, a
+<computeroutput>bz_stream</computeroutput> record should be
+allocated and initialised before the call. Fields
+<computeroutput>bzalloc</computeroutput>,
+<computeroutput>bzfree</computeroutput> and
+<computeroutput>opaque</computeroutput> should be set if a custom
+memory allocator is required, or made
+<computeroutput>NULL</computeroutput> for the normal
+<computeroutput>malloc</computeroutput> /
+<computeroutput>free</computeroutput> routines. Upon return, the
+internal state will have been initialised, and
+<computeroutput>total_in</computeroutput> and
+<computeroutput>total_out</computeroutput> will be zero.</para>
+
+<para>For the meaning of parameter
+<computeroutput>verbosity</computeroutput>, see
+<computeroutput>BZ2_bzCompressInit</computeroutput>.</para>
+
+<para>If <computeroutput>small</computeroutput> is nonzero, the
+library will use an alternative decompression algorithm which
+uses less memory but at the cost of decompressing more slowly
+(roughly speaking, half the speed, but the maximum memory
+requirement drops to around 2300k). See <xref linkend="using"/>
+for more information on memory management.</para>
+
+<para>Note that the amount of memory needed to decompress a
+stream cannot be determined until the stream's header has been
+read, so even if
+<computeroutput>BZ2_bzDecompressInit</computeroutput> succeeds, a
+subsequent <computeroutput>BZ2_bzDecompress</computeroutput>
+could fail with
+<computeroutput>BZ_MEM_ERROR</computeroutput>.</para>
+
+<para>Possible return values:</para>
+
+<programlisting>
+BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if ( small != 0 && small != 1 )
+ or (verbosity <; 0 || verbosity > 4)
+BZ_MEM_ERROR
+ if insufficient memory is available
+</programlisting>
+
+<para>Allowable next actions:</para>
+
+<programlisting>
+BZ2_bzDecompress
+ if BZ_OK was returned
+ no specific action required in case of error
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzDecompress" xreflabel="BZ2_bzDecompress">
+<title><computeroutput>BZ2_bzDecompress</computeroutput></title>
+
+<programlisting>
+int BZ2_bzDecompress ( bz_stream *strm );
+</programlisting>
+
+<para>Provides more input and/out output buffer space for the
+library. The caller maintains input and output buffers, and uses
+<computeroutput>BZ2_bzDecompress</computeroutput> to transfer
+data between them.</para>
+
+<para>Before each call to
+<computeroutput>BZ2_bzDecompress</computeroutput>,
+<computeroutput>next_in</computeroutput> should point at the
+compressed data, and <computeroutput>avail_in</computeroutput>
+should indicate how many bytes the library may read.
+<computeroutput>BZ2_bzDecompress</computeroutput> updates
+<computeroutput>next_in</computeroutput>,
+<computeroutput>avail_in</computeroutput> and
+<computeroutput>total_in</computeroutput> to reflect the number
+of bytes it has read.</para>
+
+<para>Similarly, <computeroutput>next_out</computeroutput> should
+point to a buffer in which the uncompressed output is to be
+placed, with <computeroutput>avail_out</computeroutput>
+indicating how much output space is available.
+<computeroutput>BZ2_bzCompress</computeroutput> updates
+<computeroutput>next_out</computeroutput>,
+<computeroutput>avail_out</computeroutput> and
+<computeroutput>total_out</computeroutput> to reflect the number
+of bytes output.</para>
+
+<para>You may provide and remove as little or as much data as you
+like on each call of
+<computeroutput>BZ2_bzDecompress</computeroutput>. In the limit,
+it is acceptable to supply and remove data one byte at a time,
+although this would be terribly inefficient. You should always
+ensure that at least one byte of output space is available at
+each call.</para>
+
+<para>Use of <computeroutput>BZ2_bzDecompress</computeroutput> is
+simpler than
+<computeroutput>BZ2_bzCompress</computeroutput>.</para>
+
+<para>You should provide input and remove output as described
+above, and repeatedly call
+<computeroutput>BZ2_bzDecompress</computeroutput> until
+<computeroutput>BZ_STREAM_END</computeroutput> is returned.
+Appearance of <computeroutput>BZ_STREAM_END</computeroutput>
+denotes that <computeroutput>BZ2_bzDecompress</computeroutput>
+has detected the logical end of the compressed stream.
+<computeroutput>BZ2_bzDecompress</computeroutput> will not
+produce <computeroutput>BZ_STREAM_END</computeroutput> until all
+output data has been placed into the output buffer, so once
+<computeroutput>BZ_STREAM_END</computeroutput> appears, you are
+guaranteed to have available all the decompressed output, and
+<computeroutput>BZ2_bzDecompressEnd</computeroutput> can safely
+be called.</para>
+
+<para>If case of an error return value, you should call
+<computeroutput>BZ2_bzDecompressEnd</computeroutput> to clean up
+and release memory.</para>
+
+<para>Possible return values:</para>
+
+<programlisting>
+BZ_PARAM_ERROR
+ if strm is NULL or strm->s is NULL
+ or strm->avail_out < 1
+BZ_DATA_ERROR
+ if a data integrity error is detected in the compressed stream
+BZ_DATA_ERROR_MAGIC
+ if the compressed stream doesn't begin with the right magic bytes
+BZ_MEM_ERROR
+ if there wasn't enough memory available
+BZ_STREAM_END
+ if the logical end of the data stream was detected and all
+ output in has been consumed, eg s-->avail_out > 0
+BZ_OK
+ otherwise
+</programlisting>
+
+<para>Allowable next actions:</para>
+
+<programlisting>
+BZ2_bzDecompress
+ if BZ_OK was returned
+BZ2_bzDecompressEnd
+ otherwise
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzDecompress-end" xreflabel="BZ2_bzDecompressEnd">
+<title><computeroutput>BZ2_bzDecompressEnd</computeroutput></title>
+
+<programlisting>
+int BZ2_bzDecompressEnd ( bz_stream *strm );
+</programlisting>
+
+<para>Releases all memory associated with a decompression
+stream.</para>
+
+<para>Possible return values:</para>
+
+<programlisting>
+BZ_PARAM_ERROR
+ if strm is NULL or strm->s is NULL
+BZ_OK
+ otherwise
+</programlisting>
+
+<para>Allowable next actions:</para>
+
+<programlisting>
+ None.
+</programlisting>
+
+</sect2>
+
+</sect1>
+
+
+<sect1 id="hl-interface" xreflabel="High-level interface">
+<title>High-level interface</title>
+
+<para>This interface provides functions for reading and writing
+<computeroutput>bzip2</computeroutput> format files. First, some
+general points.</para>
+
+<itemizedlist mark='bullet'>
+
+ <listitem><para>All of the functions take an
+ <computeroutput>int*</computeroutput> first argument,
+ <computeroutput>bzerror</computeroutput>. After each call,
+ <computeroutput>bzerror</computeroutput> should be consulted
+ first to determine the outcome of the call. If
+ <computeroutput>bzerror</computeroutput> is
+ <computeroutput>BZ_OK</computeroutput>, the call completed
+ successfully, and only then should the return value of the
+ function (if any) be consulted. If
+ <computeroutput>bzerror</computeroutput> is
+ <computeroutput>BZ_IO_ERROR</computeroutput>, there was an
+ error reading/writing the underlying compressed file, and you
+ should then consult <computeroutput>errno</computeroutput> /
+ <computeroutput>perror</computeroutput> to determine the cause
+ of the difficulty. <computeroutput>bzerror</computeroutput>
+ may also be set to various other values; precise details are
+ given on a per-function basis below.</para></listitem>
+
+ <listitem><para>If <computeroutput>bzerror</computeroutput> indicates
+ an error (ie, anything except
+ <computeroutput>BZ_OK</computeroutput> and
+ <computeroutput>BZ_STREAM_END</computeroutput>), you should
+ immediately call
+ <computeroutput>BZ2_bzReadClose</computeroutput> (or
+ <computeroutput>BZ2_bzWriteClose</computeroutput>, depending on
+ whether you are attempting to read or to write) to free up all
+ resources associated with the stream. Once an error has been
+ indicated, behaviour of all calls except
+ <computeroutput>BZ2_bzReadClose</computeroutput>
+ (<computeroutput>BZ2_bzWriteClose</computeroutput>) is
+ undefined. The implication is that (1)
+ <computeroutput>bzerror</computeroutput> should be checked
+ after each call, and (2) if
+ <computeroutput>bzerror</computeroutput> indicates an error,
+ <computeroutput>BZ2_bzReadClose</computeroutput>
+ (<computeroutput>BZ2_bzWriteClose</computeroutput>) should then
+ be called to clean up.</para></listitem>
+
+ <listitem><para>The <computeroutput>FILE*</computeroutput> arguments
+ passed to <computeroutput>BZ2_bzReadOpen</computeroutput> /
+ <computeroutput>BZ2_bzWriteOpen</computeroutput> should be set
+ to binary mode. Most Unix systems will do this by default, but
+ other platforms, including Windows and Mac, will not. If you
+ omit this, you may encounter problems when moving code to new
+ platforms.</para></listitem>
+
+ <listitem><para>Memory allocation requests are handled by
+ <computeroutput>malloc</computeroutput> /
+ <computeroutput>free</computeroutput>. At present there is no
+ facility for user-defined memory allocators in the file I/O
+ functions (could easily be added, though).</para></listitem>
+
+</itemizedlist>
+
+
+
+<sect2 id="bzreadopen" xreflabel="BZ2_bzReadOpen">
+<title><computeroutput>BZ2_bzReadOpen</computeroutput></title>
+
+<programlisting>
+typedef void BZFILE;
+
+BZFILE *BZ2_bzReadOpen( int *bzerror, FILE *f,
+ int verbosity, int small,
+ void *unused, int nUnused );
+</programlisting>
+
+<para>Prepare to read compressed data from file handle
+<computeroutput>f</computeroutput>.
+<computeroutput>f</computeroutput> should refer to a file which
+has been opened for reading, and for which the error indicator
+(<computeroutput>ferror(f)</computeroutput>)is not set. If
+<computeroutput>small</computeroutput> is 1, the library will try
+to decompress using less memory, at the expense of speed.</para>
+
+<para>For reasons explained below,
+<computeroutput>BZ2_bzRead</computeroutput> will decompress the
+<computeroutput>nUnused</computeroutput> bytes starting at
+<computeroutput>unused</computeroutput>, before starting to read
+from the file <computeroutput>f</computeroutput>. At most
+<computeroutput>BZ_MAX_UNUSED</computeroutput> bytes may be
+supplied like this. If this facility is not required, you should
+pass <computeroutput>NULL</computeroutput> and
+<computeroutput>0</computeroutput> for
+<computeroutput>unused</computeroutput> and
+n<computeroutput>Unused</computeroutput> respectively.</para>
+
+<para>For the meaning of parameters
+<computeroutput>small</computeroutput> and
+<computeroutput>verbosity</computeroutput>, see
+<computeroutput>BZ2_bzDecompressInit</computeroutput>.</para>
+
+<para>The amount of memory needed to decompress a file cannot be
+determined until the file's header has been read. So it is
+possible that <computeroutput>BZ2_bzReadOpen</computeroutput>
+returns <computeroutput>BZ_OK</computeroutput> but a subsequent
+call of <computeroutput>BZ2_bzRead</computeroutput> will return
+<computeroutput>BZ_MEM_ERROR</computeroutput>.</para>
+
+<para>Possible assignments to
+<computeroutput>bzerror</computeroutput>:</para>
+
+<programlisting>
+BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if f is NULL
+ or small is neither 0 nor 1
+ or ( unused == NULL && nUnused != 0 )
+ or ( unused != NULL && !(0 <= nUnused <= BZ_MAX_UNUSED) )
+BZ_IO_ERROR
+ if ferror(f) is nonzero
+BZ_MEM_ERROR
+ if insufficient memory is available
+BZ_OK
+ otherwise.
+</programlisting>
+
+<para>Possible return values:</para>
+
+<programlisting>
+Pointer to an abstract BZFILE
+ if bzerror is BZ_OK
+NULL
+ otherwise
+</programlisting>
+
+<para>Allowable next actions:</para>
+
+<programlisting>
+BZ2_bzRead
+ if bzerror is BZ_OK
+BZ2_bzClose
+ otherwise
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzread" xreflabel="BZ2_bzRead">
+<title><computeroutput>BZ2_bzRead</computeroutput></title>
+
+<programlisting>
+int BZ2_bzRead ( int *bzerror, BZFILE *b, void *buf, int len );
+</programlisting>
+
+<para>Reads up to <computeroutput>len</computeroutput>
+(uncompressed) bytes from the compressed file
+<computeroutput>b</computeroutput> into the buffer
+<computeroutput>buf</computeroutput>. If the read was
+successful, <computeroutput>bzerror</computeroutput> is set to
+<computeroutput>BZ_OK</computeroutput> and the number of bytes
+read is returned. If the logical end-of-stream was detected,
+<computeroutput>bzerror</computeroutput> will be set to
+<computeroutput>BZ_STREAM_END</computeroutput>, and the number of
+bytes read is returned. All other
+<computeroutput>bzerror</computeroutput> values denote an
+error.</para>
+
+<para><computeroutput>BZ2_bzRead</computeroutput> will supply
+<computeroutput>len</computeroutput> bytes, unless the logical
+stream end is detected or an error occurs. Because of this, it
+is possible to detect the stream end by observing when the number
+of bytes returned is less than the number requested.
+Nevertheless, this is regarded as inadvisable; you should instead
+check <computeroutput>bzerror</computeroutput> after every call
+and watch out for
+<computeroutput>BZ_STREAM_END</computeroutput>.</para>
+
+<para>Internally, <computeroutput>BZ2_bzRead</computeroutput>
+copies data from the compressed file in chunks of size
+<computeroutput>BZ_MAX_UNUSED</computeroutput> bytes before
+decompressing it. If the file contains more bytes than strictly
+needed to reach the logical end-of-stream,
+<computeroutput>BZ2_bzRead</computeroutput> will almost certainly
+read some of the trailing data before signalling
+<computeroutput>BZ_SEQUENCE_END</computeroutput>. To collect the
+read but unused data once
+<computeroutput>BZ_SEQUENCE_END</computeroutput> has appeared,
+call <computeroutput>BZ2_bzReadGetUnused</computeroutput>
+immediately before
+<computeroutput>BZ2_bzReadClose</computeroutput>.</para>
+
+<para>Possible assignments to
+<computeroutput>bzerror</computeroutput>:</para>
+
+<programlisting>
+BZ_PARAM_ERROR
+ if b is NULL or buf is NULL or len < 0
+BZ_SEQUENCE_ERROR
+ if b was opened with BZ2_bzWriteOpen
+BZ_IO_ERROR
+ if there is an error reading from the compressed file
+BZ_UNEXPECTED_EOF
+ if the compressed file ended before
+ the logical end-of-stream was detected
+BZ_DATA_ERROR
+ if a data integrity error was detected in the compressed stream
+BZ_DATA_ERROR_MAGIC
+ if the stream does not begin with the requisite header bytes
+ (ie, is not a bzip2 data file). This is really
+ a special case of BZ_DATA_ERROR.
+BZ_MEM_ERROR
+ if insufficient memory was available
+BZ_STREAM_END
+ if the logical end of stream was detected.
+BZ_OK
+ otherwise.
+</programlisting>
+
+<para>Possible return values:</para>
+
+<programlisting>
+number of bytes read
+ if bzerror is BZ_OK or BZ_STREAM_END
+undefined
+ otherwise
+</programlisting>
+
+<para>Allowable next actions:</para>
+
+<programlisting>
+collect data from buf, then BZ2_bzRead or BZ2_bzReadClose
+ if bzerror is BZ_OK
+collect data from buf, then BZ2_bzReadClose or BZ2_bzReadGetUnused
+ if bzerror is BZ_SEQUENCE_END
+BZ2_bzReadClose
+ otherwise
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzreadgetunused" xreflabel="BZ2_bzReadGetUnused">
+<title><computeroutput>BZ2_bzReadGetUnused</computeroutput></title>
+
+<programlisting>
+void BZ2_bzReadGetUnused( int* bzerror, BZFILE *b,
+ void** unused, int* nUnused );
+</programlisting>
+
+<para>Returns data which was read from the compressed file but
+was not needed to get to the logical end-of-stream.
+<computeroutput>*unused</computeroutput> is set to the address of
+the data, and <computeroutput>*nUnused</computeroutput> to the
+number of bytes. <computeroutput>*nUnused</computeroutput> will
+be set to a value between <computeroutput>0</computeroutput> and
+<computeroutput>BZ_MAX_UNUSED</computeroutput> inclusive.</para>
+
+<para>This function may only be called once
+<computeroutput>BZ2_bzRead</computeroutput> has signalled
+<computeroutput>BZ_STREAM_END</computeroutput> but before
+<computeroutput>BZ2_bzReadClose</computeroutput>.</para>
+
+<para>Possible assignments to
+<computeroutput>bzerror</computeroutput>:</para>
+
+<programlisting>
+BZ_PARAM_ERROR
+ if b is NULL
+ or unused is NULL or nUnused is NULL
+BZ_SEQUENCE_ERROR
+ if BZ_STREAM_END has not been signalled
+ or if b was opened with BZ2_bzWriteOpen
+BZ_OK
+ otherwise
+</programlisting>
+
+<para>Allowable next actions:</para>
+
+<programlisting>
+BZ2_bzReadClose
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzreadclose" xreflabel="BZ2_bzReadClose">
+<title><computeroutput>BZ2_bzReadClose</computeroutput></title>
+
+<programlisting>
+void BZ2_bzReadClose ( int *bzerror, BZFILE *b );
+</programlisting>
+
+<para>Releases all memory pertaining to the compressed file
+<computeroutput>b</computeroutput>.
+<computeroutput>BZ2_bzReadClose</computeroutput> does not call
+<computeroutput>fclose</computeroutput> on the underlying file
+handle, so you should do that yourself if appropriate.
+<computeroutput>BZ2_bzReadClose</computeroutput> should be called
+to clean up after all error situations.</para>
+
+<para>Possible assignments to
+<computeroutput>bzerror</computeroutput>:</para>
+
+<programlisting>
+BZ_SEQUENCE_ERROR
+ if b was opened with BZ2_bzOpenWrite
+BZ_OK
+ otherwise
+</programlisting>
+
+<para>Allowable next actions:</para>
+
+<programlisting>
+none
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzwriteopen" xreflabel="BZ2_bzWriteOpen">
+<title><computeroutput>BZ2_bzWriteOpen</computeroutput></title>
+
+<programlisting>
+BZFILE *BZ2_bzWriteOpen( int *bzerror, FILE *f,
+ int blockSize100k, int verbosity,
+ int workFactor );
+</programlisting>
+
+<para>Prepare to write compressed data to file handle
+<computeroutput>f</computeroutput>.
+<computeroutput>f</computeroutput> should refer to a file which
+has been opened for writing, and for which the error indicator
+(<computeroutput>ferror(f)</computeroutput>)is not set.</para>
+
+<para>For the meaning of parameters
+<computeroutput>blockSize100k</computeroutput>,
+<computeroutput>verbosity</computeroutput> and
+<computeroutput>workFactor</computeroutput>, see
+<computeroutput>BZ2_bzCompressInit</computeroutput>.</para>
+
+<para>All required memory is allocated at this stage, so if the
+call completes successfully,
+<computeroutput>BZ_MEM_ERROR</computeroutput> cannot be signalled
+by a subsequent call to
+<computeroutput>BZ2_bzWrite</computeroutput>.</para>
+
+<para>Possible assignments to
+<computeroutput>bzerror</computeroutput>:</para>
+
+<programlisting>
+BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if f is NULL
+ or blockSize100k < 1 or blockSize100k > 9
+BZ_IO_ERROR
+ if ferror(f) is nonzero
+BZ_MEM_ERROR
+ if insufficient memory is available
+BZ_OK
+ otherwise
+</programlisting>
+
+<para>Possible return values:</para>
+
+<programlisting>
+Pointer to an abstract BZFILE
+ if bzerror is BZ_OK
+NULL
+ otherwise
+</programlisting>
+
+<para>Allowable next actions:</para>
+
+<programlisting>
+BZ2_bzWrite
+ if bzerror is BZ_OK
+ (you could go directly to BZ2_bzWriteClose, but this would be pretty pointless)
+BZ2_bzWriteClose
+ otherwise
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzwrite" xreflabel="BZ2_bzWrite">
+<title><computeroutput>BZ2_bzWrite</computeroutput></title>
+
+<programlisting>
+void BZ2_bzWrite ( int *bzerror, BZFILE *b, void *buf, int len );
+</programlisting>
+
+<para>Absorbs <computeroutput>len</computeroutput> bytes from the
+buffer <computeroutput>buf</computeroutput>, eventually to be
+compressed and written to the file.</para>
+
+<para>Possible assignments to
+<computeroutput>bzerror</computeroutput>:</para>
+
+<programlisting>
+BZ_PARAM_ERROR
+ if b is NULL or buf is NULL or len < 0
+BZ_SEQUENCE_ERROR
+ if b was opened with BZ2_bzReadOpen
+BZ_IO_ERROR
+ if there is an error writing the compressed file.
+BZ_OK
+ otherwise
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzwriteclose" xreflabel="BZ2_bzWriteClose">
+<title><computeroutput>BZ2_bzWriteClose</computeroutput></title>
+
+<programlisting>
+void BZ2_bzWriteClose( int *bzerror, BZFILE* f,
+ int abandon,
+ unsigned int* nbytes_in,
+ unsigned int* nbytes_out );
+
+void BZ2_bzWriteClose64( int *bzerror, BZFILE* f,
+ int abandon,
+ unsigned int* nbytes_in_lo32,
+ unsigned int* nbytes_in_hi32,
+ unsigned int* nbytes_out_lo32,
+ unsigned int* nbytes_out_hi32 );
+</programlisting>
+
+<para>Compresses and flushes to the compressed file all data so
+far supplied by <computeroutput>BZ2_bzWrite</computeroutput>.
+The logical end-of-stream markers are also written, so subsequent
+calls to <computeroutput>BZ2_bzWrite</computeroutput> are
+illegal. All memory associated with the compressed file
+<computeroutput>b</computeroutput> is released.
+<computeroutput>fflush</computeroutput> is called on the
+compressed file, but it is not
+<computeroutput>fclose</computeroutput>'d.</para>
+
+<para>If <computeroutput>BZ2_bzWriteClose</computeroutput> is
+called to clean up after an error, the only action is to release
+the memory. The library records the error codes issued by
+previous calls, so this situation will be detected automatically.
+There is no attempt to complete the compression operation, nor to
+<computeroutput>fflush</computeroutput> the compressed file. You
+can force this behaviour to happen even in the case of no error,
+by passing a nonzero value to
+<computeroutput>abandon</computeroutput>.</para>
+
+<para>If <computeroutput>nbytes_in</computeroutput> is non-null,
+<computeroutput>*nbytes_in</computeroutput> will be set to be the
+total volume of uncompressed data handled. Similarly,
+<computeroutput>nbytes_out</computeroutput> will be set to the
+total volume of compressed data written. For compatibility with
+older versions of the library,
+<computeroutput>BZ2_bzWriteClose</computeroutput> only yields the
+lower 32 bits of these counts. Use
+<computeroutput>BZ2_bzWriteClose64</computeroutput> if you want
+the full 64 bit counts. These two functions are otherwise
+absolutely identical.</para>
+
+<para>Possible assignments to
+<computeroutput>bzerror</computeroutput>:</para>
+
+<programlisting>
+BZ_SEQUENCE_ERROR
+ if b was opened with BZ2_bzReadOpen
+BZ_IO_ERROR
+ if there is an error writing the compressed file
+BZ_OK
+ otherwise
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="embed" xreflabel="Handling embedded compressed data streams">
+<title>Handling embedded compressed data streams</title>
+
+<para>The high-level library facilitates use of
+<computeroutput>bzip2</computeroutput> data streams which form
+some part of a surrounding, larger data stream.</para>
+
+<itemizedlist mark='bullet'>
+
+ <listitem><para>For writing, the library takes an open file handle,
+ writes compressed data to it,
+ <computeroutput>fflush</computeroutput>es it but does not
+ <computeroutput>fclose</computeroutput> it. The calling
+ application can write its own data before and after the
+ compressed data stream, using that same file handle.</para></listitem>
+
+ <listitem><para>Reading is more complex, and the facilities are not as
+ general as they could be since generality is hard to reconcile
+ with efficiency. <computeroutput>BZ2_bzRead</computeroutput>
+ reads from the compressed file in blocks of size
+ <computeroutput>BZ_MAX_UNUSED</computeroutput> bytes, and in
+ doing so probably will overshoot the logical end of compressed
+ stream. To recover this data once decompression has ended,
+ call <computeroutput>BZ2_bzReadGetUnused</computeroutput> after
+ the last call of <computeroutput>BZ2_bzRead</computeroutput>
+ (the one returning
+ <computeroutput>BZ_STREAM_END</computeroutput>) but before
+ calling
+ <computeroutput>BZ2_bzReadClose</computeroutput>.</para></listitem>
+
+</itemizedlist>
+
+<para>This mechanism makes it easy to decompress multiple
+<computeroutput>bzip2</computeroutput> streams placed end-to-end.
+As the end of one stream, when
+<computeroutput>BZ2_bzRead</computeroutput> returns
+<computeroutput>BZ_STREAM_END</computeroutput>, call
+<computeroutput>BZ2_bzReadGetUnused</computeroutput> to collect
+the unused data (copy it into your own buffer somewhere). That
+data forms the start of the next compressed stream. To start
+uncompressing that next stream, call
+<computeroutput>BZ2_bzReadOpen</computeroutput> again, feeding in
+the unused data via the <computeroutput>unused</computeroutput> /
+<computeroutput>nUnused</computeroutput> parameters. Keep doing
+this until <computeroutput>BZ_STREAM_END</computeroutput> return
+coincides with the physical end of file
+(<computeroutput>feof(f)</computeroutput>). In this situation
+<computeroutput>BZ2_bzReadGetUnused</computeroutput> will of
+course return no data.</para>
+
+<para>This should give some feel for how the high-level interface
+can be used. If you require extra flexibility, you'll have to
+bite the bullet and get to grips with the low-level
+interface.</para>
+
+</sect2>
+
+
+<sect2 id="std-rdwr" xreflabel="Standard file-reading/writing code">
+<title>Standard file-reading/writing code</title>
+
+<para>Here's how you'd write data to a compressed file:</para>
+
+<programlisting>
+FILE* f;
+BZFILE* b;
+int nBuf;
+char buf[ /* whatever size you like */ ];
+int bzerror;
+int nWritten;
+
+f = fopen ( "myfile.bz2", "w" );
+if ( !f ) {
+ /* handle error */
+}
+b = BZ2_bzWriteOpen( &bzerror, f, 9 );
+if (bzerror != BZ_OK) {
+ BZ2_bzWriteClose ( b );
+ /* handle error */
+}
+
+while ( /* condition */ ) {
+ /* get data to write into buf, and set nBuf appropriately */
+ nWritten = BZ2_bzWrite ( &bzerror, b, buf, nBuf );
+ if (bzerror == BZ_IO_ERROR) {
+ BZ2_bzWriteClose ( &bzerror, b );
+ /* handle error */
+ }
+}
+
+BZ2_bzWriteClose( &bzerror, b );
+if (bzerror == BZ_IO_ERROR) {
+ /* handle error */
+}
+</programlisting>
+
+<para>And to read from a compressed file:</para>
+
+<programlisting>
+FILE* f;
+BZFILE* b;
+int nBuf;
+char buf[ /* whatever size you like */ ];
+int bzerror;
+int nWritten;
+
+f = fopen ( "myfile.bz2", "r" );
+if ( !f ) {
+ /* handle error */
+}
+b = BZ2_bzReadOpen ( &bzerror, f, 0, NULL, 0 );
+if ( bzerror != BZ_OK ) {
+ BZ2_bzReadClose ( &bzerror, b );
+ /* handle error */
+}
+
+bzerror = BZ_OK;
+while ( bzerror == BZ_OK && /* arbitrary other conditions */) {
+ nBuf = BZ2_bzRead ( &bzerror, b, buf, /* size of buf */ );
+ if ( bzerror == BZ_OK ) {
+ /* do something with buf[0 .. nBuf-1] */
+ }
+}
+if ( bzerror != BZ_STREAM_END ) {
+ BZ2_bzReadClose ( &bzerror, b );
+ /* handle error */
+} else {
+ BZ2_bzReadClose ( &bzerror, b );
+}
+</programlisting>
+
+</sect2>
+
+</sect1>
+
+
+<sect1 id="util-fns" xreflabel="Utility functions">
+<title>Utility functions</title>
+
+
+<sect2 id="bzbufftobuffcompress" xreflabel="BZ2_bzBuffToBuffCompress">
+<title><computeroutput>BZ2_bzBuffToBuffCompress</computeroutput></title>
+
+<programlisting>
+int BZ2_bzBuffToBuffCompress( char* dest,
+ unsigned int* destLen,
+ char* source,
+ unsigned int sourceLen,
+ int blockSize100k,
+ int verbosity,
+ int workFactor );
+</programlisting>
+
+<para>Attempts to compress the data in <computeroutput>source[0
+.. sourceLen-1]</computeroutput> into the destination buffer,
+<computeroutput>dest[0 .. *destLen-1]</computeroutput>. If the
+destination buffer is big enough,
+<computeroutput>*destLen</computeroutput> is set to the size of
+the compressed data, and <computeroutput>BZ_OK</computeroutput>
+is returned. If the compressed data won't fit,
+<computeroutput>*destLen</computeroutput> is unchanged, and
+<computeroutput>BZ_OUTBUFF_FULL</computeroutput> is
+returned.</para>
+
+<para>Compression in this manner is a one-shot event, done with a
+single call to this function. The resulting compressed data is a
+complete <computeroutput>bzip2</computeroutput> format data
+stream. There is no mechanism for making additional calls to
+provide extra input data. If you want that kind of mechanism,
+use the low-level interface.</para>
+
+<para>For the meaning of parameters
+<computeroutput>blockSize100k</computeroutput>,
+<computeroutput>verbosity</computeroutput> and
+<computeroutput>workFactor</computeroutput>, see
+<computeroutput>BZ2_bzCompressInit</computeroutput>.</para>
+
+<para>To guarantee that the compressed data will fit in its
+buffer, allocate an output buffer of size 1% larger than the
+uncompressed data, plus six hundred extra bytes.</para>
+
+<para><computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput>
+will not write data at or beyond
+<computeroutput>dest[*destLen]</computeroutput>, even in case of
+buffer overflow.</para>
+
+<para>Possible return values:</para>
+
+<programlisting>
+BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if dest is NULL or destLen is NULL
+ or blockSize100k < 1 or blockSize100k > 9
+ or verbosity < 0 or verbosity > 4
+ or workFactor < 0 or workFactor > 250
+BZ_MEM_ERROR
+ if insufficient memory is available
+BZ_OUTBUFF_FULL
+ if the size of the compressed data exceeds *destLen
+BZ_OK
+ otherwise
+</programlisting>
+
+</sect2>
+
+
+<sect2 id="bzbufftobuffdecompress" xreflabel="BZ2_bzBuffToBuffDecompress">
+<title><computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput></title>
+
+<programlisting>
+int BZ2_bzBuffToBuffDecompress( char* dest,
+ unsigned int* destLen,
+ char* source,
+ unsigned int sourceLen,
+ int small,
+ int verbosity );
+</programlisting>
+
+<para>Attempts to decompress the data in <computeroutput>source[0
+.. sourceLen-1]</computeroutput> into the destination buffer,
+<computeroutput>dest[0 .. *destLen-1]</computeroutput>. If the
+destination buffer is big enough,
+<computeroutput>*destLen</computeroutput> is set to the size of
+the uncompressed data, and <computeroutput>BZ_OK</computeroutput>
+is returned. If the compressed data won't fit,
+<computeroutput>*destLen</computeroutput> is unchanged, and
+<computeroutput>BZ_OUTBUFF_FULL</computeroutput> is
+returned.</para>
+
+<para><computeroutput>source</computeroutput> is assumed to hold
+a complete <computeroutput>bzip2</computeroutput> format data
+stream.
+<computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput> tries
+to decompress the entirety of the stream into the output
+buffer.</para>
+
+<para>For the meaning of parameters
+<computeroutput>small</computeroutput> and
+<computeroutput>verbosity</computeroutput>, see
+<computeroutput>BZ2_bzDecompressInit</computeroutput>.</para>
+
+<para>Because the compression ratio of the compressed data cannot
+be known in advance, there is no easy way to guarantee that the
+output buffer will be big enough. You may of course make
+arrangements in your code to record the size of the uncompressed
+data, but such a mechanism is beyond the scope of this
+library.</para>
+
+<para><computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput>
+will not write data at or beyond
+<computeroutput>dest[*destLen]</computeroutput>, even in case of
+buffer overflow.</para>
+
+<para>Possible return values:</para>
+
+<programlisting>
+BZ_CONFIG_ERROR
+ if the library has been mis-compiled
+BZ_PARAM_ERROR
+ if dest is NULL or destLen is NULL
+ or small != 0 && small != 1
+ or verbosity < 0 or verbosity > 4
+BZ_MEM_ERROR
+ if insufficient memory is available
+BZ_OUTBUFF_FULL
+ if the size of the compressed data exceeds *destLen
+BZ_DATA_ERROR
+ if a data integrity error was detected in the compressed data
+BZ_DATA_ERROR_MAGIC
+ if the compressed data doesn't begin with the right magic bytes
+BZ_UNEXPECTED_EOF
+ if the compressed data ends unexpectedly
+BZ_OK
+ otherwise
+</programlisting>
+
+</sect2>
+
+</sect1>
+
+
+<sect1 id="zlib-compat" xreflabel="zlib compatibility functions">
+<title><computeroutput>zlib</computeroutput> compatibility functions</title>
+
+<para>Yoshioka Tsuneo has contributed some functions to give
+better <computeroutput>zlib</computeroutput> compatibility.
+These functions are <computeroutput>BZ2_bzopen</computeroutput>,
+<computeroutput>BZ2_bzread</computeroutput>,
+<computeroutput>BZ2_bzwrite</computeroutput>,
+<computeroutput>BZ2_bzflush</computeroutput>,
+<computeroutput>BZ2_bzclose</computeroutput>,
+<computeroutput>BZ2_bzerror</computeroutput> and
+<computeroutput>BZ2_bzlibVersion</computeroutput>. These
+functions are not (yet) officially part of the library. If they
+break, you get to keep all the pieces. Nevertheless, I think
+they work ok.</para>
+
+<programlisting>
+typedef void BZFILE;
+
+const char * BZ2_bzlibVersion ( void );
+</programlisting>
+
+<para>Returns a string indicating the library version.</para>
+
+<programlisting>
+BZFILE * BZ2_bzopen ( const char *path, const char *mode );
+BZFILE * BZ2_bzdopen ( int fd, const char *mode );
+</programlisting>
+
+<para>Opens a <computeroutput>.bz2</computeroutput> file for
+reading or writing, using either its name or a pre-existing file
+descriptor. Analogous to <computeroutput>fopen</computeroutput>
+and <computeroutput>fdopen</computeroutput>.</para>
+
+<programlisting>
+int BZ2_bzread ( BZFILE* b, void* buf, int len );
+int BZ2_bzwrite ( BZFILE* b, void* buf, int len );
+</programlisting>
+
+<para>Reads/writes data from/to a previously opened
+<computeroutput>BZFILE</computeroutput>. Analogous to
+<computeroutput>fread</computeroutput> and
+<computeroutput>fwrite</computeroutput>.</para>
+
+<programlisting>
+int BZ2_bzflush ( BZFILE* b );
+void BZ2_bzclose ( BZFILE* b );
+</programlisting>
+
+<para>Flushes/closes a <computeroutput>BZFILE</computeroutput>.
+<computeroutput>BZ2_bzflush</computeroutput> doesn't actually do
+anything. Analogous to <computeroutput>fflush</computeroutput>
+and <computeroutput>fclose</computeroutput>.</para>
+
+<programlisting>
+const char * BZ2_bzerror ( BZFILE *b, int *errnum )
+</programlisting>
+
+<para>Returns a string describing the more recent error status of
+<computeroutput>b</computeroutput>, and also sets
+<computeroutput>*errnum</computeroutput> to its numerical
+value.</para>
+
+</sect1>
+
+
+<sect1 id="stdio-free"
+ xreflabel="Using the library in a stdio-free environment">
+<title>Using the library in a <computeroutput>stdio</computeroutput>-free environment</title>
+
+
+<sect2 id="stdio-bye" xreflabel="Getting rid of stdio">
+<title>Getting rid of <computeroutput>stdio</computeroutput></title>
+
+<para>In a deeply embedded application, you might want to use
+just the memory-to-memory functions. You can do this
+conveniently by compiling the library with preprocessor symbol
+<computeroutput>BZ_NO_STDIO</computeroutput> defined. Doing this
+gives you a library containing only the following eight
+functions:</para>
+
+<para><computeroutput>BZ2_bzCompressInit</computeroutput>,
+<computeroutput>BZ2_bzCompress</computeroutput>,
+<computeroutput>BZ2_bzCompressEnd</computeroutput>
+<computeroutput>BZ2_bzDecompressInit</computeroutput>,
+<computeroutput>BZ2_bzDecompress</computeroutput>,
+<computeroutput>BZ2_bzDecompressEnd</computeroutput>
+<computeroutput>BZ2_bzBuffToBuffCompress</computeroutput>,
+<computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput></para>
+
+<para>When compiled like this, all functions will ignore
+<computeroutput>verbosity</computeroutput> settings.</para>
+
+</sect2>
+
+
+<sect2 id="critical-error" xreflabel="Critical error handling">
+<title>Critical error handling</title>
+
+<para><computeroutput>libbzip2</computeroutput> contains a number
+of internal assertion checks which should, needless to say, never
+be activated. Nevertheless, if an assertion should fail,
+behaviour depends on whether or not the library was compiled with
+<computeroutput>BZ_NO_STDIO</computeroutput> set.</para>
+
+<para>For a normal compile, an assertion failure yields the
+message:</para>
+
+<blockquote>
+<para>bzip2/libbzip2: internal error number N.</para>
+<para>This is a bug in bzip2/libbzip2, &bz-version; of &bz-date;.
+Please report it to me at: &bz-email;. If this happened
+when you were using some program which uses libbzip2 as a
+component, you should also report this bug to the author(s)
+of that program. Please make an effort to report this bug;
+timely and accurate bug reports eventually lead to higher
+quality software. Thanks. Julian Seward, &bz-date;.
+</para></blockquote>
+
+<para>where <computeroutput>N</computeroutput> is some error code
+number. If <computeroutput>N == 1007</computeroutput>, it also
+prints some extra text advising the reader that unreliable memory
+is often associated with internal error 1007. (This is a
+frequently-observed-phenomenon with versions 1.0.0/1.0.1).</para>
+
+<para><computeroutput>exit(3)</computeroutput> is then
+called.</para>
+
+<para>For a <computeroutput>stdio</computeroutput>-free library,
+assertion failures result in a call to a function declared
+as:</para>
+
+<programlisting>
+extern void bz_internal_error ( int errcode );
+</programlisting>
+
+<para>The relevant code is passed as a parameter. You should
+supply such a function.</para>
+
+<para>In either case, once an assertion failure has occurred, any
+<computeroutput>bz_stream</computeroutput> records involved can
+be regarded as invalid. You should not attempt to resume normal
+operation with them.</para>
+
+<para>You may, of course, change critical error handling to suit
+your needs. As I said above, critical errors indicate bugs in
+the library and should not occur. All "normal" error situations
+are indicated via error return codes from functions, and can be
+recovered from.</para>
+
+</sect2>
+
+</sect1>
+
+
+<sect1 id="win-dll" xreflabel="Making a Windows DLL">
+<title>Making a Windows DLL</title>
+
+<para>Everything related to Windows has been contributed by
+Yoshioka Tsuneo
+(<computeroutput>tsuneo@rr.iij4u.or.jp</computeroutput>), so
+you should send your queries to him (but perhaps Cc: me,
+<computeroutput>&bz-email;</computeroutput>).</para>
+
+<para>My vague understanding of what to do is: using Visual C++
+5.0, open the project file
+<computeroutput>libbz2.dsp</computeroutput>, and build. That's
+all.</para>
+
+<para>If you can't open the project file for some reason, make a
+new one, naming these files:
+<computeroutput>blocksort.c</computeroutput>,
+<computeroutput>bzlib.c</computeroutput>,
+<computeroutput>compress.c</computeroutput>,
+<computeroutput>crctable.c</computeroutput>,
+<computeroutput>decompress.c</computeroutput>,
+<computeroutput>huffman.c</computeroutput>,
+<computeroutput>randtable.c</computeroutput> and
+<computeroutput>libbz2.def</computeroutput>. You will also need
+to name the header files <computeroutput>bzlib.h</computeroutput>
+and <computeroutput>bzlib_private.h</computeroutput>.</para>
+
+<para>If you don't use VC++, you may need to define the
+proprocessor symbol
+<computeroutput>_WIN32</computeroutput>.</para>
+
+<para>Finally, <computeroutput>dlltest.c</computeroutput> is a
+sample program using the DLL. It has a project file,
+<computeroutput>dlltest.dsp</computeroutput>.</para>
+
+<para>If you just want a makefile for Visual C, have a look at
+<computeroutput>makefile.msc</computeroutput>.</para>
+
+<para>Be aware that if you compile
+<computeroutput>bzip2</computeroutput> itself on Win32, you must
+set <computeroutput>BZ_UNIX</computeroutput> to 0 and
+<computeroutput>BZ_LCCWIN32</computeroutput> to 1, in the file
+<computeroutput>bzip2.c</computeroutput>, before compiling.
+Otherwise the resulting binary won't work correctly.</para>
+
+<para>I haven't tried any of this stuff myself, but it all looks
+plausible.</para>
+
+</sect1>
+
+</chapter>
+
+
+
+<chapter id="misc" xreflabel="Miscellanea">
+<title>Miscellanea</title>
+
+<para>These are just some random thoughts of mine. Your mileage
+may vary.</para>
+
+
+<sect1 id="limits" xreflabel="Limitations of the compressed file format">
+<title>Limitations of the compressed file format</title>
+
+<para><computeroutput>bzip2-1.0.X</computeroutput>,
+<computeroutput>0.9.5</computeroutput> and
+<computeroutput>0.9.0</computeroutput> use exactly the same file
+format as the original version,
+<computeroutput>bzip2-0.1</computeroutput>. This decision was
+made in the interests of stability. Creating yet another
+incompatible compressed file format would create further
+confusion and disruption for users.</para>
+
+<para>Nevertheless, this is not a painless decision. Development
+work since the release of
+<computeroutput>bzip2-0.1</computeroutput> in August 1997 has
+shown complexities in the file format which slow down
+decompression and, in retrospect, are unnecessary. These
+are:</para>
+
+<itemizedlist mark='bullet'>
+
+ <listitem><para>The run-length encoder, which is the first of the
+ compression transformations, is entirely irrelevant. The
+ original purpose was to protect the sorting algorithm from the
+ very worst case input: a string of repeated symbols. But
+ algorithm steps Q6a and Q6b in the original Burrows-Wheeler
+ technical report (SRC-124) show how repeats can be handled
+ without difficulty in block sorting.</para></listitem>
+
+ <listitem><para>The randomisation mechanism doesn't really need to be
+ there. Udi Manber and Gene Myers published a suffix array
+ construction algorithm a few years back, which can be employed
+ to sort any block, no matter how repetitive, in O(N log N)
+ time. Subsequent work by Kunihiko Sadakane has produced a
+ derivative O(N (log N)^2) algorithm which usually outperforms
+ the Manber-Myers algorithm.</para>
+
+ <para>I could have changed to Sadakane's algorithm, but I find
+ it to be slower than <computeroutput>bzip2</computeroutput>'s
+ existing algorithm for most inputs, and the randomisation
+ mechanism protects adequately against bad cases. I didn't
+ think it was a good tradeoff to make. Partly this is due to
+ the fact that I was not flooded with email complaints about
+ <computeroutput>bzip2-0.1</computeroutput>'s performance on
+ repetitive data, so perhaps it isn't a problem for real
+ inputs.</para>
+
+ <para>Probably the best long-term solution, and the one I have
+ incorporated into 0.9.5 and above, is to use the existing
+ sorting algorithm initially, and fall back to a O(N (log N)^2)
+ algorithm if the standard algorithm gets into
+ difficulties.</para></listitem>
+
+ <listitem><para>The compressed file format was never designed to be
+ handled by a library, and I have had to jump though some hoops
+ to produce an efficient implementation of decompression. It's
+ a bit hairy. Try passing
+ <computeroutput>decompress.c</computeroutput> through the C
+ preprocessor and you'll see what I mean. Much of this
+ complexity could have been avoided if the compressed size of
+ each block of data was recorded in the data stream.</para></listitem>
+
+ <listitem><para>An Adler-32 checksum, rather than a CRC32 checksum,
+ would be faster to compute.</para></listitem>
+
+</itemizedlist>
+
+<para>It would be fair to say that the
+<computeroutput>bzip2</computeroutput> format was frozen before I
+properly and fully understood the performance consequences of
+doing so.</para>
+
+<para>Improvements which I was able to incorporate into 0.9.0,
+despite using the same file format, are:</para>
+
+<itemizedlist mark='bullet'>
+
+ <listitem><para>Single array implementation of the inverse BWT. This
+ significantly speeds up decompression, presumably because it
+ reduces the number of cache misses.</para></listitem>
+
+ <listitem><para>Faster inverse MTF transform for large MTF values.
+ The new implementation is based on the notion of sliding blocks
+ of values.</para></listitem>
+
+ <listitem><para><computeroutput>bzip2-0.9.0</computeroutput> now reads
+ and writes files with <computeroutput>fread</computeroutput>
+ and <computeroutput>fwrite</computeroutput>; version 0.1 used
+ <computeroutput>putc</computeroutput> and
+ <computeroutput>getc</computeroutput>. Duh! Well, you live
+ and learn.</para></listitem>
+
+</itemizedlist>
+
+<para>Further ahead, it would be nice to be able to do random
+access into files. This will require some careful design of
+compressed file formats.</para>
+
+</sect1>
+
+
+<sect1 id="port-issues" xreflabel="Portability issues">
+<title>Portability issues</title>
+
+<para>After some consideration, I have decided not to use GNU
+<computeroutput>autoconf</computeroutput> to configure 0.9.5 or
+1.0.</para>
+
+<para><computeroutput>autoconf</computeroutput>, admirable and
+wonderful though it is, mainly assists with portability problems
+between Unix-like platforms. But
+<computeroutput>bzip2</computeroutput> doesn't have much in the
+way of portability problems on Unix; most of the difficulties
+appear when porting to the Mac, or to Microsoft's operating
+systems. <computeroutput>autoconf</computeroutput> doesn't help
+in those cases, and brings in a whole load of new
+complexity.</para>
+
+<para>Most people should be able to compile the library and
+program under Unix straight out-of-the-box, so to speak,
+especially if you have a version of GNU C available.</para>
+
+<para>There are a couple of
+<computeroutput>__inline__</computeroutput> directives in the
+code. GNU C (<computeroutput>gcc</computeroutput>) should be
+able to handle them. If you're not using GNU C, your C compiler
+shouldn't see them at all. If your compiler does, for some
+reason, see them and doesn't like them, just
+<computeroutput>#define</computeroutput>
+<computeroutput>__inline__</computeroutput> to be
+<computeroutput>/* */</computeroutput>. One easy way to do this
+is to compile with the flag
+<computeroutput>-D__inline__=</computeroutput>, which should be
+understood by most Unix compilers.</para>
+
+<para>If you still have difficulties, try compiling with the
+macro <computeroutput>BZ_STRICT_ANSI</computeroutput> defined.
+This should enable you to build the library in a strictly ANSI
+compliant environment. Building the program itself like this is
+dangerous and not supported, since you remove
+<computeroutput>bzip2</computeroutput>'s checks against
+compressing directories, symbolic links, devices, and other
+not-really-a-file entities. This could cause filesystem
+corruption!</para>
+
+<para>One other thing: if you create a
+<computeroutput>bzip2</computeroutput> binary for public distribution,
+please consider linking it statically (<computeroutput>gcc
+-static</computeroutput>). This avoids all sorts of library-version
+issues that others may encounter later on.</para>
+
+<para>If you build <computeroutput>bzip2</computeroutput> on
+Win32, you must set <computeroutput>BZ_UNIX</computeroutput> to 0
+and <computeroutput>BZ_LCCWIN32</computeroutput> to 1, in the
+file <computeroutput>bzip2.c</computeroutput>, before compiling.
+Otherwise the resulting binary won't work correctly.</para>
+
+</sect1>
+
+
+<sect1 id="bugs" xreflabel="Reporting bugs">
+<title>Reporting bugs</title>
+
+<para>I tried pretty hard to make sure
+<computeroutput>bzip2</computeroutput> is bug free, both by
+design and by testing. Hopefully you'll never need to read this
+section for real.</para>
+
+<para>Nevertheless, if <computeroutput>bzip2</computeroutput> dies
+with a segmentation fault, a bus error or an internal assertion
+failure, it will ask you to email me a bug report. Experience from
+years of feedback of bzip2 users indicates that almost all these
+problems can be traced to either compiler bugs or hardware
+problems.</para>
+
+<itemizedlist mark='bullet'>
+
+ <listitem><para>Recompile the program with no optimisation, and
+ see if it works. And/or try a different compiler. I heard all
+ sorts of stories about various flavours of GNU C (and other
+ compilers) generating bad code for
+ <computeroutput>bzip2</computeroutput>, and I've run across two
+ such examples myself.</para>
+
+ <para>2.7.X versions of GNU C are known to generate bad code
+ from time to time, at high optimisation levels. If you get
+ problems, try using the flags
+ <computeroutput>-O2</computeroutput>
+ <computeroutput>-fomit-frame-pointer</computeroutput>
+ <computeroutput>-fno-strength-reduce</computeroutput>. You
+ should specifically <emphasis>not</emphasis> use
+ <computeroutput>-funroll-loops</computeroutput>.</para>
+
+ <para>You may notice that the Makefile runs six tests as part
+ of the build process. If the program passes all of these, it's
+ a pretty good (but not 100%) indication that the compiler has
+ done its job correctly.</para></listitem>
+
+ <listitem><para>If <computeroutput>bzip2</computeroutput>
+ crashes randomly, and the crashes are not repeatable, you may
+ have a flaky memory subsystem.
+ <computeroutput>bzip2</computeroutput> really hammers your
+ memory hierarchy, and if it's a bit marginal, you may get these
+ problems. Ditto if your disk or I/O subsystem is slowly
+ failing. Yup, this really does happen.</para>
+
+ <para>Try using a different machine of the same type, and see
+ if you can repeat the problem.</para></listitem>
+
+ <listitem><para>This isn't really a bug, but ... If
+ <computeroutput>bzip2</computeroutput> tells you your file is
+ corrupted on decompression, and you obtained the file via FTP,
+ there is a possibility that you forgot to tell FTP to do a
+ binary mode transfer. That absolutely will cause the file to
+ be non-decompressible. You'll have to transfer it
+ again.</para></listitem>
+
+</itemizedlist>
+
+<para>If you've incorporated
+<computeroutput>libbzip2</computeroutput> into your own program
+and are getting problems, please, please, please, check that the
+parameters you are passing in calls to the library, are correct,
+and in accordance with what the documentation says is allowable.
+I have tried to make the library robust against such problems,
+but I'm sure I haven't succeeded.</para>
+
+<para>Finally, if the above comments don't help, you'll have to
+send me a bug report. Now, it's just amazing how many people
+will send me a bug report saying something like:</para>
+
+<programlisting>
+bzip2 crashed with segmentation fault on my machine
+</programlisting>
+
+<para>and absolutely nothing else. Needless to say, a such a
+report is <emphasis>totally, utterly, completely and
+comprehensively 100% useless; a waste of your time, my time, and
+net bandwidth</emphasis>. With no details at all, there's no way
+I can possibly begin to figure out what the problem is.</para>
+
+<para>The rules of the game are: facts, facts, facts. Don't omit
+them because "oh, they won't be relevant". At the bare
+minimum:</para>
+
+<programlisting>
+Machine type. Operating system version.
+Exact version of bzip2 (do bzip2 -V).
+Exact version of the compiler used.
+Flags passed to the compiler.
+</programlisting>
+
+<para>However, the most important single thing that will help me
+is the file that you were trying to compress or decompress at the
+time the problem happened. Without that, my ability to do
+anything more than speculate about the cause, is limited.</para>
+
+</sect1>
+
+
+<sect1 id="package" xreflabel="Did you get the right package?">
+<title>Did you get the right package?</title>
+
+<para><computeroutput>bzip2</computeroutput> is a resource hog.
+It soaks up large amounts of CPU cycles and memory. Also, it
+gives very large latencies. In the worst case, you can feed many
+megabytes of uncompressed data into the library before getting
+any compressed output, so this probably rules out applications
+requiring interactive behaviour.</para>
+
+<para>These aren't faults of my implementation, I hope, but more
+an intrinsic property of the Burrows-Wheeler transform
+(unfortunately). Maybe this isn't what you want.</para>
+
+<para>If you want a compressor and/or library which is faster,
+uses less memory but gets pretty good compression, and has
+minimal latency, consider Jean-loup Gailly's and Mark Adler's
+work, <computeroutput>zlib-1.2.1</computeroutput> and
+<computeroutput>gzip-1.2.4</computeroutput>. Look for them at
+<ulink url="http://www.zlib.org">http://www.zlib.org</ulink> and
+<ulink url="http://www.gzip.org">http://www.gzip.org</ulink>
+respectively.</para>
+
+<para>For something faster and lighter still, you might try Markus F
+X J Oberhumer's <computeroutput>LZO</computeroutput> real-time
+compression/decompression library, at
+<ulink url="http://www.oberhumer.com/opensource">http://www.oberhumer.com/opensource</ulink>.</para>
+
+</sect1>
+
+
+
+<sect1 id="reading" xreflabel="Further Reading">
+<title>Further Reading</title>
+
+<para><computeroutput>bzip2</computeroutput> is not research
+work, in the sense that it doesn't present any new ideas.
+Rather, it's an engineering exercise based on existing
+ideas.</para>
+
+<para>Four documents describe essentially all the ideas behind
+<computeroutput>bzip2</computeroutput>:</para>
+
+<literallayout>Michael Burrows and D. J. Wheeler:
+ "A block-sorting lossless data compression algorithm"
+ 10th May 1994.
+ Digital SRC Research Report 124.
+ ftp://ftp.digital.com/pub/DEC/SRC/research-reports/SRC-124.ps.gz
+ If you have trouble finding it, try searching at the
+ New Zealand Digital Library, http://www.nzdl.org.
+
+Daniel S. Hirschberg and Debra A. LeLewer
+ "Efficient Decoding of Prefix Codes"
+ Communications of the ACM, April 1990, Vol 33, Number 4.
+ You might be able to get an electronic copy of this
+ from the ACM Digital Library.
+
+David J. Wheeler
+ Program bred3.c and accompanying document bred3.ps.
+ This contains the idea behind the multi-table Huffman coding scheme.
+ ftp://ftp.cl.cam.ac.uk/users/djw3/
+
+Jon L. Bentley and Robert Sedgewick
+ "Fast Algorithms for Sorting and Searching Strings"
+ Available from Sedgewick's web page,
+ www.cs.princeton.edu/~rs
+</literallayout>
+
+<para>The following paper gives valuable additional insights into
+the algorithm, but is not immediately the basis of any code used
+in bzip2.</para>
+
+<literallayout>Peter Fenwick:
+ Block Sorting Text Compression
+ Proceedings of the 19th Australasian Computer Science Conference,
+ Melbourne, Australia. Jan 31 - Feb 2, 1996.
+ ftp://ftp.cs.auckland.ac.nz/pub/peter-f/ACSC96paper.ps</literallayout>
+
+<para>Kunihiko Sadakane's sorting algorithm, mentioned above, is
+available from:</para>
+
+<literallayout>http://naomi.is.s.u-tokyo.ac.jp/~sada/papers/Sada98b.ps.gz
+</literallayout>
+
+<para>The Manber-Myers suffix array construction algorithm is
+described in a paper available from:</para>
+
+<literallayout>http://www.cs.arizona.edu/people/gene/PAPERS/suffix.ps
+</literallayout>
+
+<para>Finally, the following papers document some
+investigations I made into the performance of sorting
+and decompression algorithms:</para>
+
+<literallayout>Julian Seward
+ On the Performance of BWT Sorting Algorithms
+ Proceedings of the IEEE Data Compression Conference 2000
+ Snowbird, Utah. 28-30 March 2000.
+
+Julian Seward
+ Space-time Tradeoffs in the Inverse B-W Transform
+ Proceedings of the IEEE Data Compression Conference 2001
+ Snowbird, Utah. 27-29 March 2001.
+</literallayout>
+
+</sect1>
+
+</chapter>
+
+</book>
diff --git a/Utilities/cmbzip2/mk251.c b/Utilities/cmbzip2/mk251.c
new file mode 100644
index 0000000000..39e94c0573
--- /dev/null
+++ b/Utilities/cmbzip2/mk251.c
@@ -0,0 +1,31 @@
+
+/* Spew out a long sequence of the byte 251. When fed to bzip2
+ versions 1.0.0 or 1.0.1, causes it to die with internal error
+ 1007 in blocksort.c. This assertion misses an extremely rare
+ case, which is fixed in this version (1.0.2) and above.
+*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#include <stdio.h>
+
+int main ()
+{
+ int i;
+ for (i = 0; i < 48500000 ; i++)
+ putchar(251);
+ return 0;
+}
diff --git a/Utilities/cmbzip2/randtable.c b/Utilities/cmbzip2/randtable.c
new file mode 100644
index 0000000000..068b76367b
--- /dev/null
+++ b/Utilities/cmbzip2/randtable.c
@@ -0,0 +1,84 @@
+
+/*-------------------------------------------------------------*/
+/*--- Table for randomising repetitive blocks ---*/
+/*--- randtable.c ---*/
+/*-------------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#include "bzlib_private.h"
+
+
+/*---------------------------------------------*/
+Int32 BZ2_rNums[512] = {
+ 619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
+ 985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
+ 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
+ 419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
+ 878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
+ 862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
+ 150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
+ 170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
+ 73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
+ 909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
+ 641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
+ 161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
+ 382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
+ 98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
+ 227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
+ 469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
+ 184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
+ 715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
+ 951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
+ 652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
+ 645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
+ 609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
+ 653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
+ 411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
+ 170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
+ 857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
+ 669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
+ 944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
+ 344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
+ 897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
+ 433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
+ 686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
+ 946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
+ 978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
+ 680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
+ 707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
+ 297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
+ 134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
+ 343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
+ 140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
+ 170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
+ 369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
+ 804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
+ 896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
+ 661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
+ 768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
+ 61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
+ 372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
+ 780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
+ 920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
+ 645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
+ 936, 638
+};
+
+
+/*-------------------------------------------------------------*/
+/*--- end randtable.c ---*/
+/*-------------------------------------------------------------*/
diff --git a/Utilities/cmbzip2/sample1.rb2 b/Utilities/cmbzip2/sample1.rb2
new file mode 100644
index 0000000000..4edda362a3
--- /dev/null
+++ b/Utilities/cmbzip2/sample1.rb2
Binary files differ
diff --git a/Utilities/cmbzip2/sample1.ref b/Utilities/cmbzip2/sample1.ref
new file mode 100644
index 0000000000..dc869ee6dc
--- /dev/null
+++ b/Utilities/cmbzip2/sample1.ref
Binary files differ
diff --git a/Utilities/cmbzip2/sample1.tst b/Utilities/cmbzip2/sample1.tst
new file mode 100644
index 0000000000..dc869ee6dc
--- /dev/null
+++ b/Utilities/cmbzip2/sample1.tst
Binary files differ
diff --git a/Utilities/cmbzip2/sample2.rb2 b/Utilities/cmbzip2/sample2.rb2
new file mode 100644
index 0000000000..8e54297c94
--- /dev/null
+++ b/Utilities/cmbzip2/sample2.rb2
Binary files differ
diff --git a/Utilities/cmbzip2/sample2.ref b/Utilities/cmbzip2/sample2.ref
new file mode 100644
index 0000000000..40e5b58f2e
--- /dev/null
+++ b/Utilities/cmbzip2/sample2.ref
Binary files differ
diff --git a/Utilities/cmbzip2/sample2.tst b/Utilities/cmbzip2/sample2.tst
new file mode 100644
index 0000000000..40e5b58f2e
--- /dev/null
+++ b/Utilities/cmbzip2/sample2.tst
Binary files differ
diff --git a/Utilities/cmbzip2/sample3.rb2 b/Utilities/cmbzip2/sample3.rb2
new file mode 100644
index 0000000000..1c9b08c476
--- /dev/null
+++ b/Utilities/cmbzip2/sample3.rb2
Binary files differ
diff --git a/Utilities/cmbzip2/sample3.ref b/Utilities/cmbzip2/sample3.ref
new file mode 100644
index 0000000000..775a2f68e2
--- /dev/null
+++ b/Utilities/cmbzip2/sample3.ref
@@ -0,0 +1,30007 @@
+This file is exceedingly boring. If you find yourself
+reading it, please (1) take it from me that you can safely
+guess what the rest of the file says, and (2) seek professional
+help.
+
+ps. there are no further sarcastic remarks in this file.
+
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
diff --git a/Utilities/cmbzip2/sample3.tst b/Utilities/cmbzip2/sample3.tst
new file mode 100644
index 0000000000..775a2f68e2
--- /dev/null
+++ b/Utilities/cmbzip2/sample3.tst
@@ -0,0 +1,30007 @@
+This file is exceedingly boring. If you find yourself
+reading it, please (1) take it from me that you can safely
+guess what the rest of the file says, and (2) seek professional
+help.
+
+ps. there are no further sarcastic remarks in this file.
+
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
+ugh
diff --git a/Utilities/cmbzip2/spewG.c b/Utilities/cmbzip2/spewG.c
new file mode 100644
index 0000000000..7bd12841d0
--- /dev/null
+++ b/Utilities/cmbzip2/spewG.c
@@ -0,0 +1,54 @@
+
+/* spew out a thoroughly gigantic file designed so that bzip2
+ can compress it reasonably rapidly. This is to help test
+ support for large files (> 2GB) in a reasonable amount of time.
+ I suggest you use the undocumented --exponential option to
+ bzip2 when compressing the resulting file; this saves a bit of
+ time. Note: *don't* bother with --exponential when compressing
+ Real Files; it'll just waste a lot of CPU time :-)
+ (but is otherwise harmless).
+*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#define _FILE_OFFSET_BITS 64
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* The number of megabytes of junk to spew out (roughly) */
+#define MEGABYTES 5000
+
+#define N_BUF 1000000
+char buf[N_BUF];
+
+int main ( int argc, char** argv )
+{
+ int ii, kk, p;
+ srandom(1);
+ setbuffer ( stdout, buf, N_BUF );
+ for (kk = 0; kk < MEGABYTES * 515; kk+=3) {
+ p = 25+random()%50;
+ for (ii = 0; ii < p; ii++)
+ printf ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" );
+ for (ii = 0; ii < p-1; ii++)
+ printf ( "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" );
+ for (ii = 0; ii < p+1; ii++)
+ printf ( "ccccccccccccccccccccccccccccccccccccc" );
+ }
+ fflush(stdout);
+ return 0;
+}
diff --git a/Utilities/cmbzip2/unzcrash.c b/Utilities/cmbzip2/unzcrash.c
new file mode 100644
index 0000000000..a1b75463ad
--- /dev/null
+++ b/Utilities/cmbzip2/unzcrash.c
@@ -0,0 +1,141 @@
+
+/* A test program written to test robustness to decompression of
+ corrupted data. Usage is
+ unzcrash filename
+ and the program will read the specified file, compress it (in memory),
+ and then repeatedly decompress it, each time with a different bit of
+ the compressed data inverted, so as to test all possible one-bit errors.
+ This should not cause any invalid memory accesses. If it does,
+ I want to know about it!
+
+ PS. As you can see from the above description, the process is
+ incredibly slow. A file of size eg 5KB will cause it to run for
+ many hours.
+*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.5 of 10 December 2007
+ Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+#include <stdio.h>
+#include <assert.h>
+#include "bzlib.h"
+
+#define M_BLOCK 1000000
+
+typedef unsigned char uchar;
+
+#define M_BLOCK_OUT (M_BLOCK + 1000000)
+uchar inbuf[M_BLOCK];
+uchar outbuf[M_BLOCK_OUT];
+uchar zbuf[M_BLOCK + 600 + (M_BLOCK / 100)];
+
+int nIn, nOut, nZ;
+
+static char *bzerrorstrings[] = {
+ "OK"
+ ,"SEQUENCE_ERROR"
+ ,"PARAM_ERROR"
+ ,"MEM_ERROR"
+ ,"DATA_ERROR"
+ ,"DATA_ERROR_MAGIC"
+ ,"IO_ERROR"
+ ,"UNEXPECTED_EOF"
+ ,"OUTBUFF_FULL"
+ ,"???" /* for future */
+ ,"???" /* for future */
+ ,"???" /* for future */
+ ,"???" /* for future */
+ ,"???" /* for future */
+ ,"???" /* for future */
+};
+
+void flip_bit ( int bit )
+{
+ int byteno = bit / 8;
+ int bitno = bit % 8;
+ uchar mask = 1 << bitno;
+ //fprintf ( stderr, "(byte %d bit %d mask %d)",
+ // byteno, bitno, (int)mask );
+ zbuf[byteno] ^= mask;
+}
+
+int main ( int argc, char** argv )
+{
+ FILE* f;
+ int r;
+ int bit;
+ int i;
+
+ if (argc != 2) {
+ fprintf ( stderr, "usage: unzcrash filename\n" );
+ return 1;
+ }
+
+ f = fopen ( argv[1], "r" );
+ if (!f) {
+ fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
+ return 1;
+ }
+
+ nIn = fread ( inbuf, 1, M_BLOCK, f );
+ fprintf ( stderr, "%d bytes read\n", nIn );
+
+ nZ = M_BLOCK;
+ r = BZ2_bzBuffToBuffCompress (
+ zbuf, &nZ, inbuf, nIn, 9, 0, 30 );
+
+ assert (r == BZ_OK);
+ fprintf ( stderr, "%d after compression\n", nZ );
+
+ for (bit = 0; bit < nZ*8; bit++) {
+ fprintf ( stderr, "bit %d ", bit );
+ flip_bit ( bit );
+ nOut = M_BLOCK_OUT;
+ r = BZ2_bzBuffToBuffDecompress (
+ outbuf, &nOut, zbuf, nZ, 0, 0 );
+ fprintf ( stderr, " %d %s ", r, bzerrorstrings[-r] );
+
+ if (r != BZ_OK) {
+ fprintf ( stderr, "\n" );
+ } else {
+ if (nOut != nIn) {
+ fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
+ return 1;
+ } else {
+ for (i = 0; i < nOut; i++)
+ if (inbuf[i] != outbuf[i]) {
+ fprintf(stderr, "mismatch at %d\n", i );
+ return 1;
+ }
+ if (i == nOut) fprintf(stderr, "really ok!\n" );
+ }
+ }
+
+ flip_bit ( bit );
+ }
+
+#if 0
+ assert (nOut == nIn);
+ for (i = 0; i < nOut; i++) {
+ if (inbuf[i] != outbuf[i]) {
+ fprintf ( stderr, "difference at %d !\n", i );
+ return 1;
+ }
+ }
+#endif
+
+ fprintf ( stderr, "all ok\n" );
+ return 0;
+}
diff --git a/Utilities/cmbzip2/words0 b/Utilities/cmbzip2/words0
new file mode 100644
index 0000000000..fbf442ad6b
--- /dev/null
+++ b/Utilities/cmbzip2/words0
@@ -0,0 +1,9 @@
+
+If compilation produces errors, or a large number of warnings,
+please read README.COMPILATION.PROBLEMS -- you might be able to
+adjust the flags in this Makefile to improve matters.
+
+Also in README.COMPILATION.PROBLEMS are some hints that may help
+if your build produces an executable which is unable to correctly
+handle so-called 'large files' -- files of size 2GB or more.
+
diff --git a/Utilities/cmbzip2/words1 b/Utilities/cmbzip2/words1
new file mode 100644
index 0000000000..2e83de9f08
--- /dev/null
+++ b/Utilities/cmbzip2/words1
@@ -0,0 +1,4 @@
+
+Doing 6 tests (3 compress, 3 uncompress) ...
+If there's a problem, things might stop at this point.
+
diff --git a/Utilities/cmbzip2/words2 b/Utilities/cmbzip2/words2
new file mode 100644
index 0000000000..caddcf4226
--- /dev/null
+++ b/Utilities/cmbzip2/words2
@@ -0,0 +1,5 @@
+
+Checking test results. If any of the four "cmp"s which follow
+report any differences, something is wrong. If you can't easily
+figure out what, please let me know (jseward@bzip.org).
+
diff --git a/Utilities/cmbzip2/words3 b/Utilities/cmbzip2/words3
new file mode 100644
index 0000000000..6972669906
--- /dev/null
+++ b/Utilities/cmbzip2/words3
@@ -0,0 +1,30 @@
+
+If you got this far and the 'cmp's didn't complain, it looks
+like you're in business.
+
+To install in /usr/local/bin, /usr/local/lib, /usr/local/man and
+/usr/local/include, type
+
+ make install
+
+To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type
+
+ make install PREFIX=/xxx/yyy
+
+If you are (justifiably) paranoid and want to see what 'make install'
+is going to do, you can first do
+
+ make -n install or
+ make -n install PREFIX=/xxx/yyy respectively.
+
+The -n instructs make to show the commands it would execute, but
+not actually execute them.
+
+Instructions for use are in the preformatted manual page, in the file
+bzip2.txt. For more detailed documentation, read the full manual.
+It is available in Postscript form (manual.ps), PDF form (manual.pdf),
+and HTML form (manual.html).
+
+You can also do "bzip2 --help" to see some helpful information.
+"bzip2 -L" displays the software license.
+
diff --git a/Utilities/cmbzip2/xmlproc.sh b/Utilities/cmbzip2/xmlproc.sh
new file mode 100755
index 0000000000..53841773d4
--- /dev/null
+++ b/Utilities/cmbzip2/xmlproc.sh
@@ -0,0 +1,114 @@
+#!/bin/bash
+# see the README file for usage etc.
+#
+# ------------------------------------------------------------------
+# This file is part of bzip2/libbzip2, a program and library for
+# lossless, block-sorting data compression.
+#
+# bzip2/libbzip2 version 1.0.5 of 10 December 2007
+# Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+#
+# Please read the WARNING, DISCLAIMER and PATENTS sections in the
+# README file.
+#
+# This program is released under the terms of the license contained
+# in the file LICENSE.
+# ----------------------------------------------------------------
+
+
+usage() {
+ echo '';
+ echo 'Usage: xmlproc.sh -[option] <filename.xml>';
+ echo 'Specify a target from:';
+ echo '-v verify xml file conforms to dtd';
+ echo '-html output in html format (single file)';
+ echo '-ps output in postscript format';
+ echo '-pdf output in pdf format';
+ exit;
+}
+
+if test $# -ne 2; then
+ usage
+fi
+# assign the variable for the output type
+action=$1; shift
+# assign the output filename
+xmlfile=$1; shift
+# and check user input it correct
+if !(test -f $xmlfile); then
+ echo "No such file: $xmlfile";
+ exit;
+fi
+# some other stuff we will use
+OUT=output
+xsl_fo=bz-fo.xsl
+xsl_html=bz-html.xsl
+
+basename=$xmlfile
+basename=${basename//'.xml'/''}
+
+fofile="${basename}.fo"
+htmlfile="${basename}.html"
+pdffile="${basename}.pdf"
+psfile="${basename}.ps"
+xmlfmtfile="${basename}.fmt"
+
+# first process the xmlfile with CDATA tags
+./format.pl $xmlfile $xmlfmtfile
+# so the shell knows where the catalogs live
+export XML_CATALOG_FILES=/etc/xml/catalog
+
+# post-processing tidy up
+cleanup() {
+ echo "Cleaning up: $@"
+ while [ $# != 0 ]
+ do
+ arg=$1; shift;
+ echo " deleting $arg";
+ rm $arg
+ done
+}
+
+case $action in
+ -v)
+ flags='--noout --xinclude --noblanks --postvalid'
+ dtd='--dtdvalid http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd'
+ xmllint $flags $dtd $xmlfmtfile 2> $OUT
+ egrep 'error' $OUT
+ rm $OUT
+ ;;
+
+ -html)
+ echo "Creating $htmlfile ..."
+ xsltproc --nonet --xinclude -o $htmlfile $xsl_html $xmlfmtfile
+ cleanup $xmlfmtfile
+ ;;
+
+ -pdf)
+ echo "Creating $pdffile ..."
+ xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
+ pdfxmltex $fofile >$OUT </dev/null
+ pdfxmltex $fofile >$OUT </dev/null
+ pdfxmltex $fofile >$OUT </dev/null
+ cleanup $OUT $xmlfmtfile *.aux *.fo *.log *.out
+ ;;
+
+ -ps)
+ echo "Creating $psfile ..."
+ xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
+ pdfxmltex $fofile >$OUT </dev/null
+ pdfxmltex $fofile >$OUT </dev/null
+ pdfxmltex $fofile >$OUT </dev/null
+ pdftops $pdffile $psfile
+ cleanup $OUT $xmlfmtfile $pdffile *.aux *.fo *.log *.out
+# passivetex is broken, so we can't go this route yet.
+# xmltex $fofile >$OUT </dev/null
+# xmltex $fofile >$OUT </dev/null
+# xmltex $fofile >$OUT </dev/null
+# dvips -R -q -o bzip-manual.ps *.dvi
+ ;;
+
+ *)
+ usage
+ ;;
+esac
diff --git a/Utilities/cmcompress/CMakeLists.txt b/Utilities/cmcompress/CMakeLists.txt
new file mode 100644
index 0000000000..806357327c
--- /dev/null
+++ b/Utilities/cmcompress/CMakeLists.txt
@@ -0,0 +1,5 @@
+PROJECT(CMCompress)
+
+ADD_LIBRARY(cmcompress cmcompress.c)
+
+INSTALL(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR}/cmcompress)
diff --git a/Utilities/cmcompress/Copyright.txt b/Utilities/cmcompress/Copyright.txt
new file mode 100644
index 0000000000..162332f696
--- /dev/null
+++ b/Utilities/cmcompress/Copyright.txt
@@ -0,0 +1,34 @@
+Copyright (c) 1985, 1986 The Regents of the University of California.
+All rights reserved.
+
+This code is derived from software contributed to Berkeley by
+James A. Woods, derived from original work by Spencer Thomas
+and Joseph Orost.
+
+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.
+3. All advertising materials mentioning features or use of this software
+ must display the following acknowledgement:
+ This product includes software developed by the University of
+ California, Berkeley and its contributors.
+4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
diff --git a/Utilities/cmcompress/cmcompress.c b/Utilities/cmcompress/cmcompress.c
new file mode 100644
index 0000000000..ea845ed5fe
--- /dev/null
+++ b/Utilities/cmcompress/cmcompress.c
@@ -0,0 +1,551 @@
+/*
+ * Copyright (c) 1985, 1986 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * James A. Woods, derived from original work by Spencer Thomas
+ * and Joseph Orost.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+#include "cmcompress.h"
+
+#include <errno.h>
+#include <string.h>
+
+static const char_type magic_header[] = { "\037\235" }; /* 1F 9D */
+
+/* Defines for third byte of header */
+#define BIT_MASK 0x1f
+#define BLOCK_MASK 0x80
+#define CHECK_GAP 10000 /* ratio check interval */
+/* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
+ a fourth header byte (for expansion).
+ */
+#define INIT_BITS 9 /* initial number of bits/code */
+
+#ifdef COMPATIBLE /* But wrong! */
+# define MAXCODE(n_bits) (1 << (n_bits) - 1)
+#else
+# define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
+#endif /* COMPATIBLE */
+
+#define htabof(i) cdata->htab[i]
+#define codetabof(i) cdata->codetab[i]
+
+/*
+ * the next two codes should not be changed lightly, as they must not
+ * lie within the contiguous general code space.
+ */
+#define FIRST 257 /* first free entry */
+#define CLEAR 256 /* table clear output code */
+
+#ifdef DEBUG
+static void prratio( FILE *stream, long int num, long int den);
+#endif
+
+int cmcompress_compress_initialize(struct cmcompress_stream* cdata)
+{
+ cdata->maxbits = BITS; /* user settable max # bits/code */
+ cdata->maxmaxcode = 1 << BITS; /* should NEVER generate this code */
+ cdata->hsize = HSIZE; /* for dynamic table sizing */
+ cdata->free_ent = 0; /* first unused entry */
+ cdata->nomagic = 0; /* Use a 3-byte magic number header, unless old file */
+ cdata->block_compress = BLOCK_MASK;
+ cdata->clear_flg = 0;
+ cdata->ratio = 0;
+ cdata->checkpoint = CHECK_GAP;
+
+ cdata->input_stream = 0;
+ cdata->output_stream = 0;
+ cdata->client_data = 0;
+ return 1;
+}
+
+static void cl_hash(struct cmcompress_stream* cdata, count_int hsize) /* reset code table */
+{
+ register count_int *htab_p = cdata->htab+hsize;
+ register long i;
+ register long m1 = -1;
+
+ i = hsize - 16;
+ do
+ { /* might use Sys V memset(3) here */
+ *(htab_p-16) = m1;
+ *(htab_p-15) = m1;
+ *(htab_p-14) = m1;
+ *(htab_p-13) = m1;
+ *(htab_p-12) = m1;
+ *(htab_p-11) = m1;
+ *(htab_p-10) = m1;
+ *(htab_p-9) = m1;
+ *(htab_p-8) = m1;
+ *(htab_p-7) = m1;
+ *(htab_p-6) = m1;
+ *(htab_p-5) = m1;
+ *(htab_p-4) = m1;
+ *(htab_p-3) = m1;
+ *(htab_p-2) = m1;
+ *(htab_p-1) = m1;
+ htab_p -= 16;
+ }
+ while ((i -= 16) >= 0);
+ for ( i += 16; i > 0; i-- )
+ {
+ *--htab_p = m1;
+ }
+}
+
+/*-
+ * Output the given code.
+ * Inputs:
+ * code: A n_bits-bit integer. If == -1, then EOF. This assumes
+ * that n_bits =< (long)wordsize - 1.
+ * Outputs:
+ * Outputs code to the file.
+ * Assumptions:
+ * Chars are 8 bits long.
+ * Algorithm:
+ * Maintain a BITS character long buffer (so that 8 codes will
+ * fit in it exactly). Use the VAX insv instruction to insert each
+ * code in turn. When the buffer fills up empty it and start over.
+ */
+
+static char buf[BITS];
+
+#ifndef vax
+char_type lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
+char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
+#endif /* vax */
+
+static int output(struct cmcompress_stream* cdata, code_int code)
+{
+#ifdef DEBUG
+ static int col = 0;
+#endif /* DEBUG */
+
+ /*
+ * On the VAX, it is important to have the register declarations
+ * in exactly the order given, or the asm will break.
+ */
+ register int r_off = cdata->offset, bits= cdata->n_bits;
+ register char * bp = buf;
+
+#ifdef DEBUG
+ if ( verbose )
+ {
+ fprintf( stderr, "%5d%c", code,
+ (col+=6) >= 74 ? (col = 0, '\n') : ' ' );
+ }
+#endif /* DEBUG */
+ if ( code >= 0 )
+ {
+#if defined(vax) && !defined(__GNUC__)
+ /*
+ * VAX and PCC DEPENDENT!! Implementation on other machines is
+ * below.
+ *
+ * Translation: Insert BITS bits from the argument starting at
+ * cdata->offset bits from the beginning of buf.
+ */
+ 0; /* Work around for pcc -O bug with asm and if stmt */
+ asm( "insv 4(ap),r11,r10,(r9)" );
+#else
+ /*
+ * byte/bit numbering on the VAX is simulated by the following code
+ */
+ /*
+ * Get to the first byte.
+ */
+ bp += (r_off >> 3);
+ r_off &= 7;
+ /*
+ * Since code is always >= 8 bits, only need to mask the first
+ * hunk on the left.
+ */
+ *bp = (char)((*bp & rmask[r_off]) | ((code << r_off) & lmask[r_off]));
+ bp++;
+ bits -= (8 - r_off);
+ code >>= 8 - r_off;
+ /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
+ if ( bits >= 8 )
+ {
+ *bp++ = (char)(code);
+ code >>= 8;
+ bits -= 8;
+ }
+ /* Last bits. */
+ if(bits)
+ {
+ *bp = (char)(code);
+ }
+#endif /* vax */
+ cdata->offset += cdata->n_bits;
+ if ( cdata->offset == (cdata->n_bits << 3) )
+ {
+ bp = buf;
+ bits = cdata->n_bits;
+ cdata->bytes_out += bits;
+ do
+ {
+ if ( cdata->output_stream(cdata, bp, 1) != 1 )
+ {
+ return 0;
+ }
+ bp++;
+ }
+ while(--bits);
+ cdata->offset = 0;
+ }
+
+ /*
+ * If the next entry is going to be too big for the code size,
+ * then increase it, if possible.
+ */
+ if ( cdata->free_ent > cdata->maxcode || (cdata->clear_flg > 0))
+ {
+ /*
+ * Write the whole buffer, because the input side won't
+ * discover the size increase until after it has read it.
+ */
+ if ( cdata->offset > 0 )
+ {
+ if ( cdata->output_stream(cdata, buf, cdata->n_bits) != cdata->n_bits )
+ {
+ return 0;
+ }
+ cdata->bytes_out += cdata->n_bits;
+ }
+ cdata->offset = 0;
+
+ if ( cdata->clear_flg )
+ {
+ cdata->maxcode = MAXCODE (cdata->n_bits = INIT_BITS);
+ cdata->clear_flg = 0;
+ }
+ else
+ {
+ cdata->n_bits++;
+ if ( cdata->n_bits == cdata->maxbits )
+ {
+ cdata->maxcode = cdata->maxmaxcode;
+ }
+ else
+ {
+ cdata->maxcode = MAXCODE(cdata->n_bits);
+ }
+ }
+#ifdef DEBUG
+ if ( debug )
+ {
+ fprintf( stderr, "\nChange to %d bits\n", cdata->n_bits );
+ col = 0;
+ }
+#endif /* DEBUG */
+ }
+ }
+ else
+ {
+ /*
+ * At EOF, write the rest of the buffer.
+ */
+ if ( cdata->offset > 0 )
+ {
+ cdata->offset = (cdata->offset + 7) / 8;
+ if ( cdata->output_stream(cdata, buf, cdata->offset ) != cdata->offset )
+ {
+ return 0;
+ }
+ cdata->bytes_out += cdata->offset;
+ }
+ cdata->offset = 0;
+ (void)fflush( stdout );
+ if( ferror( stdout ) )
+ {
+ return 0;
+ }
+#ifdef DEBUG
+ if ( verbose )
+ {
+ fprintf( stderr, "\n" );
+ }
+#endif
+ }
+ return 1;
+}
+
+/*
+ * compress stdin to stdout
+ *
+ * Algorithm: use open addressing double hashing (no chaining) on the
+ * prefix code / next character combination. We do a variant of Knuth's
+ * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
+ * secondary probe. Here, the modular division first probe is gives way
+ * to a faster exclusive-or manipulation. Also do block compression with
+ * an adaptive reset, whereby the code table is cleared when the compression
+ * ratio decreases, but after the table fills. The variable-length output
+ * codes are re-sized at this point, and a special CLEAR code is generated
+ * for the decompressor. Late addition: construct the table according to
+ * file size for noticeable speed improvement on small files. Please direct
+ * questions about this implementation to ames!jaw.
+ */
+
+int cmcompress_compress_start(struct cmcompress_stream* cdata)
+{
+#ifndef COMPATIBLE
+ if (cdata->nomagic == 0)
+ {
+ char headLast = (char)(cdata->maxbits | cdata->block_compress);
+ cdata->output_stream(cdata, (const char*)magic_header, 2);
+ cdata->output_stream(cdata, &headLast, 1);
+ if(ferror(stdout))
+ {
+ printf("Error...\n");
+ }
+ }
+#endif /* COMPATIBLE */
+
+ cdata->offset = 0;
+ cdata->bytes_out = 3; /* includes 3-byte header mojo */
+ cdata->out_count = 0;
+ cdata->clear_flg = 0;
+ cdata->ratio = 0;
+ cdata->in_count = 1;
+ cdata->checkpoint = CHECK_GAP;
+ cdata->maxcode = MAXCODE(cdata->n_bits = INIT_BITS);
+ cdata->free_ent = ((cdata->block_compress) ? FIRST : 256 );
+
+ cdata->first_pass = 1;
+
+ cdata->hshift = 0;
+ for ( cdata->fcode = (long) cdata->hsize; cdata->fcode < 65536L; cdata->fcode *= 2L )
+ {
+ cdata->hshift++;
+ }
+ cdata->hshift = 8 - cdata->hshift; /* set hash code range bound */
+
+ cdata->hsize_reg = cdata->hsize;
+ cl_hash(cdata, (count_int) cdata->hsize_reg); /* clear hash table */
+
+ return 1;
+}
+
+static int cl_block (struct cmcompress_stream* cdata) /* table clear for block compress */
+{
+ register long int rat;
+
+ cdata->checkpoint = cdata->in_count + CHECK_GAP;
+#ifdef DEBUG
+ if ( cdata->debug )
+ {
+ fprintf ( stderr, "count: %ld, ratio: ", cdata->in_count );
+ prratio ( stderr, cdata->in_count, cdata->bytes_out );
+ fprintf ( stderr, "\n");
+ }
+#endif /* DEBUG */
+
+ if(cdata->in_count > 0x007fffff)
+ { /* shift will overflow */
+ rat = cdata->bytes_out >> 8;
+ if(rat == 0)
+ { /* Don't divide by zero */
+ rat = 0x7fffffff;
+ }
+ else
+ {
+ rat = cdata->in_count / rat;
+ }
+ }
+ else
+ {
+ rat = (cdata->in_count << 8) / cdata->bytes_out; /* 8 fractional bits */
+ }
+ if ( rat > cdata->ratio )
+ {
+ cdata->ratio = rat;
+ }
+ else
+ {
+ cdata->ratio = 0;
+#ifdef DEBUG
+ if(cdata->verbose)
+ {
+ dump_tab(); /* dump string table */
+ }
+#endif
+ cl_hash (cdata, (count_int) cdata->hsize );
+ cdata->free_ent = FIRST;
+ cdata->clear_flg = 1;
+ if ( !output (cdata, (code_int) CLEAR ) )
+ {
+ return 0;
+ }
+#ifdef DEBUG
+ if(cdata->debug)
+ {
+ fprintf ( stderr, "clear\n" );
+ }
+#endif /* DEBUG */
+ }
+ return 1;
+}
+
+
+int cmcompress_compress(struct cmcompress_stream* cdata, void* buff, size_t n)
+{
+ register code_int i;
+ register int c;
+ register int disp;
+
+ unsigned char* input_buffer = (unsigned char*)buff;
+
+ size_t cc;
+
+ /*printf("cmcompress_compress(%p, %p, %d)\n", cdata, buff, n);*/
+
+ if ( cdata->first_pass )
+ {
+ cdata->ent = input_buffer[0];
+ ++ input_buffer;
+ -- n;
+ cdata->first_pass = 0;
+ }
+
+ for ( cc = 0; cc < n; ++ cc )
+ {
+ c = input_buffer[cc];
+ cdata->in_count++;
+ cdata->fcode = (long) (((long) c << cdata->maxbits) + cdata->ent);
+ i = ((c << cdata->hshift) ^ cdata->ent); /* xor hashing */
+
+ if ( htabof (i) == cdata->fcode )
+ {
+ cdata->ent = codetabof (i);
+ continue;
+ }
+ else if ( (long)htabof (i) < 0 ) /* empty slot */
+ {
+ goto nomatch;
+ }
+ disp = (int)(cdata->hsize_reg - i); /* secondary hash (after G. Knott) */
+ if ( i == 0 )
+ {
+ disp = 1;
+ }
+probe:
+ if ( (i -= disp) < 0 )
+ {
+ i += cdata->hsize_reg;
+ }
+
+ if ( htabof (i) == cdata->fcode )
+ {
+ cdata->ent = codetabof (i);
+ continue;
+ }
+ if ( (long)htabof (i) > 0 )
+ {
+ goto probe;
+ }
+nomatch:
+ if ( !output(cdata, (code_int) cdata->ent ) )
+ {
+ return 0;
+ }
+ cdata->out_count++;
+ cdata->ent = c;
+ if (
+#ifdef SIGNED_COMPARE_SLOW
+ (unsigned) cdata->free_ent < (unsigned) cdata->maxmaxcode
+#else
+ cdata->free_ent < cdata->maxmaxcode
+#endif
+ )
+ {
+ codetabof (i) = (unsigned short)(cdata->free_ent++); /* code -> hashtable */
+ htabof (i) = cdata->fcode;
+ }
+ else if ( (count_int)cdata->in_count >= cdata->checkpoint && cdata->block_compress )
+ {
+ if ( !cl_block (cdata) )
+ {
+ return 0;
+ }
+ }
+ }
+
+ return 1;
+}
+
+int cmcompress_compress_finalize(struct cmcompress_stream* cdata)
+{
+ /*
+ * Put out the final code.
+ */
+ if ( !output(cdata, (code_int)cdata->ent ) )
+ {
+ return 0;
+ }
+ cdata->out_count++;
+ if ( !output(cdata, (code_int)-1 ) )
+ {
+ return 0;
+ }
+
+ if(cdata->bytes_out > cdata->in_count) /* exit(2) if no savings */
+ {
+ return 0;
+ }
+ return 1;
+}
+
+
+#if defined(DEBUG)
+static void prratio(FILE *stream, long int num, long int den)
+{
+ register int q; /* Doesn't need to be long */
+
+ if(num > 214748L)
+ { /* 2147483647/10000 */
+ q = num / (den / 10000L);
+ }
+ else
+ {
+ q = 10000L * num / den; /* Long calculations, though */
+ }
+ if (q < 0)
+ {
+ putc('-', stream);
+ q = -q;
+ }
+ fprintf(stream, "%d.%02d%%", q / 100, q % 100);
+}
+#endif
+
diff --git a/Utilities/cmcompress/cmcompress.h b/Utilities/cmcompress/cmcompress.h
new file mode 100644
index 0000000000..fdb0d90b77
--- /dev/null
+++ b/Utilities/cmcompress/cmcompress.h
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 1985, 1986 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * James A. Woods, derived from original work by Spencer Thomas
+ * and Joseph Orost.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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 __cmcompress__h_
+#define __cmcompress__h_
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ * Set USERMEM to the maximum amount of physical user memory available
+ * in bytes. USERMEM is used to determine the maximum BITS that can be used
+ * for compression.
+ *
+ * SACREDMEM is the amount of physical memory saved for others; compress
+ * will hog the rest.
+ */
+#ifndef SACREDMEM
+#define SACREDMEM 0
+#endif
+
+#ifndef USERMEM
+# define USERMEM 450000 /* default user memory */
+#endif
+
+#ifdef pdp11
+# define BITS 12 /* max bits/code for 16-bit machine */
+# define NO_UCHAR /* also if "unsigned char" functions as signed char */
+# undef USERMEM
+#endif /* pdp11 */ /* don't forget to compile with -i */
+
+#ifdef USERMEM
+# if USERMEM >= (433484+SACREDMEM)
+# define PBITS 16
+# else
+# if USERMEM >= (229600+SACREDMEM)
+# define PBITS 15
+# else
+# if USERMEM >= (127536+SACREDMEM)
+# define PBITS 14
+# else
+# if USERMEM >= (73464+SACREDMEM)
+# define PBITS 13
+# else
+# define PBITS 12
+# endif
+# endif
+# endif
+# endif
+# undef USERMEM
+#endif /* USERMEM */
+
+#ifdef PBITS /* Preferred BITS for this memory size */
+# ifndef BITS
+# define BITS PBITS
+# endif /* BITS */
+#endif /* PBITS */
+
+#if BITS == 16
+# define HSIZE 69001 /* 95% occupancy */
+#endif
+#if BITS == 15
+# define HSIZE 35023 /* 94% occupancy */
+#endif
+#if BITS == 14
+# define HSIZE 18013 /* 91% occupancy */
+#endif
+#if BITS == 13
+# define HSIZE 9001 /* 91% occupancy */
+#endif
+#if BITS <= 12
+# define HSIZE 5003 /* 80% occupancy */
+#endif
+
+ /*
+ * a code_int must be able to hold 2**BITS values of type int, and also -1
+ */
+#if BITS > 15
+ typedef long int code_int;
+#else
+ typedef int code_int;
+#endif
+
+#ifdef SIGNED_COMPARE_SLOW
+ typedef unsigned long int count_int;
+ typedef unsigned short int count_short;
+#else
+ typedef long int count_int;
+#endif
+
+#ifdef NO_UCHAR
+ typedef char char_type;
+#else
+ typedef unsigned char char_type;
+#endif /* UCHAR */
+
+
+
+ struct cmcompress_stream
+ {
+ int n_bits; /* number of bits/code */
+ int maxbits; /* user settable max # bits/code */
+ code_int maxcode; /* maximum code, given n_bits */
+ code_int maxmaxcode; /* should NEVER generate this code */
+
+ count_int htab [HSIZE];
+ unsigned short codetab [HSIZE];
+
+ code_int hsize; /* for dynamic table sizing */
+ code_int free_ent; /* first unused entry */
+ int nomagic; /* Use a 3-byte magic number header, unless old file */
+
+ /*
+ * block compression parameters -- after all codes are used up,
+ * and compression rate changes, start over.
+ */
+ int block_compress;
+ int clear_flg;
+ long int ratio;
+ count_int checkpoint;
+
+#ifdef DEBUG
+ int debug;
+ int verbose;
+#endif
+
+ /* compress internals */
+ int offset;
+ long int in_count; /* length of input */
+ long int bytes_out; /* length of compressed output */
+ long int out_count; /* # of codes output (for debugging) */
+
+ /* internals */
+ code_int ent;
+ code_int hsize_reg;
+ int hshift;
+
+ long fcode;
+ int first_pass;
+
+ /* For input and output */
+ int (*input_stream)(void*);
+ int (*output_stream)(void*, const char*,int);
+ void* client_data;
+ };
+
+ int cmcompress_compress_initialize(struct cmcompress_stream* cdata);
+ int cmcompress_compress_start(struct cmcompress_stream* cdata);
+ int cmcompress_compress(struct cmcompress_stream* cdata, void* buff, size_t n);
+ int cmcompress_compress_finalize(struct cmcompress_stream* cdata);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __cmcompress__h_ */
diff --git a/Utilities/cmcompress/compress.c.original b/Utilities/cmcompress/compress.c.original
new file mode 100644
index 0000000000..5062bda981
--- /dev/null
+++ b/Utilities/cmcompress/compress.c.original
@@ -0,0 +1,1308 @@
+/*
+ * Copyright (c) 1985, 1986 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * James A. Woods, derived from original work by Spencer Thomas
+ * and Joseph Orost.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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 lint
+char copyright[] =
+"@(#) Copyright (c) 1985, 1986 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)compress.c 5.19 (Berkeley) 3/18/91";
+#endif /* not lint */
+
+/*
+ * compress.c - File compression ala IEEE Computer, June 1984.
+ *
+ * Authors: Spencer W. Thomas (decvax!utah-cs!thomas)
+ * Jim McKie (decvax!mcvax!jim)
+ * Steve Davies (decvax!vax135!petsd!peora!srd)
+ * Ken Turkowski (decvax!decwrl!turtlevax!ken)
+ * James A. Woods (decvax!ihnp4!ames!jaw)
+ * Joe Orost (decvax!vax135!petsd!joe)
+ */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <utime.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * Set USERMEM to the maximum amount of physical user memory available
+ * in bytes. USERMEM is used to determine the maximum BITS that can be used
+ * for compression.
+ *
+ * SACREDMEM is the amount of physical memory saved for others; compress
+ * will hog the rest.
+ */
+#ifndef SACREDMEM
+#define SACREDMEM 0
+#endif
+
+#ifndef USERMEM
+# define USERMEM 450000 /* default user memory */
+#endif
+
+#ifdef pdp11
+# define BITS 12 /* max bits/code for 16-bit machine */
+# define NO_UCHAR /* also if "unsigned char" functions as signed char */
+# undef USERMEM
+#endif /* pdp11 */ /* don't forget to compile with -i */
+
+#ifdef USERMEM
+# if USERMEM >= (433484+SACREDMEM)
+# define PBITS 16
+# else
+# if USERMEM >= (229600+SACREDMEM)
+# define PBITS 15
+# else
+# if USERMEM >= (127536+SACREDMEM)
+# define PBITS 14
+# else
+# if USERMEM >= (73464+SACREDMEM)
+# define PBITS 13
+# else
+# define PBITS 12
+# endif
+# endif
+# endif
+# endif
+# undef USERMEM
+#endif /* USERMEM */
+
+#ifdef PBITS /* Preferred BITS for this memory size */
+# ifndef BITS
+# define BITS PBITS
+# endif BITS
+#endif /* PBITS */
+
+#if BITS == 16
+# define HSIZE 69001 /* 95% occupancy */
+#endif
+#if BITS == 15
+# define HSIZE 35023 /* 94% occupancy */
+#endif
+#if BITS == 14
+# define HSIZE 18013 /* 91% occupancy */
+#endif
+#if BITS == 13
+# define HSIZE 9001 /* 91% occupancy */
+#endif
+#if BITS <= 12
+# define HSIZE 5003 /* 80% occupancy */
+#endif
+
+/*
+ * a code_int must be able to hold 2**BITS values of type int, and also -1
+ */
+#if BITS > 15
+typedef long int code_int;
+#else
+typedef int code_int;
+#endif
+
+#ifdef SIGNED_COMPARE_SLOW
+typedef unsigned long int count_int;
+typedef unsigned short int count_short;
+#else
+typedef long int count_int;
+#endif
+
+#ifdef NO_UCHAR
+ typedef char char_type;
+#else
+ typedef unsigned char char_type;
+#endif /* UCHAR */
+char_type magic_header[] = { "\037\235" }; /* 1F 9D */
+
+/* Defines for third byte of header */
+#define BIT_MASK 0x1f
+#define BLOCK_MASK 0x80
+/* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
+ a fourth header byte (for expansion).
+*/
+#define INIT_BITS 9 /* initial number of bits/code */
+
+int n_bits; /* number of bits/code */
+int maxbits = BITS; /* user settable max # bits/code */
+code_int maxcode; /* maximum code, given n_bits */
+code_int maxmaxcode = 1 << BITS; /* should NEVER generate this code */
+#ifdef COMPATIBLE /* But wrong! */
+# define MAXCODE(n_bits) (1 << (n_bits) - 1)
+#else
+# define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
+#endif /* COMPATIBLE */
+
+count_int htab [HSIZE];
+unsigned short codetab [HSIZE];
+
+#define htabof(i) htab[i]
+#define codetabof(i) codetab[i]
+code_int hsize = HSIZE; /* for dynamic table sizing */
+count_int fsize;
+
+/*
+ * To save much memory, we overlay the table used by compress() with those
+ * used by decompress(). The tab_prefix table is the same size and type
+ * as the codetab. The tab_suffix table needs 2**BITS characters. We
+ * get this from the beginning of htab. The output stack uses the rest
+ * of htab, and contains characters. There is plenty of room for any
+ * possible stack (stack used to be 8000 characters).
+ */
+
+#define tab_prefixof(i) codetabof(i)
+# define tab_suffixof(i) ((char_type *)(htab))[i]
+# define de_stack ((char_type *)&tab_suffixof(1<<BITS))
+
+code_int free_ent = 0; /* first unused entry */
+int exit_stat = 0; /* per-file status */
+int perm_stat = 0; /* permanent status */
+
+code_int getcode();
+
+int nomagic = 0; /* Use a 3-byte magic number header, unless old file */
+int zcat_flg = 0; /* Write output on stdout, suppress messages */
+int precious = 1; /* Don't unlink output file on interrupt */
+int quiet = 1; /* don't tell me about compression */
+
+/*
+ * block compression parameters -- after all codes are used up,
+ * and compression rate changes, start over.
+ */
+int block_compress = BLOCK_MASK;
+int clear_flg = 0;
+long int ratio = 0;
+#define CHECK_GAP 10000 /* ratio check interval */
+count_int checkpoint = CHECK_GAP;
+/*
+ * the next two codes should not be changed lightly, as they must not
+ * lie within the contiguous general code space.
+ */
+#define FIRST 257 /* first free entry */
+#define CLEAR 256 /* table clear output code */
+
+int force = 0;
+char ofname [100];
+#ifdef DEBUG
+int debug, verbose;
+#endif
+sig_t oldint;
+int bgnd_flag;
+
+int do_decomp = 0;
+
+/*-
+ * Algorithm from "A Technique for High Performance Data Compression",
+ * Terry A. Welch, IEEE Computer Vol 17, No 6 (June 1984), pp 8-19.
+ *
+ * Usage: compress [-dfvc] [-b bits] [file ...]
+ * Inputs:
+ * -d: If given, decompression is done instead.
+ *
+ * -c: Write output on stdout, don't remove original.
+ *
+ * -b: Parameter limits the max number of bits/code.
+ *
+ * -f: Forces output file to be generated, even if one already
+ * exists, and even if no space is saved by compressing.
+ * If -f is not used, the user will be prompted if stdin is
+ * a tty, otherwise, the output file will not be overwritten.
+ *
+ * -v: Write compression statistics
+ *
+ * file ...: Files to be compressed. If none specified, stdin
+ * is used.
+ * Outputs:
+ * file.Z: Compressed form of file with same mode, owner, and utimes
+ * or stdout (if stdin used as input)
+ *
+ * Assumptions:
+ * When filenames are given, replaces with the compressed version
+ * (.Z suffix) only if the file decreases in size.
+ * Algorithm:
+ * Modified Lempel-Ziv method (LZW). Basically finds common
+ * substrings and replaces them with a variable size code. This is
+ * deterministic, and can be done on the fly. Thus, the decompression
+ * procedure needs no input table, but tracks the way the table was built.
+ */
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ extern int optind;
+ extern char *optarg;
+ struct stat statbuf;
+ int ch, overwrite;
+ char **filelist, **fileptr, *cp, tempname[MAXPATHLEN];
+ void onintr(), oops();
+
+ /* This bg check only works for sh. */
+ if ((oldint = signal(SIGINT, SIG_IGN)) != SIG_IGN) {
+ (void)signal(SIGINT, onintr);
+ (void)signal(SIGSEGV, oops); /* XXX */
+ }
+ bgnd_flag = oldint != SIG_DFL;
+
+#ifdef COMPATIBLE
+ nomagic = 1; /* Original didn't have a magic number */
+#endif
+
+ if (cp = rindex(argv[0], '/'))
+ ++cp;
+ else
+ cp = argv[0];
+ if (strcmp(cp, "uncompress") == 0)
+ do_decomp = 1;
+ else if(strcmp(cp, "zcat") == 0) {
+ do_decomp = 1;
+ zcat_flg = 1;
+ }
+
+ /*
+ * -b maxbits => maxbits.
+ * -C => generate output compatible with compress 2.0.
+ * -c => cat all output to stdout
+ * -D => debug
+ * -d => do_decomp
+ * -f => force overwrite of output file
+ * -n => no header: useful to uncompress old files
+ * -V => print Version; debug verbose
+ * -v => unquiet
+ */
+
+ overwrite = 0;
+#ifdef DEBUG
+ while ((ch = getopt(argc, argv, "b:CcDdfnVv")) != EOF)
+#else
+ while ((ch = getopt(argc, argv, "b:Ccdfnv")) != EOF)
+#endif
+ switch(ch) {
+ case 'b':
+ maxbits = atoi(optarg);
+ break;
+ case 'C':
+ block_compress = 0;
+ break;
+ case 'c':
+ zcat_flg = 1;
+ break;
+#ifdef DEBUG
+ case 'D':
+ debug = 1;
+ break;
+#endif
+ case 'd':
+ do_decomp = 1;
+ break;
+ case 'f':
+ overwrite = 1;
+ force = 1;
+ break;
+ case 'n':
+ nomagic = 1;
+ break;
+ case 'q':
+ quiet = 1;
+ break;
+#ifdef DEBUG
+ case 'V':
+ verbose = 1;
+ break;
+#endif
+ case 'v':
+ quiet = 0;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (maxbits < INIT_BITS)
+ maxbits = INIT_BITS;
+ if (maxbits > BITS)
+ maxbits = BITS;
+ maxmaxcode = 1 << maxbits;
+
+ /* Build useless input file list. */
+ filelist = fileptr = (char **)(malloc(argc * sizeof(*argv)));
+ while (*argv)
+ *fileptr++ = *argv++;
+ *fileptr = NULL;
+
+ if (*filelist != NULL) {
+ for (fileptr = filelist; *fileptr; fileptr++) {
+ exit_stat = 0;
+ if (do_decomp) { /* DECOMPRESSION */
+ /* Check for .Z suffix */
+ if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") != 0) {
+ /* No .Z: tack one on */
+ strcpy(tempname, *fileptr);
+ strcat(tempname, ".Z");
+ *fileptr = tempname;
+ }
+ /* Open input file */
+ if ((freopen(*fileptr, "r", stdin)) == NULL) {
+ perror(*fileptr);
+ perm_stat = 1;
+ continue;
+ }
+ /* Check the magic number */
+ if (nomagic == 0) {
+ if ((getchar() != (magic_header[0] & 0xFF))
+ || (getchar() != (magic_header[1] & 0xFF))) {
+ fprintf(stderr, "%s: not in compressed format\n",
+ *fileptr);
+ continue;
+ }
+ maxbits = getchar(); /* set -b from file */
+ block_compress = maxbits & BLOCK_MASK;
+ maxbits &= BIT_MASK;
+ maxmaxcode = 1 << maxbits;
+ if(maxbits > BITS) {
+ fprintf(stderr,
+ "%s: compressed with %d bits, can only handle %d bits\n",
+ *fileptr, maxbits, BITS);
+ continue;
+ }
+ }
+ /* Generate output filename */
+ strcpy(ofname, *fileptr);
+ ofname[strlen(*fileptr) - 2] = '\0'; /* Strip off .Z */
+ } else { /* COMPRESSION */
+ if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") == 0) {
+ fprintf(stderr, "%s: already has .Z suffix -- no change\n",
+ *fileptr);
+ continue;
+ }
+ /* Open input file */
+ if ((freopen(*fileptr, "r", stdin)) == NULL) {
+ perror(*fileptr);
+ perm_stat = 1;
+ continue;
+ }
+ stat ( *fileptr, &statbuf );
+ fsize = (long) statbuf.st_size;
+ /*
+ * tune hash table size for small files -- ad hoc,
+ * but the sizes match earlier #defines, which
+ * serve as upper bounds on the number of output codes.
+ */
+ hsize = HSIZE;
+ if ( fsize < (1 << 12) )
+ hsize = MIN ( 5003, HSIZE );
+ else if ( fsize < (1 << 13) )
+ hsize = MIN ( 9001, HSIZE );
+ else if ( fsize < (1 << 14) )
+ hsize = MIN ( 18013, HSIZE );
+ else if ( fsize < (1 << 15) )
+ hsize = MIN ( 35023, HSIZE );
+ else if ( fsize < 47000 )
+ hsize = MIN ( 50021, HSIZE );
+
+ /* Generate output filename */
+ strcpy(ofname, *fileptr);
+ strcat(ofname, ".Z");
+ }
+ /* Check for overwrite of existing file */
+ if (overwrite == 0 && zcat_flg == 0) {
+ if (stat(ofname, &statbuf) == 0) {
+ char response[2];
+ response[0] = 'n';
+ fprintf(stderr, "%s already exists;", ofname);
+ if (bgnd_flag == 0 && isatty(2)) {
+ fprintf(stderr, " do you wish to overwrite %s (y or n)? ",
+ ofname);
+ fflush(stderr);
+ read(2, response, 2);
+ while (response[1] != '\n') {
+ if (read(2, response+1, 1) < 0) { /* Ack! */
+ perror("stderr"); break;
+ }
+ }
+ }
+ if (response[0] != 'y') {
+ fprintf(stderr, "\tnot overwritten\n");
+ continue;
+ }
+ }
+ }
+ if(zcat_flg == 0) { /* Open output file */
+ if (freopen(ofname, "w", stdout) == NULL) {
+ perror(ofname);
+ perm_stat = 1;
+ continue;
+ }
+ precious = 0;
+ if(!quiet)
+ fprintf(stderr, "%s: ", *fileptr);
+ }
+
+ /* Actually do the compression/decompression */
+ if (do_decomp == 0) compress();
+#ifndef DEBUG
+ else decompress();
+#else
+ else if (debug == 0) decompress();
+ else printcodes();
+ if (verbose) dump_tab();
+#endif /* DEBUG */
+ if(zcat_flg == 0) {
+ copystat(*fileptr, ofname); /* Copy stats */
+ precious = 1;
+ if((exit_stat == 1) || (!quiet))
+ putc('\n', stderr);
+ }
+ }
+ } else { /* Standard input */
+ if (do_decomp == 0) {
+ compress();
+#ifdef DEBUG
+ if(verbose) dump_tab();
+#endif /* DEBUG */
+ if(!quiet)
+ putc('\n', stderr);
+ } else {
+ /* Check the magic number */
+ if (nomagic == 0) {
+ if ((getchar()!=(magic_header[0] & 0xFF))
+ || (getchar()!=(magic_header[1] & 0xFF))) {
+ fprintf(stderr, "stdin: not in compressed format\n");
+ exit(1);
+ }
+ maxbits = getchar(); /* set -b from file */
+ block_compress = maxbits & BLOCK_MASK;
+ maxbits &= BIT_MASK;
+ maxmaxcode = 1 << maxbits;
+ fsize = 100000; /* assume stdin large for USERMEM */
+ if(maxbits > BITS) {
+ fprintf(stderr,
+ "stdin: compressed with %d bits, can only handle %d bits\n",
+ maxbits, BITS);
+ exit(1);
+ }
+ }
+#ifndef DEBUG
+ decompress();
+#else
+ if (debug == 0) decompress();
+ else printcodes();
+ if (verbose) dump_tab();
+#endif /* DEBUG */
+ }
+ }
+ exit(perm_stat ? perm_stat : exit_stat);
+}
+
+static int offset;
+long int in_count = 1; /* length of input */
+long int bytes_out; /* length of compressed output */
+long int out_count = 0; /* # of codes output (for debugging) */
+
+/*
+ * compress stdin to stdout
+ *
+ * Algorithm: use open addressing double hashing (no chaining) on the
+ * prefix code / next character combination. We do a variant of Knuth's
+ * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
+ * secondary probe. Here, the modular division first probe is gives way
+ * to a faster exclusive-or manipulation. Also do block compression with
+ * an adaptive reset, whereby the code table is cleared when the compression
+ * ratio decreases, but after the table fills. The variable-length output
+ * codes are re-sized at this point, and a special CLEAR code is generated
+ * for the decompressor. Late addition: construct the table according to
+ * file size for noticeable speed improvement on small files. Please direct
+ * questions about this implementation to ames!jaw.
+ */
+
+compress()
+{
+ register long fcode;
+ register code_int i = 0;
+ register int c;
+ register code_int ent;
+ register int disp;
+ register code_int hsize_reg;
+ register int hshift;
+
+#ifndef COMPATIBLE
+ if (nomagic == 0) {
+ putchar(magic_header[0]);
+ putchar(magic_header[1]);
+ putchar((char)(maxbits | block_compress));
+ if(ferror(stdout))
+ writeerr();
+ }
+#endif /* COMPATIBLE */
+
+ offset = 0;
+ bytes_out = 3; /* includes 3-byte header mojo */
+ out_count = 0;
+ clear_flg = 0;
+ ratio = 0;
+ in_count = 1;
+ checkpoint = CHECK_GAP;
+ maxcode = MAXCODE(n_bits = INIT_BITS);
+ free_ent = ((block_compress) ? FIRST : 256 );
+
+ ent = getchar ();
+
+ hshift = 0;
+ for ( fcode = (long) hsize; fcode < 65536L; fcode *= 2L )
+ hshift++;
+ hshift = 8 - hshift; /* set hash code range bound */
+
+ hsize_reg = hsize;
+ cl_hash( (count_int) hsize_reg); /* clear hash table */
+
+#ifdef SIGNED_COMPARE_SLOW
+ while ( (c = getchar()) != (unsigned) EOF ) {
+#else
+ while ( (c = getchar()) != EOF ) {
+#endif
+ in_count++;
+ fcode = (long) (((long) c << maxbits) + ent);
+ i = ((c << hshift) ^ ent); /* xor hashing */
+
+ if ( htabof (i) == fcode ) {
+ ent = codetabof (i);
+ continue;
+ } else if ( (long)htabof (i) < 0 ) /* empty slot */
+ goto nomatch;
+ disp = hsize_reg - i; /* secondary hash (after G. Knott) */
+ if ( i == 0 )
+ disp = 1;
+probe:
+ if ( (i -= disp) < 0 )
+ i += hsize_reg;
+
+ if ( htabof (i) == fcode ) {
+ ent = codetabof (i);
+ continue;
+ }
+ if ( (long)htabof (i) > 0 )
+ goto probe;
+nomatch:
+ output ( (code_int) ent );
+ out_count++;
+ ent = c;
+#ifdef SIGNED_COMPARE_SLOW
+ if ( (unsigned) free_ent < (unsigned) maxmaxcode) {
+#else
+ if ( free_ent < maxmaxcode ) {
+#endif
+ codetabof (i) = free_ent++; /* code -> hashtable */
+ htabof (i) = fcode;
+ }
+ else if ( (count_int)in_count >= checkpoint && block_compress )
+ cl_block ();
+ }
+ /*
+ * Put out the final code.
+ */
+ output( (code_int)ent );
+ out_count++;
+ output( (code_int)-1 );
+
+ /*
+ * Print out stats on stderr
+ */
+ if(zcat_flg == 0 && !quiet) {
+#ifdef DEBUG
+ fprintf( stderr,
+ "%ld chars in, %ld codes (%ld bytes) out, compression factor: ",
+ in_count, out_count, bytes_out );
+ prratio( stderr, in_count, bytes_out );
+ fprintf( stderr, "\n");
+ fprintf( stderr, "\tCompression as in compact: " );
+ prratio( stderr, in_count-bytes_out, in_count );
+ fprintf( stderr, "\n");
+ fprintf( stderr, "\tLargest code (of last block) was %d (%d bits)\n",
+ free_ent - 1, n_bits );
+#else /* !DEBUG */
+ fprintf( stderr, "Compression: " );
+ prratio( stderr, in_count-bytes_out, in_count );
+#endif /* DEBUG */
+ }
+ if(bytes_out > in_count) /* exit(2) if no savings */
+ exit_stat = 2;
+ return;
+}
+
+/*-
+ * Output the given code.
+ * Inputs:
+ * code: A n_bits-bit integer. If == -1, then EOF. This assumes
+ * that n_bits =< (long)wordsize - 1.
+ * Outputs:
+ * Outputs code to the file.
+ * Assumptions:
+ * Chars are 8 bits long.
+ * Algorithm:
+ * Maintain a BITS character long buffer (so that 8 codes will
+ * fit in it exactly). Use the VAX insv instruction to insert each
+ * code in turn. When the buffer fills up empty it and start over.
+ */
+
+static char buf[BITS];
+
+#ifndef vax
+char_type lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
+char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
+#endif /* vax */
+
+output( code )
+code_int code;
+{
+#ifdef DEBUG
+ static int col = 0;
+#endif /* DEBUG */
+
+ /*
+ * On the VAX, it is important to have the register declarations
+ * in exactly the order given, or the asm will break.
+ */
+ register int r_off = offset, bits= n_bits;
+ register char * bp = buf;
+
+#ifdef DEBUG
+ if ( verbose )
+ fprintf( stderr, "%5d%c", code,
+ (col+=6) >= 74 ? (col = 0, '\n') : ' ' );
+#endif /* DEBUG */
+ if ( code >= 0 ) {
+#if defined(vax) && !defined(__GNUC__)
+ /*
+ * VAX and PCC DEPENDENT!! Implementation on other machines is
+ * below.
+ *
+ * Translation: Insert BITS bits from the argument starting at
+ * offset bits from the beginning of buf.
+ */
+ 0; /* Work around for pcc -O bug with asm and if stmt */
+ asm( "insv 4(ap),r11,r10,(r9)" );
+#else
+/*
+ * byte/bit numbering on the VAX is simulated by the following code
+ */
+ /*
+ * Get to the first byte.
+ */
+ bp += (r_off >> 3);
+ r_off &= 7;
+ /*
+ * Since code is always >= 8 bits, only need to mask the first
+ * hunk on the left.
+ */
+ *bp = (*bp & rmask[r_off]) | (code << r_off) & lmask[r_off];
+ bp++;
+ bits -= (8 - r_off);
+ code >>= 8 - r_off;
+ /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
+ if ( bits >= 8 ) {
+ *bp++ = code;
+ code >>= 8;
+ bits -= 8;
+ }
+ /* Last bits. */
+ if(bits)
+ *bp = code;
+#endif /* vax */
+ offset += n_bits;
+ if ( offset == (n_bits << 3) ) {
+ bp = buf;
+ bits = n_bits;
+ bytes_out += bits;
+ do {
+ putchar(*bp++);
+ if (ferror(stdout))
+ writeerr();
+ } while(--bits);
+ offset = 0;
+ }
+
+ /*
+ * If the next entry is going to be too big for the code size,
+ * then increase it, if possible.
+ */
+ if ( free_ent > maxcode || (clear_flg > 0))
+ {
+ /*
+ * Write the whole buffer, because the input side won't
+ * discover the size increase until after it has read it.
+ */
+ if ( offset > 0 ) {
+ if( fwrite( buf, 1, n_bits, stdout ) != n_bits)
+ writeerr();
+ bytes_out += n_bits;
+ }
+ offset = 0;
+
+ if ( clear_flg ) {
+ maxcode = MAXCODE (n_bits = INIT_BITS);
+ clear_flg = 0;
+ }
+ else {
+ n_bits++;
+ if ( n_bits == maxbits )
+ maxcode = maxmaxcode;
+ else
+ maxcode = MAXCODE(n_bits);
+ }
+#ifdef DEBUG
+ if ( debug ) {
+ fprintf( stderr, "\nChange to %d bits\n", n_bits );
+ col = 0;
+ }
+#endif /* DEBUG */
+ }
+ } else {
+ /*
+ * At EOF, write the rest of the buffer.
+ */
+ if ( offset > 0 ) {
+ offset = (offset + 7) / 8;
+ if( fwrite( buf, 1, offset, stdout ) != offset )
+ writeerr();
+ bytes_out += offset;
+ }
+ offset = 0;
+ (void)fflush( stdout );
+ if( ferror( stdout ) )
+ writeerr();
+#ifdef DEBUG
+ if ( verbose )
+ fprintf( stderr, "\n" );
+#endif
+ }
+}
+
+/*
+ * Decompress stdin to stdout. This routine adapts to the codes in the
+ * file building the "string" table on-the-fly; requiring no table to
+ * be stored in the compressed file. The tables used herein are shared
+ * with those of the compress() routine. See the definitions above.
+ */
+
+decompress() {
+ register char_type *stackp;
+ register int finchar;
+ register code_int code, oldcode, incode;
+ int n, nwritten, offset; /* Variables for buffered write */
+ char buff[BUFSIZ]; /* Buffer for buffered write */
+
+
+ /*
+ * As above, initialize the first 256 entries in the table.
+ */
+ maxcode = MAXCODE(n_bits = INIT_BITS);
+ for ( code = 255; code >= 0; code-- ) {
+ tab_prefixof(code) = 0;
+ tab_suffixof(code) = (char_type)code;
+ }
+ free_ent = ((block_compress) ? FIRST : 256 );
+
+ finchar = oldcode = getcode();
+ if(oldcode == -1) /* EOF already? */
+ return; /* Get out of here */
+
+ /* first code must be 8 bits = char */
+ n=0;
+ buff[n++] = (char)finchar;
+
+ stackp = de_stack;
+
+ while ( (code = getcode()) > -1 ) {
+
+ if ( (code == CLEAR) && block_compress ) {
+ for ( code = 255; code >= 0; code-- )
+ tab_prefixof(code) = 0;
+ clear_flg = 1;
+ free_ent = FIRST - 1;
+ if ( (code = getcode ()) == -1 ) /* O, untimely death! */
+ break;
+ }
+ incode = code;
+ /*
+ * Special case for KwKwK string.
+ */
+ if ( code >= free_ent ) {
+ *stackp++ = finchar;
+ code = oldcode;
+ }
+
+ /*
+ * Generate output characters in reverse order
+ */
+#ifdef SIGNED_COMPARE_SLOW
+ while ( ((unsigned long)code) >= ((unsigned long)256) ) {
+#else
+ while ( code >= 256 ) {
+#endif
+ *stackp++ = tab_suffixof(code);
+ code = tab_prefixof(code);
+ }
+ *stackp++ = finchar = tab_suffixof(code);
+
+ /*
+ * And put them out in forward order
+ */
+ do {
+ /*
+ * About 60% of the time is spent in the putchar() call
+ * that appeared here. It was originally
+ * putchar ( *--stackp );
+ * If we buffer the writes ourselves, we can go faster (about
+ * 30%).
+ *
+ * At this point, the next line is the next *big* time
+ * sink in the code. It takes up about 10% of the time.
+ */
+ buff[n++] = *--stackp;
+ if (n == BUFSIZ) {
+ offset = 0;
+ do {
+ nwritten = write(fileno(stdout), &buff[offset], n);
+ if (nwritten < 0)
+ writeerr();
+ offset += nwritten;
+ } while ((n -= nwritten) > 0);
+ }
+ } while ( stackp > de_stack );
+
+ /*
+ * Generate the new entry.
+ */
+ if ( (code=free_ent) < maxmaxcode ) {
+ tab_prefixof(code) = (unsigned short)oldcode;
+ tab_suffixof(code) = finchar;
+ free_ent = code+1;
+ }
+ /*
+ * Remember previous code.
+ */
+ oldcode = incode;
+ }
+ /*
+ * Flush the stuff remaining in our buffer...
+ */
+ offset = 0;
+ while (n > 0) {
+ nwritten = write(fileno(stdout), &buff[offset], n);
+ if (nwritten < 0)
+ writeerr();
+ offset += nwritten;
+ n -= nwritten;
+ }
+}
+
+/*-
+ * Read one code from the standard input. If EOF, return -1.
+ * Inputs:
+ * stdin
+ * Outputs:
+ * code or -1 is returned.
+ */
+code_int
+getcode() {
+ /*
+ * On the VAX, it is important to have the register declarations
+ * in exactly the order given, or the asm will break.
+ */
+ register code_int code;
+ static int offset = 0, size = 0;
+ static char_type buf[BITS];
+ register int r_off, bits;
+ register char_type *bp = buf;
+
+ if ( clear_flg > 0 || offset >= size || free_ent > maxcode ) {
+ /*
+ * If the next entry will be too big for the current code
+ * size, then we must increase the size. This implies reading
+ * a new buffer full, too.
+ */
+ if ( free_ent > maxcode ) {
+ n_bits++;
+ if ( n_bits == maxbits )
+ maxcode = maxmaxcode; /* won't get any bigger now */
+ else
+ maxcode = MAXCODE(n_bits);
+ }
+ if ( clear_flg > 0) {
+ maxcode = MAXCODE (n_bits = INIT_BITS);
+ clear_flg = 0;
+ }
+ size = fread( buf, 1, n_bits, stdin );
+ if ( size <= 0 )
+ return -1; /* end of file */
+ offset = 0;
+ /* Round size down to integral number of codes */
+ size = (size << 3) - (n_bits - 1);
+ }
+ r_off = offset;
+ bits = n_bits;
+#ifdef vax
+ asm( "extzv r10,r9,(r8),r11" );
+#else /* not a vax */
+ /*
+ * Get to the first byte.
+ */
+ bp += (r_off >> 3);
+ r_off &= 7;
+ /* Get first part (low order bits) */
+#ifdef NO_UCHAR
+ code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff;
+#else
+ code = (*bp++ >> r_off);
+#endif /* NO_UCHAR */
+ bits -= (8 - r_off);
+ r_off = 8 - r_off; /* now, offset into code word */
+ /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
+ if ( bits >= 8 ) {
+#ifdef NO_UCHAR
+ code |= (*bp++ & 0xff) << r_off;
+#else
+ code |= *bp++ << r_off;
+#endif /* NO_UCHAR */
+ r_off += 8;
+ bits -= 8;
+ }
+ /* high order bits. */
+ code |= (*bp & rmask[bits]) << r_off;
+#endif /* vax */
+ offset += n_bits;
+
+ return code;
+}
+
+#ifdef DEBUG
+printcodes()
+{
+ /*
+ * Just print out codes from input file. For debugging.
+ */
+ code_int code;
+ int col = 0, bits;
+
+ bits = n_bits = INIT_BITS;
+ maxcode = MAXCODE(n_bits);
+ free_ent = ((block_compress) ? FIRST : 256 );
+ while ( ( code = getcode() ) >= 0 ) {
+ if ( (code == CLEAR) && block_compress ) {
+ free_ent = FIRST - 1;
+ clear_flg = 1;
+ }
+ else if ( free_ent < maxmaxcode )
+ free_ent++;
+ if ( bits != n_bits ) {
+ fprintf(stderr, "\nChange to %d bits\n", n_bits );
+ bits = n_bits;
+ col = 0;
+ }
+ fprintf(stderr, "%5d%c", code, (col+=6) >= 74 ? (col = 0, '\n') : ' ' );
+ }
+ putc( '\n', stderr );
+ exit( 0 );
+}
+
+code_int sorttab[1<<BITS]; /* sorted pointers into htab */
+
+dump_tab() /* dump string table */
+{
+ register int i, first;
+ register ent;
+#define STACK_SIZE 15000
+ int stack_top = STACK_SIZE;
+ register c;
+
+ if(do_decomp == 0) { /* compressing */
+ register int flag = 1;
+
+ for(i=0; i<hsize; i++) { /* build sort pointers */
+ if((long)htabof(i) >= 0) {
+ sorttab[codetabof(i)] = i;
+ }
+ }
+ first = block_compress ? FIRST : 256;
+ for(i = first; i < free_ent; i++) {
+ fprintf(stderr, "%5d: \"", i);
+ de_stack[--stack_top] = '\n';
+ de_stack[--stack_top] = '"';
+ stack_top = in_stack((htabof(sorttab[i])>>maxbits)&0xff,
+ stack_top);
+ for(ent=htabof(sorttab[i]) & ((1<<maxbits)-1);
+ ent > 256;
+ ent=htabof(sorttab[ent]) & ((1<<maxbits)-1)) {
+ stack_top = in_stack(htabof(sorttab[ent]) >> maxbits,
+ stack_top);
+ }
+ stack_top = in_stack(ent, stack_top);
+ fwrite( &de_stack[stack_top], 1, STACK_SIZE-stack_top, stderr);
+ stack_top = STACK_SIZE;
+ }
+ } else if(!debug) { /* decompressing */
+
+ for ( i = 0; i < free_ent; i++ ) {
+ ent = i;
+ c = tab_suffixof(ent);
+ if ( isascii(c) && isprint(c) )
+ fprintf( stderr, "%5d: %5d/'%c' \"",
+ ent, tab_prefixof(ent), c );
+ else
+ fprintf( stderr, "%5d: %5d/\\%03o \"",
+ ent, tab_prefixof(ent), c );
+ de_stack[--stack_top] = '\n';
+ de_stack[--stack_top] = '"';
+ for ( ; ent != NULL;
+ ent = (ent >= FIRST ? tab_prefixof(ent) : NULL) ) {
+ stack_top = in_stack(tab_suffixof(ent), stack_top);
+ }
+ fwrite( &de_stack[stack_top], 1, STACK_SIZE - stack_top, stderr );
+ stack_top = STACK_SIZE;
+ }
+ }
+}
+
+int
+in_stack(c, stack_top)
+ register c, stack_top;
+{
+ if ( (isascii(c) && isprint(c) && c != '\\') || c == ' ' ) {
+ de_stack[--stack_top] = c;
+ } else {
+ switch( c ) {
+ case '\n': de_stack[--stack_top] = 'n'; break;
+ case '\t': de_stack[--stack_top] = 't'; break;
+ case '\b': de_stack[--stack_top] = 'b'; break;
+ case '\f': de_stack[--stack_top] = 'f'; break;
+ case '\r': de_stack[--stack_top] = 'r'; break;
+ case '\\': de_stack[--stack_top] = '\\'; break;
+ default:
+ de_stack[--stack_top] = '0' + c % 8;
+ de_stack[--stack_top] = '0' + (c / 8) % 8;
+ de_stack[--stack_top] = '0' + c / 64;
+ break;
+ }
+ de_stack[--stack_top] = '\\';
+ }
+ return stack_top;
+}
+#endif /* DEBUG */
+
+writeerr()
+{
+ (void)fprintf(stderr, "compress: %s: %s\n",
+ ofname[0] ? ofname : "stdout", strerror(errno));
+ (void)unlink(ofname);
+ exit(1);
+}
+
+copystat(ifname, ofname)
+char *ifname, *ofname;
+{
+ struct stat statbuf;
+ int mode;
+ struct utimbuf tp;
+
+ fclose(stdout);
+ if (stat(ifname, &statbuf)) { /* Get stat on input file */
+ perror(ifname);
+ return;
+ }
+ if ((statbuf.st_mode & S_IFMT/*0170000*/) != S_IFREG/*0100000*/) {
+ if(quiet)
+ fprintf(stderr, "%s: ", ifname);
+ fprintf(stderr, " -- not a regular file: unchanged");
+ exit_stat = 1;
+ perm_stat = 1;
+ } else if (statbuf.st_nlink > 1) {
+ if(quiet)
+ fprintf(stderr, "%s: ", ifname);
+ fprintf(stderr, " -- has %d other links: unchanged",
+ statbuf.st_nlink - 1);
+ exit_stat = 1;
+ perm_stat = 1;
+ } else if (exit_stat == 2 && (!force)) { /* No compression: remove file.Z */
+ if(!quiet)
+ fprintf(stderr, " -- file unchanged");
+ } else { /* ***** Successful Compression ***** */
+ exit_stat = 0;
+ mode = statbuf.st_mode & 07777;
+ if (chmod(ofname, mode)) /* Copy modes */
+ perror(ofname);
+ chown(ofname, statbuf.st_uid, statbuf.st_gid); /* Copy ownership */
+ tp.actime = statbuf.st_atime;
+ tp.modtime = statbuf.st_mtime;
+ utime(ofname, &tp); /* Update last accessed and modified times */
+ if (unlink(ifname)) /* Remove input file */
+ perror(ifname);
+ if(!quiet)
+ fprintf(stderr, " -- replaced with %s", ofname);
+ return; /* Successful return */
+ }
+
+ /* Unsuccessful return -- one of the tests failed */
+ if (unlink(ofname))
+ perror(ofname);
+}
+
+void
+onintr ( )
+{
+ if (!precious)
+ unlink ( ofname );
+ exit ( 1 );
+}
+
+void
+oops ( ) /* wild pointer -- assume bad input */
+{
+ if ( do_decomp )
+ fprintf ( stderr, "uncompress: corrupt input\n" );
+ unlink ( ofname );
+ exit ( 1 );
+}
+
+cl_block () /* table clear for block compress */
+{
+ register long int rat;
+
+ checkpoint = in_count + CHECK_GAP;
+#ifdef DEBUG
+ if ( debug ) {
+ fprintf ( stderr, "count: %ld, ratio: ", in_count );
+ prratio ( stderr, in_count, bytes_out );
+ fprintf ( stderr, "\n");
+ }
+#endif /* DEBUG */
+
+ if(in_count > 0x007fffff) { /* shift will overflow */
+ rat = bytes_out >> 8;
+ if(rat == 0) { /* Don't divide by zero */
+ rat = 0x7fffffff;
+ } else {
+ rat = in_count / rat;
+ }
+ } else {
+ rat = (in_count << 8) / bytes_out; /* 8 fractional bits */
+ }
+ if ( rat > ratio ) {
+ ratio = rat;
+ } else {
+ ratio = 0;
+#ifdef DEBUG
+ if(verbose)
+ dump_tab(); /* dump string table */
+#endif
+ cl_hash ( (count_int) hsize );
+ free_ent = FIRST;
+ clear_flg = 1;
+ output ( (code_int) CLEAR );
+#ifdef DEBUG
+ if(debug)
+ fprintf ( stderr, "clear\n" );
+#endif /* DEBUG */
+ }
+}
+
+cl_hash(hsize) /* reset code table */
+ register count_int hsize;
+{
+ register count_int *htab_p = htab+hsize;
+ register long i;
+ register long m1 = -1;
+
+ i = hsize - 16;
+ do { /* might use Sys V memset(3) here */
+ *(htab_p-16) = m1;
+ *(htab_p-15) = m1;
+ *(htab_p-14) = m1;
+ *(htab_p-13) = m1;
+ *(htab_p-12) = m1;
+ *(htab_p-11) = m1;
+ *(htab_p-10) = m1;
+ *(htab_p-9) = m1;
+ *(htab_p-8) = m1;
+ *(htab_p-7) = m1;
+ *(htab_p-6) = m1;
+ *(htab_p-5) = m1;
+ *(htab_p-4) = m1;
+ *(htab_p-3) = m1;
+ *(htab_p-2) = m1;
+ *(htab_p-1) = m1;
+ htab_p -= 16;
+ } while ((i -= 16) >= 0);
+ for ( i += 16; i > 0; i-- )
+ *--htab_p = m1;
+}
+
+prratio(stream, num, den)
+FILE *stream;
+long int num, den;
+{
+ register int q; /* Doesn't need to be long */
+
+ if(num > 214748L) { /* 2147483647/10000 */
+ q = num / (den / 10000L);
+ } else {
+ q = 10000L * num / den; /* Long calculations, though */
+ }
+ if (q < 0) {
+ putc('-', stream);
+ q = -q;
+ }
+ fprintf(stream, "%d.%02d%%", q / 100, q % 100);
+}
+
+usage()
+{
+ (void)fprintf(stderr,
+#ifdef DEBUG
+ "compress [-CDVcdfnv] [-b maxbits] [file ...]\n");
+#else
+ "compress [-Ccdfnv] [-b maxbits] [file ...]\n");
+#endif
+ exit(1);
+}
diff --git a/Utilities/cmcurl/CMake/CMakeConfigurableFile.in b/Utilities/cmcurl/CMake/CMakeConfigurableFile.in
new file mode 100644
index 0000000000..4cf74a12bb
--- /dev/null
+++ b/Utilities/cmcurl/CMake/CMakeConfigurableFile.in
@@ -0,0 +1,2 @@
+@CMAKE_CONFIGURABLE_FILE_CONTENT@
+
diff --git a/Utilities/cmcurl/CMake/CurlCheckCSourceCompiles.cmake b/Utilities/cmcurl/CMake/CurlCheckCSourceCompiles.cmake
new file mode 100644
index 0000000000..2f427a2a7d
--- /dev/null
+++ b/Utilities/cmcurl/CMake/CurlCheckCSourceCompiles.cmake
@@ -0,0 +1,74 @@
+# - Check if the source code provided in the SOURCE argument compiles.
+# CURL_CHECK_C_SOURCE_COMPILES(SOURCE VAR)
+# - macro which checks if the source code compiles
+# SOURCE - source code to try to compile
+# VAR - variable to store whether the source code compiled
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+
+MACRO(CURL_CHECK_C_SOURCE_COMPILES SOURCE VAR)
+ IF(NOT DEFINED ${VAR} OR ${VAR} MATCHES "UNKNOWN")
+ SET(message "${VAR}")
+ # If the number of arguments is greater than 2 (SOURCE VAR)
+ IF(${ARGC} GREATER 2)
+ # then add the third argument as a message
+ SET(message "${ARGV2} (${VAR})")
+ ENDIF(${ARGC} GREATER 2)
+ SET(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ IF(CMAKE_REQUIRED_LIBRARIES)
+ SET(CURL_CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES
+ "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
+ ELSE(CMAKE_REQUIRED_LIBRARIES)
+ SET(CURL_CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES)
+ ENDIF(CMAKE_REQUIRED_LIBRARIES)
+ IF(CMAKE_REQUIRED_INCLUDES)
+ SET(CURL_CHECK_C_SOURCE_COMPILES_ADD_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ ELSE(CMAKE_REQUIRED_INCLUDES)
+ SET(CURL_CHECK_C_SOURCE_COMPILES_ADD_INCLUDES)
+ ENDIF(CMAKE_REQUIRED_INCLUDES)
+ SET(src "")
+ FOREACH(def ${EXTRA_DEFINES})
+ SET(src "${src}#define ${def} 1\n")
+ ENDFOREACH(def)
+ FOREACH(inc ${HEADER_INCLUDES})
+ SET(src "${src}#include <${inc}>\n")
+ ENDFOREACH(inc)
+
+ SET(src "${src}\nint main() { ${SOURCE} ; return 0; }")
+ SET(CMAKE_CONFIGURABLE_FILE_CONTENT "${src}")
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/CMake/CMakeConfigurableFile.in
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c")
+ MESSAGE(STATUS "Performing Test ${message}")
+ TRY_COMPILE(${VAR}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ "${CURL_CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}"
+ "${CURL_CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+ IF(${VAR})
+ SET(${VAR} 1 CACHE INTERNAL "Test ${message}")
+ MESSAGE(STATUS "Performing Test ${message} - Success")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Performing C SOURCE FILE Test ${message} succeded with the following output:\n"
+ "${OUTPUT}\n"
+ "Source file was:\n${src}\n")
+ ELSE(${VAR})
+ MESSAGE(STATUS "Performing Test ${message} - Failed")
+ SET(${VAR} "" CACHE INTERNAL "Test ${message}")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Performing C SOURCE FILE Test ${message} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Source file was:\n${src}\n")
+ ENDIF(${VAR})
+ ENDIF()
+ENDMACRO(CURL_CHECK_C_SOURCE_COMPILES)
diff --git a/Utilities/cmcurl/CMake/CurlCheckCSourceRuns.cmake b/Utilities/cmcurl/CMake/CurlCheckCSourceRuns.cmake
new file mode 100644
index 0000000000..1bd837a691
--- /dev/null
+++ b/Utilities/cmcurl/CMake/CurlCheckCSourceRuns.cmake
@@ -0,0 +1,82 @@
+# - Check if the source code provided in the SOURCE argument compiles and runs.
+# CURL_CHECK_C_SOURCE_RUNS(SOURCE VAR)
+# - macro which checks if the source code runs
+# SOURCE - source code to try to compile
+# VAR - variable to store size if the type exists.
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+
+MACRO(CURL_CHECK_C_SOURCE_RUNS SOURCE VAR)
+ IF("${VAR}" MATCHES "^${VAR}$" OR "${VAR}" MATCHES "UNKNOWN")
+ SET(message "${VAR}")
+ # If the number of arguments is greater than 2 (SOURCE VAR)
+ IF(${ARGC} GREATER 2)
+ # then add the third argument as a message
+ SET(message "${ARGV2} (${VAR})")
+ ENDIF(${ARGC} GREATER 2)
+ SET(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ IF(CMAKE_REQUIRED_LIBRARIES)
+ SET(CURL_CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES
+ "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
+ ELSE(CMAKE_REQUIRED_LIBRARIES)
+ SET(CURL_CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES)
+ ENDIF(CMAKE_REQUIRED_LIBRARIES)
+ IF(CMAKE_REQUIRED_INCLUDES)
+ SET(CURL_CHECK_C_SOURCE_COMPILES_ADD_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ ELSE(CMAKE_REQUIRED_INCLUDES)
+ SET(CURL_CHECK_C_SOURCE_COMPILES_ADD_INCLUDES)
+ ENDIF(CMAKE_REQUIRED_INCLUDES)
+ SET(src "")
+ FOREACH(def ${EXTRA_DEFINES})
+ SET(src "${src}#define ${def} 1\n")
+ ENDFOREACH(def)
+ FOREACH(inc ${HEADER_INCLUDES})
+ SET(src "${src}#include <${inc}>\n")
+ ENDFOREACH(inc)
+
+ SET(src "${src}\nint main() { ${SOURCE} ; return 0; }")
+ SET(CMAKE_CONFIGURABLE_FILE_CONTENT "${src}")
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/CMake/CMakeConfigurableFile.in
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c")
+ MESSAGE(STATUS "Performing Test ${message}")
+ TRY_RUN(${VAR} ${VAR}_COMPILED
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ "${CURL_CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}"
+ "${CURL_CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+ # if it did not compile make the return value fail code of 1
+ IF(NOT ${VAR}_COMPILED)
+ SET(${VAR} 1)
+ ENDIF(NOT ${VAR}_COMPILED)
+ # if the return value was 0 then it worked
+ SET(result_var ${${VAR}})
+ IF("${result_var}" EQUAL 0)
+ SET(${VAR} 1 CACHE INTERNAL "Test ${message}")
+ MESSAGE(STATUS "Performing Test ${message} - Success")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Performing C SOURCE FILE Test ${message} succeded with the following output:\n"
+ "${OUTPUT}\n"
+ "Return value: ${${VAR}}\n"
+ "Source file was:\n${src}\n")
+ ELSE("${result_var}" EQUAL 0)
+ MESSAGE(STATUS "Performing Test ${message} - Failed")
+ SET(${VAR} "" CACHE INTERNAL "Test ${message}")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Performing C SOURCE FILE Test ${message} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Return value: ${result_var}\n"
+ "Source file was:\n${src}\n")
+ ENDIF("${result_var}" EQUAL 0)
+ ENDIF("${VAR}" MATCHES "^${VAR}$" OR "${VAR}" MATCHES "UNKNOWN")
+ENDMACRO(CURL_CHECK_C_SOURCE_RUNS)
diff --git a/Utilities/cmcurl/CMake/CurlTests.c b/Utilities/cmcurl/CMake/CurlTests.c
new file mode 100644
index 0000000000..c5ba7c28fc
--- /dev/null
+++ b/Utilities/cmcurl/CMake/CurlTests.c
@@ -0,0 +1,526 @@
+#ifdef TIME_WITH_SYS_TIME
+/* Time with sys/time test */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
+
+int
+main ()
+{
+if ((struct tm *) 0)
+return 0;
+ ;
+ return 0;
+}
+
+#endif
+
+#ifdef HAVE_O_NONBLOCK
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int
+main ()
+{
+ /* try to compile O_NONBLOCK */
+
+#if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+# if defined(__SVR4) || defined(__srv4__)
+# define PLATFORM_SOLARIS
+# else
+# define PLATFORM_SUNOS4
+# endif
+#endif
+#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
+# define PLATFORM_AIX_V3
+#endif
+
+#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
+#error "O_NONBLOCK does not work on this platform"
+#endif
+ int socket;
+ int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
+ return 0;
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYADDR_R_5
+#include <sys/types.h>
+#include <netdb.h>
+int
+main ()
+{
+
+char * address;
+int length;
+int type;
+struct hostent h;
+struct hostent_data hdata;
+int rc;
+#ifndef gethostbyaddr_r
+ (void)gethostbyaddr_r;
+#endif
+rc = gethostbyaddr_r(address, length, type, &h, &hdata);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYADDR_R_5_REENTRANT
+#define _REENTRANT
+#include <sys/types.h>
+#include <netdb.h>
+int
+main ()
+{
+
+char * address;
+int length;q
+int type;
+struct hostent h;
+struct hostent_data hdata;
+int rc;
+#ifndef gethostbyaddr_r
+ (void)gethostbyaddr_r;
+#endif
+rc = gethostbyaddr_r(address, length, type, &h, &hdata);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYADDR_R_7
+#include <sys/types.h>
+#include <netdb.h>
+int
+main ()
+{
+
+char * address;
+int length;
+int type;
+struct hostent h;
+char buffer[8192];
+int h_errnop;
+struct hostent * hp;
+
+#ifndef gethostbyaddr_r
+ (void)gethostbyaddr_r;
+#endif
+hp = gethostbyaddr_r(address, length, type, &h,
+ buffer, 8192, &h_errnop);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYADDR_R_7_REENTRANT
+#define _REENTRANT
+#include <sys/types.h>
+#include <netdb.h>
+int
+main ()
+{
+
+char * address;
+int length;
+int type;
+struct hostent h;
+char buffer[8192];
+int h_errnop;
+struct hostent * hp;
+
+#ifndef gethostbyaddr_r
+ (void)gethostbyaddr_r;
+#endif
+hp = gethostbyaddr_r(address, length, type, &h,
+ buffer, 8192, &h_errnop);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYADDR_R_8
+#include <sys/types.h>
+#include <netdb.h>
+int
+main ()
+{
+
+char * address;
+int length;
+int type;
+struct hostent h;
+char buffer[8192];
+int h_errnop;
+struct hostent * hp;
+int rc;
+
+#ifndef gethostbyaddr_r
+ (void)gethostbyaddr_r;
+#endif
+rc = gethostbyaddr_r(address, length, type, &h,
+ buffer, 8192, &hp, &h_errnop);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYADDR_R_8_REENTRANT
+#define _REENTRANT
+#include <sys/types.h>
+#include <netdb.h>
+int
+main ()
+{
+
+char * address;
+int length;
+int type;
+struct hostent h;
+char buffer[8192];
+int h_errnop;
+struct hostent * hp;
+int rc;
+
+#ifndef gethostbyaddr_r
+ (void)gethostbyaddr_r;
+#endif
+rc = gethostbyaddr_r(address, length, type, &h,
+ buffer, 8192, &hp, &h_errnop);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYNAME_R_3
+#include <string.h>
+#include <sys/types.h>
+#include <netdb.h>
+#undef NULL
+#define NULL (void *)0
+
+int
+main ()
+{
+
+struct hostent_data data;
+#ifndef gethostbyname_r
+ (void)gethostbyname_r;
+#endif
+gethostbyname_r(NULL, NULL, NULL);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYNAME_R_3_REENTRANT
+#define _REENTRANT
+#include <string.h>
+#include <sys/types.h>
+#include <netdb.h>
+#undef NULL
+#define NULL (void *)0
+
+int
+main ()
+{
+
+struct hostent_data data;
+#ifndef gethostbyname_r
+ (void)gethostbyname_r;
+#endif
+gethostbyname_r(NULL, NULL, NULL);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYNAME_R_5
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#undef NULL
+#define NULL (void *)0
+
+int
+main ()
+{
+#ifndef gethostbyname_r
+ (void)gethostbyname_r;
+#endif
+gethostbyname_r(NULL, NULL, NULL, 0, NULL);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYNAME_R_5_REENTRANT
+#define _REENTRANT
+#include <sys/types.h>
+#include <netdb.h>
+#undef NULL
+#define NULL (void *)0
+
+int
+main ()
+{
+
+#ifndef gethostbyname_r
+ (void)gethostbyname_r;
+#endif
+gethostbyname_r(NULL, NULL, NULL, 0, NULL);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYNAME_R_6
+#include <sys/types.h>
+#include <netdb.h>
+#undef NULL
+#define NULL (void *)0
+
+int
+main ()
+{
+
+#ifndef gethostbyname_r
+ (void)gethostbyname_r;
+#endif
+gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_GETHOSTBYNAME_R_6_REENTRANT
+#define _REENTRANT
+#include <sys/types.h>
+#include <netdb.h>
+#undef NULL
+#define NULL (void *)0
+
+int
+main ()
+{
+
+#ifndef gethostbyname_r
+ (void)gethostbyname_r;
+#endif
+gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_SOCKLEN_T
+#ifdef _WIN32
+#include <ws2tcpip.h>
+#else
+#include <sys/types.h>
+#include <sys/socket.h>
+#endif
+int
+main ()
+{
+if ((socklen_t *) 0)
+ return 0;
+if (sizeof (socklen_t))
+ return 0;
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_IN_ADDR_T
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+if ((in_addr_t *) 0)
+ return 0;
+if (sizeof (in_addr_t))
+ return 0;
+ ;
+ return 0;
+}
+#endif
+#ifdef STDC_HEADERS
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+int main() { return 0; }
+#endif
+#ifdef RETSIGTYPE_TEST
+#include <sys/types.h>
+#include <signal.h>
+#ifdef signal
+# undef signal
+#endif
+#ifdef __cplusplus
+extern "C" void (*signal (int, void (*)(int)))(int);
+#else
+void (*signal ()) ();
+#endif
+
+int
+main ()
+{
+ return 0;
+}
+#endif
+#ifdef HAVE_INET_NTOA_R_DECL
+#include <arpa/inet.h>
+
+typedef void (*func_type)();
+
+int main()
+{
+#ifndef inet_ntoa_r
+ func_type func;
+ func = (func_type)inet_ntoa_r;
+#endif
+ return 0;
+}
+#endif
+#ifdef HAVE_INET_NTOA_R_DECL_REENTRANT
+#define _REENTRANT
+#include <arpa/inet.h>
+
+typedef void (*func_type)();
+
+int main()
+{
+#ifndef inet_ntoa_r
+ func_type func;
+ func = (func_type)&inet_ntoa_r;
+#endif
+ return 0;
+}
+#endif
+#ifdef HAVE_GETADDRINFO
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int main(void) {
+ struct addrinfo hints, *ai;
+ int error;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+#ifndef getaddrinfo
+ (void)getaddrinfo;
+#endif
+ error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
+ if (error) {
+ return 1;
+ }
+ return 0;
+}
+#endif
+#ifdef HAVE_FILE_OFFSET_BITS
+#ifdef _FILE_OFFSET_BITS
+#undef _FILE_OFFSET_BITS
+#endif
+#define _FILE_OFFSET_BITS 64
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+ We can't simply define LARGE_OFF_T to be 9223372036854775807,
+ since some C++ compilers masquerading as C compilers
+ incorrectly reject 9223372036854775807. */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+ int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+ && LARGE_OFF_T % 2147483647 == 1)
+ ? 1 : -1];
+int main () { ; return 0; }
+#endif
+#ifdef HAVE_IOCTLSOCKET
+#include <windows.h>
+
+int
+main ()
+{
+
+/* ioctlsocket source code */
+ int socket;
+ unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
+
+ ;
+ return 0;
+}
+
+#endif
+#ifdef HAVE_IOCTLSOCKET_CASE
+#include <windows.h>
+
+int
+main ()
+{
+
+/* IoctlSocket source code */
+ int socket;
+ int flags = IoctlSocket(socket, FIONBIO, (long)1);
+
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_FIONBIO
+/* headers for FIONBIO test */
+#include <unistd.h>
+#include <stropts.h>
+
+int
+main ()
+{
+
+/* FIONBIO source test (old-style unix) */
+ int socket;
+ int flags = ioctl(socket, FIONBIO, &flags);
+
+ ;
+ return 0;
+}
+#endif
+#ifdef HAVE_SO_NONBLOCK
+
+/* headers for SO_NONBLOCK test (BeOS) */
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int main()
+{
+/* SO_NONBLOCK source code */
+ long b = 1;
+ int socket;
+ int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
+ return 0;
+}
+#endif
+#ifdef HAVE_GLIBC_STRERROR_R
+#include <string.h>
+#include <errno.h>
+int
+main () {
+ char buffer[1024]; /* big enough to play with */
+ char *string =
+ strerror_r(EACCES, buffer, sizeof(buffer));
+ /* this should've returned a string */
+ if(!string || !string[0])
+ return 99;
+ return 0;
+}
+#endif
+#ifdef HAVE_POSIX_STRERROR_R
+#include <string.h>
+#include <errno.h>
+int
+main () {
+ char buffer[1024]; /* big enough to play with */
+ int error =
+ strerror_r(EACCES, buffer, sizeof(buffer));
+ /* This should've returned zero, and written an error string in the
+ buffer.*/
+ if(!buffer[0] || error)
+ return 99;
+ return 0;
+}
+#endif
diff --git a/Utilities/cmcurl/CMake/OtherTests.cmake b/Utilities/cmcurl/CMake/OtherTests.cmake
new file mode 100644
index 0000000000..7d2c66fa16
--- /dev/null
+++ b/Utilities/cmcurl/CMake/OtherTests.cmake
@@ -0,0 +1,242 @@
+INCLUDE(CurlCheckCSourceCompiles)
+SET(EXTRA_DEFINES "__unused1\n#undef inline\n#define __unused2")
+SET(HEADER_INCLUDES)
+SET(headers_hack)
+
+MACRO(add_header_include check header)
+ IF(${check})
+ SET(headers_hack
+ "${headers_hack}\n#include <${header}>")
+ #SET(HEADER_INCLUDES
+ # ${HEADER_INCLUDES}
+ # "${header}")
+ ENDIF(${check})
+ENDMACRO(add_header_include)
+
+SET(signature_call_conv)
+IF(HAVE_WINDOWS_H)
+ add_header_include(HAVE_WINDOWS_H "windows.h")
+ add_header_include(HAVE_WINSOCK2_H "winsock2.h")
+ add_header_include(HAVE_WINSOCK_H "winsock.h")
+ SET(EXTRA_DEFINES ${EXTRA_DEFINES}
+ "__unused7\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif\n#define __unused3")
+ SET(signature_call_conv "PASCAL")
+ELSE(HAVE_WINDOWS_H)
+ add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
+ add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
+ENDIF(HAVE_WINDOWS_H)
+
+SET(EXTRA_DEFINES_BACKUP "${EXTRA_DEFINES}")
+SET(EXTRA_DEFINES "${EXTRA_DEFINES_BACKUP}\n${headers_hack}\n${extern_line}\n#define __unused5")
+CURL_CHECK_C_SOURCE_COMPILES("recv(0, 0, 0, 0)" curl_cv_recv)
+IF(curl_cv_recv)
+ # AC_CACHE_CHECK([types of arguments and return type for recv],
+ #[curl_cv_func_recv_args], [
+ #SET(curl_cv_func_recv_args "unknown")
+ #for recv_retv in 'int' 'ssize_t'; do
+ IF(NOT DEFINED curl_cv_func_recv_args OR "${curl_cv_func_recv_args}" STREQUAL "unknown")
+ FOREACH(recv_retv "int" "ssize_t" )
+ FOREACH(recv_arg1 "int" "ssize_t" "SOCKET")
+ FOREACH(recv_arg2 "void *" "char *")
+ FOREACH(recv_arg3 "size_t" "int" "socklen_t" "unsigned int")
+ FOREACH(recv_arg4 "int" "unsigned int")
+ IF(NOT curl_cv_func_recv_done)
+ SET(curl_cv_func_recv_test "UNKNOWN")
+ SET(extern_line "extern ${recv_retv} ${signature_call_conv} recv(${recv_arg1}, ${recv_arg2}, ${recv_arg3}, ${recv_arg4})\;")
+ SET(EXTRA_DEFINES "${EXTRA_DEFINES_BACKUP}\n${headers_hack}\n${extern_line}\n#define __unused5")
+ CURL_CHECK_C_SOURCE_COMPILES("
+ ${recv_arg1} s=0;
+ ${recv_arg2} buf=0;
+ ${recv_arg3} len=0;
+ ${recv_arg4} flags=0;
+ ${recv_retv} res = recv(s, buf, len, flags)"
+ curl_cv_func_recv_test
+ "${recv_retv} recv(${recv_arg1}, ${recv_arg2}, ${recv_arg3}, ${recv_arg4})")
+ IF(curl_cv_func_recv_test)
+ SET(curl_cv_func_recv_args
+ "${recv_arg1},${recv_arg2},${recv_arg3},${recv_arg4},${recv_retv}")
+ SET(RECV_TYPE_ARG1 "${recv_arg1}")
+ SET(RECV_TYPE_ARG2 "${recv_arg2}")
+ SET(RECV_TYPE_ARG3 "${recv_arg3}")
+ SET(RECV_TYPE_ARG4 "${recv_arg4}")
+ SET(RECV_TYPE_RETV "${recv_retv}")
+ SET(HAVE_RECV 1)
+ SET(curl_cv_func_recv_done 1)
+ ENDIF(curl_cv_func_recv_test)
+ ENDIF(NOT curl_cv_func_recv_done)
+ ENDFOREACH(recv_arg4)
+ ENDFOREACH(recv_arg3)
+ ENDFOREACH(recv_arg2)
+ ENDFOREACH(recv_arg1)
+ ENDFOREACH(recv_retv)
+ ELSE(NOT DEFINED curl_cv_func_recv_args OR "${curl_cv_func_recv_args}" STREQUAL "unknown")
+ STRING(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG1 "${curl_cv_func_recv_args}")
+ STRING(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG2 "${curl_cv_func_recv_args}")
+ STRING(REGEX REPLACE "^[^,]*,[^,]*,([^,]*),[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG3 "${curl_cv_func_recv_args}")
+ STRING(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,([^,]*),[^,]*$" "\\1" RECV_TYPE_ARG4 "${curl_cv_func_recv_args}")
+ STRING(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" RECV_TYPE_RETV "${curl_cv_func_recv_args}")
+ #MESSAGE("RECV_TYPE_ARG1 ${RECV_TYPE_ARG1}")
+ #MESSAGE("RECV_TYPE_ARG2 ${RECV_TYPE_ARG2}")
+ #MESSAGE("RECV_TYPE_ARG3 ${RECV_TYPE_ARG3}")
+ #MESSAGE("RECV_TYPE_ARG4 ${RECV_TYPE_ARG4}")
+ #MESSAGE("RECV_TYPE_RETV ${RECV_TYPE_RETV}")
+ ENDIF(NOT DEFINED curl_cv_func_recv_args OR "${curl_cv_func_recv_args}" STREQUAL "unknown")
+
+ IF("${curl_cv_func_recv_args}" STREQUAL "unknown")
+ MESSAGE(FATAL_ERROR "Cannot find proper types to use for recv args")
+ ENDIF("${curl_cv_func_recv_args}" STREQUAL "unknown")
+ELSE(curl_cv_recv)
+ MESSAGE(FATAL_ERROR "Unable to link function recv")
+ENDIF(curl_cv_recv)
+SET(curl_cv_func_recv_args "${curl_cv_func_recv_args}" CACHE INTERNAL "Arguments for recv")
+SET(HAVE_RECV 1)
+
+CURL_CHECK_C_SOURCE_COMPILES("send(0, 0, 0, 0)" curl_cv_send)
+IF(curl_cv_send)
+ # AC_CACHE_CHECK([types of arguments and return type for send],
+ #[curl_cv_func_send_args], [
+ #SET(curl_cv_func_send_args "unknown")
+ #for send_retv in 'int' 'ssize_t'; do
+ IF(NOT DEFINED curl_cv_func_send_args OR "${curl_cv_func_send_args}" STREQUAL "unknown")
+ FOREACH(send_retv "int" "ssize_t" )
+ FOREACH(send_arg1 "int" "ssize_t" "SOCKET")
+ FOREACH(send_arg2 "const void *" "void *" "char *" "const char *")
+ FOREACH(send_arg3 "size_t" "int" "socklen_t" "unsigned int")
+ FOREACH(send_arg4 "int" "unsigned int")
+ IF(NOT curl_cv_func_send_done)
+ SET(curl_cv_func_send_test "UNKNOWN")
+ SET(extern_line "extern ${send_retv} ${signature_call_conv} send(${send_arg1}, ${send_arg2}, ${send_arg3}, ${send_arg4})\;")
+ SET(EXTRA_DEFINES "${EXTRA_DEFINES_BACKUP}\n${headers_hack}\n${extern_line}\n#define __unused5")
+ CURL_CHECK_C_SOURCE_COMPILES("
+ ${send_arg1} s=0;
+ ${send_arg2} buf=0;
+ ${send_arg3} len=0;
+ ${send_arg4} flags=0;
+ ${send_retv} res = send(s, buf, len, flags)"
+ curl_cv_func_send_test
+ "${send_retv} send(${send_arg1}, ${send_arg2}, ${send_arg3}, ${send_arg4})")
+ IF(curl_cv_func_send_test)
+ #MESSAGE("Found arguments: ${curl_cv_func_send_test}")
+ STRING(REGEX REPLACE "(const) .*" "\\1" send_qual_arg2 "${send_arg2}")
+ STRING(REGEX REPLACE "const (.*)" "\\1" send_arg2 "${send_arg2}")
+ SET(curl_cv_func_send_args
+ "${send_arg1},${send_arg2},${send_arg3},${send_arg4},${send_retv},${send_qual_arg2}")
+ SET(SEND_TYPE_ARG1 "${send_arg1}")
+ SET(SEND_TYPE_ARG2 "${send_arg2}")
+ SET(SEND_TYPE_ARG3 "${send_arg3}")
+ SET(SEND_TYPE_ARG4 "${send_arg4}")
+ SET(SEND_TYPE_RETV "${send_retv}")
+ SET(HAVE_SEND 1)
+ SET(curl_cv_func_send_done 1)
+ ENDIF(curl_cv_func_send_test)
+ ENDIF(NOT curl_cv_func_send_done)
+ ENDFOREACH(send_arg4)
+ ENDFOREACH(send_arg3)
+ ENDFOREACH(send_arg2)
+ ENDFOREACH(send_arg1)
+ ENDFOREACH(send_retv)
+ ELSE(NOT DEFINED curl_cv_func_send_args OR "${curl_cv_func_send_args}" STREQUAL "unknown")
+ STRING(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG1 "${curl_cv_func_send_args}")
+ STRING(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG2 "${curl_cv_func_send_args}")
+ STRING(REGEX REPLACE "^[^,]*,[^,]*,([^,]*),[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG3 "${curl_cv_func_send_args}")
+ STRING(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,([^,]*),[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG4 "${curl_cv_func_send_args}")
+ STRING(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*),[^,]*$" "\\1" SEND_TYPE_RETV "${curl_cv_func_send_args}")
+ STRING(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" SEND_QUAL_ARG2 "${curl_cv_func_send_args}")
+ #MESSAGE("SEND_TYPE_ARG1 ${SEND_TYPE_ARG1}")
+ #MESSAGE("SEND_TYPE_ARG2 ${SEND_TYPE_ARG2}")
+ #MESSAGE("SEND_TYPE_ARG3 ${SEND_TYPE_ARG3}")
+ #MESSAGE("SEND_TYPE_ARG4 ${SEND_TYPE_ARG4}")
+ #MESSAGE("SEND_TYPE_RETV ${SEND_TYPE_RETV}")
+ #MESSAGE("SEND_QUAL_ARG2 ${SEND_QUAL_ARG2}")
+ ENDIF(NOT DEFINED curl_cv_func_send_args OR "${curl_cv_func_send_args}" STREQUAL "unknown")
+
+ IF("${curl_cv_func_send_args}" STREQUAL "unknown")
+ MESSAGE(FATAL_ERROR "Cannot find proper types to use for send args")
+ ENDIF("${curl_cv_func_send_args}" STREQUAL "unknown")
+ SET(SEND_QUAL_ARG2 "const")
+ELSE(curl_cv_send)
+ MESSAGE(FATAL_ERROR "Unable to link function send")
+ENDIF(curl_cv_send)
+SET(curl_cv_func_send_args "${curl_cv_func_send_args}" CACHE INTERNAL "Arguments for send")
+SET(HAVE_SEND 1)
+
+SET(EXTRA_DEFINES "${EXTRA_DEFINES}\n${headers_hack}\n#define __unused5")
+CURL_CHECK_C_SOURCE_COMPILES("int flag = MSG_NOSIGNAL" HAVE_MSG_NOSIGNAL)
+
+SET(EXTRA_DEFINES "__unused1\n#undef inline\n#define __unused2")
+SET(HEADER_INCLUDES)
+SET(headers_hack)
+
+MACRO(add_header_include check header)
+ IF(${check})
+ SET(headers_hack
+ "${headers_hack}\n#include <${header}>")
+ #SET(HEADER_INCLUDES
+ # ${HEADER_INCLUDES}
+ # "${header}")
+ ENDIF(${check})
+ENDMACRO(add_header_include header)
+
+IF(HAVE_WINDOWS_H)
+ SET(EXTRA_DEFINES ${EXTRA_DEFINES}
+ "__unused7\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif\n#define __unused3")
+ add_header_include(HAVE_WINDOWS_H "windows.h")
+ add_header_include(HAVE_WINSOCK2_H "winsock2.h")
+ add_header_include(HAVE_WINSOCK_H "winsock.h")
+ELSE(HAVE_WINDOWS_H)
+ add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
+ add_header_include(HAVE_SYS_TIME_H "sys/time.h")
+ add_header_include(TIME_WITH_SYS_TIME "time.h")
+ add_header_include(HAVE_TIME_H "time.h")
+ENDIF(HAVE_WINDOWS_H)
+SET(EXTRA_DEFINES "${EXTRA_DEFINES}\n${headers_hack}\n#define __unused5")
+CURL_CHECK_C_SOURCE_COMPILES("struct timeval ts;\nts.tv_sec = 0;\nts.tv_usec = 0" HAVE_STRUCT_TIMEVAL)
+
+
+SET(HAVE_SIG_ATOMIC_T 1)
+SET(EXTRA_DEFINES)
+SET(HEADER_INCLUDES)
+IF(HAVE_SIGNAL_H)
+ SET(HEADER_INCLUDES "signal.h")
+ SET(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
+ENDIF(HAVE_SIGNAL_H)
+CHECK_TYPE_SIZE("sig_atomic_t" SIZEOF_SIG_ATOMIC_T)
+IF(HAVE_SIZEOF_SIG_ATOMIC_T)
+ CURL_CHECK_C_SOURCE_COMPILES("static volatile sig_atomic_t dummy = 0" HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
+ IF(NOT HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
+ SET(HAVE_SIG_ATOMIC_T_VOLATILE 1)
+ ENDIF(NOT HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
+ENDIF(HAVE_SIZEOF_SIG_ATOMIC_T)
+
+SET(CHECK_TYPE_SIZE_PREINCLUDE
+ "#undef inline")
+
+IF(HAVE_WINDOWS_H)
+ SET(CHECK_TYPE_SIZE_PREINCLUDE "${CHECK_TYPE_SIZE_PREINCLUDE}
+ #ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN
+ #endif
+ #include <windows.h>")
+ IF(HAVE_WINSOCK2_H)
+ SET(CHECK_TYPE_SIZE_PREINCLUDE "${CHECK_TYPE_SIZE_PREINCLUDE}\n#include <winsock2.h>")
+ ENDIF(HAVE_WINSOCK2_H)
+ELSE(HAVE_WINDOWS_H)
+ IF(HAVE_SYS_SOCKET_H)
+ SET(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES}
+ "sys/socket.h")
+ ENDIF(HAVE_SYS_SOCKET_H)
+ IF(HAVE_NETINET_IN_H)
+ SET(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES}
+ "netinet/in.h")
+ ENDIF(HAVE_NETINET_IN_H)
+ IF(HAVE_ARPA_INET_H)
+ SET(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES}
+ "arpa/inet.h")
+ ENDIF(HAVE_ARPA_INET_H)
+ENDIF(HAVE_WINDOWS_H)
+
+CHECK_TYPE_SIZE("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
+IF(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
+ SET(HAVE_STRUCT_SOCKADDR_STORAGE 1)
+ENDIF(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
+
diff --git a/Utilities/cmcurl/CMakeLists.txt b/Utilities/cmcurl/CMakeLists.txt
new file mode 100644
index 0000000000..03f10a0c93
--- /dev/null
+++ b/Utilities/cmcurl/CMakeLists.txt
@@ -0,0 +1,740 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR)
+IF(POLICY CMP0025)
+ CMAKE_POLICY(SET CMP0025 NEW)
+ENDIF()
+PROJECT(LIBCURL C)
+
+# Setup package meta-data
+SET(PACKAGE "curl")
+SET(VERSION "7.16.1")
+SET(PACKAGE_TARNAME "curl")
+SET(PACKAGE_BUGREPORT " ")
+SET(PACKAGE_NAME "curl")
+SET(PACKAGE_VERSION "-")
+SET(PACKAGE_STRING "curl-")
+SET(PACKAGE_BUGREPORT "a suitable curl mailing list => http://curl.haxx.se/mail/")
+SET(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
+
+# We need ansi c-flags, especially on HP
+SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
+SET(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
+
+# Disable warnings on Borland to avoid changing 3rd party code.
+IF(BORLAND)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
+ENDIF(BORLAND)
+
+# If we are on AIX, do the _ALL_SOURCE magic
+IF(${CMAKE_SYSTEM_NAME} MATCHES AIX)
+ SET(_ALL_SOURCE 1)
+ENDIF(${CMAKE_SYSTEM_NAME} MATCHES AIX)
+
+# Include all the necessary files for macros
+SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
+INCLUDE (CheckFunctionExists)
+INCLUDE (CheckIncludeFile)
+INCLUDE (CheckIncludeFiles)
+INCLUDE (CheckLibraryExists)
+INCLUDE (CheckSymbolExists)
+INCLUDE (CheckTypeSize)
+
+SET(libCurl_SRCS
+ # amigaos.c - does not build on AmigaOS
+ base64.c
+ connect.c
+ content_encoding.c
+ cookie.c
+ dict.c
+ easy.c
+ escape.c
+ file.c
+ formdata.c
+ ftp.c
+ getenv.c
+ getinfo.c
+ gtls.c
+ hash.c
+ hostares.c
+ hostasyn.c
+ hostip4.c
+ hostip6.c
+ hostip.c
+ hostsyn.c
+ hostthre.c
+ http.c
+ http_chunks.c
+ http_digest.c
+ http_negotiate.c
+ http_ntlm.c
+ if2ip.c
+ inet_ntop.c
+ inet_pton.c
+ krb4.c
+ ldap.c
+ llist.c
+ md5.c
+# memdebug.c -not used
+ mprintf.c
+ multi.c
+ netrc.c
+ # nwlib.c - Not used
+ parsedate.c
+ progress.c
+ security.c
+ select.c
+ sendf.c
+ share.c
+ socks.c
+ speedcheck.c
+ splay.c
+ ssh.c
+ sslgen.c
+ ssluse.c
+ strdup.c
+ strequal.c
+ strerror.c
+ # strtok.c - specify later
+ # strtoofft.c - specify later
+ telnet.c
+ tftp.c
+ timeval.c
+ transfer.c
+ url.c
+ version.c
+ )
+
+SET(CURL_DISABLE_LDAP 1)
+IF(NOT CURL_DISABLE_LDAP)
+ SET(libCurl_SRCS
+ ${libCurl_SRCS}
+ ldap.c
+ )
+ENDIF(NOT CURL_DISABLE_LDAP)
+
+# if we have Kerberos 4, right now this is never on
+#OPTION(CURL_KRB4 "Use Kerberos 4" OFF)
+IF(CURL_KRB4)
+ SET(libCurl_SRCS ${libCurl_SRCS}
+ krb4.c
+ security.c
+ )
+ENDIF(CURL_KRB4)
+
+#OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
+MARK_AS_ADVANCED(CURL_MALLOC_DEBUG)
+IF(CURL_MALLOC_DEBUG)
+ SET(libCurl_SRCS ${libCurl_SRCS}
+ memdebug.c
+ )
+ENDIF(CURL_MALLOC_DEBUG)
+
+# On windows preload settings
+IF(WIN32 AND NOT MINGW)
+ INCLUDE(${LIBCURL_SOURCE_DIR}/Platforms/WindowsCache.cmake)
+ENDIF()
+
+# This macro checks if the symbol exists in the library and if it
+# does, it appends library to the list.
+SET(CURL_LIBS "")
+MACRO(CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE)
+ CHECK_LIBRARY_EXISTS("${LIBRARY};${CURL_LIBS}" ${SYMBOL} ""
+ ${VARIABLE})
+ IF(${VARIABLE})
+ SET(CURL_LIBS ${CURL_LIBS} ${LIBRARY})
+ ENDIF(${VARIABLE})
+ENDMACRO(CHECK_LIBRARY_EXISTS_CONCAT)
+
+# Check for all needed libraries
+# use the cmake defined dl libs as dl is should not be used
+# on HPUX, but rather dld this avoids a warning
+SET(CURL_LIBS ${CURL_LIBS} ${CMAKE_DL_LIBS})
+#CHECK_LIBRARY_EXISTS_CONCAT("dl" dlopen HAVE_LIBDL)
+#CHECK_LIBRARY_EXISTS_CONCAT("ucb" gethostname HAVE_LIBUCB)
+CHECK_LIBRARY_EXISTS_CONCAT("socket" connect HAVE_LIBSOCKET)
+CHECK_LIBRARY_EXISTS("c" gethostbyname "" NOT_NEED_LIBNSL)
+
+# Yellowtab Zeta needs different libraries than BeOS 5.
+IF(BEOS)
+ SET(NOT_NEED_LIBNSL 1)
+ CHECK_LIBRARY_EXISTS_CONCAT("bind" gethostbyname HAVE_LIBBIND)
+ CHECK_LIBRARY_EXISTS_CONCAT("bnetapi" closesocket HAVE_LIBBNETAPI)
+ENDIF(BEOS)
+
+CHECK_LIBRARY_EXISTS_CONCAT("network" recv HAVE_LIBNETWORK)
+
+IF(NOT NOT_NEED_LIBNSL)
+ CHECK_LIBRARY_EXISTS_CONCAT("nsl" gethostbyname HAVE_LIBNSL)
+ENDIF(NOT NOT_NEED_LIBNSL)
+
+CHECK_LIBRARY_EXISTS_CONCAT("ws2_32" getch HAVE_LIBWS2_32)
+CHECK_LIBRARY_EXISTS_CONCAT("winmm" getch HAVE_LIBWINMM)
+IF(NOT CURL_SPECIAL_LIBZ)
+ CHECK_LIBRARY_EXISTS_CONCAT("z" inflateEnd HAVE_LIBZ)
+ENDIF(NOT CURL_SPECIAL_LIBZ)
+
+# Include the local directories before any others so that we do not end up
+# including system curl's include directory first by mistake.
+INCLUDE_DIRECTORIES(${LIBCURL_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${LIBCURL_BINARY_DIR})
+
+OPTION(CMAKE_USE_OPENSSL "Use OpenSSL code with curl." OFF)
+MARK_AS_ADVANCED(CMAKE_USE_OPENSSL)
+IF(CMAKE_USE_OPENSSL)
+ SET(USE_SSLEAY TRUE)
+ SET(USE_OPENSSL TRUE)
+ FIND_PACKAGE(OpenSSL REQUIRED)
+ INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+ SET(CURL_LIBS ${CURL_LIBS} ${OPENSSL_LIBRARIES})
+ SET(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
+ MARK_AS_ADVANCED(CURL_CA_BUNDLE)
+ IF(CURL_CA_BUNDLE)
+ ADD_DEFINITIONS(-DCURL_CA_BUNDLE="${CURL_CA_BUNDLE}")
+ ENDIF(CURL_CA_BUNDLE)
+ # for windows we want to install OPENSSL_LIBRARIES dlls
+ # and also copy them into the build tree so that testing
+ # can find them.
+ IF(WIN32)
+ FIND_FILE(CMAKE_EAY_DLL NAME libeay32.dll HINTS ${OPENSSL_INCLUDE_DIR}/..)
+ FIND_FILE(CMAKE_SSL_DLL NAME ssleay32.dll HINTS ${OPENSSL_INCLUDE_DIR}/..)
+ MARK_AS_ADVANCED(CMAKE_EAY_DLL CMAKE_SSL_DLL)
+ IF(CMAKE_SSL_DLL AND CMAKE_EAY_DLL)
+ SET(CMAKE_CURL_SSL_DLLS ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/libeay32.dll
+ ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/ssleay32.dll)
+ ADD_CUSTOM_COMMAND(OUTPUT
+ ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/libeay32.dll
+ DEPENDS ${CMAKE_EAY_DLL}
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_EAY_DLL}
+ ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/libeay32.dll)
+ ADD_CUSTOM_COMMAND(OUTPUT
+ ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/ssleay32.dll
+ DEPENDS ${CMAKE_SSL_DLL}
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SSL_DLL}
+ ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/ssleay32.dll)
+ INSTALL(PROGRAMS ${CMAKE_EAY_DLL} ${CMAKE_SSL_DLL} DESTINATION bin)
+ ENDIF()
+ ENDIF()
+ENDIF(CMAKE_USE_OPENSSL)
+
+# Check for idn
+CHECK_LIBRARY_EXISTS_CONCAT("idn" idna_to_ascii_lz HAVE_LIBIDN)
+
+# Check for symbol dlopen (same as HAVE_LIBDL)
+CHECK_LIBRARY_EXISTS("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
+
+# For other tests to use the same libraries
+SET(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBS})
+
+IF(CURL_SPECIAL_LIBZ)
+ SET(CURL_LIBS ${CURL_LIBS} "${CURL_SPECIAL_LIBZ}")
+ INCLUDE_DIRECTORIES(${CURL_SPECIAL_LIBZ_INCLUDES})
+ SET(HAVE_LIBZ 0)
+ SET(HAVE_ZLIB_H 0)
+ENDIF(CURL_SPECIAL_LIBZ)
+
+# do we have process.h
+CHECK_INCLUDE_FILE("process.h" HAVE_PROCESS_H)
+
+# If we have features.h, then do the _BSD_SOURCE magic
+CHECK_INCLUDE_FILE("features.h" HAVE_FEATURES_H)
+IF(HAVE_FEATURES_H)
+ SET_SOURCE_FILES_PROPERTIES(
+ cookie.c
+ easy.c
+ formdata.c
+ getenv.c
+ hash.c
+ http.c
+ if2ip.c
+ mprintf.c
+ multi.c
+ sendf.c
+ telnet.c
+ transfer.c
+ url.c
+ COMPILE_FLAGS -D_BSD_SOURCE)
+ENDIF(HAVE_FEATURES_H)
+
+# Check if header file exists and add it to the list.
+MACRO(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
+ CHECK_INCLUDE_FILES("${CURL_INCLUDES};${FILE}" ${VARIABLE})
+ IF(${VARIABLE})
+ SET(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
+ ENDIF(${VARIABLE})
+ENDMACRO(CHECK_INCLUDE_FILE_CONCAT)
+
+# Check for header files
+IF(UNIX)
+ SET(HAVE_WINDOWS_H 0)
+ SET(HAVE_WINSOCK_H 0)
+ SET(HAVE_WS2TCPIP_H 0)
+ SET(HAVE_WINSOCK2_H 0)
+ENDIF(UNIX)
+IF(NOT UNIX)
+ CHECK_INCLUDE_FILE_CONCAT("ws2tcpip.h" HAVE_WS2TCPIP_H)
+ CHECK_INCLUDE_FILE_CONCAT("winsock2.h" HAVE_WINSOCK2_H)
+ENDIF(NOT UNIX)
+CHECK_INCLUDE_FILE_CONCAT("stdio.h" HAVE_STDIO_H)
+IF(NOT UNIX)
+ CHECK_INCLUDE_FILE_CONCAT("windows.h" HAVE_WINDOWS_H)
+ CHECK_INCLUDE_FILE_CONCAT("winsock.h" HAVE_WINSOCK_H)
+ENDIF(NOT UNIX)
+CHECK_INCLUDE_FILE_CONCAT("stddef.h" HAVE_STDDEF_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/types.h" HAVE_SYS_TYPES_H)
+CHECK_INCLUDE_FILE_CONCAT("inttypes.h" HAVE_INTTYPES_H)
+CHECK_INCLUDE_FILE_CONCAT("alloca.h" HAVE_ALLOCA_H)
+CHECK_INCLUDE_FILE_CONCAT("arpa/inet.h" HAVE_ARPA_INET_H)
+CHECK_INCLUDE_FILE_CONCAT("dlfcn.h" HAVE_DLFCN_H)
+CHECK_INCLUDE_FILE_CONCAT("fcntl.h" HAVE_FCNTL_H)
+CHECK_INCLUDE_FILE_CONCAT("malloc.h" HAVE_MALLOC_H)
+CHECK_INCLUDE_FILE_CONCAT("memory.h" HAVE_MEMORY_H)
+CHECK_INCLUDE_FILE_CONCAT("netdb.h" HAVE_NETDB_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/poll.h" HAVE_SYS_POLL_H)
+CHECK_INCLUDE_FILE_CONCAT("assert.h" HAVE_ASSERT_H)
+CHECK_INCLUDE_FILE_CONCAT("limits.h" HAVE_LIMITS_H)
+
+IF(CMAKE_USE_OPENSSL)
+ CHECK_INCLUDE_FILE_CONCAT("openssl/x509.h" HAVE_OPENSSL_X509_H)
+ CHECK_INCLUDE_FILE_CONCAT("openssl/engine.h" HAVE_OPENSSL_ENGINE_H)
+ CHECK_INCLUDE_FILE_CONCAT("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
+ CHECK_INCLUDE_FILE_CONCAT("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
+ CHECK_INCLUDE_FILE_CONCAT("openssl/pem.h" HAVE_OPENSSL_PEM_H)
+ CHECK_INCLUDE_FILE_CONCAT("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
+ CHECK_INCLUDE_FILE_CONCAT("openssl/err.h" HAVE_OPENSSL_ERR_H)
+ CHECK_INCLUDE_FILE_CONCAT("openssl/rand.h" HAVE_OPENSSL_RAND_H)
+ CHECK_INCLUDE_FILE_CONCAT("openssl/pkcs12.h" HAVE_OPENSSL_PKCS12_H)
+ENDIF(CMAKE_USE_OPENSSL)
+
+IF(NOT CURL_SPECIAL_LIBZ)
+ CHECK_INCLUDE_FILE_CONCAT("zlib.h" HAVE_ZLIB_H)
+ENDIF(NOT CURL_SPECIAL_LIBZ)
+CHECK_INCLUDE_FILE_CONCAT("sys/socket.h" HAVE_SYS_SOCKET_H)
+CHECK_INCLUDE_FILE_CONCAT("netinet/in.h" HAVE_NETINET_IN_H)
+CHECK_INCLUDE_FILE_CONCAT("net/if.h" HAVE_NET_IF_H)
+CHECK_INCLUDE_FILE_CONCAT("netinet/if_ether.h"
+ HAVE_NETINET_IF_ETHER_H)
+CHECK_INCLUDE_FILE_CONCAT("netinet/tcp.h"
+ HAVE_NETINET_TCP_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/select.h" HAVE_SYS_SELECT_H)
+CHECK_INCLUDE_FILE_CONCAT("utime.h" HAVE_UTIME_H)
+CHECK_INCLUDE_FILE_CONCAT("netinet/in.h" HAVE_NETINET_IN_H)
+CHECK_INCLUDE_FILE_CONCAT("pwd.h" HAVE_PWD_H)
+CHECK_INCLUDE_FILE_CONCAT("sgtty.h" HAVE_SGTTY_H)
+CHECK_INCLUDE_FILE_CONCAT("stdint.h" HAVE_STDINT_H)
+CHECK_INCLUDE_FILE_CONCAT("stdlib.h" HAVE_STDLIB_H)
+CHECK_INCLUDE_FILE_CONCAT("string.h" HAVE_STRING_H)
+CHECK_INCLUDE_FILE_CONCAT("strings.h" HAVE_STRINGS_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/param.h" HAVE_SYS_PARAM_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/stat.h" HAVE_SYS_STAT_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/time.h" HAVE_SYS_TIME_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/resource.h" HAVE_SYS_RESOURCE_H)
+CHECK_INCLUDE_FILE_CONCAT("termios.h" HAVE_TERMIOS_H)
+CHECK_INCLUDE_FILE_CONCAT("termio.h" HAVE_TERMIO_H)
+CHECK_INCLUDE_FILE_CONCAT("io.h" HAVE_IO_H)
+CHECK_INCLUDE_FILE_CONCAT("time.h" HAVE_TIME_H)
+CHECK_INCLUDE_FILE_CONCAT("unistd.h" HAVE_UNISTD_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/utime.h" HAVE_SYS_UTIME_H)
+CHECK_INCLUDE_FILE_CONCAT("sockio.h" HAVE_SOCKIO_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/sockio.h" HAVE_SYS_SOCKIO_H)
+CHECK_INCLUDE_FILE_CONCAT("x509.h" HAVE_X509_H)
+CHECK_INCLUDE_FILE_CONCAT("locale.h" HAVE_LOCALE_H)
+CHECK_INCLUDE_FILE_CONCAT("setjmp.h" HAVE_SETJMP_H)
+CHECK_INCLUDE_FILE_CONCAT("signal.h" HAVE_SIGNAL_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/ioctl.h" HAVE_SYS_IOCTL_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/utsname.h" HAVE_SYS_UTSNAME_H)
+CHECK_INCLUDE_FILE_CONCAT("idn-free.h" HAVE_IDN_FREE_H)
+CHECK_INCLUDE_FILE_CONCAT("idna.h" HAVE_IDNA_H)
+CHECK_INCLUDE_FILE_CONCAT("tld.h" HAVE_TLD_H)
+CHECK_INCLUDE_FILE_CONCAT("arpa/tftp.h" HAVE_ARPA_TFTP_H)
+CHECK_INCLUDE_FILE_CONCAT("errno.h" HAVE_ERRNO_H)
+CHECK_INCLUDE_FILE_CONCAT("libgen.h" HAVE_LIBGEN_H)
+CHECK_INCLUDE_FILE_CONCAT("sys/filio.h" HAVE_SYS_FILIO_H)
+CHECK_TYPE_SIZE(size_t SIZEOF_SIZE_T)
+CHECK_TYPE_SIZE(ssize_t SIZEOF_SSIZE_T)
+CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
+CHECK_TYPE_SIZE("long" SIZEOF_LONG)
+CHECK_TYPE_SIZE("__int64" SIZEOF___INT64)
+CHECK_TYPE_SIZE("time_t" SIZEOF_TIME_T)
+
+IF(HAVE_SIZEOF_LONG_LONG)
+ SET(HAVE_LONGLONG 1)
+ SET(HAVE_LL 1)
+ENDIF(HAVE_SIZEOF_LONG_LONG)
+
+FIND_FILE(RANDOM_FILE urandom /dev)
+MARK_AS_ADVANCED(RANDOM_FILE)
+
+#strtoll \
+#socket \
+#select \
+#strdup \
+#strstr \
+#strtok_r \
+#uname \
+#strcasecmp \
+#stricmp \
+#strcmpi \
+#gethostbyaddr \
+#gettimeofday \
+#inet_addr \
+#inet_ntoa \
+#inet_pton \
+#perror \
+#closesocket \
+#siginterrupt \
+#sigaction \
+#signal \
+#getpass_r \
+#getpwuid \
+#geteuid \
+#dlopen \
+#utime \
+#sigsetjmp \
+#basename \
+#setlocale \
+#ftruncate \
+#pipe \
+#poll \
+#getprotobyname \
+#getrlimit \
+#setrlimit \
+#fork
+
+# Check for some functions that are used
+CHECK_SYMBOL_EXISTS(basename "${CURL_INCLUDES}" HAVE_BASENAME)
+CHECK_SYMBOL_EXISTS(socket "${CURL_INCLUDES}" HAVE_SOCKET)
+CHECK_SYMBOL_EXISTS(poll "${CURL_INCLUDES}" HAVE_POLL)
+CHECK_SYMBOL_EXISTS(select "${CURL_INCLUDES}" HAVE_SELECT)
+CHECK_SYMBOL_EXISTS(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
+CHECK_SYMBOL_EXISTS(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
+CHECK_SYMBOL_EXISTS(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
+CHECK_SYMBOL_EXISTS(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
+CHECK_SYMBOL_EXISTS(uname "${CURL_INCLUDES}" HAVE_UNAME)
+CHECK_SYMBOL_EXISTS(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
+CHECK_SYMBOL_EXISTS(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
+CHECK_SYMBOL_EXISTS(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
+CHECK_SYMBOL_EXISTS(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
+CHECK_SYMBOL_EXISTS(basename "${CURL_INCLUDES}" HAVE_BASENAME)
+IF(NOT HAVE_STRNCMPI)
+ SET(HAVE_STRCMPI)
+ENDIF(NOT HAVE_STRNCMPI)
+CHECK_SYMBOL_EXISTS(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
+CHECK_SYMBOL_EXISTS(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
+CHECK_SYMBOL_EXISTS(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
+# windows only has this for vista, but will link with it and say
+# that it has it at link time! So, force it off
+IF(WIN32)
+ SET(HAVE_INET_PTON 0 CACHE "" INTERNAL )
+ENDIF(WIN32)
+CHECK_SYMBOL_EXISTS(inet_pton "${CURL_INCLUDES}" HAVE_INET_PTON)
+CHECK_SYMBOL_EXISTS(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
+CHECK_SYMBOL_EXISTS(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
+CHECK_SYMBOL_EXISTS(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
+CHECK_SYMBOL_EXISTS(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
+CHECK_SYMBOL_EXISTS(perror "${CURL_INCLUDES}" HAVE_PERROR)
+CHECK_SYMBOL_EXISTS(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
+CHECK_SYMBOL_EXISTS(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
+CHECK_SYMBOL_EXISTS(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
+CHECK_SYMBOL_EXISTS(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
+CHECK_SYMBOL_EXISTS(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
+CHECK_SYMBOL_EXISTS(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
+CHECK_SYMBOL_EXISTS(utime "${CURL_INCLUDES}" HAVE_UTIME)
+IF(CMAKE_USE_OPENSSL)
+ CHECK_SYMBOL_EXISTS(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
+ CHECK_SYMBOL_EXISTS(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
+ CHECK_SYMBOL_EXISTS(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
+ CHECK_SYMBOL_EXISTS(CRYPTO_cleanup_all_ex_data "${CURL_INCLUDES}"
+ HAVE_CRYPTO_CLEANUP_ALL_EX_DATA)
+ENDIF(CMAKE_USE_OPENSSL)
+CHECK_SYMBOL_EXISTS(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
+CHECK_SYMBOL_EXISTS(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
+
+CHECK_SYMBOL_EXISTS(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
+CHECK_SYMBOL_EXISTS(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
+CHECK_SYMBOL_EXISTS(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
+
+CHECK_SYMBOL_EXISTS(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
+CHECK_SYMBOL_EXISTS(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
+IF(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
+ SET(HAVE_SIGNAL 1)
+ENDIF(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
+CHECK_SYMBOL_EXISTS(uname "${CURL_INCLUDES}" HAVE_UNAME)
+CHECK_SYMBOL_EXISTS(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
+CHECK_SYMBOL_EXISTS(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
+CHECK_SYMBOL_EXISTS(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
+CHECK_SYMBOL_EXISTS(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
+CHECK_SYMBOL_EXISTS(perror "${CURL_INCLUDES}" HAVE_PERROR)
+CHECK_SYMBOL_EXISTS(fork "${CURL_INCLUDES}" HAVE_FORK)
+CHECK_SYMBOL_EXISTS(pipe "${CURL_INCLUDES}" HAVE_PIPE)
+CHECK_SYMBOL_EXISTS(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
+CHECK_SYMBOL_EXISTS(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
+CHECK_SYMBOL_EXISTS(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
+CHECK_SYMBOL_EXISTS(idn_free "${CURL_INCLUDES}" HAVE_IDN_FREE)
+CHECK_SYMBOL_EXISTS(idna_strerror "${CURL_INCLUDES}" HAVE_IDNA_STRERROR)
+CHECK_SYMBOL_EXISTS(tld_strerror "${CURL_INCLUDES}" HAVE_TLD_STRERROR)
+CHECK_SYMBOL_EXISTS(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
+CHECK_SYMBOL_EXISTS(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
+
+# only build compat strtok if we need to
+IF (NOT HAVE_STRTOK_R)
+ SET(libCurl_SRCS ${libCurl_SRCS}
+ strtok.c
+ )
+ENDIF (NOT HAVE_STRTOK_R)
+
+# only build compat strtoofft if we need to
+IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
+ SET(libCurl_SRCS ${libCurl_SRCS}
+ strtoofft.c
+ )
+ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
+
+# sigaction and sigsetjmp are special. Use special mechanism for
+# detecting those, but only if previous attempt failed.
+IF(HAVE_SIGNAL_H)
+ CHECK_SYMBOL_EXISTS(sigaction "signal.h" HAVE_SIGACTION)
+ENDIF(HAVE_SIGNAL_H)
+
+IF(NOT HAVE_SIGSETJMP)
+ IF(HAVE_SETJMP_H)
+ CHECK_SYMBOL_EXISTS(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
+ IF(HAVE_MACRO_SIGSETJMP)
+ SET(HAVE_SIGSETJMP 1)
+ ENDIF(HAVE_MACRO_SIGSETJMP)
+ ENDIF(HAVE_SETJMP_H)
+ENDIF(NOT HAVE_SIGSETJMP)
+
+# For other curl specific tests, use this macro.
+MACRO(CURL_INTERNAL_TEST CURL_TEST)
+ IF(NOT DEFINED ${CURL_TEST})
+ SET(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-D${CURL_TEST} ${CMAKE_REQUIRED_FLAGS}")
+ IF(CMAKE_REQUIRED_LIBRARIES)
+ SET(CURL_TEST_ADD_LIBRARIES
+ "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
+ ENDIF(CMAKE_REQUIRED_LIBRARIES)
+
+ MESSAGE(STATUS "Performing Curl Test ${CURL_TEST}")
+ TRY_COMPILE(${CURL_TEST}
+ ${CMAKE_BINARY_DIR}
+ ${LIBCURL_SOURCE_DIR}/CMake/CurlTests.c
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ "${CURL_TEST_ADD_LIBRARIES}"
+ OUTPUT_VARIABLE OUTPUT)
+ IF(${CURL_TEST})
+ SET(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
+ MESSAGE(STATUS "Performing Curl Test ${CURL_TEST} - Success")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Performing Curl Test ${CURL_TEST} passed with the following output:\n"
+ "${OUTPUT}\n")
+ ELSE(${CURL_TEST})
+ MESSAGE(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
+ SET(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
+ "${OUTPUT}\n")
+ ENDIF(${CURL_TEST})
+ ENDIF()
+ENDMACRO(CURL_INTERNAL_TEST)
+
+# Do curl specific tests
+#OPTION(CURL_HAVE_DISABLED_NONBLOCKING "Disable non-blocking socket detection" OFF)
+SET(CURL_NONBLOCKING_TESTS)
+IF(NOT CURL_HAVE_DISABLED_NONBLOCKING)
+ SET(CURL_NONBLOCKING_TESTS
+ HAVE_FIONBIO
+ HAVE_IOCTLSOCKET
+ HAVE_IOCTLSOCKET_CASE
+ HAVE_O_NONBLOCK
+ HAVE_SO_NONBLOCK
+ )
+ENDIF(NOT CURL_HAVE_DISABLED_NONBLOCKING)
+FOREACH(CURL_TEST
+ ${CURL_NONBLOCKING_TESTS}
+ TIME_WITH_SYS_TIME
+ HAVE_O_NONBLOCKHAVE_GETHOSTBYADDR_R_5
+ HAVE_GETHOSTBYADDR_R_7
+ HAVE_GETHOSTBYADDR_R_8
+ HAVE_GETHOSTBYADDR_R_5_REENTRANT
+ HAVE_GETHOSTBYADDR_R_7_REENTRANT
+ HAVE_GETHOSTBYADDR_R_8_REENTRANT
+ HAVE_GETHOSTBYNAME_R_3
+ HAVE_GETHOSTBYNAME_R_5
+ HAVE_GETHOSTBYNAME_R_6
+ HAVE_GETHOSTBYNAME_R_3_REENTRANT
+ HAVE_GETHOSTBYNAME_R_5_REENTRANT
+ HAVE_GETHOSTBYNAME_R_6_REENTRANT
+ HAVE_SOCKLEN_T
+ HAVE_IN_ADDR_T
+ STDC_HEADERS
+ RETSIGTYPE_TEST
+ HAVE_INET_NTOA_R_DECL
+ HAVE_INET_NTOA_R_DECL_REENTRANT
+ HAVE_GETADDRINFO
+ HAVE_FILE_OFFSET_BITS
+ )
+ CURL_INTERNAL_TEST(${CURL_TEST})
+ENDFOREACH(CURL_TEST)
+IF(HAVE_FILE_OFFSET_BITS)
+ SET(_FILE_OFFSET_BITS 64)
+ENDIF(HAVE_FILE_OFFSET_BITS)
+
+# Check for reentrant
+FOREACH(CURL_TEST
+ HAVE_GETHOSTBYADDR_R_5
+ HAVE_GETHOSTBYADDR_R_7
+ HAVE_GETHOSTBYADDR_R_8
+ HAVE_GETHOSTBYNAME_R_3
+ HAVE_GETHOSTBYNAME_R_5
+ HAVE_GETHOSTBYNAME_R_6
+ HAVE_INET_NTOA_R_DECL_REENTRANT)
+ IF(NOT ${CURL_TEST})
+ IF(${CURL_TEST}_REENTRANT)
+ SET(NEED_REENTRANT 1)
+ ENDIF(${CURL_TEST}_REENTRANT)
+ ENDIF(NOT ${CURL_TEST})
+ENDFOREACH(CURL_TEST)
+
+IF(NEED_REENTRANT)
+ FOREACH(CURL_TEST
+ HAVE_GETHOSTBYADDR_R_5
+ HAVE_GETHOSTBYADDR_R_7
+ HAVE_GETHOSTBYADDR_R_8
+ HAVE_GETHOSTBYNAME_R_3
+ HAVE_GETHOSTBYNAME_R_5
+ HAVE_GETHOSTBYNAME_R_6)
+ SET(${CURL_TEST} 0)
+ IF(${CURL_TEST}_REENTRANT)
+ SET(${CURL_TEST} 1)
+ ENDIF(${CURL_TEST}_REENTRANT)
+ ENDFOREACH(CURL_TEST)
+ENDIF(NEED_REENTRANT)
+
+IF(HAVE_INET_NTOA_R_DECL_REENTRANT)
+ SET(HAVE_INET_NTOA_R_DECL 1)
+ SET(NEED_REENTRANT 1)
+ENDIF(HAVE_INET_NTOA_R_DECL_REENTRANT)
+
+# Some other minor tests
+
+IF(NOT HAVE_SOCKLEN_T)
+ SET(socklen_t "int")
+ENDIF(NOT HAVE_SOCKLEN_T)
+
+IF(NOT HAVE_IN_ADDR_T)
+ SET(in_addr_t "unsigned long")
+ENDIF(NOT HAVE_IN_ADDR_T)
+
+# Fix libz / zlib.h
+
+IF(NOT CURL_SPECIAL_LIBZ)
+ IF(NOT HAVE_LIBZ)
+ SET(HAVE_ZLIB_H 0)
+ ENDIF(NOT HAVE_LIBZ)
+
+ IF(NOT HAVE_ZLIB_H)
+ SET(HAVE_LIBZ 0)
+ ENDIF(NOT HAVE_ZLIB_H)
+ENDIF(NOT CURL_SPECIAL_LIBZ)
+
+IF(_FILE_OFFSET_BITS)
+ SET(_FILE_OFFSET_BITS 64)
+ENDIF(_FILE_OFFSET_BITS)
+SET(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
+SET(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/curl/curl.h")
+CHECK_TYPE_SIZE("curl_off_t" SIZEOF_CURL_OFF_T)
+SET(CMAKE_EXTRA_INCLUDE_FILES)
+SET(CMAKE_REQUIRED_FLAGS)
+
+
+# Check for nonblocking
+SET(HAVE_DISABLED_NONBLOCKING 1)
+IF(HAVE_FIONBIO OR
+ HAVE_IOCTLSOCKET OR
+ HAVE_IOCTLSOCKET_CASE OR
+ HAVE_O_NONBLOCK)
+ SET(HAVE_DISABLED_NONBLOCKING)
+ENDIF(HAVE_FIONBIO OR
+ HAVE_IOCTLSOCKET OR
+ HAVE_IOCTLSOCKET_CASE OR
+ HAVE_O_NONBLOCK)
+
+IF(RETSIGTYPE_TEST)
+ SET(RETSIGTYPE void)
+ELSE(RETSIGTYPE_TEST)
+ SET(RETSIGTYPE int)
+ENDIF(RETSIGTYPE_TEST)
+
+IF(CMAKE_COMPILER_IS_GNUCC AND APPLE)
+ INCLUDE(CheckCCompilerFlag)
+ CHECK_C_COMPILER_FLAG(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
+ IF(HAVE_C_FLAG_Wno_long_double)
+ # The Mac version of GCC warns about use of long double. Disable it.
+ GET_SOURCE_FILE_PROPERTY(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
+ IF(MPRINTF_COMPILE_FLAGS)
+ SET(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
+ ELSE(MPRINTF_COMPILE_FLAGS)
+ SET(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
+ ENDIF(MPRINTF_COMPILE_FLAGS)
+ SET_SOURCE_FILES_PROPERTIES(mprintf.c PROPERTIES
+ COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
+ ENDIF(HAVE_C_FLAG_Wno_long_double)
+ENDIF(CMAKE_COMPILER_IS_GNUCC AND APPLE)
+
+INCLUDE(CMake/OtherTests.cmake)
+
+# The rest of the build
+
+OPTION(CMAKE_BUILD_CURL_SHARED "Should curl be built shared" TRUE)
+IF(CMAKE_BUILD_CURL_SHARED)
+ SET(LIBRARY_TYPE SHARED)
+ ADD_DEFINITIONS(-DHAVE_CONFIG_H)
+ELSE(CMAKE_BUILD_CURL_SHARED)
+ ADD_DEFINITIONS(-DHAVE_CONFIG_H
+ -DCURL_STATICLIB)
+ENDIF(CMAKE_BUILD_CURL_SHARED)
+SET(CURL_STATICLIB)
+
+# Support CheckTypeSize module from CMake 2.8.0 and lower.
+FOREACH(var
+ SIZEOF_CURL_OFF_T
+ SIZEOF_LONG
+ SIZEOF_LONG_LONG
+ SIZEOF___INT64
+ SIZEOF_SIZE_T
+ SIZEOF_SSIZE_T
+ SIZEOF_TIME_T
+ )
+ IF(NOT ${var}_CODE)
+ MESSAGE("creating ${var}_CODE")
+ IF(${var})
+ SET(${var}_CODE "#define ${var} ${${var}}")
+ ELSE()
+ SET(${var}_CODE "/* #undef ${var} */")
+ ENDIF()
+ ENDIF()
+ENDFOREACH()
+
+CONFIGURE_FILE(${LIBCURL_SOURCE_DIR}/config.h.in
+ ${LIBCURL_BINARY_DIR}/config.h)
+
+ADD_LIBRARY(cmcurl ${LIBRARY_TYPE} ${libCurl_SRCS} ${CMAKE_CURL_SSL_DLLS})
+TARGET_LINK_LIBRARIES(cmcurl ${CURL_LIBS})
+IF(CMAKE_BUILD_CURL_SHARED)
+ SET_TARGET_PROPERTIES(cmcurl PROPERTIES DEFINE_SYMBOL BUILDING_LIBCURL
+ RUNTIME_OUTPUT_DIRECTORY ${CMake_BIN_DIR})
+ INSTALL(TARGETS cmcurl RUNTIME DESTINATION bin)
+ENDIF(CMAKE_BUILD_CURL_SHARED)
+
+OPTION(CURL_TESTING "Do libCurl testing" OFF)
+IF(CURL_TESTING)
+ SUBDIRS(Testing)
+ENDIF(CURL_TESTING)
+
+ADD_EXECUTABLE(LIBCURL Testing/curltest.c)
+TARGET_LINK_LIBRARIES(LIBCURL cmcurl ${CMAKE_DL_LIBS})
+
+IF(CMAKE_CURL_TEST_URL)
+ ADD_TEST(curl LIBCURL ${CMAKE_CURL_TEST_URL})
+ENDIF(CMAKE_CURL_TEST_URL)
+
+INSTALL(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmcurl)
diff --git a/Utilities/cmcurl/COPYING b/Utilities/cmcurl/COPYING
new file mode 100644
index 0000000000..048cf5657d
--- /dev/null
+++ b/Utilities/cmcurl/COPYING
@@ -0,0 +1,21 @@
+COPYRIGHT AND PERMISSION NOTICE
+
+Copyright (c) 1996 - 2009, Daniel Stenberg, <daniel@haxx.se>.
+
+All rights reserved.
+
+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", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN
+NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
+OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of a copyright holder shall not
+be used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization of the copyright holder.
diff --git a/Utilities/cmcurl/Platforms/WindowsCache.cmake b/Utilities/cmcurl/Platforms/WindowsCache.cmake
new file mode 100644
index 0000000000..57ab30be3f
--- /dev/null
+++ b/Utilities/cmcurl/Platforms/WindowsCache.cmake
@@ -0,0 +1,120 @@
+IF(NOT UNIX)
+ IF(WIN32)
+ SET(HAVE_LIBDL 0)
+ SET(HAVE_LIBUCB 0)
+ SET(HAVE_LIBSOCKET 0)
+ SET(NOT_NEED_LIBNSL 0)
+ SET(HAVE_LIBNSL 0)
+ SET(HAVE_LIBZ 0)
+ SET(HAVE_LIBCRYPTO 0)
+
+ SET(HAVE_DLOPEN 0)
+
+ SET(HAVE_ALLOCA_H 0)
+ SET(HAVE_ARPA_INET_H 0)
+ SET(HAVE_DLFCN_H 0)
+ SET(HAVE_FCNTL_H 1)
+ SET(HAVE_FEATURES_H 0)
+ SET(HAVE_INTTYPES_H 0)
+ SET(HAVE_IO_H 1)
+ SET(HAVE_MALLOC_H 1)
+ SET(HAVE_MEMORY_H 1)
+ SET(HAVE_NETDB_H 0)
+ SET(HAVE_NETINET_IF_ETHER_H 0)
+ SET(HAVE_NETINET_IN_H 0)
+ SET(HAVE_NET_IF_H 0)
+ SET(HAVE_PROCESS_H 1)
+ SET(HAVE_PWD_H 0)
+ SET(HAVE_SETJMP_H 1)
+ SET(HAVE_SGTTY_H 0)
+ SET(HAVE_SIGNAL_H 1)
+ SET(HAVE_SOCKIO_H 0)
+ SET(HAVE_STDINT_H 0)
+ SET(HAVE_STDLIB_H 1)
+ SET(HAVE_STRINGS_H 0)
+ SET(HAVE_STRING_H 1)
+ SET(HAVE_SYS_PARAM_H 0)
+ SET(HAVE_SYS_POLL_H 0)
+ SET(HAVE_SYS_SELECT_H 0)
+ SET(HAVE_SYS_SOCKET_H 0)
+ SET(HAVE_SYS_SOCKIO_H 0)
+ SET(HAVE_SYS_STAT_H 1)
+ SET(HAVE_SYS_TIME_H 0)
+ SET(HAVE_SYS_TYPES_H 1)
+ SET(HAVE_SYS_UTIME_H 1)
+ SET(HAVE_TERMIOS_H 0)
+ SET(HAVE_TERMIO_H 0)
+ SET(HAVE_TIME_H 1)
+ SET(HAVE_UNISTD_H 0)
+ SET(HAVE_UTIME_H 0)
+ SET(HAVE_X509_H 0)
+ SET(HAVE_ZLIB_H 0)
+
+ SET(HAVE_SIZEOF_LONG_DOUBLE 1)
+ SET(SIZEOF_LONG_DOUBLE 8)
+
+ SET(HAVE_SOCKET 1)
+ SET(HAVE_POLL 0)
+ SET(HAVE_SELECT 1)
+ SET(HAVE_STRDUP 1)
+ SET(HAVE_STRSTR 1)
+ SET(HAVE_STRTOK_R 0)
+ SET(HAVE_STRFTIME 1)
+ SET(HAVE_UNAME 0)
+ SET(HAVE_STRCASECMP 0)
+ SET(HAVE_STRICMP 1)
+ SET(HAVE_STRCMPI 1)
+ SET(HAVE_GETHOSTBYADDR 1)
+ SET(HAVE_GETTIMEOFDAY 0)
+ SET(HAVE_INET_ADDR 1)
+ SET(HAVE_INET_NTOA 1)
+ SET(HAVE_INET_NTOA_R 0)
+ SET(HAVE_TCGETATTR 0)
+ SET(HAVE_TCSETATTR 0)
+ SET(HAVE_PERROR 1)
+ SET(HAVE_CLOSESOCKET 1)
+ SET(HAVE_SETVBUF 0)
+ SET(HAVE_SIGSETJMP 0)
+ SET(HAVE_GETPASS_R 0)
+ SET(HAVE_GETPWUID 0)
+ SET(HAVE_GETEUID 0)
+ SET(HAVE_UTIME 1)
+ SET(HAVE_RAND_EGD 0)
+ SET(HAVE_RAND_SCREEN 0)
+ SET(HAVE_RAND_STATUS 0)
+ SET(HAVE_GMTIME_R 0)
+ SET(HAVE_LOCALTIME_R 0)
+ SET(HAVE_GETHOSTBYADDR_R 0)
+ SET(HAVE_GETHOSTBYNAME_R 0)
+ SET(HAVE_SIGNAL_FUNC 1)
+ SET(HAVE_SIGNAL_MACRO 0)
+
+ SET(HAVE_GETHOSTBYADDR_R_5 0)
+ SET(HAVE_GETHOSTBYADDR_R_5_REENTRANT 0)
+ SET(HAVE_GETHOSTBYADDR_R_7 0)
+ SET(HAVE_GETHOSTBYADDR_R_7_REENTRANT 0)
+ SET(HAVE_GETHOSTBYADDR_R_8 0)
+ SET(HAVE_GETHOSTBYADDR_R_8_REENTRANT 0)
+ SET(HAVE_GETHOSTBYNAME_R_3 0)
+ SET(HAVE_GETHOSTBYNAME_R_3_REENTRANT 0)
+ SET(HAVE_GETHOSTBYNAME_R_5 0)
+ SET(HAVE_GETHOSTBYNAME_R_5_REENTRANT 0)
+ SET(HAVE_GETHOSTBYNAME_R_6 0)
+ SET(HAVE_GETHOSTBYNAME_R_6_REENTRANT 0)
+
+ SET(TIME_WITH_SYS_TIME 0)
+ SET(HAVE_O_NONBLOCK 0)
+ SET(HAVE_IN_ADDR_T 0)
+ SET(HAVE_INET_NTOA_R_DECL 0)
+ SET(HAVE_INET_NTOA_R_DECL_REENTRANT 0)
+ SET(HAVE_GETADDRINFO 0)
+ SET(STDC_HEADERS 1)
+ SET(RETSIGTYPE_TEST 1)
+
+ SET(HAVE_SIGACTION 0)
+ SET(HAVE_MACRO_SIGSETJMP 0)
+ ELSE(WIN32)
+ MESSAGE("This file should be included on Windows platform only")
+ ENDIF(WIN32)
+ENDIF(NOT UNIX)
+
diff --git a/Utilities/cmcurl/Platforms/config-aix.h b/Utilities/cmcurl/Platforms/config-aix.h
new file mode 100644
index 0000000000..c98b10fdda
--- /dev/null
+++ b/Utilities/cmcurl/Platforms/config-aix.h
@@ -0,0 +1,483 @@
+/* lib/config.h. Generated by configure. */
+/* lib/config.h.in. Generated from configure.in by autoheader. */
+/* Name of this package! */
+#define PACKAGE "curl"
+
+/* Version number of this archive. */
+#define VERSION "7.10.2"
+
+/* Define if you have the getpass function. */
+/* #undef HAVE_GETPASS */
+
+/* Define cpu-machine-OS */
+#define OS "powerpc-ibm-aix5.1.0.0"
+
+/* Define if you have the gethostbyaddr_r() function with 5 arguments */
+#define HAVE_GETHOSTBYADDR_R_5 1
+
+/* Define if you have the gethostbyaddr_r() function with 7 arguments */
+/* #undef HAVE_GETHOSTBYADDR_R_7 */
+
+/* Define if you have the gethostbyaddr_r() function with 8 arguments */
+/* #undef HAVE_GETHOSTBYADDR_R_8 */
+
+/* Define if you have the gethostbyname_r() function with 3 arguments */
+#define HAVE_GETHOSTBYNAME_R_3 1
+
+/* Define if you have the gethostbyname_r() function with 5 arguments */
+/* #undef HAVE_GETHOSTBYNAME_R_5 */
+
+/* Define if you have the gethostbyname_r() function with 6 arguments */
+/* #undef HAVE_GETHOSTBYNAME_R_6 */
+
+/* Define if you have the inet_ntoa_r function declared. */
+/* #undef HAVE_INET_NTOA_R_DECL */
+
+/* Define if you need the _REENTRANT define for some functions */
+/* #undef NEED_REENTRANT */
+
+/* Define if you have the Kerberos4 libraries (including -ldes) */
+/* #undef KRB4 */
+
+/* Define if you want to enable IPv6 support */
+#define ENABLE_IPV6 1
+
+/* Define this to 'int' if ssize_t is not an available typedefed type */
+/* #undef ssize_t */
+
+/* Define this to 'int' if socklen_t is not an available typedefed type */
+/* #undef socklen_t */
+
+/* Define this as a suitable file to read random data from */
+/* #undef RANDOM_FILE */
+
+/* Define this to your Entropy Gathering Daemon socket pathname */
+/* #undef EGD_SOCKET */
+
+/* Define if you have a working OpenSSL installation */
+/* #undef OPENSSL_ENABLED */
+
+/* Define the one correct non-blocking socket method below */
+/* #undef HAVE_FIONBIO */
+/* #undef HAVE_IOCTLSOCKET */
+/* #undef HAVE_IOCTLSOCKET_CASE */
+/* #undef HAVE_O_NONBLOCK */
+#define HAVE_DISABLED_NONBLOCKING 1
+
+/* Define this to 'int' if in_addr_t is not an available typedefed type */
+/* #undef in_addr_t */
+
+/* Define to disable DICT */
+/* #undef CURL_DISABLE_DICT */
+
+/* Define to disable FILE */
+/* #undef CURL_DISABLE_FILE */
+
+/* Define to disable FTP */
+/* #undef CURL_DISABLE_FTP */
+
+/* Define to disable GOPHER */
+/* #undef CURL_DISABLE_GOPHER */
+
+/* Define to disable HTTP */
+/* #undef CURL_DISABLE_HTTP */
+
+/* Define to disable LDAP */
+/* #undef CURL_DISABLE_LDAP */
+
+/* Define to disable TELNET */
+/* #undef CURL_DISABLE_TELNET */
+
+/* Define if you have zlib present */
+#define HAVE_LIBZ 1
+
+/* CA bundle full path name */
+#define CURL_CA_BUNDLE "/usr/local/share/curl/curl-ca-bundle.crt"
+
+/* to disable FILE */
+/* #undef CURL_DISABLE_FILE */
+
+/* to disable FTP */
+/* #undef CURL_DISABLE_FTP */
+
+/* to disable GOPHER */
+/* #undef CURL_DISABLE_GOPHER */
+
+/* to disable HTTP */
+/* #undef CURL_DISABLE_HTTP */
+
+/* to disable LDAP */
+/* #undef CURL_DISABLE_LDAP */
+
+/* to disable TELNET */
+/* #undef CURL_DISABLE_TELNET */
+
+/* Set to explicitly specify we don't want to use thread-safe functions */
+/* #undef DISABLED_THREADSAFE */
+
+/* your Entropy Gathering Daemon socket pathname */
+/* #undef EGD_SOCKET */
+
+/* Define if you want to enable IPv6 support */
+#define ENABLE_IPV6 1
+
+/* Define to 1 if you have the <alloca.h> header file. */
+#define HAVE_ALLOCA_H 1
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#define HAVE_ARPA_INET_H 1
+
+/* Define to 1 if you have the `closesocket' function. */
+/* #undef HAVE_CLOSESOCKET */
+
+/* Define to 1 if you have the <crypto.h> header file. */
+/* #undef HAVE_CRYPTO_H */
+
+/* Define to 1 if you have the <des.h> header file. */
+/* #undef HAVE_DES_H */
+
+/* to disable NON-BLOCKING connections */
+#define HAVE_DISABLED_NONBLOCKING 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the `dlopen' function. */
+#define HAVE_DLOPEN 1
+
+/* Define to 1 if you have the <err.h> header file. */
+/* #undef HAVE_ERR_H */
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define if getaddrinfo exists and works */
+#define HAVE_GETADDRINFO 1
+
+/* Define to 1 if you have the `geteuid' function. */
+#define HAVE_GETEUID 1
+
+/* Define to 1 if you have the `gethostbyaddr' function. */
+#define HAVE_GETHOSTBYADDR 1
+
+/* Define to 1 if you have the `gethostbyaddr_r' function. */
+#define HAVE_GETHOSTBYADDR_R 1
+
+/* Define to 1 if you have the `gethostbyname_r' function. */
+#define HAVE_GETHOSTBYNAME_R 1
+
+/* Define to 1 if you have the `getpass_r' function. */
+/* #undef HAVE_GETPASS_R */
+
+/* Define to 1 if you have the `getpwuid' function. */
+#define HAVE_GETPWUID 1
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#define HAVE_GETTIMEOFDAY 1
+
+/* Define to 1 if you have the `gmtime_r' function. */
+#define HAVE_GMTIME_R 1
+
+/* Define to 1 if you have the `inet_addr' function. */
+#define HAVE_INET_ADDR 1
+
+/* Define to 1 if you have the `inet_ntoa' function. */
+#define HAVE_INET_NTOA 1
+
+/* Define to 1 if you have the `inet_ntoa_r' function. */
+#define HAVE_INET_NTOA_R 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <io.h> header file. */
+/* #undef HAVE_IO_H */
+
+/* Define to 1 if you have the `krb_get_our_ip_for_realm' function. */
+/* #undef HAVE_KRB_GET_OUR_IP_FOR_REALM */
+
+/* Define to 1 if you have the <krb.h> header file. */
+/* #undef HAVE_KRB_H */
+
+/* Define to 1 if you have the `crypto' library (-lcrypto). */
+/* #undef HAVE_LIBCRYPTO */
+
+/* Define to 1 if you have the `dl' library (-ldl). */
+/* #undef HAVE_LIBDL */
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+/* #undef HAVE_LIBNSL */
+
+/* Define to 1 if you have the `resolv' library (-lresolv). */
+/* #undef HAVE_LIBRESOLV */
+
+/* Define to 1 if you have the `resolve' library (-lresolve). */
+/* #undef HAVE_LIBRESOLVE */
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Define to 1 if you have the `ssl' library (-lssl). */
+/* #undef HAVE_LIBSSL */
+
+/* If zlib is available */
+#define HAVE_LIBZ 1
+
+/* Define to 1 if you have the `localtime_r' function. */
+#define HAVE_LOCALTIME_R 1
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#define HAVE_MALLOC_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <netinet/if_ether.h> header file. */
+#define HAVE_NETINET_IF_ETHER_H 1
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if you have the <net/if.h> header file. */
+#define HAVE_NET_IF_H 1
+
+/* Define to 1 if you have the <openssl/crypto.h> header file. */
+/* #undef HAVE_OPENSSL_CRYPTO_H */
+
+/* Define to 1 if you have the <openssl/engine.h> header file. */
+/* #undef HAVE_OPENSSL_ENGINE_H */
+
+/* Define to 1 if you have the <openssl/err.h> header file. */
+/* #undef HAVE_OPENSSL_ERR_H */
+
+/* Define to 1 if you have the <openssl/pem.h> header file. */
+/* #undef HAVE_OPENSSL_PEM_H */
+
+/* Define to 1 if you have the <openssl/rsa.h> header file. */
+/* #undef HAVE_OPENSSL_RSA_H */
+
+/* Define to 1 if you have the <openssl/ssl.h> header file. */
+/* #undef HAVE_OPENSSL_SSL_H */
+
+/* Define to 1 if you have the <openssl/x509.h> header file. */
+/* #undef HAVE_OPENSSL_X509_H */
+
+/* Define to 1 if you have the <pem.h> header file. */
+/* #undef HAVE_PEM_H */
+
+/* Define to 1 if you have the `perror' function. */
+#define HAVE_PERROR 1
+
+/* Define to 1 if you have the `poll' function. */
+#define HAVE_POLL 1
+
+/* Define to 1 if you have the <pwd.h> header file. */
+#define HAVE_PWD_H 1
+
+/* Define to 1 if you have the `RAND_egd' function. */
+/* #undef HAVE_RAND_EGD */
+
+/* Define to 1 if you have the `RAND_screen' function. */
+/* #undef HAVE_RAND_SCREEN */
+
+/* Define to 1 if you have the `RAND_status' function. */
+/* #undef HAVE_RAND_STATUS */
+
+/* Define to 1 if you have the <rsa.h> header file. */
+/* #undef HAVE_RSA_H */
+
+/* Define to 1 if you have the `select' function. */
+#define HAVE_SELECT 1
+
+/* Define to 1 if you have the <setjmp.h> header file. */
+#define HAVE_SETJMP_H 1
+
+/* Define to 1 if you have the `setvbuf' function. */
+#define HAVE_SETVBUF 1
+
+/* Define to 1 if you have the <sgtty.h> header file. */
+#define HAVE_SGTTY_H 1
+
+/* Define to 1 if you have the `sigaction' function. */
+#define HAVE_SIGACTION 1
+
+/* Define to 1 if you have the `signal' function. */
+#define HAVE_SIGNAL 1
+
+/* If you have sigsetjmp */
+#define HAVE_SIGSETJMP 1
+
+/* Define to 1 if you have the `socket' function. */
+#define HAVE_SOCKET 1
+
+/* Define to 1 if you have the <ssl.h> header file. */
+/* #undef HAVE_SSL_H */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+/* #undef HAVE_STDINT_H */
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#define HAVE_STRCASECMP 1
+
+/* Define to 1 if you have the `strcmpi' function. */
+/* #undef HAVE_STRCMPI */
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strftime' function. */
+#define HAVE_STRFTIME 1
+
+/* Define to 1 if you have the `stricmp' function. */
+/* #undef HAVE_STRICMP */
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strlcpy' function. */
+/* #undef HAVE_STRLCPY */
+
+/* Define to 1 if you have the `strstr' function. */
+#define HAVE_STRSTR 1
+
+/* Define to 1 if you have the `strtok_r' function. */
+#define HAVE_STRTOK_R 1
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#define HAVE_SYS_POLL_H 1
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#define HAVE_SYS_SELECT_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/sockio.h> header file. */
+/* #undef HAVE_SYS_SOCKIO_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/utime.h> header file. */
+/* #undef HAVE_SYS_UTIME_H */
+
+/* Define to 1 if you have the `tcgetattr' function. */
+#define HAVE_TCGETATTR 1
+
+/* Define to 1 if you have the `tcsetattr' function. */
+#define HAVE_TCSETATTR 1
+
+/* Define to 1 if you have the <termios.h> header file. */
+#define HAVE_TERMIOS_H 1
+
+/* Define to 1 if you have the <termio.h> header file. */
+#define HAVE_TERMIO_H 1
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the `uname' function. */
+#define HAVE_UNAME 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the `utime' function. */
+#define HAVE_UTIME 1
+
+/* Define to 1 if you have the <utime.h> header file. */
+#define HAVE_UTIME_H 1
+
+/* Define to 1 if you have the <winsock.h> header file. */
+/* #undef HAVE_WINSOCK_H */
+
+/* Define to 1 if you have the <x509.h> header file. */
+/* #undef HAVE_X509_H */
+
+/* if you have the zlib.h header file */
+/* #undef HAVE_ZLIB_H */
+
+/* if you have the Kerberos4 libraries (including -ldes) */
+/* #undef KRB4 */
+
+/* cpu-machine-OS */
+#define OS "powerpc-ibm-aix5.1.0.0"
+
+/* Name of package */
+#define PACKAGE "curl"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME ""
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING ""
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION ""
+
+/* a suitable file to read random data from */
+/* #undef RANDOM_FILE */
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME 1
+
+/* Version number of package */
+#define VERSION "7.10.2"
+
+/* Define to 1 if on AIX 3.
+ System headers sometimes define this.
+ We just want to avoid a redefinition error message. */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
+
+/* Define for large files, on AIX-style hosts. */
+#define _LARGE_FILES 1
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* type to use in place of in_addr_t if not defined */
+/* #undef in_addr_t */
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* type to use in place of socklen_t if not defined */
+/* #undef socklen_t */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef ssize_t */
diff --git a/Utilities/cmcurl/Testing/CMakeLists.txt b/Utilities/cmcurl/Testing/CMakeLists.txt
new file mode 100644
index 0000000000..214410fd56
--- /dev/null
+++ b/Utilities/cmcurl/Testing/CMakeLists.txt
@@ -0,0 +1,19 @@
+SET(CURL_TESTS
+ ftpget
+ ftpgetresp
+ ftpupload
+ getinmemory
+ persistant
+ sepheaders
+ simple
+ )
+
+CONFIGURE_FILE(${LIBCURL_SOURCE_DIR}/Testing/testconfig.h.in
+ ${LIBCURL_BINARY_DIR}/Testing/testconfig.h)
+
+INCLUDE_DIRECTORIES(${LIBCURL_BINARY_DIR}/Testing)
+
+FOREACH(TEST ${CURL_TESTS})
+ ADD_EXECUTABLE(${TEST} ${TEST}.c)
+ TARGET_LINK_LIBRARIES(${TEST} cmcurl)
+ENDFOREACH(TEST)
diff --git a/Utilities/cmcurl/Testing/curlgtk.c b/Utilities/cmcurl/Testing/curlgtk.c
new file mode 100644
index 0000000000..7c9ce2a1ba
--- /dev/null
+++ b/Utilities/cmcurl/Testing/curlgtk.c
@@ -0,0 +1,95 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+/* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */
+/* an attempt to use the curl library in concert with a gtk-threaded application */
+
+#include <stdio.h>
+#include <gtk/gtk.h>
+
+#include <curl/curl.h>
+#include <curl/types.h> /* new for v7 */
+#include <curl/easy.h> /* new for v7 */
+
+#include <pthread.h>
+
+GtkWidget *Bar;
+
+size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+ return fread(ptr, size, nmemb, stream);
+}
+
+int my_progress_func(GtkWidget *Bar, int t, int d)
+{
+/* printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/
+ gdk_threads_enter();
+ gtk_progress_set_value(GTK_PROGRESS(Bar), d*100.0/t);
+ gdk_threads_leave();
+ return 0;
+}
+
+void *curl_thread(void *ptr)
+{
+ CURL *curl;
+ CURLcode res;
+ FILE *outfile;
+ gchar *url = ptr;
+
+ curl = curl_easy_init();
+ if(curl)
+ {
+ outfile = fopen("/tmp/test.curl", "w");
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_FILE, outfile);
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func);
+ curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
+ curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar);
+
+ res = curl_easy_perform(curl);
+
+ fclose(outfile);
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+ return NULL;
+}
+
+int main(int argc, char **argv)
+{
+ GtkWidget *Window, *Frame, *Frame2;
+ GtkAdjustment *adj;
+ pthread_t curl_tid;
+
+ /* Init thread */
+ g_thread_init(NULL);
+
+ gtk_init(&argc, &argv);
+ Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ Frame = gtk_frame_new(NULL);
+ gtk_frame_set_shadow_type(GTK_FRAME(Frame), GTK_SHADOW_OUT);
+ gtk_container_add(GTK_CONTAINER(Window), Frame);
+ Frame2 = gtk_frame_new(NULL);
+ gtk_frame_set_shadow_type(GTK_FRAME(Frame2), GTK_SHADOW_IN);
+ gtk_container_add(GTK_CONTAINER(Frame), Frame2);
+ gtk_container_set_border_width(GTK_CONTAINER(Frame2), 5);
+ adj = (GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0);
+ Bar = gtk_progress_bar_new_with_adjustment(adj);
+ gtk_container_add(GTK_CONTAINER(Frame2), Bar);
+ gtk_widget_show_all(Window);
+
+ pthread_create(&curl_tid, NULL, curl_thread, argv[1]);
+
+ gdk_threads_enter();
+ gtk_main();
+ gdk_threads_leave();
+ return 0;
+}
+
diff --git a/Utilities/cmcurl/Testing/curltest.c b/Utilities/cmcurl/Testing/curltest.c
new file mode 100644
index 0000000000..210868e362
--- /dev/null
+++ b/Utilities/cmcurl/Testing/curltest.c
@@ -0,0 +1,159 @@
+/* Prevent warnings on Visual Studio */
+struct _RPC_ASYNC_STATE;
+
+#include "curl/curl.h"
+#include <stdlib.h>
+#include <string.h>
+
+int GetFtpFile(void)
+{
+ int retVal = 0;
+ CURL *curl;
+ CURLcode res;
+ curl = curl_easy_init();
+ if(curl)
+ {
+ /* Get curl 7.9.2 from sunet.se's FTP site: */
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ curl_easy_setopt(curl, CURLOPT_HEADER, 1);
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://public.kitware.com/pub/cmake/cygwin/setup.hint");
+ res = curl_easy_perform(curl);
+ if ( res != 0 )
+ {
+ printf("Error fetching: ftp://public.kitware.com/pub/cmake/cygwin/setup.hint\n");
+ retVal = 1;
+ }
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+ else
+ {
+ printf("Cannot create curl object\n");
+ retVal = 1;
+ }
+ return retVal;
+}
+
+int GetWebFiles(char *url1, char *url2)
+{
+ int retVal = 0;
+ CURL *curl;
+ CURLcode res;
+
+ char proxy[1024];
+ int proxy_type = 0;
+
+ if ( getenv("HTTP_PROXY") )
+ {
+ proxy_type = 1;
+ if (getenv("HTTP_PROXY_PORT") )
+ {
+ sprintf(proxy, "%s:%s", getenv("HTTP_PROXY"), getenv("HTTP_PROXY_PORT"));
+ }
+ else
+ {
+ sprintf(proxy, "%s", getenv("HTTP_PROXY"));
+ }
+ if ( getenv("HTTP_PROXY_TYPE") )
+ {
+ /* HTTP/SOCKS4/SOCKS5 */
+ if ( strcmp(getenv("HTTP_PROXY_TYPE"), "HTTP") == 0 )
+ {
+ proxy_type = 1;
+ }
+ else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS4") == 0 )
+ {
+ proxy_type = 2;
+ }
+ else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS5") == 0 )
+ {
+ proxy_type = 3;
+ }
+ }
+ }
+
+ curl = curl_easy_init();
+ if(curl)
+ {
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ curl_easy_setopt(curl, CURLOPT_HEADER, 1);
+
+ /* Using proxy */
+ if ( proxy_type > 0 )
+ {
+ curl_easy_setopt(curl, CURLOPT_PROXY, proxy);
+ switch (proxy_type)
+ {
+ case 2:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+ break;
+ case 3:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+ break;
+ default:
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+ }
+ }
+
+ /* get the first document */
+ curl_easy_setopt(curl, CURLOPT_URL, url1);
+ res = curl_easy_perform(curl);
+ if ( res != 0 )
+ {
+ printf("Error fetching: %s\n", url1);
+ retVal = 1;
+ }
+
+ /* get another document from the same server using the same
+ connection */
+ /* avoid warnings about url2 since below block is commented out: */
+ (void) url2;
+ /*
+ curl_easy_setopt(curl, CURLOPT_URL, url2);
+ res = curl_easy_perform(curl);
+ if ( res != 0 )
+ {
+ printf("Error fetching: %s\n", url2);
+ retVal = 1;
+ }
+ */
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+ else
+ {
+ printf("Cannot create curl object\n");
+ retVal = 1;
+ }
+
+ return retVal;
+}
+
+
+int main(int argc, char **argv)
+{
+ int retVal = 0;
+
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+
+ if(argc>1)
+ {
+ retVal += GetWebFiles(argv[1], 0);
+ }
+ else
+ {
+ printf("error: first argument should be a url to download\n");
+ retVal = 1;
+ }
+
+ /* Do not check the output of FTP socks5 cannot handle FTP yet */
+ /* GetFtpFile(); */
+ /* do not test ftp right now because we don't enable that port */
+
+ curl_global_cleanup();
+
+ return retVal;
+}
diff --git a/Utilities/cmcurl/Testing/ftpget.c b/Utilities/cmcurl/Testing/ftpget.c
new file mode 100644
index 0000000000..1a3633ec91
--- /dev/null
+++ b/Utilities/cmcurl/Testing/ftpget.c
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+#include "curl/curl.h"
+#include "curl/types.h"
+#include "curl/easy.h"
+#include "setup.h"
+
+#include "testconfig.h"
+
+/*
+ * This is an example showing how to get a single file from an FTP server.
+ * It delays the actual destination file creation until the first write
+ * callback so that it won't create an empty file in case the remote file
+ * doesn't exist or something else fails.
+ */
+
+struct FtpFile {
+ char *filename;
+ FILE *stream;
+};
+
+int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
+{
+ struct FtpFile *out=(struct FtpFile *)stream;
+ if(out && !out->stream) {
+ /* open file for writing */
+ out->stream=fopen(out->filename, "wb");
+ if(!out->stream)
+ return -1; /* failure, can't open file to write */
+ }
+ return fwrite(buffer, size, nmemb, out->stream);
+}
+
+
+int main(void)
+{
+ CURL *curl;
+ CURLcode res;
+ struct FtpFile ftpfile={
+ LIBCURL_BINARY_DIR "/Testing/ftpget-download.txt", /* name to store the file as if succesful */
+ NULL
+ };
+
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+
+ curl = curl_easy_init();
+ if(curl) {
+ /* Get curl 7.9.2 from sunet.se's FTP site: */
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://public.kitware.com/pub/cmake/cygwin/setup.hint");
+ /* Define our callback to get called when there's data to be written */
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
+ /* Set a pointer to our struct to pass to the callback */
+ curl_easy_setopt(curl, CURLOPT_FILE, &ftpfile);
+
+ /* Switch on full protocol/debug output */
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE);
+
+ res = curl_easy_perform(curl);
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+
+ if(CURLE_OK != res) {
+ /* we failed */
+ fprintf(stderr, "curl told us %d\n", res);
+ }
+ }
+
+ if(ftpfile.stream)
+ fclose(ftpfile.stream); /* close the local file */
+
+ curl_global_cleanup();
+
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/ftpgetresp.c b/Utilities/cmcurl/Testing/ftpgetresp.c
new file mode 100644
index 0000000000..9548b2a345
--- /dev/null
+++ b/Utilities/cmcurl/Testing/ftpgetresp.c
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+#include "curl/curl.h"
+#include "curl/types.h"
+#include "curl/easy.h"
+
+#include "testconfig.h"
+
+/*
+ * Similar to ftpget.c but this also stores the received response-lines
+ * in a separate file using our own callback!
+ *
+ * This functionality was introduced in libcurl 7.9.3.
+ */
+
+size_t
+write_response(void *ptr, size_t size, size_t nmemb, void *data)
+{
+ FILE *writehere = (FILE *)data;
+ return fwrite(ptr, size, nmemb, writehere);
+}
+
+int main(int argc, char **argv)
+{
+ CURL *curl;
+ CURLcode res;
+ FILE *ftpfile;
+ FILE *respfile;
+ (void)argc; (void)argv;
+
+ /* local file name to store the file as */
+ ftpfile = fopen(LIBCURL_BINARY_DIR "/Testing/ftpgetresp-list.txt", "wb"); /* b is binary, needed on win32 */
+
+ /* local file name to store the FTP server's response lines in */
+ respfile = fopen(LIBCURL_BINARY_DIR "/Testing/ftpgetresp-responses.txt", "wb"); /* b is binary, needed on win32 */
+
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+
+ curl = curl_easy_init();
+ if(curl) {
+ /* Get a file listing from sunet */
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://public.kitware.com/");
+ curl_easy_setopt(curl, CURLOPT_FILE, ftpfile);
+ curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response);
+ curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile);
+ res = curl_easy_perform(curl);
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+
+ fclose(ftpfile); /* close the local file */
+ fclose(respfile); /* close the response file */
+
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/ftpupload.c b/Utilities/cmcurl/Testing/ftpupload.c
new file mode 100644
index 0000000000..780c9cd277
--- /dev/null
+++ b/Utilities/cmcurl/Testing/ftpupload.c
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+#include "curl/curl.h"
+#include "setup.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "testconfig.h"
+
+/*
+ * This example shows an FTP upload, with a rename of the file just after
+ * a successful upload.
+ *
+ * Example based on source code provided by Erick Nuwendam. Thanks!
+ */
+
+#define LOCAL_FILE LIBCURL_SOURCE_DIR "/Testing/ftpupload.c"
+#define UPLOAD_FILE_AS "while-uploading.txt"
+#define REMOTE_URL "ftp://public.kitware.com/incoming/" UPLOAD_FILE_AS
+#define RENAME_FILE_TO "renamed-and-fine.txt"
+
+int main(int argc, char **argv)
+{
+ CURL *curl;
+ CURLcode res;
+ FILE *ftpfile;
+ FILE * hd_src ;
+ int hd ;
+ struct stat file_info;
+
+ struct curl_slist *headerlist=NULL;
+ char buf_1 [] = "RNFR " UPLOAD_FILE_AS;
+ char buf_2 [] = "RNTO " RENAME_FILE_TO;
+
+ /* get the file size of the local file */
+ hd = open(LOCAL_FILE, O_RDONLY) ;
+ fstat(hd, &file_info);
+ close(hd) ;
+
+ /* get a FILE * of the same file, could also be made with
+ fdopen() from the previous descriptor, but hey this is just
+ an example! */
+ hd_src = fopen(LOCAL_FILE, "rb");
+
+ /* In windows, this will init the winsock stuff */
+ curl_global_init(CURL_GLOBAL_ALL);
+
+ /* get a curl handle */
+ curl = curl_easy_init();
+ if(curl) {
+ /* build a list of commands to pass to libcurl */
+ headerlist = curl_slist_append(headerlist, buf_1);
+ headerlist = curl_slist_append(headerlist, buf_2);
+
+ /* enable uploading */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
+
+ /* specify target */
+ curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL);
+
+ /* pass in that last of FTP commands to run after the transfer */
+ curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
+
+ /* now specify which file to upload */
+ curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
+
+ /* and give the size of the upload (optional) */
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long)file_info.st_size);
+
+ /* Now run off and do what you've been told! */
+ res = curl_easy_perform(curl);
+
+ /* clean up the FTP commands list */
+ curl_slist_free_all (headerlist);
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+ fclose(hd_src); /* close the local file */
+
+ curl_global_cleanup();
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/getinmemory.c b/Utilities/cmcurl/Testing/getinmemory.c
new file mode 100644
index 0000000000..a8872da778
--- /dev/null
+++ b/Utilities/cmcurl/Testing/getinmemory.c
@@ -0,0 +1,83 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ *
+ * Example source code to show how the callback function can be used to
+ * download data into a chunk of memory instead of storing it in a file.
+ *
+ * This exact source code has not been verified to work.
+ */
+
+/* to make this work under windows, use the win32-functions from the
+ win32socket.c file as well */
+
+#include "curl/curl.h"
+#include "curl/types.h"
+#include "curl/easy.h"
+
+struct MemoryStruct {
+ char *memory;
+ size_t size;
+};
+
+size_t
+WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
+{
+ register int realsize = size * nmemb;
+ struct MemoryStruct *mem = (struct MemoryStruct *)data;
+
+ mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
+ if (mem->memory) {
+ memcpy(&(mem->memory[mem->size]), ptr, realsize);
+ mem->size += realsize;
+ mem->memory[mem->size] = 0;
+ }
+ return realsize;
+}
+
+int main(int argc, char **argv)
+{
+ CURL *curl_handle;
+
+ struct MemoryStruct chunk;
+
+ chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
+ chunk.size = 0; /* no data at this point */
+
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+
+ /* init the curl session */
+ curl_handle = curl_easy_init();
+
+ /* specify URL to get */
+ curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.cmake.org/HTML/Index.html");
+
+ /* send all data to this function */
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
+
+ /* we pass our 'chunk' struct to the callback function */
+ curl_easy_setopt(curl_handle, CURLOPT_FILE, (void *)&chunk);
+
+ /* get it! */
+ curl_easy_perform(curl_handle);
+
+ /* cleanup curl stuff */
+ curl_easy_cleanup(curl_handle);
+
+ /*
+ * Now, our chunk.memory points to a memory block that is chunk.size
+ * bytes big and contains the remote file.
+ *
+ * Do something nice with it!
+ */
+
+ /* For example display it... */
+ write(1, chunk.memory, chunk.size);
+
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/http-post.c b/Utilities/cmcurl/Testing/http-post.c
new file mode 100644
index 0000000000..1b4154fbf1
--- /dev/null
+++ b/Utilities/cmcurl/Testing/http-post.c
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <curl/curl.h>
+
+int main(void)
+{
+ CURL *curl;
+ CURLcode res;
+
+ curl = curl_easy_init();
+ if(curl) {
+ /* First set the URL that is about to receive our POST. This URL can
+ just as well be a https:// URL if that is what should receive the
+ data. */
+ curl_easy_setopt(curl, CURLOPT_URL, "http://postit.example.com/moo.cgi");
+ /* Now specify the POST data */
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");
+
+ /* Perform the request, res will get the return code */
+ res = curl_easy_perform(curl);
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/httpput.c b/Utilities/cmcurl/Testing/httpput.c
new file mode 100644
index 0000000000..78275c40a0
--- /dev/null
+++ b/Utilities/cmcurl/Testing/httpput.c
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#include <curl/curl.h>
+
+/*
+ * This example shows a HTTP PUT operation. PUTs a file given as a command
+ * line argument to the URL also given on the command line.
+ *
+ * This example also uses its own read callback.
+ */
+
+size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
+{
+ size_t retcode;
+
+ /* in real-world cases, this would probably get this data differently
+ as this fread() stuff is exactly what the library already would do
+ by default internally */
+ retcode = fread(ptr, size, nmemb, stream);
+
+ fprintf(stderr, "*** We read %d bytes from file\n", retcode);
+
+ return retcode;
+}
+
+int main(int argc, char **argv)
+{
+ CURL *curl;
+ CURLcode res;
+ FILE *ftpfile;
+ FILE * hd_src ;
+ int hd ;
+ struct stat file_info;
+
+ char *file;
+ char *url;
+
+ if(argc < 3)
+ return 1;
+
+ file= argv[1];
+ url = argv[2];
+
+ /* get the file size of the local file */
+ hd = open(file, O_RDONLY) ;
+ fstat(hd, &file_info);
+ close(hd) ;
+
+ /* get a FILE * of the same file, could also be made with
+ fdopen() from the previous descriptor, but hey this is just
+ an example! */
+ hd_src = fopen(file, "rb");
+
+ /* In windows, this will init the winsock stuff */
+ curl_global_init(CURL_GLOBAL_ALL);
+
+ /* get a curl handle */
+ curl = curl_easy_init();
+ if(curl) {
+ /* we want to use our own read function */
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+
+ /* enable uploading */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
+
+ /* HTTP PUT please */
+ curl_easy_setopt(curl, CURLOPT_PUT, TRUE);
+
+ /* specify target */
+ curl_easy_setopt(curl,CURLOPT_URL, url);
+
+ /* now specify which file to upload */
+ curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
+
+ /* and give the size of the upload (optional) */
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size);
+
+ /* Now run off and do what you've been told! */
+ res = curl_easy_perform(curl);
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+ fclose(hd_src); /* close the local file */
+
+ curl_global_cleanup();
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/multithread.c b/Utilities/cmcurl/Testing/multithread.c
new file mode 100644
index 0000000000..c3936ef4a9
--- /dev/null
+++ b/Utilities/cmcurl/Testing/multithread.c
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+/* A multi-threaded example that uses pthreads extensively to fetch
+ * X remote files at once */
+
+#include <stdio.h>
+#include <pthread.h>
+#include <curl/curl.h>
+
+/* silly list of test-URLs */
+char *urls[]= {
+ "http://curl.haxx.se/",
+ "ftp://cool.haxx.se/",
+ "http://www.contactor.se/",
+ "www.haxx.se"
+};
+
+void *pull_one_url(void *url)
+{
+ CURL *curl;
+
+ curl = curl_easy_init();
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_perform(curl);
+
+ curl_easy_cleanup(curl);
+
+ return NULL;
+}
+
+
+/*
+ int pthread_create(pthread_t *new_thread_ID,
+ const pthread_attr_t *attr,
+ void * (*start_func)(void *), void *arg);
+*/
+
+int main(int argc, char **argv)
+{
+ pthread_t tid[4];
+ int i;
+ int error;
+ for(i=0; i< 4; i++) {
+ error = pthread_create(&tid[i],
+ NULL, /* default attributes please */
+ pull_one_url,
+ urls[i]);
+ if(0 != error)
+ fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
+ else
+ fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]);
+ }
+
+ /* now wait for all threads to terminate */
+ for(i=0; i< 4; i++) {
+ error = pthread_join(tid[i], NULL);
+ fprintf(stderr, "Thread %d terminated\n", i);
+ }
+
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/persistant.c b/Utilities/cmcurl/Testing/persistant.c
new file mode 100644
index 0000000000..8534703456
--- /dev/null
+++ b/Utilities/cmcurl/Testing/persistant.c
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+
+#include "curl/curl.h"
+
+/* to make this work under windows, use the win32-functions from the
+ docs/examples/win32socket.c file as well */
+
+/* This example REQUIRES libcurl 7.7 or later */
+#if (LIBCURL_VERSION_NUM < 0x070700)
+#error Too old libcurl version, upgrade or stay away.
+#endif
+
+int main(int argc, char **argv)
+{
+ CURL *curl;
+ CURLcode res;
+
+#ifdef MALLOCDEBUG
+ /* this sends all memory debug messages to a specified logfile */
+ curl_memdebug("memdump");
+#endif
+
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+ curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ curl_easy_setopt(curl, CURLOPT_HEADER, 1);
+
+ /* get the first document */
+ curl_easy_setopt(curl, CURLOPT_URL, "http://www.cmake.org/");
+ res = curl_easy_perform(curl);
+
+ /* get another document from the same server using the same
+ connection */
+ curl_easy_setopt(curl, CURLOPT_URL, "http://www.cmake.org/HTML/Index.html");
+ res = curl_easy_perform(curl);
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/postit2.c b/Utilities/cmcurl/Testing/postit2.c
new file mode 100644
index 0000000000..9b7cda07ec
--- /dev/null
+++ b/Utilities/cmcurl/Testing/postit2.c
@@ -0,0 +1,92 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ *
+ * Example code that uploads a file name 'foo' to a remote script that accepts
+ * "HTML form based" (as described in RFC1738) uploads using HTTP POST.
+ *
+ * The imaginary form we'll fill in looks like:
+ *
+ * <form method="post" enctype="multipart/form-data" action="examplepost.cgi">
+ * Enter file: <input type="file" name="sendfile" size="40">
+ * Enter file name: <input type="text" name="filename" size="30">
+ * <input type="submit" value="send" name="submit">
+ * </form>
+ *
+ * This exact source code has not been verified to work.
+ */
+
+/* to make this work under windows, use the win32-functions from the
+ win32socket.c file as well */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <curl/curl.h>
+#include <curl/types.h>
+#include <curl/easy.h>
+
+#if LIBCURL_VERSION_NUM < 0x070900
+#error "curl_formadd() is not introduced until libcurl 7.9 and later"
+#endif
+
+int main(int argc, char *argv[])
+{
+ CURL *curl;
+ CURLcode res;
+
+ struct HttpPost *formpost=NULL;
+ struct HttpPost *lastptr=NULL;
+ struct curl_slist *headerlist=NULL;
+ char buf[] = "Expect:";
+
+ /* Fill in the file upload field */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "sendfile",
+ CURLFORM_FILE, "postit2.c",
+ CURLFORM_END);
+
+ /* Fill in the filename field */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "filename",
+ CURLFORM_COPYCONTENTS, "postit2.c",
+ CURLFORM_END);
+
+
+ /* Fill in the submit field too, even if this is rarely needed */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "submit",
+ CURLFORM_COPYCONTENTS, "send",
+ CURLFORM_END);
+
+ curl = curl_easy_init();
+ /* initalize custom header list (stating that Expect: 100-continue is not
+ wanted */
+ headerlist = curl_slist_append(headerlist, buf);
+ if(curl) {
+ /* what URL that receives this POST */
+ curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi");
+ if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) )
+ /* only disable 100-continue header if explicitly requested */
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
+ curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
+ res = curl_easy_perform(curl);
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+
+ /* then cleanup the formpost chain */
+ curl_formfree(formpost);
+ /* free slist */
+ curl_slist_free_all (headerlist);
+ }
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/sepheaders.c b/Utilities/cmcurl/Testing/sepheaders.c
new file mode 100644
index 0000000000..fc5b783bc1
--- /dev/null
+++ b/Utilities/cmcurl/Testing/sepheaders.c
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+/* to make this work under windows, use the win32-functions from the
+ win32socket.c file as well */
+
+#include "curl/curl.h"
+#include "curl/types.h"
+#include "curl/easy.h"
+
+#include "testconfig.h"
+
+size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
+{
+ int written = fwrite(ptr, size, nmemb, (FILE *)stream);
+ return written;
+}
+
+int main(int argc, char **argv)
+{
+ CURL *curl_handle;
+ char *headerfilename = LIBCURL_BINARY_DIR "/Testing/sepheaders-head.out";
+ FILE *headerfile;
+ char *bodyfilename = LIBCURL_BINARY_DIR "/Testing/sepheaders-body.out";
+ FILE *bodyfile;
+
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+ /* init the curl session */
+ curl_handle = curl_easy_init();
+
+ /* set URL to get */
+ curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.cmake.org/HTML/Index.html");
+
+ /* no progress meter please */
+ curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
+
+ /* shut up completely */
+ //curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);
+
+ /* send all data to this function */
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
+
+ /* open the files */
+ headerfile = fopen(headerfilename,"w");
+ if (headerfile == NULL) {
+ curl_easy_cleanup(curl_handle);
+ return -1;
+ }
+ bodyfile = fopen(bodyfilename,"w");
+ if (bodyfile == NULL) {
+ curl_easy_cleanup(curl_handle);
+ fclose(headerfile);
+ return -1;
+ }
+
+ /* we want the headers to this file handle */
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER ,headerfile);
+
+ /* we want the body to this file handle */
+ curl_easy_setopt(curl_handle, CURLOPT_FILE ,bodyfile);
+
+ /* get it! */
+ curl_easy_perform(curl_handle);
+
+ /* close the header file */
+ fclose(headerfile);
+ fclose(bodyfile);
+
+ /* cleanup curl stuff */
+ curl_easy_cleanup(curl_handle);
+
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/simple.c b/Utilities/cmcurl/Testing/simple.c
new file mode 100644
index 0000000000..6dd6050ec8
--- /dev/null
+++ b/Utilities/cmcurl/Testing/simple.c
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+#include "curl/curl.h"
+
+int main(void)
+{
+ CURL *curl;
+ CURLcode res;
+
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+ curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "http://www.cmake.org/HTML/Index.html");
+ res = curl_easy_perform(curl);
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/simplessl.c b/Utilities/cmcurl/Testing/simplessl.c
new file mode 100644
index 0000000000..e307eaa6fe
--- /dev/null
+++ b/Utilities/cmcurl/Testing/simplessl.c
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+
+#include <curl/curl.h>
+#include <curl/types.h>
+#include <curl/easy.h>
+
+
+/* some requirements for this to work:
+ 1. set pCertFile to the file with the client certificate
+ 2. if the key is passphrase protected, set pPassphrase to the
+ passphrase you use
+ 3. if you are using a crypto engine:
+ 3.1. set a #define USE_ENGINE
+ 3.2. set pEngine to the name of the crypto engine you use
+ 3.3. set pKeyName to the key identifier you want to use
+ 4. if you don't use a crypto engine:
+ 4.1. set pKeyName to the file name of your client key
+ 4.2. if the format of the key file is DER, set pKeyType to "DER"
+
+ !! verify of the server certificate is not implemented here !!
+
+ **** This example only works with libcurl 7.9.3 and later! ****
+
+*/
+
+int main(int argc, char **argv)
+{
+ CURL *curl;
+ CURLcode res;
+ FILE *headerfile;
+
+ const char *pCertFile = "testcert.pem";
+ const char *pCACertFile="cacert.pem"
+
+ const char *pKeyName;
+ const char *pKeyType;
+
+ const char *pEngine;
+
+#if USE_ENGINE
+ pKeyName = "rsa_test";
+ pKeyType = "ENG";
+ pEngine = "chil"; /* for nChiper HSM... */
+#else
+ pKeyName = "testkey.pem";
+ pKeyType = "PEM";
+ pEngine = NULL;
+#endif
+
+ const char *pPassphrase = NULL;
+
+ headerfile = fopen("dumpit", "w");
+
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+
+ curl = curl_easy_init();
+ if(curl) {
+ /* what call to write: */
+ curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://curl.haxx.se");
+ curl_easy_setopt(curl, CURLOPT_WRITEHEADER, headerfile);
+
+ while(1) /* do some ugly short cut... */
+ {
+ if (pEngine) /* use crypto engine */
+ {
+ if (curl_easy_setopt(curl, CURLOPT_SSLENGINE,pEngine) != CURLE_OK)
+ { /* load the crypto engine */
+ fprintf(stderr,"can't set crypto engine\n");
+ break;
+ }
+ if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT,1) != CURLE_OK)
+ { /* set the crypto engine as default */
+ /* only needed for the first time you load
+ a engine in a curl object... */
+ fprintf(stderr,"can't set crypto engine as default\n");
+ break;
+ }
+ }
+ /* cert is stored PEM coded in file... */
+ /* since PEM is default, we needn't set it for PEM */
+ curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");
+ /* set the cert for client authentication */
+ curl_easy_setopt(curl,CURLOPT_SSLCERT,pCertFile);
+ /* sorry, for engine we must set the passphrase
+ (if the key has one...) */
+ if (pPassphrase)
+ curl_easy_setopt(curl,CURLOPT_SSLKEYPASSWD,pPassphrase);
+ /* if we use a key stored in a crypto engine,
+ we must set the key type to "ENG" */
+ curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,pKeyType);
+ /* set the private key (file or ID in engine) */
+ curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName);
+ /* set the file with the certs vaildating the server */
+ curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile);
+ /* disconnect if we can't validate server's cert */
+ curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1);
+
+ res = curl_easy_perform(curl);
+ break; /* we are done... */
+ }
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+
+ curl_global_cleanup();
+
+ if (headerfile)
+ fclose(headerfile);
+ return 0;
+}
diff --git a/Utilities/cmcurl/Testing/testconfig.h.in b/Utilities/cmcurl/Testing/testconfig.h.in
new file mode 100644
index 0000000000..faab462239
--- /dev/null
+++ b/Utilities/cmcurl/Testing/testconfig.h.in
@@ -0,0 +1,7 @@
+#ifndef __testconfig_h__
+#define __testconfig_h__
+
+#define LIBCURL_SOURCE_DIR "${LIBCURL_SOURCE_DIR}"
+#define LIBCURL_BINARY_DIR "${LIBCURL_BINARY_DIR}"
+
+#endif /* __testconfig_h__ */
diff --git a/Utilities/cmcurl/Testing/win32sockets.c b/Utilities/cmcurl/Testing/win32sockets.c
new file mode 100644
index 0000000000..5f791c8b5e
--- /dev/null
+++ b/Utilities/cmcurl/Testing/win32sockets.c
@@ -0,0 +1,49 @@
+
+/*
+ * Note: This is only required if you use curl 7.8 or lower, later
+ * versions provide an option to curl_global_init() that does the
+ * win32 initialization for you.
+ */
+
+/*
+ * These are example functions doing socket init that Windows
+ * require. If you don't use windows, you can safely ignore this crap.
+ */
+
+#include <windows.h>
+
+void win32_cleanup(void)
+{
+ WSACleanup();
+}
+
+int win32_init(void)
+{
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ int err;
+ wVersionRequested = MAKEWORD(1, 1);
+
+ err = WSAStartup(wVersionRequested, &wsaData);
+
+ if (err != 0)
+ /* Tell the user that we couldn't find a useable */
+ /* winsock.dll. */
+ return 1;
+
+ /* Confirm that the Windows Sockets DLL supports 1.1.*/
+ /* Note that if the DLL supports versions greater */
+ /* than 1.1 in addition to 1.1, it will still return */
+ /* 1.1 in wVersion since that is the version we */
+ /* requested. */
+
+ if ( LOBYTE( wsaData.wVersion ) != 1 ||
+ HIBYTE( wsaData.wVersion ) != 1 ) {
+ /* Tell the user that we couldn't find a useable */
+
+ /* winsock.dll. */
+ WSACleanup();
+ return 1;
+ }
+ return 0; /* 0 is ok */
+}
diff --git a/Utilities/cmcurl/amigaos.c b/Utilities/cmcurl/amigaos.c
new file mode 100644
index 0000000000..7106f8daf6
--- /dev/null
+++ b/Utilities/cmcurl/amigaos.c
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "amigaos.h"
+#include <amitcp/socketbasetags.h>
+
+struct Library *SocketBase = NULL;
+extern int errno, h_errno;
+
+#ifdef __libnix__
+#include <stabs.h>
+void __request(const char *msg);
+#else
+# define __request( msg ) Printf( msg "\n\a")
+#endif
+
+void amiga_cleanup()
+{
+ if(SocketBase) {
+ CloseLibrary(SocketBase);
+ SocketBase = NULL;
+ }
+}
+
+BOOL amiga_init()
+{
+ if(!SocketBase)
+ SocketBase = OpenLibrary("bsdsocket.library", 4);
+
+ if(!SocketBase) {
+ __request("No TCP/IP Stack running!");
+ return FALSE;
+ }
+
+ if(SocketBaseTags(
+ SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (ULONG) &errno,
+// SBTM_SETVAL(SBTC_HERRNOLONGPTR), (ULONG) &h_errno,
+ SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG) "cURL",
+ TAG_DONE)) {
+
+ __request("SocketBaseTags ERROR");
+ return FALSE;
+ }
+
+#ifndef __libnix__
+ atexit(amiga_cleanup);
+#endif
+
+ return TRUE;
+}
+
+#ifdef __libnix__
+ADD2EXIT(amiga_cleanup,-50);
+#endif
diff --git a/Utilities/cmcurl/amigaos.h b/Utilities/cmcurl/amigaos.h
new file mode 100644
index 0000000000..e5786d4829
--- /dev/null
+++ b/Utilities/cmcurl/amigaos.h
@@ -0,0 +1,58 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifndef LIBCURL_AMIGAOS_H
+#define LIBCURL_AMIGAOS_H
+
+#ifndef __ixemul__
+
+#include <exec/types.h>
+#include <exec/execbase.h>
+
+#include <proto/exec.h>
+#include <proto/dos.h>
+
+#include <sys/socket.h>
+
+#include "config-amigaos.h"
+
+#ifndef select
+# define select(args...) WaitSelect( args, NULL)
+#endif
+#ifndef inet_ntoa
+# define inet_ntoa(x) Inet_NtoA( x ## .s_addr)
+#endif
+#ifndef ioctl
+# define ioctl(a,b,c,d) IoctlSocket( (LONG)a, (ULONG)b, (char*)c)
+#endif
+#define _AMIGASF 1
+
+extern void amiga_cleanup();
+extern BOOL amiga_init();
+
+#else /* __ixemul__ */
+
+#warning compiling with ixemul...
+
+#endif /* __ixemul__ */
+#endif /* LIBCURL_AMIGAOS_H */
diff --git a/Utilities/cmcurl/arpa_telnet.h b/Utilities/cmcurl/arpa_telnet.h
new file mode 100644
index 0000000000..e6a04dcefb
--- /dev/null
+++ b/Utilities/cmcurl/arpa_telnet.h
@@ -0,0 +1,101 @@
+#ifndef __ARPA_TELNET_H
+#define __ARPA_TELNET_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#ifndef CURL_DISABLE_TELNET
+/*
+ * Telnet option defines. Add more here if in need.
+ */
+#define CURL_TELOPT_BINARY 0 /* binary 8bit data */
+#define CURL_TELOPT_SGA 3 /* Supress Go Ahead */
+#define CURL_TELOPT_EXOPL 255 /* EXtended OPtions List */
+#define CURL_TELOPT_TTYPE 24 /* Terminal TYPE */
+#define CURL_TELOPT_XDISPLOC 35 /* X DISPlay LOCation */
+
+#define CURL_TELOPT_NEW_ENVIRON 39 /* NEW ENVIRONment variables */
+#define CURL_NEW_ENV_VAR 0
+#define CURL_NEW_ENV_VALUE 1
+
+/*
+ * The telnet options represented as strings
+ */
+static const char * const telnetoptions[]=
+{
+ "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD",
+ "NAME", "STATUS", "TIMING MARK", "RCTE",
+ "NAOL", "NAOP", "NAOCRD", "NAOHTS",
+ "NAOHTD", "NAOFFD", "NAOVTS", "NAOVTD",
+ "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
+ "DE TERMINAL", "SUPDUP", "SUPDUP OUTPUT", "SEND LOCATION",
+ "TERM TYPE", "END OF RECORD", "TACACS UID", "OUTPUT MARKING",
+ "TTYLOC", "3270 REGIME", "X3 PAD", "NAWS",
+ "TERM SPEED", "LFLOW", "LINEMODE", "XDISPLOC",
+ "OLD-ENVIRON", "AUTHENTICATION", "ENCRYPT", "NEW-ENVIRON"
+};
+
+#define CURL_TELOPT_MAXIMUM CURL_TELOPT_NEW_ENVIRON
+
+#define CURL_TELOPT_OK(x) ((x) <= CURL_TELOPT_MAXIMUM)
+#define CURL_TELOPT(x) telnetoptions[x]
+
+#define CURL_NTELOPTS 40
+
+/*
+ * First some defines
+ */
+#define CURL_xEOF 236 /* End Of File */
+#define CURL_SE 240 /* Sub negotiation End */
+#define CURL_NOP 241 /* No OPeration */
+#define CURL_DM 242 /* Data Mark */
+#define CURL_GA 249 /* Go Ahead, reverse the line */
+#define CURL_SB 250 /* SuBnegotiation */
+#define CURL_WILL 251 /* Our side WILL use this option */
+#define CURL_WONT 252 /* Our side WON'T use this option */
+#define CURL_DO 253 /* DO use this option! */
+#define CURL_DONT 254 /* DON'T use this option! */
+#define CURL_IAC 255 /* Interpret As Command */
+
+/*
+ * Then those numbers represented as strings:
+ */
+static const char * const telnetcmds[]=
+{
+ "EOF", "SUSP", "ABORT", "EOR", "SE",
+ "NOP", "DMARK", "BRK", "IP", "AO",
+ "AYT", "EC", "EL", "GA", "SB",
+ "WILL", "WONT", "DO", "DONT", "IAC"
+};
+
+#define CURL_TELCMD_MINIMUM CURL_xEOF /* the first one */
+#define CURL_TELCMD_MAXIMUM CURL_IAC /* surprise, 255 is the last one! ;-) */
+
+#define CURL_TELQUAL_IS 0
+#define CURL_TELQUAL_SEND 1
+#define CURL_TELQUAL_INFO 2
+#define CURL_TELQUAL_NAME 3
+
+#define CURL_TELCMD_OK(x) ( ((unsigned int)(x) >= CURL_TELCMD_MINIMUM) && \
+ ((unsigned int)(x) <= CURL_TELCMD_MAXIMUM) )
+#define CURL_TELCMD(x) telnetcmds[(x)-CURL_TELCMD_MINIMUM]
+#endif
+#endif
diff --git a/Utilities/cmcurl/base64.c b/Utilities/cmcurl/base64.c
new file mode 100644
index 0000000000..aa03f83462
--- /dev/null
+++ b/Utilities/cmcurl/base64.c
@@ -0,0 +1,366 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/* Base64 encoding/decoding
+ *
+ * Test harnesses down the bottom - compile with -DTEST_ENCODE for
+ * a program that will read in raw data from stdin and write out
+ * a base64-encoded version to stdout, and the length returned by the
+ * encoding function to stderr. Compile with -DTEST_DECODE for a program that
+ * will go the other way.
+ *
+ * This code will break if int is smaller than 32 bits
+ */
+
+#include "setup.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#include "urldata.h" /* for the SessionHandle definition */
+#include "easyif.h" /* for Curl_convert_... prototypes */
+#include "base64.h"
+#include "memory.h"
+
+/* include memdebug.h last */
+#include "memdebug.h"
+
+/* ---- Base64 Encoding/Decoding Table --- */
+static const char table64[]=
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static void decodeQuantum(unsigned char *dest, const char *src)
+{
+ unsigned int x = 0;
+ int i;
+ char *found;
+
+ for(i = 0; i < 4; i++) {
+ if((found = strchr(table64, src[i])))
+ x = (x << 6) + (unsigned int)(found - table64);
+ else if(src[i] == '=')
+ x = (x << 6);
+ }
+
+ dest[2] = (unsigned char)(x & 255);
+ x >>= 8;
+ dest[1] = (unsigned char)(x & 255);
+ x >>= 8;
+ dest[0] = (unsigned char)(x & 255);
+}
+
+/*
+ * Curl_base64_decode()
+ *
+ * Given a base64 string at src, decode it and return an allocated memory in
+ * the *outptr. Returns the length of the decoded data.
+ */
+size_t Curl_base64_decode(const char *src, unsigned char **outptr)
+{
+ int length = 0;
+ int equalsTerm = 0;
+ int i;
+ int numQuantums;
+ unsigned char lastQuantum[3];
+ size_t rawlen=0;
+ unsigned char *newstr;
+
+ *outptr = NULL;
+
+ while((src[length] != '=') && src[length])
+ length++;
+ /* A maximum of two = padding characters is allowed */
+ if(src[length] == '=') {
+ equalsTerm++;
+ if(src[length+equalsTerm] == '=')
+ equalsTerm++;
+ }
+ numQuantums = (length + equalsTerm) / 4;
+
+ /* Don't allocate a buffer if the decoded length is 0 */
+ if (numQuantums <= 0)
+ return 0;
+
+ rawlen = (numQuantums * 3) - equalsTerm;
+
+ /* The buffer must be large enough to make room for the last quantum
+ (which may be partially thrown out) and the zero terminator. */
+ newstr = malloc(rawlen+4);
+ if(!newstr)
+ return 0;
+
+ *outptr = newstr;
+
+ /* Decode all but the last quantum (which may not decode to a
+ multiple of 3 bytes) */
+ for(i = 0; i < numQuantums - 1; i++) {
+ decodeQuantum((unsigned char *)newstr, src);
+ newstr += 3; src += 4;
+ }
+
+ /* This final decode may actually read slightly past the end of the buffer
+ if the input string is missing pad bytes. This will almost always be
+ harmless. */
+ decodeQuantum(lastQuantum, src);
+ for(i = 0; i < 3 - equalsTerm; i++)
+ newstr[i] = lastQuantum[i];
+
+ newstr[i] = 0; /* zero terminate */
+ return rawlen;
+}
+
+/*
+ * Curl_base64_encode()
+ *
+ * Returns the length of the newly created base64 string. The third argument
+ * is a pointer to an allocated area holding the base64 data. If something
+ * went wrong, -1 is returned.
+ *
+ */
+size_t Curl_base64_encode(struct SessionHandle *data,
+ const char *inp, size_t insize, char **outptr)
+{
+ unsigned char ibuf[3];
+ unsigned char obuf[4];
+ int i;
+ int inputparts;
+ char *output;
+ char *base64data;
+#ifdef CURL_DOES_CONVERSIONS
+ char *convbuf;
+#endif
+
+ char *indata = (char *)inp;
+
+ *outptr = NULL; /* set to NULL in case of failure before we reach the end */
+
+ if(0 == insize)
+ insize = strlen(indata);
+
+ base64data = output = (char*)malloc(insize*4/3+4);
+ if(NULL == output)
+ return 0;
+
+#ifdef CURL_DOES_CONVERSIONS
+ /*
+ * The base64 data needs to be created using the network encoding
+ * not the host encoding. And we can't change the actual input
+ * so we copy it to a buffer, translate it, and use that instead.
+ */
+ if(data) {
+ convbuf = (char*)malloc(insize);
+ if(!convbuf) {
+ return 0;
+ }
+ memcpy(convbuf, indata, insize);
+ if(CURLE_OK != Curl_convert_to_network(data, convbuf, insize)) {
+ free(convbuf);
+ return 0;
+ }
+ indata = convbuf; /* switch to the converted buffer */
+ }
+#else
+ (void)data;
+#endif
+
+ while(insize > 0) {
+ for (i = inputparts = 0; i < 3; i++) {
+ if(insize > 0) {
+ inputparts++;
+ ibuf[i] = *indata;
+ indata++;
+ insize--;
+ }
+ else
+ ibuf[i] = 0;
+ }
+
+ obuf[0] = (unsigned char) ((ibuf[0] & 0xFC) >> 2);
+ obuf[1] = (unsigned char) (((ibuf[0] & 0x03) << 4) | \
+ ((ibuf[1] & 0xF0) >> 4));
+ obuf[2] = (unsigned char) (((ibuf[1] & 0x0F) << 2) | \
+ ((ibuf[2] & 0xC0) >> 6));
+ obuf[3] = (unsigned char) (ibuf[2] & 0x3F);
+
+ switch(inputparts) {
+ case 1: /* only one byte read */
+ snprintf(output, 5, "%c%c==",
+ table64[obuf[0]],
+ table64[obuf[1]]);
+ break;
+ case 2: /* two bytes read */
+ snprintf(output, 5, "%c%c%c=",
+ table64[obuf[0]],
+ table64[obuf[1]],
+ table64[obuf[2]]);
+ break;
+ default:
+ snprintf(output, 5, "%c%c%c%c",
+ table64[obuf[0]],
+ table64[obuf[1]],
+ table64[obuf[2]],
+ table64[obuf[3]] );
+ break;
+ }
+ output += 4;
+ }
+ *output=0;
+ *outptr = base64data; /* make it return the actual data memory */
+
+#ifdef CURL_DOES_CONVERSIONS
+ if(data)
+ free(convbuf);
+#endif
+ return strlen(base64data); /* return the length of the new data */
+}
+/* ---- End of Base64 Encoding ---- */
+
+/************* TEST HARNESS STUFF ****************/
+
+
+#ifdef TEST_ENCODE
+/* encoding test harness. Read in standard input and write out the length
+ * returned by Curl_base64_encode, followed by the base64'd data itself
+ */
+#include <stdio.h>
+
+#define TEST_NEED_SUCK
+void *suck(int *);
+
+int main(int argc, char **argv, char **envp)
+{
+ char *base64;
+ size_t base64Len;
+ unsigned char *data;
+ int dataLen;
+ struct SessionHandle *handle = NULL;
+
+#ifdef CURL_DOES_CONVERSIONS
+ /* get a Curl handle so Curl_base64_encode can translate properly */
+ handle = curl_easy_init();
+ if(handle == NULL) {
+ fprintf(stderr, "Error: curl_easy_init failed\n");
+ return 0;
+ }
+#endif
+ data = (unsigned char *)suck(&dataLen);
+ base64Len = Curl_base64_encode(handle, data, dataLen, &base64);
+
+ fprintf(stderr, "%d\n", base64Len);
+ fprintf(stdout, "%s\n", base64);
+
+ free(base64); free(data);
+#ifdef CURL_DOES_CONVERSIONS
+ curl_easy_cleanup(handle);
+#endif
+ return 0;
+}
+#endif
+
+#ifdef TEST_DECODE
+/* decoding test harness. Read in a base64 string from stdin and write out the
+ * length returned by Curl_base64_decode, followed by the decoded data itself
+ *
+ * gcc -DTEST_DECODE base64.c -o base64 mprintf.o memdebug.o
+ */
+#include <stdio.h>
+
+#define TEST_NEED_SUCK
+void *suck(int *);
+
+int main(int argc, char **argv, char **envp)
+{
+ char *base64;
+ int base64Len;
+ unsigned char *data;
+ int dataLen;
+ int i, j;
+#ifdef CURL_DOES_CONVERSIONS
+ /* get a Curl handle so main can translate properly */
+ struct SessionHandle *handle = curl_easy_init();
+ if(handle == NULL) {
+ fprintf(stderr, "Error: curl_easy_init failed\n");
+ return 0;
+ }
+#endif
+
+ base64 = (char *)suck(&base64Len);
+ dataLen = Curl_base64_decode(base64, &data);
+
+ fprintf(stderr, "%d\n", dataLen);
+
+ for(i=0; i < dataLen; i+=0x10) {
+ printf("0x%02x: ", i);
+ for(j=0; j < 0x10; j++)
+ if((j+i) < dataLen)
+ printf("%02x ", data[i+j]);
+ else
+ printf(" ");
+
+ printf(" | ");
+
+ for(j=0; j < 0x10; j++)
+ if((j+i) < dataLen) {
+#ifdef CURL_DOES_CONVERSIONS
+ if(CURLE_OK !=
+ Curl_convert_from_network(handle, &data[i+j], (size_t)1))
+ data[i+j] = '.';
+#endif /* CURL_DOES_CONVERSIONS */
+ printf("%c", ISGRAPH(data[i+j])?data[i+j]:'.');
+ } else
+ break;
+ puts("");
+ }
+
+#ifdef CURL_DOES_CONVERSIONS
+ curl_easy_cleanup(handle);
+#endif
+ free(base64); free(data);
+ return 0;
+}
+#endif
+
+#ifdef TEST_NEED_SUCK
+/* this function 'sucks' in as much as possible from stdin */
+void *suck(int *lenptr)
+{
+ int cursize = 8192;
+ unsigned char *buf = NULL;
+ int lastread;
+ int len = 0;
+
+ do {
+ cursize *= 2;
+ buf = (unsigned char *)realloc(buf, cursize);
+ memset(buf + len, 0, cursize - len);
+ lastread = fread(buf + len, 1, cursize - len, stdin);
+ len += lastread;
+ } while(!feof(stdin));
+
+ lenptr[0] = len;
+ return (void *)buf;
+}
+#endif
diff --git a/Utilities/cmcurl/base64.h b/Utilities/cmcurl/base64.h
new file mode 100644
index 0000000000..59742bcd3a
--- /dev/null
+++ b/Utilities/cmcurl/base64.h
@@ -0,0 +1,28 @@
+#ifndef __BASE64_H
+#define __BASE64_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+size_t Curl_base64_encode(struct SessionHandle *data,
+ const char *input, size_t size, char **str);
+size_t Curl_base64_decode(const char *source, unsigned char **outptr);
+#endif
diff --git a/Utilities/cmcurl/ca-bundle.h b/Utilities/cmcurl/ca-bundle.h
new file mode 100644
index 0000000000..12390bc7b9
--- /dev/null
+++ b/Utilities/cmcurl/ca-bundle.h
@@ -0,0 +1 @@
+/* ca bundle path set in here*/
diff --git a/Utilities/cmcurl/config.h.in b/Utilities/cmcurl/config.h.in
new file mode 100644
index 0000000000..148722b2fc
--- /dev/null
+++ b/Utilities/cmcurl/config.h.in
@@ -0,0 +1,720 @@
+/* lib/config.h.in. Generated from configure.ac by autoheader. */
+
+/* when building libcurl itself */
+#cmakedefine BUILDING_LIBCURL ${BUILDING_LIBCURL}
+
+/* to disable cookies support */
+#cmakedefine CURL_DISABLE_COOKIES ${CURL_DISABLE_COOKIES}
+
+/* to disable cryptographic authentication */
+#cmakedefine CURL_DISABLE_CRYPTO_AUTH ${CURL_DISABLE_CRYPTO_AUTH}
+
+/* to disable DICT */
+#cmakedefine CURL_DISABLE_DICT ${CURL_DISABLE_DICT}
+
+/* to disable FILE */
+#cmakedefine CURL_DISABLE_FILE ${CURL_DISABLE_FILE}
+
+/* to disable FTP */
+#cmakedefine CURL_DISABLE_FTP ${CURL_DISABLE_FTP}
+
+/* to disable HTTP */
+#cmakedefine CURL_DISABLE_HTTP ${CURL_DISABLE_HTTP}
+
+/* to disable LDAP */
+#cmakedefine CURL_DISABLE_LDAP ${CURL_DISABLE_LDAP}
+
+/* to disable TELNET */
+#cmakedefine CURL_DISABLE_TELNET ${CURL_DISABLE_TELNET}
+
+/* to disable TFTP */
+#cmakedefine CURL_DISABLE_TFTP ${CURL_DISABLE_TFTP}
+
+/* to disable verbose strings */
+#cmakedefine CURL_DISABLE_VERBOSE_STRINGS ${CURL_DISABLE_VERBOSE_STRINGS}
+
+/* to make a symbol visible */
+#cmakedefine CURL_EXTERN_SYMBOL ${CURL_EXTERN_SYMBOL}
+
+/* to enable hidden symbols */
+#cmakedefine CURL_HIDDEN_SYMBOLS ${CURL_HIDDEN_SYMBOLS}
+
+/* when not building a shared library */
+#cmakedefine CURL_STATICLIB ${CURL_STATICLIB}
+
+/* Set to explicitly specify we don't want to use thread-safe functions */
+#cmakedefine DISABLED_THREADSAFE ${DISABLED_THREADSAFE}
+
+/* lber dynamic library file */
+#cmakedefine DL_LBER_FILE ${DL_LBER_FILE}
+
+/* ldap dynamic library file */
+#cmakedefine DL_LDAP_FILE ${DL_LDAP_FILE}
+
+/* your Entropy Gathering Daemon socket pathname */
+#cmakedefine EGD_SOCKET ${EGD_SOCKET}
+
+/* Define if you want to enable IPv6 support */
+#cmakedefine ENABLE_IPV6 ${ENABLE_IPV6}
+
+/* Define to the type qualifier of arg 1 for getnameinfo. */
+#cmakedefine GETNAMEINFO_QUAL_ARG1 ${GETNAMEINFO_QUAL_ARG1}
+
+/* Define to the type of arg 1 for getnameinfo. */
+#cmakedefine GETNAMEINFO_TYPE_ARG1 ${GETNAMEINFO_TYPE_ARG1}
+
+/* Define to the type of arg 2 for getnameinfo. */
+#cmakedefine GETNAMEINFO_TYPE_ARG2 ${GETNAMEINFO_TYPE_ARG2}
+
+/* Define to the type of args 4 and 6 for getnameinfo. */
+#cmakedefine GETNAMEINFO_TYPE_ARG46 ${GETNAMEINFO_TYPE_ARG46}
+
+/* Define to the type of arg 7 for getnameinfo. */
+#cmakedefine GETNAMEINFO_TYPE_ARG7 ${GETNAMEINFO_TYPE_ARG7}
+
+/* Define to 1 if you have the <alloca.h> header file. */
+#cmakedefine HAVE_ALLOCA_H ${HAVE_ALLOCA_H}
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#cmakedefine HAVE_ARPA_INET_H ${HAVE_ARPA_INET_H}
+
+/* Define to 1 if you have the <arpa/tftp.h> header file. */
+#cmakedefine HAVE_ARPA_TFTP_H ${HAVE_ARPA_TFTP_H}
+
+/* Define to 1 if you have the <assert.h> header file. */
+#cmakedefine HAVE_ASSERT_H ${HAVE_ASSERT_H}
+
+/* Define to 1 if you have the `basename' function. */
+#cmakedefine HAVE_BASENAME ${HAVE_BASENAME}
+
+/* Define to 1 if you have the `closesocket' function. */
+#cmakedefine HAVE_CLOSESOCKET ${HAVE_CLOSESOCKET}
+
+/* Define to 1 if you have the `CRYPTO_cleanup_all_ex_data' function. */
+#cmakedefine HAVE_CRYPTO_CLEANUP_ALL_EX_DATA ${HAVE_CRYPTO_CLEANUP_ALL_EX_DATA}
+
+/* Define to 1 if you have the <crypto.h> header file. */
+#cmakedefine HAVE_CRYPTO_H ${HAVE_CRYPTO_H}
+
+/* Define to 1 if you have the <des.h> header file. */
+#cmakedefine HAVE_DES_H ${HAVE_DES_H}
+
+/* disabled non-blocking sockets */
+#cmakedefine HAVE_DISABLED_NONBLOCKING ${HAVE_DISABLED_NONBLOCKING}
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H}
+
+/* Define to 1 if you have the `dlopen' function. */
+#cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN}
+
+/* Define to 1 if you have the `ENGINE_load_builtin_engines' function. */
+#cmakedefine HAVE_ENGINE_LOAD_BUILTIN_ENGINES ${HAVE_ENGINE_LOAD_BUILTIN_ENGINES}
+
+/* Define to 1 if you have the <errno.h> header file. */
+#cmakedefine HAVE_ERRNO_H ${HAVE_ERRNO_H}
+
+/* Define to 1 if you have the <err.h> header file. */
+#cmakedefine HAVE_ERR_H ${HAVE_ERR_H}
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#cmakedefine HAVE_FCNTL_H ${HAVE_FCNTL_H}
+
+/* use FIONBIO for non-blocking sockets */
+#cmakedefine HAVE_FIONBIO ${HAVE_FIONBIO}
+
+/* Define to 1 if you have the `fork' function. */
+#cmakedefine HAVE_FORK ${HAVE_FORK}
+
+/* Define to 1 if you have the `ftruncate' function. */
+#cmakedefine HAVE_FTRUNCATE ${HAVE_FTRUNCATE}
+
+/* Define if getaddrinfo exists and works */
+#cmakedefine HAVE_GETADDRINFO ${HAVE_GETADDRINFO}
+
+/* Define to 1 if you have the `geteuid' function. */
+#cmakedefine HAVE_GETEUID ${HAVE_GETEUID}
+
+/* Define to 1 if you have the `gethostbyaddr' function. */
+#cmakedefine HAVE_GETHOSTBYADDR ${HAVE_GETHOSTBYADDR}
+
+/* If you have gethostbyname */
+#cmakedefine HAVE_GETHOSTBYNAME ${HAVE_GETHOSTBYNAME}
+
+/* Define to 1 if you have the `gethostbyname_r' function. */
+#cmakedefine HAVE_GETHOSTBYNAME_R ${HAVE_GETHOSTBYNAME_R}
+
+/* gethostbyname_r() takes 3 args */
+#cmakedefine HAVE_GETHOSTBYNAME_R_3 ${HAVE_GETHOSTBYNAME_R_3}
+
+/* gethostbyname_r() takes 5 args */
+#cmakedefine HAVE_GETHOSTBYNAME_R_5 ${HAVE_GETHOSTBYNAME_R_5}
+
+/* gethostbyname_r() takes 6 args */
+#cmakedefine HAVE_GETHOSTBYNAME_R_6 ${HAVE_GETHOSTBYNAME_R_6}
+
+/* Define to 1 if you have the getnameinfo function. */
+#cmakedefine HAVE_GETNAMEINFO ${HAVE_GETNAMEINFO}
+
+/* Define to 1 if you have the `getpass_r' function. */
+#cmakedefine HAVE_GETPASS_R ${HAVE_GETPASS_R}
+
+/* Define to 1 if you have the `getprotobyname' function. */
+#cmakedefine HAVE_GETPROTOBYNAME ${HAVE_GETPROTOBYNAME}
+
+/* Define to 1 if you have the `getpwuid' function. */
+#cmakedefine HAVE_GETPWUID ${HAVE_GETPWUID}
+
+/* Define to 1 if you have the `getrlimit' function. */
+#cmakedefine HAVE_GETRLIMIT ${HAVE_GETRLIMIT}
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#cmakedefine HAVE_GETTIMEOFDAY ${HAVE_GETTIMEOFDAY}
+
+/* Define to 1 if you have the `gmtime_r' function. */
+#cmakedefine HAVE_GMTIME_R ${HAVE_GMTIME_R}
+
+/* if you have the gssapi libraries */
+#cmakedefine HAVE_GSSAPI ${HAVE_GSSAPI}
+
+/* if you have the GNU gssapi libraries */
+#cmakedefine HAVE_GSSGNU ${HAVE_GSSGNU}
+
+/* if you have the Heimdal gssapi libraries */
+#cmakedefine HAVE_GSSHEIMDAL ${HAVE_GSSHEIMDAL}
+
+/* if you have the MIT gssapi libraries */
+#cmakedefine HAVE_GSSMIT ${HAVE_GSSMIT}
+
+/* Define to 1 if you have the `idna_strerror' function. */
+#cmakedefine HAVE_IDNA_STRERROR ${HAVE_IDNA_STRERROR}
+
+/* Define to 1 if you have the `idn_free' function. */
+#cmakedefine HAVE_IDN_FREE ${HAVE_IDN_FREE}
+
+/* Define to 1 if you have the <idn-free.h> header file. */
+#cmakedefine HAVE_IDN_FREE_H ${HAVE_IDN_FREE_H}
+
+/* Define to 1 if you have the `inet_addr' function. */
+#cmakedefine HAVE_INET_ADDR ${HAVE_INET_ADDR}
+
+/* Define to 1 if you have the `inet_ntoa' function. */
+#cmakedefine HAVE_INET_NTOA ${HAVE_INET_NTOA}
+
+/* Define to 1 if you have the `inet_ntoa_r' function. */
+#cmakedefine HAVE_INET_NTOA_R ${HAVE_INET_NTOA_R}
+
+/* inet_ntoa_r() is declared */
+#cmakedefine HAVE_INET_NTOA_R_DECL ${HAVE_INET_NTOA_R_DECL}
+
+/* Define to 1 if you have the `inet_pton' function. */
+#cmakedefine HAVE_INET_PTON ${HAVE_INET_PTON}
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#cmakedefine HAVE_INTTYPES_H ${HAVE_INTTYPES_H}
+
+/* use ioctlsocket() for non-blocking sockets */
+#cmakedefine HAVE_IOCTLSOCKET ${HAVE_IOCTLSOCKET}
+
+/* use Ioctlsocket() for non-blocking sockets */
+#cmakedefine HAVE_IOCTLSOCKET_CASE ${HAVE_IOCTLSOCKET_CASE}
+
+/* Define to 1 if you have the <io.h> header file. */
+#cmakedefine HAVE_IO_H ${HAVE_IO_H}
+
+/* if you have the Kerberos4 libraries (including -ldes) */
+#cmakedefine HAVE_KRB4 ${HAVE_KRB4}
+
+/* Define to 1 if you have the `krb_get_our_ip_for_realm' function. */
+#cmakedefine HAVE_KRB_GET_OUR_IP_FOR_REALM ${HAVE_KRB_GET_OUR_IP_FOR_REALM}
+
+/* Define to 1 if you have the <krb.h> header file. */
+#cmakedefine HAVE_KRB_H ${HAVE_KRB_H}
+
+/* Define to 1 if you have the `dl' library (-ldl). */
+#cmakedefine HAVE_LIBDL ${HAVE_LIBDL}
+
+/* Define to 1 if you have the <libgen.h> header file. */
+#cmakedefine HAVE_LIBGEN_H ${HAVE_LIBGEN_H}
+
+/* Define to 1 if you have the `idn' library (-lidn). */
+#cmakedefine HAVE_LIBIDN ${HAVE_LIBIDN}
+
+/* Define to 1 if you have the `resolv' library (-lresolv). */
+#cmakedefine HAVE_LIBRESOLV ${HAVE_LIBRESOLV}
+
+/* Define to 1 if you have the `resolve' library (-lresolve). */
+#cmakedefine HAVE_LIBRESOLVE ${HAVE_LIBRESOLVE}
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+#cmakedefine HAVE_LIBSOCKET ${HAVE_LIBSOCKET}
+
+/* Define to 1 if you have the `ssh2' library (-lssh2). */
+#cmakedefine HAVE_LIBSSH2 ${HAVE_LIBSSH2}
+
+/* Define to 1 if you have the <libssh2.h> header file. */
+#cmakedefine HAVE_LIBSSH2_H ${HAVE_LIBSSH2_H}
+
+/* if zlib is available */
+#cmakedefine HAVE_LIBZ ${HAVE_LIBZ}
+
+/* Define to 1 if you have the <limits.h> header file. */
+#cmakedefine HAVE_LIMITS_H ${HAVE_LIMITS_H}
+
+/* if your compiler supports LL */
+#cmakedefine HAVE_LL ${HAVE_LL}
+
+/* Define to 1 if you have the <locale.h> header file. */
+#cmakedefine HAVE_LOCALE_H ${HAVE_LOCALE_H}
+
+/* Define to 1 if you have the `localtime_r' function. */
+#cmakedefine HAVE_LOCALTIME_R ${HAVE_LOCALTIME_R}
+
+/* if your compiler supports long long */
+#cmakedefine HAVE_LONGLONG ${HAVE_LONGLONG}
+
+/* Define to 1 if you have the malloc.h header file. */
+#cmakedefine HAVE_MALLOC_H ${HAVE_MALLOC_H}
+
+/* Define to 1 if you have the <memory.h> header file. */
+#cmakedefine HAVE_MEMORY_H ${HAVE_MEMORY_H}
+
+/* Define to 1 if you have the MSG_NOSIGNAL flag. */
+#cmakedefine HAVE_MSG_NOSIGNAL ${HAVE_MSG_NOSIGNAL}
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#cmakedefine HAVE_NETDB_H ${HAVE_NETDB_H}
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#cmakedefine HAVE_NETINET_IN_H ${HAVE_NETINET_IN_H}
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+#cmakedefine HAVE_NETINET_TCP_H ${HAVE_NETINET_TCP_H}
+
+/* Define to 1 if you have the <net/if.h> header file. */
+#cmakedefine HAVE_NET_IF_H ${HAVE_NET_IF_H}
+
+/* Define to 1 if NI_WITHSCOPEID exists and works. */
+#cmakedefine HAVE_NI_WITHSCOPEID ${HAVE_NI_WITHSCOPEID}
+
+/* Defined if no inet_pton() prototype available */
+#cmakedefine HAVE_NO_INET_PTON_PROTO ${HAVE_NO_INET_PTON_PROTO}
+
+/* we have no strerror_r() proto */
+#cmakedefine HAVE_NO_STRERROR_R_DECL ${HAVE_NO_STRERROR_R_DECL}
+
+/* Define to 1 if you have the <openssl/crypto.h> header file. */
+#cmakedefine HAVE_OPENSSL_CRYPTO_H ${HAVE_OPENSSL_CRYPTO_H}
+
+/* Define to 1 if you have the <openssl/engine.h> header file. */
+#cmakedefine HAVE_OPENSSL_ENGINE_H ${HAVE_OPENSSL_ENGINE_H}
+
+/* Define to 1 if you have the <openssl/err.h> header file. */
+#cmakedefine HAVE_OPENSSL_ERR_H ${HAVE_OPENSSL_ERR_H}
+
+/* Define to 1 if you have the <openssl/pem.h> header file. */
+#cmakedefine HAVE_OPENSSL_PEM_H ${HAVE_OPENSSL_PEM_H}
+
+/* Define to 1 if you have the <openssl/pkcs12.h> header file. */
+#cmakedefine HAVE_OPENSSL_PKCS12_H ${HAVE_OPENSSL_PKCS12_H}
+
+/* Define to 1 if you have the <openssl/rsa.h> header file. */
+#cmakedefine HAVE_OPENSSL_RSA_H ${HAVE_OPENSSL_RSA_H}
+
+/* Define to 1 if you have the <openssl/ssl.h> header file. */
+#cmakedefine HAVE_OPENSSL_SSL_H ${HAVE_OPENSSL_SSL_H}
+
+/* Define to 1 if you have the <openssl/x509.h> header file. */
+#cmakedefine HAVE_OPENSSL_X509_H ${HAVE_OPENSSL_X509_H}
+
+/* use O_NONBLOCK for non-blocking sockets */
+#cmakedefine HAVE_O_NONBLOCK ${HAVE_O_NONBLOCK}
+
+/* Define to 1 if you have the <pem.h> header file. */
+#cmakedefine HAVE_PEM_H ${HAVE_PEM_H}
+
+/* Define to 1 if you have the `perror' function. */
+#cmakedefine HAVE_PERROR ${HAVE_PERROR}
+
+/* Define to 1 if you have the `pipe' function. */
+#cmakedefine HAVE_PIPE ${HAVE_PIPE}
+
+/* Define to 1 if you have the `poll' function. */
+#cmakedefine HAVE_POLL ${HAVE_POLL}
+
+/* Define to 1 if you have the <process.h> header file. */
+#cmakedefine HAVE_PROCESS_H ${HAVE_PROCESS_H}
+
+/* Define to 1 if you have the <pwd.h> header file. */
+#cmakedefine HAVE_PWD_H ${HAVE_PWD_H}
+
+/* Define to 1 if you have the `RAND_egd' function. */
+#cmakedefine HAVE_RAND_EGD ${HAVE_RAND_EGD}
+
+/* Define to 1 if you have the `RAND_screen' function. */
+#cmakedefine HAVE_RAND_SCREEN ${HAVE_RAND_SCREEN}
+
+/* Define to 1 if you have the `RAND_status' function. */
+#cmakedefine HAVE_RAND_STATUS ${HAVE_RAND_STATUS}
+
+/* Define to 1 if you have the recv function. */
+#cmakedefine HAVE_RECV ${HAVE_RECV}
+
+/* Define to 1 if you have the <rsa.h> header file. */
+#cmakedefine HAVE_RSA_H ${HAVE_RSA_H}
+
+/* Define to 1 if you have the select function. */
+#cmakedefine HAVE_SELECT ${HAVE_SELECT}
+
+/* Define to 1 if you have the send function. */
+#cmakedefine HAVE_SEND ${HAVE_SEND}
+
+/* Define to 1 if you have the <setjmp.h> header file. */
+#cmakedefine HAVE_SETJMP_H ${HAVE_SETJMP_H}
+
+/* Define to 1 if you have the `setlocale' function. */
+#cmakedefine HAVE_SETLOCALE ${HAVE_SETLOCALE}
+
+/* Define to 1 if you have the `setrlimit' function. */
+#cmakedefine HAVE_SETRLIMIT ${HAVE_SETRLIMIT}
+
+/* Define to 1 if you have the <sgtty.h> header file. */
+#cmakedefine HAVE_SGTTY_H ${HAVE_SGTTY_H}
+
+/* Define to 1 if you have the `sigaction' function. */
+#cmakedefine HAVE_SIGACTION ${HAVE_SIGACTION}
+
+/* Define to 1 if you have the `siginterrupt' function. */
+#cmakedefine HAVE_SIGINTERRUPT ${HAVE_SIGINTERRUPT}
+
+/* Define to 1 if you have the `signal' function. */
+#cmakedefine HAVE_SIGNAL ${HAVE_SIGNAL}
+
+/* Define to 1 if you have the <signal.h> header file. */
+#cmakedefine HAVE_SIGNAL_H ${HAVE_SIGNAL_H}
+
+/* If you have sigsetjmp */
+#cmakedefine HAVE_SIGSETJMP ${HAVE_SIGSETJMP}
+
+/* Define to 1 if sig_atomic_t is an available typedef. */
+#cmakedefine HAVE_SIG_ATOMIC_T ${HAVE_SIG_ATOMIC_T}
+
+/* Define to 1 if sig_atomic_t is already defined as volatile. */
+#cmakedefine HAVE_SIG_ATOMIC_T_VOLATILE ${HAVE_SIG_ATOMIC_T_VOLATILE}
+
+/* Define to 1 if you have the `socket' function. */
+#cmakedefine HAVE_SOCKET ${HAVE_SOCKET}
+
+/* use SO_NONBLOCK for non-blocking sockets */
+#cmakedefine HAVE_SO_NONBLOCK ${HAVE_SO_NONBLOCK}
+
+/* Define this if you have the SPNEGO library fbopenssl */
+#cmakedefine HAVE_SPNEGO ${HAVE_SPNEGO}
+
+/* Define to 1 if you have the <ssl.h> header file. */
+#cmakedefine HAVE_SSL_H ${HAVE_SSL_H}
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#cmakedefine HAVE_STDINT_H ${HAVE_STDINT_H}
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#cmakedefine HAVE_STDIO_H ${HAVE_STDIO_H}
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#cmakedefine HAVE_STDLIB_H ${HAVE_STDLIB_H}
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#cmakedefine HAVE_STRCASECMP ${HAVE_STRCASECMP}
+
+/* Define to 1 if you have the `strcmpi' function. */
+#cmakedefine HAVE_STRCMPI ${HAVE_STRCMPI}
+
+/* Define to 1 if you have the `strdup' function. */
+#cmakedefine HAVE_STRDUP ${HAVE_STRDUP}
+
+/* Define to 1 if you have the `stricmp' function. */
+#cmakedefine HAVE_STRICMP ${HAVE_STRICMP}
+
+/* Define to 1 if you have the <strings.h> header file. */
+#cmakedefine HAVE_STRINGS_H ${HAVE_STRINGS_H}
+
+/* Define to 1 if you have the <string.h> header file. */
+#cmakedefine HAVE_STRING_H ${HAVE_STRING_H}
+
+/* Define to 1 if you have the `strlcpy' function. */
+#cmakedefine HAVE_STRLCPY ${HAVE_STRLCPY}
+
+/* Define to 1 if you have the `strstr' function. */
+#cmakedefine HAVE_STRSTR ${HAVE_STRSTR}
+
+/* Define to 1 if you have the `strtok_r' function. */
+#cmakedefine HAVE_STRTOK_R ${HAVE_STRTOK_R}
+
+/* Define to 1 if you have the `strtoll' function. */
+#cmakedefine HAVE_STRTOLL ${HAVE_STRTOLL}
+
+/* if struct sockaddr_storage is defined */
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE ${HAVE_STRUCT_SOCKADDR_STORAGE}
+
+/* Define to 1 if you have the timeval struct. */
+#cmakedefine HAVE_STRUCT_TIMEVAL ${HAVE_STRUCT_TIMEVAL}
+
+/* Define to 1 if you have the <sys/filio.h> header file. */
+#cmakedefine HAVE_SYS_FILIO_H ${HAVE_SYS_FILIO_H}
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H}
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#cmakedefine HAVE_SYS_PARAM_H ${HAVE_SYS_PARAM_H}
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#cmakedefine HAVE_SYS_POLL_H ${HAVE_SYS_POLL_H}
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#cmakedefine HAVE_SYS_RESOURCE_H ${HAVE_SYS_RESOURCE_H}
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#cmakedefine HAVE_SYS_SELECT_H ${HAVE_SYS_SELECT_H}
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#cmakedefine HAVE_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H}
+
+/* Define to 1 if you have the <sys/sockio.h> header file. */
+#cmakedefine HAVE_SYS_SOCKIO_H ${HAVE_SYS_SOCKIO_H}
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#cmakedefine HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H}
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H}
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
+
+/* Define to 1 if you have the <sys/utime.h> header file. */
+#cmakedefine HAVE_SYS_UTIME_H ${HAVE_SYS_UTIME_H}
+
+/* Define to 1 if you have the <termios.h> header file. */
+#cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H}
+
+/* Define to 1 if you have the <termio.h> header file. */
+#cmakedefine HAVE_TERMIO_H ${HAVE_TERMIO_H}
+
+/* Define to 1 if you have the <time.h> header file. */
+#cmakedefine HAVE_TIME_H ${HAVE_TIME_H}
+
+/* Define to 1 if you have the <tld.h> header file. */
+#cmakedefine HAVE_TLD_H ${HAVE_TLD_H}
+
+/* Define to 1 if you have the `tld_strerror' function. */
+#cmakedefine HAVE_TLD_STRERROR ${HAVE_TLD_STRERROR}
+
+/* Define to 1 if you have the `uname' function. */
+#cmakedefine HAVE_UNAME ${HAVE_UNAME}
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H}
+
+/* Define to 1 if you have the `utime' function. */
+#cmakedefine HAVE_UTIME ${HAVE_UTIME}
+
+/* Define to 1 if you have the <utime.h> header file. */
+#cmakedefine HAVE_UTIME_H ${HAVE_UTIME_H}
+
+/* Define to 1 if you have the windows.h header file. */
+#cmakedefine HAVE_WINDOWS_H ${HAVE_WINDOWS_H}
+
+/* Define to 1 if you have the winsock2.h header file. */
+#cmakedefine HAVE_WINSOCK2_H ${HAVE_WINSOCK2_H}
+
+/* Define to 1 if you have the winsock.h header file. */
+#cmakedefine HAVE_WINSOCK_H ${HAVE_WINSOCK_H}
+
+/* Define this symbol if your OS supports changing the contents of argv */
+#cmakedefine HAVE_WRITABLE_ARGV ${HAVE_WRITABLE_ARGV}
+
+/* Define to 1 if you have the ws2tcpip.h header file. */
+#cmakedefine HAVE_WS2TCPIP_H ${HAVE_WS2TCPIP_H}
+
+/* Define to 1 if you have the <x509.h> header file. */
+#cmakedefine HAVE_X509_H ${HAVE_X509_H}
+
+/* if you have the zlib.h header file */
+#cmakedefine HAVE_ZLIB_H ${HAVE_ZLIB_H}
+
+/* If you lack a fine basename() prototype */
+#cmakedefine NEED_BASENAME_PROTO ${NEED_BASENAME_PROTO}
+
+/* Define to 1 if you need the malloc.h header file even with stdlib.h */
+#cmakedefine NEED_MALLOC_H ${NEED_MALLOC_H}
+
+/* need REENTRANT defined */
+#cmakedefine NEED_REENTRANT ${NEED_REENTRANT}
+
+/* cpu-machine-OS */
+#define OS "${OPERATING_SYSTEM}"
+
+/* Name of package */
+#cmakedefine PACKAGE "${PACKAGE}"
+
+/* Define to the address where bug reports for this package should be sent. */
+#cmakedefine PACKAGE_BUGREPORT "${PACKAGE_BUGREPORT}"
+
+/* Define to the full name of this package. */
+#cmakedefine PACKAGE_NAME "${PACKAGE_NAME}"
+
+/* Define to the full name and version of this package. */
+#cmakedefine PACKAGE_STRING "${PACKAGE_STRING}"
+
+/* Define to the one symbol short name of this package. */
+#cmakedefine PACKAGE_TARNAME "${PACKAGE_TARNAME}"
+
+/* Define to the version of this package. */
+#cmakedefine PACKAGE_VERSION "${PACKAGE_VERSION}"
+
+/* a suitable file to read random data from */
+#cmakedefine RANDOM_FILE "${RANDOM_FILE}"
+
+/* Define to the type of arg 1 for recv. */
+#cmakedefine RECV_TYPE_ARG1 ${RECV_TYPE_ARG1}
+
+/* Define to the type of arg 2 for recv. */
+#cmakedefine RECV_TYPE_ARG2 ${RECV_TYPE_ARG2}
+
+/* Define to the type of arg 3 for recv. */
+#cmakedefine RECV_TYPE_ARG3 ${RECV_TYPE_ARG3}
+
+/* Define to the type of arg 4 for recv. */
+#cmakedefine RECV_TYPE_ARG4 ${RECV_TYPE_ARG4}
+
+/* Define to the function return type for recv. */
+#cmakedefine RECV_TYPE_RETV ${RECV_TYPE_RETV}
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#cmakedefine RETSIGTYPE ${RETSIGTYPE}
+
+/* Define to the type of arg 1 for `select'. */
+#cmakedefine SELECT_TYPE_ARG1 ${SELECT_TYPE_ARG1}
+
+/* Define to the type of args 2, 3 and 4 for `select'. */
+#cmakedefine SELECT_TYPE_ARG234 ${SELECT_TYPE_ARG234}
+
+/* Define to the type of arg 5 for `select'. */
+#cmakedefine SELECT_TYPE_ARG5 ${SELECT_TYPE_ARG5}
+
+/* Define to the type qualifier of arg 2 for send. */
+#cmakedefine SEND_QUAL_ARG2 ${SEND_QUAL_ARG2}
+
+/* Define to the type of arg 1 for send. */
+#cmakedefine SEND_TYPE_ARG1 ${SEND_TYPE_ARG1}
+
+/* Define to the type of arg 2 for send. */
+#cmakedefine SEND_TYPE_ARG2 ${SEND_TYPE_ARG2}
+
+/* Define to the type of arg 3 for send. */
+#cmakedefine SEND_TYPE_ARG3 ${SEND_TYPE_ARG3}
+
+/* Define to the type of arg 4 for send. */
+#cmakedefine SEND_TYPE_ARG4 ${SEND_TYPE_ARG4}
+
+/* Define to the function return type for send. */
+#cmakedefine SEND_TYPE_RETV ${SEND_TYPE_RETV}
+
+/* The size of `curl_off_t', as computed by sizeof. */
+@SIZEOF_CURL_OFF_T_CODE@
+
+/* The size of `long', as computed by sizeof. */
+@SIZEOF_LONG_CODE@
+
+/* The size of `long long', as computed by sizeof. */
+@SIZEOF_LONG_LONG_CODE@
+
+/* The size of `__int64', as computed by sizeof. */
+@SIZEOF___INT64_CODE@
+
+/* The size of `size_t', as computed by sizeof. */
+@SIZEOF_SIZE_T_CODE@
+
+/* The size of `ssize_t', as computed by sizeof. */
+@SIZEOF_SSIZE_T_CODE@
+
+/* The size of `time_t', as computed by sizeof. */
+@SIZEOF_TIME_T_CODE@
+
+/* Define to 1 if you have the ANSI C header files. */
+#cmakedefine STDC_HEADERS ${STDC_HEADERS}
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#cmakedefine TIME_WITH_SYS_TIME ${TIME_WITH_SYS_TIME}
+
+/* Define if you want to enable ares support */
+#cmakedefine USE_ARES ${USE_ARES}
+
+/* if GnuTLS is enabled */
+#cmakedefine USE_GNUTLS ${USE_GNUTLS}
+
+/* if libSSH2 is in use */
+#cmakedefine USE_LIBSSH2 ${USE_LIBSSH2}
+
+/* If you want to build curl with the built-in manual */
+#cmakedefine USE_MANUAL ${USE_MANUAL}
+
+/* if OpenSSL is in use */
+#cmakedefine USE_OPENSSL ${USE_OPENSSL}
+
+/* if SSL is enabled */
+#cmakedefine USE_SSLEAY ${USE_SSLEAY}
+
+/* to enable SSPI support */
+#cmakedefine USE_WINDOWS_SSPI ${USE_WINDOWS_SSPI}
+
+/* Version number of package */
+#cmakedefine VERSION "${VERSION}"
+
+/* Define to avoid automatic inclusion of winsock.h */
+#cmakedefine WIN32_LEAN_AND_MEAN ${WIN32_LEAN_AND_MEAN}
+
+/* Define to 1 if on AIX 3.
+ System headers sometimes define this.
+ We just want to avoid a redefinition error message. */
+#ifndef _ALL_SOURCE
+#cmakedefine _ALL_SOURCE ${_ALL_SOURCE}
+#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#cmakedefine _FILE_OFFSET_BITS ${_FILE_OFFSET_BITS}
+
+/* Define for large files, on AIX-style hosts. */
+#cmakedefine _LARGE_FILES ${_LARGE_FILES}
+
+/* define this if you need it to compile thread-safe code */
+#cmakedefine _THREAD_SAFE ${_THREAD_SAFE}
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#cmakedefine const ${const}
+
+/* type to use in place of in_addr_t if not defined */
+#cmakedefine in_addr_t ${in_addr_t}
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+#cmakedefine size_t ${size_t}
+
+/* type to use in place of socklen_t if not defined */
+#cmakedefine socklen_t ${socklen_t}
+
+/* the signed version of size_t */
+#ifndef SIZEOF_SSIZE_T
+# if SIZEOF_LONG == SIZEOF_SIZE_T
+ typedef long ssize_t;
+# elif SIZEOF_LONG_LONG == SIZEOF_SIZE_T
+ typedef long long ssize_t;
+# elif SIZEOF___INT64 == SIZEOF_SIZE_T
+ typedef __int64 ssize_t;
+# else
+ typedef int ssize_t;
+# endif
+#endif
+
+/* Special handling of zlib library */
+#cmakedefine CURL_SPECIAL_ZLIB_H "${CURL_SPECIAL_ZLIB_H}"
diff --git a/Utilities/cmcurl/connect.c b/Utilities/cmcurl/connect.c
new file mode 100644
index 0000000000..2b38972040
--- /dev/null
+++ b/Utilities/cmcurl/connect.c
@@ -0,0 +1,905 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef WIN32
+/* headers for non-win32 */
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h> /* <netinet/tcp.h> may need it */
+#endif
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h> /* for TCP_NODELAY */
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* required for free() prototype, without it, this crashes
+ on macos 68K */
+#endif
+#if (defined(HAVE_FIONBIO) && defined(__NOVELL_LIBC__))
+#include <sys/filio.h>
+#endif
+#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
+#undef in_addr_t
+#define in_addr_t unsigned long
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#endif
+
+#endif
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+
+#ifdef USE_WINSOCK
+#define EINPROGRESS WSAEINPROGRESS
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#define EISCONN WSAEISCONN
+#define ENOTSOCK WSAENOTSOCK
+#define ECONNREFUSED WSAECONNREFUSED
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "if2ip.h"
+#include "strerror.h"
+#include "connect.h"
+#include "memory.h"
+#include "select.h"
+#include "url.h" /* for Curl_safefree() */
+#include "multiif.h"
+#include "sockaddr.h" /* required for Curl_sockaddr_storage */
+#include "inet_ntop.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+static bool verifyconnect(curl_socket_t sockfd, int *error);
+
+static curl_socket_t
+singleipconnect(struct connectdata *conn,
+ const Curl_addrinfo *ai, /* start connecting to this */
+ long timeout_ms,
+ bool *connected);
+
+/*
+ * Curl_sockerrno() returns the *socket-related* errno (or equivalent) on this
+ * platform to hide platform specific for the function that calls this.
+ */
+int Curl_sockerrno(void)
+{
+#ifdef USE_WINSOCK
+ return (int)WSAGetLastError();
+#else
+ return errno;
+#endif
+}
+
+/*
+ * Curl_nonblock() set the given socket to either blocking or non-blocking
+ * mode based on the 'nonblock' boolean argument. This function is highly
+ * portable.
+ */
+int Curl_nonblock(curl_socket_t sockfd, /* operate on this */
+ int nonblock /* TRUE or FALSE */)
+{
+#undef SETBLOCK
+#define SETBLOCK 0
+#ifdef HAVE_O_NONBLOCK
+ /* most recent unix versions */
+ int flags;
+
+ flags = fcntl(sockfd, F_GETFL, 0);
+ if (TRUE == nonblock)
+ return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
+ else
+ return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
+#undef SETBLOCK
+#define SETBLOCK 1
+#endif
+
+#if defined(HAVE_FIONBIO) && (SETBLOCK == 0)
+ /* older unix versions */
+ int flags;
+
+ flags = nonblock;
+ return ioctl(sockfd, FIONBIO, &flags);
+#undef SETBLOCK
+#define SETBLOCK 2
+#endif
+
+#if defined(HAVE_IOCTLSOCKET) && (SETBLOCK == 0)
+ /* Windows? */
+ unsigned long flags;
+ flags = nonblock;
+
+ return ioctlsocket(sockfd, FIONBIO, &flags);
+#undef SETBLOCK
+#define SETBLOCK 3
+#endif
+
+#if defined(HAVE_IOCTLSOCKET_CASE) && (SETBLOCK == 0)
+ /* presumably for Amiga */
+ return IoctlSocket(sockfd, FIONBIO, (long)nonblock);
+#undef SETBLOCK
+#define SETBLOCK 4
+#endif
+
+#if defined(HAVE_SO_NONBLOCK) && (SETBLOCK == 0)
+ /* BeOS */
+ long b = nonblock ? 1 : 0;
+ return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
+#undef SETBLOCK
+#define SETBLOCK 5
+#endif
+
+#ifdef HAVE_DISABLED_NONBLOCKING
+ return 0; /* returns success */
+#undef SETBLOCK
+#define SETBLOCK 6
+#endif
+
+#if (SETBLOCK == 0)
+#error "no non-blocking method was found/used/set"
+#endif
+}
+
+/*
+ * waitconnect() waits for a TCP connect on the given socket for the specified
+ * number if milliseconds. It returns:
+ * 0 fine connect
+ * -1 select() error
+ * 1 select() timeout
+ * 2 select() returned with an error condition fd_set
+ */
+
+#define WAITCONN_CONNECTED 0
+#define WAITCONN_SELECT_ERROR -1
+#define WAITCONN_TIMEOUT 1
+#define WAITCONN_FDSET_ERROR 2
+
+static
+int waitconnect(curl_socket_t sockfd, /* socket */
+ long timeout_msec)
+{
+ int rc;
+#ifdef mpeix
+ /* Call this function once now, and ignore the results. We do this to
+ "clear" the error state on the socket so that we can later read it
+ reliably. This is reported necessary on the MPE/iX operating system. */
+ (void)verifyconnect(sockfd, NULL);
+#endif
+
+ /* now select() until we get connect or timeout */
+ rc = Curl_select(CURL_SOCKET_BAD, sockfd, (int)timeout_msec);
+ if(-1 == rc)
+ /* error, no connect here, try next */
+ return WAITCONN_SELECT_ERROR;
+
+ else if(0 == rc)
+ /* timeout, no connect today */
+ return WAITCONN_TIMEOUT;
+
+ if(rc & CSELECT_ERR)
+ /* error condition caught */
+ return WAITCONN_FDSET_ERROR;
+
+ /* we have a connect! */
+ return WAITCONN_CONNECTED;
+}
+
+static CURLcode bindlocal(struct connectdata *conn,
+ curl_socket_t sockfd)
+{
+ struct SessionHandle *data = conn->data;
+ struct sockaddr_in me;
+ struct sockaddr *sock = NULL; /* bind to this address */
+ socklen_t socksize; /* size of the data sock points to */
+ unsigned short port = data->set.localport; /* use this port number, 0 for
+ "random" */
+ /* how many port numbers to try to bind to, increasing one at a time */
+ int portnum = data->set.localportrange;
+
+ /*************************************************************
+ * Select device to bind socket to
+ *************************************************************/
+ if (data->set.device && (strlen(data->set.device)<255) ) {
+ struct Curl_dns_entry *h=NULL;
+ char myhost[256] = "";
+ in_addr_t in;
+ int rc;
+ bool was_iface = FALSE;
+
+ /* First check if the given name is an IP address */
+ in=inet_addr(data->set.device);
+
+ if((in == CURL_INADDR_NONE) &&
+ Curl_if2ip(data->set.device, myhost, sizeof(myhost))) {
+ /*
+ * We now have the numerical IPv4-style x.y.z.w in the 'myhost' buffer
+ */
+ rc = Curl_resolv(conn, myhost, 0, &h);
+ if(rc == CURLRESOLV_PENDING)
+ (void)Curl_wait_for_resolv(conn, &h);
+
+ if(h) {
+ was_iface = TRUE;
+ Curl_resolv_unlock(data, h);
+ }
+ }
+
+ if(!was_iface) {
+ /*
+ * This was not an interface, resolve the name as a host name
+ * or IP number
+ */
+ rc = Curl_resolv(conn, data->set.device, 0, &h);
+ if(rc == CURLRESOLV_PENDING)
+ (void)Curl_wait_for_resolv(conn, &h);
+
+ if(h) {
+ if(in == CURL_INADDR_NONE)
+ /* convert the resolved address, sizeof myhost >= INET_ADDRSTRLEN */
+ Curl_inet_ntop(h->addr->ai_addr->sa_family,
+ &((struct sockaddr_in*)h->addr->ai_addr)->sin_addr,
+ myhost, sizeof myhost);
+ else
+ /* we know data->set.device is shorter than the myhost array */
+ strcpy(myhost, data->set.device);
+ Curl_resolv_unlock(data, h);
+ }
+ }
+
+ if(! *myhost) {
+ /* need to fix this
+ h=Curl_gethost(data,
+ getmyhost(*myhost,sizeof(myhost)),
+ hostent_buf,
+ sizeof(hostent_buf));
+ */
+ failf(data, "Couldn't bind to '%s'", data->set.device);
+ return CURLE_HTTP_PORT_FAILED;
+ }
+
+ infof(data, "Bind local address to %s\n", myhost);
+
+#ifdef SO_BINDTODEVICE
+ /* I am not sure any other OSs than Linux that provide this feature, and
+ * at the least I cannot test. --Ben
+ *
+ * This feature allows one to tightly bind the local socket to a
+ * particular interface. This will force even requests to other local
+ * interfaces to go out the external interface.
+ *
+ */
+ if (was_iface) {
+ /* Only bind to the interface when specified as interface, not just as a
+ * hostname or ip address.
+ */
+ if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
+ data->set.device, strlen(data->set.device)+1) != 0) {
+ /* printf("Failed to BINDTODEVICE, socket: %d device: %s error: %s\n",
+ sockfd, data->set.device, Curl_strerror(Curl_sockerrno())); */
+ infof(data, "SO_BINDTODEVICE %s failed\n",
+ data->set.device);
+ /* This is typically "errno 1, error: Operation not permitted" if
+ you're not running as root or another suitable privileged user */
+ }
+ }
+#endif
+
+ in=inet_addr(myhost);
+ if (CURL_INADDR_NONE == in) {
+ failf(data,"couldn't find my own IP address (%s)", myhost);
+ return CURLE_HTTP_PORT_FAILED;
+ } /* end of inet_addr */
+
+ if ( h ) {
+ Curl_addrinfo *addr = h->addr;
+ sock = addr->ai_addr;
+ socksize = addr->ai_addrlen;
+ }
+ else
+ return CURLE_HTTP_PORT_FAILED;
+
+ }
+ else if(port) {
+ /* if a local port number is requested but no local IP, extract the
+ address from the socket */
+ memset(&me, 0, sizeof(struct sockaddr));
+ me.sin_family = AF_INET;
+ me.sin_addr.s_addr = INADDR_ANY;
+
+ sock = (struct sockaddr *)&me;
+ socksize = sizeof(struct sockaddr);
+
+ }
+ else
+ /* no local kind of binding was requested */
+ return CURLE_OK;
+
+ do {
+
+ /* Set port number to bind to, 0 makes the system pick one */
+ if(sock->sa_family == AF_INET)
+ ((struct sockaddr_in *)sock)->sin_port = htons(port);
+#ifdef ENABLE_IPV6
+ else
+ ((struct sockaddr_in6 *)sock)->sin6_port = htons(port);
+#endif
+
+ if( bind(sockfd, sock, socksize) >= 0) {
+ /* we succeeded to bind */
+ struct Curl_sockaddr_storage add;
+ socklen_t size;
+
+ size = sizeof(add);
+ if(getsockname(sockfd, (struct sockaddr *) &add, &size) < 0) {
+ failf(data, "getsockname() failed");
+ return CURLE_HTTP_PORT_FAILED;
+ }
+ /* We re-use/clobber the port variable here below */
+ if(((struct sockaddr *)&add)->sa_family == AF_INET)
+ port = ntohs(((struct sockaddr_in *)&add)->sin_port);
+#ifdef ENABLE_IPV6
+ else
+ port = ntohs(((struct sockaddr_in6 *)&add)->sin6_port);
+#endif
+ infof(data, "Local port: %d\n", port);
+ return CURLE_OK;
+ }
+ if(--portnum > 0) {
+ infof(data, "Bind to local port %d failed, trying next\n", port);
+ port++; /* try next port */
+ }
+ else
+ break;
+ } while(1);
+
+ data->state.os_errno = Curl_sockerrno();
+ failf(data, "bind failure: %s",
+ Curl_strerror(conn, data->state.os_errno));
+ return CURLE_HTTP_PORT_FAILED;
+
+}
+
+/*
+ * verifyconnect() returns TRUE if the connect really has happened.
+ */
+static bool verifyconnect(curl_socket_t sockfd, int *error)
+{
+ bool rc = TRUE;
+#ifdef SO_ERROR
+ int err = 0;
+ socklen_t errSize = sizeof(err);
+
+#ifdef WIN32
+ /*
+ * In October 2003 we effectively nullified this function on Windows due to
+ * problems with it using all CPU in multi-threaded cases.
+ *
+ * In May 2004, we bring it back to offer more info back on connect failures.
+ * Gisle Vanem could reproduce the former problems with this function, but
+ * could avoid them by adding this SleepEx() call below:
+ *
+ * "I don't have Rational Quantify, but the hint from his post was
+ * ntdll::NtRemoveIoCompletion(). So I'd assume the SleepEx (or maybe
+ * just Sleep(0) would be enough?) would release whatever
+ * mutex/critical-section the ntdll call is waiting on.
+ *
+ * Someone got to verify this on Win-NT 4.0, 2000."
+ */
+
+#ifdef _WIN32_WCE
+ Sleep(0);
+#else
+ SleepEx(0, FALSE);
+#endif
+
+#endif
+
+ if( -1 == getsockopt(sockfd, SOL_SOCKET, SO_ERROR,
+ (void *)&err, &errSize))
+ err = Curl_sockerrno();
+
+#ifdef _WIN32_WCE
+ /* Always returns this error, bug in CE? */
+ if(WSAENOPROTOOPT==err)
+ err=0;
+#endif
+
+ if ((0 == err) || (EISCONN == err))
+ /* we are connected, awesome! */
+ rc = TRUE;
+ else
+ /* This wasn't a successful connect */
+ rc = FALSE;
+ if (error)
+ *error = err;
+#else
+ (void)sockfd;
+ if (error)
+ *error = Curl_sockerrno();
+#endif
+ return rc;
+}
+
+CURLcode Curl_store_ip_addr(struct connectdata *conn)
+{
+ char addrbuf[256];
+ Curl_printable_address(conn->ip_addr, addrbuf, sizeof(addrbuf));
+
+ /* save the string */
+ Curl_safefree(conn->ip_addr_str);
+ conn->ip_addr_str = strdup(addrbuf);
+ if(!conn->ip_addr_str)
+ return CURLE_OUT_OF_MEMORY; /* FAIL */
+
+#ifdef PF_INET6
+ if(conn->ip_addr->ai_family == PF_INET6)
+ conn->bits.ipv6 = TRUE;
+#endif
+
+ return CURLE_OK;
+}
+
+/* Used within the multi interface. Try next IP address, return TRUE if no
+ more address exists */
+static bool trynextip(struct connectdata *conn,
+ int sockindex,
+ bool *connected)
+{
+ curl_socket_t sockfd;
+ Curl_addrinfo *ai;
+
+ /* first close the failed socket */
+ sclose(conn->sock[sockindex]);
+ conn->sock[sockindex] = CURL_SOCKET_BAD;
+ *connected = FALSE;
+
+ if(sockindex != FIRSTSOCKET)
+ return TRUE; /* no next */
+
+ /* try the next address */
+ ai = conn->ip_addr->ai_next;
+
+ while (ai) {
+ sockfd = singleipconnect(conn, ai, 0L, connected);
+ if(sockfd != CURL_SOCKET_BAD) {
+ /* store the new socket descriptor */
+ conn->sock[sockindex] = sockfd;
+ conn->ip_addr = ai;
+
+ Curl_store_ip_addr(conn);
+ return FALSE;
+ }
+ ai = ai->ai_next;
+ }
+ return TRUE;
+}
+
+/*
+ * Curl_is_connected() is used from the multi interface to check if the
+ * firstsocket has connected.
+ */
+
+CURLcode Curl_is_connected(struct connectdata *conn,
+ int sockindex,
+ bool *connected)
+{
+ int rc;
+ struct SessionHandle *data = conn->data;
+ CURLcode code = CURLE_OK;
+ curl_socket_t sockfd = conn->sock[sockindex];
+ long allow = DEFAULT_CONNECT_TIMEOUT;
+ long allow_total = 0;
+ long has_passed;
+
+ curlassert(sockindex >= FIRSTSOCKET && sockindex <= SECONDARYSOCKET);
+
+ *connected = FALSE; /* a very negative world view is best */
+
+ /* Evaluate in milliseconds how much time that has passed */
+ has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);
+
+ /* subtract the most strict timeout of the ones */
+ if(data->set.timeout && data->set.connecttimeout) {
+ if (data->set.timeout < data->set.connecttimeout)
+ allow_total = allow = data->set.timeout*1000;
+ else
+ allow = data->set.connecttimeout*1000;
+ }
+ else if(data->set.timeout) {
+ allow_total = allow = data->set.timeout*1000;
+ }
+ else if(data->set.connecttimeout) {
+ allow = data->set.connecttimeout*1000;
+ }
+
+ if(has_passed > allow ) {
+ /* time-out, bail out, go home */
+ failf(data, "Connection time-out after %ld ms", has_passed);
+ return CURLE_OPERATION_TIMEOUTED;
+ }
+ if(conn->bits.tcpconnect) {
+ /* we are connected already! */
+ Curl_expire(data, allow_total);
+ *connected = TRUE;
+ return CURLE_OK;
+ }
+
+ Curl_expire(data, allow);
+
+ /* check for connect without timeout as we want to return immediately */
+ rc = waitconnect(sockfd, 0);
+
+ if(WAITCONN_CONNECTED == rc) {
+ int error;
+ if (verifyconnect(sockfd, &error)) {
+ /* we are connected, awesome! */
+ *connected = TRUE;
+ return CURLE_OK;
+ }
+ /* nope, not connected for real */
+ data->state.os_errno = error;
+ infof(data, "Connection failed\n");
+ if(trynextip(conn, sockindex, connected)) {
+ code = CURLE_COULDNT_CONNECT;
+ }
+ }
+ else if(WAITCONN_TIMEOUT != rc) {
+ int error = 0;
+
+ /* nope, not connected */
+ if (WAITCONN_FDSET_ERROR == rc) {
+ (void)verifyconnect(sockfd, &error);
+ data->state.os_errno = error;
+ infof(data, "%s\n",Curl_strerror(conn,error));
+ }
+ else
+ infof(data, "Connection failed\n");
+
+ if(trynextip(conn, sockindex, connected)) {
+ error = Curl_sockerrno();
+ data->state.os_errno = error;
+ failf(data, "Failed connect to %s:%d; %s",
+ conn->host.name, conn->port, Curl_strerror(conn,error));
+ code = CURLE_COULDNT_CONNECT;
+ }
+ }
+ /*
+ * If the connection failed here, we should attempt to connect to the "next
+ * address" for the given host.
+ */
+
+ return code;
+}
+
+static void tcpnodelay(struct connectdata *conn,
+ curl_socket_t sockfd)
+{
+#ifdef TCP_NODELAY
+ struct SessionHandle *data= conn->data;
+ socklen_t onoff = (socklen_t) data->set.tcp_nodelay;
+ int proto = IPPROTO_TCP;
+
+#ifdef HAVE_GETPROTOBYNAME
+ struct protoent *pe = getprotobyname("tcp");
+ if (pe)
+ proto = pe->p_proto;
+#endif
+
+ if(setsockopt(sockfd, proto, TCP_NODELAY, (void *)&onoff,
+ sizeof(onoff)) < 0)
+ infof(data, "Could not set TCP_NODELAY: %s\n",
+ Curl_strerror(conn, Curl_sockerrno()));
+ else
+ infof(data,"TCP_NODELAY set\n");
+#else
+ (void)conn;
+ (void)sockfd;
+#endif
+}
+
+#ifdef SO_NOSIGPIPE
+/* The preferred method on Mac OS X (10.2 and later) to prevent SIGPIPEs when
+ sending data to a dead peer (instead of relying on the 4th argument to send
+ being MSG_NOSIGNAL). Possibly also existing and in use on other BSD
+ systems? */
+static void nosigpipe(struct connectdata *conn,
+ curl_socket_t sockfd)
+{
+ struct SessionHandle *data= conn->data;
+ int onoff = 1;
+ if(setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&onoff,
+ sizeof(onoff)) < 0)
+ infof(data, "Could not set SO_NOSIGPIPE: %s\n",
+ Curl_strerror(conn, Curl_sockerrno()));
+}
+#else
+#define nosigpipe(x,y)
+#endif
+
+/* singleipconnect() connects to the given IP only, and it may return without
+ having connected if used from the multi interface. */
+static curl_socket_t
+singleipconnect(struct connectdata *conn,
+ const Curl_addrinfo *ai,
+ long timeout_ms,
+ bool *connected)
+{
+ char addr_buf[128];
+ int rc;
+ int error;
+ bool isconnected;
+ struct SessionHandle *data = conn->data;
+ curl_socket_t sockfd;
+ CURLcode res;
+
+ sockfd = socket(ai->ai_family, conn->socktype, ai->ai_protocol);
+ if (sockfd == CURL_SOCKET_BAD)
+ return CURL_SOCKET_BAD;
+
+ *connected = FALSE; /* default is not connected */
+
+ Curl_printable_address(ai, addr_buf, sizeof(addr_buf));
+ infof(data, " Trying %s... ", addr_buf);
+
+ if(data->set.tcp_nodelay)
+ tcpnodelay(conn, sockfd);
+
+ nosigpipe(conn, sockfd);
+
+ if(data->set.fsockopt) {
+ /* activate callback for setting socket options */
+ error = data->set.fsockopt(data->set.sockopt_client,
+ sockfd,
+ CURLSOCKTYPE_IPCXN);
+ if (error) {
+ sclose(sockfd); /* close the socket and bail out */
+ return CURL_SOCKET_BAD;
+ }
+ }
+
+ /* possibly bind the local end to an IP, interface or port */
+ res = bindlocal(conn, sockfd);
+ if(res) {
+ sclose(sockfd); /* close socket and bail out */
+ return CURL_SOCKET_BAD;
+ }
+
+ /* set socket non-blocking */
+ Curl_nonblock(sockfd, TRUE);
+
+ /* Connect TCP sockets, bind UDP */
+ if(conn->socktype == SOCK_STREAM)
+ rc = connect(sockfd, ai->ai_addr, ai->ai_addrlen);
+ else
+ rc = 0;
+
+ if(-1 == rc) {
+ error = Curl_sockerrno();
+
+ switch (error) {
+ case EINPROGRESS:
+ case EWOULDBLOCK:
+#if defined(EAGAIN) && EAGAIN != EWOULDBLOCK
+ /* On some platforms EAGAIN and EWOULDBLOCK are the
+ * same value, and on others they are different, hence
+ * the odd #if
+ */
+ case EAGAIN:
+#endif
+ rc = waitconnect(sockfd, timeout_ms);
+ break;
+ default:
+ /* unknown error, fallthrough and try another address! */
+ failf(data, "Failed to connect to %s: %s",
+ addr_buf, Curl_strerror(conn,error));
+ data->state.os_errno = error;
+ break;
+ }
+ }
+
+ /* The 'WAITCONN_TIMEOUT == rc' comes from the waitconnect(), and not from
+ connect(). We can be sure of this since connect() cannot return 1. */
+ if((WAITCONN_TIMEOUT == rc) &&
+ (data->state.used_interface == Curl_if_multi)) {
+ /* Timeout when running the multi interface */
+ return sockfd;
+ }
+
+ isconnected = verifyconnect(sockfd, &error);
+
+ if(!rc && isconnected) {
+ /* we are connected, awesome! */
+ *connected = TRUE; /* this is a true connect */
+ infof(data, "connected\n");
+ return sockfd;
+ }
+ else if(WAITCONN_TIMEOUT == rc)
+ infof(data, "Timeout\n");
+ else {
+ data->state.os_errno = error;
+ infof(data, "%s\n", Curl_strerror(conn, error));
+ }
+
+ /* connect failed or timed out */
+ sclose(sockfd);
+
+ return CURL_SOCKET_BAD;
+}
+
+/*
+ * TCP connect to the given host with timeout, proxy or remote doesn't matter.
+ * There might be more than one IP address to try out. Fill in the passed
+ * pointer with the connected socket.
+ */
+
+CURLcode Curl_connecthost(struct connectdata *conn, /* context */
+ const struct Curl_dns_entry *remotehost, /* use this one */
+ curl_socket_t *sockconn, /* the connected socket */
+ Curl_addrinfo **addr, /* the one we used */
+ bool *connected) /* really connected? */
+{
+ struct SessionHandle *data = conn->data;
+ curl_socket_t sockfd = CURL_SOCKET_BAD;
+ int aliasindex;
+ int num_addr;
+ Curl_addrinfo *ai;
+ Curl_addrinfo *curr_addr;
+
+ struct timeval after;
+ struct timeval before = Curl_tvnow();
+
+ /*************************************************************
+ * Figure out what maximum time we have left
+ *************************************************************/
+ long timeout_ms= DEFAULT_CONNECT_TIMEOUT;
+ long timeout_per_addr;
+
+ *connected = FALSE; /* default to not connected */
+
+ if(data->set.timeout || data->set.connecttimeout) {
+ long has_passed;
+
+ /* Evaluate in milliseconds how much time that has passed */
+ has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);
+
+#ifndef min
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+ /* get the most strict timeout of the ones converted to milliseconds */
+ if(data->set.timeout && data->set.connecttimeout) {
+ if (data->set.timeout < data->set.connecttimeout)
+ timeout_ms = data->set.timeout*1000;
+ else
+ timeout_ms = data->set.connecttimeout*1000;
+ }
+ else if(data->set.timeout)
+ timeout_ms = data->set.timeout*1000;
+ else
+ timeout_ms = data->set.connecttimeout*1000;
+
+ /* subtract the passed time */
+ timeout_ms -= has_passed;
+
+ if(timeout_ms < 0) {
+ /* a precaution, no need to continue if time already is up */
+ failf(data, "Connection time-out");
+ return CURLE_OPERATION_TIMEOUTED;
+ }
+ }
+ Curl_expire(data, timeout_ms);
+
+ /* Max time for each address */
+ num_addr = Curl_num_addresses(remotehost->addr);
+ timeout_per_addr = timeout_ms / num_addr;
+
+ ai = remotehost->addr;
+
+ /* Below is the loop that attempts to connect to all IP-addresses we
+ * know for the given host. One by one until one IP succeeds.
+ */
+
+ if(data->state.used_interface == Curl_if_multi)
+ /* don't hang when doing multi */
+ timeout_per_addr = 0;
+
+ /*
+ * Connecting with a Curl_addrinfo chain
+ */
+ for (curr_addr = ai, aliasindex=0; curr_addr;
+ curr_addr = curr_addr->ai_next, aliasindex++) {
+
+ /* start connecting to the IP curr_addr points to */
+ sockfd = singleipconnect(conn, curr_addr, timeout_per_addr, connected);
+
+ if(sockfd != CURL_SOCKET_BAD)
+ break;
+
+ /* get a new timeout for next attempt */
+ after = Curl_tvnow();
+ timeout_ms -= Curl_tvdiff(after, before);
+ if(timeout_ms < 0) {
+ failf(data, "connect() timed out!");
+ return CURLE_OPERATION_TIMEOUTED;
+ }
+ before = after;
+ } /* end of connect-to-each-address loop */
+
+ if (sockfd == CURL_SOCKET_BAD) {
+ /* no good connect was made */
+ *sockconn = CURL_SOCKET_BAD;
+ failf(data, "couldn't connect to host");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ /* leave the socket in non-blocking mode */
+
+ /* store the address we use */
+ if(addr)
+ *addr = curr_addr;
+
+ /* allow NULL-pointers to get passed in */
+ if(sockconn)
+ *sockconn = sockfd; /* the socket descriptor we've connected */
+
+ data->info.numconnects++; /* to track the number of connections made */
+
+ return CURLE_OK;
+}
diff --git a/Utilities/cmcurl/connect.h b/Utilities/cmcurl/connect.h
new file mode 100644
index 0000000000..599572b271
--- /dev/null
+++ b/Utilities/cmcurl/connect.h
@@ -0,0 +1,46 @@
+#ifndef __CONNECT_H
+#define __CONNECT_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+int Curl_nonblock(curl_socket_t sockfd, /* operate on this */
+ int nonblock /* TRUE or FALSE */);
+
+CURLcode Curl_is_connected(struct connectdata *conn,
+ int sockindex,
+ bool *connected);
+
+CURLcode Curl_connecthost(struct connectdata *conn,
+ const struct Curl_dns_entry *host, /* connect to this */
+ curl_socket_t *sockconn, /* not set if error */
+ Curl_addrinfo **addr, /* the one we used */
+ bool *connected /* truly connected? */
+ );
+
+int Curl_sockerrno(void);
+
+CURLcode Curl_store_ip_addr(struct connectdata *conn);
+
+#define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */
+
+#endif
diff --git a/Utilities/cmcurl/content_encoding.c b/Utilities/cmcurl/content_encoding.c
new file mode 100644
index 0000000000..97f8341774
--- /dev/null
+++ b/Utilities/cmcurl/content_encoding.c
@@ -0,0 +1,424 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifdef HAVE_LIBZ
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "sendf.h"
+#include "content_encoding.h"
+#include "memory.h"
+
+#include "memdebug.h"
+
+/* Comment this out if zlib is always going to be at least ver. 1.2.0.4
+ (doing so will reduce code size slightly). */
+#define OLD_ZLIB_SUPPORT 1
+
+#define DSIZ 0x10000 /* buffer size for decompressed data */
+
+#define GZIP_MAGIC_0 0x1f
+#define GZIP_MAGIC_1 0x8b
+
+/* gzip flag byte */
+#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
+#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define COMMENT 0x10 /* bit 4 set: file comment present */
+#define RESERVED 0xE0 /* bits 5..7: reserved */
+
+enum zlibState {
+ ZLIB_UNINIT, /* uninitialized */
+ ZLIB_INIT, /* initialized */
+ ZLIB_GZIP_HEADER, /* reading gzip header */
+ ZLIB_GZIP_INFLATING, /* inflating gzip stream */
+ ZLIB_INIT_GZIP /* initialized in transparent gzip mode */
+};
+
+static CURLcode
+process_zlib_error(struct connectdata *conn, z_stream *z)
+{
+ struct SessionHandle *data = conn->data;
+ if (z->msg)
+ failf (data, "Error while processing content unencoding: %s",
+ z->msg);
+ else
+ failf (data, "Error while processing content unencoding: "
+ "Unknown failure within decompression software.");
+
+ return CURLE_BAD_CONTENT_ENCODING;
+}
+
+static CURLcode
+exit_zlib(z_stream *z, bool *zlib_init, CURLcode result)
+{
+ inflateEnd(z);
+ *zlib_init = ZLIB_UNINIT;
+ return result;
+}
+
+static CURLcode
+inflate_stream(struct connectdata *conn,
+ struct Curl_transfer_keeper *k)
+{
+ int allow_restart = 1;
+ z_stream *z = &k->z; /* zlib state structure */
+ uInt nread = z->avail_in;
+ Bytef *orig_in = z->next_in;
+ int status; /* zlib status */
+ CURLcode result = CURLE_OK; /* Curl_client_write status */
+ char *decomp; /* Put the decompressed data here. */
+
+ /* Dynamically allocate a buffer for decompression because it's uncommonly
+ large to hold on the stack */
+ decomp = (char*)malloc(DSIZ);
+ if (decomp == NULL) {
+ return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
+ }
+
+ /* because the buffer size is fixed, iteratively decompress and transfer to
+ the client via client_write. */
+ for (;;) {
+ /* (re)set buffer for decompressed output for every iteration */
+ z->next_out = (Bytef *)decomp;
+ z->avail_out = DSIZ;
+
+ status = inflate(z, Z_SYNC_FLUSH);
+ if (status == Z_OK || status == Z_STREAM_END) {
+ allow_restart = 0;
+ if(DSIZ - z->avail_out) {
+ result = Curl_client_write(conn, CLIENTWRITE_BODY, decomp,
+ DSIZ - z->avail_out);
+ /* if !CURLE_OK, clean up, return */
+ if (result) {
+ free(decomp);
+ return exit_zlib(z, &k->zlib_init, result);
+ }
+ }
+
+ /* Done? clean up, return */
+ if (status == Z_STREAM_END) {
+ free(decomp);
+ if (inflateEnd(z) == Z_OK)
+ return exit_zlib(z, &k->zlib_init, result);
+ else
+ return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
+ }
+
+ /* Done with these bytes, exit */
+ if (status == Z_OK && z->avail_in == 0) {
+ free(decomp);
+ return result;
+ }
+ }
+ else if (allow_restart && status == Z_DATA_ERROR) {
+ /* some servers seem to not generate zlib headers, so this is an attempt
+ to fix and continue anyway */
+
+ inflateReset(z);
+ if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
+ return process_zlib_error(conn, z);
+ }
+ z->next_in = orig_in;
+ z->avail_in = nread;
+ allow_restart = 0;
+ continue;
+ }
+ else { /* Error; exit loop, handle below */
+ free(decomp);
+ return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
+ }
+ }
+ /* Will never get here */
+}
+
+CURLcode
+Curl_unencode_deflate_write(struct connectdata *conn,
+ struct Curl_transfer_keeper *k,
+ ssize_t nread)
+{
+ z_stream *z = &k->z; /* zlib state structure */
+
+ /* Initialize zlib? */
+ if (k->zlib_init == ZLIB_UNINIT) {
+ z->zalloc = (alloc_func)Z_NULL;
+ z->zfree = (free_func)Z_NULL;
+ z->opaque = 0;
+ z->next_in = NULL;
+ z->avail_in = 0;
+ if (inflateInit(z) != Z_OK)
+ return process_zlib_error(conn, z);
+ k->zlib_init = ZLIB_INIT;
+ }
+
+ /* Set the compressed input when this function is called */
+ z->next_in = (Bytef *)k->str;
+ z->avail_in = (uInt)nread;
+
+ /* Now uncompress the data */
+ return inflate_stream(conn, k);
+}
+
+#ifdef OLD_ZLIB_SUPPORT
+/* Skip over the gzip header */
+static enum {
+ GZIP_OK,
+ GZIP_BAD,
+ GZIP_UNDERFLOW
+} check_gzip_header(unsigned char const *data, ssize_t len, ssize_t *headerlen)
+{
+ int method, flags;
+ const ssize_t totallen = len;
+
+ /* The shortest header is 10 bytes */
+ if (len < 10)
+ return GZIP_UNDERFLOW;
+
+ if ((data[0] != GZIP_MAGIC_0) || (data[1] != GZIP_MAGIC_1))
+ return GZIP_BAD;
+
+ method = data[2];
+ flags = data[3];
+
+ if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
+ /* Can't handle this compression method or unknown flag */
+ return GZIP_BAD;
+ }
+
+ /* Skip over time, xflags, OS code and all previous bytes */
+ len -= 10;
+ data += 10;
+
+ if (flags & EXTRA_FIELD) {
+ ssize_t extra_len;
+
+ if (len < 2)
+ return GZIP_UNDERFLOW;
+
+ extra_len = (data[1] << 8) | data[0];
+
+ if (len < (extra_len+2))
+ return GZIP_UNDERFLOW;
+
+ len -= (extra_len + 2);
+ data += (extra_len + 2);
+ }
+
+ if (flags & ORIG_NAME) {
+ /* Skip over NUL-terminated file name */
+ while (len && *data) {
+ --len;
+ ++data;
+ }
+ if (!len || *data)
+ return GZIP_UNDERFLOW;
+
+ /* Skip over the NUL */
+ --len;
+ ++data;
+ }
+
+ if (flags & COMMENT) {
+ /* Skip over NUL-terminated comment */
+ while (len && *data) {
+ --len;
+ ++data;
+ }
+ if (!len || *data)
+ return GZIP_UNDERFLOW;
+
+ /* Skip over the NUL */
+ --len;
+ ++data;
+ }
+
+ if (flags & HEAD_CRC) {
+ if (len < 2)
+ return GZIP_UNDERFLOW;
+
+ len -= 2;
+ data += 2;
+ }
+
+ *headerlen = totallen - len;
+ return GZIP_OK;
+}
+#endif
+
+CURLcode
+Curl_unencode_gzip_write(struct connectdata *conn,
+ struct Curl_transfer_keeper *k,
+ ssize_t nread)
+{
+ z_stream *z = &k->z; /* zlib state structure */
+
+ /* Initialize zlib? */
+ if (k->zlib_init == ZLIB_UNINIT) {
+ z->zalloc = (alloc_func)Z_NULL;
+ z->zfree = (free_func)Z_NULL;
+ z->opaque = 0;
+ z->next_in = NULL;
+ z->avail_in = 0;
+
+ if (strcmp(zlibVersion(), "1.2.0.4") >= 0) {
+ /* zlib ver. >= 1.2.0.4 supports transparent gzip decompressing */
+ if (inflateInit2(z, MAX_WBITS+32) != Z_OK) {
+ return process_zlib_error(conn, z);
+ }
+ k->zlib_init = ZLIB_INIT_GZIP; /* Transparent gzip decompress state */
+
+ } else {
+ /* we must parse the gzip header ourselves */
+ if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
+ return process_zlib_error(conn, z);
+ }
+ k->zlib_init = ZLIB_INIT; /* Initial call state */
+ }
+ }
+
+ if (k->zlib_init == ZLIB_INIT_GZIP) {
+ /* Let zlib handle the gzip decompression entirely */
+ z->next_in = (Bytef *)k->str;
+ z->avail_in = (uInt)nread;
+ /* Now uncompress the data */
+ return inflate_stream(conn, k);
+ }
+
+#ifndef OLD_ZLIB_SUPPORT
+ /* Support for old zlib versions is compiled away and we are running with
+ an old version, so return an error. */
+ return exit_zlib(z, &k->zlib_init, CURLE_FUNCTION_NOT_FOUND);
+
+#else
+ /* This next mess is to get around the potential case where there isn't
+ * enough data passed in to skip over the gzip header. If that happens, we
+ * malloc a block and copy what we have then wait for the next call. If
+ * there still isn't enough (this is definitely a worst-case scenario), we
+ * make the block bigger, copy the next part in and keep waiting.
+ *
+ * This is only required with zlib versions < 1.2.0.4 as newer versions
+ * can handle the gzip header themselves.
+ */
+
+ switch (k->zlib_init) {
+ /* Skip over gzip header? */
+ case ZLIB_INIT:
+ {
+ /* Initial call state */
+ ssize_t hlen;
+
+ switch (check_gzip_header((unsigned char *)k->str, nread, &hlen)) {
+ case GZIP_OK:
+ z->next_in = (Bytef *)k->str + hlen;
+ z->avail_in = (uInt)(nread - hlen);
+ k->zlib_init = ZLIB_GZIP_INFLATING; /* Inflating stream state */
+ break;
+
+ case GZIP_UNDERFLOW:
+ /* We need more data so we can find the end of the gzip header. It's
+ * possible that the memory block we malloc here will never be freed if
+ * the transfer abruptly aborts after this point. Since it's unlikely
+ * that circumstances will be right for this code path to be followed in
+ * the first place, and it's even more unlikely for a transfer to fail
+ * immediately afterwards, it should seldom be a problem.
+ */
+ z->avail_in = (uInt)nread;
+ z->next_in = malloc(z->avail_in);
+ if (z->next_in == NULL) {
+ return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
+ }
+ memcpy(z->next_in, k->str, z->avail_in);
+ k->zlib_init = ZLIB_GZIP_HEADER; /* Need more gzip header data state */
+ /* We don't have any data to inflate yet */
+ return CURLE_OK;
+
+ case GZIP_BAD:
+ default:
+ return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
+ }
+
+ }
+ break;
+
+ case ZLIB_GZIP_HEADER:
+ {
+ /* Need more gzip header data state */
+ ssize_t hlen;
+ unsigned char *oldblock = z->next_in;
+
+ z->avail_in += nread;
+ z->next_in = realloc(z->next_in, z->avail_in);
+ if (z->next_in == NULL) {
+ free(oldblock);
+ return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
+ }
+ /* Append the new block of data to the previous one */
+ memcpy(z->next_in + z->avail_in - nread, k->str, nread);
+
+ switch (check_gzip_header(z->next_in, z->avail_in, &hlen)) {
+ case GZIP_OK:
+ /* This is the zlib stream data */
+ free(z->next_in);
+ /* Don't point into the malloced block since we just freed it */
+ z->next_in = (Bytef *)k->str + hlen + nread - z->avail_in;
+ z->avail_in = (uInt)(z->avail_in - hlen);
+ k->zlib_init = ZLIB_GZIP_INFLATING; /* Inflating stream state */
+ break;
+
+ case GZIP_UNDERFLOW:
+ /* We still don't have any data to inflate! */
+ return CURLE_OK;
+
+ case GZIP_BAD:
+ default:
+ free(z->next_in);
+ return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
+ }
+
+ }
+ break;
+
+ case ZLIB_GZIP_INFLATING:
+ default:
+ /* Inflating stream state */
+ z->next_in = (Bytef *)k->str;
+ z->avail_in = (uInt)nread;
+ break;
+ }
+
+ if (z->avail_in == 0) {
+ /* We don't have any data to inflate; wait until next time */
+ return CURLE_OK;
+ }
+
+ /* We've parsed the header, now uncompress the data */
+ return inflate_stream(conn, k);
+#endif
+}
+#endif /* HAVE_LIBZ */
diff --git a/Utilities/cmcurl/content_encoding.h b/Utilities/cmcurl/content_encoding.h
new file mode 100644
index 0000000000..b31669be4b
--- /dev/null
+++ b/Utilities/cmcurl/content_encoding.h
@@ -0,0 +1,41 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#include "setup.h"
+
+/*
+ * Comma-separated list all supported Content-Encodings ('identity' is implied)
+ */
+#ifdef HAVE_LIBZ
+#define ALL_CONTENT_ENCODINGS "deflate, gzip"
+#else
+#define ALL_CONTENT_ENCODINGS "identity"
+#endif
+
+CURLcode Curl_unencode_deflate_write(struct connectdata *conn,
+ struct Curl_transfer_keeper *k,
+ ssize_t nread);
+
+CURLcode
+Curl_unencode_gzip_write(struct connectdata *conn,
+ struct Curl_transfer_keeper *k,
+ ssize_t nread);
diff --git a/Utilities/cmcurl/cookie.c b/Utilities/cmcurl/cookie.c
new file mode 100644
index 0000000000..d8ea24196e
--- /dev/null
+++ b/Utilities/cmcurl/cookie.c
@@ -0,0 +1,1019 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/***
+
+
+RECEIVING COOKIE INFORMATION
+============================
+
+struct CookieInfo *cookie_init(char *file);
+
+ Inits a cookie struct to store data in a local file. This is always
+ called before any cookies are set.
+
+int cookies_set(struct CookieInfo *cookie, char *cookie_line);
+
+ The 'cookie_line' parameter is a full "Set-cookie:" line as
+ received from a server.
+
+ The function need to replace previously stored lines that this new
+ line superceeds.
+
+ It may remove lines that are expired.
+
+ It should return an indication of success/error.
+
+
+SENDING COOKIE INFORMATION
+==========================
+
+struct Cookies *cookie_getlist(struct CookieInfo *cookie,
+ char *host, char *path, bool secure);
+
+ For a given host and path, return a linked list of cookies that
+ the client should send to the server if used now. The secure
+ boolean informs the cookie if a secure connection is achieved or
+ not.
+
+ It shall only return cookies that haven't expired.
+
+
+Example set of cookies:
+
+ Set-cookie: PRODUCTINFO=webxpress; domain=.fidelity.com; path=/; secure
+ Set-cookie: PERSONALIZE=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
+ domain=.fidelity.com; path=/ftgw; secure
+ Set-cookie: FidHist=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
+ domain=.fidelity.com; path=/; secure
+ Set-cookie: FidOrder=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
+ domain=.fidelity.com; path=/; secure
+ Set-cookie: DisPend=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
+ domain=.fidelity.com; path=/; secure
+ Set-cookie: FidDis=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
+ domain=.fidelity.com; path=/; secure
+ Set-cookie:
+ Session_Key@6791a9e0-901a-11d0-a1c8-9b012c88aa77=none;expires=Monday,
+ 13-Jun-1988 03:04:55 GMT; domain=.fidelity.com; path=/; secure
+****/
+
+
+#include "setup.h"
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+
+#include <stdlib.h>
+#include <string.h>
+
+#define _MPRINTF_REPLACE /* without this on windows OS we get undefined reference to snprintf */
+#include <curl/mprintf.h>
+
+#include "urldata.h"
+#include "cookie.h"
+#include "strequal.h"
+#include "strtok.h"
+#include "sendf.h"
+#include "memory.h"
+#include "share.h"
+#include "strtoofft.h"
+
+/* The last #include file should be: */
+#ifdef CURLDEBUG
+#include "memdebug.h"
+#endif
+
+#define my_isspace(x) ((x == ' ') || (x == '\t'))
+
+static void freecookie(struct Cookie *co)
+{
+ if(co->expirestr)
+ free(co->expirestr);
+ if(co->domain)
+ free(co->domain);
+ if(co->path)
+ free(co->path);
+ if(co->name)
+ free(co->name);
+ if(co->value)
+ free(co->value);
+ if(co->maxage)
+ free(co->maxage);
+ if(co->version)
+ free(co->version);
+
+ free(co);
+}
+
+static bool tailmatch(const char *little, const char *bigone)
+{
+ size_t littlelen = strlen(little);
+ size_t biglen = strlen(bigone);
+
+ if(littlelen > biglen)
+ return FALSE;
+
+ return (bool)strequal(little, bigone+biglen-littlelen);
+}
+
+/*
+ * Load cookies from all given cookie files (CURLOPT_COOKIEFILE).
+ */
+void Curl_cookie_loadfiles(struct SessionHandle *data)
+{
+ struct curl_slist *list = data->change.cookielist;
+ if(list) {
+ Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
+ while(list) {
+ data->cookies = Curl_cookie_init(data,
+ list->data,
+ data->cookies,
+ data->set.cookiesession);
+ list = list->next;
+ }
+ Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
+ curl_slist_free_all(data->change.cookielist); /* clean up list */
+ data->change.cookielist = NULL; /* don't do this again! */
+ }
+}
+
+/****************************************************************************
+ *
+ * Curl_cookie_add()
+ *
+ * Add a single cookie line to the cookie keeping object.
+ *
+ ***************************************************************************/
+
+struct Cookie *
+Curl_cookie_add(struct SessionHandle *data,
+ /* The 'data' pointer here may be NULL at times, and thus
+ must only be used very carefully for things that can deal
+ with data being NULL. Such as infof() and similar */
+
+ struct CookieInfo *c,
+ bool httpheader, /* TRUE if HTTP header-style line */
+ char *lineptr, /* first character of the line */
+ char *domain, /* default domain */
+ char *path) /* full path used when this cookie is set,
+ used to get default path for the cookie
+ unless set */
+{
+ struct Cookie *clist;
+ char *what;
+ char name[MAX_NAME];
+ char *ptr;
+ char *semiptr;
+ struct Cookie *co;
+ struct Cookie *lastc=NULL;
+ time_t now = time(NULL);
+ bool replace_old = FALSE;
+ bool badcookie = FALSE; /* cookies are good by default. mmmmm yummy */
+
+ /* First, alloc and init a new struct for it */
+ co = (struct Cookie *)calloc(sizeof(struct Cookie), 1);
+ if(!co)
+ return NULL; /* bail out if we're this low on memory */
+
+ if(httpheader) {
+ /* This line was read off a HTTP-header */
+ char *sep;
+
+ what = malloc(MAX_COOKIE_LINE);
+ if(!what) {
+ free(co);
+ return NULL;
+ }
+
+ semiptr=strchr(lineptr, ';'); /* first, find a semicolon */
+
+ while(*lineptr && my_isspace(*lineptr))
+ lineptr++;
+
+ ptr = lineptr;
+ do {
+ /* we have a <what>=<this> pair or a 'secure' word here */
+ sep = strchr(ptr, '=');
+ if(sep && (!semiptr || (semiptr>sep)) ) {
+ /*
+ * There is a = sign and if there was a semicolon too, which make sure
+ * that the semicolon comes _after_ the equal sign.
+ */
+
+ name[0]=what[0]=0; /* init the buffers */
+ if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;=]=%"
+ MAX_COOKIE_LINE_TXT "[^;\r\n]",
+ name, what)) {
+ /* this is a <name>=<what> pair */
+
+ char *whatptr;
+
+ /* Strip off trailing whitespace from the 'what' */
+ size_t len=strlen(what);
+ while(len && my_isspace(what[len-1])) {
+ what[len-1]=0;
+ len--;
+ }
+
+ /* Skip leading whitespace from the 'what' */
+ whatptr=what;
+ while(my_isspace(*whatptr)) {
+ whatptr++;
+ }
+
+ if(strequal("path", name)) {
+ co->path=strdup(whatptr);
+ if(!co->path) {
+ badcookie = TRUE; /* out of memory bad */
+ break;
+ }
+ }
+ else if(strequal("domain", name)) {
+ /* note that this name may or may not have a preceeding dot, but
+ we don't care about that, we treat the names the same anyway */
+
+ const char *domptr=whatptr;
+ int dotcount=1;
+
+ /* Count the dots, we need to make sure that there are enough
+ of them. */
+
+ if('.' == whatptr[0])
+ /* don't count the initial dot, assume it */
+ domptr++;
+
+ do {
+ domptr = strchr(domptr, '.');
+ if(domptr) {
+ domptr++;
+ dotcount++;
+ }
+ } while(domptr);
+
+ /* The original Netscape cookie spec defined that this domain name
+ MUST have three dots (or two if one of the seven holy TLDs),
+ but it seems that these kinds of cookies are in use "out there"
+ so we cannot be that strict. I've therefore lowered the check
+ to not allow less than two dots. */
+
+ if(dotcount < 2) {
+ /* Received and skipped a cookie with a domain using too few
+ dots. */
+ badcookie=TRUE; /* mark this as a bad cookie */
+ infof(data, "skipped cookie with illegal dotcount domain: %s\n",
+ whatptr);
+ }
+ else {
+ /* Now, we make sure that our host is within the given domain,
+ or the given domain is not valid and thus cannot be set. */
+
+ if('.' == whatptr[0])
+ whatptr++; /* ignore preceeding dot */
+
+ if(!domain || tailmatch(whatptr, domain)) {
+ const char *tailptr=whatptr;
+ if(tailptr[0] == '.')
+ tailptr++;
+ co->domain=strdup(tailptr); /* don't prefix w/dots
+ internally */
+ if(!co->domain) {
+ badcookie = TRUE;
+ break;
+ }
+ co->tailmatch=TRUE; /* we always do that if the domain name was
+ given */
+ }
+ else {
+ /* we did not get a tailmatch and then the attempted set domain
+ is not a domain to which the current host belongs. Mark as
+ bad. */
+ badcookie=TRUE;
+ infof(data, "skipped cookie with bad tailmatch domain: %s\n",
+ whatptr);
+ }
+ }
+ }
+ else if(strequal("version", name)) {
+ co->version=strdup(whatptr);
+ if(!co->version) {
+ badcookie = TRUE;
+ break;
+ }
+ }
+ else if(strequal("max-age", name)) {
+ /* Defined in RFC2109:
+
+ Optional. The Max-Age attribute defines the lifetime of the
+ cookie, in seconds. The delta-seconds value is a decimal non-
+ negative integer. After delta-seconds seconds elapse, the
+ client should discard the cookie. A value of zero means the
+ cookie should be discarded immediately.
+
+ */
+ co->maxage = strdup(whatptr);
+ if(!co->maxage) {
+ badcookie = TRUE;
+ break;
+ }
+ co->expires =
+ atoi((*co->maxage=='\"')?&co->maxage[1]:&co->maxage[0]) + (long)now;
+ }
+ else if(strequal("expires", name)) {
+ co->expirestr=strdup(whatptr);
+ if(!co->expirestr) {
+ badcookie = TRUE;
+ break;
+ }
+ co->expires = curl_getdate(what, &now);
+ }
+ else if(!co->name) {
+ co->name = strdup(name);
+ co->value = strdup(whatptr);
+ if(!co->name || !co->value) {
+ badcookie = TRUE;
+ break;
+ }
+ }
+ /*
+ else this is the second (or more) name we don't know
+ about! */
+ }
+ else {
+ /* this is an "illegal" <what>=<this> pair */
+ }
+ }
+ else {
+ if(sscanf(ptr, "%" MAX_COOKIE_LINE_TXT "[^;\r\n]",
+ what)) {
+ if(strequal("secure", what))
+ co->secure = TRUE;
+ /* else,
+ unsupported keyword without assign! */
+
+ }
+ }
+ if(!semiptr || !*semiptr) {
+ /* we already know there are no more cookies */
+ semiptr = NULL;
+ continue;
+ }
+
+ ptr=semiptr+1;
+ while(ptr && *ptr && my_isspace(*ptr))
+ ptr++;
+ semiptr=strchr(ptr, ';'); /* now, find the next semicolon */
+
+ if(!semiptr && *ptr)
+ /* There are no more semicolons, but there's a final name=value pair
+ coming up */
+ semiptr=strchr(ptr, '\0');
+ } while(semiptr);
+
+ if(!badcookie && !co->domain) {
+ if(domain) {
+ /* no domain was given in the header line, set the default */
+ co->domain=strdup(domain);
+ if(!co->domain)
+ badcookie = TRUE;
+ }
+ }
+
+ if(!badcookie && !co->path && path) {
+ /* no path was given in the header line, set the default */
+ char *endslash = strrchr(path, '/');
+ if(endslash) {
+ size_t pathlen = endslash-path+1; /* include the ending slash */
+ co->path=malloc(pathlen+1); /* one extra for the zero byte */
+ if(co->path) {
+ memcpy(co->path, path, pathlen);
+ co->path[pathlen]=0; /* zero terminate */
+ }
+ else
+ badcookie = TRUE;
+ }
+ }
+
+ free(what);
+
+ if(badcookie || !co->name) {
+ /* we didn't get a cookie name or a bad one,
+ this is an illegal line, bail out */
+ freecookie(co);
+ return NULL;
+ }
+
+ }
+ else {
+ /* This line is NOT a HTTP header style line, we do offer support for
+ reading the odd netscape cookies-file format here */
+ char *firstptr;
+ char *tok_buf;
+ int fields;
+
+ if(lineptr[0]=='#') {
+ /* don't even try the comments */
+ free(co);
+ return NULL;
+ }
+ /* strip off the possible end-of-line characters */
+ ptr=strchr(lineptr, '\r');
+ if(ptr)
+ *ptr=0; /* clear it */
+ ptr=strchr(lineptr, '\n');
+ if(ptr)
+ *ptr=0; /* clear it */
+
+ firstptr=strtok_r(lineptr, "\t", &tok_buf); /* tokenize it on the TAB */
+
+ /* Here's a quick check to eliminate normal HTTP-headers from this */
+ if(!firstptr || strchr(firstptr, ':')) {
+ free(co);
+ return NULL;
+ }
+
+ /* Now loop through the fields and init the struct we already have
+ allocated */
+ for(ptr=firstptr, fields=0; ptr && !badcookie;
+ ptr=strtok_r(NULL, "\t", &tok_buf), fields++) {
+ switch(fields) {
+ case 0:
+ if(ptr[0]=='.') /* skip preceeding dots */
+ ptr++;
+ co->domain = strdup(ptr);
+ if(!co->domain)
+ badcookie = TRUE;
+ break;
+ case 1:
+ /* This field got its explanation on the 23rd of May 2001 by
+ Andrés García:
+
+ flag: A TRUE/FALSE value indicating if all machines within a given
+ domain can access the variable. This value is set automatically by
+ the browser, depending on the value you set for the domain.
+
+ As far as I can see, it is set to true when the cookie says
+ .domain.com and to false when the domain is complete www.domain.com
+ */
+ co->tailmatch=(bool)strequal(ptr, "TRUE"); /* store information */
+ break;
+ case 2:
+ /* It turns out, that sometimes the file format allows the path
+ field to remain not filled in, we try to detect this and work
+ around it! Andrés García made us aware of this... */
+ if (strcmp("TRUE", ptr) && strcmp("FALSE", ptr)) {
+ /* only if the path doesn't look like a boolean option! */
+ co->path = strdup(ptr);
+ if(!co->path)
+ badcookie = TRUE;
+ break;
+ }
+ /* this doesn't look like a path, make one up! */
+ co->path = strdup("/");
+ if(!co->path)
+ badcookie = TRUE;
+ fields++; /* add a field and fall down to secure */
+ /* FALLTHROUGH */
+ case 3:
+ co->secure = (bool)strequal(ptr, "TRUE");
+ break;
+ case 4:
+ co->expires = curlx_strtoofft(ptr, NULL, 10);
+ break;
+ case 5:
+ co->name = strdup(ptr);
+ if(!co->name)
+ badcookie = TRUE;
+ break;
+ case 6:
+ co->value = strdup(ptr);
+ if(!co->value)
+ badcookie = TRUE;
+ break;
+ }
+ }
+ if(6 == fields) {
+ /* we got a cookie with blank contents, fix it */
+ co->value = strdup("");
+ if(!co->value)
+ badcookie = TRUE;
+ else
+ fields++;
+ }
+
+ if(!badcookie && (7 != fields))
+ /* we did not find the sufficient number of fields */
+ badcookie = TRUE;
+
+ if(badcookie) {
+ freecookie(co);
+ return NULL;
+ }
+
+ }
+
+ if(!c->running && /* read from a file */
+ c->newsession && /* clean session cookies */
+ !co->expires) { /* this is a session cookie since it doesn't expire! */
+ freecookie(co);
+ return NULL;
+ }
+
+ co->livecookie = c->running;
+
+ /* now, we have parsed the incoming line, we must now check if this
+ superceeds an already existing cookie, which it may if the previous have
+ the same domain and path as this */
+
+ clist = c->cookies;
+ replace_old = FALSE;
+ while(clist) {
+ if(strequal(clist->name, co->name)) {
+ /* the names are identical */
+
+ if(clist->domain && co->domain) {
+ if(strequal(clist->domain, co->domain))
+ /* The domains are identical */
+ replace_old=TRUE;
+ }
+ else if(!clist->domain && !co->domain)
+ replace_old = TRUE;
+
+ if(replace_old) {
+ /* the domains were identical */
+
+ if(clist->path && co->path) {
+ if(strequal(clist->path, co->path)) {
+ replace_old = TRUE;
+ }
+ else
+ replace_old = FALSE;
+ }
+ else if(!clist->path && !co->path)
+ replace_old = TRUE;
+ else
+ replace_old = FALSE;
+
+ }
+
+ if(replace_old && !co->livecookie && clist->livecookie) {
+ /* Both cookies matched fine, except that the already present
+ cookie is "live", which means it was set from a header, while
+ the new one isn't "live" and thus only read from a file. We let
+ live cookies stay alive */
+
+ /* Free the newcomer and get out of here! */
+ freecookie(co);
+ return NULL;
+ }
+
+ if(replace_old) {
+ co->next = clist->next; /* get the next-pointer first */
+
+ /* then free all the old pointers */
+ if(clist->name)
+ free(clist->name);
+ if(clist->value)
+ free(clist->value);
+ if(clist->domain)
+ free(clist->domain);
+ if(clist->path)
+ free(clist->path);
+ if(clist->expirestr)
+ free(clist->expirestr);
+
+ if(clist->version)
+ free(clist->version);
+ if(clist->maxage)
+ free(clist->maxage);
+
+ *clist = *co; /* then store all the new data */
+
+ free(co); /* free the newly alloced memory */
+ co = clist; /* point to the previous struct instead */
+
+ /* We have replaced a cookie, now skip the rest of the list but
+ make sure the 'lastc' pointer is properly set */
+ do {
+ lastc = clist;
+ clist = clist->next;
+ } while(clist);
+ break;
+ }
+ }
+ lastc = clist;
+ clist = clist->next;
+ }
+
+ if(c->running)
+ /* Only show this when NOT reading the cookies from a file */
+ infof(data, "%s cookie %s=\"%s\" for domain %s, path %s, expire %d\n",
+ replace_old?"Replaced":"Added", co->name, co->value,
+ co->domain, co->path, co->expires);
+
+ if(!replace_old) {
+ /* then make the last item point on this new one */
+ if(lastc)
+ lastc->next = co;
+ else
+ c->cookies = co;
+ }
+
+ c->numcookies++; /* one more cookie in the jar */
+ return co;
+}
+
+/*****************************************************************************
+ *
+ * Curl_cookie_init()
+ *
+ * Inits a cookie struct to read data from a local file. This is always
+ * called before any cookies are set. File may be NULL.
+ *
+ * If 'newsession' is TRUE, discard all "session cookies" on read from file.
+ *
+ ****************************************************************************/
+struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
+ char *file,
+ struct CookieInfo *inc,
+ bool newsession)
+{
+ struct CookieInfo *c;
+ FILE *fp;
+ bool fromfile=TRUE;
+
+ if(NULL == inc) {
+ /* we didn't get a struct, create one */
+ c = (struct CookieInfo *)calloc(1, sizeof(struct CookieInfo));
+ if(!c)
+ return NULL; /* failed to get memory */
+ c->filename = strdup(file?file:"none"); /* copy the name just in case */
+ }
+ else {
+ /* we got an already existing one, use that */
+ c = inc;
+ }
+ c->running = FALSE; /* this is not running, this is init */
+
+ if(file && strequal(file, "-")) {
+ fp = stdin;
+ fromfile=FALSE;
+ }
+ else if(file && !*file) {
+ /* points to a "" string */
+ fp = NULL;
+ }
+ else
+ fp = file?fopen(file, "r"):NULL;
+
+ c->newsession = newsession; /* new session? */
+
+ if(fp) {
+ char *lineptr;
+ bool headerline;
+
+ char *line = (char *)malloc(MAX_COOKIE_LINE);
+ if(line) {
+ while(fgets(line, MAX_COOKIE_LINE, fp)) {
+ if(checkprefix("Set-Cookie:", line)) {
+ /* This is a cookie line, get it! */
+ lineptr=&line[11];
+ headerline=TRUE;
+ }
+ else {
+ lineptr=line;
+ headerline=FALSE;
+ }
+ while(*lineptr && my_isspace(*lineptr))
+ lineptr++;
+
+ Curl_cookie_add(data, c, headerline, lineptr, NULL, NULL);
+ }
+ free(line); /* free the line buffer */
+ }
+ if(fromfile)
+ fclose(fp);
+ }
+
+ c->running = TRUE; /* now, we're running */
+
+ return c;
+}
+
+/*****************************************************************************
+ *
+ * Curl_cookie_getlist()
+ *
+ * For a given host and path, return a linked list of cookies that the
+ * client should send to the server if used now. The secure boolean informs
+ * the cookie if a secure connection is achieved or not.
+ *
+ * It shall only return cookies that haven't expired.
+ *
+ ****************************************************************************/
+
+struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
+ char *host, char *path, bool secure)
+{
+ struct Cookie *newco;
+ struct Cookie *co;
+ time_t now = time(NULL);
+ struct Cookie *mainco=NULL;
+
+ if(!c || !c->cookies)
+ return NULL; /* no cookie struct or no cookies in the struct */
+
+ co = c->cookies;
+
+ while(co) {
+ /* only process this cookie if it is not expired or had no expire
+ date AND that if the cookie requires we're secure we must only
+ continue if we are! */
+ if( (co->expires<=0 || (co->expires> now)) &&
+ (co->secure?secure:TRUE) ) {
+
+ /* now check if the domain is correct */
+ if(!co->domain ||
+ (co->tailmatch && tailmatch(co->domain, host)) ||
+ (!co->tailmatch && strequal(host, co->domain)) ) {
+ /* the right part of the host matches the domain stuff in the
+ cookie data */
+
+ /* now check the left part of the path with the cookies path
+ requirement */
+ if(!co->path ||
+ /* not using checkprefix() because matching should be
+ case-sensitive */
+ !strncmp(co->path, path, strlen(co->path)) ) {
+
+ /* and now, we know this is a match and we should create an
+ entry for the return-linked-list */
+
+ newco = (struct Cookie *)malloc(sizeof(struct Cookie));
+ if(newco) {
+ /* first, copy the whole source cookie: */
+ memcpy(newco, co, sizeof(struct Cookie));
+
+ /* then modify our next */
+ newco->next = mainco;
+
+ /* point the main to us */
+ mainco = newco;
+ }
+ else {
+ /* failure, clear up the allocated chain and return NULL */
+ while(mainco) {
+ co = mainco->next;
+ free(mainco);
+ mainco = co;
+ }
+
+ return NULL;
+ }
+ }
+ }
+ }
+ co = co->next;
+ }
+
+ return mainco; /* return the new list */
+}
+
+/*****************************************************************************
+ *
+ * Curl_cookie_clearall()
+ *
+ * Clear all existing cookies and reset the counter.
+ *
+ ****************************************************************************/
+void Curl_cookie_clearall(struct CookieInfo *cookies)
+{
+ if(cookies) {
+ Curl_cookie_freelist(cookies->cookies);
+ cookies->cookies = NULL;
+ cookies->numcookies = 0;
+ }
+}
+
+/*****************************************************************************
+ *
+ * Curl_cookie_freelist()
+ *
+ * Free a list of cookies previously returned by Curl_cookie_getlist();
+ *
+ ****************************************************************************/
+
+void Curl_cookie_freelist(struct Cookie *co)
+{
+ struct Cookie *next;
+ if(co) {
+ while(co) {
+ next = co->next;
+ free(co); /* we only free the struct since the "members" are all
+ just copied! */
+ co = next;
+ }
+ }
+}
+
+
+/*****************************************************************************
+ *
+ * Curl_cookie_clearsess()
+ *
+ * Free all session cookies in the cookies list.
+ *
+ ****************************************************************************/
+void Curl_cookie_clearsess(struct CookieInfo *cookies)
+{
+ struct Cookie *first, *curr, *next, *prev = NULL;
+
+ if(!cookies->cookies)
+ return;
+
+ first = curr = prev = cookies->cookies;
+
+ for(; curr; curr = next) {
+ next = curr->next;
+ if(!curr->expires) {
+ if(first == curr)
+ first = next;
+
+ if(prev == curr)
+ prev = next;
+ else
+ prev->next = next;
+
+ free(curr);
+ cookies->numcookies--;
+ }
+ else
+ prev = curr;
+ }
+
+ cookies->cookies = first;
+}
+
+
+/*****************************************************************************
+ *
+ * Curl_cookie_cleanup()
+ *
+ * Free a "cookie object" previous created with cookie_init().
+ *
+ ****************************************************************************/
+void Curl_cookie_cleanup(struct CookieInfo *c)
+{
+ struct Cookie *co;
+ struct Cookie *next;
+ if(c) {
+ if(c->filename)
+ free(c->filename);
+ co = c->cookies;
+
+ while(co) {
+ next = co->next;
+ freecookie(co);
+ co = next;
+ }
+ free(c); /* free the base struct as well */
+ }
+}
+
+/* get_netscape_format()
+ *
+ * Formats a string for Netscape output file, w/o a newline at the end.
+ *
+ * Function returns a char * to a formatted line. Has to be free()d
+*/
+static char *get_netscape_format(const struct Cookie *co)
+{
+ return aprintf(
+ "%s%s\t" /* domain */
+ "%s\t" /* tailmatch */
+ "%s\t" /* path */
+ "%s\t" /* secure */
+ "%" FORMAT_OFF_T "\t" /* expires */
+ "%s\t" /* name */
+ "%s", /* value */
+ /* Make sure all domains are prefixed with a dot if they allow
+ tailmatching. This is Mozilla-style. */
+ (co->tailmatch && co->domain && co->domain[0] != '.')? ".":"",
+ co->domain?co->domain:"unknown",
+ co->tailmatch?"TRUE":"FALSE",
+ co->path?co->path:"/",
+ co->secure?"TRUE":"FALSE",
+ co->expires,
+ co->name,
+ co->value?co->value:"");
+}
+
+/*
+ * Curl_cookie_output()
+ *
+ * Writes all internally known cookies to the specified file. Specify
+ * "-" as file name to write to stdout.
+ *
+ * The function returns non-zero on write failure.
+ */
+int Curl_cookie_output(struct CookieInfo *c, char *dumphere)
+{
+ struct Cookie *co;
+ FILE *out;
+ bool use_stdout=FALSE;
+
+ if((NULL == c) || (0 == c->numcookies))
+ /* If there are no known cookies, we don't write or even create any
+ destination file */
+ return 0;
+
+ if(strequal("-", dumphere)) {
+ /* use stdout */
+ out = stdout;
+ use_stdout=TRUE;
+ }
+ else {
+ out = fopen(dumphere, "w");
+ if(!out)
+ return 1; /* failure */
+ }
+
+ if(c) {
+ char *format_ptr;
+
+ fputs("# Netscape HTTP Cookie File\n"
+ "# http://curlm.haxx.se/rfc/cookie_spec.html\n"
+ "# This file was generated by libcurl! Edit at your own risk.\n\n",
+ out);
+ co = c->cookies;
+
+ while(co) {
+ format_ptr = get_netscape_format(co);
+ if (format_ptr == NULL) {
+ fprintf(out, "#\n# Fatal libcurl error\n");
+ if(!use_stdout)
+ fclose(out);
+ return 1;
+ }
+ fprintf(out, "%s\n", format_ptr);
+ free(format_ptr);
+ co=co->next;
+ }
+ }
+
+ if(!use_stdout)
+ fclose(out);
+
+ return 0;
+}
+
+struct curl_slist *Curl_cookie_list(struct SessionHandle *data)
+{
+ struct curl_slist *list = NULL;
+ struct curl_slist *beg;
+ struct Cookie *c;
+ char *line;
+
+ if ((data->cookies == NULL) ||
+ (data->cookies->numcookies == 0))
+ return NULL;
+
+ c = data->cookies->cookies;
+
+ beg = list;
+ while (c) {
+ /* fill the list with _all_ the cookies we know */
+ line = get_netscape_format(c);
+ if (line == NULL) {
+ /* get_netscape_format returns null only if we run out of memory */
+
+ curl_slist_free_all(beg); /* free some memory */
+ return NULL;
+ }
+ list = curl_slist_append(list, line);
+ free(line);
+ c = c->next;
+ }
+
+ return list;
+}
+
+#endif /* CURL_DISABLE_HTTP || CURL_DISABLE_COOKIES */
diff --git a/Utilities/cmcurl/cookie.h b/Utilities/cmcurl/cookie.h
new file mode 100644
index 0000000000..57c3acbddf
--- /dev/null
+++ b/Utilities/cmcurl/cookie.h
@@ -0,0 +1,107 @@
+#ifndef __COOKIE_H
+#define __COOKIE_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include <stdio.h>
+#if defined(WIN32)
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#endif
+
+#include <curl/curl.h>
+
+struct Cookie {
+ struct Cookie *next; /* next in the chain */
+ char *name; /* <this> = value */
+ char *value; /* name = <this> */
+ char *path; /* path = <this> */
+ char *domain; /* domain = <this> */
+ curl_off_t expires; /* expires = <this> */
+ char *expirestr; /* the plain text version */
+ bool tailmatch; /* weather we do tail-matchning of the domain name */
+
+ /* RFC 2109 keywords. Version=1 means 2109-compliant cookie sending */
+ char *version; /* Version = <value> */
+ char *maxage; /* Max-Age = <value> */
+
+ bool secure; /* whether the 'secure' keyword was used */
+ bool livecookie; /* updated from a server, not a stored file */
+};
+
+struct CookieInfo {
+ /* linked list of cookies we know of */
+ struct Cookie *cookies;
+
+ char *filename; /* file we read from/write to */
+ bool running; /* state info, for cookie adding information */
+ long numcookies; /* number of cookies in the "jar" */
+ bool newsession; /* new session, discard session cookies on load */
+};
+
+/* This is the maximum line length we accept for a cookie line. RFC 2109
+ section 6.3 says:
+
+ "at least 4096 bytes per cookie (as measured by the size of the characters
+ that comprise the cookie non-terminal in the syntax description of the
+ Set-Cookie header)"
+
+*/
+#define MAX_COOKIE_LINE 5000
+#define MAX_COOKIE_LINE_TXT "4999"
+
+/* This is the maximum length of a cookie name we deal with: */
+#define MAX_NAME 1024
+#define MAX_NAME_TXT "1023"
+
+struct SessionHandle;
+/*
+ * Add a cookie to the internal list of cookies. The domain and path arguments
+ * are only used if the header boolean is TRUE.
+ */
+
+struct Cookie *Curl_cookie_add(struct SessionHandle *data,
+ struct CookieInfo *, bool header, char *line,
+ char *domain, char *path);
+
+struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
+ char *, struct CookieInfo *, bool);
+struct Cookie *Curl_cookie_getlist(struct CookieInfo *, char *, char *, bool);
+void Curl_cookie_freelist(struct Cookie *);
+void Curl_cookie_clearall(struct CookieInfo *cookies);
+void Curl_cookie_clearsess(struct CookieInfo *cookies);
+void Curl_cookie_cleanup(struct CookieInfo *);
+int Curl_cookie_output(struct CookieInfo *, char *);
+
+#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
+#define Curl_cookie_list(x) NULL
+#define Curl_cookie_loadfiles(x) do { } while (0)
+#else
+struct curl_slist *Curl_cookie_list(struct SessionHandle *data);
+void Curl_cookie_loadfiles(struct SessionHandle *data);
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/curl/curl.h b/Utilities/cmcurl/curl/curl.h
new file mode 100644
index 0000000000..e586c4a8ca
--- /dev/null
+++ b/Utilities/cmcurl/curl/curl.h
@@ -0,0 +1,1644 @@
+#ifndef __CURL_CURL_H
+#define __CURL_CURL_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/* If you have problems, all libcurl docs and details are found here:
+ http://curl.haxx.se/libcurl/
+*/
+
+#include "curlver.h" /* the libcurl version defines */
+
+#include <stdio.h>
+#include <limits.h>
+
+/* The include stuff here below is mainly for time_t! */
+#ifdef vms
+# include <types.h>
+# include <time.h>
+#else
+# include <sys/types.h>
+# include <time.h>
+#endif /* defined (vms) */
+
+typedef void CURL;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Decorate exportable functions for Win32 DLL linking.
+ * This avoids using a .def file for building libcurl.dll.
+ */
+#if (defined(WIN32) || defined(_WIN32)) && !defined(CURL_STATICLIB)
+#if defined(BUILDING_LIBCURL)
+#define CURL_EXTERN __declspec(dllexport)
+#else
+#define CURL_EXTERN __declspec(dllimport)
+#endif
+#else
+
+#ifdef CURL_HIDDEN_SYMBOLS
+/*
+ * This definition is used to make external definitions visibile in the
+ * shared library when symbols are hidden by default. It makes no
+ * difference when compiling applications whether this is set or not,
+ * only when compiling the library.
+ */
+#define CURL_EXTERN CURL_EXTERN_SYMBOL
+#else
+#define CURL_EXTERN
+#endif
+#endif
+
+/*
+ * We want the typedef curl_off_t setup for large file support on all
+ * platforms. We also provide a CURL_FORMAT_OFF_T define to use in *printf
+ * format strings when outputting a variable of type curl_off_t.
+ *
+ * Note: "pocc -Ze" is MSVC compatibily mode and this sets _MSC_VER!
+ */
+
+#if (defined(_MSC_VER) && !defined(__POCC__)) || (defined(__LCC__) && defined(WIN32))
+/* MSVC */
+#ifdef _WIN32_WCE
+ typedef long curl_off_t;
+#define CURL_FORMAT_OFF_T "%ld"
+#else
+ typedef signed __int64 curl_off_t;
+#define CURL_FORMAT_OFF_T "%I64d"
+#endif
+#else /* (_MSC_VER && !__POCC__) || (__LCC__ && WIN32) */
+#if (defined(__GNUC__) && defined(WIN32)) || defined(__WATCOMC__)
+/* gcc on windows or Watcom */
+ typedef long long curl_off_t;
+#define CURL_FORMAT_OFF_T "%I64d"
+#else /* GCC or Watcom on Windows */
+
+/* "normal" POSIX approach, do note that this does not necessarily mean that
+ the type is >32 bits, see the SIZEOF_CURL_OFF_T define for that! */
+ typedef off_t curl_off_t;
+
+/* Check a range of defines to detect large file support. On Linux it seems
+ none of these are set by default, so if you don't explicitly switches on
+ large file support, this define will be made for "small file" support. */
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 0 /* to prevent warnings in the check below */
+#define UNDEF_FILE_OFFSET_BITS
+#endif
+#ifndef FILESIZEBITS
+#define FILESIZEBITS 0 /* to prevent warnings in the check below */
+#define UNDEF_FILESIZEBITS
+#endif
+
+#if defined(_LARGE_FILES) || (_FILE_OFFSET_BITS > 32) || (FILESIZEBITS > 32) \
+ || defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE)
+ /* For now, we assume at least one of these to be set for large files to
+ work! */
+#define CURL_FORMAT_OFF_T "%lld"
+#else /* LARGE_FILE support */
+#define CURL_FORMAT_OFF_T "%ld"
+#endif
+#endif /* GCC or Watcom on Windows */
+#endif /* (_MSC_VER && !__POCC__) || (__LCC__ && WIN32) */
+
+#ifdef UNDEF_FILE_OFFSET_BITS
+/* this was defined above for our checks, undefine it again */
+#undef _FILE_OFFSET_BITS
+#endif
+
+#ifdef UNDEF_FILESIZEBITS
+/* this was defined above for our checks, undefine it again */
+#undef FILESIZEBITS
+#endif
+
+#if defined(_WIN32) && !defined(WIN32)
+/* Chris Lewis mentioned that he doesn't get WIN32 defined, only _WIN32 so we
+ make this adjustment to catch this. */
+#define WIN32 1
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__GNUC__) && \
+ !defined(__CYGWIN__) || defined(__MINGW32__)
+#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H))
+/* The check above prevents the winsock2 inclusion if winsock.h already was
+ included, since they can't co-exist without problems */
+#include <winsock2.h>
+#endif
+#else
+
+/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
+ libc5-based Linux systems. Only include it on system that are known to
+ require it! */
+#if defined(_AIX) || defined(NETWARE) || defined(__NetBSD__) || defined(__minix)
+#include <sys/select.h>
+#endif
+
+#ifndef _WIN32_WCE
+#include <sys/socket.h>
+#endif
+#ifndef __WATCOMC__
+#include <sys/time.h>
+#endif
+#include <sys/types.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef curl_socket_typedef
+/* socket typedef */
+#ifdef WIN32
+typedef SOCKET curl_socket_t;
+#define CURL_SOCKET_BAD INVALID_SOCKET
+#else
+typedef int curl_socket_t;
+#define CURL_SOCKET_BAD -1
+#endif
+#define curl_socket_typedef
+#endif /* curl_socket_typedef */
+
+struct curl_httppost {
+ struct curl_httppost *next; /* next entry in the list */
+ char *name; /* pointer to allocated name */
+ long namelength; /* length of name length */
+ char *contents; /* pointer to allocated data contents */
+ long contentslength; /* length of contents field */
+ char *buffer; /* pointer to allocated buffer contents */
+ long bufferlength; /* length of buffer field */
+ char *contenttype; /* Content-Type */
+ struct curl_slist* contentheader; /* list of extra headers for this form */
+ struct curl_httppost *more; /* if one field name has more than one
+ file, this link should link to following
+ files */
+ long flags; /* as defined below */
+#define HTTPPOST_FILENAME (1<<0) /* specified content is a file name */
+#define HTTPPOST_READFILE (1<<1) /* specified content is a file name */
+#define HTTPPOST_PTRNAME (1<<2) /* name is only stored pointer
+ do not free in formfree */
+#define HTTPPOST_PTRCONTENTS (1<<3) /* contents is only stored pointer
+ do not free in formfree */
+#define HTTPPOST_BUFFER (1<<4) /* upload file from buffer */
+#define HTTPPOST_PTRBUFFER (1<<5) /* upload file from pointer contents */
+
+ char *showfilename; /* The file name to show. If not set, the
+ actual file name will be used (if this
+ is a file part) */
+};
+
+typedef int (*curl_progress_callback)(void *clientp,
+ double dltotal,
+ double dlnow,
+ double ultotal,
+ double ulnow);
+
+ /* Tests have proven that 20K is a very bad buffer size for uploads on
+ Windows, while 16K for some odd reason performed a lot better. */
+#define CURL_MAX_WRITE_SIZE 16384
+
+typedef size_t (*curl_write_callback)(char *buffer,
+ size_t size,
+ size_t nitems,
+ void *outstream);
+
+/* This is a return code for the read callback that, when returned, will
+ signal libcurl to immediately abort the current transfer. */
+#define CURL_READFUNC_ABORT 0x10000000
+typedef size_t (*curl_read_callback)(char *buffer,
+ size_t size,
+ size_t nitems,
+ void *instream);
+
+typedef enum {
+ CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */
+ CURLSOCKTYPE_LAST /* never use */
+} curlsocktype;
+
+typedef int (*curl_sockopt_callback)(void *clientp,
+ curl_socket_t curlfd,
+ curlsocktype purpose);
+
+#ifndef CURL_NO_OLDIES
+ /* not used since 7.10.8, will be removed in a future release */
+typedef int (*curl_passwd_callback)(void *clientp,
+ const char *prompt,
+ char *buffer,
+ int buflen);
+#endif
+
+typedef enum {
+ CURLIOE_OK, /* I/O operation successful */
+ CURLIOE_UNKNOWNCMD, /* command was unknown to callback */
+ CURLIOE_FAILRESTART, /* failed to restart the read */
+ CURLIOE_LAST /* never use */
+} curlioerr;
+
+typedef enum {
+ CURLIOCMD_NOP, /* no operation */
+ CURLIOCMD_RESTARTREAD, /* restart the read stream from start */
+ CURLIOCMD_LAST /* never use */
+} curliocmd;
+
+typedef curlioerr (*curl_ioctl_callback)(CURL *handle,
+ int cmd,
+ void *clientp);
+
+/*
+ * The following typedef's are signatures of malloc, free, realloc, strdup and
+ * calloc respectively. Function pointers of these types can be passed to the
+ * curl_global_init_mem() function to set user defined memory management
+ * callback routines.
+ */
+typedef void *(*curl_malloc_callback)(size_t size);
+typedef void (*curl_free_callback)(void *ptr);
+typedef void *(*curl_realloc_callback)(void *ptr, size_t size);
+typedef char *(*curl_strdup_callback)(const char *str);
+typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size);
+
+/* the kind of data that is passed to information_callback*/
+typedef enum {
+ CURLINFO_TEXT = 0,
+ CURLINFO_HEADER_IN, /* 1 */
+ CURLINFO_HEADER_OUT, /* 2 */
+ CURLINFO_DATA_IN, /* 3 */
+ CURLINFO_DATA_OUT, /* 4 */
+ CURLINFO_SSL_DATA_IN, /* 5 */
+ CURLINFO_SSL_DATA_OUT, /* 6 */
+ CURLINFO_END
+} curl_infotype;
+
+typedef int (*curl_debug_callback)
+ (CURL *handle, /* the handle/transfer this concerns */
+ curl_infotype type, /* what kind of data */
+ char *data, /* points to the data */
+ size_t size, /* size of the data pointed to */
+ void *userptr); /* whatever the user please */
+
+/* All possible error codes from all sorts of curl functions. Future versions
+ may return other values, stay prepared.
+
+ Always add new return codes last. Never *EVER* remove any. The return
+ codes must remain the same!
+ */
+
+typedef enum {
+ CURLE_OK = 0,
+ CURLE_UNSUPPORTED_PROTOCOL, /* 1 */
+ CURLE_FAILED_INIT, /* 2 */
+ CURLE_URL_MALFORMAT, /* 3 */
+ CURLE_NOT_BUILT_IN, /* 4 */
+ CURLE_COULDNT_RESOLVE_PROXY, /* 5 */
+ CURLE_COULDNT_RESOLVE_HOST, /* 6 */
+ CURLE_COULDNT_CONNECT, /* 7 */
+ CURLE_FTP_WEIRD_SERVER_REPLY, /* 8 */
+ CURLE_FTP_ACCESS_DENIED, /* 9 a service was denied by the FTP server
+ due to lack of access - when login fails
+ this is not returned. */
+ CURLE_FTP_USER_PASSWORD_INCORRECT, /* 10 - NOT USED */
+ CURLE_FTP_WEIRD_PASS_REPLY, /* 11 */
+ CURLE_FTP_WEIRD_USER_REPLY, /* 12 */
+ CURLE_FTP_WEIRD_PASV_REPLY, /* 13 */
+ CURLE_FTP_WEIRD_227_FORMAT, /* 14 */
+ CURLE_FTP_CANT_GET_HOST, /* 15 */
+ CURLE_FTP_CANT_RECONNECT, /* 16 */
+ CURLE_FTP_COULDNT_SET_BINARY, /* 17 */
+ CURLE_PARTIAL_FILE, /* 18 */
+ CURLE_FTP_COULDNT_RETR_FILE, /* 19 */
+ CURLE_FTP_WRITE_ERROR, /* 20 */
+ CURLE_FTP_QUOTE_ERROR, /* 21 */
+ CURLE_HTTP_RETURNED_ERROR, /* 22 */
+ CURLE_WRITE_ERROR, /* 23 */
+ CURLE_MALFORMAT_USER, /* 24 - NOT USED */
+ CURLE_FTP_COULDNT_STOR_FILE, /* 25 - failed FTP upload */
+ CURLE_READ_ERROR, /* 26 - could open/read from file */
+ CURLE_OUT_OF_MEMORY, /* 27 */
+ /* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error
+ instead of a memory allocation error if CURL_DOES_CONVERSIONS
+ is defined
+ */
+ CURLE_OPERATION_TIMEOUTED, /* 28 - the timeout time was reached */
+ CURLE_FTP_COULDNT_SET_ASCII, /* 29 - TYPE A failed */
+ CURLE_FTP_PORT_FAILED, /* 30 - FTP PORT operation failed */
+ CURLE_FTP_COULDNT_USE_REST, /* 31 - the REST command failed */
+ CURLE_FTP_COULDNT_GET_SIZE, /* 32 - the SIZE command failed */
+ CURLE_HTTP_RANGE_ERROR, /* 33 - RANGE "command" didn't work */
+ CURLE_HTTP_POST_ERROR, /* 34 */
+ CURLE_SSL_CONNECT_ERROR, /* 35 - wrong when connecting with SSL */
+ CURLE_BAD_DOWNLOAD_RESUME, /* 36 - couldn't resume download */
+ CURLE_FILE_COULDNT_READ_FILE, /* 37 */
+ CURLE_LDAP_CANNOT_BIND, /* 38 */
+ CURLE_LDAP_SEARCH_FAILED, /* 39 */
+ CURLE_LIBRARY_NOT_FOUND, /* 40 */
+ CURLE_FUNCTION_NOT_FOUND, /* 41 */
+ CURLE_ABORTED_BY_CALLBACK, /* 42 */
+ CURLE_BAD_FUNCTION_ARGUMENT, /* 43 */
+ CURLE_BAD_CALLING_ORDER, /* 44 - NOT USED */
+ CURLE_INTERFACE_FAILED, /* 45 - CURLOPT_INTERFACE failed */
+ CURLE_BAD_PASSWORD_ENTERED, /* 46 - NOT USED */
+ CURLE_TOO_MANY_REDIRECTS , /* 47 - catch endless re-direct loops */
+ CURLE_UNKNOWN_TELNET_OPTION, /* 48 - User specified an unknown option */
+ CURLE_TELNET_OPTION_SYNTAX , /* 49 - Malformed telnet option */
+ CURLE_OBSOLETE, /* 50 - NOT USED */
+ CURLE_SSL_PEER_CERTIFICATE, /* 51 - peer's certificate wasn't ok */
+ CURLE_GOT_NOTHING, /* 52 - when this is a specific error */
+ CURLE_SSL_ENGINE_NOTFOUND, /* 53 - SSL crypto engine not found */
+ CURLE_SSL_ENGINE_SETFAILED, /* 54 - can not set SSL crypto engine as
+ default */
+ CURLE_SEND_ERROR, /* 55 - failed sending network data */
+ CURLE_RECV_ERROR, /* 56 - failure in receiving network data */
+ CURLE_SHARE_IN_USE, /* 57 - share is in use */
+ CURLE_SSL_CERTPROBLEM, /* 58 - problem with the local certificate */
+ CURLE_SSL_CIPHER, /* 59 - couldn't use specified cipher */
+ CURLE_SSL_CACERT, /* 60 - problem with the CA cert (path?) */
+ CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized transfer encoding */
+ CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */
+ CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */
+ CURLE_FTP_SSL_FAILED, /* 64 - Requested FTP SSL level failed */
+ CURLE_SEND_FAIL_REWIND, /* 65 - Sending the data requires a rewind
+ that failed */
+ CURLE_SSL_ENGINE_INITFAILED, /* 66 - failed to initialise ENGINE */
+ CURLE_LOGIN_DENIED, /* 67 - user, password or similar was not
+ accepted and we failed to login */
+ CURLE_TFTP_NOTFOUND, /* 68 - file not found on server */
+ CURLE_TFTP_PERM, /* 69 - permission problem on server */
+ CURLE_TFTP_DISKFULL, /* 70 - out of disk space on server */
+ CURLE_TFTP_ILLEGAL, /* 71 - Illegal TFTP operation */
+ CURLE_TFTP_UNKNOWNID, /* 72 - Unknown transfer ID */
+ CURLE_TFTP_EXISTS, /* 73 - File already exists */
+ CURLE_TFTP_NOSUCHUSER, /* 74 - No such user */
+ CURLE_CONV_FAILED, /* 75 - conversion failed */
+ CURLE_CONV_REQD, /* 76 - caller must register conversion
+ callbacks using curl_easy_setopt options
+ CURLOPT_CONV_FROM_NETWORK_FUNCTION,
+ CURLOPT_CONV_TO_NETWORK_FUNCTION, and
+ CURLOPT_CONV_FROM_UTF8_FUNCTION */
+ CURLE_SSL_CACERT_BADFILE, /* 77 - could not load CACERT file, missing
+ or wrong format */
+ CURLE_REMOTE_FILE_NOT_FOUND, /* 78 - remote file not found */
+ CURLE_SSH, /* 79 - error from the SSH layer, somewhat
+ generic so the error message will be of
+ interest when this has happened */
+
+ CURLE_SSL_SHUTDOWN_FAILED, /* 80 - Failed to shut down the SSL
+ connection */
+ CURL_LAST /* never use! */
+} CURLcode;
+
+/* This prototype applies to all conversion callbacks */
+typedef CURLcode (*curl_conv_callback)(char *buffer, size_t length);
+
+typedef CURLcode (*curl_ssl_ctx_callback)(CURL *curl, /* easy handle */
+ void *ssl_ctx, /* actually an
+ OpenSSL SSL_CTX */
+ void *userptr);
+
+/* Make a spelling correction for the operation timed-out define */
+#define CURLE_OPERATION_TIMEDOUT CURLE_OPERATION_TIMEOUTED
+
+#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all
+ the obsolete stuff removed! */
+/* backwards compatibility with older names */
+#define CURLE_HTTP_NOT_FOUND CURLE_HTTP_RETURNED_ERROR
+#define CURLE_HTTP_PORT_FAILED CURLE_INTERFACE_FAILED
+#endif
+
+typedef enum {
+ CURLPROXY_HTTP = 0,
+ CURLPROXY_SOCKS4 = 4,
+ CURLPROXY_SOCKS5 = 5
+} curl_proxytype;
+
+#define CURLAUTH_NONE 0 /* nothing */
+#define CURLAUTH_BASIC (1<<0) /* Basic (default) */
+#define CURLAUTH_DIGEST (1<<1) /* Digest */
+#define CURLAUTH_GSSNEGOTIATE (1<<2) /* GSS-Negotiate */
+#define CURLAUTH_NTLM (1<<3) /* NTLM */
+#define CURLAUTH_ANY ~0 /* all types set */
+#define CURLAUTH_ANYSAFE (~CURLAUTH_BASIC)
+
+#define CURLSSH_AUTH_ANY ~0 /* all types supported by the server */
+#define CURLSSH_AUTH_NONE 0 /* none allowed, silly but complete */
+#define CURLSSH_AUTH_PUBLICKEY (1<<0) /* public/private key files */
+#define CURLSSH_AUTH_PASSWORD (1<<1) /* password */
+#define CURLSSH_AUTH_HOST (1<<2) /* host key files */
+#define CURLSSH_AUTH_KEYBOARD (1<<3) /* keyboard interactive */
+#define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY
+
+#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all
+ the obsolete stuff removed! */
+/* this was the error code 50 in 7.7.3 and a few earlier versions, this
+ is no longer used by libcurl but is instead #defined here only to not
+ make programs break */
+#define CURLE_ALREADY_COMPLETE 99999
+
+/* These are just to make older programs not break: */
+#define CURLE_FTP_PARTIAL_FILE CURLE_PARTIAL_FILE
+#define CURLE_FTP_BAD_DOWNLOAD_RESUME CURLE_BAD_DOWNLOAD_RESUME
+#endif
+
+#define CURL_ERROR_SIZE 256
+
+/* parameter for the CURLOPT_FTP_SSL option */
+typedef enum {
+ CURLFTPSSL_NONE, /* do not attempt to use SSL */
+ CURLFTPSSL_TRY, /* try using SSL, proceed anyway otherwise */
+ CURLFTPSSL_CONTROL, /* SSL for the control connection or fail */
+ CURLFTPSSL_ALL, /* SSL for all communication or fail */
+ CURLFTPSSL_LAST /* not an option, never use */
+} curl_ftpssl;
+
+/* parameter for the CURLOPT_FTPSSLAUTH option */
+typedef enum {
+ CURLFTPAUTH_DEFAULT, /* let libcurl decide */
+ CURLFTPAUTH_SSL, /* use "AUTH SSL" */
+ CURLFTPAUTH_TLS, /* use "AUTH TLS" */
+ CURLFTPAUTH_LAST /* not an option, never use */
+} curl_ftpauth;
+
+/* parameter for the CURLOPT_FTP_FILEMETHOD option */
+typedef enum {
+ CURLFTPMETHOD_DEFAULT, /* let libcurl pick */
+ CURLFTPMETHOD_MULTICWD, /* single CWD operation for each path part */
+ CURLFTPMETHOD_NOCWD, /* no CWD at all */
+ CURLFTPMETHOD_SINGLECWD, /* one CWD to full dir, then work on file */
+ CURLFTPMETHOD_LAST /* not an option, never use */
+} curl_ftpmethod;
+
+/* long may be 32 or 64 bits, but we should never depend on anything else
+ but 32 */
+#define CURLOPTTYPE_LONG 0
+#define CURLOPTTYPE_OBJECTPOINT 10000
+#define CURLOPTTYPE_FUNCTIONPOINT 20000
+#define CURLOPTTYPE_OFF_T 30000
+
+/* name is uppercase CURLOPT_<name>,
+ type is one of the defined CURLOPTTYPE_<type>
+ number is unique identifier */
+#ifdef CINIT
+#undef CINIT
+#endif
+/*
+ * Figure out if we can use the ## operator, which is supported by ISO/ANSI C
+ * and C++. Some compilers support it without setting __STDC__ or __cplusplus
+ * so we need to carefully check for them too. We don't use configure-checks
+ * for these since we want these headers to remain generic and working for all
+ * platforms.
+ */
+#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
+ defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
+ defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__)
+ /* This compiler is believed to have an ISO compatible preprocessor */
+#define CURL_ISOCPP
+#else
+ /* This compiler is believed NOT to have an ISO compatible preprocessor */
+#undef CURL_ISOCPP
+#endif
+
+#ifdef CURL_ISOCPP
+#define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type + number
+#else
+/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */
+#define LONG CURLOPTTYPE_LONG
+#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT
+#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT
+#define OFF_T CURLOPTTYPE_OFF_T
+#define CINIT(name,type,number) CURLOPT_/**/name = type + number
+#endif
+
+/*
+ * This macro-mania below setups the CURLOPT_[what] enum, to be used with
+ * curl_easy_setopt(). The first argument in the CINIT() macro is the [what]
+ * word.
+ */
+
+typedef enum {
+ /* This is the FILE * or void * the regular output should be written to. */
+ CINIT(FILE, OBJECTPOINT, 1),
+
+ /* The full URL to get/put */
+ CINIT(URL, OBJECTPOINT, 2),
+
+ /* Port number to connect to, if other than default. */
+ CINIT(PORT, LONG, 3),
+
+ /* Name of proxy to use. */
+ CINIT(PROXY, OBJECTPOINT, 4),
+
+ /* "name:password" to use when fetching. */
+ CINIT(USERPWD, OBJECTPOINT, 5),
+
+ /* "name:password" to use with proxy. */
+ CINIT(PROXYUSERPWD, OBJECTPOINT, 6),
+
+ /* Range to get, specified as an ASCII string. */
+ CINIT(RANGE, OBJECTPOINT, 7),
+
+ /* not used */
+
+ /* Specified file stream to upload from (use as input): */
+ CINIT(INFILE, OBJECTPOINT, 9),
+
+ /* Buffer to receive error messages in, must be at least CURL_ERROR_SIZE
+ * bytes big. If this is not used, error messages go to stderr instead: */
+ CINIT(ERRORBUFFER, OBJECTPOINT, 10),
+
+ /* Function that will be called to store the output (instead of fwrite). The
+ * parameters will use fwrite() syntax, make sure to follow them. */
+ CINIT(WRITEFUNCTION, FUNCTIONPOINT, 11),
+
+ /* Function that will be called to read the input (instead of fread). The
+ * parameters will use fread() syntax, make sure to follow them. */
+ CINIT(READFUNCTION, FUNCTIONPOINT, 12),
+
+ /* Time-out the read operation after this amount of seconds */
+ CINIT(TIMEOUT, LONG, 13),
+
+ /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about
+ * how large the file being sent really is. That allows better error
+ * checking and better verifies that the upload was succcessful. -1 means
+ * unknown size.
+ *
+ * For large file support, there is also a _LARGE version of the key
+ * which takes an off_t type, allowing platforms with larger off_t
+ * sizes to handle larger files. See below for INFILESIZE_LARGE.
+ */
+ CINIT(INFILESIZE, LONG, 14),
+
+ /* POST input fields. */
+ CINIT(POSTFIELDS, OBJECTPOINT, 15),
+
+ /* Set the referer page (needed by some CGIs) */
+ CINIT(REFERER, OBJECTPOINT, 16),
+
+ /* Set the FTP PORT string (interface name, named or numerical IP address)
+ Use i.e '-' to use default address. */
+ CINIT(FTPPORT, OBJECTPOINT, 17),
+
+ /* Set the User-Agent string (examined by some CGIs) */
+ CINIT(USERAGENT, OBJECTPOINT, 18),
+
+ /* If the download receives less than "low speed limit" bytes/second
+ * during "low speed time" seconds, the operations is aborted.
+ * You could i.e if you have a pretty high speed connection, abort if
+ * it is less than 2000 bytes/sec during 20 seconds.
+ */
+
+ /* Set the "low speed limit" */
+ CINIT(LOW_SPEED_LIMIT, LONG , 19),
+
+ /* Set the "low speed time" */
+ CINIT(LOW_SPEED_TIME, LONG, 20),
+
+ /* Set the continuation offset.
+ *
+ * Note there is also a _LARGE version of this key which uses
+ * off_t types, allowing for large file offsets on platforms which
+ * use larger-than-32-bit off_t's. Look below for RESUME_FROM_LARGE.
+ */
+ CINIT(RESUME_FROM, LONG, 21),
+
+ /* Set cookie in request: */
+ CINIT(COOKIE, OBJECTPOINT, 22),
+
+ /* This points to a linked list of headers, struct curl_slist kind */
+ CINIT(HTTPHEADER, OBJECTPOINT, 23),
+
+ /* This points to a linked list of post entries, struct HttpPost */
+ CINIT(HTTPPOST, OBJECTPOINT, 24),
+
+ /* name of the file keeping your private SSL-certificate */
+ CINIT(SSLCERT, OBJECTPOINT, 25),
+
+ /* password for the SSL-private key, keep this for compatibility */
+ CINIT(SSLCERTPASSWD, OBJECTPOINT, 26),
+ /* password for the SSL private key */
+ CINIT(SSLKEYPASSWD, OBJECTPOINT, 26),
+
+ /* send TYPE parameter? */
+ CINIT(CRLF, LONG, 27),
+
+ /* send linked-list of QUOTE commands */
+ CINIT(QUOTE, OBJECTPOINT, 28),
+
+ /* send FILE * or void * to store headers to, if you use a callback it
+ is simply passed to the callback unmodified */
+ CINIT(WRITEHEADER, OBJECTPOINT, 29),
+
+ /* point to a file to read the initial cookies from, also enables
+ "cookie awareness" */
+ CINIT(COOKIEFILE, OBJECTPOINT, 31),
+
+ /* What version to specifly try to use.
+ See CURL_SSLVERSION defines below. */
+ CINIT(SSLVERSION, LONG, 32),
+
+ /* What kind of HTTP time condition to use, see defines */
+ CINIT(TIMECONDITION, LONG, 33),
+
+ /* Time to use with the above condition. Specified in number of seconds
+ since 1 Jan 1970 */
+ CINIT(TIMEVALUE, LONG, 34),
+
+ /* 35 = OBSOLETE */
+
+ /* Custom request, for customizing the get command like
+ HTTP: DELETE, TRACE and others
+ FTP: to use a different list command
+ */
+ CINIT(CUSTOMREQUEST, OBJECTPOINT, 36),
+
+ /* HTTP request, for odd commands like DELETE, TRACE and others */
+ CINIT(STDERR, OBJECTPOINT, 37),
+
+ /* 38 is not used */
+
+ /* send linked-list of post-transfer QUOTE commands */
+ CINIT(POSTQUOTE, OBJECTPOINT, 39),
+
+ /* Pass a pointer to string of the output using full variable-replacement
+ as described elsewhere. */
+ CINIT(WRITEINFO, OBJECTPOINT, 40),
+
+ CINIT(VERBOSE, LONG, 41), /* talk a lot */
+ CINIT(HEADER, LONG, 42), /* throw the header out too */
+ CINIT(NOPROGRESS, LONG, 43), /* shut off the progress meter */
+ CINIT(NOBODY, LONG, 44), /* use HEAD to get http document */
+ CINIT(FAILONERROR, LONG, 45), /* no output on http error codes >= 300 */
+ CINIT(UPLOAD, LONG, 46), /* this is an upload */
+ CINIT(POST, LONG, 47), /* HTTP POST method */
+ CINIT(FTPLISTONLY, LONG, 48), /* Use NLST when listing ftp dir */
+
+ CINIT(FTPAPPEND, LONG, 50), /* Append instead of overwrite on upload! */
+
+ /* Specify whether to read the user+password from the .netrc or the URL.
+ * This must be one of the CURL_NETRC_* enums below. */
+ CINIT(NETRC, LONG, 51),
+
+ CINIT(FOLLOWLOCATION, LONG, 52), /* use Location: Luke! */
+
+ CINIT(TRANSFERTEXT, LONG, 53), /* transfer data in text/ASCII format */
+ CINIT(PUT, LONG, 54), /* HTTP PUT */
+
+ /* 55 = OBSOLETE */
+
+ /* Function that will be called instead of the internal progress display
+ * function. This function should be defined as the curl_progress_callback
+ * prototype defines. */
+ CINIT(PROGRESSFUNCTION, FUNCTIONPOINT, 56),
+
+ /* Data passed to the progress callback */
+ CINIT(PROGRESSDATA, OBJECTPOINT, 57),
+
+ /* We want the referer field set automatically when following locations */
+ CINIT(AUTOREFERER, LONG, 58),
+
+ /* Port of the proxy, can be set in the proxy string as well with:
+ "[host]:[port]" */
+ CINIT(PROXYPORT, LONG, 59),
+
+ /* size of the POST input data, if strlen() is not good to use */
+ CINIT(POSTFIELDSIZE, LONG, 60),
+
+ /* tunnel non-http operations through a HTTP proxy */
+ CINIT(HTTPPROXYTUNNEL, LONG, 61),
+
+ /* Set the interface string to use as outgoing network interface */
+ CINIT(INTERFACE, OBJECTPOINT, 62),
+
+ /* Set the krb4 security level, this also enables krb4 awareness. This is a
+ * string, 'clear', 'safe', 'confidential' or 'private'. If the string is
+ * set but doesn't match one of these, 'private' will be used. */
+ CINIT(KRB4LEVEL, OBJECTPOINT, 63),
+
+ /* Set if we should verify the peer in ssl handshake, set 1 to verify. */
+ CINIT(SSL_VERIFYPEER, LONG, 64),
+
+ /* The CApath or CAfile used to validate the peer certificate
+ this option is used only if SSL_VERIFYPEER is true */
+ CINIT(CAINFO, OBJECTPOINT, 65),
+
+ /* 66 = OBSOLETE */
+ /* 67 = OBSOLETE */
+
+ /* Maximum number of http redirects to follow */
+ CINIT(MAXREDIRS, LONG, 68),
+
+ /* Pass a long set to 1 to get the date of the requested document (if
+ possible)! Pass a zero to shut it off. */
+ CINIT(FILETIME, LONG, 69),
+
+ /* This points to a linked list of telnet options */
+ CINIT(TELNETOPTIONS, OBJECTPOINT, 70),
+
+ /* Max amount of cached alive connections */
+ CINIT(MAXCONNECTS, LONG, 71),
+
+ /* What policy to use when closing connections when the cache is filled
+ up */
+ CINIT(CLOSEPOLICY, LONG, 72),
+
+ /* 73 = OBSOLETE */
+
+ /* Set to explicitly use a new connection for the upcoming transfer.
+ Do not use this unless you're absolutely sure of this, as it makes the
+ operation slower and is less friendly for the network. */
+ CINIT(FRESH_CONNECT, LONG, 74),
+
+ /* Set to explicitly forbid the upcoming transfer's connection to be re-used
+ when done. Do not use this unless you're absolutely sure of this, as it
+ makes the operation slower and is less friendly for the network. */
+ CINIT(FORBID_REUSE, LONG, 75),
+
+ /* Set to a file name that contains random data for libcurl to use to
+ seed the random engine when doing SSL connects. */
+ CINIT(RANDOM_FILE, OBJECTPOINT, 76),
+
+ /* Set to the Entropy Gathering Daemon socket pathname */
+ CINIT(EGDSOCKET, OBJECTPOINT, 77),
+
+ /* Time-out connect operations after this amount of seconds, if connects
+ are OK within this time, then fine... This only aborts the connect
+ phase. [Only works on unix-style/SIGALRM operating systems] */
+ CINIT(CONNECTTIMEOUT, LONG, 78),
+
+ /* Function that will be called to store headers (instead of fwrite). The
+ * parameters will use fwrite() syntax, make sure to follow them. */
+ CINIT(HEADERFUNCTION, FUNCTIONPOINT, 79),
+
+ /* Set this to force the HTTP request to get back to GET. Only really usable
+ if POST, PUT or a custom request have been used first.
+ */
+ CINIT(HTTPGET, LONG, 80),
+
+ /* Set if we should verify the Common name from the peer certificate in ssl
+ * handshake, set 1 to check existence, 2 to ensure that it matches the
+ * provided hostname. */
+ CINIT(SSL_VERIFYHOST, LONG, 81),
+
+ /* Specify which file name to write all known cookies in after completed
+ operation. Set file name to "-" (dash) to make it go to stdout. */
+ CINIT(COOKIEJAR, OBJECTPOINT, 82),
+
+ /* Specify which SSL ciphers to use */
+ CINIT(SSL_CIPHER_LIST, OBJECTPOINT, 83),
+
+ /* Specify which HTTP version to use! This must be set to one of the
+ CURL_HTTP_VERSION* enums set below. */
+ CINIT(HTTP_VERSION, LONG, 84),
+
+ /* Specificly switch on or off the FTP engine's use of the EPSV command. By
+ default, that one will always be attempted before the more traditional
+ PASV command. */
+ CINIT(FTP_USE_EPSV, LONG, 85),
+
+ /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */
+ CINIT(SSLCERTTYPE, OBJECTPOINT, 86),
+
+ /* name of the file keeping your private SSL-key */
+ CINIT(SSLKEY, OBJECTPOINT, 87),
+
+ /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */
+ CINIT(SSLKEYTYPE, OBJECTPOINT, 88),
+
+ /* crypto engine for the SSL-sub system */
+ CINIT(SSLENGINE, OBJECTPOINT, 89),
+
+ /* set the crypto engine for the SSL-sub system as default
+ the param has no meaning...
+ */
+ CINIT(SSLENGINE_DEFAULT, LONG, 90),
+
+ /* Non-zero value means to use the global dns cache */
+ CINIT(DNS_USE_GLOBAL_CACHE, LONG, 91), /* To becomeO BSOLETE soon */
+
+ /* DNS cache timeout */
+ CINIT(DNS_CACHE_TIMEOUT, LONG, 92),
+
+ /* send linked-list of pre-transfer QUOTE commands (Wesley Laxton)*/
+ CINIT(PREQUOTE, OBJECTPOINT, 93),
+
+ /* set the debug function */
+ CINIT(DEBUGFUNCTION, FUNCTIONPOINT, 94),
+
+ /* set the data for the debug function */
+ CINIT(DEBUGDATA, OBJECTPOINT, 95),
+
+ /* mark this as start of a cookie session */
+ CINIT(COOKIESESSION, LONG, 96),
+
+ /* The CApath directory used to validate the peer certificate
+ this option is used only if SSL_VERIFYPEER is true */
+ CINIT(CAPATH, OBJECTPOINT, 97),
+
+ /* Instruct libcurl to use a smaller receive buffer */
+ CINIT(BUFFERSIZE, LONG, 98),
+
+ /* Instruct libcurl to not use any signal/alarm handlers, even when using
+ timeouts. This option is useful for multi-threaded applications.
+ See libcurl-the-guide for more background information. */
+ CINIT(NOSIGNAL, LONG, 99),
+
+ /* Provide a CURLShare for mutexing non-ts data */
+ CINIT(SHARE, OBJECTPOINT, 100),
+
+ /* indicates type of proxy. accepted values are CURLPROXY_HTTP (default),
+ CURLPROXY_SOCKS4 and CURLPROXY_SOCKS5. */
+ CINIT(PROXYTYPE, LONG, 101),
+
+ /* Set the Accept-Encoding string. Use this to tell a server you would like
+ the response to be compressed. */
+ CINIT(ENCODING, OBJECTPOINT, 102),
+
+ /* Set pointer to private data */
+ CINIT(PRIVATE, OBJECTPOINT, 103),
+
+ /* Set aliases for HTTP 200 in the HTTP Response header */
+ CINIT(HTTP200ALIASES, OBJECTPOINT, 104),
+
+ /* Continue to send authentication (user+password) when following locations,
+ even when hostname changed. This can potentionally send off the name
+ and password to whatever host the server decides. */
+ CINIT(UNRESTRICTED_AUTH, LONG, 105),
+
+ /* Specificly switch on or off the FTP engine's use of the EPRT command ( it
+ also disables the LPRT attempt). By default, those ones will always be
+ attempted before the good old traditional PORT command. */
+ CINIT(FTP_USE_EPRT, LONG, 106),
+
+ /* Set this to a bitmask value to enable the particular authentications
+ methods you like. Use this in combination with CURLOPT_USERPWD.
+ Note that setting multiple bits may cause extra network round-trips. */
+ CINIT(HTTPAUTH, LONG, 107),
+
+ /* Set the ssl context callback function, currently only for OpenSSL ssl_ctx
+ in second argument. The function must be matching the
+ curl_ssl_ctx_callback proto. */
+ CINIT(SSL_CTX_FUNCTION, FUNCTIONPOINT, 108),
+
+ /* Set the userdata for the ssl context callback function's third
+ argument */
+ CINIT(SSL_CTX_DATA, OBJECTPOINT, 109),
+
+ /* FTP Option that causes missing dirs to be created on the remote server */
+ CINIT(FTP_CREATE_MISSING_DIRS, LONG, 110),
+
+ /* Set this to a bitmask value to enable the particular authentications
+ methods you like. Use this in combination with CURLOPT_PROXYUSERPWD.
+ Note that setting multiple bits may cause extra network round-trips. */
+ CINIT(PROXYAUTH, LONG, 111),
+
+ /* FTP option that changes the timeout, in seconds, associated with
+ getting a response. This is different from transfer timeout time and
+ essentially places a demand on the FTP server to acknowledge commands
+ in a timely manner. */
+ CINIT(FTP_RESPONSE_TIMEOUT, LONG , 112),
+
+ /* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to
+ tell libcurl to resolve names to those IP versions only. This only has
+ affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */
+ CINIT(IPRESOLVE, LONG, 113),
+
+ /* Set this option to limit the size of a file that will be downloaded from
+ an HTTP or FTP server.
+
+ Note there is also _LARGE version which adds large file support for
+ platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */
+ CINIT(MAXFILESIZE, LONG, 114),
+
+ /* See the comment for INFILESIZE above, but in short, specifies
+ * the size of the file being uploaded. -1 means unknown.
+ */
+ CINIT(INFILESIZE_LARGE, OFF_T, 115),
+
+ /* Sets the continuation offset. There is also a LONG version of this;
+ * look above for RESUME_FROM.
+ */
+ CINIT(RESUME_FROM_LARGE, OFF_T, 116),
+
+ /* Sets the maximum size of data that will be downloaded from
+ * an HTTP or FTP server. See MAXFILESIZE above for the LONG version.
+ */
+ CINIT(MAXFILESIZE_LARGE, OFF_T, 117),
+
+ /* Set this option to the file name of your .netrc file you want libcurl
+ to parse (using the CURLOPT_NETRC option). If not set, libcurl will do
+ a poor attempt to find the user's home directory and check for a .netrc
+ file in there. */
+ CINIT(NETRC_FILE, OBJECTPOINT, 118),
+
+ /* Enable SSL/TLS for FTP, pick one of:
+ CURLFTPSSL_TRY - try using SSL, proceed anyway otherwise
+ CURLFTPSSL_CONTROL - SSL for the control connection or fail
+ CURLFTPSSL_ALL - SSL for all communication or fail
+ */
+ CINIT(FTP_SSL, LONG, 119),
+
+ /* The _LARGE version of the standard POSTFIELDSIZE option */
+ CINIT(POSTFIELDSIZE_LARGE, OFF_T, 120),
+
+ /* Enable/disable the TCP Nagle algorithm */
+ CINIT(TCP_NODELAY, LONG, 121),
+
+ /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
+ /* 123 OBSOLETE. Gone in 7.16.0 */
+ /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
+ /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
+ /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
+ /* 127 OBSOLETE. Gone in 7.16.0 */
+ /* 128 OBSOLETE. Gone in 7.16.0 */
+
+ /* When FTP over SSL/TLS is selected (with CURLOPT_FTP_SSL), this option
+ can be used to change libcurl's default action which is to first try
+ "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK
+ response has been received.
+
+ Available parameters are:
+ CURLFTPAUTH_DEFAULT - let libcurl decide
+ CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS
+ CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL
+ */
+ CINIT(FTPSSLAUTH, LONG, 129),
+
+ CINIT(IOCTLFUNCTION, FUNCTIONPOINT, 130),
+ CINIT(IOCTLDATA, OBJECTPOINT, 131),
+
+ /* 132 OBSOLETE. Gone in 7.16.0 */
+ /* 133 OBSOLETE. Gone in 7.16.0 */
+
+ /* zero terminated string for pass on to the FTP server when asked for
+ "account" info */
+ CINIT(FTP_ACCOUNT, OBJECTPOINT, 134),
+
+ /* feed cookies into cookie engine */
+ CINIT(COOKIELIST, OBJECTPOINT, 135),
+
+ /* ignore Content-Length */
+ CINIT(IGNORE_CONTENT_LENGTH, LONG, 136),
+
+ /* Set to non-zero to skip the IP address received in a 227 PASV FTP server
+ response. Typically used for FTP-SSL purposes but is not restricted to
+ that. libcurl will then instead use the same IP address it used for the
+ control connection. */
+ CINIT(FTP_SKIP_PASV_IP, LONG, 137),
+
+ /* Select "file method" to use when doing FTP, see the curl_ftpmethod
+ above. */
+ CINIT(FTP_FILEMETHOD, LONG, 138),
+
+ /* Local port number to bind the socket to */
+ CINIT(LOCALPORT, LONG, 139),
+
+ /* Number of ports to try, including the first one set with LOCALPORT.
+ Thus, setting it to 1 will make no additional attempts but the first.
+ */
+ CINIT(LOCALPORTRANGE, LONG, 140),
+
+ /* no transfer, set up connection and let application use the socket by
+ extracting it with CURLINFO_LASTSOCKET */
+ CINIT(CONNECT_ONLY, LONG, 141),
+
+ /* Function that will be called to convert from the
+ network encoding (instead of using the iconv calls in libcurl) */
+ CINIT(CONV_FROM_NETWORK_FUNCTION, FUNCTIONPOINT, 142),
+
+ /* Function that will be called to convert to the
+ network encoding (instead of using the iconv calls in libcurl) */
+ CINIT(CONV_TO_NETWORK_FUNCTION, FUNCTIONPOINT, 143),
+
+ /* Function that will be called to convert from UTF8
+ (instead of using the iconv calls in libcurl)
+ Note that this is used only for SSL certificate processing */
+ CINIT(CONV_FROM_UTF8_FUNCTION, FUNCTIONPOINT, 144),
+
+ /* if the connection proceeds too quickly then need to slow it down */
+ /* limit-rate: maximum number of bytes per second to send or receive */
+ CINIT(MAX_SEND_SPEED_LARGE, OFF_T, 145),
+ CINIT(MAX_RECV_SPEED_LARGE, OFF_T, 146),
+
+ /* Pointer to command string to send if USER/PASS fails. */
+ CINIT(FTP_ALTERNATIVE_TO_USER, OBJECTPOINT, 147),
+
+ /* callback function for setting socket options */
+ CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 148),
+ CINIT(SOCKOPTDATA, OBJECTPOINT, 149),
+
+ /* set to 0 to disable session ID re-use for this transfer, default is
+ enabled (== 1) */
+ CINIT(SSL_SESSIONID_CACHE, LONG, 150),
+
+ /* allowed SSH authentication methods */
+ CINIT(SSH_AUTH_TYPES, LONG, 151),
+
+ /* Used by scp/sftp to do public/private key authentication */
+ CINIT(SSH_PUBLIC_KEYFILE, OBJECTPOINT, 152),
+ CINIT(SSH_PRIVATE_KEYFILE, OBJECTPOINT, 153),
+
+ /* Send CCC (Clear Command Channel) after authentication */
+ CINIT(FTP_SSL_CCC, LONG, 154),
+
+ CURLOPT_LASTENTRY /* the last unused */
+} CURLoption;
+
+ /* Below here follows defines for the CURLOPT_IPRESOLVE option. If a host
+ name resolves addresses using more than one IP protocol version, this
+ option might be handy to force libcurl to use a specific IP version. */
+#define CURL_IPRESOLVE_WHATEVER 0 /* default, resolves addresses to all IP
+ versions that your system allows */
+#define CURL_IPRESOLVE_V4 1 /* resolve to ipv4 addresses */
+#define CURL_IPRESOLVE_V6 2 /* resolve to ipv6 addresses */
+
+ /* three convenient "aliases" that follow the name scheme better */
+#define CURLOPT_WRITEDATA CURLOPT_FILE
+#define CURLOPT_READDATA CURLOPT_INFILE
+#define CURLOPT_HEADERDATA CURLOPT_WRITEHEADER
+
+#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all
+ the obsolete stuff removed! */
+#else
+/* This is set if CURL_NO_OLDIES is defined at compile-time */
+#undef CURLOPT_DNS_USE_GLOBAL_CACHE /* soon obsolete */
+#endif
+
+
+ /* These enums are for use with the CURLOPT_HTTP_VERSION option. */
+enum {
+ CURL_HTTP_VERSION_NONE, /* setting this means we don't care, and that we'd
+ like the library to choose the best possible
+ for us! */
+ CURL_HTTP_VERSION_1_0, /* please use HTTP 1.0 in the request */
+ CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 in the request */
+
+ CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */
+};
+
+ /* These enums are for use with the CURLOPT_NETRC option. */
+enum CURL_NETRC_OPTION {
+ CURL_NETRC_IGNORED, /* The .netrc will never be read.
+ * This is the default. */
+ CURL_NETRC_OPTIONAL, /* A user:password in the URL will be preferred
+ * to one in the .netrc. */
+ CURL_NETRC_REQUIRED, /* A user:password in the URL will be ignored.
+ * Unless one is set programmatically, the .netrc
+ * will be queried. */
+ CURL_NETRC_LAST
+};
+
+enum {
+ CURL_SSLVERSION_DEFAULT,
+ CURL_SSLVERSION_TLSv1,
+ CURL_SSLVERSION_SSLv2,
+ CURL_SSLVERSION_SSLv3,
+
+ CURL_SSLVERSION_LAST /* never use, keep last */
+};
+
+
+typedef enum {
+ CURL_TIMECOND_NONE,
+
+ CURL_TIMECOND_IFMODSINCE,
+ CURL_TIMECOND_IFUNMODSINCE,
+ CURL_TIMECOND_LASTMOD,
+
+ CURL_TIMECOND_LAST
+} curl_TimeCond;
+
+#ifdef __cplusplus
+}
+#endif
+
+#if defined __BEOS__ || defined __HAIKU__
+#include <support/SupportDefs.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* curl_strequal() and curl_strnequal() are subject for removal in a future
+ libcurl, see lib/README.curlx for details */
+CURL_EXTERN int (curl_strequal)(const char *s1, const char *s2);
+CURL_EXTERN int (curl_strnequal)(const char *s1, const char *s2, size_t n);
+
+/* name is uppercase CURLFORM_<name> */
+#ifdef CFINIT
+#undef CFINIT
+#endif
+
+#ifdef CURL_ISOCPP
+#define CFINIT(name) CURLFORM_ ## name
+#else
+/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */
+#define CFINIT(name) CURLFORM_/**/name
+#endif
+
+typedef enum {
+ CFINIT(NOTHING), /********* the first one is unused ************/
+
+ /* */
+ CFINIT(COPYNAME),
+ CFINIT(PTRNAME),
+ CFINIT(NAMELENGTH),
+ CFINIT(COPYCONTENTS),
+ CFINIT(PTRCONTENTS),
+ CFINIT(CONTENTSLENGTH),
+ CFINIT(FILECONTENT),
+ CFINIT(ARRAY),
+ CFINIT(OBSOLETE),
+ CFINIT(FILE),
+
+ CFINIT(BUFFER),
+ CFINIT(BUFFERPTR),
+ CFINIT(BUFFERLENGTH),
+
+ CFINIT(CONTENTTYPE),
+ CFINIT(CONTENTHEADER),
+ CFINIT(FILENAME),
+ CFINIT(END),
+ CFINIT(OBSOLETE2),
+
+ CURLFORM_LASTENTRY /* the last unusued */
+} CURLformoption;
+
+#undef CFINIT /* done */
+
+/* structure to be used as parameter for CURLFORM_ARRAY */
+struct curl_forms {
+ CURLformoption option;
+ const char *value;
+};
+
+/* use this for multipart formpost building */
+/* Returns code for curl_formadd()
+ *
+ * Returns:
+ * CURL_FORMADD_OK on success
+ * CURL_FORMADD_MEMORY if the FormInfo allocation fails
+ * CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form
+ * CURL_FORMADD_NULL if a null pointer was given for a char
+ * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed
+ * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used
+ * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error)
+ * CURL_FORMADD_MEMORY if a HttpPost struct cannot be allocated
+ * CURL_FORMADD_MEMORY if some allocation for string copying failed.
+ * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array
+ *
+ ***************************************************************************/
+typedef enum {
+ CURL_FORMADD_OK, /* first, no error */
+
+ CURL_FORMADD_MEMORY,
+ CURL_FORMADD_OPTION_TWICE,
+ CURL_FORMADD_NULL,
+ CURL_FORMADD_UNKNOWN_OPTION,
+ CURL_FORMADD_INCOMPLETE,
+ CURL_FORMADD_ILLEGAL_ARRAY,
+ CURL_FORMADD_DISABLED, /* libcurl was built with this disabled */
+
+ CURL_FORMADD_LAST /* last */
+} CURLFORMcode;
+
+/*
+ * NAME curl_formadd()
+ *
+ * DESCRIPTION
+ *
+ * Pretty advanved function for building multi-part formposts. Each invoke
+ * adds one part that together construct a full post. Then use
+ * CURLOPT_HTTPPOST to send it off to libcurl.
+ */
+CURL_EXTERN CURLFORMcode curl_formadd(struct curl_httppost **httppost,
+ struct curl_httppost **last_post,
+ ...);
+
+/*
+ * callback function for curl_formget()
+ * The void *arg pointer will be the one passed as second argument to curl_formget().
+ * The character buffer passed to it must not be freed.
+ * Should return the buffer length passed to it as the argument "len" on success.
+ */
+typedef size_t (*curl_formget_callback)(void *arg, const char *buf, size_t len);
+
+/*
+ * NAME curl_formget()
+ *
+ * DESCRIPTION
+ *
+ * Serialize a curl_httppost struct built with curl_formadd().
+ * Accepts a void pointer as second argument which will be passed to
+ * the curl_formget_callback function.
+ * Returns 0 on success.
+ */
+CURL_EXTERN int curl_formget(struct curl_httppost *form, void *arg,
+ curl_formget_callback append);
+/*
+ * NAME curl_formfree()
+ *
+ * DESCRIPTION
+ *
+ * Free a multipart formpost previously built with curl_formadd().
+ */
+CURL_EXTERN void curl_formfree(struct curl_httppost *form);
+
+/*
+ * NAME curl_getenv()
+ *
+ * DESCRIPTION
+ *
+ * Returns a malloc()'ed string that MUST be curl_free()ed after usage is
+ * complete. DEPRECATED - see lib/README.curlx
+ */
+CURL_EXTERN char *curl_getenv(const char *variable);
+
+/*
+ * NAME curl_version()
+ *
+ * DESCRIPTION
+ *
+ * Returns a static ascii string of the libcurl version.
+ */
+CURL_EXTERN char *curl_version(void);
+
+/*
+ * NAME curl_easy_escape()
+ *
+ * DESCRIPTION
+ *
+ * Escapes URL strings (converts all letters consider illegal in URLs to their
+ * %XX versions). This function returns a new allocated string or NULL if an
+ * error occurred.
+ */
+CURL_EXTERN char *curl_easy_escape(CURL *handle,
+ const char *string,
+ int length);
+
+/* the previous version: */
+CURL_EXTERN char *curl_escape(const char *string,
+ int length);
+
+
+/*
+ * NAME curl_easy_unescape()
+ *
+ * DESCRIPTION
+ *
+ * Unescapes URL encoding in strings (converts all %XX codes to their 8bit
+ * versions). This function returns a new allocated string or NULL if an error
+ * occurred.
+ * Conversion Note: On non-ASCII platforms the ASCII %XX codes are
+ * converted into the host encoding.
+ */
+CURL_EXTERN char *curl_easy_unescape(CURL *handle,
+ const char *string,
+ int length,
+ int *outlength);
+
+/* the previous version */
+CURL_EXTERN char *curl_unescape(const char *string,
+ int length);
+
+/*
+ * NAME curl_free()
+ *
+ * DESCRIPTION
+ *
+ * Provided for de-allocation in the same translation unit that did the
+ * allocation. Added in libcurl 7.10
+ */
+CURL_EXTERN void curl_free(void *p);
+
+/*
+ * NAME curl_global_init()
+ *
+ * DESCRIPTION
+ *
+ * curl_global_init() should be invoked exactly once for each application that
+ * uses libcurl
+ */
+CURL_EXTERN CURLcode curl_global_init(long flags);
+
+/*
+ * NAME curl_global_init_mem()
+ *
+ * DESCRIPTION
+ *
+ * curl_global_init() or curl_global_init_mem() should be invoked exactly once
+ * for each application that uses libcurl. This function can be used to
+ * initialize libcurl and set user defined memory management callback
+ * functions. Users can implement memory management routines to check for
+ * memory leaks, check for mis-use of the curl library etc. User registered
+ * callback routines with be invoked by this library instead of the system
+ * memory management routines like malloc, free etc.
+ */
+CURL_EXTERN CURLcode curl_global_init_mem(long flags,
+ curl_malloc_callback m,
+ curl_free_callback f,
+ curl_realloc_callback r,
+ curl_strdup_callback s,
+ curl_calloc_callback c);
+
+/*
+ * NAME curl_global_cleanup()
+ *
+ * DESCRIPTION
+ *
+ * curl_global_cleanup() should be invoked exactly once for each application
+ * that uses libcurl
+ */
+CURL_EXTERN void curl_global_cleanup(void);
+
+/* linked-list structure for the CURLOPT_QUOTE option (and other) */
+struct curl_slist {
+ char *data;
+ struct curl_slist *next;
+};
+
+/*
+ * NAME curl_slist_append()
+ *
+ * DESCRIPTION
+ *
+ * Appends a string to a linked list. If no list exists, it will be created
+ * first. Returns the new list, after appending.
+ */
+CURL_EXTERN struct curl_slist *curl_slist_append(struct curl_slist *,
+ const char *);
+
+/*
+ * NAME curl_slist_free_all()
+ *
+ * DESCRIPTION
+ *
+ * free a previously built curl_slist.
+ */
+CURL_EXTERN void curl_slist_free_all(struct curl_slist *);
+
+/*
+ * NAME curl_getdate()
+ *
+ * DESCRIPTION
+ *
+ * Returns the time, in seconds since 1 Jan 1970 of the time string given in
+ * the first argument. The time argument in the second parameter is unused
+ * and should be set to NULL.
+ */
+CURL_EXTERN time_t curl_getdate(const char *p, const time_t *unused);
+
+#define CURLINFO_STRING 0x100000
+#define CURLINFO_LONG 0x200000
+#define CURLINFO_DOUBLE 0x300000
+#define CURLINFO_SLIST 0x400000
+#define CURLINFO_MASK 0x0fffff
+#define CURLINFO_TYPEMASK 0xf00000
+
+typedef enum {
+ CURLINFO_NONE, /* first, never use this */
+ CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1,
+ CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2,
+ CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3,
+ CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4,
+ CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5,
+ CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6,
+ CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7,
+ CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8,
+ CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9,
+ CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10,
+ CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11,
+ CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12,
+ CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13,
+ CURLINFO_FILETIME = CURLINFO_LONG + 14,
+ CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15,
+ CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16,
+ CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17,
+ CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18,
+ CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19,
+ CURLINFO_REDIRECT_COUNT = CURLINFO_LONG + 20,
+ CURLINFO_PRIVATE = CURLINFO_STRING + 21,
+ CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG + 22,
+ CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG + 23,
+ CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG + 24,
+ CURLINFO_OS_ERRNO = CURLINFO_LONG + 25,
+ CURLINFO_NUM_CONNECTS = CURLINFO_LONG + 26,
+ CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27,
+ CURLINFO_COOKIELIST = CURLINFO_SLIST + 28,
+ CURLINFO_LASTSOCKET = CURLINFO_LONG + 29,
+ CURLINFO_FTP_ENTRY_PATH = CURLINFO_STRING + 30,
+ /* Fill in new entries below here! */
+
+ CURLINFO_LASTONE = 30
+} CURLINFO;
+
+/* CURLINFO_RESPONSE_CODE is the new name for the option previously known as
+ CURLINFO_HTTP_CODE */
+#define CURLINFO_HTTP_CODE CURLINFO_RESPONSE_CODE
+
+typedef enum {
+ CURLCLOSEPOLICY_NONE, /* first, never use this */
+
+ CURLCLOSEPOLICY_OLDEST,
+ CURLCLOSEPOLICY_LEAST_RECENTLY_USED,
+ CURLCLOSEPOLICY_LEAST_TRAFFIC,
+ CURLCLOSEPOLICY_SLOWEST,
+ CURLCLOSEPOLICY_CALLBACK,
+
+ CURLCLOSEPOLICY_LAST /* last, never use this */
+} curl_closepolicy;
+
+#define CURL_GLOBAL_SSL (1<<0)
+#define CURL_GLOBAL_WIN32 (1<<1)
+#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32)
+#define CURL_GLOBAL_NOTHING 0
+#define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL
+
+
+/*****************************************************************************
+ * Setup defines, protos etc for the sharing stuff.
+ */
+
+/* Different data locks for a single share */
+typedef enum {
+ CURL_LOCK_DATA_NONE = 0,
+ /* CURL_LOCK_DATA_SHARE is used internaly to say that
+ * the locking is just made to change the internal state of the share
+ * itself.
+ */
+ CURL_LOCK_DATA_SHARE,
+ CURL_LOCK_DATA_COOKIE,
+ CURL_LOCK_DATA_DNS,
+ CURL_LOCK_DATA_SSL_SESSION,
+ CURL_LOCK_DATA_CONNECT,
+ CURL_LOCK_DATA_LAST
+} curl_lock_data;
+
+/* Different lock access types */
+typedef enum {
+ CURL_LOCK_ACCESS_NONE = 0, /* unspecified action */
+ CURL_LOCK_ACCESS_SHARED = 1, /* for read perhaps */
+ CURL_LOCK_ACCESS_SINGLE = 2, /* for write perhaps */
+ CURL_LOCK_ACCESS_LAST /* never use */
+} curl_lock_access;
+
+typedef void (*curl_lock_function)(CURL *handle,
+ curl_lock_data data,
+ curl_lock_access locktype,
+ void *userptr);
+typedef void (*curl_unlock_function)(CURL *handle,
+ curl_lock_data data,
+ void *userptr);
+
+typedef void CURLSH;
+
+typedef enum {
+ CURLSHE_OK, /* all is fine */
+ CURLSHE_BAD_OPTION, /* 1 */
+ CURLSHE_IN_USE, /* 2 */
+ CURLSHE_INVALID, /* 3 */
+ CURLSHE_NOMEM, /* out of memory */
+ CURLSHE_LAST /* never use */
+} CURLSHcode;
+
+typedef enum {
+ CURLSHOPT_NONE, /* don't use */
+ CURLSHOPT_SHARE, /* specify a data type to share */
+ CURLSHOPT_UNSHARE, /* specify shich data type to stop sharing */
+ CURLSHOPT_LOCKFUNC, /* pass in a 'curl_lock_function' pointer */
+ CURLSHOPT_UNLOCKFUNC, /* pass in a 'curl_unlock_function' pointer */
+ CURLSHOPT_USERDATA, /* pass in a user data pointer used in the lock/unlock
+ callback functions */
+ CURLSHOPT_LAST /* never use */
+} CURLSHoption;
+
+CURL_EXTERN CURLSH *curl_share_init(void);
+CURL_EXTERN CURLSHcode curl_share_setopt(CURLSH *, CURLSHoption option, ...);
+CURL_EXTERN CURLSHcode curl_share_cleanup(CURLSH *);
+
+/****************************************************************************
+ * Structures for querying information about the curl library at runtime.
+ */
+
+typedef enum {
+ CURLVERSION_FIRST,
+ CURLVERSION_SECOND,
+ CURLVERSION_THIRD,
+ CURLVERSION_FOURTH,
+ CURLVERSION_LAST /* never actually use this */
+} CURLversion;
+
+/* The 'CURLVERSION_NOW' is the symbolic name meant to be used by
+ basicly all programs ever, that want to get version information. It is
+ meant to be a built-in version number for what kind of struct the caller
+ expects. If the struct ever changes, we redefine the NOW to another enum
+ from above. */
+#define CURLVERSION_NOW CURLVERSION_FOURTH
+
+typedef struct {
+ CURLversion age; /* age of the returned struct */
+ const char *version; /* LIBCURL_VERSION */
+ unsigned int version_num; /* LIBCURL_VERSION_NUM */
+ const char *host; /* OS/host/cpu/machine when configured */
+ int features; /* bitmask, see defines below */
+ const char *ssl_version; /* human readable string */
+ long ssl_version_num; /* not used anymore, always 0 */
+ const char *libz_version; /* human readable string */
+ /* protocols is terminated by an entry with a NULL protoname */
+ const char * const *protocols;
+
+ /* The fields below this were added in CURLVERSION_SECOND */
+ const char *ares;
+ int ares_num;
+
+ /* This field was added in CURLVERSION_THIRD */
+ const char *libidn;
+
+ /* These field were added in CURLVERSION_FOURTH */
+
+ /* Same as '_libiconv_version' if built with HAVE_ICONV */
+ int iconv_ver_num;
+
+ const char *libssh_version; /* human readable string */
+
+} curl_version_info_data;
+
+#define CURL_VERSION_IPV6 (1<<0) /* IPv6-enabled */
+#define CURL_VERSION_KERBEROS4 (1<<1) /* kerberos auth is supported */
+#define CURL_VERSION_SSL (1<<2) /* SSL options are present */
+#define CURL_VERSION_LIBZ (1<<3) /* libz features are present */
+#define CURL_VERSION_NTLM (1<<4) /* NTLM auth is supported */
+#define CURL_VERSION_GSSNEGOTIATE (1<<5) /* Negotiate auth support */
+#define CURL_VERSION_DEBUG (1<<6) /* built with debug capabilities */
+#define CURL_VERSION_ASYNCHDNS (1<<7) /* asynchronous dns resolves */
+#define CURL_VERSION_SPNEGO (1<<8) /* SPNEGO auth */
+#define CURL_VERSION_LARGEFILE (1<<9) /* supports files bigger than 2GB */
+#define CURL_VERSION_IDN (1<<10) /* International Domain Names support */
+#define CURL_VERSION_SSPI (1<<11) /* SSPI is supported */
+#define CURL_VERSION_CONV (1<<12) /* character conversions are
+ supported */
+
+/*
+ * NAME curl_version_info()
+ *
+ * DESCRIPTION
+ *
+ * This function returns a pointer to a static copy of the version info
+ * struct. See above.
+ */
+CURL_EXTERN curl_version_info_data *curl_version_info(CURLversion);
+
+/*
+ * NAME curl_easy_strerror()
+ *
+ * DESCRIPTION
+ *
+ * The curl_easy_strerror function may be used to turn a CURLcode value
+ * into the equivalent human readable error string. This is useful
+ * for printing meaningful error messages.
+ */
+CURL_EXTERN const char *curl_easy_strerror(CURLcode);
+
+/*
+ * NAME curl_share_strerror()
+ *
+ * DESCRIPTION
+ *
+ * The curl_share_strerror function may be used to turn a CURLSHcode value
+ * into the equivalent human readable error string. This is useful
+ * for printing meaningful error messages.
+ */
+CURL_EXTERN const char *curl_share_strerror(CURLSHcode);
+
+#ifdef __cplusplus
+}
+#endif
+
+/* unfortunately, the easy.h and multi.h include files need options and info
+ stuff before they can be included! */
+#include "easy.h" /* nothing in curl is fun without the easy stuff */
+#include "multi.h"
+
+#endif /* __CURL_CURL_H */
diff --git a/Utilities/cmcurl/curl/curlver.h b/Utilities/cmcurl/curl/curlver.h
new file mode 100644
index 0000000000..9380022855
--- /dev/null
+++ b/Utilities/cmcurl/curl/curlver.h
@@ -0,0 +1,56 @@
+#ifndef __CURL_CURLVER_H
+#define __CURL_CURLVER_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/* This header file contains nothing but libcurl version info, generated by
+ a script at release-time. This was made its own header file in 7.11.2 */
+
+/* This is the version number of the libcurl package from which this header
+ file origins: */
+#define LIBCURL_VERSION "7.16.1"
+
+/* The numeric version number is also available "in parts" by using these
+ defines: */
+#define LIBCURL_VERSION_MAJOR 7
+#define LIBCURL_VERSION_MINOR 16
+#define LIBCURL_VERSION_PATCH 1
+
+/* This is the numeric version of the libcurl version number, meant for easier
+ parsing and comparions by programs. The LIBCURL_VERSION_NUM define will
+ always follow this syntax:
+
+ 0xXXYYZZ
+
+ Where XX, YY and ZZ are the main version, release and patch numbers in
+ hexadecimal (using 8 bits each). All three numbers are always represented
+ using two digits. 1.2 would appear as "0x010200" while version 9.11.7
+ appears as "0x090b07".
+
+ This 6-digit (24 bits) hexadecimal number does not show pre-release number,
+ and it is always a greater number in a more recent release. It makes
+ comparisons with greater than and less than work.
+*/
+#define LIBCURL_VERSION_NUM 0x071001
+
+#endif /* __CURL_CURLVER_H */
diff --git a/Utilities/cmcurl/curl/easy.h b/Utilities/cmcurl/curl/easy.h
new file mode 100644
index 0000000000..17de21070e
--- /dev/null
+++ b/Utilities/cmcurl/curl/easy.h
@@ -0,0 +1,81 @@
+#ifndef __CURL_EASY_H
+#define __CURL_EASY_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+CURL_EXTERN CURL *curl_easy_init(void);
+CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);
+CURL_EXTERN CURLcode curl_easy_perform(CURL *curl);
+CURL_EXTERN void curl_easy_cleanup(CURL *curl);
+
+/*
+ * NAME curl_easy_getinfo()
+ *
+ * DESCRIPTION
+ *
+ * Request internal information from the curl session with this function. The
+ * third argument MUST be a pointer to a long, a pointer to a char * or a
+ * pointer to a double (as the documentation describes elsewhere). The data
+ * pointed to will be filled in accordingly and can be relied upon only if the
+ * function returns CURLE_OK. This function is intended to get used *AFTER* a
+ * performed transfer, all results from this function are undefined until the
+ * transfer is completed.
+ */
+CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...);
+
+
+/*
+ * NAME curl_easy_duphandle()
+ *
+ * DESCRIPTION
+ *
+ * Creates a new curl session handle with the same options set for the handle
+ * passed in. Duplicating a handle could only be a matter of cloning data and
+ * options, internal state info and things like persistant connections cannot
+ * be transfered. It is useful in multithreaded applications when you can run
+ * curl_easy_duphandle() for each new thread to avoid a series of identical
+ * curl_easy_setopt() invokes in every thread.
+ */
+CURL_EXTERN CURL* curl_easy_duphandle(CURL *curl);
+
+/*
+ * NAME curl_easy_reset()
+ *
+ * DESCRIPTION
+ *
+ * Re-initializes a CURL handle to the default values. This puts back the
+ * handle to the same state as it was in when it was just created.
+ *
+ * It does keep: live connections, the Session ID cache, the DNS cache and the
+ * cookies.
+ */
+CURL_EXTERN void curl_easy_reset(CURL *curl);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/curl/mprintf.h b/Utilities/cmcurl/curl/mprintf.h
new file mode 100644
index 0000000000..5c526882f9
--- /dev/null
+++ b/Utilities/cmcurl/curl/mprintf.h
@@ -0,0 +1,80 @@
+#ifndef __CURL_MPRINTF_H
+#define __CURL_MPRINTF_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include <stdarg.h>
+#include <stdio.h> /* needed for FILE */
+
+#include "curl.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+CURL_EXTERN int curl_mprintf(const char *format, ...);
+CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...);
+CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...);
+CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...);
+CURL_EXTERN int curl_mvprintf(const char *format, va_list args);
+CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args);
+CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args);
+CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format, va_list args);
+CURL_EXTERN char *curl_maprintf(const char *format, ...);
+CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args);
+
+#ifdef _MPRINTF_REPLACE
+# undef printf
+# undef fprintf
+# undef sprintf
+# undef vsprintf
+# undef snprintf
+# undef vprintf
+# undef vfprintf
+# undef vsnprintf
+# undef aprintf
+# undef vaprintf
+# define printf curl_mprintf
+# define fprintf curl_mfprintf
+#ifdef CURLDEBUG
+/* When built with CURLDEBUG we define away the sprintf() functions since we
+ don't want internal code to be using them */
+# define sprintf sprintf_was_used
+# define vsprintf vsprintf_was_used
+#else
+# define sprintf curl_msprintf
+# define vsprintf curl_mvsprintf
+#endif
+# define snprintf curl_msnprintf
+# define vprintf curl_mvprintf
+# define vfprintf curl_mvfprintf
+# define vsnprintf curl_mvsnprintf
+# define aprintf curl_maprintf
+# define vaprintf curl_mvaprintf
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CURL_MPRINTF_H */
diff --git a/Utilities/cmcurl/curl/multi.h b/Utilities/cmcurl/curl/multi.h
new file mode 100644
index 0000000000..1b66747681
--- /dev/null
+++ b/Utilities/cmcurl/curl/multi.h
@@ -0,0 +1,327 @@
+#ifndef __CURL_MULTI_H
+#define __CURL_MULTI_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+/*
+ This is an "external" header file. Don't give away any internals here!
+
+ GOALS
+
+ o Enable a "pull" interface. The application that uses libcurl decides where
+ and when to ask libcurl to get/send data.
+
+ o Enable multiple simultaneous transfers in the same thread without making it
+ complicated for the application.
+
+ o Enable the application to select() on its own file descriptors and curl's
+ file descriptors simultaneous easily.
+
+*/
+
+/*
+ * This header file should not really need to include "curl.h" since curl.h
+ * itself includes this file and we expect user applications to do #include
+ * <curl/curl.h> without the need for especially including multi.h.
+ *
+ * For some reason we added this include here at one point, and rather than to
+ * break existing (wrongly written) libcurl applications, we leave it as-is
+ * but with this warning attached.
+ */
+#include "curl.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void CURLM;
+
+typedef enum {
+ CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
+ curl_multi_socket*() soon */
+ CURLM_OK,
+ CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */
+ CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
+ CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */
+ CURLM_INTERNAL_ERROR, /* this is a libcurl bug */
+ CURLM_BAD_SOCKET, /* the passed in socket argument did not match */
+ CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */
+ CURLM_LAST
+} CURLMcode;
+
+/* just to make code nicer when using curl_multi_socket() you can now check
+ for CURLM_CALL_MULTI_SOCKET too in the same style it works for
+ curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */
+#define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM
+
+typedef enum {
+ CURLMSG_NONE, /* first, not used */
+ CURLMSG_DONE, /* This easy handle has completed. 'result' contains
+ the CURLcode of the transfer */
+ CURLMSG_LAST /* last, not used */
+} CURLMSG;
+
+struct CURLMsg {
+ CURLMSG msg; /* what this message means */
+ CURL *easy_handle; /* the handle it concerns */
+ union {
+ void *whatever; /* message-specific data */
+ CURLcode result; /* return code for transfer */
+ } data;
+};
+typedef struct CURLMsg CURLMsg;
+
+/*
+ * Name: curl_multi_init()
+ *
+ * Desc: inititalize multi-style curl usage
+ *
+ * Returns: a new CURLM handle to use in all 'curl_multi' functions.
+ */
+CURL_EXTERN CURLM *curl_multi_init(void);
+
+/*
+ * Name: curl_multi_add_handle()
+ *
+ * Desc: add a standard curl handle to the multi stack
+ *
+ * Returns: CURLMcode type, general multi error code.
+ */
+CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle,
+ CURL *curl_handle);
+
+ /*
+ * Name: curl_multi_remove_handle()
+ *
+ * Desc: removes a curl handle from the multi stack again
+ *
+ * Returns: CURLMcode type, general multi error code.
+ */
+CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
+ CURL *curl_handle);
+
+ /*
+ * Name: curl_multi_fdset()
+ *
+ * Desc: Ask curl for its fd_set sets. The app can use these to select() or
+ * poll() on. We want curl_multi_perform() called as soon as one of
+ * them are ready.
+ *
+ * Returns: CURLMcode type, general multi error code.
+ */
+CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle,
+ fd_set *read_fd_set,
+ fd_set *write_fd_set,
+ fd_set *exc_fd_set,
+ int *max_fd);
+
+ /*
+ * Name: curl_multi_perform()
+ *
+ * Desc: When the app thinks there's data available for curl it calls this
+ * function to read/write whatever there is right now. This returns
+ * as soon as the reads and writes are done. This function does not
+ * require that there actually is data available for reading or that
+ * data can be written, it can be called just in case. It returns
+ * the number of handles that still transfer data in the second
+ * argument's integer-pointer.
+ *
+ * Returns: CURLMcode type, general multi error code. *NOTE* that this only
+ * returns errors etc regarding the whole multi stack. There might
+ * still have occurred problems on invidual transfers even when this
+ * returns OK.
+ */
+CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
+ int *running_handles);
+
+ /*
+ * Name: curl_multi_cleanup()
+ *
+ * Desc: Cleans up and removes a whole multi stack. It does not free or
+ * touch any individual easy handles in any way. We need to define
+ * in what state those handles will be if this function is called
+ * in the middle of a transfer.
+ *
+ * Returns: CURLMcode type, general multi error code.
+ */
+CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle);
+
+/*
+ * Name: curl_multi_info_read()
+ *
+ * Desc: Ask the multi handle if there's any messages/informationals from
+ * the individual transfers. Messages include informationals such as
+ * error code from the transfer or just the fact that a transfer is
+ * completed. More details on these should be written down as well.
+ *
+ * Repeated calls to this function will return a new struct each
+ * time, until a special "end of msgs" struct is returned as a signal
+ * that there is no more to get at this point.
+ *
+ * The data the returned pointer points to will not survive calling
+ * curl_multi_cleanup().
+ *
+ * The 'CURLMsg' struct is meant to be very simple and only contain
+ * very basic information. If more involved information is wanted,
+ * we will provide the particular "transfer handle" in that struct
+ * and that should/could/would be used in subsequent
+ * curl_easy_getinfo() calls (or similar). The point being that we
+ * must never expose complex structs to applications, as then we'll
+ * undoubtably get backwards compatibility problems in the future.
+ *
+ * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
+ * of structs. It also writes the number of messages left in the
+ * queue (after this read) in the integer the second argument points
+ * to.
+ */
+CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle,
+ int *msgs_in_queue);
+
+/*
+ * Name: curl_multi_strerror()
+ *
+ * Desc: The curl_multi_strerror function may be used to turn a CURLMcode
+ * value into the equivalent human readable error string. This is
+ * useful for printing meaningful error messages.
+ *
+ * Returns: A pointer to a zero-terminated error message.
+ */
+CURL_EXTERN const char *curl_multi_strerror(CURLMcode);
+
+/*
+ * Name: curl_multi_socket() and
+ * curl_multi_socket_all()
+ *
+ * Desc: An alternative version of curl_multi_perform() that allows the
+ * application to pass in one of the file descriptors that have been
+ * detected to have "action" on them and let libcurl perform.
+ * See man page for details.
+ */
+#define CURL_POLL_NONE 0
+#define CURL_POLL_IN 1
+#define CURL_POLL_OUT 2
+#define CURL_POLL_INOUT 3
+#define CURL_POLL_REMOVE 4
+
+#define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD
+
+typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */
+ curl_socket_t s, /* socket */
+ int what, /* see above */
+ void *userp, /* private callback
+ pointer */
+ void *socketp); /* private socket
+ pointer */
+/*
+ * Name: curl_multi_timer_callback
+ *
+ * Desc: Called by libcurl whenever the library detects a change in the
+ * maximum number of milliseconds the app is allowed to wait before
+ * curl_multi_socket() or curl_multi_perform() must be called
+ * (to allow libcurl's timed events to take place).
+ *
+ * Returns: The callback should return zero.
+ */
+typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */
+ long timeout_ms, /* see above */
+ void *userp); /* private callback
+ pointer */
+
+CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s,
+ int *running_handles);
+
+CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle,
+ int *running_handles);
+
+/*
+ * Name: curl_multi_timeout()
+ *
+ * Desc: Returns the maximum number of milliseconds the app is allowed to
+ * wait before curl_multi_socket() or curl_multi_perform() must be
+ * called (to allow libcurl's timed events to take place).
+ *
+ * Returns: CURLM error code.
+ */
+CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle,
+ long *milliseconds);
+
+#undef CINIT /* re-using the same name as in curl.h */
+
+#ifdef CURL_ISOCPP
+#define CINIT(name,type,number) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + number
+#else
+/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */
+#define LONG CURLOPTTYPE_LONG
+#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT
+#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT
+#define OFF_T CURLOPTTYPE_OFF_T
+#define CINIT(name,type,number) CURLMOPT_/**/name = type + number
+#endif
+
+typedef enum {
+ /* This is the socket callback function pointer */
+ CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1),
+
+ /* This is the argument passed to the socket callback */
+ CINIT(SOCKETDATA, OBJECTPOINT, 2),
+
+ /* set to 1 to enable pipelining for this multi handle */
+ CINIT(PIPELINING, LONG, 3),
+
+ /* This is the timer callback function pointer */
+ CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4),
+
+ /* This is the argument passed to the timer callback */
+ CINIT(TIMERDATA, OBJECTPOINT, 5),
+
+ CURLMOPT_LASTENTRY /* the last unused */
+} CURLMoption;
+
+
+/*
+ * Name: curl_multi_setopt()
+ *
+ * Desc: Sets options for the multi handle.
+ *
+ * Returns: CURLM error code.
+ */
+CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
+ CURLMoption option, ...);
+
+
+/*
+ * Name: curl_multi_assign()
+ *
+ * Desc: This function sets an association in the multi handle between the
+ * given socket and a private pointer of the application. This is
+ * (only) useful for curl_multi_socket uses.
+ *
+ * Returns: CURLM error code.
+ */
+CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
+ curl_socket_t sockfd, void *sockp);
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/curl/stdcheaders.h b/Utilities/cmcurl/curl/stdcheaders.h
new file mode 100644
index 0000000000..11c1e2f6ea
--- /dev/null
+++ b/Utilities/cmcurl/curl/stdcheaders.h
@@ -0,0 +1,34 @@
+#ifndef __STDC_HEADERS_H
+#define __STDC_HEADERS_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include <sys/types.h>
+
+size_t fread (void *, size_t, size_t, FILE *);
+size_t fwrite (const void *, size_t, size_t, FILE *);
+
+int strcasecmp(const char *, const char *);
+int strncasecmp(const char *, const char *, size_t);
+
+#endif
diff --git a/Utilities/cmcurl/curl/types.h b/Utilities/cmcurl/curl/types.h
new file mode 100644
index 0000000000..d37d6ae9e1
--- /dev/null
+++ b/Utilities/cmcurl/curl/types.h
@@ -0,0 +1 @@
+/* not used */
diff --git a/Utilities/cmcurl/curlx.h b/Utilities/cmcurl/curlx.h
new file mode 100644
index 0000000000..26948d3052
--- /dev/null
+++ b/Utilities/cmcurl/curlx.h
@@ -0,0 +1,107 @@
+#ifndef __CURLX_H
+#define __CURLX_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * Defines protos and includes all header files that provide the curlx_*
+ * functions. The curlx_* functions are not part of the libcurl API, but are
+ * stand-alone functions whose sources can be built and linked by apps if need
+ * be.
+ */
+
+#include <curl/mprintf.h>
+/* this is still a public header file that provides the curl_mprintf()
+ functions while they still are offered publicly. They will be made library-
+ private one day */
+
+#include "strequal.h"
+/* "strequal.h" provides the strequal protos */
+
+#include "strtoofft.h"
+/* "strtoofft.h" provides this function: curlx_strtoofft(), returns a
+ curl_off_t number from a given string.
+*/
+
+#include "timeval.h"
+/*
+ "timeval.h" sets up a 'struct timeval' even for platforms that otherwise
+ don't have one and has protos for these functions:
+
+ curlx_tvnow()
+ curlx_tvdiff()
+ curlx_tvdiff_secs()
+*/
+
+/* Now setup curlx_ * names for the functions that are to become curlx_ and
+ be removed from a future libcurl official API:
+ curlx_getenv
+ curlx_mprintf (and its variations)
+ curlx_strequal
+ curlx_strnequal
+
+*/
+
+#define curlx_getenv curl_getenv
+#define curlx_strequal curl_strequal
+#define curlx_strnequal curl_strnequal
+#define curlx_mvsnprintf curl_mvsnprintf
+#define curlx_msnprintf curl_msnprintf
+#define curlx_maprintf curl_maprintf
+#define curlx_mvaprintf curl_mvaprintf
+#define curlx_msprintf curl_msprintf
+#define curlx_mprintf curl_mprintf
+#define curlx_mfprintf curl_mfprintf
+#define curlx_mvsprintf curl_mvsprintf
+#define curlx_mvprintf curl_mvprintf
+#define curlx_mvfprintf curl_mvfprintf
+
+#ifdef ENABLE_CURLX_PRINTF
+/* If this define is set, we define all "standard" printf() functions to use
+ the curlx_* version instead. It makes the source code transparant and
+ easier to understand/patch. Undefine them first in case _MPRINTF_REPLACE
+ is set. */
+# undef printf
+# undef fprintf
+# undef sprintf
+# undef snprintf
+# undef vprintf
+# undef vfprintf
+# undef vsprintf
+# undef vsnprintf
+# undef aprintf
+# undef vaprintf
+
+# define printf curlx_mprintf
+# define fprintf curlx_mfprintf
+# define sprintf curlx_msprintf
+# define snprintf curlx_msnprintf
+# define vprintf curlx_mvprintf
+# define vfprintf curlx_mvfprintf
+# define vsprintf curlx_mvsprintf
+# define vsnprintf curlx_mvsnprintf
+# define aprintf curlx_maprintf
+# define vaprintf curlx_mvaprintf
+#endif /* ENABLE_CURLX_PRINTF */
+
+#endif /* __CURLX_H */
diff --git a/Utilities/cmcurl/dict.c b/Utilities/cmcurl/dict.c
new file mode 100644
index 0000000000..d6443f4b95
--- /dev/null
+++ b/Utilities/cmcurl/dict.c
@@ -0,0 +1,280 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_DICT
+
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef WIN32
+#include <time.h>
+#include <io.h>
+#else
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <netinet/in.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <netdb.h>
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#include <sys/ioctl.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+
+#endif
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "transfer.h"
+#include "sendf.h"
+
+#include "progress.h"
+#include "strequal.h"
+#include "dict.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+static char *unescape_word(struct SessionHandle *data, char *inp)
+{
+ char *newp;
+ char *dictp;
+ char *ptr;
+ int len;
+ unsigned char byte;
+ int olen=0;
+
+ newp = curl_easy_unescape(data, inp, 0, &len);
+ if(!newp)
+ return NULL;
+
+ dictp = malloc(len*2 + 1); /* add one for terminating zero */
+ if(dictp) {
+ /* According to RFC2229 section 2.2, these letters need to be escaped with
+ \[letter] */
+ for(ptr = newp;
+ (byte = (unsigned char)*ptr) != 0;
+ ptr++) {
+ if ((byte <= 32) || (byte == 127) ||
+ (byte == '\'') || (byte == '\"') || (byte == '\\')) {
+ dictp[olen++] = '\\';
+ }
+ dictp[olen++] = byte;
+ }
+ dictp[olen]=0;
+
+ free(newp);
+ }
+ return dictp;
+}
+
+CURLcode Curl_dict(struct connectdata *conn, bool *done)
+{
+ char *word;
+ char *eword;
+ char *ppath;
+ char *database = NULL;
+ char *strategy = NULL;
+ char *nthdef = NULL; /* This is not part of the protocol, but required
+ by RFC 2229 */
+ CURLcode result=CURLE_OK;
+ struct SessionHandle *data=conn->data;
+ curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
+
+ char *path = data->reqdata.path;
+ curl_off_t *bytecount = &data->reqdata.keep.bytecount;
+
+ *done = TRUE; /* unconditionally */
+
+ if(conn->bits.user_passwd) {
+ /* AUTH is missing */
+ }
+
+ if (strnequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) ||
+ strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) ||
+ strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) {
+
+ word = strchr(path, ':');
+ if (word) {
+ word++;
+ database = strchr(word, ':');
+ if (database) {
+ *database++ = (char)0;
+ strategy = strchr(database, ':');
+ if (strategy) {
+ *strategy++ = (char)0;
+ nthdef = strchr(strategy, ':');
+ if (nthdef) {
+ *nthdef++ = (char)0;
+ }
+ }
+ }
+ }
+
+ if ((word == NULL) || (*word == (char)0)) {
+ failf(data, "lookup word is missing");
+ }
+ if ((database == NULL) || (*database == (char)0)) {
+ database = (char *)"!";
+ }
+ if ((strategy == NULL) || (*strategy == (char)0)) {
+ strategy = (char *)".";
+ }
+
+ eword = unescape_word(data, word);
+ if(!eword)
+ return CURLE_OUT_OF_MEMORY;
+
+ result = Curl_sendf(sockfd, conn,
+ "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
+ "MATCH "
+ "%s " /* database */
+ "%s " /* strategy */
+ "%s\r\n" /* word */
+ "QUIT\r\n",
+
+ database,
+ strategy,
+ eword
+ );
+
+ free(eword);
+
+ if(result)
+ failf(data, "Failed sending DICT request");
+ else
+ result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
+ -1, NULL); /* no upload */
+ if(result)
+ return result;
+ }
+ else if (strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
+ strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
+ strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) {
+
+ word = strchr(path, ':');
+ if (word) {
+ word++;
+ database = strchr(word, ':');
+ if (database) {
+ *database++ = (char)0;
+ nthdef = strchr(database, ':');
+ if (nthdef) {
+ *nthdef++ = (char)0;
+ }
+ }
+ }
+
+ if ((word == NULL) || (*word == (char)0)) {
+ failf(data, "lookup word is missing");
+ }
+ if ((database == NULL) || (*database == (char)0)) {
+ database = (char *)"!";
+ }
+
+ eword = unescape_word(data, word);
+ if(!eword)
+ return CURLE_OUT_OF_MEMORY;
+
+ result = Curl_sendf(sockfd, conn,
+ "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
+ "DEFINE "
+ "%s " /* database */
+ "%s\r\n" /* word */
+ "QUIT\r\n",
+ database,
+ eword);
+
+ free(eword);
+
+ if(result)
+ failf(data, "Failed sending DICT request");
+ else
+ result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
+ -1, NULL); /* no upload */
+
+ if(result)
+ return result;
+
+ }
+ else {
+
+ ppath = strchr(path, '/');
+ if (ppath) {
+ int i;
+
+ ppath++;
+ for (i = 0; ppath[i]; i++) {
+ if (ppath[i] == ':')
+ ppath[i] = ' ';
+ }
+ result = Curl_sendf(sockfd, conn,
+ "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
+ "%s\r\n"
+ "QUIT\r\n", ppath);
+ if(result)
+ failf(data, "Failed sending DICT request");
+ else
+ result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
+ -1, NULL);
+ if(result)
+ return result;
+ }
+ }
+
+ return CURLE_OK;
+}
+#endif /*CURL_DISABLE_DICT*/
diff --git a/Utilities/cmcurl/dict.h b/Utilities/cmcurl/dict.h
new file mode 100644
index 0000000000..d3da1936f6
--- /dev/null
+++ b/Utilities/cmcurl/dict.h
@@ -0,0 +1,30 @@
+#ifndef __DICT_H
+#define __DICT_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#ifndef CURL_DISABLE_DICT
+CURLcode Curl_dict(struct connectdata *conn, bool *done);
+CURLcode Curl_dict_done(struct connectdata *conn);
+#endif
+#endif
diff --git a/Utilities/cmcurl/easy.c b/Utilities/cmcurl/easy.c
new file mode 100644
index 0000000000..209d1c3e09
--- /dev/null
+++ b/Utilities/cmcurl/easy.c
@@ -0,0 +1,895 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#include <errno.h>
+
+#include "strequal.h"
+
+#ifdef WIN32
+#include <time.h>
+#include <io.h>
+#else
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <netinet/in.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <netdb.h>
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#include <sys/ioctl.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+#endif /* WIN32 ... */
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "transfer.h"
+#include "sslgen.h"
+#include "url.h"
+#include "getinfo.h"
+#include "hostip.h"
+#include "share.h"
+#include "strdup.h"
+#include "memory.h"
+#include "progress.h"
+#include "easyif.h"
+#include "sendf.h" /* for failf function prototype */
+#include <ca-bundle.h>
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
+#include <iconv.h>
+/* set default codesets for iconv */
+#ifndef CURL_ICONV_CODESET_OF_NETWORK
+#define CURL_ICONV_CODESET_OF_NETWORK "ISO8859-1"
+#endif
+#ifndef CURL_ICONV_CODESET_FOR_UTF8
+#define CURL_ICONV_CODESET_FOR_UTF8 "UTF-8"
+#endif
+#define ICONV_ERROR (size_t)-1
+#endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#ifdef USE_WINSOCK
+/* win32_cleanup() is for win32 socket cleanup functionality, the opposite
+ of win32_init() */
+static void win32_cleanup(void)
+{
+ WSACleanup();
+}
+
+/* win32_init() performs win32 socket initialization to properly setup the
+ stack to allow networking */
+static CURLcode win32_init(void)
+{
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ int err;
+
+#if defined(ENABLE_IPV6) && (USE_WINSOCK < 2)
+ Error IPV6_requires_winsock2
+#endif
+
+ wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
+
+ err = WSAStartup(wVersionRequested, &wsaData);
+
+ if (err != 0)
+ /* Tell the user that we couldn't find a useable */
+ /* winsock.dll. */
+ return CURLE_FAILED_INIT;
+
+ /* Confirm that the Windows Sockets DLL supports what we need.*/
+ /* Note that if the DLL supports versions greater */
+ /* than wVersionRequested, it will still return */
+ /* wVersionRequested in wVersion. wHighVersion contains the */
+ /* highest supported version. */
+
+ if ( LOBYTE( wsaData.wVersion ) != LOBYTE(wVersionRequested) ||
+ HIBYTE( wsaData.wVersion ) != HIBYTE(wVersionRequested) ) {
+ /* Tell the user that we couldn't find a useable */
+
+ /* winsock.dll. */
+ WSACleanup();
+ return CURLE_FAILED_INIT;
+ }
+ /* The Windows Sockets DLL is acceptable. Proceed. */
+ return CURLE_OK;
+}
+
+#else
+/* These functions exist merely to prevent compiler warnings */
+static CURLcode win32_init(void) { return CURLE_OK; }
+static void win32_cleanup(void) { }
+#endif
+
+#ifdef USE_LIBIDN
+/*
+ * Initialise use of IDNA library.
+ * It falls back to ASCII if $CHARSET isn't defined. This doesn't work for
+ * idna_to_ascii_lz().
+ */
+static void idna_init (void)
+{
+#ifdef WIN32
+ char buf[60];
+ UINT cp = GetACP();
+
+ if (!getenv("CHARSET") && cp > 0) {
+ snprintf(buf, sizeof(buf), "CHARSET=cp%u", cp);
+ putenv(buf);
+ }
+#else
+ /* to do? */
+#endif
+}
+#endif /* USE_LIBIDN */
+
+/* true globals -- for curl_global_init() and curl_global_cleanup() */
+static unsigned int initialized;
+static long init_flags;
+
+/*
+ * strdup (and other memory functions) is redefined in complicated
+ * ways, but at this point it must be defined as the system-supplied strdup
+ * so the callback pointer is initialized correctly.
+ */
+#if defined(_WIN32_WCE)
+#define system_strdup _strdup
+#elif !defined(HAVE_STRDUP)
+#define system_strdup curlx_strdup
+#else
+#define system_strdup strdup
+#endif
+
+/*
+ * If a memory-using function (like curl_getenv) is used before
+ * curl_global_init() is called, we need to have these pointers set already.
+ */
+
+curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
+curl_free_callback Curl_cfree = (curl_free_callback)free;
+curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup;
+curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
+
+/**
+ * curl_global_init() globally initializes cURL given a bitwise set of the
+ * different features of what to initialize.
+ */
+CURLcode curl_global_init(long flags)
+{
+ if (initialized++)
+ return CURLE_OK;
+
+ /* Setup the default memory functions here (again) */
+ Curl_cmalloc = (curl_malloc_callback)malloc;
+ Curl_cfree = (curl_free_callback)free;
+ Curl_crealloc = (curl_realloc_callback)realloc;
+ Curl_cstrdup = (curl_strdup_callback)system_strdup;
+ Curl_ccalloc = (curl_calloc_callback)calloc;
+
+ if (flags & CURL_GLOBAL_SSL)
+ if (!Curl_ssl_init())
+ return CURLE_FAILED_INIT;
+
+ if (flags & CURL_GLOBAL_WIN32)
+ if (win32_init() != CURLE_OK)
+ return CURLE_FAILED_INIT;
+
+#ifdef _AMIGASF
+ if(!amiga_init())
+ return CURLE_FAILED_INIT;
+#endif
+
+#ifdef USE_LIBIDN
+ idna_init();
+#endif
+
+ init_flags = flags;
+
+ return CURLE_OK;
+}
+
+/*
+ * curl_global_init_mem() globally initializes cURL and also registers the
+ * user provided callback routines.
+ */
+CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
+ curl_free_callback f, curl_realloc_callback r,
+ curl_strdup_callback s, curl_calloc_callback c)
+{
+ CURLcode code = CURLE_OK;
+
+ /* Invalid input, return immediately */
+ if (!m || !f || !r || !s || !c)
+ return CURLE_FAILED_INIT;
+
+ /* Already initialized, don't do it again */
+ if ( initialized )
+ return CURLE_OK;
+
+ /* Call the actual init function first */
+ code = curl_global_init(flags);
+ if (code == CURLE_OK) {
+ Curl_cmalloc = m;
+ Curl_cfree = f;
+ Curl_cstrdup = s;
+ Curl_crealloc = r;
+ Curl_ccalloc = c;
+ }
+
+ return code;
+}
+
+/**
+ * curl_global_cleanup() globally cleanups cURL, uses the value of
+ * "init_flags" to determine what needs to be cleaned up and what doesn't.
+ */
+void curl_global_cleanup(void)
+{
+ if (!initialized)
+ return;
+
+ if (--initialized)
+ return;
+
+ Curl_global_host_cache_dtor();
+
+ if (init_flags & CURL_GLOBAL_SSL)
+ Curl_ssl_cleanup();
+
+ if (init_flags & CURL_GLOBAL_WIN32)
+ win32_cleanup();
+
+#ifdef _AMIGASF
+ amiga_cleanup();
+#endif
+
+ init_flags = 0;
+}
+
+/*
+ * curl_easy_init() is the external interface to alloc, setup and init an
+ * easy handle that is returned. If anything goes wrong, NULL is returned.
+ */
+CURL *curl_easy_init(void)
+{
+ CURLcode res;
+ struct SessionHandle *data;
+
+ /* Make sure we inited the global SSL stuff */
+ if (!initialized) {
+ res = curl_global_init(CURL_GLOBAL_DEFAULT);
+ if(res)
+ /* something in the global init failed, return nothing */
+ return NULL;
+ }
+
+ /* We use curl_open() with undefined URL so far */
+ res = Curl_open(&data);
+ if(res != CURLE_OK)
+ return NULL;
+
+ return data;
+}
+
+/*
+ * curl_easy_setopt() is the external interface for setting options on an
+ * easy handle.
+ */
+
+CURLcode curl_easy_setopt(CURL *curl, CURLoption tag, ...)
+{
+ va_list arg;
+ struct SessionHandle *data = curl;
+ CURLcode ret;
+
+ if(!curl)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ va_start(arg, tag);
+
+ ret = Curl_setopt(data, tag, arg);
+
+ va_end(arg);
+ return ret;
+}
+
+#ifdef CURL_MULTIEASY
+/***************************************************************************
+ * This function is still only for testing purposes. It makes a great way
+ * to run the full test suite on the multi interface instead of the easy one.
+ ***************************************************************************
+ *
+ * The *new* curl_easy_perform() is the external interface that performs a
+ * transfer previously setup.
+ *
+ * Wrapper-function that: creates a multi handle, adds the easy handle to it,
+ * runs curl_multi_perform() until the transfer is done, then detaches the
+ * easy handle, destroys the multi handle and returns the easy handle's return
+ * code. This will make everything internally use and assume multi interface.
+ */
+CURLcode curl_easy_perform(CURL *easy)
+{
+ CURLM *multi;
+ CURLMcode mcode;
+ CURLcode code = CURLE_OK;
+ int still_running;
+ struct timeval timeout;
+ int rc;
+ CURLMsg *msg;
+ fd_set fdread;
+ fd_set fdwrite;
+ fd_set fdexcep;
+ int maxfd;
+
+ if(!easy)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ multi = curl_multi_init();
+ if(!multi)
+ return CURLE_OUT_OF_MEMORY;
+
+ mcode = curl_multi_add_handle(multi, easy);
+ if(mcode) {
+ curl_multi_cleanup(multi);
+ return CURLE_FAILED_INIT;
+ }
+
+ /* we start some action by calling perform right away */
+
+ do {
+ while(CURLM_CALL_MULTI_PERFORM ==
+ curl_multi_perform(multi, &still_running));
+
+ if(!still_running)
+ break;
+
+ FD_ZERO(&fdread);
+ FD_ZERO(&fdwrite);
+ FD_ZERO(&fdexcep);
+
+ /* timeout once per second */
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ /* get file descriptors from the transfers */
+ curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ if(rc == -1)
+ /* select error */
+ break;
+
+ /* timeout or data to send/receive => loop! */
+ } while(still_running);
+
+ msg = curl_multi_info_read(multi, &rc);
+ if(msg)
+ code = msg->data.result;
+
+ mcode = curl_multi_remove_handle(multi, easy);
+ /* what to do if it fails? */
+
+ mcode = curl_multi_cleanup(multi);
+ /* what to do if it fails? */
+
+ return code;
+}
+#else
+/*
+ * curl_easy_perform() is the external interface that performs a transfer
+ * previously setup.
+ */
+CURLcode curl_easy_perform(CURL *curl)
+{
+ struct SessionHandle *data = (struct SessionHandle *)curl;
+
+ if(!data)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ if ( ! (data->share && data->share->hostcache) ) {
+
+ if (Curl_global_host_cache_use(data) &&
+ (data->dns.hostcachetype != HCACHE_GLOBAL)) {
+ if (data->dns.hostcachetype == HCACHE_PRIVATE)
+ Curl_hash_destroy(data->dns.hostcache);
+ data->dns.hostcache = Curl_global_host_cache_get();
+ data->dns.hostcachetype = HCACHE_GLOBAL;
+ }
+
+ if (!data->dns.hostcache) {
+ data->dns.hostcachetype = HCACHE_PRIVATE;
+ data->dns.hostcache = Curl_mk_dnscache();
+
+ if(!data->dns.hostcache)
+ /* While we possibly could survive and do good without a host cache,
+ the fact that creating it failed indicates that things are truly
+ screwed up and we should bail out! */
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ }
+
+ if(!data->state.connc) {
+ /* oops, no connection cache, make one up */
+ data->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE, -1);
+ if(!data->state.connc)
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ return Curl_perform(data);
+}
+#endif
+
+/*
+ * curl_easy_cleanup() is the external interface to cleaning/freeing the given
+ * easy handle.
+ */
+void curl_easy_cleanup(CURL *curl)
+{
+ struct SessionHandle *data = (struct SessionHandle *)curl;
+
+ if(!data)
+ return;
+
+ Curl_close(data);
+}
+
+/*
+ * Store a pointed to the multi handle within the easy handle's data struct.
+ */
+void Curl_easy_addmulti(struct SessionHandle *data,
+ void *multi)
+{
+ data->multi = multi;
+}
+
+void Curl_easy_initHandleData(struct SessionHandle *data)
+{
+ memset(&data->reqdata, 0, sizeof(struct HandleData));
+
+ data->reqdata.maxdownload = -1;
+}
+
+/*
+ * curl_easy_getinfo() is an external interface that allows an app to retrieve
+ * information from a performed transfer and similar.
+ */
+CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...)
+{
+ va_list arg;
+ void *paramp;
+ struct SessionHandle *data = (struct SessionHandle *)curl;
+
+ va_start(arg, info);
+ paramp = va_arg(arg, void *);
+
+ return Curl_getinfo(data, info, paramp);
+}
+
+/*
+ * curl_easy_duphandle() is an external interface to allow duplication of a
+ * given input easy handle. The returned handle will be a new working handle
+ * with all options set exactly as the input source handle.
+ */
+CURL *curl_easy_duphandle(CURL *incurl)
+{
+ bool fail = TRUE;
+ struct SessionHandle *data=(struct SessionHandle *)incurl;
+
+ struct SessionHandle *outcurl = (struct SessionHandle *)
+ calloc(sizeof(struct SessionHandle), 1);
+
+ if(NULL == outcurl)
+ return NULL; /* failure */
+
+ do {
+
+ /*
+ * We setup a few buffers we need. We should probably make them
+ * get setup on-demand in the code, as that would probably decrease
+ * the likeliness of us forgetting to init a buffer here in the future.
+ */
+ outcurl->state.headerbuff=(char*)malloc(HEADERSIZE);
+ if(!outcurl->state.headerbuff) {
+ break;
+ }
+ outcurl->state.headersize=HEADERSIZE;
+
+ /* copy all userdefined values */
+ outcurl->set = data->set;
+
+ if(data->state.used_interface == Curl_if_multi)
+ outcurl->state.connc = data->state.connc;
+ else
+ outcurl->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE, -1);
+
+ if(!outcurl->state.connc)
+ break;
+
+ outcurl->state.lastconnect = -1;
+
+ outcurl->progress.flags = data->progress.flags;
+ outcurl->progress.callback = data->progress.callback;
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+ if(data->cookies) {
+ /* If cookies are enabled in the parent handle, we enable them
+ in the clone as well! */
+ outcurl->cookies = Curl_cookie_init(data,
+ data->cookies->filename,
+ outcurl->cookies,
+ data->set.cookiesession);
+ if(!outcurl->cookies) {
+ break;
+ }
+ }
+#endif /* CURL_DISABLE_HTTP */
+
+ /* duplicate all values in 'change' */
+
+ if(data->change.url) {
+ outcurl->change.url = strdup(data->change.url);
+ if(!outcurl->change.url)
+ break;
+ outcurl->change.url_alloc = TRUE;
+ }
+
+ if(data->change.referer) {
+ outcurl->change.referer = strdup(data->change.referer);
+ if(!outcurl->change.referer)
+ break;
+ outcurl->change.referer_alloc = TRUE;
+ }
+
+#ifdef USE_ARES
+ /* If we use ares, we setup a new ares channel for the new handle */
+ if(ARES_SUCCESS != ares_init(&outcurl->state.areschannel))
+ break;
+#endif
+
+#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
+ outcurl->inbound_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
+ CURL_ICONV_CODESET_OF_NETWORK);
+ outcurl->outbound_cd = iconv_open(CURL_ICONV_CODESET_OF_NETWORK,
+ CURL_ICONV_CODESET_OF_HOST);
+ outcurl->utf8_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
+ CURL_ICONV_CODESET_FOR_UTF8);
+#endif
+
+ Curl_easy_initHandleData(outcurl);
+
+ outcurl->magic = CURLEASY_MAGIC_NUMBER;
+
+ fail = FALSE; /* we reach this point and thus we are OK */
+
+ } while(0);
+
+ if(fail) {
+ if(outcurl) {
+ if(outcurl->state.connc->type == CONNCACHE_PRIVATE)
+ Curl_rm_connc(outcurl->state.connc);
+ if(outcurl->state.headerbuff)
+ free(outcurl->state.headerbuff);
+ if(outcurl->change.url)
+ free(outcurl->change.url);
+ if(outcurl->change.referer)
+ free(outcurl->change.referer);
+ free(outcurl); /* free the memory again */
+ outcurl = NULL;
+ }
+ }
+
+ return outcurl;
+}
+
+/*
+ * curl_easy_reset() is an external interface that allows an app to re-
+ * initialize a session handle to the default values.
+ */
+void curl_easy_reset(CURL *curl)
+{
+ struct SessionHandle *data = (struct SessionHandle *)curl;
+
+ Curl_safefree(data->reqdata.pathbuffer);
+ data->reqdata.pathbuffer=NULL;
+
+ Curl_safefree(data->reqdata.proto.generic);
+ data->reqdata.proto.generic=NULL;
+
+ /* zero out UserDefined data: */
+ memset(&data->set, 0, sizeof(struct UserDefined));
+
+ /* zero out Progress data: */
+ memset(&data->progress, 0, sizeof(struct Progress));
+
+ /* init Handle data */
+ Curl_easy_initHandleData(data);
+
+ /* The remainder of these calls have been taken from Curl_open() */
+
+ data->set.out = stdout; /* default output to stdout */
+ data->set.in = stdin; /* default input from stdin */
+ data->set.err = stderr; /* default stderr to stderr */
+
+ /* use fwrite as default function to store output */
+ data->set.fwrite = (curl_write_callback)fwrite;
+
+ /* use fread as default function to read input */
+ data->set.fread = (curl_read_callback)fread;
+
+ data->set.infilesize = -1; /* we don't know any size */
+ data->set.postfieldsize = -1;
+
+ data->state.current_speed = -1; /* init to negative == impossible */
+
+ data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */
+ data->set.ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */
+ data->set.ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */
+
+ data->set.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
+
+ /* make libcurl quiet by default: */
+ data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */
+ data->progress.flags |= PGRS_HIDE;
+
+ /* Set the default size of the SSL session ID cache */
+ data->set.ssl.numsessions = 5;
+
+ data->set.proxyport = 1080;
+ data->set.proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */
+ data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic */
+ data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic */
+
+ /*
+ * libcurl 7.10 introduced SSL verification *by default*! This needs to be
+ * switched off unless wanted.
+ */
+ data->set.ssl.verifypeer = TRUE;
+ data->set.ssl.verifyhost = 2;
+#ifdef CURL_CA_BUNDLE
+ /* This is our preferred CA cert bundle since install time */
+ data->set.ssl.CAfile = (char *)CURL_CA_BUNDLE;
+#endif
+
+ data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
+ type */
+}
+
+#ifdef CURL_DOES_CONVERSIONS
+/*
+ * Curl_convert_to_network() is an internal function
+ * for performing ASCII conversions on non-ASCII platforms.
+ */
+CURLcode Curl_convert_to_network(struct SessionHandle *data,
+ char *buffer, size_t length)
+{
+ CURLcode rc;
+
+ if(data->set.convtonetwork) {
+ /* use translation callback */
+ rc = data->set.convtonetwork(buffer, length);
+ if(rc != CURLE_OK) {
+ failf(data,
+ "CURLOPT_CONV_TO_NETWORK_FUNCTION callback returned %i: %s",
+ rc, curl_easy_strerror(rc));
+ }
+ return(rc);
+ } else {
+#ifdef HAVE_ICONV
+ /* do the translation ourselves */
+ char *input_ptr, *output_ptr;
+ size_t in_bytes, out_bytes, rc;
+
+ /* open an iconv conversion descriptor if necessary */
+ if(data->outbound_cd == (iconv_t)-1) {
+ data->outbound_cd = iconv_open(CURL_ICONV_CODESET_OF_NETWORK,
+ CURL_ICONV_CODESET_OF_HOST);
+ if(data->outbound_cd == (iconv_t)-1) {
+ failf(data,
+ "The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
+ CURL_ICONV_CODESET_OF_NETWORK,
+ CURL_ICONV_CODESET_OF_HOST,
+ errno, strerror(errno));
+ return CURLE_CONV_FAILED;
+ }
+ }
+ /* call iconv */
+ input_ptr = output_ptr = buffer;
+ in_bytes = out_bytes = length;
+ rc = iconv(data->outbound_cd, (const char**)&input_ptr, &in_bytes,
+ &output_ptr, &out_bytes);
+ if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
+ failf(data,
+ "The Curl_convert_to_network iconv call failed with errno %i: %s",
+ errno, strerror(errno));
+ return CURLE_CONV_FAILED;
+ }
+#else
+ failf(data, "CURLOPT_CONV_TO_NETWORK_FUNCTION callback required");
+ return CURLE_CONV_REQD;
+#endif /* HAVE_ICONV */
+ }
+
+ return CURLE_OK;
+}
+
+/*
+ * Curl_convert_from_network() is an internal function
+ * for performing ASCII conversions on non-ASCII platforms.
+ */
+CURLcode Curl_convert_from_network(struct SessionHandle *data,
+ char *buffer, size_t length)
+{
+ CURLcode rc;
+
+ if(data->set.convfromnetwork) {
+ /* use translation callback */
+ rc = data->set.convfromnetwork(buffer, length);
+ if(rc != CURLE_OK) {
+ failf(data,
+ "CURLOPT_CONV_FROM_NETWORK_FUNCTION callback returned %i: %s",
+ rc, curl_easy_strerror(rc));
+ }
+ return(rc);
+ } else {
+#ifdef HAVE_ICONV
+ /* do the translation ourselves */
+ char *input_ptr, *output_ptr;
+ size_t in_bytes, out_bytes, rc;
+
+ /* open an iconv conversion descriptor if necessary */
+ if(data->inbound_cd == (iconv_t)-1) {
+ data->inbound_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
+ CURL_ICONV_CODESET_OF_NETWORK);
+ if(data->inbound_cd == (iconv_t)-1) {
+ failf(data,
+ "The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
+ CURL_ICONV_CODESET_OF_HOST,
+ CURL_ICONV_CODESET_OF_NETWORK,
+ errno, strerror(errno));
+ return CURLE_CONV_FAILED;
+ }
+ }
+ /* call iconv */
+ input_ptr = output_ptr = buffer;
+ in_bytes = out_bytes = length;
+ rc = iconv(data->inbound_cd, (const char **)&input_ptr, &in_bytes,
+ &output_ptr, &out_bytes);
+ if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
+ failf(data,
+ "The Curl_convert_from_network iconv call failed with errno %i: %s",
+ errno, strerror(errno));
+ return CURLE_CONV_FAILED;
+ }
+#else
+ failf(data, "CURLOPT_CONV_FROM_NETWORK_FUNCTION callback required");
+ return CURLE_CONV_REQD;
+#endif /* HAVE_ICONV */
+ }
+
+ return CURLE_OK;
+}
+
+/*
+ * Curl_convert_from_utf8() is an internal function
+ * for performing UTF-8 conversions on non-ASCII platforms.
+ */
+CURLcode Curl_convert_from_utf8(struct SessionHandle *data,
+ char *buffer, size_t length)
+{
+ CURLcode rc;
+
+ if(data->set.convfromutf8) {
+ /* use translation callback */
+ rc = data->set.convfromutf8(buffer, length);
+ if(rc != CURLE_OK) {
+ failf(data,
+ "CURLOPT_CONV_FROM_UTF8_FUNCTION callback returned %i: %s",
+ rc, curl_easy_strerror(rc));
+ }
+ return(rc);
+ } else {
+#ifdef HAVE_ICONV
+ /* do the translation ourselves */
+ char *input_ptr, *output_ptr;
+ size_t in_bytes, out_bytes, rc;
+
+ /* open an iconv conversion descriptor if necessary */
+ if(data->utf8_cd == (iconv_t)-1) {
+ data->utf8_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
+ CURL_ICONV_CODESET_FOR_UTF8);
+ if(data->utf8_cd == (iconv_t)-1) {
+ failf(data,
+ "The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
+ CURL_ICONV_CODESET_OF_HOST,
+ CURL_ICONV_CODESET_FOR_UTF8,
+ errno, strerror(errno));
+ return CURLE_CONV_FAILED;
+ }
+ }
+ /* call iconv */
+ input_ptr = output_ptr = buffer;
+ in_bytes = out_bytes = length;
+ rc = iconv(data->utf8_cd, (const char**)&input_ptr, &in_bytes,
+ &output_ptr, &out_bytes);
+ if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
+ failf(data,
+ "The Curl_convert_from_utf8 iconv call failed with errno %i: %s",
+ errno, strerror(errno));
+ return CURLE_CONV_FAILED;
+ }
+ if (output_ptr < input_ptr) {
+ /* null terminate the now shorter output string */
+ *output_ptr = 0x00;
+ }
+#else
+ failf(data, "CURLOPT_CONV_FROM_UTF8_FUNCTION callback required");
+ return CURLE_CONV_REQD;
+#endif /* HAVE_ICONV */
+ }
+
+ return CURLE_OK;
+}
+
+#endif /* CURL_DOES_CONVERSIONS */
diff --git a/Utilities/cmcurl/easyif.h b/Utilities/cmcurl/easyif.h
new file mode 100644
index 0000000000..4c0f7e7952
--- /dev/null
+++ b/Utilities/cmcurl/easyif.h
@@ -0,0 +1,40 @@
+#ifndef __EASYIF_H
+#define __EASYIF_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * Prototypes for library-wide functions provided by easy.c
+ */
+void Curl_easy_addmulti(struct SessionHandle *data, void *multi);
+
+void Curl_easy_initHandleData(struct SessionHandle *data);
+
+CURLcode Curl_convert_to_network(struct SessionHandle *data,
+ char *buffer, size_t length);
+CURLcode Curl_convert_from_network(struct SessionHandle *data,
+ char *buffer, size_t length);
+CURLcode Curl_convert_from_utf8(struct SessionHandle *data,
+ char *buffer, size_t length);
+
+#endif /* __EASYIF_H */
diff --git a/Utilities/cmcurl/escape.c b/Utilities/cmcurl/escape.c
new file mode 100644
index 0000000000..9552b0f316
--- /dev/null
+++ b/Utilities/cmcurl/escape.c
@@ -0,0 +1,181 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/* Escape and unescape URL encoding in strings. The functions return a new
+ * allocated string or NULL if an error occurred. */
+
+#include "setup.h"
+#include <ctype.h>
+#include <curl/curl.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "memory.h"
+/* urldata.h and easyif.h are included for Curl_convert_... prototypes */
+#include "urldata.h"
+#include "easyif.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/* for ABI-compatibility with previous versions */
+char *curl_escape(const char *string, int inlength)
+{
+ return curl_easy_escape(NULL, string, inlength);
+}
+
+/* for ABI-compatibility with previous versions */
+char *curl_unescape(const char *string, int length)
+{
+ return curl_easy_unescape(NULL, string, length, NULL);
+}
+
+char *curl_easy_escape(CURL *handle, const char *string, int inlength)
+{
+ size_t alloc = (inlength?(size_t)inlength:strlen(string))+1;
+ char *ns;
+ char *testing_ptr = NULL;
+ unsigned char in;
+ size_t newlen = alloc;
+ int strindex=0;
+ size_t length;
+
+#ifndef CURL_DOES_CONVERSIONS
+ /* avoid compiler warnings */
+ (void)handle;
+#endif
+ ns = malloc(alloc);
+ if(!ns)
+ return NULL;
+
+ length = alloc-1;
+ while(length--) {
+ in = *string;
+ if(!(in >= 'a' && in <= 'z') &&
+ !(in >= 'A' && in <= 'Z') &&
+ !(in >= '0' && in <= '9')) {
+ /* encode it */
+ newlen += 2; /* the size grows with two, since this'll become a %XX */
+ if(newlen > alloc) {
+ alloc *= 2;
+ testing_ptr = realloc(ns, alloc);
+ if(!testing_ptr) {
+ free( ns );
+ return NULL;
+ }
+ else {
+ ns = testing_ptr;
+ }
+ }
+
+#ifdef CURL_DOES_CONVERSIONS
+/* escape sequences are always in ASCII so convert them on non-ASCII hosts */
+ if (!handle ||
+ (Curl_convert_to_network(handle, &in, 1) != CURLE_OK)) {
+ /* Curl_convert_to_network calls failf if unsuccessful */
+ free(ns);
+ return NULL;
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ snprintf(&ns[strindex], 4, "%%%02X", in);
+
+ strindex+=3;
+ }
+ else {
+ /* just copy this */
+ ns[strindex++]=in;
+ }
+ string++;
+ }
+ ns[strindex]=0; /* terminate it */
+ return ns;
+}
+
+char *curl_easy_unescape(CURL *handle, const char *string, int length,
+ int *olen)
+{
+ int alloc = (length?length:(int)strlen(string))+1;
+ char *ns = malloc(alloc);
+ unsigned char in;
+ int strindex=0;
+ long hex;
+
+#ifndef CURL_DOES_CONVERSIONS
+ /* avoid compiler warnings */
+ (void)handle;
+#endif
+ if( !ns )
+ return NULL;
+
+ while(--alloc > 0) {
+ in = *string;
+ if(('%' == in) && ISXDIGIT(string[1]) && ISXDIGIT(string[2])) {
+ /* this is two hexadecimal digits following a '%' */
+ char hexstr[3];
+ char *ptr;
+ hexstr[0] = string[1];
+ hexstr[1] = string[2];
+ hexstr[2] = 0;
+
+ hex = strtol(hexstr, &ptr, 16);
+
+ in = (unsigned char)hex; /* this long is never bigger than 255 anyway */
+
+#ifdef CURL_DOES_CONVERSIONS
+/* escape sequences are always in ASCII so convert them on non-ASCII hosts */
+ if (!handle ||
+ (Curl_convert_from_network(handle, &in, 1) != CURLE_OK)) {
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ free(ns);
+ return NULL;
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ string+=2;
+ alloc-=2;
+ }
+
+ ns[strindex++] = in;
+ string++;
+ }
+ ns[strindex]=0; /* terminate it */
+
+ if(olen)
+ /* store output size */
+ *olen = strindex;
+ return ns;
+}
+
+/* For operating systems/environments that use different malloc/free
+ ssystems for the app and for this library, we provide a free that uses
+ the library's memory system */
+void curl_free(void *p)
+{
+ if(p)
+ free(p);
+}
diff --git a/Utilities/cmcurl/escape.h b/Utilities/cmcurl/escape.h
new file mode 100644
index 0000000000..a0a0209c4c
--- /dev/null
+++ b/Utilities/cmcurl/escape.h
@@ -0,0 +1,30 @@
+#ifndef __ESCAPE_H
+#define __ESCAPE_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+/* Escape and unescape URL encoding in strings. The functions return a new
+ * allocated string or NULL if an error occurred. */
+
+
+#endif
diff --git a/Utilities/cmcurl/file.c b/Utilities/cmcurl/file.c
new file mode 100644
index 0000000000..b247a7736e
--- /dev/null
+++ b/Utilities/cmcurl/file.c
@@ -0,0 +1,407 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_FILE
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef WIN32
+#include <time.h>
+#include <io.h>
+#include <fcntl.h>
+#else
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#include <sys/ioctl.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#endif
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "progress.h"
+#include "sendf.h"
+#include "escape.h"
+#include "file.h"
+#include "speedcheck.h"
+#include "getinfo.h"
+#include "transfer.h"
+#include "url.h"
+#include "memory.h"
+#include "parsedate.h" /* for the week day and month names */
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/*
+ * Curl_file_connect() gets called from Curl_protocol_connect() to allow us to
+ * do protocol-specific actions at connect-time. We emulate a
+ * connect-then-transfer protocol and "connect" to the file here
+ */
+CURLcode Curl_file_connect(struct connectdata *conn)
+{
+ char *real_path = curl_easy_unescape(conn->data, conn->data->reqdata.path, 0, NULL);
+ struct FILEPROTO *file;
+ int fd;
+#if defined(WIN32) || defined(MSDOS) || defined(__EMX__)
+ int i;
+ char *actual_path;
+#endif
+
+ if(!real_path)
+ return CURLE_OUT_OF_MEMORY;
+
+ file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1);
+ if(!file) {
+ free(real_path);
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ if (conn->data->reqdata.proto.file) {
+ free(conn->data->reqdata.proto.file);
+ }
+
+ conn->data->reqdata.proto.file = file;
+
+#if defined(WIN32) || defined(MSDOS) || defined(__EMX__)
+ /* If the first character is a slash, and there's
+ something that looks like a drive at the beginning of
+ the path, skip the slash. If we remove the initial
+ slash in all cases, paths without drive letters end up
+ relative to the current directory which isn't how
+ browsers work.
+
+ Some browsers accept | instead of : as the drive letter
+ separator, so we do too.
+
+ On other platforms, we need the slash to indicate an
+ absolute pathname. On Windows, absolute paths start
+ with a drive letter.
+ */
+ actual_path = real_path;
+ if ((actual_path[0] == '/') &&
+ actual_path[1] &&
+ (actual_path[2] == ':' || actual_path[2] == '|'))
+ {
+ actual_path[2] = ':';
+ actual_path++;
+ }
+
+ /* change path separators from '/' to '\\' for DOS, Windows and OS/2 */
+ for (i=0; actual_path[i] != '\0'; ++i)
+ if (actual_path[i] == '/')
+ actual_path[i] = '\\';
+
+ fd = open(actual_path, O_RDONLY | O_BINARY); /* no CR/LF translation! */
+ file->path = actual_path;
+#else
+ fd = open(real_path, O_RDONLY);
+ file->path = real_path;
+#endif
+ file->freepath = real_path; /* free this when done */
+
+ file->fd = fd;
+ if(!conn->data->set.upload && (fd == -1)) {
+ failf(conn->data, "Couldn't open file %s", conn->data->reqdata.path);
+ Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE);
+ return CURLE_FILE_COULDNT_READ_FILE;
+ }
+
+ return CURLE_OK;
+}
+
+CURLcode Curl_file_done(struct connectdata *conn,
+ CURLcode status, bool premature)
+{
+ struct FILEPROTO *file = conn->data->reqdata.proto.file;
+ (void)status; /* not used */
+ (void)premature; /* not used */
+ Curl_safefree(file->freepath);
+
+ if(file->fd != -1)
+ close(file->fd);
+
+ return CURLE_OK;
+}
+
+#if defined(WIN32) || defined(MSDOS) || defined(__EMX__)
+#define DIRSEP '\\'
+#else
+#define DIRSEP '/'
+#endif
+
+static CURLcode file_upload(struct connectdata *conn)
+{
+ struct FILEPROTO *file = conn->data->reqdata.proto.file;
+ char *dir = strchr(file->path, DIRSEP);
+ FILE *fp;
+ CURLcode res=CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ char *buf = data->state.buffer;
+ size_t nread;
+ size_t nwrite;
+ curl_off_t bytecount = 0;
+ struct timeval now = Curl_tvnow();
+
+ /*
+ * Since FILE: doesn't do the full init, we need to provide some extra
+ * assignments here.
+ */
+ conn->fread = data->set.fread;
+ conn->fread_in = data->set.in;
+ conn->data->reqdata.upload_fromhere = buf;
+
+ if(!dir)
+ return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */
+
+ if(!dir[1])
+ return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */
+
+ fp = fopen(file->path, "wb");
+ if(!fp) {
+ failf(data, "Can't open %s for writing", file->path);
+ return CURLE_WRITE_ERROR;
+ }
+
+ if(-1 != data->set.infilesize)
+ /* known size of data to "upload" */
+ Curl_pgrsSetUploadSize(data, data->set.infilesize);
+
+ while (res == CURLE_OK) {
+ int readcount;
+ res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount);
+ if(res)
+ break;
+
+ if (readcount <= 0) /* fix questionable compare error. curlvms */
+ break;
+
+ nread = (size_t)readcount;
+
+ /* write the data to the target */
+ nwrite = fwrite(buf, 1, nread, fp);
+ if(nwrite != nread) {
+ res = CURLE_SEND_ERROR;
+ break;
+ }
+
+ bytecount += nread;
+
+ Curl_pgrsSetUploadCounter(data, bytecount);
+
+ if(Curl_pgrsUpdate(conn))
+ res = CURLE_ABORTED_BY_CALLBACK;
+ else
+ res = Curl_speedcheck(data, now);
+ }
+ if(!res && Curl_pgrsUpdate(conn))
+ res = CURLE_ABORTED_BY_CALLBACK;
+
+ fclose(fp);
+
+ return res;
+}
+
+/*
+ * Curl_file() is the protocol-specific function for the do-phase, separated
+ * from the connect-phase above. Other protocols merely setup the transfer in
+ * the do-phase, to have it done in the main transfer loop but since some
+ * platforms we support don't allow select()ing etc on file handles (as
+ * opposed to sockets) we instead perform the whole do-operation in this
+ * function.
+ */
+CURLcode Curl_file(struct connectdata *conn, bool *done)
+{
+ /* This implementation ignores the host name in conformance with
+ RFC 1738. Only local files (reachable via the standard file system)
+ are supported. This means that files on remotely mounted directories
+ (via NFS, Samba, NT sharing) can be accessed through a file:// URL
+ */
+ CURLcode res = CURLE_OK;
+ struct_stat statbuf; /* struct_stat instead of struct stat just to allow the
+ Windows version to have a different struct without
+ having to redefine the simple word 'stat' */
+ curl_off_t expected_size=0;
+ bool fstated=FALSE;
+ ssize_t nread;
+ struct SessionHandle *data = conn->data;
+ char *buf = data->state.buffer;
+ curl_off_t bytecount = 0;
+ int fd;
+ struct timeval now = Curl_tvnow();
+
+ *done = TRUE; /* unconditionally */
+
+ Curl_readwrite_init(conn);
+ Curl_initinfo(data);
+ Curl_pgrsStartNow(data);
+
+ if(data->set.upload)
+ return file_upload(conn);
+
+ /* get the fd from the connection phase */
+ fd = conn->data->reqdata.proto.file->fd;
+
+ /* VMS: This only works reliable for STREAMLF files */
+ if( -1 != fstat(fd, &statbuf)) {
+ /* we could stat it, then read out the size */
+ expected_size = statbuf.st_size;
+ fstated = TRUE;
+ }
+
+ /* If we have selected NOBODY and HEADER, it means that we only want file
+ information. Which for FILE can't be much more than the file size and
+ date. */
+ if(conn->bits.no_body && data->set.include_header && fstated) {
+ CURLcode result;
+ snprintf(buf, sizeof(data->state.buffer),
+ "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size);
+ result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
+ if(result)
+ return result;
+
+ result = Curl_client_write(conn, CLIENTWRITE_BOTH,
+ (char *)"Accept-ranges: bytes\r\n", 0);
+ if(result)
+ return result;
+
+ if(fstated) {
+ struct tm *tm;
+ time_t clock = (time_t)statbuf.st_mtime;
+#ifdef HAVE_GMTIME_R
+ struct tm buffer;
+ tm = (struct tm *)gmtime_r(&clock, &buffer);
+#else
+ tm = gmtime(&clock);
+#endif
+ /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
+ snprintf(buf, BUFSIZE-1,
+ "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
+ Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
+ tm->tm_mday,
+ Curl_month[tm->tm_mon],
+ tm->tm_year + 1900,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec);
+ result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
+ }
+ return result;
+ }
+
+ if (data->reqdata.resume_from <= expected_size)
+ expected_size -= data->reqdata.resume_from;
+ else {
+ failf(data, "failed to resume file:// transfer");
+ return CURLE_BAD_DOWNLOAD_RESUME;
+ }
+
+ if (fstated && (expected_size == 0))
+ return CURLE_OK;
+
+ /* The following is a shortcut implementation of file reading
+ this is both more efficient than the former call to download() and
+ it avoids problems with select() and recv() on file descriptors
+ in Winsock */
+ if(fstated)
+ Curl_pgrsSetDownloadSize(data, expected_size);
+
+ if(data->reqdata.resume_from) {
+ if(data->reqdata.resume_from !=
+ lseek(fd, data->reqdata.resume_from, SEEK_SET))
+ return CURLE_BAD_DOWNLOAD_RESUME;
+ }
+
+ Curl_pgrsTime(data, TIMER_STARTTRANSFER);
+
+ while (res == CURLE_OK) {
+ nread = read(fd, buf, BUFSIZE-1);
+
+ if ( nread > 0)
+ buf[nread] = 0;
+
+ if (nread <= 0)
+ break;
+
+ bytecount += nread;
+
+ res = Curl_client_write(conn, CLIENTWRITE_BODY, buf, nread);
+ if(res)
+ return res;
+
+ Curl_pgrsSetDownloadCounter(data, bytecount);
+
+ if(Curl_pgrsUpdate(conn))
+ res = CURLE_ABORTED_BY_CALLBACK;
+ else
+ res = Curl_speedcheck(data, now);
+ }
+ if(Curl_pgrsUpdate(conn))
+ res = CURLE_ABORTED_BY_CALLBACK;
+
+ return res;
+}
+
+#endif
diff --git a/Utilities/cmcurl/file.h b/Utilities/cmcurl/file.h
new file mode 100644
index 0000000000..20a1c4c063
--- /dev/null
+++ b/Utilities/cmcurl/file.h
@@ -0,0 +1,31 @@
+#ifndef __FILE_H
+#define __FILE_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#ifndef CURL_DISABLE_FILE
+CURLcode Curl_file(struct connectdata *, bool *done);
+CURLcode Curl_file_done(struct connectdata *, CURLcode, bool premature);
+CURLcode Curl_file_connect(struct connectdata *);
+#endif
+#endif
diff --git a/Utilities/cmcurl/formdata.c b/Utilities/cmcurl/formdata.c
new file mode 100644
index 0000000000..f10c6c70e1
--- /dev/null
+++ b/Utilities/cmcurl/formdata.c
@@ -0,0 +1,1694 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ Debug the form generator stand-alone by compiling this source file with:
+
+ gcc -DHAVE_CONFIG_H -I../ -g -D_FORM_DEBUG -DCURLDEBUG -o formdata -I../include formdata.c strequal.c memdebug.c mprintf.c strerror.c
+
+ run the 'formdata' executable the output should end with:
+ All Tests seem to have worked ...
+ and the following parts should be there:
+
+Content-Disposition: form-data; name="simple_COPYCONTENTS"
+value for simple COPYCONTENTS
+
+Content-Disposition: form-data; name="COPYCONTENTS_+_CONTENTTYPE"
+Content-Type: image/gif
+value for COPYCONTENTS + CONTENTTYPE
+
+Content-Disposition: form-data; name="PRNAME_+_NAMELENGTH_+_COPYNAME_+_CONTENTSLENGTH"
+vlue for PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH
+(or you might see P^@RNAME and v^@lue at the start)
+
+Content-Disposition: form-data; name="simple_PTRCONTENTS"
+value for simple PTRCONTENTS
+
+Content-Disposition: form-data; name="PTRCONTENTS_+_CONTENTSLENGTH"
+vlue for PTRCONTENTS + CONTENTSLENGTH
+(or you might see v^@lue at the start)
+
+Content-Disposition: form-data; name="PTRCONTENTS_+_CONTENTSLENGTH_+_CONTENTTYPE"
+Content-Type: text/plain
+vlue for PTRCOTNENTS + CONTENTSLENGTH + CONTENTTYPE
+(or you might see v^@lue at the start)
+
+Content-Disposition: form-data; name="FILE1_+_CONTENTTYPE"; filename="inet_ntoa_r.h"
+Content-Type: text/html
+...
+
+Content-Disposition: form-data; name="FILE1_+_FILE2"
+Content-Type: multipart/mixed, boundary=curlz1s0dkticx49MV1KGcYP5cvfSsz
+...
+Content-Disposition: attachment; filename="inet_ntoa_r.h"
+Content-Type: text/plain
+...
+Content-Disposition: attachment; filename="Makefile.b32"
+Content-Type: text/plain
+...
+
+Content-Disposition: form-data; name="FILE1_+_FILE2_+_FILE3"
+Content-Type: multipart/mixed, boundary=curlirkYPmPwu6FrJ1vJ1u1BmtIufh1
+...
+Content-Disposition: attachment; filename="inet_ntoa_r.h"
+Content-Type: text/plain
+...
+Content-Disposition: attachment; filename="Makefile.b32"
+Content-Type: text/plain
+...
+Content-Disposition: attachment; filename="inet_ntoa_r.h"
+Content-Type: text/plain
+...
+
+
+Content-Disposition: form-data; name="ARRAY: FILE1_+_FILE2_+_FILE3"
+Content-Type: multipart/mixed, boundary=curlirkYPmPwu6FrJ1vJ1u1BmtIufh1
+...
+Content-Disposition: attachment; filename="inet_ntoa_r.h"
+Content-Type: text/plain
+...
+Content-Disposition: attachment; filename="Makefile.b32"
+Content-Type: text/plain
+...
+Content-Disposition: attachment; filename="inet_ntoa_r.h"
+Content-Type: text/plain
+...
+
+Content-Disposition: form-data; name="FILECONTENT"
+...
+
+ */
+
+#include "setup.h"
+#include <curl/curl.h>
+
+/* Length of the random boundary string. */
+#define BOUNDARY_LENGTH 40
+
+#if !defined(CURL_DISABLE_HTTP) || defined(USE_SSLEAY)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <time.h>
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#if defined(HAVE_LIBGEN_H) && defined(HAVE_BASENAME)
+#include <libgen.h>
+#endif
+#include "urldata.h" /* for struct SessionHandle */
+#include "easyif.h" /* for Curl_convert_... prototypes */
+#include "formdata.h"
+#include "strequal.h"
+#include "memory.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#endif /* !defined(CURL_DISABLE_HTTP) || defined(USE_SSLEAY) */
+
+#ifndef CURL_DISABLE_HTTP
+
+#if defined(HAVE_BASENAME) && defined(NEED_BASENAME_PROTO)
+/* This system has a basename() but no prototype for it! */
+char *basename(char *path);
+#endif
+
+static size_t readfromfile(struct Form *form, char *buffer, size_t size);
+
+/* What kind of Content-Type to use on un-specified files with unrecognized
+ extensions. */
+#define HTTPPOST_CONTENTTYPE_DEFAULT "application/octet-stream"
+
+#define FORM_FILE_SEPARATOR ','
+#define FORM_TYPE_SEPARATOR ';'
+
+/***************************************************************************
+ *
+ * AddHttpPost()
+ *
+ * Adds a HttpPost structure to the list, if parent_post is given becomes
+ * a subpost of parent_post instead of a direct list element.
+ *
+ * Returns newly allocated HttpPost on success and NULL if malloc failed.
+ *
+ ***************************************************************************/
+static struct curl_httppost *
+AddHttpPost(char * name, size_t namelength,
+ char * value, size_t contentslength,
+ char * buffer, size_t bufferlength,
+ char *contenttype,
+ long flags,
+ struct curl_slist* contentHeader,
+ char *showfilename,
+ struct curl_httppost *parent_post,
+ struct curl_httppost **httppost,
+ struct curl_httppost **last_post)
+{
+ struct curl_httppost *post;
+ post = (struct curl_httppost *)calloc(sizeof(struct curl_httppost), 1);
+ if(post) {
+ post->name = name;
+ post->namelength = (long)(name?(namelength?namelength:strlen(name)):0);
+ post->contents = value;
+ post->contentslength = (long)contentslength;
+ post->buffer = buffer;
+ post->bufferlength = (long)bufferlength;
+ post->contenttype = contenttype;
+ post->contentheader = contentHeader;
+ post->showfilename = showfilename;
+ post->flags = flags;
+ }
+ else
+ return NULL;
+
+ if (parent_post) {
+ /* now, point our 'more' to the original 'more' */
+ post->more = parent_post->more;
+
+ /* then move the original 'more' to point to ourselves */
+ parent_post->more = post;
+ }
+ else {
+ /* make the previous point to this */
+ if(*last_post)
+ (*last_post)->next = post;
+ else
+ (*httppost) = post;
+
+ (*last_post) = post;
+ }
+ return post;
+}
+
+/***************************************************************************
+ *
+ * AddFormInfo()
+ *
+ * Adds a FormInfo structure to the list presented by parent_form_info.
+ *
+ * Returns newly allocated FormInfo on success and NULL if malloc failed/
+ * parent_form_info is NULL.
+ *
+ ***************************************************************************/
+static FormInfo * AddFormInfo(char *value,
+ char *contenttype,
+ FormInfo *parent_form_info)
+{
+ FormInfo *form_info;
+ form_info = (FormInfo *)malloc(sizeof(FormInfo));
+ if(form_info) {
+ memset(form_info, 0, sizeof(FormInfo));
+ if (value)
+ form_info->value = value;
+ if (contenttype)
+ form_info->contenttype = contenttype;
+ form_info->flags = HTTPPOST_FILENAME;
+ }
+ else
+ return NULL;
+
+ if (parent_form_info) {
+ /* now, point our 'more' to the original 'more' */
+ form_info->more = parent_form_info->more;
+
+ /* then move the original 'more' to point to ourselves */
+ parent_form_info->more = form_info;
+ }
+ else
+ return NULL;
+
+ return form_info;
+}
+
+/***************************************************************************
+ *
+ * ContentTypeForFilename()
+ *
+ * Provides content type for filename if one of the known types (else
+ * (either the prevtype or the default is returned).
+ *
+ * Returns some valid contenttype for filename.
+ *
+ ***************************************************************************/
+static const char * ContentTypeForFilename (const char *filename,
+ const char *prevtype)
+{
+ const char *contenttype = NULL;
+ unsigned int i;
+ /*
+ * No type was specified, we scan through a few well-known
+ * extensions and pick the first we match!
+ */
+ struct ContentType {
+ const char *extension;
+ const char *type;
+ };
+ static const struct ContentType ctts[]={
+ {".gif", "image/gif"},
+ {".jpg", "image/jpeg"},
+ {".jpeg", "image/jpeg"},
+ {".txt", "text/plain"},
+ {".html", "text/html"}
+ };
+
+ if(prevtype)
+ /* default to the previously set/used! */
+ contenttype = prevtype;
+ else
+ /* It seems RFC1867 defines no Content-Type to default to
+ text/plain so we don't actually need to set this: */
+ contenttype = HTTPPOST_CONTENTTYPE_DEFAULT;
+
+ for(i=0; i<sizeof(ctts)/sizeof(ctts[0]); i++) {
+ if(strlen(filename) >= strlen(ctts[i].extension)) {
+ if(strequal(filename +
+ strlen(filename) - strlen(ctts[i].extension),
+ ctts[i].extension)) {
+ contenttype = ctts[i].type;
+ break;
+ }
+ }
+ }
+ /* we have a contenttype by now */
+ return contenttype;
+}
+
+/***************************************************************************
+ *
+ * memdup()
+ *
+ * Copies the 'source' data to a newly allocated buffer buffer (that is
+ * returned). Uses buffer_length if not null, else uses strlen to determine
+ * the length of the buffer to be copied
+ *
+ * Returns the new pointer or NULL on failure.
+ *
+ ***************************************************************************/
+static char *memdup(const char *src, size_t buffer_length)
+{
+ size_t length;
+ bool add = FALSE;
+ char *buffer;
+
+ if (buffer_length)
+ length = buffer_length;
+ else {
+ length = strlen(src);
+ add = TRUE;
+ }
+ buffer = (char*)malloc(length+add);
+ if (!buffer)
+ return NULL; /* fail */
+
+ memcpy(buffer, src, length);
+
+ /* if length unknown do null termination */
+ if (add)
+ buffer[length] = '\0';
+
+ return buffer;
+}
+
+/***************************************************************************
+ *
+ * FormAdd()
+ *
+ * Stores a formpost parameter and builds the appropriate linked list.
+ *
+ * Has two principal functionalities: using files and byte arrays as
+ * post parts. Byte arrays are either copied or just the pointer is stored
+ * (as the user requests) while for files only the filename and not the
+ * content is stored.
+ *
+ * While you may have only one byte array for each name, multiple filenames
+ * are allowed (and because of this feature CURLFORM_END is needed after
+ * using CURLFORM_FILE).
+ *
+ * Examples:
+ *
+ * Simple name/value pair with copied contents:
+ * curl_formadd (&post, &last, CURLFORM_COPYNAME, "name",
+ * CURLFORM_COPYCONTENTS, "value", CURLFORM_END);
+ *
+ * name/value pair where only the content pointer is remembered:
+ * curl_formadd (&post, &last, CURLFORM_COPYNAME, "name",
+ * CURLFORM_PTRCONTENTS, ptr, CURLFORM_CONTENTSLENGTH, 10, CURLFORM_END);
+ * (if CURLFORM_CONTENTSLENGTH is missing strlen () is used)
+ *
+ * storing a filename (CONTENTTYPE is optional!):
+ * curl_formadd (&post, &last, CURLFORM_COPYNAME, "name",
+ * CURLFORM_FILE, "filename1", CURLFORM_CONTENTTYPE, "plain/text",
+ * CURLFORM_END);
+ *
+ * storing multiple filenames:
+ * curl_formadd (&post, &last, CURLFORM_COPYNAME, "name",
+ * CURLFORM_FILE, "filename1", CURLFORM_FILE, "filename2", CURLFORM_END);
+ *
+ * Returns:
+ * CURL_FORMADD_OK on success
+ * CURL_FORMADD_MEMORY if the FormInfo allocation fails
+ * CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form
+ * CURL_FORMADD_NULL if a null pointer was given for a char
+ * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed
+ * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used
+ * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or an error)
+ * CURL_FORMADD_MEMORY if a HttpPost struct cannot be allocated
+ * CURL_FORMADD_MEMORY if some allocation for string copying failed.
+ * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array
+ *
+ ***************************************************************************/
+
+static
+CURLFORMcode FormAdd(struct curl_httppost **httppost,
+ struct curl_httppost **last_post,
+ va_list params)
+{
+ FormInfo *first_form, *current_form, *form = NULL;
+ CURLFORMcode return_value = CURL_FORMADD_OK;
+ const char *prevtype = NULL;
+ struct curl_httppost *post = NULL;
+ CURLformoption option;
+ struct curl_forms *forms = NULL;
+ char *array_value=NULL; /* value read from an array */
+
+ /* This is a state variable, that if TRUE means that we're parsing an
+ array that we got passed to us. If FALSE we're parsing the input
+ va_list arguments. */
+ bool array_state = FALSE;
+
+ /*
+ * We need to allocate the first struct to fill in.
+ */
+ first_form = (FormInfo *)calloc(sizeof(struct FormInfo), 1);
+ if(!first_form)
+ return CURL_FORMADD_MEMORY;
+
+ current_form = first_form;
+
+ /*
+ * Loop through all the options set. Break if we have an error to report.
+ */
+ while (return_value == CURL_FORMADD_OK) {
+
+ /* first see if we have more parts of the array param */
+ if ( array_state ) {
+ /* get the upcoming option from the given array */
+ option = forms->option;
+ array_value = (char *)forms->value;
+
+ forms++; /* advance this to next entry */
+ if (CURLFORM_END == option) {
+ /* end of array state */
+ array_state = FALSE;
+ continue;
+ }
+ }
+ else {
+ /* This is not array-state, get next option */
+ option = va_arg(params, CURLformoption);
+ if (CURLFORM_END == option)
+ break;
+ }
+
+ switch (option) {
+ case CURLFORM_ARRAY:
+ if(array_state)
+ /* we don't support an array from within an array */
+ return_value = CURL_FORMADD_ILLEGAL_ARRAY;
+ else {
+ forms = va_arg(params, struct curl_forms *);
+ if (forms)
+ array_state = TRUE;
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ break;
+
+ /*
+ * Set the Name property.
+ */
+ case CURLFORM_PTRNAME:
+#ifdef CURL_DOES_CONVERSIONS
+ /* treat CURLFORM_PTR like CURLFORM_COPYNAME so we'll
+ have safe memory for the eventual conversion */
+#else
+ current_form->flags |= HTTPPOST_PTRNAME; /* fall through */
+#endif
+ case CURLFORM_COPYNAME:
+ if (current_form->name)
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ else {
+ char *name = array_state?
+ array_value:va_arg(params, char *);
+ if (name)
+ current_form->name = name; /* store for the moment */
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ break;
+ case CURLFORM_NAMELENGTH:
+ if (current_form->namelength)
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ else
+ current_form->namelength =
+ array_state?(long)array_value:(long)va_arg(params, long);
+ break;
+
+ /*
+ * Set the contents property.
+ */
+ case CURLFORM_PTRCONTENTS:
+ current_form->flags |= HTTPPOST_PTRCONTENTS; /* fall through */
+ case CURLFORM_COPYCONTENTS:
+ if (current_form->value)
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ else {
+ char *value =
+ array_state?array_value:va_arg(params, char *);
+ if (value)
+ current_form->value = value; /* store for the moment */
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ break;
+ case CURLFORM_CONTENTSLENGTH:
+ if (current_form->contentslength)
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ else
+ current_form->contentslength =
+ array_state?(long)array_value:va_arg(params, long);
+ break;
+
+ /* Get contents from a given file name */
+ case CURLFORM_FILECONTENT:
+ if (current_form->flags != 0)
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ else {
+ char *filename = array_state?
+ array_value:va_arg(params, char *);
+ if (filename) {
+ current_form->value = strdup(filename);
+ if(!current_form->value)
+ return_value = CURL_FORMADD_MEMORY;
+ else {
+ current_form->flags |= HTTPPOST_READFILE;
+ current_form->value_alloc = TRUE;
+ }
+ }
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ break;
+
+ /* We upload a file */
+ case CURLFORM_FILE:
+ {
+ char *filename = array_state?array_value:
+ va_arg(params, char *);
+
+ if (current_form->value) {
+ if (current_form->flags & HTTPPOST_FILENAME) {
+ if (filename) {
+ if ((current_form = AddFormInfo(strdup(filename),
+ NULL, current_form)) == NULL)
+ return_value = CURL_FORMADD_MEMORY;
+ }
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ else
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ }
+ else {
+ if (filename) {
+ current_form->value = strdup(filename);
+ if(!current_form->value)
+ return_value = CURL_FORMADD_MEMORY;
+ else {
+ current_form->flags |= HTTPPOST_FILENAME;
+ current_form->value_alloc = TRUE;
+ }
+ }
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ break;
+ }
+
+ case CURLFORM_BUFFER:
+ {
+ char *filename = array_state?array_value:
+ va_arg(params, char *);
+
+ if (current_form->value) {
+ if (current_form->flags & HTTPPOST_BUFFER) {
+ if (filename) {
+ if ((current_form = AddFormInfo(strdup(filename),
+ NULL, current_form)) == NULL)
+ return_value = CURL_FORMADD_MEMORY;
+ }
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ else
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ }
+ else {
+ if (filename) {
+ current_form->value = strdup(filename);
+ if(!current_form->value)
+ return_value = CURL_FORMADD_MEMORY;
+ }
+ else
+ return_value = CURL_FORMADD_NULL;
+ current_form->flags |= HTTPPOST_BUFFER;
+ }
+ break;
+ }
+
+ case CURLFORM_BUFFERPTR:
+ current_form->flags |= HTTPPOST_PTRBUFFER;
+ if (current_form->buffer)
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ else {
+ char *buffer =
+ array_state?array_value:va_arg(params, char *);
+ if (buffer)
+ current_form->buffer = buffer; /* store for the moment */
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ break;
+
+ case CURLFORM_BUFFERLENGTH:
+ if (current_form->bufferlength)
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ else
+ current_form->bufferlength =
+ array_state?(long)array_value:va_arg(params, long);
+ break;
+
+ case CURLFORM_CONTENTTYPE:
+ {
+ char *contenttype =
+ array_state?array_value:va_arg(params, char *);
+ if (current_form->contenttype) {
+ if (current_form->flags & HTTPPOST_FILENAME) {
+ if (contenttype) {
+ if ((current_form = AddFormInfo(NULL,
+ strdup(contenttype),
+ current_form)) == NULL)
+ return_value = CURL_FORMADD_MEMORY;
+ }
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ else
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ }
+ else {
+ if (contenttype) {
+ current_form->contenttype = strdup(contenttype);
+ if(!current_form->contenttype)
+ return_value = CURL_FORMADD_MEMORY;
+ else
+ current_form->contenttype_alloc = TRUE;
+ }
+ else
+ return_value = CURL_FORMADD_NULL;
+ }
+ break;
+ }
+ case CURLFORM_CONTENTHEADER:
+ {
+ /* this "cast increases required alignment of target type" but
+ we consider it OK anyway */
+ struct curl_slist* list = array_state?
+ (struct curl_slist*)array_value:
+ va_arg(params, struct curl_slist*);
+
+ if( current_form->contentheader )
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ else
+ current_form->contentheader = list;
+
+ break;
+ }
+ case CURLFORM_FILENAME:
+ {
+ char *filename = array_state?array_value:
+ va_arg(params, char *);
+ if( current_form->showfilename )
+ return_value = CURL_FORMADD_OPTION_TWICE;
+ else {
+ current_form->showfilename = strdup(filename);
+ if(!current_form->showfilename)
+ return_value = CURL_FORMADD_MEMORY;
+ else
+ current_form->showfilename_alloc = TRUE;
+ }
+ break;
+ }
+ default:
+ return_value = CURL_FORMADD_UNKNOWN_OPTION;
+ }
+ }
+
+ if(CURL_FORMADD_OK == return_value) {
+ /* go through the list, check for copleteness and if everything is
+ * alright add the HttpPost item otherwise set return_value accordingly */
+
+ post = NULL;
+ for(form = first_form;
+ form != NULL;
+ form = form->more) {
+ if ( ((!form->name || !form->value) && !post) ||
+ ( (form->contentslength) &&
+ (form->flags & HTTPPOST_FILENAME) ) ||
+ ( (form->flags & HTTPPOST_FILENAME) &&
+ (form->flags & HTTPPOST_PTRCONTENTS) ) ||
+
+ ( (!form->buffer) &&
+ (form->flags & HTTPPOST_BUFFER) &&
+ (form->flags & HTTPPOST_PTRBUFFER) ) ||
+
+ ( (form->flags & HTTPPOST_READFILE) &&
+ (form->flags & HTTPPOST_PTRCONTENTS) )
+ ) {
+ return_value = CURL_FORMADD_INCOMPLETE;
+ break;
+ }
+ else {
+ if ( ((form->flags & HTTPPOST_FILENAME) ||
+ (form->flags & HTTPPOST_BUFFER)) &&
+ !form->contenttype ) {
+ /* our contenttype is missing */
+ form->contenttype
+ = strdup(ContentTypeForFilename(form->value, prevtype));
+ if(!form->contenttype) {
+ return_value = CURL_FORMADD_MEMORY;
+ break;
+ }
+ form->contenttype_alloc = TRUE;
+ }
+ if ( !(form->flags & HTTPPOST_PTRNAME) &&
+ (form == first_form) ) {
+ /* copy name (without strdup; possibly contains null characters) */
+ form->name = memdup(form->name, form->namelength);
+ if (!form->name) {
+ return_value = CURL_FORMADD_MEMORY;
+ break;
+ }
+ form->name_alloc = TRUE;
+ }
+ if ( !(form->flags & HTTPPOST_FILENAME) &&
+ !(form->flags & HTTPPOST_READFILE) &&
+ !(form->flags & HTTPPOST_PTRCONTENTS) &&
+ !(form->flags & HTTPPOST_PTRBUFFER) ) {
+ /* copy value (without strdup; possibly contains null characters) */
+ form->value = memdup(form->value, form->contentslength);
+ if (!form->value) {
+ return_value = CURL_FORMADD_MEMORY;
+ break;
+ }
+ form->value_alloc = TRUE;
+ }
+ post = AddHttpPost(form->name, form->namelength,
+ form->value, form->contentslength,
+ form->buffer, form->bufferlength,
+ form->contenttype, form->flags,
+ form->contentheader, form->showfilename,
+ post, httppost,
+ last_post);
+
+ if(!post) {
+ return_value = CURL_FORMADD_MEMORY;
+ break;
+ }
+
+ if (form->contenttype)
+ prevtype = form->contenttype;
+ }
+ }
+ }
+
+ if(return_value) {
+ /* we return on error, free possibly allocated fields */
+ if(!form)
+ form = current_form;
+ if(form) {
+ if(form->name_alloc)
+ free(form->name);
+ if(form->value_alloc)
+ free(form->value);
+ if(form->contenttype_alloc)
+ free(form->contenttype);
+ if(form->showfilename_alloc)
+ free(form->showfilename);
+ }
+ }
+
+ /* always delete the allocated memory before returning */
+ form = first_form;
+ while (form != NULL) {
+ FormInfo *delete_form;
+
+ delete_form = form;
+ form = form->more;
+ free (delete_form);
+ }
+
+ return return_value;
+}
+
+/*
+ * curl_formadd() is a public API to add a section to the multipart formpost.
+ */
+
+CURLFORMcode curl_formadd(struct curl_httppost **httppost,
+ struct curl_httppost **last_post,
+ ...)
+{
+ va_list arg;
+ CURLFORMcode result;
+ va_start(arg, last_post);
+ result = FormAdd(httppost, last_post, arg);
+ va_end(arg);
+ return result;
+}
+
+/*
+ * AddFormData() adds a chunk of data to the FormData linked list.
+ *
+ * size is incremented by the chunk length, unless it is NULL
+ */
+static CURLcode AddFormData(struct FormData **formp,
+ enum formtype type,
+ const void *line,
+ size_t length,
+ curl_off_t *size)
+{
+ struct FormData *newform = (struct FormData *)
+ malloc(sizeof(struct FormData));
+ if (!newform)
+ return CURLE_OUT_OF_MEMORY;
+ newform->next = NULL;
+
+ /* we make it easier for plain strings: */
+ if(!length)
+ length = strlen((char *)line);
+
+ newform->line = (char *)malloc(length+1);
+ if (!newform->line) {
+ free(newform);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ memcpy(newform->line, line, length);
+ newform->length = length;
+ newform->line[length]=0; /* zero terminate for easier debugging */
+ newform->type = type;
+
+ if(*formp) {
+ (*formp)->next = newform;
+ *formp = newform;
+ }
+ else
+ *formp = newform;
+
+ if (size) {
+ if((type == FORM_DATA) || (type == FORM_CONTENT))
+ *size += length;
+ else {
+ /* Since this is a file to be uploaded here, add the size of the actual
+ file */
+ if(!strequal("-", newform->line)) {
+ struct_stat file;
+ if(!stat(newform->line, &file)) {
+ *size += file.st_size;
+ }
+ }
+ }
+ }
+ return CURLE_OK;
+}
+
+/*
+ * AddFormDataf() adds printf()-style formatted data to the formdata chain.
+ */
+
+static CURLcode AddFormDataf(struct FormData **formp,
+ curl_off_t *size,
+ const char *fmt, ...)
+{
+ char s[4096];
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(s, sizeof(s), fmt, ap);
+ va_end(ap);
+
+ return AddFormData(formp, FORM_DATA, s, 0, size);
+}
+
+/*
+ * Curl_formclean() is used from http.c, this cleans a built FormData linked
+ * list
+ */
+void Curl_formclean(struct FormData **form_ptr)
+{
+ struct FormData *next, *form;
+
+ form = *form_ptr;
+ if(!form)
+ return;
+
+ do {
+ next=form->next; /* the following form line */
+ free(form->line); /* free the line */
+ free(form); /* free the struct */
+
+ } while ((form = next) != NULL); /* continue */
+
+ *form_ptr = NULL;
+}
+
+#ifdef CURL_DOES_CONVERSIONS
+/*
+ * Curl_formcovert() is used from http.c, this converts any
+ form items that need to be sent in the network encoding.
+ Returns CURLE_OK on success.
+ */
+CURLcode Curl_formconvert(struct SessionHandle *data, struct FormData *form)
+{
+ struct FormData *next;
+ CURLcode rc;
+
+ if(!form)
+ return CURLE_OK;
+
+ if(!data)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ do {
+ next=form->next; /* the following form line */
+ if (form->type == FORM_DATA) {
+ rc = Curl_convert_to_network(data, form->line, form->length);
+ /* Curl_convert_to_network calls failf if unsuccessful */
+ if (rc != CURLE_OK)
+ return rc;
+ }
+ } while ((form = next) != NULL); /* continue */
+ return CURLE_OK;
+}
+#endif /* CURL_DOES_CONVERSIONS */
+
+/*
+ * curl_formget()
+ * Serialize a curl_httppost struct.
+ * Returns 0 on success.
+ */
+int curl_formget(struct curl_httppost *form, void *arg,
+ curl_formget_callback append)
+{
+ CURLcode rc;
+ curl_off_t size;
+ struct FormData *data, *ptr;
+
+ rc = Curl_getFormData(&data, form, NULL, &size);
+ if (rc != CURLE_OK)
+ return (int)rc;
+
+ for (ptr = data; ptr; ptr = ptr->next) {
+ if (ptr->type == FORM_FILE) {
+ char buffer[8192];
+ size_t read;
+ struct Form temp;
+
+ Curl_FormInit(&temp, ptr);
+
+ do {
+ read = readfromfile(&temp, buffer, sizeof(buffer));
+ if ((read == (size_t) -1) || (read != append(arg, buffer, read))) {
+ if (temp.fp) {
+ fclose(temp.fp);
+ }
+ Curl_formclean(&data);
+ return -1;
+ }
+ } while (read == sizeof(buffer));
+ } else {
+ if (ptr->length != append(arg, ptr->line, ptr->length)) {
+ Curl_formclean(&data);
+ return -1;
+ }
+ }
+ }
+ Curl_formclean(&data);
+ return 0;
+}
+
+/*
+ * curl_formfree() is an external function to free up a whole form post
+ * chain
+ */
+void curl_formfree(struct curl_httppost *form)
+{
+ struct curl_httppost *next;
+
+ if(!form)
+ /* no form to free, just get out of this */
+ return;
+
+ do {
+ next=form->next; /* the following form line */
+
+ /* recurse to sub-contents */
+ if(form->more)
+ curl_formfree(form->more);
+
+ if( !(form->flags & HTTPPOST_PTRNAME) && form->name)
+ free(form->name); /* free the name */
+ if( !(form->flags & HTTPPOST_PTRCONTENTS) && form->contents)
+ free(form->contents); /* free the contents */
+ if(form->contenttype)
+ free(form->contenttype); /* free the content type */
+ if(form->showfilename)
+ free(form->showfilename); /* free the faked file name */
+ free(form); /* free the struct */
+
+ } while ((form = next) != NULL); /* continue */
+}
+
+#ifndef HAVE_BASENAME
+/*
+ (Quote from The Open Group Base Specifications Issue 6 IEEE Std 1003.1, 2004
+ Edition)
+
+ The basename() function shall take the pathname pointed to by path and
+ return a pointer to the final component of the pathname, deleting any
+ trailing '/' characters.
+
+ If the string pointed to by path consists entirely of the '/' character,
+ basename() shall return a pointer to the string "/". If the string pointed
+ to by path is exactly "//", it is implementation-defined whether '/' or "//"
+ is returned.
+
+ If path is a null pointer or points to an empty string, basename() shall
+ return a pointer to the string ".".
+
+ The basename() function may modify the string pointed to by path, and may
+ return a pointer to static storage that may then be overwritten by a
+ subsequent call to basename().
+
+ The basename() function need not be reentrant. A function that is not
+ required to be reentrant is not required to be thread-safe.
+
+*/
+static char *basename(char *path)
+{
+ /* Ignore all the details above for now and make a quick and simple
+ implementaion here */
+ char *s1;
+ char *s2;
+
+ s1=strrchr(path, '/');
+ s2=strrchr(path, '\\');
+
+ if(s1 && s2) {
+ path = (s1 > s2? s1 : s2)+1;
+ }
+ else if(s1)
+ path = s1 + 1;
+ else if(s2)
+ path = s2 + 1;
+
+ return path;
+}
+#endif
+
+static char *strippath(char *fullfile)
+{
+ char *filename;
+ char *base;
+ filename = strdup(fullfile); /* duplicate since basename() may ruin the
+ buffer it works on */
+ if(!filename)
+ return NULL;
+ base = strdup(basename(filename));
+
+ free(filename); /* free temporary buffer */
+
+ return base; /* returns an allocated string! */
+}
+
+/*
+ * Curl_getFormData() converts a linked list of "meta data" into a complete
+ * (possibly huge) multipart formdata. The input list is in 'post', while the
+ * output resulting linked lists gets stored in '*finalform'. *sizep will get
+ * the total size of the whole POST.
+ * A multipart/form_data content-type is built, unless a custom content-type
+ * is passed in 'custom_content_type'.
+ */
+
+CURLcode Curl_getFormData(struct FormData **finalform,
+ struct curl_httppost *post,
+ const char *custom_content_type,
+ curl_off_t *sizep)
+{
+ struct FormData *form = NULL;
+ struct FormData *firstform;
+ struct curl_httppost *file;
+ CURLcode result = CURLE_OK;
+
+ curl_off_t size=0; /* support potentially ENORMOUS formposts */
+ char *boundary;
+ char *fileboundary=NULL;
+ struct curl_slist* curList;
+
+ *finalform=NULL; /* default form is empty */
+
+ if(!post)
+ return result; /* no input => no output! */
+
+ boundary = Curl_FormBoundary();
+ if(!boundary)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* Make the first line of the output */
+ result = AddFormDataf(&form, NULL,
+ "%s; boundary=%s\r\n",
+ custom_content_type?custom_content_type:
+ "Content-Type: multipart/form-data",
+ boundary);
+
+ if (result) {
+ free(boundary);
+ return result;
+ }
+ /* we DO NOT include that line in the total size of the POST, since it'll be
+ part of the header! */
+
+ firstform = form;
+
+ do {
+
+ if(size) {
+ result = AddFormDataf(&form, &size, "\r\n");
+ if (result)
+ break;
+ }
+
+ /* boundary */
+ result = AddFormDataf(&form, &size, "--%s\r\n", boundary);
+ if (result)
+ break;
+
+ /* Maybe later this should be disabled when a custom_content_type is
+ passed, since Content-Disposition is not meaningful for all multipart
+ types.
+ */
+ result = AddFormDataf(&form, &size,
+ "Content-Disposition: form-data; name=\"");
+ if (result)
+ break;
+
+ result = AddFormData(&form, FORM_DATA, post->name, post->namelength,
+ &size);
+ if (result)
+ break;
+
+ result = AddFormDataf(&form, &size, "\"");
+ if (result)
+ break;
+
+ if(post->more) {
+ /* If used, this is a link to more file names, we must then do
+ the magic to include several files with the same field name */
+
+ fileboundary = Curl_FormBoundary();
+
+ result = AddFormDataf(&form, &size,
+ "\r\nContent-Type: multipart/mixed,"
+ " boundary=%s\r\n",
+ fileboundary);
+ if (result)
+ break;
+ }
+
+ file = post;
+
+ do {
+
+ /* If 'showfilename' is set, that is a faked name passed on to us
+ to use to in the formpost. If that is not set, the actually used
+ local file name should be added. */
+
+ if(post->more) {
+ /* if multiple-file */
+ char *filebasename=
+ (!file->showfilename)?strippath(file->contents):NULL;
+
+ result = AddFormDataf(&form, &size,
+ "\r\n--%s\r\nContent-Disposition: "
+ "attachment; filename=\"%s\"",
+ fileboundary,
+ (file->showfilename?file->showfilename:
+ filebasename));
+ if (filebasename)
+ free(filebasename);
+ if (result)
+ break;
+ }
+ else if((post->flags & HTTPPOST_FILENAME) ||
+ (post->flags & HTTPPOST_BUFFER)) {
+
+ char *filebasename=
+ (!post->showfilename)?strippath(post->contents):NULL;
+
+ result = AddFormDataf(&form, &size,
+ "; filename=\"%s\"",
+ (post->showfilename?post->showfilename:
+ filebasename));
+ if (filebasename)
+ free(filebasename);
+
+ if (result)
+ break;
+ }
+
+ if(file->contenttype) {
+ /* we have a specified type */
+ result = AddFormDataf(&form, &size,
+ "\r\nContent-Type: %s",
+ file->contenttype);
+ if (result)
+ break;
+ }
+
+ curList = file->contentheader;
+ while( curList ) {
+ /* Process the additional headers specified for this form */
+ result = AddFormDataf( &form, &size, "\r\n%s", curList->data );
+ if (result)
+ break;
+ curList = curList->next;
+ }
+ if (result) {
+ Curl_formclean(&firstform);
+ free(boundary);
+ return result;
+ }
+
+#if 0
+ /* The header Content-Transfer-Encoding: seems to confuse some receivers
+ * (like the built-in PHP engine). While I can't see any reason why it
+ * should, I can just as well skip this to the benefit of the users who
+ * are using such confused receivers.
+ */
+
+ if(file->contenttype &&
+ !checkprefix("text/", file->contenttype)) {
+ /* this is not a text content, mention our binary encoding */
+ result = AddFormDataf(&form, &size,
+ "\r\nContent-Transfer-Encoding: binary");
+ if (result)
+ break;
+ }
+#endif
+
+ result = AddFormDataf(&form, &size, "\r\n\r\n");
+ if (result)
+ break;
+
+ if((post->flags & HTTPPOST_FILENAME) ||
+ (post->flags & HTTPPOST_READFILE)) {
+ /* we should include the contents from the specified file */
+ FILE *fileread;
+
+ fileread = strequal("-", file->contents)?
+ stdin:fopen(file->contents, "rb"); /* binary read for win32 */
+
+ /*
+ * VMS: This only allows for stream files on VMS. Stream files are
+ * OK, as are FIXED & VAR files WITHOUT implied CC For implied CC,
+ * every record needs to have a \n appended & 1 added to SIZE
+ */
+
+ if(fileread) {
+ if(fileread != stdin) {
+ /* close the file again */
+ fclose(fileread);
+ /* add the file name only - for later reading from this */
+ result = AddFormData(&form, FORM_FILE, file->contents, 0, &size);
+ }
+ else {
+ /* When uploading from stdin, we can't know the size of the file,
+ * thus must read the full file as before. We *could* use chunked
+ * transfer-encoding, but that only works for HTTP 1.1 and we
+ * can't be sure we work with such a server.
+ */
+ size_t nread;
+ char buffer[512];
+ while ((nread = fread(buffer, 1, sizeof(buffer), fileread)) != 0) {
+ result = AddFormData(&form, FORM_CONTENT, buffer, nread, &size);
+ if (result)
+ break;
+ }
+ }
+
+ if (result) {
+ Curl_formclean(&firstform);
+ free(boundary);
+ return result;
+ }
+
+ }
+ else {
+#ifdef _FORM_DEBUG
+ fprintf(stderr,
+ "\n==> Curl_getFormData couldn't open/read \"%s\"\n",
+ file->contents);
+#endif
+ Curl_formclean(&firstform);
+ free(boundary);
+ *finalform = NULL;
+ return CURLE_READ_ERROR;
+ }
+
+ }
+ else if (post->flags & HTTPPOST_BUFFER) {
+ /* include contents of buffer */
+ result = AddFormData(&form, FORM_CONTENT, post->buffer,
+ post->bufferlength, &size);
+ if (result)
+ break;
+ }
+
+ else {
+ /* include the contents we got */
+ result = AddFormData(&form, FORM_CONTENT, post->contents,
+ post->contentslength, &size);
+ if (result)
+ break;
+ }
+ } while ((file = file->more) != NULL); /* for each specified file for this field */
+ if (result) {
+ Curl_formclean(&firstform);
+ free(boundary);
+ return result;
+ }
+
+ if(post->more) {
+ /* this was a multiple-file inclusion, make a termination file
+ boundary: */
+ result = AddFormDataf(&form, &size,
+ "\r\n--%s--",
+ fileboundary);
+ free(fileboundary);
+ if (result)
+ break;
+ }
+
+ } while ((post = post->next) != NULL); /* for each field */
+ if (result) {
+ Curl_formclean(&firstform);
+ free(boundary);
+ return result;
+ }
+
+ /* end-boundary for everything */
+ result = AddFormDataf(&form, &size,
+ "\r\n--%s--\r\n",
+ boundary);
+ if (result) {
+ Curl_formclean(&firstform);
+ free(boundary);
+ return result;
+ }
+
+ *sizep = size;
+
+ free(boundary);
+
+ *finalform=firstform;
+
+ return result;
+}
+
+/*
+ * Curl_FormInit() inits the struct 'form' points to with the 'formdata'
+ * and resets the 'sent' counter.
+ */
+int Curl_FormInit(struct Form *form, struct FormData *formdata )
+{
+ if(!formdata)
+ return 1; /* error */
+
+ form->data = formdata;
+ form->sent = 0;
+ form->fp = NULL;
+
+ return 0;
+}
+
+static size_t readfromfile(struct Form *form, char *buffer, size_t size)
+{
+ size_t nread;
+ if(!form->fp) {
+ /* this file hasn't yet been opened */
+ form->fp = fopen(form->data->line, "rb"); /* b is for binary */
+ if(!form->fp)
+ return (size_t)-1; /* failure */
+ }
+ nread = fread(buffer, 1, size, form->fp);
+
+ if(nread != size) {
+ /* this is the last chunk from the file, move on */
+ fclose(form->fp);
+ form->fp = NULL;
+ form->data = form->data->next;
+ }
+
+ return nread;
+}
+
+/*
+ * Curl_FormReader() is the fread() emulation function that will be used to
+ * deliver the formdata to the transfer loop and then sent away to the peer.
+ */
+size_t Curl_FormReader(char *buffer,
+ size_t size,
+ size_t nitems,
+ FILE *mydata)
+{
+ struct Form *form;
+ size_t wantedsize;
+ size_t gotsize = 0;
+
+ form=(struct Form *)mydata;
+
+ wantedsize = size * nitems;
+
+ if(!form->data)
+ return 0; /* nothing, error, empty */
+
+ if(form->data->type == FORM_FILE) {
+ gotsize = readfromfile(form, buffer, wantedsize);
+
+ if(gotsize)
+ /* If positive or -1, return. If zero, continue! */
+ return gotsize;
+ }
+ do {
+
+ if( (form->data->length - form->sent ) > wantedsize - gotsize) {
+
+ memcpy(buffer + gotsize , form->data->line + form->sent,
+ wantedsize - gotsize);
+
+ form->sent += wantedsize-gotsize;
+
+ return wantedsize;
+ }
+
+ memcpy(buffer+gotsize,
+ form->data->line + form->sent,
+ (form->data->length - form->sent) );
+ gotsize += form->data->length - form->sent;
+
+ form->sent = 0;
+
+ form->data = form->data->next; /* advance */
+
+ } while(form->data && (form->data->type != FORM_FILE));
+ /* If we got an empty line and we have more data, we proceed to the next
+ line immediately to avoid returning zero before we've reached the end.
+ This is the bug reported November 22 1999 on curl 6.3. (Daniel) */
+
+ return gotsize;
+}
+
+/*
+ * Curl_formpostheader() returns the first line of the formpost, the
+ * request-header part (which is not part of the request-body like the rest of
+ * the post).
+ */
+char *Curl_formpostheader(void *formp, size_t *len)
+{
+ char *header;
+ struct Form *form=(struct Form *)formp;
+
+ if(!form->data)
+ return 0; /* nothing, ERROR! */
+
+ header = form->data->line;
+ *len = form->data->length;
+
+ form->data = form->data->next; /* advance */
+
+ return header;
+}
+
+
+#ifdef _FORM_DEBUG
+int FormAddTest(const char * errormsg,
+ struct curl_httppost **httppost,
+ struct curl_httppost **last_post,
+ ...)
+{
+ int result;
+ va_list arg;
+ va_start(arg, last_post);
+ if ((result = FormAdd(httppost, last_post, arg)))
+ fprintf (stderr, "ERROR doing FormAdd ret: %d action: %s\n", result,
+ errormsg);
+ va_end(arg);
+ return result;
+}
+
+
+int main()
+{
+ char name1[] = "simple_COPYCONTENTS";
+ char name2[] = "COPYCONTENTS_+_CONTENTTYPE";
+ char name3[] = "PTRNAME_+_NAMELENGTH_+_COPYNAME_+_CONTENTSLENGTH";
+ char name4[] = "simple_PTRCONTENTS";
+ char name5[] = "PTRCONTENTS_+_CONTENTSLENGTH";
+ char name6[] = "PTRCONTENTS_+_CONTENTSLENGTH_+_CONTENTTYPE";
+ char name7[] = "FILE1_+_CONTENTTYPE";
+ char name8[] = "FILE1_+_FILE2";
+ char name9[] = "FILE1_+_FILE2_+_FILE3";
+ char name10[] = "ARRAY: FILE1_+_FILE2_+_FILE3";
+ char name11[] = "FILECONTENT";
+ char value1[] = "value for simple COPYCONTENTS";
+ char value2[] = "value for COPYCONTENTS + CONTENTTYPE";
+ char value3[] = "value for PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH";
+ char value4[] = "value for simple PTRCONTENTS";
+ char value5[] = "value for PTRCONTENTS + CONTENTSLENGTH";
+ char value6[] = "value for PTRCOTNENTS + CONTENTSLENGTH + CONTENTTYPE";
+ char value7[] = "inet_ntoa_r.h";
+ char value8[] = "Makefile.b32";
+ char type2[] = "image/gif";
+ char type6[] = "text/plain";
+ char type7[] = "text/html";
+ int name3length = strlen(name3);
+ int value3length = strlen(value3);
+ int value5length = strlen(value4);
+ int value6length = strlen(value5);
+ int errors = 0;
+ CURLcode rc;
+ size_t size;
+ size_t nread;
+ char buffer[4096];
+ struct curl_httppost *httppost=NULL;
+ struct curl_httppost *last_post=NULL;
+ struct curl_forms forms[4];
+
+ struct FormData *form;
+ struct Form formread;
+
+ if (FormAddTest("simple COPYCONTENTS test", &httppost, &last_post,
+ CURLFORM_COPYNAME, name1, CURLFORM_COPYCONTENTS, value1,
+ CURLFORM_END))
+ ++errors;
+ if (FormAddTest("COPYCONTENTS + CONTENTTYPE test", &httppost, &last_post,
+ CURLFORM_COPYNAME, name2, CURLFORM_COPYCONTENTS, value2,
+ CURLFORM_CONTENTTYPE, type2, CURLFORM_END))
+ ++errors;
+ /* make null character at start to check that contentslength works
+ correctly */
+ name3[1] = '\0';
+ value3[1] = '\0';
+ if (FormAddTest("PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH test",
+ &httppost, &last_post,
+ CURLFORM_PTRNAME, name3, CURLFORM_COPYCONTENTS, value3,
+ CURLFORM_CONTENTSLENGTH, value3length,
+ CURLFORM_NAMELENGTH, name3length, CURLFORM_END))
+ ++errors;
+ if (FormAddTest("simple PTRCONTENTS test", &httppost, &last_post,
+ CURLFORM_COPYNAME, name4, CURLFORM_PTRCONTENTS, value4,
+ CURLFORM_END))
+ ++errors;
+ /* make null character at start to check that contentslength works
+ correctly */
+ value5[1] = '\0';
+ if (FormAddTest("PTRCONTENTS + CONTENTSLENGTH test", &httppost, &last_post,
+ CURLFORM_COPYNAME, name5, CURLFORM_PTRCONTENTS, value5,
+ CURLFORM_CONTENTSLENGTH, value5length, CURLFORM_END))
+ ++errors;
+ /* make null character at start to check that contentslength works
+ correctly */
+ value6[1] = '\0';
+ if (FormAddTest("PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE test",
+ &httppost, &last_post,
+ CURLFORM_COPYNAME, name6, CURLFORM_PTRCONTENTS, value6,
+ CURLFORM_CONTENTSLENGTH, value6length,
+ CURLFORM_CONTENTTYPE, type6, CURLFORM_END))
+ ++errors;
+ if (FormAddTest("FILE + CONTENTTYPE test", &httppost, &last_post,
+ CURLFORM_COPYNAME, name7, CURLFORM_FILE, value7,
+ CURLFORM_CONTENTTYPE, type7, CURLFORM_END))
+ ++errors;
+ if (FormAddTest("FILE1 + FILE2 test", &httppost, &last_post,
+ CURLFORM_COPYNAME, name8, CURLFORM_FILE, value7,
+ CURLFORM_FILE, value8, CURLFORM_END))
+ ++errors;
+ if (FormAddTest("FILE1 + FILE2 + FILE3 test", &httppost, &last_post,
+ CURLFORM_COPYNAME, name9, CURLFORM_FILE, value7,
+ CURLFORM_FILE, value8, CURLFORM_FILE, value7, CURLFORM_END))
+ ++errors;
+ forms[0].option = CURLFORM_FILE;
+ forms[0].value = value7;
+ forms[1].option = CURLFORM_FILE;
+ forms[1].value = value8;
+ forms[2].option = CURLFORM_FILE;
+ forms[2].value = value7;
+ forms[3].option = CURLFORM_END;
+ if (FormAddTest("FILE1 + FILE2 + FILE3 ARRAY test", &httppost, &last_post,
+ CURLFORM_COPYNAME, name10, CURLFORM_ARRAY, forms,
+ CURLFORM_END))
+ ++errors;
+ if (FormAddTest("FILECONTENT test", &httppost, &last_post,
+ CURLFORM_COPYNAME, name11, CURLFORM_FILECONTENT, value7,
+ CURLFORM_END))
+ ++errors;
+
+ rc = Curl_getFormData(&form, httppost, NULL, &size);
+ if(rc != CURLE_OK) {
+ if(rc != CURLE_READ_ERROR) {
+ const char *errortext = curl_easy_strerror(rc);
+ fprintf(stdout, "\n==> Curl_getFormData error: %s\n", errortext);
+ }
+ return 0;
+ }
+
+ Curl_FormInit(&formread, form);
+
+ do {
+ nread = Curl_FormReader(buffer, 1, sizeof(buffer),
+ (FILE *)&formread);
+
+ if(nread < 1)
+ break;
+ fwrite(buffer, nread, 1, stdout);
+ } while(1);
+
+ fprintf(stdout, "size: %d\n", size);
+ if (errors)
+ fprintf(stdout, "\n==> %d Test(s) failed!\n", errors);
+ else
+ fprintf(stdout, "\nAll Tests seem to have worked (please check output)\n");
+
+ return 0;
+}
+
+#endif /* _FORM_DEBUG */
+
+#else /* CURL_DISABLE_HTTP */
+CURLFORMcode curl_formadd(struct curl_httppost **httppost,
+ struct curl_httppost **last_post,
+ ...)
+{
+ (void)httppost;
+ (void)last_post;
+ return CURL_FORMADD_DISABLED;
+}
+
+int curl_formget(struct curl_httppost *form, void *arg,
+ curl_formget_callback append)
+{
+ (void) form;
+ (void) arg;
+ (void) append;
+ return CURL_FORMADD_DISABLED;
+}
+
+void curl_formfree(struct curl_httppost *form)
+{
+ (void)form;
+ /* does nothing HTTP is disabled */
+}
+
+#endif /* CURL_DISABLE_HTTP */
+
+#if !defined(CURL_DISABLE_HTTP) || defined(USE_SSLEAY)
+
+/*
+ * Curl_FormBoundary() creates a suitable boundary string and returns an
+ * allocated one. This is also used by SSL-code so it must be present even
+ * if HTTP is disabled!
+ */
+char *Curl_FormBoundary(void)
+{
+ char *retstring;
+ static int randomizer; /* this is just so that two boundaries within
+ the same form won't be identical */
+ size_t i;
+
+ static const char table16[]="abcdef0123456789";
+
+ retstring = (char *)malloc(BOUNDARY_LENGTH+1);
+
+ if(!retstring)
+ return NULL; /* failed */
+
+ srand((unsigned int)time(NULL)+randomizer++); /* seed */
+
+ strcpy(retstring, "----------------------------");
+
+ for(i=strlen(retstring); i<BOUNDARY_LENGTH; i++)
+ retstring[i] = table16[rand()%16];
+
+ /* 28 dashes and 12 hexadecimal digits makes 12^16 (184884258895036416)
+ combinations */
+ retstring[BOUNDARY_LENGTH]=0; /* zero terminate */
+
+ return retstring;
+}
+
+#endif /* !defined(CURL_DISABLE_HTTP) || defined(USE_SSLEAY) */
diff --git a/Utilities/cmcurl/formdata.h b/Utilities/cmcurl/formdata.h
new file mode 100644
index 0000000000..4ca0f3c5c9
--- /dev/null
+++ b/Utilities/cmcurl/formdata.h
@@ -0,0 +1,97 @@
+#ifndef __FORMDATA_H
+#define __FORMDATA_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+enum formtype {
+ FORM_DATA, /* form metadata (convert to network encoding if necessary) */
+ FORM_CONTENT, /* form content (never convert) */
+ FORM_FILE /* 'line' points to a file name we should read from
+ to create the form data (never convert) */
+};
+
+/* plain and simple linked list with lines to send */
+struct FormData {
+ struct FormData *next;
+ enum formtype type;
+ char *line;
+ size_t length;
+};
+
+struct Form {
+ struct FormData *data; /* current form line to send */
+ size_t sent; /* number of bytes of the current line that has
+ already been sent in a previous invoke */
+ FILE *fp; /* file to read from */
+};
+
+/* used by FormAdd for temporary storage */
+typedef struct FormInfo {
+ char *name;
+ bool name_alloc;
+ size_t namelength;
+ char *value;
+ bool value_alloc;
+ size_t contentslength;
+ char *contenttype;
+ bool contenttype_alloc;
+ long flags;
+ char *buffer; /* pointer to existing buffer used for file upload */
+ size_t bufferlength;
+ char *showfilename; /* The file name to show. If not set, the actual
+ file name will be used */
+ bool showfilename_alloc;
+ struct curl_slist* contentheader;
+ struct FormInfo *more;
+} FormInfo;
+
+int Curl_FormInit(struct Form *form, struct FormData *formdata );
+
+CURLcode
+Curl_getFormData(struct FormData **,
+ struct curl_httppost *post,
+ const char *custom_contenttype,
+ curl_off_t *size);
+
+/* fread() emulation */
+size_t Curl_FormReader(char *buffer,
+ size_t size,
+ size_t nitems,
+ FILE *mydata);
+
+/*
+ * Curl_formpostheader() returns the first line of the formpost, the
+ * request-header part (which is not part of the request-body like the rest of
+ * the post).
+ */
+char *Curl_formpostheader(void *formp, size_t *len);
+
+char *Curl_FormBoundary(void);
+
+void Curl_formclean(struct FormData **);
+
+CURLcode Curl_formconvert(struct SessionHandle *, struct FormData *);
+
+#endif
+
diff --git a/Utilities/cmcurl/ftp.c b/Utilities/cmcurl/ftp.c
new file mode 100644
index 0000000000..3ccbc43643
--- /dev/null
+++ b/Utilities/cmcurl/ftp.c
@@ -0,0 +1,3865 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_FTP
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef WIN32
+
+#else /* probably some kind of unix */
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <sys/types.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_UTSNAME_H
+#include <sys/utsname.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#endif
+#endif
+
+#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
+#undef in_addr_t
+#define in_addr_t unsigned long
+#endif
+
+#include <curl/curl.h>
+#include "urldata.h"
+#include "sendf.h"
+#include "easyif.h" /* for Curl_convert_... prototypes */
+
+#include "if2ip.h"
+#include "hostip.h"
+#include "progress.h"
+#include "transfer.h"
+#include "escape.h"
+#include "http.h" /* for HTTP proxy tunnel stuff */
+#include "ftp.h"
+
+#ifdef HAVE_KRB4
+#include "krb4.h"
+#endif
+
+#include "strtoofft.h"
+#include "strequal.h"
+#include "sslgen.h"
+#include "connect.h"
+#include "strerror.h"
+#include "memory.h"
+#include "inet_ntop.h"
+#include "select.h"
+#include "parsedate.h" /* for the week day and month names */
+#include "sockaddr.h" /* required for Curl_sockaddr_storage */
+#include "multiif.h"
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#ifdef CURLDEBUG
+#include "memdebug.h"
+#endif
+
+#ifdef HAVE_NI_WITHSCOPEID
+#define NIFLAGS NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID
+#else
+#define NIFLAGS NI_NUMERICHOST | NI_NUMERICSERV
+#endif
+
+/* Local API functions */
+static CURLcode ftp_sendquote(struct connectdata *conn,
+ struct curl_slist *quote);
+static CURLcode ftp_quit(struct connectdata *conn);
+static CURLcode ftp_parse_url_path(struct connectdata *conn);
+static CURLcode ftp_regular_transfer(struct connectdata *conn, bool *done);
+static void ftp_pasv_verbose(struct connectdata *conn,
+ Curl_addrinfo *ai,
+ char *newhost, /* ascii version */
+ int port);
+static CURLcode ftp_state_post_rest(struct connectdata *conn);
+static CURLcode ftp_state_post_cwd(struct connectdata *conn);
+static CURLcode ftp_state_quote(struct connectdata *conn,
+ bool init, ftpstate instate);
+static CURLcode ftp_nb_type(struct connectdata *conn,
+ bool ascii, ftpstate state);
+static int ftp_need_type(struct connectdata *conn,
+ bool ascii);
+
+/* easy-to-use macro: */
+#define FTPSENDF(x,y,z) if ((result = Curl_ftpsendf(x,y,z)) != CURLE_OK) \
+ return result
+#define NBFTPSENDF(x,y,z) if ((result = Curl_nbftpsendf(x,y,z)) != CURLE_OK) \
+ return result
+
+static void freedirs(struct connectdata *conn)
+{
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+
+ int i;
+ if(ftpc->dirs) {
+ for (i=0; i < ftpc->dirdepth; i++){
+ if(ftpc->dirs[i]) {
+ free(ftpc->dirs[i]);
+ ftpc->dirs[i]=NULL;
+ }
+ }
+ free(ftpc->dirs);
+ ftpc->dirs = NULL;
+ }
+ if(ftp->file) {
+ free(ftp->file);
+ ftp->file = NULL;
+ }
+}
+
+/* Returns non-zero if the given string contains CR (\r) or LF (\n),
+ which are not allowed within RFC 959 <string>.
+ Note: The input string is in the client's encoding which might
+ not be ASCII, so escape sequences \r & \n must be used instead
+ of hex values 0x0d & 0x0a.
+*/
+static bool isBadFtpString(const char *string)
+{
+ return (bool)((NULL != strchr(string, '\r')) || (NULL != strchr(string, '\n')));
+}
+
+/***********************************************************************
+ *
+ * AllowServerConnect()
+ *
+ * When we've issue the PORT command, we have told the server to connect
+ * to us. This function will sit and wait here until the server has
+ * connected.
+ *
+ */
+static CURLcode AllowServerConnect(struct connectdata *conn)
+{
+ int timeout_ms;
+ struct SessionHandle *data = conn->data;
+ curl_socket_t sock = conn->sock[SECONDARYSOCKET];
+ struct timeval now = Curl_tvnow();
+ long timespent = Curl_tvdiff(Curl_tvnow(), now)/1000;
+ long timeout = data->set.connecttimeout?data->set.connecttimeout:
+ (data->set.timeout?data->set.timeout: 0);
+
+ if(timeout) {
+ timeout -= timespent;
+ if(timeout<=0) {
+ failf(data, "Timed out before server could connect to us");
+ return CURLE_OPERATION_TIMEDOUT;
+ }
+ }
+
+ /* We allow the server 60 seconds to connect to us, or a custom timeout.
+ Note the typecast here. */
+ timeout_ms = (timeout?(int)timeout:60) * 1000;
+
+ switch (Curl_select(sock, CURL_SOCKET_BAD, timeout_ms)) {
+ case -1: /* error */
+ /* let's die here */
+ failf(data, "Error while waiting for server connect");
+ return CURLE_FTP_PORT_FAILED;
+ case 0: /* timeout */
+ /* let's die here */
+ failf(data, "Timeout while waiting for server connect");
+ return CURLE_FTP_PORT_FAILED;
+ default:
+ /* we have received data here */
+ {
+ curl_socket_t s = CURL_SOCKET_BAD;
+#ifdef ENABLE_IPV6
+ struct Curl_sockaddr_storage add;
+#else
+ struct sockaddr_in add;
+#endif
+ socklen_t size = (socklen_t) sizeof(add);
+
+ if(0 == getsockname(sock, (struct sockaddr *) &add, &size)) {
+ size = sizeof(add);
+
+ s=accept(sock, (struct sockaddr *) &add, &size);
+ }
+ sclose(sock); /* close the first socket */
+
+ if (CURL_SOCKET_BAD == s) {
+ /* DIE! */
+ failf(data, "Error accept()ing server connect");
+ return CURLE_FTP_PORT_FAILED;
+ }
+ infof(data, "Connection accepted from server\n");
+
+ conn->sock[SECONDARYSOCKET] = s;
+ Curl_nonblock(s, TRUE); /* enable non-blocking */
+ }
+ break;
+ }
+
+ return CURLE_OK;
+}
+
+/* initialize stuff to prepare for reading a fresh new response */
+static void ftp_respinit(struct connectdata *conn)
+{
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ ftpc->nread_resp = 0;
+ ftpc->linestart_resp = conn->data->state.buffer;
+}
+
+/* macro to check for the last line in an FTP server response */
+#define lastline(line) (ISDIGIT(line[0]) && ISDIGIT(line[1]) && \
+ ISDIGIT(line[2]) && (' ' == line[3]))
+
+static CURLcode ftp_readresp(curl_socket_t sockfd,
+ struct connectdata *conn,
+ int *ftpcode, /* return the ftp-code if done */
+ size_t *size) /* size of the response */
+{
+ int perline; /* count bytes per line */
+ bool keepon=TRUE;
+ ssize_t gotbytes;
+ char *ptr;
+ struct SessionHandle *data = conn->data;
+ char *buf = data->state.buffer;
+ CURLcode result = CURLE_OK;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ int code = 0;
+
+ if (ftpcode)
+ *ftpcode = 0; /* 0 for errors or not done */
+
+ ptr=buf + ftpc->nread_resp;
+
+ perline= (int)(ptr-ftpc->linestart_resp); /* number of bytes in the current
+ line, so far */
+ keepon=TRUE;
+
+ while((ftpc->nread_resp<BUFSIZE) && (keepon && !result)) {
+
+ if(ftpc->cache) {
+ /* we had data in the "cache", copy that instead of doing an actual
+ * read
+ *
+ * ftp->cache_size is cast to int here. This should be safe,
+ * because it would have been populated with something of size
+ * int to begin with, even though its datatype may be larger
+ * than an int.
+ */
+ memcpy(ptr, ftpc->cache, (int)ftpc->cache_size);
+ gotbytes = (int)ftpc->cache_size;
+ free(ftpc->cache); /* free the cache */
+ ftpc->cache = NULL; /* clear the pointer */
+ ftpc->cache_size = 0; /* zero the size just in case */
+ }
+ else {
+ int res = Curl_read(conn, sockfd, ptr, BUFSIZE-ftpc->nread_resp,
+ &gotbytes);
+ if(res < 0)
+ /* EWOULDBLOCK */
+ return CURLE_OK; /* return */
+
+#ifdef CURL_DOES_CONVERSIONS
+ if((res == CURLE_OK) && (gotbytes > 0)) {
+ /* convert from the network encoding */
+ result = res = Curl_convert_from_network(data, ptr, gotbytes);
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ if(CURLE_OK != res)
+ keepon = FALSE;
+ }
+
+ if(!keepon)
+ ;
+ else if(gotbytes <= 0) {
+ keepon = FALSE;
+ result = CURLE_RECV_ERROR;
+ failf(data, "FTP response reading failed");
+ }
+ else {
+ /* we got a whole chunk of data, which can be anything from one
+ * byte to a set of lines and possible just a piece of the last
+ * line */
+ int i;
+
+ conn->headerbytecount += gotbytes;
+
+ ftpc->nread_resp += gotbytes;
+ for(i = 0; i < gotbytes; ptr++, i++) {
+ perline++;
+ if(*ptr=='\n') {
+ /* a newline is CRLF in ftp-talk, so the CR is ignored as
+ the line isn't really terminated until the LF comes */
+
+ /* output debug output if that is requested */
+ if(data->set.verbose)
+ Curl_debug(data, CURLINFO_HEADER_IN,
+ ftpc->linestart_resp, (size_t)perline, conn);
+
+ /*
+ * We pass all response-lines to the callback function registered
+ * for "headers". The response lines can be seen as a kind of
+ * headers.
+ */
+ result = Curl_client_write(conn, CLIENTWRITE_HEADER,
+ ftpc->linestart_resp, perline);
+ if(result)
+ return result;
+
+ if(perline>3 && lastline(ftpc->linestart_resp)) {
+ /* This is the end of the last line, copy the last line to the
+ start of the buffer and zero terminate, for old times sake (and
+ krb4)! */
+ char *meow;
+ int n;
+ for(meow=ftpc->linestart_resp, n=0; meow<ptr; meow++, n++)
+ buf[n] = *meow;
+ *meow=0; /* zero terminate */
+ keepon=FALSE;
+ ftpc->linestart_resp = ptr+1; /* advance pointer */
+ i++; /* skip this before getting out */
+
+ *size = ftpc->nread_resp; /* size of the response */
+ ftpc->nread_resp = 0; /* restart */
+ break;
+ }
+ perline=0; /* line starts over here */
+ ftpc->linestart_resp = ptr+1;
+ }
+ }
+ if(!keepon && (i != gotbytes)) {
+ /* We found the end of the response lines, but we didn't parse the
+ full chunk of data we have read from the server. We therefore need
+ to store the rest of the data to be checked on the next invoke as
+ it may actually contain another end of response already! */
+ ftpc->cache_size = gotbytes - i;
+ ftpc->cache = (char *)malloc((int)ftpc->cache_size);
+ if(ftpc->cache)
+ memcpy(ftpc->cache, ftpc->linestart_resp, (int)ftpc->cache_size);
+ else
+ return CURLE_OUT_OF_MEMORY; /**BANG**/
+ }
+ } /* there was data */
+
+ } /* while there's buffer left and loop is requested */
+
+ if(!result)
+ code = atoi(buf);
+
+#ifdef HAVE_KRB4
+ /* handle the security-oriented responses 6xx ***/
+ /* FIXME: some errorchecking perhaps... ***/
+ switch(code) {
+ case 631:
+ Curl_sec_read_msg(conn, buf, prot_safe);
+ break;
+ case 632:
+ Curl_sec_read_msg(conn, buf, prot_private);
+ break;
+ case 633:
+ Curl_sec_read_msg(conn, buf, prot_confidential);
+ break;
+ default:
+ /* normal ftp stuff we pass through! */
+ break;
+ }
+#endif
+
+ *ftpcode=code; /* return the initial number like this */
+
+
+ /* store the latest code for later retrieval */
+ conn->data->info.httpcode=code;
+
+ return result;
+}
+
+/* --- parse FTP server responses --- */
+
+/*
+ * Curl_GetFTPResponse() is supposed to be invoked after each command sent to
+ * a remote FTP server. This function will wait and read all lines of the
+ * response and extract the relevant return code for the invoking function.
+ */
+
+CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
+ struct connectdata *conn,
+ int *ftpcode) /* return the ftp-code */
+{
+ /*
+ * We cannot read just one byte per read() and then go back to select() as
+ * the OpenSSL read() doesn't grok that properly.
+ *
+ * Alas, read as much as possible, split up into lines, use the ending
+ * line in a response or continue reading. */
+
+ curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
+ int perline; /* count bytes per line */
+ bool keepon=TRUE;
+ ssize_t gotbytes;
+ char *ptr;
+ long timeout; /* timeout in seconds */
+ int interval_ms;
+ struct SessionHandle *data = conn->data;
+ char *line_start;
+ int code=0; /* default ftp "error code" to return */
+ char *buf = data->state.buffer;
+ CURLcode result = CURLE_OK;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ struct timeval now = Curl_tvnow();
+
+ if (ftpcode)
+ *ftpcode = 0; /* 0 for errors */
+
+ ptr=buf;
+ line_start = buf;
+
+ *nreadp=0;
+ perline=0;
+ keepon=TRUE;
+
+ while((*nreadp<BUFSIZE) && (keepon && !result)) {
+ /* check and reset timeout value every lap */
+ if(data->set.ftp_response_timeout )
+ /* if CURLOPT_FTP_RESPONSE_TIMEOUT is set, use that to determine
+ remaining time. Also, use "now" as opposed to "conn->now"
+ because ftp_response_timeout is only supposed to govern
+ the response for any given ftp response, not for the time
+ from connect to the given ftp response. */
+ timeout = data->set.ftp_response_timeout - /* timeout time */
+ Curl_tvdiff(Curl_tvnow(), now)/1000; /* spent time */
+ else if(data->set.timeout)
+ /* if timeout is requested, find out how much remaining time we have */
+ timeout = data->set.timeout - /* timeout time */
+ Curl_tvdiff(Curl_tvnow(), conn->now)/1000; /* spent time */
+ else
+ /* Even without a requested timeout, we only wait response_time
+ seconds for the full response to arrive before we bail out */
+ timeout = ftpc->response_time -
+ Curl_tvdiff(Curl_tvnow(), now)/1000; /* spent time */
+
+ if(timeout <=0 ) {
+ failf(data, "FTP response timeout");
+ return CURLE_OPERATION_TIMEDOUT; /* already too little time */
+ }
+
+ if(!ftpc->cache) {
+ interval_ms = 1 * 1000; /* use 1 second timeout intervals */
+
+ switch (Curl_select(sockfd, CURL_SOCKET_BAD, interval_ms)) {
+ case -1: /* select() error, stop reading */
+ result = CURLE_RECV_ERROR;
+ failf(data, "FTP response aborted due to select() error: %d",
+ Curl_sockerrno());
+ break;
+ case 0: /* timeout */
+ if(Curl_pgrsUpdate(conn))
+ return CURLE_ABORTED_BY_CALLBACK;
+ continue; /* just continue in our loop for the timeout duration */
+
+ default:
+ break;
+ }
+ }
+ if(CURLE_OK == result) {
+ /*
+ * This code previously didn't use the kerberos sec_read() code
+ * to read, but when we use Curl_read() it may do so. Do confirm
+ * that this is still ok and then remove this comment!
+ */
+ if(ftpc->cache) {
+ /* we had data in the "cache", copy that instead of doing an actual
+ * read
+ *
+ * Dave Meyer, December 2003:
+ * ftp->cache_size is cast to int here. This should be safe,
+ * because it would have been populated with something of size
+ * int to begin with, even though its datatype may be larger
+ * than an int.
+ */
+ memcpy(ptr, ftpc->cache, (int)ftpc->cache_size);
+ gotbytes = (int)ftpc->cache_size;
+ free(ftpc->cache); /* free the cache */
+ ftpc->cache = NULL; /* clear the pointer */
+ ftpc->cache_size = 0; /* zero the size just in case */
+ }
+ else {
+ int res = Curl_read(conn, sockfd, ptr, BUFSIZE-*nreadp, &gotbytes);
+ if(res < 0)
+ /* EWOULDBLOCK */
+ continue; /* go looping again */
+
+#ifdef CURL_DOES_CONVERSIONS
+ if((res == CURLE_OK) && (gotbytes > 0)) {
+ /* convert from the network encoding */
+ result = res = Curl_convert_from_network(data, ptr, gotbytes);
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ if(CURLE_OK != res)
+ keepon = FALSE;
+ }
+
+ if(!keepon)
+ ;
+ else if(gotbytes <= 0) {
+ keepon = FALSE;
+ result = CURLE_RECV_ERROR;
+ failf(data, "FTP response reading failed");
+ }
+ else {
+ /* we got a whole chunk of data, which can be anything from one
+ * byte to a set of lines and possible just a piece of the last
+ * line */
+ int i;
+
+ conn->headerbytecount += gotbytes;
+
+ *nreadp += gotbytes;
+ for(i = 0; i < gotbytes; ptr++, i++) {
+ perline++;
+ if(*ptr=='\n') {
+ /* a newline is CRLF in ftp-talk, so the CR is ignored as
+ the line isn't really terminated until the LF comes */
+
+ /* output debug output if that is requested */
+ if(data->set.verbose)
+ Curl_debug(data, CURLINFO_HEADER_IN,
+ line_start, (size_t)perline, conn);
+
+ /*
+ * We pass all response-lines to the callback function registered
+ * for "headers". The response lines can be seen as a kind of
+ * headers.
+ */
+ result = Curl_client_write(conn, CLIENTWRITE_HEADER,
+ line_start, perline);
+ if(result)
+ return result;
+
+ if(perline>3 && lastline(line_start)) {
+ /* This is the end of the last line, copy the last
+ * line to the start of the buffer and zero terminate,
+ * for old times sake (and krb4)! */
+ char *meow;
+ int n;
+ for(meow=line_start, n=0; meow<ptr; meow++, n++)
+ buf[n] = *meow;
+ *meow=0; /* zero terminate */
+ keepon=FALSE;
+ line_start = ptr+1; /* advance pointer */
+ i++; /* skip this before getting out */
+ break;
+ }
+ perline=0; /* line starts over here */
+ line_start = ptr+1;
+ }
+ }
+ if(!keepon && (i != gotbytes)) {
+ /* We found the end of the response lines, but we didn't parse the
+ full chunk of data we have read from the server. We therefore
+ need to store the rest of the data to be checked on the next
+ invoke as it may actually contain another end of response
+ already! Cleverly figured out by Eric Lavigne in December
+ 2001. */
+ ftpc->cache_size = gotbytes - i;
+ ftpc->cache = (char *)malloc((int)ftpc->cache_size);
+ if(ftpc->cache)
+ memcpy(ftpc->cache, line_start, (int)ftpc->cache_size);
+ else
+ return CURLE_OUT_OF_MEMORY; /**BANG**/
+ }
+ } /* there was data */
+ } /* if(no error) */
+ } /* while there's buffer left and loop is requested */
+
+ if(!result)
+ code = atoi(buf);
+
+#ifdef HAVE_KRB4
+ /* handle the security-oriented responses 6xx ***/
+ /* FIXME: some errorchecking perhaps... ***/
+ switch(code) {
+ case 631:
+ Curl_sec_read_msg(conn, buf, prot_safe);
+ break;
+ case 632:
+ Curl_sec_read_msg(conn, buf, prot_private);
+ break;
+ case 633:
+ Curl_sec_read_msg(conn, buf, prot_confidential);
+ break;
+ default:
+ /* normal ftp stuff we pass through! */
+ break;
+ }
+#endif
+
+ if(ftpcode)
+ *ftpcode=code; /* return the initial number like this */
+
+ /* store the latest code for later retrieval */
+ conn->data->info.httpcode=code;
+
+ return result;
+}
+
+/* This is the ONLY way to change FTP state! */
+static void state(struct connectdata *conn,
+ ftpstate state)
+{
+#ifdef CURLDEBUG
+ /* for debug purposes */
+ const char *names[]={
+ "STOP",
+ "WAIT220",
+ "AUTH",
+ "USER",
+ "PASS",
+ "ACCT",
+ "PBSZ",
+ "PROT",
+ "CCC",
+ "PWD",
+ "QUOTE",
+ "RETR_PREQUOTE",
+ "STOR_PREQUOTE",
+ "POSTQUOTE",
+ "CWD",
+ "MKD",
+ "MDTM",
+ "TYPE",
+ "LIST_TYPE",
+ "RETR_TYPE",
+ "STOR_TYPE",
+ "SIZE",
+ "RETR_SIZE",
+ "STOR_SIZE",
+ "REST",
+ "RETR_REST",
+ "PORT",
+ "PASV",
+ "LIST",
+ "RETR",
+ "STOR",
+ "QUIT"
+ };
+#endif
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+#ifdef CURLDEBUG
+ if(ftpc->state != state)
+ infof(conn->data, "FTP %p state change from %s to %s\n",
+ ftpc, names[ftpc->state], names[state]);
+#endif
+ ftpc->state = state;
+}
+
+static CURLcode ftp_state_user(struct connectdata *conn)
+{
+ CURLcode result;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+ /* send USER */
+ NBFTPSENDF(conn, "USER %s", ftp->user?ftp->user:"");
+
+ state(conn, FTP_USER);
+ conn->data->state.ftp_trying_alternative = FALSE;
+
+ return CURLE_OK;
+}
+
+static CURLcode ftp_state_pwd(struct connectdata *conn)
+{
+ CURLcode result;
+
+ /* send PWD to discover our entry point */
+ NBFTPSENDF(conn, "PWD", NULL);
+ state(conn, FTP_PWD);
+
+ return CURLE_OK;
+}
+
+/* For the FTP "protocol connect" and "doing" phases only */
+int Curl_ftp_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
+{
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+
+ if(!numsocks)
+ return GETSOCK_BLANK;
+
+ socks[0] = conn->sock[FIRSTSOCKET];
+
+ if(ftpc->sendleft) {
+ /* write mode */
+ return GETSOCK_WRITESOCK(0);
+ }
+
+ /* read mode */
+ return GETSOCK_READSOCK(0);
+}
+
+/* This is called after the FTP_QUOTE state is passed.
+
+ ftp_state_cwd() sends the range of PWD commands to the server to change to
+ the correct directory. It may also need to send MKD commands to create
+ missing ones, if that option is enabled.
+*/
+static CURLcode ftp_state_cwd(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+
+ if(ftpc->cwddone)
+ /* already done and fine */
+ result = ftp_state_post_cwd(conn);
+ else {
+ ftpc->count2 = 0;
+ if (conn->bits.reuse && ftpc->entrypath) {
+ /* This is a re-used connection. Since we change directory to where the
+ transfer is taking place, we must first get back to the original dir
+ where we ended up after login: */
+ ftpc->count1 = 0; /* we count this as the first path, then we add one
+ for all upcoming ones in the ftp->dirs[] array */
+ NBFTPSENDF(conn, "CWD %s", ftpc->entrypath);
+ state(conn, FTP_CWD);
+ }
+ else {
+ if(ftpc->dirdepth) {
+ ftpc->count1 = 1;
+ /* issue the first CWD, the rest is sent when the CWD responses are
+ received... */
+ NBFTPSENDF(conn, "CWD %s", ftpc->dirs[ftpc->count1 -1]);
+ state(conn, FTP_CWD);
+ }
+ else {
+ /* No CWD necessary */
+ result = ftp_state_post_cwd(conn);
+ }
+ }
+ }
+ return result;
+}
+
+typedef enum {
+ EPRT,
+ PORT,
+ DONE
+} ftpport;
+
+static CURLcode ftp_state_use_port(struct connectdata *conn,
+ ftpport fcmd) /* start with this */
+
+{
+ CURLcode result = CURLE_OK;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ struct SessionHandle *data=conn->data;
+ curl_socket_t portsock= CURL_SOCKET_BAD;
+ char myhost[256] = "";
+
+#ifdef ENABLE_IPV6
+ /******************************************************************
+ * IPv6-specific section
+ */
+ struct Curl_sockaddr_storage ss;
+ struct addrinfo *res, *ai;
+ socklen_t sslen;
+ char hbuf[NI_MAXHOST];
+ struct sockaddr *sa=(struct sockaddr *)&ss;
+ char tmp[1024];
+ const char *mode[] = { "EPRT", "PORT", NULL };
+ int rc;
+ int error;
+ char *host=NULL;
+ struct Curl_dns_entry *h=NULL;
+ unsigned short port = 0;
+
+ /* Step 1, figure out what address that is requested */
+
+ if(data->set.ftpport && (strlen(data->set.ftpport) > 1)) {
+ /* attempt to get the address of the given interface name */
+ if(!Curl_if2ip(data->set.ftpport, hbuf, sizeof(hbuf)))
+ /* not an interface, use the given string as host name instead */
+ host = data->set.ftpport;
+ else
+ host = hbuf; /* use the hbuf for host name */
+ } /* data->set.ftpport */
+
+ if(!host) {
+ /* not an interface and not a host name, get default by extracting
+ the IP from the control connection */
+
+ sslen = sizeof(ss);
+ if (getsockname(conn->sock[FIRSTSOCKET], (struct sockaddr *)&ss, &sslen)) {
+ failf(data, "getsockname() failed: %s",
+ Curl_strerror(conn, Curl_sockerrno()) );
+ return CURLE_FTP_PORT_FAILED;
+ }
+
+ if (sslen > (socklen_t)sizeof(ss))
+ sslen = sizeof(ss);
+ rc = getnameinfo((struct sockaddr *)&ss, sslen, hbuf, sizeof(hbuf), NULL,
+ 0, NIFLAGS);
+ if(rc) {
+ failf(data, "getnameinfo() returned %d \n", rc);
+ return CURLE_FTP_PORT_FAILED;
+ }
+ host = hbuf; /* use this host name */
+ }
+
+ rc = Curl_resolv(conn, host, 0, &h);
+ if(rc == CURLRESOLV_PENDING)
+ rc = Curl_wait_for_resolv(conn, &h);
+ if(h) {
+ res = h->addr;
+ /* when we return from this function, we can forget about this entry
+ to we can unlock it now already */
+ Curl_resolv_unlock(data, h);
+ } /* (h) */
+ else
+ res = NULL; /* failure! */
+
+
+ /* step 2, create a socket for the requested address */
+
+ portsock = CURL_SOCKET_BAD;
+ error = 0;
+ for (ai = res; ai; ai = ai->ai_next) {
+ /*
+ * Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype):
+ */
+ if (ai->ai_socktype == 0)
+ ai->ai_socktype = conn->socktype;
+
+ portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+ if (portsock == CURL_SOCKET_BAD) {
+ error = Curl_sockerrno();
+ continue;
+ }
+ break;
+ }
+ if(!ai) {
+ failf(data, "socket failure: %s", Curl_strerror(conn, error));
+ return CURLE_FTP_PORT_FAILED;
+ }
+
+ /* step 3, bind to a suitable local address */
+
+ /* Try binding the given address. */
+ if (bind(portsock, ai->ai_addr, ai->ai_addrlen)) {
+
+ /* It failed. Bind the address used for the control connection instead */
+ sslen = sizeof(ss);
+ if (getsockname(conn->sock[FIRSTSOCKET],
+ (struct sockaddr *)sa, &sslen)) {
+ failf(data, "getsockname() failed: %s",
+ Curl_strerror(conn, Curl_sockerrno()) );
+ sclose(portsock);
+ return CURLE_FTP_PORT_FAILED;
+ }
+
+ /* set port number to zero to make bind() pick "any" */
+ if(((struct sockaddr *)sa)->sa_family == AF_INET)
+ ((struct sockaddr_in *)sa)->sin_port=0;
+ else
+ ((struct sockaddr_in6 *)sa)->sin6_port =0;
+
+ if (sslen > (socklen_t)sizeof(ss))
+ sslen = sizeof(ss);
+
+ if(bind(portsock, (struct sockaddr *)sa, sslen)) {
+ failf(data, "bind failed: %s", Curl_strerror(conn, Curl_sockerrno()));
+ sclose(portsock);
+ return CURLE_FTP_PORT_FAILED;
+ }
+ }
+
+ /* get the name again after the bind() so that we can extract the
+ port number it uses now */
+ sslen = sizeof(ss);
+ if(getsockname(portsock, (struct sockaddr *)sa, &sslen)) {
+ failf(data, "getsockname() failed: %s",
+ Curl_strerror(conn, Curl_sockerrno()) );
+ sclose(portsock);
+ return CURLE_FTP_PORT_FAILED;
+ }
+
+ /* step 4, listen on the socket */
+
+ if (listen(portsock, 1)) {
+ failf(data, "socket failure: %s", Curl_strerror(conn, Curl_sockerrno()));
+ sclose(portsock);
+ return CURLE_FTP_PORT_FAILED;
+ }
+
+ /* step 5, send the proper FTP command */
+
+ /* get a plain printable version of the numerical address to work with
+ below */
+ Curl_printable_address(ai, myhost, sizeof(myhost));
+
+#ifdef PF_INET6
+ if(!conn->bits.ftp_use_eprt && conn->bits.ipv6)
+ /* EPRT is disabled but we are connected to a IPv6 host, so we ignore the
+ request and enable EPRT again! */
+ conn->bits.ftp_use_eprt = TRUE;
+#endif
+
+ for (; fcmd != DONE; fcmd++) {
+
+ if(!conn->bits.ftp_use_eprt && (EPRT == fcmd))
+ /* if disabled, goto next */
+ continue;
+
+ switch (sa->sa_family) {
+ case AF_INET:
+ port = ntohs(((struct sockaddr_in *)sa)->sin_port);
+ break;
+ case AF_INET6:
+ port = ntohs(((struct sockaddr_in6 *)sa)->sin6_port);
+ break;
+ default:
+ break;
+ }
+
+ if (EPRT == fcmd) {
+ /*
+ * Two fine examples from RFC2428;
+ *
+ * EPRT |1|132.235.1.2|6275|
+ *
+ * EPRT |2|1080::8:800:200C:417A|5282|
+ */
+
+ result = Curl_nbftpsendf(conn, "%s |%d|%s|%d|", mode[fcmd],
+ ai->ai_family == AF_INET?1:2,
+ myhost, port);
+ if(result)
+ return result;
+ break;
+ }
+ else if (PORT == fcmd) {
+ char *source = myhost;
+ char *dest = tmp;
+
+ if ((PORT == fcmd) && ai->ai_family != AF_INET)
+ continue;
+
+ /* translate x.x.x.x to x,x,x,x */
+ while(source && *source) {
+ if(*source == '.')
+ *dest=',';
+ else
+ *dest = *source;
+ dest++;
+ source++;
+ }
+ *dest = 0;
+ snprintf(dest, 20, ",%d,%d", port>>8, port&0xff);
+
+ result = Curl_nbftpsendf(conn, "%s %s", mode[fcmd], tmp);
+ if(result)
+ return result;
+ break;
+ }
+ }
+
+ /* store which command was sent */
+ ftpc->count1 = fcmd;
+
+ /* we set the secondary socket variable to this for now, it is only so that
+ the cleanup function will close it in case we fail before the true
+ secondary stuff is made */
+ if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET])
+ sclose(conn->sock[SECONDARYSOCKET]);
+ conn->sock[SECONDARYSOCKET] = portsock;
+
+#else
+ /******************************************************************
+ * IPv4-specific section
+ */
+ struct sockaddr_in sa;
+ unsigned short porttouse;
+ bool sa_filled_in = FALSE;
+ Curl_addrinfo *addr = NULL;
+ unsigned short ip[4];
+ bool freeaddr = TRUE;
+ socklen_t sslen = sizeof(sa);
+
+ (void)fcmd; /* not used in the IPv4 code */
+ if(data->set.ftpport) {
+ in_addr_t in;
+
+ /* First check if the given name is an IP address */
+ in=inet_addr(data->set.ftpport);
+
+ if(in != CURL_INADDR_NONE)
+ /* this is an IPv4 address */
+ addr = Curl_ip2addr(in, data->set.ftpport, 0);
+ else {
+ if(Curl_if2ip(data->set.ftpport, myhost, sizeof(myhost))) {
+ /* The interface to IP conversion provided a dotted address */
+ in=inet_addr(myhost);
+ addr = Curl_ip2addr(in, myhost, 0);
+ }
+ else if(strlen(data->set.ftpport)> 1) {
+ /* might be a host name! */
+ struct Curl_dns_entry *h=NULL;
+ int rc = Curl_resolv(conn, data->set.ftpport, 0, &h);
+ if(rc == CURLRESOLV_PENDING)
+ /* BLOCKING */
+ rc = Curl_wait_for_resolv(conn, &h);
+ if(h) {
+ addr = h->addr;
+ /* when we return from this function, we can forget about this entry
+ so we can unlock it now already */
+ Curl_resolv_unlock(data, h);
+
+ freeaddr = FALSE; /* make sure we don't free 'addr' in this function
+ since it points to a DNS cache entry! */
+ } /* (h) */
+ else {
+ infof(data, "Failed to resolve host name %s\n", data->set.ftpport);
+ }
+ } /* strlen */
+ } /* CURL_INADDR_NONE */
+ } /* data->set.ftpport */
+
+ if(!addr) {
+ /* pick a suitable default here */
+
+ if (getsockname(conn->sock[FIRSTSOCKET],
+ (struct sockaddr *)&sa, &sslen)) {
+ failf(data, "getsockname() failed: %s",
+ Curl_strerror(conn, Curl_sockerrno()) );
+ return CURLE_FTP_PORT_FAILED;
+ }
+ if (sslen > (socklen_t)sizeof(sa))
+ sslen = sizeof(sa);
+
+ sa_filled_in = TRUE; /* the sa struct is filled in */
+ }
+
+ if (addr || sa_filled_in) {
+ portsock = socket(AF_INET, SOCK_STREAM, 0);
+ if(CURL_SOCKET_BAD != portsock) {
+
+ /* we set the secondary socket variable to this for now, it
+ is only so that the cleanup function will close it in case
+ we fail before the true secondary stuff is made */
+ if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET])
+ sclose(conn->sock[SECONDARYSOCKET]);
+ conn->sock[SECONDARYSOCKET] = portsock;
+
+ if(!sa_filled_in) {
+ memcpy(&sa, addr->ai_addr, sslen);
+ sa.sin_addr.s_addr = INADDR_ANY;
+ }
+
+ sa.sin_port = 0;
+ sslen = sizeof(sa);
+
+ if(bind(portsock, (struct sockaddr *)&sa, sslen) == 0) {
+ /* we succeeded to bind */
+ struct sockaddr_in add;
+ socklen_t socksize = sizeof(add);
+
+ if(getsockname(portsock, (struct sockaddr *) &add,
+ &socksize)) {
+ failf(data, "getsockname() failed: %s",
+ Curl_strerror(conn, Curl_sockerrno()) );
+ return CURLE_FTP_PORT_FAILED;
+ }
+ porttouse = ntohs(add.sin_port);
+
+ if ( listen(portsock, 1) < 0 ) {
+ failf(data, "listen(2) failed on socket");
+ return CURLE_FTP_PORT_FAILED;
+ }
+ }
+ else {
+ failf(data, "bind(2) failed on socket");
+ return CURLE_FTP_PORT_FAILED;
+ }
+ }
+ else {
+ failf(data, "socket(2) failed (%s)");
+ return CURLE_FTP_PORT_FAILED;
+ }
+ }
+ else {
+ failf(data, "couldn't find IP address to use");
+ return CURLE_FTP_PORT_FAILED;
+ }
+
+ if(sa_filled_in)
+ Curl_inet_ntop(AF_INET, &((struct sockaddr_in *)&sa)->sin_addr,
+ myhost, sizeof(myhost));
+ else
+ Curl_printable_address(addr, myhost, sizeof(myhost));
+
+ if(4 == sscanf(myhost, "%hu.%hu.%hu.%hu",
+ &ip[0], &ip[1], &ip[2], &ip[3])) {
+
+ infof(data, "Telling server to connect to %d.%d.%d.%d:%d\n",
+ ip[0], ip[1], ip[2], ip[3], porttouse);
+
+ result=Curl_nbftpsendf(conn, "PORT %d,%d,%d,%d,%d,%d",
+ ip[0], ip[1], ip[2], ip[3],
+ porttouse >> 8, porttouse & 255);
+ if(result)
+ return result;
+ }
+ else
+ return CURLE_FTP_PORT_FAILED;
+
+ if(freeaddr)
+ Curl_freeaddrinfo(addr);
+
+ ftpc->count1 = PORT;
+
+#endif /* end of ipv4-specific code */
+
+ /* this tcpconnect assignment below is a hackish work-around to make the
+ multi interface with active FTP work - as it will not wait for a
+ (passive) connect in Curl_is_connected().
+
+ The *proper* fix is to make sure that the active connection from the
+ server is done in a non-blocking way. Currently, it is still BLOCKING.
+ */
+ conn->bits.tcpconnect = TRUE;
+
+ state(conn, FTP_PORT);
+ return result;
+}
+
+static CURLcode ftp_state_use_pasv(struct connectdata *conn)
+{
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ CURLcode result = CURLE_OK;
+ /*
+ Here's the excecutive summary on what to do:
+
+ PASV is RFC959, expect:
+ 227 Entering Passive Mode (a1,a2,a3,a4,p1,p2)
+
+ LPSV is RFC1639, expect:
+ 228 Entering Long Passive Mode (4,4,a1,a2,a3,a4,2,p1,p2)
+
+ EPSV is RFC2428, expect:
+ 229 Entering Extended Passive Mode (|||port|)
+
+ */
+
+ const char *mode[] = { "EPSV", "PASV", NULL };
+ int modeoff;
+
+#ifdef PF_INET6
+ if(!conn->bits.ftp_use_epsv && conn->bits.ipv6)
+ /* EPSV is disabled but we are connected to a IPv6 host, so we ignore the
+ request and enable EPSV again! */
+ conn->bits.ftp_use_epsv = TRUE;
+#endif
+
+ modeoff = conn->bits.ftp_use_epsv?0:1;
+
+ result = Curl_nbftpsendf(conn, "%s", mode[modeoff]);
+ if(result)
+ return result;
+
+ ftpc->count1 = modeoff;
+ state(conn, FTP_PASV);
+ infof(conn->data, "Connect data stream passively\n");
+
+ return result;
+}
+
+/* REST is the last command in the chain of commands when a "head"-like
+ request is made. Thus, if an actual transfer is to be made this is where
+ we take off for real. */
+static CURLcode ftp_state_post_rest(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+ struct SessionHandle *data = conn->data;
+
+ if(ftp->no_transfer || conn->bits.no_body) {
+ /* doesn't transfer any data */
+ ftp->no_transfer = TRUE;
+
+ /* still possibly do PRE QUOTE jobs */
+ state(conn, FTP_RETR_PREQUOTE);
+ result = ftp_state_quote(conn, TRUE, FTP_RETR_PREQUOTE);
+ }
+ else if(data->set.ftp_use_port) {
+ /* We have chosen to use the PORT (or similar) command */
+ result = ftp_state_use_port(conn, EPRT);
+ }
+ else {
+ /* We have chosen (this is default) to use the PASV (or similar) command */
+ result = ftp_state_use_pasv(conn);
+ }
+ return result;
+}
+
+static CURLcode ftp_state_post_size(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+
+ if(ftp->no_transfer) {
+ /* if a "head"-like request is being made */
+
+ /* Determine if server can respond to REST command and therefore
+ whether it supports range */
+ NBFTPSENDF(conn, "REST %d", 0);
+
+ state(conn, FTP_REST);
+ }
+ else
+ result = ftp_state_post_rest(conn);
+
+ return result;
+}
+
+static CURLcode ftp_state_post_type(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+
+ if(ftp->no_transfer) {
+ /* if a "head"-like request is being made */
+
+ /* we know ftp->file is a valid pointer to a file name */
+ NBFTPSENDF(conn, "SIZE %s", ftp->file);
+
+ state(conn, FTP_SIZE);
+ }
+ else
+ result = ftp_state_post_size(conn);
+
+ return result;
+}
+
+static CURLcode ftp_state_post_listtype(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+
+ /* If this output is to be machine-parsed, the NLST command might be better
+ to use, since the LIST command output is not specified or standard in any
+ way. It has turned out that the NLST list output is not the same on all
+ servers either... */
+
+ NBFTPSENDF(conn, "%s",
+ data->set.customrequest?data->set.customrequest:
+ (data->set.ftp_list_only?"NLST":"LIST"));
+
+ state(conn, FTP_LIST);
+
+ return result;
+}
+
+static CURLcode ftp_state_post_retrtype(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+
+ /* We've sent the TYPE, now we must send the list of prequote strings */
+
+ result = ftp_state_quote(conn, TRUE, FTP_RETR_PREQUOTE);
+
+ return result;
+}
+
+static CURLcode ftp_state_post_stortype(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+
+ /* We've sent the TYPE, now we must send the list of prequote strings */
+
+ result = ftp_state_quote(conn, TRUE, FTP_STOR_PREQUOTE);
+
+ return result;
+}
+
+static CURLcode ftp_state_post_mdtm(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+ struct SessionHandle *data = conn->data;
+
+ /* If we have selected NOBODY and HEADER, it means that we only want file
+ information. Which in FTP can't be much more than the file size and
+ date. */
+ if(conn->bits.no_body && data->set.include_header && ftp->file &&
+ ftp_need_type(conn, data->set.prefer_ascii)) {
+ /* The SIZE command is _not_ RFC 959 specified, and therefor many servers
+ may not support it! It is however the only way we have to get a file's
+ size! */
+
+ ftp->no_transfer = TRUE; /* this means no actual transfer will be made */
+
+ /* Some servers return different sizes for different modes, and thus we
+ must set the proper type before we check the size */
+ result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_TYPE);
+ if (result)
+ return result;
+ }
+ else
+ result = ftp_state_post_type(conn);
+
+ return result;
+}
+
+/* This is called after the CWD commands have been done in the beginning of
+ the DO phase */
+static CURLcode ftp_state_post_cwd(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+ struct SessionHandle *data = conn->data;
+
+ /* Requested time of file or time-depended transfer? */
+ if((data->set.get_filetime || data->set.timecondition) && ftp->file) {
+
+ /* we have requested to get the modified-time of the file, this is a white
+ spot as the MDTM is not mentioned in RFC959 */
+ NBFTPSENDF(conn, "MDTM %s", ftp->file);
+
+ state(conn, FTP_MDTM);
+ }
+ else
+ result = ftp_state_post_mdtm(conn);
+
+ return result;
+}
+
+
+/* This is called after the TYPE and possible quote commands have been sent */
+static CURLcode ftp_state_ul_setup(struct connectdata *conn,
+ bool sizechecked)
+{
+ CURLcode result = CURLE_OK;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+ struct SessionHandle *data = conn->data;
+ curl_off_t passed=0;
+
+ if((data->reqdata.resume_from && !sizechecked) ||
+ ((data->reqdata.resume_from > 0) && sizechecked)) {
+ /* we're about to continue the uploading of a file */
+ /* 1. get already existing file's size. We use the SIZE command for this
+ which may not exist in the server! The SIZE command is not in
+ RFC959. */
+
+ /* 2. This used to set REST. But since we can do append, we
+ don't another ftp command. We just skip the source file
+ offset and then we APPEND the rest on the file instead */
+
+ /* 3. pass file-size number of bytes in the source file */
+ /* 4. lower the infilesize counter */
+ /* => transfer as usual */
+
+ if(data->reqdata.resume_from < 0 ) {
+ /* Got no given size to start from, figure it out */
+ NBFTPSENDF(conn, "SIZE %s", ftp->file);
+ state(conn, FTP_STOR_SIZE);
+ return result;
+ }
+
+ /* enable append */
+ data->set.ftp_append = TRUE;
+
+ /* Let's read off the proper amount of bytes from the input. If we knew it
+ was a proper file we could've just fseek()ed but we only have a stream
+ here */
+
+ /* TODO: allow the ioctlfunction to provide a fast forward function that
+ can be used here and use this method only as a fallback! */
+ do {
+ curl_off_t readthisamountnow = (data->reqdata.resume_from - passed);
+ curl_off_t actuallyread;
+
+ if(readthisamountnow > BUFSIZE)
+ readthisamountnow = BUFSIZE;
+
+ actuallyread = (curl_off_t)
+ conn->fread(data->state.buffer, 1, (size_t)readthisamountnow,
+ conn->fread_in);
+
+ passed += actuallyread;
+ if(actuallyread != readthisamountnow) {
+ failf(data, "Could only read %" FORMAT_OFF_T
+ " bytes from the input", passed);
+ return CURLE_FTP_COULDNT_USE_REST;
+ }
+ } while(passed != data->reqdata.resume_from);
+
+ /* now, decrease the size of the read */
+ if(data->set.infilesize>0) {
+ data->set.infilesize -= data->reqdata.resume_from;
+
+ if(data->set.infilesize <= 0) {
+ infof(data, "File already completely uploaded\n");
+
+ /* no data to transfer */
+ result=Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+
+ /* Set no_transfer so that we won't get any error in
+ * Curl_ftp_done() because we didn't transfer anything! */
+ ftp->no_transfer = TRUE;
+
+ state(conn, FTP_STOP);
+ return CURLE_OK;
+ }
+ }
+ /* we've passed, proceed as normal */
+ } /* resume_from */
+
+ NBFTPSENDF(conn, data->set.ftp_append?"APPE %s":"STOR %s",
+ ftp->file);
+
+ state(conn, FTP_STOR);
+
+ return result;
+}
+
+static CURLcode ftp_state_quote(struct connectdata *conn,
+ bool init,
+ ftpstate instate)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ struct FTP *ftp = data->reqdata.proto.ftp;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ bool quote=FALSE;
+ struct curl_slist *item;
+
+ switch(instate) {
+ case FTP_QUOTE:
+ default:
+ item = data->set.quote;
+ break;
+ case FTP_RETR_PREQUOTE:
+ case FTP_STOR_PREQUOTE:
+ item = data->set.prequote;
+ break;
+ case FTP_POSTQUOTE:
+ item = data->set.postquote;
+ break;
+ }
+
+ if(init)
+ ftpc->count1 = 0;
+ else
+ ftpc->count1++;
+
+ if(item) {
+ int i = 0;
+
+ /* Skip count1 items in the linked list */
+ while((i< ftpc->count1) && item) {
+ item = item->next;
+ i++;
+ }
+ if(item) {
+ NBFTPSENDF(conn, "%s", item->data);
+ state(conn, instate);
+ quote = TRUE;
+ }
+ }
+
+ if(!quote) {
+ /* No more quote to send, continue to ... */
+ switch(instate) {
+ case FTP_QUOTE:
+ default:
+ result = ftp_state_cwd(conn);
+ break;
+ case FTP_RETR_PREQUOTE:
+ if (ftp->no_transfer)
+ state(conn, FTP_STOP);
+ else {
+ NBFTPSENDF(conn, "SIZE %s", ftp->file);
+ state(conn, FTP_RETR_SIZE);
+ }
+ break;
+ case FTP_STOR_PREQUOTE:
+ result = ftp_state_ul_setup(conn, FALSE);
+ break;
+ case FTP_POSTQUOTE:
+ break;
+ }
+ }
+
+ return result;
+}
+
+static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
+ int ftpcode)
+{
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ CURLcode result;
+ struct SessionHandle *data=conn->data;
+ Curl_addrinfo *conninfo;
+ struct Curl_dns_entry *addr=NULL;
+ int rc;
+ unsigned short connectport; /* the local port connect() should use! */
+ unsigned short newport=0; /* remote port */
+ bool connected;
+
+ /* newhost must be able to hold a full IP-style address in ASCII, which
+ in the IPv6 case means 5*8-1 = 39 letters */
+#define NEWHOST_BUFSIZE 48
+ char newhost[NEWHOST_BUFSIZE];
+ char *str=&data->state.buffer[4]; /* start on the first letter */
+
+ if((ftpc->count1 == 0) &&
+ (ftpcode == 229)) {
+ /* positive EPSV response */
+ char *ptr = strchr(str, '(');
+ if(ptr) {
+ unsigned int num;
+ char separator[4];
+ ptr++;
+ if(5 == sscanf(ptr, "%c%c%c%u%c",
+ &separator[0],
+ &separator[1],
+ &separator[2],
+ &num,
+ &separator[3])) {
+ const char sep1 = separator[0];
+ int i;
+
+ /* The four separators should be identical, or else this is an oddly
+ formatted reply and we bail out immediately. */
+ for(i=1; i<4; i++) {
+ if(separator[i] != sep1) {
+ ptr=NULL; /* set to NULL to signal error */
+ break;
+ }
+ }
+ if(ptr) {
+ newport = num;
+
+ if (conn->bits.tunnel_proxy)
+ /* proxy tunnel -> use other host info because ip_addr_str is the
+ proxy address not the ftp host */
+ snprintf(newhost, sizeof(newhost), "%s", conn->host.name);
+ else
+ /* use the same IP we are already connected to */
+ snprintf(newhost, NEWHOST_BUFSIZE, "%s", conn->ip_addr_str);
+ }
+ }
+ else
+ ptr=NULL;
+ }
+ if(!ptr) {
+ failf(data, "Weirdly formatted EPSV reply");
+ return CURLE_FTP_WEIRD_PASV_REPLY;
+ }
+ }
+ else if((ftpc->count1 == 1) &&
+ (ftpcode == 227)) {
+ /* positive PASV response */
+ int ip[4];
+ int port[2];
+
+ /*
+ * Scan for a sequence of six comma-separated numbers and use them as
+ * IP+port indicators.
+ *
+ * Found reply-strings include:
+ * "227 Entering Passive Mode (127,0,0,1,4,51)"
+ * "227 Data transfer will passively listen to 127,0,0,1,4,51"
+ * "227 Entering passive mode. 127,0,0,1,4,51"
+ */
+ while(*str) {
+ if (6 == sscanf(str, "%d,%d,%d,%d,%d,%d",
+ &ip[0], &ip[1], &ip[2], &ip[3],
+ &port[0], &port[1]))
+ break;
+ str++;
+ }
+
+ if(!*str) {
+ failf(data, "Couldn't interpret the 227-response");
+ return CURLE_FTP_WEIRD_227_FORMAT;
+ }
+
+ /* we got OK from server */
+ if(data->set.ftp_skip_ip) {
+ /* told to ignore the remotely given IP but instead use the one we used
+ for the control connection */
+ infof(data, "Skips %d.%d.%d.%d for data connection, uses %s instead\n",
+ ip[0], ip[1], ip[2], ip[3],
+ conn->ip_addr_str);
+ if (conn->bits.tunnel_proxy)
+ /* proxy tunnel -> use other host info because ip_addr_str is the
+ proxy address not the ftp host */
+ snprintf(newhost, sizeof(newhost), "%s", conn->host.name);
+ else
+ snprintf(newhost, sizeof(newhost), "%s", conn->ip_addr_str);
+ }
+ else
+ snprintf(newhost, sizeof(newhost),
+ "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+ newport = (port[0]<<8) + port[1];
+ }
+ else if(ftpc->count1 == 0) {
+ /* EPSV failed, move on to PASV */
+
+ /* disable it for next transfer */
+ conn->bits.ftp_use_epsv = FALSE;
+ infof(data, "disabling EPSV usage\n");
+
+ NBFTPSENDF(conn, "PASV", NULL);
+ ftpc->count1++;
+ /* remain in the FTP_PASV state */
+ return result;
+ }
+ else {
+ failf(data, "Bad PASV/EPSV response: %03d", ftpcode);
+ return CURLE_FTP_WEIRD_PASV_REPLY;
+ }
+
+ if(data->set.proxy && *data->set.proxy) {
+ /*
+ * This is a tunnel through a http proxy and we need to connect to the
+ * proxy again here.
+ *
+ * We don't want to rely on a former host lookup that might've expired
+ * now, instead we remake the lookup here and now!
+ */
+ rc = Curl_resolv(conn, conn->proxy.name, (int)conn->port, &addr);
+ if(rc == CURLRESOLV_PENDING)
+ /* BLOCKING */
+ rc = Curl_wait_for_resolv(conn, &addr);
+
+ connectport =
+ (unsigned short)conn->port; /* we connect to the proxy's port */
+
+ }
+ else {
+ /* normal, direct, ftp connection */
+ rc = Curl_resolv(conn, newhost, newport, &addr);
+ if(rc == CURLRESOLV_PENDING)
+ /* BLOCKING */
+ rc = Curl_wait_for_resolv(conn, &addr);
+
+ if(!addr) {
+ failf(data, "Can't resolve new host %s:%d", newhost, newport);
+ return CURLE_FTP_CANT_GET_HOST;
+ }
+ connectport = newport; /* we connect to the remote port */
+ }
+
+ result = Curl_connecthost(conn,
+ addr,
+ &conn->sock[SECONDARYSOCKET],
+ &conninfo,
+ &connected);
+
+ Curl_resolv_unlock(data, addr); /* we're done using this address */
+
+ if (result && ftpc->count1 == 0 && ftpcode == 229) {
+ infof(data, "got positive EPSV response, but can't connect. "
+ "Disabling EPSV\n");
+ /* disable it for next transfer */
+ conn->bits.ftp_use_epsv = FALSE;
+ data->state.errorbuf = FALSE; /* allow error message to get rewritten */
+ NBFTPSENDF(conn, "PASV", NULL);
+ ftpc->count1++;
+ /* remain in the FTP_PASV state */
+ return result;
+ }
+
+ if(result)
+ return result;
+
+ conn->bits.tcpconnect = connected; /* simply TRUE or FALSE */
+
+ /*
+ * When this is used from the multi interface, this might've returned with
+ * the 'connected' set to FALSE and thus we are now awaiting a non-blocking
+ * connect to connect and we should not be "hanging" here waiting.
+ */
+
+ if(data->set.verbose)
+ /* this just dumps information about this second connection */
+ ftp_pasv_verbose(conn, conninfo, newhost, connectport);
+
+#ifndef CURL_DISABLE_HTTP
+ if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
+ /* FIX: this MUST wait for a proper connect first if 'connected' is
+ * FALSE */
+
+ /* BLOCKING */
+ /* We want "seamless" FTP operations through HTTP proxy tunnel */
+
+ /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member
+ * conn->proto.http; we want FTP through HTTP and we have to change the
+ * member temporarily for connecting to the HTTP proxy. After
+ * Curl_proxyCONNECT we have to set back the member to the original struct
+ * FTP pointer
+ */
+ struct HTTP http_proxy;
+ struct FTP *ftp_save = data->reqdata.proto.ftp;
+ memset(&http_proxy, 0, sizeof(http_proxy));
+ data->reqdata.proto.http = &http_proxy;
+
+ result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, newhost, newport);
+
+ data->reqdata.proto.ftp = ftp_save;
+
+ if(CURLE_OK != result)
+ return result;
+ }
+#endif /* CURL_DISABLE_HTTP */
+
+ state(conn, FTP_STOP); /* this phase is completed */
+
+ return result;
+}
+
+static CURLcode ftp_state_port_resp(struct connectdata *conn,
+ int ftpcode)
+{
+ struct SessionHandle *data = conn->data;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ ftpport fcmd = (ftpport)ftpc->count1;
+ CURLcode result = CURLE_OK;
+
+ if(ftpcode != 200) {
+ /* the command failed */
+
+ if (EPRT == fcmd) {
+ infof(data, "disabling EPRT usage\n");
+ conn->bits.ftp_use_eprt = FALSE;
+ }
+ fcmd++;
+
+ if(fcmd == DONE) {
+ failf(data, "Failed to do PORT");
+ result = CURLE_FTP_PORT_FAILED;
+ }
+ else
+ /* try next */
+ result = ftp_state_use_port(conn, fcmd);
+ }
+ else {
+ infof(data, "Connect data stream actively\n");
+ state(conn, FTP_STOP); /* end of DO phase */
+ }
+
+ return result;
+}
+
+static CURLcode ftp_state_mdtm_resp(struct connectdata *conn,
+ int ftpcode)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data=conn->data;
+ struct FTP *ftp = data->reqdata.proto.ftp;
+
+ switch(ftpcode) {
+ case 213:
+ {
+ /* we got a time. Format should be: "YYYYMMDDHHMMSS[.sss]" where the
+ last .sss part is optional and means fractions of a second */
+ int year, month, day, hour, minute, second;
+ char *buf = data->state.buffer;
+ if(6 == sscanf(buf+4, "%04d%02d%02d%02d%02d%02d",
+ &year, &month, &day, &hour, &minute, &second)) {
+ /* we have a time, reformat it */
+ time_t secs=time(NULL);
+ /* using the good old yacc/bison yuck */
+ snprintf(buf, sizeof(conn->data->state.buffer),
+ "%04d%02d%02d %02d:%02d:%02d GMT",
+ year, month, day, hour, minute, second);
+ /* now, convert this into a time() value: */
+ data->info.filetime = (long)curl_getdate(buf, &secs);
+ }
+
+ /* If we asked for a time of the file and we actually got one as well,
+ we "emulate" a HTTP-style header in our output. */
+
+ if(conn->bits.no_body &&
+ data->set.include_header &&
+ ftp->file &&
+ data->set.get_filetime &&
+ (data->info.filetime>=0) ) {
+ struct tm *tm;
+ time_t clock = (time_t)data->info.filetime;
+#ifdef HAVE_GMTIME_R
+ struct tm buffer;
+ tm = (struct tm *)gmtime_r(&clock, &buffer);
+#else
+ tm = gmtime(&clock);
+#endif
+ /* format: "Tue, 15 Nov 1994 12:45:26" */
+ snprintf(buf, BUFSIZE-1,
+ "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
+ Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
+ tm->tm_mday,
+ Curl_month[tm->tm_mon],
+ tm->tm_year + 1900,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec);
+ result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
+ if(result)
+ return result;
+ } /* end of a ridiculous amount of conditionals */
+ }
+ break;
+ default:
+ infof(data, "unsupported MDTM reply format\n");
+ break;
+ case 550: /* "No such file or directory" */
+ failf(data, "Given file does not exist");
+ result = CURLE_FTP_COULDNT_RETR_FILE;
+ break;
+ }
+
+ if(data->set.timecondition) {
+ if((data->info.filetime > 0) && (data->set.timevalue > 0)) {
+ switch(data->set.timecondition) {
+ case CURL_TIMECOND_IFMODSINCE:
+ default:
+ if(data->info.filetime <= data->set.timevalue) {
+ infof(data, "The requested document is not new enough\n");
+ ftp->no_transfer = TRUE; /* mark this to not transfer data */
+ state(conn, FTP_STOP);
+ return CURLE_OK;
+ }
+ break;
+ case CURL_TIMECOND_IFUNMODSINCE:
+ if(data->info.filetime > data->set.timevalue) {
+ infof(data, "The requested document is not old enough\n");
+ ftp->no_transfer = TRUE; /* mark this to not transfer data */
+ state(conn, FTP_STOP);
+ return CURLE_OK;
+ }
+ break;
+ } /* switch */
+ }
+ else {
+ infof(data, "Skipping time comparison\n");
+ }
+ }
+
+ if(!result)
+ result = ftp_state_post_mdtm(conn);
+
+ return result;
+}
+
+static CURLcode ftp_state_type_resp(struct connectdata *conn,
+ int ftpcode,
+ ftpstate instate)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data=conn->data;
+
+ if(ftpcode/100 != 2) {
+ /* "sasserftpd" and "(u)r(x)bot ftpd" both responds with 226 after a
+ successful 'TYPE I'. While that is not as RFC959 says, it is still a
+ positive response code and we allow that. */
+ failf(data, "Couldn't set desired mode");
+ return CURLE_FTP_COULDNT_SET_BINARY; /* FIX */
+ }
+ if(ftpcode != 200)
+ infof(data, "Got a %03d response code instead of the assumed 200\n",
+ ftpcode);
+
+ if(instate == FTP_TYPE)
+ result = ftp_state_post_type(conn);
+ else if(instate == FTP_LIST_TYPE)
+ result = ftp_state_post_listtype(conn);
+ else if(instate == FTP_RETR_TYPE)
+ result = ftp_state_post_retrtype(conn);
+ else if(instate == FTP_STOR_TYPE)
+ result = ftp_state_post_stortype(conn);
+
+ return result;
+}
+
+static CURLcode ftp_state_post_retr_size(struct connectdata *conn,
+ curl_off_t filesize)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data=conn->data;
+ struct FTP *ftp = data->reqdata.proto.ftp;
+
+ if (data->set.max_filesize && (filesize > data->set.max_filesize)) {
+ failf(data, "Maximum file size exceeded");
+ return CURLE_FILESIZE_EXCEEDED;
+ }
+ ftp->downloadsize = filesize;
+
+ if(data->reqdata.resume_from) {
+ /* We always (attempt to) get the size of downloads, so it is done before
+ this even when not doing resumes. */
+ if(filesize == -1) {
+ infof(data, "ftp server doesn't support SIZE\n");
+ /* We couldn't get the size and therefore we can't know if there really
+ is a part of the file left to get, although the server will just
+ close the connection when we start the connection so it won't cause
+ us any harm, just not make us exit as nicely. */
+ }
+ else {
+ /* We got a file size report, so we check that there actually is a
+ part of the file left to get, or else we go home. */
+ if(data->reqdata.resume_from< 0) {
+ /* We're supposed to download the last abs(from) bytes */
+ if(filesize < -data->reqdata.resume_from) {
+ failf(data, "Offset (%" FORMAT_OFF_T
+ ") was beyond file size (%" FORMAT_OFF_T ")",
+ data->reqdata.resume_from, filesize);
+ return CURLE_BAD_DOWNLOAD_RESUME;
+ }
+ /* convert to size to download */
+ ftp->downloadsize = -data->reqdata.resume_from;
+ /* download from where? */
+ data->reqdata.resume_from = filesize - ftp->downloadsize;
+ }
+ else {
+ if(filesize < data->reqdata.resume_from) {
+ failf(data, "Offset (%" FORMAT_OFF_T
+ ") was beyond file size (%" FORMAT_OFF_T ")",
+ data->reqdata.resume_from, filesize);
+ return CURLE_BAD_DOWNLOAD_RESUME;
+ }
+ /* Now store the number of bytes we are expected to download */
+ ftp->downloadsize = filesize-data->reqdata.resume_from;
+ }
+ }
+
+ if(ftp->downloadsize == 0) {
+ /* no data to transfer */
+ result = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ infof(data, "File already completely downloaded\n");
+
+ /* Set no_transfer so that we won't get any error in Curl_ftp_done()
+ * because we didn't transfer the any file */
+ ftp->no_transfer = TRUE;
+ state(conn, FTP_STOP);
+ return CURLE_OK;
+ }
+
+ /* Set resume file transfer offset */
+ infof(data, "Instructs server to resume from offset %" FORMAT_OFF_T
+ "\n", data->reqdata.resume_from);
+
+ NBFTPSENDF(conn, "REST %" FORMAT_OFF_T, data->reqdata.resume_from);
+
+ state(conn, FTP_RETR_REST);
+
+ }
+ else {
+ /* no resume */
+ NBFTPSENDF(conn, "RETR %s", ftp->file);
+ state(conn, FTP_RETR);
+ }
+
+ return result;
+}
+
+static CURLcode ftp_state_size_resp(struct connectdata *conn,
+ int ftpcode,
+ ftpstate instate)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data=conn->data;
+ curl_off_t filesize;
+ char *buf = data->state.buffer;
+
+ /* get the size from the ascii string: */
+ filesize = (ftpcode == 213)?curlx_strtoofft(buf+4, NULL, 0):-1;
+
+ if(instate == FTP_SIZE) {
+ if(-1 != filesize) {
+ snprintf(buf, sizeof(data->state.buffer),
+ "Content-Length: %" FORMAT_OFF_T "\r\n", filesize);
+ result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
+ if(result)
+ return result;
+ }
+ result = ftp_state_post_size(conn);
+ }
+ else if(instate == FTP_RETR_SIZE)
+ result = ftp_state_post_retr_size(conn, filesize);
+ else if(instate == FTP_STOR_SIZE) {
+ data->reqdata.resume_from = filesize;
+ result = ftp_state_ul_setup(conn, TRUE);
+ }
+
+ return result;
+}
+
+static CURLcode ftp_state_rest_resp(struct connectdata *conn,
+ int ftpcode,
+ ftpstate instate)
+{
+ CURLcode result = CURLE_OK;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+
+ switch(instate) {
+ case FTP_REST:
+ default:
+ if (ftpcode == 350) {
+ result = Curl_client_write(conn, CLIENTWRITE_BOTH,
+ (char *)"Accept-ranges: bytes\r\n", 0);
+ if(result)
+ return result;
+ }
+
+ result = ftp_state_post_rest(conn);
+ break;
+
+ case FTP_RETR_REST:
+ if (ftpcode != 350) {
+ failf(conn->data, "Couldn't use REST");
+ result = CURLE_FTP_COULDNT_USE_REST;
+ }
+ else {
+ NBFTPSENDF(conn, "RETR %s", ftp->file);
+ state(conn, FTP_RETR);
+ }
+ break;
+ }
+
+ return result;
+}
+
+static CURLcode ftp_state_stor_resp(struct connectdata *conn,
+ int ftpcode)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ struct FTP *ftp = data->reqdata.proto.ftp;
+
+ if(ftpcode>=400) {
+ failf(data, "Failed FTP upload: %0d", ftpcode);
+ /* oops, we never close the sockets! */
+ return CURLE_FTP_COULDNT_STOR_FILE;
+ }
+
+ if(data->set.ftp_use_port) {
+ /* BLOCKING */
+ /* PORT means we are now awaiting the server to connect to us. */
+ result = AllowServerConnect(conn);
+ if( result )
+ return result;
+ }
+
+ if(conn->ssl[SECONDARYSOCKET].use) {
+ /* since we only have a plaintext TCP connection here, we must now
+ do the TLS stuff */
+ infof(data, "Doing the SSL/TLS handshake on the data stream\n");
+ /* BLOCKING */
+ result = Curl_ssl_connect(conn, SECONDARYSOCKET);
+ if(result)
+ return result;
+ }
+
+ *(ftp->bytecountp)=0;
+
+ /* When we know we're uploading a specified file, we can get the file
+ size prior to the actual upload. */
+
+ Curl_pgrsSetUploadSize(data, data->set.infilesize);
+
+ result = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, /* no download */
+ SECONDARYSOCKET, ftp->bytecountp);
+ state(conn, FTP_STOP);
+
+ return result;
+}
+
+/* for LIST and RETR responses */
+static CURLcode ftp_state_get_resp(struct connectdata *conn,
+ int ftpcode,
+ ftpstate instate)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ struct FTP *ftp = data->reqdata.proto.ftp;
+ char *buf = data->state.buffer;
+
+ if((ftpcode == 150) || (ftpcode == 125)) {
+
+ /*
+ A;
+ 150 Opening BINARY mode data connection for /etc/passwd (2241
+ bytes). (ok, the file is being transfered)
+
+ B:
+ 150 Opening ASCII mode data connection for /bin/ls
+
+ C:
+ 150 ASCII data connection for /bin/ls (137.167.104.91,37445) (0 bytes).
+
+ D:
+ 150 Opening ASCII mode data connection for /linux/fisk/kpanelrc (0.0.0.0,0) (545 bytes).
+
+ E:
+ 125 Data connection already open; Transfer starting. */
+
+ curl_off_t size=-1; /* default unknown size */
+
+
+ /*
+ * It appears that there are FTP-servers that return size 0 for files when
+ * SIZE is used on the file while being in BINARY mode. To work around
+ * that (stupid) behavior, we attempt to parse the RETR response even if
+ * the SIZE returned size zero.
+ *
+ * Debugging help from Salvatore Sorrentino on February 26, 2003.
+ */
+
+ if((instate != FTP_LIST) &&
+ !data->set.prefer_ascii &&
+ (ftp->downloadsize < 1)) {
+ /*
+ * It seems directory listings either don't show the size or very
+ * often uses size 0 anyway. ASCII transfers may very well turn out
+ * that the transfered amount of data is not the same as this line
+ * tells, why using this number in those cases only confuses us.
+ *
+ * Example D above makes this parsing a little tricky */
+ char *bytes;
+ bytes=strstr(buf, " bytes");
+ if(bytes--) {
+ long in=(long)(bytes-buf);
+ /* this is a hint there is size information in there! ;-) */
+ while(--in) {
+ /* scan for the left parenthesis and break there */
+ if('(' == *bytes)
+ break;
+ /* skip only digits */
+ if(!ISDIGIT(*bytes)) {
+ bytes=NULL;
+ break;
+ }
+ /* one more estep backwards */
+ bytes--;
+ }
+ /* if we have nothing but digits: */
+ if(bytes++) {
+ /* get the number! */
+ size = curlx_strtoofft(bytes, NULL, 0);
+ }
+ }
+ }
+ else if(ftp->downloadsize > -1)
+ size = ftp->downloadsize;
+
+ if(data->set.ftp_use_port) {
+ /* BLOCKING */
+ result = AllowServerConnect(conn);
+ if( result )
+ return result;
+ }
+
+ if(conn->ssl[SECONDARYSOCKET].use) {
+ /* since we only have a plaintext TCP connection here, we must now
+ do the TLS stuff */
+ infof(data, "Doing the SSL/TLS handshake on the data stream\n");
+ result = Curl_ssl_connect(conn, SECONDARYSOCKET);
+ if(result)
+ return result;
+ }
+
+ if(size > data->reqdata.maxdownload && data->reqdata.maxdownload > 0)
+ size = data->reqdata.size = data->reqdata.maxdownload;
+
+ infof(data, "Maxdownload = %" FORMAT_OFF_T "\n", data->reqdata.maxdownload);
+
+ if(instate != FTP_LIST)
+ infof(data, "Getting file with size: %" FORMAT_OFF_T "\n", size);
+
+ /* FTP download: */
+ result=Curl_setup_transfer(conn, SECONDARYSOCKET, size, FALSE,
+ ftp->bytecountp,
+ -1, NULL); /* no upload here */
+ if(result)
+ return result;
+
+ state(conn, FTP_STOP);
+ }
+ else {
+ if((instate == FTP_LIST) && (ftpcode == 450)) {
+ /* simply no matching files in the dir listing */
+ ftp->no_transfer = TRUE; /* don't download anything */
+ state(conn, FTP_STOP); /* this phase is over */
+ }
+ else {
+ failf(data, "RETR response: %03d", ftpcode);
+ return CURLE_FTP_COULDNT_RETR_FILE;
+ }
+ }
+
+ return result;
+}
+
+/* after USER, PASS and ACCT */
+static CURLcode ftp_state_loggedin(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+
+#ifdef HAVE_KRB4
+ if(conn->data->set.krb4) {
+ /* We are logged in, asked to use Kerberos. Set the requested
+ * protection level
+ */
+ if(conn->sec_complete)
+ /* BLOCKING */
+ Curl_sec_set_protection_level(conn);
+
+ /* We may need to issue a KAUTH here to have access to the files
+ * do it if user supplied a password
+ */
+ if(conn->passwd && *conn->passwd) {
+ /* BLOCKING */
+ result = Curl_krb_kauth(conn);
+ if(result)
+ return result;
+ }
+ }
+#endif
+ if(conn->ssl[FIRSTSOCKET].use) {
+ /* PBSZ = PROTECTION BUFFER SIZE.
+
+ The 'draft-murray-auth-ftp-ssl' (draft 12, page 7) says:
+
+ Specifically, the PROT command MUST be preceded by a PBSZ
+ command and a PBSZ command MUST be preceded by a successful
+ security data exchange (the TLS negotiation in this case)
+
+ ... (and on page 8):
+
+ Thus the PBSZ command must still be issued, but must have a
+ parameter of '0' to indicate that no buffering is taking place
+ and the data connection should not be encapsulated.
+ */
+ NBFTPSENDF(conn, "PBSZ %d", 0);
+ state(conn, FTP_PBSZ);
+ }
+ else {
+ result = ftp_state_pwd(conn);
+ }
+ return result;
+}
+
+/* for USER and PASS responses */
+static CURLcode ftp_state_user_resp(struct connectdata *conn,
+ int ftpcode,
+ ftpstate instate)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ struct FTP *ftp = data->reqdata.proto.ftp;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ (void)instate; /* no use for this yet */
+
+ if((ftpcode == 331) && (ftpc->state == FTP_USER)) {
+ /* 331 Password required for ...
+ (the server requires to send the user's password too) */
+ NBFTPSENDF(conn, "PASS %s", ftp->passwd?ftp->passwd:"");
+ state(conn, FTP_PASS);
+ }
+ else if(ftpcode/100 == 2) {
+ /* 230 User ... logged in.
+ (the user logged in with or without password) */
+ result = ftp_state_loggedin(conn);
+ }
+ else if(ftpcode == 332) {
+ if(data->set.ftp_account) {
+ NBFTPSENDF(conn, "ACCT %s", data->set.ftp_account);
+ state(conn, FTP_ACCT);
+ }
+ else {
+ failf(data, "ACCT requested but none available");
+ result = CURLE_LOGIN_DENIED;
+ }
+ }
+ else {
+ /* All other response codes, like:
+
+ 530 User ... access denied
+ (the server denies to log the specified user) */
+
+ if (conn->data->set.ftp_alternative_to_user &&
+ !conn->data->state.ftp_trying_alternative) {
+ /* Ok, USER failed. Let's try the supplied command. */
+ NBFTPSENDF(conn, "%s", conn->data->set.ftp_alternative_to_user);
+ conn->data->state.ftp_trying_alternative = TRUE;
+ state(conn, FTP_USER);
+ result = CURLE_OK;
+ }
+ else {
+ failf(data, "Access denied: %03d", ftpcode);
+ result = CURLE_LOGIN_DENIED;
+ }
+ }
+ return result;
+}
+
+/* for ACCT response */
+static CURLcode ftp_state_acct_resp(struct connectdata *conn,
+ int ftpcode)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ if(ftpcode != 230) {
+ failf(data, "ACCT rejected by server: %03d", ftpcode);
+ result = CURLE_FTP_WEIRD_PASS_REPLY; /* FIX */
+ }
+ else
+ result = ftp_state_loggedin(conn);
+
+ return result;
+}
+
+
+static CURLcode ftp_statemach_act(struct connectdata *conn)
+{
+ CURLcode result;
+ curl_socket_t sock = conn->sock[FIRSTSOCKET];
+ struct SessionHandle *data=conn->data;
+ int ftpcode;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ static const char * const ftpauth[] = {
+ "SSL", "TLS"
+ };
+ size_t nread = 0;
+
+ if(ftpc->sendleft) {
+ /* we have a piece of a command still left to send */
+ ssize_t written;
+ result = Curl_write(conn, sock, ftpc->sendthis + ftpc->sendsize -
+ ftpc->sendleft, ftpc->sendleft, &written);
+ if(result)
+ return result;
+
+ if(written != (ssize_t)ftpc->sendleft) {
+ /* only a fraction was sent */
+ ftpc->sendleft -= written;
+ }
+ else {
+ free(ftpc->sendthis);
+ ftpc->sendthis=NULL;
+ ftpc->sendleft = ftpc->sendsize = 0;
+ ftpc->response = Curl_tvnow();
+ }
+ return CURLE_OK;
+ }
+
+ /* we read a piece of response */
+ result = ftp_readresp(sock, conn, &ftpcode, &nread);
+ if(result)
+ return result;
+
+ if(ftpcode) {
+ /* we have now received a full FTP server response */
+ switch(ftpc->state) {
+ case FTP_WAIT220:
+ if(ftpcode != 220) {
+ failf(data, "This doesn't seem like a nice ftp-server response");
+ return CURLE_FTP_WEIRD_SERVER_REPLY;
+ }
+
+ /* We have received a 220 response fine, now we proceed. */
+#ifdef HAVE_KRB4
+ if(data->set.krb4) {
+ /* If not anonymous login, try a secure login. Note that this
+ procedure is still BLOCKING. */
+
+ Curl_sec_request_prot(conn, "private");
+ /* We set private first as default, in case the line below fails to
+ set a valid level */
+ Curl_sec_request_prot(conn, data->set.krb4_level);
+
+ if(Curl_sec_login(conn) != 0)
+ infof(data, "Logging in with password in cleartext!\n");
+ else
+ infof(data, "Authentication successful\n");
+ }
+#endif
+
+ if(data->set.ftp_ssl && !conn->ssl[FIRSTSOCKET].use) {
+ /* We don't have a SSL/TLS connection yet, but FTPS is
+ requested. Try a FTPS connection now */
+
+ ftpc->count3=0;
+ switch(data->set.ftpsslauth) {
+ case CURLFTPAUTH_DEFAULT:
+ case CURLFTPAUTH_SSL:
+ ftpc->count2 = 1; /* add one to get next */
+ ftpc->count1 = 0;
+ break;
+ case CURLFTPAUTH_TLS:
+ ftpc->count2 = -1; /* subtract one to get next */
+ ftpc->count1 = 1;
+ break;
+ default:
+ failf(data, "unsupported parameter to CURLOPT_FTPSSLAUTH: %d\n",
+ data->set.ftpsslauth);
+ return CURLE_FAILED_INIT; /* we don't know what to do */
+ }
+ NBFTPSENDF(conn, "AUTH %s", ftpauth[ftpc->count1]);
+ state(conn, FTP_AUTH);
+ }
+ else {
+ result = ftp_state_user(conn);
+ if(result)
+ return result;
+ }
+
+ break;
+
+ case FTP_AUTH:
+ /* we have gotten the response to a previous AUTH command */
+
+ /* RFC2228 (page 5) says:
+ *
+ * If the server is willing to accept the named security mechanism,
+ * and does not require any security data, it must respond with
+ * reply code 234/334.
+ */
+
+ if((ftpcode == 234) || (ftpcode == 334)) {
+ /* Curl_ssl_connect is BLOCKING */
+ result = Curl_ssl_connect(conn, FIRSTSOCKET);
+ if(CURLE_OK == result) {
+ conn->protocol |= PROT_FTPS;
+ conn->ssl[SECONDARYSOCKET].use = FALSE; /* clear-text data */
+ result = ftp_state_user(conn);
+ }
+ }
+ else if(ftpc->count3 < 1) {
+ ftpc->count3++;
+ ftpc->count1 += ftpc->count2; /* get next attempt */
+ result = Curl_nbftpsendf(conn, "AUTH %s", ftpauth[ftpc->count1]);
+ /* remain in this same state */
+ }
+ else {
+ if(data->set.ftp_ssl > CURLFTPSSL_TRY)
+ /* we failed and CURLFTPSSL_CONTROL or CURLFTPSSL_ALL is set */
+ result = CURLE_FTP_SSL_FAILED;
+ else
+ /* ignore the failure and continue */
+ result = ftp_state_user(conn);
+ }
+
+ if(result)
+ return result;
+ break;
+
+ case FTP_USER:
+ case FTP_PASS:
+ result = ftp_state_user_resp(conn, ftpcode, ftpc->state);
+ break;
+
+ case FTP_ACCT:
+ result = ftp_state_acct_resp(conn, ftpcode);
+ break;
+
+ case FTP_PBSZ:
+ /* FIX: check response code */
+
+ /* For TLS, the data connection can have one of two security levels.
+
+ 1) Clear (requested by 'PROT C')
+
+ 2)Private (requested by 'PROT P')
+ */
+ if(!conn->ssl[SECONDARYSOCKET].use) {
+ NBFTPSENDF(conn, "PROT %c",
+ data->set.ftp_ssl == CURLFTPSSL_CONTROL ? 'C' : 'P');
+ state(conn, FTP_PROT);
+ }
+ else {
+ result = ftp_state_pwd(conn);
+ if(result)
+ return result;
+ }
+
+ break;
+
+ case FTP_PROT:
+ if(ftpcode/100 == 2)
+ /* We have enabled SSL for the data connection! */
+ conn->ssl[SECONDARYSOCKET].use =
+ (bool)(data->set.ftp_ssl != CURLFTPSSL_CONTROL);
+ /* FTP servers typically responds with 500 if they decide to reject
+ our 'P' request */
+ else if(data->set.ftp_ssl> CURLFTPSSL_CONTROL)
+ /* we failed and bails out */
+ return CURLE_FTP_SSL_FAILED;
+
+ if(data->set.ftp_use_ccc) {
+ /* CCC - Clear Command Channel
+ */
+ NBFTPSENDF(conn, "CCC", NULL);
+ state(conn, FTP_CCC);
+ }
+ else {
+ result = ftp_state_pwd(conn);
+ if(result)
+ return result;
+ }
+ break;
+
+ case FTP_CCC:
+ if (ftpcode < 500) {
+ /* First shut down the SSL layer (note: this call will block) */
+ result = Curl_ssl_shutdown(conn, FIRSTSOCKET);
+
+ if(result) {
+ failf(conn->data, "Failed to clear the command channel (CCC)");
+ return result;
+ }
+ }
+
+ /* Then continue as normal */
+ result = ftp_state_pwd(conn);
+ if(result)
+ return result;
+ break;
+
+ case FTP_PWD:
+ if(ftpcode == 257) {
+ char *dir = (char *)malloc(nread+1);
+ char *store=dir;
+ char *ptr=&data->state.buffer[4]; /* start on the first letter */
+
+ if(!dir)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* Reply format is like
+ 257<space>"<directory-name>"<space><commentary> and the RFC959
+ says
+
+ The directory name can contain any character; embedded
+ double-quotes should be escaped by double-quotes (the
+ "quote-doubling" convention).
+ */
+ if('\"' == *ptr) {
+ /* it started good */
+ ptr++;
+ while(ptr && *ptr) {
+ if('\"' == *ptr) {
+ if('\"' == ptr[1]) {
+ /* "quote-doubling" */
+ *store = ptr[1];
+ ptr++;
+ }
+ else {
+ /* end of path */
+ *store = '\0'; /* zero terminate */
+ break; /* get out of this loop */
+ }
+ }
+ else
+ *store = *ptr;
+ store++;
+ ptr++;
+ }
+ ftpc->entrypath =dir; /* remember this */
+ infof(data, "Entry path is '%s'\n", ftpc->entrypath);
+ /* also save it where getinfo can access it: */
+ data->state.most_recent_ftp_entrypath = ftpc->entrypath;
+ }
+ else {
+ /* couldn't get the path */
+ free(dir);
+ infof(data, "Failed to figure out path\n");
+ }
+ }
+ state(conn, FTP_STOP); /* we are done with the CONNECT phase! */
+ DEBUGF(infof(data, "protocol connect phase DONE\n"));
+ break;
+
+ case FTP_QUOTE:
+ case FTP_POSTQUOTE:
+ case FTP_RETR_PREQUOTE:
+ case FTP_STOR_PREQUOTE:
+ if(ftpcode >= 400) {
+ failf(conn->data, "QUOT command failed with %03d", ftpcode);
+ return CURLE_FTP_QUOTE_ERROR;
+ }
+ result = ftp_state_quote(conn, FALSE, ftpc->state);
+ if(result)
+ return result;
+
+ break;
+
+ case FTP_CWD:
+ if(ftpcode/100 != 2) {
+ /* failure to CWD there */
+ if(conn->data->set.ftp_create_missing_dirs &&
+ ftpc->count1 && !ftpc->count2) {
+ /* try making it */
+ ftpc->count2++; /* counter to prevent CWD-MKD loops */
+ NBFTPSENDF(conn, "MKD %s", ftpc->dirs[ftpc->count1 - 1]);
+ state(conn, FTP_MKD);
+ }
+ else {
+ /* return failure */
+ failf(data, "Server denied you to change to the given directory");
+ ftpc->cwdfail = TRUE; /* don't remember this path as we failed
+ to enter it */
+ return CURLE_FTP_ACCESS_DENIED;
+ }
+ }
+ else {
+ /* success */
+ ftpc->count2=0;
+ if(++ftpc->count1 <= ftpc->dirdepth) {
+ /* send next CWD */
+ NBFTPSENDF(conn, "CWD %s", ftpc->dirs[ftpc->count1 - 1]);
+ }
+ else {
+ result = ftp_state_post_cwd(conn);
+ if(result)
+ return result;
+ }
+ }
+ break;
+
+ case FTP_MKD:
+ if(ftpcode/100 != 2) {
+ /* failure to MKD the dir */
+ failf(data, "Failed to MKD dir: %03d", ftpcode);
+ return CURLE_FTP_ACCESS_DENIED;
+ }
+ state(conn, FTP_CWD);
+ /* send CWD */
+ NBFTPSENDF(conn, "CWD %s", ftpc->dirs[ftpc->count1 - 1]);
+ break;
+
+ case FTP_MDTM:
+ result = ftp_state_mdtm_resp(conn, ftpcode);
+ break;
+
+ case FTP_TYPE:
+ case FTP_LIST_TYPE:
+ case FTP_RETR_TYPE:
+ case FTP_STOR_TYPE:
+ result = ftp_state_type_resp(conn, ftpcode, ftpc->state);
+ break;
+
+ case FTP_SIZE:
+ case FTP_RETR_SIZE:
+ case FTP_STOR_SIZE:
+ result = ftp_state_size_resp(conn, ftpcode, ftpc->state);
+ break;
+
+ case FTP_REST:
+ case FTP_RETR_REST:
+ result = ftp_state_rest_resp(conn, ftpcode, ftpc->state);
+ break;
+
+ case FTP_PASV:
+ result = ftp_state_pasv_resp(conn, ftpcode);
+ break;
+
+ case FTP_PORT:
+ result = ftp_state_port_resp(conn, ftpcode);
+ break;
+
+ case FTP_LIST:
+ case FTP_RETR:
+ result = ftp_state_get_resp(conn, ftpcode, ftpc->state);
+ break;
+
+ case FTP_STOR:
+ result = ftp_state_stor_resp(conn, ftpcode);
+ break;
+
+ case FTP_QUIT:
+ /* fallthrough, just stop! */
+ default:
+ /* internal error */
+ state(conn, FTP_STOP);
+ break;
+ }
+ } /* if(ftpcode) */
+
+ return result;
+}
+
+/* Returns timeout in ms. 0 or negative number means the timeout has already
+ triggered */
+static long ftp_state_timeout(struct connectdata *conn)
+{
+ struct SessionHandle *data=conn->data;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ long timeout_ms=360000; /* in milliseconds */
+
+ if(data->set.ftp_response_timeout )
+ /* if CURLOPT_FTP_RESPONSE_TIMEOUT is set, use that to determine remaining
+ time. Also, use ftp->response because FTP_RESPONSE_TIMEOUT is supposed
+ to govern the response for any given ftp response, not for the time
+ from connect to the given ftp response. */
+ timeout_ms = data->set.ftp_response_timeout*1000 - /* timeout time */
+ Curl_tvdiff(Curl_tvnow(), ftpc->response); /* spent time */
+ else if(data->set.timeout)
+ /* if timeout is requested, find out how much remaining time we have */
+ timeout_ms = data->set.timeout*1000 - /* timeout time */
+ Curl_tvdiff(Curl_tvnow(), conn->now); /* spent time */
+ else
+ /* Without a requested timeout, we only wait 'response_time' seconds for
+ the full response to arrive before we bail out */
+ timeout_ms = ftpc->response_time*1000 -
+ Curl_tvdiff(Curl_tvnow(), ftpc->response); /* spent time */
+
+ return timeout_ms;
+}
+
+
+/* called repeatedly until done from multi.c */
+CURLcode Curl_ftp_multi_statemach(struct connectdata *conn,
+ bool *done)
+{
+ curl_socket_t sock = conn->sock[FIRSTSOCKET];
+ int rc;
+ struct SessionHandle *data=conn->data;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ CURLcode result = CURLE_OK;
+ long timeout_ms = ftp_state_timeout(conn);
+
+ *done = FALSE; /* default to not done yet */
+
+ if(timeout_ms <= 0) {
+ failf(data, "FTP response timeout");
+ return CURLE_OPERATION_TIMEDOUT;
+ }
+
+ rc = Curl_select(ftpc->sendleft?CURL_SOCKET_BAD:sock, /* reading */
+ ftpc->sendleft?sock:CURL_SOCKET_BAD, /* writing */
+ 0);
+
+ if(rc == -1) {
+ failf(data, "select error");
+ return CURLE_OUT_OF_MEMORY;
+ }
+ else if(rc != 0) {
+ result = ftp_statemach_act(conn);
+ *done = (bool)(ftpc->state == FTP_STOP);
+ }
+ /* if rc == 0, then select() timed out */
+
+ return result;
+}
+
+static CURLcode ftp_easy_statemach(struct connectdata *conn)
+{
+ curl_socket_t sock = conn->sock[FIRSTSOCKET];
+ int rc;
+ struct SessionHandle *data=conn->data;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ CURLcode result = CURLE_OK;
+
+ while(ftpc->state != FTP_STOP) {
+ long timeout_ms = ftp_state_timeout(conn);
+
+ if(timeout_ms <=0 ) {
+ failf(data, "FTP response timeout");
+ return CURLE_OPERATION_TIMEDOUT; /* already too little time */
+ }
+
+ rc = Curl_select(ftpc->sendleft?CURL_SOCKET_BAD:sock, /* reading */
+ ftpc->sendleft?sock:CURL_SOCKET_BAD, /* writing */
+ (int)timeout_ms);
+
+ if(rc == -1) {
+ failf(data, "select error");
+ return CURLE_OUT_OF_MEMORY;
+ }
+ else if(rc == 0) {
+ result = CURLE_OPERATION_TIMEDOUT;
+ break;
+ }
+ else {
+ result = ftp_statemach_act(conn);
+ if(result)
+ break;
+ }
+ }
+
+ return result;
+}
+
+/*
+ * Allocate and initialize the struct FTP for the current SessionHandle. If
+ * need be.
+ */
+static CURLcode ftp_init(struct connectdata *conn)
+{
+ struct SessionHandle *data = conn->data;
+ struct FTP *ftp;
+ if(data->reqdata.proto.ftp)
+ return CURLE_OK;
+
+ ftp = (struct FTP *)calloc(sizeof(struct FTP), 1);
+ if(!ftp)
+ return CURLE_OUT_OF_MEMORY;
+
+ data->reqdata.proto.ftp = ftp;
+
+ /* get some initial data into the ftp struct */
+ ftp->bytecountp = &data->reqdata.keep.bytecount;
+
+ /* no need to duplicate them, this connectdata struct won't change */
+ ftp->user = conn->user;
+ ftp->passwd = conn->passwd;
+ if (isBadFtpString(ftp->user) || isBadFtpString(ftp->passwd))
+ return CURLE_URL_MALFORMAT;
+
+ return CURLE_OK;
+}
+
+/*
+ * Curl_ftp_connect() should do everything that is to be considered a part of
+ * the connection phase.
+ *
+ * The variable 'done' points to will be TRUE if the protocol-layer connect
+ * phase is done when this function returns, or FALSE is not. When called as
+ * a part of the easy interface, it will always be TRUE.
+ */
+CURLcode Curl_ftp_connect(struct connectdata *conn,
+ bool *done) /* see description above */
+{
+ CURLcode result;
+#ifndef CURL_DISABLE_HTTP
+ /* for FTP over HTTP proxy */
+ struct HTTP http_proxy;
+ struct FTP *ftp_save;
+#endif /* CURL_DISABLE_HTTP */
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ struct SessionHandle *data=conn->data;
+
+ *done = FALSE; /* default to not done yet */
+
+ if (data->reqdata.proto.ftp) {
+ Curl_ftp_disconnect(conn);
+ free(data->reqdata.proto.ftp);
+ data->reqdata.proto.ftp = NULL;
+ }
+
+ result = ftp_init(conn);
+ if(result)
+ return result;
+
+ /* We always support persistant connections on ftp */
+ conn->bits.close = FALSE;
+
+ ftpc->response_time = 3600; /* set default response time-out */
+
+#ifndef CURL_DISABLE_HTTP
+ if (conn->bits.tunnel_proxy && conn->bits.httpproxy) {
+ /* BLOCKING */
+ /* We want "seamless" FTP operations through HTTP proxy tunnel */
+
+ /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member
+ * conn->proto.http; we want FTP through HTTP and we have to change the
+ * member temporarily for connecting to the HTTP proxy. After
+ * Curl_proxyCONNECT we have to set back the member to the original struct
+ * FTP pointer
+ */
+ ftp_save = data->reqdata.proto.ftp;
+ memset(&http_proxy, 0, sizeof(http_proxy));
+ data->reqdata.proto.http = &http_proxy;
+
+ result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
+ conn->host.name, conn->remote_port);
+
+ data->reqdata.proto.ftp = ftp_save;
+
+ if(CURLE_OK != result)
+ return result;
+ }
+#endif /* CURL_DISABLE_HTTP */
+
+ if(conn->protocol & PROT_FTPS) {
+ /* BLOCKING */
+ /* FTPS is simply ftp with SSL for the control channel */
+ /* now, perform the SSL initialization for this socket */
+ result = Curl_ssl_connect(conn, FIRSTSOCKET);
+ if(result)
+ return result;
+ }
+
+ /* When we connect, we start in the state where we await the 220
+ response */
+ ftp_respinit(conn); /* init the response reader stuff */
+ state(conn, FTP_WAIT220);
+ ftpc->response = Curl_tvnow(); /* start response time-out now! */
+
+ if(data->state.used_interface == Curl_if_multi)
+ result = Curl_ftp_multi_statemach(conn, done);
+ else {
+ result = ftp_easy_statemach(conn);
+ if(!result)
+ *done = TRUE;
+ }
+
+ return result;
+}
+
+/***********************************************************************
+ *
+ * Curl_ftp_done()
+ *
+ * The DONE function. This does what needs to be done after a single DO has
+ * performed.
+ *
+ * Input argument is already checked for validity.
+ */
+CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status, bool premature)
+{
+ struct SessionHandle *data = conn->data;
+ struct FTP *ftp = data->reqdata.proto.ftp;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ ssize_t nread;
+ int ftpcode;
+ CURLcode result=CURLE_OK;
+ bool was_ctl_valid = ftpc->ctl_valid;
+ size_t flen;
+ size_t dlen;
+ char *path;
+ char *path_to_use = data->reqdata.path;
+ struct Curl_transfer_keeper *k = &data->reqdata.keep;
+
+ if(!ftp)
+ /* When the easy handle is removed from the multi while libcurl is still
+ * trying to resolve the host name, it seems that the ftp struct is not
+ * yet initialized, but the removal action calls Curl_done() which calls
+ * this function. So we simply return success if no ftp pointer is set.
+ */
+ return CURLE_OK;
+
+ switch(status) {
+ case CURLE_BAD_DOWNLOAD_RESUME:
+ case CURLE_FTP_WEIRD_PASV_REPLY:
+ case CURLE_FTP_PORT_FAILED:
+ case CURLE_FTP_COULDNT_SET_BINARY:
+ case CURLE_FTP_COULDNT_RETR_FILE:
+ case CURLE_FTP_COULDNT_STOR_FILE:
+ case CURLE_FTP_ACCESS_DENIED:
+ /* the connection stays alive fine even though this happened */
+ /* fall-through */
+ case CURLE_OK: /* doesn't affect the control connection's status */
+ if (!premature) {
+ ftpc->ctl_valid = was_ctl_valid;
+ break;
+ }
+ /* until we cope better with prematurely ended requests, let them
+ * fallback as if in complete failure */
+ default: /* by default, an error means the control connection is
+ wedged and should not be used anymore */
+ ftpc->ctl_valid = FALSE;
+ ftpc->cwdfail = TRUE; /* set this TRUE to prevent us to remember the
+ current path, as this connection is going */
+ conn->bits.close = TRUE; /* marked for closure */
+ break;
+ }
+
+ /* now store a copy of the directory we are in */
+ if(ftpc->prevpath)
+ free(ftpc->prevpath);
+
+ /* get the "raw" path */
+ path = curl_easy_unescape(data, path_to_use, 0, NULL);
+ if(!path)
+ return CURLE_OUT_OF_MEMORY;
+
+ flen = ftp->file?strlen(ftp->file):0; /* file is "raw" already */
+ dlen = strlen(path)-flen;
+ if(dlen && !ftpc->cwdfail) {
+ ftpc->prevpath = path;
+ if(flen)
+ /* if 'path' is not the whole string */
+ ftpc->prevpath[dlen]=0; /* terminate */
+ infof(data, "Remembering we are in dir %s\n", ftpc->prevpath);
+ }
+ else {
+ ftpc->prevpath = NULL; /* no path */
+ free(path);
+ }
+ /* free the dir tree and file parts */
+ freedirs(conn);
+
+#ifdef HAVE_KRB4
+ Curl_sec_fflush_fd(conn, conn->sock[SECONDARYSOCKET]);
+#endif
+
+ /* shut down the socket to inform the server we're done */
+
+#ifdef _WIN32_WCE
+ shutdown(conn->sock[SECONDARYSOCKET],2); /* SD_BOTH */
+#endif
+
+ sclose(conn->sock[SECONDARYSOCKET]);
+
+ conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
+
+ if(!ftp->no_transfer && !status && !premature) {
+ /*
+ * Let's see what the server says about the transfer we just performed,
+ * but lower the timeout as sometimes this connection has died while the
+ * data has been transfered. This happens when doing through NATs etc that
+ * abandon old silent connections.
+ */
+ long old_time = ftpc->response_time;
+
+ ftpc->response_time = 60; /* give it only a minute for now */
+
+ result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
+
+ ftpc->response_time = old_time; /* set this back to previous value */
+
+ if(!nread && (CURLE_OPERATION_TIMEDOUT == result)) {
+ failf(data, "control connection looks dead");
+ ftpc->ctl_valid = FALSE; /* mark control connection as bad */
+ return result;
+ }
+
+ if(result)
+ return result;
+
+ if(!ftpc->dont_check) {
+ /* 226 Transfer complete, 250 Requested file action okay, completed. */
+ if((ftpcode != 226) && (ftpcode != 250)) {
+ failf(data, "server did not report OK, got %d", ftpcode);
+ result = CURLE_PARTIAL_FILE;
+ }
+ }
+ }
+
+ if(result || premature)
+ /* the response code from the transfer showed an error already so no
+ use checking further */
+ ;
+ else if(data->set.upload) {
+ if((-1 != data->set.infilesize) &&
+ (data->set.infilesize != *ftp->bytecountp) &&
+ !data->set.crlf &&
+ !ftp->no_transfer) {
+ failf(data, "Uploaded unaligned file size (%" FORMAT_OFF_T
+ " out of %" FORMAT_OFF_T " bytes)",
+ *ftp->bytecountp, data->set.infilesize);
+ result = CURLE_PARTIAL_FILE;
+ }
+ }
+ else {
+ if((-1 != k->size) && (k->size != *ftp->bytecountp) &&
+#ifdef CURL_DO_LINEEND_CONV
+ /* Most FTP servers don't adjust their file SIZE response for CRLFs, so
+ * we'll check to see if the discrepancy can be explained by the number
+ * of CRLFs we've changed to LFs.
+ */
+ ((k->size + data->state.crlf_conversions) != *ftp->bytecountp) &&
+#endif /* CURL_DO_LINEEND_CONV */
+ (k->maxdownload != *ftp->bytecountp)) {
+ failf(data, "Received only partial file: %" FORMAT_OFF_T " bytes",
+ *ftp->bytecountp);
+ result = CURLE_PARTIAL_FILE;
+ }
+ else if(!ftpc->dont_check &&
+ !*ftp->bytecountp &&
+ (k->size>0)) {
+ failf(data, "No data was received!");
+ result = CURLE_FTP_COULDNT_RETR_FILE;
+ }
+ }
+
+ /* clear these for next connection */
+ ftp->no_transfer = FALSE;
+ ftpc->dont_check = FALSE;
+
+ /* Send any post-transfer QUOTE strings? */
+ if(!status && !result && !premature && data->set.postquote)
+ result = ftp_sendquote(conn, data->set.postquote);
+
+ return result;
+}
+
+/***********************************************************************
+ *
+ * ftp_sendquote()
+ *
+ * Where a 'quote' means a list of custom commands to send to the server.
+ * The quote list is passed as an argument.
+ */
+
+static
+CURLcode ftp_sendquote(struct connectdata *conn, struct curl_slist *quote)
+{
+ struct curl_slist *item;
+ ssize_t nread;
+ int ftpcode;
+ CURLcode result;
+
+ item = quote;
+ while (item) {
+ if (item->data) {
+ FTPSENDF(conn, "%s", item->data);
+
+ result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
+ if (result)
+ return result;
+
+ if (ftpcode >= 400) {
+ failf(conn->data, "QUOT string not accepted: %s", item->data);
+ return CURLE_FTP_QUOTE_ERROR;
+ }
+ }
+
+ item = item->next;
+ }
+
+ return CURLE_OK;
+}
+
+/***********************************************************************
+ *
+ * ftp_need_type()
+ *
+ * Returns TRUE if we in the current situation should send TYPE
+ */
+static int ftp_need_type(struct connectdata *conn,
+ bool ascii_wanted)
+{
+ return conn->proto.ftpc.transfertype != (ascii_wanted?'A':'I');
+}
+
+/***********************************************************************
+ *
+ * ftp_nb_type()
+ *
+ * Set TYPE. We only deal with ASCII or BINARY so this function
+ * sets one of them.
+ * If the transfer type is not sent, simulate on OK response in newstate
+ */
+static CURLcode ftp_nb_type(struct connectdata *conn,
+ bool ascii, ftpstate newstate)
+{
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ CURLcode result;
+ int want = ascii?'A':'I';
+
+ if (ftpc->transfertype == want) {
+ state(conn, newstate);
+ return ftp_state_type_resp(conn, 200, newstate);
+ }
+
+ NBFTPSENDF(conn, "TYPE %c", want);
+ state(conn, newstate);
+
+ /* keep track of our current transfer type */
+ ftpc->transfertype = want;
+ return CURLE_OK;
+}
+
+/***************************************************************************
+ *
+ * ftp_pasv_verbose()
+ *
+ * This function only outputs some informationals about this second connection
+ * when we've issued a PASV command before and thus we have connected to a
+ * possibly new IP address.
+ *
+ */
+static void
+ftp_pasv_verbose(struct connectdata *conn,
+ Curl_addrinfo *ai,
+ char *newhost, /* ascii version */
+ int port)
+{
+ char buf[256];
+ Curl_printable_address(ai, buf, sizeof(buf));
+ infof(conn->data, "Connecting to %s (%s) port %d\n", newhost, buf, port);
+}
+
+/*
+ Check if this is a range download, and if so, set the internal variables
+ properly.
+ */
+
+static CURLcode ftp_range(struct connectdata *conn)
+{
+ curl_off_t from, to;
+ curl_off_t totalsize=-1;
+ char *ptr;
+ char *ptr2;
+ struct SessionHandle *data = conn->data;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+
+ if(data->reqdata.use_range && data->reqdata.range) {
+ from=curlx_strtoofft(data->reqdata.range, &ptr, 0);
+ while(ptr && *ptr && (ISSPACE(*ptr) || (*ptr=='-')))
+ ptr++;
+ to=curlx_strtoofft(ptr, &ptr2, 0);
+ if(ptr == ptr2) {
+ /* we didn't get any digit */
+ to=-1;
+ }
+ if((-1 == to) && (from>=0)) {
+ /* X - */
+ data->reqdata.resume_from = from;
+ DEBUGF(infof(conn->data, "FTP RANGE %" FORMAT_OFF_T " to end of file\n",
+ from));
+ }
+ else if(from < 0) {
+ /* -Y */
+ totalsize = -from;
+ data->reqdata.maxdownload = -from;
+ data->reqdata.resume_from = from;
+ DEBUGF(infof(conn->data, "FTP RANGE the last %" FORMAT_OFF_T " bytes\n",
+ totalsize));
+ }
+ else {
+ /* X-Y */
+ totalsize = to-from;
+ data->reqdata.maxdownload = totalsize+1; /* include last byte */
+ data->reqdata.resume_from = from;
+ DEBUGF(infof(conn->data, "FTP RANGE from %" FORMAT_OFF_T
+ " getting %" FORMAT_OFF_T " bytes\n",
+ from, data->reqdata.maxdownload));
+ }
+ DEBUGF(infof(conn->data, "range-download from %" FORMAT_OFF_T
+ " to %" FORMAT_OFF_T ", totally %" FORMAT_OFF_T " bytes\n",
+ from, to, data->reqdata.maxdownload));
+ ftpc->dont_check = TRUE; /* dont check for successful transfer */
+ }
+ return CURLE_OK;
+}
+
+
+/*
+ * Curl_ftp_nextconnect()
+ *
+ * This function shall be called when the second FTP (data) connection is
+ * connected.
+ */
+
+CURLcode Curl_ftp_nextconnect(struct connectdata *conn)
+{
+ struct SessionHandle *data=conn->data;
+ CURLcode result = CURLE_OK;
+
+ /* the ftp struct is inited in Curl_ftp_connect() */
+ struct FTP *ftp = data->reqdata.proto.ftp;
+
+ DEBUGF(infof(data, "DO-MORE phase starts\n"));
+
+ if(!ftp->no_transfer && !conn->bits.no_body) {
+ /* a transfer is about to take place */
+
+ if(data->set.upload) {
+ result = ftp_nb_type(conn, data->set.prefer_ascii,
+ FTP_STOR_TYPE);
+ if (result)
+ return result;
+ }
+ else {
+ /* download */
+ ftp->downloadsize = -1; /* unknown as of yet */
+
+ result = ftp_range(conn);
+ if(result)
+ ;
+ else if((data->set.ftp_list_only) || !ftp->file) {
+ /* The specified path ends with a slash, and therefore we think this
+ is a directory that is requested, use LIST. But before that we
+ need to set ASCII transfer mode. */
+ result = ftp_nb_type(conn, 1, FTP_LIST_TYPE);
+ if (result)
+ return result;
+ }
+ else {
+ result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_RETR_TYPE);
+ if (result)
+ return result;
+ }
+ }
+ result = ftp_easy_statemach(conn);
+ }
+
+ if(ftp->no_transfer)
+ /* no data to transfer. FIX: it feels like a kludge to have this here
+ too! */
+ result=Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+
+ /* end of transfer */
+ DEBUGF(infof(data, "DO-MORE phase ends with %d\n", result));
+
+ return result;
+}
+
+
+
+/***********************************************************************
+ *
+ * ftp_perform()
+ *
+ * This is the actual DO function for FTP. Get a file/directory according to
+ * the options previously setup.
+ */
+
+static
+CURLcode ftp_perform(struct connectdata *conn,
+ bool *connected, /* connect status after PASV / PORT */
+ bool *dophase_done)
+{
+ /* this is FTP and no proxy */
+ CURLcode result=CURLE_OK;
+
+ DEBUGF(infof(conn->data, "DO phase starts\n"));
+
+ *dophase_done = FALSE; /* not done yet */
+
+ /* start the first command in the DO phase */
+ result = ftp_state_quote(conn, TRUE, FTP_QUOTE);
+ if(result)
+ return result;
+
+ /* run the state-machine */
+ if(conn->data->state.used_interface == Curl_if_multi)
+ result = Curl_ftp_multi_statemach(conn, dophase_done);
+ else {
+ result = ftp_easy_statemach(conn);
+ *dophase_done = TRUE; /* with the easy interface we are done here */
+ }
+ *connected = conn->bits.tcpconnect;
+
+ if(*dophase_done) {
+ DEBUGF(infof(conn->data, "DO phase is complete\n"));
+ }
+
+ return result;
+}
+
+/***********************************************************************
+ *
+ * Curl_ftp()
+ *
+ * This function is registered as 'curl_do' function. It decodes the path
+ * parts etc as a wrapper to the actual DO function (ftp_perform).
+ *
+ * The input argument is already checked for validity.
+ */
+CURLcode Curl_ftp(struct connectdata *conn, bool *done)
+{
+ CURLcode retcode = CURLE_OK;
+
+ *done = FALSE; /* default to false */
+
+ /*
+ Since connections can be re-used between SessionHandles, this might be a
+ connection already existing but on a fresh SessionHandle struct so we must
+ make sure we have a good 'struct FTP' to play with. For new connections,
+ the struct FTP is allocated and setup in the Curl_ftp_connect() function.
+ */
+ retcode = ftp_init(conn);
+ if(retcode)
+ return retcode;
+
+ retcode = ftp_parse_url_path(conn);
+ if (retcode)
+ return retcode;
+
+ retcode = ftp_regular_transfer(conn, done);
+
+ return retcode;
+}
+
+/***********************************************************************
+ *
+ * Curl_(nb)ftpsendf()
+ *
+ * Sends the formated string as a ftp command to a ftp server
+ *
+ * NOTE: we build the command in a fixed-length buffer, which sets length
+ * restrictions on the command!
+ *
+ * The "nb" version is made to Never Block.
+ */
+CURLcode Curl_nbftpsendf(struct connectdata *conn,
+ const char *fmt, ...)
+{
+ ssize_t bytes_written;
+ char s[256];
+ size_t write_len;
+ char *sptr=s;
+ CURLcode res = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(s, 250, fmt, ap);
+ va_end(ap);
+
+ strcat(s, "\r\n"); /* append a trailing CRLF */
+
+ bytes_written=0;
+ write_len = strlen(s);
+
+ ftp_respinit(conn);
+
+#ifdef CURL_DOES_CONVERSIONS
+ res = Curl_convert_to_network(data, s, write_len);
+ /* Curl_convert_to_network calls failf if unsuccessful */
+ if(res != CURLE_OK) {
+ return res;
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ res = Curl_write(conn, conn->sock[FIRSTSOCKET], sptr, write_len,
+ &bytes_written);
+
+ if(CURLE_OK != res)
+ return res;
+
+ if(conn->data->set.verbose)
+ Curl_debug(conn->data, CURLINFO_HEADER_OUT,
+ sptr, (size_t)bytes_written, conn);
+
+ if(bytes_written != (ssize_t)write_len) {
+ /* the whole chunk was not sent, store the rest of the data */
+ write_len -= bytes_written;
+ sptr += bytes_written;
+ ftpc->sendthis = malloc(write_len);
+ if(ftpc->sendthis) {
+ memcpy(ftpc->sendthis, sptr, write_len);
+ ftpc->sendsize = ftpc->sendleft = write_len;
+ }
+ else {
+ failf(data, "out of memory");
+ res = CURLE_OUT_OF_MEMORY;
+ }
+ }
+ else
+ ftpc->response = Curl_tvnow();
+
+ return res;
+}
+
+CURLcode Curl_ftpsendf(struct connectdata *conn,
+ const char *fmt, ...)
+{
+ ssize_t bytes_written;
+ char s[256];
+ size_t write_len;
+ char *sptr=s;
+ CURLcode res = CURLE_OK;
+
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(s, 250, fmt, ap);
+ va_end(ap);
+
+ strcat(s, "\r\n"); /* append a trailing CRLF */
+
+ bytes_written=0;
+ write_len = strlen(s);
+
+#ifdef CURL_DOES_CONVERSIONS
+ res = Curl_convert_to_network(conn->data, s, write_len);
+ /* Curl_convert_to_network calls failf if unsuccessful */
+ if(res != CURLE_OK) {
+ return(res);
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ while(1) {
+ res = Curl_write(conn, conn->sock[FIRSTSOCKET], sptr, write_len,
+ &bytes_written);
+
+ if(CURLE_OK != res)
+ break;
+
+ if(conn->data->set.verbose)
+ Curl_debug(conn->data, CURLINFO_HEADER_OUT,
+ sptr, (size_t)bytes_written, conn);
+
+ if(bytes_written != (ssize_t)write_len) {
+ write_len -= bytes_written;
+ sptr += bytes_written;
+ }
+ else
+ break;
+ }
+
+ return res;
+}
+
+/***********************************************************************
+ *
+ * ftp_quit()
+ *
+ * This should be called before calling sclose() on an ftp control connection
+ * (not data connections). We should then wait for the response from the
+ * server before returning. The calling code should then try to close the
+ * connection.
+ *
+ */
+static CURLcode ftp_quit(struct connectdata *conn)
+{
+ CURLcode result = CURLE_OK;
+
+ if(conn->proto.ftpc.ctl_valid) {
+ NBFTPSENDF(conn, "QUIT", NULL);
+ state(conn, FTP_QUIT);
+
+ result = ftp_easy_statemach(conn);
+ }
+
+ return result;
+}
+
+/***********************************************************************
+ *
+ * Curl_ftp_disconnect()
+ *
+ * Disconnect from an FTP server. Cleanup protocol-specific per-connection
+ * resources. BLOCKING.
+ */
+CURLcode Curl_ftp_disconnect(struct connectdata *conn)
+{
+ struct ftp_conn *ftpc= &conn->proto.ftpc;
+
+ /* We cannot send quit unconditionally. If this connection is stale or
+ bad in any way, sending quit and waiting around here will make the
+ disconnect wait in vain and cause more problems than we need to.
+
+ ftp_quit() will check the state of ftp->ctl_valid. If it's ok it
+ will try to send the QUIT command, otherwise it will just return.
+ */
+
+ /* The FTP session may or may not have been allocated/setup at this point! */
+ if(conn->data->reqdata.proto.ftp) {
+ (void)ftp_quit(conn); /* ignore errors on the QUIT */
+
+ if(ftpc->entrypath) {
+ struct SessionHandle *data = conn->data;
+ data->state.most_recent_ftp_entrypath = NULL;
+ free(ftpc->entrypath);
+ ftpc->entrypath = NULL;
+ }
+ if(ftpc->cache) {
+ free(ftpc->cache);
+ ftpc->cache = NULL;
+ }
+ freedirs(conn);
+ if(ftpc->prevpath) {
+ free(ftpc->prevpath);
+ ftpc->prevpath = NULL;
+ }
+ }
+ return CURLE_OK;
+}
+
+/***********************************************************************
+ *
+ * ftp_parse_url_path()
+ *
+ * Parse the URL path into separate path components.
+ *
+ */
+static
+CURLcode ftp_parse_url_path(struct connectdata *conn)
+{
+ CURLcode retcode = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ /* the ftp struct is already inited in ftp_connect() */
+ struct FTP *ftp = data->reqdata.proto.ftp;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ size_t dlen;
+ char *slash_pos; /* position of the first '/' char in curpos */
+ char *path_to_use = data->reqdata.path;
+ char *cur_pos;
+
+ cur_pos = path_to_use; /* current position in path. point at the begin
+ of next path component */
+
+ ftpc->ctl_valid = FALSE;
+ ftpc->cwdfail = FALSE;
+
+ switch(data->set.ftp_filemethod) {
+ case FTPFILE_NOCWD:
+ /* fastest, but less standard-compliant */
+ ftp->file = data->reqdata.path; /* this is a full file path */
+ break;
+
+ case FTPFILE_SINGLECWD:
+ /* get the last slash */
+ slash_pos=strrchr(cur_pos, '/');
+ if(slash_pos || !cur_pos || !*cur_pos) {
+ ftpc->dirdepth = 1; /* we consider it to be a single dir */
+ ftpc->dirs = (char **)calloc(1, sizeof(ftpc->dirs[0]));
+ if(!ftpc->dirs)
+ return CURLE_OUT_OF_MEMORY;
+
+ ftpc->dirs[0] = curl_easy_unescape(conn->data, slash_pos ? cur_pos : "/",
+ slash_pos?(int)(slash_pos-cur_pos):1,
+ NULL);
+ if(!ftpc->dirs[0]) {
+ free(ftpc->dirs);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ ftp->file = slash_pos ? slash_pos+1 : cur_pos; /* rest is file name */
+ }
+ else
+ ftp->file = cur_pos; /* this is a file name only */
+ break;
+
+ default: /* allow pretty much anything */
+ case FTPFILE_MULTICWD:
+ ftpc->dirdepth = 0;
+ ftpc->diralloc = 5; /* default dir depth to allocate */
+ ftpc->dirs = (char **)calloc(ftpc->diralloc, sizeof(ftpc->dirs[0]));
+ if(!ftpc->dirs)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* parse the URL path into separate path components */
+ while ((slash_pos = strchr(cur_pos, '/')) != NULL) {
+ /* 1 or 0 to indicate absolute directory */
+ bool absolute_dir = (bool)((cur_pos - data->reqdata.path > 0) &&
+ (ftpc->dirdepth == 0));
+
+ /* seek out the next path component */
+ if (slash_pos-cur_pos) {
+ /* we skip empty path components, like "x//y" since the FTP command
+ CWD requires a parameter and a non-existent parameter a) doesn't
+ work on many servers and b) has no effect on the others. */
+ int len = (int)(slash_pos - cur_pos + absolute_dir);
+ ftpc->dirs[ftpc->dirdepth] = curl_easy_unescape(conn->data,
+ cur_pos - absolute_dir,
+ len, NULL);
+ if (!ftpc->dirs[ftpc->dirdepth]) { /* run out of memory ... */
+ failf(data, "no memory");
+ freedirs(conn);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ if (isBadFtpString(ftpc->dirs[ftpc->dirdepth])) {
+ freedirs(conn);
+ return CURLE_URL_MALFORMAT;
+ }
+ }
+ else {
+ cur_pos = slash_pos + 1; /* jump to the rest of the string */
+ continue;
+ }
+
+ if(!retcode) {
+ cur_pos = slash_pos + 1; /* jump to the rest of the string */
+ if(++ftpc->dirdepth >= ftpc->diralloc) {
+ /* enlarge array */
+ char *bigger;
+ ftpc->diralloc *= 2; /* double the size each time */
+ bigger = realloc(ftpc->dirs, ftpc->diralloc * sizeof(ftpc->dirs[0]));
+ if(!bigger) {
+ ftpc->dirdepth--;
+ freedirs(conn);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ ftpc->dirs = (char **)bigger;
+ }
+ }
+ }
+
+ ftp->file = cur_pos; /* the rest is the file name */
+ }
+
+ if(*ftp->file) {
+ ftp->file = curl_easy_unescape(conn->data, ftp->file, 0, NULL);
+ if(NULL == ftp->file) {
+ freedirs(conn);
+ failf(data, "no memory");
+ return CURLE_OUT_OF_MEMORY;
+ }
+ if (isBadFtpString(ftp->file)) {
+ freedirs(conn);
+ return CURLE_URL_MALFORMAT;
+ }
+ }
+ else
+ ftp->file=NULL; /* instead of point to a zero byte, we make it a NULL
+ pointer */
+
+ if(data->set.upload && !ftp->file &&
+ (!ftp->no_transfer || conn->bits.no_body)) {
+ /* We need a file name when uploading. Return error! */
+ failf(data, "Uploading to a URL without a file name!");
+ return CURLE_URL_MALFORMAT;
+ }
+
+ ftpc->cwddone = FALSE; /* default to not done */
+
+ if(ftpc->prevpath) {
+ /* prevpath is "raw" so we convert the input path before we compare the
+ strings */
+ char *path = curl_easy_unescape(conn->data, data->reqdata.path, 0, NULL);
+ if(!path)
+ return CURLE_OUT_OF_MEMORY;
+
+ dlen = strlen(path) - (ftp->file?strlen(ftp->file):0);
+ if((dlen == strlen(ftpc->prevpath)) &&
+ curl_strnequal(path, ftpc->prevpath, dlen)) {
+ infof(data, "Request has same path as previous transfer\n");
+ ftpc->cwddone = TRUE;
+ }
+ free(path);
+ }
+
+ return retcode;
+}
+
+/* call this when the DO phase has completed */
+static CURLcode ftp_dophase_done(struct connectdata *conn,
+ bool connected)
+{
+ CURLcode result = CURLE_OK;
+ struct FTP *ftp = conn->data->reqdata.proto.ftp;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+
+ if(connected)
+ result = Curl_ftp_nextconnect(conn);
+
+ if(result && (conn->sock[SECONDARYSOCKET] != CURL_SOCKET_BAD)) {
+ /* Failure detected, close the second socket if it was created already */
+ sclose(conn->sock[SECONDARYSOCKET]);
+ conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
+ return result;
+ }
+
+ if(ftp->no_transfer)
+ /* no data to transfer */
+ result=Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ else if(!connected)
+ /* since we didn't connect now, we want do_more to get called */
+ conn->bits.do_more = TRUE;
+
+ ftpc->ctl_valid = TRUE; /* seems good */
+
+ return result;
+}
+
+/* called from multi.c while DOing */
+CURLcode Curl_ftp_doing(struct connectdata *conn,
+ bool *dophase_done)
+{
+ CURLcode result;
+ result = Curl_ftp_multi_statemach(conn, dophase_done);
+
+ if(*dophase_done) {
+ result = ftp_dophase_done(conn, FALSE /* not connected */);
+
+ DEBUGF(infof(conn->data, "DO phase is complete\n"));
+ }
+ return result;
+}
+
+/***********************************************************************
+ *
+ * ftp_regular_transfer()
+ *
+ * The input argument is already checked for validity.
+ *
+ * Performs all commands done before a regular transfer between a local and a
+ * remote host.
+ *
+ * ftp->ctl_valid starts out as FALSE, and gets set to TRUE if we reach the
+ * Curl_ftp_done() function without finding any major problem.
+ */
+static
+CURLcode ftp_regular_transfer(struct connectdata *conn,
+ bool *dophase_done)
+{
+ CURLcode result=CURLE_OK;
+ bool connected=0;
+ struct SessionHandle *data = conn->data;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
+ data->reqdata.size = -1; /* make sure this is unknown at this point */
+
+ Curl_pgrsSetUploadCounter(data, 0);
+ Curl_pgrsSetDownloadCounter(data, 0);
+ Curl_pgrsSetUploadSize(data, 0);
+ Curl_pgrsSetDownloadSize(data, 0);
+
+ ftpc->ctl_valid = TRUE; /* starts good */
+
+ result = ftp_perform(conn,
+ &connected, /* have we connected after PASV/PORT */
+ dophase_done); /* all commands in the DO-phase done? */
+
+ if(CURLE_OK == result) {
+
+ if(!*dophase_done)
+ /* the DO phase has not completed yet */
+ return CURLE_OK;
+
+ result = ftp_dophase_done(conn, connected);
+ if(result)
+ return result;
+ }
+ else
+ freedirs(conn);
+
+ return result;
+}
+
+#endif /* CURL_DISABLE_FTP */
diff --git a/Utilities/cmcurl/ftp.h b/Utilities/cmcurl/ftp.h
new file mode 100644
index 0000000000..b64e705061
--- /dev/null
+++ b/Utilities/cmcurl/ftp.h
@@ -0,0 +1,43 @@
+#ifndef __FTP_H
+#define __FTP_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifndef CURL_DISABLE_FTP
+CURLcode Curl_ftp(struct connectdata *conn, bool *done);
+CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode, bool premature);
+CURLcode Curl_ftp_connect(struct connectdata *conn, bool *done);
+CURLcode Curl_ftp_disconnect(struct connectdata *conn);
+CURLcode Curl_ftpsendf(struct connectdata *, const char *fmt, ...);
+CURLcode Curl_nbftpsendf(struct connectdata *, const char *fmt, ...);
+CURLcode Curl_GetFTPResponse(ssize_t *nread, struct connectdata *conn,
+ int *ftpcode);
+CURLcode Curl_ftp_nextconnect(struct connectdata *conn);
+CURLcode Curl_ftp_multi_statemach(struct connectdata *conn, bool *done);
+int Curl_ftp_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks);
+CURLcode Curl_ftp_doing(struct connectdata *conn,
+ bool *dophase_done);
+#endif /* CURL_DISABLE_FTP */
+#endif /* __FTP_H */
diff --git a/Utilities/cmcurl/getenv.c b/Utilities/cmcurl/getenv.c
new file mode 100644
index 0000000000..4f955f8939
--- /dev/null
+++ b/Utilities/cmcurl/getenv.c
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef VMS
+#include <unixlib.h>
+#endif
+
+#include <curl/curl.h>
+#include "memory.h"
+
+#include "memdebug.h"
+
+static
+char *GetEnv(const char *variable)
+{
+#ifdef _WIN32_WCE
+ return NULL;
+#else
+#ifdef WIN32
+ char env[MAX_PATH]; /* MAX_PATH is from windef.h */
+ char *temp = getenv(variable);
+ env[0] = '\0';
+ if (temp != NULL)
+ ExpandEnvironmentStrings(temp, env, sizeof(env));
+#else
+#ifdef VMS
+ char *env = getenv(variable);
+ if (env && strcmp("HOME",variable) == 0) {
+ env = decc$translate_vms(env);
+ }
+#else
+ /* no length control */
+ char *env = getenv(variable);
+#endif
+#endif
+ return (env && env[0])?strdup(env):NULL;
+#endif
+}
+
+char *curl_getenv(const char *v)
+{
+ return GetEnv(v);
+}
diff --git a/Utilities/cmcurl/getinfo.c b/Utilities/cmcurl/getinfo.c
new file mode 100644
index 0000000000..5cf3bcacdd
--- /dev/null
+++ b/Utilities/cmcurl/getinfo.c
@@ -0,0 +1,234 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <curl/curl.h>
+
+#include "urldata.h"
+#include "getinfo.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include "memory.h"
+#include "sslgen.h"
+
+/* Make this the last #include */
+#include "memdebug.h"
+
+/*
+ * This is supposed to be called in the beginning of a perform() session
+ * and should reset all session-info variables
+ */
+CURLcode Curl_initinfo(struct SessionHandle *data)
+{
+ struct Progress *pro = &data->progress;
+ struct PureInfo *info =&data->info;
+
+ pro->t_nslookup = 0;
+ pro->t_connect = 0;
+ pro->t_pretransfer = 0;
+ pro->t_starttransfer = 0;
+ pro->timespent = 0;
+ pro->t_redirect = 0;
+
+ info->httpcode = 0;
+ info->httpversion=0;
+ info->filetime=-1; /* -1 is an illegal time and thus means unknown */
+
+ if (info->contenttype)
+ free(info->contenttype);
+ info->contenttype = NULL;
+
+ info->header_size = 0;
+ info->request_size = 0;
+ info->numconnects = 0;
+ return CURLE_OK;
+}
+
+CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
+{
+ va_list arg;
+ long *param_longp=NULL;
+ double *param_doublep=NULL;
+ char **param_charp=NULL;
+ struct curl_slist **param_slistp=NULL;
+ char buf;
+
+ if(!data)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ va_start(arg, info);
+
+ switch(info&CURLINFO_TYPEMASK) {
+ default:
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ case CURLINFO_STRING:
+ param_charp = va_arg(arg, char **);
+ if(NULL == param_charp)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ break;
+ case CURLINFO_LONG:
+ param_longp = va_arg(arg, long *);
+ if(NULL == param_longp)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ break;
+ case CURLINFO_DOUBLE:
+ param_doublep = va_arg(arg, double *);
+ if(NULL == param_doublep)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ break;
+ case CURLINFO_SLIST:
+ param_slistp = va_arg(arg, struct curl_slist **);
+ if(NULL == param_slistp)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ break;
+ }
+
+ switch(info) {
+ case CURLINFO_EFFECTIVE_URL:
+ *param_charp = data->change.url?data->change.url:(char *)"";
+ break;
+ case CURLINFO_RESPONSE_CODE:
+ *param_longp = data->info.httpcode;
+ break;
+ case CURLINFO_HTTP_CONNECTCODE:
+ *param_longp = data->info.httpproxycode;
+ break;
+ case CURLINFO_FILETIME:
+ *param_longp = data->info.filetime;
+ break;
+ case CURLINFO_HEADER_SIZE:
+ *param_longp = data->info.header_size;
+ break;
+ case CURLINFO_REQUEST_SIZE:
+ *param_longp = data->info.request_size;
+ break;
+ case CURLINFO_TOTAL_TIME:
+ *param_doublep = data->progress.timespent;
+ break;
+ case CURLINFO_NAMELOOKUP_TIME:
+ *param_doublep = data->progress.t_nslookup;
+ break;
+ case CURLINFO_CONNECT_TIME:
+ *param_doublep = data->progress.t_connect;
+ break;
+ case CURLINFO_PRETRANSFER_TIME:
+ *param_doublep = data->progress.t_pretransfer;
+ break;
+ case CURLINFO_STARTTRANSFER_TIME:
+ *param_doublep = data->progress.t_starttransfer;
+ break;
+ case CURLINFO_SIZE_UPLOAD:
+ *param_doublep = (double)data->progress.uploaded;
+ break;
+ case CURLINFO_SIZE_DOWNLOAD:
+ *param_doublep = (double)data->progress.downloaded;
+ break;
+ case CURLINFO_SPEED_DOWNLOAD:
+ *param_doublep = (double)data->progress.dlspeed;
+ break;
+ case CURLINFO_SPEED_UPLOAD:
+ *param_doublep = (double)data->progress.ulspeed;
+ break;
+ case CURLINFO_SSL_VERIFYRESULT:
+ *param_longp = data->set.ssl.certverifyresult;
+ break;
+ case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
+ *param_doublep = (double)data->progress.size_dl;
+ break;
+ case CURLINFO_CONTENT_LENGTH_UPLOAD:
+ *param_doublep = (double)data->progress.size_ul;
+ break;
+ case CURLINFO_REDIRECT_TIME:
+ *param_doublep = data->progress.t_redirect;
+ break;
+ case CURLINFO_REDIRECT_COUNT:
+ *param_longp = data->set.followlocation;
+ break;
+ case CURLINFO_CONTENT_TYPE:
+ *param_charp = data->info.contenttype;
+ break;
+ case CURLINFO_PRIVATE:
+ *param_charp = data->set.private_data;
+ break;
+ case CURLINFO_HTTPAUTH_AVAIL:
+ *param_longp = data->info.httpauthavail;
+ break;
+ case CURLINFO_PROXYAUTH_AVAIL:
+ *param_longp = data->info.proxyauthavail;
+ break;
+ case CURLINFO_OS_ERRNO:
+ *param_longp = data->state.os_errno;
+ break;
+ case CURLINFO_NUM_CONNECTS:
+ *param_longp = data->info.numconnects;
+ break;
+ case CURLINFO_SSL_ENGINES:
+ *param_slistp = Curl_ssl_engines_list(data);
+ break;
+ case CURLINFO_COOKIELIST:
+ *param_slistp = Curl_cookie_list(data);
+ break;
+ case CURLINFO_FTP_ENTRY_PATH:
+ /* Return the entrypath string from the most recent connection.
+ This pointer was copied from the connectdata structure by FTP.
+ The actual string may be free()ed by subsequent libcurl calls so
+ it must be copied to a safer area before the next libcurl call.
+ Callers must never free it themselves. */
+ *param_charp = data->state.most_recent_ftp_entrypath;
+ break;
+ case CURLINFO_LASTSOCKET:
+ if((data->state.lastconnect != -1) &&
+ (data->state.connc->connects[data->state.lastconnect] != NULL)) {
+ struct connectdata *c = data->state.connc->connects
+ [data->state.lastconnect];
+ *param_longp = c->sock[FIRSTSOCKET];
+ /* we have a socket connected, let's determine if the server shut down */
+ /* determine if ssl */
+ if(c->ssl[FIRSTSOCKET].use) {
+ /* use the SSL context */
+ if (!Curl_ssl_check_cxn(c))
+ *param_longp = -1; /* FIN received */
+ }
+/* Minix 3.1 doesn't support any flags on recv; just assume socket is OK */
+#ifdef MSG_PEEK
+ else {
+ /* use the socket */
+ if(recv((RECV_TYPE_ARG1)c->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf,
+ (RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) {
+ *param_longp = -1; /* FIN received */
+ }
+ }
+#endif
+ }
+ else
+ *param_longp = -1;
+ break;
+ default:
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ }
+ return CURLE_OK;
+}
diff --git a/Utilities/cmcurl/getinfo.h b/Utilities/cmcurl/getinfo.h
new file mode 100644
index 0000000000..2fe1b5c362
--- /dev/null
+++ b/Utilities/cmcurl/getinfo.h
@@ -0,0 +1,28 @@
+#ifndef __GETINFO_H
+#define __GETINFO_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...);
+CURLcode Curl_initinfo(struct SessionHandle *data);
+
+#endif
diff --git a/Utilities/cmcurl/gtls.c b/Utilities/cmcurl/gtls.c
new file mode 100644
index 0000000000..250ecada49
--- /dev/null
+++ b/Utilities/cmcurl/gtls.c
@@ -0,0 +1,640 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * Source file for all GnuTLS-specific code for the TLS/SSL layer. No code
+ * but sslgen.c should ever call or use these functions.
+ *
+ * Note: don't use the GnuTLS' *_t variable type names in this source code,
+ * since they were not present in 1.0.X.
+ */
+
+#include "setup.h"
+#ifdef USE_GNUTLS
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "gtls.h"
+#include "sslgen.h"
+#include "parsedate.h"
+#include "connect.h" /* for the connect timeout */
+#include "select.h"
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/* Enable GnuTLS debugging by defining GTLSDEBUG */
+/*#define GTLSDEBUG */
+
+#ifdef GTLSDEBUG
+static void tls_log_func(int level, const char *str)
+{
+ fprintf(stderr, "|<%d>| %s", level, str);
+}
+#endif
+
+/*
+ * Custom push and pull callback functions used by GNU TLS to read and write
+ * to the socket. These functions are simple wrappers to send() and recv()
+ * (although here using the sread/swrite macros as defined by setup_once.h).
+ * We use custom functions rather than the GNU TLS defaults because it allows
+ * us to get specific about the fourth "flags" argument, and to use arbitrary
+ * private data with gnutls_transport_set_ptr if we wish.
+ */
+static ssize_t Curl_gtls_push(void *s, const void *buf, size_t len)
+{
+ return swrite(s, buf, len);
+}
+
+static ssize_t Curl_gtls_pull(void *s, void *buf, size_t len)
+{
+ return sread(s, buf, len);
+}
+
+/* Global GnuTLS init, called from Curl_ssl_init() */
+int Curl_gtls_init(void)
+{
+ gnutls_global_init();
+#ifdef GTLSDEBUG
+ gnutls_global_set_log_function(tls_log_func);
+ gnutls_global_set_log_level(2);
+#endif
+ return 1;
+}
+
+int Curl_gtls_cleanup(void)
+{
+ gnutls_global_deinit();
+ return 1;
+}
+
+static void showtime(struct SessionHandle *data,
+ const char *text,
+ time_t stamp)
+{
+ struct tm *tm;
+#ifdef HAVE_GMTIME_R
+ struct tm buffer;
+ tm = (struct tm *)gmtime_r(&stamp, &buffer);
+#else
+ tm = gmtime(&stamp);
+#endif
+ snprintf(data->state.buffer,
+ BUFSIZE,
+ "\t %s: %s, %02d %s %4d %02d:%02d:%02d GMT\n",
+ text,
+ Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
+ tm->tm_mday,
+ Curl_month[tm->tm_mon],
+ tm->tm_year + 1900,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec);
+ infof(data, "%s", data->state.buffer);
+}
+
+/* this function does a BLOCKING SSL/TLS (re-)handshake */
+static CURLcode handshake(struct connectdata *conn,
+ gnutls_session session,
+ int sockindex,
+ bool duringconnect)
+{
+ struct SessionHandle *data = conn->data;
+ int rc;
+
+ do {
+ rc = gnutls_handshake(session);
+
+ if((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED)) {
+ long timeout_ms = DEFAULT_CONNECT_TIMEOUT;
+ long has_passed;
+
+ if(duringconnect && data->set.connecttimeout)
+ timeout_ms = data->set.connecttimeout*1000;
+
+ if(data->set.timeout) {
+ /* get the strictest timeout of the ones converted to milliseconds */
+ if((data->set.timeout*1000) < timeout_ms)
+ timeout_ms = data->set.timeout*1000;
+ }
+
+ /* Evaluate in milliseconds how much time that has passed */
+ has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);
+
+ /* subtract the passed time */
+ timeout_ms -= has_passed;
+
+ if(timeout_ms < 0) {
+ /* a precaution, no need to continue if time already is up */
+ failf(data, "SSL connection timeout");
+ return CURLE_OPERATION_TIMEOUTED;
+ }
+
+ rc = Curl_select(conn->sock[sockindex],
+ conn->sock[sockindex], (int)timeout_ms);
+ if(rc > 0)
+ /* reabable or writable, go loop*/
+ continue;
+ else if(0 == rc) {
+ /* timeout */
+ failf(data, "SSL connection timeout");
+ return CURLE_OPERATION_TIMEDOUT;
+ }
+ else {
+ /* anything that gets here is fatally bad */
+ failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+ }
+ else
+ break;
+ } while(1);
+
+ if (rc < 0) {
+ failf(data, "gnutls_handshake() failed: %s", gnutls_strerror(rc));
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+
+ return CURLE_OK;
+}
+
+static gnutls_x509_crt_fmt do_file_type(const char *type)
+{
+ if(!type || !type[0])
+ return GNUTLS_X509_FMT_PEM;
+ if(curl_strequal(type, "PEM"))
+ return GNUTLS_X509_FMT_PEM;
+ if(curl_strequal(type, "DER"))
+ return GNUTLS_X509_FMT_DER;
+ return -1;
+}
+
+
+/*
+ * This function is called after the TCP connect has completed. Setup the TLS
+ * layer and do all necessary magic.
+ */
+CURLcode
+Curl_gtls_connect(struct connectdata *conn,
+ int sockindex)
+
+{
+ const int cert_type_priority[] = { GNUTLS_CRT_X509, 0 };
+ struct SessionHandle *data = conn->data;
+ gnutls_session session;
+ int rc;
+ unsigned int cert_list_size;
+ const gnutls_datum *chainp;
+ unsigned int verify_status;
+ gnutls_x509_crt x509_cert;
+ char certbuf[256]; /* big enough? */
+ size_t size;
+ unsigned int algo;
+ unsigned int bits;
+ time_t clock;
+ const char *ptr;
+ void *ssl_sessionid;
+ size_t ssl_idsize;
+
+ /* GnuTLS only supports TLSv1 (and SSLv3?) */
+ if(data->set.ssl.version == CURL_SSLVERSION_SSLv2) {
+ failf(data, "GnuTLS does not support SSLv2");
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+
+ /* allocate a cred struct */
+ rc = gnutls_certificate_allocate_credentials(&conn->ssl[sockindex].cred);
+ if(rc < 0) {
+ failf(data, "gnutls_cert_all_cred() failed: %s", gnutls_strerror(rc));
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+
+ if(data->set.ssl.CAfile) {
+ /* set the trusted CA cert bundle file */
+ gnutls_certificate_set_verify_flags(conn->ssl[sockindex].cred,
+ GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
+
+ rc = gnutls_certificate_set_x509_trust_file(conn->ssl[sockindex].cred,
+ data->set.ssl.CAfile,
+ GNUTLS_X509_FMT_PEM);
+ if(rc < 0) {
+ infof(data, "error reading ca cert file %s (%s)\n",
+ data->set.ssl.CAfile, gnutls_strerror(rc));
+ if (data->set.ssl.verifypeer)
+ return CURLE_SSL_CACERT_BADFILE;
+ }
+ else
+ infof(data, "found %d certificates in %s\n",
+ rc, data->set.ssl.CAfile);
+ }
+
+ /* Initialize TLS session as a client */
+ rc = gnutls_init(&conn->ssl[sockindex].session, GNUTLS_CLIENT);
+ if(rc) {
+ failf(data, "gnutls_init() failed: %d", rc);
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+
+ /* convenient assign */
+ session = conn->ssl[sockindex].session;
+
+ /* Use default priorities */
+ rc = gnutls_set_default_priority(session);
+ if(rc < 0)
+ return CURLE_SSL_CONNECT_ERROR;
+
+ /* Sets the priority on the certificate types supported by gnutls. Priority
+ is higher for types specified before others. After specifying the types
+ you want, you must append a 0. */
+ rc = gnutls_certificate_type_set_priority(session, cert_type_priority);
+ if(rc < 0)
+ return CURLE_SSL_CONNECT_ERROR;
+
+ if(data->set.cert) {
+ if( gnutls_certificate_set_x509_key_file(
+ conn->ssl[sockindex].cred, data->set.cert,
+ data->set.key != 0 ? data->set.key : data->set.cert,
+ do_file_type(data->set.cert_type) ) ) {
+ failf(data, "error reading X.509 key or certificate file");
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+ }
+
+ /* put the credentials to the current session */
+ rc = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE,
+ conn->ssl[sockindex].cred);
+
+ /* set the connection handle (file descriptor for the socket) */
+ gnutls_transport_set_ptr(session,
+ (gnutls_transport_ptr)conn->sock[sockindex]);
+
+ /* register callback functions to send and receive data. */
+ gnutls_transport_set_push_function(session, Curl_gtls_push);
+ gnutls_transport_set_pull_function(session, Curl_gtls_pull);
+
+ /* lowat must be set to zero when using custom push and pull functions. */
+ gnutls_transport_set_lowat(session, 0);
+
+ /* This might be a reconnect, so we check for a session ID in the cache
+ to speed up things */
+
+ if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, &ssl_idsize)) {
+ /* we got a session id, use it! */
+ gnutls_session_set_data(session, ssl_sessionid, ssl_idsize);
+
+ /* Informational message */
+ infof (data, "SSL re-using session ID\n");
+ }
+
+ rc = handshake(conn, session, sockindex, TRUE);
+ if(rc)
+ /* handshake() sets its own error message with failf() */
+ return rc;
+
+ /* This function will return the peer's raw certificate (chain) as sent by
+ the peer. These certificates are in raw format (DER encoded for
+ X.509). In case of a X.509 then a certificate list may be present. The
+ first certificate in the list is the peer's certificate, following the
+ issuer's certificate, then the issuer's issuer etc. */
+
+ chainp = gnutls_certificate_get_peers(session, &cert_list_size);
+ if(!chainp) {
+ if(data->set.ssl.verifyhost) {
+ failf(data, "failed to get server cert");
+ return CURLE_SSL_PEER_CERTIFICATE;
+ }
+ infof(data, "\t common name: WARNING couldn't obtain\n");
+ }
+
+ /* This function will try to verify the peer's certificate and return its
+ status (trusted, invalid etc.). The value of status should be one or more
+ of the gnutls_certificate_status_t enumerated elements bitwise or'd. To
+ avoid denial of service attacks some default upper limits regarding the
+ certificate key size and chain size are set. To override them use
+ gnutls_certificate_set_verify_limits(). */
+
+ rc = gnutls_certificate_verify_peers2(session, &verify_status);
+ if (rc < 0) {
+ failf(data, "server cert verify failed: %d", rc);
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+
+ /* verify_status is a bitmask of gnutls_certificate_status bits */
+ if(verify_status & GNUTLS_CERT_INVALID) {
+ if (data->set.ssl.verifypeer) {
+ failf(data, "server certificate verification failed. CAfile: %s",
+ data->set.ssl.CAfile?data->set.ssl.CAfile:"none");
+ return CURLE_SSL_CACERT;
+ }
+ else
+ infof(data, "\t server certificate verification FAILED\n");
+ }
+ else
+ infof(data, "\t server certificate verification OK\n");
+
+ /* initialize an X.509 certificate structure. */
+ gnutls_x509_crt_init(&x509_cert);
+
+ /* convert the given DER or PEM encoded Certificate to the native
+ gnutls_x509_crt_t format */
+ gnutls_x509_crt_import(x509_cert, chainp, GNUTLS_X509_FMT_DER);
+
+ size=sizeof(certbuf);
+ rc = gnutls_x509_crt_get_dn_by_oid(x509_cert, GNUTLS_OID_X520_COMMON_NAME,
+ 0, /* the first and only one */
+ FALSE,
+ certbuf,
+ &size);
+ if(rc) {
+ infof(data, "error fetching CN from cert:%s\n",
+ gnutls_strerror(rc));
+ }
+
+ /* This function will check if the given certificate's subject matches the
+ given hostname. This is a basic implementation of the matching described
+ in RFC2818 (HTTPS), which takes into account wildcards, and the subject
+ alternative name PKIX extension. Returns non zero on success, and zero on
+ failure. */
+ rc = gnutls_x509_crt_check_hostname(x509_cert, conn->host.name);
+
+ if(!rc) {
+ if (data->set.ssl.verifyhost > 1) {
+ failf(data, "SSL: certificate subject name (%s) does not match "
+ "target host name '%s'", certbuf, conn->host.dispname);
+ gnutls_x509_crt_deinit(x509_cert);
+ return CURLE_SSL_PEER_CERTIFICATE;
+ }
+ else
+ infof(data, "\t common name: %s (does not match '%s')\n",
+ certbuf, conn->host.dispname);
+ }
+ else
+ infof(data, "\t common name: %s (matched)\n", certbuf);
+
+ /* Show:
+
+ - ciphers used
+ - subject
+ - start date
+ - expire date
+ - common name
+ - issuer
+
+ */
+
+ /* public key algorithm's parameters */
+ algo = gnutls_x509_crt_get_pk_algorithm(x509_cert, &bits);
+ infof(data, "\t certificate public key: %s\n",
+ gnutls_pk_algorithm_get_name(algo));
+
+ /* version of the X.509 certificate. */
+ infof(data, "\t certificate version: #%d\n",
+ gnutls_x509_crt_get_version(x509_cert));
+
+
+ size = sizeof(certbuf);
+ gnutls_x509_crt_get_dn(x509_cert, certbuf, &size);
+ infof(data, "\t subject: %s\n", certbuf);
+
+ clock = gnutls_x509_crt_get_activation_time(x509_cert);
+ showtime(data, "start date", clock);
+
+ clock = gnutls_x509_crt_get_expiration_time(x509_cert);
+ showtime(data, "expire date", clock);
+
+ size = sizeof(certbuf);
+ gnutls_x509_crt_get_issuer_dn(x509_cert, certbuf, &size);
+ infof(data, "\t issuer: %s\n", certbuf);
+
+ gnutls_x509_crt_deinit(x509_cert);
+
+ /* compression algorithm (if any) */
+ ptr = gnutls_compression_get_name(gnutls_compression_get(session));
+ /* the *_get_name() says "NULL" if GNUTLS_COMP_NULL is returned */
+ infof(data, "\t compression: %s\n", ptr);
+
+ /* the name of the cipher used. ie 3DES. */
+ ptr = gnutls_cipher_get_name(gnutls_cipher_get(session));
+ infof(data, "\t cipher: %s\n", ptr);
+
+ /* the MAC algorithms name. ie SHA1 */
+ ptr = gnutls_mac_get_name(gnutls_mac_get(session));
+ infof(data, "\t MAC: %s\n", ptr);
+
+ if(!ssl_sessionid) {
+ /* this session was not previously in the cache, add it now */
+
+ /* get the session ID data size */
+ gnutls_session_get_data(session, NULL, &ssl_idsize);
+ ssl_sessionid = malloc(ssl_idsize); /* get a buffer for it */
+
+ if(ssl_sessionid) {
+ /* extract session ID to the allocated buffer */
+ gnutls_session_get_data(session, ssl_sessionid, &ssl_idsize);
+
+ /* store this session id */
+ return Curl_ssl_addsessionid(conn, ssl_sessionid, ssl_idsize);
+ }
+ }
+
+ return CURLE_OK;
+}
+
+
+/* return number of sent (non-SSL) bytes */
+ssize_t Curl_gtls_send(struct connectdata *conn,
+ int sockindex,
+ void *mem,
+ size_t len)
+{
+ ssize_t rc = gnutls_record_send(conn->ssl[sockindex].session, mem, len);
+
+ if(rc < 0 ) {
+ if(rc == GNUTLS_E_AGAIN)
+ return 0; /* EWOULDBLOCK equivalent */
+ rc = -1; /* generic error code for send failure */
+ }
+
+ return rc;
+}
+
+void Curl_gtls_close_all(struct SessionHandle *data)
+{
+ /* FIX: make the OpenSSL code more generic and use parts of it here */
+ (void)data;
+}
+
+static void close_one(struct connectdata *conn,
+ int index)
+{
+ if(conn->ssl[index].session) {
+ gnutls_bye(conn->ssl[index].session, GNUTLS_SHUT_RDWR);
+ gnutls_deinit(conn->ssl[index].session);
+ }
+ gnutls_certificate_free_credentials(conn->ssl[index].cred);
+}
+
+void Curl_gtls_close(struct connectdata *conn)
+{
+ if(conn->ssl[0].use)
+ close_one(conn, 0);
+ if(conn->ssl[1].use)
+ close_one(conn, 1);
+}
+
+/*
+ * This function is called to shut down the SSL layer but keep the
+ * socket open (CCC - Clear Command Channel)
+ */
+int Curl_gtls_shutdown(struct connectdata *conn, int sockindex)
+{
+ int result;
+ int retval = 0;
+ struct SessionHandle *data = conn->data;
+ int done = 0;
+ ssize_t nread;
+ char buf[120];
+
+ /* This has only been tested on the proftpd server, and the mod_tls code
+ sends a close notify alert without waiting for a close notify alert in
+ response. Thus we wait for a close notify alert from the server, but
+ we do not send one. Let's hope other servers do the same... */
+
+ if(conn->ssl[sockindex].session) {
+ while(!done) {
+ int what = Curl_select(conn->sock[sockindex],
+ CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT);
+ if(what > 0) {
+ /* Something to read, let's do it and hope that it is the close
+ notify alert from the server */
+ result = gnutls_record_recv(conn->ssl[sockindex].session,
+ buf, sizeof(buf));
+ switch(result) {
+ case 0:
+ /* This is the expected response. There was no data but only
+ the close notify alert */
+ done = 1;
+ break;
+ case GNUTLS_E_AGAIN:
+ case GNUTLS_E_INTERRUPTED:
+ infof(data, "GNUTLS_E_AGAIN || GNUTLS_E_INTERRUPTED\n");
+ break;
+ default:
+ retval = -1;
+ done = 1;
+ break;
+ }
+ }
+ else if(0 == what) {
+ /* timeout */
+ failf(data, "SSL shutdown timeout");
+ done = 1;
+ break;
+ }
+ else {
+ /* anything that gets here is fatally bad */
+ failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
+ retval = -1;
+ done = 1;
+ }
+ }
+ gnutls_deinit(conn->ssl[sockindex].session);
+ }
+ gnutls_certificate_free_credentials(conn->ssl[sockindex].cred);
+
+ conn->ssl[sockindex].session = NULL;
+ conn->ssl[sockindex].use = FALSE;
+
+ return retval;
+}
+
+/*
+ * If the read would block we return -1 and set 'wouldblock' to TRUE.
+ * Otherwise we return the amount of data read. Other errors should return -1
+ * and set 'wouldblock' to FALSE.
+ */
+ssize_t Curl_gtls_recv(struct connectdata *conn, /* connection data */
+ int num, /* socketindex */
+ char *buf, /* store read data here */
+ size_t buffersize, /* max amount to read */
+ bool *wouldblock)
+{
+ ssize_t ret;
+
+ ret = gnutls_record_recv(conn->ssl[num].session, buf, buffersize);
+ if((ret == GNUTLS_E_AGAIN) || (ret == GNUTLS_E_INTERRUPTED)) {
+ *wouldblock = TRUE;
+ return -1;
+ }
+
+ if(ret == GNUTLS_E_REHANDSHAKE) {
+ /* BLOCKING call, this is bad but a work-around for now. Fixing this "the
+ proper way" takes a whole lot of work. */
+ CURLcode rc = handshake(conn, conn->ssl[num].session, num, FALSE);
+ if(rc)
+ /* handshake() writes error message on its own */
+ return rc;
+ *wouldblock = TRUE; /* then return as if this was a wouldblock */
+ return -1;
+ }
+
+ *wouldblock = FALSE;
+ if (!ret) {
+ failf(conn->data, "Peer closed the TLS connection");
+ return -1;
+ }
+
+ if (ret < 0) {
+ failf(conn->data, "GnuTLS recv error (%d): %s",
+ (int)ret, gnutls_strerror(ret));
+ return -1;
+ }
+
+ return ret;
+}
+
+void Curl_gtls_session_free(void *ptr)
+{
+ free(ptr);
+}
+
+size_t Curl_gtls_version(char *buffer, size_t size)
+{
+ return snprintf(buffer, size, " GnuTLS/%s", gnutls_check_version(NULL));
+}
+
+#endif /* USE_GNUTLS */
diff --git a/Utilities/cmcurl/gtls.h b/Utilities/cmcurl/gtls.h
new file mode 100644
index 0000000000..bff3f86939
--- /dev/null
+++ b/Utilities/cmcurl/gtls.h
@@ -0,0 +1,46 @@
+#ifndef __GTLS_H
+#define __GTLS_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+int Curl_gtls_init(void);
+int Curl_gtls_cleanup(void);
+CURLcode Curl_gtls_connect(struct connectdata *conn, int sockindex);
+
+/* tell GnuTLS to close down all open information regarding connections (and
+ thus session ID caching etc) */
+void Curl_gtls_close_all(struct SessionHandle *data);
+void Curl_gtls_close(struct connectdata *conn); /* close a SSL connection */
+
+/* return number of sent (non-SSL) bytes */
+ssize_t Curl_gtls_send(struct connectdata *conn, int sockindex,
+ void *mem, size_t len);
+ssize_t Curl_gtls_recv(struct connectdata *conn, /* connection data */
+ int num, /* socketindex */
+ char *buf, /* store read data here */
+ size_t buffersize, /* max amount to read */
+ bool *wouldblock);
+void Curl_gtls_session_free(void *ptr);
+size_t Curl_gtls_version(char *buffer, size_t size);
+int Curl_gtls_shutdown(struct connectdata *conn, int sockindex);
+
+#endif
diff --git a/Utilities/cmcurl/hash.c b/Utilities/cmcurl/hash.c
new file mode 100644
index 0000000000..e00462778e
--- /dev/null
+++ b/Utilities/cmcurl/hash.c
@@ -0,0 +1,315 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "hash.h"
+#include "llist.h"
+#include "memory.h"
+
+/* this must be the last include file */
+#include "memdebug.h"
+
+static unsigned long
+hash_str(const char *key, size_t key_length)
+{
+ char *end = (char *) key + key_length;
+ unsigned long h = 5381;
+
+ while (key < end) {
+ h += h << 5;
+ h ^= (unsigned long) *key++;
+ }
+
+ return h;
+}
+
+static void
+hash_element_dtor(void *user, void *element)
+{
+ struct curl_hash *h = (struct curl_hash *) user;
+ struct curl_hash_element *e = (struct curl_hash_element *) element;
+
+ if (e->key)
+ free(e->key);
+
+ h->dtor(e->ptr);
+
+ free(e);
+}
+
+/* return 1 on error, 0 is fine */
+int
+Curl_hash_init(struct curl_hash *h, int slots, curl_hash_dtor dtor)
+{
+ int i;
+
+ h->dtor = dtor;
+ h->size = 0;
+ h->slots = slots;
+
+ h->table = (struct curl_llist **) malloc(slots * sizeof(struct curl_llist *));
+ if(h->table) {
+ for (i = 0; i < slots; ++i) {
+ h->table[i] = Curl_llist_alloc((curl_llist_dtor) hash_element_dtor);
+ if(!h->table[i]) {
+ while(i--)
+ Curl_llist_destroy(h->table[i], NULL);
+ free(h->table);
+ return 1; /* failure */
+ }
+ }
+ return 0; /* fine */
+ }
+ else
+ return 1; /* failure */
+}
+
+struct curl_hash *
+Curl_hash_alloc(int slots, curl_hash_dtor dtor)
+{
+ struct curl_hash *h;
+
+ h = (struct curl_hash *) malloc(sizeof(struct curl_hash));
+ if (h) {
+ if(Curl_hash_init(h, slots, dtor)) {
+ /* failure */
+ free(h);
+ h = NULL;
+ }
+ }
+
+ return h;
+}
+
+static int
+hash_key_compare(char *key1, size_t key1_len, char *key2, size_t key2_len)
+{
+ if (key1_len == key2_len &&
+ *key1 == *key2 &&
+ memcmp(key1, key2, key1_len) == 0) {
+ return 1;
+ }
+
+ return 0;
+}
+
+static struct curl_hash_element *
+mk_hash_element(char *key, size_t key_len, const void *p)
+{
+ struct curl_hash_element *he =
+ (struct curl_hash_element *) malloc(sizeof(struct curl_hash_element));
+
+ if(he) {
+ char *dup = malloc(key_len);
+ if(dup) {
+ /* copy the key */
+ memcpy(dup, key, key_len);
+
+ he->key = dup;
+ he->key_len = key_len;
+ he->ptr = (void *) p;
+ }
+ else {
+ /* failed to duplicate the key, free memory and fail */
+ free(he);
+ he = NULL;
+ }
+ }
+ return he;
+}
+
+#define find_slot(__h, __k, __k_len) (hash_str(__k, __k_len) % (__h)->slots)
+
+#define FETCH_LIST(x,y,z) x->table[find_slot(x, y, z)]
+
+/* Return the data in the hash. If there already was a match in the hash,
+ that data is returned. */
+void *
+Curl_hash_add(struct curl_hash *h, char *key, size_t key_len, void *p)
+{
+ struct curl_hash_element *he;
+ struct curl_llist_element *le;
+ struct curl_llist *l = FETCH_LIST(h, key, key_len);
+
+ for (le = l->head; le; le = le->next) {
+ he = (struct curl_hash_element *) le->ptr;
+ if (hash_key_compare(he->key, he->key_len, key, key_len)) {
+ h->dtor(p); /* remove the NEW entry */
+ return he->ptr; /* return the EXISTING entry */
+ }
+ }
+
+ he = mk_hash_element(key, key_len, p);
+ if (he) {
+ if(Curl_llist_insert_next(l, l->tail, he)) {
+ ++h->size;
+ return p; /* return the new entry */
+ }
+ /*
+ * Couldn't insert it, destroy the 'he' element and the key again. We
+ * don't call hash_element_dtor() since that would also call the
+ * "destructor" for the actual data 'p'. When we fail, we shall not touch
+ * that data.
+ */
+ free(he->key);
+ free(he);
+ }
+
+ return NULL; /* failure */
+}
+
+/* remove the identified hash entry, returns non-zero on failure */
+int Curl_hash_delete(struct curl_hash *h, char *key, size_t key_len)
+{
+ struct curl_llist_element *le;
+ struct curl_hash_element *he;
+ struct curl_llist *l = FETCH_LIST(h, key, key_len);
+
+ for (le = l->head; le; le = le->next) {
+ he = le->ptr;
+ if (hash_key_compare(he->key, he->key_len, key, key_len)) {
+ Curl_llist_remove(l, le, (void *) h);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void *
+Curl_hash_pick(struct curl_hash *h, char *key, size_t key_len)
+{
+ struct curl_llist_element *le;
+ struct curl_hash_element *he;
+ struct curl_llist *l = FETCH_LIST(h, key, key_len);
+
+ for (le = l->head; le; le = le->next) {
+ he = le->ptr;
+ if (hash_key_compare(he->key, he->key_len, key, key_len)) {
+ return he->ptr;
+ }
+ }
+
+ return NULL;
+}
+
+#if defined(CURLDEBUG) && defined(AGGRESIVE_TEST)
+void
+Curl_hash_apply(curl_hash *h, void *user,
+ void (*cb)(void *user, void *ptr))
+{
+ struct curl_llist_element *le;
+ int i;
+
+ for (i = 0; i < h->slots; ++i) {
+ for (le = (h->table[i])->head;
+ le;
+ le = le->next) {
+ curl_hash_element *el = le->ptr;
+ cb(user, el->ptr);
+ }
+ }
+}
+#endif
+
+void
+Curl_hash_clean(struct curl_hash *h)
+{
+ int i;
+
+ for (i = 0; i < h->slots; ++i) {
+ Curl_llist_destroy(h->table[i], (void *) h);
+ }
+
+ free(h->table);
+}
+
+void
+Curl_hash_clean_with_criterium(struct curl_hash *h, void *user,
+ int (*comp)(void *, void *))
+{
+ struct curl_llist_element *le;
+ struct curl_llist_element *lnext;
+ struct curl_llist *list;
+ int i;
+
+ for (i = 0; i < h->slots; ++i) {
+ list = h->table[i];
+ le = list->head; /* get first list entry */
+ while(le) {
+ struct curl_hash_element *he = le->ptr;
+ lnext = le->next;
+ /* ask the callback function if we shall remove this entry or not */
+ if (comp(user, he->ptr)) {
+ Curl_llist_remove(list, le, (void *) h);
+ --h->size; /* one less entry in the hash now */
+ }
+ le = lnext;
+ }
+ }
+}
+
+void
+Curl_hash_destroy(struct curl_hash *h)
+{
+ if (!h)
+ return;
+
+ Curl_hash_clean(h);
+ free(h);
+}
+
+#if 0 /* useful function for debugging hashes and their contents */
+void Curl_hash_print(struct curl_hash *h,
+ void (*func)(void *))
+{
+ int i;
+ struct curl_llist_element *le;
+ struct curl_llist *list;
+ struct curl_hash_element *he;
+ if (!h)
+ return;
+
+ fprintf(stderr, "=Hash dump=\n");
+
+ for (i = 0; i < h->slots; i++) {
+ list = h->table[i];
+ le = list->head; /* get first list entry */
+ if(le) {
+ fprintf(stderr, "index %d:", i);
+ while(le) {
+ he = le->ptr;
+ if(func)
+ func(he->ptr);
+ else
+ fprintf(stderr, " [%p]", he->ptr);
+ le = le->next;
+ }
+ fprintf(stderr, "\n");
+ }
+ }
+}
+#endif
diff --git a/Utilities/cmcurl/hash.h b/Utilities/cmcurl/hash.h
new file mode 100644
index 0000000000..ceebb52348
--- /dev/null
+++ b/Utilities/cmcurl/hash.h
@@ -0,0 +1,61 @@
+#ifndef __HASH_H
+#define __HASH_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <stddef.h>
+
+#include "llist.h"
+
+typedef void (*curl_hash_dtor)(void *);
+
+struct curl_hash {
+ struct curl_llist **table;
+ curl_hash_dtor dtor;
+ int slots;
+ size_t size;
+};
+
+struct curl_hash_element {
+ void *ptr;
+ char *key;
+ size_t key_len;
+};
+
+
+int Curl_hash_init(struct curl_hash *, int, curl_hash_dtor);
+struct curl_hash *Curl_hash_alloc(int, curl_hash_dtor);
+void *Curl_hash_add(struct curl_hash *, char *, size_t, void *);
+int Curl_hash_delete(struct curl_hash *h, char *key, size_t key_len);
+void *Curl_hash_pick(struct curl_hash *, char *, size_t);
+void Curl_hash_apply(struct curl_hash *h, void *user,
+ void (*cb)(void *user, void *ptr));
+int Curl_hash_count(struct curl_hash *h);
+void Curl_hash_clean(struct curl_hash *h);
+void Curl_hash_clean_with_criterium(struct curl_hash *h, void *user,
+ int (*comp)(void *, void *));
+void Curl_hash_destroy(struct curl_hash *h);
+
+#endif
diff --git a/Utilities/cmcurl/hostares.c b/Utilities/cmcurl/hostares.c
new file mode 100644
index 0000000000..1db0f4320c
--- /dev/null
+++ b/Utilities/cmcurl/hostares.c
@@ -0,0 +1,307 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+
+#ifdef NEED_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* required for free() prototypes */
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for the close() proto */
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_SETJMP_H
+#include <setjmp.h>
+#endif
+
+#ifdef HAVE_PROCESS_H
+#include <process.h>
+#endif
+
+#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
+#undef in_addr_t
+#define in_addr_t unsigned long
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "hostip.h"
+#include "hash.h"
+#include "share.h"
+#include "strerror.h"
+#include "url.h"
+#include "multiif.h"
+#include "connect.h" /* for the Curl_sockerrno() proto */
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+#include "memory.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/***********************************************************************
+ * Only for ares-enabled builds
+ **********************************************************************/
+
+#ifdef CURLRES_ARES
+
+/*
+ * Curl_resolv_fdset() is called when someone from the outside world (using
+ * curl_multi_fdset()) wants to get our fd_set setup and we're talking with
+ * ares. The caller must make sure that this function is only called when we
+ * have a working ares channel.
+ *
+ * Returns: CURLE_OK always!
+ */
+
+int Curl_resolv_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
+
+{
+ struct timeval maxtime;
+ struct timeval timeout;
+ int max = ares_getsock(conn->data->state.areschannel,
+ (int *)socks, numsocks);
+
+
+ maxtime.tv_sec = CURL_TIMEOUT_RESOLVE;
+ maxtime.tv_usec = 0;
+
+ ares_timeout(conn->data->state.areschannel, &maxtime, &timeout);
+
+ Curl_expire(conn->data,
+ (timeout.tv_sec * 1000) + (timeout.tv_usec/1000) );
+
+ return max;
+}
+
+/*
+ * Curl_is_resolved() is called repeatedly to check if a previous name resolve
+ * request has completed. It should also make sure to time-out if the
+ * operation seems to take too long.
+ *
+ * Returns normal CURLcode errors.
+ */
+CURLcode Curl_is_resolved(struct connectdata *conn,
+ struct Curl_dns_entry **dns)
+{
+ fd_set read_fds, write_fds;
+ struct timeval tv={0,0};
+ struct SessionHandle *data = conn->data;
+ int nfds;
+
+ FD_ZERO(&read_fds);
+ FD_ZERO(&write_fds);
+
+ nfds = ares_fds(data->state.areschannel, &read_fds, &write_fds);
+
+ (void)select(nfds, &read_fds, &write_fds, NULL,
+ (struct timeval *)&tv);
+
+ /* Call ares_process() unconditonally here, even if we simply timed out
+ above, as otherwise the ares name resolve won't timeout! */
+ ares_process(data->state.areschannel, &read_fds, &write_fds);
+
+ *dns = NULL;
+
+ if(conn->async.done) {
+ /* we're done, kill the ares handle */
+ if(!conn->async.dns) {
+ failf(data, "Could not resolve host: %s (%s)", conn->host.dispname,
+ ares_strerror(conn->async.status));
+ return CURLE_COULDNT_RESOLVE_HOST;
+ }
+ *dns = conn->async.dns;
+ }
+
+ return CURLE_OK;
+}
+
+/*
+ * Curl_wait_for_resolv() waits for a resolve to finish. This function should
+ * be avoided since using this risk getting the multi interface to "hang".
+ *
+ * If 'entry' is non-NULL, make it point to the resolved dns entry
+ *
+ * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved, and
+ * CURLE_OPERATION_TIMEDOUT if a time-out occurred.
+ */
+CURLcode Curl_wait_for_resolv(struct connectdata *conn,
+ struct Curl_dns_entry **entry)
+{
+ CURLcode rc=CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ long timeout = CURL_TIMEOUT_RESOLVE; /* default name resolve timeout */
+
+ /* now, see if there's a connect timeout or a regular timeout to
+ use instead of the default one */
+ if(conn->data->set.connecttimeout)
+ timeout = conn->data->set.connecttimeout;
+ else if(conn->data->set.timeout)
+ timeout = conn->data->set.timeout;
+
+ /* We convert the number of seconds into number of milliseconds here: */
+ if(timeout < 2147483)
+ /* maximum amount of seconds that can be multiplied with 1000 and
+ still fit within 31 bits */
+ timeout *= 1000;
+ else
+ timeout = 0x7fffffff; /* ridiculous amount of time anyway */
+
+ /* Wait for the name resolve query to complete. */
+ while (1) {
+ int nfds=0;
+ fd_set read_fds, write_fds;
+ struct timeval *tvp, tv, store;
+ int count;
+ struct timeval now = Curl_tvnow();
+ long timediff;
+
+ store.tv_sec = (int)timeout/1000;
+ store.tv_usec = (timeout%1000)*1000;
+
+ FD_ZERO(&read_fds);
+ FD_ZERO(&write_fds);
+ nfds = ares_fds(data->state.areschannel, &read_fds, &write_fds);
+ if (nfds == 0)
+ /* no file descriptors means we're done waiting */
+ break;
+ tvp = ares_timeout(data->state.areschannel, &store, &tv);
+ count = select(nfds, &read_fds, &write_fds, NULL, tvp);
+ if (count < 0 && Curl_sockerrno() != EINVAL)
+ break;
+
+ ares_process(data->state.areschannel, &read_fds, &write_fds);
+
+ timediff = Curl_tvdiff(Curl_tvnow(), now); /* spent time */
+ timeout -= timediff?timediff:1; /* always deduct at least 1 */
+ if (timeout < 0) {
+ /* our timeout, so we cancel the ares operation */
+ ares_cancel(data->state.areschannel);
+ break;
+ }
+ }
+
+ /* Operation complete, if the lookup was successful we now have the entry
+ in the cache. */
+
+ if(entry)
+ *entry = conn->async.dns;
+
+ if(!conn->async.dns) {
+ /* a name was not resolved */
+ if((timeout < 0) || (conn->async.status == ARES_ETIMEOUT)) {
+ failf(data, "Resolving host timed out: %s", conn->host.dispname);
+ rc = CURLE_OPERATION_TIMEDOUT;
+ }
+ else if(conn->async.done) {
+ failf(data, "Could not resolve host: %s (%s)", conn->host.dispname,
+ ares_strerror(conn->async.status));
+ rc = CURLE_COULDNT_RESOLVE_HOST;
+ }
+ else
+ rc = CURLE_OPERATION_TIMEDOUT;
+
+ /* close the connection, since we can't return failure here without
+ cleaning up this connection properly */
+ conn->bits.close = TRUE;
+ }
+
+ return rc;
+}
+
+/*
+ * Curl_getaddrinfo() - when using ares
+ *
+ * Returns name information about the given hostname and port number. If
+ * successful, the 'hostent' is returned and the forth argument will point to
+ * memory we need to free after use. That memory *MUST* be freed with
+ * Curl_freeaddrinfo(), nothing else.
+ */
+Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ int *waitp)
+{
+ char *bufp;
+ struct SessionHandle *data = conn->data;
+ in_addr_t in = inet_addr(hostname);
+
+ *waitp = FALSE;
+
+ if (in != CURL_INADDR_NONE) {
+ /* This is a dotted IP address 123.123.123.123-style */
+ return Curl_ip2addr(in, hostname, port);
+ }
+
+ bufp = strdup(hostname);
+
+ if(bufp) {
+ Curl_safefree(conn->async.hostname);
+ conn->async.hostname = bufp;
+ conn->async.port = port;
+ conn->async.done = FALSE; /* not done */
+ conn->async.status = 0; /* clear */
+ conn->async.dns = NULL; /* clear */
+
+ /* areschannel is already setup in the Curl_open() function */
+ ares_gethostbyname(data->state.areschannel, hostname, PF_INET,
+ (ares_host_callback)Curl_addrinfo4_callback, conn);
+
+ *waitp = TRUE; /* please wait for the response */
+ }
+ return NULL; /* no struct yet */
+}
+#endif /* CURLRES_ARES */
diff --git a/Utilities/cmcurl/hostasyn.c b/Utilities/cmcurl/hostasyn.c
new file mode 100644
index 0000000000..3df147910a
--- /dev/null
+++ b/Utilities/cmcurl/hostasyn.c
@@ -0,0 +1,174 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+
+#ifdef NEED_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* required for free() prototypes */
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for the close() proto */
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_SETJMP_H
+#include <setjmp.h>
+#endif
+
+#ifdef HAVE_PROCESS_H
+#include <process.h>
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "hostip.h"
+#include "hash.h"
+#include "share.h"
+#include "strerror.h"
+#include "url.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/***********************************************************************
+ * Only for builds using asynchronous name resolves
+ **********************************************************************/
+#ifdef CURLRES_ASYNCH
+/*
+ * addrinfo_callback() gets called by ares, gethostbyname_thread() or
+ * getaddrinfo_thread() when we got the name resolved (or not!).
+ *
+ * If the status argument is CURL_ASYNC_SUCCESS, we might need to copy the
+ * address field since it might be freed when this function returns. This
+ * operation stores the resolved data in the DNS cache.
+ *
+ * NOTE: for IPv6 operations, Curl_addrinfo_copy() returns the same
+ * pointer it is given as argument!
+ *
+ * The storage operation locks and unlocks the DNS cache.
+ */
+static CURLcode addrinfo_callback(void *arg, /* "struct connectdata *" */
+ int status,
+ void *addr)
+{
+ struct connectdata *conn = (struct connectdata *)arg;
+ struct Curl_dns_entry *dns = NULL;
+ CURLcode rc = CURLE_OK;
+
+ conn->async.status = status;
+
+ if(CURL_ASYNC_SUCCESS == status) {
+
+ /*
+ * IPv4/ares: Curl_addrinfo_copy() copies the address and returns an
+ * allocated version.
+ *
+ * IPv6: Curl_addrinfo_copy() returns the input pointer!
+ */
+ Curl_addrinfo *ai = Curl_addrinfo_copy(addr, conn->async.port);
+ if(ai) {
+ struct SessionHandle *data = conn->data;
+
+ if(data->share)
+ Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
+
+ dns = Curl_cache_addr(data, ai,
+ conn->async.hostname,
+ conn->async.port);
+ if(!dns) {
+ /* failed to store, cleanup and return error */
+ Curl_freeaddrinfo(ai);
+ rc = CURLE_OUT_OF_MEMORY;
+ }
+
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+ }
+ else
+ rc = CURLE_OUT_OF_MEMORY;
+ }
+
+ conn->async.dns = dns;
+
+ /* Set async.done TRUE last in this function since it may be used multi-
+ threaded and once this is TRUE the other thread may read fields from the
+ async struct */
+ conn->async.done = TRUE;
+
+ /* ipv4: The input hostent struct will be freed by ares when we return from
+ this function */
+ return rc;
+}
+
+CURLcode Curl_addrinfo4_callback(void *arg, /* "struct connectdata *" */
+ int status,
+ struct hostent *hostent)
+{
+ return addrinfo_callback(arg, status, hostent);
+}
+
+#ifdef CURLRES_IPV6
+CURLcode Curl_addrinfo6_callback(void *arg, /* "struct connectdata *" */
+ int status,
+ struct addrinfo *ai)
+{
+ /* NOTE: for CURLRES_ARES, the 'ai' argument is really a
+ * 'struct hostent' pointer.
+ */
+ return addrinfo_callback(arg, status, ai);
+}
+#endif
+
+#endif /* CURLRES_ASYNC */
diff --git a/Utilities/cmcurl/hostip.c b/Utilities/cmcurl/hostip.c
new file mode 100644
index 0000000000..83f1564c89
--- /dev/null
+++ b/Utilities/cmcurl/hostip.c
@@ -0,0 +1,636 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+
+#ifdef NEED_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* required for free() prototypes */
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for the close() proto */
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_SETJMP_H
+#include <setjmp.h>
+#endif
+
+#ifdef HAVE_PROCESS_H
+#include <process.h>
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "hostip.h"
+#include "hash.h"
+#include "share.h"
+#include "strerror.h"
+#include "url.h"
+#include "inet_ntop.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/*
+ * hostip.c explained
+ * ==================
+ *
+ * The main COMPILE-TIME DEFINES to keep in mind when reading the host*.c
+ * source file are these:
+ *
+ * CURLRES_IPV6 - this host has getaddrinfo() and family, and thus we use
+ * that. The host may not be able to resolve IPv6, but we don't really have to
+ * take that into account. Hosts that aren't IPv6-enabled have CURLRES_IPV4
+ * defined.
+ *
+ * CURLRES_ARES - is defined if libcurl is built to use c-ares for
+ * asynchronous name resolves. This can be Windows or *nix.
+ *
+ * CURLRES_THREADED - is defined if libcurl is built to run under (native)
+ * Windows, and then the name resolve will be done in a new thread, and the
+ * supported API will be the same as for ares-builds.
+ *
+ * If any of the two previous are defined, CURLRES_ASYNCH is defined too. If
+ * libcurl is not built to use an asynchronous resolver, CURLRES_SYNCH is
+ * defined.
+ *
+ * The host*.c sources files are split up like this:
+ *
+ * hostip.c - method-independent resolver functions and utility functions
+ * hostasyn.c - functions for asynchronous name resolves
+ * hostsyn.c - functions for synchronous name resolves
+ * hostares.c - functions for ares-using name resolves
+ * hostthre.c - functions for threaded name resolves
+ * hostip4.c - ipv4-specific functions
+ * hostip6.c - ipv6-specific functions
+ *
+ * The hostip.h is the united header file for all this. It defines the
+ * CURLRES_* defines based on the config*.h and setup.h defines.
+ */
+
+/* These two symbols are for the global DNS cache */
+static struct curl_hash hostname_cache;
+static int host_cache_initialized;
+
+static void freednsentry(void *freethis);
+
+/*
+ * Curl_global_host_cache_init() initializes and sets up a global DNS cache.
+ * Global DNS cache is general badness. Do not use. This will be removed in
+ * a future version. Use the share interface instead!
+ */
+void Curl_global_host_cache_init(void)
+{
+ if (!host_cache_initialized) {
+ Curl_hash_init(&hostname_cache, 7, freednsentry);
+ host_cache_initialized = 1;
+ }
+}
+
+/*
+ * Return a pointer to the global cache
+ */
+struct curl_hash *Curl_global_host_cache_get(void)
+{
+ return &hostname_cache;
+}
+
+/*
+ * Destroy and cleanup the global DNS cache
+ */
+void Curl_global_host_cache_dtor(void)
+{
+ if (host_cache_initialized) {
+ Curl_hash_clean(&hostname_cache);
+ host_cache_initialized = 0;
+ }
+}
+
+/*
+ * Return # of adresses in a Curl_addrinfo struct
+ */
+int Curl_num_addresses(const Curl_addrinfo *addr)
+{
+ int i;
+ for (i = 0; addr; addr = addr->ai_next, i++)
+ ; /* empty loop */
+ return i;
+}
+
+/*
+ * Curl_printable_address() returns a printable version of the 1st address
+ * given in the 'ip' argument. The result will be stored in the buf that is
+ * bufsize bytes big.
+ *
+ * If the conversion fails, it returns NULL.
+ */
+const char *Curl_printable_address(const Curl_addrinfo *ip,
+ char *buf, size_t bufsize)
+{
+ const void *ip4 = &((const struct sockaddr_in*)ip->ai_addr)->sin_addr;
+ int af = ip->ai_family;
+#ifdef CURLRES_IPV6
+ const void *ip6 = &((const struct sockaddr_in6*)ip->ai_addr)->sin6_addr;
+#else
+ const void *ip6 = NULL;
+#endif
+
+ return Curl_inet_ntop(af, af == AF_INET ? ip4 : ip6, buf, bufsize);
+}
+
+/*
+ * Return a hostcache id string for the providing host + port, to be used by
+ * the DNS caching.
+ */
+static char *
+create_hostcache_id(const char *server, int port)
+{
+ /* create and return the new allocated entry */
+ return aprintf("%s:%d", server, port);
+}
+
+struct hostcache_prune_data {
+ int cache_timeout;
+ time_t now;
+};
+
+/*
+ * This function is set as a callback to be called for every entry in the DNS
+ * cache when we want to prune old unused entries.
+ *
+ * Returning non-zero means remove the entry, return 0 to keep it in the
+ * cache.
+ */
+static int
+hostcache_timestamp_remove(void *datap, void *hc)
+{
+ struct hostcache_prune_data *data =
+ (struct hostcache_prune_data *) datap;
+ struct Curl_dns_entry *c = (struct Curl_dns_entry *) hc;
+
+ if ((data->now - c->timestamp < data->cache_timeout) ||
+ c->inuse) {
+ /* please don't remove */
+ return 0;
+ }
+
+ /* fine, remove */
+ return 1;
+}
+
+/*
+ * Prune the DNS cache. This assumes that a lock has already been taken.
+ */
+static void
+hostcache_prune(struct curl_hash *hostcache, int cache_timeout, time_t now)
+{
+ struct hostcache_prune_data user;
+
+ user.cache_timeout = cache_timeout;
+ user.now = now;
+
+ Curl_hash_clean_with_criterium(hostcache,
+ (void *) &user,
+ hostcache_timestamp_remove);
+}
+
+/*
+ * Library-wide function for pruning the DNS cache. This function takes and
+ * returns the appropriate locks.
+ */
+void Curl_hostcache_prune(struct SessionHandle *data)
+{
+ time_t now;
+
+ if((data->set.dns_cache_timeout == -1) || !data->dns.hostcache)
+ /* cache forever means never prune, and NULL hostcache means
+ we can't do it */
+ return;
+
+ if(data->share)
+ Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
+
+ time(&now);
+
+ /* Remove outdated and unused entries from the hostcache */
+ hostcache_prune(data->dns.hostcache,
+ data->set.dns_cache_timeout,
+ now);
+
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+}
+
+static int
+remove_entry_if_stale(struct SessionHandle *data, struct Curl_dns_entry *dns)
+{
+ struct hostcache_prune_data user;
+
+ if( !dns || (data->set.dns_cache_timeout == -1) || !data->dns.hostcache)
+ /* cache forever means never prune, and NULL hostcache means
+ we can't do it */
+ return 0;
+
+ time(&user.now);
+ user.cache_timeout = data->set.dns_cache_timeout;
+
+ if ( !hostcache_timestamp_remove(&user,dns) )
+ return 0;
+
+ /* ok, we do need to clear the cache. although we need to remove just a
+ single entry we clean the entire hash, as no explicit delete function
+ is provided */
+ if(data->share)
+ Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
+
+ Curl_hash_clean_with_criterium(data->dns.hostcache,
+ (void *) &user,
+ hostcache_timestamp_remove);
+
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+
+ return 1;
+}
+
+
+#ifdef HAVE_SIGSETJMP
+/* Beware this is a global and unique instance. This is used to store the
+ return address that we can jump back to from inside a signal handler. This
+ is not thread-safe stuff. */
+sigjmp_buf curl_jmpenv;
+#endif
+
+
+/*
+ * Curl_cache_addr() stores a 'Curl_addrinfo' struct in the DNS cache.
+ *
+ * When calling Curl_resolv() has resulted in a response with a returned
+ * address, we call this function to store the information in the dns
+ * cache etc
+ *
+ * Returns the Curl_dns_entry entry pointer or NULL if the storage failed.
+ */
+struct Curl_dns_entry *
+Curl_cache_addr(struct SessionHandle *data,
+ Curl_addrinfo *addr,
+ const char *hostname,
+ int port)
+{
+ char *entry_id;
+ size_t entry_len;
+ struct Curl_dns_entry *dns;
+ struct Curl_dns_entry *dns2;
+ time_t now;
+
+ /* Create an entry id, based upon the hostname and port */
+ entry_id = create_hostcache_id(hostname, port);
+ /* If we can't create the entry id, fail */
+ if (!entry_id)
+ return NULL;
+ entry_len = strlen(entry_id);
+
+ /* Create a new cache entry */
+ dns = (struct Curl_dns_entry *) calloc(sizeof(struct Curl_dns_entry), 1);
+ if (!dns) {
+ free(entry_id);
+ return NULL;
+ }
+
+ dns->inuse = 0; /* init to not used */
+ dns->addr = addr; /* this is the address(es) */
+
+ /* Store the resolved data in our DNS cache. This function may return a
+ pointer to an existing struct already present in the hash, and it may
+ return the same argument we pass in. Make no assumptions. */
+ dns2 = Curl_hash_add(data->dns.hostcache, entry_id, entry_len+1,
+ (void *)dns);
+ if(!dns2) {
+ /* Major badness, run away. */
+ free(dns);
+ free(entry_id);
+ return NULL;
+ }
+ time(&now);
+ dns = dns2;
+
+ dns->timestamp = now; /* used now */
+ dns->inuse++; /* mark entry as in-use */
+
+ /* free the allocated entry_id again */
+ free(entry_id);
+
+ return dns;
+}
+
+/*
+ * Curl_resolv() is the main name resolve function within libcurl. It resolves
+ * a name and returns a pointer to the entry in the 'entry' argument (if one
+ * is provided). This function might return immediately if we're using asynch
+ * resolves. See the return codes.
+ *
+ * The cache entry we return will get its 'inuse' counter increased when this
+ * function is used. You MUST call Curl_resolv_unlock() later (when you're
+ * done using this struct) to decrease the counter again.
+ *
+ * Return codes:
+ *
+ * CURLRESOLV_ERROR (-1) = error, no pointer
+ * CURLRESOLV_RESOLVED (0) = OK, pointer provided
+ * CURLRESOLV_PENDING (1) = waiting for response, no pointer
+ */
+
+int Curl_resolv(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ struct Curl_dns_entry **entry)
+{
+ char *entry_id = NULL;
+ struct Curl_dns_entry *dns = NULL;
+ size_t entry_len;
+ int wait;
+ struct SessionHandle *data = conn->data;
+ CURLcode result;
+ int rc;
+ *entry = NULL;
+
+#ifdef HAVE_SIGSETJMP
+ /* this allows us to time-out from the name resolver, as the timeout
+ will generate a signal and we will siglongjmp() from that here */
+ if(!data->set.no_signal) {
+ if (sigsetjmp(curl_jmpenv, 1)) {
+ /* this is coming from a siglongjmp() */
+ failf(data, "name lookup timed out");
+ return CURLRESOLV_ERROR;
+ }
+ }
+#endif
+
+ /* Create an entry id, based upon the hostname and port */
+ entry_id = create_hostcache_id(hostname, port);
+ /* If we can't create the entry id, fail */
+ if (!entry_id)
+ return CURLRESOLV_ERROR;
+
+ entry_len = strlen(entry_id);
+
+ if(data->share)
+ Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
+
+ /* See if its already in our dns cache */
+ dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len+1);
+
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+
+ /* free the allocated entry_id again */
+ free(entry_id);
+
+ /* See whether the returned entry is stale. Deliberately done after the
+ locked block */
+ if ( remove_entry_if_stale(data,dns) )
+ dns = NULL; /* the memory deallocation is being handled by the hash */
+
+ rc = CURLRESOLV_ERROR; /* default to failure */
+
+ if (!dns) {
+ /* The entry was not in the cache. Resolve it to IP address */
+
+ Curl_addrinfo *addr;
+
+ /* Check what IP specifics the app has requested and if we can provide it.
+ * If not, bail out. */
+ if(!Curl_ipvalid(data))
+ return CURLRESOLV_ERROR;
+
+ /* If Curl_getaddrinfo() returns NULL, 'wait' might be set to a non-zero
+ value indicating that we need to wait for the response to the resolve
+ call */
+ addr = Curl_getaddrinfo(conn, hostname, port, &wait);
+
+ if (!addr) {
+ if(wait) {
+ /* the response to our resolve call will come asynchronously at
+ a later time, good or bad */
+ /* First, check that we haven't received the info by now */
+ result = Curl_is_resolved(conn, &dns);
+ if(result) /* error detected */
+ return CURLRESOLV_ERROR;
+ if(dns)
+ rc = CURLRESOLV_RESOLVED; /* pointer provided */
+ else
+ rc = CURLRESOLV_PENDING; /* no info yet */
+ }
+ }
+ else {
+ if(data->share)
+ Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
+
+ /* we got a response, store it in the cache */
+ dns = Curl_cache_addr(data, addr, hostname, port);
+
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+
+ if(!dns)
+ /* returned failure, bail out nicely */
+ Curl_freeaddrinfo(addr);
+ else
+ rc = CURLRESOLV_RESOLVED;
+ }
+ }
+ else {
+ if(data->share)
+ Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
+ dns->inuse++; /* we use it! */
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+ rc = CURLRESOLV_RESOLVED;
+ }
+
+ *entry = dns;
+
+ return rc;
+}
+
+/*
+ * Curl_resolv_unlock() unlocks the given cached DNS entry. When this has been
+ * made, the struct may be destroyed due to pruning. It is important that only
+ * one unlock is made for each Curl_resolv() call.
+ */
+void Curl_resolv_unlock(struct SessionHandle *data, struct Curl_dns_entry *dns)
+{
+ curlassert(dns && (dns->inuse>0));
+
+ if(data->share)
+ Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
+
+ dns->inuse--;
+
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+}
+
+/*
+ * File-internal: free a cache dns entry.
+ */
+static void freednsentry(void *freethis)
+{
+ struct Curl_dns_entry *p = (struct Curl_dns_entry *) freethis;
+
+ Curl_freeaddrinfo(p->addr);
+
+ free(p);
+}
+
+/*
+ * Curl_mk_dnscache() creates a new DNS cache and returns the handle for it.
+ */
+struct curl_hash *Curl_mk_dnscache(void)
+{
+ return Curl_hash_alloc(7, freednsentry);
+}
+
+#ifdef CURLRES_ADDRINFO_COPY
+
+/* align on even 64bit boundaries */
+#define MEMALIGN(x) ((x)+(8-(((unsigned long)(x))&0x7)))
+
+/*
+ * Curl_addrinfo_copy() performs a "deep" copy of a hostent into a buffer and
+ * returns a pointer to the malloc()ed copy. You need to call free() on the
+ * returned buffer when you're done with it.
+ */
+Curl_addrinfo *Curl_addrinfo_copy(const void *org, int port)
+{
+ const struct hostent *orig = org;
+
+ return Curl_he2ai(orig, port);
+}
+#endif /* CURLRES_ADDRINFO_COPY */
+
+/***********************************************************************
+ * Only for plain-ipv4 and c-ares builds
+ **********************************************************************/
+
+#if defined(CURLRES_IPV4) || defined(CURLRES_ARES)
+/*
+ * This is a function for freeing name information in a protocol independent
+ * way.
+ */
+void Curl_freeaddrinfo(Curl_addrinfo *ai)
+{
+ Curl_addrinfo *next;
+
+ /* walk over the list and free all entries */
+ while(ai) {
+ next = ai->ai_next;
+ free(ai);
+ ai = next;
+ }
+}
+
+struct namebuf {
+ struct hostent hostentry;
+ char *h_addr_list[2];
+ struct in_addr addrentry;
+ char h_name[16]; /* 123.123.123.123 = 15 letters is maximum */
+};
+
+/*
+ * Curl_ip2addr() takes a 32bit ipv4 internet address as input parameter
+ * together with a pointer to the string version of the address, and it
+ * returns a Curl_addrinfo chain filled in correctly with information for this
+ * address/host.
+ *
+ * The input parameters ARE NOT checked for validity but they are expected
+ * to have been checked already when this is called.
+ */
+Curl_addrinfo *Curl_ip2addr(in_addr_t num, const char *hostname, int port)
+{
+ Curl_addrinfo *ai;
+ struct hostent *h;
+ struct in_addr *addrentry;
+ struct namebuf buffer;
+ struct namebuf *buf = &buffer;
+
+ h = &buf->hostentry;
+ h->h_addr_list = &buf->h_addr_list[0];
+ addrentry = &buf->addrentry;
+#ifdef _CRAY
+ /* On UNICOS, s_addr is a bit field and for some reason assigning to it
+ * doesn't work. There must be a better fix than this ugly hack.
+ */
+ memcpy(addrentry, &num, SIZEOF_in_addr);
+#else
+ addrentry->s_addr = num;
+#endif
+ h->h_addr_list[0] = (char*)addrentry;
+ h->h_addr_list[1] = NULL;
+ h->h_addrtype = AF_INET;
+ h->h_length = sizeof(*addrentry);
+ h->h_name = &buf->h_name[0];
+ h->h_aliases = NULL;
+
+ /* Now store the dotted version of the address */
+ snprintf((char *)h->h_name, 16, "%s", hostname);
+
+ ai = Curl_he2ai(h, port);
+
+ return ai;
+}
+#endif
+
+
diff --git a/Utilities/cmcurl/hostip.h b/Utilities/cmcurl/hostip.h
new file mode 100644
index 0000000000..e6d63ca710
--- /dev/null
+++ b/Utilities/cmcurl/hostip.h
@@ -0,0 +1,271 @@
+#ifndef __HOSTIP_H
+#define __HOSTIP_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+#include "hash.h"
+
+#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
+#undef in_addr_t
+#define in_addr_t uint32_t
+#endif
+
+/*
+ * Setup comfortable CURLRES_* defines to use in the host*.c sources.
+ */
+
+#ifdef USE_ARES
+#define CURLRES_ASYNCH
+#define CURLRES_ARES
+#endif
+
+#ifdef USE_THREADING_GETHOSTBYNAME
+#define CURLRES_ASYNCH
+#define CURLRES_THREADED
+#endif
+
+#ifdef USE_THREADING_GETADDRINFO
+#define CURLRES_ASYNCH
+#define CURLRES_THREADED
+#endif
+
+#ifdef ENABLE_IPV6
+#define CURLRES_IPV6
+#else
+#define CURLRES_IPV4
+#endif
+
+#if defined(CURLRES_IPV4) || defined(CURLRES_ARES)
+#if !defined(HAVE_GETHOSTBYNAME_R) || defined(CURLRES_ASYNCH)
+/* If built for ipv4 and missing gethostbyname_r(), or if using async name
+ resolve, we need the Curl_addrinfo_copy() function (which itself needs the
+ Curl_he2ai() function)) */
+#define CURLRES_ADDRINFO_COPY
+#endif
+#endif /* IPv4/ares-only */
+
+#ifndef CURLRES_ASYNCH
+#define CURLRES_SYNCH
+#endif
+
+#ifndef USE_LIBIDN
+#define CURLRES_IDN
+#endif
+
+/* Allocate enough memory to hold the full name information structs and
+ * everything. OSF1 is known to require at least 8872 bytes. The buffer
+ * required for storing all possible aliases and IP numbers is according to
+ * Stevens' Unix Network Programming 2nd edition, p. 304: 8192 bytes!
+ */
+#define CURL_HOSTENT_SIZE 9000
+
+#define CURL_TIMEOUT_RESOLVE 300 /* when using asynch methods, we allow this
+ many seconds for a name resolve */
+
+#ifdef CURLRES_ARES
+#define CURL_ASYNC_SUCCESS ARES_SUCCESS
+#else
+#define CURL_ASYNC_SUCCESS CURLE_OK
+#define ares_cancel(x) do {} while(0)
+#define ares_destroy(x) do {} while(0)
+#endif
+
+/*
+ * Curl_addrinfo MUST be used for all name resolved info.
+ */
+#ifdef CURLRES_IPV6
+typedef struct addrinfo Curl_addrinfo;
+#else
+/* OK, so some ipv4-only include tree probably have the addrinfo struct, but
+ to work even on those that don't, we provide our own look-alike! */
+struct Curl_addrinfo {
+ int ai_flags;
+ int ai_family;
+ int ai_socktype;
+ int ai_protocol;
+ socklen_t ai_addrlen; /* Follow rfc3493 struct addrinfo */
+ char *ai_canonname;
+ struct sockaddr *ai_addr;
+ struct Curl_addrinfo *ai_next;
+};
+typedef struct Curl_addrinfo Curl_addrinfo;
+#endif
+
+struct addrinfo;
+struct hostent;
+struct SessionHandle;
+struct connectdata;
+
+void Curl_global_host_cache_init(void);
+void Curl_global_host_cache_dtor(void);
+struct curl_hash *Curl_global_host_cache_get(void);
+
+#define Curl_global_host_cache_use(__p) ((__p)->set.global_dns_cache)
+
+struct Curl_dns_entry {
+ Curl_addrinfo *addr;
+ time_t timestamp;
+ long inuse; /* use-counter, make very sure you decrease this
+ when you're done using the address you received */
+};
+
+/*
+ * Curl_resolv() returns an entry with the info for the specified host
+ * and port.
+ *
+ * The returned data *MUST* be "unlocked" with Curl_resolv_unlock() after
+ * use, or we'll leak memory!
+ */
+/* return codes */
+#define CURLRESOLV_ERROR -1
+#define CURLRESOLV_RESOLVED 0
+#define CURLRESOLV_PENDING 1
+int Curl_resolv(struct connectdata *conn, const char *hostname,
+ int port, struct Curl_dns_entry **dnsentry);
+
+/*
+ * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
+ * been set and returns TRUE if they are OK.
+ */
+bool Curl_ipvalid(struct SessionHandle *data);
+
+/*
+ * Curl_getaddrinfo() is the generic low-level name resolve API within this
+ * source file. There are several versions of this function - for different
+ * name resolve layers (selected at build-time). They all take this same set
+ * of arguments
+ */
+Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ int *waitp);
+
+CURLcode Curl_is_resolved(struct connectdata *conn,
+ struct Curl_dns_entry **dns);
+CURLcode Curl_wait_for_resolv(struct connectdata *conn,
+ struct Curl_dns_entry **dnsentry);
+
+/* Curl_resolv_getsock() is a generic function that exists in multiple
+ versions depending on what name resolve technology we've built to use. The
+ function is called from the multi_getsock() function. 'sock' is a pointer
+ to an array to hold the file descriptors, with 'numsock' being the size of
+ that array (in number of entries). This function is supposed to return
+ bitmask indicating what file descriptors (referring to array indexes in the
+ 'sock' array) to wait for, read/write. */
+int Curl_resolv_getsock(struct connectdata *conn, curl_socket_t *sock,
+ int numsocks);
+
+/* unlock a previously resolved dns entry */
+void Curl_resolv_unlock(struct SessionHandle *data,
+ struct Curl_dns_entry *dns);
+
+/* for debugging purposes only: */
+void Curl_scan_cache_used(void *user, void *ptr);
+
+/* free name info */
+void Curl_freeaddrinfo(Curl_addrinfo *freeaddr);
+
+/* make a new dns cache and return the handle */
+struct curl_hash *Curl_mk_dnscache(void);
+
+/* prune old entries from the DNS cache */
+void Curl_hostcache_prune(struct SessionHandle *data);
+
+/* Return # of adresses in a Curl_addrinfo struct */
+int Curl_num_addresses (const Curl_addrinfo *addr);
+
+#ifdef CURLDEBUG
+void curl_dofreeaddrinfo(struct addrinfo *freethis,
+ int line, const char *source);
+int curl_dogetaddrinfo(const char *hostname, const char *service,
+ struct addrinfo *hints,
+ struct addrinfo **result,
+ int line, const char *source);
+#ifdef HAVE_GETNAMEINFO
+int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
+ GETNAMEINFO_TYPE_ARG2 salen,
+ char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
+ char *serv, GETNAMEINFO_TYPE_ARG46 servlen,
+ GETNAMEINFO_TYPE_ARG7 flags,
+ int line, const char *source);
+#endif
+#endif
+
+/* This is the callback function that is used when we build with asynch
+ resolve, ipv4 */
+CURLcode Curl_addrinfo4_callback(void *arg,
+ int status,
+ struct hostent *hostent);
+/* This is the callback function that is used when we build with asynch
+ resolve, ipv6 */
+CURLcode Curl_addrinfo6_callback(void *arg,
+ int status,
+ struct addrinfo *ai);
+
+
+/* [ipv4/ares only] Creates a Curl_addrinfo struct from a numerical-only IP
+ address */
+Curl_addrinfo *Curl_ip2addr(in_addr_t num, const char *hostname, int port);
+
+/* [ipv4/ares only] Curl_he2ai() converts a struct hostent to a Curl_addrinfo chain
+ and returns it */
+Curl_addrinfo *Curl_he2ai(const struct hostent *, int port);
+
+/* Clone a Curl_addrinfo struct, works protocol independently */
+Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port);
+
+/*
+ * Curl_printable_address() returns a printable version of the 1st address
+ * given in the 'ip' argument. The result will be stored in the buf that is
+ * bufsize bytes big.
+ */
+const char *Curl_printable_address(const Curl_addrinfo *ip,
+ char *buf, size_t bufsize);
+
+/*
+ * Curl_cache_addr() stores a 'Curl_addrinfo' struct in the DNS cache.
+ *
+ * Returns the Curl_dns_entry entry pointer or NULL if the storage failed.
+ */
+struct Curl_dns_entry *
+Curl_cache_addr(struct SessionHandle *data, Curl_addrinfo *addr,
+ const char *hostname, int port);
+
+/*
+ * Curl_destroy_thread_data() cleans up async resolver data.
+ * Complementary of ares_destroy.
+ */
+struct Curl_async; /* forward-declaration */
+void Curl_destroy_thread_data(struct Curl_async *async);
+
+#ifndef INADDR_NONE
+#define CURL_INADDR_NONE (in_addr_t) ~0
+#else
+#define CURL_INADDR_NONE INADDR_NONE
+#endif
+
+
+
+
+#endif
diff --git a/Utilities/cmcurl/hostip4.c b/Utilities/cmcurl/hostip4.c
new file mode 100644
index 0000000000..877baa2ca1
--- /dev/null
+++ b/Utilities/cmcurl/hostip4.c
@@ -0,0 +1,389 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+#include <errno.h>
+
+#ifdef NEED_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* required for free() prototypes */
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for the close() proto */
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_SETJMP_H
+#include <setjmp.h>
+#endif
+
+#ifdef HAVE_PROCESS_H
+#include <process.h>
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "hostip.h"
+#include "hash.h"
+#include "share.h"
+#include "strerror.h"
+#include "url.h"
+#include "inet_pton.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/***********************************************************************
+ * Only for plain-ipv4 builds
+ **********************************************************************/
+#ifdef CURLRES_IPV4 /* plain ipv4 code coming up */
+/*
+ * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
+ * been set and returns TRUE if they are OK.
+ */
+bool Curl_ipvalid(struct SessionHandle *data)
+{
+ if(data->set.ip_version == CURL_IPRESOLVE_V6)
+ /* an ipv6 address was requested and we can't get/use one */
+ return FALSE;
+
+ return TRUE; /* OK, proceed */
+}
+
+#ifdef CURLRES_SYNCH /* the functions below are for synchronous resolves */
+
+/*
+ * Curl_getaddrinfo() - the ipv4 synchronous version.
+ *
+ * The original code to this function was from the Dancer source code, written
+ * by Bjorn Reese, it has since been patched and modified considerably.
+ *
+ * gethostbyname_r() is the thread-safe version of the gethostbyname()
+ * function. When we build for plain IPv4, we attempt to use this
+ * function. There are _three_ different gethostbyname_r() versions, and we
+ * detect which one this platform supports in the configure script and set up
+ * the HAVE_GETHOSTBYNAME_R_3, HAVE_GETHOSTBYNAME_R_5 or
+ * HAVE_GETHOSTBYNAME_R_6 defines accordingly. Note that HAVE_GETADDRBYNAME
+ * has the corresponding rules. This is primarily on *nix. Note that some unix
+ * flavours have thread-safe versions of the plain gethostbyname() etc.
+ *
+ */
+Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ int *waitp)
+{
+ Curl_addrinfo *ai = NULL;
+ struct hostent *h = NULL;
+ in_addr_t in;
+ struct SessionHandle *data = conn->data;
+ struct hostent *buf = NULL;
+
+ (void)port; /* unused in IPv4 code */
+
+ *waitp = 0; /* don't wait, we act synchronously */
+
+ if(1 == Curl_inet_pton(AF_INET, hostname, &in))
+ /* This is a dotted IP address 123.123.123.123-style */
+ return Curl_ip2addr(in, hostname, port);
+
+#if defined(HAVE_GETHOSTBYNAME_R)
+ /*
+ * gethostbyname_r() is the preferred resolve function for many platforms.
+ * Since there are three different versions of it, the following code is
+ * somewhat #ifdef-ridden.
+ */
+ else {
+ int h_errnop;
+ int res=ERANGE;
+
+ buf = (struct hostent *)calloc(CURL_HOSTENT_SIZE, 1);
+ if(!buf)
+ return NULL; /* major failure */
+ /*
+ * The clearing of the buffer is a workaround for a gethostbyname_r bug in
+ * qnx nto and it is also _required_ for some of these functions on some
+ * platforms.
+ */
+
+#ifdef HAVE_GETHOSTBYNAME_R_5
+ /* Solaris, IRIX and more */
+ (void)res; /* prevent compiler warning */
+ h = gethostbyname_r(hostname,
+ (struct hostent *)buf,
+ (char *)buf + sizeof(struct hostent),
+ CURL_HOSTENT_SIZE - sizeof(struct hostent),
+ &h_errnop);
+
+ /* If the buffer is too small, it returns NULL and sets errno to
+ * ERANGE. The errno is thread safe if this is compiled with
+ * -D_REENTRANT as then the 'errno' variable is a macro defined to get
+ * used properly for threads.
+ */
+
+ if(h) {
+ ;
+ }
+ else
+#endif /* HAVE_GETHOSTBYNAME_R_5 */
+#ifdef HAVE_GETHOSTBYNAME_R_6
+ /* Linux */
+
+ res=gethostbyname_r(hostname,
+ (struct hostent *)buf,
+ (char *)buf + sizeof(struct hostent),
+ CURL_HOSTENT_SIZE - sizeof(struct hostent),
+ &h, /* DIFFERENCE */
+ &h_errnop);
+ /* Redhat 8, using glibc 2.2.93 changed the behavior. Now all of a
+ * sudden this function returns EAGAIN if the given buffer size is too
+ * small. Previous versions are known to return ERANGE for the same
+ * problem.
+ *
+ * This wouldn't be such a big problem if older versions wouldn't
+ * sometimes return EAGAIN on a common failure case. Alas, we can't
+ * assume that EAGAIN *or* ERANGE means ERANGE for any given version of
+ * glibc.
+ *
+ * For now, we do that and thus we may call the function repeatedly and
+ * fail for older glibc versions that return EAGAIN, until we run out of
+ * buffer size (step_size grows beyond CURL_HOSTENT_SIZE).
+ *
+ * If anyone has a better fix, please tell us!
+ *
+ * -------------------------------------------------------------------
+ *
+ * On October 23rd 2003, Dan C dug up more details on the mysteries of
+ * gethostbyname_r() in glibc:
+ *
+ * In glibc 2.2.5 the interface is different (this has also been
+ * discovered in glibc 2.1.1-6 as shipped by Redhat 6). What I can't
+ * explain, is that tests performed on glibc 2.2.4-34 and 2.2.4-32
+ * (shipped/upgraded by Redhat 7.2) don't show this behavior!
+ *
+ * In this "buggy" version, the return code is -1 on error and 'errno'
+ * is set to the ERANGE or EAGAIN code. Note that 'errno' is not a
+ * thread-safe variable.
+ */
+
+ if(!h) /* failure */
+#endif/* HAVE_GETHOSTBYNAME_R_6 */
+#ifdef HAVE_GETHOSTBYNAME_R_3
+ /* AIX, Digital Unix/Tru64, HPUX 10, more? */
+
+ /* For AIX 4.3 or later, we don't use gethostbyname_r() at all, because of
+ * the plain fact that it does not return unique full buffers on each
+ * call, but instead several of the pointers in the hostent structs will
+ * point to the same actual data! This have the unfortunate down-side that
+ * our caching system breaks down horribly. Luckily for us though, AIX 4.3
+ * and more recent versions have a "completely thread-safe"[*] libc where
+ * all the data is stored in thread-specific memory areas making calls to
+ * the plain old gethostbyname() work fine even for multi-threaded
+ * programs.
+ *
+ * This AIX 4.3 or later detection is all made in the configure script.
+ *
+ * Troels Walsted Hansen helped us work this out on March 3rd, 2003.
+ *
+ * [*] = much later we've found out that it isn't at all "completely
+ * thread-safe", but at least the gethostbyname() function is.
+ */
+
+ if(CURL_HOSTENT_SIZE >=
+ (sizeof(struct hostent)+sizeof(struct hostent_data))) {
+
+ /* August 22nd, 2000: Albert Chin-A-Young brought an updated version
+ * that should work! September 20: Richard Prescott worked on the buffer
+ * size dilemma.
+ */
+
+ res = gethostbyname_r(hostname,
+ (struct hostent *)buf,
+ (struct hostent_data *)((char *)buf +
+ sizeof(struct hostent)));
+ h_errnop= errno; /* we don't deal with this, but set it anyway */
+ }
+ else
+ res = -1; /* failure, too smallish buffer size */
+
+ if(!res) { /* success */
+
+ h = buf; /* result expected in h */
+
+ /* This is the worst kind of the different gethostbyname_r() interfaces.
+ * Since we don't know how big buffer this particular lookup required,
+ * we can't realloc down the huge alloc without doing closer analysis of
+ * the returned data. Thus, we always use CURL_HOSTENT_SIZE for every
+ * name lookup. Fixing this would require an extra malloc() and then
+ * calling Curl_addrinfo_copy() that subsequent realloc()s down the new
+ * memory area to the actually used amount.
+ */
+ }
+ else
+#endif /* HAVE_GETHOSTBYNAME_R_3 */
+ {
+ infof(data, "gethostbyname_r(2) failed for %s\n", hostname);
+ h = NULL; /* set return code to NULL */
+ free(buf);
+ }
+#else /* HAVE_GETHOSTBYNAME_R */
+ /*
+ * Here is code for platforms that don't have gethostbyname_r() or for
+ * which the gethostbyname() is the preferred() function.
+ */
+ else {
+ h = gethostbyname(hostname);
+ if (!h)
+ infof(data, "gethostbyname(2) failed for %s\n", hostname);
+#endif /*HAVE_GETHOSTBYNAME_R */
+ }
+
+ if(h) {
+ ai = Curl_he2ai(h, port);
+
+ if (buf) /* used a *_r() function */
+ free(buf);
+ }
+
+ return ai;
+}
+
+#endif /* CURLRES_SYNCH */
+#endif /* CURLRES_IPV4 */
+
+/*
+ * Curl_he2ai() translates from a hostent struct to a Curl_addrinfo struct.
+ * The Curl_addrinfo is meant to work like the addrinfo struct does for IPv6
+ * stacks, but for all hosts and environments.
+ *
+ * Curl_addrinfo defined in "lib/hostip.h"
+ *
+ * struct Curl_addrinfo {
+ * int ai_flags;
+ * int ai_family;
+ * int ai_socktype;
+ * int ai_protocol;
+ * socklen_t ai_addrlen; * Follow rfc3493 struct addrinfo *
+ * char *ai_canonname;
+ * struct sockaddr *ai_addr;
+ * struct Curl_addrinfo *ai_next;
+ * };
+ *
+ * hostent defined in <netdb.h>
+ *
+ * struct hostent {
+ * char *h_name;
+ * char **h_aliases;
+ * int h_addrtype;
+ * int h_length;
+ * char **h_addr_list;
+ * };
+ *
+ * for backward compatibility:
+ *
+ * #define h_addr h_addr_list[0]
+ */
+
+Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port)
+{
+ Curl_addrinfo *ai;
+ Curl_addrinfo *prevai = NULL;
+ Curl_addrinfo *firstai = NULL;
+ struct sockaddr_in *addr;
+ int i;
+ struct in_addr *curr;
+
+ if(!he)
+ /* no input == no output! */
+ return NULL;
+
+ for(i=0; (curr = (struct in_addr *)he->h_addr_list[i]) != NULL; i++) {
+
+ ai = calloc(1, sizeof(Curl_addrinfo) + sizeof(struct sockaddr_in));
+
+ if(!ai)
+ break;
+
+ if(!firstai)
+ /* store the pointer we want to return from this function */
+ firstai = ai;
+
+ if(prevai)
+ /* make the previous entry point to this */
+ prevai->ai_next = ai;
+
+ ai->ai_family = AF_INET; /* we only support this */
+
+ /* we return all names as STREAM, so when using this address for TFTP
+ the type must be ignored and conn->socktype be used instead! */
+ ai->ai_socktype = SOCK_STREAM;
+
+ ai->ai_addrlen = sizeof(struct sockaddr_in);
+ /* make the ai_addr point to the address immediately following this struct
+ and use that area to store the address */
+ ai->ai_addr = (struct sockaddr *) ((char*)ai + sizeof(Curl_addrinfo));
+
+ /* leave the rest of the struct filled with zero */
+
+ addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */
+
+ memcpy((char *)&(addr->sin_addr), curr, sizeof(struct in_addr));
+ addr->sin_family = he->h_addrtype;
+ addr->sin_port = htons((unsigned short)port);
+
+ prevai = ai;
+ }
+ return firstai;
+}
+
diff --git a/Utilities/cmcurl/hostip6.c b/Utilities/cmcurl/hostip6.c
new file mode 100644
index 0000000000..c8bbdb5e93
--- /dev/null
+++ b/Utilities/cmcurl/hostip6.c
@@ -0,0 +1,306 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+
+#ifdef NEED_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* required for free() prototypes */
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for the close() proto */
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_SETJMP_H
+#include <setjmp.h>
+#endif
+
+#ifdef HAVE_PROCESS_H
+#include <process.h>
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "hostip.h"
+#include "hash.h"
+#include "share.h"
+#include "strerror.h"
+#include "url.h"
+#include "inet_pton.h"
+#include "connect.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/***********************************************************************
+ * Only for ipv6-enabled builds
+ **********************************************************************/
+#ifdef CURLRES_IPV6
+#ifndef CURLRES_ARES
+/*
+ * This is a wrapper function for freeing name information in a protocol
+ * independent way. This takes care of using the appropriate underlaying
+ * function.
+ */
+void Curl_freeaddrinfo(Curl_addrinfo *p)
+{
+ freeaddrinfo(p);
+}
+
+#ifdef CURLRES_ASYNCH
+/*
+ * Curl_addrinfo_copy() is used by the asynch callback to copy a given
+ * address. But this is an ipv6 build and then we don't copy the address, we
+ * just return the same pointer!
+ */
+Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port)
+{
+ (void) port;
+ return (Curl_addrinfo*)orig;
+}
+#endif /* CURLRES_ASYNCH */
+#endif /* CURLRES_ARES */
+
+#ifdef CURLDEBUG
+/* These are strictly for memory tracing and are using the same style as the
+ * family otherwise present in memdebug.c. I put these ones here since they
+ * require a bunch of structs I didn't wanna include in memdebug.c
+ */
+int curl_dogetaddrinfo(const char *hostname, const char *service,
+ struct addrinfo *hints,
+ struct addrinfo **result,
+ int line, const char *source)
+{
+ int res=(getaddrinfo)(hostname, service, hints, result);
+ if(0 == res) {
+ /* success */
+ if(logfile)
+ fprintf(logfile, "ADDR %s:%d getaddrinfo() = %p\n",
+ source, line, (void *)*result);
+ }
+ else {
+ if(logfile)
+ fprintf(logfile, "ADDR %s:%d getaddrinfo() failed\n",
+ source, line);
+ }
+ return res;
+}
+
+/*
+ * For CURLRES_ARS, this should be written using ares_gethostbyaddr()
+ * (ignoring the fact c-ares doesn't return 'serv').
+ */
+#ifdef HAVE_GETNAMEINFO
+int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
+ GETNAMEINFO_TYPE_ARG2 salen,
+ char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
+ char *serv, GETNAMEINFO_TYPE_ARG46 servlen,
+ GETNAMEINFO_TYPE_ARG7 flags,
+ int line, const char *source)
+{
+ int res = (getnameinfo)(sa, salen,
+ host, hostlen,
+ serv, servlen,
+ flags);
+ if(0 == res) {
+ /* success */
+ if(logfile)
+ fprintf(logfile, "GETNAME %s:%d getnameinfo()\n",
+ source, line);
+ }
+ else {
+ if(logfile)
+ fprintf(logfile, "GETNAME %s:%d getnameinfo() failed = %d\n",
+ source, line, res);
+ }
+ return res;
+}
+#endif
+
+void curl_dofreeaddrinfo(struct addrinfo *freethis,
+ int line, const char *source)
+{
+ (freeaddrinfo)(freethis);
+ if(logfile)
+ fprintf(logfile, "ADDR %s:%d freeaddrinfo(%p)\n",
+ source, line, (void *)freethis);
+}
+#endif /* CURLDEBUG */
+
+/*
+ * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
+ * been set and returns TRUE if they are OK.
+ */
+bool Curl_ipvalid(struct SessionHandle *data)
+{
+ if(data->set.ip_version == CURL_IPRESOLVE_V6) {
+ /* see if we have an IPv6 stack */
+ curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
+ if (s == CURL_SOCKET_BAD)
+ /* an ipv6 address was requested and we can't get/use one */
+ return FALSE;
+ sclose(s);
+ }
+ return TRUE;
+}
+
+#if !defined(USE_THREADING_GETADDRINFO) && !defined(CURLRES_ARES)
+
+#ifdef DEBUG_ADDRINFO
+static void dump_addrinfo(struct connectdata *conn, const struct addrinfo *ai)
+{
+ printf("dump_addrinfo:\n");
+ for ( ; ai; ai = ai->ai_next) {
+ char buf[INET6_ADDRSTRLEN];
+
+ printf(" fam %2d, CNAME %s, ",
+ ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
+ if (Curl_printable_address(ai, buf, sizeof(buf)))
+ printf("%s\n", buf);
+ else
+ printf("failed; %s\n", Curl_strerror(conn, Curl_sockerrno()));
+ }
+}
+#else
+#define dump_addrinfo(x,y)
+#endif
+
+/*
+ * Curl_getaddrinfo() when built ipv6-enabled (non-threading and
+ * non-ares version).
+ *
+ * Returns name information about the given hostname and port number. If
+ * successful, the 'addrinfo' is returned and the forth argument will point to
+ * memory we need to free after use. That memory *MUST* be freed with
+ * Curl_freeaddrinfo(), nothing else.
+ */
+Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ int *waitp)
+{
+ struct addrinfo hints, *res;
+ int error;
+ char sbuf[NI_MAXSERV];
+ char *sbufptr = NULL;
+ char addrbuf[128];
+ curl_socket_t s;
+ int pf;
+ struct SessionHandle *data = conn->data;
+
+ *waitp=0; /* don't wait, we have the response now */
+
+ /* see if we have an IPv6 stack */
+ s = socket(PF_INET6, SOCK_DGRAM, 0);
+ if (s == CURL_SOCKET_BAD) {
+ /* Some non-IPv6 stacks have been found to make very slow name resolves
+ * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
+ * the stack seems to be a non-ipv6 one. */
+
+ pf = PF_INET;
+ }
+ else {
+ /* This seems to be an IPv6-capable stack, use PF_UNSPEC for the widest
+ * possible checks. And close the socket again.
+ */
+ sclose(s);
+
+ /*
+ * Check if a more limited name resolve has been requested.
+ */
+ switch(data->set.ip_version) {
+ case CURL_IPRESOLVE_V4:
+ pf = PF_INET;
+ break;
+ case CURL_IPRESOLVE_V6:
+ pf = PF_INET6;
+ break;
+ default:
+ pf = PF_UNSPEC;
+ break;
+ }
+ }
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = pf;
+ hints.ai_socktype = conn->socktype;
+
+ if((1 == Curl_inet_pton(AF_INET, hostname, addrbuf)) ||
+ (1 == Curl_inet_pton(AF_INET6, hostname, addrbuf))) {
+ /* the given address is numerical only, prevent a reverse lookup */
+ hints.ai_flags = AI_NUMERICHOST;
+ }
+#if 0 /* removed nov 8 2005 before 7.15.1 */
+ else
+ hints.ai_flags = AI_CANONNAME;
+#endif
+
+ if(port) {
+ snprintf(sbuf, sizeof(sbuf), "%d", port);
+ sbufptr=sbuf;
+ }
+ error = getaddrinfo(hostname, sbufptr, &hints, &res);
+ if (error) {
+ infof(data, "getaddrinfo(3) failed for %s:%d\n", hostname, port);
+ return NULL;
+ }
+
+ dump_addrinfo(conn, res);
+
+ return res;
+}
+#endif /* !USE_THREADING_GETADDRINFO && !CURLRES_ARES */
+#endif /* ipv6 */
+
diff --git a/Utilities/cmcurl/hostsyn.c b/Utilities/cmcurl/hostsyn.c
new file mode 100644
index 0000000000..2f816b8583
--- /dev/null
+++ b/Utilities/cmcurl/hostsyn.c
@@ -0,0 +1,138 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+
+#ifdef NEED_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* required for free() prototypes */
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for the close() proto */
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_SETJMP_H
+#include <setjmp.h>
+#endif
+
+#ifdef HAVE_PROCESS_H
+#include <process.h>
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "hostip.h"
+#include "hash.h"
+#include "share.h"
+#include "strerror.h"
+#include "url.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/***********************************************************************
+ * Only for builds using synchronous name resolves
+ **********************************************************************/
+#ifdef CURLRES_SYNCH
+
+/*
+ * Curl_wait_for_resolv() for synch-builds. Curl_resolv() can never return
+ * wait==TRUE, so this function will never be called. If it still gets called,
+ * we return failure at once.
+ *
+ * We provide this function only to allow multi.c to remain unaware if we are
+ * doing asynch resolves or not.
+ */
+CURLcode Curl_wait_for_resolv(struct connectdata *conn,
+ struct Curl_dns_entry **entry)
+{
+ (void)conn;
+ *entry=NULL;
+ return CURLE_COULDNT_RESOLVE_HOST;
+}
+
+/*
+ * This function will never be called when synch-built. If it still gets
+ * called, we return failure at once.
+ *
+ * We provide this function only to allow multi.c to remain unaware if we are
+ * doing asynch resolves or not.
+ */
+CURLcode Curl_is_resolved(struct connectdata *conn,
+ struct Curl_dns_entry **dns)
+{
+ (void)conn;
+ *dns = NULL;
+
+ return CURLE_COULDNT_RESOLVE_HOST;
+}
+
+/*
+ * We just return OK, this function is never actually used for synch builds.
+ * It is present here to keep #ifdefs out from multi.c
+ */
+
+int Curl_resolv_getsock(struct connectdata *conn,
+ curl_socket_t *sock,
+ int numsocks)
+{
+ (void)conn;
+ (void)sock;
+ (void)numsocks;
+
+ return 0; /* no bits since we don't use any socks */
+}
+
+#endif /* truly sync */
diff --git a/Utilities/cmcurl/hostthre.c b/Utilities/cmcurl/hostthre.c
new file mode 100644
index 0000000000..12e31ea342
--- /dev/null
+++ b/Utilities/cmcurl/hostthre.c
@@ -0,0 +1,840 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+#include <errno.h>
+
+#ifdef NEED_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* required for free() prototypes */
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for the close() proto */
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_SETJMP_H
+#include <setjmp.h>
+#endif
+
+#ifdef HAVE_PROCESS_H
+#include <process.h>
+#endif
+
+#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
+#undef in_addr_t
+#define in_addr_t unsigned long
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "hostip.h"
+#include "hash.h"
+#include "share.h"
+#include "strerror.h"
+#include "url.h"
+#include "multiif.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#include "inet_ntop.h"
+
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#if defined(_MSC_VER) && defined(CURL_NO__BEGINTHREADEX)
+#pragma message ("No _beginthreadex() available in this RTL")
+#endif
+
+/***********************************************************************
+ * Only for Windows threaded name resolves builds
+ **********************************************************************/
+#ifdef CURLRES_THREADED
+
+/* This function is used to init a threaded resolve */
+static bool init_resolve_thread(struct connectdata *conn,
+ const char *hostname, int port,
+ const Curl_addrinfo *hints);
+
+#ifdef CURLRES_IPV4
+ #define THREAD_FUNC gethostbyname_thread
+ #define THREAD_NAME "gethostbyname_thread"
+#else
+ #define THREAD_FUNC getaddrinfo_thread
+ #define THREAD_NAME "getaddrinfo_thread"
+#endif
+
+#if defined(DEBUG_THREADING_GETHOSTBYNAME) || \
+ defined(DEBUG_THREADING_GETADDRINFO)
+/* If this is defined, provide tracing */
+#define TRACE(args) \
+ do { trace_it("%u: ", __LINE__); trace_it args; } while (0)
+
+static void trace_it (const char *fmt, ...)
+{
+ static int do_trace = -1;
+ va_list args;
+
+ if (do_trace == -1) {
+ const char *env = getenv("CURL_TRACE");
+ do_trace = (env && atoi(env) > 0);
+ }
+ if (!do_trace)
+ return;
+ va_start (args, fmt);
+ vfprintf (stderr, fmt, args);
+ fflush (stderr);
+ va_end (args);
+}
+#else
+#define TRACE(x)
+#endif
+
+#ifdef DEBUG_THREADING_GETADDRINFO
+static void dump_addrinfo (struct connectdata *conn, const struct addrinfo *ai)
+{
+ TRACE(("dump_addrinfo:\n"));
+ for ( ; ai; ai = ai->ai_next) {
+ char buf [INET6_ADDRSTRLEN];
+
+ trace_it(" fam %2d, CNAME %s, ",
+ ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
+ if (Curl_printable_address(ai, buf, sizeof(buf)))
+ trace_it("%s\n", buf);
+ else
+ trace_it("failed; %s\n", Curl_strerror(conn,WSAGetLastError()));
+ }
+}
+#endif
+
+struct thread_data {
+ HANDLE thread_hnd;
+ unsigned thread_id;
+ DWORD thread_status;
+ curl_socket_t dummy_sock; /* dummy for Curl_resolv_fdset() */
+ HANDLE mutex_waiting; /* marks that we are still waiting for a resolve */
+ HANDLE event_resolved; /* marks that the thread obtained the information */
+ HANDLE event_thread_started; /* marks that the thread has initialized and
+ started */
+ HANDLE mutex_terminate; /* serializes access to flag_terminate */
+ HANDLE event_terminate; /* flag for thread to terminate instead of calling
+ callbacks */
+#ifdef CURLRES_IPV6
+ struct addrinfo hints;
+#endif
+};
+
+/* Data for synchronization between resolver thread and its parent */
+struct thread_sync_data {
+ HANDLE mutex_waiting; /* thread_data.mutex_waiting duplicate */
+ HANDLE mutex_terminate; /* thread_data.mutex_terminate duplicate */
+ HANDLE event_terminate; /* thread_data.event_terminate duplicate */
+ char * hostname; /* hostname to resolve, Curl_async.hostname
+ duplicate */
+};
+
+/* Destroy resolver thread synchronization data */
+static
+void destroy_thread_sync_data(struct thread_sync_data * tsd)
+{
+ if (tsd->hostname) {
+ free(tsd->hostname);
+ tsd->hostname = NULL;
+ }
+ if (tsd->event_terminate) {
+ CloseHandle(tsd->event_terminate);
+ tsd->event_terminate = NULL;
+ }
+ if (tsd->mutex_terminate) {
+ CloseHandle(tsd->mutex_terminate);
+ tsd->mutex_terminate = NULL;
+ }
+ if (tsd->mutex_waiting) {
+ CloseHandle(tsd->mutex_waiting);
+ tsd->mutex_waiting = NULL;
+ }
+}
+
+/* Initialize resolver thread synchronization data */
+static
+BOOL init_thread_sync_data(struct thread_data * td,
+ char * hostname,
+ struct thread_sync_data * tsd)
+{
+ HANDLE curr_proc = GetCurrentProcess();
+
+ memset(tsd, 0, sizeof(*tsd));
+ if (!DuplicateHandle(curr_proc, td->mutex_waiting,
+ curr_proc, &tsd->mutex_waiting, 0, FALSE,
+ DUPLICATE_SAME_ACCESS)) {
+ /* failed to duplicate the mutex, no point in continuing */
+ destroy_thread_sync_data(tsd);
+ return FALSE;
+ }
+ if (!DuplicateHandle(curr_proc, td->mutex_terminate,
+ curr_proc, &tsd->mutex_terminate, 0, FALSE,
+ DUPLICATE_SAME_ACCESS)) {
+ /* failed to duplicate the mutex, no point in continuing */
+ destroy_thread_sync_data(tsd);
+ return FALSE;
+ }
+ if (!DuplicateHandle(curr_proc, td->event_terminate,
+ curr_proc, &tsd->event_terminate, 0, FALSE,
+ DUPLICATE_SAME_ACCESS)) {
+ /* failed to duplicate the event, no point in continuing */
+ destroy_thread_sync_data(tsd);
+ return FALSE;
+ }
+ /* Copying hostname string because original can be destroyed by parent
+ * thread during gethostbyname execution.
+ */
+ tsd->hostname = strdup(hostname);
+ if (!tsd->hostname) {
+ /* Memory allocation failed */
+ destroy_thread_sync_data(tsd);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/* acquire resolver thread synchronization */
+static
+BOOL acquire_thread_sync(struct thread_sync_data * tsd)
+{
+ /* is the thread initiator still waiting for us ? */
+ if (WaitForSingleObject(tsd->mutex_waiting, 0) == WAIT_TIMEOUT) {
+ /* yes, it is */
+
+ /* Waiting access to event_terminate */
+ if (WaitForSingleObject(tsd->mutex_terminate, INFINITE) != WAIT_OBJECT_0) {
+ /* Something went wrong - now just ignoring */
+ }
+ else {
+ if (WaitForSingleObject(tsd->event_terminate, 0) != WAIT_TIMEOUT) {
+ /* Parent thread signaled us to terminate.
+ * This means that all data in conn->async is now destroyed
+ * and we cannot use it.
+ */
+ }
+ else {
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+
+/* release resolver thread synchronization */
+static
+void release_thread_sync(struct thread_sync_data * tsd)
+{
+ ReleaseMutex(tsd->mutex_terminate);
+}
+
+#if defined(CURLRES_IPV4)
+/*
+ * gethostbyname_thread() resolves a name, calls the Curl_addrinfo4_callback
+ * and then exits.
+ *
+ * For builds without ARES/ENABLE_IPV6, create a resolver thread and wait on
+ * it.
+ */
+static unsigned __stdcall gethostbyname_thread (void *arg)
+{
+ struct connectdata *conn = (struct connectdata*) arg;
+ struct thread_data *td = (struct thread_data*) conn->async.os_specific;
+ struct hostent *he;
+ int rc = 0;
+
+ /* Duplicate the passed mutex and event handles.
+ * This allows us to use it even after the container gets destroyed
+ * due to a resolver timeout.
+ */
+ struct thread_sync_data tsd = { 0,0,0,NULL };
+ if (!init_thread_sync_data(td, conn->async.hostname, &tsd)) {
+ /* thread synchronization data initialization failed */
+ return (unsigned)-1;
+ }
+
+ WSASetLastError (conn->async.status = NO_DATA); /* pending status */
+
+ /* Signaling that we have initialized all copies of data and handles we
+ need */
+ SetEvent(td->event_thread_started);
+
+ he = gethostbyname (tsd.hostname);
+
+ /* is parent thread waiting for us and are we able to access conn members? */
+ if (acquire_thread_sync(&tsd)) {
+ /* Mark that we have obtained the information, and that we are calling
+ * back with it. */
+ SetEvent(td->event_resolved);
+ if (he) {
+ rc = Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he);
+ }
+ else {
+ rc = Curl_addrinfo4_callback(conn, (int)WSAGetLastError(), NULL);
+ }
+ TRACE(("Winsock-error %d, addr %s\n", conn->async.status,
+ he ? inet_ntoa(*(struct in_addr*)he->h_addr) : "unknown"));
+ release_thread_sync(&tsd);
+ }
+
+ /* clean up */
+ destroy_thread_sync_data(&tsd);
+
+ return (rc);
+ /* An implicit _endthreadex() here */
+}
+
+#elif defined(CURLRES_IPV6)
+
+/*
+ * getaddrinfo_thread() resolves a name, calls Curl_addrinfo6_callback and then
+ * exits.
+ *
+ * For builds without ARES, but with ENABLE_IPV6, create a resolver thread
+ * and wait on it.
+ */
+static unsigned __stdcall getaddrinfo_thread (void *arg)
+{
+ struct connectdata *conn = (struct connectdata*) arg;
+ struct thread_data *td = (struct thread_data*) conn->async.os_specific;
+ struct addrinfo *res;
+ char service [NI_MAXSERV];
+ int rc;
+ struct addrinfo hints = td->hints;
+
+ /* Duplicate the passed mutex handle.
+ * This allows us to use it even after the container gets destroyed
+ * due to a resolver timeout.
+ */
+ struct thread_sync_data tsd = { 0,0,0,NULL };
+ if (!init_thread_sync_data(td, conn->async.hostname, &tsd)) {
+ /* thread synchronization data initialization failed */
+ return -1;
+ }
+
+ itoa(conn->async.port, service, 10);
+
+ WSASetLastError(conn->async.status = NO_DATA); /* pending status */
+
+ /* Signaling that we have initialized all copies of data and handles we
+ need */
+ SetEvent(td->event_thread_started);
+
+ rc = getaddrinfo(tsd.hostname, service, &hints, &res);
+
+ /* is parent thread waiting for us and are we able to access conn members? */
+ if (acquire_thread_sync(&tsd)) {
+ /* Mark that we have obtained the information, and that we are calling
+ back with it. */
+ SetEvent(td->event_resolved);
+
+ if (rc == 0) {
+#ifdef DEBUG_THREADING_GETADDRINFO
+ dump_addrinfo (conn, res);
+#endif
+ rc = Curl_addrinfo6_callback(conn, CURL_ASYNC_SUCCESS, res);
+ }
+ else {
+ rc = Curl_addrinfo6_callback(conn, (int)WSAGetLastError(), NULL);
+ TRACE(("Winsock-error %d, no address\n", conn->async.status));
+ }
+ release_thread_sync(&tsd);
+ }
+
+ /* clean up */
+ destroy_thread_sync_data(&tsd);
+
+ return (rc);
+ /* An implicit _endthreadex() here */
+}
+#endif
+
+/*
+ * Curl_destroy_thread_data() cleans up async resolver data and thread handle.
+ * Complementary of ares_destroy.
+ */
+void Curl_destroy_thread_data (struct Curl_async *async)
+{
+ if (async->hostname)
+ free(async->hostname);
+
+ if (async->os_specific) {
+ struct thread_data *td = (struct thread_data*) async->os_specific;
+ curl_socket_t sock = td->dummy_sock;
+
+ if (td->mutex_terminate && td->event_terminate) {
+ /* Signaling resolver thread to terminate */
+ if (WaitForSingleObject(td->mutex_terminate, INFINITE) == WAIT_OBJECT_0) {
+ SetEvent(td->event_terminate);
+ ReleaseMutex(td->mutex_terminate);
+ }
+ else {
+ /* Something went wrong - just ignoring it */
+ }
+ }
+
+ if (td->mutex_terminate)
+ CloseHandle(td->mutex_terminate);
+ if (td->event_terminate)
+ CloseHandle(td->event_terminate);
+ if (td->event_thread_started)
+ CloseHandle(td->event_thread_started);
+
+ if (sock != CURL_SOCKET_BAD)
+ sclose(sock);
+
+ /* destroy the synchronization objects */
+ if (td->mutex_waiting)
+ CloseHandle(td->mutex_waiting);
+ td->mutex_waiting = NULL;
+ if (td->event_resolved)
+ CloseHandle(td->event_resolved);
+
+ if (td->thread_hnd)
+ CloseHandle(td->thread_hnd);
+
+ free(async->os_specific);
+ }
+ async->hostname = NULL;
+ async->os_specific = NULL;
+}
+
+/*
+ * init_resolve_thread() starts a new thread that performs the actual
+ * resolve. This function returns before the resolve is done.
+ *
+ * Returns FALSE in case of failure, otherwise TRUE.
+ */
+static bool init_resolve_thread (struct connectdata *conn,
+ const char *hostname, int port,
+ const Curl_addrinfo *hints)
+{
+ struct thread_data *td = calloc(sizeof(*td), 1);
+ HANDLE thread_and_event[2] = {0};
+
+ if (!td) {
+ SetLastError(ENOMEM);
+ return FALSE;
+ }
+
+ Curl_safefree(conn->async.hostname);
+ conn->async.hostname = strdup(hostname);
+ if (!conn->async.hostname) {
+ free(td);
+ SetLastError(ENOMEM);
+ return FALSE;
+ }
+
+ conn->async.port = port;
+ conn->async.done = FALSE;
+ conn->async.status = 0;
+ conn->async.dns = NULL;
+ conn->async.os_specific = (void*) td;
+ td->dummy_sock = CURL_SOCKET_BAD;
+
+ /* Create the mutex used to inform the resolver thread that we're
+ * still waiting, and take initial ownership.
+ */
+ td->mutex_waiting = CreateMutex(NULL, TRUE, NULL);
+ if (td->mutex_waiting == NULL) {
+ Curl_destroy_thread_data(&conn->async);
+ SetLastError(EAGAIN);
+ return FALSE;
+ }
+
+ /* Create the event that the thread uses to inform us that it's
+ * done resolving. Do not signal it.
+ */
+ td->event_resolved = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (td->event_resolved == NULL) {
+ Curl_destroy_thread_data(&conn->async);
+ SetLastError(EAGAIN);
+ return FALSE;
+ }
+ /* Create the mutex used to serialize access to event_terminated
+ * between us and resolver thread.
+ */
+ td->mutex_terminate = CreateMutex(NULL, FALSE, NULL);
+ if (td->mutex_terminate == NULL) {
+ Curl_destroy_thread_data(&conn->async);
+ SetLastError(EAGAIN);
+ return FALSE;
+ }
+ /* Create the event used to signal thread that it should terminate.
+ */
+ td->event_terminate = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (td->event_terminate == NULL) {
+ Curl_destroy_thread_data(&conn->async);
+ SetLastError(EAGAIN);
+ return FALSE;
+ }
+ /* Create the event used by thread to inform it has initialized its own data.
+ */
+ td->event_thread_started = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (td->event_thread_started == NULL) {
+ Curl_destroy_thread_data(&conn->async);
+ SetLastError(EAGAIN);
+ return FALSE;
+ }
+
+#ifdef _WIN32_WCE
+ td->thread_hnd = (HANDLE) CreateThread(NULL, 0,
+ (LPTHREAD_START_ROUTINE) THREAD_FUNC,
+ conn, 0, &td->thread_id);
+#else
+ td->thread_hnd = (HANDLE) _beginthreadex(NULL, 0, THREAD_FUNC,
+ conn, 0, &td->thread_id);
+#endif
+
+#ifdef CURLRES_IPV6
+ curlassert(hints);
+ td->hints = *hints;
+#else
+ (void) hints;
+#endif
+
+ if (!td->thread_hnd) {
+#ifdef _WIN32_WCE
+ TRACE(("CreateThread() failed; %s\n", Curl_strerror(conn,GetLastError())));
+#else
+ SetLastError(errno);
+ TRACE(("_beginthreadex() failed; %s\n", Curl_strerror(conn,errno)));
+#endif
+ Curl_destroy_thread_data(&conn->async);
+ return FALSE;
+ }
+ /* Waiting until the thread will initialize its data or it will exit due errors.
+ */
+ thread_and_event[0] = td->thread_hnd;
+ thread_and_event[1] = td->event_thread_started;
+ if (WaitForMultipleObjects(sizeof(thread_and_event) /
+ sizeof(thread_and_event[0]),
+ (const HANDLE*)thread_and_event, FALSE,
+ INFINITE) == WAIT_FAILED) {
+ /* The resolver thread has been created,
+ * most probably it works now - ignoring this "minor" error
+ */
+ }
+ /* This socket is only to keep Curl_resolv_fdset() and select() happy;
+ * should never become signalled for read/write since it's unbound but
+ * Windows needs atleast 1 socket in select().
+ */
+ td->dummy_sock = socket(AF_INET, SOCK_DGRAM, 0);
+ return TRUE;
+}
+
+
+/*
+ * Curl_wait_for_resolv() waits for a resolve to finish. This function should
+ * be avoided since using this risk getting the multi interface to "hang".
+ *
+ * If 'entry' is non-NULL, make it point to the resolved dns entry
+ *
+ * This is the version for resolves-in-a-thread.
+ */
+CURLcode Curl_wait_for_resolv(struct connectdata *conn,
+ struct Curl_dns_entry **entry)
+{
+ struct thread_data *td = (struct thread_data*) conn->async.os_specific;
+ struct SessionHandle *data = conn->data;
+ long timeout;
+ DWORD status, ticks;
+ CURLcode rc;
+
+ curlassert (conn && td);
+
+ /* now, see if there's a connect timeout or a regular timeout to
+ use instead of the default one */
+ timeout =
+ conn->data->set.connecttimeout ? conn->data->set.connecttimeout :
+ conn->data->set.timeout ? conn->data->set.timeout :
+ CURL_TIMEOUT_RESOLVE; /* default name resolve timeout */
+ ticks = GetTickCount();
+
+ /* wait for the thread to resolve the name */
+ status = WaitForSingleObject(td->event_resolved, 1000UL*timeout);
+
+ /* mark that we are now done waiting */
+ ReleaseMutex(td->mutex_waiting);
+
+ /* close our handle to the mutex, no point in hanging on to it */
+ CloseHandle(td->mutex_waiting);
+ td->mutex_waiting = NULL;
+
+ /* close the event handle, it's useless now */
+ CloseHandle(td->event_resolved);
+ td->event_resolved = NULL;
+
+ /* has the resolver thread succeeded in resolving our query ? */
+ if (status == WAIT_OBJECT_0) {
+ /* wait for the thread to exit, it's in the callback sequence */
+ if (WaitForSingleObject(td->thread_hnd, 5000) == WAIT_TIMEOUT) {
+ TerminateThread(td->thread_hnd, 0);
+ conn->async.done = TRUE;
+ td->thread_status = (DWORD)-1;
+ TRACE(("%s() thread stuck?!, ", THREAD_NAME));
+ }
+ else {
+ /* Thread finished before timeout; propagate Winsock error to this
+ * thread. 'conn->async.done = TRUE' is set in
+ * Curl_addrinfo4/6_callback().
+ */
+ WSASetLastError(conn->async.status);
+ GetExitCodeThread(td->thread_hnd, &td->thread_status);
+ TRACE(("%s() status %lu, thread retval %lu, ",
+ THREAD_NAME, status, td->thread_status));
+ }
+ }
+ else {
+ conn->async.done = TRUE;
+ td->thread_status = (DWORD)-1;
+ TRACE(("%s() timeout, ", THREAD_NAME));
+ }
+
+ TRACE(("elapsed %lu ms\n", GetTickCount()-ticks));
+
+ if(entry)
+ *entry = conn->async.dns;
+
+ rc = CURLE_OK;
+
+ if (!conn->async.dns) {
+ /* a name was not resolved */
+ if (td->thread_status == CURLE_OUT_OF_MEMORY) {
+ rc = CURLE_OUT_OF_MEMORY;
+ failf(data, "Could not resolve host: %s", curl_easy_strerror(rc));
+ }
+ else if(conn->async.done) {
+ if(conn->bits.httpproxy) {
+ failf(data, "Could not resolve proxy: %s; %s",
+ conn->proxy.dispname, Curl_strerror(conn, conn->async.status));
+ rc = CURLE_COULDNT_RESOLVE_PROXY;
+ }
+ else {
+ failf(data, "Could not resolve host: %s; %s",
+ conn->host.name, Curl_strerror(conn, conn->async.status));
+ rc = CURLE_COULDNT_RESOLVE_HOST;
+ }
+ }
+ else if (td->thread_status == (DWORD)-1 || conn->async.status == NO_DATA) {
+ failf(data, "Resolving host timed out: %s", conn->host.name);
+ rc = CURLE_OPERATION_TIMEDOUT;
+ }
+ else
+ rc = CURLE_OPERATION_TIMEDOUT;
+ }
+
+ Curl_destroy_thread_data(&conn->async);
+
+ if(!conn->async.dns)
+ conn->bits.close = TRUE;
+
+ return (rc);
+}
+
+/*
+ * Curl_is_resolved() is called repeatedly to check if a previous name resolve
+ * request has completed. It should also make sure to time-out if the
+ * operation seems to take too long.
+ */
+CURLcode Curl_is_resolved(struct connectdata *conn,
+ struct Curl_dns_entry **entry)
+{
+ *entry = NULL;
+
+ if (conn->async.done) {
+ /* we're done */
+ Curl_destroy_thread_data(&conn->async);
+ if (!conn->async.dns) {
+ TRACE(("Curl_is_resolved(): CURLE_COULDNT_RESOLVE_HOST\n"));
+ return CURLE_COULDNT_RESOLVE_HOST;
+ }
+ *entry = conn->async.dns;
+ TRACE(("resolved okay, dns %p\n", *entry));
+ }
+ return CURLE_OK;
+}
+
+int Curl_resolv_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
+{
+ const struct thread_data *td =
+ (const struct thread_data *) conn->async.os_specific;
+
+ if (td && td->dummy_sock != CURL_SOCKET_BAD) {
+ if(numsocks) {
+ /* return one socket waiting for writable, even though this is just
+ a dummy */
+ socks[0] = td->dummy_sock;
+ return GETSOCK_WRITESOCK(0);
+ }
+ }
+ return 0;
+}
+
+#ifdef CURLRES_IPV4
+/*
+ * Curl_getaddrinfo() - for Windows threading without ENABLE_IPV6.
+ */
+Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ int *waitp)
+{
+ struct hostent *h = NULL;
+ struct SessionHandle *data = conn->data;
+ in_addr_t in;
+
+ *waitp = 0; /* don't wait, we act synchronously */
+
+ in = inet_addr(hostname);
+ if (in != CURL_INADDR_NONE)
+ /* This is a dotted IP address 123.123.123.123-style */
+ return Curl_ip2addr(in, hostname, port);
+
+ /* fire up a new resolver thread! */
+ if (init_resolve_thread(conn, hostname, port, NULL)) {
+ *waitp = TRUE; /* please wait for the response */
+ return NULL;
+ }
+
+ /* fall-back to blocking version */
+ infof(data, "init_resolve_thread() failed for %s; %s\n",
+ hostname, Curl_strerror(conn,GetLastError()));
+
+ h = gethostbyname(hostname);
+ if (!h) {
+ infof(data, "gethostbyname(2) failed for %s:%d; %s\n",
+ hostname, port, Curl_strerror(conn,WSAGetLastError()));
+ return NULL;
+ }
+ return Curl_he2ai(h, port);
+}
+#endif /* CURLRES_IPV4 */
+
+#ifdef CURLRES_IPV6
+/*
+ * Curl_getaddrinfo() - for Windows threading IPv6 enabled
+ */
+Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ int *waitp)
+{
+ struct addrinfo hints, *res;
+ int error;
+ char sbuf[NI_MAXSERV];
+ curl_socket_t s;
+ int pf;
+ struct SessionHandle *data = conn->data;
+
+ *waitp = FALSE; /* default to synch response */
+
+ /* see if we have an IPv6 stack */
+ s = socket(PF_INET6, SOCK_DGRAM, 0);
+ if (s == CURL_SOCKET_BAD) {
+ /* Some non-IPv6 stacks have been found to make very slow name resolves
+ * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
+ * the stack seems to be a non-ipv6 one. */
+
+ pf = PF_INET;
+ }
+ else {
+ /* This seems to be an IPv6-capable stack, use PF_UNSPEC for the widest
+ * possible checks. And close the socket again.
+ */
+ sclose(s);
+
+ /*
+ * Check if a more limited name resolve has been requested.
+ */
+ switch(data->set.ip_version) {
+ case CURL_IPRESOLVE_V4:
+ pf = PF_INET;
+ break;
+ case CURL_IPRESOLVE_V6:
+ pf = PF_INET6;
+ break;
+ default:
+ pf = PF_UNSPEC;
+ break;
+ }
+ }
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = pf;
+ hints.ai_socktype = conn->socktype;
+#if 0 /* removed nov 8 2005 before 7.15.1 */
+ hints.ai_flags = AI_CANONNAME;
+#endif
+ itoa(port, sbuf, 10);
+
+ /* fire up a new resolver thread! */
+ if (init_resolve_thread(conn, hostname, port, &hints)) {
+ *waitp = TRUE; /* please wait for the response */
+ return NULL;
+ }
+
+ /* fall-back to blocking version */
+ infof(data, "init_resolve_thread() failed for %s; %s\n",
+ hostname, Curl_strerror(conn,GetLastError()));
+
+ error = getaddrinfo(hostname, sbuf, &hints, &res);
+ if (error) {
+ infof(data, "getaddrinfo() failed for %s:%d; %s\n",
+ hostname, port, Curl_strerror(conn,WSAGetLastError()));
+ return NULL;
+ }
+ return res;
+}
+#endif /* CURLRES_IPV6 */
+#endif /* CURLRES_THREADED */
diff --git a/Utilities/cmcurl/http.c b/Utilities/cmcurl/http.c
new file mode 100644
index 0000000000..5405aace1d
--- /dev/null
+++ b/Utilities/cmcurl/http.c
@@ -0,0 +1,2422 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_HTTP
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef WIN32
+#include <time.h>
+#include <io.h>
+#else
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#ifdef HAVE_TIME_H
+#ifdef TIME_WITH_SYS_TIME
+#include <time.h>
+#endif
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <netdb.h>
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#include <sys/ioctl.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#endif
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "transfer.h"
+#include "sendf.h"
+#include "easyif.h" /* for Curl_convert_... prototypes */
+#include "formdata.h"
+#include "progress.h"
+#include "base64.h"
+#include "cookie.h"
+#include "strequal.h"
+#include "sslgen.h"
+#include "http_digest.h"
+#include "http_ntlm.h"
+#include "http_negotiate.h"
+#include "url.h"
+#include "share.h"
+#include "hostip.h"
+#include "http.h"
+#include "memory.h"
+#include "select.h"
+#include "parsedate.h" /* for the week day and month names */
+#include "strtoofft.h"
+#include "multiif.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/*
+ * checkheaders() checks the linked list of custom HTTP headers for a
+ * particular header (prefix).
+ *
+ * Returns a pointer to the first matching header or NULL if none matched.
+ */
+static char *checkheaders(struct SessionHandle *data, const char *thisheader)
+{
+ struct curl_slist *head;
+ size_t thislen = strlen(thisheader);
+
+ for(head = data->set.headers; head; head=head->next) {
+ if(strnequal(head->data, thisheader, thislen))
+ return head->data;
+ }
+ return NULL;
+}
+
+/*
+ * Curl_output_basic() sets up an Authorization: header (or the proxy version)
+ * for HTTP Basic authentication.
+ *
+ * Returns CURLcode.
+ */
+static CURLcode Curl_output_basic(struct connectdata *conn, bool proxy)
+{
+ char *authorization;
+ struct SessionHandle *data=conn->data;
+ char **userp;
+ char *user;
+ char *pwd;
+
+ if(proxy) {
+ userp = &conn->allocptr.proxyuserpwd;
+ user = conn->proxyuser;
+ pwd = conn->proxypasswd;
+ }
+ else {
+ userp = &conn->allocptr.userpwd;
+ user = conn->user;
+ pwd = conn->passwd;
+ }
+
+ snprintf(data->state.buffer, sizeof(data->state.buffer), "%s:%s", user, pwd);
+ if(Curl_base64_encode(data, data->state.buffer,
+ strlen(data->state.buffer),
+ &authorization) > 0) {
+ if(*userp)
+ free(*userp);
+ *userp = aprintf( "%sAuthorization: Basic %s\r\n",
+ proxy?"Proxy-":"",
+ authorization);
+ free(authorization);
+ }
+ else
+ return CURLE_OUT_OF_MEMORY;
+ return CURLE_OK;
+}
+
+/* pickoneauth() selects the most favourable authentication method from the
+ * ones available and the ones we want.
+ *
+ * return TRUE if one was picked
+ */
+static bool pickoneauth(struct auth *pick)
+{
+ bool picked;
+ /* only deal with authentication we want */
+ long avail = pick->avail & pick->want;
+ picked = TRUE;
+
+ /* The order of these checks is highly relevant, as this will be the order
+ of preference in case of the existence of multiple accepted types. */
+ if(avail & CURLAUTH_GSSNEGOTIATE)
+ pick->picked = CURLAUTH_GSSNEGOTIATE;
+ else if(avail & CURLAUTH_DIGEST)
+ pick->picked = CURLAUTH_DIGEST;
+ else if(avail & CURLAUTH_NTLM)
+ pick->picked = CURLAUTH_NTLM;
+ else if(avail & CURLAUTH_BASIC)
+ pick->picked = CURLAUTH_BASIC;
+ else {
+ pick->picked = CURLAUTH_PICKNONE; /* we select to use nothing */
+ picked = FALSE;
+ }
+ pick->avail = CURLAUTH_NONE; /* clear it here */
+
+ return picked;
+}
+
+/*
+ * perhapsrewind()
+ *
+ * If we are doing POST or PUT {
+ * If we have more data to send {
+ * If we are doing NTLM {
+ * Keep sending since we must not disconnect
+ * }
+ * else {
+ * If there is more than just a little data left to send, close
+ * the current connection by force.
+ * }
+ * }
+ * If we have sent any data {
+ * If we don't have track of all the data {
+ * call app to tell it to rewind
+ * }
+ * else {
+ * rewind internally so that the operation can restart fine
+ * }
+ * }
+ * }
+ */
+static CURLcode perhapsrewind(struct connectdata *conn)
+{
+ struct SessionHandle *data = conn->data;
+ struct HTTP *http = data->reqdata.proto.http;
+ struct Curl_transfer_keeper *k = &data->reqdata.keep;
+ curl_off_t bytessent;
+ curl_off_t expectsend = -1; /* default is unknown */
+
+ if(!http)
+ /* If this is still NULL, we have not reach very far and we can
+ safely skip this rewinding stuff */
+ return CURLE_OK;
+
+ bytessent = http->writebytecount;
+
+ if(conn->bits.authneg)
+ /* This is a state where we are known to be negotiating and we don't send
+ any data then. */
+ expectsend = 0;
+ else {
+ /* figure out how much data we are expected to send */
+ switch(data->set.httpreq) {
+ case HTTPREQ_POST:
+ if(data->set.postfieldsize != -1)
+ expectsend = data->set.postfieldsize;
+ break;
+ case HTTPREQ_PUT:
+ if(data->set.infilesize != -1)
+ expectsend = data->set.infilesize;
+ break;
+ case HTTPREQ_POST_FORM:
+ expectsend = http->postsize;
+ break;
+ default:
+ break;
+ }
+ }
+
+ conn->bits.rewindaftersend = FALSE; /* default */
+
+ if((expectsend == -1) || (expectsend > bytessent)) {
+ /* There is still data left to send */
+ if((data->state.authproxy.picked == CURLAUTH_NTLM) ||
+ (data->state.authhost.picked == CURLAUTH_NTLM)) {
+ if(((expectsend - bytessent) < 2000) ||
+ (conn->ntlm.state != NTLMSTATE_NONE)) {
+ /* The NTLM-negotiation has started *OR* there is just a little (<2K)
+ data left to send, keep on sending. */
+
+ /* rewind data when completely done sending! */
+ if(!conn->bits.authneg)
+ conn->bits.rewindaftersend = TRUE;
+
+ return CURLE_OK;
+ }
+ if(conn->bits.close)
+ /* this is already marked to get closed */
+ return CURLE_OK;
+
+ infof(data, "NTLM send, close instead of sending %" FORMAT_OFF_T
+ " bytes\n", (curl_off_t)(expectsend - bytessent));
+ }
+
+ /* This is not NTLM or NTLM with many bytes left to send: close
+ */
+ conn->bits.close = TRUE;
+ k->size = 0; /* don't download any more than 0 bytes */
+ }
+
+ if(bytessent)
+ return Curl_readrewind(conn);
+
+ return CURLE_OK;
+}
+
+/*
+ * Curl_http_auth_act() gets called when a all HTTP headers have been received
+ * and it checks what authentication methods that are available and decides
+ * which one (if any) to use. It will set 'newurl' if an auth metod was
+ * picked.
+ */
+
+CURLcode Curl_http_auth_act(struct connectdata *conn)
+{
+ struct SessionHandle *data = conn->data;
+ bool pickhost = FALSE;
+ bool pickproxy = FALSE;
+ CURLcode code = CURLE_OK;
+
+ if(100 == data->reqdata.keep.httpcode)
+ /* this is a transient response code, ignore */
+ return CURLE_OK;
+
+ if(data->state.authproblem)
+ return data->set.http_fail_on_error?CURLE_HTTP_RETURNED_ERROR:CURLE_OK;
+
+ if(conn->bits.user_passwd &&
+ ((data->reqdata.keep.httpcode == 401) ||
+ (conn->bits.authneg && data->reqdata.keep.httpcode < 300))) {
+ pickhost = pickoneauth(&data->state.authhost);
+ if(!pickhost)
+ data->state.authproblem = TRUE;
+ }
+ if(conn->bits.proxy_user_passwd &&
+ ((data->reqdata.keep.httpcode == 407) ||
+ (conn->bits.authneg && data->reqdata.keep.httpcode < 300))) {
+ pickproxy = pickoneauth(&data->state.authproxy);
+ if(!pickproxy)
+ data->state.authproblem = TRUE;
+ }
+
+ if(pickhost || pickproxy) {
+ data->reqdata.newurl = strdup(data->change.url); /* clone URL */
+
+ if((data->set.httpreq != HTTPREQ_GET) &&
+ (data->set.httpreq != HTTPREQ_HEAD) &&
+ !conn->bits.rewindaftersend) {
+ code = perhapsrewind(conn);
+ if(code)
+ return code;
+ }
+ }
+
+ else if((data->reqdata.keep.httpcode < 300) &&
+ (!data->state.authhost.done) &&
+ conn->bits.authneg) {
+ /* no (known) authentication available,
+ authentication is not "done" yet and
+ no authentication seems to be required and
+ we didn't try HEAD or GET */
+ if((data->set.httpreq != HTTPREQ_GET) &&
+ (data->set.httpreq != HTTPREQ_HEAD)) {
+ data->reqdata.newurl = strdup(data->change.url); /* clone URL */
+ data->state.authhost.done = TRUE;
+ }
+ }
+ if (Curl_http_should_fail(conn)) {
+ failf (data, "The requested URL returned error: %d",
+ data->reqdata.keep.httpcode);
+ code = CURLE_HTTP_RETURNED_ERROR;
+ }
+
+ return code;
+}
+
+/**
+ * Curl_http_output_auth() setups the authentication headers for the
+ * host/proxy and the correct authentication
+ * method. conn->data->state.authdone is set to TRUE when authentication is
+ * done.
+ *
+ * @param conn all information about the current connection
+ * @param request pointer to the request keyword
+ * @param path pointer to the requested path
+ * @param proxytunnel boolean if this is the request setting up a "proxy
+ * tunnel"
+ *
+ * @returns CURLcode
+ */
+static CURLcode
+Curl_http_output_auth(struct connectdata *conn,
+ char *request,
+ char *path,
+ bool proxytunnel) /* TRUE if this is the request setting
+ up the proxy tunnel */
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ char *auth=NULL;
+ struct auth *authhost;
+ struct auth *authproxy;
+
+ curlassert(data);
+
+ authhost = &data->state.authhost;
+ authproxy = &data->state.authproxy;
+
+ if((conn->bits.httpproxy && conn->bits.proxy_user_passwd) ||
+ conn->bits.user_passwd)
+ /* continue please */ ;
+ else {
+ authhost->done = TRUE;
+ authproxy->done = TRUE;
+ return CURLE_OK; /* no authentication with no user or password */
+ }
+
+ if(authhost->want && !authhost->picked)
+ /* The app has selected one or more methods, but none has been picked
+ so far by a server round-trip. Then we set the picked one to the
+ want one, and if this is one single bit it'll be used instantly. */
+ authhost->picked = authhost->want;
+
+ if(authproxy->want && !authproxy->picked)
+ /* The app has selected one or more methods, but none has been picked so
+ far by a proxy round-trip. Then we set the picked one to the want one,
+ and if this is one single bit it'll be used instantly. */
+ authproxy->picked = authproxy->want;
+
+ /* Send proxy authentication header if needed */
+ if (conn->bits.httpproxy &&
+ (conn->bits.tunnel_proxy == proxytunnel)) {
+#ifdef USE_NTLM
+ if(authproxy->picked == CURLAUTH_NTLM) {
+ auth=(char *)"NTLM";
+ result = Curl_output_ntlm(conn, TRUE);
+ if(result)
+ return result;
+ }
+ else
+#endif
+ if(authproxy->picked == CURLAUTH_BASIC) {
+ /* Basic */
+ if(conn->bits.proxy_user_passwd &&
+ !checkheaders(data, "Proxy-authorization:")) {
+ auth=(char *)"Basic";
+ result = Curl_output_basic(conn, TRUE);
+ if(result)
+ return result;
+ }
+ /* NOTE: Curl_output_basic() should set 'done' TRUE, as the other auth
+ functions work that way */
+ authproxy->done = TRUE;
+ }
+#ifndef CURL_DISABLE_CRYPTO_AUTH
+ else if(authproxy->picked == CURLAUTH_DIGEST) {
+ auth=(char *)"Digest";
+ result = Curl_output_digest(conn,
+ TRUE, /* proxy */
+ (unsigned char *)request,
+ (unsigned char *)path);
+ if(result)
+ return result;
+ }
+#endif
+ if(auth) {
+ infof(data, "Proxy auth using %s with user '%s'\n",
+ auth, conn->proxyuser?conn->proxyuser:"");
+ authproxy->multi = (bool)(!authproxy->done);
+ }
+ else
+ authproxy->multi = FALSE;
+ }
+ else
+ /* we have no proxy so let's pretend we're done authenticating
+ with it */
+ authproxy->done = TRUE;
+
+ /* To prevent the user+password to get sent to other than the original
+ host due to a location-follow, we do some weirdo checks here */
+ if(!data->state.this_is_a_follow ||
+ conn->bits.netrc ||
+ !data->state.first_host ||
+ curl_strequal(data->state.first_host, conn->host.name) ||
+ data->set.http_disable_hostname_check_before_authentication) {
+
+ /* Send web authentication header if needed */
+ {
+ auth = NULL;
+#ifdef HAVE_GSSAPI
+ if((authhost->picked == CURLAUTH_GSSNEGOTIATE) &&
+ data->state.negotiate.context &&
+ !GSS_ERROR(data->state.negotiate.status)) {
+ auth=(char *)"GSS-Negotiate";
+ result = Curl_output_negotiate(conn);
+ if (result)
+ return result;
+ authhost->done = TRUE;
+ }
+ else
+#endif
+#ifdef USE_NTLM
+ if(authhost->picked == CURLAUTH_NTLM) {
+ auth=(char *)"NTLM";
+ result = Curl_output_ntlm(conn, FALSE);
+ if(result)
+ return result;
+ }
+ else
+#endif
+ {
+#ifndef CURL_DISABLE_CRYPTO_AUTH
+ if(authhost->picked == CURLAUTH_DIGEST) {
+ auth=(char *)"Digest";
+ result = Curl_output_digest(conn,
+ FALSE, /* not a proxy */
+ (unsigned char *)request,
+ (unsigned char *)path);
+ if(result)
+ return result;
+ } else
+#endif
+ if(authhost->picked == CURLAUTH_BASIC) {
+ if(conn->bits.user_passwd &&
+ !checkheaders(data, "Authorization:")) {
+ auth=(char *)"Basic";
+ result = Curl_output_basic(conn, FALSE);
+ if(result)
+ return result;
+ }
+ /* basic is always ready */
+ authhost->done = TRUE;
+ }
+ }
+ if(auth) {
+ infof(data, "Server auth using %s with user '%s'\n",
+ auth, conn->user);
+
+ authhost->multi = (bool)(!authhost->done);
+ }
+ else
+ authhost->multi = FALSE;
+ }
+ }
+ else
+ authhost->done = TRUE;
+
+ return result;
+}
+
+
+/*
+ * Curl_http_input_auth() deals with Proxy-Authenticate: and WWW-Authenticate:
+ * headers. They are dealt with both in the transfer.c main loop and in the
+ * proxy CONNECT loop.
+ */
+
+CURLcode Curl_http_input_auth(struct connectdata *conn,
+ int httpcode,
+ char *header) /* the first non-space */
+{
+ /*
+ * This resource requires authentication
+ */
+ struct SessionHandle *data = conn->data;
+
+ long *availp;
+ char *start;
+ struct auth *authp;
+
+ if (httpcode == 407) {
+ start = header+strlen("Proxy-authenticate:");
+ availp = &data->info.proxyauthavail;
+ authp = &data->state.authproxy;
+ }
+ else {
+ start = header+strlen("WWW-Authenticate:");
+ availp = &data->info.httpauthavail;
+ authp = &data->state.authhost;
+ }
+
+ /* pass all white spaces */
+ while(*start && ISSPACE(*start))
+ start++;
+
+ /*
+ * Here we check if we want the specific single authentication (using ==) and
+ * if we do, we initiate usage of it.
+ *
+ * If the provided authentication is wanted as one out of several accepted
+ * types (using &), we OR this authentication type to the authavail
+ * variable.
+ */
+
+#ifdef HAVE_GSSAPI
+ if (checkprefix("GSS-Negotiate", start) ||
+ checkprefix("Negotiate", start)) {
+ *availp |= CURLAUTH_GSSNEGOTIATE;
+ authp->avail |= CURLAUTH_GSSNEGOTIATE;
+ if(authp->picked == CURLAUTH_GSSNEGOTIATE) {
+ /* if exactly this is wanted, go */
+ int neg = Curl_input_negotiate(conn, start);
+ if (neg == 0) {
+ data->reqdata.newurl = strdup(data->change.url);
+ data->state.authproblem = (data->reqdata.newurl == NULL);
+ }
+ else {
+ infof(data, "Authentication problem. Ignoring this.\n");
+ data->state.authproblem = TRUE;
+ }
+ }
+ }
+ else
+#endif
+#ifdef USE_NTLM
+ /* NTLM support requires the SSL crypto libs */
+ if(checkprefix("NTLM", start)) {
+ *availp |= CURLAUTH_NTLM;
+ authp->avail |= CURLAUTH_NTLM;
+ if(authp->picked == CURLAUTH_NTLM) {
+ /* NTLM authentication is picked and activated */
+ CURLntlm ntlm =
+ Curl_input_ntlm(conn, (bool)(httpcode == 407), start);
+
+ if(CURLNTLM_BAD != ntlm)
+ data->state.authproblem = FALSE;
+ else {
+ infof(data, "Authentication problem. Ignoring this.\n");
+ data->state.authproblem = TRUE;
+ }
+ }
+ }
+ else
+#endif
+#ifndef CURL_DISABLE_CRYPTO_AUTH
+ if(checkprefix("Digest", start)) {
+ if((authp->avail & CURLAUTH_DIGEST) != 0) {
+ infof(data, "Ignoring duplicate digest auth header.\n");
+ }
+ else {
+ CURLdigest dig;
+ *availp |= CURLAUTH_DIGEST;
+ authp->avail |= CURLAUTH_DIGEST;
+
+ /* We call this function on input Digest headers even if Digest
+ * authentication isn't activated yet, as we need to store the
+ * incoming data from this header in case we are gonna use Digest. */
+ dig = Curl_input_digest(conn, (bool)(httpcode == 407), start);
+
+ if(CURLDIGEST_FINE != dig) {
+ infof(data, "Authentication problem. Ignoring this.\n");
+ data->state.authproblem = TRUE;
+ }
+ }
+ }
+ else
+#endif
+ if(checkprefix("Basic", start)) {
+ *availp |= CURLAUTH_BASIC;
+ authp->avail |= CURLAUTH_BASIC;
+ if(authp->picked == CURLAUTH_BASIC) {
+ /* We asked for Basic authentication but got a 40X back
+ anyway, which basicly means our name+password isn't
+ valid. */
+ authp->avail = CURLAUTH_NONE;
+ infof(data, "Authentication problem. Ignoring this.\n");
+ data->state.authproblem = TRUE;
+ }
+ }
+
+ return CURLE_OK;
+}
+
+/**
+ * Curl_http_should_fail() determines whether an HTTP response has gotten us
+ * into an error state or not.
+ *
+ * @param conn all information about the current connection
+ *
+ * @retval 0 communications should continue
+ *
+ * @retval 1 communications should not continue
+ */
+int Curl_http_should_fail(struct connectdata *conn)
+{
+ struct SessionHandle *data;
+ struct Curl_transfer_keeper *k;
+
+ curlassert(conn);
+ data = conn->data;
+ curlassert(data);
+
+ /*
+ ** For readability
+ */
+ k = &data->reqdata.keep;
+
+ /*
+ ** If we haven't been asked to fail on error,
+ ** don't fail.
+ */
+ if (!data->set.http_fail_on_error)
+ return 0;
+
+ /*
+ ** Any code < 400 is never terminal.
+ */
+ if (k->httpcode < 400)
+ return 0;
+
+ if (data->reqdata.resume_from &&
+ (data->set.httpreq==HTTPREQ_GET) &&
+ (k->httpcode == 416)) {
+ /* "Requested Range Not Satisfiable", just proceed and
+ pretend this is no error */
+ return 0;
+ }
+
+ /*
+ ** Any code >= 400 that's not 401 or 407 is always
+ ** a terminal error
+ */
+ if ((k->httpcode != 401) &&
+ (k->httpcode != 407))
+ return 1;
+
+ /*
+ ** All we have left to deal with is 401 and 407
+ */
+ curlassert((k->httpcode == 401) || (k->httpcode == 407));
+
+ /*
+ ** Examine the current authentication state to see if this
+ ** is an error. The idea is for this function to get
+ ** called after processing all the headers in a response
+ ** message. So, if we've been to asked to authenticate a
+ ** particular stage, and we've done it, we're OK. But, if
+ ** we're already completely authenticated, it's not OK to
+ ** get another 401 or 407.
+ **
+ ** It is possible for authentication to go stale such that
+ ** the client needs to reauthenticate. Once that info is
+ ** available, use it here.
+ */
+#if 0 /* set to 1 when debugging this functionality */
+ infof(data,"%s: authstage = %d\n",__FUNCTION__,data->state.authstage);
+ infof(data,"%s: authwant = 0x%08x\n",__FUNCTION__,data->state.authwant);
+ infof(data,"%s: authavail = 0x%08x\n",__FUNCTION__,data->state.authavail);
+ infof(data,"%s: httpcode = %d\n",__FUNCTION__,k->httpcode);
+ infof(data,"%s: authdone = %d\n",__FUNCTION__,data->state.authdone);
+ infof(data,"%s: newurl = %s\n",__FUNCTION__,data->reqdata.newurl ? data->reqdata.newurl : "(null)");
+ infof(data,"%s: authproblem = %d\n",__FUNCTION__,data->state.authproblem);
+#endif
+
+ /*
+ ** Either we're not authenticating, or we're supposed to
+ ** be authenticating something else. This is an error.
+ */
+ if((k->httpcode == 401) && !conn->bits.user_passwd)
+ return TRUE;
+ if((k->httpcode == 407) && !conn->bits.proxy_user_passwd)
+ return TRUE;
+
+ return data->state.authproblem;
+}
+
+/*
+ * readmoredata() is a "fread() emulation" to provide POST and/or request
+ * data. It is used when a huge POST is to be made and the entire chunk wasn't
+ * sent in the first send(). This function will then be called from the
+ * transfer.c loop when more data is to be sent to the peer.
+ *
+ * Returns the amount of bytes it filled the buffer with.
+ */
+static size_t readmoredata(char *buffer,
+ size_t size,
+ size_t nitems,
+ void *userp)
+{
+ struct connectdata *conn = (struct connectdata *)userp;
+ struct HTTP *http = conn->data->reqdata.proto.http;
+ size_t fullsize = size * nitems;
+
+ if(0 == http->postsize)
+ /* nothing to return */
+ return 0;
+
+ /* make sure that a HTTP request is never sent away chunked! */
+ conn->bits.forbidchunk = (bool)(http->sending == HTTPSEND_REQUEST);
+
+ if(http->postsize <= (curl_off_t)fullsize) {
+ memcpy(buffer, http->postdata, (size_t)http->postsize);
+ fullsize = (size_t)http->postsize;
+
+ if(http->backup.postsize) {
+ /* move backup data into focus and continue on that */
+ http->postdata = http->backup.postdata;
+ http->postsize = http->backup.postsize;
+ conn->fread = http->backup.fread;
+ conn->fread_in = http->backup.fread_in;
+
+ http->sending++; /* move one step up */
+
+ http->backup.postsize=0;
+ }
+ else
+ http->postsize = 0;
+
+ return fullsize;
+ }
+
+ memcpy(buffer, http->postdata, fullsize);
+ http->postdata += fullsize;
+ http->postsize -= fullsize;
+
+ return fullsize;
+}
+
+/* ------------------------------------------------------------------------- */
+/*
+ * The add_buffer series of functions are used to build one large memory chunk
+ * from repeated function invokes. Used so that the entire HTTP request can
+ * be sent in one go.
+ */
+
+struct send_buffer {
+ char *buffer;
+ size_t size_max;
+ size_t size_used;
+};
+typedef struct send_buffer send_buffer;
+
+static CURLcode add_custom_headers(struct connectdata *conn,
+ send_buffer *req_buffer);
+static CURLcode
+ add_buffer(send_buffer *in, const void *inptr, size_t size);
+
+/*
+ * add_buffer_init() sets up and returns a fine buffer struct
+ */
+static
+send_buffer *add_buffer_init(void)
+{
+ send_buffer *blonk;
+ blonk=(send_buffer *)malloc(sizeof(send_buffer));
+ if(blonk) {
+ memset(blonk, 0, sizeof(send_buffer));
+ return blonk;
+ }
+ return NULL; /* failed, go home */
+}
+
+/*
+ * add_buffer_send() sends a header buffer and frees all associated memory.
+ * Body data may be appended to the header data if desired.
+ *
+ * Returns CURLcode
+ */
+static
+CURLcode add_buffer_send(send_buffer *in,
+ struct connectdata *conn,
+ long *bytes_written, /* add the number of sent
+ bytes to this counter */
+ size_t included_body_bytes, /* how much of the buffer
+ contains body data (for log tracing) */
+ int socketindex)
+
+{
+ ssize_t amount;
+ CURLcode res;
+ char *ptr;
+ size_t size;
+ struct HTTP *http = conn->data->reqdata.proto.http;
+ size_t sendsize;
+ curl_socket_t sockfd;
+
+ curlassert(socketindex <= SECONDARYSOCKET);
+
+ sockfd = conn->sock[socketindex];
+
+ /* The looping below is required since we use non-blocking sockets, but due
+ to the circumstances we will just loop and try again and again etc */
+
+ ptr = in->buffer;
+ size = in->size_used;
+
+#ifdef CURL_DOES_CONVERSIONS
+ if(size - included_body_bytes > 0) {
+ res = Curl_convert_to_network(conn->data, ptr, size - included_body_bytes);
+ /* Curl_convert_to_network calls failf if unsuccessful */
+ if(res != CURLE_OK) {
+ /* conversion failed, free memory and return to the caller */
+ if(in->buffer)
+ free(in->buffer);
+ free(in);
+ return res;
+ }
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ if(conn->protocol & PROT_HTTPS) {
+ /* We never send more than CURL_MAX_WRITE_SIZE bytes in one single chunk
+ when we speak HTTPS, as if only a fraction of it is sent now, this data
+ needs to fit into the normal read-callback buffer later on and that
+ buffer is using this size.
+ */
+
+ sendsize= (size > CURL_MAX_WRITE_SIZE)?CURL_MAX_WRITE_SIZE:size;
+
+ /* OpenSSL is very picky and we must send the SAME buffer pointer to the
+ library when we attempt to re-send this buffer. Sending the same data
+ is not enough, we must use the exact same address. For this reason, we
+ must copy the data to the uploadbuffer first, since that is the buffer
+ we will be using if this send is retried later.
+ */
+ memcpy(conn->data->state.uploadbuffer, ptr, sendsize);
+ ptr = conn->data->state.uploadbuffer;
+ }
+ else
+ sendsize = size;
+
+ res = Curl_write(conn, sockfd, ptr, sendsize, &amount);
+
+ if(CURLE_OK == res) {
+
+ if(conn->data->set.verbose) {
+ /* this data _may_ contain binary stuff */
+ Curl_debug(conn->data, CURLINFO_HEADER_OUT, ptr,
+ (size_t)(amount-included_body_bytes), conn);
+ if (included_body_bytes)
+ Curl_debug(conn->data, CURLINFO_DATA_OUT,
+ ptr+amount-included_body_bytes,
+ (size_t)included_body_bytes, conn);
+ }
+
+ *bytes_written += amount;
+
+ if(http) {
+ if((size_t)amount != size) {
+ /* The whole request could not be sent in one system call. We must
+ queue it up and send it later when we get the chance. We must not
+ loop here and wait until it might work again. */
+
+ size -= amount;
+
+ ptr = in->buffer + amount;
+
+ /* backup the currently set pointers */
+ http->backup.fread = conn->fread;
+ http->backup.fread_in = conn->fread_in;
+ http->backup.postdata = http->postdata;
+ http->backup.postsize = http->postsize;
+
+ /* set the new pointers for the request-sending */
+ conn->fread = (curl_read_callback)readmoredata;
+ conn->fread_in = (void *)conn;
+ http->postdata = ptr;
+ http->postsize = (curl_off_t)size;
+
+ http->send_buffer = in;
+ http->sending = HTTPSEND_REQUEST;
+
+ return CURLE_OK;
+ }
+ http->sending = HTTPSEND_BODY;
+ /* the full buffer was sent, clean up and return */
+ }
+ else {
+ if((size_t)amount != size)
+ /* We have no continue-send mechanism now, fail. This can only happen
+ when this function is used from the CONNECT sending function. We
+ currently (stupidly) assume that the whole request is always sent
+ away in the first single chunk.
+
+ This needs FIXing.
+ */
+ return CURLE_SEND_ERROR;
+ else
+ conn->writechannel_inuse = FALSE;
+ }
+ }
+ if(in->buffer)
+ free(in->buffer);
+ free(in);
+
+ return res;
+}
+
+
+/*
+ * add_bufferf() add the formatted input to the buffer.
+ */
+static
+CURLcode add_bufferf(send_buffer *in, const char *fmt, ...)
+{
+ char *s;
+ va_list ap;
+ va_start(ap, fmt);
+ s = vaprintf(fmt, ap); /* this allocs a new string to append */
+ va_end(ap);
+
+ if(s) {
+ CURLcode result = add_buffer(in, s, strlen(s));
+ free(s);
+ if(CURLE_OK == result)
+ return CURLE_OK;
+ }
+ /* If we failed, we cleanup the whole buffer and return error */
+ if(in->buffer)
+ free(in->buffer);
+ free(in);
+ return CURLE_OUT_OF_MEMORY;
+}
+
+/*
+ * add_buffer() appends a memory chunk to the existing buffer
+ */
+static
+CURLcode add_buffer(send_buffer *in, const void *inptr, size_t size)
+{
+ char *new_rb;
+ size_t new_size;
+
+ if(!in->buffer ||
+ ((in->size_used + size) > (in->size_max - 1))) {
+ new_size = (in->size_used+size)*2;
+ if(in->buffer)
+ /* we have a buffer, enlarge the existing one */
+ new_rb = (char *)realloc(in->buffer, new_size);
+ else
+ /* create a new buffer */
+ new_rb = (char *)malloc(new_size);
+
+ if(!new_rb)
+ return CURLE_OUT_OF_MEMORY;
+
+ in->buffer = new_rb;
+ in->size_max = new_size;
+ }
+ memcpy(&in->buffer[in->size_used], inptr, size);
+
+ in->size_used += size;
+
+ return CURLE_OK;
+}
+
+/* end of the add_buffer functions */
+/* ------------------------------------------------------------------------- */
+
+/*
+ * Curl_compareheader()
+ *
+ * Returns TRUE if 'headerline' contains the 'header' with given 'content'.
+ * Pass headers WITH the colon.
+ */
+bool
+Curl_compareheader(char *headerline, /* line to check */
+ const char *header, /* header keyword _with_ colon */
+ const char *content) /* content string to find */
+{
+ /* RFC2616, section 4.2 says: "Each header field consists of a name followed
+ * by a colon (":") and the field value. Field names are case-insensitive.
+ * The field value MAY be preceded by any amount of LWS, though a single SP
+ * is preferred." */
+
+ size_t hlen = strlen(header);
+ size_t clen;
+ size_t len;
+ char *start;
+ char *end;
+
+ if(!strnequal(headerline, header, hlen))
+ return FALSE; /* doesn't start with header */
+
+ /* pass the header */
+ start = &headerline[hlen];
+
+ /* pass all white spaces */
+ while(*start && ISSPACE(*start))
+ start++;
+
+ /* find the end of the header line */
+ end = strchr(start, '\r'); /* lines end with CRLF */
+ if(!end) {
+ /* in case there's a non-standard compliant line here */
+ end = strchr(start, '\n');
+
+ if(!end)
+ /* hm, there's no line ending here, use the zero byte! */
+ end = strchr(start, '\0');
+ }
+
+ len = end-start; /* length of the content part of the input line */
+ clen = strlen(content); /* length of the word to find */
+
+ /* find the content string in the rest of the line */
+ for(;len>=clen;len--, start++) {
+ if(strnequal(start, content, clen))
+ return TRUE; /* match! */
+ }
+
+ return FALSE; /* no match */
+}
+
+/*
+ * Curl_proxyCONNECT() requires that we're connected to a HTTP proxy. This
+ * function will issue the necessary commands to get a seamless tunnel through
+ * this proxy. After that, the socket can be used just as a normal socket.
+ *
+ * This badly needs to be rewritten. CONNECT should be sent and dealt with
+ * like any ordinary HTTP request, and not specially crafted like this. This
+ * function only remains here like this for now since the rewrite is a bit too
+ * much work to do at the moment.
+ *
+ * This function is BLOCKING which is nasty for all multi interface using apps.
+ */
+
+CURLcode Curl_proxyCONNECT(struct connectdata *conn,
+ int sockindex,
+ char *hostname,
+ int remote_port)
+{
+ int subversion=0;
+ struct SessionHandle *data=conn->data;
+ struct Curl_transfer_keeper *k = &data->reqdata.keep;
+ CURLcode result;
+ int res;
+ size_t nread; /* total size read */
+ int perline; /* count bytes per line */
+ int keepon=TRUE;
+ ssize_t gotbytes;
+ char *ptr;
+ long timeout =
+ data->set.timeout?data->set.timeout:3600; /* in seconds */
+ char *line_start;
+ char *host_port;
+ curl_socket_t tunnelsocket = conn->sock[sockindex];
+ send_buffer *req_buffer;
+ curl_off_t cl=0;
+ bool closeConnection = FALSE;
+
+#define SELECT_OK 0
+#define SELECT_ERROR 1
+#define SELECT_TIMEOUT 2
+ int error = SELECT_OK;
+
+ infof(data, "Establish HTTP proxy tunnel to %s:%d\n", hostname, remote_port);
+ conn->bits.proxy_connect_closed = FALSE;
+
+ do {
+ if(data->reqdata.newurl) {
+ /* This only happens if we've looped here due to authentication reasons,
+ and we don't really use the newly cloned URL here then. Just free()
+ it. */
+ free(data->reqdata.newurl);
+ data->reqdata.newurl = NULL;
+ }
+
+ /* initialize a dynamic send-buffer */
+ req_buffer = add_buffer_init();
+
+ if(!req_buffer)
+ return CURLE_OUT_OF_MEMORY;
+
+ host_port = aprintf("%s:%d", hostname, remote_port);
+ if(!host_port)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* Setup the proxy-authorization header, if any */
+ result = Curl_http_output_auth(conn, (char *)"CONNECT", host_port, TRUE);
+
+ if(CURLE_OK == result) {
+ char *host=(char *)"";
+ const char *proxyconn="";
+ const char *useragent="";
+
+ if(!checkheaders(data, "Host:")) {
+ host = aprintf("Host: %s\r\n", host_port);
+ if(!host)
+ result = CURLE_OUT_OF_MEMORY;
+ }
+ if(!checkheaders(data, "Proxy-Connection:"))
+ proxyconn = "Proxy-Connection: Keep-Alive\r\n";
+
+ if(!checkheaders(data, "User-Agent:") && data->set.useragent)
+ useragent = conn->allocptr.uagent;
+
+ if(CURLE_OK == result) {
+ /* Send the connect request to the proxy */
+ /* BLOCKING */
+ result =
+ add_bufferf(req_buffer,
+ "CONNECT %s:%d HTTP/1.0\r\n"
+ "%s" /* Host: */
+ "%s" /* Proxy-Authorization */
+ "%s" /* User-Agent */
+ "%s", /* Proxy-Connection */
+ hostname, remote_port,
+ host,
+ conn->allocptr.proxyuserpwd?
+ conn->allocptr.proxyuserpwd:"",
+ useragent,
+ proxyconn);
+
+ if(CURLE_OK == result)
+ result = add_custom_headers(conn, req_buffer);
+
+ if(host && *host)
+ free(host);
+
+ if(CURLE_OK == result)
+ /* CRLF terminate the request */
+ result = add_bufferf(req_buffer, "\r\n");
+
+ if(CURLE_OK == result)
+ /* Now send off the request */
+ result = add_buffer_send(req_buffer, conn,
+ &data->info.request_size, 0, sockindex);
+ }
+ if(result)
+ failf(data, "Failed sending CONNECT to proxy");
+ }
+ free(host_port);
+ if(result)
+ return result;
+
+ ptr=data->state.buffer;
+ line_start = ptr;
+
+ nread=0;
+ perline=0;
+ keepon=TRUE;
+
+ while((nread<BUFSIZE) && (keepon && !error)) {
+
+ /* if timeout is requested, find out how much remaining time we have */
+ long check = timeout - /* timeout time */
+ Curl_tvdiff(Curl_tvnow(), conn->now)/1000; /* spent time */
+ if(check <=0 ) {
+ failf(data, "Proxy CONNECT aborted due to timeout");
+ error = SELECT_TIMEOUT; /* already too little time */
+ break;
+ }
+
+ /* timeout each second and check the timeout */
+ switch (Curl_select(tunnelsocket, CURL_SOCKET_BAD, 1000)) {
+ case -1: /* select() error, stop reading */
+ error = SELECT_ERROR;
+ failf(data, "Proxy CONNECT aborted due to select() error");
+ break;
+ case 0: /* timeout */
+ break;
+ default:
+ res = Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread, &gotbytes);
+ if(res< 0)
+ /* EWOULDBLOCK */
+ continue; /* go loop yourself */
+ else if(res)
+ keepon = FALSE;
+ else if(gotbytes <= 0) {
+ keepon = FALSE;
+ error = SELECT_ERROR;
+ failf(data, "Proxy CONNECT aborted");
+ }
+ else {
+ /*
+ * We got a whole chunk of data, which can be anything from one byte
+ * to a set of lines and possibly just a piece of the last line.
+ */
+ int i;
+
+ nread += gotbytes;
+
+ if(keepon > TRUE) {
+ /* This means we are currently ignoring a response-body, so we
+ simply count down our counter and make sure to break out of the
+ loop when we're done! */
+ cl -= gotbytes;
+ if(cl<=0) {
+ keepon = FALSE;
+ break;
+ }
+ }
+ else
+ for(i = 0; i < gotbytes; ptr++, i++) {
+ perline++; /* amount of bytes in this line so far */
+ if(*ptr=='\n') {
+ char letter;
+ int writetype;
+
+ /* output debug if that is requested */
+ if(data->set.verbose)
+ Curl_debug(data, CURLINFO_HEADER_IN,
+ line_start, (size_t)perline, conn);
+
+ /* send the header to the callback */
+ writetype = CLIENTWRITE_HEADER;
+ if(data->set.include_header)
+ writetype |= CLIENTWRITE_BODY;
+
+ result = Curl_client_write(conn, writetype, line_start, perline);
+ if(result)
+ return result;
+
+ /* Newlines are CRLF, so the CR is ignored as the line isn't
+ really terminated until the LF comes. Treat a following CR
+ as end-of-headers as well.*/
+
+ if(('\r' == line_start[0]) ||
+ ('\n' == line_start[0])) {
+ /* end of response-headers from the proxy */
+ if(cl && (407 == k->httpcode) && !data->state.authproblem) {
+ /* If we get a 407 response code with content length when we
+ * have no auth problem, we must ignore the whole
+ * response-body */
+ keepon = 2;
+ infof(data, "Ignore %" FORMAT_OFF_T
+ " bytes of response-body\n", cl);
+ cl -= (gotbytes - i);/* remove the remaining chunk of what
+ we already read */
+ if(cl<=0)
+ /* if the whole thing was already read, we are done! */
+ keepon=FALSE;
+ }
+ else
+ keepon = FALSE;
+ break; /* breaks out of for-loop, not switch() */
+ }
+
+ /* keep a backup of the position we are about to blank */
+ letter = line_start[perline];
+ line_start[perline]=0; /* zero terminate the buffer */
+ if((checkprefix("WWW-Authenticate:", line_start) &&
+ (401 == k->httpcode)) ||
+ (checkprefix("Proxy-authenticate:", line_start) &&
+ (407 == k->httpcode))) {
+ result = Curl_http_input_auth(conn, k->httpcode, line_start);
+ if(result)
+ return result;
+ }
+ else if(checkprefix("Content-Length:", line_start)) {
+ cl = curlx_strtoofft(line_start + strlen("Content-Length:"),
+ NULL, 10);
+ }
+ else if(Curl_compareheader(line_start,
+ "Connection:", "close"))
+ closeConnection = TRUE;
+ else if(2 == sscanf(line_start, "HTTP/1.%d %d",
+ &subversion,
+ &k->httpcode)) {
+ /* store the HTTP code from the proxy */
+ data->info.httpproxycode = k->httpcode;
+ }
+ /* put back the letter we blanked out before */
+ line_start[perline]= letter;
+
+ perline=0; /* line starts over here */
+ line_start = ptr+1; /* this skips the zero byte we wrote */
+ }
+ }
+ }
+ break;
+ } /* switch */
+ } /* while there's buffer left and loop is requested */
+
+ if(error)
+ return CURLE_RECV_ERROR;
+
+ if(data->info.httpproxycode != 200)
+ /* Deal with the possibly already received authenticate
+ headers. 'newurl' is set to a new URL if we must loop. */
+ Curl_http_auth_act(conn);
+
+ if (closeConnection && data->reqdata.newurl) {
+ /* Connection closed by server. Don't use it anymore */
+ sclose(conn->sock[sockindex]);
+ conn->sock[sockindex] = CURL_SOCKET_BAD;
+ break;
+ }
+ } while(data->reqdata.newurl);
+
+ if(200 != k->httpcode) {
+ failf(data, "Received HTTP code %d from proxy after CONNECT",
+ k->httpcode);
+
+ if (closeConnection && data->reqdata.newurl)
+ conn->bits.proxy_connect_closed = TRUE;
+
+ return CURLE_RECV_ERROR;
+ }
+
+ /* If a proxy-authorization header was used for the proxy, then we should
+ make sure that it isn't accidentally used for the document request
+ after we've connected. So let's free and clear it here. */
+ Curl_safefree(conn->allocptr.proxyuserpwd);
+ conn->allocptr.proxyuserpwd = NULL;
+
+ data->state.authproxy.done = TRUE;
+
+ infof (data, "Proxy replied OK to CONNECT request\n");
+ return CURLE_OK;
+}
+
+/*
+ * Curl_http_connect() performs HTTP stuff to do at connect-time, called from
+ * the generic Curl_connect().
+ */
+CURLcode Curl_http_connect(struct connectdata *conn, bool *done)
+{
+ struct SessionHandle *data;
+ CURLcode result;
+
+ data=conn->data;
+
+ /* If we are not using a proxy and we want a secure connection, perform SSL
+ * initialization & connection now. If using a proxy with https, then we
+ * must tell the proxy to CONNECT to the host we want to talk to. Only
+ * after the connect has occurred, can we start talking SSL
+ */
+
+ if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
+
+ /* either SSL over proxy, or explicitly asked for */
+ result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
+ conn->host.name,
+ conn->remote_port);
+ if(CURLE_OK != result)
+ return result;
+ }
+
+ if(!data->state.this_is_a_follow) {
+ /* this is not a followed location, get the original host name */
+ if (data->state.first_host)
+ /* Free to avoid leaking memory on multiple requests*/
+ free(data->state.first_host);
+
+ data->state.first_host = strdup(conn->host.name);
+ if(!data->state.first_host)
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ if(conn->protocol & PROT_HTTPS) {
+ /* perform SSL initialization */
+ if(data->state.used_interface == Curl_if_multi) {
+ result = Curl_https_connecting(conn, done);
+ if(result)
+ return result;
+ }
+ else {
+ /* BLOCKING */
+ result = Curl_ssl_connect(conn, FIRSTSOCKET);
+ if(result)
+ return result;
+ *done = TRUE;
+ }
+ }
+ else {
+ *done = TRUE;
+ }
+
+ return CURLE_OK;
+}
+
+CURLcode Curl_https_connecting(struct connectdata *conn, bool *done)
+{
+ CURLcode result;
+ curlassert(conn->protocol & PROT_HTTPS);
+
+ /* perform SSL initialization for this socket */
+ result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, done);
+ if(result)
+ return result;
+
+ return CURLE_OK;
+}
+
+#ifdef USE_SSLEAY
+/* This function is OpenSSL-specific. It should be made to query the generic
+ SSL layer instead. */
+int Curl_https_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
+{
+ if (conn->protocol & PROT_HTTPS) {
+ struct ssl_connect_data *connssl = &conn->ssl[FIRSTSOCKET];
+
+ if(!numsocks)
+ return GETSOCK_BLANK;
+
+ if (connssl->connecting_state == ssl_connect_2_writing) {
+ /* write mode */
+ socks[0] = conn->sock[FIRSTSOCKET];
+ return GETSOCK_WRITESOCK(0);
+ }
+ else if (connssl->connecting_state == ssl_connect_2_reading) {
+ /* read mode */
+ socks[0] = conn->sock[FIRSTSOCKET];
+ return GETSOCK_READSOCK(0);
+ }
+ }
+ return CURLE_OK;
+}
+#else
+#ifdef USE_GNUTLS
+int Curl_https_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
+{
+ (void)conn;
+ (void)socks;
+ (void)numsocks;
+ return GETSOCK_BLANK;
+}
+#endif
+#endif
+
+/*
+ * Curl_http_done() gets called from Curl_done() after a single HTTP request
+ * has been performed.
+ */
+
+CURLcode Curl_http_done(struct connectdata *conn,
+ CURLcode status, bool premature)
+{
+ struct SessionHandle *data = conn->data;
+ struct HTTP *http =data->reqdata.proto.http;
+ struct Curl_transfer_keeper *k = &data->reqdata.keep;
+ (void)premature; /* not used */
+
+ /* set the proper values (possibly modified on POST) */
+ conn->fread = data->set.fread; /* restore */
+ conn->fread_in = data->set.in; /* restore */
+
+ if (http == NULL)
+ return CURLE_OK;
+
+ if(http->send_buffer) {
+ send_buffer *buff = http->send_buffer;
+
+ free(buff->buffer);
+ free(buff);
+ http->send_buffer = NULL; /* clear the pointer */
+ }
+
+ if(HTTPREQ_POST_FORM == data->set.httpreq) {
+ k->bytecount = http->readbytecount + http->writebytecount;
+
+ Curl_formclean(&http->sendit); /* Now free that whole lot */
+ if(http->form.fp) {
+ /* a file being uploaded was left opened, close it! */
+ fclose(http->form.fp);
+ http->form.fp = NULL;
+ }
+ }
+ else if(HTTPREQ_PUT == data->set.httpreq)
+ k->bytecount = http->readbytecount + http->writebytecount;
+
+ if (status != CURLE_OK)
+ return (status);
+
+ if(!conn->bits.retry &&
+ ((http->readbytecount +
+ conn->headerbytecount -
+ conn->deductheadercount)) <= 0) {
+ /* If this connection isn't simply closed to be retried, AND nothing was
+ read from the HTTP server (that counts), this can't be right so we
+ return an error here */
+ failf(data, "Empty reply from server");
+ return CURLE_GOT_NOTHING;
+ }
+
+ return CURLE_OK;
+}
+
+/* check and possibly add an Expect: header */
+static CURLcode expect100(struct SessionHandle *data,
+ send_buffer *req_buffer)
+{
+ CURLcode result = CURLE_OK;
+ data->state.expect100header = FALSE; /* default to false unless it is set
+ to TRUE below */
+ if((data->set.httpversion != CURL_HTTP_VERSION_1_0) &&
+ !checkheaders(data, "Expect:")) {
+ /* if not doing HTTP 1.0 or disabled explicitly, we add a Expect:
+ 100-continue to the headers which actually speeds up post
+ operations (as there is one packet coming back from the web
+ server) */
+ result = add_bufferf(req_buffer,
+ "Expect: 100-continue\r\n");
+ if(result == CURLE_OK)
+ data->state.expect100header = TRUE;
+ }
+ return result;
+}
+
+static CURLcode add_custom_headers(struct connectdata *conn,
+ send_buffer *req_buffer)
+{
+ CURLcode result = CURLE_OK;
+ char *ptr;
+ struct curl_slist *headers=conn->data->set.headers;
+
+ while(headers) {
+ ptr = strchr(headers->data, ':');
+ if(ptr) {
+ /* we require a colon for this to be a true header */
+
+ ptr++; /* pass the colon */
+ while(*ptr && ISSPACE(*ptr))
+ ptr++;
+
+ if(*ptr) {
+ /* only send this if the contents was non-blank */
+
+ if(conn->allocptr.host &&
+ /* a Host: header was sent already, don't pass on any custom Host:
+ header as that will produce *two* in the same request! */
+ curl_strnequal("Host:", headers->data, 5))
+ ;
+ else if(conn->data->set.httpreq == HTTPREQ_POST_FORM &&
+ /* this header (extended by formdata.c) is sent later */
+ curl_strnequal("Content-Type:", headers->data,
+ strlen("Content-Type:")))
+ ;
+ else {
+ result = add_bufferf(req_buffer, "%s\r\n", headers->data);
+ if(result)
+ return result;
+ }
+ }
+ }
+ headers = headers->next;
+ }
+ return result;
+}
+
+/*
+ * Curl_http() gets called from the generic Curl_do() function when a HTTP
+ * request is to be performed. This creates and sends a properly constructed
+ * HTTP request.
+ */
+CURLcode Curl_http(struct connectdata *conn, bool *done)
+{
+ struct SessionHandle *data=conn->data;
+ char *buf = data->state.buffer; /* this is a short cut to the buffer */
+ CURLcode result=CURLE_OK;
+ struct HTTP *http;
+ char *ppath = data->reqdata.path;
+ char *host = conn->host.name;
+ const char *te = ""; /* transfer-encoding */
+ char *ptr;
+ char *request;
+ Curl_HttpReq httpreq = data->set.httpreq;
+ char *addcookies = NULL;
+ curl_off_t included_body = 0;
+
+ /* Always consider the DO phase done after this function call, even if there
+ may be parts of the request that is not yet sent, since we can deal with
+ the rest of the request in the PERFORM phase. */
+ *done = TRUE;
+
+ if(!data->reqdata.proto.http) {
+ /* Only allocate this struct if we don't already have it! */
+
+ http = (struct HTTP *)malloc(sizeof(struct HTTP));
+ if(!http)
+ return CURLE_OUT_OF_MEMORY;
+ memset(http, 0, sizeof(struct HTTP));
+ data->reqdata.proto.http = http;
+ }
+ else
+ http = data->reqdata.proto.http;
+
+ /* We default to persistent connections */
+ conn->bits.close = FALSE;
+
+ if ( (conn->protocol&(PROT_HTTP|PROT_FTP)) &&
+ data->set.upload) {
+ httpreq = HTTPREQ_PUT;
+ }
+
+ /* Now set the 'request' pointer to the proper request string */
+ if(data->set.customrequest)
+ request = data->set.customrequest;
+ else {
+ if(conn->bits.no_body)
+ request = (char *)"HEAD";
+ else {
+ curlassert((httpreq > HTTPREQ_NONE) && (httpreq < HTTPREQ_LAST));
+ switch(httpreq) {
+ case HTTPREQ_POST:
+ case HTTPREQ_POST_FORM:
+ request = (char *)"POST";
+ break;
+ case HTTPREQ_PUT:
+ request = (char *)"PUT";
+ break;
+ default: /* this should never happen */
+ case HTTPREQ_GET:
+ request = (char *)"GET";
+ break;
+ case HTTPREQ_HEAD:
+ request = (char *)"HEAD";
+ break;
+ }
+ }
+ }
+
+ /* The User-Agent string might have been allocated in url.c already, because
+ it might have been used in the proxy connect, but if we have got a header
+ with the user-agent string specified, we erase the previously made string
+ here. */
+ if(checkheaders(data, "User-Agent:") && conn->allocptr.uagent) {
+ free(conn->allocptr.uagent);
+ conn->allocptr.uagent=NULL;
+ }
+
+ /* setup the authentication headers */
+ result = Curl_http_output_auth(conn, request, ppath, FALSE);
+ if(result)
+ return result;
+
+ if((data->state.authhost.multi || data->state.authproxy.multi) &&
+ (httpreq != HTTPREQ_GET) &&
+ (httpreq != HTTPREQ_HEAD)) {
+ /* Auth is required and we are not authenticated yet. Make a PUT or POST
+ with content-length zero as a "probe". */
+ conn->bits.authneg = TRUE;
+ }
+ else
+ conn->bits.authneg = FALSE;
+
+ Curl_safefree(conn->allocptr.ref);
+ if(data->change.referer && !checkheaders(data, "Referer:"))
+ conn->allocptr.ref = aprintf("Referer: %s\r\n", data->change.referer);
+ else
+ conn->allocptr.ref = NULL;
+
+ if(data->set.cookie && !checkheaders(data, "Cookie:"))
+ addcookies = data->set.cookie;
+
+ if(!checkheaders(data, "Accept-Encoding:") &&
+ data->set.encoding) {
+ Curl_safefree(conn->allocptr.accept_encoding);
+ conn->allocptr.accept_encoding =
+ aprintf("Accept-Encoding: %s\r\n", data->set.encoding);
+ if(!conn->allocptr.accept_encoding)
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ ptr = checkheaders(data, "Transfer-Encoding:");
+ if(ptr) {
+ /* Some kind of TE is requested, check if 'chunked' is chosen */
+ conn->bits.upload_chunky =
+ Curl_compareheader(ptr, "Transfer-Encoding:", "chunked");
+ }
+ else {
+ if (httpreq == HTTPREQ_GET)
+ conn->bits.upload_chunky = FALSE;
+ if(conn->bits.upload_chunky)
+ te = "Transfer-Encoding: chunked\r\n";
+ }
+
+ Curl_safefree(conn->allocptr.host);
+
+ ptr = checkheaders(data, "Host:");
+ if(ptr && (!data->state.this_is_a_follow ||
+ curl_strequal(data->state.first_host, conn->host.name))) {
+#if !defined(CURL_DISABLE_COOKIES)
+ /* If we have a given custom Host: header, we extract the host name in
+ order to possibly use it for cookie reasons later on. We only allow the
+ custom Host: header if this is NOT a redirect, as setting Host: in the
+ redirected request is being out on thin ice. Except if the host name
+ is the same as the first one! */
+ char *start = ptr+strlen("Host:");
+ while(*start && ISSPACE(*start ))
+ start++;
+ ptr = start; /* start host-scanning here */
+
+ /* scan through the string to find the end (space or colon) */
+ while(*ptr && !ISSPACE(*ptr) && !(':'==*ptr))
+ ptr++;
+
+ if(ptr != start) {
+ size_t len=ptr-start;
+ Curl_safefree(conn->allocptr.cookiehost);
+ conn->allocptr.cookiehost = malloc(len+1);
+ if(!conn->allocptr.cookiehost)
+ return CURLE_OUT_OF_MEMORY;
+ memcpy(conn->allocptr.cookiehost, start, len);
+ conn->allocptr.cookiehost[len]=0;
+ }
+#endif
+
+ conn->allocptr.host = NULL;
+ }
+ else {
+ /* When building Host: headers, we must put the host name within
+ [brackets] if the host name is a plain IPv6-address. RFC2732-style. */
+
+ if(((conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTPS)) ||
+ (!(conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTP)) )
+ /* If (HTTPS on port 443) OR (non-HTTPS on port 80) then don't include
+ the port number in the host string */
+ conn->allocptr.host = aprintf("Host: %s%s%s\r\n",
+ conn->bits.ipv6_ip?"[":"",
+ host,
+ conn->bits.ipv6_ip?"]":"");
+ else
+ conn->allocptr.host = aprintf("Host: %s%s%s:%d\r\n",
+ conn->bits.ipv6_ip?"[":"",
+ host,
+ conn->bits.ipv6_ip?"]":"",
+ conn->remote_port);
+
+ if(!conn->allocptr.host)
+ /* without Host: we can't make a nice request */
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ if (conn->bits.httpproxy && !conn->bits.tunnel_proxy) {
+ /* Using a proxy but does not tunnel through it */
+
+ /* The path sent to the proxy is in fact the entire URL. But if the remote
+ host is a IDN-name, we must make sure that the request we produce only
+ uses the encoded host name! */
+ if(conn->host.dispname != conn->host.name) {
+ char *url = data->change.url;
+ ptr = strstr(url, conn->host.dispname);
+ if(ptr) {
+ /* This is where the display name starts in the URL, now replace this
+ part with the encoded name. TODO: This method of replacing the host
+ name is rather crude as I believe there's a slight risk that the
+ user has entered a user name or password that contain the host name
+ string. */
+ size_t currlen = strlen(conn->host.dispname);
+ size_t newlen = strlen(conn->host.name);
+ size_t urllen = strlen(url);
+
+ char *newurl;
+
+ newurl = malloc(urllen + newlen - currlen + 1);
+ if(newurl) {
+ /* copy the part before the host name */
+ memcpy(newurl, url, ptr - url);
+ /* append the new host name instead of the old */
+ memcpy(newurl + (ptr - url), conn->host.name, newlen);
+ /* append the piece after the host name */
+ memcpy(newurl + newlen + (ptr - url),
+ ptr + currlen, /* copy the trailing zero byte too */
+ urllen - (ptr-url) - currlen + 1);
+ if(data->change.url_alloc)
+ free(data->change.url);
+ data->change.url = newurl;
+ data->change.url_alloc = TRUE;
+ }
+ else
+ return CURLE_OUT_OF_MEMORY;
+ }
+ }
+ ppath = data->change.url;
+ }
+ if(HTTPREQ_POST_FORM == httpreq) {
+ /* we must build the whole darned post sequence first, so that we have
+ a size of the whole shebang before we start to send it */
+ result = Curl_getFormData(&http->sendit, data->set.httppost,
+ checkheaders(data, "Content-Type:"),
+ &http->postsize);
+ if(CURLE_OK != result) {
+ /* Curl_getFormData() doesn't use failf() */
+ failf(data, "failed creating formpost data");
+ return result;
+ }
+ }
+
+
+ http->p_pragma =
+ (!checkheaders(data, "Pragma:") &&
+ (conn->bits.httpproxy && !conn->bits.tunnel_proxy) )?
+ "Pragma: no-cache\r\n":NULL;
+
+ if(!checkheaders(data, "Accept:"))
+ http->p_accept = "Accept: */*\r\n";
+
+ if(( (HTTPREQ_POST == httpreq) ||
+ (HTTPREQ_POST_FORM == httpreq) ||
+ (HTTPREQ_PUT == httpreq) ) &&
+ data->reqdata.resume_from) {
+ /**********************************************************************
+ * Resuming upload in HTTP means that we PUT or POST and that we have
+ * got a resume_from value set. The resume value has already created
+ * a Range: header that will be passed along. We need to "fast forward"
+ * the file the given number of bytes and decrease the assume upload
+ * file size before we continue this venture in the dark lands of HTTP.
+ *********************************************************************/
+
+ if(data->reqdata.resume_from < 0 ) {
+ /*
+ * This is meant to get the size of the present remote-file by itself.
+ * We don't support this now. Bail out!
+ */
+ data->reqdata.resume_from = 0;
+ }
+
+ if(data->reqdata.resume_from) {
+ /* do we still game? */
+ curl_off_t passed=0;
+
+ /* Now, let's read off the proper amount of bytes from the
+ input. If we knew it was a proper file we could've just
+ fseek()ed but we only have a stream here */
+ do {
+ size_t readthisamountnow = (size_t)(data->reqdata.resume_from - passed);
+ size_t actuallyread;
+
+ if(readthisamountnow > BUFSIZE)
+ readthisamountnow = BUFSIZE;
+
+ actuallyread =
+ data->set.fread(data->state.buffer, 1, (size_t)readthisamountnow,
+ data->set.in);
+
+ passed += actuallyread;
+ if(actuallyread != readthisamountnow) {
+ failf(data, "Could only read %" FORMAT_OFF_T
+ " bytes from the input",
+ passed);
+ return CURLE_READ_ERROR;
+ }
+ } while(passed != data->reqdata.resume_from); /* loop until done */
+
+ /* now, decrease the size of the read */
+ if(data->set.infilesize>0) {
+ data->set.infilesize -= data->reqdata.resume_from;
+
+ if(data->set.infilesize <= 0) {
+ failf(data, "File already completely uploaded");
+ return CURLE_PARTIAL_FILE;
+ }
+ }
+ /* we've passed, proceed as normal */
+ }
+ }
+ if(data->reqdata.use_range) {
+ /*
+ * A range is selected. We use different headers whether we're downloading
+ * or uploading and we always let customized headers override our internal
+ * ones if any such are specified.
+ */
+ if((httpreq == HTTPREQ_GET) &&
+ !checkheaders(data, "Range:")) {
+ /* if a line like this was already allocated, free the previous one */
+ if(conn->allocptr.rangeline)
+ free(conn->allocptr.rangeline);
+ conn->allocptr.rangeline = aprintf("Range: bytes=%s\r\n", data->reqdata.range);
+ }
+ else if((httpreq != HTTPREQ_GET) &&
+ !checkheaders(data, "Content-Range:")) {
+
+ if(data->reqdata.resume_from) {
+ /* This is because "resume" was selected */
+ curl_off_t total_expected_size=
+ data->reqdata.resume_from + data->set.infilesize;
+ conn->allocptr.rangeline =
+ aprintf("Content-Range: bytes %s%" FORMAT_OFF_T
+ "/%" FORMAT_OFF_T "\r\n",
+ data->reqdata.range, total_expected_size-1,
+ total_expected_size);
+ }
+ else {
+ /* Range was selected and then we just pass the incoming range and
+ append total size */
+ conn->allocptr.rangeline =
+ aprintf("Content-Range: bytes %s/%" FORMAT_OFF_T "\r\n",
+ data->reqdata.range, data->set.infilesize);
+ }
+ }
+ }
+
+ {
+ /* Use 1.1 unless the use specificly asked for 1.0 */
+ const char *httpstring=
+ data->set.httpversion==CURL_HTTP_VERSION_1_0?"1.0":"1.1";
+
+ send_buffer *req_buffer;
+ curl_off_t postsize; /* off_t type to be able to hold a large file size */
+
+ /* initialize a dynamic send-buffer */
+ req_buffer = add_buffer_init();
+
+ if(!req_buffer)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* add the main request stuff */
+ result =
+ add_bufferf(req_buffer,
+ "%s " /* GET/HEAD/POST/PUT */
+ "%s HTTP/%s\r\n" /* path + HTTP version */
+ "%s" /* proxyuserpwd */
+ "%s" /* userpwd */
+ "%s" /* range */
+ "%s" /* user agent */
+ "%s" /* host */
+ "%s" /* pragma */
+ "%s" /* accept */
+ "%s" /* accept-encoding */
+ "%s" /* referer */
+ "%s" /* Proxy-Connection */
+ "%s",/* transfer-encoding */
+
+ request,
+ ppath,
+ httpstring,
+ conn->allocptr.proxyuserpwd?
+ conn->allocptr.proxyuserpwd:"",
+ conn->allocptr.userpwd?conn->allocptr.userpwd:"",
+ (data->reqdata.use_range && conn->allocptr.rangeline)?
+ conn->allocptr.rangeline:"",
+ (data->set.useragent && *data->set.useragent && conn->allocptr.uagent)?
+ conn->allocptr.uagent:"",
+ (conn->allocptr.host?conn->allocptr.host:""), /* Host: host */
+ http->p_pragma?http->p_pragma:"",
+ http->p_accept?http->p_accept:"",
+ (data->set.encoding && *data->set.encoding && conn->allocptr.accept_encoding)?
+ conn->allocptr.accept_encoding:"",
+ (data->change.referer && conn->allocptr.ref)?conn->allocptr.ref:"" /* Referer: <data> */,
+ (conn->bits.httpproxy &&
+ !conn->bits.tunnel_proxy &&
+ !checkheaders(data, "Proxy-Connection:"))?
+ "Proxy-Connection: Keep-Alive\r\n":"",
+ te
+ );
+
+ if(result)
+ return result;
+
+#if !defined(CURL_DISABLE_COOKIES)
+ if(data->cookies || addcookies) {
+ struct Cookie *co=NULL; /* no cookies from start */
+ int count=0;
+
+ if(data->cookies) {
+ Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
+ co = Curl_cookie_getlist(data->cookies,
+ conn->allocptr.cookiehost?
+ conn->allocptr.cookiehost:host, data->reqdata.path,
+ (bool)(conn->protocol&PROT_HTTPS?TRUE:FALSE));
+ Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
+ }
+ if(co) {
+ struct Cookie *store=co;
+ /* now loop through all cookies that matched */
+ while(co) {
+ if(co->value) {
+ if(0 == count) {
+ result = add_bufferf(req_buffer, "Cookie: ");
+ if(result)
+ break;
+ }
+ result = add_bufferf(req_buffer,
+ "%s%s=%s", count?"; ":"",
+ co->name, co->value);
+ if(result)
+ break;
+ count++;
+ }
+ co = co->next; /* next cookie please */
+ }
+ Curl_cookie_freelist(store); /* free the cookie list */
+ }
+ if(addcookies && (CURLE_OK == result)) {
+ if(!count)
+ result = add_bufferf(req_buffer, "Cookie: ");
+ if(CURLE_OK == result) {
+ result = add_bufferf(req_buffer, "%s%s",
+ count?"; ":"",
+ addcookies);
+ count++;
+ }
+ }
+ if(count && (CURLE_OK == result))
+ result = add_buffer(req_buffer, "\r\n", 2);
+
+ if(result)
+ return result;
+ }
+#endif
+
+ if(data->set.timecondition) {
+ struct tm *tm;
+
+ /* Phil Karn (Fri, 13 Apr 2001) pointed out that the If-Modified-Since
+ * header family should have their times set in GMT as RFC2616 defines:
+ * "All HTTP date/time stamps MUST be represented in Greenwich Mean Time
+ * (GMT), without exception. For the purposes of HTTP, GMT is exactly
+ * equal to UTC (Coordinated Universal Time)." (see page 20 of RFC2616).
+ */
+
+#ifdef HAVE_GMTIME_R
+ /* thread-safe version */
+ struct tm keeptime;
+ tm = (struct tm *)gmtime_r(&data->set.timevalue, &keeptime);
+#else
+ tm = gmtime(&data->set.timevalue);
+#endif
+
+ /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
+ snprintf(buf, BUFSIZE-1,
+ "%s, %02d %s %4d %02d:%02d:%02d GMT",
+ Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
+ tm->tm_mday,
+ Curl_month[tm->tm_mon],
+ tm->tm_year + 1900,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec);
+
+ switch(data->set.timecondition) {
+ case CURL_TIMECOND_IFMODSINCE:
+ default:
+ result = add_bufferf(req_buffer,
+ "If-Modified-Since: %s\r\n", buf);
+ break;
+ case CURL_TIMECOND_IFUNMODSINCE:
+ result = add_bufferf(req_buffer,
+ "If-Unmodified-Since: %s\r\n", buf);
+ break;
+ case CURL_TIMECOND_LASTMOD:
+ result = add_bufferf(req_buffer,
+ "Last-Modified: %s\r\n", buf);
+ break;
+ }
+ if(result)
+ return result;
+ }
+
+ result = add_custom_headers(conn, req_buffer);
+ if(result)
+ return result;
+
+ http->postdata = NULL; /* nothing to post at this point */
+ Curl_pgrsSetUploadSize(data, 0); /* upload size is 0 atm */
+
+ /* If 'authdone' is FALSE, we must not set the write socket index to the
+ Curl_transfer() call below, as we're not ready to actually upload any
+ data yet. */
+
+ switch(httpreq) {
+
+ case HTTPREQ_POST_FORM:
+ if(!http->sendit || conn->bits.authneg) {
+ /* nothing to post! */
+ result = add_bufferf(req_buffer, "Content-Length: 0\r\n\r\n");
+ if(result)
+ return result;
+
+ result = add_buffer_send(req_buffer, conn,
+ &data->info.request_size, 0, FIRSTSOCKET);
+ if(result)
+ failf(data, "Failed sending POST request");
+ else
+ /* setup variables for the upcoming transfer */
+ result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
+ &http->readbytecount,
+ -1, NULL);
+ break;
+ }
+
+ if(Curl_FormInit(&http->form, http->sendit)) {
+ failf(data, "Internal HTTP POST error!");
+ return CURLE_HTTP_POST_ERROR;
+ }
+
+ /* set the read function to read from the generated form data */
+ conn->fread = (curl_read_callback)Curl_FormReader;
+ conn->fread_in = &http->form;
+
+ http->sending = HTTPSEND_BODY;
+
+ if(!conn->bits.upload_chunky) {
+ /* only add Content-Length if not uploading chunked */
+ result = add_bufferf(req_buffer,
+ "Content-Length: %" FORMAT_OFF_T "\r\n",
+ http->postsize);
+ if(result)
+ return result;
+ }
+
+ result = expect100(data, req_buffer);
+ if(result)
+ return result;
+
+ {
+
+ /* Get Content-Type: line from Curl_formpostheader.
+ */
+ char *contentType;
+ size_t linelength=0;
+ contentType = Curl_formpostheader((void *)&http->form,
+ &linelength);
+ if(!contentType) {
+ failf(data, "Could not get Content-Type header line!");
+ return CURLE_HTTP_POST_ERROR;
+ }
+
+ result = add_buffer(req_buffer, contentType, linelength);
+ if(result)
+ return result;
+ }
+
+ /* make the request end in a true CRLF */
+ result = add_buffer(req_buffer, "\r\n", 2);
+ if(result)
+ return result;
+
+ /* set upload size to the progress meter */
+ Curl_pgrsSetUploadSize(data, http->postsize);
+
+ /* fire away the whole request to the server */
+ result = add_buffer_send(req_buffer, conn,
+ &data->info.request_size, 0, FIRSTSOCKET);
+ if(result)
+ failf(data, "Failed sending POST request");
+ else
+ /* setup variables for the upcoming transfer */
+ result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
+ &http->readbytecount,
+ FIRSTSOCKET,
+ &http->writebytecount);
+
+ if(result) {
+ Curl_formclean(&http->sendit); /* free that whole lot */
+ return result;
+ }
+#ifdef CURL_DOES_CONVERSIONS
+/* time to convert the form data... */
+ result = Curl_formconvert(data, http->sendit);
+ if(result) {
+ Curl_formclean(&http->sendit); /* free that whole lot */
+ return result;
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+ break;
+
+ case HTTPREQ_PUT: /* Let's PUT the data to the server! */
+
+ if(conn->bits.authneg)
+ postsize = 0;
+ else
+ postsize = data->set.infilesize;
+
+ if((postsize != -1) && !conn->bits.upload_chunky) {
+ /* only add Content-Length if not uploading chunked */
+ result = add_bufferf(req_buffer,
+ "Content-Length: %" FORMAT_OFF_T "\r\n",
+ postsize );
+ if(result)
+ return result;
+ }
+
+ result = expect100(data, req_buffer);
+ if(result)
+ return result;
+
+ result = add_buffer(req_buffer, "\r\n", 2); /* end of headers */
+ if(result)
+ return result;
+
+ /* set the upload size to the progress meter */
+ Curl_pgrsSetUploadSize(data, postsize);
+
+ /* this sends the buffer and frees all the buffer resources */
+ result = add_buffer_send(req_buffer, conn,
+ &data->info.request_size, 0, FIRSTSOCKET);
+ if(result)
+ failf(data, "Failed sending PUT request");
+ else
+ /* prepare for transfer */
+ result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
+ &http->readbytecount,
+ postsize?FIRSTSOCKET:-1,
+ postsize?&http->writebytecount:NULL);
+ if(result)
+ return result;
+ break;
+
+ case HTTPREQ_POST:
+ /* this is the simple POST, using x-www-form-urlencoded style */
+
+ if(conn->bits.authneg)
+ postsize = 0;
+ else
+ /* figure out the size of the postfields */
+ postsize = (data->set.postfieldsize != -1)?
+ data->set.postfieldsize:
+ (data->set.postfields?(curl_off_t)strlen(data->set.postfields):0);
+
+ if(!conn->bits.upload_chunky) {
+ /* We only set Content-Length and allow a custom Content-Length if
+ we don't upload data chunked, as RFC2616 forbids us to set both
+ kinds of headers (Transfer-Encoding: chunked and Content-Length) */
+
+ if(!checkheaders(data, "Content-Length:")) {
+ /* we allow replacing this header, although it isn't very wise to
+ actually set your own */
+ result = add_bufferf(req_buffer,
+ "Content-Length: %" FORMAT_OFF_T"\r\n",
+ postsize);
+ if(result)
+ return result;
+ }
+ }
+
+ if(!checkheaders(data, "Content-Type:")) {
+ result = add_bufferf(req_buffer,
+ "Content-Type: application/x-www-form-urlencoded\r\n");
+ if(result)
+ return result;
+ }
+
+ if(data->set.postfields) {
+
+ /* for really small posts we don't use Expect: headers at all, and for
+ the somewhat bigger ones we allow the app to disable it */
+ if(postsize > TINY_INITIAL_POST_SIZE) {
+ result = expect100(data, req_buffer);
+ if(result)
+ return result;
+ }
+ else
+ data->state.expect100header = FALSE;
+
+ if(!data->state.expect100header &&
+ (postsize < MAX_INITIAL_POST_SIZE)) {
+ /* if we don't use expect:-100 AND
+ postsize is less than MAX_INITIAL_POST_SIZE
+
+ then append the post data to the HTTP request header. This limit
+ is no magic limit but only set to prevent really huge POSTs to
+ get the data duplicated with malloc() and family. */
+
+ result = add_buffer(req_buffer, "\r\n", 2); /* end of headers! */
+ if(result)
+ return result;
+
+ if(!conn->bits.upload_chunky) {
+ /* We're not sending it 'chunked', append it to the request
+ already now to reduce the number if send() calls */
+ result = add_buffer(req_buffer, data->set.postfields,
+ (size_t)postsize);
+ included_body = postsize;
+ }
+ else {
+ /* Append the POST data chunky-style */
+ result = add_bufferf(req_buffer, "%x\r\n", (int)postsize);
+ if(CURLE_OK == result)
+ result = add_buffer(req_buffer, data->set.postfields,
+ (size_t)postsize);
+ if(CURLE_OK == result)
+ result = add_buffer(req_buffer,
+ "\x0d\x0a\x30\x0d\x0a\x0d\x0a", 7);
+ /* CR LF 0 CR LF CR LF */
+ included_body = postsize + 7;
+ }
+ if(result)
+ return result;
+ }
+ else {
+ /* A huge POST coming up, do data separate from the request */
+ http->postsize = postsize;
+ http->postdata = data->set.postfields;
+
+ http->sending = HTTPSEND_BODY;
+
+ conn->fread = (curl_read_callback)readmoredata;
+ conn->fread_in = (void *)conn;
+
+ /* set the upload size to the progress meter */
+ Curl_pgrsSetUploadSize(data, http->postsize);
+
+ add_buffer(req_buffer, "\r\n", 2); /* end of headers! */
+ }
+ }
+ else {
+ add_buffer(req_buffer, "\r\n", 2); /* end of headers! */
+
+ if(data->set.postfieldsize) {
+ /* set the upload size to the progress meter */
+ Curl_pgrsSetUploadSize(data, postsize?postsize:-1);
+
+ /* set the pointer to mark that we will send the post body using
+ the read callback */
+ http->postdata = (char *)&http->postdata;
+ }
+ }
+ /* issue the request */
+ result = add_buffer_send(req_buffer, conn, &data->info.request_size,
+ (size_t)included_body, FIRSTSOCKET);
+
+ if(result)
+ failf(data, "Failed sending HTTP POST request");
+ else
+ result =
+ Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
+ &http->readbytecount,
+ http->postdata?FIRSTSOCKET:-1,
+ http->postdata?&http->writebytecount:NULL);
+ break;
+
+ default:
+ add_buffer(req_buffer, "\r\n", 2);
+
+ /* issue the request */
+ result = add_buffer_send(req_buffer, conn,
+ &data->info.request_size, 0, FIRSTSOCKET);
+
+ if(result)
+ failf(data, "Failed sending HTTP request");
+ else
+ /* HTTP GET/HEAD download: */
+ result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
+ &http->readbytecount,
+ http->postdata?FIRSTSOCKET:-1,
+ http->postdata?&http->writebytecount:NULL);
+ }
+ if(result)
+ return result;
+ }
+
+ return CURLE_OK;
+}
+#endif
diff --git a/Utilities/cmcurl/http.h b/Utilities/cmcurl/http.h
new file mode 100644
index 0000000000..0f4b58f72c
--- /dev/null
+++ b/Utilities/cmcurl/http.h
@@ -0,0 +1,85 @@
+#ifndef __HTTP_H
+#define __HTTP_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#ifndef CURL_DISABLE_HTTP
+bool Curl_compareheader(char *headerline, /* line to check */
+ const char *header, /* header keyword _with_ colon */
+ const char *content); /* content string to find */
+
+/* ftp can use this as well */
+CURLcode Curl_proxyCONNECT(struct connectdata *conn,
+ int tunnelsocket,
+ char *hostname, int remote_port);
+
+/* protocol-specific functions set up to be called by the main engine */
+CURLcode Curl_http(struct connectdata *conn, bool *done);
+CURLcode Curl_http_done(struct connectdata *, CURLcode, bool premature);
+CURLcode Curl_http_connect(struct connectdata *conn, bool *done);
+CURLcode Curl_https_connecting(struct connectdata *conn, bool *done);
+int Curl_https_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks);
+
+/* The following functions are defined in http_chunks.c */
+void Curl_httpchunk_init(struct connectdata *conn);
+CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap,
+ ssize_t length, ssize_t *wrote);
+
+/* These functions are in http.c */
+void Curl_http_auth_stage(struct SessionHandle *data, int stage);
+CURLcode Curl_http_input_auth(struct connectdata *conn,
+ int httpcode, char *header);
+CURLcode Curl_http_auth_act(struct connectdata *conn);
+
+int Curl_http_should_fail(struct connectdata *conn);
+
+/* If only the PICKNONE bit is set, there has been a round-trip and we
+ selected to use no auth at all. Ie, we actively select no auth, as opposed
+ to not having one selected. The other CURLAUTH_* defines are present in the
+ public curl/curl.h header. */
+#define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
+
+/* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST
+ data get included in the initial data chunk sent to the server. If the
+ data is larger than this, it will automatically get split up in multiple
+ system calls.
+
+ This value used to be fairly big (100K), but we must take into account that
+ if the server rejects the POST due for authentication reasons, this data
+ will always be uncondtionally sent and thus it may not be larger than can
+ always be afforded to send twice.
+
+ It must not be greater than 64K to work on VMS.
+*/
+#ifndef MAX_INITIAL_POST_SIZE
+#define MAX_INITIAL_POST_SIZE (64*1024)
+#endif
+
+#ifndef TINY_INITIAL_POST_SIZE
+#define TINY_INITIAL_POST_SIZE 1024
+#endif
+
+#endif
+#endif
diff --git a/Utilities/cmcurl/http_chunks.c b/Utilities/cmcurl/http_chunks.c
new file mode 100644
index 0000000000..1b03a55699
--- /dev/null
+++ b/Utilities/cmcurl/http_chunks.c
@@ -0,0 +1,360 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#include "setup.h"
+
+#ifndef CURL_DISABLE_HTTP
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "urldata.h" /* it includes http_chunks.h */
+#include "sendf.h" /* for the client write stuff */
+
+#include "content_encoding.h"
+#include "http.h"
+#include "memory.h"
+#include "easyif.h" /* for Curl_convert_to_network prototype */
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/*
+ * Chunk format (simplified):
+ *
+ * <HEX SIZE>[ chunk extension ] CRLF
+ * <DATA> CRLF
+ *
+ * Highlights from RFC2616 section 3.6 say:
+
+ The chunked encoding modifies the body of a message in order to
+ transfer it as a series of chunks, each with its own size indicator,
+ followed by an OPTIONAL trailer containing entity-header fields. This
+ allows dynamically produced content to be transferred along with the
+ information necessary for the recipient to verify that it has
+ received the full message.
+
+ Chunked-Body = *chunk
+ last-chunk
+ trailer
+ CRLF
+
+ chunk = chunk-size [ chunk-extension ] CRLF
+ chunk-data CRLF
+ chunk-size = 1*HEX
+ last-chunk = 1*("0") [ chunk-extension ] CRLF
+
+ chunk-extension= *( ";" chunk-ext-name [ "=" chunk-ext-val ] )
+ chunk-ext-name = token
+ chunk-ext-val = token | quoted-string
+ chunk-data = chunk-size(OCTET)
+ trailer = *(entity-header CRLF)
+
+ The chunk-size field is a string of hex digits indicating the size of
+ the chunk. The chunked encoding is ended by any chunk whose size is
+ zero, followed by the trailer, which is terminated by an empty line.
+
+ */
+
+
+void Curl_httpchunk_init(struct connectdata *conn)
+{
+ struct Curl_chunker *chunk = &conn->data->reqdata.proto.http->chunk;
+ chunk->hexindex=0; /* start at 0 */
+ chunk->dataleft=0; /* no data left yet! */
+ chunk->state = CHUNK_HEX; /* we get hex first! */
+}
+
+/*
+ * chunk_read() returns a OK for normal operations, or a positive return code
+ * for errors. STOP means this sequence of chunks is complete. The 'wrote'
+ * argument is set to tell the caller how many bytes we actually passed to the
+ * client (for byte-counting and whatever).
+ *
+ * The states and the state-machine is further explained in the header file.
+ *
+ * This function always uses ASCII hex values to accommodate non-ASCII hosts.
+ * For example, 0x0d and 0x0a are used instead of '\r' and '\n'.
+ */
+CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
+ char *datap,
+ ssize_t datalen,
+ ssize_t *wrotep)
+{
+ CURLcode result=CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ struct Curl_chunker *ch = &data->reqdata.proto.http->chunk;
+ struct Curl_transfer_keeper *k = &data->reqdata.keep;
+ size_t piece;
+ size_t length = (size_t)datalen;
+ size_t *wrote = (size_t *)wrotep;
+
+ *wrote = 0; /* nothing's written yet */
+
+ while(length) {
+ switch(ch->state) {
+ case CHUNK_HEX:
+ /* Check for an ASCII hex digit.
+ We avoid the use of isxdigit to accommodate non-ASCII hosts. */
+ if((*datap >= 0x30 && *datap <= 0x39) /* 0-9 */
+ || (*datap >= 0x41 && *datap <= 0x46) /* A-F */
+ || (*datap >= 0x61 && *datap <= 0x66)) { /* a-f */
+ if(ch->hexindex < MAXNUM_SIZE) {
+ ch->hexbuffer[ch->hexindex] = *datap;
+ datap++;
+ length--;
+ ch->hexindex++;
+ }
+ else {
+ return CHUNKE_TOO_LONG_HEX; /* longer hex than we support */
+ }
+ }
+ else {
+ if(0 == ch->hexindex) {
+ /* This is illegal data, we received junk where we expected
+ a hexadecimal digit. */
+ return CHUNKE_ILLEGAL_HEX;
+ }
+ /* length and datap are unmodified */
+ ch->hexbuffer[ch->hexindex]=0;
+#ifdef CURL_DOES_CONVERSIONS
+ /* convert to host encoding before calling strtoul */
+ result = Curl_convert_from_network(conn->data,
+ ch->hexbuffer,
+ ch->hexindex);
+ if(result != CURLE_OK) {
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ /* Treat it as a bad hex character */
+ return(CHUNKE_ILLEGAL_HEX);
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+ ch->datasize=strtoul(ch->hexbuffer, NULL, 16);
+ ch->state = CHUNK_POSTHEX;
+ }
+ break;
+
+ case CHUNK_POSTHEX:
+ /* In this state, we're waiting for CRLF to arrive. We support
+ this to allow so called chunk-extensions to show up here
+ before the CRLF comes. */
+ if(*datap == 0x0d)
+ ch->state = CHUNK_CR;
+ length--;
+ datap++;
+ break;
+
+ case CHUNK_CR:
+ /* waiting for the LF */
+ if(*datap == 0x0a) {
+ /* we're now expecting data to come, unless size was zero! */
+ if(0 == ch->datasize) {
+ if (conn->bits.trailerHdrPresent!=TRUE) {
+ /* No Trailer: header found - revert to original Curl processing */
+ ch->state = CHUNK_STOP;
+ if (1 == length) {
+ /* This is the final byte, return right now */
+ return CHUNKE_STOP;
+ }
+ }
+ else {
+ ch->state = CHUNK_TRAILER; /* attempt to read trailers */
+ conn->trlPos=0;
+ }
+ }
+ else
+ ch->state = CHUNK_DATA;
+ }
+ else
+ /* previously we got a fake CR, go back to CR waiting! */
+ ch->state = CHUNK_CR;
+ datap++;
+ length--;
+ break;
+
+ case CHUNK_DATA:
+ /* we get pure and fine data
+
+ We expect another 'datasize' of data. We have 'length' right now,
+ it can be more or less than 'datasize'. Get the smallest piece.
+ */
+ piece = (ch->datasize >= length)?length:ch->datasize;
+
+ /* Write the data portion available */
+#ifdef HAVE_LIBZ
+ switch (data->reqdata.keep.content_encoding) {
+ case IDENTITY:
+#endif
+ if(!k->ignorebody)
+ result = Curl_client_write(conn, CLIENTWRITE_BODY, datap,
+ piece);
+#ifdef HAVE_LIBZ
+ break;
+
+ case DEFLATE:
+ /* update data->reqdata.keep.str to point to the chunk data. */
+ data->reqdata.keep.str = datap;
+ result = Curl_unencode_deflate_write(conn, &data->reqdata.keep,
+ (ssize_t)piece);
+ break;
+
+ case GZIP:
+ /* update data->reqdata.keep.str to point to the chunk data. */
+ data->reqdata.keep.str = datap;
+ result = Curl_unencode_gzip_write(conn, &data->reqdata.keep,
+ (ssize_t)piece);
+ break;
+
+ case COMPRESS:
+ default:
+ failf (conn->data,
+ "Unrecognized content encoding type. "
+ "libcurl understands `identity', `deflate' and `gzip' "
+ "content encodings.");
+ return CHUNKE_BAD_ENCODING;
+ }
+#endif
+
+ if(result)
+ return CHUNKE_WRITE_ERROR;
+
+ *wrote += piece;
+
+ ch->datasize -= piece; /* decrease amount left to expect */
+ datap += piece; /* move read pointer forward */
+ length -= piece; /* decrease space left in this round */
+
+ if(0 == ch->datasize)
+ /* end of data this round, we now expect a trailing CRLF */
+ ch->state = CHUNK_POSTCR;
+ break;
+
+ case CHUNK_POSTCR:
+ if(*datap == 0x0d) {
+ ch->state = CHUNK_POSTLF;
+ datap++;
+ length--;
+ }
+ else
+ return CHUNKE_BAD_CHUNK;
+ break;
+
+ case CHUNK_POSTLF:
+ if(*datap == 0x0a) {
+ /*
+ * The last one before we go back to hex state and start all
+ * over.
+ */
+ Curl_httpchunk_init(conn);
+ datap++;
+ length--;
+ }
+ else
+ return CHUNKE_BAD_CHUNK;
+ break;
+
+ case CHUNK_TRAILER:
+ /* conn->trailer is assumed to be freed in url.c on a
+ connection basis */
+ if (conn->trlPos >= conn->trlMax) {
+ char *ptr;
+ if(conn->trlMax) {
+ conn->trlMax *= 2;
+ ptr = (char*)realloc(conn->trailer,conn->trlMax);
+ }
+ else {
+ conn->trlMax=128;
+ ptr = (char*)malloc(conn->trlMax);
+ }
+ if(!ptr)
+ return CHUNKE_OUT_OF_MEMORY;
+ conn->trailer = ptr;
+ }
+ conn->trailer[conn->trlPos++]=*datap;
+
+ if(*datap == 0x0d)
+ ch->state = CHUNK_TRAILER_CR;
+ else {
+ datap++;
+ length--;
+ }
+ break;
+
+ case CHUNK_TRAILER_CR:
+ if(*datap == 0x0d) {
+ ch->state = CHUNK_TRAILER_POSTCR;
+ datap++;
+ length--;
+ }
+ else
+ return CHUNKE_BAD_CHUNK;
+ break;
+
+ case CHUNK_TRAILER_POSTCR:
+ if (*datap == 0x0a) {
+ conn->trailer[conn->trlPos++]=0x0a;
+ conn->trailer[conn->trlPos]=0;
+ if (conn->trlPos==2) {
+ ch->state = CHUNK_STOP;
+ return CHUNKE_STOP;
+ }
+ else {
+#ifdef CURL_DOES_CONVERSIONS
+ /* Convert to host encoding before calling Curl_client_write */
+ result = Curl_convert_from_network(conn->data,
+ conn->trailer,
+ conn->trlPos);
+ if(result != CURLE_OK) {
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ /* Treat it as a bad chunk */
+ return(CHUNKE_BAD_CHUNK);
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+ Curl_client_write(conn, CLIENTWRITE_HEADER,
+ conn->trailer, conn->trlPos);
+ }
+ ch->state = CHUNK_TRAILER;
+ conn->trlPos=0;
+ datap++;
+ length--;
+ }
+ else
+ return CHUNKE_BAD_CHUNK;
+ break;
+
+ case CHUNK_STOP:
+ /* If we arrive here, there is data left in the end of the buffer
+ even if there's no more chunks to read */
+ ch->dataleft = length;
+ return CHUNKE_STOP; /* return stop */
+ default:
+ return CHUNKE_STATE_ERROR;
+ }
+ }
+ return CHUNKE_OK;
+}
+#endif /* CURL_DISABLE_HTTP */
diff --git a/Utilities/cmcurl/http_chunks.h b/Utilities/cmcurl/http_chunks.h
new file mode 100644
index 0000000000..211818ab79
--- /dev/null
+++ b/Utilities/cmcurl/http_chunks.h
@@ -0,0 +1,104 @@
+#ifndef __HTTP_CHUNKS_H
+#define __HTTP_CHUNKS_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+/*
+ * The longest possible hexadecimal number we support in a chunked transfer.
+ * Weird enough, RFC2616 doesn't set a maximum size! Since we use strtoul()
+ * to convert it, we "only" support 2^32 bytes chunk data.
+ */
+#define MAXNUM_SIZE 16
+
+typedef enum {
+ CHUNK_FIRST, /* never use */
+
+ /* In this we await and buffer all hexadecimal digits until we get one
+ that isn't a hexadecimal digit. When done, we go POSTHEX */
+ CHUNK_HEX,
+
+ /* We have received the hexadecimal digit and we eat all characters until
+ we get a CRLF pair. When we see a CR we go to the CR state. */
+ CHUNK_POSTHEX,
+
+ /* A single CR has been found and we should get a LF right away in this
+ state or we go back to POSTHEX. When LF is received, we go to DATA.
+ If the size given was zero, we set state to STOP and return. */
+ CHUNK_CR,
+
+ /* We eat the amount of data specified. When done, we move on to the
+ POST_CR state. */
+ CHUNK_DATA,
+
+ /* POSTCR should get a CR and nothing else, then move to POSTLF */
+ CHUNK_POSTCR,
+
+ /* POSTLF should get a LF and nothing else, then move back to HEX as the
+ CRLF combination marks the end of a chunk */
+ CHUNK_POSTLF,
+
+ /* This is mainly used to really mark that we're out of the game.
+ NOTE: that there's a 'dataleft' field in the struct that will tell how
+ many bytes that were not passed to the client in the end of the last
+ buffer! */
+ CHUNK_STOP,
+
+ /* At this point optional trailer headers can be found, unless the next line
+ is CRLF */
+ CHUNK_TRAILER,
+
+ /* A trailer CR has been found - next state is CHUNK_TRAILER_POSTCR.
+ Next char must be a LF */
+ CHUNK_TRAILER_CR,
+
+ /* A trailer LF must be found now, otherwise CHUNKE_BAD_CHUNK will be
+ signalled If this is an empty trailer CHUNKE_STOP will be signalled.
+ Otherwise the trailer will be broadcasted via Curl_client_write() and the
+ next state will be CHUNK_TRAILER */
+ CHUNK_TRAILER_POSTCR,
+
+ CHUNK_LAST /* never use */
+
+} ChunkyState;
+
+typedef enum {
+ CHUNKE_STOP = -1,
+ CHUNKE_OK = 0,
+ CHUNKE_TOO_LONG_HEX = 1,
+ CHUNKE_ILLEGAL_HEX,
+ CHUNKE_BAD_CHUNK,
+ CHUNKE_WRITE_ERROR,
+ CHUNKE_STATE_ERROR,
+ CHUNKE_BAD_ENCODING,
+ CHUNKE_OUT_OF_MEMORY,
+ CHUNKE_LAST
+} CHUNKcode;
+
+struct Curl_chunker {
+ char hexbuffer[ MAXNUM_SIZE + 1];
+ int hexindex;
+ ChunkyState state;
+ size_t datasize;
+ size_t dataleft; /* untouched data amount at the end of the last buffer */
+};
+
+#endif
diff --git a/Utilities/cmcurl/http_digest.c b/Utilities/cmcurl/http_digest.c
new file mode 100644
index 0000000000..c223784f91
--- /dev/null
+++ b/Utilities/cmcurl/http_digest.c
@@ -0,0 +1,504 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#include "setup.h"
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "urldata.h"
+#include "sendf.h"
+#include "strequal.h"
+#include "base64.h"
+#include "md5.h"
+#include "http_digest.h"
+#include "strtok.h"
+#include "url.h" /* for Curl_safefree() */
+#include "memory.h"
+#include "easyif.h" /* included for Curl_convert_... prototypes */
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/* Test example headers:
+
+WWW-Authenticate: Digest realm="testrealm", nonce="1053604598"
+Proxy-Authenticate: Digest realm="testrealm", nonce="1053604598"
+
+*/
+
+CURLdigest Curl_input_digest(struct connectdata *conn,
+ bool proxy,
+ char *header) /* rest of the *-authenticate:
+ header */
+{
+ bool more = TRUE;
+ char *token = NULL;
+ char *tmp = NULL;
+ bool foundAuth = FALSE;
+ bool foundAuthInt = FALSE;
+ struct SessionHandle *data=conn->data;
+ bool before = FALSE; /* got a nonce before */
+ struct digestdata *d;
+
+ if(proxy) {
+ d = &data->state.proxydigest;
+ }
+ else {
+ d = &data->state.digest;
+ }
+
+ /* skip initial whitespaces */
+ while(*header && ISSPACE(*header))
+ header++;
+
+ if(checkprefix("Digest", header)) {
+ header += strlen("Digest");
+
+ /* If we already have received a nonce, keep that in mind */
+ if(d->nonce)
+ before = TRUE;
+
+ /* clear off any former leftovers and init to defaults */
+ Curl_digest_cleanup_one(d);
+
+ while(more) {
+ char value[32];
+ char content[128];
+ size_t totlen=0;
+
+ while(*header && ISSPACE(*header))
+ header++;
+
+ /* how big can these strings be? */
+ if((2 == sscanf(header, "%31[^=]=\"%127[^\"]\"",
+ value, content)) ||
+ /* try the same scan but without quotes around the content but don't
+ include the possibly trailing comma */
+ (2 == sscanf(header, "%31[^=]=%127[^,]",
+ value, content)) ) {
+ if(strequal(value, "nonce")) {
+ d->nonce = strdup(content);
+ if(!d->nonce)
+ return CURLDIGEST_NOMEM;
+ }
+ else if(strequal(value, "stale")) {
+ if(strequal(content, "true")) {
+ d->stale = TRUE;
+ d->nc = 1; /* we make a new nonce now */
+ }
+ }
+ else if(strequal(value, "realm")) {
+ d->realm = strdup(content);
+ if(!d->realm)
+ return CURLDIGEST_NOMEM;
+ }
+ else if(strequal(value, "opaque")) {
+ d->opaque = strdup(content);
+ if(!d->opaque)
+ return CURLDIGEST_NOMEM;
+ }
+ else if(strequal(value, "qop")) {
+ char *tok_buf;
+ /* tokenize the list and choose auth if possible, use a temporary
+ clone of the buffer since strtok_r() ruins it */
+ tmp = strdup(content);
+ if(!tmp)
+ return CURLDIGEST_NOMEM;
+ token = strtok_r(tmp, ",", &tok_buf);
+ while (token != NULL) {
+ if (strequal(token, "auth")) {
+ foundAuth = TRUE;
+ }
+ else if (strequal(token, "auth-int")) {
+ foundAuthInt = TRUE;
+ }
+ token = strtok_r(NULL, ",", &tok_buf);
+ }
+ free(tmp);
+ /*select only auth o auth-int. Otherwise, ignore*/
+ if (foundAuth) {
+ d->qop = strdup("auth");
+ if(!d->qop)
+ return CURLDIGEST_NOMEM;
+ }
+ else if (foundAuthInt) {
+ d->qop = strdup("auth-int");
+ if(!d->qop)
+ return CURLDIGEST_NOMEM;
+ }
+ }
+ else if(strequal(value, "algorithm")) {
+ d->algorithm = strdup(content);
+ if(!d->algorithm)
+ return CURLDIGEST_NOMEM;
+ if(strequal(content, "MD5-sess"))
+ d->algo = CURLDIGESTALGO_MD5SESS;
+ else if(strequal(content, "MD5"))
+ d->algo = CURLDIGESTALGO_MD5;
+ else
+ return CURLDIGEST_BADALGO;
+ }
+ else {
+ /* unknown specifier, ignore it! */
+ }
+ totlen = strlen(value)+strlen(content)+1;
+
+ if(header[strlen(value)+1] == '\"')
+ /* the contents were within quotes, then add 2 for them to the
+ length */
+ totlen += 2;
+ }
+ else
+ break; /* we're done here */
+
+ header += totlen;
+ if(',' == *header)
+ /* allow the list to be comma-separated */
+ header++;
+ }
+ /* We had a nonce since before, and we got another one now without
+ 'stale=true'. This means we provided bad credentials in the previous
+ request */
+ if(before && !d->stale)
+ return CURLDIGEST_BAD;
+
+ /* We got this header without a nonce, that's a bad Digest line! */
+ if(!d->nonce)
+ return CURLDIGEST_BAD;
+ }
+ else
+ /* else not a digest, get out */
+ return CURLDIGEST_NONE;
+
+ return CURLDIGEST_FINE;
+}
+
+/* convert md5 chunk to RFC2617 (section 3.1.3) -suitable ascii string*/
+static void md5_to_ascii(unsigned char *source, /* 16 bytes */
+ unsigned char *dest) /* 33 bytes */
+{
+ int i;
+ for(i=0; i<16; i++)
+ snprintf((char *)&dest[i*2], 3, "%02x", source[i]);
+}
+
+CURLcode Curl_output_digest(struct connectdata *conn,
+ bool proxy,
+ unsigned char *request,
+ unsigned char *uripath)
+{
+ /* We have a Digest setup for this, use it! Now, to get all the details for
+ this sorted out, I must urge you dear friend to read up on the RFC2617
+ section 3.2.2, */
+ unsigned char md5buf[16]; /* 16 bytes/128 bits */
+ unsigned char request_digest[33];
+ unsigned char *md5this;
+ unsigned char *ha1;
+ unsigned char ha2[33];/* 32 digits and 1 zero byte */
+ char cnoncebuf[7];
+ char *cnonce;
+ char *tmp = NULL;
+ struct timeval now;
+
+ char **allocuserpwd;
+ char *userp;
+ char *passwdp;
+ struct auth *authp;
+
+ struct SessionHandle *data = conn->data;
+ struct digestdata *d;
+#ifdef CURL_DOES_CONVERSIONS
+ CURLcode rc;
+/* The CURL_OUTPUT_DIGEST_CONV macro below is for non-ASCII machines.
+ It converts digest text to ASCII so the MD5 will be correct for
+ what ultimately goes over the network.
+*/
+#define CURL_OUTPUT_DIGEST_CONV(a, b) \
+ rc = Curl_convert_to_network(a, (char *)b, strlen((const char*)b)); \
+ if (rc != CURLE_OK) { \
+ free(b); \
+ return rc; \
+ }
+#else
+#define CURL_OUTPUT_DIGEST_CONV(a, b)
+#endif /* CURL_DOES_CONVERSIONS */
+
+ if(proxy) {
+ d = &data->state.proxydigest;
+ allocuserpwd = &conn->allocptr.proxyuserpwd;
+ userp = conn->proxyuser;
+ passwdp = conn->proxypasswd;
+ authp = &data->state.authproxy;
+ }
+ else {
+ d = &data->state.digest;
+ allocuserpwd = &conn->allocptr.userpwd;
+ userp = conn->user;
+ passwdp = conn->passwd;
+ authp = &data->state.authhost;
+ }
+
+ /* not set means empty */
+ if(!userp)
+ userp=(char *)"";
+
+ if(!passwdp)
+ passwdp=(char *)"";
+
+ if(!d->nonce) {
+ authp->done = FALSE;
+ return CURLE_OK;
+ }
+ authp->done = TRUE;
+
+ if(!d->nc)
+ d->nc = 1;
+
+ if(!d->cnonce) {
+ /* Generate a cnonce */
+ now = Curl_tvnow();
+ snprintf(cnoncebuf, sizeof(cnoncebuf), "%06ld", now.tv_sec);
+ if(Curl_base64_encode(data, cnoncebuf, strlen(cnoncebuf), &cnonce))
+ d->cnonce = cnonce;
+ else
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ /*
+ if the algorithm is "MD5" or unspecified (which then defaults to MD5):
+
+ A1 = unq(username-value) ":" unq(realm-value) ":" passwd
+
+ if the algorithm is "MD5-sess" then:
+
+ A1 = H( unq(username-value) ":" unq(realm-value) ":" passwd )
+ ":" unq(nonce-value) ":" unq(cnonce-value)
+ */
+
+ md5this = (unsigned char *)
+ aprintf("%s:%s:%s", userp, d->realm, passwdp);
+ if(!md5this)
+ return CURLE_OUT_OF_MEMORY;
+
+ CURL_OUTPUT_DIGEST_CONV(data, md5this); /* convert on non-ASCII machines */
+ Curl_md5it(md5buf, md5this);
+ free(md5this); /* free this again */
+
+ ha1 = (unsigned char *)malloc(33); /* 32 digits and 1 zero byte */
+ if(!ha1)
+ return CURLE_OUT_OF_MEMORY;
+
+ md5_to_ascii(md5buf, ha1);
+
+ if(d->algo == CURLDIGESTALGO_MD5SESS) {
+ /* nonce and cnonce are OUTSIDE the hash */
+ tmp = aprintf("%s:%s:%s", ha1, d->nonce, d->cnonce);
+ if(!tmp)
+ return CURLE_OUT_OF_MEMORY;
+ CURL_OUTPUT_DIGEST_CONV(data, tmp); /* convert on non-ASCII machines */
+ Curl_md5it(md5buf, (unsigned char *)tmp);
+ free(tmp); /* free this again */
+ md5_to_ascii(md5buf, ha1);
+ }
+
+ /*
+ If the "qop" directive's value is "auth" or is unspecified, then A2 is:
+
+ A2 = Method ":" digest-uri-value
+
+ If the "qop" value is "auth-int", then A2 is:
+
+ A2 = Method ":" digest-uri-value ":" H(entity-body)
+
+ (The "Method" value is the HTTP request method as specified in section
+ 5.1.1 of RFC 2616)
+ */
+
+ md5this = (unsigned char *)aprintf("%s:%s", request, uripath);
+ if(!md5this) {
+ free(ha1);
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ if (d->qop && strequal(d->qop, "auth-int")) {
+ /* We don't support auth-int at the moment. I can't see a easy way to get
+ entity-body here */
+ /* TODO: Append H(entity-body)*/
+ }
+ CURL_OUTPUT_DIGEST_CONV(data, md5this); /* convert on non-ASCII machines */
+ Curl_md5it(md5buf, md5this);
+ free(md5this); /* free this again */
+ md5_to_ascii(md5buf, ha2);
+
+ if (d->qop) {
+ md5this = (unsigned char *)aprintf("%s:%s:%08x:%s:%s:%s",
+ ha1,
+ d->nonce,
+ d->nc,
+ d->cnonce,
+ d->qop,
+ ha2);
+ }
+ else {
+ md5this = (unsigned char *)aprintf("%s:%s:%s",
+ ha1,
+ d->nonce,
+ ha2);
+ }
+ free(ha1);
+ if(!md5this)
+ return CURLE_OUT_OF_MEMORY;
+
+ CURL_OUTPUT_DIGEST_CONV(data, md5this); /* convert on non-ASCII machines */
+ Curl_md5it(md5buf, md5this);
+ free(md5this); /* free this again */
+ md5_to_ascii(md5buf, request_digest);
+
+ /* for test case 64 (snooped from a Mozilla 1.3a request)
+
+ Authorization: Digest username="testuser", realm="testrealm", \
+ nonce="1053604145", uri="/64", response="c55f7f30d83d774a3d2dcacf725abaca"
+ */
+
+ Curl_safefree(*allocuserpwd);
+
+ if (d->qop) {
+ *allocuserpwd =
+ aprintf( "%sAuthorization: Digest "
+ "username=\"%s\", "
+ "realm=\"%s\", "
+ "nonce=\"%s\", "
+ "uri=\"%s\", "
+ "cnonce=\"%s\", "
+ "nc=%08x, "
+ "qop=\"%s\", "
+ "response=\"%s\"",
+ proxy?"Proxy-":"",
+ userp,
+ d->realm,
+ d->nonce,
+ uripath, /* this is the PATH part of the URL */
+ d->cnonce,
+ d->nc,
+ d->qop,
+ request_digest);
+
+ if(strequal(d->qop, "auth"))
+ d->nc++; /* The nc (from RFC) has to be a 8 hex digit number 0 padded
+ which tells to the server how many times you are using the
+ same nonce in the qop=auth mode. */
+ }
+ else {
+ *allocuserpwd =
+ aprintf( "%sAuthorization: Digest "
+ "username=\"%s\", "
+ "realm=\"%s\", "
+ "nonce=\"%s\", "
+ "uri=\"%s\", "
+ "response=\"%s\"",
+ proxy?"Proxy-":"",
+ userp,
+ d->realm,
+ d->nonce,
+ uripath, /* this is the PATH part of the URL */
+ request_digest);
+ }
+ if(!*allocuserpwd)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* Add optional fields */
+ if(d->opaque) {
+ /* append opaque */
+ tmp = aprintf("%s, opaque=\"%s\"", *allocuserpwd, d->opaque);
+ if(!tmp)
+ return CURLE_OUT_OF_MEMORY;
+ free(*allocuserpwd);
+ *allocuserpwd = tmp;
+ }
+
+ if(d->algorithm) {
+ /* append algorithm */
+ tmp = aprintf("%s, algorithm=\"%s\"", *allocuserpwd, d->algorithm);
+ if(!tmp)
+ return CURLE_OUT_OF_MEMORY;
+ free(*allocuserpwd);
+ *allocuserpwd = tmp;
+ }
+
+ /* append CRLF to the userpwd header */
+ tmp = (char*) realloc(*allocuserpwd, strlen(*allocuserpwd) + 3 + 1);
+ if(!tmp)
+ return CURLE_OUT_OF_MEMORY;
+ strcat(tmp, "\r\n");
+ *allocuserpwd = tmp;
+
+ return CURLE_OK;
+}
+
+void Curl_digest_cleanup_one(struct digestdata *d)
+{
+ if(d->nonce)
+ free(d->nonce);
+ d->nonce = NULL;
+
+ if(d->cnonce)
+ free(d->cnonce);
+ d->cnonce = NULL;
+
+ if(d->realm)
+ free(d->realm);
+ d->realm = NULL;
+
+ if(d->opaque)
+ free(d->opaque);
+ d->opaque = NULL;
+
+ if(d->qop)
+ free(d->qop);
+ d->qop = NULL;
+
+ if(d->algorithm)
+ free(d->algorithm);
+ d->algorithm = NULL;
+
+ d->nc = 0;
+ d->algo = CURLDIGESTALGO_MD5; /* default algorithm */
+ d->stale = FALSE; /* default means normal, not stale */
+}
+
+
+void Curl_digest_cleanup(struct SessionHandle *data)
+{
+ Curl_digest_cleanup_one(&data->state.digest);
+ Curl_digest_cleanup_one(&data->state.proxydigest);
+}
+
+#endif
diff --git a/Utilities/cmcurl/http_digest.h b/Utilities/cmcurl/http_digest.h
new file mode 100644
index 0000000000..6cf0259754
--- /dev/null
+++ b/Utilities/cmcurl/http_digest.h
@@ -0,0 +1,58 @@
+#ifndef __HTTP_DIGEST_H
+#define __HTTP_DIGEST_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+typedef enum {
+ CURLDIGEST_NONE, /* not a digest */
+ CURLDIGEST_BAD, /* a digest, but one we don't like */
+ CURLDIGEST_BADALGO, /* unsupported algorithm requested */
+ CURLDIGEST_NOMEM,
+ CURLDIGEST_FINE, /* a digest we act on */
+
+ CURLDIGEST_LAST /* last entry in this enum, don't use */
+} CURLdigest;
+
+enum {
+ CURLDIGESTALGO_MD5,
+ CURLDIGESTALGO_MD5SESS
+};
+
+/* this is for digest header input */
+CURLdigest Curl_input_digest(struct connectdata *conn,
+ bool proxy, char *header);
+
+/* this is for creating digest header output */
+CURLcode Curl_output_digest(struct connectdata *conn,
+ bool proxy,
+ unsigned char *request,
+ unsigned char *uripath);
+void Curl_digest_cleanup_one(struct digestdata *dig);
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
+void Curl_digest_cleanup(struct SessionHandle *data);
+#else
+#define Curl_digest_cleanup(x) do {} while(0)
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/http_negotiate.c b/Utilities/cmcurl/http_negotiate.c
new file mode 100644
index 0000000000..bdfeefa0a5
--- /dev/null
+++ b/Utilities/cmcurl/http_negotiate.c
@@ -0,0 +1,327 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#include "setup.h"
+
+#ifdef HAVE_GSSAPI
+#ifdef HAVE_GSSMIT
+#define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name
+#endif
+
+#ifndef CURL_DISABLE_HTTP
+ /* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "urldata.h"
+#include "sendf.h"
+#include "strequal.h"
+#include "base64.h"
+#include "http_negotiate.h"
+#include "memory.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+static int
+get_gss_name(struct connectdata *conn, gss_name_t *server)
+{
+ struct negotiatedata *neg_ctx = &conn->data->state.negotiate;
+ OM_uint32 major_status, minor_status;
+ gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
+ char name[2048];
+ const char* service;
+
+ /* GSSAPI implementation by Globus (known as GSI) requires the name to be
+ of form "<service>/<fqdn>" instead of <service>@<fqdn> (ie. slash instead
+ of at-sign). Also GSI servers are often identified as 'host' not 'khttp'.
+ Change following lines if you want to use GSI */
+
+ /* IIS uses the <service>@<fqdn> form but uses 'http' as the service name */
+
+ if (neg_ctx->gss)
+ service = "KHTTP";
+ else
+ service = "HTTP";
+
+ token.length = strlen(service) + 1 + strlen(conn->host.name) + 1;
+ if (token.length + 1 > sizeof(name))
+ return EMSGSIZE;
+
+ snprintf(name, sizeof(name), "%s@%s", service, conn->host.name);
+
+ token.value = (void *) name;
+ major_status = gss_import_name(&minor_status,
+ &token,
+ GSS_C_NT_HOSTBASED_SERVICE,
+ server);
+
+ return GSS_ERROR(major_status) ? -1 : 0;
+}
+
+static void
+log_gss_error(struct connectdata *conn, OM_uint32 error_status, char *prefix)
+{
+ OM_uint32 maj_stat, min_stat;
+ OM_uint32 msg_ctx = 0;
+ gss_buffer_desc status_string;
+ char buf[1024];
+ size_t len;
+
+ snprintf(buf, sizeof(buf), "%s", prefix);
+ len = strlen(buf);
+ do {
+ maj_stat = gss_display_status (&min_stat,
+ error_status,
+ GSS_C_MECH_CODE,
+ GSS_C_NO_OID,
+ &msg_ctx,
+ &status_string);
+ if (sizeof(buf) > len + status_string.length + 1) {
+ snprintf(buf + len, sizeof(buf) - len,
+ ": %s", (char*) status_string.value);
+ len += status_string.length;
+ }
+ gss_release_buffer(&min_stat, &status_string);
+ } while (!GSS_ERROR(maj_stat) && msg_ctx != 0);
+
+ infof(conn->data, "%s", buf);
+}
+
+int Curl_input_negotiate(struct connectdata *conn, char *header)
+{
+ struct negotiatedata *neg_ctx = &conn->data->state.negotiate;
+ OM_uint32 major_status, minor_status, minor_status2;
+ gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER;
+ gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER;
+ int ret;
+ size_t len;
+ bool gss;
+ const char* protocol;
+
+ while(*header && ISSPACE(*header))
+ header++;
+ if(checkprefix("GSS-Negotiate", header)) {
+ protocol = "GSS-Negotiate";
+ gss = TRUE;
+ }
+ else if (checkprefix("Negotiate", header)) {
+ protocol = "Negotiate";
+ gss = FALSE;
+ }
+ else
+ return -1;
+
+ if (neg_ctx->context) {
+ if (neg_ctx->gss != gss) {
+ return -1;
+ }
+ }
+ else {
+ neg_ctx->protocol = protocol;
+ neg_ctx->gss = gss;
+ }
+
+ if (neg_ctx->context && neg_ctx->status == GSS_S_COMPLETE) {
+ /* We finished succesfully our part of authentication, but server
+ * rejected it (since we're again here). Exit with an error since we
+ * can't invent anything better */
+ Curl_cleanup_negotiate(conn->data);
+ return -1;
+ }
+
+ if (neg_ctx->server_name == NULL &&
+ (ret = get_gss_name(conn, &neg_ctx->server_name)))
+ return ret;
+
+ header += strlen(neg_ctx->protocol);
+ while(*header && ISSPACE(*header))
+ header++;
+
+ len = strlen(header);
+ if (len > 0) {
+ int rawlen = Curl_base64_decode(header, (unsigned char **)&input_token.value);
+ if (rawlen < 0)
+ return -1;
+ input_token.length = rawlen;
+
+#ifdef HAVE_SPNEGO /* Handle SPNEGO */
+ if (checkprefix("Negotiate", header)) {
+ ASN1_OBJECT * object = NULL;
+ int rc = 1;
+ unsigned char * spnegoToken = NULL;
+ size_t spnegoTokenLength = 0;
+ unsigned char * mechToken = NULL;
+ size_t mechTokenLength = 0;
+
+ spnegoToken = malloc(input_token.length);
+ if (input_token.value == NULL)
+ return ENOMEM;
+ spnegoTokenLength = input_token.length;
+
+ object = OBJ_txt2obj ("1.2.840.113554.1.2.2", 1);
+ if (!parseSpnegoTargetToken(spnegoToken,
+ spnegoTokenLength,
+ NULL,
+ NULL,
+ &mechToken,
+ &mechTokenLength,
+ NULL,
+ NULL)) {
+ free(spnegoToken);
+ spnegoToken = NULL;
+ infof(conn->data, "Parse SPNEGO Target Token failed\n");
+ }
+ else {
+ free(input_token.value);
+ input_token.value = NULL;
+ input_token.value = malloc(mechTokenLength);
+ memcpy(input_token.value, mechToken,mechTokenLength);
+ input_token.length = mechTokenLength;
+ free(mechToken);
+ mechToken = NULL;
+ infof(conn->data, "Parse SPNEGO Target Token succeeded\n");
+ }
+ }
+#endif
+ }
+
+ major_status = gss_init_sec_context(&minor_status,
+ GSS_C_NO_CREDENTIAL,
+ &neg_ctx->context,
+ neg_ctx->server_name,
+ GSS_C_NO_OID,
+ GSS_C_DELEG_FLAG,
+ 0,
+ GSS_C_NO_CHANNEL_BINDINGS,
+ &input_token,
+ NULL,
+ &output_token,
+ NULL,
+ NULL);
+ if (input_token.length > 0)
+ gss_release_buffer(&minor_status2, &input_token);
+ neg_ctx->status = major_status;
+ if (GSS_ERROR(major_status)) {
+ /* Curl_cleanup_negotiate(conn->data) ??? */
+ log_gss_error(conn, minor_status,
+ (char *)"gss_init_sec_context() failed: ");
+ return -1;
+ }
+
+ if (output_token.length == 0) {
+ return -1;
+ }
+
+ neg_ctx->output_token = output_token;
+ /* conn->bits.close = FALSE; */
+
+ return 0;
+}
+
+
+CURLcode Curl_output_negotiate(struct connectdata *conn)
+{
+ struct negotiatedata *neg_ctx = &conn->data->state.negotiate;
+ OM_uint32 minor_status;
+ char *encoded = NULL;
+ int len;
+
+#ifdef HAVE_SPNEGO /* Handle SPNEGO */
+ if (checkprefix("Negotiate",neg_ctx->protocol)) {
+ ASN1_OBJECT * object = NULL;
+ int rc = 1;
+ unsigned char * spnegoToken = NULL;
+ size_t spnegoTokenLength = 0;
+ unsigned char * responseToken = NULL;
+ size_t responseTokenLength = 0;
+
+ responseToken = malloc(neg_ctx->output_token.length);
+ if ( responseToken == NULL)
+ return CURLE_OUT_OF_MEMORY;
+ memcpy(responseToken, neg_ctx->output_token.value,
+ neg_ctx->output_token.length);
+ responseTokenLength = neg_ctx->output_token.length;
+
+ object=OBJ_txt2obj ("1.2.840.113554.1.2.2", 1);
+ if (!makeSpnegoInitialToken (object,
+ responseToken,
+ responseTokenLength,
+ &spnegoToken,
+ &spnegoTokenLength)) {
+ free(responseToken);
+ responseToken = NULL;
+ infof(conn->data, "Make SPNEGO Initial Token failed\n");
+ }
+ else {
+ free(neg_ctx->output_token.value);
+ responseToken = NULL;
+ neg_ctx->output_token.value = malloc(spnegoTokenLength);
+ memcpy(neg_ctx->output_token.value, spnegoToken,spnegoTokenLength);
+ neg_ctx->output_token.length = spnegoTokenLength;
+ free(spnegoToken);
+ spnegoToken = NULL;
+ infof(conn->data, "Make SPNEGO Initial Token succeeded\n");
+ }
+ }
+#endif
+ len = Curl_base64_encode(conn->data,
+ neg_ctx->output_token.value,
+ neg_ctx->output_token.length,
+ &encoded);
+
+ if (len < 0)
+ return CURLE_OUT_OF_MEMORY;
+
+ conn->allocptr.userpwd =
+ aprintf("Authorization: %s %s\r\n", neg_ctx->protocol, encoded);
+ free(encoded);
+ gss_release_buffer(&minor_status, &neg_ctx->output_token);
+ return (conn->allocptr.userpwd == NULL) ? CURLE_OUT_OF_MEMORY : CURLE_OK;
+}
+
+void Curl_cleanup_negotiate(struct SessionHandle *data)
+{
+ OM_uint32 minor_status;
+ struct negotiatedata *neg_ctx = &data->state.negotiate;
+
+ if (neg_ctx->context != GSS_C_NO_CONTEXT)
+ gss_delete_sec_context(&minor_status, &neg_ctx->context, GSS_C_NO_BUFFER);
+
+ if (neg_ctx->output_token.length != 0)
+ gss_release_buffer(&minor_status, &neg_ctx->output_token);
+
+ if (neg_ctx->server_name != GSS_C_NO_NAME)
+ gss_release_name(&minor_status, &neg_ctx->server_name);
+
+ memset(neg_ctx, 0, sizeof(*neg_ctx));
+}
+
+
+#endif
+#endif
diff --git a/Utilities/cmcurl/http_negotiate.h b/Utilities/cmcurl/http_negotiate.h
new file mode 100644
index 0000000000..ce0d083f91
--- /dev/null
+++ b/Utilities/cmcurl/http_negotiate.h
@@ -0,0 +1,39 @@
+#ifndef __HTTP_NEGOTIATE_H
+#define __HTTP_NEGOTIATE_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifdef HAVE_GSSAPI
+
+/* this is for Negotiate header input */
+int Curl_input_negotiate(struct connectdata *conn, char *header);
+
+/* this is for creating Negotiate header output */
+CURLcode Curl_output_negotiate(struct connectdata *conn);
+
+void Curl_cleanup_negotiate(struct SessionHandle *data);
+
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/http_ntlm.c b/Utilities/cmcurl/http_ntlm.c
new file mode 100644
index 0000000000..aff1bb1b63
--- /dev/null
+++ b/Utilities/cmcurl/http_ntlm.c
@@ -0,0 +1,1111 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#include "setup.h"
+
+/* NTLM details:
+
+ http://davenport.sourceforge.net/ntlm.html
+ http://www.innovation.ch/java/ntlm.html
+
+ Another implementation:
+ http://lxr.mozilla.org/mozilla/source/security/manager/ssl/src/nsNTLMAuthModule.cpp
+
+*/
+
+#ifndef CURL_DISABLE_HTTP
+#ifdef USE_NTLM
+
+#define DEBUG_ME 0
+
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "urldata.h"
+#include "easyif.h" /* for Curl_convert_... prototypes */
+#include "sendf.h"
+#include "strequal.h"
+#include "base64.h"
+#include "http_ntlm.h"
+#include "url.h"
+#include "memory.h"
+#include "ssluse.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* "NTLMSSP" signature is always in ASCII regardless of the platform */
+#define NTLMSSP_SIGNATURE "\x4e\x54\x4c\x4d\x53\x53\x50"
+
+#ifndef USE_WINDOWS_SSPI
+
+#include <openssl/des.h>
+#include <openssl/md4.h>
+#include <openssl/md5.h>
+#include <openssl/ssl.h>
+#include <openssl/rand.h>
+
+#if OPENSSL_VERSION_NUMBER < 0x00907001L
+#define DES_key_schedule des_key_schedule
+#define DES_cblock des_cblock
+#define DES_set_odd_parity des_set_odd_parity
+#define DES_set_key des_set_key
+#define DES_ecb_encrypt des_ecb_encrypt
+
+/* This is how things were done in the old days */
+#define DESKEY(x) x
+#define DESKEYARG(x) x
+#else
+/* Modern version */
+#define DESKEYARG(x) *x
+#define DESKEY(x) &x
+#endif
+
+#else
+
+#include <rpc.h>
+
+/* Handle of security.dll or secur32.dll, depending on Windows version */
+static HMODULE s_hSecDll = NULL;
+/* Pointer to SSPI dispatch table */
+static PSecurityFunctionTable s_pSecFn = NULL;
+
+#endif
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/* Define this to make the type-3 message include the NT response message */
+#define USE_NTRESPONSES 1
+
+/* Define this to make the type-3 message include the NTLM2Session response
+ message, requires USE_NTRESPONSES. */
+#define USE_NTLM2SESSION 1
+
+#ifndef USE_WINDOWS_SSPI
+/* this function converts from the little endian format used in the incoming
+ package to whatever endian format we're using natively */
+static unsigned int readint_le(unsigned char *buf) /* must point to a
+ 4 bytes buffer*/
+{
+ return ((unsigned int)buf[0]) | ((unsigned int)buf[1] << 8) |
+ ((unsigned int)buf[2] << 16) | ((unsigned int)buf[3] << 24);
+}
+#endif
+
+#if DEBUG_ME
+# define DEBUG_OUT(x) x
+static void print_flags(FILE *handle, unsigned long flags)
+{
+ if(flags & NTLMFLAG_NEGOTIATE_UNICODE)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_UNICODE ");
+ if(flags & NTLMFLAG_NEGOTIATE_OEM)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_OEM ");
+ if(flags & NTLMFLAG_REQUEST_TARGET)
+ fprintf(handle, "NTLMFLAG_REQUEST_TARGET ");
+ if(flags & (1<<3))
+ fprintf(handle, "NTLMFLAG_UNKNOWN_3 ");
+ if(flags & NTLMFLAG_NEGOTIATE_SIGN)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_SIGN ");
+ if(flags & NTLMFLAG_NEGOTIATE_SEAL)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_SEAL ");
+ if(flags & NTLMFLAG_NEGOTIATE_DATAGRAM_STYLE)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_DATAGRAM_STYLE ");
+ if(flags & NTLMFLAG_NEGOTIATE_LM_KEY)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_LM_KEY ");
+ if(flags & NTLMFLAG_NEGOTIATE_NETWARE)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_NETWARE ");
+ if(flags & NTLMFLAG_NEGOTIATE_NTLM_KEY)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_NTLM_KEY ");
+ if(flags & (1<<10))
+ fprintf(handle, "NTLMFLAG_UNKNOWN_10 ");
+ if(flags & (1<<11))
+ fprintf(handle, "NTLMFLAG_UNKNOWN_11 ");
+ if(flags & NTLMFLAG_NEGOTIATE_DOMAIN_SUPPLIED)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_DOMAIN_SUPPLIED ");
+ if(flags & NTLMFLAG_NEGOTIATE_WORKSTATION_SUPPLIED)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_WORKSTATION_SUPPLIED ");
+ if(flags & NTLMFLAG_NEGOTIATE_LOCAL_CALL)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_LOCAL_CALL ");
+ if(flags & NTLMFLAG_NEGOTIATE_ALWAYS_SIGN)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_ALWAYS_SIGN ");
+ if(flags & NTLMFLAG_TARGET_TYPE_DOMAIN)
+ fprintf(handle, "NTLMFLAG_TARGET_TYPE_DOMAIN ");
+ if(flags & NTLMFLAG_TARGET_TYPE_SERVER)
+ fprintf(handle, "NTLMFLAG_TARGET_TYPE_SERVER ");
+ if(flags & NTLMFLAG_TARGET_TYPE_SHARE)
+ fprintf(handle, "NTLMFLAG_TARGET_TYPE_SHARE ");
+ if(flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_NTLM2_KEY ");
+ if(flags & NTLMFLAG_REQUEST_INIT_RESPONSE)
+ fprintf(handle, "NTLMFLAG_REQUEST_INIT_RESPONSE ");
+ if(flags & NTLMFLAG_REQUEST_ACCEPT_RESPONSE)
+ fprintf(handle, "NTLMFLAG_REQUEST_ACCEPT_RESPONSE ");
+ if(flags & NTLMFLAG_REQUEST_NONNT_SESSION_KEY)
+ fprintf(handle, "NTLMFLAG_REQUEST_NONNT_SESSION_KEY ");
+ if(flags & NTLMFLAG_NEGOTIATE_TARGET_INFO)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_TARGET_INFO ");
+ if(flags & (1<<24))
+ fprintf(handle, "NTLMFLAG_UNKNOWN_24 ");
+ if(flags & (1<<25))
+ fprintf(handle, "NTLMFLAG_UNKNOWN_25 ");
+ if(flags & (1<<26))
+ fprintf(handle, "NTLMFLAG_UNKNOWN_26 ");
+ if(flags & (1<<27))
+ fprintf(handle, "NTLMFLAG_UNKNOWN_27 ");
+ if(flags & (1<<28))
+ fprintf(handle, "NTLMFLAG_UNKNOWN_28 ");
+ if(flags & NTLMFLAG_NEGOTIATE_128)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_128 ");
+ if(flags & NTLMFLAG_NEGOTIATE_KEY_EXCHANGE)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_KEY_EXCHANGE ");
+ if(flags & NTLMFLAG_NEGOTIATE_56)
+ fprintf(handle, "NTLMFLAG_NEGOTIATE_56 ");
+}
+
+static void print_hex(FILE *handle, const char *buf, size_t len)
+{
+ const char *p = buf;
+ fprintf(stderr, "0x");
+ while (len-- > 0)
+ fprintf(stderr, "%02.2x", (unsigned int)*p++);
+}
+#else
+# define DEBUG_OUT(x)
+#endif
+
+/*
+ (*) = A "security buffer" is a triplet consisting of two shorts and one
+ long:
+
+ 1. a 'short' containing the length of the buffer in bytes
+ 2. a 'short' containing the allocated space for the buffer in bytes
+ 3. a 'long' containing the offset to the start of the buffer from the
+ beginning of the NTLM message, in bytes.
+*/
+
+
+CURLntlm Curl_input_ntlm(struct connectdata *conn,
+ bool proxy, /* if proxy or not */
+ char *header) /* rest of the www-authenticate:
+ header */
+{
+ /* point to the correct struct with this */
+ struct ntlmdata *ntlm;
+#ifndef USE_WINDOWS_SSPI
+ static const char type2_marker[] = { 0x02, 0x00, 0x00, 0x00 };
+#endif
+
+ ntlm = proxy?&conn->proxyntlm:&conn->ntlm;
+
+ /* skip initial whitespaces */
+ while(*header && ISSPACE(*header))
+ header++;
+
+ if(checkprefix("NTLM", header)) {
+ header += strlen("NTLM");
+
+ while(*header && ISSPACE(*header))
+ header++;
+
+ if(*header) {
+ /* We got a type-2 message here:
+
+ Index Description Content
+ 0 NTLMSSP Signature Null-terminated ASCII "NTLMSSP"
+ (0x4e544c4d53535000)
+ 8 NTLM Message Type long (0x02000000)
+ 12 Target Name security buffer(*)
+ 20 Flags long
+ 24 Challenge 8 bytes
+ (32) Context (optional) 8 bytes (two consecutive longs)
+ (40) Target Information (optional) security buffer(*)
+ 32 (48) start of data block
+ */
+ size_t size;
+ unsigned char *buffer;
+ size = Curl_base64_decode(header, &buffer);
+ if(!buffer)
+ return CURLNTLM_BAD;
+
+ ntlm->state = NTLMSTATE_TYPE2; /* we got a type-2 */
+
+#ifdef USE_WINDOWS_SSPI
+ ntlm->type_2 = malloc(size+1);
+ if (ntlm->type_2 == NULL) {
+ free(buffer);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ ntlm->n_type_2 = size;
+ memcpy(ntlm->type_2, buffer, size);
+#else
+ ntlm->flags = 0;
+
+ if((size < 32) ||
+ (memcmp(buffer, NTLMSSP_SIGNATURE, 8) != 0) ||
+ (memcmp(buffer+8, type2_marker, sizeof(type2_marker)) != 0)) {
+ /* This was not a good enough type-2 message */
+ free(buffer);
+ return CURLNTLM_BAD;
+ }
+
+ ntlm->flags = readint_le(&buffer[20]);
+ memcpy(ntlm->nonce, &buffer[24], 8);
+
+ DEBUG_OUT({
+ fprintf(stderr, "**** TYPE2 header flags=0x%08.8lx ", ntlm->flags);
+ print_flags(stderr, ntlm->flags);
+ fprintf(stderr, "\n nonce=");
+ print_hex(stderr, (char *)ntlm->nonce, 8);
+ fprintf(stderr, "\n****\n");
+ fprintf(stderr, "**** Header %s\n ", header);
+ });
+
+ free(buffer);
+#endif
+ }
+ else {
+ if(ntlm->state >= NTLMSTATE_TYPE1)
+ return CURLNTLM_BAD;
+
+ ntlm->state = NTLMSTATE_TYPE1; /* we should sent away a type-1 */
+ }
+ }
+ return CURLNTLM_FINE;
+}
+
+#ifndef USE_WINDOWS_SSPI
+
+/*
+ * Turns a 56 bit key into the 64 bit, odd parity key and sets the key. The
+ * key schedule ks is also set.
+ */
+static void setup_des_key(unsigned char *key_56,
+ DES_key_schedule DESKEYARG(ks))
+{
+ DES_cblock key;
+
+ key[0] = key_56[0];
+ key[1] = (unsigned char)(((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1));
+ key[2] = (unsigned char)(((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2));
+ key[3] = (unsigned char)(((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3));
+ key[4] = (unsigned char)(((key_56[3] << 4) & 0xFF) | (key_56[4] >> 4));
+ key[5] = (unsigned char)(((key_56[4] << 3) & 0xFF) | (key_56[5] >> 5));
+ key[6] = (unsigned char)(((key_56[5] << 2) & 0xFF) | (key_56[6] >> 6));
+ key[7] = (unsigned char) ((key_56[6] << 1) & 0xFF);
+
+ DES_set_odd_parity(&key);
+ DES_set_key(&key, ks);
+}
+
+ /*
+ * takes a 21 byte array and treats it as 3 56-bit DES keys. The
+ * 8 byte plaintext is encrypted with each key and the resulting 24
+ * bytes are stored in the results array.
+ */
+static void lm_resp(unsigned char *keys,
+ unsigned char *plaintext,
+ unsigned char *results)
+{
+ DES_key_schedule ks;
+
+ setup_des_key(keys, DESKEY(ks));
+ DES_ecb_encrypt((DES_cblock*) plaintext, (DES_cblock*) results,
+ DESKEY(ks), DES_ENCRYPT);
+
+ setup_des_key(keys+7, DESKEY(ks));
+ DES_ecb_encrypt((DES_cblock*) plaintext, (DES_cblock*) (results+8),
+ DESKEY(ks), DES_ENCRYPT);
+
+ setup_des_key(keys+14, DESKEY(ks));
+ DES_ecb_encrypt((DES_cblock*) plaintext, (DES_cblock*) (results+16),
+ DESKEY(ks), DES_ENCRYPT);
+}
+
+
+/*
+ * Set up lanmanager hashed password
+ */
+static void mk_lm_hash(struct SessionHandle *data,
+ char *password,
+ unsigned char *lmbuffer /* 21 bytes */)
+{
+ unsigned char pw[14];
+ static const unsigned char magic[] = {
+ 0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 /* i.e. KGS!@#$% */
+ };
+ unsigned int i;
+ size_t len = strlen(password);
+
+ if (len > 14)
+ len = 14;
+
+ for (i=0; i<len; i++)
+ pw[i] = (unsigned char)toupper(password[i]);
+
+ for (; i<14; i++)
+ pw[i] = 0;
+
+#ifdef CURL_DOES_CONVERSIONS
+ /*
+ * The LanManager hashed password needs to be created using the
+ * password in the network encoding not the host encoding.
+ */
+ if(data)
+ Curl_convert_to_network(data, (char *)pw, 14);
+#else
+ (void)data;
+#endif
+
+ {
+ /* Create LanManager hashed password. */
+
+ DES_key_schedule ks;
+
+ setup_des_key(pw, DESKEY(ks));
+ DES_ecb_encrypt((DES_cblock *)magic, (DES_cblock *)lmbuffer,
+ DESKEY(ks), DES_ENCRYPT);
+
+ setup_des_key(pw+7, DESKEY(ks));
+ DES_ecb_encrypt((DES_cblock *)magic, (DES_cblock *)(lmbuffer+8),
+ DESKEY(ks), DES_ENCRYPT);
+
+ memset(lmbuffer + 16, 0, 21 - 16);
+ }
+ }
+
+#if USE_NTRESPONSES
+static void utf8_to_unicode_le(unsigned char *dest, const char *src,
+ size_t srclen)
+{
+ size_t i;
+ for (i=0; i<srclen; i++) {
+ dest[2*i] = (unsigned char)src[i];
+ dest[2*i+1] = '\0';
+ }
+}
+
+/*
+ * Set up nt hashed passwords
+ */
+static void mk_nt_hash(struct SessionHandle *data,
+ char *password,
+ unsigned char *ntbuffer /* 21 bytes */)
+{
+ size_t len = strlen(password);
+ unsigned char *pw = malloc(len*2);
+
+ utf8_to_unicode_le(pw, password, len);
+
+#ifdef CURL_DOES_CONVERSIONS
+ /*
+ * The NT hashed password needs to be created using the
+ * password in the network encoding not the host encoding.
+ */
+ if(data)
+ Curl_convert_to_network(data, (char *)pw, len*2);
+#else
+ (void)data;
+#endif
+
+ {
+ /* Create NT hashed password. */
+ MD4_CTX MD4;
+
+ MD4_Init(&MD4);
+ MD4_Update(&MD4, pw, 2*len);
+ MD4_Final(ntbuffer, &MD4);
+
+ memset(ntbuffer + 16, 0, 21 - 16);
+ }
+
+ free(pw);
+}
+#endif
+
+
+#endif
+
+#ifdef USE_WINDOWS_SSPI
+
+static void
+ntlm_sspi_cleanup(struct ntlmdata *ntlm)
+{
+ if (ntlm->type_2) {
+ free(ntlm->type_2);
+ ntlm->type_2 = NULL;
+ }
+ if (ntlm->has_handles) {
+ s_pSecFn->DeleteSecurityContext(&ntlm->c_handle);
+ s_pSecFn->FreeCredentialsHandle(&ntlm->handle);
+ ntlm->has_handles = 0;
+ }
+ if (ntlm->p_identity) {
+ if (ntlm->identity.User) free(ntlm->identity.User);
+ if (ntlm->identity.Password) free(ntlm->identity.Password);
+ if (ntlm->identity.Domain) free(ntlm->identity.Domain);
+ ntlm->p_identity = NULL;
+ }
+}
+
+#endif
+
+#define SHORTPAIR(x) ((x) & 0xff), (((x) >> 8) & 0xff)
+#define LONGQUARTET(x) ((x) & 0xff), (((x) >> 8)&0xff), \
+ (((x) >>16)&0xff), (((x)>>24) & 0xff)
+
+#define HOSTNAME_MAX 1024
+
+/* this is for creating ntlm header output */
+CURLcode Curl_output_ntlm(struct connectdata *conn,
+ bool proxy)
+{
+ const char *domain=""; /* empty */
+ char host [HOSTNAME_MAX+ 1] = ""; /* empty */
+#ifndef USE_WINDOWS_SSPI
+ size_t domlen = strlen(domain);
+ size_t hostlen = strlen(host);
+ size_t hostoff; /* host name offset */
+ size_t domoff; /* domain name offset */
+#endif
+ size_t size;
+ char *base64=NULL;
+ unsigned char ntlmbuf[1024]; /* enough, unless the user+host+domain is very
+ long */
+
+ /* point to the address of the pointer that holds the string to sent to the
+ server, which is for a plain host or for a HTTP proxy */
+ char **allocuserpwd;
+
+ /* point to the name and password for this */
+ char *userp;
+ char *passwdp;
+ /* point to the correct struct with this */
+ struct ntlmdata *ntlm;
+ struct auth *authp;
+
+ curlassert(conn);
+ curlassert(conn->data);
+
+ if(proxy) {
+ allocuserpwd = &conn->allocptr.proxyuserpwd;
+ userp = conn->proxyuser;
+ passwdp = conn->proxypasswd;
+ ntlm = &conn->proxyntlm;
+ authp = &conn->data->state.authproxy;
+ }
+ else {
+ allocuserpwd = &conn->allocptr.userpwd;
+ userp = conn->user;
+ passwdp = conn->passwd;
+ ntlm = &conn->ntlm;
+ authp = &conn->data->state.authhost;
+ }
+ authp->done = FALSE;
+
+ /* not set means empty */
+ if(!userp)
+ userp=(char *)"";
+
+ if(!passwdp)
+ passwdp=(char *)"";
+
+#ifdef USE_WINDOWS_SSPI
+ /* If security interface is not yet initialized try to do this */
+ if (s_hSecDll == NULL) {
+ /* Determine Windows version. Security functions are located in
+ * security.dll on WinNT 4.0 and in secur32.dll on Win9x. Win2K and XP
+ * contain both these DLLs (security.dll just forwards calls to
+ * secur32.dll)
+ */
+ OSVERSIONINFO osver;
+ osver.dwOSVersionInfoSize = sizeof(osver);
+ GetVersionEx(&osver);
+ if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT
+ && osver.dwMajorVersion == 4)
+ s_hSecDll = LoadLibrary("security.dll");
+ else
+ s_hSecDll = LoadLibrary("secur32.dll");
+ if (s_hSecDll != NULL) {
+ INIT_SECURITY_INTERFACE pInitSecurityInterface;
+ pInitSecurityInterface =
+ (INIT_SECURITY_INTERFACE)GetProcAddress(s_hSecDll,
+ "InitSecurityInterfaceA");
+ if (pInitSecurityInterface != NULL)
+ s_pSecFn = pInitSecurityInterface();
+ }
+ }
+ if (s_pSecFn == NULL)
+ return CURLE_RECV_ERROR;
+#endif
+
+ switch(ntlm->state) {
+ case NTLMSTATE_TYPE1:
+ default: /* for the weird cases we (re)start here */
+#ifdef USE_WINDOWS_SSPI
+ {
+ SecBuffer buf;
+ SecBufferDesc desc;
+ SECURITY_STATUS status;
+ ULONG attrs;
+ const char *user;
+ int domlen;
+ TimeStamp tsDummy; /* For Windows 9x compatibility of SPPI calls */
+
+ ntlm_sspi_cleanup(ntlm);
+
+ user = strchr(userp, '\\');
+ if (!user)
+ user = strchr(userp, '/');
+
+ if (user) {
+ domain = userp;
+ domlen = user - userp;
+ user++;
+ }
+ else {
+ user = userp;
+ domain = "";
+ domlen = 0;
+ }
+
+ if (user && *user) {
+ /* note: initialize all of this before doing the mallocs so that
+ * it can be cleaned up later without leaking memory.
+ */
+ ntlm->p_identity = &ntlm->identity;
+ memset(ntlm->p_identity, 0, sizeof(*ntlm->p_identity));
+ if ((ntlm->identity.User = (unsigned char *)strdup(user)) == NULL)
+ return CURLE_OUT_OF_MEMORY;
+ ntlm->identity.UserLength = strlen(user);
+ if ((ntlm->identity.Password = (unsigned char *)strdup(passwdp)) == NULL)
+ return CURLE_OUT_OF_MEMORY;
+ ntlm->identity.PasswordLength = strlen(passwdp);
+ if ((ntlm->identity.Domain = malloc(domlen+1)) == NULL)
+ return CURLE_OUT_OF_MEMORY;
+ strncpy((char *)ntlm->identity.Domain, domain, domlen);
+ ntlm->identity.Domain[domlen] = '\0';
+ ntlm->identity.DomainLength = domlen;
+ ntlm->identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
+ }
+ else {
+ ntlm->p_identity = NULL;
+ }
+
+ if (s_pSecFn->AcquireCredentialsHandle(
+ NULL, (char *)"NTLM", SECPKG_CRED_OUTBOUND, NULL, ntlm->p_identity,
+ NULL, NULL, &ntlm->handle, &tsDummy
+ ) != SEC_E_OK) {
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ desc.ulVersion = SECBUFFER_VERSION;
+ desc.cBuffers = 1;
+ desc.pBuffers = &buf;
+ buf.cbBuffer = sizeof(ntlmbuf);
+ buf.BufferType = SECBUFFER_TOKEN;
+ buf.pvBuffer = ntlmbuf;
+
+ status = s_pSecFn->InitializeSecurityContext(&ntlm->handle, NULL,
+ (char *) host,
+ ISC_REQ_CONFIDENTIALITY |
+ ISC_REQ_REPLAY_DETECT |
+ ISC_REQ_CONNECTION,
+ 0, SECURITY_NETWORK_DREP,
+ NULL, 0,
+ &ntlm->c_handle, &desc,
+ &attrs, &tsDummy);
+
+ if (status == SEC_I_COMPLETE_AND_CONTINUE ||
+ status == SEC_I_CONTINUE_NEEDED) {
+ s_pSecFn->CompleteAuthToken(&ntlm->c_handle, &desc);
+ }
+ else if (status != SEC_E_OK) {
+ s_pSecFn->FreeCredentialsHandle(&ntlm->handle);
+ return CURLE_RECV_ERROR;
+ }
+
+ ntlm->has_handles = 1;
+ size = buf.cbBuffer;
+ }
+#else
+ hostoff = 0;
+ domoff = hostoff + hostlen; /* This is 0: remember that host and domain
+ are empty */
+
+ /* Create and send a type-1 message:
+
+ Index Description Content
+ 0 NTLMSSP Signature Null-terminated ASCII "NTLMSSP"
+ (0x4e544c4d53535000)
+ 8 NTLM Message Type long (0x01000000)
+ 12 Flags long
+ 16 Supplied Domain security buffer(*)
+ 24 Supplied Workstation security buffer(*)
+ 32 start of data block
+
+ */
+#if USE_NTLM2SESSION
+#define NTLM2FLAG NTLMFLAG_NEGOTIATE_NTLM2_KEY
+#else
+#define NTLM2FLAG 0
+#endif
+ snprintf((char *)ntlmbuf, sizeof(ntlmbuf), NTLMSSP_SIGNATURE "%c"
+ "\x01%c%c%c" /* 32-bit type = 1 */
+ "%c%c%c%c" /* 32-bit NTLM flag field */
+ "%c%c" /* domain length */
+ "%c%c" /* domain allocated space */
+ "%c%c" /* domain name offset */
+ "%c%c" /* 2 zeroes */
+ "%c%c" /* host length */
+ "%c%c" /* host allocated space */
+ "%c%c" /* host name offset */
+ "%c%c" /* 2 zeroes */
+ "%s" /* host name */
+ "%s", /* domain string */
+ 0, /* trailing zero */
+ 0,0,0, /* part of type-1 long */
+
+ LONGQUARTET(
+ NTLMFLAG_NEGOTIATE_OEM|
+ NTLMFLAG_REQUEST_TARGET|
+ NTLMFLAG_NEGOTIATE_NTLM_KEY|
+ NTLM2FLAG|
+ NTLMFLAG_NEGOTIATE_ALWAYS_SIGN
+ ),
+ SHORTPAIR(domlen),
+ SHORTPAIR(domlen),
+ SHORTPAIR(domoff),
+ 0,0,
+ SHORTPAIR(hostlen),
+ SHORTPAIR(hostlen),
+ SHORTPAIR(hostoff),
+ 0,0,
+ host /* this is empty */, domain /* this is empty */);
+
+ /* initial packet length */
+ size = 32 + hostlen + domlen;
+#endif
+
+ DEBUG_OUT({
+ fprintf(stderr, "**** TYPE1 header flags=0x%02.2x%02.2x%02.2x%02.2x 0x%08.8x ",
+ LONGQUARTET(NTLMFLAG_NEGOTIATE_OEM|
+ NTLMFLAG_REQUEST_TARGET|
+ NTLMFLAG_NEGOTIATE_NTLM_KEY|
+ NTLM2FLAG|
+ NTLMFLAG_NEGOTIATE_ALWAYS_SIGN),
+ NTLMFLAG_NEGOTIATE_OEM|
+ NTLMFLAG_REQUEST_TARGET|
+ NTLMFLAG_NEGOTIATE_NTLM_KEY|
+ NTLM2FLAG|
+ NTLMFLAG_NEGOTIATE_ALWAYS_SIGN);
+ print_flags(stderr,
+ NTLMFLAG_NEGOTIATE_OEM|
+ NTLMFLAG_REQUEST_TARGET|
+ NTLMFLAG_NEGOTIATE_NTLM_KEY|
+ NTLM2FLAG|
+ NTLMFLAG_NEGOTIATE_ALWAYS_SIGN);
+ fprintf(stderr, "\n****\n");
+ });
+
+ /* now size is the size of the base64 encoded package size */
+ size = Curl_base64_encode(NULL, (char *)ntlmbuf, size, &base64);
+
+ if(size >0 ) {
+ Curl_safefree(*allocuserpwd);
+ *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
+ proxy?"Proxy-":"",
+ base64);
+ DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd));
+ free(base64);
+ }
+ else
+ return CURLE_OUT_OF_MEMORY; /* FIX TODO */
+
+ break;
+
+ case NTLMSTATE_TYPE2:
+ /* We received the type-2 message already, create a type-3 message:
+
+ Index Description Content
+ 0 NTLMSSP Signature Null-terminated ASCII "NTLMSSP"
+ (0x4e544c4d53535000)
+ 8 NTLM Message Type long (0x03000000)
+ 12 LM/LMv2 Response security buffer(*)
+ 20 NTLM/NTLMv2 Response security buffer(*)
+ 28 Domain Name security buffer(*)
+ 36 User Name security buffer(*)
+ 44 Workstation Name security buffer(*)
+ (52) Session Key (optional) security buffer(*)
+ (60) Flags (optional) long
+ 52 (64) start of data block
+
+ */
+
+ {
+#ifdef USE_WINDOWS_SSPI
+ SecBuffer type_2, type_3;
+ SecBufferDesc type_2_desc, type_3_desc;
+ SECURITY_STATUS status;
+ ULONG attrs;
+ TimeStamp tsDummy; /* For Windows 9x compatibility of SPPI calls */
+
+ type_2_desc.ulVersion = type_3_desc.ulVersion = SECBUFFER_VERSION;
+ type_2_desc.cBuffers = type_3_desc.cBuffers = 1;
+ type_2_desc.pBuffers = &type_2;
+ type_3_desc.pBuffers = &type_3;
+
+ type_2.BufferType = SECBUFFER_TOKEN;
+ type_2.pvBuffer = ntlm->type_2;
+ type_2.cbBuffer = ntlm->n_type_2;
+ type_3.BufferType = SECBUFFER_TOKEN;
+ type_3.pvBuffer = ntlmbuf;
+ type_3.cbBuffer = sizeof(ntlmbuf);
+
+ status = s_pSecFn->InitializeSecurityContext(&ntlm->handle, &ntlm->c_handle,
+ (char *) host,
+ ISC_REQ_CONFIDENTIALITY |
+ ISC_REQ_REPLAY_DETECT |
+ ISC_REQ_CONNECTION,
+ 0, SECURITY_NETWORK_DREP, &type_2_desc,
+ 0, &ntlm->c_handle, &type_3_desc,
+ &attrs, &tsDummy);
+
+ if (status != SEC_E_OK)
+ return CURLE_RECV_ERROR;
+
+ size = type_3.cbBuffer;
+
+ ntlm_sspi_cleanup(ntlm);
+
+#else
+ int lmrespoff;
+ unsigned char lmresp[24]; /* fixed-size */
+#if USE_NTRESPONSES
+ int ntrespoff;
+ unsigned char ntresp[24]; /* fixed-size */
+#endif
+ size_t useroff;
+ const char *user;
+ size_t userlen;
+
+ user = strchr(userp, '\\');
+ if(!user)
+ user = strchr(userp, '/');
+
+ if (user) {
+ domain = userp;
+ domlen = (user - domain);
+ user++;
+ }
+ else
+ user = userp;
+ userlen = strlen(user);
+
+ if (gethostname(host, HOSTNAME_MAX)) {
+ infof(conn->data, "gethostname() failed, continuing without!");
+ hostlen = 0;
+ }
+ else {
+ /* If the workstation if configured with a full DNS name (i.e.
+ * workstation.somewhere.net) gethostname() returns the fully qualified
+ * name, which NTLM doesn't like.
+ */
+ char *dot = strchr(host, '.');
+ if (dot)
+ *dot = '\0';
+ hostlen = strlen(host);
+ }
+
+#if USE_NTLM2SESSION
+ /* We don't support NTLM2 if we don't have USE_NTRESPONSES */
+ if (ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY) {
+ unsigned char ntbuffer[0x18];
+ unsigned char tmp[0x18];
+ unsigned char md5sum[MD5_DIGEST_LENGTH];
+ MD5_CTX MD5;
+ unsigned char random[8];
+
+ /* Need to create 8 bytes random data */
+ Curl_ossl_seed(conn->data); /* Initiate the seed if not already done */
+ RAND_bytes(random,8);
+
+ /* 8 bytes random data as challenge in lmresp */
+ memcpy(lmresp,random,8);
+ /* Pad with zeros */
+ memset(lmresp+8,0,0x10);
+
+ /* Fill tmp with challenge(nonce?) + random */
+ memcpy(tmp,&ntlm->nonce[0],8);
+ memcpy(tmp+8,random,8);
+
+ MD5_Init(&MD5);
+ MD5_Update(&MD5, tmp, 16);
+ MD5_Final(md5sum, &MD5);
+ /* We shall only use the first 8 bytes of md5sum,
+ but the des code in lm_resp only encrypt the first 8 bytes */
+ mk_nt_hash(conn->data, passwdp, ntbuffer);
+ lm_resp(ntbuffer, md5sum, ntresp);
+
+ /* End of NTLM2 Session code */
+ }
+ else {
+#endif
+
+#if USE_NTRESPONSES
+ unsigned char ntbuffer[0x18];
+#endif
+ unsigned char lmbuffer[0x18];
+
+#if USE_NTRESPONSES
+ mk_nt_hash(conn->data, passwdp, ntbuffer);
+ lm_resp(ntbuffer, &ntlm->nonce[0], ntresp);
+#endif
+
+ mk_lm_hash(conn->data, passwdp, lmbuffer);
+ lm_resp(lmbuffer, &ntlm->nonce[0], lmresp);
+ /* A safer but less compatible alternative is:
+ * lm_resp(ntbuffer, &ntlm->nonce[0], lmresp);
+ * See http://davenport.sourceforge.net/ntlm.html#ntlmVersion2 */
+#if USE_NTLM2SESSION
+ }
+#endif
+
+ lmrespoff = 64; /* size of the message header */
+#if USE_NTRESPONSES
+ ntrespoff = lmrespoff + 0x18;
+ domoff = ntrespoff + 0x18;
+#else
+ domoff = lmrespoff + 0x18;
+#endif
+ useroff = domoff + domlen;
+ hostoff = useroff + userlen;
+
+ /* Create the big type-3 message binary blob */
+ size = snprintf((char *)ntlmbuf, sizeof(ntlmbuf),
+ NTLMSSP_SIGNATURE "%c"
+ "\x03%c%c%c" /* type-3, 32 bits */
+
+ "%c%c" /* LanManager length */
+ "%c%c" /* LanManager allocated space */
+ "%c%c" /* LanManager offset */
+ "%c%c" /* 2 zeroes */
+
+ "%c%c" /* NT-response length */
+ "%c%c" /* NT-response allocated space */
+ "%c%c" /* NT-response offset */
+ "%c%c" /* 2 zeroes */
+
+ "%c%c" /* domain length */
+ "%c%c" /* domain allocated space */
+ "%c%c" /* domain name offset */
+ "%c%c" /* 2 zeroes */
+
+ "%c%c" /* user length */
+ "%c%c" /* user allocated space */
+ "%c%c" /* user offset */
+ "%c%c" /* 2 zeroes */
+
+ "%c%c" /* host length */
+ "%c%c" /* host allocated space */
+ "%c%c" /* host offset */
+ "%c%c" /* 2 zeroes */
+
+ "%c%c" /* session key length (unknown purpose) */
+ "%c%c" /* session key allocated space (unknown purpose) */
+ "%c%c" /* session key offset (unknown purpose) */
+ "%c%c" /* 2 zeroes */
+
+ "%c%c%c%c" /* flags */
+
+ /* domain string */
+ /* user string */
+ /* host string */
+ /* LanManager response */
+ /* NT response */
+ ,
+ 0, /* zero termination */
+ 0,0,0, /* type-3 long, the 24 upper bits */
+
+ SHORTPAIR(0x18), /* LanManager response length, twice */
+ SHORTPAIR(0x18),
+ SHORTPAIR(lmrespoff),
+ 0x0, 0x0,
+
+#if USE_NTRESPONSES
+ SHORTPAIR(0x18), /* NT-response length, twice */
+ SHORTPAIR(0x18),
+ SHORTPAIR(ntrespoff),
+ 0x0, 0x0,
+#else
+ 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
+#endif
+ SHORTPAIR(domlen),
+ SHORTPAIR(domlen),
+ SHORTPAIR(domoff),
+ 0x0, 0x0,
+
+ SHORTPAIR(userlen),
+ SHORTPAIR(userlen),
+ SHORTPAIR(useroff),
+ 0x0, 0x0,
+
+ SHORTPAIR(hostlen),
+ SHORTPAIR(hostlen),
+ SHORTPAIR(hostoff),
+ 0x0, 0x0,
+
+ 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
+
+ LONGQUARTET(ntlm->flags));
+ DEBUG_OUT(assert(size==64));
+
+ DEBUG_OUT(assert(size == lmrespoff));
+ /* We append the binary hashes */
+ if(size < (sizeof(ntlmbuf) - 0x18)) {
+ memcpy(&ntlmbuf[size], lmresp, 0x18);
+ size += 0x18;
+ }
+
+ DEBUG_OUT({
+ fprintf(stderr, "**** TYPE3 header lmresp=");
+ print_hex(stderr, (char *)&ntlmbuf[lmrespoff], 0x18);
+ });
+
+#if USE_NTRESPONSES
+ if(size < (sizeof(ntlmbuf) - 0x18)) {
+ DEBUG_OUT(assert(size == ntrespoff));
+ memcpy(&ntlmbuf[size], ntresp, 0x18);
+ size += 0x18;
+ }
+
+ DEBUG_OUT({
+ fprintf(stderr, "\n ntresp=");
+ print_hex(stderr, (char *)&ntlmbuf[ntrespoff], 0x18);
+ });
+
+#endif
+
+ DEBUG_OUT({
+ fprintf(stderr, "\n flags=0x%02.2x%02.2x%02.2x%02.2x 0x%08.8x ",
+ LONGQUARTET(ntlm->flags), ntlm->flags);
+ print_flags(stderr, ntlm->flags);
+ fprintf(stderr, "\n****\n");
+ });
+
+
+ /* Make sure that the domain, user and host strings fit in the target
+ buffer before we copy them there. */
+ if(size + userlen + domlen + hostlen >= sizeof(ntlmbuf)) {
+ failf(conn->data, "user + domain + host name too big");
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ curlassert(size == domoff);
+ memcpy(&ntlmbuf[size], domain, domlen);
+ size += domlen;
+
+ curlassert(size == useroff);
+ memcpy(&ntlmbuf[size], user, userlen);
+ size += userlen;
+
+ curlassert(size == hostoff);
+ memcpy(&ntlmbuf[size], host, hostlen);
+ size += hostlen;
+
+#ifdef CURL_DOES_CONVERSIONS
+ /* convert domain, user, and host to ASCII but leave the rest as-is */
+ if(CURLE_OK != Curl_convert_to_network(conn->data,
+ (char *)&ntlmbuf[domoff],
+ size-domoff)) {
+ return CURLE_CONV_FAILED;
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+#endif
+
+ /* convert the binary blob into base64 */
+ size = Curl_base64_encode(NULL, (char *)ntlmbuf, size, &base64);
+
+ if(size >0 ) {
+ Curl_safefree(*allocuserpwd);
+ *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
+ proxy?"Proxy-":"",
+ base64);
+ DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd));
+ free(base64);
+ }
+ else
+ return CURLE_OUT_OF_MEMORY; /* FIX TODO */
+
+ ntlm->state = NTLMSTATE_TYPE3; /* we sent a type-3 */
+ authp->done = TRUE;
+ }
+ break;
+
+ case NTLMSTATE_TYPE3:
+ /* connection is already authenticated,
+ * don't send a header in future requests */
+ if(*allocuserpwd) {
+ free(*allocuserpwd);
+ *allocuserpwd=NULL;
+ }
+ authp->done = TRUE;
+ break;
+ }
+
+ return CURLE_OK;
+}
+
+
+void
+Curl_ntlm_cleanup(struct connectdata *conn)
+{
+#ifdef USE_WINDOWS_SSPI
+ ntlm_sspi_cleanup(&conn->ntlm);
+ ntlm_sspi_cleanup(&conn->proxyntlm);
+ if (s_hSecDll != NULL) {
+ FreeLibrary(s_hSecDll);
+ s_hSecDll = NULL;
+ s_pSecFn = NULL;
+ }
+#else
+ (void)conn;
+#endif
+}
+
+#endif /* USE_NTLM */
+#endif /* !CURL_DISABLE_HTTP */
diff --git a/Utilities/cmcurl/http_ntlm.h b/Utilities/cmcurl/http_ntlm.h
new file mode 100644
index 0000000000..a8de220a7a
--- /dev/null
+++ b/Utilities/cmcurl/http_ntlm.h
@@ -0,0 +1,146 @@
+#ifndef __HTTP_NTLM_H
+#define __HTTP_NTLM_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+typedef enum {
+ CURLNTLM_NONE, /* not a ntlm */
+ CURLNTLM_BAD, /* an ntlm, but one we don't like */
+ CURLNTLM_FIRST, /* the first 401-reply we got with NTLM */
+ CURLNTLM_FINE, /* an ntlm we act on */
+
+ CURLNTLM_LAST /* last entry in this enum, don't use */
+} CURLntlm;
+
+/* this is for ntlm header input */
+CURLntlm Curl_input_ntlm(struct connectdata *conn, bool proxy, char *header);
+
+/* this is for creating ntlm header output */
+CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy);
+
+void Curl_ntlm_cleanup(struct connectdata *conn);
+#ifndef USE_NTLM
+#define Curl_ntlm_cleanup(x)
+#endif
+
+
+/* Flag bits definitions based on http://davenport.sourceforge.net/ntlm.html */
+
+#define NTLMFLAG_NEGOTIATE_UNICODE (1<<0)
+/* Indicates that Unicode strings are supported for use in security buffer
+ data. */
+
+#define NTLMFLAG_NEGOTIATE_OEM (1<<1)
+/* Indicates that OEM strings are supported for use in security buffer data. */
+
+#define NTLMFLAG_REQUEST_TARGET (1<<2)
+/* Requests that the server's authentication realm be included in the Type 2
+ message. */
+
+/* unknown (1<<3) */
+#define NTLMFLAG_NEGOTIATE_SIGN (1<<4)
+/* Specifies that authenticated communication between the client and server
+ should carry a digital signature (message integrity). */
+
+#define NTLMFLAG_NEGOTIATE_SEAL (1<<5)
+/* Specifies that authenticated communication between the client and server
+ should be encrypted (message confidentiality). */
+
+#define NTLMFLAG_NEGOTIATE_DATAGRAM_STYLE (1<<6)
+/* unknown purpose */
+
+#define NTLMFLAG_NEGOTIATE_LM_KEY (1<<7)
+/* Indicates that the LAN Manager session key should be used for signing and
+ sealing authenticated communications. */
+
+#define NTLMFLAG_NEGOTIATE_NETWARE (1<<8)
+/* unknown purpose */
+
+#define NTLMFLAG_NEGOTIATE_NTLM_KEY (1<<9)
+/* Indicates that NTLM authentication is being used. */
+
+/* unknown (1<<10) */
+/* unknown (1<<11) */
+
+#define NTLMFLAG_NEGOTIATE_DOMAIN_SUPPLIED (1<<12)
+/* Sent by the client in the Type 1 message to indicate that a desired
+ authentication realm is included in the message. */
+
+#define NTLMFLAG_NEGOTIATE_WORKSTATION_SUPPLIED (1<<13)
+/* Sent by the client in the Type 1 message to indicate that the client
+ workstation's name is included in the message. */
+
+#define NTLMFLAG_NEGOTIATE_LOCAL_CALL (1<<14)
+/* Sent by the server to indicate that the server and client are on the same
+ machine. Implies that the client may use a pre-established local security
+ context rather than responding to the challenge. */
+
+#define NTLMFLAG_NEGOTIATE_ALWAYS_SIGN (1<<15)
+/* Indicates that authenticated communication between the client and server
+ should be signed with a "dummy" signature. */
+
+#define NTLMFLAG_TARGET_TYPE_DOMAIN (1<<16)
+/* Sent by the server in the Type 2 message to indicate that the target
+ authentication realm is a domain. */
+
+#define NTLMFLAG_TARGET_TYPE_SERVER (1<<17)
+/* Sent by the server in the Type 2 message to indicate that the target
+ authentication realm is a server. */
+
+#define NTLMFLAG_TARGET_TYPE_SHARE (1<<18)
+/* Sent by the server in the Type 2 message to indicate that the target
+ authentication realm is a share. Presumably, this is for share-level
+ authentication. Usage is unclear. */
+
+#define NTLMFLAG_NEGOTIATE_NTLM2_KEY (1<<19)
+/* Indicates that the NTLM2 signing and sealing scheme should be used for
+ protecting authenticated communications. */
+
+#define NTLMFLAG_REQUEST_INIT_RESPONSE (1<<20)
+/* unknown purpose */
+
+#define NTLMFLAG_REQUEST_ACCEPT_RESPONSE (1<<21)
+/* unknown purpose */
+
+#define NTLMFLAG_REQUEST_NONNT_SESSION_KEY (1<<22)
+/* unknown purpose */
+
+#define NTLMFLAG_NEGOTIATE_TARGET_INFO (1<<23)
+/* Sent by the server in the Type 2 message to indicate that it is including a
+ Target Information block in the message. */
+
+/* unknown (1<24) */
+/* unknown (1<25) */
+/* unknown (1<26) */
+/* unknown (1<27) */
+/* unknown (1<28) */
+
+#define NTLMFLAG_NEGOTIATE_128 (1<<29)
+/* Indicates that 128-bit encryption is supported. */
+
+#define NTLMFLAG_NEGOTIATE_KEY_EXCHANGE (1<<30)
+/* unknown purpose */
+
+#define NTLMFLAG_NEGOTIATE_56 (1<<31)
+/* Indicates that 56-bit encryption is supported. */
+#endif
diff --git a/Utilities/cmcurl/if2ip.c b/Utilities/cmcurl/if2ip.c
new file mode 100644
index 0000000000..b4a98c6625
--- /dev/null
+++ b/Utilities/cmcurl/if2ip.c
@@ -0,0 +1,134 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "if2ip.h"
+
+/*
+ * This test can probably be simplified to #if defined(SIOCGIFADDR) and
+ * moved after the following includes.
+ */
+#if !defined(WIN32) && !defined(__BEOS__) && !defined(__CYGWIN__) && \
+ !defined(__riscos__) && !defined(__INTERIX) && !defined(NETWARE) && \
+ !defined(_AMIGASF) && !defined(__minix)
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+
+#ifdef HAVE_SYS_TIME_H
+/* This must be before net/if.h for AIX 3.2 to enjoy life */
+#include <sys/time.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
+
+#ifdef VMS
+#include <inet.h>
+#endif
+
+#include "inet_ntop.h"
+#include "memory.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#define SYS_ERROR -1
+
+char *Curl_if2ip(const char *interface, char *buf, int buf_size)
+{
+ int dummy;
+ char *ip=NULL;
+
+ if(!interface)
+ return NULL;
+
+ dummy = socket(AF_INET, SOCK_STREAM, 0);
+ if (SYS_ERROR == dummy) {
+ return NULL;
+ }
+ else {
+ struct ifreq req;
+ size_t len = strlen(interface);
+ memset(&req, 0, sizeof(req));
+ if(len >= sizeof(req.ifr_name))
+ return NULL; /* this can't be a fine interface name */
+ memcpy(req.ifr_name, interface, len+1);
+ req.ifr_addr.sa_family = AF_INET;
+#ifdef IOCTL_3_ARGS
+ if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req)) {
+#else
+ if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req, sizeof(req))) {
+#endif
+ sclose(dummy);
+ return NULL;
+ }
+ else {
+ struct in_addr in;
+
+ struct sockaddr_in *s = (struct sockaddr_in *)&req.ifr_dstaddr;
+ memcpy(&in, &s->sin_addr, sizeof(in));
+ ip = (char *) Curl_inet_ntop(s->sin_family, &in, buf, buf_size);
+ }
+ sclose(dummy);
+ }
+ return ip;
+}
+
+/* -- end of if2ip() -- */
+#else
+char *Curl_if2ip(const char *interf, char *buf, int buf_size)
+{
+ (void) interf;
+ (void) buf;
+ (void) buf_size;
+ return NULL;
+}
+#endif
diff --git a/Utilities/cmcurl/if2ip.h b/Utilities/cmcurl/if2ip.h
new file mode 100644
index 0000000000..4e86e2b27d
--- /dev/null
+++ b/Utilities/cmcurl/if2ip.h
@@ -0,0 +1,67 @@
+#ifndef __IF2IP_H
+#define __IF2IP_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#include "setup.h"
+
+extern char *Curl_if2ip(const char *interf, char *buf, int buf_size);
+
+#ifdef __INTERIX
+#include <sys/socket.h>
+
+/* Nedelcho Stanev's work-around for SFU 3.0 */
+struct ifreq {
+#define IFNAMSIZ 16
+#define IFHWADDRLEN 6
+ union {
+ char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ } ifr_ifrn;
+
+ union {
+ struct sockaddr ifru_addr;
+ struct sockaddr ifru_broadaddr;
+ struct sockaddr ifru_netmask;
+ struct sockaddr ifru_hwaddr;
+ short ifru_flags;
+ int ifru_metric;
+ int ifru_mtu;
+ } ifr_ifru;
+};
+
+/* This define was added by Daniel to avoid an extra #ifdef INTERIX in the
+ C code. */
+#define ifr_dstaddr ifr_addr
+
+#define ifr_name ifr_ifrn.ifrn_name /* interface name */
+#define ifr_addr ifr_ifru.ifru_addr /* address */
+#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
+#define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */
+#define ifr_flags ifr_ifru.ifru_flags /* flags */
+#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
+#define ifr_metric ifr_ifru.ifru_metric /* metric */
+#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
+
+#define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */
+#endif /* interix */
+
+#endif
diff --git a/Utilities/cmcurl/inet_ntoa_r.h b/Utilities/cmcurl/inet_ntoa_r.h
new file mode 100644
index 0000000000..c6c9bd8959
--- /dev/null
+++ b/Utilities/cmcurl/inet_ntoa_r.h
@@ -0,0 +1,44 @@
+#ifndef __INET_NTOA_R_H
+#define __INET_NTOA_R_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifdef HAVE_INET_NTOA_R_2_ARGS
+/*
+ * uClibc 0.9.26 (at least) doesn't define this prototype. The buffer
+ * must be at least 16 characters long.
+ */
+char *inet_ntoa_r(const struct in_addr in, char buffer[]);
+
+#else
+/*
+ * My solaris 5.6 system running gcc 2.8.1 does *not* have this prototype
+ * in any system include file! Isn't that weird?
+ */
+char *inet_ntoa_r(const struct in_addr in, char *buffer, int buflen);
+
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/inet_ntop.c b/Utilities/cmcurl/inet_ntop.c
new file mode 100644
index 0000000000..9381963f50
--- /dev/null
+++ b/Utilities/cmcurl/inet_ntop.c
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 1996-2001 Internet Software Consortium.
+ *
+ * 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 INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM 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.
+ */
+/*
+ * Original code by Paul Vixie. "curlified" by Gisle Vanem.
+ */
+
+#include "setup.h"
+
+#ifndef HAVE_INET_NTOP
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#include <string.h>
+#include <errno.h>
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#include "inet_ntop.h"
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+/* this platform has a inet_ntoa_r() function, but no proto declared anywhere
+ so we include our own proto to make compilers happy */
+#include "inet_ntoa_r.h"
+#endif
+
+#define IN6ADDRSZ 16
+#define INADDRSZ 4
+#define INT16SZ 2
+
+#ifdef USE_WINSOCK
+#define EAFNOSUPPORT WSAEAFNOSUPPORT
+#define SET_ERRNO(e) WSASetLastError(errno = (e))
+#else
+#define SET_ERRNO(e) errno = e
+#endif
+
+/*
+ * Format an IPv4 address, more or less like inet_ntoa().
+ *
+ * Returns `dst' (as a const)
+ * Note:
+ * - uses no statics
+ * - takes a unsigned char* not an in_addr as input
+ */
+static char *inet_ntop4 (const unsigned char *src, char *dst, size_t size)
+{
+#if defined(HAVE_INET_NTOA_R_2_ARGS)
+ const char *ptr;
+ curlassert(size >= 16);
+ ptr = inet_ntoa_r(*(struct in_addr*)src, dst);
+ return (char *)memmove(dst, ptr, strlen(ptr)+1);
+
+#elif defined(HAVE_INET_NTOA_R)
+ return inet_ntoa_r(*(struct in_addr*)src, dst, size);
+
+#else
+ const char *addr = inet_ntoa(*(struct in_addr*)src);
+
+ if (strlen(addr) >= size)
+ {
+ SET_ERRNO(ENOSPC);
+ return (NULL);
+ }
+ return strcpy(dst, addr);
+#endif
+}
+
+#ifdef ENABLE_IPV6
+/*
+ * Convert IPv6 binary address into presentation (printable) format.
+ */
+static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
+{
+ /*
+ * Note that int32_t and int16_t need only be "at least" large enough
+ * to contain a value of the specified size. On some systems, like
+ * Crays, there is no such thing as an integer variable with 16 bits.
+ * Keep this in mind if you think this function should have been coded
+ * to use pointer overlays. All the world's not a VAX.
+ */
+ char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
+ char *tp;
+ struct {
+ long base;
+ long len;
+ } best, cur;
+ unsigned long words[IN6ADDRSZ / INT16SZ];
+ int i;
+
+ /* Preprocess:
+ * Copy the input (bytewise) array into a wordwise array.
+ * Find the longest run of 0x00's in src[] for :: shorthanding.
+ */
+ memset(words, '\0', sizeof(words));
+ for (i = 0; i < IN6ADDRSZ; i++)
+ words[i/2] |= (src[i] << ((1 - (i % 2)) << 3));
+
+ best.base = -1;
+ cur.base = -1;
+ best.len = 0;
+ cur.len = 0;
+
+ for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
+ {
+ if (words[i] == 0)
+ {
+ if (cur.base == -1)
+ cur.base = i, cur.len = 1;
+ else
+ cur.len++;
+ }
+ else if (cur.base != -1)
+ {
+ if (best.base == -1 || cur.len > best.len)
+ best = cur;
+ cur.base = -1;
+ }
+ }
+ if ((cur.base != -1) && (best.base == -1 || cur.len > best.len))
+ best = cur;
+ if (best.base != -1 && best.len < 2)
+ best.base = -1;
+
+ /* Format the result.
+ */
+ tp = tmp;
+ for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
+ {
+ /* Are we inside the best run of 0x00's?
+ */
+ if (best.base != -1 && i >= best.base && i < (best.base + best.len))
+ {
+ if (i == best.base)
+ *tp++ = ':';
+ continue;
+ }
+
+ /* Are we following an initial run of 0x00s or any real hex?
+ */
+ if (i != 0)
+ *tp++ = ':';
+
+ /* Is this address an encapsulated IPv4?
+ */
+ if (i == 6 && best.base == 0 &&
+ (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
+ {
+ if (!inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp)))
+ {
+ SET_ERRNO(ENOSPC);
+ return (NULL);
+ }
+ tp += strlen(tp);
+ break;
+ }
+ tp += snprintf(tp, 5, "%lx", words[i]);
+ }
+
+ /* Was it a trailing run of 0x00's?
+ */
+ if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
+ *tp++ = ':';
+ *tp++ = '\0';
+
+ /* Check for overflow, copy, and we're done.
+ */
+ if ((size_t)(tp - tmp) > size)
+ {
+ SET_ERRNO(ENOSPC);
+ return (NULL);
+ }
+ return strcpy (dst, tmp);
+}
+#endif /* ENABLE_IPV6 */
+
+/*
+ * Convert a network format address to presentation format.
+ *
+ * Returns pointer to presentation format address (`buf'),
+ * Returns NULL on error (see errno).
+ */
+char *Curl_inet_ntop(int af, const void *src, char *buf, size_t size)
+{
+ switch (af) {
+ case AF_INET:
+ return inet_ntop4((const unsigned char*)src, buf, size);
+#ifdef ENABLE_IPV6
+ case AF_INET6:
+ return inet_ntop6((const unsigned char*)src, buf, size);
+#endif
+ default:
+ SET_ERRNO(EAFNOSUPPORT);
+ return NULL;
+ }
+}
+#endif /* HAVE_INET_NTOP */
diff --git a/Utilities/cmcurl/inet_ntop.h b/Utilities/cmcurl/inet_ntop.h
new file mode 100644
index 0000000000..54d64bd198
--- /dev/null
+++ b/Utilities/cmcurl/inet_ntop.h
@@ -0,0 +1,37 @@
+#ifndef __INET_NTOP_H
+#define __INET_NTOP_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+char *Curl_inet_ntop(int af, const void *addr, char *buf, size_t size);
+
+#ifdef HAVE_INET_NTOP
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#define Curl_inet_ntop(af,addr,buf,size) inet_ntop(af,addr,buf,size)
+#endif
+
+#endif /* __INET_NTOP_H */
diff --git a/Utilities/cmcurl/inet_pton.c b/Utilities/cmcurl/inet_pton.c
new file mode 100644
index 0000000000..9b9f88b5ef
--- /dev/null
+++ b/Utilities/cmcurl/inet_pton.c
@@ -0,0 +1,241 @@
+/* This is from the BIND 4.9.4 release, modified to compile by itself */
+
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM 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.
+ */
+
+#include "setup.h"
+
+#ifndef HAVE_INET_PTON
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#include <string.h>
+#include <errno.h>
+
+#include "inet_pton.h"
+
+#define IN6ADDRSZ 16
+#define INADDRSZ 4
+#define INT16SZ 2
+
+#ifdef USE_WINSOCK
+#define EAFNOSUPPORT WSAEAFNOSUPPORT
+#endif
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static int inet_pton4(const char *src, unsigned char *dst);
+#ifdef ENABLE_IPV6
+static int inet_pton6(const char *src, unsigned char *dst);
+#endif
+
+/* int
+ * inet_pton(af, src, dst)
+ * convert from presentation format (which usually means ASCII printable)
+ * to network format (which is usually some kind of binary format).
+ * return:
+ * 1 if the address was valid for the specified address family
+ * 0 if the address wasn't valid (`dst' is untouched in this case)
+ * -1 if some other error occurred (`dst' is untouched in this case, too)
+ * author:
+ * Paul Vixie, 1996.
+ */
+int
+Curl_inet_pton(int af, const char *src, void *dst)
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_pton4(src, (unsigned char *)dst));
+#ifdef ENABLE_IPV6
+#ifndef AF_INET6
+#define AF_INET6 (AF_MAX+1) /* just to let this compile */
+#endif
+ case AF_INET6:
+ return (inet_pton6(src, (unsigned char *)dst));
+#endif
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+ /* NOTREACHED */
+}
+
+/* int
+ * inet_pton4(src, dst)
+ * like inet_aton() but without all the hexadecimal and shorthand.
+ * return:
+ * 1 if `src' is a valid dotted quad, else 0.
+ * notice:
+ * does not touch `dst' unless it's returning 1.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton4(const char *src, unsigned char *dst)
+{
+ static const char digits[] = "0123456789";
+ int saw_digit, octets, ch;
+ unsigned char tmp[INADDRSZ], *tp;
+
+ saw_digit = 0;
+ octets = 0;
+ tp = tmp;
+ *tp = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr(digits, ch)) != NULL) {
+ unsigned int val = *tp * 10 + (unsigned int)(pch - digits);
+
+ if (val > 255)
+ return (0);
+ *tp = val;
+ if (! saw_digit) {
+ if (++octets > 4)
+ return (0);
+ saw_digit = 1;
+ }
+ } else if (ch == '.' && saw_digit) {
+ if (octets == 4)
+ return (0);
+ *++tp = 0;
+ saw_digit = 0;
+ } else
+ return (0);
+ }
+ if (octets < 4)
+ return (0);
+ /* bcopy(tmp, dst, INADDRSZ); */
+ memcpy(dst, tmp, INADDRSZ);
+ return (1);
+}
+
+#ifdef ENABLE_IPV6
+/* int
+ * inet_pton6(src, dst)
+ * convert presentation level address to network order binary form.
+ * return:
+ * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * notice:
+ * (1) does not touch `dst' unless it's returning 1.
+ * (2) :: in a full address is silently ignored.
+ * credit:
+ * inspired by Mark Andrews.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton6(const char *src, unsigned char *dst)
+{
+ static const char xdigits_l[] = "0123456789abcdef",
+ xdigits_u[] = "0123456789ABCDEF";
+ unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
+ const char *xdigits, *curtok;
+ int ch, saw_xdigit;
+ unsigned int val;
+
+ memset((tp = tmp), 0, IN6ADDRSZ);
+ endp = tp + IN6ADDRSZ;
+ colonp = NULL;
+ /* Leading :: requires some special handling. */
+ if (*src == ':')
+ if (*++src != ':')
+ return (0);
+ curtok = src;
+ saw_xdigit = 0;
+ val = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+ pch = strchr((xdigits = xdigits_u), ch);
+ if (pch != NULL) {
+ val <<= 4;
+ val |= (pch - xdigits);
+ if (val > 0xffff)
+ return (0);
+ saw_xdigit = 1;
+ continue;
+ }
+ if (ch == ':') {
+ curtok = src;
+ if (!saw_xdigit) {
+ if (colonp)
+ return (0);
+ colonp = tp;
+ continue;
+ }
+ if (tp + INT16SZ > endp)
+ return (0);
+ *tp++ = (unsigned char) (val >> 8) & 0xff;
+ *tp++ = (unsigned char) val & 0xff;
+ saw_xdigit = 0;
+ val = 0;
+ continue;
+ }
+ if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
+ inet_pton4(curtok, tp) > 0) {
+ tp += INADDRSZ;
+ saw_xdigit = 0;
+ break; /* '\0' was seen by inet_pton4(). */
+ }
+ return (0);
+ }
+ if (saw_xdigit) {
+ if (tp + INT16SZ > endp)
+ return (0);
+ *tp++ = (unsigned char) (val >> 8) & 0xff;
+ *tp++ = (unsigned char) val & 0xff;
+ }
+ if (colonp != NULL) {
+ /*
+ * Since some memmove()'s erroneously fail to handle
+ * overlapping regions, we'll do the shift by hand.
+ */
+ const int n = tp - colonp;
+ int i;
+
+ for (i = 1; i <= n; i++) {
+ endp[- i] = colonp[n - i];
+ colonp[n - i] = 0;
+ }
+ tp = endp;
+ }
+ if (tp != endp)
+ return (0);
+ /* bcopy(tmp, dst, IN6ADDRSZ); */
+ memcpy(dst, tmp, IN6ADDRSZ);
+ return (1);
+}
+#endif /* ENABLE_IPV6 */
+
+#endif /* HAVE_INET_PTON */
diff --git a/Utilities/cmcurl/inet_pton.h b/Utilities/cmcurl/inet_pton.h
new file mode 100644
index 0000000000..a659a97744
--- /dev/null
+++ b/Utilities/cmcurl/inet_pton.h
@@ -0,0 +1,42 @@
+#ifndef __INET_PTON_H
+#define __INET_PTON_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+int Curl_inet_pton(int, const char *, void *);
+
+#ifdef HAVE_INET_PTON
+
+#if defined(HAVE_NO_INET_PTON_PROTO)
+int inet_pton(int af, const char *src, void *dst);
+#endif
+
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#define Curl_inet_pton(x,y,z) inet_pton(x,y,z)
+#endif
+
+#endif /* __INET_PTON_H */
diff --git a/Utilities/cmcurl/krb4.c b/Utilities/cmcurl/krb4.c
new file mode 100644
index 0000000000..f2b91df69f
--- /dev/null
+++ b/Utilities/cmcurl/krb4.c
@@ -0,0 +1,425 @@
+/* This source code was modified by Martin Hedenfalk <mhe@stacken.kth.se> for
+ * use in Curl. Martin's latest changes were done 2000-09-18.
+ *
+ * It has since been patched away like a madman by Daniel Stenberg to make it
+ * better applied to curl conditions, and to make it not use globals, pollute
+ * name space and more.
+ *
+ * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * Copyright (c) 2004 - 2007 Daniel Stenberg
+ * 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.
+ *
+ * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
+ *
+ * $Id$
+ */
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_FTP
+#ifdef HAVE_KRB4
+
+#include <stdlib.h>
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#include <string.h>
+#include <krb.h>
+#include <des.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for getpid() */
+#endif
+
+#include "urldata.h"
+#include "base64.h"
+#include "ftp.h"
+#include "sendf.h"
+#include "krb4.h"
+#include "memory.h"
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#define LOCAL_ADDR (&conn->local_addr)
+#define REMOTE_ADDR conn->ip_addr->ai_addr
+#define myctladdr LOCAL_ADDR
+#define hisctladdr REMOTE_ADDR
+
+struct krb4_data {
+ des_cblock key;
+ des_key_schedule schedule;
+ char name[ANAME_SZ];
+ char instance[INST_SZ];
+ char realm[REALM_SZ];
+};
+
+#ifndef HAVE_STRLCPY
+/* if it ever goes non-static, make it Curl_ prefixed! */
+static size_t
+strlcpy (char *dst, const char *src, size_t dst_sz)
+{
+ size_t n;
+ char *p;
+
+ for (p = dst, n = 0;
+ n + 1 < dst_sz && *src != '\0';
+ ++p, ++src, ++n)
+ *p = *src;
+ *p = '\0';
+ if (*src == '\0')
+ return n;
+ else
+ return n + strlen (src);
+}
+#else
+size_t strlcpy (char *dst, const char *src, size_t dst_sz);
+#endif
+
+static int
+krb4_check_prot(void *app_data, int level)
+{
+ app_data = NULL; /* prevent compiler warning */
+ if(level == prot_confidential)
+ return -1;
+ return 0;
+}
+
+static int
+krb4_decode(void *app_data, void *buf, int len, int level,
+ struct connectdata *conn)
+{
+ MSG_DAT m;
+ int e;
+ struct krb4_data *d = app_data;
+
+ if(level == prot_safe)
+ e = krb_rd_safe(buf, len, &d->key,
+ (struct sockaddr_in *)REMOTE_ADDR,
+ (struct sockaddr_in *)LOCAL_ADDR, &m);
+ else
+ e = krb_rd_priv(buf, len, d->schedule, &d->key,
+ (struct sockaddr_in *)REMOTE_ADDR,
+ (struct sockaddr_in *)LOCAL_ADDR, &m);
+ if(e) {
+ struct SessionHandle *data = conn->data;
+ infof(data, "krb4_decode: %s\n", krb_get_err_text(e));
+ return -1;
+ }
+ memmove(buf, m.app_data, m.app_length);
+ return m.app_length;
+}
+
+static int
+krb4_overhead(void *app_data, int level, int len)
+{
+ /* no arguments are used, just init them to prevent compiler warnings */
+ app_data = NULL;
+ level = 0;
+ len = 0;
+ return 31;
+}
+
+static int
+krb4_encode(void *app_data, void *from, int length, int level, void **to,
+ struct connectdata *conn)
+{
+ struct krb4_data *d = app_data;
+ *to = malloc(length + 31);
+ if(level == prot_safe)
+ return krb_mk_safe(from, *to, length, &d->key,
+ (struct sockaddr_in *)LOCAL_ADDR,
+ (struct sockaddr_in *)REMOTE_ADDR);
+ else if(level == prot_private)
+ return krb_mk_priv(from, *to, length, d->schedule, &d->key,
+ (struct sockaddr_in *)LOCAL_ADDR,
+ (struct sockaddr_in *)REMOTE_ADDR);
+ else
+ return -1;
+}
+
+static int
+mk_auth(struct krb4_data *d, KTEXT adat,
+ const char *service, char *host, int checksum)
+{
+ int ret;
+ CREDENTIALS cred;
+ char sname[SNAME_SZ], inst[INST_SZ], realm[REALM_SZ];
+
+ strlcpy(sname, service, sizeof(sname));
+ strlcpy(inst, krb_get_phost(host), sizeof(inst));
+ strlcpy(realm, krb_realmofhost(host), sizeof(realm));
+ ret = krb_mk_req(adat, sname, inst, realm, checksum);
+ if(ret)
+ return ret;
+ strlcpy(sname, service, sizeof(sname));
+ strlcpy(inst, krb_get_phost(host), sizeof(inst));
+ strlcpy(realm, krb_realmofhost(host), sizeof(realm));
+ ret = krb_get_cred(sname, inst, realm, &cred);
+ memmove(&d->key, &cred.session, sizeof(des_cblock));
+ des_key_sched(&d->key, d->schedule);
+ memset(&cred, 0, sizeof(cred));
+ return ret;
+}
+
+#ifdef HAVE_KRB_GET_OUR_IP_FOR_REALM
+int krb_get_our_ip_for_realm(char *, struct in_addr *);
+#endif
+
+static int
+krb4_auth(void *app_data, struct connectdata *conn)
+{
+ int ret;
+ char *p;
+ unsigned char *ptr;
+ size_t len;
+ KTEXT_ST adat;
+ MSG_DAT msg_data;
+ int checksum;
+ u_int32_t cs;
+ struct krb4_data *d = app_data;
+ char *host = conn->host.name;
+ ssize_t nread;
+ int l = sizeof(conn->local_addr);
+ struct SessionHandle *data = conn->data;
+ CURLcode result;
+
+ if(getsockname(conn->sock[FIRSTSOCKET],
+ (struct sockaddr *)LOCAL_ADDR, &l) < 0)
+ perror("getsockname()");
+
+ checksum = getpid();
+ ret = mk_auth(d, &adat, "ftp", host, checksum);
+ if(ret == KDC_PR_UNKNOWN)
+ ret = mk_auth(d, &adat, "rcmd", host, checksum);
+ if(ret) {
+ infof(data, "%s\n", krb_get_err_text(ret));
+ return AUTH_CONTINUE;
+ }
+
+#ifdef HAVE_KRB_GET_OUR_IP_FOR_REALM
+ if (krb_get_config_bool("nat_in_use")) {
+ struct sockaddr_in *localaddr = (struct sockaddr_in *)LOCAL_ADDR;
+ struct in_addr natAddr;
+
+ if (krb_get_our_ip_for_realm(krb_realmofhost(host),
+ &natAddr) != KSUCCESS
+ && krb_get_our_ip_for_realm(NULL, &natAddr) != KSUCCESS)
+ infof(data, "Can't get address for realm %s\n",
+ krb_realmofhost(host));
+ else {
+ if (natAddr.s_addr != localaddr->sin_addr.s_addr) {
+#ifdef HAVE_INET_NTOA_R
+ char ntoa_buf[64];
+ char *ip = (char *)inet_ntoa_r(natAddr, ntoa_buf, sizeof(ntoa_buf));
+#else
+ char *ip = (char *)inet_ntoa(natAddr);
+#endif
+ infof(data, "Using NAT IP address (%s) for kerberos 4\n", ip);
+ localaddr->sin_addr = natAddr;
+ }
+ }
+ }
+#endif
+
+ if(Curl_base64_encode(conn->data, (char *)adat.dat, adat.length, &p) < 1) {
+ Curl_failf(data, "Out of memory base64-encoding");
+ return AUTH_CONTINUE;
+ }
+
+ result = Curl_ftpsendf(conn, "ADAT %s", p);
+
+ free(p);
+
+ if(result)
+ return -2;
+
+ if(Curl_GetFTPResponse(&nread, conn, NULL))
+ return -1;
+
+ if(data->state.buffer[0] != '2'){
+ Curl_failf(data, "Server didn't accept auth data");
+ return AUTH_ERROR;
+ }
+
+ p = strstr(data->state.buffer, "ADAT=");
+ if(!p) {
+ Curl_failf(data, "Remote host didn't send adat reply");
+ return AUTH_ERROR;
+ }
+ p += 5;
+ len = Curl_base64_decode(p, &ptr);
+ if(len > sizeof(adat.dat)-1) {
+ free(ptr);
+ len=0;
+ }
+ if(!len || !ptr) {
+ Curl_failf(data, "Failed to decode base64 from server");
+ return AUTH_ERROR;
+ }
+ memcpy((char *)adat.dat, ptr, len);
+ free(ptr);
+ adat.length = len;
+ ret = krb_rd_safe(adat.dat, adat.length, &d->key,
+ (struct sockaddr_in *)hisctladdr,
+ (struct sockaddr_in *)myctladdr, &msg_data);
+ if(ret) {
+ Curl_failf(data, "Error reading reply from server: %s",
+ krb_get_err_text(ret));
+ return AUTH_ERROR;
+ }
+ krb_get_int(msg_data.app_data, &cs, 4, 0);
+ if(cs - checksum != 1) {
+ Curl_failf(data, "Bad checksum returned from server");
+ return AUTH_ERROR;
+ }
+ return AUTH_OK;
+}
+
+struct Curl_sec_client_mech Curl_krb4_client_mech = {
+ "KERBEROS_V4",
+ sizeof(struct krb4_data),
+ NULL, /* init */
+ krb4_auth,
+ NULL, /* end */
+ krb4_check_prot,
+ krb4_overhead,
+ krb4_encode,
+ krb4_decode
+};
+
+CURLcode Curl_krb_kauth(struct connectdata *conn)
+{
+ des_cblock key;
+ des_key_schedule schedule;
+ KTEXT_ST tkt, tktcopy;
+ char *name;
+ char *p;
+ char passwd[100];
+ size_t tmp;
+ ssize_t nread;
+ int save;
+ CURLcode result;
+ unsigned char *ptr;
+
+ save = Curl_set_command_prot(conn, prot_private);
+
+ result = Curl_ftpsendf(conn, "SITE KAUTH %s", conn->user);
+
+ if(result)
+ return result;
+
+ result = Curl_GetFTPResponse(&nread, conn, NULL);
+ if(result)
+ return result;
+
+ if(conn->data->state.buffer[0] != '3'){
+ Curl_set_command_prot(conn, save);
+ return CURLE_FTP_WEIRD_SERVER_REPLY;
+ }
+
+ p = strstr(conn->data->state.buffer, "T=");
+ if(!p) {
+ Curl_failf(conn->data, "Bad reply from server");
+ Curl_set_command_prot(conn, save);
+ return CURLE_FTP_WEIRD_SERVER_REPLY;
+ }
+
+ p += 2;
+ tmp = Curl_base64_decode(p, &ptr);
+ if(tmp >= sizeof(tkt.dat)) {
+ free(ptr);
+ tmp=0;
+ }
+ if(!tmp || !ptr) {
+ Curl_failf(conn->data, "Failed to decode base64 in reply.\n");
+ Curl_set_command_prot(conn, save);
+ return CURLE_FTP_WEIRD_SERVER_REPLY;
+ }
+ memcpy((char *)tkt.dat, ptr, tmp);
+ free(ptr);
+ tkt.length = tmp;
+ tktcopy.length = tkt.length;
+
+ p = strstr(conn->data->state.buffer, "P=");
+ if(!p) {
+ Curl_failf(conn->data, "Bad reply from server");
+ Curl_set_command_prot(conn, save);
+ return CURLE_FTP_WEIRD_SERVER_REPLY;
+ }
+ name = p + 2;
+ for(; *p && *p != ' ' && *p != '\r' && *p != '\n'; p++);
+ *p = 0;
+
+ des_string_to_key (conn->passwd, &key);
+ des_key_sched(&key, schedule);
+
+ des_pcbc_encrypt((void *)tkt.dat, (void *)tktcopy.dat,
+ tkt.length,
+ schedule, &key, DES_DECRYPT);
+ if (strcmp ((char*)tktcopy.dat + 8,
+ KRB_TICKET_GRANTING_TICKET) != 0) {
+ afs_string_to_key(passwd,
+ krb_realmofhost(conn->host.name),
+ &key);
+ des_key_sched(&key, schedule);
+ des_pcbc_encrypt((void *)tkt.dat, (void *)tktcopy.dat,
+ tkt.length,
+ schedule, &key, DES_DECRYPT);
+ }
+ memset(key, 0, sizeof(key));
+ memset(schedule, 0, sizeof(schedule));
+ memset(passwd, 0, sizeof(passwd));
+ if(Curl_base64_encode(conn->data, (char *)tktcopy.dat, tktcopy.length, &p)
+ < 1) {
+ failf(conn->data, "Out of memory base64-encoding.");
+ Curl_set_command_prot(conn, save);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ memset (tktcopy.dat, 0, tktcopy.length);
+
+ result = Curl_ftpsendf(conn, "SITE KAUTH %s %s", name, p);
+ free(p);
+ if(result)
+ return result;
+
+ result = Curl_GetFTPResponse(&nread, conn, NULL);
+ if(result)
+ return result;
+ Curl_set_command_prot(conn, save);
+
+ return CURLE_OK;
+}
+
+#endif /* HAVE_KRB4 */
+#endif /* CURL_DISABLE_FTP */
diff --git a/Utilities/cmcurl/krb4.h b/Utilities/cmcurl/krb4.h
new file mode 100644
index 0000000000..f46416e620
--- /dev/null
+++ b/Utilities/cmcurl/krb4.h
@@ -0,0 +1,70 @@
+#ifndef __KRB4_H
+#define __KRB4_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+struct Curl_sec_client_mech {
+ const char *name;
+ size_t size;
+ int (*init)(void *);
+ int (*auth)(void *, struct connectdata *);
+ void (*end)(void *);
+ int (*check_prot)(void *, int);
+ int (*overhead)(void *, int, int);
+ int (*encode)(void *, void*, int, int, void**, struct connectdata *);
+ int (*decode)(void *, void*, int, int, struct connectdata *);
+};
+
+
+#define AUTH_OK 0
+#define AUTH_CONTINUE 1
+#define AUTH_ERROR 2
+
+extern struct Curl_sec_client_mech Curl_krb4_client_mech;
+
+CURLcode Curl_krb_kauth(struct connectdata *conn);
+int Curl_sec_fflush_fd(struct connectdata *conn, int fd);
+int Curl_sec_fprintf (struct connectdata *, FILE *, const char *, ...);
+int Curl_sec_getc (struct connectdata *conn, FILE *);
+int Curl_sec_putc (struct connectdata *conn, int, FILE *);
+int Curl_sec_read (struct connectdata *conn, int, void *, int);
+int Curl_sec_read_msg (struct connectdata *conn, char *, int);
+
+int Curl_sec_vfprintf(struct connectdata *, FILE *, const char *, va_list);
+int Curl_sec_fprintf2(struct connectdata *conn, FILE *f, const char *fmt, ...);
+int Curl_sec_vfprintf2(struct connectdata *conn, FILE *, const char *, va_list);
+ssize_t Curl_sec_send(struct connectdata *conn, int, char *, int);
+int Curl_sec_write(struct connectdata *conn, int, char *, int);
+
+void Curl_sec_end (struct connectdata *);
+int Curl_sec_login (struct connectdata *);
+void Curl_sec_prot (int, char **);
+int Curl_sec_request_prot (struct connectdata *conn, const char *level);
+void Curl_sec_set_protection_level(struct connectdata *conn);
+void Curl_sec_status (void);
+
+enum protection_level Curl_set_command_prot(struct connectdata *,
+ enum protection_level);
+
+
+#endif
diff --git a/Utilities/cmcurl/ldap.c b/Utilities/cmcurl/ldap.c
new file mode 100644
index 0000000000..3e1144d4fe
--- /dev/null
+++ b/Utilities/cmcurl/ldap.c
@@ -0,0 +1,702 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_LDAP
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef NEED_MALLOC_H
+#include <malloc.h>
+#endif
+#include <errno.h>
+
+#if defined(WIN32)
+# include <winldap.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#ifdef HAVE_DLFCN_H
+# include <dlfcn.h>
+#endif
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "sendf.h"
+#include "escape.h"
+#include "transfer.h"
+#include "strequal.h"
+#include "strtok.h"
+#include "ldap.h"
+#include "memory.h"
+#include "base64.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#include "memdebug.h"
+
+/* WLdap32.dll functions are *not* stdcall. Must call these via __cdecl
+ * pointers in case libcurl was compiled as fastcall (cl -Gr). Watcom
+ * uses fastcall by default.
+ */
+#if !defined(WIN32) && !defined(__cdecl)
+#define __cdecl
+#endif
+
+#ifndef LDAP_SIZELIMIT_EXCEEDED
+#define LDAP_SIZELIMIT_EXCEEDED 4
+#endif
+#ifndef LDAP_VERSION2
+#define LDAP_VERSION2 2
+#endif
+#ifndef LDAP_VERSION3
+#define LDAP_VERSION3 3
+#endif
+#ifndef LDAP_OPT_PROTOCOL_VERSION
+#define LDAP_OPT_PROTOCOL_VERSION 0x0011
+#endif
+
+#define DLOPEN_MODE RTLD_LAZY /*! assume all dlopen() implementations have
+ this */
+
+#if defined(RTLD_LAZY_GLOBAL) /* It turns out some systems use this: */
+# undef DLOPEN_MODE
+# define DLOPEN_MODE RTLD_LAZY_GLOBAL
+#elif defined(RTLD_GLOBAL)
+# undef DLOPEN_MODE
+# define DLOPEN_MODE (RTLD_LAZY | RTLD_GLOBAL)
+#endif
+
+#define DYNA_GET_FUNCTION(type, fnc) do { \
+ (fnc) = (type)DynaGetFunction(#fnc); \
+ if ((fnc) == NULL) \
+ return CURLE_FUNCTION_NOT_FOUND; \
+ } while (0)
+
+/*! CygWin etc. configure could set these, but we don't want it.
+ * Must use WLdap32.dll code.
+ */
+#if defined(WIN32)
+#undef HAVE_DLOPEN
+#undef HAVE_LIBDL
+#endif
+
+/*
+ * We use this ZERO_NULL to avoid picky compiler warnings,
+ * when assigning a NULL pointer to a function pointer var.
+ */
+
+#define ZERO_NULL 0
+
+typedef void * (*dynafunc)(void *input);
+
+/***********************************************************************
+ */
+#if defined(HAVE_DLOPEN) || defined(HAVE_LIBDL) || defined(WIN32)
+static void *libldap = NULL;
+#if defined(DL_LBER_FILE)
+static void *liblber = NULL;
+#endif
+#endif
+
+struct bv {
+ unsigned long bv_len;
+ char *bv_val;
+};
+
+static int DynaOpen(const char **mod_name)
+{
+#if defined(HAVE_DLOPEN) || defined(HAVE_LIBDL)
+ if (libldap == NULL) {
+ /*
+ * libldap.so can normally resolve its dependency on liblber.so
+ * automatically, but in broken installation it does not so
+ * handle it here by opening liblber.so as global.
+ */
+#ifdef DL_LBER_FILE
+ *mod_name = DL_LBER_FILE;
+ liblber = dlopen(*mod_name, DLOPEN_MODE);
+ if (!liblber)
+ return 0;
+#endif
+
+ /* Assume loading libldap.so will fail if loading of liblber.so failed
+ */
+ *mod_name = DL_LDAP_FILE;
+ libldap = dlopen(*mod_name, RTLD_LAZY);
+ }
+ return (libldap != NULL);
+
+#elif defined(WIN32)
+ *mod_name = DL_LDAP_FILE;
+ if (!libldap)
+ libldap = (void*)LoadLibrary(*mod_name);
+ return (libldap != NULL);
+
+#else
+ *mod_name = "";
+ return (0);
+#endif
+}
+
+static void DynaClose(void)
+{
+#if defined(HAVE_DLOPEN) || defined(HAVE_LIBDL)
+ if (libldap) {
+ dlclose(libldap);
+ libldap=NULL;
+ }
+#ifdef DL_LBER_FILE
+ if (liblber) {
+ dlclose(liblber);
+ liblber=NULL;
+ }
+#endif
+#elif defined(WIN32)
+ if (libldap) {
+ FreeLibrary ((HMODULE)libldap);
+ libldap = NULL;
+ }
+#endif
+}
+
+static dynafunc DynaGetFunction(const char *name)
+{
+ dynafunc func = (dynafunc)ZERO_NULL;
+
+#if defined(HAVE_DLOPEN) || defined(HAVE_LIBDL)
+ if (libldap) {
+ /* This typecast magic below was brought by Joe Halpin. In ISO C, you
+ * cannot typecast a data pointer to a function pointer, but that's
+ * exactly what we need to do here to avoid compiler warnings on picky
+ * compilers! */
+ *(void**) (&func) = dlsym(libldap, name);
+ }
+#elif defined(WIN32)
+ if (libldap) {
+ func = (dynafunc)GetProcAddress((HINSTANCE)libldap, name);
+ }
+#else
+ (void) name;
+#endif
+ return func;
+}
+
+/***********************************************************************
+ */
+typedef struct ldap_url_desc {
+ struct ldap_url_desc *lud_next;
+ char *lud_scheme;
+ char *lud_host;
+ int lud_port;
+ char *lud_dn;
+ char **lud_attrs;
+ int lud_scope;
+ char *lud_filter;
+ char **lud_exts;
+ int lud_crit_exts;
+} LDAPURLDesc;
+
+#ifdef WIN32
+static int _ldap_url_parse (const struct connectdata *conn,
+ LDAPURLDesc **ludp);
+static void _ldap_free_urldesc (LDAPURLDesc *ludp);
+
+static void (*ldap_free_urldesc)(LDAPURLDesc *) = _ldap_free_urldesc;
+#endif
+
+#ifdef DEBUG_LDAP
+ #define LDAP_TRACE(x) do { \
+ _ldap_trace ("%u: ", __LINE__); \
+ _ldap_trace x; \
+ } while (0)
+
+ static void _ldap_trace (const char *fmt, ...);
+#else
+ #define LDAP_TRACE(x) ((void)0)
+#endif
+
+
+CURLcode Curl_ldap(struct connectdata *conn, bool *done)
+{
+ CURLcode status = CURLE_OK;
+ int rc = 0;
+#ifndef WIN32
+ int (*ldap_url_parse)(char *, LDAPURLDesc **);
+ void (*ldap_free_urldesc)(void *);
+#endif
+ void *(__cdecl *ldap_init)(char *, int);
+ int (__cdecl *ldap_simple_bind_s)(void *, char *, char *);
+ int (__cdecl *ldap_unbind_s)(void *);
+ int (__cdecl *ldap_search_s)(void *, char *, int, char *, char **,
+ int, void **);
+ void *(__cdecl *ldap_first_entry)(void *, void *);
+ void *(__cdecl *ldap_next_entry)(void *, void *);
+ char *(__cdecl *ldap_err2string)(int);
+ char *(__cdecl *ldap_get_dn)(void *, void *);
+ char *(__cdecl *ldap_first_attribute)(void *, void *, void **);
+ char *(__cdecl *ldap_next_attribute)(void *, void *, void *);
+ void **(__cdecl *ldap_get_values_len)(void *, void *, const char *);
+ void (__cdecl *ldap_value_free_len)(void **);
+ void (__cdecl *ldap_memfree)(void *);
+ void (__cdecl *ber_free)(void *, int);
+ int (__cdecl *ldap_set_option)(void *, int, void *);
+
+ void *server;
+ LDAPURLDesc *ludp = NULL;
+ const char *mod_name;
+ void *result;
+ void *entryIterator; /*! type should be 'LDAPMessage *' */
+ int num = 0;
+ struct SessionHandle *data=conn->data;
+ int ldap_proto;
+ char *val_b64;
+ size_t val_b64_sz;
+
+ *done = TRUE; /* unconditionally */
+ infof(data, "LDAP local: %s\n", data->change.url);
+
+ if (!DynaOpen(&mod_name)) {
+ failf(data, "The %s LDAP library/libraries couldn't be opened", mod_name);
+ return CURLE_LIBRARY_NOT_FOUND;
+ }
+
+ /* The types are needed because ANSI C distinguishes between
+ * pointer-to-object (data) and pointer-to-function.
+ */
+ DYNA_GET_FUNCTION(void *(__cdecl *)(char *, int), ldap_init);
+ DYNA_GET_FUNCTION(int (__cdecl *)(void *, char *, char *),
+ ldap_simple_bind_s);
+ DYNA_GET_FUNCTION(int (__cdecl *)(void *), ldap_unbind_s);
+#ifndef WIN32
+ DYNA_GET_FUNCTION(int (*)(char *, LDAPURLDesc **), ldap_url_parse);
+ DYNA_GET_FUNCTION(void (*)(void *), ldap_free_urldesc);
+#endif
+ DYNA_GET_FUNCTION(int (__cdecl *)(void *, char *, int, char *, char **, int,
+ void **), ldap_search_s);
+ DYNA_GET_FUNCTION(void *(__cdecl *)(void *, void *), ldap_first_entry);
+ DYNA_GET_FUNCTION(void *(__cdecl *)(void *, void *), ldap_next_entry);
+ DYNA_GET_FUNCTION(char *(__cdecl *)(int), ldap_err2string);
+ DYNA_GET_FUNCTION(char *(__cdecl *)(void *, void *), ldap_get_dn);
+ DYNA_GET_FUNCTION(char *(__cdecl *)(void *, void *, void **),
+ ldap_first_attribute);
+ DYNA_GET_FUNCTION(char *(__cdecl *)(void *, void *, void *),
+ ldap_next_attribute);
+ DYNA_GET_FUNCTION(void **(__cdecl *)(void *, void *, const char *),
+ ldap_get_values_len);
+ DYNA_GET_FUNCTION(void (__cdecl *)(void **), ldap_value_free_len);
+ DYNA_GET_FUNCTION(void (__cdecl *)(void *), ldap_memfree);
+ DYNA_GET_FUNCTION(void (__cdecl *)(void *, int), ber_free);
+ DYNA_GET_FUNCTION(int (__cdecl *)(void *, int, void *), ldap_set_option);
+
+ server = (*ldap_init)(conn->host.name, (int)conn->port);
+ if (server == NULL) {
+ failf(data, "LDAP local: Cannot connect to %s:%d",
+ conn->host.name, conn->port);
+ status = CURLE_COULDNT_CONNECT;
+ goto quit;
+ }
+
+ ldap_proto = LDAP_VERSION3;
+ (*ldap_set_option)(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto);
+ rc = (*ldap_simple_bind_s)(server,
+ conn->bits.user_passwd ? conn->user : NULL,
+ conn->bits.user_passwd ? conn->passwd : NULL);
+ if (rc != 0) {
+ ldap_proto = LDAP_VERSION2;
+ (*ldap_set_option)(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto);
+ rc = (*ldap_simple_bind_s)(server,
+ conn->bits.user_passwd ? conn->user : NULL,
+ conn->bits.user_passwd ? conn->passwd : NULL);
+ }
+ if (rc != 0) {
+ failf(data, "LDAP local: %s", (*ldap_err2string)(rc));
+ status = CURLE_LDAP_CANNOT_BIND;
+ goto quit;
+ }
+
+#ifdef WIN32
+ rc = _ldap_url_parse(conn, &ludp);
+#else
+ rc = (*ldap_url_parse)(data->change.url, &ludp);
+#endif
+
+ if (rc != 0) {
+ failf(data, "LDAP local: %s", (*ldap_err2string)(rc));
+ status = CURLE_LDAP_INVALID_URL;
+ goto quit;
+ }
+
+ rc = (*ldap_search_s)(server, ludp->lud_dn, ludp->lud_scope,
+ ludp->lud_filter, ludp->lud_attrs, 0, &result);
+
+ if (rc != 0 && rc != LDAP_SIZELIMIT_EXCEEDED) {
+ failf(data, "LDAP remote: %s", (*ldap_err2string)(rc));
+ status = CURLE_LDAP_SEARCH_FAILED;
+ goto quit;
+ }
+
+ for(num = 0, entryIterator = (*ldap_first_entry)(server, result);
+ entryIterator;
+ entryIterator = (*ldap_next_entry)(server, entryIterator), num++)
+ {
+ void *ber = NULL; /*! is really 'BerElement **' */
+ void *attribute; /*! suspicious that this isn't 'const' */
+ char *dn = (*ldap_get_dn)(server, entryIterator);
+ int i;
+
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"DN: ", 4);
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)dn, 0);
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
+
+ for (attribute = (*ldap_first_attribute)(server, entryIterator, &ber);
+ attribute;
+ attribute = (*ldap_next_attribute)(server, entryIterator, ber))
+ {
+ struct bv **vals = (struct bv **)
+ (*ldap_get_values_len)(server, entryIterator, attribute);
+
+ if (vals != NULL)
+ {
+ for (i = 0; (vals[i] != NULL); i++)
+ {
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\t", 1);
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *) attribute, 0);
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)": ", 2);
+ if ((strlen(attribute) > 7) &&
+ (strcmp(";binary",
+ (char *)attribute +
+ (strlen((char *)attribute) - 7)) == 0)) {
+ /* Binary attribute, encode to base64. */
+ val_b64_sz = Curl_base64_encode(conn->data,
+ vals[i]->bv_val,
+ vals[i]->bv_len,
+ &val_b64);
+ if (val_b64_sz > 0) {
+ Curl_client_write(conn, CLIENTWRITE_BODY, val_b64, val_b64_sz);
+ free(val_b64);
+ }
+ } else
+ Curl_client_write(conn, CLIENTWRITE_BODY, vals[i]->bv_val,
+ vals[i]->bv_len);
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 0);
+ }
+
+ /* Free memory used to store values */
+ (*ldap_value_free_len)((void **)vals);
+ }
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
+
+ (*ldap_memfree)(attribute);
+ }
+ (*ldap_memfree)(dn);
+ if (ber)
+ (*ber_free)(ber, 0);
+ }
+
+quit:
+ LDAP_TRACE (("Received %d entries\n", num));
+ if (rc == LDAP_SIZELIMIT_EXCEEDED)
+ infof(data, "There are more than %d entries\n", num);
+ if (ludp)
+ (*ldap_free_urldesc)(ludp);
+ if (server)
+ (*ldap_unbind_s)(server);
+
+ DynaClose();
+
+ /* no data to transfer */
+ Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ conn->bits.close = TRUE;
+
+ return status;
+}
+
+#ifdef DEBUG_LDAP
+static void _ldap_trace (const char *fmt, ...)
+{
+ static int do_trace = -1;
+ va_list args;
+
+ if (do_trace == -1) {
+ const char *env = getenv("CURL_TRACE");
+ do_trace = (env && atoi(env) > 0);
+ }
+ if (!do_trace)
+ return;
+
+ va_start (args, fmt);
+ vfprintf (stderr, fmt, args);
+ va_end (args);
+}
+#endif
+
+#ifdef WIN32
+/*
+ * Return scope-value for a scope-string.
+ */
+static int str2scope (const char *p)
+{
+ if (!stricmp(p, "one"))
+ return LDAP_SCOPE_ONELEVEL;
+ if (!stricmp(p, "onetree"))
+ return LDAP_SCOPE_ONELEVEL;
+ if (!stricmp(p, "base"))
+ return LDAP_SCOPE_BASE;
+ if (!stricmp(p, "sub"))
+ return LDAP_SCOPE_SUBTREE;
+ if (!stricmp( p, "subtree"))
+ return LDAP_SCOPE_SUBTREE;
+ return (-1);
+}
+
+/*
+ * Split 'str' into strings separated by commas.
+ * Note: res[] points into 'str'.
+ */
+static char **split_str (char *str)
+{
+ char **res, *lasts, *s;
+ int i;
+
+ for (i = 2, s = strchr(str,','); s; i++)
+ s = strchr(++s,',');
+
+ res = calloc(i, sizeof(char*));
+ if (!res)
+ return NULL;
+
+ for (i = 0, s = strtok_r(str, ",", &lasts); s;
+ s = strtok_r(NULL, ",", &lasts), i++)
+ res[i] = s;
+ return res;
+}
+
+/*
+ * Unescape the LDAP-URL components
+ */
+static bool unescape_elements (void *data, LDAPURLDesc *ludp)
+{
+ int i;
+
+ if (ludp->lud_filter) {
+ ludp->lud_filter = curl_easy_unescape(data, ludp->lud_filter, 0, NULL);
+ if (!ludp->lud_filter)
+ return (FALSE);
+ }
+
+ for (i = 0; ludp->lud_attrs && ludp->lud_attrs[i]; i++) {
+ ludp->lud_attrs[i] = curl_easy_unescape(data, ludp->lud_attrs[i], 0, NULL);
+ if (!ludp->lud_attrs[i])
+ return (FALSE);
+ }
+
+ for (i = 0; ludp->lud_exts && ludp->lud_exts[i]; i++) {
+ ludp->lud_exts[i] = curl_easy_unescape(data, ludp->lud_exts[i], 0, NULL);
+ if (!ludp->lud_exts[i])
+ return (FALSE);
+ }
+
+ if (ludp->lud_dn) {
+ char *dn = ludp->lud_dn;
+ char *new_dn = curl_easy_unescape(data, dn, 0, NULL);
+
+ free(dn);
+ ludp->lud_dn = new_dn;
+ if (!new_dn)
+ return (FALSE);
+ }
+ return (TRUE);
+}
+
+/*
+ * Break apart the pieces of an LDAP URL.
+ * Syntax:
+ * ldap://<hostname>:<port>/<base_dn>?<attributes>?<scope>?<filter>?<ext>
+ *
+ * <hostname> already known from 'conn->host.name'.
+ * <port> already known from 'conn->remote_port'.
+ * extract the rest from 'conn->data->reqdata.path+1'. All fields are optional.
+ * e.g.
+ * ldap://<hostname>:<port>/?<attributes>?<scope>?<filter>
+ * yields ludp->lud_dn = "".
+ *
+ * Ref. http://developer.netscape.com/docs/manuals/dirsdk/csdk30/url.htm#2831915
+ */
+static int _ldap_url_parse2 (const struct connectdata *conn, LDAPURLDesc *ludp)
+{
+ char *p, *q;
+ int i;
+
+ if (!conn->data ||
+ !conn->data->reqdata.path ||
+ conn->data->reqdata.path[0] != '/' ||
+ !checkprefix(conn->protostr, conn->data->change.url))
+ return LDAP_INVALID_SYNTAX;
+
+ ludp->lud_scope = LDAP_SCOPE_BASE;
+ ludp->lud_port = conn->remote_port;
+ ludp->lud_host = conn->host.name;
+
+ /* parse DN (Distinguished Name).
+ */
+ ludp->lud_dn = strdup(conn->data->reqdata.path+1);
+ if (!ludp->lud_dn)
+ return LDAP_NO_MEMORY;
+
+ p = strchr(ludp->lud_dn, '?');
+ LDAP_TRACE (("DN '%.*s'\n", p ? (size_t)(p-ludp->lud_dn) :
+ strlen(ludp->lud_dn), ludp->lud_dn));
+
+ if (!p)
+ goto success;
+
+ *p++ = '\0';
+
+ /* parse attributes. skip "??".
+ */
+ q = strchr(p, '?');
+ if (q)
+ *q++ = '\0';
+
+ if (*p && *p != '?') {
+ ludp->lud_attrs = split_str(p);
+ if (!ludp->lud_attrs)
+ return LDAP_NO_MEMORY;
+
+ for (i = 0; ludp->lud_attrs[i]; i++)
+ LDAP_TRACE (("attr[%d] '%s'\n", i, ludp->lud_attrs[i]));
+ }
+
+ p = q;
+ if (!p)
+ goto success;
+
+ /* parse scope. skip "??"
+ */
+ q = strchr(p, '?');
+ if (q)
+ *q++ = '\0';
+
+ if (*p && *p != '?') {
+ ludp->lud_scope = str2scope(p);
+ if (ludp->lud_scope == -1)
+ return LDAP_INVALID_SYNTAX;
+ LDAP_TRACE (("scope %d\n", ludp->lud_scope));
+ }
+
+ p = q;
+ if (!p)
+ goto success;
+
+ /* parse filter
+ */
+ q = strchr(p, '?');
+ if (q)
+ *q++ = '\0';
+ if (!*p)
+ return LDAP_INVALID_SYNTAX;
+
+ ludp->lud_filter = p;
+ LDAP_TRACE (("filter '%s'\n", ludp->lud_filter));
+
+ p = q;
+ if (!p)
+ goto success;
+
+ /* parse extensions
+ */
+ ludp->lud_exts = split_str(p);
+ if (!ludp->lud_exts)
+ return LDAP_NO_MEMORY;
+
+ for (i = 0; ludp->lud_exts[i]; i++)
+ LDAP_TRACE (("exts[%d] '%s'\n", i, ludp->lud_exts[i]));
+
+success:
+ if (!unescape_elements(conn->data, ludp))
+ return LDAP_NO_MEMORY;
+ return LDAP_SUCCESS;
+}
+
+static int _ldap_url_parse (const struct connectdata *conn,
+ LDAPURLDesc **ludpp)
+{
+ LDAPURLDesc *ludp = calloc(sizeof(*ludp), 1);
+ int rc;
+
+ *ludpp = NULL;
+ if (!ludp)
+ return LDAP_NO_MEMORY;
+
+ rc = _ldap_url_parse2 (conn, ludp);
+ if (rc != LDAP_SUCCESS) {
+ _ldap_free_urldesc(ludp);
+ ludp = NULL;
+ }
+ *ludpp = ludp;
+ return (rc);
+}
+
+static void _ldap_free_urldesc (LDAPURLDesc *ludp)
+{
+ int i;
+
+ if (!ludp)
+ return;
+
+ if (ludp->lud_dn)
+ free(ludp->lud_dn);
+
+ if (ludp->lud_filter)
+ free(ludp->lud_filter);
+
+ if (ludp->lud_attrs) {
+ for (i = 0; ludp->lud_attrs[i]; i++)
+ free(ludp->lud_attrs[i]);
+ free(ludp->lud_attrs);
+ }
+
+ if (ludp->lud_exts) {
+ for (i = 0; ludp->lud_exts[i]; i++)
+ free(ludp->lud_exts[i]);
+ free(ludp->lud_exts);
+ }
+ free (ludp);
+}
+#endif /* WIN32 */
+#endif /* CURL_DISABLE_LDAP */
diff --git a/Utilities/cmcurl/ldap.h b/Utilities/cmcurl/ldap.h
new file mode 100644
index 0000000000..b2d4f3973a
--- /dev/null
+++ b/Utilities/cmcurl/ldap.h
@@ -0,0 +1,29 @@
+#ifndef __LDAP_H
+#define __LDAP_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#ifndef CURL_DISABLE_LDAP
+CURLcode Curl_ldap(struct connectdata *conn, bool *done);
+#endif
+#endif /* __LDAP_H */
diff --git a/Utilities/cmcurl/llist.c b/Utilities/cmcurl/llist.c
new file mode 100644
index 0000000000..921d1d1f9e
--- /dev/null
+++ b/Utilities/cmcurl/llist.c
@@ -0,0 +1,138 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "llist.h"
+#include "memory.h"
+
+/* this must be the last include file */
+#include "memdebug.h"
+
+void
+Curl_llist_init(struct curl_llist *l, curl_llist_dtor dtor)
+{
+ l->size = 0;
+ l->dtor = dtor;
+ l->head = NULL;
+ l->tail = NULL;
+}
+
+struct curl_llist *
+Curl_llist_alloc(curl_llist_dtor dtor)
+{
+ struct curl_llist *list;
+
+ list = (struct curl_llist *)malloc(sizeof(struct curl_llist));
+ if(NULL == list)
+ return NULL;
+
+ Curl_llist_init(list, dtor);
+
+ return list;
+}
+
+/*
+ * Curl_llist_insert_next() returns 1 on success and 0 on failure.
+ */
+int
+Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e,
+ const void *p)
+{
+ struct curl_llist_element *ne =
+ (struct curl_llist_element *) malloc(sizeof(struct curl_llist_element));
+ if(!ne)
+ return 0;
+
+ ne->ptr = (void *) p;
+ if (list->size == 0) {
+ list->head = ne;
+ list->head->prev = NULL;
+ list->head->next = NULL;
+ list->tail = ne;
+ }
+ else {
+ ne->next = e->next;
+ ne->prev = e;
+ if (e->next) {
+ e->next->prev = ne;
+ }
+ else {
+ list->tail = ne;
+ }
+ e->next = ne;
+ }
+
+ ++list->size;
+
+ return 1;
+}
+
+int
+Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e,
+ void *user)
+{
+ if (e == NULL || list->size == 0)
+ return 1;
+
+ if (e == list->head) {
+ list->head = e->next;
+
+ if (list->head == NULL)
+ list->tail = NULL;
+ else
+ e->next->prev = NULL;
+ } else {
+ e->prev->next = e->next;
+ if (!e->next)
+ list->tail = e->prev;
+ else
+ e->next->prev = e->prev;
+ }
+
+ list->dtor(user, e->ptr);
+ free(e);
+ --list->size;
+
+ return 1;
+}
+
+void
+Curl_llist_destroy(struct curl_llist *list, void *user)
+{
+ if(list) {
+ while (list->size > 0)
+ Curl_llist_remove(list, list->tail, user);
+
+ free(list);
+ }
+}
+
+size_t
+Curl_llist_count(struct curl_llist *list)
+{
+ return list->size;
+}
diff --git a/Utilities/cmcurl/llist.h b/Utilities/cmcurl/llist.h
new file mode 100644
index 0000000000..5c7a8a0085
--- /dev/null
+++ b/Utilities/cmcurl/llist.h
@@ -0,0 +1,60 @@
+#ifndef __LLIST_H
+#define __LLIST_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+#include <stddef.h>
+
+typedef void (*curl_llist_dtor)(void *, void *);
+
+struct curl_llist_element {
+ void *ptr;
+
+ struct curl_llist_element *prev;
+ struct curl_llist_element *next;
+};
+
+struct curl_llist {
+ struct curl_llist_element *head;
+ struct curl_llist_element *tail;
+
+ curl_llist_dtor dtor;
+
+ size_t size;
+};
+
+void Curl_llist_init(struct curl_llist *, curl_llist_dtor);
+struct curl_llist *Curl_llist_alloc(curl_llist_dtor);
+int Curl_llist_insert_next(struct curl_llist *, struct curl_llist_element *,
+ const void *);
+int Curl_llist_insert_prev(struct curl_llist *, struct curl_llist_element *,
+ const void *);
+int Curl_llist_remove(struct curl_llist *, struct curl_llist_element *,
+ void *);
+int Curl_llist_remove_next(struct curl_llist *, struct curl_llist_element *,
+ void *);
+size_t Curl_llist_count(struct curl_llist *);
+void Curl_llist_destroy(struct curl_llist *, void *);
+
+#endif
diff --git a/Utilities/cmcurl/md5.c b/Utilities/cmcurl/md5.c
new file mode 100644
index 0000000000..4cfb073ea9
--- /dev/null
+++ b/Utilities/cmcurl/md5.c
@@ -0,0 +1,352 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_CRYPTO_AUTH
+
+#if !defined(USE_SSLEAY) || !defined(USE_OPENSSL)
+/* This code segment is only used if OpenSSL is not provided, as if it is
+ we use the MD5-function provided there instead. No good duplicating
+ code! */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+rights reserved.
+
+License to copy and use this software is granted provided that it
+is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+Algorithm" in all material mentioning or referencing this software
+or this function.
+
+License is also granted to make and use derivative works provided
+that such works are identified as "derived from the RSA Data
+Security, Inc. MD5 Message-Digest Algorithm" in all material
+mentioning or referencing the derived work.
+
+RSA Data Security, Inc. makes no representations concerning either
+the merchantability of this software or the suitability of this
+software for any particular purpose. It is provided "as is"
+without express or implied warranty of any kind.
+
+These notices must be retained in any copies of any part of this
+documentation and/or software.
+ */
+
+#include <string.h>
+
+/* UINT4 defines a four byte word */
+typedef unsigned int UINT4;
+
+/* MD5 context. */
+struct md5_ctx {
+ UINT4 state[4]; /* state (ABCD) */
+ UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ unsigned char buffer[64]; /* input buffer */
+};
+
+typedef struct md5_ctx MD5_CTX;
+
+static void MD5_Init(struct md5_ctx *);
+static void MD5_Update(struct md5_ctx *, const unsigned char *, unsigned int);
+static void MD5_Final(unsigned char [16], struct md5_ctx *);
+
+/* Constants for MD5Transform routine.
+ */
+
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+
+static void MD5Transform(UINT4 [4], const unsigned char [64]);
+static void Encode(unsigned char *, UINT4 *, unsigned int);
+static void Decode(UINT4 *, const unsigned char *, unsigned int);
+
+static const unsigned char PADDING[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* F, G, H and I are basic MD5 functions.
+ */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits.
+ */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+Rotation is separate from addition to prevent recomputation.
+ */
+#define FF(a, b, c, d, x, s, ac) { \
+ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define GG(a, b, c, d, x, s, ac) { \
+ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define HH(a, b, c, d, x, s, ac) { \
+ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define II(a, b, c, d, x, s, ac) { \
+ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+
+/* MD5 initialization. Begins an MD5 operation, writing a new context.
+ */
+static void MD5_Init(struct md5_ctx *context)
+{
+ context->count[0] = context->count[1] = 0;
+ /* Load magic initialization constants. */
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xefcdab89;
+ context->state[2] = 0x98badcfe;
+ context->state[3] = 0x10325476;
+}
+
+/* MD5 block update operation. Continues an MD5 message-digest
+ operation, processing another message block, and updating the
+ context.
+ */
+static void MD5_Update (struct md5_ctx *context, /* context */
+ const unsigned char *input, /* input block */
+ unsigned int inputLen) /* length of input block */
+{
+ unsigned int i, bufindex, partLen;
+
+ /* Compute number of bytes mod 64 */
+ bufindex = (unsigned int)((context->count[0] >> 3) & 0x3F);
+
+ /* Update number of bits */
+ if ((context->count[0] += ((UINT4)inputLen << 3))
+ < ((UINT4)inputLen << 3))
+ context->count[1]++;
+ context->count[1] += ((UINT4)inputLen >> 29);
+
+ partLen = 64 - bufindex;
+
+ /* Transform as many times as possible. */
+ if (inputLen >= partLen) {
+ memcpy((void *)&context->buffer[bufindex], (void *)input, partLen);
+ MD5Transform(context->state, context->buffer);
+
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ MD5Transform(context->state, &input[i]);
+
+ bufindex = 0;
+ }
+ else
+ i = 0;
+
+ /* Buffer remaining input */
+ memcpy((void *)&context->buffer[bufindex], (void *)&input[i], inputLen-i);
+}
+
+/* MD5 finalization. Ends an MD5 message-digest operation, writing the
+ the message digest and zeroizing the context.
+*/
+static void MD5_Final(unsigned char digest[16], /* message digest */
+ struct md5_ctx *context) /* context */
+{
+ unsigned char bits[8];
+ unsigned int count, padLen;
+
+ /* Save number of bits */
+ Encode (bits, context->count, 8);
+
+ /* Pad out to 56 mod 64. */
+ count = (unsigned int)((context->count[0] >> 3) & 0x3f);
+ padLen = (count < 56) ? (56 - count) : (120 - count);
+ MD5_Update (context, PADDING, padLen);
+
+ /* Append length (before padding) */
+ MD5_Update (context, bits, 8);
+
+ /* Store state in digest */
+ Encode (digest, context->state, 16);
+
+ /* Zeroize sensitive information. */
+ memset ((void *)context, 0, sizeof (*context));
+}
+
+/* MD5 basic transformation. Transforms state based on block. */
+static void MD5Transform(UINT4 state[4],
+ const unsigned char block[64])
+{
+ UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+
+ Decode (x, block, 64);
+
+ /* Round 1 */
+ FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
+ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
+ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
+ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
+ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
+ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
+ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
+ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
+ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
+ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
+ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+
+ /* Round 2 */
+ GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
+ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
+ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
+ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
+ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
+ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
+ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
+ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
+ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
+ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
+ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+
+ /* Round 3 */
+ HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
+ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
+ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
+ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
+ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
+ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
+ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
+ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
+ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
+ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+
+ /* Round 4 */
+ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
+ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
+ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
+ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
+ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
+ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
+ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
+ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
+ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
+ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+
+ /* Zeroize sensitive information. */
+ memset((void *)x, 0, sizeof (x));
+}
+
+/* Encodes input (UINT4) into output (unsigned char). Assumes len is
+ a multiple of 4.
+ */
+static void Encode (unsigned char *output,
+ UINT4 *input,
+ unsigned int len)
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[j] = (unsigned char)(input[i] & 0xff);
+ output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
+ output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+ output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+ }
+}
+
+/* Decodes input (unsigned char) into output (UINT4). Assumes len is
+ a multiple of 4.
+*/
+static void Decode (UINT4 *output,
+ const unsigned char *input,
+ unsigned int len)
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4)
+ output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
+ (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+}
+
+#else
+/* If OpenSSL is present */
+#include <openssl/md5.h>
+#include <string.h>
+#endif
+
+#include "md5.h"
+
+void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */
+ const unsigned char *input)
+{
+ MD5_CTX ctx;
+ MD5_Init(&ctx);
+ MD5_Update(&ctx, input, (unsigned int)strlen((char *)input));
+ MD5_Final(outbuffer, &ctx);
+}
+
+#endif
diff --git a/Utilities/cmcurl/md5.h b/Utilities/cmcurl/md5.h
new file mode 100644
index 0000000000..63cc70e840
--- /dev/null
+++ b/Utilities/cmcurl/md5.h
@@ -0,0 +1,29 @@
+#ifndef __MD5_H
+#define __MD5_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+void Curl_md5it(unsigned char *output,
+ const unsigned char *input);
+
+#endif
diff --git a/Utilities/cmcurl/memdebug.c b/Utilities/cmcurl/memdebug.c
new file mode 100644
index 0000000000..a8cca44cbc
--- /dev/null
+++ b/Utilities/cmcurl/memdebug.c
@@ -0,0 +1,298 @@
+#ifdef CURLDEBUG
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <curl/curl.h>
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#define _MPRINTF_REPLACE
+#include <curl/mprintf.h>
+#include "urldata.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#define MEMDEBUG_NODEFINES /* don't redefine the standard functions */
+#include "memory.h"
+#include "memdebug.h"
+
+struct memdebug {
+ size_t size;
+ double mem[1];
+ /* I'm hoping this is the thing with the strictest alignment
+ * requirements. That also means we waste some space :-( */
+};
+
+/*
+ * Note that these debug functions are very simple and they are meant to
+ * remain so. For advanced analysis, record a log file and write perl scripts
+ * to analyze them!
+ *
+ * Don't use these with multithreaded test programs!
+ */
+
+#define logfile curl_debuglogfile
+FILE *curl_debuglogfile = NULL;
+static bool memlimit = FALSE; /* enable memory limit */
+static long memsize = 0; /* set number of mallocs allowed */
+
+/* this sets the log file name */
+void curl_memdebug(const char *logname)
+{
+ if (!logfile) {
+ if(logname)
+ logfile = fopen(logname, "w");
+ else
+ logfile = stderr;
+ }
+}
+
+/* This function sets the number of malloc() calls that should return
+ successfully! */
+void curl_memlimit(long limit)
+{
+ if (!memlimit) {
+ memlimit = TRUE;
+ memsize = limit;
+ }
+}
+
+/* returns TRUE if this isn't allowed! */
+static bool countcheck(const char *func, int line, const char *source)
+{
+ /* if source is NULL, then the call is made internally and this check
+ should not be made */
+ if(memlimit && source) {
+ if(!memsize) {
+ if(logfile && source)
+ fprintf(logfile, "LIMIT %s:%d %s reached memlimit\n",
+ source, line, func);
+ if(source)
+ fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
+ source, line, func);
+ errno = ENOMEM;
+ return TRUE; /* RETURN ERROR! */
+ }
+ else
+ memsize--; /* countdown */
+
+ /* log the countdown */
+ if(logfile && source)
+ fprintf(logfile, "LIMIT %s:%d %ld ALLOCS left\n",
+ source, line, memsize);
+
+ }
+
+ return FALSE; /* allow this */
+}
+
+void *curl_domalloc(size_t wantedsize, int line, const char *source)
+{
+ struct memdebug *mem;
+ size_t size;
+
+ if(countcheck("malloc", line, source))
+ return NULL;
+
+ /* alloc at least 64 bytes */
+ size = sizeof(struct memdebug)+wantedsize;
+
+ mem=(struct memdebug *)(Curl_cmalloc)(size);
+ if(mem) {
+ /* fill memory with junk */
+ memset(mem->mem, 0xA5, wantedsize);
+ mem->size = wantedsize;
+ }
+
+ if(logfile && source)
+ fprintf(logfile, "MEM %s:%d malloc(%zd) = %p\n",
+ source, line, wantedsize, mem ? mem->mem : 0);
+ return (mem ? mem->mem : NULL);
+}
+
+void *curl_docalloc(size_t wanted_elements, size_t wanted_size,
+ int line, const char *source)
+{
+ struct memdebug *mem;
+ size_t size, user_size;
+
+ if(countcheck("calloc", line, source))
+ return NULL;
+
+ /* alloc at least 64 bytes */
+ user_size = wanted_size * wanted_elements;
+ size = sizeof(struct memdebug) + user_size;
+
+ mem = (struct memdebug *)(Curl_cmalloc)(size);
+ if(mem) {
+ /* fill memory with zeroes */
+ memset(mem->mem, 0, user_size);
+ mem->size = user_size;
+ }
+
+ if(logfile && source)
+ fprintf(logfile, "MEM %s:%d calloc(%u,%u) = %p\n",
+ source, line, wanted_elements, wanted_size, mem ? mem->mem : 0);
+ return (mem ? mem->mem : NULL);
+}
+
+char *curl_dostrdup(const char *str, int line, const char *source)
+{
+ char *mem;
+ size_t len;
+
+ curlassert(str != NULL);
+
+ if(countcheck("strdup", line, source))
+ return NULL;
+
+ len=strlen(str)+1;
+
+ mem=curl_domalloc(len, 0, NULL); /* NULL prevents logging */
+ if (mem)
+ memcpy(mem, str, len);
+
+ if(logfile)
+ fprintf(logfile, "MEM %s:%d strdup(%p) (%zd) = %p\n",
+ source, line, str, len, mem);
+
+ return mem;
+}
+
+/* We provide a realloc() that accepts a NULL as pointer, which then
+ performs a malloc(). In order to work with ares. */
+void *curl_dorealloc(void *ptr, size_t wantedsize,
+ int line, const char *source)
+{
+ struct memdebug *mem=NULL;
+
+ size_t size = sizeof(struct memdebug)+wantedsize;
+
+ if(countcheck("realloc", line, source))
+ return NULL;
+
+ if(ptr)
+ mem = (struct memdebug *)((char *)ptr - offsetof(struct memdebug, mem));
+
+ mem=(struct memdebug *)(Curl_crealloc)(mem, size);
+ if(logfile)
+ fprintf(logfile, "MEM %s:%d realloc(%p, %zd) = %p\n",
+ source, line, ptr, wantedsize, mem?mem->mem:NULL);
+
+ if(mem) {
+ mem->size = wantedsize;
+ return mem->mem;
+ }
+
+ return NULL;
+}
+
+void curl_dofree(void *ptr, int line, const char *source)
+{
+ struct memdebug *mem;
+
+ curlassert(ptr != NULL);
+
+ mem = (struct memdebug *)((char *)ptr - offsetof(struct memdebug, mem));
+
+ /* destroy */
+ memset(mem->mem, 0x13, mem->size);
+
+ /* free for real */
+ (Curl_cfree)(mem);
+
+ if(logfile)
+ fprintf(logfile, "MEM %s:%d free(%p)\n", source, line, ptr);
+}
+
+int curl_socket(int domain, int type, int protocol, int line,
+ const char *source)
+{
+ int sockfd=(socket)(domain, type, protocol);
+ if(logfile && (sockfd!=-1))
+ fprintf(logfile, "FD %s:%d socket() = %d\n",
+ source, line, sockfd);
+ return sockfd;
+}
+
+int curl_accept(int s, void *saddr, void *saddrlen,
+ int line, const char *source)
+{
+ struct sockaddr *addr = (struct sockaddr *)saddr;
+ socklen_t *addrlen = (socklen_t *)saddrlen;
+ int sockfd=(accept)(s, addr, addrlen);
+ if(logfile)
+ fprintf(logfile, "FD %s:%d accept() = %d\n",
+ source, line, sockfd);
+ return sockfd;
+}
+
+/* this is our own defined way to close sockets on *ALL* platforms */
+int curl_sclose(int sockfd, int line, const char *source)
+{
+ int res=sclose(sockfd);
+ if(logfile)
+ fprintf(logfile, "FD %s:%d sclose(%d)\n",
+ source, line, sockfd);
+ return res;
+}
+
+FILE *curl_fopen(const char *file, const char *mode,
+ int line, const char *source)
+{
+ FILE *res=(fopen)(file, mode);
+ if(logfile)
+ fprintf(logfile, "FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
+ source, line, file, mode, res);
+ return res;
+}
+
+int curl_fclose(FILE *file, int line, const char *source)
+{
+ int res;
+
+ curlassert(file != NULL);
+
+ res=(fclose)(file);
+ if(logfile)
+ fprintf(logfile, "FILE %s:%d fclose(%p)\n",
+ source, line, file);
+ return res;
+}
+#else
+#ifdef VMS
+int VOID_VAR_MEMDEBUG;
+#else
+/* we provide a fake do-nothing function here to avoid compiler warnings */
+void curl_memdebug(void) {}
+#endif /* VMS */
+#endif /* CURLDEBUG */
diff --git a/Utilities/cmcurl/memdebug.h b/Utilities/cmcurl/memdebug.h
new file mode 100644
index 0000000000..a4ce7e59a8
--- /dev/null
+++ b/Utilities/cmcurl/memdebug.h
@@ -0,0 +1,125 @@
+#ifdef CURLDEBUG
+#ifndef _CURL_MEDEBUG_H
+#define _CURL_MEDEBUG_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * CAUTION: this header is designed to work when included by the app-side
+ * as well as the library. Do not mix with library internals!
+ */
+
+#include "setup.h"
+
+#include <curl/curl.h>
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_MEMORY_H
+#include <memory.h>
+#endif
+
+#define logfile curl_debuglogfile
+
+extern FILE *logfile;
+
+/* memory functions */
+CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source);
+CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line, const char *source);
+CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line, const char *source);
+CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source);
+CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source);
+CURL_EXTERN void curl_memdebug(const char *logname);
+CURL_EXTERN void curl_memlimit(long limit);
+
+/* file descriptor manipulators */
+CURL_EXTERN int curl_socket(int domain, int type, int protocol, int line , const char *);
+CURL_EXTERN int curl_sclose(int sockfd, int, const char *source);
+CURL_EXTERN int curl_accept(int s, void *addr, void *addrlen,
+ int line, const char *source);
+
+/* FILE functions */
+CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line,
+ const char *source);
+CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
+
+#ifndef MEMDEBUG_NODEFINES
+
+/* Set this symbol on the command-line, recompile all lib-sources */
+#undef strdup
+#define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
+#define malloc(size) curl_domalloc(size, __LINE__, __FILE__)
+#define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__)
+#define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
+#define free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
+
+#define socket(domain,type,protocol)\
+ curl_socket(domain,type,protocol,__LINE__,__FILE__)
+#undef accept /* for those with accept as a macro */
+#define accept(sock,addr,len)\
+ curl_accept(sock,addr,len,__LINE__,__FILE__)
+
+#if defined(getaddrinfo) && defined(__osf__)
+/* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define
+ our macro as for other platforms. Instead, we redefine the new name they
+ define getaddrinfo to become! */
+#define ogetaddrinfo(host,serv,hint,res) \
+ curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
+#else
+#undef getaddrinfo
+#define getaddrinfo(host,serv,hint,res) \
+ curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
+#endif
+
+#ifdef HAVE_GETNAMEINFO
+#undef getnameinfo
+#define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \
+ curl_dogetnameinfo(sa,salen,host,hostlen,serv,servlen,flags, __LINE__, \
+ __FILE__)
+#endif
+
+#undef freeaddrinfo
+#define freeaddrinfo(data) \
+ curl_dofreeaddrinfo(data,__LINE__,__FILE__)
+
+/* sclose is probably already defined, redefine it! */
+#undef sclose
+#define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
+/* ares-adjusted define: */
+#undef closesocket
+#define closesocket(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
+
+#undef fopen
+#define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__)
+#define fclose(file) curl_fclose(file,__LINE__,__FILE__)
+
+#endif /* MEMDEBUG_NODEFINES */
+
+#endif /* _CURL_MEDEBUG_H */
+#endif /* CURLDEBUG */
diff --git a/Utilities/cmcurl/memory.h b/Utilities/cmcurl/memory.h
new file mode 100644
index 0000000000..076d20a28a
--- /dev/null
+++ b/Utilities/cmcurl/memory.h
@@ -0,0 +1,50 @@
+#ifndef _CURL_MEMORY_H
+#define _CURL_MEMORY_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include <curl/curl.h> /* for the typedefs */
+
+extern curl_malloc_callback Curl_cmalloc;
+extern curl_free_callback Curl_cfree;
+extern curl_realloc_callback Curl_crealloc;
+extern curl_strdup_callback Curl_cstrdup;
+extern curl_calloc_callback Curl_ccalloc;
+
+#ifndef CURLDEBUG
+/* Only do this define-mania if we're not using the memdebug system, as that
+ has preference on this magic. */
+#undef strdup
+#define strdup(ptr) Curl_cstrdup(ptr)
+#undef malloc
+#define malloc(size) Curl_cmalloc(size)
+#undef calloc
+#define calloc(nbelem,size) Curl_ccalloc(nbelem, size)
+#undef realloc
+#define realloc(ptr,size) Curl_crealloc(ptr, size)
+#undef free
+#define free(ptr) Curl_cfree(ptr)
+
+#endif
+
+#endif /* _CURL_MEMORY_H */
diff --git a/Utilities/cmcurl/mprintf.c b/Utilities/cmcurl/mprintf.c
new file mode 100644
index 0000000000..8b2f3d07e6
--- /dev/null
+++ b/Utilities/cmcurl/mprintf.c
@@ -0,0 +1,1218 @@
+/****************************************************************************
+ *
+ * $Id$
+ *
+ *************************************************************************
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
+ * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
+ *
+ * Purpose:
+ * A merge of Bjorn Reese's format() function and Daniel's dsprintf()
+ * 1.0. A full blooded printf() clone with full support for <num>$
+ * everywhere (parameters, widths and precisions) including variabled
+ * sized parameters (like doubles, long longs, long doubles and even
+ * void * in 64-bit architectures).
+ *
+ * Current restrictions:
+ * - Max 128 parameters
+ * - No 'long double' support.
+ *
+ * If you ever want truly portable and good *printf() clones, the project that
+ * took on from here is named 'Trio' and you find more details on the trio web
+ * page at http://daniel.haxx.se/trio/
+ */
+
+
+#include "setup.h"
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <string.h>
+
+#if defined(DJGPP) && (DJGPP_MINOR < 4)
+#undef _MPRINTF_REPLACE /* don't use x_was_used() here */
+#endif
+
+#include <curl/mprintf.h>
+
+#ifndef SIZEOF_SIZE_T
+/* default to 4 bytes for size_t unless defined in the config.h */
+#define SIZEOF_SIZE_T 4
+#endif
+
+#ifdef DPRINTF_DEBUG
+#define HAVE_LONGLONG
+#define LONG_LONG long long
+#define ENABLE_64BIT
+#endif
+
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#define BUFFSIZE 256 /* buffer for long-to-str and float-to-str calcs */
+#define MAX_PARAMETERS 128 /* lame static limit */
+
+#undef TRUE
+#undef FALSE
+#undef BOOL
+#ifdef __cplusplus
+# define TRUE true
+# define FALSE false
+# define BOOL bool
+#else
+# define TRUE ((char)(1 == 1))
+# define FALSE ((char)(0 == 1))
+# define BOOL char
+#endif
+
+#ifdef _AMIGASF
+# undef FORMAT_INT
+#endif
+
+/* Lower-case digits. */
+static const char lower_digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+
+/* Upper-case digits. */
+static const char upper_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+#define OUTCHAR(x) \
+ do{ \
+ if(stream((unsigned char)(x), (FILE *)data) != -1) \
+ done++; \
+ else \
+ return done; /* return immediately on failure */ \
+ } while(0)
+
+/* Data type to read from the arglist */
+typedef enum {
+ FORMAT_UNKNOWN = 0,
+ FORMAT_STRING,
+ FORMAT_PTR,
+ FORMAT_INT,
+ FORMAT_INTPTR,
+ FORMAT_LONG,
+ FORMAT_LONGLONG,
+ FORMAT_DOUBLE,
+ FORMAT_LONGDOUBLE,
+ FORMAT_WIDTH /* For internal use */
+} FormatType;
+
+/* convertion and display flags */
+enum {
+ FLAGS_NEW = 0,
+ FLAGS_SPACE = 1<<0,
+ FLAGS_SHOWSIGN = 1<<1,
+ FLAGS_LEFT = 1<<2,
+ FLAGS_ALT = 1<<3,
+ FLAGS_SHORT = 1<<4,
+ FLAGS_LONG = 1<<5,
+ FLAGS_LONGLONG = 1<<6,
+ FLAGS_LONGDOUBLE = 1<<7,
+ FLAGS_PAD_NIL = 1<<8,
+ FLAGS_UNSIGNED = 1<<9,
+ FLAGS_OCTAL = 1<<10,
+ FLAGS_HEX = 1<<11,
+ FLAGS_UPPER = 1<<12,
+ FLAGS_WIDTH = 1<<13, /* '*' or '*<num>$' used */
+ FLAGS_WIDTHPARAM = 1<<14, /* width PARAMETER was specified */
+ FLAGS_PREC = 1<<15, /* precision was specified */
+ FLAGS_PRECPARAM = 1<<16, /* precision PARAMETER was specified */
+ FLAGS_CHAR = 1<<17, /* %c story */
+ FLAGS_FLOATE = 1<<18, /* %e or %E */
+ FLAGS_FLOATG = 1<<19 /* %g or %G */
+};
+
+typedef struct {
+ FormatType type;
+ int flags;
+ long width; /* width OR width parameter number */
+ long precision; /* precision OR precision parameter number */
+ union {
+ char *str;
+ void *ptr;
+ long num;
+#ifdef ENABLE_64BIT
+ LONG_LONG lnum;
+#endif
+ double dnum;
+ } data;
+} va_stack_t;
+
+struct nsprintf {
+ char *buffer;
+ size_t length;
+ size_t max;
+};
+
+struct asprintf {
+ char *buffer; /* allocated buffer */
+ size_t len; /* length of string */
+ size_t alloc; /* length of alloc */
+ bool fail; /* TRUE if an alloc has failed and thus the output is not
+ the complete data */
+};
+
+int curl_msprintf(char *buffer, const char *format, ...);
+
+static long dprintf_DollarString(char *input, char **end)
+{
+ int number=0;
+ while(ISDIGIT(*input)) {
+ number *= 10;
+ number += *input-'0';
+ input++;
+ }
+ if(number && ('$'==*input++)) {
+ *end = input;
+ return number;
+ }
+ return 0;
+}
+
+static BOOL dprintf_IsQualifierNoDollar(char c)
+{
+ switch (c) {
+ case '-': case '+': case ' ': case '#': case '.':
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ case 'h': case 'l': case 'L': case 'z': case 'q':
+ case '*': case 'O':
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+#ifdef DPRINTF_DEBUG2
+int dprintf_Pass1Report(va_stack_t *vto, int max)
+{
+ int i;
+ char buffer[128];
+ int bit;
+ int flags;
+
+ for(i=0; i<max; i++) {
+ char *type;
+ switch(vto[i].type) {
+ case FORMAT_UNKNOWN:
+ type = "unknown";
+ break;
+ case FORMAT_STRING:
+ type ="string";
+ break;
+ case FORMAT_PTR:
+ type ="pointer";
+ break;
+ case FORMAT_INT:
+ type = "int";
+ break;
+ case FORMAT_LONG:
+ type = "long";
+ break;
+ case FORMAT_LONGLONG:
+ type = "long long";
+ break;
+ case FORMAT_DOUBLE:
+ type = "double";
+ break;
+ case FORMAT_LONGDOUBLE:
+ type = "long double";
+ break;
+ }
+
+
+ buffer[0]=0;
+
+ for(bit=0; bit<31; bit++) {
+ flags = vto[i].flags & (1<<bit);
+
+ if(flags & FLAGS_SPACE)
+ strcat(buffer, "space ");
+ else if(flags & FLAGS_SHOWSIGN)
+ strcat(buffer, "plus ");
+ else if(flags & FLAGS_LEFT)
+ strcat(buffer, "left ");
+ else if(flags & FLAGS_ALT)
+ strcat(buffer, "alt ");
+ else if(flags & FLAGS_SHORT)
+ strcat(buffer, "short ");
+ else if(flags & FLAGS_LONG)
+ strcat(buffer, "long ");
+ else if(flags & FLAGS_LONGLONG)
+ strcat(buffer, "longlong ");
+ else if(flags & FLAGS_LONGDOUBLE)
+ strcat(buffer, "longdouble ");
+ else if(flags & FLAGS_PAD_NIL)
+ strcat(buffer, "padnil ");
+ else if(flags & FLAGS_UNSIGNED)
+ strcat(buffer, "unsigned ");
+ else if(flags & FLAGS_OCTAL)
+ strcat(buffer, "octal ");
+ else if(flags & FLAGS_HEX)
+ strcat(buffer, "hex ");
+ else if(flags & FLAGS_UPPER)
+ strcat(buffer, "upper ");
+ else if(flags & FLAGS_WIDTH)
+ strcat(buffer, "width ");
+ else if(flags & FLAGS_WIDTHPARAM)
+ strcat(buffer, "widthparam ");
+ else if(flags & FLAGS_PREC)
+ strcat(buffer, "precision ");
+ else if(flags & FLAGS_PRECPARAM)
+ strcat(buffer, "precparam ");
+ else if(flags & FLAGS_CHAR)
+ strcat(buffer, "char ");
+ else if(flags & FLAGS_FLOATE)
+ strcat(buffer, "floate ");
+ else if(flags & FLAGS_FLOATG)
+ strcat(buffer, "floatg ");
+ }
+ printf("REPORT: %d. %s [%s]\n", i, type, buffer);
+
+ }
+
+
+}
+#endif
+
+/******************************************************************
+ *
+ * Pass 1:
+ * Create an index with the type of each parameter entry and its
+ * value (may vary in size)
+ *
+ ******************************************************************/
+
+static long dprintf_Pass1(char *format, va_stack_t *vto, char **endpos,
+ va_list arglist)
+{
+ char *fmt = format;
+ int param_num = 0;
+ long this_param;
+ long width;
+ long precision;
+ int flags;
+ long max_param=0;
+ long i;
+
+ while (*fmt) {
+ if (*fmt++ == '%') {
+ if (*fmt == '%') {
+ fmt++;
+ continue; /* while */
+ }
+
+ flags = FLAGS_NEW;
+
+ /* Handle the positional case (N$) */
+
+ param_num++;
+
+ this_param = dprintf_DollarString(fmt, &fmt);
+ if (0 == this_param)
+ /* we got no positional, get the next counter */
+ this_param = param_num;
+
+ if (this_param > max_param)
+ max_param = this_param;
+
+ /*
+ * The parameter with number 'i' should be used. Next, we need
+ * to get SIZE and TYPE of the parameter. Add the information
+ * to our array.
+ */
+
+ width = 0;
+ precision = 0;
+
+ /* Handle the flags */
+
+ while (dprintf_IsQualifierNoDollar(*fmt)) {
+ switch (*fmt++) {
+ case ' ':
+ flags |= FLAGS_SPACE;
+ break;
+ case '+':
+ flags |= FLAGS_SHOWSIGN;
+ break;
+ case '-':
+ flags |= FLAGS_LEFT;
+ flags &= ~FLAGS_PAD_NIL;
+ break;
+ case '#':
+ flags |= FLAGS_ALT;
+ break;
+ case '.':
+ flags |= FLAGS_PREC;
+ if ('*' == *fmt) {
+ /* The precision is picked from a specified parameter */
+
+ flags |= FLAGS_PRECPARAM;
+ fmt++;
+ param_num++;
+
+ i = dprintf_DollarString(fmt, &fmt);
+ if (i)
+ precision = i;
+ else
+ precision = param_num;
+
+ if (precision > max_param)
+ max_param = precision;
+ }
+ else {
+ flags |= FLAGS_PREC;
+ precision = strtol(fmt, &fmt, 10);
+ }
+ break;
+ case 'h':
+ flags |= FLAGS_SHORT;
+ break;
+ case 'l':
+ if (flags & FLAGS_LONG)
+ flags |= FLAGS_LONGLONG;
+ else
+ flags |= FLAGS_LONG;
+ break;
+ case 'L':
+ flags |= FLAGS_LONGDOUBLE;
+ break;
+ case 'q':
+ flags |= FLAGS_LONGLONG;
+ break;
+ case 'z':
+ /* the code below generates a warning if -Wunreachable-code is
+ used */
+#if SIZEOF_SIZE_T>4
+ flags |= FLAGS_LONGLONG;
+#else
+ flags |= FLAGS_LONG;
+#endif
+ break;
+ case 'O':
+#if SIZEOF_CURL_OFF_T > 4
+ flags |= FLAGS_LONGLONG;
+#else
+ flags |= FLAGS_LONG;
+#endif
+ break;
+ case '0':
+ if (!(flags & FLAGS_LEFT))
+ flags |= FLAGS_PAD_NIL;
+ /* FALLTHROUGH */
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ flags |= FLAGS_WIDTH;
+ width = strtol(fmt-1, &fmt, 10);
+ break;
+ case '*': /* Special case */
+ flags |= FLAGS_WIDTHPARAM;
+ param_num++;
+
+ i = dprintf_DollarString(fmt, &fmt);
+ if(i)
+ width = i;
+ else
+ width = param_num;
+ if(width > max_param)
+ max_param=width;
+ break;
+ default:
+ break;
+ }
+ } /* switch */
+
+ /* Handle the specifier */
+
+ i = this_param - 1;
+
+ switch (*fmt) {
+ case 'S':
+ flags |= FLAGS_ALT;
+ /* FALLTHROUGH */
+ case 's':
+ vto[i].type = FORMAT_STRING;
+ break;
+ case 'n':
+ vto[i].type = FORMAT_INTPTR;
+ break;
+ case 'p':
+ vto[i].type = FORMAT_PTR;
+ break;
+ case 'd': case 'i':
+ vto[i].type = FORMAT_INT;
+ break;
+ case 'u':
+ vto[i].type = FORMAT_INT;
+ flags |= FLAGS_UNSIGNED;
+ break;
+ case 'o':
+ vto[i].type = FORMAT_INT;
+ flags |= FLAGS_OCTAL;
+ break;
+ case 'x':
+ vto[i].type = FORMAT_INT;
+ flags |= FLAGS_HEX;
+ break;
+ case 'X':
+ vto[i].type = FORMAT_INT;
+ flags |= FLAGS_HEX|FLAGS_UPPER;
+ break;
+ case 'c':
+ vto[i].type = FORMAT_INT;
+ flags |= FLAGS_CHAR;
+ break;
+ case 'f':
+ vto[i].type = FORMAT_DOUBLE;
+ break;
+ case 'e':
+ vto[i].type = FORMAT_DOUBLE;
+ flags |= FLAGS_FLOATE;
+ break;
+ case 'E':
+ vto[i].type = FORMAT_DOUBLE;
+ flags |= FLAGS_FLOATE|FLAGS_UPPER;
+ break;
+ case 'g':
+ vto[i].type = FORMAT_DOUBLE;
+ flags |= FLAGS_FLOATG;
+ break;
+ case 'G':
+ vto[i].type = FORMAT_DOUBLE;
+ flags |= FLAGS_FLOATG|FLAGS_UPPER;
+ break;
+ default:
+ vto[i].type = FORMAT_UNKNOWN;
+ break;
+ } /* switch */
+
+ vto[i].flags = flags;
+ vto[i].width = width;
+ vto[i].precision = precision;
+
+ if (flags & FLAGS_WIDTHPARAM) {
+ /* we have the width specified from a parameter, so we make that
+ parameter's info setup properly */
+ vto[i].width = width - 1;
+ i = width - 1;
+ vto[i].type = FORMAT_WIDTH;
+ vto[i].flags = FLAGS_NEW;
+ vto[i].precision = vto[i].width = 0; /* can't use width or precision
+ of width! */
+ }
+ if (flags & FLAGS_PRECPARAM) {
+ /* we have the precision specified from a parameter, so we make that
+ parameter's info setup properly */
+ vto[i].precision = precision - 1;
+ i = precision - 1;
+ vto[i].type = FORMAT_WIDTH;
+ vto[i].flags = FLAGS_NEW;
+ vto[i].precision = vto[i].width = 0; /* can't use width or precision
+ of width! */
+ }
+ *endpos++ = fmt + 1; /* end of this sequence */
+ }
+ }
+
+#ifdef DPRINTF_DEBUG2
+ dprintf_Pass1Report(vto, max_param);
+#endif
+
+ /* Read the arg list parameters into our data list */
+ for (i=0; i<max_param; i++) {
+ if ((i + 1 < max_param) && (vto[i + 1].type == FORMAT_WIDTH))
+ {
+ /* Width/precision arguments must be read before the main argument
+ * they are attached to
+ */
+ vto[i + 1].data.num = va_arg(arglist, int);
+ }
+
+ switch (vto[i].type)
+ {
+ case FORMAT_STRING:
+ vto[i].data.str = va_arg(arglist, char *);
+ break;
+
+ case FORMAT_INTPTR:
+ case FORMAT_UNKNOWN:
+ case FORMAT_PTR:
+ vto[i].data.ptr = va_arg(arglist, void *);
+ break;
+
+ case FORMAT_INT:
+#ifdef ENABLE_64BIT
+ if(vto[i].flags & FLAGS_LONGLONG)
+ vto[i].data.lnum = va_arg(arglist, LONG_LONG);
+ else
+#endif
+ if(vto[i].flags & FLAGS_LONG)
+ vto[i].data.num = va_arg(arglist, long);
+ else
+ vto[i].data.num = va_arg(arglist, int);
+ break;
+
+ case FORMAT_DOUBLE:
+ vto[i].data.dnum = va_arg(arglist, double);
+ break;
+
+ case FORMAT_WIDTH:
+ /* Argument has been read. Silently convert it into an integer
+ * for later use
+ */
+ vto[i].type = FORMAT_INT;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return max_param;
+
+}
+
+static int dprintf_formatf(
+ void *data, /* untouched by format(), just sent to the stream() function in
+ the second argument */
+ /* function pointer called for each output character */
+ int (*stream)(int, FILE *),
+ const char *format, /* %-formatted string */
+ va_list ap_save) /* list of parameters */
+{
+ /* Base-36 digits for numbers. */
+ const char *digits = lower_digits;
+
+ /* Pointer into the format string. */
+ char *f;
+
+ /* Number of characters written. */
+ int done = 0;
+
+ long param; /* current parameter to read */
+ long param_num=0; /* parameter counter */
+
+ va_stack_t vto[MAX_PARAMETERS];
+ char *endpos[MAX_PARAMETERS];
+ char **end;
+
+ char work[BUFFSIZE];
+
+ va_stack_t *p;
+
+ /* Do the actual %-code parsing */
+ dprintf_Pass1((char *)format, vto, endpos, ap_save);
+
+ end = &endpos[0]; /* the initial end-position from the list dprintf_Pass1()
+ created for us */
+
+ f = (char *)format;
+ while (*f != '\0') {
+ /* Format spec modifiers. */
+ char alt;
+
+ /* Width of a field. */
+ long width;
+
+ /* Precision of a field. */
+ long prec;
+
+ /* Decimal integer is negative. */
+ char is_neg;
+
+ /* Base of a number to be written. */
+ long base;
+
+ /* Integral values to be written. */
+#ifdef ENABLE_64BIT
+ unsigned LONG_LONG num;
+#else
+ unsigned long num;
+#endif
+ long signed_num;
+
+ if (*f != '%') {
+ /* This isn't a format spec, so write everything out until the next one
+ OR end of string is reached. */
+ do {
+ OUTCHAR(*f);
+ } while(*++f && ('%' != *f));
+ continue;
+ }
+
+ ++f;
+
+ /* Check for "%%". Note that although the ANSI standard lists
+ '%' as a conversion specifier, it says "The complete format
+ specification shall be `%%'," so we can avoid all the width
+ and precision processing. */
+ if (*f == '%') {
+ ++f;
+ OUTCHAR('%');
+ continue;
+ }
+
+ /* If this is a positional parameter, the position must follow imediately
+ after the %, thus create a %<num>$ sequence */
+ param=dprintf_DollarString(f, &f);
+
+ if(!param)
+ param = param_num;
+ else
+ --param;
+
+ param_num++; /* increase this always to allow "%2$s %1$s %s" and then the
+ third %s will pick the 3rd argument */
+
+ p = &vto[param];
+
+ /* pick up the specified width */
+ if(p->flags & FLAGS_WIDTHPARAM)
+ width = vto[p->width].data.num;
+ else
+ width = p->width;
+
+ /* pick up the specified precision */
+ if(p->flags & FLAGS_PRECPARAM)
+ prec = vto[p->precision].data.num;
+ else if(p->flags & FLAGS_PREC)
+ prec = p->precision;
+ else
+ prec = -1;
+
+ alt = (p->flags & FLAGS_ALT)?TRUE:FALSE;
+
+ switch (p->type) {
+ case FORMAT_INT:
+ num = p->data.num;
+ if(p->flags & FLAGS_CHAR) {
+ /* Character. */
+ if (!(p->flags & FLAGS_LEFT))
+ while (--width > 0)
+ OUTCHAR(' ');
+ OUTCHAR((char) num);
+ if (p->flags & FLAGS_LEFT)
+ while (--width > 0)
+ OUTCHAR(' ');
+ break;
+ }
+ if(p->flags & FLAGS_UNSIGNED) {
+ /* Decimal unsigned integer. */
+ base = 10;
+ goto unsigned_number;
+ }
+ if(p->flags & FLAGS_OCTAL) {
+ /* Octal unsigned integer. */
+ base = 8;
+ goto unsigned_number;
+ }
+ if(p->flags & FLAGS_HEX) {
+ /* Hexadecimal unsigned integer. */
+
+ digits = (p->flags & FLAGS_UPPER)? upper_digits : lower_digits;
+ base = 16;
+ goto unsigned_number;
+ }
+
+ /* Decimal integer. */
+ base = 10;
+
+#ifdef ENABLE_64BIT
+ if(p->flags & FLAGS_LONGLONG) {
+ /* long long */
+ is_neg = p->data.lnum < 0;
+ num = is_neg ? (- p->data.lnum) : p->data.lnum;
+ }
+ else
+#endif
+ {
+ signed_num = (long) num;
+ is_neg = signed_num < 0;
+ num = is_neg ? (- signed_num) : signed_num;
+ }
+ goto number;
+
+ unsigned_number:
+ /* Unsigned number of base BASE. */
+ is_neg = 0;
+
+ number:
+ /* Number of base BASE. */
+ {
+ char *workend = &work[sizeof(work) - 1];
+ char *w;
+
+ /* Supply a default precision if none was given. */
+ if (prec == -1)
+ prec = 1;
+
+ /* Put the number in WORK. */
+ w = workend;
+ while (num > 0) {
+ *w-- = digits[num % base];
+ num /= base;
+ }
+ width -= (long)(workend - w);
+ prec -= (long)(workend - w);
+
+ if (alt && base == 8 && prec <= 0) {
+ *w-- = '0';
+ --width;
+ }
+
+ if (prec > 0) {
+ width -= prec;
+ while (prec-- > 0)
+ *w-- = '0';
+ }
+
+ if (alt && base == 16)
+ width -= 2;
+
+ if (is_neg || (p->flags & FLAGS_SHOWSIGN) || (p->flags & FLAGS_SPACE))
+ --width;
+
+ if (!(p->flags & FLAGS_LEFT) && !(p->flags & FLAGS_PAD_NIL))
+ while (width-- > 0)
+ OUTCHAR(' ');
+
+ if (is_neg)
+ OUTCHAR('-');
+ else if (p->flags & FLAGS_SHOWSIGN)
+ OUTCHAR('+');
+ else if (p->flags & FLAGS_SPACE)
+ OUTCHAR(' ');
+
+ if (alt && base == 16) {
+ OUTCHAR('0');
+ if(p->flags & FLAGS_UPPER)
+ OUTCHAR('X');
+ else
+ OUTCHAR('x');
+ }
+
+ if (!(p->flags & FLAGS_LEFT) && (p->flags & FLAGS_PAD_NIL))
+ while (width-- > 0)
+ OUTCHAR('0');
+
+ /* Write the number. */
+ while (++w <= workend) {
+ OUTCHAR(*w);
+ }
+
+ if (p->flags & FLAGS_LEFT)
+ while (width-- > 0)
+ OUTCHAR(' ');
+ }
+ break;
+
+ case FORMAT_STRING:
+ /* String. */
+ {
+ static const char null[] = "(nil)";
+ const char *str;
+ size_t len;
+
+ str = (char *) p->data.str;
+ if ( str == NULL) {
+ /* Write null[] if there's space. */
+ if (prec == -1 || prec >= (long) sizeof(null) - 1) {
+ str = null;
+ len = sizeof(null) - 1;
+ /* Disable quotes around (nil) */
+ p->flags &= (~FLAGS_ALT);
+ }
+ else {
+ str = "";
+ len = 0;
+ }
+ }
+ else
+ len = strlen(str);
+
+ if (prec != -1 && (size_t) prec < len)
+ len = prec;
+ width -= (long)len;
+
+ if (p->flags & FLAGS_ALT)
+ OUTCHAR('"');
+
+ if (!(p->flags&FLAGS_LEFT))
+ while (width-- > 0)
+ OUTCHAR(' ');
+
+ while (len-- > 0)
+ OUTCHAR(*str++);
+ if (p->flags&FLAGS_LEFT)
+ while (width-- > 0)
+ OUTCHAR(' ');
+
+ if (p->flags & FLAGS_ALT)
+ OUTCHAR('"');
+ }
+ break;
+
+ case FORMAT_PTR:
+ /* Generic pointer. */
+ {
+ void *ptr;
+ ptr = (void *) p->data.ptr;
+ if (ptr != NULL) {
+ /* If the pointer is not NULL, write it as a %#x spec. */
+ base = 16;
+ digits = (p->flags & FLAGS_UPPER)? upper_digits : lower_digits;
+ alt = 1;
+ num = (size_t) ptr;
+ is_neg = 0;
+ goto number;
+ }
+ else {
+ /* Write "(nil)" for a nil pointer. */
+ static const char strnil[] = "(nil)";
+ const char *point;
+
+ width -= sizeof(strnil) - 1;
+ if (p->flags & FLAGS_LEFT)
+ while (width-- > 0)
+ OUTCHAR(' ');
+ for (point = strnil; *point != '\0'; ++point)
+ OUTCHAR(*point);
+ if (! (p->flags & FLAGS_LEFT))
+ while (width-- > 0)
+ OUTCHAR(' ');
+ }
+ }
+ break;
+
+ case FORMAT_DOUBLE:
+ {
+ char formatbuf[32]="%";
+ char *fptr;
+ size_t left = sizeof(formatbuf)-strlen(formatbuf);
+ int len;
+
+ width = -1;
+ if (p->flags & FLAGS_WIDTH)
+ width = p->width;
+ else if (p->flags & FLAGS_WIDTHPARAM)
+ width = vto[p->width].data.num;
+
+ prec = -1;
+ if (p->flags & FLAGS_PREC)
+ prec = p->precision;
+ else if (p->flags & FLAGS_PRECPARAM)
+ prec = vto[p->precision].data.num;
+
+ if (p->flags & FLAGS_LEFT)
+ strcat(formatbuf, "-");
+ if (p->flags & FLAGS_SHOWSIGN)
+ strcat(formatbuf, "+");
+ if (p->flags & FLAGS_SPACE)
+ strcat(formatbuf, " ");
+ if (p->flags & FLAGS_ALT)
+ strcat(formatbuf, "#");
+
+ fptr=&formatbuf[strlen(formatbuf)];
+
+ if(width >= 0) {
+ /* RECURSIVE USAGE */
+ len = curl_msnprintf(fptr, left, "%ld", width);
+ fptr += len;
+ left -= len;
+ }
+ if(prec >= 0) {
+ /* RECURSIVE USAGE */
+ len = curl_msnprintf(fptr, left, ".%ld", prec);
+ fptr += len;
+ left -= len;
+ }
+ if (p->flags & FLAGS_LONG)
+ *fptr++ = 'l';
+
+ if (p->flags & FLAGS_FLOATE)
+ *fptr++ = p->flags&FLAGS_UPPER ? 'E':'e';
+ else if (p->flags & FLAGS_FLOATG)
+ *fptr++ = p->flags & FLAGS_UPPER ? 'G' : 'g';
+ else
+ *fptr++ = 'f';
+
+ *fptr = 0; /* and a final zero termination */
+
+ /* NOTE NOTE NOTE!! Not all sprintf() implementations returns number
+ of output characters */
+ (sprintf)(work, formatbuf, p->data.dnum);
+
+ for(fptr=work; *fptr; fptr++)
+ OUTCHAR(*fptr);
+ }
+ break;
+
+ case FORMAT_INTPTR:
+ /* Answer the count of characters written. */
+#ifdef ENABLE_64BIT
+ if (p->flags & FLAGS_LONGLONG)
+ *(LONG_LONG *) p->data.ptr = (LONG_LONG)done;
+ else
+#endif
+ if (p->flags & FLAGS_LONG)
+ *(long *) p->data.ptr = (long)done;
+ else if (!(p->flags & FLAGS_SHORT))
+ *(int *) p->data.ptr = (int)done;
+ else
+ *(short *) p->data.ptr = (short)done;
+ break;
+
+ default:
+ break;
+ }
+ f = *end++; /* goto end of %-code */
+
+ }
+ return done;
+}
+
+/* fputc() look-alike */
+static int addbyter(int output, FILE *data)
+{
+ struct nsprintf *infop=(struct nsprintf *)data;
+ unsigned char outc = (unsigned char)output;
+
+ if(infop->length < infop->max) {
+ /* only do this if we haven't reached max length yet */
+ infop->buffer[0] = outc; /* store */
+ infop->buffer++; /* increase pointer */
+ infop->length++; /* we are now one byte larger */
+ return outc; /* fputc() returns like this on success */
+ }
+ return -1;
+}
+
+int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format,
+ va_list ap_save)
+{
+ int retcode;
+ struct nsprintf info;
+
+ info.buffer = buffer;
+ info.length = 0;
+ info.max = maxlength;
+
+ retcode = dprintf_formatf(&info, addbyter, format, ap_save);
+ if(info.max) {
+ /* we terminate this with a zero byte */
+ if(info.max == info.length)
+ /* we're at maximum, scrap the last letter */
+ info.buffer[-1] = 0;
+ else
+ info.buffer[0] = 0;
+ }
+ return retcode;
+}
+
+int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...)
+{
+ int retcode;
+ va_list ap_save; /* argument pointer */
+ va_start(ap_save, format);
+ retcode = curl_mvsnprintf(buffer, maxlength, format, ap_save);
+ va_end(ap_save);
+ return retcode;
+}
+
+/* fputc() look-alike */
+static int alloc_addbyter(int output, FILE *data)
+{
+ struct asprintf *infop=(struct asprintf *)data;
+ unsigned char outc = (unsigned char)output;
+
+ if(!infop->buffer) {
+ infop->buffer=(char *)malloc(32);
+ if(!infop->buffer) {
+ infop->fail = TRUE;
+ return -1; /* fail */
+ }
+ infop->alloc = 32;
+ infop->len =0;
+ }
+ else if(infop->len+1 >= infop->alloc) {
+ char *newptr;
+
+ newptr = (char *)realloc(infop->buffer, infop->alloc*2);
+
+ if(!newptr) {
+ infop->fail = TRUE;
+ return -1;
+ }
+ infop->buffer = newptr;
+ infop->alloc *= 2;
+ }
+
+ infop->buffer[ infop->len ] = outc;
+
+ infop->len++;
+
+ return outc; /* fputc() returns like this on success */
+}
+
+char *curl_maprintf(const char *format, ...)
+{
+ va_list ap_save; /* argument pointer */
+ int retcode;
+ struct asprintf info;
+
+ info.buffer = NULL;
+ info.len = 0;
+ info.alloc = 0;
+ info.fail = FALSE;
+
+ va_start(ap_save, format);
+ retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
+ va_end(ap_save);
+ if((-1 == retcode) || info.fail) {
+ if(info.alloc)
+ free(info.buffer);
+ return NULL;
+ }
+ if(info.alloc) {
+ info.buffer[info.len] = 0; /* we terminate this with a zero byte */
+ return info.buffer;
+ }
+ else
+ return strdup("");
+}
+
+char *curl_mvaprintf(const char *format, va_list ap_save)
+{
+ int retcode;
+ struct asprintf info;
+
+ info.buffer = NULL;
+ info.len = 0;
+ info.alloc = 0;
+ info.fail = FALSE;
+
+ retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
+ if((-1 == retcode) || info.fail) {
+ if(info.alloc)
+ free(info.buffer);
+ return NULL;
+ }
+
+ if(info.alloc) {
+ info.buffer[info.len] = 0; /* we terminate this with a zero byte */
+ return info.buffer;
+ }
+ else
+ return strdup("");
+}
+
+static int storebuffer(int output, FILE *data)
+{
+ char **buffer = (char **)data;
+ unsigned char outc = (unsigned char)output;
+ **buffer = outc;
+ (*buffer)++;
+ return outc; /* act like fputc() ! */
+}
+
+int curl_msprintf(char *buffer, const char *format, ...)
+{
+ va_list ap_save; /* argument pointer */
+ int retcode;
+ va_start(ap_save, format);
+ retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save);
+ va_end(ap_save);
+ *buffer=0; /* we terminate this with a zero byte */
+ return retcode;
+}
+
+int curl_mprintf(const char *format, ...)
+{
+ int retcode;
+ va_list ap_save; /* argument pointer */
+ va_start(ap_save, format);
+
+ retcode = dprintf_formatf(stdout, fputc, format, ap_save);
+ va_end(ap_save);
+ return retcode;
+}
+
+int curl_mfprintf(FILE *whereto, const char *format, ...)
+{
+ int retcode;
+ va_list ap_save; /* argument pointer */
+ va_start(ap_save, format);
+ retcode = dprintf_formatf(whereto, fputc, format, ap_save);
+ va_end(ap_save);
+ return retcode;
+}
+
+int curl_mvsprintf(char *buffer, const char *format, va_list ap_save)
+{
+ int retcode;
+ retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save);
+ *buffer=0; /* we terminate this with a zero byte */
+ return retcode;
+}
+
+int curl_mvprintf(const char *format, va_list ap_save)
+{
+ return dprintf_formatf(stdout, fputc, format, ap_save);
+}
+
+int curl_mvfprintf(FILE *whereto, const char *format, va_list ap_save)
+{
+ return dprintf_formatf(whereto, fputc, format, ap_save);
+}
+
+#ifdef DPRINTF_DEBUG
+int main()
+{
+ char buffer[129];
+ char *ptr;
+#ifdef ENABLE_64BIT
+ long long one=99;
+ long long two=100;
+ long long test = 0x1000000000LL;
+ curl_mprintf("%lld %lld %lld\n", one, two, test);
+#endif
+
+ curl_mprintf("%3d %5d\n", 10, 1998);
+
+ ptr=curl_maprintf("test this then baby %s%s%s%s%s%s %d %d %d loser baby get a hit in yer face now!", "", "pretty long string pretty long string pretty long string pretty long string pretty long string", "/", "/", "/", "pretty long string", 1998, 1999, 2001);
+
+ puts(ptr);
+
+ memset(ptr, 55, strlen(ptr)+1);
+
+ free(ptr);
+
+#if 1
+ curl_mprintf(buffer, "%s %s %d", "daniel", "stenberg", 19988);
+ puts(buffer);
+
+ curl_mfprintf(stderr, "%s %#08x\n", "dummy", 65);
+
+ printf("%s %#08x\n", "dummy", 65);
+ {
+ double tryout = 3.14156592;
+ curl_mprintf(buffer, "%.2g %G %f %e %E", tryout, tryout, tryout, tryout, tryout);
+ puts(buffer);
+ printf("%.2g %G %f %e %E\n", tryout, tryout, tryout, tryout, tryout);
+ }
+#endif
+
+ return 0;
+}
+
+#endif
diff --git a/Utilities/cmcurl/multi.c b/Utilities/cmcurl/multi.c
new file mode 100644
index 0000000000..869d56801a
--- /dev/null
+++ b/Utilities/cmcurl/multi.c
@@ -0,0 +1,1988 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <curl/curl.h>
+
+#include "urldata.h"
+#include "transfer.h"
+#include "url.h"
+#include "connect.h"
+#include "progress.h"
+#include "memory.h"
+#include "easyif.h"
+#include "multiif.h"
+#include "sendf.h"
+#include "timeval.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+struct Curl_message {
+ /* the 'CURLMsg' is the part that is visible to the external user */
+ struct CURLMsg extmsg;
+ struct Curl_message *next;
+};
+
+typedef enum {
+ CURLM_STATE_INIT, /* start in this state */
+ CURLM_STATE_CONNECT, /* resolve/connect has been sent off */
+ CURLM_STATE_WAITRESOLVE, /* awaiting the resolve to finalize */
+ CURLM_STATE_WAITCONNECT, /* awaiting the connect to finalize */
+ CURLM_STATE_PROTOCONNECT, /* completing the protocol-specific connect
+ phase */
+ CURLM_STATE_WAITDO, /* wait for our turn to send the request */
+ CURLM_STATE_DO, /* start send off the request (part 1) */
+ CURLM_STATE_DOING, /* sending off the request (part 1) */
+ CURLM_STATE_DO_MORE, /* send off the request (part 2) */
+ CURLM_STATE_DO_DONE, /* done sending off request */
+ CURLM_STATE_WAITPERFORM, /* wait for our turn to read the response */
+ CURLM_STATE_PERFORM, /* transfer data */
+ CURLM_STATE_TOOFAST, /* wait because limit-rate exceeded */
+ CURLM_STATE_DONE, /* post data transfer operation */
+ CURLM_STATE_COMPLETED, /* operation complete */
+ CURLM_STATE_CANCELLED, /* cancelled */
+
+ CURLM_STATE_LAST /* not a true state, never use this */
+} CURLMstate;
+
+/* we support N sockets per easy handle. Set the corresponding bit to what
+ action we should wait for */
+#define MAX_SOCKSPEREASYHANDLE 5
+#define GETSOCK_READABLE (0x00ff)
+#define GETSOCK_WRITABLE (0xff00)
+
+struct closure {
+ struct closure *next; /* a simple one-way list of structs */
+ struct SessionHandle *easy_handle;
+};
+
+struct Curl_one_easy {
+ /* first, two fields for the linked list of these */
+ struct Curl_one_easy *next;
+ struct Curl_one_easy *prev;
+
+ struct SessionHandle *easy_handle; /* the easy handle for this unit */
+ struct connectdata *easy_conn; /* the "unit's" connection */
+
+ CURLMstate state; /* the handle's state */
+ CURLcode result; /* previous result */
+
+ struct Curl_message *msg; /* A pointer to one single posted message.
+ Cleanup should be done on this pointer NOT on
+ the linked list in Curl_multi. This message
+ will be deleted when this handle is removed
+ from the multi-handle */
+ int msg_num; /* number of messages left in 'msg' to return */
+
+ /* Array with the plain socket numbers this handle takes care of, in no
+ particular order. Note that all sockets are added to the sockhash, where
+ the state etc are also kept. This array is mostly used to detect when a
+ socket is to be removed from the hash. See singlesocket(). */
+ curl_socket_t sockets[MAX_SOCKSPEREASYHANDLE];
+ int numsocks;
+};
+
+#define CURL_MULTI_HANDLE 0x000bab1e
+
+#define GOOD_MULTI_HANDLE(x) \
+ ((x)&&(((struct Curl_multi *)x)->type == CURL_MULTI_HANDLE))
+#define GOOD_EASY_HANDLE(x) \
+ (((struct SessionHandle *)x)->magic == CURLEASY_MAGIC_NUMBER)
+
+/* This is the struct known as CURLM on the outside */
+struct Curl_multi {
+ /* First a simple identifier to easier detect if a user mix up
+ this multi handle with an easy handle. Set this to CURL_MULTI_HANDLE. */
+ long type;
+
+ /* We have a linked list with easy handles */
+ struct Curl_one_easy easy;
+
+ int num_easy; /* amount of entries in the linked list above. */
+ int num_msgs; /* amount of messages in the easy handles */
+ int num_alive; /* amount of easy handles that are added but have not yet
+ reached COMPLETE state */
+
+ /* callback function and user data pointer for the *socket() API */
+ curl_socket_callback socket_cb;
+ void *socket_userp;
+
+ /* Hostname cache */
+ struct curl_hash *hostcache;
+
+ /* timetree points to the splay-tree of time nodes to figure out expire
+ times of all currently set timers */
+ struct Curl_tree *timetree;
+
+ /* 'sockhash' is the lookup hash for socket descriptor => easy handles (note
+ the pluralis form, there can be more than one easy handle waiting on the
+ same actual socket) */
+ struct curl_hash *sockhash;
+
+ /* Whether pipelining is enabled for this multi handle */
+ bool pipelining_enabled;
+
+ /* shared connection cache */
+ struct conncache *connc;
+
+ /* list of easy handles kept around for doing nice connection closures */
+ struct closure *closure;
+
+ /* timer callback and user data pointer for the *socket() API */
+ curl_multi_timer_callback timer_cb;
+ void *timer_userp;
+ time_t timer_lastcall; /* the fixed time for the timeout for the previous
+ callback */
+};
+
+static bool multi_conn_using(struct Curl_multi *multi,
+ struct SessionHandle *data);
+static void singlesocket(struct Curl_multi *multi,
+ struct Curl_one_easy *easy);
+static void add_closure(struct Curl_multi *multi,
+ struct SessionHandle *data);
+static int update_timer(struct Curl_multi *multi);
+
+#ifdef CURLDEBUG
+static const char *statename[]={
+ "INIT",
+ "CONNECT",
+ "WAITRESOLVE",
+ "WAITCONNECT",
+ "PROTOCONNECT",
+ "WAITDO",
+ "DO",
+ "DOING",
+ "DO_MORE",
+ "DO_DONE",
+ "WAITPERFORM",
+ "PERFORM",
+ "TOOFAST",
+ "DONE",
+ "COMPLETED",
+ "CANCELLED"
+};
+
+void curl_multi_dump(CURLM *multi_handle);
+#endif
+
+/* always use this function to change state, to make debugging easier */
+static void multistate(struct Curl_one_easy *easy, CURLMstate state)
+{
+#ifdef CURLDEBUG
+ long index = -1;
+#endif
+ CURLMstate oldstate = easy->state;
+
+ if(oldstate == state)
+ /* don't bother when the new state is the same as the old state */
+ return;
+
+ easy->state = state;
+
+#ifdef CURLDEBUG
+ if(easy->state > CURLM_STATE_CONNECT &&
+ easy->state < CURLM_STATE_COMPLETED)
+ index = easy->easy_conn->connectindex;
+
+ infof(easy->easy_handle,
+ "STATE: %s => %s handle %p; (connection #%ld) \n",
+ statename[oldstate], statename[easy->state],
+ (char *)easy, index);
+#endif
+ if(state == CURLM_STATE_COMPLETED)
+ /* changing to COMPLETED means there's one less easy handle 'alive' */
+ easy->easy_handle->multi->num_alive--;
+}
+
+/*
+ * We add one of these structs to the sockhash for a particular socket
+ */
+
+struct Curl_sh_entry {
+ struct SessionHandle *easy;
+ time_t timestamp;
+ long inuse;
+ int action; /* what action READ/WRITE this socket waits for */
+ curl_socket_t socket; /* mainly to ease debugging */
+ void *socketp; /* settable by users with curl_multi_assign() */
+};
+/* bits for 'action' having no bits means this socket is not expecting any
+ action */
+#define SH_READ 1
+#define SH_WRITE 2
+
+/* make sure this socket is present in the hash for this handle */
+static struct Curl_sh_entry *sh_addentry(struct curl_hash *sh,
+ curl_socket_t s,
+ struct SessionHandle *data)
+{
+ struct Curl_sh_entry *there =
+ Curl_hash_pick(sh, (char *)&s, sizeof(curl_socket_t));
+ struct Curl_sh_entry *check;
+
+ if(there)
+ /* it is present, return fine */
+ return there;
+
+ /* not present, add it */
+ check = calloc(sizeof(struct Curl_sh_entry), 1);
+ if(!check)
+ return NULL; /* major failure */
+ check->easy = data;
+ check->socket = s;
+
+ /* make/add new hash entry */
+ if(NULL == Curl_hash_add(sh, (char *)&s, sizeof(curl_socket_t), check)) {
+ free(check);
+ return NULL; /* major failure */
+ }
+
+ return check; /* things are good in sockhash land */
+}
+
+
+/* delete the given socket + handle from the hash */
+static void sh_delentry(struct curl_hash *sh, curl_socket_t s)
+{
+ struct Curl_sh_entry *there =
+ Curl_hash_pick(sh, (char *)&s, sizeof(curl_socket_t));
+
+ if(there) {
+ /* this socket is in the hash */
+ /* We remove the hash entry. (This'll end up in a call to
+ sh_freeentry().) */
+ Curl_hash_delete(sh, (char *)&s, sizeof(curl_socket_t));
+ }
+}
+
+/*
+ * free a sockhash entry
+ */
+static void sh_freeentry(void *freethis)
+{
+ struct Curl_sh_entry *p = (struct Curl_sh_entry *) freethis;
+
+ free(p);
+}
+
+/*
+ * sh_init() creates a new socket hash and returns the handle for it.
+ *
+ * Quote from README.multi_socket:
+ *
+ * "Some tests at 7000 and 9000 connections showed that the socket hash lookup
+ * is somewhat of a bottle neck. Its current implementation may be a bit too
+ * limiting. It simply has a fixed-size array, and on each entry in the array
+ * it has a linked list with entries. So the hash only checks which list to
+ * scan through. The code I had used so for used a list with merely 7 slots
+ * (as that is what the DNS hash uses) but with 7000 connections that would
+ * make an average of 1000 nodes in each list to run through. I upped that to
+ * 97 slots (I believe a prime is suitable) and noticed a significant speed
+ * increase. I need to reconsider the hash implementation or use a rather
+ * large default value like this. At 9000 connections I was still below 10us
+ * per call."
+ *
+ */
+static struct curl_hash *sh_init(void)
+{
+ return Curl_hash_alloc(97, sh_freeentry);
+}
+
+CURLM *curl_multi_init(void)
+{
+ struct Curl_multi *multi = (void *)calloc(sizeof(struct Curl_multi), 1);
+
+ if(!multi)
+ return NULL;
+
+ multi->type = CURL_MULTI_HANDLE;
+
+ multi->hostcache = Curl_mk_dnscache();
+ if(!multi->hostcache) {
+ /* failure, free mem and bail out */
+ free(multi);
+ return NULL;
+ }
+
+ multi->sockhash = sh_init();
+ if(!multi->sockhash) {
+ /* failure, free mem and bail out */
+ Curl_hash_destroy(multi->hostcache);
+ free(multi);
+ return NULL;
+ }
+
+ multi->connc = Curl_mk_connc(CONNCACHE_MULTI, -1);
+ if(!multi->connc) {
+ Curl_hash_destroy(multi->hostcache);
+ free(multi);
+ return NULL;
+ }
+
+ return (CURLM *) multi;
+}
+
+CURLMcode curl_multi_add_handle(CURLM *multi_handle,
+ CURL *easy_handle)
+{
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+ struct Curl_one_easy *easy;
+ struct closure *cl;
+ struct closure *prev=NULL;
+
+ /* First, make some basic checks that the CURLM handle is a good handle */
+ if(!GOOD_MULTI_HANDLE(multi))
+ return CURLM_BAD_HANDLE;
+
+ /* Verify that we got a somewhat good easy handle too */
+ if(!GOOD_EASY_HANDLE(easy_handle))
+ return CURLM_BAD_EASY_HANDLE;
+
+ /* Prevent users to add the same handle more than once! */
+ if(((struct SessionHandle *)easy_handle)->multi)
+ /* possibly we should create a new unique error code for this condition */
+ return CURLM_BAD_EASY_HANDLE;
+
+ /* Now, time to add an easy handle to the multi stack */
+ easy = (struct Curl_one_easy *)calloc(sizeof(struct Curl_one_easy), 1);
+ if(!easy)
+ return CURLM_OUT_OF_MEMORY;
+
+ cl = multi->closure;
+ while(cl) {
+ struct closure *next = cl->next;
+ if(cl->easy_handle == (struct SessionHandle *)easy_handle) {
+ /* remove this handle from the closure list */
+ free(cl);
+ if(prev)
+ prev->next = next;
+ else
+ multi->closure = next;
+ break; /* no need to continue since this handle can only be present once
+ in the list */
+ }
+ cl = next;
+ }
+
+ /* set the easy handle */
+ easy->easy_handle = easy_handle;
+ multistate(easy, CURLM_STATE_INIT);
+
+ /* for multi interface connections, we share DNS cache automatically if the
+ easy handle's one is currently private. */
+ if (easy->easy_handle->dns.hostcache &&
+ (easy->easy_handle->dns.hostcachetype == HCACHE_PRIVATE)) {
+ Curl_hash_destroy(easy->easy_handle->dns.hostcache);
+ easy->easy_handle->dns.hostcache = NULL;
+ easy->easy_handle->dns.hostcachetype = HCACHE_NONE;
+ }
+
+ if (!easy->easy_handle->dns.hostcache ||
+ (easy->easy_handle->dns.hostcachetype == HCACHE_NONE)) {
+ easy->easy_handle->dns.hostcache = multi->hostcache;
+ easy->easy_handle->dns.hostcachetype = HCACHE_MULTI;
+ }
+
+ if(easy->easy_handle->state.connc) {
+ if(easy->easy_handle->state.connc->type == CONNCACHE_PRIVATE) {
+ /* kill old private version */
+ Curl_rm_connc(easy->easy_handle->state.connc);
+ /* point out our shared one instead */
+ easy->easy_handle->state.connc = multi->connc;
+ }
+ /* else it is already using multi? */
+ }
+ else
+ /* point out our shared one */
+ easy->easy_handle->state.connc = multi->connc;
+
+ /* Make sure the type is setup correctly */
+ easy->easy_handle->state.connc->type = CONNCACHE_MULTI;
+
+ /* We add this new entry first in the list. We make our 'next' point to the
+ previous next and our 'prev' point back to the 'first' struct */
+ easy->next = multi->easy.next;
+ easy->prev = &multi->easy;
+
+ /* make 'easy' the first node in the chain */
+ multi->easy.next = easy;
+
+ /* if there was a next node, make sure its 'prev' pointer links back to
+ the new node */
+ if(easy->next)
+ easy->next->prev = easy;
+
+ Curl_easy_addmulti(easy_handle, multi_handle);
+
+ /* make the SessionHandle struct refer back to this struct */
+ easy->easy_handle->set.one_easy = easy;
+
+ /* increase the node-counter */
+ multi->num_easy++;
+
+ if((multi->num_easy * 4) > multi->connc->num) {
+ /* We want the connection cache to have plenty room. Before we supported
+ the shared cache every single easy handle had 5 entries in their cache
+ by default. */
+ CURLcode res = Curl_ch_connc(easy_handle, multi->connc,
+ multi->connc->num*4);
+ if(res != CURLE_OK)
+ /* TODO: we need to do some cleaning up here! */
+ return CURLM_OUT_OF_MEMORY;
+ }
+
+ /* increase the alive-counter */
+ multi->num_alive++;
+
+ update_timer(multi);
+ return CURLM_OK;
+}
+
+#if 0
+/* Debug-function, used like this:
+ *
+ * Curl_hash_print(multi->sockhash, debug_print_sock_hash);
+ *
+ * Enable the hash print function first by editing hash.c
+ */
+static void debug_print_sock_hash(void *p)
+{
+ struct Curl_sh_entry *sh = (struct Curl_sh_entry *)p;
+
+ fprintf(stderr, " [easy %p/magic %x/socket %d]",
+ (void *)sh->easy, sh->easy->magic, sh->socket);
+}
+#endif
+
+CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
+ CURL *curl_handle)
+{
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+ struct Curl_one_easy *easy;
+
+ /* First, make some basic checks that the CURLM handle is a good handle */
+ if(!GOOD_MULTI_HANDLE(multi))
+ return CURLM_BAD_HANDLE;
+
+ /* Verify that we got a somewhat good easy handle too */
+ if(!GOOD_EASY_HANDLE(curl_handle))
+ return CURLM_BAD_EASY_HANDLE;
+
+ /* scan through the list and remove the 'curl_handle' */
+ easy = multi->easy.next;
+ while(easy) {
+ if(easy->easy_handle == (struct SessionHandle *)curl_handle)
+ break;
+ easy=easy->next;
+ }
+
+ if(easy) {
+ bool premature = (bool)(easy->state != CURLM_STATE_COMPLETED);
+
+ /* If the 'state' is not INIT or COMPLETED, we might need to do something
+ nice to put the easy_handle in a good known state when this returns. */
+ if(premature)
+ /* this handle is "alive" so we need to count down the total number of
+ alive connections when this is removed */
+ multi->num_alive--;
+
+ if (easy->easy_handle->state.is_in_pipeline &&
+ easy->state > CURLM_STATE_DO) {
+ /* If the handle is in a pipeline and has finished sending off its
+ request, we need to remember the fact that we want to remove this
+ handle but do the actual removal at a later time */
+ easy->easy_handle->state.cancelled = TRUE;
+ return CURLM_OK;
+ }
+
+ /* The timer must be shut down before easy->multi is set to NULL,
+ else the timenode will remain in the splay tree after
+ curl_easy_cleanup is called. */
+ Curl_expire(easy->easy_handle, 0);
+
+ if(easy->easy_handle->dns.hostcachetype == HCACHE_MULTI) {
+ /* clear out the usage of the shared DNS cache */
+ easy->easy_handle->dns.hostcache = NULL;
+ easy->easy_handle->dns.hostcachetype = HCACHE_NONE;
+ }
+
+ /* if we have a connection we must call Curl_done() here so that we
+ don't leave a half-baked one around */
+ if(easy->easy_conn) {
+ /* Set up the association right */
+ easy->easy_conn->data = easy->easy_handle;
+
+ /* Curl_done() clears the conn->data field to lose the association
+ between the easy handle and the connection */
+ Curl_done(&easy->easy_conn, easy->result, premature);
+
+ if(easy->easy_conn)
+ /* the connection is still alive, set back the association to enable
+ the check below to trigger TRUE */
+ easy->easy_conn->data = easy->easy_handle;
+ }
+
+ /* If this easy_handle was the last one in charge for one or more
+ connections a the shared connection cache, we might need to keep this
+ handle around until either A) the connection is closed and killed
+ properly, or B) another easy_handle uses the connection.
+
+ The reason why we need to have a easy_handle associated with a live
+ connection is simply that some connections will need a handle to get
+ closed down properly. Currently, the only connections that need to keep
+ a easy_handle handle around are using FTP(S). Such connections have
+ the PROT_CLOSEACTION bit set.
+
+ Thus, we need to check for all connections in the shared cache that
+ points to this handle and are using PROT_CLOSEACTION. If there's any,
+ we need to add this handle to the list of "easy handles kept around for
+ nice connection closures".
+ */
+ if(multi_conn_using(multi, easy->easy_handle)) {
+ /* There's at least one connection using this handle so we must keep
+ this handle around. We also keep the connection cache pointer
+ pointing to the shared one since that will be used on close as
+ well. */
+ easy->easy_handle->state.shared_conn = multi;
+
+ /* this handle is still being used by a shared connection cache and
+ thus we leave it around for now */
+ add_closure(multi, easy->easy_handle);
+ }
+
+ if(easy->easy_handle->state.connc->type == CONNCACHE_MULTI) {
+ /* if this was using the shared connection cache we clear the pointer
+ to that since we're not part of that handle anymore */
+ easy->easy_handle->state.connc = NULL;
+
+ /* and modify the connectindex since this handle can't point to the
+ connection cache anymore */
+ if(easy->easy_conn)
+ easy->easy_conn->connectindex = -1;
+ }
+
+ /* change state without using multistate(), only to make singlesocket() do
+ what we want */
+ easy->state = CURLM_STATE_COMPLETED;
+ singlesocket(multi, easy); /* to let the application know what sockets
+ that vanish with this handle */
+
+ Curl_easy_addmulti(easy->easy_handle, NULL); /* clear the association
+ to this multi handle */
+
+ /* make the previous node point to our next */
+ if(easy->prev)
+ easy->prev->next = easy->next;
+ /* make our next point to our previous node */
+ if(easy->next)
+ easy->next->prev = easy->prev;
+
+ easy->easy_handle->set.one_easy = NULL; /* detached */
+
+ /* NOTE NOTE NOTE
+ We do not touch the easy handle here! */
+ if (easy->msg)
+ free(easy->msg);
+ free(easy);
+
+ multi->num_easy--; /* one less to care about now */
+
+ update_timer(multi);
+ return CURLM_OK;
+ }
+ else
+ return CURLM_BAD_EASY_HANDLE; /* twasn't found */
+}
+
+bool Curl_multi_canPipeline(struct Curl_multi* multi)
+{
+ return multi->pipelining_enabled;
+}
+
+static int waitconnect_getsock(struct connectdata *conn,
+ curl_socket_t *sock,
+ int numsocks)
+{
+ if(!numsocks)
+ return GETSOCK_BLANK;
+
+ sock[0] = conn->sock[FIRSTSOCKET];
+ return GETSOCK_WRITESOCK(0);
+}
+
+static int domore_getsock(struct connectdata *conn,
+ curl_socket_t *sock,
+ int numsocks)
+{
+ if(!numsocks)
+ return GETSOCK_BLANK;
+
+ /* When in DO_MORE state, we could be either waiting for us
+ to connect to a remote site, or we could wait for that site
+ to connect to us. It makes a difference in the way: if we
+ connect to the site we wait for the socket to become writable, if
+ the site connects to us we wait for it to become readable */
+ sock[0] = conn->sock[SECONDARYSOCKET];
+
+ return GETSOCK_WRITESOCK(0);
+}
+
+/* returns bitmapped flags for this handle and its sockets */
+static int multi_getsock(struct Curl_one_easy *easy,
+ curl_socket_t *socks, /* points to numsocks number
+ of sockets */
+ int numsocks)
+{
+ if (easy->easy_handle->state.pipe_broke) {
+ return 0;
+ }
+
+ if (easy->state > CURLM_STATE_CONNECT &&
+ easy->state < CURLM_STATE_COMPLETED) {
+ /* Set up ownership correctly */
+ easy->easy_conn->data = easy->easy_handle;
+ }
+
+ switch(easy->state) {
+ case CURLM_STATE_TOOFAST: /* returns 0, so will not select. */
+ default:
+ /* this will get called with CURLM_STATE_COMPLETED when a handle is
+ removed */
+ return 0;
+
+ case CURLM_STATE_WAITRESOLVE:
+ return Curl_resolv_getsock(easy->easy_conn, socks, numsocks);
+
+ case CURLM_STATE_PROTOCONNECT:
+ return Curl_protocol_getsock(easy->easy_conn, socks, numsocks);
+
+ case CURLM_STATE_DOING:
+ return Curl_doing_getsock(easy->easy_conn, socks, numsocks);
+
+ case CURLM_STATE_WAITCONNECT:
+ return waitconnect_getsock(easy->easy_conn, socks, numsocks);
+
+ case CURLM_STATE_DO_MORE:
+ return domore_getsock(easy->easy_conn, socks, numsocks);
+
+ case CURLM_STATE_PERFORM:
+ case CURLM_STATE_WAITPERFORM:
+ return Curl_single_getsock(easy->easy_conn, socks, numsocks);
+ }
+
+}
+
+CURLMcode curl_multi_fdset(CURLM *multi_handle,
+ fd_set *read_fd_set, fd_set *write_fd_set,
+ fd_set *exc_fd_set, int *max_fd)
+{
+ /* Scan through all the easy handles to get the file descriptors set.
+ Some easy handles may not have connected to the remote host yet,
+ and then we must make sure that is done. */
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+ struct Curl_one_easy *easy;
+ int this_max_fd=-1;
+ curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
+ int bitmap;
+ int i;
+ (void)exc_fd_set; /* not used */
+
+ if(!GOOD_MULTI_HANDLE(multi))
+ return CURLM_BAD_HANDLE;
+
+ easy=multi->easy.next;
+ while(easy) {
+ bitmap = multi_getsock(easy, sockbunch, MAX_SOCKSPEREASYHANDLE);
+
+ for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
+ curl_socket_t s = CURL_SOCKET_BAD;
+
+ if(bitmap & GETSOCK_READSOCK(i)) {
+ FD_SET(sockbunch[i], read_fd_set);
+ s = sockbunch[i];
+ }
+ if(bitmap & GETSOCK_WRITESOCK(i)) {
+ FD_SET(sockbunch[i], write_fd_set);
+ s = sockbunch[i];
+ }
+ if(s == CURL_SOCKET_BAD)
+ /* this socket is unused, break out of loop */
+ break;
+ else {
+ if((int)s > this_max_fd)
+ this_max_fd = (int)s;
+ }
+ }
+
+ easy = easy->next; /* check next handle */
+ }
+
+ *max_fd = this_max_fd;
+
+ return CURLM_OK;
+}
+
+static CURLMcode multi_runsingle(struct Curl_multi *multi,
+ struct Curl_one_easy *easy)
+{
+ struct Curl_message *msg = NULL;
+ bool connected;
+ bool async;
+ bool protocol_connect = 0;
+ bool dophase_done;
+ bool done;
+ CURLMcode result = CURLM_OK;
+ struct Curl_transfer_keeper *k;
+
+ do {
+
+ if(!GOOD_EASY_HANDLE(easy->easy_handle))
+ return CURLM_BAD_EASY_HANDLE;
+
+ if (easy->easy_handle->state.pipe_broke) {
+ infof(easy->easy_handle, "Pipe broke: handle 0x%x, url = %s\n",
+ easy, easy->easy_handle->reqdata.path);
+ if(easy->easy_handle->state.is_in_pipeline) {
+ /* Head back to the CONNECT state */
+ multistate(easy, CURLM_STATE_CONNECT);
+ result = CURLM_CALL_MULTI_PERFORM;
+ easy->result = CURLE_OK;
+ } else {
+ easy->result = CURLE_COULDNT_CONNECT;
+ multistate(easy, CURLM_STATE_COMPLETED);
+ }
+
+ easy->easy_handle->state.pipe_broke = FALSE;
+ easy->easy_conn = NULL;
+ break;
+ }
+
+ if (easy->state > CURLM_STATE_CONNECT &&
+ easy->state < CURLM_STATE_COMPLETED) {
+ /* Make sure we set the connection's current owner */
+ easy->easy_conn->data = easy->easy_handle;
+ }
+
+ if (CURLM_STATE_WAITCONNECT <= easy->state &&
+ easy->state <= CURLM_STATE_DO &&
+ easy->easy_handle->change.url_changed) {
+ char *gotourl;
+ Curl_posttransfer(easy->easy_handle);
+
+ easy->result = Curl_done(&easy->easy_conn, CURLE_OK, FALSE);
+ /* We make sure that the pipe broken flag is reset
+ because in this case, it isn't an actual break */
+ easy->easy_handle->state.pipe_broke = FALSE;
+ if(CURLE_OK == easy->result) {
+ gotourl = strdup(easy->easy_handle->change.url);
+ if(gotourl) {
+ easy->easy_handle->change.url_changed = FALSE;
+ easy->result = Curl_follow(easy->easy_handle, gotourl, FALSE);
+ if(CURLE_OK == easy->result)
+ multistate(easy, CURLM_STATE_CONNECT);
+ else
+ free(gotourl);
+ }
+ else {
+ easy->result = CURLE_OUT_OF_MEMORY;
+ multistate(easy, CURLM_STATE_COMPLETED);
+ break;
+ }
+ }
+ }
+
+ easy->easy_handle->change.url_changed = FALSE;
+
+ switch(easy->state) {
+ case CURLM_STATE_INIT:
+ /* init this transfer. */
+ easy->result=Curl_pretransfer(easy->easy_handle);
+
+ if(CURLE_OK == easy->result) {
+ /* after init, go CONNECT */
+ multistate(easy, CURLM_STATE_CONNECT);
+ result = CURLM_CALL_MULTI_PERFORM;
+
+ easy->easy_handle->state.used_interface = Curl_if_multi;
+ }
+ break;
+
+ case CURLM_STATE_CONNECT:
+ /* Connect. We get a connection identifier filled in. */
+ Curl_pgrsTime(easy->easy_handle, TIMER_STARTSINGLE);
+ easy->result = Curl_connect(easy->easy_handle, &easy->easy_conn,
+ &async, &protocol_connect);
+
+ if(CURLE_OK == easy->result) {
+ /* Add this handle to the send pipeline */
+ Curl_addHandleToPipeline(easy->easy_handle,
+ easy->easy_conn->send_pipe);
+
+ if(async)
+ /* We're now waiting for an asynchronous name lookup */
+ multistate(easy, CURLM_STATE_WAITRESOLVE);
+ else {
+ /* after the connect has been sent off, go WAITCONNECT unless the
+ protocol connect is already done and we can go directly to
+ WAITDO! */
+ result = CURLM_CALL_MULTI_PERFORM;
+
+ if(protocol_connect) {
+ multistate(easy, CURLM_STATE_WAITDO);
+ } else {
+ multistate(easy, CURLM_STATE_WAITCONNECT);
+ }
+ }
+ }
+ break;
+
+ case CURLM_STATE_WAITRESOLVE:
+ /* awaiting an asynch name resolve to complete */
+ {
+ struct Curl_dns_entry *dns = NULL;
+
+ /* check if we have the name resolved by now */
+ easy->result = Curl_is_resolved(easy->easy_conn, &dns);
+
+ if(dns) {
+ /* Perform the next step in the connection phase, and then move on
+ to the WAITCONNECT state */
+ easy->result = Curl_async_resolved(easy->easy_conn,
+ &protocol_connect);
+
+ if(CURLE_OK != easy->result)
+ /* if Curl_async_resolved() returns failure, the connection struct
+ is already freed and gone */
+ easy->easy_conn = NULL; /* no more connection */
+ else {
+ /* call again please so that we get the next socket setup */
+ result = CURLM_CALL_MULTI_PERFORM;
+ if(protocol_connect)
+ multistate(easy, CURLM_STATE_DO);
+ else
+ multistate(easy, CURLM_STATE_WAITCONNECT);
+ }
+ }
+
+ if(CURLE_OK != easy->result) {
+ /* failure detected */
+ Curl_disconnect(easy->easy_conn); /* disconnect properly */
+ easy->easy_conn = NULL; /* no more connection */
+ break;
+ }
+ }
+ break;
+
+ case CURLM_STATE_WAITCONNECT:
+ /* awaiting a completion of an asynch connect */
+ easy->result = Curl_is_connected(easy->easy_conn,
+ FIRSTSOCKET,
+ &connected);
+ if(connected)
+ easy->result = Curl_protocol_connect(easy->easy_conn,
+ &protocol_connect);
+
+ if(CURLE_OK != easy->result) {
+ /* failure detected */
+ Curl_disconnect(easy->easy_conn); /* close the connection */
+ easy->easy_conn = NULL; /* no more connection */
+ break;
+ }
+
+ if(connected) {
+ if(!protocol_connect) {
+ /* We have a TCP connection, but 'protocol_connect' may be false
+ and then we continue to 'STATE_PROTOCONNECT'. If protocol
+ connect is TRUE, we move on to STATE_DO. */
+ multistate(easy, CURLM_STATE_PROTOCONNECT);
+ }
+ else {
+ /* after the connect has completed, go WAITDO */
+ multistate(easy, CURLM_STATE_WAITDO);
+
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+ }
+ break;
+
+ case CURLM_STATE_PROTOCONNECT:
+ /* protocol-specific connect phase */
+ easy->result = Curl_protocol_connecting(easy->easy_conn,
+ &protocol_connect);
+ if(protocol_connect) {
+ /* after the connect has completed, go WAITDO */
+ multistate(easy, CURLM_STATE_WAITDO);
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+ else if(easy->result) {
+ /* failure detected */
+ Curl_posttransfer(easy->easy_handle);
+ Curl_done(&easy->easy_conn, easy->result, FALSE);
+ Curl_disconnect(easy->easy_conn); /* close the connection */
+ easy->easy_conn = NULL; /* no more connection */
+ }
+ break;
+
+ case CURLM_STATE_WAITDO:
+ /* Wait for our turn to DO when we're pipelining requests */
+#ifdef CURLDEBUG
+ infof(easy->easy_handle, "Conn %d send pipe %d inuse %d athead %d\n",
+ easy->easy_conn->connectindex,
+ easy->easy_conn->send_pipe->size,
+ easy->easy_conn->writechannel_inuse,
+ Curl_isHandleAtHead(easy->easy_handle,
+ easy->easy_conn->send_pipe));
+#endif
+ if (!easy->easy_conn->writechannel_inuse &&
+ Curl_isHandleAtHead(easy->easy_handle,
+ easy->easy_conn->send_pipe)) {
+ /* Grab the channel */
+ easy->easy_conn->writechannel_inuse = TRUE;
+ multistate(easy, CURLM_STATE_DO);
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+ break;
+
+ case CURLM_STATE_DO:
+ if(easy->easy_handle->set.connect_only) {
+ /* keep connection open for application to use the socket */
+ easy->easy_conn->bits.close = FALSE;
+ multistate(easy, CURLM_STATE_DONE);
+ easy->result = CURLE_OK;
+ result = CURLM_OK;
+ }
+ else {
+ /* Perform the protocol's DO action */
+ easy->result = Curl_do(&easy->easy_conn,
+ &dophase_done);
+
+ if(CURLE_OK == easy->result) {
+
+ if(!dophase_done) {
+ /* DO was not completed in one function call, we must continue
+ DOING... */
+ multistate(easy, CURLM_STATE_DOING);
+ result = CURLM_OK;
+ }
+
+ /* after DO, go DO_DONE... or DO_MORE */
+ else if(easy->easy_conn->bits.do_more) {
+ /* we're supposed to do more, but we need to sit down, relax
+ and wait a little while first */
+ multistate(easy, CURLM_STATE_DO_MORE);
+ result = CURLM_OK;
+ }
+ else {
+ /* we're done with the DO, now DO_DONE */
+ easy->result = Curl_readwrite_init(easy->easy_conn);
+ if(CURLE_OK == easy->result) {
+ multistate(easy, CURLM_STATE_DO_DONE);
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+ }
+ }
+ else {
+ /* failure detected */
+ Curl_posttransfer(easy->easy_handle);
+ Curl_done(&easy->easy_conn, easy->result, FALSE);
+ Curl_disconnect(easy->easy_conn); /* close the connection */
+ easy->easy_conn = NULL; /* no more connection */
+ }
+ }
+ break;
+
+ case CURLM_STATE_DOING:
+ /* we continue DOING until the DO phase is complete */
+ easy->result = Curl_protocol_doing(easy->easy_conn,
+ &dophase_done);
+ if(CURLE_OK == easy->result) {
+ if(dophase_done) {
+ /* after DO, go PERFORM... or DO_MORE */
+ if(easy->easy_conn->bits.do_more) {
+ /* we're supposed to do more, but we need to sit down, relax
+ and wait a little while first */
+ multistate(easy, CURLM_STATE_DO_MORE);
+ result = CURLM_OK;
+ }
+ else {
+ /* we're done with the DO, now DO_DONE */
+ easy->result = Curl_readwrite_init(easy->easy_conn);
+ if(CURLE_OK == easy->result) {
+ multistate(easy, CURLM_STATE_DO_DONE);
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+ }
+ } /* dophase_done */
+ }
+ else {
+ /* failure detected */
+ Curl_posttransfer(easy->easy_handle);
+ Curl_done(&easy->easy_conn, easy->result, FALSE);
+ Curl_disconnect(easy->easy_conn); /* close the connection */
+ easy->easy_conn = NULL; /* no more connection */
+ }
+ break;
+
+ case CURLM_STATE_DO_MORE:
+ /* Ready to do more? */
+ easy->result = Curl_is_connected(easy->easy_conn,
+ SECONDARYSOCKET,
+ &connected);
+ if(connected) {
+ /*
+ * When we are connected, DO MORE and then go DO_DONE
+ */
+ easy->result = Curl_do_more(easy->easy_conn);
+
+ if(CURLE_OK == easy->result)
+ easy->result = Curl_readwrite_init(easy->easy_conn);
+ else
+ /* Remove ourselves from the send pipeline */
+ Curl_removeHandleFromPipeline(easy->easy_handle,
+ easy->easy_conn->send_pipe);
+
+ if(CURLE_OK == easy->result) {
+ multistate(easy, CURLM_STATE_DO_DONE);
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+ }
+ break;
+
+ case CURLM_STATE_DO_DONE:
+ /* Remove ourselves from the send pipeline */
+ Curl_removeHandleFromPipeline(easy->easy_handle,
+ easy->easy_conn->send_pipe);
+ /* Add ourselves to the recv pipeline */
+ Curl_addHandleToPipeline(easy->easy_handle,
+ easy->easy_conn->recv_pipe);
+ multistate(easy, CURLM_STATE_WAITPERFORM);
+ result = CURLM_CALL_MULTI_PERFORM;
+ break;
+
+ case CURLM_STATE_WAITPERFORM:
+#ifdef CURLDEBUG
+ infof(easy->easy_handle, "Conn %d recv pipe %d inuse %d athead %d\n",
+ easy->easy_conn->connectindex,
+ easy->easy_conn->recv_pipe->size,
+ easy->easy_conn->readchannel_inuse,
+ Curl_isHandleAtHead(easy->easy_handle,
+ easy->easy_conn->recv_pipe));
+#endif
+ /* Wait for our turn to PERFORM */
+ if (!easy->easy_conn->readchannel_inuse &&
+ Curl_isHandleAtHead(easy->easy_handle,
+ easy->easy_conn->recv_pipe)) {
+ /* Grab the channel */
+ easy->easy_conn->readchannel_inuse = TRUE;
+ multistate(easy, CURLM_STATE_PERFORM);
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+ break;
+
+ case CURLM_STATE_TOOFAST: /* limit-rate exceeded in either direction */
+ /* if both rates are within spec, resume transfer */
+ Curl_pgrsUpdate(easy->easy_conn);
+ if ( ( ( easy->easy_handle->set.max_send_speed == 0 ) ||
+ ( easy->easy_handle->progress.ulspeed <
+ easy->easy_handle->set.max_send_speed ) ) &&
+ ( ( easy->easy_handle->set.max_recv_speed == 0 ) ||
+ ( easy->easy_handle->progress.dlspeed <
+ easy->easy_handle->set.max_recv_speed ) )
+ )
+ multistate(easy, CURLM_STATE_PERFORM);
+ break;
+
+ case CURLM_STATE_PERFORM:
+ /* check if over speed */
+ if ( ( ( easy->easy_handle->set.max_send_speed > 0 ) &&
+ ( easy->easy_handle->progress.ulspeed >
+ easy->easy_handle->set.max_send_speed ) ) ||
+ ( ( easy->easy_handle->set.max_recv_speed > 0 ) &&
+ ( easy->easy_handle->progress.dlspeed >
+ easy->easy_handle->set.max_recv_speed ) )
+ ) {
+ /* Transfer is over the speed limit. Change state. TODO: Call
+ * Curl_expire() with the time left until we're targeted to be below
+ * the speed limit again. */
+ multistate(easy, CURLM_STATE_TOOFAST );
+ break;
+ }
+
+ /* read/write data if it is ready to do so */
+ easy->result = Curl_readwrite(easy->easy_conn, &done);
+
+ k = &easy->easy_handle->reqdata.keep;
+
+ if (!(k->keepon & KEEP_READ)) {
+ /* We're done reading */
+ easy->easy_conn->readchannel_inuse = FALSE;
+ }
+
+ if (!(k->keepon & KEEP_WRITE)) {
+ /* We're done writing */
+ easy->easy_conn->writechannel_inuse = FALSE;
+ }
+
+ if(easy->result) {
+ /* The transfer phase returned error, we mark the connection to get
+ * closed to prevent being re-used. This is becasue we can't
+ * possibly know if the connection is in a good shape or not now. */
+ easy->easy_conn->bits.close = TRUE;
+
+ if(CURL_SOCKET_BAD != easy->easy_conn->sock[SECONDARYSOCKET]) {
+ /* if we failed anywhere, we must clean up the secondary socket if
+ it was used */
+ sclose(easy->easy_conn->sock[SECONDARYSOCKET]);
+ easy->easy_conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
+ }
+ Curl_posttransfer(easy->easy_handle);
+ Curl_done(&easy->easy_conn, easy->result, FALSE);
+ }
+ else if(TRUE == done) {
+ char *newurl;
+ bool retry = Curl_retry_request(easy->easy_conn, &newurl);
+
+ /* call this even if the readwrite function returned error */
+ Curl_posttransfer(easy->easy_handle);
+
+ /* When we follow redirects, must to go back to the CONNECT state */
+ if(easy->easy_handle->reqdata.newurl || retry) {
+ Curl_removeHandleFromPipeline(easy->easy_handle,
+ easy->easy_conn->recv_pipe);
+ if(!retry) {
+ /* if the URL is a follow-location and not just a retried request
+ then figure out the URL here */
+ newurl = easy->easy_handle->reqdata.newurl;
+ easy->easy_handle->reqdata.newurl = NULL;
+ }
+ easy->result = Curl_done(&easy->easy_conn, CURLE_OK, FALSE);
+ if(easy->result == CURLE_OK)
+ easy->result = Curl_follow(easy->easy_handle, newurl, retry);
+ if(CURLE_OK == easy->result) {
+ multistate(easy, CURLM_STATE_CONNECT);
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+ else
+ /* Since we "took it", we are in charge of freeing this on
+ failure */
+ free(newurl);
+ }
+ else {
+ /* after the transfer is done, go DONE */
+ multistate(easy, CURLM_STATE_DONE);
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+ }
+
+ break;
+
+ case CURLM_STATE_DONE:
+ /* Remove ourselves from the receive pipeline */
+ Curl_removeHandleFromPipeline(easy->easy_handle,
+ easy->easy_conn->recv_pipe);
+ easy->easy_handle->state.is_in_pipeline = FALSE;
+
+ if (easy->easy_conn->bits.stream_was_rewound) {
+ /* This request read past its response boundary so we quickly
+ let the other requests consume those bytes since there is no
+ guarantee that the socket will become active again */
+ result = CURLM_CALL_MULTI_PERFORM;
+ }
+
+ if (!easy->easy_handle->state.cancelled) {
+ /* post-transfer command */
+ easy->result = Curl_done(&easy->easy_conn, CURLE_OK, FALSE);
+
+ /* after we have DONE what we're supposed to do, go COMPLETED, and
+ it doesn't matter what the Curl_done() returned! */
+ multistate(easy, CURLM_STATE_COMPLETED);
+ }
+
+ break;
+
+ case CURLM_STATE_COMPLETED:
+ if (easy->easy_handle->state.cancelled)
+ /* Go into the CANCELLED state if we were cancelled */
+ multistate(easy, CURLM_STATE_CANCELLED);
+
+ /* this is a completed transfer, it is likely to still be connected */
+
+ /* This node should be delinked from the list now and we should post
+ an information message that we are complete. */
+ break;
+
+ case CURLM_STATE_CANCELLED:
+ /* Cancelled transfer, wait to be cleaned up */
+ break;
+
+ default:
+ return CURLM_INTERNAL_ERROR;
+ }
+
+ if(CURLM_STATE_COMPLETED != easy->state) {
+ if(CURLE_OK != easy->result) {
+ /*
+ * If an error was returned, and we aren't in completed state now,
+ * then we go to completed and consider this transfer aborted.
+ */
+ easy->easy_handle->state.is_in_pipeline = FALSE;
+ easy->easy_handle->state.pipe_broke = FALSE;
+
+ if(easy->easy_conn) {
+ /* if this has a connection, unsubscribe from the pipelines */
+ easy->easy_conn->writechannel_inuse = FALSE;
+ easy->easy_conn->readchannel_inuse = FALSE;
+ }
+ multistate(easy, CURLM_STATE_COMPLETED);
+ }
+ }
+
+ } while (easy->easy_handle->change.url_changed);
+
+ if ((CURLM_STATE_COMPLETED == easy->state) && !easy->msg) {
+ if(easy->easy_handle->dns.hostcachetype == HCACHE_MULTI) {
+ /* clear out the usage of the shared DNS cache */
+ easy->easy_handle->dns.hostcache = NULL;
+ easy->easy_handle->dns.hostcachetype = HCACHE_NONE;
+ }
+
+ /* now add a node to the Curl_message linked list with this info */
+ msg = (struct Curl_message *)malloc(sizeof(struct Curl_message));
+
+ if(!msg)
+ return CURLM_OUT_OF_MEMORY;
+
+ msg->extmsg.msg = CURLMSG_DONE;
+ msg->extmsg.easy_handle = easy->easy_handle;
+ msg->extmsg.data.result = easy->result;
+ msg->next = NULL;
+
+ easy->msg = msg;
+ easy->msg_num = 1; /* there is one unread message here */
+
+ multi->num_msgs++; /* increase message counter */
+ }
+
+ return result;
+}
+
+
+CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
+{
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+ struct Curl_one_easy *easy;
+ CURLMcode returncode=CURLM_OK;
+ struct Curl_tree *t;
+
+ if(!GOOD_MULTI_HANDLE(multi))
+ return CURLM_BAD_HANDLE;
+
+ easy=multi->easy.next;
+ while(easy) {
+ CURLMcode result;
+
+ if (easy->easy_handle->state.cancelled &&
+ easy->state == CURLM_STATE_CANCELLED) {
+ /* Remove cancelled handles once it's safe to do so */
+ Curl_multi_rmeasy(multi_handle, easy->easy_handle);
+ easy->easy_handle = NULL;
+ easy = easy->next;
+ continue;
+ }
+
+ result = multi_runsingle(multi, easy);
+ if(result)
+ returncode = result;
+
+ easy = easy->next; /* operate on next handle */
+ }
+
+ /*
+ * Simply remove all expired timers from the splay since handles are dealt
+ * with unconditionally by this function and curl_multi_timeout() requires
+ * that already passed/handled expire times are removed from the splay.
+ */
+ do {
+ struct timeval now = Curl_tvnow();
+ int key = now.tv_sec; /* drop the usec part */
+
+ multi->timetree = Curl_splaygetbest(key, multi->timetree, &t);
+ if (t) {
+ struct SessionHandle *d = t->payload;
+ struct timeval* tv = &d->state.expiretime;
+
+ /* clear the expire times within the handles that we remove from the
+ splay tree */
+ tv->tv_sec = 0;
+ tv->tv_usec = 0;
+ }
+
+ } while(t);
+
+ *running_handles = multi->num_alive;
+
+ if ( CURLM_OK == returncode )
+ update_timer(multi);
+ return returncode;
+}
+
+/* This is called when an easy handle is cleanup'ed that is part of a multi
+ handle */
+void Curl_multi_rmeasy(void *multi_handle, CURL *easy_handle)
+{
+ curl_multi_remove_handle(multi_handle, easy_handle);
+}
+
+
+CURLMcode curl_multi_cleanup(CURLM *multi_handle)
+{
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+ struct Curl_one_easy *easy;
+ struct Curl_one_easy *nexteasy;
+ int i;
+ struct closure *cl;
+ struct closure *n;
+
+ if(GOOD_MULTI_HANDLE(multi)) {
+ multi->type = 0; /* not good anymore */
+ Curl_hash_destroy(multi->hostcache);
+ Curl_hash_destroy(multi->sockhash);
+
+ /* go over all connections that have close actions */
+ for(i=0; i< multi->connc->num; i++) {
+ if(multi->connc->connects[i] &&
+ multi->connc->connects[i]->protocol & PROT_CLOSEACTION) {
+ Curl_disconnect(multi->connc->connects[i]);
+ multi->connc->connects[i] = NULL;
+ }
+ }
+ /* now walk through the list of handles we kept around only to be
+ able to close connections "properly" */
+ cl = multi->closure;
+ while(cl) {
+ cl->easy_handle->state.shared_conn = NULL; /* no more shared */
+ if(cl->easy_handle->state.closed)
+ /* close handle only if curl_easy_cleanup() already has been called
+ for this easy handle */
+ Curl_close(cl->easy_handle);
+ n = cl->next;
+ free(cl);
+ cl= n;
+ }
+
+ Curl_rm_connc(multi->connc);
+
+ /* remove all easy handles */
+ easy = multi->easy.next;
+ while(easy) {
+ nexteasy=easy->next;
+ if(easy->easy_handle->dns.hostcachetype == HCACHE_MULTI) {
+ /* clear out the usage of the shared DNS cache */
+ easy->easy_handle->dns.hostcache = NULL;
+ easy->easy_handle->dns.hostcachetype = HCACHE_NONE;
+ }
+
+ /* Clear the pointer to the connection cache */
+ easy->easy_handle->state.connc = NULL;
+
+ Curl_easy_addmulti(easy->easy_handle, NULL); /* clear the association */
+
+ if (easy->msg)
+ free(easy->msg);
+ free(easy);
+ easy = nexteasy;
+ }
+
+ free(multi);
+
+ return CURLM_OK;
+ }
+ else
+ return CURLM_BAD_HANDLE;
+}
+
+CURLMsg *curl_multi_info_read(CURLM *multi_handle, int *msgs_in_queue)
+{
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+
+ *msgs_in_queue = 0; /* default to none */
+
+ if(GOOD_MULTI_HANDLE(multi)) {
+ struct Curl_one_easy *easy;
+
+ if(!multi->num_msgs)
+ return NULL; /* no messages left to return */
+
+ easy=multi->easy.next;
+ while(easy) {
+ if(easy->msg_num) {
+ easy->msg_num--;
+ break;
+ }
+ easy = easy->next;
+ }
+ if(!easy)
+ return NULL; /* this means internal count confusion really */
+
+ multi->num_msgs--;
+ *msgs_in_queue = multi->num_msgs;
+
+ return &easy->msg->extmsg;
+ }
+ else
+ return NULL;
+}
+
+/*
+ * singlesocket() checks what sockets we deal with and their "action state"
+ * and if we have a different state in any of those sockets from last time we
+ * call the callback accordingly.
+ */
+static void singlesocket(struct Curl_multi *multi,
+ struct Curl_one_easy *easy)
+{
+ curl_socket_t socks[MAX_SOCKSPEREASYHANDLE];
+ int i;
+ struct Curl_sh_entry *entry;
+ curl_socket_t s;
+ int num;
+ unsigned int curraction;
+
+ memset(&socks, 0, sizeof(socks));
+ for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++)
+ socks[i] = CURL_SOCKET_BAD;
+
+ /* Fill in the 'current' struct with the state as it is now: what sockets to
+ supervise and for what actions */
+ curraction = multi_getsock(easy, socks, MAX_SOCKSPEREASYHANDLE);
+
+ /* We have 0 .. N sockets already and we get to know about the 0 .. M
+ sockets we should have from now on. Detect the differences, remove no
+ longer supervised ones and add new ones */
+
+ /* walk over the sockets we got right now */
+ for(i=0; (i< MAX_SOCKSPEREASYHANDLE) &&
+ (curraction & (GETSOCK_READSOCK(i) | GETSOCK_WRITESOCK(i)));
+ i++) {
+ int action = CURL_POLL_NONE;
+
+ s = socks[i];
+
+ /* get it from the hash */
+ entry = Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s));
+
+ if(curraction & GETSOCK_READSOCK(i))
+ action |= CURL_POLL_IN;
+ if(curraction & GETSOCK_WRITESOCK(i))
+ action |= CURL_POLL_OUT;
+
+ if(entry) {
+ /* yeps, already present so check if it has the same action set */
+ if(entry->action == action)
+ /* same, continue */
+ continue;
+ }
+ else {
+ /* this is a socket we didn't have before, add it! */
+ entry = sh_addentry(multi->sockhash, s, easy->easy_handle);
+ if(!entry)
+ /* fatal */
+ return;
+ }
+
+ multi->socket_cb(easy->easy_handle,
+ s,
+ action,
+ multi->socket_userp,
+ entry ? entry->socketp : NULL);
+
+ entry->action = action; /* store the current action state */
+ }
+
+ num = i; /* number of sockets */
+
+ /* when we've walked over all the sockets we should have right now, we must
+ make sure to detect sockets that are removed */
+ for(i=0; i< easy->numsocks; i++) {
+ int j;
+ s = easy->sockets[i];
+ for(j=0; j<num; j++) {
+ if(s == socks[j]) {
+ /* this is still supervised */
+ s = CURL_SOCKET_BAD;
+ break;
+ }
+ }
+ if(s != CURL_SOCKET_BAD) {
+ /* this socket has been removed. Remove it */
+
+ entry = Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s));
+ if(entry) {
+ /* just a precaution, this socket really SHOULD be in the hash already
+ but in case it isn't, we don't have to tell the app to remove it
+ either since it never got to know about it */
+ multi->socket_cb(easy->easy_handle,
+ s,
+ CURL_POLL_REMOVE,
+ multi->socket_userp,
+ entry ? entry->socketp : NULL);
+
+ sh_delentry(multi->sockhash, s);
+ }
+ }
+ }
+
+ memcpy(easy->sockets, socks, num*sizeof(curl_socket_t));
+ easy->numsocks = num;
+}
+
+static CURLMcode multi_socket(struct Curl_multi *multi,
+ bool checkall,
+ curl_socket_t s,
+ int *running_handles)
+{
+ CURLMcode result = CURLM_OK;
+ struct SessionHandle *data = NULL;
+ struct Curl_tree *t;
+
+ if(checkall) {
+ struct Curl_one_easy *easyp;
+ /* *perform() deals with running_handles on its own */
+ result = curl_multi_perform(multi, running_handles);
+
+ /* walk through each easy handle and do the socket state change magic
+ and callbacks */
+ easyp=multi->easy.next;
+ while(easyp) {
+ singlesocket(multi, easyp);
+ easyp = easyp->next;
+ }
+
+ /* or should we fall-through and do the timer-based stuff? */
+ return result;
+ }
+ else if (s != CURL_SOCKET_TIMEOUT) {
+
+ struct Curl_sh_entry *entry =
+ Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s));
+
+ if(!entry)
+ /* unmatched socket, major problemo! */
+ return CURLM_BAD_SOCKET; /* better return code? */
+
+ data = entry->easy;
+
+ if(data->magic != CURLEASY_MAGIC_NUMBER)
+ /* bad bad bad bad bad bad bad */
+ return CURLM_INTERNAL_ERROR;
+
+ result = multi_runsingle(multi, data->set.one_easy);
+
+ if(result == CURLM_OK)
+ /* get the socket(s) and check if the state has been changed since
+ last */
+ singlesocket(multi, data->set.one_easy);
+
+ /* Now we fall-through and do the timer-based stuff, since we don't want
+ to force the user to have to deal with timeouts as long as at least one
+ connection in fact has traffic. */
+
+ data = NULL; /* set data to NULL again to avoid calling multi_runsingle()
+ in case there's no need to */
+ }
+
+ /*
+ * The loop following here will go on as long as there are expire-times left
+ * to process in the splay and 'data' will be re-assigned for every expired
+ * handle we deal with.
+ */
+ do {
+ int key;
+ struct timeval now;
+
+ /* the first loop lap 'data' can be NULL */
+ if(data) {
+ result = multi_runsingle(multi, data->set.one_easy);
+
+ if(result == CURLM_OK)
+ /* get the socket(s) and check if the state has been changed since
+ last */
+ singlesocket(multi, data->set.one_easy);
+ }
+
+ /* Check if there's one (more) expired timer to deal with! This function
+ extracts a matching node if there is one */
+
+ now = Curl_tvnow();
+ key = now.tv_sec; /* drop the usec part */
+
+ multi->timetree = Curl_splaygetbest(key, multi->timetree, &t);
+ if(t) {
+ /* assign 'data' to be the easy handle we just removed from the splay
+ tree */
+ data = t->payload;
+ /* clear the expire time within the handle we removed from the
+ splay tree */
+ data->state.expiretime.tv_sec = 0;
+ data->state.expiretime.tv_usec = 0;
+ }
+
+ } while(t);
+
+ *running_handles = multi->num_alive;
+ return result;
+}
+
+CURLMcode curl_multi_setopt(CURLM *multi_handle,
+ CURLMoption option, ...)
+{
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+ CURLMcode res = CURLM_OK;
+ va_list param;
+
+ if(!GOOD_MULTI_HANDLE(multi))
+ return CURLM_BAD_HANDLE;
+
+ va_start(param, option);
+
+ switch(option) {
+ case CURLMOPT_SOCKETFUNCTION:
+ multi->socket_cb = va_arg(param, curl_socket_callback);
+ break;
+ case CURLMOPT_SOCKETDATA:
+ multi->socket_userp = va_arg(param, void *);
+ break;
+ case CURLMOPT_PIPELINING:
+ multi->pipelining_enabled = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLMOPT_TIMERFUNCTION:
+ multi->timer_cb = va_arg(param, curl_multi_timer_callback);
+ break;
+ case CURLMOPT_TIMERDATA:
+ multi->timer_userp = va_arg(param, void *);
+ break;
+ default:
+ res = CURLM_UNKNOWN_OPTION;
+ break;
+ }
+ va_end(param);
+ return res;
+}
+
+
+CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s,
+ int *running_handles)
+{
+ CURLMcode result = multi_socket((struct Curl_multi *)multi_handle, FALSE, s,
+ running_handles);
+ if (CURLM_OK == result)
+ update_timer((struct Curl_multi *)multi_handle);
+ return result;
+}
+
+CURLMcode curl_multi_socket_all(CURLM *multi_handle, int *running_handles)
+
+{
+ CURLMcode result = multi_socket((struct Curl_multi *)multi_handle,
+ TRUE, CURL_SOCKET_BAD, running_handles);
+ if (CURLM_OK == result)
+ update_timer((struct Curl_multi *)multi_handle);
+ return result;
+}
+
+static CURLMcode multi_timeout(struct Curl_multi *multi,
+ long *timeout_ms)
+{
+ if(multi->timetree) {
+ /* we have a tree of expire times */
+ struct timeval now = Curl_tvnow();
+
+ /* splay the lowest to the bottom */
+ multi->timetree = Curl_splay(0, multi->timetree);
+
+ /* At least currently, the splay key is a time_t for the expire time */
+ *timeout_ms = (multi->timetree->key - now.tv_sec) * 1000 -
+ now.tv_usec/1000;
+ if(*timeout_ms < 0)
+ /* 0 means immediately */
+ *timeout_ms = 0;
+ }
+ else
+ *timeout_ms = -1;
+
+ return CURLM_OK;
+}
+
+CURLMcode curl_multi_timeout(CURLM *multi_handle,
+ long *timeout_ms)
+{
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+
+ /* First, make some basic checks that the CURLM handle is a good handle */
+ if(!GOOD_MULTI_HANDLE(multi))
+ return CURLM_BAD_HANDLE;
+
+ return multi_timeout(multi, timeout_ms);
+}
+
+/*
+ * Tell the application it should update its timers, if it subscribes to the
+ * update timer callback.
+ */
+static int update_timer(struct Curl_multi *multi)
+{
+ long timeout_ms;
+ if (!multi->timer_cb)
+ return 0;
+ if ( multi_timeout(multi, &timeout_ms) != CURLM_OK )
+ return -1;
+ if ( timeout_ms < 0 )
+ return 0;
+
+ /* When multi_timeout() is done, multi->timetree points to the node with the
+ * timeout we got the (relative) time-out time for. We can thus easily check
+ * if this is the same (fixed) time as we got in a previous call and then
+ * avoid calling the callback again. */
+ if(multi->timetree->key == multi->timer_lastcall)
+ return 0;
+
+ multi->timer_lastcall = multi->timetree->key;
+
+ return multi->timer_cb((CURLM*)multi, timeout_ms, multi->timer_userp);
+}
+
+/* given a number of milliseconds from now to use to set the 'act before
+ this'-time for the transfer, to be extracted by curl_multi_timeout() */
+void Curl_expire(struct SessionHandle *data, long milli)
+{
+ struct Curl_multi *multi = data->multi;
+ struct timeval *nowp = &data->state.expiretime;
+ int rc;
+
+ /* this is only interesting for multi-interface using libcurl, and only
+ while there is still a multi interface struct remaining! */
+ if(!multi)
+ return;
+
+ if(!milli) {
+ /* No timeout, clear the time data. */
+ if(nowp->tv_sec) {
+ /* Since this is an cleared time, we must remove the previous entry from
+ the splay tree */
+ rc = Curl_splayremovebyaddr(multi->timetree,
+ &data->state.timenode,
+ &multi->timetree);
+ if(rc)
+ infof(data, "Internal error clearing splay node = %d\n", rc);
+ infof(data, "Expire cleared\n");
+ nowp->tv_sec = 0;
+ nowp->tv_usec = 0;
+ }
+ }
+ else {
+ struct timeval set;
+ int rest;
+
+ set = Curl_tvnow();
+ set.tv_sec += milli/1000;
+ set.tv_usec += (milli%1000)*1000;
+
+ rest = (int)(set.tv_usec - 1000000);
+ if(rest > 0) {
+ /* bigger than a full microsec */
+ set.tv_sec++;
+ set.tv_usec -= 1000000;
+ }
+
+ if(nowp->tv_sec) {
+ /* This means that the struct is added as a node in the splay tree.
+ Compare if the new time is earlier, and only remove-old/add-new if it
+ is. */
+ long diff = curlx_tvdiff(set, *nowp);
+ if(diff > 0)
+ /* the new expire time was later so we don't change this */
+ return;
+
+ /* Since this is an updated time, we must remove the previous entry from
+ the splay tree first and then re-add the new value */
+ rc = Curl_splayremovebyaddr(multi->timetree,
+ &data->state.timenode,
+ &multi->timetree);
+ if(rc)
+ infof(data, "Internal error removing splay node = %d\n", rc);
+ }
+
+ *nowp = set;
+#if 0
+ infof(data, "Expire at %ld / %ld (%ldms)\n",
+ (long)nowp->tv_sec, (long)nowp->tv_usec, milli);
+#endif
+ data->state.timenode.payload = data;
+ multi->timetree = Curl_splayinsert((int)nowp->tv_sec,
+ multi->timetree,
+ &data->state.timenode);
+ }
+#if 0
+ Curl_splayprint(multi->timetree, 0, TRUE);
+#endif
+}
+
+CURLMcode curl_multi_assign(CURLM *multi_handle,
+ curl_socket_t s, void *hashp)
+{
+ struct Curl_sh_entry *there = NULL;
+ struct Curl_multi *multi = (struct Curl_multi *)multi_handle;
+
+ if(s != CURL_SOCKET_BAD)
+ there = Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(curl_socket_t));
+
+ if(!there)
+ return CURLM_BAD_SOCKET;
+
+ there->socketp = hashp;
+
+ return CURLM_OK;
+}
+
+static bool multi_conn_using(struct Curl_multi *multi,
+ struct SessionHandle *data)
+{
+ /* any live CLOSEACTION-connections pointing to the give 'data' ? */
+ int i;
+
+ for(i=0; i< multi->connc->num; i++) {
+ if(multi->connc->connects[i] &&
+ (multi->connc->connects[i]->data == data) &&
+ multi->connc->connects[i]->protocol & PROT_CLOSEACTION)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/* Add the given data pointer to the list of 'closure handles' that are kept
+ around only to be able to close some connections nicely - just make sure
+ that this handle isn't already added, like for the cases when an easy
+ handle is removed, added and removed again... */
+static void add_closure(struct Curl_multi *multi,
+ struct SessionHandle *data)
+{
+ int i;
+ struct closure *cl = (struct closure *)calloc(sizeof(struct closure), 1);
+ struct closure *p=NULL;
+ struct closure *n;
+ if(cl) {
+ cl->easy_handle = data;
+ cl->next = multi->closure;
+ multi->closure = cl;
+ }
+
+ p = multi->closure;
+ cl = p->next; /* start immediately on the second since the first is the one
+ we just added and it is _very_ likely to actually exist
+ used in the cache since that's the whole purpose of adding
+ it to this list! */
+
+ /* When adding, scan through all the other currently kept handles and see if
+ there are any connections still referring to them and kill them if not. */
+ while(cl) {
+ bool inuse = FALSE;
+ for(i=0; i< multi->connc->num; i++) {
+ if(multi->connc->connects[i] &&
+ (multi->connc->connects[i]->data == cl->easy_handle)) {
+ inuse = TRUE;
+ break;
+ }
+ }
+
+ n = cl->next;
+
+ if(!inuse) {
+ /* cl->easy_handle is now killable */
+ infof(data, "Delayed kill of easy handle %p\n", cl->easy_handle);
+ /* unmark it as not having a connection around that uses it anymore */
+ cl->easy_handle->state.shared_conn= NULL;
+ Curl_close(cl->easy_handle);
+ if(p)
+ p->next = n;
+ else
+ multi->closure = n;
+ free(cl);
+ }
+ else
+ p = cl;
+
+ cl = n;
+ }
+
+}
+
+#ifdef CURLDEBUG
+void curl_multi_dump(CURLM *multi_handle)
+{
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+ struct Curl_one_easy *easy;
+ int i;
+ fprintf(stderr, "* Multi status: %d handles, %d alive\n",
+ multi->num_easy, multi->num_alive);
+ for(easy=multi->easy.next; easy; easy = easy->next) {
+ if(easy->state != CURLM_STATE_COMPLETED) {
+ /* only display handles that are not completed */
+ fprintf(stderr, "handle %p, state %s, %d sockets\n",
+ (void *)easy->easy_handle,
+ statename[easy->state], easy->numsocks);
+ for(i=0; i < easy->numsocks; i++) {
+ curl_socket_t s = easy->sockets[i];
+ struct Curl_sh_entry *entry =
+ Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s));
+
+ fprintf(stderr, "%d ", (int)s);
+ if(!entry) {
+ fprintf(stderr, "INTERNAL CONFUSION\n");
+ continue;
+ }
+ fprintf(stderr, "[%s %s] ",
+ entry->action&CURL_POLL_IN?"RECVING":"",
+ entry->action&CURL_POLL_OUT?"SENDING":"");
+ }
+ if(easy->numsocks)
+ fprintf(stderr, "\n");
+ }
+ }
+}
+#endif
diff --git a/Utilities/cmcurl/multiif.h b/Utilities/cmcurl/multiif.h
new file mode 100644
index 0000000000..800aa0f5db
--- /dev/null
+++ b/Utilities/cmcurl/multiif.h
@@ -0,0 +1,46 @@
+#ifndef __MULTIIF_H
+#define __MULTIIF_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * Prototypes for library-wide functions provided by multi.c
+ */
+void Curl_expire(struct SessionHandle *data, long milli);
+
+void Curl_multi_rmeasy(void *multi, CURL *data);
+
+bool Curl_multi_canPipeline(struct Curl_multi* multi);
+
+/* the write bits start at bit 16 for the *getsock() bitmap */
+#define GETSOCK_WRITEBITSTART 16
+
+#define GETSOCK_BLANK 0 /* no bits set */
+
+/* set the bit for the given sock number to make the bitmap for writable */
+#define GETSOCK_WRITESOCK(x) (1 << (GETSOCK_WRITEBITSTART + (x)))
+
+/* set the bit for the given sock number to make the bitmap for readable */
+#define GETSOCK_READSOCK(x) (1 << (x))
+
+#endif /* __MULTIIF_H */
diff --git a/Utilities/cmcurl/netrc.c b/Utilities/cmcurl/netrc.c
new file mode 100644
index 0000000000..54d175989d
--- /dev/null
+++ b/Utilities/cmcurl/netrc.c
@@ -0,0 +1,247 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+#ifdef VMS
+#include <unixlib.h>
+#endif
+
+#include <curl/curl.h>
+#include "netrc.h"
+
+#include "strequal.h"
+#include "strtok.h"
+#include "memory.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/* Debug this single source file with:
+ 'make netrc' then run './netrc'!
+
+ Oh, make sure you have a .netrc file too ;-)
+ */
+
+/* Get user and password from .netrc when given a machine name */
+
+enum {
+ NOTHING,
+ HOSTFOUND, /* the 'machine' keyword was found */
+ HOSTCOMPLETE, /* the machine name following the keyword was found too */
+ HOSTVALID, /* this is "our" machine! */
+
+ HOSTEND /* LAST enum */
+};
+
+/* make sure we have room for at least this size: */
+#define LOGINSIZE 64
+#define PASSWORDSIZE 64
+
+/* returns -1 on failure, 0 if the host is found, 1 is the host isn't found */
+int Curl_parsenetrc(char *host,
+ char *login,
+ char *password,
+ char *netrcfile)
+{
+ FILE *file;
+ int retcode=1;
+ int specific_login = (login[0] != 0);
+ char *home = NULL;
+ bool home_alloc = FALSE;
+ bool netrc_alloc = FALSE;
+ int state=NOTHING;
+
+ char state_login=0; /* Found a login keyword */
+ char state_password=0; /* Found a password keyword */
+ int state_our_login=FALSE; /* With specific_login, found *our* login name */
+
+#define NETRC DOT_CHAR "netrc"
+
+#ifdef CURLDEBUG
+ {
+ /* This is a hack to allow testing.
+ * If compiled with --enable-debug and CURL_DEBUG_NETRC is defined,
+ * then it's the path to a substitute .netrc for testing purposes *only* */
+
+ char *override = curl_getenv("CURL_DEBUG_NETRC");
+
+ if (override) {
+ fprintf(stderr, "NETRC: overridden " NETRC " file: %s\n", override);
+ netrcfile = override;
+ netrc_alloc = TRUE;
+ }
+ }
+#endif /* CURLDEBUG */
+ if(!netrcfile) {
+ home = curl_getenv("HOME"); /* portable environment reader */
+ if(home) {
+ home_alloc = TRUE;
+#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
+ }
+ else {
+ struct passwd *pw;
+ pw= getpwuid(geteuid());
+ if (pw) {
+#ifdef VMS
+ home = decc$translate_vms(pw->pw_dir);
+#else
+ home = pw->pw_dir;
+#endif
+ }
+#endif
+ }
+
+ if(!home)
+ return -1;
+
+ netrcfile = curl_maprintf("%s%s%s", home, DIR_CHAR, NETRC);
+ if(!netrcfile) {
+ if(home_alloc)
+ free(home);
+ return -1;
+ }
+ netrc_alloc = TRUE;
+ }
+
+ file = fopen(netrcfile, "r");
+ if(file) {
+ char *tok;
+ char *tok_buf;
+ bool done=FALSE;
+ char netrcbuffer[256];
+
+ while(!done && fgets(netrcbuffer, sizeof(netrcbuffer), file)) {
+ tok=strtok_r(netrcbuffer, " \t\n", &tok_buf);
+ while(!done && tok) {
+
+ if (login[0] && password[0]) {
+ done=TRUE;
+ break;
+ }
+
+ switch(state) {
+ case NOTHING:
+ if(strequal("machine", tok)) {
+ /* the next tok is the machine name, this is in itself the
+ delimiter that starts the stuff entered for this machine,
+ after this we need to search for 'login' and
+ 'password'. */
+ state=HOSTFOUND;
+ }
+ break;
+ case HOSTFOUND:
+ if(strequal(host, tok)) {
+ /* and yes, this is our host! */
+ state=HOSTVALID;
+#ifdef _NETRC_DEBUG
+ fprintf(stderr, "HOST: %s\n", tok);
+#endif
+ retcode=0; /* we did find our host */
+ }
+ else
+ /* not our host */
+ state=NOTHING;
+ break;
+ case HOSTVALID:
+ /* we are now parsing sub-keywords concerning "our" host */
+ if(state_login) {
+ if (specific_login) {
+ state_our_login = strequal(login, tok);
+ }
+ else {
+ strncpy(login, tok, LOGINSIZE-1);
+#ifdef _NETRC_DEBUG
+ fprintf(stderr, "LOGIN: %s\n", login);
+#endif
+ }
+ state_login=0;
+ }
+ else if(state_password) {
+ if (state_our_login || !specific_login) {
+ strncpy(password, tok, PASSWORDSIZE-1);
+#ifdef _NETRC_DEBUG
+ fprintf(stderr, "PASSWORD: %s\n", password);
+#endif
+ }
+ state_password=0;
+ }
+ else if(strequal("login", tok))
+ state_login=1;
+ else if(strequal("password", tok))
+ state_password=1;
+ else if(strequal("machine", tok)) {
+ /* ok, there's machine here go => */
+ state = HOSTFOUND;
+ state_our_login = FALSE;
+ }
+ break;
+ } /* switch (state) */
+
+ tok = strtok_r(NULL, " \t\n", &tok_buf);
+ } /* while (tok) */
+ } /* while fgets() */
+
+ fclose(file);
+ }
+
+ if(home_alloc)
+ free(home);
+ if(netrc_alloc)
+ free(netrcfile);
+
+ return retcode;
+}
+
+#ifdef _NETRC_DEBUG
+int main(int argc, char **argv)
+{
+ char login[64]="";
+ char password[64]="";
+
+ if(argc<2)
+ return -1;
+
+ if(0 == ParseNetrc(argv[1], login, password)) {
+ printf("HOST: %s LOGIN: %s PASSWORD: %s\n",
+ argv[1], login, password);
+ }
+}
+
+#endif
diff --git a/Utilities/cmcurl/netrc.h b/Utilities/cmcurl/netrc.h
new file mode 100644
index 0000000000..939c552dff
--- /dev/null
+++ b/Utilities/cmcurl/netrc.h
@@ -0,0 +1,34 @@
+#ifndef __NETRC_H
+#define __NETRC_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+int Curl_parsenetrc(char *host,
+ char *login,
+ char *password,
+ char *filename);
+ /* Assume: password[0]=0, host[0] != 0.
+ * If login[0] = 0, search for login and password within a machine section
+ * in the netrc.
+ * If login[0] != 0, search for password within machine and login.
+ */
+#endif
diff --git a/Utilities/cmcurl/nwlib.c b/Utilities/cmcurl/nwlib.c
new file mode 100644
index 0000000000..b0eea56c71
--- /dev/null
+++ b/Utilities/cmcurl/nwlib.c
@@ -0,0 +1,300 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <library.h>
+#include <netware.h>
+#include <screen.h>
+#include <nks/thread.h>
+#include <nks/synch.h>
+
+#include "memory.h"
+#include "memdebug.h"
+
+typedef struct
+{
+ int _errno;
+ void *twentybytes;
+} libthreaddata_t;
+
+typedef struct
+{
+ int x;
+ int y;
+ int z;
+ void *tenbytes;
+ NXKey_t perthreadkey; /* if -1, no key obtained... */
+ NXMutex_t *lock;
+} libdata_t;
+
+int gLibId = -1;
+void *gLibHandle = (void *) NULL;
+rtag_t gAllocTag = (rtag_t) NULL;
+NXMutex_t *gLibLock = (NXMutex_t *) NULL;
+
+/* internal library function prototypes... */
+int DisposeLibraryData ( void * );
+void DisposeThreadData ( void * );
+int GetOrSetUpData ( int id, libdata_t **data, libthreaddata_t **threaddata );
+
+
+int _NonAppStart( void *NLMHandle,
+ void *errorScreen,
+ const char *cmdLine,
+ const char *loadDirPath,
+ size_t uninitializedDataLength,
+ void *NLMFileHandle,
+ int (*readRoutineP)( int conn,
+ void *fileHandle, size_t offset,
+ size_t nbytes,
+ size_t *bytesRead,
+ void *buffer ),
+ size_t customDataOffset,
+ size_t customDataSize,
+ int messageCount,
+ const char **messages )
+{
+ NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
+
+#ifndef __GNUC__
+#pragma unused(cmdLine)
+#pragma unused(loadDirPath)
+#pragma unused(uninitializedDataLength)
+#pragma unused(NLMFileHandle)
+#pragma unused(readRoutineP)
+#pragma unused(customDataOffset)
+#pragma unused(customDataSize)
+#pragma unused(messageCount)
+#pragma unused(messages)
+#endif
+
+/*
+** Here we process our command line, post errors (to the error screen),
+** perform initializations and anything else we need to do before being able
+** to accept calls into us. If we succeed, we return non-zero and the NetWare
+** Loader will leave us up, otherwise we fail to load and get dumped.
+*/
+ gAllocTag = AllocateResourceTag(NLMHandle,
+ "<library-name> memory allocations",
+ AllocSignature);
+
+ if (!gAllocTag) {
+ OutputToScreen(errorScreen, "Unable to allocate resource tag for "
+ "library memory allocations.\n");
+ return -1;
+ }
+
+ gLibId = register_library(DisposeLibraryData);
+
+ if (gLibId < -1) {
+ OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
+ return -1;
+ }
+
+ gLibHandle = NLMHandle;
+
+ gLibLock = NXMutexAlloc(0, 0, &liblock);
+
+ if (!gLibLock) {
+ OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+** Here we clean up any resources we allocated. Resource tags is a big part
+** of what we created, but NetWare doesn't ask us to free those.
+*/
+void _NonAppStop( void )
+{
+ (void) unregister_library(gLibId);
+ NXMutexFree(gLibLock);
+}
+
+/*
+** This function cannot be the first in the file for if the file is linked
+** first, then the check-unload function's offset will be nlmname.nlm+0
+** which is how to tell that there isn't one. When the check function is
+** first in the linked objects, it is ambiguous. For this reason, we will
+** put it inside this file after the stop function.
+**
+** Here we check to see if it's alright to ourselves to be unloaded. If not,
+** we return a non-zero value. Right now, there isn't any reason not to allow
+** it.
+*/
+int _NonAppCheckUnload( void )
+{
+ return 0;
+}
+
+int GetOrSetUpData(int id, libdata_t **appData,
+ libthreaddata_t **threadData )
+{
+ int err;
+ libdata_t *app_data;
+ libthreaddata_t *thread_data;
+ NXKey_t key;
+ NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0);
+
+ err = 0;
+ thread_data = (libthreaddata_t *) NULL;
+
+/*
+** Attempt to get our data for the application calling us. This is where we
+** store whatever application-specific information we need to carry in support
+** of calling applications.
+*/
+ app_data = (libdata_t *) get_app_data(id);
+
+ if (!app_data) {
+/*
+** This application hasn't called us before; set up application AND per-thread
+** data. Of course, just in case a thread from this same application is calling
+** us simultaneously, we better lock our application data-creation mutex. We
+** also need to recheck for data after we acquire the lock because WE might be
+** that other thread that was too late to create the data and the first thread
+** in will have created it.
+*/
+ NXLock(gLibLock);
+
+ if (!(app_data = (libdata_t *) get_app_data(id))) {
+ app_data = (libdata_t *) malloc(sizeof(libdata_t));
+
+ if (app_data) {
+ memset(app_data, 0, sizeof(libdata_t));
+
+ app_data->tenbytes = malloc(10);
+ app_data->lock = NXMutexAlloc(0, 0, &liblock);
+
+ if (!app_data->tenbytes || !app_data->lock) {
+ if (app_data->lock)
+ NXMutexFree(app_data->lock);
+
+ free(app_data);
+ app_data = (libdata_t *) NULL;
+ err = ENOMEM;
+ }
+
+ if (app_data) {
+/*
+** Here we burn in the application data that we were trying to get by calling
+** get_app_data(). Next time we call the first function, we'll get this data
+** we're just now setting. We also go on here to establish the per-thread data
+** for the calling thread, something we'll have to do on each application
+** thread the first time it calls us.
+*/
+ err = set_app_data(gLibId, app_data);
+
+ if (err) {
+ free(app_data);
+ app_data = (libdata_t *) NULL;
+ err = ENOMEM;
+ }
+ else {
+ /* create key for thread-specific data... */
+ err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key);
+
+ if (err) /* (no more keys left?) */
+ key = -1;
+
+ app_data->perthreadkey = key;
+ }
+ }
+ }
+ }
+
+ NXUnlock(gLibLock);
+ }
+
+ if (app_data) {
+ key = app_data->perthreadkey;
+
+ if (key != -1 /* couldn't create a key? no thread data */
+ && !(err = NXKeyGetValue(key, (void **) &thread_data))
+ && !thread_data) {
+/*
+** Allocate the per-thread data for the calling thread. Regardless of whether
+** there was already application data or not, this may be the first call by a
+** a new thread. The fact that we allocation 20 bytes on a pointer is not very
+** important, this just helps to demonstrate that we can have arbitrarily
+** complex per-thread data.
+*/
+ thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t));
+
+ if (thread_data) {
+ thread_data->_errno = 0;
+ thread_data->twentybytes = malloc(20);
+
+ if (!thread_data->twentybytes) {
+ free(thread_data);
+ thread_data = (libthreaddata_t *) NULL;
+ err = ENOMEM;
+ }
+
+ if ((err = NXKeySetValue(key, thread_data))) {
+ free(thread_data->twentybytes);
+ free(thread_data);
+ thread_data = (libthreaddata_t *) NULL;
+ }
+ }
+ }
+ }
+
+ if (appData)
+ *appData = app_data;
+
+ if (threadData)
+ *threadData = thread_data;
+
+ return err;
+}
+
+int DisposeLibraryData( void *data)
+{
+ if (data) {
+ void *tenbytes = ((libdata_t *) data)->tenbytes;
+
+ if (tenbytes)
+ free(tenbytes);
+
+ free(data);
+ }
+
+ return 0;
+}
+
+void DisposeThreadData(void *data)
+{
+ if (data) {
+ void *twentybytes = ((libthreaddata_t *) data)->twentybytes;
+
+ if (twentybytes)
+ free(twentybytes);
+
+ free(data);
+ }
+}
diff --git a/Utilities/cmcurl/parsedate.c b/Utilities/cmcurl/parsedate.c
new file mode 100644
index 0000000000..ef91585e5d
--- /dev/null
+++ b/Utilities/cmcurl/parsedate.c
@@ -0,0 +1,425 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+/*
+ A brief summary of the date string formats this parser groks:
+
+ RFC 2616 3.3.1
+
+ Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
+ Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
+ Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
+
+ we support dates without week day name:
+
+ 06 Nov 1994 08:49:37 GMT
+ 06-Nov-94 08:49:37 GMT
+ Nov 6 08:49:37 1994
+
+ without the time zone:
+
+ 06 Nov 1994 08:49:37
+ 06-Nov-94 08:49:37
+
+ weird order:
+
+ 1994 Nov 6 08:49:37 (GNU date fails)
+ GMT 08:49:37 06-Nov-94 Sunday
+ 94 6 Nov 08:49:37 (GNU date fails)
+
+ time left out:
+
+ 1994 Nov 6
+ 06-Nov-94
+ Sun Nov 6 94
+
+ unusual separators:
+
+ 1994.Nov.6
+ Sun/Nov/6/94/GMT
+
+ commonly used time zone names:
+
+ Sun, 06 Nov 1994 08:49:37 CET
+ 06 Nov 1994 08:49:37 EST
+
+ time zones specified using RFC822 style:
+
+ Sun, 12 Sep 2004 15:05:58 -0700
+ Sat, 11 Sep 2004 21:32:11 +0200
+
+ compact numerical date strings:
+
+ 20040912 15:05:58 -0700
+ 20040911 +0200
+
+*/
+#include "setup.h"
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* for strtol() */
+#endif
+
+#include <curl/curl.h>
+
+static time_t Curl_parsedate(const char *date);
+
+const char * const Curl_wkday[] =
+{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
+static const char * const weekday[] =
+{ "Monday", "Tuesday", "Wednesday", "Thursday",
+ "Friday", "Saturday", "Sunday" };
+const char * const Curl_month[]=
+{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+
+struct tzinfo {
+ const char *name;
+ int offset; /* +/- in minutes */
+};
+
+/* Here's a bunch of frequently used time zone names. These were supported
+ by the old getdate parser. */
+#define tDAYZONE -60 /* offset for daylight savings time */
+static const struct tzinfo tz[]= {
+ {"GMT", 0}, /* Greenwich Mean */
+ {"UTC", 0}, /* Universal (Coordinated) */
+ {"WET", 0}, /* Western European */
+ {"BST", 0 tDAYZONE}, /* British Summer */
+ {"WAT", 60}, /* West Africa */
+ {"AST", 240}, /* Atlantic Standard */
+ {"ADT", 240 tDAYZONE}, /* Atlantic Daylight */
+ {"EST", 300}, /* Eastern Standard */
+ {"EDT", 300 tDAYZONE}, /* Eastern Daylight */
+ {"CST", 360}, /* Central Standard */
+ {"CDT", 360 tDAYZONE}, /* Central Daylight */
+ {"MST", 420}, /* Mountain Standard */
+ {"MDT", 420 tDAYZONE}, /* Mountain Daylight */
+ {"PST", 480}, /* Pacific Standard */
+ {"PDT", 480 tDAYZONE}, /* Pacific Daylight */
+ {"YST", 540}, /* Yukon Standard */
+ {"YDT", 540 tDAYZONE}, /* Yukon Daylight */
+ {"HST", 600}, /* Hawaii Standard */
+ {"HDT", 600 tDAYZONE}, /* Hawaii Daylight */
+ {"CAT", 600}, /* Central Alaska */
+ {"AHST", 600}, /* Alaska-Hawaii Standard */
+ {"NT", 660}, /* Nome */
+ {"IDLW", 720}, /* International Date Line West */
+ {"CET", -60}, /* Central European */
+ {"MET", -60}, /* Middle European */
+ {"MEWT", -60}, /* Middle European Winter */
+ {"MEST", -60 tDAYZONE}, /* Middle European Summer */
+ {"CEST", -60 tDAYZONE}, /* Central European Summer */
+ {"MESZ", -60 tDAYZONE}, /* Middle European Summer */
+ {"FWT", -60}, /* French Winter */
+ {"FST", -60 tDAYZONE}, /* French Summer */
+ {"EET", -120}, /* Eastern Europe, USSR Zone 1 */
+ {"WAST", -420}, /* West Australian Standard */
+ {"WADT", -420 tDAYZONE}, /* West Australian Daylight */
+ {"CCT", -480}, /* China Coast, USSR Zone 7 */
+ {"JST", -540}, /* Japan Standard, USSR Zone 8 */
+ {"EAST", -600}, /* Eastern Australian Standard */
+ {"EADT", -600 tDAYZONE}, /* Eastern Australian Daylight */
+ {"GST", -600}, /* Guam Standard, USSR Zone 9 */
+ {"NZT", -720}, /* New Zealand */
+ {"NZST", -720}, /* New Zealand Standard */
+ {"NZDT", -720 tDAYZONE}, /* New Zealand Daylight */
+ {"IDLE", -720}, /* International Date Line East */
+};
+
+/* returns:
+ -1 no day
+ 0 monday - 6 sunday
+*/
+
+static int checkday(char *check, size_t len)
+{
+ int i;
+ const char * const *what;
+ bool found= FALSE;
+ if(len > 3)
+ what = &weekday[0];
+ else
+ what = &Curl_wkday[0];
+ for(i=0; i<7; i++) {
+ if(curl_strequal(check, what[0])) {
+ found=TRUE;
+ break;
+ }
+ what++;
+ }
+ return found?i:-1;
+}
+
+static int checkmonth(char *check)
+{
+ int i;
+ const char * const *what;
+ bool found= FALSE;
+
+ what = &Curl_month[0];
+ for(i=0; i<12; i++) {
+ if(curl_strequal(check, what[0])) {
+ found=TRUE;
+ break;
+ }
+ what++;
+ }
+ return found?i:-1; /* return the offset or -1, no real offset is -1 */
+}
+
+/* return the time zone offset between GMT and the input one, in number
+ of seconds or -1 if the timezone wasn't found/legal */
+
+static int checktz(char *check)
+{
+ unsigned int i;
+ const struct tzinfo *what;
+ bool found= FALSE;
+
+ what = tz;
+ for(i=0; i< sizeof(tz)/sizeof(tz[0]); i++) {
+ if(curl_strequal(check, what->name)) {
+ found=TRUE;
+ break;
+ }
+ what++;
+ }
+ return found?what->offset*60:-1;
+}
+
+static void skip(const char **date)
+{
+ /* skip everything that aren't letters or digits */
+ while(**date && !ISALNUM(**date))
+ (*date)++;
+}
+
+enum assume {
+ DATE_MDAY,
+ DATE_YEAR,
+ DATE_TIME
+};
+
+static time_t Curl_parsedate(const char *date)
+{
+ time_t t = 0;
+ int wdaynum=-1; /* day of the week number, 0-6 (mon-sun) */
+ int monnum=-1; /* month of the year number, 0-11 */
+ int mdaynum=-1; /* day of month, 1 - 31 */
+ int hournum=-1;
+ int minnum=-1;
+ int secnum=-1;
+ int yearnum=-1;
+ int tzoff=-1;
+ struct tm tm;
+ enum assume dignext = DATE_MDAY;
+ const char *indate = date; /* save the original pointer */
+ int part = 0; /* max 6 parts */
+
+ while(*date && (part < 6)) {
+ bool found=FALSE;
+
+ skip(&date);
+
+ if(ISALPHA(*date)) {
+ /* a name coming up */
+ char buf[32]="";
+ size_t len;
+ sscanf(date, "%31[A-Za-z]", buf);
+ len = strlen(buf);
+
+ if(wdaynum == -1) {
+ wdaynum = checkday(buf, len);
+ if(wdaynum != -1)
+ found = TRUE;
+ }
+ if(!found && (monnum == -1)) {
+ monnum = checkmonth(buf);
+ if(monnum != -1)
+ found = TRUE;
+ }
+
+ if(!found && (tzoff == -1)) {
+ /* this just must be a time zone string */
+ tzoff = checktz(buf);
+ if(tzoff != -1)
+ found = TRUE;
+ }
+
+ if(!found)
+ return -1; /* bad string */
+
+ date += len;
+ }
+ else if(ISDIGIT(*date)) {
+ /* a digit */
+ int val;
+ char *end;
+ if((secnum == -1) &&
+ (3 == sscanf(date, "%02d:%02d:%02d", &hournum, &minnum, &secnum))) {
+ /* time stamp! */
+ date += 8;
+ found = TRUE;
+ }
+ else {
+ val = (int)strtol(date, &end, 10);
+
+ if((tzoff == -1) &&
+ ((end - date) == 4) &&
+ (val < 1300) &&
+ (indate< date) &&
+ ((date[-1] == '+' || date[-1] == '-'))) {
+ /* four digits and a value less than 1300 and it is preceeded with
+ a plus or minus. This is a time zone indication. */
+ found = TRUE;
+ tzoff = (val/100 * 60 + val%100)*60;
+
+ /* the + and - prefix indicates the local time compared to GMT,
+ this we need ther reversed math to get what we want */
+ tzoff = date[-1]=='+'?-tzoff:tzoff;
+ }
+
+ if(((end - date) == 8) &&
+ (yearnum == -1) &&
+ (monnum == -1) &&
+ (mdaynum == -1)) {
+ /* 8 digits, no year, month or day yet. This is YYYYMMDD */
+ found = TRUE;
+ yearnum = val/10000;
+ monnum = (val%10000)/100-1; /* month is 0 - 11 */
+ mdaynum = val%100;
+ }
+
+ if(!found && (dignext == DATE_MDAY) && (mdaynum == -1)) {
+ if((val > 0) && (val<32)) {
+ mdaynum = val;
+ found = TRUE;
+ }
+ dignext = DATE_YEAR;
+ }
+
+ if(!found && (dignext == DATE_YEAR) && (yearnum == -1)) {
+ yearnum = val;
+ found = TRUE;
+ if(yearnum < 1900) {
+ if (yearnum > 70)
+ yearnum += 1900;
+ else
+ yearnum += 2000;
+ }
+ if(mdaynum == -1)
+ dignext = DATE_MDAY;
+ }
+
+ if(!found)
+ return -1;
+
+ date = end;
+ }
+ }
+
+ part++;
+ }
+
+ if(-1 == secnum)
+ secnum = minnum = hournum = 0; /* no time, make it zero */
+
+ if((-1 == mdaynum) ||
+ (-1 == monnum) ||
+ (-1 == yearnum))
+ /* lacks vital info, fail */
+ return -1;
+
+#if SIZEOF_TIME_T < 5
+ /* 32 bit time_t can only hold dates to the beginning of 2038 */
+ if(yearnum > 2037)
+ return 0x7fffffff;
+#endif
+
+ tm.tm_sec = secnum;
+ tm.tm_min = minnum;
+ tm.tm_hour = hournum;
+ tm.tm_mday = mdaynum;
+ tm.tm_mon = monnum;
+ tm.tm_year = yearnum - 1900;
+ tm.tm_wday = 0;
+ tm.tm_yday = 0;
+ tm.tm_isdst = 0;
+
+ /* mktime() returns a time_t. time_t is often 32 bits, even on many
+ architectures that feature 64 bit 'long'.
+
+ Some systems have 64 bit time_t and deal with years beyond 2038. However,
+ even some of the systems with 64 bit time_t returns -1 for dates beyond
+ 03:14:07 UTC, January 19, 2038. (Such as AIX 5100-06)
+ */
+ t = mktime(&tm);
+
+ /* time zone adjust (cast t to int to compare to negative one) */
+ if(-1 != (int)t) {
+ struct tm *gmt;
+ long delta;
+ time_t t2;
+
+#ifdef HAVE_GMTIME_R
+ /* thread-safe version */
+ struct tm keeptime2;
+ gmt = (struct tm *)gmtime_r(&t, &keeptime2);
+ if(!gmt)
+ return -1; /* illegal date/time */
+ t2 = mktime(gmt);
+#else
+ /* It seems that at least the MSVC version of mktime() doesn't work
+ properly if it gets the 'gmt' pointer passed in (which is a pointer
+ returned from gmtime() pointing to static memory), so instead we copy
+ the tm struct to a local struct and pass a pointer to that struct as
+ input to mktime(). */
+ struct tm gmt2;
+ gmt = gmtime(&t); /* use gmtime_r() if available */
+ if(!gmt)
+ return -1; /* illegal date/time */
+ gmt2 = *gmt;
+ t2 = mktime(&gmt2);
+#endif
+
+ /* Add the time zone diff (between the given timezone and GMT) and the
+ diff between the local time zone and GMT. */
+ delta = (long)((tzoff!=-1?tzoff:0) + (t - t2));
+
+ if((delta>0) && (t + delta < t))
+ return -1; /* time_t overflow */
+
+ t += delta;
+ }
+
+ return t;
+}
+
+time_t curl_getdate(const char *p, const time_t *now)
+{
+ (void)now;
+ return Curl_parsedate(p);
+}
diff --git a/Utilities/cmcurl/parsedate.h b/Utilities/cmcurl/parsedate.h
new file mode 100644
index 0000000000..b29fe9bae1
--- /dev/null
+++ b/Utilities/cmcurl/parsedate.h
@@ -0,0 +1,28 @@
+#ifndef __PARSEDATE_H
+#define __PARSEDATE_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+extern const char * const Curl_wkday[7];
+extern const char * const Curl_month[12];
+
+#endif
diff --git a/Utilities/cmcurl/progress.c b/Utilities/cmcurl/progress.c
new file mode 100644
index 0000000000..5ba829a037
--- /dev/null
+++ b/Utilities/cmcurl/progress.c
@@ -0,0 +1,424 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+#include <time.h>
+
+#if defined(__EMX__)
+#include <stdlib.h>
+#endif
+
+#include <curl/curl.h>
+#include "urldata.h"
+#include "sendf.h"
+#include "progress.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero
+ byte) */
+static void time2str(char *r, long t)
+{
+ long h;
+ if(!t) {
+ strcpy(r, "--:--:--");
+ return;
+ }
+ h = (t/3600);
+ if(h <= 99) {
+ long m = (t-(h*3600))/60;
+ long s = (t-(h*3600)-(m*60));
+ snprintf(r, 9, "%2ld:%02ld:%02ld",h,m,s);
+ }
+ else {
+ /* this equals to more than 99 hours, switch to a more suitable output
+ format to fit within the limits. */
+ if(h/24 <= 999)
+ snprintf(r, 9, "%3ldd %02ldh", h/24, h-(h/24)*24);
+ else
+ snprintf(r, 9, "%7ldd", h/24);
+ }
+}
+
+/* The point of this function would be to return a string of the input data,
+ but never longer than 5 columns (+ one zero byte).
+ Add suffix k, M, G when suitable... */
+static char *max5data(curl_off_t bytes, char *max5)
+{
+#define ONE_KILOBYTE 1024
+#define ONE_MEGABYTE (1024* ONE_KILOBYTE)
+#define ONE_GIGABYTE (1024* ONE_MEGABYTE)
+#define ONE_TERRABYTE ((curl_off_t)1024* ONE_GIGABYTE)
+#define ONE_PETABYTE ((curl_off_t)1024* ONE_TERRABYTE)
+
+ if(bytes < 100000) {
+ snprintf(max5, 6, "%5" FORMAT_OFF_T, bytes);
+ }
+ else if(bytes < (10000*ONE_KILOBYTE)) {
+ snprintf(max5, 6, "%4" FORMAT_OFF_T "k", (curl_off_t)(bytes/ONE_KILOBYTE));
+ }
+ else if(bytes < (100*ONE_MEGABYTE)) {
+ /* 'XX.XM' is good as long as we're less than 100 megs */
+ snprintf(max5, 6, "%2d.%0dM",
+ (int)(bytes/ONE_MEGABYTE),
+ (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) );
+ }
+#if SIZEOF_CURL_OFF_T > 4
+ else if(bytes < ( (curl_off_t)10000*ONE_MEGABYTE))
+ /* 'XXXXM' is good until we're at 10000MB or above */
+ snprintf(max5, 6, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE));
+
+ else if(bytes < (curl_off_t)100*ONE_GIGABYTE)
+ /* 10000 MB - 100 GB, we show it as XX.XG */
+ snprintf(max5, 6, "%2d.%0dG",
+ (int)(bytes/ONE_GIGABYTE),
+ (int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) );
+
+ else if(bytes < (curl_off_t)10000 * ONE_GIGABYTE)
+ /* up to 10000GB, display without decimal: XXXXG */
+ snprintf(max5, 6, "%4dG", (int)(bytes/ONE_GIGABYTE));
+
+ else if(bytes < (curl_off_t)10000 * ONE_TERRABYTE)
+ /* up to 10000TB, display without decimal: XXXXT */
+ snprintf(max5, 6, "%4dT", (int)(bytes/ONE_TERRABYTE));
+ else {
+ /* up to 10000PB, display without decimal: XXXXP */
+ snprintf(max5, 6, "%4dP", (int)(bytes/ONE_PETABYTE));
+
+ /* 16384 petabytes (16 exabytes) is maximum a 64 bit number can hold,
+ but this type is signed so 8192PB will be max.*/
+ }
+
+#else
+ else
+ snprintf(max5, 6, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE));
+#endif
+
+ return max5;
+}
+
+/*
+
+ New proposed interface, 9th of February 2000:
+
+ pgrsStartNow() - sets start time
+ pgrsSetDownloadSize(x) - known expected download size
+ pgrsSetUploadSize(x) - known expected upload size
+ pgrsSetDownloadCounter() - amount of data currently downloaded
+ pgrsSetUploadCounter() - amount of data currently uploaded
+ pgrsUpdate() - show progress
+ pgrsDone() - transfer complete
+
+*/
+
+void Curl_pgrsDone(struct connectdata *conn)
+{
+ struct SessionHandle *data = conn->data;
+ data->progress.lastshow=0;
+ Curl_pgrsUpdate(conn); /* the final (forced) update */
+
+ data->progress.speeder_c = 0; /* reset the progress meter display */
+}
+
+/* reset all times except redirect */
+void Curl_pgrsResetTimes(struct SessionHandle *data)
+{
+ data->progress.t_nslookup = 0.0;
+ data->progress.t_connect = 0.0;
+ data->progress.t_pretransfer = 0.0;
+ data->progress.t_starttransfer = 0.0;
+}
+
+void Curl_pgrsTime(struct SessionHandle *data, timerid timer)
+{
+ switch(timer) {
+ default:
+ case TIMER_NONE:
+ /* mistake filter */
+ break;
+ case TIMER_STARTSINGLE:
+ /* This is set at the start of a single fetch */
+ data->progress.t_startsingle = Curl_tvnow();
+ break;
+
+ case TIMER_NAMELOOKUP:
+ data->progress.t_nslookup =
+ Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle);
+ break;
+ case TIMER_CONNECT:
+ data->progress.t_connect =
+ Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle);
+ break;
+ case TIMER_PRETRANSFER:
+ data->progress.t_pretransfer =
+ Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle);
+ break;
+ case TIMER_STARTTRANSFER:
+ data->progress.t_starttransfer =
+ Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle);
+ break;
+ case TIMER_POSTRANSFER:
+ /* this is the normal end-of-transfer thing */
+ break;
+ case TIMER_REDIRECT:
+ data->progress.t_redirect =
+ Curl_tvdiff_secs(Curl_tvnow(), data->progress.start);
+ break;
+ }
+}
+
+void Curl_pgrsStartNow(struct SessionHandle *data)
+{
+ data->progress.speeder_c = 0; /* reset the progress meter display */
+ data->progress.start = Curl_tvnow();
+}
+
+void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, curl_off_t size)
+{
+ data->progress.downloaded = size;
+}
+
+void Curl_pgrsSetUploadCounter(struct SessionHandle *data, curl_off_t size)
+{
+ data->progress.uploaded = size;
+}
+
+void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size)
+{
+ data->progress.size_dl = size;
+ if(size > 0)
+ data->progress.flags |= PGRS_DL_SIZE_KNOWN;
+ else
+ data->progress.flags &= ~PGRS_DL_SIZE_KNOWN;
+}
+
+void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size)
+{
+ data->progress.size_ul = size;
+ if(size > 0)
+ data->progress.flags |= PGRS_UL_SIZE_KNOWN;
+ else
+ data->progress.flags &= ~PGRS_UL_SIZE_KNOWN;
+}
+
+int Curl_pgrsUpdate(struct connectdata *conn)
+{
+ struct timeval now;
+ int result;
+ char max5[6][10];
+ int dlpercen=0;
+ int ulpercen=0;
+ int total_percen=0;
+ curl_off_t total_transfer;
+ curl_off_t total_expected_transfer;
+ long timespent;
+ struct SessionHandle *data = conn->data;
+ int nowindex = data->progress.speeder_c% CURR_TIME;
+ int checkindex;
+ int countindex; /* amount of seconds stored in the speeder array */
+ char time_left[10];
+ char time_total[10];
+ char time_spent[10];
+ long ulestimate=0;
+ long dlestimate=0;
+ long total_estimate;
+
+ if(data->progress.flags & PGRS_HIDE)
+ ; /* We do enter this function even if we don't wanna see anything, since
+ this is were lots of the calculations are being made that will be used
+ even when not displayed! */
+ else if(!(data->progress.flags & PGRS_HEADERS_OUT)) {
+ if (!data->progress.callback) {
+ if(data->reqdata.resume_from)
+ fprintf(data->set.err,
+ "** Resuming transfer from byte position %" FORMAT_OFF_T
+ "\n",
+ data->reqdata.resume_from);
+ fprintf(data->set.err,
+ " %% Total %% Received %% Xferd Average Speed Time Time Time Current\n"
+ " Dload Upload Total Spent Left Speed\n");
+ }
+ data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */
+ }
+
+ now = Curl_tvnow(); /* what time is it */
+
+ /* The time spent so far (from the start) */
+ data->progress.timespent = Curl_tvdiff_secs(now, data->progress.start);
+ timespent = (long)data->progress.timespent;
+
+ /* The average download speed this far */
+ data->progress.dlspeed = (curl_off_t)
+ ((double)data->progress.downloaded/
+ (data->progress.timespent>0?data->progress.timespent:1));
+
+ /* The average upload speed this far */
+ data->progress.ulspeed = (curl_off_t)
+ ((double)data->progress.uploaded/
+ (data->progress.timespent>0?data->progress.timespent:1));
+
+ if(data->progress.lastshow == Curl_tvlong(now))
+ return 0; /* never update this more than once a second if the end isn't
+ reached */
+ data->progress.lastshow = now.tv_sec;
+
+ /* Let's do the "current speed" thing, which should use the fastest
+ of the dl/ul speeds. Store the fasted speed at entry 'nowindex'. */
+ data->progress.speeder[ nowindex ] =
+ data->progress.downloaded>data->progress.uploaded?
+ data->progress.downloaded:data->progress.uploaded;
+
+ /* remember the exact time for this moment */
+ data->progress.speeder_time [ nowindex ] = now;
+
+ /* advance our speeder_c counter, which is increased every time we get
+ here and we expect it to never wrap as 2^32 is a lot of seconds! */
+ data->progress.speeder_c++;
+
+ /* figure out how many index entries of data we have stored in our speeder
+ array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of
+ transfer. Imagine, after one second we have filled in two entries,
+ after two seconds we've filled in three entries etc. */
+ countindex = ((data->progress.speeder_c>=CURR_TIME)?
+ CURR_TIME:data->progress.speeder_c) - 1;
+
+ /* first of all, we don't do this if there's no counted seconds yet */
+ if(countindex) {
+ long span_ms;
+
+ /* Get the index position to compare with the 'nowindex' position.
+ Get the oldest entry possible. While we have less than CURR_TIME
+ entries, the first entry will remain the oldest. */
+ checkindex = (data->progress.speeder_c>=CURR_TIME)?
+ data->progress.speeder_c%CURR_TIME:0;
+
+ /* Figure out the exact time for the time span */
+ span_ms = Curl_tvdiff(now,
+ data->progress.speeder_time[checkindex]);
+ if(0 == span_ms)
+ span_ms=1; /* at least one millisecond MUST have passed */
+
+ /* Calculate the average speed the last 'span_ms' milliseconds */
+ {
+ curl_off_t amount = data->progress.speeder[nowindex]-
+ data->progress.speeder[checkindex];
+
+ if(amount > 4294967 /* 0xffffffff/1000 */)
+ /* the 'amount' value is bigger than would fit in 32 bits if
+ multiplied with 1000, so we use the double math for this */
+ data->progress.current_speed = (curl_off_t)
+ ((double)amount/((double)span_ms/1000.0));
+ else
+ /* the 'amount' value is small enough to fit within 32 bits even
+ when multiplied with 1000 */
+ data->progress.current_speed = amount*1000/span_ms;
+ }
+ }
+ else
+ /* the first second we use the main average */
+ data->progress.current_speed =
+ (data->progress.ulspeed>data->progress.dlspeed)?
+ data->progress.ulspeed:data->progress.dlspeed;
+
+ if(data->progress.flags & PGRS_HIDE)
+ return 0;
+
+ else if(data->set.fprogress) {
+ /* There's a callback set, so we call that instead of writing
+ anything ourselves. This really is the way to go. */
+ result= data->set.fprogress(data->set.progress_client,
+ (double)data->progress.size_dl,
+ (double)data->progress.downloaded,
+ (double)data->progress.size_ul,
+ (double)data->progress.uploaded);
+ if(result)
+ failf(data, "Callback aborted");
+ return result;
+ }
+
+ /* Figure out the estimated time of arrival for the upload */
+ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) &&
+ (data->progress.ulspeed>0) &&
+ (data->progress.size_ul > 100) ) {
+ ulestimate = (long)(data->progress.size_ul / data->progress.ulspeed);
+ ulpercen = (int)(100*(data->progress.uploaded/100) /
+ (data->progress.size_ul/100) );
+ }
+
+ /* ... and the download */
+ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) &&
+ (data->progress.dlspeed>0) &&
+ (data->progress.size_dl>100)) {
+ dlestimate = (long)(data->progress.size_dl / data->progress.dlspeed);
+ dlpercen = (int)(100*(data->progress.downloaded/100) /
+ (data->progress.size_dl/100));
+ }
+
+ /* Now figure out which of them that is slower and use for the for
+ total estimate! */
+ total_estimate = ulestimate>dlestimate?ulestimate:dlestimate;
+
+ /* create the three time strings */
+ time2str(time_left, total_estimate > 0?(total_estimate - timespent):0);
+ time2str(time_total, total_estimate);
+ time2str(time_spent, timespent);
+
+ /* Get the total amount of data expected to get transfered */
+ total_expected_transfer =
+ (data->progress.flags & PGRS_UL_SIZE_KNOWN?
+ data->progress.size_ul:data->progress.uploaded)+
+ (data->progress.flags & PGRS_DL_SIZE_KNOWN?
+ data->progress.size_dl:data->progress.downloaded);
+
+ /* We have transfered this much so far */
+ total_transfer = data->progress.downloaded + data->progress.uploaded;
+
+ /* Get the percentage of data transfered so far */
+ if(total_expected_transfer > 100)
+ total_percen=(int)(100*(total_transfer/100) /
+ (total_expected_transfer/100) );
+
+ fprintf(data->set.err,
+ "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s",
+ total_percen, /* 3 letters */ /* total % */
+ max5data(total_expected_transfer, max5[2]), /* total size */
+ dlpercen, /* 3 letters */ /* rcvd % */
+ max5data(data->progress.downloaded, max5[0]), /* rcvd size */
+ ulpercen, /* 3 letters */ /* xfer % */
+ max5data(data->progress.uploaded, max5[1]), /* xfer size */
+ max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */
+ max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */
+ time_total, /* 8 letters */ /* total time */
+ time_spent, /* 8 letters */ /* time spent */
+ time_left, /* 8 letters */ /* time left */
+ max5data(data->progress.current_speed, max5[5]) /* current speed */
+ );
+
+ /* we flush the output stream to make it appear as soon as possible */
+ fflush(data->set.err);
+
+ return 0;
+}
diff --git a/Utilities/cmcurl/progress.h b/Utilities/cmcurl/progress.h
new file mode 100644
index 0000000000..ad9d6623ec
--- /dev/null
+++ b/Utilities/cmcurl/progress.h
@@ -0,0 +1,70 @@
+#ifndef __PROGRESS_H
+#define __PROGRESS_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "timeval.h"
+
+
+typedef enum {
+ TIMER_NONE,
+ TIMER_NAMELOOKUP,
+ TIMER_CONNECT,
+ TIMER_PRETRANSFER,
+ TIMER_STARTTRANSFER,
+ TIMER_POSTRANSFER,
+ TIMER_STARTSINGLE,
+ TIMER_REDIRECT,
+ TIMER_LAST /* must be last */
+} timerid;
+
+void Curl_pgrsDone(struct connectdata *);
+void Curl_pgrsStartNow(struct SessionHandle *data);
+void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size);
+void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size);
+void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, curl_off_t size);
+void Curl_pgrsSetUploadCounter(struct SessionHandle *data, curl_off_t size);
+int Curl_pgrsUpdate(struct connectdata *);
+void Curl_pgrsResetTimes(struct SessionHandle *data);
+void Curl_pgrsTime(struct SessionHandle *data, timerid timer);
+
+
+/* Don't show progress for sizes smaller than: */
+#define LEAST_SIZE_PROGRESS BUFSIZE
+
+#define PROGRESS_DOWNLOAD (1<<0)
+#define PROGRESS_UPLOAD (1<<1)
+#define PROGRESS_DOWN_AND_UP (PROGRESS_UPLOAD | PROGRESS_DOWNLOAD)
+
+#define PGRS_SHOW_DL (1<<0)
+#define PGRS_SHOW_UL (1<<1)
+#define PGRS_DONE_DL (1<<2)
+#define PGRS_DONE_UL (1<<3)
+#define PGRS_HIDE (1<<4)
+#define PGRS_UL_SIZE_KNOWN (1<<5)
+#define PGRS_DL_SIZE_KNOWN (1<<6)
+
+#define PGRS_HEADERS_OUT (1<<7) /* set when the headers have been written */
+
+
+#endif /* __PROGRESS_H */
diff --git a/Utilities/cmcurl/security.c b/Utilities/cmcurl/security.c
new file mode 100644
index 0000000000..4c9aed8121
--- /dev/null
+++ b/Utilities/cmcurl/security.c
@@ -0,0 +1,493 @@
+/* This source code was modified by Martin Hedenfalk <mhe@stacken.kth.se> for
+ * use in Curl. His latest changes were done 2000-09-18.
+ *
+ * It has since been patched and modified a lot by Daniel Stenberg
+ * <daniel@haxx.se> to make it better applied to curl conditions, and to make
+ * it not use globals, pollute name space and more. This source code awaits a
+ * rewrite to work around the paragraph 2 in the BSD licenses as explained
+ * below.
+ *
+ * Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * 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.
+ *
+ * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. */
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_FTP
+#ifdef HAVE_KRB4
+
+#define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */
+#include <curl/mprintf.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <netdb.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "urldata.h"
+#include "krb4.h"
+#include "base64.h"
+#include "sendf.h"
+#include "ftp.h"
+#include "memory.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#define min(a, b) ((a) < (b) ? (a) : (b))
+
+static const struct {
+ enum protection_level level;
+ const char *name;
+} level_names[] = {
+ { prot_clear, "clear" },
+ { prot_safe, "safe" },
+ { prot_confidential, "confidential" },
+ { prot_private, "private" }
+};
+
+static enum protection_level
+name_to_level(const char *name)
+{
+ int i;
+ for(i = 0; i < (int)sizeof(level_names)/(int)sizeof(level_names[0]); i++)
+ if(curl_strnequal(level_names[i].name, name, strlen(name)))
+ return level_names[i].level;
+ return (enum protection_level)-1;
+}
+
+static const struct Curl_sec_client_mech * const mechs[] = {
+#ifdef KRB5
+ /* not supported */
+#endif
+#ifdef HAVE_KRB4
+ &Curl_krb4_client_mech,
+#endif
+ NULL
+};
+
+int
+Curl_sec_getc(struct connectdata *conn, FILE *F)
+{
+ if(conn->sec_complete && conn->data_prot) {
+ char c;
+ if(Curl_sec_read(conn, fileno(F), &c, 1) <= 0)
+ return EOF;
+ return c;
+ }
+ else
+ return getc(F);
+}
+
+static int
+block_read(int fd, void *buf, size_t len)
+{
+ unsigned char *p = buf;
+ int b;
+ while(len) {
+ b = read(fd, p, len);
+ if (b == 0)
+ return 0;
+ else if (b < 0)
+ return -1;
+ len -= b;
+ p += b;
+ }
+ return p - (unsigned char*)buf;
+}
+
+static int
+block_write(int fd, void *buf, size_t len)
+{
+ unsigned char *p = buf;
+ int b;
+ while(len) {
+ b = write(fd, p, len);
+ if(b < 0)
+ return -1;
+ len -= b;
+ p += b;
+ }
+ return p - (unsigned char*)buf;
+}
+
+static int
+sec_get_data(struct connectdata *conn,
+ int fd, struct krb4buffer *buf)
+{
+ int len;
+ int b;
+
+ b = block_read(fd, &len, sizeof(len));
+ if (b == 0)
+ return 0;
+ else if (b < 0)
+ return -1;
+ len = ntohl(len);
+ buf->data = realloc(buf->data, len);
+ b = block_read(fd, buf->data, len);
+ if (b == 0)
+ return 0;
+ else if (b < 0)
+ return -1;
+ buf->size = (conn->mech->decode)(conn->app_data, buf->data, len,
+ conn->data_prot, conn);
+ buf->index = 0;
+ return 0;
+}
+
+static size_t
+buffer_read(struct krb4buffer *buf, void *data, size_t len)
+{
+ len = min(len, buf->size - buf->index);
+ memcpy(data, (char*)buf->data + buf->index, len);
+ buf->index += len;
+ return len;
+}
+
+static size_t
+buffer_write(struct krb4buffer *buf, void *data, size_t len)
+{
+ if(buf->index + len > buf->size) {
+ void *tmp;
+ if(buf->data == NULL)
+ tmp = malloc(1024);
+ else
+ tmp = realloc(buf->data, buf->index + len);
+ if(tmp == NULL)
+ return -1;
+ buf->data = tmp;
+ buf->size = buf->index + len;
+ }
+ memcpy((char*)buf->data + buf->index, data, len);
+ buf->index += len;
+ return len;
+}
+
+int
+Curl_sec_read(struct connectdata *conn, int fd, void *buffer, int length)
+{
+ size_t len;
+ int rx = 0;
+
+ if(conn->sec_complete == 0 || conn->data_prot == 0)
+ return read(fd, buffer, length);
+
+ if(conn->in_buffer.eof_flag){
+ conn->in_buffer.eof_flag = 0;
+ return 0;
+ }
+
+ len = buffer_read(&conn->in_buffer, buffer, length);
+ length -= len;
+ rx += len;
+ buffer = (char*)buffer + len;
+
+ while(length) {
+ if(sec_get_data(conn, fd, &conn->in_buffer) < 0)
+ return -1;
+ if(conn->in_buffer.size == 0) {
+ if(rx)
+ conn->in_buffer.eof_flag = 1;
+ return rx;
+ }
+ len = buffer_read(&conn->in_buffer, buffer, length);
+ length -= len;
+ rx += len;
+ buffer = (char*)buffer + len;
+ }
+ return rx;
+}
+
+static int
+sec_send(struct connectdata *conn, int fd, char *from, int length)
+{
+ int bytes;
+ void *buf;
+ bytes = (conn->mech->encode)(conn->app_data, from, length, conn->data_prot,
+ &buf, conn);
+ bytes = htonl(bytes);
+ block_write(fd, &bytes, sizeof(bytes));
+ block_write(fd, buf, ntohl(bytes));
+ free(buf);
+ return length;
+}
+
+int
+Curl_sec_fflush_fd(struct connectdata *conn, int fd)
+{
+ if(conn->data_prot != prot_clear) {
+ if(conn->out_buffer.index > 0){
+ Curl_sec_write(conn, fd,
+ conn->out_buffer.data, conn->out_buffer.index);
+ conn->out_buffer.index = 0;
+ }
+ sec_send(conn, fd, NULL, 0);
+ }
+ return 0;
+}
+
+int
+Curl_sec_write(struct connectdata *conn, int fd, char *buffer, int length)
+{
+ int len = conn->buffer_size;
+ int tx = 0;
+
+ if(conn->data_prot == prot_clear)
+ return write(fd, buffer, length);
+
+ len -= (conn->mech->overhead)(conn->app_data, conn->data_prot, len);
+ while(length){
+ if(length < len)
+ len = length;
+ sec_send(conn, fd, buffer, len);
+ length -= len;
+ buffer += len;
+ tx += len;
+ }
+ return tx;
+}
+
+ssize_t
+Curl_sec_send(struct connectdata *conn, int num, char *buffer, int length)
+{
+ curl_socket_t fd = conn->sock[num];
+ return (ssize_t)Curl_sec_write(conn, fd, buffer, length);
+}
+
+int
+Curl_sec_putc(struct connectdata *conn, int c, FILE *F)
+{
+ char ch = c;
+ if(conn->data_prot == prot_clear)
+ return putc(c, F);
+
+ buffer_write(&conn->out_buffer, &ch, 1);
+ if(c == '\n' || conn->out_buffer.index >= 1024 /* XXX */) {
+ Curl_sec_write(conn, fileno(F), conn->out_buffer.data,
+ conn->out_buffer.index);
+ conn->out_buffer.index = 0;
+ }
+ return c;
+}
+
+int
+Curl_sec_read_msg(struct connectdata *conn, char *s, int level)
+{
+ int len;
+ unsigned char *buf;
+ int code;
+
+ len = Curl_base64_decode(s + 4, &buf); /* XXX */
+ if(len > 0)
+ len = (conn->mech->decode)(conn->app_data, buf, len, level, conn);
+ else
+ return -1;
+
+ if(len < 0) {
+ free(buf);
+ return -1;
+ }
+
+ buf[len] = '\0';
+
+ if(buf[3] == '-')
+ code = 0;
+ else
+ sscanf((char *)buf, "%d", &code);
+ if(buf[len-1] == '\n')
+ buf[len-1] = '\0';
+ strcpy(s, (char *)buf);
+ free(buf);
+ return code;
+}
+
+enum protection_level
+Curl_set_command_prot(struct connectdata *conn, enum protection_level level)
+{
+ enum protection_level old = conn->command_prot;
+ conn->command_prot = level;
+ return old;
+}
+
+static int
+sec_prot_internal(struct connectdata *conn, int level)
+{
+ char *p;
+ unsigned int s = 1048576;
+ ssize_t nread;
+
+ if(!conn->sec_complete){
+ infof(conn->data, "No security data exchange has taken place.\n");
+ return -1;
+ }
+
+ if(level){
+ int code;
+ if(Curl_ftpsendf(conn, "PBSZ %u", s))
+ return -1;
+
+ if(Curl_GetFTPResponse(&nread, conn, &code))
+ return -1;
+
+ if(code/100 != '2'){
+ failf(conn->data, "Failed to set protection buffer size.");
+ return -1;
+ }
+ conn->buffer_size = s;
+
+ p = strstr(conn->data->state.buffer, "PBSZ=");
+ if(p)
+ sscanf(p, "PBSZ=%u", &s);
+ if(s < conn->buffer_size)
+ conn->buffer_size = s;
+ }
+
+ if(Curl_ftpsendf(conn, "PROT %c", level["CSEP"]))
+ return -1;
+
+ if(Curl_GetFTPResponse(&nread, conn, NULL))
+ return -1;
+
+ if(conn->data->state.buffer[0] != '2'){
+ failf(conn->data, "Failed to set protection level.");
+ return -1;
+ }
+
+ conn->data_prot = (enum protection_level)level;
+ return 0;
+}
+
+void
+Curl_sec_set_protection_level(struct connectdata *conn)
+{
+ if(conn->sec_complete && conn->data_prot != conn->request_data_prot)
+ sec_prot_internal(conn, conn->request_data_prot);
+}
+
+
+int
+Curl_sec_request_prot(struct connectdata *conn, const char *level)
+{
+ int l = name_to_level(level);
+ if(l == -1)
+ return -1;
+ conn->request_data_prot = (enum protection_level)l;
+ return 0;
+}
+
+int
+Curl_sec_login(struct connectdata *conn)
+{
+ int ret;
+ const struct Curl_sec_client_mech * const *m;
+ ssize_t nread;
+ struct SessionHandle *data=conn->data;
+ int ftpcode;
+
+ for(m = mechs; *m && (*m)->name; m++) {
+ void *tmp;
+
+ tmp = realloc(conn->app_data, (*m)->size);
+ if (tmp == NULL) {
+ failf (data, "realloc %u failed", (*m)->size);
+ return -1;
+ }
+ conn->app_data = tmp;
+
+ if((*m)->init && (*(*m)->init)(conn->app_data) != 0) {
+ infof(data, "Skipping %s...\n", (*m)->name);
+ continue;
+ }
+ infof(data, "Trying %s...\n", (*m)->name);
+
+ if(Curl_ftpsendf(conn, "AUTH %s", (*m)->name))
+ return -1;
+
+ if(Curl_GetFTPResponse(&nread, conn, &ftpcode))
+ return -1;
+
+ if(conn->data->state.buffer[0] != '3'){
+ switch(ftpcode) {
+ case 504:
+ infof(data,
+ "%s is not supported by the server.\n", (*m)->name);
+ break;
+ case 534:
+ infof(data, "%s rejected as security mechanism.\n", (*m)->name);
+ break;
+ default:
+ if(conn->data->state.buffer[0] == '5') {
+ infof(data, "The server doesn't support the FTP "
+ "security extensions.\n");
+ return -1;
+ }
+ break;
+ }
+ continue;
+ }
+
+ ret = (*(*m)->auth)(conn->app_data, conn);
+
+ if(ret == AUTH_CONTINUE)
+ continue;
+ else if(ret != AUTH_OK){
+ /* mechanism is supposed to output error string */
+ return -1;
+ }
+ conn->mech = *m;
+ conn->sec_complete = 1;
+ conn->command_prot = prot_safe;
+ break;
+ }
+
+ return *m == NULL;
+}
+
+void
+Curl_sec_end(struct connectdata *conn)
+{
+ if (conn->mech != NULL) {
+ if(conn->mech->end)
+ (conn->mech->end)(conn->app_data);
+ memset(conn->app_data, 0, conn->mech->size);
+ free(conn->app_data);
+ conn->app_data = NULL;
+ }
+ conn->sec_complete = 0;
+ conn->data_prot = (enum protection_level)0;
+ conn->mech=NULL;
+}
+
+#endif /* HAVE_KRB4 */
+#endif /* CURL_DISABLE_FTP */
diff --git a/Utilities/cmcurl/select.c b/Utilities/cmcurl/select.c
new file mode 100644
index 0000000000..82f9dc2fc1
--- /dev/null
+++ b/Utilities/cmcurl/select.c
@@ -0,0 +1,315 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <errno.h>
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#ifndef HAVE_SELECT
+#error "We can't compile without select() support!"
+#endif
+
+#if defined(__BEOS__)
+/* BeOS has FD_SET defined in socket.h */
+#include <socket.h>
+#endif
+
+#ifdef __MSDOS__
+#include <dos.h> /* delay() */
+#endif
+
+#include <curl/curl.h>
+
+#include "urldata.h"
+#include "connect.h"
+#include "select.h"
+
+#if defined(USE_WINSOCK) || defined(TPF)
+#define VERIFY_SOCK(x) /* sockets are not in range [0..FD_SETSIZE] */
+#else
+#define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE))
+#define VERIFY_SOCK(x) do { \
+ if(!VALID_SOCK(x)) { \
+ errno = EINVAL; \
+ return -1; \
+ } \
+} while(0)
+#endif
+
+/*
+ * This is an internal function used for waiting for read or write
+ * events on single file descriptors. It attempts to replace select()
+ * in order to avoid limits with FD_SETSIZE.
+ *
+ * Return values:
+ * -1 = system call error
+ * 0 = timeout
+ * CSELECT_IN | CSELECT_OUT | CSELECT_ERR
+ */
+int Curl_select(curl_socket_t readfd, curl_socket_t writefd, int timeout_ms)
+{
+#if (defined(HAVE_POLL) && !defined(_POLL_EMUL_H_)) || defined(CURL_HAVE_WSAPOLL)
+ struct pollfd pfd[2];
+ int num;
+ int r;
+ int ret;
+
+ num = 0;
+ if (readfd != CURL_SOCKET_BAD) {
+ pfd[num].fd = readfd;
+ pfd[num].events = POLLIN;
+ num++;
+ }
+ if (writefd != CURL_SOCKET_BAD) {
+ pfd[num].fd = writefd;
+ pfd[num].events = POLLOUT;
+ num++;
+ }
+
+#if defined(HAVE_POLL) && !defined(_POLL_EMUL_H_)
+ do {
+ r = poll(pfd, num, timeout_ms);
+ } while((r == -1) && (errno == EINTR));
+#else
+ r = WSAPoll(pfd, num, timeout_ms);
+#endif
+
+ if (r < 0)
+ return -1;
+ if (r == 0)
+ return 0;
+
+ ret = 0;
+ num = 0;
+ if (readfd != CURL_SOCKET_BAD) {
+ if (pfd[num].revents & (POLLIN|POLLHUP))
+ ret |= CSELECT_IN;
+ if (pfd[num].revents & POLLERR) {
+#ifdef __CYGWIN__
+ /* Cygwin 1.5.21 needs this hack to pass test 160 */
+ if (errno == EINPROGRESS)
+ ret |= CSELECT_IN;
+ else
+#endif
+ ret |= CSELECT_ERR;
+ }
+ num++;
+ }
+ if (writefd != CURL_SOCKET_BAD) {
+ if (pfd[num].revents & POLLOUT)
+ ret |= CSELECT_OUT;
+ if (pfd[num].revents & (POLLERR|POLLHUP))
+ ret |= CSELECT_ERR;
+ }
+
+ return ret;
+#else
+ struct timeval timeout;
+ fd_set fds_read;
+ fd_set fds_write;
+ fd_set fds_err;
+ curl_socket_t maxfd;
+ int r;
+ int ret;
+
+ timeout.tv_sec = timeout_ms / 1000;
+ timeout.tv_usec = (timeout_ms % 1000) * 1000;
+
+ if((readfd == CURL_SOCKET_BAD) && (writefd == CURL_SOCKET_BAD)) {
+ /* According to POSIX we should pass in NULL pointers if we don't want to
+ wait for anything in particular but just use the timeout function.
+ Windows however returns immediately if done so. I copied the MSDOS
+ delay() use from src/main.c that already had this work-around. */
+#ifdef WIN32
+ Sleep(timeout_ms);
+#elif defined(__MSDOS__)
+ delay(timeout_ms);
+#else
+ select(0, NULL, NULL, NULL, &timeout);
+#endif
+ return 0;
+ }
+
+ FD_ZERO(&fds_err);
+ maxfd = (curl_socket_t)-1;
+
+ FD_ZERO(&fds_read);
+ if (readfd != CURL_SOCKET_BAD) {
+ VERIFY_SOCK(readfd);
+ FD_SET(readfd, &fds_read);
+ FD_SET(readfd, &fds_err);
+ maxfd = readfd;
+ }
+
+ FD_ZERO(&fds_write);
+ if (writefd != CURL_SOCKET_BAD) {
+ VERIFY_SOCK(writefd);
+ FD_SET(writefd, &fds_write);
+ FD_SET(writefd, &fds_err);
+ if (writefd > maxfd)
+ maxfd = writefd;
+ }
+
+ do {
+ r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, &timeout);
+ } while((r == -1) && (Curl_sockerrno() == EINTR));
+
+ if (r < 0)
+ return -1;
+ if (r == 0)
+ return 0;
+
+ ret = 0;
+ if (readfd != CURL_SOCKET_BAD) {
+ if (FD_ISSET(readfd, &fds_read))
+ ret |= CSELECT_IN;
+ if (FD_ISSET(readfd, &fds_err))
+ ret |= CSELECT_ERR;
+ }
+ if (writefd != CURL_SOCKET_BAD) {
+ if (FD_ISSET(writefd, &fds_write))
+ ret |= CSELECT_OUT;
+ if (FD_ISSET(writefd, &fds_err))
+ ret |= CSELECT_ERR;
+ }
+
+ return ret;
+#endif
+}
+
+/*
+ * This is a wrapper around poll(). If poll() does not exist, then
+ * select() is used instead. An error is returned if select() is
+ * being used and a file descriptor too large for FD_SETSIZE.
+ *
+ * Return values:
+ * -1 = system call error or fd >= FD_SETSIZE
+ * 0 = timeout
+ * 1 = number of structures with non zero revent fields
+ */
+int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
+{
+ int r;
+#if defined(HAVE_POLL) && !defined(_POLL_EMUL_H_)
+ do {
+ r = poll(ufds, nfds, timeout_ms);
+ } while((r == -1) && (errno == EINTR));
+#elif defined(CURL_HAVE_WSAPOLL)
+ r = WSAPoll(ufds, nfds, timeout_ms);
+#else
+ struct timeval timeout;
+ struct timeval *ptimeout;
+ fd_set fds_read;
+ fd_set fds_write;
+ fd_set fds_err;
+ curl_socket_t maxfd;
+ unsigned int i;
+
+ FD_ZERO(&fds_read);
+ FD_ZERO(&fds_write);
+ FD_ZERO(&fds_err);
+ maxfd = (curl_socket_t)-1;
+
+ for (i = 0; i < nfds; i++) {
+ if (ufds[i].fd == CURL_SOCKET_BAD)
+ continue;
+#ifndef USE_WINSOCK /* winsock sockets are not in range [0..FD_SETSIZE] */
+ if (ufds[i].fd >= FD_SETSIZE) {
+ errno = EINVAL;
+ return -1;
+ }
+#endif
+ if (ufds[i].fd > maxfd)
+ maxfd = ufds[i].fd;
+ if (ufds[i].events & POLLIN)
+ FD_SET(ufds[i].fd, &fds_read);
+ if (ufds[i].events & POLLOUT)
+ FD_SET(ufds[i].fd, &fds_write);
+ if (ufds[i].events & POLLERR)
+ FD_SET(ufds[i].fd, &fds_err);
+ }
+
+ if (timeout_ms < 0) {
+ ptimeout = NULL; /* wait forever */
+ } else {
+ timeout.tv_sec = timeout_ms / 1000;
+ timeout.tv_usec = (timeout_ms % 1000) * 1000;
+ ptimeout = &timeout;
+ }
+
+ do {
+ r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
+ } while((r == -1) && (Curl_sockerrno() == EINTR));
+
+ if (r < 0)
+ return -1;
+ if (r == 0)
+ return 0;
+
+ r = 0;
+ for (i = 0; i < nfds; i++) {
+ ufds[i].revents = 0;
+ if (ufds[i].fd == CURL_SOCKET_BAD)
+ continue;
+ if (FD_ISSET(ufds[i].fd, &fds_read))
+ ufds[i].revents |= POLLIN;
+ if (FD_ISSET(ufds[i].fd, &fds_write))
+ ufds[i].revents |= POLLOUT;
+ if (FD_ISSET(ufds[i].fd, &fds_err))
+ ufds[i].revents |= POLLERR;
+ if (ufds[i].revents != 0)
+ r++;
+ }
+#endif
+ return r;
+}
+
+#ifdef TPF
+/*
+ * This is a replacement for select() on the TPF platform.
+ * It is used whenever libcurl calls select().
+ * The call below to tpf_process_signals() is required because
+ * TPF's select calls are not signal interruptible.
+ *
+ * Return values are the same as select's.
+ */
+int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes,
+ fd_set* excepts, struct timeval* tv)
+{
+ int rc;
+
+ rc = tpf_select_bsd(maxfds, reads, writes, excepts, tv);
+ tpf_process_signals();
+ return(rc);
+}
+#endif /* TPF */
diff --git a/Utilities/cmcurl/select.h b/Utilities/cmcurl/select.h
new file mode 100644
index 0000000000..7573b1f54b
--- /dev/null
+++ b/Utilities/cmcurl/select.h
@@ -0,0 +1,60 @@
+#ifndef __SELECT_H
+#define __SELECT_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifdef HAVE_SYS_POLL_H
+#include <sys/poll.h>
+#else
+#ifndef POLLIN
+#define POLLIN 0x01
+#define POLLPRI 0x02
+#define POLLOUT 0x04
+#define POLLERR 0x08
+#define POLLHUP 0x10
+#define POLLNVAL 0x20
+
+struct pollfd
+{
+ curl_socket_t fd;
+ short events;
+ short revents;
+};
+#endif
+
+#endif
+
+#define CSELECT_IN 0x01
+#define CSELECT_OUT 0x02
+#define CSELECT_ERR 0x04
+
+int Curl_select(curl_socket_t readfd, curl_socket_t writefd, int timeout_ms);
+
+int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms);
+
+#ifdef TPF
+int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes,
+ fd_set* excepts, struct timeval* tv);
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/sendf.c b/Utilities/cmcurl/sendf.c
new file mode 100644
index 0000000000..500bf66f06
--- /dev/null
+++ b/Utilities/cmcurl/sendf.c
@@ -0,0 +1,663 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h> /* required for send() & recv() prototypes */
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <curl/curl.h>
+#include "urldata.h"
+#include "sendf.h"
+#include "connect.h" /* for the Curl_sockerrno() proto */
+#include "sslgen.h"
+#include "ssh.h"
+#include "multiif.h"
+
+#define _MPRINTF_REPLACE /* use the internal *printf() functions */
+#include <curl/mprintf.h>
+
+#ifdef HAVE_KRB4
+#include "krb4.h"
+#else
+#define Curl_sec_send(a,b,c,d) -1
+#define Curl_sec_read(a,b,c,d) -1
+#endif
+
+#include <string.h>
+#include "memory.h"
+#include "strerror.h"
+#include "easyif.h" /* for the Curl_convert_from_network prototype */
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/* returns last node in linked list */
+static struct curl_slist *slist_get_last(struct curl_slist *list)
+{
+ struct curl_slist *item;
+
+ /* if caller passed us a NULL, return now */
+ if (!list)
+ return NULL;
+
+ /* loop through to find the last item */
+ item = list;
+ while (item->next) {
+ item = item->next;
+ }
+ return item;
+}
+
+/*
+ * curl_slist_append() appends a string to the linked list. It always retunrs
+ * the address of the first record, so that you can sure this function as an
+ * initialization function as well as an append function. If you find this
+ * bothersome, then simply create a separate _init function and call it
+ * appropriately from within the proram.
+ */
+struct curl_slist *curl_slist_append(struct curl_slist *list,
+ const char *data)
+{
+ struct curl_slist *last;
+ struct curl_slist *new_item;
+
+ new_item = (struct curl_slist *) malloc(sizeof(struct curl_slist));
+ if (new_item) {
+ char *dup = strdup(data);
+ if(dup) {
+ new_item->next = NULL;
+ new_item->data = dup;
+ }
+ else {
+ free(new_item);
+ return NULL;
+ }
+ }
+ else
+ return NULL;
+
+ if (list) {
+ last = slist_get_last(list);
+ last->next = new_item;
+ return list;
+ }
+
+ /* if this is the first item, then new_item *is* the list */
+ return new_item;
+}
+
+/* be nice and clean up resources */
+void curl_slist_free_all(struct curl_slist *list)
+{
+ struct curl_slist *next;
+ struct curl_slist *item;
+
+ if (!list)
+ return;
+
+ item = list;
+ do {
+ next = item->next;
+
+ if (item->data) {
+ free(item->data);
+ }
+ free(item);
+ item = next;
+ } while (next);
+}
+
+#ifdef CURL_DO_LINEEND_CONV
+/*
+ * convert_lineends() changes CRLF (\r\n) end-of-line markers to a single LF
+ * (\n), with special processing for CRLF sequences that are split between two
+ * blocks of data. Remaining, bare CRs are changed to LFs. The possibly new
+ * size of the data is returned.
+ */
+static size_t convert_lineends(struct SessionHandle *data,
+ char *startPtr, size_t size)
+{
+ char *inPtr, *outPtr;
+
+ /* sanity check */
+ if ((startPtr == NULL) || (size < 1)) {
+ return(size);
+ }
+
+ if (data->state.prev_block_had_trailing_cr == TRUE) {
+ /* The previous block of incoming data
+ had a trailing CR, which was turned into a LF. */
+ if (*startPtr == '\n') {
+ /* This block of incoming data starts with the
+ previous block's LF so get rid of it */
+ memcpy(startPtr, startPtr+1, size-1);
+ size--;
+ /* and it wasn't a bare CR but a CRLF conversion instead */
+ data->state.crlf_conversions++;
+ }
+ data->state.prev_block_had_trailing_cr = FALSE; /* reset the flag */
+ }
+
+ /* find 1st CR, if any */
+ inPtr = outPtr = memchr(startPtr, '\r', size);
+ if (inPtr) {
+ /* at least one CR, now look for CRLF */
+ while (inPtr < (startPtr+size-1)) {
+ /* note that it's size-1, so we'll never look past the last byte */
+ if (memcmp(inPtr, "\r\n", 2) == 0) {
+ /* CRLF found, bump past the CR and copy the NL */
+ inPtr++;
+ *outPtr = *inPtr;
+ /* keep track of how many CRLFs we converted */
+ data->state.crlf_conversions++;
+ }
+ else {
+ if (*inPtr == '\r') {
+ /* lone CR, move LF instead */
+ *outPtr = '\n';
+ }
+ else {
+ /* not a CRLF nor a CR, just copy whatever it is */
+ *outPtr = *inPtr;
+ }
+ }
+ outPtr++;
+ inPtr++;
+ } /* end of while loop */
+
+ if (inPtr < startPtr+size) {
+ /* handle last byte */
+ if (*inPtr == '\r') {
+ /* deal with a CR at the end of the buffer */
+ *outPtr = '\n'; /* copy a NL instead */
+ /* note that a CRLF might be split across two blocks */
+ data->state.prev_block_had_trailing_cr = TRUE;
+ }
+ else {
+ /* copy last byte */
+ *outPtr = *inPtr;
+ }
+ outPtr++;
+ inPtr++;
+ }
+ if (outPtr < startPtr+size) {
+ /* tidy up by null terminating the now shorter data */
+ *outPtr = '\0';
+ }
+ return(outPtr - startPtr);
+ }
+ return(size);
+}
+#endif /* CURL_DO_LINEEND_CONV */
+
+/* Curl_infof() is for info message along the way */
+
+void Curl_infof(struct SessionHandle *data, const char *fmt, ...)
+{
+ if(data && data->set.verbose) {
+ va_list ap;
+ size_t len;
+ char print_buffer[1024 + 1];
+ va_start(ap, fmt);
+ vsnprintf(print_buffer, 1024, fmt, ap);
+ va_end(ap);
+ len = strlen(print_buffer);
+ Curl_debug(data, CURLINFO_TEXT, print_buffer, len, NULL);
+ }
+}
+
+/* Curl_failf() is for messages stating why we failed.
+ * The message SHALL NOT include any LF or CR.
+ */
+
+void Curl_failf(struct SessionHandle *data, const char *fmt, ...)
+{
+ va_list ap;
+ size_t len;
+ va_start(ap, fmt);
+
+ vsnprintf(data->state.buffer, BUFSIZE, fmt, ap);
+
+ if(data->set.errorbuffer && !data->state.errorbuf) {
+ snprintf(data->set.errorbuffer, CURL_ERROR_SIZE, "%s", data->state.buffer);
+ data->state.errorbuf = TRUE; /* wrote error string */
+ }
+ if(data->set.verbose) {
+ len = strlen(data->state.buffer);
+ if(len < BUFSIZE - 1) {
+ data->state.buffer[len] = '\n';
+ data->state.buffer[++len] = '\0';
+ }
+ Curl_debug(data, CURLINFO_TEXT, data->state.buffer, len, NULL);
+ }
+
+ va_end(ap);
+}
+
+/* Curl_sendf() sends formated data to the server */
+CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *conn,
+ const char *fmt, ...)
+{
+ struct SessionHandle *data = conn->data;
+ ssize_t bytes_written;
+ size_t write_len;
+ CURLcode res = CURLE_OK;
+ char *s;
+ char *sptr;
+ va_list ap;
+ va_start(ap, fmt);
+ s = vaprintf(fmt, ap); /* returns an allocated string */
+ va_end(ap);
+ if(!s)
+ return CURLE_OUT_OF_MEMORY; /* failure */
+
+ bytes_written=0;
+ write_len = strlen(s);
+ sptr = s;
+
+ while (1) {
+ /* Write the buffer to the socket */
+ res = Curl_write(conn, sockfd, sptr, write_len, &bytes_written);
+
+ if(CURLE_OK != res)
+ break;
+
+ if(data->set.verbose)
+ Curl_debug(data, CURLINFO_DATA_OUT, sptr, (size_t)bytes_written, conn);
+
+ if((size_t)bytes_written != write_len) {
+ /* if not all was written at once, we must advance the pointer, decrease
+ the size left and try again! */
+ write_len -= bytes_written;
+ sptr += bytes_written;
+ }
+ else
+ break;
+ }
+
+ free(s); /* free the output string */
+
+ return res;
+}
+
+static ssize_t Curl_plain_send(struct connectdata *conn,
+ int num,
+ void *mem,
+ size_t len)
+{
+ curl_socket_t sockfd = conn->sock[num];
+ ssize_t bytes_written = swrite(sockfd, mem, len);
+
+ if(-1 == bytes_written) {
+ int err = Curl_sockerrno();
+
+ if(
+#ifdef WSAEWOULDBLOCK
+ /* This is how Windows does it */
+ (WSAEWOULDBLOCK == err)
+#else
+ /* errno may be EWOULDBLOCK or on some systems EAGAIN when it returned
+ due to its inability to send off data without blocking. We therefor
+ treat both error codes the same here */
+ (EWOULDBLOCK == err) || (EAGAIN == err) || (EINTR == err)
+#endif
+ )
+ /* this is just a case of EWOULDBLOCK */
+ bytes_written=0;
+ else
+ failf(conn->data, "Send failure: %s",
+ Curl_strerror(conn, err));
+ }
+ return bytes_written;
+}
+
+/*
+ * Curl_write() is an internal write function that sends data to the
+ * server. Works with plain sockets, SCP, SSL or kerberos.
+ */
+CURLcode Curl_write(struct connectdata *conn,
+ curl_socket_t sockfd,
+ void *mem,
+ size_t len,
+ ssize_t *written)
+{
+ ssize_t bytes_written;
+ CURLcode retcode;
+ int num = (sockfd == conn->sock[SECONDARYSOCKET]);
+
+ if (conn->ssl[num].use)
+ /* only TRUE if SSL enabled */
+ bytes_written = Curl_ssl_send(conn, num, mem, len);
+#ifdef USE_LIBSSH2
+ else if (conn->protocol & PROT_SCP)
+ bytes_written = Curl_scp_send(conn, num, mem, len);
+ else if (conn->protocol & PROT_SFTP)
+ bytes_written = Curl_sftp_send(conn, num, mem, len);
+#endif /* !USE_LIBSSH2 */
+ else if(conn->sec_complete)
+ /* only TRUE if krb4 enabled */
+ bytes_written = Curl_sec_send(conn, num, mem, len);
+ else
+ bytes_written = Curl_plain_send(conn, num, mem, len);
+
+ *written = bytes_written;
+ retcode = (-1 != bytes_written)?CURLE_OK:CURLE_SEND_ERROR;
+
+ return retcode;
+}
+
+/* client_write() sends data to the write callback(s)
+
+ The bit pattern defines to what "streams" to write to. Body and/or header.
+ The defines are in sendf.h of course.
+ */
+CURLcode Curl_client_write(struct connectdata *conn,
+ int type,
+ char *ptr,
+ size_t len)
+{
+ struct SessionHandle *data = conn->data;
+ size_t wrote;
+
+ if (data->state.cancelled) {
+ /* We just suck everything into a black hole */
+ return CURLE_OK;
+ }
+
+ if(0 == len)
+ len = strlen(ptr);
+
+ if(type & CLIENTWRITE_BODY) {
+ if((conn->protocol&PROT_FTP) && conn->proto.ftpc.transfertype == 'A') {
+#ifdef CURL_DOES_CONVERSIONS
+ /* convert from the network encoding */
+ size_t rc;
+ rc = Curl_convert_from_network(data, ptr, len);
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ if(rc != CURLE_OK)
+ return rc;
+#endif /* CURL_DOES_CONVERSIONS */
+
+#ifdef CURL_DO_LINEEND_CONV
+ /* convert end-of-line markers */
+ len = convert_lineends(data, ptr, len);
+#endif /* CURL_DO_LINEEND_CONV */
+ }
+ /* If the previous block of data ended with CR and this block of data is
+ just a NL, then the length might be zero */
+ if (len) {
+ wrote = data->set.fwrite(ptr, 1, len, data->set.out);
+ }
+ else {
+ wrote = len;
+ }
+
+ if(wrote != len) {
+ failf (data, "Failed writing body");
+ return CURLE_WRITE_ERROR;
+ }
+ }
+
+ if((type & CLIENTWRITE_HEADER) &&
+ (data->set.fwrite_header || data->set.writeheader) ) {
+ /*
+ * Write headers to the same callback or to the especially setup
+ * header callback function (added after version 7.7.1).
+ */
+ curl_write_callback writeit=
+ data->set.fwrite_header?data->set.fwrite_header:data->set.fwrite;
+
+ /* Note: The header is in the host encoding
+ regardless of the ftp transfer mode (ASCII/Image) */
+
+ wrote = writeit(ptr, 1, len, data->set.writeheader);
+ if(wrote != len) {
+ failf (data, "Failed writing header");
+ return CURLE_WRITE_ERROR;
+ }
+ }
+
+ return CURLE_OK;
+}
+
+#ifndef MIN
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
+/*
+ * Internal read-from-socket function. This is meant to deal with plain
+ * sockets, SSL sockets and kerberos sockets.
+ *
+ * If the read would block (EWOULDBLOCK) we return -1. Otherwise we return
+ * a regular CURLcode value.
+ */
+int Curl_read(struct connectdata *conn, /* connection data */
+ curl_socket_t sockfd, /* read from this socket */
+ char *buf, /* store read data here */
+ size_t sizerequested, /* max amount to read */
+ ssize_t *n) /* amount bytes read */
+{
+ ssize_t nread;
+ size_t bytesfromsocket = 0;
+ char *buffertofill = NULL;
+ bool pipelining = (bool)(conn->data->multi &&
+ Curl_multi_canPipeline(conn->data->multi));
+
+ /* Set 'num' to 0 or 1, depending on which socket that has been sent here.
+ If it is the second socket, we set num to 1. Otherwise to 0. This lets
+ us use the correct ssl handle. */
+ int num = (sockfd == conn->sock[SECONDARYSOCKET]);
+
+ *n=0; /* reset amount to zero */
+
+ /* If session can pipeline, check connection buffer */
+ if(pipelining) {
+ size_t bytestocopy = MIN(conn->buf_len - conn->read_pos, sizerequested);
+
+ /* Copy from our master buffer first if we have some unread data there*/
+ if (bytestocopy > 0) {
+ memcpy(buf, conn->master_buffer + conn->read_pos, bytestocopy);
+ conn->read_pos += bytestocopy;
+ conn->bits.stream_was_rewound = FALSE;
+
+ *n = (ssize_t)bytestocopy;
+ return CURLE_OK;
+ }
+ /* If we come here, it means that there is no data to read from the buffer,
+ * so we read from the socket */
+ bytesfromsocket = MIN(sizerequested, sizeof(conn->master_buffer));
+ buffertofill = conn->master_buffer;
+ }
+ else {
+ bytesfromsocket = MIN((long)sizerequested, conn->data->set.buffer_size ?
+ conn->data->set.buffer_size : BUFSIZE);
+ buffertofill = buf;
+ }
+
+ if(conn->ssl[num].use) {
+ nread = Curl_ssl_recv(conn, num, buffertofill, bytesfromsocket);
+
+ if(nread == -1) {
+ return -1; /* -1 from Curl_ssl_recv() means EWOULDBLOCK */
+ }
+ }
+#ifdef USE_LIBSSH2
+ else if (conn->protocol & PROT_SCP) {
+ nread = Curl_scp_recv(conn, num, buffertofill, bytesfromsocket);
+ /* TODO: return CURLE_OK also for nread <= 0
+ read failures and timeouts ? */
+ }
+ else if (conn->protocol & PROT_SFTP) {
+ nread = Curl_sftp_recv(conn, num, buffertofill, bytesfromsocket);
+ }
+#endif /* !USE_LIBSSH2 */
+ else {
+ if(conn->sec_complete)
+ nread = Curl_sec_read(conn, sockfd, buffertofill,
+ bytesfromsocket);
+ else
+ nread = sread(sockfd, buffertofill, bytesfromsocket);
+
+ if(-1 == nread) {
+ int err = Curl_sockerrno();
+#ifdef USE_WINSOCK
+ if(WSAEWOULDBLOCK == err)
+#else
+ if((EWOULDBLOCK == err) || (EAGAIN == err) || (EINTR == err))
+#endif
+ return -1;
+ }
+ }
+
+ if (nread >= 0) {
+ if(pipelining) {
+ memcpy(buf, conn->master_buffer, nread);
+ conn->buf_len = nread;
+ conn->read_pos = nread;
+ }
+
+ *n += nread;
+ }
+
+ return CURLE_OK;
+}
+
+/* return 0 on success */
+static int showit(struct SessionHandle *data, curl_infotype type,
+ char *ptr, size_t size)
+{
+ static const char * const s_infotype[CURLINFO_END] = {
+ "* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
+
+#ifdef CURL_DOES_CONVERSIONS
+ char buf[BUFSIZE+1];
+ size_t conv_size = 0;
+
+ switch(type) {
+ case CURLINFO_HEADER_OUT:
+ /* assume output headers are ASCII */
+ /* copy the data into my buffer so the original is unchanged */
+ if (size > BUFSIZE) {
+ size = BUFSIZE; /* truncate if necessary */
+ buf[BUFSIZE] = '\0';
+ }
+ conv_size = size;
+ memcpy(buf, ptr, size);
+ /* Special processing is needed for this block if it
+ * contains both headers and data (separated by CRLFCRLF).
+ * We want to convert just the headers, leaving the data as-is.
+ */
+ if(size > 4) {
+ size_t i;
+ for(i = 0; i < size-4; i++) {
+ if(memcmp(&buf[i], "\x0d\x0a\x0d\x0a", 4) == 0) {
+ /* convert everthing through this CRLFCRLF but no further */
+ conv_size = i + 4;
+ break;
+ }
+ }
+ }
+
+ Curl_convert_from_network(data, buf, conv_size);
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ /* we might as well continue even if it fails... */
+ ptr = buf; /* switch pointer to use my buffer instead */
+ break;
+ default:
+ /* leave everything else as-is */
+ break;
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ if(data->set.fdebug)
+ return (*data->set.fdebug)(data, type, ptr, size,
+ data->set.debugdata);
+
+ switch(type) {
+ case CURLINFO_TEXT:
+ case CURLINFO_HEADER_OUT:
+ case CURLINFO_HEADER_IN:
+ fwrite(s_infotype[type], 2, 1, data->set.err);
+ fwrite(ptr, size, 1, data->set.err);
+#ifdef CURL_DOES_CONVERSIONS
+ if(size != conv_size) {
+ /* we had untranslated data so we need an explicit newline */
+ fwrite("\n", 1, 1, data->set.err);
+ }
+#endif
+ break;
+ default: /* nada */
+ break;
+ }
+ return 0;
+}
+
+int Curl_debug(struct SessionHandle *data, curl_infotype type,
+ char *ptr, size_t size,
+ struct connectdata *conn)
+{
+ int rc;
+ if(data->set.printhost && conn && conn->host.dispname) {
+ char buffer[160];
+ const char *t=NULL;
+ const char *w="Data";
+ switch (type) {
+ case CURLINFO_HEADER_IN:
+ w = "Header";
+ case CURLINFO_DATA_IN:
+ t = "from";
+ break;
+ case CURLINFO_HEADER_OUT:
+ w = "Header";
+ case CURLINFO_DATA_OUT:
+ t = "to";
+ break;
+ default:
+ break;
+ }
+
+ if(t) {
+ snprintf(buffer, sizeof(buffer), "[%s %s %s]", w, t,
+ conn->host.dispname);
+ rc = showit(data, CURLINFO_TEXT, buffer, strlen(buffer));
+ if(rc)
+ return rc;
+ }
+ }
+ rc = showit(data, type, ptr, size);
+ return rc;
+}
diff --git a/Utilities/cmcurl/sendf.h b/Utilities/cmcurl/sendf.h
new file mode 100644
index 0000000000..7877df8233
--- /dev/null
+++ b/Utilities/cmcurl/sendf.h
@@ -0,0 +1,72 @@
+#ifndef __SENDF_H
+#define __SENDF_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *,
+ const char *fmt, ...);
+void Curl_infof(struct SessionHandle *, const char *fmt, ...);
+void Curl_failf(struct SessionHandle *, const char *fmt, ...);
+
+#if defined(CURL_DISABLE_VERBOSE_STRINGS)
+#if defined(__GNUC__)
+/* This style of variable argument macros is a gcc extension */
+#define infof(x...) /*ignore*/
+#else
+/* C99 compilers could use this if we could detect them */
+/*#define infof(...) */
+/* Cast the args to void to make them a noop, side effects notwithstanding */
+#define infof (void)
+#endif
+#else
+#define infof Curl_infof
+#endif
+#define failf Curl_failf
+
+#define CLIENTWRITE_BODY 1
+#define CLIENTWRITE_HEADER 2
+#define CLIENTWRITE_BOTH (CLIENTWRITE_BODY|CLIENTWRITE_HEADER)
+
+CURLcode Curl_client_write(struct connectdata *conn, int type, char *ptr,
+ size_t len);
+
+void Curl_read_rewind(struct connectdata *conn,
+ size_t extraBytesRead);
+
+/* internal read-function, does plain socket, SSL and krb4 */
+int Curl_read(struct connectdata *conn, curl_socket_t sockfd,
+ char *buf, size_t buffersize,
+ ssize_t *n);
+/* internal write-function, does plain socket, SSL and krb4 */
+CURLcode Curl_write(struct connectdata *conn,
+ curl_socket_t sockfd,
+ void *mem, size_t len,
+ ssize_t *written);
+
+/* the function used to output verbose information */
+int Curl_debug(struct SessionHandle *handle, curl_infotype type,
+ char *data, size_t size,
+ struct connectdata *conn);
+
+
+#endif
diff --git a/Utilities/cmcurl/setup.h b/Utilities/cmcurl/setup.h
new file mode 100644
index 0000000000..5ae881fba3
--- /dev/null
+++ b/Utilities/cmcurl/setup.h
@@ -0,0 +1,390 @@
+#ifndef __LIB_CURL_SETUP_H
+#define __LIB_CURL_SETUP_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifdef HTTP_ONLY
+#define CURL_DISABLE_TFTP
+#define CURL_DISABLE_FTP
+#define CURL_DISABLE_LDAP
+#define CURL_DISABLE_TELNET
+#define CURL_DISABLE_DICT
+#define CURL_DISABLE_FILE
+#endif /* HTTP_ONLY */
+
+#if !defined(WIN32) && defined(__WIN32__)
+/* Borland fix */
+#define WIN32
+#endif
+
+#if !defined(WIN32) && defined(_WIN32)
+/* VS2005 on x64 fix */
+#define WIN32
+#endif
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+
+/*
+ * Include configuration script results or hand-crafted
+ * configuration file for platforms which lack config tool.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#else
+
+/*
+#ifdef _WIN32_WCE
+#include "config-win32ce.h"
+#else
+#ifdef WIN32
+#include "config-win32.h"
+#endif
+#endif
+*/
+
+#ifdef macintosh
+#include "config-mac.h"
+#endif
+
+#ifdef AMIGA
+#include "amigaos.h"
+#endif
+
+#ifdef TPF
+#include "config-tpf.h" /* hand-modified TPF config.h */
+/* change which select is used for libcurl */
+#define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
+#endif
+
+#endif /* HAVE_CONFIG_H */
+
+/*
+ * Include header files for windows builds before redefining anything.
+ * Use this preproessor block only to include or exclude windows.h,
+ * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
+ * to any other further and independant block. Under Cygwin things work
+ * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
+ * never be included when __CYGWIN__ is defined. configure script takes
+ * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
+ * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
+ */
+
+#ifdef HAVE_WINDOWS_H
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# ifdef HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+# endif
+# else
+# ifdef HAVE_WINSOCK_H
+# include <winsock.h>
+# endif
+# endif
+#endif
+
+/*
+ * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
+ * define USE_WINSOCK to 1 if we have and use WINSOCK API, else
+ * undefine USE_WINSOCK.
+ */
+
+#undef USE_WINSOCK
+
+#ifdef HAVE_WINSOCK2_H
+# define USE_WINSOCK 2
+#else
+# ifdef HAVE_WINSOCK_H
+# define USE_WINSOCK 1
+# endif
+#endif
+
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#if !defined(__cplusplus) && !defined(__BEOS__) && !defined(__ECOS) && !defined(typedef_bool)
+typedef unsigned char bool;
+#define typedef_bool
+#endif
+
+#ifdef HAVE_LONGLONG
+#define LONG_LONG long long
+#define ENABLE_64BIT
+#else
+#ifdef _MSC_VER
+#define LONG_LONG __int64
+#define ENABLE_64BIT
+#endif /* _MSC_VER */
+#endif /* HAVE_LONGLONG */
+
+#ifndef SIZEOF_CURL_OFF_T
+/* If we don't know the size here, we assume a conservative size: 4. When
+ building libcurl, the actual size of this variable should be define in the
+ config*.h file. */
+#define SIZEOF_CURL_OFF_T 4
+#endif
+
+/* We set up our internal preferred (CURL_)FORMAT_OFF_T here */
+#if SIZEOF_CURL_OFF_T > 4
+#define FORMAT_OFF_T "lld"
+#else
+#define FORMAT_OFF_T "ld"
+#endif /* SIZEOF_CURL_OFF_T */
+
+#ifndef _REENTRANT
+/* Solaris needs _REENTRANT set for a few function prototypes and things to
+ appear in the #include files. We need to #define it before all #include
+ files. Unixware needs it to build proper reentrant code. Others may also
+ need it. */
+#define _REENTRANT
+#endif
+
+#include <stdio.h>
+#ifdef HAVE_ASSERT_H
+#include <assert.h>
+#endif
+#include <errno.h>
+
+#ifdef __TANDEM /* for nsr-tandem-nsk systems */
+#include <floss.h>
+#endif
+
+#ifndef STDC_HEADERS /* no standard C headers! */
+#include <curl/stdcheaders.h>
+#endif
+
+/*
+ * PellesC cludge section (yikes);
+ * - It has 'ssize_t', but it is in <unistd.h>. The way the headers
+ * on Win32 are included, forces me to include this header here.
+ * - sys_nerr, EINTR is missing in v4.0 or older.
+ */
+#ifdef __POCC__
+ #include <sys/types.h>
+ #include <unistd.h>
+ #if (__POCC__ <= 400)
+ #define sys_nerr EILSEQ /* for strerror.c */
+ #define EINTR -1 /* for select.c */
+ #endif
+#endif
+
+/*
+ * Salford-C cludge section (mostly borrowed from wxWidgets).
+ */
+#ifdef __SALFORDC__
+ #pragma suppress 353 /* Possible nested comments */
+ #pragma suppress 593 /* Define not used */
+ #pragma suppress 61 /* enum has no name */
+ #pragma suppress 106 /* unnamed, unused parameter */
+ #include <clib.h>
+#endif
+
+#if defined(CURLDEBUG) && defined(HAVE_ASSERT_H)
+#define curlassert(x) assert(x)
+#else
+/* does nothing without CURLDEBUG defined */
+#define curlassert(x)
+#endif
+
+
+/* To make large file support transparent even on Windows */
+#if defined(WIN32) && (SIZEOF_CURL_OFF_T > 4)
+#include <sys/stat.h> /* must come first before we redefine stat() */
+#include <io.h>
+#define lseek(x,y,z) _lseeki64(x, y, z)
+#define struct_stat struct _stati64
+#define stat(file,st) _stati64(file,st)
+#define fstat(fd,st) _fstati64(fd,st)
+#else
+#define struct_stat struct stat
+#endif /* Win32 with large file support */
+
+
+/* Below we define some functions. They should
+ 1. close a socket
+
+ 4. set the SIGALRM signal timeout
+ 5. set dir/file naming defines
+ */
+
+#ifdef WIN32
+
+#if !defined(__CYGWIN__)
+#define sclose(x) closesocket(x)
+
+#undef HAVE_ALARM
+#else
+ /* gcc-for-win is still good :) */
+#define sclose(x) close(x)
+#define HAVE_ALARM
+#endif /* !GNU or mingw */
+
+#define DIR_CHAR "\\"
+#define DOT_CHAR "_"
+
+#else /* WIN32 */
+
+#ifdef MSDOS /* Watt-32 */
+#include <sys/ioctl.h>
+#define sclose(x) close_s(x)
+#define select(n,r,w,x,t) select_s(n,r,w,x,t)
+#define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
+#define IOCTL_3_ARGS
+#include <tcp.h>
+#ifdef word
+#undef word
+#endif
+
+#else /* MSDOS */
+
+#ifdef __VMS
+#define IOCTL_3_ARGS 1
+#endif
+
+#ifdef __BEOS__
+#define sclose(x) closesocket(x)
+#else /* __BEOS__ */
+#define sclose(x) close(x)
+#endif /* __BEOS__ */
+
+#define HAVE_ALARM
+
+#endif /* MSDOS */
+
+#ifdef _AMIGASF
+#undef HAVE_ALARM
+#undef sclose
+#define sclose(x) CloseSocket(x)
+#endif
+
+#define DIR_CHAR "/"
+#ifndef DOT_CHAR
+#define DOT_CHAR "."
+#endif
+
+#ifdef MSDOS
+#undef DOT_CHAR
+#define DOT_CHAR "_"
+#endif
+
+#ifndef fileno /* sunos 4 have this as a macro! */
+int fileno( FILE *stream);
+#endif
+
+#endif /* WIN32 */
+
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(USE_ARES) && \
+ !defined(__LCC__) /* lcc-win32 doesn't have _beginthreadex() */
+#ifdef ENABLE_IPV6
+#define USE_THREADING_GETADDRINFO
+#else
+#define USE_THREADING_GETHOSTBYNAME /* Cygwin uses alarm() function */
+#endif
+#endif
+
+/* "cl -ML" or "cl -MLd" implies a single-threaded runtime library where
+ _beginthreadex() is not available */
+#if (defined(_MSC_VER) && !defined(__POCC__)) && !defined(_MT) && !defined(USE_ARES)
+#undef USE_THREADING_GETADDRINFO
+#undef USE_THREADING_GETHOSTBYNAME
+#define CURL_NO__BEGINTHREADEX
+#endif
+
+/*
+ * msvc 6.0 does not have struct sockaddr_storage and
+ * does not define IPPROTO_ESP in winsock2.h. But both
+ * are available if PSDK is properly installed.
+ */
+
+#ifdef _MSC_VER
+#if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
+#undef HAVE_STRUCT_SOCKADDR_STORAGE
+#endif
+#endif
+
+#ifdef mpeix
+#define IOCTL_3_ARGS
+#endif
+
+#ifdef NETWARE
+#undef HAVE_ALARM
+#endif
+
+#if defined(HAVE_LIBIDN) && defined(HAVE_TLD_H)
+/* The lib was present and the tld.h header (which is missing in libidn 0.3.X
+ but we only work with libidn 0.4.1 or later) */
+#define USE_LIBIDN
+#endif
+
+#ifndef SIZEOF_TIME_T
+/* assume default size of time_t to be 32 bit */
+#define SIZEOF_TIME_T 4
+#endif
+
+#define LIBIDN_REQUIRED_VERSION "0.4.1"
+
+#ifdef __UCLIBC__
+#define HAVE_INET_NTOA_R_2_ARGS 1
+#endif
+
+#if defined(USE_GNUTLS) || defined(USE_SSLEAY)
+#define USE_SSL /* Either OpenSSL || GnuTLS */
+#endif
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_NTLM)
+#if defined(USE_SSLEAY) || defined(USE_WINDOWS_SSPI)
+#define USE_NTLM
+#endif
+#endif
+
+#ifdef CURLDEBUG
+#define DEBUGF(x) x
+#else
+#define DEBUGF(x)
+#endif
+
+/* non-configure builds may define CURL_WANTS_CA_BUNDLE_ENV */
+#if defined(CURL_WANTS_CA_BUNDLE_ENV) && !defined(CURL_CA_BUNDLE)
+#define CURL_CA_BUNDLE getenv("CURL_CA_BUNDLE")
+#endif
+
+/*
+ * Include macros and defines that should only be processed once.
+ */
+
+#ifndef __SETUP_ONCE_H
+#include "setup_once.h"
+#endif
+
+#endif /* __LIB_CURL_SETUP_H */
diff --git a/Utilities/cmcurl/setup_once.h b/Utilities/cmcurl/setup_once.h
new file mode 100644
index 0000000000..ee68641589
--- /dev/null
+++ b/Utilities/cmcurl/setup_once.h
@@ -0,0 +1,153 @@
+#ifndef __SETUP_ONCE_H
+#define __SETUP_ONCE_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+
+/********************************************************************
+ * NOTICE *
+ * ======== *
+ * *
+ * Content of header files lib/setup_once.h and ares/setup_once.h *
+ * must be kept in sync. Modify the other one if you change this. *
+ * *
+ ********************************************************************/
+
+
+/*
+ * If we have the MSG_NOSIGNAL define, make sure we use
+ * it as the fourth argument of function send()
+ */
+
+#ifdef HAVE_MSG_NOSIGNAL
+#define SEND_4TH_ARG MSG_NOSIGNAL
+#else
+#define SEND_4TH_ARG 0
+#endif
+
+
+/*
+ * The definitions for the return type and arguments types
+ * of functions recv() and send() belong and come from the
+ * configuration file. Do not define them in any other place.
+ *
+ * HAVE_RECV is defined if you have a function named recv()
+ * which is used to read incoming data from sockets. If your
+ * function has another name then don't define HAVE_RECV.
+ *
+ * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
+ * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
+ * be defined.
+ *
+ * HAVE_SEND is defined if you have a function named send()
+ * which is used to write outgoing data on a connected socket.
+ * If yours has another name then don't define HAVE_SEND.
+ *
+ * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
+ * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
+ * SEND_TYPE_RETV must also be defined.
+ */
+
+#ifdef HAVE_RECV
+#if !defined(RECV_TYPE_ARG1) || \
+ !defined(RECV_TYPE_ARG2) || \
+ !defined(RECV_TYPE_ARG3) || \
+ !defined(RECV_TYPE_ARG4) || \
+ !defined(RECV_TYPE_RETV)
+ /* */
+ Error Missing_definition_of_return_and_arguments_types_of_recv
+ /* */
+#else
+#define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
+ (RECV_TYPE_ARG2)(y), \
+ (RECV_TYPE_ARG3)(z), \
+ (RECV_TYPE_ARG4)(0))
+#endif
+#else /* HAVE_RECV */
+#ifndef sread
+ /* */
+ Error Missing_definition_of_macro_sread
+ /* */
+#endif
+#endif /* HAVE_RECV */
+
+#ifdef HAVE_SEND
+#if !defined(SEND_TYPE_ARG1) || \
+ !defined(SEND_QUAL_ARG2) || \
+ !defined(SEND_TYPE_ARG2) || \
+ !defined(SEND_TYPE_ARG3) || \
+ !defined(SEND_TYPE_ARG4) || \
+ !defined(SEND_TYPE_RETV)
+ /* */
+ Error Missing_definition_of_return_and_arguments_types_of_send
+ /* */
+#else
+#define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
+ (SEND_TYPE_ARG2)(y), \
+ (SEND_TYPE_ARG3)(z), \
+ (SEND_TYPE_ARG4)(SEND_4TH_ARG))
+#endif
+#else /* HAVE_SEND */
+#ifndef swrite
+ /* */
+ Error Missing_definition_of_macro_swrite
+ /* */
+#endif
+#endif /* HAVE_SEND */
+
+
+/*
+ * Uppercase macro versions of ANSI/ISO is*() functions/macros which
+ * avoid negative number inputs with argument byte codes > 127.
+ */
+
+#define ISSPACE(x) (isspace((int) ((unsigned char)x)))
+#define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
+#define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
+#define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
+#define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
+#define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
+#define ISPRINT(x) (isprint((int) ((unsigned char)x)))
+
+
+/*
+ * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
+ */
+
+#ifndef HAVE_SIG_ATOMIC_T
+typedef int sig_atomic_t;
+#define HAVE_SIG_ATOMIC_T
+#endif
+
+
+/*
+ * Default return type for signal handlers.
+ */
+
+#ifndef RETSIGTYPE
+#define RETSIGTYPE void
+#endif
+
+
+#endif /* __SETUP_ONCE_H */
+
diff --git a/Utilities/cmcurl/share.c b/Utilities/cmcurl/share.c
new file mode 100644
index 0000000000..de13b60211
--- /dev/null
+++ b/Utilities/cmcurl/share.c
@@ -0,0 +1,219 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <curl/curl.h>
+#include "urldata.h"
+#include "share.h"
+#include "memory.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+CURLSH *
+curl_share_init(void)
+{
+ struct Curl_share *share =
+ (struct Curl_share *)malloc(sizeof(struct Curl_share));
+ if (share) {
+ memset (share, 0, sizeof(struct Curl_share));
+ share->specifier |= (1<<CURL_LOCK_DATA_SHARE);
+ }
+
+ return share;
+}
+
+CURLSHcode
+curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
+{
+ struct Curl_share *share = (struct Curl_share *)sh;
+ va_list param;
+ int type;
+ curl_lock_function lockfunc;
+ curl_unlock_function unlockfunc;
+ void *ptr;
+
+ if (share->dirty)
+ /* don't allow setting options while one or more handles are already
+ using this share */
+ return CURLSHE_IN_USE;
+
+ va_start(param, option);
+
+ switch(option) {
+ case CURLSHOPT_SHARE:
+ /* this is a type this share will share */
+ type = va_arg(param, int);
+ share->specifier |= (1<<type);
+ switch( type ) {
+ case CURL_LOCK_DATA_DNS:
+ if (!share->hostcache) {
+ share->hostcache = Curl_mk_dnscache();
+ if(!share->hostcache)
+ return CURLSHE_NOMEM;
+ }
+ break;
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+ case CURL_LOCK_DATA_COOKIE:
+ if (!share->cookies) {
+ share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE );
+ if(!share->cookies)
+ return CURLSHE_NOMEM;
+ }
+ break;
+#endif /* CURL_DISABLE_HTTP */
+
+ case CURL_LOCK_DATA_SSL_SESSION: /* not supported (yet) */
+ case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */
+
+ default:
+ return CURLSHE_BAD_OPTION;
+ }
+ break;
+
+ case CURLSHOPT_UNSHARE:
+ /* this is a type this share will no longer share */
+ type = va_arg(param, int);
+ share->specifier &= ~(1<<type);
+ switch( type )
+ {
+ case CURL_LOCK_DATA_DNS:
+ if (share->hostcache) {
+ Curl_hash_destroy(share->hostcache);
+ share->hostcache = NULL;
+ }
+ break;
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+ case CURL_LOCK_DATA_COOKIE:
+ if (share->cookies) {
+ Curl_cookie_cleanup(share->cookies);
+ share->cookies = NULL;
+ }
+ break;
+#endif /* CURL_DISABLE_HTTP */
+
+ case CURL_LOCK_DATA_SSL_SESSION:
+ break;
+
+ case CURL_LOCK_DATA_CONNECT:
+ break;
+
+ default:
+ return CURLSHE_BAD_OPTION;
+ }
+ break;
+
+ case CURLSHOPT_LOCKFUNC:
+ lockfunc = va_arg(param, curl_lock_function);
+ share->lockfunc = lockfunc;
+ break;
+
+ case CURLSHOPT_UNLOCKFUNC:
+ unlockfunc = va_arg(param, curl_unlock_function);
+ share->unlockfunc = unlockfunc;
+ break;
+
+ case CURLSHOPT_USERDATA:
+ ptr = va_arg(param, void *);
+ share->clientdata = ptr;
+ break;
+
+ default:
+ return CURLSHE_BAD_OPTION;
+ }
+
+ return CURLSHE_OK;
+}
+
+CURLSHcode
+curl_share_cleanup(CURLSH *sh)
+{
+ struct Curl_share *share = (struct Curl_share *)sh;
+
+ if (share == NULL)
+ return CURLSHE_INVALID;
+
+ if(share->lockfunc)
+ share->lockfunc(NULL, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE,
+ share->clientdata);
+
+ if (share->dirty) {
+ if(share->unlockfunc)
+ share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata);
+ return CURLSHE_IN_USE;
+ }
+
+ if(share->hostcache)
+ Curl_hash_destroy(share->hostcache);
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+ if(share->cookies)
+ Curl_cookie_cleanup(share->cookies);
+#endif /* CURL_DISABLE_HTTP */
+
+ if(share->unlockfunc)
+ share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata);
+ free(share);
+
+ return CURLSHE_OK;
+}
+
+
+CURLSHcode
+Curl_share_lock(struct SessionHandle *data, curl_lock_data type,
+ curl_lock_access accesstype)
+{
+ struct Curl_share *share = data->share;
+
+ if (share == NULL)
+ return CURLSHE_INVALID;
+
+ if(share->specifier & (1<<type)) {
+ if(share->lockfunc) /* only call this if set! */
+ share->lockfunc(data, type, accesstype, share->clientdata);
+ }
+ /* else if we don't share this, pretend successful lock */
+
+ return CURLSHE_OK;
+}
+
+CURLSHcode
+Curl_share_unlock(struct SessionHandle *data, curl_lock_data type)
+{
+ struct Curl_share *share = data->share;
+
+ if (share == NULL)
+ return CURLSHE_INVALID;
+
+ if(share->specifier & (1<<type)) {
+ if(share->unlockfunc) /* only call this if set! */
+ share->unlockfunc (data, type, share->clientdata);
+ }
+
+ return CURLSHE_OK;
+}
diff --git a/Utilities/cmcurl/share.h b/Utilities/cmcurl/share.h
new file mode 100644
index 0000000000..5cfe8c792a
--- /dev/null
+++ b/Utilities/cmcurl/share.h
@@ -0,0 +1,56 @@
+#ifndef __CURL_SHARE_H
+#define __CURL_SHARE_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+#include <curl/curl.h>
+#include "cookie.h"
+
+/* SalfordC says "A structure member may not be volatile". Hence:
+ */
+#ifdef __SALFORDC__
+#define CURL_VOLATILE
+#else
+#define CURL_VOLATILE volatile
+#endif
+
+/* this struct is libcurl-private, don't export details */
+struct Curl_share {
+ unsigned int specifier;
+ CURL_VOLATILE unsigned int dirty;
+
+ curl_lock_function lockfunc;
+ curl_unlock_function unlockfunc;
+ void *clientdata;
+
+ struct curl_hash *hostcache;
+ struct CookieInfo *cookies;
+};
+
+CURLSHcode Curl_share_lock (struct SessionHandle *, curl_lock_data,
+ curl_lock_access);
+CURLSHcode Curl_share_unlock (struct SessionHandle *, curl_lock_data);
+
+#endif /* __CURL_SHARE_H */
diff --git a/Utilities/cmcurl/sockaddr.h b/Utilities/cmcurl/sockaddr.h
new file mode 100644
index 0000000000..78dad4d9ed
--- /dev/null
+++ b/Utilities/cmcurl/sockaddr.h
@@ -0,0 +1,38 @@
+#ifndef __SOCKADDR_H
+#define __SOCKADDR_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
+struct Curl_sockaddr_storage {
+ struct sockaddr_storage buffer;
+};
+#else
+struct Curl_sockaddr_storage {
+ char buffer[256]; /* this should be big enough to fit a lot */
+};
+#endif
+
+#endif /* __SOCKADDR_H */
diff --git a/Utilities/cmcurl/socks.c b/Utilities/cmcurl/socks.c
new file mode 100644
index 0000000000..e0e947b806
--- /dev/null
+++ b/Utilities/cmcurl/socks.c
@@ -0,0 +1,592 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+
+#ifdef NEED_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "strequal.h"
+#include "select.h"
+#include "connect.h"
+#include "timeval.h"
+#include "socks.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/*
+ * Helper read-from-socket functions. Does the same as Curl_read() but it
+ * blocks until all bytes amount of buffersize will be read. No more, no less.
+ *
+ * This is STUPID BLOCKING behaviour which we frown upon, but right now this
+ * is what we have...
+ */
+static int blockread_all(struct connectdata *conn, /* connection data */
+ curl_socket_t sockfd, /* read from this socket */
+ char *buf, /* store read data here */
+ ssize_t buffersize, /* max amount to read */
+ ssize_t *n, /* amount bytes read */
+ long conn_timeout) /* timeout for data wait
+ relative to
+ conn->created */
+{
+ ssize_t nread;
+ ssize_t allread = 0;
+ int result;
+ struct timeval tvnow;
+ long conntime;
+ *n = 0;
+ do {
+ tvnow = Curl_tvnow();
+ /* calculating how long connection is establishing */
+ conntime = Curl_tvdiff(tvnow, conn->created);
+ if(conntime > conn_timeout) {
+ /* we already got the timeout */
+ result = ~CURLE_OK;
+ break;
+ }
+ if(Curl_select(sockfd, CURL_SOCKET_BAD,
+ (int)(conn_timeout - conntime)) <= 0) {
+ result = ~CURLE_OK;
+ break;
+ }
+ result = Curl_read(conn, sockfd, buf, buffersize, &nread);
+ if(result)
+ break;
+
+ if(buffersize == nread) {
+ allread += nread;
+ *n = allread;
+ result = CURLE_OK;
+ break;
+ }
+ buffersize -= nread;
+ buf += nread;
+ allread += nread;
+ } while(1);
+ return result;
+}
+
+/*
+* This function logs in to a SOCKS4 proxy and sends the specifics to the final
+* destination server.
+*
+* Reference :
+* http://socks.permeo.com/protocol/socks4.protocol
+*
+* Note :
+* Nonsupport "SOCKS 4A (Simple Extension to SOCKS 4 Protocol)"
+* Nonsupport "Identification Protocol (RFC1413)"
+*/
+CURLcode Curl_SOCKS4(const char *proxy_name,
+ struct connectdata *conn)
+{
+ unsigned char socksreq[262]; /* room for SOCKS4 request incl. user id */
+ int result;
+ CURLcode code;
+ curl_socket_t sock = conn->sock[FIRSTSOCKET];
+ long timeout;
+ struct SessionHandle *data = conn->data;
+
+ /* get timeout */
+ if(data->set.timeout && data->set.connecttimeout) {
+ if (data->set.timeout < data->set.connecttimeout)
+ timeout = data->set.timeout*1000;
+ else
+ timeout = data->set.connecttimeout*1000;
+ }
+ else if(data->set.timeout)
+ timeout = data->set.timeout*1000;
+ else if(data->set.connecttimeout)
+ timeout = data->set.connecttimeout*1000;
+ else
+ timeout = DEFAULT_CONNECT_TIMEOUT;
+
+ Curl_nonblock(sock, FALSE);
+
+ /*
+ * Compose socks4 request
+ *
+ * Request format
+ *
+ * +----+----+----+----+----+----+----+----+----+----+....+----+
+ * | VN | CD | DSTPORT | DSTIP | USERID |NULL|
+ * +----+----+----+----+----+----+----+----+----+----+....+----+
+ * # of bytes: 1 1 2 4 variable 1
+ */
+
+ socksreq[0] = 4; /* version (SOCKS4) */
+ socksreq[1] = 1; /* connect */
+ *((unsigned short*)&socksreq[2]) = htons(conn->remote_port);
+
+ /* DNS resolve */
+ {
+ struct Curl_dns_entry *dns;
+ Curl_addrinfo *hp=NULL;
+ int rc;
+
+ rc = Curl_resolv(conn, conn->host.name, (int)conn->remote_port, &dns);
+
+ if(rc == CURLRESOLV_ERROR)
+ return CURLE_COULDNT_RESOLVE_PROXY;
+
+ if(rc == CURLRESOLV_PENDING)
+ /* this requires that we're in "wait for resolve" state */
+ rc = Curl_wait_for_resolv(conn, &dns);
+
+ /*
+ * We cannot use 'hostent' as a struct that Curl_resolv() returns. It
+ * returns a Curl_addrinfo pointer that may not always look the same.
+ */
+ if(dns)
+ hp=dns->addr;
+ if (hp) {
+ char buf[64];
+ unsigned short ip[4];
+ Curl_printable_address(hp, buf, sizeof(buf));
+
+ if(4 == sscanf( buf, "%hu.%hu.%hu.%hu",
+ &ip[0], &ip[1], &ip[2], &ip[3])) {
+ /* Set DSTIP */
+ socksreq[4] = (unsigned char)ip[0];
+ socksreq[5] = (unsigned char)ip[1];
+ socksreq[6] = (unsigned char)ip[2];
+ socksreq[7] = (unsigned char)ip[3];
+ }
+ else
+ hp = NULL; /* fail! */
+
+ Curl_resolv_unlock(data, dns); /* not used anymore from now on */
+
+ }
+ if(!hp) {
+ failf(data, "Failed to resolve \"%s\" for SOCKS4 connect.",
+ conn->host.name);
+ return CURLE_COULDNT_RESOLVE_HOST;
+ }
+ }
+
+ /*
+ * This is currently not supporting "Identification Protocol (RFC1413)".
+ */
+ socksreq[8] = 0; /* ensure empty userid is NUL-terminated */
+ if(proxy_name) {
+ size_t plen = strlen(proxy_name);
+ if(plen >= sizeof(socksreq) - 8) {
+ failf(data, "Too long SOCKS proxy name, can't use!\n");
+ return CURLE_COULDNT_CONNECT;
+ }
+ /* copy the proxy name WITH trailing zero */
+ memcpy(socksreq + 8, proxy_name, plen+1);
+ }
+
+ /*
+ * Make connection
+ */
+ {
+ ssize_t actualread;
+ ssize_t written;
+ int packetsize = 9 +
+ (int)strlen((char*)socksreq + 8); /* size including NUL */
+
+ /* Send request */
+ code = Curl_write(conn, sock, (char *)socksreq, packetsize, &written);
+ if ((code != CURLE_OK) || (written != packetsize)) {
+ failf(data, "Failed to send SOCKS4 connect request.");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ packetsize = 8; /* receive data size */
+
+ /* Receive response */
+ result = blockread_all(conn, sock, (char *)socksreq, packetsize,
+ &actualread, timeout);
+ if ((result != CURLE_OK) || (actualread != packetsize)) {
+ failf(data, "Failed to receive SOCKS4 connect request ack.");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ /*
+ * Response format
+ *
+ * +----+----+----+----+----+----+----+----+
+ * | VN | CD | DSTPORT | DSTIP |
+ * +----+----+----+----+----+----+----+----+
+ * # of bytes: 1 1 2 4
+ *
+ * VN is the version of the reply code and should be 0. CD is the result
+ * code with one of the following values:
+ *
+ * 90: request granted
+ * 91: request rejected or failed
+ * 92: request rejected because SOCKS server cannot connect to
+ * identd on the client
+ * 93: request rejected because the client program and identd
+ * report different user-ids
+ */
+
+ /* wrong version ? */
+ if (socksreq[0] != 0) {
+ failf(data,
+ "SOCKS4 reply has wrong version, version should be 4.");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ /* Result */
+ switch(socksreq[1])
+ {
+ case 90:
+ infof(data, "SOCKS4 request granted.\n");
+ break;
+ case 91:
+ failf(data,
+ "Can't complete SOCKS4 connection to %d.%d.%d.%d:%d. (%d)"
+ ", request rejected or failed.",
+ (unsigned char)socksreq[4], (unsigned char)socksreq[5],
+ (unsigned char)socksreq[6], (unsigned char)socksreq[7],
+ (unsigned int)ntohs(*(unsigned short*)(&socksreq[8])),
+ socksreq[1]);
+ return CURLE_COULDNT_CONNECT;
+ case 92:
+ failf(data,
+ "Can't complete SOCKS4 connection to %d.%d.%d.%d:%d. (%d)"
+ ", request rejected because SOCKS server cannot connect to "
+ "identd on the client.",
+ (unsigned char)socksreq[4], (unsigned char)socksreq[5],
+ (unsigned char)socksreq[6], (unsigned char)socksreq[7],
+ (unsigned int)ntohs(*(unsigned short*)(&socksreq[8])),
+ socksreq[1]);
+ return CURLE_COULDNT_CONNECT;
+ case 93:
+ failf(data,
+ "Can't complete SOCKS4 connection to %d.%d.%d.%d:%d. (%d)"
+ ", request rejected because the client program and identd "
+ "report different user-ids.",
+ (unsigned char)socksreq[4], (unsigned char)socksreq[5],
+ (unsigned char)socksreq[6], (unsigned char)socksreq[7],
+ (unsigned int)ntohs(*(unsigned short*)(&socksreq[8])),
+ socksreq[1]);
+ return CURLE_COULDNT_CONNECT;
+ default:
+ failf(data,
+ "Can't complete SOCKS4 connection to %d.%d.%d.%d:%d. (%d)"
+ ", Unknown.",
+ (unsigned char)socksreq[4], (unsigned char)socksreq[5],
+ (unsigned char)socksreq[6], (unsigned char)socksreq[7],
+ (unsigned int)ntohs(*(unsigned short*)(&socksreq[8])),
+ socksreq[1]);
+ return CURLE_COULDNT_CONNECT;
+ }
+ }
+
+ Curl_nonblock(sock, TRUE);
+
+ return CURLE_OK; /* Proxy was successful! */
+}
+
+/*
+ * This function logs in to a SOCKS5 proxy and sends the specifics to the final
+ * destination server.
+ */
+CURLcode Curl_SOCKS5(const char *proxy_name,
+ const char *proxy_password,
+ struct connectdata *conn)
+{
+ /*
+ According to the RFC1928, section "6. Replies". This is what a SOCK5
+ replies:
+
+ +----+-----+-------+------+----------+----------+
+ |VER | REP | RSV | ATYP | BND.ADDR | BND.PORT |
+ +----+-----+-------+------+----------+----------+
+ | 1 | 1 | X'00' | 1 | Variable | 2 |
+ +----+-----+-------+------+----------+----------+
+
+ Where:
+
+ o VER protocol version: X'05'
+ o REP Reply field:
+ o X'00' succeeded
+ */
+
+ unsigned char socksreq[600]; /* room for large user/pw (255 max each) */
+ ssize_t actualread;
+ ssize_t written;
+ int result;
+ CURLcode code;
+ curl_socket_t sock = conn->sock[FIRSTSOCKET];
+ struct SessionHandle *data = conn->data;
+ long timeout;
+
+ /* get timeout */
+ if(data->set.timeout && data->set.connecttimeout) {
+ if (data->set.timeout < data->set.connecttimeout)
+ timeout = data->set.timeout*1000;
+ else
+ timeout = data->set.connecttimeout*1000;
+ }
+ else if(data->set.timeout)
+ timeout = data->set.timeout*1000;
+ else if(data->set.connecttimeout)
+ timeout = data->set.connecttimeout*1000;
+ else
+ timeout = DEFAULT_CONNECT_TIMEOUT;
+
+ Curl_nonblock(sock, TRUE);
+
+ /* wait until socket gets connected */
+ result = Curl_select(CURL_SOCKET_BAD, sock, (int)timeout);
+
+ if(-1 == result) {
+ failf(conn->data, "SOCKS5: no connection here");
+ return CURLE_COULDNT_CONNECT;
+ }
+ else if(0 == result) {
+ failf(conn->data, "SOCKS5: connection timeout");
+ return CURLE_OPERATION_TIMEDOUT;
+ }
+
+ if(result & CSELECT_ERR) {
+ failf(conn->data, "SOCKS5: error occured during connection");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ socksreq[0] = 5; /* version */
+ socksreq[1] = (char)(proxy_name ? 2 : 1); /* number of methods (below) */
+ socksreq[2] = 0; /* no authentication */
+ socksreq[3] = 2; /* username/password */
+
+ Curl_nonblock(sock, FALSE);
+
+ code = Curl_write(conn, sock, (char *)socksreq, (2 + (int)socksreq[1]),
+ &written);
+ if ((code != CURLE_OK) || (written != (2 + (int)socksreq[1]))) {
+ failf(data, "Unable to send initial SOCKS5 request.");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ Curl_nonblock(sock, TRUE);
+
+ result = Curl_select(sock, CURL_SOCKET_BAD, (int)timeout);
+
+ if(-1 == result) {
+ failf(conn->data, "SOCKS5 nothing to read");
+ return CURLE_COULDNT_CONNECT;
+ }
+ else if(0 == result) {
+ failf(conn->data, "SOCKS5 read timeout");
+ return CURLE_OPERATION_TIMEDOUT;
+ }
+
+ if(result & CSELECT_ERR) {
+ failf(conn->data, "SOCKS5 read error occured");
+ return CURLE_RECV_ERROR;
+ }
+
+ Curl_nonblock(sock, FALSE);
+
+ result=blockread_all(conn, sock, (char *)socksreq, 2, &actualread, timeout);
+ if ((result != CURLE_OK) || (actualread != 2)) {
+ failf(data, "Unable to receive initial SOCKS5 response.");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ if (socksreq[0] != 5) {
+ failf(data, "Received invalid version in initial SOCKS5 response.");
+ return CURLE_COULDNT_CONNECT;
+ }
+ if (socksreq[1] == 0) {
+ /* Nothing to do, no authentication needed */
+ ;
+ }
+ else if (socksreq[1] == 2) {
+ /* Needs user name and password */
+ size_t userlen, pwlen;
+ int len;
+ if(proxy_name && proxy_password) {
+ userlen = strlen(proxy_name);
+ pwlen = proxy_password?strlen(proxy_password):0;
+ }
+ else {
+ userlen = 0;
+ pwlen = 0;
+ }
+
+ /* username/password request looks like
+ * +----+------+----------+------+----------+
+ * |VER | ULEN | UNAME | PLEN | PASSWD |
+ * +----+------+----------+------+----------+
+ * | 1 | 1 | 1 to 255 | 1 | 1 to 255 |
+ * +----+------+----------+------+----------+
+ */
+ len = 0;
+ socksreq[len++] = 1; /* username/pw subnegotiation version */
+ socksreq[len++] = (char) userlen;
+ memcpy(socksreq + len, proxy_name, (int) userlen);
+ len += userlen;
+ socksreq[len++] = (char) pwlen;
+ memcpy(socksreq + len, proxy_password, (int) pwlen);
+ len += pwlen;
+
+ code = Curl_write(conn, sock, (char *)socksreq, len, &written);
+ if ((code != CURLE_OK) || (len != written)) {
+ failf(data, "Failed to send SOCKS5 sub-negotiation request.");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ result=blockread_all(conn, sock, (char *)socksreq, 2, &actualread,
+ timeout);
+ if ((result != CURLE_OK) || (actualread != 2)) {
+ failf(data, "Unable to receive SOCKS5 sub-negotiation response.");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ /* ignore the first (VER) byte */
+ if (socksreq[1] != 0) { /* status */
+ failf(data, "User was rejected by the SOCKS5 server (%d %d).",
+ socksreq[0], socksreq[1]);
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ /* Everything is good so far, user was authenticated! */
+ }
+ else {
+ /* error */
+ if (socksreq[1] == 1) {
+ failf(data,
+ "SOCKS5 GSSAPI per-message authentication is not supported.");
+ return CURLE_COULDNT_CONNECT;
+ }
+ else if (socksreq[1] == 255) {
+ if (!proxy_name || !*proxy_name) {
+ failf(data,
+ "No authentication method was acceptable. (It is quite likely"
+ " that the SOCKS5 server wanted a username/password, since none"
+ " was supplied to the server on this connection.)");
+ }
+ else {
+ failf(data, "No authentication method was acceptable.");
+ }
+ return CURLE_COULDNT_CONNECT;
+ }
+ else {
+ failf(data,
+ "Undocumented SOCKS5 mode attempted to be used by server.");
+ return CURLE_COULDNT_CONNECT;
+ }
+ }
+
+ /* Authentication is complete, now specify destination to the proxy */
+ socksreq[0] = 5; /* version (SOCKS5) */
+ socksreq[1] = 1; /* connect */
+ socksreq[2] = 0; /* must be zero */
+ socksreq[3] = 1; /* IPv4 = 1 */
+
+ {
+ struct Curl_dns_entry *dns;
+ Curl_addrinfo *hp=NULL;
+ int rc = Curl_resolv(conn, conn->host.name, (int)conn->remote_port, &dns);
+
+ if(rc == CURLRESOLV_ERROR)
+ return CURLE_COULDNT_RESOLVE_HOST;
+
+ if(rc == CURLRESOLV_PENDING)
+ /* this requires that we're in "wait for resolve" state */
+ rc = Curl_wait_for_resolv(conn, &dns);
+
+ /*
+ * We cannot use 'hostent' as a struct that Curl_resolv() returns. It
+ * returns a Curl_addrinfo pointer that may not always look the same.
+ */
+ if(dns)
+ hp=dns->addr;
+ if (hp) {
+ char buf[64];
+ unsigned short ip[4];
+ Curl_printable_address(hp, buf, sizeof(buf));
+
+ if(4 == sscanf( buf, "%hu.%hu.%hu.%hu",
+ &ip[0], &ip[1], &ip[2], &ip[3])) {
+ socksreq[4] = (unsigned char)ip[0];
+ socksreq[5] = (unsigned char)ip[1];
+ socksreq[6] = (unsigned char)ip[2];
+ socksreq[7] = (unsigned char)ip[3];
+ }
+ else
+ hp = NULL; /* fail! */
+
+ Curl_resolv_unlock(data, dns); /* not used anymore from now on */
+ }
+ if(!hp) {
+ failf(data, "Failed to resolve \"%s\" for SOCKS5 connect.",
+ conn->host.name);
+ return CURLE_COULDNT_RESOLVE_HOST;
+ }
+ }
+
+ *((unsigned short*)&socksreq[8]) = htons(conn->remote_port);
+
+ {
+ const int packetsize = 10;
+
+ code = Curl_write(conn, sock, (char *)socksreq, packetsize, &written);
+ if ((code != CURLE_OK) || (written != packetsize)) {
+ failf(data, "Failed to send SOCKS5 connect request.");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ result = blockread_all(conn, sock, (char *)socksreq, packetsize,
+ &actualread, timeout);
+ if ((result != CURLE_OK) || (actualread != packetsize)) {
+ failf(data, "Failed to receive SOCKS5 connect request ack.");
+ return CURLE_COULDNT_CONNECT;
+ }
+
+ if (socksreq[0] != 5) { /* version */
+ failf(data,
+ "SOCKS5 reply has wrong version, version should be 5.");
+ return CURLE_COULDNT_CONNECT;
+ }
+ if (socksreq[1] != 0) { /* Anything besides 0 is an error */
+ failf(data,
+ "Can't complete SOCKS5 connection to %d.%d.%d.%d:%d. (%d)",
+ (unsigned char)socksreq[4], (unsigned char)socksreq[5],
+ (unsigned char)socksreq[6], (unsigned char)socksreq[7],
+ (unsigned int)ntohs(*(unsigned short*)(&socksreq[8])),
+ socksreq[1]);
+ return CURLE_COULDNT_CONNECT;
+ }
+ }
+
+ Curl_nonblock(sock, TRUE);
+ return CURLE_OK; /* Proxy was successful! */
+}
diff --git a/Utilities/cmcurl/socks.h b/Utilities/cmcurl/socks.h
new file mode 100644
index 0000000000..0da987998a
--- /dev/null
+++ b/Utilities/cmcurl/socks.h
@@ -0,0 +1,41 @@
+#ifndef __SOCKS_H
+#define __SOCKS_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * This function logs in to a SOCKS4 proxy and sends the specifics to the
+ * final destination server.
+ */
+CURLcode Curl_SOCKS4(const char *proxy_name,
+ struct connectdata *conn);
+
+/*
+ * This function logs in to a SOCKS5 proxy and sends the specifics to the
+ * final destination server.
+ */
+CURLcode Curl_SOCKS5(const char *proxy_name,
+ const char *proxy_password,
+ struct connectdata *conn);
+
+#endif
diff --git a/Utilities/cmcurl/speedcheck.c b/Utilities/cmcurl/speedcheck.c
new file mode 100644
index 0000000000..adda8a963b
--- /dev/null
+++ b/Utilities/cmcurl/speedcheck.c
@@ -0,0 +1,75 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <curl/curl.h>
+#include "urldata.h"
+#include "sendf.h"
+#include "multiif.h"
+#include "speedcheck.h"
+
+void Curl_speedinit(struct SessionHandle *data)
+{
+ memset(&data->state.keeps_speed, 0, sizeof(struct timeval));
+}
+
+CURLcode Curl_speedcheck(struct SessionHandle *data,
+ struct timeval now)
+{
+ if((data->progress.current_speed >= 0) &&
+ data->set.low_speed_time &&
+ (Curl_tvlong(data->state.keeps_speed) != 0) &&
+ (data->progress.current_speed < data->set.low_speed_limit)) {
+ long howlong = Curl_tvdiff(now, data->state.keeps_speed);
+
+ /* We are now below the "low speed limit". If we are below it
+ for "low speed time" seconds we consider that enough reason
+ to abort the download. */
+
+ if( (howlong/1000) > data->set.low_speed_time) {
+ /* we have been this slow for long enough, now die */
+ failf(data,
+ "Operation too slow. "
+ "Less than %d bytes/sec transfered the last %d seconds",
+ data->set.low_speed_limit,
+ data->set.low_speed_time);
+ return CURLE_OPERATION_TIMEOUTED;
+ }
+ Curl_expire(data, howlong);
+ }
+ else {
+ /* we keep up the required speed all right */
+ data->state.keeps_speed = now;
+
+ if(data->set.low_speed_limit)
+ /* if there is a low speed limit enabled, we set the expire timer to
+ make this connection's speed get checked again no later than when
+ this time is up */
+ Curl_expire(data, data->set.low_speed_time*1000);
+ }
+ return CURLE_OK;
+}
diff --git a/Utilities/cmcurl/speedcheck.h b/Utilities/cmcurl/speedcheck.h
new file mode 100644
index 0000000000..62475f640e
--- /dev/null
+++ b/Utilities/cmcurl/speedcheck.h
@@ -0,0 +1,34 @@
+#ifndef __SPEEDCHECK_H
+#define __SPEEDCHECK_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include "timeval.h"
+
+void Curl_speedinit(struct SessionHandle *data);
+CURLcode Curl_speedcheck(struct SessionHandle *data,
+ struct timeval now);
+
+#endif
diff --git a/Utilities/cmcurl/splay.c b/Utilities/cmcurl/splay.c
new file mode 100644
index 0000000000..9fb66c76ac
--- /dev/null
+++ b/Utilities/cmcurl/splay.c
@@ -0,0 +1,425 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1997 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "splay.h"
+
+#define compare(i,j) ((i)-(j))
+
+/* Set this to a key value that will *NEVER* appear otherwise */
+#define KEY_NOTUSED -1
+
+/*
+ * Splay using the key i (which may or may not be in the tree.) The starting
+ * root is t.
+ */
+struct Curl_tree *Curl_splay(int i, struct Curl_tree *t)
+{
+ struct Curl_tree N, *l, *r, *y;
+ int comp;
+
+ if (t == NULL)
+ return t;
+ N.smaller = N.larger = NULL;
+ l = r = &N;
+
+ for (;;) {
+ comp = compare(i, t->key);
+ if (comp < 0) {
+ if (t->smaller == NULL)
+ break;
+ if (compare(i, t->smaller->key) < 0) {
+ y = t->smaller; /* rotate smaller */
+ t->smaller = y->larger;
+ y->larger = t;
+ t = y;
+ if (t->smaller == NULL)
+ break;
+ }
+ r->smaller = t; /* link smaller */
+ r = t;
+ t = t->smaller;
+ }
+ else if (comp > 0) {
+ if (t->larger == NULL)
+ break;
+ if (compare(i, t->larger->key) > 0) {
+ y = t->larger; /* rotate larger */
+ t->larger = y->smaller;
+ y->smaller = t;
+ t = y;
+ if (t->larger == NULL)
+ break;
+ }
+ l->larger = t; /* link larger */
+ l = t;
+ t = t->larger;
+ }
+ else
+ break;
+ }
+
+ l->larger = t->smaller; /* assemble */
+ r->smaller = t->larger;
+ t->smaller = N.larger;
+ t->larger = N.smaller;
+
+ return t;
+}
+
+/* Insert key i into the tree t. Return a pointer to the resulting tree or
+ NULL if something went wrong. */
+struct Curl_tree *Curl_splayinsert(int i,
+ struct Curl_tree *t,
+ struct Curl_tree *node)
+{
+ if (node == NULL)
+ return t;
+
+ if (t != NULL) {
+ t = Curl_splay(i,t);
+ if (compare(i, t->key)==0) {
+ /* There already exists a node in the tree with the very same key. Build
+ a linked list of nodes. We make the new 'node' struct the new master
+ node and make the previous node the first one in the 'same' list. */
+
+ node->same = t;
+ node->key = i;
+ node->smaller = t->smaller;
+ node->larger = t->larger;
+
+ t->smaller = node; /* in the sub node for this same key, we use the
+ smaller pointer to point back to the master
+ node */
+
+ t->key = KEY_NOTUSED; /* and we set the key in the sub node to NOTUSED
+ to quickly identify this node as a subnode */
+
+ return node; /* new root node */
+ }
+ }
+
+ if (t == NULL) {
+ node->smaller = node->larger = NULL;
+ }
+ else if (compare(i, t->key) < 0) {
+ node->smaller = t->smaller;
+ node->larger = t;
+ t->smaller = NULL;
+
+ }
+ else {
+ node->larger = t->larger;
+ node->smaller = t;
+ t->larger = NULL;
+ }
+ node->key = i;
+
+ node->same = NULL; /* no identical node (yet) */
+ return node;
+}
+
+#if 0
+/* Deletes 'i' from the tree if it's there (with an exact match). Returns a
+ pointer to the resulting tree.
+
+ Function not used in libcurl.
+*/
+struct Curl_tree *Curl_splayremove(int i, struct Curl_tree *t,
+ struct Curl_tree **removed)
+{
+ struct Curl_tree *x;
+
+ *removed = NULL; /* default to no removed */
+
+ if (t==NULL)
+ return NULL;
+
+ t = Curl_splay(i,t);
+ if (compare(i, t->key) == 0) { /* found it */
+
+ /* FIRST! Check if there is a list with identical sizes */
+ if((x = t->same)) {
+ /* there is, pick one from the list */
+
+ /* 'x' is the new root node */
+
+ x->key = t->key;
+ x->larger = t->larger;
+ x->smaller = t->smaller;
+
+ *removed = t;
+ return x; /* new root */
+ }
+
+ if (t->smaller == NULL) {
+ x = t->larger;
+ }
+ else {
+ x = Curl_splay(i, t->smaller);
+ x->larger = t->larger;
+ }
+ *removed = t;
+
+ return x;
+ }
+ else
+ return t; /* It wasn't there */
+}
+#endif
+
+/* Finds and deletes the best-fit node from the tree. Return a pointer to the
+ resulting tree. best-fit means the node with the given or lower number */
+struct Curl_tree *Curl_splaygetbest(int i, struct Curl_tree *t,
+ struct Curl_tree **removed)
+{
+ struct Curl_tree *x;
+
+ if (!t) {
+ *removed = NULL; /* none removed since there was no root */
+ return NULL;
+ }
+
+ t = Curl_splay(i,t);
+ if(compare(i, t->key) < 0) {
+ /* too big node, try the smaller chain */
+ if(t->smaller)
+ t=Curl_splay(t->smaller->key, t);
+ else {
+ /* fail */
+ *removed = NULL;
+ return t;
+ }
+ }
+
+ if (compare(i, t->key) >= 0) { /* found it */
+ /* FIRST! Check if there is a list with identical sizes */
+ x = t->same;
+ if(x) {
+ /* there is, pick one from the list */
+
+ /* 'x' is the new root node */
+
+ x->key = t->key;
+ x->larger = t->larger;
+ x->smaller = t->smaller;
+
+ *removed = t;
+ return x; /* new root */
+ }
+
+ if (t->smaller == NULL) {
+ x = t->larger;
+ }
+ else {
+ x = Curl_splay(i, t->smaller);
+ x->larger = t->larger;
+ }
+ *removed = t;
+
+ return x;
+ }
+ else {
+ *removed = NULL; /* no match */
+ return t; /* It wasn't there */
+ }
+}
+
+
+/* Deletes the very node we point out from the tree if it's there. Stores a
+ pointer to the new resulting tree in 'newroot'.
+
+ Returns zero on success and non-zero on errors! TODO: document error codes.
+ When returning error, it does not touch the 'newroot' pointer.
+
+ NOTE: when the last node of the tree is removed, there's no tree left so
+ 'newroot' will be made to point to NULL.
+*/
+int Curl_splayremovebyaddr(struct Curl_tree *t,
+ struct Curl_tree *remove,
+ struct Curl_tree **newroot)
+{
+ struct Curl_tree *x;
+
+ if (!t || !remove)
+ return 1;
+
+ if(KEY_NOTUSED == remove->key) {
+ /* Key set to NOTUSED means it is a subnode within a 'same' linked list
+ and thus we can unlink it easily. The 'smaller' link of a subnode
+ links to the parent node. */
+ if (remove->smaller == NULL)
+ return 3;
+
+ remove->smaller->same = remove->same;
+ if(remove->same)
+ remove->same->smaller = remove->smaller;
+
+ /* Ensures that double-remove gets caught. */
+ remove->smaller = NULL;
+
+ /* voila, we're done! */
+ *newroot = t; /* return the same root */
+ return 0;
+ }
+
+ t = Curl_splay(remove->key, t);
+
+ /* First make sure that we got the same root node as the one we want
+ to remove, as otherwise we might be trying to remove a node that
+ isn't actually in the tree.
+
+ We cannot just compare the keys here as a double remove in quick
+ succession of a node with key != KEY_NOTUSED && same != NULL
+ could return the same key but a different node. */
+ if(t != remove)
+ return 2;
+
+ /* Check if there is a list with identical sizes, as then we're trying to
+ remove the root node of a list of nodes with identical keys. */
+ x = t->same;
+ if(x) {
+ /* 'x' is the new root node, we just make it use the root node's
+ smaller/larger links */
+
+ x->key = t->key;
+ x->larger = t->larger;
+ x->smaller = t->smaller;
+ }
+ else {
+ /* Remove the root node */
+ if (t->smaller == NULL)
+ x = t->larger;
+ else {
+ x = Curl_splay(remove->key, t->smaller);
+ x->larger = t->larger;
+ }
+ }
+
+ *newroot = x; /* store new root pointer */
+
+ return 0;
+}
+
+#ifdef CURLDEBUG
+
+void Curl_splayprint(struct Curl_tree * t, int d, char output)
+{
+ struct Curl_tree *node;
+ int i;
+ int count;
+ if (t == NULL)
+ return;
+
+ Curl_splayprint(t->larger, d+1, output);
+ for (i=0; i<d; i++)
+ if(output)
+ printf(" ");
+
+ if(output) {
+ printf("%d[%d]", t->key, i);
+ }
+
+ for(count=0, node = t->same; node; node = node->same, count++)
+ ;
+
+ if(output) {
+ if(count)
+ printf(" [%d more]\n", count);
+ else
+ printf("\n");
+ }
+
+ Curl_splayprint(t->smaller, d+1, output);
+}
+#endif
+
+#ifdef TEST_SPLAY
+
+/*#define TEST2 */
+#define MAX 50
+#define TEST2
+
+/* A sample use of these functions. Start with the empty tree, insert some
+ stuff into it, and then delete it */
+int main(int argc, char **argv)
+{
+ struct Curl_tree *root, *t;
+ void *ptrs[MAX];
+ int adds=0;
+ int rc;
+
+ long sizes[]={
+ 50, 60, 50, 100, 60, 200, 120, 300, 400, 200, 256, 122, 60, 120, 200, 300,
+ 220, 80, 90, 50, 100, 60, 200, 120, 300, 400, 200, 256, 122, 60, 120, 200,
+ 300, 220, 80, 90, 50, 100, 60, 200, 120, 300, 400, 200, 256, 122, 60, 120,
+ 200, 300, 220, 80, 90};
+ int i;
+ root = NULL; /* the empty tree */
+
+ for (i = 0; i < MAX; i++) {
+ int key;
+ ptrs[i] = t = (struct Curl_tree *)malloc(sizeof(struct Curl_tree));
+
+#ifdef TEST2
+ key = sizes[i];
+#elif defined(TEST1)
+ key = (541*i)%1023;
+#elif defined(TEST3)
+ key = 100;
+#endif
+
+ t->payload = (void *)key; /* for simplicity */
+ if(!t) {
+ puts("out of memory!");
+ return 0;
+ }
+ root = Curl_splayinsert(key, root, t);
+ }
+
+#if 0
+ puts("Result:");
+ Curl_splayprint(root, 0, 1);
+#endif
+
+#if 1
+ for (i = 0; i < MAX; i++) {
+ int rem = (i+7)%MAX;
+ struct Curl_tree *r;
+ printf("Tree look:\n");
+ Curl_splayprint(root, 0, 1);
+ printf("remove pointer %d, payload %d\n", rem,
+ (int)((struct Curl_tree *)ptrs[rem])->payload);
+ rc = Curl_splayremovebyaddr(root, (struct Curl_tree *)ptrs[rem], &root);
+ if(rc)
+ /* failed! */
+ printf("remove %d failed!\n", rem);
+ }
+#endif
+
+ return 0;
+}
+
+#endif /* TEST_SPLAY */
diff --git a/Utilities/cmcurl/splay.h b/Utilities/cmcurl/splay.h
new file mode 100644
index 0000000000..16745341e9
--- /dev/null
+++ b/Utilities/cmcurl/splay.h
@@ -0,0 +1,54 @@
+#ifndef __SPLAY_H
+#define __SPLAY_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1997 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+struct Curl_tree {
+ struct Curl_tree *smaller; /* smaller node */
+ struct Curl_tree *larger; /* larger node */
+ struct Curl_tree *same; /* points to a node with identical key */
+ int key; /* the "sort" key */
+ void *payload; /* data the splay code doesn't care about */
+};
+
+struct Curl_tree *Curl_splay(int i, struct Curl_tree *t);
+struct Curl_tree *Curl_splayinsert(int key, struct Curl_tree *t,
+ struct Curl_tree *newnode);
+#if 0
+struct Curl_tree *Curl_splayremove(int key, struct Curl_tree *t,
+ struct Curl_tree **removed);
+#endif
+
+struct Curl_tree *Curl_splaygetbest(int key, struct Curl_tree *t,
+ struct Curl_tree **removed);
+int Curl_splayremovebyaddr(struct Curl_tree *t,
+ struct Curl_tree *remove,
+ struct Curl_tree **newroot);
+
+#ifdef CURLDEBUG
+void Curl_splayprint(struct Curl_tree * t, int d, char output);
+#else
+#define Curl_splayprint(x,y,z)
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/ssh.c b/Utilities/cmcurl/ssh.c
new file mode 100644
index 0000000000..24cba1bac9
--- /dev/null
+++ b/Utilities/cmcurl/ssh.c
@@ -0,0 +1,979 @@
+/***************************************************************************
+* _ _ ____ _
+* Project ___| | | | _ \| |
+* / __| | | | |_) | |
+* | (__| |_| | _ <| |___
+* \___|\___/|_| \_\_____|
+*
+* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+*
+* This software is licensed as described in the file COPYING, which
+* you should have received as part of this distribution. The terms
+* are also available at http://curl.haxx.se/docs/copyright.html.
+*
+* You may opt to use, copy, modify, merge, publish, distribute and/or sell
+* copies of the Software, and permit persons to whom the Software is
+* furnished to do so, under the terms of the COPYING file.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+* $Id$
+***************************************************************************/
+
+/* #define CURL_LIBSSH2_DEBUG */
+
+#include "setup.h"
+
+#ifdef USE_LIBSSH2
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <limits.h>
+
+#include <libssh2.h>
+#include <libssh2_sftp.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
+#ifdef WIN32
+
+#else /* probably some kind of unix */
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <sys/types.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_UTSNAME_H
+#include <sys/utsname.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#endif
+#endif
+
+#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
+#undef in_addr_t
+#define in_addr_t unsigned long
+#endif
+
+#include <curl/curl.h>
+#include "urldata.h"
+#include "sendf.h"
+#include "easyif.h" /* for Curl_convert_... prototypes */
+
+#include "if2ip.h"
+#include "hostip.h"
+#include "progress.h"
+#include "transfer.h"
+#include "escape.h"
+#include "http.h" /* for HTTP proxy tunnel stuff */
+#include "ssh.h"
+#include "url.h"
+#include "speedcheck.h"
+#include "getinfo.h"
+
+#include "strtoofft.h"
+#include "strequal.h"
+#include "sslgen.h"
+#include "connect.h"
+#include "strerror.h"
+#include "memory.h"
+#include "inet_ntop.h"
+#include "select.h"
+#include "parsedate.h" /* for the week day and month names */
+#include "sockaddr.h" /* required for Curl_sockaddr_storage */
+#include "multiif.h"
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#if defined(WIN32) || defined(MSDOS) || defined(__EMX__)
+#define DIRSEP '\\'
+#else
+#define DIRSEP '/'
+#endif
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#ifdef CURLDEBUG
+#include "memdebug.h"
+#endif
+
+#ifndef LIBSSH2_SFTP_S_IRUSR
+/* Here's a work-around for those of you who happend to run a libssh2 version
+ that is 0.14 or older. We should remove this kludge as soon as we can
+ require a more recent libssh2 release. */
+#ifndef S_IRGRP
+#define S_IRGRP 0
+#endif
+
+#ifndef S_IROTH
+#define S_IROTH 0
+#endif
+
+#define LIBSSH2_SFTP_S_IRUSR S_IRUSR
+#define LIBSSH2_SFTP_S_IWUSR S_IWUSR
+#define LIBSSH2_SFTP_S_IRGRP S_IRGRP
+#define LIBSSH2_SFTP_S_IROTH S_IROTH
+#define LIBSSH2_SFTP_S_IRUSR S_IRUSR
+#define LIBSSH2_SFTP_S_IWUSR S_IWUSR
+#define LIBSSH2_SFTP_S_IRGRP S_IRGRP
+#define LIBSSH2_SFTP_S_IROTH S_IROTH
+#define LIBSSH2_SFTP_S_IFMT S_IFMT
+#define LIBSSH2_SFTP_S_IFDIR S_IFDIR
+#define LIBSSH2_SFTP_S_IFLNK S_IFLNK
+#define LIBSSH2_SFTP_S_IFSOCK S_IFSOCK
+#define LIBSSH2_SFTP_S_IFCHR S_IFCHR
+#define LIBSSH2_SFTP_S_IFBLK S_IFBLK
+#define LIBSSH2_SFTP_S_IXUSR S_IXUSR
+#define LIBSSH2_SFTP_S_IWGRP S_IWGRP
+#define LIBSSH2_SFTP_S_IXGRP S_IXGRP
+#define LIBSSH2_SFTP_S_IWOTH S_IWOTH
+#define LIBSSH2_SFTP_S_IXOTH S_IXOTH
+#endif
+
+static LIBSSH2_ALLOC_FUNC(libssh2_malloc);
+static LIBSSH2_REALLOC_FUNC(libssh2_realloc);
+static LIBSSH2_FREE_FUNC(libssh2_free);
+
+static void
+kbd_callback(const char *name, int name_len, const char *instruction,
+ int instruction_len, int num_prompts,
+ const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,
+ LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses,
+ void **abstract)
+{
+ struct SSHPROTO *ssh = (struct SSHPROTO *)*abstract;
+
+#ifdef CURL_LIBSSH2_DEBUG
+ fprintf(stderr, "name=%s\n", name);
+ fprintf(stderr, "name_len=%d\n", name_len);
+ fprintf(stderr, "instruction=%s\n", instruction);
+ fprintf(stderr, "instruction_len=%d\n", instruction_len);
+ fprintf(stderr, "num_prompts=%d\n", num_prompts);
+#else
+ (void)name;
+ (void)name_len;
+ (void)instruction;
+ (void)instruction_len;
+#endif /* CURL_LIBSSH2_DEBUG */
+ if (num_prompts == 1) {
+ responses[0].text = strdup(ssh->passwd);
+ responses[0].length = strlen(ssh->passwd);
+ }
+ (void)prompts;
+ (void)abstract;
+} /* kbd_callback */
+
+static CURLcode libssh2_error_to_CURLE(struct connectdata *conn)
+{
+ int errorcode;
+ struct SSHPROTO *scp = conn->data->reqdata.proto.ssh;
+
+ /* Get the libssh2 error code and string */
+ errorcode = libssh2_session_last_error(scp->ssh_session, &scp->errorstr,
+ NULL, 0);
+ if (errorcode == LIBSSH2_FX_OK)
+ return CURLE_OK;
+
+ infof(conn->data, "libssh2 error %d, '%s'\n", errorcode, scp->errorstr);
+
+ /* TODO: map some of the libssh2 errors to the more appropriate CURLcode
+ error code, and possibly add a few new SSH-related one. We must however
+ not return or even depend on libssh2 errors in the public libcurl API */
+
+ return CURLE_SSH;
+}
+
+static LIBSSH2_ALLOC_FUNC(libssh2_malloc)
+{
+ return malloc(count);
+ (void)abstract;
+}
+
+static LIBSSH2_REALLOC_FUNC(libssh2_realloc)
+{
+ return realloc(ptr, count);
+ (void)abstract;
+}
+
+static LIBSSH2_FREE_FUNC(libssh2_free)
+{
+ free(ptr);
+ (void)abstract;
+}
+
+static CURLcode ssh_init(struct connectdata *conn)
+{
+ struct SessionHandle *data = conn->data;
+ struct SSHPROTO *ssh;
+ if (data->reqdata.proto.ssh)
+ return CURLE_OK;
+
+ ssh = (struct SSHPROTO *)calloc(sizeof(struct SSHPROTO), 1);
+ if (!ssh)
+ return CURLE_OUT_OF_MEMORY;
+
+ data->reqdata.proto.ssh = ssh;
+
+ /* get some initial data into the ssh struct */
+ ssh->bytecountp = &data->reqdata.keep.bytecount;
+
+ /* no need to duplicate them, this connectdata struct won't change */
+ ssh->user = conn->user;
+ ssh->passwd = conn->passwd;
+
+ ssh->errorstr = NULL;
+
+ ssh->ssh_session = NULL;
+ ssh->ssh_channel = NULL;
+ ssh->sftp_session = NULL;
+ ssh->sftp_handle = NULL;
+
+ return CURLE_OK;
+}
+
+/*
+ * Curl_ssh_connect() gets called from Curl_protocol_connect() to allow us to
+ * do protocol-specific actions at connect-time.
+ */
+CURLcode Curl_ssh_connect(struct connectdata *conn, bool *done)
+{
+ int i;
+ struct SSHPROTO *ssh;
+ const char *fingerprint;
+ const char *authlist;
+ char *home;
+ char rsa_pub[PATH_MAX];
+ char rsa[PATH_MAX];
+ char tempHome[PATH_MAX];
+ curl_socket_t sock;
+ char *real_path;
+ char *working_path;
+ int working_path_len;
+ bool authed = FALSE;
+ CURLcode result;
+ struct SessionHandle *data = conn->data;
+
+ rsa_pub[0] = rsa[0] = '\0';
+
+ result = ssh_init(conn);
+ if (result)
+ return result;
+
+ ssh = data->reqdata.proto.ssh;
+
+ working_path = curl_easy_unescape(data, data->reqdata.path, 0,
+ &working_path_len);
+ if (!working_path)
+ return CURLE_OUT_OF_MEMORY;
+
+#ifdef CURL_LIBSSH2_DEBUG
+ if (ssh->user) {
+ infof(data, "User: %s\n", ssh->user);
+ }
+ if (ssh->passwd) {
+ infof(data, "Password: %s\n", ssh->passwd);
+ }
+#endif /* CURL_LIBSSH2_DEBUG */
+ sock = conn->sock[FIRSTSOCKET];
+ ssh->ssh_session = libssh2_session_init_ex(libssh2_malloc, libssh2_free,
+ libssh2_realloc, ssh);
+ if (ssh->ssh_session == NULL) {
+ failf(data, "Failure initialising ssh session\n");
+ Curl_safefree(ssh->path);
+ return CURLE_FAILED_INIT;
+ }
+#ifdef CURL_LIBSSH2_DEBUG
+ infof(data, "SSH socket: %d\n", sock);
+#endif /* CURL_LIBSSH2_DEBUG */
+
+ if (libssh2_session_startup(ssh->ssh_session, sock)) {
+ failf(data, "Failure establishing ssh session\n");
+ libssh2_session_free(ssh->ssh_session);
+ ssh->ssh_session = NULL;
+ Curl_safefree(ssh->path);
+ return CURLE_FAILED_INIT;
+ }
+
+ /*
+ * Before we authenticate we should check the hostkey's fingerprint against
+ * our known hosts. How that is handled (reading from file, whatever) is
+ * up to us. As for know not much is implemented, besides showing how to
+ * get the fingerprint.
+ */
+ fingerprint = libssh2_hostkey_hash(ssh->ssh_session,
+ LIBSSH2_HOSTKEY_HASH_MD5);
+
+#ifdef CURL_LIBSSH2_DEBUG
+ /* The fingerprint points to static storage (!), don't free() it. */
+ infof(data, "Fingerprint: ");
+ for (i = 0; i < 16; i++) {
+ infof(data, "%02X ", (unsigned char) fingerprint[i]);
+ }
+ infof(data, "\n");
+#endif /* CURL_LIBSSH2_DEBUG */
+
+ /* TBD - methods to check the host keys need to be done */
+
+ /*
+ * Figure out authentication methods
+ * NB: As soon as we have provided a username to an openssh server we must
+ * never change it later. Thus, always specify the correct username here,
+ * even though the libssh2 docs kind of indicate that it should be possible
+ * to get a 'generic' list (not user-specific) of authentication methods,
+ * presumably with a blank username. That won't work in my experience.
+ * So always specify it here.
+ */
+ authlist = libssh2_userauth_list(ssh->ssh_session, ssh->user,
+ strlen(ssh->user));
+
+ /*
+ * Check the supported auth types in the order I feel is most secure with the
+ * requested type of authentication
+ */
+ if ((data->set.ssh_auth_types & CURLSSH_AUTH_PUBLICKEY) &&
+ (strstr(authlist, "publickey") != NULL)) {
+ /* To ponder about: should really the lib be messing about with the HOME
+ environment variable etc? */
+ home = curl_getenv("HOME");
+
+ if (data->set.ssh_public_key)
+ snprintf(rsa_pub, sizeof(rsa_pub), "%s", data->set.ssh_public_key);
+ else if (home)
+ snprintf(rsa_pub, sizeof(rsa_pub), "%s/.ssh/id_dsa.pub", home);
+
+ if (data->set.ssh_private_key)
+ snprintf(rsa, sizeof(rsa), "%s", data->set.ssh_private_key);
+ else if (home)
+ snprintf(rsa, sizeof(rsa), "%s/.ssh/id_dsa", home);
+
+ curl_free(home);
+
+ if (rsa_pub[0]) {
+ /* The function below checks if the files exists, no need to stat() here.
+ */
+ if (libssh2_userauth_publickey_fromfile(ssh->ssh_session, ssh->user,
+ rsa_pub, rsa, "") == 0) {
+ authed = TRUE;
+ }
+ }
+ }
+ if (!authed &&
+ (data->set.ssh_auth_types & CURLSSH_AUTH_PASSWORD) &&
+ (strstr(authlist, "password") != NULL)) {
+ if (!libssh2_userauth_password(ssh->ssh_session, ssh->user, ssh->passwd))
+ authed = TRUE;
+ }
+ if (!authed && (data->set.ssh_auth_types & CURLSSH_AUTH_HOST) &&
+ (strstr(authlist, "hostbased") != NULL)) {
+ }
+ if (!authed && (data->set.ssh_auth_types & CURLSSH_AUTH_KEYBOARD)
+ && (strstr(authlist, "keyboard-interactive") != NULL)) {
+ /* Authentication failed. Continue with keyboard-interactive now. */
+ if (libssh2_userauth_keyboard_interactive_ex(ssh->ssh_session, ssh->user,
+ strlen(ssh->user),
+ &kbd_callback) == 0) {
+ authed = TRUE;
+ }
+ }
+
+ if (!authed) {
+ failf(data, "Authentication failure\n");
+ libssh2_session_free(ssh->ssh_session);
+ ssh->ssh_session = NULL;
+ Curl_safefree(ssh->path);
+ return CURLE_FAILED_INIT;
+ }
+
+ /*
+ * At this point we have an authenticated ssh session.
+ */
+ conn->sockfd = sock;
+ conn->writesockfd = CURL_SOCKET_BAD;
+
+ if (conn->protocol == PROT_SFTP) {
+ /*
+ * Start the libssh2 sftp session
+ */
+ ssh->sftp_session = libssh2_sftp_init(ssh->ssh_session);
+ if (ssh->sftp_session == NULL) {
+ failf(data, "Failure initialising sftp session\n");
+ libssh2_sftp_shutdown(ssh->sftp_session);
+ ssh->sftp_session = NULL;
+ libssh2_session_free(ssh->ssh_session);
+ ssh->ssh_session = NULL;
+ return CURLE_FAILED_INIT;
+ }
+
+ /*
+ * Get the "home" directory
+ */
+ i = libssh2_sftp_realpath(ssh->sftp_session, ".", tempHome, PATH_MAX-1);
+ if (i > 0) {
+ /* It seems that this string is not always NULL terminated */
+ tempHome[i] = '\0';
+ ssh->homedir = (char *)strdup(tempHome);
+ if (!ssh->homedir) {
+ libssh2_sftp_shutdown(ssh->sftp_session);
+ ssh->sftp_session = NULL;
+ libssh2_session_free(ssh->ssh_session);
+ ssh->ssh_session = NULL;
+ return CURLE_OUT_OF_MEMORY;
+ }
+ }
+ else {
+ /* Return the error type */
+ i = libssh2_sftp_last_error(ssh->sftp_session);
+ DEBUGF(infof(data, "error = %d\n", i));
+ }
+ }
+
+ /* Check for /~/ , indicating realative to the users home directory */
+ if (conn->protocol == PROT_SCP) {
+ real_path = (char *)malloc(working_path_len+1);
+ if (real_path == NULL) {
+ Curl_safefree(working_path);
+ libssh2_session_free(ssh->ssh_session);
+ ssh->ssh_session = NULL;
+ return CURLE_OUT_OF_MEMORY;
+ }
+ if (working_path[1] == '~')
+ /* It is referenced to the home directory, so strip the leading '/' */
+ memcpy(real_path, working_path+1, 1 + working_path_len-1);
+ else
+ memcpy(real_path, working_path, 1 + working_path_len);
+ }
+ else if (conn->protocol == PROT_SFTP) {
+ if (working_path[1] == '~') {
+ real_path = (char *)malloc(strlen(ssh->homedir) +
+ working_path_len + 1);
+ if (real_path == NULL) {
+ libssh2_sftp_shutdown(ssh->sftp_session);
+ ssh->sftp_session = NULL;
+ libssh2_session_free(ssh->ssh_session);
+ ssh->ssh_session = NULL;
+ Curl_safefree(working_path);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ /* It is referenced to the home directory, so strip the leading '/' */
+ memcpy(real_path, ssh->homedir, strlen(ssh->homedir));
+ real_path[strlen(ssh->homedir)] = '/';
+ real_path[strlen(ssh->homedir)+1] = '\0';
+ if (working_path_len > 3) {
+ memcpy(real_path+strlen(ssh->homedir)+1, working_path + 3,
+ 1 + working_path_len -3);
+ }
+ }
+ else {
+ real_path = (char *)malloc(working_path_len+1);
+ if (real_path == NULL) {
+ libssh2_session_free(ssh->ssh_session);
+ ssh->ssh_session = NULL;
+ Curl_safefree(working_path);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ memcpy(real_path, working_path, 1+working_path_len);
+ }
+ }
+ else
+ return CURLE_FAILED_INIT;
+
+ Curl_safefree(working_path);
+ ssh->path = real_path;
+
+ *done = TRUE;
+ return CURLE_OK;
+}
+
+CURLcode Curl_scp_do(struct connectdata *conn, bool *done)
+{
+ struct stat sb;
+ struct SSHPROTO *scp = conn->data->reqdata.proto.ssh;
+ CURLcode res = CURLE_OK;
+
+ *done = TRUE; /* unconditionally */
+
+ if (conn->data->set.upload) {
+ /*
+ * NOTE!!! libssh2 requires that the destination path is a full path
+ * that includes the destination file and name OR ends in a "/" .
+ * If this is not done the destination file will be named the
+ * same name as the last directory in the path.
+ */
+ scp->ssh_channel = libssh2_scp_send_ex(scp->ssh_session, scp->path,
+ LIBSSH2_SFTP_S_IRUSR|
+ LIBSSH2_SFTP_S_IWUSR|
+ LIBSSH2_SFTP_S_IRGRP|
+ LIBSSH2_SFTP_S_IROTH,
+ conn->data->set.infilesize, 0, 0);
+ if (!scp->ssh_channel)
+ return CURLE_FAILED_INIT;
+
+ /* upload data */
+ res = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
+ }
+ else {
+ /*
+ * We must check the remote file, if it is a directory no vaules will
+ * be set in sb
+ */
+ curl_off_t bytecount;
+ memset(&sb, 0, sizeof(struct stat));
+ scp->ssh_channel = libssh2_scp_recv(scp->ssh_session, scp->path, &sb);
+ if (!scp->ssh_channel) {
+ if ((sb.st_mode == 0) && (sb.st_atime == 0) && (sb.st_mtime == 0) &&
+ (sb.st_size == 0)) {
+ /* Since sb is still empty, it is likely the file was not found */
+ return CURLE_REMOTE_FILE_NOT_FOUND;
+ }
+ return libssh2_error_to_CURLE(conn);
+ }
+ /* download data */
+ bytecount = (curl_off_t) sb.st_size;
+ conn->data->reqdata.maxdownload = (curl_off_t) sb.st_size;
+ res = Curl_setup_transfer(conn, FIRSTSOCKET,
+ bytecount, FALSE, NULL, -1, NULL);
+ }
+
+ return res;
+}
+
+CURLcode Curl_scp_done(struct connectdata *conn, CURLcode status,
+ bool premature)
+{
+ struct SSHPROTO *scp = conn->data->reqdata.proto.ssh;
+ (void)premature; /* not used */
+
+ Curl_safefree(scp->path);
+ scp->path = NULL;
+
+ if (scp->ssh_channel) {
+ if (libssh2_channel_close(scp->ssh_channel) < 0) {
+ infof(conn->data, "Failed to stop libssh2 channel subsystem\n");
+ }
+ }
+
+ if (scp->ssh_session) {
+ libssh2_session_disconnect(scp->ssh_session, "Shutdown");
+ libssh2_session_free(scp->ssh_session);
+ scp->ssh_session = NULL;
+ }
+
+ free(conn->data->reqdata.proto.ssh);
+ conn->data->reqdata.proto.ssh = NULL;
+ Curl_pgrsDone(conn);
+
+ (void)status; /* unused */
+
+ return CURLE_OK;
+}
+
+/* return number of received (decrypted) bytes */
+ssize_t Curl_scp_send(struct connectdata *conn, int sockindex,
+ void *mem, size_t len)
+{
+ ssize_t nwrite;
+
+ /* libssh2_channel_write() returns int
+ *
+ * NOTE: we should not store nor rely on connection-related data to be
+ * in the SessionHandle struct
+ */
+ nwrite = (ssize_t)
+ libssh2_channel_write(conn->data->reqdata.proto.ssh->ssh_channel,
+ mem, len);
+ (void)sockindex;
+ return nwrite;
+}
+
+/*
+ * If the read would block (EWOULDBLOCK) we return -1. Otherwise we return
+ * a regular CURLcode value.
+ */
+ssize_t Curl_scp_recv(struct connectdata *conn, int sockindex,
+ char *mem, size_t len)
+{
+ ssize_t nread;
+
+ /* libssh2_channel_read() returns int
+ *
+ * NOTE: we should not store nor rely on connection-related data to be
+ * in the SessionHandle struct
+ */
+
+ nread = (ssize_t)
+ libssh2_channel_read(conn->data->reqdata.proto.ssh->ssh_channel,
+ mem, len);
+ (void)sockindex;
+ return nread;
+}
+
+/*
+ * =============== SFTP ===============
+ */
+
+CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
+{
+ LIBSSH2_SFTP_ATTRIBUTES attrs;
+ struct SSHPROTO *sftp = conn->data->reqdata.proto.ssh;
+ CURLcode res = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ curl_off_t bytecount = 0;
+ char *buf = data->state.buffer;
+
+ *done = TRUE; /* unconditionally */
+
+ if (data->set.upload) {
+ /*
+ * NOTE!!! libssh2 requires that the destination path is a full path
+ * that includes the destination file and name OR ends in a "/" .
+ * If this is not done the destination file will be named the
+ * same name as the last directory in the path.
+ */
+ sftp->sftp_handle =
+ libssh2_sftp_open(sftp->sftp_session, sftp->path,
+ LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT,
+ LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
+ LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
+ if (!sftp->sftp_handle)
+ return CURLE_FAILED_INIT;
+
+ /* upload data */
+ res = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
+ }
+ else {
+ if (sftp->path[strlen(sftp->path)-1] == '/') {
+ /*
+ * This is a directory that we are trying to get, so produce a
+ * directory listing
+ *
+ * **BLOCKING behaviour** This should be made into a state machine and
+ * get a separate function called from Curl_sftp_recv() when there is
+ * data to read from the network, instead of "hanging" here.
+ */
+ char filename[PATH_MAX+1];
+ int len, totalLen, currLen;
+ char *line;
+
+ sftp->sftp_handle =
+ libssh2_sftp_opendir(sftp->sftp_session, sftp->path);
+ if (!sftp->sftp_handle)
+ return CURLE_SSH;
+
+ while ((len = libssh2_sftp_readdir(sftp->sftp_handle, filename,
+ PATH_MAX, &attrs)) > 0) {
+ filename[len] = '\0';
+
+ if (data->set.ftp_list_only) {
+ if ((attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) &&
+ ((attrs.permissions & LIBSSH2_SFTP_S_IFMT) ==
+ LIBSSH2_SFTP_S_IFDIR)) {
+ infof(data, "%s\n", filename);
+ }
+ }
+ else {
+ totalLen = 80 + len;
+ line = (char *)malloc(totalLen);
+ if (!line)
+ return CURLE_OUT_OF_MEMORY;
+
+ if (!(attrs.flags & LIBSSH2_SFTP_ATTR_UIDGID))
+ attrs.uid = attrs.gid =0;
+
+ currLen = snprintf(line, totalLen, "---------- 1 %5d %5d",
+ attrs.uid, attrs.gid);
+
+ if (attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
+ if ((attrs.permissions & LIBSSH2_SFTP_S_IFMT) ==
+ LIBSSH2_SFTP_S_IFDIR) {
+ line[0] = 'd';
+ }
+ else if ((attrs.permissions & LIBSSH2_SFTP_S_IFMT) ==
+ LIBSSH2_SFTP_S_IFLNK) {
+ line[0] = 'l';
+ }
+ else if ((attrs.permissions & LIBSSH2_SFTP_S_IFMT) ==
+ LIBSSH2_SFTP_S_IFSOCK) {
+ line[0] = 's';
+ }
+ else if ((attrs.permissions & LIBSSH2_SFTP_S_IFMT) ==
+ LIBSSH2_SFTP_S_IFCHR) {
+ line[0] = 'c';
+ }
+ else if ((attrs.permissions & LIBSSH2_SFTP_S_IFMT) ==
+ LIBSSH2_SFTP_S_IFBLK) {
+ line[0] = 'b';
+ }
+ if (attrs.permissions & LIBSSH2_SFTP_S_IRUSR) {
+ line[1] = 'r';
+ }
+ if (attrs.permissions & LIBSSH2_SFTP_S_IWUSR) {
+ line[2] = 'w';
+ }
+ if (attrs.permissions & LIBSSH2_SFTP_S_IXUSR) {
+ line[3] = 'x';
+ }
+ if (attrs.permissions & LIBSSH2_SFTP_S_IRGRP) {
+ line[4] = 'r';
+ }
+ if (attrs.permissions & LIBSSH2_SFTP_S_IWGRP) {
+ line[5] = 'w';
+ }
+ if (attrs.permissions & LIBSSH2_SFTP_S_IXGRP) {
+ line[6] = 'x';
+ }
+ if (attrs.permissions & LIBSSH2_SFTP_S_IROTH) {
+ line[7] = 'r';
+ }
+ if (attrs.permissions & LIBSSH2_SFTP_S_IWOTH) {
+ line[8] = 'w';
+ }
+ if (attrs.permissions & LIBSSH2_SFTP_S_IXOTH) {
+ line[9] = 'x';
+ }
+ }
+ if (attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) {
+ currLen += snprintf(line+currLen, totalLen-currLen, "%11lld",
+ attrs.filesize);
+ }
+ if (attrs.flags & LIBSSH2_SFTP_ATTR_ACMODTIME) {
+ const char *months[12] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+ struct tm *nowParts;
+ time_t now, remoteTime;
+
+ now = time(NULL);
+ remoteTime = (time_t)attrs.mtime;
+ nowParts = localtime(&remoteTime);
+
+ if ((time_t)attrs.mtime > (now - (3600 * 24 * 180))) {
+ currLen += snprintf(line+currLen, totalLen-currLen,
+ " %s %2d %2d:%02d", months[nowParts->tm_mon],
+ nowParts->tm_mday, nowParts->tm_hour,
+ nowParts->tm_min);
+ }
+ else {
+ currLen += snprintf(line+currLen, totalLen-currLen,
+ " %s %2d %5d", months[nowParts->tm_mon],
+ nowParts->tm_mday, 1900+nowParts->tm_year);
+ }
+ }
+ currLen += snprintf(line+currLen, totalLen-currLen, " %s", filename);
+ if ((attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) &&
+ ((attrs.permissions & LIBSSH2_SFTP_S_IFMT) ==
+ LIBSSH2_SFTP_S_IFLNK)) {
+ char linkPath[PATH_MAX + 1];
+
+ snprintf(linkPath, PATH_MAX, "%s%s", sftp->path, filename);
+ len = libssh2_sftp_readlink(sftp->sftp_session, linkPath, filename,
+ PATH_MAX);
+ line = realloc(line, totalLen + 4 + len);
+ if (!line)
+ return CURLE_OUT_OF_MEMORY;
+
+ currLen += snprintf(line+currLen, totalLen-currLen, " -> %s",
+ filename);
+ }
+
+ currLen += snprintf(line+currLen, totalLen-currLen, "\n");
+ res = Curl_client_write(conn, CLIENTWRITE_BODY, line, 0);
+ free(line);
+ }
+ }
+ libssh2_sftp_closedir(sftp->sftp_handle);
+ sftp->sftp_handle = NULL;
+
+ /* no data to transfer */
+ res = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ }
+ else {
+ /*
+ * Work on getting the specified file
+ */
+ sftp->sftp_handle =
+ libssh2_sftp_open(sftp->sftp_session, sftp->path, LIBSSH2_FXF_READ,
+ LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
+ LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
+ if (!sftp->sftp_handle)
+ return CURLE_SSH;
+
+ if (libssh2_sftp_stat(sftp->sftp_session, sftp->path, &attrs)) {
+ /*
+ * libssh2_sftp_open() didn't return an error, so maybe the server
+ * just doesn't support stat()
+ */
+ data->reqdata.size = -1;
+ data->reqdata.maxdownload = -1;
+ }
+ else {
+ data->reqdata.size = attrs.filesize;
+ data->reqdata.maxdownload = attrs.filesize;
+ Curl_pgrsSetDownloadSize(data, attrs.filesize);
+ }
+
+ Curl_pgrsTime(data, TIMER_STARTTRANSFER);
+
+ /* Now download data. The libssh2 0.14 doesn't offer any way to do this
+ without using this BLOCKING approach, so here's room for improvement
+ once libssh2 can return EWOULDBLOCK to us. */
+#if 0
+ /* code left here just because this is what this function will use the
+ day libssh2 is improved */
+ res = Curl_setup_transfer(conn, FIRSTSOCKET,
+ bytecount, FALSE, NULL, -1, NULL);
+#endif
+ while (res == CURLE_OK) {
+ size_t nread;
+ /* NOTE: most *read() functions return ssize_t but this returns size_t
+ which normally is unsigned! */
+ nread = libssh2_sftp_read(data->reqdata.proto.ssh->sftp_handle,
+ buf, BUFSIZE-1);
+
+ if (nread > 0)
+ buf[nread] = 0;
+
+ /* this check can be changed to a <= 0 when nread is changed to a
+ signed variable type */
+ if ((nread == 0) || (nread == (size_t)~0))
+ break;
+
+ bytecount += nread;
+
+ res = Curl_client_write(conn, CLIENTWRITE_BODY, buf, nread);
+ if(res)
+ return res;
+
+ Curl_pgrsSetDownloadCounter(data, bytecount);
+
+ if(Curl_pgrsUpdate(conn))
+ res = CURLE_ABORTED_BY_CALLBACK;
+ else {
+ struct timeval now = Curl_tvnow();
+ res = Curl_speedcheck(data, now);
+ }
+ }
+ if(Curl_pgrsUpdate(conn))
+ res = CURLE_ABORTED_BY_CALLBACK;
+
+ /* no (more) data to transfer */
+ res = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ }
+ }
+
+ return res;
+}
+
+CURLcode Curl_sftp_done(struct connectdata *conn, CURLcode status,
+ bool premature)
+{
+ struct SSHPROTO *sftp = conn->data->reqdata.proto.ssh;
+ (void)premature; /* not used */
+
+ Curl_safefree(sftp->path);
+ sftp->path = NULL;
+
+ Curl_safefree(sftp->homedir);
+ sftp->homedir = NULL;
+
+ if (sftp->sftp_handle) {
+ if (libssh2_sftp_close(sftp->sftp_handle) < 0) {
+ infof(conn->data, "Failed to close libssh2 file\n");
+ }
+ }
+
+ if (sftp->sftp_session) {
+ if (libssh2_sftp_shutdown(sftp->sftp_session) < 0) {
+ infof(conn->data, "Failed to stop libssh2 sftp subsystem\n");
+ }
+ }
+
+ if (sftp->ssh_channel) {
+ if (libssh2_channel_close(sftp->ssh_channel) < 0) {
+ infof(conn->data, "Failed to stop libssh2 channel subsystem\n");
+ }
+ }
+
+ if (sftp->ssh_session) {
+ libssh2_session_disconnect(sftp->ssh_session, "Shutdown");
+ libssh2_session_free(sftp->ssh_session);
+ sftp->ssh_session = NULL;
+ }
+
+ free(conn->data->reqdata.proto.ssh);
+ conn->data->reqdata.proto.ssh = NULL;
+ Curl_pgrsDone(conn);
+
+ (void)status; /* unused */
+
+ return CURLE_OK;
+}
+
+/* return number of received (decrypted) bytes */
+ssize_t Curl_sftp_send(struct connectdata *conn, int sockindex,
+ void *mem, size_t len)
+{
+ ssize_t nwrite;
+
+ /* libssh2_sftp_write() returns size_t !*/
+
+ nwrite = (ssize_t)
+ libssh2_sftp_write(conn->data->reqdata.proto.ssh->sftp_handle, mem, len);
+ (void)sockindex;
+ return nwrite;
+}
+
+/*
+ * If the read would block (EWOULDBLOCK) we return -1. Otherwise we return
+ * a regular CURLcode value.
+ */
+ssize_t Curl_sftp_recv(struct connectdata *conn, int sockindex,
+ char *mem, size_t len)
+{
+ ssize_t nread;
+
+ /* libssh2_sftp_read() returns size_t !*/
+
+ nread = (ssize_t)
+ libssh2_sftp_read(conn->data->reqdata.proto.ssh->sftp_handle, mem, len);
+ (void)sockindex;
+ return nread;
+}
+
+#endif /* USE_LIBSSH2 */
diff --git a/Utilities/cmcurl/ssh.h b/Utilities/cmcurl/ssh.h
new file mode 100644
index 0000000000..d9144903ba
--- /dev/null
+++ b/Utilities/cmcurl/ssh.h
@@ -0,0 +1,49 @@
+#ifndef __SSH_H
+#define __SSH_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifdef USE_LIBSSH2
+
+CURLcode Curl_ssh_connect(struct connectdata *conn, bool *done);
+
+CURLcode Curl_scp_do(struct connectdata *conn, bool *done);
+CURLcode Curl_scp_done(struct connectdata *conn, CURLcode, bool premature);
+
+ssize_t Curl_scp_send(struct connectdata *conn, int sockindex,
+ void *mem, size_t len);
+ssize_t Curl_scp_recv(struct connectdata *conn, int sockindex,
+ char *mem, size_t len);
+
+CURLcode Curl_sftp_do(struct connectdata *conn, bool *done);
+CURLcode Curl_sftp_done(struct connectdata *conn, CURLcode, bool premature);
+
+ssize_t Curl_sftp_send(struct connectdata *conn, int sockindex,
+ void *mem, size_t len);
+ssize_t Curl_sftp_recv(struct connectdata *conn, int sockindex,
+ char *mem, size_t len);
+
+#endif /* USE_LIBSSH2 */
+
+#endif /* __SSH_H */
diff --git a/Utilities/cmcurl/sslgen.c b/Utilities/cmcurl/sslgen.c
new file mode 100644
index 0000000000..f110a51eac
--- /dev/null
+++ b/Utilities/cmcurl/sslgen.c
@@ -0,0 +1,618 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/* This file is for "generic" SSL functions that all libcurl internals should
+ use. It is responsible for calling the proper 'ossl' function in ssluse.c
+ (OpenSSL based) or the 'gtls' function in gtls.c (GnuTLS based).
+
+ SSL-functions in libcurl should call functions in this source file, and not
+ to any specific SSL-layer.
+
+ Curl_ssl_ - prefix for generic ones
+ Curl_ossl_ - prefix for OpenSSL ones
+ Curl_gtls_ - prefix for GnuTLS ones
+
+ "SSL/TLS Strong Encryption: An Introduction"
+ http://httpd.apache.org/docs-2.0/ssl/ssl_intro.html
+*/
+
+#include "setup.h"
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#include "urldata.h"
+#define SSLGEN_C
+#include "sslgen.h" /* generic SSL protos etc */
+#include "ssluse.h" /* OpenSSL versions */
+#include "gtls.h" /* GnuTLS versions */
+#include "sendf.h"
+#include "strequal.h"
+#include "url.h"
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/* "global" init done? */
+static bool init_ssl=FALSE;
+
+static bool safe_strequal(char* str1, char* str2);
+
+static bool safe_strequal(char* str1, char* str2)
+{
+ if(str1 && str2)
+ /* both pointers point to something then compare them */
+ return (bool)(0 != strequal(str1, str2));
+ else
+ /* if both pointers are NULL then treat them as equal */
+ return (bool)(!str1 && !str2);
+}
+
+bool
+Curl_ssl_config_matches(struct ssl_config_data* data,
+ struct ssl_config_data* needle)
+{
+ if((data->version == needle->version) &&
+ (data->verifypeer == needle->verifypeer) &&
+ (data->verifyhost == needle->verifyhost) &&
+ safe_strequal(data->CApath, needle->CApath) &&
+ safe_strequal(data->CAfile, needle->CAfile) &&
+ safe_strequal(data->random_file, needle->random_file) &&
+ safe_strequal(data->egdsocket, needle->egdsocket) &&
+ safe_strequal(data->cipher_list, needle->cipher_list))
+ return TRUE;
+
+ return FALSE;
+}
+
+bool
+Curl_clone_ssl_config(struct ssl_config_data *source,
+ struct ssl_config_data *dest)
+{
+ dest->verifyhost = source->verifyhost;
+ dest->verifypeer = source->verifypeer;
+ dest->version = source->version;
+
+ if(source->CAfile) {
+ dest->CAfile = strdup(source->CAfile);
+ if(!dest->CAfile)
+ return FALSE;
+ }
+
+ if(source->CApath) {
+ dest->CApath = strdup(source->CApath);
+ if(!dest->CApath)
+ return FALSE;
+ }
+
+ if(source->cipher_list) {
+ dest->cipher_list = strdup(source->cipher_list);
+ if(!dest->cipher_list)
+ return FALSE;
+ }
+
+ if(source->egdsocket) {
+ dest->egdsocket = strdup(source->egdsocket);
+ if(!dest->egdsocket)
+ return FALSE;
+ }
+
+ if(source->random_file) {
+ dest->random_file = strdup(source->random_file);
+ if(!dest->random_file)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void Curl_free_ssl_config(struct ssl_config_data* sslc)
+{
+ if(sslc->CAfile)
+ free(sslc->CAfile);
+
+ if(sslc->CApath)
+ free(sslc->CApath);
+
+ if(sslc->cipher_list)
+ free(sslc->cipher_list);
+
+ if(sslc->egdsocket)
+ free(sslc->egdsocket);
+
+ if(sslc->random_file)
+ free(sslc->random_file);
+}
+
+/**
+ * Global SSL init
+ *
+ * @retval 0 error initializing SSL
+ * @retval 1 SSL initialized successfully
+ */
+int Curl_ssl_init(void)
+{
+ /* make sure this is only done once */
+ if(init_ssl)
+ return 1;
+ init_ssl = TRUE; /* never again */
+
+#ifdef USE_SSLEAY
+ return Curl_ossl_init();
+#else
+#ifdef USE_GNUTLS
+ return Curl_gtls_init();
+#else
+ /* no SSL support */
+ return 1;
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+}
+
+
+/* Global cleanup */
+void Curl_ssl_cleanup(void)
+{
+ if(init_ssl) {
+ /* only cleanup if we did a previous init */
+#ifdef USE_SSLEAY
+ Curl_ossl_cleanup();
+#else
+#ifdef USE_GNUTLS
+ Curl_gtls_cleanup();
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+ init_ssl = FALSE;
+ }
+}
+
+CURLcode
+Curl_ssl_connect(struct connectdata *conn, int sockindex)
+{
+#ifdef USE_SSL
+ /* mark this is being ssl enabled from here on. */
+ conn->ssl[sockindex].use = TRUE;
+
+#ifdef USE_SSLEAY
+ return Curl_ossl_connect(conn, sockindex);
+#else
+#ifdef USE_GNUTLS
+ return Curl_gtls_connect(conn, sockindex);
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+
+#else
+ /* without SSL */
+ (void)conn;
+ (void)sockindex;
+ return CURLE_OK;
+#endif /* USE_SSL */
+}
+
+CURLcode
+Curl_ssl_connect_nonblocking(struct connectdata *conn, int sockindex,
+ bool *done)
+{
+#if defined(USE_SSL) && defined(USE_SSLEAY)
+ /* mark this is being ssl enabled from here on. */
+ conn->ssl[sockindex].use = TRUE;
+ return Curl_ossl_connect_nonblocking(conn, sockindex, done);
+
+#else
+ /* not implemented!
+ fallback to BLOCKING call. */
+ *done = TRUE;
+ return Curl_ssl_connect(conn, sockindex);
+#endif
+}
+
+#ifdef USE_SSL
+
+/*
+ * Check if there's a session ID for the given connection in the cache, and if
+ * there's one suitable, it is provided. Returns TRUE when no entry matched.
+ */
+int Curl_ssl_getsessionid(struct connectdata *conn,
+ void **ssl_sessionid,
+ size_t *idsize) /* set 0 if unknown */
+{
+ struct curl_ssl_session *check;
+ struct SessionHandle *data = conn->data;
+ long i;
+
+ if(!conn->ssl_config.sessionid)
+ /* session ID re-use is disabled */
+ return TRUE;
+
+ for(i=0; i< data->set.ssl.numsessions; i++) {
+ check = &data->state.session[i];
+ if(!check->sessionid)
+ /* not session ID means blank entry */
+ continue;
+ if(curl_strequal(conn->host.name, check->name) &&
+ (conn->remote_port == check->remote_port) &&
+ Curl_ssl_config_matches(&conn->ssl_config, &check->ssl_config)) {
+ /* yes, we have a session ID! */
+ data->state.sessionage++; /* increase general age */
+ check->age = data->state.sessionage; /* set this as used in this age */
+ *ssl_sessionid = check->sessionid;
+ if(idsize)
+ *idsize = check->idsize;
+ return FALSE;
+ }
+ }
+ *ssl_sessionid = NULL;
+ return TRUE;
+}
+
+/*
+ * Kill a single session ID entry in the cache.
+ */
+static int kill_session(struct curl_ssl_session *session)
+{
+ if(session->sessionid) {
+ /* defensive check */
+
+ /* free the ID the SSL-layer specific way */
+#ifdef USE_SSLEAY
+ Curl_ossl_session_free(session->sessionid);
+#else
+ Curl_gtls_session_free(session->sessionid);
+#endif
+ session->sessionid=NULL;
+ session->age = 0; /* fresh */
+
+ Curl_free_ssl_config(&session->ssl_config);
+
+ Curl_safefree(session->name);
+ session->name = NULL; /* no name */
+
+ return 0; /* ok */
+ }
+ else
+ return 1;
+}
+
+/*
+ * Store session id in the session cache. The ID passed on to this function
+ * must already have been extracted and allocated the proper way for the SSL
+ * layer. Curl_XXXX_session_free() will be called to free/kill the session ID
+ * later on.
+ */
+CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
+ void *ssl_sessionid,
+ size_t idsize)
+{
+ int i;
+ struct SessionHandle *data=conn->data; /* the mother of all structs */
+ struct curl_ssl_session *store = &data->state.session[0];
+ long oldest_age=data->state.session[0].age; /* zero if unused */
+ char *clone_host;
+
+ /* Even though session ID re-use might be disabled, that only disables USING
+ IT. We still store it here in case the re-using is again enabled for an
+ upcoming transfer */
+
+ clone_host = strdup(conn->host.name);
+ if(!clone_host)
+ return CURLE_OUT_OF_MEMORY; /* bail out */
+
+ /* Now we should add the session ID and the host name to the cache, (remove
+ the oldest if necessary) */
+
+ /* find an empty slot for us, or find the oldest */
+ for(i=1; (i<data->set.ssl.numsessions) &&
+ data->state.session[i].sessionid; i++) {
+ if(data->state.session[i].age < oldest_age) {
+ oldest_age = data->state.session[i].age;
+ store = &data->state.session[i];
+ }
+ }
+ if(i == data->set.ssl.numsessions)
+ /* cache is full, we must "kill" the oldest entry! */
+ kill_session(store);
+ else
+ store = &data->state.session[i]; /* use this slot */
+
+ /* now init the session struct wisely */
+ store->sessionid = ssl_sessionid;
+ store->idsize = idsize;
+ store->age = data->state.sessionage; /* set current age */
+ store->name = clone_host; /* clone host name */
+ store->remote_port = conn->remote_port; /* port number */
+
+ if (!Curl_clone_ssl_config(&conn->ssl_config, &store->ssl_config))
+ return CURLE_OUT_OF_MEMORY;
+
+ return CURLE_OK;
+}
+
+
+#endif
+
+void Curl_ssl_close_all(struct SessionHandle *data)
+{
+#ifdef USE_SSL
+ int i;
+ /* kill the session ID cache */
+ if(data->state.session) {
+ for(i=0; i< data->set.ssl.numsessions; i++)
+ /* the single-killer function handles empty table slots */
+ kill_session(&data->state.session[i]);
+
+ /* free the cache data */
+ free(data->state.session);
+ data->state.session = NULL;
+ }
+#ifdef USE_SSLEAY
+ Curl_ossl_close_all(data);
+#else
+#ifdef USE_GNUTLS
+ Curl_gtls_close_all(data);
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+#else /* USE_SSL */
+ (void)data;
+#endif /* USE_SSL */
+}
+
+void Curl_ssl_close(struct connectdata *conn)
+{
+ if(conn->ssl[FIRSTSOCKET].use) {
+#ifdef USE_SSLEAY
+ Curl_ossl_close(conn);
+#else
+#ifdef USE_GNUTLS
+ Curl_gtls_close(conn);
+#else
+ (void)conn;
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+ }
+}
+
+CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex)
+{
+ if(conn->ssl[sockindex].use) {
+#ifdef USE_SSLEAY
+ if(Curl_ossl_shutdown(conn, sockindex))
+ return CURLE_SSL_SHUTDOWN_FAILED;
+#else
+#ifdef USE_GNUTLS
+ if(Curl_gtls_shutdown(conn, sockindex))
+ return CURLE_SSL_SHUTDOWN_FAILED;
+#else
+ (void)conn;
+ (void)sockindex;
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+ }
+ return CURLE_OK;
+}
+
+/* Selects an (Open)SSL crypto engine
+ */
+CURLcode Curl_ssl_set_engine(struct SessionHandle *data, const char *engine)
+{
+#ifdef USE_SSLEAY
+ return Curl_ossl_set_engine(data, engine);
+#else
+#ifdef USE_GNUTLS
+ /* FIX: add code here */
+ (void)data;
+ (void)engine;
+ return CURLE_FAILED_INIT;
+#else
+ /* no SSL layer */
+ (void)data;
+ (void)engine;
+ return CURLE_FAILED_INIT;
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+}
+
+/* Selects an (Open?)SSL crypto engine
+ */
+CURLcode Curl_ssl_set_engine_default(struct SessionHandle *data)
+{
+#ifdef USE_SSLEAY
+ return Curl_ossl_set_engine_default(data);
+#else
+#ifdef USE_GNUTLS
+ /* FIX: add code here */
+ (void)data;
+ return CURLE_FAILED_INIT;
+#else
+ /* No SSL layer */
+ (void)data;
+ return CURLE_FAILED_INIT;
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+}
+
+/* Return list of OpenSSL crypto engine names. */
+struct curl_slist *Curl_ssl_engines_list(struct SessionHandle *data)
+{
+#ifdef USE_SSLEAY
+ return Curl_ossl_engines_list(data);
+#else
+#ifdef USE_GNUTLS
+ /* FIX: add code here? */
+ (void)data;
+ return NULL;
+#else
+ (void)data;
+ return NULL;
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+}
+
+/* return number of sent (non-SSL) bytes */
+ssize_t Curl_ssl_send(struct connectdata *conn,
+ int sockindex,
+ void *mem,
+ size_t len)
+{
+#ifdef USE_SSLEAY
+ return Curl_ossl_send(conn, sockindex, mem, len);
+#else
+#ifdef USE_GNUTLS
+ return Curl_gtls_send(conn, sockindex, mem, len);
+#else
+ (void)conn;
+ (void)sockindex;
+ (void)mem;
+ (void)len;
+ return 0;
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+}
+
+/* return number of received (decrypted) bytes */
+
+/*
+ * If the read would block (EWOULDBLOCK) we return -1. Otherwise we return
+ * a regular CURLcode value.
+ */
+ssize_t Curl_ssl_recv(struct connectdata *conn, /* connection data */
+ int sockindex, /* socketindex */
+ char *mem, /* store read data here */
+ size_t len) /* max amount to read */
+{
+#ifdef USE_SSL
+ ssize_t nread;
+ bool block = FALSE;
+
+#ifdef USE_SSLEAY
+ nread = Curl_ossl_recv(conn, sockindex, mem, len, &block);
+#else
+#ifdef USE_GNUTLS
+ nread = Curl_gtls_recv(conn, sockindex, mem, len, &block);
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+ if(nread == -1) {
+ if(!block)
+ return 0; /* this is a true error, not EWOULDBLOCK */
+ else
+ return -1;
+ }
+
+ return (int)nread;
+
+#else /* USE_SSL */
+ (void)conn;
+ (void)sockindex;
+ (void)mem;
+ (void)len;
+ return 0;
+#endif /* USE_SSL */
+}
+
+
+/*
+ * This sets up a session ID cache to the specified size. Make sure this code
+ * is agnostic to what underlying SSL technology we use.
+ */
+CURLcode Curl_ssl_initsessions(struct SessionHandle *data, long amount)
+{
+#ifdef USE_SSL
+ struct curl_ssl_session *session;
+
+ if(data->state.session)
+ /* this is just a precaution to prevent multiple inits */
+ return CURLE_OK;
+
+ session = (struct curl_ssl_session *)
+ calloc(sizeof(struct curl_ssl_session), amount);
+ if(!session)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* store the info in the SSL section */
+ data->set.ssl.numsessions = amount;
+ data->state.session = session;
+ data->state.sessionage = 1; /* this is brand new */
+#else
+ /* without SSL, do nothing */
+ (void)data;
+ (void)amount;
+#endif
+
+ return CURLE_OK;
+}
+
+size_t Curl_ssl_version(char *buffer, size_t size)
+{
+#ifdef USE_SSLEAY
+ return Curl_ossl_version(buffer, size);
+#else
+#ifdef USE_GNUTLS
+ return Curl_gtls_version(buffer, size);
+#else
+ (void)buffer;
+ (void)size;
+ return 0; /* no SSL support */
+#endif /* USE_GNUTLS */
+#endif /* USE_SSLEAY */
+}
+
+
+/*
+ * This function tries to determine connection status.
+ *
+ * Return codes:
+ * 1 means the connection is still in place
+ * 0 means the connection has been closed
+ * -1 means the connection status is unknown
+ */
+int Curl_ssl_check_cxn(struct connectdata *conn)
+{
+#ifdef USE_SSLEAY
+ return Curl_ossl_check_cxn(conn);
+#else
+ (void)conn;
+ /* TODO: we lack implementation of this for GnuTLS */
+ return -1; /* connection status unknown */
+#endif /* USE_SSLEAY */
+}
+
+bool Curl_ssl_data_pending(struct connectdata *conn,
+ int connindex)
+{
+#ifdef USE_SSLEAY
+ /* OpenSSL-specific */
+ if(conn->ssl[connindex].handle)
+ /* SSL is in use */
+ return SSL_pending(conn->ssl[connindex].handle);
+#else
+ (void)conn;
+ (void)connindex;
+#endif
+ return FALSE; /* nothing pending */
+
+}
diff --git a/Utilities/cmcurl/sslgen.h b/Utilities/cmcurl/sslgen.h
new file mode 100644
index 0000000000..c24d46bf35
--- /dev/null
+++ b/Utilities/cmcurl/sslgen.h
@@ -0,0 +1,84 @@
+#ifndef __SSLGEN_H
+#define __SSLGEN_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+bool Curl_ssl_config_matches(struct ssl_config_data* data,
+ struct ssl_config_data* needle);
+bool Curl_clone_ssl_config(struct ssl_config_data* source,
+ struct ssl_config_data* dest);
+void Curl_free_ssl_config(struct ssl_config_data* sslc);
+
+int Curl_ssl_init(void);
+void Curl_ssl_cleanup(void);
+CURLcode Curl_ssl_connect(struct connectdata *conn, int sockindex);
+CURLcode Curl_ssl_connect_nonblocking(struct connectdata *conn,
+ int sockindex,
+ bool *done);
+void Curl_ssl_close(struct connectdata *conn);
+/* tell the SSL stuff to close down all open information regarding
+ connections (and thus session ID caching etc) */
+void Curl_ssl_close_all(struct SessionHandle *data);
+CURLcode Curl_ssl_set_engine(struct SessionHandle *data, const char *engine);
+/* Sets engine as default for all SSL operations */
+CURLcode Curl_ssl_set_engine_default(struct SessionHandle *data);
+ssize_t Curl_ssl_send(struct connectdata *conn,
+ int sockindex,
+ void *mem,
+ size_t len);
+ssize_t Curl_ssl_recv(struct connectdata *conn, /* connection data */
+ int sockindex, /* socketindex */
+ char *mem, /* store read data here */
+ size_t len); /* max amount to read */
+
+/* init the SSL session ID cache */
+CURLcode Curl_ssl_initsessions(struct SessionHandle *, long);
+/* extract a session ID */
+int Curl_ssl_getsessionid(struct connectdata *conn,
+ void **ssl_sessionid,
+ size_t *idsize) /* set 0 if unknown */;
+/* add a new session ID */
+CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
+ void *ssl_sessionid,
+ size_t idsize);
+
+
+struct curl_slist *Curl_ssl_engines_list(struct SessionHandle *data);
+
+size_t Curl_ssl_version(char *buffer, size_t size);
+
+int Curl_ssl_check_cxn(struct connectdata *conn);
+
+CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex);
+
+bool Curl_ssl_data_pending(struct connectdata *conn,
+ int connindex);
+
+#if !defined(USE_SSL) && !defined(SSLGEN_C)
+/* set up blank macros for none-SSL builds */
+#define Curl_ssl_close_all(x)
+#endif
+
+#define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
+
+#endif
diff --git a/Utilities/cmcurl/ssluse.c b/Utilities/cmcurl/ssluse.c
new file mode 100644
index 0000000000..6709278fa9
--- /dev/null
+++ b/Utilities/cmcurl/ssluse.c
@@ -0,0 +1,1950 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * Source file for all OpenSSL-specific code for the TLS/SSL layer. No code
+ * but sslgen.c should ever call or use these functions.
+ */
+
+/*
+ * The original SSLeay-using code for curl was written by Linas Vepstas and
+ * Sampo Kellomaki 1998.
+ */
+
+#include "setup.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#include "urldata.h"
+#include "sendf.h"
+#include "formdata.h" /* for the boundary function */
+#include "url.h" /* for the ssl config check function */
+#include "inet_pton.h"
+#include "ssluse.h"
+#include "connect.h" /* Curl_sockerrno() proto */
+#include "strequal.h"
+#include "select.h"
+#include "sslgen.h"
+
+#define _MPRINTF_REPLACE /* use the internal *printf() functions */
+#include <curl/mprintf.h>
+
+#ifdef USE_SSLEAY
+
+#ifdef USE_OPENSSL
+#include <openssl/rand.h>
+#include <openssl/x509v3.h>
+#else
+#include <rand.h>
+#include <x509v3.h>
+#endif
+
+#include "memory.h"
+#include "easyif.h" /* for Curl_convert_from_utf8 prototype */
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#ifndef min
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#if OPENSSL_VERSION_NUMBER >= 0x0090581fL
+#define HAVE_SSL_GET1_SESSION 1
+#else
+#undef HAVE_SSL_GET1_SESSION
+#endif
+
+#if OPENSSL_VERSION_NUMBER >= 0x00904100L
+#define HAVE_USERDATA_IN_PWD_CALLBACK 1
+#else
+#undef HAVE_USERDATA_IN_PWD_CALLBACK
+#endif
+
+#if OPENSSL_VERSION_NUMBER >= 0x00907001L
+/* ENGINE_load_private_key() takes four arguments */
+#define HAVE_ENGINE_LOAD_FOUR_ARGS
+#else
+/* ENGINE_load_private_key() takes three arguments */
+#undef HAVE_ENGINE_LOAD_FOUR_ARGS
+#endif
+
+#if (OPENSSL_VERSION_NUMBER >= 0x00903001L) && defined(HAVE_OPENSSL_PKCS12_H)
+/* OpenSSL has PKCS 12 support */
+#define HAVE_PKCS12_SUPPORT
+#else
+/* OpenSSL/SSLEay does not have PKCS12 support */
+#undef HAVE_PKCS12_SUPPORT
+#endif
+
+#if OPENSSL_VERSION_NUMBER >= 0x00906001L
+#define HAVE_ERR_ERROR_STRING_N 1
+#endif
+
+#if OPENSSL_VERSION_NUMBER >= 0x00909000L
+#define SSL_METHOD_QUAL const
+#else
+#define SSL_METHOD_QUAL
+#endif
+
+/*
+ * Number of bytes to read from the random number seed file. This must be
+ * a finite value (because some entropy "files" like /dev/urandom have
+ * an infinite length), but must be large enough to provide enough
+ * entopy to properly seed OpenSSL's PRNG.
+ */
+#define RAND_LOAD_LENGTH 1024
+
+#ifndef HAVE_USERDATA_IN_PWD_CALLBACK
+static char global_passwd[64];
+#endif
+
+static int passwd_callback(char *buf, int num, int verify
+#if HAVE_USERDATA_IN_PWD_CALLBACK
+ /* This was introduced in 0.9.4, we can set this
+ using SSL_CTX_set_default_passwd_cb_userdata()
+ */
+ , void *global_passwd
+#endif
+ )
+{
+ if(verify)
+ fprintf(stderr, "%s\n", buf);
+ else {
+ if(num > (int)strlen((char *)global_passwd)) {
+ strcpy(buf, global_passwd);
+ return (int)strlen(buf);
+ }
+ }
+ return 0;
+}
+
+/*
+ * rand_enough() is a function that returns TRUE if we have seeded the random
+ * engine properly. We use some preprocessor magic to provide a seed_enough()
+ * macro to use, just to prevent a compiler warning on this function if we
+ * pass in an argument that is never used.
+ */
+
+#ifdef HAVE_RAND_STATUS
+#define seed_enough(x) rand_enough()
+static bool rand_enough(void)
+{
+ return (bool)(0 != RAND_status());
+}
+#else
+#define seed_enough(x) rand_enough(x)
+static bool rand_enough(int nread)
+{
+ /* this is a very silly decision to make */
+ return (bool)(nread > 500);
+}
+#endif
+
+static int ossl_seed(struct SessionHandle *data)
+{
+ char *buf = data->state.buffer; /* point to the big buffer */
+ int nread=0;
+
+ /* Q: should we add support for a random file name as a libcurl option?
+ A: Yes, it is here */
+
+#ifndef RANDOM_FILE
+ /* if RANDOM_FILE isn't defined, we only perform this if an option tells
+ us to! */
+ if(data->set.ssl.random_file)
+#define RANDOM_FILE "" /* doesn't matter won't be used */
+#endif
+ {
+ /* let the option override the define */
+ nread += RAND_load_file((data->set.ssl.random_file?
+ data->set.ssl.random_file:RANDOM_FILE),
+ RAND_LOAD_LENGTH);
+ if(seed_enough(nread))
+ return nread;
+ }
+
+#if defined(HAVE_RAND_EGD)
+ /* only available in OpenSSL 0.9.5 and later */
+ /* EGD_SOCKET is set at configure time or not at all */
+#ifndef EGD_SOCKET
+ /* If we don't have the define set, we only do this if the egd-option
+ is set */
+ if(data->set.ssl.egdsocket)
+#define EGD_SOCKET "" /* doesn't matter won't be used */
+#endif
+ {
+ /* If there's an option and a define, the option overrides the
+ define */
+ int ret = RAND_egd(data->set.ssl.egdsocket?
+ data->set.ssl.egdsocket:EGD_SOCKET);
+ if(-1 != ret) {
+ nread += ret;
+ if(seed_enough(nread))
+ return nread;
+ }
+ }
+#endif
+
+ /* If we get here, it means we need to seed the PRNG using a "silly"
+ approach! */
+#ifdef HAVE_RAND_SCREEN
+ /* This one gets a random value by reading the currently shown screen */
+ RAND_screen();
+ nread = 100; /* just a value */
+#else
+ {
+ int len;
+ char *area;
+
+ /* Changed call to RAND_seed to use the underlying RAND_add implementation
+ * directly. Do this in a loop, with the amount of additional entropy
+ * being dependent upon the algorithm used by Curl_FormBoundary(): N bytes
+ * of a 7-bit ascii set. -- Richard Gorton, March 11 2003.
+ */
+
+ do {
+ area = Curl_FormBoundary();
+ if(!area)
+ return 3; /* out of memory */
+
+ len = (int)strlen(area);
+ RAND_add(area, len, (len >> 1));
+
+ free(area); /* now remove the random junk */
+ } while (!RAND_status());
+ }
+#endif
+
+ /* generates a default path for the random seed file */
+ buf[0]=0; /* blank it first */
+ RAND_file_name(buf, BUFSIZE);
+ if(buf[0]) {
+ /* we got a file name to try */
+ nread += RAND_load_file(buf, RAND_LOAD_LENGTH);
+ if(seed_enough(nread))
+ return nread;
+ }
+
+ infof(data, "libcurl is now using a weak random seed!\n");
+ return nread;
+}
+
+int Curl_ossl_seed(struct SessionHandle *data)
+{
+ /* we have the "SSL is seeded" boolean static to prevent multiple
+ time-consuming seedings in vain */
+ static bool ssl_seeded = FALSE;
+
+ if(!ssl_seeded || data->set.ssl.random_file || data->set.ssl.egdsocket) {
+ ossl_seed(data);
+ ssl_seeded = TRUE;
+ }
+ return 0;
+}
+
+
+#ifndef SSL_FILETYPE_ENGINE
+#define SSL_FILETYPE_ENGINE 42
+#endif
+#ifndef SSL_FILETYPE_PKCS12
+#define SSL_FILETYPE_PKCS12 43
+#endif
+static int do_file_type(const char *type)
+{
+ if(!type || !type[0])
+ return SSL_FILETYPE_PEM;
+ if(curl_strequal(type, "PEM"))
+ return SSL_FILETYPE_PEM;
+ if(curl_strequal(type, "DER"))
+ return SSL_FILETYPE_ASN1;
+ if(curl_strequal(type, "ENG"))
+ return SSL_FILETYPE_ENGINE;
+ if(curl_strequal(type, "P12"))
+ return SSL_FILETYPE_PKCS12;
+ return -1;
+}
+
+static
+int cert_stuff(struct connectdata *conn,
+ SSL_CTX* ctx,
+ char *cert_file,
+ const char *cert_type,
+ char *key_file,
+ const char *key_type)
+{
+ struct SessionHandle *data = conn->data;
+ int file_type;
+
+ if(cert_file != NULL) {
+ SSL *ssl;
+ X509 *x509;
+ int cert_done = 0;
+
+ if(data->set.key_passwd) {
+#ifndef HAVE_USERDATA_IN_PWD_CALLBACK
+ /*
+ * If password has been given, we store that in the global
+ * area (*shudder*) for a while:
+ */
+ size_t len = strlen(data->set.key_passwd);
+ if(len < sizeof(global_passwd))
+ memcpy(global_passwd, data->set.key_passwd, len+1);
+#else
+ /*
+ * We set the password in the callback userdata
+ */
+ SSL_CTX_set_default_passwd_cb_userdata(ctx,
+ data->set.key_passwd);
+#endif
+ /* Set passwd callback: */
+ SSL_CTX_set_default_passwd_cb(ctx, passwd_callback);
+ }
+
+ file_type = do_file_type(cert_type);
+
+#define SSL_CLIENT_CERT_ERR \
+ "unable to use client certificate (no key found or wrong pass phrase?)"
+
+ switch(file_type) {
+ case SSL_FILETYPE_PEM:
+ /* SSL_CTX_use_certificate_chain_file() only works on PEM files */
+ if(SSL_CTX_use_certificate_chain_file(ctx,
+ cert_file) != 1) {
+ failf(data, SSL_CLIENT_CERT_ERR);
+ return 0;
+ }
+ break;
+
+ case SSL_FILETYPE_ASN1:
+ /* SSL_CTX_use_certificate_file() works with either PEM or ASN1, but
+ we use the case above for PEM so this can only be performed with
+ ASN1 files. */
+ if(SSL_CTX_use_certificate_file(ctx,
+ cert_file,
+ file_type) != 1) {
+ failf(data, SSL_CLIENT_CERT_ERR);
+ return 0;
+ }
+ break;
+ case SSL_FILETYPE_ENGINE:
+ failf(data, "file type ENG for certificate not implemented");
+ return 0;
+
+ case SSL_FILETYPE_PKCS12:
+ {
+#ifdef HAVE_PKCS12_SUPPORT
+ FILE *f;
+ PKCS12 *p12;
+ EVP_PKEY *pri;
+
+ f = fopen(cert_file,"rb");
+ if (!f) {
+ failf(data, "could not open PKCS12 file '%s'", cert_file);
+ return 0;
+ }
+ p12 = d2i_PKCS12_fp(f, NULL);
+ fclose(f);
+
+ PKCS12_PBE_add();
+
+ if (!PKCS12_parse(p12, data->set.key_passwd, &pri, &x509, NULL)) {
+ failf(data,
+ "could not parse PKCS12 file, check password, OpenSSL error %s",
+ ERR_error_string(ERR_get_error(), NULL) );
+ return 0;
+ }
+
+ PKCS12_free(p12);
+
+ if(SSL_CTX_use_certificate(ctx, x509) != 1) {
+ failf(data, SSL_CLIENT_CERT_ERR);
+ EVP_PKEY_free(pri);
+ X509_free(x509);
+ return 0;
+ }
+
+ if(SSL_CTX_use_PrivateKey(ctx, pri) != 1) {
+ failf(data, "unable to use private key from PKCS12 file '%s'",
+ cert_file);
+ EVP_PKEY_free(pri);
+ X509_free(x509);
+ return 0;
+ }
+
+ EVP_PKEY_free(pri);
+ X509_free(x509);
+ cert_done = 1;
+ break;
+#else
+ failf(data, "file type P12 for certificate not supported");
+ return 0;
+#endif
+ }
+ default:
+ failf(data, "not supported file type '%s' for certificate", cert_type);
+ return 0;
+ }
+
+ file_type = do_file_type(key_type);
+
+ switch(file_type) {
+ case SSL_FILETYPE_PEM:
+ if(cert_done)
+ break;
+ if(key_file == NULL)
+ /* cert & key can only be in PEM case in the same file */
+ key_file=cert_file;
+ case SSL_FILETYPE_ASN1:
+ if(SSL_CTX_use_PrivateKey_file(ctx, key_file, file_type) != 1) {
+ failf(data, "unable to set private key file: '%s' type %s\n",
+ key_file, key_type?key_type:"PEM");
+ return 0;
+ }
+ break;
+ case SSL_FILETYPE_ENGINE:
+#ifdef HAVE_OPENSSL_ENGINE_H
+ { /* XXXX still needs some work */
+ EVP_PKEY *priv_key = NULL;
+ if(conn && conn->data && conn->data->state.engine) {
+#ifdef HAVE_ENGINE_LOAD_FOUR_ARGS
+ UI_METHOD *ui_method = UI_OpenSSL();
+#endif
+ if(!key_file || !key_file[0]) {
+ failf(data, "no key set to load from crypto engine\n");
+ return 0;
+ }
+ /* the typecast below was added to please MinGW32 */
+ priv_key = (EVP_PKEY *)
+ ENGINE_load_private_key(conn->data->state.engine,key_file,
+#ifdef HAVE_ENGINE_LOAD_FOUR_ARGS
+ ui_method,
+#endif
+ data->set.key_passwd);
+ if(!priv_key) {
+ failf(data, "failed to load private key from crypto engine\n");
+ return 0;
+ }
+ if(SSL_CTX_use_PrivateKey(ctx, priv_key) != 1) {
+ failf(data, "unable to set private key\n");
+ EVP_PKEY_free(priv_key);
+ return 0;
+ }
+ EVP_PKEY_free(priv_key); /* we don't need the handle any more... */
+ }
+ else {
+ failf(data, "crypto engine not set, can't load private key\n");
+ return 0;
+ }
+ }
+ break;
+#else
+ failf(data, "file type ENG for private key not supported\n");
+ return 0;
+#endif
+ case SSL_FILETYPE_PKCS12:
+ if(!cert_done) {
+ failf(data, "file type P12 for private key not supported\n");
+ return 0;
+ }
+ break;
+ default:
+ failf(data, "not supported file type for private key\n");
+ return 0;
+ }
+
+ ssl=SSL_new(ctx);
+ if (NULL == ssl) {
+ failf(data,"unable to create an SSL structure\n");
+ return 0;
+ }
+
+ x509=SSL_get_certificate(ssl);
+
+ /* This version was provided by Evan Jordan and is supposed to not
+ leak memory as the previous version: */
+ if(x509 != NULL) {
+ EVP_PKEY *pktmp = X509_get_pubkey(x509);
+ EVP_PKEY_copy_parameters(pktmp,SSL_get_privatekey(ssl));
+ EVP_PKEY_free(pktmp);
+ }
+
+ SSL_free(ssl);
+
+ /* If we are using DSA, we can copy the parameters from
+ * the private key */
+
+
+ /* Now we know that a key and cert have been set against
+ * the SSL context */
+ if(!SSL_CTX_check_private_key(ctx)) {
+ failf(data, "Private key does not match the certificate public key");
+ return(0);
+ }
+#ifndef HAVE_USERDATA_IN_PWD_CALLBACK
+ /* erase it now */
+ memset(global_passwd, 0, sizeof(global_passwd));
+#endif
+ }
+ return(1);
+}
+
+static
+int cert_verify_callback(int ok, X509_STORE_CTX *ctx)
+{
+ X509 *err_cert;
+ char buf[256];
+
+ err_cert=X509_STORE_CTX_get_current_cert(ctx);
+ X509_NAME_oneline(X509_get_subject_name(err_cert), buf, sizeof(buf));
+ return ok;
+}
+
+/* Return error string for last OpenSSL error
+ */
+static char *SSL_strerror(unsigned long error, char *buf, size_t size)
+{
+#ifdef HAVE_ERR_ERROR_STRING_N
+ /* OpenSSL 0.9.6 and later has a function named
+ ERRO_error_string_n() that takes the size of the buffer as a
+ third argument */
+ ERR_error_string_n(error, buf, size);
+#else
+ (void) size;
+ ERR_error_string(error, buf);
+#endif
+ return (buf);
+}
+
+#endif /* USE_SSLEAY */
+
+#ifdef USE_SSLEAY
+/**
+ * Global SSL init
+ *
+ * @retval 0 error initializing SSL
+ * @retval 1 SSL initialized successfully
+ */
+int Curl_ossl_init(void)
+{
+#ifdef HAVE_ENGINE_LOAD_BUILTIN_ENGINES
+ ENGINE_load_builtin_engines();
+#endif
+
+ /* Lets get nice error messages */
+ SSL_load_error_strings();
+
+ /* Setup all the global SSL stuff */
+ if (!SSLeay_add_ssl_algorithms())
+ return 0;
+
+ return 1;
+}
+
+#endif /* USE_SSLEAY */
+
+#ifdef USE_SSLEAY
+
+/* Global cleanup */
+void Curl_ossl_cleanup(void)
+{
+ /* Free the SSL error strings */
+ ERR_free_strings();
+
+ /* EVP_cleanup() removes all ciphers and digests from the
+ table. */
+ EVP_cleanup();
+
+#ifdef HAVE_ENGINE_cleanup
+ ENGINE_cleanup();
+#endif
+
+#ifdef HAVE_CRYPTO_CLEANUP_ALL_EX_DATA
+ /* this function was not present in 0.9.6b, but was added sometimes
+ later */
+ CRYPTO_cleanup_all_ex_data();
+#endif
+}
+
+/*
+ * This function uses SSL_peek to determine connection status.
+ *
+ * Return codes:
+ * 1 means the connection is still in place
+ * 0 means the connection has been closed
+ * -1 means the connection status is unknown
+ */
+int Curl_ossl_check_cxn(struct connectdata *conn)
+{
+ int rc;
+ char buf;
+
+ rc = SSL_peek(conn->ssl[FIRSTSOCKET].handle, (void*)&buf, 1);
+ if (rc > 0)
+ return 1; /* connection still in place */
+
+ if (rc == 0)
+ return 0; /* connection has been closed */
+
+ return -1; /* connection status unknown */
+}
+
+#endif /* USE_SSLEAY */
+
+/* Selects an OpenSSL crypto engine
+ */
+CURLcode Curl_ossl_set_engine(struct SessionHandle *data, const char *engine)
+{
+#if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H)
+ ENGINE *e = ENGINE_by_id(engine);
+
+ if (!e) {
+ failf(data, "SSL Engine '%s' not found", engine);
+ return (CURLE_SSL_ENGINE_NOTFOUND);
+ }
+
+ if (data->state.engine) {
+ ENGINE_finish(data->state.engine);
+ ENGINE_free(data->state.engine);
+ data->state.engine = NULL;
+ }
+ if (!ENGINE_init(e)) {
+ char buf[256];
+
+ ENGINE_free(e);
+ failf(data, "Failed to initialise SSL Engine '%s':\n%s",
+ engine, SSL_strerror(ERR_get_error(), buf, sizeof(buf)));
+ return (CURLE_SSL_ENGINE_INITFAILED);
+ }
+ data->state.engine = e;
+ return (CURLE_OK);
+#else
+ (void)engine;
+ failf(data, "SSL Engine not supported");
+ return (CURLE_SSL_ENGINE_NOTFOUND);
+#endif
+}
+
+#ifdef USE_SSLEAY
+/* Sets engine as default for all SSL operations
+ */
+CURLcode Curl_ossl_set_engine_default(struct SessionHandle *data)
+{
+#ifdef HAVE_OPENSSL_ENGINE_H
+ if (data->state.engine) {
+ if (ENGINE_set_default(data->state.engine, ENGINE_METHOD_ALL) > 0) {
+ infof(data,"set default crypto engine '%s'\n", ENGINE_get_id(data->state.engine));
+ }
+ else {
+ failf(data, "set default crypto engine '%s' failed", ENGINE_get_id(data->state.engine));
+ return CURLE_SSL_ENGINE_SETFAILED;
+ }
+ }
+#else
+ (void) data;
+#endif
+ return CURLE_OK;
+}
+#endif /* USE_SSLEAY */
+
+/* Return list of OpenSSL crypto engine names.
+ */
+struct curl_slist *Curl_ossl_engines_list(struct SessionHandle *data)
+{
+ struct curl_slist *list = NULL;
+#if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H)
+ ENGINE *e;
+
+ for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
+ list = curl_slist_append(list, ENGINE_get_id(e));
+#endif
+ (void) data;
+ return (list);
+}
+
+
+#ifdef USE_SSLEAY
+
+/*
+ * This function is called when an SSL connection is closed.
+ */
+void Curl_ossl_close(struct connectdata *conn)
+{
+ int i;
+ /*
+ ERR_remove_state() frees the error queue associated with
+ thread pid. If pid == 0, the current thread will have its
+ error queue removed.
+
+ Since error queue data structures are allocated
+ automatically for new threads, they must be freed when
+ threads are terminated in oder to avoid memory leaks.
+ */
+ ERR_remove_state(0);
+
+ for(i=0; i<2; i++) {
+ struct ssl_connect_data *connssl = &conn->ssl[i];
+
+ if(connssl->handle) {
+ (void)SSL_shutdown(connssl->handle);
+ SSL_set_connect_state(connssl->handle);
+
+ SSL_free (connssl->handle);
+ connssl->handle = NULL;
+ }
+ if(connssl->ctx) {
+ SSL_CTX_free (connssl->ctx);
+ connssl->ctx = NULL;
+ }
+ connssl->use = FALSE; /* get back to ordinary socket usage */
+ }
+}
+
+/*
+ * This function is called to shut down the SSL layer but keep the
+ * socket open (CCC - Clear Command Channel)
+ */
+int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
+{
+ int retval = 0;
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ struct SessionHandle *data = conn->data;
+ char buf[120]; /* We will use this for the OpenSSL error buffer, so it has
+ to be at least 120 bytes long. */
+ unsigned long sslerror;
+ ssize_t nread;
+ int err;
+ int done = 0;
+
+ /* This has only been tested on the proftpd server, and the mod_tls code
+ sends a close notify alert without waiting for a close notify alert in
+ response. Thus we wait for a close notify alert from the server, but
+ we do not send one. Let's hope other servers do the same... */
+
+ if(connssl->handle) {
+ while(!done) {
+ int what = Curl_select(conn->sock[sockindex],
+ CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT);
+ if(what > 0) {
+ /* Something to read, let's do it and hope that it is the close
+ notify alert from the server */
+ nread = (ssize_t)SSL_read(conn->ssl[sockindex].handle, buf,
+ sizeof(buf));
+ err = SSL_get_error(conn->ssl[sockindex].handle, (int)nread);
+
+ switch(err) {
+ case SSL_ERROR_NONE: /* this is not an error */
+ case SSL_ERROR_ZERO_RETURN: /* no more data */
+ /* This is the expected response. There was no data but only
+ the close notify alert */
+ done = 1;
+ break;
+ case SSL_ERROR_WANT_READ:
+ /* there's data pending, re-invoke SSL_read() */
+ infof(data, "SSL_ERROR_WANT_READ\n");
+ break;
+ case SSL_ERROR_WANT_WRITE:
+ /* SSL wants a write. Really odd. Let's bail out. */
+ infof(data, "SSL_ERROR_WANT_WRITE\n");
+ done = 1;
+ break;
+ default:
+ /* openssl/ssl.h says "look at error stack/return value/errno" */
+ sslerror = ERR_get_error();
+ failf(conn->data, "SSL read: %s, errno %d",
+ ERR_error_string(sslerror, buf),
+ Curl_sockerrno() );
+ done = 1;
+ break;
+ }
+ }
+ else if(0 == what) {
+ /* timeout */
+ failf(data, "SSL shutdown timeout");
+ done = 1;
+ break;
+ }
+ else {
+ /* anything that gets here is fatally bad */
+ failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
+ retval = -1;
+ done = 1;
+ }
+ } /* while()-loop for the select() */
+
+ if(data->set.verbose) {
+ switch(SSL_get_shutdown(connssl->handle)) {
+ case SSL_SENT_SHUTDOWN:
+ infof(data, "SSL_get_shutdown() returned SSL_SENT_SHUTDOWN\n");
+ break;
+ case SSL_RECEIVED_SHUTDOWN:
+ infof(data, "SSL_get_shutdown() returned SSL_RECEIVED_SHUTDOWN\n");
+ break;
+ case SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN:
+ infof(data, "SSL_get_shutdown() returned SSL_SENT_SHUTDOWN|"
+ "SSL_RECEIVED__SHUTDOWN\n");
+ break;
+ }
+ }
+
+ connssl->use = FALSE; /* get back to ordinary socket usage */
+
+ SSL_free (connssl->handle);
+ connssl->handle = NULL;
+ }
+ return retval;
+}
+
+void Curl_ossl_session_free(void *ptr)
+{
+ /* free the ID */
+ SSL_SESSION_free(ptr);
+}
+
+/*
+ * This function is called when the 'data' struct is going away. Close
+ * down everything and free all resources!
+ */
+int Curl_ossl_close_all(struct SessionHandle *data)
+{
+#ifdef HAVE_OPENSSL_ENGINE_H
+ if(data->state.engine) {
+ ENGINE_finish(data->state.engine);
+ ENGINE_free(data->state.engine);
+ data->state.engine = NULL;
+ }
+#else
+ (void)data;
+#endif
+ return 0;
+}
+
+static int Curl_ASN1_UTCTIME_output(struct connectdata *conn,
+ const char *prefix,
+ ASN1_UTCTIME *tm)
+{
+ char *asn1_string;
+ int gmt=FALSE;
+ int i;
+ int year=0,month=0,day=0,hour=0,minute=0,second=0;
+ struct SessionHandle *data = conn->data;
+
+ if(!data->set.verbose)
+ return 0;
+
+ i=tm->length;
+ asn1_string=(char *)tm->data;
+
+ if(i < 10)
+ return 1;
+ if(asn1_string[i-1] == 'Z')
+ gmt=TRUE;
+ for (i=0; i<10; i++)
+ if((asn1_string[i] > '9') || (asn1_string[i] < '0'))
+ return 2;
+
+ year= (asn1_string[0]-'0')*10+(asn1_string[1]-'0');
+ if(year < 50)
+ year+=100;
+
+ month= (asn1_string[2]-'0')*10+(asn1_string[3]-'0');
+ if((month > 12) || (month < 1))
+ return 3;
+
+ day= (asn1_string[4]-'0')*10+(asn1_string[5]-'0');
+ hour= (asn1_string[6]-'0')*10+(asn1_string[7]-'0');
+ minute= (asn1_string[8]-'0')*10+(asn1_string[9]-'0');
+
+ if((asn1_string[10] >= '0') && (asn1_string[10] <= '9') &&
+ (asn1_string[11] >= '0') && (asn1_string[11] <= '9'))
+ second= (asn1_string[10]-'0')*10+(asn1_string[11]-'0');
+
+ infof(data,
+ "%s%04d-%02d-%02d %02d:%02d:%02d %s\n",
+ prefix, year+1900, month, day, hour, minute, second, (gmt?"GMT":""));
+
+ return 0;
+}
+
+#endif
+
+/* ====================================================== */
+#ifdef USE_SSLEAY
+
+/*
+ * Match a hostname against a wildcard pattern.
+ * E.g.
+ * "foo.host.com" matches "*.host.com".
+ *
+ * We are a bit more liberal than RFC2818 describes in that we
+ * accept multiple "*" in pattern (similar to what some other browsers do).
+ * E.g.
+ * "abc.def.domain.com" should strickly not match "*.domain.com", but we
+ * don't consider "." to be important in CERT checking.
+ */
+#define HOST_NOMATCH 0
+#define HOST_MATCH 1
+
+static int hostmatch(const char *hostname, const char *pattern)
+{
+ while (1) {
+ int c = *pattern++;
+
+ if (c == '\0')
+ return (*hostname ? HOST_NOMATCH : HOST_MATCH);
+
+ if (c == '*') {
+ c = *pattern;
+ if (c == '\0') /* "*\0" matches anything remaining */
+ return HOST_MATCH;
+
+ while (*hostname) {
+ /* The only recursive function in libcurl! */
+ if (hostmatch(hostname++,pattern) == HOST_MATCH)
+ return HOST_MATCH;
+ }
+ break;
+ }
+
+ if (toupper(c) != toupper(*hostname++))
+ break;
+ }
+ return HOST_NOMATCH;
+}
+
+static int
+cert_hostcheck(const char *match_pattern, const char *hostname)
+{
+ if (!match_pattern || !*match_pattern ||
+ !hostname || !*hostname) /* sanity check */
+ return 0;
+
+ if(curl_strequal(hostname,match_pattern)) /* trivial case */
+ return 1;
+
+ if (hostmatch(hostname,match_pattern) == HOST_MATCH)
+ return 1;
+ return 0;
+}
+
+/* Quote from RFC2818 section 3.1 "Server Identity"
+
+ If a subjectAltName extension of type dNSName is present, that MUST
+ be used as the identity. Otherwise, the (most specific) Common Name
+ field in the Subject field of the certificate MUST be used. Although
+ the use of the Common Name is existing practice, it is deprecated and
+ Certification Authorities are encouraged to use the dNSName instead.
+
+ Matching is performed using the matching rules specified by
+ [RFC2459]. If more than one identity of a given type is present in
+ the certificate (e.g., more than one dNSName name, a match in any one
+ of the set is considered acceptable.) Names may contain the wildcard
+ character * which is considered to match any single domain name
+ component or component fragment. E.g., *.a.com matches foo.a.com but
+ not bar.foo.a.com. f*.com matches foo.com but not bar.com.
+
+ In some cases, the URI is specified as an IP address rather than a
+ hostname. In this case, the iPAddress subjectAltName must be present
+ in the certificate and must exactly match the IP in the URI.
+
+*/
+static CURLcode verifyhost(struct connectdata *conn,
+ X509 *server_cert)
+{
+ bool matched = FALSE; /* no alternative match yet */
+ int target = GEN_DNS; /* target type, GEN_DNS or GEN_IPADD */
+ int addrlen = 0;
+ struct SessionHandle *data = conn->data;
+ STACK_OF(GENERAL_NAME) *altnames;
+#ifdef ENABLE_IPV6
+ struct in6_addr addr;
+#else
+ struct in_addr addr;
+#endif
+ CURLcode res = CURLE_OK;
+
+#ifdef ENABLE_IPV6
+ if(conn->bits.ipv6_ip &&
+ Curl_inet_pton(AF_INET6, conn->host.name, &addr)) {
+ target = GEN_IPADD;
+ addrlen = sizeof(struct in6_addr);
+ }
+ else
+#endif
+ if(Curl_inet_pton(AF_INET, conn->host.name, &addr)) {
+ target = GEN_IPADD;
+ addrlen = sizeof(struct in_addr);
+ }
+
+ /* get a "list" of alternative names */
+ altnames = X509_get_ext_d2i(server_cert, NID_subject_alt_name, NULL, NULL);
+
+ if(altnames) {
+ int numalts;
+ int i;
+
+ /* get amount of alternatives, RFC2459 claims there MUST be at least
+ one, but we don't depend on it... */
+ numalts = sk_GENERAL_NAME_num(altnames);
+
+ /* loop through all alternatives while none has matched */
+ for (i=0; (i<numalts) && !matched; i++) {
+ /* get a handle to alternative name number i */
+ const GENERAL_NAME *check = sk_GENERAL_NAME_value(altnames, i);
+
+ /* only check alternatives of the same type the target is */
+ if(check->type == target) {
+ /* get data and length */
+ const char *altptr = (char *)ASN1_STRING_data(check->d.ia5);
+ int altlen;
+
+ switch(target) {
+ case GEN_DNS: /* name/pattern comparison */
+ /* The OpenSSL man page explicitly says: "In general it cannot be
+ assumed that the data returned by ASN1_STRING_data() is null
+ terminated or does not contain embedded nulls." But also that
+ "The actual format of the data will depend on the actual string
+ type itself: for example for and IA5String the data will be ASCII"
+
+ Gisle researched the OpenSSL sources:
+ "I checked the 0.9.6 and 0.9.8 sources before my patch and
+ it always 0-terminates an IA5String."
+ */
+ if (cert_hostcheck(altptr, conn->host.name))
+ matched = TRUE;
+ break;
+
+ case GEN_IPADD: /* IP address comparison */
+ /* compare alternative IP address if the data chunk is the same size
+ our server IP address is */
+ altlen = ASN1_STRING_length(check->d.ia5);
+ if((altlen == addrlen) && !memcmp(altptr, &addr, altlen))
+ matched = TRUE;
+ break;
+ }
+ }
+ }
+ GENERAL_NAMES_free(altnames);
+ }
+
+ if(matched)
+ /* an alternative name matched the server hostname */
+ infof(data, "\t subjectAltName: %s matched\n", conn->host.dispname);
+ else {
+ /* we have to look to the last occurence of a commonName in the
+ distinguished one to get the most significant one. */
+ int j,i=-1 ;
+
+/* The following is done because of a bug in 0.9.6b */
+
+ unsigned char *nulstr = (unsigned char *)"";
+ unsigned char *peer_CN = nulstr;
+
+ X509_NAME *name = X509_get_subject_name(server_cert) ;
+ if (name)
+ while ((j=X509_NAME_get_index_by_NID(name,NID_commonName,i))>=0)
+ i=j;
+
+ /* we have the name entry and we will now convert this to a string
+ that we can use for comparison. Doing this we support BMPstring,
+ UTF8 etc. */
+
+ if (i>=0) {
+ ASN1_STRING *tmp = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i));
+
+ /* In OpenSSL 0.9.7d and earlier, ASN1_STRING_to_UTF8 fails if the input
+ is already UTF-8 encoded. We check for this case and copy the raw
+ string manually to avoid the problem. This code can be made
+ conditional in the future when OpenSSL has been fixed. Work-around
+ brought by Alexis S. L. Carvalho. */
+ if (tmp && ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING) {
+ j = ASN1_STRING_length(tmp);
+ if (j >= 0) {
+ peer_CN = OPENSSL_malloc(j+1);
+ if (peer_CN) {
+ memcpy(peer_CN, ASN1_STRING_data(tmp), j);
+ peer_CN[j] = '\0';
+ }
+ }
+ }
+ else /* not a UTF8 name */
+ j = ASN1_STRING_to_UTF8(&peer_CN, tmp);
+ }
+
+ if (peer_CN == nulstr)
+ peer_CN = NULL;
+#ifdef CURL_DOES_CONVERSIONS
+ else {
+ /* convert peer_CN from UTF8 */
+ size_t rc;
+ rc = Curl_convert_from_utf8(data, peer_CN, strlen(peer_CN));
+ /* Curl_convert_from_utf8 calls failf if unsuccessful */
+ if (rc != CURLE_OK) {
+ return(rc);
+ }
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ if (!peer_CN) {
+ if(data->set.ssl.verifyhost > 1) {
+ failf(data,
+ "SSL: unable to obtain common name from peer certificate");
+ return CURLE_SSL_PEER_CERTIFICATE;
+ }
+ else {
+ /* Consider verifyhost == 1 as an "OK" for a missing CN field, but we
+ output a note about the situation */
+ infof(data, "\t common name: WARNING couldn't obtain\n");
+ }
+ }
+ else if(!cert_hostcheck((const char *)peer_CN, conn->host.name)) {
+ if(data->set.ssl.verifyhost > 1) {
+ failf(data, "SSL: certificate subject name '%s' does not match "
+ "target host name '%s'", peer_CN, conn->host.dispname);
+ res = CURLE_SSL_PEER_CERTIFICATE;
+ }
+ else
+ infof(data, "\t common name: %s (does not match '%s')\n",
+ peer_CN, conn->host.dispname);
+ }
+ else {
+ infof(data, "\t common name: %s (matched)\n", peer_CN);
+ }
+ if(peer_CN)
+ OPENSSL_free(peer_CN);
+ }
+ return res;
+}
+#endif
+
+/* The SSL_CTRL_SET_MSG_CALLBACK doesn't exist in ancient OpenSSL versions
+ and thus this cannot be done there. */
+#ifdef SSL_CTRL_SET_MSG_CALLBACK
+
+static const char *ssl_msg_type(int ssl_ver, int msg)
+{
+ if (ssl_ver == SSL2_VERSION_MAJOR) {
+ switch (msg) {
+ case SSL2_MT_ERROR:
+ return "Error";
+ case SSL2_MT_CLIENT_HELLO:
+ return "Client hello";
+ case SSL2_MT_CLIENT_MASTER_KEY:
+ return "Client key";
+ case SSL2_MT_CLIENT_FINISHED:
+ return "Client finished";
+ case SSL2_MT_SERVER_HELLO:
+ return "Server hello";
+ case SSL2_MT_SERVER_VERIFY:
+ return "Server verify";
+ case SSL2_MT_SERVER_FINISHED:
+ return "Server finished";
+ case SSL2_MT_REQUEST_CERTIFICATE:
+ return "Request CERT";
+ case SSL2_MT_CLIENT_CERTIFICATE:
+ return "Client CERT";
+ }
+ }
+ else if (ssl_ver == SSL3_VERSION_MAJOR) {
+ switch (msg) {
+ case SSL3_MT_HELLO_REQUEST:
+ return "Hello request";
+ case SSL3_MT_CLIENT_HELLO:
+ return "Client hello";
+ case SSL3_MT_SERVER_HELLO:
+ return "Server hello";
+ case SSL3_MT_CERTIFICATE:
+ return "CERT";
+ case SSL3_MT_SERVER_KEY_EXCHANGE:
+ return "Server key exchange";
+ case SSL3_MT_CLIENT_KEY_EXCHANGE:
+ return "Client key exchange";
+ case SSL3_MT_CERTIFICATE_REQUEST:
+ return "Request CERT";
+ case SSL3_MT_SERVER_DONE:
+ return "Server finished";
+ case SSL3_MT_CERTIFICATE_VERIFY:
+ return "CERT verify";
+ case SSL3_MT_FINISHED:
+ return "Finished";
+ }
+ }
+ return "Unknown";
+}
+
+static const char *tls_rt_type(int type)
+{
+ return (
+ type == SSL3_RT_CHANGE_CIPHER_SPEC ? "TLS change cipher, " :
+ type == SSL3_RT_ALERT ? "TLS alert, " :
+ type == SSL3_RT_HANDSHAKE ? "TLS handshake, " :
+ type == SSL3_RT_APPLICATION_DATA ? "TLS app data, " :
+ "TLS Unknown, ");
+}
+
+
+/*
+ * Our callback from the SSL/TLS layers.
+ */
+static void ssl_tls_trace(int direction, int ssl_ver, int content_type,
+ const void *buf, size_t len, const SSL *ssl,
+ struct connectdata *conn)
+{
+ struct SessionHandle *data;
+ const char *msg_name, *tls_rt_name;
+ char ssl_buf[1024];
+ int ver, msg_type, txt_len;
+
+ if (!conn || !conn->data || !conn->data->set.fdebug ||
+ (direction != 0 && direction != 1))
+ return;
+
+ data = conn->data;
+ ssl_ver >>= 8;
+ ver = (ssl_ver == SSL2_VERSION_MAJOR ? '2' :
+ ssl_ver == SSL3_VERSION_MAJOR ? '3' : '?');
+
+ /* SSLv2 doesn't seem to have TLS record-type headers, so OpenSSL
+ * always pass-up content-type as 0. But the interesting message-type
+ * is at 'buf[0]'.
+ */
+ if (ssl_ver == SSL3_VERSION_MAJOR && content_type != 0)
+ tls_rt_name = tls_rt_type(content_type);
+ else
+ tls_rt_name = "";
+
+ msg_type = *(char*)buf;
+ msg_name = ssl_msg_type(ssl_ver, msg_type);
+
+ txt_len = snprintf(ssl_buf, sizeof(ssl_buf), "SSLv%c, %s%s (%d):\n",
+ ver, tls_rt_name, msg_name, msg_type);
+ Curl_debug(data, CURLINFO_TEXT, ssl_buf, (size_t)txt_len, NULL);
+
+ Curl_debug(data, (direction == 1) ? CURLINFO_SSL_DATA_OUT :
+ CURLINFO_SSL_DATA_IN, (char *)buf, len, NULL);
+ (void) ssl;
+}
+#endif
+
+#ifdef USE_SSLEAY
+/* ====================================================== */
+
+static CURLcode
+Curl_ossl_connect_step1(struct connectdata *conn,
+ int sockindex)
+{
+ CURLcode retcode = CURLE_OK;
+
+ struct SessionHandle *data = conn->data;
+ SSL_METHOD_QUAL SSL_METHOD *req_method=NULL;
+ void *ssl_sessionid=NULL;
+ curl_socket_t sockfd = conn->sock[sockindex];
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+
+ curlassert(ssl_connect_1 == connssl->connecting_state);
+
+ /* Make funny stuff to get random input */
+ Curl_ossl_seed(data);
+
+ /* check to see if we've been told to use an explicit SSL/TLS version */
+ switch(data->set.ssl.version) {
+ default:
+ case CURL_SSLVERSION_DEFAULT:
+ /* we try to figure out version */
+ req_method = SSLv23_client_method();
+ break;
+ case CURL_SSLVERSION_TLSv1:
+ req_method = TLSv1_client_method();
+ break;
+ case CURL_SSLVERSION_SSLv2:
+#ifdef OPENSSL_NO_SSL2
+ failf(data, "OpenSSL was built without SSLv2 support");
+ return CURLE_NOT_BUILT_IN;
+#else
+ req_method = SSLv2_client_method();
+ break;
+#endif
+ case CURL_SSLVERSION_SSLv3:
+ req_method = SSLv3_client_method();
+ break;
+ }
+
+ if (connssl->ctx)
+ SSL_CTX_free(connssl->ctx);
+ connssl->ctx = SSL_CTX_new(req_method);
+
+ if(!connssl->ctx) {
+ failf(data, "SSL: couldn't create a context!");
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+#ifdef SSL_CTRL_SET_MSG_CALLBACK
+ if (data->set.fdebug && data->set.verbose) {
+ /* the SSL trace callback is only used for verbose logging so we only
+ inform about failures of setting it */
+ if (!SSL_CTX_callback_ctrl(connssl->ctx, SSL_CTRL_SET_MSG_CALLBACK,
+ (void (*)(void))ssl_tls_trace)) {
+ infof(data, "SSL: couldn't set callback!\n");
+ }
+ else if (!SSL_CTX_ctrl(connssl->ctx, SSL_CTRL_SET_MSG_CALLBACK_ARG, 0,
+ conn)) {
+ infof(data, "SSL: couldn't set callback argument!\n");
+ }
+ }
+#endif
+
+ /* OpenSSL contains code to work-around lots of bugs and flaws in various
+ SSL-implementations. SSL_CTX_set_options() is used to enabled those
+ work-arounds. The man page for this option states that SSL_OP_ALL enables
+ all the work-arounds and that "It is usually safe to use SSL_OP_ALL to
+ enable the bug workaround options if compatibility with somewhat broken
+ implementations is desired."
+
+ */
+ SSL_CTX_set_options(connssl->ctx, SSL_OP_ALL);
+
+#if 0
+ /*
+ * Not sure it's needed to tell SSL_connect() that socket is
+ * non-blocking. It doesn't seem to care, but just return with
+ * SSL_ERROR_WANT_x.
+ */
+ if (data->state.used_interface == Curl_if_multi)
+ SSL_CTX_ctrl(connssl->ctx, BIO_C_SET_NBIO, 1, NULL);
+#endif
+
+ if(data->set.cert) {
+ if(!cert_stuff(conn,
+ connssl->ctx,
+ data->set.cert,
+ data->set.cert_type,
+ data->set.key,
+ data->set.key_type)) {
+ /* failf() is already done in cert_stuff() */
+ return CURLE_SSL_CERTPROBLEM;
+ }
+ }
+
+ if(data->set.ssl.cipher_list) {
+ if(!SSL_CTX_set_cipher_list(connssl->ctx,
+ data->set.ssl.cipher_list)) {
+ failf(data, "failed setting cipher list");
+ return CURLE_SSL_CIPHER;
+ }
+ }
+
+ if (data->set.ssl.CAfile || data->set.ssl.CApath) {
+ /* tell SSL where to find CA certificates that are used to verify
+ the servers certificate. */
+ if (!SSL_CTX_load_verify_locations(connssl->ctx, data->set.ssl.CAfile,
+ data->set.ssl.CApath)) {
+ if (data->set.ssl.verifypeer) {
+ /* Fail if we insist on successfully verifying the server. */
+ failf(data,"error setting certificate verify locations:\n"
+ " CAfile: %s\n CApath: %s\n",
+ data->set.ssl.CAfile ? data->set.ssl.CAfile : "none",
+ data->set.ssl.CApath ? data->set.ssl.CApath : "none");
+ return CURLE_SSL_CACERT_BADFILE;
+ }
+ else {
+ /* Just continue with a warning if no strict certificate verification
+ is required. */
+ infof(data, "error setting certificate verify locations,"
+ " continuing anyway:\n");
+ }
+ }
+ else {
+ /* Everything is fine. */
+ infof(data, "successfully set certificate verify locations:\n");
+ }
+ infof(data,
+ " CAfile: %s\n"
+ " CApath: %s\n",
+ data->set.ssl.CAfile ? data->set.ssl.CAfile : "none",
+ data->set.ssl.CApath ? data->set.ssl.CApath : "none");
+ }
+ /* SSL always tries to verify the peer, this only says whether it should
+ * fail to connect if the verification fails, or if it should continue
+ * anyway. In the latter case the result of the verification is checked with
+ * SSL_get_verify_result() below. */
+ SSL_CTX_set_verify(connssl->ctx,
+ data->set.ssl.verifypeer?SSL_VERIFY_PEER:SSL_VERIFY_NONE,
+ cert_verify_callback);
+
+ /* give application a chance to interfere with SSL set up. */
+ if(data->set.ssl.fsslctx) {
+ retcode = (*data->set.ssl.fsslctx)(data, connssl->ctx,
+ data->set.ssl.fsslctxp);
+ if(retcode) {
+ failf(data,"error signaled by ssl ctx callback");
+ return retcode;
+ }
+ }
+
+ /* Lets make an SSL structure */
+ if (connssl->handle)
+ SSL_free(connssl->handle);
+ connssl->handle = SSL_new(connssl->ctx);
+ if (!connssl->handle) {
+ failf(data, "SSL: couldn't create a context (handle)!");
+ return CURLE_OUT_OF_MEMORY;
+ }
+ SSL_set_connect_state(connssl->handle);
+
+ connssl->server_cert = 0x0;
+
+ /* Check if there's a cached ID we can/should use here! */
+ if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL)) {
+ /* we got a session id, use it! */
+ if (!SSL_set_session(connssl->handle, ssl_sessionid)) {
+ failf(data, "SSL: SSL_set_session failed: %s",
+ ERR_error_string(ERR_get_error(),NULL));
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+ /* Informational message */
+ infof (data, "SSL re-using session ID\n");
+ }
+
+ /* pass the raw socket into the SSL layers */
+ if (!SSL_set_fd(connssl->handle, sockfd)) {
+ failf(data, "SSL: SSL_set_fd failed: %s",
+ ERR_error_string(ERR_get_error(),NULL));
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+
+ connssl->connecting_state = ssl_connect_2;
+ return CURLE_OK;
+}
+
+static CURLcode
+Curl_ossl_connect_step2(struct connectdata *conn,
+ int sockindex, long *timeout_ms)
+{
+ struct SessionHandle *data = conn->data;
+ int err;
+ long has_passed;
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+
+ curlassert(ssl_connect_2 == connssl->connecting_state
+ || ssl_connect_2_reading == connssl->connecting_state
+ || ssl_connect_2_writing == connssl->connecting_state);
+
+ /* Find out if any timeout is set. If not, use 300 seconds.
+ Otherwise, figure out the most strict timeout of the two possible one
+ and then how much time that has elapsed to know how much time we
+ allow for the connect call */
+ if(data->set.timeout && data->set.connecttimeout) {
+ /* get the most strict timeout of the ones converted to milliseconds */
+ if(data->set.timeout<data->set.connecttimeout)
+ *timeout_ms = data->set.timeout*1000;
+ else
+ *timeout_ms = data->set.connecttimeout*1000;
+ }
+ else if(data->set.timeout)
+ *timeout_ms = data->set.timeout*1000;
+ else if(data->set.connecttimeout)
+ *timeout_ms = data->set.connecttimeout*1000;
+ else
+ /* no particular time-out has been set */
+ *timeout_ms= DEFAULT_CONNECT_TIMEOUT;
+
+ /* Evaluate in milliseconds how much time that has passed */
+ has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);
+
+ /* subtract the passed time */
+ *timeout_ms -= has_passed;
+
+ if(*timeout_ms < 0) {
+ /* a precaution, no need to continue if time already is up */
+ failf(data, "SSL connection timeout");
+ return CURLE_OPERATION_TIMEOUTED;
+ }
+
+ err = SSL_connect(connssl->handle);
+
+ /* 1 is fine
+ 0 is "not successful but was shut down controlled"
+ <0 is "handshake was not successful, because a fatal error occurred" */
+ if(1 != err) {
+ int detail = SSL_get_error(connssl->handle, err);
+
+ if(SSL_ERROR_WANT_READ == detail) {
+ connssl->connecting_state = ssl_connect_2_reading;
+ return CURLE_OK;
+ }
+ else if(SSL_ERROR_WANT_WRITE == detail) {
+ connssl->connecting_state = ssl_connect_2_writing;
+ return CURLE_OK;
+ }
+ else {
+ /* untreated error */
+ unsigned long errdetail;
+ char error_buffer[256]; /* OpenSSL documents that this must be at least
+ 256 bytes long. */
+ CURLcode rc;
+ const char *cert_problem = NULL;
+
+ connssl->connecting_state = ssl_connect_2; /* the connection failed,
+ we're not waiting for
+ anything else. */
+
+ errdetail = ERR_get_error(); /* Gets the earliest error code from the
+ thread's error queue and removes the
+ entry. */
+
+ switch(errdetail) {
+ case 0x1407E086:
+ /* 1407E086:
+ SSL routines:
+ SSL2_SET_CERTIFICATE:
+ certificate verify failed */
+ /* fall-through */
+ case 0x14090086:
+ /* 14090086:
+ SSL routines:
+ SSL3_GET_SERVER_CERTIFICATE:
+ certificate verify failed */
+ cert_problem = "SSL certificate problem, verify that the CA cert is"
+ " OK. Details:\n";
+ rc = CURLE_SSL_CACERT;
+ break;
+ default:
+ rc = CURLE_SSL_CONNECT_ERROR;
+ break;
+ }
+
+ /* detail is already set to the SSL error above */
+
+ /* If we e.g. use SSLv2 request-method and the server doesn't like us
+ * (RST connection etc.), OpenSSL gives no explanation whatsoever and
+ * the SO_ERROR is also lost.
+ */
+ if (CURLE_SSL_CONNECT_ERROR == rc && errdetail == 0) {
+ failf(data, "Unknown SSL protocol error in connection to %s:%d ",
+ conn->host.name, conn->port);
+ return rc;
+ }
+ /* Could be a CERT problem */
+
+ SSL_strerror(errdetail, error_buffer, sizeof(error_buffer));
+ failf(data, "%s%s", cert_problem ? cert_problem : "", error_buffer);
+ return rc;
+ }
+ }
+ else {
+ /* we have been connected fine, we're not waiting for anything else. */
+ connssl->connecting_state = ssl_connect_3;
+
+ /* Informational message */
+ infof (data, "SSL connection using %s\n",
+ SSL_get_cipher(connssl->handle));
+
+ return CURLE_OK;
+ }
+}
+
+static CURLcode
+Curl_ossl_connect_step3(struct connectdata *conn,
+ int sockindex)
+{
+ CURLcode retcode = CURLE_OK;
+ char * str;
+ long lerr;
+ ASN1_TIME *certdate;
+ void *ssl_sessionid=NULL;
+ struct SessionHandle *data = conn->data;
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+
+ curlassert(ssl_connect_3 == connssl->connecting_state);
+
+ if(Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL)) {
+ /* Since this is not a cached session ID, then we want to stach this one
+ in the cache! */
+ SSL_SESSION *our_ssl_sessionid;
+#ifdef HAVE_SSL_GET1_SESSION
+ our_ssl_sessionid = SSL_get1_session(connssl->handle);
+
+ /* SSL_get1_session() will increment the reference
+ count and the session will stay in memory until explicitly freed with
+ SSL_SESSION_free(3), regardless of its state.
+ This function was introduced in openssl 0.9.5a. */
+#else
+ our_ssl_sessionid = SSL_get_session(connssl->handle);
+
+ /* if SSL_get1_session() is unavailable, use SSL_get_session().
+ This is an inferior option because the session can be flushed
+ at any time by openssl. It is included only so curl compiles
+ under versions of openssl < 0.9.5a.
+
+ WARNING: How curl behaves if it's session is flushed is
+ untested.
+ */
+#endif
+ retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid,
+ 0 /* unknown size */);
+ if(retcode) {
+ failf(data, "failed to store ssl session");
+ return retcode;
+ }
+ }
+
+
+ /* Get server's certificate (note: beware of dynamic allocation) - opt */
+ /* major serious hack alert -- we should check certificates
+ * to authenticate the server; otherwise we risk man-in-the-middle
+ * attack
+ */
+
+ connssl->server_cert = SSL_get_peer_certificate(connssl->handle);
+ if(!connssl->server_cert) {
+ failf(data, "SSL: couldn't get peer certificate!");
+ return CURLE_SSL_PEER_CERTIFICATE;
+ }
+ infof (data, "Server certificate:\n");
+
+ str = X509_NAME_oneline(X509_get_subject_name(connssl->server_cert),
+ NULL, 0);
+ if(!str) {
+ failf(data, "SSL: couldn't get X509-subject!");
+ X509_free(connssl->server_cert);
+ connssl->server_cert = NULL;
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+ infof(data, "\t subject: %s\n", str);
+ CRYPTO_free(str);
+
+ certdate = X509_get_notBefore(connssl->server_cert);
+ Curl_ASN1_UTCTIME_output(conn, "\t start date: ", certdate);
+
+ certdate = X509_get_notAfter(connssl->server_cert);
+ Curl_ASN1_UTCTIME_output(conn, "\t expire date: ", certdate);
+
+ if(data->set.ssl.verifyhost) {
+ retcode = verifyhost(conn, connssl->server_cert);
+ if(retcode) {
+ X509_free(connssl->server_cert);
+ connssl->server_cert = NULL;
+ return retcode;
+ }
+ }
+
+ str = X509_NAME_oneline(X509_get_issuer_name(connssl->server_cert),
+ NULL, 0);
+ if(!str) {
+ failf(data, "SSL: couldn't get X509-issuer name!");
+ retcode = CURLE_SSL_CONNECT_ERROR;
+ }
+ else {
+ infof(data, "\t issuer: %s\n", str);
+ CRYPTO_free(str);
+
+ /* We could do all sorts of certificate verification stuff here before
+ deallocating the certificate. */
+
+ lerr = data->set.ssl.certverifyresult=
+ SSL_get_verify_result(connssl->handle);
+ if(data->set.ssl.certverifyresult != X509_V_OK) {
+ if(data->set.ssl.verifypeer) {
+ /* We probably never reach this, because SSL_connect() will fail
+ and we return earlyer if verifypeer is set? */
+ failf(data, "SSL certificate verify result: %s (%ld)",
+ X509_verify_cert_error_string(lerr), lerr);
+ retcode = CURLE_SSL_PEER_CERTIFICATE;
+ }
+ else
+ infof(data, "SSL certificate verify result: %s (%ld),"
+ " continuing anyway.\n",
+ X509_verify_cert_error_string(lerr), lerr);
+ }
+ else
+ infof(data, "SSL certificate verify ok.\n");
+ }
+
+ X509_free(connssl->server_cert);
+ connssl->server_cert = NULL;
+ connssl->connecting_state = ssl_connect_done;
+ return retcode;
+}
+
+static CURLcode
+Curl_ossl_connect_common(struct connectdata *conn,
+ int sockindex,
+ bool nonblocking,
+ bool *done)
+{
+ CURLcode retcode;
+ struct SessionHandle *data = conn->data;
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ curl_socket_t sockfd = conn->sock[sockindex];
+ long timeout_ms;
+
+ if (ssl_connect_1==connssl->connecting_state) {
+ retcode = Curl_ossl_connect_step1(conn, sockindex);
+ if (retcode)
+ return retcode;
+ }
+
+ timeout_ms = 0;
+ while (ssl_connect_2 == connssl->connecting_state ||
+ ssl_connect_2_reading == connssl->connecting_state ||
+ ssl_connect_2_writing == connssl->connecting_state) {
+
+ /* if ssl is expecting something, check if it's available. */
+ if (connssl->connecting_state == ssl_connect_2_reading
+ || connssl->connecting_state == ssl_connect_2_writing) {
+
+ int writefd = ssl_connect_2_writing==
+ connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
+ int readfd = ssl_connect_2_reading==
+ connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
+
+ while(1) {
+ int what = Curl_select(readfd, writefd, nonblocking?0:(int)timeout_ms);
+ if(what > 0)
+ /* readable or writable, go loop in the outer loop */
+ break;
+ else if(0 == what) {
+ if (nonblocking) {
+ *done = FALSE;
+ return CURLE_OK;
+ }
+ else {
+ /* timeout */
+ failf(data, "SSL connection timeout");
+ return CURLE_OPERATION_TIMEDOUT;
+ }
+ }
+ else {
+ /* anything that gets here is fatally bad */
+ failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
+ return CURLE_SSL_CONNECT_ERROR;
+ }
+ } /* while()-loop for the select() */
+ }
+
+ /* get the timeout from step2 to avoid computing it twice. */
+ retcode = Curl_ossl_connect_step2(conn, sockindex, &timeout_ms);
+ if (retcode)
+ return retcode;
+
+ } /* repeat step2 until all transactions are done. */
+
+
+ if (ssl_connect_3==connssl->connecting_state) {
+ retcode = Curl_ossl_connect_step3(conn, sockindex);
+ if (retcode)
+ return retcode;
+ }
+
+ if (ssl_connect_done==connssl->connecting_state) {
+ *done = TRUE;
+ }
+ else {
+ *done = FALSE;
+ }
+
+ /* Reset our connect state machine */
+ connssl->connecting_state = ssl_connect_1;
+
+ return CURLE_OK;
+}
+
+CURLcode
+Curl_ossl_connect_nonblocking(struct connectdata *conn,
+ int sockindex,
+ bool *done)
+{
+ return Curl_ossl_connect_common(conn, sockindex, TRUE, done);
+}
+
+CURLcode
+Curl_ossl_connect(struct connectdata *conn,
+ int sockindex)
+{
+ CURLcode retcode;
+ bool done = FALSE;
+
+ retcode = Curl_ossl_connect_common(conn, sockindex, FALSE, &done);
+ if (retcode)
+ return retcode;
+
+ curlassert(done);
+
+ return CURLE_OK;
+}
+
+/* return number of sent (non-SSL) bytes */
+ssize_t Curl_ossl_send(struct connectdata *conn,
+ int sockindex,
+ void *mem,
+ size_t len)
+{
+ /* SSL_write() is said to return 'int' while write() and send() returns
+ 'size_t' */
+ int err;
+ char error_buffer[120]; /* OpenSSL documents that this must be at least 120
+ bytes long. */
+ unsigned long sslerror;
+ int rc = SSL_write(conn->ssl[sockindex].handle, mem, (int)len);
+
+ if(rc < 0) {
+ err = SSL_get_error(conn->ssl[sockindex].handle, rc);
+
+ switch(err) {
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_WRITE:
+ /* The operation did not complete; the same TLS/SSL I/O function
+ should be called again later. This is basicly an EWOULDBLOCK
+ equivalent. */
+ return 0;
+ case SSL_ERROR_SYSCALL:
+ failf(conn->data, "SSL_write() returned SYSCALL, errno = %d\n",
+ Curl_sockerrno());
+ return -1;
+ case SSL_ERROR_SSL:
+ /* A failure in the SSL library occurred, usually a protocol error.
+ The OpenSSL error queue contains more information on the error. */
+ sslerror = ERR_get_error();
+ failf(conn->data, "SSL_write() error: %s\n",
+ ERR_error_string(sslerror, error_buffer));
+ return -1;
+ }
+ /* a true error */
+ failf(conn->data, "SSL_write() return error %d\n", err);
+ return -1;
+ }
+ return (ssize_t)rc; /* number of bytes */
+}
+
+/*
+ * If the read would block we return -1 and set 'wouldblock' to TRUE.
+ * Otherwise we return the amount of data read. Other errors should return -1
+ * and set 'wouldblock' to FALSE.
+ */
+ssize_t Curl_ossl_recv(struct connectdata *conn, /* connection data */
+ int num, /* socketindex */
+ char *buf, /* store read data here */
+ size_t buffersize, /* max amount to read */
+ bool *wouldblock)
+{
+ char error_buffer[120]; /* OpenSSL documents that this must be at
+ least 120 bytes long. */
+ unsigned long sslerror;
+ ssize_t nread = (ssize_t)SSL_read(conn->ssl[num].handle, buf,
+ (int)buffersize);
+ *wouldblock = FALSE;
+ if(nread < 0) {
+ /* failed SSL_read */
+ int err = SSL_get_error(conn->ssl[num].handle, (int)nread);
+
+ switch(err) {
+ case SSL_ERROR_NONE: /* this is not an error */
+ case SSL_ERROR_ZERO_RETURN: /* no more data */
+ break;
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_WRITE:
+ /* there's data pending, re-invoke SSL_read() */
+ *wouldblock = TRUE;
+ return -1; /* basically EWOULDBLOCK */
+ default:
+ /* openssl/ssl.h says "look at error stack/return value/errno" */
+ sslerror = ERR_get_error();
+ failf(conn->data, "SSL read: %s, errno %d",
+ ERR_error_string(sslerror, error_buffer),
+ Curl_sockerrno() );
+ return -1;
+ }
+ }
+ return nread;
+}
+
+size_t Curl_ossl_version(char *buffer, size_t size)
+{
+#ifdef YASSL_VERSION
+ /* yassl provides an OpenSSL API compatiblity layer so it looks identical
+ to OpenSSL in all other aspects */
+ return snprintf(buffer, size, " yassl/%s", YASSL_VERSION);
+#else /* YASSL_VERSION */
+
+#if (SSLEAY_VERSION_NUMBER >= 0x905000)
+ {
+ char sub[2];
+ unsigned long ssleay_value;
+ sub[1]='\0';
+ ssleay_value=SSLeay();
+ if(ssleay_value < 0x906000) {
+ ssleay_value=SSLEAY_VERSION_NUMBER;
+ sub[0]='\0';
+ }
+ else {
+ if(ssleay_value&0xff0) {
+ sub[0]=(char)(((ssleay_value>>4)&0xff) + 'a' -1);
+ }
+ else
+ sub[0]='\0';
+ }
+
+ return snprintf(buffer, size, " OpenSSL/%lx.%lx.%lx%s",
+ (ssleay_value>>28)&0xf,
+ (ssleay_value>>20)&0xff,
+ (ssleay_value>>12)&0xff,
+ sub);
+ }
+
+#else /* SSLEAY_VERSION_NUMBER is less than 0.9.5 */
+
+#if (SSLEAY_VERSION_NUMBER >= 0x900000)
+ return snprintf(buffer, size, " OpenSSL/%lx.%lx.%lx",
+ (SSLEAY_VERSION_NUMBER>>28)&0xff,
+ (SSLEAY_VERSION_NUMBER>>20)&0xff,
+ (SSLEAY_VERSION_NUMBER>>12)&0xf);
+
+#else /* (SSLEAY_VERSION_NUMBER >= 0x900000) */
+ {
+ char sub[2];
+ sub[1]='\0';
+ if(SSLEAY_VERSION_NUMBER&0x0f) {
+ sub[0]=(SSLEAY_VERSION_NUMBER&0x0f) + 'a' -1;
+ }
+ else
+ sub[0]='\0';
+
+ return snprintf(buffer, size, " SSL/%x.%x.%x%s",
+ (SSLEAY_VERSION_NUMBER>>12)&0xff,
+ (SSLEAY_VERSION_NUMBER>>8)&0xf,
+ (SSLEAY_VERSION_NUMBER>>4)&0xf, sub);
+ }
+#endif /* (SSLEAY_VERSION_NUMBER >= 0x900000) */
+#endif /* SSLEAY_VERSION_NUMBER is less than 0.9.5 */
+
+#endif /* YASSL_VERSION */
+}
+#endif /* USE_SSLEAY */
diff --git a/Utilities/cmcurl/ssluse.h b/Utilities/cmcurl/ssluse.h
new file mode 100644
index 0000000000..5bb7090c57
--- /dev/null
+++ b/Utilities/cmcurl/ssluse.h
@@ -0,0 +1,71 @@
+#ifndef __SSLUSE_H
+#define __SSLUSE_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * This header should only be needed to get included by sslgen.c and ssluse.c
+ */
+
+#include "urldata.h"
+CURLcode Curl_ossl_connect(struct connectdata *conn, int sockindex);
+CURLcode Curl_ossl_connect_nonblocking(struct connectdata *conn,
+ int sockindex,
+ bool *done);
+void Curl_ossl_close(struct connectdata *conn); /* close a SSL connection */
+/* tell OpenSSL to close down all open information regarding connections (and
+ thus session ID caching etc) */
+int Curl_ossl_close_all(struct SessionHandle *data);
+/* Sets an OpenSSL engine */
+CURLcode Curl_ossl_set_engine(struct SessionHandle *data, const char *engine);
+
+/* function provided for the generic SSL-layer, called when a session id
+ should be freed */
+void Curl_ossl_session_free(void *ptr);
+
+/* Sets engine as default for all SSL operations */
+CURLcode Curl_ossl_set_engine_default(struct SessionHandle *data);
+
+/* Build list of OpenSSL engines */
+struct curl_slist *Curl_ossl_engines_list(struct SessionHandle *data);
+
+int Curl_ossl_init(void);
+void Curl_ossl_cleanup(void);
+
+ssize_t Curl_ossl_send(struct connectdata *conn,
+ int sockindex,
+ void *mem,
+ size_t len);
+ssize_t Curl_ossl_recv(struct connectdata *conn, /* connection data */
+ int num, /* socketindex */
+ char *buf, /* store read data here */
+ size_t buffersize, /* max amount to read */
+ bool *wouldblock);
+
+size_t Curl_ossl_version(char *buffer, size_t size);
+int Curl_ossl_check_cxn(struct connectdata *cxn);
+int Curl_ossl_seed(struct SessionHandle *data);
+
+int Curl_ossl_shutdown(struct connectdata *conn, int sockindex);
+
+#endif
diff --git a/Utilities/cmcurl/strdup.c b/Utilities/cmcurl/strdup.c
new file mode 100644
index 0000000000..e16e08a727
--- /dev/null
+++ b/Utilities/cmcurl/strdup.c
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+#include "strdup.h"
+
+#ifndef HAVE_STRDUP
+char *curlx_strdup(const char *str)
+{
+ int len;
+ char *newstr;
+
+ if (!str)
+ return (char *)NULL;
+
+ len = strlen(str);
+ newstr = (char *) malloc((len+1)*sizeof(char));
+ if (!newstr)
+ return (char *)NULL;
+
+ strcpy(newstr,str);
+
+ return newstr;
+
+}
+#endif
diff --git a/Utilities/cmcurl/strdup.h b/Utilities/cmcurl/strdup.h
new file mode 100644
index 0000000000..3206db3cfd
--- /dev/null
+++ b/Utilities/cmcurl/strdup.h
@@ -0,0 +1,34 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifndef _CURL_STRDUP_H
+#define _CURL_STRDUP_H
+
+#include "setup.h"
+
+#ifndef HAVE_STRDUP
+extern char *curlx_strdup(const char *str);
+#endif
+
+#endif
+
diff --git a/Utilities/cmcurl/strequal.c b/Utilities/cmcurl/strequal.c
new file mode 100644
index 0000000000..83796f6673
--- /dev/null
+++ b/Utilities/cmcurl/strequal.c
@@ -0,0 +1,101 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+#include <ctype.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#include "strequal.h"
+
+#if defined(HAVE_STRCASECMP) && defined(__STRICT_ANSI__)
+/* this is for "-ansi -Wall -pedantic" to stop complaining! */
+extern int (strcasecmp)(const char *s1, const char *s2);
+extern int (strncasecmp)(const char *s1, const char *s2, size_t n);
+#endif
+
+int curl_strequal(const char *first, const char *second)
+{
+#if defined(HAVE_STRCASECMP)
+ return !(strcasecmp)(first, second);
+#elif defined(HAVE_STRCMPI)
+ return !(strcmpi)(first, second);
+#elif defined(HAVE_STRICMP)
+ return !(stricmp)(first, second);
+#else
+ while (*first && *second) {
+ if (toupper(*first) != toupper(*second)) {
+ break;
+ }
+ first++;
+ second++;
+ }
+ return toupper(*first) == toupper(*second);
+#endif
+}
+
+int curl_strnequal(const char *first, const char *second, size_t max)
+{
+#if defined(HAVE_STRCASECMP)
+ return !strncasecmp(first, second, max);
+#elif defined(HAVE_STRCMPI)
+ return !strncmpi(first, second, max);
+#elif defined(HAVE_STRICMP)
+ return !strnicmp(first, second, max);
+#else
+ while (*first && *second && max) {
+ if (toupper(*first) != toupper(*second)) {
+ break;
+ }
+ max--;
+ first++;
+ second++;
+ }
+ if(0 == max)
+ return 1; /* they are equal this far */
+
+ return toupper(*first) == toupper(*second);
+#endif
+}
+
+/*
+ * Curl_strcasestr() finds the first occurrence of the substring needle in the
+ * string haystack. The terminating `\0' characters are not compared. The
+ * matching is done CASE INSENSITIVE, which thus is the difference between
+ * this and strstr().
+ */
+char *Curl_strcasestr(const char *haystack, const char *needle)
+{
+ size_t nlen = strlen(needle);
+ size_t hlen = strlen(haystack);
+
+ while(hlen-- >= nlen) {
+ if(curl_strnequal(haystack, needle, nlen))
+ return (char *)haystack;
+ haystack++;
+ }
+ return NULL;
+}
diff --git a/Utilities/cmcurl/strequal.h b/Utilities/cmcurl/strequal.h
new file mode 100644
index 0000000000..6718c3c0ed
--- /dev/null
+++ b/Utilities/cmcurl/strequal.h
@@ -0,0 +1,38 @@
+#ifndef __STREQUAL_H
+#define __STREQUAL_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include <curl/curl.h>
+
+#define strequal(a,b) curl_strequal(a,b)
+#define strnequal(a,b,c) curl_strnequal(a,b,c)
+
+/* checkprefix() is a shorter version of the above, used when the first
+ argument is zero-byte terminated */
+#define checkprefix(a,b) strnequal(a,b,strlen(a))
+
+/* case insensitive strstr() */
+char *Curl_strcasestr(const char *haystack, const char *needle);
+
+#endif
diff --git a/Utilities/cmcurl/strerror.c b/Utilities/cmcurl/strerror.c
new file mode 100644
index 0000000000..74c3457795
--- /dev/null
+++ b/Utilities/cmcurl/strerror.c
@@ -0,0 +1,751 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 2004 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifdef HAVE_STRERROR_R
+#if !defined(HAVE_POSIX_STRERROR_R) && !defined(HAVE_GLIBC_STRERROR_R)
+#error "you MUST have either POSIX or glibc strerror_r if strerror_r is found"
+#endif /* !POSIX && !glibc */
+#endif /* HAVE_STRERROR_R */
+
+#include <curl/curl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#ifdef USE_LIBIDN
+#include <idna.h>
+#endif
+
+#include "strerror.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#if defined(HAVE_STRERROR_R) && defined(HAVE_NO_STRERROR_R_DECL)
+#ifdef HAVE_POSIX_STRERROR_R
+/* seen on AIX 5100-02 gcc 2.9 */
+extern int strerror_r(int errnum, char *strerrbuf, size_t buflen);
+#else
+extern char *strerror_r(int errnum, char *buf, size_t buflen);
+#endif
+#endif
+
+const char *
+curl_easy_strerror(CURLcode error)
+{
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
+ switch (error) {
+ case CURLE_OK:
+ return "no error";
+
+ case CURLE_UNSUPPORTED_PROTOCOL:
+ return "unsupported protocol";
+
+ case CURLE_FAILED_INIT:
+ return "failed init";
+
+ case CURLE_URL_MALFORMAT:
+ return "URL using bad/illegal format or missing URL";
+
+ case CURLE_NOT_BUILT_IN:
+ return "A requested feature, protocol or option was not found built-in in"
+ " this libcurl due to a build-time decision.";
+
+ case CURLE_COULDNT_RESOLVE_PROXY:
+ return "couldn't resolve proxy name";
+
+ case CURLE_COULDNT_RESOLVE_HOST:
+ return "couldn't resolve host name";
+
+ case CURLE_COULDNT_CONNECT:
+ return "couldn't connect to server";
+
+ case CURLE_FTP_WEIRD_SERVER_REPLY:
+ return "FTP: weird server reply";
+
+ case CURLE_FTP_ACCESS_DENIED:
+ return "FTP: access denied";
+
+ case CURLE_FTP_WEIRD_PASS_REPLY:
+ return "FTP: unknown PASS reply";
+
+ case CURLE_FTP_WEIRD_USER_REPLY:
+ return "FTP: unknown USER reply";
+
+ case CURLE_FTP_WEIRD_PASV_REPLY:
+ return "FTP: unknown PASV reply";
+
+ case CURLE_FTP_WEIRD_227_FORMAT:
+ return "FTP: unknown 227 response format";
+
+ case CURLE_FTP_CANT_GET_HOST:
+ return "FTP: can't figure out the host in the PASV response";
+
+ case CURLE_FTP_CANT_RECONNECT:
+ return "FTP: can't connect to server the response code is unknown";
+
+ case CURLE_FTP_COULDNT_SET_BINARY:
+ return "FTP: couldn't set binary mode";
+
+ case CURLE_PARTIAL_FILE:
+ return "Transferred a partial file";
+
+ case CURLE_FTP_COULDNT_RETR_FILE:
+ return "FTP: couldn't retrieve (RETR failed) the specified file";
+
+ case CURLE_FTP_WRITE_ERROR:
+ return "FTP: the post-transfer acknowledge response was not OK";
+
+ case CURLE_FTP_QUOTE_ERROR:
+ return "FTP: a quote command returned error";
+
+ case CURLE_HTTP_RETURNED_ERROR:
+ return "HTTP response code said error";
+
+ case CURLE_WRITE_ERROR:
+ return "failed writing received data to disk/application";
+
+ case CURLE_FTP_COULDNT_STOR_FILE:
+ return "failed FTP upload (the STOR command)";
+
+ case CURLE_READ_ERROR:
+ return "failed to open/read local data from file/application";
+
+ case CURLE_OUT_OF_MEMORY:
+#ifdef CURL_DOES_CONVERSIONS
+ return "conversion failed -or- out of memory";
+#else
+ return "out of memory";
+#endif /* CURL_DOES_CONVERSIONS */
+
+ case CURLE_OPERATION_TIMEOUTED:
+ return "a timeout was reached";
+
+ case CURLE_FTP_COULDNT_SET_ASCII:
+ return "FTP could not set ASCII mode (TYPE A)";
+
+ case CURLE_FTP_PORT_FAILED:
+ return "FTP command PORT failed";
+
+ case CURLE_FTP_COULDNT_USE_REST:
+ return "FTP command REST failed";
+
+ case CURLE_FTP_COULDNT_GET_SIZE:
+ return "FTP command SIZE failed";
+
+ case CURLE_HTTP_RANGE_ERROR:
+ return "a range was requested but the server did not deliver it";
+
+ case CURLE_HTTP_POST_ERROR:
+ return "internal problem setting up the POST";
+
+ case CURLE_SSL_CONNECT_ERROR:
+ return "SSL connect error";
+
+ case CURLE_BAD_DOWNLOAD_RESUME:
+ return "couldn't resume download";
+
+ case CURLE_FILE_COULDNT_READ_FILE:
+ return "couldn't read a file:// file";
+
+ case CURLE_LDAP_CANNOT_BIND:
+ return "LDAP: cannot bind";
+
+ case CURLE_LDAP_SEARCH_FAILED:
+ return "LDAP: search failed";
+
+ case CURLE_LIBRARY_NOT_FOUND:
+ return "a required shared library was not found";
+
+ case CURLE_FUNCTION_NOT_FOUND:
+ return "a required function in the shared library was not found";
+
+ case CURLE_ABORTED_BY_CALLBACK:
+ return "the operation was aborted by an application callback";
+
+ case CURLE_BAD_FUNCTION_ARGUMENT:
+ return "a libcurl function was given a bad argument";
+
+ case CURLE_INTERFACE_FAILED:
+ return "failed binding local connection end";
+
+ case CURLE_TOO_MANY_REDIRECTS :
+ return "number of redirects hit maximum amount";
+
+ case CURLE_UNKNOWN_TELNET_OPTION:
+ return "User specified an unknown option";
+
+ case CURLE_TELNET_OPTION_SYNTAX :
+ return "Malformed telnet option";
+
+ case CURLE_SSL_PEER_CERTIFICATE:
+ return "SSL peer certificate was not ok";
+
+ case CURLE_GOT_NOTHING:
+ return "server returned nothing (no headers, no data)";
+
+ case CURLE_SSL_ENGINE_NOTFOUND:
+ return "SSL crypto engine not found";
+
+ case CURLE_SSL_ENGINE_SETFAILED:
+ return "can not set SSL crypto engine as default";
+
+ case CURLE_SSL_ENGINE_INITFAILED:
+ return "failed to initialise SSL crypto engine";
+
+ case CURLE_SEND_ERROR:
+ return "failed sending data to the peer";
+
+ case CURLE_RECV_ERROR:
+ return "failure when receiving data from the peer";
+
+ case CURLE_SHARE_IN_USE:
+ return "share is already in use";
+
+ case CURLE_SSL_CERTPROBLEM:
+ return "problem with the local SSL certificate";
+
+ case CURLE_SSL_CIPHER:
+ return "couldn't use specified SSL cipher";
+
+ case CURLE_SSL_CACERT:
+ return "peer certificate cannot be authenticated with known CA certificates";
+
+ case CURLE_SSL_CACERT_BADFILE:
+ return "problem with the SSL CA cert (path? access rights?)";
+
+ case CURLE_BAD_CONTENT_ENCODING:
+ return "Unrecognized HTTP Content-Encoding";
+
+ case CURLE_LDAP_INVALID_URL:
+ return "Invalid LDAP URL";
+
+ case CURLE_FILESIZE_EXCEEDED:
+ return "Maximum file size exceeded";
+
+ case CURLE_FTP_SSL_FAILED:
+ return "Requested FTP SSL level failed";
+
+ case CURLE_SSL_SHUTDOWN_FAILED:
+ return "Failed to shut down the SSL connection";
+
+ case CURLE_SEND_FAIL_REWIND:
+ return "Send failed since rewinding of the data stream failed";
+
+ case CURLE_LOGIN_DENIED:
+ return "FTP: login denied";
+
+ case CURLE_TFTP_NOTFOUND:
+ return "TFTP: File Not Found";
+
+ case CURLE_TFTP_PERM:
+ return "TFTP: Access Violation";
+
+ case CURLE_TFTP_DISKFULL:
+ return "TFTP: Disk full or allocation exceeded";
+
+ case CURLE_TFTP_ILLEGAL:
+ return "TFTP: Illegal operation";
+
+ case CURLE_TFTP_UNKNOWNID:
+ return "TFTP: Unknown transfer ID";
+
+ case CURLE_TFTP_EXISTS:
+ return "TFTP: File already exists";
+
+ case CURLE_TFTP_NOSUCHUSER:
+ return "TFTP: No such user";
+
+ case CURLE_CONV_FAILED:
+ return "conversion failed";
+
+ case CURLE_CONV_REQD:
+ return "caller must register CURLOPT_CONV_ callback options";
+
+ case CURLE_REMOTE_FILE_NOT_FOUND:
+ return "Remote file not found";
+
+ case CURLE_SSH:
+ return "Error in the SSH layer";
+
+ /* error codes not used by current libcurl */
+ case CURLE_FTP_USER_PASSWORD_INCORRECT:
+ case CURLE_MALFORMAT_USER:
+ case CURLE_BAD_CALLING_ORDER:
+ case CURLE_BAD_PASSWORD_ENTERED:
+ case CURLE_OBSOLETE:
+ case CURL_LAST:
+ break;
+ }
+ /*
+ * By using a switch, gcc -Wall will complain about enum values
+ * which do not appear, helping keep this function up-to-date.
+ * By using gcc -Wall -Werror, you can't forget.
+ *
+ * A table would not have the same benefit. Most compilers will
+ * generate code very similar to a table in any case, so there
+ * is little performance gain from a table. And something is broken
+ * for the user's application, anyways, so does it matter how fast
+ * it _doesn't_ work?
+ *
+ * The line number for the error will be near this comment, which
+ * is why it is here, and not at the start of the switch.
+ */
+ return "unknown error";
+#else
+ if (error == CURLE_OK)
+ return "no error";
+ else
+ return "error";
+#endif
+}
+
+const char *
+curl_multi_strerror(CURLMcode error)
+{
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
+ switch (error) {
+ case CURLM_CALL_MULTI_PERFORM:
+ return "please call curl_multi_perform() soon";
+
+ case CURLM_OK:
+ return "no error";
+
+ case CURLM_BAD_HANDLE:
+ return "invalid multi handle";
+
+ case CURLM_BAD_EASY_HANDLE:
+ return "invalid easy handle";
+
+ case CURLM_OUT_OF_MEMORY:
+ return "out of memory";
+
+ case CURLM_INTERNAL_ERROR:
+ return "internal error";
+
+ case CURLM_BAD_SOCKET:
+ return "invalid socket argument";
+
+ case CURLM_UNKNOWN_OPTION:
+ return "unknown option";
+
+ case CURLM_LAST:
+ break;
+ }
+
+ return "unknown error";
+#else
+ if (error == CURLM_OK)
+ return "no error";
+ else
+ return "error";
+#endif
+}
+
+const char *
+curl_share_strerror(CURLSHcode error)
+{
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
+ switch (error) {
+ case CURLSHE_OK:
+ return "no error";
+
+ case CURLSHE_BAD_OPTION:
+ return "unknown share option";
+
+ case CURLSHE_IN_USE:
+ return "share currently in use";
+
+ case CURLSHE_INVALID:
+ return "invalid share handle";
+
+ case CURLSHE_NOMEM:
+ return "out of memory";
+
+ case CURLSHE_LAST:
+ break;
+ }
+
+ return "CURLSH unknown";
+#else
+ if (error == CURLSHE_OK)
+ return "no error";
+ else
+ return "error";
+#endif
+}
+
+#ifdef USE_WINSOCK
+
+/* This function handles most / all (?) Winsock errors cURL is able to produce.
+ */
+static const char *
+get_winsock_error (int err, char *buf, size_t len)
+{
+ const char *p;
+
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
+ switch (err) {
+ case WSAEINTR:
+ p = "Call interrupted.";
+ break;
+ case WSAEBADF:
+ p = "Bad file";
+ break;
+ case WSAEACCES:
+ p = "Bad access";
+ break;
+ case WSAEFAULT:
+ p = "Bad argument";
+ break;
+ case WSAEINVAL:
+ p = "Invalid arguments";
+ break;
+ case WSAEMFILE:
+ p = "Out of file descriptors";
+ break;
+ case WSAEWOULDBLOCK:
+ p = "Call would block";
+ break;
+ case WSAEINPROGRESS:
+ case WSAEALREADY:
+ p = "Blocking call in progress";
+ break;
+ case WSAENOTSOCK:
+ p = "Descriptor is not a socket.";
+ break;
+ case WSAEDESTADDRREQ:
+ p = "Need destination address";
+ break;
+ case WSAEMSGSIZE:
+ p = "Bad message size";
+ break;
+ case WSAEPROTOTYPE:
+ p = "Bad protocol";
+ break;
+ case WSAENOPROTOOPT:
+ p = "Protocol option is unsupported";
+ break;
+ case WSAEPROTONOSUPPORT:
+ p = "Protocol is unsupported";
+ break;
+ case WSAESOCKTNOSUPPORT:
+ p = "Socket is unsupported";
+ break;
+ case WSAEOPNOTSUPP:
+ p = "Operation not supported";
+ break;
+ case WSAEAFNOSUPPORT:
+ p = "Address family not supported";
+ break;
+ case WSAEPFNOSUPPORT:
+ p = "Protocol family not supported";
+ break;
+ case WSAEADDRINUSE:
+ p = "Address already in use";
+ break;
+ case WSAEADDRNOTAVAIL:
+ p = "Address not available";
+ break;
+ case WSAENETDOWN:
+ p = "Network down";
+ break;
+ case WSAENETUNREACH:
+ p = "Network unreachable";
+ break;
+ case WSAENETRESET:
+ p = "Network has been reset";
+ break;
+ case WSAECONNABORTED:
+ p = "Connection was aborted";
+ break;
+ case WSAECONNRESET:
+ p = "Connection was reset";
+ break;
+ case WSAENOBUFS:
+ p = "No buffer space";
+ break;
+ case WSAEISCONN:
+ p = "Socket is already connected";
+ break;
+ case WSAENOTCONN:
+ p = "Socket is not connected";
+ break;
+ case WSAESHUTDOWN:
+ p = "Socket has been shut down";
+ break;
+ case WSAETOOMANYREFS:
+ p = "Too many references";
+ break;
+ case WSAETIMEDOUT:
+ p = "Timed out";
+ break;
+ case WSAECONNREFUSED:
+ p = "Connection refused";
+ break;
+ case WSAELOOP:
+ p = "Loop??";
+ break;
+ case WSAENAMETOOLONG:
+ p = "Name too long";
+ break;
+ case WSAEHOSTDOWN:
+ p = "Host down";
+ break;
+ case WSAEHOSTUNREACH:
+ p = "Host unreachable";
+ break;
+ case WSAENOTEMPTY:
+ p = "Not empty";
+ break;
+ case WSAEPROCLIM:
+ p = "Process limit reached";
+ break;
+ case WSAEUSERS:
+ p = "Too many users";
+ break;
+ case WSAEDQUOT:
+ p = "Bad quota";
+ break;
+ case WSAESTALE:
+ p = "Something is stale";
+ break;
+ case WSAEREMOTE:
+ p = "Remote error";
+ break;
+#ifdef WSAEDISCON /* missing in SalfordC! */
+ case WSAEDISCON:
+ p = "Disconnected";
+ break;
+#endif
+ /* Extended Winsock errors */
+ case WSASYSNOTREADY:
+ p = "Winsock library is not ready";
+ break;
+ case WSANOTINITIALISED:
+ p = "Winsock library not initialised";
+ break;
+ case WSAVERNOTSUPPORTED:
+ p = "Winsock version not supported.";
+ break;
+
+ /* getXbyY() errors (already handled in herrmsg):
+ * Authoritative Answer: Host not found */
+ case WSAHOST_NOT_FOUND:
+ p = "Host not found";
+ break;
+
+ /* Non-Authoritative: Host not found, or SERVERFAIL */
+ case WSATRY_AGAIN:
+ p = "Host not found, try again";
+ break;
+
+ /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
+ case WSANO_RECOVERY:
+ p = "Unrecoverable error in call to nameserver";
+ break;
+
+ /* Valid name, no data record of requested type */
+ case WSANO_DATA:
+ p = "No data record of requested type";
+ break;
+
+ default:
+ return NULL;
+ }
+#else
+ if (error == CURLE_OK)
+ return NULL;
+ else
+ p = "error";
+#endif
+ strncpy (buf, p, len);
+ buf [len-1] = '\0';
+ return buf;
+}
+#endif /* USE_WINSOCK */
+
+/*
+ * Our thread-safe and smart strerror() replacement.
+ *
+ * The 'err' argument passed in to this function MUST be a true errno number
+ * as reported on this system. We do no range checking on the number before
+ * we pass it to the "number-to-message" convertion function and there might
+ * be systems that don't do proper range checking in there themselves.
+ *
+ * We don't do range checking (on systems other than Windows) since there is
+ * no good reliable and portable way to do it.
+ */
+const char *Curl_strerror(struct connectdata *conn, int err)
+{
+ char *buf, *p;
+ size_t max;
+
+ curlassert(conn);
+ curlassert(err >= 0);
+
+ buf = conn->syserr_buf;
+ max = sizeof(conn->syserr_buf)-1;
+ *buf = '\0';
+
+#ifdef USE_WINSOCK
+
+#ifdef _WIN32_WCE
+ buf[0]=0;
+ {
+ wchar_t wbuf[256];
+
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
+ LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
+ wcstombs(buf,wbuf,max);
+ }
+
+#else
+
+ /* 'sys_nerr' is the maximum errno number, it is not widely portable */
+ if (err >= 0 && err < sys_nerr)
+ strncpy(buf, strerror(err), max);
+ else {
+ if (!get_winsock_error(err, buf, max) &&
+ !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
+ LANG_NEUTRAL, buf, (DWORD)max, NULL))
+ snprintf(buf, max, "Unknown error %d (%#x)", err, err);
+ }
+#endif
+#else /* not USE_WINSOCK coming up */
+
+ /* These should be atomic and hopefully thread-safe */
+#ifdef HAVE_STRERROR_R
+ /* There are two different APIs for strerror_r(). The POSIX and the GLIBC
+ versions. */
+#ifdef HAVE_POSIX_STRERROR_R
+ strerror_r(err, buf, max);
+ /* this may set errno to ERANGE if insufficient storage was supplied via
+ 'strerrbuf' and 'buflen' to contain the generated message string, or
+ EINVAL if the value of 'errnum' is not a valid error number.*/
+#else
+ {
+ /* HAVE_GLIBC_STRERROR_R */
+ char buffer[256];
+ char *msg = strerror_r(err, buffer, sizeof(buffer));
+ /* this version of strerror_r() only *might* use the buffer we pass to
+ the function, but it always returns the error message as a pointer,
+ so we must copy that string unconditionally (if non-NULL) */
+ if(msg)
+ strncpy(buf, msg, max);
+ else
+ snprintf(buf, max, "Unknown error %d", err);
+ }
+#endif /* end of HAVE_GLIBC_STRERROR_R */
+#else /* HAVE_STRERROR_R */
+ strncpy(buf, strerror(err), max);
+#endif /* end of HAVE_STRERROR_R */
+#endif /* end of ! USE_WINSOCK */
+
+ buf[max] = '\0'; /* make sure the string is zero terminated */
+
+ /* strip trailing '\r\n' or '\n'. */
+ if ((p = strrchr(buf,'\n')) != NULL && (p - buf) >= 2)
+ *p = '\0';
+ if ((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1)
+ *p = '\0';
+ return buf;
+}
+
+#ifdef USE_LIBIDN
+/*
+ * Return error-string for libidn status as returned from idna_to_ascii_lz().
+ */
+const char *Curl_idn_strerror (struct connectdata *conn, int err)
+{
+#ifdef HAVE_IDNA_STRERROR
+ (void)conn;
+ return idna_strerror((Idna_rc) err);
+#else
+ const char *str;
+ char *buf;
+ size_t max;
+
+ curlassert(conn);
+
+ buf = conn->syserr_buf;
+ max = sizeof(conn->syserr_buf)-1;
+
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
+ switch ((Idna_rc)err) {
+ case IDNA_SUCCESS:
+ str = "No error";
+ break;
+ case IDNA_STRINGPREP_ERROR:
+ str = "Error in string preparation";
+ break;
+ case IDNA_PUNYCODE_ERROR:
+ str = "Error in Punycode operation";
+ break;
+ case IDNA_CONTAINS_NON_LDH:
+ str = "Illegal ASCII characters";
+ break;
+ case IDNA_CONTAINS_MINUS:
+ str = "Contains minus";
+ break;
+ case IDNA_INVALID_LENGTH:
+ str = "Invalid output length";
+ break;
+ case IDNA_NO_ACE_PREFIX:
+ str = "No ACE prefix (\"xn--\")";
+ break;
+ case IDNA_ROUNDTRIP_VERIFY_ERROR:
+ str = "Roundtrip verify error";
+ break;
+ case IDNA_CONTAINS_ACE_PREFIX:
+ str = "Already have ACE prefix (\"xn--\")";
+ break;
+ case IDNA_ICONV_ERROR:
+ str = "Locale conversion failed";
+ break;
+ case IDNA_MALLOC_ERROR:
+ str = "Allocation failed";
+ break;
+ case IDNA_DLOPEN_ERROR:
+ str = "dlopen() error";
+ break;
+ default:
+ snprintf(buf, max, "error %d", (int)err);
+ str = NULL;
+ break;
+ }
+#else
+ if ((Idna_rc)err == IDNA_SUCCESS)
+ str = "No error";
+ else
+ str = "error";
+#endif
+ if (str)
+ strncpy(buf, str, max);
+ buf[max] = '\0';
+ return (buf);
+#endif
+}
+#endif /* USE_LIBIDN */
diff --git a/Utilities/cmcurl/strerror.h b/Utilities/cmcurl/strerror.h
new file mode 100644
index 0000000000..b280504377
--- /dev/null
+++ b/Utilities/cmcurl/strerror.h
@@ -0,0 +1,34 @@
+#ifndef __CURL_STRERROR_H
+#define __CURL_STRERROR_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "urldata.h"
+
+const char *Curl_strerror (struct connectdata *conn, int err);
+
+#ifdef USE_LIBIDN
+const char *Curl_idn_strerror (struct connectdata *conn, int err);
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/strtok.c b/Utilities/cmcurl/strtok.c
new file mode 100644
index 0000000000..630e4e0295
--- /dev/null
+++ b/Utilities/cmcurl/strtok.c
@@ -0,0 +1,68 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef HAVE_STRTOK_R
+#include <stddef.h>
+#include <string.h>
+
+#include "strtok.h"
+
+char *
+Curl_strtok_r(char *ptr, const char *sep, char **end)
+{
+ if (!ptr)
+ /* we got NULL input so then we get our last position instead */
+ ptr = *end;
+
+ /* pass all letters that are including in the separator string */
+ while (*ptr && strchr(sep, *ptr))
+ ++ptr;
+
+ if (*ptr) {
+ /* so this is where the next piece of string starts */
+ char *start = ptr;
+
+ /* set the end pointer to the first byte after the start */
+ *end = start + 1;
+
+ /* scan through the string to find where it ends, it ends on a
+ null byte or a character that exists in the separator string */
+ while (**end && !strchr(sep, **end))
+ ++*end;
+
+ if (**end) {
+ /* the end is not a null byte */
+ **end = '\0'; /* zero terminate it! */
+ ++*end; /* advance the last pointer to beyond the null byte */
+ }
+
+ return start; /* return the position where the string starts */
+ }
+
+ /* we ended up on a null byte, there are no more strings to find! */
+ return NULL;
+}
+
+#endif /* this was only compiled if strtok_r wasn't present */
diff --git a/Utilities/cmcurl/strtok.h b/Utilities/cmcurl/strtok.h
new file mode 100644
index 0000000000..cf9fac8c79
--- /dev/null
+++ b/Utilities/cmcurl/strtok.h
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifndef _CURL_STRTOK_R_H
+#define _CURL_STRTOK_R_H
+
+#include "setup.h"
+#include <stddef.h>
+
+#ifndef HAVE_STRTOK_R
+char *Curl_strtok_r(char *s, const char *delim, char **last);
+#define strtok_r Curl_strtok_r
+#else
+#include <string.h>
+#endif
+
+#endif
+
diff --git a/Utilities/cmcurl/strtoofft.c b/Utilities/cmcurl/strtoofft.c
new file mode 100644
index 0000000000..3ab1bfdff2
--- /dev/null
+++ b/Utilities/cmcurl/strtoofft.c
@@ -0,0 +1,165 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+#include "strtoofft.h"
+
+/*
+ * NOTE:
+ *
+ * In the ISO C standard (IEEE Std 1003.1), there is a strtoimax() function we
+ * could use in case strtoll() doesn't exist... See
+ * http://www.opengroup.org/onlinepubs/009695399/functions/strtoimax.html
+ */
+
+#ifdef NEED_CURL_STRTOLL
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+
+static int get_char(char c, int base);
+
+/**
+ * Emulated version of the strtoll function. This extracts a long long
+ * value from the given input string and returns it.
+ */
+curl_off_t
+curlx_strtoll(const char *nptr, char **endptr, int base)
+{
+ char *end;
+ int is_negative = 0;
+ int overflow;
+ int i;
+ curl_off_t value = 0;
+ curl_off_t newval;
+
+ /* Skip leading whitespace. */
+ end = (char *)nptr;
+ while (ISSPACE(end[0])) {
+ end++;
+ }
+
+ /* Handle the sign, if any. */
+ if (end[0] == '-') {
+ is_negative = 1;
+ end++;
+ }
+ else if (end[0] == '+') {
+ end++;
+ }
+ else if (end[0] == '\0') {
+ /* We had nothing but perhaps some whitespace -- there was no number. */
+ if (endptr) {
+ *endptr = end;
+ }
+ return 0;
+ }
+
+ /* Handle special beginnings, if present and allowed. */
+ if (end[0] == '0' && end[1] == 'x') {
+ if (base == 16 || base == 0) {
+ end += 2;
+ base = 16;
+ }
+ }
+ else if (end[0] == '0') {
+ if (base == 8 || base == 0) {
+ end++;
+ base = 8;
+ }
+ }
+
+ /* Matching strtol, if the base is 0 and it doesn't look like
+ * the number is octal or hex, we assume it's base 10.
+ */
+ if (base == 0) {
+ base = 10;
+ }
+
+ /* Loop handling digits. */
+ value = 0;
+ overflow = 0;
+ for (i = get_char(end[0], base);
+ i != -1;
+ end++, i = get_char(end[0], base)) {
+ newval = base * value + i;
+ if (newval < value) {
+ /* We've overflowed. */
+ overflow = 1;
+ break;
+ }
+ else
+ value = newval;
+ }
+
+ if (!overflow) {
+ if (is_negative) {
+ /* Fix the sign. */
+ value *= -1;
+ }
+ }
+ else {
+ if (is_negative)
+ value = CURL_LLONG_MIN;
+ else
+ value = CURL_LLONG_MAX;
+
+ errno = ERANGE;
+ }
+
+ if (endptr)
+ *endptr = end;
+
+ return value;
+}
+
+/**
+ * Returns the value of c in the given base, or -1 if c cannot
+ * be interpreted properly in that base (i.e., is out of range,
+ * is a null, etc.).
+ *
+ * @param c the character to interpret according to base
+ * @param base the base in which to interpret c
+ *
+ * @return the value of c in base, or -1 if c isn't in range
+ */
+static int get_char(char c, int base)
+{
+ int value = -1;
+ if (c <= '9' && c >= '0') {
+ value = c - '0';
+ }
+ else if (c <= 'Z' && c >= 'A') {
+ value = c - 'A' + 10;
+ }
+ else if (c <= 'z' && c >= 'a') {
+ value = c - 'a' + 10;
+ }
+
+ if (value >= base) {
+ value = -1;
+ }
+
+ return value;
+}
+#endif /* Only present if we need strtoll, but don't have it. */
diff --git a/Utilities/cmcurl/strtoofft.h b/Utilities/cmcurl/strtoofft.h
new file mode 100644
index 0000000000..e27b43261f
--- /dev/null
+++ b/Utilities/cmcurl/strtoofft.h
@@ -0,0 +1,73 @@
+#ifndef _CURL_STRTOOFFT_H
+#define _CURL_STRTOOFFT_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * CAUTION: this header is designed to work when included by the app-side
+ * as well as the library. Do not mix with library internals!
+ */
+
+#include "setup.h"
+#include <stddef.h>
+#include <curl/curl.h> /* for the curl_off_t type */
+
+/* Determine what type of file offset conversion handling we wish to use. For
+ * systems with a 32-bit curl_off_t type, we should use strtol. For systems
+ * with a 64-bit curl_off_t type, we should use strtoll if it exists, and if
+ * not, should try to emulate its functionality. At any rate, we define
+ * 'strtoofft' such that it can be used to work with curl_off_t's regardless.
+ */
+#if (SIZEOF_CURL_OFF_T > 4) && (SIZEOF_LONG < 8)
+#if HAVE_STRTOLL
+#define curlx_strtoofft strtoll
+#else /* HAVE_STRTOLL */
+
+/* For MSVC7 we can use _strtoi64() which seems to be a strtoll() clone */
+#if defined(_MSC_VER) && (_MSC_VER >= 1300)
+#define curlx_strtoofft _strtoi64
+#else /* MSVC7 or later */
+curl_off_t curlx_strtoll(const char *nptr, char **endptr, int base);
+#define curlx_strtoofft curlx_strtoll
+#define NEED_CURL_STRTOLL
+#endif /* MSVC7 or later */
+
+#endif /* HAVE_STRTOLL */
+#else /* (SIZEOF_CURL_OFF_T > 4) && (SIZEOF_LONG < 8) */
+/* simply use strtol() to get numbers, either 32 or 64 bit */
+#define curlx_strtoofft strtol
+#endif
+
+#if defined(_MSC_VER) || defined(__WATCOMC__)
+#define CURL_LLONG_MIN 0x8000000000000000i64
+#define CURL_LLONG_MAX 0x7FFFFFFFFFFFFFFFi64
+#elif defined(HAVE_LL)
+#define CURL_LLONG_MIN 0x8000000000000000LL
+#define CURL_LLONG_MAX 0x7FFFFFFFFFFFFFFFLL
+#else
+#define CURL_LLONG_MIN 0x8000000000000000L
+#define CURL_LLONG_MAX 0x7FFFFFFFFFFFFFFFL
+#endif
+
+#endif
+
diff --git a/Utilities/cmcurl/telnet.c b/Utilities/cmcurl/telnet.c
new file mode 100644
index 0000000000..97d22b788a
--- /dev/null
+++ b/Utilities/cmcurl/telnet.c
@@ -0,0 +1,1403 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_TELNET
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#if defined(WIN32)
+#include <time.h>
+#include <io.h>
+#else
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <netinet/in.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <netdb.h>
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#include <sys/ioctl.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+
+#endif
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "transfer.h"
+#include "sendf.h"
+#include "telnet.h"
+#include "connect.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#define TELOPTS
+#define TELCMDS
+
+#include "arpa_telnet.h"
+#include "memory.h"
+#include "select.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#define SUBBUFSIZE 512
+
+#define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer;
+#define CURL_SB_TERM(x) { x->subend = x->subpointer; CURL_SB_CLEAR(x); }
+#define CURL_SB_ACCUM(x,c) \
+ if (x->subpointer < (x->subbuffer+sizeof x->subbuffer)) { \
+ *x->subpointer++ = (c); \
+ }
+
+#define CURL_SB_GET(x) ((*x->subpointer++)&0xff)
+#define CURL_SB_PEEK(x) ((*x->subpointer)&0xff)
+#define CURL_SB_EOF(x) (x->subpointer >= x->subend)
+#define CURL_SB_LEN(x) (x->subend - x->subpointer)
+
+#ifdef USE_WINSOCK
+typedef FARPROC WSOCK2_FUNC;
+static CURLcode check_wsock2 ( struct SessionHandle *data );
+#endif
+
+static
+void telrcv(struct connectdata *,
+ unsigned char *inbuf, /* Data received from socket */
+ ssize_t count); /* Number of bytes received */
+
+static void printoption(struct SessionHandle *data,
+ const char *direction,
+ int cmd, int option);
+
+static void negotiate(struct connectdata *);
+static void send_negotiation(struct connectdata *, int cmd, int option);
+static void set_local_option(struct connectdata *, int cmd, int option);
+static void set_remote_option(struct connectdata *, int cmd, int option);
+
+static void printsub(struct SessionHandle *data,
+ int direction, unsigned char *pointer,
+ size_t length);
+static void suboption(struct connectdata *);
+
+/* For negotiation compliant to RFC 1143 */
+#define CURL_NO 0
+#define CURL_YES 1
+#define CURL_WANTYES 2
+#define CURL_WANTNO 3
+
+#define CURL_EMPTY 0
+#define CURL_OPPOSITE 1
+
+/*
+ * Telnet receiver states for fsm
+ */
+typedef enum
+{
+ CURL_TS_DATA = 0,
+ CURL_TS_IAC,
+ CURL_TS_WILL,
+ CURL_TS_WONT,
+ CURL_TS_DO,
+ CURL_TS_DONT,
+ CURL_TS_CR,
+ CURL_TS_SB, /* sub-option collection */
+ CURL_TS_SE /* looking for sub-option end */
+} TelnetReceive;
+
+struct TELNET {
+ int please_negotiate;
+ int already_negotiated;
+ int us[256];
+ int usq[256];
+ int us_preferred[256];
+ int him[256];
+ int himq[256];
+ int him_preferred[256];
+ char subopt_ttype[32]; /* Set with suboption TTYPE */
+ char subopt_xdisploc[128]; /* Set with suboption XDISPLOC */
+ struct curl_slist *telnet_vars; /* Environment variables */
+
+ /* suboptions */
+ unsigned char subbuffer[SUBBUFSIZE];
+ unsigned char *subpointer, *subend; /* buffer for sub-options */
+
+ TelnetReceive telrcv_state;
+};
+
+#ifdef USE_WINSOCK
+static CURLcode
+check_wsock2 ( struct SessionHandle *data )
+{
+ int err;
+ WORD wVersionRequested;
+ WSADATA wsaData;
+
+ curlassert(data);
+
+ /* telnet requires at least WinSock 2.0 so ask for it. */
+ wVersionRequested = MAKEWORD(2, 0);
+
+ err = WSAStartup(wVersionRequested, &wsaData);
+
+ /* We must've called this once already, so this call */
+ /* should always succeed. But, just in case... */
+ if (err != 0) {
+ failf(data,"WSAStartup failed (%d)",err);
+ return CURLE_FAILED_INIT;
+ }
+
+ /* We have to have a WSACleanup call for every successful */
+ /* WSAStartup call. */
+ WSACleanup();
+
+ /* Check that our version is supported */
+ if (LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
+ HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested)) {
+ /* Our version isn't supported */
+ failf(data,"insufficient winsock version to support "
+ "telnet");
+ return CURLE_FAILED_INIT;
+ }
+
+ /* Our version is supported */
+ return CURLE_OK;
+}
+#endif
+
+static
+CURLcode init_telnet(struct connectdata *conn)
+{
+ struct TELNET *tn;
+
+ tn = (struct TELNET *)calloc(1, sizeof(struct TELNET));
+ if(!tn)
+ return CURLE_OUT_OF_MEMORY;
+
+ conn->data->reqdata.proto.telnet = (void *)tn; /* make us known */
+
+ tn->telrcv_state = CURL_TS_DATA;
+
+ /* Init suboptions */
+ CURL_SB_CLEAR(tn);
+
+ /* Set the options we want by default */
+ tn->us_preferred[CURL_TELOPT_BINARY] = CURL_YES;
+ tn->us_preferred[CURL_TELOPT_SGA] = CURL_YES;
+ tn->him_preferred[CURL_TELOPT_BINARY] = CURL_YES;
+ tn->him_preferred[CURL_TELOPT_SGA] = CURL_YES;
+
+ return CURLE_OK;
+}
+
+static void negotiate(struct connectdata *conn)
+{
+ int i;
+ struct TELNET *tn = (struct TELNET *) conn->data->reqdata.proto.telnet;
+
+ for(i = 0;i < CURL_NTELOPTS;i++)
+ {
+ if(tn->us_preferred[i] == CURL_YES)
+ set_local_option(conn, i, CURL_YES);
+
+ if(tn->him_preferred[i] == CURL_YES)
+ set_remote_option(conn, i, CURL_YES);
+ }
+}
+
+static void printoption(struct SessionHandle *data,
+ const char *direction, int cmd, int option)
+{
+ const char *fmt;
+ const char *opt;
+
+ if (data->set.verbose)
+ {
+ if (cmd == CURL_IAC)
+ {
+ if (CURL_TELCMD_OK(option))
+ infof(data, "%s IAC %s\n", direction, CURL_TELCMD(option));
+ else
+ infof(data, "%s IAC %d\n", direction, option);
+ }
+ else
+ {
+ fmt = (cmd == CURL_WILL) ? "WILL" : (cmd == CURL_WONT) ? "WONT" :
+ (cmd == CURL_DO) ? "DO" : (cmd == CURL_DONT) ? "DONT" : 0;
+ if (fmt)
+ {
+ if (CURL_TELOPT_OK(option))
+ opt = CURL_TELOPT(option);
+ else if (option == CURL_TELOPT_EXOPL)
+ opt = "EXOPL";
+ else
+ opt = NULL;
+
+ if(opt)
+ infof(data, "%s %s %s\n", direction, fmt, opt);
+ else
+ infof(data, "%s %s %d\n", direction, fmt, option);
+ }
+ else
+ infof(data, "%s %d %d\n", direction, cmd, option);
+ }
+ }
+}
+
+static void send_negotiation(struct connectdata *conn, int cmd, int option)
+{
+ unsigned char buf[3];
+ ssize_t bytes_written;
+ int err;
+ struct SessionHandle *data = conn->data;
+
+ buf[0] = CURL_IAC;
+ buf[1] = (unsigned char)cmd;
+ buf[2] = (unsigned char)option;
+
+ bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3);
+ if(bytes_written < 0) {
+ err = Curl_sockerrno();
+ failf(data,"Sending data failed (%d)",err);
+ }
+
+ printoption(conn->data, "SENT", cmd, option);
+}
+
+static
+void set_remote_option(struct connectdata *conn, int option, int newstate)
+{
+ struct TELNET *tn = (struct TELNET *)conn->data->reqdata.proto.telnet;
+ if(newstate == CURL_YES)
+ {
+ switch(tn->him[option])
+ {
+ case CURL_NO:
+ tn->him[option] = CURL_WANTYES;
+ send_negotiation(conn, CURL_DO, option);
+ break;
+
+ case CURL_YES:
+ /* Already enabled */
+ break;
+
+ case CURL_WANTNO:
+ switch(tn->himq[option])
+ {
+ case CURL_EMPTY:
+ /* Already negotiating for CURL_YES, queue the request */
+ tn->himq[option] = CURL_OPPOSITE;
+ break;
+ case CURL_OPPOSITE:
+ /* Error: already queued an enable request */
+ break;
+ }
+ break;
+
+ case CURL_WANTYES:
+ switch(tn->himq[option])
+ {
+ case CURL_EMPTY:
+ /* Error: already negotiating for enable */
+ break;
+ case CURL_OPPOSITE:
+ tn->himq[option] = CURL_EMPTY;
+ break;
+ }
+ break;
+ }
+ }
+ else /* NO */
+ {
+ switch(tn->him[option])
+ {
+ case CURL_NO:
+ /* Already disabled */
+ break;
+
+ case CURL_YES:
+ tn->him[option] = CURL_WANTNO;
+ send_negotiation(conn, CURL_DONT, option);
+ break;
+
+ case CURL_WANTNO:
+ switch(tn->himq[option])
+ {
+ case CURL_EMPTY:
+ /* Already negotiating for NO */
+ break;
+ case CURL_OPPOSITE:
+ tn->himq[option] = CURL_EMPTY;
+ break;
+ }
+ break;
+
+ case CURL_WANTYES:
+ switch(tn->himq[option])
+ {
+ case CURL_EMPTY:
+ tn->himq[option] = CURL_OPPOSITE;
+ break;
+ case CURL_OPPOSITE:
+ break;
+ }
+ break;
+ }
+ }
+}
+
+static
+void rec_will(struct connectdata *conn, int option)
+{
+ struct TELNET *tn = (struct TELNET *)conn->data->reqdata.proto.telnet;
+ switch(tn->him[option])
+ {
+ case CURL_NO:
+ if(tn->him_preferred[option] == CURL_YES)
+ {
+ tn->him[option] = CURL_YES;
+ send_negotiation(conn, CURL_DO, option);
+ }
+ else
+ {
+ send_negotiation(conn, CURL_DONT, option);
+ }
+ break;
+
+ case CURL_YES:
+ /* Already enabled */
+ break;
+
+ case CURL_WANTNO:
+ switch(tn->himq[option])
+ {
+ case CURL_EMPTY:
+ /* Error: DONT answered by WILL */
+ tn->him[option] = CURL_NO;
+ break;
+ case CURL_OPPOSITE:
+ /* Error: DONT answered by WILL */
+ tn->him[option] = CURL_YES;
+ tn->himq[option] = CURL_EMPTY;
+ break;
+ }
+ break;
+
+ case CURL_WANTYES:
+ switch(tn->himq[option])
+ {
+ case CURL_EMPTY:
+ tn->him[option] = CURL_YES;
+ break;
+ case CURL_OPPOSITE:
+ tn->him[option] = CURL_WANTNO;
+ tn->himq[option] = CURL_EMPTY;
+ send_negotiation(conn, CURL_DONT, option);
+ break;
+ }
+ break;
+ }
+}
+
+static
+void rec_wont(struct connectdata *conn, int option)
+{
+ struct TELNET *tn = (struct TELNET *)conn->data->reqdata.proto.telnet;
+ switch(tn->him[option])
+ {
+ case CURL_NO:
+ /* Already disabled */
+ break;
+
+ case CURL_YES:
+ tn->him[option] = CURL_NO;
+ send_negotiation(conn, CURL_DONT, option);
+ break;
+
+ case CURL_WANTNO:
+ switch(tn->himq[option])
+ {
+ case CURL_EMPTY:
+ tn->him[option] = CURL_NO;
+ break;
+
+ case CURL_OPPOSITE:
+ tn->him[option] = CURL_WANTYES;
+ tn->himq[option] = CURL_EMPTY;
+ send_negotiation(conn, CURL_DO, option);
+ break;
+ }
+ break;
+
+ case CURL_WANTYES:
+ switch(tn->himq[option])
+ {
+ case CURL_EMPTY:
+ tn->him[option] = CURL_NO;
+ break;
+ case CURL_OPPOSITE:
+ tn->him[option] = CURL_NO;
+ tn->himq[option] = CURL_EMPTY;
+ break;
+ }
+ break;
+ }
+}
+
+static void
+set_local_option(struct connectdata *conn, int option, int newstate)
+{
+ struct TELNET *tn = (struct TELNET *)conn->data->reqdata.proto.telnet;
+ if(newstate == CURL_YES)
+ {
+ switch(tn->us[option])
+ {
+ case CURL_NO:
+ tn->us[option] = CURL_WANTYES;
+ send_negotiation(conn, CURL_WILL, option);
+ break;
+
+ case CURL_YES:
+ /* Already enabled */
+ break;
+
+ case CURL_WANTNO:
+ switch(tn->usq[option])
+ {
+ case CURL_EMPTY:
+ /* Already negotiating for CURL_YES, queue the request */
+ tn->usq[option] = CURL_OPPOSITE;
+ break;
+ case CURL_OPPOSITE:
+ /* Error: already queued an enable request */
+ break;
+ }
+ break;
+
+ case CURL_WANTYES:
+ switch(tn->usq[option])
+ {
+ case CURL_EMPTY:
+ /* Error: already negotiating for enable */
+ break;
+ case CURL_OPPOSITE:
+ tn->usq[option] = CURL_EMPTY;
+ break;
+ }
+ break;
+ }
+ }
+ else /* NO */
+ {
+ switch(tn->us[option])
+ {
+ case CURL_NO:
+ /* Already disabled */
+ break;
+
+ case CURL_YES:
+ tn->us[option] = CURL_WANTNO;
+ send_negotiation(conn, CURL_WONT, option);
+ break;
+
+ case CURL_WANTNO:
+ switch(tn->usq[option])
+ {
+ case CURL_EMPTY:
+ /* Already negotiating for NO */
+ break;
+ case CURL_OPPOSITE:
+ tn->usq[option] = CURL_EMPTY;
+ break;
+ }
+ break;
+
+ case CURL_WANTYES:
+ switch(tn->usq[option])
+ {
+ case CURL_EMPTY:
+ tn->usq[option] = CURL_OPPOSITE;
+ break;
+ case CURL_OPPOSITE:
+ break;
+ }
+ break;
+ }
+ }
+}
+
+static
+void rec_do(struct connectdata *conn, int option)
+{
+ struct TELNET *tn = (struct TELNET *)conn->data->reqdata.proto.telnet;
+ switch(tn->us[option])
+ {
+ case CURL_NO:
+ if(tn->us_preferred[option] == CURL_YES)
+ {
+ tn->us[option] = CURL_YES;
+ send_negotiation(conn, CURL_WILL, option);
+ }
+ else
+ {
+ send_negotiation(conn, CURL_WONT, option);
+ }
+ break;
+
+ case CURL_YES:
+ /* Already enabled */
+ break;
+
+ case CURL_WANTNO:
+ switch(tn->usq[option])
+ {
+ case CURL_EMPTY:
+ /* Error: DONT answered by WILL */
+ tn->us[option] = CURL_NO;
+ break;
+ case CURL_OPPOSITE:
+ /* Error: DONT answered by WILL */
+ tn->us[option] = CURL_YES;
+ tn->usq[option] = CURL_EMPTY;
+ break;
+ }
+ break;
+
+ case CURL_WANTYES:
+ switch(tn->usq[option])
+ {
+ case CURL_EMPTY:
+ tn->us[option] = CURL_YES;
+ break;
+ case CURL_OPPOSITE:
+ tn->us[option] = CURL_WANTNO;
+ tn->himq[option] = CURL_EMPTY;
+ send_negotiation(conn, CURL_WONT, option);
+ break;
+ }
+ break;
+ }
+}
+
+static
+void rec_dont(struct connectdata *conn, int option)
+{
+ struct TELNET *tn = (struct TELNET *)conn->data->reqdata.proto.telnet;
+ switch(tn->us[option])
+ {
+ case CURL_NO:
+ /* Already disabled */
+ break;
+
+ case CURL_YES:
+ tn->us[option] = CURL_NO;
+ send_negotiation(conn, CURL_WONT, option);
+ break;
+
+ case CURL_WANTNO:
+ switch(tn->usq[option])
+ {
+ case CURL_EMPTY:
+ tn->us[option] = CURL_NO;
+ break;
+
+ case CURL_OPPOSITE:
+ tn->us[option] = CURL_WANTYES;
+ tn->usq[option] = CURL_EMPTY;
+ send_negotiation(conn, CURL_WILL, option);
+ break;
+ }
+ break;
+
+ case CURL_WANTYES:
+ switch(tn->usq[option])
+ {
+ case CURL_EMPTY:
+ tn->us[option] = CURL_NO;
+ break;
+ case CURL_OPPOSITE:
+ tn->us[option] = CURL_NO;
+ tn->usq[option] = CURL_EMPTY;
+ break;
+ }
+ break;
+ }
+}
+
+
+static void printsub(struct SessionHandle *data,
+ int direction, /* '<' or '>' */
+ unsigned char *pointer, /* where suboption data is */
+ size_t length) /* length of suboption data */
+{
+ unsigned int i = 0;
+
+ if (data->set.verbose)
+ {
+ if (direction)
+ {
+ infof(data, "%s IAC SB ", (direction == '<')? "RCVD":"SENT");
+ if (length >= 3)
+ {
+ int j;
+
+ i = pointer[length-2];
+ j = pointer[length-1];
+
+ if (i != CURL_IAC || j != CURL_SE)
+ {
+ infof(data, "(terminated by ");
+ if (CURL_TELOPT_OK(i))
+ infof(data, "%s ", CURL_TELOPT(i));
+ else if (CURL_TELCMD_OK(i))
+ infof(data, "%s ", CURL_TELCMD(i));
+ else
+ infof(data, "%d ", i);
+ if (CURL_TELOPT_OK(j))
+ infof(data, "%s", CURL_TELOPT(j));
+ else if (CURL_TELCMD_OK(j))
+ infof(data, "%s", CURL_TELCMD(j));
+ else
+ infof(data, "%d", j);
+ infof(data, ", not IAC SE!) ");
+ }
+ }
+ length -= 2;
+ }
+ if (length < 1)
+ {
+ infof(data, "(Empty suboption?)");
+ return;
+ }
+
+ if (CURL_TELOPT_OK(pointer[0])) {
+ switch(pointer[0]) {
+ case CURL_TELOPT_TTYPE:
+ case CURL_TELOPT_XDISPLOC:
+ case CURL_TELOPT_NEW_ENVIRON:
+ infof(data, "%s", CURL_TELOPT(pointer[0]));
+ break;
+ default:
+ infof(data, "%s (unsupported)", CURL_TELOPT(pointer[0]));
+ break;
+ }
+ }
+ else
+ infof(data, "%d (unknown)", pointer[i]);
+
+ switch(pointer[1]) {
+ case CURL_TELQUAL_IS:
+ infof(data, " IS");
+ break;
+ case CURL_TELQUAL_SEND:
+ infof(data, " SEND");
+ break;
+ case CURL_TELQUAL_INFO:
+ infof(data, " INFO/REPLY");
+ break;
+ case CURL_TELQUAL_NAME:
+ infof(data, " NAME");
+ break;
+ }
+
+ switch(pointer[0]) {
+ case CURL_TELOPT_TTYPE:
+ case CURL_TELOPT_XDISPLOC:
+ pointer[length] = 0;
+ infof(data, " \"%s\"", &pointer[2]);
+ break;
+ case CURL_TELOPT_NEW_ENVIRON:
+ if(pointer[1] == CURL_TELQUAL_IS) {
+ infof(data, " ");
+ for(i = 3;i < length;i++) {
+ switch(pointer[i]) {
+ case CURL_NEW_ENV_VAR:
+ infof(data, ", ");
+ break;
+ case CURL_NEW_ENV_VALUE:
+ infof(data, " = ");
+ break;
+ default:
+ infof(data, "%c", pointer[i]);
+ break;
+ }
+ }
+ }
+ break;
+ default:
+ for (i = 2; i < length; i++)
+ infof(data, " %.2x", pointer[i]);
+ break;
+ }
+
+ if (direction)
+ {
+ infof(data, "\n");
+ }
+ }
+}
+
+static CURLcode check_telnet_options(struct connectdata *conn)
+{
+ struct curl_slist *head;
+ char option_keyword[128];
+ char option_arg[256];
+ char *buf;
+ struct SessionHandle *data = conn->data;
+ struct TELNET *tn = (struct TELNET *)conn->data->reqdata.proto.telnet;
+
+ /* Add the user name as an environment variable if it
+ was given on the command line */
+ if(conn->bits.user_passwd)
+ {
+ snprintf(option_arg, sizeof(option_arg), "USER,%s", conn->user);
+ tn->telnet_vars = curl_slist_append(tn->telnet_vars, option_arg);
+
+ tn->us_preferred[CURL_TELOPT_NEW_ENVIRON] = CURL_YES;
+ }
+
+ for(head = data->set.telnet_options; head; head=head->next) {
+ if(sscanf(head->data, "%127[^= ]%*[ =]%255s",
+ option_keyword, option_arg) == 2) {
+
+ /* Terminal type */
+ if(curl_strequal(option_keyword, "TTYPE")) {
+ strncpy(tn->subopt_ttype, option_arg, 31);
+ tn->subopt_ttype[31] = 0; /* String termination */
+ tn->us_preferred[CURL_TELOPT_TTYPE] = CURL_YES;
+ continue;
+ }
+
+ /* Display variable */
+ if(curl_strequal(option_keyword, "XDISPLOC")) {
+ strncpy(tn->subopt_xdisploc, option_arg, 127);
+ tn->subopt_xdisploc[127] = 0; /* String termination */
+ tn->us_preferred[CURL_TELOPT_XDISPLOC] = CURL_YES;
+ continue;
+ }
+
+ /* Environment variable */
+ if(curl_strequal(option_keyword, "NEW_ENV")) {
+ buf = strdup(option_arg);
+ if(!buf)
+ return CURLE_OUT_OF_MEMORY;
+ tn->telnet_vars = curl_slist_append(tn->telnet_vars, buf);
+ tn->us_preferred[CURL_TELOPT_NEW_ENVIRON] = CURL_YES;
+ continue;
+ }
+
+ failf(data, "Unknown telnet option %s", head->data);
+ return CURLE_UNKNOWN_TELNET_OPTION;
+ } else {
+ failf(data, "Syntax error in telnet option: %s", head->data);
+ return CURLE_TELNET_OPTION_SYNTAX;
+ }
+ }
+
+ return CURLE_OK;
+}
+
+/*
+ * suboption()
+ *
+ * Look at the sub-option buffer, and try to be helpful to the other
+ * side.
+ */
+
+static void suboption(struct connectdata *conn)
+{
+ struct curl_slist *v;
+ unsigned char temp[2048];
+ ssize_t bytes_written;
+ size_t len;
+ size_t tmplen;
+ int err;
+ char varname[128];
+ char varval[128];
+ struct SessionHandle *data = conn->data;
+ struct TELNET *tn = (struct TELNET *)data->reqdata.proto.telnet;
+
+ printsub(data, '<', (unsigned char *)tn->subbuffer, CURL_SB_LEN(tn)+2);
+ switch (CURL_SB_GET(tn)) {
+ case CURL_TELOPT_TTYPE:
+ len = strlen(tn->subopt_ttype) + 4 + 2;
+ snprintf((char *)temp, sizeof(temp),
+ "%c%c%c%c%s%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_TTYPE,
+ CURL_TELQUAL_IS, tn->subopt_ttype, CURL_IAC, CURL_SE);
+ bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
+ if(bytes_written < 0) {
+ err = Curl_sockerrno();
+ failf(data,"Sending data failed (%d)",err);
+ }
+ printsub(data, '>', &temp[2], len-2);
+ break;
+ case CURL_TELOPT_XDISPLOC:
+ len = strlen(tn->subopt_xdisploc) + 4 + 2;
+ snprintf((char *)temp, sizeof(temp),
+ "%c%c%c%c%s%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_XDISPLOC,
+ CURL_TELQUAL_IS, tn->subopt_xdisploc, CURL_IAC, CURL_SE);
+ bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
+ if(bytes_written < 0) {
+ err = Curl_sockerrno();
+ failf(data,"Sending data failed (%d)",err);
+ }
+ printsub(data, '>', &temp[2], len-2);
+ break;
+ case CURL_TELOPT_NEW_ENVIRON:
+ snprintf((char *)temp, sizeof(temp),
+ "%c%c%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_NEW_ENVIRON,
+ CURL_TELQUAL_IS);
+ len = 4;
+
+ for(v = tn->telnet_vars;v;v = v->next) {
+ tmplen = (strlen(v->data) + 1);
+ /* Add the variable only if it fits */
+ if(len + tmplen < (int)sizeof(temp)-6) {
+ sscanf(v->data, "%127[^,],%127s", varname, varval);
+ snprintf((char *)&temp[len], sizeof(temp) - len,
+ "%c%s%c%s", CURL_NEW_ENV_VAR, varname,
+ CURL_NEW_ENV_VALUE, varval);
+ len += tmplen;
+ }
+ }
+ snprintf((char *)&temp[len], sizeof(temp) - len,
+ "%c%c", CURL_IAC, CURL_SE);
+ len += 2;
+ bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
+ if(bytes_written < 0) {
+ err = Curl_sockerrno();
+ failf(data,"Sending data failed (%d)",err);
+ }
+ printsub(data, '>', &temp[2], len-2);
+ break;
+ }
+ return;
+}
+
+static
+void telrcv(struct connectdata *conn,
+ unsigned char *inbuf, /* Data received from socket */
+ ssize_t count) /* Number of bytes received */
+{
+ unsigned char c;
+ int in = 0;
+ struct SessionHandle *data = conn->data;
+ struct TELNET *tn = (struct TELNET *)data->reqdata.proto.telnet;
+
+ while(count--)
+ {
+ c = inbuf[in++];
+
+ switch (tn->telrcv_state)
+ {
+ case CURL_TS_CR:
+ tn->telrcv_state = CURL_TS_DATA;
+ if (c == '\0')
+ {
+ break; /* Ignore \0 after CR */
+ }
+
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)&c, 1);
+ continue;
+
+ case CURL_TS_DATA:
+ if (c == CURL_IAC)
+ {
+ tn->telrcv_state = CURL_TS_IAC;
+ break;
+ }
+ else if(c == '\r')
+ {
+ tn->telrcv_state = CURL_TS_CR;
+ }
+
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)&c, 1);
+ continue;
+
+ case CURL_TS_IAC:
+ process_iac:
+ switch (c)
+ {
+ case CURL_WILL:
+ tn->telrcv_state = CURL_TS_WILL;
+ continue;
+ case CURL_WONT:
+ tn->telrcv_state = CURL_TS_WONT;
+ continue;
+ case CURL_DO:
+ tn->telrcv_state = CURL_TS_DO;
+ continue;
+ case CURL_DONT:
+ tn->telrcv_state = CURL_TS_DONT;
+ continue;
+ case CURL_SB:
+ CURL_SB_CLEAR(tn);
+ tn->telrcv_state = CURL_TS_SB;
+ continue;
+ case CURL_IAC:
+ Curl_client_write(conn, CLIENTWRITE_BODY, (char *)&c, 1);
+ break;
+ case CURL_DM:
+ case CURL_NOP:
+ case CURL_GA:
+ default:
+ printoption(data, "RCVD", CURL_IAC, c);
+ break;
+ }
+ tn->telrcv_state = CURL_TS_DATA;
+ continue;
+
+ case CURL_TS_WILL:
+ printoption(data, "RCVD", CURL_WILL, c);
+ tn->please_negotiate = 1;
+ rec_will(conn, c);
+ tn->telrcv_state = CURL_TS_DATA;
+ continue;
+
+ case CURL_TS_WONT:
+ printoption(data, "RCVD", CURL_WONT, c);
+ tn->please_negotiate = 1;
+ rec_wont(conn, c);
+ tn->telrcv_state = CURL_TS_DATA;
+ continue;
+
+ case CURL_TS_DO:
+ printoption(data, "RCVD", CURL_DO, c);
+ tn->please_negotiate = 1;
+ rec_do(conn, c);
+ tn->telrcv_state = CURL_TS_DATA;
+ continue;
+
+ case CURL_TS_DONT:
+ printoption(data, "RCVD", CURL_DONT, c);
+ tn->please_negotiate = 1;
+ rec_dont(conn, c);
+ tn->telrcv_state = CURL_TS_DATA;
+ continue;
+
+ case CURL_TS_SB:
+ if (c == CURL_IAC)
+ {
+ tn->telrcv_state = CURL_TS_SE;
+ }
+ else
+ {
+ CURL_SB_ACCUM(tn,c);
+ }
+ continue;
+
+ case CURL_TS_SE:
+ if (c != CURL_SE)
+ {
+ if (c != CURL_IAC)
+ {
+ /*
+ * This is an error. We only expect to get "IAC IAC" or "IAC SE".
+ * Several things may have happend. An IAC was not doubled, the
+ * IAC SE was left off, or another option got inserted into the
+ * suboption are all possibilities. If we assume that the IAC was
+ * not doubled, and really the IAC SE was left off, we could get
+ * into an infinate loop here. So, instead, we terminate the
+ * suboption, and process the partial suboption if we can.
+ */
+ CURL_SB_ACCUM(tn, CURL_IAC);
+ CURL_SB_ACCUM(tn, c);
+ tn->subpointer -= 2;
+ CURL_SB_TERM(tn);
+
+ printoption(data, "In SUBOPTION processing, RCVD", CURL_IAC, c);
+ suboption(conn); /* handle sub-option */
+ tn->telrcv_state = CURL_TS_IAC;
+ goto process_iac;
+ }
+ CURL_SB_ACCUM(tn,c);
+ tn->telrcv_state = CURL_TS_SB;
+ }
+ else
+ {
+ CURL_SB_ACCUM(tn, CURL_IAC);
+ CURL_SB_ACCUM(tn, CURL_SE);
+ tn->subpointer -= 2;
+ CURL_SB_TERM(tn);
+ suboption(conn); /* handle sub-option */
+ tn->telrcv_state = CURL_TS_DATA;
+ }
+ break;
+ }
+ }
+}
+
+CURLcode Curl_telnet_done(struct connectdata *conn, CURLcode status, bool premature)
+{
+ struct TELNET *tn = (struct TELNET *)conn->data->reqdata.proto.telnet;
+ (void)status; /* unused */
+ (void)premature; /* not used */
+
+ curl_slist_free_all(tn->telnet_vars);
+
+ free(conn->data->reqdata.proto.telnet);
+ conn->data->reqdata.proto.telnet = NULL;
+
+ return CURLE_OK;
+}
+
+CURLcode Curl_telnet(struct connectdata *conn, bool *done)
+{
+ CURLcode code;
+ struct SessionHandle *data = conn->data;
+ curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
+#ifdef USE_WINSOCK
+ HMODULE wsock2;
+ WSOCK2_FUNC close_event_func;
+ WSOCK2_FUNC create_event_func;
+ WSOCK2_FUNC event_select_func;
+ WSOCK2_FUNC enum_netevents_func;
+ WSAEVENT event_handle;
+ WSANETWORKEVENTS events;
+ HANDLE stdin_handle;
+ HANDLE objs[2];
+ DWORD obj_count;
+ DWORD wait_timeout;
+ DWORD waitret;
+ DWORD readfile_read;
+#else
+ int interval_ms;
+ struct pollfd pfd[2];
+#endif
+ ssize_t nread;
+ bool keepon = TRUE;
+ char *buf = data->state.buffer;
+ struct TELNET *tn;
+
+ *done = TRUE; /* uncontionally */
+
+ code = init_telnet(conn);
+ if(code)
+ return code;
+
+ tn = (struct TELNET *)data->reqdata.proto.telnet;
+
+ code = check_telnet_options(conn);
+ if(code)
+ return code;
+
+#ifdef USE_WINSOCK
+ /*
+ ** This functionality only works with WinSock >= 2.0. So,
+ ** make sure have it.
+ */
+ code = check_wsock2(data);
+ if (code)
+ return code;
+
+ /* OK, so we have WinSock 2.0. We need to dynamically */
+ /* load ws2_32.dll and get the function pointers we need. */
+ wsock2 = LoadLibrary("WS2_32.DLL");
+ if (wsock2 == NULL) {
+ failf(data,"failed to load WS2_32.DLL (%d)",GetLastError());
+ return CURLE_FAILED_INIT;
+ }
+
+ /* Grab a pointer to WSACreateEvent */
+ create_event_func = GetProcAddress(wsock2,"WSACreateEvent");
+ if (create_event_func == NULL) {
+ failf(data,"failed to find WSACreateEvent function (%d)",
+ GetLastError());
+ FreeLibrary(wsock2);
+ return CURLE_FAILED_INIT;
+ }
+
+ /* And WSACloseEvent */
+ close_event_func = GetProcAddress(wsock2,"WSACloseEvent");
+ if (close_event_func == NULL) {
+ failf(data,"failed to find WSACloseEvent function (%d)",
+ GetLastError());
+ FreeLibrary(wsock2);
+ return CURLE_FAILED_INIT;
+ }
+
+ /* And WSAEventSelect */
+ event_select_func = GetProcAddress(wsock2,"WSAEventSelect");
+ if (event_select_func == NULL) {
+ failf(data,"failed to find WSAEventSelect function (%d)",
+ GetLastError());
+ FreeLibrary(wsock2);
+ return CURLE_FAILED_INIT;
+ }
+
+ /* And WSAEnumNetworkEvents */
+ enum_netevents_func = GetProcAddress(wsock2,"WSAEnumNetworkEvents");
+ if (enum_netevents_func == NULL) {
+ failf(data,"failed to find WSAEnumNetworkEvents function (%d)",
+ GetLastError());
+ FreeLibrary(wsock2);
+ return CURLE_FAILED_INIT;
+ }
+
+ /* We want to wait for both stdin and the socket. Since
+ ** the select() function in winsock only works on sockets
+ ** we have to use the WaitForMultipleObjects() call.
+ */
+
+ /* First, create a sockets event object */
+ event_handle = (WSAEVENT)create_event_func();
+ if (event_handle == WSA_INVALID_EVENT) {
+ failf(data,"WSACreateEvent failed (%d)",WSAGetLastError());
+ FreeLibrary(wsock2);
+ return CURLE_FAILED_INIT;
+ }
+
+ /* The get the Windows file handle for stdin */
+ stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
+
+ /* Create the list of objects to wait for */
+ objs[0] = event_handle;
+ objs[1] = stdin_handle;
+
+ /* Tell winsock what events we want to listen to */
+ if(event_select_func(sockfd, event_handle, FD_READ|FD_CLOSE) == SOCKET_ERROR) {
+ close_event_func(event_handle);
+ FreeLibrary(wsock2);
+ return 0;
+ }
+
+ /* If stdin_handle is a pipe, use PeekNamedPipe() method to check it,
+ else use the old WaitForMultipleObjects() way */
+ if(GetFileType(stdin_handle) == FILE_TYPE_PIPE) {
+ /* Don't wait for stdin_handle, just wait for event_handle */
+ obj_count = 1;
+ /* Check stdin_handle per 100 milliseconds */
+ wait_timeout = 100;
+ } else {
+ obj_count = 2;
+ wait_timeout = INFINITE;
+ }
+
+ /* Keep on listening and act on events */
+ while(keepon) {
+ waitret = WaitForMultipleObjects(obj_count, objs, FALSE, wait_timeout);
+ switch(waitret) {
+ case WAIT_TIMEOUT:
+ {
+ unsigned char outbuf[2];
+ int out_count = 0;
+ ssize_t bytes_written;
+ char *buffer = buf;
+
+ while(1) {
+ if(!PeekNamedPipe(stdin_handle, NULL, 0, NULL, &readfile_read, NULL)) {
+ keepon = FALSE;
+ break;
+ }
+ nread = readfile_read;
+
+ if(!nread)
+ break;
+
+ if(!ReadFile(stdin_handle, buf, sizeof(data->state.buffer),
+ &readfile_read, NULL)) {
+ keepon = FALSE;
+ break;
+ }
+ nread = readfile_read;
+
+ while(nread--) {
+ outbuf[0] = *buffer++;
+ out_count = 1;
+ if(outbuf[0] == CURL_IAC)
+ outbuf[out_count++] = CURL_IAC;
+
+ Curl_write(conn, conn->sock[FIRSTSOCKET], outbuf,
+ out_count, &bytes_written);
+ }
+ }
+ }
+ break;
+
+ case WAIT_OBJECT_0 + 1:
+ {
+ unsigned char outbuf[2];
+ int out_count = 0;
+ ssize_t bytes_written;
+ char *buffer = buf;
+
+ if(!ReadFile(stdin_handle, buf, sizeof(data->state.buffer),
+ &readfile_read, NULL)) {
+ keepon = FALSE;
+ break;
+ }
+ nread = readfile_read;
+
+ while(nread--) {
+ outbuf[0] = *buffer++;
+ out_count = 1;
+ if(outbuf[0] == CURL_IAC)
+ outbuf[out_count++] = CURL_IAC;
+
+ Curl_write(conn, conn->sock[FIRSTSOCKET], outbuf,
+ out_count, &bytes_written);
+ }
+ }
+ break;
+
+ case WAIT_OBJECT_0:
+ if(enum_netevents_func(sockfd, event_handle, &events)
+ != SOCKET_ERROR) {
+ if(events.lNetworkEvents & FD_READ) {
+ /* This reallu OUGHT to check its return code. */
+ (void)Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
+
+ telrcv(conn, (unsigned char *)buf, nread);
+
+ fflush(stdout);
+
+ /* Negotiate if the peer has started negotiating,
+ otherwise don't. We don't want to speak telnet with
+ non-telnet servers, like POP or SMTP. */
+ if(tn->please_negotiate && !tn->already_negotiated) {
+ negotiate(conn);
+ tn->already_negotiated = 1;
+ }
+ }
+
+ if(events.lNetworkEvents & FD_CLOSE) {
+ keepon = FALSE;
+ }
+ }
+ break;
+ }
+ }
+
+ /* We called WSACreateEvent, so call WSACloseEvent */
+ if (close_event_func(event_handle) == FALSE) {
+ infof(data,"WSACloseEvent failed (%d)",WSAGetLastError());
+ }
+
+ /* "Forget" pointers into the library we're about to free */
+ create_event_func = NULL;
+ close_event_func = NULL;
+ event_select_func = NULL;
+ enum_netevents_func = NULL;
+
+ /* We called LoadLibrary, so call FreeLibrary */
+ if (!FreeLibrary(wsock2))
+ infof(data,"FreeLibrary(wsock2) failed (%d)",GetLastError());
+#else
+ pfd[0].fd = sockfd;
+ pfd[0].events = POLLIN;
+ pfd[1].fd = 0;
+ pfd[1].events = POLLIN;
+ interval_ms = 1 * 1000;
+
+ while (keepon) {
+ switch (Curl_poll(pfd, 2, interval_ms)) {
+ case -1: /* error, stop reading */
+ keepon = FALSE;
+ continue;
+ case 0: /* timeout */
+ break;
+ default: /* read! */
+ if(pfd[1].revents & POLLIN) { /* read from stdin */
+ unsigned char outbuf[2];
+ int out_count = 0;
+ ssize_t bytes_written;
+ char *buffer = buf;
+
+ nread = read(0, buf, 255);
+
+ while(nread--) {
+ outbuf[0] = *buffer++;
+ out_count = 1;
+ if(outbuf[0] == CURL_IAC)
+ outbuf[out_count++] = CURL_IAC;
+
+ Curl_write(conn, conn->sock[FIRSTSOCKET], outbuf,
+ out_count, &bytes_written);
+ }
+ }
+
+ if(pfd[0].revents & POLLIN) {
+ /* This OUGHT to check the return code... */
+ (void)Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
+
+ /* if we receive 0 or less here, the server closed the connection and
+ we bail out from this! */
+ if (nread <= 0) {
+ keepon = FALSE;
+ break;
+ }
+
+ telrcv(conn, (unsigned char *)buf, nread);
+
+ /* Negotiate if the peer has started negotiating,
+ otherwise don't. We don't want to speak telnet with
+ non-telnet servers, like POP or SMTP. */
+ if(tn->please_negotiate && !tn->already_negotiated) {
+ negotiate(conn);
+ tn->already_negotiated = 1;
+ }
+ }
+ }
+ if(data->set.timeout) {
+ struct timeval now; /* current time */
+ now = Curl_tvnow();
+ if(Curl_tvdiff(now, conn->created)/1000 >= data->set.timeout) {
+ failf(data, "Time-out");
+ code = CURLE_OPERATION_TIMEOUTED;
+ keepon = FALSE;
+ }
+ }
+ }
+#endif
+ /* mark this as "no further transfer wanted" */
+ Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+
+ return code;
+}
+#endif
diff --git a/Utilities/cmcurl/telnet.h b/Utilities/cmcurl/telnet.h
new file mode 100644
index 0000000000..693abf3f86
--- /dev/null
+++ b/Utilities/cmcurl/telnet.h
@@ -0,0 +1,30 @@
+#ifndef __TELNET_H
+#define __TELNET_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#ifndef CURL_DISABLE_TELNET
+CURLcode Curl_telnet(struct connectdata *conn, bool *done);
+CURLcode Curl_telnet_done(struct connectdata *conn, CURLcode, bool premature);
+#endif
+#endif
diff --git a/Utilities/cmcurl/tftp.c b/Utilities/cmcurl/tftp.c
new file mode 100644
index 0000000000..0e2e7ab452
--- /dev/null
+++ b/Utilities/cmcurl/tftp.c
@@ -0,0 +1,816 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifndef CURL_DISABLE_TFTP
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#if defined(WIN32)
+#include <time.h>
+#include <io.h>
+#else
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <netinet/in.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <netdb.h>
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#include <sys/ioctl.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+
+#endif
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "transfer.h"
+#include "sendf.h"
+#include "tftp.h"
+#include "progress.h"
+#include "connect.h"
+#include "strerror.h"
+#include "sockaddr.h" /* required for Curl_sockaddr_storage */
+#include "url.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#include "memory.h"
+#include "select.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/* RFC2348 allows the block size to be negotiated, but we don't support that */
+#define TFTP_BLOCKSIZE 512
+
+typedef enum {
+ TFTP_MODE_NETASCII=0,
+ TFTP_MODE_OCTET
+} tftp_mode_t;
+
+typedef enum {
+ TFTP_STATE_START=0,
+ TFTP_STATE_RX,
+ TFTP_STATE_TX,
+ TFTP_STATE_FIN
+} tftp_state_t;
+
+typedef enum {
+ TFTP_EVENT_INIT=0,
+ TFTP_EVENT_RRQ = 1,
+ TFTP_EVENT_WRQ = 2,
+ TFTP_EVENT_DATA = 3,
+ TFTP_EVENT_ACK = 4,
+ TFTP_EVENT_ERROR = 5,
+ TFTP_EVENT_TIMEOUT
+} tftp_event_t;
+
+typedef enum {
+ TFTP_ERR_UNDEF=0,
+ TFTP_ERR_NOTFOUND,
+ TFTP_ERR_PERM,
+ TFTP_ERR_DISKFULL,
+ TFTP_ERR_ILLEGAL,
+ TFTP_ERR_UNKNOWNID,
+ TFTP_ERR_EXISTS,
+ TFTP_ERR_NOSUCHUSER,
+ TFTP_ERR_TIMEOUT,
+ TFTP_ERR_NORESPONSE
+} tftp_error_t;
+
+typedef struct tftp_packet {
+ unsigned char data[2 + 2 + TFTP_BLOCKSIZE];
+} tftp_packet_t;
+
+typedef struct tftp_state_data {
+ tftp_state_t state;
+ tftp_mode_t mode;
+ tftp_error_t error;
+ struct connectdata *conn;
+ curl_socket_t sockfd;
+ int retries;
+ int retry_time;
+ int retry_max;
+ time_t start_time;
+ time_t max_time;
+ unsigned short block;
+ struct Curl_sockaddr_storage local_addr;
+ socklen_t local_addrlen;
+ struct Curl_sockaddr_storage remote_addr;
+ socklen_t remote_addrlen;
+ int rbytes;
+ int sbytes;
+ tftp_packet_t rpacket;
+ tftp_packet_t spacket;
+} tftp_state_data_t;
+
+
+/* Forward declarations */
+static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event) ;
+static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event) ;
+void tftp_set_timeouts(tftp_state_data_t *state) ;
+
+/**********************************************************
+ *
+ * tftp_set_timeouts -
+ *
+ * Set timeouts based on state machine state.
+ * Use user provided connect timeouts until DATA or ACK
+ * packet is received, then use user-provided transfer timeouts
+ *
+ *
+ **********************************************************/
+void tftp_set_timeouts(tftp_state_data_t *state)
+{
+
+ struct SessionHandle *data = state->conn->data;
+ time_t maxtime, timeout;
+
+ time(&state->start_time);
+ if(state->state == TFTP_STATE_START) {
+ /* Compute drop-dead time */
+ maxtime = (time_t)(data->set.connecttimeout?data->set.connecttimeout:30);
+ state->max_time = state->start_time+maxtime;
+
+ /* Set per-block timeout to total */
+ timeout = maxtime ;
+
+ /* Average restart after 5 seconds */
+ state->retry_max = (int)(timeout/5);
+
+ /* Compute the re-start interval to suit the timeout */
+ state->retry_time = (int)(timeout/state->retry_max);
+ if(state->retry_time<1)
+ state->retry_time=1;
+
+ }
+ else {
+
+ /* Compute drop-dead time */
+ maxtime = (time_t)(data->set.timeout?data->set.timeout:3600);
+ state->max_time = state->start_time+maxtime;
+
+ /* Set per-block timeout to 10% of total */
+ timeout = maxtime/10 ;
+
+ /* Average reposting an ACK after 15 seconds */
+ state->retry_max = (int)(timeout/15);
+ }
+ /* But bound the total number */
+ if(state->retry_max<3)
+ state->retry_max=3;
+
+ if(state->retry_max>50)
+ state->retry_max=50;
+
+ /* Compute the re-ACK interval to suit the timeout */
+ state->retry_time = (int)(timeout/state->retry_max);
+ if(state->retry_time<1)
+ state->retry_time=1;
+
+ infof(data, "set timeouts for state %d; Total %d, retry %d maxtry %d\n",
+ state->state, (state->max_time-state->start_time),
+ state->retry_time, state->retry_max);
+}
+
+/**********************************************************
+ *
+ * tftp_set_send_first
+ *
+ * Event handler for the START state
+ *
+ **********************************************************/
+
+static void setpacketevent(tftp_packet_t *packet, unsigned short num)
+{
+ packet->data[0] = (unsigned char)(num >> 8);
+ packet->data[1] = (unsigned char)(num & 0xff);
+}
+
+
+static void setpacketblock(tftp_packet_t *packet, unsigned short num)
+{
+ packet->data[2] = (unsigned char)(num >> 8);
+ packet->data[3] = (unsigned char)(num & 0xff);
+}
+
+static unsigned short getrpacketevent(tftp_packet_t *packet)
+{
+ return (unsigned short)((packet->data[0] << 8) | packet->data[1]);
+}
+
+static unsigned short getrpacketblock(tftp_packet_t *packet)
+{
+ return (unsigned short)((packet->data[2] << 8) | packet->data[3]);
+}
+
+static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
+{
+ int sbytes;
+ const char *mode = "octet";
+ char *filename;
+ struct SessionHandle *data = state->conn->data;
+ CURLcode res = CURLE_OK;
+
+ /* Set ascii mode if -B flag was used */
+ if(data->set.prefer_ascii)
+ mode = "netascii";
+
+ switch(event) {
+
+ case TFTP_EVENT_INIT: /* Send the first packet out */
+ case TFTP_EVENT_TIMEOUT: /* Resend the first packet out */
+ /* Increment the retry counter, quit if over the limit */
+ state->retries++;
+ if(state->retries>state->retry_max) {
+ state->error = TFTP_ERR_NORESPONSE;
+ state->state = TFTP_STATE_FIN;
+ return res;
+ }
+
+ if(data->set.upload) {
+ /* If we are uploading, send an WRQ */
+ setpacketevent(&state->spacket, TFTP_EVENT_WRQ);
+ state->conn->data->reqdata.upload_fromhere = (char *)&state->spacket.data[4];
+ if(data->set.infilesize != -1)
+ Curl_pgrsSetUploadSize(data, data->set.infilesize);
+ }
+ else {
+ /* If we are downloading, send an RRQ */
+ setpacketevent(&state->spacket, TFTP_EVENT_RRQ);
+ }
+ /* As RFC3617 describes the separator slash is not actually part of the
+ file name so we skip the always-present first letter of the path string. */
+ filename = curl_easy_unescape(data, &state->conn->data->reqdata.path[1], 0,
+ NULL);
+ snprintf((char *)&state->spacket.data[2],
+ TFTP_BLOCKSIZE,
+ "%s%c%s%c", filename, '\0', mode, '\0');
+ sbytes = 4 + (int)strlen(filename) + (int)strlen(mode);
+ sbytes = sendto(state->sockfd, (void *)&state->spacket,
+ sbytes, 0,
+ state->conn->ip_addr->ai_addr,
+ state->conn->ip_addr->ai_addrlen);
+ if(sbytes < 0) {
+ failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
+ }
+ Curl_safefree(filename);
+ break;
+
+ case TFTP_EVENT_ACK: /* Connected for transmit */
+ infof(data, "%s\n", "Connected for transmit");
+ state->state = TFTP_STATE_TX;
+ tftp_set_timeouts(state);
+ return tftp_tx(state, event);
+
+ case TFTP_EVENT_DATA: /* connected for receive */
+ infof(data, "%s\n", "Connected for receive");
+ state->state = TFTP_STATE_RX;
+ tftp_set_timeouts(state);
+ return tftp_rx(state, event);
+
+ case TFTP_EVENT_ERROR:
+ state->state = TFTP_STATE_FIN;
+ break;
+
+ default:
+ failf(state->conn->data, "tftp_send_first: internal error\n");
+ break;
+ }
+ return res;
+}
+
+/**********************************************************
+ *
+ * tftp_rx
+ *
+ * Event handler for the RX state
+ *
+ **********************************************************/
+static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
+{
+ int sbytes;
+ int rblock;
+ struct SessionHandle *data = state->conn->data;
+
+ switch(event) {
+
+ case TFTP_EVENT_DATA:
+
+ /* Is this the block we expect? */
+ rblock = getrpacketblock(&state->rpacket);
+ if ((state->block+1) != rblock) {
+ /* No, log it, up the retry count and fail if over the limit */
+ infof(data,
+ "Received unexpected DATA packet block %d\n", rblock);
+ state->retries++;
+ if (state->retries>state->retry_max) {
+ failf(data, "tftp_rx: giving up waiting for block %d\n",
+ state->block+1);
+ return CURLE_TFTP_ILLEGAL;
+ }
+ }
+ /* This is the expected block. Reset counters and ACK it. */
+ state->block = (unsigned short)rblock;
+ state->retries = 0;
+ setpacketevent(&state->spacket, TFTP_EVENT_ACK);
+ setpacketblock(&state->spacket, state->block);
+ sbytes = sendto(state->sockfd, (void *)state->spacket.data,
+ 4, SEND_4TH_ARG,
+ (struct sockaddr *)&state->remote_addr,
+ state->remote_addrlen);
+ if(sbytes < 0) {
+ failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
+ }
+
+ /* Check if completed (That is, a less than full packet is received) */
+ if (state->rbytes < (int)sizeof(state->spacket)){
+ state->state = TFTP_STATE_FIN;
+ }
+ else {
+ state->state = TFTP_STATE_RX;
+ }
+ break;
+
+ case TFTP_EVENT_TIMEOUT:
+ /* Increment the retry count and fail if over the limit */
+ state->retries++;
+ infof(data,
+ "Timeout waiting for block %d ACK. Retries = %d\n", state->retries);
+ if(state->retries > state->retry_max) {
+ state->error = TFTP_ERR_TIMEOUT;
+ state->state = TFTP_STATE_FIN;
+ }
+ else {
+ /* Resend the previous ACK */
+ sbytes = sendto(state->sockfd, (void *)&state->spacket,
+ 4, SEND_4TH_ARG,
+ (struct sockaddr *)&state->remote_addr,
+ state->remote_addrlen);
+ /* Check all sbytes were sent */
+ if(sbytes<0) {
+ failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
+ }
+ }
+ break;
+
+ case TFTP_EVENT_ERROR:
+ state->state = TFTP_STATE_FIN;
+ break;
+
+ default:
+ failf(data, "%s\n", "tftp_rx: internal error");
+ break;
+ }
+ Curl_pgrsSetDownloadCounter(data,
+ (curl_off_t) state->block*TFTP_BLOCKSIZE);
+ return CURLE_OK;
+}
+
+/**********************************************************
+ *
+ * tftp_tx
+ *
+ * Event handler for the TX state
+ *
+ **********************************************************/
+static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
+{
+ struct SessionHandle *data = state->conn->data;
+ int sbytes;
+ int rblock;
+ CURLcode res = CURLE_OK;
+
+ switch(event) {
+
+ case TFTP_EVENT_ACK:
+ /* Ack the packet */
+ rblock = getrpacketblock(&state->rpacket);
+
+ if(rblock != state->block) {
+ /* This isn't the expected block. Log it and up the retry counter */
+ infof(data, "Received ACK for block %d, expecting %d\n",
+ rblock, state->block);
+ state->retries++;
+ /* Bail out if over the maximum */
+ if(state->retries>state->retry_max) {
+ failf(data, "tftp_tx: giving up waiting for block %d ack",
+ state->block);
+ res = CURLE_SEND_ERROR;
+ }
+ else {
+ /* Re-send the data packet */
+ sbytes = sendto(state->sockfd, (void *)&state->spacket,
+ 4+state->sbytes, SEND_4TH_ARG,
+ (struct sockaddr *)&state->remote_addr,
+ state->remote_addrlen);
+ /* Check all sbytes were sent */
+ if(sbytes<0) {
+ failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
+ res = CURLE_SEND_ERROR;
+ }
+ }
+ return res;
+ }
+ /* This is the expected packet. Reset the counters and send the next
+ block */
+ state->block++;
+ state->retries = 0;
+ setpacketevent(&state->spacket, TFTP_EVENT_DATA);
+ setpacketblock(&state->spacket, state->block);
+ if(state->block > 1 && state->sbytes < TFTP_BLOCKSIZE) {
+ state->state = TFTP_STATE_FIN;
+ return CURLE_OK;
+ }
+ res = Curl_fillreadbuffer(state->conn, TFTP_BLOCKSIZE, &state->sbytes);
+ if(res)
+ return res;
+ sbytes = sendto(state->sockfd, (void *)state->spacket.data,
+ 4+state->sbytes, SEND_4TH_ARG,
+ (struct sockaddr *)&state->remote_addr,
+ state->remote_addrlen);
+ /* Check all sbytes were sent */
+ if(sbytes<0) {
+ failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
+ }
+ break;
+
+ case TFTP_EVENT_TIMEOUT:
+ /* Increment the retry counter and log the timeout */
+ state->retries++;
+ infof(data, "Timeout waiting for block %d ACK. "
+ " Retries = %d\n", state->retries);
+ /* Decide if we've had enough */
+ if(state->retries > state->retry_max) {
+ state->error = TFTP_ERR_TIMEOUT;
+ state->state = TFTP_STATE_FIN;
+ } else {
+ /* Re-send the data packet */
+ sbytes = sendto(state->sockfd, (void *)&state->spacket,
+ 4+state->sbytes, SEND_4TH_ARG,
+ (struct sockaddr *)&state->remote_addr,
+ state->remote_addrlen);
+ /* Check all sbytes were sent */
+ if(sbytes<0) {
+ failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
+ }
+ }
+ break;
+
+ case TFTP_EVENT_ERROR:
+ state->state = TFTP_STATE_FIN;
+ break;
+
+ default:
+ failf(data, "%s\n", "tftp_tx: internal error");
+ break;
+ }
+
+ /* Update the progress meter */
+ Curl_pgrsSetUploadCounter(data, (curl_off_t) state->block*TFTP_BLOCKSIZE);
+
+ return res;
+}
+
+/**********************************************************
+ *
+ * tftp_state_machine
+ *
+ * The tftp state machine event dispatcher
+ *
+ **********************************************************/
+static CURLcode tftp_state_machine(tftp_state_data_t *state,
+ tftp_event_t event)
+{
+ CURLcode res = CURLE_OK;
+ struct SessionHandle *data = state->conn->data;
+ switch(state->state) {
+ case TFTP_STATE_START:
+ DEBUGF(infof(data, "TFTP_STATE_START\n"));
+ res = tftp_send_first(state, event);
+ break;
+ case TFTP_STATE_RX:
+ DEBUGF(infof(data, "TFTP_STATE_RX\n"));
+ res = tftp_rx(state, event);
+ break;
+ case TFTP_STATE_TX:
+ DEBUGF(infof(data, "TFTP_STATE_TX\n"));
+ res = tftp_tx(state, event);
+ break;
+ case TFTP_STATE_FIN:
+ infof(data, "%s\n", "TFTP finished");
+ break;
+ default:
+ DEBUGF(infof(data, "STATE: %d\n", state->state));
+ failf(data, "%s\n", "Internal state machine error");
+ res = CURLE_TFTP_ILLEGAL;
+ break;
+ }
+ return res;
+}
+
+
+/**********************************************************
+ *
+ * Curl_tftp_connect
+ *
+ * The connect callback
+ *
+ **********************************************************/
+CURLcode Curl_tftp_connect(struct connectdata *conn, bool *done)
+{
+ CURLcode code;
+ tftp_state_data_t *state;
+ int rc;
+
+ state = conn->data->reqdata.proto.tftp = calloc(sizeof(tftp_state_data_t),
+ 1);
+ if(!state)
+ return CURLE_OUT_OF_MEMORY;
+
+ conn->bits.close = FALSE; /* keep it open if possible */
+
+ state->conn = conn;
+ state->sockfd = state->conn->sock[FIRSTSOCKET];
+ state->state = TFTP_STATE_START;
+
+ ((struct sockaddr *)&state->local_addr)->sa_family =
+ conn->ip_addr->ai_family;
+
+ tftp_set_timeouts(state);
+
+ if(!conn->bits.reuse) {
+ /* If not reused, bind to any interface, random UDP port. If it is reused,
+ * this has already been done!
+ *
+ * We once used the size of the local_addr struct as the third argument for
+ * bind() to better work with IPv6 or whatever size the struct could have,
+ * but we learned that at least Tru64, AIX and IRIX *requires* the size of
+ * that argument to match the exact size of a 'sockaddr_in' struct when
+ * running IPv4-only.
+ *
+ * Therefore we use the size from the address we connected to, which we
+ * assume uses the same IP version and thus hopefully this works for both
+ * IPv4 and IPv6...
+ */
+ rc = bind(state->sockfd, (struct sockaddr *)&state->local_addr,
+ conn->ip_addr->ai_addrlen);
+ if(rc) {
+ failf(conn->data, "bind() failed; %s\n",
+ Curl_strerror(conn, Curl_sockerrno()));
+ return CURLE_COULDNT_CONNECT;
+ }
+ }
+
+ Curl_pgrsStartNow(conn->data);
+
+ *done = TRUE;
+ code = CURLE_OK;
+ return(code);
+}
+
+/**********************************************************
+ *
+ * Curl_tftp_done
+ *
+ * The done callback
+ *
+ **********************************************************/
+CURLcode Curl_tftp_done(struct connectdata *conn, CURLcode status,
+ bool premature)
+{
+ (void)status; /* unused */
+ (void)premature; /* not used */
+
+#if 0
+ free(conn->data->reqdata.proto.tftp);
+ conn->data->reqdata.proto.tftp = NULL;
+#endif
+ Curl_pgrsDone(conn);
+
+ return CURLE_OK;
+}
+
+
+/**********************************************************
+ *
+ * Curl_tftp
+ *
+ * The do callback
+ *
+ * This callback handles the entire TFTP transfer
+ *
+ **********************************************************/
+
+CURLcode Curl_tftp(struct connectdata *conn, bool *done)
+{
+ struct SessionHandle *data = conn->data;
+ tftp_state_data_t *state =
+ (tftp_state_data_t *) conn->data->reqdata.proto.tftp;
+ tftp_event_t event;
+ CURLcode code;
+ int rc;
+ struct Curl_sockaddr_storage fromaddr;
+ socklen_t fromlen;
+ int check_time = 0;
+
+ *done = TRUE;
+
+ /*
+ Since connections can be re-used between SessionHandles, this might be a
+ connection already existing but on a fresh SessionHandle struct so we must
+ make sure we have a good 'struct TFTP' to play with. For new connections,
+ the struct TFTP is allocated and setup in the Curl_tftp_connect() function.
+ */
+ if(!state) {
+ code = Curl_tftp_connect(conn, done);
+ if(code)
+ return code;
+ state = (tftp_state_data_t *)conn->data->reqdata.proto.tftp;
+ }
+
+ /* Run the TFTP State Machine */
+ for(tftp_state_machine(state, TFTP_EVENT_INIT);
+ state->state != TFTP_STATE_FIN;
+ tftp_state_machine(state, event) ) {
+
+ /* Wait until ready to read or timeout occurs */
+ rc=Curl_select(state->sockfd, CURL_SOCKET_BAD, state->retry_time * 1000);
+
+ if(rc == -1) {
+ /* bail out */
+ int error = Curl_sockerrno();
+ failf(data, "%s\n", Curl_strerror(conn, error));
+ event = TFTP_EVENT_ERROR;
+ }
+ else if (rc==0) {
+ /* A timeout occured */
+ event = TFTP_EVENT_TIMEOUT;
+
+ /* Force a look at transfer timeouts */
+ check_time = 0;
+
+ }
+ else {
+
+ /* Receive the packet */
+ fromlen=sizeof(fromaddr);
+ state->rbytes = recvfrom(state->sockfd,
+ (void *)&state->rpacket, sizeof(state->rpacket),
+ 0, (struct sockaddr *)&fromaddr, &fromlen);
+ if(state->remote_addrlen==0) {
+ memcpy(&state->remote_addr, &fromaddr, fromlen);
+ state->remote_addrlen = fromlen;
+ }
+
+ /* Sanity check packet length */
+ if (state->rbytes < 4) {
+ failf(conn->data, "Received too short packet\n");
+ /* Not a timeout, but how best to handle it? */
+ event = TFTP_EVENT_TIMEOUT;
+ }
+ else {
+
+ /* The event is given by the TFTP packet time */
+ event = (tftp_event_t)getrpacketevent(&state->rpacket);
+
+ switch(event) {
+ case TFTP_EVENT_DATA:
+ /* Don't pass to the client empty or retransmitted packets */
+ if (state->rbytes > 4 &&
+ ((state->block+1) == getrpacketblock(&state->rpacket))) {
+ code = Curl_client_write(conn, CLIENTWRITE_BODY,
+ (char *)&state->rpacket.data[4],
+ state->rbytes-4);
+ if(code)
+ return code;
+ }
+ break;
+ case TFTP_EVENT_ERROR:
+ state->error = (tftp_error_t)getrpacketblock(&state->rpacket);
+ infof(conn->data, "%s\n", (char *)&state->rpacket.data[4]);
+ break;
+ case TFTP_EVENT_ACK:
+ break;
+ case TFTP_EVENT_RRQ:
+ case TFTP_EVENT_WRQ:
+ default:
+ failf(conn->data, "%s\n", "Internal error: Unexpected packet");
+ break;
+ }
+
+ /* Update the progress meter */
+ if(Curl_pgrsUpdate(conn))
+ return CURLE_ABORTED_BY_CALLBACK;
+ }
+ }
+
+ /* Check for transfer timeout every 10 blocks, or after timeout */
+ if(check_time%10==0) {
+ time_t current;
+ time(&current);
+ if(current>state->max_time) {
+ DEBUGF(infof(data, "timeout: %d > %d\n",
+ current, state->max_time));
+ state->error = TFTP_ERR_TIMEOUT;
+ state->state = TFTP_STATE_FIN;
+ }
+ }
+
+ }
+
+ /* Tell curl we're done */
+ code = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ if(code)
+ return code;
+
+ /* If we have encountered an error */
+ if(state->error) {
+
+ /* Translate internal error codes to curl error codes */
+ switch(state->error) {
+ case TFTP_ERR_NOTFOUND:
+ code = CURLE_TFTP_NOTFOUND;
+ break;
+ case TFTP_ERR_PERM:
+ code = CURLE_TFTP_PERM;
+ break;
+ case TFTP_ERR_DISKFULL:
+ code = CURLE_TFTP_DISKFULL;
+ break;
+ case TFTP_ERR_ILLEGAL:
+ code = CURLE_TFTP_ILLEGAL;
+ break;
+ case TFTP_ERR_UNKNOWNID:
+ code = CURLE_TFTP_UNKNOWNID;
+ break;
+ case TFTP_ERR_EXISTS:
+ code = CURLE_TFTP_EXISTS;
+ break;
+ case TFTP_ERR_NOSUCHUSER:
+ code = CURLE_TFTP_NOSUCHUSER;
+ break;
+ case TFTP_ERR_TIMEOUT:
+ code = CURLE_OPERATION_TIMEOUTED;
+ break;
+ case TFTP_ERR_NORESPONSE:
+ code = CURLE_COULDNT_CONNECT;
+ break;
+ default:
+ code= CURLE_ABORTED_BY_CALLBACK;
+ break;
+ }
+ }
+ else
+ code = CURLE_OK;
+ return code;
+}
+#endif
diff --git a/Utilities/cmcurl/tftp.h b/Utilities/cmcurl/tftp.h
new file mode 100644
index 0000000000..c7125417b9
--- /dev/null
+++ b/Utilities/cmcurl/tftp.h
@@ -0,0 +1,31 @@
+#ifndef __TFTP_H
+#define __TFTP_H
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#ifndef CURL_DISABLE_TFTP
+CURLcode Curl_tftp_connect(struct connectdata *conn, bool *done);
+CURLcode Curl_tftp(struct connectdata *conn, bool *done);
+CURLcode Curl_tftp_done(struct connectdata *conn, CURLcode, bool premature);
+#endif
+#endif
diff --git a/Utilities/cmcurl/timeval.c b/Utilities/cmcurl/timeval.c
new file mode 100644
index 0000000000..bb9c0a174d
--- /dev/null
+++ b/Utilities/cmcurl/timeval.c
@@ -0,0 +1,116 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "timeval.h"
+
+#ifndef HAVE_GETTIMEOFDAY
+
+#ifdef WIN32
+#include <mmsystem.h>
+
+static int gettimeofday(struct timeval *tp, void *nothing)
+{
+#ifdef WITHOUT_MM_LIB
+ SYSTEMTIME st;
+ time_t tt;
+ struct tm tmtm;
+ /* mktime converts local to UTC */
+ GetLocalTime (&st);
+ tmtm.tm_sec = st.wSecond;
+ tmtm.tm_min = st.wMinute;
+ tmtm.tm_hour = st.wHour;
+ tmtm.tm_mday = st.wDay;
+ tmtm.tm_mon = st.wMonth - 1;
+ tmtm.tm_year = st.wYear - 1900;
+ tmtm.tm_isdst = -1;
+ tt = mktime (&tmtm);
+ tp->tv_sec = tt;
+ tp->tv_usec = st.wMilliseconds * 1000;
+#else
+ /**
+ ** The earlier time calculations using GetLocalTime
+ ** had a time resolution of 10ms.The timeGetTime, part
+ ** of multimedia apis offer a better time resolution
+ ** of 1ms.Need to link against winmm.lib for this
+ **/
+ unsigned long Ticks = 0;
+ unsigned long Sec =0;
+ unsigned long Usec = 0;
+ Ticks = timeGetTime();
+
+ Sec = Ticks/1000;
+ Usec = (Ticks - (Sec*1000))*1000;
+ tp->tv_sec = Sec;
+ tp->tv_usec = Usec;
+#endif /* WITHOUT_MM_LIB */
+ (void)nothing;
+ return 0;
+}
+#else /* WIN32 */
+/* non-win32 version of Curl_gettimeofday() */
+static int gettimeofday(struct timeval *tp, void *nothing)
+{
+ (void)nothing; /* we don't support specific time-zones */
+ tp->tv_sec = (long)time(NULL);
+ tp->tv_usec = 0;
+ return 0;
+}
+#endif /* WIN32 */
+#endif /* HAVE_GETTIMEOFDAY */
+
+/* Return the current time in a timeval struct */
+struct timeval curlx_tvnow(void)
+{
+ struct timeval now;
+ (void)gettimeofday(&now, NULL);
+ return now;
+}
+
+/*
+ * Make sure that the first argument is the more recent time, as otherwise
+ * we'll get a weird negative time-diff back...
+ *
+ * Returns: the time difference in number of milliseconds.
+ */
+long curlx_tvdiff(struct timeval newer, struct timeval older)
+{
+ return (newer.tv_sec-older.tv_sec)*1000+
+ (newer.tv_usec-older.tv_usec)/1000;
+}
+
+/*
+ * Same as curlx_tvdiff but with full usec resolution.
+ *
+ * Returns: the time difference in seconds with subsecond resolution.
+ */
+double curlx_tvdiff_secs(struct timeval newer, struct timeval older)
+{
+ return (double)(newer.tv_sec-older.tv_sec)+
+ (double)(newer.tv_usec-older.tv_usec)/1000000.0;
+}
+
+/* return the number of seconds in the given input timeval struct */
+long Curl_tvlong(struct timeval t1)
+{
+ return t1.tv_sec;
+}
diff --git a/Utilities/cmcurl/timeval.h b/Utilities/cmcurl/timeval.h
new file mode 100644
index 0000000000..effd741dac
--- /dev/null
+++ b/Utilities/cmcurl/timeval.h
@@ -0,0 +1,76 @@
+#ifndef __TIMEVAL_H
+#define __TIMEVAL_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/*
+ * CAUTION: this header is designed to work when included by the app-side
+ * as well as the library. Do not mix with library internals!
+ */
+
+#include "setup.h"
+
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#ifdef TIME_WITH_SYS_TIME
+#include <time.h>
+#endif
+#else
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+#endif
+
+#ifndef HAVE_STRUCT_TIMEVAL
+struct timeval {
+ long tv_sec;
+ long tv_usec;
+};
+#endif
+
+struct timeval curlx_tvnow(void);
+
+/*
+ * Make sure that the first argument (t1) is the more recent time and t2 is
+ * the older time, as otherwise you get a weird negative time-diff back...
+ *
+ * Returns: the time difference in number of milliseconds.
+ */
+long curlx_tvdiff(struct timeval t1, struct timeval t2);
+
+/*
+ * Same as curlx_tvdiff but with full usec resolution.
+ *
+ * Returns: the time difference in seconds with subsecond resolution.
+ */
+double curlx_tvdiff_secs(struct timeval t1, struct timeval t2);
+
+long Curl_tvlong(struct timeval t1);
+
+/* These two defines below exist to provide the older API for library
+ internals only. */
+#define Curl_tvnow() curlx_tvnow()
+#define Curl_tvdiff(x,y) curlx_tvdiff(x,y)
+#define Curl_tvdiff_secs(x,y) curlx_tvdiff_secs(x,y)
+
+#endif
diff --git a/Utilities/cmcurl/transfer.c b/Utilities/cmcurl/transfer.c
new file mode 100644
index 0000000000..5cb3361d25
--- /dev/null
+++ b/Utilities/cmcurl/transfer.c
@@ -0,0 +1,2494 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+/* -- WIN32 approved -- */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#include <errno.h>
+
+#include "strtoofft.h"
+#include "strequal.h"
+
+#ifdef WIN32
+#include <time.h>
+#include <io.h>
+#else
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <netdb.h>
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#include <signal.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+#ifndef HAVE_SOCKET
+#error "We can't compile without socket() support!"
+#endif
+
+#endif
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "netrc.h"
+
+#include "content_encoding.h"
+#include "hostip.h"
+#include "transfer.h"
+#include "sendf.h"
+#include "speedcheck.h"
+#include "progress.h"
+#include "http.h"
+#include "url.h"
+#include "getinfo.h"
+#include "sslgen.h"
+#include "http_digest.h"
+#include "http_ntlm.h"
+#include "http_negotiate.h"
+#include "share.h"
+#include "memory.h"
+#include "select.h"
+#include "multiif.h"
+#include "easyif.h" /* for Curl_convert_to_network prototype */
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+#define CURL_TIMEOUT_EXPECT_100 1000 /* counting ms here */
+
+/*
+ * This function will call the read callback to fill our buffer with data
+ * to upload.
+ */
+CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
+{
+ struct SessionHandle *data = conn->data;
+ size_t buffersize = (size_t)bytes;
+ int nread;
+
+ if(conn->bits.upload_chunky) {
+ /* if chunked Transfer-Encoding */
+ buffersize -= (8 + 2 + 2); /* 32bit hex + CRLF + CRLF */
+ data->reqdata.upload_fromhere += 10; /* 32bit hex + CRLF */
+ }
+
+ /* this function returns a size_t, so we typecast to int to prevent warnings
+ with picky compilers */
+ nread = (int)conn->fread(data->reqdata.upload_fromhere, 1,
+ buffersize, conn->fread_in);
+
+ if(nread == CURL_READFUNC_ABORT) {
+ failf(data, "operation aborted by callback\n");
+ return CURLE_ABORTED_BY_CALLBACK;
+ }
+
+ if(!conn->bits.forbidchunk && conn->bits.upload_chunky) {
+ /* if chunked Transfer-Encoding */
+ char hexbuffer[11];
+ int hexlen = snprintf(hexbuffer, sizeof(hexbuffer),
+ "%x\r\n", nread);
+ /* move buffer pointer */
+ data->reqdata.upload_fromhere -= hexlen;
+ nread += hexlen;
+
+ /* copy the prefix to the buffer */
+ memcpy(data->reqdata.upload_fromhere, hexbuffer, hexlen);
+
+ /* always append CRLF to the data */
+ memcpy(data->reqdata.upload_fromhere + nread, "\r\n", 2);
+
+ if((nread - hexlen) == 0) {
+ /* mark this as done once this chunk is transfered */
+ data->reqdata.keep.upload_done = TRUE;
+ }
+
+ nread+=2; /* for the added CRLF */
+ }
+
+ *nreadp = nread;
+
+#ifdef CURL_DOES_CONVERSIONS
+ if(data->set.prefer_ascii) {
+ CURLcode res;
+ res = Curl_convert_to_network(data, data->reqdata.upload_fromhere, nread);
+ /* Curl_convert_to_network calls failf if unsuccessful */
+ if(res != CURLE_OK) {
+ return(res);
+ }
+ }
+#endif /* CURL_DOES_CONVERSIONS */
+
+ return CURLE_OK;
+}
+
+/*
+ * checkhttpprefix()
+ *
+ * Returns TRUE if member of the list matches prefix of string
+ */
+static bool
+checkhttpprefix(struct SessionHandle *data,
+ const char *s)
+{
+ struct curl_slist *head = data->set.http200aliases;
+ bool rc = FALSE;
+#ifdef CURL_DOES_CONVERSIONS
+ /* convert from the network encoding using a scratch area */
+ char *scratch = calloc(1, strlen(s)+1);
+ if (NULL == scratch) {
+ failf (data, "Failed to calloc memory for conversion!");
+ return FALSE; /* can't return CURLE_OUT_OF_MEMORY so return FALSE */
+ }
+ strcpy(scratch, s);
+ if (CURLE_OK != Curl_convert_from_network(data, scratch, strlen(s)+1)) {
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ free(scratch);
+ return FALSE; /* can't return CURLE_foobar so return FALSE */
+ }
+ s = scratch;
+#endif /* CURL_DOES_CONVERSIONS */
+
+ while (head) {
+ if (checkprefix(head->data, s)) {
+ rc = TRUE;
+ break;
+ }
+ head = head->next;
+ }
+
+ if ((rc != TRUE) && (checkprefix("HTTP/", s))) {
+ rc = TRUE;
+ }
+
+#ifdef CURL_DOES_CONVERSIONS
+ free(scratch);
+#endif /* CURL_DOES_CONVERSIONS */
+ return rc;
+}
+
+/*
+ * Curl_readrewind() rewinds the read stream. This typically (so far) only
+ * used for HTTP POST/PUT with multi-pass authentication when a sending was
+ * denied and a resend is necessary.
+ */
+CURLcode Curl_readrewind(struct connectdata *conn)
+{
+ struct SessionHandle *data = conn->data;
+
+ conn->bits.rewindaftersend = FALSE; /* we rewind now */
+
+ /* We have sent away data. If not using CURLOPT_POSTFIELDS or
+ CURLOPT_HTTPPOST, call app to rewind
+ */
+ if(data->set.postfields ||
+ (data->set.httpreq == HTTPREQ_POST_FORM))
+ ; /* do nothing */
+ else {
+ if(data->set.ioctl) {
+ curlioerr err;
+
+ err = (data->set.ioctl) (data, CURLIOCMD_RESTARTREAD,
+ data->set.ioctl_client);
+ infof(data, "the ioctl callback returned %d\n", (int)err);
+
+ if(err) {
+ /* FIXME: convert to a human readable error message */
+ failf(data, "ioctl callback returned error %d\n", (int)err);
+ return CURLE_SEND_FAIL_REWIND;
+ }
+ }
+ else {
+ /* If no CURLOPT_READFUNCTION is used, we know that we operate on a
+ given FILE * stream and we can actually attempt to rewind that
+ ourself with fseek() */
+ if(data->set.fread == (curl_read_callback)fread) {
+ if(-1 != fseek(data->set.in, 0, SEEK_SET))
+ /* successful rewind */
+ return CURLE_OK;
+ }
+
+ /* no callback set or failure aboe, makes us fail at once */
+ failf(data, "necessary data rewind wasn't possible\n");
+ return CURLE_SEND_FAIL_REWIND;
+ }
+ }
+ return CURLE_OK;
+}
+
+static int data_pending(struct connectdata *conn)
+{
+ return Curl_ssl_data_pending(conn, FIRSTSOCKET);
+}
+
+#ifndef MIN
+#define MIN(a,b) (a < b ? a : b)
+#endif
+
+static void read_rewind(struct connectdata *conn,
+ size_t thismuch)
+{
+ conn->read_pos -= thismuch;
+ conn->bits.stream_was_rewound = TRUE;
+
+#ifdef CURLDEBUG
+ {
+ char buf[512 + 1];
+ size_t show;
+
+ show = MIN(conn->buf_len - conn->read_pos, sizeof(buf)-1);
+ memcpy(buf, conn->master_buffer + conn->read_pos, show);
+ buf[show] = '\0';
+
+ DEBUGF(infof(conn->data,
+ "Buffer after stream rewind (read_pos = %d): [%s]",
+ conn->read_pos, buf));
+ }
+#endif
+}
+
+/*
+ * Curl_readwrite() is the low-level function to be called when data is to
+ * be read and written to/from the connection.
+ */
+CURLcode Curl_readwrite(struct connectdata *conn,
+ bool *done)
+{
+ struct SessionHandle *data = conn->data;
+ struct Curl_transfer_keeper *k = &data->reqdata.keep;
+ CURLcode result;
+ ssize_t nread; /* number of bytes read */
+ int didwhat=0;
+
+ curl_socket_t fd_read;
+ curl_socket_t fd_write;
+ int select_res;
+
+ curl_off_t contentlength;
+
+ /* only use the proper socket if the *_HOLD bit is not set simultaneously as
+ then we are in rate limiting state in that transfer direction */
+
+ if((k->keepon & (KEEP_READ|KEEP_READ_HOLD)) == KEEP_READ)
+ fd_read = conn->sockfd;
+ else
+ fd_read = CURL_SOCKET_BAD;
+
+ if((k->keepon & (KEEP_WRITE|KEEP_WRITE_HOLD)) == KEEP_WRITE)
+ fd_write = conn->writesockfd;
+ else
+ fd_write = CURL_SOCKET_BAD;
+
+ select_res = Curl_select(fd_read, fd_write, 0);
+ if(select_res == CSELECT_ERR) {
+ failf(data, "select/poll returned error");
+ return CURLE_SEND_ERROR;
+ }
+
+ do {
+ /* We go ahead and do a read if we have a readable socket or if
+ the stream was rewound (in which case we have data in a
+ buffer) */
+ if((k->keepon & KEEP_READ) &&
+ ((select_res & CSELECT_IN) || conn->bits.stream_was_rewound)) {
+ /* read */
+ bool is_empty_data = FALSE;
+
+ /* This is where we loop until we have read everything there is to
+ read or we get a EWOULDBLOCK */
+ do {
+ size_t buffersize = data->set.buffer_size?
+ data->set.buffer_size : BUFSIZE;
+ size_t bytestoread = buffersize;
+ int readrc;
+
+ if (k->size != -1 && !k->header) {
+ /* make sure we don't read "too much" if we can help it since we
+ might be pipelining and then someone else might want to read what
+ follows! */
+ curl_off_t totalleft = k->size - k->bytecount;
+ if(totalleft < (curl_off_t)bytestoread)
+ bytestoread = (size_t)totalleft;
+ }
+
+ /* receive data from the network! */
+ readrc = Curl_read(conn, conn->sockfd, k->buf, bytestoread, &nread);
+
+ /* subzero, this would've blocked */
+ if(0 > readrc)
+ break; /* get out of loop */
+
+ /* get the CURLcode from the int */
+ result = (CURLcode)readrc;
+
+ if(result>0)
+ return result;
+
+ if ((k->bytecount == 0) && (k->writebytecount == 0)) {
+ Curl_pgrsTime(data, TIMER_STARTTRANSFER);
+ if(k->wait100_after_headers)
+ /* set time stamp to compare with when waiting for the 100 */
+ k->start100 = Curl_tvnow();
+ }
+
+ didwhat |= KEEP_READ;
+ /* indicates data of zero size, i.e. empty file */
+ is_empty_data = (bool)((nread == 0) && (k->bodywrites == 0));
+
+ /* NULL terminate, allowing string ops to be used */
+ if (0 < nread || is_empty_data) {
+ k->buf[nread] = 0;
+ }
+ else if (0 >= nread) {
+ /* if we receive 0 or less here, the server closed the connection
+ and we bail out from this! */
+
+ k->keepon &= ~KEEP_READ;
+ break;
+ }
+
+ /* Default buffer to use when we write the buffer, it may be changed
+ in the flow below before the actual storing is done. */
+ k->str = k->buf;
+
+ /* Since this is a two-state thing, we check if we are parsing
+ headers at the moment or not. */
+ if (k->header) {
+ /* we are in parse-the-header-mode */
+ bool stop_reading = FALSE;
+
+ /* header line within buffer loop */
+ do {
+ size_t hbufp_index;
+ size_t rest_length;
+ size_t full_length;
+ int writetype;
+
+ /* str_start is start of line within buf */
+ k->str_start = k->str;
+
+ /* data is in network encoding so use 0x0a instead of '\n' */
+ k->end_ptr = memchr(k->str_start, 0x0a, nread);
+
+ if (!k->end_ptr) {
+ /* Not a complete header line within buffer, append the data to
+ the end of the headerbuff. */
+
+ if (k->hbuflen + nread >= data->state.headersize) {
+ /* We enlarge the header buffer as it is too small */
+ char *newbuff;
+ size_t newsize=CURLMAX((k->hbuflen+nread)*3/2,
+ data->state.headersize*2);
+ hbufp_index = k->hbufp - data->state.headerbuff;
+ newbuff = (char *)realloc(data->state.headerbuff, newsize);
+ if(!newbuff) {
+ failf (data, "Failed to alloc memory for big header!");
+ return CURLE_OUT_OF_MEMORY;
+ }
+ data->state.headersize=newsize;
+ data->state.headerbuff = newbuff;
+ k->hbufp = data->state.headerbuff + hbufp_index;
+ }
+ memcpy(k->hbufp, k->str, nread);
+ k->hbufp += nread;
+ k->hbuflen += nread;
+ if (!k->headerline && (k->hbuflen>5)) {
+ /* make a first check that this looks like a HTTP header */
+ if(!checkhttpprefix(data, data->state.headerbuff)) {
+ /* this is not the beginning of a HTTP first header line */
+ k->header = FALSE;
+ k->badheader = HEADER_ALLBAD;
+ break;
+ }
+ }
+
+ break; /* read more and try again */
+ }
+
+ /* decrease the size of the remaining (supposed) header line */
+ rest_length = (k->end_ptr - k->str)+1;
+ nread -= (ssize_t)rest_length;
+
+ k->str = k->end_ptr + 1; /* move past new line */
+
+ full_length = k->str - k->str_start;
+
+ /*
+ * We're about to copy a chunk of data to the end of the
+ * already received header. We make sure that the full string
+ * fit in the allocated header buffer, or else we enlarge
+ * it.
+ */
+ if (k->hbuflen + full_length >=
+ data->state.headersize) {
+ char *newbuff;
+ size_t newsize=CURLMAX((k->hbuflen+full_length)*3/2,
+ data->state.headersize*2);
+ hbufp_index = k->hbufp - data->state.headerbuff;
+ newbuff = (char *)realloc(data->state.headerbuff, newsize);
+ if(!newbuff) {
+ failf (data, "Failed to alloc memory for big header!");
+ return CURLE_OUT_OF_MEMORY;
+ }
+ data->state.headersize= newsize;
+ data->state.headerbuff = newbuff;
+ k->hbufp = data->state.headerbuff + hbufp_index;
+ }
+
+ /* copy to end of line */
+ memcpy(k->hbufp, k->str_start, full_length);
+ k->hbufp += full_length;
+ k->hbuflen += full_length;
+ *k->hbufp = 0;
+ k->end_ptr = k->hbufp;
+
+ k->p = data->state.headerbuff;
+
+ /****
+ * We now have a FULL header line that p points to
+ *****/
+
+ if(!k->headerline) {
+ /* the first read header */
+ if((k->hbuflen>5) &&
+ !checkhttpprefix(data, data->state.headerbuff)) {
+ /* this is not the beginning of a HTTP first header line */
+ k->header = FALSE;
+ if(nread)
+ /* since there's more, this is a partial bad header */
+ k->badheader = HEADER_PARTHEADER;
+ else {
+ /* this was all we read so its all a bad header */
+ k->badheader = HEADER_ALLBAD;
+ nread = (ssize_t)rest_length;
+ }
+ break;
+ }
+ }
+
+ /* headers are in network encoding so
+ use 0x0a and 0x0d instead of '\n' and '\r' */
+ if ((0x0a == *k->p) || (0x0d == *k->p)) {
+ size_t headerlen;
+ /* Zero-length header line means end of headers! */
+
+#ifdef CURL_DOES_CONVERSIONS
+ if (0x0d == *k->p) {
+ *k->p = '\r'; /* replace with CR in host encoding */
+ k->p++; /* pass the CR byte */
+ }
+ if (0x0a == *k->p) {
+ *k->p = '\n'; /* replace with LF in host encoding */
+ k->p++; /* pass the LF byte */
+ }
+#else
+ if ('\r' == *k->p)
+ k->p++; /* pass the \r byte */
+ if ('\n' == *k->p)
+ k->p++; /* pass the \n byte */
+#endif /* CURL_DOES_CONVERSIONS */
+
+ if(100 == k->httpcode) {
+ /*
+ * We have made a HTTP PUT or POST and this is 1.1-lingo
+ * that tells us that the server is OK with this and ready
+ * to receive the data.
+ * However, we'll get more headers now so we must get
+ * back into the header-parsing state!
+ */
+ k->header = TRUE;
+ k->headerline = 0; /* restart the header line counter */
+ /* if we did wait for this do enable write now! */
+ if (k->write_after_100_header) {
+
+ k->write_after_100_header = FALSE;
+ k->keepon |= KEEP_WRITE;
+ }
+ }
+ else {
+ k->header = FALSE; /* no more header to parse! */
+
+ if((k->size == -1) && !conn->bits.chunk && !conn->bits.close)
+ /* When connection is not to get closed, but no
+ Content-Length nor Content-Encoding chunked have been
+ received, there is no body in this response. We don't set
+ stop_reading TRUE since that would also prevent necessary
+ authentication actions to take place. */
+ conn->bits.no_body = TRUE;
+
+ }
+
+ if (417 == k->httpcode) {
+ /*
+ * we got: "417 Expectation Failed" this means:
+ * we have made a HTTP call and our Expect Header
+ * seems to cause a problem => abort the write operations
+ * (or prevent them from starting).
+ */
+ k->write_after_100_header = FALSE;
+ k->keepon &= ~KEEP_WRITE;
+ }
+
+#ifndef CURL_DISABLE_HTTP
+ /*
+ * When all the headers have been parsed, see if we should give
+ * up and return an error.
+ */
+ if (Curl_http_should_fail(conn)) {
+ failf (data, "The requested URL returned error: %d",
+ k->httpcode);
+ return CURLE_HTTP_RETURNED_ERROR;
+ }
+#endif /* CURL_DISABLE_HTTP */
+
+ /* now, only output this if the header AND body are requested:
+ */
+ writetype = CLIENTWRITE_HEADER;
+ if (data->set.include_header)
+ writetype |= CLIENTWRITE_BODY;
+
+ headerlen = k->p - data->state.headerbuff;
+
+ result = Curl_client_write(conn, writetype,
+ data->state.headerbuff,
+ headerlen);
+ if(result)
+ return result;
+
+ data->info.header_size += (long)headerlen;
+ conn->headerbytecount += (long)headerlen;
+
+ conn->deductheadercount =
+ (100 == k->httpcode)?conn->headerbytecount:0;
+
+ if (data->reqdata.resume_from &&
+ (data->set.httpreq==HTTPREQ_GET) &&
+ (k->httpcode == 416)) {
+ /* "Requested Range Not Satisfiable" */
+ stop_reading = TRUE;
+ }
+
+#ifndef CURL_DISABLE_HTTP
+ if(!stop_reading) {
+ /* Curl_http_auth_act() checks what authentication methods
+ * that are available and decides which one (if any) to
+ * use. It will set 'newurl' if an auth metod was picked. */
+ result = Curl_http_auth_act(conn);
+
+ if(result)
+ return result;
+
+ if(conn->bits.rewindaftersend) {
+ /* We rewind after a complete send, so thus we continue
+ sending now */
+ infof(data, "Keep sending data to get tossed away!\n");
+ k->keepon |= KEEP_WRITE;
+ }
+ }
+#endif /* CURL_DISABLE_HTTP */
+
+ if(!k->header) {
+ /*
+ * really end-of-headers.
+ *
+ * If we requested a "no body", this is a good time to get
+ * out and return home.
+ */
+ if(conn->bits.no_body)
+ stop_reading = TRUE;
+ else {
+ /* If we know the expected size of this document, we set the
+ maximum download size to the size of the expected
+ document or else, we won't know when to stop reading!
+
+ Note that we set the download maximum even if we read a
+ "Connection: close" header, to make sure that
+ "Content-Length: 0" still prevents us from attempting to
+ read the (missing) response-body.
+ */
+ /* According to RFC2616 section 4.4, we MUST ignore
+ Content-Length: headers if we are now receiving data
+ using chunked Transfer-Encoding.
+ */
+ if(conn->bits.chunk)
+ k->size=-1;
+
+ }
+ if(-1 != k->size) {
+ /* We do this operation even if no_body is true, since this
+ data might be retrieved later with curl_easy_getinfo()
+ and its CURLINFO_CONTENT_LENGTH_DOWNLOAD option. */
+
+ Curl_pgrsSetDownloadSize(data, k->size);
+ k->maxdownload = k->size;
+ }
+ /* If max download size is *zero* (nothing) we already
+ have nothing and can safely return ok now! */
+ if(0 == k->maxdownload)
+ stop_reading = TRUE;
+
+ if(stop_reading) {
+ /* we make sure that this socket isn't read more now */
+ k->keepon &= ~KEEP_READ;
+ }
+
+ break; /* exit header line loop */
+ }
+
+ /* We continue reading headers, so reset the line-based
+ header parsing variables hbufp && hbuflen */
+ k->hbufp = data->state.headerbuff;
+ k->hbuflen = 0;
+ continue;
+ }
+
+ /*
+ * Checks for special headers coming up.
+ */
+
+ if (!k->headerline++) {
+ /* This is the first header, it MUST be the error code line
+ or else we consider this to be the body right away! */
+ int httpversion_major;
+ int nc;
+#ifdef CURL_DOES_CONVERSIONS
+#define HEADER1 scratch
+#define SCRATCHSIZE 21
+ CURLcode res;
+ char scratch[SCRATCHSIZE+1]; /* "HTTP/major.minor 123" */
+ /* We can't really convert this yet because we
+ don't know if it's the 1st header line or the body.
+ So we do a partial conversion into a scratch area,
+ leaving the data at k->p as-is.
+ */
+ strncpy(&scratch[0], k->p, SCRATCHSIZE);
+ scratch[SCRATCHSIZE] = 0; /* null terminate */
+ res = Curl_convert_from_network(data,
+ &scratch[0],
+ SCRATCHSIZE);
+ if (CURLE_OK != res) {
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ return res;
+ }
+#else
+#define HEADER1 k->p /* no conversion needed, just use k->p */
+#endif /* CURL_DOES_CONVERSIONS */
+
+ nc = sscanf(HEADER1,
+ " HTTP/%d.%d %3d",
+ &httpversion_major,
+ &k->httpversion,
+ &k->httpcode);
+ if (nc==3) {
+ k->httpversion += 10 * httpversion_major;
+ }
+ else {
+ /* this is the real world, not a Nirvana
+ NCSA 1.5.x returns this crap when asked for HTTP/1.1
+ */
+ nc=sscanf(HEADER1, " HTTP %3d", &k->httpcode);
+ k->httpversion = 10;
+
+ /* If user has set option HTTP200ALIASES,
+ compare header line against list of aliases
+ */
+ if (!nc) {
+ if (checkhttpprefix(data, k->p)) {
+ nc = 1;
+ k->httpcode = 200;
+ k->httpversion =
+ (data->set.httpversion==CURL_HTTP_VERSION_1_0)? 10 : 11;
+ }
+ }
+ }
+
+ if (nc) {
+ data->info.httpcode = k->httpcode;
+ data->info.httpversion = k->httpversion;
+
+ /*
+ * This code executes as part of processing the header. As a
+ * result, it's not totally clear how to interpret the
+ * response code yet as that depends on what other headers may
+ * be present. 401 and 407 may be errors, but may be OK
+ * depending on how authentication is working. Other codes
+ * are definitely errors, so give up here.
+ */
+ if (data->set.http_fail_on_error && (k->httpcode >= 400) &&
+ ((k->httpcode != 401) || !data->set.userpwd) &&
+ ((k->httpcode != 407) || !data->set.proxyuserpwd) ) {
+
+ if (data->reqdata.resume_from &&
+ (data->set.httpreq==HTTPREQ_GET) &&
+ (k->httpcode == 416)) {
+ /* "Requested Range Not Satisfiable", just proceed and
+ pretend this is no error */
+ }
+ else {
+ /* serious error, go home! */
+ failf (data, "The requested URL returned error: %d",
+ k->httpcode);
+ return CURLE_HTTP_RETURNED_ERROR;
+ }
+ }
+
+ if(k->httpversion == 10)
+ /* Default action for HTTP/1.0 must be to close, unless
+ we get one of those fancy headers that tell us the
+ server keeps it open for us! */
+ conn->bits.close = TRUE;
+
+ switch(k->httpcode) {
+ case 204:
+ /* (quote from RFC2616, section 10.2.5): The server has
+ * fulfilled the request but does not need to return an
+ * entity-body ... The 204 response MUST NOT include a
+ * message-body, and thus is always terminated by the first
+ * empty line after the header fields. */
+ /* FALLTHROUGH */
+ case 416: /* Requested Range Not Satisfiable, it has the
+ Content-Length: set as the "real" document but no
+ actual response is sent. */
+ case 304:
+ /* (quote from RFC2616, section 10.3.5): The 304 response
+ * MUST NOT contain a message-body, and thus is always
+ * terminated by the first empty line after the header
+ * fields. */
+ k->size=0;
+ k->maxdownload=0;
+ k->ignorecl = TRUE; /* ignore Content-Length headers */
+ break;
+ default:
+ /* nothing */
+ break;
+ }
+ }
+ else {
+ k->header = FALSE; /* this is not a header line */
+ break;
+ }
+ }
+
+#ifdef CURL_DOES_CONVERSIONS
+ /* convert from the network encoding */
+ result = Curl_convert_from_network(data, k->p, strlen(k->p));
+ if (CURLE_OK != result) {
+ return(result);
+ }
+ /* Curl_convert_from_network calls failf if unsuccessful */
+#endif /* CURL_DOES_CONVERSIONS */
+
+ /* Check for Content-Length: header lines to get size. Ignore
+ the header completely if we get a 416 response as then we're
+ resuming a document that we don't get, and this header contains
+ info about the true size of the document we didn't get now. */
+ if (!k->ignorecl && !data->set.ignorecl &&
+ checkprefix("Content-Length:", k->p)) {
+ contentlength = curlx_strtoofft(k->p+15, NULL, 10);
+ if (data->set.max_filesize &&
+ contentlength > data->set.max_filesize) {
+ failf(data, "Maximum file size exceeded");
+ return CURLE_FILESIZE_EXCEEDED;
+ }
+ if(contentlength >= 0) {
+ k->size = contentlength;
+ k->maxdownload = k->size;
+ }
+ else {
+ /* Negative Content-Length is really odd, and we know it
+ happens for example when older Apache servers send large
+ files */
+ conn->bits.close = TRUE;
+ infof(data, "Negative content-length: %" FORMAT_OFF_T
+ ", closing after transfer\n", contentlength);
+ }
+ }
+ /* check for Content-Type: header lines to get the mime-type */
+ else if (checkprefix("Content-Type:", k->p)) {
+ char *start;
+ char *end;
+ size_t len;
+
+ /* Find the first non-space letter */
+ for(start=k->p+13;
+ *start && ISSPACE(*start);
+ start++)
+ ; /* empty loop */
+
+ /* data is now in the host encoding so
+ use '\r' and '\n' instead of 0x0d and 0x0a */
+ end = strchr(start, '\r');
+ if(!end)
+ end = strchr(start, '\n');
+
+ if(end) {
+ /* skip all trailing space letters */
+ for(; ISSPACE(*end) && (end > start); end--)
+ ; /* empty loop */
+
+ /* get length of the type */
+ len = end-start+1;
+
+ /* allocate memory of a cloned copy */
+ Curl_safefree(data->info.contenttype);
+
+ data->info.contenttype = malloc(len + 1);
+ if (NULL == data->info.contenttype)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* copy the content-type string */
+ memcpy(data->info.contenttype, start, len);
+ data->info.contenttype[len] = 0; /* zero terminate */
+ }
+ }
+#ifndef CURL_DISABLE_HTTP
+ else if((k->httpversion == 10) &&
+ conn->bits.httpproxy &&
+ Curl_compareheader(k->p,
+ "Proxy-Connection:", "keep-alive")) {
+ /*
+ * When a HTTP/1.0 reply comes when using a proxy, the
+ * 'Proxy-Connection: keep-alive' line tells us the
+ * connection will be kept alive for our pleasure.
+ * Default action for 1.0 is to close.
+ */
+ conn->bits.close = FALSE; /* don't close when done */
+ infof(data, "HTTP/1.0 proxy connection set to keep alive!\n");
+ }
+ else if((k->httpversion == 11) &&
+ conn->bits.httpproxy &&
+ Curl_compareheader(k->p,
+ "Proxy-Connection:", "close")) {
+ /*
+ * We get a HTTP/1.1 response from a proxy and it says it'll
+ * close down after this transfer.
+ */
+ conn->bits.close = TRUE; /* close when done */
+ infof(data, "HTTP/1.1 proxy connection set close!\n");
+ }
+ else if((k->httpversion == 10) &&
+ Curl_compareheader(k->p, "Connection:", "keep-alive")) {
+ /*
+ * A HTTP/1.0 reply with the 'Connection: keep-alive' line
+ * tells us the connection will be kept alive for our
+ * pleasure. Default action for 1.0 is to close.
+ *
+ * [RFC2068, section 19.7.1] */
+ conn->bits.close = FALSE; /* don't close when done */
+ infof(data, "HTTP/1.0 connection set to keep alive!\n");
+ }
+ else if (Curl_compareheader(k->p, "Connection:", "close")) {
+ /*
+ * [RFC 2616, section 8.1.2.1]
+ * "Connection: close" is HTTP/1.1 language and means that
+ * the connection will close when this request has been
+ * served.
+ */
+ conn->bits.close = TRUE; /* close when done */
+ }
+ else if (Curl_compareheader(k->p,
+ "Transfer-Encoding:", "chunked")) {
+ /*
+ * [RFC 2616, section 3.6.1] A 'chunked' transfer encoding
+ * means that the server will send a series of "chunks". Each
+ * chunk starts with line with info (including size of the
+ * coming block) (terminated with CRLF), then a block of data
+ * with the previously mentioned size. There can be any amount
+ * of chunks, and a chunk-data set to zero signals the
+ * end-of-chunks. */
+ conn->bits.chunk = TRUE; /* chunks coming our way */
+
+ /* init our chunky engine */
+ Curl_httpchunk_init(conn);
+ }
+
+ else if (checkprefix("Trailer:", k->p) ||
+ checkprefix("Trailers:", k->p)) {
+ /*
+ * This test helps Curl_httpchunk_read() to determine to look
+ * for well formed trailers after the zero chunksize record. In
+ * this case a CRLF is required after the zero chunksize record
+ * when no trailers are sent, or after the last trailer record.
+ *
+ * It seems both Trailer: and Trailers: occur in the wild.
+ */
+ conn->bits.trailerHdrPresent = TRUE;
+ }
+
+ else if (checkprefix("Content-Encoding:", k->p) &&
+ data->set.encoding) {
+ /*
+ * Process Content-Encoding. Look for the values: identity,
+ * gzip, deflate, compress, x-gzip and x-compress. x-gzip and
+ * x-compress are the same as gzip and compress. (Sec 3.5 RFC
+ * 2616). zlib cannot handle compress. However, errors are
+ * handled further down when the response body is processed
+ */
+ char *start;
+
+ /* Find the first non-space letter */
+ for(start=k->p+17;
+ *start && ISSPACE(*start);
+ start++)
+ ; /* empty loop */
+
+ /* Record the content-encoding for later use */
+ if (checkprefix("identity", start))
+ k->content_encoding = IDENTITY;
+ else if (checkprefix("deflate", start))
+ k->content_encoding = DEFLATE;
+ else if (checkprefix("gzip", start)
+ || checkprefix("x-gzip", start))
+ k->content_encoding = GZIP;
+ else if (checkprefix("compress", start)
+ || checkprefix("x-compress", start))
+ k->content_encoding = COMPRESS;
+ }
+ else if (checkprefix("Content-Range:", k->p)) {
+ /* Content-Range: bytes [num]-
+ Content-Range: bytes: [num]-
+ Content-Range: [num]-
+
+ The second format was added since Sun's webserver
+ JavaWebServer/1.1.1 obviously sends the header this way!
+ The third added since some servers use that!
+ */
+
+ char *ptr = k->p + 14;
+
+ /* Move forward until first digit */
+ while(*ptr && !ISDIGIT(*ptr))
+ ptr++;
+
+ k->offset = curlx_strtoofft(ptr, NULL, 10);
+
+ if (data->reqdata.resume_from == k->offset)
+ /* we asked for a resume and we got it */
+ k->content_range = TRUE;
+ }
+#if !defined(CURL_DISABLE_COOKIES)
+ else if(data->cookies &&
+ checkprefix("Set-Cookie:", k->p)) {
+ Curl_share_lock(data, CURL_LOCK_DATA_COOKIE,
+ CURL_LOCK_ACCESS_SINGLE);
+ Curl_cookie_add(data,
+ data->cookies, TRUE, k->p+11,
+ /* If there is a custom-set Host: name, use it
+ here, or else use real peer host name. */
+ conn->allocptr.cookiehost?
+ conn->allocptr.cookiehost:conn->host.name,
+ data->reqdata.path);
+ Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
+ }
+#endif
+ else if(checkprefix("Last-Modified:", k->p) &&
+ (data->set.timecondition || data->set.get_filetime) ) {
+ time_t secs=time(NULL);
+ k->timeofdoc = curl_getdate(k->p+strlen("Last-Modified:"),
+ &secs);
+ if(data->set.get_filetime)
+ data->info.filetime = (long)k->timeofdoc;
+ }
+ else if((checkprefix("WWW-Authenticate:", k->p) &&
+ (401 == k->httpcode)) ||
+ (checkprefix("Proxy-authenticate:", k->p) &&
+ (407 == k->httpcode))) {
+ result = Curl_http_input_auth(conn, k->httpcode, k->p);
+ if(result)
+ return result;
+ }
+ else if ((k->httpcode >= 300 && k->httpcode < 400) &&
+ checkprefix("Location:", k->p)) {
+ if(data->set.http_follow_location) {
+ /* this is the URL that the server advices us to get instead */
+ char *ptr;
+ char *start=k->p;
+ char backup;
+
+ start += 9; /* pass "Location:" */
+
+ /* Skip spaces and tabs. We do this to support multiple
+ white spaces after the "Location:" keyword. */
+ while(*start && ISSPACE(*start ))
+ start++;
+
+ /* Scan through the string from the end to find the last
+ non-space. k->end_ptr points to the actual terminating zero
+ letter, move pointer one letter back and start from
+ there. This logic strips off trailing whitespace, but keeps
+ any embedded whitespace. */
+ ptr = k->end_ptr-1;
+ while((ptr>=start) && ISSPACE(*ptr))
+ ptr--;
+ ptr++;
+
+ backup = *ptr; /* store the ending letter */
+ if(ptr != start) {
+ *ptr = '\0'; /* zero terminate */
+ data->reqdata.newurl = strdup(start); /* clone string */
+ *ptr = backup; /* restore ending letter */
+ if(!data->reqdata.newurl)
+ return CURLE_OUT_OF_MEMORY;
+ }
+ }
+ }
+#endif /* CURL_DISABLE_HTTP */
+
+ /*
+ * End of header-checks. Write them to the client.
+ */
+
+ writetype = CLIENTWRITE_HEADER;
+ if (data->set.include_header)
+ writetype |= CLIENTWRITE_BODY;
+
+ if(data->set.verbose)
+ Curl_debug(data, CURLINFO_HEADER_IN,
+ k->p, (size_t)k->hbuflen, conn);
+
+ result = Curl_client_write(conn, writetype, k->p, k->hbuflen);
+ if(result)
+ return result;
+
+ data->info.header_size += (long)k->hbuflen;
+ conn->headerbytecount += (long)k->hbuflen;
+
+ /* reset hbufp pointer && hbuflen */
+ k->hbufp = data->state.headerbuff;
+ k->hbuflen = 0;
+ }
+ while (!stop_reading && *k->str); /* header line within buffer */
+
+ if(stop_reading)
+ /* We've stopped dealing with input, get out of the do-while loop */
+ break;
+
+ /* We might have reached the end of the header part here, but
+ there might be a non-header part left in the end of the read
+ buffer. */
+
+ } /* end if header mode */
+
+ /* This is not an 'else if' since it may be a rest from the header
+ parsing, where the beginning of the buffer is headers and the end
+ is non-headers. */
+ if (k->str && !k->header && (nread > 0 || is_empty_data)) {
+
+ if(0 == k->bodywrites && !is_empty_data) {
+ /* These checks are only made the first time we are about to
+ write a piece of the body */
+ if(conn->protocol&PROT_HTTP) {
+ /* HTTP-only checks */
+
+ if (data->reqdata.newurl) {
+ if(conn->bits.close) {
+ /* Abort after the headers if "follow Location" is set
+ and we're set to close anyway. */
+ k->keepon &= ~KEEP_READ;
+ *done = TRUE;
+ return CURLE_OK;
+ }
+ /* We have a new url to load, but since we want to be able
+ to re-use this connection properly, we read the full
+ response in "ignore more" */
+ k->ignorebody = TRUE;
+ infof(data, "Ignoring the response-body\n");
+ }
+ if (data->reqdata.resume_from && !k->content_range &&
+ (data->set.httpreq==HTTPREQ_GET) &&
+ !k->ignorebody) {
+ /* we wanted to resume a download, although the server doesn't
+ * seem to support this and we did this with a GET (if it
+ * wasn't a GET we did a POST or PUT resume) */
+ failf(data, "HTTP server doesn't seem to support "
+ "byte ranges. Cannot resume.");
+ return CURLE_HTTP_RANGE_ERROR;
+ }
+
+ if(data->set.timecondition && !data->reqdata.range) {
+ /* A time condition has been set AND no ranges have been
+ requested. This seems to be what chapter 13.3.4 of
+ RFC 2616 defines to be the correct action for a
+ HTTP/1.1 client */
+ if((k->timeofdoc > 0) && (data->set.timevalue > 0)) {
+ switch(data->set.timecondition) {
+ case CURL_TIMECOND_IFMODSINCE:
+ default:
+ if(k->timeofdoc < data->set.timevalue) {
+ infof(data,
+ "The requested document is not new enough\n");
+ *done = TRUE;
+ return CURLE_OK;
+ }
+ break;
+ case CURL_TIMECOND_IFUNMODSINCE:
+ if(k->timeofdoc > data->set.timevalue) {
+ infof(data,
+ "The requested document is not old enough\n");
+ *done = TRUE;
+ return CURLE_OK;
+ }
+ break;
+ } /* switch */
+ } /* two valid time strings */
+ } /* we have a time condition */
+
+ } /* this is HTTP */
+ } /* this is the first time we write a body part */
+ k->bodywrites++;
+
+ /* pass data to the debug function before it gets "dechunked" */
+ if(data->set.verbose) {
+ if(k->badheader) {
+ Curl_debug(data, CURLINFO_DATA_IN, data->state.headerbuff,
+ (size_t)k->hbuflen, conn);
+ if(k->badheader == HEADER_PARTHEADER)
+ Curl_debug(data, CURLINFO_DATA_IN,
+ k->str, (size_t)nread, conn);
+ }
+ else
+ Curl_debug(data, CURLINFO_DATA_IN,
+ k->str, (size_t)nread, conn);
+ }
+
+#ifndef CURL_DISABLE_HTTP
+ if(conn->bits.chunk) {
+ /*
+ * Bless me father for I have sinned. Here comes a chunked
+ * transfer flying and we need to decode this properly. While
+ * the name says read, this function both reads and writes away
+ * the data. The returned 'nread' holds the number of actual
+ * data it wrote to the client. */
+
+ CHUNKcode res =
+ Curl_httpchunk_read(conn, k->str, nread, &nread);
+
+ if(CHUNKE_OK < res) {
+ if(CHUNKE_WRITE_ERROR == res) {
+ failf(data, "Failed writing data");
+ return CURLE_WRITE_ERROR;
+ }
+ failf(data, "Received problem %d in the chunky parser", res);
+ return CURLE_RECV_ERROR;
+ }
+ else if(CHUNKE_STOP == res) {
+ /* we're done reading chunks! */
+ k->keepon &= ~KEEP_READ; /* read no more */
+
+ /* There are now possibly N number of bytes at the end of the
+ str buffer that weren't written to the client, but we don't
+ care about them right now. */
+ }
+ /* If it returned OK, we just keep going */
+ }
+#endif /* CURL_DISABLE_HTTP */
+
+ if((-1 != k->maxdownload) &&
+ (k->bytecount + nread >= k->maxdownload)) {
+ /* The 'excess' amount below can't be more than BUFSIZE which
+ always will fit in a size_t */
+ size_t excess = (size_t)(k->bytecount + nread - k->maxdownload);
+ if (excess > 0 && !k->ignorebody) {
+ infof(data,
+ "Rewinding stream by : %d"
+ " bytes on url %s (size = %" FORMAT_OFF_T
+ ", maxdownload = %" FORMAT_OFF_T
+ ", bytecount = %" FORMAT_OFF_T ", nread = %d)\n",
+ excess, conn->data->reqdata.path,
+ k->size, k->maxdownload, k->bytecount, nread);
+ read_rewind(conn, excess);
+ }
+
+ nread = (ssize_t) (k->maxdownload - k->bytecount);
+ if(nread < 0 ) /* this should be unusual */
+ nread = 0;
+
+ k->keepon &= ~KEEP_READ; /* we're done reading */
+ }
+
+ k->bytecount += nread;
+
+ Curl_pgrsSetDownloadCounter(data, k->bytecount);
+
+ if(!conn->bits.chunk && (nread || k->badheader || is_empty_data)) {
+ /* If this is chunky transfer, it was already written */
+
+ if(k->badheader && !k->ignorebody) {
+ /* we parsed a piece of data wrongly assuming it was a header
+ and now we output it as body instead */
+ result = Curl_client_write(conn, CLIENTWRITE_BODY,
+ data->state.headerbuff,
+ k->hbuflen);
+ if(result)
+ return result;
+ }
+ if(k->badheader < HEADER_ALLBAD) {
+ /* This switch handles various content encodings. If there's an
+ error here, be sure to check over the almost identical code
+ in http_chunks.c.
+ Make sure that ALL_CONTENT_ENCODINGS contains all the
+ encodings handled here. */
+#ifdef HAVE_LIBZ
+ switch (k->content_encoding) {
+ case IDENTITY:
+#endif
+ /* This is the default when the server sends no
+ Content-Encoding header. See Curl_readwrite_init; the
+ memset() call initializes k->content_encoding to zero. */
+ if(!k->ignorebody)
+ result = Curl_client_write(conn, CLIENTWRITE_BODY, k->str,
+ nread);
+#ifdef HAVE_LIBZ
+ break;
+
+ case DEFLATE:
+ /* Assume CLIENTWRITE_BODY; headers are not encoded. */
+ if(!k->ignorebody)
+ result = Curl_unencode_deflate_write(conn, k, nread);
+ break;
+
+ case GZIP:
+ /* Assume CLIENTWRITE_BODY; headers are not encoded. */
+ if(!k->ignorebody)
+ result = Curl_unencode_gzip_write(conn, k, nread);
+ break;
+
+ case COMPRESS:
+ default:
+ failf (data, "Unrecognized content encoding type. "
+ "libcurl understands `identity', `deflate' and `gzip' "
+ "content encodings.");
+ result = CURLE_BAD_CONTENT_ENCODING;
+ break;
+ }
+#endif
+ }
+ k->badheader = HEADER_NORMAL; /* taken care of now */
+
+ if(result)
+ return result;
+ }
+
+ } /* if (! header and data to read ) */
+
+ if (is_empty_data) {
+ /* if we received nothing, the server closed the connection and we
+ are done */
+ k->keepon &= ~KEEP_READ;
+ }
+
+ } while(data_pending(conn));
+
+ } /* if( read from socket ) */
+
+ /* If we still have writing to do, we check if we have a writable
+ socket. */
+ if((k->keepon & KEEP_WRITE) && (select_res & CSELECT_OUT)) {
+ /* write */
+
+ int i, si;
+ ssize_t bytes_written;
+ bool writedone=TRUE;
+
+ if ((k->bytecount == 0) && (k->writebytecount == 0))
+ Curl_pgrsTime(data, TIMER_STARTTRANSFER);
+
+ didwhat |= KEEP_WRITE;
+
+ /*
+ * We loop here to do the READ and SEND loop until we run out of
+ * data to send or until we get EWOULDBLOCK back
+ */
+ do {
+
+ /* only read more data if there's no upload data already
+ present in the upload buffer */
+ if(0 == data->reqdata.upload_present) {
+ /* init the "upload from here" pointer */
+ data->reqdata.upload_fromhere = k->uploadbuf;
+
+ if(!k->upload_done) {
+ /* HTTP pollution, this should be written nicer to become more
+ protocol agnostic. */
+ int fillcount;
+
+ if(k->wait100_after_headers &&
+ (data->reqdata.proto.http->sending == HTTPSEND_BODY)) {
+ /* If this call is to send body data, we must take some action:
+ We have sent off the full HTTP 1.1 request, and we shall now
+ go into the Expect: 100 state and await such a header */
+ k->wait100_after_headers = FALSE; /* headers sent */
+ k->write_after_100_header = TRUE; /* wait for the header */
+ k->keepon &= ~KEEP_WRITE; /* disable writing */
+ k->start100 = Curl_tvnow(); /* timeout count starts now */
+ didwhat &= ~KEEP_WRITE; /* we didn't write anything actually */
+ break;
+ }
+
+ result = Curl_fillreadbuffer(conn, BUFSIZE, &fillcount);
+ if(result)
+ return result;
+
+ nread = (ssize_t)fillcount;
+ }
+ else
+ nread = 0; /* we're done uploading/reading */
+
+ /* the signed int typecase of nread of for systems that has
+ unsigned size_t */
+ if (nread<=0) {
+ /* done */
+ k->keepon &= ~KEEP_WRITE; /* we're done writing */
+ writedone = TRUE;
+
+ if(conn->bits.rewindaftersend) {
+ result = Curl_readrewind(conn);
+ if(result)
+ return result;
+ }
+ break;
+ }
+
+ /* store number of bytes available for upload */
+ data->reqdata.upload_present = nread;
+
+ /* convert LF to CRLF if so asked */
+#ifdef CURL_DO_LINEEND_CONV
+ /* always convert if we're FTPing in ASCII mode */
+ if ((data->set.crlf) || (data->set.prefer_ascii)) {
+#else
+ if (data->set.crlf) {
+#endif /* CURL_DO_LINEEND_CONV */
+ if(data->state.scratch == NULL)
+ data->state.scratch = malloc(2*BUFSIZE);
+ if(data->state.scratch == NULL) {
+ failf (data, "Failed to alloc scratch buffer!");
+ return CURLE_OUT_OF_MEMORY;
+ }
+ /*
+ * ASCII/EBCDIC Note: This is presumably a text (not binary)
+ * transfer so the data should already be in ASCII.
+ * That means the hex values for ASCII CR (0x0d) & LF (0x0a)
+ * must be used instead of the escape sequences \r & \n.
+ */
+ for(i = 0, si = 0; i < nread; i++, si++) {
+ if (data->reqdata.upload_fromhere[i] == 0x0a) {
+ data->state.scratch[si++] = 0x0d;
+ data->state.scratch[si] = 0x0a;
+ if (!data->set.crlf) {
+ /* we're here only because FTP is in ASCII mode...
+ bump infilesize for the LF we just added */
+ data->set.infilesize++;
+ }
+ }
+ else
+ data->state.scratch[si] = data->reqdata.upload_fromhere[i];
+ }
+ if(si != nread) {
+ /* only perform the special operation if we really did replace
+ anything */
+ nread = si;
+
+ /* upload from the new (replaced) buffer instead */
+ data->reqdata.upload_fromhere = data->state.scratch;
+
+ /* set the new amount too */
+ data->reqdata.upload_present = nread;
+ }
+ }
+ }
+ else {
+ /* We have a partial buffer left from a previous "round". Use
+ that instead of reading more data */
+ }
+
+ /* write to socket (send away data) */
+ result = Curl_write(conn,
+ conn->writesockfd, /* socket to send to */
+ data->reqdata.upload_fromhere, /* buffer pointer */
+ data->reqdata.upload_present, /* buffer size */
+ &bytes_written); /* actually send away */
+ if(result)
+ return result;
+
+ if(data->set.verbose)
+ /* show the data before we change the pointer upload_fromhere */
+ Curl_debug(data, CURLINFO_DATA_OUT, data->reqdata.upload_fromhere,
+ (size_t)bytes_written, conn);
+
+ if(data->reqdata.upload_present != bytes_written) {
+ /* we only wrote a part of the buffer (if anything), deal with it! */
+
+ /* store the amount of bytes left in the buffer to write */
+ data->reqdata.upload_present -= bytes_written;
+
+ /* advance the pointer where to find the buffer when the next send
+ is to happen */
+ data->reqdata.upload_fromhere += bytes_written;
+
+ writedone = TRUE; /* we are done, stop the loop */
+ }
+ else {
+ /* we've uploaded that buffer now */
+ data->reqdata.upload_fromhere = k->uploadbuf;
+ data->reqdata.upload_present = 0; /* no more bytes left */
+
+ if(k->upload_done) {
+ /* switch off writing, we're done! */
+ k->keepon &= ~KEEP_WRITE; /* we're done writing */
+ writedone = TRUE;
+ }
+ }
+
+ k->writebytecount += bytes_written;
+ Curl_pgrsSetUploadCounter(data, k->writebytecount);
+
+ } while(!writedone); /* loop until we're done writing! */
+
+ }
+
+ } while(0); /* just to break out from! */
+
+ k->now = Curl_tvnow();
+ if(didwhat) {
+ /* Update read/write counters */
+ if(k->bytecountp)
+ *k->bytecountp = k->bytecount; /* read count */
+ if(k->writebytecountp)
+ *k->writebytecountp = k->writebytecount; /* write count */
+ }
+ else {
+ /* no read no write, this is a timeout? */
+ if (k->write_after_100_header) {
+ /* This should allow some time for the header to arrive, but only a
+ very short time as otherwise it'll be too much wasted times too
+ often. */
+
+ /* Quoting RFC2616, section "8.2.3 Use of the 100 (Continue) Status":
+
+ Therefore, when a client sends this header field to an origin server
+ (possibly via a proxy) from which it has never seen a 100 (Continue)
+ status, the client SHOULD NOT wait for an indefinite period before
+ sending the request body.
+
+ */
+
+ long ms = Curl_tvdiff(k->now, k->start100);
+ if(ms > CURL_TIMEOUT_EXPECT_100) {
+ /* we've waited long enough, continue anyway */
+ k->write_after_100_header = FALSE;
+ k->keepon |= KEEP_WRITE;
+ }
+ }
+ }
+
+ if(Curl_pgrsUpdate(conn))
+ result = CURLE_ABORTED_BY_CALLBACK;
+ else
+ result = Curl_speedcheck(data, k->now);
+ if (result)
+ return result;
+
+ if (data->set.timeout &&
+ ((Curl_tvdiff(k->now, k->start)/1000) >= data->set.timeout)) {
+ if (k->size != -1) {
+ failf(data, "Operation timed out after %d seconds with %"
+ FORMAT_OFF_T " out of %" FORMAT_OFF_T " bytes received",
+ data->set.timeout, k->bytecount, k->size);
+ } else {
+ failf(data, "Operation timed out after %d seconds with %"
+ FORMAT_OFF_T " bytes received",
+ data->set.timeout, k->bytecount);
+ }
+ return CURLE_OPERATION_TIMEOUTED;
+ }
+
+ if(!k->keepon) {
+ /*
+ * The transfer has been performed. Just make some general checks before
+ * returning.
+ */
+
+ if(!(conn->bits.no_body) && (k->size != -1) &&
+ (k->bytecount != k->size) &&
+#ifdef CURL_DO_LINEEND_CONV
+ /* Most FTP servers don't adjust their file SIZE response for CRLFs,
+ so we'll check to see if the discrepancy can be explained
+ by the number of CRLFs we've changed to LFs.
+ */
+ (k->bytecount != (k->size + data->state.crlf_conversions)) &&
+#endif /* CURL_DO_LINEEND_CONV */
+ !data->reqdata.newurl) {
+ failf(data, "transfer closed with %" FORMAT_OFF_T
+ " bytes remaining to read",
+ k->size - k->bytecount);
+ return CURLE_PARTIAL_FILE;
+ }
+ else if(!(conn->bits.no_body) &&
+ conn->bits.chunk &&
+ (data->reqdata.proto.http->chunk.state != CHUNK_STOP)) {
+ /*
+ * In chunked mode, return an error if the connection is closed prior to
+ * the empty (terminiating) chunk is read.
+ *
+ * The condition above used to check for
+ * conn->proto.http->chunk.datasize != 0 which is true after reading
+ * *any* chunk, not just the empty chunk.
+ *
+ */
+ failf(data, "transfer closed with outstanding read data remaining");
+ return CURLE_PARTIAL_FILE;
+ }
+ if(Curl_pgrsUpdate(conn))
+ return CURLE_ABORTED_BY_CALLBACK;
+ }
+
+ /* Now update the "done" boolean we return */
+ *done = (bool)(0 == (k->keepon&(KEEP_READ|KEEP_WRITE)));
+
+ return CURLE_OK;
+}
+
+
+/*
+ * Curl_readwrite_init() inits the readwrite session. This is inited each time for a
+ * transfer, sometimes multiple times on the same SessionHandle
+ */
+
+CURLcode Curl_readwrite_init(struct connectdata *conn)
+{
+ struct SessionHandle *data = conn->data;
+ struct Curl_transfer_keeper *k = &data->reqdata.keep;
+
+ /* NB: the content encoding software depends on this initialization of
+ Curl_transfer_keeper.*/
+ memset(k, 0, sizeof(struct Curl_transfer_keeper));
+
+ k->start = Curl_tvnow(); /* start time */
+ k->now = k->start; /* current time is now */
+ k->header = TRUE; /* assume header */
+ k->httpversion = -1; /* unknown at this point */
+
+ k->size = data->reqdata.size;
+ k->maxdownload = data->reqdata.maxdownload;
+ k->bytecountp = data->reqdata.bytecountp;
+ k->writebytecountp = data->reqdata.writebytecountp;
+
+ k->bytecount = 0;
+
+ k->buf = data->state.buffer;
+ k->uploadbuf = data->state.uploadbuffer;
+ k->maxfd = (conn->sockfd>conn->writesockfd?
+ conn->sockfd:conn->writesockfd)+1;
+ k->hbufp = data->state.headerbuff;
+ k->ignorebody=FALSE;
+
+ Curl_pgrsTime(data, TIMER_PRETRANSFER);
+ Curl_speedinit(data);
+
+ Curl_pgrsSetUploadCounter(data, 0);
+ Curl_pgrsSetDownloadCounter(data, 0);
+
+ if (!conn->bits.getheader) {
+ k->header = FALSE;
+ if(k->size > 0)
+ Curl_pgrsSetDownloadSize(data, k->size);
+ }
+ /* we want header and/or body, if neither then don't do this! */
+ if(conn->bits.getheader || !conn->bits.no_body) {
+
+ if(conn->sockfd != CURL_SOCKET_BAD) {
+ k->keepon |= KEEP_READ;
+ }
+
+ if(conn->writesockfd != CURL_SOCKET_BAD) {
+ /* HTTP 1.1 magic:
+
+ Even if we require a 100-return code before uploading data, we might
+ need to write data before that since the REQUEST may not have been
+ finished sent off just yet.
+
+ Thus, we must check if the request has been sent before we set the
+ state info where we wait for the 100-return code
+ */
+ if (data->state.expect100header &&
+ (data->reqdata.proto.http->sending == HTTPSEND_BODY)) {
+ /* wait with write until we either got 100-continue or a timeout */
+ k->write_after_100_header = TRUE;
+ k->start100 = k->start;
+ }
+ else {
+ if(data->state.expect100header)
+ /* when we've sent off the rest of the headers, we must await a
+ 100-continue */
+ k->wait100_after_headers = TRUE;
+ k->keepon |= KEEP_WRITE;
+ }
+ }
+ }
+
+ return CURLE_OK;
+}
+
+/*
+ * Curl_single_getsock() gets called by the multi interface code when the app
+ * has requested to get the sockets for the current connection. This function
+ * will then be called once for every connection that the multi interface
+ * keeps track of. This function will only be called for connections that are
+ * in the proper state to have this information available.
+ */
+int Curl_single_getsock(struct connectdata *conn,
+ curl_socket_t *sock, /* points to numsocks number
+ of sockets */
+ int numsocks)
+{
+ struct SessionHandle *data = conn->data;
+ int bitmap = GETSOCK_BLANK;
+ int index = 0;
+
+ if(numsocks < 2)
+ /* simple check but we might need two slots */
+ return GETSOCK_BLANK;
+
+ if(data->reqdata.keep.keepon & KEEP_READ) {
+ bitmap |= GETSOCK_READSOCK(index);
+ sock[index] = conn->sockfd;
+ }
+
+ if(data->reqdata.keep.keepon & KEEP_WRITE) {
+
+ if((conn->sockfd != conn->writesockfd) ||
+ !(data->reqdata.keep.keepon & KEEP_READ)) {
+ /* only if they are not the same socket or we didn't have a readable
+ one, we increase index */
+ if(data->reqdata.keep.keepon & KEEP_READ)
+ index++; /* increase index if we need two entries */
+ sock[index] = conn->writesockfd;
+ }
+
+ bitmap |= GETSOCK_WRITESOCK(index);
+ }
+
+ return bitmap;
+}
+
+
+/*
+ * Transfer()
+ *
+ * This function is what performs the actual transfer. It is capable of
+ * doing both ways simultaneously.
+ * The transfer must already have been setup by a call to Curl_setup_transfer().
+ *
+ * Note that headers are created in a preallocated buffer of a default size.
+ * That buffer can be enlarged on demand, but it is never shrunken again.
+ *
+ * Parts of this function was once written by the friendly Mark Butler
+ * <butlerm@xmission.com>.
+ */
+
+static CURLcode
+Transfer(struct connectdata *conn)
+{
+ CURLcode result;
+ struct SessionHandle *data = conn->data;
+ struct Curl_transfer_keeper *k = &data->reqdata.keep;
+ bool done=FALSE;
+
+ if(!(conn->protocol & PROT_FILE))
+ /* Only do this if we are not transferring FILE:, since the file: treatment
+ is different*/
+ Curl_readwrite_init(conn);
+
+ if((conn->sockfd == CURL_SOCKET_BAD) &&
+ (conn->writesockfd == CURL_SOCKET_BAD))
+ /* nothing to read, nothing to write, we're already OK! */
+ return CURLE_OK;
+
+ /* we want header and/or body, if neither then don't do this! */
+ if(!conn->bits.getheader && conn->bits.no_body)
+ return CURLE_OK;
+
+ while (!done) {
+ curl_socket_t fd_read;
+ curl_socket_t fd_write;
+
+ /* limit-rate logic: if speed exceeds threshold, then do not include fd in
+ select set. The current speed is recalculated in each Curl_readwrite()
+ call */
+ if ((k->keepon & KEEP_WRITE) &&
+ (!data->set.max_send_speed ||
+ (data->progress.ulspeed < data->set.max_send_speed) )) {
+ fd_write = conn->writesockfd;
+ k->keepon &= ~KEEP_WRITE_HOLD;
+ }
+ else {
+ fd_write = CURL_SOCKET_BAD;
+ if(k->keepon & KEEP_WRITE)
+ k->keepon |= KEEP_WRITE_HOLD; /* hold it */
+ }
+
+ if ((k->keepon & KEEP_READ) &&
+ (!data->set.max_recv_speed ||
+ (data->progress.dlspeed < data->set.max_recv_speed)) ) {
+ fd_read = conn->sockfd;
+ k->keepon &= ~KEEP_READ_HOLD;
+ }
+ else {
+ fd_read = CURL_SOCKET_BAD;
+ if(k->keepon & KEEP_READ)
+ k->keepon |= KEEP_READ_HOLD; /* hold it */
+ }
+
+ /* The *_HOLD logic is necessary since even though there might be no
+ traffic during the select interval, we still call Curl_readwrite() for
+ the timeout case and if we limit transfer speed we must make sure that
+ this function doesn't transfer anything while in HOLD status. */
+
+ switch (Curl_select(fd_read, fd_write, 1000)) {
+ case -1: /* select() error, stop reading */
+#ifdef EINTR
+ /* The EINTR is not serious, and it seems you might get this more
+ ofen when using the lib in a multi-threaded environment! */
+ if(errno == EINTR)
+ ;
+ else
+#endif
+ done = TRUE; /* no more read or write */
+ continue;
+ case 0: /* timeout */
+ default: /* readable descriptors */
+
+ result = Curl_readwrite(conn, &done);
+ break;
+ }
+ if(result)
+ return result;
+
+ /* "done" signals to us if the transfer(s) are ready */
+ }
+
+ return CURLE_OK;
+}
+
+/*
+ * Curl_pretransfer() is called immediately before a transfer starts.
+ */
+CURLcode Curl_pretransfer(struct SessionHandle *data)
+{
+ CURLcode res;
+ if(!data->change.url) {
+ /* we can't do anything wihout URL */
+ failf(data, "No URL set!\n");
+ return CURLE_URL_MALFORMAT;
+ }
+
+ /* Init the SSL session ID cache here. We do it here since we want to do it
+ after the *_setopt() calls (that could change the size of the cache) but
+ before any transfer takes place. */
+ res = Curl_ssl_initsessions(data, data->set.ssl.numsessions);
+ if(res)
+ return res;
+
+ data->set.followlocation=0; /* reset the location-follow counter */
+ data->state.this_is_a_follow = FALSE; /* reset this */
+ data->state.errorbuf = FALSE; /* no error has occurred */
+
+ data->state.authproblem = FALSE;
+ data->state.authhost.want = data->set.httpauth;
+ data->state.authproxy.want = data->set.proxyauth;
+
+ /* If there is a list of cookie files to read, do it now! */
+ if(data->change.cookielist) {
+ Curl_cookie_loadfiles(data);
+ }
+
+ /* Allow data->set.use_port to set which port to use. This needs to be
+ * disabled for example when we follow Location: headers to URLs using
+ * different ports! */
+ data->state.allow_port = TRUE;
+
+#if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(HAVE_MSG_NOSIGNAL)
+ /*************************************************************
+ * Tell signal handler to ignore SIGPIPE
+ *************************************************************/
+ if(!data->set.no_signal)
+ data->state.prev_signal = signal(SIGPIPE, SIG_IGN);
+#endif
+
+ Curl_initinfo(data); /* reset session-specific information "variables" */
+ Curl_pgrsStartNow(data);
+
+ return CURLE_OK;
+}
+
+/*
+ * Curl_posttransfer() is called immediately after a transfer ends
+ */
+CURLcode Curl_posttransfer(struct SessionHandle *data)
+{
+#if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(HAVE_MSG_NOSIGNAL)
+ /* restore the signal handler for SIGPIPE before we get back */
+ if(!data->set.no_signal)
+ signal(SIGPIPE, data->state.prev_signal);
+#else
+ (void)data; /* unused parameter */
+#endif
+
+ if(!(data->progress.flags & PGRS_HIDE) &&
+ !data->progress.callback)
+ /* only output if we don't use a progress callback and we're not hidden */
+ fprintf(data->set.err, "\n");
+
+ return CURLE_OK;
+}
+
+/*
+ * strlen_url() returns the length of the given URL if the spaces within the
+ * URL were properly URL encoded.
+ */
+static int strlen_url(char *url)
+{
+ char *ptr;
+ int newlen=0;
+ bool left=TRUE; /* left side of the ? */
+
+ for(ptr=url; *ptr; ptr++) {
+ switch(*ptr) {
+ case '?':
+ left=FALSE;
+ default:
+ newlen++;
+ break;
+ case ' ':
+ if(left)
+ newlen+=3;
+ else
+ newlen++;
+ break;
+ }
+ }
+ return newlen;
+}
+
+/* strcpy_url() copies a url to a output buffer and URL-encodes the spaces in
+ * the source URL accordingly.
+ */
+static void strcpy_url(char *output, char *url)
+{
+ /* we must add this with whitespace-replacing */
+ bool left=TRUE;
+ char *iptr;
+ char *optr = output;
+ for(iptr = url; /* read from here */
+ *iptr; /* until zero byte */
+ iptr++) {
+ switch(*iptr) {
+ case '?':
+ left=FALSE;
+ default:
+ *optr++=*iptr;
+ break;
+ case ' ':
+ if(left) {
+ *optr++='%'; /* add a '%' */
+ *optr++='2'; /* add a '2' */
+ *optr++='0'; /* add a '0' */
+ }
+ else
+ *optr++='+'; /* add a '+' here */
+ break;
+ }
+ }
+ *optr=0; /* zero terminate output buffer */
+
+}
+
+/*
+ * Curl_follow() handles the URL redirect magic. Pass in the 'newurl' string
+ * as given by the remote server and set up the new URL to request.
+ */
+CURLcode Curl_follow(struct SessionHandle *data,
+ char *newurl, /* this 'newurl' is the Location: string,
+ and it must be malloc()ed before passed
+ here */
+ bool retry) /* set TRUE if this is a request retry as
+ opposed to a real redirect following */
+{
+ /* Location: redirect */
+ char prot[16]; /* URL protocol string storage */
+ char letter; /* used for a silly sscanf */
+ size_t newlen;
+ char *newest;
+
+ if(!retry) {
+ if ((data->set.maxredirs != -1) &&
+ (data->set.followlocation >= data->set.maxredirs)) {
+ failf(data,"Maximum (%d) redirects followed", data->set.maxredirs);
+ return CURLE_TOO_MANY_REDIRECTS;
+ }
+
+ /* mark the next request as a followed location: */
+ data->state.this_is_a_follow = TRUE;
+
+ data->set.followlocation++; /* count location-followers */
+ }
+
+ if(data->set.http_auto_referer) {
+ /* We are asked to automatically set the previous URL as the
+ referer when we get the next URL. We pick the ->url field,
+ which may or may not be 100% correct */
+
+ if(data->change.referer_alloc)
+ /* If we already have an allocated referer, free this first */
+ free(data->change.referer);
+
+ data->change.referer = strdup(data->change.url);
+ data->change.referer_alloc = TRUE; /* yes, free this later */
+ }
+
+ if(2 != sscanf(newurl, "%15[^?&/:]://%c", prot, &letter)) {
+ /***
+ *DANG* this is an RFC 2068 violation. The URL is supposed
+ to be absolute and this doesn't seem to be that!
+ ***
+ Instead, we have to TRY to append this new path to the old URL
+ to the right of the host part. Oh crap, this is doomed to cause
+ problems in the future...
+ */
+ char *protsep;
+ char *pathsep;
+
+ char *useurl = newurl;
+ size_t urllen;
+
+ /* we must make our own copy of the URL to play with, as it may
+ point to read-only data */
+ char *url_clone=strdup(data->change.url);
+
+ if(!url_clone)
+ return CURLE_OUT_OF_MEMORY; /* skip out of this NOW */
+
+ /* protsep points to the start of the host name */
+ protsep=strstr(url_clone, "//");
+ if(!protsep)
+ protsep=url_clone;
+ else
+ protsep+=2; /* pass the slashes */
+
+ if('/' != newurl[0]) {
+ int level=0;
+
+ /* First we need to find out if there's a ?-letter in the URL,
+ and cut it and the right-side of that off */
+ pathsep = strchr(protsep, '?');
+ if(pathsep)
+ *pathsep=0;
+
+ /* we have a relative path to append to the last slash if
+ there's one available */
+ pathsep = strrchr(protsep, '/');
+ if(pathsep)
+ *pathsep=0;
+
+ /* Check if there's any slash after the host name, and if so,
+ remember that position instead */
+ pathsep = strchr(protsep, '/');
+ if(pathsep)
+ protsep = pathsep+1;
+ else
+ protsep = NULL;
+
+ /* now deal with one "./" or any amount of "../" in the newurl
+ and act accordingly */
+
+ if((useurl[0] == '.') && (useurl[1] == '/'))
+ useurl+=2; /* just skip the "./" */
+
+ while((useurl[0] == '.') &&
+ (useurl[1] == '.') &&
+ (useurl[2] == '/')) {
+ level++;
+ useurl+=3; /* pass the "../" */
+ }
+
+ if(protsep) {
+ while(level--) {
+ /* cut off one more level from the right of the original URL */
+ pathsep = strrchr(protsep, '/');
+ if(pathsep)
+ *pathsep=0;
+ else {
+ *protsep=0;
+ break;
+ }
+ }
+ }
+ }
+ else {
+ /* We got a new absolute path for this server, cut off from the
+ first slash */
+ pathsep = strchr(protsep, '/');
+ if(pathsep) {
+ /* When people use badly formatted URLs, such as
+ "http://www.url.com?dir=/home/daniel" we must not use the first
+ slash, if there's a ?-letter before it! */
+ char *sep = strchr(protsep, '?');
+ if(sep && (sep < pathsep))
+ pathsep = sep;
+ *pathsep=0;
+ }
+ else {
+ /* There was no slash. Now, since we might be operating on a badly
+ formatted URL, such as "http://www.url.com?id=2380" which doesn't
+ use a slash separator as it is supposed to, we need to check for a
+ ?-letter as well! */
+ pathsep = strchr(protsep, '?');
+ if(pathsep)
+ *pathsep=0;
+ }
+ }
+
+ /* If the new part contains a space, this is a mighty stupid redirect
+ but we still make an effort to do "right". To the left of a '?'
+ letter we replace each space with %20 while it is replaced with '+'
+ on the right side of the '?' letter.
+ */
+ newlen = strlen_url(useurl);
+
+ urllen = strlen(url_clone);
+
+ newest=(char *)malloc( urllen + 1 + /* possible slash */
+ newlen + 1 /* zero byte */);
+
+ if(!newest) {
+ free(url_clone); /* don't leak this */
+ return CURLE_OUT_OF_MEMORY; /* go out from this */
+ }
+
+ /* copy over the root url part */
+ memcpy(newest, url_clone, urllen);
+
+ /* check if we need to append a slash */
+ if(('/' == useurl[0]) || (protsep && !*protsep))
+ ;
+ else
+ newest[urllen++]='/';
+
+ /* then append the new piece on the right side */
+ strcpy_url(&newest[urllen], useurl);
+
+ free(newurl); /* newurl is the allocated pointer */
+ free(url_clone);
+ newurl = newest;
+ }
+ else {
+ /* This is an absolute URL, don't allow the custom port number */
+ data->state.allow_port = FALSE;
+
+ if(strchr(newurl, ' ')) {
+ /* This new URL contains at least one space, this is a mighty stupid
+ redirect but we still make an effort to do "right". */
+ newlen = strlen_url(newurl);
+
+ newest = malloc(newlen+1); /* get memory for this */
+ if(newest) {
+ strcpy_url(newest, newurl); /* create a space-free URL */
+
+ free(newurl); /* that was no good */
+ newurl = newest; /* use this instead now */
+ }
+ }
+
+ }
+
+ if(data->change.url_alloc)
+ free(data->change.url);
+ else
+ data->change.url_alloc = TRUE; /* the URL is allocated */
+
+ data->change.url = newurl;
+ newurl = NULL; /* don't free! */
+
+ infof(data, "Issue another request to this URL: '%s'\n", data->change.url);
+
+ /*
+ * We get here when the HTTP code is 300-399 (and 401). We need to perform
+ * differently based on exactly what return code there was.
+ *
+ * News from 7.10.6: we can also get here on a 401 or 407, in case we act on
+ * a HTTP (proxy-) authentication scheme other than Basic.
+ */
+ switch(data->info.httpcode) {
+ /* 401 - Act on a www-authentication, we keep on moving and do the
+ Authorization: XXXX header in the HTTP request code snippet */
+ /* 407 - Act on a proxy-authentication, we keep on moving and do the
+ Proxy-Authorization: XXXX header in the HTTP request code snippet */
+ /* 300 - Multiple Choices */
+ /* 306 - Not used */
+ /* 307 - Temporary Redirect */
+ default: /* for all above (and the unknown ones) */
+ /* Some codes are explicitly mentioned since I've checked RFC2616 and they
+ * seem to be OK to POST to.
+ */
+ break;
+ case 301: /* Moved Permanently */
+ /* (quote from RFC2616, section 10.3.2):
+ *
+ * Note: When automatically redirecting a POST request after receiving a
+ * 301 status code, some existing HTTP/1.0 user agents will erroneously
+ * change it into a GET request.
+ *
+ * ----
+ *
+ * Warning: Because most of importants user agents do this obvious RFC2616
+ * violation, many webservers expect this misbehavior. So these servers
+ * often answers to a POST request with an error page. To be sure that
+ * libcurl gets the page that most user agents would get, libcurl has to
+ * force GET:
+ */
+ if( data->set.httpreq == HTTPREQ_POST
+ || data->set.httpreq == HTTPREQ_POST_FORM) {
+ infof(data,
+ "Violate RFC 2616/10.3.2 and switch from POST to GET\n");
+ data->set.httpreq = HTTPREQ_GET;
+ }
+ break;
+ case 302: /* Found */
+ /* (From 10.3.3)
+
+ Note: RFC 1945 and RFC 2068 specify that the client is not allowed
+ to change the method on the redirected request. However, most
+ existing user agent implementations treat 302 as if it were a 303
+ response, performing a GET on the Location field-value regardless
+ of the original request method. The status codes 303 and 307 have
+ been added for servers that wish to make unambiguously clear which
+ kind of reaction is expected of the client.
+
+ (From 10.3.4)
+
+ Note: Many pre-HTTP/1.1 user agents do not understand the 303
+ status. When interoperability with such clients is a concern, the
+ 302 status code may be used instead, since most user agents react
+ to a 302 response as described here for 303.
+ */
+ case 303: /* See Other */
+ /* Disable both types of POSTs, since doing a second POST when
+ * following isn't what anyone would want! */
+ if(data->set.httpreq != HTTPREQ_GET) {
+ data->set.httpreq = HTTPREQ_GET; /* enforce GET request */
+ infof(data, "Disables POST, goes with %s\n",
+ data->set.opt_no_body?"HEAD":"GET");
+ }
+ break;
+ case 304: /* Not Modified */
+ /* 304 means we did a conditional request and it was "Not modified".
+ * We shouldn't get any Location: header in this response!
+ */
+ break;
+ case 305: /* Use Proxy */
+ /* (quote from RFC2616, section 10.3.6):
+ * "The requested resource MUST be accessed through the proxy given
+ * by the Location field. The Location field gives the URI of the
+ * proxy. The recipient is expected to repeat this single request
+ * via the proxy. 305 responses MUST only be generated by origin
+ * servers."
+ */
+ break;
+ }
+ Curl_pgrsTime(data, TIMER_REDIRECT);
+ Curl_pgrsResetTimes(data);
+
+ return CURLE_OK;
+}
+
+static CURLcode
+Curl_connect_host(struct SessionHandle *data,
+ struct connectdata **conn)
+{
+ CURLcode res = CURLE_OK;
+ int urlchanged = FALSE;
+
+ do {
+ bool async;
+ bool protocol_done=TRUE; /* will be TRUE always since this is only used
+ within the easy interface */
+ Curl_pgrsTime(data, TIMER_STARTSINGLE);
+ data->change.url_changed = FALSE;
+ res = Curl_connect(data, conn, &async, &protocol_done);
+
+ if((CURLE_OK == res) && async) {
+ /* Now, if async is TRUE here, we need to wait for the name
+ to resolve */
+ res = Curl_wait_for_resolv(*conn, NULL);
+ if(CURLE_OK == res)
+ /* Resolved, continue with the connection */
+ res = Curl_async_resolved(*conn, &protocol_done);
+ else
+ /* if we can't resolve, we kill this "connection" now */
+ (void)Curl_disconnect(*conn);
+ }
+ if(res)
+ break;
+
+ /* If a callback (or something) has altered the URL we should use within
+ the Curl_connect(), we detect it here and act as if we are redirected
+ to the new URL */
+ urlchanged = data->change.url_changed;
+ if ((CURLE_OK == res) && urlchanged) {
+ res = Curl_done(conn, res, FALSE);
+ if(CURLE_OK == res) {
+ char *gotourl = strdup(data->change.url);
+ res = Curl_follow(data, gotourl, FALSE);
+ if(res)
+ free(gotourl);
+ }
+ }
+ } while (urlchanged && res == CURLE_OK);
+
+ return res;
+}
+
+/* Returns TRUE and sets '*url' if a request retry is wanted */
+bool Curl_retry_request(struct connectdata *conn,
+ char **url)
+{
+ bool retry = FALSE;
+ struct SessionHandle *data = conn->data;
+
+ if((data->reqdata.keep.bytecount+conn->headerbytecount == 0) &&
+ conn->bits.reuse &&
+ !conn->bits.no_body) {
+ /* We got no data, we attempted to re-use a connection and yet we want a
+ "body". This might happen if the connection was left alive when we were
+ done using it before, but that was closed when we wanted to read from
+ it again. Bad luck. Retry the same request on a fresh connect! */
+ infof(conn->data, "Connection died, retrying a fresh connect\n");
+ *url = strdup(conn->data->change.url);
+
+ conn->bits.close = TRUE; /* close this connection */
+ conn->bits.retry = TRUE; /* mark this as a connection we're about
+ to retry. Marking it this way should
+ prevent i.e HTTP transfers to return
+ error just because nothing has been
+ transfered! */
+ retry = TRUE;
+ }
+
+ return retry;
+}
+
+/*
+ * Curl_perform() is the internal high-level function that gets called by the
+ * external curl_easy_perform() function. It inits, performs and cleans up a
+ * single file transfer.
+ */
+CURLcode Curl_perform(struct SessionHandle *data)
+{
+ CURLcode res;
+ CURLcode res2;
+ struct connectdata *conn=NULL;
+ char *newurl = NULL; /* possibly a new URL to follow to! */
+ bool retry = FALSE;
+
+ data->state.used_interface = Curl_if_easy;
+
+ res = Curl_pretransfer(data);
+ if(res)
+ return res;
+
+ /*
+ * It is important that there is NO 'return' from this function at any other
+ * place than falling down to the end of the function! This is because we
+ * have cleanup stuff that must be done before we get back, and that is only
+ * performed after this do-while loop.
+ */
+
+ do {
+ res = Curl_connect_host(data, &conn); /* primary connection */
+
+ if(res == CURLE_OK) {
+ bool do_done;
+ if(data->set.connect_only) {
+ /* keep connection open for application to use the socket */
+ conn->bits.close = FALSE;
+ res = Curl_done(&conn, CURLE_OK, FALSE);
+ break;
+ }
+ res = Curl_do(&conn, &do_done);
+
+ if(res == CURLE_OK) {
+ res = Transfer(conn); /* now fetch that URL please */
+ if(res == CURLE_OK) {
+ retry = Curl_retry_request(conn, &newurl);
+
+ if(!retry)
+ /*
+ * We must duplicate the new URL here as the connection data may
+ * be free()ed in the Curl_done() function.
+ */
+ newurl = data->reqdata.newurl?strdup(data->reqdata.newurl):NULL;
+ }
+ else {
+ /* The transfer phase returned error, we mark the connection to get
+ * closed to prevent being re-used. This is becasue we can't
+ * possibly know if the connection is in a good shape or not now. */
+ conn->bits.close = TRUE;
+
+ if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET]) {
+ /* if we failed anywhere, we must clean up the secondary socket if
+ it was used */
+ sclose(conn->sock[SECONDARYSOCKET]);
+ conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
+ }
+ }
+
+ /* Always run Curl_done(), even if some of the previous calls
+ failed, but return the previous (original) error code */
+ res2 = Curl_done(&conn, res, FALSE);
+
+ if(CURLE_OK == res)
+ res = res2;
+ }
+ else
+ /* Curl_do() failed, clean up left-overs in the done-call */
+ res2 = Curl_done(&conn, res, FALSE);
+
+ /*
+ * Important: 'conn' cannot be used here, since it may have been closed
+ * in 'Curl_done' or other functions.
+ */
+
+ if((res == CURLE_OK) && newurl) {
+ res = Curl_follow(data, newurl, retry);
+ if(CURLE_OK == res) {
+ newurl = NULL;
+ continue;
+ }
+ }
+ }
+ break; /* it only reaches here when this shouldn't loop */
+
+ } while(1); /* loop if Location: */
+
+ if(newurl)
+ free(newurl);
+
+ if(res && !data->state.errorbuf) {
+ /*
+ * As an extra precaution: if no error string has been set and there was
+ * an error, use the strerror() string or if things are so bad that not
+ * even that is good, set a bad string that mentions the error code.
+ */
+ const char *str = curl_easy_strerror(res);
+ if(!str)
+ failf(data, "unspecified error %d", (int)res);
+ else
+ failf(data, "%s", str);
+ }
+
+ /* run post-transfer uncondionally, but don't clobber the return code if
+ we already have an error code recorder */
+ res2 = Curl_posttransfer(data);
+ if(!res && res2)
+ res = res2;
+
+ return res;
+}
+
+/*
+ * Curl_setup_transfer() is called to setup some basic properties for the
+ * upcoming transfer.
+ */
+CURLcode
+Curl_setup_transfer(
+ struct connectdata *c_conn, /* connection data */
+ int sockindex, /* socket index to read from or -1 */
+ curl_off_t size, /* -1 if unknown at this point */
+ bool getheader, /* TRUE if header parsing is wanted */
+ curl_off_t *bytecountp, /* return number of bytes read or NULL */
+ int writesockindex, /* socket index to write to, it may very
+ well be the same we read from. -1
+ disables */
+ curl_off_t *writecountp /* return number of bytes written or
+ NULL */
+ )
+{
+ struct connectdata *conn = (struct connectdata *)c_conn;
+ struct SessionHandle *data = conn->data;
+
+ if(!conn)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ curlassert((sockindex <= 1) && (sockindex >= -1));
+
+ /* now copy all input parameters */
+ conn->sockfd = sockindex == -1 ?
+ CURL_SOCKET_BAD : conn->sock[sockindex];
+ conn->writesockfd = writesockindex == -1 ?
+ CURL_SOCKET_BAD:conn->sock[writesockindex];
+ conn->bits.getheader = getheader;
+
+ data->reqdata.size = size;
+ data->reqdata.bytecountp = bytecountp;
+ data->reqdata.writebytecountp = writecountp;
+
+ return CURLE_OK;
+}
diff --git a/Utilities/cmcurl/transfer.h b/Utilities/cmcurl/transfer.h
new file mode 100644
index 0000000000..3c415cc72c
--- /dev/null
+++ b/Utilities/cmcurl/transfer.h
@@ -0,0 +1,51 @@
+#ifndef __TRANSFER_H
+#define __TRANSFER_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+CURLcode Curl_perform(struct SessionHandle *data);
+CURLcode Curl_pretransfer(struct SessionHandle *data);
+CURLcode Curl_second_connect(struct connectdata *conn);
+CURLcode Curl_posttransfer(struct SessionHandle *data);
+CURLcode Curl_follow(struct SessionHandle *data, char *newurl, bool retry);
+CURLcode Curl_readwrite(struct connectdata *conn, bool *done);
+int Curl_single_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks);
+CURLcode Curl_readwrite_init(struct connectdata *conn);
+CURLcode Curl_readrewind(struct connectdata *conn);
+CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp);
+bool Curl_retry_request(struct connectdata *conn, char **url);
+
+/* This sets up a forthcoming transfer */
+CURLcode
+Curl_setup_transfer (struct connectdata *data,
+ int sockindex, /* socket index to read from or -1 */
+ curl_off_t size, /* -1 if unknown at this point */
+ bool getheader, /* TRUE if header parsing is wanted */
+ curl_off_t *bytecountp, /* return number of bytes read */
+ int writesockindex, /* socket index to write to, it may
+ very well be the same we read from.
+ -1 disables */
+ curl_off_t *writecountp /* return number of bytes written */
+);
+#endif
diff --git a/Utilities/cmcurl/url.c b/Utilities/cmcurl/url.c
new file mode 100644
index 0000000000..da12231f10
--- /dev/null
+++ b/Utilities/cmcurl/url.c
@@ -0,0 +1,4252 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/* -- WIN32 approved -- */
+
+#include "setup.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#include <errno.h>
+
+#ifdef WIN32
+#include <time.h>
+#include <io.h>
+#else
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <netinet/in.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <netdb.h>
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#include <sys/ioctl.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#ifdef VMS
+#include <in.h>
+#include <inet.h>
+#endif
+
+#ifdef HAVE_SETJMP_H
+#include <setjmp.h>
+#endif
+
+#ifndef HAVE_SOCKET
+#error "We can't compile without socket() support!"
+#endif
+#endif
+
+#ifdef USE_LIBIDN
+#include <idna.h>
+#include <tld.h>
+#include <stringprep.h>
+#ifdef HAVE_IDN_FREE_H
+#include <idn-free.h>
+#else
+void idn_free (void *ptr); /* prototype from idn-free.h, not provided by
+ libidn 0.4.5's make install! */
+#endif
+#ifndef HAVE_IDN_FREE
+/* if idn_free() was not found in this version of libidn, use plain free()
+ instead */
+#define idn_free(x) (free)(x)
+#endif
+#endif /* USE_LIBIDN */
+
+#include "urldata.h"
+#include "netrc.h"
+
+#include "formdata.h"
+#include "base64.h"
+#include "sslgen.h"
+#include "hostip.h"
+#include "transfer.h"
+#include "sendf.h"
+#include "progress.h"
+#include "cookie.h"
+#include "strequal.h"
+#include "strerror.h"
+#include "escape.h"
+#include "strtok.h"
+#include "share.h"
+#include "content_encoding.h"
+#include "http_digest.h"
+#include "http_negotiate.h"
+#include "select.h"
+#include "multiif.h"
+#include "easyif.h"
+
+/* And now for the protocols */
+#include "ftp.h"
+#include "dict.h"
+#include "telnet.h"
+#include "tftp.h"
+#include "http.h"
+#include "file.h"
+#include "ldap.h"
+#include "ssh.h"
+#include "url.h"
+#include "connect.h"
+#include "inet_ntop.h"
+#include "http_ntlm.h"
+#include "socks.h"
+#include <ca-bundle.h>
+
+#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
+#include "inet_ntoa_r.h"
+#endif
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#ifdef HAVE_KRB4
+#include "krb4.h"
+#endif
+#include "memory.h"
+
+/* The last #include file should be: */
+#include "memdebug.h"
+
+/* Local static prototypes */
+static long ConnectionKillOne(struct SessionHandle *data);
+static bool ConnectionExists(struct SessionHandle *data,
+ struct connectdata *needle,
+ struct connectdata **usethis);
+static long ConnectionStore(struct SessionHandle *data,
+ struct connectdata *conn);
+static bool IsPipeliningPossible(struct SessionHandle *handle);
+static bool IsPipeliningEnabled(struct SessionHandle *handle);
+static void conn_free(struct connectdata *conn);
+
+static void signalPipeClose(struct curl_llist *pipe);
+
+#define MAX_PIPELINE_LENGTH 5
+
+/*
+ * We use this ZERO_NULL to avoid picky compiler warnings,
+ * when assigning a NULL pointer to a function pointer var.
+ */
+
+#define ZERO_NULL 0
+
+#ifndef USE_ARES
+/* not for ares builds */
+
+#ifndef WIN32
+/* not for WIN32 builds */
+
+#ifdef HAVE_SIGSETJMP
+extern sigjmp_buf curl_jmpenv;
+#endif
+
+#ifdef SIGALRM
+static
+RETSIGTYPE alarmfunc(int sig)
+{
+ /* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */
+ (void)sig;
+#ifdef HAVE_SIGSETJMP
+ siglongjmp(curl_jmpenv, 1);
+#endif
+ /*return;*/ /* not reahed, and has no effect anyway */
+}
+#endif /* SIGALRM */
+#endif /* WIN32 */
+#endif /* USE_ARES */
+
+void Curl_safefree(void *ptr)
+{
+ if(ptr)
+ free(ptr);
+}
+
+static void close_connections(struct SessionHandle *data)
+{
+ /* Loop through all open connections and kill them one by one */
+ while(-1 != ConnectionKillOne(data))
+ ; /* empty loop */
+}
+
+/*
+ * This is the internal function curl_easy_cleanup() calls. This should
+ * cleanup and free all resources associated with this sessionhandle.
+ *
+ * NOTE: if we ever add something that attempts to write to a socket or
+ * similar here, we must ignore SIGPIPE first. It is currently only done
+ * when curl_easy_perform() is invoked.
+ */
+
+CURLcode Curl_close(struct SessionHandle *data)
+{
+ struct Curl_multi *m = data->multi;
+
+#ifdef CURLDEBUG
+ /* only for debugging, scan through all connections and see if there's a
+ pipe reference still identifying this handle */
+
+ if(data->state.is_in_pipeline)
+ fprintf(stderr, "CLOSED when in pipeline!\n");
+
+ if(data->state.connc && data->state.connc->type == CONNCACHE_MULTI) {
+ struct conncache *c = data->state.connc;
+ int i;
+ struct curl_llist *pipe;
+ struct curl_llist_element *curr;
+ struct connectdata *connptr;
+
+ for(i=0; i< c->num; i++) {
+ connptr = c->connects[i];
+ if(!connptr)
+ continue;
+
+ pipe = connptr->send_pipe;
+ if(pipe) {
+ for (curr = pipe->head; curr; curr=curr->next) {
+ if(data == (struct SessionHandle *) curr->ptr) {
+ fprintf(stderr,
+ "MAJOR problem we %p are still in send pipe for %p done %d\n",
+ data, connptr, connptr->bits.done);
+ }
+ }
+ }
+ pipe = connptr->recv_pipe;
+ if(pipe) {
+ for (curr = pipe->head; curr; curr=curr->next) {
+ if(data == (struct SessionHandle *) curr->ptr) {
+ fprintf(stderr,
+ "MAJOR problem we %p are still in recv pipe for %p done %d\n",
+ data, connptr, connptr->bits.done);
+ }
+ }
+ }
+ }
+ }
+#endif
+
+ if(m)
+ /* This handle is still part of a multi handle, take care of this first
+ and detach this handle from there. */
+ Curl_multi_rmeasy(data->multi, data);
+
+ data->magic = 0; /* force a clear AFTER the possibly enforced removal from
+ the multi handle, since that function uses the magic
+ field! */
+
+ if(data->state.connc) {
+
+ if(data->state.connc->type == CONNCACHE_PRIVATE) {
+ /* close all connections still alive that are in the private connection
+ cache, as we no longer have the pointer left to the shared one. */
+ close_connections(data);
+
+ /* free the connection cache if allocated privately */
+ Curl_rm_connc(data->state.connc);
+ }
+ }
+
+ if(data->state.shared_conn) {
+ /* marked to be used by a pending connection so we can't kill this handle
+ just yet */
+ data->state.closed = TRUE;
+ return CURLE_OK;
+ }
+
+ if ( ! (data->share && data->share->hostcache) ) {
+ if ( !Curl_global_host_cache_use(data)) {
+ Curl_hash_destroy(data->dns.hostcache);
+ }
+ }
+
+ /* Free the pathbuffer */
+ Curl_safefree(data->reqdata.pathbuffer);
+ Curl_safefree(data->reqdata.proto.generic);
+
+ /* Close down all open SSL info and sessions */
+ Curl_ssl_close_all(data);
+ Curl_safefree(data->state.first_host);
+ Curl_safefree(data->state.scratch);
+
+ if(data->change.referer_alloc)
+ free(data->change.referer);
+
+ if(data->change.url_alloc)
+ free(data->change.url);
+
+ Curl_safefree(data->state.headerbuff);
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+ Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
+ if(data->set.cookiejar) {
+ if(data->change.cookielist) {
+ /* If there is a list of cookie files to read, do it first so that
+ we have all the told files read before we write the new jar */
+ Curl_cookie_loadfiles(data);
+ }
+
+ /* we have a "destination" for all the cookies to get dumped to */
+ if(Curl_cookie_output(data->cookies, data->set.cookiejar))
+ infof(data, "WARNING: failed to save cookies in %s\n",
+ data->set.cookiejar);
+ }
+ else {
+ if(data->change.cookielist)
+ /* since nothing is written, we can just free the list of cookie file
+ names */
+ curl_slist_free_all(data->change.cookielist); /* clean up list */
+ }
+
+ if( !data->share || (data->cookies != data->share->cookies) ) {
+ Curl_cookie_cleanup(data->cookies);
+ }
+ Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
+#endif
+
+ Curl_digest_cleanup(data);
+
+ Curl_safefree(data->info.contenttype);
+
+ /* this destroys the channel and we cannot use it anymore after this */
+ ares_destroy(data->state.areschannel);
+
+#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
+ /* close iconv conversion descriptors */
+ if (data->inbound_cd != (iconv_t)-1) {
+ iconv_close(data->inbound_cd);
+ }
+ if (data->outbound_cd != (iconv_t)-1) {
+ iconv_close(data->outbound_cd);
+ }
+ if (data->utf8_cd != (iconv_t)-1) {
+ iconv_close(data->utf8_cd);
+ }
+#endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
+
+ /* No longer a dirty share, if it exists */
+ if (data->share)
+ data->share->dirty--;
+
+ free(data);
+ return CURLE_OK;
+}
+
+/* create a connection cache of a private or multi type */
+struct conncache *Curl_mk_connc(int type,
+ int amount) /* set -1 to use default */
+{
+ /* It is subject for debate how many default connections to have for a multi
+ connection cache... */
+ int default_amount = amount == -1?
+ ((type == CONNCACHE_PRIVATE)?5:10):amount;
+ struct conncache *c;
+
+ c= calloc(sizeof(struct conncache), 1);
+ if(!c)
+ return NULL;
+
+ c->connects = calloc(sizeof(struct connectdata *), default_amount);
+ if(!c->connects) {
+ free(c);
+ return NULL;
+ }
+
+ c->num = default_amount;
+
+ return c;
+}
+
+/* Change number of entries of a connection cache */
+CURLcode Curl_ch_connc(struct SessionHandle *data,
+ struct conncache *c,
+ long newamount)
+{
+ long i;
+ struct connectdata **newptr;
+
+ if(newamount < 1)
+ newamount = 1; /* we better have at least one entry */
+
+ if(!c) {
+ /* we get a NULL pointer passed in as connection cache, which means that
+ there is no cache created for this SessionHandle just yet, we create a
+ brand new with the requested size.
+ */
+ data->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE, newamount);
+ if(!data->state.connc)
+ return CURLE_OUT_OF_MEMORY;
+ return CURLE_OK;
+ }
+
+ if(newamount < c->num) {
+ /* Since this number is *decreased* from the existing number, we must
+ close the possibly open connections that live on the indexes that
+ are being removed!
+
+ NOTE: for conncache_multi cases we must make sure that we only
+ close handles not in use.
+ */
+ for(i=newamount; i< c->num; i++)
+ Curl_disconnect(c->connects[i]);
+
+ /* If the most recent connection is no longer valid, mark it
+ invalid. */
+ if(data->state.lastconnect <= newamount)
+ data->state.lastconnect = -1;
+ }
+ if(newamount > 0) {
+ newptr= (struct connectdata **)
+ realloc(c->connects, sizeof(struct connectdata *) * newamount);
+ if(!newptr)
+ /* we closed a few connections in vain, but so what? */
+ return CURLE_OUT_OF_MEMORY;
+
+ /* nullify the newly added pointers */
+ for(i=c->num; i<newamount; i++)
+ newptr[i] = NULL;
+
+ c->connects = newptr;
+ c->num = newamount;
+ }
+ /* we no longer support less than 1 as size for the connection cache, and
+ I'm not sure it ever worked to set it to zero */
+ return CURLE_OK;
+}
+
+/* Free a connection cache. This is called from Curl_close() and
+ curl_multi_cleanup(). */
+void Curl_rm_connc(struct conncache *c)
+{
+ if(c->connects) {
+ int i;
+ for(i = 0; i < c->num; ++i)
+ conn_free(c->connects[i]);
+
+ free(c->connects);
+ }
+
+ free(c);
+}
+
+/**
+ * Curl_open()
+ *
+ * @param curl is a pointer to a sessionhandle pointer that gets set by this
+ * function.
+ * @return CURLcode
+ */
+
+CURLcode Curl_open(struct SessionHandle **curl)
+{
+ CURLcode res = CURLE_OK;
+ struct SessionHandle *data;
+
+ /* Very simple start-up: alloc the struct, init it with zeroes and return */
+ data = (struct SessionHandle *)calloc(1, sizeof(struct SessionHandle));
+ if(!data)
+ /* this is a very serious error */
+ return CURLE_OUT_OF_MEMORY;
+
+ data->magic = CURLEASY_MAGIC_NUMBER;
+
+#ifdef USE_ARES
+ if(ARES_SUCCESS != ares_init(&data->state.areschannel)) {
+ free(data);
+ return CURLE_FAILED_INIT;
+ }
+ /* make sure that all other returns from this function should destroy the
+ ares channel before returning error! */
+#endif
+
+ /* We do some initial setup here, all those fields that can't be just 0 */
+
+ data->state.headerbuff=(char*)malloc(HEADERSIZE);
+ if(!data->state.headerbuff)
+ res = CURLE_OUT_OF_MEMORY;
+ else {
+ data->state.headersize=HEADERSIZE;
+
+ data->set.out = stdout; /* default output to stdout */
+ data->set.in = stdin; /* default input from stdin */
+ data->set.err = stderr; /* default stderr to stderr */
+
+ /* use fwrite as default function to store output */
+ data->set.fwrite = (curl_write_callback)fwrite;
+
+ /* use fread as default function to read input */
+ data->set.fread = (curl_read_callback)fread;
+
+ /* conversion callbacks for non-ASCII hosts */
+ data->set.convfromnetwork = (curl_conv_callback)ZERO_NULL;
+ data->set.convtonetwork = (curl_conv_callback)ZERO_NULL;
+ data->set.convfromutf8 = (curl_conv_callback)ZERO_NULL;
+
+#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
+ /* conversion descriptors for iconv calls */
+ data->outbound_cd = (iconv_t)-1;
+ data->inbound_cd = (iconv_t)-1;
+ data->utf8_cd = (iconv_t)-1;
+#endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
+
+ data->set.infilesize = -1; /* we don't know any size */
+ data->set.postfieldsize = -1;
+ data->set.maxredirs = -1; /* allow any amount by default */
+ data->state.current_speed = -1; /* init to negative == impossible */
+
+ data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */
+ data->set.ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */
+ data->set.ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */
+ data->set.ftp_filemethod = FTPFILE_MULTICWD;
+ data->set.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
+
+ /* make libcurl quiet by default: */
+ data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */
+ data->progress.flags |= PGRS_HIDE;
+
+ /* Set the default size of the SSL session ID cache */
+ data->set.ssl.numsessions = 5;
+
+ data->set.proxyport = 1080;
+ data->set.proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */
+ data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic */
+ data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic */
+
+ /* This no longer creates a connection cache here. It is instead made on
+ the first call to curl_easy_perform() or when the handle is added to a
+ multi stack. */
+
+ data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
+ type */
+
+ /* most recent connection is not yet defined */
+ data->state.lastconnect = -1;
+
+ Curl_easy_initHandleData(data);
+
+ /*
+ * libcurl 7.10 introduced SSL verification *by default*! This needs to be
+ * switched off unless wanted.
+ */
+ data->set.ssl.verifypeer = TRUE;
+ data->set.ssl.verifyhost = 2;
+ data->set.ssl.sessionid = TRUE; /* session ID caching enabled by default */
+#ifdef CURL_CA_BUNDLE
+ /* This is our preferred CA cert bundle since install time */
+ data->set.ssl.CAfile = (char *)CURL_CA_BUNDLE;
+#endif
+ }
+
+ if(res) {
+ ares_destroy(data->state.areschannel);
+ if(data->state.headerbuff)
+ free(data->state.headerbuff);
+ free(data);
+ data = NULL;
+ }
+ else
+ *curl = data;
+
+ return res;
+}
+
+CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
+ va_list param)
+{
+ char *argptr;
+ CURLcode result = CURLE_OK;
+
+ switch(option) {
+ case CURLOPT_DNS_CACHE_TIMEOUT:
+ data->set.dns_cache_timeout = va_arg(param, int);
+ break;
+ case CURLOPT_DNS_USE_GLOBAL_CACHE:
+ {
+ int use_cache = va_arg(param, int);
+ if (use_cache) {
+ Curl_global_host_cache_init();
+ }
+
+ data->set.global_dns_cache = (bool)(0 != use_cache);
+ }
+ break;
+ case CURLOPT_SSL_CIPHER_LIST:
+ /* set a list of cipher we want to use in the SSL connection */
+ data->set.ssl.cipher_list = va_arg(param, char *);
+ break;
+
+ case CURLOPT_RANDOM_FILE:
+ /*
+ * This is the path name to a file that contains random data to seed
+ * the random SSL stuff with. The file is only used for reading.
+ */
+ data->set.ssl.random_file = va_arg(param, char *);
+ break;
+ case CURLOPT_EGDSOCKET:
+ /*
+ * The Entropy Gathering Daemon socket pathname
+ */
+ data->set.ssl.egdsocket = va_arg(param, char *);
+ break;
+ case CURLOPT_MAXCONNECTS:
+ /*
+ * Set the absolute number of maximum simultaneous alive connection that
+ * libcurl is allowed to have.
+ */
+ result = Curl_ch_connc(data, data->state.connc, va_arg(param, long));
+ break;
+ case CURLOPT_FORBID_REUSE:
+ /*
+ * When this transfer is done, it must not be left to be reused by a
+ * subsequent transfer but shall be closed immediately.
+ */
+ data->set.reuse_forbid = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_FRESH_CONNECT:
+ /*
+ * This transfer shall not use a previously cached connection but
+ * should be made with a fresh new connect!
+ */
+ data->set.reuse_fresh = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_VERBOSE:
+ /*
+ * Verbose means infof() calls that give a lot of information about
+ * the connection and transfer procedures as well as internal choices.
+ */
+ data->set.verbose = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_HEADER:
+ /*
+ * Set to include the header in the general data output stream.
+ */
+ data->set.include_header = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_NOPROGRESS:
+ /*
+ * Shut off the internal supported progress meter
+ */
+ data->set.hide_progress = (bool)(0 != va_arg(param, long));
+ if(data->set.hide_progress)
+ data->progress.flags |= PGRS_HIDE;
+ else
+ data->progress.flags &= ~PGRS_HIDE;
+ break;
+ case CURLOPT_NOBODY:
+ /*
+ * Do not include the body part in the output data stream.
+ */
+ data->set.opt_no_body = (bool)(0 != va_arg(param, long));
+ if(data->set.opt_no_body)
+ /* in HTTP lingo, this means using the HEAD request */
+ data->set.httpreq = HTTPREQ_HEAD;
+ break;
+ case CURLOPT_FAILONERROR:
+ /*
+ * Don't output the >=300 error code HTML-page, but instead only
+ * return error.
+ */
+ data->set.http_fail_on_error = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_UPLOAD:
+ case CURLOPT_PUT:
+ /*
+ * We want to sent data to the remote host. If this is HTTP, that equals
+ * using the PUT request.
+ */
+ data->set.upload = (bool)(0 != va_arg(param, long));
+ if(data->set.upload)
+ /* If this is HTTP, PUT is what's needed to "upload" */
+ data->set.httpreq = HTTPREQ_PUT;
+ break;
+ case CURLOPT_FILETIME:
+ /*
+ * Try to get the file time of the remote document. The time will
+ * later (possibly) become available using curl_easy_getinfo().
+ */
+ data->set.get_filetime = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_FTP_CREATE_MISSING_DIRS:
+ /*
+ * An FTP option that modifies an upload to create missing directories on
+ * the server.
+ */
+ data->set.ftp_create_missing_dirs = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_FTP_RESPONSE_TIMEOUT:
+ /*
+ * An FTP option that specifies how quickly an FTP response must be
+ * obtained before it is considered failure.
+ */
+ data->set.ftp_response_timeout = va_arg( param , long );
+ break;
+ case CURLOPT_FTPLISTONLY:
+ /*
+ * An FTP option that changes the command to one that asks for a list
+ * only, no file info details.
+ */
+ data->set.ftp_list_only = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_FTPAPPEND:
+ /*
+ * We want to upload and append to an existing (FTP) file.
+ */
+ data->set.ftp_append = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_FTP_FILEMETHOD:
+ /*
+ * How do access files over FTP.
+ */
+ data->set.ftp_filemethod = (curl_ftpfile)va_arg(param, long);
+ break;
+ case CURLOPT_NETRC:
+ /*
+ * Parse the $HOME/.netrc file
+ */
+ data->set.use_netrc = (enum CURL_NETRC_OPTION)va_arg(param, long);
+ break;
+ case CURLOPT_NETRC_FILE:
+ /*
+ * Use this file instead of the $HOME/.netrc file
+ */
+ data->set.netrc_file = va_arg(param, char *);
+ break;
+ case CURLOPT_TRANSFERTEXT:
+ /*
+ * This option was previously named 'FTPASCII'. Renamed to work with
+ * more protocols than merely FTP.
+ *
+ * Transfer using ASCII (instead of BINARY).
+ */
+ data->set.prefer_ascii = (bool)(0 != va_arg(param, long));
+ break;
+ case CURLOPT_TIMECONDITION:
+ /*
+ * Set HTTP time condition. This must be one of the defines in the
+ * curl/curl.h header file.
+ */
+ data->set.timecondition = (curl_TimeCond)va_arg(param, long);
+ break;
+ case CURLOPT_TIMEVALUE:
+ /*
+ * This is the value to compare with the remote document with the
+ * method set with CURLOPT_TIMECONDITION
+ */
+ data->set.timevalue = (time_t)va_arg(param, long);
+ break;
+ case CURLOPT_SSLVERSION:
+ /*
+ * Set explicit SSL version to try to connect with, as some SSL
+ * implementations are lame.
+ */
+ data->set.ssl.version = va_arg(param, long);
+ break;
+
+#ifndef CURL_DISABLE_HTTP
+ case CURLOPT_AUTOREFERER:
+ /*
+ * Switch on automatic referer that gets set if curl follows locations.
+ */
+ data->set.http_auto_referer = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_ENCODING:
+ /*
+ * String to use at the value of Accept-Encoding header.
+ *
+ * If the encoding is set to "" we use an Accept-Encoding header that
+ * encompasses all the encodings we support.
+ * If the encoding is set to NULL we don't send an Accept-Encoding header
+ * and ignore an received Content-Encoding header.
+ *
+ */
+ data->set.encoding = va_arg(param, char *);
+ if(data->set.encoding && !*data->set.encoding)
+ data->set.encoding = (char*)ALL_CONTENT_ENCODINGS;
+ break;
+
+ case CURLOPT_FOLLOWLOCATION:
+ /*
+ * Follow Location: header hints on a HTTP-server.
+ */
+ data->set.http_follow_location = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_UNRESTRICTED_AUTH:
+ /*
+ * Send authentication (user+password) when following locations, even when
+ * hostname changed.
+ */
+ data->set.http_disable_hostname_check_before_authentication =
+ (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_MAXREDIRS:
+ /*
+ * The maximum amount of hops you allow curl to follow Location:
+ * headers. This should mostly be used to detect never-ending loops.
+ */
+ data->set.maxredirs = va_arg(param, long);
+ break;
+
+ case CURLOPT_POST:
+ /* Does this option serve a purpose anymore? Yes it does, when
+ CURLOPT_POSTFIELDS isn't used and the POST data is read off the
+ callback! */
+ if(va_arg(param, long)) {
+ data->set.httpreq = HTTPREQ_POST;
+ data->set.opt_no_body = FALSE; /* this is implied */
+ }
+ else
+ data->set.httpreq = HTTPREQ_GET;
+ break;
+
+ case CURLOPT_POSTFIELDS:
+ /*
+ * A string with POST data. Makes curl HTTP POST. Even if it is NULL.
+ */
+ data->set.postfields = va_arg(param, char *);
+ data->set.httpreq = HTTPREQ_POST;
+ break;
+
+ case CURLOPT_POSTFIELDSIZE:
+ /*
+ * The size of the POSTFIELD data to prevent libcurl to do strlen() to
+ * figure it out. Enables binary posts.
+ */
+ data->set.postfieldsize = va_arg(param, long);
+ break;
+
+ case CURLOPT_POSTFIELDSIZE_LARGE:
+ /*
+ * The size of the POSTFIELD data to prevent libcurl to do strlen() to
+ * figure it out. Enables binary posts.
+ */
+ data->set.postfieldsize = va_arg(param, curl_off_t);
+ break;
+
+ case CURLOPT_HTTPPOST:
+ /*
+ * Set to make us do HTTP POST
+ */
+ data->set.httppost = va_arg(param, struct curl_httppost *);
+ data->set.httpreq = HTTPREQ_POST_FORM;
+ data->set.opt_no_body = FALSE; /* this is implied */
+ break;
+
+ case CURLOPT_REFERER:
+ /*
+ * String to set in the HTTP Referer: field.
+ */
+ if(data->change.referer_alloc) {
+ free(data->change.referer);
+ data->change.referer_alloc = FALSE;
+ }
+ data->set.set_referer = va_arg(param, char *);
+ data->change.referer = data->set.set_referer;
+ break;
+
+ case CURLOPT_USERAGENT:
+ /*
+ * String to use in the HTTP User-Agent field
+ */
+ data->set.useragent = va_arg(param, char *);
+ break;
+
+ case CURLOPT_HTTPHEADER:
+ /*
+ * Set a list with HTTP headers to use (or replace internals with)
+ */
+ data->set.headers = va_arg(param, struct curl_slist *);
+ break;
+
+ case CURLOPT_HTTP200ALIASES:
+ /*
+ * Set a list of aliases for HTTP 200 in response header
+ */
+ data->set.http200aliases = va_arg(param, struct curl_slist *);
+ break;
+
+#if !defined(CURL_DISABLE_COOKIES)
+ case CURLOPT_COOKIE:
+ /*
+ * Cookie string to send to the remote server in the request.
+ */
+ data->set.cookie = va_arg(param, char *);
+ break;
+
+ case CURLOPT_COOKIEFILE:
+ /*
+ * Set cookie file to read and parse. Can be used multiple times.
+ */
+ argptr = (char *)va_arg(param, void *);
+ if(argptr) {
+ struct curl_slist *cl;
+ /* append the cookie file name to the list of file names, and deal with
+ them later */
+ cl = curl_slist_append(data->change.cookielist, argptr);
+
+ if(!cl)
+ return CURLE_OUT_OF_MEMORY;
+
+ data->change.cookielist = cl;
+ }
+ break;
+
+ case CURLOPT_COOKIEJAR:
+ /*
+ * Set cookie file name to dump all cookies to when we're done.
+ */
+ data->set.cookiejar = (char *)va_arg(param, void *);
+
+ /*
+ * Activate the cookie parser. This may or may not already
+ * have been made.
+ */
+ data->cookies = Curl_cookie_init(data, NULL, data->cookies,
+ data->set.cookiesession);
+ break;
+
+ case CURLOPT_COOKIESESSION:
+ /*
+ * Set this option to TRUE to start a new "cookie session". It will
+ * prevent the forthcoming read-cookies-from-file actions to accept
+ * cookies that are marked as being session cookies, as they belong to a
+ * previous session.
+ *
+ * In the original Netscape cookie spec, "session cookies" are cookies
+ * with no expire date set. RFC2109 describes the same action if no
+ * 'Max-Age' is set and RFC2965 includes the RFC2109 description and adds
+ * a 'Discard' action that can enforce the discard even for cookies that
+ * have a Max-Age.
+ *
+ * We run mostly with the original cookie spec, as hardly anyone implements
+ * anything else.
+ */
+ data->set.cookiesession = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_COOKIELIST:
+ argptr = va_arg(param, char *);
+
+ if(argptr == NULL)
+ break;
+
+ if(strequal(argptr, "ALL")) {
+ /* clear all cookies */
+ Curl_cookie_clearall(data->cookies);
+ break;
+ }
+ else if(strequal(argptr, "SESS")) {
+ /* clear session cookies */
+ Curl_cookie_clearsess(data->cookies);
+ break;
+ }
+
+ if(!data->cookies)
+ /* if cookie engine was not running, activate it */
+ data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE);
+
+ argptr = strdup(argptr);
+ if(!argptr) {
+ result = CURLE_OUT_OF_MEMORY;
+ break;
+ }
+
+ if(checkprefix("Set-Cookie:", argptr))
+ /* HTTP Header format line */
+ Curl_cookie_add(data, data->cookies, TRUE, argptr + 11, NULL, NULL);
+
+ else
+ /* Netscape format line */
+ Curl_cookie_add(data, data->cookies, FALSE, argptr, NULL, NULL);
+
+ free(argptr);
+ break;
+#endif /* CURL_DISABLE_COOKIES */
+
+ case CURLOPT_HTTPGET:
+ /*
+ * Set to force us do HTTP GET
+ */
+ if(va_arg(param, long)) {
+ data->set.httpreq = HTTPREQ_GET;
+ data->set.upload = FALSE; /* switch off upload */
+ data->set.opt_no_body = FALSE; /* this is implied */
+ }
+ break;
+
+ case CURLOPT_HTTP_VERSION:
+ /*
+ * This sets a requested HTTP version to be used. The value is one of
+ * the listed enums in curl/curl.h.
+ */
+ data->set.httpversion = va_arg(param, long);
+ break;
+
+ case CURLOPT_HTTPPROXYTUNNEL:
+ /*
+ * Tunnel operations through the proxy instead of normal proxy use
+ */
+ data->set.tunnel_thru_httpproxy = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_CUSTOMREQUEST:
+ /*
+ * Set a custom string to use as request
+ */
+ data->set.customrequest = va_arg(param, char *);
+
+ /* we don't set
+ data->set.httpreq = HTTPREQ_CUSTOM;
+ here, we continue as if we were using the already set type
+ and this just changes the actual request keyword */
+ break;
+
+ case CURLOPT_PROXYPORT:
+ /*
+ * Explicitly set HTTP proxy port number.
+ */
+ data->set.proxyport = va_arg(param, long);
+ break;
+
+ case CURLOPT_HTTPAUTH:
+ /*
+ * Set HTTP Authentication type BITMASK.
+ */
+ {
+ long auth = va_arg(param, long);
+ /* switch off bits we can't support */
+#ifndef USE_NTLM
+ auth &= ~CURLAUTH_NTLM; /* no NTLM without SSL */
+#endif
+#ifndef HAVE_GSSAPI
+ auth &= ~CURLAUTH_GSSNEGOTIATE; /* no GSS-Negotiate without GSSAPI */
+#endif
+ if(!auth)
+ return CURLE_FAILED_INIT; /* no supported types left! */
+
+ data->set.httpauth = auth;
+ }
+ break;
+
+ case CURLOPT_PROXYAUTH:
+ /*
+ * Set HTTP Authentication type BITMASK.
+ */
+ {
+ long auth = va_arg(param, long);
+ /* switch off bits we can't support */
+#ifndef USE_NTLM
+ auth &= ~CURLAUTH_NTLM; /* no NTLM without SSL */
+#endif
+#ifndef HAVE_GSSAPI
+ auth &= ~CURLAUTH_GSSNEGOTIATE; /* no GSS-Negotiate without GSSAPI */
+#endif
+ if(!auth)
+ return CURLE_FAILED_INIT; /* no supported types left! */
+
+ data->set.proxyauth = auth;
+ }
+ break;
+#endif /* CURL_DISABLE_HTTP */
+
+ case CURLOPT_PROXY:
+ /*
+ * Set proxy server:port to use as HTTP proxy.
+ *
+ * If the proxy is set to "" we explicitly say that we don't want to use a
+ * proxy (even though there might be environment variables saying so).
+ *
+ * Setting it to NULL, means no proxy but allows the environment variables
+ * to decide for us.
+ */
+ data->set.proxy = va_arg(param, char *);
+ break;
+
+ case CURLOPT_WRITEHEADER:
+ /*
+ * Custom pointer to pass the header write callback function
+ */
+ data->set.writeheader = (void *)va_arg(param, void *);
+ break;
+ case CURLOPT_ERRORBUFFER:
+ /*
+ * Error buffer provided by the caller to get the human readable
+ * error string in.
+ */
+ data->set.errorbuffer = va_arg(param, char *);
+ break;
+ case CURLOPT_FILE:
+ /*
+ * FILE pointer to write to or include in the data write callback
+ */
+ data->set.out = va_arg(param, FILE *);
+ break;
+ case CURLOPT_FTPPORT:
+ /*
+ * Use FTP PORT, this also specifies which IP address to use
+ */
+ data->set.ftpport = va_arg(param, char *);
+ data->set.ftp_use_port = (bool)(NULL != data->set.ftpport);
+ break;
+
+ case CURLOPT_FTP_USE_EPRT:
+ data->set.ftp_use_eprt = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_FTP_USE_EPSV:
+ data->set.ftp_use_epsv = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_FTP_SSL_CCC:
+ data->set.ftp_use_ccc = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_FTP_SKIP_PASV_IP:
+ /*
+ * Enable or disable FTP_SKIP_PASV_IP, which will disable/enable the
+ * bypass of the IP address in PASV responses.
+ */
+ data->set.ftp_skip_ip = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_INFILE:
+ /*
+ * FILE pointer to read the file to be uploaded from. Or possibly
+ * used as argument to the read callback.
+ */
+ data->set.in = va_arg(param, FILE *);
+ break;
+ case CURLOPT_INFILESIZE:
+ /*
+ * If known, this should inform curl about the file size of the
+ * to-be-uploaded file.
+ */
+ data->set.infilesize = va_arg(param, long);
+ break;
+ case CURLOPT_INFILESIZE_LARGE:
+ /*
+ * If known, this should inform curl about the file size of the
+ * to-be-uploaded file.
+ */
+ data->set.infilesize = va_arg(param, curl_off_t);
+ break;
+ case CURLOPT_LOW_SPEED_LIMIT:
+ /*
+ * The low speed limit that if transfers are below this for
+ * CURLOPT_LOW_SPEED_TIME, the transfer is aborted.
+ */
+ data->set.low_speed_limit=va_arg(param, long);
+ break;
+ case CURLOPT_MAX_SEND_SPEED_LARGE:
+ /*
+ * The max speed limit that sends transfer more than
+ * CURLOPT_MAX_SEND_PER_SECOND bytes per second the transfer is
+ * throttled..
+ */
+ data->set.max_send_speed=va_arg(param, curl_off_t);
+ break;
+ case CURLOPT_MAX_RECV_SPEED_LARGE:
+ /*
+ * The max speed limit that sends transfer more than
+ * CURLOPT_MAX_RECV_PER_SECOND bytes per second the transfer is
+ * throttled..
+ */
+ data->set.max_recv_speed=va_arg(param, curl_off_t);
+ break;
+ case CURLOPT_LOW_SPEED_TIME:
+ /*
+ * The low speed time that if transfers are below the set
+ * CURLOPT_LOW_SPEED_LIMIT during this time, the transfer is aborted.
+ */
+ data->set.low_speed_time=va_arg(param, long);
+ break;
+ case CURLOPT_URL:
+ /*
+ * The URL to fetch.
+ */
+ if(data->change.url_alloc) {
+ /* the already set URL is allocated, free it first! */
+ free(data->change.url);
+ data->change.url_alloc=FALSE;
+ }
+ data->set.set_url = va_arg(param, char *);
+ data->change.url = data->set.set_url;
+ data->change.url_changed = TRUE;
+ break;
+ case CURLOPT_PORT:
+ /*
+ * The port number to use when getting the URL
+ */
+ data->set.use_port = va_arg(param, long);
+ break;
+ case CURLOPT_TIMEOUT:
+ /*
+ * The maximum time you allow curl to use for a single transfer
+ * operation.
+ */
+ data->set.timeout = va_arg(param, long);
+ break;
+ case CURLOPT_CONNECTTIMEOUT:
+ /*
+ * The maximum time you allow curl to use to connect.
+ */
+ data->set.connecttimeout = va_arg(param, long);
+ break;
+
+ case CURLOPT_USERPWD:
+ /*
+ * user:password to use in the operation
+ */
+ data->set.userpwd = va_arg(param, char *);
+ break;
+ case CURLOPT_POSTQUOTE:
+ /*
+ * List of RAW FTP commands to use after a transfer
+ */
+ data->set.postquote = va_arg(param, struct curl_slist *);
+ break;
+ case CURLOPT_PREQUOTE:
+ /*
+ * List of RAW FTP commands to use prior to RETR (Wesley Laxton)
+ */
+ data->set.prequote = va_arg(param, struct curl_slist *);
+ break;
+ case CURLOPT_QUOTE:
+ /*
+ * List of RAW FTP commands to use before a transfer
+ */
+ data->set.quote = va_arg(param, struct curl_slist *);
+ break;
+ case CURLOPT_PROGRESSFUNCTION:
+ /*
+ * Progress callback function
+ */
+ data->set.fprogress = va_arg(param, curl_progress_callback);
+ if(data->set.fprogress)
+ data->progress.callback = TRUE; /* no longer internal */
+ else
+ data->progress.callback = FALSE; /* NULL enforces internal */
+
+ break;
+ case CURLOPT_PROGRESSDATA:
+ /*
+ * Custom client data to pass to the progress callback
+ */
+ data->set.progress_client = va_arg(param, void *);
+ break;
+ case CURLOPT_PROXYUSERPWD:
+ /*
+ * user:password needed to use the proxy
+ */
+ data->set.proxyuserpwd = va_arg(param, char *);
+ break;
+ case CURLOPT_RANGE:
+ /*
+ * What range of the file you want to transfer
+ */
+ data->set.set_range = va_arg(param, char *);
+ break;
+ case CURLOPT_RESUME_FROM:
+ /*
+ * Resume transfer at the give file position
+ */
+ data->set.set_resume_from = va_arg(param, long);
+ break;
+ case CURLOPT_RESUME_FROM_LARGE:
+ /*
+ * Resume transfer at the give file position
+ */
+ data->set.set_resume_from = va_arg(param, curl_off_t);
+ break;
+ case CURLOPT_DEBUGFUNCTION:
+ /*
+ * stderr write callback.
+ */
+ data->set.fdebug = va_arg(param, curl_debug_callback);
+ /*
+ * if the callback provided is NULL, it'll use the default callback
+ */
+ break;
+ case CURLOPT_DEBUGDATA:
+ /*
+ * Set to a void * that should receive all error writes. This
+ * defaults to CURLOPT_STDERR for normal operations.
+ */
+ data->set.debugdata = va_arg(param, void *);
+ break;
+ case CURLOPT_STDERR:
+ /*
+ * Set to a FILE * that should receive all error writes. This
+ * defaults to stderr for normal operations.
+ */
+ data->set.err = va_arg(param, FILE *);
+ if(!data->set.err)
+ data->set.err = stderr;
+ break;
+ case CURLOPT_HEADERFUNCTION:
+ /*
+ * Set header write callback
+ */
+ data->set.fwrite_header = va_arg(param, curl_write_callback);
+ break;
+ case CURLOPT_WRITEFUNCTION:
+ /*
+ * Set data write callback
+ */
+ data->set.fwrite = va_arg(param, curl_write_callback);
+ if(!data->set.fwrite)
+ /* When set to NULL, reset to our internal default function */
+ data->set.fwrite = (curl_write_callback)fwrite;
+ break;
+ case CURLOPT_READFUNCTION:
+ /*
+ * Read data callback
+ */
+ data->set.fread = va_arg(param, curl_read_callback);
+ if(!data->set.fread)
+ /* When set to NULL, reset to our internal default function */
+ data->set.fread = (curl_read_callback)fread;
+ break;
+ case CURLOPT_CONV_FROM_NETWORK_FUNCTION:
+ /*
+ * "Convert from network encoding" callback
+ */
+ data->set.convfromnetwork = va_arg(param, curl_conv_callback);
+ break;
+ case CURLOPT_CONV_TO_NETWORK_FUNCTION:
+ /*
+ * "Convert to network encoding" callback
+ */
+ data->set.convtonetwork = va_arg(param, curl_conv_callback);
+ break;
+ case CURLOPT_CONV_FROM_UTF8_FUNCTION:
+ /*
+ * "Convert from UTF-8 encoding" callback
+ */
+ data->set.convfromutf8 = va_arg(param, curl_conv_callback);
+ break;
+ case CURLOPT_IOCTLFUNCTION:
+ /*
+ * I/O control callback. Might be NULL.
+ */
+ data->set.ioctl = va_arg(param, curl_ioctl_callback);
+ break;
+ case CURLOPT_IOCTLDATA:
+ /*
+ * I/O control data pointer. Might be NULL.
+ */
+ data->set.ioctl_client = va_arg(param, void *);
+ break;
+ case CURLOPT_SSLCERT:
+ /*
+ * String that holds file name of the SSL certificate to use
+ */
+ data->set.cert = va_arg(param, char *);
+ break;
+ case CURLOPT_SSLCERTTYPE:
+ /*
+ * String that holds file type of the SSL certificate to use
+ */
+ data->set.cert_type = va_arg(param, char *);
+ break;
+ case CURLOPT_SSLKEY:
+ /*
+ * String that holds file name of the SSL certificate to use
+ */
+ data->set.key = va_arg(param, char *);
+ break;
+ case CURLOPT_SSLKEYTYPE:
+ /*
+ * String that holds file type of the SSL certificate to use
+ */
+ data->set.key_type = va_arg(param, char *);
+ break;
+ case CURLOPT_SSLKEYPASSWD:
+ /*
+ * String that holds the SSL private key password.
+ */
+ data->set.key_passwd = va_arg(param, char *);
+ break;
+ case CURLOPT_SSLENGINE:
+ /*
+ * String that holds the SSL crypto engine.
+ */
+ argptr = va_arg(param, char *);
+ if (argptr && argptr[0])
+ result = Curl_ssl_set_engine(data, argptr);
+ break;
+
+ case CURLOPT_SSLENGINE_DEFAULT:
+ /*
+ * flag to set engine as default.
+ */
+ result = Curl_ssl_set_engine_default(data);
+ break;
+ case CURLOPT_CRLF:
+ /*
+ * Kludgy option to enable CRLF conversions. Subject for removal.
+ */
+ data->set.crlf = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_INTERFACE:
+ /*
+ * Set what interface or address/hostname to bind the socket to when
+ * performing an operation and thus what from-IP your connection will use.
+ */
+ data->set.device = va_arg(param, char *);
+ break;
+ case CURLOPT_LOCALPORT:
+ /*
+ * Set what local port to bind the socket to when performing an operation.
+ */
+ data->set.localport = (unsigned short) va_arg(param, long);
+ break;
+ case CURLOPT_LOCALPORTRANGE:
+ /*
+ * Set number of local ports to try, starting with CURLOPT_LOCALPORT.
+ */
+ data->set.localportrange = (int) va_arg(param, long);
+ break;
+ case CURLOPT_KRB4LEVEL:
+ /*
+ * A string that defines the krb4 security level.
+ */
+ data->set.krb4_level = va_arg(param, char *);
+ data->set.krb4 = (bool)(NULL != data->set.krb4_level);
+ break;
+ case CURLOPT_SSL_VERIFYPEER:
+ /*
+ * Enable peer SSL verifying.
+ */
+ data->set.ssl.verifypeer = va_arg(param, long);
+ break;
+ case CURLOPT_SSL_VERIFYHOST:
+ /*
+ * Enable verification of the CN contained in the peer certificate
+ */
+ data->set.ssl.verifyhost = va_arg(param, long);
+ break;
+ case CURLOPT_SSL_CTX_FUNCTION:
+ /*
+ * Set a SSL_CTX callback
+ */
+ data->set.ssl.fsslctx = va_arg(param, curl_ssl_ctx_callback);
+ break;
+ case CURLOPT_SSL_CTX_DATA:
+ /*
+ * Set a SSL_CTX callback parameter pointer
+ */
+ data->set.ssl.fsslctxp = va_arg(param, void *);
+ break;
+ case CURLOPT_CAINFO:
+ /*
+ * Set CA info for SSL connection. Specify file name of the CA certificate
+ */
+ data->set.ssl.CAfile = va_arg(param, char *);
+ break;
+ case CURLOPT_CAPATH:
+ /*
+ * Set CA path info for SSL connection. Specify directory name of the CA
+ * certificates which have been prepared using openssl c_rehash utility.
+ */
+ /* This does not work on windows. */
+ data->set.ssl.CApath = va_arg(param, char *);
+ break;
+ case CURLOPT_TELNETOPTIONS:
+ /*
+ * Set a linked list of telnet options
+ */
+ data->set.telnet_options = va_arg(param, struct curl_slist *);
+ break;
+
+ case CURLOPT_BUFFERSIZE:
+ /*
+ * The application kindly asks for a differently sized receive buffer.
+ * If it seems reasonable, we'll use it.
+ */
+ data->set.buffer_size = va_arg(param, long);
+
+ if((data->set.buffer_size> (BUFSIZE -1 )) ||
+ (data->set.buffer_size < 1))
+ data->set.buffer_size = 0; /* huge internal default */
+
+ break;
+
+ case CURLOPT_NOSIGNAL:
+ /*
+ * The application asks not to set any signal() or alarm() handlers,
+ * even when using a timeout.
+ */
+ data->set.no_signal = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_SHARE:
+ {
+ struct Curl_share *set;
+ set = va_arg(param, struct Curl_share *);
+
+ /* disconnect from old share, if any */
+ if(data->share) {
+ Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
+
+ if(data->dns.hostcachetype == HCACHE_SHARED) {
+ data->dns.hostcache = NULL;
+ data->dns.hostcachetype = HCACHE_NONE;
+ }
+
+ if(data->share->cookies == data->cookies)
+ data->cookies = NULL;
+
+ data->share->dirty--;
+
+ Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
+ data->share = NULL;
+ }
+
+ /* use new share if it set */
+ data->share = set;
+ if(data->share) {
+
+ Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
+
+ data->share->dirty++;
+
+ if(data->share->hostcache) {
+ /* use shared host cache, first free the private one if any */
+ if(data->dns.hostcachetype == HCACHE_PRIVATE)
+ Curl_hash_destroy(data->dns.hostcache);
+
+ data->dns.hostcache = data->share->hostcache;
+ data->dns.hostcachetype = HCACHE_SHARED;
+ }
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+ if(data->share->cookies) {
+ /* use shared cookie list, first free own one if any */
+ if (data->cookies)
+ Curl_cookie_cleanup(data->cookies);
+ data->cookies = data->share->cookies;
+ }
+#endif /* CURL_DISABLE_HTTP */
+ Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
+
+ }
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+ /* check cookie list is set */
+ if(!data->cookies)
+ data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE );
+#endif /* CURL_DISABLE_HTTP */
+ /* check for host cache not needed,
+ * it will be done by curl_easy_perform */
+ }
+ break;
+
+ case CURLOPT_PROXYTYPE:
+ /*
+ * Set proxy type. HTTP/SOCKS4/SOCKS5
+ */
+ data->set.proxytype = (curl_proxytype)va_arg(param, long);
+ break;
+
+ case CURLOPT_PRIVATE:
+ /*
+ * Set private data pointer.
+ */
+ data->set.private_data = va_arg(param, char *);
+ break;
+
+ case CURLOPT_MAXFILESIZE:
+ /*
+ * Set the maximum size of a file to download.
+ */
+ data->set.max_filesize = va_arg(param, long);
+ break;
+
+ case CURLOPT_FTP_SSL:
+ /*
+ * Make FTP transfers attempt to use SSL/TLS.
+ */
+ data->set.ftp_ssl = (curl_ftpssl)va_arg(param, long);
+ break;
+
+ case CURLOPT_FTPSSLAUTH:
+ /*
+ * Set a specific auth for FTP-SSL transfers.
+ */
+ data->set.ftpsslauth = (curl_ftpauth)va_arg(param, long);
+ break;
+
+ case CURLOPT_IPRESOLVE:
+ data->set.ip_version = va_arg(param, long);
+ break;
+
+ case CURLOPT_MAXFILESIZE_LARGE:
+ /*
+ * Set the maximum size of a file to download.
+ */
+ data->set.max_filesize = va_arg(param, curl_off_t);
+ break;
+
+ case CURLOPT_TCP_NODELAY:
+ /*
+ * Enable or disable TCP_NODELAY, which will disable/enable the Nagle
+ * algorithm
+ */
+ data->set.tcp_nodelay = (bool)(0 != va_arg(param, long));
+ break;
+
+ /*
+ case CURLOPT_SOURCE_URL:
+ case CURLOPT_SOURCE_USERPWD:
+ case CURLOPT_SOURCE_QUOTE:
+ case CURLOPT_SOURCE_PREQUOTE:
+ case CURLOPT_SOURCE_POSTQUOTE:
+ These former 3rd party transfer options are deprecated */
+
+ case CURLOPT_FTP_ACCOUNT:
+ data->set.ftp_account = va_arg(param, char *);
+ break;
+
+ case CURLOPT_IGNORE_CONTENT_LENGTH:
+ data->set.ignorecl = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_CONNECT_ONLY:
+ /*
+ * No data transfer, set up connection and let application use the socket
+ */
+ data->set.connect_only = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_FTP_ALTERNATIVE_TO_USER:
+ data->set.ftp_alternative_to_user = va_arg(param, char *);
+ break;
+
+ case CURLOPT_SOCKOPTFUNCTION:
+ /*
+ * socket callback function: called after socket() but before connect()
+ */
+ data->set.fsockopt = va_arg(param, curl_sockopt_callback);
+ break;
+
+ case CURLOPT_SOCKOPTDATA:
+ /*
+ * socket callback data pointer. Might be NULL.
+ */
+ data->set.sockopt_client = va_arg(param, void *);
+ break;
+
+ case CURLOPT_SSL_SESSIONID_CACHE:
+ data->set.ssl.sessionid = (bool)(0 != va_arg(param, long));
+ break;
+
+ case CURLOPT_SSH_AUTH_TYPES:
+ data->set.ssh_auth_types = va_arg(param, long);
+ break;
+
+ case CURLOPT_SSH_PUBLIC_KEYFILE:
+ /*
+ * Use this file instead of the $HOME/.ssh/id_dsa.pub file
+ */
+ data->set.ssh_public_key = va_arg(param, char *);
+ break;
+
+ case CURLOPT_SSH_PRIVATE_KEYFILE:
+ /*
+ * Use this file instead of the $HOME/.ssh/id_dsa file
+ */
+ data->set.ssh_private_key = va_arg(param, char *);
+ break;
+
+ default:
+ /* unknown tag and its companion, just ignore: */
+ result = CURLE_FAILED_INIT; /* correct this */
+ break;
+ }
+
+ return result;
+}
+
+static void conn_free(struct connectdata *conn)
+{
+ if (!conn)
+ return;
+
+ /* close possibly still open sockets */
+ if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET])
+ sclose(conn->sock[SECONDARYSOCKET]);
+ if(CURL_SOCKET_BAD != conn->sock[FIRSTSOCKET])
+ sclose(conn->sock[FIRSTSOCKET]);
+
+ Curl_safefree(conn->user);
+ Curl_safefree(conn->passwd);
+ Curl_safefree(conn->proxyuser);
+ Curl_safefree(conn->proxypasswd);
+ Curl_safefree(conn->allocptr.proxyuserpwd);
+ Curl_safefree(conn->allocptr.uagent);
+ Curl_safefree(conn->allocptr.userpwd);
+ Curl_safefree(conn->allocptr.accept_encoding);
+ Curl_safefree(conn->allocptr.rangeline);
+ Curl_safefree(conn->allocptr.ref);
+ Curl_safefree(conn->allocptr.host);
+ Curl_safefree(conn->allocptr.cookiehost);
+ Curl_safefree(conn->ip_addr_str);
+ Curl_safefree(conn->trailer);
+ Curl_safefree(conn->host.rawalloc); /* host name buffer */
+ Curl_safefree(conn->proxy.rawalloc); /* proxy name buffer */
+
+ Curl_llist_destroy(conn->send_pipe, NULL);
+ Curl_llist_destroy(conn->recv_pipe, NULL);
+
+ /* possible left-overs from the async name resolvers */
+#if defined(USE_ARES)
+ Curl_safefree(conn->async.hostname);
+ Curl_safefree(conn->async.os_specific);
+#elif defined(CURLRES_THREADED)
+ Curl_destroy_thread_data(&conn->async);
+#endif
+
+ Curl_free_ssl_config(&conn->ssl_config);
+
+ free(conn); /* free all the connection oriented data */
+}
+
+CURLcode Curl_disconnect(struct connectdata *conn)
+{
+ struct SessionHandle *data;
+ if(!conn)
+ return CURLE_OK; /* this is closed and fine already */
+ data = conn->data;
+
+ if(!data) {
+ DEBUGF(infof(data, "DISCONNECT without easy handle, ignoring\n"));
+ return CURLE_OK;
+ }
+
+#if defined(CURLDEBUG) && defined(AGGRESIVE_TEST)
+ /* scan for DNS cache entries still marked as in use */
+ Curl_hash_apply(data->hostcache,
+ NULL, Curl_scan_cache_used);
+#endif
+
+ Curl_expire(data, 0); /* shut off timers */
+ Curl_hostcache_prune(data); /* kill old DNS cache entries */
+
+ /*
+ * The range string is usually freed in curl_done(), but we might
+ * get here *instead* if we fail prematurely. Thus we need to be able
+ * to free this resource here as well.
+ */
+ if(data->reqdata.rangestringalloc) {
+ free(data->reqdata.range);
+ data->reqdata.rangestringalloc = FALSE;
+ }
+
+ if((conn->ntlm.state != NTLMSTATE_NONE) ||
+ (conn->proxyntlm.state != NTLMSTATE_NONE)) {
+ /* Authentication data is a mix of connection-related and sessionhandle-
+ related stuff. NTLM is connection-related so when we close the shop
+ we shall forget. */
+ data->state.authhost.done = FALSE;
+ data->state.authhost.picked =
+ data->state.authhost.want;
+
+ data->state.authproxy.done = FALSE;
+ data->state.authproxy.picked =
+ data->state.authproxy.want;
+
+ data->state.authproblem = FALSE;
+
+ Curl_ntlm_cleanup(conn);
+ }
+
+ if(conn->curl_disconnect)
+ /* This is set if protocol-specific cleanups should be made */
+ conn->curl_disconnect(conn);
+
+ if(-1 != conn->connectindex) {
+ /* unlink ourselves! */
+ infof(data, "Closing connection #%ld\n", conn->connectindex);
+ if(data->state.connc)
+ /* only clear the table entry if we still know in which cache we
+ used to be in */
+ data->state.connc->connects[conn->connectindex] = NULL;
+ }
+
+#ifdef USE_LIBIDN
+ if(conn->host.encalloc)
+ idn_free(conn->host.encalloc); /* encoded host name buffer, must be freed
+ with idn_free() since this was allocated
+ by libidn */
+ if(conn->proxy.encalloc)
+ idn_free(conn->proxy.encalloc); /* encoded proxy name buffer, must be
+ freed with idn_free() since this was
+ allocated by libidn */
+#endif
+
+ Curl_ssl_close(conn);
+
+ /* Indicate to all handles on the pipe that we're dead */
+ if (IsPipeliningEnabled(data)) {
+ signalPipeClose(conn->send_pipe);
+ signalPipeClose(conn->recv_pipe);
+ }
+
+ conn_free(conn);
+
+ return CURLE_OK;
+}
+
+/*
+ * This function should return TRUE if the socket is to be assumed to
+ * be dead. Most commonly this happens when the server has closed the
+ * connection due to inactivity.
+ */
+static bool SocketIsDead(curl_socket_t sock)
+{
+ int sval;
+ bool ret_val = TRUE;
+
+ sval = Curl_select(sock, CURL_SOCKET_BAD, 0);
+ if(sval == 0)
+ /* timeout */
+ ret_val = FALSE;
+
+ return ret_val;
+}
+
+static bool IsPipeliningPossible(struct SessionHandle *handle)
+{
+ if (handle->multi && Curl_multi_canPipeline(handle->multi) &&
+ (handle->set.httpreq == HTTPREQ_GET ||
+ handle->set.httpreq == HTTPREQ_HEAD) &&
+ handle->set.httpversion != CURL_HTTP_VERSION_1_0)
+ return TRUE;
+
+ return FALSE;
+}
+
+static bool IsPipeliningEnabled(struct SessionHandle *handle)
+{
+ if (handle->multi && Curl_multi_canPipeline(handle->multi))
+ return TRUE;
+
+ return FALSE;
+}
+
+void Curl_addHandleToPipeline(struct SessionHandle *data,
+ struct curl_llist *pipe)
+{
+#ifdef CURLDEBUG
+ if(!IsPipeliningPossible(data)) {
+ /* when not pipelined, there MUST be no handle in the list already */
+ if(pipe->head)
+ infof(data, "PIPE when no PIPE supposed!\n");
+ }
+#endif
+ Curl_llist_insert_next(pipe, pipe->tail, data);
+}
+
+
+int Curl_removeHandleFromPipeline(struct SessionHandle *handle,
+ struct curl_llist *pipe)
+{
+ struct curl_llist_element *curr;
+
+ curr = pipe->head;
+ while (curr) {
+ if (curr->ptr == handle) {
+ Curl_llist_remove(pipe, curr, NULL);
+ return 1; /* we removed a handle */
+ }
+ curr = curr->next;
+ }
+
+ return 0;
+}
+
+#if 0 /* this code is saved here as it is useful for debugging purposes */
+static void Curl_printPipeline(struct curl_llist *pipe)
+{
+ struct curl_llist_element *curr;
+
+ curr = pipe->head;
+ while (curr) {
+ struct SessionHandle *data = (struct SessionHandle *) curr->ptr;
+ infof(data, "Handle in pipeline: %s\n",
+ data->reqdata.path);
+ curr = curr->next;
+ }
+}
+#endif
+
+bool Curl_isHandleAtHead(struct SessionHandle *handle,
+ struct curl_llist *pipe)
+{
+ struct curl_llist_element *curr = pipe->head;
+ if (curr) {
+ return (bool)(curr->ptr == handle);
+ }
+
+ return FALSE;
+}
+
+static void signalPipeClose(struct curl_llist *pipe)
+{
+ struct curl_llist_element *curr;
+
+ curr = pipe->head;
+ while (curr) {
+ struct curl_llist_element *next = curr->next;
+ struct SessionHandle *data = (struct SessionHandle *) curr->ptr;
+
+#ifdef CURLDEBUG /* debug-only code */
+ if(data->magic != CURLEASY_MAGIC_NUMBER) {
+ /* MAJOR BADNESS */
+ fprintf(stderr, "signalPipeClose() found BAAD easy handle\n");
+ }
+ else
+#endif
+
+ data->state.pipe_broke = TRUE;
+ Curl_llist_remove(pipe, curr, NULL);
+ curr = next;
+ }
+}
+
+
+/*
+ * Given one filled in connection struct (named needle), this function should
+ * detect if there already is one that has all the significant details
+ * exactly the same and thus should be used instead.
+ *
+ * If there is a match, this function returns TRUE - and has marked the
+ * connection as 'in-use'. It must later be called with ConnectionDone() to
+ * return back to 'idle' (unused) state.
+ */
+static bool
+ConnectionExists(struct SessionHandle *data,
+ struct connectdata *needle,
+ struct connectdata **usethis)
+{
+ long i;
+ struct connectdata *check;
+ bool canPipeline = IsPipeliningPossible(data);
+
+ for(i=0; i< data->state.connc->num; i++) {
+ bool match = FALSE;
+ /*
+ * Note that if we use a HTTP proxy, we check connections to that
+ * proxy and not to the actual remote server.
+ */
+ check = data->state.connc->connects[i];
+ if(!check)
+ /* NULL pointer means not filled-in entry */
+ continue;
+
+ if (check->connectindex == -1) {
+ check->connectindex = i; /* Set this appropriately since it might have
+ been set to -1 when the easy was removed
+ from the multi */
+ }
+
+ infof(data, "Examining connection #%ld for reuse\n", check->connectindex);
+
+ if(check->inuse && !canPipeline) {
+ /* can only happen within multi handles, and means that another easy
+ handle is using this connection */
+ continue;
+ }
+
+#ifdef CURLRES_ASYNCH
+ /* ip_addr_str is NULL only if the resolving of the name hasn't completed
+ yet and until then we don't re-use this connection */
+ if (!check->ip_addr_str) {
+ infof(data,
+ "Connection #%ld has not finished name resolve, can't reuse\n",
+ check->connectindex);
+ continue;
+ }
+#endif
+
+ if (check->send_pipe->size +
+ check->recv_pipe->size >= MAX_PIPELINE_LENGTH) {
+ infof(data, "Connection #%ld has its pipeline full, can't reuse\n",
+ check->connectindex);
+ continue;
+ }
+
+ if (data->state.is_in_pipeline && check->bits.close) {
+ /* Don't pick a connection that is going to be closed */
+ infof(data, "Connection #%ld has been marked for close, can't reuse\n",
+ check->connectindex);
+ continue;
+ }
+
+ if((needle->protocol&PROT_SSL) != (check->protocol&PROT_SSL))
+ /* don't do mixed SSL and non-SSL connections */
+ continue;
+
+ if(!needle->bits.httpproxy || needle->protocol&PROT_SSL) {
+ /* The requested connection does not use a HTTP proxy or it
+ uses SSL. */
+
+ if(!(needle->protocol&PROT_SSL) && check->bits.httpproxy)
+ /* we don't do SSL but the cached connection has a proxy,
+ then don't match this */
+ continue;
+
+ if(strequal(needle->protostr, check->protostr) &&
+ strequal(needle->host.name, check->host.name) &&
+ (needle->remote_port == check->remote_port) ) {
+ if(needle->protocol & PROT_SSL) {
+ /* This is SSL, verify that we're using the same
+ ssl options as well */
+ if(!Curl_ssl_config_matches(&needle->ssl_config,
+ &check->ssl_config)) {
+ infof(data,
+ "Connection #%ld has different SSL parameters, "
+ "can't reuse\n",
+ check->connectindex );
+ continue;
+ }
+ }
+ if((needle->protocol & PROT_FTP) ||
+ ((needle->protocol & PROT_HTTP) &&
+ (data->state.authhost.want==CURLAUTH_NTLM))) {
+ /* This is FTP or HTTP+NTLM, verify that we're using the same name
+ and password as well */
+ if(!strequal(needle->user, check->user) ||
+ !strequal(needle->passwd, check->passwd)) {
+ /* one of them was different */
+ continue;
+ }
+ }
+ match = TRUE;
+ }
+ }
+ else { /* The requested needle connection is using a proxy,
+ is the checked one using the same? */
+ if(check->bits.httpproxy &&
+ strequal(needle->proxy.name, check->proxy.name) &&
+ needle->port == check->port) {
+ /* This is the same proxy connection, use it! */
+ match = TRUE;
+ }
+ }
+
+ if(match) {
+ if (!IsPipeliningEnabled(data)) {
+ /* The check for a dead socket makes sense only in the
+ non-pipelining case */
+ bool dead = SocketIsDead(check->sock[FIRSTSOCKET]);
+ if(dead) {
+ check->data = data;
+ infof(data, "Connection #%d seems to be dead!\n", i);
+
+ Curl_disconnect(check); /* disconnect resources */
+ data->state.connc->connects[i]=NULL; /* nothing here */
+
+ return FALSE;
+ }
+ }
+
+ check->inuse = TRUE; /* mark this as being in use so that no other
+ handle in a multi stack may nick it */
+
+ if (canPipeline) {
+ /* Mark the connection as being in a pipeline */
+ check->is_in_pipeline = TRUE;
+ }
+
+ check->connectindex = i; /* Set this appropriately since it might have
+ been set to -1 when the easy was removed
+ from the multi */
+ *usethis = check;
+ return TRUE; /* yes, we found one to use! */
+ }
+ }
+
+ return FALSE; /* no matching connecting exists */
+}
+
+
+
+/*
+ * This function frees/closes a connection in the connection cache. This
+ * should take the previously set policy into account when deciding which
+ * of the connections to kill.
+ */
+static long
+ConnectionKillOne(struct SessionHandle *data)
+{
+ long i;
+ struct connectdata *conn;
+ long highscore=-1;
+ long connindex=-1;
+ long score;
+ struct timeval now;
+
+ now = Curl_tvnow();
+
+ for(i=0; data->state.connc && (i< data->state.connc->num); i++) {
+ conn = data->state.connc->connects[i];
+
+ if(!conn || conn->inuse)
+ continue;
+
+ /* Set higher score for the age passed since the connection was used */
+ score = Curl_tvdiff(now, conn->now);
+
+ if(score > highscore) {
+ highscore = score;
+ connindex = i;
+ }
+ }
+ if(connindex >= 0) {
+ /* Set the connection's owner correctly */
+ conn = data->state.connc->connects[connindex];
+ conn->data = data;
+
+ /* the winner gets the honour of being disconnected */
+ (void)Curl_disconnect(conn);
+
+ /* clean the array entry */
+ data->state.connc->connects[connindex] = NULL;
+ }
+
+ return connindex; /* return the available index or -1 */
+}
+
+/* this connection can now be marked 'idle' */
+static void
+ConnectionDone(struct connectdata *conn)
+{
+ conn->inuse = FALSE;
+ if (!conn->send_pipe && !conn->recv_pipe)
+ conn->is_in_pipeline = FALSE;
+}
+
+/*
+ * The given input connection struct pointer is to be stored. If the "cache"
+ * is already full, we must clean out the most suitable using the previously
+ * set policy.
+ *
+ * The given connection should be unique. That must've been checked prior to
+ * this call.
+ */
+static long
+ConnectionStore(struct SessionHandle *data,
+ struct connectdata *conn)
+{
+ long i;
+ for(i=0; i< data->state.connc->num; i++) {
+ if(!data->state.connc->connects[i])
+ break;
+ }
+ if(i == data->state.connc->num) {
+ /* there was no room available, kill one */
+ i = ConnectionKillOne(data);
+ if(-1 != i)
+ infof(data, "Connection (#%d) was killed to make room (holds %d)\n",
+ i, data->state.connc->num);
+ else
+ infof(data, "This connection did not fit in the connection cache\n");
+ }
+
+ conn->connectindex = i; /* Make the child know where the pointer to this
+ particular data is stored. But note that this -1
+ if this is not within the cache and this is
+ probably not checked for everywhere (yet). */
+ conn->inuse = TRUE;
+ if(-1 != i) {
+ /* Only do this if a true index was returned, if -1 was returned there
+ is no room in the cache for an unknown reason and we cannot store
+ this there.
+
+ TODO: make sure we really can work with more handles than positions in
+ the cache, or possibly we should (allow to automatically) resize the
+ connection cache when we add more easy handles to a multi handle!
+ */
+ data->state.connc->connects[i] = conn; /* fill in this */
+ conn->data = data;
+ }
+
+ return i;
+}
+
+static CURLcode ConnectPlease(struct SessionHandle *data,
+ struct connectdata *conn,
+ struct Curl_dns_entry *hostaddr,
+ bool *connected)
+{
+ CURLcode result;
+ Curl_addrinfo *addr;
+ char *hostname = conn->bits.httpproxy?conn->proxy.name:conn->host.name;
+
+ infof(data, "About to connect() to %s%s port %d (#%d)\n",
+ conn->bits.httpproxy?"proxy ":"",
+ hostname, conn->port, conn->connectindex);
+
+ /*************************************************************
+ * Connect to server/proxy
+ *************************************************************/
+ result= Curl_connecthost(conn,
+ hostaddr,
+ &conn->sock[FIRSTSOCKET],
+ &addr,
+ connected);
+ if(CURLE_OK == result) {
+ /* All is cool, then we store the current information */
+ conn->dns_entry = hostaddr;
+ conn->ip_addr = addr;
+
+ Curl_store_ip_addr(conn);
+
+ switch(data->set.proxytype) {
+ case CURLPROXY_SOCKS5:
+ result = Curl_SOCKS5(conn->proxyuser, conn->proxypasswd, conn);
+ break;
+ case CURLPROXY_HTTP:
+ /* do nothing here. handled later. */
+ break;
+ case CURLPROXY_SOCKS4:
+ result = Curl_SOCKS4(conn->proxyuser, conn);
+ break;
+ default:
+ failf(data, "unknown proxytype option given");
+ result = CURLE_COULDNT_CONNECT;
+ break;
+ }
+ }
+
+ return result;
+}
+
+/*
+ * verboseconnect() displays verbose information after a connect
+ */
+static void verboseconnect(struct connectdata *conn)
+{
+ infof(conn->data, "Connected to %s (%s) port %d (#%d)\n",
+ conn->bits.httpproxy ? conn->proxy.dispname : conn->host.dispname,
+ conn->ip_addr_str, conn->port, conn->connectindex);
+}
+
+int Curl_protocol_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
+{
+ if(conn->curl_proto_getsock)
+ return conn->curl_proto_getsock(conn, socks, numsocks);
+ return GETSOCK_BLANK;
+}
+
+int Curl_doing_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
+{
+ if(conn && conn->curl_doing_getsock)
+ return conn->curl_doing_getsock(conn, socks, numsocks);
+ return GETSOCK_BLANK;
+}
+
+/*
+ * We are doing protocol-specific connecting and this is being called over and
+ * over from the multi interface until the connection phase is done on
+ * protocol layer.
+ */
+
+CURLcode Curl_protocol_connecting(struct connectdata *conn,
+ bool *done)
+{
+ CURLcode result=CURLE_OK;
+
+ if(conn && conn->curl_connecting) {
+ *done = FALSE;
+ result = conn->curl_connecting(conn, done);
+ }
+ else
+ *done = TRUE;
+
+ return result;
+}
+
+/*
+ * We are DOING this is being called over and over from the multi interface
+ * until the DOING phase is done on protocol layer.
+ */
+
+CURLcode Curl_protocol_doing(struct connectdata *conn, bool *done)
+{
+ CURLcode result=CURLE_OK;
+
+ if(conn && conn->curl_doing) {
+ *done = FALSE;
+ result = conn->curl_doing(conn, done);
+ }
+ else
+ *done = TRUE;
+
+ return result;
+}
+
+/*
+ * We have discovered that the TCP connection has been successful, we can now
+ * proceed with some action.
+ *
+ */
+CURLcode Curl_protocol_connect(struct connectdata *conn,
+ bool *protocol_done)
+{
+ CURLcode result=CURLE_OK;
+ struct SessionHandle *data = conn->data;
+
+ *protocol_done = FALSE;
+
+ if(conn->bits.tcpconnect && conn->bits.protoconnstart) {
+ /* We already are connected, get back. This may happen when the connect
+ worked fine in the first call, like when we connect to a local server
+ or proxy. Note that we don't know if the protocol is actually done.
+
+ Unless this protocol doesn't have any protocol-connect callback, as
+ then we know we're done. */
+ if(!conn->curl_connecting)
+ *protocol_done = TRUE;
+
+ return CURLE_OK;
+ }
+
+ if(!conn->bits.tcpconnect) {
+
+ Curl_pgrsTime(data, TIMER_CONNECT); /* connect done */
+
+ if(data->set.verbose)
+ verboseconnect(conn);
+ }
+
+ if(!conn->bits.protoconnstart) {
+ if(conn->curl_connect) {
+ /* is there a protocol-specific connect() procedure? */
+
+ /* Set start time here for timeout purposes in the connect procedure, it
+ is later set again for the progress meter purpose */
+ conn->now = Curl_tvnow();
+
+ /* Call the protocol-specific connect function */
+ result = conn->curl_connect(conn, protocol_done);
+ }
+ else
+ *protocol_done = TRUE;
+
+ /* it has started, possibly even completed but that knowledge isn't stored
+ in this bit! */
+ if (!result)
+ conn->bits.protoconnstart = TRUE;
+ }
+
+ return result; /* pass back status */
+}
+
+/*
+ * Helpers for IDNA convertions.
+ */
+#ifdef USE_LIBIDN
+static bool is_ASCII_name(const char *hostname)
+{
+ const unsigned char *ch = (const unsigned char*)hostname;
+
+ while (*ch) {
+ if (*ch++ & 0x80)
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/*
+ * Check if characters in hostname is allowed in Top Level Domain.
+ */
+static bool tld_check_name(struct SessionHandle *data,
+ const char *ace_hostname)
+{
+ size_t err_pos;
+ char *uc_name = NULL;
+ int rc;
+
+ /* Convert (and downcase) ACE-name back into locale's character set */
+ rc = idna_to_unicode_lzlz(ace_hostname, &uc_name, 0);
+ if (rc != IDNA_SUCCESS)
+ return (FALSE);
+
+ rc = tld_check_lz(uc_name, &err_pos, NULL);
+ if (rc == TLD_INVALID)
+ infof(data, "WARNING: %s; pos %u = `%c'/0x%02X\n",
+#ifdef HAVE_TLD_STRERROR
+ tld_strerror((Tld_rc)rc),
+#else
+ "<no msg>",
+#endif
+ err_pos, uc_name[err_pos],
+ uc_name[err_pos] & 255);
+ else if (rc != TLD_SUCCESS)
+ infof(data, "WARNING: TLD check for %s failed; %s\n",
+ uc_name,
+#ifdef HAVE_TLD_STRERROR
+ tld_strerror((Tld_rc)rc)
+#else
+ "<no msg>"
+#endif
+ );
+ if (uc_name)
+ idn_free(uc_name);
+ return (bool)(rc == TLD_SUCCESS);
+}
+#endif
+
+static void fix_hostname(struct SessionHandle *data,
+ struct connectdata *conn, struct hostname *host)
+{
+ /* set the name we use to display the host name */
+ host->dispname = host->name;
+
+#ifdef USE_LIBIDN
+ /*************************************************************
+ * Check name for non-ASCII and convert hostname to ACE form.
+ *************************************************************/
+ if (!is_ASCII_name(host->name) &&
+ stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
+ char *ace_hostname = NULL;
+ int rc = idna_to_ascii_lz(host->name, &ace_hostname, 0);
+ infof (data, "Input domain encoded as `%s'\n",
+ stringprep_locale_charset ());
+ if (rc != IDNA_SUCCESS)
+ infof(data, "Failed to convert %s to ACE; %s\n",
+ host->name, Curl_idn_strerror(conn,rc));
+ else {
+ /* tld_check_name() displays a warning if the host name contains
+ "illegal" characters for this TLD */
+ (void)tld_check_name(data, ace_hostname);
+
+ host->encalloc = ace_hostname;
+ /* change the name pointer to point to the encoded hostname */
+ host->name = host->encalloc;
+ }
+ }
+#else
+ (void)data; /* never used */
+ (void)conn; /* never used */
+#endif
+}
+
+/*
+ * Parse URL and fill in the relevant members of the connection struct.
+ */
+static CURLcode ParseURLAndFillConnection(struct SessionHandle *data,
+ struct connectdata *conn)
+{
+ char *at;
+ char *tmp;
+
+ char *path = data->reqdata.path;
+
+ /*************************************************************
+ * Parse the URL.
+ *
+ * We need to parse the url even when using the proxy, because we will need
+ * the hostname and port in case we are trying to SSL connect through the
+ * proxy -- and we don't know if we will need to use SSL until we parse the
+ * url ...
+ ************************************************************/
+ if((2 == sscanf(data->change.url, "%15[^:]:%[^\n]",
+ conn->protostr,
+ path)) && strequal(conn->protostr, "file")) {
+ if(path[0] == '/' && path[1] == '/') {
+ /* Allow omitted hostname (e.g. file:/<path>). This is not strictly
+ * speaking a valid file: URL by RFC 1738, but treating file:/<path> as
+ * file://localhost/<path> is similar to how other schemes treat missing
+ * hostnames. See RFC 1808. */
+
+ /* This cannot be done with strcpy() in a portable manner, since the
+ memory areas overlap! */
+ memmove(path, path + 2, strlen(path + 2)+1);
+ }
+ /*
+ * we deal with file://<host>/<path> differently since it supports no
+ * hostname other than "localhost" and "127.0.0.1", which is unique among
+ * the URL protocols specified in RFC 1738
+ */
+ if(path[0] != '/') {
+ /* the URL included a host name, we ignore host names in file:// URLs
+ as the standards don't define what to do with them */
+ char *ptr=strchr(path, '/');
+ if(ptr) {
+ /* there was a slash present
+
+ RFC1738 (section 3.1, page 5) says:
+
+ The rest of the locator consists of data specific to the scheme,
+ and is known as the "url-path". It supplies the details of how the
+ specified resource can be accessed. Note that the "/" between the
+ host (or port) and the url-path is NOT part of the url-path.
+
+ As most agents use file://localhost/foo to get '/foo' although the
+ slash preceding foo is a separator and not a slash for the path,
+ a URL as file://localhost//foo must be valid as well, to refer to
+ the same file with an absolute path.
+ */
+
+ if(ptr[1] && ('/' == ptr[1]))
+ /* if there was two slashes, we skip the first one as that is then
+ used truly as a separator */
+ ptr++;
+
+ /* This cannot be made with strcpy, as the memory chunks overlap! */
+ memmove(path, ptr, strlen(ptr)+1);
+ }
+ }
+
+ strcpy(conn->protostr, "file"); /* store protocol string lowercase */
+ }
+ else {
+ /* clear path */
+ path[0]=0;
+
+ if (2 > sscanf(data->change.url,
+ "%15[^\n:]://%[^\n/]%[^\n]",
+ conn->protostr,
+ conn->host.name, path)) {
+
+ /*
+ * The URL was badly formatted, let's try the browser-style _without_
+ * protocol specified like 'http://'.
+ */
+ if((1 > sscanf(data->change.url, "%[^\n/]%[^\n]",
+ conn->host.name, path)) ) {
+ /*
+ * We couldn't even get this format.
+ */
+ failf(data, "<url> malformed");
+ return CURLE_URL_MALFORMAT;
+ }
+
+ /*
+ * Since there was no protocol part specified, we guess what protocol it
+ * is based on the first letters of the server name.
+ */
+
+ /* Note: if you add a new protocol, please update the list in
+ * lib/version.c too! */
+
+ if(checkprefix("FTP.", conn->host.name))
+ strcpy(conn->protostr, "ftp");
+ else if (checkprefix("DICT.", conn->host.name))
+ strcpy(conn->protostr, "DICT");
+ else if (checkprefix("LDAP.", conn->host.name))
+ strcpy(conn->protostr, "LDAP");
+ else {
+ strcpy(conn->protostr, "http");
+ }
+
+ conn->protocol |= PROT_MISSING; /* not given in URL */
+ }
+ }
+
+ /* We search for '?' in the host name (but only on the right side of a
+ * @-letter to allow ?-letters in username and password) to handle things
+ * like http://example.com?param= (notice the missing '/').
+ */
+ at = strchr(conn->host.name, '@');
+ if(at)
+ tmp = strchr(at+1, '?');
+ else
+ tmp = strchr(conn->host.name, '?');
+
+ if(tmp) {
+ /* We must insert a slash before the '?'-letter in the URL. If the URL had
+ a slash after the '?', that is where the path currently begins and the
+ '?string' is still part of the host name.
+
+ We must move the trailing part from the host name and put it first in
+ the path. And have it all prefixed with a slash.
+ */
+
+ size_t hostlen = strlen(tmp);
+ size_t pathlen = strlen(path);
+
+ /* move the existing path plus the zero byte forward, to make room for
+ the host-name part */
+ memmove(path+hostlen+1, path, pathlen+1);
+
+ /* now copy the trailing host part in front of the existing path */
+ memcpy(path+1, tmp, hostlen);
+
+ path[0]='/'; /* prepend the missing slash */
+
+ *tmp=0; /* now cut off the hostname at the ? */
+ }
+ else if(!path[0]) {
+ /* if there's no path set, use a single slash */
+ strcpy(path, "/");
+ }
+
+ /* If the URL is malformatted (missing a '/' after hostname before path) we
+ * insert a slash here. The only letter except '/' we accept to start a path
+ * is '?'.
+ */
+ if(path[0] == '?') {
+ /* We need this function to deal with overlapping memory areas. We know
+ that the memory area 'path' points to is 'urllen' bytes big and that
+ is bigger than the path. Use +1 to move the zero byte too. */
+ memmove(&path[1], path, strlen(path)+1);
+ path[0] = '/';
+ }
+
+ /*
+ * So if the URL was A://B/C,
+ * conn->protostr is A
+ * conn->host.name is B
+ * data->reqdata.path is /C
+ */
+
+ return CURLE_OK;
+}
+
+static void llist_dtor(void *user, void *element)
+{
+ (void)user;
+ (void)element;
+ /* Do nothing */
+}
+
+
+/**
+ * CreateConnection() sets up a new connectdata struct, or re-uses an already
+ * existing one, and resolves host name.
+ *
+ * if this function returns CURLE_OK and *async is set to TRUE, the resolve
+ * response will be coming asynchronously. If *async is FALSE, the name is
+ * already resolved.
+ *
+ * @param data The sessionhandle pointer
+ * @param in_connect is set to the next connection data pointer
+ * @param addr is set to the new dns entry for this connection. If this
+ * connection is re-used it will be NULL.
+ * @param async is set TRUE/FALSE depending on the nature of this lookup
+ * @return CURLcode
+ * @see SetupConnection()
+ *
+ * *NOTE* this function assigns the conn->data pointer!
+ */
+
+static CURLcode CreateConnection(struct SessionHandle *data,
+ struct connectdata **in_connect,
+ struct Curl_dns_entry **addr,
+ bool *async)
+{
+
+ char *tmp;
+ CURLcode result=CURLE_OK;
+ struct connectdata *conn;
+ struct connectdata *conn_temp = NULL;
+ size_t urllen;
+ struct Curl_dns_entry *hostaddr;
+#if defined(HAVE_ALARM) && !defined(USE_ARES)
+ unsigned int prev_alarm=0;
+#endif
+ char endbracket;
+ char user[MAX_CURL_USER_LENGTH];
+ char passwd[MAX_CURL_PASSWORD_LENGTH];
+ int rc;
+ bool reuse;
+ char *proxy;
+ bool proxy_alloc = FALSE;
+
+#ifndef USE_ARES
+#ifdef SIGALRM
+#ifdef HAVE_SIGACTION
+ struct sigaction keep_sigact; /* store the old struct here */
+ bool keep_copysig=FALSE; /* did copy it? */
+#else
+#ifdef HAVE_SIGNAL
+ void (*keep_sigact)(int); /* store the old handler here */
+#endif /* HAVE_SIGNAL */
+#endif /* HAVE_SIGACTION */
+#endif /* SIGALRM */
+#endif /* USE_ARES */
+
+ *addr = NULL; /* nothing yet */
+ *async = FALSE;
+
+ /*************************************************************
+ * Check input data
+ *************************************************************/
+
+ if(!data->change.url)
+ return CURLE_URL_MALFORMAT;
+
+ /* First, split up the current URL in parts so that we can use the
+ parts for checking against the already present connections. In order
+ to not have to modify everything at once, we allocate a temporary
+ connection data struct and fill in for comparison purposes. */
+
+ conn = (struct connectdata *)calloc(sizeof(struct connectdata), 1);
+ if(!conn) {
+ *in_connect = NULL; /* clear the pointer */
+ return CURLE_OUT_OF_MEMORY;
+ }
+ /* We must set the return variable as soon as possible, so that our
+ parent can cleanup any possible allocs we may have done before
+ any failure */
+ *in_connect = conn;
+
+ /* and we setup a few fields in case we end up actually using this struct */
+
+ conn->data = data; /* Setup the association between this connection
+ and the SessionHandle */
+
+ conn->sock[FIRSTSOCKET] = CURL_SOCKET_BAD; /* no file descriptor */
+ conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD; /* no file descriptor */
+ conn->connectindex = -1; /* no index */
+
+ conn->bits.httpproxy = (bool)(data->set.proxy /* http proxy or not */
+ && *data->set.proxy
+ && (data->set.proxytype == CURLPROXY_HTTP));
+ proxy = data->set.proxy; /* if global proxy is set, this is it */
+
+ /* Default protocol-independent behavior doesn't support persistent
+ connections, so we set this to force-close. Protocols that support
+ this need to set this to FALSE in their "curl_do" functions. */
+ conn->bits.close = TRUE;
+
+ conn->readchannel_inuse = FALSE;
+ conn->writechannel_inuse = FALSE;
+
+ conn->read_pos = 0;
+ conn->buf_len = 0;
+
+ /* Initialize the pipeline lists */
+ conn->send_pipe = Curl_llist_alloc((curl_llist_dtor) llist_dtor);
+ conn->recv_pipe = Curl_llist_alloc((curl_llist_dtor) llist_dtor);
+
+ /* Store creation time to help future close decision making */
+ conn->created = Curl_tvnow();
+
+ /* range status */
+ data->reqdata.use_range = (bool)(NULL != data->set.set_range);
+
+ data->reqdata.range = data->set.set_range; /* clone the range setting */
+ data->reqdata.resume_from = data->set.set_resume_from;
+
+ conn->bits.user_passwd = (bool)(NULL != data->set.userpwd);
+ conn->bits.proxy_user_passwd = (bool)(NULL != data->set.proxyuserpwd);
+ conn->bits.no_body = data->set.opt_no_body;
+ conn->bits.tunnel_proxy = data->set.tunnel_thru_httpproxy;
+ conn->bits.ftp_use_epsv = data->set.ftp_use_epsv;
+ conn->bits.ftp_use_eprt = data->set.ftp_use_eprt;
+
+ /* This initing continues below, see the comment "Continue connectdata
+ * initialization here" */
+
+ /***********************************************************
+ * We need to allocate memory to store the path in. We get the size of the
+ * full URL to be sure, and we need to make it at least 256 bytes since
+ * other parts of the code will rely on this fact
+ ***********************************************************/
+#define LEAST_PATH_ALLOC 256
+ urllen=strlen(data->change.url);
+ if(urllen < LEAST_PATH_ALLOC)
+ urllen=LEAST_PATH_ALLOC;
+
+ if (!data->set.source_url /* 3rd party FTP */
+ && data->reqdata.pathbuffer) {
+ /* Free the old buffer */
+ free(data->reqdata.pathbuffer);
+ }
+
+ /*
+ * We malloc() the buffers below urllen+2 to make room for to possibilities:
+ * 1 - an extra terminating zero
+ * 2 - an extra slash (in case a syntax like "www.host.com?moo" is used)
+ */
+
+ data->reqdata.pathbuffer=(char *)malloc(urllen+2);
+ if(NULL == data->reqdata.pathbuffer)
+ return CURLE_OUT_OF_MEMORY; /* really bad error */
+ data->reqdata.path = data->reqdata.pathbuffer;
+
+ conn->host.rawalloc=(char *)malloc(urllen+2);
+ if(NULL == conn->host.rawalloc)
+ return CURLE_OUT_OF_MEMORY;
+
+ conn->host.name = conn->host.rawalloc;
+ conn->host.name[0] = 0;
+
+ result = ParseURLAndFillConnection(data, conn);
+ if (result != CURLE_OK) {
+ return result;
+ }
+
+ /*************************************************************
+ * Take care of proxy authentication stuff
+ *************************************************************/
+ if(conn->bits.proxy_user_passwd) {
+ char proxyuser[MAX_CURL_USER_LENGTH]="";
+ char proxypasswd[MAX_CURL_PASSWORD_LENGTH]="";
+
+ sscanf(data->set.proxyuserpwd,
+ "%" MAX_CURL_USER_LENGTH_TXT "[^:]:"
+ "%" MAX_CURL_PASSWORD_LENGTH_TXT "[^\n]",
+ proxyuser, proxypasswd);
+
+ conn->proxyuser = curl_easy_unescape(data, proxyuser, 0, NULL);
+ if(!conn->proxyuser)
+ return CURLE_OUT_OF_MEMORY;
+
+ conn->proxypasswd = curl_easy_unescape(data, proxypasswd, 0, NULL);
+ if(!conn->proxypasswd)
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+#ifndef CURL_DISABLE_HTTP
+ /*************************************************************
+ * Detect what (if any) proxy to use
+ *************************************************************/
+ if(!conn->bits.httpproxy) {
+ /* If proxy was not specified, we check for default proxy environment
+ * variables, to enable i.e Lynx compliance:
+ *
+ * http_proxy=http://some.server.dom:port/
+ * https_proxy=http://some.server.dom:port/
+ * ftp_proxy=http://some.server.dom:port/
+ * no_proxy=domain1.dom,host.domain2.dom
+ * (a comma-separated list of hosts which should
+ * not be proxied, or an asterisk to override
+ * all proxy variables)
+ * all_proxy=http://some.server.dom:port/
+ * (seems to exist for the CERN www lib. Probably
+ * the first to check for.)
+ *
+ * For compatibility, the all-uppercase versions of these variables are
+ * checked if the lowercase versions don't exist.
+ */
+ char *no_proxy=NULL;
+ char *no_proxy_tok_buf;
+ char proxy_env[128];
+
+ no_proxy=curl_getenv("no_proxy");
+ if(!no_proxy)
+ no_proxy=curl_getenv("NO_PROXY");
+
+ if(!no_proxy || !strequal("*", no_proxy)) {
+ /* NO_PROXY wasn't specified or it wasn't just an asterisk */
+ char *nope;
+
+ nope=no_proxy?strtok_r(no_proxy, ", ", &no_proxy_tok_buf):NULL;
+ while(nope) {
+ size_t namelen;
+ char *endptr = strchr(conn->host.name, ':');
+ if(endptr)
+ namelen=endptr-conn->host.name;
+ else
+ namelen=strlen(conn->host.name);
+
+ if(strlen(nope) <= namelen) {
+ char *checkn=
+ conn->host.name + namelen - strlen(nope);
+ if(checkprefix(nope, checkn)) {
+ /* no proxy for this host! */
+ break;
+ }
+ }
+ nope=strtok_r(NULL, ", ", &no_proxy_tok_buf);
+ }
+ if(!nope) {
+ /* It was not listed as without proxy */
+ char *protop = conn->protostr;
+ char *envp = proxy_env;
+ char *prox;
+
+ /* Now, build <protocol>_proxy and check for such a one to use */
+ while(*protop)
+ *envp++ = (char)tolower((int)*protop++);
+
+ /* append _proxy */
+ strcpy(envp, "_proxy");
+
+ /* read the protocol proxy: */
+ prox=curl_getenv(proxy_env);
+
+ /*
+ * We don't try the uppercase version of HTTP_PROXY because of
+ * security reasons:
+ *
+ * When curl is used in a webserver application
+ * environment (cgi or php), this environment variable can
+ * be controlled by the web server user by setting the
+ * http header 'Proxy:' to some value.
+ *
+ * This can cause 'internal' http/ftp requests to be
+ * arbitrarily redirected by any external attacker.
+ */
+ if(!prox && !strequal("http_proxy", proxy_env)) {
+ /* There was no lowercase variable, try the uppercase version: */
+ for(envp = proxy_env; *envp; envp++)
+ *envp = (char)toupper((int)*envp);
+ prox=curl_getenv(proxy_env);
+ }
+
+ if(prox && *prox) { /* don't count "" strings */
+ proxy = prox; /* use this */
+ }
+ else {
+ proxy = curl_getenv("all_proxy"); /* default proxy to use */
+ if(!proxy)
+ proxy=curl_getenv("ALL_PROXY");
+ }
+
+ if(proxy && *proxy) {
+ long bits = conn->protocol & (PROT_HTTPS|PROT_SSL|PROT_MISSING);
+ /* force this to become HTTP */
+ conn->protocol = PROT_HTTP | bits;
+
+ proxy_alloc=TRUE; /* this needs to be freed later */
+ conn->bits.httpproxy = TRUE;
+ }
+ } /* if (!nope) - it wasn't specified non-proxy */
+ } /* NO_PROXY wasn't specified or '*' */
+ if(no_proxy)
+ free(no_proxy);
+ } /* if not using proxy */
+#endif /* CURL_DISABLE_HTTP */
+
+ /*************************************************************
+ * No protocol part in URL was used, add it!
+ *************************************************************/
+ if(conn->protocol&PROT_MISSING) {
+ /* We're guessing prefixes here and if we're told to use a proxy or if
+ we're gonna follow a Location: later or... then we need the protocol
+ part added so that we have a valid URL. */
+ char *reurl;
+
+ reurl = aprintf("%s://%s", conn->protostr, data->change.url);
+
+ if(!reurl)
+ return CURLE_OUT_OF_MEMORY;
+
+ data->change.url = reurl;
+ data->change.url_alloc = TRUE; /* free this later */
+ conn->protocol &= ~PROT_MISSING; /* switch that one off again */
+ }
+
+#ifndef CURL_DISABLE_HTTP
+ /************************************************************
+ * RESUME on a HTTP page is a tricky business. First, let's just check that
+ * 'range' isn't used, then set the range parameter and leave the resume as
+ * it is to inform about this situation for later use. We will then
+ * "attempt" to resume, and if we're talking to a HTTP/1.1 (or later)
+ * server, we will get the document resumed. If we talk to a HTTP/1.0
+ * server, we just fail since we can't rewind the file writing from within
+ * this function.
+ ***********************************************************/
+ if(data->reqdata.resume_from) {
+ if(!data->reqdata.use_range) {
+ /* if it already was in use, we just skip this */
+ data->reqdata.range = aprintf("%" FORMAT_OFF_T "-", data->reqdata.resume_from);
+ if(!data->reqdata.range)
+ return CURLE_OUT_OF_MEMORY;
+ data->reqdata.rangestringalloc = TRUE; /* mark as allocated */
+ data->reqdata.use_range = 1; /* switch on range usage */
+ }
+ }
+#endif
+ /*************************************************************
+ * Setup internals depending on protocol
+ *************************************************************/
+
+ conn->socktype = SOCK_STREAM; /* most of them are TCP streams */
+
+ if (strequal(conn->protostr, "HTTP")) {
+#ifndef CURL_DISABLE_HTTP
+ conn->port = PORT_HTTP;
+ conn->remote_port = PORT_HTTP;
+ conn->protocol |= PROT_HTTP;
+ conn->curl_do = Curl_http;
+ conn->curl_do_more = (Curl_do_more_func)ZERO_NULL;
+ conn->curl_done = Curl_http_done;
+ conn->curl_connect = Curl_http_connect;
+#else
+ failf(data, LIBCURL_NAME
+ " was built with HTTP disabled, http: not supported!");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+#endif
+ }
+ else if (strequal(conn->protostr, "HTTPS")) {
+#if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
+
+ conn->port = PORT_HTTPS;
+ conn->remote_port = PORT_HTTPS;
+ conn->protocol |= PROT_HTTP|PROT_HTTPS|PROT_SSL;
+
+ conn->curl_do = Curl_http;
+ conn->curl_do_more = (Curl_do_more_func)ZERO_NULL;
+ conn->curl_done = Curl_http_done;
+ conn->curl_connect = Curl_http_connect;
+ conn->curl_connecting = Curl_https_connecting;
+ conn->curl_proto_getsock = Curl_https_getsock;
+
+#else /* USE_SSL */
+ failf(data, LIBCURL_NAME
+ " was built with SSL disabled, https: not supported!");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+#endif /* !USE_SSL */
+ }
+ else if(strequal(conn->protostr, "FTP") ||
+ strequal(conn->protostr, "FTPS")) {
+
+#ifndef CURL_DISABLE_FTP
+ char *type;
+ int port = PORT_FTP;
+
+ if(strequal(conn->protostr, "FTPS")) {
+#ifdef USE_SSL
+ conn->protocol |= PROT_FTPS|PROT_SSL;
+ conn->ssl[SECONDARYSOCKET].use = TRUE; /* send data securely */
+ port = PORT_FTPS;
+#else
+ failf(data, LIBCURL_NAME
+ " was built with SSL disabled, ftps: not supported!");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+#endif /* !USE_SSL */
+ }
+
+ conn->port = port;
+ conn->remote_port = (unsigned short)port;
+ conn->protocol |= PROT_FTP;
+
+ if(proxy && *proxy && !data->set.tunnel_thru_httpproxy) {
+ /* Unless we have asked to tunnel ftp operations through the proxy, we
+ switch and use HTTP operations only */
+#ifndef CURL_DISABLE_HTTP
+ conn->curl_do = Curl_http;
+ conn->curl_done = Curl_http_done;
+ conn->protocol = PROT_HTTP; /* switch to HTTP */
+#else
+ failf(data, "FTP over http proxy requires HTTP support built-in!");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+#endif
+ }
+ else {
+ conn->curl_do = Curl_ftp;
+ conn->curl_do_more = Curl_ftp_nextconnect;
+ conn->curl_done = Curl_ftp_done;
+ conn->curl_connect = Curl_ftp_connect;
+ conn->curl_connecting = Curl_ftp_multi_statemach;
+ conn->curl_doing = Curl_ftp_doing;
+ conn->curl_proto_getsock = Curl_ftp_getsock;
+ conn->curl_doing_getsock = Curl_ftp_getsock;
+ conn->curl_disconnect = Curl_ftp_disconnect;
+ }
+
+ data->reqdata.path++; /* don't include the initial slash */
+
+ /* FTP URLs support an extension like ";type=<typecode>" that
+ * we'll try to get now! */
+ type=strstr(data->reqdata.path, ";type=");
+ if(!type) {
+ type=strstr(conn->host.rawalloc, ";type=");
+ }
+ if(type) {
+ char command;
+ *type=0; /* it was in the middle of the hostname */
+ command = (char)toupper((int)type[6]);
+ switch(command) {
+ case 'A': /* ASCII mode */
+ data->set.prefer_ascii = TRUE;
+ break;
+ case 'D': /* directory mode */
+ data->set.ftp_list_only = TRUE;
+ break;
+ case 'I': /* binary mode */
+ default:
+ /* switch off ASCII */
+ data->set.prefer_ascii = FALSE;
+ break;
+ }
+ }
+#else /* CURL_DISABLE_FTP */
+ failf(data, LIBCURL_NAME
+ " was built with FTP disabled, ftp/ftps: not supported!");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+#endif
+ }
+ else if(strequal(conn->protostr, "TELNET")) {
+#ifndef CURL_DISABLE_TELNET
+ /* telnet testing factory */
+ conn->protocol |= PROT_TELNET;
+
+ conn->port = PORT_TELNET;
+ conn->remote_port = PORT_TELNET;
+ conn->curl_do = Curl_telnet;
+ conn->curl_done = Curl_telnet_done;
+#else
+ failf(data, LIBCURL_NAME
+ " was built with TELNET disabled!");
+#endif
+ }
+ else if (strequal(conn->protostr, "DICT")) {
+#ifndef CURL_DISABLE_DICT
+ conn->protocol |= PROT_DICT;
+ conn->port = PORT_DICT;
+ conn->remote_port = PORT_DICT;
+ conn->curl_do = Curl_dict;
+ /* no DICT-specific done */
+ conn->curl_done = (Curl_done_func)ZERO_NULL;
+#else
+ failf(data, LIBCURL_NAME
+ " was built with DICT disabled!");
+#endif
+ }
+ else if (strequal(conn->protostr, "LDAP")) {
+#ifndef CURL_DISABLE_LDAP
+ conn->protocol |= PROT_LDAP;
+ conn->port = PORT_LDAP;
+ conn->remote_port = PORT_LDAP;
+ conn->curl_do = Curl_ldap;
+ /* no LDAP-specific done */
+ conn->curl_done = (Curl_done_func)ZERO_NULL;
+#else
+ failf(data, LIBCURL_NAME
+ " was built with LDAP disabled!");
+#endif
+ }
+ else if (strequal(conn->protostr, "FILE")) {
+#ifndef CURL_DISABLE_FILE
+ conn->protocol |= PROT_FILE;
+
+ conn->curl_do = Curl_file;
+ conn->curl_done = Curl_file_done;
+
+ /* anyway, this is supposed to be the connect function so we better
+ at least check that the file is present here! */
+ result = Curl_file_connect(conn);
+
+ /* Setup a "faked" transfer that'll do nothing */
+ if(CURLE_OK == result) {
+ conn->data = data;
+ conn->bits.tcpconnect = TRUE; /* we are "connected */
+ ConnectionStore(data, conn);
+
+ result = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, /* no download */
+ -1, NULL); /* no upload */
+ }
+
+ return result;
+#else
+ failf(data, LIBCURL_NAME
+ " was built with FILE disabled!");
+#endif
+ }
+ else if (strequal(conn->protostr, "TFTP")) {
+#ifndef CURL_DISABLE_TFTP
+ char *type;
+ conn->socktype = SOCK_DGRAM; /* UDP datagram based */
+ conn->protocol |= PROT_TFTP;
+ conn->port = PORT_TFTP;
+ conn->remote_port = PORT_TFTP;
+ conn->curl_connect = Curl_tftp_connect;
+ conn->curl_do = Curl_tftp;
+ conn->curl_done = Curl_tftp_done;
+ /* TFTP URLs support an extension like ";mode=<typecode>" that
+ * we'll try to get now! */
+ type=strstr(data->reqdata.path, ";mode=");
+ if(!type) {
+ type=strstr(conn->host.rawalloc, ";mode=");
+ }
+ if(type) {
+ char command;
+ *type=0; /* it was in the middle of the hostname */
+ command = (char)toupper((int)type[6]);
+ switch(command) {
+ case 'A': /* ASCII mode */
+ case 'N': /* NETASCII mode */
+ data->set.prefer_ascii = TRUE;
+ break;
+ case 'O': /* octet mode */
+ case 'I': /* binary mode */
+ default:
+ /* switch off ASCII */
+ data->set.prefer_ascii = FALSE;
+ break;
+ }
+ }
+#else
+ failf(data, LIBCURL_NAME
+ " was built with TFTP disabled!");
+#endif
+ }
+ else if (strequal(conn->protostr, "SCP")) {
+#ifdef USE_LIBSSH2
+ conn->port = PORT_SSH;
+ conn->remote_port = PORT_SSH;
+ conn->protocol = PROT_SCP;
+ conn->curl_connect = Curl_ssh_connect; /* ssh_connect? */
+ conn->curl_do = Curl_scp_do;
+ conn->curl_done = Curl_scp_done;
+ conn->curl_do_more = (Curl_do_more_func)ZERO_NULL;
+#else
+ failf(data, LIBCURL_NAME
+ " was built without LIBSSH2, scp: not supported!");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+#endif
+ }
+ else if (strequal(conn->protostr, "SFTP")) {
+#ifdef USE_LIBSSH2
+ conn->port = PORT_SSH;
+ conn->remote_port = PORT_SSH;
+ conn->protocol = PROT_SFTP;
+ conn->curl_connect = Curl_ssh_connect; /* ssh_connect? */
+ conn->curl_do = Curl_sftp_do;
+ conn->curl_done = Curl_sftp_done;
+ conn->curl_do_more = (Curl_do_more_func)NULL;
+#else
+ failf(data, LIBCURL_NAME
+ " was built without LIBSSH2, scp: not supported!");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+#endif
+}
+else {
+ /* We fell through all checks and thus we don't support the specified
+ protocol */
+ failf(data, "Unsupported protocol: %s", conn->protostr);
+ return CURLE_UNSUPPORTED_PROTOCOL;
+ }
+
+ if(proxy && *proxy) {
+ /* If this is supposed to use a proxy, we need to figure out the proxy
+ host name name, so that we can re-use an existing connection
+ that may exist registered to the same proxy host. */
+
+ char *prox_portno;
+ char *endofprot;
+
+ /* We need to make a duplicate of the proxy so that we can modify the
+ string safely. If 'proxy_alloc' is TRUE, the string is already
+ allocated and we can treat it as duplicated. */
+ char *proxydup=proxy_alloc?proxy:strdup(proxy);
+
+ /* We use 'proxyptr' to point to the proxy name from now on... */
+ char *proxyptr=proxydup;
+ char *portptr;
+ char *atsign;
+
+ if(NULL == proxydup) {
+ failf(data, "memory shortage");
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ /* We do the proxy host string parsing here. We want the host name and the
+ * port name. Accept a protocol:// prefix, even though it should just be
+ * ignored.
+ */
+
+ /* Skip the protocol part if present */
+ endofprot=strstr(proxyptr, "://");
+ if(endofprot)
+ proxyptr = endofprot+3;
+
+ /* Is there a username and password given in this proxy url? */
+ atsign = strchr(proxyptr, '@');
+ if(atsign) {
+ char proxyuser[MAX_CURL_USER_LENGTH];
+ char proxypasswd[MAX_CURL_PASSWORD_LENGTH];
+ proxypasswd[0] = 0;
+
+ if(1 <= sscanf(proxyptr,
+ "%" MAX_CURL_USER_LENGTH_TXT"[^:]:"
+ "%" MAX_CURL_PASSWORD_LENGTH_TXT "[^@]",
+ proxyuser, proxypasswd)) {
+ CURLcode res = CURLE_OK;
+
+ /* found user and password, rip them out. note that we are
+ unescaping them, as there is otherwise no way to have a
+ username or password with reserved characters like ':' in
+ them. */
+ Curl_safefree(conn->proxyuser);
+ conn->proxyuser = curl_easy_unescape(data, proxyuser, 0, NULL);
+
+ if(!conn->proxyuser)
+ res = CURLE_OUT_OF_MEMORY;
+ else {
+ Curl_safefree(conn->proxypasswd);
+ conn->proxypasswd = curl_easy_unescape(data, proxypasswd, 0, NULL);
+
+ if(!conn->proxypasswd)
+ res = CURLE_OUT_OF_MEMORY;
+ }
+
+ if(CURLE_OK == res) {
+ conn->bits.proxy_user_passwd = TRUE; /* enable it */
+ atsign = strdup(atsign+1); /* the right side of the @-letter */
+
+ if(atsign) {
+ free(proxydup); /* free the former proxy string */
+ proxydup = proxyptr = atsign; /* now use this instead */
+ }
+ else
+ res = CURLE_OUT_OF_MEMORY;
+ }
+
+ if(res) {
+ free(proxydup); /* free the allocated proxy string */
+ return res;
+ }
+ }
+ }
+
+ /* start scanning for port number at this point */
+ portptr = proxyptr;
+
+ /* detect and extract RFC2732-style IPv6-addresses */
+ if(*proxyptr == '[') {
+ char *ptr = ++proxyptr; /* advance beyond the initial bracket */
+ while(*ptr && (ISXDIGIT(*ptr) || (*ptr == ':')))
+ ptr++;
+ if(*ptr == ']') {
+ /* yeps, it ended nicely with a bracket as well */
+ *ptr = 0;
+ portptr = ptr+1;
+ }
+ /* Note that if this didn't end with a bracket, we still advanced the
+ * proxyptr first, but I can't see anything wrong with that as no host
+ * name nor a numeric can legally start with a bracket.
+ */
+ }
+
+ /* Get port number off proxy.server.com:1080 */
+ prox_portno = strchr(portptr, ':');
+ if (prox_portno) {
+ *prox_portno = 0x0; /* cut off number from host name */
+ prox_portno ++;
+ /* now set the local port number */
+ conn->port = atoi(prox_portno);
+ }
+ else if(data->set.proxyport) {
+ /* None given in the proxy string, then get the default one if it is
+ given */
+ conn->port = data->set.proxyport;
+ }
+
+ /* now, clone the cleaned proxy host name */
+ conn->proxy.rawalloc = strdup(proxyptr);
+ conn->proxy.name = conn->proxy.rawalloc;
+
+ free(proxydup); /* free the duplicate pointer and not the modified */
+ proxy = NULL; /* this may have just been freed */
+ if(!conn->proxy.rawalloc)
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ /*************************************************************
+ * If the protocol is using SSL and HTTP proxy is used, we set
+ * the tunnel_proxy bit.
+ *************************************************************/
+ if((conn->protocol&PROT_SSL) && conn->bits.httpproxy)
+ conn->bits.tunnel_proxy = TRUE;
+
+ /*************************************************************
+ * Take care of user and password authentication stuff
+ *************************************************************/
+
+ /*
+ * Inputs: data->set.userpwd (CURLOPT_USERPWD)
+ * data->set.fpasswd (CURLOPT_PASSWDFUNCTION)
+ * data->set.use_netrc (CURLOPT_NETRC)
+ * conn->host.name
+ * netrc file
+ * hard-coded defaults
+ *
+ * Outputs: (almost :- all currently undefined)
+ * conn->bits.user_passwd - non-zero if non-default passwords exist
+ * conn->user - non-zero length if defined
+ * conn->passwd - ditto
+ * conn->host.name - remove user name and password
+ */
+
+ /* At this point, we're hoping all the other special cases have
+ * been taken care of, so conn->host.name is at most
+ * [user[:password]]@]hostname
+ *
+ * We need somewhere to put the embedded details, so do that first.
+ */
+
+ user[0] =0; /* to make everything well-defined */
+ passwd[0]=0;
+
+ if (conn->protocol & (PROT_FTP|PROT_HTTP|PROT_SCP|PROT_SFTP)) {
+ /* This is a FTP, HTTP, SCP or SFTP URL, we will now try to extract the
+ * possible user+password pair in a string like:
+ * ftp://user:password@ftp.my.site:8021/README */
+ char *ptr=strchr(conn->host.name, '@');
+ char *userpass = conn->host.name;
+ if(ptr != NULL) {
+ /* there's a user+password given here, to the left of the @ */
+
+ conn->host.name = ++ptr;
+
+ /* So the hostname is sane. Only bother interpreting the
+ * results if we could care. It could still be wasted
+ * work because it might be overtaken by the programmatically
+ * set user/passwd, but doing that first adds more cases here :-(
+ */
+
+ if (data->set.use_netrc != CURL_NETRC_REQUIRED) {
+ /* We could use the one in the URL */
+
+ conn->bits.user_passwd = 1; /* enable user+password */
+
+ if(*userpass != ':') {
+ /* the name is given, get user+password */
+ sscanf(userpass, "%" MAX_CURL_USER_LENGTH_TXT "[^:@]:"
+ "%" MAX_CURL_PASSWORD_LENGTH_TXT "[^@]",
+ user, passwd);
+ }
+ else
+ /* no name given, get the password only */
+ sscanf(userpass, ":%" MAX_CURL_PASSWORD_LENGTH_TXT "[^@]", passwd);
+
+ if(user[0]) {
+ char *newname=curl_easy_unescape(data, user, 0, NULL);
+ if(!newname)
+ return CURLE_OUT_OF_MEMORY;
+ if(strlen(newname) < sizeof(user))
+ strcpy(user, newname);
+
+ /* if the new name is longer than accepted, then just use
+ the unconverted name, it'll be wrong but what the heck */
+ free(newname);
+ }
+ if (passwd[0]) {
+ /* we have a password found in the URL, decode it! */
+ char *newpasswd=curl_easy_unescape(data, passwd, 0, NULL);
+ if(!newpasswd)
+ return CURLE_OUT_OF_MEMORY;
+ if(strlen(newpasswd) < sizeof(passwd))
+ strcpy(passwd, newpasswd);
+
+ free(newpasswd);
+ }
+ }
+ }
+ }
+
+ /*************************************************************
+ * Figure out the remote port number
+ *
+ * No matter if we use a proxy or not, we have to figure out the remote
+ * port number of various reasons.
+ *
+ * To be able to detect port number flawlessly, we must not confuse them
+ * IPv6-specified addresses in the [0::1] style. (RFC2732)
+ *
+ * The conn->host.name is currently [user:passwd@]host[:port] where host
+ * could be a hostname, IPv4 address or IPv6 address.
+ *************************************************************/
+ if((1 == sscanf(conn->host.name, "[%*39[0-9a-fA-F:.]%c", &endbracket)) &&
+ (']' == endbracket)) {
+ /* this is a RFC2732-style specified IP-address */
+ conn->bits.ipv6_ip = TRUE;
+
+ conn->host.name++; /* pass the starting bracket */
+ tmp = strchr(conn->host.name, ']');
+ *tmp = 0; /* zero terminate */
+ tmp++; /* pass the ending bracket */
+ if(':' != *tmp)
+ tmp = NULL; /* no port number available */
+ }
+ else
+ tmp = strrchr(conn->host.name, ':');
+
+ if(data->set.use_port && data->state.allow_port) {
+ /* if set, we use this and ignore the port possibly given in the URL */
+ conn->remote_port = (unsigned short)data->set.use_port;
+ if(tmp)
+ *tmp = '\0'; /* cut off the name there anyway - if there was a port
+ number - since the port number is to be ignored! */
+ if(conn->bits.httpproxy) {
+ /* we need to create new URL with the new port number */
+ char *url;
+
+ url = aprintf("http://%s:%d%s", conn->host.name, conn->remote_port,
+ data->reqdata.path);
+ if(!url)
+ return CURLE_OUT_OF_MEMORY;
+
+ if(data->change.url_alloc)
+ free(data->change.url);
+
+ data->change.url = url;
+ data->change.url_alloc = TRUE;
+ }
+ }
+ else if (tmp) {
+ /* no CURLOPT_PORT given, extract the one from the URL */
+
+ char *rest;
+ unsigned long port;
+
+ port=strtoul(tmp+1, &rest, 10); /* Port number must be decimal */
+
+ if (rest != (tmp+1) && *rest == '\0') {
+ /* The colon really did have only digits after it,
+ * so it is either a port number or a mistake */
+
+ if (port > 0xffff) { /* Single unix standard says port numbers are
+ * 16 bits long */
+ failf(data, "Port number too large: %lu", port);
+ return CURLE_URL_MALFORMAT;
+ }
+
+ *tmp = '\0'; /* cut off the name there */
+ conn->remote_port = (unsigned short)port;
+ }
+ }
+
+ /* Programmatically set password:
+ * - always applies, if available
+ * - takes precedence over the values we just set above
+ * so scribble it over the top.
+ * User-supplied passwords are assumed not to need unescaping.
+ *
+ * user_password is set in "inherit initial knowledge' above,
+ * so it doesn't have to be set in this block
+ */
+ if (data->set.userpwd != NULL) {
+ /* the name is given, get user+password */
+ sscanf(data->set.userpwd,
+ "%" MAX_CURL_USER_LENGTH_TXT "[^:]:"
+ "%" MAX_CURL_PASSWORD_LENGTH_TXT "[^\n]",
+ user, passwd);
+ }
+
+ conn->bits.netrc = FALSE;
+ if (data->set.use_netrc != CURL_NETRC_IGNORED) {
+ if(Curl_parsenetrc(conn->host.name,
+ user, passwd,
+ data->set.netrc_file)) {
+ infof(data, "Couldn't find host %s in the " DOT_CHAR
+ "netrc file, using defaults\n",
+ conn->host.name);
+ }
+ else {
+ /* set bits.netrc TRUE to remember that we got the name from a .netrc
+ file, so that it is safe to use even if we followed a Location: to a
+ different host or similar. */
+ conn->bits.netrc = TRUE;
+
+ conn->bits.user_passwd = 1; /* enable user+password */
+ }
+ }
+
+ /* If our protocol needs a password and we have none, use the defaults */
+ if ( (conn->protocol & PROT_FTP) &&
+ !conn->bits.user_passwd) {
+
+ conn->user = strdup(CURL_DEFAULT_USER);
+ conn->passwd = strdup(CURL_DEFAULT_PASSWORD);
+ /* This is the default password, so DON'T set conn->bits.user_passwd */
+ }
+ else {
+ /* store user + password, zero-length if not set */
+ conn->user = strdup(user);
+ conn->passwd = strdup(passwd);
+ }
+ if(!conn->user || !conn->passwd)
+ return CURLE_OUT_OF_MEMORY;
+
+ /*************************************************************
+ * Check the current list of connections to see if we can
+ * re-use an already existing one or if we have to create a
+ * new one.
+ *************************************************************/
+
+ /* get a cloned copy of the SSL config situation stored in the
+ connection struct */
+ if(!Curl_clone_ssl_config(&data->set.ssl, &conn->ssl_config))
+ return CURLE_OUT_OF_MEMORY;
+
+ /* reuse_fresh is TRUE if we are told to use a new connection by force, but
+ we only acknowledge this option if this is not a re-used connection
+ already (which happens due to follow-location or during a HTTP
+ authentication phase). */
+ if(data->set.reuse_fresh && !data->state.this_is_a_follow)
+ reuse = FALSE;
+ else
+ reuse = ConnectionExists(data, conn, &conn_temp);
+
+ if(reuse) {
+ /*
+ * We already have a connection for this, we got the former connection
+ * in the conn_temp variable and thus we need to cleanup the one we
+ * just allocated before we can move along and use the previously
+ * existing one.
+ */
+ struct connectdata *old_conn = conn;
+
+ if(old_conn->proxy.rawalloc)
+ free(old_conn->proxy.rawalloc);
+
+ /* free the SSL config struct from this connection struct as this was
+ allocated in vain and is targeted for destruction */
+ Curl_free_ssl_config(&conn->ssl_config);
+
+ conn = conn_temp; /* use this connection from now on */
+
+ conn->data = old_conn->data;
+
+ /* get the user+password information from the old_conn struct since it may
+ * be new for this request even when we re-use an existing connection */
+ conn->bits.user_passwd = old_conn->bits.user_passwd;
+ if (conn->bits.user_passwd) {
+ /* use the new user namd and password though */
+ Curl_safefree(conn->user);
+ Curl_safefree(conn->passwd);
+ conn->user = old_conn->user;
+ conn->passwd = old_conn->passwd;
+ old_conn->user = NULL;
+ old_conn->passwd = NULL;
+ }
+
+ conn->bits.proxy_user_passwd = old_conn->bits.proxy_user_passwd;
+ if (conn->bits.proxy_user_passwd) {
+ /* use the new proxy user name and proxy password though */
+ Curl_safefree(conn->proxyuser);
+ Curl_safefree(conn->proxypasswd);
+ conn->proxyuser = old_conn->proxyuser;
+ conn->proxypasswd = old_conn->proxypasswd;
+ old_conn->proxyuser = NULL;
+ old_conn->proxypasswd = NULL;
+ }
+
+ /* host can change, when doing keepalive with a proxy ! */
+ if (conn->bits.httpproxy) {
+ free(conn->host.rawalloc);
+ conn->host=old_conn->host;
+ }
+
+ /* get the newly set value, not the old one */
+ conn->bits.no_body = old_conn->bits.no_body;
+
+ if (!conn->bits.httpproxy)
+ free(old_conn->host.rawalloc); /* free the newly allocated name buffer */
+
+ /* re-use init */
+ conn->bits.reuse = TRUE; /* yes, we're re-using here */
+ conn->bits.chunk = FALSE; /* always assume not chunked unless told
+ otherwise */
+
+ Curl_safefree(old_conn->user);
+ Curl_safefree(old_conn->passwd);
+ Curl_safefree(old_conn->proxyuser);
+ Curl_safefree(old_conn->proxypasswd);
+ Curl_llist_destroy(old_conn->send_pipe, NULL);
+ Curl_llist_destroy(old_conn->recv_pipe, NULL);
+
+ free(old_conn); /* we don't need this anymore */
+
+ /*
+ * If we're doing a resumed transfer, we need to setup our stuff
+ * properly.
+ */
+ data->reqdata.resume_from = data->set.set_resume_from;
+ if (data->reqdata.resume_from) {
+ if (data->reqdata.rangestringalloc == TRUE)
+ free(data->reqdata.range);
+ data->reqdata.range = aprintf("%" FORMAT_OFF_T "-",
+ data->reqdata.resume_from);
+ if(!data->reqdata.range)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* tell ourselves to fetch this range */
+ data->reqdata.use_range = TRUE; /* enable range download */
+ data->reqdata.rangestringalloc = TRUE; /* mark range string allocated */
+ }
+ else if (data->set.set_range) {
+ /* There is a range, but is not a resume, useful for random ftp access */
+ data->reqdata.range = strdup(data->set.set_range);
+ if(!data->reqdata.range)
+ return CURLE_OUT_OF_MEMORY;
+ data->reqdata.rangestringalloc = TRUE; /* mark range string allocated */
+ data->reqdata.use_range = TRUE; /* enable range download */
+ }
+ else
+ data->reqdata.use_range = FALSE; /* disable range download */
+
+ *in_connect = conn; /* return this instead! */
+
+ infof(data, "Re-using existing connection! (#%ld) with host %s\n",
+ conn->connectindex,
+ conn->bits.httpproxy?conn->proxy.dispname:conn->host.dispname);
+ }
+ else {
+ /*
+ * This is a brand new connection, so let's store it in the connection
+ * cache of ours!
+ */
+ ConnectionStore(data, conn);
+ }
+
+ /* Continue connectdata initialization here. */
+
+ /*
+ *
+ * Inherit the proper values from the urldata struct AFTER we have arranged
+ * the persistent connection stuff */
+ conn->fread = data->set.fread;
+ conn->fread_in = data->set.in;
+
+ if ((conn->protocol&PROT_HTTP) &&
+ data->set.upload &&
+ (data->set.infilesize == -1) &&
+ (data->set.httpversion != CURL_HTTP_VERSION_1_0)) {
+ /* HTTP, upload, unknown file size and not HTTP 1.0 */
+ conn->bits.upload_chunky = TRUE;
+ }
+ else {
+ /* else, no chunky upload */
+ conn->bits.upload_chunky = FALSE;
+ }
+
+#ifndef USE_ARES
+ /*************************************************************
+ * Set timeout if that is being used, and we're not using an asynchronous
+ * name resolve.
+ *************************************************************/
+ if((data->set.timeout || data->set.connecttimeout) && !data->set.no_signal) {
+ /*************************************************************
+ * Set signal handler to catch SIGALRM
+ * Store the old value to be able to set it back later!
+ *************************************************************/
+
+#ifdef SIGALRM
+#ifdef HAVE_ALARM
+ long shortest;
+#endif
+#ifdef HAVE_SIGACTION
+ struct sigaction sigact;
+ sigaction(SIGALRM, NULL, &sigact);
+ keep_sigact = sigact;
+ keep_copysig = TRUE; /* yes, we have a copy */
+ sigact.sa_handler = alarmfunc;
+#ifdef SA_RESTART
+ /* HPUX doesn't have SA_RESTART but defaults to that behaviour! */
+ sigact.sa_flags &= ~SA_RESTART;
+#endif
+ /* now set the new struct */
+ sigaction(SIGALRM, &sigact, NULL);
+#else /* HAVE_SIGACTION */
+ /* no sigaction(), revert to the much lamer signal() */
+#ifdef HAVE_SIGNAL
+ keep_sigact = signal(SIGALRM, alarmfunc);
+#endif
+#endif /* HAVE_SIGACTION */
+
+ /* We set the timeout on the name resolving phase first, separately from
+ * the download/upload part to allow a maximum time on everything. This is
+ * a signal-based timeout, why it won't work and shouldn't be used in
+ * multi-threaded environments. */
+
+#ifdef HAVE_ALARM
+ shortest = data->set.timeout; /* default to this timeout value */
+ if(shortest && data->set.connecttimeout &&
+ (data->set.connecttimeout < shortest))
+ /* if both are set, pick the shortest */
+ shortest = data->set.connecttimeout;
+ else if(!shortest)
+ /* if timeout is not set, use the connect timeout */
+ shortest = data->set.connecttimeout;
+
+ /* alarm() makes a signal get sent when the timeout fires off, and that
+ will abort system calls */
+ prev_alarm = alarm((unsigned int) shortest);
+ /* We can expect the conn->created time to be "now", as that was just
+ recently set in the beginning of this function and nothing slow
+ has been done since then until now. */
+#endif
+#endif /* SIGALRM */
+ }
+#endif /* USE_ARES */
+
+ /*************************************************************
+ * Resolve the name of the server or proxy
+ *************************************************************/
+ if(conn->bits.reuse) {
+ /* re-used connection, no resolving is necessary */
+ hostaddr = NULL;
+ /* we'll need to clear conn->dns_entry later in Curl_disconnect() */
+
+ if (conn->bits.httpproxy)
+ fix_hostname(data, conn, &conn->host);
+ }
+ else {
+ /* this is a fresh connect */
+
+ /* set a pointer to the hostname we display */
+ fix_hostname(data, conn, &conn->host);
+
+ if(!conn->proxy.name || !*conn->proxy.name) {
+ /* If not connecting via a proxy, extract the port from the URL, if it is
+ * there, thus overriding any defaults that might have been set above. */
+ conn->port = conn->remote_port; /* it is the same port */
+
+ /* Resolve target host right on */
+ rc = Curl_resolv(conn, conn->host.name, (int)conn->port, &hostaddr);
+ if(rc == CURLRESOLV_PENDING)
+ *async = TRUE;
+
+ else if(!hostaddr) {
+ failf(data, "Couldn't resolve host '%s'", conn->host.dispname);
+ result = CURLE_COULDNT_RESOLVE_HOST;
+ /* don't return yet, we need to clean up the timeout first */
+ }
+ }
+ else {
+ /* This is a proxy that hasn't been resolved yet. */
+
+ /* IDN-fix the proxy name */
+ fix_hostname(data, conn, &conn->proxy);
+
+ /* resolve proxy */
+ rc = Curl_resolv(conn, conn->proxy.name, (int)conn->port, &hostaddr);
+
+ if(rc == CURLRESOLV_PENDING)
+ *async = TRUE;
+
+ else if(!hostaddr) {
+ failf(data, "Couldn't resolve proxy '%s'", conn->proxy.dispname);
+ result = CURLE_COULDNT_RESOLVE_PROXY;
+ /* don't return yet, we need to clean up the timeout first */
+ }
+ }
+ }
+ *addr = hostaddr;
+
+#if defined(HAVE_ALARM) && defined(SIGALRM) && !defined(USE_ARES)
+ if((data->set.timeout || data->set.connecttimeout) && !data->set.no_signal) {
+#ifdef HAVE_SIGACTION
+ if(keep_copysig) {
+ /* we got a struct as it looked before, now put that one back nice
+ and clean */
+ sigaction(SIGALRM, &keep_sigact, NULL); /* put it back */
+ }
+#else
+#ifdef HAVE_SIGNAL
+ /* restore the previous SIGALRM handler */
+ signal(SIGALRM, keep_sigact);
+#endif
+#endif /* HAVE_SIGACTION */
+
+ /* switch back the alarm() to either zero or to what it was before minus
+ the time we spent until now! */
+ if(prev_alarm) {
+ /* there was an alarm() set before us, now put it back */
+ unsigned long elapsed_ms = Curl_tvdiff(Curl_tvnow(), conn->created);
+ unsigned long alarm_set;
+
+ /* the alarm period is counted in even number of seconds */
+ alarm_set = prev_alarm - elapsed_ms/1000;
+
+ if(!alarm_set ||
+ ((alarm_set >= 0x80000000) && (prev_alarm < 0x80000000)) ) {
+ /* if the alarm time-left reached zero or turned "negative" (counted
+ with unsigned values), we should fire off a SIGALRM here, but we
+ won't, and zero would be to switch it off so we never set it to
+ less than 1! */
+ alarm(1);
+ result = CURLE_OPERATION_TIMEOUTED;
+ failf(data, "Previous alarm fired off!");
+ }
+ else
+ alarm((unsigned int)alarm_set);
+ }
+ else
+ alarm(0); /* just shut it off */
+ }
+#endif
+
+ return result;
+}
+
+/* SetupConnection() is called after the name resolve initiated in
+ * CreateConnection() is all done.
+ *
+ * NOTE: the argument 'hostaddr' is NULL when this function is called for a
+ * re-used connection.
+ *
+ * conn->data MUST already have been setup fine (in CreateConnection)
+ */
+
+static CURLcode SetupConnection(struct connectdata *conn,
+ struct Curl_dns_entry *hostaddr,
+ bool *protocol_done)
+{
+ CURLcode result=CURLE_OK;
+ struct SessionHandle *data = conn->data;
+
+ Curl_pgrsTime(data, TIMER_NAMELOOKUP);
+
+ if(conn->protocol & PROT_FILE) {
+ /* There's nothing in this function to setup if we're only doing
+ a file:// transfer */
+ *protocol_done = TRUE;
+ return result;
+ }
+ *protocol_done = FALSE; /* default to not done */
+
+ /*************************************************************
+ * Send user-agent to HTTP proxies even if the target protocol
+ * isn't HTTP.
+ *************************************************************/
+ if((conn->protocol&PROT_HTTP) || conn->bits.httpproxy) {
+ if(data->set.useragent) {
+ Curl_safefree(conn->allocptr.uagent);
+ conn->allocptr.uagent =
+ aprintf("User-Agent: %s\r\n", data->set.useragent);
+ if(!conn->allocptr.uagent)
+ return CURLE_OUT_OF_MEMORY;
+ }
+ }
+
+ conn->headerbytecount = 0;
+
+#ifdef CURL_DO_LINEEND_CONV
+ data->state.crlf_conversions = 0; /* reset CRLF conversion counter */
+#endif /* CURL_DO_LINEEND_CONV */
+
+ for(;;) {
+ /* loop for CURL_SERVER_CLOSED_CONNECTION */
+
+ if(CURL_SOCKET_BAD == conn->sock[FIRSTSOCKET]) {
+ bool connected = FALSE;
+
+ /* Connect only if not already connected! */
+ result = ConnectPlease(data, conn, hostaddr, &connected);
+
+ if(connected) {
+ result = Curl_protocol_connect(conn, protocol_done);
+ if(CURLE_OK == result)
+ conn->bits.tcpconnect = TRUE;
+ }
+ else
+ conn->bits.tcpconnect = FALSE;
+
+ /* if the connection was closed by the server while exchanging
+ authentication information, retry with the new set
+ authentication information */
+ if(conn->bits.proxy_connect_closed) {
+ /* reset the error buffer */
+ if (data->set.errorbuffer)
+ data->set.errorbuffer[0] = '\0';
+ data->state.errorbuf = FALSE;
+ continue;
+ }
+
+ if(CURLE_OK != result)
+ return result;
+ }
+ else {
+ Curl_pgrsTime(data, TIMER_CONNECT); /* we're connected already */
+ conn->bits.tcpconnect = TRUE;
+ *protocol_done = TRUE;
+ if(data->set.verbose)
+ verboseconnect(conn);
+ }
+ /* Stop the loop now */
+ break;
+ }
+
+ conn->now = Curl_tvnow(); /* time this *after* the connect is done, we
+ set this here perhaps a second time */
+
+#ifdef __EMX__
+ /* 20000330 mgs
+ * the check is quite a hack...
+ * we're calling _fsetmode to fix the problem with fwrite converting newline
+ * characters (you get mangled text files, and corrupted binary files when
+ * you download to stdout and redirect it to a file). */
+
+ if ((data->set.out)->_handle == NULL) {
+ _fsetmode(stdout, "b");
+ }
+#endif
+
+ return CURLE_OK;
+}
+
+CURLcode Curl_connect(struct SessionHandle *data,
+ struct connectdata **in_connect,
+ bool *asyncp,
+ bool *protocol_done)
+{
+ CURLcode code;
+ struct Curl_dns_entry *dns;
+
+ *asyncp = FALSE; /* assume synchronous resolves by default */
+
+ /* call the stuff that needs to be called */
+ code = CreateConnection(data, in_connect, &dns, asyncp);
+
+ if(CURLE_OK == code) {
+ /* no error */
+ if(dns || !*asyncp)
+ /* If an address is available it means that we already have the name
+ resolved, OR it isn't async. if this is a re-used connection 'dns'
+ will be NULL here. Continue connecting from here */
+ code = SetupConnection(*in_connect, dns, protocol_done);
+ /* else
+ response will be received and treated async wise */
+ }
+
+ if(CURLE_OK != code) {
+ /* We're not allowed to return failure with memory left allocated
+ in the connectdata struct, free those here */
+ if(*in_connect) {
+ Curl_disconnect(*in_connect); /* close the connection */
+ *in_connect = NULL; /* return a NULL */
+ }
+ }
+ else {
+ if ((*in_connect)->is_in_pipeline)
+ data->state.is_in_pipeline = TRUE;
+ }
+
+ return code;
+}
+
+/* Call this function after Curl_connect() has returned async=TRUE and
+ then a successful name resolve has been received.
+
+ Note: this function disconnects and frees the conn data in case of
+ resolve failure */
+CURLcode Curl_async_resolved(struct connectdata *conn,
+ bool *protocol_done)
+{
+#if defined(USE_ARES) || defined(USE_THREADING_GETHOSTBYNAME) || \
+ defined(USE_THREADING_GETADDRINFO)
+ CURLcode code = SetupConnection(conn, conn->async.dns, protocol_done);
+
+ if(code)
+ /* We're not allowed to return failure with memory left allocated
+ in the connectdata struct, free those here */
+ Curl_disconnect(conn); /* close the connection */
+
+ return code;
+#else
+ (void)conn;
+ (void)protocol_done;
+ return CURLE_OK;
+#endif
+}
+
+
+CURLcode Curl_done(struct connectdata **connp,
+ CURLcode status, bool premature) /* an error if this is called after an
+ error was detected */
+{
+ CURLcode result;
+ struct connectdata *conn = *connp;
+ struct SessionHandle *data = conn->data;
+
+ Curl_expire(data, 0); /* stop timer */
+
+ if(conn->bits.done)
+ return CURLE_OK; /* Curl_done() has already been called */
+
+ conn->bits.done = TRUE; /* called just now! */
+
+ if(Curl_removeHandleFromPipeline(data, conn->recv_pipe) &&
+ conn->readchannel_inuse)
+ conn->readchannel_inuse = FALSE;
+ if(Curl_removeHandleFromPipeline(data, conn->send_pipe) &&
+ conn->writechannel_inuse)
+ conn->writechannel_inuse = FALSE;
+
+ /* cleanups done even if the connection is re-used */
+ if(data->reqdata.rangestringalloc) {
+ free(data->reqdata.range);
+ data->reqdata.rangestringalloc = FALSE;
+ }
+
+ /* Cleanup possible redirect junk */
+ if(data->reqdata.newurl) {
+ free(data->reqdata.newurl);
+ data->reqdata.newurl = NULL;
+ }
+
+ if(conn->dns_entry) {
+ Curl_resolv_unlock(data, conn->dns_entry); /* done with this */
+ conn->dns_entry = NULL;
+ }
+
+ /* this calls the protocol-specific function pointer previously set */
+ if(conn->curl_done)
+ result = conn->curl_done(conn, status, premature);
+ else
+ result = CURLE_OK;
+
+ Curl_pgrsDone(conn); /* done with the operation */
+
+ /* for ares-using, make sure all possible outstanding requests are properly
+ cancelled before we proceed */
+ ares_cancel(data->state.areschannel);
+
+ /* if data->set.reuse_forbid is TRUE, it means the libcurl client has
+ forced us to close this no matter what we think.
+
+ if conn->bits.close is TRUE, it means that the connection should be
+ closed in spite of all our efforts to be nice, due to protocol
+ restrictions in our or the server's end */
+ if(data->set.reuse_forbid || conn->bits.close) {
+ CURLcode res2 = Curl_disconnect(conn); /* close the connection */
+
+ *connp = NULL; /* to make the caller of this function better detect that
+ this was actually killed here */
+
+ /* If we had an error already, make sure we return that one. But
+ if we got a new error, return that. */
+ if(!result && res2)
+ result = res2;
+ }
+ else {
+ ConnectionDone(conn); /* the connection is no longer in use */
+
+ /* remember the most recently used connection */
+ data->state.lastconnect = conn->connectindex;
+
+ infof(data, "Connection #%ld to host %s left intact\n",
+ conn->connectindex,
+ conn->bits.httpproxy?conn->proxy.dispname:conn->host.dispname);
+ }
+
+ return result;
+}
+
+CURLcode Curl_do(struct connectdata **connp, bool *done)
+{
+ CURLcode result=CURLE_OK;
+ struct connectdata *conn = *connp;
+ struct SessionHandle *data = conn->data;
+
+ conn->bits.done = FALSE; /* Curl_done() is not called yet */
+ conn->bits.do_more = FALSE; /* by default there's no curl_do_more() to use */
+
+ if(conn->curl_do) {
+ /* generic protocol-specific function pointer set in curl_connect() */
+ result = conn->curl_do(conn, done);
+
+ /* This was formerly done in transfer.c, but we better do it here */
+
+ if((CURLE_SEND_ERROR == result) && conn->bits.reuse) {
+ /* This was a re-use of a connection and we got a write error in the
+ * DO-phase. Then we DISCONNECT this connection and have another attempt
+ * to CONNECT and then DO again! The retry cannot possibly find another
+ * connection to re-use, since we only keep one possible connection for
+ * each. */
+
+ infof(data, "Re-used connection seems dead, get a new one\n");
+
+ conn->bits.close = TRUE; /* enforce close of this connection */
+ result = Curl_done(&conn, result, FALSE); /* we are so done with this */
+
+ /* conn may no longer be a good pointer */
+
+ /*
+ * According to bug report #1330310. We need to check for
+ * CURLE_SEND_ERROR here as well. I figure this could happen when the
+ * request failed on a FTP connection and thus Curl_done() itself tried
+ * to use the connection (again). Slight Lack of feedback in the report,
+ * but I don't think this extra check can do much harm.
+ */
+ if((CURLE_OK == result) || (CURLE_SEND_ERROR == result)) {
+ bool async;
+ bool protocol_done = TRUE;
+
+ /* Now, redo the connect and get a new connection */
+ result = Curl_connect(data, connp, &async, &protocol_done);
+ if(CURLE_OK == result) {
+ /* We have connected or sent away a name resolve query fine */
+
+ conn = *connp; /* setup conn to again point to something nice */
+ if(async) {
+ /* Now, if async is TRUE here, we need to wait for the name
+ to resolve */
+ result = Curl_wait_for_resolv(conn, NULL);
+ if(result)
+ return result;
+
+ /* Resolved, continue with the connection */
+ result = Curl_async_resolved(conn, &protocol_done);
+ if(result)
+ return result;
+ }
+
+ /* ... finally back to actually retry the DO phase */
+ result = conn->curl_do(conn, done);
+ }
+ }
+ }
+ }
+ return result;
+}
+
+CURLcode Curl_do_more(struct connectdata *conn)
+{
+ CURLcode result=CURLE_OK;
+
+ if(conn->curl_do_more)
+ result = conn->curl_do_more(conn);
+
+ return result;
+}
diff --git a/Utilities/cmcurl/url.h b/Utilities/cmcurl/url.h
new file mode 100644
index 0000000000..446b3d91a4
--- /dev/null
+++ b/Utilities/cmcurl/url.h
@@ -0,0 +1,85 @@
+#ifndef __URL_H
+#define __URL_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include <stdarg.h> /* to make sure we have ap_list */
+
+/*
+ * Prototypes for library-wide functions provided by url.c
+ */
+
+CURLcode Curl_open(struct SessionHandle **curl);
+CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
+ va_list arg);
+CURLcode Curl_close(struct SessionHandle *data); /* opposite of curl_open() */
+CURLcode Curl_connect(struct SessionHandle *, struct connectdata **,
+ bool *async, bool *protocol_connect);
+CURLcode Curl_async_resolved(struct connectdata *conn,
+ bool *protocol_connect);
+CURLcode Curl_do(struct connectdata **, bool *done);
+CURLcode Curl_do_more(struct connectdata *);
+CURLcode Curl_done(struct connectdata **, CURLcode, bool premature);
+CURLcode Curl_disconnect(struct connectdata *);
+CURLcode Curl_protocol_connect(struct connectdata *conn, bool *done);
+CURLcode Curl_protocol_connecting(struct connectdata *conn, bool *done);
+CURLcode Curl_protocol_doing(struct connectdata *conn, bool *done);
+void Curl_safefree(void *ptr);
+
+/* create a connection cache */
+struct conncache *Curl_mk_connc(int type, int amount);
+/* free a connection cache */
+void Curl_rm_connc(struct conncache *c);
+/* Change number of entries of a connection cache */
+CURLcode Curl_ch_connc(struct SessionHandle *data,
+ struct conncache *c,
+ long newamount);
+
+int Curl_protocol_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks);
+int Curl_doing_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks);
+
+void Curl_addHandleToPipeline(struct SessionHandle *handle,
+ struct curl_llist *pipe);
+int Curl_removeHandleFromPipeline(struct SessionHandle *handle,
+ struct curl_llist *pipe);
+bool Curl_isHandleAtHead(struct SessionHandle *handle,
+ struct curl_llist *pipe);
+
+void Curl_close_connections(struct SessionHandle *data);
+
+#if 0
+CURLcode Curl_protocol_fdset(struct connectdata *conn,
+ fd_set *read_fd_set,
+ fd_set *write_fd_set,
+ int *max_fdp);
+CURLcode Curl_doing_fdset(struct connectdata *conn,
+ fd_set *read_fd_set,
+ fd_set *write_fd_set,
+ int *max_fdp);
+#endif
+
+#endif
diff --git a/Utilities/cmcurl/urldata.h b/Utilities/cmcurl/urldata.h
new file mode 100644
index 0000000000..46d956d1af
--- /dev/null
+++ b/Utilities/cmcurl/urldata.h
@@ -0,0 +1,1340 @@
+#ifndef __URLDATA_H
+#define __URLDATA_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+/* This file is for lib internal stuff */
+
+#include "setup.h"
+
+#define PORT_FTP 21
+#define PORT_FTPS 990
+#define PORT_TELNET 23
+#define PORT_HTTP 80
+#define PORT_HTTPS 443
+#define PORT_DICT 2628
+#define PORT_LDAP 389
+#define PORT_TFTP 69
+#define PORT_SSH 22
+
+#define DICT_MATCH "/MATCH:"
+#define DICT_MATCH2 "/M:"
+#define DICT_MATCH3 "/FIND:"
+#define DICT_DEFINE "/DEFINE:"
+#define DICT_DEFINE2 "/D:"
+#define DICT_DEFINE3 "/LOOKUP:"
+
+#define CURL_DEFAULT_USER "anonymous"
+#define CURL_DEFAULT_PASSWORD "curl_by_daniel@haxx.se"
+
+#include "cookie.h"
+#include "formdata.h"
+
+#ifdef USE_SSLEAY
+#ifdef USE_OPENSSL
+#include "openssl/rsa.h"
+#include "openssl/crypto.h"
+#include "openssl/x509.h"
+#include "openssl/pem.h"
+#include "openssl/ssl.h"
+#include "openssl/err.h"
+#ifdef HAVE_OPENSSL_ENGINE_H
+#include <openssl/engine.h>
+#endif
+#ifdef HAVE_OPENSSL_PKCS12_H
+#include <openssl/pkcs12.h>
+#endif
+#else /* SSLeay-style includes */
+#include "rsa.h"
+#include "crypto.h"
+#include "x509.h"
+#include "pem.h"
+#include "ssl.h"
+#include "err.h"
+#endif /* USE_OPENSSL */
+#endif /* USE_SSLEAY */
+
+#ifdef USE_GNUTLS
+#include <gnutls/gnutls.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#include "timeval.h"
+
+#ifdef HAVE_ZLIB_H
+#include <zlib.h> /* for content-encoding */
+#endif
+
+#ifdef USE_ARES
+#include <ares.h>
+#endif
+
+#include <curl/curl.h>
+
+#include "http_chunks.h" /* for the structs and enum stuff */
+#include "hostip.h"
+#include "hash.h"
+#include "splay.h"
+
+#ifdef HAVE_GSSAPI
+# ifdef HAVE_GSSGNU
+# include <gss.h>
+# elif defined HAVE_GSSMIT
+# include <gssapi/gssapi.h>
+# include <gssapi/gssapi_generic.h>
+# else
+# include <gssapi.h>
+# endif
+#endif
+
+#ifdef HAVE_LIBSSH2_H
+#include <libssh2.h>
+#include <libssh2_sftp.h>
+#endif /* HAVE_LIBSSH2_H */
+
+/* Download buffer size, keep it fairly big for speed reasons */
+#undef BUFSIZE
+#define BUFSIZE CURL_MAX_WRITE_SIZE
+
+/* Initial size of the buffer to store headers in, it'll be enlarged in case
+ of need. */
+#define HEADERSIZE 256
+
+#define CURLEASY_MAGIC_NUMBER 0xc0dedbad
+
+/* Just a convenience macro to get the larger value out of two given.
+ We prefix with CURL to prevent name collisions. */
+#define CURLMAX(x,y) ((x)>(y)?(x):(y))
+
+#ifdef HAVE_KRB4
+/* Types needed for krb4-ftp connections */
+struct krb4buffer {
+ void *data;
+ size_t size;
+ size_t index;
+ int eof_flag;
+};
+enum protection_level {
+ prot_clear,
+ prot_safe,
+ prot_confidential,
+ prot_private
+};
+#endif
+
+/* enum for the nonblocking SSL connection state machine */
+typedef enum {
+ ssl_connect_1,
+ ssl_connect_2,
+ ssl_connect_2_reading,
+ ssl_connect_2_writing,
+ ssl_connect_3,
+ ssl_connect_done
+} ssl_connect_state;
+
+/* struct for data related to each SSL connection */
+struct ssl_connect_data {
+ bool use; /* use ssl encrypted communications TRUE/FALSE */
+#ifdef USE_SSLEAY
+ /* these ones requires specific SSL-types */
+ SSL_CTX* ctx;
+ SSL* handle;
+ X509* server_cert;
+ ssl_connect_state connecting_state;
+#endif /* USE_SSLEAY */
+#ifdef USE_GNUTLS
+ gnutls_session session;
+ gnutls_certificate_credentials cred;
+#endif /* USE_GNUTLS */
+};
+
+struct ssl_config_data {
+ long version; /* what version the client wants to use */
+ long certverifyresult; /* result from the certificate verification */
+ long verifypeer; /* set TRUE if this is desired */
+ long verifyhost; /* 0: no verify
+ 1: check that CN exists
+ 2: CN must match hostname */
+ char *CApath; /* DOES NOT WORK ON WINDOWS */
+ char *CAfile; /* cerficate to verify peer against */
+ char *random_file; /* path to file containing "random" data */
+ char *egdsocket; /* path to file containing the EGD daemon socket */
+ char *cipher_list; /* list of ciphers to use */
+ long numsessions; /* SSL session id cache size */
+ curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */
+ void *fsslctxp; /* parameter for call back */
+ bool sessionid; /* cache session IDs or not */
+};
+
+/* information stored about one single SSL session */
+struct curl_ssl_session {
+ char *name; /* host name for which this ID was used */
+ void *sessionid; /* as returned from the SSL layer */
+ size_t idsize; /* if known, otherwise 0 */
+ long age; /* just a number, the higher the more recent */
+ unsigned short remote_port; /* remote port to connect to */
+ struct ssl_config_data ssl_config; /* setup for this session */
+};
+
+/* Struct used for Digest challenge-response authentication */
+struct digestdata {
+ char *nonce;
+ char *cnonce;
+ char *realm;
+ int algo;
+ bool stale; /* set true for re-negotiation */
+ char *opaque;
+ char *qop;
+ char *algorithm;
+ int nc; /* nounce count */
+};
+
+typedef enum {
+ NTLMSTATE_NONE,
+ NTLMSTATE_TYPE1,
+ NTLMSTATE_TYPE2,
+ NTLMSTATE_TYPE3,
+ NTLMSTATE_LAST
+} curlntlm;
+
+#ifdef USE_WINDOWS_SSPI
+/* When including these headers, you must define either SECURITY_WIN32
+ * or SECURITY_KERNEL, indicating who is compiling the code.
+ */
+#define SECURITY_WIN32 1
+#include <security.h>
+#include <sspi.h>
+#include <rpc.h>
+#endif
+
+#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
+#include <iconv.h>
+#endif
+
+/* Struct used for NTLM challenge-response authentication */
+struct ntlmdata {
+ curlntlm state;
+#ifdef USE_WINDOWS_SSPI
+ CredHandle handle;
+ CtxtHandle c_handle;
+ SEC_WINNT_AUTH_IDENTITY identity;
+ SEC_WINNT_AUTH_IDENTITY *p_identity;
+ int has_handles;
+ void *type_2;
+ int n_type_2;
+#else
+ unsigned int flags;
+ unsigned char nonce[8];
+#endif
+};
+
+#ifdef HAVE_GSSAPI
+struct negotiatedata {
+ bool gss; /* Whether we're processing GSS-Negotiate or Negotiate */
+ const char* protocol; /* "GSS-Negotiate" or "Negotiate" */
+ OM_uint32 status;
+ gss_ctx_id_t context;
+ gss_name_t server_name;
+ gss_buffer_desc output_token;
+};
+#endif
+
+/****************************************************************************
+ * HTTP unique setup
+ ***************************************************************************/
+struct HTTP {
+ struct FormData *sendit;
+ curl_off_t postsize; /* off_t to handle large file sizes */
+ char *postdata;
+
+ const char *p_pragma; /* Pragma: string */
+ const char *p_accept; /* Accept: string */
+ curl_off_t readbytecount;
+ curl_off_t writebytecount;
+
+ /* For FORM posting */
+ struct Form form;
+ struct Curl_chunker chunk;
+
+ struct back {
+ curl_read_callback fread; /* backup storage for fread pointer */
+ void *fread_in; /* backup storage for fread_in pointer */
+ char *postdata;
+ curl_off_t postsize;
+ } backup;
+
+ enum {
+ HTTPSEND_NADA, /* init */
+ HTTPSEND_REQUEST, /* sending a request */
+ HTTPSEND_BODY, /* sending body */
+ HTTPSEND_LAST /* never use this */
+ } sending;
+
+ void *send_buffer; /* used if the request couldn't be sent in one chunk,
+ points to an allocated send_buffer struct */
+};
+
+/****************************************************************************
+ * FTP unique setup
+ ***************************************************************************/
+typedef enum {
+ FTP_STOP, /* do nothing state, stops the state machine */
+ FTP_WAIT220, /* waiting for the initial 220 response immediately after
+ a connect */
+ FTP_AUTH,
+ FTP_USER,
+ FTP_PASS,
+ FTP_ACCT,
+ FTP_PBSZ,
+ FTP_PROT,
+ FTP_CCC,
+ FTP_PWD,
+ FTP_QUOTE, /* waiting for a response to a command sent in a quote list */
+ FTP_RETR_PREQUOTE,
+ FTP_STOR_PREQUOTE,
+ FTP_POSTQUOTE,
+ FTP_CWD, /* change dir */
+ FTP_MKD, /* if the dir didn't exist */
+ FTP_MDTM, /* to figure out the datestamp */
+ FTP_TYPE, /* to set type when doing a head-like request */
+ FTP_LIST_TYPE, /* set type when about to do a dir list */
+ FTP_RETR_TYPE, /* set type when about to RETR a file */
+ FTP_STOR_TYPE, /* set type when about to STOR a file */
+ FTP_SIZE, /* get the remote file's size for head-like request */
+ FTP_RETR_SIZE, /* get the remote file's size for RETR */
+ FTP_STOR_SIZE, /* get the size for (resumed) STOR */
+ FTP_REST, /* when used to check if the server supports it in head-like */
+ FTP_RETR_REST, /* when asking for "resume" in for RETR */
+ FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */
+ FTP_PASV, /* generic state for PASV and EPSV, check count1 */
+ FTP_LIST, /* generic state for LIST, NLST or a custom list command */
+ FTP_RETR,
+ FTP_STOR, /* generic state for STOR and APPE */
+ FTP_QUIT,
+ FTP_LAST /* never used */
+} ftpstate;
+
+typedef enum {
+ FTPFILE_MULTICWD = 1, /* as defined by RFC1738 */
+ FTPFILE_NOCWD = 2, /* use SIZE / RETR / STOR on the full path */
+ FTPFILE_SINGLECWD = 3 /* make one CWD, then SIZE / RETR / STOR on the file */
+} curl_ftpfile;
+
+/* This FTP struct is used in the SessionHandle. All FTP data that is
+ connection-oriented must be in FTP_conn to properly deal with the fact that
+ perhaps the SessionHandle is changed between the times the connection is
+ used. */
+struct FTP {
+ curl_off_t *bytecountp;
+ char *user; /* user name string */
+ char *passwd; /* password string */
+ char *urlpath; /* the originally given path part of the URL */
+ char *file; /* decoded file */
+ bool no_transfer; /* nothing was transfered, (possibly because a resumed
+ transfer already was complete) */
+ curl_off_t downloadsize;
+};
+
+/* ftp_conn is used for striuct connection-oriented data in the connectdata
+ struct */
+struct ftp_conn {
+ char *entrypath; /* the PWD reply when we logged on */
+ char **dirs; /* realloc()ed array for path components */
+ int dirdepth; /* number of entries used in the 'dirs' array */
+ int diralloc; /* number of entries allocated for the 'dirs' array */
+ char *cache; /* data cache between getresponse()-calls */
+ curl_off_t cache_size; /* size of cache in bytes */
+ bool dont_check; /* Set to TRUE to prevent the final (post-transfer)
+ file size and 226/250 status check. It should still
+ read the line, just ignore the result. */
+ long response_time; /* When no timeout is given, this is the amount of
+ seconds we await for an FTP response. Initialized
+ in Curl_ftp_connect() */
+ bool ctl_valid; /* Tells Curl_ftp_quit() whether or not to do anything. If
+ the connection has timed out or been closed, this
+ should be FALSE when it gets to Curl_ftp_quit() */
+ bool cwddone; /* if it has been determined that the proper CWD combo
+ already has been done */
+ bool cwdfail; /* set TRUE if a CWD command fails, as then we must prevent
+ caching the current directory */
+ char *prevpath; /* conn->path from the previous transfer */
+ char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a
+ and others (A/I or zero) */
+ size_t nread_resp; /* number of bytes currently read of a server response */
+ char *linestart_resp; /* line start pointer for the FTP server response
+ reader function */
+
+ int count1; /* general purpose counter for the state machine */
+ int count2; /* general purpose counter for the state machine */
+ int count3; /* general purpose counter for the state machine */
+ char *sendthis; /* allocated pointer to a buffer that is to be sent to the
+ ftp server */
+ size_t sendleft; /* number of bytes left to send from the sendthis buffer */
+ size_t sendsize; /* total size of the sendthis buffer */
+ struct timeval response; /* set to Curl_tvnow() when a command has been sent
+ off, used to time-out response reading */
+ ftpstate state; /* always use ftp.c:state() to change state! */
+};
+
+struct SSHPROTO {
+ curl_off_t *bytecountp;
+ char *user;
+ char *passwd;
+ char *path; /* the path we operate on */
+ char *homedir;
+ char *errorstr;
+#ifdef USE_LIBSSH2
+ LIBSSH2_SESSION *ssh_session; /* Secure Shell session */
+ LIBSSH2_CHANNEL *ssh_channel; /* Secure Shell channel handle */
+ LIBSSH2_SFTP *sftp_session; /* SFTP handle */
+ LIBSSH2_SFTP_HANDLE *sftp_handle;
+#endif /* USE_LIBSSH2 */
+};
+
+
+/****************************************************************************
+ * FILE unique setup
+ ***************************************************************************/
+struct FILEPROTO {
+ char *path; /* the path we operate on */
+ char *freepath; /* pointer to the allocated block we must free, this might
+ differ from the 'path' pointer */
+ int fd; /* open file descriptor to read from! */
+};
+
+/*
+ * Boolean values that concerns this connection.
+ */
+struct ConnectBits {
+ bool close; /* if set, we close the connection after this request */
+ bool reuse; /* if set, this is a re-used connection */
+ bool chunk; /* if set, this is a chunked transfer-encoding */
+ bool httpproxy; /* if set, this transfer is done through a http proxy */
+ bool user_passwd; /* do we use user+password for this connection? */
+ bool proxy_user_passwd; /* user+password for the proxy? */
+ bool ipv6_ip; /* we communicate with a remote site specified with pure IPv6
+ IP address */
+ bool ipv6; /* we communicate with a site using an IPv6 address */
+
+ bool do_more; /* this is set TRUE if the ->curl_do_more() function is
+ supposed to be called, after ->curl_do() */
+
+ bool upload_chunky; /* set TRUE if we are doing chunked transfer-encoding
+ on upload */
+ bool getheader; /* TRUE if header parsing is wanted */
+
+ bool forbidchunk; /* used only to explicitly forbid chunk-upload for
+ specific upload buffers. See readmoredata() in
+ http.c for details. */
+
+ bool tcpconnect; /* the TCP layer (or simimlar) is connected, this is set
+ the first time on the first connect function call */
+ bool protoconnstart;/* the protocol layer has STARTED its operation after
+ the TCP layer connect */
+
+ bool retry; /* this connection is about to get closed and then
+ re-attempted at another connection. */
+ bool no_body; /* CURLOPT_NO_BODY (or similar) was set */
+ bool tunnel_proxy; /* if CONNECT is used to "tunnel" through the proxy.
+ This is implicit when SSL-protocols are used through
+ proxies, but can also be enabled explicitly by
+ apps */
+ bool authneg; /* TRUE when the auth phase has started, which means
+ that we are creating a request with an auth header,
+ but it is not the final request in the auth
+ negotiation. */
+ bool rewindaftersend;/* TRUE when the sending couldn't be stopped even
+ though it will be discarded. When the whole send
+ operation is done, we must call the data rewind
+ callback. */
+ bool ftp_use_epsv; /* As set with CURLOPT_FTP_USE_EPSV, but if we find out
+ EPSV doesn't work we disable it for the forthcoming
+ requests */
+
+ bool ftp_use_eprt; /* As set with CURLOPT_FTP_USE_EPRT, but if we find out
+ EPRT doesn't work we disable it for the forthcoming
+ requests */
+ bool netrc; /* name+password provided by netrc */
+
+ bool trailerHdrPresent; /* Set when Trailer: header found in HTTP response.
+ Required to determine whether to look for trailers
+ in case of Transfer-Encoding: chunking */
+ bool done; /* set to FALSE when Curl_do() is called and set to TRUE
+ when Curl_done() is called, to prevent Curl_done() to
+ get invoked twice when the multi interface is
+ used. */
+ bool stream_was_rewound; /* Indicates that the stream was rewound after a
+ request read past the end of its response byte
+ boundary */
+ bool proxy_connect_closed; /* set true if a proxy disconnected the
+ connection in a CONNECT request with auth, so
+ that libcurl should reconnect and continue. */
+};
+
+struct hostname {
+ char *rawalloc; /* allocated "raw" version of the name */
+ char *encalloc; /* allocated IDN-encoded version of the name */
+ char *name; /* name to use internally, might be encoded, might be raw */
+ char *dispname; /* name to display, as 'name' might be encoded */
+};
+
+/*
+ * Flags on the keepon member of the Curl_transfer_keeper
+ */
+
+#define KEEP_NONE 0
+#define KEEP_READ 1 /* there is or may be data to read */
+#define KEEP_WRITE 2 /* there is or may be data to write */
+#define KEEP_READ_HOLD 4 /* when set, no reading should be done but there
+ might still be data to read */
+#define KEEP_WRITE_HOLD 8 /* when set, no writing should be done but there
+ might still be data to write */
+
+/*
+ * This struct is all the previously local variables from Curl_perform() moved
+ * to struct to allow the function to return and get re-invoked better without
+ * losing state.
+ */
+
+struct Curl_transfer_keeper {
+
+ /** Values copied over from the HandleData struct each time on init **/
+
+ curl_off_t size; /* -1 if unknown at this point */
+ curl_off_t *bytecountp; /* return number of bytes read or NULL */
+
+ curl_off_t maxdownload; /* in bytes, the maximum amount of data to fetch, 0
+ means unlimited */
+ curl_off_t *writebytecountp; /* return number of bytes written or NULL */
+
+ /** End of HandleData struct copies **/
+
+ curl_off_t bytecount; /* total number of bytes read */
+ curl_off_t writebytecount; /* number of bytes written */
+
+ struct timeval start; /* transfer started at this time */
+ struct timeval now; /* current time */
+ bool header; /* incoming data has HTTP header */
+ enum {
+ HEADER_NORMAL, /* no bad header at all */
+ HEADER_PARTHEADER, /* part of the chunk is a bad header, the rest
+ is normal data */
+ HEADER_ALLBAD /* all was believed to be header */
+ } badheader; /* the header was deemed bad and will be
+ written as body */
+ int headerline; /* counts header lines to better track the
+ first one */
+ char *hbufp; /* points at *end* of header line */
+ size_t hbuflen;
+ char *str; /* within buf */
+ char *str_start; /* within buf */
+ char *end_ptr; /* within buf */
+ char *p; /* within headerbuff */
+ bool content_range; /* set TRUE if Content-Range: was found */
+ curl_off_t offset; /* possible resume offset read from the
+ Content-Range: header */
+ int httpcode; /* error code from the 'HTTP/1.? XXX' line */
+ int httpversion; /* the HTTP version*10 */
+ struct timeval start100; /* time stamp to wait for the 100 code from */
+ bool write_after_100_header; /* TRUE = we enable the write after we
+ received a 100-continue/timeout or
+ FALSE = directly */
+ bool wait100_after_headers; /* TRUE = after the request-headers have been
+ sent off properly, we go into the wait100
+ state, FALSE = don't */
+ int content_encoding; /* What content encoding. sec 3.5, RFC2616. */
+
+#define IDENTITY 0 /* No encoding */
+#define DEFLATE 1 /* zlib delfate [RFC 1950 & 1951] */
+#define GZIP 2 /* gzip algorithm [RFC 1952] */
+#define COMPRESS 3 /* Not handled, added for completeness */
+
+#ifdef HAVE_LIBZ
+ bool zlib_init; /* True if zlib already initialized;
+ undefined if Content-Encoding header. */
+ z_stream z; /* State structure for zlib. */
+#endif
+
+ time_t timeofdoc;
+ long bodywrites;
+
+ char *buf;
+ char *uploadbuf;
+ curl_socket_t maxfd;
+
+ int keepon;
+
+ bool upload_done; /* set to TRUE when doing chunked transfer-encoding upload
+ and we're uploading the last chunk */
+
+ bool ignorebody; /* we read a response-body but we ignore it! */
+ bool ignorecl; /* This HTTP response has no body so we ignore the Content-
+ Length: header */
+};
+
+#if defined(USE_ARES) || defined(USE_THREADING_GETHOSTBYNAME) || \
+ defined(USE_THREADING_GETADDRINFO)
+struct Curl_async {
+ char *hostname;
+ int port;
+ struct Curl_dns_entry *dns;
+ bool done; /* set TRUE when the lookup is complete */
+ int status; /* if done is TRUE, this is the status from the callback */
+ void *os_specific; /* 'struct thread_data' for Windows */
+};
+#endif
+
+#define FIRSTSOCKET 0
+#define SECONDARYSOCKET 1
+
+/* These function pointer types are here only to allow easier typecasting
+ within the source when we need to cast between data pointers (such as NULL)
+ and function pointers. */
+typedef CURLcode (*Curl_do_more_func)(struct connectdata *);
+typedef CURLcode (*Curl_done_func)(struct connectdata *, CURLcode, bool);
+
+
+/*
+ * Store's request specific data in the easy handle (SessionHandle).
+ * Previously, these members were on the connectdata struct but since
+ * a conn struct may now be shared between different SessionHandles,
+ * we store connection-specific data here.
+ *
+ */
+struct HandleData {
+ char *pathbuffer;/* allocated buffer to store the URL's path part in */
+ char *path; /* path to use, points to somewhere within the pathbuffer
+ area */
+
+ char *newurl; /* This can only be set if a Location: was in the
+ document headers */
+
+ /* This struct is inited when needed */
+ struct Curl_transfer_keeper keep;
+
+ /* 'upload_present' is used to keep a byte counter of how much data there is
+ still left in the buffer, aimed for upload. */
+ ssize_t upload_present;
+
+ /* 'upload_fromhere' is used as a read-pointer when we uploaded parts of a
+ buffer, so the next read should read from where this pointer points to,
+ and the 'upload_present' contains the number of bytes available at this
+ position */
+ char *upload_fromhere;
+
+ curl_off_t size; /* -1 if unknown at this point */
+ curl_off_t *bytecountp; /* return number of bytes read or NULL */
+
+ curl_off_t maxdownload; /* in bytes, the maximum amount of data to fetch, 0
+ means unlimited */
+ curl_off_t *writebytecountp; /* return number of bytes written or NULL */
+
+ bool use_range;
+ bool rangestringalloc; /* the range string is malloc()'ed */
+
+ char *range; /* range, if used. See README for detailed specification on
+ this syntax. */
+ curl_off_t resume_from; /* continue [ftp] transfer from here */
+
+ /* Protocol specific data */
+
+ union {
+ struct HTTP *http;
+ struct HTTP *https; /* alias, just for the sake of being more readable */
+ struct FTP *ftp;
+ void *tftp; /* private for tftp.c-eyes only */
+ struct FILEPROTO *file;
+ void *telnet; /* private for telnet.c-eyes only */
+ void *generic;
+ struct SSHPROTO *ssh;
+ } proto;
+};
+
+/*
+ * The connectdata struct contains all fields and variables that should be
+ * unique for an entire connection.
+ */
+struct connectdata {
+ /* 'data' is the CURRENT SessionHandle using this connection -- take great
+ caution that this might very well vary between different times this
+ connection is used! */
+ struct SessionHandle *data;
+
+ bool inuse; /* This is a marker for the connection cache logic. If this is
+ TRUE this handle is being used by an easy handle and cannot
+ be used by any other easy handle without careful
+ consideration (== only for pipelining). */
+
+ /**** Fields set when inited and not modified again */
+ long connectindex; /* what index in the connection cache connects index this
+ particular struct has */
+ long protocol; /* PROT_* flags concerning the protocol set */
+#define PROT_MISSING (1<<0)
+#define PROT_HTTP (1<<2)
+#define PROT_HTTPS (1<<3)
+#define PROT_FTP (1<<4)
+#define PROT_TELNET (1<<5)
+#define PROT_DICT (1<<6)
+#define PROT_LDAP (1<<7)
+#define PROT_FILE (1<<8)
+#define PROT_FTPS (1<<9)
+#define PROT_SSL (1<<10) /* protocol requires SSL */
+#define PROT_TFTP (1<<11)
+#define PROT_SCP (1<<12)
+#define PROT_SFTP (1<<13)
+
+#define PROT_CLOSEACTION PROT_FTP /* these ones need action before socket
+ close */
+
+ /* 'dns_entry' is the particular host we use. This points to an entry in the
+ DNS cache and it will not get pruned while locked. It gets unlocked in
+ Curl_done(). This entry will be NULL if the connection is re-used as then
+ there is no name resolve done. */
+ struct Curl_dns_entry *dns_entry;
+
+ /* 'ip_addr' is the particular IP we connected to. It points to a struct
+ within the DNS cache, so this pointer is only valid as long as the DNS
+ cache entry remains locked. It gets unlocked in Curl_done() */
+ Curl_addrinfo *ip_addr;
+
+ /* 'ip_addr_str' is the ip_addr data as a human readable malloc()ed string.
+ It remains available as long as the connection does, which is longer than
+ the ip_addr itself. Set with Curl_store_ip_addr() when ip_addr has been
+ set. */
+ char *ip_addr_str;
+
+ char protostr[16]; /* store the protocol string in this buffer */
+ int socktype; /* SOCK_STREAM or SOCK_DGRAM */
+
+ struct hostname host;
+ struct hostname proxy;
+
+ long port; /* which port to use locally */
+ unsigned short remote_port; /* what remote port to connect to,
+ not the proxy port! */
+
+ long headerbytecount; /* only count received headers */
+ long deductheadercount; /* this amount of bytes doesn't count when we check
+ if anything has been transfered at the end of
+ a connection. We use this counter to make only
+ a 100 reply (without a following second response
+ code) result in a CURLE_GOT_NOTHING error code */
+
+ char *user; /* user name string, allocated */
+ char *passwd; /* password string, allocated */
+
+ char *proxyuser; /* proxy user name string, allocated */
+ char *proxypasswd; /* proxy password string, allocated */
+
+ struct timeval now; /* "current" time */
+ struct timeval created; /* creation time */
+ curl_socket_t sock[2]; /* two sockets, the second is used for the data
+ transfer when doing FTP */
+
+ struct ssl_connect_data ssl[2]; /* this is for ssl-stuff */
+ struct ssl_config_data ssl_config;
+
+ struct ConnectBits bits; /* various state-flags for this connection */
+
+ /* These two functions MUST be set by the curl_connect() function to be
+ be protocol dependent */
+ CURLcode (*curl_do)(struct connectdata *, bool *done);
+ Curl_done_func curl_done;
+
+ /* If the curl_do() function is better made in two halves, this
+ * curl_do_more() function will be called afterwards, if set. For example
+ * for doing the FTP stuff after the PASV/PORT command.
+ */
+ Curl_do_more_func curl_do_more;
+
+ /* This function *MAY* be set to a protocol-dependent function that is run
+ * after the connect() and everything is done, as a step in the connection.
+ * The 'done' pointer points to a bool that should be set to TRUE if the
+ * function completes before return. If it doesn't complete, the caller
+ * should call the curl_connecting() function until it is.
+ */
+ CURLcode (*curl_connect)(struct connectdata *, bool *done);
+
+ /* See above. Currently only used for FTP. */
+ CURLcode (*curl_connecting)(struct connectdata *, bool *done);
+ CURLcode (*curl_doing)(struct connectdata *, bool *done);
+
+ /* Called from the multi interface during the PROTOCONNECT phase, and it
+ should then return a proper fd set */
+ int (*curl_proto_getsock)(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks);
+
+ /* Called from the multi interface during the DOING phase, and it should
+ then return a proper fd set */
+ int (*curl_doing_getsock)(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks);
+
+ /* This function *MAY* be set to a protocol-dependent function that is run
+ * by the curl_disconnect(), as a step in the disconnection.
+ */
+ CURLcode (*curl_disconnect)(struct connectdata *);
+
+ /* This function *MAY* be set to a protocol-dependent function that is run
+ * in the curl_close() function if protocol-specific cleanups are required.
+ */
+ CURLcode (*curl_close)(struct connectdata *);
+
+ /**** curl_get() phase fields */
+
+ curl_socket_t sockfd; /* socket to read from or CURL_SOCKET_BAD */
+ curl_socket_t writesockfd; /* socket to write to, it may very
+ well be the same we read from.
+ CURL_SOCKET_BAD disables */
+
+ /** Dynamicly allocated strings, may need to be freed before this **/
+ /** struct is killed. **/
+ struct dynamically_allocated_data {
+ char *proxyuserpwd; /* free later if not NULL! */
+ char *uagent; /* free later if not NULL! */
+ char *accept_encoding; /* free later if not NULL! */
+ char *userpwd; /* free later if not NULL! */
+ char *rangeline; /* free later if not NULL! */
+ char *ref; /* free later if not NULL! */
+ char *host; /* free later if not NULL */
+ char *cookiehost; /* free later if not NULL */
+ } allocptr;
+
+ int sec_complete; /* if krb4 is enabled for this connection */
+#ifdef HAVE_KRB4
+ enum protection_level command_prot;
+ enum protection_level data_prot;
+ enum protection_level request_data_prot;
+ size_t buffer_size;
+ struct krb4buffer in_buffer, out_buffer;
+ void *app_data;
+ const struct Curl_sec_client_mech *mech;
+ struct sockaddr_in local_addr;
+#endif
+
+ bool readchannel_inuse; /* whether the read channel is in use by an easy
+ handle */
+ bool writechannel_inuse; /* whether the write channel is in use by an easy
+ handle */
+ bool is_in_pipeline; /* TRUE if this connection is in a pipeline */
+
+ struct curl_llist *send_pipe; /* List of handles waiting to
+ send on this pipeline */
+ struct curl_llist *recv_pipe; /* List of handles waiting to read
+ their responses on this pipeline */
+
+ char master_buffer[BUFSIZE]; /* The master buffer for this connection. */
+ size_t read_pos; /* Current read position in the master buffer */
+ size_t buf_len; /* Length of the buffer?? */
+
+
+ /*************** Request - specific items ************/
+
+ /* previously this was in the urldata struct */
+ curl_read_callback fread; /* function that reads the input */
+ void *fread_in; /* pointer to pass to the fread() above */
+
+ struct ntlmdata ntlm; /* NTLM differs from other authentication schemes
+ because it authenticates connections, not
+ single requests! */
+ struct ntlmdata proxyntlm; /* NTLM data for proxy */
+
+ char syserr_buf [256]; /* buffer for Curl_strerror() */
+
+#if defined(USE_ARES) || defined(USE_THREADING_GETHOSTBYNAME) || \
+ defined(USE_THREADING_GETADDRINFO)
+ /* data used for the asynch name resolve callback */
+ struct Curl_async async;
+#endif
+
+ /* These three are used for chunked-encoding trailer support */
+ char *trailer; /* allocated buffer to store trailer in */
+ int trlMax; /* allocated buffer size */
+ int trlPos; /* index of where to store data */
+
+ union {
+ struct ftp_conn ftpc;
+ } proto;
+};
+
+/* The end of connectdata. */
+
+/*
+ * Struct to keep statistical and informational data.
+ */
+struct PureInfo {
+ int httpcode; /* Recent HTTP or FTP response code */
+ int httpproxycode;
+ int httpversion;
+ long filetime; /* If requested, this is might get set. Set to -1 if the time
+ was unretrievable. We cannot have this of type time_t,
+ since time_t is unsigned on several platforms such as
+ OpenVMS. */
+ long header_size; /* size of read header(s) in bytes */
+ long request_size; /* the amount of bytes sent in the request(s) */
+
+ long proxyauthavail;
+ long httpauthavail;
+
+ long numconnects; /* how many new connection did libcurl created */
+
+ char *contenttype; /* the content type of the object */
+};
+
+
+struct Progress {
+ long lastshow; /* time() of the last displayed progress meter or NULL to
+ force redraw at next call */
+ curl_off_t size_dl; /* total expected size */
+ curl_off_t size_ul; /* total expected size */
+ curl_off_t downloaded; /* transfered so far */
+ curl_off_t uploaded; /* transfered so far */
+
+ curl_off_t current_speed; /* uses the currently fastest transfer */
+
+ bool callback; /* set when progress callback is used */
+ int width; /* screen width at download start */
+ int flags; /* see progress.h */
+
+ double timespent;
+
+ curl_off_t dlspeed;
+ curl_off_t ulspeed;
+
+ double t_nslookup;
+ double t_connect;
+ double t_pretransfer;
+ double t_starttransfer;
+ double t_redirect;
+
+ struct timeval start;
+ struct timeval t_startsingle;
+#define CURR_TIME (5+1) /* 6 entries for 5 seconds */
+
+ curl_off_t speeder[ CURR_TIME ];
+ struct timeval speeder_time[ CURR_TIME ];
+ int speeder_c;
+};
+
+typedef enum {
+ HTTPREQ_NONE, /* first in list */
+ HTTPREQ_GET,
+ HTTPREQ_POST,
+ HTTPREQ_POST_FORM, /* we make a difference internally */
+ HTTPREQ_PUT,
+ HTTPREQ_HEAD,
+ HTTPREQ_CUSTOM,
+ HTTPREQ_LAST /* last in list */
+} Curl_HttpReq;
+
+/*
+ * Values that are generated, temporary or calculated internally for a
+ * "session handle" must be defined within the 'struct UrlState'. This struct
+ * will be used within the SessionHandle struct. When the 'SessionHandle'
+ * struct is cloned, this data MUST NOT be copied.
+ *
+ * Remember that any "state" information goes globally for the curl handle.
+ * Session-data MUST be put in the connectdata struct and here. */
+#define MAX_CURL_USER_LENGTH 256
+#define MAX_CURL_PASSWORD_LENGTH 256
+#define MAX_CURL_USER_LENGTH_TXT "255"
+#define MAX_CURL_PASSWORD_LENGTH_TXT "255"
+
+struct auth {
+ long want; /* Bitmask set to the authentication methods wanted by the app
+ (with CURLOPT_HTTPAUTH or CURLOPT_PROXYAUTH). */
+ long picked;
+ long avail; /* bitmask for what the server reports to support for this
+ resource */
+ bool done; /* TRUE when the auth phase is done and ready to do the *actual*
+ request */
+ bool multi; /* TRUE if this is not yet authenticated but within the auth
+ multipass negotiation */
+
+};
+
+struct conncache {
+ /* 'connects' will be an allocated array with pointers. If the pointer is
+ set, it holds an allocated connection. */
+ struct connectdata **connects;
+ long num; /* number of entries of the 'connects' array */
+ enum {
+ CONNCACHE_PRIVATE, /* used for an easy handle alone */
+ CONNCACHE_MULTI /* shared within a multi handle */
+ } type;
+};
+
+
+struct UrlState {
+ enum {
+ Curl_if_none,
+ Curl_if_easy,
+ Curl_if_multi
+ } used_interface;
+
+ struct conncache *connc; /* points to the connection cache this handle
+ uses */
+
+ /* buffers to store authentication data in, as parsed from input options */
+ struct timeval keeps_speed; /* for the progress meter really */
+
+ long lastconnect; /* index of most recent connect or -1 if undefined */
+
+ char *headerbuff; /* allocated buffer to store headers in */
+ size_t headersize; /* size of the allocation */
+
+ char buffer[BUFSIZE+1]; /* download buffer */
+ char uploadbuffer[BUFSIZE+1]; /* upload buffer */
+ curl_off_t current_speed; /* the ProgressShow() funcion sets this,
+ bytes / second */
+ bool this_is_a_follow; /* this is a followed Location: request */
+
+ bool is_in_pipeline; /* Indicates whether this handle is part of a pipeline */
+
+ char *first_host; /* if set, this should be the host name that we will
+ sent authorization to, no else. Used to make Location:
+ following not keep sending user+password... This is
+ strdup() data.
+ */
+
+ struct curl_ssl_session *session; /* array of 'numsessions' size */
+ long sessionage; /* number of the most recent session */
+
+ char *scratch; /* huge buffer[BUFSIZE*2] when doing upload CRLF replacing */
+ bool errorbuf; /* Set to TRUE if the error buffer is already filled in.
+ This must be set to FALSE every time _easy_perform() is
+ called. */
+ int os_errno; /* filled in with errno whenever an error occurs */
+#ifdef HAVE_SIGNAL
+ /* storage for the previous bag^H^H^HSIGPIPE signal handler :-) */
+ void (*prev_signal)(int sig);
+#endif
+ bool allow_port; /* Is set.use_port allowed to take effect or not. This
+ is always set TRUE when curl_easy_perform() is called. */
+
+ struct digestdata digest;
+ struct digestdata proxydigest;
+
+#ifdef HAVE_GSSAPI
+ struct negotiatedata negotiate;
+#endif
+
+ struct auth authhost;
+ struct auth authproxy;
+
+ bool authproblem; /* TRUE if there's some problem authenticating */
+
+#ifdef USE_ARES
+ ares_channel areschannel; /* for name resolves */
+#endif
+
+#if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H)
+ ENGINE *engine;
+#endif /* USE_SSLEAY */
+ struct timeval expiretime; /* set this with Curl_expire() only */
+ struct Curl_tree timenode; /* for the splay stuff */
+
+ /* a place to store the most recenlty set FTP entrypath */
+ char *most_recent_ftp_entrypath;
+
+ /* set after initial USER failure, to prevent an authentication loop */
+ bool ftp_trying_alternative;
+
+ bool expect100header; /* TRUE if we added Expect: 100-continue */
+
+ bool pipe_broke; /* TRUE if the connection we were pipelined on broke
+ and we need to restart from the beginning */
+ bool cancelled; /* TRUE if the request was cancelled */
+
+#ifndef WIN32
+/* do FTP line-end conversions on most platforms */
+#define CURL_DO_LINEEND_CONV
+ /* for FTP downloads: track CRLF sequences that span blocks */
+ bool prev_block_had_trailing_cr;
+ /* for FTP downloads: how many CRLFs did we converted to LFs? */
+ curl_off_t crlf_conversions;
+#endif
+ /* If set to non-NULL, there's a connection in a shared connection cache
+ that uses this handle so we can't kill this SessionHandle just yet but
+ must keep it around and add it to the list of handles to kill once all
+ its connections are gone */
+ void *shared_conn;
+ bool closed; /* set to TRUE when curl_easy_cleanup() has been called on this
+ handle, but it is kept around as mentioned for
+ shared_conn */
+};
+
+
+/*
+ * This 'DynamicStatic' struct defines dynamic states that actually change
+ * values in the 'UserDefined' area, which MUST be taken into consideration
+ * if the UserDefined struct is cloned or similar. You can probably just
+ * copy these, but each one indicate a special action on other data.
+ */
+
+struct DynamicStatic {
+ char *url; /* work URL, copied from UserDefined */
+ bool url_alloc; /* URL string is malloc()'ed */
+ bool url_changed; /* set on CURL_OPT_URL, used to detect if the URL was
+ changed after the connect phase, as we allow callback
+ to change it and if so, we reconnect to use the new
+ URL instead */
+ char *referer; /* referer string */
+ bool referer_alloc; /* referer sting is malloc()ed */
+ struct curl_slist *cookielist; /* list of cookie files set by
+ curl_easy_setopt(COOKIEFILE) calls */
+};
+
+/*
+ * This 'UserDefined' struct must only contain data that is set once to go
+ * for many (perhaps) independent connections. Values that are generated or
+ * calculated internally for the "session handle" MUST be defined within the
+ * 'struct UrlState' instead. The only exceptions MUST note the changes in
+ * the 'DynamicStatic' struct.
+ */
+struct Curl_one_easy; /* declared and used only in multi.c */
+struct Curl_multi; /* declared and used only in multi.c */
+
+struct UserDefined {
+ FILE *err; /* the stderr user data goes here */
+ void *debugdata; /* the data that will be passed to fdebug */
+ char *errorbuffer; /* store failure messages in here */
+ char *proxyuserpwd; /* Proxy <user:password>, if used */
+ long proxyport; /* If non-zero, use this port number by default. If the
+ proxy string features a ":[port]" that one will override
+ this. */
+ void *out; /* the fetched file goes here */
+ void *in; /* the uploaded file is read from here */
+ void *writeheader; /* write the header to this if non-NULL */
+ char *set_url; /* what original URL to work on */
+ char *proxy; /* proxy to use */
+ long use_port; /* which port to use (when not using default) */
+ char *userpwd; /* <user:password>, if used */
+ long httpauth; /* what kind of HTTP authentication to use (bitmask) */
+ long proxyauth; /* what kind of proxy authentication to use (bitmask) */
+ char *set_range; /* range, if used. See README for detailed specification
+ on this syntax. */
+ long followlocation; /* as in HTTP Location: */
+ long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1
+ for infinity */
+ char *set_referer; /* custom string */
+ bool free_referer; /* set TRUE if 'referer' points to a string we
+ allocated */
+ char *useragent; /* User-Agent string */
+ char *encoding; /* Accept-Encoding string */
+ char *postfields; /* if POST, set the fields' values here */
+ curl_off_t postfieldsize; /* if POST, this might have a size to use instead
+ of strlen(), and then the data *may* be binary
+ (contain zero bytes) */
+ char *ftpport; /* port to send with the FTP PORT command */
+ char *device; /* local network interface/address to use */
+ unsigned short localport; /* local port number to bind to */
+ int localportrange; /* number of additional port numbers to test in case the
+ 'localport' one can't be bind()ed */
+ curl_write_callback fwrite; /* function that stores the output */
+ curl_write_callback fwrite_header; /* function that stores headers */
+ curl_read_callback fread; /* function that reads the input */
+ curl_progress_callback fprogress; /* function for progress information */
+ curl_debug_callback fdebug; /* function that write informational data */
+ curl_ioctl_callback ioctl; /* function for I/O control */
+ curl_sockopt_callback fsockopt; /* function for setting socket options */
+ void *sockopt_client; /* pointer to pass to the socket options callback */
+
+ /* the 3 curl_conv_callback functions below are used on non-ASCII hosts */
+ /* function to convert from the network encoding: */
+ curl_conv_callback convfromnetwork;
+ /* function to convert to the network encoding: */
+ curl_conv_callback convtonetwork;
+ /* function to convert from UTF-8 encoding: */
+ curl_conv_callback convfromutf8;
+
+ void *progress_client; /* pointer to pass to the progress callback */
+ void *ioctl_client; /* pointer to pass to the ioctl callback */
+ long timeout; /* in seconds, 0 means no timeout */
+ long connecttimeout; /* in seconds, 0 means no timeout */
+ long ftp_response_timeout; /* in seconds, 0 means no timeout */
+ curl_off_t infilesize; /* size of file to upload, -1 means unknown */
+ long low_speed_limit; /* bytes/second */
+ long low_speed_time; /* number of seconds */
+ curl_off_t max_send_speed; /* high speed limit in bytes/second for upload */
+ curl_off_t max_recv_speed; /* high speed limit in bytes/second for download */
+ curl_off_t set_resume_from; /* continue [ftp] transfer from here */
+ char *cookie; /* HTTP cookie string to send */
+ struct curl_slist *headers; /* linked list of extra headers */
+ struct curl_httppost *httppost; /* linked list of POST data */
+ char *cert; /* certificate */
+ char *cert_type; /* format for certificate (default: PEM) */
+ char *key; /* private key */
+ char *key_type; /* format for private key (default: PEM) */
+ char *key_passwd; /* plain text private key password */
+ char *cookiejar; /* dump all cookies to this file */
+ bool cookiesession; /* new cookie session? */
+ bool crlf; /* convert crlf on ftp upload(?) */
+ char *ftp_account; /* ftp account data */
+ char *ftp_alternative_to_user; /* command to send if USER/PASS fails */
+ struct curl_slist *quote; /* after connection is established */
+ struct curl_slist *postquote; /* after the transfer */
+ struct curl_slist *prequote; /* before the transfer, after type */
+ struct curl_slist *source_quote; /* 3rd party quote */
+ struct curl_slist *source_prequote; /* in 3rd party transfer mode - before
+ the transfer on source host */
+ struct curl_slist *source_postquote; /* in 3rd party transfer mode - after
+ the transfer on source host */
+ struct curl_slist *telnet_options; /* linked list of telnet options */
+ curl_TimeCond timecondition; /* kind of time/date comparison */
+ time_t timevalue; /* what time to compare with */
+ Curl_HttpReq httpreq; /* what kind of HTTP request (if any) is this */
+ char *customrequest; /* HTTP/FTP request to use */
+ long httpversion; /* when non-zero, a specific HTTP version requested to
+ be used in the library's request(s) */
+ char *auth_host; /* if set, this is the allocated string to the host name
+ * to which to send the authorization data to, and no other
+ * host (which location-following otherwise could lead to)
+ */
+ char *krb4_level; /* what security level */
+ struct ssl_config_data ssl; /* user defined SSL stuff */
+
+ curl_proxytype proxytype; /* what kind of proxy that is in use */
+
+ int dns_cache_timeout; /* DNS cache timeout */
+ long buffer_size; /* size of receive buffer to use */
+
+ char *private_data; /* Private data */
+
+ struct Curl_one_easy *one_easy; /* When adding an easy handle to a multi
+ handle, an internal 'Curl_one_easy'
+ struct is created and this is a pointer
+ to the particular struct associated with
+ this SessionHandle */
+
+ struct curl_slist *http200aliases; /* linked list of aliases for http200 */
+
+ long ip_version;
+
+ curl_off_t max_filesize; /* Maximum file size to download */
+
+ char *source_url; /* for 3rd party transfer */
+ char *source_userpwd; /* for 3rd party transfer */
+
+ curl_ftpfile ftp_filemethod; /* how to get to a file when FTP is used */
+
+/* Here follows boolean settings that define how to behave during
+ this session. They are STATIC, set by libcurl users or at least initially
+ and they don't change during operations. */
+
+ bool printhost; /* printing host name in debug info */
+ bool get_filetime;
+ bool tunnel_thru_httpproxy;
+ bool prefer_ascii; /* ASCII rather than binary */
+ bool ftp_append;
+ bool ftp_list_only;
+ bool ftp_create_missing_dirs;
+ bool ftp_use_port;
+ bool hide_progress;
+ bool http_fail_on_error;
+ bool http_follow_location;
+ bool http_disable_hostname_check_before_authentication;
+ bool include_header; /* include received protocol headers in data output */
+ bool http_set_referer;
+ bool http_auto_referer; /* set "correct" referer when following location: */
+ bool opt_no_body; /* as set with CURLOPT_NO_BODY */
+ bool set_port;
+ bool upload;
+ enum CURL_NETRC_OPTION
+ use_netrc; /* defined in include/curl.h */
+ char *netrc_file; /* if not NULL, use this instead of trying to find
+ $HOME/.netrc */
+ bool verbose;
+ bool krb4; /* kerberos4 connection requested */
+ bool reuse_forbid; /* forbidden to be reused, close after use */
+ bool reuse_fresh; /* do not re-use an existing connection */
+ bool ftp_use_epsv; /* if EPSV is to be attempted or not */
+ bool ftp_use_eprt; /* if EPRT is to be attempted or not */
+ bool ftp_use_ccc; /* if CCC is to be attempted or not */
+
+ curl_ftpssl ftp_ssl; /* if AUTH TLS is to be attempted etc */
+ curl_ftpauth ftpsslauth; /* what AUTH XXX to be attempted */
+ bool no_signal; /* do not use any signal/alarm handler */
+ bool global_dns_cache; /* subject for future removal */
+ bool tcp_nodelay; /* whether to enable TCP_NODELAY or not */
+ bool ignorecl; /* ignore content length */
+ bool ftp_skip_ip; /* skip the IP address the FTP server passes on to
+ us */
+ bool connect_only; /* make connection, let application use the socket */
+ long ssh_auth_types; /* allowed SSH auth types */
+ char *ssh_public_key; /* the path to the public key file for
+ authentication */
+ char *ssh_private_key; /* the path to the private key file for
+ authentication */
+};
+
+struct Names {
+ struct curl_hash *hostcache;
+ enum {
+ HCACHE_NONE, /* not pointing to anything */
+ HCACHE_PRIVATE, /* points to our own */
+ HCACHE_GLOBAL, /* points to the (shrug) global one */
+ HCACHE_MULTI, /* points to a shared one in the multi handle */
+ HCACHE_SHARED /* points to a shared one in a shared object */
+ } hostcachetype;
+};
+
+/*
+ * The 'connectdata' struct MUST have all the connection oriented stuff as we
+ * may have several simultaneous connections and connection structs in memory.
+ *
+ * The 'struct UserDefined' must only contain data that is set once to go for
+ * many (perhaps) independent connections. Values that are generated or
+ * calculated internally for the "session handle" must be defined within the
+ * 'struct UrlState' instead.
+ */
+
+struct SessionHandle {
+ struct Names dns;
+ struct Curl_multi *multi; /* if non-NULL, points to the multi handle
+ struct to which this "belongs" */
+ struct Curl_share *share; /* Share, handles global variable mutexing */
+ struct HandleData reqdata; /* Request-specific data */
+ struct UserDefined set; /* values set by the libcurl user */
+ struct DynamicStatic change; /* possibly modified userdefined data */
+
+ struct CookieInfo *cookies; /* the cookies, read from files and servers */
+ struct Progress progress; /* for all the progress meter data */
+ struct UrlState state; /* struct for fields used for state info and
+ other dynamic purposes */
+ struct PureInfo info; /* stats, reports and info data */
+#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
+ iconv_t outbound_cd; /* for translating to the network encoding */
+ iconv_t inbound_cd; /* for translating from the network encoding */
+ iconv_t utf8_cd; /* for translating to UTF8 */
+#endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
+ unsigned int magic; /* set to a CURLEASY_MAGIC_NUMBER */
+};
+
+#define LIBCURL_NAME "libcurl"
+
+#endif
diff --git a/Utilities/cmcurl/version.c b/Utilities/cmcurl/version.c
new file mode 100644
index 0000000000..9085f7df81
--- /dev/null
+++ b/Utilities/cmcurl/version.c
@@ -0,0 +1,249 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <curl/curl.h>
+#include "urldata.h"
+#include "sslgen.h"
+
+#define _MPRINTF_REPLACE /* use the internal *printf() functions */
+#include <curl/mprintf.h>
+
+#ifdef USE_ARES
+#include <ares_version.h>
+#endif
+
+#ifdef USE_LIBIDN
+#include <stringprep.h>
+#endif
+
+#if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
+#include <iconv.h>
+#endif
+
+#ifdef USE_LIBSSH2
+#include <libssh2.h>
+#endif
+
+
+char *curl_version(void)
+{
+ static char version[200];
+ char *ptr=version;
+ size_t len;
+ size_t left = sizeof(version);
+ strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION );
+ ptr=strchr(ptr, '\0');
+ left -= strlen(ptr);
+
+ len = Curl_ssl_version(ptr, left);
+ left -= len;
+ ptr += len;
+
+#ifdef HAVE_LIBZ
+ len = snprintf(ptr, left, " zlib/%s", zlibVersion());
+ left -= len;
+ ptr += len;
+#endif
+#ifdef USE_ARES
+ /* this function is only present in c-ares, not in the original ares */
+ len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
+ left -= len;
+ ptr += len;
+#endif
+#ifdef USE_LIBIDN
+ if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
+ len = snprintf(ptr, left, " libidn/%s", stringprep_check_version(NULL));
+ left -= len;
+ ptr += len;
+ }
+#endif
+#if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
+#ifdef _LIBICONV_VERSION
+ len = snprintf(ptr, left, " iconv/%d.%d",
+ _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
+#else
+ /* version unknown */
+ len = snprintf(ptr, left, " iconv");
+#endif /* _LIBICONV_VERSION */
+ left -= len;
+ ptr += len;
+#endif
+#ifdef USE_LIBSSH2
+ len = snprintf(ptr, left, " libssh2/%s", LIBSSH2_VERSION);
+ left -= len;
+ ptr += len;
+#endif
+
+ return version;
+}
+
+/* data for curl_version_info */
+
+static const char * const protocols[] = {
+#ifndef CURL_DISABLE_TFTP
+ "tftp",
+#endif
+#ifndef CURL_DISABLE_FTP
+ "ftp",
+#endif
+#ifndef CURL_DISABLE_TELNET
+ "telnet",
+#endif
+#ifndef CURL_DISABLE_DICT
+ "dict",
+#endif
+#ifndef CURL_DISABLE_LDAP
+ "ldap",
+#endif
+#ifndef CURL_DISABLE_HTTP
+ "http",
+#endif
+#ifndef CURL_DISABLE_FILE
+ "file",
+#endif
+
+#ifdef USE_SSL
+#ifndef CURL_DISABLE_HTTP
+ "https",
+#endif
+#ifndef CURL_DISABLE_FTP
+ "ftps",
+#endif
+#endif
+
+#ifdef USE_LIBSSH2
+ "scp",
+ "sftp",
+#endif
+
+ NULL
+};
+
+static curl_version_info_data version_info = {
+ CURLVERSION_NOW,
+ LIBCURL_VERSION,
+ LIBCURL_VERSION_NUM,
+ OS, /* as found by configure or set by hand at build-time */
+ 0 /* features is 0 by default */
+#ifdef ENABLE_IPV6
+ | CURL_VERSION_IPV6
+#endif
+#ifdef HAVE_KRB4
+ | CURL_VERSION_KERBEROS4
+#endif
+#ifdef USE_SSL
+ | CURL_VERSION_SSL
+#endif
+#ifdef USE_NTLM
+ | CURL_VERSION_NTLM
+#endif
+#ifdef USE_WINDOWS_SSPI
+ | CURL_VERSION_SSPI
+#endif
+#ifdef HAVE_LIBZ
+ | CURL_VERSION_LIBZ
+#endif
+#ifdef HAVE_GSSAPI
+ | CURL_VERSION_GSSNEGOTIATE
+#endif
+#ifdef CURLDEBUG
+ | CURL_VERSION_DEBUG
+#endif
+#ifdef USE_ARES
+ | CURL_VERSION_ASYNCHDNS
+#endif
+#ifdef HAVE_SPNEGO
+ | CURL_VERSION_SPNEGO
+#endif
+#if defined(ENABLE_64BIT) && (SIZEOF_CURL_OFF_T > 4)
+ | CURL_VERSION_LARGEFILE
+#endif
+#if defined(CURL_DOES_CONVERSIONS)
+ | CURL_VERSION_CONV
+#endif
+ ,
+ NULL, /* ssl_version */
+ 0, /* ssl_version_num, this is kept at zero */
+ NULL, /* zlib_version */
+ protocols,
+ NULL, /* c-ares version */
+ 0, /* c-ares version numerical */
+ NULL, /* libidn version */
+ 0, /* iconv version */
+ NULL, /* ssh lib version */
+};
+
+curl_version_info_data *curl_version_info(CURLversion stamp)
+{
+#ifdef USE_LIBSSH2
+ static char ssh_buffer[80];
+#endif
+
+#ifdef USE_SSL
+ static char ssl_buffer[80];
+ Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
+ version_info.ssl_version = ssl_buffer;
+#endif
+
+#ifdef HAVE_LIBZ
+ version_info.libz_version = zlibVersion();
+ /* libz left NULL if non-existing */
+#endif
+#ifdef USE_ARES
+ {
+ int aresnum;
+ version_info.ares = ares_version(&aresnum);
+ version_info.ares_num = aresnum;
+ }
+#endif
+#ifdef USE_LIBIDN
+ /* This returns a version string if we use the given version or later,
+ otherwise it returns NULL */
+ version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
+ if(version_info.libidn)
+ version_info.features |= CURL_VERSION_IDN;
+#endif
+
+#if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
+#ifdef _LIBICONV_VERSION
+ version_info.iconv_ver_num = _LIBICONV_VERSION;
+#else
+ /* version unknown */
+ version_info.iconv_ver_num = -1;
+#endif /* _LIBICONV_VERSION */
+#endif
+
+#ifdef USE_LIBSSH2
+ snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
+ version_info.libssh_version = ssh_buffer;
+#endif
+
+ (void)stamp; /* avoid compiler warnings, we don't use this */
+
+ return &version_info;
+}
diff --git a/Utilities/cmexpat/.NoDartCoverage b/Utilities/cmexpat/.NoDartCoverage
new file mode 100644
index 0000000000..3c99729386
--- /dev/null
+++ b/Utilities/cmexpat/.NoDartCoverage
@@ -0,0 +1 @@
+# do not do coverage in this directory
diff --git a/Utilities/cmexpat/CMakeLists.txt b/Utilities/cmexpat/CMakeLists.txt
new file mode 100644
index 0000000000..51ba413e5c
--- /dev/null
+++ b/Utilities/cmexpat/CMakeLists.txt
@@ -0,0 +1,34 @@
+PROJECT(CMEXPAT)
+
+SET(expat_SRCS
+ xmlparse.c
+ xmltok.c
+ xmlrole.c
+)
+
+INCLUDE(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
+TEST_BIG_ENDIAN(CMEXPAT_BIGENDIAN)
+
+INCLUDE_DIRECTORIES(
+ "${CMEXPAT_BINARY_DIR}/.."
+ )
+
+IF(WIN32)
+ IF(NOT BUILD_SHARED_LIBS)
+ SET (CM_EXPAT_STATIC 1)
+ ENDIF(NOT BUILD_SHARED_LIBS)
+ENDIF(WIN32)
+
+CONFIGURE_FILE(${CMEXPAT_SOURCE_DIR}/expatConfig.h.in
+ ${CMEXPAT_BINARY_DIR}/expatConfig.h)
+CONFIGURE_FILE(${CMEXPAT_SOURCE_DIR}/expatDllConfig.h.in
+ ${CMEXPAT_BINARY_DIR}/expatDllConfig.h)
+CONFIGURE_FILE(${CMEXPAT_SOURCE_DIR}/.NoDartCoverage
+ ${CMEXPAT_BINARY_DIR}/.NoDartCoverage)
+CONFIGURE_FILE(${CMEXPAT_SOURCE_DIR}/cm_expat_mangle.h
+ ${CMEXPAT_BINARY_DIR}/cm_expat_mangle.h)
+CONFIGURE_FILE(${CMEXPAT_SOURCE_DIR}/expat.h
+ ${CMEXPAT_BINARY_DIR}/expat.h)
+
+ADD_LIBRARY(cmexpat ${expat_SRCS})
+INSTALL(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmexpat)
diff --git a/Utilities/cmexpat/COPYING b/Utilities/cmexpat/COPYING
new file mode 100644
index 0000000000..fc97b02d90
--- /dev/null
+++ b/Utilities/cmexpat/COPYING
@@ -0,0 +1,21 @@
+Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
+ and Clark Cooper
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Utilities/cmexpat/ascii.h b/Utilities/cmexpat/ascii.h
new file mode 100644
index 0000000000..6376b1f311
--- /dev/null
+++ b/Utilities/cmexpat/ascii.h
@@ -0,0 +1,86 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+#define ASCII_A 0x41
+#define ASCII_B 0x42
+#define ASCII_C 0x43
+#define ASCII_D 0x44
+#define ASCII_E 0x45
+#define ASCII_F 0x46
+#define ASCII_G 0x47
+#define ASCII_H 0x48
+#define ASCII_I 0x49
+#define ASCII_J 0x4A
+#define ASCII_K 0x4B
+#define ASCII_L 0x4C
+#define ASCII_M 0x4D
+#define ASCII_N 0x4E
+#define ASCII_O 0x4F
+#define ASCII_P 0x50
+#define ASCII_Q 0x51
+#define ASCII_R 0x52
+#define ASCII_S 0x53
+#define ASCII_T 0x54
+#define ASCII_U 0x55
+#define ASCII_V 0x56
+#define ASCII_W 0x57
+#define ASCII_X 0x58
+#define ASCII_Y 0x59
+#define ASCII_Z 0x5A
+
+#define ASCII_a 0x61
+#define ASCII_b 0x62
+#define ASCII_c 0x63
+#define ASCII_d 0x64
+#define ASCII_e 0x65
+#define ASCII_f 0x66
+#define ASCII_g 0x67
+#define ASCII_h 0x68
+#define ASCII_i 0x69
+#define ASCII_j 0x6A
+#define ASCII_k 0x6B
+#define ASCII_l 0x6C
+#define ASCII_m 0x6D
+#define ASCII_n 0x6E
+#define ASCII_o 0x6F
+#define ASCII_p 0x70
+#define ASCII_q 0x71
+#define ASCII_r 0x72
+#define ASCII_s 0x73
+#define ASCII_t 0x74
+#define ASCII_u 0x75
+#define ASCII_v 0x76
+#define ASCII_w 0x77
+#define ASCII_x 0x78
+#define ASCII_y 0x79
+#define ASCII_z 0x7A
+
+#define ASCII_0 0x30
+#define ASCII_1 0x31
+#define ASCII_2 0x32
+#define ASCII_3 0x33
+#define ASCII_4 0x34
+#define ASCII_5 0x35
+#define ASCII_6 0x36
+#define ASCII_7 0x37
+#define ASCII_8 0x38
+#define ASCII_9 0x39
+
+#define ASCII_TAB 0x09
+#define ASCII_SPACE 0x20
+#define ASCII_EXCL 0x21
+#define ASCII_QUOT 0x22
+#define ASCII_AMP 0x26
+#define ASCII_APOS 0x27
+#define ASCII_MINUS 0x2D
+#define ASCII_PERIOD 0x2E
+#define ASCII_COLON 0x3A
+#define ASCII_SEMI 0x3B
+#define ASCII_LT 0x3C
+#define ASCII_EQUALS 0x3D
+#define ASCII_GT 0x3E
+#define ASCII_LSQB 0x5B
+#define ASCII_RSQB 0x5D
+#define ASCII_UNDERSCORE 0x5F
diff --git a/Utilities/cmexpat/asciitab.h b/Utilities/cmexpat/asciitab.h
new file mode 100644
index 0000000000..eb445cc52c
--- /dev/null
+++ b/Utilities/cmexpat/asciitab.h
@@ -0,0 +1,37 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML,
+/* 0x0C */ BT_NONXML, BT_CR, BT_NONXML, BT_NONXML,
+/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM,
+/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS,
+/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS,
+/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL,
+/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT,
+/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT,
+/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI,
+/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST,
+/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX,
+/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT,
+/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB,
+/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT,
+/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX,
+/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT,
+/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER,
+/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER,
diff --git a/Utilities/cmexpat/cm_expat_mangle.h b/Utilities/cmexpat/cm_expat_mangle.h
new file mode 100644
index 0000000000..82276a56d8
--- /dev/null
+++ b/Utilities/cmexpat/cm_expat_mangle.h
@@ -0,0 +1,87 @@
+#ifndef cm_expat_mangle_h
+#define cm_expat_mangle_h
+
+/*
+
+This header file mangles all symbols exported from the expat library.
+It is included in all files while building the expat library. Due to
+namespace pollution, no expat headers should be included in .h files in
+CMake.
+
+The following command was used to obtain the symbol list:
+
+nm libcmexpat.a |grep " T "
+
+*/
+
+#define XML_DefaultCurrent cm_expat_XML_DefaultCurrent
+#define XML_ErrorString cm_expat_XML_ErrorString
+#define XML_ExpatVersion cm_expat_XML_ExpatVersion
+#define XML_ExpatVersionInfo cm_expat_XML_ExpatVersionInfo
+#define XML_ExternalEntityParserCreate cm_expat_XML_ExternalEntityParserCreate
+#define XML_GetBase cm_expat_XML_GetBase
+#define XML_GetBuffer cm_expat_XML_GetBuffer
+#define XML_GetCurrentByteCount cm_expat_XML_GetCurrentByteCount
+#define XML_GetCurrentByteIndex cm_expat_XML_GetCurrentByteIndex
+#define XML_GetCurrentColumnNumber cm_expat_XML_GetCurrentColumnNumber
+#define XML_GetCurrentLineNumber cm_expat_XML_GetCurrentLineNumber
+#define XML_GetErrorCode cm_expat_XML_GetErrorCode
+#define XML_GetIdAttributeIndex cm_expat_XML_GetIdAttributeIndex
+#define XML_GetInputContext cm_expat_XML_GetInputContext
+#define XML_GetSpecifiedAttributeCount cm_expat_XML_GetSpecifiedAttributeCount
+#define XML_Parse cm_expat_XML_Parse
+#define XML_ParseBuffer cm_expat_XML_ParseBuffer
+#define XML_ParserCreate cm_expat_XML_ParserCreate
+#define XML_ParserCreateNS cm_expat_XML_ParserCreateNS
+#define XML_ParserCreate_MM cm_expat_XML_ParserCreate_MM
+#define XML_ParserFree cm_expat_XML_ParserFree
+#define XML_SetAttlistDeclHandler cm_expat_XML_SetAttlistDeclHandler
+#define XML_SetBase cm_expat_XML_SetBase
+#define XML_SetCdataSectionHandler cm_expat_XML_SetCdataSectionHandler
+#define XML_SetCharacterDataHandler cm_expat_XML_SetCharacterDataHandler
+#define XML_SetCommentHandler cm_expat_XML_SetCommentHandler
+#define XML_SetDefaultHandler cm_expat_XML_SetDefaultHandler
+#define XML_SetDefaultHandlerExpand cm_expat_XML_SetDefaultHandlerExpand
+#define XML_SetDoctypeDeclHandler cm_expat_XML_SetDoctypeDeclHandler
+#define XML_SetElementDeclHandler cm_expat_XML_SetElementDeclHandler
+#define XML_SetElementHandler cm_expat_XML_SetElementHandler
+#define XML_SetEncoding cm_expat_XML_SetEncoding
+#define XML_SetEndCdataSectionHandler cm_expat_XML_SetEndCdataSectionHandler
+#define XML_SetEndDoctypeDeclHandler cm_expat_XML_SetEndDoctypeDeclHandler
+#define XML_SetEndElementHandler cm_expat_XML_SetEndElementHandler
+#define XML_SetEndNamespaceDeclHandler cm_expat_XML_SetEndNamespaceDeclHandler
+#define XML_SetEntityDeclHandler cm_expat_XML_SetEntityDeclHandler
+#define XML_SetExternalEntityRefHandler cm_expat_XML_SetExternalEntityRefHandler
+#define XML_SetExternalEntityRefHandlerArg cm_expat_XML_SetExternalEntityRefHandlerArg
+#define XML_SetNamespaceDeclHandler cm_expat_XML_SetNamespaceDeclHandler
+#define XML_SetNotStandaloneHandler cm_expat_XML_SetNotStandaloneHandler
+#define XML_SetNotationDeclHandler cm_expat_XML_SetNotationDeclHandler
+#define XML_SetParamEntityParsing cm_expat_XML_SetParamEntityParsing
+#define XML_SetProcessingInstructionHandler cm_expat_XML_SetProcessingInstructionHandler
+#define XML_SetReturnNSTriplet cm_expat_XML_SetReturnNSTriplet
+#define XML_SetStartCdataSectionHandler cm_expat_XML_SetStartCdataSectionHandler
+#define XML_SetStartDoctypeDeclHandler cm_expat_XML_SetStartDoctypeDeclHandler
+#define XML_SetStartElementHandler cm_expat_XML_SetStartElementHandler
+#define XML_SetStartNamespaceDeclHandler cm_expat_XML_SetStartNamespaceDeclHandler
+#define XML_SetUnknownEncodingHandler cm_expat_XML_SetUnknownEncodingHandler
+#define XML_SetUnparsedEntityDeclHandler cm_expat_XML_SetUnparsedEntityDeclHandler
+#define XML_SetUserData cm_expat_XML_SetUserData
+#define XML_SetXmlDeclHandler cm_expat_XML_SetXmlDeclHandler
+#define XML_UseParserAsHandlerArg cm_expat_XML_UseParserAsHandlerArg
+#define XmlGetUtf16InternalEncoding cm_expat_XmlGetUtf16InternalEncoding
+#define XmlGetUtf16InternalEncodingNS cm_expat_XmlGetUtf16InternalEncodingNS
+#define XmlGetUtf8InternalEncoding cm_expat_XmlGetUtf8InternalEncoding
+#define XmlGetUtf8InternalEncodingNS cm_expat_XmlGetUtf8InternalEncodingNS
+#define XmlInitEncoding cm_expat_XmlInitEncoding
+#define XmlInitEncodingNS cm_expat_XmlInitEncodingNS
+#define XmlInitUnknownEncoding cm_expat_XmlInitUnknownEncoding
+#define XmlInitUnknownEncodingNS cm_expat_XmlInitUnknownEncodingNS
+#define XmlParseXmlDecl cm_expat_XmlParseXmlDecl
+#define XmlParseXmlDeclNS cm_expat_XmlParseXmlDeclNS
+#define XmlSizeOfUnknownEncoding cm_expat_XmlSizeOfUnknownEncoding
+#define XmlUtf16Encode cm_expat_XmlUtf16Encode
+#define XmlUtf8Encode cm_expat_XmlUtf8Encode
+#define XmlPrologStateInit cm_expat_XmlPrologStateInit
+#define XmlPrologStateInitExternalEntity cm_expat_XmlPrologStateInitExternalEntity
+
+#endif
diff --git a/Utilities/cmexpat/expat.h b/Utilities/cmexpat/expat.h
new file mode 100644
index 0000000000..86e58a1e53
--- /dev/null
+++ b/Utilities/cmexpat/expat.h
@@ -0,0 +1,740 @@
+#include "cm_expat_mangle.h"
+/*
+Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+#ifndef XmlParse_INCLUDED
+#define XmlParse_INCLUDED 1
+
+#include <stdlib.h>
+
+#include <cmexpat/expatDllConfig.h>
+
+#if defined(_WIN32) && !defined(CM_EXPAT_STATIC)
+# if defined(cmexpat_EXPORTS)
+# define XMLPARSEAPI(type) __declspec( dllexport ) type __cdecl
+# else
+# define XMLPARSEAPI(type) __declspec( dllimport ) type __cdecl
+# endif
+#else
+# define XMLPARSEAPI(type) type
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *XML_Parser;
+
+/* Information is UTF-8 encoded. */
+typedef char XML_Char;
+typedef char XML_LChar;
+
+enum XML_Content_Type {
+ XML_CTYPE_EMPTY = 1,
+ XML_CTYPE_ANY,
+ XML_CTYPE_MIXED,
+ XML_CTYPE_NAME,
+ XML_CTYPE_CHOICE,
+ XML_CTYPE_SEQ
+};
+
+enum XML_Content_Quant {
+ XML_CQUANT_NONE,
+ XML_CQUANT_OPT,
+ XML_CQUANT_REP,
+ XML_CQUANT_PLUS
+};
+
+/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
+ XML_CQUANT_NONE, and the other fields will be zero or NULL.
+ If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
+ numchildren will contain number of elements that may be mixed in
+ and children point to an array of XML_Content cells that will be
+ all of XML_CTYPE_NAME type with no quantification.
+
+ If type == XML_CTYPE_NAME, then the name points to the name, and
+ the numchildren field will be zero and children will be NULL. The
+ quant fields indicates any quantifiers placed on the name.
+
+ CHOICE and SEQ will have name NULL, the number of children in
+ numchildren and children will point, recursively, to an array
+ of XML_Content cells.
+
+ The EMPTY, ANY, and MIXED types will only occur at top level.
+*/
+
+typedef struct XML_cp XML_Content;
+
+struct XML_cp {
+ enum XML_Content_Type type;
+ enum XML_Content_Quant quant;
+ XML_Char * name;
+ unsigned int numchildren;
+ XML_Content * children;
+};
+
+
+/* This is called for an element declaration. See above for
+ description of the model argument. It's the caller's responsibility
+ to free model when finished with it.
+*/
+
+typedef void (*XML_ElementDeclHandler) (void *userData,
+ const XML_Char *name,
+ XML_Content *model);
+
+XMLPARSEAPI(void)
+XML_SetElementDeclHandler(XML_Parser parser,
+ XML_ElementDeclHandler eldecl);
+
+/*
+ The Attlist declaration handler is called for *each* attribute. So
+ a single Attlist declaration with multiple attributes declared will
+ generate multiple calls to this handler. The "default" parameter
+ may be NULL in the case of the "#IMPLIED" or "#REQUIRED" keyword.
+ The "isrequired" parameter will be true and the default value will
+ be NULL in the case of "#REQUIRED". If "isrequired" is true and
+ default is non-NULL, then this is a "#FIXED" default.
+ */
+
+typedef void (*XML_AttlistDeclHandler) (void *userData,
+ const XML_Char *elname,
+ const XML_Char *attname,
+ const XML_Char *att_type,
+ const XML_Char *dflt,
+ int isrequired);
+
+XMLPARSEAPI(void)
+XML_SetAttlistDeclHandler(XML_Parser parser,
+ XML_AttlistDeclHandler attdecl);
+
+
+ /* The XML declaration handler is called for *both* XML declarations and
+ text declarations. The way to distinguish is that the version parameter
+ will be null for text declarations. The encoding parameter may be null
+ for XML declarations. The standalone parameter will be -1, 0, or 1
+ indicating respectively that there was no standalone parameter in
+ the declaration, that it was given as no, or that it was given as yes.
+ */
+
+typedef void (*XML_XmlDeclHandler) (void *userData,
+ const XML_Char *version,
+ const XML_Char *encoding,
+ int standalone);
+
+XMLPARSEAPI(void)
+XML_SetXmlDeclHandler(XML_Parser parser,
+ XML_XmlDeclHandler xmldecl);
+
+
+typedef struct {
+ void *(*malloc_fcn)(size_t size);
+ void *(*realloc_fcn)(void *ptr, size_t size);
+ void (*free_fcn)(void *ptr);
+} XML_Memory_Handling_Suite;
+
+/* Constructs a new parser; encoding is the encoding specified by the
+external protocol or null if there is none specified. */
+
+XMLPARSEAPI(XML_Parser)
+XML_ParserCreate(const XML_Char *encoding);
+
+/* Constructs a new parser and namespace processor. Element type
+names and attribute names that belong to a namespace will be expanded;
+unprefixed attribute names are never expanded; unprefixed element type
+names are expanded only if there is a default namespace. The expanded
+name is the concatenation of the namespace URI, the namespace
+separator character, and the local part of the name. If the namespace
+separator is '\0' then the namespace URI and the local part will be
+concatenated without any separator. When a namespace is not declared,
+the name and prefix will be passed through without expansion. */
+
+XMLPARSEAPI(XML_Parser)
+XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
+
+
+/* Constructs a new parser using the memory management suit referred to
+ by memsuite. If memsuite is NULL, then use the standard library memory
+ suite. If namespaceSeparator is non-NULL it creates a parser with
+ namespace processing as described above. The character pointed at
+ will serve as the namespace separator.
+
+ All further memory operations used for the created parser will come from
+ the given suite.
+*/
+
+XMLPARSEAPI(XML_Parser)
+XML_ParserCreate_MM(const XML_Char *encoding,
+ const XML_Memory_Handling_Suite *memsuite,
+ const XML_Char *namespaceSeparator);
+
+/* atts is array of name/value pairs, terminated by 0;
+ names and values are 0 terminated. */
+
+typedef void (*XML_StartElementHandler)(void *userData,
+ const XML_Char *name,
+ const XML_Char **atts);
+
+typedef void (*XML_EndElementHandler)(void *userData,
+ const XML_Char *name);
+
+
+/* s is not 0 terminated. */
+typedef void (*XML_CharacterDataHandler)(void *userData,
+ const XML_Char *s,
+ int len);
+
+/* target and data are 0 terminated */
+typedef void (*XML_ProcessingInstructionHandler)(void *userData,
+ const XML_Char *target,
+ const XML_Char *data);
+
+/* data is 0 terminated */
+typedef void (*XML_CommentHandler)(void *userData, const XML_Char *data);
+
+typedef void (*XML_StartCdataSectionHandler)(void *userData);
+typedef void (*XML_EndCdataSectionHandler)(void *userData);
+
+/* This is called for any characters in the XML document for
+which there is no applicable handler. This includes both
+characters that are part of markup which is of a kind that is
+not reported (comments, markup declarations), or characters
+that are part of a construct which could be reported but
+for which no handler has been supplied. The characters are passed
+exactly as they were in the XML document except that
+they will be encoded in UTF-8. Line boundaries are not normalized.
+Note that a byte order mark character is not passed to the default handler.
+There are no guarantees about how characters are divided between calls
+to the default handler: for example, a comment might be split between
+multiple calls. */
+
+typedef void (*XML_DefaultHandler)(void *userData,
+ const XML_Char *s,
+ int len);
+
+/* This is called for the start of the DOCTYPE declaration, before
+ any DTD or internal subset is parsed. */
+
+typedef void (*XML_StartDoctypeDeclHandler)(void *userData,
+ const XML_Char *doctypeName,
+ const XML_Char *sysid,
+ const XML_Char *pubid,
+ int has_internal_subset);
+
+/* This is called for the start of the DOCTYPE declaration when the
+closing > is encountered, but after processing any external subset. */
+typedef void (*XML_EndDoctypeDeclHandler)(void *userData);
+
+/* This is called for entity declarations. The is_parameter_entity
+ argument will be non-zero if the entity is a parameter entity, zero
+ otherwise.
+
+ For internal entities (<!ENTITY foo "bar">), value will
+ be non-null and systemId, publicID, and notationName will be null.
+ The value string is NOT null terminated; the length is provided in
+ the value_length argument. Since it is legal to have zero-length
+ values, do not use this argument to test for internal entities.
+
+ For external entities, value will be null and systemId will be non-null.
+ The publicId argument will be null unless a public identifier was
+ provided. The notationName argument will have a non-null value only
+ for unparsed entity declarations.
+*/
+
+typedef void (*XML_EntityDeclHandler) (void *userData,
+ const XML_Char *entityName,
+ int is_parameter_entity,
+ const XML_Char *value,
+ int value_length,
+ const XML_Char *base,
+ const XML_Char *systemId,
+ const XML_Char *publicId,
+ const XML_Char *notationName);
+
+XMLPARSEAPI(void)
+XML_SetEntityDeclHandler(XML_Parser parser,
+ XML_EntityDeclHandler handler);
+
+/* OBSOLETE -- OBSOLETE -- OBSOLETE
+ This handler has been superceded by the EntityDeclHandler above.
+ It is provided here for backward compatibility.
+This is called for a declaration of an unparsed (NDATA)
+entity. The base argument is whatever was set by XML_SetBase.
+The entityName, systemId and notationName arguments will never be null.
+The other arguments may be. */
+
+typedef void (*XML_UnparsedEntityDeclHandler)(void *userData,
+ const XML_Char *entityName,
+ const XML_Char *base,
+ const XML_Char *systemId,
+ const XML_Char *publicId,
+ const XML_Char *notationName);
+
+/* This is called for a declaration of notation.
+The base argument is whatever was set by XML_SetBase.
+The notationName will never be null. The other arguments can be. */
+
+typedef void (*XML_NotationDeclHandler)(void *userData,
+ const XML_Char *notationName,
+ const XML_Char *base,
+ const XML_Char *systemId,
+ const XML_Char *publicId);
+
+/* When namespace processing is enabled, these are called once for
+each namespace declaration. The call to the start and end element
+handlers occur between the calls to the start and end namespace
+declaration handlers. For an xmlns attribute, prefix will be null.
+For an xmlns="" attribute, uri will be null. */
+
+typedef void (*XML_StartNamespaceDeclHandler)(void *userData,
+ const XML_Char *prefix,
+ const XML_Char *uri);
+
+typedef void (*XML_EndNamespaceDeclHandler)(void *userData,
+ const XML_Char *prefix);
+
+/* This is called if the document is not standalone (it has an
+external subset or a reference to a parameter entity, but does not
+have standalone="yes"). If this handler returns 0, then processing
+will not continue, and the parser will return a
+XML_ERROR_NOT_STANDALONE error. */
+
+typedef int (*XML_NotStandaloneHandler)(void *userData);
+
+/* This is called for a reference to an external parsed general entity.
+The referenced entity is not automatically parsed.
+The application can parse it immediately or later using
+XML_ExternalEntityParserCreate.
+The parser argument is the parser parsing the entity containing the reference;
+it can be passed as the parser argument to XML_ExternalEntityParserCreate.
+The systemId argument is the system identifier as specified in the entity
+declaration; it will not be null.
+The base argument is the system identifier that should be used as the base for
+resolving systemId if systemId was relative; this is set by XML_SetBase;
+it may be null.
+The publicId argument is the public identifier as specified in the entity
+declaration, or null if none was specified; the whitespace in the public
+identifier will have been normalized as required by the XML spec.
+The context argument specifies the parsing context in the format
+expected by the context argument to
+XML_ExternalEntityParserCreate; context is valid only until the handler
+returns, so if the referenced entity is to be parsed later, it must be copied.
+The handler should return 0 if processing should not continue because of
+a fatal error in the handling of the external entity.
+In this case the calling parser will return an
+XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
+Note that unlike other handlers the first argument is the parser, not
+userData. */
+
+typedef int (*XML_ExternalEntityRefHandler)(XML_Parser parser,
+ const XML_Char *context,
+ const XML_Char *base,
+ const XML_Char *systemId,
+ const XML_Char *publicId);
+
+/* This structure is filled in by the XML_UnknownEncodingHandler
+to provide information to the parser about encodings that are unknown
+to the parser.
+The map[b] member gives information about byte sequences
+whose first byte is b.
+If map[b] is c where c is >= 0, then b by itself encodes the Unicode scalar
+value c.
+If map[b] is -1, then the byte sequence is malformed.
+If map[b] is -n, where n >= 2, then b is the first byte of an n-byte
+sequence that encodes a single Unicode scalar value.
+The data member will be passed as the first argument to the convert function.
+The convert function is used to convert multibyte sequences;
+s will point to a n-byte sequence where map[(unsigned char)*s] == -n.
+The convert function must return the Unicode scalar value
+represented by this byte sequence or -1 if the byte sequence is malformed.
+The convert function may be null if the encoding is a single-byte encoding,
+that is if map[b] >= -1 for all bytes b.
+When the parser is finished with the encoding, then if release is not null,
+it will call release passing it the data member;
+once release has been called, the convert function will not be called again.
+
+Expat places certain restrictions on the encodings that are supported
+using this mechanism.
+
+1. Every ASCII character that can appear in a well-formed XML document,
+other than the characters
+
+ $@\^`{}~
+
+must be represented by a single byte, and that byte must be the
+same byte that represents that character in ASCII.
+
+2. No character may require more than 4 bytes to encode.
+
+3. All characters encoded must have Unicode scalar values <= 0xFFFF, (i.e.,
+characters that would be encoded by surrogates in UTF-16 are not
+allowed). Note that this restriction doesn't apply to the built-in
+support for UTF-8 and UTF-16.
+
+4. No Unicode character may be encoded by more than one distinct sequence
+of bytes. */
+
+typedef struct {
+ int map[256];
+ void *data;
+ int (*convert)(void *data, const char *s);
+ void (*release)(void *data);
+} XML_Encoding;
+
+/* This is called for an encoding that is unknown to the parser.
+The encodingHandlerData argument is that which was passed as the
+second argument to XML_SetUnknownEncodingHandler.
+The name argument gives the name of the encoding as specified in
+the encoding declaration.
+If the callback can provide information about the encoding,
+it must fill in the XML_Encoding structure, and return 1.
+Otherwise it must return 0.
+If info does not describe a suitable encoding,
+then the parser will return an XML_UNKNOWN_ENCODING error. */
+
+typedef int (*XML_UnknownEncodingHandler)(void *encodingHandlerData,
+ const XML_Char *name,
+ XML_Encoding *info);
+
+XMLPARSEAPI(void)
+XML_SetElementHandler(XML_Parser parser,
+ XML_StartElementHandler start,
+ XML_EndElementHandler end);
+
+XMLPARSEAPI(void)
+XML_SetStartElementHandler(XML_Parser, XML_StartElementHandler);
+
+XMLPARSEAPI(void)
+XML_SetEndElementHandler(XML_Parser, XML_EndElementHandler);
+
+XMLPARSEAPI(void)
+XML_SetCharacterDataHandler(XML_Parser parser,
+ XML_CharacterDataHandler handler);
+
+XMLPARSEAPI(void)
+XML_SetProcessingInstructionHandler(XML_Parser parser,
+ XML_ProcessingInstructionHandler handler);
+XMLPARSEAPI(void)
+XML_SetCommentHandler(XML_Parser parser,
+ XML_CommentHandler handler);
+
+XMLPARSEAPI(void)
+XML_SetCdataSectionHandler(XML_Parser parser,
+ XML_StartCdataSectionHandler start,
+ XML_EndCdataSectionHandler end);
+
+XMLPARSEAPI(void)
+XML_SetStartCdataSectionHandler(XML_Parser parser,
+ XML_StartCdataSectionHandler start);
+
+XMLPARSEAPI(void)
+XML_SetEndCdataSectionHandler(XML_Parser parser,
+ XML_EndCdataSectionHandler end);
+
+/* This sets the default handler and also inhibits expansion of
+internal entities. The entity reference will be passed to the default
+handler. */
+
+XMLPARSEAPI(void)
+XML_SetDefaultHandler(XML_Parser parser,
+ XML_DefaultHandler handler);
+
+/* This sets the default handler but does not inhibit expansion of
+internal entities. The entity reference will not be passed to the
+default handler. */
+
+XMLPARSEAPI(void)
+XML_SetDefaultHandlerExpand(XML_Parser parser,
+ XML_DefaultHandler handler);
+
+XMLPARSEAPI(void)
+XML_SetDoctypeDeclHandler(XML_Parser parser,
+ XML_StartDoctypeDeclHandler start,
+ XML_EndDoctypeDeclHandler end);
+
+XMLPARSEAPI(void)
+XML_SetStartDoctypeDeclHandler(XML_Parser parser,
+ XML_StartDoctypeDeclHandler start);
+
+XMLPARSEAPI(void)
+XML_SetEndDoctypeDeclHandler(XML_Parser parser,
+ XML_EndDoctypeDeclHandler end);
+
+XMLPARSEAPI(void)
+XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
+ XML_UnparsedEntityDeclHandler handler);
+
+XMLPARSEAPI(void)
+XML_SetNotationDeclHandler(XML_Parser parser,
+ XML_NotationDeclHandler handler);
+
+XMLPARSEAPI(void)
+XML_SetNamespaceDeclHandler(XML_Parser parser,
+ XML_StartNamespaceDeclHandler start,
+ XML_EndNamespaceDeclHandler end);
+
+XMLPARSEAPI(void)
+XML_SetStartNamespaceDeclHandler(XML_Parser parser,
+ XML_StartNamespaceDeclHandler start);
+
+XMLPARSEAPI(void)
+XML_SetEndNamespaceDeclHandler(XML_Parser parser,
+ XML_EndNamespaceDeclHandler end);
+
+XMLPARSEAPI(void)
+XML_SetNotStandaloneHandler(XML_Parser parser,
+ XML_NotStandaloneHandler handler);
+
+XMLPARSEAPI(void)
+XML_SetExternalEntityRefHandler(XML_Parser parser,
+ XML_ExternalEntityRefHandler handler);
+
+/* If a non-null value for arg is specified here, then it will be passed
+as the first argument to the external entity ref handler instead
+of the parser object. */
+XMLPARSEAPI(void)
+XML_SetExternalEntityRefHandlerArg(XML_Parser, void *arg);
+
+XMLPARSEAPI(void)
+XML_SetUnknownEncodingHandler(XML_Parser parser,
+ XML_UnknownEncodingHandler handler,
+ void *encodingHandlerData);
+
+/* This can be called within a handler for a start element, end element,
+processing instruction or character data. It causes the corresponding
+markup to be passed to the default handler. */
+XMLPARSEAPI(void)
+XML_DefaultCurrent(XML_Parser parser);
+
+/* If do_nst is non-zero, and namespace processing is in effect, and
+ a name has a prefix (i.e. an explicit namespace qualifier) then
+ that name is returned as a triplet in a single
+ string separated by the separator character specified when the parser
+ was created: URI + sep + local_name + sep + prefix.
+
+ If do_nst is zero, then namespace information is returned in the
+ default manner (URI + sep + local_name) whether or not the names
+ has a prefix.
+*/
+
+XMLPARSEAPI(void)
+XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
+
+/* This value is passed as the userData argument to callbacks. */
+XMLPARSEAPI(void)
+XML_SetUserData(XML_Parser parser, void *userData);
+
+/* Returns the last value set by XML_SetUserData or null. */
+#define XML_GetUserData(parser) (*(void **)(parser))
+
+/* This is equivalent to supplying an encoding argument
+to XML_ParserCreate. It must not be called after XML_Parse
+or XML_ParseBuffer. */
+
+XMLPARSEAPI(int)
+XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
+
+/* If this function is called, then the parser will be passed
+as the first argument to callbacks instead of userData.
+The userData will still be accessible using XML_GetUserData. */
+
+XMLPARSEAPI(void)
+XML_UseParserAsHandlerArg(XML_Parser parser);
+
+/* Sets the base to be used for resolving relative URIs in system
+identifiers in declarations. Resolving relative identifiers is left
+to the application: this value will be passed through as the base
+argument to the XML_ExternalEntityRefHandler, XML_NotationDeclHandler
+and XML_UnparsedEntityDeclHandler. The base argument will be copied.
+Returns zero if out of memory, non-zero otherwise. */
+
+XMLPARSEAPI(int)
+XML_SetBase(XML_Parser parser, const XML_Char *base);
+
+XMLPARSEAPI(const XML_Char *)
+XML_GetBase(XML_Parser parser);
+
+/* Returns the number of the attribute/value pairs passed in last call
+to the XML_StartElementHandler that were specified in the start-tag
+rather than defaulted. Each attribute/value pair counts as 2; thus
+this correspondds to an index into the atts array passed to the
+XML_StartElementHandler. */
+
+XMLPARSEAPI(int)
+XML_GetSpecifiedAttributeCount(XML_Parser parser);
+
+/* Returns the index of the ID attribute passed in the last call to
+XML_StartElementHandler, or -1 if there is no ID attribute. Each
+attribute/value pair counts as 2; thus this correspondds to an index
+into the atts array passed to the XML_StartElementHandler. */
+
+XMLPARSEAPI(int)
+XML_GetIdAttributeIndex(XML_Parser parser);
+
+/* Parses some input. Returns 0 if a fatal error is detected.
+The last call to XML_Parse must have isFinal true;
+len may be zero for this call (or any other). */
+XMLPARSEAPI(int)
+XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
+
+XMLPARSEAPI(void *)
+XML_GetBuffer(XML_Parser parser, int len);
+
+XMLPARSEAPI(int)
+XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
+
+/* Creates an XML_Parser object that can parse an external general
+entity; context is a '\0'-terminated string specifying the parse
+context; encoding is a '\0'-terminated string giving the name of the
+externally specified encoding, or null if there is no externally
+specified encoding. The context string consists of a sequence of
+tokens separated by formfeeds (\f); a token consisting of a name
+specifies that the general entity of the name is open; a token of the
+form prefix=uri specifies the namespace for a particular prefix; a
+token of the form =uri specifies the default namespace. This can be
+called at any point after the first call to an
+ExternalEntityRefHandler so longer as the parser has not yet been
+freed. The new parser is completely independent and may safely be
+used in a separate thread. The handlers and userData are initialized
+from the parser argument. Returns 0 if out of memory. Otherwise
+returns a new XML_Parser object. */
+XMLPARSEAPI(XML_Parser)
+XML_ExternalEntityParserCreate(XML_Parser parser,
+ const XML_Char *context,
+ const XML_Char *encoding);
+
+enum XML_ParamEntityParsing {
+ XML_PARAM_ENTITY_PARSING_NEVER,
+ XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
+ XML_PARAM_ENTITY_PARSING_ALWAYS
+};
+
+/* Controls parsing of parameter entities (including the external DTD
+subset). If parsing of parameter entities is enabled, then references
+to external parameter entities (including the external DTD subset)
+will be passed to the handler set with
+XML_SetExternalEntityRefHandler. The context passed will be 0.
+Unlike external general entities, external parameter entities can only
+be parsed synchronously. If the external parameter entity is to be
+parsed, it must be parsed during the call to the external entity ref
+handler: the complete sequence of XML_ExternalEntityParserCreate,
+XML_Parse/XML_ParseBuffer and XML_ParserFree calls must be made during
+this call. After XML_ExternalEntityParserCreate has been called to
+create the parser for the external parameter entity (context must be 0
+for this call), it is illegal to make any calls on the old parser
+until XML_ParserFree has been called on the newly created parser. If
+the library has been compiled without support for parameter entity
+parsing (ie without XML_DTD being defined), then
+XML_SetParamEntityParsing will return 0 if parsing of parameter
+entities is requested; otherwise it will return non-zero. */
+
+XMLPARSEAPI(int)
+XML_SetParamEntityParsing(XML_Parser parser,
+ enum XML_ParamEntityParsing parsing);
+
+enum XML_Error {
+ XML_ERROR_NONE,
+ XML_ERROR_NO_MEMORY,
+ XML_ERROR_SYNTAX,
+ XML_ERROR_NO_ELEMENTS,
+ XML_ERROR_INVALID_TOKEN,
+ XML_ERROR_UNCLOSED_TOKEN,
+ XML_ERROR_PARTIAL_CHAR,
+ XML_ERROR_TAG_MISMATCH,
+ XML_ERROR_DUPLICATE_ATTRIBUTE,
+ XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
+ XML_ERROR_PARAM_ENTITY_REF,
+ XML_ERROR_UNDEFINED_ENTITY,
+ XML_ERROR_RECURSIVE_ENTITY_REF,
+ XML_ERROR_ASYNC_ENTITY,
+ XML_ERROR_BAD_CHAR_REF,
+ XML_ERROR_BINARY_ENTITY_REF,
+ XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
+ XML_ERROR_MISPLACED_XML_PI,
+ XML_ERROR_UNKNOWN_ENCODING,
+ XML_ERROR_INCORRECT_ENCODING,
+ XML_ERROR_UNCLOSED_CDATA_SECTION,
+ XML_ERROR_EXTERNAL_ENTITY_HANDLING,
+ XML_ERROR_NOT_STANDALONE,
+ XML_ERROR_UNEXPECTED_STATE
+};
+
+/* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
+returns information about the error. */
+
+XMLPARSEAPI(enum XML_Error)
+XML_GetErrorCode(XML_Parser parser);
+
+/* These functions return information about the current parse location.
+They may be called when XML_Parse or XML_ParseBuffer return 0;
+in this case the location is the location of the character at which
+the error was detected.
+They may also be called from any other callback called to report
+some parse event; in this the location is the location of the first
+of the sequence of characters that generated the event. */
+
+XMLPARSEAPI(int) XML_GetCurrentLineNumber(XML_Parser parser);
+XMLPARSEAPI(int) XML_GetCurrentColumnNumber(XML_Parser parser);
+XMLPARSEAPI(long) XML_GetCurrentByteIndex(XML_Parser parser);
+
+/* Return the number of bytes in the current event.
+Returns 0 if the event is in an internal entity. */
+
+XMLPARSEAPI(int)
+XML_GetCurrentByteCount(XML_Parser parser);
+
+/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
+ the integer pointed to by offset to the offset within this buffer
+ of the current parse position, and sets the integer pointed to by size
+ to the size of this buffer (the number of input bytes). Otherwise
+ returns a null pointer. Also returns a null pointer if a parse isn't
+ active.
+
+ NOTE: The character pointer returned should not be used outside
+ the handler that makes the call. */
+
+XMLPARSEAPI(const char *)
+XML_GetInputContext(XML_Parser parser,
+ int *offset,
+ int *size);
+
+/* For backwards compatibility with previous versions. */
+#define XML_GetErrorLineNumber XML_GetCurrentLineNumber
+#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
+#define XML_GetErrorByteIndex XML_GetCurrentByteIndex
+
+/* Frees memory used by the parser. */
+XMLPARSEAPI(void)
+XML_ParserFree(XML_Parser parser);
+
+/* Returns a string describing the error. */
+XMLPARSEAPI(const XML_LChar *)
+XML_ErrorString(int code);
+
+/* Return a string containing the version number of this expat */
+XMLPARSEAPI(const XML_LChar *)
+XML_ExpatVersion(void);
+
+typedef struct {
+ int major;
+ int minor;
+ int micro;
+} XML_Expat_Version;
+
+/* Return an XML_Expat_Version structure containing numeric version
+ number information for this version of expat */
+
+XMLPARSEAPI(XML_Expat_Version)
+XML_ExpatVersionInfo(void);
+
+#define XML_MAJOR_VERSION 1
+#define XML_MINOR_VERSION 95
+#define XML_MICRO_VERSION 2
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* not XmlParse_INCLUDED */
diff --git a/Utilities/cmexpat/expatConfig.h.in b/Utilities/cmexpat/expatConfig.h.in
new file mode 100644
index 0000000000..8f9669a597
--- /dev/null
+++ b/Utilities/cmexpat/expatConfig.h.in
@@ -0,0 +1,43 @@
+#include "cm_expat_mangle.h"
+#if defined(_WIN32) || defined(WIN32)
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#undef WIN32_LEAN_AND_MEAN
+#include <memory.h>
+#include <string.h>
+#define XML_BYTE_ORDER 12
+
+#else
+
+#cmakedefine CMEXPAT_BIGENDIAN
+#ifdef CMEXPAT_BIGENDIAN
+# define XML_BYTE_ORDER 21
+#else
+# define XML_BYTE_ORDER 12
+#endif
+
+#endif
+
+#define XML_NS
+#define XML_DTD
+#define XML_CONTEXT_BYTES 1024
+
+#if defined ( _MSC_VER )
+#pragma warning ( disable : 4100 )
+#pragma warning ( disable : 4127 )
+#pragma warning ( disable : 4244 )
+#pragma warning ( disable : 4251 )
+#pragma warning ( disable : 4305 )
+#pragma warning ( disable : 4309 )
+#pragma warning ( disable : 4702 )
+#pragma warning ( disable : 4706 )
+#pragma warning ( disable : 4786 )
+#pragma warning ( disable : 4057 )
+#pragma warning ( disable : 4189 )
+#pragma warning ( disable : 4505 )
+#endif
+
+#define VERSION "1.95.2"
+
+#define cmExpatUnused(x) (void)x
diff --git a/Utilities/cmexpat/expatDllConfig.h.in b/Utilities/cmexpat/expatDllConfig.h.in
new file mode 100644
index 0000000000..eaaf4b0188
--- /dev/null
+++ b/Utilities/cmexpat/expatDllConfig.h.in
@@ -0,0 +1,6 @@
+#ifndef _expatDllConfig_h
+#define _expatDllConfig_h
+
+#cmakedefine CM_EXPAT_STATIC
+
+#endif
diff --git a/Utilities/cmexpat/iasciitab.h b/Utilities/cmexpat/iasciitab.h
new file mode 100644
index 0000000000..55dbc398b8
--- /dev/null
+++ b/Utilities/cmexpat/iasciitab.h
@@ -0,0 +1,38 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+/* Like asciitab.h, except that 0xD has code BT_S rather than BT_CR */
+/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML,
+/* 0x0C */ BT_NONXML, BT_S, BT_NONXML, BT_NONXML,
+/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM,
+/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS,
+/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS,
+/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL,
+/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT,
+/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT,
+/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI,
+/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST,
+/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX,
+/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT,
+/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB,
+/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT,
+/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX,
+/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT,
+/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER,
+/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER,
diff --git a/Utilities/cmexpat/latin1tab.h b/Utilities/cmexpat/latin1tab.h
new file mode 100644
index 0000000000..178b1d186d
--- /dev/null
+++ b/Utilities/cmexpat/latin1tab.h
@@ -0,0 +1,37 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+/* 0x80 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0x84 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0x88 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0x8C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0x90 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0x94 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0x98 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0x9C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0xA0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0xA4 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0xA8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER,
+/* 0xAC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0xB0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0xB4 */ BT_OTHER, BT_NMSTRT, BT_OTHER, BT_NAME,
+/* 0xB8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER,
+/* 0xBC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
+/* 0xC0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xC4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xC8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xCC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xD0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xD4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER,
+/* 0xD8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xDC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xE0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xE4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xE8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xEC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xF0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xF4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER,
+/* 0xF8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
+/* 0xFC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
diff --git a/Utilities/cmexpat/nametab.h b/Utilities/cmexpat/nametab.h
new file mode 100644
index 0000000000..b05e62c77a
--- /dev/null
+++ b/Utilities/cmexpat/nametab.h
@@ -0,0 +1,150 @@
+static const unsigned namingBitmap[] = {
+0x00000000, 0x00000000, 0x00000000, 0x00000000,
+0x00000000, 0x00000000, 0x00000000, 0x00000000,
+0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+0x00000000, 0x04000000, 0x87FFFFFE, 0x07FFFFFE,
+0x00000000, 0x00000000, 0xFF7FFFFF, 0xFF7FFFFF,
+0xFFFFFFFF, 0x7FF3FFFF, 0xFFFFFDFE, 0x7FFFFFFF,
+0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE00F, 0xFC31FFFF,
+0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF,
+0xFFFFFFFF, 0xF80001FF, 0x00000003, 0x00000000,
+0x00000000, 0x00000000, 0x00000000, 0x00000000,
+0xFFFFD740, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD,
+0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF,
+0xFFFF0003, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF,
+0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE,
+0x0000007F, 0x00000000, 0xFFFF0000, 0x000707FF,
+0x00000000, 0x07FFFFFE, 0x000007FE, 0xFFFE0000,
+0xFFFFFFFF, 0x7CFFFFFF, 0x002F7FFF, 0x00000060,
+0xFFFFFFE0, 0x23FFFFFF, 0xFF000000, 0x00000003,
+0xFFF99FE0, 0x03C5FDFF, 0xB0000000, 0x00030003,
+0xFFF987E0, 0x036DFDFF, 0x5E000000, 0x001C0000,
+0xFFFBAFE0, 0x23EDFDFF, 0x00000000, 0x00000001,
+0xFFF99FE0, 0x23CDFDFF, 0xB0000000, 0x00000003,
+0xD63DC7E0, 0x03BFC718, 0x00000000, 0x00000000,
+0xFFFDDFE0, 0x03EFFDFF, 0x00000000, 0x00000003,
+0xFFFDDFE0, 0x03EFFDFF, 0x40000000, 0x00000003,
+0xFFFDDFE0, 0x03FFFDFF, 0x00000000, 0x00000003,
+0x00000000, 0x00000000, 0x00000000, 0x00000000,
+0xFFFFFFFE, 0x000D7FFF, 0x0000003F, 0x00000000,
+0xFEF02596, 0x200D6CAE, 0x0000001F, 0x00000000,
+0x00000000, 0x00000000, 0xFFFFFEFF, 0x000003FF,
+0x00000000, 0x00000000, 0x00000000, 0x00000000,
+0x00000000, 0x00000000, 0x00000000, 0x00000000,
+0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x007FFFFF,
+0x0007DAED, 0x50000000, 0x82315001, 0x002C62AB,
+0x40000000, 0xF580C900, 0x00000007, 0x02010800,
+0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+0x0FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x03FFFFFF,
+0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF,
+0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF,
+0x00000000, 0x00004C40, 0x00000000, 0x00000000,
+0x00000007, 0x00000000, 0x00000000, 0x00000000,
+0x00000080, 0x000003FE, 0xFFFFFFFE, 0xFFFFFFFF,
+0x001FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x07FFFFFF,
+0xFFFFFFE0, 0x00001FFF, 0x00000000, 0x00000000,
+0x00000000, 0x00000000, 0x00000000, 0x00000000,
+0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000,
+0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+0xFFFFFFFF, 0x0000000F, 0x00000000, 0x00000000,
+0x00000000, 0x07FF6000, 0x87FFFFFE, 0x07FFFFFE,
+0x00000000, 0x00800000, 0xFF7FFFFF, 0xFF7FFFFF,
+0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF,
+0xFFFFFFFF, 0xF80001FF, 0x00030003, 0x00000000,
+0xFFFFFFFF, 0xFFFFFFFF, 0x0000003F, 0x00000003,
+0xFFFFD7C0, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD,
+0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF,
+0xFFFF007B, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF,
+0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE,
+0xFFFE007F, 0xBBFFFFFB, 0xFFFF0016, 0x000707FF,
+0x00000000, 0x07FFFFFE, 0x0007FFFF, 0xFFFF03FF,
+0xFFFFFFFF, 0x7CFFFFFF, 0xFFEF7FFF, 0x03FF3DFF,
+0xFFFFFFEE, 0xF3FFFFFF, 0xFF1E3FFF, 0x0000FFCF,
+0xFFF99FEE, 0xD3C5FDFF, 0xB080399F, 0x0003FFCF,
+0xFFF987E4, 0xD36DFDFF, 0x5E003987, 0x001FFFC0,
+0xFFFBAFEE, 0xF3EDFDFF, 0x00003BBF, 0x0000FFC1,
+0xFFF99FEE, 0xF3CDFDFF, 0xB0C0398F, 0x0000FFC3,
+0xD63DC7EC, 0xC3BFC718, 0x00803DC7, 0x0000FF80,
+0xFFFDDFEE, 0xC3EFFDFF, 0x00603DDF, 0x0000FFC3,
+0xFFFDDFEC, 0xC3EFFDFF, 0x40603DDF, 0x0000FFC3,
+0xFFFDDFEC, 0xC3FFFDFF, 0x00803DCF, 0x0000FFC3,
+0x00000000, 0x00000000, 0x00000000, 0x00000000,
+0xFFFFFFFE, 0x07FF7FFF, 0x03FF7FFF, 0x00000000,
+0xFEF02596, 0x3BFF6CAE, 0x03FF3F5F, 0x00000000,
+0x03000000, 0xC2A003FF, 0xFFFFFEFF, 0xFFFE03FF,
+0xFEBF0FDF, 0x02FE3FFF, 0x00000000, 0x00000000,
+0x00000000, 0x00000000, 0x00000000, 0x00000000,
+0x00000000, 0x00000000, 0x1FFF0000, 0x00000002,
+0x000000A0, 0x003EFFFE, 0xFFFFFFFE, 0xFFFFFFFF,
+0x661FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x77FFFFFF,
+};
+static const unsigned char nmstrtPages[] = {
+0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00,
+0x00, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13,
+0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x15, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+static const unsigned char namePages[] = {
+0x19, 0x03, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x00,
+0x00, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
+0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13,
+0x26, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x27, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
diff --git a/Utilities/cmexpat/utf8tab.h b/Utilities/cmexpat/utf8tab.h
new file mode 100644
index 0000000000..9e3b6b83eb
--- /dev/null
+++ b/Utilities/cmexpat/utf8tab.h
@@ -0,0 +1,38 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+
+/* 0x80 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0x88 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0x8C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0x90 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0x94 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0x98 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0x9C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0xA0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0xA4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0xA8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0xAC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0xB0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0xB4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0xB8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0xBC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
+/* 0xC0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
+/* 0xC4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
+/* 0xC8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
+/* 0xCC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
+/* 0xD0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
+/* 0xD4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
+/* 0xD8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
+/* 0xDC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
+/* 0xE0 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3,
+/* 0xE4 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3,
+/* 0xE8 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3,
+/* 0xEC */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3,
+/* 0xF0 */ BT_LEAD4, BT_LEAD4, BT_LEAD4, BT_LEAD4,
+/* 0xF4 */ BT_LEAD4, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0xF8 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
+/* 0xFC */ BT_NONXML, BT_NONXML, BT_MALFORM, BT_MALFORM,
diff --git a/Utilities/cmexpat/xmlparse.c b/Utilities/cmexpat/xmlparse.c
new file mode 100644
index 0000000000..29ea3d3d76
--- /dev/null
+++ b/Utilities/cmexpat/xmlparse.c
@@ -0,0 +1,4622 @@
+/*
+Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+#include <cmexpat/expatConfig.h>
+#include <cmexpat/expat.h>
+
+#include <stddef.h>
+#include <string.h>
+
+#ifdef XML_UNICODE
+#define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX
+#define XmlConvert XmlUtf16Convert
+#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding
+#define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS
+#define XmlEncode XmlUtf16Encode
+#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((unsigned long)s) & 1))
+typedef unsigned short ICHAR;
+#else
+#define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX
+#define XmlConvert XmlUtf8Convert
+#define XmlGetInternalEncoding XmlGetUtf8InternalEncoding
+#define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS
+#define XmlEncode XmlUtf8Encode
+#define MUST_CONVERT(enc, s) (!(enc)->isUtf8)
+typedef char ICHAR;
+#endif
+
+
+#ifndef XML_NS
+
+#define XmlInitEncodingNS XmlInitEncoding
+#define XmlInitUnknownEncodingNS XmlInitUnknownEncoding
+#undef XmlGetInternalEncodingNS
+#define XmlGetInternalEncodingNS XmlGetInternalEncoding
+#define XmlParseXmlDeclNS XmlParseXmlDecl
+
+#endif
+
+#ifdef XML_UNICODE_WCHAR_T
+#define XML_T(x) L ## x
+#else
+#define XML_T(x) x
+#endif
+
+/* Round up n to be a multiple of sz, where sz is a power of 2. */
+#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
+
+#include "xmltok.h"
+#include "xmlrole.h"
+
+typedef const XML_Char *KEY;
+
+typedef struct {
+ KEY name;
+} NAMED;
+
+typedef struct {
+ NAMED **v;
+ size_t size;
+ size_t used;
+ size_t usedLim;
+ XML_Memory_Handling_Suite *mem;
+} HASH_TABLE;
+
+typedef struct {
+ NAMED **p;
+ NAMED **end;
+} HASH_TABLE_ITER;
+
+#define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */
+#define INIT_DATA_BUF_SIZE 1024
+#define INIT_ATTS_SIZE 16
+#define INIT_BLOCK_SIZE 1024
+#define INIT_BUFFER_SIZE 1024
+
+#define EXPAND_SPARE 24
+
+typedef struct binding {
+ struct prefix *prefix;
+ struct binding *nextTagBinding;
+ struct binding *prevPrefixBinding;
+ const struct attribute_id *attId;
+ XML_Char *uri;
+ int uriLen;
+ int uriAlloc;
+} BINDING;
+
+typedef struct prefix {
+ const XML_Char *name;
+ BINDING *binding;
+} PREFIX;
+
+typedef struct {
+ const XML_Char *str;
+ const XML_Char *localPart;
+ int uriLen;
+} TAG_NAME;
+
+typedef struct tag {
+ struct tag *parent;
+ const char *rawName;
+ int rawNameLength;
+ TAG_NAME name;
+ char *buf;
+ char *bufEnd;
+ BINDING *bindings;
+} TAG;
+
+typedef struct {
+ const XML_Char *name;
+ const XML_Char *textPtr;
+ int textLen;
+ const XML_Char *systemId;
+ const XML_Char *base;
+ const XML_Char *publicId;
+ const XML_Char *notation;
+ char open;
+ char is_param;
+} ENTITY;
+
+typedef struct {
+ enum XML_Content_Type type;
+ enum XML_Content_Quant quant;
+ const XML_Char * name;
+ int firstchild;
+ int lastchild;
+ int childcnt;
+ int nextsib;
+} CONTENT_SCAFFOLD;
+
+typedef struct block {
+ struct block *next;
+ int size;
+ XML_Char s[1];
+} BLOCK;
+
+typedef struct {
+ BLOCK *blocks;
+ BLOCK *freeBlocks;
+ const XML_Char *end;
+ XML_Char *ptr;
+ XML_Char *start;
+ XML_Memory_Handling_Suite *mem;
+} STRING_POOL;
+
+/* The XML_Char before the name is used to determine whether
+an attribute has been specified. */
+typedef struct attribute_id {
+ XML_Char *name;
+ PREFIX *prefix;
+ char maybeTokenized;
+ char xmlns;
+} ATTRIBUTE_ID;
+
+typedef struct {
+ const ATTRIBUTE_ID *id;
+ char isCdata;
+ const XML_Char *value;
+} DEFAULT_ATTRIBUTE;
+
+typedef struct {
+ const XML_Char *name;
+ PREFIX *prefix;
+ const ATTRIBUTE_ID *idAtt;
+ int nDefaultAtts;
+ int allocDefaultAtts;
+ DEFAULT_ATTRIBUTE *defaultAtts;
+} ELEMENT_TYPE;
+
+typedef struct {
+ HASH_TABLE generalEntities;
+ HASH_TABLE elementTypes;
+ HASH_TABLE attributeIds;
+ HASH_TABLE prefixes;
+ STRING_POOL pool;
+ int complete;
+ int standalone;
+#ifdef XML_DTD
+ HASH_TABLE paramEntities;
+#endif /* XML_DTD */
+ PREFIX defaultPrefix;
+ /* === scaffolding for building content model === */
+ int in_eldecl;
+ CONTENT_SCAFFOLD *scaffold;
+ unsigned contentStringLen;
+ unsigned scaffSize;
+ unsigned scaffCount;
+ int scaffLevel;
+ int *scaffIndex;
+} DTD;
+
+typedef struct open_internal_entity {
+ const char *internalEventPtr;
+ const char *internalEventEndPtr;
+ struct open_internal_entity *next;
+ ENTITY *entity;
+} OPEN_INTERNAL_ENTITY;
+
+typedef enum XML_Error Processor(XML_Parser parser,
+ const char *start,
+ const char *end,
+ const char **endPtr);
+
+static Processor prologProcessor;
+static Processor prologInitProcessor;
+static Processor contentProcessor;
+static Processor cdataSectionProcessor;
+#ifdef XML_DTD
+static Processor ignoreSectionProcessor;
+#endif /* XML_DTD */
+static Processor epilogProcessor;
+static Processor errorProcessor;
+static Processor externalEntityInitProcessor;
+static Processor externalEntityInitProcessor2;
+static Processor externalEntityInitProcessor3;
+static Processor externalEntityContentProcessor;
+
+static enum XML_Error
+handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName);
+static enum XML_Error
+processXmlDecl(XML_Parser parser, int isGeneralTextEntity, const char *, const char *);
+static enum XML_Error
+initializeEncoding(XML_Parser parser);
+static enum XML_Error
+doProlog(XML_Parser parser, const ENCODING *enc, const char *s,
+ const char *end, int tok, const char *next, const char **nextPtr);
+static enum XML_Error
+processInternalParamEntity(XML_Parser parser, ENTITY *entity);
+static enum XML_Error
+doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc,
+ const char *start, const char *end, const char **endPtr);
+static enum XML_Error
+doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, const char *end, const char **nextPtr);
+#ifdef XML_DTD
+static enum XML_Error
+doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, const char *end, const char **nextPtr);
+#endif /* XML_DTD */
+static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *, const char *s,
+ TAG_NAME *tagNamePtr, BINDING **bindingsPtr);
+static
+int addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, const XML_Char *uri, BINDING **bindingsPtr);
+
+static int
+defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *,
+ int isCdata, int isId, const XML_Char *dfltValue,
+ XML_Parser parser);
+
+static enum XML_Error
+storeAttributeValue(XML_Parser parser, const ENCODING *, int isCdata, const char *, const char *,
+ STRING_POOL *);
+static enum XML_Error
+appendAttributeValue(XML_Parser parser, const ENCODING *, int isCdata, const char *, const char *,
+ STRING_POOL *);
+static ATTRIBUTE_ID *
+getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, const char *end);
+static int setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *);
+static enum XML_Error
+storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, const char *end);
+static int
+reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, const char *start, const char *end);
+static int
+reportComment(XML_Parser parser, const ENCODING *enc, const char *start, const char *end);
+static void
+reportDefault(XML_Parser parser, const ENCODING *enc, const char *start, const char *end);
+
+static const XML_Char *getContext(XML_Parser parser);
+static int setContext(XML_Parser parser, const XML_Char *context);
+static void normalizePublicId(XML_Char *s);
+static int dtdInit(DTD *, XML_Parser parser);
+
+static void dtdDestroy(DTD *, XML_Parser parser);
+
+static int dtdCopy(DTD *newDtd, const DTD *oldDtd, XML_Parser parser);
+
+static int copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *,
+ XML_Parser parser);
+
+#ifdef XML_DTD
+static void dtdSwap(DTD *, DTD *);
+#endif /* XML_DTD */
+
+static NAMED *lookup(HASH_TABLE *table, KEY name, size_t createSize);
+
+static void hashTableInit(HASH_TABLE *, XML_Memory_Handling_Suite *ms);
+
+static void hashTableDestroy(HASH_TABLE *);
+static void hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *);
+static NAMED *hashTableIterNext(HASH_TABLE_ITER *);
+static void poolInit(STRING_POOL *, XML_Memory_Handling_Suite *ms);
+static void poolClear(STRING_POOL *);
+static void poolDestroy(STRING_POOL *);
+static XML_Char *poolAppend(STRING_POOL *pool, const ENCODING *enc,
+ const char *ptr, const char *end);
+static XML_Char *poolStoreString(STRING_POOL *pool, const ENCODING *enc,
+ const char *ptr, const char *end);
+
+static int poolGrow(STRING_POOL *pool);
+
+static int nextScaffoldPart(XML_Parser parser);
+static XML_Content *build_model(XML_Parser parser);
+
+static const XML_Char *poolCopyString(STRING_POOL *pool, const XML_Char *s);
+static const XML_Char *poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n);
+static const XML_Char *poolAppendString(STRING_POOL *pool, const XML_Char *s);
+static ELEMENT_TYPE * getElementType(XML_Parser Paraser,
+ const ENCODING *enc,
+ const char *ptr,
+ const char *end);
+
+#define poolStart(pool) ((pool)->start)
+#define poolEnd(pool) ((pool)->ptr)
+#define poolLength(pool) ((pool)->ptr - (pool)->start)
+#define poolChop(pool) ((void)--(pool->ptr))
+#define poolLastChar(pool) (((pool)->ptr)[-1])
+#define poolDiscard(pool) ((pool)->ptr = (pool)->start)
+#define poolFinish(pool) ((pool)->start = (pool)->ptr)
+#define poolAppendChar(pool, c) \
+ (((pool)->ptr == (pool)->end && !poolGrow(pool)) \
+ ? 0 \
+ : ((*((pool)->ptr)++ = c), 1))
+
+typedef struct {
+ /* The first member must be userData so that the XML_GetUserData macro works. */
+ void *m_userData;
+ void *m_handlerArg;
+ char *m_buffer;
+ XML_Memory_Handling_Suite m_mem;
+ /* first character to be parsed */
+ const char *m_bufferPtr;
+ /* past last character to be parsed */
+ char *m_bufferEnd;
+ /* allocated end of buffer */
+ const char *m_bufferLim;
+ long m_parseEndByteIndex;
+ const char *m_parseEndPtr;
+ XML_Char *m_dataBuf;
+ XML_Char *m_dataBufEnd;
+ XML_StartElementHandler m_startElementHandler;
+ XML_EndElementHandler m_endElementHandler;
+ XML_CharacterDataHandler m_characterDataHandler;
+ XML_ProcessingInstructionHandler m_processingInstructionHandler;
+ XML_CommentHandler m_commentHandler;
+ XML_StartCdataSectionHandler m_startCdataSectionHandler;
+ XML_EndCdataSectionHandler m_endCdataSectionHandler;
+ XML_DefaultHandler m_defaultHandler;
+ XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler;
+ XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler;
+ XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler;
+ XML_NotationDeclHandler m_notationDeclHandler;
+ XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler;
+ XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler;
+ XML_NotStandaloneHandler m_notStandaloneHandler;
+ XML_ExternalEntityRefHandler m_externalEntityRefHandler;
+ void *m_externalEntityRefHandlerArg;
+ XML_UnknownEncodingHandler m_unknownEncodingHandler;
+ XML_ElementDeclHandler m_elementDeclHandler;
+ XML_AttlistDeclHandler m_attlistDeclHandler;
+ XML_EntityDeclHandler m_entityDeclHandler;
+ XML_XmlDeclHandler m_xmlDeclHandler;
+ const ENCODING *m_encoding;
+ INIT_ENCODING m_initEncoding;
+ const ENCODING *m_internalEncoding;
+ const XML_Char *m_protocolEncodingName;
+ int m_ns;
+ int m_ns_triplets;
+ void *m_unknownEncodingMem;
+ void *m_unknownEncodingData;
+ void *m_unknownEncodingHandlerData;
+ void (*m_unknownEncodingRelease)(void *);
+ PROLOG_STATE m_prologState;
+ Processor *m_processor;
+ enum XML_Error m_errorCode;
+ const char *m_eventPtr;
+ const char *m_eventEndPtr;
+ const char *m_positionPtr;
+ OPEN_INTERNAL_ENTITY *m_openInternalEntities;
+ int m_defaultExpandInternalEntities;
+ int m_tagLevel;
+ ENTITY *m_declEntity;
+ const XML_Char *m_doctypeName;
+ const XML_Char *m_doctypeSysid;
+ const XML_Char *m_doctypePubid;
+ const XML_Char *m_declAttributeType;
+ const XML_Char *m_declNotationName;
+ const XML_Char *m_declNotationPublicId;
+ ELEMENT_TYPE *m_declElementType;
+ ATTRIBUTE_ID *m_declAttributeId;
+ char m_declAttributeIsCdata;
+ char m_declAttributeIsId;
+ DTD m_dtd;
+ const XML_Char *m_curBase;
+ TAG *m_tagStack;
+ TAG *m_freeTagList;
+ BINDING *m_inheritedBindings;
+ BINDING *m_freeBindingList;
+ int m_attsSize;
+ int m_nSpecifiedAtts;
+ int m_idAttIndex;
+ ATTRIBUTE *m_atts;
+ POSITION m_position;
+ STRING_POOL m_tempPool;
+ STRING_POOL m_temp2Pool;
+ char *m_groupConnector;
+ unsigned m_groupSize;
+ int m_hadExternalDoctype;
+ XML_Char m_namespaceSeparator;
+#ifdef XML_DTD
+ enum XML_ParamEntityParsing m_paramEntityParsing;
+ XML_Parser m_parentParser;
+#endif
+} Parser;
+
+#define MALLOC(s) (((Parser *)parser)->m_mem.malloc_fcn((s)))
+#define REALLOC(p,s) (((Parser *)parser)->m_mem.realloc_fcn((p),(s)))
+#define FREE(p) (((Parser *)parser)->m_mem.free_fcn((p)))
+
+#define userData (((Parser *)parser)->m_userData)
+#define handlerArg (((Parser *)parser)->m_handlerArg)
+#define startElementHandler (((Parser *)parser)->m_startElementHandler)
+#define endElementHandler (((Parser *)parser)->m_endElementHandler)
+#define characterDataHandler (((Parser *)parser)->m_characterDataHandler)
+#define processingInstructionHandler (((Parser *)parser)->m_processingInstructionHandler)
+#define commentHandler (((Parser *)parser)->m_commentHandler)
+#define startCdataSectionHandler (((Parser *)parser)->m_startCdataSectionHandler)
+#define endCdataSectionHandler (((Parser *)parser)->m_endCdataSectionHandler)
+#define defaultHandler (((Parser *)parser)->m_defaultHandler)
+#define startDoctypeDeclHandler (((Parser *)parser)->m_startDoctypeDeclHandler)
+#define endDoctypeDeclHandler (((Parser *)parser)->m_endDoctypeDeclHandler)
+#define unparsedEntityDeclHandler (((Parser *)parser)->m_unparsedEntityDeclHandler)
+#define notationDeclHandler (((Parser *)parser)->m_notationDeclHandler)
+#define startNamespaceDeclHandler (((Parser *)parser)->m_startNamespaceDeclHandler)
+#define endNamespaceDeclHandler (((Parser *)parser)->m_endNamespaceDeclHandler)
+#define notStandaloneHandler (((Parser *)parser)->m_notStandaloneHandler)
+#define externalEntityRefHandler (((Parser *)parser)->m_externalEntityRefHandler)
+#define externalEntityRefHandlerArg (((Parser *)parser)->m_externalEntityRefHandlerArg)
+#define internalEntityRefHandler (((Parser *)parser)->m_internalEntityRefHandler)
+#define unknownEncodingHandler (((Parser *)parser)->m_unknownEncodingHandler)
+#define elementDeclHandler (((Parser *)parser)->m_elementDeclHandler)
+#define attlistDeclHandler (((Parser *)parser)->m_attlistDeclHandler)
+#define entityDeclHandler (((Parser *)parser)->m_entityDeclHandler)
+#define xmlDeclHandler (((Parser *)parser)->m_xmlDeclHandler)
+#define encoding (((Parser *)parser)->m_encoding)
+#define initEncoding (((Parser *)parser)->m_initEncoding)
+#define internalEncoding (((Parser *)parser)->m_internalEncoding)
+#define unknownEncodingMem (((Parser *)parser)->m_unknownEncodingMem)
+#define unknownEncodingData (((Parser *)parser)->m_unknownEncodingData)
+#define unknownEncodingHandlerData \
+ (((Parser *)parser)->m_unknownEncodingHandlerData)
+#define unknownEncodingRelease (((Parser *)parser)->m_unknownEncodingRelease)
+#define protocolEncodingName (((Parser *)parser)->m_protocolEncodingName)
+#define ns (((Parser *)parser)->m_ns)
+#define ns_triplets (((Parser *)parser)->m_ns_triplets)
+#define prologState (((Parser *)parser)->m_prologState)
+#define processor (((Parser *)parser)->m_processor)
+#define errorCode (((Parser *)parser)->m_errorCode)
+#define eventPtr (((Parser *)parser)->m_eventPtr)
+#define eventEndPtr (((Parser *)parser)->m_eventEndPtr)
+#define positionPtr (((Parser *)parser)->m_positionPtr)
+#define position (((Parser *)parser)->m_position)
+#define openInternalEntities (((Parser *)parser)->m_openInternalEntities)
+#define defaultExpandInternalEntities (((Parser *)parser)->m_defaultExpandInternalEntities)
+#define tagLevel (((Parser *)parser)->m_tagLevel)
+#define buffer (((Parser *)parser)->m_buffer)
+#define bufferPtr (((Parser *)parser)->m_bufferPtr)
+#define bufferEnd (((Parser *)parser)->m_bufferEnd)
+#define parseEndByteIndex (((Parser *)parser)->m_parseEndByteIndex)
+#define parseEndPtr (((Parser *)parser)->m_parseEndPtr)
+#define bufferLim (((Parser *)parser)->m_bufferLim)
+#define dataBuf (((Parser *)parser)->m_dataBuf)
+#define dataBufEnd (((Parser *)parser)->m_dataBufEnd)
+#define dtd (((Parser *)parser)->m_dtd)
+#define curBase (((Parser *)parser)->m_curBase)
+#define declEntity (((Parser *)parser)->m_declEntity)
+#define doctypeName (((Parser *)parser)->m_doctypeName)
+#define doctypeSysid (((Parser *)parser)->m_doctypeSysid)
+#define doctypePubid (((Parser *)parser)->m_doctypePubid)
+#define declAttributeType (((Parser *)parser)->m_declAttributeType)
+#define declNotationName (((Parser *)parser)->m_declNotationName)
+#define declNotationPublicId (((Parser *)parser)->m_declNotationPublicId)
+#define declElementType (((Parser *)parser)->m_declElementType)
+#define declAttributeId (((Parser *)parser)->m_declAttributeId)
+#define declAttributeIsCdata (((Parser *)parser)->m_declAttributeIsCdata)
+#define declAttributeIsId (((Parser *)parser)->m_declAttributeIsId)
+#define freeTagList (((Parser *)parser)->m_freeTagList)
+#define freeBindingList (((Parser *)parser)->m_freeBindingList)
+#define inheritedBindings (((Parser *)parser)->m_inheritedBindings)
+#define tagStack (((Parser *)parser)->m_tagStack)
+#define atts (((Parser *)parser)->m_atts)
+#define attsSize (((Parser *)parser)->m_attsSize)
+#define nSpecifiedAtts (((Parser *)parser)->m_nSpecifiedAtts)
+#define idAttIndex (((Parser *)parser)->m_idAttIndex)
+#define tempPool (((Parser *)parser)->m_tempPool)
+#define temp2Pool (((Parser *)parser)->m_temp2Pool)
+#define groupConnector (((Parser *)parser)->m_groupConnector)
+#define groupSize (((Parser *)parser)->m_groupSize)
+#define hadExternalDoctype (((Parser *)parser)->m_hadExternalDoctype)
+#define namespaceSeparator (((Parser *)parser)->m_namespaceSeparator)
+#ifdef XML_DTD
+#define parentParser (((Parser *)parser)->m_parentParser)
+#define paramEntityParsing (((Parser *)parser)->m_paramEntityParsing)
+#endif /* XML_DTD */
+
+#ifdef COMPILED_FROM_DSP
+BOOL WINAPI DllMain(HINSTANCE h, DWORD r, LPVOID p) {
+ return TRUE;
+}
+#endif /* def COMPILED_FROM_DSP */
+
+#ifdef _MSC_VER
+#ifdef _DEBUG
+Parser *asParser(XML_Parser parser)
+{
+ return parser;
+}
+#endif
+#endif
+
+XML_Parser XML_ParserCreate(const XML_Char *encodingName)
+{
+ return XML_ParserCreate_MM(encodingName, NULL, NULL);
+}
+
+XML_Parser XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep)
+{
+ XML_Char tmp[2];
+ *tmp = nsSep;
+ return XML_ParserCreate_MM(encodingName, NULL, tmp);
+}
+
+XML_Parser
+XML_ParserCreate_MM(const XML_Char *encodingName,
+ const XML_Memory_Handling_Suite *memsuite,
+ const XML_Char *nameSep) {
+
+ XML_Parser parser;
+ static
+ const XML_Char implicitContext[] = {
+ XML_T('x'), XML_T('m'), XML_T('l'), XML_T('='),
+ XML_T('h'), XML_T('t'), XML_T('t'), XML_T('p'), XML_T(':'),
+ XML_T('/'), XML_T('/'), XML_T('w'), XML_T('w'), XML_T('w'),
+ XML_T('.'), XML_T('w'), XML_T('3'),
+ XML_T('.'), XML_T('o'), XML_T('r'), XML_T('g'),
+ XML_T('/'), XML_T('X'), XML_T('M'), XML_T('L'),
+ XML_T('/'), XML_T('1'), XML_T('9'), XML_T('9'), XML_T('8'),
+ XML_T('/'), XML_T('n'), XML_T('a'), XML_T('m'), XML_T('e'),
+ XML_T('s'), XML_T('p'), XML_T('a'), XML_T('c'), XML_T('e'),
+ XML_T('\0')
+ };
+
+
+ if (memsuite) {
+ XML_Memory_Handling_Suite *mtemp;
+ parser = memsuite->malloc_fcn(sizeof(Parser));
+ mtemp = &(((Parser *) parser)->m_mem);
+ mtemp->malloc_fcn = memsuite->malloc_fcn;
+ mtemp->realloc_fcn = memsuite->realloc_fcn;
+ mtemp->free_fcn = memsuite->free_fcn;
+ }
+ else {
+ XML_Memory_Handling_Suite *mtemp;
+ parser = malloc(sizeof(Parser));
+ mtemp = &(((Parser *) parser)->m_mem);
+ mtemp->malloc_fcn = malloc;
+ mtemp->realloc_fcn = realloc;
+ mtemp->free_fcn = free;
+ }
+
+ if (!parser)
+ return parser;
+ processor = prologInitProcessor;
+ XmlPrologStateInit(&prologState);
+ userData = 0;
+ handlerArg = 0;
+ startElementHandler = 0;
+ endElementHandler = 0;
+ characterDataHandler = 0;
+ processingInstructionHandler = 0;
+ commentHandler = 0;
+ startCdataSectionHandler = 0;
+ endCdataSectionHandler = 0;
+ defaultHandler = 0;
+ startDoctypeDeclHandler = 0;
+ endDoctypeDeclHandler = 0;
+ unparsedEntityDeclHandler = 0;
+ notationDeclHandler = 0;
+ startNamespaceDeclHandler = 0;
+ endNamespaceDeclHandler = 0;
+ notStandaloneHandler = 0;
+ externalEntityRefHandler = 0;
+ externalEntityRefHandlerArg = parser;
+ unknownEncodingHandler = 0;
+ elementDeclHandler = 0;
+ attlistDeclHandler = 0;
+ entityDeclHandler = 0;
+ xmlDeclHandler = 0;
+ buffer = 0;
+ bufferPtr = 0;
+ bufferEnd = 0;
+ parseEndByteIndex = 0;
+ parseEndPtr = 0;
+ bufferLim = 0;
+ declElementType = 0;
+ declAttributeId = 0;
+ declEntity = 0;
+ doctypeName = 0;
+ doctypeSysid = 0;
+ doctypePubid = 0;
+ declAttributeType = 0;
+ declNotationName = 0;
+ declNotationPublicId = 0;
+ memset(&position, 0, sizeof(POSITION));
+ errorCode = XML_ERROR_NONE;
+ eventPtr = 0;
+ eventEndPtr = 0;
+ positionPtr = 0;
+ openInternalEntities = 0;
+ tagLevel = 0;
+ tagStack = 0;
+ freeTagList = 0;
+ freeBindingList = 0;
+ inheritedBindings = 0;
+ attsSize = INIT_ATTS_SIZE;
+ atts = MALLOC(attsSize * sizeof(ATTRIBUTE));
+ nSpecifiedAtts = 0;
+ dataBuf = MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char));
+ groupSize = 0;
+ groupConnector = 0;
+ hadExternalDoctype = 0;
+ unknownEncodingMem = 0;
+ unknownEncodingRelease = 0;
+ unknownEncodingData = 0;
+ unknownEncodingHandlerData = 0;
+ namespaceSeparator = '!';
+#ifdef XML_DTD
+ parentParser = 0;
+ paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
+#endif
+ ns = 0;
+ ns_triplets = 0;
+ poolInit(&tempPool, &(((Parser *) parser)->m_mem));
+ poolInit(&temp2Pool, &(((Parser *) parser)->m_mem));
+ protocolEncodingName = encodingName ? poolCopyString(&tempPool, encodingName) : 0;
+ curBase = 0;
+ if (!dtdInit(&dtd, parser) || !atts || !dataBuf
+ || (encodingName && !protocolEncodingName)) {
+ XML_ParserFree(parser);
+ return 0;
+ }
+ dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE;
+
+ if (nameSep) {
+ XmlInitEncodingNS(&initEncoding, &encoding, 0);
+ ns = 1;
+ internalEncoding = XmlGetInternalEncodingNS();
+ namespaceSeparator = *nameSep;
+
+ if (! setContext(parser, implicitContext)) {
+ XML_ParserFree(parser);
+ return 0;
+ }
+ }
+ else {
+ XmlInitEncoding(&initEncoding, &encoding, 0);
+ internalEncoding = XmlGetInternalEncoding();
+ }
+
+ return parser;
+} /* End XML_ParserCreate_MM */
+
+int XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName)
+{
+ if (!encodingName)
+ protocolEncodingName = 0;
+ else {
+ protocolEncodingName = poolCopyString(&tempPool, encodingName);
+ if (!protocolEncodingName)
+ return 0;
+ }
+ return 1;
+}
+
+XML_Parser XML_ExternalEntityParserCreate(XML_Parser oldParser,
+ const XML_Char *context,
+ const XML_Char *encodingName)
+{
+ XML_Parser parser = oldParser;
+ DTD *oldDtd = &dtd;
+ XML_StartElementHandler oldStartElementHandler = startElementHandler;
+ XML_EndElementHandler oldEndElementHandler = endElementHandler;
+ XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler;
+ XML_ProcessingInstructionHandler oldProcessingInstructionHandler = processingInstructionHandler;
+ XML_CommentHandler oldCommentHandler = commentHandler;
+ XML_StartCdataSectionHandler oldStartCdataSectionHandler = startCdataSectionHandler;
+ XML_EndCdataSectionHandler oldEndCdataSectionHandler = endCdataSectionHandler;
+ XML_DefaultHandler oldDefaultHandler = defaultHandler;
+ XML_UnparsedEntityDeclHandler oldUnparsedEntityDeclHandler = unparsedEntityDeclHandler;
+ XML_NotationDeclHandler oldNotationDeclHandler = notationDeclHandler;
+ XML_StartNamespaceDeclHandler oldStartNamespaceDeclHandler = startNamespaceDeclHandler;
+ XML_EndNamespaceDeclHandler oldEndNamespaceDeclHandler = endNamespaceDeclHandler;
+ XML_NotStandaloneHandler oldNotStandaloneHandler = notStandaloneHandler;
+ XML_ExternalEntityRefHandler oldExternalEntityRefHandler = externalEntityRefHandler;
+ XML_UnknownEncodingHandler oldUnknownEncodingHandler = unknownEncodingHandler;
+ XML_ElementDeclHandler oldElementDeclHandler = elementDeclHandler;
+ XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler;
+ XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler;
+ XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler;
+ ELEMENT_TYPE * oldDeclElementType = declElementType;
+
+ void *oldUserData = userData;
+ void *oldHandlerArg = handlerArg;
+ int oldDefaultExpandInternalEntities = defaultExpandInternalEntities;
+ void *oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg;
+#ifdef XML_DTD
+ enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing;
+#endif
+ int oldns_triplets = ns_triplets;
+
+ if (ns) {
+ XML_Char tmp[2];
+
+ *tmp = namespaceSeparator;
+ parser = XML_ParserCreate_MM(encodingName, &((Parser *)parser)->m_mem,
+ tmp);
+ }
+ else {
+ parser = XML_ParserCreate_MM(encodingName, &((Parser *)parser)->m_mem,
+ NULL);
+ }
+
+ if (!parser)
+ return 0;
+
+ startElementHandler = oldStartElementHandler;
+ endElementHandler = oldEndElementHandler;
+ characterDataHandler = oldCharacterDataHandler;
+ processingInstructionHandler = oldProcessingInstructionHandler;
+ commentHandler = oldCommentHandler;
+ startCdataSectionHandler = oldStartCdataSectionHandler;
+ endCdataSectionHandler = oldEndCdataSectionHandler;
+ defaultHandler = oldDefaultHandler;
+ unparsedEntityDeclHandler = oldUnparsedEntityDeclHandler;
+ notationDeclHandler = oldNotationDeclHandler;
+ startNamespaceDeclHandler = oldStartNamespaceDeclHandler;
+ endNamespaceDeclHandler = oldEndNamespaceDeclHandler;
+ notStandaloneHandler = oldNotStandaloneHandler;
+ externalEntityRefHandler = oldExternalEntityRefHandler;
+ unknownEncodingHandler = oldUnknownEncodingHandler;
+ elementDeclHandler = oldElementDeclHandler;
+ attlistDeclHandler = oldAttlistDeclHandler;
+ entityDeclHandler = oldEntityDeclHandler;
+ xmlDeclHandler = oldXmlDeclHandler;
+ declElementType = oldDeclElementType;
+ userData = oldUserData;
+ if (oldUserData == oldHandlerArg)
+ handlerArg = userData;
+ else
+ handlerArg = parser;
+ if (oldExternalEntityRefHandlerArg != oldParser)
+ externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg;
+ defaultExpandInternalEntities = oldDefaultExpandInternalEntities;
+ ns_triplets = oldns_triplets;
+#ifdef XML_DTD
+ paramEntityParsing = oldParamEntityParsing;
+ if (context) {
+#endif /* XML_DTD */
+ if (!dtdCopy(&dtd, oldDtd, parser) || !setContext(parser, context)) {
+ XML_ParserFree(parser);
+ return 0;
+ }
+ processor = externalEntityInitProcessor;
+#ifdef XML_DTD
+ }
+ else {
+ dtdSwap(&dtd, oldDtd);
+ parentParser = oldParser;
+ XmlPrologStateInitExternalEntity(&prologState);
+ dtd.complete = 1;
+ hadExternalDoctype = 1;
+ }
+#endif /* XML_DTD */
+ return parser;
+}
+
+static
+void destroyBindings(BINDING *bindings, XML_Parser parser)
+{
+ for (;;) {
+ BINDING *b = bindings;
+ if (!b)
+ break;
+ bindings = b->nextTagBinding;
+ FREE(b->uri);
+ FREE(b);
+ }
+}
+
+void XML_ParserFree(XML_Parser parser)
+{
+ for (;;) {
+ TAG *p;
+ if (tagStack == 0) {
+ if (freeTagList == 0)
+ break;
+ tagStack = freeTagList;
+ freeTagList = 0;
+ }
+ p = tagStack;
+ tagStack = tagStack->parent;
+ FREE(p->buf);
+ destroyBindings(p->bindings, parser);
+ FREE(p);
+ }
+ destroyBindings(freeBindingList, parser);
+ destroyBindings(inheritedBindings, parser);
+ poolDestroy(&tempPool);
+ poolDestroy(&temp2Pool);
+#ifdef XML_DTD
+ if (parentParser) {
+ if (hadExternalDoctype)
+ dtd.complete = 0;
+ dtdSwap(&dtd, &((Parser *)parentParser)->m_dtd);
+ }
+#endif /* XML_DTD */
+ dtdDestroy(&dtd, parser);
+ FREE((void *)atts);
+ if (groupConnector)
+ FREE(groupConnector);
+ if (buffer)
+ FREE(buffer);
+ FREE(dataBuf);
+ if (unknownEncodingMem)
+ FREE(unknownEncodingMem);
+ if (unknownEncodingRelease)
+ unknownEncodingRelease(unknownEncodingData);
+ FREE(parser);
+}
+
+void XML_UseParserAsHandlerArg(XML_Parser parser)
+{
+ handlerArg = parser;
+}
+
+void
+XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) {
+ ns_triplets = do_nst;
+}
+
+void XML_SetUserData(XML_Parser parser, void *p)
+{
+ if (handlerArg == userData)
+ handlerArg = userData = p;
+ else
+ userData = p;
+}
+
+int XML_SetBase(XML_Parser parser, const XML_Char *p)
+{
+ if (p) {
+ p = poolCopyString(&dtd.pool, p);
+ if (!p)
+ return 0;
+ curBase = p;
+ }
+ else
+ curBase = 0;
+ return 1;
+}
+
+const XML_Char *XML_GetBase(XML_Parser parser)
+{
+ return curBase;
+}
+
+int XML_GetSpecifiedAttributeCount(XML_Parser parser)
+{
+ return nSpecifiedAtts;
+}
+
+int XML_GetIdAttributeIndex(XML_Parser parser)
+{
+ return idAttIndex;
+}
+
+void XML_SetElementHandler(XML_Parser parser,
+ XML_StartElementHandler start,
+ XML_EndElementHandler end)
+{
+ startElementHandler = start;
+ endElementHandler = end;
+}
+
+void XML_SetStartElementHandler(XML_Parser parser,
+ XML_StartElementHandler start) {
+ startElementHandler = start;
+}
+
+void XML_SetEndElementHandler(XML_Parser parser,
+ XML_EndElementHandler end) {
+ endElementHandler = end;
+}
+
+void XML_SetCharacterDataHandler(XML_Parser parser,
+ XML_CharacterDataHandler handler)
+{
+ characterDataHandler = handler;
+}
+
+void XML_SetProcessingInstructionHandler(XML_Parser parser,
+ XML_ProcessingInstructionHandler handler)
+{
+ processingInstructionHandler = handler;
+}
+
+void XML_SetCommentHandler(XML_Parser parser,
+ XML_CommentHandler handler)
+{
+ commentHandler = handler;
+}
+
+void XML_SetCdataSectionHandler(XML_Parser parser,
+ XML_StartCdataSectionHandler start,
+ XML_EndCdataSectionHandler end)
+{
+ startCdataSectionHandler = start;
+ endCdataSectionHandler = end;
+}
+
+void XML_SetStartCdataSectionHandler(XML_Parser parser,
+ XML_StartCdataSectionHandler start) {
+ startCdataSectionHandler = start;
+}
+
+void XML_SetEndCdataSectionHandler(XML_Parser parser,
+ XML_EndCdataSectionHandler end) {
+ endCdataSectionHandler = end;
+}
+
+void XML_SetDefaultHandler(XML_Parser parser,
+ XML_DefaultHandler handler)
+{
+ defaultHandler = handler;
+ defaultExpandInternalEntities = 0;
+}
+
+void XML_SetDefaultHandlerExpand(XML_Parser parser,
+ XML_DefaultHandler handler)
+{
+ defaultHandler = handler;
+ defaultExpandInternalEntities = 1;
+}
+
+void XML_SetDoctypeDeclHandler(XML_Parser parser,
+ XML_StartDoctypeDeclHandler start,
+ XML_EndDoctypeDeclHandler end)
+{
+ startDoctypeDeclHandler = start;
+ endDoctypeDeclHandler = end;
+}
+
+void XML_SetStartDoctypeDeclHandler(XML_Parser parser,
+ XML_StartDoctypeDeclHandler start) {
+ startDoctypeDeclHandler = start;
+}
+
+void XML_SetEndDoctypeDeclHandler(XML_Parser parser,
+ XML_EndDoctypeDeclHandler end) {
+ endDoctypeDeclHandler = end;
+}
+
+void XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
+ XML_UnparsedEntityDeclHandler handler)
+{
+ unparsedEntityDeclHandler = handler;
+}
+
+void XML_SetNotationDeclHandler(XML_Parser parser,
+ XML_NotationDeclHandler handler)
+{
+ notationDeclHandler = handler;
+}
+
+void XML_SetNamespaceDeclHandler(XML_Parser parser,
+ XML_StartNamespaceDeclHandler start,
+ XML_EndNamespaceDeclHandler end)
+{
+ startNamespaceDeclHandler = start;
+ endNamespaceDeclHandler = end;
+}
+
+void XML_SetStartNamespaceDeclHandler(XML_Parser parser,
+ XML_StartNamespaceDeclHandler start) {
+ startNamespaceDeclHandler = start;
+}
+
+void XML_SetEndNamespaceDeclHandler(XML_Parser parser,
+ XML_EndNamespaceDeclHandler end) {
+ endNamespaceDeclHandler = end;
+}
+
+
+void XML_SetNotStandaloneHandler(XML_Parser parser,
+ XML_NotStandaloneHandler handler)
+{
+ notStandaloneHandler = handler;
+}
+
+void XML_SetExternalEntityRefHandler(XML_Parser parser,
+ XML_ExternalEntityRefHandler handler)
+{
+ externalEntityRefHandler = handler;
+}
+
+void XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg)
+{
+ if (arg)
+ externalEntityRefHandlerArg = arg;
+ else
+ externalEntityRefHandlerArg = parser;
+}
+
+void XML_SetUnknownEncodingHandler(XML_Parser parser,
+ XML_UnknownEncodingHandler handler,
+ void *data)
+{
+ unknownEncodingHandler = handler;
+ unknownEncodingHandlerData = data;
+}
+
+void XML_SetElementDeclHandler(XML_Parser parser,
+ XML_ElementDeclHandler eldecl)
+{
+ elementDeclHandler = eldecl;
+}
+
+void XML_SetAttlistDeclHandler(XML_Parser parser,
+ XML_AttlistDeclHandler attdecl)
+{
+ attlistDeclHandler = attdecl;
+}
+
+void XML_SetEntityDeclHandler(XML_Parser parser,
+ XML_EntityDeclHandler handler)
+{
+ entityDeclHandler = handler;
+}
+
+void XML_SetXmlDeclHandler(XML_Parser parser,
+ XML_XmlDeclHandler handler) {
+ xmlDeclHandler = handler;
+}
+
+int XML_SetParamEntityParsing(XML_Parser parser,
+ enum XML_ParamEntityParsing parsing)
+{
+#ifdef XML_DTD
+ paramEntityParsing = parsing;
+ return 1;
+#else
+ return parsing == XML_PARAM_ENTITY_PARSING_NEVER;
+#endif
+}
+
+int XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
+{
+ if (len == 0) {
+ if (!isFinal)
+ return 1;
+ positionPtr = bufferPtr;
+ errorCode = processor(parser, bufferPtr, parseEndPtr = bufferEnd, 0);
+ if (errorCode == XML_ERROR_NONE)
+ return 1;
+ eventEndPtr = eventPtr;
+ processor = errorProcessor;
+ return 0;
+ }
+#ifndef XML_CONTEXT_BYTES
+ else if (bufferPtr == bufferEnd) {
+ const char *end;
+ int nLeftOver;
+ parseEndByteIndex += len;
+ positionPtr = s;
+ if (isFinal) {
+ errorCode = processor(parser, s, parseEndPtr = s + len, 0);
+ if (errorCode == XML_ERROR_NONE)
+ return 1;
+ eventEndPtr = eventPtr;
+ processor = errorProcessor;
+ return 0;
+ }
+ errorCode = processor(parser, s, parseEndPtr = s + len, &end);
+ if (errorCode != XML_ERROR_NONE) {
+ eventEndPtr = eventPtr;
+ processor = errorProcessor;
+ return 0;
+ }
+ XmlUpdatePosition(encoding, positionPtr, end, &position);
+ nLeftOver = s + len - end;
+ if (nLeftOver) {
+ if (buffer == 0 || nLeftOver > bufferLim - buffer) {
+ /* FIXME avoid integer overflow */
+ buffer = buffer == 0 ? MALLOC(len * 2) : REALLOC(buffer, len * 2);
+ /* FIXME storage leak if realloc fails */
+ if (!buffer) {
+ errorCode = XML_ERROR_NO_MEMORY;
+ eventPtr = eventEndPtr = 0;
+ processor = errorProcessor;
+ return 0;
+ }
+ bufferLim = buffer + len * 2;
+ }
+ memcpy(buffer, end, nLeftOver);
+ bufferPtr = buffer;
+ bufferEnd = buffer + nLeftOver;
+ }
+ return 1;
+ }
+#endif /* not defined XML_CONTEXT_BYTES */
+ else {
+ memcpy(XML_GetBuffer(parser, len), s, len);
+ return XML_ParseBuffer(parser, len, isFinal);
+ }
+}
+
+int XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
+{
+ const char *start = bufferPtr;
+ positionPtr = start;
+ bufferEnd += len;
+ parseEndByteIndex += len;
+ errorCode = processor(parser, start, parseEndPtr = bufferEnd,
+ isFinal ? (const char **)0 : &bufferPtr);
+ if (errorCode == XML_ERROR_NONE) {
+ if (!isFinal)
+ XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
+ return 1;
+ }
+ else {
+ eventEndPtr = eventPtr;
+ processor = errorProcessor;
+ return 0;
+ }
+}
+
+void *XML_GetBuffer(XML_Parser parser, int len)
+{
+ if (len > bufferLim - bufferEnd) {
+ /* FIXME avoid integer overflow */
+ int neededSize = len + (bufferEnd - bufferPtr);
+#ifdef XML_CONTEXT_BYTES
+ int keep = bufferPtr - buffer;
+
+ if (keep > XML_CONTEXT_BYTES)
+ keep = XML_CONTEXT_BYTES;
+ neededSize += keep;
+#endif /* defined XML_CONTEXT_BYTES */
+ if (neededSize <= bufferLim - buffer) {
+#ifdef XML_CONTEXT_BYTES
+ if (keep < bufferPtr - buffer) {
+ int offset = (bufferPtr - buffer) - keep;
+ memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep);
+ bufferEnd -= offset;
+ bufferPtr -= offset;
+ }
+#else
+ memmove(buffer, bufferPtr, bufferEnd - bufferPtr);
+ bufferEnd = buffer + (bufferEnd - bufferPtr);
+ bufferPtr = buffer;
+#endif /* not defined XML_CONTEXT_BYTES */
+ }
+ else {
+ char *newBuf;
+ int bufferSize = bufferLim - bufferPtr;
+ if (bufferSize == 0)
+ bufferSize = INIT_BUFFER_SIZE;
+ do {
+ bufferSize *= 2;
+ } while (bufferSize < neededSize);
+ newBuf = MALLOC(bufferSize);
+ if (newBuf == 0) {
+ errorCode = XML_ERROR_NO_MEMORY;
+ return 0;
+ }
+ bufferLim = newBuf + bufferSize;
+#ifdef XML_CONTEXT_BYTES
+ if (bufferPtr) {
+ int xmKeep = bufferPtr - buffer;
+ if (xmKeep > XML_CONTEXT_BYTES)
+ xmKeep = XML_CONTEXT_BYTES;
+ memcpy(newBuf, &bufferPtr[-xmKeep], bufferEnd - bufferPtr + xmKeep);
+ FREE(buffer);
+ buffer = newBuf;
+ bufferEnd = buffer + (bufferEnd - bufferPtr) + xmKeep;
+ bufferPtr = buffer + xmKeep;
+ }
+ else {
+ bufferEnd = newBuf + (bufferEnd - bufferPtr);
+ bufferPtr = buffer = newBuf;
+ }
+#else
+ if (bufferPtr) {
+ memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr);
+ FREE(buffer);
+ }
+ bufferEnd = newBuf + (bufferEnd - bufferPtr);
+ bufferPtr = buffer = newBuf;
+#endif /* not defined XML_CONTEXT_BYTES */
+ }
+ }
+ return bufferEnd;
+}
+
+enum XML_Error XML_GetErrorCode(XML_Parser parser)
+{
+ return errorCode;
+}
+
+long XML_GetCurrentByteIndex(XML_Parser parser)
+{
+ if (eventPtr)
+ return parseEndByteIndex - (parseEndPtr - eventPtr);
+ return -1;
+}
+
+int XML_GetCurrentByteCount(XML_Parser parser)
+{
+ if (eventEndPtr && eventPtr)
+ return eventEndPtr - eventPtr;
+ return 0;
+}
+
+const char * XML_GetInputContext(XML_Parser parser, int *offset, int *size)
+{
+#ifdef XML_CONTEXT_BYTES
+ if (eventPtr && buffer) {
+ *offset = eventPtr - buffer;
+ *size = bufferEnd - buffer;
+ return buffer;
+ }
+#endif /* defined XML_CONTEXT_BYTES */
+ return (char *) 0;
+}
+
+int XML_GetCurrentLineNumber(XML_Parser parser)
+{
+ if (eventPtr) {
+ XmlUpdatePosition(encoding, positionPtr, eventPtr, &position);
+ positionPtr = eventPtr;
+ }
+ return position.lineNumber + 1;
+}
+
+int XML_GetCurrentColumnNumber(XML_Parser parser)
+{
+ if (eventPtr) {
+ XmlUpdatePosition(encoding, positionPtr, eventPtr, &position);
+ positionPtr = eventPtr;
+ }
+ return position.columnNumber;
+}
+
+void XML_DefaultCurrent(XML_Parser parser)
+{
+ if (defaultHandler) {
+ if (openInternalEntities)
+ reportDefault(parser,
+ internalEncoding,
+ openInternalEntities->internalEventPtr,
+ openInternalEntities->internalEventEndPtr);
+ else
+ reportDefault(parser, encoding, eventPtr, eventEndPtr);
+ }
+}
+
+const XML_LChar *XML_ErrorString(int code)
+{
+ static const XML_LChar *message[] = {
+ 0,
+ XML_T("out of memory"),
+ XML_T("syntax error"),
+ XML_T("no element found"),
+ XML_T("not well-formed (invalid token)"),
+ XML_T("unclosed token"),
+ XML_T("unclosed token"),
+ XML_T("mismatched tag"),
+ XML_T("duplicate attribute"),
+ XML_T("junk after document element"),
+ XML_T("illegal parameter entity reference"),
+ XML_T("undefined entity"),
+ XML_T("recursive entity reference"),
+ XML_T("asynchronous entity"),
+ XML_T("reference to invalid character number"),
+ XML_T("reference to binary entity"),
+ XML_T("reference to external entity in attribute"),
+ XML_T("xml processing instruction not at start of external entity"),
+ XML_T("unknown encoding"),
+ XML_T("encoding specified in XML declaration is incorrect"),
+ XML_T("unclosed CDATA section"),
+ XML_T("error in processing external entity reference"),
+ XML_T("document is not standalone"),
+ XML_T("unexpected parser state - please send a bug report")
+ };
+ if (code > 0 && code < (int)(sizeof(message)/sizeof(message[0])))
+ return message[code];
+ return 0;
+}
+
+const XML_LChar *
+XML_ExpatVersion(void) {
+ return VERSION;
+}
+
+XML_Expat_Version
+XML_ExpatVersionInfo(void) {
+ XML_Expat_Version version;
+
+ version.major = XML_MAJOR_VERSION;
+ version.minor = XML_MINOR_VERSION;
+ version.micro = XML_MICRO_VERSION;
+
+ return version;
+}
+
+static
+enum XML_Error contentProcessor(XML_Parser parser,
+ const char *start,
+ const char *end,
+ const char **endPtr)
+{
+ return doContent(parser, 0, encoding, start, end, endPtr);
+}
+
+static
+enum XML_Error externalEntityInitProcessor(XML_Parser parser,
+ const char *start,
+ const char *end,
+ const char **endPtr)
+{
+ enum XML_Error result = initializeEncoding(parser);
+ if (result != XML_ERROR_NONE)
+ return result;
+ processor = externalEntityInitProcessor2;
+ return externalEntityInitProcessor2(parser, start, end, endPtr);
+}
+
+static
+enum XML_Error externalEntityInitProcessor2(XML_Parser parser,
+ const char *start,
+ const char *end,
+ const char **endPtr)
+{
+ const char *next;
+ int tok = XmlContentTok(encoding, start, end, &next);
+ switch (tok) {
+ case XML_TOK_BOM:
+ start = next;
+ break;
+ case XML_TOK_PARTIAL:
+ if (endPtr) {
+ *endPtr = start;
+ return XML_ERROR_NONE;
+ }
+ eventPtr = start;
+ return XML_ERROR_UNCLOSED_TOKEN;
+ case XML_TOK_PARTIAL_CHAR:
+ if (endPtr) {
+ *endPtr = start;
+ return XML_ERROR_NONE;
+ }
+ eventPtr = start;
+ return XML_ERROR_PARTIAL_CHAR;
+ }
+ processor = externalEntityInitProcessor3;
+ return externalEntityInitProcessor3(parser, start, end, endPtr);
+}
+
+static
+enum XML_Error externalEntityInitProcessor3(XML_Parser parser,
+ const char *start,
+ const char *end,
+ const char **endPtr)
+{
+ const char *next;
+ int tok = XmlContentTok(encoding, start, end, &next);
+ switch (tok) {
+ case XML_TOK_XML_DECL:
+ {
+ enum XML_Error result = processXmlDecl(parser, 1, start, next);
+ if (result != XML_ERROR_NONE)
+ return result;
+ start = next;
+ }
+ break;
+ case XML_TOK_PARTIAL:
+ if (endPtr) {
+ *endPtr = start;
+ return XML_ERROR_NONE;
+ }
+ eventPtr = start;
+ return XML_ERROR_UNCLOSED_TOKEN;
+ case XML_TOK_PARTIAL_CHAR:
+ if (endPtr) {
+ *endPtr = start;
+ return XML_ERROR_NONE;
+ }
+ eventPtr = start;
+ return XML_ERROR_PARTIAL_CHAR;
+ }
+ processor = externalEntityContentProcessor;
+ tagLevel = 1;
+ return doContent(parser, 1, encoding, start, end, endPtr);
+}
+
+static
+enum XML_Error externalEntityContentProcessor(XML_Parser parser,
+ const char *start,
+ const char *end,
+ const char **endPtr)
+{
+ return doContent(parser, 1, encoding, start, end, endPtr);
+}
+
+static enum XML_Error
+doContent(XML_Parser parser,
+ int startTagLevel,
+ const ENCODING *enc,
+ const char *s,
+ const char *end,
+ const char **nextPtr)
+{
+ const char **eventPP;
+ const char **eventEndPP;
+ if (enc == encoding) {
+ eventPP = &eventPtr;
+ eventEndPP = &eventEndPtr;
+ }
+ else {
+ eventPP = &(openInternalEntities->internalEventPtr);
+ eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ }
+ *eventPP = s;
+ for (;;) {
+ const char *next = s; /* XmlContentTok doesn't always set the last arg */
+ int tok = XmlContentTok(enc, s, end, &next);
+ *eventEndPP = next;
+ switch (tok) {
+ case XML_TOK_TRAILING_CR:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ *eventEndPP = end;
+ if (characterDataHandler) {
+ XML_Char c = 0xA;
+ characterDataHandler(handlerArg, &c, 1);
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, end);
+ if (startTagLevel == 0)
+ return XML_ERROR_NO_ELEMENTS;
+ if (tagLevel != startTagLevel)
+ return XML_ERROR_ASYNC_ENTITY;
+ return XML_ERROR_NONE;
+ case XML_TOK_NONE:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ if (startTagLevel > 0) {
+ if (tagLevel != startTagLevel)
+ return XML_ERROR_ASYNC_ENTITY;
+ return XML_ERROR_NONE;
+ }
+ return XML_ERROR_NO_ELEMENTS;
+ case XML_TOK_INVALID:
+ *eventPP = next;
+ return XML_ERROR_INVALID_TOKEN;
+ case XML_TOK_PARTIAL:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ return XML_ERROR_UNCLOSED_TOKEN;
+ case XML_TOK_PARTIAL_CHAR:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ return XML_ERROR_PARTIAL_CHAR;
+ case XML_TOK_ENTITY_REF:
+ {
+ const XML_Char *name;
+ ENTITY *entity;
+ XML_Char ch = XmlPredefinedEntityName(enc,
+ s + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (ch) {
+ if (characterDataHandler)
+ characterDataHandler(handlerArg, &ch, 1);
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ break;
+ }
+ name = poolStoreString(&dtd.pool, enc,
+ s + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (!name)
+ return XML_ERROR_NO_MEMORY;
+ entity = (ENTITY *)lookup(&dtd.generalEntities, name, 0);
+ poolDiscard(&dtd.pool);
+ if (!entity) {
+ if (dtd.complete || dtd.standalone)
+ return XML_ERROR_UNDEFINED_ENTITY;
+ if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ break;
+ }
+ if (entity->open)
+ return XML_ERROR_RECURSIVE_ENTITY_REF;
+ if (entity->notation)
+ return XML_ERROR_BINARY_ENTITY_REF;
+ if (entity) {
+ if (entity->textPtr) {
+ enum XML_Error result;
+ OPEN_INTERNAL_ENTITY openEntity;
+ if (defaultHandler && !defaultExpandInternalEntities) {
+ reportDefault(parser, enc, s, next);
+ break;
+ }
+ entity->open = 1;
+ openEntity.next = openInternalEntities;
+ openInternalEntities = &openEntity;
+ openEntity.entity = entity;
+ openEntity.internalEventPtr = 0;
+ openEntity.internalEventEndPtr = 0;
+ result = doContent(parser,
+ tagLevel,
+ internalEncoding,
+ (char *)entity->textPtr,
+ (char *)(entity->textPtr + entity->textLen),
+ 0);
+ entity->open = 0;
+ openInternalEntities = openEntity.next;
+ if (result)
+ return result;
+ }
+ else if (externalEntityRefHandler) {
+ const XML_Char *context;
+ entity->open = 1;
+ context = getContext(parser);
+ entity->open = 0;
+ if (!context)
+ return XML_ERROR_NO_MEMORY;
+ if (!externalEntityRefHandler(externalEntityRefHandlerArg,
+ context,
+ entity->base,
+ entity->systemId,
+ entity->publicId))
+ return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
+ poolDiscard(&tempPool);
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ }
+ break;
+ }
+ case XML_TOK_START_TAG_WITH_ATTS:
+ if (!startElementHandler) {
+ enum XML_Error result = storeAtts(parser, enc, s, 0, 0);
+ if (result)
+ return result;
+ }
+ /* fall through */
+ case XML_TOK_START_TAG_NO_ATTS:
+ {
+ TAG *tag;
+ if (freeTagList) {
+ tag = freeTagList;
+ freeTagList = freeTagList->parent;
+ }
+ else {
+ tag = MALLOC(sizeof(TAG));
+ if (!tag)
+ return XML_ERROR_NO_MEMORY;
+ tag->buf = MALLOC(INIT_TAG_BUF_SIZE);
+ if (!tag->buf)
+ return XML_ERROR_NO_MEMORY;
+ tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE;
+ }
+ tag->bindings = 0;
+ tag->parent = tagStack;
+ tagStack = tag;
+ tag->name.localPart = 0;
+ tag->rawName = s + enc->minBytesPerChar;
+ tag->rawNameLength = XmlNameLength(enc, tag->rawName);
+ if (nextPtr) {
+ /* Need to guarantee that:
+ tag->buf + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)) <= tag->bufEnd - sizeof(XML_Char) */
+ if (tag->rawNameLength + (int)(sizeof(XML_Char) - 1) + (int)sizeof(XML_Char) > tag->bufEnd - tag->buf) {
+ int bufSize = tag->rawNameLength * 4;
+ bufSize = ROUND_UP(bufSize, sizeof(XML_Char));
+ tag->buf = REALLOC(tag->buf, bufSize);
+ if (!tag->buf)
+ return XML_ERROR_NO_MEMORY;
+ tag->bufEnd = tag->buf + bufSize;
+ }
+ memcpy(tag->buf, tag->rawName, tag->rawNameLength);
+ tag->rawName = tag->buf;
+ }
+ ++tagLevel;
+ if (startElementHandler) {
+ enum XML_Error result;
+ XML_Char *toPtr;
+ for (;;) {
+ const char *rawNameEnd = tag->rawName + tag->rawNameLength;
+ const char *fromPtr = tag->rawName;
+ int bufSize;
+ if (nextPtr)
+ toPtr = (XML_Char *)(tag->buf + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)));
+ else
+ toPtr = (XML_Char *)tag->buf;
+ tag->name.str = toPtr;
+ XmlConvert(enc,
+ &fromPtr, rawNameEnd,
+ (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1);
+ if (fromPtr == rawNameEnd)
+ break;
+ bufSize = (tag->bufEnd - tag->buf) << 1;
+ tag->buf = REALLOC(tag->buf, bufSize);
+ if (!tag->buf)
+ return XML_ERROR_NO_MEMORY;
+ tag->bufEnd = tag->buf + bufSize;
+ if (nextPtr)
+ tag->rawName = tag->buf;
+ }
+ *toPtr = XML_T('\0');
+ result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
+ if (result)
+ return result;
+ startElementHandler(handlerArg, tag->name.str, (const XML_Char **)atts);
+ poolClear(&tempPool);
+ }
+ else {
+ tag->name.str = 0;
+ if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ }
+ break;
+ }
+ case XML_TOK_EMPTY_ELEMENT_WITH_ATTS:
+ if (!startElementHandler) {
+ enum XML_Error result = storeAtts(parser, enc, s, 0, 0);
+ if (result)
+ return result;
+ }
+ /* fall through */
+ case XML_TOK_EMPTY_ELEMENT_NO_ATTS:
+ if (startElementHandler || endElementHandler) {
+ const char *rawName = s + enc->minBytesPerChar;
+ enum XML_Error result;
+ BINDING *bindings = 0;
+ TAG_NAME name;
+ name.str = poolStoreString(&tempPool, enc, rawName,
+ rawName + XmlNameLength(enc, rawName));
+ if (!name.str)
+ return XML_ERROR_NO_MEMORY;
+ poolFinish(&tempPool);
+ result = storeAtts(parser, enc, s, &name, &bindings);
+ if (result)
+ return result;
+ poolFinish(&tempPool);
+ if (startElementHandler)
+ startElementHandler(handlerArg, name.str, (const XML_Char **)atts);
+ if (endElementHandler) {
+ if (startElementHandler)
+ *eventPP = *eventEndPP;
+ endElementHandler(handlerArg, name.str);
+ }
+ poolClear(&tempPool);
+ while (bindings) {
+ BINDING *b = bindings;
+ if (endNamespaceDeclHandler)
+ endNamespaceDeclHandler(handlerArg, b->prefix->name);
+ bindings = bindings->nextTagBinding;
+ b->nextTagBinding = freeBindingList;
+ freeBindingList = b;
+ b->prefix->binding = b->prevPrefixBinding;
+ }
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ if (tagLevel == 0)
+ return epilogProcessor(parser, next, end, nextPtr);
+ break;
+ case XML_TOK_END_TAG:
+ if (tagLevel == startTagLevel)
+ return XML_ERROR_ASYNC_ENTITY;
+ else {
+ int len;
+ const char *rawName;
+ TAG *tag = tagStack;
+ tagStack = tag->parent;
+ tag->parent = freeTagList;
+ freeTagList = tag;
+ rawName = s + enc->minBytesPerChar*2;
+ len = XmlNameLength(enc, rawName);
+ if (len != tag->rawNameLength
+ || memcmp(tag->rawName, rawName, len) != 0) {
+ *eventPP = rawName;
+ return XML_ERROR_TAG_MISMATCH;
+ }
+ --tagLevel;
+ if (endElementHandler && tag->name.str) {
+ if (tag->name.localPart) {
+ XML_Char *to = (XML_Char *)tag->name.str + tag->name.uriLen;
+ const XML_Char *from = tag->name.localPart;
+ while ((*to++ = *from++) != 0)
+ ;
+ }
+ endElementHandler(handlerArg, tag->name.str);
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ while (tag->bindings) {
+ BINDING *b = tag->bindings;
+ if (endNamespaceDeclHandler)
+ endNamespaceDeclHandler(handlerArg, b->prefix->name);
+ tag->bindings = tag->bindings->nextTagBinding;
+ b->nextTagBinding = freeBindingList;
+ freeBindingList = b;
+ b->prefix->binding = b->prevPrefixBinding;
+ }
+ if (tagLevel == 0)
+ return epilogProcessor(parser, next, end, nextPtr);
+ }
+ break;
+ case XML_TOK_CHAR_REF:
+ {
+ int n = XmlCharRefNumber(enc, s);
+ if (n < 0)
+ return XML_ERROR_BAD_CHAR_REF;
+ if (characterDataHandler) {
+ XML_Char buf[XML_ENCODE_MAX];
+ characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf));
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ }
+ break;
+ case XML_TOK_XML_DECL:
+ return XML_ERROR_MISPLACED_XML_PI;
+ case XML_TOK_DATA_NEWLINE:
+ if (characterDataHandler) {
+ XML_Char c = 0xA;
+ characterDataHandler(handlerArg, &c, 1);
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ break;
+ case XML_TOK_CDATA_SECT_OPEN:
+ {
+ enum XML_Error result;
+ if (startCdataSectionHandler)
+ startCdataSectionHandler(handlerArg);
+#if 0
+ /* Suppose you doing a transformation on a document that involves
+ changing only the character data. You set up a defaultHandler
+ and a characterDataHandler. The defaultHandler simply copies
+ characters through. The characterDataHandler does the transformation
+ and writes the characters out escaping them as necessary. This case
+ will fail to work if we leave out the following two lines (because &
+ and < inside CDATA sections will be incorrectly escaped).
+
+ However, now we have a start/endCdataSectionHandler, so it seems
+ easier to let the user deal with this. */
+
+ else if (characterDataHandler)
+ characterDataHandler(handlerArg, dataBuf, 0);
+#endif
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ result = doCdataSection(parser, enc, &next, end, nextPtr);
+ if (!next) {
+ processor = cdataSectionProcessor;
+ return result;
+ }
+ }
+ break;
+ case XML_TOK_TRAILING_RSQB:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ if (characterDataHandler) {
+ if (MUST_CONVERT(enc, s)) {
+ ICHAR *dataPtr = (ICHAR *)dataBuf;
+ XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
+ characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
+ }
+ else
+ characterDataHandler(handlerArg,
+ (XML_Char *)s,
+ (XML_Char *)end - (XML_Char *)s);
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, end);
+ if (startTagLevel == 0) {
+ *eventPP = end;
+ return XML_ERROR_NO_ELEMENTS;
+ }
+ if (tagLevel != startTagLevel) {
+ *eventPP = end;
+ return XML_ERROR_ASYNC_ENTITY;
+ }
+ return XML_ERROR_NONE;
+ case XML_TOK_DATA_CHARS:
+ if (characterDataHandler) {
+ if (MUST_CONVERT(enc, s)) {
+ for (;;) {
+ ICHAR *dataPtr = (ICHAR *)dataBuf;
+ XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
+ *eventEndPP = s;
+ characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
+ if (s == next)
+ break;
+ *eventPP = s;
+ }
+ }
+ else
+ characterDataHandler(handlerArg,
+ (XML_Char *)s,
+ (XML_Char *)next - (XML_Char *)s);
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ break;
+ case XML_TOK_PI:
+ if (!reportProcessingInstruction(parser, enc, s, next))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ case XML_TOK_COMMENT:
+ if (!reportComment(parser, enc, s, next))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ default:
+ if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ break;
+ }
+ *eventPP = s = next;
+ }
+ /* not reached */
+}
+
+/* If tagNamePtr is non-null, build a real list of attributes,
+otherwise just check the attributes for well-formedness. */
+
+static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *enc,
+ const char *attStr, TAG_NAME *tagNamePtr,
+ BINDING **bindingsPtr)
+{
+ ELEMENT_TYPE *elementType = 0;
+ int nDefaultAtts = 0;
+ const XML_Char **appAtts; /* the attribute list to pass to the application */
+ int attIndex = 0;
+ int i;
+ int n;
+ int nPrefixes = 0;
+ BINDING *binding;
+ const XML_Char *localPart;
+
+ /* lookup the element type name */
+ if (tagNamePtr) {
+ elementType = (ELEMENT_TYPE *)lookup(&dtd.elementTypes, tagNamePtr->str,0);
+ if (!elementType) {
+ tagNamePtr->str = poolCopyString(&dtd.pool, tagNamePtr->str);
+ if (!tagNamePtr->str)
+ return XML_ERROR_NO_MEMORY;
+ elementType = (ELEMENT_TYPE *)lookup(&dtd.elementTypes, tagNamePtr->str, sizeof(ELEMENT_TYPE));
+ if (!elementType)
+ return XML_ERROR_NO_MEMORY;
+ if (ns && !setElementTypePrefix(parser, elementType))
+ return XML_ERROR_NO_MEMORY;
+ }
+ nDefaultAtts = elementType->nDefaultAtts;
+ }
+ /* get the attributes from the tokenizer */
+ n = XmlGetAttributes(enc, attStr, attsSize, atts);
+ if (n + nDefaultAtts > attsSize) {
+ int oldAttsSize = attsSize;
+ attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;
+ atts = REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE));
+ if (!atts)
+ return XML_ERROR_NO_MEMORY;
+ if (n > oldAttsSize)
+ XmlGetAttributes(enc, attStr, n, atts);
+ }
+ appAtts = (const XML_Char **)atts;
+ for (i = 0; i < n; i++) {
+ /* add the name and value to the attribute list */
+ ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name,
+ atts[i].name
+ + XmlNameLength(enc, atts[i].name));
+ if (!attId)
+ return XML_ERROR_NO_MEMORY;
+ /* detect duplicate attributes */
+ if ((attId->name)[-1]) {
+ if (enc == encoding)
+ eventPtr = atts[i].name;
+ return XML_ERROR_DUPLICATE_ATTRIBUTE;
+ }
+ (attId->name)[-1] = 1;
+ appAtts[attIndex++] = attId->name;
+ if (!atts[i].normalized) {
+ enum XML_Error result;
+ int isCdata = 1;
+
+ /* figure out whether declared as other than CDATA */
+ if (attId->maybeTokenized) {
+ int j;
+ for (j = 0; j < nDefaultAtts; j++) {
+ if (attId == elementType->defaultAtts[j].id) {
+ isCdata = elementType->defaultAtts[j].isCdata;
+ break;
+ }
+ }
+ }
+
+ /* normalize the attribute value */
+ result = storeAttributeValue(parser, enc, isCdata,
+ atts[i].valuePtr, atts[i].valueEnd,
+ &tempPool);
+ if (result)
+ return result;
+ if (tagNamePtr) {
+ appAtts[attIndex] = poolStart(&tempPool);
+ poolFinish(&tempPool);
+ }
+ else
+ poolDiscard(&tempPool);
+ }
+ else if (tagNamePtr) {
+ /* the value did not need normalizing */
+ appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, atts[i].valueEnd);
+ if (appAtts[attIndex] == 0)
+ return XML_ERROR_NO_MEMORY;
+ poolFinish(&tempPool);
+ }
+ /* handle prefixed attribute names */
+ if (attId->prefix && tagNamePtr) {
+ if (attId->xmlns) {
+ /* deal with namespace declarations here */
+ if (!addBinding(parser, attId->prefix, attId, appAtts[attIndex], bindingsPtr))
+ return XML_ERROR_NO_MEMORY;
+ --attIndex;
+ }
+ else {
+ /* deal with other prefixed names later */
+ attIndex++;
+ nPrefixes++;
+ (attId->name)[-1] = 2;
+ }
+ }
+ else
+ attIndex++;
+ }
+ if (tagNamePtr) {
+ int j;
+ nSpecifiedAtts = attIndex;
+ if (elementType->idAtt && (elementType->idAtt->name)[-1]) {
+ for (i = 0; i < attIndex; i += 2)
+ if (appAtts[i] == elementType->idAtt->name) {
+ idAttIndex = i;
+ break;
+ }
+ }
+ else
+ idAttIndex = -1;
+ /* do attribute defaulting */
+ for (j = 0; j < nDefaultAtts; j++) {
+ const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + j;
+ if (!(da->id->name)[-1] && da->value) {
+ if (da->id->prefix) {
+ if (da->id->xmlns) {
+ if (!addBinding(parser, da->id->prefix, da->id, da->value, bindingsPtr))
+ return XML_ERROR_NO_MEMORY;
+ }
+ else {
+ (da->id->name)[-1] = 2;
+ nPrefixes++;
+ appAtts[attIndex++] = da->id->name;
+ appAtts[attIndex++] = da->value;
+ }
+ }
+ else {
+ (da->id->name)[-1] = 1;
+ appAtts[attIndex++] = da->id->name;
+ appAtts[attIndex++] = da->value;
+ }
+ }
+ }
+ appAtts[attIndex] = 0;
+ }
+ i = 0;
+ if (nPrefixes) {
+ /* expand prefixed attribute names */
+ for (; i < attIndex; i += 2) {
+ if (appAtts[i][-1] == 2) {
+ ATTRIBUTE_ID *id;
+ ((XML_Char *)(appAtts[i]))[-1] = 0;
+ id = (ATTRIBUTE_ID *)lookup(&dtd.attributeIds, appAtts[i], 0);
+ if (id->prefix->binding) {
+ int j;
+ const BINDING *b = id->prefix->binding;
+ const XML_Char *s = appAtts[i];
+ for (j = 0; j < b->uriLen; j++) {
+ if (!poolAppendChar(&tempPool, b->uri[j]))
+ return XML_ERROR_NO_MEMORY;
+ }
+ while (*s++ != ':')
+ ;
+ do {
+ if (!poolAppendChar(&tempPool, *s))
+ return XML_ERROR_NO_MEMORY;
+ } while (*s++);
+ if (ns_triplets) {
+ tempPool.ptr[-1] = namespaceSeparator;
+ s = b->prefix->name;
+ do {
+ if (!poolAppendChar(&tempPool, *s))
+ return XML_ERROR_NO_MEMORY;
+ } while (*s++);
+ }
+
+ appAtts[i] = poolStart(&tempPool);
+ poolFinish(&tempPool);
+ }
+ if (!--nPrefixes)
+ break;
+ }
+ else
+ ((XML_Char *)(appAtts[i]))[-1] = 0;
+ }
+ }
+ /* clear the flags that say whether attributes were specified */
+ for (; i < attIndex; i += 2)
+ ((XML_Char *)(appAtts[i]))[-1] = 0;
+ if (!tagNamePtr)
+ return XML_ERROR_NONE;
+ for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding)
+ binding->attId->name[-1] = 0;
+ /* expand the element type name */
+ if (elementType->prefix) {
+ binding = elementType->prefix->binding;
+ if (!binding)
+ return XML_ERROR_NONE;
+ localPart = tagNamePtr->str;
+ while (*localPart++ != XML_T(':'))
+ ;
+ }
+ else if (dtd.defaultPrefix.binding) {
+ binding = dtd.defaultPrefix.binding;
+ localPart = tagNamePtr->str;
+ }
+ else
+ return XML_ERROR_NONE;
+ tagNamePtr->localPart = localPart;
+ tagNamePtr->uriLen = binding->uriLen;
+ for (i = 0; localPart[i++];)
+ ;
+ n = i + binding->uriLen;
+ if (n > binding->uriAlloc) {
+ TAG *p;
+ XML_Char *uri = MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char));
+ if (!uri)
+ return XML_ERROR_NO_MEMORY;
+ binding->uriAlloc = n + EXPAND_SPARE;
+ memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char));
+ for (p = tagStack; p; p = p->parent)
+ if (p->name.str == binding->uri)
+ p->name.str = uri;
+ FREE(binding->uri);
+ binding->uri = uri;
+ }
+ memcpy(binding->uri + binding->uriLen, localPart, i * sizeof(XML_Char));
+ tagNamePtr->str = binding->uri;
+ return XML_ERROR_NONE;
+}
+
+static
+int addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, const XML_Char *uri, BINDING **bindingsPtr)
+{
+ BINDING *b;
+ int len;
+ for (len = 0; uri[len]; len++)
+ ;
+ if (namespaceSeparator)
+ len++;
+ if (freeBindingList) {
+ b = freeBindingList;
+ if (len > b->uriAlloc) {
+ b->uri = REALLOC(b->uri, sizeof(XML_Char) * (len + EXPAND_SPARE));
+ if (!b->uri)
+ return 0;
+ b->uriAlloc = len + EXPAND_SPARE;
+ }
+ freeBindingList = b->nextTagBinding;
+ }
+ else {
+ b = MALLOC(sizeof(BINDING));
+ if (!b)
+ return 0;
+ b->uri = MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE));
+ if (!b->uri) {
+ FREE(b);
+ return 0;
+ }
+ b->uriAlloc = len + EXPAND_SPARE;
+ }
+ b->uriLen = len;
+ memcpy(b->uri, uri, len * sizeof(XML_Char));
+ if (namespaceSeparator)
+ b->uri[len - 1] = namespaceSeparator;
+ b->prefix = prefix;
+ b->attId = attId;
+ b->prevPrefixBinding = prefix->binding;
+ if (*uri == XML_T('\0') && prefix == &dtd.defaultPrefix)
+ prefix->binding = 0;
+ else
+ prefix->binding = b;
+ b->nextTagBinding = *bindingsPtr;
+ *bindingsPtr = b;
+ if (startNamespaceDeclHandler)
+ startNamespaceDeclHandler(handlerArg, prefix->name,
+ prefix->binding ? uri : 0);
+ return 1;
+}
+
+/* The idea here is to avoid using stack for each CDATA section when
+the whole file is parsed with one call. */
+
+static
+enum XML_Error cdataSectionProcessor(XML_Parser parser,
+ const char *start,
+ const char *end,
+ const char **endPtr)
+{
+ enum XML_Error result = doCdataSection(parser, encoding, &start, end, endPtr);
+ if (start) {
+ processor = contentProcessor;
+ return contentProcessor(parser, start, end, endPtr);
+ }
+ return result;
+}
+
+/* startPtr gets set to non-null is the section is closed, and to null if
+the section is not yet closed. */
+
+static
+enum XML_Error doCdataSection(XML_Parser parser,
+ const ENCODING *enc,
+ const char **startPtr,
+ const char *end,
+ const char **nextPtr)
+{
+ const char *s = *startPtr;
+ const char **eventPP;
+ const char **eventEndPP;
+ if (enc == encoding) {
+ eventPP = &eventPtr;
+ *eventPP = s;
+ eventEndPP = &eventEndPtr;
+ }
+ else {
+ eventPP = &(openInternalEntities->internalEventPtr);
+ eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ }
+ *eventPP = s;
+ *startPtr = 0;
+ for (;;) {
+ const char *next;
+ int tok = XmlCdataSectionTok(enc, s, end, &next);
+ *eventEndPP = next;
+ switch (tok) {
+ case XML_TOK_CDATA_SECT_CLOSE:
+ if (endCdataSectionHandler)
+ endCdataSectionHandler(handlerArg);
+#if 0
+ /* see comment under XML_TOK_CDATA_SECT_OPEN */
+ else if (characterDataHandler)
+ characterDataHandler(handlerArg, dataBuf, 0);
+#endif
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ *startPtr = next;
+ return XML_ERROR_NONE;
+ case XML_TOK_DATA_NEWLINE:
+ if (characterDataHandler) {
+ XML_Char c = 0xA;
+ characterDataHandler(handlerArg, &c, 1);
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ break;
+ case XML_TOK_DATA_CHARS:
+ if (characterDataHandler) {
+ if (MUST_CONVERT(enc, s)) {
+ for (;;) {
+ ICHAR *dataPtr = (ICHAR *)dataBuf;
+ XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
+ *eventEndPP = next;
+ characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
+ if (s == next)
+ break;
+ *eventPP = s;
+ }
+ }
+ else
+ characterDataHandler(handlerArg,
+ (XML_Char *)s,
+ (XML_Char *)next - (XML_Char *)s);
+ }
+ else if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ break;
+ case XML_TOK_INVALID:
+ *eventPP = next;
+ return XML_ERROR_INVALID_TOKEN;
+ case XML_TOK_PARTIAL_CHAR:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ return XML_ERROR_PARTIAL_CHAR;
+ case XML_TOK_PARTIAL:
+ case XML_TOK_NONE:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ return XML_ERROR_UNCLOSED_CDATA_SECTION;
+ default:
+ *eventPP = next;
+ return XML_ERROR_UNEXPECTED_STATE;
+ }
+ *eventPP = s = next;
+ }
+ /* not reached */
+}
+
+#ifdef XML_DTD
+
+/* The idea here is to avoid using stack for each IGNORE section when
+the whole file is parsed with one call. */
+
+static
+enum XML_Error ignoreSectionProcessor(XML_Parser parser,
+ const char *start,
+ const char *end,
+ const char **endPtr)
+{
+ enum XML_Error result = doIgnoreSection(parser, encoding, &start, end, endPtr);
+ if (start) {
+ processor = prologProcessor;
+ return prologProcessor(parser, start, end, endPtr);
+ }
+ return result;
+}
+
+/* startPtr gets set to non-null is the section is closed, and to null if
+the section is not yet closed. */
+
+static
+enum XML_Error doIgnoreSection(XML_Parser parser,
+ const ENCODING *enc,
+ const char **startPtr,
+ const char *end,
+ const char **nextPtr)
+{
+ const char *next;
+ int tok;
+ const char *s = *startPtr;
+ const char **eventPP;
+ const char **eventEndPP;
+ if (enc == encoding) {
+ eventPP = &eventPtr;
+ *eventPP = s;
+ eventEndPP = &eventEndPtr;
+ }
+ else {
+ eventPP = &(openInternalEntities->internalEventPtr);
+ eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ }
+ *eventPP = s;
+ *startPtr = 0;
+ tok = XmlIgnoreSectionTok(enc, s, end, &next);
+ *eventEndPP = next;
+ switch (tok) {
+ case XML_TOK_IGNORE_SECT:
+ if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ *startPtr = next;
+ return XML_ERROR_NONE;
+ case XML_TOK_INVALID:
+ *eventPP = next;
+ return XML_ERROR_INVALID_TOKEN;
+ case XML_TOK_PARTIAL_CHAR:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ return XML_ERROR_PARTIAL_CHAR;
+ case XML_TOK_PARTIAL:
+ case XML_TOK_NONE:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */
+ default:
+ *eventPP = next;
+ return XML_ERROR_UNEXPECTED_STATE;
+ }
+ /* not reached */
+}
+
+#endif /* XML_DTD */
+
+static enum XML_Error
+initializeEncoding(XML_Parser parser)
+{
+ const char *s;
+#ifdef XML_UNICODE
+ char encodingBuf[128];
+ if (!protocolEncodingName)
+ s = 0;
+ else {
+ int i;
+ for (i = 0; protocolEncodingName[i]; i++) {
+ if (i == sizeof(encodingBuf) - 1
+ || (protocolEncodingName[i] & ~0x7f) != 0) {
+ encodingBuf[0] = '\0';
+ break;
+ }
+ encodingBuf[i] = (char)protocolEncodingName[i];
+ }
+ encodingBuf[i] = '\0';
+ s = encodingBuf;
+ }
+#else
+ s = protocolEncodingName;
+#endif
+ if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s))
+ return XML_ERROR_NONE;
+ return handleUnknownEncoding(parser, protocolEncodingName);
+}
+
+static enum XML_Error
+processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
+ const char *s, const char *next)
+{
+ const char *encodingName = 0;
+ const char *storedEncName = 0;
+ const ENCODING *newEncoding = 0;
+ const char *version = 0;
+ const char *versionend;
+ const char *storedversion = 0;
+ int standalone = -1;
+ if (!(ns
+ ? XmlParseXmlDeclNS
+ : XmlParseXmlDecl)(isGeneralTextEntity,
+ encoding,
+ s,
+ next,
+ &eventPtr,
+ &version,
+ &versionend,
+ &encodingName,
+ &newEncoding,
+ &standalone))
+ return XML_ERROR_SYNTAX;
+ if (!isGeneralTextEntity && standalone == 1) {
+ dtd.standalone = 1;
+#ifdef XML_DTD
+ if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE)
+ paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
+#endif /* XML_DTD */
+ }
+ if (xmlDeclHandler) {
+ if (encodingName) {
+ storedEncName = poolStoreString(&temp2Pool,
+ encoding,
+ encodingName,
+ encodingName
+ + XmlNameLength(encoding, encodingName));
+ if (! storedEncName)
+ return XML_ERROR_NO_MEMORY;
+ poolFinish(&temp2Pool);
+ }
+ if (version) {
+ storedversion = poolStoreString(&temp2Pool,
+ encoding,
+ version,
+ versionend - encoding->minBytesPerChar);
+ if (! storedversion)
+ return XML_ERROR_NO_MEMORY;
+ }
+ xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone);
+ }
+ else if (defaultHandler)
+ reportDefault(parser, encoding, s, next);
+ if (!protocolEncodingName) {
+ if (newEncoding) {
+ if (newEncoding->minBytesPerChar != encoding->minBytesPerChar) {
+ eventPtr = encodingName;
+ return XML_ERROR_INCORRECT_ENCODING;
+ }
+ encoding = newEncoding;
+ }
+ else if (encodingName) {
+ enum XML_Error result;
+ if (! storedEncName) {
+ storedEncName = poolStoreString(&temp2Pool,
+ encoding,
+ encodingName,
+ encodingName
+ + XmlNameLength(encoding, encodingName));
+ if (! storedEncName)
+ return XML_ERROR_NO_MEMORY;
+ }
+ result = handleUnknownEncoding(parser, storedEncName);
+ poolClear(&tempPool);
+ if (result == XML_ERROR_UNKNOWN_ENCODING)
+ eventPtr = encodingName;
+ return result;
+ }
+ }
+
+ if (storedEncName || storedversion)
+ poolClear(&temp2Pool);
+
+ return XML_ERROR_NONE;
+}
+
+static enum XML_Error
+handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName)
+{
+ if (unknownEncodingHandler) {
+ XML_Encoding info;
+ int i;
+ for (i = 0; i < 256; i++)
+ info.map[i] = -1;
+ info.convert = 0;
+ info.data = 0;
+ info.release = 0;
+ if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName, &info)) {
+ ENCODING *enc;
+ unknownEncodingMem = MALLOC(XmlSizeOfUnknownEncoding());
+ if (!unknownEncodingMem) {
+ if (info.release)
+ info.release(info.data);
+ return XML_ERROR_NO_MEMORY;
+ }
+ enc = (ns
+ ? XmlInitUnknownEncodingNS
+ : XmlInitUnknownEncoding)(unknownEncodingMem,
+ info.map,
+ info.convert,
+ info.data);
+ if (enc) {
+ unknownEncodingData = info.data;
+ unknownEncodingRelease = info.release;
+ encoding = enc;
+ return XML_ERROR_NONE;
+ }
+ }
+ if (info.release)
+ info.release(info.data);
+ }
+ return XML_ERROR_UNKNOWN_ENCODING;
+}
+
+static enum XML_Error
+prologInitProcessor(XML_Parser parser,
+ const char *s,
+ const char *end,
+ const char **nextPtr)
+{
+ enum XML_Error result = initializeEncoding(parser);
+ if (result != XML_ERROR_NONE)
+ return result;
+ processor = prologProcessor;
+ return prologProcessor(parser, s, end, nextPtr);
+}
+
+static enum XML_Error
+prologProcessor(XML_Parser parser,
+ const char *s,
+ const char *end,
+ const char **nextPtr)
+{
+ const char *next;
+ int tok = XmlPrologTok(encoding, s, end, &next);
+ return doProlog(parser, encoding, s, end, tok, next, nextPtr);
+}
+
+static enum XML_Error
+doProlog(XML_Parser parser,
+ const ENCODING *enc,
+ const char *s,
+ const char *end,
+ int tok,
+ const char *next,
+ const char **nextPtr)
+{
+#ifdef XML_DTD
+ static const XML_Char externalSubsetName[] = { '#' , '\0' };
+#endif /* XML_DTD */
+
+ const char **eventPP;
+ const char **eventEndPP;
+ enum XML_Content_Quant quant;
+
+ if (enc == encoding) {
+ eventPP = &eventPtr;
+ eventEndPP = &eventEndPtr;
+ }
+ else {
+ eventPP = &(openInternalEntities->internalEventPtr);
+ eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ }
+ for (;;) {
+ int role;
+ *eventPP = s;
+ *eventEndPP = next;
+ if (tok <= 0) {
+ if (nextPtr != 0 && tok != XML_TOK_INVALID) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ switch (tok) {
+ case XML_TOK_INVALID:
+ *eventPP = next;
+ return XML_ERROR_INVALID_TOKEN;
+ case XML_TOK_PARTIAL:
+ return XML_ERROR_UNCLOSED_TOKEN;
+ case XML_TOK_PARTIAL_CHAR:
+ return XML_ERROR_PARTIAL_CHAR;
+ case XML_TOK_NONE:
+#ifdef XML_DTD
+ if (enc != encoding)
+ return XML_ERROR_NONE;
+ if (parentParser) {
+ if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc)
+ == XML_ROLE_ERROR)
+ return XML_ERROR_SYNTAX;
+ hadExternalDoctype = 0;
+ return XML_ERROR_NONE;
+ }
+#endif /* XML_DTD */
+ return XML_ERROR_NO_ELEMENTS;
+ default:
+ tok = -tok;
+ next = end;
+ break;
+ }
+ }
+ role = XmlTokenRole(&prologState, tok, s, next, enc);
+ switch (role) {
+ case XML_ROLE_XML_DECL:
+ {
+ enum XML_Error result = processXmlDecl(parser, 0, s, next);
+ if (result != XML_ERROR_NONE)
+ return result;
+ enc = encoding;
+ }
+ break;
+ case XML_ROLE_DOCTYPE_NAME:
+ if (startDoctypeDeclHandler) {
+ doctypeName = poolStoreString(&tempPool, enc, s, next);
+ if (! doctypeName)
+ return XML_ERROR_NO_MEMORY;
+ poolFinish(&tempPool);
+ doctypeSysid = 0;
+ doctypePubid = 0;
+ }
+ break;
+ case XML_ROLE_DOCTYPE_INTERNAL_SUBSET:
+ if (startDoctypeDeclHandler) {
+ startDoctypeDeclHandler(handlerArg, doctypeName, doctypeSysid,
+ doctypePubid, 1);
+ doctypeName = 0;
+ poolClear(&tempPool);
+ }
+ break;
+#ifdef XML_DTD
+ case XML_ROLE_TEXT_DECL:
+ {
+ enum XML_Error result = processXmlDecl(parser, 1, s, next);
+ if (result != XML_ERROR_NONE)
+ return result;
+ enc = encoding;
+ }
+ break;
+#endif /* XML_DTD */
+ case XML_ROLE_DOCTYPE_PUBLIC_ID:
+ if (startDoctypeDeclHandler) {
+ doctypePubid = poolStoreString(&tempPool, enc, s + 1, next - 1);
+ if (! doctypePubid)
+ return XML_ERROR_NO_MEMORY;
+ poolFinish(&tempPool);
+ }
+#ifdef XML_DTD
+ declEntity = (ENTITY *)lookup(&dtd.paramEntities,
+ externalSubsetName,
+ sizeof(ENTITY));
+ if (!declEntity)
+ return XML_ERROR_NO_MEMORY;
+#endif /* XML_DTD */
+ /* fall through */
+ case XML_ROLE_ENTITY_PUBLIC_ID:
+ if (!XmlIsPublicId(enc, s, next, eventPP))
+ return XML_ERROR_SYNTAX;
+ if (declEntity) {
+ XML_Char *tem = poolStoreString(&dtd.pool,
+ enc,
+ s + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (!tem)
+ return XML_ERROR_NO_MEMORY;
+ normalizePublicId(tem);
+ declEntity->publicId = tem;
+ poolFinish(&dtd.pool);
+ }
+ break;
+ case XML_ROLE_DOCTYPE_CLOSE:
+ if (doctypeName) {
+ startDoctypeDeclHandler(handlerArg, doctypeName,
+ doctypeSysid, doctypePubid, 0);
+ poolClear(&tempPool);
+ }
+ if (dtd.complete && hadExternalDoctype) {
+ dtd.complete = 0;
+#ifdef XML_DTD
+ if (paramEntityParsing && externalEntityRefHandler) {
+ ENTITY *entity = (ENTITY *)lookup(&dtd.paramEntities,
+ externalSubsetName,
+ 0);
+ if (!externalEntityRefHandler(externalEntityRefHandlerArg,
+ 0,
+ entity->base,
+ entity->systemId,
+ entity->publicId))
+ return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
+ }
+#endif /* XML_DTD */
+ if (!dtd.complete
+ && !dtd.standalone
+ && notStandaloneHandler
+ && !notStandaloneHandler(handlerArg))
+ return XML_ERROR_NOT_STANDALONE;
+ }
+ if (endDoctypeDeclHandler)
+ endDoctypeDeclHandler(handlerArg);
+ break;
+ case XML_ROLE_INSTANCE_START:
+ processor = contentProcessor;
+ return contentProcessor(parser, s, end, nextPtr);
+ case XML_ROLE_ATTLIST_ELEMENT_NAME:
+ declElementType = getElementType(parser, enc, s, next);
+ if (!declElementType)
+ return XML_ERROR_NO_MEMORY;
+ break;
+ case XML_ROLE_ATTRIBUTE_NAME:
+ declAttributeId = getAttributeId(parser, enc, s, next);
+ if (!declAttributeId)
+ return XML_ERROR_NO_MEMORY;
+ declAttributeIsCdata = 0;
+ declAttributeType = 0;
+ declAttributeIsId = 0;
+ break;
+ case XML_ROLE_ATTRIBUTE_TYPE_CDATA:
+ declAttributeIsCdata = 1;
+ declAttributeType = "CDATA";
+ break;
+ case XML_ROLE_ATTRIBUTE_TYPE_ID:
+ declAttributeIsId = 1;
+ declAttributeType = "ID";
+ break;
+ case XML_ROLE_ATTRIBUTE_TYPE_IDREF:
+ declAttributeType = "IDREF";
+ break;
+ case XML_ROLE_ATTRIBUTE_TYPE_IDREFS:
+ declAttributeType = "IDREFS";
+ break;
+ case XML_ROLE_ATTRIBUTE_TYPE_ENTITY:
+ declAttributeType = "ENTITY";
+ break;
+ case XML_ROLE_ATTRIBUTE_TYPE_ENTITIES:
+ declAttributeType = "ENTITIES";
+ break;
+ case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN:
+ declAttributeType = "NMTOKEN";
+ break;
+ case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS:
+ declAttributeType = "NMTOKENS";
+ break;
+
+ case XML_ROLE_ATTRIBUTE_ENUM_VALUE:
+ case XML_ROLE_ATTRIBUTE_NOTATION_VALUE:
+ if (attlistDeclHandler)
+ {
+ char *prefix;
+ if (declAttributeType) {
+ prefix = "|";
+ }
+ else {
+ prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE
+ ? "NOTATION("
+ : "(");
+ }
+ if (! poolAppendString(&tempPool, prefix))
+ return XML_ERROR_NO_MEMORY;
+ if (! poolAppend(&tempPool, enc, s, next))
+ return XML_ERROR_NO_MEMORY;
+ declAttributeType = tempPool.start;
+ }
+ break;
+ case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE:
+ case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE:
+ if (dtd.complete
+ && !defineAttribute(declElementType, declAttributeId,
+ declAttributeIsCdata, declAttributeIsId, 0,
+ parser))
+ return XML_ERROR_NO_MEMORY;
+ if (attlistDeclHandler && declAttributeType) {
+ if (*declAttributeType == '('
+ || (*declAttributeType == 'N' && declAttributeType[1] == 'O')) {
+ /* Enumerated or Notation type */
+ if (! poolAppendChar(&tempPool, ')')
+ || ! poolAppendChar(&tempPool, '\0'))
+ return XML_ERROR_NO_MEMORY;
+ declAttributeType = tempPool.start;
+ poolFinish(&tempPool);
+ }
+ *eventEndPP = s;
+ attlistDeclHandler(handlerArg, declElementType->name,
+ declAttributeId->name, declAttributeType,
+ 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE);
+ poolClear(&tempPool);
+ }
+ break;
+ case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE:
+ case XML_ROLE_FIXED_ATTRIBUTE_VALUE:
+ {
+ const XML_Char *attVal;
+ enum XML_Error result
+ = storeAttributeValue(parser, enc, declAttributeIsCdata,
+ s + enc->minBytesPerChar,
+ next - enc->minBytesPerChar,
+ &dtd.pool);
+ if (result)
+ return result;
+ attVal = poolStart(&dtd.pool);
+ poolFinish(&dtd.pool);
+ if (dtd.complete
+ /* ID attributes aren't allowed to have a default */
+ && !defineAttribute(declElementType, declAttributeId, declAttributeIsCdata, 0, attVal, parser))
+ return XML_ERROR_NO_MEMORY;
+ if (attlistDeclHandler && declAttributeType) {
+ if (*declAttributeType == '('
+ || (*declAttributeType == 'N' && declAttributeType[1] == 'O')) {
+ /* Enumerated or Notation type */
+ if (! poolAppendChar(&tempPool, ')')
+ || ! poolAppendChar(&tempPool, '\0'))
+ return XML_ERROR_NO_MEMORY;
+ declAttributeType = tempPool.start;
+ poolFinish(&tempPool);
+ }
+ *eventEndPP = s;
+ attlistDeclHandler(handlerArg, declElementType->name,
+ declAttributeId->name, declAttributeType,
+ attVal,
+ role == XML_ROLE_FIXED_ATTRIBUTE_VALUE);
+ poolClear(&tempPool);
+ }
+ break;
+ }
+ case XML_ROLE_ENTITY_VALUE:
+ {
+ enum XML_Error result = storeEntityValue(parser, enc,
+ s + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (declEntity) {
+ declEntity->textPtr = poolStart(&dtd.pool);
+ declEntity->textLen = poolLength(&dtd.pool);
+ poolFinish(&dtd.pool);
+ if (entityDeclHandler) {
+ *eventEndPP = s;
+ entityDeclHandler(handlerArg,
+ declEntity->name,
+ declEntity->is_param,
+ declEntity->textPtr,
+ declEntity->textLen,
+ curBase, 0, 0, 0);
+ }
+ }
+ else
+ poolDiscard(&dtd.pool);
+ if (result != XML_ERROR_NONE)
+ return result;
+ }
+ break;
+ case XML_ROLE_DOCTYPE_SYSTEM_ID:
+ if (startDoctypeDeclHandler) {
+ doctypeSysid = poolStoreString(&tempPool, enc, s + 1, next - 1);
+ if (! doctypeSysid)
+ return XML_ERROR_NO_MEMORY;
+ poolFinish(&tempPool);
+ }
+ if (!dtd.standalone
+#ifdef XML_DTD
+ && !paramEntityParsing
+#endif /* XML_DTD */
+ && notStandaloneHandler
+ && !notStandaloneHandler(handlerArg))
+ return XML_ERROR_NOT_STANDALONE;
+ hadExternalDoctype = 1;
+#ifndef XML_DTD
+ break;
+#else /* XML_DTD */
+ if (!declEntity) {
+ declEntity = (ENTITY *)lookup(&dtd.paramEntities,
+ externalSubsetName,
+ sizeof(ENTITY));
+ declEntity->publicId = 0;
+ if (!declEntity)
+ return XML_ERROR_NO_MEMORY;
+ }
+ /* fall through */
+#endif /* XML_DTD */
+ case XML_ROLE_ENTITY_SYSTEM_ID:
+ if (declEntity) {
+ declEntity->systemId = poolStoreString(&dtd.pool, enc,
+ s + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (!declEntity->systemId)
+ return XML_ERROR_NO_MEMORY;
+ declEntity->base = curBase;
+ poolFinish(&dtd.pool);
+ }
+ break;
+ case XML_ROLE_ENTITY_COMPLETE:
+ if (declEntity && entityDeclHandler) {
+ *eventEndPP = s;
+ entityDeclHandler(handlerArg,
+ declEntity->name,
+ 0,0,0,
+ declEntity->base,
+ declEntity->systemId,
+ declEntity->publicId,
+ 0);
+ }
+ break;
+ case XML_ROLE_ENTITY_NOTATION_NAME:
+ if (declEntity) {
+ declEntity->notation = poolStoreString(&dtd.pool, enc, s, next);
+ if (!declEntity->notation)
+ return XML_ERROR_NO_MEMORY;
+ poolFinish(&dtd.pool);
+ if (unparsedEntityDeclHandler) {
+ *eventEndPP = s;
+ unparsedEntityDeclHandler(handlerArg,
+ declEntity->name,
+ declEntity->base,
+ declEntity->systemId,
+ declEntity->publicId,
+ declEntity->notation);
+ }
+ else if (entityDeclHandler) {
+ *eventEndPP = s;
+ entityDeclHandler(handlerArg,
+ declEntity->name,
+ 0,0,0,
+ declEntity->base,
+ declEntity->systemId,
+ declEntity->publicId,
+ declEntity->notation);
+ }
+ }
+ break;
+ case XML_ROLE_GENERAL_ENTITY_NAME:
+ {
+ const XML_Char *name;
+ if (XmlPredefinedEntityName(enc, s, next)) {
+ declEntity = 0;
+ break;
+ }
+ name = poolStoreString(&dtd.pool, enc, s, next);
+ if (!name)
+ return XML_ERROR_NO_MEMORY;
+ if (dtd.complete) {
+ declEntity = (ENTITY *)lookup(&dtd.generalEntities, name, sizeof(ENTITY));
+ if (!declEntity)
+ return XML_ERROR_NO_MEMORY;
+ if (declEntity->name != name) {
+ poolDiscard(&dtd.pool);
+ declEntity = 0;
+ }
+ else {
+ poolFinish(&dtd.pool);
+ declEntity->publicId = 0;
+ declEntity->is_param = 0;
+ }
+ }
+ else {
+ poolDiscard(&dtd.pool);
+ declEntity = 0;
+ }
+ }
+ break;
+ case XML_ROLE_PARAM_ENTITY_NAME:
+#ifdef XML_DTD
+ if (dtd.complete) {
+ const XML_Char *name = poolStoreString(&dtd.pool, enc, s, next);
+ if (!name)
+ return XML_ERROR_NO_MEMORY;
+ declEntity = (ENTITY *)lookup(&dtd.paramEntities,
+ name, sizeof(ENTITY));
+ if (!declEntity)
+ return XML_ERROR_NO_MEMORY;
+ if (declEntity->name != name) {
+ poolDiscard(&dtd.pool);
+ declEntity = 0;
+ }
+ else {
+ poolFinish(&dtd.pool);
+ declEntity->publicId = 0;
+ declEntity->is_param = 1;
+ }
+ }
+#else /* not XML_DTD */
+ declEntity = 0;
+#endif /* not XML_DTD */
+ break;
+ case XML_ROLE_NOTATION_NAME:
+ declNotationPublicId = 0;
+ declNotationName = 0;
+ if (notationDeclHandler) {
+ declNotationName = poolStoreString(&tempPool, enc, s, next);
+ if (!declNotationName)
+ return XML_ERROR_NO_MEMORY;
+ poolFinish(&tempPool);
+ }
+ break;
+ case XML_ROLE_NOTATION_PUBLIC_ID:
+ if (!XmlIsPublicId(enc, s, next, eventPP))
+ return XML_ERROR_SYNTAX;
+ if (declNotationName) {
+ XML_Char *tem = poolStoreString(&tempPool,
+ enc,
+ s + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (!tem)
+ return XML_ERROR_NO_MEMORY;
+ normalizePublicId(tem);
+ declNotationPublicId = tem;
+ poolFinish(&tempPool);
+ }
+ break;
+ case XML_ROLE_NOTATION_SYSTEM_ID:
+ if (declNotationName && notationDeclHandler) {
+ const XML_Char *systemId
+ = poolStoreString(&tempPool, enc,
+ s + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (!systemId)
+ return XML_ERROR_NO_MEMORY;
+ *eventEndPP = s;
+ notationDeclHandler(handlerArg,
+ declNotationName,
+ curBase,
+ systemId,
+ declNotationPublicId);
+ }
+ poolClear(&tempPool);
+ break;
+ case XML_ROLE_NOTATION_NO_SYSTEM_ID:
+ if (declNotationPublicId && notationDeclHandler) {
+ *eventEndPP = s;
+ notationDeclHandler(handlerArg,
+ declNotationName,
+ curBase,
+ 0,
+ declNotationPublicId);
+ }
+ poolClear(&tempPool);
+ break;
+ case XML_ROLE_ERROR:
+ switch (tok) {
+ case XML_TOK_PARAM_ENTITY_REF:
+ return XML_ERROR_PARAM_ENTITY_REF;
+ case XML_TOK_XML_DECL:
+ return XML_ERROR_MISPLACED_XML_PI;
+ default:
+ return XML_ERROR_SYNTAX;
+ }
+#ifdef XML_DTD
+ case XML_ROLE_IGNORE_SECT:
+ {
+ enum XML_Error result;
+ if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ result = doIgnoreSection(parser, enc, &next, end, nextPtr);
+ if (!next) {
+ processor = ignoreSectionProcessor;
+ return result;
+ }
+ }
+ break;
+#endif /* XML_DTD */
+ case XML_ROLE_GROUP_OPEN:
+ if (prologState.level >= groupSize) {
+ if (groupSize) {
+ groupConnector = REALLOC(groupConnector, groupSize *= 2);
+ if (dtd.scaffIndex)
+ dtd.scaffIndex = REALLOC(dtd.scaffIndex, groupSize * sizeof(int));
+ }
+ else
+ groupConnector = MALLOC(groupSize = 32);
+ if (!groupConnector)
+ return XML_ERROR_NO_MEMORY;
+ }
+ groupConnector[prologState.level] = 0;
+ if (dtd.in_eldecl) {
+ int myindex = nextScaffoldPart(parser);
+ if (myindex < 0)
+ return XML_ERROR_NO_MEMORY;
+ dtd.scaffIndex[dtd.scaffLevel] = myindex;
+ dtd.scaffLevel++;
+ dtd.scaffold[myindex].type = XML_CTYPE_SEQ;
+ }
+ break;
+ case XML_ROLE_GROUP_SEQUENCE:
+ if (groupConnector[prologState.level] == '|')
+ return XML_ERROR_SYNTAX;
+ groupConnector[prologState.level] = ',';
+ break;
+ case XML_ROLE_GROUP_CHOICE:
+ if (groupConnector[prologState.level] == ',')
+ return XML_ERROR_SYNTAX;
+ if (dtd.in_eldecl
+ && ! groupConnector[prologState.level]
+ && dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel - 1]].type != XML_CTYPE_MIXED
+ ) {
+ dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel - 1]].type = XML_CTYPE_CHOICE;
+ }
+ groupConnector[prologState.level] = '|';
+ break;
+ case XML_ROLE_PARAM_ENTITY_REF:
+#ifdef XML_DTD
+ case XML_ROLE_INNER_PARAM_ENTITY_REF:
+ if (paramEntityParsing
+ && (dtd.complete || role == XML_ROLE_INNER_PARAM_ENTITY_REF)) {
+ const XML_Char *name;
+ ENTITY *entity;
+ name = poolStoreString(&dtd.pool, enc,
+ s + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (!name)
+ return XML_ERROR_NO_MEMORY;
+ entity = (ENTITY *)lookup(&dtd.paramEntities, name, 0);
+ poolDiscard(&dtd.pool);
+ if (!entity) {
+ /* FIXME what to do if !dtd.complete? */
+ return XML_ERROR_UNDEFINED_ENTITY;
+ }
+ if (entity->open)
+ return XML_ERROR_RECURSIVE_ENTITY_REF;
+ if (entity->textPtr) {
+ enum XML_Error result;
+ result = processInternalParamEntity(parser, entity);
+ if (result != XML_ERROR_NONE)
+ return result;
+ break;
+ }
+ if (role == XML_ROLE_INNER_PARAM_ENTITY_REF)
+ return XML_ERROR_PARAM_ENTITY_REF;
+ if (externalEntityRefHandler) {
+ dtd.complete = 0;
+ entity->open = 1;
+ if (!externalEntityRefHandler(externalEntityRefHandlerArg,
+ 0,
+ entity->base,
+ entity->systemId,
+ entity->publicId)) {
+ entity->open = 0;
+ return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
+ }
+ entity->open = 0;
+ if (dtd.complete)
+ break;
+ }
+ }
+#endif /* XML_DTD */
+ if (!dtd.standalone
+ && notStandaloneHandler
+ && !notStandaloneHandler(handlerArg))
+ return XML_ERROR_NOT_STANDALONE;
+ dtd.complete = 0;
+ if (defaultHandler)
+ reportDefault(parser, enc, s, next);
+ break;
+
+ /* Element declaration stuff */
+
+ case XML_ROLE_ELEMENT_NAME:
+ if (elementDeclHandler) {
+ declElementType = getElementType(parser, enc, s, next);
+ if (! declElementType)
+ return XML_ERROR_NO_MEMORY;
+ dtd.scaffLevel = 0;
+ dtd.scaffCount = 0;
+ dtd.in_eldecl = 1;
+ }
+ break;
+
+ case XML_ROLE_CONTENT_ANY:
+ case XML_ROLE_CONTENT_EMPTY:
+ if (dtd.in_eldecl) {
+ if (elementDeclHandler) {
+ XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content));
+ if (! content)
+ return XML_ERROR_NO_MEMORY;
+ content->quant = XML_CQUANT_NONE;
+ content->name = 0;
+ content->numchildren = 0;
+ content->children = 0;
+ content->type = ((role == XML_ROLE_CONTENT_ANY) ?
+ XML_CTYPE_ANY :
+ XML_CTYPE_EMPTY);
+ *eventEndPP = s;
+ elementDeclHandler(handlerArg, declElementType->name, content);
+ }
+ dtd.in_eldecl = 0;
+ }
+ break;
+
+ case XML_ROLE_CONTENT_PCDATA:
+ if (dtd.in_eldecl) {
+ dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel - 1]].type = XML_CTYPE_MIXED;
+ }
+ break;
+
+ case XML_ROLE_CONTENT_ELEMENT:
+ quant = XML_CQUANT_NONE;
+ goto elementContent;
+ case XML_ROLE_CONTENT_ELEMENT_OPT:
+ quant = XML_CQUANT_OPT;
+ goto elementContent;
+ case XML_ROLE_CONTENT_ELEMENT_REP:
+ quant = XML_CQUANT_REP;
+ goto elementContent;
+ case XML_ROLE_CONTENT_ELEMENT_PLUS:
+ quant = XML_CQUANT_PLUS;
+ elementContent:
+ if (dtd.in_eldecl)
+ {
+ ELEMENT_TYPE *el;
+ const char *nxt = quant == XML_CQUANT_NONE ? next : next - 1;
+ int myindex = nextScaffoldPart(parser);
+ if (myindex < 0)
+ return XML_ERROR_NO_MEMORY;
+ dtd.scaffold[myindex].type = XML_CTYPE_NAME;
+ dtd.scaffold[myindex].quant = quant;
+ el = getElementType(parser, enc, s, nxt);
+ if (! el)
+ return XML_ERROR_NO_MEMORY;
+ dtd.scaffold[myindex].name = el->name;
+ dtd.contentStringLen += nxt - s + 1;
+ }
+ break;
+
+ case XML_ROLE_GROUP_CLOSE:
+ quant = XML_CQUANT_NONE;
+ goto closeGroup;
+ case XML_ROLE_GROUP_CLOSE_OPT:
+ quant = XML_CQUANT_OPT;
+ goto closeGroup;
+ case XML_ROLE_GROUP_CLOSE_REP:
+ quant = XML_CQUANT_REP;
+ goto closeGroup;
+ case XML_ROLE_GROUP_CLOSE_PLUS:
+ quant = XML_CQUANT_PLUS;
+ closeGroup:
+ if (dtd.in_eldecl) {
+ dtd.scaffLevel--;
+ dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel]].quant = quant;
+ if (dtd.scaffLevel == 0) {
+ if (elementDeclHandler) {
+ XML_Content *model = build_model(parser);
+ if (! model)
+ return XML_ERROR_NO_MEMORY;
+ *eventEndPP = s;
+ elementDeclHandler(handlerArg, declElementType->name, model);
+ }
+ dtd.in_eldecl = 0;
+ dtd.contentStringLen = 0;
+ }
+ }
+ break;
+ /* End element declaration stuff */
+
+ case XML_ROLE_NONE:
+ switch (tok) {
+ case XML_TOK_PI:
+ if (!reportProcessingInstruction(parser, enc, s, next))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ case XML_TOK_COMMENT:
+ if (!reportComment(parser, enc, s, next))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ }
+ break;
+ }
+ if (defaultHandler) {
+ switch (tok) {
+ case XML_TOK_PI:
+ case XML_TOK_COMMENT:
+ case XML_TOK_BOM:
+ case XML_TOK_XML_DECL:
+#ifdef XML_DTD
+ case XML_TOK_IGNORE_SECT:
+#endif /* XML_DTD */
+ case XML_TOK_PARAM_ENTITY_REF:
+ break;
+ default:
+#ifdef XML_DTD
+ if (role != XML_ROLE_IGNORE_SECT)
+#endif /* XML_DTD */
+ reportDefault(parser, enc, s, next);
+ }
+ }
+ s = next;
+ tok = XmlPrologTok(enc, s, end, &next);
+ }
+ /* not reached */
+}
+
+static
+enum XML_Error epilogProcessor(XML_Parser parser,
+ const char *s,
+ const char *end,
+ const char **nextPtr)
+{
+ processor = epilogProcessor;
+ eventPtr = s;
+ for (;;) {
+ const char *next;
+ int tok = XmlPrologTok(encoding, s, end, &next);
+ eventEndPtr = next;
+ switch (tok) {
+ case -XML_TOK_PROLOG_S:
+ if (defaultHandler) {
+ eventEndPtr = end;
+ reportDefault(parser, encoding, s, end);
+ }
+ /* fall through */
+ case XML_TOK_NONE:
+ if (nextPtr)
+ *nextPtr = end;
+ return XML_ERROR_NONE;
+ case XML_TOK_PROLOG_S:
+ if (defaultHandler)
+ reportDefault(parser, encoding, s, next);
+ break;
+ case XML_TOK_PI:
+ if (!reportProcessingInstruction(parser, encoding, s, next))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ case XML_TOK_COMMENT:
+ if (!reportComment(parser, encoding, s, next))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ case XML_TOK_INVALID:
+ eventPtr = next;
+ return XML_ERROR_INVALID_TOKEN;
+ case XML_TOK_PARTIAL:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ return XML_ERROR_UNCLOSED_TOKEN;
+ case XML_TOK_PARTIAL_CHAR:
+ if (nextPtr) {
+ *nextPtr = s;
+ return XML_ERROR_NONE;
+ }
+ return XML_ERROR_PARTIAL_CHAR;
+ default:
+ return XML_ERROR_JUNK_AFTER_DOC_ELEMENT;
+ }
+ eventPtr = s = next;
+ }
+}
+
+#ifdef XML_DTD
+
+static enum XML_Error
+processInternalParamEntity(XML_Parser parser, ENTITY *entity)
+{
+ const char *s, *end, *next;
+ int tok;
+ enum XML_Error result;
+ OPEN_INTERNAL_ENTITY openEntity;
+ entity->open = 1;
+ openEntity.next = openInternalEntities;
+ openInternalEntities = &openEntity;
+ openEntity.entity = entity;
+ openEntity.internalEventPtr = 0;
+ openEntity.internalEventEndPtr = 0;
+ s = (char *)entity->textPtr;
+ end = (char *)(entity->textPtr + entity->textLen);
+ tok = XmlPrologTok(internalEncoding, s, end, &next);
+ result = doProlog(parser, internalEncoding, s, end, tok, next, 0);
+ entity->open = 0;
+ openInternalEntities = openEntity.next;
+ return result;
+}
+
+#endif /* XML_DTD */
+
+static
+enum XML_Error errorProcessor(XML_Parser parser,
+ const char *s,
+ const char *end,
+ const char **nextPtr)
+{
+ cmExpatUnused(s);
+ cmExpatUnused(end);
+ cmExpatUnused(nextPtr);
+ return errorCode;
+}
+
+static enum XML_Error
+storeAttributeValue(XML_Parser parser, const ENCODING *enc, int isCdata,
+ const char *ptr, const char *end,
+ STRING_POOL *pool)
+{
+ enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, end, pool);
+ if (result)
+ return result;
+ if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20)
+ poolChop(pool);
+ if (!poolAppendChar(pool, XML_T('\0')))
+ return XML_ERROR_NO_MEMORY;
+ return XML_ERROR_NONE;
+}
+
+static enum XML_Error
+appendAttributeValue(XML_Parser parser, const ENCODING *enc, int isCdata,
+ const char *ptr, const char *end,
+ STRING_POOL *pool)
+{
+ for (;;) {
+ const char *next;
+ int tok = XmlAttributeValueTok(enc, ptr, end, &next);
+ switch (tok) {
+ case XML_TOK_NONE:
+ return XML_ERROR_NONE;
+ case XML_TOK_INVALID:
+ if (enc == encoding)
+ eventPtr = next;
+ return XML_ERROR_INVALID_TOKEN;
+ case XML_TOK_PARTIAL:
+ if (enc == encoding)
+ eventPtr = ptr;
+ return XML_ERROR_INVALID_TOKEN;
+ case XML_TOK_CHAR_REF:
+ {
+ XML_Char buf[XML_ENCODE_MAX];
+ int i;
+ int n = XmlCharRefNumber(enc, ptr);
+ if (n < 0) {
+ if (enc == encoding)
+ eventPtr = ptr;
+ return XML_ERROR_BAD_CHAR_REF;
+ }
+ if (!isCdata
+ && n == 0x20 /* space */
+ && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20))
+ break;
+ n = XmlEncode(n, (ICHAR *)buf);
+ if (!n) {
+ if (enc == encoding)
+ eventPtr = ptr;
+ return XML_ERROR_BAD_CHAR_REF;
+ }
+ for (i = 0; i < n; i++) {
+ if (!poolAppendChar(pool, buf[i]))
+ return XML_ERROR_NO_MEMORY;
+ }
+ }
+ break;
+ case XML_TOK_DATA_CHARS:
+ if (!poolAppend(pool, enc, ptr, next))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ case XML_TOK_TRAILING_CR:
+ next = ptr + enc->minBytesPerChar;
+ /* fall through */
+ case XML_TOK_ATTRIBUTE_VALUE_S:
+ case XML_TOK_DATA_NEWLINE:
+ if (!isCdata && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20))
+ break;
+ if (!poolAppendChar(pool, 0x20))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ case XML_TOK_ENTITY_REF:
+ {
+ const XML_Char *name;
+ ENTITY *entity;
+ XML_Char ch = XmlPredefinedEntityName(enc,
+ ptr + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (ch) {
+ if (!poolAppendChar(pool, ch))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ }
+ name = poolStoreString(&temp2Pool, enc,
+ ptr + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (!name)
+ return XML_ERROR_NO_MEMORY;
+ entity = (ENTITY *)lookup(&dtd.generalEntities, name, 0);
+ poolDiscard(&temp2Pool);
+ if (!entity) {
+ if (dtd.complete) {
+ if (enc == encoding)
+ eventPtr = ptr;
+ return XML_ERROR_UNDEFINED_ENTITY;
+ }
+ }
+ else if (entity->open) {
+ if (enc == encoding)
+ eventPtr = ptr;
+ return XML_ERROR_RECURSIVE_ENTITY_REF;
+ }
+ else if (entity->notation) {
+ if (enc == encoding)
+ eventPtr = ptr;
+ return XML_ERROR_BINARY_ENTITY_REF;
+ }
+ else if (!entity->textPtr) {
+ if (enc == encoding)
+ eventPtr = ptr;
+ return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF;
+ }
+ else {
+ enum XML_Error result;
+ const XML_Char *textEnd = entity->textPtr + entity->textLen;
+ entity->open = 1;
+ result = appendAttributeValue(parser, internalEncoding, isCdata, (char *)entity->textPtr, (char *)textEnd, pool);
+ entity->open = 0;
+ if (result)
+ return result;
+ }
+ }
+ break;
+ default:
+ if (enc == encoding)
+ eventPtr = ptr;
+ return XML_ERROR_UNEXPECTED_STATE;
+ }
+ ptr = next;
+ }
+ /* not reached */
+}
+
+static
+enum XML_Error storeEntityValue(XML_Parser parser,
+ const ENCODING *enc,
+ const char *entityTextPtr,
+ const char *entityTextEnd)
+{
+ STRING_POOL *pool = &(dtd.pool);
+ for (;;) {
+ const char *next;
+ int tok = XmlEntityValueTok(enc, entityTextPtr, entityTextEnd, &next);
+ switch (tok) {
+ case XML_TOK_PARAM_ENTITY_REF:
+#ifdef XML_DTD
+ if (parentParser || enc != encoding) {
+ enum XML_Error result;
+ const XML_Char *name;
+ ENTITY *entity;
+ name = poolStoreString(&tempPool, enc,
+ entityTextPtr + enc->minBytesPerChar,
+ next - enc->minBytesPerChar);
+ if (!name)
+ return XML_ERROR_NO_MEMORY;
+ entity = (ENTITY *)lookup(&dtd.paramEntities, name, 0);
+ poolDiscard(&tempPool);
+ if (!entity) {
+ if (enc == encoding)
+ eventPtr = entityTextPtr;
+ return XML_ERROR_UNDEFINED_ENTITY;
+ }
+ if (entity->open) {
+ if (enc == encoding)
+ eventPtr = entityTextPtr;
+ return XML_ERROR_RECURSIVE_ENTITY_REF;
+ }
+ if (entity->systemId) {
+ if (enc == encoding)
+ eventPtr = entityTextPtr;
+ return XML_ERROR_PARAM_ENTITY_REF;
+ }
+ entity->open = 1;
+ result = storeEntityValue(parser,
+ internalEncoding,
+ (char *)entity->textPtr,
+ (char *)(entity->textPtr + entity->textLen));
+ entity->open = 0;
+ if (result)
+ return result;
+ break;
+ }
+#endif /* XML_DTD */
+ eventPtr = entityTextPtr;
+ return XML_ERROR_SYNTAX;
+ case XML_TOK_NONE:
+ return XML_ERROR_NONE;
+ case XML_TOK_ENTITY_REF:
+ case XML_TOK_DATA_CHARS:
+ if (!poolAppend(pool, enc, entityTextPtr, next))
+ return XML_ERROR_NO_MEMORY;
+ break;
+ case XML_TOK_TRAILING_CR:
+ next = entityTextPtr + enc->minBytesPerChar;
+ /* fall through */
+ case XML_TOK_DATA_NEWLINE:
+ if (pool->end == pool->ptr && !poolGrow(pool))
+ return XML_ERROR_NO_MEMORY;
+ *(pool->ptr)++ = 0xA;
+ break;
+ case XML_TOK_CHAR_REF:
+ {
+ XML_Char buf[XML_ENCODE_MAX];
+ int i;
+ int n = XmlCharRefNumber(enc, entityTextPtr);
+ if (n < 0) {
+ if (enc == encoding)
+ eventPtr = entityTextPtr;
+ return XML_ERROR_BAD_CHAR_REF;
+ }
+ n = XmlEncode(n, (ICHAR *)buf);
+ if (!n) {
+ if (enc == encoding)
+ eventPtr = entityTextPtr;
+ return XML_ERROR_BAD_CHAR_REF;
+ }
+ for (i = 0; i < n; i++) {
+ if (pool->end == pool->ptr && !poolGrow(pool))
+ return XML_ERROR_NO_MEMORY;
+ *(pool->ptr)++ = buf[i];
+ }
+ }
+ break;
+ case XML_TOK_PARTIAL:
+ if (enc == encoding)
+ eventPtr = entityTextPtr;
+ return XML_ERROR_INVALID_TOKEN;
+ case XML_TOK_INVALID:
+ if (enc == encoding)
+ eventPtr = next;
+ return XML_ERROR_INVALID_TOKEN;
+ default:
+ if (enc == encoding)
+ eventPtr = entityTextPtr;
+ return XML_ERROR_UNEXPECTED_STATE;
+ }
+ entityTextPtr = next;
+ }
+ /* not reached */
+}
+
+static void
+normalizeLines(XML_Char *s)
+{
+ XML_Char *p;
+ for (;; s++) {
+ if (*s == XML_T('\0'))
+ return;
+ if (*s == 0xD)
+ break;
+ }
+ p = s;
+ do {
+ if (*s == 0xD) {
+ *p++ = 0xA;
+ if (*++s == 0xA)
+ s++;
+ }
+ else
+ *p++ = *s++;
+ } while (*s);
+ *p = XML_T('\0');
+}
+
+static int
+reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, const char *start, const char *end)
+{
+ const XML_Char *target;
+ XML_Char *data;
+ const char *tem;
+ if (!processingInstructionHandler) {
+ if (defaultHandler)
+ reportDefault(parser, enc, start, end);
+ return 1;
+ }
+ start += enc->minBytesPerChar * 2;
+ tem = start + XmlNameLength(enc, start);
+ target = poolStoreString(&tempPool, enc, start, tem);
+ if (!target)
+ return 0;
+ poolFinish(&tempPool);
+ data = poolStoreString(&tempPool, enc,
+ XmlSkipS(enc, tem),
+ end - enc->minBytesPerChar*2);
+ if (!data)
+ return 0;
+ normalizeLines(data);
+ processingInstructionHandler(handlerArg, target, data);
+ poolClear(&tempPool);
+ return 1;
+}
+
+static int
+reportComment(XML_Parser parser, const ENCODING *enc, const char *start, const char *end)
+{
+ XML_Char *data;
+ if (!commentHandler) {
+ if (defaultHandler)
+ reportDefault(parser, enc, start, end);
+ return 1;
+ }
+ data = poolStoreString(&tempPool,
+ enc,
+ start + enc->minBytesPerChar * 4,
+ end - enc->minBytesPerChar * 3);
+ if (!data)
+ return 0;
+ normalizeLines(data);
+ commentHandler(handlerArg, data);
+ poolClear(&tempPool);
+ return 1;
+}
+
+static void
+reportDefault(XML_Parser parser, const ENCODING *enc, const char *s, const char *end)
+{
+ if (MUST_CONVERT(enc, s)) {
+ const char **eventPP;
+ const char **eventEndPP;
+ if (enc == encoding) {
+ eventPP = &eventPtr;
+ eventEndPP = &eventEndPtr;
+ }
+ else {
+ eventPP = &(openInternalEntities->internalEventPtr);
+ eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ }
+ do {
+ ICHAR *dataPtr = (ICHAR *)dataBuf;
+ XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
+ *eventEndPP = s;
+ defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
+ *eventPP = s;
+ } while (s != end);
+ }
+ else
+ defaultHandler(handlerArg, (XML_Char *)s, (XML_Char *)end - (XML_Char *)s);
+}
+
+
+static int
+defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, int isCdata,
+ int isId, const XML_Char *value, XML_Parser parser)
+{
+ DEFAULT_ATTRIBUTE *att;
+ if (value || isId) {
+ /* The handling of default attributes gets messed up if we have
+ a default which duplicates a non-default. */
+ int i;
+ for (i = 0; i < type->nDefaultAtts; i++)
+ if (attId == type->defaultAtts[i].id)
+ return 1;
+ if (isId && !type->idAtt && !attId->xmlns)
+ type->idAtt = attId;
+ }
+ if (type->nDefaultAtts == type->allocDefaultAtts) {
+ if (type->allocDefaultAtts == 0) {
+ type->allocDefaultAtts = 8;
+ type->defaultAtts = MALLOC(type->allocDefaultAtts*sizeof(DEFAULT_ATTRIBUTE));
+ }
+ else {
+ type->allocDefaultAtts *= 2;
+ type->defaultAtts = REALLOC(type->defaultAtts,
+ type->allocDefaultAtts*sizeof(DEFAULT_ATTRIBUTE));
+ }
+ if (!type->defaultAtts)
+ return 0;
+ }
+ att = type->defaultAtts + type->nDefaultAtts;
+ att->id = attId;
+ att->value = value;
+ att->isCdata = isCdata;
+ if (!isCdata)
+ attId->maybeTokenized = 1;
+ type->nDefaultAtts += 1;
+ return 1;
+}
+
+static int setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType)
+{
+ const XML_Char *name;
+ for (name = elementType->name; *name; name++) {
+ if (*name == XML_T(':')) {
+ PREFIX *prefix;
+ const XML_Char *s;
+ for (s = elementType->name; s != name; s++) {
+ if (!poolAppendChar(&dtd.pool, *s))
+ return 0;
+ }
+ if (!poolAppendChar(&dtd.pool, XML_T('\0')))
+ return 0;
+ prefix = (PREFIX *)lookup(&dtd.prefixes, poolStart(&dtd.pool), sizeof(PREFIX));
+ if (!prefix)
+ return 0;
+ if (prefix->name == poolStart(&dtd.pool))
+ poolFinish(&dtd.pool);
+ else
+ poolDiscard(&dtd.pool);
+ elementType->prefix = prefix;
+
+ }
+ }
+ return 1;
+}
+
+static ATTRIBUTE_ID *
+getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, const char *end)
+{
+ ATTRIBUTE_ID *id;
+ const XML_Char *name;
+ if (!poolAppendChar(&dtd.pool, XML_T('\0')))
+ return 0;
+ name = poolStoreString(&dtd.pool, enc, start, end);
+ if (!name)
+ return 0;
+ ++name;
+ id = (ATTRIBUTE_ID *)lookup(&dtd.attributeIds, name, sizeof(ATTRIBUTE_ID));
+ if (!id)
+ return 0;
+ if (id->name != name)
+ poolDiscard(&dtd.pool);
+ else {
+ poolFinish(&dtd.pool);
+ if (!ns)
+ ;
+ else if (name[0] == 'x'
+ && name[1] == 'm'
+ && name[2] == 'l'
+ && name[3] == 'n'
+ && name[4] == 's'
+ && (name[5] == XML_T('\0') || name[5] == XML_T(':'))) {
+ if (name[5] == '\0')
+ id->prefix = &dtd.defaultPrefix;
+ else
+ id->prefix = (PREFIX *)lookup(&dtd.prefixes, name + 6, sizeof(PREFIX));
+ id->xmlns = 1;
+ }
+ else {
+ int i;
+ for (i = 0; name[i]; i++) {
+ if (name[i] == XML_T(':')) {
+ int j;
+ for (j = 0; j < i; j++) {
+ if (!poolAppendChar(&dtd.pool, name[j]))
+ return 0;
+ }
+ if (!poolAppendChar(&dtd.pool, XML_T('\0')))
+ return 0;
+ id->prefix = (PREFIX *)lookup(&dtd.prefixes, poolStart(&dtd.pool), sizeof(PREFIX));
+ if (id->prefix->name == poolStart(&dtd.pool))
+ poolFinish(&dtd.pool);
+ else
+ poolDiscard(&dtd.pool);
+ break;
+ }
+ }
+ }
+ }
+ return id;
+}
+
+#define CONTEXT_SEP XML_T('\f')
+
+static
+const XML_Char *getContext(XML_Parser parser)
+{
+ HASH_TABLE_ITER iter;
+ int needSep = 0;
+
+ if (dtd.defaultPrefix.binding) {
+ int i;
+ int len;
+ if (!poolAppendChar(&tempPool, XML_T('=')))
+ return 0;
+ len = dtd.defaultPrefix.binding->uriLen;
+ if (namespaceSeparator != XML_T('\0'))
+ len--;
+ for (i = 0; i < len; i++)
+ if (!poolAppendChar(&tempPool, dtd.defaultPrefix.binding->uri[i]))
+ return 0;
+ needSep = 1;
+ }
+
+ hashTableIterInit(&iter, &(dtd.prefixes));
+ for (;;) {
+ int i;
+ int len;
+ const XML_Char *s;
+ PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter);
+ if (!prefix)
+ break;
+ if (!prefix->binding)
+ continue;
+ if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP))
+ return 0;
+ for (s = prefix->name; *s; s++)
+ if (!poolAppendChar(&tempPool, *s))
+ return 0;
+ if (!poolAppendChar(&tempPool, XML_T('=')))
+ return 0;
+ len = prefix->binding->uriLen;
+ if (namespaceSeparator != XML_T('\0'))
+ len--;
+ for (i = 0; i < len; i++)
+ if (!poolAppendChar(&tempPool, prefix->binding->uri[i]))
+ return 0;
+ needSep = 1;
+ }
+
+
+ hashTableIterInit(&iter, &(dtd.generalEntities));
+ for (;;) {
+ const XML_Char *s;
+ ENTITY *e = (ENTITY *)hashTableIterNext(&iter);
+ if (!e)
+ break;
+ if (!e->open)
+ continue;
+ if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP))
+ return 0;
+ for (s = e->name; *s; s++)
+ if (!poolAppendChar(&tempPool, *s))
+ return 0;
+ needSep = 1;
+ }
+
+ if (!poolAppendChar(&tempPool, XML_T('\0')))
+ return 0;
+ return tempPool.start;
+}
+
+static
+int setContext(XML_Parser parser, const XML_Char *context)
+{
+ const XML_Char *s = context;
+
+ while (*context != XML_T('\0')) {
+ if (*s == CONTEXT_SEP || *s == XML_T('\0')) {
+ ENTITY *e;
+ if (!poolAppendChar(&tempPool, XML_T('\0')))
+ return 0;
+ e = (ENTITY *)lookup(&dtd.generalEntities, poolStart(&tempPool), 0);
+ if (e)
+ e->open = 1;
+ if (*s != XML_T('\0'))
+ s++;
+ context = s;
+ poolDiscard(&tempPool);
+ }
+ else if (*s == '=') {
+ PREFIX *prefix;
+ if (poolLength(&tempPool) == 0)
+ prefix = &dtd.defaultPrefix;
+ else {
+ if (!poolAppendChar(&tempPool, XML_T('\0')))
+ return 0;
+ prefix = (PREFIX *)lookup(&dtd.prefixes, poolStart(&tempPool), sizeof(PREFIX));
+ if (!prefix)
+ return 0;
+ if (prefix->name == poolStart(&tempPool)) {
+ prefix->name = poolCopyString(&dtd.pool, prefix->name);
+ if (!prefix->name)
+ return 0;
+ }
+ poolDiscard(&tempPool);
+ }
+ for (context = s + 1; *context != CONTEXT_SEP && *context != XML_T('\0'); context++)
+ if (!poolAppendChar(&tempPool, *context))
+ return 0;
+ if (!poolAppendChar(&tempPool, XML_T('\0')))
+ return 0;
+ if (!addBinding(parser, prefix, 0, poolStart(&tempPool), &inheritedBindings))
+ return 0;
+ poolDiscard(&tempPool);
+ if (*context != XML_T('\0'))
+ ++context;
+ s = context;
+ }
+ else {
+ if (!poolAppendChar(&tempPool, *s))
+ return 0;
+ s++;
+ }
+ }
+ return 1;
+}
+
+
+static
+void normalizePublicId(XML_Char *publicId)
+{
+ XML_Char *p = publicId;
+ XML_Char *s;
+ for (s = publicId; *s; s++) {
+ switch (*s) {
+ case 0x20:
+ case 0xD:
+ case 0xA:
+ if (p != publicId && p[-1] != 0x20)
+ *p++ = 0x20;
+ break;
+ default:
+ *p++ = *s;
+ }
+ }
+ if (p != publicId && p[-1] == 0x20)
+ --p;
+ *p = XML_T('\0');
+}
+
+static int dtdInit(DTD *p, XML_Parser parser)
+{
+ XML_Memory_Handling_Suite *ms = &((Parser *) parser)->m_mem;
+ poolInit(&(p->pool), ms);
+ hashTableInit(&(p->generalEntities), ms);
+ hashTableInit(&(p->elementTypes), ms);
+ hashTableInit(&(p->attributeIds), ms);
+ hashTableInit(&(p->prefixes), ms);
+ p->complete = 1;
+ p->standalone = 0;
+#ifdef XML_DTD
+ hashTableInit(&(p->paramEntities), ms);
+#endif /* XML_DTD */
+ p->defaultPrefix.name = 0;
+ p->defaultPrefix.binding = 0;
+
+ p->in_eldecl = 0;
+ p->scaffIndex = 0;
+ p->scaffLevel = 0;
+ p->scaffold = 0;
+ p->contentStringLen = 0;
+ p->scaffSize = 0;
+ p->scaffCount = 0;
+
+ return 1;
+}
+
+#ifdef XML_DTD
+
+static void dtdSwap(DTD *p1, DTD *p2)
+{
+ DTD tem;
+ memcpy(&tem, p1, sizeof(DTD));
+ memcpy(p1, p2, sizeof(DTD));
+ memcpy(p2, &tem, sizeof(DTD));
+}
+
+#endif /* XML_DTD */
+
+static void dtdDestroy(DTD *p, XML_Parser parser)
+{
+ HASH_TABLE_ITER iter;
+ hashTableIterInit(&iter, &(p->elementTypes));
+ for (;;) {
+ ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter);
+ if (!e)
+ break;
+ if (e->allocDefaultAtts != 0)
+ FREE(e->defaultAtts);
+ }
+ hashTableDestroy(&(p->generalEntities));
+#ifdef XML_DTD
+ hashTableDestroy(&(p->paramEntities));
+#endif /* XML_DTD */
+ hashTableDestroy(&(p->elementTypes));
+ hashTableDestroy(&(p->attributeIds));
+ hashTableDestroy(&(p->prefixes));
+ poolDestroy(&(p->pool));
+ if (p->scaffIndex)
+ FREE(p->scaffIndex);
+ if (p->scaffold)
+ FREE(p->scaffold);
+}
+
+/* Do a deep copy of the DTD. Return 0 for out of memory; non-zero otherwise.
+The new DTD has already been initialized. */
+
+static int dtdCopy(DTD *newDtd, const DTD *oldDtd, XML_Parser parser)
+{
+ HASH_TABLE_ITER iter;
+
+ /* Copy the prefix table. */
+
+ hashTableIterInit(&iter, &(oldDtd->prefixes));
+ for (;;) {
+ const XML_Char *name;
+ const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter);
+ if (!oldP)
+ break;
+ name = poolCopyString(&(newDtd->pool), oldP->name);
+ if (!name)
+ return 0;
+ if (!lookup(&(newDtd->prefixes), name, sizeof(PREFIX)))
+ return 0;
+ }
+
+ hashTableIterInit(&iter, &(oldDtd->attributeIds));
+
+ /* Copy the attribute id table. */
+
+ for (;;) {
+ ATTRIBUTE_ID *newA;
+ const XML_Char *name;
+ const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter);
+
+ if (!oldA)
+ break;
+ /* Remember to allocate the scratch byte before the name. */
+ if (!poolAppendChar(&(newDtd->pool), XML_T('\0')))
+ return 0;
+ name = poolCopyString(&(newDtd->pool), oldA->name);
+ if (!name)
+ return 0;
+ ++name;
+ newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name, sizeof(ATTRIBUTE_ID));
+ if (!newA)
+ return 0;
+ newA->maybeTokenized = oldA->maybeTokenized;
+ if (oldA->prefix) {
+ newA->xmlns = oldA->xmlns;
+ if (oldA->prefix == &oldDtd->defaultPrefix)
+ newA->prefix = &newDtd->defaultPrefix;
+ else
+ newA->prefix = (PREFIX *)lookup(&(newDtd->prefixes), oldA->prefix->name, 0);
+ }
+ }
+
+ /* Copy the element type table. */
+
+ hashTableIterInit(&iter, &(oldDtd->elementTypes));
+
+ for (;;) {
+ int i;
+ ELEMENT_TYPE *newE;
+ const XML_Char *name;
+ const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter);
+ if (!oldE)
+ break;
+ name = poolCopyString(&(newDtd->pool), oldE->name);
+ if (!name)
+ return 0;
+ newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, sizeof(ELEMENT_TYPE));
+ if (!newE)
+ return 0;
+ if (oldE->nDefaultAtts) {
+ newE->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
+ if (!newE->defaultAtts)
+ return 0;
+ }
+ if (oldE->idAtt)
+ newE->idAtt = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0);
+ newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts;
+ if (oldE->prefix)
+ newE->prefix = (PREFIX *)lookup(&(newDtd->prefixes), oldE->prefix->name, 0);
+ for (i = 0; i < newE->nDefaultAtts; i++) {
+ newE->defaultAtts[i].id = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0);
+ newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata;
+ if (oldE->defaultAtts[i].value) {
+ newE->defaultAtts[i].value = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value);
+ if (!newE->defaultAtts[i].value)
+ return 0;
+ }
+ else
+ newE->defaultAtts[i].value = 0;
+ }
+ }
+
+ /* Copy the entity tables. */
+ if (!copyEntityTable(&(newDtd->generalEntities),
+ &(newDtd->pool),
+ &(oldDtd->generalEntities), parser))
+ return 0;
+
+#ifdef XML_DTD
+ if (!copyEntityTable(&(newDtd->paramEntities),
+ &(newDtd->pool),
+ &(oldDtd->paramEntities), parser))
+ return 0;
+#endif /* XML_DTD */
+
+ newDtd->complete = oldDtd->complete;
+ newDtd->standalone = oldDtd->standalone;
+
+ /* Don't want deep copying for scaffolding */
+ newDtd->in_eldecl = oldDtd->in_eldecl;
+ newDtd->scaffold = oldDtd->scaffold;
+ newDtd->contentStringLen = oldDtd->contentStringLen;
+ newDtd->scaffSize = oldDtd->scaffSize;
+ newDtd->scaffLevel = oldDtd->scaffLevel;
+ newDtd->scaffIndex = oldDtd->scaffIndex;
+
+ return 1;
+} /* End dtdCopy */
+
+static int copyEntityTable(HASH_TABLE *newTable,
+ STRING_POOL *newPool,
+ const HASH_TABLE *oldTable,
+ XML_Parser parser)
+{
+ HASH_TABLE_ITER iter;
+ const XML_Char *cachedOldBase = 0;
+ const XML_Char *cachedNewBase = 0;
+ cmExpatUnused(parser);
+
+ hashTableIterInit(&iter, oldTable);
+
+ for (;;) {
+ ENTITY *newE;
+ const XML_Char *name;
+ const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter);
+ if (!oldE)
+ break;
+ name = poolCopyString(newPool, oldE->name);
+ if (!name)
+ return 0;
+ newE = (ENTITY *)lookup(newTable, name, sizeof(ENTITY));
+ if (!newE)
+ return 0;
+ if (oldE->systemId) {
+ const XML_Char *tem = poolCopyString(newPool, oldE->systemId);
+ if (!tem)
+ return 0;
+ newE->systemId = tem;
+ if (oldE->base) {
+ if (oldE->base == cachedOldBase)
+ newE->base = cachedNewBase;
+ else {
+ cachedOldBase = oldE->base;
+ tem = poolCopyString(newPool, cachedOldBase);
+ if (!tem)
+ return 0;
+ cachedNewBase = newE->base = tem;
+ }
+ }
+ }
+ else {
+ const XML_Char *tem = poolCopyStringN(newPool, oldE->textPtr, oldE->textLen);
+ if (!tem)
+ return 0;
+ newE->textPtr = tem;
+ newE->textLen = oldE->textLen;
+ }
+ if (oldE->notation) {
+ const XML_Char *tem = poolCopyString(newPool, oldE->notation);
+ if (!tem)
+ return 0;
+ newE->notation = tem;
+ }
+ }
+ return 1;
+}
+
+#define INIT_SIZE 64
+
+static
+int keyeq(KEY s1, KEY s2)
+{
+ for (; *s1 == *s2; s1++, s2++)
+ if (*s1 == 0)
+ return 1;
+ return 0;
+}
+
+static
+unsigned long hash(KEY s)
+{
+ unsigned long h = 0;
+ while (*s)
+ h = (h << 5) + h + (unsigned char)*s++;
+ return h;
+}
+
+static
+NAMED *lookup(HASH_TABLE *table, KEY name, size_t createSize)
+{
+ size_t i;
+ if (table->size == 0) {
+ size_t tsize;
+
+ if (!createSize)
+ return 0;
+ tsize = INIT_SIZE * sizeof(NAMED *);
+ table->v = table->mem->malloc_fcn(tsize);
+ if (!table->v)
+ return 0;
+ memset(table->v, 0, tsize);
+ table->size = INIT_SIZE;
+ table->usedLim = INIT_SIZE / 2;
+ i = hash(name) & (table->size - 1);
+ }
+ else {
+ unsigned long h = hash(name);
+ for (i = h & (table->size - 1);
+ table->v[i];
+ i == 0 ? i = table->size - 1 : --i) {
+ if (keyeq(name, table->v[i]->name))
+ return table->v[i];
+ }
+ if (!createSize)
+ return 0;
+ if (table->used == table->usedLim) {
+ /* check for overflow */
+ size_t newSize = table->size * 2;
+ size_t tsize = newSize * sizeof(NAMED *);
+ NAMED **newV = table->mem->malloc_fcn(tsize);
+ if (!newV)
+ return 0;
+ memset(newV, 0, tsize);
+ for (i = 0; i < table->size; i++)
+ if (table->v[i]) {
+ size_t j;
+ for (j = hash(table->v[i]->name) & (newSize - 1);
+ newV[j];
+ j == 0 ? j = newSize - 1 : --j)
+ ;
+ newV[j] = table->v[i];
+ }
+ table->mem->free_fcn(table->v);
+ table->v = newV;
+ table->size = newSize;
+ table->usedLim = newSize/2;
+ for (i = h & (table->size - 1);
+ table->v[i];
+ i == 0 ? i = table->size - 1 : --i)
+ ;
+ }
+ }
+ table->v[i] = table->mem->malloc_fcn(createSize);
+ if (!table->v[i])
+ return 0;
+ memset(table->v[i], 0, createSize);
+ table->v[i]->name = name;
+ (table->used)++;
+ return table->v[i];
+}
+
+static
+void hashTableDestroy(HASH_TABLE *table)
+{
+ size_t i;
+ for (i = 0; i < table->size; i++) {
+ NAMED *p = table->v[i];
+ if (p)
+ table->mem->free_fcn(p);
+ }
+ if (table->v)
+ table->mem->free_fcn(table->v);
+}
+
+static
+void hashTableInit(HASH_TABLE *p, XML_Memory_Handling_Suite *ms)
+{
+ p->size = 0;
+ p->usedLim = 0;
+ p->used = 0;
+ p->v = 0;
+ p->mem = ms;
+}
+
+static
+void hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table)
+{
+ iter->p = table->v;
+ iter->end = iter->p + table->size;
+}
+
+static
+NAMED *hashTableIterNext(HASH_TABLE_ITER *iter)
+{
+ while (iter->p != iter->end) {
+ NAMED *tem = *(iter->p)++;
+ if (tem)
+ return tem;
+ }
+ return 0;
+}
+
+
+static
+void poolInit(STRING_POOL *pool, XML_Memory_Handling_Suite *ms)
+{
+ pool->blocks = 0;
+ pool->freeBlocks = 0;
+ pool->start = 0;
+ pool->ptr = 0;
+ pool->end = 0;
+ pool->mem = ms;
+}
+
+static
+void poolClear(STRING_POOL *pool)
+{
+ if (!pool->freeBlocks)
+ pool->freeBlocks = pool->blocks;
+ else {
+ BLOCK *p = pool->blocks;
+ while (p) {
+ BLOCK *tem = p->next;
+ p->next = pool->freeBlocks;
+ pool->freeBlocks = p;
+ p = tem;
+ }
+ }
+ pool->blocks = 0;
+ pool->start = 0;
+ pool->ptr = 0;
+ pool->end = 0;
+}
+
+static
+void poolDestroy(STRING_POOL *pool)
+{
+ BLOCK *p = pool->blocks;
+ while (p) {
+ BLOCK *tem = p->next;
+ pool->mem->free_fcn(p);
+ p = tem;
+ }
+ pool->blocks = 0;
+ p = pool->freeBlocks;
+ while (p) {
+ BLOCK *tem = p->next;
+ pool->mem->free_fcn(p);
+ p = tem;
+ }
+ pool->freeBlocks = 0;
+ pool->ptr = 0;
+ pool->start = 0;
+ pool->end = 0;
+}
+
+static
+XML_Char *poolAppend(STRING_POOL *pool, const ENCODING *enc,
+ const char *ptr, const char *end)
+{
+ if (!pool->ptr && !poolGrow(pool))
+ return 0;
+ for (;;) {
+ XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end);
+ if (ptr == end)
+ break;
+ if (!poolGrow(pool))
+ return 0;
+ }
+ return pool->start;
+}
+
+static const XML_Char *poolCopyString(STRING_POOL *pool, const XML_Char *s)
+{
+ do {
+ if (!poolAppendChar(pool, *s))
+ return 0;
+ } while (*s++);
+ s = pool->start;
+ poolFinish(pool);
+ return s;
+}
+
+static const XML_Char *poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n)
+{
+ if (!pool->ptr && !poolGrow(pool))
+ return 0;
+ for (; n > 0; --n, s++) {
+ if (!poolAppendChar(pool, *s))
+ return 0;
+
+ }
+ s = pool->start;
+ poolFinish(pool);
+ return s;
+}
+
+static
+const XML_Char *poolAppendString(STRING_POOL *pool, const XML_Char *s)
+{
+ while (*s) {
+ if (!poolAppendChar(pool, *s))
+ return 0;
+ s++;
+ }
+ return pool->start;
+} /* End poolAppendString */
+
+static
+XML_Char *poolStoreString(STRING_POOL *pool, const ENCODING *enc,
+ const char *ptr, const char *end)
+{
+ if (!poolAppend(pool, enc, ptr, end))
+ return 0;
+ if (pool->ptr == pool->end && !poolGrow(pool))
+ return 0;
+ *(pool->ptr)++ = 0;
+ return pool->start;
+}
+
+static
+int poolGrow(STRING_POOL *pool)
+{
+ if (pool->freeBlocks) {
+ if (pool->start == 0) {
+ pool->blocks = pool->freeBlocks;
+ pool->freeBlocks = pool->freeBlocks->next;
+ pool->blocks->next = 0;
+ pool->start = pool->blocks->s;
+ pool->end = pool->start + pool->blocks->size;
+ pool->ptr = pool->start;
+ return 1;
+ }
+ if (pool->end - pool->start < pool->freeBlocks->size) {
+ BLOCK *tem = pool->freeBlocks->next;
+ pool->freeBlocks->next = pool->blocks;
+ pool->blocks = pool->freeBlocks;
+ pool->freeBlocks = tem;
+ memcpy(pool->blocks->s, pool->start, (pool->end - pool->start) * sizeof(XML_Char));
+ pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
+ pool->start = pool->blocks->s;
+ pool->end = pool->start + pool->blocks->size;
+ return 1;
+ }
+ }
+ if (pool->blocks && pool->start == pool->blocks->s) {
+ int blockSize = (pool->end - pool->start)*2;
+ pool->blocks = pool->mem->realloc_fcn(pool->blocks, offsetof(BLOCK, s) + blockSize * sizeof(XML_Char));
+ if (!pool->blocks)
+ return 0;
+ pool->blocks->size = blockSize;
+ pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
+ pool->start = pool->blocks->s;
+ pool->end = pool->start + blockSize;
+ }
+ else {
+ BLOCK *tem;
+ int blockSize = pool->end - pool->start;
+ if (blockSize < INIT_BLOCK_SIZE)
+ blockSize = INIT_BLOCK_SIZE;
+ else
+ blockSize *= 2;
+ tem = pool->mem->malloc_fcn(offsetof(BLOCK, s) + blockSize * sizeof(XML_Char));
+ if (!tem)
+ return 0;
+ tem->size = blockSize;
+ tem->next = pool->blocks;
+ pool->blocks = tem;
+ if (pool->ptr != pool->start)
+ memcpy(tem->s, pool->start, (pool->ptr - pool->start) * sizeof(XML_Char));
+ pool->ptr = tem->s + (pool->ptr - pool->start);
+ pool->start = tem->s;
+ pool->end = tem->s + blockSize;
+ }
+ return 1;
+}
+
+static int
+nextScaffoldPart(XML_Parser parser)
+{
+ CONTENT_SCAFFOLD * me;
+ int next;
+
+ if (! dtd.scaffIndex) {
+ dtd.scaffIndex = MALLOC(groupSize * sizeof(int));
+ if (! dtd.scaffIndex)
+ return -1;
+ dtd.scaffIndex[0] = 0;
+ }
+
+ if (dtd.scaffCount >= dtd.scaffSize) {
+ if (dtd.scaffold) {
+ dtd.scaffSize *= 2;
+ dtd.scaffold = (CONTENT_SCAFFOLD *) REALLOC(dtd.scaffold,
+ dtd.scaffSize * sizeof(CONTENT_SCAFFOLD));
+ }
+ else {
+ dtd.scaffSize = 32;
+ dtd.scaffold = (CONTENT_SCAFFOLD *) MALLOC(dtd.scaffSize * sizeof(CONTENT_SCAFFOLD));
+ }
+ if (! dtd.scaffold)
+ return -1;
+ }
+ next = dtd.scaffCount++;
+ me = &dtd.scaffold[next];
+ if (dtd.scaffLevel) {
+ CONTENT_SCAFFOLD *parent = &dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel - 1]];
+ if (parent->lastchild) {
+ dtd.scaffold[parent->lastchild].nextsib = next;
+ }
+ if (! parent->childcnt)
+ parent->firstchild = next;
+ parent->lastchild = next;
+ parent->childcnt++;
+ }
+ me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0;
+ return next;
+} /* End nextScaffoldPart */
+
+static void
+build_node (XML_Parser parser,
+ int src_node,
+ XML_Content *dest,
+ XML_Content **contpos,
+ char **strpos)
+{
+ dest->type = dtd.scaffold[src_node].type;
+ dest->quant = dtd.scaffold[src_node].quant;
+ if (dest->type == XML_CTYPE_NAME) {
+ const char *src;
+ dest->name = *strpos;
+ src = dtd.scaffold[src_node].name;
+ for (;;) {
+ *(*strpos)++ = *src;
+ if (! *src)
+ break;
+ src++;
+ }
+ dest->numchildren = 0;
+ dest->children = 0;
+ }
+ else {
+ unsigned int i;
+ int cn;
+ dest->numchildren = dtd.scaffold[src_node].childcnt;
+ dest->children = *contpos;
+ *contpos += dest->numchildren;
+ for (i = 0, cn = dtd.scaffold[src_node].firstchild;
+ i < dest->numchildren;
+ i++, cn = dtd.scaffold[cn].nextsib) {
+ build_node(parser, cn, &(dest->children[i]), contpos, strpos);
+ }
+ dest->name = 0;
+ }
+} /* End build_node */
+
+static XML_Content *
+build_model (XML_Parser parser)
+{
+ XML_Content *ret;
+ XML_Content *cpos;
+ char * str;
+ int allocsize = dtd.scaffCount * sizeof(XML_Content) + dtd.contentStringLen;
+
+ ret = MALLOC(allocsize);
+ if (! ret)
+ return 0;
+
+ str = (char *) (&ret[dtd.scaffCount]);
+ cpos = &ret[1];
+
+ build_node(parser, 0, ret, &cpos, &str);
+ return ret;
+} /* End build_model */
+
+static ELEMENT_TYPE *
+getElementType(XML_Parser parser,
+ const ENCODING *enc,
+ const char *ptr,
+ const char *end)
+{
+ const XML_Char *name = poolStoreString(&dtd.pool, enc, ptr, end);
+ ELEMENT_TYPE *ret;
+
+ if (! name)
+ return 0;
+ ret = (ELEMENT_TYPE *) lookup(&dtd.elementTypes, name, sizeof(ELEMENT_TYPE));
+ if (! ret)
+ return 0;
+ if (ret->name != name)
+ poolDiscard(&dtd.pool);
+ else {
+ poolFinish(&dtd.pool);
+ if (!setElementTypePrefix(parser, ret))
+ return 0;
+ }
+ return ret;
+} /* End getElementType */
diff --git a/Utilities/cmexpat/xmlrole.c b/Utilities/cmexpat/xmlrole.c
new file mode 100644
index 0000000000..289964ca58
--- /dev/null
+++ b/Utilities/cmexpat/xmlrole.c
@@ -0,0 +1,1401 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+static char RCSId[]
+ = "$Header$";
+const char* cm_expat_GetXMLRole_RCSId()
+{
+ /* Avoid warning about unused static without removing RCSId from original. */
+ return RCSId;
+}
+
+#include <cmexpat/expatConfig.h>
+
+#include "xmlrole.h"
+#include "ascii.h"
+
+/* Doesn't check:
+
+ that ,| are not mixed in a model group
+ content of literals
+
+*/
+
+static const char KW_ANY[] = { ASCII_A, ASCII_N, ASCII_Y, '\0' };
+static const char KW_ATTLIST[] = { ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' };
+static const char KW_CDATA[] = { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
+static const char KW_DOCTYPE[] = { ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' };
+static const char KW_ELEMENT[] = { ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' };
+static const char KW_EMPTY[] = { ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' };
+static const char KW_ENTITIES[] = { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' };
+static const char KW_ENTITY[] = { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' };
+static const char KW_FIXED[] = { ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' };
+static const char KW_ID[] = { ASCII_I, ASCII_D, '\0' };
+static const char KW_IDREF[] = { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' };
+static const char KW_IDREFS[] = { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' };
+static const char KW_IGNORE[] = { ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' };
+static const char KW_IMPLIED[] = { ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' };
+static const char KW_INCLUDE[] = { ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' };
+static const char KW_NDATA[] = { ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
+static const char KW_NMTOKEN[] = { ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' };
+static const char KW_NMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' };
+static const char KW_NOTATION[] = { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, '\0' };
+static const char KW_PCDATA[] = { ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
+static const char KW_PUBLIC[] = { ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' };
+static const char KW_REQUIRED[] = { ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D, '\0' };
+static const char KW_SYSTEM[] = { ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' };
+
+#ifndef MIN_BYTES_PER_CHAR
+#define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
+#endif
+
+#ifdef XML_DTD
+#define setTopLevel(state) \
+ ((state)->handler = ((state)->documentEntity \
+ ? internalSubset \
+ : externalSubset1))
+#else /* not XML_DTD */
+#define setTopLevel(state) ((state)->handler = internalSubset)
+#endif /* not XML_DTD */
+
+typedef int PROLOG_HANDLER(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc);
+
+static PROLOG_HANDLER
+ prolog0, prolog1, prolog2,
+ doctype0, doctype1, doctype2, doctype3, doctype4, doctype5,
+ internalSubset,
+ entity0, entity1, entity2, entity3, entity4, entity5, entity6,
+ entity7, entity8, entity9,
+ notation0, notation1, notation2, notation3, notation4,
+ attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6,
+ attlist7, attlist8, attlist9,
+ element0, element1, element2, element3, element4, element5, element6,
+ element7,
+#ifdef XML_DTD
+ externalSubset0, externalSubset1,
+ condSect0, condSect1, condSect2,
+#endif /* XML_DTD */
+ declClose,
+ error;
+
+static
+int common(PROLOG_STATE *state, int tok);
+
+static
+int prolog0(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ state->handler = prolog1;
+ return XML_ROLE_NONE;
+ case XML_TOK_XML_DECL:
+ state->handler = prolog1;
+ return XML_ROLE_XML_DECL;
+ case XML_TOK_PI:
+ state->handler = prolog1;
+ return XML_ROLE_NONE;
+ case XML_TOK_COMMENT:
+ state->handler = prolog1;
+ case XML_TOK_BOM:
+ return XML_ROLE_NONE;
+ case XML_TOK_DECL_OPEN:
+ if (!XmlNameMatchesAscii(enc,
+ ptr + 2 * MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_DOCTYPE))
+ break;
+ state->handler = doctype0;
+ return XML_ROLE_NONE;
+ case XML_TOK_INSTANCE_START:
+ state->handler = error;
+ return XML_ROLE_INSTANCE_START;
+ }
+ return common(state, tok);
+}
+
+static
+int prolog1(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_PI:
+ case XML_TOK_COMMENT:
+ case XML_TOK_BOM:
+ return XML_ROLE_NONE;
+ case XML_TOK_DECL_OPEN:
+ if (!XmlNameMatchesAscii(enc,
+ ptr + 2 * MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_DOCTYPE))
+ break;
+ state->handler = doctype0;
+ return XML_ROLE_NONE;
+ case XML_TOK_INSTANCE_START:
+ state->handler = error;
+ return XML_ROLE_INSTANCE_START;
+ }
+ return common(state, tok);
+}
+
+static
+int prolog2(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_PI:
+ case XML_TOK_COMMENT:
+ return XML_ROLE_NONE;
+ case XML_TOK_INSTANCE_START:
+ state->handler = error;
+ return XML_ROLE_INSTANCE_START;
+ }
+ return common(state, tok);
+}
+
+static
+int doctype0(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ case XML_TOK_PREFIXED_NAME:
+ state->handler = doctype1;
+ return XML_ROLE_DOCTYPE_NAME;
+ }
+ return common(state, tok);
+}
+
+static
+int doctype1(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_OPEN_BRACKET:
+ state->handler = internalSubset;
+ return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
+ case XML_TOK_DECL_CLOSE:
+ state->handler = prolog2;
+ return XML_ROLE_DOCTYPE_CLOSE;
+ case XML_TOK_NAME:
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
+ state->handler = doctype3;
+ return XML_ROLE_NONE;
+ }
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
+ state->handler = doctype2;
+ return XML_ROLE_NONE;
+ }
+ break;
+ }
+ return common(state, tok);
+}
+
+static
+int doctype2(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = doctype3;
+ return XML_ROLE_DOCTYPE_PUBLIC_ID;
+ }
+ return common(state, tok);
+}
+
+static
+int doctype3(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = doctype4;
+ return XML_ROLE_DOCTYPE_SYSTEM_ID;
+ }
+ return common(state, tok);
+}
+
+static
+int doctype4(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_OPEN_BRACKET:
+ state->handler = internalSubset;
+ return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
+ case XML_TOK_DECL_CLOSE:
+ state->handler = prolog2;
+ return XML_ROLE_DOCTYPE_CLOSE;
+ }
+ return common(state, tok);
+}
+
+static
+int doctype5(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_DECL_CLOSE:
+ state->handler = prolog2;
+ return XML_ROLE_DOCTYPE_CLOSE;
+ }
+ return common(state, tok);
+}
+
+static
+int internalSubset(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_DECL_OPEN:
+ if (XmlNameMatchesAscii(enc,
+ ptr + 2 * MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_ENTITY)) {
+ state->handler = entity0;
+ return XML_ROLE_NONE;
+ }
+ if (XmlNameMatchesAscii(enc,
+ ptr + 2 * MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_ATTLIST)) {
+ state->handler = attlist0;
+ return XML_ROLE_NONE;
+ }
+ if (XmlNameMatchesAscii(enc,
+ ptr + 2 * MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_ELEMENT)) {
+ state->handler = element0;
+ return XML_ROLE_NONE;
+ }
+ if (XmlNameMatchesAscii(enc,
+ ptr + 2 * MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_NOTATION)) {
+ state->handler = notation0;
+ return XML_ROLE_NONE;
+ }
+ break;
+ case XML_TOK_PI:
+ case XML_TOK_COMMENT:
+ return XML_ROLE_NONE;
+ case XML_TOK_PARAM_ENTITY_REF:
+ return XML_ROLE_PARAM_ENTITY_REF;
+ case XML_TOK_CLOSE_BRACKET:
+ state->handler = doctype5;
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+
+#ifdef XML_DTD
+
+static
+int externalSubset0(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ state->handler = externalSubset1;
+ if (tok == XML_TOK_XML_DECL)
+ return XML_ROLE_TEXT_DECL;
+ return externalSubset1(state, tok, ptr, end, enc);
+}
+
+static
+int externalSubset1(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ switch (tok) {
+ case XML_TOK_COND_SECT_OPEN:
+ state->handler = condSect0;
+ return XML_ROLE_NONE;
+ case XML_TOK_COND_SECT_CLOSE:
+ if (state->includeLevel == 0)
+ break;
+ state->includeLevel -= 1;
+ return XML_ROLE_NONE;
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_CLOSE_BRACKET:
+ break;
+ case XML_TOK_NONE:
+ if (state->includeLevel)
+ break;
+ return XML_ROLE_NONE;
+ default:
+ return internalSubset(state, tok, ptr, end, enc);
+ }
+ return common(state, tok);
+}
+
+#endif /* XML_DTD */
+
+static
+int entity0(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_PERCENT:
+ state->handler = entity1;
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ state->handler = entity2;
+ return XML_ROLE_GENERAL_ENTITY_NAME;
+ }
+ return common(state, tok);
+}
+
+static
+int entity1(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ state->handler = entity7;
+ return XML_ROLE_PARAM_ENTITY_NAME;
+ }
+ return common(state, tok);
+}
+
+static
+int entity2(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
+ state->handler = entity4;
+ return XML_ROLE_NONE;
+ }
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
+ state->handler = entity3;
+ return XML_ROLE_NONE;
+ }
+ break;
+ case XML_TOK_LITERAL:
+ state->handler = declClose;
+ return XML_ROLE_ENTITY_VALUE;
+ }
+ return common(state, tok);
+}
+
+static
+int entity3(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = entity4;
+ return XML_ROLE_ENTITY_PUBLIC_ID;
+ }
+ return common(state, tok);
+}
+
+
+static
+int entity4(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = entity5;
+ return XML_ROLE_ENTITY_SYSTEM_ID;
+ }
+ return common(state, tok);
+}
+
+static
+int entity5(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_DECL_CLOSE:
+ setTopLevel(state);
+ return XML_ROLE_ENTITY_COMPLETE;
+ case XML_TOK_NAME:
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) {
+ state->handler = entity6;
+ return XML_ROLE_NONE;
+ }
+ break;
+ }
+ return common(state, tok);
+}
+
+static
+int entity6(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ state->handler = declClose;
+ return XML_ROLE_ENTITY_NOTATION_NAME;
+ }
+ return common(state, tok);
+}
+
+static
+int entity7(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
+ state->handler = entity9;
+ return XML_ROLE_NONE;
+ }
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
+ state->handler = entity8;
+ return XML_ROLE_NONE;
+ }
+ break;
+ case XML_TOK_LITERAL:
+ state->handler = declClose;
+ return XML_ROLE_ENTITY_VALUE;
+ }
+ return common(state, tok);
+}
+
+static
+int entity8(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = entity9;
+ return XML_ROLE_ENTITY_PUBLIC_ID;
+ }
+ return common(state, tok);
+}
+
+static
+int entity9(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = declClose;
+ return XML_ROLE_ENTITY_SYSTEM_ID;
+ }
+ return common(state, tok);
+}
+
+static
+int notation0(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ state->handler = notation1;
+ return XML_ROLE_NOTATION_NAME;
+ }
+ return common(state, tok);
+}
+
+static
+int notation1(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
+ state->handler = notation3;
+ return XML_ROLE_NONE;
+ }
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
+ state->handler = notation2;
+ return XML_ROLE_NONE;
+ }
+ break;
+ }
+ return common(state, tok);
+}
+
+static
+int notation2(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = notation4;
+ return XML_ROLE_NOTATION_PUBLIC_ID;
+ }
+ return common(state, tok);
+}
+
+static
+int notation3(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = declClose;
+ return XML_ROLE_NOTATION_SYSTEM_ID;
+ }
+ return common(state, tok);
+}
+
+static
+int notation4(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = declClose;
+ return XML_ROLE_NOTATION_SYSTEM_ID;
+ case XML_TOK_DECL_CLOSE:
+ setTopLevel(state);
+ return XML_ROLE_NOTATION_NO_SYSTEM_ID;
+ }
+ return common(state, tok);
+}
+
+static
+int attlist0(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ case XML_TOK_PREFIXED_NAME:
+ state->handler = attlist1;
+ return XML_ROLE_ATTLIST_ELEMENT_NAME;
+ }
+ return common(state, tok);
+}
+
+static
+int attlist1(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_DECL_CLOSE:
+ setTopLevel(state);
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ case XML_TOK_PREFIXED_NAME:
+ state->handler = attlist2;
+ return XML_ROLE_ATTRIBUTE_NAME;
+ }
+ return common(state, tok);
+}
+
+static
+int attlist2(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ {
+ static const char *types[] = {
+ KW_CDATA,
+ KW_ID,
+ KW_IDREF,
+ KW_IDREFS,
+ KW_ENTITY,
+ KW_ENTITIES,
+ KW_NMTOKEN,
+ KW_NMTOKENS,
+ };
+ int i;
+ for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++)
+ if (XmlNameMatchesAscii(enc, ptr, end, types[i])) {
+ state->handler = attlist8;
+ return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i;
+ }
+ }
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) {
+ state->handler = attlist5;
+ return XML_ROLE_NONE;
+ }
+ break;
+ case XML_TOK_OPEN_PAREN:
+ state->handler = attlist3;
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+
+static
+int attlist3(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NMTOKEN:
+ case XML_TOK_NAME:
+ case XML_TOK_PREFIXED_NAME:
+ state->handler = attlist4;
+ return XML_ROLE_ATTRIBUTE_ENUM_VALUE;
+ }
+ return common(state, tok);
+}
+
+static
+int attlist4(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_CLOSE_PAREN:
+ state->handler = attlist8;
+ return XML_ROLE_NONE;
+ case XML_TOK_OR:
+ state->handler = attlist3;
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+
+static
+int attlist5(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_OPEN_PAREN:
+ state->handler = attlist6;
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+
+
+static
+int attlist6(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ state->handler = attlist7;
+ return XML_ROLE_ATTRIBUTE_NOTATION_VALUE;
+ }
+ return common(state, tok);
+}
+
+static
+int attlist7(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_CLOSE_PAREN:
+ state->handler = attlist8;
+ return XML_ROLE_NONE;
+ case XML_TOK_OR:
+ state->handler = attlist6;
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+
+/* default value */
+static
+int attlist8(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_POUND_NAME:
+ if (XmlNameMatchesAscii(enc,
+ ptr + MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_IMPLIED)) {
+ state->handler = attlist1;
+ return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE;
+ }
+ if (XmlNameMatchesAscii(enc,
+ ptr + MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_REQUIRED)) {
+ state->handler = attlist1;
+ return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE;
+ }
+ if (XmlNameMatchesAscii(enc,
+ ptr + MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_FIXED)) {
+ state->handler = attlist9;
+ return XML_ROLE_NONE;
+ }
+ break;
+ case XML_TOK_LITERAL:
+ state->handler = attlist1;
+ return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE;
+ }
+ return common(state, tok);
+}
+
+static
+int attlist9(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_LITERAL:
+ state->handler = attlist1;
+ return XML_ROLE_FIXED_ATTRIBUTE_VALUE;
+ }
+ return common(state, tok);
+}
+
+static
+int element0(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ case XML_TOK_PREFIXED_NAME:
+ state->handler = element1;
+ return XML_ROLE_ELEMENT_NAME;
+ }
+ return common(state, tok);
+}
+
+static
+int element1(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) {
+ state->handler = declClose;
+ return XML_ROLE_CONTENT_EMPTY;
+ }
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) {
+ state->handler = declClose;
+ return XML_ROLE_CONTENT_ANY;
+ }
+ break;
+ case XML_TOK_OPEN_PAREN:
+ state->handler = element2;
+ state->level = 1;
+ return XML_ROLE_GROUP_OPEN;
+ }
+ return common(state, tok);
+}
+
+static
+int element2(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_POUND_NAME:
+ if (XmlNameMatchesAscii(enc,
+ ptr + MIN_BYTES_PER_CHAR(enc),
+ end,
+ KW_PCDATA)) {
+ state->handler = element3;
+ return XML_ROLE_CONTENT_PCDATA;
+ }
+ break;
+ case XML_TOK_OPEN_PAREN:
+ state->level = 2;
+ state->handler = element6;
+ return XML_ROLE_GROUP_OPEN;
+ case XML_TOK_NAME:
+ case XML_TOK_PREFIXED_NAME:
+ state->handler = element7;
+ return XML_ROLE_CONTENT_ELEMENT;
+ case XML_TOK_NAME_QUESTION:
+ state->handler = element7;
+ return XML_ROLE_CONTENT_ELEMENT_OPT;
+ case XML_TOK_NAME_ASTERISK:
+ state->handler = element7;
+ return XML_ROLE_CONTENT_ELEMENT_REP;
+ case XML_TOK_NAME_PLUS:
+ state->handler = element7;
+ return XML_ROLE_CONTENT_ELEMENT_PLUS;
+ }
+ return common(state, tok);
+}
+
+static
+int element3(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_CLOSE_PAREN:
+ state->handler = declClose;
+ return XML_ROLE_GROUP_CLOSE;
+ case XML_TOK_CLOSE_PAREN_ASTERISK:
+ state->handler = declClose;
+ return XML_ROLE_GROUP_CLOSE_REP;
+ case XML_TOK_OR:
+ state->handler = element4;
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+
+static
+int element4(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ case XML_TOK_PREFIXED_NAME:
+ state->handler = element5;
+ return XML_ROLE_CONTENT_ELEMENT;
+ }
+ return common(state, tok);
+}
+
+static
+int element5(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_CLOSE_PAREN_ASTERISK:
+ state->handler = declClose;
+ return XML_ROLE_GROUP_CLOSE_REP;
+ case XML_TOK_OR:
+ state->handler = element4;
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+
+static
+int element6(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_OPEN_PAREN:
+ state->level += 1;
+ return XML_ROLE_GROUP_OPEN;
+ case XML_TOK_NAME:
+ case XML_TOK_PREFIXED_NAME:
+ state->handler = element7;
+ return XML_ROLE_CONTENT_ELEMENT;
+ case XML_TOK_NAME_QUESTION:
+ state->handler = element7;
+ return XML_ROLE_CONTENT_ELEMENT_OPT;
+ case XML_TOK_NAME_ASTERISK:
+ state->handler = element7;
+ return XML_ROLE_CONTENT_ELEMENT_REP;
+ case XML_TOK_NAME_PLUS:
+ state->handler = element7;
+ return XML_ROLE_CONTENT_ELEMENT_PLUS;
+ }
+ return common(state, tok);
+}
+
+static
+int element7(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_CLOSE_PAREN:
+ state->level -= 1;
+ if (state->level == 0)
+ state->handler = declClose;
+ return XML_ROLE_GROUP_CLOSE;
+ case XML_TOK_CLOSE_PAREN_ASTERISK:
+ state->level -= 1;
+ if (state->level == 0)
+ state->handler = declClose;
+ return XML_ROLE_GROUP_CLOSE_REP;
+ case XML_TOK_CLOSE_PAREN_QUESTION:
+ state->level -= 1;
+ if (state->level == 0)
+ state->handler = declClose;
+ return XML_ROLE_GROUP_CLOSE_OPT;
+ case XML_TOK_CLOSE_PAREN_PLUS:
+ state->level -= 1;
+ if (state->level == 0)
+ state->handler = declClose;
+ return XML_ROLE_GROUP_CLOSE_PLUS;
+ case XML_TOK_COMMA:
+ state->handler = element6;
+ return XML_ROLE_GROUP_SEQUENCE;
+ case XML_TOK_OR:
+ state->handler = element6;
+ return XML_ROLE_GROUP_CHOICE;
+ }
+ return common(state, tok);
+}
+
+#ifdef XML_DTD
+
+static
+int condSect0(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_NAME:
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) {
+ state->handler = condSect1;
+ return XML_ROLE_NONE;
+ }
+ if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) {
+ state->handler = condSect2;
+ return XML_ROLE_NONE;
+ }
+ break;
+ }
+ return common(state, tok);
+}
+
+static
+int condSect1(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_OPEN_BRACKET:
+ state->handler = externalSubset1;
+ state->includeLevel += 1;
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+
+static
+int condSect2(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_OPEN_BRACKET:
+ state->handler = externalSubset1;
+ return XML_ROLE_IGNORE_SECT;
+ }
+ return common(state, tok);
+}
+
+#endif /* XML_DTD */
+
+static
+int declClose(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_PROLOG_S:
+ return XML_ROLE_NONE;
+ case XML_TOK_DECL_CLOSE:
+ setTopLevel(state);
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+
+#if 0
+
+static
+int ignore(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ switch (tok) {
+ case XML_TOK_DECL_CLOSE:
+ state->handler = internalSubset;
+ return 0;
+ default:
+ return XML_ROLE_NONE;
+ }
+ return common(state, tok);
+}
+#endif
+
+static
+int error(PROLOG_STATE *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc)
+{
+ cmExpatUnused(state);
+ cmExpatUnused(tok);
+ cmExpatUnused(ptr);
+ cmExpatUnused(end);
+ cmExpatUnused(enc);
+ return XML_ROLE_NONE;
+}
+
+static
+int common(PROLOG_STATE *state, int tok)
+{
+#ifdef XML_DTD
+ if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF)
+ return XML_ROLE_INNER_PARAM_ENTITY_REF;
+#endif
+ state->handler = error;
+ return XML_ROLE_ERROR;
+}
+
+void XmlPrologStateInit(PROLOG_STATE *state)
+{
+ state->handler = prolog0;
+#ifdef XML_DTD
+ state->documentEntity = 1;
+ state->includeLevel = 0;
+#endif /* XML_DTD */
+}
+
+#ifdef XML_DTD
+
+void XmlPrologStateInitExternalEntity(PROLOG_STATE *state)
+{
+ state->handler = externalSubset0;
+ state->documentEntity = 0;
+ state->includeLevel = 0;
+}
+
+#endif /* XML_DTD */
diff --git a/Utilities/cmexpat/xmlrole.h b/Utilities/cmexpat/xmlrole.h
new file mode 100644
index 0000000000..6f25793066
--- /dev/null
+++ b/Utilities/cmexpat/xmlrole.h
@@ -0,0 +1,100 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+#ifndef XmlRole_INCLUDED
+#define XmlRole_INCLUDED 1
+
+#include "xmltok.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum {
+ XML_ROLE_ERROR = -1,
+ XML_ROLE_NONE = 0,
+ XML_ROLE_XML_DECL,
+ XML_ROLE_INSTANCE_START,
+ XML_ROLE_DOCTYPE_NAME,
+ XML_ROLE_DOCTYPE_SYSTEM_ID,
+ XML_ROLE_DOCTYPE_PUBLIC_ID,
+ XML_ROLE_DOCTYPE_INTERNAL_SUBSET,
+ XML_ROLE_DOCTYPE_CLOSE,
+ XML_ROLE_GENERAL_ENTITY_NAME,
+ XML_ROLE_PARAM_ENTITY_NAME,
+ XML_ROLE_ENTITY_VALUE,
+ XML_ROLE_ENTITY_SYSTEM_ID,
+ XML_ROLE_ENTITY_PUBLIC_ID,
+ XML_ROLE_ENTITY_COMPLETE,
+ XML_ROLE_ENTITY_NOTATION_NAME,
+ XML_ROLE_NOTATION_NAME,
+ XML_ROLE_NOTATION_SYSTEM_ID,
+ XML_ROLE_NOTATION_NO_SYSTEM_ID,
+ XML_ROLE_NOTATION_PUBLIC_ID,
+ XML_ROLE_ATTRIBUTE_NAME,
+ XML_ROLE_ATTRIBUTE_TYPE_CDATA,
+ XML_ROLE_ATTRIBUTE_TYPE_ID,
+ XML_ROLE_ATTRIBUTE_TYPE_IDREF,
+ XML_ROLE_ATTRIBUTE_TYPE_IDREFS,
+ XML_ROLE_ATTRIBUTE_TYPE_ENTITY,
+ XML_ROLE_ATTRIBUTE_TYPE_ENTITIES,
+ XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN,
+ XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS,
+ XML_ROLE_ATTRIBUTE_ENUM_VALUE,
+ XML_ROLE_ATTRIBUTE_NOTATION_VALUE,
+ XML_ROLE_ATTLIST_ELEMENT_NAME,
+ XML_ROLE_IMPLIED_ATTRIBUTE_VALUE,
+ XML_ROLE_REQUIRED_ATTRIBUTE_VALUE,
+ XML_ROLE_DEFAULT_ATTRIBUTE_VALUE,
+ XML_ROLE_FIXED_ATTRIBUTE_VALUE,
+ XML_ROLE_ELEMENT_NAME,
+ XML_ROLE_CONTENT_ANY,
+ XML_ROLE_CONTENT_EMPTY,
+ XML_ROLE_CONTENT_PCDATA,
+ XML_ROLE_GROUP_OPEN,
+ XML_ROLE_GROUP_CLOSE,
+ XML_ROLE_GROUP_CLOSE_REP,
+ XML_ROLE_GROUP_CLOSE_OPT,
+ XML_ROLE_GROUP_CLOSE_PLUS,
+ XML_ROLE_GROUP_CHOICE,
+ XML_ROLE_GROUP_SEQUENCE,
+ XML_ROLE_CONTENT_ELEMENT,
+ XML_ROLE_CONTENT_ELEMENT_REP,
+ XML_ROLE_CONTENT_ELEMENT_OPT,
+ XML_ROLE_CONTENT_ELEMENT_PLUS,
+#ifdef XML_DTD
+ XML_ROLE_TEXT_DECL,
+ XML_ROLE_IGNORE_SECT,
+ XML_ROLE_INNER_PARAM_ENTITY_REF,
+#endif /* XML_DTD */
+ XML_ROLE_PARAM_ENTITY_REF
+};
+
+typedef struct prolog_state {
+ int (*handler)(struct prolog_state *state,
+ int tok,
+ const char *ptr,
+ const char *end,
+ const ENCODING *enc);
+ unsigned level;
+#ifdef XML_DTD
+ unsigned includeLevel;
+ int documentEntity;
+#endif /* XML_DTD */
+} PROLOG_STATE;
+
+void XmlPrologStateInit(PROLOG_STATE *);
+#ifdef XML_DTD
+void XmlPrologStateInitExternalEntity(PROLOG_STATE *);
+#endif /* XML_DTD */
+
+#define XmlTokenRole(state, tok, ptr, end, enc) \
+ (((state)->handler)(state, tok, ptr, end, enc))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* not XmlRole_INCLUDED */
diff --git a/Utilities/cmexpat/xmltok.c b/Utilities/cmexpat/xmltok.c
new file mode 100644
index 0000000000..8ee9c7519c
--- /dev/null
+++ b/Utilities/cmexpat/xmltok.c
@@ -0,0 +1,1584 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+#include <cmexpat/expatConfig.h>
+
+#include "xmltok.h"
+#include "nametab.h"
+
+#if defined(__BORLANDC__)
+#pragma warn -8008 // Disable "condition is always true" warning.
+#pragma warn -8066 // Disable "unreachable code" warning.
+#endif
+
+#ifdef XML_DTD
+#define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok)
+#else
+#define IGNORE_SECTION_TOK_VTABLE /* as nothing */
+#endif
+
+#define VTABLE1 \
+ { PREFIX(prologTok), PREFIX(contentTok), \
+ PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \
+ { PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \
+ PREFIX(sameName), \
+ PREFIX(nameMatchesAscii), \
+ PREFIX(nameLength), \
+ PREFIX(skipS), \
+ PREFIX(getAtts), \
+ PREFIX(charRefNumber), \
+ PREFIX(predefinedEntityName), \
+ PREFIX(updatePosition), \
+ PREFIX(isPublicId)
+
+#define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16)
+
+#define UCS2_GET_NAMING(pages, hi, lo) \
+ (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1 << ((lo) & 0x1F)))
+
+/* A 2 byte UTF-8 representation splits the characters 11 bits
+between the bottom 5 and 6 bits of the bytes.
+We need 8 bits to index into pages, 3 bits to add to that index and
+5 bits to generate the mask. */
+#define UTF8_GET_NAMING2(pages, byte) \
+ (namingBitmap[((pages)[(((byte)[0]) >> 2) & 7] << 3) \
+ + ((((byte)[0]) & 3) << 1) \
+ + ((((byte)[1]) >> 5) & 1)] \
+ & (1 << (((byte)[1]) & 0x1F)))
+
+/* A 3 byte UTF-8 representation splits the characters 16 bits
+between the bottom 4, 6 and 6 bits of the bytes.
+We need 8 bits to index into pages, 3 bits to add to that index and
+5 bits to generate the mask. */
+#define UTF8_GET_NAMING3(pages, byte) \
+ (namingBitmap[((pages)[((((byte)[0]) & 0xF) << 4) \
+ + ((((byte)[1]) >> 2) & 0xF)] \
+ << 3) \
+ + ((((byte)[1]) & 3) << 1) \
+ + ((((byte)[2]) >> 5) & 1)] \
+ & (1 << (((byte)[2]) & 0x1F)))
+
+#define UTF8_GET_NAMING(pages, p, n) \
+ ((n) == 2 \
+ ? UTF8_GET_NAMING2(pages, (const unsigned char *)(p)) \
+ : ((n) == 3 \
+ ? UTF8_GET_NAMING3(pages, (const unsigned char *)(p)) \
+ : 0))
+
+#define UTF8_INVALID3(p) \
+ ((*p) == 0xED \
+ ? (((p)[1] & 0x20) != 0) \
+ : ((*p) == 0xEF \
+ ? ((p)[1] == 0xBF && ((p)[2] == 0xBF || (p)[2] == 0xBE)) \
+ : 0))
+
+#define UTF8_INVALID4(p) ((*p) == 0xF4 && ((p)[1] & 0x30) != 0)
+
+static
+int isNever(const ENCODING *enc, const char *p)
+{
+ cmExpatUnused(enc);
+ cmExpatUnused(p);
+ return 0;
+}
+
+static
+int utf8_isName2(const ENCODING *enc, const char *p)
+{
+ cmExpatUnused(enc);
+ return UTF8_GET_NAMING2(namePages, (const unsigned char *)p);
+}
+
+static
+int utf8_isName3(const ENCODING *enc, const char *p)
+{
+ cmExpatUnused(enc);
+ return UTF8_GET_NAMING3(namePages, (const unsigned char *)p);
+}
+
+#define utf8_isName4 isNever
+
+static
+int utf8_isNmstrt2(const ENCODING *enc, const char *p)
+{
+ cmExpatUnused(enc);
+ return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p);
+}
+
+static
+int utf8_isNmstrt3(const ENCODING *enc, const char *p)
+{
+ cmExpatUnused(enc);
+ return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p);
+}
+
+#define utf8_isNmstrt4 isNever
+
+#define utf8_isInvalid2 isNever
+
+static
+int utf8_isInvalid3(const ENCODING *enc, const char *p)
+{
+ cmExpatUnused(enc);
+ return UTF8_INVALID3((const unsigned char *)p);
+}
+
+static
+int utf8_isInvalid4(const ENCODING *enc, const char *p)
+{
+ cmExpatUnused(enc);
+ return UTF8_INVALID4((const unsigned char *)p);
+}
+
+struct normal_encoding {
+ ENCODING enc;
+ unsigned char type[256];
+#ifdef XML_MIN_SIZE
+ int (*byteType)(const ENCODING *, const char *);
+ int (*isNameMin)(const ENCODING *, const char *);
+ int (*isNmstrtMin)(const ENCODING *, const char *);
+ int (*byteToAscii)(const ENCODING *, const char *);
+ int (*charMatches)(const ENCODING *, const char *, int);
+#endif /* XML_MIN_SIZE */
+ int (*isName2)(const ENCODING *, const char *);
+ int (*isName3)(const ENCODING *, const char *);
+ int (*isName4)(const ENCODING *, const char *);
+ int (*isNmstrt2)(const ENCODING *, const char *);
+ int (*isNmstrt3)(const ENCODING *, const char *);
+ int (*isNmstrt4)(const ENCODING *, const char *);
+ int (*isInvalid2)(const ENCODING *, const char *);
+ int (*isInvalid3)(const ENCODING *, const char *);
+ int (*isInvalid4)(const ENCODING *, const char *);
+};
+
+#ifdef XML_MIN_SIZE
+
+#define STANDARD_VTABLE(E) \
+ E ## byteType, \
+ E ## isNameMin, \
+ E ## isNmstrtMin, \
+ E ## byteToAscii, \
+ E ## charMatches,
+
+#else
+
+#define STANDARD_VTABLE(E) /* as nothing */
+
+#endif
+
+#define NORMAL_VTABLE(E) \
+ E ## isName2, \
+ E ## isName3, \
+ E ## isName4, \
+ E ## isNmstrt2, \
+ E ## isNmstrt3, \
+ E ## isNmstrt4, \
+ E ## isInvalid2, \
+ E ## isInvalid3, \
+ E ## isInvalid4
+
+#define EMPTY_VTABLE(E) 0, 0, 0, 0, 0, 0, 0, 0, 0
+
+static int checkCharRefNumber(int);
+
+#include "xmltok_impl.h"
+#include "ascii.h"
+
+#ifdef XML_MIN_SIZE
+#define sb_isNameMin isNever
+#define sb_isNmstrtMin isNever
+#endif
+
+#ifdef XML_MIN_SIZE
+#define MINBPC(enc) ((enc)->minBytesPerChar)
+#else
+/* minimum bytes per character */
+#define MINBPC(enc) 1
+#endif
+
+#define SB_BYTE_TYPE(enc, p) \
+ (((struct normal_encoding *)(enc))->type[(unsigned char)*(p)])
+
+#ifdef XML_MIN_SIZE
+static
+int sb_byteType(const ENCODING *enc, const char *p)
+{
+ return SB_BYTE_TYPE(enc, p);
+}
+#define BYTE_TYPE(enc, p) \
+ (((const struct normal_encoding *)(enc))->byteType(enc, p))
+#else
+#define BYTE_TYPE(enc, p) SB_BYTE_TYPE(enc, p)
+#endif
+
+#ifdef XML_MIN_SIZE
+#define BYTE_TO_ASCII(enc, p) \
+ (((const struct normal_encoding *)(enc))->byteToAscii(enc, p))
+static
+int sb_byteToAscii(const ENCODING *enc, const char *p)
+{
+ return *p;
+}
+#else
+#define BYTE_TO_ASCII(enc, p) (*(p))
+#endif
+
+#define IS_NAME_CHAR(enc, p, n) \
+ (((const struct normal_encoding *)(enc))->isName ## n(enc, p))
+#define IS_NMSTRT_CHAR(enc, p, n) \
+ (((const struct normal_encoding *)(enc))->isNmstrt ## n(enc, p))
+#define IS_INVALID_CHAR(enc, p, n) \
+ (((const struct normal_encoding *)(enc))->isInvalid ## n(enc, p))
+
+#ifdef XML_MIN_SIZE
+#define IS_NAME_CHAR_MINBPC(enc, p) \
+ (((const struct normal_encoding *)(enc))->isNameMin(enc, p))
+#define IS_NMSTRT_CHAR_MINBPC(enc, p) \
+ (((const struct normal_encoding *)(enc))->isNmstrtMin(enc, p))
+#else
+#define IS_NAME_CHAR_MINBPC(enc, p) (0)
+#define IS_NMSTRT_CHAR_MINBPC(enc, p) (0)
+#endif
+
+#ifdef XML_MIN_SIZE
+#define CHAR_MATCHES(enc, p, c) \
+ (((const struct normal_encoding *)(enc))->charMatches(enc, p, c))
+static
+int sb_charMatches(const ENCODING *enc, const char *p, int c)
+{
+ return *p == c;
+}
+#else
+/* c is an ASCII character */
+#define CHAR_MATCHES(enc, p, c) (*(p) == c)
+#endif
+
+#define PREFIX(ident) normal_ ## ident
+#include "xmltok_impl.c"
+
+#undef MINBPC
+#undef BYTE_TYPE
+#undef BYTE_TO_ASCII
+#undef CHAR_MATCHES
+#undef IS_NAME_CHAR
+#undef IS_NAME_CHAR_MINBPC
+#undef IS_NMSTRT_CHAR
+#undef IS_NMSTRT_CHAR_MINBPC
+#undef IS_INVALID_CHAR
+
+enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */
+ UTF8_cval1 = 0x00,
+ UTF8_cval2 = 0xc0,
+ UTF8_cval3 = 0xe0,
+ UTF8_cval4 = 0xf0
+};
+
+static
+void utf8_toUtf8(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ char **toP, const char *toLim)
+{
+ char *to;
+ const char *from;
+ cmExpatUnused(enc);
+ if (fromLim - *fromP > toLim - *toP) {
+ /* Avoid copying partial characters. */
+ for (fromLim = *fromP + (toLim - *toP); fromLim > *fromP; fromLim--)
+ if (((unsigned char)fromLim[-1] & 0xc0) != 0x80)
+ break;
+ }
+ for (to = *toP, from = *fromP; from != fromLim; from++, to++)
+ *to = *from;
+ *fromP = from;
+ *toP = to;
+}
+
+static
+void utf8_toUtf16(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ unsigned short **toP, const unsigned short *toLim)
+{
+ unsigned short *to = *toP;
+ const char *from = *fromP;
+ while (from != fromLim && to != toLim) {
+ switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) {
+ case BT_LEAD2:
+ *to++ = ((from[0] & 0x1f) << 6) | (from[1] & 0x3f);
+ from += 2;
+ break;
+ case BT_LEAD3:
+ *to++ = ((from[0] & 0xf) << 12) | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f);
+ from += 3;
+ break;
+ case BT_LEAD4:
+ {
+ unsigned long n;
+ if (to + 1 == toLim)
+ break;
+ n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12) | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f);
+ n -= 0x10000;
+ to[0] = (unsigned short)((n >> 10) | 0xD800);
+ to[1] = (unsigned short)((n & 0x3FF) | 0xDC00);
+ to += 2;
+ from += 4;
+ }
+ break;
+ default:
+ *to++ = *from++;
+ break;
+ }
+ }
+ *fromP = from;
+ *toP = to;
+}
+
+#ifdef XML_NS
+static const struct normal_encoding utf8_encoding_ns = {
+ { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
+ {
+#include "asciitab.h"
+#include "utf8tab.h"
+ },
+ STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)
+};
+#endif
+
+static const struct normal_encoding utf8_encoding = {
+ { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
+ {
+#define BT_COLON BT_NMSTRT
+#include "asciitab.h"
+#undef BT_COLON
+#include "utf8tab.h"
+ },
+ STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)
+};
+
+#ifdef XML_NS
+
+static const struct normal_encoding internal_utf8_encoding_ns = {
+ { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
+ {
+#include "iasciitab.h"
+#include "utf8tab.h"
+ },
+ STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)
+};
+
+#endif
+
+static const struct normal_encoding internal_utf8_encoding = {
+ { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
+ {
+#define BT_COLON BT_NMSTRT
+#include "iasciitab.h"
+#undef BT_COLON
+#include "utf8tab.h"
+ },
+ STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)
+};
+
+static
+void latin1_toUtf8(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ char **toP, const char *toLim)
+{
+ cmExpatUnused(enc);
+ for (;;) {
+ unsigned char c;
+ if (*fromP == fromLim)
+ break;
+ c = (unsigned char)**fromP;
+ if (c & 0x80) {
+ if (toLim - *toP < 2)
+ break;
+ *(*toP)++ = ((c >> 6) | UTF8_cval2);
+ *(*toP)++ = ((c & 0x3f) | 0x80);
+ (*fromP)++;
+ }
+ else {
+ if (*toP == toLim)
+ break;
+ *(*toP)++ = *(*fromP)++;
+ }
+ }
+}
+
+static
+void latin1_toUtf16(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ unsigned short **toP, const unsigned short *toLim)
+{
+ cmExpatUnused(enc);
+ while (*fromP != fromLim && *toP != toLim)
+ *(*toP)++ = (unsigned char)*(*fromP)++;
+}
+
+#ifdef XML_NS
+
+static const struct normal_encoding latin1_encoding_ns = {
+ { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 },
+ {
+#include "asciitab.h"
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(sb_) EMPTY_VTABLE(sb_)
+};
+
+#endif
+
+static const struct normal_encoding latin1_encoding = {
+ { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 },
+ {
+#define BT_COLON BT_NMSTRT
+#include "asciitab.h"
+#undef BT_COLON
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(sb_) EMPTY_VTABLE(sb_)
+};
+
+static
+void ascii_toUtf8(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ char **toP, const char *toLim)
+{
+ cmExpatUnused(enc);
+ while (*fromP != fromLim && *toP != toLim)
+ *(*toP)++ = *(*fromP)++;
+}
+
+#ifdef XML_NS
+
+static const struct normal_encoding ascii_encoding_ns = {
+ { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 },
+ {
+#include "asciitab.h"
+/* BT_NONXML == 0 */
+ },
+ STANDARD_VTABLE(sb_) EMPTY_VTABLE(sb_)
+};
+
+#endif
+
+static const struct normal_encoding ascii_encoding = {
+ { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 },
+ {
+#define BT_COLON BT_NMSTRT
+#include "asciitab.h"
+#undef BT_COLON
+/* BT_NONXML == 0 */
+ },
+ STANDARD_VTABLE(sb_) EMPTY_VTABLE(sb_)
+};
+
+static int unicode_byte_type(char hi, char lo)
+{
+ switch ((unsigned char)hi) {
+ case 0xD8: case 0xD9: case 0xDA: case 0xDB:
+ return BT_LEAD4;
+ case 0xDC: case 0xDD: case 0xDE: case 0xDF:
+ return BT_TRAIL;
+ case 0xFF:
+ switch ((unsigned char)lo) {
+ case 0xFF:
+ case 0xFE:
+ return BT_NONXML;
+ }
+ break;
+ }
+ return BT_NONASCII;
+}
+
+#define DEFINE_UTF16_TO_UTF8(E) \
+static \
+void E ## toUtf8(const ENCODING *enc, \
+ const char **fromP, const char *fromLim, \
+ char **toP, const char *toLim) \
+{ \
+ const char *from; \
+ cmExpatUnused(enc);\
+ for (from = *fromP; from != fromLim; from += 2) { \
+ int plane; \
+ unsigned char lo2; \
+ unsigned char lo = GET_LO(from); \
+ unsigned char hi = GET_HI(from); \
+ switch (hi) { \
+ case 0: \
+ if (lo < 0x80) { \
+ if (*toP == toLim) { \
+ *fromP = from; \
+ return; \
+ } \
+ *(*toP)++ = lo; \
+ break; \
+ } \
+ /* fall through */ \
+ case 0x1: case 0x2: case 0x3: \
+ case 0x4: case 0x5: case 0x6: case 0x7: \
+ if (toLim - *toP < 2) { \
+ *fromP = from; \
+ return; \
+ } \
+ *(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \
+ *(*toP)++ = ((lo & 0x3f) | 0x80); \
+ break; \
+ default: \
+ if (toLim - *toP < 3) { \
+ *fromP = from; \
+ return; \
+ } \
+ /* 16 bits divided 4, 6, 6 amongst 3 bytes */ \
+ *(*toP)++ = ((hi >> 4) | UTF8_cval3); \
+ *(*toP)++ = (((hi & 0xf) << 2) | (lo >> 6) | 0x80); \
+ *(*toP)++ = ((lo & 0x3f) | 0x80); \
+ break; \
+ case 0xD8: case 0xD9: case 0xDA: case 0xDB: \
+ if (toLim - *toP < 4) { \
+ *fromP = from; \
+ return; \
+ } \
+ plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \
+ *(*toP)++ = ((plane >> 2) | UTF8_cval4); \
+ *(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \
+ from += 2; \
+ lo2 = GET_LO(from); \
+ *(*toP)++ = (((lo & 0x3) << 4) \
+ | ((GET_HI(from) & 0x3) << 2) \
+ | (lo2 >> 6) \
+ | 0x80); \
+ *(*toP)++ = ((lo2 & 0x3f) | 0x80); \
+ break; \
+ } \
+ } \
+ *fromP = from; \
+}
+
+#define DEFINE_UTF16_TO_UTF16(E) \
+static \
+void E ## toUtf16(const ENCODING *enc, \
+ const char **fromP, const char *fromLim, \
+ unsigned short **toP, const unsigned short *toLim) \
+{ \
+ cmExpatUnused(enc);\
+ /* Avoid copying first half only of surrogate */ \
+ if (fromLim - *fromP > ((toLim - *toP) << 1) \
+ && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \
+ fromLim -= 2; \
+ for (; *fromP != fromLim && *toP != toLim; *fromP += 2) \
+ *(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \
+}
+
+#define SET2(ptr, ch) \
+ (((ptr)[0] = ((ch) & 0xff)), ((ptr)[1] = ((ch) >> 8)))
+#define GET_LO(ptr) ((unsigned char)(ptr)[0])
+#define GET_HI(ptr) ((unsigned char)(ptr)[1])
+
+DEFINE_UTF16_TO_UTF8(little2_)
+DEFINE_UTF16_TO_UTF16(little2_)
+
+#undef SET2
+#undef GET_LO
+#undef GET_HI
+
+#define SET2(ptr, ch) \
+ (((ptr)[0] = ((ch) >> 8)), ((ptr)[1] = ((ch) & 0xFF)))
+#define GET_LO(ptr) ((unsigned char)(ptr)[1])
+#define GET_HI(ptr) ((unsigned char)(ptr)[0])
+
+DEFINE_UTF16_TO_UTF8(big2_)
+DEFINE_UTF16_TO_UTF16(big2_)
+
+#undef SET2
+#undef GET_LO
+#undef GET_HI
+
+#define LITTLE2_BYTE_TYPE(enc, p) \
+ ((p)[1] == 0 \
+ ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \
+ : unicode_byte_type((p)[1], (p)[0]))
+#define LITTLE2_BYTE_TO_ASCII(enc, p) ((p)[1] == 0 ? (p)[0] : -1)
+#define LITTLE2_CHAR_MATCHES(enc, p, c) ((p)[1] == 0 && (p)[0] == c)
+#define LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) \
+ UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0])
+#define LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) \
+ UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[1], (unsigned char)p[0])
+
+#ifdef XML_MIN_SIZE
+
+static
+int little2_byteType(const ENCODING *enc, const char *p)
+{
+ return LITTLE2_BYTE_TYPE(enc, p);
+}
+
+static
+int little2_byteToAscii(const ENCODING *enc, const char *p)
+{
+ return LITTLE2_BYTE_TO_ASCII(enc, p);
+}
+
+static
+int little2_charMatches(const ENCODING *enc, const char *p, int c)
+{
+ return LITTLE2_CHAR_MATCHES(enc, p, c);
+}
+
+static
+int little2_isNameMin(const ENCODING *enc, const char *p)
+{
+ return LITTLE2_IS_NAME_CHAR_MINBPC(enc, p);
+}
+
+static
+int little2_isNmstrtMin(const ENCODING *enc, const char *p)
+{
+ return LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p);
+}
+
+#undef VTABLE
+#define VTABLE VTABLE1, little2_toUtf8, little2_toUtf16
+
+#else /* not XML_MIN_SIZE */
+
+#undef PREFIX
+#define PREFIX(ident) little2_ ## ident
+#define MINBPC(enc) 2
+/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */
+#define BYTE_TYPE(enc, p) LITTLE2_BYTE_TYPE(enc, p)
+#define BYTE_TO_ASCII(enc, p) LITTLE2_BYTE_TO_ASCII(enc, p)
+#define CHAR_MATCHES(enc, p, c) LITTLE2_CHAR_MATCHES(enc, p, c)
+#define IS_NAME_CHAR(enc, p, n) 0
+#define IS_NAME_CHAR_MINBPC(enc, p) LITTLE2_IS_NAME_CHAR_MINBPC(enc, p)
+#define IS_NMSTRT_CHAR(enc, p, n) (0)
+#define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p)
+
+#include "xmltok_impl.c"
+
+#undef MINBPC
+#undef BYTE_TYPE
+#undef BYTE_TO_ASCII
+#undef CHAR_MATCHES
+#undef IS_NAME_CHAR
+#undef IS_NAME_CHAR_MINBPC
+#undef IS_NMSTRT_CHAR
+#undef IS_NMSTRT_CHAR_MINBPC
+#undef IS_INVALID_CHAR
+
+#endif /* not XML_MIN_SIZE */
+
+#ifdef XML_NS
+
+static const struct normal_encoding little2_encoding_ns = {
+ { VTABLE, 2, 0,
+#if XML_BYTE_ORDER == 12
+ 1
+#else
+ 0
+#endif
+ },
+ {
+#include "asciitab.h"
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(little2_) EMPTY_VTABLE(little2_)
+};
+
+#endif
+
+static const struct normal_encoding little2_encoding = {
+ { VTABLE, 2, 0,
+#if XML_BYTE_ORDER == 12
+ 1
+#else
+ 0
+#endif
+ },
+ {
+#define BT_COLON BT_NMSTRT
+#include "asciitab.h"
+#undef BT_COLON
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(little2_) EMPTY_VTABLE(little2_)
+};
+
+#if XML_BYTE_ORDER != 21
+
+#ifdef XML_NS
+
+static const struct normal_encoding internal_little2_encoding_ns = {
+ { VTABLE, 2, 0, 1 },
+ {
+#include "iasciitab.h"
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(little2_) EMPTY_VTABLE(little2_)
+};
+
+#endif
+
+static const struct normal_encoding internal_little2_encoding = {
+ { VTABLE, 2, 0, 1 },
+ {
+#define BT_COLON BT_NMSTRT
+#include "iasciitab.h"
+#undef BT_COLON
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(little2_) EMPTY_VTABLE(little2_)
+};
+
+#endif
+
+
+#define BIG2_BYTE_TYPE(enc, p) \
+ ((p)[0] == 0 \
+ ? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \
+ : unicode_byte_type((p)[0], (p)[1]))
+#define BIG2_BYTE_TO_ASCII(enc, p) ((p)[0] == 0 ? (p)[1] : -1)
+#define BIG2_CHAR_MATCHES(enc, p, c) ((p)[0] == 0 && (p)[1] == c)
+#define BIG2_IS_NAME_CHAR_MINBPC(enc, p) \
+ UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1])
+#define BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) \
+ UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[0], (unsigned char)p[1])
+
+#ifdef XML_MIN_SIZE
+
+static
+int big2_byteType(const ENCODING *enc, const char *p)
+{
+ return BIG2_BYTE_TYPE(enc, p);
+}
+
+static
+int big2_byteToAscii(const ENCODING *enc, const char *p)
+{
+ return BIG2_BYTE_TO_ASCII(enc, p);
+}
+
+static
+int big2_charMatches(const ENCODING *enc, const char *p, int c)
+{
+ return BIG2_CHAR_MATCHES(enc, p, c);
+}
+
+static
+int big2_isNameMin(const ENCODING *enc, const char *p)
+{
+ return BIG2_IS_NAME_CHAR_MINBPC(enc, p);
+}
+
+static
+int big2_isNmstrtMin(const ENCODING *enc, const char *p)
+{
+ return BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p);
+}
+
+#undef VTABLE
+#define VTABLE VTABLE1, big2_toUtf8, big2_toUtf16
+
+#else /* not XML_MIN_SIZE */
+
+#undef PREFIX
+#define PREFIX(ident) big2_ ## ident
+#define MINBPC(enc) 2
+/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */
+#define BYTE_TYPE(enc, p) BIG2_BYTE_TYPE(enc, p)
+#define BYTE_TO_ASCII(enc, p) BIG2_BYTE_TO_ASCII(enc, p)
+#define CHAR_MATCHES(enc, p, c) BIG2_CHAR_MATCHES(enc, p, c)
+#define IS_NAME_CHAR(enc, p, n) 0
+#define IS_NAME_CHAR_MINBPC(enc, p) BIG2_IS_NAME_CHAR_MINBPC(enc, p)
+#define IS_NMSTRT_CHAR(enc, p, n) (0)
+#define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p)
+
+#include "xmltok_impl.c"
+
+#undef MINBPC
+#undef BYTE_TYPE
+#undef BYTE_TO_ASCII
+#undef CHAR_MATCHES
+#undef IS_NAME_CHAR
+#undef IS_NAME_CHAR_MINBPC
+#undef IS_NMSTRT_CHAR
+#undef IS_NMSTRT_CHAR_MINBPC
+#undef IS_INVALID_CHAR
+
+#endif /* not XML_MIN_SIZE */
+
+#ifdef XML_NS
+
+static const struct normal_encoding big2_encoding_ns = {
+ { VTABLE, 2, 0,
+#if XML_BYTE_ORDER == 21
+ 1
+#else
+ 0
+#endif
+ },
+ {
+#include "asciitab.h"
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(big2_) EMPTY_VTABLE(big2_)
+};
+
+#endif
+
+static const struct normal_encoding big2_encoding = {
+ { VTABLE, 2, 0,
+#if XML_BYTE_ORDER == 21
+ 1
+#else
+ 0
+#endif
+ },
+ {
+#define BT_COLON BT_NMSTRT
+#include "asciitab.h"
+#undef BT_COLON
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(big2_) EMPTY_VTABLE(big2_)
+};
+
+#if XML_BYTE_ORDER != 12
+
+#ifdef XML_NS
+
+static const struct normal_encoding internal_big2_encoding_ns = {
+ { VTABLE, 2, 0, 1 },
+ {
+#include "iasciitab.h"
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(big2_) EMPTY_VTABLE(big2_)
+};
+
+#endif
+
+static const struct normal_encoding internal_big2_encoding = {
+ { VTABLE, 2, 0, 1 },
+ {
+#define BT_COLON BT_NMSTRT
+#include "iasciitab.h"
+#undef BT_COLON
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(big2_) EMPTY_VTABLE(big2_)
+};
+
+#endif
+
+#undef PREFIX
+
+static
+int streqci(const char *s1, const char *s2)
+{
+ for (;;) {
+ char c1 = *s1++;
+ char c2 = *s2++;
+ if (ASCII_a <= c1 && c1 <= ASCII_z)
+ c1 += ASCII_A - ASCII_a;
+ if (ASCII_a <= c2 && c2 <= ASCII_z)
+ c2 += ASCII_A - ASCII_a;
+ if (c1 != c2)
+ return 0;
+ if (!c1)
+ break;
+ }
+ return 1;
+}
+
+static
+void initUpdatePosition(const ENCODING *enc, const char *ptr,
+ const char *end, POSITION *pos)
+{
+ cmExpatUnused(enc);
+ normal_updatePosition(&utf8_encoding.enc, ptr, end, pos);
+}
+
+static
+int toAscii(const ENCODING *enc, const char *ptr, const char *end)
+{
+ char buf[1];
+ char *p = buf;
+ XmlUtf8Convert(enc, &ptr, end, &p, p + 1);
+ if (p == buf)
+ return -1;
+ else
+ return buf[0];
+}
+
+static
+int isSpace(int c)
+{
+ switch (c) {
+ case 0x20:
+ case 0xD:
+ case 0xA:
+ case 0x9:
+ return 1;
+ }
+ return 0;
+}
+
+/* Return 1 if there's just optional white space
+or there's an S followed by name=val. */
+static
+int parsePseudoAttribute(const ENCODING *enc,
+ const char *ptr,
+ const char *end,
+ const char **namePtr,
+ const char **nameEndPtr,
+ const char **valPtr,
+ const char **nextTokPtr)
+{
+ int c;
+ char open;
+ if (ptr == end) {
+ *namePtr = 0;
+ return 1;
+ }
+ if (!isSpace(toAscii(enc, ptr, end))) {
+ *nextTokPtr = ptr;
+ return 0;
+ }
+ do {
+ ptr += enc->minBytesPerChar;
+ } while (isSpace(toAscii(enc, ptr, end)));
+ if (ptr == end) {
+ *namePtr = 0;
+ return 1;
+ }
+ *namePtr = ptr;
+ for (;;) {
+ c = toAscii(enc, ptr, end);
+ if (c == -1) {
+ *nextTokPtr = ptr;
+ return 0;
+ }
+ if (c == ASCII_EQUALS) {
+ *nameEndPtr = ptr;
+ break;
+ }
+ if (isSpace(c)) {
+ *nameEndPtr = ptr;
+ do {
+ ptr += enc->minBytesPerChar;
+ } while (isSpace(c = toAscii(enc, ptr, end)));
+ if (c != ASCII_EQUALS) {
+ *nextTokPtr = ptr;
+ return 0;
+ }
+ break;
+ }
+ ptr += enc->minBytesPerChar;
+ }
+ if (ptr == *namePtr) {
+ *nextTokPtr = ptr;
+ return 0;
+ }
+ ptr += enc->minBytesPerChar;
+ c = toAscii(enc, ptr, end);
+ while (isSpace(c)) {
+ ptr += enc->minBytesPerChar;
+ c = toAscii(enc, ptr, end);
+ }
+ if (c != ASCII_QUOT && c != ASCII_APOS) {
+ *nextTokPtr = ptr;
+ return 0;
+ }
+ open = c;
+ ptr += enc->minBytesPerChar;
+ *valPtr = ptr;
+ for (;; ptr += enc->minBytesPerChar) {
+ c = toAscii(enc, ptr, end);
+ if (c == open)
+ break;
+ if (!(ASCII_a <= c && c <= ASCII_z)
+ && !(ASCII_A <= c && c <= ASCII_Z)
+ && !(ASCII_0 <= c && c <= ASCII_9)
+ && c != ASCII_PERIOD
+ && c != ASCII_MINUS
+ && c != ASCII_UNDERSCORE) {
+ *nextTokPtr = ptr;
+ return 0;
+ }
+ }
+ *nextTokPtr = ptr + enc->minBytesPerChar;
+ return 1;
+}
+
+static const char KW_version[] = {
+ ASCII_v, ASCII_e, ASCII_r, ASCII_s, ASCII_i, ASCII_o, ASCII_n, '\0'
+};
+
+static const char KW_encoding[] = {
+ ASCII_e, ASCII_n, ASCII_c, ASCII_o, ASCII_d, ASCII_i, ASCII_n, ASCII_g, '\0'
+};
+
+static const char KW_standalone[] = {
+ ASCII_s, ASCII_t, ASCII_a, ASCII_n, ASCII_d, ASCII_a, ASCII_l, ASCII_o, ASCII_n, ASCII_e, '\0'
+};
+
+static const char KW_yes[] = {
+ ASCII_y, ASCII_e, ASCII_s, '\0'
+};
+
+static const char KW_no[] = {
+ ASCII_n, ASCII_o, '\0'
+};
+
+static
+int doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
+ const char *,
+ const char *),
+ int isGeneralTextEntity,
+ const ENCODING *enc,
+ const char *ptr,
+ const char *end,
+ const char **badPtr,
+ const char **versionPtr,
+ const char **versionEndPtr,
+ const char **encodingName,
+ const ENCODING **encoding,
+ int *standalone)
+{
+ const char *val = 0;
+ const char *name = 0;
+ const char *nameEnd = 0;
+ ptr += 5 * enc->minBytesPerChar;
+ end -= 2 * enc->minBytesPerChar;
+ if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr) || !name) {
+ *badPtr = ptr;
+ return 0;
+ }
+ if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_version)) {
+ if (!isGeneralTextEntity) {
+ *badPtr = name;
+ return 0;
+ }
+ }
+ else {
+ if (versionPtr)
+ *versionPtr = val;
+ if (versionEndPtr)
+ *versionEndPtr = ptr;
+ if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) {
+ *badPtr = ptr;
+ return 0;
+ }
+ if (!name) {
+ if (isGeneralTextEntity) {
+ /* a TextDecl must have an EncodingDecl */
+ *badPtr = ptr;
+ return 0;
+ }
+ return 1;
+ }
+ }
+ if (XmlNameMatchesAscii(enc, name, nameEnd, KW_encoding)) {
+ int c = toAscii(enc, val, end);
+ if (!(ASCII_a <= c && c <= ASCII_z) && !(ASCII_A <= c && c <= ASCII_Z)) {
+ *badPtr = val;
+ return 0;
+ }
+ if (encodingName)
+ *encodingName = val;
+ if (encoding)
+ *encoding = encodingFinder(enc, val, ptr - enc->minBytesPerChar);
+ if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) {
+ *badPtr = ptr;
+ return 0;
+ }
+ if (!name)
+ return 1;
+ }
+ if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_standalone) || isGeneralTextEntity) {
+ *badPtr = name;
+ return 0;
+ }
+ if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_yes)) {
+ if (standalone)
+ *standalone = 1;
+ }
+ else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_no)) {
+ if (standalone)
+ *standalone = 0;
+ }
+ else {
+ *badPtr = val;
+ return 0;
+ }
+ while (isSpace(toAscii(enc, ptr, end)))
+ ptr += enc->minBytesPerChar;
+ if (ptr != end) {
+ *badPtr = ptr;
+ return 0;
+ }
+ return 1;
+}
+
+static
+int checkCharRefNumber(int result)
+{
+ switch (result >> 8) {
+ case 0xD8: case 0xD9: case 0xDA: case 0xDB:
+ case 0xDC: case 0xDD: case 0xDE: case 0xDF:
+ return -1;
+ case 0:
+ if (latin1_encoding.type[result] == BT_NONXML)
+ return -1;
+ break;
+ case 0xFF:
+ if (result == 0xFFFE || result == 0xFFFF)
+ return -1;
+ break;
+ }
+ return result;
+}
+
+int XmlUtf8Encode(int c, char *buf)
+{
+ enum {
+ /* minN is minimum legal resulting value for N byte sequence */
+ min2 = 0x80,
+ min3 = 0x800,
+ min4 = 0x10000
+ };
+
+ if (c < 0)
+ return 0;
+ if (c < min2) {
+ buf[0] = (c | UTF8_cval1);
+ return 1;
+ }
+ if (c < min3) {
+ buf[0] = ((c >> 6) | UTF8_cval2);
+ buf[1] = ((c & 0x3f) | 0x80);
+ return 2;
+ }
+ if (c < min4) {
+ buf[0] = ((c >> 12) | UTF8_cval3);
+ buf[1] = (((c >> 6) & 0x3f) | 0x80);
+ buf[2] = ((c & 0x3f) | 0x80);
+ return 3;
+ }
+ if (c < 0x110000) {
+ buf[0] = ((c >> 18) | UTF8_cval4);
+ buf[1] = (((c >> 12) & 0x3f) | 0x80);
+ buf[2] = (((c >> 6) & 0x3f) | 0x80);
+ buf[3] = ((c & 0x3f) | 0x80);
+ return 4;
+ }
+ return 0;
+}
+
+int XmlUtf16Encode(int charNum, unsigned short *buf)
+{
+ if (charNum < 0)
+ return 0;
+ if (charNum < 0x10000) {
+ buf[0] = charNum;
+ return 1;
+ }
+ if (charNum < 0x110000) {
+ charNum -= 0x10000;
+ buf[0] = (charNum >> 10) + 0xD800;
+ buf[1] = (charNum & 0x3FF) + 0xDC00;
+ return 2;
+ }
+ return 0;
+}
+
+struct unknown_encoding {
+ struct normal_encoding normal;
+ int (*convert)(void *userData, const char *p);
+ void *userData;
+ unsigned short utf16[256];
+ char utf8[256][4];
+};
+
+int XmlSizeOfUnknownEncoding(void)
+{
+ return sizeof(struct unknown_encoding);
+}
+
+static
+int unknown_isName(const ENCODING *enc, const char *p)
+{
+ int c = ((const struct unknown_encoding *)enc)
+ ->convert(((const struct unknown_encoding *)enc)->userData, p);
+ if (c & ~0xFFFF)
+ return 0;
+ return UCS2_GET_NAMING(namePages, c >> 8, c & 0xFF);
+}
+
+static
+int unknown_isNmstrt(const ENCODING *enc, const char *p)
+{
+ int c = ((const struct unknown_encoding *)enc)
+ ->convert(((const struct unknown_encoding *)enc)->userData, p);
+ if (c & ~0xFFFF)
+ return 0;
+ return UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xFF);
+}
+
+static
+int unknown_isInvalid(const ENCODING *enc, const char *p)
+{
+ int c = ((const struct unknown_encoding *)enc)
+ ->convert(((const struct unknown_encoding *)enc)->userData, p);
+ return (c & ~0xFFFF) || checkCharRefNumber(c) < 0;
+}
+
+static
+void unknown_toUtf8(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ char **toP, const char *toLim)
+{
+ char buf[XML_UTF8_ENCODE_MAX];
+ for (;;) {
+ const char *utf8;
+ int n;
+ if (*fromP == fromLim)
+ break;
+ utf8 = ((const struct unknown_encoding *)enc)->utf8[(unsigned char)**fromP];
+ n = *utf8++;
+ if (n == 0) {
+ int c = ((const struct unknown_encoding *)enc)
+ ->convert(((const struct unknown_encoding *)enc)->userData, *fromP);
+ n = XmlUtf8Encode(c, buf);
+ if (n > toLim - *toP)
+ break;
+ utf8 = buf;
+ *fromP += ((const struct normal_encoding *)enc)->type[(unsigned char)**fromP]
+ - (BT_LEAD2 - 2);
+ }
+ else {
+ if (n > toLim - *toP)
+ break;
+ (*fromP)++;
+ }
+ do {
+ *(*toP)++ = *utf8++;
+ } while (--n != 0);
+ }
+}
+
+static
+void unknown_toUtf16(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ unsigned short **toP, const unsigned short *toLim)
+{
+ while (*fromP != fromLim && *toP != toLim) {
+ unsigned short c
+ = ((const struct unknown_encoding *)enc)->utf16[(unsigned char)**fromP];
+ if (c == 0) {
+ c = (unsigned short)((const struct unknown_encoding *)enc)
+ ->convert(((const struct unknown_encoding *)enc)->userData, *fromP);
+ *fromP += ((const struct normal_encoding *)enc)->type[(unsigned char)**fromP]
+ - (BT_LEAD2 - 2);
+ }
+ else
+ (*fromP)++;
+ *(*toP)++ = c;
+ }
+}
+
+ENCODING *
+XmlInitUnknownEncoding(void *mem,
+ int *table,
+ int (*convert)(void *userData, const char *p),
+ void *userData)
+{
+ int i;
+ struct unknown_encoding *e = mem;
+ for (i = 0; i < (int)sizeof(struct normal_encoding); i++)
+ ((char *)mem)[i] = ((char *)&latin1_encoding)[i];
+ for (i = 0; i < 128; i++)
+ if (latin1_encoding.type[i] != BT_OTHER
+ && latin1_encoding.type[i] != BT_NONXML
+ && table[i] != i)
+ return 0;
+ for (i = 0; i < 256; i++) {
+ int c = table[i];
+ if (c == -1) {
+ e->normal.type[i] = BT_MALFORM;
+ /* This shouldn't really get used. */
+ e->utf16[i] = 0xFFFF;
+ e->utf8[i][0] = 1;
+ e->utf8[i][1] = 0;
+ }
+ else if (c < 0) {
+ if (c < -4)
+ return 0;
+ e->normal.type[i] = BT_LEAD2 - (c + 2);
+ e->utf8[i][0] = 0;
+ e->utf16[i] = 0;
+ }
+ else if (c < 0x80) {
+ if (latin1_encoding.type[c] != BT_OTHER
+ && latin1_encoding.type[c] != BT_NONXML
+ && c != i)
+ return 0;
+ e->normal.type[i] = latin1_encoding.type[c];
+ e->utf8[i][0] = 1;
+ e->utf8[i][1] = (char)c;
+ e->utf16[i] = c == 0 ? 0xFFFF : c;
+ }
+ else if (checkCharRefNumber(c) < 0) {
+ e->normal.type[i] = BT_NONXML;
+ /* This shouldn't really get used. */
+ e->utf16[i] = 0xFFFF;
+ e->utf8[i][0] = 1;
+ e->utf8[i][1] = 0;
+ }
+ else {
+ if (c > 0xFFFF)
+ return 0;
+ if (UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xff))
+ e->normal.type[i] = BT_NMSTRT;
+ else if (UCS2_GET_NAMING(namePages, c >> 8, c & 0xff))
+ e->normal.type[i] = BT_NAME;
+ else
+ e->normal.type[i] = BT_OTHER;
+ e->utf8[i][0] = (char)XmlUtf8Encode(c, e->utf8[i] + 1);
+ e->utf16[i] = c;
+ }
+ }
+ e->userData = userData;
+ e->convert = convert;
+ if (convert) {
+ e->normal.isName2 = unknown_isName;
+ e->normal.isName3 = unknown_isName;
+ e->normal.isName4 = unknown_isName;
+ e->normal.isNmstrt2 = unknown_isNmstrt;
+ e->normal.isNmstrt3 = unknown_isNmstrt;
+ e->normal.isNmstrt4 = unknown_isNmstrt;
+ e->normal.isInvalid2 = unknown_isInvalid;
+ e->normal.isInvalid3 = unknown_isInvalid;
+ e->normal.isInvalid4 = unknown_isInvalid;
+ }
+ e->normal.enc.utf8Convert = unknown_toUtf8;
+ e->normal.enc.utf16Convert = unknown_toUtf16;
+ return &(e->normal.enc);
+}
+
+/* If this enumeration is changed, getEncodingIndex and encodings
+must also be changed. */
+enum {
+ UNKNOWN_ENC = -1,
+ ISO_8859_1_ENC = 0,
+ US_ASCII_ENC,
+ UTF_8_ENC,
+ UTF_16_ENC,
+ UTF_16BE_ENC,
+ UTF_16LE_ENC,
+ /* must match encodingNames up to here */
+ NO_ENC
+};
+
+static const char KW_ISO_8859_1[] = {
+ ASCII_I, ASCII_S, ASCII_O, ASCII_MINUS, ASCII_8, ASCII_8, ASCII_5, ASCII_9, ASCII_MINUS, ASCII_1, '\0'
+};
+static const char KW_US_ASCII[] = {
+ ASCII_U, ASCII_S, ASCII_MINUS, ASCII_A, ASCII_S, ASCII_C, ASCII_I, ASCII_I, '\0'
+};
+static const char KW_UTF_8[] = {
+ ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_8, '\0'
+};
+static const char KW_UTF_16[] = {
+ ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, '\0'
+};
+static const char KW_UTF_16BE[] = {
+ ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_B, ASCII_E, '\0'
+};
+static const char KW_UTF_16LE[] = {
+ ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_L, ASCII_E, '\0'
+};
+
+static
+int getEncodingIndex(const char *name)
+{
+ static const char *encodingNames[] = {
+ KW_ISO_8859_1,
+ KW_US_ASCII,
+ KW_UTF_8,
+ KW_UTF_16,
+ KW_UTF_16BE,
+ KW_UTF_16LE,
+ };
+ int i;
+ if (name == 0)
+ return NO_ENC;
+ for (i = 0; i < (int)(sizeof(encodingNames)/sizeof(encodingNames[0])); i++)
+ if (streqci(name, encodingNames[i]))
+ return i;
+ return UNKNOWN_ENC;
+}
+
+/* For binary compatibility, we store the index of the encoding specified
+at initialization in the isUtf16 member. */
+
+#define INIT_ENC_INDEX(enc) ((int)(enc)->initEnc.isUtf16)
+#define SET_INIT_ENC_INDEX(enc, i) ((enc)->initEnc.isUtf16 = (char)i)
+
+/* This is what detects the encoding.
+encodingTable maps from encoding indices to encodings;
+INIT_ENC_INDEX(enc) is the index of the external (protocol) specified encoding;
+state is XML_CONTENT_STATE if we're parsing an external text entity,
+and XML_PROLOG_STATE otherwise.
+*/
+
+
+static
+int initScan(const ENCODING **encodingTable,
+ const INIT_ENCODING *enc,
+ int state,
+ const char *ptr,
+ const char *end,
+ const char **nextTokPtr)
+{
+ const ENCODING **encPtr;
+
+ if (ptr == end)
+ return XML_TOK_NONE;
+ encPtr = enc->encPtr;
+ if (ptr + 1 == end) {
+ /* only a single byte available for auto-detection */
+#ifndef XML_DTD /* FIXME */
+ /* a well-formed document entity must have more than one byte */
+ if (state != XML_CONTENT_STATE)
+ return XML_TOK_PARTIAL;
+#endif
+ /* so we're parsing an external text entity... */
+ /* if UTF-16 was externally specified, then we need at least 2 bytes */
+ switch (INIT_ENC_INDEX(enc)) {
+ case UTF_16_ENC:
+ case UTF_16LE_ENC:
+ case UTF_16BE_ENC:
+ return XML_TOK_PARTIAL;
+ }
+ switch ((unsigned char)*ptr) {
+ case 0xFE:
+ case 0xFF:
+ case 0xEF: /* possibly first byte of UTF-8 BOM */
+ if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
+ && state == XML_CONTENT_STATE)
+ break;
+ /* fall through */
+ case 0x00:
+ case 0x3C:
+ return XML_TOK_PARTIAL;
+ }
+ }
+ else {
+ switch (((unsigned char)ptr[0] << 8) | (unsigned char)ptr[1]) {
+ case 0xFEFF:
+ if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
+ && state == XML_CONTENT_STATE)
+ break;
+ *nextTokPtr = ptr + 2;
+ *encPtr = encodingTable[UTF_16BE_ENC];
+ return XML_TOK_BOM;
+ /* 00 3C is handled in the default case */
+ case 0x3C00:
+ if ((INIT_ENC_INDEX(enc) == UTF_16BE_ENC
+ || INIT_ENC_INDEX(enc) == UTF_16_ENC)
+ && state == XML_CONTENT_STATE)
+ break;
+ *encPtr = encodingTable[UTF_16LE_ENC];
+ return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
+ case 0xFFFE:
+ if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
+ && state == XML_CONTENT_STATE)
+ break;
+ *nextTokPtr = ptr + 2;
+ *encPtr = encodingTable[UTF_16LE_ENC];
+ return XML_TOK_BOM;
+ case 0xEFBB:
+ /* Maybe a UTF-8 BOM (EF BB BF) */
+ /* If there's an explicitly specified (external) encoding
+ of ISO-8859-1 or some flavour of UTF-16
+ and this is an external text entity,
+ don't look for the BOM,
+ because it might be a legal data. */
+ if (state == XML_CONTENT_STATE) {
+ int e = INIT_ENC_INDEX(enc);
+ if (e == ISO_8859_1_ENC || e == UTF_16BE_ENC || e == UTF_16LE_ENC || e == UTF_16_ENC)
+ break;
+ }
+ if (ptr + 2 == end)
+ return XML_TOK_PARTIAL;
+ if ((unsigned char)ptr[2] == 0xBF) {
+ *nextTokPtr = ptr + 3;
+ *encPtr = encodingTable[UTF_8_ENC];
+ return XML_TOK_BOM;
+ }
+ break;
+ default:
+ if (ptr[0] == '\0') {
+ /* 0 isn't a legal data character. Furthermore a document entity can only
+ start with ASCII characters. So the only way this can fail to be big-endian
+ UTF-16 if it it's an external parsed general entity that's labelled as
+ UTF-16LE. */
+ if (state == XML_CONTENT_STATE && INIT_ENC_INDEX(enc) == UTF_16LE_ENC)
+ break;
+ *encPtr = encodingTable[UTF_16BE_ENC];
+ return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
+ }
+ else if (ptr[1] == '\0') {
+ /* We could recover here in the case:
+ - parsing an external entity
+ - second byte is 0
+ - no externally specified encoding
+ - no encoding declaration
+ by assuming UTF-16LE. But we don't, because this would mean when
+ presented just with a single byte, we couldn't reliably determine
+ whether we needed further bytes. */
+ if (state == XML_CONTENT_STATE)
+ break;
+ *encPtr = encodingTable[UTF_16LE_ENC];
+ return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
+ }
+ break;
+ }
+ }
+ *encPtr = encodingTable[INIT_ENC_INDEX(enc)];
+ return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
+}
+
+
+#define NS(x) x
+#define ns(x) x
+#include "xmltok_ns.c"
+#undef NS
+#undef ns
+
+#ifdef XML_NS
+
+#define NS(x) x ## NS
+#define ns(x) x ## _ns
+
+#include "xmltok_ns.c"
+
+#undef NS
+#undef ns
+
+ENCODING *
+XmlInitUnknownEncodingNS(void *mem,
+ int *table,
+ int (*convert)(void *userData, const char *p),
+ void *userData)
+{
+ ENCODING *enc = XmlInitUnknownEncoding(mem, table, convert, userData);
+ if (enc)
+ ((struct normal_encoding *)enc)->type[ASCII_COLON] = BT_COLON;
+ return enc;
+}
+
+#endif /* XML_NS */
diff --git a/Utilities/cmexpat/xmltok.h b/Utilities/cmexpat/xmltok.h
new file mode 100644
index 0000000000..cdf49b2cba
--- /dev/null
+++ b/Utilities/cmexpat/xmltok.h
@@ -0,0 +1,299 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+#ifndef XmlTok_INCLUDED
+#define XmlTok_INCLUDED 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* The following token may be returned by XmlContentTok */
+#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be start of
+ illegal ]]> sequence */
+/* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
+#define XML_TOK_NONE -4 /* The string to be scanned is empty */
+#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan;
+ might be part of CRLF sequence */
+#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */
+#define XML_TOK_PARTIAL -1 /* only part of a token */
+#define XML_TOK_INVALID 0
+
+/* The following tokens are returned by XmlContentTok; some are also
+ returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok */
+
+#define XML_TOK_START_TAG_WITH_ATTS 1
+#define XML_TOK_START_TAG_NO_ATTS 2
+#define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */
+#define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4
+#define XML_TOK_END_TAG 5
+#define XML_TOK_DATA_CHARS 6
+#define XML_TOK_DATA_NEWLINE 7
+#define XML_TOK_CDATA_SECT_OPEN 8
+#define XML_TOK_ENTITY_REF 9
+#define XML_TOK_CHAR_REF 10 /* numeric character reference */
+
+/* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
+#define XML_TOK_PI 11 /* processing instruction */
+#define XML_TOK_XML_DECL 12 /* XML decl or text decl */
+#define XML_TOK_COMMENT 13
+#define XML_TOK_BOM 14 /* Byte order mark */
+
+/* The following tokens are returned only by XmlPrologTok */
+#define XML_TOK_PROLOG_S 15
+#define XML_TOK_DECL_OPEN 16 /* <!foo */
+#define XML_TOK_DECL_CLOSE 17 /* > */
+#define XML_TOK_NAME 18
+#define XML_TOK_NMTOKEN 19
+#define XML_TOK_POUND_NAME 20 /* #name */
+#define XML_TOK_OR 21 /* | */
+#define XML_TOK_PERCENT 22
+#define XML_TOK_OPEN_PAREN 23
+#define XML_TOK_CLOSE_PAREN 24
+#define XML_TOK_OPEN_BRACKET 25
+#define XML_TOK_CLOSE_BRACKET 26
+#define XML_TOK_LITERAL 27
+#define XML_TOK_PARAM_ENTITY_REF 28
+#define XML_TOK_INSTANCE_START 29
+
+/* The following occur only in element type declarations */
+#define XML_TOK_NAME_QUESTION 30 /* name? */
+#define XML_TOK_NAME_ASTERISK 31 /* name* */
+#define XML_TOK_NAME_PLUS 32 /* name+ */
+#define XML_TOK_COND_SECT_OPEN 33 /* <![ */
+#define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */
+#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */
+#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */
+#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */
+#define XML_TOK_COMMA 38
+
+/* The following token is returned only by XmlAttributeValueTok */
+#define XML_TOK_ATTRIBUTE_VALUE_S 39
+
+/* The following token is returned only by XmlCdataSectionTok */
+#define XML_TOK_CDATA_SECT_CLOSE 40
+
+/* With namespace processing this is returned by XmlPrologTok
+ for a name with a colon. */
+#define XML_TOK_PREFIXED_NAME 41
+
+#ifdef XML_DTD
+#define XML_TOK_IGNORE_SECT 42
+#endif /* XML_DTD */
+
+#ifdef XML_DTD
+#define XML_N_STATES 4
+#else /* not XML_DTD */
+#define XML_N_STATES 3
+#endif /* not XML_DTD */
+
+#define XML_PROLOG_STATE 0
+#define XML_CONTENT_STATE 1
+#define XML_CDATA_SECTION_STATE 2
+#ifdef XML_DTD
+#define XML_IGNORE_SECTION_STATE 3
+#endif /* XML_DTD */
+
+#define XML_N_LITERAL_TYPES 2
+#define XML_ATTRIBUTE_VALUE_LITERAL 0
+#define XML_ENTITY_VALUE_LITERAL 1
+
+/* The size of the buffer passed to XmlUtf8Encode must be at least this. */
+#define XML_UTF8_ENCODE_MAX 4
+/* The size of the buffer passed to XmlUtf16Encode must be at least this. */
+#define XML_UTF16_ENCODE_MAX 2
+
+typedef struct position {
+ /* first line and first column are 0 not 1 */
+ unsigned long lineNumber;
+ unsigned long columnNumber;
+} POSITION;
+
+typedef struct {
+ const char *name;
+ const char *valuePtr;
+ const char *valueEnd;
+ char normalized;
+} ATTRIBUTE;
+
+struct encoding;
+typedef struct encoding ENCODING;
+
+struct encoding {
+ int (*scanners[XML_N_STATES])(const ENCODING *,
+ const char *,
+ const char *,
+ const char **);
+ int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
+ const char *,
+ const char *,
+ const char **);
+ int (*sameName)(const ENCODING *,
+ const char *, const char *);
+ int (*nameMatchesAscii)(const ENCODING *,
+ const char *, const char *, const char *);
+ int (*nameLength)(const ENCODING *, const char *);
+ const char *(*skipS)(const ENCODING *, const char *);
+ int (*getAtts)(const ENCODING *enc, const char *ptr,
+ int attsMax, ATTRIBUTE *atts);
+ int (*charRefNumber)(const ENCODING *enc, const char *ptr);
+ int (*predefinedEntityName)(const ENCODING *, const char *, const char *);
+ void (*updatePosition)(const ENCODING *,
+ const char *ptr,
+ const char *end,
+ POSITION *);
+ int (*isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **badPtr);
+ void (*utf8Convert)(const ENCODING *enc,
+ const char **fromP,
+ const char *fromLim,
+ char **toP,
+ const char *toLim);
+ void (*utf16Convert)(const ENCODING *enc,
+ const char **fromP,
+ const char *fromLim,
+ unsigned short **toP,
+ const unsigned short *toLim);
+ int minBytesPerChar;
+ char isUtf8;
+ char isUtf16;
+};
+
+/*
+Scan the string starting at ptr until the end of the next complete token,
+but do not scan past eptr. Return an integer giving the type of token.
+
+Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set.
+
+Return XML_TOK_PARTIAL when the string does not contain a complete token;
+nextTokPtr will not be set.
+
+Return XML_TOK_INVALID when the string does not start a valid token; nextTokPtr
+will be set to point to the character which made the token invalid.
+
+Otherwise the string starts with a valid token; nextTokPtr will be set to point
+to the character following the end of that token.
+
+Each data character counts as a single token, but adjacent data characters
+may be returned together. Similarly for characters in the prolog outside
+literals, comments and processing instructions.
+*/
+
+
+#define XmlTok(enc, state, ptr, end, nextTokPtr) \
+ (((enc)->scanners[state])(enc, ptr, end, nextTokPtr))
+
+#define XmlPrologTok(enc, ptr, end, nextTokPtr) \
+ XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr)
+
+#define XmlContentTok(enc, ptr, end, nextTokPtr) \
+ XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr)
+
+#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
+ XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
+
+#ifdef XML_DTD
+
+#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \
+ XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr)
+
+#endif /* XML_DTD */
+
+/* This is used for performing a 2nd-level tokenization on
+the content of a literal that has already been returned by XmlTok. */
+
+#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \
+ (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr))
+
+#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \
+ XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr)
+
+#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
+ XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
+
+#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
+
+#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \
+ (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2))
+
+#define XmlNameLength(enc, ptr) \
+ (((enc)->nameLength)(enc, ptr))
+
+#define XmlSkipS(enc, ptr) \
+ (((enc)->skipS)(enc, ptr))
+
+#define XmlGetAttributes(enc, ptr, attsMax, atts) \
+ (((enc)->getAtts)(enc, ptr, attsMax, atts))
+
+#define XmlCharRefNumber(enc, ptr) \
+ (((enc)->charRefNumber)(enc, ptr))
+
+#define XmlPredefinedEntityName(enc, ptr, end) \
+ (((enc)->predefinedEntityName)(enc, ptr, end))
+
+#define XmlUpdatePosition(enc, ptr, end, pos) \
+ (((enc)->updatePosition)(enc, ptr, end, pos))
+
+#define XmlIsPublicId(enc, ptr, end, badPtr) \
+ (((enc)->isPublicId)(enc, ptr, end, badPtr))
+
+#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
+ (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
+
+#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
+ (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
+
+typedef struct {
+ ENCODING initEnc;
+ const ENCODING **encPtr;
+} INIT_ENCODING;
+
+int XmlParseXmlDecl(int isGeneralTextEntity,
+ const ENCODING *enc,
+ const char *ptr,
+ const char *end,
+ const char **badPtr,
+ const char **versionPtr,
+ const char **versionEndPtr,
+ const char **encodingNamePtr,
+ const ENCODING **namedEncodingPtr,
+ int *standalonePtr);
+
+int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
+const ENCODING *XmlGetUtf8InternalEncoding(void);
+const ENCODING *XmlGetUtf16InternalEncoding(void);
+int XmlUtf8Encode(int charNumber, char *buf);
+int XmlUtf16Encode(int charNumber, unsigned short *buf);
+
+int XmlSizeOfUnknownEncoding(void);
+ENCODING *
+XmlInitUnknownEncoding(void *mem,
+ int *table,
+ int (*conv)(void *userData, const char *p),
+ void *userData);
+
+int XmlParseXmlDeclNS(int isGeneralTextEntity,
+ const ENCODING *enc,
+ const char *ptr,
+ const char *end,
+ const char **badPtr,
+ const char **versionPtr,
+ const char **versionEndPtr,
+ const char **encodingNamePtr,
+ const ENCODING **namedEncodingPtr,
+ int *standalonePtr);
+int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name);
+const ENCODING *XmlGetUtf8InternalEncodingNS(void);
+const ENCODING *XmlGetUtf16InternalEncodingNS(void);
+ENCODING *
+XmlInitUnknownEncodingNS(void *mem,
+ int *table,
+ int (*conv)(void *userData, const char *p),
+ void *userData);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* not XmlTok_INCLUDED */
diff --git a/Utilities/cmexpat/xmltok_impl.c b/Utilities/cmexpat/xmltok_impl.c
new file mode 100644
index 0000000000..6e0be95515
--- /dev/null
+++ b/Utilities/cmexpat/xmltok_impl.c
@@ -0,0 +1,1775 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+#ifndef IS_INVALID_CHAR
+#define IS_INVALID_CHAR(enc, ptr, n) (0)
+#endif
+
+#ifndef INVALID_LEAD_CASE
+#define INVALID_LEAD_CASE(n, ptr, nextTokPtr) \
+ case BT_LEAD ## n: \
+ if (end - ptr < n) \
+ return XML_TOK_PARTIAL_CHAR; \
+ if (IS_INVALID_CHAR(enc, ptr, n)) { \
+ *(nextTokPtr) = (ptr); \
+ return XML_TOK_INVALID; \
+ } \
+ ptr += n; \
+ break;
+#endif
+
+#define INVALID_CASES(ptr, nextTokPtr) \
+ INVALID_LEAD_CASE(2, ptr, nextTokPtr) \
+ INVALID_LEAD_CASE(3, ptr, nextTokPtr) \
+ INVALID_LEAD_CASE(4, ptr, nextTokPtr) \
+ case BT_NONXML: \
+ case BT_MALFORM: \
+ case BT_TRAIL: \
+ *(nextTokPtr) = (ptr); \
+ return XML_TOK_INVALID;
+
+#define CHECK_NAME_CASE(n, enc, ptr, end, nextTokPtr) \
+ case BT_LEAD ## n: \
+ if (end - ptr < n) \
+ return XML_TOK_PARTIAL_CHAR; \
+ if (!IS_NAME_CHAR(enc, ptr, n)) { \
+ *nextTokPtr = ptr; \
+ return XML_TOK_INVALID; \
+ } \
+ ptr += n; \
+ break;
+
+#define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) \
+ case BT_NONASCII: \
+ if (!IS_NAME_CHAR_MINBPC(enc, ptr)) { \
+ *nextTokPtr = ptr; \
+ return XML_TOK_INVALID; \
+ } \
+ case BT_NMSTRT: \
+ case BT_HEX: \
+ case BT_DIGIT: \
+ case BT_NAME: \
+ case BT_MINUS: \
+ ptr += MINBPC(enc); \
+ break; \
+ CHECK_NAME_CASE(2, enc, ptr, end, nextTokPtr) \
+ CHECK_NAME_CASE(3, enc, ptr, end, nextTokPtr) \
+ CHECK_NAME_CASE(4, enc, ptr, end, nextTokPtr)
+
+#define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr) \
+ case BT_LEAD ## n: \
+ if (end - ptr < n) \
+ return XML_TOK_PARTIAL_CHAR; \
+ if (!IS_NMSTRT_CHAR(enc, ptr, n)) { \
+ *nextTokPtr = ptr; \
+ return XML_TOK_INVALID; \
+ } \
+ ptr += n; \
+ break;
+
+#define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) \
+ case BT_NONASCII: \
+ if (!IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { \
+ *nextTokPtr = ptr; \
+ return XML_TOK_INVALID; \
+ } \
+ case BT_NMSTRT: \
+ case BT_HEX: \
+ ptr += MINBPC(enc); \
+ break; \
+ CHECK_NMSTRT_CASE(2, enc, ptr, end, nextTokPtr) \
+ CHECK_NMSTRT_CASE(3, enc, ptr, end, nextTokPtr) \
+ CHECK_NMSTRT_CASE(4, enc, ptr, end, nextTokPtr)
+
+#ifndef PREFIX
+#define PREFIX(ident) ident
+#endif
+
+/* ptr points to character following "<!-" */
+
+static
+int PREFIX(scanComment)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr != end) {
+ if (!CHAR_MATCHES(enc, ptr, ASCII_MINUS)) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ ptr += MINBPC(enc);
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ INVALID_CASES(ptr, nextTokPtr)
+ case BT_MINUS:
+ if ((ptr += MINBPC(enc)) == end)
+ return XML_TOK_PARTIAL;
+ if (CHAR_MATCHES(enc, ptr, ASCII_MINUS)) {
+ if ((ptr += MINBPC(enc)) == end)
+ return XML_TOK_PARTIAL;
+ if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_COMMENT;
+ }
+ break;
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+/* ptr points to character following "<!" */
+
+static
+int PREFIX(scanDecl)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_MINUS:
+ return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_LSQB:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_COND_SECT_OPEN;
+ case BT_NMSTRT:
+ case BT_HEX:
+ ptr += MINBPC(enc);
+ break;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_PERCNT:
+ if (ptr + MINBPC(enc) == end)
+ return XML_TOK_PARTIAL;
+ /* don't allow <!ENTITY% foo "whatever"> */
+ switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) {
+ case BT_S: case BT_CR: case BT_LF: case BT_PERCNT:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ /* fall through */
+ case BT_S: case BT_CR: case BT_LF:
+ *nextTokPtr = ptr;
+ return XML_TOK_DECL_OPEN;
+ case BT_NMSTRT:
+ case BT_HEX:
+ ptr += MINBPC(enc);
+ break;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+static
+int PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, const char *end, int *tokPtr)
+{
+ int upper = 0;
+ cmExpatUnused(enc);
+ *tokPtr = XML_TOK_PI;
+ if (end - ptr != MINBPC(enc)*3)
+ return 1;
+ switch (BYTE_TO_ASCII(enc, ptr)) {
+ case ASCII_x:
+ break;
+ case ASCII_X:
+ upper = 1;
+ break;
+ default:
+ return 1;
+ }
+ ptr += MINBPC(enc);
+ switch (BYTE_TO_ASCII(enc, ptr)) {
+ case ASCII_m:
+ break;
+ case ASCII_M:
+ upper = 1;
+ break;
+ default:
+ return 1;
+ }
+ ptr += MINBPC(enc);
+ switch (BYTE_TO_ASCII(enc, ptr)) {
+ case ASCII_l:
+ break;
+ case ASCII_L:
+ upper = 1;
+ break;
+ default:
+ return 1;
+ }
+ if (upper)
+ return 0;
+ *tokPtr = XML_TOK_XML_DECL;
+ return 1;
+}
+
+/* ptr points to character following "<?" */
+
+static
+int PREFIX(scanPi)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ int tok;
+ const char *target = ptr;
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
+ case BT_S: case BT_CR: case BT_LF:
+ if (!PREFIX(checkPiTarget)(enc, target, ptr, &tok)) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ ptr += MINBPC(enc);
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ INVALID_CASES(ptr, nextTokPtr)
+ case BT_QUEST:
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ if (CHAR_MATCHES(enc, ptr, ASCII_GT)) {
+ *nextTokPtr = ptr + MINBPC(enc);
+ return tok;
+ }
+ break;
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ }
+ return XML_TOK_PARTIAL;
+ case BT_QUEST:
+ if (!PREFIX(checkPiTarget)(enc, target, ptr, &tok)) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ if (CHAR_MATCHES(enc, ptr, ASCII_GT)) {
+ *nextTokPtr = ptr + MINBPC(enc);
+ return tok;
+ }
+ /* fall through */
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+
+static
+int PREFIX(scanCdataSection)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ static const char CDATA_LSQB[] = { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, ASCII_LSQB };
+ int i;
+ cmExpatUnused(enc);
+ /* CDATA[ */
+ if (end - ptr < 6 * MINBPC(enc))
+ return XML_TOK_PARTIAL;
+ for (i = 0; i < 6; i++, ptr += MINBPC(enc)) {
+ if (!CHAR_MATCHES(enc, ptr, CDATA_LSQB[i])) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_CDATA_SECT_OPEN;
+}
+
+static
+int PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr == end)
+ return XML_TOK_NONE;
+ if (MINBPC(enc) > 1) {
+ size_t n = end - ptr;
+ if (n & (MINBPC(enc) - 1)) {
+ n &= ~(MINBPC(enc) - 1);
+ if (n == 0)
+ return XML_TOK_PARTIAL;
+ end = ptr + n;
+ }
+ }
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_RSQB:
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB))
+ break;
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) {
+ ptr -= MINBPC(enc);
+ break;
+ }
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_CDATA_SECT_CLOSE;
+ case BT_CR:
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ if (BYTE_TYPE(enc, ptr) == BT_LF)
+ ptr += MINBPC(enc);
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_NEWLINE;
+ case BT_LF:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_DATA_NEWLINE;
+ INVALID_CASES(ptr, nextTokPtr)
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+#define LEAD_CASE(n) \
+ case BT_LEAD ## n: \
+ if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \
+ *nextTokPtr = ptr; \
+ return XML_TOK_DATA_CHARS; \
+ } \
+ ptr += n; \
+ break;
+ LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)
+#undef LEAD_CASE
+ case BT_NONXML:
+ case BT_MALFORM:
+ case BT_TRAIL:
+ case BT_CR:
+ case BT_LF:
+ case BT_RSQB:
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+}
+
+/* ptr points to character following "</" */
+
+static
+int PREFIX(scanEndTag)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
+ case BT_S: case BT_CR: case BT_LF:
+ for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_S: case BT_CR: case BT_LF:
+ break;
+ case BT_GT:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_END_TAG;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return XML_TOK_PARTIAL;
+#ifdef XML_NS
+ case BT_COLON:
+ /* no need to check qname syntax here, since end-tag must match exactly */
+ ptr += MINBPC(enc);
+ break;
+#endif
+ case BT_GT:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_END_TAG;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+/* ptr points to character following "&#X" */
+
+static
+int PREFIX(scanHexCharRef)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_DIGIT:
+ case BT_HEX:
+ break;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_DIGIT:
+ case BT_HEX:
+ break;
+ case BT_SEMI:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_CHAR_REF;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+/* ptr points to character following "&#" */
+
+static
+int PREFIX(scanCharRef)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr != end) {
+ if (CHAR_MATCHES(enc, ptr, ASCII_x))
+ return PREFIX(scanHexCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_DIGIT:
+ break;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_DIGIT:
+ break;
+ case BT_SEMI:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_CHAR_REF;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+/* ptr points to character following "&" */
+
+static
+int PREFIX(scanRef)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ case BT_NUM:
+ return PREFIX(scanCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
+ case BT_SEMI:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_ENTITY_REF;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+/* ptr points to character following first character of attribute name */
+
+static
+int PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+#ifdef XML_NS
+ int hadColon = 0;
+#endif
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
+#ifdef XML_NS
+ case BT_COLON:
+ if (hadColon) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ hadColon = 1;
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ break;
+#endif
+ case BT_S: case BT_CR: case BT_LF:
+ for (;;) {
+ int t;
+
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ t = BYTE_TYPE(enc, ptr);
+ if (t == BT_EQUALS)
+ break;
+ switch (t) {
+ case BT_S:
+ case BT_LF:
+ case BT_CR:
+ break;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ /* fall through */
+ case BT_EQUALS:
+ {
+ int open;
+#ifdef XML_NS
+ hadColon = 0;
+#endif
+ for (;;) {
+
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ open = BYTE_TYPE(enc, ptr);
+ if (open == BT_QUOT || open == BT_APOS)
+ break;
+ switch (open) {
+ case BT_S:
+ case BT_LF:
+ case BT_CR:
+ break;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ ptr += MINBPC(enc);
+ /* in attribute value */
+ for (;;) {
+ int t;
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ t = BYTE_TYPE(enc, ptr);
+ if (t == open)
+ break;
+ switch (t) {
+ INVALID_CASES(ptr, nextTokPtr)
+ case BT_AMP:
+ {
+ int tok = PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, &ptr);
+ if (tok <= 0) {
+ if (tok == XML_TOK_INVALID)
+ *nextTokPtr = ptr;
+ return tok;
+ }
+ break;
+ }
+ case BT_LT:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ }
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_S:
+ case BT_CR:
+ case BT_LF:
+ break;
+ case BT_SOL:
+ goto sol;
+ case BT_GT:
+ goto gt;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ /* ptr points to closing quote */
+ for (;;) {
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ case BT_S: case BT_CR: case BT_LF:
+ continue;
+ case BT_GT:
+ gt:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_START_TAG_WITH_ATTS;
+ case BT_SOL:
+ sol:
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_EMPTY_ELEMENT_WITH_ATTS;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ break;
+ }
+ break;
+ }
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+/* ptr points to character following "<" */
+
+static
+int PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+#ifdef XML_NS
+ int hadColon;
+#endif
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ case BT_EXCL:
+ if ((ptr += MINBPC(enc)) == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_MINUS:
+ return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_LSQB:
+ return PREFIX(scanCdataSection)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ case BT_QUEST:
+ return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_SOL:
+ return PREFIX(scanEndTag)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+#ifdef XML_NS
+ hadColon = 0;
+#endif
+ /* we have a start-tag */
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
+#ifdef XML_NS
+ case BT_COLON:
+ if (hadColon) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ hadColon = 1;
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ break;
+#endif
+ case BT_S: case BT_CR: case BT_LF:
+ {
+ ptr += MINBPC(enc);
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ case BT_GT:
+ goto gt;
+ case BT_SOL:
+ goto sol;
+ case BT_S: case BT_CR: case BT_LF:
+ ptr += MINBPC(enc);
+ continue;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ return PREFIX(scanAtts)(enc, ptr, end, nextTokPtr);
+ }
+ return XML_TOK_PARTIAL;
+ }
+ case BT_GT:
+ gt:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_START_TAG_NO_ATTS;
+ case BT_SOL:
+ sol:
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_EMPTY_ELEMENT_NO_ATTS;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+static
+int PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr == end)
+ return XML_TOK_NONE;
+ if (MINBPC(enc) > 1) {
+ size_t n = end - ptr;
+ if (n & (MINBPC(enc) - 1)) {
+ n &= ~(MINBPC(enc) - 1);
+ if (n == 0)
+ return XML_TOK_PARTIAL;
+ end = ptr + n;
+ }
+ }
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_LT:
+ return PREFIX(scanLt)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_AMP:
+ return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_CR:
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_TRAILING_CR;
+ if (BYTE_TYPE(enc, ptr) == BT_LF)
+ ptr += MINBPC(enc);
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_NEWLINE;
+ case BT_LF:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_DATA_NEWLINE;
+ case BT_RSQB:
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_TRAILING_RSQB;
+ if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB))
+ break;
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_TRAILING_RSQB;
+ if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) {
+ ptr -= MINBPC(enc);
+ break;
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ INVALID_CASES(ptr, nextTokPtr)
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+#define LEAD_CASE(n) \
+ case BT_LEAD ## n: \
+ if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \
+ *nextTokPtr = ptr; \
+ return XML_TOK_DATA_CHARS; \
+ } \
+ ptr += n; \
+ break;
+ LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)
+#undef LEAD_CASE
+ case BT_RSQB:
+ if (ptr + MINBPC(enc) != end) {
+ if (!CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) {
+ ptr += MINBPC(enc);
+ break;
+ }
+ if (ptr + 2*MINBPC(enc) != end) {
+ if (!CHAR_MATCHES(enc, ptr + 2*MINBPC(enc), ASCII_GT)) {
+ ptr += MINBPC(enc);
+ break;
+ }
+ *nextTokPtr = ptr + 2*MINBPC(enc);
+ return XML_TOK_INVALID;
+ }
+ }
+ /* fall through */
+ case BT_AMP:
+ case BT_LT:
+ case BT_NONXML:
+ case BT_MALFORM:
+ case BT_TRAIL:
+ case BT_CR:
+ case BT_LF:
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+}
+
+/* ptr points to character following "%" */
+
+static
+int PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ case BT_S: case BT_LF: case BT_CR: case BT_PERCNT:
+ *nextTokPtr = ptr;
+ return XML_TOK_PERCENT;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
+ case BT_SEMI:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_PARAM_ENTITY_REF;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+static
+int PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
+ case BT_CR: case BT_LF: case BT_S:
+ case BT_RPAR: case BT_GT: case BT_PERCNT: case BT_VERBAR:
+ *nextTokPtr = ptr;
+ return XML_TOK_POUND_NAME;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return -XML_TOK_POUND_NAME;
+}
+
+static
+int PREFIX(scanLit)(int open, const ENCODING *enc,
+ const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ while (ptr != end) {
+ int t = BYTE_TYPE(enc, ptr);
+ switch (t) {
+ INVALID_CASES(ptr, nextTokPtr)
+ case BT_QUOT:
+ case BT_APOS:
+ ptr += MINBPC(enc);
+ if (t != open)
+ break;
+ if (ptr == end)
+ return -XML_TOK_LITERAL;
+ *nextTokPtr = ptr;
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_S: case BT_CR: case BT_LF:
+ case BT_GT: case BT_PERCNT: case BT_LSQB:
+ return XML_TOK_LITERAL;
+ default:
+ return XML_TOK_INVALID;
+ }
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+static
+int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ int tok;
+ if (ptr == end)
+ return XML_TOK_NONE;
+ if (MINBPC(enc) > 1) {
+ size_t n = end - ptr;
+ if (n & (MINBPC(enc) - 1)) {
+ n &= ~(MINBPC(enc) - 1);
+ if (n == 0)
+ return XML_TOK_PARTIAL;
+ end = ptr + n;
+ }
+ }
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_QUOT:
+ return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_APOS:
+ return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_LT:
+ {
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_EXCL:
+ return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_QUEST:
+ return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_NMSTRT:
+ case BT_HEX:
+ case BT_NONASCII:
+ case BT_LEAD2:
+ case BT_LEAD3:
+ case BT_LEAD4:
+ *nextTokPtr = ptr - MINBPC(enc);
+ return XML_TOK_INSTANCE_START;
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ case BT_CR:
+ if (ptr + MINBPC(enc) == end)
+ return -XML_TOK_PROLOG_S;
+ /* fall through */
+ case BT_S: case BT_LF:
+ for (;;) {
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ break;
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_S: case BT_LF:
+ break;
+ case BT_CR:
+ /* don't split CR/LF pair */
+ if (ptr + MINBPC(enc) != end)
+ break;
+ /* fall through */
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_PROLOG_S;
+ }
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_PROLOG_S;
+ case BT_PERCNT:
+ return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ case BT_COMMA:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_COMMA;
+ case BT_LSQB:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_OPEN_BRACKET;
+ case BT_RSQB:
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return -XML_TOK_CLOSE_BRACKET;
+ if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) {
+ if (ptr + MINBPC(enc) == end)
+ return XML_TOK_PARTIAL;
+ if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) {
+ *nextTokPtr = ptr + 2*MINBPC(enc);
+ return XML_TOK_COND_SECT_CLOSE;
+ }
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_CLOSE_BRACKET;
+ case BT_LPAR:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_OPEN_PAREN;
+ case BT_RPAR:
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return -XML_TOK_CLOSE_PAREN;
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_AST:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_CLOSE_PAREN_ASTERISK;
+ case BT_QUEST:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_CLOSE_PAREN_QUESTION;
+ case BT_PLUS:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_CLOSE_PAREN_PLUS;
+ case BT_CR: case BT_LF: case BT_S:
+ case BT_GT: case BT_COMMA: case BT_VERBAR:
+ case BT_RPAR:
+ *nextTokPtr = ptr;
+ return XML_TOK_CLOSE_PAREN;
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ case BT_VERBAR:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_OR;
+ case BT_GT:
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_DECL_CLOSE;
+ case BT_NUM:
+ return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+#define LEAD_CASE(n) \
+ case BT_LEAD ## n: \
+ if (end - ptr < n) \
+ return XML_TOK_PARTIAL_CHAR; \
+ if (IS_NMSTRT_CHAR(enc, ptr, n)) { \
+ ptr += n; \
+ tok = XML_TOK_NAME; \
+ break; \
+ } \
+ if (IS_NAME_CHAR(enc, ptr, n)) { \
+ ptr += n; \
+ tok = XML_TOK_NMTOKEN; \
+ break; \
+ } \
+ *nextTokPtr = ptr; \
+ return XML_TOK_INVALID;
+ LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)
+#undef LEAD_CASE
+ case BT_NMSTRT:
+ case BT_HEX:
+ tok = XML_TOK_NAME;
+ ptr += MINBPC(enc);
+ break;
+ case BT_DIGIT:
+ case BT_NAME:
+ case BT_MINUS:
+#ifdef XML_NS
+ case BT_COLON:
+#endif
+ tok = XML_TOK_NMTOKEN;
+ ptr += MINBPC(enc);
+ break;
+ case BT_NONASCII:
+ if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) {
+ ptr += MINBPC(enc);
+ tok = XML_TOK_NAME;
+ break;
+ }
+ if (IS_NAME_CHAR_MINBPC(enc, ptr)) {
+ ptr += MINBPC(enc);
+ tok = XML_TOK_NMTOKEN;
+ break;
+ }
+ /* fall through */
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
+ case BT_GT: case BT_RPAR: case BT_COMMA:
+ case BT_VERBAR: case BT_LSQB: case BT_PERCNT:
+ case BT_S: case BT_CR: case BT_LF:
+ *nextTokPtr = ptr;
+ return tok;
+#ifdef XML_NS
+ case BT_COLON:
+ ptr += MINBPC(enc);
+ switch (tok) {
+ case XML_TOK_NAME:
+ if (ptr == end)
+ return XML_TOK_PARTIAL;
+ tok = XML_TOK_PREFIXED_NAME;
+ switch (BYTE_TYPE(enc, ptr)) {
+ CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
+ default:
+ tok = XML_TOK_NMTOKEN;
+ break;
+ }
+ break;
+ case XML_TOK_PREFIXED_NAME:
+ tok = XML_TOK_NMTOKEN;
+ break;
+ }
+ break;
+#endif
+ case BT_PLUS:
+ if (tok == XML_TOK_NMTOKEN) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_NAME_PLUS;
+ case BT_AST:
+ if (tok == XML_TOK_NMTOKEN) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_NAME_ASTERISK;
+ case BT_QUEST:
+ if (tok == XML_TOK_NMTOKEN) {
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_NAME_QUESTION;
+ default:
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ }
+ }
+ return -tok;
+}
+
+static
+int PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ const char *start;
+ if (ptr == end)
+ return XML_TOK_NONE;
+ start = ptr;
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+#define LEAD_CASE(n) \
+ case BT_LEAD ## n: ptr += n; break;
+ LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)
+#undef LEAD_CASE
+ case BT_AMP:
+ if (ptr == start)
+ return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ case BT_LT:
+ /* this is for inside entity references */
+ *nextTokPtr = ptr;
+ return XML_TOK_INVALID;
+ case BT_LF:
+ if (ptr == start) {
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_DATA_NEWLINE;
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ case BT_CR:
+ if (ptr == start) {
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_TRAILING_CR;
+ if (BYTE_TYPE(enc, ptr) == BT_LF)
+ ptr += MINBPC(enc);
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_NEWLINE;
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ case BT_S:
+ if (ptr == start) {
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_ATTRIBUTE_VALUE_S;
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+}
+
+static
+int PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ const char *start;
+ if (ptr == end)
+ return XML_TOK_NONE;
+ start = ptr;
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+#define LEAD_CASE(n) \
+ case BT_LEAD ## n: ptr += n; break;
+ LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)
+#undef LEAD_CASE
+ case BT_AMP:
+ if (ptr == start)
+ return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ case BT_PERCNT:
+ if (ptr == start) {
+ int tok = PREFIX(scanPercent)(enc, ptr + MINBPC(enc),
+ end, nextTokPtr);
+ return (tok == XML_TOK_PERCENT) ? XML_TOK_INVALID : tok;
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ case BT_LF:
+ if (ptr == start) {
+ *nextTokPtr = ptr + MINBPC(enc);
+ return XML_TOK_DATA_NEWLINE;
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ case BT_CR:
+ if (ptr == start) {
+ ptr += MINBPC(enc);
+ if (ptr == end)
+ return XML_TOK_TRAILING_CR;
+ if (BYTE_TYPE(enc, ptr) == BT_LF)
+ ptr += MINBPC(enc);
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_NEWLINE;
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ }
+ *nextTokPtr = ptr;
+ return XML_TOK_DATA_CHARS;
+}
+
+#ifdef XML_DTD
+
+static
+int PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ int level = 0;
+ if (MINBPC(enc) > 1) {
+ size_t n = end - ptr;
+ if (n & (MINBPC(enc) - 1)) {
+ n &= ~(MINBPC(enc) - 1);
+ end = ptr + n;
+ }
+ }
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ INVALID_CASES(ptr, nextTokPtr)
+ case BT_LT:
+ if ((ptr += MINBPC(enc)) == end)
+ return XML_TOK_PARTIAL;
+ if (CHAR_MATCHES(enc, ptr, ASCII_EXCL)) {
+ if ((ptr += MINBPC(enc)) == end)
+ return XML_TOK_PARTIAL;
+ if (CHAR_MATCHES(enc, ptr, ASCII_LSQB)) {
+ ++level;
+ ptr += MINBPC(enc);
+ }
+ }
+ break;
+ case BT_RSQB:
+ if ((ptr += MINBPC(enc)) == end)
+ return XML_TOK_PARTIAL;
+ if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) {
+ if ((ptr += MINBPC(enc)) == end)
+ return XML_TOK_PARTIAL;
+ if (CHAR_MATCHES(enc, ptr, ASCII_GT)) {
+ ptr += MINBPC(enc);
+ if (level == 0) {
+ *nextTokPtr = ptr;
+ return XML_TOK_IGNORE_SECT;
+ }
+ --level;
+ }
+ }
+ break;
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ }
+ return XML_TOK_PARTIAL;
+}
+
+#endif /* XML_DTD */
+
+static
+int PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **badPtr)
+{
+ ptr += MINBPC(enc);
+ end -= MINBPC(enc);
+ for (; ptr != end; ptr += MINBPC(enc)) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_DIGIT:
+ case BT_HEX:
+ case BT_MINUS:
+ case BT_APOS:
+ case BT_LPAR:
+ case BT_RPAR:
+ case BT_PLUS:
+ case BT_COMMA:
+ case BT_SOL:
+ case BT_EQUALS:
+ case BT_QUEST:
+ case BT_CR:
+ case BT_LF:
+ case BT_SEMI:
+ case BT_EXCL:
+ case BT_AST:
+ case BT_PERCNT:
+ case BT_NUM:
+#ifdef XML_NS
+ case BT_COLON:
+#endif
+ break;
+ case BT_S:
+ if (CHAR_MATCHES(enc, ptr, ASCII_TAB)) {
+ *badPtr = ptr;
+ return 0;
+ }
+ break;
+ case BT_NAME:
+ case BT_NMSTRT:
+ if (!(BYTE_TO_ASCII(enc, ptr) & ~0x7f))
+ break;
+ default:
+ switch (BYTE_TO_ASCII(enc, ptr)) {
+ case 0x24: /* $ */
+ case 0x40: /* @ */
+ break;
+ default:
+ *badPtr = ptr;
+ return 0;
+ }
+ break;
+ }
+ }
+ return 1;
+}
+
+/* This must only be called for a well-formed start-tag or empty element tag.
+Returns the number of attributes. Pointers to the first attsMax attributes
+are stored in atts. */
+
+static
+int PREFIX(getAtts)(const ENCODING *enc, const char *ptr,
+ int attsMax, ATTRIBUTE *atts)
+{
+ enum { other, inName, inValue } state = inName;
+ int nAtts = 0;
+ int open = 0; /* defined when state == inValue;
+ initialization just to shut up compilers */
+
+ for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) {
+ switch (BYTE_TYPE(enc, ptr)) {
+#define START_NAME \
+ if (state == other) { \
+ if (nAtts < attsMax) { \
+ atts[nAtts].name = ptr; \
+ atts[nAtts].normalized = 1; \
+ } \
+ state = inName; \
+ }
+#define LEAD_CASE(n) \
+ case BT_LEAD ## n: START_NAME ptr += (n - MINBPC(enc)); break;
+ LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)
+#undef LEAD_CASE
+ case BT_NONASCII:
+ case BT_NMSTRT:
+ case BT_HEX:
+ START_NAME
+ break;
+#undef START_NAME
+ case BT_QUOT:
+ if (state != inValue) {
+ if (nAtts < attsMax)
+ atts[nAtts].valuePtr = ptr + MINBPC(enc);
+ state = inValue;
+ open = BT_QUOT;
+ }
+ else if (open == BT_QUOT) {
+ state = other;
+ if (nAtts < attsMax)
+ atts[nAtts].valueEnd = ptr;
+ nAtts++;
+ }
+ break;
+ case BT_APOS:
+ if (state != inValue) {
+ if (nAtts < attsMax)
+ atts[nAtts].valuePtr = ptr + MINBPC(enc);
+ state = inValue;
+ open = BT_APOS;
+ }
+ else if (open == BT_APOS) {
+ state = other;
+ if (nAtts < attsMax)
+ atts[nAtts].valueEnd = ptr;
+ nAtts++;
+ }
+ break;
+ case BT_AMP:
+ if (nAtts < attsMax)
+ atts[nAtts].normalized = 0;
+ break;
+ case BT_S:
+ if (state == inName)
+ state = other;
+ else if (state == inValue
+ && nAtts < attsMax
+ && atts[nAtts].normalized
+ && (ptr == atts[nAtts].valuePtr
+ || BYTE_TO_ASCII(enc, ptr) != ASCII_SPACE
+ || BYTE_TO_ASCII(enc, ptr + MINBPC(enc)) == ASCII_SPACE
+ || BYTE_TYPE(enc, ptr + MINBPC(enc)) == open))
+ atts[nAtts].normalized = 0;
+ break;
+ case BT_CR: case BT_LF:
+ /* This case ensures that the first attribute name is counted
+ Apart from that we could just change state on the quote. */
+ if (state == inName)
+ state = other;
+ else if (state == inValue && nAtts < attsMax)
+ atts[nAtts].normalized = 0;
+ break;
+ case BT_GT:
+ case BT_SOL:
+ if (state != inValue)
+ return nAtts;
+ break;
+ default:
+ break;
+ }
+ }
+ /* not reached */
+}
+
+static
+int PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr)
+{
+ int result = 0;
+ cmExpatUnused(enc);
+ /* skip &# */
+ ptr += 2*MINBPC(enc);
+ if (CHAR_MATCHES(enc, ptr, ASCII_x)) {
+ for (ptr += MINBPC(enc); !CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) {
+ int c = BYTE_TO_ASCII(enc, ptr);
+ switch (c) {
+ case ASCII_0: case ASCII_1: case ASCII_2: case ASCII_3: case ASCII_4:
+ case ASCII_5: case ASCII_6: case ASCII_7: case ASCII_8: case ASCII_9:
+ result <<= 4;
+ result |= (c - ASCII_0);
+ break;
+ case ASCII_A: case ASCII_B: case ASCII_C: case ASCII_D: case ASCII_E: case ASCII_F:
+ result <<= 4;
+ result += 10 + (c - ASCII_A);
+ break;
+ case ASCII_a: case ASCII_b: case ASCII_c: case ASCII_d: case ASCII_e: case ASCII_f:
+ result <<= 4;
+ result += 10 + (c - ASCII_a);
+ break;
+ }
+ if (result >= 0x110000)
+ return -1;
+ }
+ }
+ else {
+ for (; !CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) {
+ int c = BYTE_TO_ASCII(enc, ptr);
+ result *= 10;
+ result += (c - ASCII_0);
+ if (result >= 0x110000)
+ return -1;
+ }
+ }
+ return checkCharRefNumber(result);
+}
+
+static
+int PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, const char *end)
+{
+ cmExpatUnused(enc);
+ switch ((end - ptr)/MINBPC(enc)) {
+ case 2:
+ if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_t)) {
+ switch (BYTE_TO_ASCII(enc, ptr)) {
+ case ASCII_l:
+ return ASCII_LT;
+ case ASCII_g:
+ return ASCII_GT;
+ }
+ }
+ break;
+ case 3:
+ if (CHAR_MATCHES(enc, ptr, ASCII_a)) {
+ ptr += MINBPC(enc);
+ if (CHAR_MATCHES(enc, ptr, ASCII_m)) {
+ ptr += MINBPC(enc);
+ if (CHAR_MATCHES(enc, ptr, ASCII_p))
+ return ASCII_AMP;
+ }
+ }
+ break;
+ case 4:
+ switch (BYTE_TO_ASCII(enc, ptr)) {
+ case ASCII_q:
+ ptr += MINBPC(enc);
+ if (CHAR_MATCHES(enc, ptr, ASCII_u)) {
+ ptr += MINBPC(enc);
+ if (CHAR_MATCHES(enc, ptr, ASCII_o)) {
+ ptr += MINBPC(enc);
+ if (CHAR_MATCHES(enc, ptr, ASCII_t))
+ return ASCII_QUOT;
+ }
+ }
+ break;
+ case ASCII_a:
+ ptr += MINBPC(enc);
+ if (CHAR_MATCHES(enc, ptr, ASCII_p)) {
+ ptr += MINBPC(enc);
+ if (CHAR_MATCHES(enc, ptr, ASCII_o)) {
+ ptr += MINBPC(enc);
+ if (CHAR_MATCHES(enc, ptr, ASCII_s))
+ return ASCII_APOS;
+ }
+ }
+ break;
+ }
+ }
+ return 0;
+}
+
+static
+int PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2)
+{
+ for (;;) {
+ switch (BYTE_TYPE(enc, ptr1)) {
+#define LEAD_CASE(n) \
+ case BT_LEAD ## n: \
+ if (*ptr1++ != *ptr2++) \
+ return 0;
+ LEAD_CASE(4) LEAD_CASE(3) LEAD_CASE(2)
+#undef LEAD_CASE
+ /* fall through */
+ if (*ptr1++ != *ptr2++)
+ return 0;
+ break;
+ case BT_NONASCII:
+ case BT_NMSTRT:
+#ifdef XML_NS
+ case BT_COLON:
+#endif
+ case BT_HEX:
+ case BT_DIGIT:
+ case BT_NAME:
+ case BT_MINUS:
+ if (*ptr2++ != *ptr1++)
+ return 0;
+ if (MINBPC(enc) > 1) {
+ if (*ptr2++ != *ptr1++)
+ return 0;
+ if (MINBPC(enc) > 2) {
+ if (*ptr2++ != *ptr1++)
+ return 0;
+ if (MINBPC(enc) > 3) {
+ if (*ptr2++ != *ptr1++)
+ return 0;
+ }
+ }
+ }
+ break;
+ default:
+ if (MINBPC(enc) == 1 && *ptr1 == *ptr2)
+ return 1;
+ switch (BYTE_TYPE(enc, ptr2)) {
+ case BT_LEAD2:
+ case BT_LEAD3:
+ case BT_LEAD4:
+ case BT_NONASCII:
+ case BT_NMSTRT:
+#ifdef XML_NS
+ case BT_COLON:
+#endif
+ case BT_HEX:
+ case BT_DIGIT:
+ case BT_NAME:
+ case BT_MINUS:
+ return 0;
+ default:
+ return 1;
+ }
+ }
+ }
+ /* not reached */
+}
+
+static
+int PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1,
+ const char *end1, const char *ptr2)
+{
+ cmExpatUnused(enc);
+ for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) {
+ if (ptr1 == end1)
+ return 0;
+ if (!CHAR_MATCHES(enc, ptr1, *ptr2))
+ return 0;
+ }
+ return ptr1 == end1;
+}
+
+static
+int PREFIX(nameLength)(const ENCODING *enc, const char *ptr)
+{
+ const char *start = ptr;
+ for (;;) {
+ switch (BYTE_TYPE(enc, ptr)) {
+#define LEAD_CASE(n) \
+ case BT_LEAD ## n: ptr += n; break;
+ LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)
+#undef LEAD_CASE
+ case BT_NONASCII:
+ case BT_NMSTRT:
+#ifdef XML_NS
+ case BT_COLON:
+#endif
+ case BT_HEX:
+ case BT_DIGIT:
+ case BT_NAME:
+ case BT_MINUS:
+ ptr += MINBPC(enc);
+ break;
+ default:
+ return ptr - start;
+ }
+ }
+}
+
+static
+const char *PREFIX(skipS)(const ENCODING *enc, const char *ptr)
+{
+ for (;;) {
+ switch (BYTE_TYPE(enc, ptr)) {
+ case BT_LF:
+ case BT_CR:
+ case BT_S:
+ ptr += MINBPC(enc);
+ break;
+ default:
+ return ptr;
+ }
+ }
+}
+
+static
+void PREFIX(updatePosition)(const ENCODING *enc,
+ const char *ptr,
+ const char *end,
+ POSITION *pos)
+{
+ while (ptr != end) {
+ switch (BYTE_TYPE(enc, ptr)) {
+#define LEAD_CASE(n) \
+ case BT_LEAD ## n: \
+ ptr += n; \
+ break;
+ LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)
+#undef LEAD_CASE
+ case BT_LF:
+ pos->columnNumber = (unsigned)-1;
+ pos->lineNumber++;
+ ptr += MINBPC(enc);
+ break;
+ case BT_CR:
+ pos->lineNumber++;
+ ptr += MINBPC(enc);
+ if (ptr != end && BYTE_TYPE(enc, ptr) == BT_LF)
+ ptr += MINBPC(enc);
+ pos->columnNumber = (unsigned)-1;
+ break;
+ default:
+ ptr += MINBPC(enc);
+ break;
+ }
+ pos->columnNumber++;
+ }
+}
+
+#undef DO_LEAD_CASE
+#undef MULTIBYTE_CASES
+#undef INVALID_CASES
+#undef CHECK_NAME_CASE
+#undef CHECK_NAME_CASES
+#undef CHECK_NMSTRT_CASE
+#undef CHECK_NMSTRT_CASES
diff --git a/Utilities/cmexpat/xmltok_impl.h b/Utilities/cmexpat/xmltok_impl.h
new file mode 100644
index 0000000000..da0ea60a65
--- /dev/null
+++ b/Utilities/cmexpat/xmltok_impl.h
@@ -0,0 +1,46 @@
+/*
+Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
+See the file COPYING for copying permission.
+*/
+
+enum {
+ BT_NONXML,
+ BT_MALFORM,
+ BT_LT,
+ BT_AMP,
+ BT_RSQB,
+ BT_LEAD2,
+ BT_LEAD3,
+ BT_LEAD4,
+ BT_TRAIL,
+ BT_CR,
+ BT_LF,
+ BT_GT,
+ BT_QUOT,
+ BT_APOS,
+ BT_EQUALS,
+ BT_QUEST,
+ BT_EXCL,
+ BT_SOL,
+ BT_SEMI,
+ BT_NUM,
+ BT_LSQB,
+ BT_S,
+ BT_NMSTRT,
+ BT_COLON,
+ BT_HEX,
+ BT_DIGIT,
+ BT_NAME,
+ BT_MINUS,
+ BT_OTHER, /* known not to be a name or name start character */
+ BT_NONASCII, /* might be a name or name start character */
+ BT_PERCNT,
+ BT_LPAR,
+ BT_RPAR,
+ BT_AST,
+ BT_PLUS,
+ BT_COMMA,
+ BT_VERBAR
+};
+
+#include <stddef.h>
diff --git a/Utilities/cmexpat/xmltok_ns.c b/Utilities/cmexpat/xmltok_ns.c
new file mode 100644
index 0000000000..fa78adffce
--- /dev/null
+++ b/Utilities/cmexpat/xmltok_ns.c
@@ -0,0 +1,98 @@
+const ENCODING *NS(XmlGetUtf8InternalEncoding)(void)
+{
+ return &ns(internal_utf8_encoding).enc;
+}
+
+const ENCODING *NS(XmlGetUtf16InternalEncoding)(void)
+{
+#if XML_BYTE_ORDER == 12
+ return &ns(internal_little2_encoding).enc;
+#elif XML_BYTE_ORDER == 21
+ return &ns(internal_big2_encoding).enc;
+#else
+ const short n = 1;
+ return *(const char *)&n ? &ns(internal_little2_encoding).enc : &ns(internal_big2_encoding).enc;
+#endif
+}
+
+static
+const ENCODING *NS(encodings)[] = {
+ &ns(latin1_encoding).enc,
+ &ns(ascii_encoding).enc,
+ &ns(utf8_encoding).enc,
+ &ns(big2_encoding).enc,
+ &ns(big2_encoding).enc,
+ &ns(little2_encoding).enc,
+ &ns(utf8_encoding).enc /* NO_ENC */
+};
+
+static
+int NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE, ptr, end, nextTokPtr);
+}
+
+static
+int NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
+ const char **nextTokPtr)
+{
+ return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE, ptr, end, nextTokPtr);
+}
+
+int NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, const char *name)
+{
+ int i = getEncodingIndex(name);
+ if (i == UNKNOWN_ENC)
+ return 0;
+ SET_INIT_ENC_INDEX(p, i);
+ p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
+ p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
+ p->initEnc.updatePosition = initUpdatePosition;
+ p->encPtr = encPtr;
+ *encPtr = &(p->initEnc);
+ return 1;
+}
+
+static
+const ENCODING *NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
+{
+#define ENCODING_MAX 128
+ char buf[ENCODING_MAX];
+ char *p = buf;
+ int i;
+ XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
+ if (ptr != end)
+ return 0;
+ *p = 0;
+ if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
+ return enc;
+ i = getEncodingIndex(buf);
+ if (i == UNKNOWN_ENC)
+ return 0;
+ return NS(encodings)[i];
+}
+
+int NS(XmlParseXmlDecl)(int isGeneralTextEntity,
+ const ENCODING *enc,
+ const char *ptr,
+ const char *end,
+ const char **badPtr,
+ const char **versionPtr,
+ const char **versionEndPtr,
+ const char **encodingName,
+ const ENCODING **encoding,
+ int *standalone)
+{
+ return doParseXmlDecl(NS(findEncoding),
+ isGeneralTextEntity,
+ enc,
+ ptr,
+ end,
+ badPtr,
+ versionPtr,
+ versionEndPtr,
+ encodingName,
+ encoding,
+ standalone);
+}
diff --git a/Utilities/cmlibarchive/.gitattributes b/Utilities/cmlibarchive/.gitattributes
new file mode 100644
index 0000000000..562b12e16e
--- /dev/null
+++ b/Utilities/cmlibarchive/.gitattributes
@@ -0,0 +1 @@
+* -whitespace
diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt
new file mode 100644
index 0000000000..f1459d4552
--- /dev/null
+++ b/Utilities/cmlibarchive/CMakeLists.txt
@@ -0,0 +1,1334 @@
+PROJECT(libarchive C)
+#
+SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake")
+if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${libarchive_BINARY_DIR}/bin)
+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)
+
+#
+# Version - read from 'version' file.
+#
+FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/build/version _version)
+STRING(REGEX REPLACE
+ "^([0-9])[0-9][0-9][0-9][0-9][0-9][0-9][a-z]?$" "\\1" _major ${_version})
+STRING(REGEX REPLACE
+ "^[0-9]([0-9][0-9][0-9])[0-9][0-9][0-9][a-z]?$" "\\1" _minor ${_version})
+STRING(REGEX REPLACE
+ "^[0-9][0-9][0-9][0-9]([0-9][0-9][0-9])[a-z]?$" "\\1" _revision ${_version})
+STRING(REGEX REPLACE
+ "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]([a-z]?)$" "\\1" _quality ${_version})
+SET(_version_number ${_major}${_minor}${_revision})
+STRING(REGEX REPLACE "[0]*([^0]*[0-9])$" "\\1" _trimmed_minor ${_minor})
+STRING(REGEX REPLACE "[0]*([^0]*[0-9])$" "\\1" _trimmed_revision ${_revision})
+#
+SET(VERSION "${_major}.${_trimmed_minor}.${_trimmed_revision}${_quality}")
+SET(BSDCPIO_VERSION_STRING "${VERSION}")
+SET(BSDTAR_VERSION_STRING "${VERSION}")
+SET(BSDCAT_VERSION_STRING "${VERSION}")
+SET(LIBARCHIVE_VERSION_NUMBER "${_version_number}")
+SET(LIBARCHIVE_VERSION_STRING "${VERSION}")
+
+# INTERFACE_VERSION increments with every release
+# libarchive 2.7 == interface version 9 = 2 + 7
+# libarchive 2.8 == interface version 10 = 2 + 8
+# libarchive 2.9 == interface version 11 = 2 + 9
+# libarchive 3.0 == interface version 12
+# libarchive 3.1 == interface version 13
+math(EXPR INTERFACE_VERSION "13 + ${_minor}")
+
+# Set SOVERSION == Interface version
+# ?? Should there be more here ??
+SET(SOVERSION "${INTERFACE_VERSION}")
+
+# Enalbe CMAKE_PUSH_CHECK_STATE() and CMAKE_POP_CHECK_STATE() macros
+# saving and restoring the state of the variables.
+INCLUDE(${CMake_SOURCE_DIR}/Modules/CMakePushCheckState.cmake)
+
+# Initialize the state of the variables. This initialization is not
+# necessary but this shows you what value the variables initially have.
+SET(CMAKE_REQUIRED_DEFINITIONS)
+SET(CMAKE_REQUIRED_INCLUDES)
+SET(CMAKE_REQUIRED_LIBRARIES)
+SET(CMAKE_REQUIRED_FLAGS)
+
+# Disable warnings to avoid changing 3rd party code.
+IF("${CMAKE_C_COMPILER_ID}" MATCHES
+ "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
+ELSEIF("${CMAKE_C_COMPILER_ID}" MATCHES "^(PathScale)$")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
+ELSEIF(BORLAND)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
+ENDIF()
+
+# Enable CTest/CDash support
+include(CTest)
+
+OPTION(ENABLE_NETTLE "Enable use of Nettle" ON)
+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_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)
+
+OPTION(ENABLE_XATTR "Enable extended attribute support" ON)
+OPTION(ENABLE_ACL "Enable ACL support" ON)
+OPTION(ENABLE_ICONV "Enable iconv support" ON)
+
+IF(WIN32)
+ IF(MSVC60)
+ SET(WINVER 0x0400)
+ ELSE()
+ SET(WINVER 0x0500)
+ ENDIF()
+ SET(_WIN32_WINNT ${WINVER})
+ENDIF(WIN32)
+
+IF("${CMAKE_C_PLATFORM_ID}" MATCHES "^(HP-UX)$")
+ ADD_DEFINITIONS(-D_XOPEN_SOURCE=500) # Ask wchar.h for mbstate_t
+ENDIF()
+
+#
+INCLUDE(CheckCSourceCompiles)
+INCLUDE(CheckCSourceRuns)
+INCLUDE(CheckFileOffsetBits)
+INCLUDE(CheckFuncs)
+INCLUDE(CheckHeaderDirent)
+INCLUDE(CheckIncludeFile)
+INCLUDE(CheckIncludeFiles)
+INCLUDE(CheckLibraryExists)
+INCLUDE(CheckStructMember)
+INCLUDE(CheckSymbolExists)
+INCLUDE(CheckTypeExists)
+INCLUDE(CheckTypeSize)
+
+#
+# Generate list.h
+#
+MACRO (GENERATE_LIST_H _listfile _cmlist __list_sources)
+ SET(_argv ${ARGV})
+ # Remove _listfile and _cmlist from _argv
+ LIST(REMOVE_AT _argv 0 1)
+ IF (NOT EXISTS "${_listfile}" OR
+ ${_cmlist} IS_NEWER_THAN "${_listfile}")
+
+ MESSAGE(STATUS "Generating ${_listfile}")
+ FILE(WRITE ${_listfile} "")
+ FOREACH (testfile ${_argv})
+ IF (testfile MATCHES "^test_[^/]+[.]c$")
+ FILE(STRINGS ${testfile} testvar REGEX "^DEFINE_TEST")
+ FOREACH (deftest ${testvar})
+ FILE(APPEND ${_listfile} "${deftest}\n")
+ ENDFOREACH (deftest)
+ ENDIF (testfile MATCHES "^test_[^/]+[.]c$")
+ ENDFOREACH (testfile)
+
+ ENDIF (NOT EXISTS "${_listfile}" OR
+ ${_cmlist} IS_NEWER_THAN "${_listfile}")
+ENDMACRO (GENERATE_LIST_H)
+#
+# Generate installation rules for man pages.
+#
+MACRO (INSTALL_MAN __mans)
+ FOREACH (_man ${ARGV})
+ STRING(REGEX REPLACE "^.+[.]([1-9])" "\\1" _mansect ${_man})
+ INSTALL(FILES ${_man} DESTINATION "share/man/man${_mansect}")
+ ENDFOREACH (_man)
+ENDMACRO (INSTALL_MAN __mans)
+#
+# Find out what macro is needed to use libraries on Windows.
+#
+MACRO (TRY_MACRO_FOR_LIBRARY INCLUDES LIBRARIES
+ TRY_TYPE SAMPLE_SOURCE MACRO_LIST)
+ IF(WIN32 AND NOT CYGWIN)
+ CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
+ SET(CMAKE_REQUIRED_INCLUDES ${INCLUDES})
+ SET(CMAKE_REQUIRED_LIBRARIES ${LIBRARIES})
+ FOREACH(VAR ${MACRO_LIST})
+ # Clear ${VAR} from CACHE If the libraries which ${VAR} was
+ # checked with are changed.
+ SET(VAR_WITH_LIB "${VAR}_WITH_LIB")
+ GET_PROPERTY(PREV_VAR_WITH_LIB VARIABLE PROPERTY ${VAR_WITH_LIB})
+ IF(NOT "${PREV_VAR_WITH_LIB}" STREQUAL "${LIBRARIES}")
+ UNSET(${VAR} CACHE)
+ ENDIF(NOT "${PREV_VAR_WITH_LIB}" STREQUAL "${LIBRARIES}")
+ # Check if the library can be used with the macro.
+ IF("${TRY_TYPE}" MATCHES "COMPILES")
+ CHECK_C_SOURCE_COMPILES("${SAMPLE_SOURCE}" ${VAR})
+ ELSEIF("${TRY_TYPE}" MATCHES "RUNS")
+ CHECK_C_SOURCE_RUNS("${SAMPLE_SOURCE}" ${VAR})
+ ELSE("${TRY_TYPE}" MATCHES "COMPILES")
+ MESSAGE(FATAL_ERROR "UNKNOWN KEYWORD \"${TRY_TYPE}\" FOR TRY_TYPE")
+ ENDIF("${TRY_TYPE}" MATCHES "COMPILES")
+ # Save the libraries which ${VAR} is checked with.
+ SET(${VAR_WITH_LIB} "${LIBRARIES}" CACHE INTERNAL
+ "Macro ${VAR} is checked with")
+ ENDFOREACH(VAR)
+ CMAKE_POP_CHECK_STATE() # Restore the state of the variables
+ ENDIF(WIN32 AND NOT CYGWIN)
+ENDMACRO (TRY_MACRO_FOR_LIBRARY)
+#
+# Check compress/decompress libraries
+#
+IF(WIN32 AND NOT CMAKE_CL_64 AND NOT CYGWIN)
+ # GnuWin32 is only for Win32, not Win64.
+ SET(__GNUWIN32PATH "C:/Program Files/GnuWin32")
+ENDIF(WIN32 AND NOT CMAKE_CL_64 AND NOT CYGWIN)
+IF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}")
+ # You have to add a path availabel DLL file into PATH environment variable.
+ # Maybe DLL path is "C:/Program Files/GnuWin32/bin".
+ # The zlib and the bzip2 Setup program have installed programs and DLLs into
+ # "C:/Program Files/GnuWin32" by default.
+ # This is convenience setting for Windows.
+ SET(CMAKE_PREFIX_PATH ${__GNUWIN32PATH} $(CMAKE_PREFIX_PATH))
+ #
+ # If you didn't use Setup program or installed into nonstandard path,
+ # cmake cannot find out your zlib or bzip2 libraries and include files,
+ # you should execute cmake with -DCMAKE_PREFIX_PATH option.
+ # e.g.
+ # cmake -DCMAKE_PREFIX_PATH=<your-GnuWin32-path> <path-to-source>
+ #
+ # If compiling error occured in zconf.h, You may need patch to zconf.h.
+ #--- zconf.h.orig 2005-07-21 00:40:26.000000000
+ #+++ zconf.h 2009-01-19 11:39:10.093750000
+ #@@ -286,7 +286,7 @@
+ #
+ # #if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */
+ # # include <sys/types.h> /* for off_t */
+ #-# include <unistd.h> /* for SEEK_* and off_t */
+ #+# include <stdio.h> /* for SEEK_* and off_t */
+ # # ifdef VMS
+ # # include <unixio.h> /* for off_t */
+ # # endif
+ENDIF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}")
+
+SET(ADDITIONAL_LIBS "")
+#
+# Find ZLIB
+#
+IF(ENABLE_ZLIB)
+ FIND_PACKAGE(ZLIB)
+ELSE()
+ SET(ZLIB_FOUND FALSE) # Override cached value
+ENDIF()
+IF(ZLIB_FOUND)
+ SET(HAVE_LIBZ 1)
+ SET(HAVE_ZLIB_H 1)
+ INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${ZLIB_LIBRARIES})
+ IF(WIN32 AND NOT CYGWIN)
+ #
+ # Test if ZLIB_WINAPI macro is needed to use.
+ #
+ TRY_MACRO_FOR_LIBRARY(
+ "${ZLIB_INCLUDE_DIR}" "${ZLIB_LIBRARIES}"
+ RUNS
+ "#include <zlib.h>\nint main() {uLong f = zlibCompileFlags(); return (f&(1U<<10))?0:-1; }"
+ ZLIB_WINAPI)
+ IF(ZLIB_WINAPI)
+ ADD_DEFINITIONS(-DZLIB_WINAPI)
+ ELSE(ZLIB_WINAPI)
+ # Test if a macro is needed for the library.
+ TRY_MACRO_FOR_LIBRARY(
+ "${ZLIB_INCLUDE_DIR}" "${ZLIB_LIBRARIES}"
+ COMPILES
+ "#include <zlib.h>\nint main() {return zlibVersion()?1:0; }"
+ "ZLIB_DLL;WITHOUT_ZLIB_DLL")
+ IF(ZLIB_DLL)
+ ADD_DEFINITIONS(-DZLIB_DLL)
+ ENDIF(ZLIB_DLL)
+ ENDIF(ZLIB_WINAPI)
+ ENDIF(WIN32 AND NOT CYGWIN)
+ELSE(ZLIB_FOUND)
+ MESSAGE(FATAL_ERROR "CMake requires zlib to be available to libarchive")
+ENDIF(ZLIB_FOUND)
+#
+# Find BZip2
+#
+IF(ENABLE_BZip2)
+ FIND_PACKAGE(BZip2)
+ELSE()
+ SET(BZIP2_FOUND FALSE) # Override cached value
+ENDIF()
+IF(BZIP2_FOUND)
+ SET(HAVE_LIBBZ2 1)
+ SET(HAVE_BZLIB_H 1)
+ INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${BZIP2_LIBRARIES})
+ # Test if a macro is needed for the library.
+ TRY_MACRO_FOR_LIBRARY(
+ "${BZIP2_INCLUDE_DIR}" "${BZIP2_LIBRARIES}"
+ COMPILES
+ "#include <bzlib.h>\nint main() {return BZ2_bzlibVersion()?1:0; }"
+ "USE_BZIP2_DLL;USE_BZIP2_STATIC")
+ IF(USE_BZIP2_DLL)
+ ADD_DEFINITIONS(-DUSE_BZIP2_DLL)
+ ELSEIF(USE_BZIP2_STATIC)
+ ADD_DEFINITIONS(-DUSE_BZIP2_STATIC)
+ ENDIF(USE_BZIP2_DLL)
+ENDIF(BZIP2_FOUND)
+MARK_AS_ADVANCED(CLEAR BZIP2_INCLUDE_DIR)
+MARK_AS_ADVANCED(CLEAR BZIP2_LIBRARIES)
+#
+# Find LZMA
+#
+IF(ENABLE_LZMA)
+ FIND_PACKAGE(LZMA)
+ELSE()
+ SET(LZMA_FOUND FALSE) # Override cached value
+ SET(LZMADEC_FOUND FALSE) # Override cached value
+ENDIF()
+
+IF(LZMA_FOUND)
+ SET(HAVE_LIBLZMA 1)
+ SET(HAVE_LZMA_H 1)
+ INCLUDE_DIRECTORIES(${LZMA_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${LZMA_LIBRARIES})
+ IF(CMAKE_USE_SYSTEM_LIBLZMA)
+ # Test if a macro is needed for the library.
+ TRY_MACRO_FOR_LIBRARY(
+ "${LZMA_INCLUDE_DIR}" "${LZMA_LIBRARIES}"
+ COMPILES
+ "#include <lzma.h>\nint main() {return (int)lzma_version_number(); }"
+ "WITHOUT_LZMA_API_STATIC;LZMA_API_STATIC")
+ IF(NOT WITHOUT_LZMA_API_STATIC AND LZMA_API_STATIC)
+ ADD_DEFINITIONS(-DLZMA_API_STATIC)
+ ENDIF(NOT WITHOUT_LZMA_API_STATIC AND LZMA_API_STATIC)
+ ELSE()
+ ADD_DEFINITIONS(-DLZMA_API_STATIC)
+ ENDIF()
+ELSEIF(LZMADEC_FOUND)
+ SET(HAVE_LIBLZMADEC 1)
+ SET(HAVE_LZMADEC_H 1)
+ INCLUDE_DIRECTORIES(${LZMADEC_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${LZMADEC_LIBRARIES})
+ELSE(LZMA_FOUND)
+# LZMA not found and will not be used.
+ENDIF(LZMA_FOUND)
+IF(0) # CMake does not need LZO2 support in libarchive
+#
+# Find LZO2
+#
+IF (LZO2_INCLUDE_DIR)
+ # Already in cache, be silent
+ SET(LZO2_FIND_QUIETLY TRUE)
+ENDIF (LZO2_INCLUDE_DIR)
+
+FIND_PATH(LZO2_INCLUDE_DIR lzo/lzoconf.h)
+FIND_LIBRARY(LZO2_LIBRARY NAMES lzo2 liblzo2)
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZO2 DEFAULT_MSG LZO2_LIBRARY LZO2_INCLUDE_DIR)
+IF(LZO2_FOUND)
+ SET(HAVE_LIBLZO2 1)
+ SET(HAVE_LZO_LZOCONF_H 1)
+ SET(HAVE_LZO_LZO1X_H 1)
+ INCLUDE_DIRECTORIES(${LZO2_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${LZO2_LIBRARY})
+ #
+ # TODO: test for static library.
+ #
+ENDIF(LZO2_FOUND)
+MARK_AS_ADVANCED(CLEAR LZO2_INCLUDE_DIR)
+MARK_AS_ADVANCED(CLEAR LZO2_LIBRARY)
+ENDIF()
+
+#
+# Check headers
+#
+CHECK_HEADER_DIRENT()
+
+SET(INCLUDES "")
+MACRO (LA_CHECK_INCLUDE_FILE header var)
+ CHECK_INCLUDE_FILES("${INCLUDES};${header}" ${var})
+ IF (${var})
+ SET(INCLUDES ${INCLUDES} ${header})
+ ENDIF (${var})
+ENDMACRO (LA_CHECK_INCLUDE_FILE)
+
+# Some FreeBSD headers assume sys/types.h was already included.
+LA_CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
+
+# Alphabetize the rest unless there's a compelling reason
+IF(ENABLE_ACL)
+ LA_CHECK_INCLUDE_FILE("acl/libacl.h" HAVE_ACL_LIBACL_H)
+ELSE(ENABLE_ACL)
+ SET(HAVE_ACL_LIBACL_H FALSE)
+ENDIF(ENABLE_ACL)
+LA_CHECK_INCLUDE_FILE("ctype.h" HAVE_CTYPE_H)
+LA_CHECK_INCLUDE_FILE("copyfile.h" HAVE_COPYFILE_H)
+LA_CHECK_INCLUDE_FILE("direct.h" HAVE_DIRECT_H)
+LA_CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H)
+LA_CHECK_INCLUDE_FILE("errno.h" HAVE_ERRNO_H)
+LA_CHECK_INCLUDE_FILE("ext2fs/ext2_fs.h" HAVE_EXT2FS_EXT2_FS_H)
+
+CHECK_C_SOURCE_COMPILES("#include <sys/ioctl.h>
+#include <ext2fs/ext2_fs.h>
+int main(void) { return EXT2_IOC_GETFLAGS; }" HAVE_WORKING_EXT2_IOC_GETFLAGS)
+
+LA_CHECK_INCLUDE_FILE("fcntl.h" HAVE_FCNTL_H)
+LA_CHECK_INCLUDE_FILE("grp.h" HAVE_GRP_H)
+LA_CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
+LA_CHECK_INCLUDE_FILE("io.h" HAVE_IO_H)
+LA_CHECK_INCLUDE_FILE("langinfo.h" HAVE_LANGINFO_H)
+LA_CHECK_INCLUDE_FILE("limits.h" HAVE_LIMITS_H)
+LA_CHECK_INCLUDE_FILE("linux/types.h" HAVE_LINUX_TYPES_H)
+LA_CHECK_INCLUDE_FILE("linux/fiemap.h" HAVE_LINUX_FIEMAP_H)
+LA_CHECK_INCLUDE_FILE("linux/fs.h" HAVE_LINUX_FS_H)
+LA_CHECK_INCLUDE_FILE("linux/magic.h" HAVE_LINUX_MAGIC_H)
+LA_CHECK_INCLUDE_FILE("locale.h" HAVE_LOCALE_H)
+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("pwd.h" HAVE_PWD_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)
+LA_CHECK_INCLUDE_FILE("stdarg.h" HAVE_STDARG_H)
+LA_CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
+LA_CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
+LA_CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
+LA_CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
+LA_CHECK_INCLUDE_FILE("sys/acl.h" HAVE_SYS_ACL_H)
+LA_CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H)
+LA_CHECK_INCLUDE_FILE("sys/ioctl.h" HAVE_SYS_IOCTL_H)
+LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H)
+LA_CHECK_INCLUDE_FILE("sys/mount.h" HAVE_SYS_MOUNT_H)
+LA_CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H)
+LA_CHECK_INCLUDE_FILE("sys/poll.h" HAVE_SYS_POLL_H)
+LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H)
+LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
+LA_CHECK_INCLUDE_FILE("sys/statfs.h" HAVE_SYS_STATFS_H)
+LA_CHECK_INCLUDE_FILE("sys/statvfs.h" HAVE_SYS_STATVFS_H)
+LA_CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H)
+LA_CHECK_INCLUDE_FILE("sys/utime.h" HAVE_SYS_UTIME_H)
+LA_CHECK_INCLUDE_FILE("sys/utsname.h" HAVE_SYS_UTSNAME_H)
+LA_CHECK_INCLUDE_FILE("sys/vfs.h" HAVE_SYS_VFS_H)
+LA_CHECK_INCLUDE_FILE("sys/wait.h" HAVE_SYS_WAIT_H)
+LA_CHECK_INCLUDE_FILE("time.h" HAVE_TIME_H)
+LA_CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
+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)
+# 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)
+
+#
+# Check whether use of __EXTENSIONS__ is safe.
+# We need some macro such as _GNU_SOURCE to use extension functions.
+#
+SET(_INCLUDE_FILES)
+FOREACH (it ${_HEADER})
+ SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
+ENDFOREACH (it)
+
+CHECK_C_SOURCE_COMPILES(
+ "#define __EXTENSIONS__ 1
+ ${_INCLUDE_FILES}
+ int main() { return 0;}"
+ SAFE_TO_DEFINE_EXTENSIONS)
+
+#
+# Find Nettle
+#
+IF(ENABLE_NETTLE)
+ FIND_PACKAGE(Nettle)
+ IF(NETTLE_FOUND)
+ SET(HAVE_LIBNETTLE 1)
+ SET(HAVE_NETTLE_MD5_H 1)
+ SET(HAVE_NETTLE_RIPEMD160_H 1)
+ SET(HAVE_NETTLE_SHA_H 1)
+ INCLUDE_DIRECTORIES(${NETTLE_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${NETTLE_LIBRARIES})
+ ENDIF(NETTLE_FOUND)
+ MARK_AS_ADVANCED(CLEAR NETTLE_INCLUDE_DIR)
+ MARK_AS_ADVANCED(CLEAR NETTLE_LIBRARIES)
+ENDIF(ENABLE_NETTLE)
+
+#
+# Find OpenSSL
+# (Except on Mac, where OpenSSL is deprecated.)
+#
+IF(ENABLE_OPENSSL AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ FIND_PACKAGE(OpenSSL)
+ELSE()
+ SET(OPENSSL_FOUND FALSE) # Override cached value
+ENDIF()
+
+# FreeBSD libmd
+IF(NOT OPENSSL_FOUND)
+ CHECK_LIBRARY_EXISTS(md "MD5Init" "" LIBMD_FOUND)
+ IF(LIBMD_FOUND)
+ CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
+ SET(CMAKE_REQUIRED_LIBRARIES "md")
+ FIND_LIBRARY(LIBMD_LIBRARY NAMES md)
+ LIST(APPEND ADDITIONAL_LIBS ${LIBMD_LIBRARY})
+ CMAKE_POP_CHECK_STATE() # Restore the state of the variables
+ ENDIF(LIBMD_FOUND)
+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
+# required libraries.
+#
+MACRO(CHECK_CRYPTO ALGORITHMS IMPLEMENTATION)
+ FOREACH(ALGORITHM ${ALGORITHMS})
+ IF(NOT ARCHIVE_CRYPTO_${ALGORITHM})
+ STRING(TOLOWER "${ALGORITHM}" lower_algorithm)
+ STRING(TOUPPER "${ALGORITHM}" algorithm)
+ IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND NOT OPENSSL_FOUND)
+ SET(ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} FALSE)
+ ELSEIF("${IMPLEMENTATION}" MATCHES "^NETTLE$" AND NOT NETTLE_FOUND)
+ SET(ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} FALSE)
+ ENDIF("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND NOT OPENSSL_FOUND)
+
+ IF(NOT DEFINED ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION})
+ # Probe the local implementation for whether this
+ # crypto implementation is available on this platform.
+ SET(TRY_CRYPTO_REQUIRED_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}/libarchive;${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp")
+ SET(TRY_CRYPTO_REQUIRED_LIBS)
+ IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND)
+ SET(TRY_CRYPTO_REQUIRED_INCLUDES
+ "${TRY_CRYPTO_REQUIRED_INCLUDES};${OPENSSL_INCLUDE_DIR}")
+ SET(TRY_CRYPTO_REQUIRED_LIBS
+ "-DLINK_LIBRARIES:STRING=${OPENSSL_LIBRARIES}")
+ ELSEIF("${IMPLEMENTATION}" MATCHES "^NETTLE$" AND NETTLE_FOUND)
+ SET(TRY_CRYPTO_REQUIRED_INCLUDES
+ "${TRY_CRYPTO_REQUIRED_INCLUDES};${NETTLE_INCLUDE_DIR}")
+ SET(TRY_CRYPTO_REQUIRED_LIBS
+ "-DLINK_LIBRARIES:STRING=${NETTLE_LIBRARY}")
+ ELSEIF("${IMPLEMENTATION}" MATCHES "^LIBMD$" AND LIBMD_FOUND)
+ SET(TRY_CRYPTO_REQUIRED_LIBS
+ "-DLINK_LIBRARIES:STRING=${LIBMD_LIBRARY}")
+ ENDIF("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND)
+
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in
+ ${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"
+ ARCHIVE_CRYPTO_C)
+
+ SET(SOURCE "${CONFDEFS_H}
+
+#define ARCHIVE_${algorithm}_COMPILE_TEST
+#define ARCHIVE_CRYPTO_${algorithm}_${IMPLEMENTATION}
+#define PLATFORM_CONFIG_H \"check_crypto_md.h\"
+
+${ARCHIVE_CRYPTO_C}
+
+int
+main(int argc, char **argv)
+{
+ archive_${lower_algorithm}_ctx ctx;
+ archive_${lower_algorithm}_init(&ctx);
+ archive_${lower_algorithm}_update(&ctx, *argv, argc);
+ archive_${lower_algorithm}_final(&ctx, NULL);
+ return 0;
+}
+")
+
+ FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_md.h" "")
+ FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_md.c" "${SOURCE}")
+ MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}")
+
+ TRY_COMPILE(ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_md.c
+ CMAKE_FLAGS
+ "${TRY_CRYPTO_REQUIRED_LIBS}"
+ "${TRY_CRYPTO_REQUIRED_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ # Inform user whether or not we found it; if not, log why we didn't.
+ IF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION})
+ MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} -- found")
+ SET(ARCHIVE_CRYPTO_${ALGORITHM} 1)
+ ELSE (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION})
+ MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} -- not found")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ ENDIF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION})
+ ENDIF(NOT DEFINED ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION})
+
+ # Add appropriate libs/includes depending on whether the implementation
+ # was found on this platform.
+ IF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION})
+ IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND)
+ INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${OPENSSL_LIBRARIES})
+ LIST(REMOVE_DUPLICATES ADDITIONAL_LIBS)
+ ENDIF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND)
+ ENDIF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION})
+ ENDIF(NOT ARCHIVE_CRYPTO_${ALGORITHM})
+ ENDFOREACH(ALGORITHM ${ALGORITHMS})
+ENDMACRO(CHECK_CRYPTO ALGORITHMS IMPLEMENTATION)
+
+#
+# CRYPTO functions on Windows is defined at archive_windows.c, thus we do not
+# need the test what the functions can be mapped to archive_{crypto name}_init,
+# archive_{crypto name}_update and archive_{crypto name}_final.
+# The functions on Windows use CALG_{crypto name} macro to create a crypt object
+# and then we need to know what CALG_{crypto name} macros is available to show
+# ARCHIVE_CRYPTO_{crypto name}_WIN macros because Windows 2000 and earlier version
+# of Windows XP do not support SHA256, SHA384 and SHA512.
+#
+MACRO(CHECK_CRYPTO_WIN CRYPTO_LIST)
+ IF(WIN32 AND NOT CYGWIN)
+ FOREACH(CRYPTO ${CRYPTO_LIST})
+ IF(NOT ARCHIVE_CRYPTO_${CRYPTO})
+ IF(NOT DEFINED ARCHIVE_CRYPTO_${CRYPTO}_WIN)
+ STRING(TOUPPER "${CRYPTO}" crypto)
+ SET(ALGID "")
+ IF ("${CRYPTO}" MATCHES "^MD5$")
+ SET(ALGID "CALG_MD5")
+ ENDIF ("${CRYPTO}" MATCHES "^MD5$")
+ IF ("${CRYPTO}" MATCHES "^SHA1$")
+ SET(ALGID "CALG_SHA1")
+ ENDIF ("${CRYPTO}" MATCHES "^SHA1$")
+ IF ("${CRYPTO}" MATCHES "^SHA256$")
+ SET(ALGID "CALG_SHA_256")
+ ENDIF ("${CRYPTO}" MATCHES "^SHA256$")
+ IF ("${CRYPTO}" MATCHES "^SHA384$")
+ SET(ALGID "CALG_SHA_384")
+ ENDIF ("${CRYPTO}" MATCHES "^SHA384$")
+ IF ("${CRYPTO}" MATCHES "^SHA512$")
+ SET(ALGID "CALG_SHA_512")
+ ENDIF ("${CRYPTO}" MATCHES "^SHA512$")
+
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/confdefs.h)
+ FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/confdefs.h"
+ CONFDEFS_H)
+
+ SET(SOURCE "${CONFDEFS_H}
+
+#define ${crypto}_COMPILE_TEST
+#include <windows.h>
+#include <wincrypt.h>
+
+int
+main(int argc, char **argv)
+{
+ return ${ALGID};
+}
+")
+ SET(SOURCE_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_win.c")
+
+ FILE(WRITE "${SOURCE_FILE}" "${SOURCE}")
+ MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN")
+
+ TRY_COMPILE(ARCHIVE_CRYPTO_${CRYPTO}_WIN
+ ${CMAKE_BINARY_DIR}
+ ${SOURCE_FILE}
+ CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}/libarchive"
+ OUTPUT_VARIABLE OUTPUT)
+
+ IF (ARCHIVE_CRYPTO_${CRYPTO}_WIN)
+ MESSAGE(STATUS
+ "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN -- found")
+ SET(ARCHIVE_CRYPTO_${CRYPTO} 1)
+ ELSE (ARCHIVE_CRYPTO_${CRYPTO}_WIN)
+ MESSAGE(STATUS
+ "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN -- not found")
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ ENDIF (ARCHIVE_CRYPTO_${CRYPTO}_WIN)
+
+ ENDIF(NOT DEFINED ARCHIVE_CRYPTO_${CRYPTO}_WIN)
+ ENDIF(NOT ARCHIVE_CRYPTO_${CRYPTO})
+ ENDFOREACH(CRYPTO)
+ ENDIF(WIN32 AND NOT CYGWIN)
+ENDMACRO(CHECK_CRYPTO_WIN CRYPTO_LIST)
+
+#
+# Find iconv
+# POSIX defines the second arg as const char **
+# and requires it to be in libc. But we can accept
+# a non-const argument here and can support iconv()
+# being in libiconv.
+#
+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" MATCHES "^GNU$")
+ #
+ # 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" MATCHES "^GNU$")
+ IF (MSVC)
+ # NOTE: /WX option is the same as gcc's -Werror option.
+ SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /WX")
+ ENDIF (MSVC)
+ #
+ CHECK_C_SOURCE_COMPILES(
+ "#include <stdlib.h>
+ #include <iconv.h>
+ int main() {
+ ${TRY_ICONV_CONST} char *ccp;
+ iconv_t cd = iconv_open(\"\", \"\");
+ iconv(cd, &ccp, (size_t *)0, (char **)0, (size_t *)0);
+ iconv_close(cd);
+ return 0;
+ }"
+ HAVE_ICONV_${LIB}_${TRY_ICONV_CONST})
+ IF(HAVE_ICONV_${LIB}_${TRY_ICONV_CONST})
+ SET(HAVE_ICONV true)
+ SET(ICONV_CONST ${TRY_ICONV_CONST})
+ ENDIF(HAVE_ICONV_${LIB}_${TRY_ICONV_CONST})
+ CMAKE_POP_CHECK_STATE() # Restore the state of the variables
+ ENDIF(NOT HAVE_ICONV)
+ENDMACRO(CHECK_ICONV TRY_ICONV_CONST)
+
+IF(ENABLE_ICONV)
+ CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
+ FIND_PATH(ICONV_INCLUDE_DIR iconv.h)
+ MARK_AS_ADVANCED(ICONV_INCLUDE_DIR)
+ IF(ICONV_INCLUDE_DIR)
+ #SET(INCLUDES ${INCLUDES} "iconv.h")
+ SET(HAVE_ICONV_H 1)
+ INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
+ SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
+ CHECK_ICONV("libc" "const")
+ CHECK_ICONV("libc" "")
+
+ # If iconv isn't in libc and we have a libiconv, try that.
+ FIND_LIBRARY(LIBICONV_PATH NAMES iconv libiconv)
+ IF(NOT HAVE_ICONV AND LIBICONV_PATH)
+ LIST(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBICONV_PATH})
+ # Test if a macro is needed for the library.
+ TRY_MACRO_FOR_LIBRARY(
+ "${ICONV_INCLUDE_DIR}" "${LIBICONV_PATH}"
+ COMPILES
+ "#include <iconv.h>\nint main() {return iconv_close((iconv_t)0);}"
+ "WITHOUT_LIBICONV_STATIC;LIBICONV_STATIC")
+ IF(NOT WITHOUT_LIBICONV_STATIC AND LIBICONV_STATIC)
+ ADD_DEFINITIONS(-DLIBICONV_STATIC)
+ ENDIF(NOT WITHOUT_LIBICONV_STATIC AND LIBICONV_STATIC)
+ #
+ # Set up CMAKE_REQUIRED_* for CHECK_ICONV
+ #
+ SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
+ SET(CMAKE_REQUIRED_LIBRARIES ${LIBICONV_PATH})
+ IF(LIBICONV_STATIC)
+ # LIBICONV_STATIC is necessary for the success of CHECK_ICONV
+ # on Windows.
+ SET(CMAKE_REQUIRED_DEFINITIONS "-DLIBICONV_STATIC")
+ ELSE(LIBICONV_STATIC)
+ SET(CMAKE_REQUIRED_DEFINITIONS)
+ ENDIF(LIBICONV_STATIC)
+ CHECK_ICONV("libiconv" "const")
+ CHECK_ICONV("libiconv" "")
+ IF (HAVE_ICONV)
+ LIST(APPEND ADDITIONAL_LIBS ${LIBICONV_PATH})
+ ENDIF(HAVE_ICONV)
+ ENDIF(NOT HAVE_ICONV AND LIBICONV_PATH)
+ ENDIF(ICONV_INCLUDE_DIR)
+ #
+ # Find locale_charset() for libiconv.
+ #
+ IF(LIBICONV_PATH)
+ SET(CMAKE_REQUIRED_DEFINITIONS)
+ SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
+ SET(CMAKE_REQUIRED_LIBRARIES)
+ CHECK_INCLUDE_FILES("localcharset.h" HAVE_LOCALCHARSET_H)
+ FIND_LIBRARY(LIBCHARSET_PATH NAMES charset libcharset)
+ IF(LIBCHARSET_PATH)
+ SET(CMAKE_REQUIRED_LIBRARIES ${LIBCHARSET_PATH})
+ IF(WIN32 AND NOT CYGWIN)
+ # Test if a macro is needed for the library.
+ TRY_MACRO_FOR_LIBRARY(
+ "${ICONV_INCLUDE_DIR}" "${LIBCHARSET_PATH}"
+ COMPILES
+ "#include <localcharset.h>\nint main() {return locale_charset()?1:0;}"
+ "WITHOUT_LIBCHARSET_STATIC;LIBCHARSET_STATIC")
+ IF(NOT WITHOUT_LIBCHARSET_STATIC AND LIBCHARSET_STATIC)
+ ADD_DEFINITIONS(-DLIBCHARSET_STATIC)
+ ENDIF(NOT WITHOUT_LIBCHARSET_STATIC AND LIBCHARSET_STATIC)
+ IF(WITHOUT_LIBCHARSET_STATIC OR LIBCHARSET_STATIC)
+ SET(HAVE_LOCALE_CHARSET ON CACHE INTERNAL
+ "Have function locale_charset")
+ ENDIF(WITHOUT_LIBCHARSET_STATIC OR LIBCHARSET_STATIC)
+ ELSE(WIN32 AND NOT CYGWIN)
+ CHECK_FUNCTION_EXISTS_GLIBC(locale_charset HAVE_LOCALE_CHARSET)
+ ENDIF(WIN32 AND NOT CYGWIN)
+ IF(HAVE_LOCALE_CHARSET)
+ LIST(APPEND ADDITIONAL_LIBS ${LIBCHARSET_PATH})
+ ENDIF(HAVE_LOCALE_CHARSET)
+ ENDIF(LIBCHARSET_PATH)
+ ENDIF(LIBICONV_PATH)
+ CMAKE_POP_CHECK_STATE() # Restore the state of the variables
+ELSE(ENABLE_ICONV)
+ # Make sure ICONV variables are not in CACHE after ENABLE_ICONV disabled
+ # (once enabled).
+ UNSET(HAVE_LOCALE_CHARSET CACHE)
+ UNSET(HAVE_ICONV CACHE)
+ UNSET(HAVE_ICONV_libc_ CACHE)
+ UNSET(HAVE_ICONV_libc_const CACHE)
+ UNSET(HAVE_ICONV_libiconv_ CACHE)
+ UNSET(HAVE_ICONV_libiconv_const CACHE)
+ UNSET(ICONV_INCLUDE_DIR CACHE)
+ UNSET(LIBICONV_PATH CACHE)
+ UNSET(LIBICONV_DLL CACHE)
+ UNSET(LIBICONV_STATIC CACHE)
+ UNSET(LIBCHARSET_DLL CACHE)
+ UNSET(LIBCHARSET_STATIC CACHE)
+ENDIF(ENABLE_ICONV)
+
+IF(0) # CMake does not need XML support in libarchive
+#
+# Find Libxml2
+#
+FIND_PACKAGE(LibXml2)
+IF(LIBXML2_FOUND)
+ CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
+ INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${LIBXML2_LIBRARIES})
+ SET(HAVE_LIBXML2 1)
+ # libxml2's include files use iconv.h
+ SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR})
+ CHECK_INCLUDE_FILES("libxml/xmlreader.h" HAVE_LIBXML_XMLREADER_H)
+ CHECK_INCLUDE_FILES("libxml/xmlwriter.h" HAVE_LIBXML_XMLWRITER_H)
+ # Test if a macro is needed for the library.
+ TRY_MACRO_FOR_LIBRARY(
+ "${ICONV_INCLUDE_DIR};${LIBXML2_INCLUDE_DIR}"
+ "ws2_32.lib;${ZLIB_LIBRARIES};${LIBICONV_PATH};${LIBXML2_LIBRARIES}"
+ COMPILES
+ "#include <stddef.h>\n#include <libxml/xmlreader.h>\nint main() {return xmlTextReaderRead((xmlTextReaderPtr)(void *)0);}"
+ "WITHOUT_LIBXML_STATIC;LIBXML_STATIC")
+ IF(NOT WITHOUT_LIBXML_STATIC AND LIBXML_STATIC)
+ ADD_DEFINITIONS(-DLIBXML_STATIC)
+ ENDIF(NOT WITHOUT_LIBXML_STATIC AND LIBXML_STATIC)
+ CMAKE_POP_CHECK_STATE() # Restore the state of the variables
+ELSE(LIBXML2_FOUND)
+ #
+ # Find Expat
+ #
+ FIND_PACKAGE(EXPAT)
+ IF(EXPAT_FOUND)
+ CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
+ INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${EXPAT_LIBRARIES})
+ SET(HAVE_LIBEXPAT 1)
+ LA_CHECK_INCLUDE_FILE("expat.h" HAVE_EXPAT_H)
+ CMAKE_POP_CHECK_STATE() # Restore the state of the variables
+ ENDIF(EXPAT_FOUND)
+ENDIF(LIBXML2_FOUND)
+MARK_AS_ADVANCED(CLEAR LIBXML2_INCLUDE_DIR)
+MARK_AS_ADVANCED(CLEAR LIBXML2_LIBRARIES)
+ENDIF()
+
+#
+# Check functions
+#
+CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
+IF (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ #
+ # During checking functions, we should use -fno-builtin to avoid the
+ # failure of function detection which failure is an error "conflicting
+ # types for built-in function" caused by using -Werror option.
+ #
+ SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-builtin")
+ENDIF ()
+CHECK_SYMBOL_EXISTS(_CrtSetReportMode "crtdbg.h" HAVE__CrtSetReportMode)
+CHECK_FUNCTION_EXISTS_GLIBC(chflags HAVE_CHFLAGS)
+CHECK_FUNCTION_EXISTS_GLIBC(chown HAVE_CHOWN)
+CHECK_FUNCTION_EXISTS_GLIBC(chroot HAVE_CHROOT)
+CHECK_FUNCTION_EXISTS_GLIBC(ctime_r HAVE_CTIME_R)
+CHECK_FUNCTION_EXISTS_GLIBC(dirfd HAVE_DIRFD)
+CHECK_FUNCTION_EXISTS_GLIBC(fchdir HAVE_FCHDIR)
+CHECK_FUNCTION_EXISTS_GLIBC(fchflags HAVE_FCHFLAGS)
+CHECK_FUNCTION_EXISTS_GLIBC(fchmod HAVE_FCHMOD)
+CHECK_FUNCTION_EXISTS_GLIBC(fchown HAVE_FCHOWN)
+CHECK_FUNCTION_EXISTS_GLIBC(fcntl HAVE_FCNTL)
+CHECK_FUNCTION_EXISTS_GLIBC(fdopendir HAVE_FDOPENDIR)
+CHECK_FUNCTION_EXISTS_GLIBC(fork HAVE_FORK)
+CHECK_FUNCTION_EXISTS_GLIBC(fstat HAVE_FSTAT)
+CHECK_FUNCTION_EXISTS_GLIBC(fstatat HAVE_FSTATAT)
+CHECK_FUNCTION_EXISTS_GLIBC(fstatfs HAVE_FSTATFS)
+CHECK_FUNCTION_EXISTS_GLIBC(fstatvfs HAVE_FSTATVFS)
+CHECK_FUNCTION_EXISTS_GLIBC(ftruncate HAVE_FTRUNCATE)
+CHECK_FUNCTION_EXISTS_GLIBC(futimens HAVE_FUTIMENS)
+CHECK_FUNCTION_EXISTS_GLIBC(futimes HAVE_FUTIMES)
+CHECK_FUNCTION_EXISTS_GLIBC(futimesat HAVE_FUTIMESAT)
+CHECK_FUNCTION_EXISTS_GLIBC(geteuid HAVE_GETEUID)
+CHECK_FUNCTION_EXISTS_GLIBC(getgrgid_r HAVE_GETGRGID_R)
+CHECK_FUNCTION_EXISTS_GLIBC(getgrnam_r HAVE_GETGRNAM_R)
+CHECK_FUNCTION_EXISTS_GLIBC(getpwnam_r HAVE_GETPWNAM_R)
+CHECK_FUNCTION_EXISTS_GLIBC(getpwuid_r HAVE_GETPWUID_R)
+CHECK_FUNCTION_EXISTS_GLIBC(getpid HAVE_GETPID)
+CHECK_FUNCTION_EXISTS_GLIBC(getvfsbyname HAVE_GETVFSBYNAME)
+CHECK_FUNCTION_EXISTS_GLIBC(gmtime_r HAVE_GMTIME_R)
+CHECK_FUNCTION_EXISTS_GLIBC(lchflags HAVE_LCHFLAGS)
+CHECK_FUNCTION_EXISTS_GLIBC(lchmod HAVE_LCHMOD)
+CHECK_FUNCTION_EXISTS_GLIBC(lchown HAVE_LCHOWN)
+CHECK_FUNCTION_EXISTS_GLIBC(link HAVE_LINK)
+CHECK_FUNCTION_EXISTS_GLIBC(localtime_r HAVE_LOCALTIME_R)
+CHECK_FUNCTION_EXISTS_GLIBC(lstat HAVE_LSTAT)
+CHECK_FUNCTION_EXISTS_GLIBC(lutimes HAVE_LUTIMES)
+CHECK_FUNCTION_EXISTS_GLIBC(mbrtowc HAVE_MBRTOWC)
+CHECK_FUNCTION_EXISTS_GLIBC(memmove HAVE_MEMMOVE)
+CHECK_FUNCTION_EXISTS_GLIBC(mkdir HAVE_MKDIR)
+CHECK_FUNCTION_EXISTS_GLIBC(mkfifo HAVE_MKFIFO)
+CHECK_FUNCTION_EXISTS_GLIBC(mknod HAVE_MKNOD)
+CHECK_FUNCTION_EXISTS_GLIBC(mkstemp HAVE_MKSTEMP)
+CHECK_FUNCTION_EXISTS_GLIBC(nl_langinfo HAVE_NL_LANGINFO)
+CHECK_FUNCTION_EXISTS_GLIBC(openat HAVE_OPENAT)
+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(select HAVE_SELECT)
+CHECK_FUNCTION_EXISTS_GLIBC(setenv HAVE_SETENV)
+CHECK_FUNCTION_EXISTS_GLIBC(setlocale HAVE_SETLOCALE)
+CHECK_FUNCTION_EXISTS_GLIBC(sigaction HAVE_SIGACTION)
+CHECK_FUNCTION_EXISTS_GLIBC(statfs HAVE_STATFS)
+CHECK_FUNCTION_EXISTS_GLIBC(statvfs HAVE_STATVFS)
+CHECK_FUNCTION_EXISTS_GLIBC(strchr HAVE_STRCHR)
+CHECK_FUNCTION_EXISTS_GLIBC(strdup HAVE_STRDUP)
+CHECK_FUNCTION_EXISTS_GLIBC(strerror HAVE_STRERROR)
+CHECK_FUNCTION_EXISTS_GLIBC(strncpy_s HAVE_STRNCPY_S)
+CHECK_FUNCTION_EXISTS_GLIBC(strrchr HAVE_STRRCHR)
+CHECK_FUNCTION_EXISTS_GLIBC(symlink HAVE_SYMLINK)
+CHECK_FUNCTION_EXISTS_GLIBC(timegm HAVE_TIMEGM)
+CHECK_FUNCTION_EXISTS_GLIBC(tzset HAVE_TZSET)
+CHECK_FUNCTION_EXISTS_GLIBC(unsetenv HAVE_UNSETENV)
+CHECK_FUNCTION_EXISTS_GLIBC(utime HAVE_UTIME)
+CHECK_FUNCTION_EXISTS_GLIBC(utimes HAVE_UTIMES)
+CHECK_FUNCTION_EXISTS_GLIBC(utimensat HAVE_UTIMENSAT)
+CHECK_FUNCTION_EXISTS_GLIBC(vfork HAVE_VFORK)
+CHECK_FUNCTION_EXISTS_GLIBC(wcrtomb HAVE_WCRTOMB)
+CHECK_FUNCTION_EXISTS_GLIBC(wcscmp HAVE_WCSCMP)
+CHECK_FUNCTION_EXISTS_GLIBC(wcscpy HAVE_WCSCPY)
+CHECK_FUNCTION_EXISTS_GLIBC(wcslen HAVE_WCSLEN)
+CHECK_FUNCTION_EXISTS_GLIBC(wctomb HAVE_WCTOMB)
+CHECK_FUNCTION_EXISTS_GLIBC(_ctime64_s HAVE__CTIME64_S)
+CHECK_FUNCTION_EXISTS_GLIBC(_fseeki64 HAVE__FSEEKI64)
+CHECK_FUNCTION_EXISTS_GLIBC(_get_timezone HAVE__GET_TIMEZONE)
+CHECK_FUNCTION_EXISTS_GLIBC(_localtime64_s HAVE__LOCALTIME64_S)
+CHECK_FUNCTION_EXISTS_GLIBC(_mkgmtime64 HAVE__MKGMTIME64)
+
+SET(CMAKE_REQUIRED_LIBRARIES "")
+CHECK_FUNCTION_EXISTS(cygwin_conv_path HAVE_CYGWIN_CONV_PATH)
+CHECK_FUNCTION_EXISTS(fseeko HAVE_FSEEKO)
+CHECK_FUNCTION_EXISTS(strerror_r HAVE_STRERROR_R)
+CHECK_FUNCTION_EXISTS(strftime HAVE_STRFTIME)
+CHECK_FUNCTION_EXISTS(vprintf HAVE_VPRINTF)
+CHECK_FUNCTION_EXISTS(wmemcmp HAVE_WMEMCMP)
+CHECK_FUNCTION_EXISTS(wmemcpy HAVE_WMEMCPY)
+
+CMAKE_POP_CHECK_STATE() # Restore the state of the variables
+
+# Make sure we have the POSIX version of readdir_r, not the
+# older 2-argument version.
+CHECK_C_SOURCE_COMPILES(
+ "#include <dirent.h>\nint main() {DIR *d = opendir(\".\"); struct dirent e,*r; return readdir_r(d,&e,&r);}"
+ HAVE_READDIR_R)
+
+
+# Only detect readlinkat() if we also have AT_FDCWD in unistd.h.
+# NOTE: linux requires fcntl.h for AT_FDCWD.
+CHECK_C_SOURCE_COMPILES(
+ "#include <fcntl.h>\n#include <unistd.h>\nint main() {char buf[10]; return readlinkat(AT_FDCWD, \"\", buf, 0);}"
+ HAVE_READLINKAT)
+
+
+# To verify major(), we need to both include the header
+# of interest and verify that the result can be linked.
+# CHECK_FUNCTION_EXISTS doesn't accept a header argument,
+# CHECK_SYMBOL_EXISTS doesn't test linkage.
+CHECK_C_SOURCE_COMPILES(
+ "#include <sys/mkdev.h>\nint main() { return major(256); }"
+ MAJOR_IN_MKDEV)
+CHECK_C_SOURCE_COMPILES(
+ "#include <sys/sysmacros.h>\nint main() { return major(256); }"
+ MAJOR_IN_SYSMACROS)
+
+IF(HAVE_STRERROR_R)
+ SET(HAVE_DECL_STRERROR_R 1)
+ENDIF(HAVE_STRERROR_R)
+
+#
+# Check defines
+#
+SET(headers "limits.h")
+IF(HAVE_STDINT_H)
+ LIST(APPEND headers "stdint.h")
+ENDIF(HAVE_STDINT_H)
+IF(HAVE_INTTYPES_H)
+ LIST(APPEND headers "inttypes.h")
+ENDIF(HAVE_INTTYPES_H)
+CHECK_SYMBOL_EXISTS(EFTYPE "errno.h" HAVE_EFTYPE)
+CHECK_SYMBOL_EXISTS(EILSEQ "errno.h" HAVE_EILSEQ)
+CHECK_SYMBOL_EXISTS(D_MD_ORDER "langinfo.h" HAVE_D_MD_ORDER)
+CHECK_SYMBOL_EXISTS(INT64_MAX "${headers}" HAVE_DECL_INT64_MAX)
+CHECK_SYMBOL_EXISTS(INT64_MIN "${headers}" HAVE_DECL_INT64_MIN)
+CHECK_SYMBOL_EXISTS(UINT32_MAX "${headers}" HAVE_DECL_UINT32_MAX)
+CHECK_SYMBOL_EXISTS(UINT64_MAX "${headers}" HAVE_DECL_UINT64_MAX)
+CHECK_SYMBOL_EXISTS(SIZE_MAX "${headers}" HAVE_DECL_SIZE_MAX)
+CHECK_SYMBOL_EXISTS(SSIZE_MAX "limits.h" HAVE_DECL_SSIZE_MAX)
+
+#
+# Check struct members
+#
+# Check for tm_gmtoff in struct tm
+CHECK_STRUCT_MEMBER("struct tm" tm_gmtoff
+ "time.h" HAVE_STRUCT_TM_TM_GMTOFF)
+CHECK_STRUCT_MEMBER("struct tm" __tm_gmtoff
+ "time.h" HAVE_STRUCT_TM___TM_GMTOFF)
+
+# Check for f_namemax in struct statfs
+CHECK_STRUCT_MEMBER("struct statfs" f_namemax
+ "sys/param.h;sys/mount.h" HAVE_STRUCT_STATFS_F_NAMEMAX)
+
+# Check for birthtime in struct stat
+CHECK_STRUCT_MEMBER("struct stat" st_birthtime
+ "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BIRTHTIME)
+
+# Check for high-resolution timestamps in struct stat
+CHECK_STRUCT_MEMBER("struct stat" st_birthtimespec.tv_nsec
+ "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC)
+CHECK_STRUCT_MEMBER("struct stat" st_mtimespec.tv_nsec
+ "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
+CHECK_STRUCT_MEMBER("struct stat" st_mtim.tv_nsec
+ "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
+CHECK_STRUCT_MEMBER("struct stat" st_mtime_n
+ "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIME_N)
+CHECK_STRUCT_MEMBER("struct stat" st_umtime
+ "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_UMTIME)
+CHECK_STRUCT_MEMBER("struct stat" st_mtime_usec
+ "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIME_USEC)
+# Check for block size support in struct stat
+CHECK_STRUCT_MEMBER("struct stat" st_blksize
+ "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BLKSIZE)
+# Check for st_flags in struct stat (BSD fflags)
+CHECK_STRUCT_MEMBER("struct stat" st_flags
+ "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_FLAGS)
+
+IF(HAVE_SYS_STATVFS_H)
+ CHECK_STRUCT_MEMBER("struct statvfs" f_iosize
+ "sys/types.h;sys/statvfs.h" HAVE_STRUCT_STATVFS_F_IOSIZE)
+ENDIF()
+
+#
+#
+CHECK_STRUCT_MEMBER("struct tm" tm_sec
+ "sys/types.h;sys/time.h;time.h" TIME_WITH_SYS_TIME)
+
+#
+# Check for integer types
+#
+#
+CHECK_TYPE_SIZE("short" SIZE_OF_SHORT)
+CHECK_TYPE_SIZE("int" SIZE_OF_INT)
+CHECK_TYPE_SIZE("long" SIZE_OF_LONG)
+CHECK_TYPE_SIZE("long long" SIZE_OF_LONG_LONG)
+
+CHECK_TYPE_SIZE("unsigned short" SIZE_OF_UNSIGNED_SHORT)
+CHECK_TYPE_SIZE("unsigned" SIZE_OF_UNSIGNED)
+CHECK_TYPE_SIZE("unsigned long" SIZE_OF_UNSIGNED_LONG)
+CHECK_TYPE_SIZE("unsigned long long" SIZE_OF_UNSIGNED_LONG_LONG)
+
+CHECK_TYPE_SIZE("__int64" __INT64)
+CHECK_TYPE_SIZE("unsigned __int64" UNSIGNED___INT64)
+
+CHECK_TYPE_SIZE(int16_t INT16_T)
+CHECK_TYPE_SIZE(int32_t INT32_T)
+CHECK_TYPE_SIZE(int64_t INT64_T)
+CHECK_TYPE_SIZE(intmax_t INTMAX_T)
+CHECK_TYPE_SIZE(uint8_t UINT8_T)
+CHECK_TYPE_SIZE(uint16_t UINT16_T)
+CHECK_TYPE_SIZE(uint32_t UINT32_T)
+CHECK_TYPE_SIZE(uint64_t UINT64_T)
+CHECK_TYPE_SIZE(uintmax_t UINTMAX_T)
+
+CHECK_TYPE_SIZE(dev_t DEV_T)
+IF(NOT HAVE_DEV_T)
+ IF(MSVC)
+ SET(dev_t "unsigned int")
+ ENDIF(MSVC)
+ENDIF(NOT HAVE_DEV_T)
+#
+CHECK_TYPE_SIZE(gid_t GID_T)
+IF(NOT HAVE_GID_T)
+ IF(WIN32)
+ SET(gid_t "short")
+ ELSE(WIN32)
+ SET(gid_t "unsigned int")
+ ENDIF(WIN32)
+ENDIF(NOT HAVE_GID_T)
+#
+CHECK_TYPE_SIZE(id_t ID_T)
+IF(NOT HAVE_ID_T)
+ IF(WIN32)
+ SET(id_t "short")
+ ELSE(WIN32)
+ SET(id_t "unsigned int")
+ ENDIF(WIN32)
+ENDIF(NOT HAVE_ID_T)
+#
+CHECK_TYPE_SIZE(mode_t MODE_T)
+IF(NOT HAVE_MODE_T)
+ IF(WIN32)
+ SET(mode_t "unsigned short")
+ ELSE(WIN32)
+ SET(mode_t "int")
+ ENDIF(WIN32)
+ENDIF(NOT HAVE_MODE_T)
+#
+CHECK_TYPE_SIZE(off_t OFF_T)
+IF(NOT HAVE_OFF_T)
+ SET(off_t "__int64")
+ENDIF(NOT HAVE_OFF_T)
+#
+CHECK_TYPE_SIZE(size_t SIZE_T)
+IF(NOT HAVE_SIZE_T)
+ IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ SET(size_t "uint64_t")
+ ELSE("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ SET(size_t "uint32_t")
+ ENDIF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ENDIF(NOT HAVE_SIZE_T)
+#
+CHECK_TYPE_SIZE(ssize_t SSIZE_T)
+IF(NOT HAVE_SSIZE_T)
+ IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ SET(ssize_t "int64_t")
+ ELSE("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ SET(ssize_t "long")
+ ENDIF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ENDIF(NOT HAVE_SSIZE_T)
+#
+CHECK_TYPE_SIZE(uid_t UID_T)
+IF(NOT HAVE_UID_T)
+ IF(WIN32)
+ SET(uid_t "short")
+ ELSE(WIN32)
+ SET(uid_t "unsigned int")
+ ENDIF(WIN32)
+ENDIF(NOT HAVE_UID_T)
+#
+CHECK_TYPE_SIZE(pid_t PID_T)
+IF(NOT HAVE_PID_T)
+ IF(WIN32)
+ SET(pid_t "int")
+ ELSE(WIN32)
+ MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?")
+ ENDIF(WIN32)
+ENDIF(NOT HAVE_PID_T)
+#
+CHECK_TYPE_SIZE(intptr_t INTPTR_T)
+IF(NOT HAVE_INTPTR_T)
+ IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ SET(intptr_t "int64_t")
+ ELSE()
+ SET(intptr_t "int32_t")
+ ENDIF()
+ENDIF(NOT HAVE_INTPTR_T)
+#
+CHECK_TYPE_SIZE(uintptr_t UINTPTR_T)
+IF(NOT HAVE_UINTPTR_T)
+ IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ SET(uintptr_t "uint64_t")
+ ELSE()
+ SET(uintptr_t "uint32_t")
+ ENDIF()
+ENDIF(NOT HAVE_UINTPTR_T)
+#
+CHECK_TYPE_SIZE(wchar_t SIZEOF_WCHAR_T)
+IF(HAVE_SIZEOF_WCHAR_T)
+ SET(HAVE_WCHAR_T 1)
+ENDIF(HAVE_SIZEOF_WCHAR_T)
+#
+# Check if _FILE_OFFSET_BITS macro needed for large files
+#
+CHECK_FILE_OFFSET_BITS()
+
+#
+# Check for Extended Attribute libraries, headers, and functions
+#
+IF(ENABLE_XATTR)
+ LA_CHECK_INCLUDE_FILE(attr/xattr.h HAVE_ATTR_XATTR_H)
+ LA_CHECK_INCLUDE_FILE(sys/xattr.h HAVE_SYS_XATTR_H)
+ LA_CHECK_INCLUDE_FILE(sys/extattr.h HAVE_SYS_EXTATTR_H)
+ CHECK_LIBRARY_EXISTS(attr "setxattr" "" HAVE_LIBATTR)
+ IF(HAVE_LIBATTR)
+ SET(CMAKE_REQUIRED_LIBRARIES "attr")
+ ENDIF(HAVE_LIBATTR)
+ CHECK_SYMBOL_EXISTS(EXTATTR_NAMESPACE_USER "sys/types.h;sys/extattr.h" HAVE_DECL_EXTATTR_NAMESPACE_USER)
+ CHECK_FUNCTION_EXISTS_GLIBC(extattr_get_file HAVE_EXTATTR_GET_FILE)
+ CHECK_FUNCTION_EXISTS_GLIBC(extattr_list_file HAVE_EXTATTR_LIST_FILE)
+ CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_fd HAVE_EXTATTR_SET_FD)
+ CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_file HAVE_EXTATTR_SET_FILE)
+ CHECK_FUNCTION_EXISTS_GLIBC(fgetxattr HAVE_FGETXATTR)
+ CHECK_FUNCTION_EXISTS_GLIBC(flistxattr HAVE_FLISTXATTR)
+ CHECK_FUNCTION_EXISTS_GLIBC(fsetxattr HAVE_FSETXATTR)
+ CHECK_FUNCTION_EXISTS_GLIBC(getxattr HAVE_GETXATTR)
+ CHECK_FUNCTION_EXISTS_GLIBC(lgetxattr HAVE_LGETXATTR)
+ CHECK_FUNCTION_EXISTS_GLIBC(listxattr HAVE_LISTXATTR)
+ CHECK_FUNCTION_EXISTS_GLIBC(llistxattr HAVE_LLISTXATTR)
+ CHECK_FUNCTION_EXISTS_GLIBC(lsetxattr HAVE_LSETXATTR)
+ CHECK_FUNCTION_EXISTS_GLIBC(fgetea HAVE_FGETEA)
+ CHECK_FUNCTION_EXISTS_GLIBC(flistea HAVE_FLISTEA)
+ CHECK_FUNCTION_EXISTS_GLIBC(fsetea HAVE_FSETEA)
+ CHECK_FUNCTION_EXISTS_GLIBC(getea HAVE_GETEA)
+ CHECK_FUNCTION_EXISTS_GLIBC(lgetea HAVE_LGETEA)
+ CHECK_FUNCTION_EXISTS_GLIBC(listea HAVE_LISTEA)
+ CHECK_FUNCTION_EXISTS_GLIBC(llistea HAVE_LLISTEA)
+ CHECK_FUNCTION_EXISTS_GLIBC(lsetea HAVE_LSETEA)
+ELSE(ENABLE_XATTR)
+ SET(HAVE_ATTR_LIB FALSE)
+ SET(HAVE_ATTR_XATTR_H FALSE)
+ SET(HAVE_DECL_EXTATTR_NAMESPACE_USER FALSE)
+ SET(HAVE_EXTATTR_GET_FILE FALSE)
+ SET(HAVE_EXTATTR_LIST_FILE FALSE)
+ SET(HAVE_EXTATTR_SET_FD FALSE)
+ SET(HAVE_EXTATTR_SET_FILE FALSE)
+ SET(HAVE_FGETEA FALSE)
+ SET(HAVE_FGETXATTR FALSE)
+ SET(HAVE_FLISTEA FALSE)
+ SET(HAVE_FLISTXATTR FALSE)
+ SET(HAVE_FSETEA FALSE)
+ SET(HAVE_FSETXATTR FALSE)
+ SET(HAVE_GETEA FALSE)
+ SET(HAVE_GETXATTR FALSE)
+ SET(HAVE_LGETEA FALSE)
+ SET(HAVE_LGETXATTR FALSE)
+ SET(HAVE_LISTEA FALSE)
+ SET(HAVE_LISTXATTR FALSE)
+ SET(HAVE_LLISTEA FALSE)
+ SET(HAVE_LLISTXATTR FALSE)
+ SET(HAVE_LSETEA FALSE)
+ SET(HAVE_LSETXATTR FALSE)
+ SET(HAVE_SYS_EXTATTR_H FALSE)
+ SET(HAVE_SYS_XATTR_H FALSE)
+ENDIF(ENABLE_XATTR)
+
+#
+# Check for ACL libraries, headers, and functions
+#
+# The ACL support in libarchive is written against the POSIX1e draft,
+# which was never officially approved and varies quite a bit across
+# platforms. Worse, some systems have completely non-POSIX acl functions,
+# which makes the following checks rather more complex than I would like.
+#
+IF(ENABLE_ACL)
+ CHECK_LIBRARY_EXISTS(acl "acl_get_file" "" HAVE_LIBACL)
+ IF(HAVE_LIBACL)
+ SET(CMAKE_REQUIRED_LIBRARIES "acl")
+ FIND_LIBRARY(ACL_LIBRARY NAMES acl)
+ LIST(APPEND ADDITIONAL_LIBS ${ACL_LIBRARY})
+ ENDIF(HAVE_LIBACL)
+ #
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_create_entry HAVE_ACL_CREATE_ENTRY)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_init HAVE_ACL_INIT)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_set_fd HAVE_ACL_SET_FD)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_set_fd_np HAVE_ACL_SET_FD_NP)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_set_file HAVE_ACL_SET_FILE)
+ CHECK_TYPE_EXISTS(acl_permset_t "${INCLUDES}" HAVE_ACL_PERMSET_T)
+
+ # The "acl_get_perm()" function was omitted from the POSIX draft.
+ # (It's a pretty obvious oversight; otherwise, there's no way to
+ # test for specific permissions in a permset.) Linux uses the obvious
+ # name, FreeBSD adds _np to mark it as "non-Posix extension."
+ # Test for both as a double-check that we really have POSIX-style ACL support.
+ CHECK_FUNCTION_EXISTS(acl_get_perm HAVE_ACL_GET_PERM)
+ CHECK_FUNCTION_EXISTS(acl_get_perm_np HAVE_ACL_GET_PERM_NP)
+ CHECK_FUNCTION_EXISTS(acl_get_link HAVE_ACL_GET_LINK)
+ CHECK_FUNCTION_EXISTS(acl_get_link_np HAVE_ACL_GET_LINK_NP)
+ CHECK_FUNCTION_EXISTS(acl_is_trivial_np HAVE_ACL_IS_TRIVIAL_NP)
+ CHECK_FUNCTION_EXISTS(acl_set_link_np HAVE_ACL_SET_LINK_NP)
+
+ # MacOS has an acl.h that isn't POSIX. It can be detected by
+ # checking for ACL_USER
+ CHECK_SYMBOL_EXISTS(ACL_USER "${INCLUDES}" HAVE_ACL_USER)
+ELSE(ENABLE_ACL)
+ # If someone runs cmake, then disables ACL support, we need
+ # to forcibly override the cached values for these.
+ SET(HAVE_ACL_CREATE_ENTRY FALSE)
+ SET(HAVE_ACL_GET_LINK FALSE)
+ SET(HAVE_ACL_GET_LINK_NP FALSE)
+ SET(HAVE_ACL_GET_PERM FALSE)
+ SET(HAVE_ACL_GET_PERM_NP FALSE)
+ SET(HAVE_ACL_INIT FALSE)
+ SET(HAVE_ACL_LIB FALSE)
+ SET(HAVE_ACL_PERMSET_T FALSE)
+ SET(HAVE_ACL_SET_FD FALSE)
+ SET(HAVE_ACL_SET_FD_NP FALSE)
+ SET(HAVE_ACL_SET_FILE FALSE)
+ SET(HAVE_ACL_USER FALSE)
+ENDIF(ENABLE_ACL)
+
+#
+# Check MD5/RMD160/SHA support
+# NOTE: Crypto checks must be run last before generating config.h
+#
+CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA384;SHA512" LIBC)
+CHECK_CRYPTO("SHA256;SHA384;SHA512" LIBC2)
+CHECK_CRYPTO("SHA256;SHA384;SHA512" LIBC3)
+CHECK_CRYPTO("MD5;SHA1;SHA256;SHA384;SHA512" LIBSYSTEM)
+CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA384;SHA512" NETTLE)
+CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA384;SHA512" OPENSSL)
+
+# Libmd has to be probed after OpenSSL.
+CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA512" LIBMD)
+
+CHECK_CRYPTO_WIN("MD5;SHA1;SHA256;SHA384;SHA512")
+
+# Generate "config.h" from "build/cmake/config.h.in"
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
+ADD_DEFINITIONS(-DHAVE_CONFIG_H)
+
+#
+# Register installation of PDF documents.
+#
+IF(WIN32 AND NOT CYGWIN)
+ #
+ # On Windows platform, It's better that we install PDF documents
+ # on one's computer.
+ # These PDF documents are available in the release package.
+ #
+ IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf)
+ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf
+ DESTINATION share/man
+ FILES_MATCHING PATTERN "*.pdf"
+ )
+ ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf)
+ENDIF(WIN32 AND NOT CYGWIN)
+#
+#
+#
+INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/libarchive)
+#
+IF(MSVC)
+ ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
+ENDIF(MSVC)
+
+# We need CoreServices on Mac OS.
+IF(APPLE)
+ LIST(APPEND ADDITIONAL_LIBS "-framework CoreServices")
+ENDIF(APPLE)
+
+add_subdirectory(libarchive)
+
+install(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmlibarchive)
diff --git a/Utilities/cmlibarchive/COPYING b/Utilities/cmlibarchive/COPYING
new file mode 100644
index 0000000000..b258806002
--- /dev/null
+++ b/Utilities/cmlibarchive/COPYING
@@ -0,0 +1,60 @@
+The libarchive distribution as a whole is Copyright by Tim Kientzle
+and is subject to the copyright notice reproduced at the bottom of
+this file.
+
+Each individual file in this distribution should have a clear
+copyright/licensing statement at the beginning of the file. If any do
+not, please let me know and I will rectify it. The following is
+intended to summarize the copyright status of the individual files;
+the actual statements in the files are controlling.
+
+* Except as listed below, all C sources (including .c and .h files)
+ and documentation files are subject to the copyright notice reproduced
+ at the bottom of this file.
+
+* The following source files are also subject in whole or in part to
+ a 3-clause UC Regents copyright; please read the individual source
+ files for details:
+ libarchive/archive_entry.c
+ libarchive/archive_read_support_filter_compress.c
+ libarchive/archive_write_set_filter_compress.c
+ libarchive/mtree.5
+ tar/matching.c
+
+* The following source files are in the public domain:
+ tar/getdate.c
+
+* The build files---including Makefiles, configure scripts,
+ and auxiliary scripts used as part of the compile process---have
+ widely varying licensing terms. Please check individual files before
+ distributing them to see if those restrictions apply to you.
+
+I intend for all new source code to use the license below and hope over
+time to replace code with other licenses with new implementations that
+do use the license below. The varying licensing of the build scripts
+seems to be an unavoidable mess.
+
+
+Copyright (c) 2003-2009 <author(s)>
+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
+ in this position and unchanged.
+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.
diff --git a/Utilities/cmlibarchive/CTestConfig.cmake b/Utilities/cmlibarchive/CTestConfig.cmake
new file mode 100644
index 0000000000..7a09742db0
--- /dev/null
+++ b/Utilities/cmlibarchive/CTestConfig.cmake
@@ -0,0 +1,11 @@
+# TODO: This file should be moved into the build/cmake directory...
+
+# The libarchive CDash page appears at
+# http://my.cdash.org/index.php?project=libarchive
+set(CTEST_PROJECT_NAME "libarchive")
+set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
+
+set(CTEST_DROP_METHOD "http")
+set(CTEST_DROP_SITE "my.cdash.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=libarchive")
+set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/Utilities/cmlibarchive/README-CMake.txt b/Utilities/cmlibarchive/README-CMake.txt
new file mode 100644
index 0000000000..8f3b29b715
--- /dev/null
+++ b/Utilities/cmlibarchive/README-CMake.txt
@@ -0,0 +1,66 @@
+The Utilities/cmlibarchive directory contains a reduced distribution
+of the libarchive source tree with only the library source code and
+CMake build system. It is not a submodule; the actual content is part
+of our source tree and changes can be made and committed directly.
+
+We update from upstream using Git's "subtree" merge strategy. A
+special branch contains commits of upstream libarchive snapshots and
+nothing else. No Git ref points explicitly to the head of this
+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
+
+Use a temporary directory to checkout the branch:
+
+ mkdir libarchive-tmp
+ cd libarchive-tmp
+ git init
+ git pull .. libarchive-upstream
+ rm -rf *
+
+Now place the (reduced) libarchive content in this directory. See
+instructions shown by
+
+ git log 37f225b7
+
+for help extracting the content from the upstream svn repo. Then run
+the following commands to commit the new version. Substitute the
+appropriate date and version number:
+
+ git add --all
+
+ GIT_AUTHOR_NAME='LibArchive Upstream' \
+ GIT_AUTHOR_EMAIL='libarchive-discuss@googlegroups.com' \
+ GIT_AUTHOR_DATE='Mon Apr 14 19:19:05 2014 -0700' \
+ git commit -m 'libarchive 3.1.2-246-ga5a5d28b (reduced)' &&
+ git commit --amend
+
+Edit the commit message to describe the procedure used to obtain the
+content. Then push the changes back up to the main local repository:
+
+ git push .. HEAD:libarchive-upstream
+ cd ..
+ rm -rf libarchive-tmp
+
+Create a topic in the main repository on which to perform the update:
+
+ git checkout -b update-libarchive master
+
+Merge the libarchive-upstream branch as a subtree:
+
+ git merge -s recursive -X subtree=Utilities/cmlibarchive \
+ libarchive-upstream
+
+If there are conflicts, resolve them and commit. Build and test the
+tree. Commit any additional changes needed to succeed.
+
+Finally, run
+
+ git rev-parse --short=8 libarchive-upstream
+
+to get the commit from which the libarchive-upstream branch must be started
+on the next update. Edit the "git branch libarchive-upstream" line above to
+record it, and commit this file.
diff --git a/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.c b/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.c
new file mode 100644
index 0000000000..d948fecf2b
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.c
@@ -0,0 +1,14 @@
+#include <sys/types.h>
+
+#define KB ((off_t)1024)
+#define MB ((off_t)1024 * KB)
+#define GB ((off_t)1024 * MB)
+#define TB ((off_t)1024 * GB)
+int t2[(((64 * GB -1) % 671088649) == 268434537)
+ && (((TB - (64 * GB -1) + 255) % 1792151290) == 305159546)? 1: -1];
+
+int main()
+{
+ ;
+ return 0;
+}
diff --git a/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.cmake b/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.cmake
new file mode 100644
index 0000000000..b347c9366e
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.cmake
@@ -0,0 +1,44 @@
+# - Check if _FILE_OFFSET_BITS macro needed for large files
+# CHECK_FILE_OFFSET_BITS ()
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# Copyright (c) 2009, Michihiro NAKAJIMA
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+#INCLUDE(CheckCXXSourceCompiles)
+
+GET_FILENAME_COMPONENT(_selfdir_CheckFileOffsetBits
+ "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+MACRO (CHECK_FILE_OFFSET_BITS)
+ IF(NOT DEFINED _FILE_OFFSET_BITS)
+ MESSAGE(STATUS "Checking _FILE_OFFSET_BITS for large files")
+ TRY_COMPILE(__WITHOUT_FILE_OFFSET_BITS_64
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
+ IF(NOT __WITHOUT_FILE_OFFSET_BITS_64)
+ TRY_COMPILE(__WITH_FILE_OFFSET_BITS_64
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_FILE_OFFSET_BITS=64)
+ ENDIF(NOT __WITHOUT_FILE_OFFSET_BITS_64)
+
+ IF(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64)
+ SET(_FILE_OFFSET_BITS 64 CACHE INTERNAL "_FILE_OFFSET_BITS macro needed for large files")
+ MESSAGE(STATUS "Checking _FILE_OFFSET_BITS for large files - needed")
+ ELSE(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64)
+ SET(_FILE_OFFSET_BITS "" CACHE INTERNAL "_FILE_OFFSET_BITS macro needed for large files")
+ MESSAGE(STATUS "Checking _FILE_OFFSET_BITS for large files - not needed")
+ ENDIF(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64)
+ ENDIF(NOT DEFINED _FILE_OFFSET_BITS)
+
+ENDMACRO (CHECK_FILE_OFFSET_BITS)
+
diff --git a/Utilities/cmlibarchive/build/cmake/CheckFuncs.cmake b/Utilities/cmlibarchive/build/cmake/CheckFuncs.cmake
new file mode 100644
index 0000000000..84cc881e3c
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/CheckFuncs.cmake
@@ -0,0 +1,49 @@
+# Check if the system has the specified function; treat glibc "stub"
+# functions as nonexistent:
+# CHECK_FUNCTION_EXISTS_GLIBC (FUNCTION FUNCVAR)
+#
+# FUNCTION - the function(s) where the prototype should be declared
+# FUNCVAR - variable to define if the function does exist
+#
+# In particular, this understands the glibc convention of
+# defining macros __stub_XXXX or __stub___XXXX if the function
+# does appear in the library but is merely a stub that does nothing.
+# By detecting this case, we can select alternate behavior on
+# platforms that don't support this functionality.
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# Copyright (c) 2009, Michihiro NAKAJIMA
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+INCLUDE(CheckFunctionExists)
+GET_FILENAME_COMPONENT(_selfdir_CheckFunctionExistsGlibc
+ "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+MACRO (CHECK_FUNCTION_EXISTS_GLIBC _FUNC _FUNCVAR)
+ IF(NOT DEFINED ${_FUNCVAR})
+ SET(CHECK_STUB_FUNC_1 "__stub_${_FUNC}")
+ SET(CHECK_STUB_FUNC_2 "__stub___${_FUNC}")
+ CONFIGURE_FILE( ${_selfdir_CheckFunctionExistsGlibc}/CheckFuncs_stub.c.in
+ ${CMAKE_CURRENT_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c)
+ TRY_COMPILE(__stub
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ CMAKE_FLAGS
+ -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
+ "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}")
+ IF (__stub)
+ SET("${_FUNCVAR}" "" CACHE INTERNAL "Have function ${_FUNC}")
+ ELSE (__stub)
+ CHECK_FUNCTION_EXISTS("${_FUNC}" "${_FUNCVAR}")
+ ENDIF (__stub)
+ ENDIF(NOT DEFINED ${_FUNCVAR})
+ENDMACRO (CHECK_FUNCTION_EXISTS_GLIBC)
+
diff --git a/Utilities/cmlibarchive/build/cmake/CheckFuncs_stub.c.in b/Utilities/cmlibarchive/build/cmake/CheckFuncs_stub.c.in
new file mode 100644
index 0000000000..50da414b5f
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/CheckFuncs_stub.c.in
@@ -0,0 +1,16 @@
+#ifdef __STDC__
+#include <limits.h>
+#else
+#include <assert.h>
+#endif
+
+int
+main()
+{
+#if defined ${CHECK_STUB_FUNC_1} || defined ${CHECK_STUB_FUNC_2}
+ return 0;
+#else
+this system have stub
+ return 0;
+#endif
+}
diff --git a/Utilities/cmlibarchive/build/cmake/CheckHeaderDirent.cmake b/Utilities/cmlibarchive/build/cmake/CheckHeaderDirent.cmake
new file mode 100644
index 0000000000..e9a7ea8553
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/CheckHeaderDirent.cmake
@@ -0,0 +1,32 @@
+# - Check if the system has the specified type
+# CHECK_HEADER_DIRENT (HEADER1 HEARDER2 ...)
+#
+# HEADER - the header(s) where the prototype should be declared
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# Copyright (c) 2009, Michihiro NAKAJIMA
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+INCLUDE(CheckTypeExists)
+
+MACRO (CHECK_HEADER_DIRENT)
+ CHECK_TYPE_EXISTS("DIR *" dirent.h HAVE_DIRENT_H)
+ IF(NOT HAVE_DIRENT_H)
+ CHECK_TYPE_EXISTS("DIR *" sys/ndir.h HAVE_SYS_NDIR_H)
+ IF(NOT HAVE_SYS_NDIR_H)
+ CHECK_TYPE_EXISTS("DIR *" ndir.h HAVE_NDIR_H)
+ IF(NOT HAVE_NDIR_H)
+ CHECK_TYPE_EXISTS("DIR *" sys/dir.h HAVE_SYS_DIR_H)
+ ENDIF(NOT HAVE_NDIR_H)
+ ENDIF(NOT HAVE_SYS_NDIR_H)
+ ENDIF(NOT HAVE_DIRENT_H)
+ENDMACRO (CHECK_HEADER_DIRENT)
+
diff --git a/Utilities/cmlibarchive/build/cmake/CheckStructMember.cmake b/Utilities/cmlibarchive/build/cmake/CheckStructMember.cmake
new file mode 100644
index 0000000000..05ddb3a11f
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/CheckStructMember.cmake
@@ -0,0 +1,43 @@
+# - Check if the given struct or class has the specified member variable
+# CHECK_STRUCT_MEMBER (STRUCT MEMBER HEADER VARIABLE)
+#
+# STRUCT - the name of the struct or class you are interested in
+# MEMBER - the member which existence you want to check
+# HEADER - the header(s) where the prototype should be declared
+# VARIABLE - variable to store the result
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+
+# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+INCLUDE(CheckCSourceCompiles)
+
+MACRO (CHECK_STRUCT_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
+ SET(_INCLUDE_FILES)
+ FOREACH (it ${_HEADER})
+ SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
+ ENDFOREACH (it)
+
+ SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
+${_INCLUDE_FILES}
+int main()
+{
+ static ${_STRUCT} tmp;
+ if (sizeof(tmp.${_MEMBER}))
+ return 0;
+ return 0;
+}
+")
+ CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
+
+ENDMACRO (CHECK_STRUCT_MEMBER)
+
diff --git a/Utilities/cmlibarchive/build/cmake/CheckTypeExists.cmake b/Utilities/cmlibarchive/build/cmake/CheckTypeExists.cmake
new file mode 100644
index 0000000000..b05234fd87
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/CheckTypeExists.cmake
@@ -0,0 +1,42 @@
+# - Check if the system has the specified type
+# CHECK_TYPE_EXISTS (TYPE HEADER VARIABLE)
+#
+# TYPE - the name of the type or struct or class you are interested in
+# HEADER - the header(s) where the prototype should be declared
+# VARIABLE - variable to store the result
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# Copyright (c) 2009, Michihiro NAKAJIMA
+# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+INCLUDE(CheckCSourceCompiles)
+
+MACRO (CHECK_TYPE_EXISTS _TYPE _HEADER _RESULT)
+ SET(_INCLUDE_FILES)
+ FOREACH (it ${_HEADER})
+ SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
+ ENDFOREACH (it)
+
+ SET(_CHECK_TYPE_EXISTS_SOURCE_CODE "
+${_INCLUDE_FILES}
+int main()
+{
+ static ${_TYPE} tmp;
+ if (sizeof(tmp))
+ return 0;
+ return 0;
+}
+")
+ CHECK_C_SOURCE_COMPILES("${_CHECK_TYPE_EXISTS_SOURCE_CODE}" ${_RESULT})
+
+ENDMACRO (CHECK_TYPE_EXISTS)
+
diff --git a/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake b/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake
new file mode 100644
index 0000000000..f96bbef00f
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake
@@ -0,0 +1,31 @@
+# - Generate a libarchive.pc like autotools for pkg-config
+#
+
+# Set the required variables (we use the same input file as autotools)
+SET(prefix ${CMAKE_INSTALL_PREFIX})
+SET(exec_prefix \${prefix})
+SET(libdir \${exec_prefix}/lib)
+SET(includedir \${prefix}/include)
+# Now, this is not particularly pretty, nor is it terribly accurate...
+# Loop over all our additional libs
+FOREACH(mylib ${ADDITIONAL_LIBS})
+ # Extract the filename from the absolute path
+ GET_FILENAME_COMPONENT(mylib_name ${mylib} NAME_WE)
+ # Strip the lib prefix
+ STRING(REGEX REPLACE "^lib" "" mylib_name ${mylib_name})
+ # Append it to our LIBS string
+ SET(LIBS "${LIBS} -l${mylib_name}")
+ENDFOREACH()
+# libxml2 is easier, since it's already using pkg-config
+FOREACH(mylib ${PC_LIBXML_STATIC_LDFLAGS})
+ SET(LIBS "${LIBS} ${mylib}")
+ENDFOREACH()
+# FIXME: The order of the libraries doesn't take dependencies into account,
+# thus there's a good chance it'll make some binutils versions unhappy...
+# This only affects Libs.private (looked up for static builds) though.
+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")
diff --git a/Utilities/cmlibarchive/build/cmake/FindLZMA.cmake b/Utilities/cmlibarchive/build/cmake/FindLZMA.cmake
new file mode 100644
index 0000000000..0b46b2cdd1
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/FindLZMA.cmake
@@ -0,0 +1,48 @@
+# - Find lzma and lzmadec
+# Find the native LZMA includes and library
+#
+# LZMA_INCLUDE_DIR - where to find lzma.h, etc.
+# LZMA_LIBRARIES - List of libraries when using liblzma.
+# LZMA_FOUND - True if liblzma found.
+# LZMADEC_INCLUDE_DIR - where to find lzmadec.h, etc.
+# LZMADEC_LIBRARIES - List of libraries when using liblzmadec.
+# LZMADEC_FOUND - True if liblzmadec found.
+
+IF (LZMA_INCLUDE_DIR)
+ # Already in cache, be silent
+ SET(LZMA_FIND_QUIETLY TRUE)
+ENDIF (LZMA_INCLUDE_DIR)
+
+FIND_PATH(LZMA_INCLUDE_DIR lzma.h)
+FIND_LIBRARY(LZMA_LIBRARY NAMES lzma liblzma)
+
+# handle the QUIETLY and REQUIRED arguments and set LZMA_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZMA DEFAULT_MSG LZMA_LIBRARY LZMA_INCLUDE_DIR)
+
+IF(LZMA_FOUND)
+ SET( LZMA_LIBRARIES ${LZMA_LIBRARY} )
+ELSE(LZMA_FOUND)
+ SET( LZMA_LIBRARIES )
+
+ IF (LZMADEC_INCLUDE_DIR)
+ # Already in cache, be silent
+ SET(LZMADEC_FIND_QUIETLY TRUE)
+ ENDIF (LZMADEC_INCLUDE_DIR)
+
+ FIND_PATH(LZMADEC_INCLUDE_DIR lzmadec.h)
+ FIND_LIBRARY(LZMADEC_LIBRARY NAMES lzmadec )
+
+ # handle the QUIETLY and REQUIRED arguments and set LZMADEC_FOUND to TRUE if
+ # all listed variables are TRUE
+ INCLUDE(FindPackageHandleStandardArgs)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZMADEC DEFAULT_MSG LZMADEC_LIBRARY
+ LZMADEC_INCLUDE_DIR)
+
+ IF(LZMADEC_FOUND)
+ SET( LZMADEC_LIBRARIES ${LZMADEC_LIBRARY} )
+ ELSE(LZMADEC_FOUND)
+ SET( LZMADEC_LIBRARIES )
+ ENDIF(LZMADEC_FOUND)
+ENDIF(LZMA_FOUND)
diff --git a/Utilities/cmlibarchive/build/cmake/FindLibGCC.cmake b/Utilities/cmlibarchive/build/cmake/FindLibGCC.cmake
new file mode 100644
index 0000000000..7985f2b003
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/FindLibGCC.cmake
@@ -0,0 +1,22 @@
+# - Find libgcc
+# Find the libgcc library.
+#
+# LIBGCC_LIBRARIES - List of libraries when using libgcc
+# LIBGCC_FOUND - True if libgcc found.
+
+IF (LIBGCC_LIBRARY)
+ # Already in cache, be silent
+ SET(LIBGCC_FIND_QUIETLY TRUE)
+ENDIF (LIBGCC_LIBRARY)
+
+FIND_LIBRARY(LIBGCC_LIBRARY NAMES gcc libgcc)
+
+# handle the QUIETLY and REQUIRED arguments and set LIBGCC_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBGCC DEFAULT_MSG LIBGCC_LIBRARY)
+
+IF(LIBGCC_FOUND)
+ SET(LIBGCC_LIBRARIES ${LIBGCC_LIBRARY})
+ SET(HAVE_LIBGCC 1)
+ENDIF(LIBGCC_FOUND)
diff --git a/Utilities/cmlibarchive/build/cmake/FindNettle.cmake b/Utilities/cmlibarchive/build/cmake/FindNettle.cmake
new file mode 100644
index 0000000000..1f66610f01
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/FindNettle.cmake
@@ -0,0 +1,23 @@
+# - Find Nettle
+# Find the Nettle include directory and library
+#
+# NETTLE_INCLUDE_DIR - where to find <nettle/sha.h>, etc.
+# NETTLE_LIBRARIES - List of libraries when using libnettle.
+# NETTLE_FOUND - True if libnettle found.
+
+IF (NETTLE_INCLUDE_DIR)
+ # Already in cache, be silent
+ SET(NETTLE_FIND_QUIETLY TRUE)
+ENDIF (NETTLE_INCLUDE_DIR)
+
+FIND_PATH(NETTLE_INCLUDE_DIR nettle/md5.h nettle/ripemd160.h nettle/sha.h)
+FIND_LIBRARY(NETTLE_LIBRARY NAMES nettle libnettle)
+
+# handle the QUIETLY and REQUIRED arguments and set NETTLE_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(NETTLE DEFAULT_MSG NETTLE_LIBRARY NETTLE_INCLUDE_DIR)
+
+IF(NETTLE_FOUND)
+ SET(NETTLE_LIBRARIES ${NETTLE_LIBRARY})
+ENDIF(NETTLE_FOUND)
diff --git a/Utilities/cmlibarchive/build/cmake/FindPCREPOSIX.cmake b/Utilities/cmlibarchive/build/cmake/FindPCREPOSIX.cmake
new file mode 100644
index 0000000000..7cc40ec0fb
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/FindPCREPOSIX.cmake
@@ -0,0 +1,34 @@
+# - Find pcreposix
+# Find the native PCRE and PCREPOSIX include and libraries
+#
+# PCRE_INCLUDE_DIR - where to find pcreposix.h, etc.
+# PCREPOSIX_LIBRARIES - List of libraries when using libpcreposix.
+# PCRE_LIBRARIES - List of libraries when using libpcre.
+# PCREPOSIX_FOUND - True if libpcreposix found.
+# PCRE_FOUND - True if libpcre found.
+
+IF (PCRE_INCLUDE_DIR)
+ # Already in cache, be silent
+ SET(PCRE_FIND_QUIETLY TRUE)
+ENDIF (PCRE_INCLUDE_DIR)
+
+FIND_PATH(PCRE_INCLUDE_DIR pcreposix.h)
+FIND_LIBRARY(PCREPOSIX_LIBRARY NAMES pcreposix libpcreposix)
+FIND_LIBRARY(PCRE_LIBRARY NAMES pcre libpcre)
+
+# handle the QUIETLY and REQUIRED arguments and set PCREPOSIX_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCREPOSIX DEFAULT_MSG PCREPOSIX_LIBRARY PCRE_INCLUDE_DIR)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY)
+
+IF(PCREPOSIX_FOUND)
+ SET(PCREPOSIX_LIBRARIES ${PCREPOSIX_LIBRARY})
+ SET(HAVE_LIBPCREPOSIX 1)
+ SET(HAVE_PCREPOSIX_H 1)
+ENDIF(PCREPOSIX_FOUND)
+
+IF(PCRE_FOUND)
+ SET(PCRE_LIBRARIES ${PCRE_LIBRARY})
+ SET(HAVE_LIBPCRE 1)
+ENDIF(PCRE_FOUND)
diff --git a/Utilities/cmlibarchive/build/cmake/LibarchiveCodeCoverage.cmake b/Utilities/cmlibarchive/build/cmake/LibarchiveCodeCoverage.cmake
new file mode 100644
index 0000000000..297b886ccf
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/LibarchiveCodeCoverage.cmake
@@ -0,0 +1,68 @@
+#################################################################
+# Adds a build target called "coverage" for code coverage.
+#
+# This compiles the code using special GCC flags, run the tests,
+# and then generates a nice HTML output. This new "coverage" make
+# target will only be available if you build using GCC in Debug
+# mode. If any of the required programs (lcov and genhtml) were
+# not found, a FATAL_ERROR message is printed.
+#
+# If not already done, this code will set ENABLE_TEST to ON.
+#
+# To build the code coverage and open it in your browser do this:
+#
+# mkdir debug
+# cd debug
+# cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON ..
+# make -j4
+# make coverage
+# xdg-open coverage/index.html
+#################################################################
+
+# Find programs we need
+FIND_PROGRAM(LCOV_EXECUTABLE lcov DOC "Full path to lcov executable")
+FIND_PROGRAM(GENHTML_EXECUTABLE genhtml DOC "Full path to genhtml executable")
+MARK_AS_ADVANCED(LCOV_EXECUTABLE GENHTML_EXECUTABLE)
+
+# Check, compiler, build types and programs are available
+IF(NOT CMAKE_COMPILER_IS_GNUCC)
+MESSAGE(FATAL_ERROR "Coverage can only be built on GCC")
+ELSEIF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
+MESSAGE(FATAL_ERROR "Coverage can only be built in Debug mode")
+ELSEIF(NOT LCOV_EXECUTABLE)
+MESSAGE(FATAL_ERROR "lcov executable not found")
+ELSEIF(NOT GENHTML_EXECUTABLE)
+MESSAGE(FATAL_ERROR "genhtml executable not found")
+ENDIF(NOT CMAKE_COMPILER_IS_GNUCC)
+
+# Enable testing if not already done
+SET(ENABLE_TEST ON)
+
+#################################################################
+# Set special compiler and linker flags for test coverage
+#################################################################
+# 0. Enable debug: -g
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
+# 1. Disable optimizations: -O0
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
+# 2. Enable all kind of warnings:
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W")
+# 3. Enable special coverage flag (HINT: --coverage is a synonym for -fprofile-arcs -ftest-coverage)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
+SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
+#################################################################
+
+ADD_CUSTOM_TARGET(coverage
+COMMAND ${CMAKE_COMMAND} -E echo "Beginning test coverage. Output is written to coverage.log."
+COMMAND ${CMAKE_COMMAND} -E echo "COVERAGE-STEP-1/5: Reset all execution counts to zero"
+COMMAND ${LCOV_EXECUTABLE} --directory . --zerocounters > coverage.log 2>&1
+COMMAND ${CMAKE_COMMAND} -E echo "COVERAGE-STEP-2/5: Run testrunner"
+COMMAND ${CMAKE_CTEST_COMMAND} >> coverage.log 2>&1
+COMMAND ${CMAKE_COMMAND} -E echo "COVERAGE-STEP-3/5: Collect coverage data"
+COMMAND ${LCOV_EXECUTABLE} --capture --directory . --output-file "./coverage.info" >> coverage.log 2>&1
+COMMAND ${CMAKE_COMMAND} -E echo "COVERAGE-STEP-4/5: Generate HTML from coverage data"
+COMMAND ${GENHTML_EXECUTABLE} "coverage.info" --title="libarchive-${LIBARCHIVE_VERSION_STRING}" --show-details --legend --output-directory "./coverage" >> coverage.log 2>&1
+COMMAND ${CMAKE_COMMAND} -E echo "COVERAGE-STEP-5/5: Open test coverage HTML output in browser: xdg-open ./coverage/index.html"
+COMMENT "Runs testrunner and generates coverage output (formats: .info and .html)")
+
diff --git a/Utilities/cmlibarchive/build/cmake/config.h.in b/Utilities/cmlibarchive/build/cmake/config.h.in
new file mode 100644
index 0000000000..32a29d0494
--- /dev/null
+++ b/Utilities/cmlibarchive/build/cmake/config.h.in
@@ -0,0 +1,1157 @@
+/* config.h. Generated from build/cmake/config.h.in by cmake configure */
+#if defined(__osf__)
+# define _OSF_SOURCE
+#endif
+
+/*
+ * Ensure we have C99-style int64_t, etc, all defined.
+ */
+
+/* First, we need to know if the system has already defined them. */
+#cmakedefine HAVE_INT16_T
+#cmakedefine HAVE_INT32_T
+#cmakedefine HAVE_INT64_T
+#cmakedefine HAVE_INTMAX_T
+
+#cmakedefine HAVE_UINT8_T
+#cmakedefine HAVE_UINT16_T
+#cmakedefine HAVE_UINT32_T
+#cmakedefine HAVE_UINT64_T
+#cmakedefine HAVE_UINTMAX_T
+
+/* We might have the types we want under other spellings. */
+#cmakedefine HAVE___INT64
+#cmakedefine HAVE_U_INT64_T
+#cmakedefine HAVE_UNSIGNED___INT64
+
+/* The sizes of various standard integer types. */
+@SIZE_OF_SHORT_CODE@
+@SIZE_OF_INT_CODE@
+@SIZE_OF_LONG_CODE@
+@SIZE_OF_LONG_LONG_CODE@
+@SIZE_OF_UNSIGNED_SHORT_CODE@
+@SIZE_OF_UNSIGNED_CODE@
+@SIZE_OF_UNSIGNED_LONG_CODE@
+@SIZE_OF_UNSIGNED_LONG_LONG_CODE@
+
+/*
+ * If we lack int64_t, define it to the first of __int64, int, long, and long long
+ * that exists and is the right size.
+ */
+#if !defined(HAVE_INT64_T) && defined(HAVE___INT64)
+typedef __int64 int64_t;
+#define HAVE_INT64_T
+#endif
+
+#if !defined(HAVE_INT64_T) && SIZE_OF_INT == 8
+typedef int int64_t;
+#define HAVE_INT64_T
+#endif
+
+#if !defined(HAVE_INT64_T) && SIZE_OF_LONG == 8
+typedef long int64_t;
+#define HAVE_INT64_T
+#endif
+
+#if !defined(HAVE_INT64_T) && SIZE_OF_LONG_LONG == 8
+typedef long long int64_t;
+#define HAVE_INT64_T
+#endif
+
+#if !defined(HAVE_INT64_T)
+#error No 64-bit integer type was found.
+#endif
+
+/*
+ * Similarly for int32_t
+ */
+#if !defined(HAVE_INT32_T) && SIZE_OF_INT == 4
+typedef long int32_t;
+#define HAVE_INT32_T
+#endif
+
+#if !defined(HAVE_INT32_T) && SIZE_OF_LONG == 4
+typedef long int32_t;
+#define HAVE_INT32_T
+#endif
+
+#if !defined(HAVE_INT32_T)
+#error No 32-bit integer type was found.
+#endif
+
+/*
+ * Similarly for int16_t
+ */
+#if !defined(HAVE_INT16_T) && SIZE_OF_INT == 2
+typedef int int16_t;
+#define HAVE_INT16_T
+#endif
+
+#if !defined(HAVE_INT16_T) && SIZE_OF_SHORT == 2
+typedef short int16_t;
+#define HAVE_INT16_T
+#endif
+
+#if !defined(HAVE_INT16_T)
+#error No 16-bit integer type was found.
+#endif
+
+/*
+ * Similarly for uint64_t
+ */
+#if !defined(HAVE_UINT64_T) && defined(HAVE_UNSIGNED___INT64)
+typedef unsigned __int64 uint64_t;
+#define HAVE_UINT64_T
+#endif
+
+#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED == 8
+typedef unsigned uint64_t;
+#define HAVE_UINT64_T
+#endif
+
+#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG == 8
+typedef unsigned long uint64_t;
+#define HAVE_UINT64_T
+#endif
+
+#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG_LONG == 8
+typedef unsigned long long uint64_t;
+#define HAVE_UINT64_T
+#endif
+
+#if !defined(HAVE_UINT64_T)
+#error No 64-bit unsigned integer type was found.
+#endif
+
+
+/*
+ * Similarly for uint32_t
+ */
+#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED == 4
+typedef unsigned uint32_t;
+#define HAVE_UINT32_T
+#endif
+
+#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED_LONG == 4
+typedef unsigned long uint32_t;
+#define HAVE_UINT32_T
+#endif
+
+#if !defined(HAVE_UINT32_T)
+#error No 32-bit unsigned integer type was found.
+#endif
+
+/*
+ * Similarly for uint16_t
+ */
+#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED == 2
+typedef unsigned uint16_t;
+#define HAVE_UINT16_T
+#endif
+
+#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED_SHORT == 2
+typedef unsigned short uint16_t;
+#define HAVE_UINT16_T
+#endif
+
+#if !defined(HAVE_UINT16_T)
+#error No 16-bit unsigned integer type was found.
+#endif
+
+/*
+ * Similarly for uint8_t
+ */
+#if !defined(HAVE_UINT8_T)
+typedef unsigned char uint8_t;
+#define HAVE_UINT8_T
+#endif
+
+#if !defined(HAVE_UINT16_T)
+#error No 8-bit unsigned integer type was found.
+#endif
+
+/* Define intmax_t and uintmax_t if they are not already defined. */
+#if !defined(HAVE_INTMAX_T)
+typedef int64_t intmax_t;
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#endif
+
+#if !defined(HAVE_UINTMAX_T)
+typedef uint64_t uintmax_t;
+#endif
+
+/* Define ZLIB_WINAPI if zlib was built on Visual Studio. */
+#cmakedefine ZLIB_WINAPI 1
+
+/* MD5 via ARCHIVE_CRYPTO_MD5_LIBC supported. */
+#cmakedefine ARCHIVE_CRYPTO_MD5_LIBC 1
+
+/* MD5 via ARCHIVE_CRYPTO_MD5_LIBSYSTEM supported. */
+#cmakedefine ARCHIVE_CRYPTO_MD5_LIBSYSTEM 1
+
+/* MD5 via ARCHIVE_CRYPTO_MD5_NETTLE supported. */
+#cmakedefine ARCHIVE_CRYPTO_MD5_NETTLE 1
+
+/* MD5 via ARCHIVE_CRYPTO_MD5_OPENSSL supported. */
+#cmakedefine ARCHIVE_CRYPTO_MD5_OPENSSL 1
+
+/* MD5 via ARCHIVE_CRYPTO_MD5_WIN supported. */
+#cmakedefine ARCHIVE_CRYPTO_MD5_WIN 1
+
+/* RMD160 via ARCHIVE_CRYPTO_RMD160_LIBC supported. */
+#cmakedefine ARCHIVE_CRYPTO_RMD160_LIBC 1
+
+/* RMD160 via ARCHIVE_CRYPTO_RMD160_NETTLE supported. */
+#cmakedefine ARCHIVE_CRYPTO_RMD160_NETTLE 1
+
+/* RMD160 via ARCHIVE_CRYPTO_RMD160_OPENSSL supported. */
+#cmakedefine ARCHIVE_CRYPTO_RMD160_OPENSSL 1
+
+/* SHA1 via ARCHIVE_CRYPTO_SHA1_LIBC supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA1_LIBC 1
+
+/* SHA1 via ARCHIVE_CRYPTO_SHA1_LIBSYSTEM supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA1_LIBSYSTEM 1
+
+/* SHA1 via ARCHIVE_CRYPTO_SHA1_NETTLE supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA1_NETTLE 1
+
+/* SHA1 via ARCHIVE_CRYPTO_SHA1_OPENSSL supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA1_OPENSSL 1
+
+/* SHA1 via ARCHIVE_CRYPTO_SHA1_WIN supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA1_WIN 1
+
+/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBC supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBC 1
+
+/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBC2 supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBC2 1
+
+/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBC3 supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBC3 1
+
+/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBSYSTEM supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBSYSTEM 1
+
+/* SHA256 via ARCHIVE_CRYPTO_SHA256_NETTLE supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA256_NETTLE 1
+
+/* SHA256 via ARCHIVE_CRYPTO_SHA256_OPENSSL supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA256_OPENSSL 1
+
+/* SHA256 via ARCHIVE_CRYPTO_SHA256_WIN supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA256_WIN 1
+
+/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBC supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBC 1
+
+/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBC2 supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBC2 1
+
+/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBC3 supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBC3 1
+
+/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBSYSTEM supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBSYSTEM 1
+
+/* SHA384 via ARCHIVE_CRYPTO_SHA384_NETTLE supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA384_NETTLE 1
+
+/* SHA384 via ARCHIVE_CRYPTO_SHA384_OPENSSL supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA384_OPENSSL 1
+
+/* SHA384 via ARCHIVE_CRYPTO_SHA384_WIN supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA384_WIN 1
+
+/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBC supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBC 1
+
+/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBC2 supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBC2 1
+
+/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBC3 supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBC3 1
+
+/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBSYSTEM supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBSYSTEM 1
+
+/* SHA512 via ARCHIVE_CRYPTO_SHA512_NETTLE supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA512_NETTLE 1
+
+/* SHA512 via ARCHIVE_CRYPTO_SHA512_OPENSSL supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA512_OPENSSL 1
+
+/* SHA512 via ARCHIVE_CRYPTO_SHA512_WIN supported. */
+#cmakedefine ARCHIVE_CRYPTO_SHA512_WIN 1
+
+/* Version number of bsdcpio */
+#cmakedefine BSDCPIO_VERSION_STRING "${BSDCPIO_VERSION_STRING}"
+
+/* Version number of bsdtar */
+#cmakedefine BSDTAR_VERSION_STRING "${BSDTAR_VERSION_STRING}"
+
+/* Version number of bsdcat */
+#cmakedefine BSDCAT_VERSION_STRING "${BSDCAT_VERSION_STRING}"
+
+/* Define to 1 if you have the `acl_create_entry' function. */
+#cmakedefine HAVE_ACL_CREATE_ENTRY 1
+
+/* Define to 1 if you have the `acl_get_link' function. */
+#cmakedefine HAVE_ACL_GET_LINK 1
+
+/* Define to 1 if you have the `acl_get_link_np' function. */
+#cmakedefine HAVE_ACL_GET_LINK_NP 1
+
+/* Define to 1 if you have the `acl_get_perm' function. */
+#cmakedefine HAVE_ACL_GET_PERM 1
+
+/* Define to 1 if you have the `acl_get_perm_np' function. */
+#cmakedefine HAVE_ACL_GET_PERM_NP 1
+
+/* Define to 1 if you have the `acl_init' function. */
+#cmakedefine HAVE_ACL_INIT 1
+
+/* Define to 1 if you have the <acl/libacl.h> header file. */
+#cmakedefine HAVE_ACL_LIBACL_H 1
+
+/* Define to 1 if the system has the type `acl_permset_t'. */
+#cmakedefine HAVE_ACL_PERMSET_T 1
+
+/* Define to 1 if you have the `acl_set_fd' function. */
+#cmakedefine HAVE_ACL_SET_FD 1
+
+/* Define to 1 if you have the `acl_set_fd_np' function. */
+#cmakedefine HAVE_ACL_SET_FD_NP 1
+
+/* Define to 1 if you have the `acl_set_file' function. */
+#cmakedefine HAVE_ACL_SET_FILE 1
+
+/* True for systems with POSIX ACL support */
+#cmakedefine HAVE_ACL_USER 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 <bsdxml.h> header file. */
+#cmakedefine HAVE_BSDXML_H 1
+
+/* Define to 1 if you have the <bzlib.h> header file. */
+#cmakedefine HAVE_BZLIB_H 1
+
+/* Define to 1 if you have the `chflags' function. */
+#cmakedefine HAVE_CHFLAGS 1
+
+/* Define to 1 if you have the `chown' function. */
+#cmakedefine HAVE_CHOWN 1
+
+/* Define to 1 if you have the `chroot' function. */
+#cmakedefine HAVE_CHROOT 1
+
+/* Define to 1 if you have the <copyfile.h> header file. */
+#cmakedefine HAVE_COPYFILE_H 1
+
+/* Define to 1 if you have the `ctime_r' function. */
+#cmakedefine HAVE_CTIME_R 1
+
+/* Define to 1 if you have the <ctype.h> header file. */
+#cmakedefine HAVE_CTYPE_H 1
+
+/* Define to 1 if you have the `cygwin_conv_path' function. */
+#cmakedefine HAVE_CYGWIN_CONV_PATH 1
+
+/* Define to 1 if you have the declaration of `INT64_MAX', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_INT64_MAX 1
+
+/* Define to 1 if you have the declaration of `INT64_MIN', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_INT64_MIN 1
+
+/* Define to 1 if you have the declaration of `SIZE_MAX', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_SIZE_MAX 1
+
+/* Define to 1 if you have the declaration of `SSIZE_MAX', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_SSIZE_MAX 1
+
+/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_STRERROR_R 1
+
+/* Define to 1 if you have the declaration of `UINT32_MAX', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_UINT32_MAX 1
+
+/* Define to 1 if you have the declaration of `UINT64_MAX', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_UINT64_MAX 1
+
+/* Define to 1 if you have the <direct.h> header file. */
+#cmakedefine HAVE_DIRECT_H 1
+
+/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
+ */
+#cmakedefine HAVE_DIRENT_H 1
+
+/* Define to 1 if you have the `dirfd' function. */
+#cmakedefine HAVE_DIRFD 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#cmakedefine HAVE_DLFCN_H 1
+
+/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
+#cmakedefine HAVE_DOPRNT 1
+
+/* Define to 1 if nl_langinfo supports D_MD_ORDER */
+#cmakedefine HAVE_D_MD_ORDER 1
+
+/* A possible errno value for invalid file format errors */
+#cmakedefine HAVE_EFTYPE 1
+
+/* A possible errno value for invalid file format errors */
+#cmakedefine HAVE_EILSEQ 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+#cmakedefine HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <expat.h> header file. */
+#cmakedefine HAVE_EXPAT_H 1
+
+/* Define to 1 if you have the <ext2fs/ext2_fs.h> header file. */
+#cmakedefine HAVE_EXT2FS_EXT2_FS_H 1
+
+/* Define to 1 if you have the `extattr_get_file' function. */
+#cmakedefine HAVE_EXTATTR_GET_FILE 1
+
+/* Define to 1 if you have the `extattr_list_file' function. */
+#cmakedefine HAVE_EXTATTR_LIST_FILE 1
+
+/* Define to 1 if you have the `extattr_set_fd' function. */
+#cmakedefine HAVE_EXTATTR_SET_FD 1
+
+/* Define to 1 if you have the `extattr_set_file' function. */
+#cmakedefine HAVE_EXTATTR_SET_FILE 1
+
+/* Define to 1 if EXTATTR_NAMESPACE_USER is defined in sys/extattr.h. */
+#cmakedefine HAVE_DECL_EXTATTR_NAMESPACE_USER 1
+
+/* Define to 1 if you have the `fchdir' function. */
+#cmakedefine HAVE_FCHDIR 1
+
+/* Define to 1 if you have the `fchflags' function. */
+#cmakedefine HAVE_FCHFLAGS 1
+
+/* Define to 1 if you have the `fchmod' function. */
+#cmakedefine HAVE_FCHMOD 1
+
+/* Define to 1 if you have the `fchown' function. */
+#cmakedefine HAVE_FCHOWN 1
+
+/* Define to 1 if you have the `fcntl' function. */
+#cmakedefine HAVE_FCNTL 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#cmakedefine HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the `fdopendir' function. */
+#cmakedefine HAVE_FDOPENDIR 1
+
+/* Define to 1 if you have the `fgetea' function. */
+#cmakedefine HAVE_FGETEA 1
+
+/* Define to 1 if you have the `fgetxattr' function. */
+#cmakedefine HAVE_FGETXATTR 1
+
+/* Define to 1 if you have the `flistea' function. */
+#cmakedefine HAVE_FLISTEA 1
+
+/* Define to 1 if you have the `flistxattr' function. */
+#cmakedefine HAVE_FLISTXATTR 1
+
+/* Define to 1 if you have the `fork' function. */
+#cmakedefine HAVE_FORK 1
+
+/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+#cmakedefine HAVE_FSEEKO 1
+
+/* Define to 1 if you have the `fsetea' function. */
+#cmakedefine HAVE_FSETEA 1
+
+/* Define to 1 if you have the `fsetxattr' function. */
+#cmakedefine HAVE_FSETXATTR 1
+
+/* Define to 1 if you have the `fstat' function. */
+#cmakedefine HAVE_FSTAT 1
+
+/* Define to 1 if you have the `fstatat' function. */
+#cmakedefine HAVE_FSTATAT 1
+
+/* Define to 1 if you have the `fstatfs' function. */
+#cmakedefine HAVE_FSTATFS 1
+
+/* Define to 1 if you have the `fstatvfs' function. */
+#cmakedefine HAVE_FSTATVFS 1
+
+/* Define to 1 if you have the `ftruncate' function. */
+#cmakedefine HAVE_FTRUNCATE 1
+
+/* Define to 1 if you have the `futimens' function. */
+#cmakedefine HAVE_FUTIMENS 1
+
+/* Define to 1 if you have the `futimes' function. */
+#cmakedefine HAVE_FUTIMES 1
+
+/* Define to 1 if you have the `futimesat' function. */
+#cmakedefine HAVE_FUTIMESAT 1
+
+/* Define to 1 if you have the `getea' function. */
+#cmakedefine HAVE_GETEA 1
+
+/* Define to 1 if you have the `geteuid' function. */
+#cmakedefine HAVE_GETEUID 1
+
+/* Define to 1 if you have the `getgrgid_r' function. */
+#cmakedefine HAVE_GETGRGID_R 1
+
+/* Define to 1 if you have the `getgrnam_r' function. */
+#cmakedefine HAVE_GETGRNAM_R 1
+
+/* Define to 1 if you have the `getpid' function. */
+#cmakedefine HAVE_GETPID 1
+
+/* Define to 1 if you have the `getpwnam_r' function. */
+#cmakedefine HAVE_GETPWNAM_R 1
+
+/* Define to 1 if you have the `getpwuid_r' function. */
+#cmakedefine HAVE_GETPWUID_R 1
+
+/* Define to 1 if you have the `getvfsbyname' function. */
+#cmakedefine HAVE_GETVFSBYNAME 1
+
+/* Define to 1 if you have the `getxattr' function. */
+#cmakedefine HAVE_GETXATTR 1
+
+/* Define to 1 if you have the `gmtime_r' function. */
+#cmakedefine HAVE_GMTIME_R 1
+
+/* Define to 1 if you have the <grp.h> header file. */
+#cmakedefine HAVE_GRP_H 1
+
+/* Define to 1 if you have the `iconv' function. */
+#cmakedefine HAVE_ICONV 1
+
+/* Define to 1 if you have the <iconv.h> header file. */
+#cmakedefine HAVE_ICONV_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#cmakedefine HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <io.h> header file. */
+#cmakedefine HAVE_IO_H 1
+
+/* Define to 1 if you have the <langinfo.h> header file. */
+#cmakedefine HAVE_LANGINFO_H 1
+
+/* Define to 1 if you have the `lchflags' function. */
+#cmakedefine HAVE_LCHFLAGS 1
+
+/* Define to 1 if you have the `lchmod' function. */
+#cmakedefine HAVE_LCHMOD 1
+
+/* Define to 1 if you have the `lchown' function. */
+#cmakedefine HAVE_LCHOWN 1
+
+/* Define to 1 if you have the `lgetea' function. */
+#cmakedefine HAVE_LGETEA 1
+
+/* Define to 1 if you have the `lgetxattr' function. */
+#cmakedefine HAVE_LGETXATTR 1
+
+/* Define to 1 if you have the `acl' library (-lacl). */
+#cmakedefine HAVE_LIBACL 1
+
+/* Define to 1 if you have the `attr' library (-lattr). */
+#cmakedefine HAVE_LIBATTR 1
+
+/* Define to 1 if you have the `bsdxml' library (-lbsdxml). */
+#cmakedefine HAVE_LIBBSDXML 1
+
+/* Define to 1 if you have the `bz2' library (-lbz2). */
+#cmakedefine HAVE_LIBBZ2 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 `lzma' library (-llzma). */
+#cmakedefine HAVE_LIBLZMA 1
+
+/* Define to 1 if you have the `lzmadec' library (-llzmadec). */
+#cmakedefine HAVE_LIBLZMADEC 1
+
+/* Define to 1 if you have the `lzo2' library (-llzo2). */
+#cmakedefine HAVE_LIBLZO2 1
+
+/* Define to 1 if you have the `nettle' library (-lnettle). */
+#cmakedefine HAVE_LIBNETTLE 1
+
+/* Define to 1 if you have the `pcre' library (-lpcre). */
+#cmakedefine HAVE_LIBPCRE 1
+
+/* Define to 1 if you have the `pcreposix' library (-lpcreposix). */
+#cmakedefine HAVE_LIBPCREPOSIX 1
+
+/* Define to 1 if you have the `xml2' library (-lxml2). */
+#cmakedefine HAVE_LIBXML2 1
+
+/* Define to 1 if you have the <libxml/xmlreader.h> header file. */
+#cmakedefine HAVE_LIBXML_XMLREADER_H 1
+
+/* Define to 1 if you have the <libxml/xmlwriter.h> header file. */
+#cmakedefine HAVE_LIBXML_XMLWRITER_H 1
+
+/* Define to 1 if you have the `z' library (-lz). */
+#cmakedefine HAVE_LIBZ 1
+
+/* Define to 1 if you have the <limits.h> header file. */
+#cmakedefine HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the `link' function. */
+#cmakedefine HAVE_LINK 1
+
+/* Define to 1 if you have the <linux/types.h> header file. */
+#cmakedefine HAVE_LINUX_TYPES_H 1
+
+/* Define to 1 if you have the <linux/fiemap.h> header file. */
+#cmakedefine HAVE_LINUX_FIEMAP_H 1
+
+/* Define to 1 if you have the <linux/fs.h> header file. */
+#cmakedefine HAVE_LINUX_FS_H 1
+
+/* Define to 1 if you have the <linux/magic.h> header file. */
+#cmakedefine HAVE_LINUX_MAGIC_H 1
+
+/* Define to 1 if you have the <linux/types.h> header file. */
+#cmakedefine HAVE_LINUX_TYPES_H 1
+
+/* Define to 1 if you have the `listea' function. */
+#cmakedefine HAVE_LISTEA 1
+
+/* Define to 1 if you have the `listxattr' function. */
+#cmakedefine HAVE_LISTXATTR 1
+
+/* Define to 1 if you have the `llistea' function. */
+#cmakedefine HAVE_LLISTEA 1
+
+/* Define to 1 if you have the `llistxattr' function. */
+#cmakedefine HAVE_LLISTXATTR 1
+
+/* Define to 1 if you have the <localcharset.h> header file. */
+#cmakedefine HAVE_LOCALCHARSET_H 1
+
+/* Define to 1 if you have the `locale_charset' function. */
+#cmakedefine HAVE_LOCALE_CHARSET 1
+
+/* Define to 1 if you have the <locale.h> header file. */
+#cmakedefine HAVE_LOCALE_H 1
+
+/* Define to 1 if you have the `localtime_r' function. */
+#cmakedefine HAVE_LOCALTIME_R 1
+
+/* Define to 1 if the system has the type `long long int'. */
+#cmakedefine HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if you have the `lsetea' function. */
+#cmakedefine HAVE_LSETEA 1
+
+/* Define to 1 if you have the `lsetxattr' function. */
+#cmakedefine HAVE_LSETXATTR 1
+
+/* Define to 1 if you have the `lstat' function. */
+#cmakedefine HAVE_LSTAT 1
+
+/* Define to 1 if `lstat' has the bug that it succeeds when given the
+ zero-length file name argument. */
+#cmakedefine HAVE_LSTAT_EMPTY_STRING_BUG 1
+
+/* Define to 1 if you have the `lutimes' function. */
+#cmakedefine HAVE_LUTIMES 1
+
+/* Define to 1 if you have the <lzmadec.h> header file. */
+#cmakedefine HAVE_LZMADEC_H 1
+
+/* Define to 1 if you have the <lzma.h> header file. */
+#cmakedefine HAVE_LZMA_H 1
+
+/* Define to 1 if you have the <lzo/lzo1x.h> header file. */
+#cmakedefine HAVE_LZO_LZO1X_H 1
+
+/* Define to 1 if you have the <lzo/lzoconf.h> header file. */
+#cmakedefine HAVE_LZO_LZOCONF_H 1
+
+/* Define to 1 if you have the `mbrtowc' function. */
+#cmakedefine HAVE_MBRTOWC 1
+
+/* Define to 1 if you have the `memmove' function. */
+#cmakedefine HAVE_MEMMOVE 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#cmakedefine HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `mkdir' function. */
+#cmakedefine HAVE_MKDIR 1
+
+/* Define to 1 if you have the `mkfifo' function. */
+#cmakedefine HAVE_MKFIFO 1
+
+/* Define to 1 if you have the `mknod' function. */
+#cmakedefine HAVE_MKNOD 1
+
+/* Define to 1 if you have the `mkstemp' function. */
+#cmakedefine HAVE_MKSTEMP 1
+
+/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
+#cmakedefine HAVE_NDIR_H 1
+
+/* 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/ripemd160.h> header file. */
+#cmakedefine HAVE_NETTLE_RIPEMD160_H 1
+
+/* Define to 1 if you have the <nettle/sha.h> header file. */
+#cmakedefine HAVE_NETTLE_SHA_H 1
+
+/* Define to 1 if you have the `nl_langinfo' function. */
+#cmakedefine HAVE_NL_LANGINFO 1
+
+/* Define to 1 if you have the `openat' function. */
+#cmakedefine HAVE_OPENAT 1
+
+/* Define to 1 if you have the <paths.h> header file. */
+#cmakedefine HAVE_PATHS_H 1
+
+/* Define to 1 if you have the <pcreposix.h> header file. */
+#cmakedefine HAVE_PCREPOSIX_H 1
+
+/* Define to 1 if you have the `pipe' function. */
+#cmakedefine HAVE_PIPE 1
+
+/* Define to 1 if you have the `poll' function. */
+#cmakedefine HAVE_POLL 1
+
+/* Define to 1 if you have the <poll.h> header file. */
+#cmakedefine HAVE_POLL_H 1
+
+/* Define to 1 if you have the `posix_spawnp' function. */
+#cmakedefine HAVE_POSIX_SPAWNP 1
+
+/* Define to 1 if you have the <process.h> header file. */
+#cmakedefine HAVE_PROCESS_H 1
+
+/* Define to 1 if you have the <pwd.h> header file. */
+#cmakedefine HAVE_PWD_H 1
+
+/* Define to 1 if you have the `readdir_r' function. */
+#cmakedefine HAVE_READDIR_R 1
+
+/* Define to 1 if you have the `readlink' function. */
+#cmakedefine HAVE_READLINK 1
+
+/* Define to 1 if you have the `readlinkat' function. */
+#cmakedefine HAVE_READLINKAT 1
+
+/* Define to 1 if you have the <regex.h> header file. */
+#cmakedefine HAVE_REGEX_H 1
+
+/* Define to 1 if you have the `select' function. */
+#cmakedefine HAVE_SELECT 1
+
+/* Define to 1 if you have the `setenv' function. */
+#cmakedefine HAVE_SETENV 1
+
+/* Define to 1 if you have the `setlocale' function. */
+#cmakedefine HAVE_SETLOCALE 1
+
+/* Define to 1 if you have the `sigaction' function. */
+#cmakedefine HAVE_SIGACTION 1
+
+/* Define to 1 if you have the <signal.h> header file. */
+#cmakedefine HAVE_SIGNAL_H 1
+
+/* Define to 1 if you have the <spawn.h> header file. */
+#cmakedefine HAVE_SPAWN_H 1
+
+/* Define to 1 if you have the `statfs' function. */
+#cmakedefine HAVE_STATFS 1
+
+/* Define to 1 if you have the `statvfs' function. */
+#cmakedefine HAVE_STATVFS 1
+
+/* Define to 1 if `stat' has the bug that it succeeds when given the
+ zero-length file name argument. */
+#cmakedefine HAVE_STAT_EMPTY_STRING_BUG 1
+
+/* Define to 1 if you have the <stdarg.h> header file. */
+#cmakedefine HAVE_STDARG_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#cmakedefine HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#cmakedefine HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strchr' function. */
+#cmakedefine HAVE_STRCHR 1
+
+/* Define to 1 if you have the `strdup' function. */
+#cmakedefine HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strerror' function. */
+#cmakedefine HAVE_STRERROR 1
+
+/* Define to 1 if you have the `strerror_r' function. */
+#cmakedefine HAVE_STRERROR_R 1
+
+/* Define to 1 if you have the `strftime' function. */
+#cmakedefine HAVE_STRFTIME 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#cmakedefine HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#cmakedefine HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strrchr' function. */
+#cmakedefine HAVE_STRRCHR 1
+
+/* Define to 1 if `f_namemax' is a member of `struct statfs'. */
+#cmakedefine HAVE_STRUCT_STATFS_F_NAMEMAX 1
+
+/* Define to 1 if `f_iosize' is a member of `struct statvfs'. */
+#cmakedefine HAVE_STRUCT_STATVFS_F_IOSIZE 1
+
+/* Define to 1 if `st_birthtime' is a member of `struct stat'. */
+#cmakedefine HAVE_STRUCT_STAT_ST_BIRTHTIME 1
+
+/* Define to 1 if `st_birthtimespec.tv_nsec' is a member of `struct stat'. */
+#cmakedefine HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1
+
+/* Define to 1 if `st_blksize' is a member of `struct stat'. */
+#cmakedefine HAVE_STRUCT_STAT_ST_BLKSIZE 1
+
+/* Define to 1 if `st_flags' is a member of `struct stat'. */
+#cmakedefine HAVE_STRUCT_STAT_ST_FLAGS 1
+
+/* Define to 1 if `st_mtimespec.tv_nsec' is a member of `struct stat'. */
+#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
+
+/* Define to 1 if `st_mtime_n' is a member of `struct stat'. */
+#cmakedefine HAVE_STRUCT_STAT_ST_MTIME_N 1
+
+/* Define to 1 if `st_mtime_usec' is a member of `struct stat'. */
+#cmakedefine HAVE_STRUCT_STAT_ST_MTIME_USEC 1
+
+/* Define to 1 if `st_mtim.tv_nsec' is a member of `struct stat'. */
+#cmakedefine HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 1
+
+/* Define to 1 if `st_umtime' is a member of `struct stat'. */
+#cmakedefine HAVE_STRUCT_STAT_ST_UMTIME 1
+
+/* Define to 1 if `tm_gmtoff' is a member of `struct tm'. */
+#cmakedefine HAVE_STRUCT_TM_TM_GMTOFF 1
+
+/* Define to 1 if `__tm_gmtoff' is a member of `struct tm'. */
+#cmakedefine HAVE_STRUCT_TM___TM_GMTOFF 1
+
+/* Define to 1 if you have the `symlink' function. */
+#cmakedefine HAVE_SYMLINK 1
+
+/* Define to 1 if you have the <sys/acl.h> header file. */
+#cmakedefine HAVE_SYS_ACL_H 1
+
+/* Define to 1 if you have the <sys/cdefs.h> header file. */
+#cmakedefine HAVE_SYS_CDEFS_H 1
+
+/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
+ */
+#cmakedefine HAVE_SYS_DIR_H 1
+
+/* Define to 1 if you have the <sys/ea.h> header file. */
+#cmakedefine HAVE_SYS_EA_H 1
+
+/* Define to 1 if you have the <sys/extattr.h> header file. */
+#cmakedefine HAVE_SYS_EXTATTR_H 1
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#cmakedefine HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/mkdev.h> header file. */
+#cmakedefine HAVE_SYS_MKDEV_H 1
+
+/* Define to 1 if you have the <sys/mount.h> header file. */
+#cmakedefine HAVE_SYS_MOUNT_H 1
+
+/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
+ */
+#cmakedefine HAVE_SYS_NDIR_H 1
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#cmakedefine HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#cmakedefine HAVE_SYS_POLL_H 1
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#cmakedefine HAVE_SYS_SELECT_H 1
+
+/* Define to 1 if you have the <sys/statfs.h> header file. */
+#cmakedefine HAVE_SYS_STATFS_H 1
+
+/* Define to 1 if you have the <sys/statvfs.h> header file. */
+#cmakedefine HAVE_SYS_STATVFS_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#cmakedefine HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#cmakedefine HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#cmakedefine HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/utime.h> header file. */
+#cmakedefine HAVE_SYS_UTIME_H 1
+
+/* Define to 1 if you have the <sys/utsname.h> header file. */
+#cmakedefine HAVE_SYS_UTSNAME_H 1
+
+/* Define to 1 if you have the <sys/vfs.h> header file. */
+#cmakedefine HAVE_SYS_VFS_H 1
+
+/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
+#cmakedefine HAVE_SYS_WAIT_H 1
+
+/* Define to 1 if you have the <sys/xattr.h> header file. */
+#cmakedefine HAVE_SYS_XATTR_H 1
+
+/* Define to 1 if you have the `timegm' function. */
+#cmakedefine HAVE_TIMEGM 1
+
+/* Define to 1 if you have the <time.h> header file. */
+#cmakedefine HAVE_TIME_H 1
+
+/* Define to 1 if you have the `tzset' function. */
+#cmakedefine HAVE_TZSET 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the `unsetenv' function. */
+#cmakedefine HAVE_UNSETENV 1
+
+/* Define to 1 if the system has the type `unsigned long long'. */
+#cmakedefine HAVE_UNSIGNED_LONG_LONG 1
+
+/* Define to 1 if the system has the type `unsigned long long int'. */
+#cmakedefine HAVE_UNSIGNED_LONG_LONG_INT 1
+
+/* Define to 1 if you have the `utime' function. */
+#cmakedefine HAVE_UTIME 1
+
+/* Define to 1 if you have the `utimensat' function. */
+#cmakedefine HAVE_UTIMENSAT 1
+
+/* Define to 1 if you have the `utimes' function. */
+#cmakedefine HAVE_UTIMES 1
+
+/* Define to 1 if you have the <utime.h> header file. */
+#cmakedefine HAVE_UTIME_H 1
+
+/* Define to 1 if you have the `vfork' function. */
+#cmakedefine HAVE_VFORK 1
+
+/* Define to 1 if you have the `vprintf' function. */
+#cmakedefine HAVE_VPRINTF 1
+
+/* Define to 1 if you have the <wchar.h> header file. */
+#cmakedefine HAVE_WCHAR_H 1
+
+/* Define to 1 if the system has the type `wchar_t'. */
+#cmakedefine HAVE_WCHAR_T 1
+
+/* Define to 1 if you have the `wcrtomb' function. */
+#cmakedefine HAVE_WCRTOMB 1
+
+/* Define to 1 if you have the `wcscmp' function. */
+#cmakedefine HAVE_WCSCMP 1
+
+/* Define to 1 if you have the `wcscpy' function. */
+#cmakedefine HAVE_WCSCPY 1
+
+/* Define to 1 if you have the `wcslen' function. */
+#cmakedefine HAVE_WCSLEN 1
+
+/* Define to 1 if you have the `wctomb' function. */
+#cmakedefine HAVE_WCTOMB 1
+
+/* Define to 1 if you have the <wctype.h> header file. */
+#cmakedefine HAVE_WCTYPE_H 1
+
+/* Define to 1 if you have the <wincrypt.h> header file. */
+#cmakedefine HAVE_WINCRYPT_H 1
+
+/* Define to 1 if you have the <windows.h> header file. */
+#cmakedefine HAVE_WINDOWS_H 1
+
+/* Define to 1 if you have the <winioctl.h> header file. */
+#cmakedefine HAVE_WINIOCTL_H 1
+
+/* Define to 1 if you have _CrtSetReportMode in <crtdbg.h> */
+#cmakedefine HAVE__CrtSetReportMode 1
+
+/* Define to 1 if you have the `wmemcmp' function. */
+#cmakedefine HAVE_WMEMCMP 1
+
+/* Define to 1 if you have the `wmemcpy' function. */
+#cmakedefine HAVE_WMEMCPY 1
+
+/* Define to 1 if you have a working EXT2_IOC_GETFLAGS */
+#cmakedefine HAVE_WORKING_EXT2_IOC_GETFLAGS 1
+
+/* Define to 1 if you have the <zlib.h> header file. */
+#cmakedefine HAVE_ZLIB_H 1
+
+/* Define to 1 if you have the `_ctime64_s' function. */
+#cmakedefine HAVE__CTIME64_S 1
+
+/* Define to 1 if you have the `_fseeki64' function. */
+#cmakedefine HAVE__FSEEKI64 1
+
+/* Define to 1 if you have the `_get_timezone' function. */
+#cmakedefine HAVE__GET_TIMEZONE 1
+
+/* Define to 1 if you have the `_localtime64_s' function. */
+#cmakedefine HAVE__LOCALTIME64_S 1
+
+/* Define to 1 if you have the `_mkgmtime64' function. */
+#cmakedefine HAVE__MKGMTIME64 1
+
+/* Define as const if the declaration of iconv() needs const. */
+#define ICONV_CONST ${ICONV_CONST}
+
+/* Version number of libarchive as a single integer */
+#cmakedefine LIBARCHIVE_VERSION_NUMBER "${LIBARCHIVE_VERSION_NUMBER}"
+
+/* Version number of libarchive */
+#cmakedefine LIBARCHIVE_VERSION_STRING "${LIBARCHIVE_VERSION_STRING}"
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+ slash. */
+#cmakedefine LSTAT_FOLLOWS_SLASHED_SYMLINK 1
+
+/* Define to 1 if `major', `minor', and `makedev' are declared in <mkdev.h>.
+ */
+#cmakedefine MAJOR_IN_MKDEV 1
+
+/* Define to 1 if `major', `minor', and `makedev' are declared in
+ <sysmacros.h>. */
+#cmakedefine MAJOR_IN_SYSMACROS 1
+
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+#cmakedefine NO_MINUS_C_MINUS_O 1
+
+/* The size of `wchar_t', as computed by sizeof. */
+#cmakedefine SIZEOF_WCHAR_T ${SIZEOF_WCHAR_T}
+
+/* Define to 1 if strerror_r returns char *. */
+#cmakedefine STRERROR_R_CHAR_P 1
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#cmakedefine TIME_WITH_SYS_TIME 1
+
+/*
+ * Some platform requires a macro to use extension functions.
+ */
+#cmakedefine SAFE_TO_DEFINE_EXTENSIONS 1
+#ifdef SAFE_TO_DEFINE_EXTENSIONS
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+# define _TANDEM_SOURCE 1
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__ 1
+#endif
+#endif /* SAFE_TO_DEFINE_EXTENSIONS */
+
+/* Version number of package */
+#cmakedefine VERSION "${VERSION}"
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#cmakedefine _FILE_OFFSET_BITS ${_FILE_OFFSET_BITS}
+
+/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+#cmakedefine _LARGEFILE_SOURCE 1
+
+/* Define for large files, on AIX-style hosts. */
+#cmakedefine _LARGE_FILES ${_LARGE_FILES}
+
+/* Define for Windows to use Windows 2000+ APIs. */
+#ifndef _WIN32_WINNT
+#cmakedefine _WIN32_WINNT ${_WIN32_WINNT}
+#endif // _WIN32_WINNT
+
+#ifndef WINVER
+#cmakedefine WINVER ${WINVER}
+#endif // WINVER
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#cmakedefine const ${const}
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+#cmakedefine gid_t ${gid_t}
+
+/* Define to `unsigned long' if <sys/types.h> does not define. */
+#cmakedefine id_t ${id_t}
+
+/* Define to `int' if <sys/types.h> does not define. */
+#cmakedefine mode_t ${mode_t}
+
+/* Define to `long long' if <sys/types.h> does not define. */
+#cmakedefine off_t ${off_t}
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+#cmakedefine pid_t ${pid_t}
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+#cmakedefine size_t ${size_t}
+
+/* Define to `int' if <sys/types.h> does not define. */
+#cmakedefine ssize_t ${ssize_t}
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+#cmakedefine uid_t ${uid_t}
+
+/* Define to `int' if <sys/types.h> does not define. */
+#cmakedefine intptr_t ${intptr_t}
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+#cmakedefine uintptr_t ${uintptr_t}
diff --git a/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in b/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in
new file mode 100644
index 0000000000..95d7159517
--- /dev/null
+++ b/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libarchive
+Description: library that can create and read several streaming archive formats
+Version: @VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -larchive
+Libs.private: @LIBS@
diff --git a/Utilities/cmlibarchive/build/utils/gen_archive_string_composition_h.sh b/Utilities/cmlibarchive/build/utils/gen_archive_string_composition_h.sh
new file mode 100755
index 0000000000..925de5c85e
--- /dev/null
+++ b/Utilities/cmlibarchive/build/utils/gen_archive_string_composition_h.sh
@@ -0,0 +1,455 @@
+#!/bin/sh
+#
+# This needs http://unicode.org/Public/6.0.0/ucd/UnicodeData.txt
+#
+inputfile="$1" # Expect UnicodeData.txt
+outfile=archive_string_composition.h
+pickout=/tmp/mk_unicode_composition_tbl$$.awk
+pickout2=/tmp/mk_unicode_composition_tbl2$$.awk
+#nfdtmp=/tmp/mk_unicode_decomposition_tmp$$.txt
+nfdtmp="nfdtmpx"
+#################################################################################
+#
+# Append the file header of "archive_string_composition.h"
+#
+#################################################################################
+append_copyright()
+{
+cat > ${outfile} <<CR_END
+/*-
+ * Copyright (c) 2011-2012 libarchive Project
+ * 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.
+ *
+ * \$FreeBSD\$
+ *
+ */
+
+/*
+ * ATTENTION!
+ * This file is generated by build/utils/gen_archive_string_composition_h.sh
+ * from http://unicode.org/Public/6.0.0/ucd/UnicodeData.txt
+ *
+ * See also http://unicode.org/report/tr15/
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_STRING_COMPOSITION_H_INCLUDED
+#define ARCHIVE_STRING_COMPOSITION_H_INCLUDED
+
+struct unicode_composition_table {
+ uint32_t cp1;
+ uint32_t cp2;
+ uint32_t nfc;
+};
+
+CR_END
+}
+#################################################################################
+#
+# awk script
+#
+#################################################################################
+cat > ${pickout} <<AWK_END
+#
+BEGIN {
+ FS = ";"
+ min = "";
+ max = "";
+ cmd="sort | awk -F ' ' '{printf \"\\\\t{ 0x%s , 0x%s , 0x%s },\\\\n\",\$1,\$2,\$3}'"
+ nfdtbl="${nfdtmp}"
+ print "static const struct unicode_composition_table u_composition_table[] = {"
+}
+END {
+ close(cmd)
+ print "};"
+ print ""
+ #
+ # Output Canonical Combining Class tables used for translating NFD to NFC.
+ #
+ printf "#define CANONICAL_CLASS_MIN\\t0x%s\\n", min
+ printf "#define CANONICAL_CLASS_MAX\\t0x%s\\n", max
+ print ""
+ printf "#define IS_DECOMPOSABLE_BLOCK(uc)\\t\\\\\n"
+ printf "\\t(((uc)>>8) <= 0x%X && u_decomposable_blocks[(uc)>>8])\\n", highnum
+ printf "static const char u_decomposable_blocks[0x%X+1] = {\\n\\t", highnum
+ #
+ # Output blockmap
+ for (i = 0; i <= highnum; i++) {
+ if (i != 0 && i % 32 == 0)
+ printf "\\n\\t"
+ # Additionally Hangul[11XX(17), AC00(172) - D7FF(215)] is decomposable.
+ if (blockmap[i] || i == 17 || (i >= 172 && i <= 215))
+ printf "1,"
+ else
+ printf "0,"
+ }
+ printf "\\n};\\n\\n"
+ #
+ # Output a macro to get a canonical combining class.
+ #
+ print "/* Get Canonical Combining Class(CCC). */"
+ printf "#define CCC(uc)\\t\\\\\n"
+ printf "\\t(((uc) > 0x%s)?0:\\\\\\n", max
+ printf "\\tccc_val[ccc_val_index[ccc_index[(uc)>>8]][((uc)>>4)&0x0F]][(uc)&0x0F])\\n"
+ print ""
+ #
+ # Output a canonical combining class value table.
+ #
+ midcnt = 0
+ printf "/* The table of the value of Canonical Cimbining Class */\\n"
+ print "static const unsigned char ccc_val[][16] = {"
+ print " /* idx=0: XXXX0 - XXXXF */"
+ print " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },"
+ for (h = 0; h <= highnum; h++) {
+ if (!blockmap[h])
+ continue;
+ for (m = 0; m < 16; m++) {
+ if (!xx_blockmap[h, m])
+ continue;
+ midcnt++
+ printf " /* idx=%d: %03X%1X0 - %03X%1XF */\\n {", midcnt, h, m, h, m
+ for (l = 0; l < 15; l++) {
+ printf "%d, ", xxx_blockmap[h, m, l]
+ }
+ printf "%d },\n", xxx_blockmap[h, m, 15]
+ }
+ }
+ printf "};\n"
+ #
+ # Output the index table of the canonical combining class value table.
+ #
+ cnt = 0
+ midcnt = 0
+ printf "\\n/* The index table to ccc_val[*][16] */\\n"
+ print "static const unsigned char ccc_val_index[][16] = {"
+ print " /* idx=0: XXX00 - XXXFF */"
+ print " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },"
+ for (h = 0; h <= highnum; h++) {
+ if (!blockmap[h])
+ continue;
+ cnt++
+ printf " /* idx=%d: %03X00 - %03XFF */\\n {", cnt, h, h
+ for (m = 0; m < 16; m++) {
+ if (m != 0)
+ printf ","
+ if (xx_blockmap[h, m]) {
+ midcnt++
+ printf "%2d", midcnt
+ } else
+ printf " 0"
+ }
+ printf " },\\n"
+ }
+ printf "};\\n"
+ #
+ # Output the index table to the index table of the canonical combining
+ # class value table.
+ #
+ printf "\\n/* The index table to ccc_val_index[*][16] */\\n"
+ printf "static const unsigned char ccc_index[] = {\\n ", h
+ cnt = 0
+ for (h = 0; h <= highnum; h++) {
+ if (h != 0 && h % 24 == 0)
+ printf "\\n "
+ if (blockmap[h]) {
+ cnt++;
+ printf "%2d,", cnt
+ } else
+ printf " 0,"
+ }
+ print "};"
+ print ""
+}
+#
+#
+function hextoi(hex)
+{
+ dec = 0
+ for (i=0; i < length(hex); i++) {
+ x = substr(hex, i+1, 1)
+ if (x ~/[0-9]/)
+ dec = dec * 16 + x;
+ else if (x == "A")
+ dec = dec * 16 + 10;
+ else if (x == "B")
+ dec = dec * 16 + 11;
+ else if (x == "C")
+ dec = dec * 16 + 12;
+ else if (x == "D")
+ dec = dec * 16 + 13;
+ else if (x == "E")
+ dec = dec * 16 + 14;
+ else if (x == "F")
+ dec = dec * 16 + 15;
+ }
+ return dec
+}
+#
+# Collect Canonical Combining Class values.
+#
+\$4 ~/^[0-9A-F]+$/ {
+ if (\$4 !~/^0$/) {
+ if (min == "") {
+ min = \$1
+ }
+ max = \$1
+ high = substr(\$1, 1, length(\$1) -2)
+ highnum = hextoi(high)
+ mid = substr(\$1, length(\$1) -1, 1)
+ midnum = hextoi(mid)
+ low = substr(\$1, length(\$1), 1)
+ lownum = hextoi(low)
+ blockmap[highnum] = 1
+ xx_blockmap[highnum, midnum] = 1
+ xxx_blockmap[highnum, midnum, lownum] = \$4
+ }
+}
+#
+# Following code points are not decomposed in MAC OS.
+# U+2000 - U+2FFF
+# U+F900 - U+FAFF
+# U+2F800 - U+2FAFF
+#
+#\$1 ~/^2[0-9A-F][0-9A-F][0-9A-F]\$/ {
+# next
+#}
+#\$1 ~/^F[9A][0-9A-F][0-9A-F]\$/ {
+# next
+#}
+#\$1 ~/^2F[89A][0-9A-F][0-9A-F]\$/ {
+# next
+#}
+#
+# Exclusion code points specified by
+# http://unicode.org/Public/6.0.0/ucd/CompositionExclusions.txt
+##
+# 1. Script Specifices
+##
+\$1 ~/^095[89ABCDEF]\$/ {
+ next
+}
+\$1 ~/^09D[CDF]\$/ {
+ next
+}
+\$1 ~/^0A3[36]\$/ {
+ next
+}
+\$1 ~/^0A5[9ABE]\$/ {
+ next
+}
+\$1 ~/^0B5[CD]\$/ {
+ next
+}
+\$1 ~/^0F4[3D]\$/ {
+ next
+}
+\$1 ~/^0F5[27C]\$/ {
+ next
+}
+\$1 ~/^0F69\$/ {
+ next
+}
+\$1 ~/^0F7[68]\$/ {
+ next
+}
+\$1 ~/^0F9[3D]\$/ {
+ next
+}
+\$1 ~/^0FA[27C]\$/ {
+ next
+}
+\$1 ~/^0FB9\$/ {
+ next
+}
+\$1 ~/^FB1[DF]\$/ {
+ next
+}
+\$1 ~/^FB2[ABCDEF]\$/ {
+ next
+}
+\$1 ~/^FB3[012345689ABCE]\$/ {
+ next
+}
+\$1 ~/^FB4[01346789ABCDE]\$/ {
+ next
+}
+##
+# 2. Post Composition Version precomposed characters
+##
+\$1 ~/^2ADC\$/ {
+ next
+}
+\$1 ~/^1D15[EF]\$/ {
+ next
+}
+\$1 ~/^1D16[01234]\$/ {
+ next
+}
+\$1 ~/^1D1B[BCDEF]\$/ {
+ next
+}
+\$1 ~/^1D1C0\$/ {
+ next
+}
+##
+# 3. Singleton Decompositions
+##
+\$1 ~/^034[01]\$/ {
+ next
+}
+\$1 ~/^037[4E]\$/ {
+ next
+}
+\$1 ~/^0387\$/ {
+ next
+}
+\$1 ~/^1F7[13579BD]\$/ {
+ next
+}
+\$1 ~/^1FB[BE]\$/ {
+ next
+}
+\$1 ~/^1FC[9B]\$/ {
+ next
+}
+\$1 ~/^1FD[3B]\$/ {
+ next
+}
+\$1 ~/^1FE[3BEF]\$/ {
+ next
+}
+\$1 ~/^1FF[9BD]\$/ {
+ next
+}
+\$1 ~/^200[01]\$/ {
+ next
+}
+\$1 ~/^212[6AB]\$/ {
+ next
+}
+\$1 ~/^232[9A]\$/ {
+ next
+}
+\$1 ~/^F9[0-9A-F][0-9A-F]\$/ {
+ next
+}
+\$1 ~/^FA0[0-9A-D]\$/ {
+ next
+}
+\$1 ~/^FA1[025-9A-E]\$/ {
+ next
+}
+\$1 ~/^FA2[0256A-D]\$/ {
+ next
+}
+\$1 ~/^FA[3-5][0-9A-F]\$/ {
+ next
+}
+\$1 ~/^FA6[0-9A-D]\$/ {
+ next
+}
+\$1 ~/^FA[7-9A-C][0-9A-F]\$/ {
+ next
+}
+\$1 ~/^FAD[0-9]\$/ {
+ next
+}
+\$1 ~/^2F[89][0-9A-F][0-9A-F]\$/ {
+ next
+}
+\$1 ~/^2FA0[0-9A-F]\$/ {
+ next
+}
+\$1 ~/^2FA1[0-9A-D]\$/ {
+ next
+}
+##
+# 4. Non-Starter Decompositions
+##
+\$1 ~/^0344\$/ {
+ next
+}
+\$1 ~/^0F7[35]\$/ {
+ next
+}
+\$1 ~/^0F81\$/ {
+ next
+}
+#
+# Output combinations for NFD ==> NFC.
+#
+\$6 ~/^[0-9A-F]+ [0-9A-F]+\$/ {
+ split(\$6, cp, " ")
+ if (length(\$1) == 4)
+ print "0"cp[1], "0"cp[2], "0"\$1 | cmd
+ else
+ print cp[1], cp[2], \$1 | cmd
+ # NFC ==> NFD table.
+ if (length(\$1) == 4)
+ print "0"\$1, "0"cp[1], "0"cp[2] >>nfdtbl
+ else
+ print \$1, cp[1], cp[2] >>nfdtbl
+}
+AWK_END
+#################################################################################
+# awk script
+#
+#################################################################################
+cat > ${pickout2} <<AWK_END
+#
+BEGIN {
+ FS = " "
+ print "struct unicode_decomposition_table {"
+ print "\tuint32_t nfc;"
+ print "\tuint32_t cp1;"
+ print "\tuint32_t cp2;"
+ print "};"
+ print ""
+ print "static const struct unicode_decomposition_table u_decomposition_table[] = {"
+}
+END {
+ print "};"
+ print ""
+}
+{
+printf "\t{ 0x%s , 0x%s , 0x%s },\n", \$1, \$2, \$3;
+}
+AWK_END
+#################################################################################
+#
+# Run awk a script.
+#
+#################################################################################
+append_copyright
+awk -f ${pickout} ${inputfile} >> ${outfile}
+awk -f ${pickout2} ${nfdtmp} >> ${outfile}
+echo "#endif /* ARCHIVE_STRING_COMPOSITION_H_INCLUDED */" >> ${outfile}
+echo "" >> ${outfile}
+#
+# Remove awk the script.
+rm ${pickout}
+rm ${pickout2}
+rm ${nfdtmp}
diff --git a/Utilities/cmlibarchive/build/version b/Utilities/cmlibarchive/build/version
new file mode 100644
index 0000000000..937b126a2e
--- /dev/null
+++ b/Utilities/cmlibarchive/build/version
@@ -0,0 +1 @@
+3001002
diff --git a/Utilities/cmlibarchive/libarchive/CMakeLists.txt b/Utilities/cmlibarchive/libarchive/CMakeLists.txt
new file mode 100644
index 0000000000..8908a62752
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/CMakeLists.txt
@@ -0,0 +1,177 @@
+
+############################################
+#
+# How to build libarchive
+#
+############################################
+
+# Public headers
+SET(include_HEADERS
+ archive.h
+ archive_entry.h
+)
+
+# Sources and private headers
+SET(libarchive_SOURCES
+ archive_acl.c
+ archive_check_magic.c
+ archive_cmdline.c
+ archive_cmdline_private.h
+ archive_crc32.h
+ archive_crypto.c
+ archive_crypto_private.h
+ archive_endian.h
+ archive_entry.c
+ archive_entry.h
+ archive_entry_copy_stat.c
+ archive_entry_link_resolver.c
+ archive_entry_locale.h
+ archive_entry_private.h
+ archive_entry_sparse.c
+ archive_entry_stat.c
+ archive_entry_strmode.c
+ archive_entry_xattr.c
+ archive_getdate.c
+ archive_match.c
+ archive_options.c
+ archive_options_private.h
+ archive_pack_dev.h
+ archive_pack_dev.c
+ archive_pathmatch.c
+ archive_pathmatch.h
+ archive_platform.h
+ archive_ppmd_private.h
+ archive_ppmd7.c
+ archive_ppmd7_private.h
+ archive_private.h
+ archive_rb.c
+ archive_rb.h
+ archive_read.c
+ archive_read_append_filter.c
+ archive_read_data_into_fd.c
+ archive_read_disk_entry_from_file.c
+ archive_read_disk_posix.c
+ archive_read_disk_private.h
+ archive_read_disk_set_standard_lookup.c
+ archive_read_extract.c
+ archive_read_extract2.c
+ archive_read_open_fd.c
+ archive_read_open_file.c
+ archive_read_open_filename.c
+ archive_read_open_memory.c
+ archive_read_private.h
+ archive_read_set_format.c
+ archive_read_set_options.c
+ archive_read_support_filter_all.c
+ archive_read_support_filter_bzip2.c
+ archive_read_support_filter_compress.c
+ archive_read_support_filter_gzip.c
+ archive_read_support_filter_grzip.c
+ archive_read_support_filter_lrzip.c
+ archive_read_support_filter_lzop.c
+ archive_read_support_filter_none.c
+ archive_read_support_filter_program.c
+ archive_read_support_filter_rpm.c
+ archive_read_support_filter_uu.c
+ archive_read_support_filter_xz.c
+ archive_read_support_format_7zip.c
+ archive_read_support_format_all.c
+ archive_read_support_format_ar.c
+ archive_read_support_format_by_code.c
+ archive_read_support_format_cab.c
+ archive_read_support_format_cpio.c
+ archive_read_support_format_empty.c
+ archive_read_support_format_iso9660.c
+ archive_read_support_format_lha.c
+ archive_read_support_format_mtree.c
+ archive_read_support_format_rar.c
+ archive_read_support_format_raw.c
+ archive_read_support_format_tar.c
+ archive_read_support_format_xar.c
+ archive_read_support_format_zip.c
+ archive_string.c
+ archive_string.h
+ archive_string_composition.h
+ archive_string_sprintf.c
+ archive_util.c
+ archive_virtual.c
+ archive_write.c
+ archive_write_disk_acl.c
+ archive_write_disk_posix.c
+ archive_write_disk_private.h
+ archive_write_disk_set_standard_lookup.c
+ archive_write_private.h
+ archive_write_open_fd.c
+ archive_write_open_file.c
+ archive_write_open_filename.c
+ archive_write_open_memory.c
+ archive_write_add_filter.c
+ archive_write_add_filter_b64encode.c
+ archive_write_add_filter_by_name.c
+ archive_write_add_filter_bzip2.c
+ archive_write_add_filter_compress.c
+ archive_write_add_filter_grzip.c
+ archive_write_add_filter_gzip.c
+ archive_write_add_filter_lrzip.c
+ archive_write_add_filter_lzop.c
+ archive_write_add_filter_none.c
+ archive_write_add_filter_program.c
+ archive_write_add_filter_uuencode.c
+ archive_write_add_filter_xz.c
+ archive_write_set_format.c
+ archive_write_set_format_7zip.c
+ archive_write_set_format_ar.c
+ archive_write_set_format_by_name.c
+ archive_write_set_format_cpio.c
+ archive_write_set_format_cpio_newc.c
+ archive_write_set_format_gnutar.c
+ archive_write_set_format_iso9660.c
+ archive_write_set_format_mtree.c
+ archive_write_set_format_pax.c
+ archive_write_set_format_raw.c
+ archive_write_set_format_shar.c
+ archive_write_set_format_ustar.c
+ archive_write_set_format_v7tar.c
+ archive_write_set_format_xar.c
+ archive_write_set_format_zip.c
+ archive_write_set_options.c
+ filter_fork_posix.c
+ filter_fork.h
+)
+
+# Man pages
+SET(libarchive_MANS
+ archive_entry.3
+ archive_entry_acl.3
+ archive_entry_linkify.3
+ archive_entry_paths.3
+ archive_entry_perms.3
+ archive_entry_stat.3
+ archive_entry_time.3
+ archive_read.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
+ cpio.5
+ libarchive.3
+ libarchive_internals.3
+ libarchive-formats.5
+ mtree.5
+ tar.5
+)
+
+IF(WIN32 AND NOT CYGWIN)
+ LIST(APPEND libarchive_SOURCES archive_entry_copy_bhfi.c)
+ LIST(APPEND libarchive_SOURCES archive_read_disk_windows.c)
+ LIST(APPEND libarchive_SOURCES archive_windows.c)
+ LIST(APPEND libarchive_SOURCES archive_windows.h)
+ LIST(APPEND libarchive_SOURCES archive_write_disk_windows.c)
+ LIST(APPEND libarchive_SOURCES filter_fork_windows.c)
+ENDIF(WIN32 AND NOT CYGWIN)
+
+# CMake needs just one static "cmlibarchive" library.
+ADD_LIBRARY(cmlibarchive STATIC ${libarchive_SOURCES} ${include_HEADERS})
+TARGET_LINK_LIBRARIES(cmlibarchive ${ADDITIONAL_LIBS})
diff --git a/Utilities/cmlibarchive/libarchive/archive.h b/Utilities/cmlibarchive/libarchive/archive.h
new file mode 100644
index 0000000000..9cf762da58
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive.h
@@ -0,0 +1,1116 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD: src/lib/libarchive/archive.h.in,v 1.50 2008/05/26 17:00:22 kientzle Exp $
+ */
+
+#ifndef ARCHIVE_H_INCLUDED
+#define ARCHIVE_H_INCLUDED
+
+#include <sys/stat.h>
+#include <stddef.h> /* for wchar_t */
+#include <stdio.h> /* For FILE * */
+
+/*
+ * Note: archive.h is for use outside of libarchive; the configuration
+ * headers (config.h, archive_platform.h, etc.) are purely internal.
+ * Do NOT use HAVE_XXX configuration macros to control the behavior of
+ * this header! If you must conditionalize, use predefined compiler and/or
+ * platform macros.
+ */
+#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560
+# include <stdint.h>
+#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS) && !defined(__osf__)
+# 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_
+#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
+# endif
+#else
+# include <unistd.h> /* ssize_t, uid_t, and gid_t */
+# if defined(_SCO_DS) || defined(__osf__)
+# define __LA_INT64_T long long
+# else
+# define __LA_INT64_T int64_t
+# endif
+# define __LA_SSIZE_T ssize_t
+#endif
+
+/*
+ * On Windows, define LIBARCHIVE_STATIC if you're building or using a
+ * .lib. The default here assumes you're building a DLL. Only
+ * libarchive source should ever define __LIBARCHIVE_BUILD.
+ */
+#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
+# ifdef __LIBARCHIVE_BUILD
+# ifdef __GNUC__
+# define __LA_DECL __attribute__((dllexport)) extern
+# else
+# define __LA_DECL __declspec(dllexport)
+# endif
+# else
+# ifdef __GNUC__
+# define __LA_DECL
+# else
+# define __LA_DECL __declspec(dllimport)
+# endif
+# endif
+#else
+/* Static libraries or non-Windows needs no special declaration. */
+# define __LA_DECL
+#endif
+
+#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__MINGW32__)
+#define __LA_PRINTF(fmtarg, firstvararg) \
+ __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
+#else
+#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */
+#endif
+
+/* CMake uses some deprecated APIs to build with old libarchive versions. */
+#define __LA_DEPRECATED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * The version number is provided as both a macro and a function.
+ * The macro identifies the installed header; the function identifies
+ * the library version (which may not be the same if you're using a
+ * dynamically-linked version of the library). Of course, if the
+ * 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"
+__LA_DECL const char * archive_version_string(void);
+
+/*
+ * Detailed textual name/version of the library and its dependencies.
+ */
+__LA_DECL const char * archive_version_details(void);
+
+/* Declare our basic types. */
+struct archive;
+struct archive_entry;
+
+/*
+ * Error codes: Use archive_errno() and archive_error_string()
+ * to retrieve details. Unless specified otherwise, all functions
+ * that return 'int' use these codes.
+ */
+#define ARCHIVE_EOF 1 /* Found end of archive. */
+#define ARCHIVE_OK 0 /* Operation was successful. */
+#define ARCHIVE_RETRY (-10) /* Retry might succeed. */
+#define ARCHIVE_WARN (-20) /* Partial success. */
+/* For example, if write_header "fails", then you can't push data. */
+#define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */
+/* But if write_header is "fatal," then this archive is dead and useless. */
+#define ARCHIVE_FATAL (-30) /* No more operations are possible. */
+
+/*
+ * As far as possible, archive_errno returns standard platform errno codes.
+ * Of course, the details vary by platform, so the actual definitions
+ * here are stored in "archive_platform.h". The symbols are listed here
+ * for reference; as a rule, clients should not need to know the exact
+ * platform-dependent error code.
+ */
+/* Unrecognized or invalid file format. */
+/* #define ARCHIVE_ERRNO_FILE_FORMAT */
+/* Illegal usage of the library. */
+/* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */
+/* Unknown or unclassified error. */
+/* #define ARCHIVE_ERRNO_MISC */
+
+/*
+ * Callbacks are invoked to automatically read/skip/write/open/close the
+ * archive. You can provide your own for complex tasks (like breaking
+ * archives across multiple tapes) or use standard ones built into the
+ * library.
+ */
+
+/* Returns pointer and size of next block of data from 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.
+ * This may skip fewer bytes than requested; it may even skip zero bytes.
+ * 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);
+
+/* 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);
+
+/* Returns size actually written, zero on EOF, -1 on error. */
+typedef __LA_SSIZE_T archive_write_callback(struct archive *,
+ void *_client_data,
+ const void *_buffer, size_t _length);
+
+typedef int archive_open_callback(struct archive *, void *_client_data);
+
+typedef int archive_close_callback(struct archive *, void *_client_data);
+
+/* Switches from one client data object to the next/prev client data object.
+ * This is useful for reading from different data blocks such as a set of files
+ * that make up one large file.
+ */
+typedef int archive_switch_callback(struct archive *, void *_client_data1,
+ void *_client_data2);
+
+/*
+ * Codes to identify various stream filters.
+ */
+#define ARCHIVE_FILTER_NONE 0
+#define ARCHIVE_FILTER_GZIP 1
+#define ARCHIVE_FILTER_BZIP2 2
+#define ARCHIVE_FILTER_COMPRESS 3
+#define ARCHIVE_FILTER_PROGRAM 4
+#define ARCHIVE_FILTER_LZMA 5
+#define ARCHIVE_FILTER_XZ 6
+#define ARCHIVE_FILTER_UU 7
+#define ARCHIVE_FILTER_RPM 8
+#define ARCHIVE_FILTER_LZIP 9
+#define ARCHIVE_FILTER_LRZIP 10
+#define ARCHIVE_FILTER_LZOP 11
+#define ARCHIVE_FILTER_GRZIP 12
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+#define ARCHIVE_COMPRESSION_NONE ARCHIVE_FILTER_NONE
+#define ARCHIVE_COMPRESSION_GZIP ARCHIVE_FILTER_GZIP
+#define ARCHIVE_COMPRESSION_BZIP2 ARCHIVE_FILTER_BZIP2
+#define ARCHIVE_COMPRESSION_COMPRESS ARCHIVE_FILTER_COMPRESS
+#define ARCHIVE_COMPRESSION_PROGRAM ARCHIVE_FILTER_PROGRAM
+#define ARCHIVE_COMPRESSION_LZMA ARCHIVE_FILTER_LZMA
+#define ARCHIVE_COMPRESSION_XZ ARCHIVE_FILTER_XZ
+#define ARCHIVE_COMPRESSION_UU ARCHIVE_FILTER_UU
+#define ARCHIVE_COMPRESSION_RPM ARCHIVE_FILTER_RPM
+#define ARCHIVE_COMPRESSION_LZIP ARCHIVE_FILTER_LZIP
+#define ARCHIVE_COMPRESSION_LRZIP ARCHIVE_FILTER_LRZIP
+#endif
+
+/*
+ * Codes returned by archive_format.
+ *
+ * Top 16 bits identifies the format family (e.g., "tar"); lower
+ * 16 bits indicate the variant. This is updated by read_next_header.
+ * Note that the lower 16 bits will often vary from entry to entry.
+ * In some cases, this variation occurs as libarchive learns more about
+ * the archive (for example, later entries might utilize extensions that
+ * weren't necessary earlier in the archive; in this case, libarchive
+ * will change the format code to indicate the extended format that
+ * was used). In other cases, it's because different tools have
+ * modified the archive and so different parts of the archive
+ * actually have slightly different formats. (Both tar and cpio store
+ * format codes in each entry, so it is quite possible for each
+ * entry to be in a different format.)
+ */
+#define ARCHIVE_FORMAT_BASE_MASK 0xff0000
+#define ARCHIVE_FORMAT_CPIO 0x10000
+#define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1)
+#define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2)
+#define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3)
+#define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4)
+#define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5)
+#define ARCHIVE_FORMAT_CPIO_AFIO_LARGE (ARCHIVE_FORMAT_CPIO | 6)
+#define ARCHIVE_FORMAT_SHAR 0x20000
+#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1)
+#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2)
+#define ARCHIVE_FORMAT_TAR 0x30000
+#define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1)
+#define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2)
+#define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3)
+#define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4)
+#define ARCHIVE_FORMAT_ISO9660 0x40000
+#define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1)
+#define ARCHIVE_FORMAT_ZIP 0x50000
+#define ARCHIVE_FORMAT_EMPTY 0x60000
+#define ARCHIVE_FORMAT_AR 0x70000
+#define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1)
+#define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2)
+#define ARCHIVE_FORMAT_MTREE 0x80000
+#define ARCHIVE_FORMAT_RAW 0x90000
+#define ARCHIVE_FORMAT_XAR 0xA0000
+#define ARCHIVE_FORMAT_LHA 0xB0000
+#define ARCHIVE_FORMAT_CAB 0xC0000
+#define ARCHIVE_FORMAT_RAR 0xD0000
+#define ARCHIVE_FORMAT_7ZIP 0xE0000
+
+/*
+ * Codes returned by archive_read_format_capabilities().
+ *
+ * This list can be extended with values between 0 and 0xffff.
+ * The original purpose of this list was to let different archive
+ * format readers expose their general capabilities in terms of
+ * encryption.
+ */
+#define ARCHIVE_READ_FORMAT_CAPS_NONE (0) /* no special capabilities */
+#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA (1<<0) /* reader can detect encrypted data */
+#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA (1<<1) /* reader can detect encryptable metadata (pathname, mtime, etc.) */
+
+/*
+ * Codes returned by archive_read_has_encrypted_entries().
+ *
+ * In case the archive does not support encryption detection at all
+ * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned. If the reader
+ * for some other reason (e.g. not enough bytes read) cannot say if
+ * there are encrypted entries, ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW
+ * is returned.
+ */
+#define ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED -2
+#define ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW -1
+
+/*-
+ * Basic outline for reading an archive:
+ * 1) Ask archive_read_new for an archive reader object.
+ * 2) Update any global properties as appropriate.
+ * In particular, you'll certainly want to call appropriate
+ * archive_read_support_XXX functions.
+ * 3) Call archive_read_open_XXX to open the archive
+ * 4) Repeatedly call archive_read_next_header to get information about
+ * successive archive entries. Call archive_read_data to extract
+ * data for entries of interest.
+ * 5) Call archive_read_finish to end processing.
+ */
+__LA_DECL struct archive *archive_read_new(void);
+
+/*
+ * The archive_read_support_XXX calls enable auto-detect for this
+ * archive handle. They also link in the necessary support code.
+ * For example, if you don't want bzlib linked in, don't invoke
+ * support_compression_bzip2(). The "all" functions provide the
+ * obvious shorthand.
+ */
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+__LA_DECL int archive_read_support_compression_all(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_bzip2(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_compress(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_gzip(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_lzip(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_lzma(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_none(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_program(struct archive *,
+ const char *command) __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_program_signature
+ (struct archive *, const char *,
+ const void * /* match */, size_t) __LA_DEPRECATED;
+
+__LA_DECL int archive_read_support_compression_rpm(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_uu(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_read_support_compression_xz(struct archive *)
+ __LA_DEPRECATED;
+#endif
+
+__LA_DECL int archive_read_support_filter_all(struct archive *);
+__LA_DECL int archive_read_support_filter_bzip2(struct archive *);
+__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_lzip(struct archive *);
+__LA_DECL int archive_read_support_filter_lzma(struct archive *);
+__LA_DECL int archive_read_support_filter_lzop(struct archive *);
+__LA_DECL int archive_read_support_filter_none(struct archive *);
+__LA_DECL int archive_read_support_filter_program(struct archive *,
+ const char *command);
+__LA_DECL int archive_read_support_filter_program_signature
+ (struct archive *, const char * /* cmd */,
+ const void * /* match */, size_t);
+__LA_DECL int archive_read_support_filter_rpm(struct archive *);
+__LA_DECL int archive_read_support_filter_uu(struct archive *);
+__LA_DECL int archive_read_support_filter_xz(struct archive *);
+
+__LA_DECL int archive_read_support_format_7zip(struct archive *);
+__LA_DECL int archive_read_support_format_all(struct archive *);
+__LA_DECL int archive_read_support_format_ar(struct archive *);
+__LA_DECL int archive_read_support_format_by_code(struct archive *, int);
+__LA_DECL int archive_read_support_format_cab(struct archive *);
+__LA_DECL int archive_read_support_format_cpio(struct archive *);
+__LA_DECL int archive_read_support_format_empty(struct archive *);
+__LA_DECL int archive_read_support_format_gnutar(struct archive *);
+__LA_DECL int archive_read_support_format_iso9660(struct archive *);
+__LA_DECL int archive_read_support_format_lha(struct archive *);
+__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_xar(struct archive *);
+/* archive_read_support_format_zip() enables both streamable and seekable
+ * zip readers. */
+__LA_DECL int archive_read_support_format_zip(struct archive *);
+/* Reads Zip archives as stream from beginning to end. Doesn't
+ * correctly handle SFX ZIP files or ZIP archives that have been modified
+ * in-place. */
+__LA_DECL int archive_read_support_format_zip_streamable(struct archive *);
+/* Reads starting from central directory; requires seekable input. */
+__LA_DECL int archive_read_support_format_zip_seekable(struct archive *);
+
+/* Functions to manually set the format and filters to be used. This is
+ * useful to bypass the bidding process when the format and filters to use
+ * is known in advance.
+ */
+__LA_DECL int archive_read_set_format(struct archive *, int);
+__LA_DECL int archive_read_append_filter(struct archive *, int);
+__LA_DECL int archive_read_append_filter_program(struct archive *,
+ const char *);
+__LA_DECL int archive_read_append_filter_program_signature
+ (struct archive *, const char *, const void * /* match */, size_t);
+
+/* Set various callbacks. */
+__LA_DECL int archive_read_set_open_callback(struct archive *,
+ archive_open_callback *);
+__LA_DECL int archive_read_set_read_callback(struct archive *,
+ archive_read_callback *);
+__LA_DECL int archive_read_set_seek_callback(struct archive *,
+ archive_seek_callback *);
+__LA_DECL int archive_read_set_skip_callback(struct archive *,
+ archive_skip_callback *);
+__LA_DECL int archive_read_set_close_callback(struct archive *,
+ archive_close_callback *);
+/* Callback used to switch between one data object to the next */
+__LA_DECL int archive_read_set_switch_callback(struct archive *,
+ archive_switch_callback *);
+
+/* This sets the first data object. */
+__LA_DECL int archive_read_set_callback_data(struct archive *, void *);
+/* This sets data object at specified index */
+__LA_DECL int archive_read_set_callback_data2(struct archive *, void *,
+ unsigned int);
+/* This adds a data object at the specified index. */
+__LA_DECL int archive_read_add_callback_data(struct archive *, void *,
+ unsigned int);
+/* This appends a data object to the end of list */
+__LA_DECL int archive_read_append_callback_data(struct archive *, void *);
+/* This prepends a data object to the beginning of list */
+__LA_DECL int archive_read_prepend_callback_data(struct archive *, void *);
+
+/* Opening freezes the callbacks. */
+__LA_DECL int archive_read_open1(struct archive *);
+
+/* Convenience wrappers around the above. */
+__LA_DECL int archive_read_open(struct archive *, void *_client_data,
+ archive_open_callback *, archive_read_callback *,
+ archive_close_callback *);
+__LA_DECL int archive_read_open2(struct archive *, void *_client_data,
+ archive_open_callback *, archive_read_callback *,
+ archive_skip_callback *, archive_close_callback *);
+
+/*
+ * A variety of shortcuts that invoke archive_read_open() with
+ * canned callbacks suitable for common situations. The ones that
+ * accept a block size handle tape blocking correctly.
+ */
+/* Use this if you know the filename. Note: NULL indicates stdin. */
+__LA_DECL int archive_read_open_filename(struct archive *,
+ const char *_filename, size_t _block_size);
+/* Use this for reading multivolume files by filenames.
+ * NOTE: Must be NULL terminated. Sorting is NOT done. */
+__LA_DECL int archive_read_open_filenames(struct archive *,
+ const char **_filenames, size_t _block_size);
+__LA_DECL int archive_read_open_filename_w(struct archive *,
+ const wchar_t *_filename, size_t _block_size);
+/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */
+__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);
+/* A more involved version that is only used for internal testing. */
+__LA_DECL int archive_read_open_memory2(struct archive *a, 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,
+ size_t _block_size);
+/* Read an archive that's already open, using a FILE *. */
+/* Note: DO NOT use this with tape drives. */
+__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file);
+
+/* Parses and returns next entry header. */
+__LA_DECL int archive_read_next_header(struct archive *,
+ struct archive_entry **);
+
+/* Parses and returns next entry header using the archive_entry passed in */
+__LA_DECL int archive_read_next_header2(struct archive *,
+ struct archive_entry *);
+
+/*
+ * Retrieve the byte offset in UNCOMPRESSED data where last-read
+ * header started.
+ */
+__LA_DECL __LA_INT64_T archive_read_header_position(struct archive *);
+
+/*
+ * Returns 1 if the archive contains at least one encrypted entry.
+ * If the archive format not support encryption at all
+ * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned.
+ * If for any other reason (e.g. not enough data read so far)
+ * we cannot say whether there are encrypted entries, then
+ * ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW is returned.
+ * In general, this function will return values below zero when the
+ * reader is uncertain or totally uncapable of encryption support.
+ * When this function returns 0 you can be sure that the reader
+ * supports encryption detection but no encrypted entries have
+ * been found yet.
+ *
+ * NOTE: If the metadata/header of an archive is also encrypted, you
+ * cannot rely on the number of encrypted entries. That is why this
+ * function does not return the number of encrypted entries but#
+ * just shows that there are some.
+ */
+__LA_DECL int archive_read_has_encrypted_entries(struct archive *);
+
+/*
+ * Returns a bitmask of capabilities that are supported by the archive format reader.
+ * If the reader has no special capabilities, ARCHIVE_READ_FORMAT_CAPS_NONE is returned.
+ */
+__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 *,
+ 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);
+
+/*
+ * A zero-copy version of archive_read_data that also exposes the file offset
+ * of each returned block. Note that the client has no way to specify
+ * the desired size of the block. The API does guarantee that offsets will
+ * 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);
+
+/*-
+ * Some convenience functions that are built on archive_read_data:
+ * 'skip': skips entire entry
+ * 'into_buffer': writes data into memory buffer that you provide
+ * 'into_fd': writes data to specified filedes
+ */
+__LA_DECL int archive_read_data_skip(struct archive *);
+__LA_DECL int archive_read_data_into_fd(struct archive *, int fd);
+
+/*
+ * Set read options.
+ */
+/* Apply option to the format only. */
+__LA_DECL int archive_read_set_format_option(struct archive *_a,
+ const char *m, const char *o,
+ const char *v);
+/* Apply option to the filter only. */
+__LA_DECL int archive_read_set_filter_option(struct archive *_a,
+ const char *m, const char *o,
+ const char *v);
+/* Apply option to both the format and the filter. */
+__LA_DECL int archive_read_set_option(struct archive *_a,
+ const char *m, const char *o,
+ const char *v);
+/* Apply option string to both the format and the filter. */
+__LA_DECL int archive_read_set_options(struct archive *_a,
+ const char *opts);
+
+/*-
+ * Convenience function to recreate the current entry (whose header
+ * has just been read) on disk.
+ *
+ * This does quite a bit more than just copy data to disk. It also:
+ * - Creates intermediate directories as required.
+ * - Manages directory permissions: non-writable directories will
+ * be initially created with write permission enabled; when the
+ * archive is closed, dir permissions are edited to the values specified
+ * in the archive.
+ * - Checks hardlinks: hardlinks will not be extracted unless the
+ * linked-to file was also extracted within the same session. (TODO)
+ */
+
+/* The "flags" argument selects optional behavior, 'OR' the flags you want. */
+
+/* Default: Do not try to set owner/group. */
+#define ARCHIVE_EXTRACT_OWNER (0x0001)
+/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
+#define ARCHIVE_EXTRACT_PERM (0x0002)
+/* Default: Do not restore mtime/atime. */
+#define ARCHIVE_EXTRACT_TIME (0x0004)
+/* Default: Replace existing files. */
+#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008)
+/* Default: Try create first, unlink only if create fails with EEXIST. */
+#define ARCHIVE_EXTRACT_UNLINK (0x0010)
+/* Default: Do not restore ACLs. */
+#define ARCHIVE_EXTRACT_ACL (0x0020)
+/* Default: Do not restore fflags. */
+#define ARCHIVE_EXTRACT_FFLAGS (0x0040)
+/* Default: Do not restore xattrs. */
+#define ARCHIVE_EXTRACT_XATTR (0x0080)
+/* Default: Do not try to guard against extracts redirected by symlinks. */
+/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
+#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100)
+/* Default: Do not reject entries with '..' as path elements. */
+#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200)
+/* Default: Create parent directories as needed. */
+#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400)
+/* Default: Overwrite files, even if one on disk is newer. */
+#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800)
+/* Detect blocks of 0 and write holes instead. */
+#define ARCHIVE_EXTRACT_SPARSE (0x1000)
+/* Default: Do not restore Mac extended metadata. */
+/* This has no effect except on Mac OS. */
+#define ARCHIVE_EXTRACT_MAC_METADATA (0x2000)
+/* Default: Use HFS+ compression if it was compressed. */
+/* This has no effect except on Mac OS v10.6 or later. */
+#define ARCHIVE_EXTRACT_NO_HFS_COMPRESSION (0x4000)
+/* 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)
+
+__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
+ int flags);
+__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *,
+ struct archive * /* dest */);
+__LA_DECL void archive_read_extract_set_progress_callback(struct archive *,
+ void (*_progress_func)(void *), void *_user_data);
+
+/* 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);
+
+/* Close the file and release most resources. */
+__LA_DECL int archive_read_close(struct archive *);
+/* Release all resources and destroy the object. */
+/* Note that archive_read_free will call archive_read_close for you. */
+__LA_DECL int archive_read_free(struct archive *);
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Synonym for archive_read_free() for backwards compatibility. */
+__LA_DECL int archive_read_finish(struct archive *) __LA_DEPRECATED;
+#endif
+
+/*-
+ * To create an archive:
+ * 1) Ask archive_write_new for an archive writer object.
+ * 2) Set any global properties. In particular, you should set
+ * the compression and format to use.
+ * 3) Call archive_write_open to open the file (most people
+ * will use archive_write_open_file or archive_write_open_fd,
+ * which provide convenient canned I/O callbacks for you).
+ * 4) For each entry:
+ * - construct an appropriate struct archive_entry structure
+ * - archive_write_header to write the header
+ * - archive_write_data to write the entry data
+ * 5) archive_write_close to close the output
+ * 6) archive_write_free to cleanup the writer and release resources
+ */
+__LA_DECL struct archive *archive_write_new(void);
+__LA_DECL int archive_write_set_bytes_per_block(struct archive *,
+ int bytes_per_block);
+__LA_DECL int archive_write_get_bytes_per_block(struct archive *);
+/* XXX This is badly misnamed; suggestions appreciated. XXX */
+__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *,
+ int bytes_in_last_block);
+__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);
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+__LA_DECL int archive_write_set_compression_bzip2(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_write_set_compression_compress(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_write_set_compression_gzip(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_write_set_compression_lzip(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_write_set_compression_lzma(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_write_set_compression_none(struct archive *)
+ __LA_DEPRECATED;
+__LA_DECL int archive_write_set_compression_program(struct archive *,
+ const char *cmd) __LA_DEPRECATED;
+__LA_DECL int archive_write_set_compression_xz(struct archive *)
+ __LA_DEPRECATED;
+#endif
+
+/* A convenience function to set the filter based on the code. */
+__LA_DECL int archive_write_add_filter(struct archive *, int filter_code);
+__LA_DECL int archive_write_add_filter_by_name(struct archive *,
+ const char *name);
+__LA_DECL int archive_write_add_filter_b64encode(struct archive *);
+__LA_DECL int archive_write_add_filter_bzip2(struct archive *);
+__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_lzip(struct archive *);
+__LA_DECL int archive_write_add_filter_lzma(struct archive *);
+__LA_DECL int archive_write_add_filter_lzop(struct archive *);
+__LA_DECL int archive_write_add_filter_none(struct archive *);
+__LA_DECL int archive_write_add_filter_program(struct archive *,
+ const char *cmd);
+__LA_DECL int archive_write_add_filter_uuencode(struct archive *);
+__LA_DECL int archive_write_add_filter_xz(struct archive *);
+
+
+/* A convenience function to set the format based on the code or name. */
+__LA_DECL int archive_write_set_format(struct archive *, int format_code);
+__LA_DECL int archive_write_set_format_by_name(struct archive *,
+ const char *name);
+/* To minimize link pollution, use one or more of the following. */
+__LA_DECL int archive_write_set_format_7zip(struct archive *);
+__LA_DECL int archive_write_set_format_ar_bsd(struct archive *);
+__LA_DECL int archive_write_set_format_ar_svr4(struct archive *);
+__LA_DECL int archive_write_set_format_cpio(struct archive *);
+__LA_DECL int archive_write_set_format_cpio_newc(struct archive *);
+__LA_DECL int archive_write_set_format_gnutar(struct archive *);
+__LA_DECL int archive_write_set_format_iso9660(struct archive *);
+__LA_DECL int archive_write_set_format_mtree(struct archive *);
+__LA_DECL int archive_write_set_format_mtree_classic(struct archive *);
+/* TODO: int archive_write_set_format_old_tar(struct archive *); */
+__LA_DECL int archive_write_set_format_pax(struct archive *);
+__LA_DECL int archive_write_set_format_pax_restricted(struct archive *);
+__LA_DECL int archive_write_set_format_raw(struct archive *);
+__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_xar(struct archive *);
+__LA_DECL int archive_write_set_format_zip(struct archive *);
+__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 *,
+ archive_open_callback *, archive_write_callback *,
+ archive_close_callback *);
+__LA_DECL int archive_write_open_fd(struct archive *, int _fd);
+__LA_DECL int archive_write_open_filename(struct archive *, const char *_file);
+__LA_DECL int archive_write_open_filename_w(struct archive *,
+ const wchar_t *_file);
+/* A deprecated synonym for archive_write_open_filename() */
+__LA_DECL int archive_write_open_file(struct archive *, const char *_file)
+ __LA_DEPRECATED;
+__LA_DECL int archive_write_open_FILE(struct archive *, FILE *);
+/* _buffSize is the size of the buffer, _used refers to a variable that
+ * will be updated after each write into the buffer. */
+__LA_DECL int archive_write_open_memory(struct archive *,
+ void *_buffer, size_t _buffSize, size_t *_used);
+
+/*
+ * Note that the library will truncate writes beyond the size provided
+ * to archive_write_header or pad if the provided data is short.
+ */
+__LA_DECL int archive_write_header(struct archive *,
+ struct archive_entry *);
+__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 int archive_write_finish_entry(struct archive *);
+__LA_DECL int archive_write_close(struct archive *);
+/* Marks the archive as FATAL so that a subsequent free() operation
+ * won't try to close() cleanly. Provides a fast abort capability
+ * when the client discovers that things have gone wrong. */
+__LA_DECL int archive_write_fail(struct archive *);
+/* This can fail if the archive wasn't already closed, in which case
+ * archive_write_free() will implicitly call archive_write_close(). */
+__LA_DECL int archive_write_free(struct archive *);
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Synonym for archive_write_free() for backwards compatibility. */
+__LA_DECL int archive_write_finish(struct archive *) __LA_DEPRECATED;
+#endif
+
+/*
+ * Set write options.
+ */
+/* Apply option to the format only. */
+__LA_DECL int archive_write_set_format_option(struct archive *_a,
+ const char *m, const char *o,
+ const char *v);
+/* Apply option to the filter only. */
+__LA_DECL int archive_write_set_filter_option(struct archive *_a,
+ const char *m, const char *o,
+ const char *v);
+/* Apply option to both the format and the filter. */
+__LA_DECL int archive_write_set_option(struct archive *_a,
+ const char *m, const char *o,
+ const char *v);
+/* Apply option string to both the format and the filter. */
+__LA_DECL int archive_write_set_options(struct archive *_a,
+ const char *opts);
+
+/*-
+ * ARCHIVE_WRITE_DISK API
+ *
+ * To create objects on disk:
+ * 1) Ask archive_write_disk_new for a new archive_write_disk object.
+ * 2) Set any global properties. In particular, you probably
+ * want to set the options.
+ * 3) For each entry:
+ * - construct an appropriate struct archive_entry structure
+ * - archive_write_header to create the file/dir/etc on disk
+ * - archive_write_data to write the entry data
+ * 4) archive_write_free to cleanup the writer and release resources
+ *
+ * In particular, you can use this in conjunction with archive_read()
+ * to pull entries out of an archive and create them on disk.
+ */
+__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);
+/* 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 *,
+ int flags);
+/*
+ * The lookup functions are given uname/uid (or gname/gid) pairs and
+ * return a uid (gid) suitable for this system. These are used for
+ * restoring ownership and for setting ACLs. The default functions
+ * are naive, they just return the uid/gid. These are small, so reasonable
+ * for applications that don't need to preserve ownership; they
+ * are probably also appropriate for applications that are doing
+ * same-system backup and restore.
+ */
+/*
+ * The "standard" lookup functions use common system calls to lookup
+ * the uname/gname, falling back to the uid/gid if the names can't be
+ * found. They cache lookups and are reasonably fast, but can be very
+ * large, so they are not used unless you ask for them. In
+ * particular, these match the specifications of POSIX "pax" and old
+ * POSIX "tar".
+ */
+__LA_DECL int archive_write_disk_set_standard_lookup(struct archive *);
+/*
+ * If neither the default (naive) nor the standard (big) functions suit
+ * your needs, you can write your own and register them. Be sure to
+ * include a cleanup function if you have allocated private data.
+ */
+__LA_DECL int archive_write_disk_set_group_lookup(struct archive *,
+ void * /* private_data */,
+ __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),
+ 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);
+
+/*
+ * ARCHIVE_READ_DISK API
+ *
+ * This is still evolving and somewhat experimental.
+ */
+__LA_DECL struct archive *archive_read_disk_new(void);
+/* The names for symlink modes here correspond to an old BSD
+ * command-line argument convention: -L, -P, -H */
+/* Follow all symlinks. */
+__LA_DECL int archive_read_disk_set_symlink_logical(struct archive *);
+/* Follow no symlinks. */
+__LA_DECL int archive_read_disk_set_symlink_physical(struct archive *);
+/* Follow symlink initially, then not. */
+__LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *);
+/* TODO: Handle Linux stat32/stat64 ugliness. <sigh> */
+__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);
+/* "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),
+ 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),
+ void (* /* cleanup_fn */)(void *));
+/* Start traversal. */
+__LA_DECL int archive_read_disk_open(struct archive *, const char *);
+__LA_DECL int archive_read_disk_open_w(struct archive *, const wchar_t *);
+/*
+ * Request that current entry be visited. If you invoke it on every
+ * directory, you'll get a physical traversal. This is ignored if the
+ * current entry isn't a directory or a link to a directory. So, if
+ * you invoke this on every returned path, you'll get a full logical
+ * traversal.
+ */
+__LA_DECL int archive_read_disk_descend(struct archive *);
+__LA_DECL int archive_read_disk_can_descend(struct archive *);
+__LA_DECL int archive_read_disk_current_filesystem(struct archive *);
+__LA_DECL int archive_read_disk_current_filesystem_is_synthetic(struct archive *);
+__LA_DECL int archive_read_disk_current_filesystem_is_remote(struct archive *);
+/* Request that the access time of the entry visited by travesal be restored. */
+__LA_DECL int archive_read_disk_set_atime_restored(struct archive *);
+/*
+ * Set behavior. The "flags" argument selects optional behavior.
+ */
+/* Request that the access time of the entry visited by travesal be restored.
+ * This is the same as archive_read_disk_set_atime_restored. */
+#define ARCHIVE_READDISK_RESTORE_ATIME (0x0001)
+/* Default: Do not skip an entry which has nodump flags. */
+#define ARCHIVE_READDISK_HONOR_NODUMP (0x0002)
+/* 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. */
+#define ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS (0x0008)
+
+__LA_DECL int archive_read_disk_set_behavior(struct archive *,
+ int flags);
+
+/*
+ * Set archive_match object that will be used in archive_read_disk to
+ * know whether an entry should be skipped. The callback function
+ * _excluded_func will be invoked when an entry is skipped by the result
+ * of archive_match.
+ */
+__LA_DECL int archive_read_disk_set_matching(struct archive *,
+ struct archive *_matching, void (*_excluded_func)
+ (struct archive *, void *, struct archive_entry *),
+ void *_client_data);
+__LA_DECL int archive_read_disk_set_metadata_filter_callback(struct archive *,
+ int (*_metadata_filter_func)(struct archive *, void *,
+ struct archive_entry *), void *_client_data);
+
+/* Simplified cleanup interface;
+ * This calls archive_read_free() or archive_write_free() as needed. */
+__LA_DECL int archive_free(struct archive *);
+
+/*
+ * Accessor functions to read/set various information in
+ * the struct archive object:
+ */
+
+/* Number of filters in the current filter pipeline. */
+/* Filter #0 is the one closest to the format, -1 is a synonym for the
+ * 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 int archive_filter_code(struct archive *, int);
+__LA_DECL const char * archive_filter_name(struct archive *, int);
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* 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_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_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 *)
+ __LA_DEPRECATED;
+/* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */
+__LA_DECL int archive_compression(struct archive *)
+ __LA_DEPRECATED;
+#endif
+
+__LA_DECL int archive_errno(struct archive *);
+__LA_DECL const char *archive_error_string(struct archive *);
+__LA_DECL const char *archive_format_name(struct archive *);
+__LA_DECL int archive_format(struct archive *);
+__LA_DECL void archive_clear_error(struct archive *);
+__LA_DECL void archive_set_error(struct archive *, int _err,
+ const char *fmt, ...) __LA_PRINTF(3, 4);
+__LA_DECL void archive_copy_error(struct archive *dest,
+ struct archive *src);
+__LA_DECL int archive_file_count(struct archive *);
+
+/*
+ * ARCHIVE_MATCH API
+ */
+__LA_DECL struct archive *archive_match_new(void);
+__LA_DECL int archive_match_free(struct archive *);
+
+/*
+ * Test if archive_entry is excluded.
+ * This is a convenience function. This is the same as calling all
+ * archive_match_path_excluded, archive_match_time_excluded
+ * and archive_match_owner_excluded.
+ */
+__LA_DECL int archive_match_excluded(struct archive *,
+ struct archive_entry *);
+
+/*
+ * Test if pathname is excluded. The conditions are set by following functions.
+ */
+__LA_DECL int archive_match_path_excluded(struct archive *,
+ struct archive_entry *);
+/* Add exclusion pathname pattern. */
+__LA_DECL int archive_match_exclude_pattern(struct archive *, const char *);
+__LA_DECL int archive_match_exclude_pattern_w(struct archive *,
+ const wchar_t *);
+/* Add exclusion pathname pattern from file. */
+__LA_DECL int archive_match_exclude_pattern_from_file(struct archive *,
+ const char *, int _nullSeparator);
+__LA_DECL int archive_match_exclude_pattern_from_file_w(struct archive *,
+ const wchar_t *, int _nullSeparator);
+/* Add inclusion pathname pattern. */
+__LA_DECL int archive_match_include_pattern(struct archive *, const char *);
+__LA_DECL int archive_match_include_pattern_w(struct archive *,
+ const wchar_t *);
+/* Add inclusion pathname pattern from file. */
+__LA_DECL int archive_match_include_pattern_from_file(struct archive *,
+ const char *, int _nullSeparator);
+__LA_DECL int archive_match_include_pattern_from_file_w(struct archive *,
+ const wchar_t *, int _nullSeparator);
+/*
+ * How to get statistic information for inclusion patterns.
+ */
+/* Return the amount number of unmatched inclusion patterns. */
+__LA_DECL int archive_match_path_unmatched_inclusions(struct archive *);
+/* Return the pattern of unmatched inclusion with ARCHIVE_OK.
+ * Return ARCHIVE_EOF if there is no inclusion pattern. */
+__LA_DECL int archive_match_path_unmatched_inclusions_next(
+ struct archive *, const char **);
+__LA_DECL int archive_match_path_unmatched_inclusions_next_w(
+ struct archive *, const wchar_t **);
+
+/*
+ * Test if a file is excluded by its time stamp.
+ * The conditions are set by following functions.
+ */
+__LA_DECL int archive_match_time_excluded(struct archive *,
+ struct archive_entry *);
+
+/*
+ * Flags to tell a matching type of time stamps. These are used for
+ * following functinos.
+ */
+/* Time flag: mtime to be tested. */
+#define ARCHIVE_MATCH_MTIME (0x0100)
+/* Time flag: ctime to be tested. */
+#define ARCHIVE_MATCH_CTIME (0x0200)
+/* Comparison flag: Match the time if it is newer than. */
+#define ARCHIVE_MATCH_NEWER (0x0001)
+/* Comparison flag: Match the time if it is older than. */
+#define ARCHIVE_MATCH_OLDER (0x0002)
+/* Comparison flag: Match the time if it is equal to. */
+#define ARCHIVE_MATCH_EQUAL (0x0010)
+/* Set inclusion time. */
+__LA_DECL int archive_match_include_time(struct archive *, int _flag,
+ time_t _sec, long _nsec);
+/* Set inclusion time by a date string. */
+__LA_DECL int archive_match_include_date(struct archive *, int _flag,
+ const char *_datestr);
+__LA_DECL int archive_match_include_date_w(struct archive *, int _flag,
+ const wchar_t *_datestr);
+/* Set inclusion time by a particluar file. */
+__LA_DECL int archive_match_include_file_time(struct archive *,
+ int _flag, const char *_pathname);
+__LA_DECL int archive_match_include_file_time_w(struct archive *,
+ int _flag, const wchar_t *_pathname);
+/* Add exclusion entry. */
+__LA_DECL int archive_match_exclude_entry(struct archive *,
+ int _flag, struct archive_entry *);
+
+/*
+ * Test if a file is excluded by its uid ,gid, uname or gname.
+ * The conditions are set by following functions.
+ */
+__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_uname(struct archive *, const char *);
+__LA_DECL int archive_match_include_uname_w(struct archive *,
+ const wchar_t *);
+__LA_DECL int archive_match_include_gname(struct archive *, const char *);
+__LA_DECL int archive_match_include_gname_w(struct archive *,
+ const wchar_t *);
+
+/* Utility functions */
+/* Convenience function to sort a NULL terminated list of strings */
+__LA_DECL int archive_utility_string_sort(char **);
+
+#ifdef __cplusplus
+}
+#endif
+
+/* 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_acl.c b/Utilities/cmlibarchive/libarchive/archive_acl.c
new file mode 100644
index 0000000000..bf4b61040e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_acl.c
@@ -0,0 +1,1278 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+
+#include "archive_acl_private.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+
+#undef max
+#define max(a, b) ((a)>(b)?(a):(b))
+
+#ifndef HAVE_WMEMCMP
+/* Good enough for simple equality testing, but not for sorting. */
+#define wmemcmp(a,b,i) memcmp((a), (b), (i) * sizeof(wchar_t))
+#endif
+
+static int acl_special(struct archive_acl *acl,
+ int type, int permset, int tag);
+static struct archive_acl_entry *acl_new_entry(struct archive_acl *acl,
+ int type, int permset, int tag, int id);
+static int archive_acl_add_entry_len_l(struct archive_acl *acl,
+ int type, int permset, int tag, int id, const char *name,
+ size_t len, struct archive_string_conv *sc);
+static int isint_w(const wchar_t *start, const wchar_t *end, int *result);
+static int ismode_w(const wchar_t *start, const wchar_t *end, int *result);
+static void next_field_w(const wchar_t **wp, const wchar_t **start,
+ const wchar_t **end, wchar_t *sep);
+static int prefix_w(const wchar_t *start, const wchar_t *end,
+ const wchar_t *test);
+static void append_entry_w(wchar_t **wp, const wchar_t *prefix, int tag,
+ const wchar_t *wname, int perm, int id);
+static void append_id_w(wchar_t **wp, int id);
+static int isint(const char *start, const char *end, int *result);
+static int ismode(const char *start, const char *end, int *result);
+static void next_field(const char **p, const char **start,
+ const char **end, char *sep);
+static int prefix_c(const char *start, const char *end,
+ const char *test);
+static void append_entry(char **p, const char *prefix, int tag,
+ const char *name, int perm, int id);
+static void append_id(char **p, int id);
+
+void
+archive_acl_clear(struct archive_acl *acl)
+{
+ struct archive_acl_entry *ap;
+
+ while (acl->acl_head != NULL) {
+ ap = acl->acl_head->next;
+ archive_mstring_clean(&acl->acl_head->name);
+ free(acl->acl_head);
+ acl->acl_head = ap;
+ }
+ if (acl->acl_text_w != NULL) {
+ free(acl->acl_text_w);
+ acl->acl_text_w = NULL;
+ }
+ if (acl->acl_text != NULL) {
+ free(acl->acl_text);
+ acl->acl_text = NULL;
+ }
+ acl->acl_p = NULL;
+ acl->acl_state = 0; /* Not counting. */
+}
+
+void
+archive_acl_copy(struct archive_acl *dest, struct archive_acl *src)
+{
+ struct archive_acl_entry *ap, *ap2;
+
+ archive_acl_clear(dest);
+
+ dest->mode = src->mode;
+ ap = src->acl_head;
+ while (ap != NULL) {
+ ap2 = acl_new_entry(dest,
+ ap->type, ap->permset, ap->tag, ap->id);
+ if (ap2 != NULL)
+ archive_mstring_copy(&ap2->name, &ap->name);
+ ap = ap->next;
+ }
+}
+
+int
+archive_acl_add_entry(struct archive_acl *acl,
+ int type, int permset, int tag, int id, const char *name)
+{
+ struct archive_acl_entry *ap;
+
+ if (acl_special(acl, type, permset, tag) == 0)
+ return ARCHIVE_OK;
+ ap = acl_new_entry(acl, type, permset, tag, id);
+ if (ap == NULL) {
+ /* XXX Error XXX */
+ return ARCHIVE_FAILED;
+ }
+ if (name != NULL && *name != '\0')
+ archive_mstring_copy_mbs(&ap->name, name);
+ else
+ archive_mstring_clean(&ap->name);
+ return ARCHIVE_OK;
+}
+
+int
+archive_acl_add_entry_w_len(struct archive_acl *acl,
+ int type, int permset, int tag, int id, const wchar_t *name, size_t len)
+{
+ struct archive_acl_entry *ap;
+
+ if (acl_special(acl, type, permset, tag) == 0)
+ return ARCHIVE_OK;
+ ap = acl_new_entry(acl, type, permset, tag, id);
+ if (ap == NULL) {
+ /* XXX Error XXX */
+ return ARCHIVE_FAILED;
+ }
+ if (name != NULL && *name != L'\0' && len > 0)
+ archive_mstring_copy_wcs_len(&ap->name, name, len);
+ else
+ archive_mstring_clean(&ap->name);
+ return ARCHIVE_OK;
+}
+
+static int
+archive_acl_add_entry_len_l(struct archive_acl *acl,
+ int type, int permset, int tag, int id, const char *name, size_t len,
+ struct archive_string_conv *sc)
+{
+ struct archive_acl_entry *ap;
+ int r;
+
+ if (acl_special(acl, type, permset, tag) == 0)
+ return ARCHIVE_OK;
+ ap = acl_new_entry(acl, type, permset, tag, id);
+ if (ap == NULL) {
+ /* XXX Error XXX */
+ return ARCHIVE_FAILED;
+ }
+ if (name != NULL && *name != '\0' && len > 0) {
+ r = archive_mstring_copy_mbs_len_l(&ap->name, name, len, sc);
+ } else {
+ r = 0;
+ archive_mstring_clean(&ap->name);
+ }
+ if (r == 0)
+ return (ARCHIVE_OK);
+ else if (errno == ENOMEM)
+ return (ARCHIVE_FATAL);
+ else
+ return (ARCHIVE_WARN);
+}
+
+/*
+ * If this ACL entry is part of the standard POSIX permissions set,
+ * store the permissions in the stat structure and return zero.
+ */
+static int
+acl_special(struct archive_acl *acl, int type, int permset, int tag)
+{
+ if (type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS
+ && ((permset & ~007) == 0)) {
+ switch (tag) {
+ case ARCHIVE_ENTRY_ACL_USER_OBJ:
+ acl->mode &= ~0700;
+ acl->mode |= (permset & 7) << 6;
+ return (0);
+ case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
+ acl->mode &= ~0070;
+ acl->mode |= (permset & 7) << 3;
+ return (0);
+ case ARCHIVE_ENTRY_ACL_OTHER:
+ acl->mode &= ~0007;
+ acl->mode |= permset & 7;
+ return (0);
+ }
+ }
+ return (1);
+}
+
+/*
+ * Allocate and populate a new ACL entry with everything but the
+ * name.
+ */
+static struct archive_acl_entry *
+acl_new_entry(struct archive_acl *acl,
+ int type, int permset, int tag, int id)
+{
+ struct archive_acl_entry *ap, *aq;
+
+ /* Type argument must be a valid NFS4 or POSIX.1e type.
+ * The type must agree with anything already set and
+ * the permset must be compatible. */
+ if (type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
+ if (acl->acl_types & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
+ return (NULL);
+ }
+ if (permset &
+ ~(ARCHIVE_ENTRY_ACL_PERMS_NFS4
+ | ARCHIVE_ENTRY_ACL_INHERITANCE_NFS4)) {
+ return (NULL);
+ }
+ } else if (type & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) {
+ if (acl->acl_types & ~ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) {
+ return (NULL);
+ }
+ if (permset & ~ARCHIVE_ENTRY_ACL_PERMS_POSIX1E) {
+ return (NULL);
+ }
+ } else {
+ return (NULL);
+ }
+
+ /* Verify the tag is valid and compatible with NFS4 or POSIX.1e. */
+ switch (tag) {
+ case ARCHIVE_ENTRY_ACL_USER:
+ case ARCHIVE_ENTRY_ACL_USER_OBJ:
+ case ARCHIVE_ENTRY_ACL_GROUP:
+ case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
+ /* Tags valid in both NFS4 and POSIX.1e */
+ break;
+ case ARCHIVE_ENTRY_ACL_MASK:
+ case ARCHIVE_ENTRY_ACL_OTHER:
+ /* Tags valid only in POSIX.1e. */
+ if (type & ~ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) {
+ return (NULL);
+ }
+ break;
+ case ARCHIVE_ENTRY_ACL_EVERYONE:
+ /* Tags valid only in NFS4. */
+ if (type & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
+ return (NULL);
+ }
+ break;
+ default:
+ /* No other values are valid. */
+ return (NULL);
+ }
+
+ if (acl->acl_text_w != NULL) {
+ free(acl->acl_text_w);
+ acl->acl_text_w = NULL;
+ }
+ if (acl->acl_text != NULL) {
+ free(acl->acl_text);
+ acl->acl_text = NULL;
+ }
+
+ /* If there's a matching entry already in the list, overwrite it. */
+ ap = acl->acl_head;
+ aq = NULL;
+ while (ap != NULL) {
+ if (ap->type == type && ap->tag == tag && ap->id == id) {
+ ap->permset = permset;
+ return (ap);
+ }
+ aq = ap;
+ ap = ap->next;
+ }
+
+ /* Add a new entry to the end of the list. */
+ ap = (struct archive_acl_entry *)malloc(sizeof(*ap));
+ if (ap == NULL)
+ return (NULL);
+ memset(ap, 0, sizeof(*ap));
+ if (aq == NULL)
+ acl->acl_head = ap;
+ else
+ aq->next = ap;
+ ap->type = type;
+ ap->tag = tag;
+ ap->id = id;
+ ap->permset = permset;
+ acl->acl_types |= type;
+ return (ap);
+}
+
+/*
+ * Return a count of entries matching "want_type".
+ */
+int
+archive_acl_count(struct archive_acl *acl, int want_type)
+{
+ int count;
+ struct archive_acl_entry *ap;
+
+ count = 0;
+ ap = acl->acl_head;
+ while (ap != NULL) {
+ if ((ap->type & want_type) != 0)
+ count++;
+ ap = ap->next;
+ }
+
+ if (count > 0 && ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0))
+ count += 3;
+ return (count);
+}
+
+/*
+ * Prepare for reading entries from the ACL data. Returns a count
+ * of entries matching "want_type", or zero if there are no
+ * non-extended ACL entries of that type.
+ */
+int
+archive_acl_reset(struct archive_acl *acl, int want_type)
+{
+ int count, cutoff;
+
+ count = archive_acl_count(acl, want_type);
+
+ /*
+ * If the only entries are the three standard ones,
+ * then don't return any ACL data. (In this case,
+ * client can just use chmod(2) to set permissions.)
+ */
+ if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)
+ cutoff = 3;
+ else
+ cutoff = 0;
+
+ if (count > cutoff)
+ acl->acl_state = ARCHIVE_ENTRY_ACL_USER_OBJ;
+ else
+ acl->acl_state = 0;
+ acl->acl_p = acl->acl_head;
+ return (count);
+}
+
+
+/*
+ * Return the next ACL entry in the list. Fake entries for the
+ * standard permissions and include them in the returned list.
+ */
+int
+archive_acl_next(struct archive *a, struct archive_acl *acl, int want_type, int *type,
+ int *permset, int *tag, int *id, const char **name)
+{
+ *name = NULL;
+ *id = -1;
+
+ /*
+ * The acl_state is either zero (no entries available), -1
+ * (reading from list), or an entry type (retrieve that type
+ * from ae_stat.aest_mode).
+ */
+ if (acl->acl_state == 0)
+ return (ARCHIVE_WARN);
+
+ /* The first three access entries are special. */
+ if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) {
+ switch (acl->acl_state) {
+ case ARCHIVE_ENTRY_ACL_USER_OBJ:
+ *permset = (acl->mode >> 6) & 7;
+ *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
+ *tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
+ acl->acl_state = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
+ return (ARCHIVE_OK);
+ case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
+ *permset = (acl->mode >> 3) & 7;
+ *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
+ *tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
+ acl->acl_state = ARCHIVE_ENTRY_ACL_OTHER;
+ return (ARCHIVE_OK);
+ case ARCHIVE_ENTRY_ACL_OTHER:
+ *permset = acl->mode & 7;
+ *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
+ *tag = ARCHIVE_ENTRY_ACL_OTHER;
+ acl->acl_state = -1;
+ acl->acl_p = acl->acl_head;
+ return (ARCHIVE_OK);
+ default:
+ break;
+ }
+ }
+
+ while (acl->acl_p != NULL && (acl->acl_p->type & want_type) == 0)
+ acl->acl_p = acl->acl_p->next;
+ if (acl->acl_p == NULL) {
+ acl->acl_state = 0;
+ *type = 0;
+ *permset = 0;
+ *tag = 0;
+ *id = -1;
+ *name = NULL;
+ return (ARCHIVE_EOF); /* End of ACL entries. */
+ }
+ *type = acl->acl_p->type;
+ *permset = acl->acl_p->permset;
+ *tag = acl->acl_p->tag;
+ *id = acl->acl_p->id;
+ if (archive_mstring_get_mbs(a, &acl->acl_p->name, name) != 0) {
+ if (errno == ENOMEM)
+ return (ARCHIVE_FATAL);
+ *name = NULL;
+ }
+ acl->acl_p = acl->acl_p->next;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Generate a text version of the ACL. The flags parameter controls
+ * the style of the generated ACL.
+ */
+const wchar_t *
+archive_acl_text_w(struct archive *a, struct archive_acl *acl, int flags)
+{
+ int count;
+ size_t length;
+ const wchar_t *wname;
+ const wchar_t *prefix;
+ wchar_t separator;
+ struct archive_acl_entry *ap;
+ int id, r;
+ wchar_t *wp;
+
+ if (acl->acl_text_w != NULL) {
+ free (acl->acl_text_w);
+ acl->acl_text_w = NULL;
+ }
+
+ separator = L',';
+ count = 0;
+ length = 0;
+ ap = acl->acl_head;
+ while (ap != NULL) {
+ if ((ap->type & flags) != 0) {
+ count++;
+ if ((flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) &&
+ (ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT))
+ length += 8; /* "default:" */
+ length += 5; /* tag name */
+ length += 1; /* colon */
+ r = archive_mstring_get_wcs(a, &ap->name, &wname);
+ if (r == 0 && wname != NULL)
+ length += wcslen(wname);
+ else if (r < 0 && errno == ENOMEM)
+ return (NULL);
+ else
+ length += sizeof(uid_t) * 3 + 1;
+ length ++; /* colon */
+ length += 3; /* rwx */
+ length += 1; /* colon */
+ length += max(sizeof(uid_t), sizeof(gid_t)) * 3 + 1;
+ length ++; /* newline */
+ }
+ ap = ap->next;
+ }
+
+ if (count > 0 && ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)) {
+ length += 10; /* "user::rwx\n" */
+ length += 11; /* "group::rwx\n" */
+ length += 11; /* "other::rwx\n" */
+ }
+
+ if (count == 0)
+ return (NULL);
+
+ /* Now, allocate the string and actually populate it. */
+ wp = acl->acl_text_w = (wchar_t *)malloc(length * sizeof(wchar_t));
+ if (wp == NULL)
+ return (NULL);
+ count = 0;
+ if ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) {
+ append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_USER_OBJ, NULL,
+ acl->mode & 0700, -1);
+ *wp++ = ',';
+ append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_GROUP_OBJ, NULL,
+ acl->mode & 0070, -1);
+ *wp++ = ',';
+ append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_OTHER, NULL,
+ acl->mode & 0007, -1);
+ count += 3;
+
+ ap = acl->acl_head;
+ while (ap != NULL) {
+ if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) {
+ r = archive_mstring_get_wcs(a, &ap->name, &wname);
+ if (r == 0) {
+ *wp++ = separator;
+ if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID)
+ id = ap->id;
+ else
+ id = -1;
+ append_entry_w(&wp, NULL, ap->tag, wname,
+ ap->permset, id);
+ count++;
+ } else if (r < 0 && errno == ENOMEM)
+ return (NULL);
+ }
+ ap = ap->next;
+ }
+ }
+
+
+ if ((flags & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) {
+ if (flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT)
+ prefix = L"default:";
+ else
+ prefix = NULL;
+ ap = acl->acl_head;
+ count = 0;
+ while (ap != NULL) {
+ if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) {
+ r = archive_mstring_get_wcs(a, &ap->name, &wname);
+ if (r == 0) {
+ if (count > 0)
+ *wp++ = separator;
+ if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID)
+ id = ap->id;
+ else
+ id = -1;
+ append_entry_w(&wp, prefix, ap->tag,
+ wname, ap->permset, id);
+ count ++;
+ } else if (r < 0 && errno == ENOMEM)
+ return (NULL);
+ }
+ ap = ap->next;
+ }
+ }
+
+ return (acl->acl_text_w);
+}
+
+
+static void
+append_id_w(wchar_t **wp, int id)
+{
+ if (id < 0)
+ id = 0;
+ if (id > 9)
+ append_id_w(wp, id / 10);
+ *(*wp)++ = L"0123456789"[id % 10];
+}
+
+static void
+append_entry_w(wchar_t **wp, const wchar_t *prefix, int tag,
+ const wchar_t *wname, int perm, int id)
+{
+ if (prefix != NULL) {
+ wcscpy(*wp, prefix);
+ *wp += wcslen(*wp);
+ }
+ switch (tag) {
+ case ARCHIVE_ENTRY_ACL_USER_OBJ:
+ wname = NULL;
+ id = -1;
+ /* FALLTHROUGH */
+ case ARCHIVE_ENTRY_ACL_USER:
+ wcscpy(*wp, L"user");
+ break;
+ case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
+ wname = NULL;
+ id = -1;
+ /* FALLTHROUGH */
+ case ARCHIVE_ENTRY_ACL_GROUP:
+ wcscpy(*wp, L"group");
+ break;
+ case ARCHIVE_ENTRY_ACL_MASK:
+ wcscpy(*wp, L"mask");
+ wname = NULL;
+ id = -1;
+ break;
+ case ARCHIVE_ENTRY_ACL_OTHER:
+ wcscpy(*wp, L"other");
+ wname = NULL;
+ id = -1;
+ break;
+ }
+ *wp += wcslen(*wp);
+ *(*wp)++ = L':';
+ if (wname != NULL) {
+ wcscpy(*wp, wname);
+ *wp += wcslen(*wp);
+ } else if (tag == ARCHIVE_ENTRY_ACL_USER
+ || tag == ARCHIVE_ENTRY_ACL_GROUP) {
+ append_id_w(wp, id);
+ id = -1;
+ }
+ *(*wp)++ = L':';
+ *(*wp)++ = (perm & 0444) ? L'r' : L'-';
+ *(*wp)++ = (perm & 0222) ? L'w' : L'-';
+ *(*wp)++ = (perm & 0111) ? L'x' : L'-';
+ if (id != -1) {
+ *(*wp)++ = L':';
+ append_id_w(wp, id);
+ }
+ **wp = L'\0';
+}
+
+int
+archive_acl_text_l(struct archive_acl *acl, int flags,
+ const char **acl_text, size_t *acl_text_len,
+ struct archive_string_conv *sc)
+{
+ int count;
+ size_t length;
+ const char *name;
+ const char *prefix;
+ char separator;
+ struct archive_acl_entry *ap;
+ size_t len;
+ int id, r;
+ char *p;
+
+ if (acl->acl_text != NULL) {
+ free (acl->acl_text);
+ acl->acl_text = NULL;
+ }
+
+ *acl_text = NULL;
+ if (acl_text_len != NULL)
+ *acl_text_len = 0;
+ separator = ',';
+ count = 0;
+ length = 0;
+ ap = acl->acl_head;
+ while (ap != NULL) {
+ if ((ap->type & flags) != 0) {
+ count++;
+ if ((flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) &&
+ (ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT))
+ length += 8; /* "default:" */
+ length += 5; /* tag name */
+ length += 1; /* colon */
+ r = archive_mstring_get_mbs_l(
+ &ap->name, &name, &len, sc);
+ if (r != 0)
+ return (-1);
+ if (len > 0 && name != NULL)
+ length += len;
+ else
+ length += sizeof(uid_t) * 3 + 1;
+ length ++; /* colon */
+ length += 3; /* rwx */
+ length += 1; /* colon */
+ length += max(sizeof(uid_t), sizeof(gid_t)) * 3 + 1;
+ length ++; /* newline */
+ }
+ ap = ap->next;
+ }
+
+ if (count > 0 && ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)) {
+ length += 10; /* "user::rwx\n" */
+ length += 11; /* "group::rwx\n" */
+ length += 11; /* "other::rwx\n" */
+ }
+
+ if (count == 0)
+ return (0);
+
+ /* Now, allocate the string and actually populate it. */
+ p = acl->acl_text = (char *)malloc(length);
+ if (p == NULL)
+ return (-1);
+ count = 0;
+ if ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) {
+ append_entry(&p, NULL, ARCHIVE_ENTRY_ACL_USER_OBJ, NULL,
+ acl->mode & 0700, -1);
+ *p++ = ',';
+ append_entry(&p, NULL, ARCHIVE_ENTRY_ACL_GROUP_OBJ, NULL,
+ acl->mode & 0070, -1);
+ *p++ = ',';
+ append_entry(&p, NULL, ARCHIVE_ENTRY_ACL_OTHER, NULL,
+ acl->mode & 0007, -1);
+ count += 3;
+
+ for (ap = acl->acl_head; ap != NULL; ap = ap->next) {
+ if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) == 0)
+ continue;
+ r = archive_mstring_get_mbs_l(
+ &ap->name, &name, &len, sc);
+ if (r != 0)
+ return (-1);
+ *p++ = separator;
+ if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID)
+ id = ap->id;
+ else
+ id = -1;
+ append_entry(&p, NULL, ap->tag, name,
+ ap->permset, id);
+ count++;
+ }
+ }
+
+
+ if ((flags & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) {
+ if (flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT)
+ prefix = "default:";
+ else
+ prefix = NULL;
+ count = 0;
+ for (ap = acl->acl_head; ap != NULL; ap = ap->next) {
+ if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) == 0)
+ continue;
+ r = archive_mstring_get_mbs_l(
+ &ap->name, &name, &len, sc);
+ if (r != 0)
+ return (-1);
+ if (count > 0)
+ *p++ = separator;
+ if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID)
+ id = ap->id;
+ else
+ id = -1;
+ append_entry(&p, prefix, ap->tag,
+ name, ap->permset, id);
+ count ++;
+ }
+ }
+
+ *acl_text = acl->acl_text;
+ if (acl_text_len != NULL)
+ *acl_text_len = strlen(acl->acl_text);
+ return (0);
+}
+
+static void
+append_id(char **p, int id)
+{
+ if (id < 0)
+ id = 0;
+ if (id > 9)
+ append_id(p, id / 10);
+ *(*p)++ = "0123456789"[id % 10];
+}
+
+static void
+append_entry(char **p, const char *prefix, int tag,
+ const char *name, int perm, int id)
+{
+ if (prefix != NULL) {
+ strcpy(*p, prefix);
+ *p += strlen(*p);
+ }
+ switch (tag) {
+ case ARCHIVE_ENTRY_ACL_USER_OBJ:
+ name = NULL;
+ id = -1;
+ /* FALLTHROUGH */
+ case ARCHIVE_ENTRY_ACL_USER:
+ strcpy(*p, "user");
+ break;
+ case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
+ name = NULL;
+ id = -1;
+ /* FALLTHROUGH */
+ case ARCHIVE_ENTRY_ACL_GROUP:
+ strcpy(*p, "group");
+ break;
+ case ARCHIVE_ENTRY_ACL_MASK:
+ strcpy(*p, "mask");
+ name = NULL;
+ id = -1;
+ break;
+ case ARCHIVE_ENTRY_ACL_OTHER:
+ strcpy(*p, "other");
+ name = NULL;
+ id = -1;
+ break;
+ }
+ *p += strlen(*p);
+ *(*p)++ = ':';
+ if (name != NULL) {
+ strcpy(*p, name);
+ *p += strlen(*p);
+ } else if (tag == ARCHIVE_ENTRY_ACL_USER
+ || tag == ARCHIVE_ENTRY_ACL_GROUP) {
+ append_id(p, id);
+ id = -1;
+ }
+ *(*p)++ = ':';
+ *(*p)++ = (perm & 0444) ? 'r' : '-';
+ *(*p)++ = (perm & 0222) ? 'w' : '-';
+ *(*p)++ = (perm & 0111) ? 'x' : '-';
+ if (id != -1) {
+ *(*p)++ = ':';
+ append_id(p, id);
+ }
+ **p = '\0';
+}
+
+/*
+ * Parse a textual ACL. This automatically recognizes and supports
+ * extensions described above. The 'type' argument is used to
+ * indicate the type that should be used for any entries not
+ * explicitly marked as "default:".
+ */
+int
+archive_acl_parse_w(struct archive_acl *acl,
+ const wchar_t *text, int default_type)
+{
+ struct {
+ const wchar_t *start;
+ const wchar_t *end;
+ } field[4], name;
+
+ int fields, n;
+ int type, tag, permset, id;
+ wchar_t sep;
+
+ while (text != NULL && *text != L'\0') {
+ /*
+ * Parse the fields out of the next entry,
+ * advance 'text' to start of next entry.
+ */
+ fields = 0;
+ do {
+ const wchar_t *start, *end;
+ next_field_w(&text, &start, &end, &sep);
+ if (fields < 4) {
+ field[fields].start = start;
+ field[fields].end = end;
+ }
+ ++fields;
+ } while (sep == L':');
+
+ /* Set remaining fields to blank. */
+ for (n = fields; n < 4; ++n)
+ field[n].start = field[n].end = NULL;
+
+ /* Check for a numeric ID in field 1 or 3. */
+ id = -1;
+ isint_w(field[1].start, field[1].end, &id);
+ /* Field 3 is optional. */
+ if (id == -1 && fields > 3)
+ isint_w(field[3].start, field[3].end, &id);
+
+ /*
+ * Solaris extension: "defaultuser::rwx" is the
+ * default ACL corresponding to "user::rwx", etc.
+ */
+ if (field[0].end - field[0].start > 7
+ && wmemcmp(field[0].start, L"default", 7) == 0) {
+ type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT;
+ field[0].start += 7;
+ } else
+ type = default_type;
+
+ name.start = name.end = NULL;
+ if (prefix_w(field[0].start, field[0].end, L"user")) {
+ if (!ismode_w(field[2].start, field[2].end, &permset))
+ return (ARCHIVE_WARN);
+ if (id != -1 || field[1].start < field[1].end) {
+ tag = ARCHIVE_ENTRY_ACL_USER;
+ name = field[1];
+ } else
+ tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
+ } else if (prefix_w(field[0].start, field[0].end, L"group")) {
+ if (!ismode_w(field[2].start, field[2].end, &permset))
+ return (ARCHIVE_WARN);
+ if (id != -1 || field[1].start < field[1].end) {
+ tag = ARCHIVE_ENTRY_ACL_GROUP;
+ name = field[1];
+ } else
+ tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
+ } else if (prefix_w(field[0].start, field[0].end, L"other")) {
+ if (fields == 2
+ && field[1].start < field[1].end
+ && ismode_w(field[1].start, field[1].end, &permset)) {
+ /* This is Solaris-style "other:rwx" */
+ } else if (fields == 3
+ && field[1].start == field[1].end
+ && field[2].start < field[2].end
+ && ismode_w(field[2].start, field[2].end, &permset)) {
+ /* This is FreeBSD-style "other::rwx" */
+ } else
+ return (ARCHIVE_WARN);
+ tag = ARCHIVE_ENTRY_ACL_OTHER;
+ } else if (prefix_w(field[0].start, field[0].end, L"mask")) {
+ if (fields == 2
+ && field[1].start < field[1].end
+ && ismode_w(field[1].start, field[1].end, &permset)) {
+ /* This is Solaris-style "mask:rwx" */
+ } else if (fields == 3
+ && field[1].start == field[1].end
+ && field[2].start < field[2].end
+ && ismode_w(field[2].start, field[2].end, &permset)) {
+ /* This is FreeBSD-style "mask::rwx" */
+ } else
+ return (ARCHIVE_WARN);
+ tag = ARCHIVE_ENTRY_ACL_MASK;
+ } else
+ return (ARCHIVE_WARN);
+
+ /* Add entry to the internal list. */
+ archive_acl_add_entry_w_len(acl, type, permset,
+ tag, id, name.start, name.end - name.start);
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Parse a string to a positive decimal integer. Returns true if
+ * the string is non-empty and consists only of decimal digits,
+ * false otherwise.
+ */
+static int
+isint_w(const wchar_t *start, const wchar_t *end, int *result)
+{
+ int n = 0;
+ if (start >= end)
+ return (0);
+ while (start < end) {
+ if (*start < '0' || *start > '9')
+ return (0);
+ if (n > (INT_MAX / 10) ||
+ (n == INT_MAX / 10 && (*start - '0') > INT_MAX % 10)) {
+ n = INT_MAX;
+ } else {
+ n *= 10;
+ n += *start - '0';
+ }
+ start++;
+ }
+ *result = n;
+ return (1);
+}
+
+/*
+ * Parse a string as a mode field. Returns true if
+ * the string is non-empty and consists only of mode characters,
+ * false otherwise.
+ */
+static int
+ismode_w(const wchar_t *start, const wchar_t *end, int *permset)
+{
+ const wchar_t *p;
+
+ if (start >= end)
+ return (0);
+ p = start;
+ *permset = 0;
+ while (p < end) {
+ switch (*p++) {
+ case 'r': case 'R':
+ *permset |= ARCHIVE_ENTRY_ACL_READ;
+ break;
+ case 'w': case 'W':
+ *permset |= ARCHIVE_ENTRY_ACL_WRITE;
+ break;
+ case 'x': case 'X':
+ *permset |= ARCHIVE_ENTRY_ACL_EXECUTE;
+ break;
+ case '-':
+ break;
+ default:
+ return (0);
+ }
+ }
+ return (1);
+}
+
+/*
+ * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *wp is updated
+ * to point to just after the separator. *start points to the first
+ * character of the matched text and *end just after the last
+ * character of the matched identifier. In particular *end - *start
+ * is the length of the field body, not including leading or trailing
+ * whitespace.
+ */
+static void
+next_field_w(const wchar_t **wp, const wchar_t **start,
+ const wchar_t **end, wchar_t *sep)
+{
+ /* Skip leading whitespace to find start of field. */
+ while (**wp == L' ' || **wp == L'\t' || **wp == L'\n') {
+ (*wp)++;
+ }
+ *start = *wp;
+
+ /* Scan for the separator. */
+ while (**wp != L'\0' && **wp != L',' && **wp != L':' &&
+ **wp != L'\n') {
+ (*wp)++;
+ }
+ *sep = **wp;
+
+ /* Trim trailing whitespace to locate end of field. */
+ *end = *wp - 1;
+ while (**end == L' ' || **end == L'\t' || **end == L'\n') {
+ (*end)--;
+ }
+ (*end)++;
+
+ /* Adjust scanner location. */
+ if (**wp != L'\0')
+ (*wp)++;
+}
+
+/*
+ * Return true if the characters [start...end) are a prefix of 'test'.
+ * This makes it easy to handle the obvious abbreviations: 'u' for 'user', etc.
+ */
+static int
+prefix_w(const wchar_t *start, const wchar_t *end, const wchar_t *test)
+{
+ if (start == end)
+ return (0);
+
+ if (*start++ != *test++)
+ return (0);
+
+ while (start < end && *start++ == *test++)
+ ;
+
+ if (start < end)
+ return (0);
+
+ return (1);
+}
+
+/*
+ * Parse a textual ACL. This automatically recognizes and supports
+ * extensions described above. The 'type' argument is used to
+ * indicate the type that should be used for any entries not
+ * explicitly marked as "default:".
+ */
+int
+archive_acl_parse_l(struct archive_acl *acl,
+ const char *text, int default_type, struct archive_string_conv *sc)
+{
+ struct {
+ const char *start;
+ const char *end;
+ } field[4], name;
+
+ int fields, n, r, ret = ARCHIVE_OK;
+ int type, tag, permset, id;
+ char sep;
+
+ while (text != NULL && *text != '\0') {
+ /*
+ * Parse the fields out of the next entry,
+ * advance 'text' to start of next entry.
+ */
+ fields = 0;
+ do {
+ const char *start, *end;
+ next_field(&text, &start, &end, &sep);
+ if (fields < 4) {
+ field[fields].start = start;
+ field[fields].end = end;
+ }
+ ++fields;
+ } while (sep == ':');
+
+ /* Set remaining fields to blank. */
+ for (n = fields; n < 4; ++n)
+ field[n].start = field[n].end = NULL;
+
+ /* Check for a numeric ID in field 1 or 3. */
+ id = -1;
+ isint(field[1].start, field[1].end, &id);
+ /* Field 3 is optional. */
+ if (id == -1 && fields > 3)
+ isint(field[3].start, field[3].end, &id);
+
+ /*
+ * Solaris extension: "defaultuser::rwx" is the
+ * default ACL corresponding to "user::rwx", etc.
+ */
+ if (field[0].end - field[0].start > 7
+ && memcmp(field[0].start, "default", 7) == 0) {
+ type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT;
+ field[0].start += 7;
+ } else
+ type = default_type;
+
+ name.start = name.end = NULL;
+ if (prefix_c(field[0].start, field[0].end, "user")) {
+ if (!ismode(field[2].start, field[2].end, &permset))
+ return (ARCHIVE_WARN);
+ if (id != -1 || field[1].start < field[1].end) {
+ tag = ARCHIVE_ENTRY_ACL_USER;
+ name = field[1];
+ } else
+ tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
+ } else if (prefix_c(field[0].start, field[0].end, "group")) {
+ if (!ismode(field[2].start, field[2].end, &permset))
+ return (ARCHIVE_WARN);
+ if (id != -1 || field[1].start < field[1].end) {
+ tag = ARCHIVE_ENTRY_ACL_GROUP;
+ name = field[1];
+ } else
+ tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
+ } else if (prefix_c(field[0].start, field[0].end, "other")) {
+ if (fields == 2
+ && field[1].start < field[1].end
+ && ismode(field[1].start, field[1].end, &permset)) {
+ /* This is Solaris-style "other:rwx" */
+ } else if (fields == 3
+ && field[1].start == field[1].end
+ && field[2].start < field[2].end
+ && ismode(field[2].start, field[2].end, &permset)) {
+ /* This is FreeBSD-style "other::rwx" */
+ } else
+ return (ARCHIVE_WARN);
+ tag = ARCHIVE_ENTRY_ACL_OTHER;
+ } else if (prefix_c(field[0].start, field[0].end, "mask")) {
+ if (fields == 2
+ && field[1].start < field[1].end
+ && ismode(field[1].start, field[1].end, &permset)) {
+ /* This is Solaris-style "mask:rwx" */
+ } else if (fields == 3
+ && field[1].start == field[1].end
+ && field[2].start < field[2].end
+ && ismode(field[2].start, field[2].end, &permset)) {
+ /* This is FreeBSD-style "mask::rwx" */
+ } else
+ return (ARCHIVE_WARN);
+ tag = ARCHIVE_ENTRY_ACL_MASK;
+ } else
+ return (ARCHIVE_WARN);
+
+ /* Add entry to the internal list. */
+ r = archive_acl_add_entry_len_l(acl, type, permset,
+ tag, id, name.start, name.end - name.start, sc);
+ if (r < ARCHIVE_WARN)
+ return (r);
+ if (r != ARCHIVE_OK)
+ ret = ARCHIVE_WARN;
+ }
+ return (ret);
+}
+
+/*
+ * Parse a string to a positive decimal integer. Returns true if
+ * the string is non-empty and consists only of decimal digits,
+ * false otherwise.
+ */
+static int
+isint(const char *start, const char *end, int *result)
+{
+ int n = 0;
+ if (start >= end)
+ return (0);
+ while (start < end) {
+ if (*start < '0' || *start > '9')
+ return (0);
+ if (n > (INT_MAX / 10) ||
+ (n == INT_MAX / 10 && (*start - '0') > INT_MAX % 10)) {
+ n = INT_MAX;
+ } else {
+ n *= 10;
+ n += *start - '0';
+ }
+ start++;
+ }
+ *result = n;
+ return (1);
+}
+
+/*
+ * Parse a string as a mode field. Returns true if
+ * the string is non-empty and consists only of mode characters,
+ * false otherwise.
+ */
+static int
+ismode(const char *start, const char *end, int *permset)
+{
+ const char *p;
+
+ if (start >= end)
+ return (0);
+ p = start;
+ *permset = 0;
+ while (p < end) {
+ switch (*p++) {
+ case 'r': case 'R':
+ *permset |= ARCHIVE_ENTRY_ACL_READ;
+ break;
+ case 'w': case 'W':
+ *permset |= ARCHIVE_ENTRY_ACL_WRITE;
+ break;
+ case 'x': case 'X':
+ *permset |= ARCHIVE_ENTRY_ACL_EXECUTE;
+ break;
+ case '-':
+ break;
+ default:
+ return (0);
+ }
+ }
+ return (1);
+}
+
+/*
+ * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *wp is updated
+ * to point to just after the separator. *start points to the first
+ * character of the matched text and *end just after the last
+ * character of the matched identifier. In particular *end - *start
+ * is the length of the field body, not including leading or trailing
+ * whitespace.
+ */
+static void
+next_field(const char **p, const char **start,
+ const char **end, char *sep)
+{
+ /* Skip leading whitespace to find start of field. */
+ while (**p == ' ' || **p == '\t' || **p == '\n') {
+ (*p)++;
+ }
+ *start = *p;
+
+ /* Scan for the separator. */
+ while (**p != '\0' && **p != ',' && **p != ':' && **p != '\n') {
+ (*p)++;
+ }
+ *sep = **p;
+
+ /* Trim trailing whitespace to locate end of field. */
+ *end = *p - 1;
+ while (**end == ' ' || **end == '\t' || **end == '\n') {
+ (*end)--;
+ }
+ (*end)++;
+
+ /* Adjust scanner location. */
+ if (**p != '\0')
+ (*p)++;
+}
+
+/*
+ * Return true if the characters [start...end) are a prefix of 'test'.
+ * This makes it easy to handle the obvious abbreviations: 'u' for 'user', etc.
+ */
+static int
+prefix_c(const char *start, const char *end, const char *test)
+{
+ if (start == end)
+ return (0);
+
+ if (*start++ != *test++)
+ return (0);
+
+ while (start < end && *start++ == *test++)
+ ;
+
+ if (start < end)
+ return (0);
+
+ return (1);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_acl_private.h b/Utilities/cmlibarchive/libarchive/archive_acl_private.h
new file mode 100644
index 0000000000..1421adbf8a
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_acl_private.h
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_ACL_PRIVATE_H_INCLUDED
+#define ARCHIVE_ACL_PRIVATE_H_INCLUDED
+
+#include "archive_string.h"
+
+struct archive_acl_entry {
+ struct archive_acl_entry *next;
+ int type; /* E.g., access or default */
+ int tag; /* E.g., user/group/other/mask */
+ int permset; /* r/w/x bits */
+ int id; /* uid/gid for user/group */
+ struct archive_mstring name; /* uname/gname */
+};
+
+struct archive_acl {
+ mode_t mode;
+ struct archive_acl_entry *acl_head;
+ struct archive_acl_entry *acl_p;
+ int acl_state; /* See acl_next for details. */
+ wchar_t *acl_text_w;
+ char *acl_text;
+ int acl_types;
+};
+
+void archive_acl_clear(struct archive_acl *);
+void archive_acl_copy(struct archive_acl *, struct archive_acl *);
+int archive_acl_count(struct archive_acl *, int);
+int archive_acl_reset(struct archive_acl *, int);
+int archive_acl_next(struct archive *, struct archive_acl *, int,
+ int *, int *, int *, int *, const char **);
+
+int archive_acl_add_entry(struct archive_acl *, int, int, int, int, const char *);
+int archive_acl_add_entry_w_len(struct archive_acl *,
+ int, int, int, int, const wchar_t *, size_t);
+int archive_acl_add_entry_len(struct archive_acl *,
+ int, int, int, int, const char *, size_t);
+
+const wchar_t *archive_acl_text_w(struct archive *, struct archive_acl *, int);
+int archive_acl_text_l(struct archive_acl *, int, const char **, size_t *,
+ struct archive_string_conv *);
+
+/*
+ * Private ACL parser. This is private because it handles some
+ * very weird formats that clients should not be messing with.
+ * Clients should only deal with their platform-native formats.
+ * Because of the need to support many formats cleanly, new arguments
+ * are likely to get added on a regular basis. Clients who try to use
+ * this interface are likely to be surprised when it changes.
+ */
+int archive_acl_parse_w(struct archive_acl *,
+ const wchar_t *, int /* type */);
+int archive_acl_parse_l(struct archive_acl *,
+ const char *, int /* type */,
+ struct archive_string_conv *);
+
+#endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_check_magic.c b/Utilities/cmlibarchive/libarchive/archive_check_magic.c
new file mode 100644
index 0000000000..c695e582a2
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_check_magic.c
@@ -0,0 +1,175 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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_check_magic.c 201089 2009-12-28 02:20:23Z kientzle $");
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.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
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <windows.h>
+#include <winbase.h>
+#endif
+
+#include "archive_private.h"
+
+static void
+errmsg(const char *m)
+{
+ size_t s = strlen(m);
+ ssize_t written;
+
+ while (s > 0) {
+ written = write(2, m, strlen(m));
+ if (written <= 0)
+ return;
+ m += written;
+ s -= written;
+ }
+}
+
+static void
+diediedie(void)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG)
+ /* Cause a breakpoint exception */
+ DebugBreak();
+#endif
+ abort(); /* Terminate the program abnormally. */
+}
+
+static const char *
+state_name(unsigned s)
+{
+ switch (s) {
+ case ARCHIVE_STATE_NEW: return ("new");
+ case ARCHIVE_STATE_HEADER: return ("header");
+ case ARCHIVE_STATE_DATA: return ("data");
+ case ARCHIVE_STATE_EOF: return ("eof");
+ case ARCHIVE_STATE_CLOSED: return ("closed");
+ case ARCHIVE_STATE_FATAL: return ("fatal");
+ default: return ("??");
+ }
+}
+
+static const char *
+archive_handle_type_name(unsigned m)
+{
+ switch (m) {
+ case ARCHIVE_WRITE_MAGIC: return ("archive_write");
+ case ARCHIVE_READ_MAGIC: return ("archive_read");
+ case ARCHIVE_WRITE_DISK_MAGIC: return ("archive_write_disk");
+ case ARCHIVE_READ_DISK_MAGIC: return ("archive_read_disk");
+ case ARCHIVE_MATCH_MAGIC: return ("archive_match");
+ default: return NULL;
+ }
+}
+
+
+static char *
+write_all_states(char *buff, unsigned int states)
+{
+ unsigned int lowbit;
+
+ buff[0] = '\0';
+
+ /* A trick for computing the lowest set bit. */
+ while ((lowbit = states & (1 + ~states)) != 0) {
+ states &= ~lowbit; /* Clear the low bit. */
+ strcat(buff, state_name(lowbit));
+ if (states != 0)
+ strcat(buff, "/");
+ }
+ return buff;
+}
+
+/*
+ * Check magic value and current state.
+ * Magic value mismatches are fatal and result in calls to abort().
+ * State mismatches return ARCHIVE_FATAL.
+ * Otherwise, returns ARCHIVE_OK.
+ *
+ * This is designed to catch serious programming errors that violate
+ * the libarchive API.
+ */
+int
+__archive_check_magic(struct archive *a, unsigned int magic,
+ unsigned int state, const char *function)
+{
+ char states1[64];
+ char states2[64];
+ const char *handle_type;
+
+ /*
+ * If this isn't some form of archive handle,
+ * then the library user has screwed up so bad that
+ * we don't even have a reliable way to report an error.
+ */
+ handle_type = archive_handle_type_name(a->magic);
+
+ if (!handle_type) {
+ errmsg("PROGRAMMER ERROR: Function ");
+ errmsg(function);
+ errmsg(" invoked with invalid archive handle.\n");
+ diediedie();
+ }
+
+ if (a->magic != magic) {
+ archive_set_error(a, -1,
+ "PROGRAMMER ERROR: Function '%s' invoked"
+ " on '%s' archive object, which is not supported.",
+ function,
+ handle_type);
+ a->state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+
+ if ((a->state & state) == 0) {
+ /* If we're already FATAL, don't overwrite the error. */
+ if (a->state != ARCHIVE_STATE_FATAL)
+ archive_set_error(a, -1,
+ "INTERNAL ERROR: Function '%s' invoked with"
+ " archive structure in state '%s',"
+ " should be in state '%s'",
+ function,
+ write_all_states(states1, a->state),
+ write_all_states(states2, state));
+ a->state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ return ARCHIVE_OK;
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_cmdline.c b/Utilities/cmlibarchive/libarchive/archive_cmdline.c
new file mode 100644
index 0000000000..7d3bac53bb
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_cmdline.c
@@ -0,0 +1,227 @@
+/*-
+ * Copyright (c) 2012 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_STRING_H
+# include <string.h>
+#endif
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_cmdline_private.h"
+#include "archive_string.h"
+
+static int cmdline_set_path(struct archive_cmdline *, const char *);
+static int cmdline_add_arg(struct archive_cmdline *, const char *);
+
+static ssize_t
+extract_quotation(struct archive_string *as, const char *p)
+{
+ const char *s;
+
+ for (s = p + 1; *s;) {
+ if (*s == '\\') {
+ if (s[1] != '\0') {
+ archive_strappend_char(as, s[1]);
+ s += 2;
+ } else
+ s++;
+ } else if (*s == '"')
+ break;
+ else {
+ archive_strappend_char(as, s[0]);
+ s++;
+ }
+ }
+ if (*s != '"')
+ return (ARCHIVE_FAILED);/* Invalid sequence. */
+ return ((ssize_t)(s + 1 - p));
+}
+
+static ssize_t
+get_argument(struct archive_string *as, const char *p)
+{
+ const char *s = p;
+
+ archive_string_empty(as);
+
+ /* Skip beginning space characters. */
+ while (*s != '\0' && *s == ' ')
+ s++;
+ /* Copy non-space characters. */
+ while (*s != '\0' && *s != ' ') {
+ if (*s == '\\') {
+ if (s[1] != '\0') {
+ archive_strappend_char(as, s[1]);
+ s += 2;
+ } else {
+ s++;/* Ignore this character.*/
+ break;
+ }
+ } else if (*s == '"') {
+ ssize_t q = extract_quotation(as, s);
+ if (q < 0)
+ return (ARCHIVE_FAILED);/* Invalid sequence. */
+ s += q;
+ } else {
+ archive_strappend_char(as, s[0]);
+ s++;
+ }
+ }
+ return ((ssize_t)(s - p));
+}
+
+/*
+ * Set up command line arguments.
+ * Returns ARChIVE_OK if everything okey.
+ * Returns ARChIVE_FAILED if there is a lack of the `"' terminator or an
+ * empty command line.
+ * Returns ARChIVE_FATAL if no memory.
+ */
+int
+__archive_cmdline_parse(struct archive_cmdline *data, const char *cmd)
+{
+ struct archive_string as;
+ const char *p;
+ ssize_t al;
+ int r;
+
+ archive_string_init(&as);
+
+ /* Get first argument as a command path. */
+ al = get_argument(&as, cmd);
+ if (al < 0) {
+ r = ARCHIVE_FAILED;/* Invalid sequence. */
+ goto exit_function;
+ }
+ if (archive_strlen(&as) == 0) {
+ r = ARCHIVE_FAILED;/* An empty command path. */
+ goto exit_function;
+ }
+ r = cmdline_set_path(data, as.s);
+ if (r != ARCHIVE_OK)
+ goto exit_function;
+ p = strrchr(as.s, '/');
+ if (p == NULL)
+ p = as.s;
+ else
+ p++;
+ r = cmdline_add_arg(data, p);
+ if (r != ARCHIVE_OK)
+ goto exit_function;
+ cmd += al;
+
+ for (;;) {
+ al = get_argument(&as, cmd);
+ if (al < 0) {
+ r = ARCHIVE_FAILED;/* Invalid sequence. */
+ goto exit_function;
+ }
+ if (al == 0)
+ break;
+ cmd += al;
+ if (archive_strlen(&as) == 0 && *cmd == '\0')
+ break;
+ r = cmdline_add_arg(data, as.s);
+ if (r != ARCHIVE_OK)
+ goto exit_function;
+ }
+ r = ARCHIVE_OK;
+exit_function:
+ archive_string_free(&as);
+ return (r);
+}
+
+/*
+ * Set the program path.
+ */
+static int
+cmdline_set_path(struct archive_cmdline *data, const char *path)
+{
+ char *newptr;
+
+ newptr = realloc(data->path, strlen(path) + 1);
+ if (newptr == NULL)
+ return (ARCHIVE_FATAL);
+ data->path = newptr;
+ strcpy(data->path, path);
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Add a argument for the program.
+ */
+static int
+cmdline_add_arg(struct archive_cmdline *data, const char *arg)
+{
+ char **newargv;
+
+ if (data->path == NULL)
+ return (ARCHIVE_FAILED);
+
+ newargv = realloc(data->argv, (data->argc + 2) * sizeof(char *));
+ if (newargv == NULL)
+ return (ARCHIVE_FATAL);
+ data->argv = newargv;
+ data->argv[data->argc] = strdup(arg);
+ if (data->argv[data->argc] == NULL)
+ return (ARCHIVE_FATAL);
+ /* Set the terminator of argv. */
+ data->argv[++data->argc] = NULL;
+ return (ARCHIVE_OK);
+}
+
+struct archive_cmdline *
+__archive_cmdline_allocate(void)
+{
+ return (struct archive_cmdline *)
+ calloc(1, sizeof(struct archive_cmdline));
+}
+
+/*
+ * Release the resources.
+ */
+int
+__archive_cmdline_free(struct archive_cmdline *data)
+{
+
+ if (data) {
+ free(data->path);
+ if (data->argv != NULL) {
+ int i;
+ for (i = 0; data->argv[i] != NULL; i++)
+ free(data->argv[i]);
+ free(data->argv);
+ }
+ free(data);
+ }
+ return (ARCHIVE_OK);
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_cmdline_private.h b/Utilities/cmlibarchive/libarchive/archive_cmdline_private.h
new file mode 100644
index 0000000000..4e409e8148
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_cmdline_private.h
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#ifndef __LIBARCHIVE_TEST
+#error This header is only to be used internally to libarchive.
+#endif
+#endif
+
+#ifndef ARCHIVE_CMDLINE_PRIVATE_H
+#define ARCHIVE_CMDLINE_PRIVATE_H
+
+struct archive_cmdline {
+ char *path;
+ char **argv;
+ int argc;
+};
+
+struct archive_cmdline *__archive_cmdline_allocate(void);
+int __archive_cmdline_parse(struct archive_cmdline *, const char *);
+int __archive_cmdline_free(struct archive_cmdline *);
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_crc32.h b/Utilities/cmlibarchive/libarchive/archive_crc32.h
new file mode 100644
index 0000000000..cd633af89b
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_crc32.h
@@ -0,0 +1,78 @@
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_crc32.h 201102 2009-12-28 03:11:36Z kientzle $
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+/*
+ * When zlib is unavailable, we should still be able to validate
+ * uncompressed zip archives. That requires us to be able to compute
+ * the CRC32 check value. This is a drop-in compatible replacement
+ * for crc32() from zlib. It's slower than the zlib implementation,
+ * but still pretty fast: This runs about 300MB/s on my 3GHz P4
+ * compared to about 800MB/s for the zlib implementation.
+ */
+static unsigned long
+crc32(unsigned long crc, const void *_p, size_t len)
+{
+ unsigned long crc2, b, i;
+ const unsigned char *p = _p;
+ static volatile int crc_tbl_inited = 0;
+ static unsigned long crc_tbl[256];
+
+ if (!crc_tbl_inited) {
+ for (b = 0; b < 256; ++b) {
+ crc2 = b;
+ for (i = 8; i > 0; --i) {
+ if (crc2 & 1)
+ crc2 = (crc2 >> 1) ^ 0xedb88320UL;
+ else
+ crc2 = (crc2 >> 1);
+ }
+ crc_tbl[b] = crc2;
+ }
+ crc_tbl_inited = 1;
+ }
+
+ crc = crc ^ 0xffffffffUL;
+ /* A use of this loop is about 20% - 30% faster than
+ * no use version in any optimization option of gcc. */
+ for (;len >= 8; len -= 8) {
+ crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ }
+ while (len--)
+ crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ return (crc ^ 0xffffffffUL);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_crypto.c b/Utilities/cmlibarchive/libarchive/archive_crypto.c
new file mode 100644
index 0000000000..85aba3ae27
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_crypto.c
@@ -0,0 +1,1429 @@
+/*-
+* Copyright (c) 2003-2007 Tim Kientzle
+* Copyright (c) 2011 Andres Mejia
+* Copyright (c) 2011 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"
+
+#include "archive.h"
+#include "archive_crypto_private.h"
+
+/* In particular, force the configure probe to break if it tries
+ * to test a combination of OpenSSL and libmd. */
+#if defined(ARCHIVE_CRYPTO_OPENSSL) && defined(ARCHIVE_CRYPTO_LIBMD)
+#error Cannot use both OpenSSL and libmd.
+#endif
+
+/*
+ * Message digest functions for Windows platform.
+ */
+#if defined(ARCHIVE_CRYPTO_MD5_WIN) ||\
+ defined(ARCHIVE_CRYPTO_SHA1_WIN) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_WIN) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_WIN) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_WIN)
+
+/*
+ * Initialize a Message digest.
+ */
+static int
+win_crypto_init(Digest_CTX *ctx, ALG_ID algId)
+{
+
+ ctx->valid = 0;
+ if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL,
+ PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
+ if (GetLastError() != (DWORD)NTE_BAD_KEYSET)
+ return (ARCHIVE_FAILED);
+ if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL,
+ PROV_RSA_FULL, CRYPT_NEWKEYSET))
+ return (ARCHIVE_FAILED);
+ }
+
+ if (!CryptCreateHash(ctx->cryptProv, algId, 0, 0, &ctx->hash)) {
+ CryptReleaseContext(ctx->cryptProv, 0);
+ return (ARCHIVE_FAILED);
+ }
+
+ ctx->valid = 1;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Update a Message digest.
+ */
+static int
+win_crypto_Update(Digest_CTX *ctx, const unsigned char *buf, size_t len)
+{
+
+ if (!ctx->valid)
+ return (ARCHIVE_FAILED);
+
+ CryptHashData(ctx->hash,
+ (unsigned char *)(uintptr_t)buf,
+ (DWORD)len, 0);
+ return (ARCHIVE_OK);
+}
+
+static int
+win_crypto_Final(unsigned char *buf, size_t bufsize, Digest_CTX *ctx)
+{
+ DWORD siglen = (DWORD)bufsize;
+
+ if (!ctx->valid)
+ return (ARCHIVE_FAILED);
+
+ CryptGetHashParam(ctx->hash, HP_HASHVAL, buf, &siglen, 0);
+ CryptDestroyHash(ctx->hash);
+ CryptReleaseContext(ctx->cryptProv, 0);
+ ctx->valid = 0;
+ return (ARCHIVE_OK);
+}
+
+#endif /* defined(ARCHIVE_CRYPTO_*_WIN) */
+
+
+/* MD5 implementations */
+#if defined(ARCHIVE_CRYPTO_MD5_LIBC)
+
+static int
+__archive_libc_md5init(archive_md5_ctx *ctx)
+{
+ MD5Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_md5update(archive_md5_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ MD5Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_md5final(archive_md5_ctx *ctx, void *md)
+{
+ MD5Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_MD5_LIBMD)
+
+static int
+__archive_libmd_md5init(archive_md5_ctx *ctx)
+{
+ MD5Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_md5update(archive_md5_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ MD5Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_md5final(archive_md5_ctx *ctx, void *md)
+{
+ MD5Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM)
+
+static int
+__archive_libsystem_md5init(archive_md5_ctx *ctx)
+{
+ CC_MD5_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_md5update(archive_md5_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ CC_MD5_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_md5final(archive_md5_ctx *ctx, void *md)
+{
+ CC_MD5_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_MD5_NETTLE)
+
+static int
+__archive_nettle_md5init(archive_md5_ctx *ctx)
+{
+ md5_init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_md5update(archive_md5_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ md5_update(ctx, insize, indata);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_md5final(archive_md5_ctx *ctx, void *md)
+{
+ md5_digest(ctx, MD5_DIGEST_SIZE, md);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_MD5_OPENSSL)
+
+static int
+__archive_openssl_md5init(archive_md5_ctx *ctx)
+{
+ EVP_DigestInit(ctx, EVP_md5());
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_md5update(archive_md5_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ EVP_DigestUpdate(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_md5final(archive_md5_ctx *ctx, void *md)
+{
+ /* HACK: archive_write_set_format_xar.c is finalizing empty contexts, so
+ * this is meant to cope with that. Real fix is probably to fix
+ * archive_write_set_format_xar.c
+ */
+ if (ctx->digest)
+ EVP_DigestFinal(ctx, md, NULL);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_MD5_WIN)
+
+static int
+__archive_windowsapi_md5init(archive_md5_ctx *ctx)
+{
+ return (win_crypto_init(ctx, CALG_MD5));
+}
+
+static int
+__archive_windowsapi_md5update(archive_md5_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ return (win_crypto_Update(ctx, indata, insize));
+}
+
+static int
+__archive_windowsapi_md5final(archive_md5_ctx *ctx, void *md)
+{
+ return (win_crypto_Final(md, 16, ctx));
+}
+
+#else
+
+static int
+__archive_stub_md5init(archive_md5_ctx *ctx)
+{
+ (void)ctx; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_md5update(archive_md5_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ (void)ctx; /* UNUSED */
+ (void)indata; /* UNUSED */
+ (void)insize; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_md5final(archive_md5_ctx *ctx, void *md)
+{
+ (void)ctx; /* UNUSED */
+ (void)md; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+#endif
+
+/* RIPEMD160 implementations */
+#if defined(ARCHIVE_CRYPTO_RMD160_LIBC)
+
+static int
+__archive_libc_ripemd160init(archive_rmd160_ctx *ctx)
+{
+ RMD160Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ RMD160Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_ripemd160final(archive_rmd160_ctx *ctx, void *md)
+{
+ RMD160Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_RMD160_LIBMD)
+
+static int
+__archive_libmd_ripemd160init(archive_rmd160_ctx *ctx)
+{
+ RIPEMD160_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ RIPEMD160_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_ripemd160final(archive_rmd160_ctx *ctx, void *md)
+{
+ RIPEMD160_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_RMD160_NETTLE)
+
+static int
+__archive_nettle_ripemd160init(archive_rmd160_ctx *ctx)
+{
+ ripemd160_init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ ripemd160_update(ctx, insize, indata);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_ripemd160final(archive_rmd160_ctx *ctx, void *md)
+{
+ ripemd160_digest(ctx, RIPEMD160_DIGEST_SIZE, md);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_RMD160_OPENSSL)
+
+static int
+__archive_openssl_ripemd160init(archive_rmd160_ctx *ctx)
+{
+ EVP_DigestInit(ctx, EVP_ripemd160());
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ EVP_DigestUpdate(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_ripemd160final(archive_rmd160_ctx *ctx, void *md)
+{
+ EVP_DigestFinal(ctx, md, NULL);
+ return (ARCHIVE_OK);
+}
+
+#else
+
+static int
+__archive_stub_ripemd160init(archive_rmd160_ctx *ctx)
+{
+ (void)ctx; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ (void)ctx; /* UNUSED */
+ (void)indata; /* UNUSED */
+ (void)insize; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_ripemd160final(archive_rmd160_ctx *ctx, void *md)
+{
+ (void)ctx; /* UNUSED */
+ (void)md; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+#endif
+
+/* SHA1 implementations */
+#if defined(ARCHIVE_CRYPTO_SHA1_LIBC)
+
+static int
+__archive_libc_sha1init(archive_sha1_ctx *ctx)
+{
+ SHA1Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_sha1update(archive_sha1_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA1Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_sha1final(archive_sha1_ctx *ctx, void *md)
+{
+ SHA1Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA1_LIBMD)
+
+static int
+__archive_libmd_sha1init(archive_sha1_ctx *ctx)
+{
+ SHA1_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_sha1update(archive_sha1_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA1_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_sha1final(archive_sha1_ctx *ctx, void *md)
+{
+ SHA1_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM)
+
+static int
+__archive_libsystem_sha1init(archive_sha1_ctx *ctx)
+{
+ CC_SHA1_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_sha1update(archive_sha1_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ CC_SHA1_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_sha1final(archive_sha1_ctx *ctx, void *md)
+{
+ CC_SHA1_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA1_NETTLE)
+
+static int
+__archive_nettle_sha1init(archive_sha1_ctx *ctx)
+{
+ sha1_init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_sha1update(archive_sha1_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ sha1_update(ctx, insize, indata);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_sha1final(archive_sha1_ctx *ctx, void *md)
+{
+ sha1_digest(ctx, SHA1_DIGEST_SIZE, md);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA1_OPENSSL)
+
+static int
+__archive_openssl_sha1init(archive_sha1_ctx *ctx)
+{
+ EVP_DigestInit(ctx, EVP_sha1());
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_sha1update(archive_sha1_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ EVP_DigestUpdate(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_sha1final(archive_sha1_ctx *ctx, void *md)
+{
+ /* HACK: archive_write_set_format_xar.c is finalizing empty contexts, so
+ * this is meant to cope with that. Real fix is probably to fix
+ * archive_write_set_format_xar.c
+ */
+ if (ctx->digest)
+ EVP_DigestFinal(ctx, md, NULL);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA1_WIN)
+
+static int
+__archive_windowsapi_sha1init(archive_sha1_ctx *ctx)
+{
+ return (win_crypto_init(ctx, CALG_SHA1));
+}
+
+static int
+__archive_windowsapi_sha1update(archive_sha1_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ return (win_crypto_Update(ctx, indata, insize));
+}
+
+static int
+__archive_windowsapi_sha1final(archive_sha1_ctx *ctx, void *md)
+{
+ return (win_crypto_Final(md, 20, ctx));
+}
+
+#else
+
+static int
+__archive_stub_sha1init(archive_sha1_ctx *ctx)
+{
+ (void)ctx; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_sha1update(archive_sha1_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ (void)ctx; /* UNUSED */
+ (void)indata; /* UNUSED */
+ (void)insize; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_sha1final(archive_sha1_ctx *ctx, void *md)
+{
+ (void)ctx; /* UNUSED */
+ (void)md; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+#endif
+
+/* SHA256 implementations */
+#if defined(ARCHIVE_CRYPTO_SHA256_LIBC)
+
+static int
+__archive_libc_sha256init(archive_sha256_ctx *ctx)
+{
+ SHA256_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_sha256update(archive_sha256_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA256_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_sha256final(archive_sha256_ctx *ctx, void *md)
+{
+ SHA256_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC2)
+
+static int
+__archive_libc2_sha256init(archive_sha256_ctx *ctx)
+{
+ SHA256Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc2_sha256update(archive_sha256_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA256Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc2_sha256final(archive_sha256_ctx *ctx, void *md)
+{
+ SHA256Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC3)
+
+static int
+__archive_libc3_sha256init(archive_sha256_ctx *ctx)
+{
+ SHA256Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc3_sha256update(archive_sha256_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA256Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc3_sha256final(archive_sha256_ctx *ctx, void *md)
+{
+ SHA256Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBMD)
+
+static int
+__archive_libmd_sha256init(archive_sha256_ctx *ctx)
+{
+ SHA256_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_sha256update(archive_sha256_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA256_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_sha256final(archive_sha256_ctx *ctx, void *md)
+{
+ SHA256_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM)
+
+static int
+__archive_libsystem_sha256init(archive_sha256_ctx *ctx)
+{
+ CC_SHA256_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_sha256update(archive_sha256_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ CC_SHA256_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_sha256final(archive_sha256_ctx *ctx, void *md)
+{
+ CC_SHA256_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA256_NETTLE)
+
+static int
+__archive_nettle_sha256init(archive_sha256_ctx *ctx)
+{
+ sha256_init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_sha256update(archive_sha256_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ sha256_update(ctx, insize, indata);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_sha256final(archive_sha256_ctx *ctx, void *md)
+{
+ sha256_digest(ctx, SHA256_DIGEST_SIZE, md);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA256_OPENSSL)
+
+static int
+__archive_openssl_sha256init(archive_sha256_ctx *ctx)
+{
+ EVP_DigestInit(ctx, EVP_sha256());
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_sha256update(archive_sha256_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ EVP_DigestUpdate(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_sha256final(archive_sha256_ctx *ctx, void *md)
+{
+ EVP_DigestFinal(ctx, md, NULL);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA256_WIN)
+
+static int
+__archive_windowsapi_sha256init(archive_sha256_ctx *ctx)
+{
+ return (win_crypto_init(ctx, CALG_SHA_256));
+}
+
+static int
+__archive_windowsapi_sha256update(archive_sha256_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ return (win_crypto_Update(ctx, indata, insize));
+}
+
+static int
+__archive_windowsapi_sha256final(archive_sha256_ctx *ctx, void *md)
+{
+ return (win_crypto_Final(md, 32, ctx));
+}
+
+#else
+
+static int
+__archive_stub_sha256init(archive_sha256_ctx *ctx)
+{
+ (void)ctx; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_sha256update(archive_sha256_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ (void)ctx; /* UNUSED */
+ (void)indata; /* UNUSED */
+ (void)insize; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_sha256final(archive_sha256_ctx *ctx, void *md)
+{
+ (void)ctx; /* UNUSED */
+ (void)md; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+#endif
+
+/* SHA384 implementations */
+#if defined(ARCHIVE_CRYPTO_SHA384_LIBC)
+
+static int
+__archive_libc_sha384init(archive_sha384_ctx *ctx)
+{
+ SHA384_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_sha384update(archive_sha384_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA384_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_sha384final(archive_sha384_ctx *ctx, void *md)
+{
+ SHA384_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC2)
+
+static int
+__archive_libc2_sha384init(archive_sha384_ctx *ctx)
+{
+ SHA384Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc2_sha384update(archive_sha384_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA384Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc2_sha384final(archive_sha384_ctx *ctx, void *md)
+{
+ SHA384Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC3)
+
+static int
+__archive_libc3_sha384init(archive_sha384_ctx *ctx)
+{
+ SHA384Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc3_sha384update(archive_sha384_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA384Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc3_sha384final(archive_sha384_ctx *ctx, void *md)
+{
+ SHA384Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM)
+
+static int
+__archive_libsystem_sha384init(archive_sha384_ctx *ctx)
+{
+ CC_SHA384_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_sha384update(archive_sha384_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ CC_SHA384_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_sha384final(archive_sha384_ctx *ctx, void *md)
+{
+ CC_SHA384_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA384_NETTLE)
+
+static int
+__archive_nettle_sha384init(archive_sha384_ctx *ctx)
+{
+ sha384_init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_sha384update(archive_sha384_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ sha384_update(ctx, insize, indata);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_sha384final(archive_sha384_ctx *ctx, void *md)
+{
+ sha384_digest(ctx, SHA384_DIGEST_SIZE, md);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA384_OPENSSL)
+
+static int
+__archive_openssl_sha384init(archive_sha384_ctx *ctx)
+{
+ EVP_DigestInit(ctx, EVP_sha384());
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_sha384update(archive_sha384_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ EVP_DigestUpdate(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_sha384final(archive_sha384_ctx *ctx, void *md)
+{
+ EVP_DigestFinal(ctx, md, NULL);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA384_WIN)
+
+static int
+__archive_windowsapi_sha384init(archive_sha384_ctx *ctx)
+{
+ return (win_crypto_init(ctx, CALG_SHA_384));
+}
+
+static int
+__archive_windowsapi_sha384update(archive_sha384_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ return (win_crypto_Update(ctx, indata, insize));
+}
+
+static int
+__archive_windowsapi_sha384final(archive_sha384_ctx *ctx, void *md)
+{
+ return (win_crypto_Final(md, 48, ctx));
+}
+
+#else
+
+static int
+__archive_stub_sha384init(archive_sha384_ctx *ctx)
+{
+ (void)ctx; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_sha384update(archive_sha384_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ (void)ctx; /* UNUSED */
+ (void)indata; /* UNUSED */
+ (void)insize; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_sha384final(archive_sha384_ctx *ctx, void *md)
+{
+ (void)ctx; /* UNUSED */
+ (void)md; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+#endif
+
+/* SHA512 implementations */
+#if defined(ARCHIVE_CRYPTO_SHA512_LIBC)
+
+static int
+__archive_libc_sha512init(archive_sha512_ctx *ctx)
+{
+ SHA512_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_sha512update(archive_sha512_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA512_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc_sha512final(archive_sha512_ctx *ctx, void *md)
+{
+ SHA512_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC2)
+
+static int
+__archive_libc2_sha512init(archive_sha512_ctx *ctx)
+{
+ SHA512Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc2_sha512update(archive_sha512_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA512Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc2_sha512final(archive_sha512_ctx *ctx, void *md)
+{
+ SHA512Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC3)
+
+static int
+__archive_libc3_sha512init(archive_sha512_ctx *ctx)
+{
+ SHA512Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc3_sha512update(archive_sha512_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA512Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libc3_sha512final(archive_sha512_ctx *ctx, void *md)
+{
+ SHA512Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBMD)
+
+static int
+__archive_libmd_sha512init(archive_sha512_ctx *ctx)
+{
+ SHA512_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_sha512update(archive_sha512_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ SHA512_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libmd_sha512final(archive_sha512_ctx *ctx, void *md)
+{
+ SHA512_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM)
+
+static int
+__archive_libsystem_sha512init(archive_sha512_ctx *ctx)
+{
+ CC_SHA512_Init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_sha512update(archive_sha512_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ CC_SHA512_Update(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_libsystem_sha512final(archive_sha512_ctx *ctx, void *md)
+{
+ CC_SHA512_Final(md, ctx);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE)
+
+static int
+__archive_nettle_sha512init(archive_sha512_ctx *ctx)
+{
+ sha512_init(ctx);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_sha512update(archive_sha512_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ sha512_update(ctx, insize, indata);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_nettle_sha512final(archive_sha512_ctx *ctx, void *md)
+{
+ sha512_digest(ctx, SHA512_DIGEST_SIZE, md);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL)
+
+static int
+__archive_openssl_sha512init(archive_sha512_ctx *ctx)
+{
+ EVP_DigestInit(ctx, EVP_sha512());
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_sha512update(archive_sha512_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ EVP_DigestUpdate(ctx, indata, insize);
+ return (ARCHIVE_OK);
+}
+
+static int
+__archive_openssl_sha512final(archive_sha512_ctx *ctx, void *md)
+{
+ EVP_DigestFinal(ctx, md, NULL);
+ return (ARCHIVE_OK);
+}
+
+#elif defined(ARCHIVE_CRYPTO_SHA512_WIN)
+
+static int
+__archive_windowsapi_sha512init(archive_sha512_ctx *ctx)
+{
+ return (win_crypto_init(ctx, CALG_SHA_512));
+}
+
+static int
+__archive_windowsapi_sha512update(archive_sha512_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ return (win_crypto_Update(ctx, indata, insize));
+}
+
+static int
+__archive_windowsapi_sha512final(archive_sha512_ctx *ctx, void *md)
+{
+ return (win_crypto_Final(md, 64, ctx));
+}
+
+#else
+
+static int
+__archive_stub_sha512init(archive_sha512_ctx *ctx)
+{
+ (void)ctx; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_sha512update(archive_sha512_ctx *ctx, const void *indata,
+ size_t insize)
+{
+ (void)ctx; /* UNUSED */
+ (void)indata; /* UNUSED */
+ (void)insize; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+static int
+__archive_stub_sha512final(archive_sha512_ctx *ctx, void *md)
+{
+ (void)ctx; /* UNUSED */
+ (void)md; /* UNUSED */
+ return (ARCHIVE_FAILED);
+}
+
+#endif
+
+/* NOTE: Crypto functions are set based on availability and by the following
+ * order of preference.
+ * 1. libc
+ * 2. libc2
+ * 3. libc3
+ * 4. libSystem
+ * 5. Nettle
+ * 6. OpenSSL
+ * 7. libmd
+ * 8. Windows API
+ */
+const struct archive_crypto __archive_crypto =
+{
+/* MD5 */
+#if defined(ARCHIVE_CRYPTO_MD5_LIBC)
+ &__archive_libc_md5init,
+ &__archive_libc_md5update,
+ &__archive_libc_md5final,
+#elif defined(ARCHIVE_CRYPTO_MD5_LIBMD)
+ &__archive_libmd_md5init,
+ &__archive_libmd_md5update,
+ &__archive_libmd_md5final,
+#elif defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM)
+ &__archive_libsystem_md5init,
+ &__archive_libsystem_md5update,
+ &__archive_libsystem_md5final,
+#elif defined(ARCHIVE_CRYPTO_MD5_NETTLE)
+ &__archive_nettle_md5init,
+ &__archive_nettle_md5update,
+ &__archive_nettle_md5final,
+#elif defined(ARCHIVE_CRYPTO_MD5_OPENSSL)
+ &__archive_openssl_md5init,
+ &__archive_openssl_md5update,
+ &__archive_openssl_md5final,
+#elif defined(ARCHIVE_CRYPTO_MD5_WIN)
+ &__archive_windowsapi_md5init,
+ &__archive_windowsapi_md5update,
+ &__archive_windowsapi_md5final,
+#elif !defined(ARCHIVE_MD5_COMPILE_TEST)
+ &__archive_stub_md5init,
+ &__archive_stub_md5update,
+ &__archive_stub_md5final,
+#endif
+
+/* RIPEMD160 */
+#if defined(ARCHIVE_CRYPTO_RMD160_LIBC)
+ &__archive_libc_ripemd160init,
+ &__archive_libc_ripemd160update,
+ &__archive_libc_ripemd160final,
+#elif defined(ARCHIVE_CRYPTO_RMD160_LIBMD)
+ &__archive_libmd_ripemd160init,
+ &__archive_libmd_ripemd160update,
+ &__archive_libmd_ripemd160final,
+#elif defined(ARCHIVE_CRYPTO_RMD160_NETTLE)
+ &__archive_nettle_ripemd160init,
+ &__archive_nettle_ripemd160update,
+ &__archive_nettle_ripemd160final,
+#elif defined(ARCHIVE_CRYPTO_RMD160_OPENSSL)
+ &__archive_openssl_ripemd160init,
+ &__archive_openssl_ripemd160update,
+ &__archive_openssl_ripemd160final,
+#elif !defined(ARCHIVE_RMD160_COMPILE_TEST)
+ &__archive_stub_ripemd160init,
+ &__archive_stub_ripemd160update,
+ &__archive_stub_ripemd160final,
+#endif
+
+/* SHA1 */
+#if defined(ARCHIVE_CRYPTO_SHA1_LIBC)
+ &__archive_libc_sha1init,
+ &__archive_libc_sha1update,
+ &__archive_libc_sha1final,
+#elif defined(ARCHIVE_CRYPTO_SHA1_LIBMD)
+ &__archive_libmd_sha1init,
+ &__archive_libmd_sha1update,
+ &__archive_libmd_sha1final,
+#elif defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM)
+ &__archive_libsystem_sha1init,
+ &__archive_libsystem_sha1update,
+ &__archive_libsystem_sha1final,
+#elif defined(ARCHIVE_CRYPTO_SHA1_NETTLE)
+ &__archive_nettle_sha1init,
+ &__archive_nettle_sha1update,
+ &__archive_nettle_sha1final,
+#elif defined(ARCHIVE_CRYPTO_SHA1_OPENSSL)
+ &__archive_openssl_sha1init,
+ &__archive_openssl_sha1update,
+ &__archive_openssl_sha1final,
+#elif defined(ARCHIVE_CRYPTO_SHA1_WIN)
+ &__archive_windowsapi_sha1init,
+ &__archive_windowsapi_sha1update,
+ &__archive_windowsapi_sha1final,
+#elif !defined(ARCHIVE_SHA1_COMPILE_TEST)
+ &__archive_stub_sha1init,
+ &__archive_stub_sha1update,
+ &__archive_stub_sha1final,
+#endif
+
+/* SHA256 */
+#if defined(ARCHIVE_CRYPTO_SHA256_LIBC)
+ &__archive_libc_sha256init,
+ &__archive_libc_sha256update,
+ &__archive_libc_sha256final,
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC2)
+ &__archive_libc2_sha256init,
+ &__archive_libc2_sha256update,
+ &__archive_libc2_sha256final,
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC3)
+ &__archive_libc3_sha256init,
+ &__archive_libc3_sha256update,
+ &__archive_libc3_sha256final,
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBMD)
+ &__archive_libmd_sha256init,
+ &__archive_libmd_sha256update,
+ &__archive_libmd_sha256final,
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM)
+ &__archive_libsystem_sha256init,
+ &__archive_libsystem_sha256update,
+ &__archive_libsystem_sha256final,
+#elif defined(ARCHIVE_CRYPTO_SHA256_NETTLE)
+ &__archive_nettle_sha256init,
+ &__archive_nettle_sha256update,
+ &__archive_nettle_sha256final,
+#elif defined(ARCHIVE_CRYPTO_SHA256_OPENSSL)
+ &__archive_openssl_sha256init,
+ &__archive_openssl_sha256update,
+ &__archive_openssl_sha256final,
+#elif defined(ARCHIVE_CRYPTO_SHA256_WIN)
+ &__archive_windowsapi_sha256init,
+ &__archive_windowsapi_sha256update,
+ &__archive_windowsapi_sha256final,
+#elif !defined(ARCHIVE_SHA256_COMPILE_TEST)
+ &__archive_stub_sha256init,
+ &__archive_stub_sha256update,
+ &__archive_stub_sha256final,
+#endif
+
+/* SHA384 */
+#if defined(ARCHIVE_CRYPTO_SHA384_LIBC)
+ &__archive_libc_sha384init,
+ &__archive_libc_sha384update,
+ &__archive_libc_sha384final,
+#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC2)
+ &__archive_libc2_sha384init,
+ &__archive_libc2_sha384update,
+ &__archive_libc2_sha384final,
+#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC3)
+ &__archive_libc3_sha384init,
+ &__archive_libc3_sha384update,
+ &__archive_libc3_sha384final,
+#elif defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM)
+ &__archive_libsystem_sha384init,
+ &__archive_libsystem_sha384update,
+ &__archive_libsystem_sha384final,
+#elif defined(ARCHIVE_CRYPTO_SHA384_NETTLE)
+ &__archive_nettle_sha384init,
+ &__archive_nettle_sha384update,
+ &__archive_nettle_sha384final,
+#elif defined(ARCHIVE_CRYPTO_SHA384_OPENSSL)
+ &__archive_openssl_sha384init,
+ &__archive_openssl_sha384update,
+ &__archive_openssl_sha384final,
+#elif defined(ARCHIVE_CRYPTO_SHA384_WIN)
+ &__archive_windowsapi_sha384init,
+ &__archive_windowsapi_sha384update,
+ &__archive_windowsapi_sha384final,
+#elif !defined(ARCHIVE_SHA384_COMPILE_TEST)
+ &__archive_stub_sha384init,
+ &__archive_stub_sha384update,
+ &__archive_stub_sha384final,
+#endif
+
+/* SHA512 */
+#if defined(ARCHIVE_CRYPTO_SHA512_LIBC)
+ &__archive_libc_sha512init,
+ &__archive_libc_sha512update,
+ &__archive_libc_sha512final
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC2)
+ &__archive_libc2_sha512init,
+ &__archive_libc2_sha512update,
+ &__archive_libc2_sha512final
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC3)
+ &__archive_libc3_sha512init,
+ &__archive_libc3_sha512update,
+ &__archive_libc3_sha512final
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBMD)
+ &__archive_libmd_sha512init,
+ &__archive_libmd_sha512update,
+ &__archive_libmd_sha512final
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM)
+ &__archive_libsystem_sha512init,
+ &__archive_libsystem_sha512update,
+ &__archive_libsystem_sha512final
+#elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE)
+ &__archive_nettle_sha512init,
+ &__archive_nettle_sha512update,
+ &__archive_nettle_sha512final,
+#elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL)
+ &__archive_openssl_sha512init,
+ &__archive_openssl_sha512update,
+ &__archive_openssl_sha512final
+#elif defined(ARCHIVE_CRYPTO_SHA512_WIN)
+ &__archive_windowsapi_sha512init,
+ &__archive_windowsapi_sha512update,
+ &__archive_windowsapi_sha512final
+#elif !defined(ARCHIVE_SHA512_COMPILE_TEST)
+ &__archive_stub_sha512init,
+ &__archive_stub_sha512update,
+ &__archive_stub_sha512final
+#endif
+};
diff --git a/Utilities/cmlibarchive/libarchive/archive_crypto_private.h b/Utilities/cmlibarchive/libarchive/archive_crypto_private.h
new file mode 100644
index 0000000000..f8b1fb3c3f
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_crypto_private.h
@@ -0,0 +1,376 @@
+/*-
+* Copyright (c) 2003-2007 Tim Kientzle
+* Copyright (c) 2011 Andres Mejia
+* 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_CRYPTO_PRIVATE_H_INCLUDED
+#define ARCHIVE_CRYPTO_PRIVATE_H_INCLUDED
+
+/*
+ * Crypto support in various Operating Systems:
+ *
+ * NetBSD:
+ * - MD5 and SHA1 in libc: without _ after algorithm name
+ * - SHA2 in libc: with _ after algorithm name
+ *
+ * OpenBSD:
+ * - MD5, SHA1 and SHA2 in libc: without _ after algorithm name
+ * - OpenBSD 4.4 and earlier have SHA2 in libc with _ after algorithm name
+ *
+ * DragonFly and FreeBSD:
+ * - MD5 libmd: without _ after algorithm name
+ * - SHA1, SHA256 and SHA512 in libmd: with _ after algorithm name
+ *
+ * Mac OS X (10.4 and later):
+ * - MD5, SHA1 and SHA2 in libSystem: with CC_ prefix and _ after algorithm name
+ *
+ * OpenSSL:
+ * - MD5, SHA1 and SHA2 in libcrypto: with _ after algorithm name
+ *
+ * Windows:
+ * - MD5, SHA1 and SHA2 in archive_crypto.c using Windows crypto API
+ */
+
+/* libc crypto headers */
+#if defined(ARCHIVE_CRYPTO_MD5_LIBC)
+#include <md5.h>
+#endif
+#if defined(ARCHIVE_CRYPTO_RMD160_LIBC)
+#include <rmd160.h>
+#endif
+#if defined(ARCHIVE_CRYPTO_SHA1_LIBC)
+#include <sha1.h>
+#endif
+#if defined(ARCHIVE_CRYPTO_SHA256_LIBC) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_LIBC2) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_LIBC3) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_LIBC) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_LIBC2) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_LIBC3) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_LIBC) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_LIBC2) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_LIBC3)
+#include <sha2.h>
+#endif
+
+/* libmd crypto headers */
+#if defined(ARCHIVE_CRYPTO_MD5_LIBMD) ||\
+ defined(ARCHIVE_CRYPTO_RMD160_LIBMD) ||\
+ defined(ARCHIVE_CRYPTO_SHA1_LIBMD) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_LIBMD) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_LIBMD)
+#define ARCHIVE_CRYPTO_LIBMD 1
+#endif
+
+#if defined(ARCHIVE_CRYPTO_MD5_LIBMD)
+#include <md5.h>
+#endif
+#if defined(ARCHIVE_CRYPTO_RMD160_LIBMD)
+#include <ripemd.h>
+#endif
+#if defined(ARCHIVE_CRYPTO_SHA1_LIBMD)
+#include <sha.h>
+#endif
+#if defined(ARCHIVE_CRYPTO_SHA256_LIBMD)
+#include <sha256.h>
+#endif
+#if defined(ARCHIVE_CRYPTO_SHA512_LIBMD)
+#include <sha512.h>
+#endif
+
+/* libSystem crypto headers */
+#if defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM) ||\
+ defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM)
+#include <CommonCrypto/CommonDigest.h>
+#endif
+
+/* Nettle crypto headers */
+#if defined(ARCHIVE_CRYPTO_MD5_NETTLE)
+#include <nettle/md5.h>
+#endif
+#if defined(ARCHIVE_CRYPTO_RMD160_NETTLE)
+#include <nettle/ripemd160.h>
+#endif
+#if defined(ARCHIVE_CRYPTO_SHA1_NETTLE) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_NETTLE) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_NETTLE) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_NETTLE)
+#include <nettle/sha.h>
+#endif
+
+/* OpenSSL crypto headers */
+#if defined(ARCHIVE_CRYPTO_MD5_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_RMD160_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_SHA1_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_OPENSSL)
+#define ARCHIVE_CRYPTO_OPENSSL 1
+#include <openssl/evp.h>
+#endif
+
+/* Windows crypto headers */
+#if defined(ARCHIVE_CRYPTO_MD5_WIN) ||\
+ defined(ARCHIVE_CRYPTO_SHA1_WIN) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_WIN) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_WIN) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_WIN)
+#include <wincrypt.h>
+typedef struct {
+ int valid;
+ HCRYPTPROV cryptProv;
+ HCRYPTHASH hash;
+} Digest_CTX;
+#endif
+
+/* typedefs */
+#if defined(ARCHIVE_CRYPTO_MD5_LIBC)
+typedef MD5_CTX archive_md5_ctx;
+#elif defined(ARCHIVE_CRYPTO_MD5_LIBMD)
+typedef MD5_CTX archive_md5_ctx;
+#elif defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM)
+typedef CC_MD5_CTX archive_md5_ctx;
+#elif defined(ARCHIVE_CRYPTO_MD5_NETTLE)
+typedef struct md5_ctx archive_md5_ctx;
+#elif defined(ARCHIVE_CRYPTO_MD5_OPENSSL)
+typedef EVP_MD_CTX archive_md5_ctx;
+#elif defined(ARCHIVE_CRYPTO_MD5_WIN)
+typedef Digest_CTX archive_md5_ctx;
+#else
+typedef unsigned char archive_md5_ctx;
+#endif
+
+#if defined(ARCHIVE_CRYPTO_RMD160_LIBC)
+typedef RMD160_CTX archive_rmd160_ctx;
+#elif defined(ARCHIVE_CRYPTO_RMD160_LIBMD)
+typedef RIPEMD160_CTX archive_rmd160_ctx;
+#elif defined(ARCHIVE_CRYPTO_RMD160_NETTLE)
+typedef struct ripemd160_ctx archive_rmd160_ctx;
+#elif defined(ARCHIVE_CRYPTO_RMD160_OPENSSL)
+typedef EVP_MD_CTX archive_rmd160_ctx;
+#else
+typedef unsigned char archive_rmd160_ctx;
+#endif
+
+#if defined(ARCHIVE_CRYPTO_SHA1_LIBC)
+typedef SHA1_CTX archive_sha1_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA1_LIBMD)
+typedef SHA1_CTX archive_sha1_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM)
+typedef CC_SHA1_CTX archive_sha1_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA1_NETTLE)
+typedef struct sha1_ctx archive_sha1_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA1_OPENSSL)
+typedef EVP_MD_CTX archive_sha1_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA1_WIN)
+typedef Digest_CTX archive_sha1_ctx;
+#else
+typedef unsigned char archive_sha1_ctx;
+#endif
+
+#if defined(ARCHIVE_CRYPTO_SHA256_LIBC)
+typedef SHA256_CTX archive_sha256_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC2)
+typedef SHA256_CTX archive_sha256_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC3)
+typedef SHA2_CTX archive_sha256_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBMD)
+typedef SHA256_CTX archive_sha256_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM)
+typedef CC_SHA256_CTX archive_sha256_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA256_NETTLE)
+typedef struct sha256_ctx archive_sha256_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA256_OPENSSL)
+typedef EVP_MD_CTX archive_sha256_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA256_WIN)
+typedef Digest_CTX archive_sha256_ctx;
+#else
+typedef unsigned char archive_sha256_ctx;
+#endif
+
+#if defined(ARCHIVE_CRYPTO_SHA384_LIBC)
+typedef SHA384_CTX archive_sha384_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC2)
+typedef SHA384_CTX archive_sha384_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC3)
+typedef SHA2_CTX archive_sha384_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM)
+typedef CC_SHA512_CTX archive_sha384_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA384_NETTLE)
+typedef struct sha384_ctx archive_sha384_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA384_OPENSSL)
+typedef EVP_MD_CTX archive_sha384_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA384_WIN)
+typedef Digest_CTX archive_sha384_ctx;
+#else
+typedef unsigned char archive_sha384_ctx;
+#endif
+
+#if defined(ARCHIVE_CRYPTO_SHA512_LIBC)
+typedef SHA512_CTX archive_sha512_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC2)
+typedef SHA512_CTX archive_sha512_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC3)
+typedef SHA2_CTX archive_sha512_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBMD)
+typedef SHA512_CTX archive_sha512_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM)
+typedef CC_SHA512_CTX archive_sha512_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE)
+typedef struct sha512_ctx archive_sha512_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL)
+typedef EVP_MD_CTX archive_sha512_ctx;
+#elif defined(ARCHIVE_CRYPTO_SHA512_WIN)
+typedef Digest_CTX archive_sha512_ctx;
+#else
+typedef unsigned char archive_sha512_ctx;
+#endif
+
+/* defines */
+#if defined(ARCHIVE_CRYPTO_MD5_LIBC) ||\
+ defined(ARCHIVE_CRYPTO_MD5_LIBMD) || \
+ defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM) ||\
+ defined(ARCHIVE_CRYPTO_MD5_NETTLE) ||\
+ defined(ARCHIVE_CRYPTO_MD5_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_MD5_WIN)
+#define ARCHIVE_HAS_MD5
+#endif
+#define archive_md5_init(ctx)\
+ __archive_crypto.md5init(ctx)
+#define archive_md5_final(ctx, md)\
+ __archive_crypto.md5final(ctx, md)
+#define archive_md5_update(ctx, buf, n)\
+ __archive_crypto.md5update(ctx, buf, n)
+
+#if defined(ARCHIVE_CRYPTO_RMD160_LIBC) ||\
+ defined(ARCHIVE_CRYPTO_RMD160_NETTLE) ||\
+ defined(ARCHIVE_CRYPTO_RMD160_OPENSSL)
+#define ARCHIVE_HAS_RMD160
+#endif
+#define archive_rmd160_init(ctx)\
+ __archive_crypto.rmd160init(ctx)
+#define archive_rmd160_final(ctx, md)\
+ __archive_crypto.rmd160final(ctx, md)
+#define archive_rmd160_update(ctx, buf, n)\
+ __archive_crypto.rmd160update(ctx, buf, n)
+
+#if defined(ARCHIVE_CRYPTO_SHA1_LIBC) ||\
+ defined(ARCHIVE_CRYPTO_SHA1_LIBMD) || \
+ defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM) ||\
+ defined(ARCHIVE_CRYPTO_SHA1_NETTLE) ||\
+ defined(ARCHIVE_CRYPTO_SHA1_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_SHA1_WIN)
+#define ARCHIVE_HAS_SHA1
+#endif
+#define archive_sha1_init(ctx)\
+ __archive_crypto.sha1init(ctx)
+#define archive_sha1_final(ctx, md)\
+ __archive_crypto.sha1final(ctx, md)
+#define archive_sha1_update(ctx, buf, n)\
+ __archive_crypto.sha1update(ctx, buf, n)
+
+#if defined(ARCHIVE_CRYPTO_SHA256_LIBC) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_LIBC2) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_LIBC3) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_LIBMD) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_NETTLE) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_SHA256_WIN)
+#define ARCHIVE_HAS_SHA256
+#endif
+#define archive_sha256_init(ctx)\
+ __archive_crypto.sha256init(ctx)
+#define archive_sha256_final(ctx, md)\
+ __archive_crypto.sha256final(ctx, md)
+#define archive_sha256_update(ctx, buf, n)\
+ __archive_crypto.sha256update(ctx, buf, n)
+
+#if defined(ARCHIVE_CRYPTO_SHA384_LIBC) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_LIBC2) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_LIBC3) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_NETTLE) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_SHA384_WIN)
+#define ARCHIVE_HAS_SHA384
+#endif
+#define archive_sha384_init(ctx)\
+ __archive_crypto.sha384init(ctx)
+#define archive_sha384_final(ctx, md)\
+ __archive_crypto.sha384final(ctx, md)
+#define archive_sha384_update(ctx, buf, n)\
+ __archive_crypto.sha384update(ctx, buf, n)
+
+#if defined(ARCHIVE_CRYPTO_SHA512_LIBC) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_LIBC2) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_LIBC3) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_LIBMD) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_NETTLE) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_OPENSSL) ||\
+ defined(ARCHIVE_CRYPTO_SHA512_WIN)
+#define ARCHIVE_HAS_SHA512
+#endif
+#define archive_sha512_init(ctx)\
+ __archive_crypto.sha512init(ctx)
+#define archive_sha512_final(ctx, md)\
+ __archive_crypto.sha512final(ctx, md)
+#define archive_sha512_update(ctx, buf, n)\
+ __archive_crypto.sha512update(ctx, buf, n)
+
+/* Minimal interface to crypto functionality for internal use in libarchive */
+struct archive_crypto
+{
+ /* Message Digest */
+ int (*md5init)(archive_md5_ctx *ctx);
+ int (*md5update)(archive_md5_ctx *, const void *, size_t);
+ int (*md5final)(archive_md5_ctx *, void *);
+ int (*rmd160init)(archive_rmd160_ctx *);
+ int (*rmd160update)(archive_rmd160_ctx *, const void *, size_t);
+ int (*rmd160final)(archive_rmd160_ctx *, void *);
+ int (*sha1init)(archive_sha1_ctx *);
+ int (*sha1update)(archive_sha1_ctx *, const void *, size_t);
+ int (*sha1final)(archive_sha1_ctx *, void *);
+ int (*sha256init)(archive_sha256_ctx *);
+ int (*sha256update)(archive_sha256_ctx *, const void *, size_t);
+ int (*sha256final)(archive_sha256_ctx *, void *);
+ int (*sha384init)(archive_sha384_ctx *);
+ int (*sha384update)(archive_sha384_ctx *, const void *, size_t);
+ int (*sha384final)(archive_sha384_ctx *, void *);
+ int (*sha512init)(archive_sha512_ctx *);
+ int (*sha512update)(archive_sha512_ctx *, const void *, size_t);
+ int (*sha512final)(archive_sha512_ctx *, void *);
+};
+
+extern const struct archive_crypto __archive_crypto;
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_endian.h b/Utilities/cmlibarchive/libarchive/archive_endian.h
new file mode 100644
index 0000000000..1c48563b13
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_endian.h
@@ -0,0 +1,196 @@
+/*-
+ * Copyright (c) 2002 Thomas Moestl <tmm@FreeBSD.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 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 AUTHOR 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_endian.h 201085 2009-12-28 02:17:15Z kientzle $
+ *
+ * Borrowed from FreeBSD's <sys/endian.h>
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+/* Note: This is a purely internal header! */
+/* Do not use this outside of libarchive internal code! */
+
+#ifndef ARCHIVE_ENDIAN_H_INCLUDED
+#define ARCHIVE_ENDIAN_H_INCLUDED
+
+
+/*
+ * Disabling inline keyword for compilers known to choke on it:
+ * - Watcom C++ in C code. (For any version?)
+ * - SGI MIPSpro
+ * - Microsoft Visual C++ 6.0 (supposedly newer versions too)
+ * - IBM VisualAge 6 (XL v6)
+ * - Sun WorkShop C (SunPro) before 5.9
+ */
+#if defined(__WATCOMC__) || defined(__sgi) || defined(__hpux) || defined(__BORLANDC__)
+#define inline
+#elif defined(__IBMC__) && __IBMC__ < 700
+#define inline
+#elif defined(__SUNPRO_C) && __SUNPRO_C < 0x590
+#define inline
+#elif defined(_MSC_VER) || defined(__osf__)
+#define inline __inline
+#endif
+
+/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
+
+static inline uint16_t
+archive_be16dec(const void *pp)
+{
+ unsigned char const *p = (unsigned char const *)pp;
+
+ /* Store into unsigned temporaries before left shifting, to avoid
+ promotion to signed int and then left shifting into the sign bit,
+ which is undefined behaviour. */
+ unsigned int p1 = p[1];
+ unsigned int p0 = p[0];
+
+ return ((p0 << 8) | p1);
+}
+
+static inline uint32_t
+archive_be32dec(const void *pp)
+{
+ unsigned char const *p = (unsigned char const *)pp;
+
+ /* Store into unsigned temporaries before left shifting, to avoid
+ promotion to signed int and then left shifting into the sign bit,
+ which is undefined behaviour. */
+ unsigned int p3 = p[3];
+ unsigned int p2 = p[2];
+ unsigned int p1 = p[1];
+ unsigned int p0 = p[0];
+
+ return ((p0 << 24) | (p1 << 16) | (p2 << 8) | p3);
+}
+
+static inline uint64_t
+archive_be64dec(const void *pp)
+{
+ unsigned char const *p = (unsigned char const *)pp;
+
+ return (((uint64_t)archive_be32dec(p) << 32) | archive_be32dec(p + 4));
+}
+
+static inline uint16_t
+archive_le16dec(const void *pp)
+{
+ unsigned char const *p = (unsigned char const *)pp;
+
+ /* Store into unsigned temporaries before left shifting, to avoid
+ promotion to signed int and then left shifting into the sign bit,
+ which is undefined behaviour. */
+ unsigned int p1 = p[1];
+ unsigned int p0 = p[0];
+
+ return ((p1 << 8) | p0);
+}
+
+static inline uint32_t
+archive_le32dec(const void *pp)
+{
+ unsigned char const *p = (unsigned char const *)pp;
+
+ /* Store into unsigned temporaries before left shifting, to avoid
+ promotion to signed int and then left shifting into the sign bit,
+ which is undefined behaviour. */
+ unsigned int p3 = p[3];
+ unsigned int p2 = p[2];
+ unsigned int p1 = p[1];
+ unsigned int p0 = p[0];
+
+ return ((p3 << 24) | (p2 << 16) | (p1 << 8) | p0);
+}
+
+static inline uint64_t
+archive_le64dec(const void *pp)
+{
+ unsigned char const *p = (unsigned char const *)pp;
+
+ return (((uint64_t)archive_le32dec(p + 4) << 32) | archive_le32dec(p));
+}
+
+static inline void
+archive_be16enc(void *pp, uint16_t u)
+{
+ unsigned char *p = (unsigned char *)pp;
+
+ p[0] = (u >> 8) & 0xff;
+ p[1] = u & 0xff;
+}
+
+static inline void
+archive_be32enc(void *pp, uint32_t u)
+{
+ unsigned char *p = (unsigned char *)pp;
+
+ p[0] = (u >> 24) & 0xff;
+ p[1] = (u >> 16) & 0xff;
+ p[2] = (u >> 8) & 0xff;
+ p[3] = u & 0xff;
+}
+
+static inline void
+archive_be64enc(void *pp, uint64_t u)
+{
+ unsigned char *p = (unsigned char *)pp;
+
+ archive_be32enc(p, (uint32_t)(u >> 32));
+ archive_be32enc(p + 4, (uint32_t)(u & 0xffffffff));
+}
+
+static inline void
+archive_le16enc(void *pp, uint16_t u)
+{
+ unsigned char *p = (unsigned char *)pp;
+
+ p[0] = u & 0xff;
+ p[1] = (u >> 8) & 0xff;
+}
+
+static inline void
+archive_le32enc(void *pp, uint32_t u)
+{
+ unsigned char *p = (unsigned char *)pp;
+
+ p[0] = u & 0xff;
+ p[1] = (u >> 8) & 0xff;
+ p[2] = (u >> 16) & 0xff;
+ p[3] = (u >> 24) & 0xff;
+}
+
+static inline void
+archive_le64enc(void *pp, uint64_t u)
+{
+ unsigned char *p = (unsigned char *)pp;
+
+ archive_le32enc(p, (uint32_t)(u & 0xffffffff));
+ archive_le32enc(p + 4, (uint32_t)(u >> 32));
+}
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.3 b/Utilities/cmlibarchive/libarchive/archive_entry.3
new file mode 100644
index 0000000000..f77f385f2e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry.3
@@ -0,0 +1,150 @@
+.\" Copyright (c) 2003-2007 Tim Kientzle
+.\" Copyright (c) 2010 Joerg Sonnenberger
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd Feburary 2, 2012
+.Dt ARCHIVE_ENTRY 3
+.Os
+.Sh NAME
+.Nm archive_entry_clear ,
+.Nm archive_entry_clone ,
+.Nm archive_entry_free ,
+.Nm archive_entry_new ,
+.Nd functions for managing archive entry descriptions
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive_entry.h
+.Ft "struct archive_entry *"
+.Fn archive_entry_clear "struct archive_entry *"
+.Ft struct archive_entry *
+.Fn archive_entry_clone "struct archive_entry *"
+.Ft void
+.Fn archive_entry_free "struct archive_entry *"
+.Ft struct archive_entry *
+.Fn archive_entry_new "void"
+.Sh DESCRIPTION
+These functions create and manipulate data objects that
+represent entries within an archive.
+You can think of a
+.Tn struct archive_entry
+as a heavy-duty version of
+.Tn struct stat :
+it includes everything from
+.Tn struct stat
+plus associated pathname, textual group and user names, etc.
+These objects are used by
+.Xr libarchive 3
+to represent the metadata associated with a particular
+entry in an archive.
+.Ss Create and Destroy
+There are functions to allocate, destroy, clear, and copy
+.Va archive_entry
+objects:
+.Bl -tag -compact -width indent
+.It Fn archive_entry_clear
+Erases the object, resetting all internal fields to the
+same state as a newly-created object.
+This is provided to allow you to quickly recycle objects
+without thrashing the heap.
+.It Fn archive_entry_clone
+A deep copy operation; all text fields are duplicated.
+.It Fn archive_entry_free
+Releases the
+.Tn struct archive_entry
+object.
+.It Fn archive_entry_new
+Allocate and return a blank
+.Tn struct archive_entry
+object.
+.El
+.Ss Function groups
+Due to high number of functions, the accessor functions can be found in
+man pages grouped by the purpose.
+.Bl -tag -width ".Xr archive_entry_perms 3"
+.It Xr archive_entry_acl 3
+Access Control List manipulation
+.It Xr archive_entry_paths 3
+Path name manipulation
+.It Xr archive_entry_perms 3
+User, group and mode manipulation
+.It Xr archive_entry_stat 3
+Functions not in the other groups and copying to/from
+.Vt struct stat .
+.It Xr archive_entry_time 3
+Time field manipulation
+.El
+.Pp
+Most of the functions set or read entries in an object.
+Such functions have one of the following forms:
+.Bl -tag -compact -width indent
+.It Fn archive_entry_set_XXXX
+Stores the provided data in the object.
+In particular, for strings, the pointer is stored,
+not the referenced string.
+.It Fn archive_entry_copy_XXXX
+As above, except that the referenced data is copied
+into the object.
+.It Fn archive_entry_XXXX
+Returns the specified data.
+In the case of strings, a const-qualified pointer to
+the string is returned.
+.El
+String data can be set or accessed as wide character strings
+or normal
+.Va char
+strings.
+The functions that use wide character strings are suffixed with
+.Cm _w .
+Note that these are different representations of the same data:
+For example, if you store a narrow string and read the corresponding
+wide string, the object will transparently convert formats
+using the current locale.
+Similarly, if you store a wide string and then store a
+narrow string for the same data, the previously-set wide string will
+be discarded in favor of the new data.
+.Pp
+.\" .Sh EXAMPLE
+.\" .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
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libarchive
+library was written by
+.An Tim Kientzle Aq kientzle@acm.org .
+.\" .Sh BUGS
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.c b/Utilities/cmlibarchive/libarchive/archive_entry.c
new file mode 100644
index 0000000000..293c7016a8
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry.c
@@ -0,0 +1,1753 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_entry.c 201096 2009-12-28 02:41:27Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if MAJOR_IN_MKDEV
+#include <sys/mkdev.h>
+#define HAVE_MAJOR
+#elif MAJOR_IN_SYSMACROS
+#include <sys/sysmacros.h>
+#define HAVE_MAJOR
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_LINUX_FS_H
+#include <linux/fs.h> /* for Linux file flags */
+#endif
+/*
+ * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
+ * As the include guards don't agree, the order of include is important.
+ */
+#ifdef HAVE_LINUX_EXT2_FS_H
+#include <linux/ext2_fs.h> /* for Linux file flags */
+#endif
+#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
+#include <ext2fs/ext2_fs.h> /* for Linux file flags */
+#endif
+#include <stddef.h>
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+
+#include "archive.h"
+#include "archive_acl_private.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_entry_private.h"
+
+#if !defined(HAVE_MAJOR) && !defined(major)
+/* Replacement for major/minor/makedev. */
+#define major(x) ((int)(0x00ff & ((x) >> 8)))
+#define minor(x) ((int)(0xffff00ff & (x)))
+#define makedev(maj,min) ((0xff00 & ((maj)<<8)) | (0xffff00ff & (min)))
+#endif
+
+/* Play games to come up with a suitable makedev() definition. */
+#ifdef __QNXNTO__
+/* QNX. <sigh> */
+#include <sys/netmgr.h>
+#define ae_makedev(maj, min) makedev(ND_LOCAL_NODE, (maj), (min))
+#elif defined makedev
+/* There's a "makedev" macro. */
+#define ae_makedev(maj, min) makedev((maj), (min))
+#elif defined mkdev || ((defined _WIN32 || defined __WIN32__) && !defined(__CYGWIN__))
+/* Windows. <sigh> */
+#define ae_makedev(maj, min) mkdev((maj), (min))
+#else
+/* There's a "makedev" function. */
+#define ae_makedev(maj, min) makedev((maj), (min))
+#endif
+
+/*
+ * This adjustment is needed to support the following idiom for adding
+ * 1000ns to the stored time:
+ * archive_entry_set_atime(archive_entry_atime(),
+ * archive_entry_atime_nsec() + 1000)
+ * The additional if() here compensates for ambiguity in the C standard,
+ * which permits two possible interpretations of a % b when a is negative.
+ */
+#define FIX_NS(t,ns) \
+ do { \
+ t += ns / 1000000000; \
+ ns %= 1000000000; \
+ if (ns < 0) { --t; ns += 1000000000; } \
+ } while (0)
+
+static char * ae_fflagstostr(unsigned long bitset, unsigned long bitclear);
+static const wchar_t *ae_wcstofflags(const wchar_t *stringp,
+ unsigned long *setp, unsigned long *clrp);
+static const char *ae_strtofflags(const char *stringp,
+ unsigned long *setp, unsigned long *clrp);
+
+#ifndef HAVE_WCSCPY
+static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2)
+{
+ wchar_t *dest = s1;
+ while ((*s1 = *s2) != L'\0')
+ ++s1, ++s2;
+ return dest;
+}
+#endif
+#ifndef HAVE_WCSLEN
+static size_t wcslen(const wchar_t *s)
+{
+ const wchar_t *p = s;
+ while (*p != L'\0')
+ ++p;
+ return p - s;
+}
+#endif
+#ifndef HAVE_WMEMCMP
+/* Good enough for simple equality testing, but not for sorting. */
+#define wmemcmp(a,b,i) memcmp((a), (b), (i) * sizeof(wchar_t))
+#endif
+
+/****************************************************************************
+ *
+ * Public Interface
+ *
+ ****************************************************************************/
+
+struct archive_entry *
+archive_entry_clear(struct archive_entry *entry)
+{
+ if (entry == NULL)
+ return (NULL);
+ archive_mstring_clean(&entry->ae_fflags_text);
+ archive_mstring_clean(&entry->ae_gname);
+ archive_mstring_clean(&entry->ae_hardlink);
+ archive_mstring_clean(&entry->ae_pathname);
+ archive_mstring_clean(&entry->ae_sourcepath);
+ archive_mstring_clean(&entry->ae_symlink);
+ archive_mstring_clean(&entry->ae_uname);
+ archive_entry_copy_mac_metadata(entry, NULL, 0);
+ archive_acl_clear(&entry->acl);
+ archive_entry_xattr_clear(entry);
+ archive_entry_sparse_clear(entry);
+ free(entry->stat);
+ memset(entry, 0, sizeof(*entry));
+ return entry;
+}
+
+struct archive_entry *
+archive_entry_clone(struct archive_entry *entry)
+{
+ struct archive_entry *entry2;
+ struct ae_xattr *xp;
+ struct ae_sparse *sp;
+ size_t s;
+ const void *p;
+
+ /* Allocate new structure and copy over all of the fields. */
+ /* TODO: Should we copy the archive over? Or require a new archive
+ * as an argument? */
+ entry2 = archive_entry_new2(entry->archive);
+ if (entry2 == NULL)
+ return (NULL);
+ entry2->ae_stat = entry->ae_stat;
+ entry2->ae_fflags_set = entry->ae_fflags_set;
+ entry2->ae_fflags_clear = entry->ae_fflags_clear;
+
+ /* TODO: XXX If clone can have a different archive, what do we do here if
+ * character sets are different? XXX */
+ archive_mstring_copy(&entry2->ae_fflags_text, &entry->ae_fflags_text);
+ archive_mstring_copy(&entry2->ae_gname, &entry->ae_gname);
+ archive_mstring_copy(&entry2->ae_hardlink, &entry->ae_hardlink);
+ archive_mstring_copy(&entry2->ae_pathname, &entry->ae_pathname);
+ archive_mstring_copy(&entry2->ae_sourcepath, &entry->ae_sourcepath);
+ archive_mstring_copy(&entry2->ae_symlink, &entry->ae_symlink);
+ entry2->ae_set = entry->ae_set;
+ archive_mstring_copy(&entry2->ae_uname, &entry->ae_uname);
+
+ /* Copy encryption status */
+ entry2->encryption = entry->encryption;
+
+ /* Copy ACL data over. */
+ archive_acl_copy(&entry2->acl, &entry->acl);
+
+ /* Copy Mac OS metadata. */
+ p = archive_entry_mac_metadata(entry, &s);
+ archive_entry_copy_mac_metadata(entry2, p, s);
+
+ /* Copy xattr data over. */
+ xp = entry->xattr_head;
+ while (xp != NULL) {
+ archive_entry_xattr_add_entry(entry2,
+ xp->name, xp->value, xp->size);
+ xp = xp->next;
+ }
+
+ /* Copy sparse data over. */
+ sp = entry->sparse_head;
+ while (sp != NULL) {
+ archive_entry_sparse_add_entry(entry2,
+ sp->offset, sp->length);
+ sp = sp->next;
+ }
+
+ return (entry2);
+}
+
+void
+archive_entry_free(struct archive_entry *entry)
+{
+ archive_entry_clear(entry);
+ free(entry);
+}
+
+struct archive_entry *
+archive_entry_new(void)
+{
+ return archive_entry_new2(NULL);
+}
+
+struct archive_entry *
+archive_entry_new2(struct archive *a)
+{
+ struct archive_entry *entry;
+
+ entry = (struct archive_entry *)malloc(sizeof(*entry));
+ if (entry == NULL)
+ return (NULL);
+ memset(entry, 0, sizeof(*entry));
+ entry->archive = a;
+ return (entry);
+}
+
+/*
+ * Functions for reading fields from an archive_entry.
+ */
+
+time_t
+archive_entry_atime(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_atime);
+}
+
+long
+archive_entry_atime_nsec(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_atime_nsec);
+}
+
+int
+archive_entry_atime_is_set(struct archive_entry *entry)
+{
+ return (entry->ae_set & AE_SET_ATIME);
+}
+
+time_t
+archive_entry_birthtime(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_birthtime);
+}
+
+long
+archive_entry_birthtime_nsec(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_birthtime_nsec);
+}
+
+int
+archive_entry_birthtime_is_set(struct archive_entry *entry)
+{
+ return (entry->ae_set & AE_SET_BIRTHTIME);
+}
+
+time_t
+archive_entry_ctime(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_ctime);
+}
+
+int
+archive_entry_ctime_is_set(struct archive_entry *entry)
+{
+ return (entry->ae_set & AE_SET_CTIME);
+}
+
+long
+archive_entry_ctime_nsec(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_ctime_nsec);
+}
+
+dev_t
+archive_entry_dev(struct archive_entry *entry)
+{
+ if (entry->ae_stat.aest_dev_is_broken_down)
+ return ae_makedev(entry->ae_stat.aest_devmajor,
+ entry->ae_stat.aest_devminor);
+ else
+ return (entry->ae_stat.aest_dev);
+}
+
+int
+archive_entry_dev_is_set(struct archive_entry *entry)
+{
+ return (entry->ae_set & AE_SET_DEV);
+}
+
+dev_t
+archive_entry_devmajor(struct archive_entry *entry)
+{
+ if (entry->ae_stat.aest_dev_is_broken_down)
+ return (entry->ae_stat.aest_devmajor);
+ else
+ return major(entry->ae_stat.aest_dev);
+}
+
+dev_t
+archive_entry_devminor(struct archive_entry *entry)
+{
+ if (entry->ae_stat.aest_dev_is_broken_down)
+ return (entry->ae_stat.aest_devminor);
+ else
+ return minor(entry->ae_stat.aest_dev);
+}
+
+mode_t
+archive_entry_filetype(struct archive_entry *entry)
+{
+ return (AE_IFMT & entry->acl.mode);
+}
+
+void
+archive_entry_fflags(struct archive_entry *entry,
+ unsigned long *set, unsigned long *clear)
+{
+ *set = entry->ae_fflags_set;
+ *clear = entry->ae_fflags_clear;
+}
+
+/*
+ * Note: if text was provided, this just returns that text. If you
+ * really need the text to be rebuilt in a canonical form, set the
+ * text, ask for the bitmaps, then set the bitmaps. (Setting the
+ * bitmaps clears any stored text.) This design is deliberate: if
+ * we're editing archives, we don't want to discard flags just because
+ * they aren't supported on the current system. The bitmap<->text
+ * conversions are platform-specific (see below).
+ */
+const char *
+archive_entry_fflags_text(struct archive_entry *entry)
+{
+ const char *f;
+ char *p;
+
+ if (archive_mstring_get_mbs(entry->archive,
+ &entry->ae_fflags_text, &f) == 0) {
+ if (f != NULL)
+ return (f);
+ } else if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+
+ if (entry->ae_fflags_set == 0 && entry->ae_fflags_clear == 0)
+ return (NULL);
+
+ p = ae_fflagstostr(entry->ae_fflags_set, entry->ae_fflags_clear);
+ if (p == NULL)
+ return (NULL);
+
+ archive_mstring_copy_mbs(&entry->ae_fflags_text, p);
+ free(p);
+ if (archive_mstring_get_mbs(entry->archive,
+ &entry->ae_fflags_text, &f) == 0)
+ return (f);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (NULL);
+}
+
+int64_t
+archive_entry_gid(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_gid);
+}
+
+const char *
+archive_entry_gname(struct archive_entry *entry)
+{
+ const char *p;
+ if (archive_mstring_get_mbs(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)
+{
+ const wchar_t *p;
+ if (archive_mstring_get_wcs(entry->archive, &entry->ae_gname, &p) == 0)
+ return (p);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (NULL);
+}
+
+int
+_archive_entry_gname_l(struct archive_entry *entry,
+ const char **p, size_t *len, struct archive_string_conv *sc)
+{
+ return (archive_mstring_get_mbs_l(&entry->ae_gname, p, len, sc));
+}
+
+const char *
+archive_entry_hardlink(struct archive_entry *entry)
+{
+ const char *p;
+ if ((entry->ae_set & AE_SET_HARDLINK) == 0)
+ return (NULL);
+ if (archive_mstring_get_mbs(
+ 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)
+{
+ const wchar_t *p;
+ if ((entry->ae_set & AE_SET_HARDLINK) == 0)
+ return (NULL);
+ if (archive_mstring_get_wcs(
+ entry->archive, &entry->ae_hardlink, &p) == 0)
+ return (p);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (NULL);
+}
+
+int
+_archive_entry_hardlink_l(struct archive_entry *entry,
+ const char **p, size_t *len, struct archive_string_conv *sc)
+{
+ if ((entry->ae_set & AE_SET_HARDLINK) == 0) {
+ *p = NULL;
+ *len = 0;
+ return (0);
+ }
+ return (archive_mstring_get_mbs_l(&entry->ae_hardlink, p, len, sc));
+}
+
+int64_t
+archive_entry_ino(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_ino);
+}
+
+int
+archive_entry_ino_is_set(struct archive_entry *entry)
+{
+ return (entry->ae_set & AE_SET_INO);
+}
+
+int64_t
+archive_entry_ino64(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_ino);
+}
+
+mode_t
+archive_entry_mode(struct archive_entry *entry)
+{
+ return (entry->acl.mode);
+}
+
+time_t
+archive_entry_mtime(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_mtime);
+}
+
+long
+archive_entry_mtime_nsec(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_mtime_nsec);
+}
+
+int
+archive_entry_mtime_is_set(struct archive_entry *entry)
+{
+ return (entry->ae_set & AE_SET_MTIME);
+}
+
+unsigned int
+archive_entry_nlink(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_nlink);
+}
+
+const char *
+archive_entry_pathname(struct archive_entry *entry)
+{
+ const char *p;
+ if (archive_mstring_get_mbs(
+ 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)
+{
+ const wchar_t *p;
+ if (archive_mstring_get_wcs(
+ entry->archive, &entry->ae_pathname, &p) == 0)
+ return (p);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (NULL);
+}
+
+int
+_archive_entry_pathname_l(struct archive_entry *entry,
+ const char **p, size_t *len, struct archive_string_conv *sc)
+{
+ return (archive_mstring_get_mbs_l(&entry->ae_pathname, p, len, sc));
+}
+
+mode_t
+archive_entry_perm(struct archive_entry *entry)
+{
+ return (~AE_IFMT & entry->acl.mode);
+}
+
+dev_t
+archive_entry_rdev(struct archive_entry *entry)
+{
+ if (entry->ae_stat.aest_rdev_is_broken_down)
+ return ae_makedev(entry->ae_stat.aest_rdevmajor,
+ entry->ae_stat.aest_rdevminor);
+ else
+ return (entry->ae_stat.aest_rdev);
+}
+
+dev_t
+archive_entry_rdevmajor(struct archive_entry *entry)
+{
+ if (entry->ae_stat.aest_rdev_is_broken_down)
+ return (entry->ae_stat.aest_rdevmajor);
+ else
+ return major(entry->ae_stat.aest_rdev);
+}
+
+dev_t
+archive_entry_rdevminor(struct archive_entry *entry)
+{
+ if (entry->ae_stat.aest_rdev_is_broken_down)
+ return (entry->ae_stat.aest_rdevminor);
+ else
+ return minor(entry->ae_stat.aest_rdev);
+}
+
+int64_t
+archive_entry_size(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_size);
+}
+
+int
+archive_entry_size_is_set(struct archive_entry *entry)
+{
+ return (entry->ae_set & AE_SET_SIZE);
+}
+
+const char *
+archive_entry_sourcepath(struct archive_entry *entry)
+{
+ const char *p;
+ if (archive_mstring_get_mbs(
+ entry->archive, &entry->ae_sourcepath, &p) == 0)
+ return (p);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (NULL);
+}
+
+const wchar_t *
+archive_entry_sourcepath_w(struct archive_entry *entry)
+{
+ const wchar_t *p;
+ if (archive_mstring_get_wcs(
+ entry->archive, &entry->ae_sourcepath, &p) == 0)
+ return (p);
+ return (NULL);
+}
+
+const char *
+archive_entry_symlink(struct archive_entry *entry)
+{
+ const char *p;
+ if ((entry->ae_set & AE_SET_SYMLINK) == 0)
+ return (NULL);
+ if (archive_mstring_get_mbs(
+ 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)
+{
+ const wchar_t *p;
+ if ((entry->ae_set & AE_SET_SYMLINK) == 0)
+ return (NULL);
+ if (archive_mstring_get_wcs(
+ entry->archive, &entry->ae_symlink, &p) == 0)
+ return (p);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (NULL);
+}
+
+int
+_archive_entry_symlink_l(struct archive_entry *entry,
+ const char **p, size_t *len, struct archive_string_conv *sc)
+{
+ if ((entry->ae_set & AE_SET_SYMLINK) == 0) {
+ *p = NULL;
+ *len = 0;
+ return (0);
+ }
+ return (archive_mstring_get_mbs_l( &entry->ae_symlink, p, len, sc));
+}
+
+int64_t
+archive_entry_uid(struct archive_entry *entry)
+{
+ return (entry->ae_stat.aest_uid);
+}
+
+const char *
+archive_entry_uname(struct archive_entry *entry)
+{
+ const char *p;
+ if (archive_mstring_get_mbs(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)
+{
+ const wchar_t *p;
+ if (archive_mstring_get_wcs(entry->archive, &entry->ae_uname, &p) == 0)
+ return (p);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (NULL);
+}
+
+int
+_archive_entry_uname_l(struct archive_entry *entry,
+ const char **p, size_t *len, struct archive_string_conv *sc)
+{
+ return (archive_mstring_get_mbs_l(&entry->ae_uname, p, len, sc));
+}
+
+int
+archive_entry_is_data_encrypted(struct archive_entry *entry)
+{
+ return ((entry->encryption & AE_ENCRYPTION_DATA) == AE_ENCRYPTION_DATA);
+}
+
+int
+archive_entry_is_metadata_encrypted(struct archive_entry *entry)
+{
+ return ((entry->encryption & AE_ENCRYPTION_METADATA) == AE_ENCRYPTION_METADATA);
+}
+
+int
+archive_entry_is_encrypted(struct archive_entry *entry)
+{
+ return (entry->encryption & (AE_ENCRYPTION_DATA|AE_ENCRYPTION_METADATA));
+}
+
+/*
+ * Functions to set archive_entry properties.
+ */
+
+void
+archive_entry_set_filetype(struct archive_entry *entry, unsigned int type)
+{
+ entry->stat_valid = 0;
+ entry->acl.mode &= ~AE_IFMT;
+ entry->acl.mode |= AE_IFMT & type;
+}
+
+void
+archive_entry_set_fflags(struct archive_entry *entry,
+ unsigned long set, unsigned long clear)
+{
+ archive_mstring_clean(&entry->ae_fflags_text);
+ entry->ae_fflags_set = set;
+ entry->ae_fflags_clear = clear;
+}
+
+const char *
+archive_entry_copy_fflags_text(struct archive_entry *entry,
+ const char *flags)
+{
+ archive_mstring_copy_mbs(&entry->ae_fflags_text, flags);
+ return (ae_strtofflags(flags,
+ &entry->ae_fflags_set, &entry->ae_fflags_clear));
+}
+
+const wchar_t *
+archive_entry_copy_fflags_text_w(struct archive_entry *entry,
+ const wchar_t *flags)
+{
+ archive_mstring_copy_wcs(&entry->ae_fflags_text, flags);
+ return (ae_wcstofflags(flags,
+ &entry->ae_fflags_set, &entry->ae_fflags_clear));
+}
+
+void
+archive_entry_set_gid(struct archive_entry *entry, int64_t g)
+{
+ entry->stat_valid = 0;
+ entry->ae_stat.aest_gid = g;
+}
+
+void
+archive_entry_set_gname(struct archive_entry *entry, const char *name)
+{
+ archive_mstring_copy_mbs(&entry->ae_gname, name);
+}
+
+void
+archive_entry_copy_gname(struct archive_entry *entry, const char *name)
+{
+ archive_mstring_copy_mbs(&entry->ae_gname, name);
+}
+
+void
+archive_entry_copy_gname_w(struct archive_entry *entry, const wchar_t *name)
+{
+ archive_mstring_copy_wcs(&entry->ae_gname, name);
+}
+
+int
+archive_entry_update_gname_utf8(struct archive_entry *entry, const char *name)
+{
+ if (archive_mstring_update_utf8(entry->archive,
+ &entry->ae_gname, name) == 0)
+ return (1);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (0);
+}
+
+int
+_archive_entry_copy_gname_l(struct archive_entry *entry,
+ const char *name, size_t len, struct archive_string_conv *sc)
+{
+ return (archive_mstring_copy_mbs_len_l(&entry->ae_gname, name, len, sc));
+}
+
+void
+archive_entry_set_ino(struct archive_entry *entry, int64_t ino)
+{
+ entry->stat_valid = 0;
+ entry->ae_set |= AE_SET_INO;
+ entry->ae_stat.aest_ino = ino;
+}
+
+void
+archive_entry_set_ino64(struct archive_entry *entry, int64_t ino)
+{
+ entry->stat_valid = 0;
+ entry->ae_set |= AE_SET_INO;
+ entry->ae_stat.aest_ino = ino;
+}
+
+void
+archive_entry_set_hardlink(struct archive_entry *entry, const char *target)
+{
+ archive_mstring_copy_mbs(&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);
+ if (target != NULL)
+ entry->ae_set |= AE_SET_HARDLINK;
+ else
+ entry->ae_set &= ~AE_SET_HARDLINK;
+}
+
+void
+archive_entry_copy_hardlink_w(struct archive_entry *entry, const wchar_t *target)
+{
+ archive_mstring_copy_wcs(&entry->ae_hardlink, target);
+ if (target != NULL)
+ entry->ae_set |= AE_SET_HARDLINK;
+ else
+ entry->ae_set &= ~AE_SET_HARDLINK;
+}
+
+int
+archive_entry_update_hardlink_utf8(struct archive_entry *entry, const char *target)
+{
+ if (target != NULL)
+ entry->ae_set |= AE_SET_HARDLINK;
+ else
+ entry->ae_set &= ~AE_SET_HARDLINK;
+ if (archive_mstring_update_utf8(entry->archive,
+ &entry->ae_hardlink, target) == 0)
+ return (1);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (0);
+}
+
+int
+_archive_entry_copy_hardlink_l(struct archive_entry *entry,
+ const char *target, size_t len, struct archive_string_conv *sc)
+{
+ int r;
+
+ r = archive_mstring_copy_mbs_len_l(&entry->ae_hardlink,
+ target, len, sc);
+ if (target != NULL && r == 0)
+ entry->ae_set |= AE_SET_HARDLINK;
+ else
+ entry->ae_set &= ~AE_SET_HARDLINK;
+ return (r);
+}
+
+void
+archive_entry_set_atime(struct archive_entry *entry, time_t t, long ns)
+{
+ FIX_NS(t, ns);
+ entry->stat_valid = 0;
+ entry->ae_set |= AE_SET_ATIME;
+ entry->ae_stat.aest_atime = t;
+ entry->ae_stat.aest_atime_nsec = ns;
+}
+
+void
+archive_entry_unset_atime(struct archive_entry *entry)
+{
+ archive_entry_set_atime(entry, 0, 0);
+ entry->ae_set &= ~AE_SET_ATIME;
+}
+
+void
+archive_entry_set_birthtime(struct archive_entry *entry, time_t t, long ns)
+{
+ FIX_NS(t, ns);
+ entry->stat_valid = 0;
+ entry->ae_set |= AE_SET_BIRTHTIME;
+ entry->ae_stat.aest_birthtime = t;
+ entry->ae_stat.aest_birthtime_nsec = ns;
+}
+
+void
+archive_entry_unset_birthtime(struct archive_entry *entry)
+{
+ archive_entry_set_birthtime(entry, 0, 0);
+ entry->ae_set &= ~AE_SET_BIRTHTIME;
+}
+
+void
+archive_entry_set_ctime(struct archive_entry *entry, time_t t, long ns)
+{
+ FIX_NS(t, ns);
+ entry->stat_valid = 0;
+ entry->ae_set |= AE_SET_CTIME;
+ entry->ae_stat.aest_ctime = t;
+ entry->ae_stat.aest_ctime_nsec = ns;
+}
+
+void
+archive_entry_unset_ctime(struct archive_entry *entry)
+{
+ archive_entry_set_ctime(entry, 0, 0);
+ entry->ae_set &= ~AE_SET_CTIME;
+}
+
+void
+archive_entry_set_dev(struct archive_entry *entry, dev_t d)
+{
+ entry->stat_valid = 0;
+ entry->ae_set |= AE_SET_DEV;
+ entry->ae_stat.aest_dev_is_broken_down = 0;
+ entry->ae_stat.aest_dev = d;
+}
+
+void
+archive_entry_set_devmajor(struct archive_entry *entry, dev_t m)
+{
+ entry->stat_valid = 0;
+ entry->ae_set |= AE_SET_DEV;
+ entry->ae_stat.aest_dev_is_broken_down = 1;
+ entry->ae_stat.aest_devmajor = m;
+}
+
+void
+archive_entry_set_devminor(struct archive_entry *entry, dev_t m)
+{
+ entry->stat_valid = 0;
+ entry->ae_set |= AE_SET_DEV;
+ entry->ae_stat.aest_dev_is_broken_down = 1;
+ entry->ae_stat.aest_devminor = m;
+}
+
+/* Set symlink if symlink is already set, else set hardlink. */
+void
+archive_entry_set_link(struct archive_entry *entry, const char *target)
+{
+ if (entry->ae_set & AE_SET_SYMLINK)
+ archive_mstring_copy_mbs(&entry->ae_symlink, target);
+ else
+ archive_mstring_copy_mbs(&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)
+{
+ if (entry->ae_set & AE_SET_SYMLINK)
+ archive_mstring_copy_mbs(&entry->ae_symlink, target);
+ else
+ archive_mstring_copy_mbs(&entry->ae_hardlink, target);
+}
+
+/* Set symlink if symlink is already set, else set hardlink. */
+void
+archive_entry_copy_link_w(struct archive_entry *entry, const wchar_t *target)
+{
+ if (entry->ae_set & AE_SET_SYMLINK)
+ archive_mstring_copy_wcs(&entry->ae_symlink, target);
+ else
+ archive_mstring_copy_wcs(&entry->ae_hardlink, target);
+}
+
+int
+archive_entry_update_link_utf8(struct archive_entry *entry, const char *target)
+{
+ int r;
+ if (entry->ae_set & AE_SET_SYMLINK)
+ r = archive_mstring_update_utf8(entry->archive,
+ &entry->ae_symlink, target);
+ else
+ r = archive_mstring_update_utf8(entry->archive,
+ &entry->ae_hardlink, target);
+ if (r == 0)
+ return (1);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (0);
+}
+
+int
+_archive_entry_copy_link_l(struct archive_entry *entry,
+ const char *target, size_t len, struct archive_string_conv *sc)
+{
+ int r;
+
+ if (entry->ae_set & AE_SET_SYMLINK)
+ r = archive_mstring_copy_mbs_len_l(&entry->ae_symlink,
+ target, len, sc);
+ else
+ r = archive_mstring_copy_mbs_len_l(&entry->ae_hardlink,
+ target, len, sc);
+ return (r);
+}
+
+void
+archive_entry_set_mode(struct archive_entry *entry, mode_t m)
+{
+ entry->stat_valid = 0;
+ entry->acl.mode = m;
+}
+
+void
+archive_entry_set_mtime(struct archive_entry *entry, time_t t, long ns)
+{
+ FIX_NS(t, ns);
+ entry->stat_valid = 0;
+ entry->ae_set |= AE_SET_MTIME;
+ entry->ae_stat.aest_mtime = t;
+ entry->ae_stat.aest_mtime_nsec = ns;
+}
+
+void
+archive_entry_unset_mtime(struct archive_entry *entry)
+{
+ archive_entry_set_mtime(entry, 0, 0);
+ entry->ae_set &= ~AE_SET_MTIME;
+}
+
+void
+archive_entry_set_nlink(struct archive_entry *entry, unsigned int nlink)
+{
+ entry->stat_valid = 0;
+ entry->ae_stat.aest_nlink = nlink;
+}
+
+void
+archive_entry_set_pathname(struct archive_entry *entry, const char *name)
+{
+ archive_mstring_copy_mbs(&entry->ae_pathname, name);
+}
+
+void
+archive_entry_copy_pathname(struct archive_entry *entry, const char *name)
+{
+ archive_mstring_copy_mbs(&entry->ae_pathname, name);
+}
+
+void
+archive_entry_copy_pathname_w(struct archive_entry *entry, const wchar_t *name)
+{
+ archive_mstring_copy_wcs(&entry->ae_pathname, name);
+}
+
+int
+archive_entry_update_pathname_utf8(struct archive_entry *entry, const char *name)
+{
+ if (archive_mstring_update_utf8(entry->archive,
+ &entry->ae_pathname, name) == 0)
+ return (1);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (0);
+}
+
+int
+_archive_entry_copy_pathname_l(struct archive_entry *entry,
+ const char *name, size_t len, struct archive_string_conv *sc)
+{
+ return (archive_mstring_copy_mbs_len_l(&entry->ae_pathname,
+ name, len, sc));
+}
+
+void
+archive_entry_set_perm(struct archive_entry *entry, mode_t p)
+{
+ entry->stat_valid = 0;
+ entry->acl.mode &= AE_IFMT;
+ entry->acl.mode |= ~AE_IFMT & p;
+}
+
+void
+archive_entry_set_rdev(struct archive_entry *entry, dev_t m)
+{
+ entry->stat_valid = 0;
+ entry->ae_stat.aest_rdev = m;
+ entry->ae_stat.aest_rdev_is_broken_down = 0;
+}
+
+void
+archive_entry_set_rdevmajor(struct archive_entry *entry, dev_t m)
+{
+ entry->stat_valid = 0;
+ entry->ae_stat.aest_rdev_is_broken_down = 1;
+ entry->ae_stat.aest_rdevmajor = m;
+}
+
+void
+archive_entry_set_rdevminor(struct archive_entry *entry, dev_t m)
+{
+ entry->stat_valid = 0;
+ entry->ae_stat.aest_rdev_is_broken_down = 1;
+ entry->ae_stat.aest_rdevminor = m;
+}
+
+void
+archive_entry_set_size(struct archive_entry *entry, int64_t s)
+{
+ entry->stat_valid = 0;
+ entry->ae_stat.aest_size = s;
+ entry->ae_set |= AE_SET_SIZE;
+}
+
+void
+archive_entry_unset_size(struct archive_entry *entry)
+{
+ archive_entry_set_size(entry, 0);
+ entry->ae_set &= ~AE_SET_SIZE;
+}
+
+void
+archive_entry_copy_sourcepath(struct archive_entry *entry, const char *path)
+{
+ archive_mstring_copy_mbs(&entry->ae_sourcepath, path);
+}
+
+void
+archive_entry_copy_sourcepath_w(struct archive_entry *entry, const wchar_t *path)
+{
+ archive_mstring_copy_wcs(&entry->ae_sourcepath, path);
+}
+
+void
+archive_entry_set_symlink(struct archive_entry *entry, const char *linkname)
+{
+ archive_mstring_copy_mbs(&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);
+ if (linkname != NULL)
+ entry->ae_set |= AE_SET_SYMLINK;
+ else
+ entry->ae_set &= ~AE_SET_SYMLINK;
+}
+
+void
+archive_entry_copy_symlink_w(struct archive_entry *entry, const wchar_t *linkname)
+{
+ archive_mstring_copy_wcs(&entry->ae_symlink, linkname);
+ if (linkname != NULL)
+ entry->ae_set |= AE_SET_SYMLINK;
+ else
+ entry->ae_set &= ~AE_SET_SYMLINK;
+}
+
+int
+archive_entry_update_symlink_utf8(struct archive_entry *entry, const char *linkname)
+{
+ if (linkname != NULL)
+ entry->ae_set |= AE_SET_SYMLINK;
+ else
+ entry->ae_set &= ~AE_SET_SYMLINK;
+ if (archive_mstring_update_utf8(entry->archive,
+ &entry->ae_symlink, linkname) == 0)
+ return (1);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (0);
+}
+
+int
+_archive_entry_copy_symlink_l(struct archive_entry *entry,
+ const char *linkname, size_t len, struct archive_string_conv *sc)
+{
+ int r;
+
+ r = archive_mstring_copy_mbs_len_l(&entry->ae_symlink,
+ linkname, len, sc);
+ if (linkname != NULL && r == 0)
+ entry->ae_set |= AE_SET_SYMLINK;
+ else
+ entry->ae_set &= ~AE_SET_SYMLINK;
+ return (r);
+}
+
+void
+archive_entry_set_uid(struct archive_entry *entry, int64_t u)
+{
+ entry->stat_valid = 0;
+ entry->ae_stat.aest_uid = u;
+}
+
+void
+archive_entry_set_uname(struct archive_entry *entry, const char *name)
+{
+ archive_mstring_copy_mbs(&entry->ae_uname, name);
+}
+
+void
+archive_entry_copy_uname(struct archive_entry *entry, const char *name)
+{
+ archive_mstring_copy_mbs(&entry->ae_uname, name);
+}
+
+void
+archive_entry_copy_uname_w(struct archive_entry *entry, const wchar_t *name)
+{
+ archive_mstring_copy_wcs(&entry->ae_uname, name);
+}
+
+int
+archive_entry_update_uname_utf8(struct archive_entry *entry, const char *name)
+{
+ if (archive_mstring_update_utf8(entry->archive,
+ &entry->ae_uname, name) == 0)
+ return (1);
+ if (errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (0);
+}
+
+void
+archive_entry_set_is_data_encrypted(struct archive_entry *entry, char is_encrypted)
+{
+ if (is_encrypted) {
+ entry->encryption |= AE_ENCRYPTION_DATA;
+ } else {
+ entry->encryption &= ~AE_ENCRYPTION_DATA;
+ }
+}
+
+void
+archive_entry_set_is_metadata_encrypted(struct archive_entry *entry, char is_encrypted)
+{
+ if (is_encrypted) {
+ entry->encryption |= AE_ENCRYPTION_METADATA;
+ } else {
+ entry->encryption &= ~AE_ENCRYPTION_METADATA;
+ }
+}
+
+int
+_archive_entry_copy_uname_l(struct archive_entry *entry,
+ const char *name, size_t len, struct archive_string_conv *sc)
+{
+ return (archive_mstring_copy_mbs_len_l(&entry->ae_uname,
+ name, len, sc));
+}
+
+const void *
+archive_entry_mac_metadata(struct archive_entry *entry, size_t *s)
+{
+ *s = entry->mac_metadata_size;
+ return entry->mac_metadata;
+}
+
+void
+archive_entry_copy_mac_metadata(struct archive_entry *entry,
+ const void *p, size_t s)
+{
+ free(entry->mac_metadata);
+ if (p == NULL || s == 0) {
+ entry->mac_metadata = NULL;
+ entry->mac_metadata_size = 0;
+ } else {
+ entry->mac_metadata_size = s;
+ entry->mac_metadata = malloc(s);
+ if (entry->mac_metadata == NULL)
+ abort();
+ memcpy(entry->mac_metadata, p, s);
+ }
+}
+
+/*
+ * ACL management. The following would, of course, be a lot simpler
+ * if: 1) the last draft of POSIX.1e were a really thorough and
+ * complete standard that addressed the needs of ACL archiving and 2)
+ * everyone followed it faithfully. Alas, neither is true, so the
+ * following is a lot more complex than might seem necessary to the
+ * uninitiated.
+ */
+
+struct archive_acl *
+archive_entry_acl(struct archive_entry *entry)
+{
+ return &entry->acl;
+}
+
+void
+archive_entry_acl_clear(struct archive_entry *entry)
+{
+ archive_acl_clear(&entry->acl);
+}
+
+/*
+ * Add a single ACL entry to the internal list of ACL data.
+ */
+int
+archive_entry_acl_add_entry(struct archive_entry *entry,
+ int type, int permset, int tag, int id, const char *name)
+{
+ return archive_acl_add_entry(&entry->acl, type, permset, tag, id, name);
+}
+
+/*
+ * As above, but with a wide-character name.
+ */
+int
+archive_entry_acl_add_entry_w(struct archive_entry *entry,
+ int type, int permset, int tag, int id, const wchar_t *name)
+{
+ return archive_acl_add_entry_w_len(&entry->acl,
+ type, permset, tag, id, name, wcslen(name));
+}
+
+/*
+ * Return a count of entries matching "want_type".
+ */
+int
+archive_entry_acl_count(struct archive_entry *entry, int want_type)
+{
+ return archive_acl_count(&entry->acl, want_type);
+}
+
+/*
+ * Prepare for reading entries from the ACL data. Returns a count
+ * of entries matching "want_type", or zero if there are no
+ * non-extended ACL entries of that type.
+ */
+int
+archive_entry_acl_reset(struct archive_entry *entry, int want_type)
+{
+ return archive_acl_reset(&entry->acl, want_type);
+}
+
+/*
+ * Return the next ACL entry in the list. Fake entries for the
+ * standard permissions and include them in the returned list.
+ */
+int
+archive_entry_acl_next(struct archive_entry *entry, int want_type, int *type,
+ int *permset, int *tag, int *id, const char **name)
+{
+ int r;
+ r = archive_acl_next(entry->archive, &entry->acl, want_type, type,
+ permset, tag, id, name);
+ if (r == ARCHIVE_FATAL && errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (r);
+}
+
+/*
+ * Generate a text version of the ACL. The flags parameter controls
+ * the style of the generated ACL.
+ */
+const wchar_t *
+archive_entry_acl_text_w(struct archive_entry *entry, int flags)
+{
+ const wchar_t *r;
+ r = archive_acl_text_w(entry->archive, &entry->acl, flags);
+ if (r == NULL && errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (r);
+}
+
+const char *
+archive_entry_acl_text(struct archive_entry *entry, int flags)
+{
+ const char *p;
+ if (archive_acl_text_l(&entry->acl, flags, &p, NULL, NULL) != 0
+ && errno == ENOMEM)
+ __archive_errx(1, "No memory");
+ return (p);
+}
+
+int
+_archive_entry_acl_text_l(struct archive_entry *entry, int flags,
+ const char **acl_text, size_t *len, struct archive_string_conv *sc)
+{
+ return (archive_acl_text_l(&entry->acl, flags, acl_text, len, sc));
+}
+
+/*
+ * Following code is modified from UC Berkeley sources, and
+ * is subject to the following copyright notice.
+ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. 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.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+static struct flag {
+ const char *name;
+ const wchar_t *wname;
+ unsigned long set;
+ unsigned long clear;
+} flags[] = {
+ /* Preferred (shorter) names per flag first, all prefixed by "no" */
+#ifdef SF_APPEND
+ { "nosappnd", L"nosappnd", SF_APPEND, 0 },
+ { "nosappend", L"nosappend", SF_APPEND, 0 },
+#endif
+#ifdef EXT2_APPEND_FL /* 'a' */
+ { "nosappnd", L"nosappnd", EXT2_APPEND_FL, 0 },
+ { "nosappend", L"nosappend", EXT2_APPEND_FL, 0 },
+#endif
+#ifdef SF_ARCHIVED
+ { "noarch", L"noarch", SF_ARCHIVED, 0 },
+ { "noarchived", L"noarchived", SF_ARCHIVED, 0 },
+#endif
+#ifdef SF_IMMUTABLE
+ { "noschg", L"noschg", SF_IMMUTABLE, 0 },
+ { "noschange", L"noschange", SF_IMMUTABLE, 0 },
+ { "nosimmutable", L"nosimmutable", SF_IMMUTABLE, 0 },
+#endif
+#ifdef EXT2_IMMUTABLE_FL /* 'i' */
+ { "noschg", L"noschg", EXT2_IMMUTABLE_FL, 0 },
+ { "noschange", L"noschange", EXT2_IMMUTABLE_FL, 0 },
+ { "nosimmutable", L"nosimmutable", EXT2_IMMUTABLE_FL, 0 },
+#endif
+#ifdef SF_NOUNLINK
+ { "nosunlnk", L"nosunlnk", SF_NOUNLINK, 0 },
+ { "nosunlink", L"nosunlink", SF_NOUNLINK, 0 },
+#endif
+#ifdef SF_SNAPSHOT
+ { "nosnapshot", L"nosnapshot", SF_SNAPSHOT, 0 },
+#endif
+#ifdef UF_APPEND
+ { "nouappnd", L"nouappnd", UF_APPEND, 0 },
+ { "nouappend", L"nouappend", UF_APPEND, 0 },
+#endif
+#ifdef UF_IMMUTABLE
+ { "nouchg", L"nouchg", UF_IMMUTABLE, 0 },
+ { "nouchange", L"nouchange", UF_IMMUTABLE, 0 },
+ { "nouimmutable", L"nouimmutable", UF_IMMUTABLE, 0 },
+#endif
+#ifdef UF_NODUMP
+ { "nodump", L"nodump", 0, UF_NODUMP},
+#endif
+#ifdef EXT2_NODUMP_FL /* 'd' */
+ { "nodump", L"nodump", 0, EXT2_NODUMP_FL},
+#endif
+#ifdef UF_OPAQUE
+ { "noopaque", L"noopaque", UF_OPAQUE, 0 },
+#endif
+#ifdef UF_NOUNLINK
+ { "nouunlnk", L"nouunlnk", UF_NOUNLINK, 0 },
+ { "nouunlink", L"nouunlink", UF_NOUNLINK, 0 },
+#endif
+#ifdef UF_COMPRESSED
+ { "nocompressed",L"nocompressed", UF_COMPRESSED, 0 },
+#endif
+#ifdef EXT2_UNRM_FL
+ { "nouunlink", L"nouunlink", EXT2_UNRM_FL, 0},
+#endif
+
+#ifdef EXT2_BTREE_FL
+ { "nobtree", L"nobtree", EXT2_BTREE_FL, 0 },
+#endif
+
+#ifdef EXT2_ECOMPR_FL
+ { "nocomperr", L"nocomperr", EXT2_ECOMPR_FL, 0 },
+#endif
+
+#ifdef EXT2_COMPR_FL /* 'c' */
+ { "nocompress", L"nocompress", EXT2_COMPR_FL, 0 },
+#endif
+
+#ifdef EXT2_NOATIME_FL /* 'A' */
+ { "noatime", L"noatime", 0, EXT2_NOATIME_FL},
+#endif
+
+#ifdef EXT2_DIRTY_FL
+ { "nocompdirty",L"nocompdirty", EXT2_DIRTY_FL, 0},
+#endif
+
+#ifdef EXT2_COMPRBLK_FL
+#ifdef EXT2_NOCOMPR_FL
+ { "nocomprblk", L"nocomprblk", EXT2_COMPRBLK_FL, EXT2_NOCOMPR_FL},
+#else
+ { "nocomprblk", L"nocomprblk", EXT2_COMPRBLK_FL, 0},
+#endif
+#endif
+#ifdef EXT2_DIRSYNC_FL
+ { "nodirsync", L"nodirsync", EXT2_DIRSYNC_FL, 0},
+#endif
+#ifdef EXT2_INDEX_FL
+ { "nohashidx", L"nohashidx", EXT2_INDEX_FL, 0},
+#endif
+#ifdef EXT2_IMAGIC_FL
+ { "noimagic", L"noimagic", EXT2_IMAGIC_FL, 0},
+#endif
+#ifdef EXT3_JOURNAL_DATA_FL
+ { "nojournal", L"nojournal", EXT3_JOURNAL_DATA_FL, 0},
+#endif
+#ifdef EXT2_SECRM_FL
+ { "nosecuredeletion",L"nosecuredeletion",EXT2_SECRM_FL, 0},
+#endif
+#ifdef EXT2_SYNC_FL
+ { "nosync", L"nosync", EXT2_SYNC_FL, 0},
+#endif
+#ifdef EXT2_NOTAIL_FL
+ { "notail", L"notail", 0, EXT2_NOTAIL_FL},
+#endif
+#ifdef EXT2_TOPDIR_FL
+ { "notopdir", L"notopdir", EXT2_TOPDIR_FL, 0},
+#endif
+#ifdef EXT2_RESERVED_FL
+ { "noreserved", L"noreserved", EXT2_RESERVED_FL, 0},
+#endif
+
+ { NULL, NULL, 0, 0 }
+};
+
+/*
+ * fflagstostr --
+ * Convert file flags to a comma-separated string. If no flags
+ * are set, return the empty string.
+ */
+static char *
+ae_fflagstostr(unsigned long bitset, unsigned long bitclear)
+{
+ char *string, *dp;
+ const char *sp;
+ unsigned long bits;
+ struct flag *flag;
+ size_t length;
+
+ bits = bitset | bitclear;
+ length = 0;
+ for (flag = flags; flag->name != NULL; flag++)
+ if (bits & (flag->set | flag->clear)) {
+ length += strlen(flag->name) + 1;
+ bits &= ~(flag->set | flag->clear);
+ }
+
+ if (length == 0)
+ return (NULL);
+ string = (char *)malloc(length);
+ if (string == NULL)
+ return (NULL);
+
+ dp = string;
+ for (flag = flags; flag->name != NULL; flag++) {
+ if (bitset & flag->set || bitclear & flag->clear) {
+ sp = flag->name + 2;
+ } else if (bitset & flag->clear || bitclear & flag->set) {
+ sp = flag->name;
+ } else
+ continue;
+ bitset &= ~(flag->set | flag->clear);
+ bitclear &= ~(flag->set | flag->clear);
+ if (dp > string)
+ *dp++ = ',';
+ while ((*dp++ = *sp++) != '\0')
+ ;
+ dp--;
+ }
+
+ *dp = '\0';
+ return (string);
+}
+
+/*
+ * strtofflags --
+ * Take string of arguments and return file flags. This
+ * version works a little differently than strtofflags(3).
+ * In particular, it always tests every token, skipping any
+ * unrecognized tokens. It returns a pointer to the first
+ * unrecognized token, or NULL if every token was recognized.
+ * This version is also const-correct and does not modify the
+ * provided string.
+ */
+static const char *
+ae_strtofflags(const char *s, unsigned long *setp, unsigned long *clrp)
+{
+ const char *start, *end;
+ struct flag *flag;
+ unsigned long set, clear;
+ const char *failed;
+
+ set = clear = 0;
+ start = s;
+ failed = NULL;
+ /* Find start of first token. */
+ while (*start == '\t' || *start == ' ' || *start == ',')
+ start++;
+ while (*start != '\0') {
+ /* Locate end of token. */
+ end = start;
+ while (*end != '\0' && *end != '\t' &&
+ *end != ' ' && *end != ',')
+ end++;
+ for (flag = flags; flag->name != NULL; flag++) {
+ if (memcmp(start, flag->name, end - start) == 0) {
+ /* Matched "noXXXX", so reverse the sense. */
+ clear |= flag->set;
+ set |= flag->clear;
+ break;
+ } else if (memcmp(start, flag->name + 2, end - start)
+ == 0) {
+ /* Matched "XXXX", so don't reverse. */
+ set |= flag->set;
+ clear |= flag->clear;
+ break;
+ }
+ }
+ /* Ignore unknown flag names. */
+ if (flag->name == NULL && failed == NULL)
+ failed = start;
+
+ /* Find start of next token. */
+ start = end;
+ while (*start == '\t' || *start == ' ' || *start == ',')
+ start++;
+
+ }
+
+ if (setp)
+ *setp = set;
+ if (clrp)
+ *clrp = clear;
+
+ /* Return location of first failure. */
+ return (failed);
+}
+
+/*
+ * wcstofflags --
+ * Take string of arguments and return file flags. This
+ * version works a little differently than strtofflags(3).
+ * In particular, it always tests every token, skipping any
+ * unrecognized tokens. It returns a pointer to the first
+ * unrecognized token, or NULL if every token was recognized.
+ * This version is also const-correct and does not modify the
+ * provided string.
+ */
+static const wchar_t *
+ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp)
+{
+ const wchar_t *start, *end;
+ struct flag *flag;
+ unsigned long set, clear;
+ const wchar_t *failed;
+
+ set = clear = 0;
+ start = s;
+ failed = NULL;
+ /* Find start of first token. */
+ while (*start == L'\t' || *start == L' ' || *start == L',')
+ start++;
+ while (*start != L'\0') {
+ /* Locate end of token. */
+ end = start;
+ while (*end != L'\0' && *end != L'\t' &&
+ *end != L' ' && *end != L',')
+ end++;
+ for (flag = flags; flag->wname != NULL; flag++) {
+ if (wmemcmp(start, flag->wname, end - start) == 0) {
+ /* Matched "noXXXX", so reverse the sense. */
+ clear |= flag->set;
+ set |= flag->clear;
+ break;
+ } else if (wmemcmp(start, flag->wname + 2, end - start)
+ == 0) {
+ /* Matched "XXXX", so don't reverse. */
+ set |= flag->set;
+ clear |= flag->clear;
+ break;
+ }
+ }
+ /* Ignore unknown flag names. */
+ if (flag->wname == NULL && failed == NULL)
+ failed = start;
+
+ /* Find start of next token. */
+ start = end;
+ while (*start == L'\t' || *start == L' ' || *start == L',')
+ start++;
+
+ }
+
+ if (setp)
+ *setp = set;
+ if (clrp)
+ *clrp = clear;
+
+ /* Return location of first failure. */
+ return (failed);
+}
+
+
+#ifdef TEST
+#include <stdio.h>
+int
+main(int argc, char **argv)
+{
+ struct archive_entry *entry = archive_entry_new();
+ unsigned long set, clear;
+ const wchar_t *remainder;
+
+ remainder = archive_entry_copy_fflags_text_w(entry, L"nosappnd dump archive,,,,,,,");
+ archive_entry_fflags(entry, &set, &clear);
+
+ wprintf(L"set=0x%lX clear=0x%lX remainder='%ls'\n", set, clear, remainder);
+
+ wprintf(L"new flags='%s'\n", archive_entry_fflags_text(entry));
+ return (0);
+}
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.h b/Utilities/cmlibarchive/libarchive/archive_entry.h
new file mode 100644
index 0000000000..efc4d733f4
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry.h
@@ -0,0 +1,616 @@
+/*-
+ * Copyright (c) 2003-2008 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_entry.h 201096 2009-12-28 02:41:27Z kientzle $
+ */
+
+#ifndef ARCHIVE_ENTRY_H_INCLUDED
+#define ARCHIVE_ENTRY_H_INCLUDED
+
+/* Note: Compiler will complain if this does not match archive.h! */
+#define ARCHIVE_VERSION_NUMBER 3001002
+
+/*
+ * Note: archive_entry.h is for use outside of libarchive; the
+ * configuration headers (config.h, archive_platform.h, etc.) are
+ * purely internal. Do NOT use HAVE_XXX configuration macros to
+ * control the behavior of this header! If you must conditionalize,
+ * use predefined compiler and/or platform macros.
+ */
+
+#include <sys/types.h>
+#include <stddef.h> /* for wchar_t */
+#include <time.h>
+
+/* 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
+# else
+# define __LA_INT64_T int64_t
+# endif
+#endif
+
+/* Get a suitable definition for mode_t */
+#if ARCHIVE_VERSION_NUMBER >= 3999000
+/* Switch to plain 'int' for libarchive 4.0. It's less broken than 'mode_t' */
+# define __LA_MODE_T int
+#elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
+# define __LA_MODE_T unsigned short
+#else
+# define __LA_MODE_T mode_t
+#endif
+
+/*
+ * On Windows, define LIBARCHIVE_STATIC if you're building or using a
+ * .lib. The default here assumes you're building a DLL. Only
+ * libarchive source should ever define __LIBARCHIVE_BUILD.
+ */
+#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
+# ifdef __LIBARCHIVE_BUILD
+# ifdef __GNUC__
+# define __LA_DECL __attribute__((dllexport)) extern
+# else
+# define __LA_DECL __declspec(dllexport)
+# endif
+# else
+# ifdef __GNUC__
+# define __LA_DECL
+# else
+# define __LA_DECL __declspec(dllimport)
+# endif
+# endif
+#else
+/* Static libraries on all platforms and shared libraries on non-Windows. */
+# define __LA_DECL
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Description of an archive entry.
+ *
+ * You can think of this as "struct stat" with some text fields added in.
+ *
+ * TODO: Add "comment", "charset", and possibly other entries that are
+ * supported by "pax interchange" format. However, GNU, ustar, cpio,
+ * and other variants don't support these features, so they're not an
+ * excruciatingly high priority right now.
+ *
+ * TODO: "pax interchange" format allows essentially arbitrary
+ * key/value attributes to be attached to any entry. Supporting
+ * such extensions may make this library useful for special
+ * applications (e.g., a package manager could attach special
+ * package-management attributes to each entry).
+ */
+struct archive;
+struct archive_entry;
+
+/*
+ * File-type constants. These are returned from archive_entry_filetype()
+ * and passed to archive_entry_set_filetype().
+ *
+ * These values match S_XXX defines on every platform I've checked,
+ * including Windows, AIX, Linux, Solaris, and BSD. They're
+ * (re)defined here because platforms generally don't define the ones
+ * they don't support. For example, Windows doesn't define S_IFLNK or
+ * S_IFBLK. Instead of having a mass of conditional logic and system
+ * checks to define any S_XXX values that aren't supported locally,
+ * I've just defined a new set of such constants so that
+ * libarchive-based applications can manipulate and identify archive
+ * entries properly even if the hosting platform can't store them on
+ * disk.
+ *
+ * These values are also used directly within some portable formats,
+ * such as cpio. If you find a platform that varies from these, the
+ * correct solution is to leave these alone and translate from these
+ * portable values to platform-native values when entries are read from
+ * or written to disk.
+ */
+/*
+ * In libarchive 4.0, we can drop the casts here.
+ * They're needed to work around Borland C's broken mode_t.
+ */
+#define AE_IFMT ((__LA_MODE_T)0170000)
+#define AE_IFREG ((__LA_MODE_T)0100000)
+#define AE_IFLNK ((__LA_MODE_T)0120000)
+#define AE_IFSOCK ((__LA_MODE_T)0140000)
+#define AE_IFCHR ((__LA_MODE_T)0020000)
+#define AE_IFBLK ((__LA_MODE_T)0060000)
+#define AE_IFDIR ((__LA_MODE_T)0040000)
+#define AE_IFIFO ((__LA_MODE_T)0010000)
+
+/*
+ * Basic object manipulation
+ */
+
+__LA_DECL struct archive_entry *archive_entry_clear(struct archive_entry *);
+/* The 'clone' function does a deep copy; all of the strings are copied too. */
+__LA_DECL struct archive_entry *archive_entry_clone(struct archive_entry *);
+__LA_DECL void archive_entry_free(struct archive_entry *);
+__LA_DECL struct archive_entry *archive_entry_new(void);
+
+/*
+ * This form of archive_entry_new2() will pull character-set
+ * conversion information from the specified archive handle. The
+ * older archive_entry_new(void) form is equivalent to calling
+ * archive_entry_new2(NULL) and will result in the use of an internal
+ * default character-set conversion.
+ */
+__LA_DECL struct archive_entry *archive_entry_new2(struct archive *);
+
+/*
+ * Retrieve fields from an archive_entry.
+ *
+ * There are a number of implicit conversions among these fields. For
+ * example, if a regular string field is set and you read the _w wide
+ * character field, the entry will implicitly convert narrow-to-wide
+ * using the current locale. Similarly, dev values are automatically
+ * updated when you write devmajor or devminor and vice versa.
+ *
+ * In addition, fields can be "set" or "unset." Unset string fields
+ * return NULL, non-string fields have _is_set() functions to test
+ * whether they've been set. You can "unset" a string field by
+ * assigning NULL; non-string fields have _unset() functions to
+ * unset them.
+ *
+ * Note: There is one ambiguity in the above; string fields will
+ * also return NULL when implicit character set conversions fail.
+ * This is usually what you want.
+ */
+__LA_DECL time_t archive_entry_atime(struct archive_entry *);
+__LA_DECL long archive_entry_atime_nsec(struct archive_entry *);
+__LA_DECL int archive_entry_atime_is_set(struct archive_entry *);
+__LA_DECL time_t archive_entry_birthtime(struct archive_entry *);
+__LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *);
+__LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *);
+__LA_DECL time_t archive_entry_ctime(struct archive_entry *);
+__LA_DECL long archive_entry_ctime_nsec(struct archive_entry *);
+__LA_DECL int archive_entry_ctime_is_set(struct archive_entry *);
+__LA_DECL dev_t archive_entry_dev(struct archive_entry *);
+__LA_DECL int archive_entry_dev_is_set(struct archive_entry *);
+__LA_DECL dev_t archive_entry_devmajor(struct archive_entry *);
+__LA_DECL dev_t archive_entry_devminor(struct archive_entry *);
+__LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *);
+__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 const char *archive_entry_gname(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 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 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 *);
+__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 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 *);
+__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 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 wchar_t *archive_entry_symlink_w(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 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 *);
+__LA_DECL int archive_entry_is_encrypted(struct archive_entry *);
+
+/*
+ * Set fields in an archive_entry.
+ *
+ * Note: Before libarchive 2.4, there were 'set' and 'copy' versions
+ * of the string setters. 'copy' copied the actual string, 'set' just
+ * stored the pointer. In libarchive 2.4 and later, strings are
+ * always copied.
+ */
+
+__LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long);
+__LA_DECL void archive_entry_unset_atime(struct archive_entry *);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+__LA_DECL void archive_entry_copy_bhfi(struct archive_entry *, struct _BY_HANDLE_FILE_INFORMATION *);
+#endif
+__LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long);
+__LA_DECL void archive_entry_unset_birthtime(struct archive_entry *);
+__LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long);
+__LA_DECL void archive_entry_unset_ctime(struct archive_entry *);
+__LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t);
+__LA_DECL void archive_entry_set_devmajor(struct archive_entry *, dev_t);
+__LA_DECL void archive_entry_set_devminor(struct archive_entry *, dev_t);
+__LA_DECL void archive_entry_set_filetype(struct archive_entry *, unsigned int);
+__LA_DECL void archive_entry_set_fflags(struct archive_entry *,
+ unsigned long /* set */, unsigned long /* clear */);
+/* Returns pointer to start of first invalid token, or NULL if none. */
+/* Note that all recognized tokens are processed, regardless. */
+__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_gname(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_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_link(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 *);
+__LA_DECL void archive_entry_set_mode(struct archive_entry *, __LA_MODE_T);
+__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_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 *);
+__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_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_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_uname(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 *);
+__LA_DECL void archive_entry_set_is_data_encrypted(struct archive_entry *, char is_encrypted);
+__LA_DECL void archive_entry_set_is_metadata_encrypted(struct archive_entry *, char is_encrypted);
+/*
+ * Routines to bulk copy fields to/from a platform-native "struct
+ * stat." Libarchive used to just store a struct stat inside of each
+ * archive_entry object, but this created issues when trying to
+ * manipulate archives on systems different than the ones they were
+ * created on.
+ *
+ * TODO: On Linux and other LFS systems, provide both stat32 and
+ * stat64 versions of these functions and all of the macro glue so
+ * that archive_entry_stat is magically defined to
+ * archive_entry_stat32 or archive_entry_stat64 as appropriate.
+ */
+__LA_DECL const struct stat *archive_entry_stat(struct archive_entry *);
+__LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *);
+
+/*
+ * Storage for Mac OS-specific AppleDouble metadata information.
+ * Apple-format tar files store a separate binary blob containing
+ * encoded metadata with ACL, extended attributes, etc.
+ * This provides a place to store that blob.
+ */
+
+__LA_DECL const void * archive_entry_mac_metadata(struct archive_entry *, size_t *);
+__LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const void *, size_t);
+
+/*
+ * ACL routines. This used to simply store and return text-format ACL
+ * strings, but that proved insufficient for a number of reasons:
+ * = clients need control over uname/uid and gname/gid mappings
+ * = there are many different ACL text formats
+ * = would like to be able to read/convert archives containing ACLs
+ * on platforms that lack ACL libraries
+ *
+ * This last point, in particular, forces me to implement a reasonably
+ * complete set of ACL support routines.
+ */
+
+/*
+ * Permission bits.
+ */
+#define ARCHIVE_ENTRY_ACL_EXECUTE 0x00000001
+#define ARCHIVE_ENTRY_ACL_WRITE 0x00000002
+#define ARCHIVE_ENTRY_ACL_READ 0x00000004
+#define ARCHIVE_ENTRY_ACL_READ_DATA 0x00000008
+#define ARCHIVE_ENTRY_ACL_LIST_DIRECTORY 0x00000008
+#define ARCHIVE_ENTRY_ACL_WRITE_DATA 0x00000010
+#define ARCHIVE_ENTRY_ACL_ADD_FILE 0x00000010
+#define ARCHIVE_ENTRY_ACL_APPEND_DATA 0x00000020
+#define ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY 0x00000020
+#define ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS 0x00000040
+#define ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS 0x00000080
+#define ARCHIVE_ENTRY_ACL_DELETE_CHILD 0x00000100
+#define ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES 0x00000200
+#define ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES 0x00000400
+#define ARCHIVE_ENTRY_ACL_DELETE 0x00000800
+#define ARCHIVE_ENTRY_ACL_READ_ACL 0x00001000
+#define ARCHIVE_ENTRY_ACL_WRITE_ACL 0x00002000
+#define ARCHIVE_ENTRY_ACL_WRITE_OWNER 0x00004000
+#define ARCHIVE_ENTRY_ACL_SYNCHRONIZE 0x00008000
+
+#define ARCHIVE_ENTRY_ACL_PERMS_POSIX1E \
+ (ARCHIVE_ENTRY_ACL_EXECUTE \
+ | ARCHIVE_ENTRY_ACL_WRITE \
+ | ARCHIVE_ENTRY_ACL_READ)
+
+#define ARCHIVE_ENTRY_ACL_PERMS_NFS4 \
+ (ARCHIVE_ENTRY_ACL_EXECUTE \
+ | ARCHIVE_ENTRY_ACL_READ_DATA \
+ | ARCHIVE_ENTRY_ACL_LIST_DIRECTORY \
+ | ARCHIVE_ENTRY_ACL_WRITE_DATA \
+ | ARCHIVE_ENTRY_ACL_ADD_FILE \
+ | ARCHIVE_ENTRY_ACL_APPEND_DATA \
+ | ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY \
+ | ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS \
+ | ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS \
+ | ARCHIVE_ENTRY_ACL_DELETE_CHILD \
+ | ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES \
+ | ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES \
+ | ARCHIVE_ENTRY_ACL_DELETE \
+ | ARCHIVE_ENTRY_ACL_READ_ACL \
+ | ARCHIVE_ENTRY_ACL_WRITE_ACL \
+ | ARCHIVE_ENTRY_ACL_WRITE_OWNER \
+ | ARCHIVE_ENTRY_ACL_SYNCHRONIZE)
+
+/*
+ * Inheritance values (NFS4 ACLs only); included in permset.
+ */
+#define ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT 0x02000000
+#define ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT 0x04000000
+#define ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT 0x08000000
+#define ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY 0x10000000
+#define ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS 0x20000000
+#define ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS 0x40000000
+
+#define ARCHIVE_ENTRY_ACL_INHERITANCE_NFS4 \
+ (ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT \
+ | ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT \
+ | ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT \
+ | ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY \
+ | ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS \
+ | ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS)
+
+/* We need to be able to specify combinations of these. */
+#define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256 /* POSIX.1e only */
+#define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512 /* POSIX.1e only */
+#define ARCHIVE_ENTRY_ACL_TYPE_ALLOW 1024 /* NFS4 only */
+#define ARCHIVE_ENTRY_ACL_TYPE_DENY 2048 /* NFS4 only */
+#define ARCHIVE_ENTRY_ACL_TYPE_AUDIT 4096 /* NFS4 only */
+#define ARCHIVE_ENTRY_ACL_TYPE_ALARM 8192 /* NFS4 only */
+#define ARCHIVE_ENTRY_ACL_TYPE_POSIX1E (ARCHIVE_ENTRY_ACL_TYPE_ACCESS \
+ | ARCHIVE_ENTRY_ACL_TYPE_DEFAULT)
+#define ARCHIVE_ENTRY_ACL_TYPE_NFS4 (ARCHIVE_ENTRY_ACL_TYPE_ALLOW \
+ | ARCHIVE_ENTRY_ACL_TYPE_DENY \
+ | ARCHIVE_ENTRY_ACL_TYPE_AUDIT \
+ | ARCHIVE_ENTRY_ACL_TYPE_ALARM)
+
+/* Tag values mimic POSIX.1e */
+#define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */
+#define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */
+#define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */
+#define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */
+#define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access (POSIX.1e only) */
+#define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public (POSIX.1e only) */
+#define ARCHIVE_ENTRY_ACL_EVERYONE 10107 /* Everyone (NFS4 only) */
+
+/*
+ * Set the ACL by clearing it and adding entries one at a time.
+ * Unlike the POSIX.1e ACL routines, you must specify the type
+ * (access/default) for each entry. Internally, the ACL data is just
+ * a soup of entries. API calls here allow you to retrieve just the
+ * entries of interest. This design (which goes against the spirit of
+ * POSIX.1e) is useful for handling archive formats that combine
+ * default and access information in a single ACL list.
+ */
+__LA_DECL void archive_entry_acl_clear(struct archive_entry *);
+__LA_DECL int archive_entry_acl_add_entry(struct archive_entry *,
+ int /* type */, int /* permset */, int /* tag */,
+ int /* qual */, const char * /* name */);
+__LA_DECL int archive_entry_acl_add_entry_w(struct archive_entry *,
+ int /* type */, int /* permset */, int /* tag */,
+ int /* qual */, const wchar_t * /* name */);
+
+/*
+ * To retrieve the ACL, first "reset", then repeatedly ask for the
+ * "next" entry. The want_type parameter allows you to request only
+ * certain types of entries.
+ */
+__LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type */);
+__LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */,
+ int * /* type */, int * /* permset */, int * /* tag */,
+ int * /* qual */, const char ** /* name */);
+__LA_DECL int archive_entry_acl_next_w(struct archive_entry *, int /* want_type */,
+ int * /* type */, int * /* permset */, int * /* tag */,
+ int * /* qual */, const wchar_t ** /* name */);
+
+/*
+ * Construct a text-format ACL. The flags argument is a bitmask that
+ * can include any of the following:
+ *
+ * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include POSIX.1e "access" entries.
+ * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include POSIX.1e "default" entries.
+ * ARCHIVE_ENTRY_ACL_TYPE_NFS4 - Include NFS4 entries.
+ * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
+ * each ACL entry. ('star' introduced this for POSIX.1e, this flag
+ * also applies to NFS4.)
+ * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each
+ * default ACL entry, as used in old Solaris ACLs.
+ */
+#define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024
+#define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048
+__LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *,
+ int /* flags */);
+__LA_DECL const char *archive_entry_acl_text(struct archive_entry *,
+ int /* flags */);
+
+/* Return a count of entries matching 'want_type' */
+__LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */);
+
+/* Return an opaque ACL object. */
+/* There's not yet anything clients can actually do with this... */
+struct archive_acl;
+__LA_DECL struct archive_acl *archive_entry_acl(struct archive_entry *);
+
+/*
+ * extended attributes
+ */
+
+__LA_DECL void archive_entry_xattr_clear(struct archive_entry *);
+__LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *,
+ const char * /* name */, const void * /* value */,
+ size_t /* size */);
+
+/*
+ * To retrieve the xattr list, first "reset", then repeatedly ask for the
+ * "next" entry.
+ */
+
+__LA_DECL int archive_entry_xattr_count(struct archive_entry *);
+__LA_DECL int archive_entry_xattr_reset(struct archive_entry *);
+__LA_DECL int archive_entry_xattr_next(struct archive_entry *,
+ const char ** /* name */, const void ** /* value */, size_t *);
+
+/*
+ * sparse
+ */
+
+__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 */);
+
+/*
+ * To retrieve the xattr list, first "reset", then repeatedly ask for the
+ * "next" 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 */);
+
+/*
+ * Utility to match up hardlinks.
+ *
+ * The 'struct archive_entry_linkresolver' is a cache of archive entries
+ * for files with multiple links. Here's how to use it:
+ * 1. Create a lookup object with archive_entry_linkresolver_new()
+ * 2. Tell it the archive format you're using.
+ * 3. Hand each archive_entry to archive_entry_linkify().
+ * That function will return 0, 1, or 2 entries that should
+ * be written.
+ * 4. Call archive_entry_linkify(resolver, NULL) until
+ * no more entries are returned.
+ * 5. Call archive_entry_linkresolver_free(resolver) to free resources.
+ *
+ * The entries returned have their hardlink and size fields updated
+ * appropriately. If an entry is passed in that does not refer to
+ * a file with multiple links, it is returned unchanged. The intention
+ * is that you should be able to simply filter all entries through
+ * this machine.
+ *
+ * To make things more efficient, be sure that each entry has a valid
+ * nlinks value. The hardlink cache uses this to track when all links
+ * have been found. If the nlinks value is zero, it will keep every
+ * name in the cache indefinitely, which can use a lot of memory.
+ *
+ * Note that archive_entry_size() is reset to zero if the file
+ * body should not be written to the archive. Pay attention!
+ */
+struct archive_entry_linkresolver;
+
+/*
+ * There are three different strategies for marking hardlinks.
+ * The descriptions below name them after the best-known
+ * formats that rely on each strategy:
+ *
+ * "Old cpio" is the simplest, it always returns any entry unmodified.
+ * As far as I know, only cpio formats use this. Old cpio archives
+ * store every link with the full body; the onus is on the dearchiver
+ * to detect and properly link the files as they are restored.
+ * "tar" is also pretty simple; it caches a copy the first time it sees
+ * any link. Subsequent appearances are modified to be hardlink
+ * references to the first one without any body. Used by all tar
+ * formats, although the newest tar formats permit the "old cpio" strategy
+ * as well. This strategy is very simple for the dearchiver,
+ * and reasonably straightforward for the archiver.
+ * "new cpio" is trickier. It stores the body only with the last
+ * occurrence. The complication is that we might not
+ * see every link to a particular file in a single session, so
+ * there's no easy way to know when we've seen the last occurrence.
+ * The solution here is to queue one link until we see the next.
+ * At the end of the session, you can enumerate any remaining
+ * entries by calling archive_entry_linkify(NULL) and store those
+ * bodies. If you have a file with three links l1, l2, and l3,
+ * you'll get the following behavior if you see all three links:
+ * linkify(l1) => NULL (the resolver stores l1 internally)
+ * linkify(l2) => l1 (resolver stores l2, you write l1)
+ * linkify(l3) => l2, l3 (all links seen, you can write both).
+ * If you only see l1 and l2, you'll get this behavior:
+ * linkify(l1) => NULL
+ * linkify(l2) => l1
+ * linkify(NULL) => l2 (at end, you retrieve remaining links)
+ * As the name suggests, this strategy is used by newer cpio variants.
+ * It's noticeably more complex for the archiver, slightly more complex
+ * for the dearchiver than the tar strategy, but makes it straightforward
+ * to restore a file using any link by simply continuing to scan until
+ * you see a link that is stored with a body. In contrast, the tar
+ * strategy requires you to rescan the archive from the beginning to
+ * correctly extract an arbitrary link.
+ */
+
+__LA_DECL struct archive_entry_linkresolver *archive_entry_linkresolver_new(void);
+__LA_DECL void archive_entry_linkresolver_set_strategy(
+ struct archive_entry_linkresolver *, int /* format_code */);
+__LA_DECL void archive_entry_linkresolver_free(struct archive_entry_linkresolver *);
+__LA_DECL void archive_entry_linkify(struct archive_entry_linkresolver *,
+ struct archive_entry **, struct archive_entry **);
+__LA_DECL struct archive_entry *archive_entry_partial_links(
+ struct archive_entry_linkresolver *res, unsigned int *links);
+
+#ifdef __cplusplus
+}
+#endif
+
+/* This is meaningless outside of this header. */
+#undef __LA_DECL
+
+#endif /* !ARCHIVE_ENTRY_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3
new file mode 100644
index 0000000000..f5c337733c
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3
@@ -0,0 +1,235 @@
+.\" Copyright (c) 2010 Joerg Sonnenberger
+.\" 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 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 AUTHOR 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.
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_ENTRY_ACL 3
+.Os
+.Sh NAME
+.Nm archive_entry_acl_add_entry ,
+.Nm archive_entry_acl_add_entry_w ,
+.Nm archive_entry_acl_clear ,
+.Nm archive_entry_acl_count ,
+.Nm archive_entry_acl_next ,
+.Nm archive_entry_acl_next_w ,
+.Nm archive_entry_acl_reset ,
+.Nm archive_entry_acl_text_w
+.Nd functions for manipulating Access Control Lists in archive entry descriptions
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive_entry.h
+.Ft void
+.Fo archive_entry_acl_add_entry
+.Fa "struct archive_entry *a"
+.Fa "int type"
+.Fa "int permset"
+.Fa "int tag"
+.Fa "int qualifier"
+.Fa "const char *name"
+.Fc
+.Ft void
+.Fo archive_entry_acl_add_entry_w
+.Fa "struct archive_entry *a"
+.Fa "int type"
+.Fa "int permset"
+.Fa "int tag"
+.Fa "int qualifier"
+.Fa "const wchar_t *name"
+.Fc
+.Ft void
+.Fn archive_entry_acl_clear "struct archive_entry *a"
+.Ft int
+.Fn archive_entry_acl_count "struct archive_entry *a" "int type"
+.Ft int
+.Fo archive_entry_acl_next
+.Fa "struct archive_entry *a"
+.Fa "int type"
+.Fa "int *ret_type"
+.Fa "int *ret_permset"
+.Fa "int *ret_tag"
+.Fa "int *ret_qual"
+.Fa "const char **ret_name"
+.Fc
+.Ft int
+.Fo archive_entry_acl_next_w
+.Fa "struct archive_entry *a"
+.Fa "int type"
+.Fa "int *ret_type"
+.Fa "int *ret_permset"
+.Fa "int *ret_tag"
+.Fa "int *ret_qual"
+.Fa "const wchar_t **ret_name"
+.Fc
+.Ft int
+.Fn archive_entry_acl_reset "struct archive_entry *a" "int type"
+.Ft const wchar_t *
+.Fn archive_entry_acl_text_w "struct archive_entry *a" "int flags"
+.\" enum?
+.Sh DESCRIPTION
+An
+.Dq Access Control List
+is a generalisation of the classic Unix permission system.
+The ACL interface of
+.Nm libarchive
+is derived from the POSIX.1e draft, but restricted to simplify dealing
+with practical implementations in various Operating Systems and archive formats.
+.Pp
+An ACL consists of a number of independent entries.
+Each entry specifies the permission set as bitmask of basic permissions.
+Valid permissions are:
+.Bl -tag -offset indent -compact -width "ARCHIVE_ENTRY_ACL_EXECUTE"
+.It Dv ARCHIVE_ENTRY_ACL_EXECUTE
+.It Dv ARCHIVE_ENTRY_ACL_WRITE
+.It Dv ARCHIVE_ENTRY_ACL_READ
+.El
+The permissions correspond to the normal Unix permissions.
+.Pp
+The tag specifies the principal to which the permission applies.
+Valid values are:
+.Bl -tag -offset indent -compact -width "ARCHIVE_ENTRY_ACL_GROUP_OBJ"
+.It Dv ARCHIVE_ENTRY_ACL_USER
+The user specified by the name field.
+.It Dv ARCHIVE_ENTRY_ACL_USER_OBJ
+The owner of the file.
+.It Dv ARCHIVE_ENTRY_ACL_GROUP
+The group specied by the name field.
+.It Dv ARCHIVE_ENTRY_ACL_GROUP_OBJ
+The group who owns the file.
+.It Dv ARCHIVE_ENTRY_ACL_MASK
+The maximum permissions to be obtained via group permissions.
+.It Dv ARCHIVE_ENTRY_ACL_OTHER
+Any principal who doesn't have a user or group entry.
+.El
+The principals
+.Dv ARCHIVE_ENTRY_ACL_USER_OBJ ,
+.Dv ARCHIVE_ENTRY_ACL_GROUP_OBJ
+and
+.Dv ARCHIVE_ENTRY_ACL_OTHER
+are equivalent to user, group and other in the classic Unix permission
+model and specify non-extended ACL entries.
+.Pp
+All files have an access ACL
+.Pq Dv ARCHIVE_ENTRY_ACL_TYPE_ACCESS .
+This specifies the permissions required for access to the file itself.
+Directories have an additional ACL
+.Pq Dv ARCHIVE_ENTRY_ACL_TYPE_DEFAULT ,
+which controls the initial access ACL for newly created directory entries.
+.Pp
+.Fn archive_entry_acl_add_entry
+and
+.Fn archive_entry_acl_add_entry_w
+add a single ACL entry.
+For the access ACL and non-extended principals, the classic Unix permissions
+are updated.
+.Pp
+.Fn archive_entry_acl_clear
+removes all ACL entries and resets the enumeration pointer.
+.Pp
+.Fn archive_entry_acl_count
+counts the ACL entries that have the given type mask.
+.Fa type
+can be the bitwise-or of
+.Dv ARCHIVE_ENTRY_ACL_TYPE_ACCESS
+and
+.Dv ARCHIVE_ENTRY_ACL_TYPE_DEFAULT .
+If
+.Dv ARCHIVE_ENTRY_ACL_TYPE_ACCESS
+is included and at least one extended ACL entry is found,
+the three non-extened ACLs are added.
+.Pp
+.Fn archive_entry_acl_next
+and
+.Fn archive_entry_acl_next_w
+return the next entry of the ACL list.
+This functions may only be called after
+.Fn archive_entry_acl_reset
+has indicated the presence of extended ACL entries.
+.Pp
+.Fn archive_entry_acl_reset
+prepare reading the list of ACL entries with
+.Fn archive_entry_acl_next
+or
+.Fn archive_entry_acl_next_w .
+The function returns either 0, if no non-extended ACLs are found.
+In this case, the access permissions should be obtained by
+.Xr archive_entry_mode 3
+or set using
+.Xr chmod 2 .
+Otherwise, the function returns the same value as
+.Fn archive_entry_acl_count .
+.Pp
+.Fn archive_entry_acl_text_w
+converts the ACL entries for the given type mask into a wide string.
+In addition to the normal type flags,
+.Dv ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID
+and
+.Dv ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT
+can be specified to further customize the result.
+The returned long string is valid until the next call to
+.Fn archive_entry_acl_clear ,
+.Fn archive_entry_acl_add_entry ,
+.Fn archive_entry_acl_add_entry_w
+or
+.Fn archive_entry_acl_text_w .
+.Sh RETURN VALUES
+.Fn archive_entry_acl_count
+and
+.Fn archive_entry_acl_reset
+returns the number of ACL entries that match the given type mask.
+If the type mask includes
+.Dv ARCHIVE_ENTRY_ACL_TYPE_ACCESS
+and at least one extended ACL entry exists, the three classic Unix
+permissions are counted.
+.Pp
+.Fn archive_entry_acl_next
+and
+.Fn archive_entry_acl_next_w
+return
+.Dv ARCHIVE_OK
+on success,
+.Dv ARCHIVE_EOF
+if no more ACL entries exist
+and
+.Dv ARCHIVE_WARN
+if
+.Fn archive_entry_acl_reset
+has not been called first.
+.Pp
+.Fn archive_entry_text_w
+returns a wide string representation of the ACL entrise matching the
+given type mask.
+The returned long string is valid until the next call to
+.Fn archive_entry_acl_clear ,
+.Fn archive_entry_acl_add_entry ,
+.Fn archive_entry_acl_add_entry_w
+or
+.Fn archive_entry_acl_text_w .
+.Sh SEE ALSO
+.Xr archive 3 ,
+.Xr archive_entry 3
+.Sh BUGS
+.Dv ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID
+and
+.Dv ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT
+are not documented.
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_copy_bhfi.c b/Utilities/cmlibarchive/libarchive/archive_entry_copy_bhfi.c
new file mode 100644
index 0000000000..77bf38e450
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_copy_bhfi.c
@@ -0,0 +1,75 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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$");
+
+#include "archive_private.h"
+#include "archive_entry.h"
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
+
+__inline static void
+fileTimeToUtc(const FILETIME *filetime, time_t *t, long *ns)
+{
+ ULARGE_INTEGER utc;
+
+ utc.HighPart = filetime->dwHighDateTime;
+ utc.LowPart = filetime->dwLowDateTime;
+ if (utc.QuadPart >= EPOC_TIME) {
+ utc.QuadPart -= EPOC_TIME;
+ *t = (time_t)(utc.QuadPart / 10000000); /* milli seconds base */
+ *ns = (long)(utc.QuadPart % 10000000) * 100;/* nano seconds base */
+ } else {
+ *t = 0;
+ *ns = 0;
+ }
+}
+
+void
+archive_entry_copy_bhfi(struct archive_entry *entry,
+ BY_HANDLE_FILE_INFORMATION *bhfi)
+{
+ time_t secs;
+ long nsecs;
+
+ fileTimeToUtc(&bhfi->ftLastAccessTime, &secs, &nsecs);
+ archive_entry_set_atime(entry, secs, nsecs);
+ fileTimeToUtc(&bhfi->ftLastWriteTime, &secs, &nsecs);
+ archive_entry_set_mtime(entry, secs, nsecs);
+ fileTimeToUtc(&bhfi->ftCreationTime, &secs, &nsecs);
+ archive_entry_set_birthtime(entry, secs, nsecs);
+ archive_entry_set_ctime(entry, secs, nsecs);
+ archive_entry_set_dev(entry, bhfi->dwVolumeSerialNumber);
+ archive_entry_set_ino64(entry, (((int64_t)bhfi->nFileIndexHigh) << 32)
+ + bhfi->nFileIndexLow);
+ archive_entry_set_nlink(entry, bhfi->nNumberOfLinks);
+ archive_entry_set_size(entry, (((int64_t)bhfi->nFileSizeHigh) << 32)
+ + bhfi->nFileSizeLow);
+ /* archive_entry_set_mode(entry, st->st_mode); */
+}
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_copy_stat.c b/Utilities/cmlibarchive/libarchive/archive_entry_copy_stat.c
new file mode 100644
index 0000000000..37d4d6edbd
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_copy_stat.c
@@ -0,0 +1,79 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_entry_copy_stat.c 189466 2009-03-07 00:52:02Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+
+void
+archive_entry_copy_stat(struct archive_entry *entry, const struct stat *st)
+{
+#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
+ archive_entry_set_atime(entry, st->st_atime, st->st_atimespec.tv_nsec);
+ archive_entry_set_ctime(entry, st->st_ctime, st->st_ctimespec.tv_nsec);
+ archive_entry_set_mtime(entry, st->st_mtime, st->st_mtimespec.tv_nsec);
+#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+ archive_entry_set_atime(entry, st->st_atime, st->st_atim.tv_nsec);
+ archive_entry_set_ctime(entry, st->st_ctime, st->st_ctim.tv_nsec);
+ archive_entry_set_mtime(entry, st->st_mtime, st->st_mtim.tv_nsec);
+#elif HAVE_STRUCT_STAT_ST_MTIME_N
+ archive_entry_set_atime(entry, st->st_atime, st->st_atime_n);
+ archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_n);
+ archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_n);
+#elif HAVE_STRUCT_STAT_ST_UMTIME
+ archive_entry_set_atime(entry, st->st_atime, st->st_uatime * 1000);
+ archive_entry_set_ctime(entry, st->st_ctime, st->st_uctime * 1000);
+ archive_entry_set_mtime(entry, st->st_mtime, st->st_umtime * 1000);
+#elif HAVE_STRUCT_STAT_ST_MTIME_USEC
+ archive_entry_set_atime(entry, st->st_atime, st->st_atime_usec * 1000);
+ archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_usec * 1000);
+ archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_usec * 1000);
+#else
+ archive_entry_set_atime(entry, st->st_atime, 0);
+ archive_entry_set_ctime(entry, st->st_ctime, 0);
+ archive_entry_set_mtime(entry, st->st_mtime, 0);
+#endif
+#if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
+ archive_entry_set_birthtime(entry, st->st_birthtime, st->st_birthtimespec.tv_nsec);
+#elif HAVE_STRUCT_STAT_ST_BIRTHTIME
+ archive_entry_set_birthtime(entry, st->st_birthtime, 0);
+#else
+ archive_entry_unset_birthtime(entry);
+#endif
+ archive_entry_set_dev(entry, st->st_dev);
+ archive_entry_set_gid(entry, st->st_gid);
+ archive_entry_set_uid(entry, st->st_uid);
+ archive_entry_set_ino(entry, st->st_ino);
+ archive_entry_set_nlink(entry, st->st_nlink);
+ archive_entry_set_rdev(entry, st->st_rdev);
+ archive_entry_set_size(entry, st->st_size);
+ archive_entry_set_mode(entry, st->st_mode);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_link_resolver.c b/Utilities/cmlibarchive/libarchive/archive_entry_link_resolver.c
new file mode 100644
index 0000000000..c7d59497a7
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_link_resolver.c
@@ -0,0 +1,447 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_entry_link_resolver.c 201100 2009-12-28 03:05:31Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#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
+
+#include "archive.h"
+#include "archive_entry.h"
+
+/*
+ * This is mostly a pretty straightforward hash table implementation.
+ * The only interesting bit is the different strategies used to
+ * match up links. These strategies match those used by various
+ * archiving formats:
+ * tar - content stored with first link, remainder refer back to it.
+ * This requires us to match each subsequent link up with the
+ * first appearance.
+ * cpio - Old cpio just stored body with each link, match-ups were
+ * implicit. This is trivial.
+ * new cpio - New cpio only stores body with last link, match-ups
+ * are implicit. This is actually quite tricky; see the notes
+ * below.
+ */
+
+/* Users pass us a format code, we translate that into a strategy here. */
+#define ARCHIVE_ENTRY_LINKIFY_LIKE_TAR 0
+#define ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE 1
+#define ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO 2
+#define ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO 3
+
+/* Initial size of link cache. */
+#define links_cache_initial_size 1024
+
+struct links_entry {
+ struct links_entry *next;
+ struct links_entry *previous;
+ struct archive_entry *canonical;
+ struct archive_entry *entry;
+ size_t hash;
+ unsigned int links; /* # links not yet seen */
+};
+
+struct archive_entry_linkresolver {
+ struct links_entry **buckets;
+ struct links_entry *spare;
+ unsigned long number_entries;
+ size_t number_buckets;
+ int strategy;
+};
+
+#define NEXT_ENTRY_DEFERRED 1
+#define NEXT_ENTRY_PARTIAL 2
+#define NEXT_ENTRY_ALL (NEXT_ENTRY_DEFERRED | NEXT_ENTRY_PARTIAL)
+
+static struct links_entry *find_entry(struct archive_entry_linkresolver *,
+ struct archive_entry *);
+static void grow_hash(struct archive_entry_linkresolver *);
+static struct links_entry *insert_entry(struct archive_entry_linkresolver *,
+ struct archive_entry *);
+static struct links_entry *next_entry(struct archive_entry_linkresolver *,
+ int);
+
+struct archive_entry_linkresolver *
+archive_entry_linkresolver_new(void)
+{
+ struct archive_entry_linkresolver *res;
+
+ /* Check for positive power-of-two */
+ if (links_cache_initial_size == 0 ||
+ (links_cache_initial_size & (links_cache_initial_size - 1)) != 0)
+ return (NULL);
+
+ res = calloc(1, sizeof(struct archive_entry_linkresolver));
+ if (res == NULL)
+ return (NULL);
+ res->number_buckets = links_cache_initial_size;
+ res->buckets = calloc(res->number_buckets, sizeof(res->buckets[0]));
+ if (res->buckets == NULL) {
+ free(res);
+ return (NULL);
+ }
+ return (res);
+}
+
+void
+archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *res,
+ int fmt)
+{
+ int fmtbase = fmt & ARCHIVE_FORMAT_BASE_MASK;
+
+ switch (fmtbase) {
+ case ARCHIVE_FORMAT_7ZIP:
+ case ARCHIVE_FORMAT_AR:
+ case ARCHIVE_FORMAT_ZIP:
+ res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO;
+ break;
+ case ARCHIVE_FORMAT_CPIO:
+ switch (fmt) {
+ case ARCHIVE_FORMAT_CPIO_SVR4_NOCRC:
+ case ARCHIVE_FORMAT_CPIO_SVR4_CRC:
+ res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO;
+ break;
+ default:
+ res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO;
+ break;
+ }
+ break;
+ case ARCHIVE_FORMAT_MTREE:
+ res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE;
+ break;
+ case ARCHIVE_FORMAT_ISO9660:
+ case ARCHIVE_FORMAT_SHAR:
+ case ARCHIVE_FORMAT_TAR:
+ case ARCHIVE_FORMAT_XAR:
+ res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_TAR;
+ break;
+ default:
+ res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO;
+ break;
+ }
+}
+
+void
+archive_entry_linkresolver_free(struct archive_entry_linkresolver *res)
+{
+ struct links_entry *le;
+
+ if (res == NULL)
+ return;
+
+ while ((le = next_entry(res, NEXT_ENTRY_ALL)) != NULL)
+ archive_entry_free(le->entry);
+ free(res->buckets);
+ free(res);
+}
+
+void
+archive_entry_linkify(struct archive_entry_linkresolver *res,
+ struct archive_entry **e, struct archive_entry **f)
+{
+ struct links_entry *le;
+ struct archive_entry *t;
+
+ *f = NULL; /* Default: Don't return a second entry. */
+
+ if (*e == NULL) {
+ le = next_entry(res, NEXT_ENTRY_DEFERRED);
+ if (le != NULL) {
+ *e = le->entry;
+ le->entry = NULL;
+ }
+ return;
+ }
+
+ /* If it has only one link, then we're done. */
+ if (archive_entry_nlink(*e) == 1)
+ return;
+ /* Directories, devices never have hardlinks. */
+ if (archive_entry_filetype(*e) == AE_IFDIR
+ || archive_entry_filetype(*e) == AE_IFBLK
+ || archive_entry_filetype(*e) == AE_IFCHR)
+ return;
+
+ switch (res->strategy) {
+ case ARCHIVE_ENTRY_LINKIFY_LIKE_TAR:
+ le = find_entry(res, *e);
+ if (le != NULL) {
+ archive_entry_unset_size(*e);
+ archive_entry_copy_hardlink(*e,
+ archive_entry_pathname(le->canonical));
+ } else
+ insert_entry(res, *e);
+ return;
+ case ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE:
+ le = find_entry(res, *e);
+ if (le != NULL) {
+ archive_entry_copy_hardlink(*e,
+ archive_entry_pathname(le->canonical));
+ } else
+ insert_entry(res, *e);
+ return;
+ case ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO:
+ /* This one is trivial. */
+ return;
+ case ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO:
+ le = find_entry(res, *e);
+ if (le != NULL) {
+ /*
+ * Put the new entry in le, return the
+ * old entry from le.
+ */
+ t = *e;
+ *e = le->entry;
+ le->entry = t;
+ /* Make the old entry into a hardlink. */
+ archive_entry_unset_size(*e);
+ archive_entry_copy_hardlink(*e,
+ archive_entry_pathname(le->canonical));
+ /* If we ran out of links, return the
+ * final entry as well. */
+ if (le->links == 0) {
+ *f = le->entry;
+ le->entry = NULL;
+ }
+ } else {
+ /*
+ * If we haven't seen it, tuck it away
+ * for future use.
+ */
+ le = insert_entry(res, *e);
+ if (le == NULL)
+ /* XXX We should return an error code XXX */
+ return;
+ le->entry = *e;
+ *e = NULL;
+ }
+ return;
+ default:
+ break;
+ }
+ return;
+}
+
+static struct links_entry *
+find_entry(struct archive_entry_linkresolver *res,
+ struct archive_entry *entry)
+{
+ struct links_entry *le;
+ size_t hash, bucket;
+ dev_t dev;
+ int64_t ino;
+
+ /* Free a held entry. */
+ if (res->spare != NULL) {
+ archive_entry_free(res->spare->canonical);
+ archive_entry_free(res->spare->entry);
+ free(res->spare);
+ res->spare = NULL;
+ }
+
+ dev = archive_entry_dev(entry);
+ ino = archive_entry_ino64(entry);
+ hash = (size_t)(dev ^ ino);
+
+ /* Try to locate this entry in the links cache. */
+ bucket = hash & (res->number_buckets - 1);
+ for (le = res->buckets[bucket]; le != NULL; le = le->next) {
+ if (le->hash == hash
+ && dev == archive_entry_dev(le->canonical)
+ && ino == archive_entry_ino64(le->canonical)) {
+ /*
+ * Decrement link count each time and release
+ * the entry if it hits zero. This saves
+ * memory and is necessary for detecting
+ * missed links.
+ */
+ --le->links;
+ if (le->links > 0)
+ return (le);
+ /* Remove it from this hash bucket. */
+ if (le->previous != NULL)
+ le->previous->next = le->next;
+ if (le->next != NULL)
+ le->next->previous = le->previous;
+ if (res->buckets[bucket] == le)
+ res->buckets[bucket] = le->next;
+ res->number_entries--;
+ /* Defer freeing this entry. */
+ res->spare = le;
+ return (le);
+ }
+ }
+ return (NULL);
+}
+
+static struct links_entry *
+next_entry(struct archive_entry_linkresolver *res, int mode)
+{
+ struct links_entry *le;
+ size_t bucket;
+
+ /* Free a held entry. */
+ if (res->spare != NULL) {
+ archive_entry_free(res->spare->canonical);
+ archive_entry_free(res->spare->entry);
+ free(res->spare);
+ res->spare = NULL;
+ }
+
+ /* Look for next non-empty bucket in the links cache. */
+ for (bucket = 0; bucket < res->number_buckets; bucket++) {
+ for (le = res->buckets[bucket]; le != NULL; le = le->next) {
+ if (le->entry != NULL &&
+ (mode & NEXT_ENTRY_DEFERRED) == 0)
+ continue;
+ if (le->entry == NULL &&
+ (mode & NEXT_ENTRY_PARTIAL) == 0)
+ continue;
+ /* Remove it from this hash bucket. */
+ if (le->next != NULL)
+ le->next->previous = le->previous;
+ if (le->previous != NULL)
+ le->previous->next = le->next;
+ else
+ res->buckets[bucket] = le->next;
+ res->number_entries--;
+ /* Defer freeing this entry. */
+ res->spare = le;
+ return (le);
+ }
+ }
+ return (NULL);
+}
+
+static struct links_entry *
+insert_entry(struct archive_entry_linkresolver *res,
+ struct archive_entry *entry)
+{
+ struct links_entry *le;
+ size_t hash, bucket;
+
+ /* Add this entry to the links cache. */
+ le = calloc(1, sizeof(struct links_entry));
+ if (le == NULL)
+ return (NULL);
+ le->canonical = archive_entry_clone(entry);
+
+ /* If the links cache is getting too full, enlarge the hash table. */
+ if (res->number_entries > res->number_buckets * 2)
+ grow_hash(res);
+
+ hash = (size_t)(archive_entry_dev(entry) ^ archive_entry_ino64(entry));
+ bucket = hash & (res->number_buckets - 1);
+
+ /* If we could allocate the entry, record it. */
+ if (res->buckets[bucket] != NULL)
+ res->buckets[bucket]->previous = le;
+ res->number_entries++;
+ le->next = res->buckets[bucket];
+ le->previous = NULL;
+ res->buckets[bucket] = le;
+ le->hash = hash;
+ le->links = archive_entry_nlink(entry) - 1;
+ return (le);
+}
+
+static void
+grow_hash(struct archive_entry_linkresolver *res)
+{
+ struct links_entry *le, **new_buckets;
+ size_t new_size;
+ size_t i, bucket;
+
+ /* Try to enlarge the bucket list. */
+ new_size = res->number_buckets * 2;
+ if (new_size < res->number_buckets)
+ return;
+ new_buckets = calloc(new_size, sizeof(struct links_entry *));
+
+ if (new_buckets == NULL)
+ return;
+
+ for (i = 0; i < res->number_buckets; i++) {
+ while (res->buckets[i] != NULL) {
+ /* Remove entry from old bucket. */
+ le = res->buckets[i];
+ res->buckets[i] = le->next;
+
+ /* Add entry to new bucket. */
+ bucket = le->hash & (new_size - 1);
+
+ if (new_buckets[bucket] != NULL)
+ new_buckets[bucket]->previous = le;
+ le->next = new_buckets[bucket];
+ le->previous = NULL;
+ new_buckets[bucket] = le;
+ }
+ }
+ free(res->buckets);
+ res->buckets = new_buckets;
+ res->number_buckets = new_size;
+}
+
+struct archive_entry *
+archive_entry_partial_links(struct archive_entry_linkresolver *res,
+ unsigned int *links)
+{
+ struct archive_entry *e;
+ struct links_entry *le;
+
+ /* Free a held entry. */
+ if (res->spare != NULL) {
+ archive_entry_free(res->spare->canonical);
+ archive_entry_free(res->spare->entry);
+ free(res->spare);
+ res->spare = NULL;
+ }
+
+ le = next_entry(res, NEXT_ENTRY_PARTIAL);
+ if (le != NULL) {
+ e = le->canonical;
+ if (links != NULL)
+ *links = le->links;
+ le->canonical = NULL;
+ } else {
+ e = NULL;
+ if (links != NULL)
+ *links = 0;
+ }
+ return (e);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_linkify.3 b/Utilities/cmlibarchive/libarchive/archive_entry_linkify.3
new file mode 100644
index 0000000000..8c19fddb6e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_linkify.3
@@ -0,0 +1,224 @@
+.\" Copyright (c) 2010 Joerg Sonnenberger
+.\" 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 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 AUTHOR 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.
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_ENTRY_LINKIFY 3
+.Os
+.Sh NAME
+.Nm archive_entry_linkresolver ,
+.Nm archive_entry_linkresolver_new ,
+.Nm archive_entry_linkresolver_set_strategy ,
+.Nm archive_entry_linkresolver_free ,
+.Nm archive_entry_linkify
+.Nd hardlink resolver functions
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive_entry.h
+.Ft struct archive_entry_linkresolver *
+.Fn archive_entry_linkresolver_new void
+.Ft void
+.Fo archive_entry_linkresolver_set_strategy
+.Fa "struct archive_entry_linkresolver *resolver"
+.Fa "int format"
+.Fc
+.Ft void
+.Fo archive_entry_linkresolver_free
+.Fa "struct archive_entry_linkresolver *resolver"
+.Fc
+.Ft void
+.Fo archive_entry_linkify
+.Fa "struct archive_entry_linkresolver *resolver"
+.Fa "struct archive_entry **entry"
+.Fa "struct archive_entry **sparse"
+.Fc
+.Sh DESCRIPTION
+Programs that want to create archives have to deal with hardlinks.
+Hardlinks are handled in different ways by the archive formats.
+The basic strategies are:
+.Bl -enum
+.It
+Ignore hardlinks and store the body for each reference (old cpio, zip).
+.It
+Store the body the first time an inode is seen (ustar, pax).
+.It
+Store the body the last time an inode is seen (new cpio).
+.El
+.Pp
+The
+.Nm
+functions help by providing a unified interface and handling the complexity
+behind the scene.
+.Pp
+The
+.Nm
+functions assume that
+.Vt archive_entry
+instances have valid nlinks, inode and device values.
+The inode and device value is used to match entries.
+The nlinks value is used to determined if all references have been found and
+if the internal references can be recycled.
+.Pp
+The
+.Fn archive_entry_linkresolver_new
+function allocates a new link resolver.
+The instance can be freed using
+.Fn archive_entry_linkresolver_free .
+All deferred entries are flushed and the internal storage is freed.
+.Pp
+The
+.Fn archive_entry_linkresolver_set_strategy
+function selects the optimal hardlink strategy for the given format.
+The format code can be obtained from
+.Xr archive_format 3 .
+The function can be called more than once, but it is recommended to
+flush all deferred entries first.
+.Pp
+The
+.Fn archive_entry_linkify
+function is the core of
+.Nm .
+The
+.Fn entry
+argument points to the
+.Vt archive_entry
+that should be written.
+Depending on the strategy one of the following actions is taken:
+.Bl -enum
+.It
+For the simple archive formats
+.Va *entry
+is left unmodified and
+.Va *sparse
+is set to
+.Dv NULL .
+.It
+For tar like archive formats,
+.Va *sparse
+is set to
+.Dv NULL .
+If
+.Va *entry
+is
+.Dv NULL ,
+no action is taken.
+If the hardlink count of
+.Va *entry
+is larger than 1 and the file type is a regular file or symbolic link,
+the internal list is searched for a matching inode.
+If such an inode is found, the link count is decremented and the file size
+of
+.Va *entry
+is set to 0 to notify that no body should be written.
+If no such inode is found, a copy of the entry is added to the internal cache
+with a link count reduced by one.
+.It
+For new cpio like archive formats a value for
+.Va *entry
+of
+.Dv NULL
+is used to flush deferred entries.
+In that case
+.Va *entry
+is set to an arbitrary deferred entry and the entry itself is removed from the
+internal list.
+If the internal list is empty,
+.Va *entry
+is set to
+.Dv NULL .
+In either case,
+.Va *sparse
+is set to
+.Dv NULL
+and the function returns.
+If the hardlink count of
+.Va *entry
+is one or the file type is a directory or device,
+.Va *sparse
+is set to
+.Dv NULL
+and no further action is taken.
+Otherwise, the internal list is searched for a matching inode.
+If such an inode is not found, the entry is added to the internal list,
+both
+.Va *entry
+and
+.Va *sparse
+are set to
+.Dv NULL
+and the function returns.
+If such an inode is found, the link count is decremented.
+If it remains larger than one, the existing entry on the internal list
+is swapped with
+.Va *entry
+after retaining the link count.
+The existing entry is returned in
+.Va *entry .
+If the link count reached one, the new entry is also removed from the
+internal list and returned in
+.Va *sparse .
+Otherwise
+.Va *sparse
+is set to
+.Dv NULL .
+.El
+.Pp
+The general usage is therefore:
+.Bl -enum
+.It
+For each new archive entry, call
+.Fn archive_entry_linkify .
+.It
+Keep in mind that the entries returned may have a size of 0 now.
+.It
+If
+.Va *entry
+is not
+.Dv NULL ,
+archive it.
+.It
+If
+.Va *sparse
+is not
+.Dv NULL ,
+archive it.
+.It
+After all entries have been written to disk, call
+.Fn archive_entry_linkify
+with
+.Va *entry
+set to
+.Dv NULL
+and archive the returned entry as long as it is not
+.Dv NULL .
+.El
+.Sh RETURN VALUES
+.Fn archive_entry_linkresolver_new
+returns
+.Dv NULL
+on
+.Xr malloc 3
+failures.
+.Sh SEE ALSO
+.Xr archive_entry 3
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_locale.h b/Utilities/cmlibarchive/libarchive/archive_entry_locale.h
new file mode 100644
index 0000000000..02e024ae20
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_locale.h
@@ -0,0 +1,88 @@
+/*-
+ * Copyright (c) 2011 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_ENTRY_LOCALE_H_INCLUDED
+#define ARCHIVE_ENTRY_LOCALE_H_INCLUDED
+
+struct archive_entry;
+struct archive_string_conv;
+
+/*
+ * Utility functions to set and get entry attributes by translating
+ * character-set. These are designed for use in format readers and writers.
+ *
+ * The return code and interface of these are quite different from other
+ * functions for archive_entry defined in archive_entry.h.
+ * Common return code are:
+ * Return 0 if the string conversion succeeded.
+ * Return -1 if the string conversion failed.
+ */
+
+#define archive_entry_gname_l _archive_entry_gname_l
+int _archive_entry_gname_l(struct archive_entry *,
+ const char **, size_t *, struct archive_string_conv *);
+#define archive_entry_hardlink_l _archive_entry_hardlink_l
+int _archive_entry_hardlink_l(struct archive_entry *,
+ const char **, size_t *, struct archive_string_conv *);
+#define archive_entry_pathname_l _archive_entry_pathname_l
+int _archive_entry_pathname_l(struct archive_entry *,
+ const char **, size_t *, struct archive_string_conv *);
+#define archive_entry_symlink_l _archive_entry_symlink_l
+int _archive_entry_symlink_l(struct archive_entry *,
+ const char **, size_t *, struct archive_string_conv *);
+#define archive_entry_uname_l _archive_entry_uname_l
+int _archive_entry_uname_l(struct archive_entry *,
+ const char **, size_t *, struct archive_string_conv *);
+#define archive_entry_acl_text_l _archive_entry_acl_text_l
+int _archive_entry_acl_text_l(struct archive_entry *, int,
+ const char **, size_t *, struct archive_string_conv *);
+
+
+#define archive_entry_copy_gname_l _archive_entry_copy_gname_l
+int _archive_entry_copy_gname_l(struct archive_entry *,
+ const char *, size_t, struct archive_string_conv *);
+#define archive_entry_copy_hardlink_l _archive_entry_copy_hardlink_l
+int _archive_entry_copy_hardlink_l(struct archive_entry *,
+ const char *, size_t, struct archive_string_conv *);
+#define archive_entry_copy_link_l _archive_entry_copy_link_l
+int _archive_entry_copy_link_l(struct archive_entry *,
+ const char *, size_t, struct archive_string_conv *);
+#define archive_entry_copy_pathname_l _archive_entry_copy_pathname_l
+int _archive_entry_copy_pathname_l(struct archive_entry *,
+ const char *, size_t, struct archive_string_conv *);
+#define archive_entry_copy_symlink_l _archive_entry_copy_symlink_l
+int _archive_entry_copy_symlink_l(struct archive_entry *,
+ const char *, size_t, struct archive_string_conv *);
+#define archive_entry_copy_uname_l _archive_entry_copy_uname_l
+int _archive_entry_copy_uname_l(struct archive_entry *,
+ const char *, size_t, struct archive_string_conv *);
+
+#endif /* ARCHIVE_ENTRY_LOCALE_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3
new file mode 100644
index 0000000000..51c8b8c8e6
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3
@@ -0,0 +1,153 @@
+.\" Copyright (c) 2010 Joerg Sonnenberger
+.\" 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 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 AUTHOR 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.
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_ENTRY_PATHS 3
+.Os
+.Sh NAME
+.Nm archive_entry_hardlink ,
+.Nm archive_entry_hardlink_w ,
+.Nm archive_entry_set_hardlink ,
+.Nm archive_entry_copy_hardlink ,
+.Nm archive_entry_copy_hardlink_w ,
+.Nm archve_entry_update_hardlink_utf8 ,
+.Nm archive_entry_set_link ,
+.Nm archive_entry_copy_link ,
+.Nm archive_entry_copy_link_w ,
+.Nm archve_entry_update_link_utf8 ,
+.Nm archive_entry_pathname ,
+.Nm archive_entry_pathname_w ,
+.Nm archive_entry_set_pathname ,
+.Nm archive_entry_copy_pathname ,
+.Nm archive_entry_copy_pathname_w ,
+.Nm archve_entry_update_pathname_utf8 ,
+.Nm archive_entry_sourcepath ,
+.Nm archive_entry_copy_sourcepath ,
+.Nm archive_entry_symlink,
+.Nm archive_entry_symlink_w,
+.Nm archive_entry_set_symlink ,
+.Nm archive_entry_copy_symlink ,
+.Nm archive_entry_copy_symlink_w ,
+.Nm archve_entry_update_symlink_utf8
+.Nd functions for manipulating path names in archive entry descriptions
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive_entry.h
+.Ft const char *
+.Fn archive_entry_hardlink "struct archive_entry *a"
+.Ft const wchar_t *
+.Fn archive_entry_hardlink_w "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_hardlink "struct archive_entry *a" "const char *path"
+.Ft void
+.Fn archive_entry_copy_hardlink "struct archive_entry *a" "const char *path"
+.Ft void
+.Fn archive_entry_copy_hardlink_w "struct archive_entry *a "const wchar_t *path"
+.Ft int
+.Fn archive_entry_update_hardlink_utf8 "struct archive_entry *a" "const char *path"
+.Ft void
+.Fn archive_entry_set_link "struct archive_entry *a" "const char *path"
+.Ft void
+.Fn archive_entry_copy_link "struct archive_entry *a" " const char *path"
+.Ft void
+.Fn archive_entry_copy_link_w "struct archive_entry *a" " const wchar_t *path"
+.Ft int
+.Fn archive_entry_update_link_utf8 "struct archive_entry *a" " const char *path"
+.Ft const char *
+.Fn archive_entry_pathname "struct archive_entry *a"
+.Ft const wchar_t *
+.Fn archive_entry_pathname_w "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_pathname "struct archive_entry *a" "const char *path"
+.Ft void
+.Fn archive_entry_copy_pathname "struct archive_entry *a" "const char *path"
+.Ft void
+.Fn archive_entry_copy_pathname_w "struct archive_entry *a" "const wchar_t *path"
+.Ft int
+.Fn archive_entry_update_pathname_utf8 "struct archive_entry *a" "const char *path"
+.Ft const char *
+.Fn archive_entry_sourcepath "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_copy_sourcepath "struct archive_entry *a" "const char *path"
+.Ft const char *
+.Fn archive_entry_symlink "struct archive_entry *a"
+.Ft const wchar_t *
+.Fn archive_entry_symlink_w "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_symlink "struct archive_entry *a" "const char *path"
+.Ft void
+.Fn archive_entry_copy_symlink "struct archive_entry *a" "const char *path"
+.Ft void
+.Fn archive_entry_copy_symlink_w "struct archive_entry *a" "const wchar_t *path"
+.Ft int
+.Fn archive_entry_update_symlink_utf8 "struct archive_entry *a" "const char *path"
+.Sh DESCRIPTION
+Path names supported by
+.Xr archive_entry 3 :
+.Bl -tag -width "sourcepath" -compact
+.It hardlink
+Destination of the hardlink.
+.It link
+Update only.
+For a symlink, update the destination.
+Otherwise, make the entry a hardlink and alter
+the destination for that.
+.It pathname
+Path in the archive
+.It sourcepath
+Path on the disk for use by
+.Xr archive_read_disk 3 .
+.It symlink
+Destination of the symbolic link.
+.El
+.Pp
+Path names can be provided in one of three different ways:
+.Bl -tag -width "wchar_t *"
+.It char *
+Multibyte strings in the current locale.
+.It wchar_t *
+Wide character strings in the current locale.
+The accessor functions are named
+.Fn XXX_w .
+.It UTF-8
+Unicode strings encoded as UTF-8.
+This are convience functions to update both the multibyte and wide
+character strings at the same time.
+.El
+.Pp
+The sourcepath is a pure filesystem concept and never stored in an
+archive directly.
+.Pp
+For that reason, it is only available as multibyte string.
+The link path is a convience function for conditionally setting
+hardlink or symlink destination.
+It doesn't have a corresponding get accessor function.
+.Pp
+.Fn archive_entry_set_XXX
+is an alias for
+.Fn archive_entry_copy_XXX .
+.Sh SEE ALSO
+.Xr archive 3 ,
+.Xr archive_entry 3
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3
new file mode 100644
index 0000000000..5b7b5d955a
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3
@@ -0,0 +1,209 @@
+.\" Copyright (c) 2003-2007 Tim Kientzle
+.\" Copyright (c) 2010 Joerg Sonnenberger
+.\" 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 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 AUTHOR 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.
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_ENTRY_PERMS 3
+.Os
+.Sh NAME
+.Nm archive_entry_gid ,
+.Nm archive_entry_set_gid ,
+.Nm archive_entry_uid ,
+.Nm archive_entry_set_uid ,
+.Nm archive_entry_perm ,
+.Nm archive_entry_set_perm ,
+.Nm archive_entry_strmode ,
+.Nm archive_entry_uname
+.Nm archive_entry_uname_w
+.Nm archive_entry_set_uname ,
+.Nm archive_entry_copy_uname ,
+.Nm archive_entry_copy_uname_w ,
+.Nm archive_entry_update_uname_utf8 ,
+.Nm archive_entry_gname ,
+.Nm archive_entry_gname_w ,
+.Nm archive_entry_set_gname ,
+.Nm archive_entry_copy_gname ,
+.Nm archive_entry_copy_gname_w ,
+.Nm archive_entry_update_gname_utf8 ,
+.Nm archive_entry_fflags ,
+.Nm archive_entry_fflags_text ,
+.Nm archive_entry_set_fflags ,
+.Nm archive_entry_copy_fflags_text ,
+.Nm archive_entry_copy_fflags_text_w
+.Nd functions for manipulating ownership and permissions in archive entry descriptions
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive_entry.h
+.Ft gid_t
+.Fn archive_entry_gid "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_gid "struct archive_entry *a" "gid_t gid"
+.Ft uid_t
+.Fn archive_entry_uid "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_uid "struct archive_entry *a" "uid_t uid"
+.Ft mode_t
+.Fn archive_entry_perm "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_perm "struct archive_entry *a" "mode_t mode"
+.Ft const char *
+.Fn archive_entry_strmode "struct archive_entry *a"
+.Ft const char *
+.Fn archive_entry_gname "struct archive_entry *a"
+.Ft const wchar_t *
+.Fn archive_entry_gname_w "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_gname "struct archive_entry *a" "const char *a"
+.Ft void
+.Fn archive_entry_copy_gname "struct archive_entry *a" "const char *name"
+.Ft void
+.Fn archive_entry_copy_gname_w "struct archive_entry *a" "const wchar_t *name"
+.Ft int
+.Fn archive_entry_update_gname_utf8 "struct archive_entry *a" "const char *name"
+.Ft const char *
+.Fn archive_entry_uname "struct archive_entry *a"
+.Ft const wchar_t *
+.Fn archive_entry_uname_w "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_uname "struct archive_entry *a" "const char *name"
+.Ft void
+.Fn archive_entry_copy_uname "struct archive_entry *a" "const char *name"
+.Ft void
+.Fn archive_entry_copy_uname_w "struct archive_entry *a" "const wchar_t *name"
+.Ft int
+.Fn archive_entry_update_uname_utf8 "struct archive_entry *a" "const char *name"
+.Ft void
+.Fo archive_entry_fflags
+.Fa "struct archive_entry *a"
+.Fa "unsigned long *set_bits"
+.Fa "unsigned long *clear_bits"
+.Fc
+.Ft const char *
+.Fn archive_entry_fflags_text "struct archive_entry *a"
+.Ft void
+.Fo archive_entry_set_fflags
+.Fa "struct archive_entry *a"
+.Fa "unsigned long set_bits"
+.Fa "unsigned long clear_bits"
+.Fc
+.Ft const char *
+.Fn archive_entry_copy_fflags_text "struct archive_entry *a" "const char *text"
+.Ft const wchar_t *
+.Fn archive_entry_copy_fflags_text_w "struct archive_entry *a" "const wchar_t *text"
+.Sh DESCRIPTION
+.Ss User id, group id and mode
+The functions
+.Fn archive_entry_uid ,
+.Fn archive_entry_gid ,
+and
+.Fn archive_entry_perm
+can be used to extract the user id, group id and permission from the given entry.
+The corresponding functions
+.Fn archive_entry_set_uid ,
+.Fn archive_entry_set_gid ,
+and
+.Fn archive_entry_set_perm
+store the given user id, group id and permission in the entry.
+The permission is also set as side effect of calling
+.Fn archive_entry_set_mode .
+.Pp
+.Fn archive_entry_strmode
+returns a string representation of the permission as used by the long mode of
+.Xr ls 1 .
+.Ss User and group name
+User and group names can be provided in one of three different ways:
+.Bl -tag -width "wchar_t *"
+.It char *
+Multibyte strings in the current locale.
+.It wchar_t *
+Wide character strings in the current locale.
+The accessor functions are named
+.Fn XXX_w .
+.It UTF-8
+Unicode strings encoded as UTF-8.
+This are convience functions to update both the multibyte and wide
+character strings at the same time.
+.El
+.Pp
+.Fn archive_entry_set_XXX
+is an alias for
+.Fn archive_entry_copy_XXX .
+.Ss File Flags
+File flags are transparently converted between a bitmap
+representation and a textual format.
+For example, if you set the bitmap and ask for text, the library
+will build a canonical text format.
+However, if you set a text format and request a text format,
+you will get back the same text, even if it is ill-formed.
+If you need to canonicalize a textual flags string, you should first set the
+text form, then request the bitmap form, then use that to set the bitmap form.
+Setting the bitmap format will clear the internal text representation
+and force it to be reconstructed when you next request the text form.
+.Pp
+The bitmap format consists of two integers, one containing bits
+that should be set, the other specifying bits that should be
+cleared.
+Bits not mentioned in either bitmap will be ignored.
+Usually, the bitmap of bits to be cleared will be set to zero.
+In unusual circumstances, you can force a fully-specified set
+of file flags by setting the bitmap of flags to clear to the complement
+of the bitmap of flags to set.
+(This differs from
+.Xr fflagstostr 3 ,
+which only includes names for set bits.)
+Converting a bitmap to a textual string is a platform-specific
+operation; bits that are not meaningful on the current platform
+will be ignored.
+.Pp
+The canonical text format is a comma-separated list of flag names.
+The
+.Fn archive_entry_copy_fflags_text
+and
+.Fn archive_entry_copy_fflags_text_w
+functions parse the provided text and sets the internal bitmap values.
+This is a platform-specific operation; names that are not meaningful
+on the current platform will be ignored.
+The function returns a pointer to the start of the first name that was not
+recognized, or NULL if every name was recognized.
+Note that every name \(em including names that follow an unrecognized
+name \(em will be evaluated, and the bitmaps will be set to reflect
+every name that is recognized.
+(In particular, this differs from
+.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
+.Sh BUGS
+The platform types
+.Vt uid_t
+and
+.Vt gid_t
+are often 16 or 32 bit wide.
+In this case it is possible that the ids can not be correctly restored
+from archives and get truncated.
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_private.h b/Utilities/cmlibarchive/libarchive/archive_entry_private.h
new file mode 100644
index 0000000000..c69233e68b
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_private.h
@@ -0,0 +1,181 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_entry_private.h 201096 2009-12-28 02:41:27Z kientzle $
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_ENTRY_PRIVATE_H_INCLUDED
+#define ARCHIVE_ENTRY_PRIVATE_H_INCLUDED
+
+#include "archive_acl_private.h"
+#include "archive_string.h"
+
+struct ae_xattr {
+ struct ae_xattr *next;
+
+ char *name;
+ void *value;
+ size_t size;
+};
+
+struct ae_sparse {
+ struct ae_sparse *next;
+
+ int64_t offset;
+ int64_t length;
+};
+
+/*
+ * Description of an archive entry.
+ *
+ * Basically, this is a "struct stat" with a few text fields added in.
+ *
+ * TODO: Add "comment", "charset", and possibly other entries
+ * that are supported by "pax interchange" format. However, GNU, ustar,
+ * cpio, and other variants don't support these features, so they're not an
+ * excruciatingly high priority right now.
+ *
+ * TODO: "pax interchange" format allows essentially arbitrary
+ * key/value attributes to be attached to any entry. Supporting
+ * such extensions may make this library useful for special
+ * applications (e.g., a package manager could attach special
+ * package-management attributes to each entry). There are tricky
+ * API issues involved, so this is not going to happen until
+ * there's a real demand for it.
+ *
+ * TODO: Design a good API for handling sparse files.
+ */
+struct archive_entry {
+ struct archive *archive;
+
+ /*
+ * Note that ae_stat.st_mode & AE_IFMT can be 0!
+ *
+ * This occurs when the actual file type of the object is not
+ * in the archive. For example, 'tar' archives store
+ * hardlinks without marking the type of the underlying
+ * object.
+ */
+
+ /*
+ * We have a "struct aest" for holding file metadata rather than just
+ * a "struct stat" because on some platforms the "struct stat" has
+ * fields which are too narrow to hold the range of possible values;
+ * we don't want to lose information if we read an archive and write
+ * out another (e.g., in "tar -cf new.tar @old.tar").
+ *
+ * The "stat" pointer points to some form of platform-specific struct
+ * stat; it is declared as a void * rather than a struct stat * as
+ * some platforms have multiple varieties of stat structures.
+ */
+ void *stat;
+ int stat_valid; /* Set to 0 whenever a field in aest changes. */
+
+ struct aest {
+ int64_t aest_atime;
+ uint32_t aest_atime_nsec;
+ int64_t aest_ctime;
+ uint32_t aest_ctime_nsec;
+ int64_t aest_mtime;
+ uint32_t aest_mtime_nsec;
+ int64_t aest_birthtime;
+ uint32_t aest_birthtime_nsec;
+ int64_t aest_gid;
+ int64_t aest_ino;
+ uint32_t aest_nlink;
+ uint64_t aest_size;
+ int64_t aest_uid;
+ /*
+ * Because converting between device codes and
+ * major/minor values is platform-specific and
+ * inherently a bit risky, we only do that conversion
+ * lazily. That way, we will do a better job of
+ * preserving information in those cases where no
+ * conversion is actually required.
+ */
+ int aest_dev_is_broken_down;
+ dev_t aest_dev;
+ dev_t aest_devmajor;
+ dev_t aest_devminor;
+ int aest_rdev_is_broken_down;
+ dev_t aest_rdev;
+ dev_t aest_rdevmajor;
+ dev_t aest_rdevminor;
+ } ae_stat;
+
+ int ae_set; /* bitmap of fields that are currently set */
+#define AE_SET_HARDLINK 1
+#define AE_SET_SYMLINK 2
+#define AE_SET_ATIME 4
+#define AE_SET_CTIME 8
+#define AE_SET_MTIME 16
+#define AE_SET_BIRTHTIME 32
+#define AE_SET_SIZE 64
+#define AE_SET_INO 128
+#define AE_SET_DEV 256
+
+ /*
+ * Use aes here so that we get transparent mbs<->wcs conversions.
+ */
+ struct archive_mstring ae_fflags_text; /* Text fflags per fflagstostr(3) */
+ unsigned long ae_fflags_set; /* Bitmap fflags */
+ unsigned long ae_fflags_clear;
+ struct archive_mstring ae_gname; /* Name of owning group */
+ struct archive_mstring ae_hardlink; /* Name of target for hardlink */
+ struct archive_mstring ae_pathname; /* Name of entry */
+ struct archive_mstring ae_symlink; /* symlink contents */
+ struct archive_mstring ae_uname; /* Name of owner */
+
+ /* Not used within libarchive; useful for some clients. */
+ struct archive_mstring ae_sourcepath; /* Path this entry is sourced from. */
+
+#define AE_ENCRYPTION_NONE 0
+#define AE_ENCRYPTION_DATA 1
+#define AE_ENCRYPTION_METADATA 2
+ char encryption;
+
+ void *mac_metadata;
+ size_t mac_metadata_size;
+
+ /* ACL support. */
+ struct archive_acl acl;
+
+ /* extattr support. */
+ struct ae_xattr *xattr_head;
+ struct ae_xattr *xattr_p;
+
+ /* sparse support. */
+ struct ae_sparse *sparse_head;
+ struct ae_sparse *sparse_tail;
+ struct ae_sparse *sparse_p;
+
+ /* Miscellaneous. */
+ char strmode[12];
+};
+
+#endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c b/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c
new file mode 100644
index 0000000000..fed74f5121
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c
@@ -0,0 +1,156 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2010-2011 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$");
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_entry_private.h"
+
+/*
+ * sparse handling
+ */
+
+void
+archive_entry_sparse_clear(struct archive_entry *entry)
+{
+ struct ae_sparse *sp;
+
+ while (entry->sparse_head != NULL) {
+ sp = entry->sparse_head->next;
+ free(entry->sparse_head);
+ entry->sparse_head = sp;
+ }
+ entry->sparse_tail = NULL;
+}
+
+void
+archive_entry_sparse_add_entry(struct archive_entry *entry,
+ int64_t offset, int64_t length)
+{
+ struct ae_sparse *sp;
+
+ if (offset < 0 || length < 0)
+ /* Invalid value */
+ return;
+ if (offset > INT64_MAX - length ||
+ offset + length > archive_entry_size(entry))
+ /* A value of "length" parameter is too large. */
+ return;
+ if ((sp = entry->sparse_tail) != NULL) {
+ if (sp->offset + sp->length > offset)
+ /* Invalid value. */
+ return;
+ if (sp->offset + sp->length == offset) {
+ if (sp->offset + sp->length + length < 0)
+ /* A value of "length" parameter is
+ * too large. */
+ return;
+ /* Expand existing sparse block size. */
+ sp->length += length;
+ return;
+ }
+ }
+
+ if ((sp = (struct ae_sparse *)malloc(sizeof(*sp))) == NULL)
+ /* XXX Error XXX */
+ return;
+
+ sp->offset = offset;
+ sp->length = length;
+ sp->next = NULL;
+
+ if (entry->sparse_head == NULL)
+ entry->sparse_head = entry->sparse_tail = sp;
+ else {
+ /* Add a new sparse block to the tail of list. */
+ if (entry->sparse_tail != NULL)
+ entry->sparse_tail->next = sp;
+ entry->sparse_tail = sp;
+ }
+}
+
+
+/*
+ * returns number of the sparse entries
+ */
+int
+archive_entry_sparse_count(struct archive_entry *entry)
+{
+ struct ae_sparse *sp;
+ int count = 0;
+
+ for (sp = entry->sparse_head; sp != NULL; sp = sp->next)
+ count++;
+
+ /*
+ * Sanity check if this entry is exactly sparse.
+ * If amount of sparse blocks is just one and it indicates the whole
+ * file data, we should remove it and return zero.
+ */
+ if (count == 1) {
+ sp = entry->sparse_head;
+ if (sp->offset == 0 &&
+ sp->length >= archive_entry_size(entry)) {
+ count = 0;
+ archive_entry_sparse_clear(entry);
+ }
+ }
+
+ return (count);
+}
+
+int
+archive_entry_sparse_reset(struct archive_entry * entry)
+{
+ entry->sparse_p = entry->sparse_head;
+
+ return archive_entry_sparse_count(entry);
+}
+
+int
+archive_entry_sparse_next(struct archive_entry * entry,
+ int64_t *offset, int64_t *length)
+{
+ if (entry->sparse_p) {
+ *offset = entry->sparse_p->offset;
+ *length = entry->sparse_p->length;
+
+ entry->sparse_p = entry->sparse_p->next;
+
+ return (ARCHIVE_OK);
+ } else {
+ *offset = 0;
+ *length = 0;
+ return (ARCHIVE_WARN);
+ }
+}
+
+/*
+ * end of sparse handling
+ */
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_stat.3 b/Utilities/cmlibarchive/libarchive/archive_entry_stat.3
new file mode 100644
index 0000000000..84a4ea12a0
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_stat.3
@@ -0,0 +1,274 @@
+.\" Copyright (c) 2010 Joerg Sonnenberger
+.\" 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 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 AUTHOR 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.
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_ENTRY_STAT 3
+.Os
+.Sh NAME
+.Nm archive_entry_stat ,
+.Nm archive_entry_copy_stat ,
+.Nm archive_entry_filetype ,
+.Nm archive_entry_set_filetype ,
+.Nm archive_entry_mode ,
+.Nm archive_entry_set_mode ,
+.Nm archive_entry_size ,
+.Nm archive_entry_size_is_set ,
+.Nm archive_entry_set_size ,
+.Nm archive_entry_unset_size ,
+.Nm archive_entry_dev ,
+.Nm archive_entry_set_dev ,
+.Nm archive_entry_dev_is_set ,
+.Nm archive_entry_devmajor ,
+.Nm archive_entry_set_devmajor ,
+.Nm archive_entry_devminor ,
+.Nm archive_entry_set_devminor ,
+.Nm archive_entry_ino ,
+.Nm archive_entry_set_ino ,
+.Nm archive_entry_ino_is_set ,
+.Nm archive_entry_ino64 ,
+.Nm archive_entry_set_ino64 ,
+.Nm archive_entry_nlink ,
+.Nm archive_entry_rdev ,
+.Nm archive_entry_set_rdev ,
+.Nm archive_entry_rdevmajor ,
+.Nm archive_entry_set_rdevmajor ,
+.Nm archive_entry_rdevminor ,
+.Nm archive_entry_set_rdevminor ,
+.Nd accessor functions for manipulating archive entry descriptions
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive_entry.h
+.Ft const struct stat *
+.Fn archive_entry_stat "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_copy_stat "struct archive_entry *a" "const struct stat *sb"
+.Ft mode_t
+.Fn archive_entry_filetype "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_filetype "struct archive_entry *a" "unsigned int type"
+.Ft mode_t
+.Fn archive_entry_mode "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_mode "struct archive_entry *a" "mode_t mode"
+.Ft int64_t
+.Fn archive_entry_size "struct archive_entry *a"
+.Ft int
+.Fn archive_entry_size_is_set "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_size "struct archive_entry *a" "int64_t size"
+.Ft void
+.Fn archive_entry_unset_size "struct archive_entry *a"
+.Ft dev_t
+.Fn archive_entry_dev "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_dev "struct archive_entry *a" "dev_t dev"
+.Ft int
+.Fn archive_entry_dev_is_set "struct archive_entry *a"
+.Ft dev_t
+.Fn archive_entry_devmajor "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_devmajor "struct archive_entry *a" "dev_t major"
+.Ft dev_t
+.Fn archive_entry_devminor "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_devminor "struct archive_entry *a" "dev_t minor"
+.Ft ino_t
+.Fn archive_entry_ino "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_ino "struct archive_entry *a" "unsigned long ino"
+.Ft int
+.Fn archive_entry_ino_is_set "struct archive_entry *a"
+.Ft int64_t
+.Fn archive_entry_ino64 "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_ino64 "struct archive_entry *a" "int64_t ino"
+.Ft unsigned int
+.Fn archive_entry_nlink "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_nlink "struct archive_entry *a" "unsigned int count"
+.Ft dev_t
+.Fn archive_entry_rdev "struct archive_entry *a"
+.Ft dev_t
+.Fn archive_entry_rdevmajor "struct archive_entry *a"
+.Ft dev_t
+.Fn archive_entry_rdevminor "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_rdev "struct archive_entry *a" "dev_t dev"
+.Ft void
+.Fn archive_entry_set_rdevmajor "struct archive_entry *a" "dev_t major"
+.Ft void
+.Fn archive_entry_set_rdevminor "struct archive_entry *a" "dev_t minor"
+.Sh DESCRIPTION
+.Ss Copying to and from Vt struct stat
+The function
+.Fn archive_entry_stat
+converts the various fields stored in the archive entry to the format
+used by
+.Xr stat 2 .
+The return value remains valid until either
+.Fn archive_entry_clear
+or
+.Fn archive_entry_free
+is called.
+It is not affected by calls to the set accessor functions.
+It currently sets the following values in
+.Vt struct stat :
+.Vt st_atime ,
+.Vt st_ctime ,
+.Vt st_dev ,
+.Vt st_gid ,
+.Vt st_ino ,
+.Vt st_mode ,
+.Vt st_mtime ,
+.Vt st_nlink ,
+.Vt st_rdev ,
+.Vt st_size ,
+.Vt st_uid .
+In addition,
+.Vt st_birthtime
+and high-precision information for time-related fields
+will be included on platforms that support it.
+.Pp
+The function
+.Fn archive_entry_copy_stat
+copies fields from the platform's
+.Vt struct stat .
+Fields not provided by
+.Vt struct stat
+are unchanged.
+.Ss General accessor functions
+The functions
+.Fn archive_entry_filetype
+and
+.Fn archive_entry_set_filetype
+get respectively set the filetype.
+The file type is one of the following constants:
+.Bl -tag -width "AE_IFSOCK" -compact -offset indent
+.It AE_IFREG
+Regular file
+.It AE_IFLNK
+Symbolic link
+.It AE_IFSOCK
+Socket
+.It AE_IFCHR
+Character device
+.It AE_IFBLK
+Block device
+.It AE_IFDIR
+Directory
+.It AE_IFIFO
+Named pipe (fifo)
+.El
+Not all file types are supported by all platforms.
+The constants used by
+.Xr stat 2
+may have different numeric values from the
+corresponding constants above.
+.Pp
+The functions
+.Fn archive_entry_mode
+and
+.Fn archive_entry_set_mode
+get/set a combination of file type and permissions and provide the
+equivalent of
+.Va st_mode .
+Use of
+.Fn archive_entry_filetype
+and
+.Fn archive_entry_perm
+for getting and
+.Fn archive_entry_set_filetype
+and
+.Fn archive_entry_set_perm
+for setting is recommended.
+.Pp
+The function
+.Fn archive_entry_size
+returns the file size, if it has been set, and 0 otherwise.
+.Fn archive_entry_size
+can be used to query that status.
+.Fn archive_entry_set_size
+and
+.Fn archive_entry_unset_size
+set and unset the size, respectively.
+.Pp
+The number of references (hardlinks) can be obtained by calling
+.Fn archive_entry_nlinks
+and set with
+.Fn archive_entry_set_nlinks .
+.Ss Identifying unique files
+The functions
+.Fn archive_entry_dev
+and
+.Fn archive_entry_ino64
+are used by
+.Xr archive_entry_linkify 3
+to find hardlinks.
+The pair of device and inode is suppossed to identify hardlinked files.
+.Pp
+The device major and minor number can be obtained independently using
+.Fn archive_entry_devmajor
+and
+.Fn archive_entry_devminor .
+The device can be set either via
+.Fn archive_entry_set_dev
+or by the combination of major and minor number using
+.Fn archive_entry_set_devmajor
+and
+.Fn archive_entry_set_devminor .
+.Pp
+The inode number can be obtained using
+.Fn archive_entry_ino .
+This is a legacy interface that uses the platform
+.Vt ino_t ,
+which may be very small.
+To set the inode number,
+.Fn archive_entry_set_ino64
+is the preferred interface.
+.Ss Accessor functions for block and character devices
+Block and character devices are characterised either using a device number
+or a pair of major and minor number.
+The combined device number can be obtained with
+.Fn archive_device_rdev
+and set with
+.Fn archive_device_set_rdev .
+The major and minor numbers are accessed by
+.Fn archive_device_rdevmajor ,
+.Fn archive_device_rdevminor
+.Fn archive_device_set_rdevmajor
+and
+.Fn archive_device_set_rdevminor .
+.Pp
+The process of splitting the combined device number into major and
+minor number and the reverse process of combing them differs between
+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 stat 2
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_stat.c b/Utilities/cmlibarchive/libarchive/archive_entry_stat.c
new file mode 100644
index 0000000000..71a407b1f8
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_stat.c
@@ -0,0 +1,118 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_entry_stat.c 201100 2009-12-28 03:05:31Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include "archive_entry.h"
+#include "archive_entry_private.h"
+
+const struct stat *
+archive_entry_stat(struct archive_entry *entry)
+{
+ struct stat *st;
+ if (entry->stat == NULL) {
+ entry->stat = calloc(1, sizeof(*st));
+ if (entry->stat == NULL)
+ return (NULL);
+ entry->stat_valid = 0;
+ }
+
+ /*
+ * If none of the underlying fields have been changed, we
+ * don't need to regenerate. In theory, we could use a bitmap
+ * here to flag only those items that have changed, but the
+ * extra complexity probably isn't worth it. It will be very
+ * rare for anyone to change just one field then request a new
+ * stat structure.
+ */
+ if (entry->stat_valid)
+ return (entry->stat);
+
+ st = entry->stat;
+ /*
+ * Use the public interfaces to extract items, so that
+ * the appropriate conversions get invoked.
+ */
+ st->st_atime = archive_entry_atime(entry);
+#if HAVE_STRUCT_STAT_ST_BIRTHTIME
+ st->st_birthtime = archive_entry_birthtime(entry);
+#endif
+ st->st_ctime = archive_entry_ctime(entry);
+ st->st_mtime = archive_entry_mtime(entry);
+ st->st_dev = archive_entry_dev(entry);
+ st->st_gid = (gid_t)archive_entry_gid(entry);
+ st->st_uid = (uid_t)archive_entry_uid(entry);
+ st->st_ino = (ino_t)archive_entry_ino64(entry);
+ st->st_nlink = archive_entry_nlink(entry);
+ st->st_rdev = archive_entry_rdev(entry);
+ st->st_size = (off_t)archive_entry_size(entry);
+ st->st_mode = archive_entry_mode(entry);
+
+ /*
+ * On systems that support high-res timestamps, copy that
+ * information into struct stat.
+ */
+#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
+ st->st_atimespec.tv_nsec = archive_entry_atime_nsec(entry);
+ st->st_ctimespec.tv_nsec = archive_entry_ctime_nsec(entry);
+ st->st_mtimespec.tv_nsec = archive_entry_mtime_nsec(entry);
+#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+ st->st_atim.tv_nsec = archive_entry_atime_nsec(entry);
+ st->st_ctim.tv_nsec = archive_entry_ctime_nsec(entry);
+ st->st_mtim.tv_nsec = archive_entry_mtime_nsec(entry);
+#elif HAVE_STRUCT_STAT_ST_MTIME_N
+ st->st_atime_n = archive_entry_atime_nsec(entry);
+ st->st_ctime_n = archive_entry_ctime_nsec(entry);
+ st->st_mtime_n = archive_entry_mtime_nsec(entry);
+#elif HAVE_STRUCT_STAT_ST_UMTIME
+ st->st_uatime = archive_entry_atime_nsec(entry) / 1000;
+ st->st_uctime = archive_entry_ctime_nsec(entry) / 1000;
+ st->st_umtime = archive_entry_mtime_nsec(entry) / 1000;
+#elif HAVE_STRUCT_STAT_ST_MTIME_USEC
+ st->st_atime_usec = archive_entry_atime_nsec(entry) / 1000;
+ st->st_ctime_usec = archive_entry_ctime_nsec(entry) / 1000;
+ st->st_mtime_usec = archive_entry_mtime_nsec(entry) / 1000;
+#endif
+#if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
+ st->st_birthtimespec.tv_nsec = archive_entry_birthtime_nsec(entry);
+#endif
+
+ /*
+ * TODO: On Linux, store 32 or 64 here depending on whether
+ * the cached stat structure is a stat32 or a stat64. This
+ * will allow us to support both variants interchangeably.
+ */
+ entry->stat_valid = 1;
+
+ return (st);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_strmode.c b/Utilities/cmlibarchive/libarchive/archive_entry_strmode.c
new file mode 100644
index 0000000000..16cb3f7bb3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_strmode.c
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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: src/lib/libarchive/archive_entry_strmode.c,v 1.4 2008/06/15 05:14:01 kientzle Exp $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive_entry.h"
+#include "archive_entry_private.h"
+
+const char *
+archive_entry_strmode(struct archive_entry *entry)
+{
+ static const mode_t permbits[] =
+ { 0400, 0200, 0100, 0040, 0020, 0010, 0004, 0002, 0001 };
+ char *bp = entry->strmode;
+ mode_t mode;
+ int i;
+
+ /* Fill in a default string, then selectively override. */
+ strcpy(bp, "?rwxrwxrwx ");
+
+ mode = archive_entry_mode(entry);
+ switch (archive_entry_filetype(entry)) {
+ case AE_IFREG: bp[0] = '-'; break;
+ case AE_IFBLK: bp[0] = 'b'; break;
+ case AE_IFCHR: bp[0] = 'c'; break;
+ case AE_IFDIR: bp[0] = 'd'; break;
+ case AE_IFLNK: bp[0] = 'l'; break;
+ case AE_IFSOCK: bp[0] = 's'; break;
+ case AE_IFIFO: bp[0] = 'p'; break;
+ default:
+ if (archive_entry_hardlink(entry) != NULL) {
+ bp[0] = 'h';
+ break;
+ }
+ }
+
+ for (i = 0; i < 9; i++)
+ if (!(mode & permbits[i]))
+ bp[i+1] = '-';
+
+ if (mode & S_ISUID) {
+ if (mode & 0100) bp[3] = 's';
+ else bp[3] = 'S';
+ }
+ if (mode & S_ISGID) {
+ if (mode & 0010) bp[6] = 's';
+ else bp[6] = 'S';
+ }
+ if (mode & S_ISVTX) {
+ if (mode & 0001) bp[9] = 't';
+ else bp[9] = 'T';
+ }
+ if (archive_entry_acl_count(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS))
+ bp[10] = '+';
+
+ return (bp);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_time.3 b/Utilities/cmlibarchive/libarchive/archive_entry_time.3
new file mode 100644
index 0000000000..17c658a658
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_time.3
@@ -0,0 +1,129 @@
+.\" Copyright (c) 2003-2007 Tim Kientzle
+.\" Copyright (c) 2010 Joerg Sonnenberger
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_ENTRY_TIME 3
+.Os
+.Sh NAME
+.Nm archive_entry_atime ,
+.Nm archive_entry_atime_nsec ,
+.Nm archive_entry_atime_is_set ,
+.Nm archive_entry_set_atime ,
+.Nm archive_entry_unset_atime ,
+.Nm archive_entry_birthtime ,
+.Nm archive_entry_birthtime_nsec ,
+.Nm archive_entry_birthtime_is_set ,
+.Nm archive_entry_set_birthtime ,
+.Nm archive_entry_unset_birthtime ,
+.Nm archive_entry_ctime ,
+.Nm archive_entry_ctime_nsec ,
+.Nm archive_entry_ctime_is_set ,
+.Nm archive_entry_set_ctime ,
+.Nm archive_entry_unset_ctime ,
+.Nm archive_entry_mtime ,
+.Nm archive_entry_mtime_nsec ,
+.Nm archive_entry_mtime_is_set ,
+.Nm archive_entry_set_mtime ,
+.Nm archive_entry_unset_mtime ,
+.Nd functions for manipulating times in archive entry descriptions
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive_entry.h
+.Ft time_t
+.Fn archive_entry_atime "struct archive_entry *a"
+.Ft long
+.Fn archive_entry_atime_nsec "struct archive_entry *a"
+.Ft int
+.Fn archive_entry_atime_is_set "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_atime "struct archive_entry *a" "time_t sec" "long nanosec"
+.Ft void
+.Fn archive_entry_unset_atime "struct archive_entry *a"
+.Ft time_t
+.Fn archive_entry_birthtime "struct archive_entry *a"
+.Ft long
+.Fn archive_entry_birthtime_nsec "struct archive_entry *a"
+.Ft int
+.Fn archive_entry_birthtime_is_set "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_birthtime "struct archive_entry *a" "time_t sec" "long nanosec"
+.Ft void
+.Fn archive_entry_unset_birthtime "struct archive_entry *a"
+.Ft time_t
+.Fn archive_entry_ctime "struct archive_entry *a"
+.Ft long
+.Fn archive_entry_ctime_nsec "struct archive_entry *a"
+.Ft int
+.Fn archive_entry_ctime_is_set "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_ctime "struct archive_entry *a" "time_t sec" "long nanosec"
+.Ft void
+.Fn archive_entry_unset_ctime "struct archive_entry *a"
+.Ft time_t
+.Fn archive_entry_mtime "struct archive_entry *a"
+.Ft long
+.Fn archive_entry_mtime_nsec "struct archive_entry *a"
+.Ft int
+.Fn archive_entry_mtime_is_set "struct archive_entry *a"
+.Ft void
+.Fn archive_entry_set_mtime "struct archive_entry *a" "time_t sec" "long nanosec"
+.Ft void
+.Fn archive_entry_unset_mtime "struct archive_entry *a"
+.Sh DESCRIPTION
+These functions create and manipulate the time fields in an
+.Vt archive_entry .
+Supported time fields are atime (access time), birthtime (creation time),
+ctime (last time an inode property was changed) and mtime (modification time).
+.Pp
+.Xr libarchive 3
+provides a high-resolution interface.
+The timestamps are truncated automatically depending on the archive format
+(for archiving) or the filesystem capabilities (for restoring).
+.Pp
+All timestamp fields are optional.
+The
+.Fn XXX_unset
+functions can be used to mark the corresponding field as missing.
+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
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libarchive
+library was written by
+.An Tim Kientzle Aq kientzle@acm.org .
+.\" .Sh BUGS
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c b/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c
new file mode 100644
index 0000000000..a3efe7ca8d
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c
@@ -0,0 +1,158 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_entry_xattr.c 201096 2009-12-28 02:41:27Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_LINUX_FS_H
+#include <linux/fs.h> /* for Linux file flags */
+#endif
+/*
+ * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
+ * As the include guards don't agree, the order of include is important.
+ */
+#ifdef HAVE_LINUX_EXT2_FS_H
+#include <linux/ext2_fs.h> /* for Linux file flags */
+#endif
+#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
+#include <ext2fs/ext2_fs.h> /* for Linux file flags */
+#endif
+#include <stddef.h>
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_entry_private.h"
+
+/*
+ * extended attribute handling
+ */
+
+void
+archive_entry_xattr_clear(struct archive_entry *entry)
+{
+ struct ae_xattr *xp;
+
+ while (entry->xattr_head != NULL) {
+ xp = entry->xattr_head->next;
+ free(entry->xattr_head->name);
+ free(entry->xattr_head->value);
+ free(entry->xattr_head);
+ entry->xattr_head = xp;
+ }
+
+ entry->xattr_head = NULL;
+}
+
+void
+archive_entry_xattr_add_entry(struct archive_entry *entry,
+ const char *name, const void *value, size_t size)
+{
+ struct ae_xattr *xp;
+
+ for (xp = entry->xattr_head; xp != NULL; xp = xp->next)
+ ;
+
+ if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL)
+ /* XXX Error XXX */
+ return;
+
+ xp->name = strdup(name);
+ if ((xp->value = malloc(size)) != NULL) {
+ memcpy(xp->value, value, size);
+ xp->size = size;
+ } else
+ xp->size = 0;
+
+ xp->next = entry->xattr_head;
+ entry->xattr_head = xp;
+}
+
+
+/*
+ * returns number of the extended attribute entries
+ */
+int
+archive_entry_xattr_count(struct archive_entry *entry)
+{
+ struct ae_xattr *xp;
+ int count = 0;
+
+ for (xp = entry->xattr_head; xp != NULL; xp = xp->next)
+ count++;
+
+ return count;
+}
+
+int
+archive_entry_xattr_reset(struct archive_entry * entry)
+{
+ entry->xattr_p = entry->xattr_head;
+
+ return archive_entry_xattr_count(entry);
+}
+
+int
+archive_entry_xattr_next(struct archive_entry * entry,
+ const char **name, const void **value, size_t *size)
+{
+ if (entry->xattr_p) {
+ *name = entry->xattr_p->name;
+ *value = entry->xattr_p->value;
+ *size = entry->xattr_p->size;
+
+ entry->xattr_p = entry->xattr_p->next;
+
+ return (ARCHIVE_OK);
+ } else {
+ *name = NULL;
+ *value = NULL;
+ *size = (size_t)0;
+ return (ARCHIVE_WARN);
+ }
+}
+
+/*
+ * end of xattr handling
+ */
diff --git a/Utilities/cmlibarchive/libarchive/archive_getdate.c b/Utilities/cmlibarchive/libarchive/archive_getdate.c
new file mode 100644
index 0000000000..aaa9d6fa12
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_getdate.c
@@ -0,0 +1,1038 @@
+/*
+ * This code is in the public domain and has no copyright.
+ *
+ * This is a plain C recursive-descent translation of an old
+ * public-domain YACC grammar that has been used for parsing dates in
+ * very many open-source projects.
+ *
+ * Since the original authors were generous enough to donate their
+ * work to the public domain, I feel compelled to match their
+ * generosity.
+ *
+ * Tim Kientzle, February 2009.
+ */
+
+/*
+ * Header comment from original getdate.y:
+ */
+
+/*
+** Originally written by Steven M. Bellovin <smb@research.att.com> while
+** at the University of North Carolina at Chapel Hill. Later tweaked by
+** a couple of people on Usenet. Completely overhauled by Rich $alz
+** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
+**
+** This grammar has 10 shift/reduce conflicts.
+**
+** This code is in the public domain and has no copyright.
+*/
+
+#ifdef __FreeBSD__
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+/* This file defines a single public function. */
+time_t __archive_get_date(time_t now, char *);
+
+/* Basic time units. */
+#define EPOCH 1970
+#define MINUTE (60L)
+#define HOUR (60L * MINUTE)
+#define DAY (24L * HOUR)
+
+/* Daylight-savings mode: on, off, or not yet known. */
+enum DSTMODE { DSTon, DSToff, DSTmaybe };
+/* Meridian: am or pm. */
+enum { tAM, tPM };
+/* Token types returned by nexttoken() */
+enum { tAGO = 260, tDAY, tDAYZONE, tAMPM, tMONTH, tMONTH_UNIT, tSEC_UNIT,
+ tUNUMBER, tZONE, tDST };
+struct token { int token; time_t value; };
+
+/*
+ * Parser state.
+ */
+struct gdstate {
+ struct token *tokenp; /* Pointer to next token. */
+ /* HaveXxxx counts how many of this kind of phrase we've seen;
+ * it's a fatal error to have more than one time, zone, day,
+ * or date phrase. */
+ int HaveYear;
+ int HaveMonth;
+ int HaveDay;
+ int HaveWeekDay; /* Day of week */
+ int HaveTime; /* Hour/minute/second */
+ int HaveZone; /* timezone and/or DST info */
+ int HaveRel; /* time offset; we can have more than one */
+ /* Absolute time values. */
+ time_t Timezone; /* Seconds offset from GMT */
+ time_t Day;
+ time_t Hour;
+ time_t Minutes;
+ time_t Month;
+ time_t Seconds;
+ time_t Year;
+ /* DST selection */
+ enum DSTMODE DSTmode;
+ /* Day of week accounting, e.g., "3rd Tuesday" */
+ time_t DayOrdinal; /* "3" in "3rd Tuesday" */
+ time_t DayNumber; /* "Tuesday" in "3rd Tuesday" */
+ /* Relative time values: hour/day/week offsets are measured in
+ * seconds, month/year are counted in months. */
+ time_t RelMonth;
+ time_t RelSeconds;
+};
+
+/*
+ * A series of functions that recognize certain common time phrases.
+ * Each function returns 1 if it managed to make sense of some of the
+ * tokens, zero otherwise.
+ */
+
+/*
+ * hour:minute or hour:minute:second with optional AM, PM, or numeric
+ * timezone offset
+ */
+static int
+timephrase(struct gdstate *gds)
+{
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == ':'
+ && gds->tokenp[2].token == tUNUMBER
+ && gds->tokenp[3].token == ':'
+ && gds->tokenp[4].token == tUNUMBER) {
+ /* "12:14:18" or "22:08:07" */
+ ++gds->HaveTime;
+ gds->Hour = gds->tokenp[0].value;
+ gds->Minutes = gds->tokenp[2].value;
+ gds->Seconds = gds->tokenp[4].value;
+ gds->tokenp += 5;
+ }
+ else if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == ':'
+ && gds->tokenp[2].token == tUNUMBER) {
+ /* "12:14" or "22:08" */
+ ++gds->HaveTime;
+ gds->Hour = gds->tokenp[0].value;
+ gds->Minutes = gds->tokenp[2].value;
+ gds->Seconds = 0;
+ gds->tokenp += 3;
+ }
+ else if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tAMPM) {
+ /* "7" is a time if it's followed by "am" or "pm" */
+ ++gds->HaveTime;
+ gds->Hour = gds->tokenp[0].value;
+ gds->Minutes = gds->Seconds = 0;
+ /* We'll handle the AM/PM below. */
+ gds->tokenp += 1;
+ } else {
+ /* We can't handle this. */
+ return 0;
+ }
+
+ if (gds->tokenp[0].token == tAMPM) {
+ /* "7:12pm", "12:20:13am" */
+ if (gds->Hour == 12)
+ gds->Hour = 0;
+ if (gds->tokenp[0].value == tPM)
+ gds->Hour += 12;
+ gds->tokenp += 1;
+ }
+ if (gds->tokenp[0].token == '+'
+ && gds->tokenp[1].token == tUNUMBER) {
+ /* "7:14+0700" */
+ gds->HaveZone++;
+ gds->DSTmode = DSToff;
+ gds->Timezone = - ((gds->tokenp[1].value / 100) * HOUR
+ + (gds->tokenp[1].value % 100) * MINUTE);
+ gds->tokenp += 2;
+ }
+ if (gds->tokenp[0].token == '-'
+ && gds->tokenp[1].token == tUNUMBER) {
+ /* "19:14:12-0530" */
+ gds->HaveZone++;
+ gds->DSTmode = DSToff;
+ gds->Timezone = + ((gds->tokenp[1].value / 100) * HOUR
+ + (gds->tokenp[1].value % 100) * MINUTE);
+ gds->tokenp += 2;
+ }
+ return 1;
+}
+
+/*
+ * Timezone name, possibly including DST.
+ */
+static int
+zonephrase(struct gdstate *gds)
+{
+ if (gds->tokenp[0].token == tZONE
+ && gds->tokenp[1].token == tDST) {
+ gds->HaveZone++;
+ gds->Timezone = gds->tokenp[0].value;
+ gds->DSTmode = DSTon;
+ gds->tokenp += 1;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tZONE) {
+ gds->HaveZone++;
+ gds->Timezone = gds->tokenp[0].value;
+ gds->DSTmode = DSToff;
+ gds->tokenp += 1;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tDAYZONE) {
+ gds->HaveZone++;
+ gds->Timezone = gds->tokenp[0].value;
+ gds->DSTmode = DSTon;
+ gds->tokenp += 1;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Year/month/day in various combinations.
+ */
+static int
+datephrase(struct gdstate *gds)
+{
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == '/'
+ && gds->tokenp[2].token == tUNUMBER
+ && gds->tokenp[3].token == '/'
+ && gds->tokenp[4].token == tUNUMBER) {
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ if (gds->tokenp[0].value >= 13) {
+ /* First number is big: 2004/01/29, 99/02/17 */
+ gds->Year = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[2].value;
+ gds->Day = gds->tokenp[4].value;
+ } else if ((gds->tokenp[4].value >= 13)
+ || (gds->tokenp[2].value >= 13)) {
+ /* Last number is big: 01/07/98 */
+ /* Middle number is big: 01/29/04 */
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[2].value;
+ gds->Year = gds->tokenp[4].value;
+ } else {
+ /* No significant clues: 02/03/04 */
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[2].value;
+ gds->Year = gds->tokenp[4].value;
+ }
+ gds->tokenp += 5;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == '/'
+ && gds->tokenp[2].token == tUNUMBER) {
+ /* "1/15" */
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == '-'
+ && gds->tokenp[2].token == tUNUMBER
+ && gds->tokenp[3].token == '-'
+ && gds->tokenp[4].token == tUNUMBER) {
+ /* ISO 8601 format. yyyy-mm-dd. */
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Year = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[2].value;
+ gds->Day = gds->tokenp[4].value;
+ gds->tokenp += 5;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == '-'
+ && gds->tokenp[2].token == tMONTH
+ && gds->tokenp[3].token == '-'
+ && gds->tokenp[4].token == tUNUMBER) {
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ if (gds->tokenp[0].value > 31) {
+ /* e.g. 1992-Jun-17 */
+ gds->Year = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[2].value;
+ gds->Day = gds->tokenp[4].value;
+ } else {
+ /* e.g. 17-JUN-1992. */
+ gds->Day = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[2].value;
+ gds->Year = gds->tokenp[4].value;
+ }
+ gds->tokenp += 5;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tMONTH
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == ','
+ && gds->tokenp[3].token == tUNUMBER) {
+ /* "June 17, 2001" */
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[1].value;
+ gds->Year = gds->tokenp[3].value;
+ gds->tokenp += 4;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tMONTH
+ && gds->tokenp[1].token == tUNUMBER) {
+ /* "May 3" */
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[1].value;
+ gds->tokenp += 2;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tMONTH
+ && gds->tokenp[2].token == tUNUMBER) {
+ /* "12 Sept 1997" */
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Day = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[1].value;
+ gds->Year = gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tMONTH) {
+ /* "12 Sept" */
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Day = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[1].value;
+ gds->tokenp += 2;
+ return 1;
+ }
+
+ return 0;
+}
+
+/*
+ * Relative time phrase: "tomorrow", "yesterday", "+1 hour", etc.
+ */
+static int
+relunitphrase(struct gdstate *gds)
+{
+ if (gds->tokenp[0].token == '-'
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == tSEC_UNIT) {
+ /* "-3 hours" */
+ gds->HaveRel++;
+ gds->RelSeconds -= gds->tokenp[1].value * gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
+ }
+ if (gds->tokenp[0].token == '+'
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == tSEC_UNIT) {
+ /* "+1 minute" */
+ gds->HaveRel++;
+ gds->RelSeconds += gds->tokenp[1].value * gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
+ }
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tSEC_UNIT) {
+ /* "1 day" */
+ gds->HaveRel++;
+ gds->RelSeconds += gds->tokenp[0].value * gds->tokenp[1].value;
+ gds->tokenp += 2;
+ return 1;
+ }
+ if (gds->tokenp[0].token == '-'
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == tMONTH_UNIT) {
+ /* "-3 months" */
+ gds->HaveRel++;
+ gds->RelMonth -= gds->tokenp[1].value * gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
+ }
+ if (gds->tokenp[0].token == '+'
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == tMONTH_UNIT) {
+ /* "+5 years" */
+ gds->HaveRel++;
+ gds->RelMonth += gds->tokenp[1].value * gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
+ }
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tMONTH_UNIT) {
+ /* "2 years" */
+ gds->HaveRel++;
+ gds->RelMonth += gds->tokenp[0].value * gds->tokenp[1].value;
+ gds->tokenp += 2;
+ return 1;
+ }
+ if (gds->tokenp[0].token == tSEC_UNIT) {
+ /* "now", "tomorrow" */
+ gds->HaveRel++;
+ gds->RelSeconds += gds->tokenp[0].value;
+ gds->tokenp += 1;
+ return 1;
+ }
+ if (gds->tokenp[0].token == tMONTH_UNIT) {
+ /* "month" */
+ gds->HaveRel++;
+ gds->RelMonth += gds->tokenp[0].value;
+ gds->tokenp += 1;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Day of the week specification.
+ */
+static int
+dayphrase(struct gdstate *gds)
+{
+ if (gds->tokenp[0].token == tDAY) {
+ /* "tues", "wednesday," */
+ gds->HaveWeekDay++;
+ gds->DayOrdinal = 1;
+ gds->DayNumber = gds->tokenp[0].value;
+ gds->tokenp += 1;
+ if (gds->tokenp[0].token == ',')
+ gds->tokenp += 1;
+ return 1;
+ }
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tDAY) {
+ /* "second tues" "3 wed" */
+ gds->HaveWeekDay++;
+ gds->DayOrdinal = gds->tokenp[0].value;
+ gds->DayNumber = gds->tokenp[1].value;
+ gds->tokenp += 2;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Try to match a phrase using one of the above functions.
+ * This layer also deals with a couple of generic issues.
+ */
+static int
+phrase(struct gdstate *gds)
+{
+ if (timephrase(gds))
+ return 1;
+ if (zonephrase(gds))
+ return 1;
+ if (datephrase(gds))
+ return 1;
+ if (dayphrase(gds))
+ return 1;
+ if (relunitphrase(gds)) {
+ if (gds->tokenp[0].token == tAGO) {
+ gds->RelSeconds = -gds->RelSeconds;
+ gds->RelMonth = -gds->RelMonth;
+ gds->tokenp += 1;
+ }
+ return 1;
+ }
+
+ /* Bare numbers sometimes have meaning. */
+ if (gds->tokenp[0].token == tUNUMBER) {
+ if (gds->HaveTime && !gds->HaveYear && !gds->HaveRel) {
+ gds->HaveYear++;
+ gds->Year = gds->tokenp[0].value;
+ gds->tokenp += 1;
+ return 1;
+ }
+
+ if(gds->tokenp[0].value > 10000) {
+ /* "20040301" */
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Day= (gds->tokenp[0].value)%100;
+ gds->Month= (gds->tokenp[0].value/100)%100;
+ gds->Year = gds->tokenp[0].value/10000;
+ gds->tokenp += 1;
+ return 1;
+ }
+
+ if (gds->tokenp[0].value < 24) {
+ gds->HaveTime++;
+ gds->Hour = gds->tokenp[0].value;
+ gds->Minutes = 0;
+ gds->Seconds = 0;
+ gds->tokenp += 1;
+ return 1;
+ }
+
+ if ((gds->tokenp[0].value / 100 < 24)
+ && (gds->tokenp[0].value % 100 < 60)) {
+ /* "513" is same as "5:13" */
+ gds->Hour = gds->tokenp[0].value / 100;
+ gds->Minutes = gds->tokenp[0].value % 100;
+ gds->Seconds = 0;
+ gds->tokenp += 1;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * A dictionary of time words.
+ */
+static struct LEXICON {
+ size_t abbrev;
+ const char *name;
+ int type;
+ time_t value;
+} const TimeWords[] = {
+ /* am/pm */
+ { 0, "am", tAMPM, tAM },
+ { 0, "pm", tAMPM, tPM },
+
+ /* Month names. */
+ { 3, "january", tMONTH, 1 },
+ { 3, "february", tMONTH, 2 },
+ { 3, "march", tMONTH, 3 },
+ { 3, "april", tMONTH, 4 },
+ { 3, "may", tMONTH, 5 },
+ { 3, "june", tMONTH, 6 },
+ { 3, "july", tMONTH, 7 },
+ { 3, "august", tMONTH, 8 },
+ { 3, "september", tMONTH, 9 },
+ { 3, "october", tMONTH, 10 },
+ { 3, "november", tMONTH, 11 },
+ { 3, "december", tMONTH, 12 },
+
+ /* Days of the week. */
+ { 2, "sunday", tDAY, 0 },
+ { 3, "monday", tDAY, 1 },
+ { 2, "tuesday", tDAY, 2 },
+ { 3, "wednesday", tDAY, 3 },
+ { 2, "thursday", tDAY, 4 },
+ { 2, "friday", tDAY, 5 },
+ { 2, "saturday", tDAY, 6 },
+
+ /* Timezones: Offsets are in seconds. */
+ { 0, "gmt", tZONE, 0*HOUR }, /* Greenwich Mean */
+ { 0, "ut", tZONE, 0*HOUR }, /* Universal (Coordinated) */
+ { 0, "utc", tZONE, 0*HOUR },
+ { 0, "wet", tZONE, 0*HOUR }, /* Western European */
+ { 0, "bst", tDAYZONE, 0*HOUR }, /* British Summer */
+ { 0, "wat", tZONE, 1*HOUR }, /* West Africa */
+ { 0, "at", tZONE, 2*HOUR }, /* Azores */
+ /* { 0, "bst", tZONE, 3*HOUR }, */ /* Brazil Standard: Conflict */
+ /* { 0, "gst", tZONE, 3*HOUR }, */ /* Greenland Standard: Conflict*/
+ { 0, "nft", tZONE, 3*HOUR+30*MINUTE }, /* Newfoundland */
+ { 0, "nst", tZONE, 3*HOUR+30*MINUTE }, /* Newfoundland Standard */
+ { 0, "ndt", tDAYZONE, 3*HOUR+30*MINUTE }, /* Newfoundland Daylight */
+ { 0, "ast", tZONE, 4*HOUR }, /* Atlantic Standard */
+ { 0, "adt", tDAYZONE, 4*HOUR }, /* Atlantic Daylight */
+ { 0, "est", tZONE, 5*HOUR }, /* Eastern Standard */
+ { 0, "edt", tDAYZONE, 5*HOUR }, /* Eastern Daylight */
+ { 0, "cst", tZONE, 6*HOUR }, /* Central Standard */
+ { 0, "cdt", tDAYZONE, 6*HOUR }, /* Central Daylight */
+ { 0, "mst", tZONE, 7*HOUR }, /* Mountain Standard */
+ { 0, "mdt", tDAYZONE, 7*HOUR }, /* Mountain Daylight */
+ { 0, "pst", tZONE, 8*HOUR }, /* Pacific Standard */
+ { 0, "pdt", tDAYZONE, 8*HOUR }, /* Pacific Daylight */
+ { 0, "yst", tZONE, 9*HOUR }, /* Yukon Standard */
+ { 0, "ydt", tDAYZONE, 9*HOUR }, /* Yukon Daylight */
+ { 0, "hst", tZONE, 10*HOUR }, /* Hawaii Standard */
+ { 0, "hdt", tDAYZONE, 10*HOUR }, /* Hawaii Daylight */
+ { 0, "cat", tZONE, 10*HOUR }, /* Central Alaska */
+ { 0, "ahst", tZONE, 10*HOUR }, /* Alaska-Hawaii Standard */
+ { 0, "nt", tZONE, 11*HOUR }, /* Nome */
+ { 0, "idlw", tZONE, 12*HOUR }, /* Intl Date Line West */
+ { 0, "cet", tZONE, -1*HOUR }, /* Central European */
+ { 0, "met", tZONE, -1*HOUR }, /* Middle European */
+ { 0, "mewt", tZONE, -1*HOUR }, /* Middle European Winter */
+ { 0, "mest", tDAYZONE, -1*HOUR }, /* Middle European Summer */
+ { 0, "swt", tZONE, -1*HOUR }, /* Swedish Winter */
+ { 0, "sst", tDAYZONE, -1*HOUR }, /* Swedish Summer */
+ { 0, "fwt", tZONE, -1*HOUR }, /* French Winter */
+ { 0, "fst", tDAYZONE, -1*HOUR }, /* French Summer */
+ { 0, "eet", tZONE, -2*HOUR }, /* Eastern Eur, USSR Zone 1 */
+ { 0, "bt", tZONE, -3*HOUR }, /* Baghdad, USSR Zone 2 */
+ { 0, "it", tZONE, -3*HOUR-30*MINUTE },/* Iran */
+ { 0, "zp4", tZONE, -4*HOUR }, /* USSR Zone 3 */
+ { 0, "zp5", tZONE, -5*HOUR }, /* USSR Zone 4 */
+ { 0, "ist", tZONE, -5*HOUR-30*MINUTE },/* Indian Standard */
+ { 0, "zp6", tZONE, -6*HOUR }, /* USSR Zone 5 */
+ /* { 0, "nst", tZONE, -6.5*HOUR }, */ /* North Sumatra: Conflict */
+ /* { 0, "sst", tZONE, -7*HOUR }, */ /* So Sumatra, USSR 6: Conflict */
+ { 0, "wast", tZONE, -7*HOUR }, /* West Australian Standard */
+ { 0, "wadt", tDAYZONE, -7*HOUR }, /* West Australian Daylight */
+ { 0, "jt", tZONE, -7*HOUR-30*MINUTE },/* Java (3pm in Cronusland!)*/
+ { 0, "cct", tZONE, -8*HOUR }, /* China Coast, USSR Zone 7 */
+ { 0, "jst", tZONE, -9*HOUR }, /* Japan Std, USSR Zone 8 */
+ { 0, "cast", tZONE, -9*HOUR-30*MINUTE },/* Ctrl Australian Std */
+ { 0, "cadt", tDAYZONE, -9*HOUR-30*MINUTE },/* Ctrl Australian Daylt */
+ { 0, "east", tZONE, -10*HOUR }, /* Eastern Australian Std */
+ { 0, "eadt", tDAYZONE, -10*HOUR }, /* Eastern Australian Daylt */
+ { 0, "gst", tZONE, -10*HOUR }, /* Guam Std, USSR Zone 9 */
+ { 0, "nzt", tZONE, -12*HOUR }, /* New Zealand */
+ { 0, "nzst", tZONE, -12*HOUR }, /* New Zealand Standard */
+ { 0, "nzdt", tDAYZONE, -12*HOUR }, /* New Zealand Daylight */
+ { 0, "idle", tZONE, -12*HOUR }, /* Intl Date Line East */
+
+ { 0, "dst", tDST, 0 },
+
+ /* Time units. */
+ { 4, "years", tMONTH_UNIT, 12 },
+ { 5, "months", tMONTH_UNIT, 1 },
+ { 9, "fortnights", tSEC_UNIT, 14 * DAY },
+ { 4, "weeks", tSEC_UNIT, 7 * DAY },
+ { 3, "days", tSEC_UNIT, DAY },
+ { 4, "hours", tSEC_UNIT, HOUR },
+ { 3, "minutes", tSEC_UNIT, MINUTE },
+ { 3, "seconds", tSEC_UNIT, 1 },
+
+ /* Relative-time words. */
+ { 0, "tomorrow", tSEC_UNIT, DAY },
+ { 0, "yesterday", tSEC_UNIT, -DAY },
+ { 0, "today", tSEC_UNIT, 0 },
+ { 0, "now", tSEC_UNIT, 0 },
+ { 0, "last", tUNUMBER, -1 },
+ { 0, "this", tSEC_UNIT, 0 },
+ { 0, "next", tUNUMBER, 2 },
+ { 0, "first", tUNUMBER, 1 },
+ { 0, "1st", tUNUMBER, 1 },
+/* { 0, "second", tUNUMBER, 2 }, */
+ { 0, "2nd", tUNUMBER, 2 },
+ { 0, "third", tUNUMBER, 3 },
+ { 0, "3rd", tUNUMBER, 3 },
+ { 0, "fourth", tUNUMBER, 4 },
+ { 0, "4th", tUNUMBER, 4 },
+ { 0, "fifth", tUNUMBER, 5 },
+ { 0, "5th", tUNUMBER, 5 },
+ { 0, "sixth", tUNUMBER, 6 },
+ { 0, "seventh", tUNUMBER, 7 },
+ { 0, "eighth", tUNUMBER, 8 },
+ { 0, "ninth", tUNUMBER, 9 },
+ { 0, "tenth", tUNUMBER, 10 },
+ { 0, "eleventh", tUNUMBER, 11 },
+ { 0, "twelfth", tUNUMBER, 12 },
+ { 0, "ago", tAGO, 1 },
+
+ /* Military timezones. */
+ { 0, "a", tZONE, 1*HOUR },
+ { 0, "b", tZONE, 2*HOUR },
+ { 0, "c", tZONE, 3*HOUR },
+ { 0, "d", tZONE, 4*HOUR },
+ { 0, "e", tZONE, 5*HOUR },
+ { 0, "f", tZONE, 6*HOUR },
+ { 0, "g", tZONE, 7*HOUR },
+ { 0, "h", tZONE, 8*HOUR },
+ { 0, "i", tZONE, 9*HOUR },
+ { 0, "k", tZONE, 10*HOUR },
+ { 0, "l", tZONE, 11*HOUR },
+ { 0, "m", tZONE, 12*HOUR },
+ { 0, "n", tZONE, -1*HOUR },
+ { 0, "o", tZONE, -2*HOUR },
+ { 0, "p", tZONE, -3*HOUR },
+ { 0, "q", tZONE, -4*HOUR },
+ { 0, "r", tZONE, -5*HOUR },
+ { 0, "s", tZONE, -6*HOUR },
+ { 0, "t", tZONE, -7*HOUR },
+ { 0, "u", tZONE, -8*HOUR },
+ { 0, "v", tZONE, -9*HOUR },
+ { 0, "w", tZONE, -10*HOUR },
+ { 0, "x", tZONE, -11*HOUR },
+ { 0, "y", tZONE, -12*HOUR },
+ { 0, "z", tZONE, 0*HOUR },
+
+ /* End of table. */
+ { 0, NULL, 0, 0 }
+};
+
+/*
+ * Year is either:
+ * = A number from 0 to 99, which means a year from 1970 to 2069, or
+ * = The actual year (>=100).
+ */
+static time_t
+Convert(time_t Month, time_t Day, time_t Year,
+ time_t Hours, time_t Minutes, time_t Seconds,
+ time_t Timezone, enum DSTMODE DSTmode)
+{
+ static int DaysInMonth[12] = {
+ 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+ };
+ time_t Julian;
+ int i;
+
+ if (Year < 69)
+ Year += 2000;
+ else if (Year < 100)
+ Year += 1900;
+ DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
+ ? 29 : 28;
+ /* Checking for 2038 bogusly assumes that time_t is 32 bits. But
+ I'm too lazy to try to check for time_t overflow in another way. */
+ if (Year < EPOCH || Year > 2038
+ || Month < 1 || Month > 12
+ /* Lint fluff: "conversion from long may lose accuracy" */
+ || Day < 1 || Day > DaysInMonth[(int)--Month]
+ || Hours < 0 || Hours > 23
+ || Minutes < 0 || Minutes > 59
+ || Seconds < 0 || Seconds > 59)
+ return -1;
+
+ Julian = Day - 1;
+ for (i = 0; i < Month; i++)
+ Julian += DaysInMonth[i];
+ for (i = EPOCH; i < Year; i++)
+ Julian += 365 + (i % 4 == 0);
+ Julian *= DAY;
+ Julian += Timezone;
+ Julian += Hours * HOUR + Minutes * MINUTE + Seconds;
+ if (DSTmode == DSTon
+ || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
+ Julian -= HOUR;
+ return Julian;
+}
+
+
+static time_t
+DSTcorrect(time_t Start, time_t Future)
+{
+ time_t StartDay;
+ time_t FutureDay;
+
+ StartDay = (localtime(&Start)->tm_hour + 1) % 24;
+ FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
+ return (Future - Start) + (StartDay - FutureDay) * HOUR;
+}
+
+
+static time_t
+RelativeDate(time_t Start, time_t zone, int dstmode,
+ time_t DayOrdinal, time_t DayNumber)
+{
+ struct tm *tm;
+ time_t t, now;
+
+ t = Start - zone;
+ tm = gmtime(&t);
+ now = Start;
+ now += DAY * ((DayNumber - tm->tm_wday + 7) % 7);
+ now += 7 * DAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
+ if (dstmode == DSTmaybe)
+ return DSTcorrect(Start, now);
+ return now - Start;
+}
+
+
+static time_t
+RelativeMonth(time_t Start, time_t Timezone, time_t RelMonth)
+{
+ struct tm *tm;
+ time_t Month;
+ time_t Year;
+
+ if (RelMonth == 0)
+ return 0;
+ tm = localtime(&Start);
+ Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth;
+ Year = Month / 12;
+ Month = Month % 12 + 1;
+ return DSTcorrect(Start,
+ Convert(Month, (time_t)tm->tm_mday, Year,
+ (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
+ Timezone, DSTmaybe));
+}
+
+/*
+ * Tokenizer.
+ */
+static int
+nexttoken(char **in, time_t *value)
+{
+ char c;
+ char buff[64];
+
+ for ( ; ; ) {
+ while (isspace((unsigned char)**in))
+ ++*in;
+
+ /* Skip parenthesized comments. */
+ if (**in == '(') {
+ int Count = 0;
+ do {
+ c = *(*in)++;
+ if (c == '\0')
+ return c;
+ if (c == '(')
+ Count++;
+ else if (c == ')')
+ Count--;
+ } while (Count > 0);
+ continue;
+ }
+
+ /* Try the next token in the word table first. */
+ /* This allows us to match "2nd", for example. */
+ {
+ char *src = *in;
+ const struct LEXICON *tp;
+ unsigned i = 0;
+
+ /* Force to lowercase and strip '.' characters. */
+ while (*src != '\0'
+ && (isalnum((unsigned char)*src) || *src == '.')
+ && i < sizeof(buff)-1) {
+ if (*src != '.') {
+ if (isupper((unsigned char)*src))
+ buff[i++] = tolower((unsigned char)*src);
+ else
+ buff[i++] = *src;
+ }
+ src++;
+ }
+ buff[i] = '\0';
+
+ /*
+ * Find the first match. If the word can be
+ * abbreviated, make sure we match at least
+ * the minimum abbreviation.
+ */
+ for (tp = TimeWords; tp->name; tp++) {
+ size_t abbrev = tp->abbrev;
+ if (abbrev == 0)
+ abbrev = strlen(tp->name);
+ if (strlen(buff) >= abbrev
+ && strncmp(tp->name, buff, strlen(buff))
+ == 0) {
+ /* Skip over token. */
+ *in = src;
+ /* Return the match. */
+ *value = tp->value;
+ return tp->type;
+ }
+ }
+ }
+
+ /*
+ * Not in the word table, maybe it's a number. Note:
+ * Because '-' and '+' have other special meanings, I
+ * don't deal with signed numbers here.
+ */
+ if (isdigit((unsigned char)(c = **in))) {
+ for (*value = 0; isdigit((unsigned char)(c = *(*in)++)); )
+ *value = 10 * *value + c - '0';
+ (*in)--;
+ return (tUNUMBER);
+ }
+
+ return *(*in)++;
+ }
+}
+
+#define TM_YEAR_ORIGIN 1900
+
+/* Yield A - B, measured in seconds. */
+static long
+difftm (struct tm *a, struct tm *b)
+{
+ int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
+ int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
+ int days = (
+ /* difference in day of year */
+ a->tm_yday - b->tm_yday
+ /* + intervening leap days */
+ + ((ay >> 2) - (by >> 2))
+ - (ay/100 - by/100)
+ + ((ay/100 >> 2) - (by/100 >> 2))
+ /* + difference in years * 365 */
+ + (long)(ay-by) * 365
+ );
+ return (days * DAY + (a->tm_hour - b->tm_hour) * HOUR
+ + (a->tm_min - b->tm_min) * MINUTE
+ + (a->tm_sec - b->tm_sec));
+}
+
+/*
+ *
+ * The public function.
+ *
+ * TODO: tokens[] array should be dynamically sized.
+ */
+time_t
+__archive_get_date(time_t now, char *p)
+{
+ struct token tokens[256];
+ struct gdstate _gds;
+ struct token *lasttoken;
+ struct gdstate *gds;
+ struct tm local, *tm;
+ struct tm gmt, *gmt_ptr;
+ time_t Start;
+ time_t tod;
+ long tzone;
+
+ /* Clear out the parsed token array. */
+ memset(tokens, 0, sizeof(tokens));
+ /* Initialize the parser state. */
+ memset(&_gds, 0, sizeof(_gds));
+ gds = &_gds;
+
+ /* Look up the current time. */
+ memset(&local, 0, sizeof(local));
+ tm = localtime (&now);
+ if (tm == NULL)
+ return -1;
+ local = *tm;
+
+ /* Look up UTC if we can and use that to determine the current
+ * timezone offset. */
+ memset(&gmt, 0, sizeof(gmt));
+ gmt_ptr = gmtime (&now);
+ if (gmt_ptr != NULL) {
+ /* Copy, in case localtime and gmtime use the same buffer. */
+ gmt = *gmt_ptr;
+ }
+ if (gmt_ptr != NULL)
+ tzone = difftm (&gmt, &local);
+ else
+ /* This system doesn't understand timezones; fake it. */
+ tzone = 0;
+ if(local.tm_isdst)
+ tzone += HOUR;
+
+ /* Tokenize the input string. */
+ lasttoken = tokens;
+ while ((lasttoken->token = nexttoken(&p, &lasttoken->value)) != 0) {
+ ++lasttoken;
+ if (lasttoken > tokens + 255)
+ return -1;
+ }
+ gds->tokenp = tokens;
+
+ /* Match phrases until we run out of input tokens. */
+ while (gds->tokenp < lasttoken) {
+ if (!phrase(gds))
+ return -1;
+ }
+
+ /* Use current local timezone if none was specified. */
+ if (!gds->HaveZone) {
+ gds->Timezone = tzone;
+ gds->DSTmode = DSTmaybe;
+ }
+
+ /* If a timezone was specified, use that for generating the default
+ * time components instead of the local timezone. */
+ if (gds->HaveZone && gmt_ptr != NULL) {
+ now -= gds->Timezone;
+ gmt_ptr = gmtime (&now);
+ if (gmt_ptr != NULL)
+ local = *gmt_ptr;
+ now += gds->Timezone;
+ }
+
+ if (!gds->HaveYear)
+ gds->Year = local.tm_year + 1900;
+ if (!gds->HaveMonth)
+ gds->Month = local.tm_mon + 1;
+ if (!gds->HaveDay)
+ gds->Day = local.tm_mday;
+ /* Note: No default for hour/min/sec; a specifier that just
+ * gives date always refers to 00:00 on that date. */
+
+ /* If we saw more than one time, timezone, weekday, year, month,
+ * or day, then give up. */
+ if (gds->HaveTime > 1 || gds->HaveZone > 1 || gds->HaveWeekDay > 1
+ || gds->HaveYear > 1 || gds->HaveMonth > 1 || gds->HaveDay > 1)
+ return -1;
+
+ /* Compute an absolute time based on whatever absolute information
+ * we collected. */
+ if (gds->HaveYear || gds->HaveMonth || gds->HaveDay
+ || gds->HaveTime || gds->HaveWeekDay) {
+ Start = Convert(gds->Month, gds->Day, gds->Year,
+ gds->Hour, gds->Minutes, gds->Seconds,
+ gds->Timezone, gds->DSTmode);
+ if (Start < 0)
+ return -1;
+ } else {
+ Start = now;
+ if (!gds->HaveRel)
+ Start -= local.tm_hour * HOUR + local.tm_min * MINUTE
+ + local.tm_sec;
+ }
+
+ /* Add the relative offset. */
+ Start += gds->RelSeconds;
+ Start += RelativeMonth(Start, gds->Timezone, gds->RelMonth);
+
+ /* Adjust for day-of-week offsets. */
+ if (gds->HaveWeekDay
+ && !(gds->HaveYear || gds->HaveMonth || gds->HaveDay)) {
+ tod = RelativeDate(Start, gds->Timezone,
+ gds->DSTmode, gds->DayOrdinal, gds->DayNumber);
+ Start += tod;
+ }
+
+ /* -1 is an error indicator, so return 0 instead of -1 if
+ * that's the actual time. */
+ return Start == -1 ? 0 : Start;
+}
+
+
+#if defined(TEST)
+
+/* ARGSUSED */
+int
+main(int argc, char **argv)
+{
+ time_t d;
+ time_t now = time(NULL);
+
+ while (*++argv != NULL) {
+ (void)printf("Input: %s\n", *argv);
+ d = get_date(now, *argv);
+ if (d == -1)
+ (void)printf("Bad format - couldn't convert.\n");
+ else
+ (void)printf("Output: %s\n", ctime(&d));
+ }
+ exit(0);
+ /* NOTREACHED */
+}
+#endif /* defined(TEST) */
diff --git a/Utilities/cmlibarchive/libarchive/archive_match.c b/Utilities/cmlibarchive/libarchive/archive_match.c
new file mode 100644
index 0000000000..6fb86445cd
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_match.c
@@ -0,0 +1,1841 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_entry.h"
+#include "archive_pathmatch.h"
+#include "archive_rb.h"
+#include "archive_string.h"
+
+struct match {
+ struct match *next;
+ int matches;
+ struct archive_mstring pattern;
+};
+
+struct match_list {
+ struct match *first;
+ struct match **last;
+ int count;
+ int unmatched_count;
+ struct match *unmatched_next;
+ int unmatched_eof;
+};
+
+struct match_file {
+ struct archive_rb_node node;
+ struct match_file *next;
+ struct archive_mstring pathname;
+ int flag;
+ time_t mtime_sec;
+ long mtime_nsec;
+ time_t ctime_sec;
+ long ctime_nsec;
+};
+
+struct entry_list {
+ struct match_file *first;
+ struct match_file **last;
+ int count;
+};
+
+struct id_array {
+ size_t size;/* Allocated size */
+ size_t count;
+ int64_t *ids;
+};
+
+#define PATTERN_IS_SET 1
+#define TIME_IS_SET 2
+#define ID_IS_SET 4
+
+struct archive_match {
+ struct archive archive;
+
+ /* exclusion/inclusion set flag. */
+ int setflag;
+
+ /*
+ * Matching filename patterns.
+ */
+ struct match_list exclusions;
+ struct match_list inclusions;
+
+ /*
+ * Matching time stamps.
+ */
+ time_t now;
+ int newer_mtime_filter;
+ time_t newer_mtime_sec;
+ long newer_mtime_nsec;
+ int newer_ctime_filter;
+ time_t newer_ctime_sec;
+ long newer_ctime_nsec;
+ int older_mtime_filter;
+ time_t older_mtime_sec;
+ long older_mtime_nsec;
+ int older_ctime_filter;
+ time_t older_ctime_sec;
+ long older_ctime_nsec;
+ /*
+ * Matching time stamps with its filename.
+ */
+ struct archive_rb_tree exclusion_tree;
+ struct entry_list exclusion_entry_list;
+
+ /*
+ * Matching file owners.
+ */
+ struct id_array inclusion_uids;
+ struct id_array inclusion_gids;
+ struct match_list inclusion_unames;
+ struct match_list inclusion_gnames;
+};
+
+static int add_pattern_from_file(struct archive_match *,
+ struct match_list *, int, const void *, int);
+static int add_entry(struct archive_match *, int,
+ struct archive_entry *);
+static int add_owner_id(struct archive_match *, struct id_array *,
+ int64_t);
+static int add_owner_name(struct archive_match *, struct match_list *,
+ int, const void *);
+static int add_pattern_mbs(struct archive_match *, struct match_list *,
+ const char *);
+static int add_pattern_wcs(struct archive_match *, struct match_list *,
+ const wchar_t *);
+static int cmp_key_mbs(const struct archive_rb_node *, const void *);
+static int cmp_key_wcs(const struct archive_rb_node *, const void *);
+static int cmp_node_mbs(const struct archive_rb_node *,
+ const struct archive_rb_node *);
+static int cmp_node_wcs(const struct archive_rb_node *,
+ const struct archive_rb_node *);
+static void entry_list_add(struct entry_list *, struct match_file *);
+static void entry_list_free(struct entry_list *);
+static void entry_list_init(struct entry_list *);
+static int error_nomem(struct archive_match *);
+static void match_list_add(struct match_list *, struct match *);
+static void match_list_free(struct match_list *);
+static void match_list_init(struct match_list *);
+static int match_list_unmatched_inclusions_next(struct archive_match *,
+ struct match_list *, int, const void **);
+static int match_owner_id(struct id_array *, int64_t);
+#if !defined(_WIN32) || defined(__CYGWIN__)
+static int match_owner_name_mbs(struct archive_match *,
+ struct match_list *, const char *);
+#else
+static int match_owner_name_wcs(struct archive_match *,
+ struct match_list *, const wchar_t *);
+#endif
+static int match_path_exclusion(struct archive_match *,
+ struct match *, int, const void *);
+static int match_path_inclusion(struct archive_match *,
+ struct match *, int, const void *);
+static int owner_excluded(struct archive_match *,
+ struct archive_entry *);
+static int path_excluded(struct archive_match *, int, const void *);
+static int set_timefilter(struct archive_match *, int, time_t, long,
+ time_t, long);
+static int set_timefilter_pathname_mbs(struct archive_match *,
+ int, const char *);
+static int set_timefilter_pathname_wcs(struct archive_match *,
+ int, const wchar_t *);
+static int set_timefilter_date(struct archive_match *, int, const char *);
+static int set_timefilter_date_w(struct archive_match *, int,
+ const wchar_t *);
+static int time_excluded(struct archive_match *,
+ struct archive_entry *);
+static int validate_time_flag(struct archive *, int, const char *);
+
+time_t __archive_get_date(time_t now, const char *);
+#define get_date __archive_get_date
+
+static const struct archive_rb_tree_ops rb_ops_mbs = {
+ cmp_node_mbs, cmp_key_mbs
+};
+
+static const struct archive_rb_tree_ops rb_ops_wcs = {
+ cmp_node_wcs, cmp_key_wcs
+};
+
+/*
+ * The matching logic here needs to be re-thought. I started out to
+ * try to mimic gtar's matching logic, but it's not entirely
+ * consistent. In particular 'tar -t' and 'tar -x' interpret patterns
+ * on the command line as anchored, but --exclude doesn't.
+ */
+
+static int
+error_nomem(struct archive_match *a)
+{
+ archive_set_error(&(a->archive), ENOMEM, "No memory");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Create an ARCHIVE_MATCH object.
+ */
+struct archive *
+archive_match_new(void)
+{
+ struct archive_match *a;
+
+ a = (struct archive_match *)calloc(1, sizeof(*a));
+ if (a == NULL)
+ return (NULL);
+ a->archive.magic = ARCHIVE_MATCH_MAGIC;
+ a->archive.state = ARCHIVE_STATE_NEW;
+ match_list_init(&(a->inclusions));
+ match_list_init(&(a->exclusions));
+ __archive_rb_tree_init(&(a->exclusion_tree), &rb_ops_mbs);
+ entry_list_init(&(a->exclusion_entry_list));
+ match_list_init(&(a->inclusion_unames));
+ match_list_init(&(a->inclusion_gnames));
+ time(&a->now);
+ return (&(a->archive));
+}
+
+/*
+ * Free an ARCHIVE_MATCH object.
+ */
+int
+archive_match_free(struct archive *_a)
+{
+ struct archive_match *a;
+
+ if (_a == NULL)
+ return (ARCHIVE_OK);
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_match_free");
+ a = (struct archive_match *)_a;
+ match_list_free(&(a->inclusions));
+ match_list_free(&(a->exclusions));
+ entry_list_free(&(a->exclusion_entry_list));
+ free(a->inclusion_uids.ids);
+ free(a->inclusion_gids.ids);
+ match_list_free(&(a->inclusion_unames));
+ match_list_free(&(a->inclusion_gnames));
+ free(a);
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Convenience function to perform all exclusion tests.
+ *
+ * Returns 1 if archive entry is excluded.
+ * Returns 0 if archive entry is not excluded.
+ * Returns <0 if something error happened.
+ */
+int
+archive_match_excluded(struct archive *_a, struct archive_entry *entry)
+{
+ struct archive_match *a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_excluded_ae");
+
+ a = (struct archive_match *)_a;
+ if (entry == NULL) {
+ archive_set_error(&(a->archive), EINVAL, "entry is NULL");
+ return (ARCHIVE_FAILED);
+ }
+
+ r = 0;
+ if (a->setflag & PATTERN_IS_SET) {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ r = path_excluded(a, 0, archive_entry_pathname_w(entry));
+#else
+ r = path_excluded(a, 1, archive_entry_pathname(entry));
+#endif
+ if (r != 0)
+ return (r);
+ }
+
+ if (a->setflag & TIME_IS_SET) {
+ r = time_excluded(a, entry);
+ if (r != 0)
+ return (r);
+ }
+
+ if (a->setflag & ID_IS_SET)
+ r = owner_excluded(a, entry);
+ return (r);
+}
+
+/*
+ * Utility functions to manage exclusion/inclusion patterns
+ */
+
+int
+archive_match_exclude_pattern(struct archive *_a, const char *pattern)
+{
+ struct archive_match *a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_exclude_pattern");
+ a = (struct archive_match *)_a;
+
+ if (pattern == NULL || *pattern == '\0') {
+ archive_set_error(&(a->archive), EINVAL, "pattern is empty");
+ return (ARCHIVE_FAILED);
+ }
+ if ((r = add_pattern_mbs(a, &(a->exclusions), pattern)) != ARCHIVE_OK)
+ return (r);
+ return (ARCHIVE_OK);
+}
+
+int
+archive_match_exclude_pattern_w(struct archive *_a, const wchar_t *pattern)
+{
+ struct archive_match *a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_exclude_pattern_w");
+ a = (struct archive_match *)_a;
+
+ if (pattern == NULL || *pattern == L'\0') {
+ archive_set_error(&(a->archive), EINVAL, "pattern is empty");
+ return (ARCHIVE_FAILED);
+ }
+ if ((r = add_pattern_wcs(a, &(a->exclusions), pattern)) != ARCHIVE_OK)
+ return (r);
+ return (ARCHIVE_OK);
+}
+
+int
+archive_match_exclude_pattern_from_file(struct archive *_a,
+ const char *pathname, int nullSeparator)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_exclude_pattern_from_file");
+ a = (struct archive_match *)_a;
+
+ return add_pattern_from_file(a, &(a->exclusions), 1, pathname,
+ nullSeparator);
+}
+
+int
+archive_match_exclude_pattern_from_file_w(struct archive *_a,
+ const wchar_t *pathname, int nullSeparator)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_exclude_pattern_from_file_w");
+ a = (struct archive_match *)_a;
+
+ return add_pattern_from_file(a, &(a->exclusions), 0, pathname,
+ nullSeparator);
+}
+
+int
+archive_match_include_pattern(struct archive *_a, const char *pattern)
+{
+ struct archive_match *a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_pattern");
+ a = (struct archive_match *)_a;
+
+ if (pattern == NULL || *pattern == '\0') {
+ archive_set_error(&(a->archive), EINVAL, "pattern is empty");
+ return (ARCHIVE_FAILED);
+ }
+ if ((r = add_pattern_mbs(a, &(a->inclusions), pattern)) != ARCHIVE_OK)
+ return (r);
+ return (ARCHIVE_OK);
+}
+
+int
+archive_match_include_pattern_w(struct archive *_a, const wchar_t *pattern)
+{
+ struct archive_match *a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_pattern_w");
+ a = (struct archive_match *)_a;
+
+ if (pattern == NULL || *pattern == L'\0') {
+ archive_set_error(&(a->archive), EINVAL, "pattern is empty");
+ return (ARCHIVE_FAILED);
+ }
+ if ((r = add_pattern_wcs(a, &(a->inclusions), pattern)) != ARCHIVE_OK)
+ return (r);
+ return (ARCHIVE_OK);
+}
+
+int
+archive_match_include_pattern_from_file(struct archive *_a,
+ const char *pathname, int nullSeparator)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_pattern_from_file");
+ a = (struct archive_match *)_a;
+
+ return add_pattern_from_file(a, &(a->inclusions), 1, pathname,
+ nullSeparator);
+}
+
+int
+archive_match_include_pattern_from_file_w(struct archive *_a,
+ const wchar_t *pathname, int nullSeparator)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_pattern_from_file_w");
+ a = (struct archive_match *)_a;
+
+ return add_pattern_from_file(a, &(a->inclusions), 0, pathname,
+ nullSeparator);
+}
+
+/*
+ * Test functions for pathname patterns.
+ *
+ * Returns 1 if archive entry is excluded.
+ * Returns 0 if archive entry is not excluded.
+ * Returns <0 if something error happened.
+ */
+int
+archive_match_path_excluded(struct archive *_a,
+ struct archive_entry *entry)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_path_excluded");
+
+ a = (struct archive_match *)_a;
+ if (entry == NULL) {
+ archive_set_error(&(a->archive), EINVAL, "entry is NULL");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* If we don't have exclusion/inclusion pattern set at all,
+ * the entry is always not excluded. */
+ if ((a->setflag & PATTERN_IS_SET) == 0)
+ return (0);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ return (path_excluded(a, 0, archive_entry_pathname_w(entry)));
+#else
+ return (path_excluded(a, 1, archive_entry_pathname(entry)));
+#endif
+}
+
+/*
+ * Utilty functions to get statistic information for inclusion patterns.
+ */
+int
+archive_match_path_unmatched_inclusions(struct archive *_a)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_unmatched_inclusions");
+ a = (struct archive_match *)_a;
+
+ return (a->inclusions.unmatched_count);
+}
+
+int
+archive_match_path_unmatched_inclusions_next(struct archive *_a,
+ const char **_p)
+{
+ struct archive_match *a;
+ const void *v;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_unmatched_inclusions_next");
+ a = (struct archive_match *)_a;
+
+ r = match_list_unmatched_inclusions_next(a, &(a->inclusions), 1, &v);
+ *_p = (const char *)v;
+ return (r);
+}
+
+int
+archive_match_path_unmatched_inclusions_next_w(struct archive *_a,
+ const wchar_t **_p)
+{
+ struct archive_match *a;
+ const void *v;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_unmatched_inclusions_next_w");
+ a = (struct archive_match *)_a;
+
+ r = match_list_unmatched_inclusions_next(a, &(a->inclusions), 0, &v);
+ *_p = (const wchar_t *)v;
+ return (r);
+}
+
+/*
+ * Add inclusion/exclusion patterns.
+ */
+static int
+add_pattern_mbs(struct archive_match *a, struct match_list *list,
+ const char *pattern)
+{
+ struct match *match;
+ size_t len;
+
+ match = calloc(1, sizeof(*match));
+ if (match == NULL)
+ return (error_nomem(a));
+ /* Both "foo/" and "foo" should match "foo/bar". */
+ len = strlen(pattern);
+ if (len && pattern[len - 1] == '/')
+ --len;
+ archive_mstring_copy_mbs_len(&(match->pattern), pattern, len);
+ match_list_add(list, match);
+ a->setflag |= PATTERN_IS_SET;
+ return (ARCHIVE_OK);
+}
+
+static int
+add_pattern_wcs(struct archive_match *a, struct match_list *list,
+ const wchar_t *pattern)
+{
+ struct match *match;
+ size_t len;
+
+ match = calloc(1, sizeof(*match));
+ if (match == NULL)
+ return (error_nomem(a));
+ /* Both "foo/" and "foo" should match "foo/bar". */
+ len = wcslen(pattern);
+ if (len && pattern[len - 1] == L'/')
+ --len;
+ archive_mstring_copy_wcs_len(&(match->pattern), pattern, len);
+ match_list_add(list, match);
+ a->setflag |= PATTERN_IS_SET;
+ return (ARCHIVE_OK);
+}
+
+static int
+add_pattern_from_file(struct archive_match *a, struct match_list *mlist,
+ int mbs, const void *pathname, int nullSeparator)
+{
+ struct archive *ar;
+ struct archive_entry *ae;
+ struct archive_string as;
+ const void *buff;
+ size_t size;
+ int64_t offset;
+ int r;
+
+ ar = archive_read_new();
+ if (ar == NULL) {
+ archive_set_error(&(a->archive), ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ r = archive_read_support_format_raw(ar);
+ if (r != ARCHIVE_OK) {
+ archive_copy_error(&(a->archive), ar);
+ archive_read_free(ar);
+ return (r);
+ }
+ if (mbs)
+ r = archive_read_open_filename(ar, pathname, 512*20);
+ else
+ r = archive_read_open_filename_w(ar, pathname, 512*20);
+ if (r != ARCHIVE_OK) {
+ archive_copy_error(&(a->archive), ar);
+ archive_read_free(ar);
+ return (r);
+ }
+ r = archive_read_next_header(ar, &ae);
+ if (r != ARCHIVE_OK) {
+ archive_copy_error(&(a->archive), ar);
+ archive_read_free(ar);
+ return (r);
+ }
+
+ archive_string_init(&as);
+
+ while ((r = archive_read_data_block(ar, &buff, &size, &offset))
+ == ARCHIVE_OK) {
+ const char *b = (const char *)buff;
+
+ while (size) {
+ const char *s = (const char *)b;
+ size_t length = 0;
+ int found_separator = 0;
+
+ while (length < size) {
+ if (nullSeparator) {
+ if (*b == '\0') {
+ found_separator = 1;
+ break;
+ }
+ } else {
+ if (*b == 0x0d || *b == 0x0a) {
+ found_separator = 1;
+ break;
+ }
+ }
+ b++;
+ length++;
+ }
+ if (!found_separator) {
+ archive_strncat(&as, s, length);
+ /* Read next data block. */
+ break;
+ }
+ b++;
+ size -= length + 1;
+ archive_strncat(&as, s, length);
+
+ /* If the line is not empty, add the pattern. */
+ if (archive_strlen(&as) > 0) {
+ /* Add pattern. */
+ r = add_pattern_mbs(a, mlist, as.s);
+ if (r != ARCHIVE_OK) {
+ archive_read_free(ar);
+ archive_string_free(&as);
+ return (r);
+ }
+ archive_string_empty(&as);
+ }
+ }
+ }
+
+ /* If something error happend, report it immediately. */
+ if (r < ARCHIVE_OK) {
+ archive_copy_error(&(a->archive), ar);
+ archive_read_free(ar);
+ archive_string_free(&as);
+ return (r);
+ }
+
+ /* If the line is not empty, add the pattern. */
+ if (r == ARCHIVE_EOF && archive_strlen(&as) > 0) {
+ /* Add pattern. */
+ r = add_pattern_mbs(a, mlist, as.s);
+ if (r != ARCHIVE_OK) {
+ archive_read_free(ar);
+ archive_string_free(&as);
+ return (r);
+ }
+ }
+ archive_read_free(ar);
+ archive_string_free(&as);
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Test if pathname is excluded by inclusion/exclusion patterns.
+ */
+static int
+path_excluded(struct archive_match *a, int mbs, const void *pathname)
+{
+ struct match *match;
+ struct match *matched;
+ int r;
+
+ if (a == NULL)
+ return (0);
+
+ /* Mark off any unmatched inclusions. */
+ /* In particular, if a filename does appear in the archive and
+ * is explicitly included and excluded, then we don't report
+ * it as missing even though we don't extract it.
+ */
+ matched = NULL;
+ for (match = a->inclusions.first; match != NULL;
+ match = match->next){
+ if (match->matches == 0 &&
+ (r = match_path_inclusion(a, match, mbs, pathname)) != 0) {
+ if (r < 0)
+ return (r);
+ a->inclusions.unmatched_count--;
+ match->matches++;
+ matched = match;
+ }
+ }
+
+ /* Exclusions take priority */
+ for (match = a->exclusions.first; match != NULL;
+ match = match->next){
+ r = match_path_exclusion(a, match, mbs, pathname);
+ if (r)
+ return (r);
+ }
+
+ /* It's not excluded and we found an inclusion above, so it's
+ * included. */
+ if (matched != NULL)
+ return (0);
+
+
+ /* We didn't find an unmatched inclusion, check the remaining ones. */
+ for (match = a->inclusions.first; match != NULL;
+ match = match->next){
+ /* We looked at previously-unmatched inclusions already. */
+ if (match->matches > 0 &&
+ (r = match_path_inclusion(a, match, mbs, pathname)) != 0) {
+ if (r < 0)
+ return (r);
+ match->matches++;
+ return (0);
+ }
+ }
+
+ /* If there were inclusions, default is to exclude. */
+ if (a->inclusions.first != NULL)
+ return (1);
+
+ /* No explicit inclusions, default is to match. */
+ return (0);
+}
+
+/*
+ * This is a little odd, but it matches the default behavior of
+ * gtar. In particular, 'a*b' will match 'foo/a1111/222b/bar'
+ *
+ */
+static int
+match_path_exclusion(struct archive_match *a, struct match *m,
+ int mbs, const void *pn)
+{
+ int flag = PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END;
+ int r;
+
+ if (mbs) {
+ const char *p;
+ r = archive_mstring_get_mbs(&(a->archive), &(m->pattern), &p);
+ if (r == 0)
+ return (archive_pathmatch(p, (const char *)pn, flag));
+ } else {
+ const wchar_t *p;
+ r = archive_mstring_get_wcs(&(a->archive), &(m->pattern), &p);
+ if (r == 0)
+ return (archive_pathmatch_w(p, (const wchar_t *)pn,
+ flag));
+ }
+ if (errno == ENOMEM)
+ return (error_nomem(a));
+ return (0);
+}
+
+/*
+ * Again, mimic gtar: inclusions are always anchored (have to match
+ * the beginning of the path) even though exclusions are not anchored.
+ */
+static int
+match_path_inclusion(struct archive_match *a, struct match *m,
+ int mbs, const void *pn)
+{
+ int flag = PATHMATCH_NO_ANCHOR_END;
+ int r;
+
+ if (mbs) {
+ const char *p;
+ r = archive_mstring_get_mbs(&(a->archive), &(m->pattern), &p);
+ if (r == 0)
+ return (archive_pathmatch(p, (const char *)pn, flag));
+ } else {
+ const wchar_t *p;
+ r = archive_mstring_get_wcs(&(a->archive), &(m->pattern), &p);
+ if (r == 0)
+ return (archive_pathmatch_w(p, (const wchar_t *)pn,
+ flag));
+ }
+ if (errno == ENOMEM)
+ return (error_nomem(a));
+ return (0);
+}
+
+static void
+match_list_init(struct match_list *list)
+{
+ list->first = NULL;
+ list->last = &(list->first);
+ list->count = 0;
+}
+
+static void
+match_list_free(struct match_list *list)
+{
+ struct match *p, *q;
+
+ for (p = list->first; p != NULL; ) {
+ q = p;
+ p = p->next;
+ archive_mstring_clean(&(q->pattern));
+ free(q);
+ }
+}
+
+static void
+match_list_add(struct match_list *list, struct match *m)
+{
+ *list->last = m;
+ list->last = &(m->next);
+ list->count++;
+ list->unmatched_count++;
+}
+
+static int
+match_list_unmatched_inclusions_next(struct archive_match *a,
+ struct match_list *list, int mbs, const void **vp)
+{
+ struct match *m;
+
+ *vp = NULL;
+ if (list->unmatched_eof) {
+ list->unmatched_eof = 0;
+ return (ARCHIVE_EOF);
+ }
+ if (list->unmatched_next == NULL) {
+ if (list->unmatched_count == 0)
+ return (ARCHIVE_EOF);
+ list->unmatched_next = list->first;
+ }
+
+ for (m = list->unmatched_next; m != NULL; m = m->next) {
+ int r;
+
+ if (m->matches)
+ continue;
+ if (mbs) {
+ const char *p;
+ r = archive_mstring_get_mbs(&(a->archive),
+ &(m->pattern), &p);
+ if (r < 0 && errno == ENOMEM)
+ return (error_nomem(a));
+ if (p == NULL)
+ p = "";
+ *vp = p;
+ } else {
+ const wchar_t *p;
+ r = archive_mstring_get_wcs(&(a->archive),
+ &(m->pattern), &p);
+ if (r < 0 && errno == ENOMEM)
+ return (error_nomem(a));
+ if (p == NULL)
+ p = L"";
+ *vp = p;
+ }
+ list->unmatched_next = m->next;
+ if (list->unmatched_next == NULL)
+ /* To return EOF next time. */
+ list->unmatched_eof = 1;
+ return (ARCHIVE_OK);
+ }
+ list->unmatched_next = NULL;
+ return (ARCHIVE_EOF);
+}
+
+/*
+ * Utility functions to manage inclusion timestamps.
+ */
+int
+archive_match_include_time(struct archive *_a, int flag, time_t sec,
+ long nsec)
+{
+ int r;
+
+ r = validate_time_flag(_a, flag, "archive_match_include_time");
+ if (r != ARCHIVE_OK)
+ return (r);
+ return set_timefilter((struct archive_match *)_a, flag,
+ sec, nsec, sec, nsec);
+}
+
+int
+archive_match_include_date(struct archive *_a, int flag,
+ const char *datestr)
+{
+ int r;
+
+ r = validate_time_flag(_a, flag, "archive_match_include_date");
+ if (r != ARCHIVE_OK)
+ return (r);
+ return set_timefilter_date((struct archive_match *)_a, flag, datestr);
+}
+
+int
+archive_match_include_date_w(struct archive *_a, int flag,
+ const wchar_t *datestr)
+{
+ int r;
+
+ r = validate_time_flag(_a, flag, "archive_match_include_date_w");
+ if (r != ARCHIVE_OK)
+ return (r);
+
+ return set_timefilter_date_w((struct archive_match *)_a, flag, datestr);
+}
+
+int
+archive_match_include_file_time(struct archive *_a, int flag,
+ const char *pathname)
+{
+ int r;
+
+ r = validate_time_flag(_a, flag, "archive_match_include_file_time");
+ if (r != ARCHIVE_OK)
+ return (r);
+ return set_timefilter_pathname_mbs((struct archive_match *)_a,
+ flag, pathname);
+}
+
+int
+archive_match_include_file_time_w(struct archive *_a, int flag,
+ const wchar_t *pathname)
+{
+ int r;
+
+ r = validate_time_flag(_a, flag, "archive_match_include_file_time_w");
+ if (r != ARCHIVE_OK)
+ return (r);
+ return set_timefilter_pathname_wcs((struct archive_match *)_a,
+ flag, pathname);
+}
+
+int
+archive_match_exclude_entry(struct archive *_a, int flag,
+ struct archive_entry *entry)
+{
+ struct archive_match *a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_time_include_entry");
+ a = (struct archive_match *)_a;
+
+ if (entry == NULL) {
+ archive_set_error(&(a->archive), EINVAL, "entry is NULL");
+ return (ARCHIVE_FAILED);
+ }
+ r = validate_time_flag(_a, flag, "archive_match_exclude_entry");
+ if (r != ARCHIVE_OK)
+ return (r);
+ return (add_entry(a, flag, entry));
+}
+
+/*
+ * Test function for time stamps.
+ *
+ * Returns 1 if archive entry is excluded.
+ * Returns 0 if archive entry is not excluded.
+ * Returns <0 if something error happened.
+ */
+int
+archive_match_time_excluded(struct archive *_a,
+ struct archive_entry *entry)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_time_excluded_ae");
+
+ a = (struct archive_match *)_a;
+ if (entry == NULL) {
+ archive_set_error(&(a->archive), EINVAL, "entry is NULL");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* If we don't have inclusion time set at all, the entry is always
+ * not excluded. */
+ if ((a->setflag & TIME_IS_SET) == 0)
+ return (0);
+ return (time_excluded(a, entry));
+}
+
+static int
+validate_time_flag(struct archive *_a, int flag, const char *_fn)
+{
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, _fn);
+
+ /* Check a type of time. */
+ if (flag &
+ ((~(ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME)) & 0xff00)) {
+ archive_set_error(_a, EINVAL, "Invalid time flag");
+ return (ARCHIVE_FAILED);
+ }
+ if ((flag & (ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME)) == 0) {
+ archive_set_error(_a, EINVAL, "No time flag");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Check a type of comparison. */
+ if (flag &
+ ((~(ARCHIVE_MATCH_NEWER | ARCHIVE_MATCH_OLDER
+ | ARCHIVE_MATCH_EQUAL)) & 0x00ff)) {
+ archive_set_error(_a, EINVAL, "Invalid comparison flag");
+ return (ARCHIVE_FAILED);
+ }
+ if ((flag & (ARCHIVE_MATCH_NEWER | ARCHIVE_MATCH_OLDER
+ | ARCHIVE_MATCH_EQUAL)) == 0) {
+ archive_set_error(_a, EINVAL, "No comparison flag");
+ return (ARCHIVE_FAILED);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+#define JUST_EQUAL(t) (((t) & (ARCHIVE_MATCH_EQUAL |\
+ ARCHIVE_MATCH_NEWER | ARCHIVE_MATCH_OLDER)) == ARCHIVE_MATCH_EQUAL)
+static int
+set_timefilter(struct archive_match *a, int timetype,
+ time_t mtime_sec, long mtime_nsec, time_t ctime_sec, long ctime_nsec)
+{
+ if (timetype & ARCHIVE_MATCH_MTIME) {
+ if ((timetype & ARCHIVE_MATCH_NEWER) || JUST_EQUAL(timetype)) {
+ a->newer_mtime_filter = timetype;
+ a->newer_mtime_sec = mtime_sec;
+ a->newer_mtime_nsec = mtime_nsec;
+ a->setflag |= TIME_IS_SET;
+ }
+ if ((timetype & ARCHIVE_MATCH_OLDER) || JUST_EQUAL(timetype)) {
+ a->older_mtime_filter = timetype;
+ a->older_mtime_sec = mtime_sec;
+ a->older_mtime_nsec = mtime_nsec;
+ a->setflag |= TIME_IS_SET;
+ }
+ }
+ if (timetype & ARCHIVE_MATCH_CTIME) {
+ if ((timetype & ARCHIVE_MATCH_NEWER) || JUST_EQUAL(timetype)) {
+ a->newer_ctime_filter = timetype;
+ a->newer_ctime_sec = ctime_sec;
+ a->newer_ctime_nsec = ctime_nsec;
+ a->setflag |= TIME_IS_SET;
+ }
+ if ((timetype & ARCHIVE_MATCH_OLDER) || JUST_EQUAL(timetype)) {
+ a->older_ctime_filter = timetype;
+ a->older_ctime_sec = ctime_sec;
+ a->older_ctime_nsec = ctime_nsec;
+ a->setflag |= TIME_IS_SET;
+ }
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+set_timefilter_date(struct archive_match *a, int timetype, const char *datestr)
+{
+ time_t t;
+
+ if (datestr == NULL || *datestr == '\0') {
+ archive_set_error(&(a->archive), EINVAL, "date is empty");
+ return (ARCHIVE_FAILED);
+ }
+ t = get_date(a->now, datestr);
+ if (t == (time_t)-1) {
+ archive_set_error(&(a->archive), EINVAL, "invalid date string");
+ return (ARCHIVE_FAILED);
+ }
+ return set_timefilter(a, timetype, t, 0, t, 0);
+}
+
+static int
+set_timefilter_date_w(struct archive_match *a, int timetype,
+ const wchar_t *datestr)
+{
+ struct archive_string as;
+ time_t t;
+
+ if (datestr == NULL || *datestr == L'\0') {
+ archive_set_error(&(a->archive), EINVAL, "date is empty");
+ return (ARCHIVE_FAILED);
+ }
+
+ archive_string_init(&as);
+ if (archive_string_append_from_wcs(&as, datestr, wcslen(datestr)) < 0) {
+ archive_string_free(&as);
+ if (errno == ENOMEM)
+ return (error_nomem(a));
+ archive_set_error(&(a->archive), -1,
+ "Failed to convert WCS to MBS");
+ return (ARCHIVE_FAILED);
+ }
+ t = get_date(a->now, as.s);
+ archive_string_free(&as);
+ if (t == (time_t)-1) {
+ archive_set_error(&(a->archive), EINVAL, "invalid date string");
+ return (ARCHIVE_FAILED);
+ }
+ return set_timefilter(a, timetype, t, 0, t, 0);
+}
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
+static int
+set_timefilter_find_data(struct archive_match *a, int timetype,
+ DWORD ftLastWriteTime_dwHighDateTime, DWORD ftLastWriteTime_dwLowDateTime,
+ DWORD ftCreationTime_dwHighDateTime, DWORD ftCreationTime_dwLowDateTime)
+{
+ ULARGE_INTEGER utc;
+ time_t ctime_sec, mtime_sec;
+ long ctime_ns, mtime_ns;
+
+ utc.HighPart = ftCreationTime_dwHighDateTime;
+ utc.LowPart = ftCreationTime_dwLowDateTime;
+ if (utc.QuadPart >= EPOC_TIME) {
+ utc.QuadPart -= EPOC_TIME;
+ ctime_sec = (time_t)(utc.QuadPart / 10000000);
+ ctime_ns = (long)(utc.QuadPart % 10000000) * 100;
+ } else {
+ ctime_sec = 0;
+ ctime_ns = 0;
+ }
+ utc.HighPart = ftLastWriteTime_dwHighDateTime;
+ utc.LowPart = ftLastWriteTime_dwLowDateTime;
+ if (utc.QuadPart >= EPOC_TIME) {
+ utc.QuadPart -= EPOC_TIME;
+ mtime_sec = (time_t)(utc.QuadPart / 10000000);
+ mtime_ns = (long)(utc.QuadPart % 10000000) * 100;
+ } else {
+ mtime_sec = 0;
+ mtime_ns = 0;
+ }
+ return set_timefilter(a, timetype,
+ mtime_sec, mtime_ns, ctime_sec, ctime_ns);
+}
+
+static int
+set_timefilter_pathname_mbs(struct archive_match *a, int timetype,
+ const char *path)
+{
+ /* NOTE: stat() on Windows cannot handle nano seconds. */
+ HANDLE h;
+ WIN32_FIND_DATAA d;
+
+ if (path == NULL || *path == '\0') {
+ archive_set_error(&(a->archive), EINVAL, "pathname is empty");
+ return (ARCHIVE_FAILED);
+ }
+ h = FindFirstFileA(path, &d);
+ if (h == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&(a->archive), errno,
+ "Failed to FindFirstFileA");
+ return (ARCHIVE_FAILED);
+ }
+ FindClose(h);
+ return set_timefilter_find_data(a, timetype,
+ d.ftLastWriteTime.dwHighDateTime, d.ftLastWriteTime.dwLowDateTime,
+ d.ftCreationTime.dwHighDateTime, d.ftCreationTime.dwLowDateTime);
+}
+
+static int
+set_timefilter_pathname_wcs(struct archive_match *a, int timetype,
+ const wchar_t *path)
+{
+ HANDLE h;
+ WIN32_FIND_DATAW d;
+
+ if (path == NULL || *path == L'\0') {
+ archive_set_error(&(a->archive), EINVAL, "pathname is empty");
+ return (ARCHIVE_FAILED);
+ }
+ h = FindFirstFileW(path, &d);
+ if (h == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&(a->archive), errno,
+ "Failed to FindFirstFile");
+ return (ARCHIVE_FAILED);
+ }
+ FindClose(h);
+ return set_timefilter_find_data(a, timetype,
+ d.ftLastWriteTime.dwHighDateTime, d.ftLastWriteTime.dwLowDateTime,
+ d.ftCreationTime.dwHighDateTime, d.ftCreationTime.dwLowDateTime);
+}
+
+#else /* _WIN32 && !__CYGWIN__ */
+
+static int
+set_timefilter_stat(struct archive_match *a, int timetype, struct stat *st)
+{
+ struct archive_entry *ae;
+ time_t ctime_sec, mtime_sec;
+ long ctime_ns, mtime_ns;
+
+ ae = archive_entry_new();
+ if (ae == NULL)
+ return (error_nomem(a));
+ archive_entry_copy_stat(ae, st);
+ ctime_sec = archive_entry_ctime(ae);
+ ctime_ns = archive_entry_ctime_nsec(ae);
+ mtime_sec = archive_entry_mtime(ae);
+ mtime_ns = archive_entry_mtime_nsec(ae);
+ archive_entry_free(ae);
+ return set_timefilter(a, timetype, mtime_sec, mtime_ns,
+ ctime_sec, ctime_ns);
+}
+
+static int
+set_timefilter_pathname_mbs(struct archive_match *a, int timetype,
+ const char *path)
+{
+ struct stat st;
+
+ if (path == NULL || *path == '\0') {
+ archive_set_error(&(a->archive), EINVAL, "pathname is empty");
+ return (ARCHIVE_FAILED);
+ }
+ if (stat(path, &st) != 0) {
+ archive_set_error(&(a->archive), errno, "Failed to stat()");
+ return (ARCHIVE_FAILED);
+ }
+ return (set_timefilter_stat(a, timetype, &st));
+}
+
+static int
+set_timefilter_pathname_wcs(struct archive_match *a, int timetype,
+ const wchar_t *path)
+{
+ struct archive_string as;
+ int r;
+
+ if (path == NULL || *path == L'\0') {
+ archive_set_error(&(a->archive), EINVAL, "pathname is empty");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Convert WCS filename to MBS filename. */
+ archive_string_init(&as);
+ if (archive_string_append_from_wcs(&as, path, wcslen(path)) < 0) {
+ archive_string_free(&as);
+ if (errno == ENOMEM)
+ return (error_nomem(a));
+ archive_set_error(&(a->archive), -1,
+ "Failed to convert WCS to MBS");
+ return (ARCHIVE_FAILED);
+ }
+
+ r = set_timefilter_pathname_mbs(a, timetype, as.s);
+ archive_string_free(&as);
+
+ return (r);
+}
+#endif /* _WIN32 && !__CYGWIN__ */
+
+/*
+ * Call back funtions for archive_rb.
+ */
+static int
+cmp_node_mbs(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ struct match_file *f1 = (struct match_file *)(uintptr_t)n1;
+ struct match_file *f2 = (struct match_file *)(uintptr_t)n2;
+ const char *p1, *p2;
+
+ archive_mstring_get_mbs(NULL, &(f1->pathname), &p1);
+ archive_mstring_get_mbs(NULL, &(f2->pathname), &p2);
+ if (p1 == NULL)
+ return (1);
+ if (p2 == NULL)
+ return (-1);
+ return (strcmp(p1, p2));
+}
+
+static int
+cmp_key_mbs(const struct archive_rb_node *n, const void *key)
+{
+ struct match_file *f = (struct match_file *)(uintptr_t)n;
+ const char *p;
+
+ archive_mstring_get_mbs(NULL, &(f->pathname), &p);
+ if (p == NULL)
+ return (-1);
+ return (strcmp(p, (const char *)key));
+}
+
+static int
+cmp_node_wcs(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ struct match_file *f1 = (struct match_file *)(uintptr_t)n1;
+ struct match_file *f2 = (struct match_file *)(uintptr_t)n2;
+ const wchar_t *p1, *p2;
+
+ archive_mstring_get_wcs(NULL, &(f1->pathname), &p1);
+ archive_mstring_get_wcs(NULL, &(f2->pathname), &p2);
+ if (p1 == NULL)
+ return (1);
+ if (p2 == NULL)
+ return (-1);
+ return (wcscmp(p1, p2));
+}
+
+static int
+cmp_key_wcs(const struct archive_rb_node *n, const void *key)
+{
+ struct match_file *f = (struct match_file *)(uintptr_t)n;
+ const wchar_t *p;
+
+ archive_mstring_get_wcs(NULL, &(f->pathname), &p);
+ if (p == NULL)
+ return (-1);
+ return (wcscmp(p, (const wchar_t *)key));
+}
+
+static void
+entry_list_init(struct entry_list *list)
+{
+ list->first = NULL;
+ list->last = &(list->first);
+ list->count = 0;
+}
+
+static void
+entry_list_free(struct entry_list *list)
+{
+ struct match_file *p, *q;
+
+ for (p = list->first; p != NULL; ) {
+ q = p;
+ p = p->next;
+ archive_mstring_clean(&(q->pathname));
+ free(q);
+ }
+}
+
+static void
+entry_list_add(struct entry_list *list, struct match_file *file)
+{
+ *list->last = file;
+ list->last = &(file->next);
+ list->count++;
+}
+
+static int
+add_entry(struct archive_match *a, int flag,
+ struct archive_entry *entry)
+{
+ struct match_file *f;
+ const void *pathname;
+ int r;
+
+ f = calloc(1, sizeof(*f));
+ if (f == NULL)
+ return (error_nomem(a));
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ pathname = archive_entry_pathname_w(entry);
+ if (pathname == NULL) {
+ free(f);
+ archive_set_error(&(a->archive), EINVAL, "pathname is NULL");
+ return (ARCHIVE_FAILED);
+ }
+ archive_mstring_copy_wcs(&(f->pathname), pathname);
+ a->exclusion_tree.rbt_ops = &rb_ops_wcs;
+#else
+ (void)rb_ops_wcs;
+ pathname = archive_entry_pathname(entry);
+ if (pathname == NULL) {
+ free(f);
+ archive_set_error(&(a->archive), EINVAL, "pathname is NULL");
+ return (ARCHIVE_FAILED);
+ }
+ archive_mstring_copy_mbs(&(f->pathname), pathname);
+ a->exclusion_tree.rbt_ops = &rb_ops_mbs;
+#endif
+ f->flag = flag;
+ f->mtime_sec = archive_entry_mtime(entry);
+ f->mtime_nsec = archive_entry_mtime_nsec(entry);
+ f->ctime_sec = archive_entry_ctime(entry);
+ f->ctime_nsec = archive_entry_ctime_nsec(entry);
+ r = __archive_rb_tree_insert_node(&(a->exclusion_tree), &(f->node));
+ if (!r) {
+ struct match_file *f2;
+
+ /* Get the duplicated file. */
+ f2 = (struct match_file *)__archive_rb_tree_find_node(
+ &(a->exclusion_tree), pathname);
+
+ /*
+ * We always overwrite comparison condision.
+ * If you do not want to overwrite it, you should not
+ * call archive_match_exclude_entry(). We cannot know
+ * what behavior you really expect since overwriting
+ * condition might be different with the flag.
+ */
+ if (f2 != NULL) {
+ f2->flag = f->flag;
+ f2->mtime_sec = f->mtime_sec;
+ f2->mtime_nsec = f->mtime_nsec;
+ f2->ctime_sec = f->ctime_sec;
+ f2->ctime_nsec = f->ctime_nsec;
+ }
+ /* Release the duplicated file. */
+ archive_mstring_clean(&(f->pathname));
+ free(f);
+ return (ARCHIVE_OK);
+ }
+ entry_list_add(&(a->exclusion_entry_list), f);
+ a->setflag |= TIME_IS_SET;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Test if entry is excluded by its timestamp.
+ */
+static int
+time_excluded(struct archive_match *a, struct archive_entry *entry)
+{
+ struct match_file *f;
+ const void *pathname;
+ time_t sec;
+ long nsec;
+
+ /*
+ * If this file/dir is excluded by a time comparison, skip it.
+ */
+ if (a->newer_ctime_filter) {
+ /* If ctime is not set, use mtime instead. */
+ if (archive_entry_ctime_is_set(entry))
+ sec = archive_entry_ctime(entry);
+ else
+ sec = archive_entry_mtime(entry);
+ if (sec < a->newer_ctime_sec)
+ return (1); /* Too old, skip it. */
+ if (sec == a->newer_ctime_sec) {
+ if (archive_entry_ctime_is_set(entry))
+ nsec = archive_entry_ctime_nsec(entry);
+ else
+ nsec = archive_entry_mtime_nsec(entry);
+ if (nsec < a->newer_ctime_nsec)
+ return (1); /* Too old, skip it. */
+ if (nsec == a->newer_ctime_nsec &&
+ (a->newer_ctime_filter & ARCHIVE_MATCH_EQUAL)
+ == 0)
+ return (1); /* Equal, skip it. */
+ }
+ }
+ if (a->older_ctime_filter) {
+ /* If ctime is not set, use mtime instead. */
+ if (archive_entry_ctime_is_set(entry))
+ sec = archive_entry_ctime(entry);
+ else
+ sec = archive_entry_mtime(entry);
+ if (sec > a->older_ctime_sec)
+ return (1); /* Too new, skip it. */
+ if (sec == a->older_ctime_sec) {
+ if (archive_entry_ctime_is_set(entry))
+ nsec = archive_entry_ctime_nsec(entry);
+ else
+ nsec = archive_entry_mtime_nsec(entry);
+ if (nsec > a->older_ctime_nsec)
+ return (1); /* Too new, skip it. */
+ if (nsec == a->older_ctime_nsec &&
+ (a->older_ctime_filter & ARCHIVE_MATCH_EQUAL)
+ == 0)
+ return (1); /* Eeual, skip it. */
+ }
+ }
+ if (a->newer_mtime_filter) {
+ sec = archive_entry_mtime(entry);
+ if (sec < a->newer_mtime_sec)
+ return (1); /* Too old, skip it. */
+ if (sec == a->newer_mtime_sec) {
+ nsec = archive_entry_mtime_nsec(entry);
+ if (nsec < a->newer_mtime_nsec)
+ return (1); /* Too old, skip it. */
+ if (nsec == a->newer_mtime_nsec &&
+ (a->newer_mtime_filter & ARCHIVE_MATCH_EQUAL)
+ == 0)
+ return (1); /* Equal, skip it. */
+ }
+ }
+ if (a->older_mtime_filter) {
+ sec = archive_entry_mtime(entry);
+ if (sec > a->older_mtime_sec)
+ return (1); /* Too new, skip it. */
+ nsec = archive_entry_mtime_nsec(entry);
+ if (sec == a->older_mtime_sec) {
+ if (nsec > a->older_mtime_nsec)
+ return (1); /* Too new, skip it. */
+ if (nsec == a->older_mtime_nsec &&
+ (a->older_mtime_filter & ARCHIVE_MATCH_EQUAL)
+ == 0)
+ return (1); /* Equal, skip it. */
+ }
+ }
+
+ /* If there is no excluson list, include the file. */
+ if (a->exclusion_entry_list.count == 0)
+ return (0);
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ pathname = archive_entry_pathname_w(entry);
+ a->exclusion_tree.rbt_ops = &rb_ops_wcs;
+#else
+ (void)rb_ops_wcs;
+ pathname = archive_entry_pathname(entry);
+ a->exclusion_tree.rbt_ops = &rb_ops_mbs;
+#endif
+ if (pathname == NULL)
+ return (0);
+
+ f = (struct match_file *)__archive_rb_tree_find_node(
+ &(a->exclusion_tree), pathname);
+ /* If the file wasn't rejected, include it. */
+ if (f == NULL)
+ return (0);
+
+ if (f->flag & ARCHIVE_MATCH_CTIME) {
+ sec = archive_entry_ctime(entry);
+ if (f->ctime_sec > sec) {
+ if (f->flag & ARCHIVE_MATCH_OLDER)
+ return (1);
+ } else if (f->ctime_sec < sec) {
+ if (f->flag & ARCHIVE_MATCH_NEWER)
+ return (1);
+ } else {
+ nsec = archive_entry_ctime_nsec(entry);
+ if (f->ctime_nsec > nsec) {
+ if (f->flag & ARCHIVE_MATCH_OLDER)
+ return (1);
+ } else if (f->ctime_nsec < nsec) {
+ if (f->flag & ARCHIVE_MATCH_NEWER)
+ return (1);
+ } else if (f->flag & ARCHIVE_MATCH_EQUAL)
+ return (1);
+ }
+ }
+ if (f->flag & ARCHIVE_MATCH_MTIME) {
+ sec = archive_entry_mtime(entry);
+ if (f->mtime_sec > sec) {
+ if (f->flag & ARCHIVE_MATCH_OLDER)
+ return (1);
+ } else if (f->mtime_sec < sec) {
+ if (f->flag & ARCHIVE_MATCH_NEWER)
+ return (1);
+ } else {
+ nsec = archive_entry_mtime_nsec(entry);
+ if (f->mtime_nsec > nsec) {
+ if (f->flag & ARCHIVE_MATCH_OLDER)
+ return (1);
+ } else if (f->mtime_nsec < nsec) {
+ if (f->flag & ARCHIVE_MATCH_NEWER)
+ return (1);
+ } else if (f->flag & ARCHIVE_MATCH_EQUAL)
+ return (1);
+ }
+ }
+ return (0);
+}
+
+/*
+ * Utility functions to manage inclusion owners
+ */
+
+int
+archive_match_include_uid(struct archive *_a, int64_t uid)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_uid");
+ a = (struct archive_match *)_a;
+ return (add_owner_id(a, &(a->inclusion_uids), uid));
+}
+
+int
+archive_match_include_gid(struct archive *_a, int64_t gid)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_gid");
+ a = (struct archive_match *)_a;
+ return (add_owner_id(a, &(a->inclusion_gids), gid));
+}
+
+int
+archive_match_include_uname(struct archive *_a, const char *uname)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_uname");
+ a = (struct archive_match *)_a;
+ return (add_owner_name(a, &(a->inclusion_unames), 1, uname));
+}
+
+int
+archive_match_include_uname_w(struct archive *_a, const wchar_t *uname)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_uname_w");
+ a = (struct archive_match *)_a;
+ return (add_owner_name(a, &(a->inclusion_unames), 0, uname));
+}
+
+int
+archive_match_include_gname(struct archive *_a, const char *gname)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_gname");
+ a = (struct archive_match *)_a;
+ return (add_owner_name(a, &(a->inclusion_gnames), 1, gname));
+}
+
+int
+archive_match_include_gname_w(struct archive *_a, const wchar_t *gname)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_gname_w");
+ a = (struct archive_match *)_a;
+ return (add_owner_name(a, &(a->inclusion_gnames), 0, gname));
+}
+
+/*
+ * Test function for owner(uid, gid, uname, gname).
+ *
+ * Returns 1 if archive entry is excluded.
+ * Returns 0 if archive entry is not excluded.
+ * Returns <0 if something error happened.
+ */
+int
+archive_match_owner_excluded(struct archive *_a,
+ struct archive_entry *entry)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_id_excluded_ae");
+
+ a = (struct archive_match *)_a;
+ if (entry == NULL) {
+ archive_set_error(&(a->archive), EINVAL, "entry is NULL");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* If we don't have inclusion id set at all, the entry is always
+ * not excluded. */
+ if ((a->setflag & ID_IS_SET) == 0)
+ return (0);
+ return (owner_excluded(a, entry));
+}
+
+static int
+add_owner_id(struct archive_match *a, struct id_array *ids, int64_t id)
+{
+ unsigned i;
+
+ if (ids->count + 1 >= ids->size) {
+ void *p;
+
+ if (ids->size == 0)
+ ids->size = 8;
+ else
+ ids->size *= 2;
+ p = realloc(ids->ids, sizeof(*ids->ids) * ids->size);
+ if (p == NULL)
+ return (error_nomem(a));
+ ids->ids = (int64_t *)p;
+ }
+
+ /* Find an insert point. */
+ for (i = 0; i < ids->count; i++) {
+ if (ids->ids[i] >= id)
+ break;
+ }
+
+ /* Add oowner id. */
+ if (i == ids->count)
+ ids->ids[ids->count++] = id;
+ else if (ids->ids[i] != id) {
+ memmove(&(ids->ids[i+1]), &(ids->ids[i]),
+ (ids->count - i) * sizeof(ids->ids[0]));
+ ids->ids[i] = id;
+ ids->count++;
+ }
+ a->setflag |= ID_IS_SET;
+ return (ARCHIVE_OK);
+}
+
+static int
+match_owner_id(struct id_array *ids, int64_t id)
+{
+ unsigned b, m, t;
+
+ t = 0;
+ b = (unsigned)ids->count;
+ while (t < b) {
+ m = (t + b)>>1;
+ if (ids->ids[m] == id)
+ return (1);
+ if (ids->ids[m] < id)
+ t = m + 1;
+ else
+ b = m;
+ }
+ return (0);
+}
+
+static int
+add_owner_name(struct archive_match *a, struct match_list *list,
+ int mbs, const void *name)
+{
+ struct match *match;
+
+ match = calloc(1, sizeof(*match));
+ if (match == NULL)
+ return (error_nomem(a));
+ if (mbs)
+ archive_mstring_copy_mbs(&(match->pattern), name);
+ else
+ archive_mstring_copy_wcs(&(match->pattern), name);
+ match_list_add(list, match);
+ a->setflag |= ID_IS_SET;
+ return (ARCHIVE_OK);
+}
+
+#if !defined(_WIN32) || defined(__CYGWIN__)
+static int
+match_owner_name_mbs(struct archive_match *a, struct match_list *list,
+ const char *name)
+{
+ struct match *m;
+ const char *p;
+
+ if (name == NULL || *name == '\0')
+ return (0);
+ for (m = list->first; m; m = m->next) {
+ if (archive_mstring_get_mbs(&(a->archive), &(m->pattern), &p)
+ < 0 && errno == ENOMEM)
+ return (error_nomem(a));
+ if (p != NULL && strcmp(p, name) == 0) {
+ m->matches++;
+ return (1);
+ }
+ }
+ return (0);
+}
+#else
+static int
+match_owner_name_wcs(struct archive_match *a, struct match_list *list,
+ const wchar_t *name)
+{
+ struct match *m;
+ const wchar_t *p;
+
+ if (name == NULL || *name == L'\0')
+ return (0);
+ for (m = list->first; m; m = m->next) {
+ if (archive_mstring_get_wcs(&(a->archive), &(m->pattern), &p)
+ < 0 && errno == ENOMEM)
+ return (error_nomem(a));
+ if (p != NULL && wcscmp(p, name) == 0) {
+ m->matches++;
+ return (1);
+ }
+ }
+ return (0);
+}
+#endif
+
+/*
+ * Test if entry is excluded by uid, gid, uname or gname.
+ */
+static int
+owner_excluded(struct archive_match *a, struct archive_entry *entry)
+{
+ int r;
+
+ if (a->inclusion_uids.count) {
+ if (!match_owner_id(&(a->inclusion_uids),
+ archive_entry_uid(entry)))
+ return (1);
+ }
+
+ if (a->inclusion_gids.count) {
+ if (!match_owner_id(&(a->inclusion_gids),
+ archive_entry_gid(entry)))
+ return (1);
+ }
+
+ if (a->inclusion_unames.count) {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ r = match_owner_name_wcs(a, &(a->inclusion_unames),
+ archive_entry_uname_w(entry));
+#else
+ r = match_owner_name_mbs(a, &(a->inclusion_unames),
+ archive_entry_uname(entry));
+#endif
+ if (!r)
+ return (1);
+ else if (r < 0)
+ return (r);
+ }
+
+ if (a->inclusion_gnames.count) {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ r = match_owner_name_wcs(a, &(a->inclusion_gnames),
+ archive_entry_gname_w(entry));
+#else
+ r = match_owner_name_mbs(a, &(a->inclusion_gnames),
+ archive_entry_gname(entry));
+#endif
+ if (!r)
+ return (1);
+ else if (r < 0)
+ return (r);
+ }
+ return (0);
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_options.c b/Utilities/cmlibarchive/libarchive/archive_options.c
new file mode 100644
index 0000000000..220ebd4173
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_options.c
@@ -0,0 +1,211 @@
+/*-
+ * Copyright (c) 2011 Tim Kientzle
+ * 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$");
+
+#include "archive_options_private.h"
+
+static const char *
+parse_option(const char **str,
+ const char **mod, const char **opt, const char **val);
+
+int
+_archive_set_option(struct archive *a,
+ const char *m, const char *o, const char *v,
+ int magic, const char *fn, option_handler use_option)
+{
+ const char *mp, *op, *vp;
+ int r;
+
+ archive_check_magic(a, magic, ARCHIVE_STATE_NEW, fn);
+
+ mp = m != NULL && m[0] != '\0' ? m : NULL;
+ op = o != NULL && o[0] != '\0' ? o : NULL;
+ vp = v != NULL && v[0] != '\0' ? v : NULL;
+
+ if (op == NULL && vp == NULL)
+ return (ARCHIVE_OK);
+ if (op == NULL) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC, "Empty option");
+ return (ARCHIVE_FAILED);
+ }
+
+ r = use_option(a, mp, op, vp);
+ if (r == ARCHIVE_WARN - 1) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Unknown module name: `%s'", mp);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_WARN) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Undefined option: `%s%s%s%s%s%s'",
+ vp?"":"!", mp?mp:"", mp?":":"", op, vp?"=":"", vp?vp:"");
+ return (ARCHIVE_FAILED);
+ }
+ return (r);
+}
+
+int
+_archive_set_either_option(struct archive *a, const char *m, const char *o, const char *v,
+ option_handler use_format_option, option_handler use_filter_option)
+{
+ int r1, r2;
+
+ if (o == NULL && v == NULL)
+ return (ARCHIVE_OK);
+ if (o == NULL)
+ return (ARCHIVE_FAILED);
+
+ r1 = use_format_option(a, m, o, v);
+ if (r1 == ARCHIVE_FATAL)
+ return (ARCHIVE_FATAL);
+
+ r2 = use_filter_option(a, m, o, v);
+ if (r2 == ARCHIVE_FATAL)
+ return (ARCHIVE_FATAL);
+
+ if (r2 == ARCHIVE_WARN - 1)
+ return r1;
+ return r1 > r2 ? r1 : r2;
+}
+
+int
+_archive_set_options(struct archive *a, const char *options,
+ int magic, const char *fn, option_handler use_option)
+{
+ int allok = 1, anyok = 0, ignore_mod_err = 0, r;
+ char *data;
+ const char *s, *mod, *opt, *val;
+
+ archive_check_magic(a, magic, ARCHIVE_STATE_NEW, fn);
+
+ if (options == NULL || options[0] == '\0')
+ return ARCHIVE_OK;
+
+ data = (char *)malloc(strlen(options) + 1);
+ strcpy(data, options);
+ s = (const char *)data;
+
+ do {
+ mod = opt = val = NULL;
+
+ parse_option(&s, &mod, &opt, &val);
+ if (mod == NULL && opt != NULL &&
+ strcmp("__ignore_wrong_module_name__", opt) == 0) {
+ /* Ignore module name error */
+ if (val != NULL) {
+ ignore_mod_err = 1;
+ anyok = 1;
+ }
+ continue;
+ }
+
+ r = use_option(a, mod, opt, val);
+ if (r == ARCHIVE_FATAL) {
+ free(data);
+ return (ARCHIVE_FATAL);
+ }
+ if (r == ARCHIVE_FAILED && mod != NULL) {
+ free(data);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_WARN - 1) {
+ if (ignore_mod_err)
+ continue;
+ /* The module name is wrong. */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Unknown module name: `%s'", mod);
+ free(data);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_WARN) {
+ /* The option name is wrong. No-one used this. */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Undefined option: `%s%s%s'",
+ mod?mod:"", mod?":":"", opt);
+ free(data);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_OK)
+ anyok = 1;
+ else
+ allok = 0;
+ } while (s != NULL);
+
+ free(data);
+ return allok ? ARCHIVE_OK : anyok ? ARCHIVE_WARN : ARCHIVE_FAILED;
+}
+
+static const char *
+parse_option(const char **s, const char **m, const char **o, const char **v)
+{
+ const char *end, *mod, *opt, *val;
+ char *p;
+
+ end = NULL;
+ mod = NULL;
+ opt = *s;
+ val = "1";
+
+ p = strchr(opt, ',');
+
+ if (p != NULL) {
+ *p = '\0';
+ end = ((const char *)p) + 1;
+ }
+
+ if (0 == strlen(opt)) {
+ *s = end;
+ *m = NULL;
+ *o = NULL;
+ *v = NULL;
+ return end;
+ }
+
+ p = strchr(opt, ':');
+ if (p != NULL) {
+ *p = '\0';
+ mod = opt;
+ opt = ++p;
+ }
+
+ p = strchr(opt, '=');
+ if (p != NULL) {
+ *p = '\0';
+ val = ++p;
+ } else if (opt[0] == '!') {
+ ++opt;
+ val = NULL;
+ }
+
+ *s = end;
+ *m = mod;
+ *o = opt;
+ *v = val;
+
+ return end;
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_options_private.h b/Utilities/cmlibarchive/libarchive/archive_options_private.h
new file mode 100644
index 0000000000..6ef0165aff
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_options_private.h
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2011 Tim Kientzle
+ * 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$");
+
+#include "archive_private.h"
+
+typedef int (*option_handler)(struct archive *a,
+ const char *mod, const char *opt, const char *val);
+
+int
+_archive_set_option(struct archive *a,
+ const char *mod, const char *opt, const char *val,
+ int magic, const char *fn, option_handler use_option);
+
+int
+_archive_set_options(struct archive *a, const char *options,
+ int magic, const char *fn, option_handler use_option);
+
+int
+_archive_set_either_option(struct archive *a,
+ const char *m, const char *o, const char *v,
+ option_handler use_format_option, option_handler use_filter_option);
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_pack_dev.c b/Utilities/cmlibarchive/libarchive/archive_pack_dev.c
new file mode 100644
index 0000000000..6b7b4726d6
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_pack_dev.c
@@ -0,0 +1,329 @@
+/* $NetBSD: pack_dev.c,v 1.12 2013/06/14 16:28:20 tsutsui Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/* Originally from NetBSD's mknod(8) source. */
+
+#include "archive_platform.h"
+
+#if HAVE_SYS_CDEFS_H
+#include <sys/cdefs.h>
+#endif
+#if !defined(lint)
+__RCSID("$NetBSD$");
+#endif /* not lint */
+
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive_pack_dev.h"
+
+static pack_t pack_netbsd;
+static pack_t pack_freebsd;
+static pack_t pack_8_8;
+static pack_t pack_12_20;
+static pack_t pack_14_18;
+static pack_t pack_8_24;
+static pack_t pack_bsdos;
+static int compare_format(const void *, const void *);
+
+static const char iMajorError[] = "invalid major number";
+static const char iMinorError[] = "invalid minor number";
+static const char tooManyFields[] = "too many fields for format";
+
+/* This is blatantly stolen from libarchive/archive_entry.c,
+ * in an attempt to get this to play nice on MinGW... */
+#if !defined(HAVE_MAJOR) && !defined(major)
+/* Replacement for major/minor/makedev. */
+#define major(x) ((int)(0x00ff & ((x) >> 8)))
+#define minor(x) ((int)(0xffff00ff & (x)))
+#define makedev(maj,min) ((0xff00 & ((maj)<<8)) | (0xffff00ff & (min)))
+#endif
+
+/* Play games to come up with a suitable makedev() definition. */
+#ifdef __QNXNTO__
+/* QNX. <sigh> */
+#include <sys/netmgr.h>
+#define apd_makedev(maj, min) makedev(ND_LOCAL_NODE, (maj), (min))
+#elif defined makedev
+/* There's a "makedev" macro. */
+#define apd_makedev(maj, min) makedev((maj), (min))
+#elif defined mkdev || ((defined _WIN32 || defined __WIN32__) && !defined(__CYGWIN__))
+/* Windows. <sigh> */
+#define apd_makedev(maj, min) mkdev((maj), (min))
+#else
+/* There's a "makedev" function. */
+#define apd_makedev(maj, min) makedev((maj), (min))
+#endif
+
+/* exported */
+dev_t
+pack_native(int n, unsigned long numbers[], const char **error)
+{
+ dev_t dev = 0;
+
+ if (n == 2) {
+ dev = apd_makedev(numbers[0], numbers[1]);
+ if ((unsigned long)major(dev) != numbers[0])
+ *error = iMajorError;
+ else if ((unsigned long)minor(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+static dev_t
+pack_netbsd(int n, unsigned long numbers[], const char **error)
+{
+ dev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_netbsd(numbers[0], numbers[1]);
+ if ((unsigned long)major_netbsd(dev) != numbers[0])
+ *error = iMajorError;
+ else if ((unsigned long)minor_netbsd(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_freebsd(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
+#define minor_freebsd(x) ((int32_t)(((x) & 0xffff00ff) >> 0))
+#define makedev_freebsd(x,y) ((dev_t)((((x) << 8) & 0x0000ff00) | \
+ (((y) << 0) & 0xffff00ff)))
+
+static dev_t
+pack_freebsd(int n, unsigned long numbers[], const char **error)
+{
+ dev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_freebsd(numbers[0], numbers[1]);
+ if ((unsigned long)major_freebsd(dev) != numbers[0])
+ *error = iMajorError;
+ if ((unsigned long)minor_freebsd(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_8_8(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
+#define minor_8_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
+#define makedev_8_8(x,y) ((dev_t)((((x) << 8) & 0x0000ff00) | \
+ (((y) << 0) & 0x000000ff)))
+
+static dev_t
+pack_8_8(int n, unsigned long numbers[], const char **error)
+{
+ dev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_8_8(numbers[0], numbers[1]);
+ if ((unsigned long)major_8_8(dev) != numbers[0])
+ *error = iMajorError;
+ if ((unsigned long)minor_8_8(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_12_20(x) ((int32_t)(((x) & 0xfff00000) >> 20))
+#define minor_12_20(x) ((int32_t)(((x) & 0x000fffff) >> 0))
+#define makedev_12_20(x,y) ((dev_t)((((x) << 20) & 0xfff00000) | \
+ (((y) << 0) & 0x000fffff)))
+
+static dev_t
+pack_12_20(int n, unsigned long numbers[], const char **error)
+{
+ dev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_12_20(numbers[0], numbers[1]);
+ if ((unsigned long)major_12_20(dev) != numbers[0])
+ *error = iMajorError;
+ if ((unsigned long)minor_12_20(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_14_18(x) ((int32_t)(((x) & 0xfffc0000) >> 18))
+#define minor_14_18(x) ((int32_t)(((x) & 0x0003ffff) >> 0))
+#define makedev_14_18(x,y) ((dev_t)((((x) << 18) & 0xfffc0000) | \
+ (((y) << 0) & 0x0003ffff)))
+
+static dev_t
+pack_14_18(int n, unsigned long numbers[], const char **error)
+{
+ dev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_14_18(numbers[0], numbers[1]);
+ if ((unsigned long)major_14_18(dev) != numbers[0])
+ *error = iMajorError;
+ if ((unsigned long)minor_14_18(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_8_24(x) ((int32_t)(((x) & 0xff000000) >> 24))
+#define minor_8_24(x) ((int32_t)(((x) & 0x00ffffff) >> 0))
+#define makedev_8_24(x,y) ((dev_t)((((x) << 24) & 0xff000000) | \
+ (((y) << 0) & 0x00ffffff)))
+
+static dev_t
+pack_8_24(int n, unsigned long numbers[], const char **error)
+{
+ dev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_8_24(numbers[0], numbers[1]);
+ if ((unsigned long)major_8_24(dev) != numbers[0])
+ *error = iMajorError;
+ if ((unsigned long)minor_8_24(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_12_12_8(x) ((int32_t)(((x) & 0xfff00000) >> 20))
+#define unit_12_12_8(x) ((int32_t)(((x) & 0x000fff00) >> 8))
+#define subunit_12_12_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
+#define makedev_12_12_8(x,y,z) ((dev_t)((((x) << 20) & 0xfff00000) | \
+ (((y) << 8) & 0x000fff00) | \
+ (((z) << 0) & 0x000000ff)))
+
+static dev_t
+pack_bsdos(int n, unsigned long numbers[], const char **error)
+{
+ dev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_12_20(numbers[0], numbers[1]);
+ if ((unsigned long)major_12_20(dev) != numbers[0])
+ *error = iMajorError;
+ if ((unsigned long)minor_12_20(dev) != numbers[1])
+ *error = iMinorError;
+ } else if (n == 3) {
+ dev = makedev_12_12_8(numbers[0], numbers[1], numbers[2]);
+ if ((unsigned long)major_12_12_8(dev) != numbers[0])
+ *error = iMajorError;
+ if ((unsigned long)unit_12_12_8(dev) != numbers[1])
+ *error = "invalid unit number";
+ if ((unsigned long)subunit_12_12_8(dev) != numbers[2])
+ *error = "invalid subunit number";
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+ /* list of formats and pack functions */
+ /* this list must be sorted lexically */
+static struct format {
+ const char *name;
+ pack_t *pack;
+} formats[] = {
+ {"386bsd", pack_8_8},
+ {"4bsd", pack_8_8},
+ {"bsdos", pack_bsdos},
+ {"freebsd", pack_freebsd},
+ {"hpux", pack_8_24},
+ {"isc", pack_8_8},
+ {"linux", pack_8_8},
+ {"native", pack_native},
+ {"netbsd", pack_netbsd},
+ {"osf1", pack_12_20},
+ {"sco", pack_8_8},
+ {"solaris", pack_14_18},
+ {"sunos", pack_8_8},
+ {"svr3", pack_8_8},
+ {"svr4", pack_14_18},
+ {"ultrix", pack_8_8},
+};
+
+static int
+compare_format(const void *key, const void *element)
+{
+ const char *name;
+ const struct format *format;
+
+ name = key;
+ format = element;
+
+ return (strcmp(name, format->name));
+}
+
+
+pack_t *
+pack_find(const char *name)
+{
+ struct format *format;
+
+ format = bsearch(name, formats,
+ sizeof(formats)/sizeof(formats[0]),
+ sizeof(formats[0]), compare_format);
+ if (format == 0)
+ return (NULL);
+ return (format->pack);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_pack_dev.h b/Utilities/cmlibarchive/libarchive/archive_pack_dev.h
new file mode 100644
index 0000000000..749fd3d2cb
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_pack_dev.h
@@ -0,0 +1,49 @@
+/* $NetBSD: pack_dev.h,v 1.8 2013/06/14 16:28:20 tsutsui Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/* Originally from NetBSD's mknod(8) source. */
+
+#ifndef _PACK_DEV_H
+#define _PACK_DEV_H
+
+typedef dev_t pack_t(int, unsigned long [], const char **);
+
+pack_t *pack_find(const char *);
+pack_t pack_native;
+
+#define major_netbsd(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
+#define minor_netbsd(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
+ (((x) & 0x000000ff) >> 0)))
+#define makedev_netbsd(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
+ (((y) << 12) & 0xfff00000) | \
+ (((y) << 0) & 0x000000ff)))
+
+#endif /* _PACK_DEV_H */
diff --git a/Utilities/cmlibarchive/libarchive/archive_pathmatch.c b/Utilities/cmlibarchive/libarchive/archive_pathmatch.c
new file mode 100644
index 0000000000..505252a18f
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_pathmatch.c
@@ -0,0 +1,459 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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
+ * in this position and unchanged.
+ * 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_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+
+#include "archive_pathmatch.h"
+
+/*
+ * Check whether a character 'c' is matched by a list specification [...]:
+ * * Leading '!' or '^' negates the class.
+ * * <char>-<char> is a range of characters
+ * * \<char> removes any special meaning for <char>
+ *
+ * Some interesting boundary cases:
+ * a-d-e is one range (a-d) followed by two single characters - and e.
+ * \a-\d is same as a-d
+ * a\-d is three single characters: a, d, -
+ * Trailing - is not special (so [a-] is two characters a and -).
+ * Initial - is not special ([a-] is same as [-a] is same as [\\-a])
+ * This function never sees a trailing \.
+ * [] always fails
+ * [!] always succeeds
+ */
+static int
+pm_list(const char *start, const char *end, const char c, int flags)
+{
+ const char *p = start;
+ char rangeStart = '\0', nextRangeStart;
+ int match = 1, nomatch = 0;
+
+ /* This will be used soon... */
+ (void)flags; /* UNUSED */
+
+ /* If this is a negated class, return success for nomatch. */
+ if ((*p == '!' || *p == '^') && p < end) {
+ match = 0;
+ nomatch = 1;
+ ++p;
+ }
+
+ while (p < end) {
+ nextRangeStart = '\0';
+ switch (*p) {
+ case '-':
+ /* Trailing or initial '-' is not special. */
+ if ((rangeStart == '\0') || (p == end - 1)) {
+ if (*p == c)
+ return (match);
+ } else {
+ char rangeEnd = *++p;
+ if (rangeEnd == '\\')
+ rangeEnd = *++p;
+ if ((rangeStart <= c) && (c <= rangeEnd))
+ return (match);
+ }
+ break;
+ case '\\':
+ ++p;
+ /* Fall through */
+ default:
+ if (*p == c)
+ return (match);
+ nextRangeStart = *p; /* Possible start of range. */
+ }
+ rangeStart = nextRangeStart;
+ ++p;
+ }
+ return (nomatch);
+}
+
+static int
+pm_list_w(const wchar_t *start, const wchar_t *end, const wchar_t c, int flags)
+{
+ const wchar_t *p = start;
+ wchar_t rangeStart = L'\0', nextRangeStart;
+ int match = 1, nomatch = 0;
+
+ /* This will be used soon... */
+ (void)flags; /* UNUSED */
+
+ /* If this is a negated class, return success for nomatch. */
+ if ((*p == L'!' || *p == L'^') && p < end) {
+ match = 0;
+ nomatch = 1;
+ ++p;
+ }
+
+ while (p < end) {
+ nextRangeStart = L'\0';
+ switch (*p) {
+ case L'-':
+ /* Trailing or initial '-' is not special. */
+ if ((rangeStart == L'\0') || (p == end - 1)) {
+ if (*p == c)
+ return (match);
+ } else {
+ wchar_t rangeEnd = *++p;
+ if (rangeEnd == L'\\')
+ rangeEnd = *++p;
+ if ((rangeStart <= c) && (c <= rangeEnd))
+ return (match);
+ }
+ break;
+ case L'\\':
+ ++p;
+ /* Fall through */
+ default:
+ if (*p == c)
+ return (match);
+ nextRangeStart = *p; /* Possible start of range. */
+ }
+ rangeStart = nextRangeStart;
+ ++p;
+ }
+ return (nomatch);
+}
+
+/*
+ * If s is pointing to "./", ".//", "./././" or the like, skip it.
+ */
+static const char *
+pm_slashskip(const char *s) {
+ while ((*s == '/')
+ || (s[0] == '.' && s[1] == '/')
+ || (s[0] == '.' && s[1] == '\0'))
+ ++s;
+ return (s);
+}
+
+static const wchar_t *
+pm_slashskip_w(const wchar_t *s) {
+ while ((*s == L'/')
+ || (s[0] == L'.' && s[1] == L'/')
+ || (s[0] == L'.' && s[1] == L'\0'))
+ ++s;
+ return (s);
+}
+
+static int
+pm(const char *p, const char *s, int flags)
+{
+ const char *end;
+
+ /*
+ * Ignore leading './', './/', '././', etc.
+ */
+ if (s[0] == '.' && s[1] == '/')
+ s = pm_slashskip(s + 1);
+ if (p[0] == '.' && p[1] == '/')
+ p = pm_slashskip(p + 1);
+
+ for (;;) {
+ switch (*p) {
+ case '\0':
+ if (s[0] == '/') {
+ if (flags & PATHMATCH_NO_ANCHOR_END)
+ return (1);
+ /* "dir" == "dir/" == "dir/." */
+ s = pm_slashskip(s);
+ }
+ return (*s == '\0');
+ case '?':
+ /* ? always succeeds, unless we hit end of 's' */
+ if (*s == '\0')
+ return (0);
+ break;
+ case '*':
+ /* "*" == "**" == "***" ... */
+ while (*p == '*')
+ ++p;
+ /* Trailing '*' always succeeds. */
+ if (*p == '\0')
+ return (1);
+ while (*s) {
+ if (archive_pathmatch(p, s, flags))
+ return (1);
+ ++s;
+ }
+ return (0);
+ case '[':
+ /*
+ * Find the end of the [...] character class,
+ * ignoring \] that might occur within the class.
+ */
+ end = p + 1;
+ while (*end != '\0' && *end != ']') {
+ if (*end == '\\' && end[1] != '\0')
+ ++end;
+ ++end;
+ }
+ if (*end == ']') {
+ /* We found [...], try to match it. */
+ if (!pm_list(p + 1, end, *s, flags))
+ return (0);
+ p = end; /* Jump to trailing ']' char. */
+ break;
+ } else
+ /* No final ']', so just match '['. */
+ if (*p != *s)
+ return (0);
+ break;
+ case '\\':
+ /* Trailing '\\' matches itself. */
+ if (p[1] == '\0') {
+ if (*s != '\\')
+ return (0);
+ } else {
+ ++p;
+ if (*p != *s)
+ return (0);
+ }
+ break;
+ case '/':
+ if (*s != '/' && *s != '\0')
+ return (0);
+ /* Note: pattern "/\./" won't match "/";
+ * pm_slashskip() correctly stops at backslash. */
+ p = pm_slashskip(p);
+ s = pm_slashskip(s);
+ if (*p == '\0' && (flags & PATHMATCH_NO_ANCHOR_END))
+ return (1);
+ --p; /* Counteract the increment below. */
+ --s;
+ break;
+ case '$':
+ /* '$' is special only at end of pattern and only
+ * if PATHMATCH_NO_ANCHOR_END is specified. */
+ if (p[1] == '\0' && (flags & PATHMATCH_NO_ANCHOR_END)){
+ /* "dir" == "dir/" == "dir/." */
+ return (*pm_slashskip(s) == '\0');
+ }
+ /* Otherwise, '$' is not special. */
+ /* FALL THROUGH */
+ default:
+ if (*p != *s)
+ return (0);
+ break;
+ }
+ ++p;
+ ++s;
+ }
+}
+
+static int
+pm_w(const wchar_t *p, const wchar_t *s, int flags)
+{
+ const wchar_t *end;
+
+ /*
+ * Ignore leading './', './/', '././', etc.
+ */
+ if (s[0] == L'.' && s[1] == L'/')
+ s = pm_slashskip_w(s + 1);
+ if (p[0] == L'.' && p[1] == L'/')
+ p = pm_slashskip_w(p + 1);
+
+ for (;;) {
+ switch (*p) {
+ case L'\0':
+ if (s[0] == L'/') {
+ if (flags & PATHMATCH_NO_ANCHOR_END)
+ return (1);
+ /* "dir" == "dir/" == "dir/." */
+ s = pm_slashskip_w(s);
+ }
+ return (*s == L'\0');
+ case L'?':
+ /* ? always succeeds, unless we hit end of 's' */
+ if (*s == L'\0')
+ return (0);
+ break;
+ case L'*':
+ /* "*" == "**" == "***" ... */
+ while (*p == L'*')
+ ++p;
+ /* Trailing '*' always succeeds. */
+ if (*p == L'\0')
+ return (1);
+ while (*s) {
+ if (archive_pathmatch_w(p, s, flags))
+ return (1);
+ ++s;
+ }
+ return (0);
+ case L'[':
+ /*
+ * Find the end of the [...] character class,
+ * ignoring \] that might occur within the class.
+ */
+ end = p + 1;
+ while (*end != L'\0' && *end != L']') {
+ if (*end == L'\\' && end[1] != L'\0')
+ ++end;
+ ++end;
+ }
+ if (*end == L']') {
+ /* We found [...], try to match it. */
+ if (!pm_list_w(p + 1, end, *s, flags))
+ return (0);
+ p = end; /* Jump to trailing ']' char. */
+ break;
+ } else
+ /* No final ']', so just match '['. */
+ if (*p != *s)
+ return (0);
+ break;
+ case L'\\':
+ /* Trailing '\\' matches itself. */
+ if (p[1] == L'\0') {
+ if (*s != L'\\')
+ return (0);
+ } else {
+ ++p;
+ if (*p != *s)
+ return (0);
+ }
+ break;
+ case L'/':
+ if (*s != L'/' && *s != L'\0')
+ return (0);
+ /* Note: pattern "/\./" won't match "/";
+ * pm_slashskip() correctly stops at backslash. */
+ p = pm_slashskip_w(p);
+ s = pm_slashskip_w(s);
+ if (*p == L'\0' && (flags & PATHMATCH_NO_ANCHOR_END))
+ return (1);
+ --p; /* Counteract the increment below. */
+ --s;
+ break;
+ case L'$':
+ /* '$' is special only at end of pattern and only
+ * if PATHMATCH_NO_ANCHOR_END is specified. */
+ if (p[1] == L'\0' && (flags & PATHMATCH_NO_ANCHOR_END)){
+ /* "dir" == "dir/" == "dir/." */
+ return (*pm_slashskip_w(s) == L'\0');
+ }
+ /* Otherwise, '$' is not special. */
+ /* FALL THROUGH */
+ default:
+ if (*p != *s)
+ return (0);
+ break;
+ }
+ ++p;
+ ++s;
+ }
+}
+
+/* Main entry point. */
+int
+__archive_pathmatch(const char *p, const char *s, int flags)
+{
+ /* Empty pattern only matches the empty string. */
+ if (p == NULL || *p == '\0')
+ return (s == NULL || *s == '\0');
+
+ /* Leading '^' anchors the start of the pattern. */
+ if (*p == '^') {
+ ++p;
+ flags &= ~PATHMATCH_NO_ANCHOR_START;
+ }
+
+ if (*p == '/' && *s != '/')
+ return (0);
+
+ /* Certain patterns and file names anchor implicitly. */
+ if (*p == '*' || *p == '/' || *p == '/') {
+ while (*p == '/')
+ ++p;
+ while (*s == '/')
+ ++s;
+ return (pm(p, s, flags));
+ }
+
+ /* If start is unanchored, try to match start of each path element. */
+ if (flags & PATHMATCH_NO_ANCHOR_START) {
+ for ( ; s != NULL; s = strchr(s, '/')) {
+ if (*s == '/')
+ s++;
+ if (pm(p, s, flags))
+ return (1);
+ }
+ return (0);
+ }
+
+ /* Default: Match from beginning. */
+ return (pm(p, s, flags));
+}
+
+int
+__archive_pathmatch_w(const wchar_t *p, const wchar_t *s, int flags)
+{
+ /* Empty pattern only matches the empty string. */
+ if (p == NULL || *p == L'\0')
+ return (s == NULL || *s == L'\0');
+
+ /* Leading '^' anchors the start of the pattern. */
+ if (*p == L'^') {
+ ++p;
+ flags &= ~PATHMATCH_NO_ANCHOR_START;
+ }
+
+ if (*p == L'/' && *s != L'/')
+ return (0);
+
+ /* Certain patterns and file names anchor implicitly. */
+ if (*p == L'*' || *p == L'/' || *p == L'/') {
+ while (*p == L'/')
+ ++p;
+ while (*s == L'/')
+ ++s;
+ return (pm_w(p, s, flags));
+ }
+
+ /* If start is unanchored, try to match start of each path element. */
+ if (flags & PATHMATCH_NO_ANCHOR_START) {
+ for ( ; s != NULL; s = wcschr(s, L'/')) {
+ if (*s == L'/')
+ s++;
+ if (pm_w(p, s, flags))
+ return (1);
+ }
+ return (0);
+ }
+
+ /* Default: Match from beginning. */
+ return (pm_w(p, s, flags));
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_pathmatch.h b/Utilities/cmlibarchive/libarchive/archive_pathmatch.h
new file mode 100644
index 0000000000..e6901774dd
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_pathmatch.h
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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
+ * in this position and unchanged.
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#ifndef __LIBARCHIVE_TEST
+#error This header is only to be used internally to libarchive.
+#endif
+#endif
+
+#ifndef ARCHIVE_PATHMATCH_H
+#define ARCHIVE_PATHMATCH_H
+
+/* Don't anchor at beginning unless the pattern starts with "^" */
+#define PATHMATCH_NO_ANCHOR_START 1
+/* Don't anchor at end unless the pattern ends with "$" */
+#define PATHMATCH_NO_ANCHOR_END 2
+
+/* Note that "^" and "$" are not special unless you set the corresponding
+ * flag above. */
+
+int __archive_pathmatch(const char *p, const char *s, int flags);
+int __archive_pathmatch_w(const wchar_t *p, const wchar_t *s, int flags);
+
+#define archive_pathmatch(p, s, f) __archive_pathmatch(p, s, f)
+#define archive_pathmatch_w(p, s, f) __archive_pathmatch_w(p, s, f)
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_platform.h b/Utilities/cmlibarchive/libarchive/archive_platform.h
new file mode 100644
index 0000000000..cbe08ec9ba
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_platform.h
@@ -0,0 +1,173 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_platform.h 201090 2009-12-28 02:22:04Z kientzle $
+ */
+
+/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */
+
+/*
+ * This header is the first thing included in any of the libarchive
+ * source files. As far as possible, platform-specific issues should
+ * be dealt with here and not within individual source files. I'm
+ * actively trying to minimize #if blocks within the main source,
+ * since they obfuscate the code.
+ */
+
+#ifndef ARCHIVE_PLATFORM_H_INCLUDED
+#define ARCHIVE_PLATFORM_H_INCLUDED
+
+/* archive.h and archive_entry.h require this. */
+#define __LIBARCHIVE_BUILD 1
+
+#if defined(PLATFORM_CONFIG_H)
+/* Use hand-built config.h in environments that need it. */
+#include PLATFORM_CONFIG_H
+#elif defined(HAVE_CONFIG_H)
+/* Most POSIX platforms use the 'configure' script to build config.h */
+#include "config.h"
+#else
+/* Warn if the library hasn't been (automatically or manually) configured. */
+#error Oops: No config.h and no pre-built configuration in archive_platform.h.
+#endif
+
+/* It should be possible to get rid of this by extending the feature-test
+ * macros to cover Windows API functions, probably along with non-trivial
+ * refactoring of code to find structures that sit more cleanly on top of
+ * either Windows or Posix APIs. */
+#if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)
+#include "archive_windows.h"
+#endif
+
+/*
+ * The config files define a lot of feature macros. The following
+ * uses those macros to select/define replacements and include key
+ * headers as required.
+ */
+
+/* Get a real definition for __FBSDID or __RCSID if we can */
+#if HAVE_SYS_CDEFS_H
+#include <sys/cdefs.h>
+#endif
+
+/* If not, define them so as to avoid dangling semicolons. */
+#ifndef __FBSDID
+#define __FBSDID(a) struct _undefined_hack
+#endif
+#ifndef __RCSID
+#define __RCSID(a) struct _undefined_hack
+#endif
+
+/* Old glibc mbsnrtowcs fails assertions in our use case. */
+#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1
+# undef HAVE_MBSNRTOWCS
+#endif
+
+/* Try to get standard C99-style integer type definitions. */
+#if HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+/* Borland warns about its own constants! */
+#if defined(__BORLANDC__)
+# if HAVE_DECL_UINT64_MAX
+# undef UINT64_MAX
+# undef HAVE_DECL_UINT64_MAX
+# endif
+# if HAVE_DECL_UINT64_MIN
+# undef UINT64_MIN
+# undef HAVE_DECL_UINT64_MIN
+# endif
+# if HAVE_DECL_INT64_MAX
+# undef INT64_MAX
+# undef HAVE_DECL_INT64_MAX
+# endif
+# if HAVE_DECL_INT64_MIN
+# undef INT64_MIN
+# undef HAVE_DECL_INT64_MIN
+# endif
+#endif
+
+/* Some platforms lack the standard *_MAX definitions. */
+#if !HAVE_DECL_SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+#if !HAVE_DECL_SSIZE_MAX
+#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1))
+#endif
+#if !HAVE_DECL_UINT32_MAX
+#define UINT32_MAX (~(uint32_t)0)
+#endif
+#if !HAVE_DECL_UINT64_MAX
+#define UINT64_MAX (~(uint64_t)0)
+#endif
+#if !HAVE_DECL_INT64_MAX
+#define INT64_MAX ((int64_t)(UINT64_MAX >> 1))
+#endif
+#if !HAVE_DECL_INT64_MIN
+#define INT64_MIN ((int64_t)(~INT64_MAX))
+#endif
+
+/*
+ * If this platform has <sys/acl.h>, acl_create(), acl_init(),
+ * acl_set_file(), and ACL_USER, we assume it has the rest of the
+ * POSIX.1e draft functions used in archive_read_extract.c.
+ */
+#if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER
+#define HAVE_POSIX_ACL 1
+#endif
+
+/*
+ * If we can't restore metadata using a file descriptor, then
+ * for compatibility's sake, close files before trying to restore metadata.
+ */
+#if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN)
+#define CAN_RESTORE_METADATA_FD
+#endif
+
+/* Set up defaults for internal error codes. */
+#ifndef ARCHIVE_ERRNO_FILE_FORMAT
+#if HAVE_EFTYPE
+#define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE
+#else
+#if HAVE_EILSEQ
+#define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ
+#else
+#define ARCHIVE_ERRNO_FILE_FORMAT EINVAL
+#endif
+#endif
+#endif
+
+#ifndef ARCHIVE_ERRNO_PROGRAMMER
+#define ARCHIVE_ERRNO_PROGRAMMER EINVAL
+#endif
+
+#ifndef ARCHIVE_ERRNO_MISC
+#define ARCHIVE_ERRNO_MISC (-1)
+#endif
+
+#endif /* !ARCHIVE_PLATFORM_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd7.c b/Utilities/cmlibarchive/libarchive/archive_ppmd7.c
new file mode 100644
index 0000000000..fe0b0318cc
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_ppmd7.c
@@ -0,0 +1,1163 @@
+/* Ppmd7.c -- PPMdH codec
+2010-03-12 : Igor Pavlov : Public domain
+This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
+
+#include "archive_platform.h"
+
+#include <memory.h>
+
+#include "archive_ppmd7_private.h"
+
+#ifdef PPMD_32BIT
+ #define Ppmd7_GetPtr(p, ptr) (ptr)
+ #define Ppmd7_GetContext(p, ptr) (ptr)
+ #define Ppmd7_GetStats(p, ctx) ((ctx)->Stats)
+#else
+ #define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs)))
+ #define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs)))
+ #define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats)))
+#endif
+
+#define Ppmd7_GetBinSumm(p) \
+ &p->BinSumm[Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \
+ p->NS2BSIndx[Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \
+ (p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \
+ 2 * p->HB2Flag[Ppmd7Context_OneState(p->MinContext)->Symbol] + \
+ ((p->RunLength >> 26) & 0x20)]
+
+#define kTopValue (1 << 24)
+#define MAX_FREQ 124
+#define UNIT_SIZE 12
+
+#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE)
+#define U2I(nu) (p->Units2Indx[(nu) - 1])
+#define I2U(indx) (p->Indx2Units[indx])
+
+#ifdef PPMD_32BIT
+ #define REF(ptr) (ptr)
+#else
+ #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base))
+#endif
+
+#define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr))
+
+#define CTX(ref) ((CPpmd7_Context *)Ppmd7_GetContext(p, ref))
+#define STATS(ctx) Ppmd7_GetStats(p, ctx)
+#define ONE_STATE(ctx) Ppmd7Context_OneState(ctx)
+#define SUFFIX(ctx) CTX((ctx)->Suffix)
+
+static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};
+static const Byte PPMD7_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
+
+typedef CPpmd7_Context * CTX_PTR;
+
+struct CPpmd7_Node_;
+
+typedef
+ #ifdef PPMD_32BIT
+ struct CPpmd7_Node_ *
+ #else
+ UInt32
+ #endif
+ CPpmd7_Node_Ref;
+
+typedef struct CPpmd7_Node_
+{
+ UInt16 Stamp; /* must be at offset 0 as CPpmd7_Context::NumStats. Stamp=0 means free */
+ UInt16 NU;
+ CPpmd7_Node_Ref Next; /* must be at offset >= 4 */
+ CPpmd7_Node_Ref Prev;
+} CPpmd7_Node;
+
+#ifdef PPMD_32BIT
+ #define NODE(ptr) (ptr)
+#else
+ #define NODE(offs) ((CPpmd7_Node *)(p->Base + (offs)))
+#endif
+
+static void Ppmd7_Update1(CPpmd7 *p);
+static void Ppmd7_Update1_0(CPpmd7 *p);
+static void Ppmd7_Update2(CPpmd7 *p);
+static void Ppmd7_UpdateBin(CPpmd7 *p);
+static CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked,
+ UInt32 *scale);
+
+/* ----------- Base ----------- */
+
+static void Ppmd7_Construct(CPpmd7 *p)
+{
+ unsigned i, k, m;
+
+ p->Base = 0;
+
+ for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
+ {
+ unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
+ do { p->Units2Indx[k++] = (Byte)i; } while(--step);
+ p->Indx2Units[i] = (Byte)k;
+ }
+
+ p->NS2BSIndx[0] = (0 << 1);
+ p->NS2BSIndx[1] = (1 << 1);
+ memset(p->NS2BSIndx + 2, (2 << 1), 9);
+ memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11);
+
+ for (i = 0; i < 3; i++)
+ p->NS2Indx[i] = (Byte)i;
+ for (m = i, k = 1; i < 256; i++)
+ {
+ p->NS2Indx[i] = (Byte)m;
+ if (--k == 0)
+ k = (++m) - 2;
+ }
+
+ memset(p->HB2Flag, 0, 0x40);
+ memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40);
+}
+
+static void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->Base);
+ p->Size = 0;
+ p->Base = 0;
+}
+
+static Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc)
+{
+ if (p->Base == 0 || p->Size != size)
+ {
+ Ppmd7_Free(p, alloc);
+ p->AlignOffset =
+ #ifdef PPMD_32BIT
+ (4 - size) & 3;
+ #else
+ 4 - (size & 3);
+ #endif
+ if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size
+ #ifndef PPMD_32BIT
+ + UNIT_SIZE
+ #endif
+ )) == 0)
+ return False;
+ p->Size = size;
+ }
+ return True;
+}
+
+static void InsertNode(CPpmd7 *p, void *node, unsigned indx)
+{
+ *((CPpmd_Void_Ref *)node) = p->FreeList[indx];
+ p->FreeList[indx] = REF(node);
+}
+
+static void *RemoveNode(CPpmd7 *p, unsigned indx)
+{
+ CPpmd_Void_Ref *node = (CPpmd_Void_Ref *)Ppmd7_GetPtr(p, p->FreeList[indx]);
+ p->FreeList[indx] = *node;
+ return node;
+}
+
+static void SplitBlock(CPpmd7 *p, void *ptr, unsigned oldIndx, unsigned newIndx)
+{
+ unsigned i, nu = I2U(oldIndx) - I2U(newIndx);
+ ptr = (Byte *)ptr + U2B(I2U(newIndx));
+ if (I2U(i = U2I(nu)) != nu)
+ {
+ unsigned k = I2U(--i);
+ InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1);
+ }
+ InsertNode(p, ptr, i);
+}
+
+static void GlueFreeBlocks(CPpmd7 *p)
+{
+ #ifdef PPMD_32BIT
+ CPpmd7_Node headItem;
+ CPpmd7_Node_Ref head = &headItem;
+ #else
+ CPpmd7_Node_Ref head = p->AlignOffset + p->Size;
+ #endif
+
+ CPpmd7_Node_Ref n = head;
+ unsigned i;
+
+ p->GlueCount = 255;
+
+ /* create doubly-linked list of free blocks */
+ for (i = 0; i < PPMD_NUM_INDEXES; i++)
+ {
+ UInt16 nu = I2U(i);
+ CPpmd7_Node_Ref next = (CPpmd7_Node_Ref)p->FreeList[i];
+ p->FreeList[i] = 0;
+ while (next != 0)
+ {
+ CPpmd7_Node *node = NODE(next);
+ node->Next = n;
+ n = NODE(n)->Prev = next;
+ next = *(const CPpmd7_Node_Ref *)node;
+ node->Stamp = 0;
+ node->NU = (UInt16)nu;
+ }
+ }
+ NODE(head)->Stamp = 1;
+ NODE(head)->Next = n;
+ NODE(n)->Prev = head;
+ if (p->LoUnit != p->HiUnit)
+ ((CPpmd7_Node *)p->LoUnit)->Stamp = 1;
+
+ /* Glue free blocks */
+ while (n != head)
+ {
+ CPpmd7_Node *node = NODE(n);
+ UInt32 nu = (UInt32)node->NU;
+ for (;;)
+ {
+ CPpmd7_Node *node2 = NODE(n) + nu;
+ nu += node2->NU;
+ if (node2->Stamp != 0 || nu >= 0x10000)
+ break;
+ NODE(node2->Prev)->Next = node2->Next;
+ NODE(node2->Next)->Prev = node2->Prev;
+ node->NU = (UInt16)nu;
+ }
+ n = node->Next;
+ }
+
+ /* Fill lists of free blocks */
+ for (n = NODE(head)->Next; n != head;)
+ {
+ CPpmd7_Node *node = NODE(n);
+ unsigned nu;
+ CPpmd7_Node_Ref next = node->Next;
+ for (nu = node->NU; nu > 128; nu -= 128, node += 128)
+ InsertNode(p, node, PPMD_NUM_INDEXES - 1);
+ if (I2U(i = U2I(nu)) != nu)
+ {
+ unsigned k = I2U(--i);
+ InsertNode(p, node + k, nu - k - 1);
+ }
+ InsertNode(p, node, i);
+ n = next;
+ }
+}
+
+static void *AllocUnitsRare(CPpmd7 *p, unsigned indx)
+{
+ unsigned i;
+ void *retVal;
+ if (p->GlueCount == 0)
+ {
+ GlueFreeBlocks(p);
+ if (p->FreeList[indx] != 0)
+ return RemoveNode(p, indx);
+ }
+ i = indx;
+ do
+ {
+ if (++i == PPMD_NUM_INDEXES)
+ {
+ UInt32 numBytes = U2B(I2U(indx));
+ p->GlueCount--;
+ return ((UInt32)(p->UnitsStart - p->Text) > numBytes) ? (p->UnitsStart -= numBytes) : (NULL);
+ }
+ }
+ while (p->FreeList[i] == 0);
+ retVal = RemoveNode(p, i);
+ SplitBlock(p, retVal, i, indx);
+ return retVal;
+}
+
+static void *AllocUnits(CPpmd7 *p, unsigned indx)
+{
+ UInt32 numBytes;
+ if (p->FreeList[indx] != 0)
+ return RemoveNode(p, indx);
+ numBytes = U2B(I2U(indx));
+ if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit))
+ {
+ void *retVal = p->LoUnit;
+ p->LoUnit += numBytes;
+ return retVal;
+ }
+ return AllocUnitsRare(p, indx);
+}
+
+#define MyMem12Cpy(dest, src, num) \
+ { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \
+ do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while(--n); }
+
+static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU)
+{
+ unsigned i0 = U2I(oldNU);
+ unsigned i1 = U2I(newNU);
+ if (i0 == i1)
+ return oldPtr;
+ if (p->FreeList[i1] != 0)
+ {
+ void *ptr = RemoveNode(p, i1);
+ MyMem12Cpy(ptr, oldPtr, newNU);
+ InsertNode(p, oldPtr, i0);
+ return ptr;
+ }
+ SplitBlock(p, oldPtr, i0, i1);
+ return oldPtr;
+}
+
+#define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16)))
+
+static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v)
+{
+ (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF);
+ (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF);
+}
+
+static void RestartModel(CPpmd7 *p)
+{
+ unsigned i, k, m;
+
+ memset(p->FreeList, 0, sizeof(p->FreeList));
+ p->Text = p->Base + p->AlignOffset;
+ p->HiUnit = p->Text + p->Size;
+ p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE;
+ p->GlueCount = 0;
+
+ p->OrderFall = p->MaxOrder;
+ p->RunLength = p->InitRL = -(Int32)((p->MaxOrder < 12) ? p->MaxOrder : 12) - 1;
+ p->PrevSuccess = 0;
+
+ p->MinContext = p->MaxContext = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */
+ p->MinContext->Suffix = 0;
+ p->MinContext->NumStats = 256;
+ p->MinContext->SummFreq = 256 + 1;
+ p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */
+ p->LoUnit += U2B(256 / 2);
+ p->MinContext->Stats = REF(p->FoundState);
+ for (i = 0; i < 256; i++)
+ {
+ CPpmd_State *s = &p->FoundState[i];
+ s->Symbol = (Byte)i;
+ s->Freq = 1;
+ SetSuccessor(s, 0);
+ }
+
+ for (i = 0; i < 128; i++)
+ for (k = 0; k < 8; k++)
+ {
+ UInt16 *dest = p->BinSumm[i] + k;
+ UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 2));
+ for (m = 0; m < 64; m += 8)
+ dest[m] = val;
+ }
+
+ for (i = 0; i < 25; i++)
+ for (k = 0; k < 16; k++)
+ {
+ CPpmd_See *s = &p->See[i][k];
+ s->Summ = (UInt16)((5 * i + 10) << (s->Shift = PPMD_PERIOD_BITS - 4));
+ s->Count = 4;
+ }
+}
+
+static void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder)
+{
+ p->MaxOrder = maxOrder;
+ RestartModel(p);
+ p->DummySee.Shift = PPMD_PERIOD_BITS;
+ p->DummySee.Summ = 0; /* unused */
+ p->DummySee.Count = 64; /* unused */
+}
+
+static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip)
+{
+ CPpmd_State upState;
+ CTX_PTR c = p->MinContext;
+ CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState);
+ CPpmd_State *ps[PPMD7_MAX_ORDER];
+ unsigned numPs = 0;
+
+ if (!skip)
+ ps[numPs++] = p->FoundState;
+
+ while (c->Suffix)
+ {
+ CPpmd_Void_Ref successor;
+ CPpmd_State *s;
+ c = SUFFIX(c);
+ if (c->NumStats != 1)
+ {
+ for (s = STATS(c); s->Symbol != p->FoundState->Symbol; s++);
+ }
+ else
+ s = ONE_STATE(c);
+ successor = SUCCESSOR(s);
+ if (successor != upBranch)
+ {
+ c = CTX(successor);
+ if (numPs == 0)
+ return c;
+ break;
+ }
+ ps[numPs++] = s;
+ }
+
+ upState.Symbol = *(const Byte *)Ppmd7_GetPtr(p, upBranch);
+ SetSuccessor(&upState, upBranch + 1);
+
+ if (c->NumStats == 1)
+ upState.Freq = ONE_STATE(c)->Freq;
+ else
+ {
+ UInt32 cf, s0;
+ CPpmd_State *s;
+ for (s = STATS(c); s->Symbol != upState.Symbol; s++);
+ cf = s->Freq - 1;
+ s0 = c->SummFreq - c->NumStats - cf;
+ upState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : ((2 * cf + 3 * s0 - 1) / (2 * s0))));
+ }
+
+ while (numPs != 0)
+ {
+ /* Create Child */
+ CTX_PTR c1; /* = AllocContext(p); */
+ if (p->HiUnit != p->LoUnit)
+ c1 = (CTX_PTR)(p->HiUnit -= UNIT_SIZE);
+ else if (p->FreeList[0] != 0)
+ c1 = (CTX_PTR)RemoveNode(p, 0);
+ else
+ {
+ c1 = (CTX_PTR)AllocUnitsRare(p, 0);
+ if (!c1)
+ return NULL;
+ }
+ c1->NumStats = 1;
+ *ONE_STATE(c1) = upState;
+ c1->Suffix = REF(c);
+ SetSuccessor(ps[--numPs], REF(c1));
+ c = c1;
+ }
+
+ return c;
+}
+
+static void SwapStates(CPpmd_State *t1, CPpmd_State *t2)
+{
+ CPpmd_State tmp = *t1;
+ *t1 = *t2;
+ *t2 = tmp;
+}
+
+static void UpdateModel(CPpmd7 *p)
+{
+ CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState);
+ CTX_PTR c;
+ unsigned s0, ns;
+
+ if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0)
+ {
+ c = SUFFIX(p->MinContext);
+
+ if (c->NumStats == 1)
+ {
+ CPpmd_State *s = ONE_STATE(c);
+ if (s->Freq < 32)
+ s->Freq++;
+ }
+ else
+ {
+ CPpmd_State *s = STATS(c);
+ if (s->Symbol != p->FoundState->Symbol)
+ {
+ do { s++; } while (s->Symbol != p->FoundState->Symbol);
+ if (s[0].Freq >= s[-1].Freq)
+ {
+ SwapStates(&s[0], &s[-1]);
+ s--;
+ }
+ }
+ if (s->Freq < MAX_FREQ - 9)
+ {
+ s->Freq += 2;
+ c->SummFreq += 2;
+ }
+ }
+ }
+
+ if (p->OrderFall == 0)
+ {
+ p->MinContext = p->MaxContext = CreateSuccessors(p, True);
+ if (p->MinContext == 0)
+ {
+ RestartModel(p);
+ return;
+ }
+ SetSuccessor(p->FoundState, REF(p->MinContext));
+ return;
+ }
+
+ *p->Text++ = p->FoundState->Symbol;
+ successor = REF(p->Text);
+ if (p->Text >= p->UnitsStart)
+ {
+ RestartModel(p);
+ return;
+ }
+
+ if (fSuccessor)
+ {
+ if (fSuccessor <= successor)
+ {
+ CTX_PTR cs = CreateSuccessors(p, False);
+ if (cs == NULL)
+ {
+ RestartModel(p);
+ return;
+ }
+ fSuccessor = REF(cs);
+ }
+ if (--p->OrderFall == 0)
+ {
+ successor = fSuccessor;
+ p->Text -= (p->MaxContext != p->MinContext);
+ }
+ }
+ else
+ {
+ SetSuccessor(p->FoundState, successor);
+ fSuccessor = REF(p->MinContext);
+ }
+
+ s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - (p->FoundState->Freq - 1);
+
+ for (c = p->MaxContext; c != p->MinContext; c = SUFFIX(c))
+ {
+ unsigned ns1;
+ UInt32 cf, sf;
+ if ((ns1 = c->NumStats) != 1)
+ {
+ if ((ns1 & 1) == 0)
+ {
+ /* Expand for one UNIT */
+ unsigned oldNU = ns1 >> 1;
+ unsigned i = U2I(oldNU);
+ if (i != U2I(oldNU + 1))
+ {
+ void *ptr = AllocUnits(p, i + 1);
+ void *oldPtr;
+ if (!ptr)
+ {
+ RestartModel(p);
+ return;
+ }
+ oldPtr = STATS(c);
+ MyMem12Cpy(ptr, oldPtr, oldNU);
+ InsertNode(p, oldPtr, i);
+ c->Stats = STATS_REF(ptr);
+ }
+ }
+ c->SummFreq = (UInt16)(c->SummFreq + (2 * ns1 < ns) + 2 * ((4 * ns1 <= ns) & (c->SummFreq <= 8 * ns1)));
+ }
+ else
+ {
+ CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0);
+ if (!s)
+ {
+ RestartModel(p);
+ return;
+ }
+ *s = *ONE_STATE(c);
+ c->Stats = REF(s);
+ if (s->Freq < MAX_FREQ / 4 - 1)
+ s->Freq <<= 1;
+ else
+ s->Freq = MAX_FREQ - 4;
+ c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 3));
+ }
+ cf = 2 * (UInt32)p->FoundState->Freq * (c->SummFreq + 6);
+ sf = (UInt32)s0 + c->SummFreq;
+ if (cf < 6 * sf)
+ {
+ cf = 1 + (cf > sf) + (cf >= 4 * sf);
+ c->SummFreq += 3;
+ }
+ else
+ {
+ cf = 4 + (cf >= 9 * sf) + (cf >= 12 * sf) + (cf >= 15 * sf);
+ c->SummFreq = (UInt16)(c->SummFreq + cf);
+ }
+ {
+ CPpmd_State *s = STATS(c) + ns1;
+ SetSuccessor(s, successor);
+ s->Symbol = p->FoundState->Symbol;
+ s->Freq = (Byte)cf;
+ c->NumStats = (UInt16)(ns1 + 1);
+ }
+ }
+ p->MaxContext = p->MinContext = CTX(fSuccessor);
+}
+
+static void Rescale(CPpmd7 *p)
+{
+ unsigned i, adder, sumFreq, escFreq;
+ CPpmd_State *stats = STATS(p->MinContext);
+ CPpmd_State *s = p->FoundState;
+ {
+ CPpmd_State tmp = *s;
+ for (; s != stats; s--)
+ s[0] = s[-1];
+ *s = tmp;
+ }
+ escFreq = p->MinContext->SummFreq - s->Freq;
+ s->Freq += 4;
+ adder = (p->OrderFall != 0);
+ s->Freq = (Byte)((s->Freq + adder) >> 1);
+ sumFreq = s->Freq;
+
+ i = p->MinContext->NumStats - 1;
+ do
+ {
+ escFreq -= (++s)->Freq;
+ s->Freq = (Byte)((s->Freq + adder) >> 1);
+ sumFreq += s->Freq;
+ if (s[0].Freq > s[-1].Freq)
+ {
+ CPpmd_State *s1 = s;
+ CPpmd_State tmp = *s1;
+ do
+ s1[0] = s1[-1];
+ while (--s1 != stats && tmp.Freq > s1[-1].Freq);
+ *s1 = tmp;
+ }
+ }
+ while (--i);
+
+ if (s->Freq == 0)
+ {
+ unsigned numStats = p->MinContext->NumStats;
+ unsigned n0, n1;
+ do { i++; } while ((--s)->Freq == 0);
+ escFreq += i;
+ p->MinContext->NumStats = (UInt16)(p->MinContext->NumStats - i);
+ if (p->MinContext->NumStats == 1)
+ {
+ CPpmd_State tmp = *stats;
+ do
+ {
+ tmp.Freq = (Byte)(tmp.Freq - (tmp.Freq >> 1));
+ escFreq >>= 1;
+ }
+ while (escFreq > 1);
+ InsertNode(p, stats, U2I(((numStats + 1) >> 1)));
+ *(p->FoundState = ONE_STATE(p->MinContext)) = tmp;
+ return;
+ }
+ n0 = (numStats + 1) >> 1;
+ n1 = (p->MinContext->NumStats + 1) >> 1;
+ if (n0 != n1)
+ p->MinContext->Stats = STATS_REF(ShrinkUnits(p, stats, n0, n1));
+ }
+ p->MinContext->SummFreq = (UInt16)(sumFreq + escFreq - (escFreq >> 1));
+ p->FoundState = STATS(p->MinContext);
+}
+
+static CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq)
+{
+ CPpmd_See *see;
+ unsigned nonMasked = p->MinContext->NumStats - numMasked;
+ if (p->MinContext->NumStats != 256)
+ {
+ see = p->See[p->NS2Indx[nonMasked - 1]] +
+ (nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) +
+ 2 * (p->MinContext->SummFreq < 11 * p->MinContext->NumStats) +
+ 4 * (numMasked > nonMasked) +
+ p->HiBitsFlag;
+ {
+ unsigned r = (see->Summ >> see->Shift);
+ see->Summ = (UInt16)(see->Summ - r);
+ *escFreq = r + (r == 0);
+ }
+ }
+ else
+ {
+ see = &p->DummySee;
+ *escFreq = 1;
+ }
+ return see;
+}
+
+static void NextContext(CPpmd7 *p)
+{
+ CTX_PTR c = CTX(SUCCESSOR(p->FoundState));
+ if (p->OrderFall == 0 && (Byte *)c > p->Text)
+ p->MinContext = p->MaxContext = c;
+ else
+ UpdateModel(p);
+}
+
+static void Ppmd7_Update1(CPpmd7 *p)
+{
+ CPpmd_State *s = p->FoundState;
+ s->Freq += 4;
+ p->MinContext->SummFreq += 4;
+ if (s[0].Freq > s[-1].Freq)
+ {
+ SwapStates(&s[0], &s[-1]);
+ p->FoundState = --s;
+ if (s->Freq > MAX_FREQ)
+ Rescale(p);
+ }
+ NextContext(p);
+}
+
+static void Ppmd7_Update1_0(CPpmd7 *p)
+{
+ p->PrevSuccess = (2 * p->FoundState->Freq > p->MinContext->SummFreq);
+ p->RunLength += p->PrevSuccess;
+ p->MinContext->SummFreq += 4;
+ if ((p->FoundState->Freq += 4) > MAX_FREQ)
+ Rescale(p);
+ NextContext(p);
+}
+
+static void Ppmd7_UpdateBin(CPpmd7 *p)
+{
+ p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 128 ? 1: 0));
+ p->PrevSuccess = 1;
+ p->RunLength++;
+ NextContext(p);
+}
+
+static void Ppmd7_Update2(CPpmd7 *p)
+{
+ p->MinContext->SummFreq += 4;
+ if ((p->FoundState->Freq += 4) > MAX_FREQ)
+ Rescale(p);
+ p->RunLength = p->InitRL;
+ UpdateModel(p);
+}
+
+/* ---------- Decode ---------- */
+
+static Bool Ppmd_RangeDec_Init(CPpmd7z_RangeDec *p)
+{
+ unsigned i;
+ p->Low = p->Bottom = 0;
+ p->Range = 0xFFFFFFFF;
+ for (i = 0; i < 4; i++)
+ p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);
+ return (p->Code < 0xFFFFFFFF);
+}
+
+static Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p)
+{
+ if (p->Stream->Read((void *)p->Stream) != 0)
+ return False;
+ return Ppmd_RangeDec_Init(p);
+}
+
+static Bool PpmdRAR_RangeDec_Init(CPpmd7z_RangeDec *p)
+{
+ if (!Ppmd_RangeDec_Init(p))
+ return False;
+ p->Bottom = 0x8000;
+ return True;
+}
+
+static UInt32 Range_GetThreshold(void *pp, UInt32 total)
+{
+ CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
+ return (p->Code - p->Low) / (p->Range /= total);
+}
+
+static void Range_Normalize(CPpmd7z_RangeDec *p)
+{
+ while (1)
+ {
+ if((p->Low ^ (p->Low + p->Range)) >= kTopValue)
+ {
+ if(p->Range >= p->Bottom)
+ break;
+ else
+ p->Range = ((uint32_t)(-(int32_t)p->Low)) & (p->Bottom - 1);
+ }
+ p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);
+ p->Range <<= 8;
+ p->Low <<= 8;
+ }
+}
+
+static void Range_Decode_7z(void *pp, UInt32 start, UInt32 size)
+{
+ CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
+ p->Code -= start * p->Range;
+ p->Range *= size;
+ Range_Normalize(p);
+}
+
+static void Range_Decode_RAR(void *pp, UInt32 start, UInt32 size)
+{
+ CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
+ p->Low += start * p->Range;
+ p->Range *= size;
+ Range_Normalize(p);
+}
+
+static UInt32 Range_DecodeBit_7z(void *pp, UInt32 size0)
+{
+ CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
+ UInt32 newBound = (p->Range >> 14) * size0;
+ UInt32 symbol;
+ if (p->Code < newBound)
+ {
+ symbol = 0;
+ p->Range = newBound;
+ }
+ else
+ {
+ symbol = 1;
+ p->Code -= newBound;
+ p->Range -= newBound;
+ }
+ Range_Normalize(p);
+ return symbol;
+}
+
+static UInt32 Range_DecodeBit_RAR(void *pp, UInt32 size0)
+{
+ CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
+ UInt32 bit, value = p->p.GetThreshold(p, PPMD_BIN_SCALE);
+ if(value < size0)
+ {
+ bit = 0;
+ p->p.Decode(p, 0, size0);
+ }
+ else
+ {
+ bit = 1;
+ p->p.Decode(p, size0, PPMD_BIN_SCALE - size0);
+ }
+ return bit;
+}
+
+static void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p)
+{
+ p->p.GetThreshold = Range_GetThreshold;
+ p->p.Decode = Range_Decode_7z;
+ p->p.DecodeBit = Range_DecodeBit_7z;
+}
+
+static void PpmdRAR_RangeDec_CreateVTable(CPpmd7z_RangeDec *p)
+{
+ p->p.GetThreshold = Range_GetThreshold;
+ p->p.Decode = Range_Decode_RAR;
+ p->p.DecodeBit = Range_DecodeBit_RAR;
+}
+
+#define MASK(sym) ((signed char *)charMask)[sym]
+
+static int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc)
+{
+ size_t charMask[256 / sizeof(size_t)];
+ if (p->MinContext->NumStats != 1)
+ {
+ CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext);
+ unsigned i;
+ UInt32 count, hiCnt;
+ if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq))
+ {
+ Byte symbol;
+ rc->Decode(rc, 0, s->Freq);
+ p->FoundState = s;
+ symbol = s->Symbol;
+ Ppmd7_Update1_0(p);
+ return symbol;
+ }
+ p->PrevSuccess = 0;
+ i = p->MinContext->NumStats - 1;
+ do
+ {
+ if ((hiCnt += (++s)->Freq) > count)
+ {
+ Byte symbol;
+ rc->Decode(rc, hiCnt - s->Freq, s->Freq);
+ p->FoundState = s;
+ symbol = s->Symbol;
+ Ppmd7_Update1(p);
+ return symbol;
+ }
+ }
+ while (--i);
+ if (count >= p->MinContext->SummFreq)
+ return -2;
+ p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];
+ rc->Decode(rc, hiCnt, p->MinContext->SummFreq - hiCnt);
+ PPMD_SetAllBitsIn256Bytes(charMask);
+ MASK(s->Symbol) = 0;
+ i = p->MinContext->NumStats - 1;
+ do { MASK((--s)->Symbol) = 0; } while (--i);
+ }
+ else
+ {
+ UInt16 *prob = Ppmd7_GetBinSumm(p);
+ if (rc->DecodeBit(rc, *prob) == 0)
+ {
+ Byte symbol;
+ *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
+ symbol = (p->FoundState = Ppmd7Context_OneState(p->MinContext))->Symbol;
+ Ppmd7_UpdateBin(p);
+ return symbol;
+ }
+ *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
+ p->InitEsc = PPMD7_kExpEscape[*prob >> 10];
+ PPMD_SetAllBitsIn256Bytes(charMask);
+ MASK(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0;
+ p->PrevSuccess = 0;
+ }
+ for (;;)
+ {
+ CPpmd_State *ps[256], *s;
+ UInt32 freqSum, count, hiCnt;
+ CPpmd_See *see;
+ unsigned i, num, numMasked = p->MinContext->NumStats;
+ do
+ {
+ p->OrderFall++;
+ if (!p->MinContext->Suffix)
+ return -1;
+ p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix);
+ }
+ while (p->MinContext->NumStats == numMasked);
+ hiCnt = 0;
+ s = Ppmd7_GetStats(p, p->MinContext);
+ i = 0;
+ num = p->MinContext->NumStats - numMasked;
+ do
+ {
+ int k = (int)(MASK(s->Symbol));
+ hiCnt += (s->Freq & k);
+ ps[i] = s++;
+ i -= k;
+ }
+ while (i != num);
+
+ see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum);
+ freqSum += hiCnt;
+ count = rc->GetThreshold(rc, freqSum);
+
+ if (count < hiCnt)
+ {
+ Byte symbol;
+ CPpmd_State **pps = ps;
+ for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++);
+ s = *pps;
+ rc->Decode(rc, hiCnt - s->Freq, s->Freq);
+ Ppmd_See_Update(see);
+ p->FoundState = s;
+ symbol = s->Symbol;
+ Ppmd7_Update2(p);
+ return symbol;
+ }
+ if (count >= freqSum)
+ return -2;
+ rc->Decode(rc, hiCnt, freqSum - hiCnt);
+ see->Summ = (UInt16)(see->Summ + freqSum);
+ do { MASK(ps[--i]->Symbol) = 0; } while (i != 0);
+ }
+}
+
+/* ---------- Encode ---------- Ppmd7Enc.c */
+
+#define kTopValue (1 << 24)
+
+static void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p)
+{
+ p->Low = 0;
+ p->Range = 0xFFFFFFFF;
+ p->Cache = 0;
+ p->CacheSize = 1;
+}
+
+static void RangeEnc_ShiftLow(CPpmd7z_RangeEnc *p)
+{
+ if ((UInt32)p->Low < (UInt32)0xFF000000 || (unsigned)(p->Low >> 32) != 0)
+ {
+ Byte temp = p->Cache;
+ do
+ {
+ p->Stream->Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32)));
+ temp = 0xFF;
+ }
+ while(--p->CacheSize != 0);
+ p->Cache = (Byte)((UInt32)p->Low >> 24);
+ }
+ p->CacheSize++;
+ p->Low = ((UInt32)p->Low << 8) & 0xFFFFFFFF;
+}
+
+static void RangeEnc_Encode(CPpmd7z_RangeEnc *p, UInt32 start, UInt32 size, UInt32 total)
+{
+ p->Low += start * (p->Range /= total);
+ p->Range *= size;
+ while (p->Range < kTopValue)
+ {
+ p->Range <<= 8;
+ RangeEnc_ShiftLow(p);
+ }
+}
+
+static void RangeEnc_EncodeBit_0(CPpmd7z_RangeEnc *p, UInt32 size0)
+{
+ p->Range = (p->Range >> 14) * size0;
+ while (p->Range < kTopValue)
+ {
+ p->Range <<= 8;
+ RangeEnc_ShiftLow(p);
+ }
+}
+
+static void RangeEnc_EncodeBit_1(CPpmd7z_RangeEnc *p, UInt32 size0)
+{
+ UInt32 newBound = (p->Range >> 14) * size0;
+ p->Low += newBound;
+ p->Range -= newBound;
+ while (p->Range < kTopValue)
+ {
+ p->Range <<= 8;
+ RangeEnc_ShiftLow(p);
+ }
+}
+
+static void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p)
+{
+ unsigned i;
+ for (i = 0; i < 5; i++)
+ RangeEnc_ShiftLow(p);
+}
+
+
+#define MASK(sym) ((signed char *)charMask)[sym]
+
+static void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol)
+{
+ size_t charMask[256 / sizeof(size_t)];
+ if (p->MinContext->NumStats != 1)
+ {
+ CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext);
+ UInt32 sum;
+ unsigned i;
+ if (s->Symbol == symbol)
+ {
+ RangeEnc_Encode(rc, 0, s->Freq, p->MinContext->SummFreq);
+ p->FoundState = s;
+ Ppmd7_Update1_0(p);
+ return;
+ }
+ p->PrevSuccess = 0;
+ sum = s->Freq;
+ i = p->MinContext->NumStats - 1;
+ do
+ {
+ if ((++s)->Symbol == symbol)
+ {
+ RangeEnc_Encode(rc, sum, s->Freq, p->MinContext->SummFreq);
+ p->FoundState = s;
+ Ppmd7_Update1(p);
+ return;
+ }
+ sum += s->Freq;
+ }
+ while (--i);
+
+ p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];
+ PPMD_SetAllBitsIn256Bytes(charMask);
+ MASK(s->Symbol) = 0;
+ i = p->MinContext->NumStats - 1;
+ do { MASK((--s)->Symbol) = 0; } while (--i);
+ RangeEnc_Encode(rc, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq);
+ }
+ else
+ {
+ UInt16 *prob = Ppmd7_GetBinSumm(p);
+ CPpmd_State *s = Ppmd7Context_OneState(p->MinContext);
+ if (s->Symbol == symbol)
+ {
+ RangeEnc_EncodeBit_0(rc, *prob);
+ *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
+ p->FoundState = s;
+ Ppmd7_UpdateBin(p);
+ return;
+ }
+ else
+ {
+ RangeEnc_EncodeBit_1(rc, *prob);
+ *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
+ p->InitEsc = PPMD7_kExpEscape[*prob >> 10];
+ PPMD_SetAllBitsIn256Bytes(charMask);
+ MASK(s->Symbol) = 0;
+ p->PrevSuccess = 0;
+ }
+ }
+ for (;;)
+ {
+ UInt32 escFreq;
+ CPpmd_See *see;
+ CPpmd_State *s;
+ UInt32 sum;
+ unsigned i, numMasked = p->MinContext->NumStats;
+ do
+ {
+ p->OrderFall++;
+ if (!p->MinContext->Suffix)
+ return; /* EndMarker (symbol = -1) */
+ p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix);
+ }
+ while (p->MinContext->NumStats == numMasked);
+
+ see = Ppmd7_MakeEscFreq(p, numMasked, &escFreq);
+ s = Ppmd7_GetStats(p, p->MinContext);
+ sum = 0;
+ i = p->MinContext->NumStats;
+ do
+ {
+ int cur = s->Symbol;
+ if (cur == symbol)
+ {
+ UInt32 low = sum;
+ CPpmd_State *s1 = s;
+ do
+ {
+ sum += (s->Freq & (int)(MASK(s->Symbol)));
+ s++;
+ }
+ while (--i);
+ RangeEnc_Encode(rc, low, s1->Freq, sum + escFreq);
+ Ppmd_See_Update(see);
+ p->FoundState = s1;
+ Ppmd7_Update2(p);
+ return;
+ }
+ sum += (s->Freq & (int)(MASK(cur)));
+ MASK(cur) = 0;
+ s++;
+ }
+ while (--i);
+
+ RangeEnc_Encode(rc, sum, escFreq, sum + escFreq);
+ see->Summ = (UInt16)(see->Summ + sum + escFreq);
+ }
+}
+
+const IPpmd7 __archive_ppmd7_functions =
+{
+ &Ppmd7_Construct,
+ &Ppmd7_Alloc,
+ &Ppmd7_Free,
+ &Ppmd7_Init,
+ &Ppmd7z_RangeDec_CreateVTable,
+ &PpmdRAR_RangeDec_CreateVTable,
+ &Ppmd7z_RangeDec_Init,
+ &PpmdRAR_RangeDec_Init,
+ &Ppmd7_DecodeSymbol,
+ &Ppmd7z_RangeEnc_Init,
+ &Ppmd7z_RangeEnc_FlushData,
+ &Ppmd7_EncodeSymbol
+};
diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h b/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h
new file mode 100644
index 0000000000..3a6b9eb419
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h
@@ -0,0 +1,119 @@
+/* Ppmd7.h -- PPMdH compression codec
+2010-03-12 : Igor Pavlov : Public domain
+This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
+
+/* This code supports virtual RangeDecoder and includes the implementation
+of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H.
+If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_PPMD7_PRIVATE_H_INCLUDED
+#define ARCHIVE_PPMD7_PRIVATE_H_INCLUDED
+
+#include "archive_ppmd_private.h"
+
+#define PPMD7_MIN_ORDER 2
+#define PPMD7_MAX_ORDER 64
+
+#define PPMD7_MIN_MEM_SIZE (1 << 11)
+#define PPMD7_MAX_MEM_SIZE (0xFFFFFFFF - 12 * 3)
+
+struct CPpmd7_Context_;
+
+typedef
+ #ifdef PPMD_32BIT
+ struct CPpmd7_Context_ *
+ #else
+ UInt32
+ #endif
+ CPpmd7_Context_Ref;
+
+typedef struct CPpmd7_Context_
+{
+ UInt16 NumStats;
+ UInt16 SummFreq;
+ CPpmd_State_Ref Stats;
+ CPpmd7_Context_Ref Suffix;
+} CPpmd7_Context;
+
+#define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq)
+
+typedef struct
+{
+ CPpmd7_Context *MinContext, *MaxContext;
+ CPpmd_State *FoundState;
+ unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag;
+ Int32 RunLength, InitRL; /* must be 32-bit at least */
+
+ UInt32 Size;
+ UInt32 GlueCount;
+ Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart;
+ UInt32 AlignOffset;
+
+ Byte Indx2Units[PPMD_NUM_INDEXES];
+ Byte Units2Indx[128];
+ CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES];
+ Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256];
+ CPpmd_See DummySee, See[25][16];
+ UInt16 BinSumm[128][64];
+} CPpmd7;
+
+/* ---------- Decode ---------- */
+
+typedef struct
+{
+ UInt32 (*GetThreshold)(void *p, UInt32 total);
+ void (*Decode)(void *p, UInt32 start, UInt32 size);
+ UInt32 (*DecodeBit)(void *p, UInt32 size0);
+} IPpmd7_RangeDec;
+
+typedef struct
+{
+ IPpmd7_RangeDec p;
+ UInt32 Range;
+ UInt32 Code;
+ UInt32 Low;
+ UInt32 Bottom;
+ IByteIn *Stream;
+} CPpmd7z_RangeDec;
+
+/* ---------- Encode ---------- */
+
+typedef struct
+{
+ UInt64 Low;
+ UInt32 Range;
+ Byte Cache;
+ UInt64 CacheSize;
+ IByteOut *Stream;
+} CPpmd7z_RangeEnc;
+
+typedef struct
+{
+ /* Base Functions */
+ void (*Ppmd7_Construct)(CPpmd7 *p);
+ Bool (*Ppmd7_Alloc)(CPpmd7 *p, UInt32 size, ISzAlloc *alloc);
+ void (*Ppmd7_Free)(CPpmd7 *p, ISzAlloc *alloc);
+ void (*Ppmd7_Init)(CPpmd7 *p, unsigned maxOrder);
+ #define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
+
+ /* Decode Functions */
+ void (*Ppmd7z_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p);
+ void (*PpmdRAR_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p);
+ Bool (*Ppmd7z_RangeDec_Init)(CPpmd7z_RangeDec *p);
+ Bool (*PpmdRAR_RangeDec_Init)(CPpmd7z_RangeDec *p);
+ #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
+ int (*Ppmd7_DecodeSymbol)(CPpmd7 *p, IPpmd7_RangeDec *rc);
+
+ /* Encode Functions */
+ void (*Ppmd7z_RangeEnc_Init)(CPpmd7z_RangeEnc *p);
+ void (*Ppmd7z_RangeEnc_FlushData)(CPpmd7z_RangeEnc *p);
+
+ void (*Ppmd7_EncodeSymbol)(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol);
+} IPpmd7;
+
+extern const IPpmd7 __archive_ppmd7_functions;
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h b/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h
new file mode 100644
index 0000000000..e78bde5940
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h
@@ -0,0 +1,158 @@
+/* Ppmd.h -- PPMD codec common code
+2010-03-12 : Igor Pavlov : Public domain
+This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_PPMD_PRIVATE_H_INCLUDED
+#define ARCHIVE_PPMD_PRIVATE_H_INCLUDED
+
+#include <stddef.h>
+
+#include "archive_read_private.h"
+
+/*** Begin defined in Types.h ***/
+
+#if !defined(ZCONF_H)
+typedef unsigned char Byte;
+#endif
+typedef short Int16;
+typedef unsigned short UInt16;
+
+#ifdef _LZMA_UINT32_IS_ULONG
+typedef long Int32;
+typedef unsigned long UInt32;
+#else
+typedef int Int32;
+typedef unsigned int UInt32;
+#endif
+
+#ifdef _SZ_NO_INT_64
+
+/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
+ NOTES: Some code will work incorrectly in that case! */
+
+typedef long Int64;
+typedef unsigned long UInt64;
+
+#else
+
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+typedef __int64 Int64;
+typedef unsigned __int64 UInt64;
+#define UINT64_CONST(n) n
+#else
+typedef long long int Int64;
+typedef unsigned long long int UInt64;
+#define UINT64_CONST(n) n ## ULL
+#endif
+
+#endif
+
+typedef int Bool;
+#define True 1
+#define False 0
+
+/* The following interfaces use first parameter as pointer to structure */
+
+typedef struct
+{
+ struct archive_read *a;
+ Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
+} IByteIn;
+
+typedef struct
+{
+ struct archive_write *a;
+ void (*Write)(void *p, Byte b);
+} IByteOut;
+
+
+typedef struct
+{
+ void *(*Alloc)(void *p, size_t size);
+ void (*Free)(void *p, void *address); /* address can be 0 */
+} ISzAlloc;
+
+/*** End defined in Types.h ***/
+/*** Begin defined in CpuArch.h ***/
+
+#if defined(_M_IX86) || defined(__i386__)
+#define MY_CPU_X86
+#endif
+
+#if defined(MY_CPU_X86) || defined(_M_ARM)
+#define MY_CPU_32BIT
+#endif
+
+#ifdef MY_CPU_32BIT
+#define PPMD_32BIT
+#endif
+
+/*** End defined in CpuArch.h ***/
+
+#define PPMD_INT_BITS 7
+#define PPMD_PERIOD_BITS 7
+#define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS))
+
+#define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift))
+#define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2)
+#define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob))
+#define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob))
+
+#define PPMD_N1 4
+#define PPMD_N2 4
+#define PPMD_N3 4
+#define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4)
+#define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4)
+
+/* SEE-contexts for PPM-contexts with masked symbols */
+typedef struct
+{
+ UInt16 Summ; /* Freq */
+ Byte Shift; /* Speed of Freq change; low Shift is for fast change */
+ Byte Count; /* Count to next change of Shift */
+} CPpmd_See;
+
+#define Ppmd_See_Update(p) if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \
+ { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); }
+
+typedef struct
+{
+ Byte Symbol;
+ Byte Freq;
+ UInt16 SuccessorLow;
+ UInt16 SuccessorHigh;
+} CPpmd_State;
+
+typedef
+ #ifdef PPMD_32BIT
+ CPpmd_State *
+ #else
+ UInt32
+ #endif
+ CPpmd_State_Ref;
+
+typedef
+ #ifdef PPMD_32BIT
+ void *
+ #else
+ UInt32
+ #endif
+ CPpmd_Void_Ref;
+
+typedef
+ #ifdef PPMD_32BIT
+ Byte *
+ #else
+ UInt32
+ #endif
+ CPpmd_Byte_Ref;
+
+#define PPMD_SetAllBitsIn256Bytes(p) \
+ { unsigned j; for (j = 0; j < 256 / sizeof(p[0]); j += 8) { \
+ p[j+7] = p[j+6] = p[j+5] = p[j+4] = p[j+3] = p[j+2] = p[j+1] = p[j+0] = ~(size_t)0; }}
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_private.h b/Utilities/cmlibarchive/libarchive/archive_private.h
new file mode 100644
index 0000000000..30d472fcda
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_private.h
@@ -0,0 +1,152 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_private.h 201098 2009-12-28 02:58:14Z kientzle $
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_PRIVATE_H_INCLUDED
+#define ARCHIVE_PRIVATE_H_INCLUDED
+
+#if HAVE_ICONV_H
+#include <iconv.h>
+#endif
+
+#include "archive.h"
+#include "archive_string.h"
+
+#if defined(__GNUC__) && (__GNUC__ > 2 || \
+ (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
+#define __LA_DEAD __attribute__((__noreturn__))
+#else
+#define __LA_DEAD
+#endif
+
+#define ARCHIVE_WRITE_MAGIC (0xb0c5c0deU)
+#define ARCHIVE_READ_MAGIC (0xdeb0c5U)
+#define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U)
+#define ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U)
+#define ARCHIVE_MATCH_MAGIC (0xcad11c9U)
+
+#define ARCHIVE_STATE_NEW 1U
+#define ARCHIVE_STATE_HEADER 2U
+#define ARCHIVE_STATE_DATA 4U
+#define ARCHIVE_STATE_EOF 0x10U
+#define ARCHIVE_STATE_CLOSED 0x20U
+#define ARCHIVE_STATE_FATAL 0x8000U
+#define ARCHIVE_STATE_ANY (0xFFFFU & ~ARCHIVE_STATE_FATAL)
+
+struct archive_vtable {
+ int (*archive_close)(struct archive *);
+ int (*archive_free)(struct archive *);
+ int (*archive_write_header)(struct archive *,
+ struct archive_entry *);
+ int (*archive_write_finish_entry)(struct archive *);
+ ssize_t (*archive_write_data)(struct archive *,
+ const void *, size_t);
+ ssize_t (*archive_write_data_block)(struct archive *,
+ const void *, size_t, int64_t);
+
+ int (*archive_read_next_header)(struct archive *,
+ struct archive_entry **);
+ int (*archive_read_next_header2)(struct archive *,
+ struct archive_entry *);
+ int (*archive_read_data_block)(struct archive *,
+ const void **, size_t *, int64_t *);
+
+ int (*archive_filter_count)(struct archive *);
+ int64_t (*archive_filter_bytes)(struct archive *, int);
+ int (*archive_filter_code)(struct archive *, int);
+ const char * (*archive_filter_name)(struct archive *, int);
+};
+
+struct archive_string_conv;
+
+struct archive {
+ /*
+ * The magic/state values are used to sanity-check the
+ * client's usage. If an API function is called at a
+ * ridiculous time, or the client passes us an invalid
+ * pointer, these values allow me to catch that.
+ */
+ unsigned int magic;
+ unsigned int state;
+
+ /*
+ * Some public API functions depend on the "real" type of the
+ * archive object.
+ */
+ struct archive_vtable *vtable;
+
+ int archive_format;
+ const char *archive_format_name;
+
+ int compression_code; /* Currently active compression. */
+ const char *compression_name;
+
+ /* Number of file entries processed. */
+ int file_count;
+
+ int archive_error_number;
+ const char *error;
+ struct archive_string error_string;
+
+ char *current_code;
+ unsigned current_codepage; /* Current ACP(ANSI CodePage). */
+ unsigned current_oemcp; /* Current OEMCP(OEM CodePage). */
+ struct archive_string_conv *sconv;
+};
+
+/* Check magic value and state; return(ARCHIVE_FATAL) if it isn't valid. */
+int __archive_check_magic(struct archive *, unsigned int magic,
+ unsigned int state, const char *func);
+#define archive_check_magic(a, expected_magic, allowed_states, function_name) \
+ do { \
+ int magic_test = __archive_check_magic((a), (expected_magic), \
+ (allowed_states), (function_name)); \
+ if (magic_test == ARCHIVE_FATAL) \
+ return ARCHIVE_FATAL; \
+ } while (0)
+
+void __archive_errx(int retvalue, const char *msg) __LA_DEAD;
+
+void __archive_ensure_cloexec_flag(int fd);
+int __archive_mktemp(const char *tmpdir);
+
+int __archive_clean(struct archive *);
+
+#define err_combine(a,b) ((a) < (b) ? (a) : (b))
+
+#if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER <= 1300)
+# define ARCHIVE_LITERAL_LL(x) x##i64
+# define ARCHIVE_LITERAL_ULL(x) x##ui64
+#else
+# define ARCHIVE_LITERAL_LL(x) x##ll
+# define ARCHIVE_LITERAL_ULL(x) x##ull
+#endif
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_rb.c b/Utilities/cmlibarchive/libarchive/archive_rb.c
new file mode 100644
index 0000000000..5b5da20344
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_rb.c
@@ -0,0 +1,709 @@
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas <matt@3am-software.com>.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ *
+ * Based on: NetBSD: rb.c,v 1.6 2010/04/30 13:58:09 joerg Exp
+ */
+
+#include "archive_platform.h"
+
+#include <stddef.h>
+
+#include "archive_rb.h"
+
+/* Keep in sync with archive_rb.h */
+#define RB_DIR_LEFT 0
+#define RB_DIR_RIGHT 1
+#define RB_DIR_OTHER 1
+#define rb_left rb_nodes[RB_DIR_LEFT]
+#define rb_right rb_nodes[RB_DIR_RIGHT]
+
+#define RB_FLAG_POSITION 0x2
+#define RB_FLAG_RED 0x1
+#define RB_FLAG_MASK (RB_FLAG_POSITION|RB_FLAG_RED)
+#define RB_FATHER(rb) \
+ ((struct archive_rb_node *)((rb)->rb_info & ~RB_FLAG_MASK))
+#define RB_SET_FATHER(rb, father) \
+ ((void)((rb)->rb_info = (uintptr_t)(father)|((rb)->rb_info & RB_FLAG_MASK)))
+
+#define RB_SENTINEL_P(rb) ((rb) == NULL)
+#define RB_LEFT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_left)
+#define RB_RIGHT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_right)
+#define RB_FATHER_SENTINEL_P(rb) RB_SENTINEL_P(RB_FATHER((rb)))
+#define RB_CHILDLESS_P(rb) \
+ (RB_SENTINEL_P(rb) || (RB_LEFT_SENTINEL_P(rb) && RB_RIGHT_SENTINEL_P(rb)))
+#define RB_TWOCHILDREN_P(rb) \
+ (!RB_SENTINEL_P(rb) && !RB_LEFT_SENTINEL_P(rb) && !RB_RIGHT_SENTINEL_P(rb))
+
+#define RB_POSITION(rb) \
+ (((rb)->rb_info & RB_FLAG_POSITION) ? RB_DIR_RIGHT : RB_DIR_LEFT)
+#define RB_RIGHT_P(rb) (RB_POSITION(rb) == RB_DIR_RIGHT)
+#define RB_LEFT_P(rb) (RB_POSITION(rb) == RB_DIR_LEFT)
+#define RB_RED_P(rb) (!RB_SENTINEL_P(rb) && ((rb)->rb_info & RB_FLAG_RED) != 0)
+#define RB_BLACK_P(rb) (RB_SENTINEL_P(rb) || ((rb)->rb_info & RB_FLAG_RED) == 0)
+#define RB_MARK_RED(rb) ((void)((rb)->rb_info |= RB_FLAG_RED))
+#define RB_MARK_BLACK(rb) ((void)((rb)->rb_info &= ~RB_FLAG_RED))
+#define RB_INVERT_COLOR(rb) ((void)((rb)->rb_info ^= RB_FLAG_RED))
+#define RB_ROOT_P(rbt, rb) ((rbt)->rbt_root == (rb))
+#define RB_SET_POSITION(rb, position) \
+ ((void)((position) ? ((rb)->rb_info |= RB_FLAG_POSITION) : \
+ ((rb)->rb_info &= ~RB_FLAG_POSITION)))
+#define RB_ZERO_PROPERTIES(rb) ((void)((rb)->rb_info &= ~RB_FLAG_MASK))
+#define RB_COPY_PROPERTIES(dst, src) \
+ ((void)((dst)->rb_info ^= ((dst)->rb_info ^ (src)->rb_info) & RB_FLAG_MASK))
+#define RB_SWAP_PROPERTIES(a, b) do { \
+ uintptr_t xorinfo = ((a)->rb_info ^ (b)->rb_info) & RB_FLAG_MASK; \
+ (a)->rb_info ^= xorinfo; \
+ (b)->rb_info ^= xorinfo; \
+ } while (/*CONSTCOND*/ 0)
+
+static void __archive_rb_tree_insert_rebalance(struct archive_rb_tree *,
+ struct archive_rb_node *);
+static void __archive_rb_tree_removal_rebalance(struct archive_rb_tree *,
+ struct archive_rb_node *, unsigned int);
+
+#define RB_SENTINEL_NODE NULL
+
+#define T 1
+#define F 0
+
+void
+__archive_rb_tree_init(struct archive_rb_tree *rbt,
+ const struct archive_rb_tree_ops *ops)
+{
+ rbt->rbt_ops = ops;
+ *((struct archive_rb_node **)&rbt->rbt_root) = RB_SENTINEL_NODE;
+}
+
+struct archive_rb_node *
+__archive_rb_tree_find_node(struct archive_rb_tree *rbt, const void *key)
+{
+ archive_rbto_compare_key_fn compare_key = rbt->rbt_ops->rbto_compare_key;
+ struct archive_rb_node *parent = rbt->rbt_root;
+
+ while (!RB_SENTINEL_P(parent)) {
+ const signed int diff = (*compare_key)(parent, key);
+ if (diff == 0)
+ return parent;
+ parent = parent->rb_nodes[diff > 0];
+ }
+
+ return NULL;
+}
+
+struct archive_rb_node *
+__archive_rb_tree_find_node_geq(struct archive_rb_tree *rbt, const void *key)
+{
+ archive_rbto_compare_key_fn compare_key = rbt->rbt_ops->rbto_compare_key;
+ struct archive_rb_node *parent = rbt->rbt_root;
+ struct archive_rb_node *last = NULL;
+
+ while (!RB_SENTINEL_P(parent)) {
+ const signed int diff = (*compare_key)(parent, key);
+ if (diff == 0)
+ return parent;
+ if (diff < 0)
+ last = parent;
+ parent = parent->rb_nodes[diff > 0];
+ }
+
+ return last;
+}
+
+struct archive_rb_node *
+__archive_rb_tree_find_node_leq(struct archive_rb_tree *rbt, const void *key)
+{
+ archive_rbto_compare_key_fn compare_key = rbt->rbt_ops->rbto_compare_key;
+ struct archive_rb_node *parent = rbt->rbt_root;
+ struct archive_rb_node *last = NULL;
+
+ while (!RB_SENTINEL_P(parent)) {
+ const signed int diff = (*compare_key)(parent, key);
+ if (diff == 0)
+ return parent;
+ if (diff > 0)
+ last = parent;
+ parent = parent->rb_nodes[diff > 0];
+ }
+
+ return last;
+}
+
+int
+__archive_rb_tree_insert_node(struct archive_rb_tree *rbt,
+ struct archive_rb_node *self)
+{
+ archive_rbto_compare_nodes_fn compare_nodes = rbt->rbt_ops->rbto_compare_nodes;
+ struct archive_rb_node *parent, *tmp;
+ unsigned int position;
+ int rebalance;
+
+ tmp = rbt->rbt_root;
+ /*
+ * This is a hack. Because rbt->rbt_root is just a
+ * struct archive_rb_node *, just like rb_node->rb_nodes[RB_DIR_LEFT],
+ * we can use this fact to avoid a lot of tests for root and know
+ * that even at root, updating
+ * RB_FATHER(rb_node)->rb_nodes[RB_POSITION(rb_node)] will
+ * update rbt->rbt_root.
+ */
+ parent = (struct archive_rb_node *)(void *)&rbt->rbt_root;
+ position = RB_DIR_LEFT;
+
+ /*
+ * Find out where to place this new leaf.
+ */
+ while (!RB_SENTINEL_P(tmp)) {
+ const signed int diff = (*compare_nodes)(tmp, self);
+ if (diff == 0) {
+ /*
+ * Node already exists; don't insert.
+ */
+ return F;
+ }
+ parent = tmp;
+ position = (diff > 0);
+ tmp = parent->rb_nodes[position];
+ }
+
+ /*
+ * Initialize the node and insert as a leaf into the tree.
+ */
+ RB_SET_FATHER(self, parent);
+ RB_SET_POSITION(self, position);
+ if (parent == (struct archive_rb_node *)(void *)&rbt->rbt_root) {
+ RB_MARK_BLACK(self); /* root is always black */
+ rebalance = F;
+ } else {
+ /*
+ * All new nodes are colored red. We only need to rebalance
+ * if our parent is also red.
+ */
+ RB_MARK_RED(self);
+ rebalance = RB_RED_P(parent);
+ }
+ self->rb_left = parent->rb_nodes[position];
+ self->rb_right = parent->rb_nodes[position];
+ parent->rb_nodes[position] = self;
+
+ /*
+ * Rebalance tree after insertion
+ */
+ if (rebalance)
+ __archive_rb_tree_insert_rebalance(rbt, self);
+
+ return T;
+}
+
+/*
+ * Swap the location and colors of 'self' and its child @ which. The child
+ * can not be a sentinel node. This is our rotation function. However,
+ * since it preserves coloring, it great simplifies both insertion and
+ * removal since rotation almost always involves the exchanging of colors
+ * as a separate step.
+ */
+/*ARGSUSED*/
+static void
+__archive_rb_tree_reparent_nodes(
+ struct archive_rb_node *old_father, const unsigned int which)
+{
+ const unsigned int other = which ^ RB_DIR_OTHER;
+ struct archive_rb_node * const grandpa = RB_FATHER(old_father);
+ struct archive_rb_node * const old_child = old_father->rb_nodes[which];
+ struct archive_rb_node * const new_father = old_child;
+ struct archive_rb_node * const new_child = old_father;
+
+ if (new_father == NULL)
+ return;
+ /*
+ * Exchange descendant linkages.
+ */
+ grandpa->rb_nodes[RB_POSITION(old_father)] = new_father;
+ new_child->rb_nodes[which] = old_child->rb_nodes[other];
+ new_father->rb_nodes[other] = new_child;
+
+ /*
+ * Update ancestor linkages
+ */
+ RB_SET_FATHER(new_father, grandpa);
+ RB_SET_FATHER(new_child, new_father);
+
+ /*
+ * Exchange properties between new_father and new_child. The only
+ * change is that new_child's position is now on the other side.
+ */
+ RB_SWAP_PROPERTIES(new_father, new_child);
+ RB_SET_POSITION(new_child, other);
+
+ /*
+ * Make sure to reparent the new child to ourself.
+ */
+ if (!RB_SENTINEL_P(new_child->rb_nodes[which])) {
+ RB_SET_FATHER(new_child->rb_nodes[which], new_child);
+ RB_SET_POSITION(new_child->rb_nodes[which], which);
+ }
+
+}
+
+static void
+__archive_rb_tree_insert_rebalance(struct archive_rb_tree *rbt,
+ struct archive_rb_node *self)
+{
+ struct archive_rb_node * father = RB_FATHER(self);
+ struct archive_rb_node * grandpa;
+ struct archive_rb_node * uncle;
+ unsigned int which;
+ unsigned int other;
+
+ for (;;) {
+ /*
+ * We are red and our parent is red, therefore we must have a
+ * grandfather and he must be black.
+ */
+ grandpa = RB_FATHER(father);
+ which = (father == grandpa->rb_right);
+ other = which ^ RB_DIR_OTHER;
+ uncle = grandpa->rb_nodes[other];
+
+ if (RB_BLACK_P(uncle))
+ break;
+
+ /*
+ * Case 1: our uncle is red
+ * Simply invert the colors of our parent and
+ * uncle and make our grandparent red. And
+ * then solve the problem up at his level.
+ */
+ RB_MARK_BLACK(uncle);
+ RB_MARK_BLACK(father);
+ if (RB_ROOT_P(rbt, grandpa)) {
+ /*
+ * If our grandpa is root, don't bother
+ * setting him to red, just return.
+ */
+ return;
+ }
+ RB_MARK_RED(grandpa);
+ self = grandpa;
+ father = RB_FATHER(self);
+ if (RB_BLACK_P(father)) {
+ /*
+ * If our greatgrandpa is black, we're done.
+ */
+ return;
+ }
+ }
+
+ /*
+ * Case 2&3: our uncle is black.
+ */
+ if (self == father->rb_nodes[other]) {
+ /*
+ * Case 2: we are on the same side as our uncle
+ * Swap ourselves with our parent so this case
+ * becomes case 3. Basically our parent becomes our
+ * child.
+ */
+ __archive_rb_tree_reparent_nodes(father, other);
+ }
+ /*
+ * Case 3: we are opposite a child of a black uncle.
+ * Swap our parent and grandparent. Since our grandfather
+ * is black, our father will become black and our new sibling
+ * (former grandparent) will become red.
+ */
+ __archive_rb_tree_reparent_nodes(grandpa, which);
+
+ /*
+ * Final step: Set the root to black.
+ */
+ RB_MARK_BLACK(rbt->rbt_root);
+}
+
+static void
+__archive_rb_tree_prune_node(struct archive_rb_tree *rbt,
+ struct archive_rb_node *self, int rebalance)
+{
+ const unsigned int which = RB_POSITION(self);
+ struct archive_rb_node *father = RB_FATHER(self);
+
+ /*
+ * Since we are childless, we know that self->rb_left is pointing
+ * to the sentinel node.
+ */
+ father->rb_nodes[which] = self->rb_left;
+
+ /*
+ * Rebalance if requested.
+ */
+ if (rebalance)
+ __archive_rb_tree_removal_rebalance(rbt, father, which);
+}
+
+/*
+ * When deleting an interior node
+ */
+static void
+__archive_rb_tree_swap_prune_and_rebalance(struct archive_rb_tree *rbt,
+ struct archive_rb_node *self, struct archive_rb_node *standin)
+{
+ const unsigned int standin_which = RB_POSITION(standin);
+ unsigned int standin_other = standin_which ^ RB_DIR_OTHER;
+ struct archive_rb_node *standin_son;
+ struct archive_rb_node *standin_father = RB_FATHER(standin);
+ int rebalance = RB_BLACK_P(standin);
+
+ if (standin_father == self) {
+ /*
+ * As a child of self, any children would be opposite of
+ * our parent.
+ */
+ standin_son = standin->rb_nodes[standin_which];
+ } else {
+ /*
+ * Since we aren't a child of self, any children would be
+ * on the same side as our parent.
+ */
+ standin_son = standin->rb_nodes[standin_other];
+ }
+
+ if (RB_RED_P(standin_son)) {
+ /*
+ * We know we have a red child so if we flip it to black
+ * we don't have to rebalance.
+ */
+ RB_MARK_BLACK(standin_son);
+ rebalance = F;
+
+ if (standin_father != self) {
+ /*
+ * Change the son's parentage to point to his grandpa.
+ */
+ RB_SET_FATHER(standin_son, standin_father);
+ RB_SET_POSITION(standin_son, standin_which);
+ }
+ }
+
+ if (standin_father == self) {
+ /*
+ * If we are about to delete the standin's father, then when
+ * we call rebalance, we need to use ourselves as our father.
+ * Otherwise remember our original father. Also, since we are
+ * our standin's father we only need to reparent the standin's
+ * brother.
+ *
+ * | R --> S |
+ * | Q S --> Q T |
+ * | t --> |
+ *
+ * Have our son/standin adopt his brother as his new son.
+ */
+ standin_father = standin;
+ } else {
+ /*
+ * | R --> S . |
+ * | / \ | T --> / \ | / |
+ * | ..... | S --> ..... | T |
+ *
+ * Sever standin's connection to his father.
+ */
+ standin_father->rb_nodes[standin_which] = standin_son;
+ /*
+ * Adopt the far son.
+ */
+ standin->rb_nodes[standin_other] = self->rb_nodes[standin_other];
+ RB_SET_FATHER(standin->rb_nodes[standin_other], standin);
+ /*
+ * Use standin_other because we need to preserve standin_which
+ * for the removal_rebalance.
+ */
+ standin_other = standin_which;
+ }
+
+ /*
+ * Move the only remaining son to our standin. If our standin is our
+ * son, this will be the only son needed to be moved.
+ */
+ standin->rb_nodes[standin_other] = self->rb_nodes[standin_other];
+ RB_SET_FATHER(standin->rb_nodes[standin_other], standin);
+
+ /*
+ * Now copy the result of self to standin and then replace
+ * self with standin in the tree.
+ */
+ RB_COPY_PROPERTIES(standin, self);
+ RB_SET_FATHER(standin, RB_FATHER(self));
+ RB_FATHER(standin)->rb_nodes[RB_POSITION(standin)] = standin;
+
+ if (rebalance)
+ __archive_rb_tree_removal_rebalance(rbt, standin_father, standin_which);
+}
+
+/*
+ * We could do this by doing
+ * __archive_rb_tree_node_swap(rbt, self, which);
+ * __archive_rb_tree_prune_node(rbt, self, F);
+ *
+ * But it's more efficient to just evaluate and recolor the child.
+ */
+static void
+__archive_rb_tree_prune_blackred_branch(
+ struct archive_rb_node *self, unsigned int which)
+{
+ struct archive_rb_node *father = RB_FATHER(self);
+ struct archive_rb_node *son = self->rb_nodes[which];
+
+ /*
+ * Remove ourselves from the tree and give our former child our
+ * properties (position, color, root).
+ */
+ RB_COPY_PROPERTIES(son, self);
+ father->rb_nodes[RB_POSITION(son)] = son;
+ RB_SET_FATHER(son, father);
+}
+/*
+ *
+ */
+void
+__archive_rb_tree_remove_node(struct archive_rb_tree *rbt,
+ struct archive_rb_node *self)
+{
+ struct archive_rb_node *standin;
+ unsigned int which;
+
+ /*
+ * In the following diagrams, we (the node to be removed) are S. Red
+ * nodes are lowercase. T could be either red or black.
+ *
+ * Remember the major axiom of the red-black tree: the number of
+ * black nodes from the root to each leaf is constant across all
+ * leaves, only the number of red nodes varies.
+ *
+ * Thus removing a red leaf doesn't require any other changes to a
+ * red-black tree. So if we must remove a node, attempt to rearrange
+ * the tree so we can remove a red node.
+ *
+ * The simplest case is a childless red node or a childless root node:
+ *
+ * | T --> T | or | R --> * |
+ * | s --> * |
+ */
+ if (RB_CHILDLESS_P(self)) {
+ const int rebalance = RB_BLACK_P(self) && !RB_ROOT_P(rbt, self);
+ __archive_rb_tree_prune_node(rbt, self, rebalance);
+ return;
+ }
+ if (!RB_TWOCHILDREN_P(self)) {
+ /*
+ * The next simplest case is the node we are deleting is
+ * black and has one red child.
+ *
+ * | T --> T --> T |
+ * | S --> R --> R |
+ * | r --> s --> * |
+ */
+ which = RB_LEFT_SENTINEL_P(self) ? RB_DIR_RIGHT : RB_DIR_LEFT;
+ __archive_rb_tree_prune_blackred_branch(self, which);
+ return;
+ }
+
+ /*
+ * We invert these because we prefer to remove from the inside of
+ * the tree.
+ */
+ which = RB_POSITION(self) ^ RB_DIR_OTHER;
+
+ /*
+ * Let's find the node closes to us opposite of our parent
+ * Now swap it with ourself, "prune" it, and rebalance, if needed.
+ */
+ standin = __archive_rb_tree_iterate(rbt, self, which);
+ __archive_rb_tree_swap_prune_and_rebalance(rbt, self, standin);
+}
+
+static void
+__archive_rb_tree_removal_rebalance(struct archive_rb_tree *rbt,
+ struct archive_rb_node *parent, unsigned int which)
+{
+
+ while (RB_BLACK_P(parent->rb_nodes[which])) {
+ unsigned int other = which ^ RB_DIR_OTHER;
+ struct archive_rb_node *brother = parent->rb_nodes[other];
+
+ if (brother == NULL)
+ return;/* The tree may be broken. */
+ /*
+ * For cases 1, 2a, and 2b, our brother's children must
+ * be black and our father must be black
+ */
+ if (RB_BLACK_P(parent)
+ && RB_BLACK_P(brother->rb_left)
+ && RB_BLACK_P(brother->rb_right)) {
+ if (RB_RED_P(brother)) {
+ /*
+ * Case 1: Our brother is red, swap its
+ * position (and colors) with our parent.
+ * This should now be case 2b (unless C or E
+ * has a red child which is case 3; thus no
+ * explicit branch to case 2b).
+ *
+ * B -> D
+ * A d -> b E
+ * C E -> A C
+ */
+ __archive_rb_tree_reparent_nodes(parent, other);
+ brother = parent->rb_nodes[other];
+ if (brother == NULL)
+ return;/* The tree may be broken. */
+ } else {
+ /*
+ * Both our parent and brother are black.
+ * Change our brother to red, advance up rank
+ * and go through the loop again.
+ *
+ * B -> *B
+ * *A D -> A d
+ * C E -> C E
+ */
+ RB_MARK_RED(brother);
+ if (RB_ROOT_P(rbt, parent))
+ return; /* root == parent == black */
+ which = RB_POSITION(parent);
+ parent = RB_FATHER(parent);
+ continue;
+ }
+ }
+ /*
+ * Avoid an else here so that case 2a above can hit either
+ * case 2b, 3, or 4.
+ */
+ if (RB_RED_P(parent)
+ && RB_BLACK_P(brother)
+ && RB_BLACK_P(brother->rb_left)
+ && RB_BLACK_P(brother->rb_right)) {
+ /*
+ * We are black, our father is red, our brother and
+ * both nephews are black. Simply invert/exchange the
+ * colors of our father and brother (to black and red
+ * respectively).
+ *
+ * | f --> F |
+ * | * B --> * b |
+ * | N N --> N N |
+ */
+ RB_MARK_BLACK(parent);
+ RB_MARK_RED(brother);
+ break; /* We're done! */
+ } else {
+ /*
+ * Our brother must be black and have at least one
+ * red child (it may have two).
+ */
+ if (RB_BLACK_P(brother->rb_nodes[other])) {
+ /*
+ * Case 3: our brother is black, our near
+ * nephew is red, and our far nephew is black.
+ * Swap our brother with our near nephew.
+ * This result in a tree that matches case 4.
+ * (Our father could be red or black).
+ *
+ * | F --> F |
+ * | x B --> x B |
+ * | n --> n |
+ */
+ __archive_rb_tree_reparent_nodes(brother, which);
+ brother = parent->rb_nodes[other];
+ }
+ /*
+ * Case 4: our brother is black and our far nephew
+ * is red. Swap our father and brother locations and
+ * change our far nephew to black. (these can be
+ * done in either order so we change the color first).
+ * The result is a valid red-black tree and is a
+ * terminal case. (again we don't care about the
+ * father's color)
+ *
+ * If the father is red, we will get a red-black-black
+ * tree:
+ * | f -> f --> b |
+ * | B -> B --> F N |
+ * | n -> N --> |
+ *
+ * If the father is black, we will get an all black
+ * tree:
+ * | F -> F --> B |
+ * | B -> B --> F N |
+ * | n -> N --> |
+ *
+ * If we had two red nephews, then after the swap,
+ * our former father would have a red grandson.
+ */
+ if (brother->rb_nodes[other] == NULL)
+ return;/* The tree may be broken. */
+ RB_MARK_BLACK(brother->rb_nodes[other]);
+ __archive_rb_tree_reparent_nodes(parent, other);
+ break; /* We're done! */
+ }
+ }
+}
+
+struct archive_rb_node *
+__archive_rb_tree_iterate(struct archive_rb_tree *rbt,
+ struct archive_rb_node *self, const unsigned int direction)
+{
+ const unsigned int other = direction ^ RB_DIR_OTHER;
+
+ if (self == NULL) {
+ self = rbt->rbt_root;
+ if (RB_SENTINEL_P(self))
+ return NULL;
+ while (!RB_SENTINEL_P(self->rb_nodes[direction]))
+ self = self->rb_nodes[direction];
+ return self;
+ }
+ /*
+ * We can't go any further in this direction. We proceed up in the
+ * opposite direction until our parent is in direction we want to go.
+ */
+ if (RB_SENTINEL_P(self->rb_nodes[direction])) {
+ while (!RB_ROOT_P(rbt, self)) {
+ if (other == (unsigned int)RB_POSITION(self))
+ return RB_FATHER(self);
+ self = RB_FATHER(self);
+ }
+ return NULL;
+ }
+
+ /*
+ * Advance down one in current direction and go down as far as possible
+ * in the opposite direction.
+ */
+ self = self->rb_nodes[direction];
+ while (!RB_SENTINEL_P(self->rb_nodes[other]))
+ self = self->rb_nodes[other];
+ return self;
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_rb.h b/Utilities/cmlibarchive/libarchive/archive_rb.h
new file mode 100644
index 0000000000..4562e9ebc4
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_rb.h
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas <matt@3am-software.com>.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ *
+ * Based on NetBSD: rb.h,v 1.13 2009/08/16 10:57:01 yamt Exp
+ */
+#ifndef ARCHIVE_RB_H_
+#define ARCHIVE_RB_H_
+
+struct archive_rb_node {
+ struct archive_rb_node *rb_nodes[2];
+ /*
+ * rb_info contains the two flags and the parent back pointer.
+ * We put the two flags in the low two bits since we know that
+ * rb_node will have an alignment of 4 or 8 bytes.
+ */
+ uintptr_t rb_info;
+};
+
+#define ARCHIVE_RB_DIR_LEFT 0
+#define ARCHIVE_RB_DIR_RIGHT 1
+
+#define ARCHIVE_RB_TREE_MIN(T) \
+ __archive_rb_tree_iterate((T), NULL, ARCHIVE_RB_DIR_LEFT)
+#define ARCHIVE_RB_TREE_MAX(T) \
+ __archive_rb_tree_iterate((T), NULL, ARCHIVE_RB_DIR_RIGHT)
+#define ARCHIVE_RB_TREE_FOREACH(N, T) \
+ for ((N) = ARCHIVE_RB_TREE_MIN(T); (N); \
+ (N) = __archive_rb_tree_iterate((T), (N), ARCHIVE_RB_DIR_RIGHT))
+#define ARCHIVE_RB_TREE_FOREACH_REVERSE(N, T) \
+ for ((N) = ARCHIVE_RB_TREE_MAX(T); (N); \
+ (N) = __archive_rb_tree_iterate((T), (N), ARCHIVE_RB_DIR_LEFT))
+
+/*
+ * archive_rbto_compare_nodes_fn:
+ * return a positive value if the first node < the second node.
+ * return a negative value if the first node > the second node.
+ * return 0 if they are considered same.
+ *
+ * archive_rbto_compare_key_fn:
+ * return a positive value if the node < the key.
+ * return a negative value if the node > the key.
+ * return 0 if they are considered same.
+ */
+
+typedef signed int (*const archive_rbto_compare_nodes_fn)(const struct archive_rb_node *,
+ const struct archive_rb_node *);
+typedef signed int (*const archive_rbto_compare_key_fn)(const struct archive_rb_node *,
+ const void *);
+
+struct archive_rb_tree_ops {
+ archive_rbto_compare_nodes_fn rbto_compare_nodes;
+ archive_rbto_compare_key_fn rbto_compare_key;
+};
+
+struct archive_rb_tree {
+ struct archive_rb_node *rbt_root;
+ const struct archive_rb_tree_ops *rbt_ops;
+};
+
+void __archive_rb_tree_init(struct archive_rb_tree *,
+ const struct archive_rb_tree_ops *);
+int __archive_rb_tree_insert_node(struct archive_rb_tree *,
+ struct archive_rb_node *);
+struct archive_rb_node *
+ __archive_rb_tree_find_node(struct archive_rb_tree *, const void *);
+struct archive_rb_node *
+ __archive_rb_tree_find_node_geq(struct archive_rb_tree *, const void *);
+struct archive_rb_node *
+ __archive_rb_tree_find_node_leq(struct archive_rb_tree *, const void *);
+void __archive_rb_tree_remove_node(struct archive_rb_tree *, struct archive_rb_node *);
+struct archive_rb_node *
+ __archive_rb_tree_iterate(struct archive_rb_tree *,
+ struct archive_rb_node *, const unsigned int);
+
+#endif /* ARCHIVE_RB_H_*/
diff --git a/Utilities/cmlibarchive/libarchive/archive_read.3 b/Utilities/cmlibarchive/libarchive/archive_read.3
new file mode 100644
index 0000000000..a29cc1ea69
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read.3
@@ -0,0 +1,252 @@
+.\" Copyright (c) 2003-2007 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ 3
+.Os
+.Sh NAME
+.Nm archive_read
+.Nd functions for reading streaming archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Sh DESCRIPTION
+These functions provide a complete API for reading streaming archives.
+The general process is to first create the
+.Tn struct archive
+object, set options, initialize the reader, iterate over the archive
+headers and associated data, then close the archive and release all
+resources.
+.\"
+.Ss Create archive object
+See
+.Xr archive_read_new 3 .
+.Pp
+To read an archive, you must first obtain an initialized
+.Tn struct archive
+object from
+.Fn archive_read_new .
+.\"
+.Ss Enable filters and formats
+See
+.Xr archive_read_filter 3
+and
+.Xr archive_read_format 3 .
+.Pp
+You can then modify this object for the desired operations with the
+various
+.Fn archive_read_set_XXX
+and
+.Fn archive_read_support_XXX
+functions.
+In particular, you will need to invoke appropriate
+.Fn archive_read_support_XXX
+functions to enable the corresponding compression and format
+support.
+Note that these latter functions perform two distinct operations:
+they cause the corresponding support code to be linked into your
+program, and they enable the corresponding auto-detect code.
+Unless you have specific constraints, you will generally want
+to invoke
+.Fn archive_read_support_filter_all
+and
+.Fn archive_read_support_format_all
+to enable auto-detect for all formats and compression types
+currently supported by the library.
+.\"
+.Ss Set options
+See
+.Xr archive_read_set_options 3 .
+.\"
+.Ss Open archive
+See
+.Xr archive_read_open 3 .
+.Pp
+Once you have prepared the
+.Tn struct archive
+object, you call
+.Fn archive_read_open
+to actually open the archive and prepare it for reading.
+There are several variants of this function;
+the most basic expects you to provide pointers to several
+functions that can provide blocks of bytes from the archive.
+There are convenience forms that allow you to
+specify a filename, file descriptor,
+.Ft "FILE *"
+object, or a block of memory from which to read the archive data.
+Note that the core library makes no assumptions about the
+size of the blocks read;
+callback functions are free to read whatever block size is
+most appropriate for the medium.
+.\"
+.Ss Consume archive
+See
+.Xr archive_read_header 3 ,
+.Xr archive_read_data 3
+and
+.Xr archive_read_extract 3 .
+.Pp
+Each archive entry consists of a header followed by a certain
+amount of data.
+You can obtain the next header with
+.Fn archive_read_next_header ,
+which returns a pointer to an
+.Tn struct archive_entry
+structure with information about the current archive element.
+If the entry is a regular file, then the header will be followed
+by the file data.
+You can use
+.Fn archive_read_data
+(which works much like the
+.Xr read 2
+system call)
+to read this data from the archive, or
+.Fn archive_read_data_block
+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 ,
+which copies the data to the provided file descriptor, or
+.Fn archive_read_extract ,
+which recreates the specified entry on disk and copies data
+from the archive.
+In particular, note that
+.Fn archive_read_extract
+uses the
+.Tn struct archive_entry
+structure that you provide it, which may differ from the
+entry just read from the archive.
+In particular, many applications will want to override the
+pathname, file permissions, or ownership.
+.\"
+.Ss Release resources
+See
+.Xr archive_read_free 3 .
+.Pp
+Once you have finished reading data from the archive, you
+should call
+.Fn archive_read_close
+to close the archive, then call
+.Fn archive_read_free
+to release all resources, including all memory allocated by the library.
+.\"
+.Sh EXAMPLE
+The following illustrates basic usage of the library.
+In this example,
+the callback functions are simply wrappers around the standard
+.Xr open 2 ,
+.Xr read 2 ,
+and
+.Xr close 2
+system calls.
+.Bd -literal -offset indent
+void
+list_archive(const char *name)
+{
+ struct mydata *mydata;
+ struct archive *a;
+ struct archive_entry *entry;
+
+ mydata = malloc(sizeof(struct mydata));
+ a = archive_read_new();
+ mydata->name = name;
+ archive_read_support_filter_all(a);
+ archive_read_support_format_all(a);
+ archive_read_open(a, mydata, myopen, myread, myclose);
+ while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
+ printf("%s\en",archive_entry_pathname(entry));
+ archive_read_data_skip(a);
+ }
+ archive_read_free(a);
+ free(mydata);
+}
+
+ssize_t
+myread(struct archive *a, void *client_data, const void **buff)
+{
+ struct mydata *mydata = client_data;
+
+ *buff = mydata->buff;
+ return (read(mydata->fd, mydata->buff, 10240));
+}
+
+int
+myopen(struct archive *a, void *client_data)
+{
+ struct mydata *mydata = client_data;
+
+ mydata->fd = open(mydata->name, O_RDONLY);
+ return (mydata->fd >= 0 ? ARCHIVE_OK : ARCHIVE_FATAL);
+}
+
+int
+myclose(struct archive *a, void *client_data)
+{
+ struct mydata *mydata = client_data;
+
+ if (mydata->fd > 0)
+ close(mydata->fd);
+ return (ARCHIVE_OK);
+}
+.Ed
+.\" .Sh ERRORS
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_read_new 3 ,
+.Xr archive_read_data 3 ,
+.Xr archive_read_extract 3 ,
+.Xr archive_read_filter 3 ,
+.Xr archive_read_format 3 ,
+.Xr archive_read_header 3 ,
+.Xr archive_read_open 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_util 3 ,
+.Xr tar 5
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libarchive
+library was written by
+.An Tim Kientzle Aq kientzle@acm.org .
+.Sh BUGS
+Many traditional archiver programs treat
+empty files as valid empty archives.
+For example, many implementations of
+.Xr tar 1
+allow you to append entries to an empty file.
+Of course, it is impossible to determine the format of an empty file
+by inspecting the contents, so this library treats empty files as
+having a special
+.Dq empty
+format.
diff --git a/Utilities/cmlibarchive/libarchive/archive_read.c b/Utilities/cmlibarchive/libarchive/archive_read.c
new file mode 100644
index 0000000000..a65b94dae7
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read.c
@@ -0,0 +1,1696 @@
+/*-
+ * Copyright (c) 2003-2011 Tim Kientzle
+ * 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.
+ */
+
+/*
+ * This file contains the "essential" portions of the read API, that
+ * is, stuff that will probably always be used by any client that
+ * actually needs to read an archive. Optional pieces have been, as
+ * far as possible, separated out into separate files to avoid
+ * needlessly bloating statically-linked clients.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD: head/lib/libarchive/archive_read.c 201157 2009-12-29 05:30:23Z kientzle $");
+
+#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
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+#define minimum(a, b) (a < b ? a : b)
+
+static int choose_filters(struct archive_read *);
+static int choose_format(struct archive_read *);
+static struct archive_vtable *archive_read_vtable(void);
+static int64_t _archive_filter_bytes(struct archive *, int);
+static int _archive_filter_code(struct archive *, int);
+static const char *_archive_filter_name(struct archive *, int);
+static int _archive_filter_count(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_free(struct archive *);
+static int _archive_read_next_header(struct archive *,
+ struct archive_entry **);
+static int _archive_read_next_header2(struct archive *,
+ struct archive_entry *);
+static int64_t advance_file_pointer(struct archive_read_filter *, int64_t);
+
+static struct archive_vtable *
+archive_read_vtable(void)
+{
+ static struct archive_vtable av;
+ static int inited = 0;
+
+ if (!inited) {
+ av.archive_filter_bytes = _archive_filter_bytes;
+ av.archive_filter_code = _archive_filter_code;
+ av.archive_filter_name = _archive_filter_name;
+ av.archive_filter_count = _archive_filter_count;
+ 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;
+ av.archive_free = _archive_read_free;
+ av.archive_close = _archive_read_close;
+ inited = 1;
+ }
+ return (&av);
+}
+
+/*
+ * Allocate, initialize and return a struct archive object.
+ */
+struct archive *
+archive_read_new(void)
+{
+ struct archive_read *a;
+
+ a = (struct archive_read *)malloc(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();
+
+ return (&a->archive);
+}
+
+/*
+ * Record the do-not-extract-to file. This belongs in archive_read_extract.c.
+ */
+void
+archive_read_extract_set_skip_file(struct archive *_a, int64_t d, int64_t i)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+
+ if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_extract_set_skip_file"))
+ return;
+ a->skip_file_set = 1;
+ a->skip_file_dev = d;
+ a->skip_file_ino = i;
+}
+
+/*
+ * Open the archive
+ */
+int
+archive_read_open(struct archive *a, void *client_data,
+ archive_open_callback *client_opener, archive_read_callback *client_reader,
+ archive_close_callback *client_closer)
+{
+ /* Old archive_read_open() is just a thin shell around
+ * archive_read_open1. */
+ archive_read_set_open_callback(a, client_opener);
+ archive_read_set_read_callback(a, client_reader);
+ archive_read_set_close_callback(a, client_closer);
+ archive_read_set_callback_data(a, client_data);
+ return archive_read_open1(a);
+}
+
+
+int
+archive_read_open2(struct archive *a, void *client_data,
+ archive_open_callback *client_opener,
+ archive_read_callback *client_reader,
+ archive_skip_callback *client_skipper,
+ archive_close_callback *client_closer)
+{
+ /* Old archive_read_open2() is just a thin shell around
+ * archive_read_open1. */
+ archive_read_set_callback_data(a, client_data);
+ archive_read_set_open_callback(a, client_opener);
+ archive_read_set_read_callback(a, client_reader);
+ archive_read_set_skip_callback(a, client_skipper);
+ archive_read_set_close_callback(a, client_closer);
+ return archive_read_open1(a);
+}
+
+static ssize_t
+client_read_proxy(struct archive_read_filter *self, const void **buff)
+{
+ ssize_t r;
+ r = (self->archive->client.reader)(&self->archive->archive,
+ self->data, buff);
+ return (r);
+}
+
+static int64_t
+client_skip_proxy(struct archive_read_filter *self, int64_t request)
+{
+ if (request < 0)
+ __archive_errx(1, "Negative skip requested.");
+ if (request == 0)
+ return 0;
+
+ if (self->archive->client.skipper != NULL) {
+ /* Seek requests over 1GiB are broken down into
+ * multiple seeks. This avoids overflows when the
+ * requests get passed through 32-bit arguments. */
+ int64_t skip_limit = (int64_t)1 << 30;
+ int64_t total = 0;
+ for (;;) {
+ int64_t get, ask = request;
+ if (ask > skip_limit)
+ ask = skip_limit;
+ get = (self->archive->client.skipper)
+ (&self->archive->archive, self->data, ask);
+ if (get == 0)
+ return (total);
+ request -= get;
+ total += get;
+ }
+ } else if (self->archive->client.seeker != NULL
+ && request > 64 * 1024) {
+ /* If the client provided a seeker but not a skipper,
+ * we can use the seeker to skip forward.
+ *
+ * Note: This isn't always a good idea. The client
+ * skipper is allowed to skip by less than requested
+ * if it needs to maintain block alignment. The
+ * seeker is not allowed to play such games, so using
+ * the seeker here may be a performance loss compared
+ * to just reading and discarding. That's why we
+ * only do this for skips of over 64k.
+ */
+ int64_t before = self->position;
+ int64_t after = (self->archive->client.seeker)
+ (&self->archive->archive, self->data, request, SEEK_CUR);
+ if (after != before + request)
+ return ARCHIVE_FATAL;
+ return after - before;
+ }
+ return 0;
+}
+
+static int64_t
+client_seek_proxy(struct archive_read_filter *self, int64_t offset, int whence)
+{
+ /* DO NOT use the skipper here! If we transparently handled
+ * forward seek here by using the skipper, that will break
+ * other libarchive code that assumes a successful forward
+ * seek means it can also seek backwards.
+ */
+ if (self->archive->client.seeker == NULL)
+ return (ARCHIVE_FAILED);
+ return (self->archive->client.seeker)(&self->archive->archive,
+ self->data, offset, whence);
+}
+
+static int
+client_close_proxy(struct archive_read_filter *self)
+{
+ int r = ARCHIVE_OK, r2;
+ unsigned int i;
+
+ if (self->archive->client.closer == NULL)
+ return (r);
+ for (i = 0; i < self->archive->client.nodes; i++)
+ {
+ r2 = (self->archive->client.closer)
+ ((struct archive *)self->archive,
+ self->archive->client.dataset[i].data);
+ if (r > r2)
+ r = r2;
+ }
+ return (r);
+}
+
+static int
+client_open_proxy(struct archive_read_filter *self)
+{
+ int r = ARCHIVE_OK;
+ if (self->archive->client.opener != NULL)
+ r = (self->archive->client.opener)(
+ (struct archive *)self->archive, self->data);
+ return (r);
+}
+
+static int
+client_switch_proxy(struct archive_read_filter *self, unsigned int iindex)
+{
+ int r1 = ARCHIVE_OK, r2 = ARCHIVE_OK;
+ void *data2 = NULL;
+
+ /* Don't do anything if already in the specified data node */
+ if (self->archive->client.cursor == iindex)
+ return (ARCHIVE_OK);
+
+ self->archive->client.cursor = iindex;
+ data2 = self->archive->client.dataset[self->archive->client.cursor].data;
+ if (self->archive->client.switcher != NULL)
+ {
+ r1 = r2 = (self->archive->client.switcher)
+ ((struct archive *)self->archive, self->data, data2);
+ self->data = data2;
+ }
+ else
+ {
+ /* Attempt to call close and open instead */
+ if (self->archive->client.closer != NULL)
+ r1 = (self->archive->client.closer)
+ ((struct archive *)self->archive, self->data);
+ self->data = data2;
+ if (self->archive->client.opener != NULL)
+ r2 = (self->archive->client.opener)
+ ((struct archive *)self->archive, self->data);
+ }
+ return (r1 < r2) ? r1 : r2;
+}
+
+int
+archive_read_set_open_callback(struct archive *_a,
+ archive_open_callback *client_opener)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_set_open_callback");
+ a->client.opener = client_opener;
+ return ARCHIVE_OK;
+}
+
+int
+archive_read_set_read_callback(struct archive *_a,
+ archive_read_callback *client_reader)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_set_read_callback");
+ a->client.reader = client_reader;
+ return ARCHIVE_OK;
+}
+
+int
+archive_read_set_skip_callback(struct archive *_a,
+ archive_skip_callback *client_skipper)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_set_skip_callback");
+ a->client.skipper = client_skipper;
+ return ARCHIVE_OK;
+}
+
+int
+archive_read_set_seek_callback(struct archive *_a,
+ archive_seek_callback *client_seeker)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_set_seek_callback");
+ a->client.seeker = client_seeker;
+ return ARCHIVE_OK;
+}
+
+int
+archive_read_set_close_callback(struct archive *_a,
+ archive_close_callback *client_closer)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_set_close_callback");
+ a->client.closer = client_closer;
+ return ARCHIVE_OK;
+}
+
+int
+archive_read_set_switch_callback(struct archive *_a,
+ archive_switch_callback *client_switcher)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_set_switch_callback");
+ a->client.switcher = client_switcher;
+ return ARCHIVE_OK;
+}
+
+int
+archive_read_set_callback_data(struct archive *_a, void *client_data)
+{
+ return archive_read_set_callback_data2(_a, client_data, 0);
+}
+
+int
+archive_read_set_callback_data2(struct archive *_a, void *client_data,
+ unsigned int iindex)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_set_callback_data2");
+
+ if (a->client.nodes == 0)
+ {
+ a->client.dataset = (struct archive_read_data_node *)
+ calloc(1, sizeof(*a->client.dataset));
+ if (a->client.dataset == NULL)
+ {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory.");
+ return ARCHIVE_FATAL;
+ }
+ a->client.nodes = 1;
+ }
+
+ if (iindex > a->client.nodes - 1)
+ {
+ archive_set_error(&a->archive, EINVAL,
+ "Invalid index specified.");
+ return ARCHIVE_FATAL;
+ }
+ a->client.dataset[iindex].data = client_data;
+ a->client.dataset[iindex].begin_position = -1;
+ a->client.dataset[iindex].total_size = -1;
+ return ARCHIVE_OK;
+}
+
+int
+archive_read_add_callback_data(struct archive *_a, void *client_data,
+ unsigned int iindex)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ void *p;
+ unsigned int i;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_add_callback_data");
+ if (iindex > a->client.nodes) {
+ archive_set_error(&a->archive, EINVAL,
+ "Invalid index specified.");
+ return ARCHIVE_FATAL;
+ }
+ p = realloc(a->client.dataset, sizeof(*a->client.dataset)
+ * (++(a->client.nodes)));
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory.");
+ return ARCHIVE_FATAL;
+ }
+ a->client.dataset = (struct archive_read_data_node *)p;
+ for (i = a->client.nodes - 1; i > iindex && i > 0; i--) {
+ a->client.dataset[i].data = a->client.dataset[i-1].data;
+ a->client.dataset[i].begin_position = -1;
+ a->client.dataset[i].total_size = -1;
+ }
+ a->client.dataset[iindex].data = client_data;
+ a->client.dataset[iindex].begin_position = -1;
+ a->client.dataset[iindex].total_size = -1;
+ return ARCHIVE_OK;
+}
+
+int
+archive_read_append_callback_data(struct archive *_a, void *client_data)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ return archive_read_add_callback_data(_a, client_data, a->client.nodes);
+}
+
+int
+archive_read_prepend_callback_data(struct archive *_a, void *client_data)
+{
+ return archive_read_add_callback_data(_a, client_data, 0);
+}
+
+int
+archive_read_open1(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter *filter, *tmp;
+ int slot, e;
+ unsigned int i;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_open");
+ archive_clear_error(&a->archive);
+
+ if (a->client.reader == NULL) {
+ archive_set_error(&a->archive, EINVAL,
+ "No reader function provided to archive_read_open");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Open data source. */
+ if (a->client.opener != NULL) {
+ e = (a->client.opener)(&a->archive, a->client.dataset[0].data);
+ if (e != 0) {
+ /* If the open failed, call the closer to clean up. */
+ if (a->client.closer) {
+ for (i = 0; i < a->client.nodes; i++)
+ (a->client.closer)(&a->archive,
+ a->client.dataset[i].data);
+ }
+ return (e);
+ }
+ }
+
+ filter = calloc(1, sizeof(*filter));
+ if (filter == NULL)
+ return (ARCHIVE_FATAL);
+ filter->bidder = NULL;
+ filter->upstream = NULL;
+ filter->archive = a;
+ filter->data = a->client.dataset[0].data;
+ filter->open = client_open_proxy;
+ filter->read = client_read_proxy;
+ filter->skip = client_skip_proxy;
+ filter->seek = client_seek_proxy;
+ filter->close = client_close_proxy;
+ filter->sswitch = client_switch_proxy;
+ filter->name = "none";
+ filter->code = ARCHIVE_FILTER_NONE;
+
+ a->client.dataset[0].begin_position = 0;
+ if (!a->filter || !a->bypass_filter_bidding)
+ {
+ a->filter = filter;
+ /* Build out the input pipeline. */
+ e = choose_filters(a);
+ if (e < ARCHIVE_WARN) {
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ }
+ else
+ {
+ /* Need to add "NONE" type filter at the end of the filter chain */
+ tmp = a->filter;
+ while (tmp->upstream)
+ tmp = tmp->upstream;
+ tmp->upstream = filter;
+ }
+
+ if (!a->format)
+ {
+ slot = choose_format(a);
+ if (slot < 0) {
+ __archive_read_close_filters(a);
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ a->format = &(a->formats[slot]);
+ }
+
+ a->archive.state = ARCHIVE_STATE_HEADER;
+
+ /* Ensure libarchive starts from the first node in a multivolume set */
+ client_switch_proxy(a->filter, 0);
+ return (e);
+}
+
+/*
+ * Allow each registered stream transform to bid on whether
+ * it wants to handle this stream. Repeat until we've finished
+ * building the pipeline.
+ */
+static int
+choose_filters(struct archive_read *a)
+{
+ int number_bidders, i, bid, best_bid;
+ struct archive_read_filter_bidder *bidder, *best_bidder;
+ struct archive_read_filter *filter;
+ ssize_t avail;
+ int r;
+
+ for (;;) {
+ number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);
+
+ best_bid = 0;
+ best_bidder = NULL;
+
+ bidder = a->bidders;
+ for (i = 0; i < number_bidders; i++, bidder++) {
+ if (bidder->bid != NULL) {
+ bid = (bidder->bid)(bidder, a->filter);
+ if (bid > best_bid) {
+ best_bid = bid;
+ best_bidder = bidder;
+ }
+ }
+ }
+
+ /* If no bidder, we're done. */
+ if (best_bidder == NULL) {
+ /* Verify the filter by asking it for some data. */
+ __archive_read_filter_ahead(a->filter, 1, &avail);
+ if (avail < 0) {
+ __archive_read_close_filters(a);
+ __archive_read_free_filters(a);
+ return (ARCHIVE_FATAL);
+ }
+ a->archive.compression_name = a->filter->name;
+ a->archive.compression_code = a->filter->code;
+ return (ARCHIVE_OK);
+ }
+
+ filter
+ = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+ if (filter == NULL)
+ return (ARCHIVE_FATAL);
+ filter->bidder = best_bidder;
+ filter->archive = a;
+ filter->upstream = a->filter;
+ a->filter = filter;
+ r = (best_bidder->init)(a->filter);
+ if (r != ARCHIVE_OK) {
+ __archive_read_close_filters(a);
+ __archive_read_free_filters(a);
+ return (ARCHIVE_FATAL);
+ }
+ }
+}
+
+/*
+ * Read header of next entry.
+ */
+static int
+_archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ int r1 = ARCHIVE_OK, r2;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_read_next_header");
+
+ archive_entry_clear(entry);
+ archive_clear_error(&a->archive);
+
+ /*
+ * If client didn't consume entire data, skip any remainder
+ * (This is especially important for GNU incremental directories.)
+ */
+ if (a->archive.state == ARCHIVE_STATE_DATA) {
+ r1 = archive_read_data_skip(&a->archive);
+ if (r1 == ARCHIVE_EOF)
+ archive_set_error(&a->archive, EIO,
+ "Premature end-of-file.");
+ if (r1 == ARCHIVE_EOF || r1 == ARCHIVE_FATAL) {
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ /* Record start-of-header offset in uncompressed stream. */
+ a->header_position = a->filter->position;
+
+ ++_a->file_count;
+ r2 = (a->format->read_header)(a, entry);
+
+ /*
+ * EOF and FATAL are persistent at this layer. By
+ * modifying the state, we guarantee that future calls to
+ * read a header or read data will fail.
+ */
+ switch (r2) {
+ case ARCHIVE_EOF:
+ a->archive.state = ARCHIVE_STATE_EOF;
+ --_a->file_count;/* Revert a file counter. */
+ break;
+ case ARCHIVE_OK:
+ a->archive.state = ARCHIVE_STATE_DATA;
+ break;
+ case ARCHIVE_WARN:
+ a->archive.state = ARCHIVE_STATE_DATA;
+ break;
+ case ARCHIVE_RETRY:
+ break;
+ case ARCHIVE_FATAL:
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ break;
+ }
+
+ a->read_data_output_offset = 0;
+ a->read_data_remaining = 0;
+ a->read_data_is_posix_read = 0;
+ a->read_data_requested = 0;
+ a->data_start_node = a->client.cursor;
+ /* EOF always wins; otherwise return the worst error. */
+ return (r2 < r1 || r2 == ARCHIVE_EOF) ? r2 : r1;
+}
+
+int
+_archive_read_next_header(struct archive *_a, struct archive_entry **entryp)
+{
+ int ret;
+ struct archive_read *a = (struct archive_read *)_a;
+ *entryp = NULL;
+ ret = _archive_read_next_header2(_a, a->entry);
+ *entryp = a->entry;
+ return ret;
+}
+
+/*
+ * Allow each registered format to bid on whether it wants to handle
+ * the next entry. Return index of winning bidder.
+ */
+static int
+choose_format(struct archive_read *a)
+{
+ int slots;
+ int i;
+ int bid, best_bid;
+ int best_bid_slot;
+
+ slots = sizeof(a->formats) / sizeof(a->formats[0]);
+ best_bid = -1;
+ best_bid_slot = -1;
+
+ /* Set up a->format for convenience of bidders. */
+ a->format = &(a->formats[0]);
+ for (i = 0; i < slots; i++, a->format++) {
+ if (a->format->bid) {
+ bid = (a->format->bid)(a, best_bid);
+ if (bid == ARCHIVE_FATAL)
+ return (ARCHIVE_FATAL);
+ if (a->filter->position != 0)
+ __archive_read_seek(a, 0, SEEK_SET);
+ if ((bid > best_bid) || (best_bid_slot < 0)) {
+ best_bid = bid;
+ best_bid_slot = i;
+ }
+ }
+ }
+
+ /*
+ * There were no bidders; this is a serious programmer error
+ * and demands a quick and definitive abort.
+ */
+ if (best_bid_slot < 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "No formats registered");
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * There were bidders, but no non-zero bids; this means we
+ * can't support this stream.
+ */
+ if (best_bid < 1) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unrecognized archive format");
+ return (ARCHIVE_FATAL);
+ }
+
+ return (best_bid_slot);
+}
+
+/*
+ * Return the file offset (within the uncompressed data stream) where
+ * the last header started.
+ */
+int64_t
+archive_read_header_position(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_header_position");
+ return (a->header_position);
+}
+
+/*
+ * Returns 1 if the archive contains at least one encrypted entry.
+ * If the archive format not support encryption at all
+ * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned.
+ * If for any other reason (e.g. not enough data read so far)
+ * we cannot say whether there are encrypted entries, then
+ * ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW is returned.
+ * In general, this function will return values below zero when the
+ * reader is uncertain or totally uncapable of encryption support.
+ * When this function returns 0 you can be sure that the reader
+ * supports encryption detection but no encrypted entries have
+ * been found yet.
+ *
+ * NOTE: If the metadata/header of an archive is also encrypted, you
+ * cannot rely on the number of encrypted entries. That is why this
+ * function does not return the number of encrypted entries but#
+ * just shows that there are some.
+ */
+int
+archive_read_has_encrypted_entries(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ int format_supports_encryption = archive_read_format_capabilities(_a)
+ & (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA | ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA);
+
+ if (!_a || !format_supports_encryption) {
+ /* Format in general doesn't support encryption */
+ return ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED;
+ }
+
+ /* A reader potentially has read enough data now. */
+ if (a->format && a->format->has_encrypted_entries) {
+ return (a->format->has_encrypted_entries)(a);
+ }
+
+ /* For any other reason we cannot say how many entries are there. */
+ return ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW;
+}
+
+/*
+ * Returns a bitmask of capabilities that are supported by the archive format reader.
+ * If the reader has no special capabilities, ARCHIVE_READ_FORMAT_CAPS_NONE is returned.
+ */
+int
+archive_read_format_capabilities(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ if (a && a->format && a->format->format_capabilties) {
+ return (a->format->format_capabilties)(a);
+ }
+ return ARCHIVE_READ_FORMAT_CAPS_NONE;
+}
+
+/*
+ * Read data from an archive entry, using a read(2)-style interface.
+ * This is a convenience routine that just calls
+ * archive_read_data_block and copies the results into the client
+ * buffer, filling any gaps with zero bytes. Clients using this
+ * API can be completely ignorant of sparse-file issues; sparse files
+ * will simply be padded with nulls.
+ *
+ * DO NOT intermingle calls to this function and archive_read_data_block
+ * to read a single entry body.
+ */
+ssize_t
+archive_read_data(struct archive *_a, void *buff, size_t s)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ char *dest;
+ const void *read_buf;
+ size_t bytes_read;
+ size_t len;
+ int r;
+
+ bytes_read = 0;
+ dest = (char *)buff;
+
+ while (s > 0) {
+ if (a->read_data_remaining == 0) {
+ 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,
+ &a->read_data_remaining, &a->read_data_offset);
+ a->read_data_block = read_buf;
+ if (r == ARCHIVE_EOF)
+ return (bytes_read);
+ /*
+ * Error codes are all negative, so the status
+ * return here cannot be confused with a valid
+ * byte count. (ARCHIVE_OK is zero.)
+ */
+ if (r < ARCHIVE_OK)
+ return (r);
+ }
+
+ if (a->read_data_offset < a->read_data_output_offset) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Encountered out-of-order sparse blocks");
+ return (ARCHIVE_RETRY);
+ }
+
+ /* Compute the amount of zero padding needed. */
+ if (a->read_data_output_offset + (int64_t)s <
+ a->read_data_offset) {
+ len = s;
+ } else if (a->read_data_output_offset <
+ a->read_data_offset) {
+ len = (size_t)(a->read_data_offset -
+ a->read_data_output_offset);
+ } else
+ len = 0;
+
+ /* Add zeroes. */
+ memset(dest, 0, len);
+ s -= len;
+ a->read_data_output_offset += len;
+ dest += len;
+ bytes_read += len;
+
+ /* Copy data if there is any space left. */
+ if (s > 0) {
+ len = a->read_data_remaining;
+ if (len > s)
+ len = s;
+ memcpy(dest, a->read_data_block, len);
+ s -= len;
+ a->read_data_block += len;
+ a->read_data_remaining -= len;
+ a->read_data_output_offset += len;
+ a->read_data_offset += len;
+ dest += len;
+ bytes_read += len;
+ }
+ }
+ a->read_data_is_posix_read = 0;
+ a->read_data_requested = 0;
+ return (bytes_read);
+}
+
+/*
+ * Skip over all remaining data in this entry.
+ */
+int
+archive_read_data_skip(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ int r;
+ const void *buff;
+ size_t size;
+ int64_t offset;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_data_skip");
+
+ if (a->format->read_data_skip != NULL)
+ r = (a->format->read_data_skip)(a);
+ else {
+ while ((r = archive_read_data_block(&a->archive,
+ &buff, &size, &offset))
+ == ARCHIVE_OK)
+ ;
+ }
+
+ if (r == ARCHIVE_EOF)
+ r = ARCHIVE_OK;
+
+ a->archive.state = ARCHIVE_STATE_HEADER;
+ return (r);
+}
+
+int64_t
+archive_seek_data(struct archive *_a, int64_t offset, int whence)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_seek_data_block");
+
+ if (a->format->seek_data == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "Internal error: "
+ "No format_seek_data_block function registered");
+ return (ARCHIVE_FATAL);
+ }
+
+ return (a->format->seek_data)(a, offset, whence);
+}
+
+/*
+ * Read the next block of entry data from the archive.
+ * This is a zero-copy interface; the client receives a pointer,
+ * size, and file offset of the next available block of data.
+ *
+ * Returns ARCHIVE_OK if the operation is successful, ARCHIVE_EOF if
+ * the end of entry is encountered.
+ */
+static int
+_archive_read_data_block(struct archive *_a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_data_block");
+
+ if (a->format->read_data == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "Internal error: "
+ "No format_read_data_block function registered");
+ return (ARCHIVE_FATAL);
+ }
+
+ return (a->format->read_data)(a, buff, size, offset);
+}
+
+int
+__archive_read_close_filters(struct archive_read *a)
+{
+ struct archive_read_filter *f = a->filter;
+ int r = ARCHIVE_OK;
+ /* Close each filter in the pipeline. */
+ while (f != NULL) {
+ struct archive_read_filter *t = f->upstream;
+ if (!f->closed && f->close != NULL) {
+ int r1 = (f->close)(f);
+ f->closed = 1;
+ if (r1 < r)
+ r = r1;
+ }
+ free(f->buffer);
+ f->buffer = NULL;
+ f = t;
+ }
+ return r;
+}
+
+void
+__archive_read_free_filters(struct archive_read *a)
+{
+ while (a->filter != NULL) {
+ struct archive_read_filter *t = a->filter->upstream;
+ free(a->filter);
+ a->filter = t;
+ }
+}
+
+/*
+ * return the count of # of filters in use
+ */
+static int
+_archive_filter_count(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter *p = a->filter;
+ int count = 0;
+ while(p) {
+ count++;
+ p = p->upstream;
+ }
+ return count;
+}
+
+/*
+ * Close the file and all I/O.
+ */
+static int
+_archive_read_close(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ int r = ARCHIVE_OK, r1 = ARCHIVE_OK;
+
+ archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_close");
+ if (a->archive.state == ARCHIVE_STATE_CLOSED)
+ return (ARCHIVE_OK);
+ archive_clear_error(&a->archive);
+ a->archive.state = ARCHIVE_STATE_CLOSED;
+
+ /* TODO: Clean up the formatters. */
+
+ /* Release the filter objects. */
+ r1 = __archive_read_close_filters(a);
+ if (r1 < r)
+ r = r1;
+
+ return (r);
+}
+
+/*
+ * Release memory and other resources.
+ */
+static int
+_archive_read_free(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ int i, n;
+ int slots;
+ int r = ARCHIVE_OK;
+
+ if (_a == NULL)
+ return (ARCHIVE_OK);
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_free");
+ if (a->archive.state != ARCHIVE_STATE_CLOSED
+ && a->archive.state != ARCHIVE_STATE_FATAL)
+ r = archive_read_close(&a->archive);
+
+ /* Call cleanup functions registered by optional components. */
+ if (a->cleanup_archive_extract != NULL)
+ r = (a->cleanup_archive_extract)(a);
+
+ /* Cleanup format-specific data. */
+ slots = sizeof(a->formats) / sizeof(a->formats[0]);
+ for (i = 0; i < slots; i++) {
+ a->format = &(a->formats[i]);
+ if (a->formats[i].cleanup)
+ (a->formats[i].cleanup)(a);
+ }
+
+ /* Free the filters */
+ __archive_read_free_filters(a);
+
+ /* Release the bidder objects. */
+ n = sizeof(a->bidders)/sizeof(a->bidders[0]);
+ for (i = 0; i < n; i++) {
+ if (a->bidders[i].free != NULL) {
+ int r1 = (a->bidders[i].free)(&a->bidders[i]);
+ if (r1 < r)
+ r = r1;
+ }
+ }
+
+ archive_string_free(&a->archive.error_string);
+ if (a->entry)
+ archive_entry_free(a->entry);
+ a->archive.magic = 0;
+ __archive_clean(&a->archive);
+ free(a->client.dataset);
+ free(a);
+ return (r);
+}
+
+static struct archive_read_filter *
+get_filter(struct archive *_a, int n)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter *f = a->filter;
+ /* We use n == -1 for 'the last filter', which is always the
+ * client proxy. */
+ if (n == -1 && f != NULL) {
+ struct archive_read_filter *last = f;
+ f = f->upstream;
+ while (f != NULL) {
+ last = f;
+ f = f->upstream;
+ }
+ return (last);
+ }
+ if (n < 0)
+ return NULL;
+ while (n > 0 && f != NULL) {
+ f = f->upstream;
+ --n;
+ }
+ return (f);
+}
+
+static int
+_archive_filter_code(struct archive *_a, int n)
+{
+ struct archive_read_filter *f = get_filter(_a, n);
+ return f == NULL ? -1 : f->code;
+}
+
+static const char *
+_archive_filter_name(struct archive *_a, int n)
+{
+ struct archive_read_filter *f = get_filter(_a, n);
+ return f != NULL ? f->name : NULL;
+}
+
+static int64_t
+_archive_filter_bytes(struct archive *_a, int n)
+{
+ struct archive_read_filter *f = get_filter(_a, n);
+ return f == NULL ? -1 : f->position;
+}
+
+/*
+ * Used internally by read format handlers to register their bid and
+ * initialization functions.
+ */
+int
+__archive_read_register_format(struct archive_read *a,
+ void *format_data,
+ const char *name,
+ int (*bid)(struct archive_read *, int),
+ int (*options)(struct archive_read *, const char *, const char *),
+ int (*read_header)(struct archive_read *, struct archive_entry *),
+ int (*read_data)(struct archive_read *, const void **, size_t *, int64_t *),
+ int (*read_data_skip)(struct archive_read *),
+ int64_t (*seek_data)(struct archive_read *, int64_t, int),
+ int (*cleanup)(struct archive_read *),
+ int (*format_capabilities)(struct archive_read *),
+ int (*has_encrypted_entries)(struct archive_read *))
+{
+ int i, number_slots;
+
+ archive_check_magic(&a->archive,
+ ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "__archive_read_register_format");
+
+ number_slots = sizeof(a->formats) / sizeof(a->formats[0]);
+
+ for (i = 0; i < number_slots; i++) {
+ if (a->formats[i].bid == bid)
+ return (ARCHIVE_WARN); /* We've already installed */
+ if (a->formats[i].bid == NULL) {
+ a->formats[i].bid = bid;
+ a->formats[i].options = options;
+ a->formats[i].read_header = read_header;
+ a->formats[i].read_data = read_data;
+ a->formats[i].read_data_skip = read_data_skip;
+ a->formats[i].seek_data = seek_data;
+ a->formats[i].cleanup = cleanup;
+ a->formats[i].data = format_data;
+ a->formats[i].name = name;
+ a->formats[i].format_capabilties = format_capabilities;
+ a->formats[i].has_encrypted_entries = has_encrypted_entries;
+ return (ARCHIVE_OK);
+ }
+ }
+
+ archive_set_error(&a->archive, ENOMEM,
+ "Not enough slots for format registration");
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Used internally by decompression routines to register their bid and
+ * initialization functions.
+ */
+int
+__archive_read_get_bidder(struct archive_read *a,
+ struct archive_read_filter_bidder **bidder)
+{
+ int i, number_slots;
+
+ number_slots = sizeof(a->bidders) / sizeof(a->bidders[0]);
+
+ for (i = 0; i < number_slots; i++) {
+ if (a->bidders[i].bid == NULL) {
+ memset(a->bidders + i, 0, sizeof(a->bidders[0]));
+ *bidder = (a->bidders + i);
+ return (ARCHIVE_OK);
+ }
+ }
+
+ archive_set_error(&a->archive, ENOMEM,
+ "Not enough slots for filter registration");
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * The next section implements the peek/consume internal I/O
+ * system used by archive readers. This system allows simple
+ * read-ahead for consumers while preserving zero-copy operation
+ * most of the time.
+ *
+ * The two key operations:
+ * * The read-ahead function returns a pointer to a block of data
+ * that satisfies a minimum request.
+ * * The consume function advances the file pointer.
+ *
+ * In the ideal case, filters generate blocks of data
+ * and __archive_read_ahead() just returns pointers directly into
+ * those blocks. Then __archive_read_consume() just bumps those
+ * pointers. Only if your request would span blocks does the I/O
+ * layer use a copy buffer to provide you with a contiguous block of
+ * data.
+ *
+ * A couple of useful idioms:
+ * * "I just want some data." Ask for 1 byte and pay attention to
+ * the "number of bytes available" from __archive_read_ahead().
+ * Consume whatever you actually use.
+ * * "I want to output a large block of data." As above, ask for 1 byte,
+ * emit all that's available (up to whatever limit you have), consume
+ * it all, then repeat until you're done. This effectively means that
+ * you're passing along the blocks that came from your provider.
+ * * "I want to peek ahead by a large amount." Ask for 4k or so, then
+ * double and repeat until you get an error or have enough. Note
+ * that the I/O layer will likely end up expanding its copy buffer
+ * to fit your request, so use this technique cautiously. This
+ * technique is used, for example, by some of the format tasting
+ * code that has uncertain look-ahead needs.
+ */
+
+/*
+ * Looks ahead in the input stream:
+ * * If 'avail' pointer is provided, that returns number of bytes available
+ * in the current buffer, which may be much larger than requested.
+ * * If end-of-file, *avail gets set to zero.
+ * * If error, *avail gets error code.
+ * * If request can be met, returns pointer to data.
+ * * If minimum request cannot be met, returns NULL.
+ *
+ * Note: If you just want "some data", ask for 1 byte and pay attention
+ * to *avail, which will have the actual amount available. If you
+ * know exactly how many bytes you need, just ask for that and treat
+ * a NULL return as an error.
+ *
+ * Important: This does NOT move the file pointer. See
+ * __archive_read_consume() below.
+ */
+const void *
+__archive_read_ahead(struct archive_read *a, size_t min, ssize_t *avail)
+{
+ return (__archive_read_filter_ahead(a->filter, min, avail));
+}
+
+const void *
+__archive_read_filter_ahead(struct archive_read_filter *filter,
+ size_t min, ssize_t *avail)
+{
+ ssize_t bytes_read;
+ size_t tocopy;
+
+ if (filter->fatal) {
+ if (avail)
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+
+ /*
+ * Keep pulling more data until we can satisfy the request.
+ */
+ for (;;) {
+
+ /*
+ * If we can satisfy from the copy buffer (and the
+ * copy buffer isn't empty), we're done. In particular,
+ * note that min == 0 is a perfectly well-defined
+ * request.
+ */
+ if (filter->avail >= min && filter->avail > 0) {
+ if (avail != NULL)
+ *avail = filter->avail;
+ return (filter->next);
+ }
+
+ /*
+ * We can satisfy directly from client buffer if everything
+ * currently in the copy buffer is still in the client buffer.
+ */
+ if (filter->client_total >= filter->client_avail + filter->avail
+ && filter->client_avail + filter->avail >= min) {
+ /* "Roll back" to client buffer. */
+ filter->client_avail += filter->avail;
+ filter->client_next -= filter->avail;
+ /* Copy buffer is now empty. */
+ filter->avail = 0;
+ filter->next = filter->buffer;
+ /* Return data from client buffer. */
+ if (avail != NULL)
+ *avail = filter->client_avail;
+ return (filter->client_next);
+ }
+
+ /* Move data forward in copy buffer if necessary. */
+ if (filter->next > filter->buffer &&
+ filter->next + min > filter->buffer + filter->buffer_size) {
+ if (filter->avail > 0)
+ memmove(filter->buffer, filter->next,
+ filter->avail);
+ filter->next = filter->buffer;
+ }
+
+ /* If we've used up the client data, get more. */
+ if (filter->client_avail <= 0) {
+ if (filter->end_of_file) {
+ if (avail != NULL)
+ *avail = 0;
+ return (NULL);
+ }
+ bytes_read = (filter->read)(filter,
+ &filter->client_buff);
+ if (bytes_read < 0) { /* Read error. */
+ filter->client_total = filter->client_avail = 0;
+ filter->client_next =
+ filter->client_buff = NULL;
+ filter->fatal = 1;
+ if (avail != NULL)
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ if (bytes_read == 0) {
+ /* Check for another client object first */
+ if (filter->archive->client.cursor !=
+ filter->archive->client.nodes - 1) {
+ if (client_switch_proxy(filter,
+ filter->archive->client.cursor + 1)
+ == ARCHIVE_OK)
+ continue;
+ }
+ /* Premature end-of-file. */
+ filter->client_total = filter->client_avail = 0;
+ filter->client_next =
+ filter->client_buff = NULL;
+ filter->end_of_file = 1;
+ /* Return whatever we do have. */
+ if (avail != NULL)
+ *avail = filter->avail;
+ return (NULL);
+ }
+ filter->client_total = bytes_read;
+ filter->client_avail = filter->client_total;
+ filter->client_next = filter->client_buff;
+ } else {
+ /*
+ * We can't satisfy the request from the copy
+ * buffer or the existing client data, so we
+ * need to copy more client data over to the
+ * copy buffer.
+ */
+
+ /* Ensure the buffer is big enough. */
+ if (min > filter->buffer_size) {
+ size_t s, t;
+ char *p;
+
+ /* Double the buffer; watch for overflow. */
+ s = t = filter->buffer_size;
+ if (s == 0)
+ s = min;
+ while (s < min) {
+ t *= 2;
+ if (t <= s) { /* Integer overflow! */
+ archive_set_error(
+ &filter->archive->archive,
+ ENOMEM,
+ "Unable to allocate copy"
+ " buffer");
+ filter->fatal = 1;
+ if (avail != NULL)
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ s = t;
+ }
+ /* Now s >= min, so allocate a new buffer. */
+ p = (char *)malloc(s);
+ if (p == NULL) {
+ archive_set_error(
+ &filter->archive->archive,
+ ENOMEM,
+ "Unable to allocate copy buffer");
+ filter->fatal = 1;
+ if (avail != NULL)
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ /* Move data into newly-enlarged buffer. */
+ if (filter->avail > 0)
+ memmove(p, filter->next, filter->avail);
+ free(filter->buffer);
+ filter->next = filter->buffer = p;
+ filter->buffer_size = s;
+ }
+
+ /* We can add client data to copy buffer. */
+ /* First estimate: copy to fill rest of buffer. */
+ tocopy = (filter->buffer + filter->buffer_size)
+ - (filter->next + filter->avail);
+ /* Don't waste time buffering more than we need to. */
+ if (tocopy + filter->avail > min)
+ tocopy = min - filter->avail;
+ /* Don't copy more than is available. */
+ if (tocopy > filter->client_avail)
+ tocopy = filter->client_avail;
+
+ memcpy(filter->next + filter->avail,
+ filter->client_next, tocopy);
+ /* Remove this data from client buffer. */
+ filter->client_next += tocopy;
+ filter->client_avail -= tocopy;
+ /* add it to copy buffer. */
+ filter->avail += tocopy;
+ }
+ }
+}
+
+/*
+ * Move the file pointer forward.
+ */
+int64_t
+__archive_read_consume(struct archive_read *a, int64_t request)
+{
+ return (__archive_read_filter_consume(a->filter, request));
+}
+
+int64_t
+__archive_read_filter_consume(struct archive_read_filter * filter,
+ int64_t request)
+{
+ int64_t skipped;
+
+ if (request == 0)
+ return 0;
+
+ skipped = advance_file_pointer(filter, request);
+ if (skipped == request)
+ return (skipped);
+ /* We hit EOF before we satisfied the skip request. */
+ if (skipped < 0) /* Map error code to 0 for error message below. */
+ skipped = 0;
+ archive_set_error(&filter->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Truncated input file (needed %jd bytes, only %jd available)",
+ (intmax_t)request, (intmax_t)skipped);
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Advance the file pointer by the amount requested.
+ * Returns the amount actually advanced, which may be less than the
+ * request if EOF is encountered first.
+ * Returns a negative value if there's an I/O error.
+ */
+static int64_t
+advance_file_pointer(struct archive_read_filter *filter, int64_t request)
+{
+ int64_t bytes_skipped, total_bytes_skipped = 0;
+ ssize_t bytes_read;
+ size_t min;
+
+ if (filter->fatal)
+ return (-1);
+
+ /* Use up the copy buffer first. */
+ if (filter->avail > 0) {
+ min = (size_t)minimum(request, (int64_t)filter->avail);
+ filter->next += min;
+ filter->avail -= min;
+ request -= min;
+ filter->position += min;
+ total_bytes_skipped += min;
+ }
+
+ /* Then use up the client buffer. */
+ if (filter->client_avail > 0) {
+ min = (size_t)minimum(request, (int64_t)filter->client_avail);
+ filter->client_next += min;
+ filter->client_avail -= min;
+ request -= min;
+ filter->position += min;
+ total_bytes_skipped += min;
+ }
+ if (request == 0)
+ return (total_bytes_skipped);
+
+ /* If there's an optimized skip function, use it. */
+ if (filter->skip != NULL) {
+ bytes_skipped = (filter->skip)(filter, request);
+ if (bytes_skipped < 0) { /* error */
+ filter->fatal = 1;
+ return (bytes_skipped);
+ }
+ filter->position += bytes_skipped;
+ total_bytes_skipped += bytes_skipped;
+ request -= bytes_skipped;
+ if (request == 0)
+ return (total_bytes_skipped);
+ }
+
+ /* Use ordinary reads as necessary to complete the request. */
+ for (;;) {
+ bytes_read = (filter->read)(filter, &filter->client_buff);
+ if (bytes_read < 0) {
+ filter->client_buff = NULL;
+ filter->fatal = 1;
+ return (bytes_read);
+ }
+
+ if (bytes_read == 0) {
+ if (filter->archive->client.cursor !=
+ filter->archive->client.nodes - 1) {
+ if (client_switch_proxy(filter,
+ filter->archive->client.cursor + 1)
+ == ARCHIVE_OK)
+ continue;
+ }
+ filter->client_buff = NULL;
+ filter->end_of_file = 1;
+ return (total_bytes_skipped);
+ }
+
+ if (bytes_read >= request) {
+ filter->client_next =
+ ((const char *)filter->client_buff) + request;
+ filter->client_avail = (size_t)(bytes_read - request);
+ filter->client_total = bytes_read;
+ total_bytes_skipped += request;
+ filter->position += request;
+ return (total_bytes_skipped);
+ }
+
+ filter->position += bytes_read;
+ total_bytes_skipped += bytes_read;
+ request -= bytes_read;
+ }
+}
+
+/**
+ * Returns ARCHIVE_FAILED if seeking isn't supported.
+ */
+int64_t
+__archive_read_seek(struct archive_read *a, int64_t offset, int whence)
+{
+ return __archive_read_filter_seek(a->filter, offset, whence);
+}
+
+int64_t
+__archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset,
+ int whence)
+{
+ struct archive_read_client *client;
+ int64_t r;
+ unsigned int cursor;
+
+ if (filter->closed || filter->fatal)
+ return (ARCHIVE_FATAL);
+ if (filter->seek == NULL)
+ return (ARCHIVE_FAILED);
+
+ client = &(filter->archive->client);
+ switch (whence) {
+ case SEEK_CUR:
+ /* Adjust the offset and use SEEK_SET instead */
+ offset += filter->position;
+ case SEEK_SET:
+ cursor = 0;
+ while (1)
+ {
+ if (client->dataset[cursor].begin_position < 0 ||
+ client->dataset[cursor].total_size < 0 ||
+ client->dataset[cursor].begin_position +
+ client->dataset[cursor].total_size - 1 > offset ||
+ cursor + 1 >= client->nodes)
+ break;
+ r = client->dataset[cursor].begin_position +
+ client->dataset[cursor].total_size;
+ client->dataset[++cursor].begin_position = r;
+ }
+ while (1) {
+ r = client_switch_proxy(filter, cursor);
+ if (r != ARCHIVE_OK)
+ return r;
+ if ((r = client_seek_proxy(filter, 0, SEEK_END)) < 0)
+ return r;
+ client->dataset[cursor].total_size = r;
+ if (client->dataset[cursor].begin_position +
+ client->dataset[cursor].total_size - 1 > offset ||
+ cursor + 1 >= client->nodes)
+ break;
+ r = client->dataset[cursor].begin_position +
+ client->dataset[cursor].total_size;
+ client->dataset[++cursor].begin_position = r;
+ }
+ offset -= client->dataset[cursor].begin_position;
+ if (offset < 0
+ || offset > client->dataset[cursor].total_size)
+ return ARCHIVE_FATAL;
+ if ((r = client_seek_proxy(filter, offset, SEEK_SET)) < 0)
+ return r;
+ break;
+
+ case SEEK_END:
+ cursor = 0;
+ while (1) {
+ if (client->dataset[cursor].begin_position < 0 ||
+ client->dataset[cursor].total_size < 0 ||
+ cursor + 1 >= client->nodes)
+ break;
+ r = client->dataset[cursor].begin_position +
+ client->dataset[cursor].total_size;
+ client->dataset[++cursor].begin_position = r;
+ }
+ while (1) {
+ r = client_switch_proxy(filter, cursor);
+ if (r != ARCHIVE_OK)
+ return r;
+ if ((r = client_seek_proxy(filter, 0, SEEK_END)) < 0)
+ return r;
+ client->dataset[cursor].total_size = r;
+ r = client->dataset[cursor].begin_position +
+ client->dataset[cursor].total_size;
+ if (cursor + 1 >= client->nodes)
+ break;
+ client->dataset[++cursor].begin_position = r;
+ }
+ while (1) {
+ if (r + offset >=
+ client->dataset[cursor].begin_position)
+ break;
+ offset += client->dataset[cursor].total_size;
+ if (cursor == 0)
+ break;
+ cursor--;
+ r = client->dataset[cursor].begin_position +
+ client->dataset[cursor].total_size;
+ }
+ offset = (r + offset) - client->dataset[cursor].begin_position;
+ if ((r = client_switch_proxy(filter, cursor)) != ARCHIVE_OK)
+ return r;
+ r = client_seek_proxy(filter, offset, SEEK_SET);
+ if (r < ARCHIVE_OK)
+ return r;
+ break;
+
+ default:
+ return (ARCHIVE_FATAL);
+ }
+ r += client->dataset[cursor].begin_position;
+
+ if (r >= 0) {
+ /*
+ * Ouch. Clearing the buffer like this hurts, especially
+ * at bid time. A lot of our efficiency at bid time comes
+ * from having bidders reuse the data we've already read.
+ *
+ * TODO: If the seek request is in data we already
+ * have, then don't call the seek callback.
+ *
+ * TODO: Zip seeks to end-of-file at bid time. If
+ * other formats also start doing this, we may need to
+ * find a way for clients to fudge the seek offset to
+ * a block boundary.
+ *
+ * Hmmm... If whence was SEEK_END, we know the file
+ * size is (r - offset). Can we use that to simplify
+ * the TODO items above?
+ */
+ filter->avail = filter->client_avail = 0;
+ filter->next = filter->buffer;
+ filter->position = r;
+ filter->end_of_file = 0;
+ }
+ return r;
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c b/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c
new file mode 100644
index 0000000000..017d7c68a4
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c
@@ -0,0 +1,198 @@
+/*-
+ * Copyright (c) 2003-2012 Tim Kientzle
+ * 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.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+int
+archive_read_append_filter(struct archive *_a, int code)
+{
+ int r1, r2, number_bidders, i;
+ char str[20];
+ struct archive_read_filter_bidder *bidder;
+ struct archive_read_filter *filter;
+ struct archive_read *a = (struct archive_read *)_a;
+
+ r1 = r2 = (ARCHIVE_OK);
+ switch (code)
+ {
+ case ARCHIVE_FILTER_NONE:
+ /* No filter to add, so do nothing.
+ * NOTE: An initial "NONE" type filter is always set at the end of the
+ * filter chain.
+ */
+ r1 = (ARCHIVE_OK);
+ break;
+ case ARCHIVE_FILTER_GZIP:
+ strcpy(str, "gzip");
+ r1 = archive_read_support_filter_gzip(_a);
+ break;
+ case ARCHIVE_FILTER_BZIP2:
+ strcpy(str, "bzip2");
+ r1 = archive_read_support_filter_bzip2(_a);
+ break;
+ case ARCHIVE_FILTER_COMPRESS:
+ strcpy(str, "compress (.Z)");
+ r1 = archive_read_support_filter_compress(_a);
+ break;
+ case ARCHIVE_FILTER_PROGRAM:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "Cannot append program filter using archive_read_append_filter");
+ return (ARCHIVE_FATAL);
+ case ARCHIVE_FILTER_LZMA:
+ strcpy(str, "lzma");
+ r1 = archive_read_support_filter_lzma(_a);
+ break;
+ case ARCHIVE_FILTER_XZ:
+ strcpy(str, "xz");
+ r1 = archive_read_support_filter_xz(_a);
+ break;
+ case ARCHIVE_FILTER_UU:
+ strcpy(str, "uu");
+ r1 = archive_read_support_filter_uu(_a);
+ break;
+ case ARCHIVE_FILTER_RPM:
+ strcpy(str, "rpm");
+ r1 = archive_read_support_filter_rpm(_a);
+ break;
+ case ARCHIVE_FILTER_LZIP:
+ strcpy(str, "lzip");
+ r1 = archive_read_support_filter_lzip(_a);
+ break;
+ case ARCHIVE_FILTER_LRZIP:
+ strcpy(str, "lrzip");
+ r1 = archive_read_support_filter_lrzip(_a);
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "Invalid filter code specified");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (code != ARCHIVE_FILTER_NONE)
+ {
+ number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);
+
+ bidder = a->bidders;
+ for (i = 0; i < number_bidders; i++, bidder++)
+ {
+ if (!bidder->name || !strcmp(bidder->name, str))
+ break;
+ }
+ if (!bidder->name || strcmp(bidder->name, str))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "Internal error: Unable to append filter");
+ return (ARCHIVE_FATAL);
+ }
+
+ filter
+ = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+ if (filter == NULL)
+ {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ filter->bidder = bidder;
+ filter->archive = a;
+ filter->upstream = a->filter;
+ a->filter = filter;
+ r2 = (bidder->init)(a->filter);
+ if (r2 != ARCHIVE_OK) {
+ __archive_read_close_filters(a);
+ __archive_read_free_filters(a);
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ a->bypass_filter_bidding = 1;
+ return (r1 < r2) ? r1 : r2;
+}
+
+int
+archive_read_append_filter_program(struct archive *_a, const char *cmd)
+{
+ return (archive_read_append_filter_program_signature(_a, cmd, NULL, 0));
+}
+
+int
+archive_read_append_filter_program_signature(struct archive *_a,
+ const char *cmd, const void *signature, size_t signature_len)
+{
+ int r, number_bidders, i;
+ struct archive_read_filter_bidder *bidder;
+ struct archive_read_filter *filter;
+ struct archive_read *a = (struct archive_read *)_a;
+
+ if (archive_read_support_filter_program_signature(_a, cmd, signature,
+ signature_len) != (ARCHIVE_OK))
+ return (ARCHIVE_FATAL);
+
+ number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);
+
+ bidder = a->bidders;
+ for (i = 0; i < number_bidders; i++, bidder++)
+ {
+ /* Program bidder name set to filter name after initialization */
+ if (bidder->data && !bidder->name)
+ break;
+ }
+ if (!bidder->data)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "Internal error: Unable to append program filter");
+ return (ARCHIVE_FATAL);
+ }
+
+ filter
+ = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+ if (filter == NULL)
+ {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ filter->bidder = bidder;
+ filter->archive = a;
+ filter->upstream = a->filter;
+ a->filter = filter;
+ r = (bidder->init)(a->filter);
+ if (r != ARCHIVE_OK) {
+ __archive_read_close_filters(a);
+ __archive_read_free_filters(a);
+ return (ARCHIVE_FATAL);
+ }
+ bidder->name = a->filter->name;
+
+ a->bypass_filter_bidding = 1;
+ return r;
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_data.3 b/Utilities/cmlibarchive/libarchive/archive_read_data.3
new file mode 100644
index 0000000000..bf0578ce37
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_data.3
@@ -0,0 +1,130 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_DATA 3
+.Os
+.Sh NAME
+.Nm archive_read_data
+.Nm archive_read_data_block ,
+.Nm archive_read_data_skip ,
+.Nm archive_read_data_into_fd
+.Nd functions for reading streaming archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft ssize_t
+.Fn archive_read_data "struct archive *" "void *buff" "size_t len"
+.Ft int
+.Fo archive_read_data_block
+.Fa "struct archive *"
+.Fa "const void **buff"
+.Fa "size_t *len"
+.Fa "off_t *offset"
+.Fc
+.Ft int
+.Fn archive_read_data_skip "struct archive *"
+.Ft int
+.Fn archive_read_data_into_fd "struct archive *" "int fd"
+.\"
+.Sh DESCRIPTION
+.Bl -tag -compact -width indent
+.It Fn archive_read_data
+Read data associated with the header just read.
+Internally, this is a convenience function that calls
+.Fn archive_read_data_block
+and fills any gaps with nulls so that callers see a single
+continuous stream of data.
+.It Fn archive_read_data_block
+Return the next available block of data for this entry.
+Unlike
+.Fn archive_read_data ,
+the
+.Fn archive_read_data_block
+function avoids copying data and allows you to correctly handle
+sparse files, as supported by some archive formats.
+The library guarantees that offsets will increase and that blocks
+will not overlap.
+Note that the blocks returned from this function can be much larger
+than the block size read from disk, due to compression
+and internal buffer optimizations.
+.It Fn archive_read_data_skip
+A convenience function that repeatedly calls
+.Fn archive_read_data_block
+to skip all of the data for this archive entry.
+Note that this function is invoked automatically by
+.Fn archive_read_next_header2
+if the previous entry was not completely consumed.
+.It Fn archive_read_data_into_fd
+A convenience function that repeatedly calls
+.Fn archive_read_data_block
+to copy the entire entry to the provided file descriptor.
+.El
+.\"
+.Sh RETURN VALUES
+Most functions return zero on success, non-zero on error.
+The possible return codes include:
+.Cm ARCHIVE_OK
+(the operation succeeded),
+.Cm ARCHIVE_WARN
+(the operation succeeded but a non-critical error was encountered),
+.Cm ARCHIVE_EOF
+(end-of-archive was encountered),
+.Cm ARCHIVE_RETRY
+(the operation failed but can be retried),
+and
+.Cm ARCHIVE_FATAL
+(there was a fatal error; the archive should be closed immediately).
+.Pp
+.Fn archive_read_data
+returns a count of bytes actually read or zero at the end of the entry.
+On error, a value of
+.Cm ARCHIVE_FATAL ,
+.Cm ARCHIVE_WARN ,
+or
+.Cm ARCHIVE_RETRY
+is returned.
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_read 3 ,
+.Xr archive_read_extract 3 ,
+.Xr archive_read_filter 3 ,
+.Xr archive_read_format 3 ,
+.Xr archive_read_header 3 ,
+.Xr archive_read_open 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_util 3 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_data_into_fd.c b/Utilities/cmlibarchive/libarchive/archive_read_data_into_fd.c
new file mode 100644
index 0000000000..b4398f1ecc
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_data_into_fd.c
@@ -0,0 +1,139 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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: src/lib/libarchive/archive_read_data_into_fd.c,v 1.16 2008/05/23 05:01:29 cperciva Exp $");
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+
+/* Maximum amount of data to write at one time. */
+#define MAX_WRITE (1024 * 1024)
+
+/*
+ * This implementation minimizes copying of data and is sparse-file aware.
+ */
+static int
+pad_to(struct archive *a, int fd, int can_lseek,
+ size_t nulls_size, const char *nulls,
+ int64_t target_offset, int64_t actual_offset)
+{
+ size_t to_write;
+ ssize_t bytes_written;
+
+ if (can_lseek) {
+ actual_offset = lseek(fd,
+ target_offset - actual_offset, SEEK_CUR);
+ if (actual_offset != target_offset) {
+ archive_set_error(a, errno, "Seek error");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+ }
+ while (target_offset > actual_offset) {
+ to_write = nulls_size;
+ if (target_offset < actual_offset + (int64_t)nulls_size)
+ to_write = (size_t)(target_offset - actual_offset);
+ bytes_written = write(fd, nulls, to_write);
+ if (bytes_written < 0) {
+ archive_set_error(a, errno, "Write error");
+ return (ARCHIVE_FATAL);
+ }
+ actual_offset += bytes_written;
+ }
+ return (ARCHIVE_OK);
+}
+
+
+int
+archive_read_data_into_fd(struct archive *a, int fd)
+{
+ struct stat st;
+ int r, r2;
+ const void *buff;
+ size_t size, bytes_to_write;
+ ssize_t bytes_written;
+ int64_t target_offset;
+ int64_t actual_offset = 0;
+ int can_lseek;
+ char *nulls = NULL;
+ size_t nulls_size = 16384;
+
+ archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_data_into_fd");
+
+ can_lseek = (fstat(fd, &st) == 0) && S_ISREG(st.st_mode);
+ if (!can_lseek)
+ nulls = calloc(1, nulls_size);
+
+ while ((r = archive_read_data_block(a, &buff, &size, &target_offset)) ==
+ ARCHIVE_OK) {
+ const char *p = buff;
+ if (target_offset > actual_offset) {
+ r = pad_to(a, fd, can_lseek, nulls_size, nulls,
+ target_offset, actual_offset);
+ if (r != ARCHIVE_OK)
+ break;
+ actual_offset = target_offset;
+ }
+ while (size > 0) {
+ bytes_to_write = size;
+ if (bytes_to_write > MAX_WRITE)
+ bytes_to_write = MAX_WRITE;
+ bytes_written = write(fd, p, bytes_to_write);
+ if (bytes_written < 0) {
+ archive_set_error(a, errno, "Write error");
+ r = ARCHIVE_FATAL;
+ goto cleanup;
+ }
+ actual_offset += bytes_written;
+ p += bytes_written;
+ size -= bytes_written;
+ }
+ }
+
+ if (r == ARCHIVE_EOF && target_offset > actual_offset) {
+ r2 = pad_to(a, fd, can_lseek, nulls_size, nulls,
+ target_offset, actual_offset);
+ if (r2 != ARCHIVE_OK)
+ r = r2;
+ }
+
+cleanup:
+ free(nulls);
+ if (r != ARCHIVE_EOF)
+ return (r);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk.3 b/Utilities/cmlibarchive/libarchive/archive_read_disk.3
new file mode 100644
index 0000000000..525dc59cb4
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk.3
@@ -0,0 +1,317 @@
+.\" Copyright (c) 2003-2009 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_DISK 3
+.Os
+.Sh NAME
+.Nm archive_read_disk_new ,
+.Nm archive_read_disk_set_symlink_logical ,
+.Nm archive_read_disk_set_symlink_physical ,
+.Nm archive_read_disk_set_symlink_hybrid ,
+.Nm archive_read_disk_entry_from_file ,
+.Nm archive_read_disk_gname ,
+.Nm archive_read_disk_uname ,
+.Nm archive_read_disk_set_uname_lookup ,
+.Nm archive_read_disk_set_gname_lookup ,
+.Nm archive_read_disk_set_standard_lookup ,
+.Nm archive_read_close ,
+.Nm archive_read_finish ,
+.Nm archive_read_free
+.Nd functions for reading objects from disk
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft struct archive *
+.Fn archive_read_disk_new "void"
+.Ft int
+.Fn archive_read_disk_set_symlink_logical "struct archive *"
+.Ft int
+.Fn archive_read_disk_set_symlink_physical "struct archive *"
+.Ft int
+.Fn archive_read_disk_set_symlink_hybrid "struct archive *"
+.Ft int
+.Fn archive_read_disk_gname "struct archive *" "gid_t"
+.Ft int
+.Fn archive_read_disk_uname "struct archive *" "uid_t"
+.Ft int
+.Fo archive_read_disk_set_gname_lookup
+.Fa "struct archive *"
+.Fa "void *"
+.Fa "const char *(*lookup)(void *, gid_t)"
+.Fa "void (*cleanup)(void *)"
+.Fc
+.Ft int
+.Fo archive_read_disk_set_uname_lookup
+.Fa "struct archive *"
+.Fa "void *"
+.Fa "const char *(*lookup)(void *, uid_t)"
+.Fa "void (*cleanup)(void *)"
+.Fc
+.Ft int
+.Fn archive_read_disk_set_standard_lookup "struct archive *"
+.Ft int
+.Fo archive_read_disk_entry_from_file
+.Fa "struct archive *"
+.Fa "struct archive_entry *"
+.Fa "int fd"
+.Fa "const struct stat *"
+.Fc
+.Ft int
+.Fn archive_read_close "struct archive *"
+.Ft int
+.Fn archive_read_finish "struct archive *"
+.Ft int
+.Fn archive_read_free "struct archive *"
+.Sh DESCRIPTION
+These functions provide an API for reading information about
+objects on disk.
+In particular, they provide an interface for populating
+.Tn struct archive_entry
+objects.
+.Bl -tag -width indent
+.It Fn archive_read_disk_new
+Allocates and initializes a
+.Tn struct archive
+object suitable for reading object information from disk.
+.It Xo
+.Fn archive_read_disk_set_symlink_logical ,
+.Fn archive_read_disk_set_symlink_physical ,
+.Fn archive_read_disk_set_symlink_hybrid
+.Xc
+This sets the mode used for handling symbolic links.
+The
+.Dq logical
+mode follows all symbolic links.
+The
+.Dq physical
+mode does not follow any symbolic links.
+The
+.Dq hybrid
+mode currently behaves identically to the
+.Dq logical
+mode.
+.It Xo
+.Fn archive_read_disk_gname ,
+.Fn archive_read_disk_uname
+.Xc
+Returns a user or group name given a gid or uid value.
+By default, these always return a NULL string.
+.It Xo
+.Fn archive_read_disk_set_gname_lookup ,
+.Fn archive_read_disk_set_uname_lookup
+.Xc
+These allow you to override the functions used for
+user and group name lookups.
+You may also provide a
+.Tn void *
+pointer to a private data structure and a cleanup function for
+that data.
+The cleanup function will be invoked when the
+.Tn struct archive
+object is destroyed or when new lookup functions are registered.
+.It Fn archive_read_disk_set_standard_lookup
+This convenience function installs a standard set of user
+and group name lookup functions.
+These functions use
+.Xr getpwuid 3
+and
+.Xr getgrgid 3
+to convert ids to names, defaulting to NULL if the names cannot
+be looked up.
+These functions also implement a simple memory cache to reduce
+the number of calls to
+.Xr getpwuid 3
+and
+.Xr getgrgid 3 .
+.It Fn archive_read_disk_entry_from_file
+Populates a
+.Tn struct archive_entry
+object with information about a particular file.
+The
+.Tn archive_entry
+object must have already been created with
+.Xr archive_entry_new 3
+and at least one of the source path or path fields must already be set.
+(If both are set, the source path will be used.)
+.Pp
+Information is read from disk using the path name from the
+.Tn struct archive_entry
+object.
+If a file descriptor is provided, some information will be obtained using
+that file descriptor, on platforms that support the appropriate
+system calls.
+.Pp
+If a pointer to a
+.Tn struct stat
+is provided, information from that structure will be used instead
+of reading from the disk where appropriate.
+This can provide performance benefits in scenarios where
+.Tn struct stat
+information has already been read from the disk as a side effect
+of some other operation.
+(For example, directory traversal libraries often provide this information.)
+.Pp
+Where necessary, user and group ids are converted to user and group names
+using the currently registered lookup functions above.
+This affects the file ownership fields and ACL values in the
+.Tn struct archive_entry
+object.
+.It Fn archive_read_close
+Does nothing for
+.Tn archive_read_disk
+handles.
+.It Fn archive_read_finish
+This is a deprecated synonym for
+.Fn archive_read_free .
+.It Fn archive_read_free
+Invokes
+.Fn archive_read_close
+if it was not invoked manually, then releases all resources.
+.El
+More information about the
+.Va struct archive
+object and the overall design of the library can be found in the
+.Xr libarchive 3
+overview.
+.Sh EXAMPLE
+The following illustrates basic usage of the library by
+showing how to use it to copy an item on disk into an archive.
+.Bd -literal -offset indent
+void
+file_to_archive(struct archive *a, const char *name)
+{
+ char buff[8192];
+ size_t bytes_read;
+ struct archive *ard;
+ struct archive_entry *entry;
+ int fd;
+
+ ard = archive_read_disk_new();
+ archive_read_disk_set_standard_lookup(ard);
+ entry = archive_entry_new();
+ fd = open(name, O_RDONLY);
+ if (fd < 0)
+ return;
+ archive_entry_copy_pathname(entry, name);
+ archive_read_disk_entry_from_file(ard, entry, fd, NULL);
+ archive_write_header(a, entry);
+ while ((bytes_read = read(fd, buff, sizeof(buff))) > 0)
+ archive_write_data(a, buff, bytes_read);
+ archive_write_finish_entry(a);
+ archive_read_free(ard);
+ archive_entry_free(entry);
+}
+.Ed
+.Sh RETURN VALUES
+Most functions return
+.Cm ARCHIVE_OK
+(zero) on success, or one of several negative
+error codes for errors.
+Specific error codes include:
+.Cm ARCHIVE_RETRY
+for operations that might succeed if retried,
+.Cm ARCHIVE_WARN
+for unusual conditions that do not prevent further operations, and
+.Cm ARCHIVE_FATAL
+for serious errors that make remaining operations impossible.
+.Pp
+.Fn archive_read_disk_new
+returns a pointer to a newly-allocated
+.Tn struct archive
+object or NULL if the allocation failed for any reason.
+.Pp
+.Fn archive_read_disk_gname
+and
+.Fn archive_read_disk_uname
+return
+.Tn const char *
+pointers to the textual name or NULL if the lookup failed for any reason.
+The returned pointer points to internal storage that
+may be reused on the next call to either of these functions;
+callers should copy the string if they need to continue accessing it.
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr archive_read 3 ,
+.Xr archive_util 3 ,
+.Xr archive_write 3 ,
+.Xr archive_write_disk 3 ,
+.Xr tar 1 ,
+.Xr libarchive 3
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+The
+.Nm archive_read_disk
+interface was added to
+.Nm libarchive 2.6
+and first appeared in
+.Fx 8.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libarchive
+library was written by
+.An Tim Kientzle Aq kientzle@FreeBSD.org .
+.Sh BUGS
+The
+.Dq standard
+user name and group name lookup functions are not the defaults because
+.Xr getgrgid 3
+and
+.Xr getpwuid 3
+are sometimes too large for particular applications.
+The current design allows the application author to use a more
+compact implementation when appropriate.
+.Pp
+The full list of metadata read from disk by
+.Fn archive_read_disk_entry_from_file
+is necessarily system-dependent.
+.Pp
+The
+.Fn archive_read_disk_entry_from_file
+function reads as much information as it can from disk.
+Some method should be provided to limit this so that clients who
+do not need ACLs, for instance, can avoid the extra work needed
+to look up such information.
+.Pp
+This API should provide a set of methods for walking a directory tree.
+That would make it a direct parallel of the
+.Xr archive_read 3
+API.
+When such methods are implemented, the
+.Dq hybrid
+symbolic link mode will make sense.
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c
new file mode 100644
index 0000000000..e81cbeccd1
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c
@@ -0,0 +1,1240 @@
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * Copyright (c) 2010-2012 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: head/lib/libarchive/archive_read_disk_entry_from_file.c 201084 2009-12-28 02:14:09Z kientzle $");
+
+/* This is the tree-walking code for POSIX systems. */
+#if !defined(_WIN32) || defined(__CYGWIN__)
+
+#ifdef HAVE_SYS_TYPES_H
+/* Mac OSX requires sys/types.h before sys/acl.h. */
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_ACL_H
+#include <sys/acl.h>
+#endif
+#ifdef HAVE_SYS_EXTATTR_H
+#include <sys/extattr.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#if defined(HAVE_SYS_XATTR_H)
+#include <sys/xattr.h>
+#elif defined(HAVE_ATTR_XATTR_H)
+#include <attr/xattr.h>
+#endif
+#ifdef HAVE_SYS_EA_H
+#include <sys/ea.h>
+#endif
+#ifdef HAVE_ACL_LIBACL_H
+#include <acl/libacl.h>
+#endif
+#ifdef HAVE_COPYFILE_H
+#include <copyfile.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_LINUX_TYPES_H
+#include <linux/types.h>
+#endif
+#ifdef HAVE_LINUX_FIEMAP_H
+#include <linux/fiemap.h>
+#endif
+#ifdef HAVE_LINUX_FS_H
+#include <linux/fs.h>
+#endif
+/*
+ * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
+ * As the include guards don't agree, the order of include is important.
+ */
+#ifdef HAVE_LINUX_EXT2_FS_H
+#include <linux/ext2_fs.h> /* for Linux file flags */
+#endif
+#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
+#include <ext2fs/ext2_fs.h> /* Linux file flags, broken on Cygwin */
+#endif
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_disk_private.h"
+
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
+/*
+ * Linux and FreeBSD plug this obvious hole in POSIX.1e in
+ * different ways.
+ */
+#if HAVE_ACL_GET_PERM
+#define ACL_GET_PERM acl_get_perm
+#elif HAVE_ACL_GET_PERM_NP
+#define ACL_GET_PERM acl_get_perm_np
+#endif
+
+static int setup_acls(struct archive_read_disk *,
+ struct archive_entry *, int *fd);
+static int setup_mac_metadata(struct archive_read_disk *,
+ struct archive_entry *, int *fd);
+static int setup_xattrs(struct archive_read_disk *,
+ struct archive_entry *, int *fd);
+static int setup_sparse(struct archive_read_disk *,
+ struct archive_entry *, int *fd);
+
+int
+archive_read_disk_entry_from_file(struct archive *_a,
+ struct archive_entry *entry,
+ int fd,
+ const struct stat *st)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ const char *path, *name;
+ struct stat s;
+ int initial_fd = fd;
+ int r, r1;
+
+ archive_clear_error(_a);
+ path = archive_entry_sourcepath(entry);
+ if (path == NULL)
+ path = archive_entry_pathname(entry);
+
+ if (a->tree == NULL) {
+ if (st == NULL) {
+#if HAVE_FSTAT
+ if (fd >= 0) {
+ if (fstat(fd, &s) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't fstat");
+ return (ARCHIVE_FAILED);
+ }
+ } else
+#endif
+#if HAVE_LSTAT
+ if (!a->follow_symlinks) {
+ if (lstat(path, &s) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't lstat %s", path);
+ return (ARCHIVE_FAILED);
+ }
+ } else
+#endif
+ if (stat(path, &s) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't stat %s", path);
+ return (ARCHIVE_FAILED);
+ }
+ st = &s;
+ }
+ archive_entry_copy_stat(entry, st);
+ }
+
+ /* Lookup uname/gname */
+ name = archive_read_disk_uname(_a, archive_entry_uid(entry));
+ if (name != NULL)
+ archive_entry_copy_uname(entry, name);
+ name = archive_read_disk_gname(_a, archive_entry_gid(entry));
+ if (name != NULL)
+ archive_entry_copy_gname(entry, name);
+
+#ifdef HAVE_STRUCT_STAT_ST_FLAGS
+ /* On FreeBSD, we get flags for free with the stat. */
+ /* TODO: Does this belong in copy_stat()? */
+ if (st->st_flags != 0)
+ archive_entry_set_fflags(entry, st->st_flags, 0);
+#endif
+
+#if defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)
+ /* Linux requires an extra ioctl to pull the flags. Although
+ * this is an extra step, it has a nice side-effect: We get an
+ * open file descriptor which we can use in the subsequent lookups. */
+ if ((S_ISREG(st->st_mode) || S_ISDIR(st->st_mode))) {
+ if (fd < 0) {
+ if (a->tree != NULL)
+ fd = a->open_on_current_dir(a->tree, path,
+ O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+ else
+ fd = open(path, O_RDONLY | O_NONBLOCK |
+ O_CLOEXEC);
+ __archive_ensure_cloexec_flag(fd);
+ }
+ if (fd >= 0) {
+ int stflags;
+ r = ioctl(fd, EXT2_IOC_GETFLAGS, &stflags);
+ if (r == 0 && stflags != 0)
+ archive_entry_set_fflags(entry, stflags, 0);
+ }
+ }
+#endif
+
+#if defined(HAVE_READLINK) || defined(HAVE_READLINKAT)
+ if (S_ISLNK(st->st_mode)) {
+ size_t linkbuffer_len = st->st_size + 1;
+ char *linkbuffer;
+ int lnklen;
+
+ linkbuffer = malloc(linkbuffer_len);
+ if (linkbuffer == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't read link data");
+ return (ARCHIVE_FAILED);
+ }
+ if (a->tree != NULL) {
+#ifdef HAVE_READLINKAT
+ lnklen = readlinkat(a->tree_current_dir_fd(a->tree),
+ path, linkbuffer, linkbuffer_len);
+#else
+ if (a->tree_enter_working_dir(a->tree) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't read link data");
+ free(linkbuffer);
+ return (ARCHIVE_FAILED);
+ }
+ lnklen = readlink(path, linkbuffer, linkbuffer_len);
+#endif /* HAVE_READLINKAT */
+ } else
+ lnklen = readlink(path, linkbuffer, linkbuffer_len);
+ if (lnklen < 0) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't read link data");
+ free(linkbuffer);
+ return (ARCHIVE_FAILED);
+ }
+ linkbuffer[lnklen] = 0;
+ archive_entry_set_symlink(entry, linkbuffer);
+ free(linkbuffer);
+ }
+#endif /* HAVE_READLINK || HAVE_READLINKAT */
+
+ r = setup_acls(a, entry, &fd);
+ 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)
+ r = r1;
+ }
+ r1 = setup_sparse(a, entry, &fd);
+ if (r1 < r)
+ r = r1;
+
+ /* If we opened the file earlier in this function, close it. */
+ if (initial_fd != fd)
+ close(fd);
+ return (r);
+}
+
+#if defined(__APPLE__) && defined(HAVE_COPYFILE_H)
+/*
+ * The Mac OS "copyfile()" API copies the extended metadata for a
+ * file into a separate file in AppleDouble format (see RFC 1740).
+ *
+ * Mac OS tar and cpio implementations store this extended
+ * metadata as a separate entry just before the regular entry
+ * with a "._" prefix added to the filename.
+ *
+ * Note that this is currently done unconditionally; the tar program has
+ * an option to discard this information before the archive is written.
+ *
+ * TODO: If there's a failure, report it and return ARCHIVE_WARN.
+ */
+static int
+setup_mac_metadata(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ int tempfd = -1;
+ int copyfile_flags = COPYFILE_NOFOLLOW | COPYFILE_ACL | COPYFILE_XATTR;
+ struct stat copyfile_stat;
+ int ret = ARCHIVE_OK;
+ void *buff = NULL;
+ int have_attrs;
+ const char *name, *tempdir;
+ struct archive_string tempfile;
+
+ (void)fd; /* UNUSED */
+ name = archive_entry_sourcepath(entry);
+ if (name == NULL)
+ name = archive_entry_pathname(entry);
+ if (name == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't open file to read extended attributes: No name");
+ return (ARCHIVE_WARN);
+ }
+
+ if (a->tree != NULL) {
+ if (a->tree_enter_working_dir(a->tree) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't change dir");
+ return (ARCHIVE_FAILED);
+ }
+ }
+
+ /* Short-circuit if there's nothing to do. */
+ have_attrs = copyfile(name, NULL, 0, copyfile_flags | COPYFILE_CHECK);
+ if (have_attrs == -1) {
+ archive_set_error(&a->archive, errno,
+ "Could not check extended attributes");
+ return (ARCHIVE_WARN);
+ }
+ if (have_attrs == 0)
+ return (ARCHIVE_OK);
+
+ tempdir = NULL;
+ if (issetugid() == 0)
+ tempdir = getenv("TMPDIR");
+ if (tempdir == NULL)
+ tempdir = _PATH_TMP;
+ archive_string_init(&tempfile);
+ archive_strcpy(&tempfile, tempdir);
+ archive_strcat(&tempfile, "tar.md.XXXXXX");
+ tempfd = mkstemp(tempfile.s);
+ if (tempfd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Could not open extended attribute file");
+ ret = ARCHIVE_WARN;
+ goto cleanup;
+ }
+ __archive_ensure_cloexec_flag(tempfd);
+
+ /* XXX I wish copyfile() could pack directly to a memory
+ * buffer; that would avoid the temp file here. For that
+ * matter, it would be nice if fcopyfile() actually worked,
+ * that would reduce the many open/close races here. */
+ if (copyfile(name, tempfile.s, 0, copyfile_flags | COPYFILE_PACK)) {
+ archive_set_error(&a->archive, errno,
+ "Could not pack extended attributes");
+ ret = ARCHIVE_WARN;
+ goto cleanup;
+ }
+ if (fstat(tempfd, &copyfile_stat)) {
+ archive_set_error(&a->archive, errno,
+ "Could not check size of extended attributes");
+ ret = ARCHIVE_WARN;
+ goto cleanup;
+ }
+ buff = malloc(copyfile_stat.st_size);
+ if (buff == NULL) {
+ archive_set_error(&a->archive, errno,
+ "Could not allocate memory for extended attributes");
+ ret = ARCHIVE_WARN;
+ goto cleanup;
+ }
+ if (copyfile_stat.st_size != read(tempfd, buff, copyfile_stat.st_size)) {
+ archive_set_error(&a->archive, errno,
+ "Could not read extended attributes into memory");
+ ret = ARCHIVE_WARN;
+ goto cleanup;
+ }
+ archive_entry_copy_mac_metadata(entry, buff, copyfile_stat.st_size);
+
+cleanup:
+ if (tempfd >= 0) {
+ close(tempfd);
+ unlink(tempfile.s);
+ }
+ archive_string_free(&tempfile);
+ free(buff);
+ return (ret);
+}
+
+#else
+
+/*
+ * Stub implementation for non-Mac systems.
+ */
+static int
+setup_mac_metadata(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ (void)a; /* UNUSED */
+ (void)entry; /* UNUSED */
+ (void)fd; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+#endif
+
+
+#ifdef HAVE_POSIX_ACL
+static int translate_acl(struct archive_read_disk *a,
+ struct archive_entry *entry, acl_t acl, int archive_entry_acl_type);
+
+static int
+setup_acls(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ const char *accpath;
+ acl_t acl;
+#if HAVE_ACL_IS_TRIVIAL_NP
+ int r;
+#endif
+
+ accpath = archive_entry_sourcepath(entry);
+ if (accpath == NULL)
+ accpath = archive_entry_pathname(entry);
+
+ archive_entry_acl_clear(entry);
+
+#ifdef ACL_TYPE_NFS4
+ /* Try NFS4 ACL first. */
+ if (*fd >= 0)
+ acl = acl_get_fd(*fd);
+#if HAVE_ACL_GET_LINK_NP
+ else if (!a->follow_symlinks)
+ acl = acl_get_link_np(accpath, ACL_TYPE_NFS4);
+#else
+ else if ((!a->follow_symlinks)
+ && (archive_entry_filetype(entry) == AE_IFLNK))
+ /* We can't get the ACL of a symlink, so we assume it can't
+ have one. */
+ acl = NULL;
+#endif
+ else
+ acl = acl_get_file(accpath, ACL_TYPE_NFS4);
+#if HAVE_ACL_IS_TRIVIAL_NP
+ /* Ignore "trivial" ACLs that just mirror the file mode. */
+ acl_is_trivial_np(acl, &r);
+ if (r) {
+ acl_free(acl);
+ acl = NULL;
+ }
+#endif
+ if (acl != NULL) {
+ translate_acl(a, entry, acl, ARCHIVE_ENTRY_ACL_TYPE_NFS4);
+ acl_free(acl);
+ return (ARCHIVE_OK);
+ }
+#endif
+
+ /* Retrieve access ACL from file. */
+ if (*fd >= 0)
+ acl = acl_get_fd(*fd);
+#if HAVE_ACL_GET_LINK_NP
+ else if (!a->follow_symlinks)
+ acl = acl_get_link_np(accpath, ACL_TYPE_ACCESS);
+#else
+ else if ((!a->follow_symlinks)
+ && (archive_entry_filetype(entry) == AE_IFLNK))
+ /* We can't get the ACL of a symlink, so we assume it can't
+ have one. */
+ acl = NULL;
+#endif
+ else
+ acl = acl_get_file(accpath, ACL_TYPE_ACCESS);
+ if (acl != NULL) {
+ translate_acl(a, entry, acl,
+ ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
+ acl_free(acl);
+ }
+
+ /* Only directories can have default ACLs. */
+ if (S_ISDIR(archive_entry_mode(entry))) {
+ acl = acl_get_file(accpath, ACL_TYPE_DEFAULT);
+ if (acl != NULL) {
+ translate_acl(a, entry, acl,
+ ARCHIVE_ENTRY_ACL_TYPE_DEFAULT);
+ acl_free(acl);
+ }
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Translate system ACL into libarchive internal structure.
+ */
+
+static struct {
+ int archive_perm;
+ int platform_perm;
+} acl_perm_map[] = {
+ {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE},
+ {ARCHIVE_ENTRY_ACL_WRITE, ACL_WRITE},
+ {ARCHIVE_ENTRY_ACL_READ, ACL_READ},
+#ifdef ACL_TYPE_NFS4
+ {ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA},
+ {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY},
+ {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA},
+ {ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE},
+ {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA},
+ {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY},
+ {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_NAMED_ATTRS},
+ {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_NAMED_ATTRS},
+ {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD},
+ {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES},
+ {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES},
+ {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE},
+ {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_ACL},
+ {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_ACL},
+ {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_WRITE_OWNER},
+ {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE}
+#endif
+};
+
+#ifdef ACL_TYPE_NFS4
+static struct {
+ int archive_inherit;
+ int platform_inherit;
+} acl_inherit_map[] = {
+ {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT},
+ {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT},
+ {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_NO_PROPAGATE_INHERIT},
+ {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_INHERIT_ONLY}
+};
+#endif
+static int
+translate_acl(struct archive_read_disk *a,
+ struct archive_entry *entry, acl_t acl, int default_entry_acl_type)
+{
+ acl_tag_t acl_tag;
+#ifdef ACL_TYPE_NFS4
+ acl_entry_type_t acl_type;
+ acl_flagset_t acl_flagset;
+ int brand, r;
+#endif
+ acl_entry_t acl_entry;
+ acl_permset_t acl_permset;
+ int i, entry_acl_type;
+ int s, ae_id, ae_tag, ae_perm;
+ const char *ae_name;
+
+
+#ifdef ACL_TYPE_NFS4
+ // FreeBSD "brands" ACLs as POSIX.1e or NFSv4
+ // Make sure the "brand" on this ACL is consistent
+ // with the default_entry_acl_type bits provided.
+ acl_get_brand_np(acl, &brand);
+ switch (brand) {
+ case ACL_BRAND_POSIX:
+ switch (default_entry_acl_type) {
+ case ARCHIVE_ENTRY_ACL_TYPE_ACCESS:
+ case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT:
+ break;
+ default:
+ // XXX set warning message?
+ return ARCHIVE_FAILED;
+ }
+ break;
+ case ACL_BRAND_NFS4:
+ if (default_entry_acl_type & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
+ // XXX set warning message?
+ return ARCHIVE_FAILED;
+ }
+ break;
+ default:
+ // XXX set warning message?
+ return ARCHIVE_FAILED;
+ break;
+ }
+#endif
+
+
+ s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry);
+ while (s == 1) {
+ ae_id = -1;
+ ae_name = NULL;
+ ae_perm = 0;
+
+ acl_get_tag_type(acl_entry, &acl_tag);
+ switch (acl_tag) {
+ case ACL_USER:
+ ae_id = (int)*(uid_t *)acl_get_qualifier(acl_entry);
+ ae_name = archive_read_disk_uname(&a->archive, ae_id);
+ ae_tag = ARCHIVE_ENTRY_ACL_USER;
+ break;
+ case ACL_GROUP:
+ ae_id = (int)*(gid_t *)acl_get_qualifier(acl_entry);
+ ae_name = archive_read_disk_gname(&a->archive, ae_id);
+ ae_tag = ARCHIVE_ENTRY_ACL_GROUP;
+ break;
+ case ACL_MASK:
+ ae_tag = ARCHIVE_ENTRY_ACL_MASK;
+ break;
+ case ACL_USER_OBJ:
+ ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
+ break;
+ case ACL_GROUP_OBJ:
+ ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
+ break;
+ case ACL_OTHER:
+ ae_tag = ARCHIVE_ENTRY_ACL_OTHER;
+ break;
+#ifdef ACL_TYPE_NFS4
+ case ACL_EVERYONE:
+ ae_tag = ARCHIVE_ENTRY_ACL_EVERYONE;
+ break;
+#endif
+ default:
+ /* Skip types that libarchive can't support. */
+ s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
+ continue;
+ }
+
+ // XXX acl type maps to allow/deny/audit/YYYY bits
+ // XXX acl_get_entry_type_np on FreeBSD returns EINVAL for
+ // non-NFSv4 ACLs
+ entry_acl_type = default_entry_acl_type;
+#ifdef ACL_TYPE_NFS4
+ r = acl_get_entry_type_np(acl_entry, &acl_type);
+ if (r == 0) {
+ switch (acl_type) {
+ case ACL_ENTRY_TYPE_ALLOW:
+ entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW;
+ break;
+ case ACL_ENTRY_TYPE_DENY:
+ entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY;
+ break;
+ case ACL_ENTRY_TYPE_AUDIT:
+ entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_AUDIT;
+ break;
+ case ACL_ENTRY_TYPE_ALARM:
+ entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALARM;
+ break;
+ }
+ }
+
+ /*
+ * Libarchive stores "flag" (NFSv4 inheritance bits)
+ * in the ae_perm bitmap.
+ */
+ acl_get_flagset_np(acl_entry, &acl_flagset);
+ for (i = 0; i < (int)(sizeof(acl_inherit_map) / sizeof(acl_inherit_map[0])); ++i) {
+ if (acl_get_flag_np(acl_flagset,
+ acl_inherit_map[i].platform_inherit))
+ ae_perm |= acl_inherit_map[i].archive_inherit;
+
+ }
+#endif
+
+ acl_get_permset(acl_entry, &acl_permset);
+ for (i = 0; i < (int)(sizeof(acl_perm_map) / sizeof(acl_perm_map[0])); ++i) {
+ /*
+ * acl_get_perm() is spelled differently on different
+ * platforms; see above.
+ */
+ if (ACL_GET_PERM(acl_permset, acl_perm_map[i].platform_perm))
+ ae_perm |= acl_perm_map[i].archive_perm;
+ }
+
+ archive_entry_acl_add_entry(entry, entry_acl_type,
+ ae_perm, ae_tag,
+ ae_id, ae_name);
+
+ s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
+ }
+ return (ARCHIVE_OK);
+}
+#else
+static int
+setup_acls(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ (void)a; /* UNUSED */
+ (void)entry; /* UNUSED */
+ (void)fd; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+#endif
+
+#if (HAVE_FGETXATTR && HAVE_FLISTXATTR && HAVE_LISTXATTR && \
+ HAVE_LLISTXATTR && HAVE_GETXATTR && HAVE_LGETXATTR) || \
+ (HAVE_FGETEA && HAVE_FLISTEA && HAVE_LISTEA)
+
+/*
+ * Linux and AIX extended attribute support.
+ *
+ * TODO: By using a stack-allocated buffer for the first
+ * call to getxattr(), we might be able to avoid the second
+ * call entirely. We only need the second call if the
+ * stack-allocated buffer is too small. But a modest buffer
+ * of 1024 bytes or so will often be big enough. Same applies
+ * to listxattr().
+ */
+
+
+static int
+setup_xattr(struct archive_read_disk *a,
+ struct archive_entry *entry, const char *name, int fd)
+{
+ ssize_t size;
+ void *value = NULL;
+ const char *accpath;
+
+ accpath = archive_entry_sourcepath(entry);
+ if (accpath == NULL)
+ accpath = archive_entry_pathname(entry);
+
+#if HAVE_FGETXATTR
+ if (fd >= 0)
+ size = fgetxattr(fd, name, NULL, 0);
+ else if (!a->follow_symlinks)
+ size = lgetxattr(accpath, name, NULL, 0);
+ else
+ size = getxattr(accpath, name, NULL, 0);
+#elif HAVE_FGETEA
+ if (fd >= 0)
+ size = fgetea(fd, name, NULL, 0);
+ else if (!a->follow_symlinks)
+ size = lgetea(accpath, name, NULL, 0);
+ else
+ size = getea(accpath, name, NULL, 0);
+#endif
+
+ if (size == -1) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't query extended attribute");
+ return (ARCHIVE_WARN);
+ }
+
+ if (size > 0 && (value = malloc(size)) == NULL) {
+ archive_set_error(&a->archive, errno, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+
+#if HAVE_FGETXATTR
+ if (fd >= 0)
+ size = fgetxattr(fd, name, value, size);
+ else if (!a->follow_symlinks)
+ size = lgetxattr(accpath, name, value, size);
+ else
+ size = getxattr(accpath, name, value, size);
+#elif HAVE_FGETEA
+ if (fd >= 0)
+ size = fgetea(fd, name, value, size);
+ else if (!a->follow_symlinks)
+ size = lgetea(accpath, name, value, size);
+ else
+ size = getea(accpath, name, value, size);
+#endif
+
+ if (size == -1) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't read extended attribute");
+ return (ARCHIVE_WARN);
+ }
+
+ archive_entry_xattr_add_entry(entry, name, value, size);
+
+ free(value);
+ return (ARCHIVE_OK);
+}
+
+static int
+setup_xattrs(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ char *list, *p;
+ const char *path;
+ ssize_t list_size;
+
+ path = archive_entry_sourcepath(entry);
+ if (path == NULL)
+ path = archive_entry_pathname(entry);
+
+ if (*fd < 0 && a->tree != NULL) {
+ if (a->follow_symlinks ||
+ archive_entry_filetype(entry) != AE_IFLNK)
+ *fd = a->open_on_current_dir(a->tree, path,
+ O_RDONLY | O_NONBLOCK);
+ if (*fd < 0) {
+ if (a->tree_enter_working_dir(a->tree) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't access %s", path);
+ return (ARCHIVE_FAILED);
+ }
+ }
+ }
+
+#if HAVE_FLISTXATTR
+ if (*fd >= 0)
+ list_size = flistxattr(*fd, NULL, 0);
+ else if (!a->follow_symlinks)
+ list_size = llistxattr(path, NULL, 0);
+ else
+ list_size = listxattr(path, NULL, 0);
+#elif HAVE_FLISTEA
+ if (*fd >= 0)
+ list_size = flistea(*fd, NULL, 0);
+ else if (!a->follow_symlinks)
+ list_size = llistea(path, NULL, 0);
+ else
+ list_size = listea(path, NULL, 0);
+#endif
+
+ if (list_size == -1) {
+ if (errno == ENOTSUP || errno == ENOSYS)
+ return (ARCHIVE_OK);
+ archive_set_error(&a->archive, errno,
+ "Couldn't list extended attributes");
+ return (ARCHIVE_WARN);
+ }
+
+ if (list_size == 0)
+ return (ARCHIVE_OK);
+
+ if ((list = malloc(list_size)) == NULL) {
+ archive_set_error(&a->archive, errno, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+
+#if HAVE_FLISTXATTR
+ if (*fd >= 0)
+ list_size = flistxattr(*fd, list, list_size);
+ else if (!a->follow_symlinks)
+ list_size = llistxattr(path, list, list_size);
+ else
+ list_size = listxattr(path, list, list_size);
+#elif HAVE_FLISTEA
+ if (*fd >= 0)
+ list_size = flistea(*fd, list, list_size);
+ else if (!a->follow_symlinks)
+ list_size = llistea(path, list, list_size);
+ else
+ list_size = listea(path, list, list_size);
+#endif
+
+ if (list_size == -1) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't retrieve extended attributes");
+ free(list);
+ return (ARCHIVE_WARN);
+ }
+
+ for (p = list; (p - list) < list_size; p += strlen(p) + 1) {
+ if (strncmp(p, "system.", 7) == 0 ||
+ strncmp(p, "xfsroot.", 8) == 0)
+ continue;
+ setup_xattr(a, entry, p, *fd);
+ }
+
+ free(list);
+ return (ARCHIVE_OK);
+}
+
+#elif HAVE_EXTATTR_GET_FILE && HAVE_EXTATTR_LIST_FILE && \
+ HAVE_DECL_EXTATTR_NAMESPACE_USER
+
+/*
+ * FreeBSD extattr interface.
+ */
+
+/* TODO: Implement this. Follow the Linux model above, but
+ * with FreeBSD-specific system calls, of course. Be careful
+ * to not include the system extattrs that hold ACLs; we handle
+ * those separately.
+ */
+static int
+setup_xattr(struct archive_read_disk *a, struct archive_entry *entry,
+ int namespace, const char *name, const char *fullname, int fd);
+
+static int
+setup_xattr(struct archive_read_disk *a, struct archive_entry *entry,
+ int namespace, const char *name, const char *fullname, int fd)
+{
+ ssize_t size;
+ void *value = NULL;
+ const char *accpath;
+
+ accpath = archive_entry_sourcepath(entry);
+ if (accpath == NULL)
+ accpath = archive_entry_pathname(entry);
+
+ if (fd >= 0)
+ size = extattr_get_fd(fd, namespace, name, NULL, 0);
+ else if (!a->follow_symlinks)
+ size = extattr_get_link(accpath, namespace, name, NULL, 0);
+ else
+ size = extattr_get_file(accpath, namespace, name, NULL, 0);
+
+ if (size == -1) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't query extended attribute");
+ return (ARCHIVE_WARN);
+ }
+
+ if (size > 0 && (value = malloc(size)) == NULL) {
+ archive_set_error(&a->archive, errno, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (fd >= 0)
+ size = extattr_get_fd(fd, namespace, name, value, size);
+ else if (!a->follow_symlinks)
+ size = extattr_get_link(accpath, namespace, name, value, size);
+ else
+ size = extattr_get_file(accpath, namespace, name, value, size);
+
+ if (size == -1) {
+ free(value);
+ archive_set_error(&a->archive, errno,
+ "Couldn't read extended attribute");
+ return (ARCHIVE_WARN);
+ }
+
+ archive_entry_xattr_add_entry(entry, fullname, value, size);
+
+ free(value);
+ return (ARCHIVE_OK);
+}
+
+static int
+setup_xattrs(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ char buff[512];
+ char *list, *p;
+ ssize_t list_size;
+ const char *path;
+ int namespace = EXTATTR_NAMESPACE_USER;
+
+ path = archive_entry_sourcepath(entry);
+ if (path == NULL)
+ path = archive_entry_pathname(entry);
+
+ if (*fd < 0 && a->tree != NULL) {
+ if (a->follow_symlinks ||
+ archive_entry_filetype(entry) != AE_IFLNK)
+ *fd = a->open_on_current_dir(a->tree, path,
+ O_RDONLY | O_NONBLOCK);
+ if (*fd < 0) {
+ if (a->tree_enter_working_dir(a->tree) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't access %s", path);
+ return (ARCHIVE_FAILED);
+ }
+ }
+ }
+
+ if (*fd >= 0)
+ list_size = extattr_list_fd(*fd, namespace, NULL, 0);
+ else if (!a->follow_symlinks)
+ list_size = extattr_list_link(path, namespace, NULL, 0);
+ else
+ list_size = extattr_list_file(path, namespace, NULL, 0);
+
+ if (list_size == -1 && errno == EOPNOTSUPP)
+ return (ARCHIVE_OK);
+ if (list_size == -1) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't list extended attributes");
+ return (ARCHIVE_WARN);
+ }
+
+ if (list_size == 0)
+ return (ARCHIVE_OK);
+
+ if ((list = malloc(list_size)) == NULL) {
+ archive_set_error(&a->archive, errno, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (*fd >= 0)
+ list_size = extattr_list_fd(*fd, namespace, list, list_size);
+ else if (!a->follow_symlinks)
+ list_size = extattr_list_link(path, namespace, list, list_size);
+ else
+ list_size = extattr_list_file(path, namespace, list, list_size);
+
+ if (list_size == -1) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't retrieve extended attributes");
+ free(list);
+ return (ARCHIVE_WARN);
+ }
+
+ p = list;
+ while ((p - list) < list_size) {
+ size_t len = 255 & (int)*p;
+ char *name;
+
+ strcpy(buff, "user.");
+ name = buff + strlen(buff);
+ memcpy(name, p + 1, len);
+ name[len] = '\0';
+ setup_xattr(a, entry, namespace, name, buff, *fd);
+ p += 1 + len;
+ }
+
+ free(list);
+ return (ARCHIVE_OK);
+}
+
+#else
+
+/*
+ * Generic (stub) extended attribute support.
+ */
+static int
+setup_xattrs(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ (void)a; /* UNUSED */
+ (void)entry; /* UNUSED */
+ (void)fd; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+#endif
+
+#if defined(HAVE_LINUX_FIEMAP_H)
+
+/*
+ * Linux sparse interface.
+ *
+ * The FIEMAP ioctl returns an "extent" for each physical allocation
+ * on disk. We need to process those to generate a more compact list
+ * of logical file blocks. We also need to be very careful to use
+ * FIEMAP_FLAG_SYNC here, since there are reports that Linux sometimes
+ * does not report allocations for newly-written data that hasn't
+ * been synced to disk.
+ *
+ * It's important to return a minimal sparse file list because we want
+ * to not trigger sparse file extensions if we don't have to, since
+ * not all readers support them.
+ */
+
+static int
+setup_sparse(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ char buff[4096];
+ struct fiemap *fm;
+ struct fiemap_extent *fe;
+ int64_t size;
+ int count, do_fiemap;
+ int exit_sts = ARCHIVE_OK;
+
+ if (archive_entry_filetype(entry) != AE_IFREG
+ || archive_entry_size(entry) <= 0
+ || archive_entry_hardlink(entry) != NULL)
+ return (ARCHIVE_OK);
+
+ if (*fd < 0) {
+ const char *path;
+
+ path = archive_entry_sourcepath(entry);
+ if (path == NULL)
+ path = archive_entry_pathname(entry);
+ if (a->tree != NULL)
+ *fd = a->open_on_current_dir(a->tree, path,
+ O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+ else
+ *fd = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+ if (*fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't open `%s'", path);
+ return (ARCHIVE_FAILED);
+ }
+ __archive_ensure_cloexec_flag(*fd);
+ }
+
+ /* Initialize buffer to avoid the error valgrind complains about. */
+ memset(buff, 0, sizeof(buff));
+ count = (sizeof(buff) - sizeof(*fm))/sizeof(*fe);
+ fm = (struct fiemap *)buff;
+ fm->fm_start = 0;
+ fm->fm_length = ~0ULL;;
+ fm->fm_flags = FIEMAP_FLAG_SYNC;
+ fm->fm_extent_count = count;
+ do_fiemap = 1;
+ size = archive_entry_size(entry);
+ for (;;) {
+ int i, r;
+
+ r = ioctl(*fd, FS_IOC_FIEMAP, fm);
+ if (r < 0) {
+ /* When something error happens, it is better we
+ * should return ARCHIVE_OK because an earlier
+ * version(<2.6.28) cannot perfom FS_IOC_FIEMAP. */
+ goto exit_setup_sparse;
+ }
+ if (fm->fm_mapped_extents == 0)
+ break;
+ fe = fm->fm_extents;
+ for (i = 0; i < (int)fm->fm_mapped_extents; i++, fe++) {
+ if (!(fe->fe_flags & FIEMAP_EXTENT_UNWRITTEN)) {
+ /* The fe_length of the last block does not
+ * adjust itself to its size files. */
+ int64_t length = fe->fe_length;
+ if (fe->fe_logical + length > (uint64_t)size)
+ length -= fe->fe_logical + length - size;
+ if (fe->fe_logical == 0 && length == size) {
+ /* This is not sparse. */
+ do_fiemap = 0;
+ break;
+ }
+ if (length > 0)
+ archive_entry_sparse_add_entry(entry,
+ fe->fe_logical, length);
+ }
+ if (fe->fe_flags & FIEMAP_EXTENT_LAST)
+ do_fiemap = 0;
+ }
+ if (do_fiemap) {
+ fe = fm->fm_extents + fm->fm_mapped_extents -1;
+ fm->fm_start = fe->fe_logical + fe->fe_length;
+ } else
+ break;
+ }
+exit_setup_sparse:
+ return (exit_sts);
+}
+
+#elif defined(SEEK_HOLE) && defined(SEEK_DATA) && defined(_PC_MIN_HOLE_SIZE)
+
+/*
+ * FreeBSD and Solaris sparse interface.
+ */
+
+static int
+setup_sparse(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ int64_t size;
+ off_t initial_off; /* FreeBSD/Solaris only, so off_t okay here */
+ off_t off_s, off_e; /* FreeBSD/Solaris only, so off_t okay here */
+ int exit_sts = ARCHIVE_OK;
+
+ if (archive_entry_filetype(entry) != AE_IFREG
+ || archive_entry_size(entry) <= 0
+ || archive_entry_hardlink(entry) != NULL)
+ return (ARCHIVE_OK);
+
+ /* Does filesystem support the reporting of hole ? */
+ if (*fd < 0 && a->tree != NULL) {
+ const char *path;
+
+ path = archive_entry_sourcepath(entry);
+ if (path == NULL)
+ path = archive_entry_pathname(entry);
+ *fd = a->open_on_current_dir(a->tree, path,
+ O_RDONLY | O_NONBLOCK);
+ if (*fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't open `%s'", path);
+ return (ARCHIVE_FAILED);
+ }
+ }
+
+ if (*fd >= 0) {
+ if (fpathconf(*fd, _PC_MIN_HOLE_SIZE) <= 0)
+ return (ARCHIVE_OK);
+ initial_off = lseek(*fd, 0, SEEK_CUR);
+ if (initial_off != 0)
+ lseek(*fd, 0, SEEK_SET);
+ } else {
+ const char *path;
+
+ path = archive_entry_sourcepath(entry);
+ if (path == NULL)
+ path = archive_entry_pathname(entry);
+
+ if (pathconf(path, _PC_MIN_HOLE_SIZE) <= 0)
+ return (ARCHIVE_OK);
+ *fd = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+ if (*fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't open `%s'", path);
+ return (ARCHIVE_FAILED);
+ }
+ __archive_ensure_cloexec_flag(*fd);
+ initial_off = 0;
+ }
+
+ off_s = 0;
+ size = archive_entry_size(entry);
+ while (off_s < size) {
+ off_s = lseek(*fd, off_s, SEEK_DATA);
+ if (off_s == (off_t)-1) {
+ if (errno == ENXIO)
+ break;/* no more hole */
+ archive_set_error(&a->archive, errno,
+ "lseek(SEEK_HOLE) failed");
+ exit_sts = ARCHIVE_FAILED;
+ goto exit_setup_sparse;
+ }
+ off_e = lseek(*fd, off_s, SEEK_HOLE);
+ if (off_e == (off_t)-1) {
+ if (errno == ENXIO) {
+ off_e = lseek(*fd, 0, SEEK_END);
+ if (off_e != (off_t)-1)
+ break;/* no more data */
+ }
+ archive_set_error(&a->archive, errno,
+ "lseek(SEEK_DATA) failed");
+ exit_sts = ARCHIVE_FAILED;
+ goto exit_setup_sparse;
+ }
+ if (off_s == 0 && off_e == size)
+ break;/* This is not spase. */
+ archive_entry_sparse_add_entry(entry, off_s,
+ off_e - off_s);
+ off_s = off_e;
+ }
+exit_setup_sparse:
+ lseek(*fd, initial_off, SEEK_SET);
+ return (exit_sts);
+}
+
+#else
+
+/*
+ * Generic (stub) sparse support.
+ */
+static int
+setup_sparse(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ (void)a; /* UNUSED */
+ (void)entry; /* UNUSED */
+ (void)fd; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+#endif
+
+#endif /* !defined(_WIN32) || defined(__CYGWIN__) */
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c
new file mode 100644
index 0000000000..94eb5e7be2
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c
@@ -0,0 +1,2606 @@
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * Copyright (c) 2010-2012 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
+ * in this position and unchanged.
+ * 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.
+ */
+
+/* This is the tree-walking code for POSIX systems. */
+#if !defined(_WIN32) || defined(__CYGWIN__)
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_MOUNT_H
+#include <sys/mount.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_STATFS_H
+#include <sys/statfs.h>
+#endif
+#ifdef HAVE_SYS_STATVFS_H
+#include <sys/statvfs.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_LINUX_MAGIC_H
+#include <linux/magic.h>
+#endif
+#ifdef HAVE_LINUX_FS_H
+#include <linux/fs.h>
+#endif
+/*
+ * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
+ * As the include guards don't agree, the order of include is important.
+ */
+#ifdef HAVE_LINUX_EXT2_FS_H
+#include <linux/ext2_fs.h> /* for Linux file flags */
+#endif
+#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
+#include <ext2fs/ext2_fs.h> /* Linux file flags, broken on Cygwin */
+#endif
+#ifdef HAVE_DIRECT_H
+#include <direct.h>
+#endif
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#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_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+
+#include "archive.h"
+#include "archive_string.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_disk_private.h"
+
+#ifndef HAVE_FCHDIR
+#error fchdir function required.
+#endif
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
+/*-
+ * This is a new directory-walking system that addresses a number
+ * of problems I've had with fts(3). In particular, it has no
+ * pathname-length limits (other than the size of 'int'), handles
+ * deep logical traversals, uses considerably less memory, and has
+ * an opaque interface (easier to modify in the future).
+ *
+ * Internally, it keeps a single list of "tree_entry" items that
+ * represent filesystem objects that require further attention.
+ * Non-directories are not kept in memory: they are pulled from
+ * readdir(), returned to the client, then freed as soon as possible.
+ * Any directory entry to be traversed gets pushed onto the stack.
+ *
+ * There is surprisingly little information that needs to be kept for
+ * each item on the stack. Just the name, depth (represented here as the
+ * string length of the parent directory's pathname), and some markers
+ * indicating how to get back to the parent (via chdir("..") for a
+ * regular dir or via fchdir(2) for a symlink).
+ */
+/*
+ * TODO:
+ * 1) Loop checking.
+ * 3) Arbitrary logical traversals by closing/reopening intermediate fds.
+ */
+
+struct restore_time {
+ const char *name;
+ time_t mtime;
+ long mtime_nsec;
+ time_t atime;
+ long atime_nsec;
+ mode_t filetype;
+ int noatime;
+};
+
+struct tree_entry {
+ int depth;
+ struct tree_entry *next;
+ struct tree_entry *parent;
+ struct archive_string name;
+ size_t dirname_length;
+ int64_t dev;
+ int64_t ino;
+ int flags;
+ int filesystem_id;
+ /* How to return back to the parent of a symlink. */
+ int symlink_parent_fd;
+ /* How to restore time of a directory. */
+ struct restore_time restore_time;
+};
+
+struct filesystem {
+ int64_t dev;
+ int synthetic;
+ int remote;
+ int noatime;
+#if defined(HAVE_READDIR_R)
+ size_t name_max;
+#endif
+ long incr_xfer_size;
+ long max_xfer_size;
+ long min_xfer_size;
+ long xfer_align;
+
+ /*
+ * Buffer used for reading file contents.
+ */
+ /* Exactly allocated memory pointer. */
+ unsigned char *allocation_ptr;
+ /* Pointer adjusted to the filesystem alignment . */
+ unsigned char *buff;
+ size_t buff_size;
+};
+
+/* Definitions for tree_entry.flags bitmap. */
+#define isDir 1 /* This entry is a regular directory. */
+#define isDirLink 2 /* This entry is a symbolic link to a directory. */
+#define needsFirstVisit 4 /* This is an initial entry. */
+#define needsDescent 8 /* This entry needs to be previsited. */
+#define needsOpen 16 /* This is a directory that needs to be opened. */
+#define needsAscent 32 /* This entry needs to be postvisited. */
+
+/*
+ * Local data for this package.
+ */
+struct tree {
+ struct tree_entry *stack;
+ struct tree_entry *current;
+ DIR *d;
+#define INVALID_DIR_HANDLE NULL
+ struct dirent *de;
+#if defined(HAVE_READDIR_R)
+ struct dirent *dirent;
+ size_t dirent_allocated;
+#endif
+ int flags;
+ int visit_type;
+ /* Error code from last failed operation. */
+ int tree_errno;
+
+ /* Dynamically-sized buffer for holding path */
+ struct archive_string path;
+
+ /* Last path element */
+ const char *basename;
+ /* Leading dir length */
+ size_t dirname_length;
+
+ int depth;
+ int openCount;
+ int maxOpenCount;
+ int initial_dir_fd;
+ int working_dir_fd;
+
+ struct stat lst;
+ struct stat st;
+ int descend;
+ int nlink;
+ /* How to restore time of a file. */
+ struct restore_time restore_time;
+
+ struct entry_sparse {
+ int64_t length;
+ int64_t offset;
+ } *sparse_list, *current_sparse;
+ int sparse_count;
+ int sparse_list_size;
+
+ char initial_symlink_mode;
+ char symlink_mode;
+ struct filesystem *current_filesystem;
+ struct filesystem *filesystem_table;
+ int initial_filesystem_id;
+ int current_filesystem_id;
+ int max_filesystem_id;
+ int allocated_filesytem;
+
+ int entry_fd;
+ int entry_eof;
+ int64_t entry_remaining_bytes;
+ int64_t entry_total;
+ unsigned char *entry_buff;
+ size_t entry_buff_size;
+};
+
+/* Definitions for tree.flags bitmap. */
+#define hasStat 16 /* The st entry is valid. */
+#define hasLstat 32 /* The lst entry is valid. */
+#define onWorkingDir 64 /* We are on the working dir where we are
+ * reading directory entry at this time. */
+#define needsRestoreTimes 128
+#define onInitialDir 256 /* We are on the initial dir. */
+
+static int
+tree_dir_next_posix(struct tree *t);
+
+#ifdef HAVE_DIRENT_D_NAMLEN
+/* BSD extension; avoids need for a strlen() call. */
+#define D_NAMELEN(dp) (dp)->d_namlen
+#else
+#define D_NAMELEN(dp) (strlen((dp)->d_name))
+#endif
+
+/* Initiate/terminate a tree traversal. */
+static struct tree *tree_open(const char *, int, int);
+static struct tree *tree_reopen(struct tree *, const char *, int);
+static void tree_close(struct tree *);
+static void tree_free(struct tree *);
+static void tree_push(struct tree *, const char *, int, int64_t, int64_t,
+ struct restore_time *);
+static int tree_enter_initial_dir(struct tree *);
+static int tree_enter_working_dir(struct tree *);
+static int tree_current_dir_fd(struct tree *);
+
+/*
+ * tree_next() returns Zero if there is no next entry, non-zero if
+ * there is. Note that directories are visited three times.
+ * Directories are always visited first as part of enumerating their
+ * parent; that is a "regular" visit. If tree_descend() is invoked at
+ * that time, the directory is added to a work list and will
+ * subsequently be visited two more times: once just after descending
+ * into the directory ("postdescent") and again just after ascending
+ * back to the parent ("postascent").
+ *
+ * TREE_ERROR_DIR is returned if the descent failed (because the
+ * directory couldn't be opened, for instance). This is returned
+ * instead of TREE_POSTDESCENT/TREE_POSTASCENT. TREE_ERROR_DIR is not a
+ * fatal error, but it does imply that the relevant subtree won't be
+ * visited. TREE_ERROR_FATAL is returned for an error that left the
+ * traversal completely hosed. Right now, this is only returned for
+ * chdir() failures during ascent.
+ */
+#define TREE_REGULAR 1
+#define TREE_POSTDESCENT 2
+#define TREE_POSTASCENT 3
+#define TREE_ERROR_DIR -1
+#define TREE_ERROR_FATAL -2
+
+static int tree_next(struct tree *);
+
+/*
+ * Return information about the current entry.
+ */
+
+/*
+ * The current full pathname, length of the full pathname, and a name
+ * that can be used to access the file. Because tree does use chdir
+ * extensively, the access path is almost never the same as the full
+ * current path.
+ *
+ * TODO: On platforms that support it, use openat()-style operations
+ * to eliminate the chdir() operations entirely while still supporting
+ * arbitrarily deep traversals. This makes access_path troublesome to
+ * support, of course, which means we'll need a rich enough interface
+ * that clients can function without it. (In particular, we'll need
+ * tree_current_open() that returns an open file descriptor.)
+ *
+ */
+static const char *tree_current_path(struct tree *);
+static const char *tree_current_access_path(struct tree *);
+
+/*
+ * Request the lstat() or stat() data for the current path. Since the
+ * tree package needs to do some of this anyway, and caches the
+ * results, you should take advantage of it here if you need it rather
+ * than make a redundant stat() or lstat() call of your own.
+ */
+static const struct stat *tree_current_stat(struct tree *);
+static const struct stat *tree_current_lstat(struct tree *);
+static int tree_current_is_symblic_link_target(struct tree *);
+
+/* The following functions use tricks to avoid a certain number of
+ * stat()/lstat() calls. */
+/* "is_physical_dir" is equivalent to S_ISDIR(tree_current_lstat()->st_mode) */
+static int tree_current_is_physical_dir(struct tree *);
+/* "is_dir" is equivalent to S_ISDIR(tree_current_stat()->st_mode) */
+static int tree_current_is_dir(struct tree *);
+static int update_current_filesystem(struct archive_read_disk *a,
+ int64_t dev);
+static int setup_current_filesystem(struct archive_read_disk *);
+static int tree_target_is_same_as_parent(struct tree *, const struct stat *);
+
+static int _archive_read_disk_open(struct archive *, const char *);
+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_header2(struct archive *,
+ struct archive_entry *);
+static const char *trivial_lookup_gname(void *, int64_t gid);
+static const char *trivial_lookup_uname(void *, int64_t uid);
+static int setup_sparse(struct archive_read_disk *, struct archive_entry *);
+static int close_and_restore_time(int fd, struct tree *,
+ struct restore_time *);
+static int open_on_current_dir(struct tree *, const char *, int);
+static int tree_dup(int);
+
+
+static struct archive_vtable *
+archive_read_disk_vtable(void)
+{
+ static struct archive_vtable av;
+ static int inited = 0;
+
+ if (!inited) {
+ 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_header2 = _archive_read_next_header2;
+ inited = 1;
+ }
+ return (&av);
+}
+
+const char *
+archive_read_disk_gname(struct archive *_a, int64_t gid)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_gname"))
+ return (NULL);
+ if (a->lookup_gname == NULL)
+ return (NULL);
+ return ((*a->lookup_gname)(a->lookup_gname_data, gid));
+}
+
+const char *
+archive_read_disk_uname(struct archive *_a, int64_t uid)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_uname"))
+ return (NULL);
+ if (a->lookup_uname == NULL)
+ return (NULL);
+ return ((*a->lookup_uname)(a->lookup_uname_data, uid));
+}
+
+int
+archive_read_disk_set_gname_lookup(struct archive *_a,
+ void *private_data,
+ const char * (*lookup_gname)(void *private, int64_t gid),
+ void (*cleanup_gname)(void *private))
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_gname_lookup");
+
+ if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL)
+ (a->cleanup_gname)(a->lookup_gname_data);
+
+ a->lookup_gname = lookup_gname;
+ a->cleanup_gname = cleanup_gname;
+ a->lookup_gname_data = private_data;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_uname_lookup(struct archive *_a,
+ void *private_data,
+ const char * (*lookup_uname)(void *private, int64_t uid),
+ void (*cleanup_uname)(void *private))
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_uname_lookup");
+
+ if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL)
+ (a->cleanup_uname)(a->lookup_uname_data);
+
+ a->lookup_uname = lookup_uname;
+ a->cleanup_uname = cleanup_uname;
+ a->lookup_uname_data = private_data;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Create a new archive_read_disk object and initialize it with global state.
+ */
+struct archive *
+archive_read_disk_new(void)
+{
+ struct archive_read_disk *a;
+
+ a = (struct archive_read_disk *)calloc(1, sizeof(*a));
+ if (a == NULL)
+ return (NULL);
+ a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
+ a->archive.state = ARCHIVE_STATE_NEW;
+ a->archive.vtable = archive_read_disk_vtable();
+ a->lookup_uname = trivial_lookup_uname;
+ a->lookup_gname = trivial_lookup_gname;
+ a->enable_copyfile = 1;
+ a->traverse_mount_points = 1;
+ a->open_on_current_dir = open_on_current_dir;
+ a->tree_current_dir_fd = tree_current_dir_fd;
+ a->tree_enter_working_dir = tree_enter_working_dir;
+ return (&a->archive);
+}
+
+static int
+_archive_read_free(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ int r;
+
+ if (_a == NULL)
+ return (ARCHIVE_OK);
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_free");
+
+ if (a->archive.state != ARCHIVE_STATE_CLOSED)
+ r = _archive_read_close(&a->archive);
+ else
+ r = ARCHIVE_OK;
+
+ tree_free(a->tree);
+ if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL)
+ (a->cleanup_gname)(a->lookup_gname_data);
+ if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL)
+ (a->cleanup_uname)(a->lookup_uname_data);
+ archive_string_free(&a->archive.error_string);
+ a->archive.magic = 0;
+ __archive_clean(&a->archive);
+ free(a);
+ return (r);
+}
+
+static int
+_archive_read_close(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_close");
+
+ if (a->archive.state != ARCHIVE_STATE_FATAL)
+ a->archive.state = ARCHIVE_STATE_CLOSED;
+
+ tree_close(a->tree);
+
+ return (ARCHIVE_OK);
+}
+
+static void
+setup_symlink_mode(struct archive_read_disk *a, char symlink_mode,
+ int follow_symlinks)
+{
+ a->symlink_mode = symlink_mode;
+ a->follow_symlinks = follow_symlinks;
+ if (a->tree != NULL) {
+ a->tree->initial_symlink_mode = a->symlink_mode;
+ a->tree->symlink_mode = a->symlink_mode;
+ }
+}
+
+int
+archive_read_disk_set_symlink_logical(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_logical");
+ setup_symlink_mode(a, 'L', 1);
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_symlink_physical(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_physical");
+ setup_symlink_mode(a, 'P', 0);
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_symlink_hybrid(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_hybrid");
+ setup_symlink_mode(a, 'H', 1);/* Follow symlinks initially. */
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_atime_restored(struct archive *_a)
+{
+#ifndef HAVE_UTIMES
+ static int warning_done = 0;
+#endif
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_restore_atime");
+#ifdef HAVE_UTIMES
+ a->restore_time = 1;
+ if (a->tree != NULL)
+ a->tree->flags |= needsRestoreTimes;
+ return (ARCHIVE_OK);
+#else
+ if (warning_done)
+ /* Warning was already emitted; suppress further warnings. */
+ return (ARCHIVE_OK);
+
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Cannot restore access time on this system");
+ warning_done = 1;
+ return (ARCHIVE_WARN);
+#endif
+}
+
+int
+archive_read_disk_set_behavior(struct archive *_a, int flags)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ int r = ARCHIVE_OK;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_honor_nodump");
+
+ if (flags & ARCHIVE_READDISK_RESTORE_ATIME)
+ r = archive_read_disk_set_atime_restored(_a);
+ else {
+ a->restore_time = 0;
+ if (a->tree != NULL)
+ a->tree->flags &= ~needsRestoreTimes;
+ }
+ if (flags & ARCHIVE_READDISK_HONOR_NODUMP)
+ a->honor_nodump = 1;
+ else
+ a->honor_nodump = 0;
+ if (flags & ARCHIVE_READDISK_MAC_COPYFILE)
+ a->enable_copyfile = 1;
+ else
+ a->enable_copyfile = 0;
+ if (flags & ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS)
+ a->traverse_mount_points = 0;
+ else
+ a->traverse_mount_points = 1;
+ return (r);
+}
+
+/*
+ * Trivial implementations of gname/uname lookup functions.
+ * These are normally overridden by the client, but these stub
+ * versions ensure that we always have something that works.
+ */
+static const char *
+trivial_lookup_gname(void *private_data, int64_t gid)
+{
+ (void)private_data; /* UNUSED */
+ (void)gid; /* UNUSED */
+ return (NULL);
+}
+
+static const char *
+trivial_lookup_uname(void *private_data, int64_t uid)
+{
+ (void)private_data; /* UNUSED */
+ (void)uid; /* UNUSED */
+ return (NULL);
+}
+
+/*
+ * Allocate memory for the reading buffer adjusted to the filesystem
+ * alignment.
+ */
+static int
+setup_suitable_read_buffer(struct archive_read_disk *a)
+{
+ struct tree *t = a->tree;
+ struct filesystem *cf = t->current_filesystem;
+ size_t asize;
+ size_t s;
+
+ if (cf->allocation_ptr == NULL) {
+ /* If we couldn't get a filesystem alignment,
+ * we use 4096 as default value but we won't use
+ * O_DIRECT to open() and openat() operations. */
+ long xfer_align = (cf->xfer_align == -1)?4096:cf->xfer_align;
+
+ if (cf->max_xfer_size != -1)
+ asize = cf->max_xfer_size + xfer_align;
+ else {
+ long incr = cf->incr_xfer_size;
+ /* Some platform does not set a proper value to
+ * incr_xfer_size.*/
+ if (incr < 0)
+ incr = cf->min_xfer_size;
+ if (cf->min_xfer_size < 0) {
+ incr = xfer_align;
+ asize = xfer_align;
+ } else
+ asize = cf->min_xfer_size;
+
+ /* Increase a buffer size up to 64K bytes in
+ * a proper incremant size. */
+ while (asize < 1024*64)
+ asize += incr;
+ /* Take a margin to adjust to the filesystem
+ * alignment. */
+ asize += xfer_align;
+ }
+ cf->allocation_ptr = malloc(asize);
+ if (cf->allocation_ptr == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't allocate memory");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Calculate proper address for the filesystem.
+ */
+ s = (uintptr_t)cf->allocation_ptr;
+ s %= xfer_align;
+ if (s > 0)
+ s = xfer_align - s;
+
+ /*
+ * Set a read buffer pointer in the proper alignment of
+ * the current filesystem.
+ */
+ cf->buff = cf->allocation_ptr + s;
+ cf->buff_size = asize - xfer_align;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+_archive_read_data_block(struct archive *_a, const void **buff,
+ size_t *size, int64_t *offset)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct tree *t = a->tree;
+ int r;
+ ssize_t bytes;
+ size_t buffbytes;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_data_block");
+
+ if (t->entry_eof || t->entry_remaining_bytes <= 0) {
+ r = ARCHIVE_EOF;
+ goto abort_read_data;
+ }
+
+ /*
+ * Open the current file.
+ */
+ if (t->entry_fd < 0) {
+ int flags = O_RDONLY | O_BINARY | O_CLOEXEC;
+
+ /*
+ * Eliminate or reduce cache effects if we can.
+ *
+ * Carefully consider this to be enabled.
+ */
+#if defined(O_DIRECT) && 0/* Disabled for now */
+ if (t->current_filesystem->xfer_align != -1 &&
+ t->nlink == 1)
+ flags |= O_DIRECT;
+#endif
+#if defined(O_NOATIME)
+ /*
+ * Linux has O_NOATIME flag; use it if we need.
+ */
+ if ((t->flags & needsRestoreTimes) != 0 &&
+ t->restore_time.noatime == 0)
+ flags |= O_NOATIME;
+ do {
+#endif
+ t->entry_fd = open_on_current_dir(t,
+ tree_current_access_path(t), flags);
+ __archive_ensure_cloexec_flag(t->entry_fd);
+#if defined(O_NOATIME)
+ /*
+ * When we did open the file with O_NOATIME flag,
+ * if successful, set 1 to t->restore_time.noatime
+ * not to restore an atime of the file later.
+ * if failed by EPERM, retry it without O_NOATIME flag.
+ */
+ if (flags & O_NOATIME) {
+ if (t->entry_fd >= 0)
+ t->restore_time.noatime = 1;
+ else if (errno == EPERM) {
+ flags &= ~O_NOATIME;
+ continue;
+ }
+ }
+ } while (0);
+#endif
+ if (t->entry_fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't open %s", tree_current_path(t));
+ r = ARCHIVE_FAILED;
+ tree_enter_initial_dir(t);
+ goto abort_read_data;
+ }
+ tree_enter_initial_dir(t);
+ }
+
+ /*
+ * Allocate read buffer if not allocated.
+ */
+ if (t->current_filesystem->allocation_ptr == NULL) {
+ r = setup_suitable_read_buffer(a);
+ if (r != ARCHIVE_OK) {
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ goto abort_read_data;
+ }
+ }
+ t->entry_buff = t->current_filesystem->buff;
+ t->entry_buff_size = t->current_filesystem->buff_size;
+
+ buffbytes = t->entry_buff_size;
+ if ((int64_t)buffbytes > t->current_sparse->length)
+ buffbytes = t->current_sparse->length;
+
+ /*
+ * Skip hole.
+ * TODO: Should we consider t->current_filesystem->xfer_align?
+ */
+ if (t->current_sparse->offset > t->entry_total) {
+ if (lseek(t->entry_fd,
+ (off_t)t->current_sparse->offset, SEEK_SET) < 0) {
+ archive_set_error(&a->archive, errno, "Seek error");
+ r = ARCHIVE_FATAL;
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ goto abort_read_data;
+ }
+ bytes = t->current_sparse->offset - t->entry_total;
+ t->entry_remaining_bytes -= bytes;
+ t->entry_total += bytes;
+ }
+
+ /*
+ * Read file contents.
+ */
+ if (buffbytes > 0) {
+ bytes = read(t->entry_fd, t->entry_buff, buffbytes);
+ if (bytes < 0) {
+ archive_set_error(&a->archive, errno, "Read error");
+ r = ARCHIVE_FATAL;
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ goto abort_read_data;
+ }
+ } else
+ bytes = 0;
+ if (bytes == 0) {
+ /* Get EOF */
+ t->entry_eof = 1;
+ r = ARCHIVE_EOF;
+ goto abort_read_data;
+ }
+ *buff = t->entry_buff;
+ *size = bytes;
+ *offset = t->entry_total;
+ t->entry_total += bytes;
+ t->entry_remaining_bytes -= bytes;
+ if (t->entry_remaining_bytes == 0) {
+ /* Close the current file descriptor */
+ close_and_restore_time(t->entry_fd, t, &t->restore_time);
+ t->entry_fd = -1;
+ t->entry_eof = 1;
+ }
+ t->current_sparse->offset += bytes;
+ t->current_sparse->length -= bytes;
+ if (t->current_sparse->length == 0 && !t->entry_eof)
+ t->current_sparse++;
+ return (ARCHIVE_OK);
+
+abort_read_data:
+ *buff = NULL;
+ *size = 0;
+ *offset = t->entry_total;
+ if (t->entry_fd >= 0) {
+ /* Close the current file descriptor */
+ close_and_restore_time(t->entry_fd, t, &t->restore_time);
+ t->entry_fd = -1;
+ }
+ return (r);
+}
+
+static int
+next_entry(struct archive_read_disk *a, struct tree *t,
+ struct archive_entry *entry)
+{
+ const struct stat *st; /* info to use for this entry */
+ const struct stat *lst;/* lstat() information */
+ const char *name;
+ int descend, r;
+
+ st = NULL;
+ lst = NULL;
+ t->descend = 0;
+ do {
+ switch (tree_next(t)) {
+ case TREE_ERROR_FATAL:
+ archive_set_error(&a->archive, t->tree_errno,
+ "%s: Unable to continue traversing directory tree",
+ tree_current_path(t));
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ tree_enter_initial_dir(t);
+ return (ARCHIVE_FATAL);
+ case TREE_ERROR_DIR:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s: Couldn't visit directory",
+ tree_current_path(t));
+ tree_enter_initial_dir(t);
+ return (ARCHIVE_FAILED);
+ case 0:
+ tree_enter_initial_dir(t);
+ return (ARCHIVE_EOF);
+ case TREE_POSTDESCENT:
+ case TREE_POSTASCENT:
+ break;
+ case TREE_REGULAR:
+ lst = tree_current_lstat(t);
+ if (lst == NULL) {
+ archive_set_error(&a->archive, errno,
+ "%s: Cannot stat",
+ tree_current_path(t));
+ tree_enter_initial_dir(t);
+ return (ARCHIVE_FAILED);
+ }
+ break;
+ }
+ } while (lst == NULL);
+
+#ifdef __APPLE__
+ if (a->enable_copyfile) {
+ /* If we're using copyfile(), ignore "._XXX" files. */
+ const char *bname = strrchr(tree_current_path(t), '/');
+ if (bname == NULL)
+ bname = tree_current_path(t);
+ else
+ ++bname;
+ if (bname[0] == '.' && bname[1] == '_')
+ return (ARCHIVE_RETRY);
+ }
+#endif
+
+ archive_entry_copy_pathname(entry, tree_current_path(t));
+ /*
+ * Perform path matching.
+ */
+ if (a->matching) {
+ r = archive_match_path_excluded(a->matching, entry);
+ if (r < 0) {
+ archive_set_error(&(a->archive), errno,
+ "Faild : %s", archive_error_string(a->matching));
+ return (r);
+ }
+ if (r) {
+ if (a->excluded_cb_func)
+ a->excluded_cb_func(&(a->archive),
+ a->excluded_cb_data, entry);
+ return (ARCHIVE_RETRY);
+ }
+ }
+
+ /*
+ * Distinguish 'L'/'P'/'H' symlink following.
+ */
+ switch(t->symlink_mode) {
+ case 'H':
+ /* 'H': After the first item, rest like 'P'. */
+ t->symlink_mode = 'P';
+ /* 'H': First item (from command line) like 'L'. */
+ /* FALLTHROUGH */
+ case 'L':
+ /* 'L': Do descend through a symlink to dir. */
+ descend = tree_current_is_dir(t);
+ /* 'L': Follow symlinks to files. */
+ a->symlink_mode = 'L';
+ a->follow_symlinks = 1;
+ /* 'L': Archive symlinks as targets, if we can. */
+ st = tree_current_stat(t);
+ if (st != NULL && !tree_target_is_same_as_parent(t, st))
+ break;
+ /* If stat fails, we have a broken symlink;
+ * in that case, don't follow the link. */
+ /* FALLTHROUGH */
+ default:
+ /* 'P': Don't descend through a symlink to dir. */
+ descend = tree_current_is_physical_dir(t);
+ /* 'P': Don't follow symlinks to files. */
+ a->symlink_mode = 'P';
+ a->follow_symlinks = 0;
+ /* 'P': Archive symlinks as symlinks. */
+ st = lst;
+ break;
+ }
+
+ if (update_current_filesystem(a, st->st_dev) != ARCHIVE_OK) {
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ tree_enter_initial_dir(t);
+ return (ARCHIVE_FATAL);
+ }
+ if (t->initial_filesystem_id == -1)
+ 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);
+ }
+ t->descend = descend;
+
+ /*
+ * Honor nodump flag.
+ * If the file is marked with nodump flag, do not return this entry.
+ */
+ if (a->honor_nodump) {
+#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
+ if (st->st_flags & UF_NODUMP)
+ return (ARCHIVE_RETRY);
+#elif defined(EXT2_IOC_GETFLAGS) && defined(EXT2_NODUMP_FL) &&\
+ defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)
+ if (S_ISREG(st->st_mode) || S_ISDIR(st->st_mode)) {
+ int stflags;
+
+ t->entry_fd = open_on_current_dir(t,
+ tree_current_access_path(t),
+ O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(t->entry_fd);
+ if (t->entry_fd >= 0) {
+ r = ioctl(t->entry_fd, EXT2_IOC_GETFLAGS,
+ &stflags);
+ if (r == 0 && (stflags & EXT2_NODUMP_FL) != 0)
+ return (ARCHIVE_RETRY);
+ }
+ }
+#endif
+ }
+
+ archive_entry_copy_stat(entry, st);
+
+ /* Save the times to be restored. This must be in before
+ * calling archive_read_disk_descend() or any chance of it,
+ * especially, invokng a callback. */
+ t->restore_time.mtime = archive_entry_mtime(entry);
+ t->restore_time.mtime_nsec = archive_entry_mtime_nsec(entry);
+ t->restore_time.atime = archive_entry_atime(entry);
+ t->restore_time.atime_nsec = archive_entry_atime_nsec(entry);
+ t->restore_time.filetype = archive_entry_filetype(entry);
+ t->restore_time.noatime = t->current_filesystem->noatime;
+
+ /*
+ * Perform time matching.
+ */
+ if (a->matching) {
+ r = archive_match_time_excluded(a->matching, entry);
+ if (r < 0) {
+ archive_set_error(&(a->archive), errno,
+ "Faild : %s", archive_error_string(a->matching));
+ return (r);
+ }
+ if (r) {
+ if (a->excluded_cb_func)
+ a->excluded_cb_func(&(a->archive),
+ a->excluded_cb_data, entry);
+ return (ARCHIVE_RETRY);
+ }
+ }
+
+ /* Lookup uname/gname */
+ name = archive_read_disk_uname(&(a->archive), archive_entry_uid(entry));
+ if (name != NULL)
+ archive_entry_copy_uname(entry, name);
+ name = archive_read_disk_gname(&(a->archive), archive_entry_gid(entry));
+ if (name != NULL)
+ archive_entry_copy_gname(entry, name);
+
+ /*
+ * Perform owner matching.
+ */
+ if (a->matching) {
+ r = archive_match_owner_excluded(a->matching, entry);
+ if (r < 0) {
+ archive_set_error(&(a->archive), errno,
+ "Faild : %s", archive_error_string(a->matching));
+ return (r);
+ }
+ if (r) {
+ if (a->excluded_cb_func)
+ a->excluded_cb_func(&(a->archive),
+ a->excluded_cb_data, entry);
+ return (ARCHIVE_RETRY);
+ }
+ }
+
+ /*
+ * Invoke a meta data filter callback.
+ */
+ if (a->metadata_filter_func) {
+ if (!a->metadata_filter_func(&(a->archive),
+ a->metadata_filter_data, entry))
+ return (ARCHIVE_RETRY);
+ }
+
+ /*
+ * Populate the archive_entry with metadata from the disk.
+ */
+ archive_entry_copy_sourcepath(entry, tree_current_access_path(t));
+ r = archive_read_disk_entry_from_file(&(a->archive), entry,
+ t->entry_fd, st);
+
+ return (r);
+}
+
+static int
+_archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct tree *t;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_read_next_header2");
+
+ t = a->tree;
+ if (t->entry_fd >= 0) {
+ close_and_restore_time(t->entry_fd, t, &t->restore_time);
+ t->entry_fd = -1;
+ }
+
+ for (;;) {
+ r = next_entry(a, t, entry);
+ if (t->entry_fd >= 0) {
+ close(t->entry_fd);
+ t->entry_fd = -1;
+ }
+
+ if (r == ARCHIVE_RETRY) {
+ archive_entry_clear(entry);
+ continue;
+ }
+ break;
+ }
+
+ /* Return to the initial directory. */
+ tree_enter_initial_dir(t);
+
+ /*
+ * EOF and FATAL are persistent at this layer. By
+ * modifying the state, we guarantee that future calls to
+ * read a header or read data will fail.
+ */
+ switch (r) {
+ case ARCHIVE_EOF:
+ a->archive.state = ARCHIVE_STATE_EOF;
+ break;
+ case ARCHIVE_OK:
+ case ARCHIVE_WARN:
+ /* Overwrite the sourcepath based on the initial directory. */
+ archive_entry_copy_sourcepath(entry, tree_current_path(t));
+ t->entry_total = 0;
+ if (archive_entry_filetype(entry) == AE_IFREG) {
+ t->nlink = archive_entry_nlink(entry);
+ t->entry_remaining_bytes = archive_entry_size(entry);
+ t->entry_eof = (t->entry_remaining_bytes == 0)? 1: 0;
+ if (!t->entry_eof &&
+ setup_sparse(a, entry) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } else {
+ t->entry_remaining_bytes = 0;
+ t->entry_eof = 1;
+ }
+ a->archive.state = ARCHIVE_STATE_DATA;
+ break;
+ case ARCHIVE_RETRY:
+ break;
+ case ARCHIVE_FATAL:
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ break;
+ }
+
+ return (r);
+}
+
+static int
+setup_sparse(struct archive_read_disk *a, struct archive_entry *entry)
+{
+ struct tree *t = a->tree;
+ int64_t length, offset;
+ int i;
+
+ t->sparse_count = archive_entry_sparse_reset(entry);
+ if (t->sparse_count+1 > t->sparse_list_size) {
+ free(t->sparse_list);
+ t->sparse_list_size = t->sparse_count + 1;
+ t->sparse_list = malloc(sizeof(t->sparse_list[0]) *
+ t->sparse_list_size);
+ if (t->sparse_list == NULL) {
+ t->sparse_list_size = 0;
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate data");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ }
+ for (i = 0; i < t->sparse_count; i++) {
+ archive_entry_sparse_next(entry, &offset, &length);
+ t->sparse_list[i].offset = offset;
+ t->sparse_list[i].length = length;
+ }
+ if (i == 0) {
+ t->sparse_list[i].offset = 0;
+ t->sparse_list[i].length = archive_entry_size(entry);
+ } else {
+ t->sparse_list[i].offset = archive_entry_size(entry);
+ t->sparse_list[i].length = 0;
+ }
+ t->current_sparse = t->sparse_list;
+
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_matching(struct archive *_a, struct archive *_ma,
+ void (*_excluded_func)(struct archive *, void *, struct archive_entry *),
+ void *_client_data)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_matching");
+ a->matching = _ma;
+ a->excluded_cb_func = _excluded_func;
+ a->excluded_cb_data = _client_data;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_metadata_filter_callback(struct archive *_a,
+ int (*_metadata_filter_func)(struct archive *, void *,
+ struct archive_entry *), void *_client_data)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_ANY,
+ "archive_read_disk_set_metadata_filter_callback");
+
+ a->metadata_filter_func = _metadata_filter_func;
+ a->metadata_filter_data = _client_data;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_can_descend(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct tree *t = a->tree;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_read_disk_can_descend");
+
+ return (t->visit_type == TREE_REGULAR && t->descend);
+}
+
+/*
+ * Called by the client to mark the directory just returned from
+ * tree_next() as needing to be visited.
+ */
+int
+archive_read_disk_descend(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct tree *t = a->tree;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_read_disk_descend");
+
+ if (t->visit_type != TREE_REGULAR || !t->descend)
+ return (ARCHIVE_OK);
+
+ if (tree_current_is_physical_dir(t)) {
+ tree_push(t, t->basename, t->current_filesystem_id,
+ t->lst.st_dev, t->lst.st_ino, &t->restore_time);
+ t->stack->flags |= isDir;
+ } else if (tree_current_is_dir(t)) {
+ tree_push(t, t->basename, t->current_filesystem_id,
+ t->st.st_dev, t->st.st_ino, &t->restore_time);
+ t->stack->flags |= isDirLink;
+ }
+ t->descend = 0;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_open(struct archive *_a, const char *pathname)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_NEW | ARCHIVE_STATE_CLOSED,
+ "archive_read_disk_open");
+ archive_clear_error(&a->archive);
+
+ return (_archive_read_disk_open(_a, pathname));
+}
+
+int
+archive_read_disk_open_w(struct archive *_a, const wchar_t *pathname)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct archive_string path;
+ int ret;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_NEW | ARCHIVE_STATE_CLOSED,
+ "archive_read_disk_open_w");
+ archive_clear_error(&a->archive);
+
+ /* Make a char string from a wchar_t string. */
+ archive_string_init(&path);
+ if (archive_string_append_from_wcs(&path, pathname,
+ wcslen(pathname)) != 0) {
+ if (errno == ENOMEM)
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't convert a path to a char string");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ ret = ARCHIVE_FATAL;
+ } else
+ ret = _archive_read_disk_open(_a, path.s);
+
+ archive_string_free(&path);
+ return (ret);
+}
+
+static int
+_archive_read_disk_open(struct archive *_a, const char *pathname)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ if (a->tree != NULL)
+ a->tree = tree_reopen(a->tree, pathname, a->restore_time);
+ else
+ a->tree = tree_open(pathname, a->symlink_mode,
+ a->restore_time);
+ if (a->tree == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate tar data");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ a->archive.state = ARCHIVE_STATE_HEADER;
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Return a current filesystem ID which is index of the filesystem entry
+ * you've visited through archive_read_disk.
+ */
+int
+archive_read_disk_current_filesystem(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_disk_current_filesystem");
+
+ return (a->tree->current_filesystem_id);
+}
+
+static int
+update_current_filesystem(struct archive_read_disk *a, int64_t dev)
+{
+ struct tree *t = a->tree;
+ int i, fid;
+
+ if (t->current_filesystem != NULL &&
+ t->current_filesystem->dev == dev)
+ return (ARCHIVE_OK);
+
+ for (i = 0; i < t->max_filesystem_id; i++) {
+ if (t->filesystem_table[i].dev == dev) {
+ /* There is the filesytem ID we've already generated. */
+ t->current_filesystem_id = i;
+ t->current_filesystem = &(t->filesystem_table[i]);
+ return (ARCHIVE_OK);
+ }
+ }
+
+ /*
+ * This is the new filesytem which we have to generate a new ID for.
+ */
+ fid = t->max_filesystem_id++;
+ if (t->max_filesystem_id > t->allocated_filesytem) {
+ size_t s;
+ void *p;
+
+ s = t->max_filesystem_id * 2;
+ p = realloc(t->filesystem_table,
+ s * sizeof(*t->filesystem_table));
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate tar data");
+ return (ARCHIVE_FATAL);
+ }
+ t->filesystem_table = (struct filesystem *)p;
+ t->allocated_filesytem = s;
+ }
+ t->current_filesystem_id = fid;
+ t->current_filesystem = &(t->filesystem_table[fid]);
+ t->current_filesystem->dev = dev;
+ t->current_filesystem->allocation_ptr = NULL;
+ t->current_filesystem->buff = NULL;
+
+ /* Setup the current filesystem properties which depend on
+ * platform specific. */
+ return (setup_current_filesystem(a));
+}
+
+/*
+ * Returns 1 if current filesystem is generated filesystem, 0 if it is not
+ * or -1 if it is unknown.
+ */
+int
+archive_read_disk_current_filesystem_is_synthetic(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_disk_current_filesystem");
+
+ return (a->tree->current_filesystem->synthetic);
+}
+
+/*
+ * Returns 1 if current filesystem is remote filesystem, 0 if it is not
+ * or -1 if it is unknown.
+ */
+int
+archive_read_disk_current_filesystem_is_remote(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_disk_current_filesystem");
+
+ return (a->tree->current_filesystem->remote);
+}
+
+#if defined(_PC_REC_INCR_XFER_SIZE) && defined(_PC_REC_MAX_XFER_SIZE) &&\
+ defined(_PC_REC_MIN_XFER_SIZE) && defined(_PC_REC_XFER_ALIGN)
+static int
+get_xfer_size(struct tree *t, int fd, const char *path)
+{
+ t->current_filesystem->xfer_align = -1;
+ errno = 0;
+ if (fd >= 0) {
+ t->current_filesystem->incr_xfer_size =
+ fpathconf(fd, _PC_REC_INCR_XFER_SIZE);
+ t->current_filesystem->max_xfer_size =
+ fpathconf(fd, _PC_REC_MAX_XFER_SIZE);
+ t->current_filesystem->min_xfer_size =
+ fpathconf(fd, _PC_REC_MIN_XFER_SIZE);
+ t->current_filesystem->xfer_align =
+ fpathconf(fd, _PC_REC_XFER_ALIGN);
+ } else if (path != NULL) {
+ t->current_filesystem->incr_xfer_size =
+ pathconf(path, _PC_REC_INCR_XFER_SIZE);
+ t->current_filesystem->max_xfer_size =
+ pathconf(path, _PC_REC_MAX_XFER_SIZE);
+ t->current_filesystem->min_xfer_size =
+ pathconf(path, _PC_REC_MIN_XFER_SIZE);
+ t->current_filesystem->xfer_align =
+ pathconf(path, _PC_REC_XFER_ALIGN);
+ }
+ /* At least we need an alignment size. */
+ if (t->current_filesystem->xfer_align == -1)
+ return ((errno == EINVAL)?1:-1);
+ else
+ return (0);
+}
+#else
+static int
+get_xfer_size(struct tree *t, int fd, const char *path)
+{
+ (void)t; /* UNUSED */
+ (void)fd; /* UNUSED */
+ (void)path; /* UNUSED */
+ return (1);/* Not supported */
+}
+#endif
+
+#if defined(HAVE_STATFS) && defined(HAVE_FSTATFS) && defined(MNT_LOCAL) \
+ && !defined(ST_LOCAL)
+
+/*
+ * Gather current filesystem properties on FreeBSD, OpenBSD and Mac OS X.
+ */
+static int
+setup_current_filesystem(struct archive_read_disk *a)
+{
+ struct tree *t = a->tree;
+ struct statfs sfs;
+#if defined(HAVE_GETVFSBYNAME) && defined(VFCF_SYNTHETIC)
+ struct xvfsconf vfc;
+#endif
+ int r, xr = 0;
+#if !defined(HAVE_STRUCT_STATFS_F_NAMEMAX)
+ long nm;
+#endif
+
+ t->current_filesystem->synthetic = -1;
+ t->current_filesystem->remote = -1;
+ if (tree_current_is_symblic_link_target(t)) {
+#if defined(HAVE_OPENAT)
+ /*
+ * Get file system statistics on any directory
+ * where current is.
+ */
+ int fd = openat(tree_current_dir_fd(t),
+ tree_current_access_path(t), O_RDONLY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(fd);
+ if (fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "openat failed");
+ return (ARCHIVE_FAILED);
+ }
+ r = fstatfs(fd, &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, fd, NULL);
+ close(fd);
+#else
+ if (tree_enter_working_dir(t) != 0) {
+ archive_set_error(&a->archive, errno, "fchdir failed");
+ return (ARCHIVE_FAILED);
+ }
+ r = statfs(tree_current_access_path(t), &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, -1, tree_current_access_path(t));
+#endif
+ } else {
+ r = fstatfs(tree_current_dir_fd(t), &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, tree_current_dir_fd(t), NULL);
+ }
+ if (r == -1 || xr == -1) {
+ archive_set_error(&a->archive, errno, "statfs failed");
+ return (ARCHIVE_FAILED);
+ } else if (xr == 1) {
+ /* pathconf(_PC_REX_*) operations are not supported. */
+ t->current_filesystem->xfer_align = sfs.f_bsize;
+ t->current_filesystem->max_xfer_size = -1;
+ t->current_filesystem->min_xfer_size = sfs.f_iosize;
+ t->current_filesystem->incr_xfer_size = sfs.f_iosize;
+ }
+ if (sfs.f_flags & MNT_LOCAL)
+ t->current_filesystem->remote = 0;
+ else
+ t->current_filesystem->remote = 1;
+
+#if defined(HAVE_GETVFSBYNAME) && defined(VFCF_SYNTHETIC)
+ r = getvfsbyname(sfs.f_fstypename, &vfc);
+ if (r == -1) {
+ archive_set_error(&a->archive, errno, "getvfsbyname failed");
+ return (ARCHIVE_FAILED);
+ }
+ if (vfc.vfc_flags & VFCF_SYNTHETIC)
+ t->current_filesystem->synthetic = 1;
+ else
+ t->current_filesystem->synthetic = 0;
+#endif
+
+#if defined(MNT_NOATIME)
+ if (sfs.f_flags & MNT_NOATIME)
+ t->current_filesystem->noatime = 1;
+ else
+#endif
+ t->current_filesystem->noatime = 0;
+
+#if defined(HAVE_READDIR_R)
+ /* Set maximum filename length. */
+#if defined(HAVE_STRUCT_STATFS_F_NAMEMAX)
+ t->current_filesystem->name_max = sfs.f_namemax;
+#else
+ /* Mac OS X does not have f_namemax in struct statfs. */
+ if (tree_current_is_symblic_link_target(t)) {
+ if (tree_enter_working_dir(t) != 0) {
+ archive_set_error(&a->archive, errno, "fchdir failed");
+ return (ARCHIVE_FAILED);
+ }
+ nm = pathconf(tree_current_access_path(t), _PC_NAME_MAX);
+ } else
+ nm = fpathconf(tree_current_dir_fd(t), _PC_NAME_MAX);
+ if (nm == -1)
+ t->current_filesystem->name_max = NAME_MAX;
+ else
+ t->current_filesystem->name_max = nm;
+#endif
+#endif /* HAVE_READDIR_R */
+ return (ARCHIVE_OK);
+}
+
+#elif (defined(HAVE_STATVFS) || defined(HAVE_FSTATVFS)) && defined(ST_LOCAL)
+
+/*
+ * Gather current filesystem properties on NetBSD
+ */
+static int
+setup_current_filesystem(struct archive_read_disk *a)
+{
+ struct tree *t = a->tree;
+ struct statvfs sfs;
+ int r, xr = 0;
+
+ t->current_filesystem->synthetic = -1;
+ if (tree_enter_working_dir(t) != 0) {
+ archive_set_error(&a->archive, errno, "fchdir failed");
+ return (ARCHIVE_FAILED);
+ }
+ if (tree_current_is_symblic_link_target(t)) {
+ r = statvfs(tree_current_access_path(t), &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, -1, tree_current_access_path(t));
+ } else {
+#ifdef HAVE_FSTATVFS
+ r = fstatvfs(tree_current_dir_fd(t), &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, tree_current_dir_fd(t), NULL);
+#else
+ r = statvfs(".", &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, -1, ".");
+#endif
+ }
+ if (r == -1 || xr == -1) {
+ t->current_filesystem->remote = -1;
+ archive_set_error(&a->archive, errno, "statvfs failed");
+ return (ARCHIVE_FAILED);
+ } else if (xr == 1) {
+ /* Usuall come here unless NetBSD supports _PC_REC_XFER_ALIGN
+ * for pathconf() function. */
+ t->current_filesystem->xfer_align = sfs.f_frsize;
+ t->current_filesystem->max_xfer_size = -1;
+#if defined(HAVE_STRUCT_STATVFS_F_IOSIZE)
+ t->current_filesystem->min_xfer_size = sfs.f_iosize;
+ t->current_filesystem->incr_xfer_size = sfs.f_iosize;
+#else
+ t->current_filesystem->min_xfer_size = sfs.f_bsize;
+ t->current_filesystem->incr_xfer_size = sfs.f_bsize;
+#endif
+ }
+ if (sfs.f_flag & ST_LOCAL)
+ t->current_filesystem->remote = 0;
+ else
+ t->current_filesystem->remote = 1;
+
+#if defined(ST_NOATIME)
+ if (sfs.f_flag & ST_NOATIME)
+ t->current_filesystem->noatime = 1;
+ else
+#endif
+ t->current_filesystem->noatime = 0;
+
+ /* Set maximum filename length. */
+ t->current_filesystem->name_max = sfs.f_namemax;
+ return (ARCHIVE_OK);
+}
+
+#elif defined(HAVE_SYS_STATFS_H) && defined(HAVE_LINUX_MAGIC_H) &&\
+ defined(HAVE_STATFS) && defined(HAVE_FSTATFS)
+/*
+ * Note: statfs is deprecated since LSB 3.2
+ */
+
+#ifndef CIFS_SUPER_MAGIC
+#define CIFS_SUPER_MAGIC 0xFF534D42
+#endif
+#ifndef DEVFS_SUPER_MAGIC
+#define DEVFS_SUPER_MAGIC 0x1373
+#endif
+
+/*
+ * Gather current filesystem properties on Linux
+ */
+static int
+setup_current_filesystem(struct archive_read_disk *a)
+{
+ struct tree *t = a->tree;
+ struct statfs sfs;
+ struct statvfs svfs;
+ int r, vr = 0, xr = 0;
+
+ if (tree_current_is_symblic_link_target(t)) {
+#if defined(HAVE_OPENAT)
+ /*
+ * Get file system statistics on any directory
+ * where current is.
+ */
+ int fd = openat(tree_current_dir_fd(t),
+ tree_current_access_path(t), O_RDONLY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(fd);
+ if (fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "openat failed");
+ return (ARCHIVE_FAILED);
+ }
+ vr = fstatvfs(fd, &svfs);/* for f_flag, mount flags */
+ r = fstatfs(fd, &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, fd, NULL);
+ close(fd);
+#else
+ if (tree_enter_working_dir(t) != 0) {
+ archive_set_error(&a->archive, errno, "fchdir failed");
+ return (ARCHIVE_FAILED);
+ }
+ vr = statvfs(tree_current_access_path(t), &svfs);
+ r = statfs(tree_current_access_path(t), &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, -1, tree_current_access_path(t));
+#endif
+ } else {
+#ifdef HAVE_FSTATFS
+ vr = fstatvfs(tree_current_dir_fd(t), &svfs);
+ r = fstatfs(tree_current_dir_fd(t), &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, tree_current_dir_fd(t), NULL);
+#else
+ if (tree_enter_working_dir(t) != 0) {
+ archive_set_error(&a->archive, errno, "fchdir failed");
+ return (ARCHIVE_FAILED);
+ }
+ vr = statvfs(".", &svfs);
+ r = statfs(".", &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, -1, ".");
+#endif
+ }
+ if (r == -1 || xr == -1 || vr == -1) {
+ t->current_filesystem->synthetic = -1;
+ t->current_filesystem->remote = -1;
+ archive_set_error(&a->archive, errno, "statfs failed");
+ return (ARCHIVE_FAILED);
+ } else if (xr == 1) {
+ /* pathconf(_PC_REX_*) operations are not supported. */
+ t->current_filesystem->xfer_align = svfs.f_frsize;
+ t->current_filesystem->max_xfer_size = -1;
+ t->current_filesystem->min_xfer_size = svfs.f_bsize;
+ t->current_filesystem->incr_xfer_size = svfs.f_bsize;
+ }
+ switch (sfs.f_type) {
+ case AFS_SUPER_MAGIC:
+ case CIFS_SUPER_MAGIC:
+ case CODA_SUPER_MAGIC:
+ case NCP_SUPER_MAGIC:/* NetWare */
+ case NFS_SUPER_MAGIC:
+ case SMB_SUPER_MAGIC:
+ t->current_filesystem->remote = 1;
+ t->current_filesystem->synthetic = 0;
+ break;
+ case DEVFS_SUPER_MAGIC:
+ case PROC_SUPER_MAGIC:
+ case USBDEVICE_SUPER_MAGIC:
+ t->current_filesystem->remote = 0;
+ t->current_filesystem->synthetic = 1;
+ break;
+ default:
+ t->current_filesystem->remote = 0;
+ t->current_filesystem->synthetic = 0;
+ break;
+ }
+
+#if defined(ST_NOATIME)
+ if (svfs.f_flag & ST_NOATIME)
+ t->current_filesystem->noatime = 1;
+ else
+#endif
+ t->current_filesystem->noatime = 0;
+
+#if defined(HAVE_READDIR_R)
+ /* Set maximum filename length. */
+ t->current_filesystem->name_max = sfs.f_namelen;
+#endif
+ return (ARCHIVE_OK);
+}
+
+#elif defined(HAVE_SYS_STATVFS_H) &&\
+ (defined(HAVE_STATVFS) || defined(HAVE_FSTATVFS))
+
+/*
+ * Gather current filesystem properties on other posix platform.
+ */
+static int
+setup_current_filesystem(struct archive_read_disk *a)
+{
+ struct tree *t = a->tree;
+ struct statvfs sfs;
+ int r, xr = 0;
+
+ t->current_filesystem->synthetic = -1;/* Not supported */
+ t->current_filesystem->remote = -1;/* Not supported */
+ if (tree_current_is_symblic_link_target(t)) {
+#if defined(HAVE_OPENAT)
+ /*
+ * Get file system statistics on any directory
+ * where current is.
+ */
+ int fd = openat(tree_current_dir_fd(t),
+ tree_current_access_path(t), O_RDONLY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(fd);
+ if (fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "openat failed");
+ return (ARCHIVE_FAILED);
+ }
+ r = fstatvfs(fd, &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, fd, NULL);
+ close(fd);
+#else
+ if (tree_enter_working_dir(t) != 0) {
+ archive_set_error(&a->archive, errno, "fchdir failed");
+ return (ARCHIVE_FAILED);
+ }
+ r = statvfs(tree_current_access_path(t), &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, -1, tree_current_access_path(t));
+#endif
+ } else {
+#ifdef HAVE_FSTATVFS
+ r = fstatvfs(tree_current_dir_fd(t), &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, tree_current_dir_fd(t), NULL);
+#else
+ if (tree_enter_working_dir(t) != 0) {
+ archive_set_error(&a->archive, errno, "fchdir failed");
+ return (ARCHIVE_FAILED);
+ }
+ r = statvfs(".", &sfs);
+ if (r == 0)
+ xr = get_xfer_size(t, -1, ".");
+#endif
+ }
+ if (r == -1 || xr == -1) {
+ t->current_filesystem->synthetic = -1;
+ t->current_filesystem->remote = -1;
+ archive_set_error(&a->archive, errno, "statvfs failed");
+ return (ARCHIVE_FAILED);
+ } else if (xr == 1) {
+ /* pathconf(_PC_REX_*) operations are not supported. */
+ t->current_filesystem->xfer_align = sfs.f_frsize;
+ t->current_filesystem->max_xfer_size = -1;
+ t->current_filesystem->min_xfer_size = sfs.f_bsize;
+ t->current_filesystem->incr_xfer_size = sfs.f_bsize;
+ }
+
+#if defined(ST_NOATIME)
+ if (sfs.f_flag & ST_NOATIME)
+ t->current_filesystem->noatime = 1;
+ else
+#endif
+ t->current_filesystem->noatime = 0;
+
+#if defined(HAVE_READDIR_R)
+ /* Set maximum filename length. */
+ t->current_filesystem->name_max = sfs.f_namemax;
+#endif
+ return (ARCHIVE_OK);
+}
+
+#else
+
+/*
+ * Generic: Gather current filesystem properties.
+ * TODO: Is this generic function really needed?
+ */
+static int
+setup_current_filesystem(struct archive_read_disk *a)
+{
+ struct tree *t = a->tree;
+#if defined(_PC_NAME_MAX) && defined(HAVE_READDIR_R)
+ long nm;
+#endif
+ t->current_filesystem->synthetic = -1;/* Not supported */
+ t->current_filesystem->remote = -1;/* Not supported */
+ t->current_filesystem->noatime = 0;
+ (void)get_xfer_size(t, -1, ".");/* Dummy call to avoid build error. */
+ t->current_filesystem->xfer_align = -1;/* Unknown */
+ t->current_filesystem->max_xfer_size = -1;
+ t->current_filesystem->min_xfer_size = -1;
+ t->current_filesystem->incr_xfer_size = -1;
+
+#if defined(HAVE_READDIR_R)
+ /* Set maximum filename length. */
+# if defined(_PC_NAME_MAX)
+ if (tree_current_is_symblic_link_target(t)) {
+ if (tree_enter_working_dir(t) != 0) {
+ archive_set_error(&a->archive, errno, "fchdir failed");
+ return (ARCHIVE_FAILED);
+ }
+ nm = pathconf(tree_current_access_path(t), _PC_NAME_MAX);
+ } else
+ nm = fpathconf(tree_current_dir_fd(t), _PC_NAME_MAX);
+ if (nm == -1)
+# endif /* _PC_NAME_MAX */
+ /*
+ * Some sysmtes (HP-UX or others?) incorrectly defined
+ * NAME_MAX macro to be a smaller value.
+ */
+# if defined(NAME_MAX) && NAME_MAX >= 255
+ t->current_filesystem->name_max = NAME_MAX;
+# else
+ /* No way to get a trusted value of maximum filename
+ * length. */
+ t->current_filesystem->name_max = PATH_MAX;
+# endif /* NAME_MAX */
+# if defined(_PC_NAME_MAX)
+ else
+ t->current_filesystem->name_max = nm;
+# endif /* _PC_NAME_MAX */
+#endif /* HAVE_READDIR_R */
+ return (ARCHIVE_OK);
+}
+
+#endif
+
+static int
+close_and_restore_time(int fd, struct tree *t, struct restore_time *rt)
+{
+#ifndef HAVE_UTIMES
+ (void)t; /* UNUSED */
+ (void)rt; /* UNUSED */
+ return (close(fd));
+#else
+#if defined(HAVE_FUTIMENS) && !defined(__CYGWIN__)
+ struct timespec timespecs[2];
+#endif
+ struct timeval times[2];
+
+ if ((t->flags & needsRestoreTimes) == 0 || rt->noatime) {
+ if (fd >= 0)
+ return (close(fd));
+ else
+ return (0);
+ }
+
+#if defined(HAVE_FUTIMENS) && !defined(__CYGWIN__)
+ timespecs[1].tv_sec = rt->mtime;
+ timespecs[1].tv_nsec = rt->mtime_nsec;
+
+ timespecs[0].tv_sec = rt->atime;
+ timespecs[0].tv_nsec = rt->atime_nsec;
+ /* futimens() is defined in POSIX.1-2008. */
+ if (futimens(fd, timespecs) == 0)
+ return (close(fd));
+#endif
+
+ times[1].tv_sec = rt->mtime;
+ times[1].tv_usec = rt->mtime_nsec / 1000;
+
+ times[0].tv_sec = rt->atime;
+ times[0].tv_usec = rt->atime_nsec / 1000;
+
+#if !defined(HAVE_FUTIMENS) && defined(HAVE_FUTIMES) && !defined(__CYGWIN__)
+ if (futimes(fd, times) == 0)
+ return (close(fd));
+#endif
+ close(fd);
+#if defined(HAVE_FUTIMESAT)
+ if (futimesat(tree_current_dir_fd(t), rt->name, times) == 0)
+ return (0);
+#endif
+#ifdef HAVE_LUTIMES
+ if (lutimes(rt->name, times) != 0)
+#else
+ if (AE_IFLNK != rt->filetype && utimes(rt->name, times) != 0)
+#endif
+ return (-1);
+#endif
+ return (0);
+}
+
+static int
+open_on_current_dir(struct tree *t, const char *path, int flags)
+{
+#ifdef HAVE_OPENAT
+ return (openat(tree_current_dir_fd(t), path, flags));
+#else
+ if (tree_enter_working_dir(t) != 0)
+ return (-1);
+ return (open(path, flags));
+#endif
+}
+
+static int
+tree_dup(int fd)
+{
+ int new_fd;
+#ifdef F_DUPFD_CLOEXEC
+ static volatile int can_dupfd_cloexec = 1;
+
+ if (can_dupfd_cloexec) {
+ new_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
+ if (new_fd != -1)
+ return (new_fd);
+ /* Linux 2.6.18 - 2.6.23 declare F_DUPFD_CLOEXEC,
+ * but it cannot be used. So we have to try dup(). */
+ /* We won't try F_DUPFD_CLOEXEC. */
+ can_dupfd_cloexec = 0;
+ }
+#endif /* F_DUPFD_CLOEXEC */
+ new_fd = dup(fd);
+ __archive_ensure_cloexec_flag(new_fd);
+ return (new_fd);
+}
+
+/*
+ * Add a directory path to the current stack.
+ */
+static void
+tree_push(struct tree *t, const char *path, int filesystem_id,
+ int64_t dev, int64_t ino, struct restore_time *rt)
+{
+ struct tree_entry *te;
+
+ te = malloc(sizeof(*te));
+ memset(te, 0, sizeof(*te));
+ te->next = t->stack;
+ te->parent = t->current;
+ if (te->parent)
+ te->depth = te->parent->depth + 1;
+ t->stack = te;
+ archive_string_init(&te->name);
+ te->symlink_parent_fd = -1;
+ archive_strcpy(&te->name, path);
+ te->flags = needsDescent | needsOpen | needsAscent;
+ te->filesystem_id = filesystem_id;
+ te->dev = dev;
+ te->ino = ino;
+ te->dirname_length = t->dirname_length;
+ te->restore_time.name = te->name.s;
+ if (rt != NULL) {
+ te->restore_time.mtime = rt->mtime;
+ te->restore_time.mtime_nsec = rt->mtime_nsec;
+ te->restore_time.atime = rt->atime;
+ te->restore_time.atime_nsec = rt->atime_nsec;
+ te->restore_time.filetype = rt->filetype;
+ te->restore_time.noatime = rt->noatime;
+ }
+}
+
+/*
+ * Append a name to the current dir path.
+ */
+static void
+tree_append(struct tree *t, const char *name, size_t name_length)
+{
+ size_t size_needed;
+
+ t->path.s[t->dirname_length] = '\0';
+ t->path.length = t->dirname_length;
+ /* Strip trailing '/' from name, unless entire name is "/". */
+ while (name_length > 1 && name[name_length - 1] == '/')
+ name_length--;
+
+ /* Resize pathname buffer as needed. */
+ size_needed = name_length + t->dirname_length + 2;
+ archive_string_ensure(&t->path, size_needed);
+ /* Add a separating '/' if it's needed. */
+ if (t->dirname_length > 0 && t->path.s[archive_strlen(&t->path)-1] != '/')
+ archive_strappend_char(&t->path, '/');
+ t->basename = t->path.s + archive_strlen(&t->path);
+ archive_strncat(&t->path, name, name_length);
+ t->restore_time.name = t->basename;
+}
+
+/*
+ * Open a directory tree for traversal.
+ */
+static struct tree *
+tree_open(const char *path, int symlink_mode, int restore_time)
+{
+ struct tree *t;
+
+ if ((t = malloc(sizeof(*t))) == NULL)
+ return (NULL);
+ memset(t, 0, sizeof(*t));
+ archive_string_init(&t->path);
+ archive_string_ensure(&t->path, 31);
+ t->initial_symlink_mode = symlink_mode;
+ return (tree_reopen(t, path, restore_time));
+}
+
+static struct tree *
+tree_reopen(struct tree *t, const char *path, int restore_time)
+{
+ t->flags = (restore_time)?needsRestoreTimes:0;
+ t->flags |= onInitialDir;
+ t->visit_type = 0;
+ t->tree_errno = 0;
+ t->dirname_length = 0;
+ t->depth = 0;
+ t->descend = 0;
+ t->current = NULL;
+ t->d = INVALID_DIR_HANDLE;
+ t->symlink_mode = t->initial_symlink_mode;
+ archive_string_empty(&t->path);
+ t->entry_fd = -1;
+ t->entry_eof = 0;
+ t->entry_remaining_bytes = 0;
+ t->initial_filesystem_id = -1;
+
+ /* First item is set up a lot like a symlink traversal. */
+ tree_push(t, path, 0, 0, 0, NULL);
+ t->stack->flags = needsFirstVisit;
+ t->maxOpenCount = t->openCount = 1;
+ t->initial_dir_fd = open(".", O_RDONLY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(t->initial_dir_fd);
+ t->working_dir_fd = tree_dup(t->initial_dir_fd);
+ return (t);
+}
+
+static int
+tree_descent(struct tree *t)
+{
+ int flag, new_fd, r = 0;
+
+ t->dirname_length = archive_strlen(&t->path);
+ flag = O_RDONLY | O_CLOEXEC;
+#if defined(O_DIRECTORY)
+ flag |= O_DIRECTORY;
+#endif
+ new_fd = open_on_current_dir(t, t->stack->name.s, flag);
+ __archive_ensure_cloexec_flag(new_fd);
+ if (new_fd < 0) {
+ t->tree_errno = errno;
+ r = TREE_ERROR_DIR;
+ } else {
+ t->depth++;
+ /* If it is a link, set up fd for the ascent. */
+ if (t->stack->flags & isDirLink) {
+ t->stack->symlink_parent_fd = t->working_dir_fd;
+ t->openCount++;
+ if (t->openCount > t->maxOpenCount)
+ t->maxOpenCount = t->openCount;
+ } else
+ close(t->working_dir_fd);
+ /* Renew the current working directory. */
+ t->working_dir_fd = new_fd;
+ t->flags &= ~onWorkingDir;
+ }
+ return (r);
+}
+
+/*
+ * We've finished a directory; ascend back to the parent.
+ */
+static int
+tree_ascend(struct tree *t)
+{
+ struct tree_entry *te;
+ int new_fd, r = 0, prev_dir_fd;
+
+ te = t->stack;
+ prev_dir_fd = t->working_dir_fd;
+ if (te->flags & isDirLink)
+ new_fd = te->symlink_parent_fd;
+ else {
+ new_fd = open_on_current_dir(t, "..", O_RDONLY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(new_fd);
+ }
+ if (new_fd < 0) {
+ t->tree_errno = errno;
+ r = TREE_ERROR_FATAL;
+ } else {
+ /* Renew the current working directory. */
+ t->working_dir_fd = new_fd;
+ t->flags &= ~onWorkingDir;
+ /* Current directory has been changed, we should
+ * close an fd of previous working directory. */
+ close_and_restore_time(prev_dir_fd, t, &te->restore_time);
+ if (te->flags & isDirLink) {
+ t->openCount--;
+ te->symlink_parent_fd = -1;
+ }
+ t->depth--;
+ }
+ return (r);
+}
+
+/*
+ * Return to the initial directory where tree_open() was performed.
+ */
+static int
+tree_enter_initial_dir(struct tree *t)
+{
+ int r = 0;
+
+ if ((t->flags & onInitialDir) == 0) {
+ r = fchdir(t->initial_dir_fd);
+ if (r == 0) {
+ t->flags &= ~onWorkingDir;
+ t->flags |= onInitialDir;
+ }
+ }
+ return (r);
+}
+
+/*
+ * Restore working directory of directory traversals.
+ */
+static int
+tree_enter_working_dir(struct tree *t)
+{
+ int r = 0;
+
+ /*
+ * Change the current directory if really needed.
+ * Sometimes this is unneeded when we did not do
+ * descent.
+ */
+ if (t->depth > 0 && (t->flags & onWorkingDir) == 0) {
+ r = fchdir(t->working_dir_fd);
+ if (r == 0) {
+ t->flags &= ~onInitialDir;
+ t->flags |= onWorkingDir;
+ }
+ }
+ return (r);
+}
+
+static int
+tree_current_dir_fd(struct tree *t)
+{
+ return (t->working_dir_fd);
+}
+
+/*
+ * Pop the working stack.
+ */
+static void
+tree_pop(struct tree *t)
+{
+ struct tree_entry *te;
+
+ t->path.s[t->dirname_length] = '\0';
+ t->path.length = t->dirname_length;
+ if (t->stack == t->current && t->current != NULL)
+ t->current = t->current->parent;
+ te = t->stack;
+ t->stack = te->next;
+ t->dirname_length = te->dirname_length;
+ t->basename = t->path.s + t->dirname_length;
+ while (t->basename[0] == '/')
+ t->basename++;
+ archive_string_free(&te->name);
+ free(te);
+}
+
+/*
+ * Get the next item in the tree traversal.
+ */
+static int
+tree_next(struct tree *t)
+{
+ int r;
+
+ while (t->stack != NULL) {
+ /* If there's an open dir, get the next entry from there. */
+ if (t->d != INVALID_DIR_HANDLE) {
+ r = tree_dir_next_posix(t);
+ if (r == 0)
+ continue;
+ return (r);
+ }
+
+ if (t->stack->flags & needsFirstVisit) {
+ /* Top stack item needs a regular visit. */
+ t->current = t->stack;
+ tree_append(t, t->stack->name.s,
+ archive_strlen(&(t->stack->name)));
+ /* t->dirname_length = t->path_length; */
+ /* tree_pop(t); */
+ t->stack->flags &= ~needsFirstVisit;
+ return (t->visit_type = TREE_REGULAR);
+ } else if (t->stack->flags & needsDescent) {
+ /* Top stack item is dir to descend into. */
+ t->current = t->stack;
+ tree_append(t, t->stack->name.s,
+ archive_strlen(&(t->stack->name)));
+ t->stack->flags &= ~needsDescent;
+ r = tree_descent(t);
+ if (r != 0) {
+ tree_pop(t);
+ t->visit_type = r;
+ } else
+ t->visit_type = TREE_POSTDESCENT;
+ return (t->visit_type);
+ } else if (t->stack->flags & needsOpen) {
+ t->stack->flags &= ~needsOpen;
+ r = tree_dir_next_posix(t);
+ if (r == 0)
+ continue;
+ return (r);
+ } else if (t->stack->flags & needsAscent) {
+ /* Top stack item is dir and we're done with it. */
+ r = tree_ascend(t);
+ tree_pop(t);
+ t->visit_type = r != 0 ? r : TREE_POSTASCENT;
+ return (t->visit_type);
+ } else {
+ /* Top item on stack is dead. */
+ tree_pop(t);
+ t->flags &= ~hasLstat;
+ t->flags &= ~hasStat;
+ }
+ }
+ return (t->visit_type = 0);
+}
+
+static int
+tree_dir_next_posix(struct tree *t)
+{
+ int r;
+ const char *name;
+ size_t namelen;
+
+ if (t->d == NULL) {
+#if defined(HAVE_READDIR_R)
+ size_t dirent_size;
+#endif
+
+#if defined(HAVE_FDOPENDIR)
+ t->d = fdopendir(tree_dup(t->working_dir_fd));
+#else /* HAVE_FDOPENDIR */
+ if (tree_enter_working_dir(t) == 0) {
+ t->d = opendir(".");
+#if HAVE_DIRFD || defined(dirfd)
+ __archive_ensure_cloexec_flag(dirfd(t->d));
+#endif
+ }
+#endif /* HAVE_FDOPENDIR */
+ if (t->d == NULL) {
+ r = tree_ascend(t); /* Undo "chdir" */
+ tree_pop(t);
+ t->tree_errno = errno;
+ t->visit_type = r != 0 ? r : TREE_ERROR_DIR;
+ return (t->visit_type);
+ }
+#if defined(HAVE_READDIR_R)
+ dirent_size = offsetof(struct dirent, d_name) +
+ t->filesystem_table[t->current->filesystem_id].name_max + 1;
+ if (t->dirent == NULL || t->dirent_allocated < dirent_size) {
+ free(t->dirent);
+ t->dirent = malloc(dirent_size);
+ if (t->dirent == NULL) {
+ closedir(t->d);
+ t->d = INVALID_DIR_HANDLE;
+ (void)tree_ascend(t);
+ tree_pop(t);
+ t->tree_errno = ENOMEM;
+ t->visit_type = TREE_ERROR_DIR;
+ return (t->visit_type);
+ }
+ t->dirent_allocated = dirent_size;
+ }
+#endif /* HAVE_READDIR_R */
+ }
+ for (;;) {
+ errno = 0;
+#if defined(HAVE_READDIR_R)
+ r = readdir_r(t->d, t->dirent, &t->de);
+#ifdef _AIX
+ /* Note: According to the man page, return value 9 indicates
+ * that the readdir_r was not successful and the error code
+ * is set to the global errno variable. And then if the end
+ * of directory entries was reached, the return value is 9
+ * and the third parameter is set to NULL and errno is
+ * unchanged. */
+ if (r == 9)
+ r = errno;
+#endif /* _AIX */
+ if (r != 0 || t->de == NULL) {
+#else
+ t->de = readdir(t->d);
+ if (t->de == NULL) {
+ r = errno;
+#endif
+ closedir(t->d);
+ t->d = INVALID_DIR_HANDLE;
+ if (r != 0) {
+ t->tree_errno = r;
+ t->visit_type = TREE_ERROR_DIR;
+ return (t->visit_type);
+ } else
+ return (0);
+ }
+ name = t->de->d_name;
+ namelen = D_NAMELEN(t->de);
+ t->flags &= ~hasLstat;
+ t->flags &= ~hasStat;
+ if (name[0] == '.' && name[1] == '\0')
+ continue;
+ if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
+ continue;
+ tree_append(t, name, namelen);
+ return (t->visit_type = TREE_REGULAR);
+ }
+}
+
+
+/*
+ * Get the stat() data for the entry just returned from tree_next().
+ */
+static const struct stat *
+tree_current_stat(struct tree *t)
+{
+ if (!(t->flags & hasStat)) {
+#ifdef HAVE_FSTATAT
+ if (fstatat(tree_current_dir_fd(t),
+ tree_current_access_path(t), &t->st, 0) != 0)
+#else
+ if (tree_enter_working_dir(t) != 0)
+ return NULL;
+ if (stat(tree_current_access_path(t), &t->st) != 0)
+#endif
+ return NULL;
+ t->flags |= hasStat;
+ }
+ return (&t->st);
+}
+
+/*
+ * Get the lstat() data for the entry just returned from tree_next().
+ */
+static const struct stat *
+tree_current_lstat(struct tree *t)
+{
+ if (!(t->flags & hasLstat)) {
+#ifdef HAVE_FSTATAT
+ if (fstatat(tree_current_dir_fd(t),
+ tree_current_access_path(t), &t->lst,
+ AT_SYMLINK_NOFOLLOW) != 0)
+#else
+ if (tree_enter_working_dir(t) != 0)
+ return NULL;
+ if (lstat(tree_current_access_path(t), &t->lst) != 0)
+#endif
+ return NULL;
+ t->flags |= hasLstat;
+ }
+ return (&t->lst);
+}
+
+/*
+ * Test whether current entry is a dir or link to a dir.
+ */
+static int
+tree_current_is_dir(struct tree *t)
+{
+ const struct stat *st;
+ /*
+ * If we already have lstat() info, then try some
+ * cheap tests to determine if this is a dir.
+ */
+ if (t->flags & hasLstat) {
+ /* If lstat() says it's a dir, it must be a dir. */
+ st = tree_current_lstat(t);
+ if (st == NULL)
+ return 0;
+ if (S_ISDIR(st->st_mode))
+ return 1;
+ /* Not a dir; might be a link to a dir. */
+ /* If it's not a link, then it's not a link to a dir. */
+ if (!S_ISLNK(st->st_mode))
+ return 0;
+ /*
+ * It's a link, but we don't know what it's a link to,
+ * so we'll have to use stat().
+ */
+ }
+
+ st = tree_current_stat(t);
+ /* If we can't stat it, it's not a dir. */
+ if (st == NULL)
+ return 0;
+ /* Use the definitive test. Hopefully this is cached. */
+ return (S_ISDIR(st->st_mode));
+}
+
+/*
+ * Test whether current entry is a physical directory. Usually, we
+ * already have at least one of stat() or lstat() in memory, so we
+ * use tricks to try to avoid an extra trip to the disk.
+ */
+static int
+tree_current_is_physical_dir(struct tree *t)
+{
+ const struct stat *st;
+
+ /*
+ * If stat() says it isn't a dir, then it's not a dir.
+ * If stat() data is cached, this check is free, so do it first.
+ */
+ if (t->flags & hasStat) {
+ st = tree_current_stat(t);
+ if (st == NULL)
+ return (0);
+ if (!S_ISDIR(st->st_mode))
+ return (0);
+ }
+
+ /*
+ * Either stat() said it was a dir (in which case, we have
+ * to determine whether it's really a link to a dir) or
+ * stat() info wasn't available. So we use lstat(), which
+ * hopefully is already cached.
+ */
+
+ st = tree_current_lstat(t);
+ /* If we can't stat it, it's not a dir. */
+ if (st == NULL)
+ return 0;
+ /* Use the definitive test. Hopefully this is cached. */
+ return (S_ISDIR(st->st_mode));
+}
+
+/*
+ * Test whether the same file has been in the tree as its parent.
+ */
+static int
+tree_target_is_same_as_parent(struct tree *t, const struct stat *st)
+{
+ struct tree_entry *te;
+
+ for (te = t->current->parent; te != NULL; te = te->parent) {
+ if (te->dev == (int64_t)st->st_dev &&
+ te->ino == (int64_t)st->st_ino)
+ return (1);
+ }
+ return (0);
+}
+
+/*
+ * Test whether the current file is symbolic link target and
+ * on the other filesystem.
+ */
+static int
+tree_current_is_symblic_link_target(struct tree *t)
+{
+ static const struct stat *lst, *st;
+
+ lst = tree_current_lstat(t);
+ st = tree_current_stat(t);
+ return (st != NULL && lst != NULL &&
+ (int64_t)st->st_dev == t->current_filesystem->dev &&
+ st->st_dev != lst->st_dev);
+}
+
+/*
+ * Return the access path for the entry just returned from tree_next().
+ */
+static const char *
+tree_current_access_path(struct tree *t)
+{
+ return (t->basename);
+}
+
+/*
+ * Return the full path for the entry just returned from tree_next().
+ */
+static const char *
+tree_current_path(struct tree *t)
+{
+ return (t->path.s);
+}
+
+/*
+ * Terminate the traversal.
+ */
+static void
+tree_close(struct tree *t)
+{
+
+ if (t == NULL)
+ return;
+ if (t->entry_fd >= 0) {
+ close_and_restore_time(t->entry_fd, t, &t->restore_time);
+ t->entry_fd = -1;
+ }
+ /* Close the handle of readdir(). */
+ if (t->d != INVALID_DIR_HANDLE) {
+ closedir(t->d);
+ t->d = INVALID_DIR_HANDLE;
+ }
+ /* Release anything remaining in the stack. */
+ while (t->stack != NULL) {
+ if (t->stack->flags & isDirLink)
+ close(t->stack->symlink_parent_fd);
+ tree_pop(t);
+ }
+ if (t->working_dir_fd >= 0) {
+ close(t->working_dir_fd);
+ t->working_dir_fd = -1;
+ }
+ if (t->initial_dir_fd >= 0) {
+ close(t->initial_dir_fd);
+ t->initial_dir_fd = -1;
+ }
+}
+
+/*
+ * Release any resources.
+ */
+static void
+tree_free(struct tree *t)
+{
+ int i;
+
+ if (t == NULL)
+ return;
+ archive_string_free(&t->path);
+#if defined(HAVE_READDIR_R)
+ free(t->dirent);
+#endif
+ free(t->sparse_list);
+ for (i = 0; i < t->max_filesystem_id; i++)
+ free(t->filesystem_table[i].allocation_ptr);
+ free(t->filesystem_table);
+ free(t);
+}
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h
new file mode 100644
index 0000000000..e5af16b916
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h
@@ -0,0 +1,92 @@
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * 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
+ * in this position and unchanged.
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_read_disk_private.h 201105 2009-12-28 03:20:54Z kientzle $
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED
+#define ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED
+
+struct tree;
+struct archive_entry;
+
+struct archive_read_disk {
+ struct archive archive;
+
+ /*
+ * Symlink mode is one of 'L'ogical, 'P'hysical, or 'H'ybrid,
+ * following an old BSD convention. 'L' follows all symlinks,
+ * 'P' follows none, 'H' follows symlinks only for the first
+ * item.
+ */
+ char symlink_mode;
+
+ /*
+ * Since symlink interaction changes, we need to track whether
+ * we're following symlinks for the current item. 'L' mode above
+ * sets this true, 'P' sets it false, 'H' changes it as we traverse.
+ */
+ char follow_symlinks; /* Either 'L' or 'P'. */
+
+ /* Directory traversals. */
+ struct tree *tree;
+ int (*open_on_current_dir)(struct tree*, const char *, int);
+ int (*tree_current_dir_fd)(struct tree*);
+ int (*tree_enter_working_dir)(struct tree*);
+
+ /* Set 1 if users request to restore atime . */
+ int restore_time;
+ /* Set 1 if users request to honor nodump flag . */
+ int honor_nodump;
+ /* Set 1 if users request to enable mac copyfile. */
+ int enable_copyfile;
+ /* Set 1 if users request to traverse mount points. */
+ int traverse_mount_points;
+
+ const char * (*lookup_gname)(void *private, int64_t gid);
+ void (*cleanup_gname)(void *private);
+ void *lookup_gname_data;
+ const char * (*lookup_uname)(void *private, int64_t uid);
+ void (*cleanup_uname)(void *private);
+ void *lookup_uname_data;
+
+ int (*metadata_filter_func)(struct archive *, void *,
+ struct archive_entry *);
+ void *metadata_filter_data;
+
+ /* ARCHIVE_MATCH object. */
+ struct archive *matching;
+ /* Callback function, this will be invoked when ARCHIVE_MATCH
+ * archive_match_*_excluded_ae return true. */
+ void (*excluded_cb_func)(struct archive *, void *,
+ struct archive_entry *);
+ void *excluded_cb_data;
+};
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c
new file mode 100644
index 0000000000..3bc52c70db
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c
@@ -0,0 +1,311 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_read_disk_set_standard_lookup.c 201109 2009-12-28 03:30:31Z kientzle $");
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+int
+archive_read_disk_set_standard_lookup(struct archive *a)
+{
+ archive_set_error(a, -1, "Standard lookups not available on Windows");
+ return (ARCHIVE_FATAL);
+}
+#else /* ! (_WIN32 && !__CYGWIN__) */
+#define name_cache_size 127
+
+static const char * const NO_NAME = "(noname)";
+
+struct name_cache {
+ struct archive *archive;
+ char *buff;
+ size_t buff_size;
+ int probes;
+ int hits;
+ size_t size;
+ struct {
+ id_t id;
+ const char *name;
+ } cache[name_cache_size];
+};
+
+static const char * lookup_gname(void *, int64_t);
+static const char * lookup_uname(void *, int64_t);
+static void cleanup(void *);
+static const char * lookup_gname_helper(struct name_cache *, id_t gid);
+static const char * lookup_uname_helper(struct name_cache *, id_t uid);
+
+/*
+ * Installs functions that use getpwuid()/getgrgid()---along with
+ * 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
+ * it inappropriate for some space-constrained applications.
+ *
+ * Applications that are size-sensitive may want to just use the
+ * real default functions (defined in archive_read_disk.c) that just
+ * use the uid/gid without the lookup. Or define your own custom functions
+ * if you prefer.
+ */
+int
+archive_read_disk_set_standard_lookup(struct archive *a)
+{
+ struct name_cache *ucache = malloc(sizeof(struct name_cache));
+ struct name_cache *gcache = malloc(sizeof(struct name_cache));
+
+ if (ucache == NULL || gcache == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate uname/gname lookup cache");
+ free(ucache);
+ free(gcache);
+ return (ARCHIVE_FATAL);
+ }
+
+ memset(ucache, 0, sizeof(*ucache));
+ ucache->archive = a;
+ ucache->size = name_cache_size;
+ memset(gcache, 0, sizeof(*gcache));
+ gcache->archive = a;
+ gcache->size = name_cache_size;
+
+ archive_read_disk_set_gname_lookup(a, gcache, lookup_gname, cleanup);
+ archive_read_disk_set_uname_lookup(a, ucache, lookup_uname, cleanup);
+
+ return (ARCHIVE_OK);
+}
+
+static void
+cleanup(void *data)
+{
+ struct name_cache *cache = (struct name_cache *)data;
+ size_t i;
+
+ if (cache != NULL) {
+ for (i = 0; i < cache->size; i++) {
+ if (cache->cache[i].name != NULL &&
+ cache->cache[i].name != NO_NAME)
+ free((void *)(uintptr_t)cache->cache[i].name);
+ }
+ free(cache->buff);
+ free(cache);
+ }
+}
+
+/*
+ * Lookup uid/gid from uname/gname, return NULL if no match.
+ */
+static const char *
+lookup_name(struct name_cache *cache,
+ const char * (*lookup_fn)(struct name_cache *, id_t), id_t id)
+{
+ const char *name;
+ int slot;
+
+
+ cache->probes++;
+
+ slot = id % cache->size;
+ if (cache->cache[slot].name != NULL) {
+ if (cache->cache[slot].id == id) {
+ cache->hits++;
+ if (cache->cache[slot].name == NO_NAME)
+ return (NULL);
+ return (cache->cache[slot].name);
+ }
+ if (cache->cache[slot].name != NO_NAME)
+ free((void *)(uintptr_t)cache->cache[slot].name);
+ cache->cache[slot].name = NULL;
+ }
+
+ name = (lookup_fn)(cache, id);
+ if (name == NULL) {
+ /* Cache and return the negative response. */
+ cache->cache[slot].name = NO_NAME;
+ cache->cache[slot].id = id;
+ return (NULL);
+ }
+
+ cache->cache[slot].name = name;
+ cache->cache[slot].id = id;
+ return (cache->cache[slot].name);
+}
+
+static const char *
+lookup_uname(void *data, int64_t uid)
+{
+ struct name_cache *uname_cache = (struct name_cache *)data;
+ return (lookup_name(uname_cache,
+ &lookup_uname_helper, (id_t)uid));
+}
+
+#if HAVE_GETPWUID_R
+static const char *
+lookup_uname_helper(struct name_cache *cache, id_t id)
+{
+ struct passwd pwent, *result;
+ char * nbuff;
+ size_t nbuff_size;
+ int r;
+
+ if (cache->buff_size == 0) {
+ cache->buff_size = 256;
+ cache->buff = malloc(cache->buff_size);
+ }
+ if (cache->buff == NULL)
+ return (NULL);
+ for (;;) {
+ result = &pwent; /* Old getpwuid_r ignores last arg. */
+ r = getpwuid_r((uid_t)id, &pwent,
+ cache->buff, cache->buff_size, &result);
+ if (r == 0)
+ break;
+ if (r != ERANGE)
+ break;
+ /* ERANGE means our buffer was too small, but POSIX
+ * doesn't tell us how big the buffer should be, so
+ * we just double it and try again. Because the buffer
+ * is kept around in the cache object, we shouldn't
+ * have to do this very often. */
+ nbuff_size = cache->buff_size * 2;
+ nbuff = realloc(cache->buff, nbuff_size);
+ if (nbuff == NULL)
+ break;
+ cache->buff = nbuff;
+ cache->buff_size = nbuff_size;
+ }
+ if (r != 0) {
+ archive_set_error(cache->archive, errno,
+ "Can't lookup user for id %d", (int)id);
+ return (NULL);
+ }
+ if (result == NULL)
+ return (NULL);
+
+ return strdup(result->pw_name);
+}
+#else
+static const char *
+lookup_uname_helper(struct name_cache *cache, id_t id)
+{
+ struct passwd *result;
+
+ result = getpwuid((uid_t)id);
+
+ if (result == NULL)
+ return (NULL);
+
+ return strdup(result->pw_name);
+}
+#endif
+
+static const char *
+lookup_gname(void *data, int64_t gid)
+{
+ struct name_cache *gname_cache = (struct name_cache *)data;
+ return (lookup_name(gname_cache,
+ &lookup_gname_helper, (id_t)gid));
+}
+
+#if HAVE_GETGRGID_R
+static const char *
+lookup_gname_helper(struct name_cache *cache, id_t id)
+{
+ struct group grent, *result;
+ char * nbuff;
+ size_t nbuff_size;
+ int r;
+
+ if (cache->buff_size == 0) {
+ cache->buff_size = 256;
+ cache->buff = malloc(cache->buff_size);
+ }
+ if (cache->buff == NULL)
+ return (NULL);
+ for (;;) {
+ result = &grent; /* Old getgrgid_r ignores last arg. */
+ r = getgrgid_r((gid_t)id, &grent,
+ cache->buff, cache->buff_size, &result);
+ if (r == 0)
+ break;
+ if (r != ERANGE)
+ break;
+ /* ERANGE means our buffer was too small, but POSIX
+ * doesn't tell us how big the buffer should be, so
+ * we just double it and try again. */
+ nbuff_size = cache->buff_size * 2;
+ nbuff = realloc(cache->buff, nbuff_size);
+ if (nbuff == NULL)
+ break;
+ cache->buff = nbuff;
+ cache->buff_size = nbuff_size;
+ }
+ if (r != 0) {
+ archive_set_error(cache->archive, errno,
+ "Can't lookup group for id %d", (int)id);
+ return (NULL);
+ }
+ if (result == NULL)
+ return (NULL);
+
+ return strdup(result->gr_name);
+}
+#else
+static const char *
+lookup_gname_helper(struct name_cache *cache, id_t id)
+{
+ struct group *result;
+
+ result = getgrgid((gid_t)id);
+
+ if (result == NULL)
+ return (NULL);
+
+ return strdup(result->gr_name);
+}
+#endif
+
+#endif /* ! (_WIN32 && !__CYGWIN__) */
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c
new file mode 100644
index 0000000000..5c0f3666ab
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c
@@ -0,0 +1,2296 @@
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * Copyright (c) 2010-2012 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
+ * in this position and unchanged.
+ * 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$");
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include <winioctl.h>
+
+#include "archive.h"
+#include "archive_string.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_disk_private.h"
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef IO_REPARSE_TAG_SYMLINK
+/* Old SDKs do not provide IO_REPARSE_TAG_SYMLINK */
+#define IO_REPARSE_TAG_SYMLINK 0xA000000CL
+#endif
+
+/*-
+ * This is a new directory-walking system that addresses a number
+ * of problems I've had with fts(3). In particular, it has no
+ * pathname-length limits (other than the size of 'int'), handles
+ * deep logical traversals, uses considerably less memory, and has
+ * an opaque interface (easier to modify in the future).
+ *
+ * Internally, it keeps a single list of "tree_entry" items that
+ * represent filesystem objects that require further attention.
+ * Non-directories are not kept in memory: they are pulled from
+ * readdir(), returned to the client, then freed as soon as possible.
+ * Any directory entry to be traversed gets pushed onto the stack.
+ *
+ * There is surprisingly little information that needs to be kept for
+ * each item on the stack. Just the name, depth (represented here as the
+ * string length of the parent directory's pathname), and some markers
+ * indicating how to get back to the parent (via chdir("..") for a
+ * regular dir or via fchdir(2) for a symlink).
+ */
+
+struct restore_time {
+ const wchar_t *full_path;
+ FILETIME lastWriteTime;
+ FILETIME lastAccessTime;
+ mode_t filetype;
+};
+
+struct tree_entry {
+ int depth;
+ struct tree_entry *next;
+ struct tree_entry *parent;
+ size_t full_path_dir_length;
+ struct archive_wstring name;
+ struct archive_wstring full_path;
+ size_t dirname_length;
+ int64_t dev;
+ int64_t ino;
+ int flags;
+ int filesystem_id;
+ /* How to restore time of a directory. */
+ struct restore_time restore_time;
+};
+
+struct filesystem {
+ int64_t dev;
+ int synthetic;
+ int remote;
+ DWORD bytesPerSector;
+};
+
+/* Definitions for tree_entry.flags bitmap. */
+#define isDir 1 /* This entry is a regular directory. */
+#define isDirLink 2 /* This entry is a symbolic link to a directory. */
+#define needsFirstVisit 4 /* This is an initial entry. */
+#define needsDescent 8 /* This entry needs to be previsited. */
+#define needsOpen 16 /* This is a directory that needs to be opened. */
+#define needsAscent 32 /* This entry needs to be postvisited. */
+
+/*
+ * On Windows, "first visit" is handled as a pattern to be handed to
+ * _findfirst(). This is consistent with Windows conventions that
+ * file patterns are handled within the application. On Posix,
+ * "first visit" is just returned to the client.
+ */
+
+#define MAX_OVERLAPPED 8
+#define BUFFER_SIZE (1024 * 8)
+#define DIRECT_IO 0/* Disabled */
+#define ASYNC_IO 1/* Enabled */
+
+/*
+ * Local data for this package.
+ */
+struct tree {
+ struct tree_entry *stack;
+ struct tree_entry *current;
+ HANDLE d;
+ WIN32_FIND_DATAW _findData;
+ WIN32_FIND_DATAW *findData;
+ int flags;
+ int visit_type;
+ /* Error code from last failed operation. */
+ int tree_errno;
+
+ /* A full path with "\\?\" prefix. */
+ struct archive_wstring full_path;
+ size_t full_path_dir_length;
+ /* Dynamically-sized buffer for holding path */
+ struct archive_wstring path;
+
+ /* Last path element */
+ const wchar_t *basename;
+ /* Leading dir length */
+ size_t dirname_length;
+
+ int depth;
+
+ BY_HANDLE_FILE_INFORMATION lst;
+ BY_HANDLE_FILE_INFORMATION st;
+ int descend;
+ /* How to restore time of a file. */
+ struct restore_time restore_time;
+
+ struct entry_sparse {
+ int64_t length;
+ int64_t offset;
+ } *sparse_list, *current_sparse;
+ int sparse_count;
+ int sparse_list_size;
+
+ char initial_symlink_mode;
+ char symlink_mode;
+ struct filesystem *current_filesystem;
+ struct filesystem *filesystem_table;
+ int initial_filesystem_id;
+ int current_filesystem_id;
+ int max_filesystem_id;
+ int allocated_filesytem;
+
+ HANDLE entry_fh;
+ int entry_eof;
+ int64_t entry_remaining_bytes;
+ int64_t entry_total;
+
+ int ol_idx_doing;
+ int ol_idx_done;
+ int ol_num_doing;
+ int ol_num_done;
+ int64_t ol_remaining_bytes;
+ int64_t ol_total;
+ struct la_overlapped {
+ OVERLAPPED ol;
+ struct archive * _a;
+ unsigned char *buff;
+ size_t buff_size;
+ int64_t offset;
+ size_t bytes_expected;
+ size_t bytes_transferred;
+ } ol[MAX_OVERLAPPED];
+ int direct_io;
+ int async_io;
+};
+
+#define bhfi_dev(bhfi) ((bhfi)->dwVolumeSerialNumber)
+/* Treat FileIndex as i-node. We should remove a sequence number
+ * which is high-16-bits of nFileIndexHigh. */
+#define bhfi_ino(bhfi) \
+ ((((int64_t)((bhfi)->nFileIndexHigh & 0x0000FFFFUL)) << 32) \
+ + (bhfi)->nFileIndexLow)
+
+/* Definitions for tree.flags bitmap. */
+#define hasStat 16 /* The st entry is valid. */
+#define hasLstat 32 /* The lst entry is valid. */
+#define needsRestoreTimes 128
+
+static int
+tree_dir_next_windows(struct tree *t, const wchar_t *pattern);
+
+/* Initiate/terminate a tree traversal. */
+static struct tree *tree_open(const wchar_t *, int, int);
+static struct tree *tree_reopen(struct tree *, const wchar_t *, int);
+static void tree_close(struct tree *);
+static void tree_free(struct tree *);
+static void tree_push(struct tree *, const wchar_t *, const wchar_t *,
+ int, int64_t, int64_t, struct restore_time *);
+
+/*
+ * tree_next() returns Zero if there is no next entry, non-zero if
+ * there is. Note that directories are visited three times.
+ * Directories are always visited first as part of enumerating their
+ * parent; that is a "regular" visit. If tree_descend() is invoked at
+ * that time, the directory is added to a work list and will
+ * subsequently be visited two more times: once just after descending
+ * into the directory ("postdescent") and again just after ascending
+ * back to the parent ("postascent").
+ *
+ * TREE_ERROR_DIR is returned if the descent failed (because the
+ * directory couldn't be opened, for instance). This is returned
+ * instead of TREE_POSTDESCENT/TREE_POSTASCENT. TREE_ERROR_DIR is not a
+ * fatal error, but it does imply that the relevant subtree won't be
+ * visited. TREE_ERROR_FATAL is returned for an error that left the
+ * traversal completely hosed. Right now, this is only returned for
+ * chdir() failures during ascent.
+ */
+#define TREE_REGULAR 1
+#define TREE_POSTDESCENT 2
+#define TREE_POSTASCENT 3
+#define TREE_ERROR_DIR -1
+#define TREE_ERROR_FATAL -2
+
+static int tree_next(struct tree *);
+
+/*
+ * Return information about the current entry.
+ */
+
+/*
+ * The current full pathname, length of the full pathname, and a name
+ * that can be used to access the file. Because tree does use chdir
+ * extensively, the access path is almost never the same as the full
+ * current path.
+ *
+ */
+static const wchar_t *tree_current_path(struct tree *);
+static const wchar_t *tree_current_access_path(struct tree *);
+
+/*
+ * Request the lstat() or stat() data for the current path. Since the
+ * tree package needs to do some of this anyway, and caches the
+ * results, you should take advantage of it here if you need it rather
+ * than make a redundant stat() or lstat() call of your own.
+ */
+static const BY_HANDLE_FILE_INFORMATION *tree_current_stat(struct tree *);
+static const BY_HANDLE_FILE_INFORMATION *tree_current_lstat(struct tree *);
+
+/* The following functions use tricks to avoid a certain number of
+ * stat()/lstat() calls. */
+/* "is_physical_dir" is equivalent to S_ISDIR(tree_current_lstat()->st_mode) */
+static int tree_current_is_physical_dir(struct tree *);
+/* "is_physical_link" is equivalent to S_ISLNK(tree_current_lstat()->st_mode) */
+static int tree_current_is_physical_link(struct tree *);
+/* Instead of archive_entry_copy_stat for BY_HANDLE_FILE_INFORMATION */
+static void tree_archive_entry_copy_bhfi(struct archive_entry *,
+ struct tree *, const BY_HANDLE_FILE_INFORMATION *);
+/* "is_dir" is equivalent to S_ISDIR(tree_current_stat()->st_mode) */
+static int tree_current_is_dir(struct tree *);
+static int update_current_filesystem(struct archive_read_disk *a,
+ int64_t dev);
+static int setup_current_filesystem(struct archive_read_disk *);
+static int tree_target_is_same_as_parent(struct tree *,
+ const BY_HANDLE_FILE_INFORMATION *);
+
+static int _archive_read_disk_open_w(struct archive *, const wchar_t *);
+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_header2(struct archive *,
+ struct archive_entry *);
+static const char *trivial_lookup_gname(void *, int64_t gid);
+static const char *trivial_lookup_uname(void *, int64_t uid);
+static int setup_sparse(struct archive_read_disk *, struct archive_entry *);
+static int close_and_restore_time(HANDLE, struct tree *,
+ struct restore_time *);
+static int setup_sparse_from_disk(struct archive_read_disk *,
+ struct archive_entry *, HANDLE);
+
+
+
+static struct archive_vtable *
+archive_read_disk_vtable(void)
+{
+ static struct archive_vtable av;
+ static int inited = 0;
+
+ if (!inited) {
+ 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_header2 = _archive_read_next_header2;
+ inited = 1;
+ }
+ return (&av);
+}
+
+const char *
+archive_read_disk_gname(struct archive *_a, int64_t gid)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_gname"))
+ return (NULL);
+ if (a->lookup_gname == NULL)
+ return (NULL);
+ return ((*a->lookup_gname)(a->lookup_gname_data, gid));
+}
+
+const char *
+archive_read_disk_uname(struct archive *_a, int64_t uid)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_uname"))
+ return (NULL);
+ if (a->lookup_uname == NULL)
+ return (NULL);
+ return ((*a->lookup_uname)(a->lookup_uname_data, uid));
+}
+
+int
+archive_read_disk_set_gname_lookup(struct archive *_a,
+ void *private_data,
+ const char * (*lookup_gname)(void *private, int64_t gid),
+ void (*cleanup_gname)(void *private))
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_gname_lookup");
+
+ if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL)
+ (a->cleanup_gname)(a->lookup_gname_data);
+
+ a->lookup_gname = lookup_gname;
+ a->cleanup_gname = cleanup_gname;
+ a->lookup_gname_data = private_data;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_uname_lookup(struct archive *_a,
+ void *private_data,
+ const char * (*lookup_uname)(void *private, int64_t uid),
+ void (*cleanup_uname)(void *private))
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_uname_lookup");
+
+ if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL)
+ (a->cleanup_uname)(a->lookup_uname_data);
+
+ a->lookup_uname = lookup_uname;
+ a->cleanup_uname = cleanup_uname;
+ a->lookup_uname_data = private_data;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Create a new archive_read_disk object and initialize it with global state.
+ */
+struct archive *
+archive_read_disk_new(void)
+{
+ struct archive_read_disk *a;
+
+ a = (struct archive_read_disk *)malloc(sizeof(*a));
+ if (a == NULL)
+ return (NULL);
+ memset(a, 0, sizeof(*a));
+ a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
+ a->archive.state = ARCHIVE_STATE_NEW;
+ a->archive.vtable = archive_read_disk_vtable();
+ a->lookup_uname = trivial_lookup_uname;
+ a->lookup_gname = trivial_lookup_gname;
+ a->enable_copyfile = 1;
+ a->traverse_mount_points = 1;
+ return (&a->archive);
+}
+
+static int
+_archive_read_free(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ int r;
+
+ if (_a == NULL)
+ return (ARCHIVE_OK);
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_free");
+
+ if (a->archive.state != ARCHIVE_STATE_CLOSED)
+ r = _archive_read_close(&a->archive);
+ else
+ r = ARCHIVE_OK;
+
+ tree_free(a->tree);
+ if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL)
+ (a->cleanup_gname)(a->lookup_gname_data);
+ if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL)
+ (a->cleanup_uname)(a->lookup_uname_data);
+ archive_string_free(&a->archive.error_string);
+ a->archive.magic = 0;
+ free(a);
+ return (r);
+}
+
+static int
+_archive_read_close(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_close");
+
+ if (a->archive.state != ARCHIVE_STATE_FATAL)
+ a->archive.state = ARCHIVE_STATE_CLOSED;
+
+ tree_close(a->tree);
+
+ return (ARCHIVE_OK);
+}
+
+static void
+setup_symlink_mode(struct archive_read_disk *a, char symlink_mode,
+ int follow_symlinks)
+{
+ a->symlink_mode = symlink_mode;
+ a->follow_symlinks = follow_symlinks;
+ if (a->tree != NULL) {
+ a->tree->initial_symlink_mode = a->symlink_mode;
+ a->tree->symlink_mode = a->symlink_mode;
+ }
+}
+
+int
+archive_read_disk_set_symlink_logical(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_logical");
+ setup_symlink_mode(a, 'L', 1);
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_symlink_physical(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_physical");
+ setup_symlink_mode(a, 'P', 0);
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_symlink_hybrid(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_hybrid");
+ setup_symlink_mode(a, 'H', 1);/* Follow symlinks initially. */
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_atime_restored(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_restore_atime");
+ a->restore_time = 1;
+ if (a->tree != NULL)
+ a->tree->flags |= needsRestoreTimes;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_behavior(struct archive *_a, int flags)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ int r = ARCHIVE_OK;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_honor_nodump");
+
+ if (flags & ARCHIVE_READDISK_RESTORE_ATIME)
+ r = archive_read_disk_set_atime_restored(_a);
+ else {
+ a->restore_time = 0;
+ if (a->tree != NULL)
+ a->tree->flags &= ~needsRestoreTimes;
+ }
+ if (flags & ARCHIVE_READDISK_HONOR_NODUMP)
+ a->honor_nodump = 1;
+ else
+ a->honor_nodump = 0;
+ if (flags & ARCHIVE_READDISK_MAC_COPYFILE)
+ a->enable_copyfile = 1;
+ else
+ a->enable_copyfile = 0;
+ if (flags & ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS)
+ a->traverse_mount_points = 0;
+ else
+ a->traverse_mount_points = 1;
+ return (r);
+}
+
+/*
+ * Trivial implementations of gname/uname lookup functions.
+ * These are normally overridden by the client, but these stub
+ * versions ensure that we always have something that works.
+ */
+static const char *
+trivial_lookup_gname(void *private_data, int64_t gid)
+{
+ (void)private_data; /* UNUSED */
+ (void)gid; /* UNUSED */
+ return (NULL);
+}
+
+static const char *
+trivial_lookup_uname(void *private_data, int64_t uid)
+{
+ (void)private_data; /* UNUSED */
+ (void)uid; /* UNUSED */
+ return (NULL);
+}
+
+static int64_t
+align_num_per_sector(struct tree *t, int64_t size)
+{
+ int64_t surplus;
+
+ size += t->current_filesystem->bytesPerSector -1;
+ surplus = size % t->current_filesystem->bytesPerSector;
+ size -= surplus;
+ return (size);
+}
+
+static int
+start_next_async_read(struct archive_read_disk *a, struct tree *t)
+{
+ struct la_overlapped *olp;
+ DWORD buffbytes, rbytes;
+
+ if (t->ol_remaining_bytes == 0)
+ return (ARCHIVE_EOF);
+
+ olp = &(t->ol[t->ol_idx_doing]);
+ t->ol_idx_doing = (t->ol_idx_doing + 1) % MAX_OVERLAPPED;
+
+ /* Allocate read buffer. */
+ if (olp->buff == NULL) {
+ void *p;
+ size_t s = (size_t)align_num_per_sector(t, BUFFER_SIZE);
+ p = VirtualAlloc(NULL, s, MEM_COMMIT, PAGE_READWRITE);
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't allocate memory");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ olp->buff = p;
+ olp->buff_size = s;
+ olp->_a = &a->archive;
+ olp->ol.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
+ if (olp->ol.hEvent == NULL) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&a->archive, errno,
+ "CreateEvent failed");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ } else
+ ResetEvent(olp->ol.hEvent);
+
+ buffbytes = (DWORD)olp->buff_size;
+ if (buffbytes > t->current_sparse->length)
+ buffbytes = (DWORD)t->current_sparse->length;
+
+ /* Skip hole. */
+ if (t->current_sparse->offset > t->ol_total) {
+ t->ol_remaining_bytes -=
+ t->current_sparse->offset - t->ol_total;
+ }
+
+ olp->offset = t->current_sparse->offset;
+ olp->ol.Offset = (DWORD)(olp->offset & 0xffffffff);
+ olp->ol.OffsetHigh = (DWORD)(olp->offset >> 32);
+
+ if (t->ol_remaining_bytes > buffbytes) {
+ olp->bytes_expected = buffbytes;
+ t->ol_remaining_bytes -= buffbytes;
+ } else {
+ olp->bytes_expected = (size_t)t->ol_remaining_bytes;
+ t->ol_remaining_bytes = 0;
+ }
+ olp->bytes_transferred = 0;
+ t->current_sparse->offset += buffbytes;
+ t->current_sparse->length -= buffbytes;
+ t->ol_total = t->current_sparse->offset;
+ if (t->current_sparse->length == 0 && t->ol_remaining_bytes > 0)
+ t->current_sparse++;
+
+ if (!ReadFile(t->entry_fh, olp->buff, buffbytes, &rbytes, &(olp->ol))) {
+ DWORD lasterr;
+
+ lasterr = GetLastError();
+ if (lasterr == ERROR_HANDLE_EOF) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Reading file truncated");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ } else if (lasterr != ERROR_IO_PENDING) {
+ if (lasterr == ERROR_NO_DATA)
+ errno = EAGAIN;
+ else if (lasterr == ERROR_ACCESS_DENIED)
+ errno = EBADF;
+ else
+ la_dosmaperr(lasterr);
+ archive_set_error(&a->archive, errno, "Read error");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ } else
+ olp->bytes_transferred = rbytes;
+ t->ol_num_doing++;
+
+ return (t->ol_remaining_bytes == 0)? ARCHIVE_EOF: ARCHIVE_OK;
+}
+
+static void
+cancel_async(struct tree *t)
+{
+ if (t->ol_num_doing != t->ol_num_done) {
+ CancelIo(t->entry_fh);
+ t->ol_num_doing = t->ol_num_done = 0;
+ }
+}
+
+static int
+_archive_read_data_block(struct archive *_a, const void **buff,
+ size_t *size, int64_t *offset)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct tree *t = a->tree;
+ struct la_overlapped *olp;
+ DWORD bytes_transferred;
+ int r = ARCHIVE_FATAL;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_data_block");
+
+ if (t->entry_eof || t->entry_remaining_bytes <= 0) {
+ r = ARCHIVE_EOF;
+ goto abort_read_data;
+ }
+
+ /*
+ * Make a request to read the file in asynchronous.
+ */
+ if (t->ol_num_doing == 0) {
+ do {
+ r = start_next_async_read(a, t);
+ if (r == ARCHIVE_FATAL)
+ goto abort_read_data;
+ if (!t->async_io)
+ break;
+ } while (r == ARCHIVE_OK && t->ol_num_doing < MAX_OVERLAPPED);
+ } else {
+ if (start_next_async_read(a, t) == ARCHIVE_FATAL)
+ goto abort_read_data;
+ }
+
+ olp = &(t->ol[t->ol_idx_done]);
+ t->ol_idx_done = (t->ol_idx_done + 1) % MAX_OVERLAPPED;
+ if (olp->bytes_transferred)
+ bytes_transferred = (DWORD)olp->bytes_transferred;
+ else if (!GetOverlappedResult(t->entry_fh, &(olp->ol),
+ &bytes_transferred, TRUE)) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&a->archive, errno,
+ "GetOverlappedResult failed");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ r = ARCHIVE_FATAL;
+ goto abort_read_data;
+ }
+ t->ol_num_done++;
+
+ if (bytes_transferred == 0 ||
+ olp->bytes_expected != bytes_transferred) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Reading file truncated");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ r = ARCHIVE_FATAL;
+ goto abort_read_data;
+ }
+
+ *buff = olp->buff;
+ *size = bytes_transferred;
+ *offset = olp->offset;
+ if (olp->offset > t->entry_total)
+ t->entry_remaining_bytes -= olp->offset - t->entry_total;
+ t->entry_total = olp->offset + *size;
+ t->entry_remaining_bytes -= *size;
+ if (t->entry_remaining_bytes == 0) {
+ /* Close the current file descriptor */
+ close_and_restore_time(t->entry_fh, t, &t->restore_time);
+ t->entry_fh = INVALID_HANDLE_VALUE;
+ t->entry_eof = 1;
+ }
+ return (ARCHIVE_OK);
+
+abort_read_data:
+ *buff = NULL;
+ *size = 0;
+ *offset = t->entry_total;
+ if (t->entry_fh != INVALID_HANDLE_VALUE) {
+ cancel_async(t);
+ /* Close the current file descriptor */
+ close_and_restore_time(t->entry_fh, t, &t->restore_time);
+ t->entry_fh = INVALID_HANDLE_VALUE;
+ }
+ return (r);
+}
+
+static int
+next_entry(struct archive_read_disk *a, struct tree *t,
+ struct archive_entry *entry)
+{
+ const BY_HANDLE_FILE_INFORMATION *st;
+ const BY_HANDLE_FILE_INFORMATION *lst;
+ const char*name;
+ int descend, r;
+
+ st = NULL;
+ lst = NULL;
+ t->descend = 0;
+ do {
+ switch (tree_next(t)) {
+ case TREE_ERROR_FATAL:
+ archive_set_error(&a->archive, t->tree_errno,
+ "%ls: Unable to continue traversing directory tree",
+ tree_current_path(t));
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ case TREE_ERROR_DIR:
+ archive_set_error(&a->archive, t->tree_errno,
+ "%ls: Couldn't visit directory",
+ tree_current_path(t));
+ return (ARCHIVE_FAILED);
+ case 0:
+ return (ARCHIVE_EOF);
+ case TREE_POSTDESCENT:
+ case TREE_POSTASCENT:
+ break;
+ case TREE_REGULAR:
+ lst = tree_current_lstat(t);
+ if (lst == NULL) {
+ archive_set_error(&a->archive, t->tree_errno,
+ "%ls: Cannot stat",
+ tree_current_path(t));
+ return (ARCHIVE_FAILED);
+ }
+ break;
+ }
+ } while (lst == NULL);
+
+ archive_entry_copy_pathname_w(entry, tree_current_path(t));
+
+ /*
+ * Perform path matching.
+ */
+ if (a->matching) {
+ r = archive_match_path_excluded(a->matching, entry);
+ if (r < 0) {
+ archive_set_error(&(a->archive), errno,
+ "Faild : %s", archive_error_string(a->matching));
+ return (r);
+ }
+ if (r) {
+ if (a->excluded_cb_func)
+ a->excluded_cb_func(&(a->archive),
+ a->excluded_cb_data, entry);
+ return (ARCHIVE_RETRY);
+ }
+ }
+
+ /*
+ * Distinguish 'L'/'P'/'H' symlink following.
+ */
+ switch(t->symlink_mode) {
+ case 'H':
+ /* 'H': After the first item, rest like 'P'. */
+ t->symlink_mode = 'P';
+ /* 'H': First item (from command line) like 'L'. */
+ /* FALLTHROUGH */
+ case 'L':
+ /* 'L': Do descend through a symlink to dir. */
+ descend = tree_current_is_dir(t);
+ /* 'L': Follow symlinks to files. */
+ a->symlink_mode = 'L';
+ a->follow_symlinks = 1;
+ /* 'L': Archive symlinks as targets, if we can. */
+ st = tree_current_stat(t);
+ if (st != NULL && !tree_target_is_same_as_parent(t, st))
+ break;
+ /* If stat fails, we have a broken symlink;
+ * in that case, don't follow the link. */
+ /* FALLTHROUGH */
+ default:
+ /* 'P': Don't descend through a symlink to dir. */
+ descend = tree_current_is_physical_dir(t);
+ /* 'P': Don't follow symlinks to files. */
+ a->symlink_mode = 'P';
+ a->follow_symlinks = 0;
+ /* 'P': Archive symlinks as symlinks. */
+ st = lst;
+ break;
+ }
+
+ if (update_current_filesystem(a, bhfi_dev(st)) != ARCHIVE_OK) {
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ if (t->initial_filesystem_id == -1)
+ 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);
+ }
+ t->descend = descend;
+
+ tree_archive_entry_copy_bhfi(entry, t, st);
+
+ /* Save the times to be restored. This must be in before
+ * calling archive_read_disk_descend() or any chance of it,
+ * especially, invokng a callback. */
+ t->restore_time.lastWriteTime = st->ftLastWriteTime;
+ t->restore_time.lastAccessTime = st->ftLastAccessTime;
+ t->restore_time.filetype = archive_entry_filetype(entry);
+
+ /*
+ * Perform time matching.
+ */
+ if (a->matching) {
+ r = archive_match_time_excluded(a->matching, entry);
+ if (r < 0) {
+ archive_set_error(&(a->archive), errno,
+ "Faild : %s", archive_error_string(a->matching));
+ return (r);
+ }
+ if (r) {
+ if (a->excluded_cb_func)
+ a->excluded_cb_func(&(a->archive),
+ a->excluded_cb_data, entry);
+ return (ARCHIVE_RETRY);
+ }
+ }
+
+ /* Lookup uname/gname */
+ name = archive_read_disk_uname(&(a->archive), archive_entry_uid(entry));
+ if (name != NULL)
+ archive_entry_copy_uname(entry, name);
+ name = archive_read_disk_gname(&(a->archive), archive_entry_gid(entry));
+ if (name != NULL)
+ archive_entry_copy_gname(entry, name);
+
+ /*
+ * Perform owner matching.
+ */
+ if (a->matching) {
+ r = archive_match_owner_excluded(a->matching, entry);
+ if (r < 0) {
+ archive_set_error(&(a->archive), errno,
+ "Faild : %s", archive_error_string(a->matching));
+ return (r);
+ }
+ if (r) {
+ if (a->excluded_cb_func)
+ a->excluded_cb_func(&(a->archive),
+ a->excluded_cb_data, entry);
+ return (ARCHIVE_RETRY);
+ }
+ }
+
+ /*
+ * Invoke a meta data filter callback.
+ */
+ if (a->metadata_filter_func) {
+ if (!a->metadata_filter_func(&(a->archive),
+ a->metadata_filter_data, entry))
+ return (ARCHIVE_RETRY);
+ }
+
+ archive_entry_copy_sourcepath_w(entry, tree_current_access_path(t));
+
+ r = ARCHIVE_OK;
+ if (archive_entry_filetype(entry) == AE_IFREG &&
+ archive_entry_size(entry) > 0) {
+ DWORD flags = FILE_FLAG_BACKUP_SEMANTICS;
+ if (t->async_io)
+ flags |= FILE_FLAG_OVERLAPPED;
+ if (t->direct_io)
+ flags |= FILE_FLAG_NO_BUFFERING;
+ else
+ flags |= FILE_FLAG_SEQUENTIAL_SCAN;
+ t->entry_fh = CreateFileW(tree_current_access_path(t),
+ GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, flags, NULL);
+ if (t->entry_fh == INVALID_HANDLE_VALUE) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't open %ls", tree_current_path(a->tree));
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Find sparse data from the disk. */
+ if (archive_entry_hardlink(entry) == NULL &&
+ (st->dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) != 0)
+ r = setup_sparse_from_disk(a, entry, t->entry_fh);
+ }
+ return (r);
+}
+
+static int
+_archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct tree *t;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_read_next_header2");
+
+ t = a->tree;
+ if (t->entry_fh != INVALID_HANDLE_VALUE) {
+ cancel_async(t);
+ close_and_restore_time(t->entry_fh, t, &t->restore_time);
+ t->entry_fh = INVALID_HANDLE_VALUE;
+ }
+
+ while ((r = next_entry(a, t, entry)) == ARCHIVE_RETRY)
+ archive_entry_clear(entry);
+
+ /*
+ * EOF and FATAL are persistent at this layer. By
+ * modifying the state, we guarantee that future calls to
+ * read a header or read data will fail.
+ */
+ switch (r) {
+ case ARCHIVE_EOF:
+ a->archive.state = ARCHIVE_STATE_EOF;
+ break;
+ case ARCHIVE_OK:
+ case ARCHIVE_WARN:
+ t->entry_total = 0;
+ if (archive_entry_filetype(entry) == AE_IFREG) {
+ t->entry_remaining_bytes = archive_entry_size(entry);
+ t->entry_eof = (t->entry_remaining_bytes == 0)? 1: 0;
+ if (!t->entry_eof &&
+ setup_sparse(a, entry) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } else {
+ t->entry_remaining_bytes = 0;
+ t->entry_eof = 1;
+ }
+ t->ol_idx_doing = t->ol_idx_done = 0;
+ t->ol_num_doing = t->ol_num_done = 0;
+ t->ol_remaining_bytes = t->entry_remaining_bytes;
+ t->ol_total = 0;
+ a->archive.state = ARCHIVE_STATE_DATA;
+ break;
+ case ARCHIVE_RETRY:
+ break;
+ case ARCHIVE_FATAL:
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ break;
+ }
+
+ return (r);
+}
+
+static int
+setup_sparse(struct archive_read_disk *a, struct archive_entry *entry)
+{
+ struct tree *t = a->tree;
+ int64_t aligned, length, offset;
+ int i;
+
+ t->sparse_count = archive_entry_sparse_reset(entry);
+ if (t->sparse_count+1 > t->sparse_list_size) {
+ free(t->sparse_list);
+ t->sparse_list_size = t->sparse_count + 1;
+ t->sparse_list = malloc(sizeof(t->sparse_list[0]) *
+ t->sparse_list_size);
+ if (t->sparse_list == NULL) {
+ t->sparse_list_size = 0;
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate data");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ }
+ /*
+ * Get sparse list and make sure those offsets and lengths are
+ * aligned by a sector size.
+ */
+ for (i = 0; i < t->sparse_count; i++) {
+ archive_entry_sparse_next(entry, &offset, &length);
+ aligned = align_num_per_sector(t, offset);
+ if (aligned != offset) {
+ aligned -= t->current_filesystem->bytesPerSector;
+ length += offset - aligned;
+ }
+ t->sparse_list[i].offset = aligned;
+ aligned = align_num_per_sector(t, length);
+ t->sparse_list[i].length = aligned;
+ }
+
+ aligned = align_num_per_sector(t, archive_entry_size(entry));
+ if (i == 0) {
+ t->sparse_list[i].offset = 0;
+ t->sparse_list[i].length = aligned;
+ } else {
+ int j, last = i;
+
+ t->sparse_list[i].offset = aligned;
+ t->sparse_list[i].length = 0;
+ for (i = 0; i < last; i++) {
+ if ((t->sparse_list[i].offset +
+ t->sparse_list[i].length) <=
+ t->sparse_list[i+1].offset)
+ continue;
+ /*
+ * Now sparse_list[i+1] is overlapped by sparse_list[i].
+ * Merge those two.
+ */
+ length = t->sparse_list[i+1].offset -
+ t->sparse_list[i].offset;
+ t->sparse_list[i+1].offset = t->sparse_list[i].offset;
+ t->sparse_list[i+1].length += length;
+ /* Remove sparse_list[i]. */
+ for (j = i; j < last; j++) {
+ t->sparse_list[j].offset =
+ t->sparse_list[j+1].offset;
+ t->sparse_list[j].length =
+ t->sparse_list[j+1].length;
+ }
+ last--;
+ }
+ }
+ t->current_sparse = t->sparse_list;
+
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_matching(struct archive *_a, struct archive *_ma,
+ void (*_excluded_func)(struct archive *, void *, struct archive_entry *),
+ void *_client_data)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_read_disk_set_matching");
+ a->matching = _ma;
+ a->excluded_cb_func = _excluded_func;
+ a->excluded_cb_data = _client_data;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_set_metadata_filter_callback(struct archive *_a,
+ int (*_metadata_filter_func)(struct archive *, void *,
+ struct archive_entry *), void *_client_data)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_ANY,
+ "archive_read_disk_set_metadata_filter_callback");
+
+ a->metadata_filter_func = _metadata_filter_func;
+ a->metadata_filter_data = _client_data;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_can_descend(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct tree *t = a->tree;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_read_disk_can_descend");
+
+ return (t->visit_type == TREE_REGULAR && t->descend);
+}
+
+/*
+ * Called by the client to mark the directory just returned from
+ * tree_next() as needing to be visited.
+ */
+int
+archive_read_disk_descend(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct tree *t = a->tree;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_read_disk_descend");
+
+ if (t->visit_type != TREE_REGULAR || !t->descend)
+ return (ARCHIVE_OK);
+
+ if (tree_current_is_physical_dir(t)) {
+ tree_push(t, t->basename, t->full_path.s,
+ t->current_filesystem_id,
+ bhfi_dev(&(t->lst)), bhfi_ino(&(t->lst)),
+ &t->restore_time);
+ t->stack->flags |= isDir;
+ } else if (tree_current_is_dir(t)) {
+ tree_push(t, t->basename, t->full_path.s,
+ t->current_filesystem_id,
+ bhfi_dev(&(t->st)), bhfi_ino(&(t->st)),
+ &t->restore_time);
+ t->stack->flags |= isDirLink;
+ }
+ t->descend = 0;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_disk_open(struct archive *_a, const char *pathname)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ struct archive_wstring wpath;
+ int ret;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_NEW | ARCHIVE_STATE_CLOSED,
+ "archive_read_disk_open");
+ archive_clear_error(&a->archive);
+
+ /* Make a wchar_t string from a char string. */
+ archive_string_init(&wpath);
+ if (archive_wstring_append_from_mbs(&wpath, pathname,
+ strlen(pathname)) != 0) {
+ if (errno == ENOMEM)
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't convert a path to a wchar_t string");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ ret = ARCHIVE_FATAL;
+ } else
+ ret = _archive_read_disk_open_w(_a, wpath.s);
+
+ archive_wstring_free(&wpath);
+ return (ret);
+}
+
+int
+archive_read_disk_open_w(struct archive *_a, const wchar_t *pathname)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
+ ARCHIVE_STATE_NEW | ARCHIVE_STATE_CLOSED,
+ "archive_read_disk_open_w");
+ archive_clear_error(&a->archive);
+
+ return (_archive_read_disk_open_w(_a, pathname));
+}
+
+static int
+_archive_read_disk_open_w(struct archive *_a, const wchar_t *pathname)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ if (a->tree != NULL)
+ a->tree = tree_reopen(a->tree, pathname, a->restore_time);
+ else
+ a->tree = tree_open(pathname, a->symlink_mode, a->restore_time);
+ if (a->tree == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate directory traversal data");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ a->archive.state = ARCHIVE_STATE_HEADER;
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Return a current filesystem ID which is index of the filesystem entry
+ * you've visited through archive_read_disk.
+ */
+int
+archive_read_disk_current_filesystem(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_disk_current_filesystem");
+
+ return (a->tree->current_filesystem_id);
+}
+
+static int
+update_current_filesystem(struct archive_read_disk *a, int64_t dev)
+{
+ struct tree *t = a->tree;
+ int i, fid;
+
+ if (t->current_filesystem != NULL &&
+ t->current_filesystem->dev == dev)
+ return (ARCHIVE_OK);
+
+ for (i = 0; i < t->max_filesystem_id; i++) {
+ if (t->filesystem_table[i].dev == dev) {
+ /* There is the filesytem ID we've already generated. */
+ t->current_filesystem_id = i;
+ t->current_filesystem = &(t->filesystem_table[i]);
+ return (ARCHIVE_OK);
+ }
+ }
+
+ /*
+ * There is a new filesytem, we generate a new ID for.
+ */
+ fid = t->max_filesystem_id++;
+ if (t->max_filesystem_id > t->allocated_filesytem) {
+ size_t s;
+ void *p;
+
+ s = t->max_filesystem_id * 2;
+ p = realloc(t->filesystem_table,
+ s * sizeof(*t->filesystem_table));
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate tar data");
+ return (ARCHIVE_FATAL);
+ }
+ t->filesystem_table = (struct filesystem *)p;
+ t->allocated_filesytem = (int)s;
+ }
+ t->current_filesystem_id = fid;
+ t->current_filesystem = &(t->filesystem_table[fid]);
+ t->current_filesystem->dev = dev;
+
+ return (setup_current_filesystem(a));
+}
+
+/*
+ * Returns 1 if current filesystem is generated filesystem, 0 if it is not
+ * or -1 if it is unknown.
+ */
+int
+archive_read_disk_current_filesystem_is_synthetic(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_disk_current_filesystem");
+
+ return (a->tree->current_filesystem->synthetic);
+}
+
+/*
+ * Returns 1 if current filesystem is remote filesystem, 0 if it is not
+ * or -1 if it is unknown.
+ */
+int
+archive_read_disk_current_filesystem_is_remote(struct archive *_a)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+
+ archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA,
+ "archive_read_disk_current_filesystem");
+
+ return (a->tree->current_filesystem->remote);
+}
+
+/*
+ * If symlink is broken, statfs or statvfs will fail.
+ * Use its directory path instead.
+ */
+static wchar_t *
+safe_path_for_statfs(struct tree *t)
+{
+ const wchar_t *path;
+ wchar_t *cp, *p = NULL;
+
+ path = tree_current_access_path(t);
+ if (tree_current_stat(t) == NULL) {
+ p = _wcsdup(path);
+ cp = wcsrchr(p, '/');
+ if (cp != NULL && wcslen(cp) >= 2) {
+ cp[1] = '.';
+ cp[2] = '\0';
+ path = p;
+ }
+ } else
+ p = _wcsdup(path);
+ return (p);
+}
+
+/*
+ * Get conditions of synthetic and remote on Windows
+ */
+static int
+setup_current_filesystem(struct archive_read_disk *a)
+{
+ struct tree *t = a->tree;
+ wchar_t vol[256];
+ wchar_t *path;
+
+ t->current_filesystem->synthetic = -1;/* Not supported */
+ path = safe_path_for_statfs(t);
+ if (!GetVolumePathNameW(path, vol, sizeof(vol)/sizeof(vol[0]))) {
+ free(path);
+ t->current_filesystem->remote = -1;
+ t->current_filesystem->bytesPerSector = 0;
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "GetVolumePathName failed: %d", (int)GetLastError());
+ return (ARCHIVE_FAILED);
+ }
+ free(path);
+ switch (GetDriveTypeW(vol)) {
+ case DRIVE_UNKNOWN:
+ case DRIVE_NO_ROOT_DIR:
+ t->current_filesystem->remote = -1;
+ break;
+ case DRIVE_REMOTE:
+ t->current_filesystem->remote = 1;
+ break;
+ default:
+ t->current_filesystem->remote = 0;
+ break;
+ }
+
+ if (!GetDiskFreeSpaceW(vol, NULL,
+ &(t->current_filesystem->bytesPerSector), NULL, NULL)) {
+ t->current_filesystem->bytesPerSector = 0;
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "GetDiskFreeSpace failed: %d", (int)GetLastError());
+ return (ARCHIVE_FAILED);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static int
+close_and_restore_time(HANDLE h, struct tree *t, struct restore_time *rt)
+{
+ HANDLE handle;
+ int r = 0;
+
+ if (h == INVALID_HANDLE_VALUE && AE_IFLNK == rt->filetype)
+ return (0);
+
+ /* Close a file descritor.
+ * It will not be used for SetFileTime() because it has been opened
+ * by a read only mode.
+ */
+ if (h != INVALID_HANDLE_VALUE)
+ CloseHandle(h);
+ if ((t->flags & needsRestoreTimes) == 0)
+ return (r);
+
+ handle = CreateFileW(rt->full_path, FILE_WRITE_ATTRIBUTES,
+ 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ if (handle == INVALID_HANDLE_VALUE) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if (SetFileTime(handle, NULL, &rt->lastAccessTime,
+ &rt->lastWriteTime) == 0) {
+ errno = EINVAL;
+ r = -1;
+ } else
+ r = 0;
+ CloseHandle(handle);
+ return (r);
+}
+
+/*
+ * Add a directory path to the current stack.
+ */
+static void
+tree_push(struct tree *t, const wchar_t *path, const wchar_t *full_path,
+ int filesystem_id, int64_t dev, int64_t ino, struct restore_time *rt)
+{
+ struct tree_entry *te;
+
+ te = malloc(sizeof(*te));
+ memset(te, 0, sizeof(*te));
+ te->next = t->stack;
+ te->parent = t->current;
+ if (te->parent)
+ te->depth = te->parent->depth + 1;
+ t->stack = te;
+ archive_string_init(&te->name);
+ archive_wstrcpy(&te->name, path);
+ archive_string_init(&te->full_path);
+ archive_wstrcpy(&te->full_path, full_path);
+ te->flags = needsDescent | needsOpen | needsAscent;
+ te->filesystem_id = filesystem_id;
+ te->dev = dev;
+ te->ino = ino;
+ te->dirname_length = t->dirname_length;
+ te->full_path_dir_length = t->full_path_dir_length;
+ te->restore_time.full_path = te->full_path.s;
+ if (rt != NULL) {
+ te->restore_time.lastWriteTime = rt->lastWriteTime;
+ te->restore_time.lastAccessTime = rt->lastAccessTime;
+ te->restore_time.filetype = rt->filetype;
+ }
+}
+
+/*
+ * Append a name to the current dir path.
+ */
+static void
+tree_append(struct tree *t, const wchar_t *name, size_t name_length)
+{
+ size_t size_needed;
+
+ t->path.s[t->dirname_length] = L'\0';
+ t->path.length = t->dirname_length;
+ /* Strip trailing '/' from name, unless entire name is "/". */
+ while (name_length > 1 && name[name_length - 1] == L'/')
+ name_length--;
+
+ /* Resize pathname buffer as needed. */
+ size_needed = name_length + t->dirname_length + 2;
+ archive_wstring_ensure(&t->path, size_needed);
+ /* Add a separating '/' if it's needed. */
+ if (t->dirname_length > 0 &&
+ t->path.s[archive_strlen(&t->path)-1] != L'/')
+ archive_wstrappend_wchar(&t->path, L'/');
+ t->basename = t->path.s + archive_strlen(&t->path);
+ archive_wstrncat(&t->path, name, name_length);
+ t->restore_time.full_path = t->basename;
+ if (t->full_path_dir_length > 0) {
+ t->full_path.s[t->full_path_dir_length] = L'\0';
+ t->full_path.length = t->full_path_dir_length;
+ size_needed = name_length + t->full_path_dir_length + 2;
+ archive_wstring_ensure(&t->full_path, size_needed);
+ /* Add a separating '\' if it's needed. */
+ if (t->full_path.s[archive_strlen(&t->full_path)-1] != L'\\')
+ archive_wstrappend_wchar(&t->full_path, L'\\');
+ archive_wstrncat(&t->full_path, name, name_length);
+ t->restore_time.full_path = t->full_path.s;
+ }
+}
+
+/*
+ * Open a directory tree for traversal.
+ */
+static struct tree *
+tree_open(const wchar_t *path, int symlink_mode, int restore_time)
+{
+ struct tree *t;
+
+ t = malloc(sizeof(*t));
+ memset(t, 0, sizeof(*t));
+ archive_string_init(&(t->full_path));
+ archive_string_init(&t->path);
+ archive_wstring_ensure(&t->path, 15);
+ t->initial_symlink_mode = symlink_mode;
+ return (tree_reopen(t, path, restore_time));
+}
+
+static struct tree *
+tree_reopen(struct tree *t, const wchar_t *path, int restore_time)
+{
+ struct archive_wstring ws;
+ wchar_t *pathname, *p, *base;
+
+ t->flags = (restore_time)?needsRestoreTimes:0;
+ t->visit_type = 0;
+ t->tree_errno = 0;
+ t->full_path_dir_length = 0;
+ t->dirname_length = 0;
+ t->depth = 0;
+ t->descend = 0;
+ t->current = NULL;
+ t->d = INVALID_HANDLE_VALUE;
+ t->symlink_mode = t->initial_symlink_mode;
+ archive_string_empty(&(t->full_path));
+ archive_string_empty(&t->path);
+ t->entry_fh = INVALID_HANDLE_VALUE;
+ t->entry_eof = 0;
+ t->entry_remaining_bytes = 0;
+ t->initial_filesystem_id = -1;
+
+ /* Get wchar_t strings from char strings. */
+ archive_string_init(&ws);
+ archive_wstrcpy(&ws, path);
+ pathname = ws.s;
+ /* Get a full-path-name. */
+ p = __la_win_permissive_name_w(pathname);
+ if (p == NULL)
+ goto failed;
+ archive_wstrcpy(&(t->full_path), p);
+ free(p);
+
+ /* Convert path separators from '\' to '/' */
+ for (p = pathname; *p != L'\0'; ++p) {
+ if (*p == L'\\')
+ *p = L'/';
+ }
+ base = pathname;
+
+ /* First item is set up a lot like a symlink traversal. */
+ /* printf("Looking for wildcard in %s\n", path); */
+ if ((base[0] == L'/' && base[1] == L'/' &&
+ base[2] == L'?' && base[3] == L'/' &&
+ (wcschr(base+4, L'*') || wcschr(base+4, L'?'))) ||
+ (!(base[0] == L'/' && base[1] == L'/' &&
+ base[2] == L'?' && base[3] == L'/') &&
+ (wcschr(base, L'*') || wcschr(base, L'?')))) {
+ // It has a wildcard in it...
+ // Separate the last element.
+ p = wcsrchr(base, L'/');
+ if (p != NULL) {
+ *p = L'\0';
+ tree_append(t, base, p - base);
+ t->dirname_length = archive_strlen(&t->path);
+ base = p + 1;
+ }
+ p = wcsrchr(t->full_path.s, L'\\');
+ if (p != NULL) {
+ *p = L'\0';
+ t->full_path.length = wcslen(t->full_path.s);
+ t->full_path_dir_length = archive_strlen(&t->full_path);
+ }
+ }
+ tree_push(t, base, t->full_path.s, 0, 0, 0, NULL);
+ archive_wstring_free(&ws);
+ t->stack->flags = needsFirstVisit;
+ /*
+ * Debug flag for Direct IO(No buffering) or Async IO.
+ * Those dependant on environment variable switches
+ * will be removed until next release.
+ */
+ {
+ const char *e;
+ if ((e = getenv("LIBARCHIVE_DIRECT_IO")) != NULL) {
+ if (e[0] == '0')
+ t->direct_io = 0;
+ else
+ t->direct_io = 1;
+ fprintf(stderr, "LIBARCHIVE_DIRECT_IO=%s\n",
+ (t->direct_io)?"Enabled":"Disabled");
+ } else
+ t->direct_io = DIRECT_IO;
+ if ((e = getenv("LIBARCHIVE_ASYNC_IO")) != NULL) {
+ if (e[0] == '0')
+ t->async_io = 0;
+ else
+ t->async_io = 1;
+ fprintf(stderr, "LIBARCHIVE_ASYNC_IO=%s\n",
+ (t->async_io)?"Enabled":"Disabled");
+ } else
+ t->async_io = ASYNC_IO;
+ }
+ return (t);
+failed:
+ archive_wstring_free(&ws);
+ tree_free(t);
+ return (NULL);
+}
+
+static int
+tree_descent(struct tree *t)
+{
+ t->dirname_length = archive_strlen(&t->path);
+ t->full_path_dir_length = archive_strlen(&t->full_path);
+ t->depth++;
+ return (0);
+}
+
+/*
+ * We've finished a directory; ascend back to the parent.
+ */
+static int
+tree_ascend(struct tree *t)
+{
+ struct tree_entry *te;
+
+ te = t->stack;
+ t->depth--;
+ close_and_restore_time(INVALID_HANDLE_VALUE, t, &te->restore_time);
+ return (0);
+}
+
+/*
+ * Pop the working stack.
+ */
+static void
+tree_pop(struct tree *t)
+{
+ struct tree_entry *te;
+
+ t->full_path.s[t->full_path_dir_length] = L'\0';
+ t->full_path.length = t->full_path_dir_length;
+ t->path.s[t->dirname_length] = L'\0';
+ t->path.length = t->dirname_length;
+ if (t->stack == t->current && t->current != NULL)
+ t->current = t->current->parent;
+ te = t->stack;
+ t->stack = te->next;
+ t->dirname_length = te->dirname_length;
+ t->basename = t->path.s + t->dirname_length;
+ t->full_path_dir_length = te->full_path_dir_length;
+ while (t->basename[0] == L'/')
+ t->basename++;
+ archive_wstring_free(&te->name);
+ archive_wstring_free(&te->full_path);
+ free(te);
+}
+
+/*
+ * Get the next item in the tree traversal.
+ */
+static int
+tree_next(struct tree *t)
+{
+ int r;
+
+ while (t->stack != NULL) {
+ /* If there's an open dir, get the next entry from there. */
+ if (t->d != INVALID_HANDLE_VALUE) {
+ r = tree_dir_next_windows(t, NULL);
+ if (r == 0)
+ continue;
+ return (r);
+ }
+
+ if (t->stack->flags & needsFirstVisit) {
+ wchar_t *d = t->stack->name.s;
+ t->stack->flags &= ~needsFirstVisit;
+ if (!(d[0] == L'/' && d[1] == L'/' &&
+ d[2] == L'?' && d[3] == L'/') &&
+ (wcschr(d, L'*') || wcschr(d, L'?'))) {
+ r = tree_dir_next_windows(t, d);
+ if (r == 0)
+ continue;
+ return (r);
+ } else {
+ HANDLE h = FindFirstFileW(d, &t->_findData);
+ if (h == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ t->tree_errno = errno;
+ t->visit_type = TREE_ERROR_DIR;
+ return (t->visit_type);
+ }
+ t->findData = &t->_findData;
+ FindClose(h);
+ }
+ /* Top stack item needs a regular visit. */
+ t->current = t->stack;
+ tree_append(t, t->stack->name.s,
+ archive_strlen(&(t->stack->name)));
+ //t->dirname_length = t->path_length;
+ //tree_pop(t);
+ t->stack->flags &= ~needsFirstVisit;
+ return (t->visit_type = TREE_REGULAR);
+ } else if (t->stack->flags & needsDescent) {
+ /* Top stack item is dir to descend into. */
+ t->current = t->stack;
+ tree_append(t, t->stack->name.s,
+ archive_strlen(&(t->stack->name)));
+ t->stack->flags &= ~needsDescent;
+ r = tree_descent(t);
+ if (r != 0) {
+ tree_pop(t);
+ t->visit_type = r;
+ } else
+ t->visit_type = TREE_POSTDESCENT;
+ return (t->visit_type);
+ } else if (t->stack->flags & needsOpen) {
+ t->stack->flags &= ~needsOpen;
+ r = tree_dir_next_windows(t, L"*");
+ if (r == 0)
+ continue;
+ return (r);
+ } else if (t->stack->flags & needsAscent) {
+ /* Top stack item is dir and we're done with it. */
+ r = tree_ascend(t);
+ tree_pop(t);
+ t->visit_type = r != 0 ? r : TREE_POSTASCENT;
+ return (t->visit_type);
+ } else {
+ /* Top item on stack is dead. */
+ tree_pop(t);
+ t->flags &= ~hasLstat;
+ t->flags &= ~hasStat;
+ }
+ }
+ return (t->visit_type = 0);
+}
+
+static int
+tree_dir_next_windows(struct tree *t, const wchar_t *pattern)
+{
+ const wchar_t *name;
+ size_t namelen;
+ int r;
+
+ for (;;) {
+ if (pattern != NULL) {
+ struct archive_wstring pt;
+
+ archive_string_init(&pt);
+ archive_wstring_ensure(&pt,
+ archive_strlen(&(t->full_path))
+ + 2 + wcslen(pattern));
+ archive_wstring_copy(&pt, &(t->full_path));
+ archive_wstrappend_wchar(&pt, L'\\');
+ archive_wstrcat(&pt, pattern);
+ t->d = FindFirstFileW(pt.s, &t->_findData);
+ archive_wstring_free(&pt);
+ if (t->d == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ t->tree_errno = errno;
+ r = tree_ascend(t); /* Undo "chdir" */
+ tree_pop(t);
+ t->visit_type = r != 0 ? r : TREE_ERROR_DIR;
+ return (t->visit_type);
+ }
+ t->findData = &t->_findData;
+ pattern = NULL;
+ } else if (!FindNextFileW(t->d, &t->_findData)) {
+ FindClose(t->d);
+ t->d = INVALID_HANDLE_VALUE;
+ t->findData = NULL;
+ return (0);
+ }
+ name = t->findData->cFileName;
+ namelen = wcslen(name);
+ t->flags &= ~hasLstat;
+ t->flags &= ~hasStat;
+ if (name[0] == L'.' && name[1] == L'\0')
+ continue;
+ if (name[0] == L'.' && name[1] == L'.' && name[2] == L'\0')
+ continue;
+ tree_append(t, name, namelen);
+ return (t->visit_type = TREE_REGULAR);
+ }
+}
+
+#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
+static void
+fileTimeToUtc(const FILETIME *filetime, time_t *t, long *ns)
+{
+ ULARGE_INTEGER utc;
+
+ utc.HighPart = filetime->dwHighDateTime;
+ utc.LowPart = filetime->dwLowDateTime;
+ if (utc.QuadPart >= EPOC_TIME) {
+ utc.QuadPart -= EPOC_TIME;
+ /* milli seconds base */
+ *t = (time_t)(utc.QuadPart / 10000000);
+ /* nano seconds base */
+ *ns = (long)(utc.QuadPart % 10000000) * 100;
+ } else {
+ *t = 0;
+ *ns = 0;
+ }
+}
+
+static void
+entry_copy_bhfi(struct archive_entry *entry, const wchar_t *path,
+ const WIN32_FIND_DATAW *findData,
+ const BY_HANDLE_FILE_INFORMATION *bhfi)
+{
+ time_t secs;
+ long nsecs;
+ mode_t mode;
+
+ fileTimeToUtc(&bhfi->ftLastAccessTime, &secs, &nsecs);
+ archive_entry_set_atime(entry, secs, nsecs);
+ fileTimeToUtc(&bhfi->ftLastWriteTime, &secs, &nsecs);
+ archive_entry_set_mtime(entry, secs, nsecs);
+ fileTimeToUtc(&bhfi->ftCreationTime, &secs, &nsecs);
+ archive_entry_set_birthtime(entry, secs, nsecs);
+ archive_entry_set_ctime(entry, secs, nsecs);
+ archive_entry_set_dev(entry, bhfi_dev(bhfi));
+ archive_entry_set_ino64(entry, bhfi_ino(bhfi));
+ if (bhfi->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ archive_entry_set_nlink(entry, bhfi->nNumberOfLinks + 1);
+ else
+ archive_entry_set_nlink(entry, bhfi->nNumberOfLinks);
+ archive_entry_set_size(entry,
+ (((int64_t)bhfi->nFileSizeHigh) << 32)
+ + bhfi->nFileSizeLow);
+ archive_entry_set_uid(entry, 0);
+ archive_entry_set_gid(entry, 0);
+ archive_entry_set_rdev(entry, 0);
+
+ mode = S_IRUSR | S_IRGRP | S_IROTH;
+ if ((bhfi->dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0)
+ mode |= S_IWUSR | S_IWGRP | S_IWOTH;
+ if ((bhfi->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
+ findData != NULL &&
+ findData->dwReserved0 == IO_REPARSE_TAG_SYMLINK)
+ mode |= S_IFLNK;
+ else if (bhfi->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
+ else {
+ const wchar_t *p;
+
+ mode |= S_IFREG;
+ p = wcsrchr(path, L'.');
+ if (p != NULL && wcslen(p) == 4) {
+ switch (p[1]) {
+ case L'B': case L'b':
+ if ((p[2] == L'A' || p[2] == L'a' ) &&
+ (p[3] == L'T' || p[3] == L't' ))
+ mode |= S_IXUSR | S_IXGRP | S_IXOTH;
+ 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;
+ case L'E': case L'e':
+ if ((p[2] == L'X' || p[2] == L'x' ) &&
+ (p[3] == L'E' || p[3] == L'e' ))
+ mode |= S_IXUSR | S_IXGRP | S_IXOTH;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ archive_entry_set_mode(entry, mode);
+}
+
+static void
+tree_archive_entry_copy_bhfi(struct archive_entry *entry, struct tree *t,
+ const BY_HANDLE_FILE_INFORMATION *bhfi)
+{
+ entry_copy_bhfi(entry, tree_current_path(t), t->findData, bhfi);
+}
+
+static int
+tree_current_file_information(struct tree *t, BY_HANDLE_FILE_INFORMATION *st,
+ int sim_lstat)
+{
+ HANDLE h;
+ int r;
+ DWORD flag = FILE_FLAG_BACKUP_SEMANTICS;
+
+ if (sim_lstat && tree_current_is_physical_link(t))
+ flag |= FILE_FLAG_OPEN_REPARSE_POINT;
+ h = CreateFileW(tree_current_access_path(t), 0, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, flag, NULL);
+ if (h == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ t->tree_errno = errno;
+ return (0);
+ }
+ r = GetFileInformationByHandle(h, st);
+ CloseHandle(h);
+ return (r);
+}
+
+/*
+ * Get the stat() data for the entry just returned from tree_next().
+ */
+static const BY_HANDLE_FILE_INFORMATION *
+tree_current_stat(struct tree *t)
+{
+ if (!(t->flags & hasStat)) {
+ if (!tree_current_file_information(t, &t->st, 0))
+ return NULL;
+ t->flags |= hasStat;
+ }
+ return (&t->st);
+}
+
+/*
+ * Get the lstat() data for the entry just returned from tree_next().
+ */
+static const BY_HANDLE_FILE_INFORMATION *
+tree_current_lstat(struct tree *t)
+{
+ if (!(t->flags & hasLstat)) {
+ if (!tree_current_file_information(t, &t->lst, 1))
+ return NULL;
+ t->flags |= hasLstat;
+ }
+ return (&t->lst);
+}
+
+/*
+ * Test whether current entry is a dir or link to a dir.
+ */
+static int
+tree_current_is_dir(struct tree *t)
+{
+ if (t->findData)
+ return (t->findData->dwFileAttributes
+ & FILE_ATTRIBUTE_DIRECTORY);
+ return (0);
+}
+
+/*
+ * Test whether current entry is a physical directory. Usually, we
+ * already have at least one of stat() or lstat() in memory, so we
+ * use tricks to try to avoid an extra trip to the disk.
+ */
+static int
+tree_current_is_physical_dir(struct tree *t)
+{
+ if (tree_current_is_physical_link(t))
+ return (0);
+ return (tree_current_is_dir(t));
+}
+
+/*
+ * Test whether current entry is a symbolic link.
+ */
+static int
+tree_current_is_physical_link(struct tree *t)
+{
+ if (t->findData)
+ return ((t->findData->dwFileAttributes
+ & FILE_ATTRIBUTE_REPARSE_POINT) &&
+ (t->findData->dwReserved0
+ == IO_REPARSE_TAG_SYMLINK));
+ return (0);
+}
+
+/*
+ * Test whether the same file has been in the tree as its parent.
+ */
+static int
+tree_target_is_same_as_parent(struct tree *t,
+ const BY_HANDLE_FILE_INFORMATION *st)
+{
+ struct tree_entry *te;
+ int64_t dev = bhfi_dev(st);
+ int64_t ino = bhfi_ino(st);
+
+ for (te = t->current->parent; te != NULL; te = te->parent) {
+ if (te->dev == dev && te->ino == ino)
+ return (1);
+ }
+ return (0);
+}
+
+/*
+ * Return the access path for the entry just returned from tree_next().
+ */
+static const wchar_t *
+tree_current_access_path(struct tree *t)
+{
+ return (t->full_path.s);
+}
+
+/*
+ * Return the full path for the entry just returned from tree_next().
+ */
+static const wchar_t *
+tree_current_path(struct tree *t)
+{
+ return (t->path.s);
+}
+
+/*
+ * Terminate the traversal.
+ */
+static void
+tree_close(struct tree *t)
+{
+
+ if (t == NULL)
+ return;
+ if (t->entry_fh != INVALID_HANDLE_VALUE) {
+ cancel_async(t);
+ close_and_restore_time(t->entry_fh, t, &t->restore_time);
+ t->entry_fh = INVALID_HANDLE_VALUE;
+ }
+ /* Close the handle of FindFirstFileW */
+ if (t->d != INVALID_HANDLE_VALUE) {
+ FindClose(t->d);
+ t->d = INVALID_HANDLE_VALUE;
+ t->findData = NULL;
+ }
+ /* Release anything remaining in the stack. */
+ while (t->stack != NULL)
+ tree_pop(t);
+}
+
+/*
+ * Release any resources.
+ */
+static void
+tree_free(struct tree *t)
+{
+ int i;
+
+ if (t == NULL)
+ return;
+ archive_wstring_free(&t->path);
+ archive_wstring_free(&t->full_path);
+ free(t->sparse_list);
+ free(t->filesystem_table);
+ for (i = 0; i < MAX_OVERLAPPED; i++) {
+ if (t->ol[i].buff)
+ VirtualFree(t->ol[i].buff, 0, MEM_RELEASE);
+ CloseHandle(t->ol[i].ol.hEvent);
+ }
+ free(t);
+}
+
+
+/*
+ * Populate the archive_entry with metadata from the disk.
+ */
+int
+archive_read_disk_entry_from_file(struct archive *_a,
+ struct archive_entry *entry, int fd, const struct stat *st)
+{
+ struct archive_read_disk *a = (struct archive_read_disk *)_a;
+ const wchar_t *path;
+ const wchar_t *wname;
+ const char *name;
+ HANDLE h;
+ BY_HANDLE_FILE_INFORMATION bhfi;
+ DWORD fileAttributes = 0;
+ int r;
+
+ archive_clear_error(_a);
+ wname = archive_entry_sourcepath_w(entry);
+ if (wname == NULL)
+ wname = archive_entry_pathname_w(entry);
+ if (wname == NULL) {
+ archive_set_error(&a->archive, EINVAL,
+ "Can't get a wide character version of the path");
+ return (ARCHIVE_FAILED);
+ }
+ path = __la_win_permissive_name_w(wname);
+
+ if (st == NULL) {
+ /*
+ * Get metadata through GetFileInformationByHandle().
+ */
+ if (fd >= 0) {
+ h = (HANDLE)_get_osfhandle(fd);
+ r = GetFileInformationByHandle(h, &bhfi);
+ if (r == 0) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&a->archive, errno,
+ "Can't GetFileInformationByHandle");
+ return (ARCHIVE_FAILED);
+ }
+ entry_copy_bhfi(entry, path, NULL, &bhfi);
+ } else {
+ WIN32_FIND_DATAW findData;
+ DWORD flag, desiredAccess;
+
+ h = FindFirstFileW(path, &findData);
+ if (h == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&a->archive, errno,
+ "Can't FindFirstFileW");
+ return (ARCHIVE_FAILED);
+ }
+ FindClose(h);
+
+ flag = FILE_FLAG_BACKUP_SEMANTICS;
+ if (!a->follow_symlinks &&
+ (findData.dwFileAttributes
+ & FILE_ATTRIBUTE_REPARSE_POINT) &&
+ (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) {
+ flag |= FILE_FLAG_OPEN_REPARSE_POINT;
+ desiredAccess = 0;
+ } else if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ desiredAccess = 0;
+ } else
+ desiredAccess = GENERIC_READ;
+
+ h = CreateFileW(path, desiredAccess, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, flag, NULL);
+ if (h == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&a->archive, errno,
+ "Can't CreateFileW");
+ return (ARCHIVE_FAILED);
+ }
+ r = GetFileInformationByHandle(h, &bhfi);
+ if (r == 0) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&a->archive, errno,
+ "Can't GetFileInformationByHandle");
+ CloseHandle(h);
+ return (ARCHIVE_FAILED);
+ }
+ entry_copy_bhfi(entry, path, &findData, &bhfi);
+ }
+ fileAttributes = bhfi.dwFileAttributes;
+ } else {
+ archive_entry_copy_stat(entry, st);
+ h = INVALID_HANDLE_VALUE;
+ }
+
+ /* Lookup uname/gname */
+ name = archive_read_disk_uname(_a, archive_entry_uid(entry));
+ if (name != NULL)
+ archive_entry_copy_uname(entry, name);
+ name = archive_read_disk_gname(_a, archive_entry_gid(entry));
+ if (name != NULL)
+ archive_entry_copy_gname(entry, name);
+
+ /*
+ * Can this file be sparse file ?
+ */
+ if (archive_entry_filetype(entry) != AE_IFREG
+ || archive_entry_size(entry) <= 0
+ || archive_entry_hardlink(entry) != NULL) {
+ if (h != INVALID_HANDLE_VALUE && fd < 0)
+ CloseHandle(h);
+ return (ARCHIVE_OK);
+ }
+
+ if (h == INVALID_HANDLE_VALUE) {
+ if (fd >= 0) {
+ h = (HANDLE)_get_osfhandle(fd);
+ } else {
+ h = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ if (h == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&a->archive, errno,
+ "Can't CreateFileW");
+ return (ARCHIVE_FAILED);
+ }
+ }
+ r = GetFileInformationByHandle(h, &bhfi);
+ if (r == 0) {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&a->archive, errno,
+ "Can't GetFileInformationByHandle");
+ if (h != INVALID_HANDLE_VALUE && fd < 0)
+ CloseHandle(h);
+ return (ARCHIVE_FAILED);
+ }
+ fileAttributes = bhfi.dwFileAttributes;
+ }
+
+ /* Sparse file must be set a mark, FILE_ATTRIBUTE_SPARSE_FILE */
+ if ((fileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
+ if (fd < 0)
+ CloseHandle(h);
+ return (ARCHIVE_OK);
+ }
+
+ r = setup_sparse_from_disk(a, entry, h);
+ if (fd < 0)
+ CloseHandle(h);
+
+ return (r);
+}
+
+/*
+ * Windows sparse interface.
+ */
+#if defined(__MINGW32__) && !defined(FSCTL_QUERY_ALLOCATED_RANGES)
+#define FSCTL_QUERY_ALLOCATED_RANGES 0x940CF
+typedef struct {
+ LARGE_INTEGER FileOffset;
+ LARGE_INTEGER Length;
+} FILE_ALLOCATED_RANGE_BUFFER;
+#endif
+
+static int
+setup_sparse_from_disk(struct archive_read_disk *a,
+ struct archive_entry *entry, HANDLE handle)
+{
+ FILE_ALLOCATED_RANGE_BUFFER range, *outranges = NULL;
+ size_t outranges_size;
+ int64_t entry_size = archive_entry_size(entry);
+ int exit_sts = ARCHIVE_OK;
+
+ range.FileOffset.QuadPart = 0;
+ range.Length.QuadPart = entry_size;
+ outranges_size = 2048;
+ outranges = (FILE_ALLOCATED_RANGE_BUFFER *)malloc(outranges_size);
+ if (outranges == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't allocate memory");
+ exit_sts = ARCHIVE_FATAL;
+ goto exit_setup_sparse;
+ }
+
+ for (;;) {
+ DWORD retbytes;
+ BOOL ret;
+
+ for (;;) {
+ ret = DeviceIoControl(handle,
+ FSCTL_QUERY_ALLOCATED_RANGES,
+ &range, sizeof(range), outranges,
+ (DWORD)outranges_size, &retbytes, NULL);
+ if (ret == 0 && GetLastError() == ERROR_MORE_DATA) {
+ free(outranges);
+ outranges_size *= 2;
+ outranges = (FILE_ALLOCATED_RANGE_BUFFER *)
+ malloc(outranges_size);
+ if (outranges == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't allocate memory");
+ exit_sts = ARCHIVE_FATAL;
+ goto exit_setup_sparse;
+ }
+ continue;
+ } else
+ break;
+ }
+ if (ret != 0) {
+ if (retbytes > 0) {
+ DWORD i, n;
+
+ n = retbytes / sizeof(outranges[0]);
+ if (n == 1 &&
+ outranges[0].FileOffset.QuadPart == 0 &&
+ outranges[0].Length.QuadPart == entry_size)
+ break;/* This is not sparse. */
+ for (i = 0; i < n; i++)
+ archive_entry_sparse_add_entry(entry,
+ outranges[i].FileOffset.QuadPart,
+ outranges[i].Length.QuadPart);
+ range.FileOffset.QuadPart =
+ outranges[n-1].FileOffset.QuadPart
+ + outranges[n-1].Length.QuadPart;
+ range.Length.QuadPart =
+ entry_size - range.FileOffset.QuadPart;
+ if (range.Length.QuadPart > 0)
+ continue;
+ } else {
+ /* The remaining data is hole. */
+ archive_entry_sparse_add_entry(entry,
+ range.FileOffset.QuadPart,
+ range.Length.QuadPart);
+ }
+ break;
+ } else {
+ la_dosmaperr(GetLastError());
+ archive_set_error(&a->archive, errno,
+ "DeviceIoControl Failed: %lu", GetLastError());
+ exit_sts = ARCHIVE_FAILED;
+ goto exit_setup_sparse;
+ }
+ }
+exit_setup_sparse:
+ free(outranges);
+
+ return (exit_sts);
+}
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_extract.3 b/Utilities/cmlibarchive/libarchive/archive_read_extract.3
new file mode 100644
index 0000000000..6ec0ced939
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_extract.3
@@ -0,0 +1,137 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_EXTRACT 3
+.Os
+.Sh NAME
+.Nm archive_read_extract ,
+.Nm archive_read_extract2 ,
+.Nm archive_read_extract_set_progress_callback
+.Nd functions for reading streaming archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fo archive_read_extract
+.Fa "struct archive *"
+.Fa "struct archive_entry *"
+.Fa "int flags"
+.Fc
+.Ft int
+.Fo archive_read_extract2
+.Fa "struct archive *src"
+.Fa "struct archive_entry *"
+.Fa "struct archive *dest"
+.Fc
+.Ft void
+.Fo archive_read_extract_set_progress_callback
+.Fa "struct archive *"
+.Fa "void (*func)(void *)"
+.Fa "void *user_data"
+.Fc
+.Sh DESCRIPTION
+.Bl -tag -compact -width indent
+.It Fn archive_read_extract , Fn archive_read_extract_set_skip_file
+A convenience function that wraps the corresponding
+.Xr archive_write_disk 3
+interfaces.
+The first call to
+.Fn archive_read_extract
+creates a restore object using
+.Xr archive_write_disk_new 3
+and
+.Xr archive_write_disk_set_standard_lookup 3 ,
+then transparently invokes
+.Xr archive_write_disk_set_options 3 ,
+.Xr archive_write_header 3 ,
+.Xr archive_write_data 3 ,
+and
+.Xr archive_write_finish_entry 3
+to create the entry on disk and copy data into it.
+The
+.Va flags
+argument is passed unmodified to
+.Xr archive_write_disk_set_options 3 .
+.It Fn archive_read_extract2
+This is another version of
+.Fn archive_read_extract
+that allows you to provide your own restore object.
+In particular, this allows you to override the standard lookup functions
+using
+.Xr archive_write_disk_set_group_lookup 3 ,
+and
+.Xr archive_write_disk_set_user_lookup 3 .
+Note that
+.Fn archive_read_extract2
+does not accept a
+.Va flags
+argument; you should use
+.Fn archive_write_disk_set_options
+to set the restore options yourself.
+.It Fn archive_read_extract_set_progress_callback
+Sets a pointer to a user-defined callback that can be used
+for updating progress displays during extraction.
+The progress function will be invoked during the extraction of large
+regular files.
+The progress function will be invoked with the pointer provided to this call.
+Generally, the data pointed to should include a reference to the archive
+object and the archive_entry object so that various statistics
+can be retrieved for the progress display.
+.El
+.\"
+.Sh RETURN VALUES
+Most functions return zero on success, non-zero on error.
+The possible return codes include:
+.Cm ARCHIVE_OK
+(the operation succeeded),
+.Cm ARCHIVE_WARN
+(the operation succeeded but a non-critical error was encountered),
+.Cm ARCHIVE_EOF
+(end-of-archive was encountered),
+.Cm ARCHIVE_RETRY
+(the operation failed but can be retried),
+and
+.Cm ARCHIVE_FATAL
+(there was a fatal error; the archive should be closed immediately).
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_read 3 ,
+.Xr archive_read_data 3 ,
+.Xr archive_read_filter 3 ,
+.Xr archive_read_format 3 ,
+.Xr archive_read_open 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_util 3 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_extract.c b/Utilities/cmlibarchive/libarchive/archive_read_extract.c
new file mode 100644
index 0000000000..ce76a6cadf
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_extract.c
@@ -0,0 +1,77 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 17:00:22 kientzle Exp $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#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)
+{
+ struct archive_read_extract *extract;
+ struct archive_read * a = (struct archive_read *)_a;
+
+ extract = __archive_read_get_extract(a);
+ if (extract == NULL)
+ return (ARCHIVE_FATAL);
+
+ /* If we haven't initialized the archive_write_disk object, do it now. */
+ if (extract->ad == NULL) {
+ extract->ad = archive_write_disk_new();
+ if (extract->ad == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't extract");
+ 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
new file mode 100644
index 0000000000..3c65e8040f
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_extract2.c
@@ -0,0 +1,137 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 17:00:22 kientzle Exp $");
+
+#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_entry.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+static int copy_data(struct archive *ar, struct archive *aw);
+
+/* Retrieve an extract object without initialising the associated
+ * archive_write_disk object.
+ */
+struct archive_read_extract *
+__archive_read_get_extract(struct archive_read *a)
+{
+ if (a->extract == NULL) {
+ a->extract = (struct archive_read_extract *)malloc(sizeof(*a->extract));
+ if (a->extract == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't extract");
+ return (NULL);
+ }
+ memset(a->extract, 0, sizeof(*a->extract));
+ }
+ return (a->extract);
+}
+
+int
+archive_read_extract2(struct archive *_a, struct archive_entry *entry,
+ struct archive *ad)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ int r, r2;
+
+ /* Set up for this particular entry. */
+ if (a->skip_file_set)
+ archive_write_disk_set_skip_file(ad,
+ a->skip_file_dev, a->skip_file_ino);
+ r = archive_write_header(ad, entry);
+ if (r < ARCHIVE_WARN)
+ r = ARCHIVE_WARN;
+ if (r != ARCHIVE_OK)
+ /* If _write_header failed, copy the error. */
+ archive_copy_error(&a->archive, ad);
+ else if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) > 0)
+ /* Otherwise, pour data into the entry. */
+ r = copy_data(_a, ad);
+ r2 = archive_write_finish_entry(ad);
+ if (r2 < ARCHIVE_WARN)
+ r2 = ARCHIVE_WARN;
+ /* Use the first message. */
+ if (r2 != ARCHIVE_OK && r == ARCHIVE_OK)
+ archive_copy_error(&a->archive, ad);
+ /* Use the worst error return. */
+ if (r2 < r)
+ r = r2;
+ return (r);
+}
+
+void
+archive_read_extract_set_progress_callback(struct archive *_a,
+ void (*progress_func)(void *), void *user_data)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_extract *extract = __archive_read_get_extract(a);
+ if (extract != NULL) {
+ extract->extract_progress = progress_func;
+ extract->extract_progress_user_data = user_data;
+ }
+}
+
+static int
+copy_data(struct archive *ar, struct archive *aw)
+{
+ int64_t offset;
+ const void *buff;
+ struct archive_read_extract *extract;
+ size_t size;
+ int r;
+
+ extract = __archive_read_get_extract((struct archive_read *)ar);
+ if (extract == NULL)
+ return (ARCHIVE_FATAL);
+ for (;;) {
+ r = archive_read_data_block(ar, &buff, &size, &offset);
+ if (r == ARCHIVE_EOF)
+ return (ARCHIVE_OK);
+ if (r != ARCHIVE_OK)
+ return (r);
+ r = (int)archive_write_data_block(aw, buff, size, offset);
+ if (r < ARCHIVE_WARN)
+ r = ARCHIVE_WARN;
+ if (r != ARCHIVE_OK) {
+ archive_set_error(ar, archive_errno(aw),
+ "%s", archive_error_string(aw));
+ return (r);
+ }
+ if (extract->extract_progress)
+ (extract->extract_progress)
+ (extract->extract_progress_user_data);
+ }
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_filter.3 b/Utilities/cmlibarchive/libarchive/archive_read_filter.3
new file mode 100644
index 0000000000..8761127d96
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_filter.3
@@ -0,0 +1,129 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_FILTER 3
+.Os
+.Sh NAME
+.Nm archive_read_support_filter_all ,
+.Nm archive_read_support_filter_bzip2 ,
+.Nm archive_read_support_filter_compress ,
+.Nm archive_read_support_filter_gzip ,
+.Nm archive_read_support_filter_lzma ,
+.Nm archive_read_support_filter_none ,
+.Nm archive_read_support_filter_xz ,
+.Nm archive_read_support_filter_program ,
+.Nm archive_read_support_filter_program_signature
+.Nd functions for reading streaming archives
+.\"
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fn archive_read_support_filter_all "struct archive *"
+.Ft int
+.Fn archive_read_support_filter_bzip2 "struct archive *"
+.Ft int
+.Fn archive_read_support_filter_compress "struct archive *"
+.Ft int
+.Fn archive_read_support_filter_gzip "struct archive *"
+.Ft int
+.Fn archive_read_support_filter_lzma "struct archive *"
+.Ft int
+.Fn archive_read_support_filter_none "struct archive *"
+.Ft int
+.Fn archive_read_support_filter_xz "struct archive *"
+.Ft int
+.Fo archive_read_support_filter_program
+.Fa "struct archive *"
+.Fa "const char *cmd"
+.Fc
+.Ft int
+.Fo archive_read_support_filter_program_signature
+.Fa "struct archive *"
+.Fa "const char *cmd"
+.Fa "const void *signature"
+.Fa "size_t signature_length"
+.Fc
+.\"
+.Sh DESCRIPTION
+.Bl -tag -compact -width indent
+.It Xo
+.Fn archive_read_support_filter_bzip2 ,
+.Fn archive_read_support_filter_compress ,
+.Fn archive_read_support_filter_gzip ,
+.Fn archive_read_support_filter_lzma ,
+.Fn archive_read_support_filter_none ,
+.Fn archive_read_support_filter_xz
+.Xc
+Enables auto-detection code and decompression support for the
+specified compression.
+These functions may fall back on external programs if an appropriate
+library was not available at build time.
+Decompression using an external program is usually slower than
+decompression through built-in libraries.
+Note that
+.Dq none
+is always enabled by default.
+.It Fn archive_read_support_filter_all
+Enables all available decompression filters.
+.It Fn archive_read_support_filter_program
+Data is fed through the specified external program before being dearchived.
+Note that this disables automatic detection of the compression format,
+so it makes no sense to specify this in conjunction with any other
+decompression option.
+.It Fn archive_read_support_filter_program_signature
+This feeds data through the specified external program
+but only if the initial bytes of the data match the specified
+signature value.
+.El
+.\"
+.\". Sh EXAMPLE
+.\"
+.Sh RETURN VALUES
+These functions return
+.Cm ARCHIVE_OK
+if the compression is fully supported,
+.Cm ARCHIVE_WARN
+if the compression is supported only through an external program.
+.Pp
+.Fn archive_read_support_filter_none
+always succeeds.
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr libarchive 3 ,
+.Xr archive_read 3 ,
+.Xr archive_read_data 3 ,
+.Xr archive_read_format 3 ,
+.Xr archive_read_format 3
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_format.3 b/Utilities/cmlibarchive/libarchive/archive_read_format.3
new file mode 100644
index 0000000000..53b9a7e0e6
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_format.3
@@ -0,0 +1,177 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_FORMAT 3
+.Os
+.Sh NAME
+.Nm archive_read_support_format_7zip ,
+.Nm archive_read_support_format_all ,
+.Nm archive_read_support_format_ar ,
+.Nm archive_read_support_format_by_code ,
+.Nm archive_read_support_format_cab ,
+.Nm archive_read_support_format_cpio ,
+.Nm archive_read_support_format_empty ,
+.Nm archive_read_support_format_iso9660 ,
+.Nm archive_read_support_format_lha ,
+.Nm archive_read_support_format_mtree,
+.Nm archive_read_support_format_rar,
+.Nm archive_read_support_format_raw,
+.Nm archive_read_support_format_tar ,
+.Nm archive_read_support_format_xar ,
+.Nm archive_read_support_format_zip
+.Nd functions for reading streaming archives
+.\"
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fn archive_read_support_format_7zip "struct archive *"
+.Ft int
+.Fn archive_read_support_format_all "struct archive *"
+.Ft int
+.Fn archive_read_support_format_ar "struct archive *"
+.Ft int
+.Fn archive_read_support_format_by_code "struct archive *" "int"
+.Ft int
+.Fn archive_read_support_format_cab "struct archive *"
+.Ft int
+.Fn archive_read_support_format_cpio "struct archive *"
+.Ft int
+.Fn archive_read_support_format_empty "struct archive *"
+.Ft int
+.Fn archive_read_support_format_iso9660 "struct archive *"
+.Ft int
+.Fn archive_read_support_format_lha "struct archive *"
+.Ft int
+.Fn archive_read_support_format_mtree "struct archive *"
+.Ft int
+.Fn archive_read_support_format_rar "struct archive *"
+.Ft int
+.Fn archive_read_support_format_raw "struct archive *"
+.Ft int
+.Fn archive_read_support_format_tar "struct archive *"
+.Ft int
+.Fn archive_read_support_format_xar "struct archive *"
+.Ft int
+.Fn archive_read_support_format_zip "struct archive *"
+.\"
+.Sh DESCRIPTION
+.Bl -tag -compact -width indent
+.It Xo
+.Fn archive_read_support_format_7zip ,
+.Fn archive_read_support_format_ar ,
+.Fn archive_read_support_format_cab ,
+.Fn archive_read_support_format_cpio ,
+.Fn archive_read_support_format_iso9660 ,
+.Fn archive_read_support_format_lha ,
+.Fn archive_read_support_format_mtree ,
+.Fn archive_read_support_format_rar ,
+.Fn archive_read_support_format_raw ,
+.Fn archive_read_support_format_tar ,
+.Fn archive_read_support_format_xar ,
+.Fn archive_read_support_format_zip
+.Xc
+Enables support---including auto-detection code---for the
+specified archive format.
+For example,
+.Fn archive_read_support_format_tar
+enables support for a variety of standard tar formats, old-style tar,
+ustar, pax interchange format, and many common variants.
+.It Fn archive_read_support_format_all
+Enables support for all available formats except the
+.Dq raw
+format (see below).
+.It Fn archive_read_support_format_by_code
+Enables a single format specified by the format code.
+This can be useful when reading a single archive twice;
+use
+.Fn archive_format
+after reading the first time and pass the resulting code
+to this function to selectively enable only the necessary
+format support.
+Note: In statically-linked executables, this will cause
+your program to include support for every format.
+If executable size is a concern, you may wish to avoid
+using this function.
+.It Fn archive_read_support_format_empty
+Enables support for treating empty files as empty archives.
+Because empty files are valid for several different formats,
+it is not possible to accurately determine a format for
+an empty file based purely on contents.
+So empty files are treated by libarchive as a distinct
+format.
+.It Fn archive_read_support_format_raw
+The
+.Dq raw
+format handler allows libarchive to be used to read arbitrary data.
+It treats any data stream as an archive with a single entry.
+The pathname of this entry is
+.Dq data ;
+all other entry fields are unset.
+This is not enabled by
+.Fn archive_read_support_format_all
+in order to avoid erroneous handling of damaged archives.
+.El
+.\" .Sh EXAMPLE
+.Sh RETURN VALUES
+These functions return
+.Cm ARCHIVE_OK
+on success, or
+.Cm ARCHIVE_FATAL .
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_read_data 3 ,
+.Xr archive_read_filter 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_util 3 ,
+.Xr tar 5
+.Sh BUGS
+Many traditional archiver programs treat
+empty files as valid empty archives.
+For example, many implementations of
+.Xr tar 1
+allow you to append entries to an empty file.
+Of course, it is impossible to determine the format of an empty file
+by inspecting the contents, so this library treats empty files as
+having a special
+.Dq empty
+format.
+.Pp
+Using the
+.Dq raw
+handler together with any other handler will often work
+but can produce surprising results.
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_free.3 b/Utilities/cmlibarchive/libarchive/archive_read_free.3
new file mode 100644
index 0000000000..5b218225ba
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_free.3
@@ -0,0 +1,93 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_FREE 3
+.Os
+.Sh NAME
+.Nm archive_read_close ,
+.Nm archive_read_finish ,
+.Nm archive_read_free
+.Nd functions for reading streaming archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fn archive_read_close "struct archive *"
+.Ft int
+.Fn archive_read_finish "struct archive *"
+.Ft int
+.Fn archive_read_free "struct archive *"
+.\"
+.Sh DESCRIPTION
+.Bl -tag -compact -width indent
+.It Fn archive_read_close
+Complete the archive and invoke the close callback.
+.It Fn archive_read_finish
+This is a deprecated synonym for
+.Fn archive_read_free .
+The new name was introduced with libarchive 3.0.
+Applications that need to compile with either libarchive 2
+or libarchive 3 should continue to use the
+.Fn archive_read_finish
+name.
+Both names will be supported until libarchive 4.0 is
+released, which is not expected to occur earlier
+than 2013.
+.It Fn archive_read_free
+Invokes
+.Fn archive_read_close
+if it was not invoked manually, then release all resources.
+Note: In libarchive 1.x, this function was declared to return
+.Ft void ,
+which made it impossible to detect certain errors when
+.Fn archive_read_close
+was invoked implicitly from this function.
+The declaration is corrected beginning with libarchive 2.0.
+.El
+.Sh RETURN VALUES
+These functions return
+.Cm ARCHIVE_OK
+on success, or
+.Cm ARCHIVE_FATAL .
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr libarchive 3 ,
+.Xr archive_read_new 3 ,
+.Xr archive_read_data 3 ,
+.Xr archive_read_filter 3 ,
+.Xr archive_read_format 3 ,
+.Xr archive_read_open 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_util 3
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_header.3 b/Utilities/cmlibarchive/libarchive/archive_read_header.3
new file mode 100644
index 0000000000..480a666ca3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_header.3
@@ -0,0 +1,91 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_HEADER 3
+.Os
+.Sh NAME
+.Nm archive_read_next_header ,
+.Nm archive_read_next_header2
+.Nd functions for reading streaming archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fn archive_read_next_header "struct archive *" "struct archive_entry **"
+.Ft int
+.Fn archive_read_next_header2 "struct archive *" "struct archive_entry *"
+.\"
+.Sh DESCRIPTION
+.Bl -tag -compact -width indent
+.It Fn archive_read_next_header
+Read the header for the next entry and return a pointer to
+a
+.Tn struct archive_entry .
+This is a convenience wrapper around
+.Fn archive_read_next_header2
+that reuses an internal
+.Tn struct archive_entry
+object for each request.
+.It Fn archive_read_next_header2
+Read the header for the next entry and populate the provided
+.Tn struct archive_entry .
+.El
+.\"
+.Sh RETURN VALUES
+These functions return
+.Cm ARCHIVE_OK
+(the operation succeeded),
+.Cm ARCHIVE_WARN
+(the operation succeeded but a non-critical error was encountered),
+.Cm ARCHIVE_EOF
+(end-of-archive was encountered),
+.Cm ARCHIVE_RETRY
+(the operation failed but can be retried),
+and
+.Cm ARCHIVE_FATAL
+(there was a fatal error; the archive should be closed immediately).
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_read 3 ,
+.Xr archive_read_data 3 ,
+.Xr archive_read_extract 3 ,
+.Xr archive_read_filter 3 ,
+.Xr archive_read_format 3 ,
+.Xr archive_read_open 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_util 3 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_new.3 b/Utilities/cmlibarchive/libarchive/archive_read_new.3
new file mode 100644
index 0000000000..0c9d1a7fbb
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_new.3
@@ -0,0 +1,59 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_NEW 3
+.Os
+.Sh NAME
+.Nm archive_read_new
+.Nd functions for reading streaming archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft struct archive *
+.Fn archive_read_new "void"
+.Sh DESCRIPTION
+Allocates and initializes a
+.Tn struct archive
+object suitable for reading from an archive.
+.Dv NULL
+is returned on error.
+.Pp
+A complete description of the
+.Tn struct archive
+object can be found in the overview manual page for
+.Xr libarchive 3 .
+.\" .Sh ERRORS
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_read_data 3 ,
+.Xr archive_read_filter 3 ,
+.Xr archive_read_format 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_util 3 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open.3 b/Utilities/cmlibarchive/libarchive/archive_read_open.3
new file mode 100644
index 0000000000..30a740bef1
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_open.3
@@ -0,0 +1,233 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_OPEN 3
+.Os
+.Sh NAME
+.Nm archive_read_open ,
+.Nm archive_read_open2 ,
+.Nm archive_read_open_fd ,
+.Nm archive_read_open_FILE ,
+.Nm archive_read_open_filename ,
+.Nm archive_read_open_memory ,
+.Nd functions for reading streaming archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fo archive_read_open
+.Fa "struct archive *"
+.Fa "void *client_data"
+.Fa "archive_open_callback *"
+.Fa "archive_read_callback *"
+.Fa "archive_close_callback *"
+.Fc
+.Ft int
+.Fo archive_read_open2
+.Fa "struct archive *"
+.Fa "void *client_data"
+.Fa "archive_open_callback *"
+.Fa "archive_read_callback *"
+.Fa "archive_skip_callback *"
+.Fa "archive_close_callback *"
+.Fc
+.Ft int
+.Fn archive_read_open_FILE "struct archive *" "FILE *file"
+.Ft int
+.Fn archive_read_open_fd "struct archive *" "int fd" "size_t block_size"
+.Ft int
+.Fo archive_read_open_filename
+.Fa "struct archive *"
+.Fa "const char *filename"
+.Fa "size_t block_size"
+.Fc
+.Ft int
+.Fn archive_read_open_memory "struct archive *" "void *buff" "size_t size"
+.Sh DESCRIPTION
+.Bl -tag -compact -width indent
+.It Fn archive_read_open
+The same as
+.Fn archive_read_open2 ,
+except that the skip callback is assumed to be
+.Dv NULL .
+.It Fn archive_read_open2
+Freeze the settings, open the archive, and prepare for reading entries.
+This is the most generic version of this call, which accepts
+four callback functions.
+Most clients will want to use
+.Fn archive_read_open_filename ,
+.Fn archive_read_open_FILE ,
+.Fn archive_read_open_fd ,
+or
+.Fn archive_read_open_memory
+instead.
+The library invokes the client-provided functions to obtain
+raw bytes from the archive.
+.It Fn archive_read_open_FILE
+Like
+.Fn archive_read_open ,
+except that it accepts a
+.Ft "FILE *"
+pointer.
+This function should not be used with tape drives or other devices
+that require strict I/O blocking.
+.It Fn archive_read_open_fd
+Like
+.Fn archive_read_open ,
+except that it accepts a file descriptor and block size rather than
+a set of function pointers.
+Note that the file descriptor will not be automatically closed at
+end-of-archive.
+This function is safe for use with tape drives or other blocked devices.
+.It Fn archive_read_open_file
+This is a deprecated synonym for
+.Fn archive_read_open_filename .
+.It Fn archive_read_open_filename
+Like
+.Fn archive_read_open ,
+except that it accepts a simple filename and a block size.
+A NULL filename represents standard input.
+This function is safe for use with tape drives or other blocked devices.
+.It Fn archive_read_open_memory
+Like
+.Fn archive_read_open ,
+except that it accepts a pointer and size of a block of
+memory containing the archive data.
+.El
+.Pp
+A complete description of the
+.Tn struct archive
+and
+.Tn struct archive_entry
+objects can be found in the overview manual page for
+.Xr libarchive 3 .
+.Sh CLIENT CALLBACKS
+The callback functions must match the following prototypes:
+.Bl -item -offset indent
+.It
+.Ft typedef ssize_t
+.Fo archive_read_callback
+.Fa "struct archive *"
+.Fa "void *client_data"
+.Fa "const void **buffer"
+.Fc
+.It
+.Ft typedef off_t
+.Fo archive_skip_callback
+.Fa "struct archive *"
+.Fa "void *client_data"
+.Fa "off_t request"
+.Fc
+.It
+.Ft typedef int
+.Fn archive_open_callback "struct archive *" "void *client_data"
+.It
+.Ft typedef int
+.Fn archive_close_callback "struct archive *" "void *client_data"
+.El
+.Pp
+The open callback is invoked by
+.Fn archive_open .
+It should return
+.Cm ARCHIVE_OK
+if the underlying file or data source is successfully
+opened.
+If the open fails, it should call
+.Fn archive_set_error
+to register an error code and message and return
+.Cm ARCHIVE_FATAL .
+.Pp
+The read callback is invoked whenever the library
+requires raw bytes from the archive.
+The read callback should read data into a buffer,
+set the
+.Li const void **buffer
+argument to point to the available data, and
+return a count of the number of bytes available.
+The library will invoke the read callback again
+only after it has consumed this data.
+The library imposes no constraints on the size
+of the data blocks returned.
+On end-of-file, the read callback should
+return zero.
+On error, the read callback should invoke
+.Fn archive_set_error
+to register an error code and message and
+return -1.
+.Pp
+The skip callback is invoked when the
+library wants to ignore a block of data.
+The return value is the number of bytes actually
+skipped, which may differ from the request.
+If the callback cannot skip data, it should return
+zero.
+If the skip callback is not provided (the
+function pointer is
+.Dv NULL ),
+the library will invoke the read function
+instead and simply discard the result.
+A skip callback can provide significant
+performance gains when reading uncompressed
+archives from slow disk drives or other media
+that can skip quickly.
+.Pp
+The close callback is invoked by archive_close when
+the archive processing is complete.
+The callback should return
+.Cm ARCHIVE_OK
+on success.
+On failure, the callback should invoke
+.Fn archive_set_error
+to register an error code and message and
+return
+.Cm ARCHIVE_FATAL.
+.\" .Sh EXAMPLE
+.\"
+.Sh RETURN VALUES
+These functions return
+.Cm ARCHIVE_OK
+on success, or
+.Cm ARCHIVE_FATAL .
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_read 3 ,
+.Xr archive_read_data 3 ,
+.Xr archive_read_filter 3 ,
+.Xr archive_read_format 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_util 3 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c b/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c
new file mode 100644
index 0000000000..e0f95bf41b
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c
@@ -0,0 +1,182 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_read_open_fd.c 201103 2009-12-28 03:13:49Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+
+struct read_fd_data {
+ int fd;
+ size_t block_size;
+ char use_lseek;
+ void *buffer;
+};
+
+static int file_close(struct archive *, void *);
+static ssize_t file_read(struct archive *, void *, const void **buff);
+static int64_t file_skip(struct archive *, void *, int64_t request);
+
+int
+archive_read_open_fd(struct archive *a, int fd, size_t block_size)
+{
+ struct stat st;
+ struct read_fd_data *mine;
+ void *b;
+
+ archive_clear_error(a);
+ if (fstat(fd, &st) != 0) {
+ archive_set_error(a, errno, "Can't stat fd %d", fd);
+ return (ARCHIVE_FATAL);
+ }
+
+ mine = (struct read_fd_data *)calloc(1, sizeof(*mine));
+ b = malloc(block_size);
+ if (mine == NULL || b == NULL) {
+ archive_set_error(a, ENOMEM, "No memory");
+ free(mine);
+ free(b);
+ return (ARCHIVE_FATAL);
+ }
+ mine->block_size = block_size;
+ mine->buffer = b;
+ mine->fd = fd;
+ /*
+ * Skip support is a performance optimization for anything
+ * that supports lseek(). On FreeBSD, only regular files and
+ * raw disk devices support lseek() and there's no portable
+ * way to determine if a device is a raw disk device, so we
+ * only enable this optimization for regular files.
+ */
+ if (S_ISREG(st.st_mode)) {
+ archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino);
+ mine->use_lseek = 1;
+ }
+#if defined(__CYGWIN__) || defined(_WIN32)
+ setmode(mine->fd, O_BINARY);
+#endif
+
+ archive_read_set_read_callback(a, file_read);
+ archive_read_set_skip_callback(a, file_skip);
+ archive_read_set_close_callback(a, file_close);
+ archive_read_set_callback_data(a, mine);
+ return (archive_read_open1(a));
+}
+
+static ssize_t
+file_read(struct archive *a, void *client_data, const void **buff)
+{
+ struct read_fd_data *mine = (struct read_fd_data *)client_data;
+ ssize_t bytes_read;
+
+ *buff = mine->buffer;
+ for (;;) {
+ bytes_read = read(mine->fd, mine->buffer, mine->block_size);
+ if (bytes_read < 0) {
+ if (errno == EINTR)
+ continue;
+ archive_set_error(a, errno, "Error reading fd %d",
+ mine->fd);
+ }
+ return (bytes_read);
+ }
+}
+
+static int64_t
+file_skip(struct archive *a, void *client_data, int64_t request)
+{
+ struct read_fd_data *mine = (struct read_fd_data *)client_data;
+ int64_t skip = request;
+ int64_t old_offset, new_offset;
+ int skip_bits = sizeof(skip) * 8 - 1; /* off_t is a signed type. */
+
+ if (!mine->use_lseek)
+ return (0);
+
+ /* Reduce a request that would overflow the 'skip' variable. */
+ if (sizeof(request) > sizeof(skip)) {
+ int64_t max_skip =
+ (((int64_t)1 << (skip_bits - 1)) - 1) * 2 + 1;
+ if (request > max_skip)
+ skip = max_skip;
+ }
+
+ /* Reduce request to the next smallest multiple of block_size */
+ request = (request / mine->block_size) * mine->block_size;
+ if (request == 0)
+ return (0);
+
+ if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) >= 0) &&
+ ((new_offset = lseek(mine->fd, skip, SEEK_CUR)) >= 0))
+ return (new_offset - old_offset);
+
+ /* If seek failed once, it will probably fail again. */
+ mine->use_lseek = 0;
+
+ /* Let libarchive recover with read+discard. */
+ if (errno == ESPIPE)
+ return (0);
+
+ /*
+ * There's been an error other than ESPIPE. This is most
+ * likely caused by a programmer error (too large request)
+ * or a corrupted archive file.
+ */
+ archive_set_error(a, errno, "Error seeking");
+ return (-1);
+}
+
+static int
+file_close(struct archive *a, void *client_data)
+{
+ struct read_fd_data *mine = (struct read_fd_data *)client_data;
+
+ (void)a; /* UNUSED */
+ free(mine->buffer);
+ free(mine);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_file.c b/Utilities/cmlibarchive/libarchive/archive_read_open_file.c
new file mode 100644
index 0000000000..3a33c258ee
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_open_file.c
@@ -0,0 +1,177 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_read_open_file.c 201093 2009-12-28 02:28:44Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+
+struct read_FILE_data {
+ FILE *f;
+ size_t block_size;
+ void *buffer;
+ char can_skip;
+};
+
+static int file_close(struct archive *, void *);
+static ssize_t file_read(struct archive *, void *, const void **buff);
+static int64_t file_skip(struct archive *, void *, int64_t request);
+
+int
+archive_read_open_FILE(struct archive *a, FILE *f)
+{
+ struct stat st;
+ struct read_FILE_data *mine;
+ size_t block_size = 128 * 1024;
+ void *b;
+
+ archive_clear_error(a);
+ mine = (struct read_FILE_data *)malloc(sizeof(*mine));
+ b = malloc(block_size);
+ if (mine == NULL || b == NULL) {
+ archive_set_error(a, ENOMEM, "No memory");
+ free(mine);
+ free(b);
+ return (ARCHIVE_FATAL);
+ }
+ mine->block_size = block_size;
+ mine->buffer = b;
+ mine->f = f;
+ /*
+ * If we can't fstat() the file, it may just be that it's not
+ * a file. (FILE * objects can wrap many kinds of I/O
+ * streams, some of which don't support fileno()).)
+ */
+ if (fstat(fileno(mine->f), &st) == 0 && S_ISREG(st.st_mode)) {
+ archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino);
+ /* Enable the seek optimization only for regular files. */
+ mine->can_skip = 1;
+ } else
+ mine->can_skip = 0;
+
+#if defined(__CYGWIN__) || defined(_WIN32)
+ setmode(fileno(mine->f), O_BINARY);
+#endif
+
+ archive_read_set_read_callback(a, file_read);
+ archive_read_set_skip_callback(a, file_skip);
+ archive_read_set_close_callback(a, file_close);
+ archive_read_set_callback_data(a, mine);
+ return (archive_read_open1(a));
+}
+
+static ssize_t
+file_read(struct archive *a, void *client_data, const void **buff)
+{
+ struct read_FILE_data *mine = (struct read_FILE_data *)client_data;
+ size_t bytes_read;
+
+ *buff = mine->buffer;
+ bytes_read = fread(mine->buffer, 1, mine->block_size, mine->f);
+ if (bytes_read < mine->block_size && ferror(mine->f)) {
+ archive_set_error(a, errno, "Error reading file");
+ }
+ return (bytes_read);
+}
+
+static int64_t
+file_skip(struct archive *a, void *client_data, int64_t request)
+{
+ struct read_FILE_data *mine = (struct read_FILE_data *)client_data;
+#if HAVE_FSEEKO
+ off_t skip = (off_t)request;
+#elif HAVE__FSEEKI64
+ int64_t skip = request;
+#else
+ long skip = (long)request;
+#endif
+ int skip_bits = sizeof(skip) * 8 - 1;
+
+ (void)a; /* UNUSED */
+
+ /*
+ * If we can't skip, return 0 as the amount we did step and
+ * the caller will work around by reading and discarding.
+ */
+ if (!mine->can_skip)
+ return (0);
+ if (request == 0)
+ return (0);
+
+ /* If request is too big for a long or an off_t, reduce it. */
+ if (sizeof(request) > sizeof(skip)) {
+ int64_t max_skip =
+ (((int64_t)1 << (skip_bits - 1)) - 1) * 2 + 1;
+ if (request > max_skip)
+ skip = max_skip;
+ }
+
+#if HAVE_FSEEKO
+ if (fseeko(mine->f, skip, SEEK_CUR) != 0)
+#elif HAVE__FSEEKI64
+ if (_fseeki64(mine->f, skip, SEEK_CUR) != 0)
+#else
+ if (fseek(mine->f, skip, SEEK_CUR) != 0)
+#endif
+ {
+ mine->can_skip = 0;
+ return (0);
+ }
+ return (request);
+}
+
+static int
+file_close(struct archive *a, void *client_data)
+{
+ struct read_FILE_data *mine = (struct read_FILE_data *)client_data;
+
+ (void)a; /* UNUSED */
+ if (mine->buffer != NULL)
+ free(mine->buffer);
+ free(mine);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c b/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c
new file mode 100644
index 0000000000..622c960c46
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c
@@ -0,0 +1,576 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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_read_open_filename.c 201093 2009-12-28 02:28:44Z kientzle $");
+
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#include <sys/disk.h>
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/disklabel.h>
+#include <sys/dkio.h>
+#elif defined(__DragonFly__)
+#include <sys/diskslice.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_string.h"
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
+struct read_file_data {
+ int fd;
+ size_t block_size;
+ void *buffer;
+ mode_t st_mode; /* Mode bits for opened file. */
+ char use_lseek;
+ enum fnt_e { FNT_STDIN, FNT_MBS, FNT_WCS } filename_type;
+ union {
+ char m[1];/* MBS filename. */
+ wchar_t w[1];/* WCS filename. */
+ } filename; /* Must be last! */
+};
+
+static int file_open(struct archive *, void *);
+static int file_close(struct archive *, void *);
+static int file_close2(struct archive *, void *);
+static int file_switch(struct archive *, void *, 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);
+static int64_t file_skip_lseek(struct archive *, void *, int64_t request);
+
+int
+archive_read_open_file(struct archive *a, const char *filename,
+ size_t block_size)
+{
+ return (archive_read_open_filename(a, filename, block_size));
+}
+
+int
+archive_read_open_filename(struct archive *a, const char *filename,
+ size_t block_size)
+{
+ const char *filenames[2];
+ filenames[0] = filename;
+ filenames[1] = NULL;
+ return archive_read_open_filenames(a, filenames, block_size);
+}
+
+int
+archive_read_open_filenames(struct archive *a, const char **filenames,
+ size_t block_size)
+{
+ struct read_file_data *mine;
+ const char *filename = NULL;
+ if (filenames)
+ filename = *(filenames++);
+
+ archive_clear_error(a);
+ do
+ {
+ if (filename == NULL)
+ filename = "";
+ mine = (struct read_file_data *)calloc(1,
+ sizeof(*mine) + strlen(filename));
+ if (mine == NULL)
+ goto no_memory;
+ strcpy(mine->filename.m, filename);
+ mine->block_size = block_size;
+ mine->fd = -1;
+ mine->buffer = NULL;
+ mine->st_mode = mine->use_lseek = 0;
+ if (filename == NULL || filename[0] == '\0') {
+ mine->filename_type = FNT_STDIN;
+ } else
+ mine->filename_type = FNT_MBS;
+ if (archive_read_append_callback_data(a, mine) != (ARCHIVE_OK))
+ return (ARCHIVE_FATAL);
+ if (filenames == NULL)
+ break;
+ filename = *(filenames++);
+ } while (filename != NULL && filename[0] != '\0');
+ archive_read_set_open_callback(a, file_open);
+ archive_read_set_read_callback(a, file_read);
+ archive_read_set_skip_callback(a, file_skip);
+ archive_read_set_close_callback(a, file_close);
+ archive_read_set_switch_callback(a, file_switch);
+ archive_read_set_seek_callback(a, file_seek);
+
+ return (archive_read_open1(a));
+no_memory:
+ archive_set_error(a, ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+}
+
+int
+archive_read_open_filename_w(struct archive *a, const wchar_t *wfilename,
+ size_t block_size)
+{
+ struct read_file_data *mine = (struct read_file_data *)calloc(1,
+ sizeof(*mine) + wcslen(wfilename) * sizeof(wchar_t));
+ if (!mine)
+ {
+ archive_set_error(a, ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ mine->fd = -1;
+ mine->block_size = block_size;
+
+ if (wfilename == NULL || wfilename[0] == L'\0') {
+ mine->filename_type = FNT_STDIN;
+ } else {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ mine->filename_type = FNT_WCS;
+ wcscpy(mine->filename.w, wfilename);
+#else
+ /*
+ * POSIX system does not support a wchar_t interface for
+ * open() system call, so we have to translate a whcar_t
+ * filename to multi-byte one and use it.
+ */
+ struct archive_string fn;
+
+ archive_string_init(&fn);
+ if (archive_string_append_from_wcs(&fn, wfilename,
+ wcslen(wfilename)) != 0) {
+ if (errno == ENOMEM)
+ archive_set_error(a, errno,
+ "Can't allocate memory");
+ else
+ archive_set_error(a, EINVAL,
+ "Failed to convert a wide-character"
+ " filename to a multi-byte filename");
+ archive_string_free(&fn);
+ free(mine);
+ return (ARCHIVE_FATAL);
+ }
+ mine->filename_type = FNT_MBS;
+ strcpy(mine->filename.m, fn.s);
+ archive_string_free(&fn);
+#endif
+ }
+ if (archive_read_append_callback_data(a, mine) != (ARCHIVE_OK))
+ return (ARCHIVE_FATAL);
+ archive_read_set_open_callback(a, file_open);
+ archive_read_set_read_callback(a, file_read);
+ archive_read_set_skip_callback(a, file_skip);
+ archive_read_set_close_callback(a, file_close);
+ archive_read_set_switch_callback(a, file_switch);
+ archive_read_set_seek_callback(a, file_seek);
+
+ return (archive_read_open1(a));
+}
+
+static int
+file_open(struct archive *a, void *client_data)
+{
+ struct stat st;
+ struct read_file_data *mine = (struct read_file_data *)client_data;
+ void *buffer;
+ const char *filename = NULL;
+ const wchar_t *wfilename = NULL;
+ int fd;
+ int is_disk_like = 0;
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ off_t mediasize = 0; /* FreeBSD-specific, so off_t okay here. */
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+ struct disklabel dl;
+#elif defined(__DragonFly__)
+ struct partinfo pi;
+#endif
+
+ archive_clear_error(a);
+ if (mine->filename_type == FNT_STDIN) {
+ /* We used to delegate stdin support by
+ * directly calling archive_read_open_fd(a,0,block_size)
+ * here, but that doesn't (and shouldn't) handle the
+ * end-of-file flush when reading stdout from a pipe.
+ * Basically, read_open_fd() is intended for folks who
+ * are willing to handle such details themselves. This
+ * API is intended to be a little smarter for folks who
+ * want easy handling of the common case.
+ */
+ fd = 0;
+#if defined(__CYGWIN__) || defined(_WIN32)
+ setmode(0, O_BINARY);
+#endif
+ filename = "";
+ } else if (mine->filename_type == FNT_MBS) {
+ filename = mine->filename.m;
+ fd = open(filename, O_RDONLY | O_BINARY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(fd);
+ if (fd < 0) {
+ archive_set_error(a, errno,
+ "Failed to open '%s'", filename);
+ return (ARCHIVE_FATAL);
+ }
+ } else {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ wfilename = mine->filename.w;
+ fd = _wopen(wfilename, O_RDONLY | O_BINARY);
+ if (fd < 0 && errno == ENOENT) {
+ wchar_t *fullpath;
+ fullpath = __la_win_permissive_name_w(wfilename);
+ if (fullpath != NULL) {
+ fd = _wopen(fullpath, O_RDONLY | O_BINARY);
+ free(fullpath);
+ }
+ }
+ if (fd < 0) {
+ archive_set_error(a, errno,
+ "Failed to open '%S'", wfilename);
+ return (ARCHIVE_FATAL);
+ }
+#else
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Unexpedted operation in archive_read_open_filename");
+ return (ARCHIVE_FATAL);
+#endif
+ }
+ if (fstat(fd, &st) != 0) {
+ if (mine->filename_type == FNT_WCS)
+ archive_set_error(a, errno, "Can't stat '%S'",
+ wfilename);
+ else
+ archive_set_error(a, errno, "Can't stat '%s'",
+ filename);
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Determine whether the input looks like a disk device or a
+ * tape device. The results are used below to select an I/O
+ * strategy:
+ * = "disk-like" devices support arbitrary lseek() and will
+ * support I/O requests of any size. So we get easy skipping
+ * and can cheat on block sizes to get better performance.
+ * = "tape-like" devices require strict blocking and use
+ * specialized ioctls for seeking.
+ * = "socket-like" devices cannot seek at all but can improve
+ * performance by using nonblocking I/O to read "whatever is
+ * available right now".
+ *
+ * Right now, we only specially recognize disk-like devices,
+ * but it should be straightforward to add probes and strategy
+ * here for tape-like and socket-like devices.
+ */
+ if (S_ISREG(st.st_mode)) {
+ /* Safety: Tell the extractor not to overwrite the input. */
+ archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino);
+ /* Regular files act like disks. */
+ is_disk_like = 1;
+ }
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ /* FreeBSD: if it supports DIOCGMEDIASIZE ioctl, it's disk-like. */
+ else if (S_ISCHR(st.st_mode) &&
+ ioctl(fd, DIOCGMEDIASIZE, &mediasize) == 0 &&
+ mediasize > 0) {
+ is_disk_like = 1;
+ }
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+ /* Net/OpenBSD: if it supports DIOCGDINFO ioctl, it's disk-like. */
+ else if ((S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) &&
+ ioctl(fd, DIOCGDINFO, &dl) == 0 &&
+ dl.d_partitions[DISKPART(st.st_rdev)].p_size > 0) {
+ is_disk_like = 1;
+ }
+#elif defined(__DragonFly__)
+ /* DragonFly BSD: if it supports DIOCGPART ioctl, it's disk-like. */
+ else if (S_ISCHR(st.st_mode) &&
+ ioctl(fd, DIOCGPART, &pi) == 0 &&
+ pi.media_size > 0) {
+ is_disk_like = 1;
+ }
+#elif defined(__linux__)
+ /* Linux: All block devices are disk-like. */
+ else if (S_ISBLK(st.st_mode) &&
+ lseek(fd, 0, SEEK_CUR) == 0 &&
+ lseek(fd, 0, SEEK_SET) == 0 &&
+ lseek(fd, 0, SEEK_END) > 0 &&
+ lseek(fd, 0, SEEK_SET) == 0) {
+ is_disk_like = 1;
+ }
+#endif
+ /* TODO: Add an "is_tape_like" variable and appropriate tests. */
+
+ /* Disk-like devices prefer power-of-two block sizes. */
+ /* Use provided block_size as a guide so users have some control. */
+ if (is_disk_like) {
+ size_t new_block_size = 64 * 1024;
+ while (new_block_size < mine->block_size
+ && new_block_size < 64 * 1024 * 1024)
+ new_block_size *= 2;
+ mine->block_size = new_block_size;
+ }
+ buffer = malloc(mine->block_size);
+ if (mine == NULL || buffer == NULL) {
+ archive_set_error(a, ENOMEM, "No memory");
+ free(mine);
+ free(buffer);
+ return (ARCHIVE_FATAL);
+ }
+ mine->buffer = buffer;
+ mine->fd = fd;
+ /* Remember mode so close can decide whether to flush. */
+ mine->st_mode = st.st_mode;
+
+ /* Disk-like inputs can use lseek(). */
+ if (is_disk_like)
+ mine->use_lseek = 1;
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+file_read(struct archive *a, void *client_data, const void **buff)
+{
+ struct read_file_data *mine = (struct read_file_data *)client_data;
+ ssize_t bytes_read;
+
+ /* TODO: If a recent lseek() operation has left us
+ * mis-aligned, read and return a short block to try to get
+ * us back in alignment. */
+
+ /* TODO: Someday, try mmap() here; if that succeeds, give
+ * the entire file to libarchive as a single block. That
+ * could be a lot faster than block-by-block manual I/O. */
+
+ /* TODO: We might be able to improve performance on pipes and
+ * sockets by setting non-blocking I/O and just accepting
+ * whatever we get here instead of waiting for a full block
+ * worth of data. */
+
+ *buff = mine->buffer;
+ for (;;) {
+ bytes_read = read(mine->fd, mine->buffer, mine->block_size);
+ if (bytes_read < 0) {
+ if (errno == EINTR)
+ continue;
+ else if (mine->filename_type == FNT_STDIN)
+ archive_set_error(a, errno,
+ "Error reading stdin");
+ else if (mine->filename_type == FNT_MBS)
+ archive_set_error(a, errno,
+ "Error reading '%s'", mine->filename.m);
+ else
+ archive_set_error(a, errno,
+ "Error reading '%S'", mine->filename.w);
+ }
+ return (bytes_read);
+ }
+}
+
+/*
+ * Regular files and disk-like block devices can use simple lseek
+ * without needing to round the request to the block size.
+ *
+ * TODO: This can leave future reads mis-aligned. Since we know the
+ * offset here, we should store it and use it in file_read() above
+ * to determine whether we should perform a short read to get back
+ * into alignment. Long series of mis-aligned reads can negatively
+ * impact disk throughput. (Of course, the performance impact should
+ * be carefully tested; extra code complexity is only worthwhile if
+ * it does provide measurable improvement.)
+ *
+ * TODO: Be lazy about the actual seek. There are a few pathological
+ * cases where libarchive makes a bunch of seek requests in a row
+ * without any intervening reads. This isn't a huge performance
+ * problem, since the kernel handles seeks lazily already, but
+ * it would be very slightly faster if we simply remembered the
+ * seek request here and then actually performed the seek at the
+ * top of the read callback above.
+ */
+static int64_t
+file_skip_lseek(struct archive *a, void *client_data, int64_t request)
+{
+ struct read_file_data *mine = (struct read_file_data *)client_data;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* We use _lseeki64() on Windows. */
+ int64_t old_offset, new_offset;
+#else
+ off_t old_offset, new_offset;
+#endif
+
+ /* We use off_t here because lseek() is declared that way. */
+
+ /* TODO: Deal with case where off_t isn't 64 bits.
+ * This shouldn't be a problem on Linux or other POSIX
+ * systems, since the configuration logic for libarchive
+ * tries to obtain a 64-bit off_t.
+ */
+ if ((old_offset = lseek(mine->fd, 0, SEEK_CUR)) >= 0 &&
+ (new_offset = lseek(mine->fd, request, SEEK_CUR)) >= 0)
+ return (new_offset - old_offset);
+
+ /* If lseek() fails, don't bother trying again. */
+ mine->use_lseek = 0;
+
+ /* Let libarchive recover with read+discard */
+ if (errno == ESPIPE)
+ return (0);
+
+ /* If the input is corrupted or truncated, fail. */
+ if (mine->filename_type == FNT_STDIN)
+ archive_set_error(a, errno, "Error seeking in stdin");
+ else if (mine->filename_type == FNT_MBS)
+ archive_set_error(a, errno, "Error seeking in '%s'",
+ mine->filename.m);
+ else
+ archive_set_error(a, errno, "Error seeking in '%S'",
+ mine->filename.w);
+ return (-1);
+}
+
+
+/*
+ * TODO: Implement another file_skip_XXXX that uses MTIO ioctls to
+ * accelerate operation on tape drives.
+ */
+
+static int64_t
+file_skip(struct archive *a, void *client_data, int64_t request)
+{
+ struct read_file_data *mine = (struct read_file_data *)client_data;
+
+ /* Delegate skip requests. */
+ if (mine->use_lseek)
+ return (file_skip_lseek(a, client_data, request));
+
+ /* If we can't skip, return 0; libarchive will read+discard instead. */
+ return (0);
+}
+
+/*
+ * 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_file_data *mine = (struct read_file_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 the input is corrupted or truncated, fail. */
+ if (mine->filename_type == FNT_STDIN)
+ archive_set_error(a, errno, "Error seeking in stdin");
+ else if (mine->filename_type == FNT_MBS)
+ archive_set_error(a, errno, "Error seeking in '%s'",
+ mine->filename.m);
+ else
+ archive_set_error(a, errno, "Error seeking in '%S'",
+ mine->filename.w);
+ return (ARCHIVE_FATAL);
+}
+
+static int
+file_close2(struct archive *a, void *client_data)
+{
+ struct read_file_data *mine = (struct read_file_data *)client_data;
+
+ (void)a; /* UNUSED */
+
+ /* Only flush and close if open succeeded. */
+ if (mine->fd >= 0) {
+ /*
+ * Sometimes, we should flush the input before closing.
+ * Regular files: faster to just close without flush.
+ * Disk-like devices: Ditto.
+ * Tapes: must not flush (user might need to
+ * read the "next" item on a non-rewind device).
+ * Pipes and sockets: must flush (otherwise, the
+ * program feeding the pipe or socket may complain).
+ * Here, I flush everything except for regular files and
+ * device nodes.
+ */
+ if (!S_ISREG(mine->st_mode)
+ && !S_ISCHR(mine->st_mode)
+ && !S_ISBLK(mine->st_mode)) {
+ ssize_t bytesRead;
+ do {
+ bytesRead = read(mine->fd, mine->buffer,
+ mine->block_size);
+ } while (bytesRead > 0);
+ }
+ /* If a named file was opened, then it needs to be closed. */
+ if (mine->filename_type != FNT_STDIN)
+ close(mine->fd);
+ }
+ free(mine->buffer);
+ mine->buffer = NULL;
+ mine->fd = -1;
+ return (ARCHIVE_OK);
+}
+
+static int
+file_close(struct archive *a, void *client_data)
+{
+ struct read_file_data *mine = (struct read_file_data *)client_data;
+ file_close2(a, client_data);
+ free(mine);
+ return (ARCHIVE_OK);
+}
+
+static int
+file_switch(struct archive *a, void *client_data1, void *client_data2)
+{
+ file_close2(a, client_data1);
+ return file_open(a, client_data2);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c b/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c
new file mode 100644
index 0000000000..bcc7d6f78e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c
@@ -0,0 +1,187 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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: src/lib/libarchive/archive_read_open_memory.c,v 1.6 2007/07/06 15:51:59 kientzle Exp $");
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "archive.h"
+
+/*
+ * Glue to read an archive from a block of memory.
+ *
+ * This is mostly a huge help in building test harnesses;
+ * test programs can build archives in memory and read them
+ * back again without having to mess with files on disk.
+ */
+
+struct read_memory_data {
+ unsigned char *start;
+ unsigned char *p;
+ unsigned char *end;
+ ssize_t read_size;
+};
+
+static int memory_read_close(struct archive *, void *);
+static int memory_read_open(struct archive *, void *);
+static int64_t memory_read_seek(struct archive *, void *, int64_t offset, int whence);
+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)
+{
+ return archive_read_open_memory2(a, buff, size, size);
+}
+
+/*
+ * Don't use _open_memory2() in production code; the archive_read_open_memory()
+ * version is the one you really want. This is just here so that
+ * test harnesses can exercise block operations inside the library.
+ */
+int
+archive_read_open_memory2(struct archive *a, void *buff,
+ size_t size, size_t read_size)
+{
+ struct read_memory_data *mine;
+
+ mine = (struct read_memory_data *)malloc(sizeof(*mine));
+ if (mine == NULL) {
+ archive_set_error(a, ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ memset(mine, 0, sizeof(*mine));
+ mine->start = mine->p = (unsigned char *)buff;
+ mine->end = mine->start + size;
+ mine->read_size = read_size;
+ archive_read_set_open_callback(a, memory_read_open);
+ archive_read_set_read_callback(a, memory_read);
+ archive_read_set_seek_callback(a, memory_read_seek);
+ archive_read_set_skip_callback(a, memory_read_skip);
+ archive_read_set_close_callback(a, memory_read_close);
+ archive_read_set_callback_data(a, mine);
+ return (archive_read_open1(a));
+}
+
+/*
+ * There's nothing to open.
+ */
+static int
+memory_read_open(struct archive *a, void *client_data)
+{
+ (void)a; /* UNUSED */
+ (void)client_data; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+/*
+ * This is scary simple: Just advance a pointer. Limiting
+ * to read_size is not technically necessary, but it exercises
+ * more of the internal logic when used with a small block size
+ * in a test harness. Production use should not specify a block
+ * size; then this is much faster.
+ */
+static ssize_t
+memory_read(struct archive *a, void *client_data, const void **buff)
+{
+ struct read_memory_data *mine = (struct read_memory_data *)client_data;
+ ssize_t size;
+
+ (void)a; /* UNUSED */
+ *buff = mine->p;
+ size = mine->end - mine->p;
+ if (size > mine->read_size)
+ size = mine->read_size;
+ mine->p += size;
+ return (size);
+}
+
+/*
+ * Advancing is just as simple. Again, this is doing more than
+ * necessary in order to better exercise internal code when used
+ * as a test harness.
+ */
+static int64_t
+memory_read_skip(struct archive *a, void *client_data, int64_t skip)
+{
+ struct read_memory_data *mine = (struct read_memory_data *)client_data;
+
+ (void)a; /* UNUSED */
+ if ((int64_t)skip > (int64_t)(mine->end - mine->p))
+ skip = mine->end - mine->p;
+ /* Round down to block size. */
+ skip /= mine->read_size;
+ skip *= mine->read_size;
+ mine->p += skip;
+ return (skip);
+}
+
+/*
+ * Seeking.
+ */
+static int64_t
+memory_read_seek(struct archive *a, void *client_data, int64_t offset, int whence)
+{
+ struct read_memory_data *mine = (struct read_memory_data *)client_data;
+
+ (void)a; /* UNUSED */
+ switch (whence) {
+ case SEEK_SET:
+ mine->p = mine->start + offset;
+ break;
+ case SEEK_CUR:
+ mine->p += offset;
+ break;
+ case SEEK_END:
+ mine->p = mine->end + offset;
+ break;
+ default:
+ return ARCHIVE_FATAL;
+ }
+ if (mine->p < mine->start) {
+ mine->p = mine->start;
+ return ARCHIVE_FAILED;
+ }
+ if (mine->p > mine->end) {
+ mine->p = mine->end;
+ return ARCHIVE_FAILED;
+ }
+ return (mine->p - mine->start);
+}
+
+/*
+ * Close is just cleaning up our one small bit of data.
+ */
+static int
+memory_read_close(struct archive *a, void *client_data)
+{
+ struct read_memory_data *mine = (struct read_memory_data *)client_data;
+ (void)a; /* UNUSED */
+ free(mine);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_private.h b/Utilities/cmlibarchive/libarchive/archive_read_private.h
new file mode 100644
index 0000000000..27e203b7fb
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_private.h
@@ -0,0 +1,257 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_read_private.h 201088 2009-12-28 02:18:55Z kientzle $
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_READ_PRIVATE_H_INCLUDED
+#define ARCHIVE_READ_PRIVATE_H_INCLUDED
+
+#include "archive.h"
+#include "archive_string.h"
+#include "archive_private.h"
+
+struct archive_read;
+struct archive_read_filter_bidder;
+struct archive_read_filter;
+
+/*
+ * How bidding works for filters:
+ * * The bid manager initializes the client-provided reader as the
+ * first filter.
+ * * It invokes the bidder for each registered filter with the
+ * current head filter.
+ * * The bidders can use archive_read_filter_ahead() to peek ahead
+ * at the incoming data to compose their bids.
+ * * The bid manager creates a new filter structure for the winning
+ * bidder and gives the winning bidder a chance to initialize it.
+ * * The new filter becomes the new top filter and we repeat the
+ * process.
+ * This ends only when no bidder provides a non-zero bid. Then
+ * we perform a similar dance with the registered format handlers.
+ */
+struct archive_read_filter_bidder {
+ /* Configuration data for the bidder. */
+ void *data;
+ /* Name of the filter */
+ const char *name;
+ /* Taste the upstream filter to see if we handle this. */
+ int (*bid)(struct archive_read_filter_bidder *,
+ struct archive_read_filter *);
+ /* Initialize a newly-created filter. */
+ int (*init)(struct archive_read_filter *);
+ /* Set an option for the filter bidder. */
+ int (*options)(struct archive_read_filter_bidder *,
+ const char *key, const char *value);
+ /* Release the bidder's configuration data. */
+ int (*free)(struct archive_read_filter_bidder *);
+};
+
+/*
+ * This structure is allocated within the archive_read core
+ * and initialized by archive_read and the init() method of the
+ * corresponding bidder above.
+ */
+struct archive_read_filter {
+ int64_t position;
+ /* Essentially all filters will need these values, so
+ * just declare them here. */
+ struct archive_read_filter_bidder *bidder; /* My bidder. */
+ struct archive_read_filter *upstream; /* Who I read from. */
+ struct archive_read *archive; /* Associated archive. */
+ /* Open a block for reading */
+ int (*open)(struct archive_read_filter *self);
+ /* Return next block. */
+ ssize_t (*read)(struct archive_read_filter *, const void **);
+ /* Skip forward this many bytes. */
+ int64_t (*skip)(struct archive_read_filter *self, int64_t request);
+ /* Seek to an absolute location. */
+ int64_t (*seek)(struct archive_read_filter *self, int64_t offset, int whence);
+ /* Close (just this filter) and free(self). */
+ int (*close)(struct archive_read_filter *self);
+ /* Function that handles switching from reading one block to the next/prev */
+ int (*sswitch)(struct archive_read_filter *self, unsigned int iindex);
+ /* My private data. */
+ void *data;
+
+ const char *name;
+ int code;
+
+ /* Used by reblocking logic. */
+ char *buffer;
+ size_t buffer_size;
+ char *next; /* Current read location. */
+ size_t avail; /* Bytes in my buffer. */
+ const void *client_buff; /* Client buffer information. */
+ size_t client_total;
+ const char *client_next;
+ size_t client_avail;
+ char end_of_file;
+ char closed;
+ char fatal;
+};
+
+/*
+ * The client looks a lot like a filter, so we just wrap it here.
+ *
+ * TODO: Make archive_read_filter and archive_read_client identical so
+ * that users of the library can easily register their own
+ * transformation filters. This will probably break the API/ABI and
+ * so should be deferred at least until libarchive 3.0.
+ */
+struct archive_read_data_node {
+ int64_t begin_position;
+ int64_t total_size;
+ void *data;
+};
+struct archive_read_client {
+ archive_open_callback *opener;
+ archive_read_callback *reader;
+ archive_skip_callback *skipper;
+ archive_seek_callback *seeker;
+ archive_close_callback *closer;
+ archive_switch_callback *switcher;
+ unsigned int nodes;
+ unsigned int cursor;
+ int64_t position;
+ struct archive_read_data_node *dataset;
+};
+
+struct archive_read_extract {
+ struct archive *ad; /* archive_write_disk object */
+
+ /* Progress function invoked during extract. */
+ void (*extract_progress)(void *);
+ void *extract_progress_user_data;
+};
+
+struct archive_read {
+ struct archive archive;
+
+ struct archive_entry *entry;
+
+ /* Dev/ino of the archive being read/written. */
+ int skip_file_set;
+ 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];
+
+ /* Last filter in chain */
+ struct archive_read_filter *filter;
+
+ /* Whether to bypass filter bidding process */
+ int bypass_filter_bidding;
+
+ /* File offset of beginning of most recently-read header. */
+ int64_t header_position;
+
+ /* Nodes and offsets of compressed data block */
+ unsigned int data_start_node;
+ unsigned int data_end_node;
+
+ /*
+ * Format detection is mostly the same as compression
+ * detection, with one significant difference: The bidders
+ * use the read_ahead calls above to examine the stream rather
+ * than having the supervisor hand them a block of data to
+ * examine.
+ */
+
+ struct archive_format_descriptor {
+ void *data;
+ const char *name;
+ int (*bid)(struct archive_read *, int best_bid);
+ int (*options)(struct archive_read *, const char *key,
+ const char *value);
+ int (*read_header)(struct archive_read *, struct archive_entry *);
+ int (*read_data)(struct archive_read *, const void **, size_t *, int64_t *);
+ int (*read_data_skip)(struct archive_read *);
+ int64_t (*seek_data)(struct archive_read *, int64_t, int);
+ int (*cleanup)(struct archive_read *);
+ int (*format_capabilties)(struct archive_read *);
+ int (*has_encrypted_entries)(struct archive_read *);
+ } formats[16];
+ struct archive_format_descriptor *format; /* Active format. */
+
+ /*
+ * Various information needed by archive_extract.
+ */
+ struct archive_read_extract *extract;
+ int (*cleanup_archive_extract)(struct archive_read *);
+};
+
+int __archive_read_register_format(struct archive_read *a,
+ void *format_data,
+ const char *name,
+ int (*bid)(struct archive_read *, int),
+ int (*options)(struct archive_read *, const char *, const char *),
+ int (*read_header)(struct archive_read *, struct archive_entry *),
+ int (*read_data)(struct archive_read *, const void **, size_t *, int64_t *),
+ int (*read_data_skip)(struct archive_read *),
+ int64_t (*seek_data)(struct archive_read *, int64_t, int),
+ int (*cleanup)(struct archive_read *),
+ int (*format_capabilities)(struct archive_read *),
+ int (*has_encrypted_entries)(struct archive_read *));
+
+int __archive_read_get_bidder(struct archive_read *a,
+ struct archive_read_filter_bidder **bidder);
+
+const void *__archive_read_ahead(struct archive_read *, size_t, ssize_t *);
+const void *__archive_read_filter_ahead(struct archive_read_filter *,
+ size_t, ssize_t *);
+int64_t __archive_read_seek(struct archive_read*, int64_t, int);
+int64_t __archive_read_filter_seek(struct archive_read_filter *, int64_t, int);
+int64_t __archive_read_consume(struct archive_read *, int64_t);
+int64_t __archive_read_filter_consume(struct archive_read_filter *, int64_t);
+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 *);
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_set_format.c b/Utilities/cmlibarchive/libarchive/archive_read_set_format.c
new file mode 100644
index 0000000000..190f4369d2
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_set_format.c
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2003-2012 Tim Kientzle
+ * 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.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+int
+archive_read_set_format(struct archive *_a, int code)
+{
+ int r1, r2, slots, i;
+ char str[10];
+ struct archive_read *a = (struct archive_read *)_a;
+
+ if ((r1 = archive_read_support_format_by_code(_a, code)) < (ARCHIVE_OK))
+ return r1;
+
+ r1 = r2 = (ARCHIVE_OK);
+ if (a->format)
+ r2 = (ARCHIVE_WARN);
+ switch (code & ARCHIVE_FORMAT_BASE_MASK)
+ {
+ case ARCHIVE_FORMAT_7ZIP:
+ strcpy(str, "7zip");
+ break;
+ case ARCHIVE_FORMAT_AR:
+ strcpy(str, "ar");
+ break;
+ case ARCHIVE_FORMAT_CAB:
+ strcpy(str, "cab");
+ break;
+ case ARCHIVE_FORMAT_CPIO:
+ strcpy(str, "cpio");
+ break;
+ case ARCHIVE_FORMAT_ISO9660:
+ strcpy(str, "iso9660");
+ break;
+ case ARCHIVE_FORMAT_LHA:
+ strcpy(str, "lha");
+ break;
+ case ARCHIVE_FORMAT_MTREE:
+ strcpy(str, "mtree");
+ break;
+ case ARCHIVE_FORMAT_RAR:
+ strcpy(str, "rar");
+ break;
+ case ARCHIVE_FORMAT_TAR:
+ strcpy(str, "tar");
+ break;
+ case ARCHIVE_FORMAT_XAR:
+ strcpy(str, "xar");
+ break;
+ case ARCHIVE_FORMAT_ZIP:
+ strcpy(str, "zip");
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "Invalid format code specified");
+ return (ARCHIVE_FATAL);
+ }
+
+ slots = sizeof(a->formats) / sizeof(a->formats[0]);
+ a->format = &(a->formats[0]);
+ for (i = 0; i < slots; i++, a->format++) {
+ if (!a->format->name || !strcmp(a->format->name, str))
+ break;
+ }
+ if (!a->format->name || strcmp(a->format->name, str))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "Internal error: Unable to set format");
+ r1 = (ARCHIVE_FATAL);
+ }
+
+ return (r1 < r2) ? r1 : r2;
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_set_options.3 b/Utilities/cmlibarchive/libarchive/archive_read_set_options.3
new file mode 100644
index 0000000000..1a251cefec
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_set_options.3
@@ -0,0 +1,231 @@
+.\" Copyright (c) 2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_READ_OPTIONS 3
+.Os
+.Sh NAME
+.Nm archive_read_set_filter_option ,
+.Nm archive_read_set_format_option ,
+.Nm archive_read_set_option ,
+.Nm archive_read_set_options
+.Nd functions controlling options for reading archives
+.\"
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.Ft int
+.Fo archive_read_set_filter_option
+.Fa "struct archive *"
+.Fa "const char *module"
+.Fa "const char *option"
+.Fa "const char *value"
+.Fc
+.Ft int
+.Fo archive_read_set_format_option
+.Fa "struct archive *"
+.Fa "const char *module"
+.Fa "const char *option"
+.Fa "const char *value"
+.Fc
+.Ft int
+.Fo archive_read_set_option
+.Fa "struct archive *"
+.Fa "const char *module"
+.Fa "const char *option"
+.Fa "const char *value"
+.Fc
+.Ft int
+.Fo archive_read_set_options
+.Fa "struct archive *"
+.Fa "const char *options"
+.Fc
+.Sh DESCRIPTION
+These functions provide a way for libarchive clients to configure
+specific read modules.
+.Bl -tag -width indent
+.It Xo
+.Fn archive_read_set_filter_option ,
+.Fn archive_read_set_format_option
+.Xc
+Specifies an option that will be passed to currently-registered
+filters (including decompression filters) or format readers.
+.Pp
+If
+.Ar option
+and
+.Ar value
+are both
+.Dv NULL ,
+these functions will do nothing and
+.Cm ARCHIVE_OK
+will be returned.
+If
+.Ar option
+is
+.Dv NULL
+but
+.Ar value
+is not, these functions will do nothing and
+.Cm ARCHIVE_FAILED
+will be returned.
+.Pp
+If
+.Ar module
+is not
+.Dv NULL ,
+.Ar option
+and
+.Ar value
+will be provided to the filter or reader named
+.Ar module .
+The return value will be that of the module.
+If there is no such module,
+.Cm ARCHIVE_FAILED
+will be returned.
+.Pp
+If
+.Ar module
+is
+.Dv NULL ,
+.Ar option
+and
+.Ar value
+will be provided to every registered module.
+If any module returns
+.Cm ARCHIVE_FATAL ,
+this value will be returned immediately.
+Otherwise,
+.Cm ARCHIVE_OK
+will be returned if any module accepts the option, and
+.Cm ARCHIVE_FAILED
+in all other cases.
+.\"
+.It Xo
+.Fn archive_read_set_option
+.Xc
+Calls
+.Fn archive_read_set_format_option ,
+then
+.Fn archive_read_set_filter_option .
+If either function returns
+.Cm ARCHIVE_FATAL ,
+.Cm ARCHIVE_FATAL
+will be returned
+immediately.
+Otherwise, greater of the two values will be returned.
+.\"
+.It Xo
+.Fn archive_read_set_options
+.Xc
+.Ar options
+is a comma-separated list of options.
+If
+.Ar options
+is
+.Dv NULL
+or empty,
+.Cm ARCHIVE_OK
+will be returned immediately.
+.Pp
+Calls
+.Fn archive_read_set_option
+with each option in turn.
+If any
+.Fn archive_read_set_option
+call returns
+.Cm ARCHIVE_FATAL ,
+.Cm ARCHIVE_FATAL
+will be returned immediately.
+.Pp
+Individual options have one of the following forms:
+.Bl -tag -compact -width indent
+.It Ar option=value
+The option/value pair will be provided to every module.
+Modules that do not accept an option with this name will ignore it.
+.It Ar option
+The option will be provided to every module with a value of
+.Dq 1 .
+.It Ar !option
+The option will be provided to every module with a NULL value.
+.It Ar module:option=value , Ar module:option , Ar module:!option
+As above, but the corresponding option and value will be provided
+only to modules whose name matches
+.Ar module .
+.El
+.El
+.\"
+.Sh OPTIONS
+.Bl -tag -compact -width indent
+.It Format iso9660
+.Bl -tag -compact -width indent
+.It Cm joliet
+Support Joliet extensions.
+Defaults to enabled, use
+.Cm !joliet
+to disable.
+.It Cm rockridge
+Support RockRidge extensions.
+Defaults to enabled, use
+.Cm !rockridge
+to disable.
+.El
+.It Format tar
+.Bl -tag -compact -width indent
+.It Cm compat-2x
+Libarchive 2.x incorrectly encoded Unicode filenames on
+some platforms.
+This option mimics the libarchive 2.x filename handling
+so that such archives can be read correctly.
+.It Cm hdrcharset
+The value is used as a character set name that will be
+used when translating filenames.
+.It Cm mac-ext
+Support Mac OS metadata extension that records data in special
+files beginning with a period and underscore.
+Defaults to enabled on Mac OS, disabled on other platforms.
+Use
+.Cm !mac-ext
+to disable.
+.It Cm read_concatenated_archives
+Ignore zeroed blocks in the archive, which occurs when multiple tar archives
+have been concatenated together. Without this option, only the contents of
+the first concatenated archive would be read.
+.El
+.El
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr archive_read 3
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_set_options.c b/Utilities/cmlibarchive/libarchive/archive_read_set_options.c
new file mode 100644
index 0000000000..46678b1636
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_set_options.c
@@ -0,0 +1,156 @@
+/*-
+ * Copyright (c) 2011 Tim Kientzle
+ * 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$");
+
+#include "archive_read_private.h"
+#include "archive_options_private.h"
+
+static int archive_set_format_option(struct archive *a,
+ const char *m, const char *o, const char *v);
+static int archive_set_filter_option(struct archive *a,
+ const char *m, const char *o, const char *v);
+static int archive_set_option(struct archive *a,
+ const char *m, const char *o, const char *v);
+
+int
+archive_read_set_format_option(struct archive *a, const char *m, const char *o,
+ const char *v)
+{
+ return _archive_set_option(a, m, o, v,
+ ARCHIVE_READ_MAGIC, "archive_read_set_format_option",
+ archive_set_format_option);
+}
+
+int
+archive_read_set_filter_option(struct archive *a, const char *m, const char *o,
+ const char *v)
+{
+ return _archive_set_option(a, m, o, v,
+ ARCHIVE_READ_MAGIC, "archive_read_set_filter_option",
+ archive_set_filter_option);
+}
+
+int
+archive_read_set_option(struct archive *a, const char *m, const char *o,
+ const char *v)
+{
+ return _archive_set_option(a, m, o, v,
+ ARCHIVE_READ_MAGIC, "archive_read_set_option",
+ archive_set_option);
+}
+
+int
+archive_read_set_options(struct archive *a, const char *options)
+{
+ return _archive_set_options(a, options,
+ ARCHIVE_READ_MAGIC, "archive_read_set_options",
+ archive_set_option);
+}
+
+static int
+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)
+ /* This format does not support option. */
+ continue;
+ if (m != NULL) {
+ if (strcmp(format->name, m) != 0)
+ continue;
+ ++matched_modules;
+ }
+
+ a->format = format;
+ r = format->options(a, o, v);
+ a->format = NULL;
+
+ if (r == ARCHIVE_FATAL)
+ return (ARCHIVE_FATAL);
+
+ if (r == ARCHIVE_OK)
+ rv = ARCHIVE_OK;
+ }
+ /* If the format name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (m != NULL && matched_modules == 0)
+ return ARCHIVE_WARN - 1;
+ return (rv);
+}
+
+static int
+archive_set_filter_option(struct archive *_a, const char *m, const char *o,
+ const char *v)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter *filter;
+ struct archive_read_filter_bidder *bidder;
+ int r, rv = ARCHIVE_WARN, matched_modules = 0;
+
+ for (filter = a->filter; filter != NULL; filter = filter->upstream) {
+ bidder = filter->bidder;
+ if (bidder == NULL)
+ continue;
+ if (bidder->options == NULL)
+ /* This bidder does not support option */
+ continue;
+ if (m != NULL) {
+ if (strcmp(filter->name, m) != 0)
+ continue;
+ ++matched_modules;
+ }
+
+ r = bidder->options(bidder, o, v);
+
+ if (r == ARCHIVE_FATAL)
+ return (ARCHIVE_FATAL);
+
+ if (r == ARCHIVE_OK)
+ rv = ARCHIVE_OK;
+ }
+ /* If the filter name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (m != NULL && matched_modules == 0)
+ return ARCHIVE_WARN - 1;
+ return (rv);
+}
+
+static int
+archive_set_option(struct archive *a, const char *m, const char *o,
+ const char *v)
+{
+ return _archive_set_either_option(a, m, o, v,
+ archive_set_format_option,
+ archive_set_filter_option);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c
new file mode 100644
index 0000000000..b778cfb792
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c
@@ -0,0 +1,81 @@
+/*-
+ * Copyright (c) 2003-2011 Tim Kientzle
+ * 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$");
+
+#include "archive.h"
+#include "archive_private.h"
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Deprecated; remove in libarchive 4.0 */
+int
+archive_read_support_compression_all(struct archive *a)
+{
+ return archive_read_support_filter_all(a);
+}
+#endif
+
+int
+archive_read_support_filter_all(struct archive *a)
+{
+ archive_check_magic(a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_filter_all");
+
+ /* Bzip falls back to "bunzip2" command-line */
+ archive_read_support_filter_bzip2(a);
+ /* The decompress code doesn't use an outside library. */
+ archive_read_support_filter_compress(a);
+ /* Gzip decompress falls back to "gzip -d" command-line. */
+ archive_read_support_filter_gzip(a);
+ /* Lzip falls back to "unlzip" command-line program. */
+ archive_read_support_filter_lzip(a);
+ /* The LZMA file format has a very weak signature, so it
+ * may not be feasible to keep this here, but we'll try.
+ * This will come back out if there are problems. */
+ /* Lzma falls back to "unlzma" command-line program. */
+ archive_read_support_filter_lzma(a);
+ /* Xz falls back to "unxz" command-line program. */
+ archive_read_support_filter_xz(a);
+ /* The decode code doesn't use an outside library. */
+ archive_read_support_filter_uu(a);
+ /* The decode code doesn't use an outside library. */
+ archive_read_support_filter_rpm(a);
+ /* The decode code always uses "lrzip -q -d" command-line. */
+ archive_read_support_filter_lrzip(a);
+ /* Lzop decompress falls back to "lzop -d" command-line. */
+ archive_read_support_filter_lzop(a);
+ /* The decode code always uses "grzip -d" command-line. */
+ archive_read_support_filter_grzip(a);
+
+ /* Note: We always return ARCHIVE_OK here, even if some of the
+ * above return ARCHIVE_WARN. The intent here is to enable
+ * "as much as possible." Clients who need specific
+ * compression should enable those individually so they can
+ * verify the level of support. */
+ /* Clear any warning messages set by the above functions. */
+ archive_clear_error(a);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_bzip2.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_bzip2.c
new file mode 100644
index 0000000000..2b1a5e2aa7
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_bzip2.c
@@ -0,0 +1,371 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_BZLIB_H
+#include <cm_bzlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+struct private_data {
+ bz_stream stream;
+ char *out_block;
+ size_t out_block_size;
+ char valid; /* True = decompressor is initialized */
+ char eof; /* True = found end of compressed data. */
+};
+
+/* Bzip2 filter */
+static ssize_t bzip2_filter_read(struct archive_read_filter *, const void **);
+static int bzip2_filter_close(struct archive_read_filter *);
+#endif
+
+/*
+ * Note that we can detect bzip2 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 bzlib is unavailable.
+ */
+static int bzip2_reader_bid(struct archive_read_filter_bidder *, struct archive_read_filter *);
+static int bzip2_reader_init(struct archive_read_filter *);
+static int bzip2_reader_free(struct archive_read_filter_bidder *);
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Deprecated; remove in libarchive 4.0 */
+int
+archive_read_support_compression_bzip2(struct archive *a)
+{
+ return archive_read_support_filter_bzip2(a);
+}
+#endif
+
+int
+archive_read_support_filter_bzip2(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_bzip2");
+
+ if (__archive_read_get_bidder(a, &reader) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ reader->data = NULL;
+ reader->name = "bzip2";
+ reader->bid = bzip2_reader_bid;
+ reader->init = bzip2_reader_init;
+ reader->options = NULL;
+ reader->free = bzip2_reader_free;
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ return (ARCHIVE_OK);
+#else
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external bzip2 program");
+ return (ARCHIVE_WARN);
+#endif
+}
+
+static int
+bzip2_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
+bzip2_reader_bid(struct archive_read_filter_bidder *self, struct archive_read_filter *filter)
+{
+ const unsigned char *buffer;
+ ssize_t avail;
+ int bits_checked;
+
+ (void)self; /* UNUSED */
+
+ /* Minimal bzip2 archive is 14 bytes. */
+ buffer = __archive_read_filter_ahead(filter, 14, &avail);
+ if (buffer == NULL)
+ return (0);
+
+ /* First three bytes must be "BZh" */
+ bits_checked = 0;
+ if (memcmp(buffer, "BZh", 3) != 0)
+ return (0);
+ bits_checked += 24;
+
+ /* Next follows a compression flag which must be an ASCII digit. */
+ if (buffer[3] < '1' || buffer[3] > '9')
+ return (0);
+ bits_checked += 5;
+
+ /* After BZh[1-9], there must be either a data block
+ * which begins with 0x314159265359 or an end-of-data
+ * marker of 0x177245385090. */
+ if (memcmp(buffer + 4, "\x31\x41\x59\x26\x53\x59", 6) == 0)
+ bits_checked += 48;
+ else if (memcmp(buffer + 4, "\x17\x72\x45\x38\x50\x90", 6) == 0)
+ bits_checked += 48;
+ else
+ return (0);
+
+ return (bits_checked);
+}
+
+#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR)
+
+/*
+ * 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
+bzip2_reader_init(struct archive_read_filter *self)
+{
+ int r;
+
+ r = __archive_read_program(self, "bzip2 -d");
+ /* 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_BZIP2;
+ self->name = "bzip2";
+ return (r);
+}
+
+
+#else
+
+/*
+ * Setup the callbacks.
+ */
+static int
+bzip2_reader_init(struct archive_read_filter *self)
+{
+ static const size_t out_block_size = 64 * 1024;
+ void *out_block;
+ struct private_data *state;
+
+ self->code = ARCHIVE_FILTER_BZIP2;
+ self->name = "bzip2";
+
+ state = (struct private_data *)calloc(sizeof(*state), 1);
+ out_block = (unsigned char *)malloc(out_block_size);
+ if (state == NULL || out_block == NULL) {
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate data for bzip2 decompression");
+ free(out_block);
+ free(state);
+ return (ARCHIVE_FATAL);
+ }
+
+ self->data = state;
+ state->out_block_size = out_block_size;
+ state->out_block = out_block;
+ self->read = bzip2_filter_read;
+ self->skip = NULL; /* not supported */
+ self->close = bzip2_filter_close;
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Return the next block of decompressed data.
+ */
+static ssize_t
+bzip2_filter_read(struct archive_read_filter *self, const void **p)
+{
+ struct private_data *state;
+ size_t decompressed;
+ const char *read_buf;
+ ssize_t ret;
+
+ state = (struct private_data *)self->data;
+
+ if (state->eof) {
+ *p = NULL;
+ return (0);
+ }
+
+ /* Empty our output buffer. */
+ state->stream.next_out = state->out_block;
+ state->stream.avail_out = state->out_block_size;
+
+ /* Try to fill the output buffer. */
+ for (;;) {
+ if (!state->valid) {
+ if (bzip2_reader_bid(self->bidder, self->upstream) == 0) {
+ state->eof = 1;
+ *p = state->out_block;
+ decompressed = state->stream.next_out
+ - state->out_block;
+ return (decompressed);
+ }
+ /* Initialize compression library. */
+ ret = BZ2_bzDecompressInit(&(state->stream),
+ 0 /* library verbosity */,
+ 0 /* don't use low-mem algorithm */);
+
+ /* If init fails, try low-memory algorithm instead. */
+ if (ret == BZ_MEM_ERROR)
+ ret = BZ2_bzDecompressInit(&(state->stream),
+ 0 /* library verbosity */,
+ 1 /* do use low-mem algo */);
+
+ if (ret != BZ_OK) {
+ const char *detail = NULL;
+ int err = ARCHIVE_ERRNO_MISC;
+ switch (ret) {
+ case BZ_PARAM_ERROR:
+ detail = "invalid setup parameter";
+ break;
+ case BZ_MEM_ERROR:
+ err = ENOMEM;
+ detail = "out of memory";
+ break;
+ case BZ_CONFIG_ERROR:
+ detail = "mis-compiled library";
+ break;
+ }
+ archive_set_error(&self->archive->archive, err,
+ "Internal error initializing decompressor%s%s",
+ detail == NULL ? "" : ": ",
+ detail);
+ return (ARCHIVE_FATAL);
+ }
+ state->valid = 1;
+ }
+
+ /* stream.next_in is really const, but bzlib
+ * doesn't declare it so. <sigh> */
+ read_buf =
+ __archive_read_filter_ahead(self->upstream, 1, &ret);
+ if (read_buf == NULL) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "truncated bzip2 input");
+ return (ARCHIVE_FATAL);
+ }
+ state->stream.next_in = (char *)(uintptr_t)read_buf;
+ state->stream.avail_in = ret;
+ /* There is no more data, return whatever we have. */
+ if (ret == 0) {
+ state->eof = 1;
+ *p = state->out_block;
+ decompressed = state->stream.next_out
+ - state->out_block;
+ return (decompressed);
+ }
+
+ /* Decompress as much as we can in one pass. */
+ ret = BZ2_bzDecompress(&(state->stream));
+ __archive_read_filter_consume(self->upstream,
+ state->stream.next_in - read_buf);
+
+ switch (ret) {
+ case BZ_STREAM_END: /* Found end of stream. */
+ switch (BZ2_bzDecompressEnd(&(state->stream))) {
+ case BZ_OK:
+ break;
+ default:
+ archive_set_error(&(self->archive->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up decompressor");
+ return (ARCHIVE_FATAL);
+ }
+ state->valid = 0;
+ /* FALLTHROUGH */
+ case BZ_OK: /* Decompressor made some progress. */
+ /* If we filled our buffer, update stats and return. */
+ if (state->stream.avail_out == 0) {
+ *p = state->out_block;
+ decompressed = state->stream.next_out
+ - state->out_block;
+ return (decompressed);
+ }
+ break;
+ default: /* Return an error. */
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC, "bzip decompression failed");
+ return (ARCHIVE_FATAL);
+ }
+ }
+}
+
+/*
+ * Clean up the decompressor.
+ */
+static int
+bzip2_filter_close(struct archive_read_filter *self)
+{
+ struct private_data *state;
+ int ret = ARCHIVE_OK;
+
+ state = (struct private_data *)self->data;
+
+ if (state->valid) {
+ switch (BZ2_bzDecompressEnd(&state->stream)) {
+ case BZ_OK:
+ break;
+ default:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up decompressor");
+ ret = ARCHIVE_FATAL;
+ }
+ state->valid = 0;
+ }
+
+ free(state->out_block);
+ free(state);
+ return (ret);
+}
+
+#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c
new file mode 100644
index 0000000000..3f5d1f37ea
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c
@@ -0,0 +1,455 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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.
+ */
+
+/*
+ * This code borrows heavily from "compress" source code, which is
+ * protected by the following copyright. (Clause 3 dropped by request
+ * of the Regents.)
+ */
+
+/*-
+ * Copyright (c) 1985, 1986, 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Diomidis Spinellis and James A. Woods, derived from original
+ * work by Spencer Thomas and Joseph Orost.
+ *
+ * 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.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD$");
+
+#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_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+/*
+ * Because LZW decompression is pretty simple, I've just implemented
+ * the whole decompressor here (cribbing from "compress" source code,
+ * of course), rather than relying on an external library. I have
+ * made an effort to clarify and simplify the algorithm, so the
+ * names and structure here don't exactly match those used by compress.
+ */
+
+struct private_data {
+ /* Input variables. */
+ const unsigned char *next_in;
+ size_t avail_in;
+ size_t consume_unnotified;
+ int bit_buffer;
+ int bits_avail;
+ size_t bytes_in_section;
+
+ /* Output variables. */
+ size_t out_block_size;
+ void *out_block;
+
+ /* Decompression status variables. */
+ int use_reset_code;
+ int end_of_stream; /* EOF status. */
+ int maxcode; /* Largest code. */
+ int maxcode_bits; /* Length of largest code. */
+ int section_end_code; /* When to increase bits. */
+ int bits; /* Current code length. */
+ int oldcode; /* Previous code. */
+ int finbyte; /* Last byte of prev code. */
+
+ /* Dictionary. */
+ int free_ent; /* Next dictionary entry. */
+ unsigned char suffix[65536];
+ uint16_t prefix[65536];
+
+ /*
+ * Scratch area for expanding dictionary entries. Note:
+ * "worst" case here comes from compressing /dev/zero: the
+ * last code in the dictionary will code a sequence of
+ * 65536-256 zero bytes. Thus, we need stack space to expand
+ * a 65280-byte dictionary entry. (Of course, 32640:1
+ * compression could also be considered the "best" case. ;-)
+ */
+ unsigned char *stackp;
+ unsigned char stack[65300];
+};
+
+static int compress_bidder_bid(struct archive_read_filter_bidder *, struct archive_read_filter *);
+static int compress_bidder_init(struct archive_read_filter *);
+static int compress_bidder_free(struct archive_read_filter_bidder *);
+
+static ssize_t compress_filter_read(struct archive_read_filter *, const void **);
+static int compress_filter_close(struct archive_read_filter *);
+
+static int getbits(struct archive_read_filter *, int n);
+static int next_code(struct archive_read_filter *);
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Deprecated; remove in libarchive 4.0 */
+int
+archive_read_support_compression_compress(struct archive *a)
+{
+ return archive_read_support_filter_compress(a);
+}
+#endif
+
+int
+archive_read_support_filter_compress(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter_bidder *bidder;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_filter_compress");
+
+ if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ bidder->data = NULL;
+ bidder->name = "compress (.Z)";
+ bidder->bid = compress_bidder_bid;
+ bidder->init = compress_bidder_init;
+ bidder->options = NULL;
+ bidder->free = compress_bidder_free;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Test whether we can handle this data.
+ * This logic returns zero if any part of the signature fails.
+ */
+static int
+compress_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+ const unsigned char *buffer;
+ ssize_t avail;
+ int bits_checked;
+
+ (void)self; /* UNUSED */
+
+ buffer = __archive_read_filter_ahead(filter, 2, &avail);
+
+ if (buffer == NULL)
+ return (0);
+
+ bits_checked = 0;
+ if (buffer[0] != 0x1F || buffer[1] != 0x9D)
+ return (0);
+ bits_checked += 16;
+
+ /*
+ * TODO: Verify more.
+ */
+
+ return (bits_checked);
+}
+
+/*
+ * Setup the callbacks.
+ */
+static int
+compress_bidder_init(struct archive_read_filter *self)
+{
+ struct private_data *state;
+ static const size_t out_block_size = 64 * 1024;
+ void *out_block;
+ int code;
+
+ self->code = ARCHIVE_FILTER_COMPRESS;
+ self->name = "compress (.Z)";
+
+ state = (struct private_data *)calloc(sizeof(*state), 1);
+ out_block = malloc(out_block_size);
+ if (state == NULL || out_block == NULL) {
+ free(out_block);
+ free(state);
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate data for %s decompression",
+ self->name);
+ return (ARCHIVE_FATAL);
+ }
+
+ self->data = state;
+ state->out_block_size = out_block_size;
+ state->out_block = out_block;
+ self->read = compress_filter_read;
+ self->skip = NULL; /* not supported */
+ self->close = compress_filter_close;
+
+ /* XXX MOVE THE FOLLOWING OUT OF INIT() XXX */
+
+ (void)getbits(self, 8); /* Skip first signature byte. */
+ (void)getbits(self, 8); /* Skip second signature byte. */
+
+ code = getbits(self, 8);
+ state->maxcode_bits = code & 0x1f;
+ state->maxcode = (1 << state->maxcode_bits);
+ state->use_reset_code = code & 0x80;
+
+ /* Initialize decompressor. */
+ state->free_ent = 256;
+ state->stackp = state->stack;
+ if (state->use_reset_code)
+ state->free_ent++;
+ state->bits = 9;
+ state->section_end_code = (1<<state->bits) - 1;
+ state->oldcode = -1;
+ for (code = 255; code >= 0; code--) {
+ state->prefix[code] = 0;
+ state->suffix[code] = code;
+ }
+ next_code(self);
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Return a block of data from the decompression buffer. Decompress more
+ * as necessary.
+ */
+static ssize_t
+compress_filter_read(struct archive_read_filter *self, const void **pblock)
+{
+ struct private_data *state;
+ unsigned char *p, *start, *end;
+ int ret;
+
+ state = (struct private_data *)self->data;
+ if (state->end_of_stream) {
+ *pblock = NULL;
+ return (0);
+ }
+ p = start = (unsigned char *)state->out_block;
+ end = start + state->out_block_size;
+
+ while (p < end && !state->end_of_stream) {
+ if (state->stackp > state->stack) {
+ *p++ = *--state->stackp;
+ } else {
+ ret = next_code(self);
+ if (ret == -1)
+ state->end_of_stream = ret;
+ else if (ret != ARCHIVE_OK)
+ return (ret);
+ }
+ }
+
+ *pblock = start;
+ return (p - start);
+}
+
+/*
+ * Clean up the reader.
+ */
+static int
+compress_bidder_free(struct archive_read_filter_bidder *self)
+{
+ self->data = NULL;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Close and release the filter.
+ */
+static int
+compress_filter_close(struct archive_read_filter *self)
+{
+ struct private_data *state = (struct private_data *)self->data;
+
+ free(state->out_block);
+ free(state);
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Process the next code and fill the stack with the expansion
+ * of the code. Returns ARCHIVE_FATAL if there is a fatal I/O or
+ * format error, ARCHIVE_EOF if we hit end of data, ARCHIVE_OK otherwise.
+ */
+static int
+next_code(struct archive_read_filter *self)
+{
+ struct private_data *state = (struct private_data *)self->data;
+ int code, newcode;
+
+ static int debug_buff[1024];
+ static unsigned debug_index;
+
+ code = newcode = getbits(self, state->bits);
+ if (code < 0)
+ return (code);
+
+ debug_buff[debug_index++] = code;
+ if (debug_index >= sizeof(debug_buff)/sizeof(debug_buff[0]))
+ debug_index = 0;
+
+ /* If it's a reset code, reset the dictionary. */
+ if ((code == 256) && state->use_reset_code) {
+ /*
+ * The original 'compress' implementation blocked its
+ * I/O in a manner that resulted in junk bytes being
+ * inserted after every reset. The next section skips
+ * this junk. (Yes, the number of *bytes* to skip is
+ * a function of the current *bit* length.)
+ */
+ int skip_bytes = state->bits -
+ (state->bytes_in_section % state->bits);
+ skip_bytes %= state->bits;
+ state->bits_avail = 0; /* Discard rest of this byte. */
+ while (skip_bytes-- > 0) {
+ code = getbits(self, 8);
+ if (code < 0)
+ return (code);
+ }
+ /* Now, actually do the reset. */
+ state->bytes_in_section = 0;
+ state->bits = 9;
+ state->section_end_code = (1 << state->bits) - 1;
+ state->free_ent = 257;
+ state->oldcode = -1;
+ return (next_code(self));
+ }
+
+ if (code > state->free_ent) {
+ /* An invalid code is a fatal error. */
+ archive_set_error(&(self->archive->archive), -1,
+ "Invalid compressed data");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Special case for KwKwK string. */
+ if (code >= state->free_ent) {
+ *state->stackp++ = state->finbyte;
+ code = state->oldcode;
+ }
+
+ /* Generate output characters in reverse order. */
+ while (code >= 256) {
+ *state->stackp++ = state->suffix[code];
+ code = state->prefix[code];
+ }
+ *state->stackp++ = state->finbyte = code;
+
+ /* Generate the new entry. */
+ code = state->free_ent;
+ if (code < state->maxcode && state->oldcode >= 0) {
+ state->prefix[code] = state->oldcode;
+ state->suffix[code] = state->finbyte;
+ ++state->free_ent;
+ }
+ if (state->free_ent > state->section_end_code) {
+ state->bits++;
+ state->bytes_in_section = 0;
+ if (state->bits == state->maxcode_bits)
+ state->section_end_code = state->maxcode;
+ else
+ state->section_end_code = (1 << state->bits) - 1;
+ }
+
+ /* Remember previous code. */
+ state->oldcode = newcode;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Return next 'n' bits from stream.
+ *
+ * -1 indicates end of available data.
+ */
+static int
+getbits(struct archive_read_filter *self, int n)
+{
+ struct private_data *state = (struct private_data *)self->data;
+ int code;
+ ssize_t ret;
+ static const int mask[] = {
+ 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff,
+ 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff, 0xffff
+ };
+
+ while (state->bits_avail < n) {
+ if (state->avail_in <= 0) {
+ if (state->consume_unnotified) {
+ __archive_read_filter_consume(self->upstream,
+ state->consume_unnotified);
+ state->consume_unnotified = 0;
+ }
+ state->next_in
+ = __archive_read_filter_ahead(self->upstream,
+ 1, &ret);
+ if (ret == 0)
+ return (-1);
+ if (ret < 0 || state->next_in == NULL)
+ return (ARCHIVE_FATAL);
+ state->consume_unnotified = state->avail_in = ret;
+ }
+ state->bit_buffer |= *state->next_in++ << state->bits_avail;
+ state->avail_in--;
+ state->bits_avail += 8;
+ state->bytes_in_section++;
+ }
+
+ code = state->bit_buffer;
+ state->bit_buffer >>= n;
+ state->bits_avail -= n;
+
+ return (code & mask[n]);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_grzip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_grzip.c
new file mode 100644
index 0000000000..84c86aeb43
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_grzip.c
@@ -0,0 +1,121 @@
+/*-
+ * Copyright (c) 2012 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+static const unsigned char grzip_magic[] = {
+ 0x47, 0x52, 0x5a, 0x69, 0x70, 0x49, 0x49, 0x00,
+ 0x02, 0x04, 0x3a, 0x29 };
+
+static int grzip_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *);
+static int grzip_bidder_init(struct archive_read_filter *);
+
+
+static int
+grzip_reader_free(struct archive_read_filter_bidder *self)
+{
+ (void)self; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_support_filter_grzip(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_grzip");
+
+ if (__archive_read_get_bidder(a, &reader) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ reader->data = NULL;
+ reader->bid = grzip_bidder_bid;
+ reader->init = grzip_bidder_init;
+ reader->options = NULL;
+ reader->free = grzip_reader_free;
+ /* This filter always uses an external program. */
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external grzip program for grzip decompression");
+ return (ARCHIVE_WARN);
+}
+
+/*
+ * Bidder just verifies the header and returns the number of verified bits.
+ */
+static int
+grzip_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+ const unsigned char *p;
+ ssize_t avail;
+
+ (void)self; /* UNUSED */
+
+ p = __archive_read_filter_ahead(filter, sizeof(grzip_magic), &avail);
+ if (p == NULL || avail == 0)
+ return (0);
+
+ if (memcmp(p, grzip_magic, sizeof(grzip_magic)))
+ return (0);
+
+ return (sizeof(grzip_magic) * 8);
+}
+
+static int
+grzip_bidder_init(struct archive_read_filter *self)
+{
+ int r;
+
+ r = __archive_read_program(self, "grzip -d");
+ /* 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_GRZIP;
+ self->name = "grzip";
+ return (r);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_gzip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_gzip.c
new file mode 100644
index 0000000000..e9f59f13fd
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_gzip.c
@@ -0,0 +1,477 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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
+#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_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+#ifdef HAVE_ZLIB_H
+struct private_data {
+ z_stream stream;
+ char in_stream;
+ unsigned char *out_block;
+ size_t out_block_size;
+ int64_t total_out;
+ unsigned long crc;
+ char eof; /* True = found end of compressed data. */
+};
+
+/* Gzip Filter. */
+static ssize_t gzip_filter_read(struct archive_read_filter *, const void **);
+static int gzip_filter_close(struct archive_read_filter *);
+#endif
+
+/*
+ * Note that we can detect gzip 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 zlib is unavailable.
+ *
+ * TODO: If zlib is unavailable, gzip_bidder_init() should
+ * use the compress_program framework to try to fire up an external
+ * gzip program.
+ */
+static int gzip_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *);
+static int gzip_bidder_init(struct archive_read_filter *);
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Deprecated; remove in libarchive 4.0 */
+int
+archive_read_support_compression_gzip(struct archive *a)
+{
+ return archive_read_support_filter_gzip(a);
+}
+#endif
+
+int
+archive_read_support_filter_gzip(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter_bidder *bidder;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_filter_gzip");
+
+ if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ bidder->data = NULL;
+ bidder->name = "gzip";
+ bidder->bid = gzip_bidder_bid;
+ bidder->init = gzip_bidder_init;
+ bidder->options = NULL;
+ bidder->free = NULL; /* No data, so no cleanup necessary. */
+ /* Signal the extent of gzip support with the return value here. */
+#if HAVE_ZLIB_H
+ return (ARCHIVE_OK);
+#else
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external gzip program");
+ return (ARCHIVE_WARN);
+#endif
+}
+
+/*
+ * Read and verify the header.
+ *
+ * Returns zero if the header couldn't be validated, else returns
+ * number of bytes in header. If pbits is non-NULL, it receives a
+ * count of bits verified, suitable for use by bidder.
+ */
+static ssize_t
+peek_at_header(struct archive_read_filter *filter, int *pbits)
+{
+ const unsigned char *p;
+ ssize_t avail, len;
+ int bits = 0;
+ int header_flags;
+
+ /* Start by looking at the first ten bytes of the header, which
+ * is all fixed layout. */
+ len = 10;
+ p = __archive_read_filter_ahead(filter, len, &avail);
+ if (p == NULL || avail == 0)
+ return (0);
+ /* We only support deflation- third byte must be 0x08. */
+ if (memcmp(p, "\x1F\x8B\x08", 3) != 0)
+ return (0);
+ bits += 24;
+ if ((p[3] & 0xE0)!= 0) /* No reserved flags set. */
+ return (0);
+ bits += 3;
+ header_flags = p[3];
+ /* Bytes 4-7 are mod time. */
+ /* Byte 8 is deflate flags. */
+ /* XXXX TODO: return deflate flags back to consume_header for use
+ in initializing the decompressor. */
+ /* Byte 9 is OS. */
+
+ /* Optional extra data: 2 byte length plus variable body. */
+ if (header_flags & 4) {
+ p = __archive_read_filter_ahead(filter, len + 2, &avail);
+ if (p == NULL)
+ return (0);
+ len += ((int)p[len + 1] << 8) | (int)p[len];
+ len += 2;
+ }
+
+ /* Null-terminated optional filename. */
+ if (header_flags & 8) {
+ do {
+ ++len;
+ if (avail < len)
+ p = __archive_read_filter_ahead(filter,
+ len, &avail);
+ if (p == NULL)
+ return (0);
+ } while (p[len - 1] != 0);
+ }
+
+ /* Null-terminated optional comment. */
+ if (header_flags & 16) {
+ do {
+ ++len;
+ if (avail < len)
+ p = __archive_read_filter_ahead(filter,
+ len, &avail);
+ if (p == NULL)
+ return (0);
+ } while (p[len - 1] != 0);
+ }
+
+ /* Optional header CRC */
+ if ((header_flags & 2)) {
+ p = __archive_read_filter_ahead(filter, len + 2, &avail);
+ if (p == NULL)
+ return (0);
+#if 0
+ int hcrc = ((int)p[len + 1] << 8) | (int)p[len];
+ int crc = /* XXX TODO: Compute header CRC. */;
+ if (crc != hcrc)
+ return (0);
+ bits += 16;
+#endif
+ len += 2;
+ }
+
+ if (pbits != NULL)
+ *pbits = bits;
+ return (len);
+}
+
+/*
+ * Bidder just verifies the header and returns the number of verified bits.
+ */
+static int
+gzip_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+ int bits_checked;
+
+ (void)self; /* UNUSED */
+
+ if (peek_at_header(filter, &bits_checked))
+ return (bits_checked);
+ return (0);
+}
+
+
+#ifndef HAVE_ZLIB_H
+
+/*
+ * If we don't have the library on this system, we can't do the
+ * decompression directly. We can, however, try to run "gzip -d"
+ * in case that's available.
+ */
+static int
+gzip_bidder_init(struct archive_read_filter *self)
+{
+ int r;
+
+ r = __archive_read_program(self, "gzip -d");
+ /* 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_GZIP;
+ self->name = "gzip";
+ return (r);
+}
+
+#else
+
+/*
+ * Initialize the filter object.
+ */
+static int
+gzip_bidder_init(struct archive_read_filter *self)
+{
+ struct private_data *state;
+ static const size_t out_block_size = 64 * 1024;
+ void *out_block;
+
+ self->code = ARCHIVE_FILTER_GZIP;
+ self->name = "gzip";
+
+ state = (struct private_data *)calloc(sizeof(*state), 1);
+ out_block = (unsigned char *)malloc(out_block_size);
+ if (state == NULL || out_block == NULL) {
+ free(out_block);
+ free(state);
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate data for gzip decompression");
+ return (ARCHIVE_FATAL);
+ }
+
+ self->data = state;
+ state->out_block_size = out_block_size;
+ state->out_block = out_block;
+ self->read = gzip_filter_read;
+ self->skip = NULL; /* not supported */
+ self->close = gzip_filter_close;
+
+ state->in_stream = 0; /* We're not actually within a stream yet. */
+
+ return (ARCHIVE_OK);
+}
+
+static int
+consume_header(struct archive_read_filter *self)
+{
+ struct private_data *state;
+ ssize_t avail;
+ size_t len;
+ int ret;
+
+ state = (struct private_data *)self->data;
+
+ /* If this is a real header, consume it. */
+ len = peek_at_header(self->upstream, NULL);
+ if (len == 0)
+ return (ARCHIVE_EOF);
+ __archive_read_filter_consume(self->upstream, len);
+
+ /* Initialize CRC accumulator. */
+ state->crc = crc32(0L, NULL, 0);
+
+ /* Initialize compression library. */
+ state->stream.next_in = (unsigned char *)(uintptr_t)
+ __archive_read_filter_ahead(self->upstream, 1, &avail);
+ state->stream.avail_in = (uInt)avail;
+ ret = inflateInit2(&(state->stream),
+ -15 /* Don't check for zlib header */);
+
+ /* Decipher the error code. */
+ switch (ret) {
+ case Z_OK:
+ state->in_stream = 1;
+ return (ARCHIVE_OK);
+ case Z_STREAM_ERROR:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ "invalid setup parameter");
+ break;
+ case Z_MEM_ERROR:
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Internal error initializing compression library: "
+ "out of memory");
+ break;
+ case Z_VERSION_ERROR:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ "invalid library version");
+ break;
+ default:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ " Zlib error %d", ret);
+ break;
+ }
+ return (ARCHIVE_FATAL);
+}
+
+static int
+consume_trailer(struct archive_read_filter *self)
+{
+ struct private_data *state;
+ const unsigned char *p;
+ ssize_t avail;
+
+ state = (struct private_data *)self->data;
+
+ state->in_stream = 0;
+ switch (inflateEnd(&(state->stream))) {
+ case Z_OK:
+ break;
+ default:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up gzip decompressor");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* GZip trailer is a fixed 8 byte structure. */
+ p = __archive_read_filter_ahead(self->upstream, 8, &avail);
+ if (p == NULL || avail == 0)
+ return (ARCHIVE_FATAL);
+
+ /* XXX TODO: Verify the length and CRC. */
+
+ /* We've verified the trailer, so consume it now. */
+ __archive_read_filter_consume(self->upstream, 8);
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+gzip_filter_read(struct archive_read_filter *self, const void **p)
+{
+ struct private_data *state;
+ size_t decompressed;
+ ssize_t avail_in;
+ int ret;
+
+ state = (struct private_data *)self->data;
+
+ /* Empty our output buffer. */
+ state->stream.next_out = state->out_block;
+ state->stream.avail_out = (uInt)state->out_block_size;
+
+ /* Try to fill the output buffer. */
+ while (state->stream.avail_out > 0 && !state->eof) {
+ /* If we're not in a stream, read a header
+ * and initialize the decompression library. */
+ if (!state->in_stream) {
+ ret = consume_header(self);
+ if (ret == ARCHIVE_EOF) {
+ state->eof = 1;
+ break;
+ }
+ if (ret < ARCHIVE_OK)
+ return (ret);
+ }
+
+ /* Peek at the next available data. */
+ /* ZLib treats stream.next_in as const but doesn't declare
+ * it so, hence this ugly cast. */
+ state->stream.next_in = (unsigned char *)(uintptr_t)
+ __archive_read_filter_ahead(self->upstream, 1, &avail_in);
+ if (state->stream.next_in == NULL) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "truncated gzip input");
+ return (ARCHIVE_FATAL);
+ }
+ state->stream.avail_in = (uInt)avail_in;
+
+ /* Decompress and consume some of that data. */
+ ret = inflate(&(state->stream), 0);
+ switch (ret) {
+ case Z_OK: /* Decompressor made some progress. */
+ __archive_read_filter_consume(self->upstream,
+ avail_in - state->stream.avail_in);
+ break;
+ case Z_STREAM_END: /* Found end of stream. */
+ __archive_read_filter_consume(self->upstream,
+ avail_in - state->stream.avail_in);
+ /* Consume the stream trailer; release the
+ * decompression library. */
+ ret = consume_trailer(self);
+ if (ret < ARCHIVE_OK)
+ return (ret);
+ break;
+ default:
+ /* Return an error. */
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "gzip decompression failed");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ /* We've read as much as we can. */
+ decompressed = state->stream.next_out - state->out_block;
+ state->total_out += decompressed;
+ if (decompressed == 0)
+ *p = NULL;
+ else
+ *p = state->out_block;
+ return (decompressed);
+}
+
+/*
+ * Clean up the decompressor.
+ */
+static int
+gzip_filter_close(struct archive_read_filter *self)
+{
+ struct private_data *state;
+ int ret;
+
+ state = (struct private_data *)self->data;
+ ret = ARCHIVE_OK;
+
+ if (state->in_stream) {
+ switch (inflateEnd(&(state->stream))) {
+ case Z_OK:
+ break;
+ default:
+ archive_set_error(&(self->archive->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up gzip compressor");
+ ret = ARCHIVE_FATAL;
+ }
+ }
+
+ free(state->out_block);
+ free(state);
+ return (ret);
+}
+
+#endif /* HAVE_ZLIB_H */
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lrzip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lrzip.c
new file mode 100644
index 0000000000..c82a8e2f13
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lrzip.c
@@ -0,0 +1,132 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+#define LRZIP_HEADER_MAGIC "LRZI"
+#define LRZIP_HEADER_MAGIC_LEN 4
+
+static int lrzip_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *);
+static int lrzip_bidder_init(struct archive_read_filter *);
+
+
+static int
+lrzip_reader_free(struct archive_read_filter_bidder *self)
+{
+ (void)self; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_support_filter_lrzip(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_lrzip");
+
+ if (__archive_read_get_bidder(a, &reader) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ reader->data = NULL;
+ reader->name = "lrzip";
+ reader->bid = lrzip_bidder_bid;
+ reader->init = lrzip_bidder_init;
+ reader->options = NULL;
+ reader->free = lrzip_reader_free;
+ /* This filter always uses an external program. */
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external lrzip program for lrzip decompression");
+ return (ARCHIVE_WARN);
+}
+
+/*
+ * Bidder just verifies the header and returns the number of verified bits.
+ */
+static int
+lrzip_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+ const unsigned char *p;
+ ssize_t avail, len;
+ int i;
+
+ (void)self; /* UNUSED */
+ /* Start by looking at the first six bytes of the header, which
+ * is all fixed layout. */
+ len = 6;
+ p = __archive_read_filter_ahead(filter, len, &avail);
+ if (p == NULL || avail == 0)
+ return (0);
+
+ if (memcmp(p, LRZIP_HEADER_MAGIC, LRZIP_HEADER_MAGIC_LEN))
+ return (0);
+
+ /* current major version is always 0, verify this */
+ if (p[LRZIP_HEADER_MAGIC_LEN])
+ return 0;
+ /* support only v0.6+ lrzip for sanity */
+ i = p[LRZIP_HEADER_MAGIC_LEN + 1];
+ if ((i < 6) || (i > 10))
+ return 0;
+
+ return (int)len;
+}
+
+static int
+lrzip_bidder_init(struct archive_read_filter *self)
+{
+ int r;
+
+ r = __archive_read_program(self, "lrzip -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_LRZIP;
+ self->name = "lrzip";
+ return (r);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c
new file mode 100644
index 0000000000..9ef20549ba
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c
@@ -0,0 +1,487 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 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_UNISTD_H
+#include <unistd.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_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_LZO_LZOCONF_H
+#include <lzo/lzoconf.h>
+#endif
+#ifdef HAVE_LZO_LZO1X_H
+#include <lzo/lzo1x.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h> /* for crc32 and adler32 */
+#endif
+
+#include "archive.h"
+#if !defined(HAVE_ZLIB_H) &&\
+ defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
+#include "archive_crc32.h"
+#endif
+#include "archive_endian.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+#ifndef HAVE_ZLIB_H
+#define adler32 lzo_adler32
+#endif
+
+#define LZOP_HEADER_MAGIC "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a"
+#define LZOP_HEADER_MAGIC_LEN 9
+
+#if defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
+struct read_lzop {
+ unsigned char *out_block;
+ size_t out_block_size;
+ int64_t total_out;
+ int flags;
+ uint32_t compressed_cksum;
+ uint32_t uncompressed_cksum;
+ size_t compressed_size;
+ size_t uncompressed_size;
+ size_t unconsumed_bytes;
+ char in_stream;
+ char eof; /* True = found end of compressed data. */
+};
+
+#define FILTER 0x0800
+#define CRC32_HEADER 0x1000
+#define EXTRA_FIELD 0x0040
+#define ADLER32_UNCOMPRESSED 0x0001
+#define ADLER32_COMPRESSED 0x0002
+#define CRC32_UNCOMPRESSED 0x0100
+#define CRC32_COMPRESSED 0x0200
+#define MAX_BLOCK_SIZE (64 * 1024 * 1024)
+
+static ssize_t lzop_filter_read(struct archive_read_filter *, const void **);
+static int lzop_filter_close(struct archive_read_filter *);
+#endif
+
+static int lzop_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *);
+static int lzop_bidder_init(struct archive_read_filter *);
+
+int
+archive_read_support_filter_lzop(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_lzop");
+
+ if (__archive_read_get_bidder(a, &reader) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ reader->data = NULL;
+ reader->bid = lzop_bidder_bid;
+ reader->init = lzop_bidder_init;
+ reader->options = NULL;
+ reader->free = NULL;
+ /* Signal the extent of lzop support with the return value here. */
+#if defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
+ return (ARCHIVE_OK);
+#else
+ /* Return ARCHIVE_WARN since this always uses an external program. */
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external lzop program for lzop decompression");
+ return (ARCHIVE_WARN);
+#endif
+}
+
+/*
+ * Bidder just verifies the header and returns the number of verified bits.
+ */
+static int
+lzop_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+ const unsigned char *p;
+ ssize_t avail;
+
+ (void)self; /* UNUSED */
+
+ p = __archive_read_filter_ahead(filter, LZOP_HEADER_MAGIC_LEN, &avail);
+ if (p == NULL || avail == 0)
+ return (0);
+
+ if (memcmp(p, LZOP_HEADER_MAGIC, LZOP_HEADER_MAGIC_LEN))
+ return (0);
+
+ return (LZOP_HEADER_MAGIC_LEN * 8);
+}
+
+#if !defined(HAVE_LZO_LZOCONF_H) || !defined(HAVE_LZO_LZO1X_H)
+/*
+ * If we don't have the library on this system, we can't do the
+ * decompression directly. We can, however, try to run "lzop -d"
+ * in case that's available.
+ */
+static int
+lzop_bidder_init(struct archive_read_filter *self)
+{
+ int r;
+
+ r = __archive_read_program(self, "lzop -d");
+ /* 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_LZOP;
+ self->name = "lzop";
+ return (r);
+}
+#else
+/*
+ * Initialize the filter object.
+ */
+static int
+lzop_bidder_init(struct archive_read_filter *self)
+{
+ struct read_lzop *state;
+
+ self->code = ARCHIVE_FILTER_LZOP;
+ self->name = "lzop";
+
+ state = (struct read_lzop *)calloc(sizeof(*state), 1);
+ if (state == NULL) {
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate data for lzop decompression");
+ return (ARCHIVE_FATAL);
+ }
+
+ self->data = state;
+ self->read = lzop_filter_read;
+ self->skip = NULL; /* not supported */
+ self->close = lzop_filter_close;
+
+ return (ARCHIVE_OK);
+}
+
+static int
+consume_header(struct archive_read_filter *self)
+{
+ struct read_lzop *state = (struct read_lzop *)self->data;
+ const unsigned char *p, *_p;
+ unsigned checksum, flags, len, method, version;
+
+ /*
+ * Check LZOP magic code.
+ */
+ p = __archive_read_filter_ahead(self->upstream,
+ LZOP_HEADER_MAGIC_LEN, NULL);
+ if (p == NULL)
+ return (ARCHIVE_EOF);
+
+ if (memcmp(p, LZOP_HEADER_MAGIC, LZOP_HEADER_MAGIC_LEN))
+ return (ARCHIVE_EOF);
+ __archive_read_filter_consume(self->upstream,
+ LZOP_HEADER_MAGIC_LEN);
+
+ p = __archive_read_filter_ahead(self->upstream, 29, NULL);
+ if (p == NULL)
+ goto truncated;
+ _p = p;
+ version = archive_be16dec(p);
+ p += 4;/* version(2 bytes) + library version(2 bytes) */
+
+ if (version >= 0x940) {
+ unsigned reqversion = archive_be16dec(p); p += 2;
+ if (reqversion < 0x900) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC, "Invalid required version");
+ return (ARCHIVE_FAILED);
+ }
+ }
+
+ method = *p++;
+ if (method < 1 || method > 3) {
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+ "Unsupported method");
+ return (ARCHIVE_FAILED);
+ }
+
+ if (version >= 0x940) {
+ unsigned level = *p++;
+ unsigned default_level[] = {0, 3, 1, 9};
+ if (level == 0)
+ /* Method is 1..3 here due to check above. */
+ level = default_level[method];
+ else if (level > 9) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC, "Invalid level");
+ return (ARCHIVE_FAILED);
+ }
+ }
+
+ flags = archive_be32dec(p); p += 4;
+
+ if (flags & FILTER)
+ p += 4; /* Skip filter */
+ p += 4; /* Skip mode */
+ if (version >= 0x940)
+ p += 8; /* Skip mtime */
+ else
+ p += 4; /* Skip mtime */
+ len = *p++; /* Read filename length */
+ len += p - _p;
+ /* Make sure we have all bytes we need to calculate checksum. */
+ p = __archive_read_filter_ahead(self->upstream, len + 4, NULL);
+ if (p == NULL)
+ goto truncated;
+ if (flags & CRC32_HEADER)
+ checksum = crc32(crc32(0, NULL, 0), p, len);
+ else
+ checksum = adler32(adler32(0, NULL, 0), p, len);
+ if (archive_be32dec(p + len) != checksum)
+ goto corrupted;
+ __archive_read_filter_consume(self->upstream, len + 4);
+ if (flags & EXTRA_FIELD) {
+ /* Skip extra field */
+ p = __archive_read_filter_ahead(self->upstream, 4, NULL);
+ if (p == NULL)
+ goto truncated;
+ len = archive_be32dec(p);
+ __archive_read_filter_consume(self->upstream, len + 4 + 4);
+ }
+ state->flags = flags;
+ state->in_stream = 1;
+ return (ARCHIVE_OK);
+truncated:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT, "Truncated lzop data");
+ return (ARCHIVE_FAILED);
+corrupted:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT, "Corrupted lzop header");
+ return (ARCHIVE_FAILED);
+}
+
+static int
+consume_block_info(struct archive_read_filter *self)
+{
+ struct read_lzop *state = (struct read_lzop *)self->data;
+ const unsigned char *p;
+ unsigned flags = state->flags;
+
+ p = __archive_read_filter_ahead(self->upstream, 4, NULL);
+ if (p == NULL)
+ goto truncated;
+ state->uncompressed_size = archive_be32dec(p);
+ __archive_read_filter_consume(self->upstream, 4);
+ if (state->uncompressed_size == 0)
+ return (ARCHIVE_EOF);
+ if (state->uncompressed_size > MAX_BLOCK_SIZE)
+ goto corrupted;
+
+ p = __archive_read_filter_ahead(self->upstream, 4, NULL);
+ if (p == NULL)
+ goto truncated;
+ state->compressed_size = archive_be32dec(p);
+ __archive_read_filter_consume(self->upstream, 4);
+ if (state->compressed_size > state->uncompressed_size)
+ goto corrupted;
+
+ if (flags & (CRC32_UNCOMPRESSED | ADLER32_UNCOMPRESSED)) {
+ p = __archive_read_filter_ahead(self->upstream, 4, NULL);
+ if (p == NULL)
+ goto truncated;
+ state->compressed_cksum = state->uncompressed_cksum =
+ archive_be32dec(p);
+ __archive_read_filter_consume(self->upstream, 4);
+ }
+ if ((flags & (CRC32_COMPRESSED | ADLER32_COMPRESSED)) &&
+ state->compressed_size < state->uncompressed_size) {
+ p = __archive_read_filter_ahead(self->upstream, 4, NULL);
+ if (p == NULL)
+ goto truncated;
+ state->compressed_cksum = archive_be32dec(p);
+ __archive_read_filter_consume(self->upstream, 4);
+ }
+ return (ARCHIVE_OK);
+truncated:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT, "Truncated lzop data");
+ return (ARCHIVE_FAILED);
+corrupted:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT, "Corrupted lzop header");
+ return (ARCHIVE_FAILED);
+}
+
+static ssize_t
+lzop_filter_read(struct archive_read_filter *self, const void **p)
+{
+ struct read_lzop *state = (struct read_lzop *)self->data;
+ const void *b;
+ lzo_uint out_size;
+ uint32_t cksum;
+ int ret, r;
+
+ if (state->unconsumed_bytes) {
+ __archive_read_filter_consume(self->upstream,
+ state->unconsumed_bytes);
+ state->unconsumed_bytes = 0;
+ }
+ if (state->eof)
+ return (0);
+
+ for (;;) {
+ if (!state->in_stream) {
+ ret = consume_header(self);
+ if (ret < ARCHIVE_OK)
+ return (ret);
+ if (ret == ARCHIVE_EOF) {
+ state->eof = 1;
+ return (0);
+ }
+ }
+ ret = consume_block_info(self);
+ if (ret < ARCHIVE_OK)
+ return (ret);
+ if (ret == ARCHIVE_EOF)
+ state->in_stream = 0;
+ else
+ break;
+ }
+
+ if (state->out_block == NULL ||
+ state->out_block_size < state->uncompressed_size) {
+ void *new_block;
+
+ new_block = realloc(state->out_block, state->uncompressed_size);
+ if (new_block == NULL) {
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate data for lzop decompression");
+ return (ARCHIVE_FATAL);
+ }
+ state->out_block = new_block;
+ state->out_block_size = state->uncompressed_size;
+ }
+
+ b = __archive_read_filter_ahead(self->upstream,
+ state->compressed_size, NULL);
+ if (b == NULL) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT, "Truncated lzop data");
+ return (ARCHIVE_FATAL);
+ }
+ if (state->flags & CRC32_COMPRESSED)
+ cksum = crc32(crc32(0, NULL, 0), b, state->compressed_size);
+ else if (state->flags & ADLER32_COMPRESSED)
+ cksum = adler32(adler32(0, NULL, 0), b, state->compressed_size);
+ else
+ cksum = state->compressed_cksum;
+ if (cksum != state->compressed_cksum) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC, "Corrupted data");
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * If the both uncompressed size and compressed size are the same,
+ * we do not decompress this block.
+ */
+ if (state->uncompressed_size == state->compressed_size) {
+ *p = b;
+ state->total_out += state->compressed_size;
+ state->unconsumed_bytes = state->compressed_size;
+ return ((ssize_t)state->uncompressed_size);
+ }
+
+ /*
+ * Drive lzo uncompresison.
+ */
+ out_size = (lzo_uint)state->uncompressed_size;
+ r = lzo1x_decompress_safe(b, (lzo_uint)state->compressed_size,
+ state->out_block, &out_size, NULL);
+ switch (r) {
+ case LZO_E_OK:
+ if (out_size == state->uncompressed_size)
+ break;
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC, "Corrupted data");
+ return (ARCHIVE_FATAL);
+ case LZO_E_OUT_OF_MEMORY:
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "lzop decompression failed: out of memory");
+ return (ARCHIVE_FATAL);
+ default:
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+ "lzop decompression failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+
+ if (state->flags & CRC32_UNCOMPRESSED)
+ cksum = crc32(crc32(0, NULL, 0), state->out_block,
+ state->uncompressed_size);
+ else if (state->flags & ADLER32_UNCOMPRESSED)
+ cksum = adler32(adler32(0, NULL, 0), state->out_block,
+ state->uncompressed_size);
+ else
+ cksum = state->uncompressed_cksum;
+ if (cksum != state->uncompressed_cksum) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC, "Corrupted data");
+ return (ARCHIVE_FATAL);
+ }
+
+ __archive_read_filter_consume(self->upstream, state->compressed_size);
+ *p = state->out_block;
+ state->total_out += out_size;
+ return ((ssize_t)out_size);
+}
+
+/*
+ * Clean up the decompressor.
+ */
+static int
+lzop_filter_close(struct archive_read_filter *self)
+{
+ struct read_lzop *state = (struct read_lzop *)self->data;
+
+ free(state->out_block);
+ free(state);
+ return (ARCHIVE_OK);
+}
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_none.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_none.c
new file mode 100644
index 0000000000..95e5cfdb15
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_none.c
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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$");
+
+#include "archive.h"
+#include "archive_private.h"
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Deprecated; remove in libarchive 4.0 */
+int
+archive_read_support_compression_none(struct archive *a)
+{
+ return archive_read_support_filter_none(a);
+}
+#endif
+
+/*
+ * Uncompressed streams are handled implicitly by the read core,
+ * so this is now a no-op.
+ */
+int
+archive_read_support_filter_none(struct archive *a)
+{
+ archive_check_magic(a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_filter_none");
+
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c
new file mode 100644
index 0000000000..66dc2f424f
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c
@@ -0,0 +1,516 @@
+/*-
+ * Copyright (c) 2007 Joerg Sonnenberger
+ * Copyright (c) 2012 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_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+#ifdef HAVE_ERRNO_H
+# include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#ifdef HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_string.h"
+#include "archive_read_private.h"
+#include "filter_fork.h"
+
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Deprecated; remove in libarchive 4.0 */
+int
+archive_read_support_compression_program(struct archive *a, const char *cmd)
+{
+ return archive_read_support_filter_program(a, cmd);
+}
+
+int
+archive_read_support_compression_program_signature(struct archive *a,
+ const char *cmd, const void *signature, size_t signature_len)
+{
+ return archive_read_support_filter_program_signature(a,
+ cmd, signature, signature_len);
+}
+#endif
+
+int
+archive_read_support_filter_program(struct archive *a, const char *cmd)
+{
+ return (archive_read_support_filter_program_signature(a, cmd, NULL, 0));
+}
+
+/*
+ * The bidder object stores the command and the signature to watch for.
+ * The 'inhibit' entry here is used to ensure that unchecked filters never
+ * bid twice in the same pipeline.
+ */
+struct program_bidder {
+ char *description;
+ char *cmd;
+ void *signature;
+ size_t signature_len;
+ int inhibit;
+};
+
+static int program_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *upstream);
+static int program_bidder_init(struct archive_read_filter *);
+static int program_bidder_free(struct archive_read_filter_bidder *);
+
+/*
+ * The actual filter needs to track input and output data.
+ */
+struct program_filter {
+ struct archive_string description;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ HANDLE child;
+#else
+ pid_t child;
+#endif
+ int exit_status;
+ int waitpid_return;
+ int child_stdin, child_stdout;
+
+ char *out_buf;
+ size_t out_buf_len;
+};
+
+static ssize_t program_filter_read(struct archive_read_filter *,
+ const void **);
+static int program_filter_close(struct archive_read_filter *);
+static void free_state(struct program_bidder *);
+
+static int
+set_bidder_signature(struct archive_read_filter_bidder *bidder,
+ struct program_bidder *state, const void *signature, size_t signature_len)
+{
+
+ if (signature != NULL && signature_len > 0) {
+ state->signature_len = signature_len;
+ state->signature = malloc(signature_len);
+ memcpy(state->signature, signature, signature_len);
+ }
+
+ /*
+ * Fill in the bidder object.
+ */
+ bidder->data = state;
+ bidder->bid = program_bidder_bid;
+ bidder->init = program_bidder_init;
+ bidder->options = NULL;
+ bidder->free = program_bidder_free;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_support_filter_program_signature(struct archive *_a,
+ const char *cmd, const void *signature, size_t signature_len)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter_bidder *bidder;
+ struct program_bidder *state;
+
+ /*
+ * Get a bidder object from the read core.
+ */
+ if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /*
+ * Allocate our private state.
+ */
+ state = (struct program_bidder *)calloc(1, sizeof (*state));
+ if (state == NULL)
+ goto memerr;
+ state->cmd = strdup(cmd);
+ if (state->cmd == NULL)
+ goto memerr;
+
+ return set_bidder_signature(bidder, state, signature, signature_len);
+memerr:
+ free_state(state);
+ archive_set_error(_a, ENOMEM, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+program_bidder_free(struct archive_read_filter_bidder *self)
+{
+ struct program_bidder *state = (struct program_bidder *)self->data;
+
+ free_state(state);
+ return (ARCHIVE_OK);
+}
+
+static void
+free_state(struct program_bidder *state)
+{
+
+ if (state) {
+ free(state->cmd);
+ free(state->signature);
+ free(state);
+ }
+}
+
+/*
+ * If we do have a signature, bid only if that matches.
+ *
+ * If there's no signature, we bid INT_MAX the first time
+ * we're called, then never bid again.
+ */
+static int
+program_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *upstream)
+{
+ struct program_bidder *state = self->data;
+ const char *p;
+
+ /* If we have a signature, use that to match. */
+ if (state->signature_len > 0) {
+ p = __archive_read_filter_ahead(upstream,
+ state->signature_len, NULL);
+ if (p == NULL)
+ return (0);
+ /* No match, so don't bid. */
+ if (memcmp(p, state->signature, state->signature_len) != 0)
+ return (0);
+ return ((int)state->signature_len * 8);
+ }
+
+ /* Otherwise, bid once and then never bid again. */
+ if (state->inhibit)
+ return (0);
+ state->inhibit = 1;
+ return (INT_MAX);
+}
+
+/*
+ * Shut down the child, return ARCHIVE_OK if it exited normally.
+ *
+ * Note that the return value is sticky; if we're called again,
+ * we won't reap the child again, but we will return the same status
+ * (including error message if the child came to a bad end).
+ */
+static int
+child_stop(struct archive_read_filter *self, struct program_filter *state)
+{
+ /* Close our side of the I/O with the child. */
+ if (state->child_stdin != -1) {
+ close(state->child_stdin);
+ state->child_stdin = -1;
+ }
+ if (state->child_stdout != -1) {
+ close(state->child_stdout);
+ state->child_stdout = -1;
+ }
+
+ if (state->child != 0) {
+ /* Reap the child. */
+ do {
+ state->waitpid_return
+ = waitpid(state->child, &state->exit_status, 0);
+ } while (state->waitpid_return == -1 && errno == EINTR);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ CloseHandle(state->child);
+#endif
+ state->child = 0;
+ }
+
+ if (state->waitpid_return < 0) {
+ /* waitpid() failed? This is ugly. */
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+ "Child process exited badly");
+ return (ARCHIVE_WARN);
+ }
+
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ if (WIFSIGNALED(state->exit_status)) {
+#ifdef SIGPIPE
+ /* If the child died because we stopped reading before
+ * it was done, that's okay. Some archive formats
+ * have padding at the end that we routinely ignore. */
+ /* The alternative to this would be to add a step
+ * before close(child_stdout) above to read from the
+ * child until the child has no more to write. */
+ if (WTERMSIG(state->exit_status) == SIGPIPE)
+ return (ARCHIVE_OK);
+#endif
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+ "Child process exited with signal %d",
+ WTERMSIG(state->exit_status));
+ return (ARCHIVE_WARN);
+ }
+#endif /* !_WIN32 || __CYGWIN__ */
+
+ if (WIFEXITED(state->exit_status)) {
+ if (WEXITSTATUS(state->exit_status) == 0)
+ return (ARCHIVE_OK);
+
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Child process exited with status %d",
+ WEXITSTATUS(state->exit_status));
+ return (ARCHIVE_WARN);
+ }
+
+ return (ARCHIVE_WARN);
+}
+
+/*
+ * Use select() to decide whether the child is ready for read or write.
+ */
+static ssize_t
+child_read(struct archive_read_filter *self, char *buf, size_t buf_len)
+{
+ struct program_filter *state = self->data;
+ ssize_t ret, requested, avail;
+ const char *p;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ HANDLE handle = (HANDLE)_get_osfhandle(state->child_stdout);
+#endif
+
+ requested = buf_len > SSIZE_MAX ? SSIZE_MAX : buf_len;
+
+ for (;;) {
+ do {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Avoid infinity wait.
+ * Note: If there is no data in the pipe, ReadFile()
+ * called in read() never returns and so we won't
+ * write remaining encoded data to the pipe.
+ * Note: This way may cause performance problem.
+ * we are looking forward to great code to resolve
+ * this. */
+ DWORD pipe_avail = -1;
+ int cnt = 2;
+
+ while (PeekNamedPipe(handle, NULL, 0, NULL,
+ &pipe_avail, NULL) != 0 && pipe_avail == 0 &&
+ cnt--)
+ Sleep(5);
+ if (pipe_avail == 0) {
+ ret = -1;
+ errno = EAGAIN;
+ break;
+ }
+#endif
+ ret = read(state->child_stdout, buf, requested);
+ } while (ret == -1 && errno == EINTR);
+
+ if (ret > 0)
+ return (ret);
+ if (ret == 0 || (ret == -1 && errno == EPIPE))
+ /* Child has closed its output; reap the child
+ * and return the status. */
+ return (child_stop(self, state));
+ if (ret == -1 && errno != EAGAIN)
+ return (-1);
+
+ if (state->child_stdin == -1) {
+ /* Block until child has some I/O ready. */
+ __archive_check_child(state->child_stdin,
+ state->child_stdout);
+ continue;
+ }
+
+ /* Get some more data from upstream. */
+ p = __archive_read_filter_ahead(self->upstream, 1, &avail);
+ if (p == NULL) {
+ close(state->child_stdin);
+ state->child_stdin = -1;
+ fcntl(state->child_stdout, F_SETFL, 0);
+ if (avail < 0)
+ return (avail);
+ continue;
+ }
+
+ do {
+ ret = write(state->child_stdin, p, avail);
+ } while (ret == -1 && errno == EINTR);
+
+ if (ret > 0) {
+ /* Consume whatever we managed to write. */
+ __archive_read_filter_consume(self->upstream, ret);
+ } else if (ret == -1 && errno == EAGAIN) {
+ /* Block until child has some I/O ready. */
+ __archive_check_child(state->child_stdin,
+ state->child_stdout);
+ } else {
+ /* Write failed. */
+ close(state->child_stdin);
+ state->child_stdin = -1;
+ fcntl(state->child_stdout, F_SETFL, 0);
+ /* If it was a bad error, we're done; otherwise
+ * it was EPIPE or EOF, and we can still read
+ * from the child. */
+ if (ret == -1 && errno != EPIPE)
+ return (-1);
+ }
+ }
+}
+
+int
+__archive_read_program(struct archive_read_filter *self, const char *cmd)
+{
+ struct program_filter *state;
+ static const size_t out_buf_len = 65536;
+ char *out_buf;
+ const char *prefix = "Program: ";
+ pid_t child;
+ size_t l;
+
+ l = strlen(prefix) + strlen(cmd) + 1;
+ state = (struct program_filter *)calloc(1, sizeof(*state));
+ out_buf = (char *)malloc(out_buf_len);
+ if (state == NULL || out_buf == NULL ||
+ archive_string_ensure(&state->description, l) == NULL) {
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate input data");
+ if (state != NULL) {
+ archive_string_free(&state->description);
+ free(state);
+ }
+ free(out_buf);
+ return (ARCHIVE_FATAL);
+ }
+ archive_strcpy(&state->description, prefix);
+ archive_strcat(&state->description, cmd);
+
+ self->code = ARCHIVE_FILTER_PROGRAM;
+ self->name = state->description.s;
+
+ state->out_buf = out_buf;
+ state->out_buf_len = out_buf_len;
+
+ child = __archive_create_child(cmd, &state->child_stdin,
+ &state->child_stdout);
+ if (child == -1) {
+ free(state->out_buf);
+ free(state);
+ archive_set_error(&self->archive->archive, EINVAL,
+ "Can't initialize filter; unable to run program \"%s\"",
+ cmd);
+ return (ARCHIVE_FATAL);
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ state->child = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, child);
+ if (state->child == NULL) {
+ child_stop(self, state);
+ free(state->out_buf);
+ free(state);
+ archive_set_error(&self->archive->archive, EINVAL,
+ "Can't initialize filter; unable to run program \"%s\"",
+ cmd);
+ return (ARCHIVE_FATAL);
+ }
+#else
+ state->child = child;
+#endif
+
+ self->data = state;
+ self->read = program_filter_read;
+ self->skip = NULL;
+ self->close = program_filter_close;
+
+ /* XXX Check that we can read at least one byte? */
+ return (ARCHIVE_OK);
+}
+
+static int
+program_bidder_init(struct archive_read_filter *self)
+{
+ struct program_bidder *bidder_state;
+
+ bidder_state = (struct program_bidder *)self->bidder->data;
+ return (__archive_read_program(self, bidder_state->cmd));
+}
+
+static ssize_t
+program_filter_read(struct archive_read_filter *self, const void **buff)
+{
+ struct program_filter *state;
+ ssize_t bytes;
+ size_t total;
+ char *p;
+
+ state = (struct program_filter *)self->data;
+
+ total = 0;
+ p = state->out_buf;
+ while (state->child_stdout != -1 && total < state->out_buf_len) {
+ bytes = child_read(self, p, state->out_buf_len - total);
+ if (bytes < 0)
+ /* No recovery is possible if we can no longer
+ * read from the child. */
+ return (ARCHIVE_FATAL);
+ if (bytes == 0)
+ /* We got EOF from the child. */
+ break;
+ total += bytes;
+ p += bytes;
+ }
+
+ *buff = state->out_buf;
+ return (total);
+}
+
+static int
+program_filter_close(struct archive_read_filter *self)
+{
+ struct program_filter *state;
+ int e;
+
+ state = (struct program_filter *)self->data;
+ e = child_stop(self, state);
+
+ /* Release our private data. */
+ free(state->out_buf);
+ archive_string_free(&state->description);
+ free(state);
+
+ return (e);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_rpm.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_rpm.c
new file mode 100644
index 0000000000..e7e58e51f3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_rpm.c
@@ -0,0 +1,289 @@
+/*-
+ * Copyright (c) 2009 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_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_endian.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+struct rpm {
+ int64_t total_in;
+ size_t hpos;
+ size_t hlen;
+ unsigned char header[16];
+ enum {
+ ST_LEAD, /* Skipping 'Lead' section. */
+ ST_HEADER, /* Reading 'Header' section;
+ * first 16 bytes. */
+ ST_HEADER_DATA, /* Skipping 'Header' section. */
+ ST_PADDING, /* Skipping padding data after the
+ * 'Header' section. */
+ ST_ARCHIVE /* Reading 'Archive' section. */
+ } state;
+ int first_header;
+};
+#define RPM_LEAD_SIZE 96 /* Size of 'Lead' section. */
+
+static int rpm_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *);
+static int rpm_bidder_init(struct archive_read_filter *);
+
+static ssize_t rpm_filter_read(struct archive_read_filter *,
+ const void **);
+static int rpm_filter_close(struct archive_read_filter *);
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Deprecated; remove in libarchive 4.0 */
+int
+archive_read_support_compression_rpm(struct archive *a)
+{
+ return archive_read_support_filter_rpm(a);
+}
+#endif
+
+int
+archive_read_support_filter_rpm(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter_bidder *bidder;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_filter_rpm");
+
+ if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ bidder->data = NULL;
+ bidder->name = "rpm";
+ bidder->bid = rpm_bidder_bid;
+ bidder->init = rpm_bidder_init;
+ bidder->options = NULL;
+ bidder->free = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+rpm_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+ const unsigned char *b;
+ ssize_t avail;
+ int bits_checked;
+
+ (void)self; /* UNUSED */
+
+ b = __archive_read_filter_ahead(filter, 8, &avail);
+ if (b == NULL)
+ return (0);
+
+ bits_checked = 0;
+ /*
+ * Verify Header Magic Bytes : 0XED 0XAB 0XEE 0XDB
+ */
+ if (memcmp(b, "\xED\xAB\xEE\xDB", 4) != 0)
+ return (0);
+ bits_checked += 32;
+ /*
+ * Check major version.
+ */
+ if (b[4] != 3 && b[4] != 4)
+ return (0);
+ bits_checked += 8;
+ /*
+ * Check package type; binary or source.
+ */
+ if (b[6] != 0)
+ return (0);
+ bits_checked += 8;
+ if (b[7] != 0 && b[7] != 1)
+ return (0);
+ bits_checked += 8;
+
+ return (bits_checked);
+}
+
+static int
+rpm_bidder_init(struct archive_read_filter *self)
+{
+ struct rpm *rpm;
+
+ self->code = ARCHIVE_FILTER_RPM;
+ self->name = "rpm";
+ self->read = rpm_filter_read;
+ self->skip = NULL; /* not supported */
+ self->close = rpm_filter_close;
+
+ rpm = (struct rpm *)calloc(sizeof(*rpm), 1);
+ if (rpm == NULL) {
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate data for rpm");
+ return (ARCHIVE_FATAL);
+ }
+
+ self->data = rpm;
+ rpm->state = ST_LEAD;
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+rpm_filter_read(struct archive_read_filter *self, const void **buff)
+{
+ struct rpm *rpm;
+ const unsigned char *b;
+ ssize_t avail_in, total;
+ size_t used, n;
+ uint32_t section;
+ uint32_t bytes;
+
+ rpm = (struct rpm *)self->data;
+ *buff = NULL;
+ total = avail_in = 0;
+ b = NULL;
+ used = 0;
+ do {
+ if (b == NULL) {
+ b = __archive_read_filter_ahead(self->upstream, 1,
+ &avail_in);
+ if (b == NULL) {
+ if (avail_in < 0)
+ return (ARCHIVE_FATAL);
+ else
+ break;
+ }
+ }
+
+ switch (rpm->state) {
+ case ST_LEAD:
+ if (rpm->total_in + avail_in < RPM_LEAD_SIZE)
+ used += avail_in;
+ else {
+ n = (size_t)(RPM_LEAD_SIZE - rpm->total_in);
+ used += n;
+ b += n;
+ rpm->state = ST_HEADER;
+ rpm->hpos = 0;
+ rpm->hlen = 0;
+ rpm->first_header = 1;
+ }
+ break;
+ case ST_HEADER:
+ n = 16 - rpm->hpos;
+ if (n > avail_in - used)
+ n = avail_in - used;
+ memcpy(rpm->header+rpm->hpos, b, n);
+ b += n;
+ used += n;
+ rpm->hpos += n;
+
+ if (rpm->hpos == 16) {
+ if (rpm->header[0] != 0x8e ||
+ rpm->header[1] != 0xad ||
+ rpm->header[2] != 0xe8 ||
+ rpm->header[3] != 0x01) {
+ if (rpm->first_header) {
+ archive_set_error(
+ &self->archive->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unrecoginized rpm header");
+ return (ARCHIVE_FATAL);
+ }
+ rpm->state = ST_ARCHIVE;
+ *buff = rpm->header;
+ total = rpm->hpos;
+ break;
+ }
+ /* Calculate 'Header' length. */
+ section = archive_be32dec(rpm->header+8);
+ bytes = archive_be32dec(rpm->header+12);
+ rpm->hlen = 16 + section * 16 + bytes;
+ rpm->state = ST_HEADER_DATA;
+ rpm->first_header = 0;
+ }
+ break;
+ case ST_HEADER_DATA:
+ n = rpm->hlen - rpm->hpos;
+ if (n > avail_in - used)
+ n = avail_in - used;
+ b += n;
+ used += n;
+ rpm->hpos += n;
+ if (rpm->hpos == rpm->hlen)
+ rpm->state = ST_PADDING;
+ break;
+ case ST_PADDING:
+ while (used < (size_t)avail_in) {
+ if (*b != 0) {
+ /* Read next header. */
+ rpm->state = ST_HEADER;
+ rpm->hpos = 0;
+ rpm->hlen = 0;
+ break;
+ }
+ b++;
+ used++;
+ }
+ break;
+ case ST_ARCHIVE:
+ *buff = b;
+ total = avail_in;
+ used = avail_in;
+ break;
+ }
+ if (used == (size_t)avail_in) {
+ rpm->total_in += used;
+ __archive_read_filter_consume(self->upstream, used);
+ b = NULL;
+ used = 0;
+ }
+ } while (total == 0 && avail_in > 0);
+
+ if (used > 0 && b != NULL) {
+ rpm->total_in += used;
+ __archive_read_filter_consume(self->upstream, used);
+ }
+ return (total);
+}
+
+static int
+rpm_filter_close(struct archive_read_filter *self)
+{
+ struct rpm *rpm;
+
+ rpm = (struct rpm *)self->data;
+ free(rpm);
+
+ return (ARCHIVE_OK);
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c
new file mode 100644
index 0000000000..471771b6f4
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c
@@ -0,0 +1,694 @@
+/*-
+ * Copyright (c) 2009-2011 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+/* Maximum lookahead during bid phase */
+#define UUENCODE_BID_MAX_READ 128*1024 /* in bytes */
+
+struct uudecode {
+ int64_t total;
+ unsigned char *in_buff;
+#define IN_BUFF_SIZE (1024)
+ int in_cnt;
+ size_t in_allocated;
+ unsigned char *out_buff;
+#define OUT_BUFF_SIZE (64 * 1024)
+ int state;
+#define ST_FIND_HEAD 0
+#define ST_READ_UU 1
+#define ST_UUEND 2
+#define ST_READ_BASE64 3
+#define ST_IGNORE 4
+};
+
+static int uudecode_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *filter);
+static int uudecode_bidder_init(struct archive_read_filter *);
+
+static ssize_t uudecode_filter_read(struct archive_read_filter *,
+ const void **);
+static int uudecode_filter_close(struct archive_read_filter *);
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Deprecated; remove in libarchive 4.0 */
+int
+archive_read_support_compression_uu(struct archive *a)
+{
+ return archive_read_support_filter_uu(a);
+}
+#endif
+
+int
+archive_read_support_filter_uu(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter_bidder *bidder;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_filter_uu");
+
+ if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ bidder->data = NULL;
+ bidder->name = "uu";
+ bidder->bid = uudecode_bidder_bid;
+ bidder->init = uudecode_bidder_init;
+ bidder->options = NULL;
+ bidder->free = NULL;
+ return (ARCHIVE_OK);
+}
+
+static const unsigned char ascii[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\n', 0, 0, '\r', 0, 0, /* 00 - 0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30 - 3F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, /* 70 - 7F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */
+ 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 */
+};
+
+static const unsigned char uuchar[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30 - 3F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 70 - 7F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */
+ 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 */
+};
+
+static const unsigned char base64[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, /* 20 - 2F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 30 - 3F */
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 50 - 5F */
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 70 - 7F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */
+ 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 */
+};
+
+static const int base64num[128] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 62, 0, 0, 0, 63, /* 20 - 2F */
+ 52, 53, 54, 55, 56, 57, 58, 59,
+ 60, 61, 0, 0, 0, 0, 0, 0, /* 30 - 3F */
+ 0, 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14, /* 40 - 4F */
+ 15, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, 0, 0, 0, 0, 0, /* 50 - 5F */
+ 0, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35, 36, 37, 38, 39, 40, /* 60 - 6F */
+ 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 0, 0, 0, 0, 0, /* 70 - 7F */
+};
+
+static ssize_t
+get_line(const unsigned char *b, ssize_t avail, ssize_t *nlsize)
+{
+ ssize_t len;
+
+ len = 0;
+ while (len < avail) {
+ switch (ascii[*b]) {
+ case 0: /* Non-ascii character or control character. */
+ if (nlsize != NULL)
+ *nlsize = 0;
+ return (-1);
+ case '\r':
+ if (avail-len > 1 && b[1] == '\n') {
+ if (nlsize != NULL)
+ *nlsize = 2;
+ return (len+2);
+ }
+ /* FALL THROUGH */
+ case '\n':
+ if (nlsize != NULL)
+ *nlsize = 1;
+ return (len+1);
+ case 1:
+ b++;
+ len++;
+ break;
+ }
+ }
+ if (nlsize != NULL)
+ *nlsize = 0;
+ return (avail);
+}
+
+static ssize_t
+bid_get_line(struct archive_read_filter *filter,
+ const unsigned char **b, ssize_t *avail, ssize_t *ravail,
+ ssize_t *nl, size_t* nbytes_read)
+{
+ ssize_t len;
+ int quit;
+
+ quit = 0;
+ if (*avail == 0) {
+ *nl = 0;
+ len = 0;
+ } else
+ len = get_line(*b, *avail, nl);
+
+ /*
+ * Read bytes more while it does not reach the end of line.
+ */
+ while (*nl == 0 && len == *avail && !quit &&
+ *nbytes_read < UUENCODE_BID_MAX_READ) {
+ ssize_t diff = *ravail - *avail;
+ size_t nbytes_req = (*ravail+1023) & ~1023U;
+ ssize_t tested;
+
+ /* Increase reading bytes if it is not enough to at least
+ * new two lines. */
+ if (nbytes_req < (size_t)*ravail + 160)
+ nbytes_req <<= 1;
+
+ *b = __archive_read_filter_ahead(filter, nbytes_req, avail);
+ if (*b == NULL) {
+ if (*ravail >= *avail)
+ return (0);
+ /* Reading bytes reaches the end of a stream. */
+ *b = __archive_read_filter_ahead(filter, *avail, avail);
+ quit = 1;
+ }
+ *nbytes_read = *avail;
+ *ravail = *avail;
+ *b += diff;
+ *avail -= diff;
+ tested = len;/* Skip some bytes we already determinated. */
+ len = get_line(*b + tested, *avail - tested, nl);
+ if (len >= 0)
+ len += tested;
+ }
+ return (len);
+}
+
+#define UUDECODE(c) (((c) - 0x20) & 0x3f)
+
+static int
+uudecode_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+ const unsigned char *b;
+ ssize_t avail, ravail;
+ ssize_t len, nl;
+ int l;
+ int firstline;
+ size_t nbytes_read;
+
+ (void)self; /* UNUSED */
+
+ b = __archive_read_filter_ahead(filter, 1, &avail);
+ if (b == NULL)
+ return (0);
+
+ firstline = 20;
+ ravail = avail;
+ nbytes_read = avail;
+ for (;;) {
+ len = bid_get_line(filter, &b, &avail, &ravail, &nl, &nbytes_read);
+ if (len < 0 || nl == 0)
+ return (0); /* No match found. */
+ if (len - nl >= 11 && memcmp(b, "begin ", 6) == 0)
+ l = 6;
+ else if (len -nl >= 18 && memcmp(b, "begin-base64 ", 13) == 0)
+ l = 13;
+ else
+ l = 0;
+
+ if (l > 0 && (b[l] < '0' || b[l] > '7' ||
+ b[l+1] < '0' || b[l+1] > '7' ||
+ b[l+2] < '0' || b[l+2] > '7' || b[l+3] != ' '))
+ l = 0;
+
+ b += len;
+ avail -= len;
+ if (l)
+ break;
+ firstline = 0;
+
+ /* Do not read more than UUENCODE_BID_MAX_READ bytes */
+ if (nbytes_read >= UUENCODE_BID_MAX_READ)
+ return (0);
+ }
+ if (!avail)
+ return (0);
+ len = bid_get_line(filter, &b, &avail, &ravail, &nl, &nbytes_read);
+ if (len < 0 || nl == 0)
+ return (0);/* There are non-ascii characters. */
+ avail -= len;
+
+ if (l == 6) {
+ if (!uuchar[*b])
+ return (0);
+ /* Get a length of decoded bytes. */
+ l = UUDECODE(*b++); len--;
+ if (l > 45)
+ /* Normally, maximum length is 45(character 'M'). */
+ return (0);
+ while (l && len-nl > 0) {
+ if (l > 0) {
+ if (!uuchar[*b++])
+ return (0);
+ if (!uuchar[*b++])
+ return (0);
+ len -= 2;
+ --l;
+ }
+ if (l > 0) {
+ if (!uuchar[*b++])
+ return (0);
+ --len;
+ --l;
+ }
+ if (l > 0) {
+ if (!uuchar[*b++])
+ return (0);
+ --len;
+ --l;
+ }
+ }
+ if (len-nl < 0)
+ return (0);
+ if (len-nl == 1 &&
+ (uuchar[*b] || /* Check sum. */
+ (*b >= 'a' && *b <= 'z'))) {/* Padding data(MINIX). */
+ ++b;
+ --len;
+ }
+ b += nl;
+ if (avail && uuchar[*b])
+ return (firstline+30);
+ }
+ if (l == 13) {
+ while (len-nl > 0) {
+ if (!base64[*b++])
+ return (0);
+ --len;
+ }
+ b += nl;
+
+ if (avail >= 5 && memcmp(b, "====\n", 5) == 0)
+ return (firstline+40);
+ if (avail >= 6 && memcmp(b, "====\r\n", 6) == 0)
+ return (firstline+40);
+ if (avail > 0 && base64[*b])
+ return (firstline+30);
+ }
+
+ return (0);
+}
+
+static int
+uudecode_bidder_init(struct archive_read_filter *self)
+{
+ struct uudecode *uudecode;
+ void *out_buff;
+ void *in_buff;
+
+ self->code = ARCHIVE_FILTER_UU;
+ self->name = "uu";
+ self->read = uudecode_filter_read;
+ self->skip = NULL; /* not supported */
+ self->close = uudecode_filter_close;
+
+ uudecode = (struct uudecode *)calloc(sizeof(*uudecode), 1);
+ out_buff = malloc(OUT_BUFF_SIZE);
+ in_buff = malloc(IN_BUFF_SIZE);
+ if (uudecode == NULL || out_buff == NULL || in_buff == NULL) {
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate data for uudecode");
+ free(uudecode);
+ free(out_buff);
+ free(in_buff);
+ return (ARCHIVE_FATAL);
+ }
+
+ self->data = uudecode;
+ uudecode->in_buff = in_buff;
+ uudecode->in_cnt = 0;
+ uudecode->in_allocated = IN_BUFF_SIZE;
+ uudecode->out_buff = out_buff;
+ uudecode->state = ST_FIND_HEAD;
+
+ return (ARCHIVE_OK);
+}
+
+static int
+ensure_in_buff_size(struct archive_read_filter *self,
+ struct uudecode *uudecode, size_t size)
+{
+
+ if (size > uudecode->in_allocated) {
+ unsigned char *ptr;
+ size_t newsize;
+
+ /*
+ * Calculate a new buffer size for in_buff.
+ * Increase its value until it has enough size we need.
+ */
+ newsize = uudecode->in_allocated;
+ do {
+ if (newsize < IN_BUFF_SIZE*32)
+ newsize <<= 1;
+ else
+ newsize += IN_BUFF_SIZE;
+ } while (size > newsize);
+ /* Allocate the new buffer. */
+ ptr = malloc(newsize);
+ if (ptr == NULL) {
+ free(ptr);
+ archive_set_error(&self->archive->archive,
+ ENOMEM,
+ "Can't allocate data for uudecode");
+ return (ARCHIVE_FATAL);
+ }
+ /* Move the remaining data in in_buff into the new buffer. */
+ if (uudecode->in_cnt)
+ memmove(ptr, uudecode->in_buff, uudecode->in_cnt);
+ /* Replace in_buff with the new buffer. */
+ free(uudecode->in_buff);
+ uudecode->in_buff = ptr;
+ uudecode->in_allocated = newsize;
+ }
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+uudecode_filter_read(struct archive_read_filter *self, const void **buff)
+{
+ struct uudecode *uudecode;
+ const unsigned char *b, *d;
+ unsigned char *out;
+ ssize_t avail_in, ravail;
+ ssize_t used;
+ ssize_t total;
+ ssize_t len, llen, nl;
+
+ uudecode = (struct uudecode *)self->data;
+
+read_more:
+ d = __archive_read_filter_ahead(self->upstream, 1, &avail_in);
+ if (d == NULL && avail_in < 0)
+ return (ARCHIVE_FATAL);
+ /* Quiet a code analyzer; make sure avail_in must be zero
+ * when d is NULL. */
+ if (d == NULL)
+ avail_in = 0;
+ used = 0;
+ total = 0;
+ out = uudecode->out_buff;
+ ravail = avail_in;
+ if (uudecode->state == ST_IGNORE) {
+ used = avail_in;
+ goto finish;
+ }
+ if (uudecode->in_cnt) {
+ /*
+ * If there is remaining data which is saved by
+ * previous calling, use it first.
+ */
+ if (ensure_in_buff_size(self, uudecode,
+ avail_in + uudecode->in_cnt) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ memcpy(uudecode->in_buff + uudecode->in_cnt,
+ d, avail_in);
+ d = uudecode->in_buff;
+ avail_in += uudecode->in_cnt;
+ uudecode->in_cnt = 0;
+ }
+ for (;used < avail_in; d += llen, used += llen) {
+ int64_t l, body;
+
+ b = d;
+ len = get_line(b, avail_in - used, &nl);
+ if (len < 0) {
+ /* Non-ascii character is found. */
+ if (uudecode->state == ST_FIND_HEAD &&
+ (uudecode->total > 0 || total > 0)) {
+ uudecode->state = ST_IGNORE;
+ used = avail_in;
+ goto finish;
+ }
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Insufficient compressed data");
+ return (ARCHIVE_FATAL);
+ }
+ llen = len;
+ if (nl == 0) {
+ /*
+ * Save remaining data which does not contain
+ * NL('\n','\r').
+ */
+ if (ensure_in_buff_size(self, uudecode, len)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ if (uudecode->in_buff != b)
+ memmove(uudecode->in_buff, b, len);
+ uudecode->in_cnt = (int)len;
+ if (total == 0) {
+ /* Do not return 0; it means end-of-file.
+ * We should try to read bytes more. */
+ __archive_read_filter_consume(
+ self->upstream, ravail);
+ goto read_more;
+ }
+ break;
+ }
+ switch (uudecode->state) {
+ default:
+ case ST_FIND_HEAD:
+ /* Do not read more than UUENCODE_BID_MAX_READ bytes */
+ if (total + len >= UUENCODE_BID_MAX_READ) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid format data");
+ return (ARCHIVE_FATAL);
+ }
+ if (len - nl >= 11 && memcmp(b, "begin ", 6) == 0)
+ l = 6;
+ else if (len - nl >= 18 &&
+ memcmp(b, "begin-base64 ", 13) == 0)
+ l = 13;
+ else
+ l = 0;
+ if (l != 0 && b[l] >= '0' && b[l] <= '7' &&
+ b[l+1] >= '0' && b[l+1] <= '7' &&
+ b[l+2] >= '0' && b[l+2] <= '7' && b[l+3] == ' ') {
+ if (l == 6)
+ uudecode->state = ST_READ_UU;
+ else
+ uudecode->state = ST_READ_BASE64;
+ }
+ break;
+ case ST_READ_UU:
+ if (total + len * 2 > OUT_BUFF_SIZE)
+ goto finish;
+ body = len - nl;
+ if (!uuchar[*b] || body <= 0) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Insufficient compressed data");
+ return (ARCHIVE_FATAL);
+ }
+ /* Get length of undecoded bytes of curent line. */
+ l = UUDECODE(*b++);
+ body--;
+ if (l > body) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Insufficient compressed data");
+ return (ARCHIVE_FATAL);
+ }
+ if (l == 0) {
+ uudecode->state = ST_UUEND;
+ break;
+ }
+ while (l > 0) {
+ int n = 0;
+
+ if (l > 0) {
+ if (!uuchar[b[0]] || !uuchar[b[1]])
+ break;
+ n = UUDECODE(*b++) << 18;
+ n |= UUDECODE(*b++) << 12;
+ *out++ = n >> 16; total++;
+ --l;
+ }
+ if (l > 0) {
+ if (!uuchar[b[0]])
+ break;
+ n |= UUDECODE(*b++) << 6;
+ *out++ = (n >> 8) & 0xFF; total++;
+ --l;
+ }
+ if (l > 0) {
+ if (!uuchar[b[0]])
+ break;
+ n |= UUDECODE(*b++);
+ *out++ = n & 0xFF; total++;
+ --l;
+ }
+ }
+ if (l) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Insufficient compressed data");
+ return (ARCHIVE_FATAL);
+ }
+ break;
+ case ST_UUEND:
+ if (len - nl == 3 && memcmp(b, "end ", 3) == 0)
+ uudecode->state = ST_FIND_HEAD;
+ else {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Insufficient compressed data");
+ return (ARCHIVE_FATAL);
+ }
+ break;
+ case ST_READ_BASE64:
+ if (total + len * 2 > OUT_BUFF_SIZE)
+ goto finish;
+ l = len - nl;
+ if (l >= 3 && b[0] == '=' && b[1] == '=' &&
+ b[2] == '=') {
+ uudecode->state = ST_FIND_HEAD;
+ break;
+ }
+ while (l > 0) {
+ int n = 0;
+
+ if (l > 0) {
+ if (!base64[b[0]] || !base64[b[1]])
+ break;
+ n = base64num[*b++] << 18;
+ n |= base64num[*b++] << 12;
+ *out++ = n >> 16; total++;
+ l -= 2;
+ }
+ if (l > 0) {
+ if (*b == '=')
+ break;
+ if (!base64[*b])
+ break;
+ n |= base64num[*b++] << 6;
+ *out++ = (n >> 8) & 0xFF; total++;
+ --l;
+ }
+ if (l > 0) {
+ if (*b == '=')
+ break;
+ if (!base64[*b])
+ break;
+ n |= base64num[*b++];
+ *out++ = n & 0xFF; total++;
+ --l;
+ }
+ }
+ if (l && *b != '=') {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Insufficient compressed data");
+ return (ARCHIVE_FATAL);
+ }
+ break;
+ }
+ }
+finish:
+ if (ravail < avail_in)
+ used -= avail_in - ravail;
+ __archive_read_filter_consume(self->upstream, used);
+
+ *buff = uudecode->out_buff;
+ uudecode->total += total;
+ return (total);
+}
+
+static int
+uudecode_filter_close(struct archive_read_filter *self)
+{
+ struct uudecode *uudecode;
+
+ uudecode = (struct uudecode *)self->data;
+ free(uudecode->in_buff);
+ free(uudecode->out_buff);
+ free(uudecode);
+
+ return (ARCHIVE_OK);
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c
new file mode 100644
index 0000000000..a3ad67aabc
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c
@@ -0,0 +1,988 @@
+/*-
+ * Copyright (c) 2009-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2003-2008 Tim Kientzle and Miklos Vajna
+ * 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
+#if HAVE_LZMA_H
+#include <cm_lzma.h>
+#elif HAVE_LZMADEC_H
+#include <lzmadec.h>
+#endif
+
+#include "archive.h"
+#include "archive_endian.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+#if HAVE_LZMA_H && HAVE_LIBLZMA
+
+struct private_data {
+ lzma_stream stream;
+ unsigned char *out_block;
+ size_t out_block_size;
+ int64_t total_out;
+ char eof; /* True = found end of compressed data. */
+ char in_stream;
+
+ /* Following variables are used for lzip only. */
+ char lzip_ver;
+ uint32_t crc32;
+ int64_t member_in;
+ int64_t member_out;
+};
+
+#if LZMA_VERSION_MAJOR >= 5
+/* Effectively disable the limiter. */
+#define LZMA_MEMLIMIT UINT64_MAX
+#else
+/* NOTE: This needs to check memory size which running system has. */
+#define LZMA_MEMLIMIT (1U << 30)
+#endif
+
+/* Combined lzip/lzma/xz filter */
+static ssize_t xz_filter_read(struct archive_read_filter *, const void **);
+static int xz_filter_close(struct archive_read_filter *);
+static int xz_lzma_bidder_init(struct archive_read_filter *);
+
+#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC
+
+struct private_data {
+ lzmadec_stream stream;
+ unsigned char *out_block;
+ size_t out_block_size;
+ int64_t total_out;
+ char eof; /* True = found end of compressed data. */
+};
+
+/* Lzma-only filter */
+static ssize_t lzma_filter_read(struct archive_read_filter *, const void **);
+static int lzma_filter_close(struct archive_read_filter *);
+#endif
+
+/*
+ * Note that we can detect xz and lzma compressed files 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 no lzma library is available.
+ */
+static int xz_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *);
+static int xz_bidder_init(struct archive_read_filter *);
+static int lzma_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *);
+static int lzma_bidder_init(struct archive_read_filter *);
+static int lzip_has_member(struct archive_read_filter *);
+static int lzip_bidder_bid(struct archive_read_filter_bidder *,
+ struct archive_read_filter *);
+static int lzip_bidder_init(struct archive_read_filter *);
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* Deprecated; remove in libarchive 4.0 */
+int
+archive_read_support_compression_xz(struct archive *a)
+{
+ return archive_read_support_filter_xz(a);
+}
+#endif
+
+int
+archive_read_support_filter_xz(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter_bidder *bidder;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_filter_xz");
+
+ if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ bidder->data = NULL;
+ bidder->name = "xz";
+ bidder->bid = xz_bidder_bid;
+ bidder->init = xz_bidder_init;
+ bidder->options = NULL;
+ bidder->free = NULL;
+#if HAVE_LZMA_H && HAVE_LIBLZMA
+ return (ARCHIVE_OK);
+#else
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external xz program for xz decompression");
+ return (ARCHIVE_WARN);
+#endif
+}
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+int
+archive_read_support_compression_lzma(struct archive *a)
+{
+ return archive_read_support_filter_lzma(a);
+}
+#endif
+
+int
+archive_read_support_filter_lzma(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter_bidder *bidder;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_filter_lzma");
+
+ if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ bidder->data = NULL;
+ bidder->name = "lzma";
+ bidder->bid = lzma_bidder_bid;
+ bidder->init = lzma_bidder_init;
+ bidder->options = NULL;
+ bidder->free = NULL;
+#if HAVE_LZMA_H && HAVE_LIBLZMA
+ return (ARCHIVE_OK);
+#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC
+ return (ARCHIVE_OK);
+#else
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external lzma program for lzma decompression");
+ return (ARCHIVE_WARN);
+#endif
+}
+
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+int
+archive_read_support_compression_lzip(struct archive *a)
+{
+ return archive_read_support_filter_lzip(a);
+}
+#endif
+
+int
+archive_read_support_filter_lzip(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_filter_bidder *bidder;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_filter_lzip");
+
+ if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ bidder->data = NULL;
+ bidder->name = "lzip";
+ bidder->bid = lzip_bidder_bid;
+ bidder->init = lzip_bidder_init;
+ bidder->options = NULL;
+ bidder->free = NULL;
+#if HAVE_LZMA_H && HAVE_LIBLZMA
+ return (ARCHIVE_OK);
+#else
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external lzip program for lzip decompression");
+ return (ARCHIVE_WARN);
+#endif
+}
+
+/*
+ * Test whether we can handle this data.
+ */
+static int
+xz_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+ const unsigned char *buffer;
+ ssize_t avail;
+
+ (void)self; /* UNUSED */
+
+ buffer = __archive_read_filter_ahead(filter, 6, &avail);
+ if (buffer == NULL)
+ return (0);
+
+ /*
+ * Verify Header Magic Bytes : FD 37 7A 58 5A 00
+ */
+ if (memcmp(buffer, "\xFD\x37\x7A\x58\x5A\x00", 6) != 0)
+ return (0);
+
+ return (48);
+}
+
+/*
+ * Test whether we can handle this data.
+ *
+ * <sigh> LZMA has a rather poor file signature. Zeros do not
+ * make good signature bytes as a rule, and the only non-zero byte
+ * here is an ASCII character. For example, an uncompressed tar
+ * archive whose first file is ']' would satisfy this check. It may
+ * be necessary to exclude LZMA from compression_all() because of
+ * this. Clients of libarchive would then have to explicitly enable
+ * LZMA checking instead of (or in addition to) compression_all() when
+ * they have other evidence (file name, command-line option) to go on.
+ */
+static int
+lzma_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+ const unsigned char *buffer;
+ ssize_t avail;
+ uint32_t dicsize;
+ uint64_t uncompressed_size;
+ int bits_checked;
+
+ (void)self; /* UNUSED */
+
+ buffer = __archive_read_filter_ahead(filter, 14, &avail);
+ if (buffer == NULL)
+ return (0);
+
+ /* First byte of raw LZMA stream is commonly 0x5d.
+ * The first byte is a special number, which consists of
+ * three parameters of LZMA compression, a number of literal
+ * context bits(which is from 0 to 8, default is 3), a number
+ * of literal pos bits(which is from 0 to 4, default is 0),
+ * a number of pos bits(which is from 0 to 4, default is 2).
+ * The first byte is made by
+ * (pos bits * 5 + literal pos bit) * 9 + * literal contest bit,
+ * and so the default value in this field is
+ * (2 * 5 + 0) * 9 + 3 = 0x5d.
+ * lzma of LZMA SDK has options to change those parameters.
+ * It means a range of this field is from 0 to 224. And lzma of
+ * XZ Utils with option -e records 0x5e in this field. */
+ /* NOTE: If this checking of the first byte increases false
+ * recognition, we should allow only 0x5d and 0x5e for the first
+ * byte of LZMA stream. */
+ bits_checked = 0;
+ if (buffer[0] > (4 * 5 + 4) * 9 + 8)
+ return (0);
+ /* Most likely value in the first byte of LZMA stream. */
+ if (buffer[0] == 0x5d || buffer[0] == 0x5e)
+ bits_checked += 8;
+
+ /* Sixth through fourteenth bytes are uncompressed size,
+ * stored in little-endian order. `-1' means uncompressed
+ * size is unknown and lzma of XZ Utils always records `-1'
+ * in this field. */
+ uncompressed_size = archive_le64dec(buffer+5);
+ if (uncompressed_size == (uint64_t)ARCHIVE_LITERAL_LL(-1))
+ bits_checked += 64;
+
+ /* Second through fifth bytes are dictionary size, stored in
+ * little-endian order. The minimum dictionary size is
+ * 1 << 12(4KiB) which the lzma of LZMA SDK uses with option
+ * -d12 and the maxinam dictionary size is 1 << 27(128MiB)
+ * which the one uses with option -d27.
+ * NOTE: A comment of LZMA SDK source code says this dictionary
+ * range is from 1 << 12 to 1 << 30. */
+ dicsize = archive_le32dec(buffer+1);
+ switch (dicsize) {
+ case 0x00001000:/* lzma of LZMA SDK option -d12. */
+ case 0x00002000:/* lzma of LZMA SDK option -d13. */
+ case 0x00004000:/* lzma of LZMA SDK option -d14. */
+ case 0x00008000:/* lzma of LZMA SDK option -d15. */
+ case 0x00010000:/* lzma of XZ Utils option -0 and -1.
+ * lzma of LZMA SDK option -d16. */
+ case 0x00020000:/* lzma of LZMA SDK option -d17. */
+ case 0x00040000:/* lzma of LZMA SDK option -d18. */
+ case 0x00080000:/* lzma of XZ Utils option -2.
+ * lzma of LZMA SDK option -d19. */
+ case 0x00100000:/* lzma of XZ Utils option -3.
+ * lzma of LZMA SDK option -d20. */
+ case 0x00200000:/* lzma of XZ Utils option -4.
+ * lzma of LZMA SDK option -d21. */
+ case 0x00400000:/* lzma of XZ Utils option -5.
+ * lzma of LZMA SDK option -d22. */
+ case 0x00800000:/* lzma of XZ Utils option -6.
+ * lzma of LZMA SDK option -d23. */
+ case 0x01000000:/* lzma of XZ Utils option -7.
+ * lzma of LZMA SDK option -d24. */
+ case 0x02000000:/* lzma of XZ Utils option -8.
+ * lzma of LZMA SDK option -d25. */
+ case 0x04000000:/* lzma of XZ Utils option -9.
+ * lzma of LZMA SDK option -d26. */
+ case 0x08000000:/* lzma of LZMA SDK option -d27. */
+ bits_checked += 32;
+ break;
+ default:
+ /* If a memory usage for encoding was not enough on
+ * the platform where LZMA stream was made, lzma of
+ * XZ Utils automatically decreased the dictionary
+ * size to enough memory for encoding by 1Mi bytes
+ * (1 << 20).*/
+ if (dicsize <= 0x03F00000 && dicsize >= 0x00300000 &&
+ (dicsize & ((1 << 20)-1)) == 0 &&
+ bits_checked == 8 + 64) {
+ bits_checked += 32;
+ break;
+ }
+ /* Otherwise dictionary size is unlikely. But it is
+ * possible that someone makes lzma stream with
+ * liblzma/LZMA SDK in one's dictionary size. */
+ return (0);
+ }
+
+ /* TODO: The above test is still very weak. It would be
+ * good to do better. */
+
+ return (bits_checked);
+}
+
+static int
+lzip_has_member(struct archive_read_filter *filter)
+{
+ const unsigned char *buffer;
+ ssize_t avail;
+ int bits_checked;
+ int log2dic;
+
+ buffer = __archive_read_filter_ahead(filter, 6, &avail);
+ if (buffer == NULL)
+ return (0);
+
+ /*
+ * Verify Header Magic Bytes : 4C 5A 49 50 (`LZIP')
+ */
+ bits_checked = 0;
+ if (memcmp(buffer, "LZIP", 4) != 0)
+ return (0);
+ bits_checked += 32;
+
+ /* A version number must be 0 or 1 */
+ if (buffer[4] != 0 && buffer[4] != 1)
+ return (0);
+ bits_checked += 8;
+
+ /* Dictionary size. */
+ log2dic = buffer[5] & 0x1f;
+ if (log2dic < 12 || log2dic > 27)
+ return (0);
+ bits_checked += 8;
+
+ return (bits_checked);
+}
+
+static int
+lzip_bidder_bid(struct archive_read_filter_bidder *self,
+ struct archive_read_filter *filter)
+{
+
+ (void)self; /* UNUSED */
+ return (lzip_has_member(filter));
+}
+
+#if HAVE_LZMA_H && HAVE_LIBLZMA
+
+/*
+ * liblzma 4.999.7 and later support both lzma and xz streams.
+ */
+static int
+xz_bidder_init(struct archive_read_filter *self)
+{
+ self->code = ARCHIVE_FILTER_XZ;
+ self->name = "xz";
+ return (xz_lzma_bidder_init(self));
+}
+
+static int
+lzma_bidder_init(struct archive_read_filter *self)
+{
+ self->code = ARCHIVE_FILTER_LZMA;
+ self->name = "lzma";
+ return (xz_lzma_bidder_init(self));
+}
+
+static int
+lzip_bidder_init(struct archive_read_filter *self)
+{
+ self->code = ARCHIVE_FILTER_LZIP;
+ self->name = "lzip";
+ return (xz_lzma_bidder_init(self));
+}
+
+/*
+ * Set an error code and choose an error message
+ */
+static void
+set_error(struct archive_read_filter *self, int ret)
+{
+
+ switch (ret) {
+ case LZMA_STREAM_END: /* Found end of stream. */
+ case LZMA_OK: /* Decompressor made some progress. */
+ break;
+ case LZMA_MEM_ERROR:
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Lzma library error: Cannot allocate memory");
+ break;
+ case LZMA_MEMLIMIT_ERROR:
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Lzma library error: Out of memory");
+ break;
+ case LZMA_FORMAT_ERROR:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma library error: format not recognized");
+ break;
+ case LZMA_OPTIONS_ERROR:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma library error: Invalid options");
+ break;
+ case LZMA_DATA_ERROR:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma library error: Corrupted input data");
+ break;
+ case LZMA_BUF_ERROR:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma library error: No progress is possible");
+ break;
+ default:
+ /* Return an error. */
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma decompression failed: Unknown error");
+ break;
+ }
+}
+
+/*
+ * Setup the callbacks.
+ */
+static int
+xz_lzma_bidder_init(struct archive_read_filter *self)
+{
+ static const size_t out_block_size = 64 * 1024;
+ void *out_block;
+ struct private_data *state;
+ int ret;
+
+ state = (struct private_data *)calloc(sizeof(*state), 1);
+ out_block = (unsigned char *)malloc(out_block_size);
+ if (state == NULL || out_block == NULL) {
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate data for xz decompression");
+ free(out_block);
+ free(state);
+ return (ARCHIVE_FATAL);
+ }
+
+ self->data = state;
+ state->out_block_size = out_block_size;
+ state->out_block = out_block;
+ self->read = xz_filter_read;
+ self->skip = NULL; /* not supported */
+ self->close = xz_filter_close;
+
+ state->stream.avail_in = 0;
+
+ state->stream.next_out = state->out_block;
+ state->stream.avail_out = state->out_block_size;
+
+ state->crc32 = 0;
+ if (self->code == ARCHIVE_FILTER_LZIP) {
+ /*
+ * We have to read a lzip header and use it to initialize
+ * compression library, thus we cannot initialize the
+ * library for lzip here.
+ */
+ state->in_stream = 0;
+ return (ARCHIVE_OK);
+ } else
+ state->in_stream = 1;
+
+ /* Initialize compression library. */
+ if (self->code == ARCHIVE_FILTER_XZ)
+ ret = lzma_stream_decoder(&(state->stream),
+ LZMA_MEMLIMIT,/* memlimit */
+ LZMA_CONCATENATED);
+ else
+ ret = lzma_alone_decoder(&(state->stream),
+ LZMA_MEMLIMIT);/* memlimit */
+
+ if (ret == LZMA_OK)
+ return (ARCHIVE_OK);
+
+ /* Library setup failed: Choose an error message and clean up. */
+ set_error(self, ret);
+
+ free(state->out_block);
+ free(state);
+ self->data = NULL;
+ return (ARCHIVE_FATAL);
+}
+
+static int
+lzip_init(struct archive_read_filter *self)
+{
+ struct private_data *state;
+ const unsigned char *h;
+ lzma_filter filters[2];
+ unsigned char props[5];
+ ssize_t avail_in;
+ uint32_t dicsize;
+ int log2dic, ret;
+
+ state = (struct private_data *)self->data;
+ h = __archive_read_filter_ahead(self->upstream, 6, &avail_in);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+
+ /* Get a version number. */
+ state->lzip_ver = h[4];
+
+ /*
+ * Setup lzma property.
+ */
+ props[0] = 0x5d;
+
+ /* Get dictionary size. */
+ log2dic = h[5] & 0x1f;
+ if (log2dic < 12 || log2dic > 27)
+ return (ARCHIVE_FATAL);
+ dicsize = 1U << log2dic;
+ if (log2dic > 12)
+ dicsize -= (dicsize / 16) * (h[5] >> 5);
+ archive_le32enc(props+1, dicsize);
+
+ /* Consume lzip header. */
+ __archive_read_filter_consume(self->upstream, 6);
+ state->member_in = 6;
+
+ filters[0].id = LZMA_FILTER_LZMA1;
+ filters[0].options = NULL;
+ filters[1].id = LZMA_VLI_UNKNOWN;
+ filters[1].options = NULL;
+
+ ret = lzma_properties_decode(&filters[0], NULL, props, sizeof(props));
+ if (ret != LZMA_OK) {
+ set_error(self, ret);
+ return (ARCHIVE_FATAL);
+ }
+ ret = lzma_raw_decoder(&(state->stream), filters);
+#if LZMA_VERSION < 50010000
+ free(filters[0].options);
+#endif
+ if (ret != LZMA_OK) {
+ set_error(self, ret);
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+lzip_tail(struct archive_read_filter *self)
+{
+ struct private_data *state;
+ const unsigned char *f;
+ ssize_t avail_in;
+ int tail;
+
+ state = (struct private_data *)self->data;
+ if (state->lzip_ver == 0)
+ tail = 12;
+ else
+ tail = 20;
+ f = __archive_read_filter_ahead(self->upstream, tail, &avail_in);
+ if (f == NULL && avail_in < 0)
+ return (ARCHIVE_FATAL);
+ if (avail_in < tail) {
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+ "Lzip: Remaining data is less bytes");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Check the crc32 value of the uncompressed data of the current
+ * member */
+ if (state->crc32 != archive_le32dec(f)) {
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+ "Lzip: CRC32 error");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Check the uncompressed size of the current member */
+ if ((uint64_t)state->member_out != archive_le64dec(f + 4)) {
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+ "Lzip: Uncompressed size error");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Check the total size of the current member */
+ if (state->lzip_ver == 1 &&
+ (uint64_t)state->member_in + tail != archive_le64dec(f + 12)) {
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+ "Lzip: Member size error");
+ return (ARCHIVE_FAILED);
+ }
+ __archive_read_filter_consume(self->upstream, tail);
+
+ /* If current lzip data consists of multi member, try decompressing
+ * a next member. */
+ if (lzip_has_member(self->upstream) != 0) {
+ state->in_stream = 0;
+ state->crc32 = 0;
+ state->member_out = 0;
+ state->member_in = 0;
+ state->eof = 0;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Return the next block of decompressed data.
+ */
+static ssize_t
+xz_filter_read(struct archive_read_filter *self, const void **p)
+{
+ struct private_data *state;
+ size_t decompressed;
+ ssize_t avail_in;
+ int ret;
+
+ state = (struct private_data *)self->data;
+
+ /* Empty our output buffer. */
+ state->stream.next_out = state->out_block;
+ state->stream.avail_out = state->out_block_size;
+
+ /* Try to fill the output buffer. */
+ while (state->stream.avail_out > 0 && !state->eof) {
+ if (!state->in_stream) {
+ /*
+ * Initialize liblzma for lzip
+ */
+ ret = lzip_init(self);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ state->in_stream = 1;
+ }
+ state->stream.next_in =
+ __archive_read_filter_ahead(self->upstream, 1, &avail_in);
+ if (state->stream.next_in == NULL && avail_in < 0) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "truncated input");
+ return (ARCHIVE_FATAL);
+ }
+ state->stream.avail_in = avail_in;
+
+ /* Decompress as much as we can in one pass. */
+ ret = lzma_code(&(state->stream),
+ (state->stream.avail_in == 0)? LZMA_FINISH: LZMA_RUN);
+ switch (ret) {
+ case LZMA_STREAM_END: /* Found end of stream. */
+ state->eof = 1;
+ /* FALL THROUGH */
+ case LZMA_OK: /* Decompressor made some progress. */
+ __archive_read_filter_consume(self->upstream,
+ avail_in - state->stream.avail_in);
+ state->member_in +=
+ avail_in - state->stream.avail_in;
+ break;
+ default:
+ set_error(self, ret);
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ decompressed = state->stream.next_out - state->out_block;
+ state->total_out += decompressed;
+ state->member_out += decompressed;
+ if (decompressed == 0)
+ *p = NULL;
+ else {
+ *p = state->out_block;
+ if (self->code == ARCHIVE_FILTER_LZIP) {
+ state->crc32 = lzma_crc32(state->out_block,
+ decompressed, state->crc32);
+ if (state->eof) {
+ ret = lzip_tail(self);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ }
+ }
+ }
+ return (decompressed);
+}
+
+/*
+ * Clean up the decompressor.
+ */
+static int
+xz_filter_close(struct archive_read_filter *self)
+{
+ struct private_data *state;
+
+ state = (struct private_data *)self->data;
+ lzma_end(&(state->stream));
+ free(state->out_block);
+ free(state);
+ return (ARCHIVE_OK);
+}
+
+#else
+
+#if HAVE_LZMADEC_H && HAVE_LIBLZMADEC
+
+/*
+ * If we have the older liblzmadec library, then we can handle
+ * LZMA streams but not XZ streams.
+ */
+
+/*
+ * Setup the callbacks.
+ */
+static int
+lzma_bidder_init(struct archive_read_filter *self)
+{
+ static const size_t out_block_size = 64 * 1024;
+ void *out_block;
+ struct private_data *state;
+ ssize_t ret, avail_in;
+
+ self->code = ARCHIVE_FILTER_LZMA;
+ self->name = "lzma";
+
+ state = (struct private_data *)calloc(sizeof(*state), 1);
+ out_block = (unsigned char *)malloc(out_block_size);
+ if (state == NULL || out_block == NULL) {
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Can't allocate data for lzma decompression");
+ free(out_block);
+ free(state);
+ return (ARCHIVE_FATAL);
+ }
+
+ self->data = state;
+ state->out_block_size = out_block_size;
+ state->out_block = out_block;
+ self->read = lzma_filter_read;
+ self->skip = NULL; /* not supported */
+ self->close = lzma_filter_close;
+
+ /* Prime the lzma library with 18 bytes of input. */
+ state->stream.next_in = (unsigned char *)(uintptr_t)
+ __archive_read_filter_ahead(self->upstream, 18, &avail_in);
+ if (state->stream.next_in == NULL)
+ return (ARCHIVE_FATAL);
+ state->stream.avail_in = avail_in;
+ state->stream.next_out = state->out_block;
+ state->stream.avail_out = state->out_block_size;
+
+ /* Initialize compression library. */
+ ret = lzmadec_init(&(state->stream));
+ __archive_read_filter_consume(self->upstream,
+ avail_in - state->stream.avail_in);
+ if (ret == LZMADEC_OK)
+ return (ARCHIVE_OK);
+
+ /* Library setup failed: Clean up. */
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing lzma library");
+
+ /* Override the error message if we know what really went wrong. */
+ switch (ret) {
+ case LZMADEC_HEADER_ERROR:
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ "invalid header");
+ break;
+ case LZMADEC_MEM_ERROR:
+ archive_set_error(&self->archive->archive, ENOMEM,
+ "Internal error initializing compression library: "
+ "out of memory");
+ break;
+ }
+
+ free(state->out_block);
+ free(state);
+ self->data = NULL;
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Return the next block of decompressed data.
+ */
+static ssize_t
+lzma_filter_read(struct archive_read_filter *self, const void **p)
+{
+ struct private_data *state;
+ size_t decompressed;
+ ssize_t avail_in, ret;
+
+ state = (struct private_data *)self->data;
+
+ /* Empty our output buffer. */
+ state->stream.next_out = state->out_block;
+ state->stream.avail_out = state->out_block_size;
+
+ /* Try to fill the output buffer. */
+ while (state->stream.avail_out > 0 && !state->eof) {
+ state->stream.next_in = (unsigned char *)(uintptr_t)
+ __archive_read_filter_ahead(self->upstream, 1, &avail_in);
+ if (state->stream.next_in == NULL && avail_in < 0) {
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "truncated lzma input");
+ return (ARCHIVE_FATAL);
+ }
+ state->stream.avail_in = avail_in;
+
+ /* Decompress as much as we can in one pass. */
+ ret = lzmadec_decode(&(state->stream), avail_in == 0);
+ switch (ret) {
+ case LZMADEC_STREAM_END: /* Found end of stream. */
+ state->eof = 1;
+ /* FALL THROUGH */
+ case LZMADEC_OK: /* Decompressor made some progress. */
+ __archive_read_filter_consume(self->upstream,
+ avail_in - state->stream.avail_in);
+ break;
+ case LZMADEC_BUF_ERROR: /* Insufficient input data? */
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Insufficient compressed data");
+ return (ARCHIVE_FATAL);
+ default:
+ /* Return an error. */
+ archive_set_error(&self->archive->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma decompression failed");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ decompressed = state->stream.next_out - state->out_block;
+ state->total_out += decompressed;
+ if (decompressed == 0)
+ *p = NULL;
+ else
+ *p = state->out_block;
+ return (decompressed);
+}
+
+/*
+ * Clean up the decompressor.
+ */
+static int
+lzma_filter_close(struct archive_read_filter *self)
+{
+ struct private_data *state;
+ int ret;
+
+ state = (struct private_data *)self->data;
+ ret = ARCHIVE_OK;
+ switch (lzmadec_end(&(state->stream))) {
+ case LZMADEC_OK:
+ break;
+ default:
+ archive_set_error(&(self->archive->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up %s compressor",
+ self->archive->archive.compression_name);
+ ret = ARCHIVE_FATAL;
+ }
+
+ free(state->out_block);
+ free(state);
+ return (ret);
+}
+
+#else
+
+/*
+ *
+ * If we have no suitable 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
+lzma_bidder_init(struct archive_read_filter *self)
+{
+ int r;
+
+ r = __archive_read_program(self, "lzma -d -qq");
+ /* 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_LZMA;
+ self->name = "lzma";
+ return (r);
+}
+
+#endif /* HAVE_LZMADEC_H */
+
+
+static int
+xz_bidder_init(struct archive_read_filter *self)
+{
+ int r;
+
+ r = __archive_read_program(self, "xz -d -qq");
+ /* 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_XZ;
+ self->name = "xz";
+ return (r);
+}
+
+static int
+lzip_bidder_init(struct archive_read_filter *self)
+{
+ int r;
+
+ r = __archive_read_program(self, "lzip -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_LZIP;
+ self->name = "lzip";
+ return (r);
+}
+
+
+#endif /* HAVE_LZMA_H */
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c
new file mode 100644
index 0000000000..47e0752d29
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c
@@ -0,0 +1,3862 @@
+/*-
+ * Copyright (c) 2011 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_BZLIB_H
+#include <cm_bzlib.h>
+#endif
+#ifdef HAVE_LZMA_H
+#include <cm_lzma.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_ppmd7_private.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+#include "archive_endian.h"
+
+#ifndef HAVE_ZLIB_H
+#include "archive_crc32.h"
+#endif
+
+#define _7ZIP_SIGNATURE "7z\xBC\xAF\x27\x1C"
+#define SFX_MIN_ADDR 0x27000
+#define SFX_MAX_ADDR 0x60000
+
+
+/*
+ * Codec ID
+ */
+#define _7Z_COPY 0
+#define _7Z_LZMA 0x030101
+#define _7Z_LZMA2 0x21
+#define _7Z_DEFLATE 0x040108
+#define _7Z_BZ2 0x040202
+#define _7Z_PPMD 0x030401
+#define _7Z_DELTA 0x03
+#define _7Z_CRYPTO_MAIN_ZIP 0x06F10101 /* Main Zip crypto algo */
+#define _7Z_CRYPTO_RAR_29 0x06F10303 /* Rar29 AES-128 + (modified SHA-1) */
+#define _7Z_CRYPTO_AES_256_SHA_256 0x06F10701 /* AES-256 + SHA-256 */
+
+
+#define _7Z_X86 0x03030103
+#define _7Z_X86_BCJ2 0x0303011B
+#define _7Z_POWERPC 0x03030205
+#define _7Z_IA64 0x03030401
+#define _7Z_ARM 0x03030501
+#define _7Z_ARMTHUMB 0x03030701
+#define _7Z_SPARC 0x03030805
+
+/*
+ * 7-Zip header property IDs.
+ */
+#define kEnd 0x00
+#define kHeader 0x01
+#define kArchiveProperties 0x02
+#define kAdditionalStreamsInfo 0x03
+#define kMainStreamsInfo 0x04
+#define kFilesInfo 0x05
+#define kPackInfo 0x06
+#define kUnPackInfo 0x07
+#define kSubStreamsInfo 0x08
+#define kSize 0x09
+#define kCRC 0x0A
+#define kFolder 0x0B
+#define kCodersUnPackSize 0x0C
+#define kNumUnPackStream 0x0D
+#define kEmptyStream 0x0E
+#define kEmptyFile 0x0F
+#define kAnti 0x10
+#define kName 0x11
+#define kCTime 0x12
+#define kATime 0x13
+#define kMTime 0x14
+#define kAttributes 0x15
+#define kEncodedHeader 0x17
+
+struct _7z_digests {
+ unsigned char *defineds;
+ uint32_t *digests;
+};
+
+
+struct _7z_folder {
+ uint64_t numCoders;
+ struct _7z_coder {
+ unsigned long codec;
+ uint64_t numInStreams;
+ uint64_t numOutStreams;
+ uint64_t propertiesSize;
+ unsigned char *properties;
+ } *coders;
+ uint64_t numBindPairs;
+ struct {
+ uint64_t inIndex;
+ uint64_t outIndex;
+ } *bindPairs;
+ uint64_t numPackedStreams;
+ uint64_t *packedStreams;
+ uint64_t numInStreams;
+ uint64_t numOutStreams;
+ uint64_t *unPackSize;
+ unsigned char digest_defined;
+ uint32_t digest;
+ uint64_t numUnpackStreams;
+ uint32_t packIndex;
+ /* Unoperated bytes. */
+ uint64_t skipped_bytes;
+};
+
+struct _7z_coders_info {
+ uint64_t numFolders;
+ struct _7z_folder *folders;
+ uint64_t dataStreamIndex;
+};
+
+struct _7z_pack_info {
+ uint64_t pos;
+ uint64_t numPackStreams;
+ uint64_t *sizes;
+ struct _7z_digests digest;
+ /* Calculated from pos and numPackStreams. */
+ uint64_t *positions;
+};
+
+struct _7z_substream_info {
+ size_t unpack_streams;
+ uint64_t *unpackSizes;
+ unsigned char *digestsDefined;
+ uint32_t *digests;
+};
+
+struct _7z_stream_info {
+ struct _7z_pack_info pi;
+ struct _7z_coders_info ci;
+ struct _7z_substream_info ss;
+};
+
+struct _7z_header_info {
+ uint64_t dataIndex;
+
+ unsigned char *emptyStreamBools;
+ unsigned char *emptyFileBools;
+ unsigned char *antiBools;
+ unsigned char *attrBools;
+};
+
+struct _7zip_entry {
+ size_t name_len;
+ unsigned char *utf16name;
+#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG)
+ const wchar_t *wname;
+#endif
+ uint32_t folderIndex;
+ uint32_t ssIndex;
+ unsigned flg;
+#define MTIME_IS_SET (1<<0)
+#define ATIME_IS_SET (1<<1)
+#define CTIME_IS_SET (1<<2)
+#define CRC32_IS_SET (1<<3)
+#define HAS_STREAM (1<<4)
+
+ time_t mtime;
+ time_t atime;
+ time_t ctime;
+ long mtime_ns;
+ long atime_ns;
+ long ctime_ns;
+ uint32_t mode;
+ uint32_t attr;
+};
+
+struct _7zip {
+ /* Structural information about the archive. */
+ struct _7z_stream_info si;
+
+ int header_is_being_read;
+ int header_is_encoded;
+ uint64_t header_bytes_remaining;
+ unsigned long header_crc32;
+ /* Header offset to check that reading pointes of the file contens
+ * will not exceed the header. */
+ uint64_t header_offset;
+ /* Base offset of the archive file for a seek in case reading SFX. */
+ uint64_t seek_base;
+
+ /* List of entries */
+ size_t entries_remaining;
+ uint64_t numFiles;
+ struct _7zip_entry *entries;
+ struct _7zip_entry *entry;
+ unsigned char *entry_names;
+
+ /* entry_bytes_remaining is the number of bytes we expect. */
+ int64_t entry_offset;
+ uint64_t entry_bytes_remaining;
+
+ /* Running CRC32 of the decompressed data */
+ unsigned long entry_crc32;
+
+ /* Flags to mark progress of decompression. */
+ char end_of_entry;
+
+ /* Uncompressed buffer control. */
+#define UBUFF_SIZE (64 * 1024)
+ unsigned char *uncompressed_buffer;
+ unsigned char *uncompressed_buffer_pointer;
+ size_t uncompressed_buffer_size;
+ size_t uncompressed_buffer_bytes_remaining;
+
+ /* Offset of the compressed data. */
+ int64_t stream_offset;
+
+ /*
+ * Decompressing control data.
+ */
+ unsigned folder_index;
+ uint64_t folder_outbytes_remaining;
+ unsigned pack_stream_index;
+ unsigned pack_stream_remaining;
+ uint64_t pack_stream_inbytes_remaining;
+ size_t pack_stream_bytes_unconsumed;
+
+ /* The codec information of a folder. */
+ unsigned long codec;
+ unsigned long codec2;
+
+ /*
+ * Decompressor controllers.
+ */
+ /* Decording LZMA1 and LZMA2 data. */
+#ifdef HAVE_LZMA_H
+ lzma_stream lzstream;
+ int lzstream_valid;
+#endif
+ /* Decording bzip2 data. */
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ bz_stream bzstream;
+ int bzstream_valid;
+#endif
+ /* Decording deflate data. */
+#ifdef HAVE_ZLIB_H
+ z_stream stream;
+ int stream_valid;
+#endif
+ /* Decording PPMd data. */
+ int ppmd7_stat;
+ CPpmd7 ppmd7_context;
+ CPpmd7z_RangeDec range_dec;
+ IByteIn bytein;
+ struct {
+ const unsigned char *next_in;
+ int64_t avail_in;
+ int64_t total_in;
+ unsigned char *next_out;
+ int64_t avail_out;
+ int64_t total_out;
+ int overconsumed;
+ } ppstream;
+ int ppmd7_valid;
+
+ /* Decoding BCJ and BCJ2 data. */
+ uint32_t bcj_state;
+ size_t odd_bcj_size;
+ unsigned char odd_bcj[4];
+ /* Decoding BCJ data. */
+ size_t bcj_prevPosT;
+ uint32_t bcj_prevMask;
+ uint32_t bcj_ip;
+
+ /* Decoding BCJ2 data. */
+ size_t main_stream_bytes_remaining;
+ unsigned char *sub_stream_buff[3];
+ size_t sub_stream_size[3];
+ size_t sub_stream_bytes_remaining[3];
+ unsigned char *tmp_stream_buff;
+ size_t tmp_stream_buff_size;
+ size_t tmp_stream_bytes_avail;
+ size_t tmp_stream_bytes_remaining;
+#ifdef _LZMA_PROB32
+#define CProb uint32_t
+#else
+#define CProb uint16_t
+#endif
+ CProb bcj2_p[256 + 2];
+ uint8_t bcj2_prevByte;
+ uint32_t bcj2_range;
+ uint32_t bcj2_code;
+ uint64_t bcj2_outPos;
+
+ /* Filename character-set conversion data. */
+ struct archive_string_conv *sconv;
+
+ char format_name[64];
+
+ /* Custom value that is non-zero if this archive contains encrypted entries. */
+ int has_encrypted_entries;
+};
+
+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);
+static int archive_read_format_7zip_cleanup(struct archive_read *);
+static int archive_read_format_7zip_read_data(struct archive_read *,
+ const void **, size_t *, int64_t *);
+static int archive_read_format_7zip_read_data_skip(struct archive_read *);
+static int archive_read_format_7zip_read_header(struct archive_read *,
+ struct archive_entry *);
+static int check_7zip_header_in_sfx(const char *);
+static unsigned long decode_codec_id(const unsigned char *, size_t);
+static int decode_encoded_header_info(struct archive_read *,
+ struct _7z_stream_info *);
+static int decompress(struct archive_read *, struct _7zip *,
+ void *, size_t *, const void *, size_t *);
+static ssize_t extract_pack_stream(struct archive_read *, size_t);
+static void fileTimeToUtc(uint64_t, time_t *, long *);
+static uint64_t folder_uncompressed_size(struct _7z_folder *);
+static void free_CodersInfo(struct _7z_coders_info *);
+static void free_Digest(struct _7z_digests *);
+static void free_Folder(struct _7z_folder *);
+static void free_Header(struct _7z_header_info *);
+static void free_PackInfo(struct _7z_pack_info *);
+static void free_StreamsInfo(struct _7z_stream_info *);
+static void free_SubStreamsInfo(struct _7z_substream_info *);
+static int free_decompression(struct archive_read *, struct _7zip *);
+static ssize_t get_uncompressed_data(struct archive_read *, const void **,
+ size_t, size_t);
+static const unsigned char * header_bytes(struct archive_read *, size_t);
+static int init_decompression(struct archive_read *, struct _7zip *,
+ const struct _7z_coder *, const struct _7z_coder *);
+static int parse_7zip_uint64(struct archive_read *, uint64_t *);
+static int read_Bools(struct archive_read *, unsigned char *, size_t);
+static int read_CodersInfo(struct archive_read *,
+ struct _7z_coders_info *);
+static int read_Digests(struct archive_read *, struct _7z_digests *,
+ size_t);
+static int read_Folder(struct archive_read *, struct _7z_folder *);
+static int read_Header(struct archive_read *, struct _7z_header_info *,
+ int);
+static int read_PackInfo(struct archive_read *, struct _7z_pack_info *);
+static int read_StreamsInfo(struct archive_read *,
+ struct _7z_stream_info *);
+static int read_SubStreamsInfo(struct archive_read *,
+ struct _7z_substream_info *, struct _7z_folder *, size_t);
+static int read_Times(struct archive_read *, struct _7z_header_info *,
+ int);
+static void read_consume(struct archive_read *);
+static ssize_t read_stream(struct archive_read *, const void **, size_t,
+ size_t);
+static int seek_pack(struct archive_read *);
+static int64_t skip_stream(struct archive_read *, size_t);
+static int skip_sfx(struct archive_read *, ssize_t);
+static int slurp_central_directory(struct archive_read *, struct _7zip *,
+ struct _7z_header_info *);
+static int setup_decode_folder(struct archive_read *, struct _7z_folder *,
+ int);
+static void x86_Init(struct _7zip *);
+static size_t x86_Convert(struct _7zip *, uint8_t *, size_t);
+static ssize_t Bcj2_Decode(struct _7zip *, uint8_t *, size_t);
+
+
+int
+archive_read_support_format_7zip(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct _7zip *zip;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_7zip");
+
+ zip = calloc(1, sizeof(*zip));
+ if (zip == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate 7zip data");
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Until enough data has been read, we cannot tell about
+ * any encrypted entries yet.
+ */
+ zip->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW;
+
+
+ r = __archive_read_register_format(a,
+ zip,
+ "7zip",
+ archive_read_format_7zip_bid,
+ NULL,
+ archive_read_format_7zip_read_header,
+ archive_read_format_7zip_read_data,
+ archive_read_format_7zip_read_data_skip,
+ NULL,
+ archive_read_format_7zip_cleanup,
+ archive_read_support_format_7zip_capabilities,
+ archive_read_format_7zip_has_encrypted_entries);
+
+ if (r != ARCHIVE_OK)
+ free(zip);
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_support_format_7zip_capabilities(struct archive_read * a)
+{
+ (void)a; /* UNUSED */
+ return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA |
+ ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA);
+}
+
+
+static int
+archive_read_format_7zip_has_encrypted_entries(struct archive_read *_a)
+{
+ if (_a && _a->format) {
+ struct _7zip * zip = (struct _7zip *)_a->format->data;
+ if (zip) {
+ return zip->has_encrypted_entries;
+ }
+ }
+ return ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW;
+}
+
+static int
+archive_read_format_7zip_bid(struct archive_read *a, int best_bid)
+{
+ const char *p;
+
+ /* If someone has already bid more than 32, then avoid
+ trashing the look-ahead buffers with a seek. */
+ if (best_bid > 32)
+ return (-1);
+
+ if ((p = __archive_read_ahead(a, 6, NULL)) == NULL)
+ return (0);
+
+ /* If first six bytes are the 7-Zip signature,
+ * return the bid right now. */
+ if (memcmp(p, _7ZIP_SIGNATURE, 6) == 0)
+ return (48);
+
+ /*
+ * It may a 7-Zip SFX archive file. If first two bytes are
+ * 'M' and 'Z' available on Windows or first four bytes are
+ * "\x7F\x45LF" available on posix like system, seek the 7-Zip
+ * signature. Although we will perform a seek when reading
+ * a header, what we do not use __archive_read_seek() here is
+ * due to a bidding performance.
+ */
+ if ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0) {
+ ssize_t offset = SFX_MIN_ADDR;
+ ssize_t window = 4096;
+ ssize_t bytes_avail;
+ while (offset + window <= (SFX_MAX_ADDR)) {
+ const char *buff = __archive_read_ahead(a,
+ offset + window, &bytes_avail);
+ if (buff == NULL) {
+ /* Remaining bytes are less than window. */
+ window >>= 1;
+ if (window < 0x40)
+ return (0);
+ continue;
+ }
+ p = buff + offset;
+ while (p + 32 < buff + bytes_avail) {
+ int step = check_7zip_header_in_sfx(p);
+ if (step == 0)
+ return (48);
+ p += step;
+ }
+ offset = p - buff;
+ }
+ }
+ return (0);
+}
+
+static int
+check_7zip_header_in_sfx(const char *p)
+{
+ switch ((unsigned char)p[5]) {
+ case 0x1C:
+ if (memcmp(p, _7ZIP_SIGNATURE, 6) != 0)
+ return (6);
+ /*
+ * Test the CRC because its extraction code has 7-Zip
+ * Magic Code, so we should do this in order not to
+ * make a mis-detection.
+ */
+ if (crc32(0, (const unsigned char *)p + 12, 20)
+ != archive_le32dec(p + 8))
+ return (6);
+ /* Hit the header! */
+ return (0);
+ case 0x37: return (5);
+ case 0x7A: return (4);
+ case 0xBC: return (3);
+ case 0xAF: return (2);
+ case 0x27: return (1);
+ default: return (6);
+ }
+}
+
+static int
+skip_sfx(struct archive_read *a, ssize_t bytes_avail)
+{
+ const void *h;
+ const char *p, *q;
+ size_t skip, offset;
+ ssize_t bytes, window;
+
+ /*
+ * If bytes_avail > SFX_MIN_ADDR we do not have to call
+ * __archive_read_seek() at this time since we have
+ * alredy had enough data.
+ */
+ if (bytes_avail > SFX_MIN_ADDR)
+ __archive_read_consume(a, SFX_MIN_ADDR);
+ else if (__archive_read_seek(a, SFX_MIN_ADDR, SEEK_SET) < 0)
+ return (ARCHIVE_FATAL);
+
+ offset = 0;
+ window = 1;
+ while (offset + window <= SFX_MAX_ADDR - SFX_MIN_ADDR) {
+ h = __archive_read_ahead(a, window, &bytes);
+ if (h == NULL) {
+ /* Remaining bytes are less than window. */
+ window >>= 1;
+ if (window < 0x40)
+ goto fatal;
+ continue;
+ }
+ if (bytes < 6) {
+ /* This case might happen when window == 1. */
+ window = 4096;
+ continue;
+ }
+ p = (const char *)h;
+ q = p + bytes;
+
+ /*
+ * Scan ahead until we find something that looks
+ * like the 7-Zip header.
+ */
+ while (p + 32 < q) {
+ int step = check_7zip_header_in_sfx(p);
+ if (step == 0) {
+ struct _7zip *zip =
+ (struct _7zip *)a->format->data;
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ zip->seek_base = SFX_MIN_ADDR + offset + skip;
+ return (ARCHIVE_OK);
+ }
+ p += step;
+ }
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ offset += skip;
+ if (window == 1)
+ window = 4096;
+ }
+fatal:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Couldn't find out 7-Zip header");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+archive_read_format_7zip_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ struct _7zip_entry *zip_entry;
+ int r, ret = ARCHIVE_OK;
+ struct _7z_folder *folder = 0;
+ uint64_t fidx = 0;
+
+ /*
+ * It should be sufficient to call archive_read_next_header() for
+ * a reader to determine if an entry is encrypted or not. If the
+ * encryption of an entry is only detectable when calling
+ * 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) {
+ zip->has_encrypted_entries = 0;
+ }
+
+ a->archive.archive_format = ARCHIVE_FORMAT_7ZIP;
+ if (a->archive.archive_format_name == NULL)
+ a->archive.archive_format_name = "7-Zip";
+
+ if (zip->entries == NULL) {
+ struct _7z_header_info header;
+
+ memset(&header, 0, sizeof(header));
+ r = slurp_central_directory(a, zip, &header);
+ free_Header(&header);
+ if (r != ARCHIVE_OK)
+ return (r);
+ zip->entries_remaining = (size_t)zip->numFiles;
+ zip->entry = zip->entries;
+ } else {
+ ++zip->entry;
+ }
+ zip_entry = zip->entry;
+
+ if (zip->entries_remaining <= 0)
+ return ARCHIVE_EOF;
+ --zip->entries_remaining;
+
+ zip->entry_offset = 0;
+ zip->end_of_entry = 0;
+ zip->entry_crc32 = crc32(0, NULL, 0);
+
+ /* Setup a string conversion for a filename. */
+ if (zip->sconv == NULL) {
+ zip->sconv = archive_string_conversion_from_charset(
+ &a->archive, "UTF-16LE", 1);
+ if (zip->sconv == NULL)
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Figure out if the entry is encrypted by looking at the folder
+ that is associated to the current 7zip entry. If the folder
+ has a coder with a _7Z_CRYPTO codec then the folder is encrypted.
+ Hence the entry must also be encrypted. */
+ if (zip_entry && zip_entry->folderIndex < zip->si.ci.numFolders) {
+ folder = &(zip->si.ci.folders[zip_entry->folderIndex]);
+ for (fidx=0; folder && fidx<folder->numCoders; fidx++) {
+ switch(folder->coders[fidx].codec) {
+ case _7Z_CRYPTO_MAIN_ZIP:
+ case _7Z_CRYPTO_RAR_29:
+ case _7Z_CRYPTO_AES_256_SHA_256: {
+ archive_entry_set_is_data_encrypted(entry, 1);
+ zip->has_encrypted_entries = 1;
+ break;
+ }
+ }
+ }
+ }
+
+ /* Now that we've checked for encryption, if there were still no
+ * encrypted entries found we can say for sure that there are none.
+ */
+ if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
+ zip->has_encrypted_entries = 0;
+ }
+
+ if (archive_entry_copy_pathname_l(entry,
+ (const char *)zip_entry->utf16name,
+ zip_entry->name_len, zip->sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Pathname cannot be converted "
+ "from %s to current locale.",
+ archive_string_conversion_charset_name(zip->sconv));
+ ret = ARCHIVE_WARN;
+ }
+
+ /* Populate some additional entry fields: */
+ archive_entry_set_mode(entry, zip_entry->mode);
+ if (zip_entry->flg & MTIME_IS_SET)
+ archive_entry_set_mtime(entry, zip_entry->mtime,
+ zip_entry->mtime_ns);
+ if (zip_entry->flg & CTIME_IS_SET)
+ archive_entry_set_ctime(entry, zip_entry->ctime,
+ zip_entry->ctime_ns);
+ if (zip_entry->flg & ATIME_IS_SET)
+ archive_entry_set_atime(entry, zip_entry->atime,
+ zip_entry->atime_ns);
+ if (zip_entry->ssIndex != (uint32_t)-1) {
+ zip->entry_bytes_remaining =
+ zip->si.ss.unpackSizes[zip_entry->ssIndex];
+ archive_entry_set_size(entry, zip->entry_bytes_remaining);
+ } else {
+ zip->entry_bytes_remaining = 0;
+ archive_entry_set_size(entry, 0);
+ }
+
+ /* If there's no body, force read_data() to return EOF immediately. */
+ if (zip->entry_bytes_remaining < 1)
+ zip->end_of_entry = 1;
+
+ if ((zip_entry->mode & AE_IFMT) == AE_IFLNK) {
+ unsigned char *symname = NULL;
+ size_t symsize = 0;
+
+ /*
+ * Symbolic-name is recorded as its contents. We have to
+ * read the contents at this time.
+ */
+ while (zip->entry_bytes_remaining > 0) {
+ const void *buff;
+ unsigned char *mem;
+ size_t size;
+ int64_t offset;
+
+ r = archive_read_format_7zip_read_data(a, &buff,
+ &size, &offset);
+ if (r < ARCHIVE_WARN) {
+ free(symname);
+ return (r);
+ }
+ mem = realloc(symname, symsize + size + 1);
+ if (mem == NULL) {
+ free(symname);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Symname");
+ return (ARCHIVE_FATAL);
+ }
+ symname = mem;
+ memcpy(symname+symsize, buff, size);
+ symsize += size;
+ }
+ if (symsize == 0) {
+ /* If there is no synname, handle it as a regular
+ * file. */
+ zip_entry->mode &= ~AE_IFMT;
+ zip_entry->mode |= AE_IFREG;
+ archive_entry_set_mode(entry, zip_entry->mode);
+ } else {
+ symname[symsize] = '\0';
+ archive_entry_copy_symlink(entry,
+ (const char *)symname);
+ }
+ free(symname);
+ archive_entry_set_size(entry, 0);
+ }
+
+ /* Set up a more descriptive format name. */
+ sprintf(zip->format_name, "7-Zip");
+ a->archive.archive_format_name = zip->format_name;
+
+ return (ret);
+}
+
+static int
+archive_read_format_7zip_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ struct _7zip *zip;
+ ssize_t bytes;
+ int ret = ARCHIVE_OK;
+
+ zip = (struct _7zip *)(a->format->data);
+
+ if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
+ zip->has_encrypted_entries = 0;
+ }
+
+ if (zip->pack_stream_bytes_unconsumed)
+ read_consume(a);
+
+ *offset = zip->entry_offset;
+ *size = 0;
+ *buff = NULL;
+ /*
+ * If we hit end-of-entry last time, clean up and return
+ * ARCHIVE_EOF this time.
+ */
+ if (zip->end_of_entry)
+ return (ARCHIVE_EOF);
+
+ bytes = read_stream(a, buff,
+ (size_t)zip->entry_bytes_remaining, 0);
+ if (bytes < 0)
+ return ((int)bytes);
+ if (bytes == 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated 7-Zip file body");
+ return (ARCHIVE_FATAL);
+ }
+ zip->entry_bytes_remaining -= bytes;
+ if (zip->entry_bytes_remaining == 0)
+ zip->end_of_entry = 1;
+
+ /* Update checksum */
+ if ((zip->entry->flg & CRC32_IS_SET) && bytes)
+ zip->entry_crc32 = crc32(zip->entry_crc32, *buff,
+ (unsigned)bytes);
+
+ /* If we hit the end, swallow any end-of-data marker. */
+ if (zip->end_of_entry) {
+ /* Check computed CRC against file contents. */
+ if ((zip->entry->flg & CRC32_IS_SET) &&
+ zip->si.ss.digests[zip->entry->ssIndex] !=
+ zip->entry_crc32) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "7-Zip bad CRC: 0x%lx should be 0x%lx",
+ (unsigned long)zip->entry_crc32,
+ (unsigned long)zip->si.ss.digests[
+ zip->entry->ssIndex]);
+ ret = ARCHIVE_WARN;
+ }
+ }
+
+ *size = bytes;
+ *offset = zip->entry_offset;
+ zip->entry_offset += bytes;
+
+ return (ret);
+}
+
+static int
+archive_read_format_7zip_read_data_skip(struct archive_read *a)
+{
+ struct _7zip *zip;
+ int64_t bytes_skipped;
+
+ zip = (struct _7zip *)(a->format->data);
+
+ if (zip->pack_stream_bytes_unconsumed)
+ read_consume(a);
+
+ /* If we've already read to end of data, we're done. */
+ if (zip->end_of_entry)
+ return (ARCHIVE_OK);
+
+ /*
+ * If the length is at the beginning, we can skip the
+ * compressed data much more quickly.
+ */
+ bytes_skipped = skip_stream(a, (size_t)zip->entry_bytes_remaining);
+ if (bytes_skipped < 0)
+ return (ARCHIVE_FATAL);
+ zip->entry_bytes_remaining = 0;
+
+ /* This entry is finished and done. */
+ zip->end_of_entry = 1;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_7zip_cleanup(struct archive_read *a)
+{
+ struct _7zip *zip;
+
+ zip = (struct _7zip *)(a->format->data);
+ free_StreamsInfo(&(zip->si));
+ free(zip->entries);
+ free(zip->entry_names);
+ free_decompression(a, zip);
+ free(zip->uncompressed_buffer);
+ free(zip->sub_stream_buff[0]);
+ free(zip->sub_stream_buff[1]);
+ free(zip->sub_stream_buff[2]);
+ free(zip->tmp_stream_buff);
+ free(zip);
+ (a->format->data) = NULL;
+ return (ARCHIVE_OK);
+}
+
+static void
+read_consume(struct archive_read *a)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+
+ if (zip->pack_stream_bytes_unconsumed) {
+ __archive_read_consume(a, zip->pack_stream_bytes_unconsumed);
+ zip->stream_offset += zip->pack_stream_bytes_unconsumed;
+ zip->pack_stream_bytes_unconsumed = 0;
+ }
+}
+
+#ifdef HAVE_LZMA_H
+
+/*
+ * Set an error code and choose an error message for liblzma.
+ */
+static void
+set_error(struct archive_read *a, int ret)
+{
+
+ switch (ret) {
+ case LZMA_STREAM_END: /* Found end of stream. */
+ case LZMA_OK: /* Decompressor made some progress. */
+ break;
+ case LZMA_MEM_ERROR:
+ archive_set_error(&a->archive, ENOMEM,
+ "Lzma library error: Cannot allocate memory");
+ break;
+ case LZMA_MEMLIMIT_ERROR:
+ archive_set_error(&a->archive, ENOMEM,
+ "Lzma library error: Out of memory");
+ break;
+ case LZMA_FORMAT_ERROR:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma library error: format not recognized");
+ break;
+ case LZMA_OPTIONS_ERROR:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma library error: Invalid options");
+ break;
+ case LZMA_DATA_ERROR:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma library error: Corrupted input data");
+ break;
+ case LZMA_BUF_ERROR:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma library error: No progress is possible");
+ break;
+ default:
+ /* Return an error. */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Lzma decompression failed: Unknown error");
+ break;
+ }
+}
+
+#endif
+
+static unsigned long
+decode_codec_id(const unsigned char *codecId, size_t id_size)
+{
+ unsigned i;
+ unsigned long id = 0;
+
+ for (i = 0; i < id_size; i++) {
+ id <<= 8;
+ id += codecId[i];
+ }
+ return (id);
+}
+
+static void *
+ppmd_alloc(void *p, size_t size)
+{
+ (void)p;
+ return malloc(size);
+}
+static void
+ppmd_free(void *p, void *address)
+{
+ (void)p;
+ free(address);
+}
+static Byte
+ppmd_read(void *p)
+{
+ struct archive_read *a = ((IByteIn*)p)->a;
+ struct _7zip *zip = (struct _7zip *)(a->format->data);
+ Byte b;
+
+ if (zip->ppstream.avail_in == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated RAR file data");
+ zip->ppstream.overconsumed = 1;
+ return (0);
+ }
+ b = *zip->ppstream.next_in++;
+ zip->ppstream.avail_in--;
+ zip->ppstream.total_in++;
+ return (b);
+}
+
+static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free };
+
+static int
+init_decompression(struct archive_read *a, struct _7zip *zip,
+ const struct _7z_coder *coder1, const struct _7z_coder *coder2)
+{
+ int r;
+
+ zip->codec = coder1->codec;
+ zip->codec2 = -1;
+
+ switch (zip->codec) {
+ case _7Z_COPY:
+ case _7Z_BZ2:
+ case _7Z_DEFLATE:
+ case _7Z_PPMD:
+ if (coder2 != NULL) {
+ if (coder2->codec != _7Z_X86 &&
+ coder2->codec != _7Z_X86_BCJ2) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Unsupported filter %lx for %lx",
+ coder2->codec, coder1->codec);
+ return (ARCHIVE_FAILED);
+ }
+ zip->codec2 = coder2->codec;
+ zip->bcj_state = 0;
+ if (coder2->codec == _7Z_X86)
+ x86_Init(zip);
+ }
+ break;
+ default:
+ break;
+ }
+
+ switch (zip->codec) {
+ case _7Z_COPY:
+ break;
+
+ case _7Z_LZMA: case _7Z_LZMA2:
+#ifdef HAVE_LZMA_H
+#if LZMA_VERSION_MAJOR >= 5
+/* Effectively disable the limiter. */
+#define LZMA_MEMLIMIT UINT64_MAX
+#else
+/* NOTE: This needs to check memory size which running system has. */
+#define LZMA_MEMLIMIT (1U << 30)
+#endif
+ {
+ lzma_options_delta delta_opt;
+ lzma_filter filters[LZMA_FILTERS_MAX];
+#if LZMA_VERSION < 50010000
+ lzma_filter *ff;
+#endif
+ int fi = 0;
+
+ if (zip->lzstream_valid) {
+ lzma_end(&(zip->lzstream));
+ zip->lzstream_valid = 0;
+ }
+
+ /*
+ * NOTE: liblzma incompletely handle the BCJ+LZMA compressed
+ * data made by 7-Zip because 7-Zip does not add End-Of-
+ * Payload Marker(EOPM) at the end of LZMA compressed data,
+ * and so liblzma cannot know the end of the compressed data
+ * without EOPM. So consequently liblzma will not return last
+ * three or four bytes of uncompressed data because
+ * LZMA_FILTER_X86 filter does not handle input data if its
+ * data size is less than five bytes. If liblzma detect EOPM
+ * or know the uncompressed data size, liblzma will flush out
+ * the remaining that three or four bytes of uncompressed
+ * data. That is why we have to use our converting program
+ * for BCJ+LZMA. If we were able to tell the uncompressed
+ * size to liblzma when using lzma_raw_decoder() liblzma
+ * could correctly deal with BCJ+LZMA. But unfortunately
+ * there is no way to do that.
+ * Discussion about this can be found at XZ Utils forum.
+ */
+ if (coder2 != NULL) {
+ zip->codec2 = coder2->codec;
+
+ filters[fi].options = NULL;
+ switch (zip->codec2) {
+ case _7Z_X86:
+ if (zip->codec == _7Z_LZMA2) {
+ filters[fi].id = LZMA_FILTER_X86;
+ fi++;
+ } else
+ /* Use our filter. */
+ x86_Init(zip);
+ break;
+ case _7Z_X86_BCJ2:
+ /* Use our filter. */
+ zip->bcj_state = 0;
+ break;
+ case _7Z_DELTA:
+ filters[fi].id = LZMA_FILTER_DELTA;
+ memset(&delta_opt, 0, sizeof(delta_opt));
+ delta_opt.type = LZMA_DELTA_TYPE_BYTE;
+ delta_opt.dist = 1;
+ filters[fi].options = &delta_opt;
+ fi++;
+ break;
+ /* Following filters have not been tested yet. */
+ case _7Z_POWERPC:
+ filters[fi].id = LZMA_FILTER_POWERPC;
+ fi++;
+ break;
+ case _7Z_IA64:
+ filters[fi].id = LZMA_FILTER_IA64;
+ fi++;
+ break;
+ case _7Z_ARM:
+ filters[fi].id = LZMA_FILTER_ARM;
+ fi++;
+ break;
+ case _7Z_ARMTHUMB:
+ filters[fi].id = LZMA_FILTER_ARMTHUMB;
+ fi++;
+ break;
+ case _7Z_SPARC:
+ filters[fi].id = LZMA_FILTER_SPARC;
+ fi++;
+ break;
+ default:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Unexpected codec ID: %lX", zip->codec2);
+ return (ARCHIVE_FAILED);
+ }
+ }
+
+ if (zip->codec == _7Z_LZMA2)
+ filters[fi].id = LZMA_FILTER_LZMA2;
+ else
+ filters[fi].id = LZMA_FILTER_LZMA1;
+ filters[fi].options = NULL;
+#if LZMA_VERSION < 50010000
+ ff = &filters[fi];
+#endif
+ r = lzma_properties_decode(&filters[fi], NULL,
+ coder1->properties, (size_t)coder1->propertiesSize);
+ if (r != LZMA_OK) {
+ set_error(a, r);
+ return (ARCHIVE_FAILED);
+ }
+ fi++;
+
+ filters[fi].id = LZMA_VLI_UNKNOWN;
+ filters[fi].options = NULL;
+ r = lzma_raw_decoder(&(zip->lzstream), filters);
+#if LZMA_VERSION < 50010000
+ free(ff->options);
+#endif
+ if (r != LZMA_OK) {
+ set_error(a, r);
+ return (ARCHIVE_FAILED);
+ }
+ zip->lzstream_valid = 1;
+ zip->lzstream.total_in = 0;
+ zip->lzstream.total_out = 0;
+ break;
+ }
+#else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "LZMA codec is unsupported");
+ return (ARCHIVE_FAILED);
+#endif
+ case _7Z_BZ2:
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ if (zip->bzstream_valid) {
+ BZ2_bzDecompressEnd(&(zip->bzstream));
+ zip->bzstream_valid = 0;
+ }
+ r = BZ2_bzDecompressInit(&(zip->bzstream), 0, 0);
+ if (r == BZ_MEM_ERROR)
+ r = BZ2_bzDecompressInit(&(zip->bzstream), 0, 1);
+ if (r != BZ_OK) {
+ int err = ARCHIVE_ERRNO_MISC;
+ const char *detail = NULL;
+ switch (r) {
+ case BZ_PARAM_ERROR:
+ detail = "invalid setup parameter";
+ break;
+ case BZ_MEM_ERROR:
+ err = ENOMEM;
+ detail = "out of memory";
+ break;
+ case BZ_CONFIG_ERROR:
+ detail = "mis-compiled library";
+ break;
+ }
+ archive_set_error(&a->archive, err,
+ "Internal error initializing decompressor: %s",
+ detail != NULL ? detail : "??");
+ zip->bzstream_valid = 0;
+ return (ARCHIVE_FAILED);
+ }
+ zip->bzstream_valid = 1;
+ zip->bzstream.total_in_lo32 = 0;
+ zip->bzstream.total_in_hi32 = 0;
+ zip->bzstream.total_out_lo32 = 0;
+ zip->bzstream.total_out_hi32 = 0;
+ break;
+#else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "BZ2 codec is unsupported");
+ return (ARCHIVE_FAILED);
+#endif
+ case _7Z_DEFLATE:
+#ifdef HAVE_ZLIB_H
+ if (zip->stream_valid)
+ r = inflateReset(&(zip->stream));
+ else
+ r = inflateInit2(&(zip->stream),
+ -15 /* Don't check for zlib header */);
+ if (r != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Couldn't initialize zlib stream.");
+ return (ARCHIVE_FAILED);
+ }
+ zip->stream_valid = 1;
+ zip->stream.total_in = 0;
+ zip->stream.total_out = 0;
+ break;
+#else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "DEFLATE codec is unsupported");
+ return (ARCHIVE_FAILED);
+#endif
+ case _7Z_PPMD:
+ {
+ unsigned order;
+ uint32_t msize;
+
+ if (zip->ppmd7_valid) {
+ __archive_ppmd7_functions.Ppmd7_Free(
+ &zip->ppmd7_context, &g_szalloc);
+ zip->ppmd7_valid = 0;
+ }
+
+ if (coder1->propertiesSize < 5) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Malformed PPMd parameter");
+ return (ARCHIVE_FAILED);
+ }
+ order = coder1->properties[0];
+ msize = archive_le32dec(&(coder1->properties[1]));
+ if (order < PPMD7_MIN_ORDER || order > PPMD7_MAX_ORDER ||
+ msize < PPMD7_MIN_MEM_SIZE || msize > PPMD7_MAX_MEM_SIZE) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Malformed PPMd parameter");
+ return (ARCHIVE_FAILED);
+ }
+ __archive_ppmd7_functions.Ppmd7_Construct(&zip->ppmd7_context);
+ r = __archive_ppmd7_functions.Ppmd7_Alloc(
+ &zip->ppmd7_context, msize, &g_szalloc);
+ if (r == 0) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Coludn't allocate memory for PPMd");
+ return (ARCHIVE_FATAL);
+ }
+ __archive_ppmd7_functions.Ppmd7_Init(
+ &zip->ppmd7_context, order);
+ __archive_ppmd7_functions.Ppmd7z_RangeDec_CreateVTable(
+ &zip->range_dec);
+ zip->ppmd7_valid = 1;
+ zip->ppmd7_stat = 0;
+ zip->ppstream.overconsumed = 0;
+ zip->ppstream.total_in = 0;
+ zip->ppstream.total_out = 0;
+ break;
+ }
+ case _7Z_X86:
+ case _7Z_X86_BCJ2:
+ case _7Z_POWERPC:
+ case _7Z_IA64:
+ case _7Z_ARM:
+ case _7Z_ARMTHUMB:
+ case _7Z_SPARC:
+ case _7Z_DELTA:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Unexpected codec ID: %lX", zip->codec);
+ return (ARCHIVE_FAILED);
+ case _7Z_CRYPTO_MAIN_ZIP:
+ case _7Z_CRYPTO_RAR_29:
+ case _7Z_CRYPTO_AES_256_SHA_256:
+ if (a->entry) {
+ archive_entry_set_is_metadata_encrypted(a->entry, 1);
+ archive_entry_set_is_data_encrypted(a->entry, 1);
+ zip->has_encrypted_entries = 1;
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Crypto codec not supported yet (ID: 0x%lX)", zip->codec);
+ return (ARCHIVE_FAILED);
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Unknown codec ID: %lX", zip->codec);
+ return (ARCHIVE_FAILED);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static int
+decompress(struct archive_read *a, struct _7zip *zip,
+ void *buff, size_t *outbytes, const void *b, size_t *used)
+{
+ const uint8_t *t_next_in;
+ uint8_t *t_next_out;
+ size_t o_avail_in, o_avail_out;
+ size_t t_avail_in, t_avail_out;
+ uint8_t *bcj2_next_out;
+ size_t bcj2_avail_out;
+ int r, ret = ARCHIVE_OK;
+
+ t_avail_in = o_avail_in = *used;
+ t_avail_out = o_avail_out = *outbytes;
+ t_next_in = b;
+ t_next_out = buff;
+
+ if (zip->codec != _7Z_LZMA2 && zip->codec2 == _7Z_X86) {
+ int i;
+
+ /* Do not copy out the BCJ remaining bytes when the output
+ * buffer size is less than five bytes. */
+ if (o_avail_in != 0 && t_avail_out < 5 && zip->odd_bcj_size) {
+ *used = 0;
+ *outbytes = 0;
+ return (ret);
+ }
+ for (i = 0; zip->odd_bcj_size > 0 && t_avail_out; i++) {
+ *t_next_out++ = zip->odd_bcj[i];
+ t_avail_out--;
+ zip->odd_bcj_size--;
+ }
+ if (o_avail_in == 0 || t_avail_out == 0) {
+ *used = o_avail_in - t_avail_in;
+ *outbytes = o_avail_out - t_avail_out;
+ if (o_avail_in == 0)
+ ret = ARCHIVE_EOF;
+ return (ret);
+ }
+ }
+
+ bcj2_next_out = t_next_out;
+ bcj2_avail_out = t_avail_out;
+ if (zip->codec2 == _7Z_X86_BCJ2) {
+ /*
+ * Decord a remaining decompressed main stream for BCJ2.
+ */
+ if (zip->tmp_stream_bytes_remaining) {
+ ssize_t bytes;
+ size_t remaining = zip->tmp_stream_bytes_remaining;
+ bytes = Bcj2_Decode(zip, t_next_out, t_avail_out);
+ if (bytes < 0) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "BCJ2 conversion Failed");
+ return (ARCHIVE_FAILED);
+ }
+ zip->main_stream_bytes_remaining -=
+ remaining - zip->tmp_stream_bytes_remaining;
+ t_avail_out -= bytes;
+ if (o_avail_in == 0 || t_avail_out == 0) {
+ *used = 0;
+ *outbytes = o_avail_out - t_avail_out;
+ if (o_avail_in == 0 &&
+ zip->tmp_stream_bytes_remaining)
+ ret = ARCHIVE_EOF;
+ return (ret);
+ }
+ t_next_out += bytes;
+ bcj2_next_out = t_next_out;
+ bcj2_avail_out = t_avail_out;
+ }
+ t_next_out = zip->tmp_stream_buff;
+ t_avail_out = zip->tmp_stream_buff_size;
+ }
+
+ switch (zip->codec) {
+ case _7Z_COPY:
+ {
+ size_t bytes =
+ (t_avail_in > t_avail_out)?t_avail_out:t_avail_in;
+
+ memcpy(t_next_out, t_next_in, bytes);
+ t_avail_in -= bytes;
+ t_avail_out -= bytes;
+ if (o_avail_in == 0)
+ ret = ARCHIVE_EOF;
+ break;
+ }
+#ifdef HAVE_LZMA_H
+ case _7Z_LZMA: case _7Z_LZMA2:
+ zip->lzstream.next_in = t_next_in;
+ zip->lzstream.avail_in = t_avail_in;
+ zip->lzstream.next_out = t_next_out;
+ zip->lzstream.avail_out = t_avail_out;
+
+ r = lzma_code(&(zip->lzstream), LZMA_RUN);
+ switch (r) {
+ case LZMA_STREAM_END: /* Found end of stream. */
+ lzma_end(&(zip->lzstream));
+ zip->lzstream_valid = 0;
+ ret = ARCHIVE_EOF;
+ break;
+ case LZMA_OK: /* Decompressor made some progress. */
+ break;
+ default:
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Decompression failed(%d)",
+ r);
+ return (ARCHIVE_FAILED);
+ }
+ t_avail_in = zip->lzstream.avail_in;
+ t_avail_out = zip->lzstream.avail_out;
+ break;
+#endif
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ case _7Z_BZ2:
+ zip->bzstream.next_in = (char *)(uintptr_t)t_next_in;
+ zip->bzstream.avail_in = t_avail_in;
+ zip->bzstream.next_out = (char *)(uintptr_t)t_next_out;
+ zip->bzstream.avail_out = t_avail_out;
+ r = BZ2_bzDecompress(&(zip->bzstream));
+ switch (r) {
+ case BZ_STREAM_END: /* Found end of stream. */
+ switch (BZ2_bzDecompressEnd(&(zip->bzstream))) {
+ case BZ_OK:
+ break;
+ default:
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up decompressor");
+ return (ARCHIVE_FAILED);
+ }
+ zip->bzstream_valid = 0;
+ ret = ARCHIVE_EOF;
+ break;
+ case BZ_OK: /* Decompressor made some progress. */
+ break;
+ default:
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "bzip decompression failed");
+ return (ARCHIVE_FAILED);
+ }
+ t_avail_in = zip->bzstream.avail_in;
+ t_avail_out = zip->bzstream.avail_out;
+ break;
+#endif
+#ifdef HAVE_ZLIB_H
+ case _7Z_DEFLATE:
+ zip->stream.next_in = (Bytef *)(uintptr_t)t_next_in;
+ zip->stream.avail_in = (uInt)t_avail_in;
+ zip->stream.next_out = t_next_out;
+ zip->stream.avail_out = (uInt)t_avail_out;
+ r = inflate(&(zip->stream), 0);
+ switch (r) {
+ case Z_STREAM_END: /* Found end of stream. */
+ ret = ARCHIVE_EOF;
+ break;
+ case Z_OK: /* Decompressor made some progress.*/
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "File decompression failed (%d)", r);
+ return (ARCHIVE_FAILED);
+ }
+ t_avail_in = zip->stream.avail_in;
+ t_avail_out = zip->stream.avail_out;
+ break;
+#endif
+ case _7Z_PPMD:
+ {
+ uint64_t flush_bytes;
+
+ if (!zip->ppmd7_valid || zip->ppmd7_stat < 0 ||
+ t_avail_out <= 0) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Decompression internal error");
+ return (ARCHIVE_FAILED);
+ }
+ zip->ppstream.next_in = t_next_in;
+ zip->ppstream.avail_in = t_avail_in;
+ zip->ppstream.next_out = t_next_out;
+ zip->ppstream.avail_out = t_avail_out;
+ if (zip->ppmd7_stat == 0) {
+ zip->bytein.a = a;
+ zip->bytein.Read = &ppmd_read;
+ zip->range_dec.Stream = &zip->bytein;
+ r = __archive_ppmd7_functions.Ppmd7z_RangeDec_Init(
+ &(zip->range_dec));
+ if (r == 0) {
+ zip->ppmd7_stat = -1;
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to initialize PPMd range decorder");
+ return (ARCHIVE_FAILED);
+ }
+ if (zip->ppstream.overconsumed) {
+ zip->ppmd7_stat = -1;
+ return (ARCHIVE_FAILED);
+ }
+ zip->ppmd7_stat = 1;
+ }
+
+ if (t_avail_in == 0)
+ /* XXX Flush out remaining decoded data XXX */
+ flush_bytes = zip->folder_outbytes_remaining;
+ else
+ flush_bytes = 0;
+
+ do {
+ int sym;
+
+ sym = __archive_ppmd7_functions.Ppmd7_DecodeSymbol(
+ &(zip->ppmd7_context), &(zip->range_dec.p));
+ if (sym < 0) {
+ zip->ppmd7_stat = -1;
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Failed to decode PPMd");
+ return (ARCHIVE_FAILED);
+ }
+ if (zip->ppstream.overconsumed) {
+ zip->ppmd7_stat = -1;
+ return (ARCHIVE_FAILED);
+ }
+ *zip->ppstream.next_out++ = (unsigned char)sym;
+ zip->ppstream.avail_out--;
+ zip->ppstream.total_out++;
+ if (flush_bytes)
+ flush_bytes--;
+ } while (zip->ppstream.avail_out &&
+ (zip->ppstream.avail_in || flush_bytes));
+
+ t_avail_in = (size_t)zip->ppstream.avail_in;
+ t_avail_out = (size_t)zip->ppstream.avail_out;
+ break;
+ }
+ default:
+ archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC,
+ "Decompression internal error");
+ return (ARCHIVE_FAILED);
+ }
+ if (ret != ARCHIVE_OK && ret != ARCHIVE_EOF)
+ return (ret);
+
+ *used = o_avail_in - t_avail_in;
+ *outbytes = o_avail_out - t_avail_out;
+
+ /*
+ * Decord BCJ.
+ */
+ if (zip->codec != _7Z_LZMA2 && zip->codec2 == _7Z_X86) {
+ size_t l = x86_Convert(zip, buff, *outbytes);
+ zip->odd_bcj_size = *outbytes - l;
+ if (zip->odd_bcj_size > 0 && zip->odd_bcj_size <= 4 &&
+ o_avail_in && ret != ARCHIVE_EOF) {
+ memcpy(zip->odd_bcj, ((unsigned char *)buff) + l,
+ zip->odd_bcj_size);
+ *outbytes = l;
+ } else
+ zip->odd_bcj_size = 0;
+ }
+
+ /*
+ * Decord BCJ2 with a decompressed main stream.
+ */
+ if (zip->codec2 == _7Z_X86_BCJ2) {
+ ssize_t bytes;
+
+ zip->tmp_stream_bytes_avail =
+ zip->tmp_stream_buff_size - t_avail_out;
+ if (zip->tmp_stream_bytes_avail >
+ zip->main_stream_bytes_remaining)
+ zip->tmp_stream_bytes_avail =
+ zip->main_stream_bytes_remaining;
+ zip->tmp_stream_bytes_remaining = zip->tmp_stream_bytes_avail;
+ bytes = Bcj2_Decode(zip, bcj2_next_out, bcj2_avail_out);
+ if (bytes < 0) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC, "BCJ2 conversion Failed");
+ return (ARCHIVE_FAILED);
+ }
+ zip->main_stream_bytes_remaining -=
+ zip->tmp_stream_bytes_avail
+ - zip->tmp_stream_bytes_remaining;
+ bcj2_avail_out -= bytes;
+ *outbytes = o_avail_out - bcj2_avail_out;
+ }
+
+ return (ret);
+}
+
+static int
+free_decompression(struct archive_read *a, struct _7zip *zip)
+{
+ int r = ARCHIVE_OK;
+
+#if !defined(HAVE_ZLIB_H) &&\
+ !(defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR))
+ (void)a;/* UNUSED */
+#endif
+#ifdef HAVE_LZMA_H
+ if (zip->lzstream_valid)
+ lzma_end(&(zip->lzstream));
+#endif
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ if (zip->bzstream_valid) {
+ if (BZ2_bzDecompressEnd(&(zip->bzstream)) != BZ_OK) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up bzip2 decompressor");
+ r = ARCHIVE_FATAL;
+ }
+ zip->bzstream_valid = 0;
+ }
+#endif
+#ifdef HAVE_ZLIB_H
+ if (zip->stream_valid) {
+ if (inflateEnd(&(zip->stream)) != Z_OK) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up zlib decompressor");
+ r = ARCHIVE_FATAL;
+ }
+ zip->stream_valid = 0;
+ }
+#endif
+ if (zip->ppmd7_valid) {
+ __archive_ppmd7_functions.Ppmd7_Free(
+ &zip->ppmd7_context, &g_szalloc);
+ zip->ppmd7_valid = 0;
+ }
+ return (r);
+}
+
+static int
+parse_7zip_uint64(struct archive_read *a, uint64_t *val)
+{
+ const unsigned char *p;
+ unsigned char avail, mask;
+ int i;
+
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ avail = *p;
+ mask = 0x80;
+ *val = 0;
+ for (i = 0; i < 8; i++) {
+ if (avail & mask) {
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ *val |= ((uint64_t)*p) << (8 * i);
+ mask >>= 1;
+ continue;
+ }
+ *val += (avail & (mask -1)) << (8 * i);
+ break;
+ }
+ return (0);
+}
+
+static int
+read_Bools(struct archive_read *a, unsigned char *data, size_t num)
+{
+ const unsigned char *p;
+ unsigned i, mask = 0, avail = 0;
+
+ for (i = 0; i < num; i++) {
+ if (mask == 0) {
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ avail = *p;
+ mask = 0x80;
+ }
+ data[i] = (avail & mask)?1:0;
+ mask >>= 1;
+ }
+ return (0);
+}
+
+static void
+free_Digest(struct _7z_digests *d)
+{
+ free(d->defineds);
+ free(d->digests);
+}
+
+static int
+read_Digests(struct archive_read *a, struct _7z_digests *d, size_t num)
+{
+ const unsigned char *p;
+ unsigned i;
+
+ if (num == 0)
+ return (-1);
+ memset(d, 0, sizeof(*d));
+
+ d->defineds = malloc(num);
+ if (d->defineds == NULL)
+ return (-1);
+ /*
+ * Read Bools.
+ */
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ if (*p == 0) {
+ if (read_Bools(a, d->defineds, num) < 0)
+ return (-1);
+ } else
+ /* All are defined */
+ memset(d->defineds, 1, num);
+
+ d->digests = calloc(num, sizeof(*d->digests));
+ if (d->digests == NULL)
+ return (-1);
+ for (i = 0; i < num; i++) {
+ if (d->defineds[i]) {
+ if ((p = header_bytes(a, 4)) == NULL)
+ return (-1);
+ d->digests[i] = archive_le32dec(p);
+ }
+ }
+
+ return (0);
+}
+
+static void
+free_PackInfo(struct _7z_pack_info *pi)
+{
+ free(pi->sizes);
+ free(pi->positions);
+ free_Digest(&(pi->digest));
+}
+
+static int
+read_PackInfo(struct archive_read *a, struct _7z_pack_info *pi)
+{
+ const unsigned char *p;
+ unsigned i;
+
+ memset(pi, 0, sizeof(*pi));
+
+ /*
+ * Read PackPos.
+ */
+ if (parse_7zip_uint64(a, &(pi->pos)) < 0)
+ return (-1);
+
+ /*
+ * Read NumPackStreams.
+ */
+ if (parse_7zip_uint64(a, &(pi->numPackStreams)) < 0)
+ return (-1);
+ if (pi->numPackStreams == 0)
+ return (-1);
+ if (1000000 < pi->numPackStreams)
+ return (-1);
+
+ /*
+ * Read PackSizes[num]
+ */
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ if (*p == kEnd)
+ /* PackSizes[num] are not present. */
+ return (0);
+ if (*p != kSize)
+ return (-1);
+ pi->sizes = calloc((size_t)pi->numPackStreams, sizeof(uint64_t));
+ pi->positions = calloc((size_t)pi->numPackStreams, sizeof(uint64_t));
+ if (pi->sizes == NULL || pi->positions == NULL)
+ return (-1);
+
+ for (i = 0; i < pi->numPackStreams; i++) {
+ if (parse_7zip_uint64(a, &(pi->sizes[i])) < 0)
+ return (-1);
+ }
+
+ /*
+ * Read PackStreamDigests[num]
+ */
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ if (*p == kEnd) {
+ /* PackStreamDigests[num] are not present. */
+ pi->digest.defineds =
+ calloc((size_t)pi->numPackStreams, sizeof(*pi->digest.defineds));
+ pi->digest.digests =
+ calloc((size_t)pi->numPackStreams, sizeof(*pi->digest.digests));
+ if (pi->digest.defineds == NULL || pi->digest.digests == NULL)
+ return (-1);
+ return (0);
+ }
+
+ if (*p != kSize)
+ return (-1);
+
+ if (read_Digests(a, &(pi->digest), (size_t)pi->numPackStreams) < 0)
+ return (-1);
+
+ /*
+ * Must be marked by kEnd.
+ */
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ if (*p != kEnd)
+ return (-1);
+ return (0);
+}
+
+static void
+free_Folder(struct _7z_folder *f)
+{
+ unsigned i;
+
+ if (f->coders) {
+ for (i = 0; i< f->numCoders; i++) {
+ free(f->coders[i].properties);
+ }
+ free(f->coders);
+ }
+ free(f->bindPairs);
+ free(f->packedStreams);
+ free(f->unPackSize);
+}
+
+static int
+read_Folder(struct archive_read *a, struct _7z_folder *f)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ const unsigned char *p;
+ uint64_t numInStreamsTotal = 0;
+ uint64_t numOutStreamsTotal = 0;
+ unsigned i;
+
+ memset(f, 0, sizeof(*f));
+
+ /*
+ * Read NumCoders.
+ */
+ if (parse_7zip_uint64(a, &(f->numCoders)) < 0)
+ return (-1);
+ if (f->numCoders > 4)
+ /* Too many coders. */
+ return (-1);
+
+ f->coders = calloc((size_t)f->numCoders, sizeof(*f->coders));
+ if (f->coders == NULL)
+ return (-1);
+ for (i = 0; i< f->numCoders; i++) {
+ size_t codec_size;
+ int simple, attr;
+
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ /*
+ * 0:3 CodecIdSize
+ * 4: 0 - IsSimple
+ * 1 - Is not Simple
+ * 5: 0 - No Attributes
+ * 1 - There are Attributes;
+ * 7: Must be zero.
+ */
+ codec_size = *p & 0xf;
+ simple = (*p & 0x10)?0:1;
+ attr = *p & 0x20;
+ if (*p & 0x80)
+ return (-1);/* Not supported. */
+
+ /*
+ * Read Decompression Method IDs.
+ */
+ if ((p = header_bytes(a, codec_size)) == NULL)
+ return (-1);
+
+ f->coders[i].codec = decode_codec_id(p, codec_size);
+
+ if (simple) {
+ f->coders[i].numInStreams = 1;
+ f->coders[i].numOutStreams = 1;
+ } else {
+ if (parse_7zip_uint64(
+ a, &(f->coders[i].numInStreams)) < 0)
+ return (-1);
+ if (1000000 < f->coders[i].numInStreams)
+ return (-1);
+ if (parse_7zip_uint64(
+ a, &(f->coders[i].numOutStreams)) < 0)
+ return (-1);
+ if (1000000 < f->coders[i].numOutStreams)
+ return (-1);
+ }
+
+ if (attr) {
+ if (parse_7zip_uint64(
+ a, &(f->coders[i].propertiesSize)) < 0)
+ return (-1);
+ if ((p = header_bytes(
+ a, (size_t)f->coders[i].propertiesSize)) == NULL)
+ return (-1);
+ f->coders[i].properties =
+ malloc((size_t)f->coders[i].propertiesSize);
+ if (f->coders[i].properties == NULL)
+ return (-1);
+ memcpy(f->coders[i].properties, p,
+ (size_t)f->coders[i].propertiesSize);
+ }
+
+ numInStreamsTotal += f->coders[i].numInStreams;
+ numOutStreamsTotal += f->coders[i].numOutStreams;
+ }
+
+ if (numOutStreamsTotal == 0 ||
+ numInStreamsTotal < numOutStreamsTotal-1)
+ return (-1);
+
+ f->numBindPairs = numOutStreamsTotal - 1;
+ if (zip->header_bytes_remaining < f->numBindPairs)
+ return (-1);
+ if (f->numBindPairs > 0) {
+ f->bindPairs =
+ calloc((size_t)f->numBindPairs, sizeof(*f->bindPairs));
+ if (f->bindPairs == NULL)
+ return (-1);
+ } else
+ f->bindPairs = NULL;
+ 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)
+ return (-1);
+ if (parse_7zip_uint64(a, &(f->bindPairs[i].outIndex)) < 0)
+ return (-1);
+ if (1000000 < f->bindPairs[i].outIndex)
+ return (-1);
+ }
+
+ f->numPackedStreams = numInStreamsTotal - f->numBindPairs;
+ f->packedStreams =
+ calloc((size_t)f->numPackedStreams, sizeof(*f->packedStreams));
+ if (f->packedStreams == NULL)
+ return (-1);
+ if (f->numPackedStreams == 1) {
+ for (i = 0; i < numInStreamsTotal; i++) {
+ unsigned j;
+ for (j = 0; j < f->numBindPairs; j++) {
+ if (f->bindPairs[j].inIndex == i)
+ break;
+ }
+ if (j == f->numBindPairs)
+ break;
+ }
+ if (i == numInStreamsTotal)
+ return (-1);
+ f->packedStreams[0] = i;
+ } else {
+ for (i = 0; i < f->numPackedStreams; i++) {
+ if (parse_7zip_uint64(a, &(f->packedStreams[i])) < 0)
+ return (-1);
+ if (1000000 < f->packedStreams[i])
+ return (-1);
+ }
+ }
+ f->numInStreams = numInStreamsTotal;
+ f->numOutStreams = numOutStreamsTotal;
+
+ return (0);
+}
+
+static void
+free_CodersInfo(struct _7z_coders_info *ci)
+{
+ unsigned i;
+
+ if (ci->folders) {
+ for (i = 0; i < ci->numFolders; i++)
+ free_Folder(&(ci->folders[i]));
+ free(ci->folders);
+ }
+}
+
+static int
+read_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci)
+{
+ const unsigned char *p;
+ struct _7z_digests digest;
+ unsigned i;
+
+ memset(ci, 0, sizeof(*ci));
+ memset(&digest, 0, sizeof(digest));
+
+ if ((p = header_bytes(a, 1)) == NULL)
+ goto failed;
+ if (*p != kFolder)
+ goto failed;
+
+ /*
+ * Read NumFolders.
+ */
+ if (parse_7zip_uint64(a, &(ci->numFolders)) < 0)
+ goto failed;
+ if (1000000 < ci->numFolders)
+ return (-1);
+
+ /*
+ * Read External.
+ */
+ if ((p = header_bytes(a, 1)) == NULL)
+ goto failed;
+ switch (*p) {
+ case 0:
+ ci->folders =
+ calloc((size_t)ci->numFolders, sizeof(*ci->folders));
+ if (ci->folders == NULL)
+ return (-1);
+ for (i = 0; i < ci->numFolders; i++) {
+ if (read_Folder(a, &(ci->folders[i])) < 0)
+ goto failed;
+ }
+ break;
+ case 1:
+ if (parse_7zip_uint64(a, &(ci->dataStreamIndex)) < 0)
+ return (-1);
+ if (1000000 < ci->dataStreamIndex)
+ return (-1);
+ break;
+ }
+
+ if ((p = header_bytes(a, 1)) == NULL)
+ goto failed;
+ if (*p != kCodersUnPackSize)
+ goto failed;
+
+ for (i = 0; i < ci->numFolders; i++) {
+ struct _7z_folder *folder = &(ci->folders[i]);
+ unsigned j;
+
+ folder->unPackSize =
+ calloc((size_t)folder->numOutStreams, sizeof(*folder->unPackSize));
+ if (folder->unPackSize == NULL)
+ goto failed;
+ for (j = 0; j < folder->numOutStreams; j++) {
+ if (parse_7zip_uint64(a, &(folder->unPackSize[j])) < 0)
+ goto failed;
+ }
+ }
+
+ /*
+ * Read CRCs.
+ */
+ if ((p = header_bytes(a, 1)) == NULL)
+ goto failed;
+ if (*p == kEnd)
+ return (0);
+ if (*p != kCRC)
+ goto failed;
+ if (read_Digests(a, &digest, (size_t)ci->numFolders) < 0)
+ goto failed;
+ for (i = 0; i < ci->numFolders; i++) {
+ ci->folders[i].digest_defined = digest.defineds[i];
+ ci->folders[i].digest = digest.digests[i];
+ }
+
+ /*
+ * Must be kEnd.
+ */
+ if ((p = header_bytes(a, 1)) == NULL)
+ goto failed;
+ if (*p != kEnd)
+ goto failed;
+ free_Digest(&digest);
+ return (0);
+failed:
+ free_Digest(&digest);
+ return (-1);
+}
+
+static uint64_t
+folder_uncompressed_size(struct _7z_folder *f)
+{
+ int n = (int)f->numOutStreams;
+ unsigned pairs = (unsigned)f->numBindPairs;
+
+ while (--n >= 0) {
+ unsigned i;
+ for (i = 0; i < pairs; i++) {
+ if (f->bindPairs[i].outIndex == (uint64_t)n)
+ break;
+ }
+ if (i >= pairs)
+ return (f->unPackSize[n]);
+ }
+ return (0);
+}
+
+static void
+free_SubStreamsInfo(struct _7z_substream_info *ss)
+{
+ free(ss->unpackSizes);
+ free(ss->digestsDefined);
+ free(ss->digests);
+}
+
+static int
+read_SubStreamsInfo(struct archive_read *a, struct _7z_substream_info *ss,
+ struct _7z_folder *f, size_t numFolders)
+{
+ const unsigned char *p;
+ uint64_t *usizes;
+ size_t unpack_streams;
+ int type;
+ unsigned i;
+ uint32_t numDigests;
+
+ memset(ss, 0, sizeof(*ss));
+
+ for (i = 0; i < numFolders; i++)
+ f[i].numUnpackStreams = 1;
+
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ type = *p;
+
+ if (type == kNumUnPackStream) {
+ unpack_streams = 0;
+ for (i = 0; i < numFolders; i++) {
+ if (parse_7zip_uint64(a, &(f[i].numUnpackStreams)) < 0)
+ return (-1);
+ if (1000000 < f[i].numUnpackStreams)
+ return (-1);
+ unpack_streams += (size_t)f[i].numUnpackStreams;
+ }
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ type = *p;
+ } else
+ unpack_streams = numFolders;
+
+ ss->unpack_streams = unpack_streams;
+ if (unpack_streams) {
+ ss->unpackSizes = calloc(unpack_streams,
+ sizeof(*ss->unpackSizes));
+ ss->digestsDefined = calloc(unpack_streams,
+ sizeof(*ss->digestsDefined));
+ ss->digests = calloc(unpack_streams,
+ sizeof(*ss->digests));
+ if (ss->unpackSizes == NULL || ss->digestsDefined == NULL ||
+ ss->digests == NULL)
+ return (-1);
+ }
+
+ usizes = ss->unpackSizes;
+ for (i = 0; i < numFolders; i++) {
+ unsigned pack;
+ uint64_t sum;
+
+ if (f[i].numUnpackStreams == 0)
+ continue;
+
+ sum = 0;
+ if (type == kSize) {
+ for (pack = 1; pack < f[i].numUnpackStreams; pack++) {
+ if (parse_7zip_uint64(a, usizes) < 0)
+ return (-1);
+ sum += *usizes++;
+ }
+ }
+ *usizes++ = folder_uncompressed_size(&f[i]) - sum;
+ }
+
+ if (type == kSize) {
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ type = *p;
+ }
+
+ for (i = 0; i < unpack_streams; i++) {
+ ss->digestsDefined[i] = 0;
+ ss->digests[i] = 0;
+ }
+
+ numDigests = 0;
+ for (i = 0; i < numFolders; i++) {
+ if (f[i].numUnpackStreams != 1 || !f[i].digest_defined)
+ numDigests += (uint32_t)f[i].numUnpackStreams;
+ }
+
+ if (type == kCRC) {
+ struct _7z_digests tmpDigests;
+ unsigned char *digestsDefined = ss->digestsDefined;
+ uint32_t * digests = ss->digests;
+ int di = 0;
+
+ memset(&tmpDigests, 0, sizeof(tmpDigests));
+ if (read_Digests(a, &(tmpDigests), numDigests) < 0) {
+ free_Digest(&tmpDigests);
+ return (-1);
+ }
+ for (i = 0; i < numFolders; i++) {
+ if (f[i].numUnpackStreams == 1 && f[i].digest_defined) {
+ *digestsDefined++ = 1;
+ *digests++ = f[i].digest;
+ } else {
+ unsigned j;
+
+ for (j = 0; j < f[i].numUnpackStreams;
+ j++, di++) {
+ *digestsDefined++ =
+ tmpDigests.defineds[di];
+ *digests++ =
+ tmpDigests.digests[di];
+ }
+ }
+ }
+ free_Digest(&tmpDigests);
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ type = *p;
+ }
+
+ /*
+ * Must be kEnd.
+ */
+ if (type != kEnd)
+ return (-1);
+ return (0);
+}
+
+static void
+free_StreamsInfo(struct _7z_stream_info *si)
+{
+ free_PackInfo(&(si->pi));
+ free_CodersInfo(&(si->ci));
+ free_SubStreamsInfo(&(si->ss));
+}
+
+static int
+read_StreamsInfo(struct archive_read *a, struct _7z_stream_info *si)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ const unsigned char *p;
+ unsigned i;
+
+ memset(si, 0, sizeof(*si));
+
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ if (*p == kPackInfo) {
+ uint64_t packPos;
+
+ if (read_PackInfo(a, &(si->pi)) < 0)
+ return (-1);
+
+ if (si->pi.positions == NULL || si->pi.sizes == NULL)
+ return (-1);
+ /*
+ * Calculate packed stream positions.
+ */
+ packPos = si->pi.pos;
+ for (i = 0; i < si->pi.numPackStreams; i++) {
+ si->pi.positions[i] = packPos;
+ packPos += si->pi.sizes[i];
+ if (packPos > zip->header_offset)
+ return (-1);
+ }
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ }
+ if (*p == kUnPackInfo) {
+ uint32_t packIndex;
+ struct _7z_folder *f;
+
+ if (read_CodersInfo(a, &(si->ci)) < 0)
+ return (-1);
+
+ /*
+ * Calculate packed stream indexes.
+ */
+ packIndex = 0;
+ f = si->ci.folders;
+ for (i = 0; i < si->ci.numFolders; i++) {
+ f[i].packIndex = packIndex;
+ packIndex += (uint32_t)f[i].numPackedStreams;
+ if (packIndex > si->pi.numPackStreams)
+ return (-1);
+ }
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ }
+
+ if (*p == kSubStreamsInfo) {
+ if (read_SubStreamsInfo(a, &(si->ss),
+ si->ci.folders, (size_t)si->ci.numFolders) < 0)
+ return (-1);
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ }
+
+ /*
+ * Must be kEnd.
+ */
+ if (*p != kEnd)
+ return (-1);
+ return (0);
+}
+
+static void
+free_Header(struct _7z_header_info *h)
+{
+ free(h->emptyStreamBools);
+ free(h->emptyFileBools);
+ free(h->antiBools);
+ free(h->attrBools);
+}
+
+static int
+read_Header(struct archive_read *a, struct _7z_header_info *h,
+ int check_header_id)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ const unsigned char *p;
+ struct _7z_folder *folders;
+ struct _7z_stream_info *si = &(zip->si);
+ struct _7zip_entry *entries;
+ uint32_t folderIndex, indexInFolder;
+ unsigned i;
+ int eindex, empty_streams, sindex;
+
+ if (check_header_id) {
+ /*
+ * Read Header.
+ */
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ if (*p != kHeader)
+ return (-1);
+ }
+
+ /*
+ * Read ArchiveProperties.
+ */
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ if (*p == kArchiveProperties) {
+ for (;;) {
+ uint64_t size;
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ if (*p == 0)
+ break;
+ if (parse_7zip_uint64(a, &size) < 0)
+ return (-1);
+ }
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ }
+
+ /*
+ * Read MainStreamsInfo.
+ */
+ if (*p == kMainStreamsInfo) {
+ if (read_StreamsInfo(a, &(zip->si)) < 0)
+ return (-1);
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ }
+ if (*p == kEnd)
+ return (0);
+
+ /*
+ * Read FilesInfo.
+ */
+ if (*p != kFilesInfo)
+ return (-1);
+
+ if (parse_7zip_uint64(a, &(zip->numFiles)) < 0)
+ return (-1);
+ if (1000000 < zip->numFiles)
+ return (-1);
+
+ zip->entries = calloc((size_t)zip->numFiles, sizeof(*zip->entries));
+ if (zip->entries == NULL)
+ return (-1);
+ entries = zip->entries;
+
+ empty_streams = 0;
+ for (;;) {
+ int type;
+ uint64_t size;
+ size_t ll;
+
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ type = *p;
+ if (type == kEnd)
+ break;
+
+ if (parse_7zip_uint64(a, &size) < 0)
+ return (-1);
+ if (zip->header_bytes_remaining < size)
+ return (-1);
+ ll = (size_t)size;
+
+ switch (type) {
+ case kEmptyStream:
+ h->emptyStreamBools = calloc((size_t)zip->numFiles,
+ sizeof(*h->emptyStreamBools));
+ if (h->emptyStreamBools == NULL)
+ return (-1);
+ if (read_Bools(
+ a, h->emptyStreamBools, (size_t)zip->numFiles) < 0)
+ return (-1);
+ empty_streams = 0;
+ for (i = 0; i < zip->numFiles; i++) {
+ if (h->emptyStreamBools[i])
+ empty_streams++;
+ }
+ break;
+ case kEmptyFile:
+ if (empty_streams <= 0) {
+ /* Unexcepted sequence. Skip this. */
+ if (header_bytes(a, ll) == NULL)
+ return (-1);
+ break;
+ }
+ h->emptyFileBools = calloc(empty_streams,
+ sizeof(*h->emptyFileBools));
+ if (h->emptyFileBools == NULL)
+ return (-1);
+ if (read_Bools(a, h->emptyFileBools, empty_streams) < 0)
+ return (-1);
+ break;
+ case kAnti:
+ if (empty_streams <= 0) {
+ /* Unexcepted sequence. Skip this. */
+ if (header_bytes(a, ll) == NULL)
+ return (-1);
+ break;
+ }
+ h->antiBools = calloc(empty_streams,
+ sizeof(*h->antiBools));
+ if (h->antiBools == NULL)
+ return (-1);
+ if (read_Bools(a, h->antiBools, empty_streams) < 0)
+ return (-1);
+ break;
+ case kCTime:
+ case kATime:
+ case kMTime:
+ if (read_Times(a, h, type) < 0)
+ return (-1);
+ break;
+ case kName:
+ {
+ unsigned char *np;
+ size_t nl, nb;
+
+ /* Skip one byte. */
+ if ((p = header_bytes(a, 1)) == NULL)
+ return (-1);
+ ll--;
+
+ if ((ll & 1) || ll < zip->numFiles * 4)
+ return (-1);
+
+ zip->entry_names = malloc(ll);
+ if (zip->entry_names == NULL)
+ return (-1);
+ np = zip->entry_names;
+ nb = ll;
+ /*
+ * Copy whole file names.
+ * NOTE: This loop prevents from expanding
+ * the uncompressed buffer in order not to
+ * use extra memory resource.
+ */
+ while (nb) {
+ size_t b;
+ if (nb > UBUFF_SIZE)
+ b = UBUFF_SIZE;
+ else
+ b = nb;
+ if ((p = header_bytes(a, b)) == NULL)
+ return (-1);
+ memcpy(np, p, b);
+ np += b;
+ nb -= b;
+ }
+ np = zip->entry_names;
+ nl = ll;
+
+ for (i = 0; i < zip->numFiles; i++) {
+ entries[i].utf16name = np;
+#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG)
+ entries[i].wname = (wchar_t *)np;
+#endif
+
+ /* Find a terminator. */
+ while (nl >= 2 && (np[0] || np[1])) {
+ np += 2;
+ nl -= 2;
+ }
+ if (nl < 2)
+ return (-1);/* Terminator not found */
+ entries[i].name_len = np - entries[i].utf16name;
+ np += 2;
+ nl -= 2;
+ }
+ break;
+ }
+ case kAttributes:
+ {
+ int allAreDefined;
+
+ if ((p = header_bytes(a, 2)) == NULL)
+ return (-1);
+ allAreDefined = *p;
+ h->attrBools = calloc((size_t)zip->numFiles,
+ sizeof(*h->attrBools));
+ if (h->attrBools == NULL)
+ return (-1);
+ if (allAreDefined)
+ memset(h->attrBools, 1, (size_t)zip->numFiles);
+ else {
+ if (read_Bools(a, h->attrBools,
+ (size_t)zip->numFiles) < 0)
+ return (-1);
+ }
+ for (i = 0; i < zip->numFiles; i++) {
+ if (h->attrBools[i]) {
+ if ((p = header_bytes(a, 4)) == NULL)
+ return (-1);
+ entries[i].attr = archive_le32dec(p);
+ }
+ }
+ break;
+ }
+ default:
+ if (header_bytes(a, ll) == NULL)
+ return (-1);
+ break;
+ }
+ }
+
+ /*
+ * Set up entry's attributes.
+ */
+ folders = si->ci.folders;
+ eindex = sindex = 0;
+ folderIndex = indexInFolder = 0;
+ for (i = 0; i < zip->numFiles; i++) {
+ if (h->emptyStreamBools == NULL || h->emptyStreamBools[i] == 0)
+ entries[i].flg |= HAS_STREAM;
+ /* The high 16 bits of attributes is a posix file mode. */
+ entries[i].mode = entries[i].attr >> 16;
+ if (entries[i].flg & HAS_STREAM) {
+ if ((size_t)sindex >= si->ss.unpack_streams)
+ return (-1);
+ if (entries[i].mode == 0)
+ entries[i].mode = AE_IFREG | 0666;
+ if (si->ss.digestsDefined[sindex])
+ entries[i].flg |= CRC32_IS_SET;
+ entries[i].ssIndex = sindex;
+ sindex++;
+ } else {
+ int dir;
+ if (h->emptyFileBools == NULL)
+ dir = 1;
+ else {
+ if (h->emptyFileBools[eindex])
+ dir = 0;
+ else
+ dir = 1;
+ eindex++;
+ }
+ if (entries[i].mode == 0) {
+ if (dir)
+ entries[i].mode = AE_IFDIR | 0777;
+ else
+ entries[i].mode = AE_IFREG | 0666;
+ } else if (dir &&
+ (entries[i].mode & AE_IFMT) != AE_IFDIR) {
+ entries[i].mode &= ~AE_IFMT;
+ entries[i].mode |= AE_IFDIR;
+ }
+ if ((entries[i].mode & AE_IFMT) == AE_IFDIR &&
+ entries[i].name_len >= 2 &&
+ (entries[i].utf16name[entries[i].name_len-2] != '/' ||
+ entries[i].utf16name[entries[i].name_len-1] != 0)) {
+ entries[i].utf16name[entries[i].name_len] = '/';
+ entries[i].utf16name[entries[i].name_len+1] = 0;
+ entries[i].name_len += 2;
+ }
+ entries[i].ssIndex = -1;
+ }
+ if (entries[i].attr & 0x01)
+ entries[i].mode &= ~0222;/* Read only. */
+
+ if ((entries[i].flg & HAS_STREAM) == 0 && indexInFolder == 0) {
+ /*
+ * The entry is an empty file or a directory file,
+ * those both have no contents.
+ */
+ entries[i].folderIndex = -1;
+ continue;
+ }
+ if (indexInFolder == 0) {
+ for (;;) {
+ if (folderIndex >= si->ci.numFolders)
+ return (-1);
+ if (folders[folderIndex].numUnpackStreams)
+ break;
+ folderIndex++;
+ }
+ }
+ entries[i].folderIndex = folderIndex;
+ if ((entries[i].flg & HAS_STREAM) == 0)
+ continue;
+ indexInFolder++;
+ if (indexInFolder >= folders[folderIndex].numUnpackStreams) {
+ folderIndex++;
+ indexInFolder = 0;
+ }
+ }
+
+ return (0);
+}
+
+#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
+static void
+fileTimeToUtc(uint64_t fileTime, time_t *timep, long *ns)
+{
+
+ if (fileTime >= EPOC_TIME) {
+ fileTime -= EPOC_TIME;
+ /* milli seconds base */
+ *timep = (time_t)(fileTime / 10000000);
+ /* nano seconds base */
+ *ns = (long)(fileTime % 10000000) * 100;
+ } else {
+ *timep = 0;
+ *ns = 0;
+ }
+}
+
+static int
+read_Times(struct archive_read *a, struct _7z_header_info *h, int type)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ const unsigned char *p;
+ struct _7zip_entry *entries = zip->entries;
+ unsigned char *timeBools;
+ int allAreDefined;
+ unsigned i;
+
+ timeBools = calloc((size_t)zip->numFiles, sizeof(*timeBools));
+ if (timeBools == NULL)
+ return (-1);
+
+ /* Read allAreDefined. */
+ if ((p = header_bytes(a, 1)) == NULL)
+ goto failed;
+ allAreDefined = *p;
+ if (allAreDefined)
+ memset(timeBools, 1, (size_t)zip->numFiles);
+ else {
+ if (read_Bools(a, timeBools, (size_t)zip->numFiles) < 0)
+ goto failed;
+ }
+
+ /* Read external. */
+ if ((p = header_bytes(a, 1)) == NULL)
+ goto failed;
+ if (*p) {
+ if (parse_7zip_uint64(a, &(h->dataIndex)) < 0)
+ goto failed;
+ if (1000000 < h->dataIndex)
+ goto failed;
+ }
+
+ for (i = 0; i < zip->numFiles; i++) {
+ if (!timeBools[i])
+ continue;
+ if ((p = header_bytes(a, 8)) == NULL)
+ goto failed;
+ switch (type) {
+ case kCTime:
+ fileTimeToUtc(archive_le64dec(p),
+ &(entries[i].ctime),
+ &(entries[i].ctime_ns));
+ entries[i].flg |= CTIME_IS_SET;
+ break;
+ case kATime:
+ fileTimeToUtc(archive_le64dec(p),
+ &(entries[i].atime),
+ &(entries[i].atime_ns));
+ entries[i].flg |= ATIME_IS_SET;
+ break;
+ case kMTime:
+ fileTimeToUtc(archive_le64dec(p),
+ &(entries[i].mtime),
+ &(entries[i].mtime_ns));
+ entries[i].flg |= MTIME_IS_SET;
+ break;
+ }
+ }
+
+ free(timeBools);
+ return (0);
+failed:
+ free(timeBools);
+ return (-1);
+}
+
+static int
+decode_encoded_header_info(struct archive_read *a, struct _7z_stream_info *si)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+
+ errno = 0;
+ if (read_StreamsInfo(a, si) < 0) {
+ if (errno == ENOMEM)
+ archive_set_error(&a->archive, -1,
+ "Couldn't allocate memory");
+ else
+ archive_set_error(&a->archive, -1,
+ "Malformed 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (si->pi.numPackStreams == 0 || si->ci.numFolders == 0) {
+ archive_set_error(&a->archive, -1, "Malformed 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (zip->header_offset < si->pi.pos + si->pi.sizes[0] ||
+ (int64_t)(si->pi.pos + si->pi.sizes[0]) < 0 ||
+ si->pi.sizes[0] == 0 || (int64_t)si->pi.pos < 0) {
+ archive_set_error(&a->archive, -1, "Malformed Header offset");
+ return (ARCHIVE_FATAL);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static const unsigned char *
+header_bytes(struct archive_read *a, size_t rbytes)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ const unsigned char *p;
+
+ if (zip->header_bytes_remaining < rbytes)
+ return (NULL);
+ if (zip->pack_stream_bytes_unconsumed)
+ read_consume(a);
+
+ if (zip->header_is_encoded == 0) {
+ p = __archive_read_ahead(a, rbytes, NULL);
+ if (p == NULL)
+ return (NULL);
+ zip->header_bytes_remaining -= rbytes;
+ zip->pack_stream_bytes_unconsumed = rbytes;
+ } else {
+ const void *buff;
+ ssize_t bytes;
+
+ bytes = read_stream(a, &buff, rbytes, rbytes);
+ if (bytes <= 0)
+ return (NULL);
+ zip->header_bytes_remaining -= bytes;
+ p = buff;
+ }
+
+ /* Update checksum */
+ zip->header_crc32 = crc32(zip->header_crc32, p, (unsigned)rbytes);
+ return (p);
+}
+
+static int
+slurp_central_directory(struct archive_read *a, struct _7zip *zip,
+ struct _7z_header_info *header)
+{
+ const unsigned char *p;
+ uint64_t next_header_offset;
+ uint64_t next_header_size;
+ uint32_t next_header_crc;
+ ssize_t bytes_avail;
+ int check_header_crc, r;
+
+ if ((p = __archive_read_ahead(a, 32, &bytes_avail)) == NULL)
+ return (ARCHIVE_FATAL);
+
+ if ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0) {
+ /* This is an executable ? Must be self-extracting... */
+ r = skip_sfx(a, bytes_avail);
+ if (r < ARCHIVE_WARN)
+ return (r);
+ if ((p = __archive_read_ahead(a, 32, &bytes_avail)) == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ zip->seek_base += 32;
+
+ if (memcmp(p, _7ZIP_SIGNATURE, 6) != 0) {
+ archive_set_error(&a->archive, -1, "Not 7-Zip archive file");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* CRC check. */
+ if (crc32(0, (const unsigned char *)p + 12, 20)
+ != archive_le32dec(p + 8)) {
+ archive_set_error(&a->archive, -1, "Header CRC error");
+ return (ARCHIVE_FATAL);
+ }
+
+ next_header_offset = archive_le64dec(p + 12);
+ next_header_size = archive_le64dec(p + 20);
+ next_header_crc = archive_le32dec(p + 28);
+
+ if (next_header_size == 0)
+ /* There is no entry in an archive file. */
+ return (ARCHIVE_EOF);
+
+ if (((int64_t)next_header_offset) < 0) {
+ archive_set_error(&a->archive, -1, "Malformed 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+ __archive_read_consume(a, 32);
+ if (next_header_offset != 0) {
+ if (bytes_avail >= (ssize_t)next_header_offset)
+ __archive_read_consume(a, next_header_offset);
+ else if (__archive_read_seek(a,
+ next_header_offset + zip->seek_base, SEEK_SET) < 0)
+ return (ARCHIVE_FATAL);
+ }
+ zip->stream_offset = next_header_offset;
+ zip->header_offset = next_header_offset;
+ zip->header_bytes_remaining = next_header_size;
+ zip->header_crc32 = 0;
+ zip->header_is_encoded = 0;
+ zip->header_is_being_read = 1;
+ zip->has_encrypted_entries = 0;
+ check_header_crc = 1;
+
+ if ((p = header_bytes(a, 1)) == NULL) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated 7-Zip file body");
+ return (ARCHIVE_FATAL);
+ }
+ /* Parse ArchiveProperties. */
+ switch (p[0]) {
+ case kEncodedHeader:
+ /*
+ * The archive has an encoded header and we have to decode it
+ * in order to parse the header correctly.
+ */
+ r = decode_encoded_header_info(a, &(zip->si));
+
+ /* Check the EncodedHeader CRC.*/
+ if (r == 0 && zip->header_crc32 != next_header_crc) {
+ archive_set_error(&a->archive, -1,
+ "Damaged 7-Zip archive");
+ r = -1;
+ }
+ if (r == 0) {
+ if (zip->si.ci.folders[0].digest_defined)
+ next_header_crc = zip->si.ci.folders[0].digest;
+ else
+ check_header_crc = 0;
+ if (zip->pack_stream_bytes_unconsumed)
+ read_consume(a);
+ r = setup_decode_folder(a, zip->si.ci.folders, 1);
+ if (r == 0) {
+ zip->header_bytes_remaining =
+ zip->folder_outbytes_remaining;
+ r = seek_pack(a);
+ }
+ }
+ /* Clean up StreamsInfo. */
+ free_StreamsInfo(&(zip->si));
+ memset(&(zip->si), 0, sizeof(zip->si));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ zip->header_is_encoded = 1;
+ zip->header_crc32 = 0;
+ /* FALL THROUGH */
+ case kHeader:
+ /*
+ * Parse the header.
+ */
+ errno = 0;
+ r = read_Header(a, header, zip->header_is_encoded);
+ if (r < 0) {
+ if (errno == ENOMEM)
+ archive_set_error(&a->archive, -1,
+ "Couldn't allocate memory");
+ else
+ archive_set_error(&a->archive, -1,
+ "Damaged 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Must be kEnd.
+ */
+ if ((p = header_bytes(a, 1)) == NULL ||*p != kEnd) {
+ archive_set_error(&a->archive, -1,
+ "Malformed 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Check the Header CRC.*/
+ if (check_header_crc && zip->header_crc32 != next_header_crc) {
+ archive_set_error(&a->archive, -1,
+ "Malformed 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+ break;
+ default:
+ archive_set_error(&a->archive, -1,
+ "Unexpected Property ID = %X", p[0]);
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Clean up variables be used for decoding the archive header */
+ zip->pack_stream_remaining = 0;
+ zip->pack_stream_index = 0;
+ zip->folder_outbytes_remaining = 0;
+ zip->uncompressed_buffer_bytes_remaining = 0;
+ zip->pack_stream_bytes_unconsumed = 0;
+ zip->header_is_being_read = 0;
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+get_uncompressed_data(struct archive_read *a, const void **buff, size_t size,
+ size_t minimum)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ ssize_t bytes_avail;
+
+ if (zip->codec == _7Z_COPY && zip->codec2 == (unsigned long)-1) {
+ /* Copy mode. */
+
+ /*
+ * Note: '1' here is a performance optimization.
+ * Recall that the decompression layer returns a count of
+ * available bytes; asking for more than that forces the
+ * decompressor to combine reads by copying data.
+ */
+ *buff = __archive_read_ahead(a, 1, &bytes_avail);
+ if (bytes_avail <= 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated 7-Zip file data");
+ return (ARCHIVE_FATAL);
+ }
+ if ((size_t)bytes_avail >
+ zip->uncompressed_buffer_bytes_remaining)
+ bytes_avail = (ssize_t)
+ zip->uncompressed_buffer_bytes_remaining;
+ if ((size_t)bytes_avail > size)
+ bytes_avail = (ssize_t)size;
+
+ zip->pack_stream_bytes_unconsumed = bytes_avail;
+ } else if (zip->uncompressed_buffer_pointer == NULL) {
+ /* Decompression has failed. */
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ } else {
+ /* Packed mode. */
+ if (minimum > zip->uncompressed_buffer_bytes_remaining) {
+ /*
+ * If remaining uncompressed data size is less than
+ * the minimum size, fill the buffer up to the
+ * minimum size.
+ */
+ if (extract_pack_stream(a, minimum) < 0)
+ return (ARCHIVE_FATAL);
+ }
+ if (size > zip->uncompressed_buffer_bytes_remaining)
+ bytes_avail = (ssize_t)
+ zip->uncompressed_buffer_bytes_remaining;
+ else
+ bytes_avail = (ssize_t)size;
+ *buff = zip->uncompressed_buffer_pointer;
+ zip->uncompressed_buffer_pointer += bytes_avail;
+ }
+ zip->uncompressed_buffer_bytes_remaining -= bytes_avail;
+ return (bytes_avail);
+}
+
+static ssize_t
+extract_pack_stream(struct archive_read *a, size_t minimum)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ ssize_t bytes_avail;
+ int r;
+
+ if (zip->codec == _7Z_COPY && zip->codec2 == (unsigned long)-1) {
+ if (minimum == 0)
+ minimum = 1;
+ if (__archive_read_ahead(a, minimum, &bytes_avail) == NULL
+ || bytes_avail <= 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated 7-Zip file body");
+ return (ARCHIVE_FATAL);
+ }
+ if (bytes_avail > (ssize_t)zip->pack_stream_inbytes_remaining)
+ bytes_avail = (ssize_t)zip->pack_stream_inbytes_remaining;
+ zip->pack_stream_inbytes_remaining -= bytes_avail;
+ if (bytes_avail > (ssize_t)zip->folder_outbytes_remaining)
+ bytes_avail = (ssize_t)zip->folder_outbytes_remaining;
+ zip->folder_outbytes_remaining -= bytes_avail;
+ zip->uncompressed_buffer_bytes_remaining = bytes_avail;
+ return (ARCHIVE_OK);
+ }
+
+ /* If the buffer hasn't been allocated, allocate it now. */
+ if (zip->uncompressed_buffer == NULL) {
+ zip->uncompressed_buffer_size = UBUFF_SIZE;
+ if (zip->uncompressed_buffer_size < minimum) {
+ zip->uncompressed_buffer_size = minimum + 1023;
+ zip->uncompressed_buffer_size &= ~0x3ff;
+ }
+ zip->uncompressed_buffer =
+ malloc(zip->uncompressed_buffer_size);
+ if (zip->uncompressed_buffer == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for 7-Zip decompression");
+ return (ARCHIVE_FATAL);
+ }
+ zip->uncompressed_buffer_bytes_remaining = 0;
+ } else if (zip->uncompressed_buffer_size < minimum ||
+ zip->uncompressed_buffer_bytes_remaining < minimum) {
+ /*
+ * Make sure the uncompressed buffer can have bytes
+ * at least `minimum' bytes.
+ * NOTE: This case happen when reading the header.
+ */
+ size_t used;
+ if (zip->uncompressed_buffer_pointer != 0)
+ used = zip->uncompressed_buffer_pointer -
+ zip->uncompressed_buffer;
+ else
+ used = 0;
+ if (zip->uncompressed_buffer_size < minimum) {
+ /*
+ * Expand the uncompressed buffer up to
+ * the minimum size.
+ */
+ void *p;
+ size_t new_size;
+
+ new_size = minimum + 1023;
+ new_size &= ~0x3ff;
+ p = realloc(zip->uncompressed_buffer, new_size);
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for 7-Zip decompression");
+ return (ARCHIVE_FATAL);
+ }
+ zip->uncompressed_buffer = (unsigned char *)p;
+ zip->uncompressed_buffer_size = new_size;
+ }
+ /*
+ * Move unconsumed bytes to the head.
+ */
+ if (used) {
+ memmove(zip->uncompressed_buffer,
+ zip->uncompressed_buffer + used,
+ zip->uncompressed_buffer_bytes_remaining);
+ }
+ } else
+ zip->uncompressed_buffer_bytes_remaining = 0;
+ zip->uncompressed_buffer_pointer = NULL;
+ for (;;) {
+ size_t bytes_in, bytes_out;
+ const void *buff_in;
+ unsigned char *buff_out;
+ int end_of_data;
+
+ /*
+ * Note: '1' here is a performance optimization.
+ * Recall that the decompression layer returns a count of
+ * available bytes; asking for more than that forces the
+ * decompressor to combine reads by copying data.
+ */
+ buff_in = __archive_read_ahead(a, 1, &bytes_avail);
+ if (bytes_avail <= 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated 7-Zip file body");
+ return (ARCHIVE_FATAL);
+ }
+
+ buff_out = zip->uncompressed_buffer
+ + zip->uncompressed_buffer_bytes_remaining;
+ bytes_out = zip->uncompressed_buffer_size
+ - zip->uncompressed_buffer_bytes_remaining;
+ bytes_in = bytes_avail;
+ if (bytes_in > zip->pack_stream_inbytes_remaining)
+ bytes_in = (size_t)zip->pack_stream_inbytes_remaining;
+ /* Drive decompression. */
+ r = decompress(a, zip, buff_out, &bytes_out,
+ buff_in, &bytes_in);
+ switch (r) {
+ case ARCHIVE_OK:
+ end_of_data = 0;
+ break;
+ case ARCHIVE_EOF:
+ end_of_data = 1;
+ break;
+ default:
+ return (ARCHIVE_FATAL);
+ }
+ zip->pack_stream_inbytes_remaining -= bytes_in;
+ if (bytes_out > zip->folder_outbytes_remaining)
+ bytes_out = (size_t)zip->folder_outbytes_remaining;
+ zip->folder_outbytes_remaining -= bytes_out;
+ zip->uncompressed_buffer_bytes_remaining += bytes_out;
+ zip->pack_stream_bytes_unconsumed = bytes_in;
+
+ /*
+ * Continue decompression until uncompressed_buffer is full.
+ */
+ if (zip->uncompressed_buffer_bytes_remaining ==
+ zip->uncompressed_buffer_size)
+ break;
+ if (zip->codec2 == _7Z_X86 && zip->odd_bcj_size &&
+ zip->uncompressed_buffer_bytes_remaining + 5 >
+ zip->uncompressed_buffer_size)
+ break;
+ if (zip->pack_stream_inbytes_remaining == 0 &&
+ zip->folder_outbytes_remaining == 0)
+ break;
+ if (end_of_data || (bytes_in == 0 && bytes_out == 0)) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+ read_consume(a);
+ }
+ if (zip->uncompressed_buffer_bytes_remaining < minimum) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+ zip->uncompressed_buffer_pointer = zip->uncompressed_buffer;
+ return (ARCHIVE_OK);
+}
+
+static int
+seek_pack(struct archive_read *a)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ int64_t pack_offset;
+
+ if (zip->pack_stream_remaining <= 0) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+ zip->pack_stream_inbytes_remaining =
+ zip->si.pi.sizes[zip->pack_stream_index];
+ pack_offset = zip->si.pi.positions[zip->pack_stream_index];
+ if (zip->stream_offset != pack_offset) {
+ if (0 > __archive_read_seek(a, pack_offset + zip->seek_base,
+ SEEK_SET))
+ return (ARCHIVE_FATAL);
+ zip->stream_offset = pack_offset;
+ }
+ zip->pack_stream_index++;
+ zip->pack_stream_remaining--;
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+read_stream(struct archive_read *a, const void **buff, size_t size,
+ size_t minimum)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ uint64_t skip_bytes = 0;
+ ssize_t r;
+
+ if (zip->uncompressed_buffer_bytes_remaining == 0) {
+ if (zip->pack_stream_inbytes_remaining > 0) {
+ r = extract_pack_stream(a, 0);
+ if (r < 0)
+ return (r);
+ return (get_uncompressed_data(a, buff, size, minimum));
+ } else if (zip->folder_outbytes_remaining > 0) {
+ /* Extract a remaining pack stream. */
+ r = extract_pack_stream(a, 0);
+ if (r < 0)
+ return (r);
+ return (get_uncompressed_data(a, buff, size, minimum));
+ }
+ } else
+ return (get_uncompressed_data(a, buff, size, minimum));
+
+ /*
+ * Current pack stream has been consumed.
+ */
+ if (zip->pack_stream_remaining == 0) {
+ if (zip->header_is_being_read) {
+ /* Invalid sequence. This might happen when
+ * reading a malformed archive. */
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC, "Malformed 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * All current folder's pack streams have been
+ * consumed. Switch to next folder.
+ */
+ if (zip->folder_index == 0 &&
+ (zip->si.ci.folders[zip->entry->folderIndex].skipped_bytes
+ || zip->folder_index != zip->entry->folderIndex)) {
+ zip->folder_index = zip->entry->folderIndex;
+ skip_bytes =
+ zip->si.ci.folders[zip->folder_index].skipped_bytes;
+ }
+
+ if (zip->folder_index >= zip->si.ci.numFolders) {
+ /*
+ * We have consumed all folders and its pack streams.
+ */
+ *buff = NULL;
+ return (0);
+ }
+ r = setup_decode_folder(a,
+ &(zip->si.ci.folders[zip->folder_index]), 0);
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ zip->folder_index++;
+ }
+
+ /*
+ * Switch to next pack stream.
+ */
+ r = seek_pack(a);
+ if (r < 0)
+ return (r);
+
+ /* Extract a new pack stream. */
+ r = extract_pack_stream(a, 0);
+ if (r < 0)
+ return (r);
+
+ /*
+ * Skip the bytes we alrady has skipped in skip_stream().
+ */
+ while (skip_bytes) {
+ ssize_t skipped;
+
+ if (zip->uncompressed_buffer_bytes_remaining == 0) {
+ if (zip->pack_stream_inbytes_remaining > 0) {
+ r = extract_pack_stream(a, 0);
+ if (r < 0)
+ return (r);
+ } else if (zip->folder_outbytes_remaining > 0) {
+ /* Extract a remaining pack stream. */
+ r = extract_pack_stream(a, 0);
+ if (r < 0)
+ return (r);
+ } else {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated 7-Zip file body");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ skipped = get_uncompressed_data(
+ a, buff, (size_t)skip_bytes, 0);
+ if (skipped < 0)
+ return (skipped);
+ skip_bytes -= skipped;
+ if (zip->pack_stream_bytes_unconsumed)
+ read_consume(a);
+ }
+
+ return (get_uncompressed_data(a, buff, size, minimum));
+}
+
+static int
+setup_decode_folder(struct archive_read *a, struct _7z_folder *folder,
+ int header)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ const struct _7z_coder *coder1, *coder2;
+ const char *cname = (header)?"archive header":"file content";
+ unsigned i;
+ int r, found_bcj2 = 0;
+
+ /*
+ * Release the memory which the previous folder used for BCJ2.
+ */
+ for (i = 0; i < 3; i++) {
+ if (zip->sub_stream_buff[i] != NULL)
+ free(zip->sub_stream_buff[i]);
+ zip->sub_stream_buff[i] = NULL;
+ }
+
+ /*
+ * Initialize a stream reader.
+ */
+ zip->pack_stream_remaining = (unsigned)folder->numPackedStreams;
+ zip->pack_stream_index = (unsigned)folder->packIndex;
+ zip->folder_outbytes_remaining = folder_uncompressed_size(folder);
+ zip->uncompressed_buffer_bytes_remaining = 0;
+
+ /*
+ * Check coder types.
+ */
+ for (i = 0; i < folder->numCoders; i++) {
+ switch(folder->coders[i].codec) {
+ case _7Z_CRYPTO_MAIN_ZIP:
+ case _7Z_CRYPTO_RAR_29:
+ case _7Z_CRYPTO_AES_256_SHA_256: {
+ /* For entry that is associated with this folder, mark
+ it as encrypted (data+metadata). */
+ zip->has_encrypted_entries = 1;
+ if (a->entry) {
+ archive_entry_set_is_data_encrypted(a->entry, 1);
+ archive_entry_set_is_metadata_encrypted(a->entry, 1);
+ }
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "The %s is encrypted, "
+ "but currently not supported", cname);
+ return (ARCHIVE_FATAL);
+ }
+ case _7Z_X86_BCJ2: {
+ found_bcj2++;
+ break;
+ }
+ }
+ }
+ /* Now that we've checked for encryption, if there were still no
+ * encrypted entries found we can say for sure that there are none.
+ */
+ if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
+ zip->has_encrypted_entries = 0;
+ }
+
+ if ((folder->numCoders > 2 && !found_bcj2) || found_bcj2 > 1) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "The %s is encoded with many filters, "
+ "but currently not supported", cname);
+ return (ARCHIVE_FATAL);
+ }
+ coder1 = &(folder->coders[0]);
+ if (folder->numCoders == 2)
+ coder2 = &(folder->coders[1]);
+ else
+ coder2 = NULL;
+
+ if (found_bcj2) {
+ /*
+ * Preparation to decode BCJ2.
+ * Decoding BCJ2 requires four sources. Those are at least,
+ * as far as I know, two types of the storage form.
+ */
+ const struct _7z_coder *fc = folder->coders;
+ static const struct _7z_coder coder_copy = {0, 1, 1, 0, NULL};
+ const struct _7z_coder *scoder[3] =
+ {&coder_copy, &coder_copy, &coder_copy};
+ const void *buff;
+ ssize_t bytes;
+ unsigned char *b[3] = {NULL, NULL, NULL};
+ uint64_t sunpack[3] ={-1, -1, -1};
+ size_t s[3] = {0, 0, 0};
+ int idx[3] = {0, 1, 2};
+
+ if (folder->numCoders == 4 && fc[3].codec == _7Z_X86_BCJ2 &&
+ folder->numInStreams == 7 && folder->numOutStreams == 4 &&
+ zip->pack_stream_remaining == 4) {
+ /* Source type 1 made by 7zr or 7z with -m options. */
+ if (folder->bindPairs[0].inIndex == 5) {
+ /* The form made by 7zr */
+ idx[0] = 1; idx[1] = 2; idx[2] = 0;
+ scoder[1] = &(fc[1]);
+ scoder[2] = &(fc[0]);
+ sunpack[1] = folder->unPackSize[1];
+ sunpack[2] = folder->unPackSize[0];
+ coder1 = &(fc[2]);
+ } else {
+ /*
+ * NOTE: Some patterns do not work.
+ * work:
+ * 7z a -m0=BCJ2 -m1=COPY -m2=COPY
+ * -m3=(any)
+ * 7z a -m0=BCJ2 -m1=COPY -m2=(any)
+ * -m3=COPY
+ * 7z a -m0=BCJ2 -m1=(any) -m2=COPY
+ * -m3=COPY
+ * not work:
+ * other patterns.
+ *
+ * We have to handle this like `pipe' or
+ * our libarchive7s filter frame work,
+ * decoding the BCJ2 main stream sequentially,
+ * m3 -> m2 -> m1 -> BCJ2.
+ *
+ */
+ if (fc[0].codec == _7Z_COPY &&
+ fc[1].codec == _7Z_COPY)
+ coder1 = &(folder->coders[2]);
+ else if (fc[0].codec == _7Z_COPY &&
+ fc[2].codec == _7Z_COPY)
+ coder1 = &(folder->coders[1]);
+ else if (fc[1].codec == _7Z_COPY &&
+ fc[2].codec == _7Z_COPY)
+ coder1 = &(folder->coders[0]);
+ else {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Unsupported form of "
+ "BCJ2 streams");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ coder2 = &(fc[3]);
+ zip->main_stream_bytes_remaining =
+ (size_t)folder->unPackSize[2];
+ } else if (coder2 != NULL && coder2->codec == _7Z_X86_BCJ2 &&
+ zip->pack_stream_remaining == 4 &&
+ folder->numInStreams == 5 && folder->numOutStreams == 2) {
+ /* Source type 0 made by 7z */
+ zip->main_stream_bytes_remaining =
+ (size_t)folder->unPackSize[0];
+ } else {
+ /* We got an unexpected form. */
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Unsupported form of BCJ2 streams");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Skip the main stream at this time. */
+ if ((r = seek_pack(a)) < 0)
+ return (r);
+ zip->pack_stream_bytes_unconsumed =
+ (size_t)zip->pack_stream_inbytes_remaining;
+ read_consume(a);
+
+ /* Read following three sub streams. */
+ for (i = 0; i < 3; i++) {
+ const struct _7z_coder *coder = scoder[i];
+
+ if ((r = seek_pack(a)) < 0) {
+ free(b[0]); free(b[1]); free(b[2]);
+ return (r);
+ }
+
+ if (sunpack[i] == (uint64_t)-1)
+ zip->folder_outbytes_remaining =
+ zip->pack_stream_inbytes_remaining;
+ else
+ zip->folder_outbytes_remaining = sunpack[i];
+
+ r = init_decompression(a, zip, coder, NULL);
+ if (r != ARCHIVE_OK) {
+ free(b[0]); free(b[1]); free(b[2]);
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Allocate memory for the decorded data of a sub
+ * stream. */
+ b[i] = malloc((size_t)zip->folder_outbytes_remaining);
+ if (b[i] == NULL) {
+ free(b[0]); free(b[1]); free(b[2]);
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for 7-Zip decompression");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Extract a sub stream. */
+ while (zip->pack_stream_inbytes_remaining > 0) {
+ r = (int)extract_pack_stream(a, 0);
+ if (r < 0) {
+ free(b[0]); free(b[1]); free(b[2]);
+ return (r);
+ }
+ bytes = get_uncompressed_data(a, &buff,
+ zip->uncompressed_buffer_bytes_remaining,
+ 0);
+ if (bytes < 0) {
+ free(b[0]); free(b[1]); free(b[2]);
+ return ((int)bytes);
+ }
+ memcpy(b[i]+s[i], buff, bytes);
+ s[i] += bytes;
+ if (zip->pack_stream_bytes_unconsumed)
+ read_consume(a);
+ }
+ }
+
+ /* Set the sub streams to the right place. */
+ for (i = 0; i < 3; i++) {
+ zip->sub_stream_buff[i] = b[idx[i]];
+ zip->sub_stream_size[i] = s[idx[i]];
+ zip->sub_stream_bytes_remaining[i] = s[idx[i]];
+ }
+
+ /* Allocate memory used for decoded main stream bytes. */
+ if (zip->tmp_stream_buff == NULL) {
+ zip->tmp_stream_buff_size = 32 * 1024;
+ zip->tmp_stream_buff =
+ malloc(zip->tmp_stream_buff_size);
+ if (zip->tmp_stream_buff == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for 7-Zip decompression");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ zip->tmp_stream_bytes_avail = 0;
+ zip->tmp_stream_bytes_remaining = 0;
+ zip->odd_bcj_size = 0;
+ zip->bcj2_outPos = 0;
+
+ /*
+ * Reset a stream reader in order to read the main stream
+ * of BCJ2.
+ */
+ zip->pack_stream_remaining = 1;
+ zip->pack_stream_index = (unsigned)folder->packIndex;
+ zip->folder_outbytes_remaining =
+ folder_uncompressed_size(folder);
+ zip->uncompressed_buffer_bytes_remaining = 0;
+ }
+
+ /*
+ * Initialize the decompressor for the new folder's pack streams.
+ */
+ r = init_decompression(a, zip, coder1, coder2);
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ return (ARCHIVE_OK);
+}
+
+static int64_t
+skip_stream(struct archive_read *a, size_t skip_bytes)
+{
+ struct _7zip *zip = (struct _7zip *)a->format->data;
+ const void *p;
+ int64_t skipped_bytes;
+ size_t bytes = skip_bytes;
+
+ if (zip->folder_index == 0) {
+ /*
+ * Optimization for a list mode.
+ * Avoid unncecessary decoding operations.
+ */
+ zip->si.ci.folders[zip->entry->folderIndex].skipped_bytes
+ += skip_bytes;
+ return (skip_bytes);
+ }
+
+ while (bytes) {
+ skipped_bytes = read_stream(a, &p, bytes, 0);
+ if (skipped_bytes < 0)
+ return (skipped_bytes);
+ if (skipped_bytes == 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated 7-Zip file body");
+ return (ARCHIVE_FATAL);
+ }
+ bytes -= (size_t)skipped_bytes;
+ if (zip->pack_stream_bytes_unconsumed)
+ read_consume(a);
+ }
+ return (skip_bytes);
+}
+
+/*
+ * Brought from LZMA SDK.
+ *
+ * Bra86.c -- Converter for x86 code (BCJ)
+ * 2008-10-04 : Igor Pavlov : Public domain
+ *
+ */
+
+#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
+
+static void
+x86_Init(struct _7zip *zip)
+{
+ zip->bcj_state = 0;
+ zip->bcj_prevPosT = (size_t)0 - 1;
+ zip->bcj_prevMask = 0;
+ zip->bcj_ip = 5;
+}
+
+static size_t
+x86_Convert(struct _7zip *zip, uint8_t *data, size_t size)
+{
+ static const uint8_t kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
+ static const uint8_t kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
+ size_t bufferPos, prevPosT;
+ uint32_t ip, prevMask;
+
+ if (size < 5)
+ return 0;
+
+ bufferPos = 0;
+ prevPosT = zip->bcj_prevPosT;
+ prevMask = zip->bcj_prevMask;
+ ip = zip->bcj_ip;
+
+ for (;;) {
+ uint8_t *p = data + bufferPos;
+ uint8_t *limit = data + size - 4;
+
+ for (; p < limit; p++)
+ if ((*p & 0xFE) == 0xE8)
+ break;
+ bufferPos = (size_t)(p - data);
+ if (p >= limit)
+ break;
+ prevPosT = bufferPos - prevPosT;
+ if (prevPosT > 3)
+ prevMask = 0;
+ else {
+ prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
+ if (prevMask != 0) {
+ unsigned char b =
+ p[4 - kMaskToBitNumber[prevMask]];
+ if (!kMaskToAllowedStatus[prevMask] ||
+ Test86MSByte(b)) {
+ prevPosT = bufferPos;
+ prevMask = ((prevMask << 1) & 0x7) | 1;
+ bufferPos++;
+ continue;
+ }
+ }
+ }
+ prevPosT = bufferPos;
+
+ if (Test86MSByte(p[4])) {
+ uint32_t src = ((uint32_t)p[4] << 24) |
+ ((uint32_t)p[3] << 16) | ((uint32_t)p[2] << 8) |
+ ((uint32_t)p[1]);
+ uint32_t dest;
+ for (;;) {
+ uint8_t b;
+ int b_index;
+
+ dest = src - (ip + (uint32_t)bufferPos);
+ if (prevMask == 0)
+ break;
+ b_index = kMaskToBitNumber[prevMask] * 8;
+ b = (uint8_t)(dest >> (24 - b_index));
+ if (!Test86MSByte(b))
+ break;
+ src = dest ^ ((1 << (32 - b_index)) - 1);
+ }
+ p[4] = (uint8_t)(~(((dest >> 24) & 1) - 1));
+ p[3] = (uint8_t)(dest >> 16);
+ p[2] = (uint8_t)(dest >> 8);
+ p[1] = (uint8_t)dest;
+ bufferPos += 5;
+ } else {
+ prevMask = ((prevMask << 1) & 0x7) | 1;
+ bufferPos++;
+ }
+ }
+ zip->bcj_prevPosT = prevPosT;
+ zip->bcj_prevMask = prevMask;
+ zip->bcj_ip += (uint32_t)bufferPos;
+ return (bufferPos);
+}
+
+/*
+ * Brought from LZMA SDK.
+ *
+ * Bcj2.c -- Converter for x86 code (BCJ2)
+ * 2008-10-04 : Igor Pavlov : Public domain
+ *
+ */
+
+#define SZ_ERROR_DATA ARCHIVE_FAILED
+
+#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)
+#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))
+
+#define kNumTopBits 24
+#define kTopValue ((uint32_t)1 << kNumTopBits)
+
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+#define kNumMoveBits 5
+
+#define RC_READ_BYTE (*buffer++)
+#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }
+#define RC_INIT2 zip->bcj2_code = 0; zip->bcj2_range = 0xFFFFFFFF; \
+ { int ii; for (ii = 0; ii < 5; ii++) { RC_TEST; zip->bcj2_code = (zip->bcj2_code << 8) | RC_READ_BYTE; }}
+
+#define NORMALIZE if (zip->bcj2_range < kTopValue) { RC_TEST; zip->bcj2_range <<= 8; zip->bcj2_code = (zip->bcj2_code << 8) | RC_READ_BYTE; }
+
+#define IF_BIT_0(p) ttt = *(p); bound = (zip->bcj2_range >> kNumBitModelTotalBits) * ttt; if (zip->bcj2_code < bound)
+#define UPDATE_0(p) zip->bcj2_range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;
+#define UPDATE_1(p) zip->bcj2_range -= bound; zip->bcj2_code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;
+
+static ssize_t
+Bcj2_Decode(struct _7zip *zip, uint8_t *outBuf, size_t outSize)
+{
+ size_t inPos = 0, outPos = 0;
+ const uint8_t *buf0, *buf1, *buf2, *buf3;
+ size_t size0, size1, size2, size3;
+ const uint8_t *buffer, *bufferLim;
+ unsigned int i, j;
+
+ size0 = zip->tmp_stream_bytes_remaining;
+ buf0 = zip->tmp_stream_buff + zip->tmp_stream_bytes_avail - size0;
+ size1 = zip->sub_stream_bytes_remaining[0];
+ buf1 = zip->sub_stream_buff[0] + zip->sub_stream_size[0] - size1;
+ size2 = zip->sub_stream_bytes_remaining[1];
+ buf2 = zip->sub_stream_buff[1] + zip->sub_stream_size[1] - size2;
+ size3 = zip->sub_stream_bytes_remaining[2];
+ buf3 = zip->sub_stream_buff[2] + zip->sub_stream_size[2] - size3;
+
+ buffer = buf3;
+ bufferLim = buffer + size3;
+
+ if (zip->bcj_state == 0) {
+ /*
+ * Initialize.
+ */
+ zip->bcj2_prevByte = 0;
+ for (i = 0;
+ i < sizeof(zip->bcj2_p) / sizeof(zip->bcj2_p[0]); i++)
+ zip->bcj2_p[i] = kBitModelTotal >> 1;
+ RC_INIT2;
+ zip->bcj_state = 1;
+ }
+
+ /*
+ * Gather the odd bytes of a previous call.
+ */
+ for (i = 0; zip->odd_bcj_size > 0 && outPos < outSize; i++) {
+ outBuf[outPos++] = zip->odd_bcj[i];
+ zip->odd_bcj_size--;
+ }
+
+ if (outSize == 0) {
+ zip->bcj2_outPos += outPos;
+ return (outPos);
+ }
+
+ for (;;) {
+ uint8_t b;
+ CProb *prob;
+ uint32_t bound;
+ uint32_t ttt;
+
+ size_t limit = size0 - inPos;
+ if (outSize - outPos < limit)
+ limit = outSize - outPos;
+
+ if (zip->bcj_state == 1) {
+ while (limit != 0) {
+ uint8_t bb = buf0[inPos];
+ outBuf[outPos++] = bb;
+ if (IsJ(zip->bcj2_prevByte, bb)) {
+ zip->bcj_state = 2;
+ break;
+ }
+ inPos++;
+ zip->bcj2_prevByte = bb;
+ limit--;
+ }
+ }
+
+ if (limit == 0 || outPos == outSize)
+ break;
+ zip->bcj_state = 1;
+
+ b = buf0[inPos++];
+
+ if (b == 0xE8)
+ prob = zip->bcj2_p + zip->bcj2_prevByte;
+ else if (b == 0xE9)
+ prob = zip->bcj2_p + 256;
+ else
+ prob = zip->bcj2_p + 257;
+
+ IF_BIT_0(prob) {
+ UPDATE_0(prob)
+ zip->bcj2_prevByte = b;
+ } else {
+ uint32_t dest;
+ const uint8_t *v;
+ uint8_t out[4];
+
+ UPDATE_1(prob)
+ if (b == 0xE8) {
+ v = buf1;
+ if (size1 < 4)
+ return SZ_ERROR_DATA;
+ buf1 += 4;
+ size1 -= 4;
+ } else {
+ v = buf2;
+ if (size2 < 4)
+ return SZ_ERROR_DATA;
+ buf2 += 4;
+ size2 -= 4;
+ }
+ dest = (((uint32_t)v[0] << 24) |
+ ((uint32_t)v[1] << 16) |
+ ((uint32_t)v[2] << 8) |
+ ((uint32_t)v[3])) -
+ ((uint32_t)zip->bcj2_outPos + (uint32_t)outPos + 4);
+ out[0] = (uint8_t)dest;
+ out[1] = (uint8_t)(dest >> 8);
+ out[2] = (uint8_t)(dest >> 16);
+ out[3] = zip->bcj2_prevByte = (uint8_t)(dest >> 24);
+
+ for (i = 0; i < 4 && outPos < outSize; i++)
+ outBuf[outPos++] = out[i];
+ if (i < 4) {
+ /*
+ * Save odd bytes which we could not add into
+ * the output buffer because of out of space.
+ */
+ zip->odd_bcj_size = 4 -i;
+ for (; i < 4; i++) {
+ j = i - 4 + (unsigned)zip->odd_bcj_size;
+ zip->odd_bcj[j] = out[i];
+ }
+ break;
+ }
+ }
+ }
+ zip->tmp_stream_bytes_remaining -= inPos;
+ zip->sub_stream_bytes_remaining[0] = size1;
+ zip->sub_stream_bytes_remaining[1] = size2;
+ zip->sub_stream_bytes_remaining[2] = bufferLim - buffer;
+ zip->bcj2_outPos += outPos;
+
+ return ((ssize_t)outPos);
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c
new file mode 100644
index 0000000000..53fe6fa391
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 2003-2011 Tim Kientzle
+ * 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_read_support_format_all.c 174991 2007-12-30 04:58:22Z kientzle $");
+
+#include "archive.h"
+#include "archive_private.h"
+
+int
+archive_read_support_format_all(struct archive *a)
+{
+ archive_check_magic(a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_all");
+
+ /* TODO: It would be nice to compute the ordering
+ * here automatically so that people who enable just
+ * a few formats can still get the benefits. That
+ * may just require the format registration to include
+ * a "maximum read-ahead" value (anything that uses seek
+ * would be essentially infinite read-ahead). The core
+ * bid management can then sort the bidders before calling
+ * them.
+ *
+ * If you implement the above, please return the list below
+ * to alphabetic order.
+ */
+
+ /*
+ * These bidders are all pretty cheap; they just examine a
+ * small initial part of the archive. If one of these bids
+ * high, we can maybe avoid running any of the more expensive
+ * bidders below.
+ */
+ archive_read_support_format_ar(a);
+ archive_read_support_format_cpio(a);
+ archive_read_support_format_empty(a);
+ archive_read_support_format_lha(a);
+ archive_read_support_format_mtree(a);
+ archive_read_support_format_tar(a);
+ archive_read_support_format_xar(a);
+
+ /*
+ * Install expensive bidders last. By doing them last, we
+ * increase the chance that a high bid from someone else will
+ * make it unnecessary for these to do anything at all.
+ */
+ /* These three have potentially large look-ahead. */
+ archive_read_support_format_7zip(a);
+ archive_read_support_format_cab(a);
+ archive_read_support_format_rar(a);
+ archive_read_support_format_iso9660(a);
+ /* Seek is really bad, since it forces the read-ahead
+ * logic to discard buffered data. */
+ archive_read_support_format_zip(a);
+
+ /* Note: We always return ARCHIVE_OK here, even if some of the
+ * above return ARCHIVE_WARN. The intent here is to enable
+ * "as much as possible." Clients who need specific
+ * compression should enable those individually so they can
+ * verify the level of support. */
+ /* Clear any warning messages set by the above functions. */
+ archive_clear_error(a);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c
new file mode 100644
index 0000000000..82756c976e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c
@@ -0,0 +1,628 @@
+/*-
+ * Copyright (c) 2007 Kai Wang
+ * Copyright (c) 2007 Tim Kientzle
+ * 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
+ * in this position and unchanged.
+ * 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_read_support_format_ar.c 201101 2009-12-28 03:06:27Z kientzle $");
+
+#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
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+struct ar {
+ int64_t entry_bytes_remaining;
+ /* unconsumed is purely to track data we've gotten from readahead,
+ * but haven't yet marked as consumed. Must be paired with
+ * entry_bytes_remaining usage/modification.
+ */
+ size_t entry_bytes_unconsumed;
+ int64_t entry_offset;
+ int64_t entry_padding;
+ char *strtab;
+ size_t strtab_size;
+ char read_global_header;
+};
+
+/*
+ * Define structure of the "ar" header.
+ */
+#define AR_name_offset 0
+#define AR_name_size 16
+#define AR_date_offset 16
+#define AR_date_size 12
+#define AR_uid_offset 28
+#define AR_uid_size 6
+#define AR_gid_offset 34
+#define AR_gid_size 6
+#define AR_mode_offset 40
+#define AR_mode_size 8
+#define AR_size_offset 48
+#define AR_size_size 10
+#define AR_fmag_offset 58
+#define AR_fmag_size 2
+
+static int archive_read_format_ar_bid(struct archive_read *a, int);
+static int archive_read_format_ar_cleanup(struct archive_read *a);
+static int archive_read_format_ar_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset);
+static int archive_read_format_ar_skip(struct archive_read *a);
+static int archive_read_format_ar_read_header(struct archive_read *a,
+ struct archive_entry *e);
+static uint64_t ar_atol8(const char *p, unsigned char_cnt);
+static uint64_t ar_atol10(const char *p, unsigned char_cnt);
+static int ar_parse_gnu_filename_table(struct archive_read *a);
+static int ar_parse_common_header(struct ar *ar, struct archive_entry *,
+ const char *h);
+
+int
+archive_read_support_format_ar(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct ar *ar;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_ar");
+
+ ar = (struct ar *)malloc(sizeof(*ar));
+ if (ar == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ar data");
+ return (ARCHIVE_FATAL);
+ }
+ memset(ar, 0, sizeof(*ar));
+ ar->strtab = NULL;
+
+ r = __archive_read_register_format(a,
+ ar,
+ "ar",
+ archive_read_format_ar_bid,
+ NULL,
+ archive_read_format_ar_read_header,
+ archive_read_format_ar_read_data,
+ archive_read_format_ar_skip,
+ NULL,
+ archive_read_format_ar_cleanup,
+ NULL,
+ NULL);
+
+ if (r != ARCHIVE_OK) {
+ free(ar);
+ return (r);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_ar_cleanup(struct archive_read *a)
+{
+ struct ar *ar;
+
+ ar = (struct ar *)(a->format->data);
+ if (ar->strtab)
+ free(ar->strtab);
+ free(ar);
+ (a->format->data) = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_ar_bid(struct archive_read *a, int best_bid)
+{
+ const void *h;
+
+ (void)best_bid; /* UNUSED */
+
+ /*
+ * Verify the 8-byte file signature.
+ * TODO: Do we need to check more than this?
+ */
+ if ((h = __archive_read_ahead(a, 8, NULL)) == NULL)
+ return (-1);
+ if (memcmp(h, "!<arch>\n", 8) == 0) {
+ return (64);
+ }
+ return (-1);
+}
+
+static int
+_ar_read_header(struct archive_read *a, struct archive_entry *entry,
+ struct ar *ar, const char *h, size_t *unconsumed)
+{
+ char filename[AR_name_size + 1];
+ uint64_t number; /* Used to hold parsed numbers before validation. */
+ size_t bsd_name_length, entry_size;
+ char *p, *st;
+ const void *b;
+ int r;
+
+ /* Verify the magic signature on the file header. */
+ if (strncmp(h + AR_fmag_offset, "`\n", 2) != 0) {
+ archive_set_error(&a->archive, EINVAL,
+ "Incorrect file header signature");
+ return (ARCHIVE_WARN);
+ }
+
+ /* Copy filename into work buffer. */
+ strncpy(filename, h + AR_name_offset, AR_name_size);
+ filename[AR_name_size] = '\0';
+
+ /*
+ * Guess the format variant based on the filename.
+ */
+ if (a->archive.archive_format == ARCHIVE_FORMAT_AR) {
+ /* We don't already know the variant, so let's guess. */
+ /*
+ * Biggest clue is presence of '/': GNU starts special
+ * filenames with '/', appends '/' as terminator to
+ * non-special names, so anything with '/' should be
+ * GNU except for BSD long filenames.
+ */
+ if (strncmp(filename, "#1/", 3) == 0)
+ a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD;
+ else if (strchr(filename, '/') != NULL)
+ a->archive.archive_format = ARCHIVE_FORMAT_AR_GNU;
+ else if (strncmp(filename, "__.SYMDEF", 9) == 0)
+ a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD;
+ /*
+ * XXX Do GNU/SVR4 'ar' programs ever omit trailing '/'
+ * if name exactly fills 16-byte field? If so, we
+ * can't assume entries without '/' are BSD. XXX
+ */
+ }
+
+ /* Update format name from the code. */
+ if (a->archive.archive_format == ARCHIVE_FORMAT_AR_GNU)
+ a->archive.archive_format_name = "ar (GNU/SVR4)";
+ else if (a->archive.archive_format == ARCHIVE_FORMAT_AR_BSD)
+ a->archive.archive_format_name = "ar (BSD)";
+ else
+ a->archive.archive_format_name = "ar";
+
+ /*
+ * Remove trailing spaces from the filename. GNU and BSD
+ * variants both pad filename area out with spaces.
+ * This will only be wrong if GNU/SVR4 'ar' implementations
+ * omit trailing '/' for 16-char filenames and we have
+ * a 16-char filename that ends in ' '.
+ */
+ p = filename + AR_name_size - 1;
+ while (p >= filename && *p == ' ') {
+ *p = '\0';
+ p--;
+ }
+
+ /*
+ * Remove trailing slash unless first character is '/'.
+ * (BSD entries never end in '/', so this will only trim
+ * GNU-format entries. GNU special entries start with '/'
+ * and are not terminated in '/', so we don't trim anything
+ * that starts with '/'.)
+ */
+ if (filename[0] != '/' && *p == '/')
+ *p = '\0';
+
+ /*
+ * '//' is the GNU filename table.
+ * Later entries can refer to names in this table.
+ */
+ if (strcmp(filename, "//") == 0) {
+ /* This must come before any call to _read_ahead. */
+ ar_parse_common_header(ar, entry, h);
+ archive_entry_copy_pathname(entry, filename);
+ archive_entry_set_filetype(entry, AE_IFREG);
+ /* Get the size of the filename table. */
+ number = ar_atol10(h + AR_size_offset, AR_size_size);
+ if (number > SIZE_MAX) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Filename table too large");
+ return (ARCHIVE_FATAL);
+ }
+ entry_size = (size_t)number;
+ if (entry_size == 0) {
+ archive_set_error(&a->archive, EINVAL,
+ "Invalid string table");
+ return (ARCHIVE_WARN);
+ }
+ if (ar->strtab != NULL) {
+ archive_set_error(&a->archive, EINVAL,
+ "More than one string tables exist");
+ return (ARCHIVE_WARN);
+ }
+
+ /* Read the filename table into memory. */
+ st = malloc(entry_size);
+ if (st == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate filename table buffer");
+ return (ARCHIVE_FATAL);
+ }
+ ar->strtab = st;
+ ar->strtab_size = entry_size;
+
+ if (*unconsumed) {
+ __archive_read_consume(a, *unconsumed);
+ *unconsumed = 0;
+ }
+
+ if ((b = __archive_read_ahead(a, entry_size, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+ memcpy(st, b, entry_size);
+ __archive_read_consume(a, entry_size);
+ /* All contents are consumed. */
+ ar->entry_bytes_remaining = 0;
+ archive_entry_set_size(entry, ar->entry_bytes_remaining);
+
+ /* Parse the filename table. */
+ return (ar_parse_gnu_filename_table(a));
+ }
+
+ /*
+ * GNU variant handles long filenames by storing /<number>
+ * to indicate a name stored in the filename table.
+ * XXX TODO: Verify that it's all digits... Don't be fooled
+ * by "/9xyz" XXX
+ */
+ if (filename[0] == '/' && filename[1] >= '0' && filename[1] <= '9') {
+ number = ar_atol10(h + AR_name_offset + 1, AR_name_size - 1);
+ /*
+ * If we can't look up the real name, warn and return
+ * the entry with the wrong name.
+ */
+ if (ar->strtab == NULL || number > ar->strtab_size) {
+ archive_set_error(&a->archive, EINVAL,
+ "Can't find long filename for entry");
+ archive_entry_copy_pathname(entry, filename);
+ /* Parse the time, owner, mode, size fields. */
+ ar_parse_common_header(ar, entry, h);
+ return (ARCHIVE_WARN);
+ }
+
+ archive_entry_copy_pathname(entry, &ar->strtab[(size_t)number]);
+ /* Parse the time, owner, mode, size fields. */
+ return (ar_parse_common_header(ar, entry, h));
+ }
+
+ /*
+ * BSD handles long filenames by storing "#1/" followed by the
+ * length of filename as a decimal number, then prepends the
+ * the filename to the file contents.
+ */
+ if (strncmp(filename, "#1/", 3) == 0) {
+ /* Parse the time, owner, mode, size fields. */
+ /* This must occur before _read_ahead is called again. */
+ ar_parse_common_header(ar, entry, h);
+
+ /* Parse the size of the name, adjust the file size. */
+ number = ar_atol10(h + AR_name_offset + 3, AR_name_size - 3);
+ bsd_name_length = (size_t)number;
+ /* Guard against the filename + trailing NUL
+ * overflowing a size_t and against the filename size
+ * being larger than the entire entry. */
+ if (number > (uint64_t)(bsd_name_length + 1)
+ || (int64_t)bsd_name_length > ar->entry_bytes_remaining) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Bad input file size");
+ return (ARCHIVE_FATAL);
+ }
+ ar->entry_bytes_remaining -= bsd_name_length;
+ /* Adjust file size reported to client. */
+ archive_entry_set_size(entry, ar->entry_bytes_remaining);
+
+ if (*unconsumed) {
+ __archive_read_consume(a, *unconsumed);
+ *unconsumed = 0;
+ }
+
+ /* Read the long name into memory. */
+ if ((b = __archive_read_ahead(a, bsd_name_length, NULL)) == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Truncated input file");
+ return (ARCHIVE_FATAL);
+ }
+ /* Store it in the entry. */
+ p = (char *)malloc(bsd_name_length + 1);
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate fname buffer");
+ return (ARCHIVE_FATAL);
+ }
+ strncpy(p, b, bsd_name_length);
+ p[bsd_name_length] = '\0';
+
+ __archive_read_consume(a, bsd_name_length);
+
+ archive_entry_copy_pathname(entry, p);
+ free(p);
+ return (ARCHIVE_OK);
+ }
+
+ /*
+ * "/" is the SVR4/GNU archive symbol table.
+ */
+ if (strcmp(filename, "/") == 0) {
+ archive_entry_copy_pathname(entry, "/");
+ /* Parse the time, owner, mode, size fields. */
+ r = ar_parse_common_header(ar, entry, h);
+ /* Force the file type to a regular file. */
+ archive_entry_set_filetype(entry, AE_IFREG);
+ return (r);
+ }
+
+ /*
+ * "__.SYMDEF" is a BSD archive symbol table.
+ */
+ if (strcmp(filename, "__.SYMDEF") == 0) {
+ archive_entry_copy_pathname(entry, filename);
+ /* Parse the time, owner, mode, size fields. */
+ return (ar_parse_common_header(ar, entry, h));
+ }
+
+ /*
+ * Otherwise, this is a standard entry. The filename
+ * has already been trimmed as much as possible, based
+ * on our current knowledge of the format.
+ */
+ archive_entry_copy_pathname(entry, filename);
+ return (ar_parse_common_header(ar, entry, h));
+}
+
+static int
+archive_read_format_ar_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ struct ar *ar = (struct ar*)(a->format->data);
+ size_t unconsumed;
+ const void *header_data;
+ int ret;
+
+ if (!ar->read_global_header) {
+ /*
+ * We are now at the beginning of the archive,
+ * so we need first consume the ar global header.
+ */
+ __archive_read_consume(a, 8);
+ ar->read_global_header = 1;
+ /* Set a default format code for now. */
+ a->archive.archive_format = ARCHIVE_FORMAT_AR;
+ }
+
+ /* Read the header for the next file entry. */
+ if ((header_data = __archive_read_ahead(a, 60, NULL)) == NULL)
+ /* Broken header. */
+ return (ARCHIVE_EOF);
+
+ unconsumed = 60;
+
+ ret = _ar_read_header(a, entry, ar, (const char *)header_data, &unconsumed);
+
+ if (unconsumed)
+ __archive_read_consume(a, unconsumed);
+
+ return ret;
+}
+
+
+static int
+ar_parse_common_header(struct ar *ar, struct archive_entry *entry,
+ const char *h)
+{
+ uint64_t n;
+
+ /* Copy remaining header */
+ archive_entry_set_mtime(entry,
+ (time_t)ar_atol10(h + AR_date_offset, AR_date_size), 0L);
+ archive_entry_set_uid(entry,
+ (uid_t)ar_atol10(h + AR_uid_offset, AR_uid_size));
+ archive_entry_set_gid(entry,
+ (gid_t)ar_atol10(h + AR_gid_offset, AR_gid_size));
+ archive_entry_set_mode(entry,
+ (mode_t)ar_atol8(h + AR_mode_offset, AR_mode_size));
+ n = ar_atol10(h + AR_size_offset, AR_size_size);
+
+ ar->entry_offset = 0;
+ ar->entry_padding = n % 2;
+ archive_entry_set_size(entry, n);
+ ar->entry_bytes_remaining = n;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_ar_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ ssize_t bytes_read;
+ struct ar *ar;
+
+ ar = (struct ar *)(a->format->data);
+
+ if (ar->entry_bytes_unconsumed) {
+ __archive_read_consume(a, ar->entry_bytes_unconsumed);
+ ar->entry_bytes_unconsumed = 0;
+ }
+
+ if (ar->entry_bytes_remaining > 0) {
+ *buff = __archive_read_ahead(a, 1, &bytes_read);
+ if (bytes_read == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Truncated ar archive");
+ return (ARCHIVE_FATAL);
+ }
+ if (bytes_read < 0)
+ return (ARCHIVE_FATAL);
+ if (bytes_read > ar->entry_bytes_remaining)
+ bytes_read = (ssize_t)ar->entry_bytes_remaining;
+ *size = bytes_read;
+ ar->entry_bytes_unconsumed = bytes_read;
+ *offset = ar->entry_offset;
+ ar->entry_offset += bytes_read;
+ ar->entry_bytes_remaining -= bytes_read;
+ return (ARCHIVE_OK);
+ } else {
+ int64_t skipped = __archive_read_consume(a, ar->entry_padding);
+ if (skipped >= 0) {
+ ar->entry_padding -= skipped;
+ }
+ if (ar->entry_padding) {
+ if (skipped >= 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Truncated ar archive- failed consuming padding");
+ }
+ return (ARCHIVE_FATAL);
+ }
+ *buff = NULL;
+ *size = 0;
+ *offset = ar->entry_offset;
+ return (ARCHIVE_EOF);
+ }
+}
+
+static int
+archive_read_format_ar_skip(struct archive_read *a)
+{
+ int64_t bytes_skipped;
+ struct ar* ar;
+
+ ar = (struct ar *)(a->format->data);
+
+ bytes_skipped = __archive_read_consume(a,
+ ar->entry_bytes_remaining + ar->entry_padding
+ + ar->entry_bytes_unconsumed);
+ if (bytes_skipped < 0)
+ return (ARCHIVE_FATAL);
+
+ ar->entry_bytes_remaining = 0;
+ ar->entry_bytes_unconsumed = 0;
+ ar->entry_padding = 0;
+
+ return (ARCHIVE_OK);
+}
+
+static int
+ar_parse_gnu_filename_table(struct archive_read *a)
+{
+ struct ar *ar;
+ char *p;
+ size_t size;
+
+ ar = (struct ar*)(a->format->data);
+ size = ar->strtab_size;
+
+ for (p = ar->strtab; p < ar->strtab + size - 1; ++p) {
+ if (*p == '/') {
+ *p++ = '\0';
+ if (*p != '\n')
+ goto bad_string_table;
+ *p = '\0';
+ }
+ }
+ /*
+ * GNU ar always pads the table to an even size.
+ * The pad character is either '\n' or '`'.
+ */
+ if (p != ar->strtab + size && *p != '\n' && *p != '`')
+ goto bad_string_table;
+
+ /* Enforce zero termination. */
+ ar->strtab[size - 1] = '\0';
+
+ return (ARCHIVE_OK);
+
+bad_string_table:
+ archive_set_error(&a->archive, EINVAL,
+ "Invalid string table");
+ free(ar->strtab);
+ ar->strtab = NULL;
+ return (ARCHIVE_WARN);
+}
+
+static uint64_t
+ar_atol8(const char *p, unsigned char_cnt)
+{
+ uint64_t l, limit, last_digit_limit;
+ unsigned int digit, base;
+
+ base = 8;
+ limit = UINT64_MAX / base;
+ last_digit_limit = UINT64_MAX % base;
+
+ while ((*p == ' ' || *p == '\t') && char_cnt-- > 0)
+ p++;
+
+ l = 0;
+ digit = *p - '0';
+ while (*p >= '0' && digit < base && char_cnt-- > 0) {
+ if (l>limit || (l == limit && digit > last_digit_limit)) {
+ l = UINT64_MAX; /* Truncate on overflow. */
+ break;
+ }
+ l = (l * base) + digit;
+ digit = *++p - '0';
+ }
+ return (l);
+}
+
+static uint64_t
+ar_atol10(const char *p, unsigned char_cnt)
+{
+ uint64_t l, limit, last_digit_limit;
+ unsigned int base, digit;
+
+ base = 10;
+ limit = UINT64_MAX / base;
+ last_digit_limit = UINT64_MAX % base;
+
+ while ((*p == ' ' || *p == '\t') && char_cnt-- > 0)
+ p++;
+ l = 0;
+ digit = *p - '0';
+ while (*p >= '0' && digit < base && char_cnt-- > 0) {
+ if (l > limit || (l == limit && digit > last_digit_limit)) {
+ l = UINT64_MAX; /* Truncate on overflow. */
+ break;
+ }
+ l = (l * base) + digit;
+ digit = *++p - '0';
+ }
+ return (l);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c
new file mode 100644
index 0000000000..084563f431
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c
@@ -0,0 +1,74 @@
+/*-
+ * Copyright (c) 2003-2011 Tim Kientzle
+ * 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$");
+
+#include "archive.h"
+#include "archive_private.h"
+
+int
+archive_read_support_format_by_code(struct archive *a, int format_code)
+{
+ archive_check_magic(a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_by_code");
+
+ switch (format_code & ARCHIVE_FORMAT_BASE_MASK) {
+ case ARCHIVE_FORMAT_7ZIP:
+ return archive_read_support_format_7zip(a);
+ break;
+ case ARCHIVE_FORMAT_AR:
+ return archive_read_support_format_ar(a);
+ break;
+ case ARCHIVE_FORMAT_CAB:
+ return archive_read_support_format_cab(a);
+ break;
+ case ARCHIVE_FORMAT_CPIO:
+ return archive_read_support_format_cpio(a);
+ break;
+ case ARCHIVE_FORMAT_ISO9660:
+ return archive_read_support_format_iso9660(a);
+ break;
+ case ARCHIVE_FORMAT_LHA:
+ return archive_read_support_format_lha(a);
+ break;
+ case ARCHIVE_FORMAT_MTREE:
+ return archive_read_support_format_mtree(a);
+ break;
+ case ARCHIVE_FORMAT_RAR:
+ return archive_read_support_format_rar(a);
+ break;
+ case ARCHIVE_FORMAT_TAR:
+ return archive_read_support_format_tar(a);
+ break;
+ case ARCHIVE_FORMAT_XAR:
+ return archive_read_support_format_xar(a);
+ break;
+ case ARCHIVE_FORMAT_ZIP:
+ return archive_read_support_format_zip(a);
+ break;
+ }
+ return (ARCHIVE_FATAL);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c
new file mode 100644
index 0000000000..63569635ea
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c
@@ -0,0 +1,3350 @@
+/*-
+ * Copyright (c) 2010-2012 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_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+#include "archive_endian.h"
+
+
+struct lzx_dec {
+ /* Decoding status. */
+ int state;
+
+ /*
+ * Window to see last decoded data, from 32KBi to 2MBi.
+ */
+ int w_size;
+ int w_mask;
+ /* Window buffer, which is a loop buffer. */
+ unsigned char *w_buff;
+ /* The insert position to the window. */
+ int w_pos;
+ /* The position where we can copy decoded code from the window. */
+ int copy_pos;
+ /* The length how many bytes we can copy decoded code from
+ * the window. */
+ int copy_len;
+ /* Translation reversal for x86 proccessor CALL byte sequence(E8).
+ * This is used for LZX only. */
+ uint32_t translation_size;
+ char translation;
+ char block_type;
+#define VERBATIM_BLOCK 1
+#define ALIGNED_OFFSET_BLOCK 2
+#define UNCOMPRESSED_BLOCK 3
+ size_t block_size;
+ size_t block_bytes_avail;
+ /* Repeated offset. */
+ int r0, r1, r2;
+ unsigned char rbytes[4];
+ int rbytes_avail;
+ int length_header;
+ int position_slot;
+ int offset_bits;
+
+ struct lzx_pos_tbl {
+ int base;
+ int footer_bits;
+ } *pos_tbl;
+ /*
+ * Bit stream reader.
+ */
+ struct lzx_br {
+#define CACHE_TYPE uint64_t
+#define CACHE_BITS (8 * sizeof(CACHE_TYPE))
+ /* Cache buffer. */
+ CACHE_TYPE cache_buffer;
+ /* Indicates how many bits avail in cache_buffer. */
+ int cache_avail;
+ unsigned char odd;
+ char have_odd;
+ } br;
+
+ /*
+ * Huffman coding.
+ */
+ struct huffman {
+ int len_size;
+ int freq[17];
+ unsigned char *bitlen;
+
+ /*
+ * Use a index table. It's faster than searching a huffman
+ * coding tree, which is a binary tree. But a use of a large
+ * index table causes L1 cache read miss many times.
+ */
+#define HTBL_BITS 10
+ int max_bits;
+ int shift_bits;
+ int tbl_bits;
+ int tree_used;
+ int tree_avail;
+ /* Direct access table. */
+ uint16_t *tbl;
+ /* Binary tree table for extra bits over the direct access. */
+ struct htree_t {
+ uint16_t left;
+ uint16_t right;
+ } *tree;
+ } at, lt, mt, pt;
+
+ int loop;
+ int error;
+};
+
+static const int slots[] = {
+ 30, 32, 34, 36, 38, 42, 50, 66, 98, 162, 290
+};
+#define SLOT_BASE 15
+#define SLOT_MAX 21/*->25*/
+
+struct lzx_stream {
+ const unsigned char *next_in;
+ int64_t avail_in;
+ int64_t total_in;
+ unsigned char *next_out;
+ int64_t avail_out;
+ int64_t total_out;
+ struct lzx_dec *ds;
+};
+
+/*
+ * Cabinet file definitions.
+ */
+/* CFHEADER offset */
+#define CFHEADER_signature 0
+#define CFHEADER_cbCabinet 8
+#define CFHEADER_coffFiles 16
+#define CFHEADER_versionMinor 24
+#define CFHEADER_versionMajor 25
+#define CFHEADER_cFolders 26
+#define CFHEADER_cFiles 28
+#define CFHEADER_flags 30
+#define CFHEADER_setID 32
+#define CFHEADER_iCabinet 34
+#define CFHEADER_cbCFHeader 36
+#define CFHEADER_cbCFFolder 38
+#define CFHEADER_cbCFData 39
+
+/* CFFOLDER offset */
+#define CFFOLDER_coffCabStart 0
+#define CFFOLDER_cCFData 4
+#define CFFOLDER_typeCompress 6
+#define CFFOLDER_abReserve 8
+
+/* CFFILE offset */
+#define CFFILE_cbFile 0
+#define CFFILE_uoffFolderStart 4
+#define CFFILE_iFolder 8
+#define CFFILE_date_time 10
+#define CFFILE_attribs 14
+
+/* CFDATA offset */
+#define CFDATA_csum 0
+#define CFDATA_cbData 4
+#define CFDATA_cbUncomp 6
+
+static const char *compression_name[] = {
+ "NONE",
+ "MSZIP",
+ "Quantum",
+ "LZX",
+};
+
+struct cfdata {
+ /* Sum value of this CFDATA. */
+ uint32_t sum;
+ uint16_t compressed_size;
+ uint16_t compressed_bytes_remaining;
+ uint16_t uncompressed_size;
+ uint16_t uncompressed_bytes_remaining;
+ /* To know how many bytes we have decompressed. */
+ uint16_t uncompressed_avail;
+ /* Offset from the beginning of compressed data of this CFDATA */
+ uint16_t read_offset;
+ int64_t unconsumed;
+ /* To keep memory image of this CFDATA to compute the sum. */
+ size_t memimage_size;
+ unsigned char *memimage;
+ /* Result of calculation of sum. */
+ uint32_t sum_calculated;
+ unsigned char sum_extra[4];
+ int sum_extra_avail;
+ const void *sum_ptr;
+};
+
+struct cffolder {
+ uint32_t cfdata_offset_in_cab;
+ uint16_t cfdata_count;
+ uint16_t comptype;
+#define COMPTYPE_NONE 0x0000
+#define COMPTYPE_MSZIP 0x0001
+#define COMPTYPE_QUANTUM 0x0002
+#define COMPTYPE_LZX 0x0003
+ uint16_t compdata;
+ const char *compname;
+ /* At the time reading CFDATA */
+ struct cfdata cfdata;
+ int cfdata_index;
+ /* Flags to mark progress of decompression. */
+ char decompress_init;
+};
+
+struct cffile {
+ uint32_t uncompressed_size;
+ uint32_t offset;
+ time_t mtime;
+ uint16_t folder;
+#define iFoldCONTINUED_FROM_PREV 0xFFFD
+#define iFoldCONTINUED_TO_NEXT 0xFFFE
+#define iFoldCONTINUED_PREV_AND_NEXT 0xFFFF
+ unsigned char attr;
+#define ATTR_RDONLY 0x01
+#define ATTR_NAME_IS_UTF 0x80
+ struct archive_string pathname;
+};
+
+struct cfheader {
+ /* Total bytes of all file size in a Cabinet. */
+ uint32_t total_bytes;
+ uint32_t files_offset;
+ uint16_t folder_count;
+ uint16_t file_count;
+ uint16_t flags;
+#define PREV_CABINET 0x0001
+#define NEXT_CABINET 0x0002
+#define RESERVE_PRESENT 0x0004
+ uint16_t setid;
+ uint16_t cabinet;
+ /* Version number. */
+ unsigned char major;
+ unsigned char minor;
+ unsigned char cffolder;
+ unsigned char cfdata;
+ /* All folders in a cabinet. */
+ struct cffolder *folder_array;
+ /* All files in a cabinet. */
+ struct cffile *file_array;
+ int file_index;
+};
+
+struct cab {
+ /* entry_bytes_remaining is the number of bytes we expect. */
+ int64_t entry_offset;
+ int64_t entry_bytes_remaining;
+ int64_t entry_unconsumed;
+ int64_t entry_compressed_bytes_read;
+ int64_t entry_uncompressed_bytes_read;
+ struct cffolder *entry_cffolder;
+ struct cffile *entry_cffile;
+ struct cfdata *entry_cfdata;
+
+ /* Offset from beginning of a cabinet file. */
+ int64_t cab_offset;
+ struct cfheader cfheader;
+ struct archive_wstring ws;
+
+ /* Flag to mark progress that an archive was read their first header.*/
+ char found_header;
+ char end_of_archive;
+ char end_of_entry;
+ char end_of_entry_cleanup;
+ char read_data_invoked;
+ int64_t bytes_skipped;
+
+ unsigned char *uncompressed_buffer;
+ size_t uncompressed_buffer_size;
+
+ int init_default_conversion;
+ struct archive_string_conv *sconv;
+ struct archive_string_conv *sconv_default;
+ struct archive_string_conv *sconv_utf8;
+ char format_name[64];
+
+#ifdef HAVE_ZLIB_H
+ z_stream stream;
+ char stream_valid;
+#endif
+ struct lzx_stream xstrm;
+};
+
+static int archive_read_format_cab_bid(struct archive_read *, int);
+static int archive_read_format_cab_options(struct archive_read *,
+ const char *, const char *);
+static int archive_read_format_cab_read_header(struct archive_read *,
+ struct archive_entry *);
+static int archive_read_format_cab_read_data(struct archive_read *,
+ const void **, size_t *, int64_t *);
+static int archive_read_format_cab_read_data_skip(struct archive_read *);
+static int archive_read_format_cab_cleanup(struct archive_read *);
+
+static int cab_skip_sfx(struct archive_read *);
+static time_t cab_dos_time(const unsigned char *);
+static int cab_read_data(struct archive_read *, const void **,
+ size_t *, int64_t *);
+static int cab_read_header(struct archive_read *);
+static uint32_t cab_checksum_cfdata_4(const void *, size_t bytes, uint32_t);
+static uint32_t cab_checksum_cfdata(const void *, size_t bytes, uint32_t);
+static void cab_checksum_update(struct archive_read *, size_t);
+static int cab_checksum_finish(struct archive_read *);
+static int cab_next_cfdata(struct archive_read *);
+static const void *cab_read_ahead_cfdata(struct archive_read *, ssize_t *);
+static const void *cab_read_ahead_cfdata_none(struct archive_read *, ssize_t *);
+static const void *cab_read_ahead_cfdata_deflate(struct archive_read *,
+ ssize_t *);
+static const void *cab_read_ahead_cfdata_lzx(struct archive_read *,
+ ssize_t *);
+static int64_t cab_consume_cfdata(struct archive_read *, int64_t);
+static int64_t cab_minimum_consume_cfdata(struct archive_read *, int64_t);
+static int lzx_decode_init(struct lzx_stream *, int);
+static int lzx_read_blocks(struct lzx_stream *, int);
+static int lzx_decode_blocks(struct lzx_stream *, int);
+static void lzx_decode_free(struct lzx_stream *);
+static void lzx_translation(struct lzx_stream *, void *, size_t, uint32_t);
+static void lzx_cleanup_bitstream(struct lzx_stream *);
+static int lzx_decode(struct lzx_stream *, int);
+static int lzx_read_pre_tree(struct lzx_stream *);
+static int lzx_read_bitlen(struct lzx_stream *, struct huffman *, int);
+static int lzx_huffman_init(struct huffman *, size_t, int);
+static void lzx_huffman_free(struct huffman *);
+static int lzx_make_huffman_table(struct huffman *);
+static inline int lzx_decode_huffman(struct huffman *, unsigned);
+static int lzx_decode_huffman_tree(struct huffman *, unsigned, int);
+
+
+int
+archive_read_support_format_cab(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct cab *cab;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_cab");
+
+ cab = (struct cab *)calloc(1, sizeof(*cab));
+ if (cab == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate CAB data");
+ return (ARCHIVE_FATAL);
+ }
+ archive_string_init(&cab->ws);
+ archive_wstring_ensure(&cab->ws, 256);
+
+ r = __archive_read_register_format(a,
+ cab,
+ "cab",
+ archive_read_format_cab_bid,
+ archive_read_format_cab_options,
+ archive_read_format_cab_read_header,
+ archive_read_format_cab_read_data,
+ archive_read_format_cab_read_data_skip,
+ NULL,
+ archive_read_format_cab_cleanup,
+ NULL,
+ NULL);
+
+ if (r != ARCHIVE_OK)
+ free(cab);
+ return (ARCHIVE_OK);
+}
+
+static int
+find_cab_magic(const char *p)
+{
+ switch (p[4]) {
+ case 0:
+ /*
+ * Note: Self-Extraction program has 'MSCF' string in their
+ * program. If we were finding 'MSCF' string only, we got
+ * wrong place for Cabinet header, thus, we have to check
+ * following four bytes which are reserved and must be set
+ * to zero.
+ */
+ if (memcmp(p, "MSCF\0\0\0\0", 8) == 0)
+ return 0;
+ return 5;
+ case 'F': return 1;
+ case 'C': return 2;
+ case 'S': return 3;
+ case 'M': return 4;
+ default: return 5;
+ }
+}
+
+static int
+archive_read_format_cab_bid(struct archive_read *a, int best_bid)
+{
+ const char *p;
+ ssize_t bytes_avail, offset, window;
+
+ /* If there's already a better bid than we can ever
+ make, don't bother testing. */
+ if (best_bid > 64)
+ return (-1);
+
+ if ((p = __archive_read_ahead(a, 8, NULL)) == NULL)
+ return (-1);
+
+ if (memcmp(p, "MSCF\0\0\0\0", 8) == 0)
+ return (64);
+
+ /*
+ * Attempt to handle self-extracting archives
+ * by noting a PE header and searching forward
+ * up to 128k for a 'MSCF' marker.
+ */
+ if (p[0] == 'M' && p[1] == 'Z') {
+ offset = 0;
+ window = 4096;
+ while (offset < (1024 * 128)) {
+ const char *h = __archive_read_ahead(a, offset + window,
+ &bytes_avail);
+ if (h == NULL) {
+ /* Remaining bytes are less than window. */
+ window >>= 1;
+ if (window < 128)
+ return (0);
+ continue;
+ }
+ p = h + offset;
+ while (p + 8 < h + bytes_avail) {
+ int next;
+ if ((next = find_cab_magic(p)) == 0)
+ return (64);
+ p += next;
+ }
+ offset = p - h;
+ }
+ }
+ return (0);
+}
+
+static int
+archive_read_format_cab_options(struct archive_read *a,
+ const char *key, const char *val)
+{
+ struct cab *cab;
+ int ret = ARCHIVE_FAILED;
+
+ cab = (struct cab *)(a->format->data);
+ if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "cab: hdrcharset option needs a character-set name");
+ else {
+ cab->sconv = archive_string_conversion_from_charset(
+ &a->archive, val, 0);
+ if (cab->sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ }
+
+ /* 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
+cab_skip_sfx(struct archive_read *a)
+{
+ const char *p, *q;
+ size_t skip;
+ ssize_t bytes, window;
+
+ window = 4096;
+ for (;;) {
+ const char *h = __archive_read_ahead(a, window, &bytes);
+ if (h == NULL) {
+ /* Remaining size are less than window. */
+ window >>= 1;
+ if (window < 128) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Couldn't find out CAB header");
+ return (ARCHIVE_FATAL);
+ }
+ continue;
+ }
+ p = h;
+ q = p + bytes;
+
+ /*
+ * Scan ahead until we find something that looks
+ * like the cab header.
+ */
+ while (p + 8 < q) {
+ int next;
+ if ((next = find_cab_magic(p)) == 0) {
+ skip = p - h;
+ __archive_read_consume(a, skip);
+ return (ARCHIVE_OK);
+ }
+ p += next;
+ }
+ skip = p - h;
+ __archive_read_consume(a, skip);
+ }
+}
+
+static int
+truncated_error(struct archive_read *a)
+{
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated CAB header");
+ return (ARCHIVE_FATAL);
+}
+
+static ssize_t
+cab_strnlen(const unsigned char *p, size_t maxlen)
+{
+ size_t i;
+
+ for (i = 0; i <= maxlen; i++) {
+ if (p[i] == 0)
+ break;
+ }
+ if (i > maxlen)
+ return (-1);/* invalid */
+ return ((ssize_t)i);
+}
+
+/* Read bytes as much as remaining. */
+static const void *
+cab_read_ahead_remaining(struct archive_read *a, size_t min, ssize_t *avail)
+{
+ const void *p;
+
+ while (min > 0) {
+ p = __archive_read_ahead(a, min, avail);
+ if (p != NULL)
+ return (p);
+ min--;
+ }
+ return (NULL);
+}
+
+/* Convert a path separator '\' -> '/' */
+static int
+cab_convert_path_separator_1(struct archive_string *fn, unsigned char attr)
+{
+ size_t i;
+ int mb;
+
+ /* Easy check if we have '\' in multi-byte string. */
+ mb = 0;
+ for (i = 0; i < archive_strlen(fn); i++) {
+ if (fn->s[i] == '\\') {
+ if (mb) {
+ /* This may be second byte of multi-byte
+ * character. */
+ break;
+ }
+ fn->s[i] = '/';
+ mb = 0;
+ } else if ((fn->s[i] & 0x80) && !(attr & ATTR_NAME_IS_UTF))
+ mb = 1;
+ else
+ mb = 0;
+ }
+ if (i == archive_strlen(fn))
+ return (0);
+ return (-1);
+}
+
+/*
+ * Replace a character '\' with '/' in wide character.
+ */
+static void
+cab_convert_path_separator_2(struct cab *cab, struct archive_entry *entry)
+{
+ const wchar_t *wp;
+ size_t i;
+
+ /* If a conversion to wide character failed, force the replacement. */
+ if ((wp = archive_entry_pathname_w(entry)) != NULL) {
+ archive_wstrcpy(&(cab->ws), wp);
+ for (i = 0; i < archive_strlen(&(cab->ws)); i++) {
+ if (cab->ws.s[i] == L'\\')
+ cab->ws.s[i] = L'/';
+ }
+ archive_entry_copy_pathname_w(entry, cab->ws.s);
+ }
+}
+
+/*
+ * Read CFHEADER, CFFOLDER and CFFILE.
+ */
+static int
+cab_read_header(struct archive_read *a)
+{
+ const unsigned char *p;
+ struct cab *cab;
+ struct cfheader *hd;
+ size_t bytes, used;
+ ssize_t len;
+ int64_t skip;
+ int err, i;
+ int cur_folder, prev_folder;
+ uint32_t offset32;
+
+ a->archive.archive_format = ARCHIVE_FORMAT_CAB;
+ if (a->archive.archive_format_name == NULL)
+ a->archive.archive_format_name = "CAB";
+
+ if ((p = __archive_read_ahead(a, 42, NULL)) == NULL)
+ return (truncated_error(a));
+
+ cab = (struct cab *)(a->format->data);
+ if (cab->found_header == 0 &&
+ p[0] == 'M' && p[1] == 'Z') {
+ /* This is an executable? Must be self-extracting... */
+ err = cab_skip_sfx(a);
+ if (err < ARCHIVE_WARN)
+ return (err);
+
+ if ((p = __archive_read_ahead(a, sizeof(*p), NULL)) == NULL)
+ return (truncated_error(a));
+ }
+
+ cab->cab_offset = 0;
+ /*
+ * Read CFHEADER.
+ */
+ hd = &cab->cfheader;
+ if (p[CFHEADER_signature+0] != 'M' || p[CFHEADER_signature+1] != 'S' ||
+ p[CFHEADER_signature+2] != 'C' || p[CFHEADER_signature+3] != 'F') {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Couldn't find out CAB header");
+ return (ARCHIVE_FATAL);
+ }
+ hd->total_bytes = archive_le32dec(p + CFHEADER_cbCabinet);
+ hd->files_offset = archive_le32dec(p + CFHEADER_coffFiles);
+ hd->minor = p[CFHEADER_versionMinor];
+ hd->major = p[CFHEADER_versionMajor];
+ hd->folder_count = archive_le16dec(p + CFHEADER_cFolders);
+ if (hd->folder_count == 0)
+ goto invalid;
+ hd->file_count = archive_le16dec(p + CFHEADER_cFiles);
+ if (hd->file_count == 0)
+ goto invalid;
+ hd->flags = archive_le16dec(p + CFHEADER_flags);
+ hd->setid = archive_le16dec(p + CFHEADER_setID);
+ hd->cabinet = archive_le16dec(p + CFHEADER_iCabinet);
+ used = CFHEADER_iCabinet + 2;
+ if (hd->flags & RESERVE_PRESENT) {
+ uint16_t cfheader;
+ cfheader = archive_le16dec(p + CFHEADER_cbCFHeader);
+ if (cfheader > 60000U)
+ goto invalid;
+ hd->cffolder = p[CFHEADER_cbCFFolder];
+ hd->cfdata = p[CFHEADER_cbCFData];
+ used += 4;/* cbCFHeader, cbCFFolder and cbCFData */
+ used += cfheader;/* abReserve */
+ } else
+ hd->cffolder = 0;/* Avoid compiling warning. */
+ if (hd->flags & PREV_CABINET) {
+ /* How many bytes are used for szCabinetPrev. */
+ if ((p = __archive_read_ahead(a, used+256, NULL)) == NULL)
+ return (truncated_error(a));
+ if ((len = cab_strnlen(p + used, 255)) <= 0)
+ goto invalid;
+ used += len + 1;
+ /* How many bytes are used for szDiskPrev. */
+ if ((p = __archive_read_ahead(a, used+256, NULL)) == NULL)
+ return (truncated_error(a));
+ if ((len = cab_strnlen(p + used, 255)) <= 0)
+ goto invalid;
+ used += len + 1;
+ }
+ if (hd->flags & NEXT_CABINET) {
+ /* How many bytes are used for szCabinetNext. */
+ if ((p = __archive_read_ahead(a, used+256, NULL)) == NULL)
+ return (truncated_error(a));
+ if ((len = cab_strnlen(p + used, 255)) <= 0)
+ goto invalid;
+ used += len + 1;
+ /* How many bytes are used for szDiskNext. */
+ if ((p = __archive_read_ahead(a, used+256, NULL)) == NULL)
+ return (truncated_error(a));
+ if ((len = cab_strnlen(p + used, 255)) <= 0)
+ goto invalid;
+ used += len + 1;
+ }
+ __archive_read_consume(a, used);
+ cab->cab_offset += used;
+ used = 0;
+
+ /*
+ * Read CFFOLDER.
+ */
+ hd->folder_array = (struct cffolder *)calloc(
+ hd->folder_count, sizeof(struct cffolder));
+ if (hd->folder_array == NULL)
+ goto nomem;
+
+ bytes = 8;
+ if (hd->flags & RESERVE_PRESENT)
+ bytes += hd->cffolder;
+ bytes *= hd->folder_count;
+ if ((p = __archive_read_ahead(a, bytes, NULL)) == NULL)
+ return (truncated_error(a));
+ offset32 = 0;
+ for (i = 0; i < hd->folder_count; i++) {
+ struct cffolder *folder = &(hd->folder_array[i]);
+ folder->cfdata_offset_in_cab =
+ archive_le32dec(p + CFFOLDER_coffCabStart);
+ folder->cfdata_count = archive_le16dec(p+CFFOLDER_cCFData);
+ folder->comptype =
+ archive_le16dec(p+CFFOLDER_typeCompress) & 0x0F;
+ folder->compdata =
+ archive_le16dec(p+CFFOLDER_typeCompress) >> 8;
+ /* Get a compression name. */
+ if (folder->comptype <
+ sizeof(compression_name) / sizeof(compression_name[0]))
+ folder->compname = compression_name[folder->comptype];
+ else
+ folder->compname = "UNKNOWN";
+ p += 8;
+ used += 8;
+ if (hd->flags & RESERVE_PRESENT) {
+ p += hd->cffolder;/* abReserve */
+ used += hd->cffolder;
+ }
+ /*
+ * Sanity check if each data is acceptable.
+ */
+ if (offset32 >= folder->cfdata_offset_in_cab)
+ goto invalid;
+ offset32 = folder->cfdata_offset_in_cab;
+
+ /* Set a request to initialize zlib for the CFDATA of
+ * this folder. */
+ folder->decompress_init = 0;
+ }
+ __archive_read_consume(a, used);
+ cab->cab_offset += used;
+
+ /*
+ * Read CFFILE.
+ */
+ /* Seek read pointer to the offset of CFFILE if needed. */
+ skip = (int64_t)hd->files_offset - cab->cab_offset;
+ if (skip < 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid offset of CFFILE %jd < %jd",
+ (intmax_t)hd->files_offset, (intmax_t)cab->cab_offset);
+ return (ARCHIVE_FATAL);
+ }
+ if (skip) {
+ __archive_read_consume(a, skip);
+ cab->cab_offset += skip;
+ }
+ /* Allocate memory for CFDATA */
+ hd->file_array = (struct cffile *)calloc(
+ hd->file_count, sizeof(struct cffile));
+ if (hd->file_array == NULL)
+ goto nomem;
+
+ prev_folder = -1;
+ for (i = 0; i < hd->file_count; i++) {
+ struct cffile *file = &(hd->file_array[i]);
+ ssize_t avail;
+
+ if ((p = __archive_read_ahead(a, 16, NULL)) == NULL)
+ return (truncated_error(a));
+ file->uncompressed_size = archive_le32dec(p + CFFILE_cbFile);
+ file->offset = archive_le32dec(p + CFFILE_uoffFolderStart);
+ file->folder = archive_le16dec(p + CFFILE_iFolder);
+ file->mtime = cab_dos_time(p + CFFILE_date_time);
+ file->attr = (uint8_t)archive_le16dec(p + CFFILE_attribs);
+ __archive_read_consume(a, 16);
+
+ cab->cab_offset += 16;
+ if ((p = cab_read_ahead_remaining(a, 256, &avail)) == NULL)
+ return (truncated_error(a));
+ if ((len = cab_strnlen(p, avail-1)) <= 0)
+ goto invalid;
+
+ /* Copy a pathname. */
+ archive_string_init(&(file->pathname));
+ archive_strncpy(&(file->pathname), p, len);
+ __archive_read_consume(a, len + 1);
+ cab->cab_offset += len + 1;
+
+ /*
+ * Sanity check if each data is acceptable.
+ */
+ if (file->uncompressed_size > 0x7FFF8000)
+ goto invalid;/* Too large */
+ if ((int64_t)file->offset + (int64_t)file->uncompressed_size
+ > ARCHIVE_LITERAL_LL(0x7FFF8000))
+ goto invalid;/* Too large */
+ switch (file->folder) {
+ case iFoldCONTINUED_TO_NEXT:
+ /* This must be last file in a folder. */
+ if (i != hd->file_count -1)
+ goto invalid;
+ cur_folder = hd->folder_count -1;
+ break;
+ case iFoldCONTINUED_PREV_AND_NEXT:
+ /* This must be only one file in a folder. */
+ if (hd->file_count != 1)
+ goto invalid;
+ /* FALL THROUGH */
+ case iFoldCONTINUED_FROM_PREV:
+ /* This must be first file in a folder. */
+ if (i != 0)
+ goto invalid;
+ prev_folder = cur_folder = 0;
+ offset32 = file->offset;
+ break;
+ default:
+ if (file->folder >= hd->folder_count)
+ goto invalid;
+ cur_folder = file->folder;
+ break;
+ }
+ /* Dot not back track. */
+ if (cur_folder < prev_folder)
+ goto invalid;
+ if (cur_folder != prev_folder)
+ offset32 = 0;
+ prev_folder = cur_folder;
+
+ /* Make sure there are not any blanks from last file
+ * contents. */
+ if (offset32 != file->offset)
+ goto invalid;
+ offset32 += file->uncompressed_size;
+
+ /* CFDATA is available for file contents. */
+ if (file->uncompressed_size > 0 &&
+ hd->folder_array[cur_folder].cfdata_count == 0)
+ goto invalid;
+ }
+
+ if (hd->cabinet != 0 || hd->flags & (PREV_CABINET | NEXT_CABINET)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Multivolume cabinet file is unsupported");
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+invalid:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid CAB header");
+ return (ARCHIVE_FATAL);
+nomem:
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for CAB data");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+archive_read_format_cab_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ struct cab *cab;
+ struct cfheader *hd;
+ struct cffolder *prev_folder;
+ struct cffile *file;
+ struct archive_string_conv *sconv;
+ int err = ARCHIVE_OK, r;
+
+ cab = (struct cab *)(a->format->data);
+ if (cab->found_header == 0) {
+ err = cab_read_header(a);
+ if (err < ARCHIVE_WARN)
+ return (err);
+ /* We've found the header. */
+ cab->found_header = 1;
+ }
+ hd = &cab->cfheader;
+
+ if (hd->file_index >= hd->file_count) {
+ cab->end_of_archive = 1;
+ return (ARCHIVE_EOF);
+ }
+ file = &hd->file_array[hd->file_index++];
+
+ cab->end_of_entry = 0;
+ cab->end_of_entry_cleanup = 0;
+ cab->entry_compressed_bytes_read = 0;
+ cab->entry_uncompressed_bytes_read = 0;
+ cab->entry_unconsumed = 0;
+ cab->entry_cffile = file;
+
+ /*
+ * Choose a proper folder.
+ */
+ prev_folder = cab->entry_cffolder;
+ switch (file->folder) {
+ case iFoldCONTINUED_FROM_PREV:
+ case iFoldCONTINUED_PREV_AND_NEXT:
+ cab->entry_cffolder = &hd->folder_array[0];
+ break;
+ case iFoldCONTINUED_TO_NEXT:
+ cab->entry_cffolder = &hd->folder_array[hd->folder_count-1];
+ break;
+ default:
+ cab->entry_cffolder = &hd->folder_array[file->folder];
+ break;
+ }
+ /* If a cffolder of this file is changed, reset a cfdata to read
+ * file contents from next cfdata. */
+ if (prev_folder != cab->entry_cffolder)
+ cab->entry_cfdata = NULL;
+
+ /* If a pathname is UTF-8, prepare a string conversion object
+ * for UTF-8 and use it. */
+ if (file->attr & ATTR_NAME_IS_UTF) {
+ if (cab->sconv_utf8 == NULL) {
+ cab->sconv_utf8 =
+ archive_string_conversion_from_charset(
+ &(a->archive), "UTF-8", 1);
+ if (cab->sconv_utf8 == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ sconv = cab->sconv_utf8;
+ } else if (cab->sconv != NULL) {
+ /* Choose the conversion specified by the option. */
+ sconv = cab->sconv;
+ } else {
+ /* Choose the default conversion. */
+ if (!cab->init_default_conversion) {
+ cab->sconv_default =
+ archive_string_default_conversion_for_read(
+ &(a->archive));
+ cab->init_default_conversion = 1;
+ }
+ sconv = cab->sconv_default;
+ }
+
+ /*
+ * Set a default value and common data
+ */
+ r = cab_convert_path_separator_1(&(file->pathname), file->attr);
+ if (archive_entry_copy_pathname_l(entry, file->pathname.s,
+ archive_strlen(&(file->pathname)), sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Pathname cannot be converted "
+ "from %s to current locale.",
+ archive_string_conversion_charset_name(sconv));
+ err = ARCHIVE_WARN;
+ }
+ if (r < 0) {
+ /* Convert a path separator '\' -> '/' */
+ cab_convert_path_separator_2(cab, entry);
+ }
+
+ archive_entry_set_size(entry, file->uncompressed_size);
+ if (file->attr & ATTR_RDONLY)
+ archive_entry_set_mode(entry, AE_IFREG | 0555);
+ else
+ archive_entry_set_mode(entry, AE_IFREG | 0666);
+ archive_entry_set_mtime(entry, file->mtime, 0);
+
+ cab->entry_bytes_remaining = file->uncompressed_size;
+ cab->entry_offset = 0;
+ /* We don't need compress data. */
+ if (file->uncompressed_size == 0)
+ cab->end_of_entry_cleanup = cab->end_of_entry = 1;
+
+ /* Set up a more descriptive format name. */
+ sprintf(cab->format_name, "CAB %d.%d (%s)",
+ hd->major, hd->minor, cab->entry_cffolder->compname);
+ a->archive.archive_format_name = cab->format_name;
+
+ return (err);
+}
+
+static int
+archive_read_format_cab_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ int r;
+
+ switch (cab->entry_cffile->folder) {
+ case iFoldCONTINUED_FROM_PREV:
+ case iFoldCONTINUED_TO_NEXT:
+ case iFoldCONTINUED_PREV_AND_NEXT:
+ *buff = NULL;
+ *size = 0;
+ *offset = 0;
+ archive_clear_error(&a->archive);
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Cannot restore this file split in multivolume.");
+ return (ARCHIVE_FAILED);
+ default:
+ break;
+ }
+ if (cab->read_data_invoked == 0) {
+ if (cab->bytes_skipped) {
+ if (cab->entry_cfdata == NULL) {
+ r = cab_next_cfdata(a);
+ if (r < 0)
+ return (r);
+ }
+ if (cab_consume_cfdata(a, cab->bytes_skipped) < 0)
+ return (ARCHIVE_FATAL);
+ cab->bytes_skipped = 0;
+ }
+ cab->read_data_invoked = 1;
+ }
+ if (cab->entry_unconsumed) {
+ /* Consume as much as the compressor actually used. */
+ r = (int)cab_consume_cfdata(a, cab->entry_unconsumed);
+ cab->entry_unconsumed = 0;
+ if (r < 0)
+ return (r);
+ }
+ if (cab->end_of_archive || cab->end_of_entry) {
+ if (!cab->end_of_entry_cleanup) {
+ /* End-of-entry cleanup done. */
+ cab->end_of_entry_cleanup = 1;
+ }
+ *offset = cab->entry_offset;
+ *size = 0;
+ *buff = NULL;
+ return (ARCHIVE_EOF);
+ }
+
+ return (cab_read_data(a, buff, size, offset));
+}
+
+static uint32_t
+cab_checksum_cfdata_4(const void *p, size_t bytes, uint32_t seed)
+{
+ const unsigned char *b;
+ unsigned u32num;
+ uint32_t sum;
+
+ u32num = (unsigned)bytes / 4;
+ sum = seed;
+ b = p;
+ for (;u32num > 0; --u32num) {
+ sum ^= archive_le32dec(b);
+ b += 4;
+ }
+ return (sum);
+}
+
+static uint32_t
+cab_checksum_cfdata(const void *p, size_t bytes, uint32_t seed)
+{
+ const unsigned char *b;
+ uint32_t sum;
+ uint32_t t;
+
+ sum = cab_checksum_cfdata_4(p, bytes, seed);
+ b = p;
+ b += bytes & ~3;
+ t = 0;
+ switch (bytes & 3) {
+ case 3:
+ t |= ((uint32_t)(*b++)) << 16;
+ /* FALL THROUGH */
+ case 2:
+ t |= ((uint32_t)(*b++)) << 8;
+ /* FALL THROUGH */
+ case 1:
+ t |= *b;
+ /* FALL THROUGH */
+ default:
+ break;
+ }
+ sum ^= t;
+
+ return (sum);
+}
+
+static void
+cab_checksum_update(struct archive_read *a, size_t bytes)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ struct cfdata *cfdata = cab->entry_cfdata;
+ const unsigned char *p;
+ size_t sumbytes;
+
+ if (cfdata->sum == 0 || cfdata->sum_ptr == NULL)
+ return;
+ /*
+ * Calculate the sum of this CFDATA.
+ * Make sure CFDATA must be calculated in four bytes.
+ */
+ p = cfdata->sum_ptr;
+ sumbytes = bytes;
+ if (cfdata->sum_extra_avail) {
+ while (cfdata->sum_extra_avail < 4 && sumbytes > 0) {
+ cfdata->sum_extra[
+ cfdata->sum_extra_avail++] = *p++;
+ sumbytes--;
+ }
+ if (cfdata->sum_extra_avail == 4) {
+ cfdata->sum_calculated = cab_checksum_cfdata_4(
+ cfdata->sum_extra, 4, cfdata->sum_calculated);
+ cfdata->sum_extra_avail = 0;
+ }
+ }
+ if (sumbytes) {
+ int odd = sumbytes & 3;
+ if (sumbytes - odd > 0)
+ cfdata->sum_calculated = cab_checksum_cfdata_4(
+ p, sumbytes - odd, cfdata->sum_calculated);
+ if (odd)
+ memcpy(cfdata->sum_extra, p + sumbytes - odd, odd);
+ cfdata->sum_extra_avail = odd;
+ }
+ cfdata->sum_ptr = NULL;
+}
+
+static int
+cab_checksum_finish(struct archive_read *a)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ struct cfdata *cfdata = cab->entry_cfdata;
+ int l;
+
+ /* Do not need to compute a sum. */
+ if (cfdata->sum == 0)
+ return (ARCHIVE_OK);
+
+ /*
+ * Calculate the sum of remaining CFDATA.
+ */
+ if (cfdata->sum_extra_avail) {
+ cfdata->sum_calculated =
+ cab_checksum_cfdata(cfdata->sum_extra,
+ cfdata->sum_extra_avail, cfdata->sum_calculated);
+ cfdata->sum_extra_avail = 0;
+ }
+
+ l = 4;
+ if (cab->cfheader.flags & RESERVE_PRESENT)
+ l += cab->cfheader.cfdata;
+ cfdata->sum_calculated = cab_checksum_cfdata(
+ cfdata->memimage + CFDATA_cbData, l, cfdata->sum_calculated);
+ if (cfdata->sum_calculated != cfdata->sum) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Checksum error CFDATA[%d] %x:%x in %d bytes",
+ cab->entry_cffolder->cfdata_index -1,
+ cfdata->sum, cfdata->sum_calculated,
+ cfdata->compressed_size);
+ return (ARCHIVE_FAILED);
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Read CFDATA if needed.
+ */
+static int
+cab_next_cfdata(struct archive_read *a)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ struct cfdata *cfdata = cab->entry_cfdata;
+
+ /* There are remaining bytes in current CFDATA, use it first. */
+ if (cfdata != NULL && cfdata->uncompressed_bytes_remaining > 0)
+ return (ARCHIVE_OK);
+
+ if (cfdata == NULL) {
+ int64_t skip;
+
+ cab->entry_cffolder->cfdata_index = 0;
+
+ /* Seek read pointer to the offset of CFDATA if needed. */
+ skip = cab->entry_cffolder->cfdata_offset_in_cab
+ - cab->cab_offset;
+ if (skip < 0) {
+ int folder_index;
+ switch (cab->entry_cffile->folder) {
+ case iFoldCONTINUED_FROM_PREV:
+ case iFoldCONTINUED_PREV_AND_NEXT:
+ folder_index = 0;
+ break;
+ case iFoldCONTINUED_TO_NEXT:
+ folder_index = cab->cfheader.folder_count-1;
+ break;
+ default:
+ folder_index = cab->entry_cffile->folder;
+ break;
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid offset of CFDATA in folder(%d) %jd < %jd",
+ folder_index,
+ (intmax_t)cab->entry_cffolder->cfdata_offset_in_cab,
+ (intmax_t)cab->cab_offset);
+ return (ARCHIVE_FATAL);
+ }
+ if (skip > 0) {
+ if (__archive_read_consume(a, skip) < 0)
+ return (ARCHIVE_FATAL);
+ cab->cab_offset =
+ cab->entry_cffolder->cfdata_offset_in_cab;
+ }
+ }
+
+ /*
+ * Read a CFDATA.
+ */
+ if (cab->entry_cffolder->cfdata_index <
+ cab->entry_cffolder->cfdata_count) {
+ const unsigned char *p;
+ int l;
+
+ cfdata = &(cab->entry_cffolder->cfdata);
+ cab->entry_cffolder->cfdata_index++;
+ cab->entry_cfdata = cfdata;
+ cfdata->sum_calculated = 0;
+ cfdata->sum_extra_avail = 0;
+ cfdata->sum_ptr = NULL;
+ l = 8;
+ if (cab->cfheader.flags & RESERVE_PRESENT)
+ l += cab->cfheader.cfdata;
+ if ((p = __archive_read_ahead(a, l, NULL)) == NULL)
+ return (truncated_error(a));
+ cfdata->sum = archive_le32dec(p + CFDATA_csum);
+ cfdata->compressed_size = archive_le16dec(p + CFDATA_cbData);
+ cfdata->compressed_bytes_remaining = cfdata->compressed_size;
+ cfdata->uncompressed_size =
+ archive_le16dec(p + CFDATA_cbUncomp);
+ cfdata->uncompressed_bytes_remaining =
+ cfdata->uncompressed_size;
+ cfdata->uncompressed_avail = 0;
+ cfdata->read_offset = 0;
+ cfdata->unconsumed = 0;
+
+ /*
+ * Sanity check if data size is acceptable.
+ */
+ if (cfdata->compressed_size == 0 ||
+ cfdata->compressed_size > (0x8000+6144))
+ goto invalid;
+ if (cfdata->uncompressed_size > 0x8000)
+ goto invalid;
+ if (cfdata->uncompressed_size == 0) {
+ switch (cab->entry_cffile->folder) {
+ case iFoldCONTINUED_PREV_AND_NEXT:
+ case iFoldCONTINUED_TO_NEXT:
+ break;
+ case iFoldCONTINUED_FROM_PREV:
+ default:
+ goto invalid;
+ }
+ }
+ /* If CFDATA is not last in a folder, an uncompressed
+ * size must be 0x8000(32KBi) */
+ if ((cab->entry_cffolder->cfdata_index <
+ cab->entry_cffolder->cfdata_count) &&
+ cfdata->uncompressed_size != 0x8000)
+ goto invalid;
+
+ /* A compressed data size and an uncompressed data size must
+ * be the same in no compression mode. */
+ if (cab->entry_cffolder->comptype == COMPTYPE_NONE &&
+ cfdata->compressed_size != cfdata->uncompressed_size)
+ goto invalid;
+
+ /*
+ * Save CFDATA image for sum check.
+ */
+ if (cfdata->memimage_size < (size_t)l) {
+ free(cfdata->memimage);
+ cfdata->memimage = malloc(l);
+ if (cfdata->memimage == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for CAB data");
+ return (ARCHIVE_FATAL);
+ }
+ cfdata->memimage_size = l;
+ }
+ memcpy(cfdata->memimage, p, l);
+
+ /* Consume bytes as much as we used. */
+ __archive_read_consume(a, l);
+ cab->cab_offset += l;
+ } else if (cab->entry_cffolder->cfdata_count > 0) {
+ /* Run out of all CFDATA in a folder. */
+ cfdata->compressed_size = 0;
+ cfdata->uncompressed_size = 0;
+ cfdata->compressed_bytes_remaining = 0;
+ cfdata->uncompressed_bytes_remaining = 0;
+ } else {
+ /* Current folder does not have any CFDATA. */
+ cfdata = &(cab->entry_cffolder->cfdata);
+ cab->entry_cfdata = cfdata;
+ memset(cfdata, 0, sizeof(*cfdata));
+ }
+ return (ARCHIVE_OK);
+invalid:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid CFDATA");
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Read ahead CFDATA.
+ */
+static const void *
+cab_read_ahead_cfdata(struct archive_read *a, ssize_t *avail)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ int err;
+
+ err = cab_next_cfdata(a);
+ if (err < ARCHIVE_OK) {
+ *avail = err;
+ return (NULL);
+ }
+
+ switch (cab->entry_cffolder->comptype) {
+ case COMPTYPE_NONE:
+ return (cab_read_ahead_cfdata_none(a, avail));
+ case COMPTYPE_MSZIP:
+ return (cab_read_ahead_cfdata_deflate(a, avail));
+ case COMPTYPE_LZX:
+ return (cab_read_ahead_cfdata_lzx(a, avail));
+ default: /* Unsupported compression. */
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unsupported CAB compression : %s",
+ cab->entry_cffolder->compname);
+ *avail = ARCHIVE_FAILED;
+ return (NULL);
+ }
+}
+
+/*
+ * Read ahead CFDATA as uncompressed data.
+ */
+static const void *
+cab_read_ahead_cfdata_none(struct archive_read *a, ssize_t *avail)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ struct cfdata *cfdata;
+ const void *d;
+
+ cfdata = cab->entry_cfdata;
+
+ /*
+ * Note: '1' here is a performance optimization.
+ * Recall that the decompression layer returns a count of
+ * available bytes; asking for more than that forces the
+ * decompressor to combine reads by copying data.
+ */
+ d = __archive_read_ahead(a, 1, avail);
+ if (*avail <= 0) {
+ *avail = truncated_error(a);
+ return (NULL);
+ }
+ if (*avail > cfdata->uncompressed_bytes_remaining)
+ *avail = cfdata->uncompressed_bytes_remaining;
+ cfdata->uncompressed_avail = cfdata->uncompressed_size;
+ cfdata->unconsumed = *avail;
+ cfdata->sum_ptr = d;
+ return (d);
+}
+
+/*
+ * Read ahead CFDATA as deflate data.
+ */
+#ifdef HAVE_ZLIB_H
+static const void *
+cab_read_ahead_cfdata_deflate(struct archive_read *a, ssize_t *avail)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ struct cfdata *cfdata;
+ const void *d;
+ int r, mszip;
+ uint16_t uavail;
+ char eod = 0;
+
+ cfdata = cab->entry_cfdata;
+ /* If the buffer hasn't been allocated, allocate it now. */
+ if (cab->uncompressed_buffer == NULL) {
+ cab->uncompressed_buffer_size = 0x8000;
+ cab->uncompressed_buffer
+ = (unsigned char *)malloc(cab->uncompressed_buffer_size);
+ if (cab->uncompressed_buffer == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for CAB reader");
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ }
+
+ uavail = cfdata->uncompressed_avail;
+ if (uavail == cfdata->uncompressed_size) {
+ d = cab->uncompressed_buffer + cfdata->read_offset;
+ *avail = uavail - cfdata->read_offset;
+ return (d);
+ }
+
+ if (!cab->entry_cffolder->decompress_init) {
+ cab->stream.next_in = NULL;
+ cab->stream.avail_in = 0;
+ cab->stream.total_in = 0;
+ cab->stream.next_out = NULL;
+ cab->stream.avail_out = 0;
+ cab->stream.total_out = 0;
+ if (cab->stream_valid)
+ r = inflateReset(&cab->stream);
+ else
+ r = inflateInit2(&cab->stream,
+ -15 /* Don't check for zlib header */);
+ if (r != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't initialize deflate decompression.");
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ /* Stream structure has been set up. */
+ cab->stream_valid = 1;
+ /* We've initialized decompression for this stream. */
+ cab->entry_cffolder->decompress_init = 1;
+ }
+
+ if (cfdata->compressed_bytes_remaining == cfdata->compressed_size)
+ mszip = 2;
+ else
+ mszip = 0;
+ eod = 0;
+ cab->stream.total_out = uavail;
+ /*
+ * We always uncompress all data in current CFDATA.
+ */
+ while (!eod && cab->stream.total_out < cfdata->uncompressed_size) {
+ ssize_t bytes_avail;
+
+ cab->stream.next_out =
+ cab->uncompressed_buffer + cab->stream.total_out;
+ cab->stream.avail_out =
+ cfdata->uncompressed_size - cab->stream.total_out;
+
+ d = __archive_read_ahead(a, 1, &bytes_avail);
+ if (bytes_avail <= 0) {
+ *avail = truncated_error(a);
+ return (NULL);
+ }
+ if (bytes_avail > cfdata->compressed_bytes_remaining)
+ bytes_avail = cfdata->compressed_bytes_remaining;
+ /*
+ * A bug in zlib.h: stream.next_in should be marked 'const'
+ * but isn't (the library never alters data through the
+ * next_in pointer, only reads it). The result: this ugly
+ * cast to remove 'const'.
+ */
+ cab->stream.next_in = (Bytef *)(uintptr_t)d;
+ cab->stream.avail_in = (uInt)bytes_avail;
+ cab->stream.total_in = 0;
+
+ /* Cut out a tow-byte MSZIP signature(0x43, 0x4b). */
+ if (mszip > 0) {
+ if (bytes_avail <= mszip) {
+ if (mszip == 2) {
+ if (cab->stream.next_in[0] != 0x43)
+ goto nomszip;
+ if (bytes_avail > 1 &&
+ cab->stream.next_in[1] != 0x4b)
+ goto nomszip;
+ } else if (cab->stream.next_in[0] != 0x4b)
+ goto nomszip;
+ cfdata->unconsumed = bytes_avail;
+ cfdata->sum_ptr = d;
+ if (cab_minimum_consume_cfdata(
+ a, cfdata->unconsumed) < 0) {
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ mszip -= (int)bytes_avail;
+ continue;
+ }
+ if (mszip == 1 && cab->stream.next_in[0] != 0x4b)
+ goto nomszip;
+ else if (cab->stream.next_in[0] != 0x43 ||
+ cab->stream.next_in[1] != 0x4b)
+ goto nomszip;
+ cab->stream.next_in += mszip;
+ cab->stream.avail_in -= mszip;
+ cab->stream.total_in += mszip;
+ mszip = 0;
+ }
+
+ r = inflate(&cab->stream, 0);
+ switch (r) {
+ case Z_OK:
+ break;
+ case Z_STREAM_END:
+ eod = 1;
+ break;
+ default:
+ goto zlibfailed;
+ }
+ cfdata->unconsumed = cab->stream.total_in;
+ cfdata->sum_ptr = d;
+ if (cab_minimum_consume_cfdata(a, cfdata->unconsumed) < 0) {
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ }
+ uavail = (uint16_t)cab->stream.total_out;
+
+ if (uavail < cfdata->uncompressed_size) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid uncompressed size (%d < %d)",
+ uavail, cfdata->uncompressed_size);
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+
+ /*
+ * Note: I suspect there is a bug in makecab.exe because, in rare
+ * case, compressed bytes are still remaining regardless we have
+ * gotten all uncompressed bytes, which size is recoded in CFDATA,
+ * as much as we need, and we have to use the garbage so as to
+ * correctly compute the sum of CFDATA accordingly.
+ */
+ if (cfdata->compressed_bytes_remaining > 0) {
+ ssize_t bytes_avail;
+
+ d = __archive_read_ahead(a, cfdata->compressed_bytes_remaining,
+ &bytes_avail);
+ if (bytes_avail <= 0) {
+ *avail = truncated_error(a);
+ return (NULL);
+ }
+ cfdata->unconsumed = cfdata->compressed_bytes_remaining;
+ cfdata->sum_ptr = d;
+ if (cab_minimum_consume_cfdata(a, cfdata->unconsumed) < 0) {
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ }
+
+ /*
+ * Set dictionary data for decompressing of next CFDATA, which
+ * in the same folder. This is why we always do decompress CFDATA
+ * even if beginning CFDATA or some of CFDATA are not used in
+ * skipping file data.
+ */
+ if (cab->entry_cffolder->cfdata_index <
+ cab->entry_cffolder->cfdata_count) {
+ r = inflateReset(&cab->stream);
+ if (r != Z_OK)
+ goto zlibfailed;
+ r = inflateSetDictionary(&cab->stream,
+ cab->uncompressed_buffer, cfdata->uncompressed_size);
+ if (r != Z_OK)
+ goto zlibfailed;
+ }
+
+ d = cab->uncompressed_buffer + cfdata->read_offset;
+ *avail = uavail - cfdata->read_offset;
+ cfdata->uncompressed_avail = uavail;
+
+ return (d);
+
+zlibfailed:
+ switch (r) {
+ case Z_MEM_ERROR:
+ archive_set_error(&a->archive, ENOMEM,
+ "Out of memory for deflate decompression");
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Deflate decompression failed (%d)", r);
+ break;
+ }
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+nomszip:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "CFDATA incorrect(no MSZIP signature)");
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+}
+
+#else /* HAVE_ZLIB_H */
+
+static const void *
+cab_read_ahead_cfdata_deflate(struct archive_read *a, ssize_t *avail)
+{
+ *avail = ARCHIVE_FATAL;
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "libarchive compiled without deflate support (no libz)");
+ return (NULL);
+}
+
+#endif /* HAVE_ZLIB_H */
+
+static const void *
+cab_read_ahead_cfdata_lzx(struct archive_read *a, ssize_t *avail)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ struct cfdata *cfdata;
+ const void *d;
+ int r;
+ uint16_t uavail;
+
+ cfdata = cab->entry_cfdata;
+ /* If the buffer hasn't been allocated, allocate it now. */
+ if (cab->uncompressed_buffer == NULL) {
+ cab->uncompressed_buffer_size = 0x8000;
+ cab->uncompressed_buffer
+ = (unsigned char *)malloc(cab->uncompressed_buffer_size);
+ if (cab->uncompressed_buffer == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for CAB reader");
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ }
+
+ uavail = cfdata->uncompressed_avail;
+ if (uavail == cfdata->uncompressed_size) {
+ d = cab->uncompressed_buffer + cfdata->read_offset;
+ *avail = uavail - cfdata->read_offset;
+ return (d);
+ }
+
+ if (!cab->entry_cffolder->decompress_init) {
+ r = lzx_decode_init(&cab->xstrm,
+ cab->entry_cffolder->compdata);
+ if (r != ARCHIVE_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't initialize LZX decompression.");
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ /* We've initialized decompression for this stream. */
+ cab->entry_cffolder->decompress_init = 1;
+ }
+
+ /* Clean up remaining bits of previous CFDATA. */
+ lzx_cleanup_bitstream(&cab->xstrm);
+ cab->xstrm.total_out = uavail;
+ while (cab->xstrm.total_out < cfdata->uncompressed_size) {
+ ssize_t bytes_avail;
+
+ cab->xstrm.next_out =
+ cab->uncompressed_buffer + cab->xstrm.total_out;
+ cab->xstrm.avail_out =
+ cfdata->uncompressed_size - cab->xstrm.total_out;
+
+ d = __archive_read_ahead(a, 1, &bytes_avail);
+ if (bytes_avail <= 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated CAB file data");
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ if (bytes_avail > cfdata->compressed_bytes_remaining)
+ bytes_avail = cfdata->compressed_bytes_remaining;
+
+ cab->xstrm.next_in = d;
+ cab->xstrm.avail_in = bytes_avail;
+ cab->xstrm.total_in = 0;
+ r = lzx_decode(&cab->xstrm,
+ cfdata->compressed_bytes_remaining == bytes_avail);
+ switch (r) {
+ case ARCHIVE_OK:
+ case ARCHIVE_EOF:
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "LZX decompression failed (%d)", r);
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ cfdata->unconsumed = cab->xstrm.total_in;
+ cfdata->sum_ptr = d;
+ if (cab_minimum_consume_cfdata(a, cfdata->unconsumed) < 0) {
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ }
+
+ uavail = (uint16_t)cab->xstrm.total_out;
+ /*
+ * Make sure a read pointer advances to next CFDATA.
+ */
+ if (cfdata->compressed_bytes_remaining > 0) {
+ ssize_t bytes_avail;
+
+ d = __archive_read_ahead(a, cfdata->compressed_bytes_remaining,
+ &bytes_avail);
+ if (bytes_avail <= 0) {
+ *avail = truncated_error(a);
+ return (NULL);
+ }
+ cfdata->unconsumed = cfdata->compressed_bytes_remaining;
+ cfdata->sum_ptr = d;
+ if (cab_minimum_consume_cfdata(a, cfdata->unconsumed) < 0) {
+ *avail = ARCHIVE_FATAL;
+ return (NULL);
+ }
+ }
+
+ /*
+ * Translation reversal of x86 proccessor CALL byte sequence(E8).
+ */
+ lzx_translation(&cab->xstrm, cab->uncompressed_buffer,
+ cfdata->uncompressed_size,
+ (cab->entry_cffolder->cfdata_index-1) * 0x8000);
+
+ d = cab->uncompressed_buffer + cfdata->read_offset;
+ *avail = uavail - cfdata->read_offset;
+ cfdata->uncompressed_avail = uavail;
+
+ return (d);
+}
+
+/*
+ * Consume CFDATA.
+ * We always decompress CFDATA to consume CFDATA as much as we need
+ * in uncompressed bytes because all CFDATA in a folder are related
+ * so we do not skip any CFDATA without decompressing.
+ * Note: If the folder of a CFFILE is iFoldCONTINUED_PREV_AND_NEXT or
+ * iFoldCONTINUED_FROM_PREV, we won't decompress because a CFDATA for
+ * the CFFILE is remaining bytes of previous Multivolume CAB file.
+ */
+static int64_t
+cab_consume_cfdata(struct archive_read *a, int64_t consumed_bytes)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ struct cfdata *cfdata;
+ int64_t cbytes, rbytes;
+ int err;
+
+ rbytes = cab_minimum_consume_cfdata(a, consumed_bytes);
+ if (rbytes < 0)
+ return (ARCHIVE_FATAL);
+
+ cfdata = cab->entry_cfdata;
+ while (rbytes > 0) {
+ ssize_t avail;
+
+ if (cfdata->compressed_size == 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid CFDATA");
+ return (ARCHIVE_FATAL);
+ }
+ cbytes = cfdata->uncompressed_bytes_remaining;
+ if (cbytes > rbytes)
+ cbytes = rbytes;
+ rbytes -= cbytes;
+
+ if (cfdata->uncompressed_avail == 0 &&
+ (cab->entry_cffile->folder == iFoldCONTINUED_PREV_AND_NEXT ||
+ cab->entry_cffile->folder == iFoldCONTINUED_FROM_PREV)) {
+ /* We have not read any data yet. */
+ if (cbytes == cfdata->uncompressed_bytes_remaining) {
+ /* Skip whole current CFDATA. */
+ __archive_read_consume(a,
+ cfdata->compressed_size);
+ cab->cab_offset += cfdata->compressed_size;
+ cfdata->compressed_bytes_remaining = 0;
+ cfdata->uncompressed_bytes_remaining = 0;
+ err = cab_next_cfdata(a);
+ if (err < 0)
+ return (err);
+ cfdata = cab->entry_cfdata;
+ if (cfdata->uncompressed_size == 0) {
+ switch (cab->entry_cffile->folder) {
+ case iFoldCONTINUED_PREV_AND_NEXT:
+ case iFoldCONTINUED_TO_NEXT:
+ case iFoldCONTINUED_FROM_PREV:
+ rbytes = 0;
+ break;
+ default:
+ break;
+ }
+ }
+ continue;
+ }
+ cfdata->read_offset += (uint16_t)cbytes;
+ cfdata->uncompressed_bytes_remaining -= (uint16_t)cbytes;
+ break;
+ } else if (cbytes == 0) {
+ err = cab_next_cfdata(a);
+ if (err < 0)
+ return (err);
+ cfdata = cab->entry_cfdata;
+ if (cfdata->uncompressed_size == 0) {
+ switch (cab->entry_cffile->folder) {
+ case iFoldCONTINUED_PREV_AND_NEXT:
+ case iFoldCONTINUED_TO_NEXT:
+ case iFoldCONTINUED_FROM_PREV:
+ return (ARCHIVE_FATAL);
+ default:
+ break;
+ }
+ }
+ continue;
+ }
+ while (cbytes > 0) {
+ (void)cab_read_ahead_cfdata(a, &avail);
+ if (avail <= 0)
+ return (ARCHIVE_FATAL);
+ if (avail > cbytes)
+ avail = (ssize_t)cbytes;
+ if (cab_minimum_consume_cfdata(a, avail) < 0)
+ return (ARCHIVE_FATAL);
+ cbytes -= avail;
+ }
+ }
+ return (consumed_bytes);
+}
+
+/*
+ * Consume CFDATA as much as we have already gotten and
+ * compute the sum of CFDATA.
+ */
+static int64_t
+cab_minimum_consume_cfdata(struct archive_read *a, int64_t consumed_bytes)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ struct cfdata *cfdata;
+ int64_t cbytes, rbytes;
+ int err;
+
+ cfdata = cab->entry_cfdata;
+ rbytes = consumed_bytes;
+ if (cab->entry_cffolder->comptype == COMPTYPE_NONE) {
+ if (consumed_bytes < cfdata->unconsumed)
+ cbytes = consumed_bytes;
+ else
+ cbytes = cfdata->unconsumed;
+ rbytes -= cbytes;
+ cfdata->read_offset += (uint16_t)cbytes;
+ cfdata->uncompressed_bytes_remaining -= (uint16_t)cbytes;
+ cfdata->unconsumed -= cbytes;
+ } else {
+ cbytes = cfdata->uncompressed_avail - cfdata->read_offset;
+ if (cbytes > 0) {
+ if (consumed_bytes < cbytes)
+ cbytes = consumed_bytes;
+ rbytes -= cbytes;
+ cfdata->read_offset += (uint16_t)cbytes;
+ cfdata->uncompressed_bytes_remaining -= (uint16_t)cbytes;
+ }
+
+ if (cfdata->unconsumed) {
+ cbytes = cfdata->unconsumed;
+ cfdata->unconsumed = 0;
+ } else
+ cbytes = 0;
+ }
+ if (cbytes) {
+ /* Compute the sum. */
+ cab_checksum_update(a, (size_t)cbytes);
+
+ /* Consume as much as the compressor actually used. */
+ __archive_read_consume(a, cbytes);
+ cab->cab_offset += cbytes;
+ cfdata->compressed_bytes_remaining -= (uint16_t)cbytes;
+ if (cfdata->compressed_bytes_remaining == 0) {
+ err = cab_checksum_finish(a);
+ if (err < 0)
+ return (err);
+ }
+ }
+ return (rbytes);
+}
+
+/*
+ * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets
+ * cab->end_of_entry if it consumes all of the data.
+ */
+static int
+cab_read_data(struct archive_read *a, const void **buff,
+ size_t *size, int64_t *offset)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ ssize_t bytes_avail;
+
+ if (cab->entry_bytes_remaining == 0) {
+ *buff = NULL;
+ *size = 0;
+ *offset = cab->entry_offset;
+ cab->end_of_entry = 1;
+ return (ARCHIVE_OK);
+ }
+
+ *buff = cab_read_ahead_cfdata(a, &bytes_avail);
+ if (bytes_avail <= 0) {
+ *buff = NULL;
+ *size = 0;
+ *offset = 0;
+ if (bytes_avail == 0 &&
+ cab->entry_cfdata->uncompressed_size == 0) {
+ /* All of CFDATA in a folder has been handled. */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT, "Invalid CFDATA");
+ return (ARCHIVE_FATAL);
+ } else
+ return ((int)bytes_avail);
+ }
+ if (bytes_avail > cab->entry_bytes_remaining)
+ bytes_avail = (ssize_t)cab->entry_bytes_remaining;
+
+ *size = bytes_avail;
+ *offset = cab->entry_offset;
+ cab->entry_offset += bytes_avail;
+ cab->entry_bytes_remaining -= bytes_avail;
+ if (cab->entry_bytes_remaining == 0)
+ cab->end_of_entry = 1;
+ cab->entry_unconsumed = bytes_avail;
+ if (cab->entry_cffolder->comptype == COMPTYPE_NONE) {
+ /* Don't consume more than current entry used. */
+ if (cab->entry_cfdata->unconsumed > cab->entry_unconsumed)
+ cab->entry_cfdata->unconsumed = cab->entry_unconsumed;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_cab_read_data_skip(struct archive_read *a)
+{
+ struct cab *cab;
+ int64_t bytes_skipped;
+ int r;
+
+ cab = (struct cab *)(a->format->data);
+
+ if (cab->end_of_archive)
+ return (ARCHIVE_EOF);
+
+ if (!cab->read_data_invoked) {
+ cab->bytes_skipped += cab->entry_bytes_remaining;
+ cab->entry_bytes_remaining = 0;
+ /* This entry is finished and done. */
+ cab->end_of_entry_cleanup = cab->end_of_entry = 1;
+ return (ARCHIVE_OK);
+ }
+
+ if (cab->entry_unconsumed) {
+ /* Consume as much as the compressor actually used. */
+ r = (int)cab_consume_cfdata(a, cab->entry_unconsumed);
+ cab->entry_unconsumed = 0;
+ if (r < 0)
+ return (r);
+ } else if (cab->entry_cfdata == NULL) {
+ r = cab_next_cfdata(a);
+ if (r < 0)
+ return (r);
+ }
+
+ /* if we've already read to end of data, we're done. */
+ if (cab->end_of_entry_cleanup)
+ return (ARCHIVE_OK);
+
+ /*
+ * If the length is at the beginning, we can skip the
+ * compressed data much more quickly.
+ */
+ bytes_skipped = cab_consume_cfdata(a, cab->entry_bytes_remaining);
+ if (bytes_skipped < 0)
+ return (ARCHIVE_FATAL);
+
+ /* If the compression type is none(uncompressed), we've already
+ * consumed data as much as the current entry size. */
+ if (cab->entry_cffolder->comptype == COMPTYPE_NONE &&
+ cab->entry_cfdata != NULL)
+ cab->entry_cfdata->unconsumed = 0;
+
+ /* This entry is finished and done. */
+ cab->end_of_entry_cleanup = cab->end_of_entry = 1;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_cab_cleanup(struct archive_read *a)
+{
+ struct cab *cab = (struct cab *)(a->format->data);
+ struct cfheader *hd = &cab->cfheader;
+ int i;
+
+ if (hd->folder_array != NULL) {
+ for (i = 0; i < hd->folder_count; i++)
+ free(hd->folder_array[i].cfdata.memimage);
+ free(hd->folder_array);
+ }
+ if (hd->file_array != NULL) {
+ for (i = 0; i < cab->cfheader.file_count; i++)
+ archive_string_free(&(hd->file_array[i].pathname));
+ free(hd->file_array);
+ }
+#ifdef HAVE_ZLIB_H
+ if (cab->stream_valid)
+ inflateEnd(&cab->stream);
+#endif
+ lzx_decode_free(&cab->xstrm);
+ archive_wstring_free(&cab->ws);
+ free(cab->uncompressed_buffer);
+ free(cab);
+ (a->format->data) = NULL;
+ return (ARCHIVE_OK);
+}
+
+/* Convert an MSDOS-style date/time into Unix-style time. */
+static time_t
+cab_dos_time(const unsigned char *p)
+{
+ int msTime, msDate;
+ struct tm ts;
+
+ msDate = archive_le16dec(p);
+ msTime = archive_le16dec(p+2);
+
+ memset(&ts, 0, sizeof(ts));
+ ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */
+ ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */
+ ts.tm_mday = msDate & 0x1f; /* Day of month. */
+ ts.tm_hour = (msTime >> 11) & 0x1f;
+ ts.tm_min = (msTime >> 5) & 0x3f;
+ ts.tm_sec = (msTime << 1) & 0x3e;
+ ts.tm_isdst = -1;
+ return (mktime(&ts));
+}
+
+/*****************************************************************
+ *
+ * LZX decompression code.
+ *
+ *****************************************************************/
+
+/*
+ * Initialize LZX decoder.
+ *
+ * Returns ARCHIVE_OK if initialization was successful.
+ * Returns ARCHIVE_FAILED if w_bits has unsupported value.
+ * Returns ARCHIVE_FATAL if initialization failed; memory allocation
+ * error occurred.
+ */
+static int
+lzx_decode_init(struct lzx_stream *strm, int w_bits)
+{
+ struct lzx_dec *ds;
+ int slot, w_size, w_slot;
+ int base, footer;
+ int base_inc[18];
+
+ if (strm->ds == NULL) {
+ strm->ds = calloc(1, sizeof(*strm->ds));
+ if (strm->ds == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ ds = strm->ds;
+ ds->error = ARCHIVE_FAILED;
+
+ /* Allow bits from 15(32KBi) up to 21(2MBi) */
+ if (w_bits < SLOT_BASE || w_bits > SLOT_MAX)
+ return (ARCHIVE_FAILED);
+
+ ds->error = ARCHIVE_FATAL;
+
+ /*
+ * Alloc window
+ */
+ w_size = ds->w_size;
+ w_slot = slots[w_bits - SLOT_BASE];
+ ds->w_size = 1U << w_bits;
+ ds->w_mask = ds->w_size -1;
+ if (ds->w_buff == NULL || w_size != ds->w_size) {
+ free(ds->w_buff);
+ ds->w_buff = malloc(ds->w_size);
+ if (ds->w_buff == NULL)
+ return (ARCHIVE_FATAL);
+ free(ds->pos_tbl);
+ ds->pos_tbl = malloc(sizeof(ds->pos_tbl[0]) * w_slot);
+ if (ds->pos_tbl == NULL)
+ return (ARCHIVE_FATAL);
+ lzx_huffman_free(&(ds->mt));
+ }
+
+ for (footer = 0; footer < 18; footer++)
+ base_inc[footer] = 1 << footer;
+ base = footer = 0;
+ for (slot = 0; slot < w_slot; slot++) {
+ int n;
+ if (footer == 0)
+ base = slot;
+ else
+ base += base_inc[footer];
+ if (footer < 17) {
+ footer = -2;
+ for (n = base; n; n >>= 1)
+ footer++;
+ if (footer <= 0)
+ footer = 0;
+ }
+ ds->pos_tbl[slot].base = base;
+ ds->pos_tbl[slot].footer_bits = footer;
+ }
+
+ ds->w_pos = 0;
+ ds->state = 0;
+ ds->br.cache_buffer = 0;
+ ds->br.cache_avail = 0;
+ ds->r0 = ds->r1 = ds->r2 = 1;
+
+ /* Initialize aligned offset tree. */
+ if (lzx_huffman_init(&(ds->at), 8, 8) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Initialize pre-tree. */
+ if (lzx_huffman_init(&(ds->pt), 20, 10) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Initialize Main tree. */
+ if (lzx_huffman_init(&(ds->mt), 256+(w_slot<<3), 16)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Initialize Length tree. */
+ if (lzx_huffman_init(&(ds->lt), 249, 16) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ ds->error = 0;
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Release LZX decoder.
+ */
+static void
+lzx_decode_free(struct lzx_stream *strm)
+{
+
+ if (strm->ds == NULL)
+ return;
+ free(strm->ds->w_buff);
+ free(strm->ds->pos_tbl);
+ lzx_huffman_free(&(strm->ds->at));
+ lzx_huffman_free(&(strm->ds->pt));
+ lzx_huffman_free(&(strm->ds->mt));
+ lzx_huffman_free(&(strm->ds->lt));
+ free(strm->ds);
+ strm->ds = NULL;
+}
+
+/*
+ * E8 Call Translation reversal.
+ */
+static void
+lzx_translation(struct lzx_stream *strm, void *p, size_t size, uint32_t offset)
+{
+ struct lzx_dec *ds = strm->ds;
+ unsigned char *b, *end;
+
+ if (!ds->translation || size <= 10)
+ return;
+ b = p;
+ end = b + size - 10;
+ while (b < end && (b = memchr(b, 0xE8, end - b)) != NULL) {
+ size_t i = b - (unsigned char *)p;
+ int32_t cp, displacement, value;
+
+ cp = (int32_t)(offset + (uint32_t)i);
+ value = archive_le32dec(&b[1]);
+ if (value >= -cp && value < (int32_t)ds->translation_size) {
+ if (value >= 0)
+ displacement = value - cp;
+ else
+ displacement = value + ds->translation_size;
+ archive_le32enc(&b[1], (uint32_t)displacement);
+ }
+ b += 5;
+ }
+}
+
+/*
+ * Bit stream reader.
+ */
+/* Check that the cache buffer has enough bits. */
+#define lzx_br_has(br, n) ((br)->cache_avail >= n)
+/* Get compressed data by bit. */
+#define lzx_br_bits(br, n) \
+ (((uint32_t)((br)->cache_buffer >> \
+ ((br)->cache_avail - (n)))) & cache_masks[n])
+#define lzx_br_bits_forced(br, n) \
+ (((uint32_t)((br)->cache_buffer << \
+ ((n) - (br)->cache_avail))) & cache_masks[n])
+/* Read ahead to make sure the cache buffer has enough compressed data we
+ * will use.
+ * True : completed, there is enough data in the cache buffer.
+ * False : we met that strm->next_in is empty, we have to get following
+ * bytes. */
+#define lzx_br_read_ahead_0(strm, br, n) \
+ (lzx_br_has((br), (n)) || lzx_br_fillup(strm, br))
+/* True : the cache buffer has some bits as much as we need.
+ * False : there are no enough bits in the cache buffer to be used,
+ * we have to get following bytes if we could. */
+#define lzx_br_read_ahead(strm, br, n) \
+ (lzx_br_read_ahead_0((strm), (br), (n)) || lzx_br_has((br), (n)))
+
+/* Notify how many bits we consumed. */
+#define lzx_br_consume(br, n) ((br)->cache_avail -= (n))
+#define lzx_br_consume_unaligned_bits(br) ((br)->cache_avail &= ~0x0f)
+
+#define lzx_br_is_unaligned(br) ((br)->cache_avail & 0x0f)
+
+static const uint32_t cache_masks[] = {
+ 0x00000000, 0x00000001, 0x00000003, 0x00000007,
+ 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F,
+ 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,
+ 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF,
+ 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF,
+ 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,
+ 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF,
+ 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF,
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
+};
+
+/*
+ * Shift away used bits in the cache data and fill it up with following bits.
+ * Call this when cache buffer does not have enough bits you need.
+ *
+ * Returns 1 if the cache buffer is full.
+ * Returns 0 if the cache buffer is not full; input buffer is empty.
+ */
+static int
+lzx_br_fillup(struct lzx_stream *strm, struct lzx_br *br)
+{
+/*
+ * x86 proccessor family can read misaligned data without an access error.
+ */
+ int n = CACHE_BITS - br->cache_avail;
+
+ for (;;) {
+ switch (n >> 4) {
+ case 4:
+ if (strm->avail_in >= 8) {
+ br->cache_buffer =
+ ((uint64_t)strm->next_in[1]) << 56 |
+ ((uint64_t)strm->next_in[0]) << 48 |
+ ((uint64_t)strm->next_in[3]) << 40 |
+ ((uint64_t)strm->next_in[2]) << 32 |
+ ((uint32_t)strm->next_in[5]) << 24 |
+ ((uint32_t)strm->next_in[4]) << 16 |
+ ((uint32_t)strm->next_in[7]) << 8 |
+ (uint32_t)strm->next_in[6];
+ strm->next_in += 8;
+ strm->avail_in -= 8;
+ br->cache_avail += 8 * 8;
+ return (1);
+ }
+ break;
+ case 3:
+ if (strm->avail_in >= 6) {
+ br->cache_buffer =
+ (br->cache_buffer << 48) |
+ ((uint64_t)strm->next_in[1]) << 40 |
+ ((uint64_t)strm->next_in[0]) << 32 |
+ ((uint32_t)strm->next_in[3]) << 24 |
+ ((uint32_t)strm->next_in[2]) << 16 |
+ ((uint32_t)strm->next_in[5]) << 8 |
+ (uint32_t)strm->next_in[4];
+ strm->next_in += 6;
+ strm->avail_in -= 6;
+ br->cache_avail += 6 * 8;
+ return (1);
+ }
+ break;
+ case 0:
+ /* We have enough compressed data in
+ * the cache buffer.*/
+ return (1);
+ default:
+ break;
+ }
+ if (strm->avail_in < 2) {
+ /* There is not enough compressed data to
+ * fill up the cache buffer. */
+ if (strm->avail_in == 1) {
+ br->odd = *strm->next_in++;
+ strm->avail_in--;
+ br->have_odd = 1;
+ }
+ return (0);
+ }
+ br->cache_buffer =
+ (br->cache_buffer << 16) |
+ archive_le16dec(strm->next_in);
+ strm->next_in += 2;
+ strm->avail_in -= 2;
+ br->cache_avail += 16;
+ n -= 16;
+ }
+}
+
+static void
+lzx_br_fixup(struct lzx_stream *strm, struct lzx_br *br)
+{
+ int n = CACHE_BITS - br->cache_avail;
+
+ if (br->have_odd && n >= 16 && strm->avail_in > 0) {
+ br->cache_buffer =
+ (br->cache_buffer << 16) |
+ ((uint16_t)(*strm->next_in)) << 8 | br->odd;
+ strm->next_in++;
+ strm->avail_in--;
+ br->cache_avail += 16;
+ br->have_odd = 0;
+ }
+}
+
+static void
+lzx_cleanup_bitstream(struct lzx_stream *strm)
+{
+ strm->ds->br.cache_avail = 0;
+ strm->ds->br.have_odd = 0;
+}
+
+/*
+ * Decode LZX.
+ *
+ * 1. Returns ARCHIVE_OK if output buffer or input buffer are empty.
+ * Please set available buffer and call this function again.
+ * 2. Returns ARCHIVE_EOF if decompression has been completed.
+ * 3. Returns ARCHIVE_FAILED if an error occurred; compressed data
+ * is broken or you do not set 'last' flag properly.
+ */
+#define ST_RD_TRANSLATION 0
+#define ST_RD_TRANSLATION_SIZE 1
+#define ST_RD_BLOCK_TYPE 2
+#define ST_RD_BLOCK_SIZE 3
+#define ST_RD_ALIGNMENT 4
+#define ST_RD_R0 5
+#define ST_RD_R1 6
+#define ST_RD_R2 7
+#define ST_COPY_UNCOMP1 8
+#define ST_COPY_UNCOMP2 9
+#define ST_RD_ALIGNED_OFFSET 10
+#define ST_RD_VERBATIM 11
+#define ST_RD_PRE_MAIN_TREE_256 12
+#define ST_MAIN_TREE_256 13
+#define ST_RD_PRE_MAIN_TREE_REM 14
+#define ST_MAIN_TREE_REM 15
+#define ST_RD_PRE_LENGTH_TREE 16
+#define ST_LENGTH_TREE 17
+#define ST_MAIN 18
+#define ST_LENGTH 19
+#define ST_OFFSET 20
+#define ST_REAL_POS 21
+#define ST_COPY 22
+
+static int
+lzx_decode(struct lzx_stream *strm, int last)
+{
+ struct lzx_dec *ds = strm->ds;
+ int64_t avail_in;
+ int r;
+
+ if (ds->error)
+ return (ds->error);
+
+ avail_in = strm->avail_in;
+ lzx_br_fixup(strm, &(ds->br));
+ do {
+ if (ds->state < ST_MAIN)
+ r = lzx_read_blocks(strm, last);
+ else {
+ int64_t bytes_written = strm->avail_out;
+ r = lzx_decode_blocks(strm, last);
+ bytes_written -= strm->avail_out;
+ strm->next_out += bytes_written;
+ strm->total_out += bytes_written;
+ }
+ } while (r == 100);
+ strm->total_in += avail_in - strm->avail_in;
+ return (r);
+}
+
+static int
+lzx_read_blocks(struct lzx_stream *strm, int last)
+{
+ struct lzx_dec *ds = strm->ds;
+ struct lzx_br *br = &(ds->br);
+ int i, r;
+
+ for (;;) {
+ switch (ds->state) {
+ case ST_RD_TRANSLATION:
+ if (!lzx_br_read_ahead(strm, br, 1)) {
+ ds->state = ST_RD_TRANSLATION;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ ds->translation = lzx_br_bits(br, 1);
+ lzx_br_consume(br, 1);
+ /* FALL THROUGH */
+ case ST_RD_TRANSLATION_SIZE:
+ if (ds->translation) {
+ if (!lzx_br_read_ahead(strm, br, 32)) {
+ ds->state = ST_RD_TRANSLATION_SIZE;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ ds->translation_size = lzx_br_bits(br, 16);
+ lzx_br_consume(br, 16);
+ ds->translation_size <<= 16;
+ ds->translation_size |= lzx_br_bits(br, 16);
+ lzx_br_consume(br, 16);
+ }
+ /* FALL THROUGH */
+ case ST_RD_BLOCK_TYPE:
+ if (!lzx_br_read_ahead(strm, br, 3)) {
+ ds->state = ST_RD_BLOCK_TYPE;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ ds->block_type = lzx_br_bits(br, 3);
+ lzx_br_consume(br, 3);
+ /* Check a block type. */
+ switch (ds->block_type) {
+ case VERBATIM_BLOCK:
+ case ALIGNED_OFFSET_BLOCK:
+ case UNCOMPRESSED_BLOCK:
+ break;
+ default:
+ goto failed;/* Invalid */
+ }
+ /* FALL THROUGH */
+ case ST_RD_BLOCK_SIZE:
+ if (!lzx_br_read_ahead(strm, br, 24)) {
+ ds->state = ST_RD_BLOCK_SIZE;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ ds->block_size = lzx_br_bits(br, 8);
+ lzx_br_consume(br, 8);
+ ds->block_size <<= 16;
+ ds->block_size |= lzx_br_bits(br, 16);
+ lzx_br_consume(br, 16);
+ if (ds->block_size == 0)
+ goto failed;
+ ds->block_bytes_avail = ds->block_size;
+ if (ds->block_type != UNCOMPRESSED_BLOCK) {
+ if (ds->block_type == VERBATIM_BLOCK)
+ ds->state = ST_RD_VERBATIM;
+ else
+ ds->state = ST_RD_ALIGNED_OFFSET;
+ break;
+ }
+ /* FALL THROUGH */
+ case ST_RD_ALIGNMENT:
+ /*
+ * Handle an Uncompressed Block.
+ */
+ /* Skip padding to align following field on
+ * 16-bit boundary. */
+ if (lzx_br_is_unaligned(br))
+ lzx_br_consume_unaligned_bits(br);
+ else {
+ if (lzx_br_read_ahead(strm, br, 16))
+ lzx_br_consume(br, 16);
+ else {
+ ds->state = ST_RD_ALIGNMENT;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ }
+ /* Preparation to read repeated offsets R0,R1 and R2. */
+ ds->rbytes_avail = 0;
+ ds->state = ST_RD_R0;
+ /* FALL THROUGH */
+ case ST_RD_R0:
+ case ST_RD_R1:
+ case ST_RD_R2:
+ do {
+ uint16_t u16;
+ /* Drain bits in the cache buffer of
+ * bit-stream. */
+ if (lzx_br_has(br, 32)) {
+ u16 = lzx_br_bits(br, 16);
+ lzx_br_consume(br, 16);
+ archive_le16enc(ds->rbytes, u16);
+ u16 = lzx_br_bits(br, 16);
+ lzx_br_consume(br, 16);
+ archive_le16enc(ds->rbytes+2, u16);
+ ds->rbytes_avail = 4;
+ } else if (lzx_br_has(br, 16)) {
+ u16 = lzx_br_bits(br, 16);
+ lzx_br_consume(br, 16);
+ archive_le16enc(ds->rbytes, u16);
+ ds->rbytes_avail = 2;
+ }
+ if (ds->rbytes_avail < 4 && ds->br.have_odd) {
+ ds->rbytes[ds->rbytes_avail++] =
+ ds->br.odd;
+ ds->br.have_odd = 0;
+ }
+ while (ds->rbytes_avail < 4) {
+ if (strm->avail_in <= 0) {
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ ds->rbytes[ds->rbytes_avail++] =
+ *strm->next_in++;
+ strm->avail_in--;
+ }
+ ds->rbytes_avail = 0;
+ if (ds->state == ST_RD_R0) {
+ ds->r0 = archive_le32dec(ds->rbytes);
+ if (ds->r0 < 0)
+ goto failed;
+ ds->state = ST_RD_R1;
+ } else if (ds->state == ST_RD_R1) {
+ ds->r1 = archive_le32dec(ds->rbytes);
+ if (ds->r1 < 0)
+ goto failed;
+ ds->state = ST_RD_R2;
+ } else if (ds->state == ST_RD_R2) {
+ ds->r2 = archive_le32dec(ds->rbytes);
+ if (ds->r2 < 0)
+ goto failed;
+ /* We've gotten all repeated offsets. */
+ ds->state = ST_COPY_UNCOMP1;
+ }
+ } while (ds->state != ST_COPY_UNCOMP1);
+ /* FALL THROUGH */
+ case ST_COPY_UNCOMP1:
+ /*
+ * Copy bytes form next_in to next_out directly.
+ */
+ while (ds->block_bytes_avail) {
+ int l;
+
+ if (strm->avail_out <= 0)
+ /* Output buffer is empty. */
+ return (ARCHIVE_OK);
+ if (strm->avail_in <= 0) {
+ /* Input buffer is empty. */
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ l = (int)ds->block_bytes_avail;
+ if (l > ds->w_size - ds->w_pos)
+ l = ds->w_size - ds->w_pos;
+ if (l > strm->avail_out)
+ l = (int)strm->avail_out;
+ if (l > strm->avail_in)
+ l = (int)strm->avail_in;
+ memcpy(strm->next_out, strm->next_in, l);
+ memcpy(&(ds->w_buff[ds->w_pos]),
+ strm->next_in, l);
+ strm->next_in += l;
+ strm->avail_in -= l;
+ strm->next_out += l;
+ strm->avail_out -= l;
+ strm->total_out += l;
+ ds->w_pos = (ds->w_pos + l) & ds->w_mask;
+ ds->block_bytes_avail -= l;
+ }
+ /* FALL THROUGH */
+ case ST_COPY_UNCOMP2:
+ /* Re-align; skip padding byte. */
+ if (ds->block_size & 1) {
+ if (strm->avail_in <= 0) {
+ /* Input buffer is empty. */
+ ds->state = ST_COPY_UNCOMP2;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ strm->next_in++;
+ strm->avail_in --;
+ }
+ /* This block ended. */
+ ds->state = ST_RD_BLOCK_TYPE;
+ return (ARCHIVE_EOF);
+ /********************/
+ case ST_RD_ALIGNED_OFFSET:
+ /*
+ * Read Aligned offset tree.
+ */
+ if (!lzx_br_read_ahead(strm, br, 3 * ds->at.len_size)) {
+ ds->state = ST_RD_ALIGNED_OFFSET;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ memset(ds->at.freq, 0, sizeof(ds->at.freq));
+ for (i = 0; i < ds->at.len_size; i++) {
+ ds->at.bitlen[i] = lzx_br_bits(br, 3);
+ ds->at.freq[ds->at.bitlen[i]]++;
+ lzx_br_consume(br, 3);
+ }
+ if (!lzx_make_huffman_table(&ds->at))
+ goto failed;
+ /* FALL THROUGH */
+ case ST_RD_VERBATIM:
+ ds->loop = 0;
+ /* FALL THROUGH */
+ case ST_RD_PRE_MAIN_TREE_256:
+ /*
+ * Read Pre-tree for first 256 elements of main tree.
+ */
+ if (!lzx_read_pre_tree(strm)) {
+ ds->state = ST_RD_PRE_MAIN_TREE_256;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ if (!lzx_make_huffman_table(&ds->pt))
+ goto failed;
+ ds->loop = 0;
+ /* FALL THROUGH */
+ case ST_MAIN_TREE_256:
+ /*
+ * Get path lengths of first 256 elements of main tree.
+ */
+ r = lzx_read_bitlen(strm, &ds->mt, 256);
+ if (r < 0)
+ goto failed;
+ else if (!r) {
+ ds->state = ST_MAIN_TREE_256;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ ds->loop = 0;
+ /* FALL THROUGH */
+ case ST_RD_PRE_MAIN_TREE_REM:
+ /*
+ * Read Pre-tree for remaining elements of main tree.
+ */
+ if (!lzx_read_pre_tree(strm)) {
+ ds->state = ST_RD_PRE_MAIN_TREE_REM;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ if (!lzx_make_huffman_table(&ds->pt))
+ goto failed;
+ ds->loop = 256;
+ /* FALL THROUGH */
+ case ST_MAIN_TREE_REM:
+ /*
+ * Get path lengths of remaining elements of main tree.
+ */
+ r = lzx_read_bitlen(strm, &ds->mt, -1);
+ if (r < 0)
+ goto failed;
+ else if (!r) {
+ ds->state = ST_MAIN_TREE_REM;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ if (!lzx_make_huffman_table(&ds->mt))
+ goto failed;
+ ds->loop = 0;
+ /* FALL THROUGH */
+ case ST_RD_PRE_LENGTH_TREE:
+ /*
+ * Read Pre-tree for remaining elements of main tree.
+ */
+ if (!lzx_read_pre_tree(strm)) {
+ ds->state = ST_RD_PRE_LENGTH_TREE;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ if (!lzx_make_huffman_table(&ds->pt))
+ goto failed;
+ ds->loop = 0;
+ /* FALL THROUGH */
+ case ST_LENGTH_TREE:
+ /*
+ * Get path lengths of remaining elements of main tree.
+ */
+ r = lzx_read_bitlen(strm, &ds->lt, -1);
+ if (r < 0)
+ goto failed;
+ else if (!r) {
+ ds->state = ST_LENGTH_TREE;
+ if (last)
+ goto failed;
+ return (ARCHIVE_OK);
+ }
+ if (!lzx_make_huffman_table(&ds->lt))
+ goto failed;
+ ds->state = ST_MAIN;
+ return (100);
+ }
+ }
+failed:
+ return (ds->error = ARCHIVE_FAILED);
+}
+
+static int
+lzx_decode_blocks(struct lzx_stream *strm, int last)
+{
+ struct lzx_dec *ds = strm->ds;
+ struct lzx_br bre = ds->br;
+ struct huffman *at = &(ds->at), *lt = &(ds->lt), *mt = &(ds->mt);
+ const struct lzx_pos_tbl *pos_tbl = ds->pos_tbl;
+ unsigned char *noutp = strm->next_out;
+ unsigned char *endp = noutp + strm->avail_out;
+ unsigned char *w_buff = ds->w_buff;
+ unsigned char *at_bitlen = at->bitlen;
+ unsigned char *lt_bitlen = lt->bitlen;
+ unsigned char *mt_bitlen = mt->bitlen;
+ size_t block_bytes_avail = ds->block_bytes_avail;
+ int at_max_bits = at->max_bits;
+ int lt_max_bits = lt->max_bits;
+ int mt_max_bits = mt->max_bits;
+ int c, copy_len = ds->copy_len, copy_pos = ds->copy_pos;
+ int w_pos = ds->w_pos, w_mask = ds->w_mask, w_size = ds->w_size;
+ int length_header = ds->length_header;
+ int offset_bits = ds->offset_bits;
+ int position_slot = ds->position_slot;
+ int r0 = ds->r0, r1 = ds->r1, r2 = ds->r2;
+ int state = ds->state;
+ char block_type = ds->block_type;
+
+ for (;;) {
+ switch (state) {
+ case ST_MAIN:
+ for (;;) {
+ if (block_bytes_avail == 0) {
+ /* This block ended. */
+ ds->state = ST_RD_BLOCK_TYPE;
+ ds->br = bre;
+ ds->block_bytes_avail =
+ block_bytes_avail;
+ ds->copy_len = copy_len;
+ ds->copy_pos = copy_pos;
+ ds->length_header = length_header;
+ ds->position_slot = position_slot;
+ ds->r0 = r0; ds->r1 = r1; ds->r2 = r2;
+ ds->w_pos = w_pos;
+ strm->avail_out = endp - noutp;
+ return (ARCHIVE_EOF);
+ }
+ if (noutp >= endp)
+ /* Output buffer is empty. */
+ goto next_data;
+
+ if (!lzx_br_read_ahead(strm, &bre,
+ mt_max_bits)) {
+ if (!last)
+ goto next_data;
+ /* Remaining bits are less than
+ * maximum bits(mt.max_bits) but maybe
+ * it still remains as much as we need,
+ * so we should try to use it with
+ * dummy bits. */
+ c = lzx_decode_huffman(mt,
+ lzx_br_bits_forced(
+ &bre, mt_max_bits));
+ lzx_br_consume(&bre, mt_bitlen[c]);
+ if (!lzx_br_has(&bre, 0))
+ goto failed;/* Over read. */
+ } else {
+ c = lzx_decode_huffman(mt,
+ lzx_br_bits(&bre, mt_max_bits));
+ lzx_br_consume(&bre, mt_bitlen[c]);
+ }
+ if (c > UCHAR_MAX)
+ break;
+ /*
+ * 'c' is exactly literal code.
+ */
+ /* Save a decoded code to reference it
+ * afterward. */
+ w_buff[w_pos] = c;
+ w_pos = (w_pos + 1) & w_mask;
+ /* Store the decoded code to output buffer. */
+ *noutp++ = c;
+ block_bytes_avail--;
+ }
+ /*
+ * Get a match code, its length and offset.
+ */
+ c -= UCHAR_MAX + 1;
+ length_header = c & 7;
+ position_slot = c >> 3;
+ /* FALL THROUGH */
+ case ST_LENGTH:
+ /*
+ * Get a length.
+ */
+ if (length_header == 7) {
+ if (!lzx_br_read_ahead(strm, &bre,
+ lt_max_bits)) {
+ if (!last) {
+ state = ST_LENGTH;
+ goto next_data;
+ }
+ c = lzx_decode_huffman(lt,
+ lzx_br_bits_forced(
+ &bre, lt_max_bits));
+ lzx_br_consume(&bre, lt_bitlen[c]);
+ if (!lzx_br_has(&bre, 0))
+ goto failed;/* Over read. */
+ } else {
+ c = lzx_decode_huffman(lt,
+ lzx_br_bits(&bre, lt_max_bits));
+ lzx_br_consume(&bre, lt_bitlen[c]);
+ }
+ copy_len = c + 7 + 2;
+ } else
+ copy_len = length_header + 2;
+ if ((size_t)copy_len > block_bytes_avail)
+ goto failed;
+ /*
+ * Get an offset.
+ */
+ switch (position_slot) {
+ case 0: /* Use repeated offset 0. */
+ copy_pos = r0;
+ state = ST_REAL_POS;
+ continue;
+ case 1: /* Use repeated offset 1. */
+ copy_pos = r1;
+ /* Swap repeated offset. */
+ r1 = r0;
+ r0 = copy_pos;
+ state = ST_REAL_POS;
+ continue;
+ case 2: /* Use repeated offset 2. */
+ copy_pos = r2;
+ /* Swap repeated offset. */
+ r2 = r0;
+ r0 = copy_pos;
+ state = ST_REAL_POS;
+ continue;
+ default:
+ offset_bits =
+ pos_tbl[position_slot].footer_bits;
+ break;
+ }
+ /* FALL THROUGH */
+ case ST_OFFSET:
+ /*
+ * Get the offset, which is a distance from
+ * current window position.
+ */
+ if (block_type == ALIGNED_OFFSET_BLOCK &&
+ offset_bits >= 3) {
+ int offbits = offset_bits - 3;
+
+ if (!lzx_br_read_ahead(strm, &bre, offbits)) {
+ state = ST_OFFSET;
+ if (last)
+ goto failed;
+ goto next_data;
+ }
+ copy_pos = lzx_br_bits(&bre, offbits) << 3;
+
+ /* Get an aligned number. */
+ if (!lzx_br_read_ahead(strm, &bre,
+ offbits + at_max_bits)) {
+ if (!last) {
+ state = ST_OFFSET;
+ goto next_data;
+ }
+ lzx_br_consume(&bre, offbits);
+ c = lzx_decode_huffman(at,
+ lzx_br_bits_forced(&bre,
+ at_max_bits));
+ lzx_br_consume(&bre, at_bitlen[c]);
+ if (!lzx_br_has(&bre, 0))
+ goto failed;/* Over read. */
+ } else {
+ lzx_br_consume(&bre, offbits);
+ c = lzx_decode_huffman(at,
+ lzx_br_bits(&bre, at_max_bits));
+ lzx_br_consume(&bre, at_bitlen[c]);
+ }
+ /* Add an aligned number. */
+ copy_pos += c;
+ } else {
+ if (!lzx_br_read_ahead(strm, &bre,
+ offset_bits)) {
+ state = ST_OFFSET;
+ if (last)
+ goto failed;
+ goto next_data;
+ }
+ copy_pos = lzx_br_bits(&bre, offset_bits);
+ lzx_br_consume(&bre, offset_bits);
+ }
+ copy_pos += pos_tbl[position_slot].base -2;
+
+ /* Update repeated offset LRU queue. */
+ r2 = r1;
+ r1 = r0;
+ r0 = copy_pos;
+ /* FALL THROUGH */
+ case ST_REAL_POS:
+ /*
+ * Compute a real position in window.
+ */
+ copy_pos = (w_pos - copy_pos) & w_mask;
+ /* FALL THROUGH */
+ case ST_COPY:
+ /*
+ * Copy several bytes as extracted data from the window
+ * into the output buffer.
+ */
+ for (;;) {
+ const unsigned char *s;
+ int l;
+
+ l = copy_len;
+ if (copy_pos > w_pos) {
+ if (l > w_size - copy_pos)
+ l = w_size - copy_pos;
+ } else {
+ if (l > w_size - w_pos)
+ l = w_size - w_pos;
+ }
+ if (noutp + l >= endp)
+ l = (int)(endp - noutp);
+ s = w_buff + copy_pos;
+ if (l >= 8 && ((copy_pos + l < w_pos)
+ || (w_pos + l < copy_pos))) {
+ memcpy(w_buff + w_pos, s, l);
+ memcpy(noutp, s, l);
+ } else {
+ unsigned char *d;
+ int li;
+
+ d = w_buff + w_pos;
+ for (li = 0; li < l; li++)
+ noutp[li] = d[li] = s[li];
+ }
+ noutp += l;
+ copy_pos = (copy_pos + l) & w_mask;
+ w_pos = (w_pos + l) & w_mask;
+ block_bytes_avail -= l;
+ if (copy_len <= l)
+ /* A copy of current pattern ended. */
+ break;
+ copy_len -= l;
+ if (noutp >= endp) {
+ /* Output buffer is empty. */
+ state = ST_COPY;
+ goto next_data;
+ }
+ }
+ state = ST_MAIN;
+ break;
+ }
+ }
+failed:
+ return (ds->error = ARCHIVE_FAILED);
+next_data:
+ ds->br = bre;
+ ds->block_bytes_avail = block_bytes_avail;
+ ds->copy_len = copy_len;
+ ds->copy_pos = copy_pos;
+ ds->length_header = length_header;
+ ds->offset_bits = offset_bits;
+ ds->position_slot = position_slot;
+ ds->r0 = r0; ds->r1 = r1; ds->r2 = r2;
+ ds->state = state;
+ ds->w_pos = w_pos;
+ strm->avail_out = endp - noutp;
+ return (ARCHIVE_OK);
+}
+
+static int
+lzx_read_pre_tree(struct lzx_stream *strm)
+{
+ struct lzx_dec *ds = strm->ds;
+ struct lzx_br *br = &(ds->br);
+ int i;
+
+ if (ds->loop == 0)
+ memset(ds->pt.freq, 0, sizeof(ds->pt.freq));
+ for (i = ds->loop; i < ds->pt.len_size; i++) {
+ if (!lzx_br_read_ahead(strm, br, 4)) {
+ ds->loop = i;
+ return (0);
+ }
+ ds->pt.bitlen[i] = lzx_br_bits(br, 4);
+ ds->pt.freq[ds->pt.bitlen[i]]++;
+ lzx_br_consume(br, 4);
+ }
+ ds->loop = i;
+ return (1);
+}
+
+/*
+ * Read a bunch of bit-lengths from pre-tree.
+ */
+static int
+lzx_read_bitlen(struct lzx_stream *strm, struct huffman *d, int end)
+{
+ struct lzx_dec *ds = strm->ds;
+ struct lzx_br *br = &(ds->br);
+ int c, i, j, ret, same;
+ unsigned rbits;
+
+ i = ds->loop;
+ if (i == 0)
+ memset(d->freq, 0, sizeof(d->freq));
+ ret = 0;
+ if (end < 0)
+ end = d->len_size;
+ while (i < end) {
+ ds->loop = i;
+ if (!lzx_br_read_ahead(strm, br, ds->pt.max_bits))
+ goto getdata;
+ rbits = lzx_br_bits(br, ds->pt.max_bits);
+ c = lzx_decode_huffman(&(ds->pt), rbits);
+ switch (c) {
+ case 17:/* several zero lengths, from 4 to 19. */
+ if (!lzx_br_read_ahead(strm, br, ds->pt.bitlen[c]+4))
+ goto getdata;
+ lzx_br_consume(br, ds->pt.bitlen[c]);
+ same = lzx_br_bits(br, 4) + 4;
+ if (i + same > end)
+ return (-1);/* Invalid */
+ lzx_br_consume(br, 4);
+ for (j = 0; j < same; j++)
+ d->bitlen[i++] = 0;
+ break;
+ case 18:/* many zero lengths, from 20 to 51. */
+ if (!lzx_br_read_ahead(strm, br, ds->pt.bitlen[c]+5))
+ goto getdata;
+ lzx_br_consume(br, ds->pt.bitlen[c]);
+ same = lzx_br_bits(br, 5) + 20;
+ if (i + same > end)
+ return (-1);/* Invalid */
+ lzx_br_consume(br, 5);
+ memset(d->bitlen + i, 0, same);
+ i += same;
+ break;
+ case 19:/* a few same lengths. */
+ if (!lzx_br_read_ahead(strm, br,
+ ds->pt.bitlen[c]+1+ds->pt.max_bits))
+ goto getdata;
+ lzx_br_consume(br, ds->pt.bitlen[c]);
+ same = lzx_br_bits(br, 1) + 4;
+ if (i + same > end)
+ return (-1);
+ lzx_br_consume(br, 1);
+ rbits = lzx_br_bits(br, ds->pt.max_bits);
+ c = lzx_decode_huffman(&(ds->pt), rbits);
+ lzx_br_consume(br, ds->pt.bitlen[c]);
+ c = (d->bitlen[i] - c + 17) % 17;
+ if (c < 0)
+ return (-1);/* Invalid */
+ for (j = 0; j < same; j++)
+ d->bitlen[i++] = c;
+ d->freq[c] += same;
+ break;
+ default:
+ lzx_br_consume(br, ds->pt.bitlen[c]);
+ c = (d->bitlen[i] - c + 17) % 17;
+ if (c < 0)
+ return (-1);/* Invalid */
+ d->freq[c]++;
+ d->bitlen[i++] = c;
+ break;
+ }
+ }
+ ret = 1;
+getdata:
+ ds->loop = i;
+ return (ret);
+}
+
+static int
+lzx_huffman_init(struct huffman *hf, size_t len_size, int tbl_bits)
+{
+ int bits;
+
+ if (hf->bitlen == NULL || hf->len_size != (int)len_size) {
+ free(hf->bitlen);
+ hf->bitlen = calloc(len_size, sizeof(hf->bitlen[0]));
+ if (hf->bitlen == NULL)
+ return (ARCHIVE_FATAL);
+ hf->len_size = (int)len_size;
+ } else
+ memset(hf->bitlen, 0, len_size * sizeof(hf->bitlen[0]));
+ if (hf->tbl == NULL) {
+ if (tbl_bits < HTBL_BITS)
+ bits = tbl_bits;
+ else
+ bits = HTBL_BITS;
+ hf->tbl = malloc(((size_t)1 << bits) * sizeof(hf->tbl[0]));
+ if (hf->tbl == NULL)
+ return (ARCHIVE_FATAL);
+ hf->tbl_bits = tbl_bits;
+ }
+ if (hf->tree == NULL && tbl_bits > HTBL_BITS) {
+ hf->tree_avail = 1 << (tbl_bits - HTBL_BITS + 4);
+ hf->tree = malloc(hf->tree_avail * sizeof(hf->tree[0]));
+ if (hf->tree == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+
+static void
+lzx_huffman_free(struct huffman *hf)
+{
+ free(hf->bitlen);
+ free(hf->tbl);
+ free(hf->tree);
+}
+
+/*
+ * Make a huffman coding table.
+ */
+static int
+lzx_make_huffman_table(struct huffman *hf)
+{
+ uint16_t *tbl;
+ const unsigned char *bitlen;
+ int bitptn[17], weight[17];
+ int i, maxbits = 0, ptn, tbl_size, w;
+ int diffbits, len_avail;
+
+ /*
+ * Initialize bit patterns.
+ */
+ ptn = 0;
+ for (i = 1, w = 1 << 15; i <= 16; i++, w >>= 1) {
+ bitptn[i] = ptn;
+ weight[i] = w;
+ if (hf->freq[i]) {
+ ptn += hf->freq[i] * w;
+ maxbits = i;
+ }
+ }
+ if ((ptn & 0xffff) != 0 || maxbits > hf->tbl_bits)
+ return (0);/* Invalid */
+
+ hf->max_bits = maxbits;
+
+ /*
+ * Cut out extra bits which we won't house in the table.
+ * This preparation reduces the same calculation in the for-loop
+ * making the table.
+ */
+ if (maxbits < 16) {
+ int ebits = 16 - maxbits;
+ for (i = 1; i <= maxbits; i++) {
+ bitptn[i] >>= ebits;
+ weight[i] >>= ebits;
+ }
+ }
+ if (maxbits > HTBL_BITS) {
+ int htbl_max;
+ uint16_t *p;
+
+ diffbits = maxbits - HTBL_BITS;
+ for (i = 1; i <= HTBL_BITS; i++) {
+ bitptn[i] >>= diffbits;
+ weight[i] >>= diffbits;
+ }
+ htbl_max = bitptn[HTBL_BITS] +
+ weight[HTBL_BITS] * hf->freq[HTBL_BITS];
+ p = &(hf->tbl[htbl_max]);
+ while (p < &hf->tbl[1U<<HTBL_BITS])
+ *p++ = 0;
+ } else
+ diffbits = 0;
+ hf->shift_bits = diffbits;
+
+ /*
+ * Make the table.
+ */
+ tbl_size = 1 << HTBL_BITS;
+ tbl = hf->tbl;
+ bitlen = hf->bitlen;
+ len_avail = hf->len_size;
+ hf->tree_used = 0;
+ for (i = 0; i < len_avail; i++) {
+ uint16_t *p;
+ int len, cnt;
+ uint16_t bit;
+ int extlen;
+ struct htree_t *ht;
+
+ if (bitlen[i] == 0)
+ continue;
+ /* Get a bit pattern */
+ len = bitlen[i];
+ ptn = bitptn[len];
+ cnt = weight[len];
+ if (len <= HTBL_BITS) {
+ /* Calculate next bit pattern */
+ if ((bitptn[len] = ptn + cnt) > tbl_size)
+ return (0);/* Invalid */
+ /* Update the table */
+ p = &(tbl[ptn]);
+ while (--cnt >= 0)
+ p[cnt] = (uint16_t)i;
+ continue;
+ }
+
+ /*
+ * A bit length is too big to be housed to a direct table,
+ * so we use a tree model for its extra bits.
+ */
+ bitptn[len] = ptn + cnt;
+ bit = 1U << (diffbits -1);
+ extlen = len - HTBL_BITS;
+
+ p = &(tbl[ptn >> diffbits]);
+ if (*p == 0) {
+ *p = len_avail + hf->tree_used;
+ ht = &(hf->tree[hf->tree_used++]);
+ if (hf->tree_used > hf->tree_avail)
+ return (0);/* Invalid */
+ ht->left = 0;
+ ht->right = 0;
+ } else {
+ if (*p < len_avail ||
+ *p >= (len_avail + hf->tree_used))
+ return (0);/* Invalid */
+ ht = &(hf->tree[*p - len_avail]);
+ }
+ while (--extlen > 0) {
+ if (ptn & bit) {
+ if (ht->left < len_avail) {
+ ht->left = len_avail + hf->tree_used;
+ ht = &(hf->tree[hf->tree_used++]);
+ if (hf->tree_used > hf->tree_avail)
+ return (0);/* Invalid */
+ ht->left = 0;
+ ht->right = 0;
+ } else {
+ ht = &(hf->tree[ht->left - len_avail]);
+ }
+ } else {
+ if (ht->right < len_avail) {
+ ht->right = len_avail + hf->tree_used;
+ ht = &(hf->tree[hf->tree_used++]);
+ if (hf->tree_used > hf->tree_avail)
+ return (0);/* Invalid */
+ ht->left = 0;
+ ht->right = 0;
+ } else {
+ ht = &(hf->tree[ht->right - len_avail]);
+ }
+ }
+ bit >>= 1;
+ }
+ if (ptn & bit) {
+ if (ht->left != 0)
+ return (0);/* Invalid */
+ ht->left = (uint16_t)i;
+ } else {
+ if (ht->right != 0)
+ return (0);/* Invalid */
+ ht->right = (uint16_t)i;
+ }
+ }
+ return (1);
+}
+
+static int
+lzx_decode_huffman_tree(struct huffman *hf, unsigned rbits, int c)
+{
+ struct htree_t *ht;
+ int extlen;
+
+ ht = hf->tree;
+ extlen = hf->shift_bits;
+ while (c >= hf->len_size) {
+ c -= hf->len_size;
+ if (extlen-- <= 0 || c >= hf->tree_used)
+ return (0);
+ if (rbits & (1U << extlen))
+ c = ht[c].left;
+ else
+ c = ht[c].right;
+ }
+ return (c);
+}
+
+static inline int
+lzx_decode_huffman(struct huffman *hf, unsigned rbits)
+{
+ int c;
+ /*
+ * At first search an index table for a bit pattern.
+ * If it fails, search a huffman tree for.
+ */
+ c = hf->tbl[rbits >> hf->shift_bits];
+ if (c < hf->len_size)
+ return (c);
+ /* This bit pattern needs to be found out at a huffman tree. */
+ return (lzx_decode_huffman_tree(hf, rbits, c));
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c
new file mode 100644
index 0000000000..0b6968980b
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c
@@ -0,0 +1,1068 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2010-2012 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: head/lib/libarchive/archive_read_support_format_cpio.c 201163 2009-12-29 05:50:34Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+/* #include <stdint.h> */ /* See archive_platform.h */
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+#define bin_magic_offset 0
+#define bin_magic_size 2
+#define bin_dev_offset 2
+#define bin_dev_size 2
+#define bin_ino_offset 4
+#define bin_ino_size 2
+#define bin_mode_offset 6
+#define bin_mode_size 2
+#define bin_uid_offset 8
+#define bin_uid_size 2
+#define bin_gid_offset 10
+#define bin_gid_size 2
+#define bin_nlink_offset 12
+#define bin_nlink_size 2
+#define bin_rdev_offset 14
+#define bin_rdev_size 2
+#define bin_mtime_offset 16
+#define bin_mtime_size 4
+#define bin_namesize_offset 20
+#define bin_namesize_size 2
+#define bin_filesize_offset 22
+#define bin_filesize_size 4
+#define bin_header_size 26
+
+#define odc_magic_offset 0
+#define odc_magic_size 6
+#define odc_dev_offset 6
+#define odc_dev_size 6
+#define odc_ino_offset 12
+#define odc_ino_size 6
+#define odc_mode_offset 18
+#define odc_mode_size 6
+#define odc_uid_offset 24
+#define odc_uid_size 6
+#define odc_gid_offset 30
+#define odc_gid_size 6
+#define odc_nlink_offset 36
+#define odc_nlink_size 6
+#define odc_rdev_offset 42
+#define odc_rdev_size 6
+#define odc_mtime_offset 48
+#define odc_mtime_size 11
+#define odc_namesize_offset 59
+#define odc_namesize_size 6
+#define odc_filesize_offset 65
+#define odc_filesize_size 11
+#define odc_header_size 76
+
+#define newc_magic_offset 0
+#define newc_magic_size 6
+#define newc_ino_offset 6
+#define newc_ino_size 8
+#define newc_mode_offset 14
+#define newc_mode_size 8
+#define newc_uid_offset 22
+#define newc_uid_size 8
+#define newc_gid_offset 30
+#define newc_gid_size 8
+#define newc_nlink_offset 38
+#define newc_nlink_size 8
+#define newc_mtime_offset 46
+#define newc_mtime_size 8
+#define newc_filesize_offset 54
+#define newc_filesize_size 8
+#define newc_devmajor_offset 62
+#define newc_devmajor_size 8
+#define newc_devminor_offset 70
+#define newc_devminor_size 8
+#define newc_rdevmajor_offset 78
+#define newc_rdevmajor_size 8
+#define newc_rdevminor_offset 86
+#define newc_rdevminor_size 8
+#define newc_namesize_offset 94
+#define newc_namesize_size 8
+#define newc_checksum_offset 102
+#define newc_checksum_size 8
+#define newc_header_size 110
+
+/*
+ * An afio large ASCII header, which they named itself.
+ * afio utility uses this header, if a file size is larger than 2G bytes
+ * or inode/uid/gid is bigger than 65535(0xFFFF) or mtime is bigger than
+ * 0x7fffffff, which we cannot record to odc header because of its limit.
+ * If not, uses odc header.
+ */
+#define afiol_magic_offset 0
+#define afiol_magic_size 6
+#define afiol_dev_offset 6
+#define afiol_dev_size 8 /* hex */
+#define afiol_ino_offset 14
+#define afiol_ino_size 16 /* hex */
+#define afiol_ino_m_offset 30 /* 'm' */
+#define afiol_mode_offset 31
+#define afiol_mode_size 6 /* oct */
+#define afiol_uid_offset 37
+#define afiol_uid_size 8 /* hex */
+#define afiol_gid_offset 45
+#define afiol_gid_size 8 /* hex */
+#define afiol_nlink_offset 53
+#define afiol_nlink_size 8 /* hex */
+#define afiol_rdev_offset 61
+#define afiol_rdev_size 8 /* hex */
+#define afiol_mtime_offset 69
+#define afiol_mtime_size 16 /* hex */
+#define afiol_mtime_n_offset 85 /* 'n' */
+#define afiol_namesize_offset 86
+#define afiol_namesize_size 4 /* hex */
+#define afiol_flag_offset 90
+#define afiol_flag_size 4 /* hex */
+#define afiol_xsize_offset 94
+#define afiol_xsize_size 4 /* hex */
+#define afiol_xsize_s_offset 98 /* 's' */
+#define afiol_filesize_offset 99
+#define afiol_filesize_size 16 /* hex */
+#define afiol_filesize_c_offset 115 /* ':' */
+#define afiol_header_size 116
+
+
+struct links_entry {
+ struct links_entry *next;
+ struct links_entry *previous;
+ int links;
+ dev_t dev;
+ int64_t ino;
+ char *name;
+};
+
+#define CPIO_MAGIC 0x13141516
+struct cpio {
+ int magic;
+ int (*read_header)(struct archive_read *, struct cpio *,
+ struct archive_entry *, size_t *, size_t *);
+ struct links_entry *links_head;
+ int64_t entry_bytes_remaining;
+ int64_t entry_bytes_unconsumed;
+ int64_t entry_offset;
+ int64_t entry_padding;
+
+ struct archive_string_conv *opt_sconv;
+ struct archive_string_conv *sconv_default;
+ int init_default_conversion;
+};
+
+static int64_t atol16(const char *, unsigned);
+static int64_t atol8(const char *, unsigned);
+static int archive_read_format_cpio_bid(struct archive_read *, int);
+static int archive_read_format_cpio_options(struct archive_read *,
+ const char *, const char *);
+static int archive_read_format_cpio_cleanup(struct archive_read *);
+static int archive_read_format_cpio_read_data(struct archive_read *,
+ const void **, size_t *, int64_t *);
+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 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 *,
+ struct archive_entry *, size_t *, size_t *);
+static int header_bin_le(struct archive_read *, struct cpio *,
+ struct archive_entry *, size_t *, size_t *);
+static int header_newc(struct archive_read *, struct cpio *,
+ struct archive_entry *, size_t *, size_t *);
+static int header_odc(struct archive_read *, struct cpio *,
+ struct archive_entry *, size_t *, size_t *);
+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 int record_hardlink(struct archive_read *a,
+ struct cpio *cpio, struct archive_entry *entry);
+
+int
+archive_read_support_format_cpio(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct cpio *cpio;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_cpio");
+
+ cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+ if (cpio == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
+ return (ARCHIVE_FATAL);
+ }
+ cpio->magic = CPIO_MAGIC;
+
+ r = __archive_read_register_format(a,
+ cpio,
+ "cpio",
+ archive_read_format_cpio_bid,
+ archive_read_format_cpio_options,
+ archive_read_format_cpio_read_header,
+ archive_read_format_cpio_read_data,
+ archive_read_format_cpio_skip,
+ NULL,
+ archive_read_format_cpio_cleanup,
+ NULL,
+ NULL);
+
+ if (r != ARCHIVE_OK)
+ free(cpio);
+ return (ARCHIVE_OK);
+}
+
+
+static int
+archive_read_format_cpio_bid(struct archive_read *a, int best_bid)
+{
+ const unsigned char *p;
+ struct cpio *cpio;
+ int bid;
+
+ (void)best_bid; /* UNUSED */
+
+ cpio = (struct cpio *)(a->format->data);
+
+ if ((p = __archive_read_ahead(a, 6, NULL)) == NULL)
+ return (-1);
+
+ bid = 0;
+ if (memcmp(p, "070707", 6) == 0) {
+ /* ASCII cpio archive (odc, POSIX.1) */
+ cpio->read_header = header_odc;
+ bid += 48;
+ /*
+ * XXX TODO: More verification; Could check that only octal
+ * digits appear in appropriate header locations. XXX
+ */
+ } else if (memcmp(p, "070727", 6) == 0) {
+ /* afio large ASCII cpio archive */
+ cpio->read_header = header_odc;
+ bid += 48;
+ /*
+ * XXX TODO: More verification; Could check that almost hex
+ * digits appear in appropriate header locations. XXX
+ */
+ } else if (memcmp(p, "070701", 6) == 0) {
+ /* ASCII cpio archive (SVR4 without CRC) */
+ cpio->read_header = header_newc;
+ bid += 48;
+ /*
+ * XXX TODO: More verification; Could check that only hex
+ * digits appear in appropriate header locations. XXX
+ */
+ } else if (memcmp(p, "070702", 6) == 0) {
+ /* ASCII cpio archive (SVR4 with CRC) */
+ /* XXX TODO: Flag that we should check the CRC. XXX */
+ cpio->read_header = header_newc;
+ bid += 48;
+ /*
+ * XXX TODO: More verification; Could check that only hex
+ * digits appear in appropriate header locations. XXX
+ */
+ } else if (p[0] * 256 + p[1] == 070707) {
+ /* big-endian binary cpio archives */
+ cpio->read_header = header_bin_be;
+ bid += 16;
+ /* Is more verification possible here? */
+ } else if (p[0] + p[1] * 256 == 070707) {
+ /* little-endian binary cpio archives */
+ cpio->read_header = header_bin_le;
+ bid += 16;
+ /* Is more verification possible here? */
+ } else
+ return (ARCHIVE_WARN);
+
+ return (bid);
+}
+
+static int
+archive_read_format_cpio_options(struct archive_read *a,
+ const char *key, const char *val)
+{
+ struct cpio *cpio;
+ int ret = ARCHIVE_FAILED;
+
+ cpio = (struct cpio *)(a->format->data);
+ if (strcmp(key, "compat-2x") == 0) {
+ /* Handle filnames as libarchive 2.x */
+ cpio->init_default_conversion = (val != NULL)?1:0;
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "cpio: hdrcharset option needs a character-set name");
+ else {
+ cpio->opt_sconv =
+ archive_string_conversion_from_charset(
+ &a->archive, val, 0);
+ if (cpio->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ }
+
+ /* 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
+archive_read_format_cpio_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ struct cpio *cpio;
+ const void *h;
+ struct archive_string_conv *sconv;
+ size_t namelength;
+ size_t name_pad;
+ int r;
+
+ cpio = (struct cpio *)(a->format->data);
+ sconv = cpio->opt_sconv;
+ if (sconv == NULL) {
+ if (!cpio->init_default_conversion) {
+ cpio->sconv_default =
+ archive_string_default_conversion_for_read(
+ &(a->archive));
+ cpio->init_default_conversion = 1;
+ }
+ sconv = cpio->sconv_default;
+ }
+
+ r = (cpio->read_header(a, cpio, entry, &namelength, &name_pad));
+
+ if (r < ARCHIVE_WARN)
+ return (r);
+
+ /* Read name from buffer. */
+ h = __archive_read_ahead(a, namelength + name_pad, NULL);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+ if (archive_entry_copy_pathname_l(entry,
+ (const char *)h, namelength, sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Pathname can't be converted from %s to current locale.",
+ archive_string_conversion_charset_name(sconv));
+ r = ARCHIVE_WARN;
+ }
+ cpio->entry_offset = 0;
+
+ __archive_read_consume(a, namelength + name_pad);
+
+ /* If this is a symlink, read the link contents. */
+ if (archive_entry_filetype(entry) == AE_IFLNK) {
+ h = __archive_read_ahead(a,
+ (size_t)cpio->entry_bytes_remaining, NULL);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+ if (archive_entry_copy_symlink_l(entry, (const char *)h,
+ (size_t)cpio->entry_bytes_remaining, sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Linkname can't be converted from %s to "
+ "current locale.",
+ archive_string_conversion_charset_name(sconv));
+ r = ARCHIVE_WARN;
+ }
+ __archive_read_consume(a, cpio->entry_bytes_remaining);
+ cpio->entry_bytes_remaining = 0;
+ }
+
+ /* XXX TODO: If the full mode is 0160200, then this is a Solaris
+ * ACL description for the following entry. Read this body
+ * and parse it as a Solaris-style ACL, then read the next
+ * header. XXX */
+
+ /* Compare name to "TRAILER!!!" to test for end-of-archive. */
+ if (namelength == 11 && strcmp((const char *)h, "TRAILER!!!") == 0) {
+ /* TODO: Store file location of start of block. */
+ archive_clear_error(&a->archive);
+ return (ARCHIVE_EOF);
+ }
+
+ /* Detect and record hardlinks to previously-extracted entries. */
+ if (record_hardlink(a, cpio, entry) != ARCHIVE_OK) {
+ return (ARCHIVE_FATAL);
+ }
+
+ return (r);
+}
+
+static int
+archive_read_format_cpio_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ ssize_t bytes_read;
+ struct cpio *cpio;
+
+ cpio = (struct cpio *)(a->format->data);
+
+ if (cpio->entry_bytes_unconsumed) {
+ __archive_read_consume(a, cpio->entry_bytes_unconsumed);
+ cpio->entry_bytes_unconsumed = 0;
+ }
+
+ if (cpio->entry_bytes_remaining > 0) {
+ *buff = __archive_read_ahead(a, 1, &bytes_read);
+ if (bytes_read <= 0)
+ return (ARCHIVE_FATAL);
+ if (bytes_read > cpio->entry_bytes_remaining)
+ bytes_read = (ssize_t)cpio->entry_bytes_remaining;
+ *size = bytes_read;
+ cpio->entry_bytes_unconsumed = bytes_read;
+ *offset = cpio->entry_offset;
+ cpio->entry_offset += bytes_read;
+ cpio->entry_bytes_remaining -= bytes_read;
+ return (ARCHIVE_OK);
+ } else {
+ if (cpio->entry_padding !=
+ __archive_read_consume(a, cpio->entry_padding)) {
+ return (ARCHIVE_FATAL);
+ }
+ cpio->entry_padding = 0;
+ *buff = NULL;
+ *size = 0;
+ *offset = cpio->entry_offset;
+ return (ARCHIVE_EOF);
+ }
+}
+
+static int
+archive_read_format_cpio_skip(struct archive_read *a)
+{
+ struct cpio *cpio = (struct cpio *)(a->format->data);
+ int64_t to_skip = cpio->entry_bytes_remaining + cpio->entry_padding +
+ cpio->entry_bytes_unconsumed;
+
+ if (to_skip != __archive_read_consume(a, to_skip)) {
+ return (ARCHIVE_FATAL);
+ }
+ cpio->entry_bytes_remaining = 0;
+ cpio->entry_padding = 0;
+ cpio->entry_bytes_unconsumed = 0;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Skip forward to the next cpio newc header by searching for the
+ * 07070[12] string. This should be generalized and merged with
+ * find_odc_header below.
+ */
+static int
+is_hex(const char *p, size_t len)
+{
+ while (len-- > 0) {
+ if ((*p >= '0' && *p <= '9')
+ || (*p >= 'a' && *p <= 'f')
+ || (*p >= 'A' && *p <= 'F'))
+ ++p;
+ else
+ return (0);
+ }
+ return (1);
+}
+
+static int
+find_newc_header(struct archive_read *a)
+{
+ const void *h;
+ const char *p, *q;
+ size_t skip, skipped = 0;
+ ssize_t bytes;
+
+ for (;;) {
+ h = __archive_read_ahead(a, newc_header_size, &bytes);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+ q = p + bytes;
+
+ /* Try the typical case first, then go into the slow search.*/
+ if (memcmp("07070", p, 5) == 0
+ && (p[5] == '1' || p[5] == '2')
+ && is_hex(p, newc_header_size))
+ return (ARCHIVE_OK);
+
+ /*
+ * Scan ahead until we find something that looks
+ * like a newc header.
+ */
+ while (p + newc_header_size <= q) {
+ switch (p[5]) {
+ case '1':
+ case '2':
+ if (memcmp("07070", p, 5) == 0
+ && is_hex(p, newc_header_size)) {
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ skipped += skip;
+ if (skipped > 0) {
+ archive_set_error(&a->archive,
+ 0,
+ "Skipped %d bytes before "
+ "finding valid header",
+ (int)skipped);
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+ }
+ p += 2;
+ break;
+ case '0':
+ p++;
+ break;
+ default:
+ p += 6;
+ break;
+ }
+ }
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ skipped += skip;
+ }
+}
+
+static int
+header_newc(struct archive_read *a, struct cpio *cpio,
+ struct archive_entry *entry, size_t *namelength, size_t *name_pad)
+{
+ const void *h;
+ const char *header;
+ int r;
+
+ r = find_newc_header(a);
+ if (r < ARCHIVE_WARN)
+ return (r);
+
+ /* Read fixed-size portion of header. */
+ h = __archive_read_ahead(a, newc_header_size, NULL);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+
+ /* Parse out hex fields. */
+ header = (const char *)h;
+
+ if (memcmp(header + newc_magic_offset, "070701", 6) == 0) {
+ a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC;
+ a->archive.archive_format_name = "ASCII cpio (SVR4 with no CRC)";
+ } else if (memcmp(header + newc_magic_offset, "070702", 6) == 0) {
+ a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_CRC;
+ a->archive.archive_format_name = "ASCII cpio (SVR4 with CRC)";
+ } else {
+ /* TODO: Abort here? */
+ }
+
+ archive_entry_set_devmajor(entry,
+ (dev_t)atol16(header + newc_devmajor_offset, newc_devmajor_size));
+ archive_entry_set_devminor(entry,
+ (dev_t)atol16(header + newc_devminor_offset, newc_devminor_size));
+ archive_entry_set_ino(entry, atol16(header + newc_ino_offset, newc_ino_size));
+ archive_entry_set_mode(entry,
+ (mode_t)atol16(header + newc_mode_offset, newc_mode_size));
+ archive_entry_set_uid(entry, atol16(header + newc_uid_offset, newc_uid_size));
+ archive_entry_set_gid(entry, atol16(header + newc_gid_offset, newc_gid_size));
+ archive_entry_set_nlink(entry,
+ (unsigned int)atol16(header + newc_nlink_offset, newc_nlink_size));
+ archive_entry_set_rdevmajor(entry,
+ (dev_t)atol16(header + newc_rdevmajor_offset, newc_rdevmajor_size));
+ archive_entry_set_rdevminor(entry,
+ (dev_t)atol16(header + newc_rdevminor_offset, newc_rdevminor_size));
+ archive_entry_set_mtime(entry, atol16(header + newc_mtime_offset, newc_mtime_size), 0);
+ *namelength = (size_t)atol16(header + newc_namesize_offset, newc_namesize_size);
+ /* Pad name to 2 more than a multiple of 4. */
+ *name_pad = (2 - *namelength) & 3;
+
+ /*
+ * Note: entry_bytes_remaining is at least 64 bits and
+ * therefore guaranteed to be big enough for a 33-bit file
+ * size.
+ */
+ cpio->entry_bytes_remaining =
+ atol16(header + newc_filesize_offset, newc_filesize_size);
+ archive_entry_set_size(entry, cpio->entry_bytes_remaining);
+ /* Pad file contents to a multiple of 4. */
+ cpio->entry_padding = 3 & -cpio->entry_bytes_remaining;
+ __archive_read_consume(a, newc_header_size);
+ return (r);
+}
+
+/*
+ * Skip forward to the next cpio odc header by searching for the
+ * 070707 string. This is a hand-optimized search that could
+ * probably be easily generalized to handle all character-based
+ * cpio variants.
+ */
+static int
+is_octal(const char *p, size_t len)
+{
+ while (len-- > 0) {
+ if (*p < '0' || *p > '7')
+ return (0);
+ ++p;
+ }
+ return (1);
+}
+
+static int
+is_afio_large(const char *h, size_t len)
+{
+ if (len < afiol_header_size)
+ return (0);
+ if (h[afiol_ino_m_offset] != 'm'
+ || h[afiol_mtime_n_offset] != 'n'
+ || h[afiol_xsize_s_offset] != 's'
+ || h[afiol_filesize_c_offset] != ':')
+ return (0);
+ if (!is_hex(h + afiol_dev_offset, afiol_ino_m_offset - afiol_dev_offset))
+ return (0);
+ if (!is_hex(h + afiol_mode_offset, afiol_mtime_n_offset - afiol_mode_offset))
+ return (0);
+ if (!is_hex(h + afiol_namesize_offset, afiol_xsize_s_offset - afiol_namesize_offset))
+ return (0);
+ if (!is_hex(h + afiol_filesize_offset, afiol_filesize_size))
+ return (0);
+ return (1);
+}
+
+static int
+find_odc_header(struct archive_read *a)
+{
+ const void *h;
+ const char *p, *q;
+ size_t skip, skipped = 0;
+ ssize_t bytes;
+
+ for (;;) {
+ h = __archive_read_ahead(a, odc_header_size, &bytes);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+ q = p + bytes;
+
+ /* Try the typical case first, then go into the slow search.*/
+ if (memcmp("070707", p, 6) == 0 && is_octal(p, odc_header_size))
+ return (ARCHIVE_OK);
+ if (memcmp("070727", p, 6) == 0 && is_afio_large(p, bytes)) {
+ a->archive.archive_format = ARCHIVE_FORMAT_CPIO_AFIO_LARGE;
+ return (ARCHIVE_OK);
+ }
+
+ /*
+ * Scan ahead until we find something that looks
+ * like an odc header.
+ */
+ while (p + odc_header_size <= q) {
+ switch (p[5]) {
+ case '7':
+ if ((memcmp("070707", p, 6) == 0
+ && is_octal(p, odc_header_size))
+ || (memcmp("070727", p, 6) == 0
+ && is_afio_large(p, q - p))) {
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ skipped += skip;
+ if (p[4] == '2')
+ a->archive.archive_format =
+ ARCHIVE_FORMAT_CPIO_AFIO_LARGE;
+ if (skipped > 0) {
+ archive_set_error(&a->archive,
+ 0,
+ "Skipped %d bytes before "
+ "finding valid header",
+ (int)skipped);
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+ }
+ p += 2;
+ break;
+ case '0':
+ p++;
+ break;
+ default:
+ p += 6;
+ break;
+ }
+ }
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ skipped += skip;
+ }
+}
+
+static int
+header_odc(struct archive_read *a, struct cpio *cpio,
+ struct archive_entry *entry, size_t *namelength, size_t *name_pad)
+{
+ const void *h;
+ int r;
+ const char *header;
+
+ a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX;
+ a->archive.archive_format_name = "POSIX octet-oriented cpio";
+
+ /* Find the start of the next header. */
+ r = find_odc_header(a);
+ if (r < ARCHIVE_WARN)
+ return (r);
+
+ if (a->archive.archive_format == ARCHIVE_FORMAT_CPIO_AFIO_LARGE) {
+ int r2 = (header_afiol(a, cpio, entry, namelength, name_pad));
+ if (r2 == ARCHIVE_OK)
+ return (r);
+ else
+ return (r2);
+ }
+
+ /* Read fixed-size portion of header. */
+ h = __archive_read_ahead(a, odc_header_size, NULL);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+
+ /* Parse out octal fields. */
+ header = (const char *)h;
+
+ archive_entry_set_dev(entry,
+ (dev_t)atol8(header + odc_dev_offset, odc_dev_size));
+ archive_entry_set_ino(entry, atol8(header + odc_ino_offset, odc_ino_size));
+ archive_entry_set_mode(entry,
+ (mode_t)atol8(header + odc_mode_offset, odc_mode_size));
+ archive_entry_set_uid(entry, atol8(header + odc_uid_offset, odc_uid_size));
+ archive_entry_set_gid(entry, atol8(header + odc_gid_offset, odc_gid_size));
+ archive_entry_set_nlink(entry,
+ (unsigned int)atol8(header + odc_nlink_offset, odc_nlink_size));
+ archive_entry_set_rdev(entry,
+ (dev_t)atol8(header + odc_rdev_offset, odc_rdev_size));
+ archive_entry_set_mtime(entry, atol8(header + odc_mtime_offset, odc_mtime_size), 0);
+ *namelength = (size_t)atol8(header + odc_namesize_offset, odc_namesize_size);
+ *name_pad = 0; /* No padding of filename. */
+
+ /*
+ * Note: entry_bytes_remaining is at least 64 bits and
+ * therefore guaranteed to be big enough for a 33-bit file
+ * size.
+ */
+ cpio->entry_bytes_remaining =
+ atol8(header + odc_filesize_offset, odc_filesize_size);
+ archive_entry_set_size(entry, cpio->entry_bytes_remaining);
+ cpio->entry_padding = 0;
+ __archive_read_consume(a, odc_header_size);
+ return (r);
+}
+
+/*
+ * NOTE: if a filename suffix is ".z", it is the file gziped by afio.
+ * it would be nice that we can show uncompressed file size and we can
+ * uncompressed file contents automatically, unfortunately we have nothing
+ * to get a uncompressed file size while reading each header. it means
+ * we also cannot uncompressed file contens under the our framework.
+ */
+static int
+header_afiol(struct archive_read *a, struct cpio *cpio,
+ struct archive_entry *entry, size_t *namelength, size_t *name_pad)
+{
+ const void *h;
+ const char *header;
+
+ a->archive.archive_format = ARCHIVE_FORMAT_CPIO_AFIO_LARGE;
+ a->archive.archive_format_name = "afio large ASCII";
+
+ /* Read fixed-size portion of header. */
+ h = __archive_read_ahead(a, afiol_header_size, NULL);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+
+ /* Parse out octal fields. */
+ header = (const char *)h;
+
+ archive_entry_set_dev(entry,
+ (dev_t)atol16(header + afiol_dev_offset, afiol_dev_size));
+ archive_entry_set_ino(entry, atol16(header + afiol_ino_offset, afiol_ino_size));
+ archive_entry_set_mode(entry,
+ (mode_t)atol8(header + afiol_mode_offset, afiol_mode_size));
+ archive_entry_set_uid(entry, atol16(header + afiol_uid_offset, afiol_uid_size));
+ archive_entry_set_gid(entry, atol16(header + afiol_gid_offset, afiol_gid_size));
+ archive_entry_set_nlink(entry,
+ (unsigned int)atol16(header + afiol_nlink_offset, afiol_nlink_size));
+ archive_entry_set_rdev(entry,
+ (dev_t)atol16(header + afiol_rdev_offset, afiol_rdev_size));
+ archive_entry_set_mtime(entry, atol16(header + afiol_mtime_offset, afiol_mtime_size), 0);
+ *namelength = (size_t)atol16(header + afiol_namesize_offset, afiol_namesize_size);
+ *name_pad = 0; /* No padding of filename. */
+
+ cpio->entry_bytes_remaining =
+ atol16(header + afiol_filesize_offset, afiol_filesize_size);
+ archive_entry_set_size(entry, cpio->entry_bytes_remaining);
+ cpio->entry_padding = 0;
+ __archive_read_consume(a, afiol_header_size);
+ return (ARCHIVE_OK);
+}
+
+
+static int
+header_bin_le(struct archive_read *a, struct cpio *cpio,
+ struct archive_entry *entry, size_t *namelength, size_t *name_pad)
+{
+ const void *h;
+ const unsigned char *header;
+
+ a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_LE;
+ a->archive.archive_format_name = "cpio (little-endian binary)";
+
+ /* Read fixed-size portion of header. */
+ h = __archive_read_ahead(a, bin_header_size, NULL);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+
+ /* Parse out binary fields. */
+ header = (const unsigned char *)h;
+
+ archive_entry_set_dev(entry, header[bin_dev_offset] + header[bin_dev_offset + 1] * 256);
+ archive_entry_set_ino(entry, header[bin_ino_offset] + header[bin_ino_offset + 1] * 256);
+ archive_entry_set_mode(entry, header[bin_mode_offset] + header[bin_mode_offset + 1] * 256);
+ archive_entry_set_uid(entry, header[bin_uid_offset] + header[bin_uid_offset + 1] * 256);
+ archive_entry_set_gid(entry, header[bin_gid_offset] + header[bin_gid_offset + 1] * 256);
+ archive_entry_set_nlink(entry, header[bin_nlink_offset] + header[bin_nlink_offset + 1] * 256);
+ archive_entry_set_rdev(entry, header[bin_rdev_offset] + header[bin_rdev_offset + 1] * 256);
+ archive_entry_set_mtime(entry, le4(header + bin_mtime_offset), 0);
+ *namelength = header[bin_namesize_offset] + header[bin_namesize_offset + 1] * 256;
+ *name_pad = *namelength & 1; /* Pad to even. */
+
+ cpio->entry_bytes_remaining = le4(header + bin_filesize_offset);
+ archive_entry_set_size(entry, cpio->entry_bytes_remaining);
+ cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */
+ __archive_read_consume(a, bin_header_size);
+ return (ARCHIVE_OK);
+}
+
+static int
+header_bin_be(struct archive_read *a, struct cpio *cpio,
+ struct archive_entry *entry, size_t *namelength, size_t *name_pad)
+{
+ const void *h;
+ const unsigned char *header;
+
+ a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_BE;
+ a->archive.archive_format_name = "cpio (big-endian binary)";
+
+ /* Read fixed-size portion of header. */
+ h = __archive_read_ahead(a, bin_header_size, NULL);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+
+ /* Parse out binary fields. */
+ header = (const unsigned char *)h;
+
+ archive_entry_set_dev(entry, header[bin_dev_offset] * 256 + header[bin_dev_offset + 1]);
+ archive_entry_set_ino(entry, header[bin_ino_offset] * 256 + header[bin_ino_offset + 1]);
+ archive_entry_set_mode(entry, header[bin_mode_offset] * 256 + header[bin_mode_offset + 1]);
+ archive_entry_set_uid(entry, header[bin_uid_offset] * 256 + header[bin_uid_offset + 1]);
+ archive_entry_set_gid(entry, header[bin_gid_offset] * 256 + header[bin_gid_offset + 1]);
+ archive_entry_set_nlink(entry, header[bin_nlink_offset] * 256 + header[bin_nlink_offset + 1]);
+ archive_entry_set_rdev(entry, header[bin_rdev_offset] * 256 + header[bin_rdev_offset + 1]);
+ archive_entry_set_mtime(entry, be4(header + bin_mtime_offset), 0);
+ *namelength = header[bin_namesize_offset] * 256 + header[bin_namesize_offset + 1];
+ *name_pad = *namelength & 1; /* Pad to even. */
+
+ cpio->entry_bytes_remaining = be4(header + bin_filesize_offset);
+ archive_entry_set_size(entry, cpio->entry_bytes_remaining);
+ cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */
+ __archive_read_consume(a, bin_header_size);
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_cpio_cleanup(struct archive_read *a)
+{
+ struct cpio *cpio;
+
+ cpio = (struct cpio *)(a->format->data);
+ /* Free inode->name map */
+ while (cpio->links_head != NULL) {
+ struct links_entry *lp = cpio->links_head->next;
+
+ if (cpio->links_head->name)
+ free(cpio->links_head->name);
+ free(cpio->links_head);
+ cpio->links_head = lp;
+ }
+ free(cpio);
+ (a->format->data) = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+le4(const unsigned char *p)
+{
+ return ((p[0]<<16) + (p[1]<<24) + (p[2]<<0) + (p[3]<<8));
+}
+
+
+static int
+be4(const unsigned char *p)
+{
+ return ((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + (p[3]));
+}
+
+/*
+ * Note that this implementation does not (and should not!) obey
+ * locale settings; you cannot simply substitute strtol here, since
+ * it does obey locale.
+ */
+static int64_t
+atol8(const char *p, unsigned char_cnt)
+{
+ int64_t l;
+ int digit;
+
+ l = 0;
+ while (char_cnt-- > 0) {
+ if (*p >= '0' && *p <= '7')
+ digit = *p - '0';
+ else
+ return (l);
+ p++;
+ l <<= 3;
+ l |= digit;
+ }
+ return (l);
+}
+
+static int64_t
+atol16(const char *p, unsigned char_cnt)
+{
+ int64_t l;
+ int digit;
+
+ l = 0;
+ while (char_cnt-- > 0) {
+ if (*p >= 'a' && *p <= 'f')
+ digit = *p - 'a' + 10;
+ else if (*p >= 'A' && *p <= 'F')
+ digit = *p - 'A' + 10;
+ else if (*p >= '0' && *p <= '9')
+ digit = *p - '0';
+ else
+ return (l);
+ p++;
+ l <<= 4;
+ l |= digit;
+ }
+ return (l);
+}
+
+static int
+record_hardlink(struct archive_read *a,
+ struct cpio *cpio, struct archive_entry *entry)
+{
+ struct links_entry *le;
+ dev_t dev;
+ int64_t ino;
+
+ if (archive_entry_nlink(entry) <= 1)
+ return (ARCHIVE_OK);
+
+ dev = archive_entry_dev(entry);
+ ino = archive_entry_ino64(entry);
+
+ /*
+ * First look in the list of multiply-linked files. If we've
+ * already dumped it, convert this entry to a hard link entry.
+ */
+ for (le = cpio->links_head; le; le = le->next) {
+ if (le->dev == dev && le->ino == ino) {
+ archive_entry_copy_hardlink(entry, le->name);
+
+ if (--le->links <= 0) {
+ if (le->previous != NULL)
+ le->previous->next = le->next;
+ if (le->next != NULL)
+ le->next->previous = le->previous;
+ if (cpio->links_head == le)
+ cpio->links_head = le->next;
+ free(le->name);
+ free(le);
+ }
+
+ return (ARCHIVE_OK);
+ }
+ }
+
+ le = (struct links_entry *)malloc(sizeof(struct links_entry));
+ if (le == NULL) {
+ archive_set_error(&a->archive,
+ ENOMEM, "Out of memory adding file to list");
+ return (ARCHIVE_FATAL);
+ }
+ if (cpio->links_head != NULL)
+ cpio->links_head->previous = le;
+ le->next = cpio->links_head;
+ le->previous = NULL;
+ cpio->links_head = le;
+ le->dev = dev;
+ le->ino = ino;
+ le->links = archive_entry_nlink(entry) - 1;
+ le->name = strdup(archive_entry_pathname(entry));
+ if (le->name == NULL) {
+ archive_set_error(&a->archive,
+ ENOMEM, "Out of memory adding file to list");
+ return (ARCHIVE_FATAL);
+ }
+
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c
new file mode 100644
index 0000000000..c641eb9b15
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c
@@ -0,0 +1,96 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_read_support_format_empty.c 191524 2009-04-26 18:24:14Z kientzle $");
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+static int archive_read_format_empty_bid(struct archive_read *, int);
+static int archive_read_format_empty_read_data(struct archive_read *,
+ const void **, size_t *, int64_t *);
+static int archive_read_format_empty_read_header(struct archive_read *,
+ struct archive_entry *);
+int
+archive_read_support_format_empty(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_empty");
+
+ r = __archive_read_register_format(a,
+ NULL,
+ NULL,
+ archive_read_format_empty_bid,
+ NULL,
+ archive_read_format_empty_read_header,
+ archive_read_format_empty_read_data,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+
+ return (r);
+}
+
+
+static int
+archive_read_format_empty_bid(struct archive_read *a, int best_bid)
+{
+ if (best_bid < 1 && __archive_read_ahead(a, 1, NULL) == NULL)
+ return (1);
+ return (-1);
+}
+
+static int
+archive_read_format_empty_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ (void)a; /* UNUSED */
+ (void)entry; /* UNUSED */
+
+ a->archive.archive_format = ARCHIVE_FORMAT_EMPTY;
+ a->archive.archive_format_name = "Empty file";
+
+ return (ARCHIVE_EOF);
+}
+
+static int
+archive_read_format_empty_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ (void)a; /* UNUSED */
+ (void)buff; /* UNUSED */
+ (void)size; /* UNUSED */
+ (void)offset; /* UNUSED */
+
+ return (ARCHIVE_EOF);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c
new file mode 100644
index 0000000000..2219e61708
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c
@@ -0,0 +1,3235 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2009 Andreas Henriksson <andreas@fatal.se>
+ * Copyright (c) 2009-2012 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: head/lib/libarchive/archive_read_support_format_iso9660.c 201246 2009-12-30 05:30:35Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+/* #include <stdint.h> */ /* See archive_platform.h */
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <time.h>
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_endian.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+#include "archive_string.h"
+
+/*
+ * An overview of ISO 9660 format:
+ *
+ * Each disk is laid out as follows:
+ * * 32k reserved for private use
+ * * Volume descriptor table. Each volume descriptor
+ * is 2k and specifies basic format information.
+ * The "Primary Volume Descriptor" (PVD) is defined by the
+ * standard and should always be present; other volume
+ * descriptors include various vendor-specific extensions.
+ * * Files and directories. Each file/dir is specified by
+ * an "extent" (starting sector and length in bytes).
+ * Dirs are just files with directory records packed one
+ * after another. The PVD contains a single dir entry
+ * specifying the location of the root directory. Everything
+ * else follows from there.
+ *
+ * This module works by first reading the volume descriptors, then
+ * building a list of directory entries, sorted by starting
+ * sector. At each step, I look for the earliest dir entry that
+ * hasn't yet been read, seek forward to that location and read
+ * that entry. If it's a dir, I slurp in the new dir entries and
+ * add them to the heap; if it's a regular file, I return the
+ * corresponding archive_entry and wait for the client to request
+ * the file body. This strategy allows us to read most compliant
+ * CDs with a single pass through the data, as required by libarchive.
+ */
+#define LOGICAL_BLOCK_SIZE 2048
+#define SYSTEM_AREA_BLOCK 16
+
+/* Structure of on-disk primary volume descriptor. */
+#define PVD_type_offset 0
+#define PVD_type_size 1
+#define PVD_id_offset (PVD_type_offset + PVD_type_size)
+#define PVD_id_size 5
+#define PVD_version_offset (PVD_id_offset + PVD_id_size)
+#define PVD_version_size 1
+#define PVD_reserved1_offset (PVD_version_offset + PVD_version_size)
+#define PVD_reserved1_size 1
+#define PVD_system_id_offset (PVD_reserved1_offset + PVD_reserved1_size)
+#define PVD_system_id_size 32
+#define PVD_volume_id_offset (PVD_system_id_offset + PVD_system_id_size)
+#define PVD_volume_id_size 32
+#define PVD_reserved2_offset (PVD_volume_id_offset + PVD_volume_id_size)
+#define PVD_reserved2_size 8
+#define PVD_volume_space_size_offset (PVD_reserved2_offset + PVD_reserved2_size)
+#define PVD_volume_space_size_size 8
+#define PVD_reserved3_offset (PVD_volume_space_size_offset + PVD_volume_space_size_size)
+#define PVD_reserved3_size 32
+#define PVD_volume_set_size_offset (PVD_reserved3_offset + PVD_reserved3_size)
+#define PVD_volume_set_size_size 4
+#define PVD_volume_sequence_number_offset (PVD_volume_set_size_offset + PVD_volume_set_size_size)
+#define PVD_volume_sequence_number_size 4
+#define PVD_logical_block_size_offset (PVD_volume_sequence_number_offset + PVD_volume_sequence_number_size)
+#define PVD_logical_block_size_size 4
+#define PVD_path_table_size_offset (PVD_logical_block_size_offset + PVD_logical_block_size_size)
+#define PVD_path_table_size_size 8
+#define PVD_type_1_path_table_offset (PVD_path_table_size_offset + PVD_path_table_size_size)
+#define PVD_type_1_path_table_size 4
+#define PVD_opt_type_1_path_table_offset (PVD_type_1_path_table_offset + PVD_type_1_path_table_size)
+#define PVD_opt_type_1_path_table_size 4
+#define PVD_type_m_path_table_offset (PVD_opt_type_1_path_table_offset + PVD_opt_type_1_path_table_size)
+#define PVD_type_m_path_table_size 4
+#define PVD_opt_type_m_path_table_offset (PVD_type_m_path_table_offset + PVD_type_m_path_table_size)
+#define PVD_opt_type_m_path_table_size 4
+#define PVD_root_directory_record_offset (PVD_opt_type_m_path_table_offset + PVD_opt_type_m_path_table_size)
+#define PVD_root_directory_record_size 34
+#define PVD_volume_set_id_offset (PVD_root_directory_record_offset + PVD_root_directory_record_size)
+#define PVD_volume_set_id_size 128
+#define PVD_publisher_id_offset (PVD_volume_set_id_offset + PVD_volume_set_id_size)
+#define PVD_publisher_id_size 128
+#define PVD_preparer_id_offset (PVD_publisher_id_offset + PVD_publisher_id_size)
+#define PVD_preparer_id_size 128
+#define PVD_application_id_offset (PVD_preparer_id_offset + PVD_preparer_id_size)
+#define PVD_application_id_size 128
+#define PVD_copyright_file_id_offset (PVD_application_id_offset + PVD_application_id_size)
+#define PVD_copyright_file_id_size 37
+#define PVD_abstract_file_id_offset (PVD_copyright_file_id_offset + PVD_copyright_file_id_size)
+#define PVD_abstract_file_id_size 37
+#define PVD_bibliographic_file_id_offset (PVD_abstract_file_id_offset + PVD_abstract_file_id_size)
+#define PVD_bibliographic_file_id_size 37
+#define PVD_creation_date_offset (PVD_bibliographic_file_id_offset + PVD_bibliographic_file_id_size)
+#define PVD_creation_date_size 17
+#define PVD_modification_date_offset (PVD_creation_date_offset + PVD_creation_date_size)
+#define PVD_modification_date_size 17
+#define PVD_expiration_date_offset (PVD_modification_date_offset + PVD_modification_date_size)
+#define PVD_expiration_date_size 17
+#define PVD_effective_date_offset (PVD_expiration_date_offset + PVD_expiration_date_size)
+#define PVD_effective_date_size 17
+#define PVD_file_structure_version_offset (PVD_effective_date_offset + PVD_effective_date_size)
+#define PVD_file_structure_version_size 1
+#define PVD_reserved4_offset (PVD_file_structure_version_offset + PVD_file_structure_version_size)
+#define PVD_reserved4_size 1
+#define PVD_application_data_offset (PVD_reserved4_offset + PVD_reserved4_size)
+#define PVD_application_data_size 512
+#define PVD_reserved5_offset (PVD_application_data_offset + PVD_application_data_size)
+#define PVD_reserved5_size (2048 - PVD_reserved5_offset)
+
+/* TODO: It would make future maintenance easier to just hardcode the
+ * above values. In particular, ECMA119 states the offsets as part of
+ * the standard. That would eliminate the need for the following check.*/
+#if PVD_reserved5_offset != 1395
+#error PVD offset and size definitions are wrong.
+#endif
+
+
+/* Structure of optional on-disk supplementary volume descriptor. */
+#define SVD_type_offset 0
+#define SVD_type_size 1
+#define SVD_id_offset (SVD_type_offset + SVD_type_size)
+#define SVD_id_size 5
+#define SVD_version_offset (SVD_id_offset + SVD_id_size)
+#define SVD_version_size 1
+/* ... */
+#define SVD_reserved1_offset 72
+#define SVD_reserved1_size 8
+#define SVD_volume_space_size_offset 80
+#define SVD_volume_space_size_size 8
+#define SVD_escape_sequences_offset (SVD_volume_space_size_offset + SVD_volume_space_size_size)
+#define SVD_escape_sequences_size 32
+/* ... */
+#define SVD_logical_block_size_offset 128
+#define SVD_logical_block_size_size 4
+#define SVD_type_L_path_table_offset 140
+#define SVD_type_M_path_table_offset 148
+/* ... */
+#define SVD_root_directory_record_offset 156
+#define SVD_root_directory_record_size 34
+#define SVD_file_structure_version_offset 881
+#define SVD_reserved2_offset 882
+#define SVD_reserved2_size 1
+#define SVD_reserved3_offset 1395
+#define SVD_reserved3_size 653
+/* ... */
+/* FIXME: validate correctness of last SVD entry offset. */
+
+/* Structure of an on-disk directory record. */
+/* Note: ISO9660 stores each multi-byte integer twice, once in
+ * each byte order. The sizes here are the size of just one
+ * of the two integers. (This is why the offset of a field isn't
+ * the same as the offset+size of the previous field.) */
+#define DR_length_offset 0
+#define DR_length_size 1
+#define DR_ext_attr_length_offset 1
+#define DR_ext_attr_length_size 1
+#define DR_extent_offset 2
+#define DR_extent_size 4
+#define DR_size_offset 10
+#define DR_size_size 4
+#define DR_date_offset 18
+#define DR_date_size 7
+#define DR_flags_offset 25
+#define DR_flags_size 1
+#define DR_file_unit_size_offset 26
+#define DR_file_unit_size_size 1
+#define DR_interleave_offset 27
+#define DR_interleave_size 1
+#define DR_volume_sequence_number_offset 28
+#define DR_volume_sequence_number_size 2
+#define DR_name_len_offset 32
+#define DR_name_len_size 1
+#define DR_name_offset 33
+
+#ifdef HAVE_ZLIB_H
+static const unsigned char zisofs_magic[8] = {
+ 0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07
+};
+
+struct zisofs {
+ /* Set 1 if this file compressed by paged zlib */
+ int pz;
+ int pz_log2_bs; /* Log2 of block size */
+ uint64_t pz_uncompressed_size;
+
+ int initialized;
+ unsigned char *uncompressed_buffer;
+ size_t uncompressed_buffer_size;
+
+ uint32_t pz_offset;
+ unsigned char header[16];
+ size_t header_avail;
+ int header_passed;
+ unsigned char *block_pointers;
+ size_t block_pointers_alloc;
+ size_t block_pointers_size;
+ size_t block_pointers_avail;
+ size_t block_off;
+ uint32_t block_avail;
+
+ z_stream stream;
+ int stream_valid;
+};
+#else
+struct zisofs {
+ /* Set 1 if this file compressed by paged zlib */
+ int pz;
+};
+#endif
+
+struct content {
+ uint64_t offset;/* Offset on disk. */
+ uint64_t size; /* File size in bytes. */
+ struct content *next;
+};
+
+/* In-memory storage for a directory record. */
+struct file_info {
+ struct file_info *use_next;
+ struct file_info *parent;
+ struct file_info *next;
+ struct file_info *re_next;
+ int subdirs;
+ uint64_t key; /* Heap Key. */
+ uint64_t offset; /* Offset on disk. */
+ uint64_t size; /* File size in bytes. */
+ uint32_t ce_offset; /* Offset of CE. */
+ uint32_t ce_size; /* Size of CE. */
+ char rr_moved; /* Flag to rr_moved. */
+ char rr_moved_has_re_only;
+ char re; /* Having RRIP "RE" extension. */
+ char re_descendant;
+ uint64_t cl_offset; /* Having RRIP "CL" extension. */
+ int birthtime_is_set;
+ time_t birthtime; /* File created time. */
+ time_t mtime; /* File last modified time. */
+ time_t atime; /* File last accessed time. */
+ time_t ctime; /* File attribute change time. */
+ uint64_t rdev; /* Device number. */
+ mode_t mode;
+ uid_t uid;
+ gid_t gid;
+ int64_t number;
+ int nlinks;
+ struct archive_string name; /* Pathname */
+ unsigned char *utf16be_name;
+ size_t utf16be_bytes;
+ char name_continues; /* Non-zero if name continues */
+ struct archive_string symlink;
+ char symlink_continues; /* Non-zero if link continues */
+ /* Set 1 if this file compressed by paged zlib(zisofs) */
+ int pz;
+ int pz_log2_bs; /* Log2 of block size */
+ uint64_t pz_uncompressed_size;
+ /* Set 1 if this file is multi extent. */
+ int multi_extent;
+ struct {
+ struct content *first;
+ struct content **last;
+ } contents;
+ struct {
+ struct file_info *first;
+ struct file_info **last;
+ } rede_files;
+};
+
+struct heap_queue {
+ struct file_info **files;
+ int allocated;
+ int used;
+};
+
+struct iso9660 {
+ int magic;
+#define ISO9660_MAGIC 0x96609660
+
+ int opt_support_joliet;
+ int opt_support_rockridge;
+
+ struct archive_string pathname;
+ char seenRockridge; /* Set true if RR extensions are used. */
+ char seenSUSP; /* Set true if SUSP is beging used. */
+ char seenJoliet;
+
+ unsigned char suspOffset;
+ struct file_info *rr_moved;
+ struct read_ce_queue {
+ struct read_ce_req {
+ uint64_t offset;/* Offset of CE on disk. */
+ struct file_info *file;
+ } *reqs;
+ int cnt;
+ int allocated;
+ } read_ce_req;
+
+ int64_t previous_number;
+ struct archive_string previous_pathname;
+
+ struct file_info *use_files;
+ struct heap_queue pending_files;
+ struct {
+ struct file_info *first;
+ struct file_info **last;
+ } cache_files;
+ struct {
+ struct file_info *first;
+ struct file_info **last;
+ } re_files;
+
+ uint64_t current_position;
+ ssize_t logical_block_size;
+ uint64_t volume_size; /* Total size of volume in bytes. */
+ int32_t volume_block;/* Total size of volume in logical blocks. */
+
+ struct vd {
+ int location; /* Location of Extent. */
+ uint32_t size;
+ } primary, joliet;
+
+ int64_t entry_sparse_offset;
+ int64_t entry_bytes_remaining;
+ size_t entry_bytes_unconsumed;
+ struct zisofs entry_zisofs;
+ struct content *entry_content;
+ struct archive_string_conv *sconv_utf16be;
+ /*
+ * Buffers for a full pathname in UTF-16BE in Joliet extensions.
+ */
+#define UTF16_NAME_MAX 1024
+ unsigned char *utf16be_path;
+ size_t utf16be_path_len;
+ unsigned char *utf16be_previous_path;
+ size_t utf16be_previous_path_len;
+ /* Null buufer used in bidder to improve its performance. */
+ unsigned char null[2048];
+};
+
+static int archive_read_format_iso9660_bid(struct archive_read *, int);
+static int archive_read_format_iso9660_options(struct archive_read *,
+ const char *, const char *);
+static int archive_read_format_iso9660_cleanup(struct archive_read *);
+static int archive_read_format_iso9660_read_data(struct archive_read *,
+ const void **, size_t *, int64_t *);
+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 int build_pathname_utf16be(unsigned char *, size_t, size_t *,
+ struct file_info *);
+#if DEBUG
+static void dump_isodirrec(FILE *, const unsigned char *isodirrec);
+#endif
+static time_t time_from_tm(struct tm *);
+static time_t isodate17(const unsigned char *);
+static time_t isodate7(const unsigned char *);
+static int isBootRecord(struct iso9660 *, const unsigned char *);
+static int isVolumePartition(struct iso9660 *, const unsigned char *);
+static int isVDSetTerminator(struct iso9660 *, const unsigned char *);
+static int isJolietSVD(struct iso9660 *, const unsigned char *);
+static int isSVD(struct iso9660 *, const unsigned char *);
+static int isEVD(struct iso9660 *, const unsigned char *);
+static int isPVD(struct iso9660 *, const unsigned char *);
+static int next_cache_entry(struct archive_read *, struct iso9660 *,
+ struct file_info **);
+static int next_entry_seek(struct archive_read *, struct iso9660 *,
+ struct file_info **);
+static struct file_info *
+ parse_file_info(struct archive_read *a,
+ struct file_info *parent, const unsigned char *isodirrec);
+static int parse_rockridge(struct archive_read *a,
+ struct file_info *file, const unsigned char *start,
+ const unsigned char *end);
+static int register_CE(struct archive_read *a, int32_t location,
+ struct file_info *file);
+static int read_CE(struct archive_read *a, struct iso9660 *iso9660);
+static void parse_rockridge_NM1(struct file_info *,
+ const unsigned char *, int);
+static void parse_rockridge_SL1(struct file_info *,
+ const unsigned char *, int);
+static void parse_rockridge_TF1(struct file_info *,
+ const unsigned char *, int);
+static void parse_rockridge_ZF1(struct file_info *,
+ const unsigned char *, int);
+static void register_file(struct iso9660 *, struct file_info *);
+static void release_files(struct iso9660 *);
+static unsigned toi(const void *p, int n);
+static inline void re_add_entry(struct iso9660 *, struct file_info *);
+static inline struct file_info * re_get_entry(struct iso9660 *);
+static inline int rede_add_entry(struct file_info *);
+static inline struct file_info * rede_get_entry(struct file_info *);
+static inline void cache_add_entry(struct iso9660 *iso9660,
+ struct file_info *file);
+static inline struct file_info *cache_get_entry(struct iso9660 *iso9660);
+static int heap_add_entry(struct archive_read *a, struct heap_queue *heap,
+ struct file_info *file, uint64_t key);
+static struct file_info *heap_get_entry(struct heap_queue *heap);
+
+#define add_entry(arch, iso9660, file) \
+ heap_add_entry(arch, &((iso9660)->pending_files), file, file->offset)
+#define next_entry(iso9660) \
+ heap_get_entry(&((iso9660)->pending_files))
+
+int
+archive_read_support_format_iso9660(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct iso9660 *iso9660;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_iso9660");
+
+ iso9660 = (struct iso9660 *)calloc(1, sizeof(*iso9660));
+ if (iso9660 == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate iso9660 data");
+ return (ARCHIVE_FATAL);
+ }
+ iso9660->magic = ISO9660_MAGIC;
+ iso9660->cache_files.first = NULL;
+ iso9660->cache_files.last = &(iso9660->cache_files.first);
+ iso9660->re_files.first = NULL;
+ iso9660->re_files.last = &(iso9660->re_files.first);
+ /* Enable to support Joliet extensions by default. */
+ iso9660->opt_support_joliet = 1;
+ /* Enable to support Rock Ridge extensions by default. */
+ iso9660->opt_support_rockridge = 1;
+
+ r = __archive_read_register_format(a,
+ iso9660,
+ "iso9660",
+ archive_read_format_iso9660_bid,
+ archive_read_format_iso9660_options,
+ archive_read_format_iso9660_read_header,
+ archive_read_format_iso9660_read_data,
+ archive_read_format_iso9660_read_data_skip,
+ NULL,
+ archive_read_format_iso9660_cleanup,
+ NULL,
+ NULL);
+
+ if (r != ARCHIVE_OK) {
+ free(iso9660);
+ return (r);
+ }
+ return (ARCHIVE_OK);
+}
+
+
+static int
+archive_read_format_iso9660_bid(struct archive_read *a, int best_bid)
+{
+ struct iso9660 *iso9660;
+ ssize_t bytes_read;
+ const unsigned char *p;
+ int seenTerminator;
+
+ /* If there's already a better bid than we can ever
+ make, don't bother testing. */
+ if (best_bid > 48)
+ return (-1);
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+
+ /*
+ * Skip the first 32k (reserved area) and get the first
+ * 8 sectors of the volume descriptor table. Of course,
+ * if the I/O layer gives us more, we'll take it.
+ */
+#define RESERVED_AREA (SYSTEM_AREA_BLOCK * LOGICAL_BLOCK_SIZE)
+ p = __archive_read_ahead(a,
+ RESERVED_AREA + 8 * LOGICAL_BLOCK_SIZE,
+ &bytes_read);
+ if (p == NULL)
+ return (-1);
+
+ /* Skip the reserved area. */
+ bytes_read -= RESERVED_AREA;
+ p += RESERVED_AREA;
+
+ /* Check each volume descriptor. */
+ seenTerminator = 0;
+ for (; bytes_read > LOGICAL_BLOCK_SIZE;
+ bytes_read -= LOGICAL_BLOCK_SIZE, p += LOGICAL_BLOCK_SIZE) {
+ /* Do not handle undefined Volume Descriptor Type. */
+ if (p[0] >= 4 && p[0] <= 254)
+ return (0);
+ /* Standard Identifier must be "CD001" */
+ if (memcmp(p + 1, "CD001", 5) != 0)
+ return (0);
+ if (isPVD(iso9660, p))
+ continue;
+ if (!iso9660->joliet.location) {
+ if (isJolietSVD(iso9660, p))
+ continue;
+ }
+ if (isBootRecord(iso9660, p))
+ continue;
+ if (isEVD(iso9660, p))
+ continue;
+ if (isSVD(iso9660, p))
+ continue;
+ if (isVolumePartition(iso9660, p))
+ continue;
+ if (isVDSetTerminator(iso9660, p)) {
+ seenTerminator = 1;
+ break;
+ }
+ return (0);
+ }
+ /*
+ * ISO 9660 format must have Primary Volume Descriptor and
+ * Volume Descriptor Set Terminator.
+ */
+ if (seenTerminator && iso9660->primary.location > 16)
+ return (48);
+
+ /* We didn't find a valid PVD; return a bid of zero. */
+ return (0);
+}
+
+static int
+archive_read_format_iso9660_options(struct archive_read *a,
+ const char *key, const char *val)
+{
+ struct iso9660 *iso9660;
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+
+ if (strcmp(key, "joliet") == 0) {
+ if (val == NULL || strcmp(val, "off") == 0 ||
+ strcmp(val, "ignore") == 0 ||
+ strcmp(val, "disable") == 0 ||
+ strcmp(val, "0") == 0)
+ iso9660->opt_support_joliet = 0;
+ else
+ iso9660->opt_support_joliet = 1;
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "rockridge") == 0 ||
+ strcmp(key, "Rockridge") == 0) {
+ iso9660->opt_support_rockridge = val != 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);
+}
+
+static int
+isNull(struct iso9660 *iso9660, const unsigned char *h, unsigned offset,
+unsigned bytes)
+{
+
+ while (bytes >= sizeof(iso9660->null)) {
+ if (!memcmp(iso9660->null, h + offset, sizeof(iso9660->null)))
+ return (0);
+ offset += sizeof(iso9660->null);
+ bytes -= sizeof(iso9660->null);
+ }
+ if (bytes)
+ return memcmp(iso9660->null, h + offset, bytes) == 0;
+ else
+ return (1);
+}
+
+static int
+isBootRecord(struct iso9660 *iso9660, const unsigned char *h)
+{
+ (void)iso9660; /* UNUSED */
+
+ /* Type of the Volume Descriptor Boot Record must be 0. */
+ if (h[0] != 0)
+ return (0);
+
+ /* Volume Descriptor Version must be 1. */
+ if (h[6] != 1)
+ return (0);
+
+ return (1);
+}
+
+static int
+isVolumePartition(struct iso9660 *iso9660, const unsigned char *h)
+{
+ int32_t location;
+
+ /* Type of the Volume Partition Descriptor must be 3. */
+ if (h[0] != 3)
+ return (0);
+
+ /* Volume Descriptor Version must be 1. */
+ if (h[6] != 1)
+ return (0);
+ /* Unused Field */
+ if (h[7] != 0)
+ return (0);
+
+ location = archive_le32dec(h + 72);
+ if (location <= SYSTEM_AREA_BLOCK ||
+ location >= iso9660->volume_block)
+ return (0);
+ if ((uint32_t)location != archive_be32dec(h + 76))
+ return (0);
+
+ return (1);
+}
+
+static int
+isVDSetTerminator(struct iso9660 *iso9660, const unsigned char *h)
+{
+ (void)iso9660; /* UNUSED */
+
+ /* Type of the Volume Descriptor Set Terminator must be 255. */
+ if (h[0] != 255)
+ return (0);
+
+ /* Volume Descriptor Version must be 1. */
+ if (h[6] != 1)
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (!isNull(iso9660, h, 7, 2048-7))
+ return (0);
+
+ return (1);
+}
+
+static int
+isJolietSVD(struct iso9660 *iso9660, const unsigned char *h)
+{
+ const unsigned char *p;
+ ssize_t logical_block_size;
+ int32_t volume_block;
+
+ /* Check if current sector is a kind of Supplementary Volume
+ * Descriptor. */
+ if (!isSVD(iso9660, h))
+ return (0);
+
+ /* FIXME: do more validations according to joliet spec. */
+
+ /* check if this SVD contains joliet extension! */
+ p = h + SVD_escape_sequences_offset;
+ /* N.B. Joliet spec says p[1] == '\\', but.... */
+ if (p[0] == '%' && p[1] == '/') {
+ int level = 0;
+
+ if (p[2] == '@')
+ level = 1;
+ else if (p[2] == 'C')
+ level = 2;
+ else if (p[2] == 'E')
+ level = 3;
+ else /* not joliet */
+ return (0);
+
+ iso9660->seenJoliet = level;
+
+ } else /* not joliet */
+ return (0);
+
+ logical_block_size =
+ archive_le16dec(h + SVD_logical_block_size_offset);
+ volume_block = archive_le32dec(h + SVD_volume_space_size_offset);
+
+ iso9660->logical_block_size = logical_block_size;
+ iso9660->volume_block = volume_block;
+ iso9660->volume_size = logical_block_size * (uint64_t)volume_block;
+ /* Read Root Directory Record in Volume Descriptor. */
+ p = h + SVD_root_directory_record_offset;
+ iso9660->joliet.location = archive_le32dec(p + DR_extent_offset);
+ iso9660->joliet.size = archive_le32dec(p + DR_size_offset);
+
+ return (48);
+}
+
+static int
+isSVD(struct iso9660 *iso9660, const unsigned char *h)
+{
+ const unsigned char *p;
+ ssize_t logical_block_size;
+ int32_t volume_block;
+ int32_t location;
+
+ (void)iso9660; /* UNUSED */
+
+ /* Type 2 means it's a SVD. */
+ if (h[SVD_type_offset] != 2)
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (!isNull(iso9660, h, SVD_reserved1_offset, SVD_reserved1_size))
+ return (0);
+ if (!isNull(iso9660, h, SVD_reserved2_offset, SVD_reserved2_size))
+ return (0);
+ if (!isNull(iso9660, h, SVD_reserved3_offset, SVD_reserved3_size))
+ return (0);
+
+ /* File structure version must be 1 for ISO9660/ECMA119. */
+ if (h[SVD_file_structure_version_offset] != 1)
+ return (0);
+
+ logical_block_size =
+ archive_le16dec(h + SVD_logical_block_size_offset);
+ if (logical_block_size <= 0)
+ return (0);
+
+ volume_block = archive_le32dec(h + SVD_volume_space_size_offset);
+ if (volume_block <= SYSTEM_AREA_BLOCK+4)
+ return (0);
+
+ /* Location of Occurrence of Type L Path Table must be
+ * available location,
+ * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+ location = archive_le32dec(h+SVD_type_L_path_table_offset);
+ if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block)
+ return (0);
+
+ /* The Type M Path Table must be at a valid location (WinISO
+ * and probably other programs omit this, so we allow zero)
+ *
+ * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+ location = archive_be32dec(h+SVD_type_M_path_table_offset);
+ if ((location > 0 && location < SYSTEM_AREA_BLOCK+2)
+ || location >= volume_block)
+ return (0);
+
+ /* Read Root Directory Record in Volume Descriptor. */
+ p = h + SVD_root_directory_record_offset;
+ if (p[DR_length_offset] != 34)
+ return (0);
+
+ return (48);
+}
+
+static int
+isEVD(struct iso9660 *iso9660, const unsigned char *h)
+{
+ const unsigned char *p;
+ ssize_t logical_block_size;
+ int32_t volume_block;
+ int32_t location;
+
+ (void)iso9660; /* UNUSED */
+
+ /* Type of the Enhanced Volume Descriptor must be 2. */
+ if (h[PVD_type_offset] != 2)
+ return (0);
+
+ /* EVD version must be 2. */
+ if (h[PVD_version_offset] != 2)
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (h[PVD_reserved1_offset] != 0)
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (!isNull(iso9660, h, PVD_reserved2_offset, PVD_reserved2_size))
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (!isNull(iso9660, h, PVD_reserved3_offset, PVD_reserved3_size))
+ return (0);
+
+ /* Logical block size must be > 0. */
+ /* I've looked at Ecma 119 and can't find any stronger
+ * restriction on this field. */
+ logical_block_size =
+ archive_le16dec(h + PVD_logical_block_size_offset);
+ if (logical_block_size <= 0)
+ return (0);
+
+ volume_block =
+ archive_le32dec(h + PVD_volume_space_size_offset);
+ if (volume_block <= SYSTEM_AREA_BLOCK+4)
+ return (0);
+
+ /* File structure version must be 2 for ISO9660:1999. */
+ if (h[PVD_file_structure_version_offset] != 2)
+ return (0);
+
+ /* Location of Occurrence of Type L Path Table must be
+ * available location,
+ * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+ location = archive_le32dec(h+PVD_type_1_path_table_offset);
+ if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block)
+ return (0);
+
+ /* Location of Occurrence of Type M Path Table must be
+ * available location,
+ * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+ location = archive_be32dec(h+PVD_type_m_path_table_offset);
+ if ((location > 0 && location < SYSTEM_AREA_BLOCK+2)
+ || location >= volume_block)
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (!isNull(iso9660, h, PVD_reserved4_offset, PVD_reserved4_size))
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (!isNull(iso9660, h, PVD_reserved5_offset, PVD_reserved5_size))
+ return (0);
+
+ /* Read Root Directory Record in Volume Descriptor. */
+ p = h + PVD_root_directory_record_offset;
+ if (p[DR_length_offset] != 34)
+ return (0);
+
+ return (48);
+}
+
+static int
+isPVD(struct iso9660 *iso9660, const unsigned char *h)
+{
+ const unsigned char *p;
+ ssize_t logical_block_size;
+ int32_t volume_block;
+ int32_t location;
+ int i;
+
+ /* Type of the Primary Volume Descriptor must be 1. */
+ if (h[PVD_type_offset] != 1)
+ return (0);
+
+ /* PVD version must be 1. */
+ if (h[PVD_version_offset] != 1)
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (h[PVD_reserved1_offset] != 0)
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (!isNull(iso9660, h, PVD_reserved2_offset, PVD_reserved2_size))
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (!isNull(iso9660, h, PVD_reserved3_offset, PVD_reserved3_size))
+ return (0);
+
+ /* Logical block size must be > 0. */
+ /* I've looked at Ecma 119 and can't find any stronger
+ * restriction on this field. */
+ logical_block_size =
+ archive_le16dec(h + PVD_logical_block_size_offset);
+ if (logical_block_size <= 0)
+ return (0);
+
+ volume_block = archive_le32dec(h + PVD_volume_space_size_offset);
+ if (volume_block <= SYSTEM_AREA_BLOCK+4)
+ return (0);
+
+ /* File structure version must be 1 for ISO9660/ECMA119. */
+ if (h[PVD_file_structure_version_offset] != 1)
+ return (0);
+
+ /* Location of Occurrence of Type L Path Table must be
+ * available location,
+ * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+ location = archive_le32dec(h+PVD_type_1_path_table_offset);
+ if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block)
+ return (0);
+
+ /* The Type M Path Table must also be at a valid location
+ * (although ECMA 119 requires a Type M Path Table, WinISO and
+ * probably other programs omit it, so we permit a zero here)
+ *
+ * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+ location = archive_be32dec(h+PVD_type_m_path_table_offset);
+ if ((location > 0 && location < SYSTEM_AREA_BLOCK+2)
+ || location >= volume_block)
+ return (0);
+
+ /* Reserved field must be 0. */
+ /* But accept NetBSD/FreeBSD "makefs" images with 0x20 here. */
+ for (i = 0; i < PVD_reserved4_size; ++i)
+ if (h[PVD_reserved4_offset + i] != 0
+ && h[PVD_reserved4_offset + i] != 0x20)
+ return (0);
+
+ /* Reserved field must be 0. */
+ if (!isNull(iso9660, h, PVD_reserved5_offset, PVD_reserved5_size))
+ return (0);
+
+ /* XXX TODO: Check other values for sanity; reject more
+ * malformed PVDs. XXX */
+
+ /* Read Root Directory Record in Volume Descriptor. */
+ p = h + PVD_root_directory_record_offset;
+ if (p[DR_length_offset] != 34)
+ return (0);
+
+ if (!iso9660->primary.location) {
+ iso9660->logical_block_size = logical_block_size;
+ iso9660->volume_block = volume_block;
+ iso9660->volume_size =
+ logical_block_size * (uint64_t)volume_block;
+ iso9660->primary.location =
+ archive_le32dec(p + DR_extent_offset);
+ iso9660->primary.size = archive_le32dec(p + DR_size_offset);
+ }
+
+ return (48);
+}
+
+static int
+read_children(struct archive_read *a, struct file_info *parent)
+{
+ struct iso9660 *iso9660;
+ const unsigned char *b, *p;
+ struct file_info *multi;
+ size_t step, skip_size;
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+ /* flush any remaining bytes from the last round to ensure
+ * we're positioned */
+ if (iso9660->entry_bytes_unconsumed) {
+ __archive_read_consume(a, iso9660->entry_bytes_unconsumed);
+ iso9660->entry_bytes_unconsumed = 0;
+ }
+ if (iso9660->current_position > parent->offset) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Ignoring out-of-order directory (%s) %jd > %jd",
+ parent->name.s,
+ (intmax_t)iso9660->current_position,
+ (intmax_t)parent->offset);
+ return (ARCHIVE_WARN);
+ }
+ if (parent->offset + parent->size > iso9660->volume_size) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Directory is beyond end-of-media: %s",
+ parent->name.s);
+ return (ARCHIVE_WARN);
+ }
+ if (iso9660->current_position < parent->offset) {
+ int64_t skipsize;
+
+ skipsize = parent->offset - iso9660->current_position;
+ skipsize = __archive_read_consume(a, skipsize);
+ if (skipsize < 0)
+ return ((int)skipsize);
+ iso9660->current_position = parent->offset;
+ }
+
+ step = (size_t)(((parent->size + iso9660->logical_block_size -1) /
+ iso9660->logical_block_size) * iso9660->logical_block_size);
+ b = __archive_read_ahead(a, step, NULL);
+ if (b == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to read full block when scanning "
+ "ISO9660 directory list");
+ return (ARCHIVE_FATAL);
+ }
+ iso9660->current_position += step;
+ multi = NULL;
+ skip_size = step;
+ while (step) {
+ p = b;
+ b += iso9660->logical_block_size;
+ step -= iso9660->logical_block_size;
+ for (; *p != 0 && p < b && p + *p <= b; p += *p) {
+ struct file_info *child;
+
+ /* N.B.: these special directory identifiers
+ * are 8 bit "values" even on a
+ * Joliet CD with UCS-2 (16bit) encoding.
+ */
+
+ /* Skip '.' entry. */
+ if (*(p + DR_name_len_offset) == 1
+ && *(p + DR_name_offset) == '\0')
+ continue;
+ /* Skip '..' entry. */
+ if (*(p + DR_name_len_offset) == 1
+ && *(p + DR_name_offset) == '\001')
+ continue;
+ child = parse_file_info(a, parent, p);
+ if (child == NULL) {
+ __archive_read_consume(a, skip_size);
+ return (ARCHIVE_FATAL);
+ }
+ if (child->cl_offset == 0 &&
+ (child->multi_extent || multi != NULL)) {
+ struct content *con;
+
+ if (multi == NULL) {
+ multi = child;
+ multi->contents.first = NULL;
+ multi->contents.last =
+ &(multi->contents.first);
+ }
+ con = malloc(sizeof(struct content));
+ if (con == NULL) {
+ archive_set_error(
+ &a->archive, ENOMEM,
+ "No memory for multi extent");
+ __archive_read_consume(a, skip_size);
+ return (ARCHIVE_FATAL);
+ }
+ con->offset = child->offset;
+ con->size = child->size;
+ con->next = NULL;
+ *multi->contents.last = con;
+ multi->contents.last = &(con->next);
+ if (multi == child) {
+ if (add_entry(a, iso9660, child)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } else {
+ multi->size += child->size;
+ if (!child->multi_extent)
+ multi = NULL;
+ }
+ } else
+ if (add_entry(a, iso9660, child) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ __archive_read_consume(a, skip_size);
+
+ /* Read data which recorded by RRIP "CE" extension. */
+ if (read_CE(a, iso9660) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+choose_volume(struct archive_read *a, struct iso9660 *iso9660)
+{
+ struct file_info *file;
+ int64_t skipsize;
+ struct vd *vd;
+ const void *block;
+ char seenJoliet;
+
+ vd = &(iso9660->primary);
+ if (!iso9660->opt_support_joliet)
+ iso9660->seenJoliet = 0;
+ if (iso9660->seenJoliet &&
+ vd->location > iso9660->joliet.location)
+ /* This condition is unlikely; by way of caution. */
+ vd = &(iso9660->joliet);
+
+ skipsize = LOGICAL_BLOCK_SIZE * vd->location;
+ skipsize = __archive_read_consume(a, skipsize);
+ if (skipsize < 0)
+ return ((int)skipsize);
+ iso9660->current_position = skipsize;
+
+ block = __archive_read_ahead(a, vd->size, NULL);
+ if (block == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to read full block when scanning "
+ "ISO9660 directory list");
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * While reading Root Directory, flag seenJoliet must be zero to
+ * avoid converting special name 0x00(Current Directory) and
+ * next byte to UCS2.
+ */
+ seenJoliet = iso9660->seenJoliet;/* Save flag. */
+ iso9660->seenJoliet = 0;
+ file = parse_file_info(a, NULL, block);
+ if (file == NULL)
+ return (ARCHIVE_FATAL);
+ iso9660->seenJoliet = seenJoliet;
+
+ /*
+ * If the iso image has both RockRidge and Joliet, we preferentially
+ * use RockRidge Extensions rather than Joliet ones.
+ */
+ if (vd == &(iso9660->primary) && iso9660->seenRockridge
+ && iso9660->seenJoliet)
+ iso9660->seenJoliet = 0;
+
+ if (vd == &(iso9660->primary) && !iso9660->seenRockridge
+ && iso9660->seenJoliet) {
+ /* Switch reading data from primary to joliet. */
+ vd = &(iso9660->joliet);
+ skipsize = LOGICAL_BLOCK_SIZE * vd->location;
+ skipsize -= iso9660->current_position;
+ skipsize = __archive_read_consume(a, skipsize);
+ if (skipsize < 0)
+ return ((int)skipsize);
+ iso9660->current_position += skipsize;
+
+ block = __archive_read_ahead(a, vd->size, NULL);
+ if (block == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to read full block when scanning "
+ "ISO9660 directory list");
+ return (ARCHIVE_FATAL);
+ }
+ iso9660->seenJoliet = 0;
+ file = parse_file_info(a, NULL, block);
+ if (file == NULL)
+ return (ARCHIVE_FATAL);
+ iso9660->seenJoliet = seenJoliet;
+ }
+
+ /* Store the root directory in the pending list. */
+ if (add_entry(a, iso9660, file) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ if (iso9660->seenRockridge) {
+ a->archive.archive_format = ARCHIVE_FORMAT_ISO9660_ROCKRIDGE;
+ a->archive.archive_format_name =
+ "ISO9660 with Rockridge extensions";
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_iso9660_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ struct iso9660 *iso9660;
+ struct file_info *file;
+ int r, rd_r = ARCHIVE_OK;
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+
+ if (!a->archive.archive_format) {
+ a->archive.archive_format = ARCHIVE_FORMAT_ISO9660;
+ a->archive.archive_format_name = "ISO9660";
+ }
+
+ if (iso9660->current_position == 0) {
+ r = choose_volume(a, iso9660);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+
+ file = NULL;/* Eliminate a warning. */
+ /* Get the next entry that appears after the current offset. */
+ r = next_entry_seek(a, iso9660, &file);
+ if (r != ARCHIVE_OK)
+ return (r);
+
+ if (iso9660->seenJoliet) {
+ /*
+ * Convert UTF-16BE of a filename to local locale MBS
+ * and store the result into a filename field.
+ */
+ if (iso9660->sconv_utf16be == NULL) {
+ iso9660->sconv_utf16be =
+ archive_string_conversion_from_charset(
+ &(a->archive), "UTF-16BE", 1);
+ if (iso9660->sconv_utf16be == NULL)
+ /* Coundn't allocate memory */
+ return (ARCHIVE_FATAL);
+ }
+ if (iso9660->utf16be_path == NULL) {
+ iso9660->utf16be_path = malloc(UTF16_NAME_MAX);
+ if (iso9660->utf16be_path == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ if (iso9660->utf16be_previous_path == NULL) {
+ iso9660->utf16be_previous_path = malloc(UTF16_NAME_MAX);
+ if (iso9660->utf16be_previous_path == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ iso9660->utf16be_path_len = 0;
+ if (build_pathname_utf16be(iso9660->utf16be_path,
+ UTF16_NAME_MAX, &(iso9660->utf16be_path_len), file) != 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Pathname is too long");
+ }
+
+ r = archive_entry_copy_pathname_l(entry,
+ (const char *)iso9660->utf16be_path,
+ iso9660->utf16be_path_len,
+ iso9660->sconv_utf16be);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Pathname cannot be converted "
+ "from %s to current locale.",
+ archive_string_conversion_charset_name(
+ iso9660->sconv_utf16be));
+
+ rd_r = ARCHIVE_WARN;
+ }
+ } else {
+ archive_string_empty(&iso9660->pathname);
+ archive_entry_set_pathname(entry,
+ build_pathname(&iso9660->pathname, file));
+ }
+
+ iso9660->entry_bytes_remaining = file->size;
+ /* Offset for sparse-file-aware clients. */
+ iso9660->entry_sparse_offset = 0;
+
+ if (file->offset + file->size > iso9660->volume_size) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "File is beyond end-of-media: %s",
+ archive_entry_pathname(entry));
+ iso9660->entry_bytes_remaining = 0;
+ return (ARCHIVE_WARN);
+ }
+
+ /* Set up the entry structure with information about this entry. */
+ archive_entry_set_mode(entry, file->mode);
+ archive_entry_set_uid(entry, file->uid);
+ archive_entry_set_gid(entry, file->gid);
+ archive_entry_set_nlink(entry, file->nlinks);
+ if (file->birthtime_is_set)
+ archive_entry_set_birthtime(entry, file->birthtime, 0);
+ else
+ archive_entry_unset_birthtime(entry);
+ archive_entry_set_mtime(entry, file->mtime, 0);
+ archive_entry_set_ctime(entry, file->ctime, 0);
+ archive_entry_set_atime(entry, file->atime, 0);
+ /* N.B.: Rock Ridge supports 64-bit device numbers. */
+ archive_entry_set_rdev(entry, (dev_t)file->rdev);
+ archive_entry_set_size(entry, iso9660->entry_bytes_remaining);
+ if (file->symlink.s != NULL)
+ archive_entry_copy_symlink(entry, file->symlink.s);
+
+ /* Note: If the input isn't seekable, we can't rewind to
+ * return the same body again, so if the next entry refers to
+ * the same data, we have to return it as a hardlink to the
+ * original entry. */
+ if (file->number != -1 &&
+ file->number == iso9660->previous_number) {
+ if (iso9660->seenJoliet) {
+ r = archive_entry_copy_hardlink_l(entry,
+ (const char *)iso9660->utf16be_previous_path,
+ iso9660->utf16be_previous_path_len,
+ iso9660->sconv_utf16be);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Linkname cannot be converted "
+ "from %s to current locale.",
+ archive_string_conversion_charset_name(
+ iso9660->sconv_utf16be));
+ rd_r = ARCHIVE_WARN;
+ }
+ } else
+ archive_entry_set_hardlink(entry,
+ iso9660->previous_pathname.s);
+ archive_entry_unset_size(entry);
+ iso9660->entry_bytes_remaining = 0;
+ return (rd_r);
+ }
+
+ if ((file->mode & AE_IFMT) != AE_IFDIR &&
+ file->offset < iso9660->current_position) {
+ int64_t r64;
+
+ r64 = __archive_read_seek(a, file->offset, SEEK_SET);
+ if (r64 != (int64_t)file->offset) {
+ /* We can't seek backwards to extract it, so issue
+ * a warning. Note that this can only happen if
+ * this entry was added to the heap after we passed
+ * this offset, that is, only if the directory
+ * mentioning this entry is later than the body of
+ * the entry. Such layouts are very unusual; most
+ * ISO9660 writers lay out and record all directory
+ * information first, then store all file bodies. */
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Ignoring out-of-order file @%jx (%s) %jd < %jd",
+ (intmax_t)file->number,
+ iso9660->pathname.s,
+ (intmax_t)file->offset,
+ (intmax_t)iso9660->current_position);
+ iso9660->entry_bytes_remaining = 0;
+ return (ARCHIVE_WARN);
+ }
+ iso9660->current_position = (uint64_t)r64;
+ }
+
+ /* Initialize zisofs variables. */
+ iso9660->entry_zisofs.pz = file->pz;
+ if (file->pz) {
+#ifdef HAVE_ZLIB_H
+ struct zisofs *zisofs;
+
+ zisofs = &iso9660->entry_zisofs;
+ zisofs->initialized = 0;
+ zisofs->pz_log2_bs = file->pz_log2_bs;
+ zisofs->pz_uncompressed_size = file->pz_uncompressed_size;
+ zisofs->pz_offset = 0;
+ zisofs->header_avail = 0;
+ zisofs->header_passed = 0;
+ zisofs->block_pointers_avail = 0;
+#endif
+ archive_entry_set_size(entry, file->pz_uncompressed_size);
+ }
+
+ iso9660->previous_number = file->number;
+ if (iso9660->seenJoliet) {
+ memcpy(iso9660->utf16be_previous_path, iso9660->utf16be_path,
+ iso9660->utf16be_path_len);
+ iso9660->utf16be_previous_path_len = iso9660->utf16be_path_len;
+ } else
+ archive_strcpy(
+ &iso9660->previous_pathname, iso9660->pathname.s);
+
+ /* Reset entry_bytes_remaining if the file is multi extent. */
+ iso9660->entry_content = file->contents.first;
+ if (iso9660->entry_content != NULL)
+ iso9660->entry_bytes_remaining = iso9660->entry_content->size;
+
+ if (archive_entry_filetype(entry) == AE_IFDIR) {
+ /* Overwrite nlinks by proper link number which is
+ * calculated from number of sub directories. */
+ archive_entry_set_nlink(entry, 2 + file->subdirs);
+ /* Directory data has been read completely. */
+ iso9660->entry_bytes_remaining = 0;
+ }
+
+ if (rd_r != ARCHIVE_OK)
+ return (rd_r);
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_iso9660_read_data_skip(struct archive_read *a)
+{
+ /* Because read_next_header always does an explicit skip
+ * to the next entry, we don't need to do anything here. */
+ (void)a; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+#ifdef HAVE_ZLIB_H
+
+static int
+zisofs_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ struct iso9660 *iso9660;
+ struct zisofs *zisofs;
+ const unsigned char *p;
+ size_t avail;
+ ssize_t bytes_read;
+ size_t uncompressed_size;
+ int r;
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+ zisofs = &iso9660->entry_zisofs;
+
+ p = __archive_read_ahead(a, 1, &bytes_read);
+ if (bytes_read <= 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated zisofs file body");
+ return (ARCHIVE_FATAL);
+ }
+ if (bytes_read > iso9660->entry_bytes_remaining)
+ bytes_read = (ssize_t)iso9660->entry_bytes_remaining;
+ avail = bytes_read;
+ uncompressed_size = 0;
+
+ if (!zisofs->initialized) {
+ size_t ceil, xsize;
+
+ /* Allocate block pointers buffer. */
+ ceil = (size_t)((zisofs->pz_uncompressed_size +
+ (((int64_t)1) << zisofs->pz_log2_bs) - 1)
+ >> zisofs->pz_log2_bs);
+ xsize = (ceil + 1) * 4;
+ if (zisofs->block_pointers_alloc < xsize) {
+ size_t alloc;
+
+ if (zisofs->block_pointers != NULL)
+ free(zisofs->block_pointers);
+ alloc = ((xsize >> 10) + 1) << 10;
+ zisofs->block_pointers = malloc(alloc);
+ if (zisofs->block_pointers == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for zisofs decompression");
+ return (ARCHIVE_FATAL);
+ }
+ zisofs->block_pointers_alloc = alloc;
+ }
+ zisofs->block_pointers_size = xsize;
+
+ /* Allocate uncompressed data buffer. */
+ xsize = (size_t)1UL << zisofs->pz_log2_bs;
+ if (zisofs->uncompressed_buffer_size < xsize) {
+ if (zisofs->uncompressed_buffer != NULL)
+ free(zisofs->uncompressed_buffer);
+ zisofs->uncompressed_buffer = malloc(xsize);
+ if (zisofs->uncompressed_buffer == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for zisofs decompression");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ zisofs->uncompressed_buffer_size = xsize;
+
+ /*
+ * Read the file header, and check the magic code of zisofs.
+ */
+ if (zisofs->header_avail < sizeof(zisofs->header)) {
+ xsize = sizeof(zisofs->header) - zisofs->header_avail;
+ if (avail < xsize)
+ xsize = avail;
+ memcpy(zisofs->header + zisofs->header_avail, p, xsize);
+ zisofs->header_avail += xsize;
+ avail -= xsize;
+ p += xsize;
+ }
+ if (!zisofs->header_passed &&
+ zisofs->header_avail == sizeof(zisofs->header)) {
+ int err = 0;
+
+ if (memcmp(zisofs->header, zisofs_magic,
+ sizeof(zisofs_magic)) != 0)
+ err = 1;
+ if (archive_le32dec(zisofs->header + 8)
+ != zisofs->pz_uncompressed_size)
+ err = 1;
+ if (zisofs->header[12] != 4)
+ err = 1;
+ if (zisofs->header[13] != zisofs->pz_log2_bs)
+ err = 1;
+ if (err) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Illegal zisofs file body");
+ return (ARCHIVE_FATAL);
+ }
+ zisofs->header_passed = 1;
+ }
+ /*
+ * Read block pointers.
+ */
+ if (zisofs->header_passed &&
+ zisofs->block_pointers_avail < zisofs->block_pointers_size) {
+ xsize = zisofs->block_pointers_size
+ - zisofs->block_pointers_avail;
+ if (avail < xsize)
+ xsize = avail;
+ memcpy(zisofs->block_pointers
+ + zisofs->block_pointers_avail, p, xsize);
+ zisofs->block_pointers_avail += xsize;
+ avail -= xsize;
+ p += xsize;
+ if (zisofs->block_pointers_avail
+ == zisofs->block_pointers_size) {
+ /* We've got all block pointers and initialize
+ * related variables. */
+ zisofs->block_off = 0;
+ zisofs->block_avail = 0;
+ /* Complete a initialization */
+ zisofs->initialized = 1;
+ }
+ }
+
+ if (!zisofs->initialized)
+ goto next_data; /* We need more data. */
+ }
+
+ /*
+ * Get block offsets from block pointers.
+ */
+ if (zisofs->block_avail == 0) {
+ uint32_t bst, bed;
+
+ if (zisofs->block_off + 4 >= zisofs->block_pointers_size) {
+ /* There isn't a pair of offsets. */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Illegal zisofs block pointers");
+ return (ARCHIVE_FATAL);
+ }
+ bst = archive_le32dec(
+ zisofs->block_pointers + zisofs->block_off);
+ if (bst != zisofs->pz_offset + (bytes_read - avail)) {
+ /* TODO: Should we seek offset of current file
+ * by bst ? */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Illegal zisofs block pointers(cannot seek)");
+ return (ARCHIVE_FATAL);
+ }
+ bed = archive_le32dec(
+ zisofs->block_pointers + zisofs->block_off + 4);
+ if (bed < bst) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Illegal zisofs block pointers");
+ return (ARCHIVE_FATAL);
+ }
+ zisofs->block_avail = bed - bst;
+ zisofs->block_off += 4;
+
+ /* Initialize compression library for new block. */
+ if (zisofs->stream_valid)
+ r = inflateReset(&zisofs->stream);
+ else
+ r = inflateInit(&zisofs->stream);
+ if (r != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't initialize zisofs decompression.");
+ return (ARCHIVE_FATAL);
+ }
+ zisofs->stream_valid = 1;
+ zisofs->stream.total_in = 0;
+ zisofs->stream.total_out = 0;
+ }
+
+ /*
+ * Make uncompressed data.
+ */
+ if (zisofs->block_avail == 0) {
+ memset(zisofs->uncompressed_buffer, 0,
+ zisofs->uncompressed_buffer_size);
+ uncompressed_size = zisofs->uncompressed_buffer_size;
+ } else {
+ zisofs->stream.next_in = (Bytef *)(uintptr_t)(const void *)p;
+ if (avail > zisofs->block_avail)
+ zisofs->stream.avail_in = zisofs->block_avail;
+ else
+ zisofs->stream.avail_in = (uInt)avail;
+ zisofs->stream.next_out = zisofs->uncompressed_buffer;
+ zisofs->stream.avail_out =
+ (uInt)zisofs->uncompressed_buffer_size;
+
+ r = inflate(&zisofs->stream, 0);
+ switch (r) {
+ case Z_OK: /* Decompressor made some progress.*/
+ case Z_STREAM_END: /* Found end of stream. */
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "zisofs decompression failed (%d)", r);
+ return (ARCHIVE_FATAL);
+ }
+ uncompressed_size =
+ zisofs->uncompressed_buffer_size - zisofs->stream.avail_out;
+ avail -= zisofs->stream.next_in - p;
+ zisofs->block_avail -= (uint32_t)(zisofs->stream.next_in - p);
+ }
+next_data:
+ bytes_read -= avail;
+ *buff = zisofs->uncompressed_buffer;
+ *size = uncompressed_size;
+ *offset = iso9660->entry_sparse_offset;
+ iso9660->entry_sparse_offset += uncompressed_size;
+ iso9660->entry_bytes_remaining -= bytes_read;
+ iso9660->current_position += bytes_read;
+ zisofs->pz_offset += (uint32_t)bytes_read;
+ iso9660->entry_bytes_unconsumed += bytes_read;
+
+ return (ARCHIVE_OK);
+}
+
+#else /* HAVE_ZLIB_H */
+
+static int
+zisofs_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+
+ (void)buff;/* UNUSED */
+ (void)size;/* UNUSED */
+ (void)offset;/* UNUSED */
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "zisofs is not supported on this platform.");
+ return (ARCHIVE_FAILED);
+}
+
+#endif /* HAVE_ZLIB_H */
+
+static int
+archive_read_format_iso9660_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ ssize_t bytes_read;
+ struct iso9660 *iso9660;
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+
+ if (iso9660->entry_bytes_unconsumed) {
+ __archive_read_consume(a, iso9660->entry_bytes_unconsumed);
+ iso9660->entry_bytes_unconsumed = 0;
+ }
+
+ if (iso9660->entry_bytes_remaining <= 0) {
+ if (iso9660->entry_content != NULL)
+ iso9660->entry_content = iso9660->entry_content->next;
+ if (iso9660->entry_content == NULL) {
+ *buff = NULL;
+ *size = 0;
+ *offset = iso9660->entry_sparse_offset;
+ return (ARCHIVE_EOF);
+ }
+ /* Seek forward to the start of the entry. */
+ if (iso9660->current_position < iso9660->entry_content->offset) {
+ int64_t step;
+
+ step = iso9660->entry_content->offset -
+ iso9660->current_position;
+ step = __archive_read_consume(a, step);
+ if (step < 0)
+ return ((int)step);
+ iso9660->current_position =
+ iso9660->entry_content->offset;
+ }
+ if (iso9660->entry_content->offset < iso9660->current_position) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Ignoring out-of-order file (%s) %jd < %jd",
+ iso9660->pathname.s,
+ (intmax_t)iso9660->entry_content->offset,
+ (intmax_t)iso9660->current_position);
+ *buff = NULL;
+ *size = 0;
+ *offset = iso9660->entry_sparse_offset;
+ return (ARCHIVE_WARN);
+ }
+ iso9660->entry_bytes_remaining = iso9660->entry_content->size;
+ }
+ if (iso9660->entry_zisofs.pz)
+ return (zisofs_read_data(a, buff, size, offset));
+
+ *buff = __archive_read_ahead(a, 1, &bytes_read);
+ if (bytes_read == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Truncated input file");
+ if (*buff == NULL)
+ return (ARCHIVE_FATAL);
+ if (bytes_read > iso9660->entry_bytes_remaining)
+ bytes_read = (ssize_t)iso9660->entry_bytes_remaining;
+ *size = bytes_read;
+ *offset = iso9660->entry_sparse_offset;
+ iso9660->entry_sparse_offset += bytes_read;
+ iso9660->entry_bytes_remaining -= bytes_read;
+ iso9660->entry_bytes_unconsumed = bytes_read;
+ iso9660->current_position += bytes_read;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_iso9660_cleanup(struct archive_read *a)
+{
+ struct iso9660 *iso9660;
+ int r = ARCHIVE_OK;
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+ release_files(iso9660);
+ free(iso9660->read_ce_req.reqs);
+ archive_string_free(&iso9660->pathname);
+ archive_string_free(&iso9660->previous_pathname);
+ if (iso9660->pending_files.files)
+ free(iso9660->pending_files.files);
+#ifdef HAVE_ZLIB_H
+ free(iso9660->entry_zisofs.uncompressed_buffer);
+ free(iso9660->entry_zisofs.block_pointers);
+ if (iso9660->entry_zisofs.stream_valid) {
+ if (inflateEnd(&iso9660->entry_zisofs.stream) != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to clean up zlib decompressor");
+ r = ARCHIVE_FATAL;
+ }
+ }
+#endif
+ free(iso9660->utf16be_path);
+ free(iso9660->utf16be_previous_path);
+ free(iso9660);
+ (a->format->data) = NULL;
+ return (r);
+}
+
+/*
+ * This routine parses a single ISO directory record, makes sense
+ * of any extensions, and stores the result in memory.
+ */
+static struct file_info *
+parse_file_info(struct archive_read *a, struct file_info *parent,
+ const unsigned char *isodirrec)
+{
+ struct iso9660 *iso9660;
+ struct file_info *file;
+ size_t name_len;
+ const unsigned char *rr_start, *rr_end;
+ const unsigned char *p;
+ size_t dr_len;
+ uint64_t fsize;
+ int32_t location;
+ int flags;
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+
+ dr_len = (size_t)isodirrec[DR_length_offset];
+ name_len = (size_t)isodirrec[DR_name_len_offset];
+ location = archive_le32dec(isodirrec + DR_extent_offset);
+ fsize = toi(isodirrec + DR_size_offset, DR_size_size);
+ /* Sanity check that dr_len needs at least 34. */
+ if (dr_len < 34) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid length of directory record");
+ return (NULL);
+ }
+ /* Sanity check that name_len doesn't exceed dr_len. */
+ if (dr_len - 33 < name_len || name_len == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid length of file identifier");
+ return (NULL);
+ }
+ /* Sanity check that location doesn't exceed volume block.
+ * Don't check lower limit of location; it's possibility
+ * the location has negative value when file type is symbolic
+ * link or file size is zero. As far as I know latest mkisofs
+ * do that.
+ */
+ if (location > 0 &&
+ (location + ((fsize + iso9660->logical_block_size -1)
+ / iso9660->logical_block_size))
+ > (uint32_t)iso9660->volume_block) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid location of extent of file");
+ return (NULL);
+ }
+ /* Sanity check that location doesn't have a negative value
+ * when the file is not empty. it's too large. */
+ if (fsize != 0 && location < 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid location of extent of file");
+ 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) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for file entry");
+ return (NULL);
+ }
+ file->parent = parent;
+ file->offset = iso9660->logical_block_size * (uint64_t)location;
+ file->size = fsize;
+ file->mtime = isodate7(isodirrec + DR_date_offset);
+ file->ctime = file->atime = file->mtime;
+ file->rede_files.first = NULL;
+ file->rede_files.last = &(file->rede_files.first);
+
+ p = isodirrec + DR_name_offset;
+ /* Rockridge extensions (if any) follow name. Compute this
+ * before fidgeting the name_len below. */
+ rr_start = p + name_len + (name_len & 1 ? 0 : 1);
+ rr_end = isodirrec + dr_len;
+
+ if (iso9660->seenJoliet) {
+ /* Joliet names are max 64 chars (128 bytes) according to spec,
+ * but genisoimage/mkisofs allows recording longer Joliet
+ * names which are 103 UCS2 characters(206 bytes) by their
+ * option '-joliet-long'.
+ */
+ if (name_len > 206)
+ name_len = 206;
+ name_len &= ~1;
+
+ /* trim trailing first version and dot from filename.
+ *
+ * Remember we were in UTF-16BE land!
+ * SEPARATOR 1 (.) and SEPARATOR 2 (;) are both
+ * 16 bits big endian characters on Joliet.
+ *
+ * TODO: sanitize filename?
+ * Joliet allows any UCS-2 char except:
+ * *, /, :, ;, ? and \.
+ */
+ /* Chop off trailing ';1' from files. */
+ if (name_len > 4 && p[name_len-4] == 0 && p[name_len-3] == ';'
+ && p[name_len-2] == 0 && p[name_len-1] == '1')
+ name_len -= 4;
+#if 0 /* XXX: this somehow manages to strip of single-character file extensions, like '.c'. */
+ /* Chop off trailing '.' from filenames. */
+ if (name_len > 2 && p[name_len-2] == 0 && p[name_len-1] == '.')
+ name_len -= 2;
+#endif
+ if ((file->utf16be_name = malloc(name_len)) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for file name");
+ return (NULL);
+ }
+ memcpy(file->utf16be_name, p, name_len);
+ file->utf16be_bytes = name_len;
+ } else {
+ /* Chop off trailing ';1' from files. */
+ if (name_len > 2 && p[name_len - 2] == ';' &&
+ p[name_len - 1] == '1')
+ name_len -= 2;
+ /* Chop off trailing '.' from filenames. */
+ if (name_len > 1 && p[name_len - 1] == '.')
+ --name_len;
+
+ archive_strncpy(&file->name, (const char *)p, name_len);
+ }
+
+ flags = isodirrec[DR_flags_offset];
+ if (flags & 0x02)
+ file->mode = AE_IFDIR | 0700;
+ else
+ file->mode = AE_IFREG | 0400;
+ if (flags & 0x80)
+ file->multi_extent = 1;
+ else
+ file->multi_extent = 0;
+ /*
+ * Use a location for the file number, which is treated as an inode
+ * number to find out hardlink target. If Rockridge extensions is
+ * being used, the file number will be overwritten by FILE SERIAL
+ * NUMBER of RRIP "PX" extension.
+ * Note: Old mkisofs did not record that FILE SERIAL NUMBER
+ * in ISO images.
+ * Note2: xorriso set 0 to the location of a symlink file.
+ */
+ if (file->size == 0 && location >= 0) {
+ /* If file->size is zero, its location points wrong place,
+ * and so we should not use it for the file number.
+ * When the location has negative value, it can be used
+ * for the file number.
+ */
+ file->number = -1;
+ /* Do not appear before any directory entries. */
+ file->offset = -1;
+ } else
+ file->number = (int64_t)(uint32_t)location;
+
+ /* Rockridge extensions overwrite information from above. */
+ if (iso9660->opt_support_rockridge) {
+ if (parent == NULL && rr_end - rr_start >= 7) {
+ p = rr_start;
+ if (memcmp(p, "SP\x07\x01\xbe\xef", 6) == 0) {
+ /*
+ * SP extension stores the suspOffset
+ * (Number of bytes to skip between
+ * filename and SUSP records.)
+ * It is mandatory by the SUSP standard
+ * (IEEE 1281).
+ *
+ * It allows SUSP to coexist with
+ * non-SUSP uses of the System
+ * Use Area by placing non-SUSP data
+ * before SUSP data.
+ *
+ * SP extension must be in the root
+ * directory entry, disable all SUSP
+ * processing if not found.
+ */
+ iso9660->suspOffset = p[6];
+ iso9660->seenSUSP = 1;
+ rr_start += 7;
+ }
+ }
+ if (iso9660->seenSUSP) {
+ int r;
+
+ file->name_continues = 0;
+ file->symlink_continues = 0;
+ rr_start += iso9660->suspOffset;
+ r = parse_rockridge(a, file, rr_start, rr_end);
+ if (r != ARCHIVE_OK) {
+ free(file);
+ return (NULL);
+ }
+ /*
+ * A file size of symbolic link files in ISO images
+ * made by makefs is not zero and its location is
+ * the same as those of next regular file. That is
+ * the same as hard like file and it causes unexpected
+ * error.
+ */
+ if (file->size > 0 &&
+ (file->mode & AE_IFMT) == AE_IFLNK) {
+ file->size = 0;
+ file->number = -1;
+ file->offset = -1;
+ }
+ } else
+ /* If there isn't SUSP, disable parsing
+ * rock ridge extensions. */
+ iso9660->opt_support_rockridge = 0;
+ }
+
+ file->nlinks = 1;/* Reset nlink. we'll calculate it later. */
+ /* Tell file's parent how many children that parent has. */
+ if (parent != NULL && (flags & 0x02))
+ parent->subdirs++;
+
+ if (iso9660->seenRockridge) {
+ if (parent != NULL && parent->parent == NULL &&
+ (flags & 0x02) && iso9660->rr_moved == NULL &&
+ file->name.s &&
+ (strcmp(file->name.s, "rr_moved") == 0 ||
+ strcmp(file->name.s, ".rr_moved") == 0)) {
+ iso9660->rr_moved = file;
+ file->rr_moved = 1;
+ file->rr_moved_has_re_only = 1;
+ file->re = 0;
+ parent->subdirs--;
+ } else if (file->re) {
+ /*
+ * Sanity check: file's parent is rr_moved.
+ */
+ if (parent == NULL || parent->rr_moved == 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Invalid Rockridge RE");
+ return (NULL);
+ }
+ /*
+ * Sanity check: file does not have "CL" extension.
+ */
+ if (file->cl_offset) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Invalid Rockridge RE and CL");
+ return (NULL);
+ }
+ /*
+ * Sanity check: The file type must be a directory.
+ */
+ if ((flags & 0x02) == 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Invalid Rockridge RE");
+ return (NULL);
+ }
+ } else if (parent != NULL && parent->rr_moved)
+ file->rr_moved_has_re_only = 0;
+ else if (parent != NULL && (flags & 0x02) &&
+ (parent->re || parent->re_descendant))
+ file->re_descendant = 1;
+ if (file->cl_offset) {
+ struct file_info *r;
+
+ if (parent == NULL || parent->parent == NULL) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Invalid Rockridge CL");
+ return (NULL);
+ }
+ /*
+ * Sanity check: The file type must be a regular file.
+ */
+ if ((flags & 0x02) != 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Invalid Rockridge CL");
+ return (NULL);
+ }
+ parent->subdirs++;
+ /* Overwrite an offset and a number of this "CL" entry
+ * to appear before other dirs. "+1" to those is to
+ * make sure to appear after "RE" entry which this
+ * "CL" entry should be connected with. */
+ file->offset = file->number = file->cl_offset + 1;
+
+ /*
+ * Sanity check: cl_offset does not point at its
+ * the parents or itself.
+ */
+ for (r = parent; r; r = r->parent) {
+ if (r->offset == file->cl_offset) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Invalid Rockridge CL");
+ return (NULL);
+ }
+ }
+ if (file->cl_offset == file->offset ||
+ parent->rr_moved) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Invalid Rockridge CL");
+ return (NULL);
+ }
+ }
+ }
+
+#if DEBUG
+ /* DEBUGGING: Warn about attributes I don't yet fully support. */
+ if ((flags & ~0x02) != 0) {
+ fprintf(stderr, "\n ** Unrecognized flag: ");
+ dump_isodirrec(stderr, isodirrec);
+ fprintf(stderr, "\n");
+ } else if (toi(isodirrec + DR_volume_sequence_number_offset, 2) != 1) {
+ fprintf(stderr, "\n ** Unrecognized sequence number: ");
+ dump_isodirrec(stderr, isodirrec);
+ fprintf(stderr, "\n");
+ } else if (*(isodirrec + DR_file_unit_size_offset) != 0) {
+ fprintf(stderr, "\n ** Unexpected file unit size: ");
+ dump_isodirrec(stderr, isodirrec);
+ fprintf(stderr, "\n");
+ } else if (*(isodirrec + DR_interleave_offset) != 0) {
+ fprintf(stderr, "\n ** Unexpected interleave: ");
+ dump_isodirrec(stderr, isodirrec);
+ fprintf(stderr, "\n");
+ } else if (*(isodirrec + DR_ext_attr_length_offset) != 0) {
+ fprintf(stderr, "\n ** Unexpected extended attribute length: ");
+ dump_isodirrec(stderr, isodirrec);
+ fprintf(stderr, "\n");
+ }
+#endif
+ register_file(iso9660, file);
+ return (file);
+}
+
+static int
+parse_rockridge(struct archive_read *a, struct file_info *file,
+ const unsigned char *p, const unsigned char *end)
+{
+ struct iso9660 *iso9660;
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+
+ while (p + 4 <= end /* Enough space for another entry. */
+ && p[0] >= 'A' && p[0] <= 'Z' /* Sanity-check 1st char of name. */
+ && p[1] >= 'A' && p[1] <= 'Z' /* Sanity-check 2nd char of name. */
+ && p[2] >= 4 /* Sanity-check length. */
+ && p + p[2] <= end) { /* Sanity-check length. */
+ const unsigned char *data = p + 4;
+ int data_length = p[2] - 4;
+ int version = p[3];
+
+ switch(p[0]) {
+ case 'C':
+ if (p[1] == 'E') {
+ if (version == 1 && data_length == 24) {
+ /*
+ * CE extension comprises:
+ * 8 byte sector containing extension
+ * 8 byte offset w/in above sector
+ * 8 byte length of continuation
+ */
+ int32_t location =
+ archive_le32dec(data);
+ file->ce_offset =
+ archive_le32dec(data+8);
+ file->ce_size =
+ archive_le32dec(data+16);
+ if (register_CE(a, location, file)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ }
+ else if (p[1] == 'L') {
+ if (version == 1 && data_length == 8) {
+ file->cl_offset = (uint64_t)
+ iso9660->logical_block_size *
+ (uint64_t)archive_le32dec(data);
+ iso9660->seenRockridge = 1;
+ }
+ }
+ break;
+ case 'N':
+ if (p[1] == 'M') {
+ if (version == 1) {
+ parse_rockridge_NM1(file,
+ data, data_length);
+ iso9660->seenRockridge = 1;
+ }
+ }
+ break;
+ case 'P':
+ /*
+ * PD extension is padding;
+ * contents are always ignored.
+ *
+ * PL extension won't appear;
+ * contents are always ignored.
+ */
+ if (p[1] == 'N') {
+ if (version == 1 && data_length == 16) {
+ file->rdev = toi(data,4);
+ file->rdev <<= 32;
+ file->rdev |= toi(data + 8, 4);
+ iso9660->seenRockridge = 1;
+ }
+ }
+ else if (p[1] == 'X') {
+ /*
+ * PX extension comprises:
+ * 8 bytes for mode,
+ * 8 bytes for nlinks,
+ * 8 bytes for uid,
+ * 8 bytes for gid,
+ * 8 bytes for inode.
+ */
+ if (version == 1) {
+ if (data_length >= 8)
+ file->mode
+ = toi(data, 4);
+ if (data_length >= 16)
+ file->nlinks
+ = toi(data + 8, 4);
+ if (data_length >= 24)
+ file->uid
+ = toi(data + 16, 4);
+ if (data_length >= 32)
+ file->gid
+ = toi(data + 24, 4);
+ if (data_length >= 40)
+ file->number
+ = toi(data + 32, 4);
+ iso9660->seenRockridge = 1;
+ }
+ }
+ break;
+ case 'R':
+ if (p[1] == 'E' && version == 1) {
+ file->re = 1;
+ iso9660->seenRockridge = 1;
+ }
+ else if (p[1] == 'R' && version == 1) {
+ /*
+ * RR extension comprises:
+ * one byte flag value
+ * This extension is obsolete,
+ * so contents are always ignored.
+ */
+ }
+ break;
+ case 'S':
+ if (p[1] == 'L') {
+ if (version == 1) {
+ parse_rockridge_SL1(file,
+ data, data_length);
+ iso9660->seenRockridge = 1;
+ }
+ }
+ else if (p[1] == 'T'
+ && data_length == 0 && version == 1) {
+ /*
+ * ST extension marks end of this
+ * block of SUSP entries.
+ *
+ * It allows SUSP to coexist with
+ * non-SUSP uses of the System
+ * Use Area by placing non-SUSP data
+ * after SUSP data.
+ */
+ iso9660->seenSUSP = 0;
+ iso9660->seenRockridge = 0;
+ return (ARCHIVE_OK);
+ }
+ break;
+ case 'T':
+ if (p[1] == 'F') {
+ if (version == 1) {
+ parse_rockridge_TF1(file,
+ data, data_length);
+ iso9660->seenRockridge = 1;
+ }
+ }
+ break;
+ case 'Z':
+ if (p[1] == 'F') {
+ if (version == 1)
+ parse_rockridge_ZF1(file,
+ data, data_length);
+ }
+ break;
+ default:
+ break;
+ }
+
+ p += p[2];
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+register_CE(struct archive_read *a, int32_t location,
+ struct file_info *file)
+{
+ struct iso9660 *iso9660;
+ struct read_ce_queue *heap;
+ struct read_ce_req *p;
+ uint64_t offset, parent_offset;
+ int hole, parent;
+
+ iso9660 = (struct iso9660 *)(a->format->data);
+ offset = ((uint64_t)location) * (uint64_t)iso9660->logical_block_size;
+ if (((file->mode & AE_IFMT) == AE_IFREG &&
+ offset >= file->offset) ||
+ offset < iso9660->current_position ||
+ (((uint64_t)file->ce_offset) + file->ce_size)
+ > (uint64_t)iso9660->logical_block_size ||
+ offset + file->ce_offset + file->ce_size
+ > iso9660->volume_size) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid parameter in SUSP \"CE\" extension");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Expand our CE list as necessary. */
+ heap = &(iso9660->read_ce_req);
+ if (heap->cnt >= heap->allocated) {
+ int new_size;
+
+ if (heap->allocated < 16)
+ new_size = 16;
+ else
+ new_size = heap->allocated * 2;
+ /* Overflow might keep us from growing the list. */
+ if (new_size <= heap->allocated) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ p = calloc(new_size, sizeof(p[0]));
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ if (heap->reqs != NULL) {
+ memcpy(p, heap->reqs, heap->cnt * sizeof(*p));
+ free(heap->reqs);
+ }
+ heap->reqs = p;
+ heap->allocated = new_size;
+ }
+
+ /*
+ * Start with hole at end, walk it up tree to find insertion point.
+ */
+ hole = heap->cnt++;
+ while (hole > 0) {
+ parent = (hole - 1)/2;
+ parent_offset = heap->reqs[parent].offset;
+ if (offset >= parent_offset) {
+ heap->reqs[hole].offset = offset;
+ heap->reqs[hole].file = file;
+ return (ARCHIVE_OK);
+ }
+ /* Move parent into hole <==> move hole up tree. */
+ heap->reqs[hole] = heap->reqs[parent];
+ hole = parent;
+ }
+ heap->reqs[0].offset = offset;
+ heap->reqs[0].file = file;
+ return (ARCHIVE_OK);
+}
+
+static void
+next_CE(struct read_ce_queue *heap)
+{
+ uint64_t a_offset, b_offset, c_offset;
+ int a, b, c;
+ struct read_ce_req tmp;
+
+ if (heap->cnt < 1)
+ return;
+
+ /*
+ * Move the last item in the heap to the root of the tree
+ */
+ heap->reqs[0] = heap->reqs[--(heap->cnt)];
+
+ /*
+ * Rebalance the heap.
+ */
+ a = 0; /* Starting element and its offset */
+ a_offset = heap->reqs[a].offset;
+ for (;;) {
+ b = a + a + 1; /* First child */
+ if (b >= heap->cnt)
+ return;
+ b_offset = heap->reqs[b].offset;
+ c = b + 1; /* Use second child if it is smaller. */
+ if (c < heap->cnt) {
+ c_offset = heap->reqs[c].offset;
+ if (c_offset < b_offset) {
+ b = c;
+ b_offset = c_offset;
+ }
+ }
+ if (a_offset <= b_offset)
+ return;
+ tmp = heap->reqs[a];
+ heap->reqs[a] = heap->reqs[b];
+ heap->reqs[b] = tmp;
+ a = b;
+ }
+}
+
+
+static int
+read_CE(struct archive_read *a, struct iso9660 *iso9660)
+{
+ struct read_ce_queue *heap;
+ const unsigned char *b, *p, *end;
+ struct file_info *file;
+ size_t step;
+ int r;
+
+ /* Read data which RRIP "CE" extension points. */
+ heap = &(iso9660->read_ce_req);
+ step = iso9660->logical_block_size;
+ while (heap->cnt &&
+ heap->reqs[0].offset == iso9660->current_position) {
+ b = __archive_read_ahead(a, step, NULL);
+ if (b == NULL) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to read full block when scanning "
+ "ISO9660 directory list");
+ return (ARCHIVE_FATAL);
+ }
+ do {
+ file = heap->reqs[0].file;
+ if (file->ce_offset + file->ce_size > step) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Malformed CE information");
+ return (ARCHIVE_FATAL);
+ }
+ p = b + file->ce_offset;
+ end = p + file->ce_size;
+ next_CE(heap);
+ r = parse_rockridge(a, file, p, end);
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } while (heap->cnt &&
+ heap->reqs[0].offset == iso9660->current_position);
+ /* NOTE: Do not move this consume's code to fron of
+ * do-while loop. Registration of nested CE extension
+ * might cause error because of current position. */
+ __archive_read_consume(a, step);
+ iso9660->current_position += step;
+ }
+ return (ARCHIVE_OK);
+}
+
+static void
+parse_rockridge_NM1(struct file_info *file,
+ const unsigned char *data, int data_length)
+{
+ if (!file->name_continues)
+ archive_string_empty(&file->name);
+ file->name_continues = 0;
+ if (data_length < 1)
+ return;
+ /*
+ * NM version 1 extension comprises:
+ * 1 byte flag, value is one of:
+ * = 0: remainder is name
+ * = 1: remainder is name, next NM entry continues name
+ * = 2: "."
+ * = 4: ".."
+ * = 32: Implementation specific
+ * All other values are reserved.
+ */
+ switch(data[0]) {
+ case 0:
+ if (data_length < 2)
+ return;
+ archive_strncat(&file->name,
+ (const char *)data + 1, data_length - 1);
+ break;
+ case 1:
+ if (data_length < 2)
+ return;
+ archive_strncat(&file->name,
+ (const char *)data + 1, data_length - 1);
+ file->name_continues = 1;
+ break;
+ case 2:
+ archive_strcat(&file->name, ".");
+ break;
+ case 4:
+ archive_strcat(&file->name, "..");
+ break;
+ default:
+ return;
+ }
+
+}
+
+static void
+parse_rockridge_TF1(struct file_info *file, const unsigned char *data,
+ int data_length)
+{
+ char flag;
+ /*
+ * TF extension comprises:
+ * one byte flag
+ * create time (optional)
+ * modify time (optional)
+ * access time (optional)
+ * attribute time (optional)
+ * Time format and presence of fields
+ * is controlled by flag bits.
+ */
+ if (data_length < 1)
+ return;
+ flag = data[0];
+ ++data;
+ --data_length;
+ if (flag & 0x80) {
+ /* Use 17-byte time format. */
+ if ((flag & 1) && data_length >= 17) {
+ /* Create time. */
+ file->birthtime_is_set = 1;
+ file->birthtime = isodate17(data);
+ data += 17;
+ data_length -= 17;
+ }
+ if ((flag & 2) && data_length >= 17) {
+ /* Modify time. */
+ file->mtime = isodate17(data);
+ data += 17;
+ data_length -= 17;
+ }
+ if ((flag & 4) && data_length >= 17) {
+ /* Access time. */
+ file->atime = isodate17(data);
+ data += 17;
+ data_length -= 17;
+ }
+ if ((flag & 8) && data_length >= 17) {
+ /* Attribute change time. */
+ file->ctime = isodate17(data);
+ }
+ } else {
+ /* Use 7-byte time format. */
+ if ((flag & 1) && data_length >= 7) {
+ /* Create time. */
+ file->birthtime_is_set = 1;
+ file->birthtime = isodate7(data);
+ data += 7;
+ data_length -= 7;
+ }
+ if ((flag & 2) && data_length >= 7) {
+ /* Modify time. */
+ file->mtime = isodate7(data);
+ data += 7;
+ data_length -= 7;
+ }
+ if ((flag & 4) && data_length >= 7) {
+ /* Access time. */
+ file->atime = isodate7(data);
+ data += 7;
+ data_length -= 7;
+ }
+ if ((flag & 8) && data_length >= 7) {
+ /* Attribute change time. */
+ file->ctime = isodate7(data);
+ }
+ }
+}
+
+static void
+parse_rockridge_SL1(struct file_info *file, const unsigned char *data,
+ int data_length)
+{
+ const char *separator = "";
+
+ if (!file->symlink_continues || file->symlink.length < 1)
+ archive_string_empty(&file->symlink);
+ file->symlink_continues = 0;
+
+ /*
+ * Defined flag values:
+ * 0: This is the last SL record for this symbolic link
+ * 1: this symbolic link field continues in next SL entry
+ * All other values are reserved.
+ */
+ if (data_length < 1)
+ return;
+ switch(*data) {
+ case 0:
+ break;
+ case 1:
+ file->symlink_continues = 1;
+ break;
+ default:
+ return;
+ }
+ ++data; /* Skip flag byte. */
+ --data_length;
+
+ /*
+ * SL extension body stores "components".
+ * Basically, this is a complicated way of storing
+ * a POSIX path. It also interferes with using
+ * symlinks for storing non-path data. <sigh>
+ *
+ * Each component is 2 bytes (flag and length)
+ * possibly followed by name data.
+ */
+ while (data_length >= 2) {
+ unsigned char flag = *data++;
+ unsigned char nlen = *data++;
+ data_length -= 2;
+
+ archive_strcat(&file->symlink, separator);
+ separator = "/";
+
+ switch(flag) {
+ case 0: /* Usual case, this is text. */
+ if (data_length < nlen)
+ return;
+ archive_strncat(&file->symlink,
+ (const char *)data, nlen);
+ break;
+ case 0x01: /* Text continues in next component. */
+ if (data_length < nlen)
+ return;
+ archive_strncat(&file->symlink,
+ (const char *)data, nlen);
+ separator = "";
+ break;
+ case 0x02: /* Current dir. */
+ archive_strcat(&file->symlink, ".");
+ break;
+ case 0x04: /* Parent dir. */
+ archive_strcat(&file->symlink, "..");
+ break;
+ case 0x08: /* Root of filesystem. */
+ archive_strcat(&file->symlink, "/");
+ separator = "";
+ break;
+ case 0x10: /* Undefined (historically "volume root" */
+ archive_string_empty(&file->symlink);
+ archive_strcat(&file->symlink, "ROOT");
+ break;
+ case 0x20: /* Undefined (historically "hostname") */
+ archive_strcat(&file->symlink, "hostname");
+ break;
+ default:
+ /* TODO: issue a warning ? */
+ return;
+ }
+ data += nlen;
+ data_length -= nlen;
+ }
+}
+
+static void
+parse_rockridge_ZF1(struct file_info *file, const unsigned char *data,
+ int data_length)
+{
+
+ if (data[0] == 0x70 && data[1] == 0x7a && data_length == 12) {
+ /* paged zlib */
+ file->pz = 1;
+ file->pz_log2_bs = data[3];
+ file->pz_uncompressed_size = archive_le32dec(&data[4]);
+ }
+}
+
+static void
+register_file(struct iso9660 *iso9660, struct file_info *file)
+{
+
+ file->use_next = iso9660->use_files;
+ iso9660->use_files = file;
+}
+
+static void
+release_files(struct iso9660 *iso9660)
+{
+ struct content *con, *connext;
+ struct file_info *file;
+
+ file = iso9660->use_files;
+ while (file != NULL) {
+ struct file_info *next = file->use_next;
+
+ archive_string_free(&file->name);
+ archive_string_free(&file->symlink);
+ free(file->utf16be_name);
+ con = file->contents.first;
+ while (con != NULL) {
+ connext = con->next;
+ free(con);
+ con = connext;
+ }
+ free(file);
+ file = next;
+ }
+}
+
+static int
+next_entry_seek(struct archive_read *a, struct iso9660 *iso9660,
+ struct file_info **pfile)
+{
+ struct file_info *file;
+ int r;
+
+ r = next_cache_entry(a, iso9660, pfile);
+ if (r != ARCHIVE_OK)
+ return (r);
+ file = *pfile;
+
+ /* Don't waste time seeking for zero-length bodies. */
+ if (file->size == 0)
+ file->offset = iso9660->current_position;
+
+ /* flush any remaining bytes from the last round to ensure
+ * we're positioned */
+ if (iso9660->entry_bytes_unconsumed) {
+ __archive_read_consume(a, iso9660->entry_bytes_unconsumed);
+ iso9660->entry_bytes_unconsumed = 0;
+ }
+
+ /* Seek forward to the start of the entry. */
+ if (iso9660->current_position < file->offset) {
+ int64_t step;
+
+ step = file->offset - iso9660->current_position;
+ step = __archive_read_consume(a, step);
+ if (step < 0)
+ return ((int)step);
+ iso9660->current_position = file->offset;
+ }
+
+ /* We found body of file; handle it now. */
+ return (ARCHIVE_OK);
+}
+
+static int
+next_cache_entry(struct archive_read *a, struct iso9660 *iso9660,
+ struct file_info **pfile)
+{
+ struct file_info *file;
+ struct {
+ struct file_info *first;
+ struct file_info **last;
+ } empty_files;
+ int64_t number;
+ int count;
+
+ file = cache_get_entry(iso9660);
+ if (file != NULL) {
+ *pfile = file;
+ return (ARCHIVE_OK);
+ }
+
+ for (;;) {
+ struct file_info *re, *d;
+
+ *pfile = file = next_entry(iso9660);
+ if (file == NULL) {
+ /*
+ * If directory entries all which are descendant of
+ * rr_moved are stil remaning, expose their.
+ */
+ if (iso9660->re_files.first != NULL &&
+ iso9660->rr_moved != NULL &&
+ iso9660->rr_moved->rr_moved_has_re_only)
+ /* Expose "rr_moved" entry. */
+ cache_add_entry(iso9660, iso9660->rr_moved);
+ while ((re = re_get_entry(iso9660)) != NULL) {
+ /* Expose its descendant dirs. */
+ while ((d = rede_get_entry(re)) != NULL)
+ cache_add_entry(iso9660, d);
+ }
+ if (iso9660->cache_files.first != NULL)
+ return (next_cache_entry(a, iso9660, pfile));
+ return (ARCHIVE_EOF);
+ }
+
+ if (file->cl_offset) {
+ struct file_info *first_re = NULL;
+ int nexted_re = 0;
+
+ /*
+ * Find "RE" dir for the current file, which
+ * has "CL" flag.
+ */
+ while ((re = re_get_entry(iso9660))
+ != first_re) {
+ if (first_re == NULL)
+ first_re = re;
+ if (re->offset == file->cl_offset) {
+ re->parent->subdirs--;
+ re->parent = file->parent;
+ re->re = 0;
+ if (re->parent->re_descendant) {
+ nexted_re = 1;
+ re->re_descendant = 1;
+ if (rede_add_entry(re) < 0)
+ goto fatal_rr;
+ /* Move a list of descendants
+ * to a new ancestor. */
+ while ((d = rede_get_entry(
+ re)) != NULL)
+ if (rede_add_entry(d)
+ < 0)
+ goto fatal_rr;
+ break;
+ }
+ /* Replace the current file
+ * with "RE" dir */
+ *pfile = file = re;
+ /* Expose its descendant */
+ while ((d = rede_get_entry(
+ file)) != NULL)
+ cache_add_entry(
+ iso9660, d);
+ break;
+ } else
+ re_add_entry(iso9660, re);
+ }
+ if (nexted_re) {
+ /*
+ * Do not expose this at this time
+ * because we have not gotten its full-path
+ * name yet.
+ */
+ continue;
+ }
+ } else if ((file->mode & AE_IFMT) == AE_IFDIR) {
+ int r;
+
+ /* Read file entries in this dir. */
+ r = read_children(a, file);
+ if (r != ARCHIVE_OK)
+ return (r);
+
+ /*
+ * Handle a special dir of Rockridge extensions,
+ * "rr_moved".
+ */
+ if (file->rr_moved) {
+ /*
+ * If this has only the subdirectories which
+ * have "RE" flags, do not expose at this time.
+ */
+ if (file->rr_moved_has_re_only)
+ continue;
+ /* Otherwise expose "rr_moved" entry. */
+ } else if (file->re) {
+ /*
+ * Do not expose this at this time
+ * because we have not gotten its full-path
+ * name yet.
+ */
+ re_add_entry(iso9660, file);
+ continue;
+ } else if (file->re_descendant) {
+ /*
+ * If the top level "RE" entry of this entry
+ * is not exposed, we, accordingly, should not
+ * expose this entry at this time because
+ * we cannot make its proper full-path name.
+ */
+ if (rede_add_entry(file) == 0)
+ continue;
+ /* Otherwise we can expose this entry because
+ * it seems its top level "RE" has already been
+ * exposed. */
+ }
+ }
+ break;
+ }
+
+ if ((file->mode & AE_IFMT) != AE_IFREG || file->number == -1)
+ return (ARCHIVE_OK);
+
+ count = 0;
+ number = file->number;
+ iso9660->cache_files.first = NULL;
+ iso9660->cache_files.last = &(iso9660->cache_files.first);
+ empty_files.first = NULL;
+ empty_files.last = &empty_files.first;
+ /* Collect files which has the same file serial number.
+ * Peek pending_files so that file which number is different
+ * is not put bak. */
+ while (iso9660->pending_files.used > 0 &&
+ (iso9660->pending_files.files[0]->number == -1 ||
+ iso9660->pending_files.files[0]->number == number)) {
+ if (file->number == -1) {
+ /* This file has the same offset
+ * but it's wrong offset which empty files
+ * and symlink files have.
+ * NOTE: This wrong offse was recorded by
+ * old mkisofs utility. If ISO images is
+ * created by latest mkisofs, this does not
+ * happen.
+ */
+ file->next = NULL;
+ *empty_files.last = file;
+ empty_files.last = &(file->next);
+ } else {
+ count++;
+ cache_add_entry(iso9660, file);
+ }
+ file = next_entry(iso9660);
+ }
+
+ if (count == 0) {
+ *pfile = file;
+ return ((file == NULL)?ARCHIVE_EOF:ARCHIVE_OK);
+ }
+ if (file->number == -1) {
+ file->next = NULL;
+ *empty_files.last = file;
+ empty_files.last = &(file->next);
+ } else {
+ count++;
+ cache_add_entry(iso9660, file);
+ }
+
+ if (count > 1) {
+ /* The count is the same as number of hardlink,
+ * so much so that each nlinks of files in cache_file
+ * is overwritten by value of the count.
+ */
+ for (file = iso9660->cache_files.first;
+ file != NULL; file = file->next)
+ file->nlinks = count;
+ }
+ /* If there are empty files, that files are added
+ * to the tail of the cache_files. */
+ if (empty_files.first != NULL) {
+ *iso9660->cache_files.last = empty_files.first;
+ iso9660->cache_files.last = empty_files.last;
+ }
+ *pfile = cache_get_entry(iso9660);
+ return ((*pfile == NULL)?ARCHIVE_EOF:ARCHIVE_OK);
+
+fatal_rr:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to connect 'CL' pointer to 'RE' rr_moved pointer of "
+ "Rockridge extensions: current position = %jd, CL offset = %jd",
+ (intmax_t)iso9660->current_position, (intmax_t)file->cl_offset);
+ return (ARCHIVE_FATAL);
+}
+
+static inline void
+re_add_entry(struct iso9660 *iso9660, struct file_info *file)
+{
+ file->re_next = NULL;
+ *iso9660->re_files.last = file;
+ iso9660->re_files.last = &(file->re_next);
+}
+
+static inline struct file_info *
+re_get_entry(struct iso9660 *iso9660)
+{
+ struct file_info *file;
+
+ if ((file = iso9660->re_files.first) != NULL) {
+ iso9660->re_files.first = file->re_next;
+ if (iso9660->re_files.first == NULL)
+ iso9660->re_files.last =
+ &(iso9660->re_files.first);
+ }
+ return (file);
+}
+
+static inline int
+rede_add_entry(struct file_info *file)
+{
+ struct file_info *re;
+
+ /*
+ * Find "RE" entry.
+ */
+ re = file->parent;
+ while (re != NULL && !re->re)
+ re = re->parent;
+ if (re == NULL)
+ return (-1);
+
+ file->re_next = NULL;
+ *re->rede_files.last = file;
+ re->rede_files.last = &(file->re_next);
+ return (0);
+}
+
+static inline struct file_info *
+rede_get_entry(struct file_info *re)
+{
+ struct file_info *file;
+
+ if ((file = re->rede_files.first) != NULL) {
+ re->rede_files.first = file->re_next;
+ if (re->rede_files.first == NULL)
+ re->rede_files.last =
+ &(re->rede_files.first);
+ }
+ return (file);
+}
+
+static inline void
+cache_add_entry(struct iso9660 *iso9660, struct file_info *file)
+{
+ file->next = NULL;
+ *iso9660->cache_files.last = file;
+ iso9660->cache_files.last = &(file->next);
+}
+
+static inline struct file_info *
+cache_get_entry(struct iso9660 *iso9660)
+{
+ struct file_info *file;
+
+ if ((file = iso9660->cache_files.first) != NULL) {
+ iso9660->cache_files.first = file->next;
+ if (iso9660->cache_files.first == NULL)
+ iso9660->cache_files.last =
+ &(iso9660->cache_files.first);
+ }
+ return (file);
+}
+
+static int
+heap_add_entry(struct archive_read *a, struct heap_queue *heap,
+ struct file_info *file, uint64_t key)
+{
+ uint64_t file_key, parent_key;
+ int hole, parent;
+
+ /* Expand our pending files list as necessary. */
+ if (heap->used >= heap->allocated) {
+ struct file_info **new_pending_files;
+ int new_size = heap->allocated * 2;
+
+ if (heap->allocated < 1024)
+ new_size = 1024;
+ /* Overflow might keep us from growing the list. */
+ if (new_size <= heap->allocated) {
+ archive_set_error(&a->archive,
+ ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ new_pending_files = (struct file_info **)
+ malloc(new_size * sizeof(new_pending_files[0]));
+ if (new_pending_files == NULL) {
+ archive_set_error(&a->archive,
+ ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(new_pending_files, heap->files,
+ heap->allocated * sizeof(new_pending_files[0]));
+ if (heap->files != NULL)
+ free(heap->files);
+ heap->files = new_pending_files;
+ heap->allocated = new_size;
+ }
+
+ file_key = file->key = key;
+
+ /*
+ * Start with hole at end, walk it up tree to find insertion point.
+ */
+ hole = heap->used++;
+ while (hole > 0) {
+ parent = (hole - 1)/2;
+ parent_key = heap->files[parent]->key;
+ if (file_key >= parent_key) {
+ heap->files[hole] = file;
+ return (ARCHIVE_OK);
+ }
+ /* Move parent into hole <==> move hole up tree. */
+ heap->files[hole] = heap->files[parent];
+ hole = parent;
+ }
+ heap->files[0] = file;
+
+ return (ARCHIVE_OK);
+}
+
+static struct file_info *
+heap_get_entry(struct heap_queue *heap)
+{
+ uint64_t a_key, b_key, c_key;
+ int a, b, c;
+ struct file_info *r, *tmp;
+
+ if (heap->used < 1)
+ return (NULL);
+
+ /*
+ * The first file in the list is the earliest; we'll return this.
+ */
+ r = heap->files[0];
+
+ /*
+ * Move the last item in the heap to the root of the tree
+ */
+ heap->files[0] = heap->files[--(heap->used)];
+
+ /*
+ * Rebalance the heap.
+ */
+ a = 0; /* Starting element and its heap key */
+ a_key = heap->files[a]->key;
+ for (;;) {
+ b = a + a + 1; /* First child */
+ if (b >= heap->used)
+ return (r);
+ b_key = heap->files[b]->key;
+ c = b + 1; /* Use second child if it is smaller. */
+ if (c < heap->used) {
+ c_key = heap->files[c]->key;
+ if (c_key < b_key) {
+ b = c;
+ b_key = c_key;
+ }
+ }
+ if (a_key <= b_key)
+ return (r);
+ tmp = heap->files[a];
+ heap->files[a] = heap->files[b];
+ heap->files[b] = tmp;
+ a = b;
+ }
+}
+
+static unsigned int
+toi(const void *p, int n)
+{
+ const unsigned char *v = (const unsigned char *)p;
+ if (n > 1)
+ return v[0] + 256 * toi(v + 1, n - 1);
+ if (n == 1)
+ return v[0];
+ return (0);
+}
+
+static time_t
+isodate7(const unsigned char *v)
+{
+ struct tm tm;
+ int offset;
+ time_t t;
+
+ memset(&tm, 0, sizeof(tm));
+ tm.tm_year = v[0];
+ tm.tm_mon = v[1] - 1;
+ tm.tm_mday = v[2];
+ tm.tm_hour = v[3];
+ tm.tm_min = v[4];
+ tm.tm_sec = v[5];
+ /* v[6] is the signed timezone offset, in 1/4-hour increments. */
+ offset = ((const signed char *)v)[6];
+ if (offset > -48 && offset < 52) {
+ tm.tm_hour -= offset / 4;
+ tm.tm_min -= (offset % 4) * 15;
+ }
+ t = time_from_tm(&tm);
+ if (t == (time_t)-1)
+ return ((time_t)0);
+ return (t);
+}
+
+static time_t
+isodate17(const unsigned char *v)
+{
+ struct tm tm;
+ int offset;
+ time_t t;
+
+ memset(&tm, 0, sizeof(tm));
+ tm.tm_year = (v[0] - '0') * 1000 + (v[1] - '0') * 100
+ + (v[2] - '0') * 10 + (v[3] - '0')
+ - 1900;
+ tm.tm_mon = (v[4] - '0') * 10 + (v[5] - '0');
+ tm.tm_mday = (v[6] - '0') * 10 + (v[7] - '0');
+ tm.tm_hour = (v[8] - '0') * 10 + (v[9] - '0');
+ tm.tm_min = (v[10] - '0') * 10 + (v[11] - '0');
+ tm.tm_sec = (v[12] - '0') * 10 + (v[13] - '0');
+ /* v[16] is the signed timezone offset, in 1/4-hour increments. */
+ offset = ((const signed char *)v)[16];
+ if (offset > -48 && offset < 52) {
+ tm.tm_hour -= offset / 4;
+ tm.tm_min -= (offset % 4) * 15;
+ }
+ t = time_from_tm(&tm);
+ if (t == (time_t)-1)
+ return ((time_t)0);
+ return (t);
+}
+
+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 const char *
+build_pathname(struct archive_string *as, struct file_info *file)
+{
+ if (file->parent != NULL && archive_strlen(&file->parent->name) > 0) {
+ build_pathname(as, file->parent);
+ archive_strcat(as, "/");
+ }
+ if (archive_strlen(&file->name) == 0)
+ archive_strcat(as, ".");
+ else
+ archive_string_concat(as, &file->name);
+ return (as->s);
+}
+
+static int
+build_pathname_utf16be(unsigned char *p, size_t max, size_t *len,
+ struct file_info *file)
+{
+ if (file->parent != NULL && file->parent->utf16be_bytes > 0) {
+ if (build_pathname_utf16be(p, max, len, file->parent) != 0)
+ return (-1);
+ p[*len] = 0;
+ p[*len + 1] = '/';
+ *len += 2;
+ }
+ if (file->utf16be_bytes == 0) {
+ if (*len + 2 > max)
+ return (-1);/* Path is too long! */
+ p[*len] = 0;
+ p[*len + 1] = '.';
+ *len += 2;
+ } else {
+ if (*len + file->utf16be_bytes > max)
+ return (-1);/* Path is too long! */
+ memcpy(p + *len, file->utf16be_name, file->utf16be_bytes);
+ *len += file->utf16be_bytes;
+ }
+ return (0);
+}
+
+#if DEBUG
+static void
+dump_isodirrec(FILE *out, const unsigned char *isodirrec)
+{
+ fprintf(out, " l %d,",
+ toi(isodirrec + DR_length_offset, DR_length_size));
+ fprintf(out, " a %d,",
+ toi(isodirrec + DR_ext_attr_length_offset, DR_ext_attr_length_size));
+ fprintf(out, " ext 0x%x,",
+ toi(isodirrec + DR_extent_offset, DR_extent_size));
+ fprintf(out, " s %d,",
+ toi(isodirrec + DR_size_offset, DR_extent_size));
+ fprintf(out, " f 0x%x,",
+ toi(isodirrec + DR_flags_offset, DR_flags_size));
+ fprintf(out, " u %d,",
+ toi(isodirrec + DR_file_unit_size_offset, DR_file_unit_size_size));
+ fprintf(out, " ilv %d,",
+ toi(isodirrec + DR_interleave_offset, DR_interleave_size));
+ fprintf(out, " seq %d,",
+ toi(isodirrec + DR_volume_sequence_number_offset,
+ DR_volume_sequence_number_size));
+ fprintf(out, " nl %d:",
+ toi(isodirrec + DR_name_len_offset, DR_name_len_size));
+ fprintf(out, " `%.*s'",
+ toi(isodirrec + DR_name_len_offset, DR_name_len_size),
+ isodirrec + DR_name_offset);
+}
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c
new file mode 100644
index 0000000000..b88731afa8
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c
@@ -0,0 +1,2750 @@
+/*-
+ * Copyright (c) 2008-2012 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_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+#include "archive_endian.h"
+
+
+#define MAXMATCH 256 /* Maximum match length. */
+#define MINMATCH 3 /* Minimum match length. */
+/*
+ * Literal table format:
+ * +0 +256 +510
+ * +---------------+-------------------------+
+ * | literal code | match length |
+ * | 0 ... 255 | MINMATCH ... MAXMATCH |
+ * +---------------+-------------------------+
+ * <--- LT_BITLEN_SIZE --->
+ */
+/* Literal table size. */
+#define LT_BITLEN_SIZE (UCHAR_MAX + 1 + MAXMATCH - MINMATCH + 1)
+/* Position table size.
+ * Note: this used for both position table and pre literal table.*/
+#define PT_BITLEN_SIZE (3 + 16)
+
+struct lzh_dec {
+ /* Decoding status. */
+ int state;
+
+ /*
+ * Window to see last 8Ki(lh5),32Ki(lh6),64Ki(lh7) bytes of decoded
+ * data.
+ */
+ int w_size;
+ int w_mask;
+ /* Window buffer, which is a loop buffer. */
+ unsigned char *w_buff;
+ /* The insert position to the window. */
+ int w_pos;
+ /* The position where we can copy decoded code from the window. */
+ int copy_pos;
+ /* 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.
+ */
+ struct lzh_br {
+#define CACHE_TYPE uint64_t
+#define CACHE_BITS (8 * sizeof(CACHE_TYPE))
+ /* Cache buffer. */
+ CACHE_TYPE cache_buffer;
+ /* Indicates how many bits avail in cache_buffer. */
+ int cache_avail;
+ } br;
+
+ /*
+ * Huffman coding.
+ */
+ struct huffman {
+ int len_size;
+ int len_avail;
+ int len_bits;
+ int freq[17];
+ unsigned char *bitlen;
+
+ /*
+ * Use a index table. It's faster than searching a huffman
+ * coding tree, which is a binary tree. But a use of a large
+ * index table causes L1 cache read miss many times.
+ */
+#define HTBL_BITS 10
+ int max_bits;
+ int shift_bits;
+ int tbl_bits;
+ int tree_used;
+ int tree_avail;
+ /* Direct access table. */
+ uint16_t *tbl;
+ /* Binary tree table for extra bits over the direct access. */
+ struct htree_t {
+ uint16_t left;
+ uint16_t right;
+ } *tree;
+ } lt, pt;
+
+ int blocks_avail;
+ int pos_pt_len_size;
+ int pos_pt_len_bits;
+ int literal_pt_len_size;
+ int literal_pt_len_bits;
+ int reading_position;
+ int loop;
+ int error;
+};
+
+struct lzh_stream {
+ const unsigned char *next_in;
+ int64_t avail_in;
+ int64_t total_in;
+ unsigned char *next_out;
+ int64_t avail_out;
+ int64_t total_out;
+ struct lzh_dec *ds;
+};
+
+struct lha {
+ /* entry_bytes_remaining is the number of bytes we expect. */
+ int64_t entry_offset;
+ int64_t entry_bytes_remaining;
+ int64_t entry_unconsumed;
+ uint16_t entry_crc_calculated;
+
+ size_t header_size; /* header size */
+ unsigned char level; /* header level */
+ char method[3]; /* compress type */
+ int64_t compsize; /* compressed data size */
+ int64_t origsize; /* original file size */
+ int setflag;
+#define BIRTHTIME_IS_SET 1
+#define ATIME_IS_SET 2
+#define UNIX_MODE_IS_SET 4
+#define CRC_IS_SET 8
+ time_t birthtime;
+ long birthtime_tv_nsec;
+ time_t mtime;
+ long mtime_tv_nsec;
+ time_t atime;
+ long atime_tv_nsec;
+ mode_t mode;
+ int64_t uid;
+ int64_t gid;
+ struct archive_string uname;
+ struct archive_string gname;
+ uint16_t header_crc;
+ uint16_t crc;
+ struct archive_string_conv *sconv;
+ struct archive_string_conv *opt_sconv;
+
+ struct archive_string dirname;
+ struct archive_string filename;
+ struct archive_wstring ws;
+
+ unsigned char dos_attr;
+
+ /* Flag to mark progress that an archive was read their first header.*/
+ char found_first_header;
+ /* Flag to mark that indicates an empty directory. */
+ char directory;
+
+ /* Flags to mark progress of decompression. */
+ char decompress_init;
+ char end_of_entry;
+ 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;
+};
+
+/*
+ * LHA header common member offset.
+ */
+#define H_METHOD_OFFSET 2 /* Compress type. */
+#define H_ATTR_OFFSET 19 /* DOS attribute. */
+#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 *);
+static int archive_read_format_lha_read_header(struct archive_read *,
+ struct archive_entry *);
+static int archive_read_format_lha_read_data(struct archive_read *,
+ const void **, size_t *, int64_t *);
+static int archive_read_format_lha_read_data_skip(struct archive_read *);
+static int archive_read_format_lha_cleanup(struct archive_read *);
+
+static void lha_replace_path_separator(struct lha *,
+ struct archive_entry *);
+static int lha_read_file_header_0(struct archive_read *, struct lha *);
+static int lha_read_file_header_1(struct archive_read *, struct lha *);
+static int lha_read_file_header_2(struct archive_read *, struct lha *);
+static int lha_read_file_header_3(struct archive_read *, struct lha *);
+static int lha_read_file_extended_header(struct archive_read *,
+ struct lha *, uint16_t *, int, size_t, size_t *);
+static size_t lha_check_header_format(const void *);
+static int lha_skip_sfx(struct archive_read *);
+static time_t lha_dos_time(const unsigned char *);
+static time_t lha_win_time(uint64_t, long *);
+static unsigned char lha_calcsum(unsigned char, const void *,
+ int, size_t);
+static int lha_parse_linkname(struct archive_string *,
+ struct archive_string *);
+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 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 *);
+static int lzh_decode(struct lzh_stream *, int);
+static int lzh_br_fillup(struct lzh_stream *, struct lzh_br *);
+static int lzh_huffman_init(struct huffman *, size_t, int);
+static void lzh_huffman_free(struct huffman *);
+static int lzh_read_pt_bitlen(struct lzh_stream *, int start, int end);
+static int lzh_make_fake_table(struct huffman *, uint16_t);
+static int lzh_make_huffman_table(struct huffman *);
+static inline int lzh_decode_huffman(struct huffman *, unsigned);
+static int lzh_decode_huffman_tree(struct huffman *, unsigned, int);
+
+
+int
+archive_read_support_format_lha(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct lha *lha;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_lha");
+
+ lha = (struct lha *)calloc(1, sizeof(*lha));
+ if (lha == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate lha data");
+ return (ARCHIVE_FATAL);
+ }
+ archive_string_init(&lha->ws);
+
+ r = __archive_read_register_format(a,
+ lha,
+ "lha",
+ archive_read_format_lha_bid,
+ archive_read_format_lha_options,
+ archive_read_format_lha_read_header,
+ archive_read_format_lha_read_data,
+ archive_read_format_lha_read_data_skip,
+ NULL,
+ archive_read_format_lha_cleanup,
+ NULL,
+ NULL);
+
+ if (r != ARCHIVE_OK)
+ free(lha);
+ return (ARCHIVE_OK);
+}
+
+static size_t
+lha_check_header_format(const void *h)
+{
+ const unsigned char *p = h;
+ size_t next_skip_bytes;
+
+ switch (p[H_METHOD_OFFSET+3]) {
+ /*
+ * "-lh0-" ... "-lh7-" "-lhd-"
+ * "-lzs-" "-lz5-"
+ */
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ case 'd':
+ case 's':
+ next_skip_bytes = 4;
+
+ /* b0 == 0 means the end of an LHa archive file. */
+ if (p[0] == 0)
+ break;
+ if (p[H_METHOD_OFFSET] != '-' || p[H_METHOD_OFFSET+1] != 'l'
+ || p[H_METHOD_OFFSET+4] != '-')
+ break;
+
+ if (p[H_METHOD_OFFSET+2] == 'h') {
+ /* "-lh?-" */
+ if (p[H_METHOD_OFFSET+3] == 's')
+ break;
+ if (p[H_LEVEL_OFFSET] == 0)
+ return (0);
+ if (p[H_LEVEL_OFFSET] <= 3 && p[H_ATTR_OFFSET] == 0x20)
+ return (0);
+ }
+ if (p[H_METHOD_OFFSET+2] == 'z') {
+ /* LArc extensions: -lzs-,-lz4- and -lz5- */
+ if (p[H_LEVEL_OFFSET] != 0)
+ break;
+ if (p[H_METHOD_OFFSET+3] == 's'
+ || p[H_METHOD_OFFSET+3] == '4'
+ || p[H_METHOD_OFFSET+3] == '5')
+ return (0);
+ }
+ break;
+ case 'h': next_skip_bytes = 1; break;
+ case 'z': next_skip_bytes = 1; break;
+ case 'l': next_skip_bytes = 2; break;
+ case '-': next_skip_bytes = 3; break;
+ default : next_skip_bytes = 4; break;
+ }
+
+ return (next_skip_bytes);
+}
+
+static int
+archive_read_format_lha_bid(struct archive_read *a, int best_bid)
+{
+ const char *p;
+ const void *buff;
+ ssize_t bytes_avail, offset, window;
+ size_t next;
+
+ /* If there's already a better bid than we can ever
+ make, don't bother testing. */
+ if (best_bid > 30)
+ return (-1);
+
+ if ((p = __archive_read_ahead(a, H_SIZE, NULL)) == NULL)
+ return (-1);
+
+ if (lha_check_header_format(p) == 0)
+ return (30);
+
+ if (p[0] == 'M' && p[1] == 'Z') {
+ /* PE file */
+ offset = 0;
+ window = 4096;
+ while (offset < (1024 * 20)) {
+ buff = __archive_read_ahead(a, offset + window,
+ &bytes_avail);
+ if (buff == NULL) {
+ /* Remaining bytes are less than window. */
+ window >>= 1;
+ if (window < (H_SIZE + 3))
+ return (0);
+ continue;
+ }
+ p = (const char *)buff + offset;
+ while (p + H_SIZE < (const char *)buff + bytes_avail) {
+ if ((next = lha_check_header_format(p)) == 0)
+ return (30);
+ p += next;
+ }
+ offset = p - (const char *)buff;
+ }
+ }
+ return (0);
+}
+
+static int
+archive_read_format_lha_options(struct archive_read *a,
+ const char *key, const char *val)
+{
+ struct lha *lha;
+ int ret = ARCHIVE_FAILED;
+
+ lha = (struct lha *)(a->format->data);
+ if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "lha: hdrcharset option needs a character-set name");
+ else {
+ lha->opt_sconv =
+ archive_string_conversion_from_charset(
+ &a->archive, val, 0);
+ if (lha->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ }
+
+ /* 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
+lha_skip_sfx(struct archive_read *a)
+{
+ const void *h;
+ const char *p, *q;
+ size_t next, skip;
+ ssize_t bytes, window;
+
+ window = 4096;
+ for (;;) {
+ h = __archive_read_ahead(a, window, &bytes);
+ if (h == NULL) {
+ /* Remaining bytes are less than window. */
+ window >>= 1;
+ if (window < (H_SIZE + 3))
+ goto fatal;
+ continue;
+ }
+ if (bytes < H_SIZE)
+ goto fatal;
+ p = h;
+ q = p + bytes;
+
+ /*
+ * Scan ahead until we find something that looks
+ * like the lha header.
+ */
+ while (p + H_SIZE < q) {
+ if ((next = lha_check_header_format(p)) == 0) {
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ return (ARCHIVE_OK);
+ }
+ p += next;
+ }
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ }
+fatal:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Couldn't find out LHa header");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+truncated_error(struct archive_read *a)
+{
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated LHa header");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+archive_read_format_lha_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ struct archive_string linkname;
+ struct archive_string pathname;
+ struct lha *lha;
+ const unsigned char *p;
+ const char *signature;
+ int err;
+
+ a->archive.archive_format = ARCHIVE_FORMAT_LHA;
+ if (a->archive.archive_format_name == NULL)
+ a->archive.archive_format_name = "lha";
+
+ lha = (struct lha *)(a->format->data);
+ lha->decompress_init = 0;
+ lha->end_of_entry = 0;
+ lha->end_of_entry_cleanup = 0;
+ lha->entry_unconsumed = 0;
+
+ if ((p = __archive_read_ahead(a, H_SIZE, NULL)) == NULL) {
+ /*
+ * LHa archiver added 0 to the tail of its archive file as
+ * the mark of the end of the archive.
+ */
+ signature = __archive_read_ahead(a, sizeof(signature[0]), NULL);
+ if (signature == NULL || signature[0] == 0)
+ return (ARCHIVE_EOF);
+ return (truncated_error(a));
+ }
+
+ signature = (const char *)p;
+ if (lha->found_first_header == 0 &&
+ signature[0] == 'M' && signature[1] == 'Z') {
+ /* This is an executable? Must be self-extracting... */
+ err = lha_skip_sfx(a);
+ if (err < ARCHIVE_WARN)
+ return (err);
+
+ if ((p = __archive_read_ahead(a, sizeof(*p), NULL)) == NULL)
+ return (truncated_error(a));
+ signature = (const char *)p;
+ }
+ /* signature[0] == 0 means the end of an LHa archive file. */
+ if (signature[0] == 0)
+ return (ARCHIVE_EOF);
+
+ /*
+ * Check the header format and method type.
+ */
+ if (lha_check_header_format(p) != 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Bad LHa file");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* We've found the first header. */
+ lha->found_first_header = 1;
+ /* Set a default value and common data */
+ lha->header_size = 0;
+ lha->level = p[H_LEVEL_OFFSET];
+ lha->method[0] = p[H_METHOD_OFFSET+1];
+ lha->method[1] = p[H_METHOD_OFFSET+2];
+ lha->method[2] = p[H_METHOD_OFFSET+3];
+ if (memcmp(lha->method, "lhd", 3) == 0)
+ lha->directory = 1;
+ else
+ lha->directory = 0;
+ if (memcmp(lha->method, "lh0", 3) == 0 ||
+ memcmp(lha->method, "lz4", 3) == 0)
+ lha->entry_is_compressed = 0;
+ else
+ lha->entry_is_compressed = 1;
+
+ lha->compsize = 0;
+ lha->origsize = 0;
+ lha->setflag = 0;
+ lha->birthtime = 0;
+ lha->birthtime_tv_nsec = 0;
+ lha->mtime = 0;
+ lha->mtime_tv_nsec = 0;
+ lha->atime = 0;
+ lha->atime_tv_nsec = 0;
+ lha->mode = (lha->directory)? 0777 : 0666;
+ lha->uid = 0;
+ lha->gid = 0;
+ archive_string_empty(&lha->dirname);
+ archive_string_empty(&lha->filename);
+ lha->dos_attr = 0;
+ if (lha->opt_sconv != NULL)
+ lha->sconv = lha->opt_sconv;
+ else
+ lha->sconv = NULL;
+
+ switch (p[H_LEVEL_OFFSET]) {
+ case 0:
+ err = lha_read_file_header_0(a, lha);
+ break;
+ case 1:
+ err = lha_read_file_header_1(a, lha);
+ break;
+ case 2:
+ err = lha_read_file_header_2(a, lha);
+ break;
+ case 3:
+ err = lha_read_file_header_3(a, lha);
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unsupported LHa header level %d", p[H_LEVEL_OFFSET]);
+ err = ARCHIVE_FATAL;
+ break;
+ }
+ if (err < ARCHIVE_WARN)
+ return (err);
+
+
+ if (!lha->directory && archive_strlen(&lha->filename) == 0)
+ /* The filename has not been set */
+ return (truncated_error(a));
+
+ /*
+ * Make a pathname from a dirname and a filename.
+ */
+ archive_string_concat(&lha->dirname, &lha->filename);
+ archive_string_init(&pathname);
+ archive_string_init(&linkname);
+ archive_string_copy(&pathname, &lha->dirname);
+
+ if ((lha->mode & AE_IFMT) == AE_IFLNK) {
+ /*
+ * Extract the symlink-name if it's included in the pathname.
+ */
+ if (!lha_parse_linkname(&linkname, &pathname)) {
+ /* We couldn't get the symlink-name. */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unknown symlink-name");
+ archive_string_free(&pathname);
+ archive_string_free(&linkname);
+ return (ARCHIVE_FAILED);
+ }
+ } else {
+ /*
+ * Make sure a file-type is set.
+ * The mode has been overridden if it is in the extended data.
+ */
+ lha->mode = (lha->mode & ~AE_IFMT) |
+ ((lha->directory)? AE_IFDIR: AE_IFREG);
+ }
+ if ((lha->setflag & UNIX_MODE_IS_SET) == 0 &&
+ (lha->dos_attr & 1) != 0)
+ lha->mode &= ~(0222);/* read only. */
+
+ /*
+ * Set basic file parameters.
+ */
+ if (archive_entry_copy_pathname_l(entry, pathname.s,
+ pathname.length, lha->sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Pathname cannot be converted "
+ "from %s to current locale.",
+ archive_string_conversion_charset_name(lha->sconv));
+ err = ARCHIVE_WARN;
+ }
+ archive_string_free(&pathname);
+ if (archive_strlen(&linkname) > 0) {
+ if (archive_entry_copy_symlink_l(entry, linkname.s,
+ linkname.length, lha->sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Linkname cannot be converted "
+ "from %s to current locale.",
+ archive_string_conversion_charset_name(lha->sconv));
+ err = ARCHIVE_WARN;
+ }
+ } else
+ archive_entry_set_symlink(entry, NULL);
+ archive_string_free(&linkname);
+ /*
+ * When a header level is 0, there is a possibility that
+ * a pathname and a symlink has '\' character, a directory
+ * separator in DOS/Windows. So we should convert it to '/'.
+ */
+ if (p[H_LEVEL_OFFSET] == 0)
+ lha_replace_path_separator(lha, entry);
+
+ archive_entry_set_mode(entry, lha->mode);
+ archive_entry_set_uid(entry, lha->uid);
+ archive_entry_set_gid(entry, lha->gid);
+ if (archive_strlen(&lha->uname) > 0)
+ archive_entry_set_uname(entry, lha->uname.s);
+ if (archive_strlen(&lha->gname) > 0)
+ archive_entry_set_gname(entry, lha->gname.s);
+ if (lha->setflag & BIRTHTIME_IS_SET) {
+ archive_entry_set_birthtime(entry, lha->birthtime,
+ lha->birthtime_tv_nsec);
+ archive_entry_set_ctime(entry, lha->birthtime,
+ lha->birthtime_tv_nsec);
+ } else {
+ archive_entry_unset_birthtime(entry);
+ archive_entry_unset_ctime(entry);
+ }
+ archive_entry_set_mtime(entry, lha->mtime, lha->mtime_tv_nsec);
+ if (lha->setflag & ATIME_IS_SET)
+ archive_entry_set_atime(entry, lha->atime,
+ lha->atime_tv_nsec);
+ else
+ archive_entry_unset_atime(entry);
+ if (lha->directory || archive_entry_symlink(entry) != NULL)
+ archive_entry_unset_size(entry);
+ else
+ archive_entry_set_size(entry, lha->origsize);
+
+ /*
+ * Prepare variables used to read a file content.
+ */
+ lha->entry_bytes_remaining = lha->compsize;
+ lha->entry_offset = 0;
+ lha->entry_crc_calculated = 0;
+
+ /*
+ * This file does not have a content.
+ */
+ if (lha->directory || lha->compsize == 0)
+ lha->end_of_entry = 1;
+
+ sprintf(lha->format_name, "lha -%c%c%c-",
+ lha->method[0], lha->method[1], lha->method[2]);
+ a->archive.archive_format_name = lha->format_name;
+
+ return (err);
+}
+
+/*
+ * Replace a DOS path separator '\' by a character '/'.
+ * Some multi-byte character set have a character '\' in its second byte.
+ */
+static void
+lha_replace_path_separator(struct lha *lha, struct archive_entry *entry)
+{
+ const wchar_t *wp;
+ size_t i;
+
+ if ((wp = archive_entry_pathname_w(entry)) != NULL) {
+ archive_wstrcpy(&(lha->ws), wp);
+ for (i = 0; i < archive_strlen(&(lha->ws)); i++) {
+ if (lha->ws.s[i] == L'\\')
+ lha->ws.s[i] = L'/';
+ }
+ archive_entry_copy_pathname_w(entry, lha->ws.s);
+ }
+
+ if ((wp = archive_entry_symlink_w(entry)) != NULL) {
+ archive_wstrcpy(&(lha->ws), wp);
+ for (i = 0; i < archive_strlen(&(lha->ws)); i++) {
+ if (lha->ws.s[i] == L'\\')
+ lha->ws.s[i] = L'/';
+ }
+ archive_entry_copy_symlink_w(entry, lha->ws.s);
+ }
+}
+
+/*
+ * Header 0 format
+ *
+ * +0 +1 +2 +7 +11
+ * +---------------+----------+----------------+-------------------+
+ * |header size(*1)|header sum|compression type|compressed size(*2)|
+ * +---------------+----------+----------------+-------------------+
+ * <---------------------(*1)----------*
+ *
+ * +11 +15 +17 +19 +20 +21
+ * +-----------------+---------+---------+--------------+----------------+
+ * |uncompressed size|time(DOS)|date(DOS)|attribute(DOS)|header level(=0)|
+ * +-----------------+---------+---------+--------------+----------------+
+ * *--------------------------------(*1)---------------------------------*
+ *
+ * +21 +22 +22+(*3) +22+(*3)+2 +22+(*3)+2+(*4)
+ * +---------------+---------+----------+----------------+------------------+
+ * |name length(*3)|file name|file CRC16|extra header(*4)| compressed data |
+ * +---------------+---------+----------+----------------+------------------+
+ * <--(*3)-> <------(*2)------>
+ * *----------------------(*1)-------------------------->
+ *
+ */
+#define H0_HEADER_SIZE_OFFSET 0
+#define H0_HEADER_SUM_OFFSET 1
+#define H0_COMP_SIZE_OFFSET 7
+#define H0_ORIG_SIZE_OFFSET 11
+#define H0_DOS_TIME_OFFSET 15
+#define H0_NAME_LEN_OFFSET 21
+#define H0_FILE_NAME_OFFSET 22
+#define H0_FIXED_SIZE 24
+static int
+lha_read_file_header_0(struct archive_read *a, struct lha *lha)
+{
+ const unsigned char *p;
+ int extdsize, namelen;
+ unsigned char headersum, sum_calculated;
+
+ if ((p = __archive_read_ahead(a, H0_FIXED_SIZE, NULL)) == NULL)
+ return (truncated_error(a));
+ lha->header_size = p[H0_HEADER_SIZE_OFFSET] + 2;
+ headersum = p[H0_HEADER_SUM_OFFSET];
+ lha->compsize = archive_le32dec(p + H0_COMP_SIZE_OFFSET);
+ lha->origsize = archive_le32dec(p + H0_ORIG_SIZE_OFFSET);
+ lha->mtime = lha_dos_time(p + H0_DOS_TIME_OFFSET);
+ namelen = p[H0_NAME_LEN_OFFSET];
+ extdsize = (int)lha->header_size - H0_FIXED_SIZE - namelen;
+ if ((namelen > 221 || extdsize < 0) && extdsize != -2) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid LHa header");
+ return (ARCHIVE_FATAL);
+ }
+ if ((p = __archive_read_ahead(a, lha->header_size, NULL)) == NULL)
+ return (truncated_error(a));
+
+ archive_strncpy(&lha->filename, p + H0_FILE_NAME_OFFSET, namelen);
+ /* When extdsize == -2, A CRC16 value is not present in the header. */
+ if (extdsize >= 0) {
+ lha->crc = archive_le16dec(p + H0_FILE_NAME_OFFSET + namelen);
+ lha->setflag |= CRC_IS_SET;
+ }
+ sum_calculated = lha_calcsum(0, p, 2, lha->header_size - 2);
+
+ /* Read an extended header */
+ if (extdsize > 0) {
+ /* This extended data is set by 'LHa for UNIX' only.
+ * Maybe fixed size.
+ */
+ p += H0_FILE_NAME_OFFSET + namelen + 2;
+ if (p[0] == 'U' && extdsize == 12) {
+ /* p[1] is a minor version. */
+ lha->mtime = archive_le32dec(&p[2]);
+ lha->mode = archive_le16dec(&p[6]);
+ lha->uid = archive_le16dec(&p[8]);
+ lha->gid = archive_le16dec(&p[10]);
+ lha->setflag |= UNIX_MODE_IS_SET;
+ }
+ }
+ __archive_read_consume(a, lha->header_size);
+
+ if (sum_calculated != headersum) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "LHa header sum error");
+ return (ARCHIVE_FATAL);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Header 1 format
+ *
+ * +0 +1 +2 +7 +11
+ * +---------------+----------+----------------+-------------+
+ * |header size(*1)|header sum|compression type|skip size(*2)|
+ * +---------------+----------+----------------+-------------+
+ * <---------------(*1)----------*
+ *
+ * +11 +15 +17 +19 +20 +21
+ * +-----------------+---------+---------+--------------+----------------+
+ * |uncompressed size|time(DOS)|date(DOS)|attribute(DOS)|header level(=1)|
+ * +-----------------+---------+---------+--------------+----------------+
+ * *-------------------------------(*1)----------------------------------*
+ *
+ * +21 +22 +22+(*3) +22+(*3)+2 +22+(*3)+3 +22+(*3)+3+(*4)
+ * +---------------+---------+----------+-----------+-----------+
+ * |name length(*3)|file name|file CRC16| creator |padding(*4)|
+ * +---------------+---------+----------+-----------+-----------+
+ * <--(*3)->
+ * *----------------------------(*1)----------------------------*
+ *
+ * +22+(*3)+3+(*4) +22+(*3)+3+(*4)+2 +22+(*3)+3+(*4)+2+(*5)
+ * +----------------+---------------------+------------------------+
+ * |next header size| extended header(*5) | compressed data |
+ * +----------------+---------------------+------------------------+
+ * *------(*1)-----> <--------------------(*2)-------------------->
+ */
+#define H1_HEADER_SIZE_OFFSET 0
+#define H1_HEADER_SUM_OFFSET 1
+#define H1_COMP_SIZE_OFFSET 7
+#define H1_ORIG_SIZE_OFFSET 11
+#define H1_DOS_TIME_OFFSET 15
+#define H1_NAME_LEN_OFFSET 21
+#define H1_FILE_NAME_OFFSET 22
+#define H1_FIXED_SIZE 27
+static int
+lha_read_file_header_1(struct archive_read *a, struct lha *lha)
+{
+ const unsigned char *p;
+ size_t extdsize;
+ int i, err, err2;
+ int namelen, padding;
+ unsigned char headersum, sum_calculated;
+
+ err = ARCHIVE_OK;
+
+ if ((p = __archive_read_ahead(a, H1_FIXED_SIZE, NULL)) == NULL)
+ return (truncated_error(a));
+
+ lha->header_size = p[H1_HEADER_SIZE_OFFSET] + 2;
+ headersum = p[H1_HEADER_SUM_OFFSET];
+ /* Note: An extended header size is included in a compsize. */
+ lha->compsize = archive_le32dec(p + H1_COMP_SIZE_OFFSET);
+ lha->origsize = archive_le32dec(p + H1_ORIG_SIZE_OFFSET);
+ lha->mtime = lha_dos_time(p + H1_DOS_TIME_OFFSET);
+ namelen = p[H1_NAME_LEN_OFFSET];
+ /* Calculate a padding size. The result will be normally 0 only(?) */
+ padding = ((int)lha->header_size) - H1_FIXED_SIZE - namelen;
+
+ if (namelen > 230 || padding < 0)
+ goto invalid;
+
+ if ((p = __archive_read_ahead(a, lha->header_size, NULL)) == NULL)
+ return (truncated_error(a));
+
+ for (i = 0; i < namelen; i++) {
+ if (p[i + H1_FILE_NAME_OFFSET] == 0xff)
+ goto invalid;/* Invalid filename. */
+ }
+ archive_strncpy(&lha->filename, p + H1_FILE_NAME_OFFSET, namelen);
+ lha->crc = archive_le16dec(p + H1_FILE_NAME_OFFSET + namelen);
+ lha->setflag |= CRC_IS_SET;
+
+ sum_calculated = lha_calcsum(0, p, 2, lha->header_size - 2);
+ /* Consume used bytes but not include `next header size' data
+ * since it will be consumed in lha_read_file_extended_header(). */
+ __archive_read_consume(a, lha->header_size - 2);
+
+ /* Read extended headers */
+ err2 = lha_read_file_extended_header(a, lha, NULL, 2,
+ (size_t)(lha->compsize + 2), &extdsize);
+ if (err2 < ARCHIVE_WARN)
+ return (err2);
+ if (err2 < err)
+ err = err2;
+ /* Get a real compressed file size. */
+ lha->compsize -= extdsize - 2;
+
+ if (sum_calculated != headersum) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "LHa header sum error");
+ return (ARCHIVE_FATAL);
+ }
+ return (err);
+invalid:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid LHa header");
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Header 2 format
+ *
+ * +0 +2 +7 +11 +15
+ * +---------------+----------------+-------------------+-----------------+
+ * |header size(*1)|compression type|compressed size(*2)|uncompressed size|
+ * +---------------+----------------+-------------------+-----------------+
+ * <--------------------------------(*1)---------------------------------*
+ *
+ * +15 +19 +20 +21 +23 +24
+ * +-----------------+------------+----------------+----------+-----------+
+ * |data/time(time_t)| 0x20 fixed |header level(=2)|file CRC16| creator |
+ * +-----------------+------------+----------------+----------+-----------+
+ * *---------------------------------(*1)---------------------------------*
+ *
+ * +24 +26 +26+(*3) +26+(*3)+(*4)
+ * +----------------+-------------------+-------------+-------------------+
+ * |next header size|extended header(*3)| padding(*4) | compressed data |
+ * +----------------+-------------------+-------------+-------------------+
+ * *--------------------------(*1)-------------------> <------(*2)------->
+ *
+ */
+#define H2_HEADER_SIZE_OFFSET 0
+#define H2_COMP_SIZE_OFFSET 7
+#define H2_ORIG_SIZE_OFFSET 11
+#define H2_TIME_OFFSET 15
+#define H2_CRC_OFFSET 21
+#define H2_FIXED_SIZE 24
+static int
+lha_read_file_header_2(struct archive_read *a, struct lha *lha)
+{
+ const unsigned char *p;
+ size_t extdsize;
+ int err, padding;
+ uint16_t header_crc;
+
+ if ((p = __archive_read_ahead(a, H2_FIXED_SIZE, NULL)) == NULL)
+ return (truncated_error(a));
+
+ lha->header_size =archive_le16dec(p + H2_HEADER_SIZE_OFFSET);
+ lha->compsize = archive_le32dec(p + H2_COMP_SIZE_OFFSET);
+ lha->origsize = archive_le32dec(p + H2_ORIG_SIZE_OFFSET);
+ lha->mtime = archive_le32dec(p + H2_TIME_OFFSET);
+ lha->crc = archive_le16dec(p + H2_CRC_OFFSET);
+ lha->setflag |= CRC_IS_SET;
+
+ if (lha->header_size < H2_FIXED_SIZE) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid LHa header size");
+ return (ARCHIVE_FATAL);
+ }
+
+ header_crc = lha_crc16(0, p, H2_FIXED_SIZE);
+ __archive_read_consume(a, H2_FIXED_SIZE);
+
+ /* Read extended headers */
+ err = lha_read_file_extended_header(a, lha, &header_crc, 2,
+ lha->header_size - H2_FIXED_SIZE, &extdsize);
+ if (err < ARCHIVE_WARN)
+ return (err);
+
+ /* Calculate a padding size. The result will be normally 0 or 1. */
+ padding = (int)lha->header_size - (int)(H2_FIXED_SIZE + extdsize);
+ if (padding > 0) {
+ if ((p = __archive_read_ahead(a, padding, NULL)) == NULL)
+ return (truncated_error(a));
+ header_crc = lha_crc16(header_crc, p, padding);
+ __archive_read_consume(a, padding);
+ }
+
+ if (header_crc != lha->header_crc) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "LHa header CRC error");
+ return (ARCHIVE_FATAL);
+ }
+ return (err);
+}
+
+/*
+ * Header 3 format
+ *
+ * +0 +2 +7 +11 +15
+ * +------------+----------------+-------------------+-----------------+
+ * | 0x04 fixed |compression type|compressed size(*2)|uncompressed size|
+ * +------------+----------------+-------------------+-----------------+
+ * <-------------------------------(*1)-------------------------------*
+ *
+ * +15 +19 +20 +21 +23 +24
+ * +-----------------+------------+----------------+----------+-----------+
+ * |date/time(time_t)| 0x20 fixed |header level(=3)|file CRC16| creator |
+ * +-----------------+------------+----------------+----------+-----------+
+ * *--------------------------------(*1)----------------------------------*
+ *
+ * +24 +28 +32 +32+(*3)
+ * +---------------+----------------+-------------------+-----------------+
+ * |header size(*1)|next header size|extended header(*3)| compressed data |
+ * +---------------+----------------+-------------------+-----------------+
+ * *------------------------(*1)-----------------------> <------(*2)----->
+ *
+ */
+#define H3_FIELD_LEN_OFFSET 0
+#define H3_COMP_SIZE_OFFSET 7
+#define H3_ORIG_SIZE_OFFSET 11
+#define H3_TIME_OFFSET 15
+#define H3_CRC_OFFSET 21
+#define H3_HEADER_SIZE_OFFSET 24
+#define H3_FIXED_SIZE 28
+static int
+lha_read_file_header_3(struct archive_read *a, struct lha *lha)
+{
+ const unsigned char *p;
+ size_t extdsize;
+ int err;
+ uint16_t header_crc;
+
+ if ((p = __archive_read_ahead(a, H3_FIXED_SIZE, NULL)) == NULL)
+ return (truncated_error(a));
+
+ if (archive_le16dec(p + H3_FIELD_LEN_OFFSET) != 4)
+ goto invalid;
+ lha->header_size =archive_le32dec(p + H3_HEADER_SIZE_OFFSET);
+ lha->compsize = archive_le32dec(p + H3_COMP_SIZE_OFFSET);
+ lha->origsize = archive_le32dec(p + H3_ORIG_SIZE_OFFSET);
+ lha->mtime = archive_le32dec(p + H3_TIME_OFFSET);
+ lha->crc = archive_le16dec(p + H3_CRC_OFFSET);
+ lha->setflag |= CRC_IS_SET;
+
+ if (lha->header_size < H3_FIXED_SIZE + 4)
+ goto invalid;
+ header_crc = lha_crc16(0, p, H3_FIXED_SIZE);
+ __archive_read_consume(a, H3_FIXED_SIZE);
+
+ /* Read extended headers */
+ err = lha_read_file_extended_header(a, lha, &header_crc, 4,
+ lha->header_size - H3_FIXED_SIZE, &extdsize);
+ if (err < ARCHIVE_WARN)
+ return (err);
+
+ if (header_crc != lha->header_crc) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "LHa header CRC error");
+ return (ARCHIVE_FATAL);
+ }
+ return (err);
+invalid:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid LHa header");
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Extended header format
+ *
+ * +0 +2 +3 -- used in header 1 and 2
+ * +0 +4 +5 -- used in header 3
+ * +--------------+---------+-------------------+--------------+--
+ * |ex-header size|header id| data |ex-header size| .......
+ * +--------------+---------+-------------------+--------------+--
+ * <-------------( ex-header size)------------> <-- next extended header --*
+ *
+ * If the ex-header size is zero, it is the make of the end of extended
+ * headers.
+ *
+ */
+static int
+lha_read_file_extended_header(struct archive_read *a, struct lha *lha,
+ uint16_t *crc, int sizefield_length, size_t limitsize, size_t *total_size)
+{
+ const void *h;
+ const unsigned char *extdheader;
+ size_t extdsize;
+ size_t datasize;
+ unsigned int i;
+ unsigned char extdtype;
+
+#define EXT_HEADER_CRC 0x00 /* Header CRC and information*/
+#define EXT_FILENAME 0x01 /* Filename */
+#define EXT_DIRECTORY 0x02 /* Directory name */
+#define EXT_DOS_ATTR 0x40 /* MS-DOS attribute */
+#define EXT_TIMESTAMP 0x41 /* Windows time stamp */
+#define EXT_FILESIZE 0x42 /* Large file size */
+#define EXT_TIMEZONE 0x43 /* Time zone */
+#define EXT_UTF16_FILENAME 0x44 /* UTF-16 filename */
+#define EXT_UTF16_DIRECTORY 0x45 /* UTF-16 directory name */
+#define EXT_CODEPAGE 0x46 /* Codepage */
+#define EXT_UNIX_MODE 0x50 /* File permission */
+#define EXT_UNIX_GID_UID 0x51 /* gid,uid */
+#define EXT_UNIX_GNAME 0x52 /* Group name */
+#define EXT_UNIX_UNAME 0x53 /* User name */
+#define EXT_UNIX_MTIME 0x54 /* Modified time */
+#define EXT_OS2_NEW_ATTR 0x7f /* new attribute(OS/2 only) */
+#define EXT_NEW_ATTR 0xff /* new attribute */
+
+ *total_size = sizefield_length;
+
+ for (;;) {
+ /* Read an extended header size. */
+ if ((h =
+ __archive_read_ahead(a, sizefield_length, NULL)) == NULL)
+ return (truncated_error(a));
+ /* Check if the size is the zero indicates the end of the
+ * extended header. */
+ if (sizefield_length == sizeof(uint16_t))
+ extdsize = archive_le16dec(h);
+ else
+ extdsize = archive_le32dec(h);
+ if (extdsize == 0) {
+ /* End of extended header */
+ if (crc != NULL)
+ *crc = lha_crc16(*crc, h, sizefield_length);
+ __archive_read_consume(a, sizefield_length);
+ return (ARCHIVE_OK);
+ }
+
+ /* Sanity check to the extended header size. */
+ if (((uint64_t)*total_size + extdsize) >
+ (uint64_t)limitsize ||
+ extdsize <= (size_t)sizefield_length)
+ goto invalid;
+
+ /* Read the extended header. */
+ if ((h = __archive_read_ahead(a, extdsize, NULL)) == NULL)
+ return (truncated_error(a));
+ *total_size += extdsize;
+
+ extdheader = (const unsigned char *)h;
+ /* Get the extended header type. */
+ extdtype = extdheader[sizefield_length];
+ /* Calculate an extended data size. */
+ datasize = extdsize - (1 + sizefield_length);
+ /* Skip an extended header size field and type field. */
+ extdheader += sizefield_length + 1;
+
+ if (crc != NULL && extdtype != EXT_HEADER_CRC)
+ *crc = lha_crc16(*crc, h, extdsize);
+ switch (extdtype) {
+ case EXT_HEADER_CRC:
+ /* We only use a header CRC. Following data will not
+ * be used. */
+ if (datasize >= 2) {
+ lha->header_crc = archive_le16dec(extdheader);
+ if (crc != NULL) {
+ static const char zeros[2] = {0, 0};
+ *crc = lha_crc16(*crc, h,
+ extdsize - datasize);
+ /* CRC value itself as zero */
+ *crc = lha_crc16(*crc, zeros, 2);
+ *crc = lha_crc16(*crc,
+ extdheader+2, datasize - 2);
+ }
+ }
+ break;
+ case EXT_FILENAME:
+ if (datasize == 0) {
+ /* maybe directory header */
+ archive_string_empty(&lha->filename);
+ break;
+ }
+ archive_strncpy(&lha->filename,
+ (const char *)extdheader, datasize);
+ break;
+ case EXT_DIRECTORY:
+ if (datasize == 0)
+ /* no directory name data. exit this case. */
+ break;
+
+ archive_strncpy(&lha->dirname,
+ (const char *)extdheader, datasize);
+ /*
+ * Convert directory delimiter from 0xFF
+ * to '/' for local system.
+ */
+ for (i = 0; i < lha->dirname.length; i++) {
+ if ((unsigned char)lha->dirname.s[i] == 0xFF)
+ lha->dirname.s[i] = '/';
+ }
+ /* Is last character directory separator? */
+ if (lha->dirname.s[lha->dirname.length-1] != '/')
+ /* invalid directory data */
+ goto invalid;
+ break;
+ case EXT_DOS_ATTR:
+ if (datasize == 2)
+ lha->dos_attr = (unsigned char)
+ (archive_le16dec(extdheader) & 0xff);
+ break;
+ case EXT_TIMESTAMP:
+ if (datasize == (sizeof(uint64_t) * 3)) {
+ lha->birthtime = lha_win_time(
+ archive_le64dec(extdheader),
+ &lha->birthtime_tv_nsec);
+ extdheader += sizeof(uint64_t);
+ lha->mtime = lha_win_time(
+ archive_le64dec(extdheader),
+ &lha->mtime_tv_nsec);
+ extdheader += sizeof(uint64_t);
+ lha->atime = lha_win_time(
+ archive_le64dec(extdheader),
+ &lha->atime_tv_nsec);
+ lha->setflag |= BIRTHTIME_IS_SET |
+ ATIME_IS_SET;
+ }
+ break;
+ case EXT_FILESIZE:
+ if (datasize == sizeof(uint64_t) * 2) {
+ lha->compsize = archive_le64dec(extdheader);
+ extdheader += sizeof(uint64_t);
+ lha->origsize = archive_le64dec(extdheader);
+ }
+ break;
+ case EXT_CODEPAGE:
+ /* Get an archived filename charset from codepage.
+ * This overwrites the charset specified by
+ * hdrcharset option. */
+ if (datasize == sizeof(uint32_t)) {
+ struct archive_string cp;
+ const char *charset;
+
+ archive_string_init(&cp);
+ switch (archive_le32dec(extdheader)) {
+ case 65001: /* UTF-8 */
+ charset = "UTF-8";
+ break;
+ default:
+ archive_string_sprintf(&cp, "CP%d",
+ (int)archive_le32dec(extdheader));
+ charset = cp.s;
+ break;
+ }
+ lha->sconv =
+ archive_string_conversion_from_charset(
+ &(a->archive), charset, 1);
+ archive_string_free(&cp);
+ if (lha->sconv == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ break;
+ case EXT_UNIX_MODE:
+ if (datasize == sizeof(uint16_t)) {
+ lha->mode = archive_le16dec(extdheader);
+ lha->setflag |= UNIX_MODE_IS_SET;
+ }
+ break;
+ case EXT_UNIX_GID_UID:
+ if (datasize == (sizeof(uint16_t) * 2)) {
+ lha->gid = archive_le16dec(extdheader);
+ lha->uid = archive_le16dec(extdheader+2);
+ }
+ break;
+ case EXT_UNIX_GNAME:
+ if (datasize > 0)
+ archive_strncpy(&lha->gname,
+ (const char *)extdheader, datasize);
+ break;
+ case EXT_UNIX_UNAME:
+ if (datasize > 0)
+ archive_strncpy(&lha->uname,
+ (const char *)extdheader, datasize);
+ break;
+ case EXT_UNIX_MTIME:
+ if (datasize == sizeof(uint32_t))
+ lha->mtime = archive_le32dec(extdheader);
+ break;
+ case EXT_OS2_NEW_ATTR:
+ /* This extended header is OS/2 depend. */
+ if (datasize == 16) {
+ lha->dos_attr = (unsigned char)
+ (archive_le16dec(extdheader) & 0xff);
+ lha->mode = archive_le16dec(extdheader+2);
+ lha->gid = archive_le16dec(extdheader+4);
+ lha->uid = archive_le16dec(extdheader+6);
+ lha->birthtime = archive_le32dec(extdheader+8);
+ lha->atime = archive_le32dec(extdheader+12);
+ lha->setflag |= UNIX_MODE_IS_SET
+ | BIRTHTIME_IS_SET | ATIME_IS_SET;
+ }
+ break;
+ case EXT_NEW_ATTR:
+ if (datasize == 20) {
+ lha->mode = (mode_t)archive_le32dec(extdheader);
+ lha->gid = archive_le32dec(extdheader+4);
+ lha->uid = archive_le32dec(extdheader+8);
+ lha->birthtime = archive_le32dec(extdheader+12);
+ lha->atime = archive_le32dec(extdheader+16);
+ lha->setflag |= UNIX_MODE_IS_SET
+ | BIRTHTIME_IS_SET | ATIME_IS_SET;
+ }
+ break;
+ case EXT_TIMEZONE: /* Not supported */
+ case EXT_UTF16_FILENAME: /* Not supported */
+ case EXT_UTF16_DIRECTORY: /* Not supported */
+ default:
+ break;
+ }
+
+ __archive_read_consume(a, extdsize);
+ }
+invalid:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid extended LHa header");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+archive_read_format_lha_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ struct lha *lha = (struct lha *)(a->format->data);
+ int r;
+
+ if (lha->entry_unconsumed) {
+ /* Consume as much as the decompressor actually used. */
+ __archive_read_consume(a, lha->entry_unconsumed);
+ 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);
+ }
+
+ if (lha->entry_is_compressed)
+ r = lha_read_data_lzh(a, buff, size, offset);
+ else
+ /* No compression. */
+ r = lha_read_data_none(a, buff, size, offset);
+ return (r);
+}
+
+/*
+ * Read a file content in no compression.
+ *
+ * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets
+ * lha->end_of_entry if it consumes all of the data.
+ */
+static int
+lha_read_data_none(struct archive_read *a, const void **buff,
+ size_t *size, int64_t *offset)
+{
+ struct lha *lha = (struct lha *)(a->format->data);
+ ssize_t bytes_avail;
+
+ if (lha->entry_bytes_remaining == 0) {
+ *buff = NULL;
+ *size = 0;
+ *offset = lha->entry_offset;
+ lha->end_of_entry = 1;
+ return (ARCHIVE_OK);
+ }
+ /*
+ * Note: '1' here is a performance optimization.
+ * Recall that the decompression layer returns a count of
+ * available bytes; asking for more than that forces the
+ * decompressor to combine reads by copying data.
+ */
+ *buff = __archive_read_ahead(a, 1, &bytes_avail);
+ if (bytes_avail <= 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated LHa file data");
+ return (ARCHIVE_FATAL);
+ }
+ if (bytes_avail > lha->entry_bytes_remaining)
+ bytes_avail = (ssize_t)lha->entry_bytes_remaining;
+ lha->entry_crc_calculated =
+ lha_crc16(lha->entry_crc_calculated, *buff, bytes_avail);
+ *size = bytes_avail;
+ *offset = lha->entry_offset;
+ lha->entry_offset += bytes_avail;
+ lha->entry_bytes_remaining -= bytes_avail;
+ if (lha->entry_bytes_remaining == 0)
+ lha->end_of_entry = 1;
+ lha->entry_unconsumed = bytes_avail;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Read a file content in LZHUFF encoding.
+ *
+ * Returns ARCHIVE_OK if successful, returns ARCHIVE_WARN if compression is
+ * unsupported, ARCHIVE_FATAL otherwise, sets lha->end_of_entry if it consumes
+ * all of the data.
+ */
+static int
+lha_read_data_lzh(struct archive_read *a, const void **buff,
+ size_t *size, int64_t *offset)
+{
+ struct lha *lha = (struct lha *)(a->format->data);
+ 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);
+ switch (r) {
+ case ARCHIVE_OK:
+ break;
+ case ARCHIVE_FAILED:
+ /* Unsupported compression. */
+ *buff = NULL;
+ *size = 0;
+ *offset = 0;
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unsupported lzh compression method -%c%c%c-",
+ lha->method[0], lha->method[1], lha->method[2]);
+ /* We know compressed size; just skip it. */
+ archive_read_format_lha_read_data_skip(a);
+ return (ARCHIVE_WARN);
+ default:
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't allocate memory "
+ "for lzh decompression");
+ return (ARCHIVE_FATAL);
+ }
+ /* We've initialized decompression for this stream. */
+ lha->decompress_init = 1;
+ lha->strm.avail_out = 0;
+ lha->strm.total_out = 0;
+ }
+
+ /*
+ * Note: '1' here is a performance optimization.
+ * Recall that the decompression layer returns a count of
+ * available bytes; asking for more than that forces the
+ * decompressor to combine reads by copying data.
+ */
+ lha->strm.next_in = __archive_read_ahead(a, 1, &bytes_avail);
+ if (bytes_avail <= 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated LHa file body");
+ return (ARCHIVE_FATAL);
+ }
+ if (bytes_avail > lha->entry_bytes_remaining)
+ bytes_avail = (ssize_t)lha->entry_bytes_remaining;
+
+ lha->strm.avail_in = 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;
+ }
+
+ r = lzh_decode(&(lha->strm), bytes_avail == lha->entry_bytes_remaining);
+ switch (r) {
+ case ARCHIVE_OK:
+ break;
+ case ARCHIVE_EOF:
+ lha->end_of_entry = 1;
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Bad lzh data");
+ return (ARCHIVE_FAILED);
+ }
+ 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) {
+ *offset = lha->entry_offset;
+ *size = lha->strm.next_out - lha->uncompressed_buffer;
+ *buff = lha->uncompressed_buffer;
+ lha->entry_crc_calculated =
+ lha_crc16(lha->entry_crc_calculated, *buff, *size);
+ lha->entry_offset += *size;
+ } else {
+ *offset = lha->entry_offset;
+ *size = 0;
+ *buff = NULL;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Skip a file content.
+ */
+static int
+archive_read_format_lha_read_data_skip(struct archive_read *a)
+{
+ struct lha *lha;
+ int64_t bytes_skipped;
+
+ lha = (struct lha *)(a->format->data);
+
+ if (lha->entry_unconsumed) {
+ /* Consume as much as the decompressor actually used. */
+ __archive_read_consume(a, lha->entry_unconsumed);
+ lha->entry_unconsumed = 0;
+ }
+
+ /* if we've already read to end of data, we're done. */
+ if (lha->end_of_entry_cleanup)
+ return (ARCHIVE_OK);
+
+ /*
+ * If the length is at the beginning, we can skip the
+ * compressed data much more quickly.
+ */
+ bytes_skipped = __archive_read_consume(a, lha->entry_bytes_remaining);
+ if (bytes_skipped < 0)
+ return (ARCHIVE_FATAL);
+
+ /* This entry is finished and done. */
+ lha->end_of_entry_cleanup = lha->end_of_entry = 1;
+ return (ARCHIVE_OK);
+}
+
+static int
+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));
+ archive_string_free(&(lha->gname));
+ archive_wstring_free(&(lha->ws));
+ free(lha);
+ (a->format->data) = NULL;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * 'LHa for UNIX' utility has archived a symbolic-link name after
+ * a pathname with '|' character.
+ * This function extracts the symbolic-link name from the pathname.
+ *
+ * example.
+ * 1. a symbolic-name is 'aaa/bb/cc'
+ * 2. a filename is 'xxx/bbb'
+ * then a archived pathname is 'xxx/bbb|aaa/bb/cc'
+ */
+static int
+lha_parse_linkname(struct archive_string *linkname,
+ struct archive_string *pathname)
+{
+ char * linkptr;
+ size_t symlen;
+
+ linkptr = strchr(pathname->s, '|');
+ if (linkptr != NULL) {
+ symlen = strlen(linkptr + 1);
+ archive_strncpy(linkname, linkptr+1, symlen);
+
+ *linkptr = 0;
+ pathname->length = strlen(pathname->s);
+
+ return (1);
+ }
+ return (0);
+}
+
+/* Convert an MSDOS-style date/time into Unix-style time. */
+static time_t
+lha_dos_time(const unsigned char *p)
+{
+ int msTime, msDate;
+ struct tm ts;
+
+ msTime = archive_le16dec(p);
+ msDate = archive_le16dec(p+2);
+
+ memset(&ts, 0, sizeof(ts));
+ ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */
+ ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */
+ ts.tm_mday = msDate & 0x1f; /* Day of month. */
+ ts.tm_hour = (msTime >> 11) & 0x1f;
+ ts.tm_min = (msTime >> 5) & 0x3f;
+ ts.tm_sec = (msTime << 1) & 0x3e;
+ ts.tm_isdst = -1;
+ return (mktime(&ts));
+}
+
+/* Convert an MS-Windows-style date/time into Unix-style time. */
+static time_t
+lha_win_time(uint64_t wintime, long *ns)
+{
+#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
+
+ if (wintime >= EPOC_TIME) {
+ wintime -= EPOC_TIME; /* 1970-01-01 00:00:00 (UTC) */
+ if (ns != NULL)
+ *ns = (long)(wintime % 10000000) * 100;
+ return (wintime / 10000000);
+ } else {
+ if (ns != NULL)
+ *ns = 0;
+ return (0);
+ }
+}
+
+static unsigned char
+lha_calcsum(unsigned char sum, const void *pp, int offset, size_t size)
+{
+ unsigned char const *p = (unsigned char const *)pp;
+
+ p += offset;
+ for (;size > 0; --size)
+ sum += *p++;
+ return (sum);
+}
+
+#define CRC16(crc, v) do { \
+ (crc) = crc16tbl[((crc) ^ v) & 0xFF] ^ ((crc) >> 8); \
+} while (0)
+
+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;
+ }
+ 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;
+ }
+ return (crc);
+}
+
+
+/*
+ * Initialize LZHUF decoder.
+ *
+ * Returns ARCHIVE_OK if initialization was successful.
+ * Returns ARCHIVE_FAILED if method is unsupported.
+ * Returns ARCHIVE_FATAL if initialization failed; memory allocation
+ * error occurred.
+ */
+static int
+lzh_decode_init(struct lzh_stream *strm, const char *method)
+{
+ struct lzh_dec *ds;
+ int w_bits, w_size;
+
+ if (strm->ds == NULL) {
+ strm->ds = calloc(1, sizeof(*strm->ds));
+ if (strm->ds == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ ds = strm->ds;
+ ds->error = ARCHIVE_FAILED;
+ if (method == NULL || method[0] != 'l' || method[1] != 'h')
+ return (ARCHIVE_FAILED);
+ switch (method[2]) {
+ case '5':
+ w_bits = 13;/* 8KiB for window */
+ break;
+ case '6':
+ w_bits = 15;/* 32KiB for window */
+ break;
+ case '7':
+ w_bits = 16;/* 64KiB for window */
+ break;
+ default:
+ return (ARCHIVE_FAILED);/* Not supported. */
+ }
+ ds->error = ARCHIVE_FATAL;
+ w_size = ds->w_size;
+ ds->w_size = 1U << w_bits;
+ ds->w_mask = ds->w_size -1;
+ if (ds->w_buff == NULL || w_size != ds->w_size) {
+ free(ds->w_buff);
+ ds->w_buff = malloc(ds->w_size);
+ if (ds->w_buff == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ memset(ds->w_buff, 0x20, ds->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;
+ ds->literal_pt_len_size = PT_BITLEN_SIZE;
+ ds->literal_pt_len_bits = 5;
+ ds->br.cache_buffer = 0;
+ ds->br.cache_avail = 0;
+
+ if (lzh_huffman_init(&(ds->lt), LT_BITLEN_SIZE, 16)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ ds->lt.len_bits = 9;
+ if (lzh_huffman_init(&(ds->pt), PT_BITLEN_SIZE, 16)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ ds->error = 0;
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Release LZHUF decoder.
+ */
+static void
+lzh_decode_free(struct lzh_stream *strm)
+{
+
+ if (strm->ds == NULL)
+ return;
+ free(strm->ds->w_buff);
+ lzh_huffman_free(&(strm->ds->lt));
+ lzh_huffman_free(&(strm->ds->pt));
+ free(strm->ds);
+ strm->ds = NULL;
+}
+
+/*
+ * Bit stream reader.
+ */
+/* Check that the cache buffer has enough bits. */
+#define lzh_br_has(br, n) ((br)->cache_avail >= n)
+/* Get compressed data by bit. */
+#define lzh_br_bits(br, n) \
+ (((uint16_t)((br)->cache_buffer >> \
+ ((br)->cache_avail - (n)))) & cache_masks[n])
+#define lzh_br_bits_forced(br, n) \
+ (((uint16_t)((br)->cache_buffer << \
+ ((n) - (br)->cache_avail))) & cache_masks[n])
+/* Read ahead to make sure the cache buffer has enough compressed data we
+ * will use.
+ * True : completed, there is enough data in the cache buffer.
+ * False : we met that strm->next_in is empty, we have to get following
+ * bytes. */
+#define lzh_br_read_ahead_0(strm, br, n) \
+ (lzh_br_has(br, (n)) || lzh_br_fillup(strm, br))
+/* True : the cache buffer has some bits as much as we need.
+ * False : there are no enough bits in the cache buffer to be used,
+ * we have to get following bytes if we could. */
+#define lzh_br_read_ahead(strm, br, n) \
+ (lzh_br_read_ahead_0((strm), (br), (n)) || lzh_br_has((br), (n)))
+
+/* Notify how many bits we consumed. */
+#define lzh_br_consume(br, n) ((br)->cache_avail -= (n))
+#define lzh_br_unconsume(br, n) ((br)->cache_avail += (n))
+
+static const uint16_t cache_masks[] = {
+ 0x0000, 0x0001, 0x0003, 0x0007,
+ 0x000F, 0x001F, 0x003F, 0x007F,
+ 0x00FF, 0x01FF, 0x03FF, 0x07FF,
+ 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF,
+ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF
+};
+
+/*
+ * Shift away used bits in the cache data and fill it up with following bits.
+ * Call this when cache buffer does not have enough bits you need.
+ *
+ * Returns 1 if the cache buffer is full.
+ * Returns 0 if the cache buffer is not full; input buffer is empty.
+ */
+static int
+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) {
+ br->cache_buffer =
+ ((uint64_t)strm->next_in[0]) << 56 |
+ ((uint64_t)strm->next_in[1]) << 48 |
+ ((uint64_t)strm->next_in[2]) << 40 |
+ ((uint64_t)strm->next_in[3]) << 32 |
+ ((uint32_t)strm->next_in[4]) << 24 |
+ ((uint32_t)strm->next_in[5]) << 16 |
+ ((uint32_t)strm->next_in[6]) << 8 |
+ (uint32_t)strm->next_in[7];
+ strm->next_in += 8;
+ strm->avail_in -= 8;
+ br->cache_avail += 8 * 8;
+ return (1);
+ }
+ break;
+ case 7:
+ if (strm->avail_in >= 7) {
+ br->cache_buffer =
+ (br->cache_buffer << 56) |
+ ((uint64_t)strm->next_in[0]) << 48 |
+ ((uint64_t)strm->next_in[1]) << 40 |
+ ((uint64_t)strm->next_in[2]) << 32 |
+ ((uint32_t)strm->next_in[3]) << 24 |
+ ((uint32_t)strm->next_in[4]) << 16 |
+ ((uint32_t)strm->next_in[5]) << 8 |
+ (uint32_t)strm->next_in[6];
+ strm->next_in += 7;
+ strm->avail_in -= 7;
+ br->cache_avail += 7 * 8;
+ return (1);
+ }
+ break;
+ case 6:
+ if (strm->avail_in >= 6) {
+ br->cache_buffer =
+ (br->cache_buffer << 48) |
+ ((uint64_t)strm->next_in[0]) << 40 |
+ ((uint64_t)strm->next_in[1]) << 32 |
+ ((uint32_t)strm->next_in[2]) << 24 |
+ ((uint32_t)strm->next_in[3]) << 16 |
+ ((uint32_t)strm->next_in[4]) << 8 |
+ (uint32_t)strm->next_in[5];
+ strm->next_in += 6;
+ strm->avail_in -= 6;
+ br->cache_avail += 6 * 8;
+ return (1);
+ }
+ 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
+ * cache buffer. */
+ return (0);
+ }
+ br->cache_buffer =
+ (br->cache_buffer << 8) | *strm->next_in++;
+ strm->avail_in--;
+ br->cache_avail += 8;
+ n -= 8;
+ }
+}
+
+/*
+ * Decode LZHUF.
+ *
+ * 1. Returns ARCHIVE_OK if output buffer or input buffer are empty.
+ * Please set available buffer and call this function again.
+ * 2. Returns ARCHIVE_EOF if decompression has been completed.
+ * 3. Returns ARCHIVE_FAILED if an error occurred; compressed data
+ * is broken or you do not set 'last' flag properly.
+ * 4. 'last' flag is very important, you must set 1 to the flag if there
+ * is no input data. The lha compressed data format does not provide how
+ * to know the compressed data is really finished.
+ * Note: lha command utility check if the total size of output bytes is
+ * reached the uncompressed size recorded in its header. it does not mind
+ * that the decoding process is properly finished.
+ * GNU ZIP can decompress another compressed file made by SCO LZH compress.
+ * it handles EOF as null to fill read buffer with zero until the decoding
+ * process meet 2 bytes of zeros at reading a size of a next chunk, so the
+ * zeros are treated as the mark of the end of the data although the zeros
+ * is dummy, not the file data.
+ */
+static int lzh_read_blocks(struct lzh_stream *, int);
+static int lzh_decode_blocks(struct lzh_stream *, int);
+#define ST_RD_BLOCK 0
+#define ST_RD_PT_1 1
+#define ST_RD_PT_2 2
+#define ST_RD_PT_3 3
+#define ST_RD_PT_4 4
+#define ST_RD_LITERAL_1 5
+#define ST_RD_LITERAL_2 6
+#define ST_RD_LITERAL_3 7
+#define ST_RD_POS_DATA_1 8
+#define ST_GET_LITERAL 9
+#define ST_GET_POS_1 10
+#define ST_GET_POS_2 11
+#define ST_COPY_DATA 12
+
+static int
+lzh_decode(struct lzh_stream *strm, int last)
+{
+ struct lzh_dec *ds = strm->ds;
+ int64_t avail_in;
+ int r;
+
+ if (ds->error)
+ return (ds->error);
+
+ avail_in = strm->avail_in;
+ do {
+ if (ds->state < ST_GET_LITERAL)
+ r = lzh_read_blocks(strm, last);
+ else
+ r = lzh_decode_blocks(strm, last);
+ } while (r == 100);
+ strm->total_in += avail_in - strm->avail_in;
+ return (r);
+}
+
+static int
+lzh_copy_from_window(struct lzh_stream *strm, struct lzh_dec *ds)
+{
+ 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);
+}
+
+static int
+lzh_read_blocks(struct lzh_stream *strm, int last)
+{
+ struct lzh_dec *ds = strm->ds;
+ struct lzh_br *br = &(ds->br);
+ int c = 0, i;
+ unsigned rbits;
+
+ for (;;) {
+ switch (ds->state) {
+ case ST_RD_BLOCK:
+ /*
+ * Read a block number indicates how many blocks
+ * we will handle. The block is composed of a
+ * literal and a match, sometimes a literal only
+ * in particular, there are no reference data at
+ * the beginning of the decompression.
+ */
+ if (!lzh_br_read_ahead_0(strm, br, 16)) {
+ if (!last)
+ /* We need following data. */
+ return (ARCHIVE_OK);
+ if (lzh_br_has(br, 8)) {
+ /*
+ * It seems there are extra bits.
+ * 1. Compressed data is broken.
+ * 2. `last' flag does not properly
+ * set.
+ */
+ goto failed;
+ }
+ if (ds->w_pos > 0) {
+ if (!lzh_copy_from_window(strm, ds))
+ return (ARCHIVE_OK);
+ }
+ /* End of compressed data; we have completely
+ * handled all compressed data. */
+ return (ARCHIVE_EOF);
+ }
+ ds->blocks_avail = lzh_br_bits(br, 16);
+ if (ds->blocks_avail == 0)
+ goto failed;
+ lzh_br_consume(br, 16);
+ /*
+ * Read a literal table compressed in huffman
+ * coding.
+ */
+ ds->pt.len_size = ds->literal_pt_len_size;
+ ds->pt.len_bits = ds->literal_pt_len_bits;
+ ds->reading_position = 0;
+ /* FALL THROUGH */
+ case ST_RD_PT_1:
+ /* Note: ST_RD_PT_1, ST_RD_PT_2 and ST_RD_PT_4 are
+ * used in reading both a literal table and a
+ * position table. */
+ if (!lzh_br_read_ahead(strm, br, ds->pt.len_bits)) {
+ if (last)
+ goto failed;/* Truncated data. */
+ ds->state = ST_RD_PT_1;
+ return (ARCHIVE_OK);
+ }
+ ds->pt.len_avail = lzh_br_bits(br, ds->pt.len_bits);
+ lzh_br_consume(br, ds->pt.len_bits);
+ /* FALL THROUGH */
+ case ST_RD_PT_2:
+ if (ds->pt.len_avail == 0) {
+ /* There is no bitlen. */
+ if (!lzh_br_read_ahead(strm, br,
+ ds->pt.len_bits)) {
+ if (last)
+ goto failed;/* Truncated data.*/
+ ds->state = ST_RD_PT_2;
+ return (ARCHIVE_OK);
+ }
+ if (!lzh_make_fake_table(&(ds->pt),
+ lzh_br_bits(br, ds->pt.len_bits)))
+ goto failed;/* Invalid data. */
+ lzh_br_consume(br, ds->pt.len_bits);
+ if (ds->reading_position)
+ ds->state = ST_GET_LITERAL;
+ else
+ ds->state = ST_RD_LITERAL_1;
+ break;
+ } else if (ds->pt.len_avail > ds->pt.len_size)
+ goto failed;/* Invalid data. */
+ ds->loop = 0;
+ memset(ds->pt.freq, 0, sizeof(ds->pt.freq));
+ if (ds->pt.len_avail < 3 ||
+ ds->pt.len_size == ds->pos_pt_len_size) {
+ ds->state = ST_RD_PT_4;
+ break;
+ }
+ /* FALL THROUGH */
+ case ST_RD_PT_3:
+ ds->loop = lzh_read_pt_bitlen(strm, ds->loop, 3);
+ if (ds->loop < 3) {
+ if (ds->loop < 0 || last)
+ goto failed;/* Invalid data. */
+ /* Not completed, get following data. */
+ ds->state = ST_RD_PT_3;
+ return (ARCHIVE_OK);
+ }
+ /* There are some null in bitlen of the literal. */
+ if (!lzh_br_read_ahead(strm, br, 2)) {
+ if (last)
+ goto failed;/* Truncated data. */
+ ds->state = ST_RD_PT_3;
+ return (ARCHIVE_OK);
+ }
+ c = lzh_br_bits(br, 2);
+ lzh_br_consume(br, 2);
+ if (c > ds->pt.len_avail - 3)
+ goto failed;/* Invalid data. */
+ for (i = 3; c-- > 0 ;)
+ ds->pt.bitlen[i++] = 0;
+ ds->loop = i;
+ /* FALL THROUGH */
+ case ST_RD_PT_4:
+ ds->loop = lzh_read_pt_bitlen(strm, ds->loop,
+ ds->pt.len_avail);
+ if (ds->loop < ds->pt.len_avail) {
+ if (ds->loop < 0 || last)
+ goto failed;/* Invalid data. */
+ /* Not completed, get following data. */
+ ds->state = ST_RD_PT_4;
+ return (ARCHIVE_OK);
+ }
+ if (!lzh_make_huffman_table(&(ds->pt)))
+ goto failed;/* Invalid data */
+ if (ds->reading_position) {
+ ds->state = ST_GET_LITERAL;
+ break;
+ }
+ /* FALL THROUGH */
+ case ST_RD_LITERAL_1:
+ if (!lzh_br_read_ahead(strm, br, ds->lt.len_bits)) {
+ if (last)
+ goto failed;/* Truncated data. */
+ ds->state = ST_RD_LITERAL_1;
+ return (ARCHIVE_OK);
+ }
+ ds->lt.len_avail = lzh_br_bits(br, ds->lt.len_bits);
+ lzh_br_consume(br, ds->lt.len_bits);
+ /* FALL THROUGH */
+ case ST_RD_LITERAL_2:
+ if (ds->lt.len_avail == 0) {
+ /* There is no bitlen. */
+ if (!lzh_br_read_ahead(strm, br,
+ ds->lt.len_bits)) {
+ if (last)
+ goto failed;/* Truncated data.*/
+ ds->state = ST_RD_LITERAL_2;
+ return (ARCHIVE_OK);
+ }
+ if (!lzh_make_fake_table(&(ds->lt),
+ lzh_br_bits(br, ds->lt.len_bits)))
+ goto failed;/* Invalid data */
+ lzh_br_consume(br, ds->lt.len_bits);
+ ds->state = ST_RD_POS_DATA_1;
+ break;
+ } else if (ds->lt.len_avail > ds->lt.len_size)
+ goto failed;/* Invalid data */
+ ds->loop = 0;
+ memset(ds->lt.freq, 0, sizeof(ds->lt.freq));
+ /* FALL THROUGH */
+ case ST_RD_LITERAL_3:
+ i = ds->loop;
+ while (i < ds->lt.len_avail) {
+ if (!lzh_br_read_ahead(strm, br,
+ ds->pt.max_bits)) {
+ if (last)
+ goto failed;/* Truncated data.*/
+ ds->loop = i;
+ ds->state = ST_RD_LITERAL_3;
+ return (ARCHIVE_OK);
+ }
+ rbits = lzh_br_bits(br, ds->pt.max_bits);
+ c = lzh_decode_huffman(&(ds->pt), rbits);
+ if (c > 2) {
+ /* Note: 'c' will never be more than
+ * eighteen since it's limited by
+ * PT_BITLEN_SIZE, which is being set
+ * to ds->pt.len_size through
+ * ds->literal_pt_len_size. */
+ lzh_br_consume(br, ds->pt.bitlen[c]);
+ c -= 2;
+ ds->lt.freq[c]++;
+ ds->lt.bitlen[i++] = c;
+ } else if (c == 0) {
+ lzh_br_consume(br, ds->pt.bitlen[c]);
+ ds->lt.bitlen[i++] = 0;
+ } else {
+ /* c == 1 or c == 2 */
+ int n = (c == 1)?4:9;
+ if (!lzh_br_read_ahead(strm, br,
+ ds->pt.bitlen[c] + n)) {
+ if (last) /* Truncated data. */
+ goto failed;
+ ds->loop = i;
+ ds->state = ST_RD_LITERAL_3;
+ return (ARCHIVE_OK);
+ }
+ lzh_br_consume(br, ds->pt.bitlen[c]);
+ c = lzh_br_bits(br, n);
+ lzh_br_consume(br, n);
+ c += (n == 4)?3:20;
+ if (i + c > ds->lt.len_avail)
+ goto failed;/* Invalid data */
+ memset(&(ds->lt.bitlen[i]), 0, c);
+ i += c;
+ }
+ }
+ if (i > ds->lt.len_avail ||
+ !lzh_make_huffman_table(&(ds->lt)))
+ goto failed;/* Invalid data */
+ /* FALL THROUGH */
+ case ST_RD_POS_DATA_1:
+ /*
+ * Read a position table compressed in huffman
+ * coding.
+ */
+ ds->pt.len_size = ds->pos_pt_len_size;
+ ds->pt.len_bits = ds->pos_pt_len_bits;
+ ds->reading_position = 1;
+ ds->state = ST_RD_PT_1;
+ break;
+ case ST_GET_LITERAL:
+ return (100);
+ }
+ }
+failed:
+ return (ds->error = ARCHIVE_FAILED);
+}
+
+static int
+lzh_decode_blocks(struct lzh_stream *strm, int last)
+{
+ struct lzh_dec *ds = strm->ds;
+ struct lzh_br bre = ds->br;
+ struct huffman *lt = &(ds->lt);
+ struct huffman *pt = &(ds->pt);
+ unsigned char *w_buff = ds->w_buff;
+ unsigned char *lt_bitlen = lt->bitlen;
+ unsigned char *pt_bitlen = pt->bitlen;
+ int blocks_avail = ds->blocks_avail, c = 0;
+ int copy_len = ds->copy_len, copy_pos = ds->copy_pos;
+ int w_pos = ds->w_pos, w_mask = ds->w_mask, w_size = ds->w_size;
+ 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:
+ for (;;) {
+ if (blocks_avail == 0) {
+ /* We have decoded all blocks.
+ * Let's handle next blocks. */
+ ds->state = ST_RD_BLOCK;
+ ds->br = bre;
+ ds->blocks_avail = 0;
+ ds->w_pos = w_pos;
+ ds->copy_pos = 0;
+ return (100);
+ }
+
+ /* lzh_br_read_ahead() always try to fill the
+ * cache buffer up. In specific situation we
+ * are close to the end of the data, the cache
+ * buffer will not be full and thus we have to
+ * determine if the cache buffer has some bits
+ * as much as we need after lzh_br_read_ahead()
+ * failed. */
+ if (!lzh_br_read_ahead(strm, &bre,
+ lt_max_bits)) {
+ if (!last)
+ goto next_data;
+ /* Remaining bits are less than
+ * maximum bits(lt.max_bits) but maybe
+ * it still remains as much as we need,
+ * so we should try to use it with
+ * dummy bits. */
+ c = lzh_decode_huffman(lt,
+ lzh_br_bits_forced(&bre,
+ lt_max_bits));
+ lzh_br_consume(&bre, lt_bitlen[c]);
+ if (!lzh_br_has(&bre, 0))
+ goto failed;/* Over read. */
+ } else {
+ c = lzh_decode_huffman(lt,
+ lzh_br_bits(&bre, lt_max_bits));
+ lzh_br_consume(&bre, lt_bitlen[c]);
+ }
+ blocks_avail--;
+ if (c > UCHAR_MAX)
+ /* Current block is a match data. */
+ break;
+ /*
+ * 'c' is exactly a literal code.
+ */
+ /* Save a decoded code to reference it
+ * afterward. */
+ 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;
+ }
+ }
+ /* 'c' is the length of a match pattern we have
+ * already extracted, which has be stored in
+ * window(ds->w_buff). */
+ copy_len = c - (UCHAR_MAX + 1) + MINMATCH;
+ /* FALL THROUGH */
+ case ST_GET_POS_1:
+ /*
+ * Get a reference position.
+ */
+ if (!lzh_br_read_ahead(strm, &bre, pt_max_bits)) {
+ if (!last) {
+ state = ST_GET_POS_1;
+ ds->copy_len = copy_len;
+ goto next_data;
+ }
+ copy_pos = lzh_decode_huffman(pt,
+ lzh_br_bits_forced(&bre, pt_max_bits));
+ lzh_br_consume(&bre, pt_bitlen[copy_pos]);
+ if (!lzh_br_has(&bre, 0))
+ goto failed;/* Over read. */
+ } else {
+ copy_pos = lzh_decode_huffman(pt,
+ lzh_br_bits(&bre, pt_max_bits));
+ lzh_br_consume(&bre, pt_bitlen[copy_pos]);
+ }
+ /* FALL THROUGH */
+ case ST_GET_POS_2:
+ if (copy_pos > 1) {
+ /* We need an additional adjustment number to
+ * the position. */
+ int p = copy_pos - 1;
+ if (!lzh_br_read_ahead(strm, &bre, p)) {
+ if (last)
+ goto failed;/* Truncated data.*/
+ state = ST_GET_POS_2;
+ ds->copy_len = copy_len;
+ ds->copy_pos = copy_pos;
+ goto next_data;
+ }
+ copy_pos = (1 << p) + lzh_br_bits(&bre, p);
+ lzh_br_consume(&bre, p);
+ }
+ /* The position is actually a distance from the last
+ * code we had extracted and thus we have to convert
+ * it to a position of the window. */
+ copy_pos = (w_pos - copy_pos - 1) & w_mask;
+ /* FALL THROUGH */
+ case ST_COPY_DATA:
+ /*
+ * Copy `copy_len' bytes as extracted data from
+ * the window into the output buffer.
+ */
+ for (;;) {
+ int l;
+
+ l = copy_len;
+ if (copy_pos > w_pos) {
+ if (l > w_size - copy_pos)
+ l = w_size - copy_pos;
+ } else {
+ if (l > w_size - w_pos)
+ l = w_size - w_pos;
+ }
+ if ((copy_pos + l < w_pos)
+ || (w_pos + l < copy_pos)) {
+ /* No overlap. */
+ memcpy(w_buff + w_pos,
+ w_buff + copy_pos, l);
+ } else {
+ const unsigned char *s;
+ unsigned char *d;
+ int li;
+
+ d = w_buff + w_pos;
+ s = w_buff + copy_pos;
+ for (li = 0; li < l; li++)
+ 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;
+ }
+ }
+ if (copy_len <= l)
+ /* A copy of current pattern ended. */
+ break;
+ copy_len -= l;
+ copy_pos = (copy_pos + l) & w_mask;
+ }
+ state = ST_GET_LITERAL;
+ break;
+ }
+ }
+failed:
+ return (ds->error = ARCHIVE_FAILED);
+next_data:
+ ds->br = bre;
+ ds->blocks_avail = blocks_avail;
+ ds->state = state;
+ ds->w_pos = w_pos;
+ return (ARCHIVE_OK);
+}
+
+static int
+lzh_huffman_init(struct huffman *hf, size_t len_size, int tbl_bits)
+{
+ int bits;
+
+ if (hf->bitlen == NULL) {
+ hf->bitlen = malloc(len_size * sizeof(hf->bitlen[0]));
+ if (hf->bitlen == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ if (hf->tbl == NULL) {
+ if (tbl_bits < HTBL_BITS)
+ bits = tbl_bits;
+ else
+ bits = HTBL_BITS;
+ hf->tbl = malloc(((size_t)1 << bits) * sizeof(hf->tbl[0]));
+ if (hf->tbl == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ if (hf->tree == NULL && tbl_bits > HTBL_BITS) {
+ hf->tree_avail = 1 << (tbl_bits - HTBL_BITS + 4);
+ hf->tree = malloc(hf->tree_avail * sizeof(hf->tree[0]));
+ if (hf->tree == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ hf->len_size = (int)len_size;
+ hf->tbl_bits = tbl_bits;
+ return (ARCHIVE_OK);
+}
+
+static void
+lzh_huffman_free(struct huffman *hf)
+{
+ free(hf->bitlen);
+ free(hf->tbl);
+ free(hf->tree);
+}
+
+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);
+ int c, i;
+
+ for (i = start; i < end;) {
+ /*
+ * bit pattern the number we need
+ * 000 -> 0
+ * 001 -> 1
+ * 010 -> 2
+ * ...
+ * 110 -> 6
+ * 1110 -> 7
+ * 11110 -> 8
+ * ...
+ * 1111111111110 -> 16
+ */
+ 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)
+ return (-1);/* Invalid data. */
+ lzh_br_consume(br, c - 3);
+ } else
+ lzh_br_consume(br, 3);
+ ds->pt.bitlen[i++] = c;
+ ds->pt.freq[c]++;
+ }
+ return (i);
+}
+
+static int
+lzh_make_fake_table(struct huffman *hf, uint16_t c)
+{
+ if (c >= hf->len_size)
+ return (0);
+ hf->tbl[0] = c;
+ hf->max_bits = 0;
+ hf->shift_bits = 0;
+ hf->bitlen[hf->tbl[0]] = 0;
+ return (1);
+}
+
+/*
+ * Make a huffman coding table.
+ */
+static int
+lzh_make_huffman_table(struct huffman *hf)
+{
+ uint16_t *tbl;
+ const unsigned char *bitlen;
+ int bitptn[17], weight[17];
+ int i, maxbits = 0, ptn, tbl_size, w;
+ int diffbits, len_avail;
+
+ /*
+ * Initialize bit patterns.
+ */
+ ptn = 0;
+ for (i = 1, w = 1 << 15; i <= 16; i++, w >>= 1) {
+ bitptn[i] = ptn;
+ weight[i] = w;
+ if (hf->freq[i]) {
+ ptn += hf->freq[i] * w;
+ maxbits = i;
+ }
+ }
+ if (ptn != 0x10000 || maxbits > hf->tbl_bits)
+ return (0);/* Invalid */
+
+ hf->max_bits = maxbits;
+
+ /*
+ * Cut out extra bits which we won't house in the table.
+ * This preparation reduces the same calculation in the for-loop
+ * making the table.
+ */
+ if (maxbits < 16) {
+ int ebits = 16 - maxbits;
+ for (i = 1; i <= maxbits; i++) {
+ bitptn[i] >>= ebits;
+ weight[i] >>= ebits;
+ }
+ }
+ if (maxbits > HTBL_BITS) {
+ int htbl_max;
+ uint16_t *p;
+
+ diffbits = maxbits - HTBL_BITS;
+ for (i = 1; i <= HTBL_BITS; i++) {
+ bitptn[i] >>= diffbits;
+ weight[i] >>= diffbits;
+ }
+ htbl_max = bitptn[HTBL_BITS] +
+ weight[HTBL_BITS] * hf->freq[HTBL_BITS];
+ p = &(hf->tbl[htbl_max]);
+ while (p < &hf->tbl[1U<<HTBL_BITS])
+ *p++ = 0;
+ } else
+ diffbits = 0;
+ hf->shift_bits = diffbits;
+
+ /*
+ * Make the table.
+ */
+ tbl_size = 1 << HTBL_BITS;
+ tbl = hf->tbl;
+ bitlen = hf->bitlen;
+ len_avail = hf->len_avail;
+ hf->tree_used = 0;
+ for (i = 0; i < len_avail; i++) {
+ uint16_t *p;
+ int len, cnt;
+ uint16_t bit;
+ int extlen;
+ struct htree_t *ht;
+
+ if (bitlen[i] == 0)
+ continue;
+ /* Get a bit pattern */
+ len = bitlen[i];
+ ptn = bitptn[len];
+ cnt = weight[len];
+ if (len <= HTBL_BITS) {
+ /* Calculate next bit pattern */
+ if ((bitptn[len] = ptn + cnt) > tbl_size)
+ return (0);/* Invalid */
+ /* Update the table */
+ p = &(tbl[ptn]);
+ while (--cnt >= 0)
+ p[cnt] = (uint16_t)i;
+ continue;
+ }
+
+ /*
+ * A bit length is too big to be housed to a direct table,
+ * so we use a tree model for its extra bits.
+ */
+ bitptn[len] = ptn + cnt;
+ bit = 1U << (diffbits -1);
+ extlen = len - HTBL_BITS;
+
+ p = &(tbl[ptn >> diffbits]);
+ if (*p == 0) {
+ *p = len_avail + hf->tree_used;
+ ht = &(hf->tree[hf->tree_used++]);
+ if (hf->tree_used > hf->tree_avail)
+ return (0);/* Invalid */
+ ht->left = 0;
+ ht->right = 0;
+ } else {
+ if (*p < len_avail ||
+ *p >= (len_avail + hf->tree_used))
+ return (0);/* Invalid */
+ ht = &(hf->tree[*p - len_avail]);
+ }
+ while (--extlen > 0) {
+ if (ptn & bit) {
+ if (ht->left < len_avail) {
+ ht->left = len_avail + hf->tree_used;
+ ht = &(hf->tree[hf->tree_used++]);
+ if (hf->tree_used > hf->tree_avail)
+ return (0);/* Invalid */
+ ht->left = 0;
+ ht->right = 0;
+ } else {
+ ht = &(hf->tree[ht->left - len_avail]);
+ }
+ } else {
+ if (ht->right < len_avail) {
+ ht->right = len_avail + hf->tree_used;
+ ht = &(hf->tree[hf->tree_used++]);
+ if (hf->tree_used > hf->tree_avail)
+ return (0);/* Invalid */
+ ht->left = 0;
+ ht->right = 0;
+ } else {
+ ht = &(hf->tree[ht->right - len_avail]);
+ }
+ }
+ bit >>= 1;
+ }
+ if (ptn & bit) {
+ if (ht->left != 0)
+ return (0);/* Invalid */
+ ht->left = (uint16_t)i;
+ } else {
+ if (ht->right != 0)
+ return (0);/* Invalid */
+ ht->right = (uint16_t)i;
+ }
+ }
+ return (1);
+}
+
+static int
+lzh_decode_huffman_tree(struct huffman *hf, unsigned rbits, int c)
+{
+ struct htree_t *ht;
+ int extlen;
+
+ ht = hf->tree;
+ extlen = hf->shift_bits;
+ while (c >= hf->len_avail) {
+ c -= hf->len_avail;
+ if (extlen-- <= 0 || c >= hf->tree_used)
+ return (0);
+ if (rbits & (1U << extlen))
+ c = ht[c].left;
+ else
+ c = ht[c].right;
+ }
+ return (c);
+}
+
+static inline int
+lzh_decode_huffman(struct huffman *hf, unsigned rbits)
+{
+ int c;
+ /*
+ * At first search an index table for a bit pattern.
+ * If it fails, search a huffman tree for.
+ */
+ c = hf->tbl[rbits >> hf->shift_bits];
+ if (c < hf->len_avail)
+ 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
new file mode 100644
index 0000000000..d82d4c1573
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c
@@ -0,0 +1,1972 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2008 Joerg Sonnenberger
+ * Copyright (c) 2011-2012 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: head/lib/libarchive/archive_read_support_format_mtree.c 201165 2009-12-29 05:52:13Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#include <stddef.h>
+/* #include <stdint.h> */ /* See archive_platform.h */
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+#include "archive_string.h"
+#include "archive_pack_dev.h"
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
+#define MTREE_HAS_DEVICE 0x0001
+#define MTREE_HAS_FFLAGS 0x0002
+#define MTREE_HAS_GID 0x0004
+#define MTREE_HAS_GNAME 0x0008
+#define MTREE_HAS_MTIME 0x0010
+#define MTREE_HAS_NLINK 0x0020
+#define MTREE_HAS_PERM 0x0040
+#define MTREE_HAS_SIZE 0x0080
+#define MTREE_HAS_TYPE 0x0100
+#define MTREE_HAS_UID 0x0200
+#define MTREE_HAS_UNAME 0x0400
+
+#define MTREE_HAS_OPTIONAL 0x0800
+#define MTREE_HAS_NOCHANGE 0x1000 /* FreeBSD specific */
+
+struct mtree_option {
+ struct mtree_option *next;
+ char *value;
+};
+
+struct mtree_entry {
+ struct mtree_entry *next;
+ struct mtree_option *options;
+ char *name;
+ char full;
+ char used;
+};
+
+struct mtree {
+ struct archive_string line;
+ size_t buffsize;
+ char *buff;
+ int64_t offset;
+ int fd;
+ int archive_format;
+ const char *archive_format_name;
+ struct mtree_entry *entries;
+ struct mtree_entry *this_entry;
+ struct archive_string current_dir;
+ struct archive_string contents_name;
+
+ struct archive_entry_linkresolver *resolver;
+
+ int64_t cur_size;
+ char checkfs;
+};
+
+static int bid_keycmp(const char *, const char *, ssize_t);
+static int cleanup(struct archive_read *);
+static int detect_form(struct archive_read *, int *);
+static int mtree_bid(struct archive_read *, int);
+static int parse_file(struct archive_read *, struct archive_entry *,
+ struct mtree *, struct mtree_entry *, int *);
+static void parse_escapes(char *, struct mtree_entry *);
+static int parse_line(struct archive_read *, struct archive_entry *,
+ struct mtree *, struct mtree_entry *, int *);
+static int parse_keyword(struct archive_read *, struct mtree *,
+ struct archive_entry *, struct mtree_option *, int *);
+static int read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset);
+static ssize_t readline(struct archive_read *, struct mtree *, char **, ssize_t);
+static int skip(struct archive_read *a);
+static int read_header(struct archive_read *,
+ struct archive_entry *);
+static int64_t mtree_atol10(char **);
+static int64_t mtree_atol8(char **);
+static int64_t mtree_atol(char **);
+
+/*
+ * There's no standard for TIME_T_MAX/TIME_T_MIN. So we compute them
+ * here. TODO: Move this to configure time, but be careful
+ * about cross-compile environments.
+ */
+static int64_t
+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;
+ }
+ }
+ return t;
+#endif
+}
+
+static int64_t
+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;
+ }
+ return t;
+#endif
+}
+
+static int
+archive_read_format_mtree_options(struct archive_read *a,
+ const char *key, const char *val)
+{
+ struct mtree *mtree;
+
+ mtree = (struct mtree *)(a->format->data);
+ if (strcmp(key, "checkfs") == 0) {
+ /* Allows to read information missing from the mtree from the file system */
+ if (val == NULL || val[0] == 0) {
+ mtree->checkfs = 0;
+ } else {
+ mtree->checkfs = 1;
+ }
+ 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 void
+free_options(struct mtree_option *head)
+{
+ struct mtree_option *next;
+
+ for (; head != NULL; head = next) {
+ next = head->next;
+ free(head->value);
+ free(head);
+ }
+}
+
+int
+archive_read_support_format_mtree(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct mtree *mtree;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_mtree");
+
+ mtree = (struct mtree *)malloc(sizeof(*mtree));
+ if (mtree == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate mtree data");
+ return (ARCHIVE_FATAL);
+ }
+ memset(mtree, 0, sizeof(*mtree));
+ mtree->fd = -1;
+
+ r = __archive_read_register_format(a, mtree, "mtree",
+ mtree_bid, archive_read_format_mtree_options, read_header, read_data, skip, NULL, cleanup, NULL, NULL);
+
+ if (r != ARCHIVE_OK)
+ free(mtree);
+ return (ARCHIVE_OK);
+}
+
+static int
+cleanup(struct archive_read *a)
+{
+ struct mtree *mtree;
+ struct mtree_entry *p, *q;
+
+ mtree = (struct mtree *)(a->format->data);
+
+ p = mtree->entries;
+ while (p != NULL) {
+ q = p->next;
+ free(p->name);
+ free_options(p->options);
+ free(p);
+ p = q;
+ }
+ archive_string_free(&mtree->line);
+ archive_string_free(&mtree->current_dir);
+ archive_string_free(&mtree->contents_name);
+ archive_entry_linkresolver_free(mtree->resolver);
+
+ free(mtree->buff);
+ free(mtree);
+ (a->format->data) = NULL;
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+get_line_size(const char *b, ssize_t avail, ssize_t *nlsize)
+{
+ ssize_t len;
+
+ len = 0;
+ while (len < avail) {
+ switch (*b) {
+ case '\0':/* Non-ascii character or control character. */
+ if (nlsize != NULL)
+ *nlsize = 0;
+ return (-1);
+ case '\r':
+ if (avail-len > 1 && b[1] == '\n') {
+ if (nlsize != NULL)
+ *nlsize = 2;
+ return (len+2);
+ }
+ /* FALL THROUGH */
+ case '\n':
+ if (nlsize != NULL)
+ *nlsize = 1;
+ return (len+1);
+ default:
+ b++;
+ len++;
+ break;
+ }
+ }
+ if (nlsize != NULL)
+ *nlsize = 0;
+ return (avail);
+}
+
+static ssize_t
+next_line(struct archive_read *a,
+ const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl)
+{
+ ssize_t len;
+ int quit;
+
+ quit = 0;
+ if (*avail == 0) {
+ *nl = 0;
+ len = 0;
+ } else
+ len = get_line_size(*b, *avail, nl);
+ /*
+ * Read bytes more while it does not reach the end of line.
+ */
+ while (*nl == 0 && len == *avail && !quit) {
+ ssize_t diff = *ravail - *avail;
+ size_t nbytes_req = (*ravail+1023) & ~1023U;
+ ssize_t tested;
+
+ /* Increase reading bytes if it is not enough to at least
+ * new two lines. */
+ if (nbytes_req < (size_t)*ravail + 160)
+ nbytes_req <<= 1;
+
+ *b = __archive_read_ahead(a, nbytes_req, avail);
+ if (*b == NULL) {
+ if (*ravail >= *avail)
+ return (0);
+ /* Reading bytes reaches the end of file. */
+ *b = __archive_read_ahead(a, *avail, avail);
+ quit = 1;
+ }
+ *ravail = *avail;
+ *b += diff;
+ *avail -= diff;
+ tested = len;/* Skip some bytes we already determinated. */
+ len = get_line_size(*b, *avail, nl);
+ if (len >= 0)
+ len += tested;
+ }
+ return (len);
+}
+
+/*
+ * Compare characters with a mtree keyword.
+ * Returns the length of a mtree keyword if matched.
+ * Returns 0 if not matched.
+ */
+static int
+bid_keycmp(const char *p, const char *key, ssize_t len)
+{
+ int match_len = 0;
+
+ while (len > 0 && *p && *key) {
+ if (*p == *key) {
+ --len;
+ ++p;
+ ++key;
+ ++match_len;
+ continue;
+ }
+ return (0);/* Not match */
+ }
+ if (*key != '\0')
+ return (0);/* Not match */
+
+ /* A following character should be specified characters */
+ if (p[0] == '=' || p[0] == ' ' || p[0] == '\t' ||
+ p[0] == '\n' || p[0] == '\r' ||
+ (p[0] == '\\' && (p[1] == '\n' || p[1] == '\r')))
+ return (match_len);
+ return (0);/* Not match */
+}
+
+/*
+ * Test whether the characters 'p' has is mtree keyword.
+ * Returns the length of a detected keyword.
+ * Returns 0 if any keywords were not found.
+ */
+static int
+bid_keyword(const char *p, ssize_t len)
+{
+ static const char *keys_c[] = {
+ "content", "contents", "cksum", NULL
+ };
+ static const char *keys_df[] = {
+ "device", "flags", NULL
+ };
+ static const char *keys_g[] = {
+ "gid", "gname", NULL
+ };
+ static const char *keys_il[] = {
+ "ignore", "inode", "link", NULL
+ };
+ static const char *keys_m[] = {
+ "md5", "md5digest", "mode", NULL
+ };
+ static const char *keys_no[] = {
+ "nlink", "nochange", "optional", NULL
+ };
+ static const char *keys_r[] = {
+ "resdevice", "rmd160", "rmd160digest", NULL
+ };
+ static const char *keys_s[] = {
+ "sha1", "sha1digest",
+ "sha256", "sha256digest",
+ "sha384", "sha384digest",
+ "sha512", "sha512digest",
+ "size", NULL
+ };
+ static const char *keys_t[] = {
+ "tags", "time", "type", NULL
+ };
+ static const char *keys_u[] = {
+ "uid", "uname", NULL
+ };
+ const char **keys;
+ int i;
+
+ switch (*p) {
+ case 'c': keys = keys_c; break;
+ case 'd': case 'f': keys = keys_df; break;
+ case 'g': keys = keys_g; break;
+ case 'i': case 'l': keys = keys_il; break;
+ case 'm': keys = keys_m; break;
+ case 'n': case 'o': keys = keys_no; break;
+ case 'r': keys = keys_r; break;
+ case 's': keys = keys_s; break;
+ case 't': keys = keys_t; break;
+ case 'u': keys = keys_u; break;
+ default: return (0);/* Unknown key */
+ }
+
+ for (i = 0; keys[i] != NULL; i++) {
+ int l = bid_keycmp(p, keys[i], len);
+ if (l > 0)
+ return (l);
+ }
+ return (0);/* Unknown key */
+}
+
+/*
+ * Test whether there is a set of mtree keywords.
+ * Returns the number of keyword.
+ * Returns -1 if we got incorrect sequence.
+ * This function expects a set of "<space characters>keyword=value".
+ * When "unset" is specified, expects a set of "<space characters>keyword".
+ */
+static int
+bid_keyword_list(const char *p, ssize_t len, int unset, int last_is_path)
+{
+ int l;
+ int keycnt = 0;
+
+ while (len > 0 && *p) {
+ int blank = 0;
+
+ /* Test whether there are blank characters in the line. */
+ while (len >0 && (*p == ' ' || *p == '\t')) {
+ ++p;
+ --len;
+ blank = 1;
+ }
+ if (*p == '\n' || *p == '\r')
+ break;
+ if (p[0] == '\\' && (p[1] == '\n' || p[1] == '\r'))
+ break;
+ if (!blank && !last_is_path) /* No blank character. */
+ return (-1);
+ if (last_is_path && len == 0)
+ return (keycnt);
+
+ if (unset) {
+ l = bid_keycmp(p, "all", len);
+ if (l > 0)
+ return (1);
+ }
+ /* Test whether there is a correct key in the line. */
+ l = bid_keyword(p, len);
+ if (l == 0)
+ return (-1);/* Unknown keyword was found. */
+ p += l;
+ len -= l;
+ keycnt++;
+
+ /* Skip value */
+ if (*p == '=') {
+ int value = 0;
+ ++p;
+ --len;
+ while (len > 0 && *p != ' ' && *p != '\t') {
+ ++p;
+ --len;
+ value = 1;
+ }
+ /* A keyword should have a its value unless
+ * "/unset" operation. */
+ if (!unset && value == 0)
+ return (-1);
+ }
+ }
+ return (keycnt);
+}
+
+static int
+bid_entry(const char *p, ssize_t len, ssize_t nl, int *last_is_path)
+{
+ int f = 0;
+ static const unsigned char safe_char[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */
+ /* !"$%&'()*+,-./ EXCLUSION:( )(#) */
+ 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */
+ /* 0123456789:;<>? EXCLUSION:(=) */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, /* 30 - 3F */
+ /* @ABCDEFGHIJKLMNO */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */
+ /* PQRSTUVWXYZ[\]^_ */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */
+ /* `abcdefghijklmno */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */
+ /* pqrstuvwxyz{|}~ */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, /* 70 - 7F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */
+ 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;
+ const char *pp = p;
+
+ *last_is_path = 0;
+ /*
+ * Skip the path-name which is quoted.
+ */
+ while (ll > 0 && *pp != ' ' &&*pp != '\t' && *pp != '\r' &&
+ *pp != '\n') {
+ if (!safe_char[*(const unsigned char *)pp]) {
+ f = 0;
+ break;
+ }
+ ++pp;
+ --ll;
+ ++f;
+ }
+ /* 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. */
+ if (f == 0) {
+ const char *pb = p + len - nl;
+ int name_len = 0;
+ int slash;
+
+ /* Do not accept multi lines for form D. */
+ if (pb-2 >= p &&
+ pb[-1] == '\\' && (pb[-2] == ' ' || pb[-2] == '\t'))
+ return (-1);
+ if (pb-1 >= p && pb[-1] == '\\')
+ return (-1);
+
+ slash = 0;
+ while (p <= --pb && *pb != ' ' && *pb != '\t') {
+ if (!safe_char[*(const unsigned char *)pb])
+ return (-1);
+ name_len++;
+ /* The pathname should have a slash in this
+ * format. */
+ if (*pb == '/')
+ slash = 1;
+ }
+ if (name_len == 0 || slash == 0)
+ return (-1);
+ /* If '/' is placed at the first in this field, this is not
+ * a valid filename. */
+ if (pb[1] == '/')
+ return (-1);
+ ll = len - nl - name_len;
+ pp = p;
+ *last_is_path = 1;
+ }
+
+ return (bid_keyword_list(pp, ll, 0, *last_is_path));
+}
+
+#define MAX_BID_ENTRY 3
+
+static int
+mtree_bid(struct archive_read *a, int best_bid)
+{
+ const char *signature = "#mtree";
+ const char *p;
+
+ (void)best_bid; /* UNUSED */
+
+ /* Now let's look at the actual header and see if it matches. */
+ p = __archive_read_ahead(a, strlen(signature), NULL);
+ if (p == NULL)
+ return (-1);
+
+ if (memcmp(p, signature, strlen(signature)) == 0)
+ return (8 * (int)strlen(signature));
+
+ /*
+ * There is not a mtree signature. Let's try to detect mtree format.
+ */
+ return (detect_form(a, NULL));
+}
+
+static int
+detect_form(struct archive_read *a, int *is_form_d)
+{
+ const char *p;
+ ssize_t avail, ravail;
+ ssize_t detected_bytes = 0, len, nl;
+ int entry_cnt = 0, multiline = 0;
+ int form_D = 0;/* The archive is generated by `NetBSD mtree -D'
+ * (In this source we call it `form D') . */
+
+ if (is_form_d != NULL)
+ *is_form_d = 0;
+ p = __archive_read_ahead(a, 1, &avail);
+ if (p == NULL)
+ return (-1);
+ ravail = avail;
+ for (;;) {
+ len = next_line(a, &p, &avail, &ravail, &nl);
+ /* The terminal character of the line should be
+ * a new line character, '\r\n' or '\n'. */
+ if (len <= 0 || nl == 0)
+ break;
+ if (!multiline) {
+ /* Leading whitespace is never significant,
+ * ignore it. */
+ while (len > 0 && (*p == ' ' || *p == '\t')) {
+ ++p;
+ --avail;
+ --len;
+ }
+ /* Skip comment or empty line. */
+ if (p[0] == '#' || p[0] == '\n' || p[0] == '\r') {
+ p += len;
+ avail -= len;
+ continue;
+ }
+ } else {
+ /* A continuance line; the terminal
+ * character of previous line was '\' character. */
+ if (bid_keyword_list(p, len, 0, 0) <= 0)
+ break;
+ if (multiline == 1)
+ detected_bytes += len;
+ if (p[len-nl-1] != '\\') {
+ if (multiline == 1 &&
+ ++entry_cnt >= MAX_BID_ENTRY)
+ break;
+ multiline = 0;
+ }
+ p += len;
+ avail -= len;
+ continue;
+ }
+ if (p[0] != '/') {
+ int last_is_path, keywords;
+
+ keywords = bid_entry(p, len, nl, &last_is_path);
+ if (keywords >= 0) {
+ detected_bytes += len;
+ if (form_D == 0) {
+ if (last_is_path)
+ form_D = 1;
+ else if (keywords > 0)
+ /* This line is not `form D'. */
+ form_D = -1;
+ } else if (form_D == 1) {
+ if (!last_is_path && keywords > 0)
+ /* This this is not `form D'
+ * and We cannot accept mixed
+ * format. */
+ break;
+ }
+ if (!last_is_path && p[len-nl-1] == '\\')
+ /* This line continues. */
+ multiline = 1;
+ else {
+ /* We've got plenty of correct lines
+ * to assume that this file is a mtree
+ * format. */
+ if (++entry_cnt >= MAX_BID_ENTRY)
+ break;
+ }
+ } else
+ break;
+ } else if (strncmp(p, "/set", 4) == 0) {
+ if (bid_keyword_list(p+4, len-4, 0, 0) <= 0)
+ break;
+ /* This line continues. */
+ if (p[len-nl-1] == '\\')
+ multiline = 2;
+ } else if (strncmp(p, "/unset", 6) == 0) {
+ if (bid_keyword_list(p+6, len-6, 1, 0) <= 0)
+ break;
+ /* This line continues. */
+ if (p[len-nl-1] == '\\')
+ multiline = 2;
+ } else
+ break;
+
+ /* Test next line. */
+ p += len;
+ avail -= len;
+ }
+ if (entry_cnt >= MAX_BID_ENTRY || (entry_cnt > 0 && len == 0)) {
+ if (is_form_d != NULL) {
+ if (form_D == 1)
+ *is_form_d = 1;
+ }
+ return (32);
+ }
+
+ return (0);
+}
+
+/*
+ * The extended mtree format permits multiple lines specifying
+ * attributes for each file. For those entries, only the last line
+ * is actually used. Practically speaking, that means we have
+ * to read the entire mtree file into memory up front.
+ *
+ * The parsing is done in two steps. First, it is decided if a line
+ * changes the global defaults and if it is, processed accordingly.
+ * Otherwise, the options of the line are merged with the current
+ * global options.
+ */
+static int
+add_option(struct archive_read *a, struct mtree_option **global,
+ const char *value, size_t len)
+{
+ struct mtree_option *opt;
+
+ if ((opt = malloc(sizeof(*opt))) == NULL) {
+ archive_set_error(&a->archive, errno, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ if ((opt->value = malloc(len + 1)) == NULL) {
+ free(opt);
+ archive_set_error(&a->archive, errno, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(opt->value, value, len);
+ opt->value[len] = '\0';
+ opt->next = *global;
+ *global = opt;
+ return (ARCHIVE_OK);
+}
+
+static void
+remove_option(struct mtree_option **global, const char *value, size_t len)
+{
+ struct mtree_option *iter, *last;
+
+ last = NULL;
+ for (iter = *global; iter != NULL; last = iter, iter = iter->next) {
+ if (strncmp(iter->value, value, len) == 0 &&
+ (iter->value[len] == '\0' ||
+ iter->value[len] == '='))
+ break;
+ }
+ if (iter == NULL)
+ return;
+ if (last == NULL)
+ *global = iter->next;
+ else
+ last->next = iter->next;
+
+ free(iter->value);
+ free(iter);
+}
+
+static int
+process_global_set(struct archive_read *a,
+ struct mtree_option **global, const char *line)
+{
+ const char *next, *eq;
+ size_t len;
+ int r;
+
+ line += 4;
+ for (;;) {
+ next = line + strspn(line, " \t\r\n");
+ if (*next == '\0')
+ return (ARCHIVE_OK);
+ line = next;
+ next = line + strcspn(line, " \t\r\n");
+ eq = strchr(line, '=');
+ if (eq > next)
+ len = next - line;
+ else
+ len = eq - line;
+
+ remove_option(global, line, len);
+ r = add_option(a, global, line, next - line);
+ if (r != ARCHIVE_OK)
+ return (r);
+ line = next;
+ }
+}
+
+static int
+process_global_unset(struct archive_read *a,
+ struct mtree_option **global, const char *line)
+{
+ const char *next;
+ size_t len;
+
+ line += 6;
+ if (strchr(line, '=') != NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "/unset shall not contain `='");
+ return ARCHIVE_FATAL;
+ }
+
+ for (;;) {
+ next = line + strspn(line, " \t\r\n");
+ if (*next == '\0')
+ return (ARCHIVE_OK);
+ line = next;
+ len = strcspn(line, " \t\r\n");
+
+ if (len == 3 && strncmp(line, "all", 3) == 0) {
+ free_options(*global);
+ *global = NULL;
+ } else {
+ remove_option(global, line, len);
+ }
+
+ line += len;
+ }
+}
+
+static int
+process_add_entry(struct archive_read *a, struct mtree *mtree,
+ struct mtree_option **global, const char *line, ssize_t line_len,
+ struct mtree_entry **last_entry, int is_form_d)
+{
+ struct mtree_entry *entry;
+ struct mtree_option *iter;
+ const char *next, *eq, *name, *end;
+ size_t len;
+ int r;
+
+ if ((entry = malloc(sizeof(*entry))) == NULL) {
+ archive_set_error(&a->archive, errno, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ entry->next = NULL;
+ entry->options = NULL;
+ entry->name = NULL;
+ entry->used = 0;
+ entry->full = 0;
+
+ /* Add this entry to list. */
+ if (*last_entry == NULL)
+ mtree->entries = entry;
+ else
+ (*last_entry)->next = entry;
+ *last_entry = entry;
+
+ if (is_form_d) {
+ /*
+ * This form places the file name as last parameter.
+ */
+ name = line + line_len -1;
+ while (line_len > 0) {
+ if (*name != '\r' && *name != '\n' &&
+ *name != '\t' && *name != ' ')
+ break;
+ name--;
+ line_len--;
+ }
+ len = 0;
+ while (line_len > 0) {
+ if (*name == '\r' || *name == '\n' ||
+ *name == '\t' || *name == ' ') {
+ name++;
+ break;
+ }
+ name--;
+ line_len--;
+ len++;
+ }
+ end = name;
+ } else {
+ len = strcspn(line, " \t\r\n");
+ name = line;
+ line += len;
+ end = line + line_len;
+ }
+
+ if ((entry->name = malloc(len + 1)) == NULL) {
+ archive_set_error(&a->archive, errno, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ memcpy(entry->name, name, len);
+ entry->name[len] = '\0';
+ parse_escapes(entry->name, entry);
+
+ for (iter = *global; iter != NULL; iter = iter->next) {
+ r = add_option(a, &entry->options, iter->value,
+ strlen(iter->value));
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+
+ for (;;) {
+ next = line + strspn(line, " \t\r\n");
+ if (*next == '\0')
+ return (ARCHIVE_OK);
+ if (next >= end)
+ return (ARCHIVE_OK);
+ line = next;
+ next = line + strcspn(line, " \t\r\n");
+ eq = strchr(line, '=');
+ if (eq == NULL || eq > next)
+ len = next - line;
+ else
+ len = eq - line;
+
+ remove_option(&entry->options, line, len);
+ r = add_option(a, &entry->options, line, next - line);
+ if (r != ARCHIVE_OK)
+ return (r);
+ line = next;
+ }
+}
+
+static int
+read_mtree(struct archive_read *a, struct mtree *mtree)
+{
+ ssize_t len;
+ uintmax_t counter;
+ char *p;
+ struct mtree_option *global;
+ struct mtree_entry *last_entry;
+ int r, is_form_d;
+
+ mtree->archive_format = ARCHIVE_FORMAT_MTREE;
+ mtree->archive_format_name = "mtree";
+
+ global = NULL;
+ last_entry = NULL;
+
+ (void)detect_form(a, &is_form_d);
+
+ for (counter = 1; ; ++counter) {
+ len = readline(a, mtree, &p, 65536);
+ if (len == 0) {
+ mtree->this_entry = mtree->entries;
+ free_options(global);
+ return (ARCHIVE_OK);
+ }
+ if (len < 0) {
+ free_options(global);
+ return ((int)len);
+ }
+ /* Leading whitespace is never significant, ignore it. */
+ while (*p == ' ' || *p == '\t') {
+ ++p;
+ --len;
+ }
+ /* Skip content lines and blank lines. */
+ if (*p == '#')
+ continue;
+ if (*p == '\r' || *p == '\n' || *p == '\0')
+ continue;
+ if (*p != '/') {
+ r = process_add_entry(a, mtree, &global, p, len,
+ &last_entry, is_form_d);
+ } else if (strncmp(p, "/set", 4) == 0) {
+ if (p[4] != ' ' && p[4] != '\t')
+ break;
+ r = process_global_set(a, &global, p);
+ } else if (strncmp(p, "/unset", 6) == 0) {
+ if (p[6] != ' ' && p[6] != '\t')
+ break;
+ r = process_global_unset(a, &global, p);
+ } else
+ break;
+
+ if (r != ARCHIVE_OK) {
+ free_options(global);
+ return r;
+ }
+ }
+
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't parse line %ju", counter);
+ free_options(global);
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Read in the entire mtree file into memory on the first request.
+ * Then use the next unused file to satisfy each header request.
+ */
+static int
+read_header(struct archive_read *a, struct archive_entry *entry)
+{
+ struct mtree *mtree;
+ char *p;
+ int r, use_next;
+
+ mtree = (struct mtree *)(a->format->data);
+
+ if (mtree->fd >= 0) {
+ close(mtree->fd);
+ mtree->fd = -1;
+ }
+
+ if (mtree->entries == NULL) {
+ mtree->resolver = archive_entry_linkresolver_new();
+ if (mtree->resolver == NULL)
+ return ARCHIVE_FATAL;
+ archive_entry_linkresolver_set_strategy(mtree->resolver,
+ ARCHIVE_FORMAT_MTREE);
+ r = read_mtree(a, mtree);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+
+ a->archive.archive_format = mtree->archive_format;
+ a->archive.archive_format_name = mtree->archive_format_name;
+
+ for (;;) {
+ if (mtree->this_entry == NULL)
+ return (ARCHIVE_EOF);
+ if (strcmp(mtree->this_entry->name, "..") == 0) {
+ mtree->this_entry->used = 1;
+ if (archive_strlen(&mtree->current_dir) > 0) {
+ /* Roll back current path. */
+ p = mtree->current_dir.s
+ + mtree->current_dir.length - 1;
+ while (p >= mtree->current_dir.s && *p != '/')
+ --p;
+ if (p >= mtree->current_dir.s)
+ --p;
+ mtree->current_dir.length
+ = p - mtree->current_dir.s + 1;
+ }
+ }
+ if (!mtree->this_entry->used) {
+ use_next = 0;
+ r = parse_file(a, entry, mtree, mtree->this_entry, &use_next);
+ if (use_next == 0)
+ return (r);
+ }
+ mtree->this_entry = mtree->this_entry->next;
+ }
+}
+
+/*
+ * A single file can have multiple lines contribute specifications.
+ * Parse as many lines as necessary, then pull additional information
+ * from a backing file on disk as necessary.
+ */
+static int
+parse_file(struct archive_read *a, struct archive_entry *entry,
+ struct mtree *mtree, struct mtree_entry *mentry, int *use_next)
+{
+ const char *path;
+ struct stat st_storage, *st;
+ struct mtree_entry *mp;
+ struct archive_entry *sparse_entry;
+ int r = ARCHIVE_OK, r1, parsed_kws;
+
+ mentry->used = 1;
+
+ /* Initialize reasonable defaults. */
+ archive_entry_set_filetype(entry, AE_IFREG);
+ archive_entry_set_size(entry, 0);
+ archive_string_empty(&mtree->contents_name);
+
+ /* Parse options from this line. */
+ parsed_kws = 0;
+ r = parse_line(a, entry, mtree, mentry, &parsed_kws);
+
+ if (mentry->full) {
+ archive_entry_copy_pathname(entry, mentry->name);
+ /*
+ * "Full" entries are allowed to have multiple lines
+ * and those lines aren't required to be adjacent. We
+ * don't support multiple lines for "relative" entries
+ * nor do we make any attempt to merge data from
+ * separate "relative" and "full" entries. (Merging
+ * "relative" and "full" entries would require dealing
+ * with pathname canonicalization, which is a very
+ * tricky subject.)
+ */
+ for (mp = mentry->next; mp != NULL; mp = mp->next) {
+ if (mp->full && !mp->used
+ && strcmp(mentry->name, mp->name) == 0) {
+ /* Later lines override earlier ones. */
+ mp->used = 1;
+ r1 = parse_line(a, entry, mtree, mp,
+ &parsed_kws);
+ if (r1 < r)
+ r = r1;
+ }
+ }
+ } else {
+ /*
+ * Relative entries require us to construct
+ * the full path and possibly update the
+ * current directory.
+ */
+ size_t n = archive_strlen(&mtree->current_dir);
+ if (n > 0)
+ archive_strcat(&mtree->current_dir, "/");
+ archive_strcat(&mtree->current_dir, mentry->name);
+ archive_entry_copy_pathname(entry, mtree->current_dir.s);
+ if (archive_entry_filetype(entry) != AE_IFDIR)
+ mtree->current_dir.length = n;
+ }
+
+ if (mtree->checkfs) {
+ /*
+ * Try to open and stat the file to get the real size
+ * and other file info. It would be nice to avoid
+ * this here so that getting a listing of an mtree
+ * wouldn't require opening every referenced contents
+ * file. But then we wouldn't know the actual
+ * contents size, so I don't see a really viable way
+ * around this. (Also, we may want to someday pull
+ * other unspecified info from the contents file on
+ * disk.)
+ */
+ mtree->fd = -1;
+ if (archive_strlen(&mtree->contents_name) > 0)
+ path = mtree->contents_name.s;
+ else
+ path = archive_entry_pathname(entry);
+
+ if (archive_entry_filetype(entry) == AE_IFREG ||
+ archive_entry_filetype(entry) == AE_IFDIR) {
+ 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)) {
+ archive_set_error(&a->archive, errno,
+ "Can't open %s", path);
+ r = ARCHIVE_WARN;
+ }
+ }
+
+ st = &st_storage;
+ if (mtree->fd >= 0) {
+ if (fstat(mtree->fd, st) == -1) {
+ archive_set_error(&a->archive, errno,
+ "Could not fstat %s", path);
+ r = ARCHIVE_WARN;
+ /* If we can't stat it, don't keep it open. */
+ close(mtree->fd);
+ mtree->fd = -1;
+ st = NULL;
+ }
+ } else if (lstat(path, st) == -1) {
+ st = NULL;
+ }
+
+ /*
+ * 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)
+#ifdef S_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)
+#endif
+#ifdef S_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)
+#endif
+ || ((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)
+#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;
+ }
+ }
+
+ /*
+ * 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))
+ archive_entry_set_rdev(entry, st->st_rdev);
+ 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)
+ archive_entry_set_uid(entry, st->st_uid);
+ if ((parsed_kws & MTREE_HAS_MTIME) == 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);
+#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+ archive_entry_set_mtime(entry, st->st_mtime,
+ st->st_mtim.tv_nsec);
+#elif HAVE_STRUCT_STAT_ST_MTIME_N
+ archive_entry_set_mtime(entry, st->st_mtime,
+ st->st_mtime_n);
+#elif HAVE_STRUCT_STAT_ST_UMTIME
+ archive_entry_set_mtime(entry, st->st_mtime,
+ st->st_umtime*1000);
+#elif HAVE_STRUCT_STAT_ST_MTIME_USEC
+ archive_entry_set_mtime(entry, st->st_mtime,
+ st->st_mtime_usec*1000);
+#else
+ archive_entry_set_mtime(entry, st->st_mtime, 0);
+#endif
+ }
+ if ((parsed_kws & MTREE_HAS_NLINK) == 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)
+ archive_entry_set_perm(entry, st->st_mode);
+ if ((parsed_kws & MTREE_HAS_SIZE) == 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);
+ } 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.
+ */
+ *use_next = 1;
+ return ARCHIVE_OK;
+ }
+ }
+
+ mtree->cur_size = archive_entry_size(entry);
+ mtree->offset = 0;
+
+ return r;
+}
+
+/*
+ * Each line contains a sequence of keywords.
+ */
+static int
+parse_line(struct archive_read *a, struct archive_entry *entry,
+ struct mtree *mtree, struct mtree_entry *mp, int *parsed_kws)
+{
+ struct mtree_option *iter;
+ int r = ARCHIVE_OK, r1;
+
+ for (iter = mp->options; iter != NULL; iter = iter->next) {
+ r1 = parse_keyword(a, mtree, entry, iter, parsed_kws);
+ if (r1 < r)
+ r = r1;
+ }
+ if (r == ARCHIVE_OK && (*parsed_kws & MTREE_HAS_TYPE) == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Missing type keyword in mtree specification");
+ return (ARCHIVE_WARN);
+ }
+ return (r);
+}
+
+/*
+ * Device entries have one of the following forms:
+ * - raw dev_t
+ * - format,major,minor[,subdevice]
+ * When parsing succeeded, `pdev' will contain the appropriate dev_t value.
+ */
+
+/* strsep() is not in C90, but strcspn() is. */
+/* Taken from http://unixpapa.com/incnote/string.html */
+static char *
+la_strsep(char **sp, char *sep)
+{
+ char *p, *s;
+ if (sp == NULL || *sp == NULL || **sp == '\0')
+ return(NULL);
+ s = *sp;
+ p = s + strcspn(s, sep);
+ if (*p != '\0')
+ *p++ = '\0';
+ *sp = p;
+ return(s);
+}
+
+static int
+parse_device(dev_t *pdev, struct archive *a, char *val)
+{
+#define MAX_PACK_ARGS 3
+ unsigned long numbers[MAX_PACK_ARGS];
+ char *p, *dev;
+ int argc;
+ pack_t *pack;
+ dev_t result;
+ const char *error = NULL;
+
+ memset(pdev, 0, sizeof(*pdev));
+ if ((dev = strchr(val, ',')) != NULL) {
+ /*
+ * Device's major/minor are given in a specified format.
+ * Decode and pack it accordingly.
+ */
+ *dev++ = '\0';
+ if ((pack = pack_find(val)) == NULL) {
+ archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unknown format `%s'", val);
+ return ARCHIVE_WARN;
+ }
+ argc = 0;
+ while ((p = la_strsep(&dev, ",")) != NULL) {
+ if (*p == '\0') {
+ archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Missing number");
+ return ARCHIVE_WARN;
+ }
+ numbers[argc++] = mtree_atol(&p);
+ if (argc > MAX_PACK_ARGS) {
+ archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Too many arguments");
+ return ARCHIVE_WARN;
+ }
+ }
+ if (argc < 2) {
+ archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Not enough arguments");
+ return ARCHIVE_WARN;
+ }
+ result = (*pack)(argc, numbers, &error);
+ if (error != NULL) {
+ archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
+ "%s", error);
+ return ARCHIVE_WARN;
+ }
+ } else {
+ /* file system raw value. */
+ result = (dev_t)mtree_atol(&val);
+ }
+ *pdev = result;
+ return ARCHIVE_OK;
+#undef MAX_PACK_ARGS
+}
+
+/*
+ * Parse a single keyword and its value.
+ */
+static int
+parse_keyword(struct archive_read *a, struct mtree *mtree,
+ struct archive_entry *entry, struct mtree_option *opt, int *parsed_kws)
+{
+ char *val, *key;
+
+ key = opt->value;
+
+ if (*key == '\0')
+ return (ARCHIVE_OK);
+
+ if (strcmp(key, "nochange") == 0) {
+ *parsed_kws |= MTREE_HAS_NOCHANGE;
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "optional") == 0) {
+ *parsed_kws |= MTREE_HAS_OPTIONAL;
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "ignore") == 0) {
+ /*
+ * The mtree processing is not recursive, so
+ * recursion will only happen for explicitly listed
+ * entries.
+ */
+ return (ARCHIVE_OK);
+ }
+
+ val = strchr(key, '=');
+ if (val == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Malformed attribute \"%s\" (%d)", key, key[0]);
+ return (ARCHIVE_WARN);
+ }
+
+ *val = '\0';
+ ++val;
+
+ switch (key[0]) {
+ case 'c':
+ if (strcmp(key, "content") == 0
+ || strcmp(key, "contents") == 0) {
+ parse_escapes(val, NULL);
+ archive_strcpy(&mtree->contents_name, val);
+ break;
+ }
+ if (strcmp(key, "cksum") == 0)
+ break;
+ case 'd':
+ if (strcmp(key, "device") == 0) {
+ /* stat(2) st_rdev field, e.g. the major/minor IDs
+ * of a char/block special file */
+ int r;
+ dev_t dev;
+
+ *parsed_kws |= MTREE_HAS_DEVICE;
+ r = parse_device(&dev, &a->archive, val);
+ if (r == ARCHIVE_OK)
+ archive_entry_set_rdev(entry, dev);
+ return r;
+ }
+ case 'f':
+ if (strcmp(key, "flags") == 0) {
+ *parsed_kws |= MTREE_HAS_FFLAGS;
+ archive_entry_copy_fflags_text(entry, val);
+ break;
+ }
+ case 'g':
+ if (strcmp(key, "gid") == 0) {
+ *parsed_kws |= MTREE_HAS_GID;
+ archive_entry_set_gid(entry, mtree_atol10(&val));
+ break;
+ }
+ if (strcmp(key, "gname") == 0) {
+ *parsed_kws |= MTREE_HAS_GNAME;
+ archive_entry_copy_gname(entry, val);
+ break;
+ }
+ case 'i':
+ if (strcmp(key, "inode") == 0) {
+ archive_entry_set_ino(entry, mtree_atol10(&val));
+ break;
+ }
+ case 'l':
+ if (strcmp(key, "link") == 0) {
+ archive_entry_copy_symlink(entry, val);
+ break;
+ }
+ case 'm':
+ if (strcmp(key, "md5") == 0 || strcmp(key, "md5digest") == 0)
+ break;
+ if (strcmp(key, "mode") == 0) {
+ if (val[0] >= '0' && val[0] <= '9') {
+ *parsed_kws |= MTREE_HAS_PERM;
+ archive_entry_set_perm(entry,
+ (mode_t)mtree_atol8(&val));
+ } else {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Symbolic mode \"%s\" unsupported", val);
+ return ARCHIVE_WARN;
+ }
+ break;
+ }
+ case 'n':
+ if (strcmp(key, "nlink") == 0) {
+ *parsed_kws |= MTREE_HAS_NLINK;
+ archive_entry_set_nlink(entry,
+ (unsigned int)mtree_atol10(&val));
+ break;
+ }
+ case 'r':
+ if (strcmp(key, "resdevice") == 0) {
+ /* stat(2) st_dev field, e.g. the device ID where the
+ * inode resides */
+ int r;
+ dev_t dev;
+
+ r = parse_device(&dev, &a->archive, val);
+ if (r == ARCHIVE_OK)
+ archive_entry_set_dev(entry, dev);
+ return r;
+ }
+ if (strcmp(key, "rmd160") == 0 ||
+ strcmp(key, "rmd160digest") == 0)
+ break;
+ case 's':
+ if (strcmp(key, "sha1") == 0 || strcmp(key, "sha1digest") == 0)
+ break;
+ if (strcmp(key, "sha256") == 0 ||
+ strcmp(key, "sha256digest") == 0)
+ break;
+ if (strcmp(key, "sha384") == 0 ||
+ strcmp(key, "sha384digest") == 0)
+ break;
+ if (strcmp(key, "sha512") == 0 ||
+ strcmp(key, "sha512digest") == 0)
+ break;
+ if (strcmp(key, "size") == 0) {
+ archive_entry_set_size(entry, mtree_atol10(&val));
+ break;
+ }
+ case 't':
+ if (strcmp(key, "tags") == 0) {
+ /*
+ * Comma delimited list of tags.
+ * Ignore the tags for now, but the interface
+ * should be extended to allow inclusion/exclusion.
+ */
+ break;
+ }
+ if (strcmp(key, "time") == 0) {
+ int64_t m;
+ int64_t my_time_t_max = get_time_t_max();
+ int64_t my_time_t_min = get_time_t_min();
+ long ns;
+
+ *parsed_kws |= MTREE_HAS_MTIME;
+ m = mtree_atol10(&val);
+ /* Replicate an old mtree bug:
+ * 123456789.1 represents 123456789
+ * seconds and 1 nanosecond. */
+ if (*val == '.') {
+ ++val;
+ ns = (long)mtree_atol10(&val);
+ } else
+ ns = 0;
+ if (m > my_time_t_max)
+ m = my_time_t_max;
+ else if (m < my_time_t_min)
+ m = my_time_t_min;
+ archive_entry_set_mtime(entry, (time_t)m, ns);
+ break;
+ }
+ if (strcmp(key, "type") == 0) {
+ switch (val[0]) {
+ case 'b':
+ if (strcmp(val, "block") == 0) {
+ archive_entry_set_filetype(entry, AE_IFBLK);
+ break;
+ }
+ case 'c':
+ if (strcmp(val, "char") == 0) {
+ archive_entry_set_filetype(entry, AE_IFCHR);
+ break;
+ }
+ case 'd':
+ if (strcmp(val, "dir") == 0) {
+ archive_entry_set_filetype(entry, AE_IFDIR);
+ break;
+ }
+ case 'f':
+ if (strcmp(val, "fifo") == 0) {
+ archive_entry_set_filetype(entry, AE_IFIFO);
+ break;
+ }
+ if (strcmp(val, "file") == 0) {
+ archive_entry_set_filetype(entry, AE_IFREG);
+ break;
+ }
+ case 'l':
+ if (strcmp(val, "link") == 0) {
+ 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);
+ archive_entry_set_filetype(entry, AE_IFREG);
+ return (ARCHIVE_WARN);
+ }
+ *parsed_kws |= MTREE_HAS_TYPE;
+ break;
+ }
+ case 'u':
+ if (strcmp(key, "uid") == 0) {
+ *parsed_kws |= MTREE_HAS_UID;
+ archive_entry_set_uid(entry, mtree_atol10(&val));
+ break;
+ }
+ if (strcmp(key, "uname") == 0) {
+ *parsed_kws |= MTREE_HAS_UNAME;
+ archive_entry_copy_uname(entry, val);
+ break;
+ }
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unrecognized key %s=%s", key, val);
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset)
+{
+ size_t bytes_to_read;
+ ssize_t bytes_read;
+ struct mtree *mtree;
+
+ mtree = (struct mtree *)(a->format->data);
+ if (mtree->fd < 0) {
+ *buff = NULL;
+ *offset = 0;
+ *size = 0;
+ return (ARCHIVE_EOF);
+ }
+ if (mtree->buff == NULL) {
+ mtree->buffsize = 64 * 1024;
+ mtree->buff = malloc(mtree->buffsize);
+ if (mtree->buff == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ *buff = mtree->buff;
+ *offset = mtree->offset;
+ if ((int64_t)mtree->buffsize > mtree->cur_size - mtree->offset)
+ bytes_to_read = (size_t)(mtree->cur_size - mtree->offset);
+ else
+ bytes_to_read = mtree->buffsize;
+ bytes_read = read(mtree->fd, mtree->buff, bytes_to_read);
+ if (bytes_read < 0) {
+ archive_set_error(&a->archive, errno, "Can't read");
+ return (ARCHIVE_WARN);
+ }
+ if (bytes_read == 0) {
+ *size = 0;
+ return (ARCHIVE_EOF);
+ }
+ mtree->offset += bytes_read;
+ *size = bytes_read;
+ return (ARCHIVE_OK);
+}
+
+/* Skip does nothing except possibly close the contents file. */
+static int
+skip(struct archive_read *a)
+{
+ struct mtree *mtree;
+
+ mtree = (struct mtree *)(a->format->data);
+ if (mtree->fd >= 0) {
+ close(mtree->fd);
+ mtree->fd = -1;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Since parsing backslash sequences always makes strings shorter,
+ * we can always do this conversion in-place.
+ */
+static void
+parse_escapes(char *src, struct mtree_entry *mentry)
+{
+ char *dest = src;
+ char c;
+
+ if (mentry != NULL && strcmp(src, ".") == 0)
+ mentry->full = 1;
+
+ while (*src != '\0') {
+ c = *src++;
+ if (c == '/' && mentry != NULL)
+ mentry->full = 1;
+ if (c == '\\') {
+ switch (src[0]) {
+ case '0':
+ if (src[1] < '0' || src[1] > '7') {
+ c = 0;
+ ++src;
+ break;
+ }
+ /* FALLTHROUGH */
+ case '1':
+ case '2':
+ case '3':
+ if (src[1] >= '0' && src[1] <= '7' &&
+ src[2] >= '0' && src[2] <= '7') {
+ c = (src[0] - '0') << 6;
+ c |= (src[1] - '0') << 3;
+ c |= (src[2] - '0');
+ src += 3;
+ }
+ break;
+ case 'a':
+ c = '\a';
+ ++src;
+ break;
+ case 'b':
+ c = '\b';
+ ++src;
+ break;
+ case 'f':
+ c = '\f';
+ ++src;
+ break;
+ case 'n':
+ c = '\n';
+ ++src;
+ break;
+ case 'r':
+ c = '\r';
+ ++src;
+ break;
+ case 's':
+ c = ' ';
+ ++src;
+ break;
+ case 't':
+ c = '\t';
+ ++src;
+ break;
+ case 'v':
+ c = '\v';
+ ++src;
+ break;
+ }
+ }
+ *dest++ = c;
+ }
+ *dest = '\0';
+}
+
+/*
+ * Note that this implementation does not (and should not!) obey
+ * locale settings; you cannot simply substitute strtol here, since
+ * it does obey locale.
+ */
+static int64_t
+mtree_atol8(char **p)
+{
+ int64_t l, limit, last_digit_limit;
+ int digit, base;
+
+ base = 8;
+ limit = INT64_MAX / base;
+ last_digit_limit = INT64_MAX % base;
+
+ l = 0;
+ digit = **p - '0';
+ while (digit >= 0 && digit < base) {
+ if (l>limit || (l == limit && digit > last_digit_limit)) {
+ l = INT64_MAX; /* Truncate on overflow. */
+ break;
+ }
+ l = (l * base) + digit;
+ digit = *++(*p) - '0';
+ }
+ return (l);
+}
+
+/*
+ * Note that this implementation does not (and should not!) obey
+ * locale settings; you cannot simply substitute strtol here, since
+ * it does obey locale.
+ */
+static int64_t
+mtree_atol10(char **p)
+{
+ int64_t l, limit, last_digit_limit;
+ int base, digit, sign;
+
+ base = 10;
+
+ if (**p == '-') {
+ sign = -1;
+ limit = ((uint64_t)(INT64_MAX) + 1) / base;
+ last_digit_limit = ((uint64_t)(INT64_MAX) + 1) % base;
+ ++(*p);
+ } else {
+ sign = 1;
+ limit = INT64_MAX / base;
+ last_digit_limit = INT64_MAX % base;
+ }
+
+ l = 0;
+ digit = **p - '0';
+ while (digit >= 0 && digit < base) {
+ if (l > limit || (l == limit && digit > last_digit_limit))
+ return (sign < 0) ? INT64_MIN : INT64_MAX;
+ l = (l * base) + digit;
+ digit = *++(*p) - '0';
+ }
+ return (sign < 0) ? -l : l;
+}
+
+/* Parse a hex digit. */
+static int
+parsehex(char c)
+{
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ else if (c >= 'a' && c <= 'f')
+ return c - 'a';
+ else if (c >= 'A' && c <= 'F')
+ return c - 'A';
+ else
+ return -1;
+}
+
+/*
+ * Note that this implementation does not (and should not!) obey
+ * locale settings; you cannot simply substitute strtol here, since
+ * it does obey locale.
+ */
+static int64_t
+mtree_atol16(char **p)
+{
+ int64_t l, limit, last_digit_limit;
+ int base, digit, sign;
+
+ base = 16;
+
+ if (**p == '-') {
+ sign = -1;
+ limit = ((uint64_t)(INT64_MAX) + 1) / base;
+ last_digit_limit = ((uint64_t)(INT64_MAX) + 1) % base;
+ ++(*p);
+ } else {
+ sign = 1;
+ limit = INT64_MAX / base;
+ last_digit_limit = INT64_MAX % base;
+ }
+
+ l = 0;
+ digit = parsehex(**p);
+ while (digit >= 0 && digit < base) {
+ if (l > limit || (l == limit && digit > last_digit_limit))
+ return (sign < 0) ? INT64_MIN : INT64_MAX;
+ l = (l * base) + digit;
+ digit = parsehex(*++(*p));
+ }
+ return (sign < 0) ? -l : l;
+}
+
+static int64_t
+mtree_atol(char **p)
+{
+ if (**p != '0')
+ return mtree_atol10(p);
+ if ((*p)[1] == 'x' || (*p)[1] == 'X') {
+ *p += 2;
+ return mtree_atol16(p);
+ }
+ return mtree_atol8(p);
+}
+
+/*
+ * Returns length of line (including trailing newline)
+ * or negative on error. 'start' argument is updated to
+ * point to first character of line.
+ */
+static ssize_t
+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;
+ char *u;
+
+ /* Accumulate line in a line buffer. */
+ for (;;) {
+ /* Read some more. */
+ t = __archive_read_ahead(a, 1, &bytes_read);
+ if (t == NULL)
+ 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;
+ }
+ if (total_size + bytes_read + 1 > limit) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Line too long");
+ return (ARCHIVE_FATAL);
+ }
+ if (archive_string_ensure(&mtree->line,
+ total_size + bytes_read + 1) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate working buffer");
+ return (ARCHIVE_FATAL);
+ }
+ 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') {
+ *start = mtree->line.s;
+ return total_size;
+ }
+ if (u[0] == '#') {
+ if (p == NULL)
+ 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;
+ }
+ 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
new file mode 100644
index 0000000000..4c568348c6
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c
@@ -0,0 +1,2919 @@
+/*-
+* Copyright (c) 2003-2007 Tim Kientzle
+* Copyright (c) 2011 Andres Mejia
+* 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_ERRNO_H
+#include <errno.h>
+#endif
+#include <time.h>
+#include <limits.h>
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h> /* crc32 */
+#endif
+
+#include "archive.h"
+#ifndef HAVE_ZLIB_H
+#include "archive_crc32.h"
+#endif
+#include "archive_endian.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_ppmd7_private.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+/* RAR signature, also known as the mark header */
+#define RAR_SIGNATURE "\x52\x61\x72\x21\x1A\x07\x00"
+
+/* Header types */
+#define MARK_HEAD 0x72
+#define MAIN_HEAD 0x73
+#define FILE_HEAD 0x74
+#define COMM_HEAD 0x75
+#define AV_HEAD 0x76
+#define SUB_HEAD 0x77
+#define PROTECT_HEAD 0x78
+#define SIGN_HEAD 0x79
+#define NEWSUB_HEAD 0x7a
+#define ENDARC_HEAD 0x7b
+
+/* Main Header Flags */
+#define MHD_VOLUME 0x0001
+#define MHD_COMMENT 0x0002
+#define MHD_LOCK 0x0004
+#define MHD_SOLID 0x0008
+#define MHD_NEWNUMBERING 0x0010
+#define MHD_AV 0x0020
+#define MHD_PROTECT 0x0040
+#define MHD_PASSWORD 0x0080
+#define MHD_FIRSTVOLUME 0x0100
+#define MHD_ENCRYPTVER 0x0200
+
+/* Flags common to all headers */
+#define HD_MARKDELETION 0x4000
+#define HD_ADD_SIZE_PRESENT 0x8000
+
+/* File Header Flags */
+#define FHD_SPLIT_BEFORE 0x0001
+#define FHD_SPLIT_AFTER 0x0002
+#define FHD_PASSWORD 0x0004
+#define FHD_COMMENT 0x0008
+#define FHD_SOLID 0x0010
+#define FHD_LARGE 0x0100
+#define FHD_UNICODE 0x0200
+#define FHD_SALT 0x0400
+#define FHD_VERSION 0x0800
+#define FHD_EXTTIME 0x1000
+#define FHD_EXTFLAGS 0x2000
+
+/* File dictionary sizes */
+#define DICTIONARY_SIZE_64 0x00
+#define DICTIONARY_SIZE_128 0x20
+#define DICTIONARY_SIZE_256 0x40
+#define DICTIONARY_SIZE_512 0x60
+#define DICTIONARY_SIZE_1024 0x80
+#define DICTIONARY_SIZE_2048 0xA0
+#define DICTIONARY_SIZE_4096 0xC0
+#define FILE_IS_DIRECTORY 0xE0
+#define DICTIONARY_MASK FILE_IS_DIRECTORY
+
+/* OS Flags */
+#define OS_MSDOS 0
+#define OS_OS2 1
+#define OS_WIN32 2
+#define OS_UNIX 3
+#define OS_MAC_OS 4
+#define OS_BEOS 5
+
+/* Compression Methods */
+#define COMPRESS_METHOD_STORE 0x30
+/* LZSS */
+#define COMPRESS_METHOD_FASTEST 0x31
+#define COMPRESS_METHOD_FAST 0x32
+#define COMPRESS_METHOD_NORMAL 0x33
+/* PPMd Variant H */
+#define COMPRESS_METHOD_GOOD 0x34
+#define COMPRESS_METHOD_BEST 0x35
+
+#define CRC_POLYNOMIAL 0xEDB88320
+
+#define NS_UNIT 10000000
+
+#define DICTIONARY_MAX_SIZE 0x400000
+
+#define MAINCODE_SIZE 299
+#define OFFSETCODE_SIZE 60
+#define LOWOFFSETCODE_SIZE 17
+#define LENGTHCODE_SIZE 28
+#define HUFFMAN_TABLE_SIZE \
+ MAINCODE_SIZE + OFFSETCODE_SIZE + LOWOFFSETCODE_SIZE + LENGTHCODE_SIZE
+
+#define MAX_SYMBOL_LENGTH 0xF
+#define MAX_SYMBOLS 20
+
+/*
+ * Considering L1,L2 cache miss and a calling of write system-call,
+ * the best size of the output buffer(uncompressed buffer) is 128K.
+ * If the structure of extracting process is changed, this value
+ * might be researched again.
+ */
+#define UNP_BUFFER_SIZE (128 * 1024)
+
+/* Define this here for non-Windows platforms */
+#if !((defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__))
+#define FILE_ATTRIBUTE_DIRECTORY 0x10
+#endif
+
+/* Fields common to all headers */
+struct rar_header
+{
+ char crc[2];
+ char type;
+ char flags[2];
+ char size[2];
+};
+
+/* Fields common to all file headers */
+struct rar_file_header
+{
+ char pack_size[4];
+ char unp_size[4];
+ char host_os;
+ char file_crc[4];
+ char file_time[4];
+ char unp_ver;
+ char method;
+ char name_size[2];
+ char file_attr[4];
+};
+
+struct huffman_tree_node
+{
+ int branches[2];
+};
+
+struct huffman_table_entry
+{
+ unsigned int length;
+ int value;
+};
+
+struct huffman_code
+{
+ struct huffman_tree_node *tree;
+ int numentries;
+ int minlength;
+ int maxlength;
+ int tablesize;
+ struct huffman_table_entry *table;
+};
+
+struct lzss
+{
+ unsigned char *window;
+ int mask;
+ int64_t position;
+};
+
+struct data_block_offsets
+{
+ int64_t header_size;
+ int64_t start_offset;
+ int64_t end_offset;
+};
+
+struct rar
+{
+ /* Entries from main RAR header */
+ unsigned main_flags;
+ unsigned long file_crc;
+ char reserved1[2];
+ char reserved2[4];
+ char encryptver;
+
+ /* File header entries */
+ char compression_method;
+ unsigned file_flags;
+ int64_t packed_size;
+ int64_t unp_size;
+ time_t mtime;
+ long mnsec;
+ mode_t mode;
+ char *filename;
+ char *filename_save;
+ size_t filename_allocated;
+
+ /* File header optional entries */
+ char salt[8];
+ time_t atime;
+ long ansec;
+ time_t ctime;
+ long cnsec;
+ time_t arctime;
+ long arcnsec;
+
+ /* Fields to help with tracking decompression of files. */
+ int64_t bytes_unconsumed;
+ int64_t bytes_remaining;
+ int64_t bytes_uncopied;
+ int64_t offset;
+ int64_t offset_outgoing;
+ int64_t offset_seek;
+ char valid;
+ unsigned int unp_offset;
+ unsigned int unp_buffer_size;
+ unsigned char *unp_buffer;
+ unsigned int dictionary_size;
+ char start_new_block;
+ char entry_eof;
+ unsigned long crc_calculated;
+ int found_first_header;
+ char has_endarc_header;
+ struct data_block_offsets *dbo;
+ unsigned int cursor;
+ unsigned int nodes;
+
+ /* LZSS members */
+ struct huffman_code maincode;
+ struct huffman_code offsetcode;
+ struct huffman_code lowoffsetcode;
+ struct huffman_code lengthcode;
+ unsigned char lengthtable[HUFFMAN_TABLE_SIZE];
+ struct lzss lzss;
+ char output_last_match;
+ unsigned int lastlength;
+ unsigned int lastoffset;
+ unsigned int oldoffset[4];
+ unsigned int lastlowoffset;
+ unsigned int numlowoffsetrepeats;
+ int64_t filterstart;
+ char start_new_table;
+
+ /* PPMd Variant H members */
+ char ppmd_valid;
+ char ppmd_eod;
+ char is_ppmd_block;
+ int ppmd_escape;
+ CPpmd7 ppmd7_context;
+ CPpmd7z_RangeDec range_dec;
+ IByteIn bytein;
+
+ /*
+ * String conversion object.
+ */
+ int init_default_conversion;
+ struct archive_string_conv *sconv_default;
+ struct archive_string_conv *opt_sconv;
+ struct archive_string_conv *sconv_utf8;
+ struct archive_string_conv *sconv_utf16be;
+
+ /*
+ * Bit stream reader.
+ */
+ struct rar_br {
+#define CACHE_TYPE uint64_t
+#define CACHE_BITS (8 * sizeof(CACHE_TYPE))
+ /* Cache buffer. */
+ CACHE_TYPE cache_buffer;
+ /* Indicates how many bits avail in cache_buffer. */
+ int cache_avail;
+ ssize_t avail_in;
+ const unsigned char *next_in;
+ } br;
+
+ /*
+ * Custom field to denote that this archive contains encrypted entries
+ */
+ int has_encrypted_entries;
+};
+
+static int archive_read_support_format_rar_capabilities(struct archive_read *);
+static int archive_read_format_rar_has_encrypted_entries(struct archive_read *);
+static int archive_read_format_rar_bid(struct archive_read *, int);
+static int archive_read_format_rar_options(struct archive_read *,
+ const char *, const char *);
+static int archive_read_format_rar_read_header(struct archive_read *,
+ struct archive_entry *);
+static int archive_read_format_rar_read_data(struct archive_read *,
+ const void **, size_t *, int64_t *);
+static int archive_read_format_rar_read_data_skip(struct archive_read *a);
+static int64_t archive_read_format_rar_seek_data(struct archive_read *, int64_t,
+ int);
+static int archive_read_format_rar_cleanup(struct archive_read *);
+
+/* Support functions */
+static int read_header(struct archive_read *, struct archive_entry *, char);
+static time_t get_time(int);
+static int read_exttime(const char *, struct rar *, const char *);
+static int read_symlink_stored(struct archive_read *, struct archive_entry *,
+ struct archive_string_conv *);
+static int read_data_stored(struct archive_read *, const void **, size_t *,
+ int64_t *);
+static int read_data_compressed(struct archive_read *, const void **, size_t *,
+ int64_t *);
+static int rar_br_preparation(struct archive_read *, struct rar_br *);
+static int parse_codes(struct archive_read *);
+static void free_codes(struct archive_read *);
+static int read_next_symbol(struct archive_read *, struct huffman_code *);
+static int create_code(struct archive_read *, struct huffman_code *,
+ unsigned char *, int, char);
+static int add_value(struct archive_read *, struct huffman_code *, int, int,
+ int);
+static int new_node(struct huffman_code *);
+static int make_table(struct archive_read *, struct huffman_code *);
+static int make_table_recurse(struct archive_read *, struct huffman_code *, int,
+ struct huffman_table_entry *, int, int);
+static int64_t expand(struct archive_read *, int64_t);
+static int copy_from_lzss_window(struct archive_read *, const void **,
+ int64_t, int);
+static const void *rar_read_ahead(struct archive_read *, size_t, ssize_t *);
+
+/*
+ * Bit stream reader.
+ */
+/* Check that the cache buffer has enough bits. */
+#define rar_br_has(br, n) ((br)->cache_avail >= n)
+/* Get compressed data by bit. */
+#define rar_br_bits(br, n) \
+ (((uint32_t)((br)->cache_buffer >> \
+ ((br)->cache_avail - (n)))) & cache_masks[n])
+#define rar_br_bits_forced(br, n) \
+ (((uint32_t)((br)->cache_buffer << \
+ ((n) - (br)->cache_avail))) & cache_masks[n])
+/* Read ahead to make sure the cache buffer has enough compressed data we
+ * will use.
+ * True : completed, there is enough data in the cache buffer.
+ * False : there is no data in the stream. */
+#define rar_br_read_ahead(a, br, n) \
+ ((rar_br_has(br, (n)) || rar_br_fillup(a, br)) || rar_br_has(br, (n)))
+/* Notify how many bits we consumed. */
+#define rar_br_consume(br, n) ((br)->cache_avail -= (n))
+#define rar_br_consume_unalined_bits(br) ((br)->cache_avail &= ~7)
+
+static const uint32_t cache_masks[] = {
+ 0x00000000, 0x00000001, 0x00000003, 0x00000007,
+ 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F,
+ 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,
+ 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF,
+ 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF,
+ 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,
+ 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF,
+ 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF,
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
+};
+
+/*
+ * Shift away used bits in the cache data and fill it up with following bits.
+ * Call this when cache buffer does not have enough bits you need.
+ *
+ * Returns 1 if the cache buffer is full.
+ * Returns 0 if the cache buffer is not full; input buffer is empty.
+ */
+static int
+rar_br_fillup(struct archive_read *a, struct rar_br *br)
+{
+ struct rar *rar = (struct rar *)(a->format->data);
+ int n = CACHE_BITS - br->cache_avail;
+
+ for (;;) {
+ switch (n >> 3) {
+ case 8:
+ if (br->avail_in >= 8) {
+ br->cache_buffer =
+ ((uint64_t)br->next_in[0]) << 56 |
+ ((uint64_t)br->next_in[1]) << 48 |
+ ((uint64_t)br->next_in[2]) << 40 |
+ ((uint64_t)br->next_in[3]) << 32 |
+ ((uint32_t)br->next_in[4]) << 24 |
+ ((uint32_t)br->next_in[5]) << 16 |
+ ((uint32_t)br->next_in[6]) << 8 |
+ (uint32_t)br->next_in[7];
+ br->next_in += 8;
+ br->avail_in -= 8;
+ br->cache_avail += 8 * 8;
+ rar->bytes_unconsumed += 8;
+ rar->bytes_remaining -= 8;
+ return (1);
+ }
+ break;
+ case 7:
+ if (br->avail_in >= 7) {
+ br->cache_buffer =
+ (br->cache_buffer << 56) |
+ ((uint64_t)br->next_in[0]) << 48 |
+ ((uint64_t)br->next_in[1]) << 40 |
+ ((uint64_t)br->next_in[2]) << 32 |
+ ((uint32_t)br->next_in[3]) << 24 |
+ ((uint32_t)br->next_in[4]) << 16 |
+ ((uint32_t)br->next_in[5]) << 8 |
+ (uint32_t)br->next_in[6];
+ br->next_in += 7;
+ br->avail_in -= 7;
+ br->cache_avail += 7 * 8;
+ rar->bytes_unconsumed += 7;
+ rar->bytes_remaining -= 7;
+ return (1);
+ }
+ break;
+ case 6:
+ if (br->avail_in >= 6) {
+ br->cache_buffer =
+ (br->cache_buffer << 48) |
+ ((uint64_t)br->next_in[0]) << 40 |
+ ((uint64_t)br->next_in[1]) << 32 |
+ ((uint32_t)br->next_in[2]) << 24 |
+ ((uint32_t)br->next_in[3]) << 16 |
+ ((uint32_t)br->next_in[4]) << 8 |
+ (uint32_t)br->next_in[5];
+ br->next_in += 6;
+ br->avail_in -= 6;
+ br->cache_avail += 6 * 8;
+ rar->bytes_unconsumed += 6;
+ rar->bytes_remaining -= 6;
+ return (1);
+ }
+ break;
+ case 0:
+ /* We have enough compressed data in
+ * the cache buffer.*/
+ return (1);
+ default:
+ break;
+ }
+ if (br->avail_in <= 0) {
+
+ if (rar->bytes_unconsumed > 0) {
+ /* Consume as much as the decompressor
+ * actually used. */
+ __archive_read_consume(a, rar->bytes_unconsumed);
+ rar->bytes_unconsumed = 0;
+ }
+ br->next_in = rar_read_ahead(a, 1, &(br->avail_in));
+ if (br->next_in == NULL)
+ return (0);
+ if (br->avail_in == 0)
+ return (0);
+ }
+ br->cache_buffer =
+ (br->cache_buffer << 8) | *br->next_in++;
+ br->avail_in--;
+ br->cache_avail += 8;
+ n -= 8;
+ rar->bytes_unconsumed++;
+ rar->bytes_remaining--;
+ }
+}
+
+static int
+rar_br_preparation(struct archive_read *a, struct rar_br *br)
+{
+ struct rar *rar = (struct rar *)(a->format->data);
+
+ if (rar->bytes_remaining > 0) {
+ br->next_in = rar_read_ahead(a, 1, &(br->avail_in));
+ if (br->next_in == NULL) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated RAR file data");
+ return (ARCHIVE_FATAL);
+ }
+ if (br->cache_avail == 0)
+ (void)rar_br_fillup(a, br);
+ }
+ return (ARCHIVE_OK);
+}
+
+/* Find last bit set */
+static inline int
+rar_fls(unsigned int word)
+{
+ word |= (word >> 1);
+ word |= (word >> 2);
+ word |= (word >> 4);
+ word |= (word >> 8);
+ word |= (word >> 16);
+ return word - (word >> 1);
+}
+
+/* LZSS functions */
+static inline int64_t
+lzss_position(struct lzss *lzss)
+{
+ return lzss->position;
+}
+
+static inline int
+lzss_mask(struct lzss *lzss)
+{
+ return lzss->mask;
+}
+
+static inline int
+lzss_size(struct lzss *lzss)
+{
+ return lzss->mask + 1;
+}
+
+static inline int
+lzss_offset_for_position(struct lzss *lzss, int64_t pos)
+{
+ return (int)(pos & lzss->mask);
+}
+
+static inline unsigned char *
+lzss_pointer_for_position(struct lzss *lzss, int64_t pos)
+{
+ return &lzss->window[lzss_offset_for_position(lzss, pos)];
+}
+
+static inline int
+lzss_current_offset(struct lzss *lzss)
+{
+ return lzss_offset_for_position(lzss, lzss->position);
+}
+
+static inline uint8_t *
+lzss_current_pointer(struct lzss *lzss)
+{
+ return lzss_pointer_for_position(lzss, lzss->position);
+}
+
+static inline void
+lzss_emit_literal(struct rar *rar, uint8_t literal)
+{
+ *lzss_current_pointer(&rar->lzss) = literal;
+ rar->lzss.position++;
+}
+
+static inline void
+lzss_emit_match(struct rar *rar, int offset, int length)
+{
+ int dstoffs = lzss_current_offset(&rar->lzss);
+ int srcoffs = (dstoffs - offset) & lzss_mask(&rar->lzss);
+ int l, li, remaining;
+ unsigned char *d, *s;
+
+ remaining = length;
+ while (remaining > 0) {
+ l = remaining;
+ if (dstoffs > srcoffs) {
+ if (l > lzss_size(&rar->lzss) - dstoffs)
+ l = lzss_size(&rar->lzss) - dstoffs;
+ } else {
+ if (l > lzss_size(&rar->lzss) - srcoffs)
+ l = lzss_size(&rar->lzss) - srcoffs;
+ }
+ d = &(rar->lzss.window[dstoffs]);
+ s = &(rar->lzss.window[srcoffs]);
+ if ((dstoffs + l < srcoffs) || (srcoffs + l < dstoffs))
+ memcpy(d, s, l);
+ else {
+ for (li = 0; li < l; li++)
+ d[li] = s[li];
+ }
+ remaining -= l;
+ dstoffs = (dstoffs + l) & lzss_mask(&(rar->lzss));
+ srcoffs = (srcoffs + l) & lzss_mask(&(rar->lzss));
+ }
+ rar->lzss.position += length;
+}
+
+static void *
+ppmd_alloc(void *p, size_t size)
+{
+ (void)p;
+ return malloc(size);
+}
+static void
+ppmd_free(void *p, void *address)
+{
+ (void)p;
+ free(address);
+}
+static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free };
+
+static Byte
+ppmd_read(void *p)
+{
+ struct archive_read *a = ((IByteIn*)p)->a;
+ struct rar *rar = (struct rar *)(a->format->data);
+ struct rar_br *br = &(rar->br);
+ Byte b;
+ if (!rar_br_read_ahead(a, br, 8))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated RAR file data");
+ rar->valid = 0;
+ return 0;
+ }
+ b = rar_br_bits(br, 8);
+ rar_br_consume(br, 8);
+ return b;
+}
+
+int
+archive_read_support_format_rar(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct rar *rar;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+ "archive_read_support_format_rar");
+
+ rar = (struct rar *)malloc(sizeof(*rar));
+ if (rar == NULL)
+ {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate rar data");
+ return (ARCHIVE_FATAL);
+ }
+ memset(rar, 0, sizeof(*rar));
+
+ /*
+ * Until enough data has been read, we cannot tell about
+ * any encrypted entries yet.
+ */
+ rar->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW;
+
+ r = __archive_read_register_format(a,
+ rar,
+ "rar",
+ archive_read_format_rar_bid,
+ archive_read_format_rar_options,
+ archive_read_format_rar_read_header,
+ archive_read_format_rar_read_data,
+ archive_read_format_rar_read_data_skip,
+ archive_read_format_rar_seek_data,
+ archive_read_format_rar_cleanup,
+ archive_read_support_format_rar_capabilities,
+ archive_read_format_rar_has_encrypted_entries);
+
+ if (r != ARCHIVE_OK)
+ free(rar);
+ return (r);
+}
+
+static int
+archive_read_support_format_rar_capabilities(struct archive_read * a)
+{
+ (void)a; /* UNUSED */
+ return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA
+ | ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA);
+}
+
+static int
+archive_read_format_rar_has_encrypted_entries(struct archive_read *_a)
+{
+ if (_a && _a->format) {
+ struct rar * rar = (struct rar *)_a->format->data;
+ if (rar) {
+ return rar->has_encrypted_entries;
+ }
+ }
+ return ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW;
+}
+
+
+static int
+archive_read_format_rar_bid(struct archive_read *a, int best_bid)
+{
+ const char *p;
+
+ /* If there's already a bid > 30, we'll never win. */
+ if (best_bid > 30)
+ return (-1);
+
+ if ((p = __archive_read_ahead(a, 7, NULL)) == NULL)
+ return (-1);
+
+ if (memcmp(p, RAR_SIGNATURE, 7) == 0)
+ return (30);
+
+ if ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0) {
+ /* This is a PE file */
+ ssize_t offset = 0x10000;
+ ssize_t window = 4096;
+ ssize_t bytes_avail;
+ while (offset + window <= (1024 * 128)) {
+ const char *buff = __archive_read_ahead(a, offset + window, &bytes_avail);
+ if (buff == NULL) {
+ /* Remaining bytes are less than window. */
+ window >>= 1;
+ if (window < 0x40)
+ return (0);
+ continue;
+ }
+ p = buff + offset;
+ while (p + 7 < buff + bytes_avail) {
+ if (memcmp(p, RAR_SIGNATURE, 7) == 0)
+ return (30);
+ p += 0x10;
+ }
+ offset = p - buff;
+ }
+ }
+ return (0);
+}
+
+static int
+skip_sfx(struct archive_read *a)
+{
+ const void *h;
+ const char *p, *q;
+ size_t skip, total;
+ ssize_t bytes, window;
+
+ total = 0;
+ window = 4096;
+ while (total + window <= (1024 * 128)) {
+ h = __archive_read_ahead(a, window, &bytes);
+ if (h == NULL) {
+ /* Remaining bytes are less than window. */
+ window >>= 1;
+ if (window < 0x40)
+ goto fatal;
+ continue;
+ }
+ if (bytes < 0x40)
+ goto fatal;
+ p = h;
+ q = p + bytes;
+
+ /*
+ * Scan ahead until we find something that looks
+ * like the RAR header.
+ */
+ while (p + 7 < q) {
+ if (memcmp(p, RAR_SIGNATURE, 7) == 0) {
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ return (ARCHIVE_OK);
+ }
+ p += 0x10;
+ }
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ total += skip;
+ }
+fatal:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Couldn't find out RAR header");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+archive_read_format_rar_options(struct archive_read *a,
+ const char *key, const char *val)
+{
+ struct rar *rar;
+ int ret = ARCHIVE_FAILED;
+
+ rar = (struct rar *)(a->format->data);
+ if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "rar: hdrcharset option needs a character-set name");
+ else {
+ rar->opt_sconv =
+ archive_string_conversion_from_charset(
+ &a->archive, val, 0);
+ if (rar->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ }
+
+ /* 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
+archive_read_format_rar_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ const void *h;
+ const char *p;
+ struct rar *rar;
+ size_t skip;
+ char head_type;
+ int ret;
+ unsigned flags;
+
+ a->archive.archive_format = ARCHIVE_FORMAT_RAR;
+ if (a->archive.archive_format_name == NULL)
+ a->archive.archive_format_name = "RAR";
+
+ rar = (struct rar *)(a->format->data);
+
+ /*
+ * It should be sufficient to call archive_read_next_header() for
+ * a reader to determine if an entry is encrypted or not. If the
+ * encryption of an entry is only detectable when calling
+ * archive_read_data(), so be it. We'll do the same check there
+ * as well.
+ */
+ if (rar->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
+ rar->has_encrypted_entries = 0;
+ }
+
+ /* RAR files can be generated without EOF headers, so return ARCHIVE_EOF if
+ * this fails.
+ */
+ if ((h = __archive_read_ahead(a, 7, NULL)) == NULL)
+ return (ARCHIVE_EOF);
+
+ p = h;
+ if (rar->found_first_header == 0 &&
+ ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0)) {
+ /* This is an executable ? Must be self-extracting... */
+ ret = skip_sfx(a);
+ if (ret < ARCHIVE_WARN)
+ return (ret);
+ }
+ rar->found_first_header = 1;
+
+ while (1)
+ {
+ unsigned long crc32_val;
+
+ if ((h = __archive_read_ahead(a, 7, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+
+ head_type = p[2];
+ switch(head_type)
+ {
+ case MARK_HEAD:
+ if (memcmp(p, RAR_SIGNATURE, 7) != 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid marker header");
+ return (ARCHIVE_FATAL);
+ }
+ __archive_read_consume(a, 7);
+ break;
+
+ case MAIN_HEAD:
+ rar->main_flags = archive_le16dec(p + 3);
+ skip = archive_le16dec(p + 5);
+ if (skip < 7 + sizeof(rar->reserved1) + sizeof(rar->reserved2)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid header size");
+ return (ARCHIVE_FATAL);
+ }
+ if ((h = __archive_read_ahead(a, skip, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+ memcpy(rar->reserved1, p + 7, sizeof(rar->reserved1));
+ memcpy(rar->reserved2, p + 7 + sizeof(rar->reserved1),
+ sizeof(rar->reserved2));
+ if (rar->main_flags & MHD_ENCRYPTVER) {
+ if (skip < 7 + sizeof(rar->reserved1) + sizeof(rar->reserved2)+1) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid header size");
+ return (ARCHIVE_FATAL);
+ }
+ rar->encryptver = *(p + 7 + sizeof(rar->reserved1) +
+ sizeof(rar->reserved2));
+ }
+
+ /* Main header is password encrytped, so we cannot read any
+ file names or any other info about files from the header. */
+ if (rar->main_flags & MHD_PASSWORD)
+ {
+ archive_entry_set_is_metadata_encrypted(entry, 1);
+ archive_entry_set_is_data_encrypted(entry, 1);
+ rar->has_encrypted_entries = 1;
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "RAR encryption support unavailable.");
+ return (ARCHIVE_FATAL);
+ }
+
+ crc32_val = crc32(0, (const unsigned char *)p + 2, (unsigned)skip - 2);
+ if ((crc32_val & 0xffff) != archive_le16dec(p)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Header CRC error");
+ return (ARCHIVE_FATAL);
+ }
+ __archive_read_consume(a, skip);
+ break;
+
+ case FILE_HEAD:
+ return read_header(a, entry, head_type);
+
+ case COMM_HEAD:
+ case AV_HEAD:
+ case SUB_HEAD:
+ case PROTECT_HEAD:
+ case SIGN_HEAD:
+ case ENDARC_HEAD:
+ flags = archive_le16dec(p + 3);
+ skip = archive_le16dec(p + 5);
+ if (skip < 7) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid header size");
+ return (ARCHIVE_FATAL);
+ }
+ if (skip > 7) {
+ if ((h = __archive_read_ahead(a, skip, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+ }
+ if (flags & HD_ADD_SIZE_PRESENT)
+ {
+ if (skip < 7 + 4) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid header size");
+ return (ARCHIVE_FATAL);
+ }
+ skip += archive_le32dec(p + 7);
+ if ((h = __archive_read_ahead(a, skip, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+ }
+
+ crc32_val = crc32(0, (const unsigned char *)p + 2, (unsigned)skip - 2);
+ if ((crc32_val & 0xffff) != archive_le16dec(p)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Header CRC error");
+ return (ARCHIVE_FATAL);
+ }
+ __archive_read_consume(a, skip);
+ if (head_type == ENDARC_HEAD)
+ return (ARCHIVE_EOF);
+ break;
+
+ case NEWSUB_HEAD:
+ if ((ret = read_header(a, entry, head_type)) < ARCHIVE_WARN)
+ return ret;
+ break;
+
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Bad RAR file");
+ return (ARCHIVE_FATAL);
+ }
+ }
+}
+
+static int
+archive_read_format_rar_read_data(struct archive_read *a, const void **buff,
+ size_t *size, int64_t *offset)
+{
+ struct rar *rar = (struct rar *)(a->format->data);
+ int ret;
+
+ if (rar->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
+ rar->has_encrypted_entries = 0;
+ }
+
+ if (rar->bytes_unconsumed > 0) {
+ /* Consume as much as the decompressor actually used. */
+ __archive_read_consume(a, rar->bytes_unconsumed);
+ rar->bytes_unconsumed = 0;
+ }
+
+ if (rar->entry_eof || rar->offset_seek >= rar->unp_size) {
+ *buff = NULL;
+ *size = 0;
+ *offset = rar->offset;
+ if (*offset < rar->unp_size)
+ *offset = rar->unp_size;
+ return (ARCHIVE_EOF);
+ }
+
+ switch (rar->compression_method)
+ {
+ case COMPRESS_METHOD_STORE:
+ ret = read_data_stored(a, buff, size, offset);
+ break;
+
+ case COMPRESS_METHOD_FASTEST:
+ case COMPRESS_METHOD_FAST:
+ case COMPRESS_METHOD_NORMAL:
+ case COMPRESS_METHOD_GOOD:
+ case COMPRESS_METHOD_BEST:
+ ret = read_data_compressed(a, buff, size, offset);
+ if (ret != ARCHIVE_OK && ret != ARCHIVE_WARN)
+ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc);
+ break;
+
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unsupported compression method for RAR file.");
+ ret = ARCHIVE_FATAL;
+ break;
+ }
+ return (ret);
+}
+
+static int
+archive_read_format_rar_read_data_skip(struct archive_read *a)
+{
+ struct rar *rar;
+ int64_t bytes_skipped;
+ int ret;
+
+ rar = (struct rar *)(a->format->data);
+
+ if (rar->bytes_unconsumed > 0) {
+ /* Consume as much as the decompressor actually used. */
+ __archive_read_consume(a, rar->bytes_unconsumed);
+ rar->bytes_unconsumed = 0;
+ }
+
+ if (rar->bytes_remaining > 0) {
+ bytes_skipped = __archive_read_consume(a, rar->bytes_remaining);
+ if (bytes_skipped < 0)
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Compressed data to skip must be read from each header in a multivolume
+ * archive.
+ */
+ if (rar->main_flags & MHD_VOLUME && rar->file_flags & FHD_SPLIT_AFTER)
+ {
+ ret = archive_read_format_rar_read_header(a, a->entry);
+ if (ret == (ARCHIVE_EOF))
+ ret = archive_read_format_rar_read_header(a, a->entry);
+ if (ret != (ARCHIVE_OK))
+ return ret;
+ return archive_read_format_rar_read_data_skip(a);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static int64_t
+archive_read_format_rar_seek_data(struct archive_read *a, int64_t offset,
+ int whence)
+{
+ int64_t client_offset, ret;
+ unsigned int i;
+ struct rar *rar = (struct rar *)(a->format->data);
+
+ if (rar->compression_method == COMPRESS_METHOD_STORE)
+ {
+ /* Modify the offset for use with SEEK_SET */
+ switch (whence)
+ {
+ case SEEK_CUR:
+ client_offset = rar->offset_seek;
+ break;
+ case SEEK_END:
+ client_offset = rar->unp_size;
+ break;
+ case SEEK_SET:
+ default:
+ client_offset = 0;
+ }
+ client_offset += offset;
+ if (client_offset < 0)
+ {
+ /* Can't seek past beginning of data block */
+ return -1;
+ }
+ else if (client_offset > rar->unp_size)
+ {
+ /*
+ * Set the returned offset but only seek to the end of
+ * the data block.
+ */
+ rar->offset_seek = client_offset;
+ client_offset = rar->unp_size;
+ }
+
+ client_offset += rar->dbo[0].start_offset;
+ i = 0;
+ while (i < rar->cursor)
+ {
+ i++;
+ client_offset += rar->dbo[i].start_offset - rar->dbo[i-1].end_offset;
+ }
+ if (rar->main_flags & MHD_VOLUME)
+ {
+ /* Find the appropriate offset among the multivolume archive */
+ while (1)
+ {
+ if (client_offset < rar->dbo[rar->cursor].start_offset &&
+ rar->file_flags & FHD_SPLIT_BEFORE)
+ {
+ /* Search backwards for the correct data block */
+ if (rar->cursor == 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Attempt to seek past beginning of RAR data block");
+ return (ARCHIVE_FAILED);
+ }
+ rar->cursor--;
+ client_offset -= rar->dbo[rar->cursor+1].start_offset -
+ rar->dbo[rar->cursor].end_offset;
+ if (client_offset < rar->dbo[rar->cursor].start_offset)
+ continue;
+ ret = __archive_read_seek(a, rar->dbo[rar->cursor].start_offset -
+ rar->dbo[rar->cursor].header_size, SEEK_SET);
+ if (ret < (ARCHIVE_OK))
+ return ret;
+ ret = archive_read_format_rar_read_header(a, a->entry);
+ if (ret != (ARCHIVE_OK))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Error during seek of RAR file");
+ return (ARCHIVE_FAILED);
+ }
+ rar->cursor--;
+ break;
+ }
+ else if (client_offset > rar->dbo[rar->cursor].end_offset &&
+ rar->file_flags & FHD_SPLIT_AFTER)
+ {
+ /* Search forward for the correct data block */
+ rar->cursor++;
+ if (rar->cursor < rar->nodes &&
+ client_offset > rar->dbo[rar->cursor].end_offset)
+ {
+ client_offset += rar->dbo[rar->cursor].start_offset -
+ rar->dbo[rar->cursor-1].end_offset;
+ continue;
+ }
+ rar->cursor--;
+ ret = __archive_read_seek(a, rar->dbo[rar->cursor].end_offset,
+ SEEK_SET);
+ if (ret < (ARCHIVE_OK))
+ return ret;
+ ret = archive_read_format_rar_read_header(a, a->entry);
+ if (ret == (ARCHIVE_EOF))
+ {
+ rar->has_endarc_header = 1;
+ ret = archive_read_format_rar_read_header(a, a->entry);
+ }
+ if (ret != (ARCHIVE_OK))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Error during seek of RAR file");
+ return (ARCHIVE_FAILED);
+ }
+ client_offset += rar->dbo[rar->cursor].start_offset -
+ rar->dbo[rar->cursor-1].end_offset;
+ continue;
+ }
+ break;
+ }
+ }
+
+ ret = __archive_read_seek(a, client_offset, SEEK_SET);
+ if (ret < (ARCHIVE_OK))
+ return ret;
+ rar->bytes_remaining = rar->dbo[rar->cursor].end_offset - ret;
+ i = rar->cursor;
+ while (i > 0)
+ {
+ i--;
+ ret -= rar->dbo[i+1].start_offset - rar->dbo[i].end_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;
+ rar->bytes_unconsumed = 0;
+ rar->offset = 0;
+
+ /*
+ * If a seek past the end of file was requested, return the requested
+ * offset.
+ */
+ if (ret == rar->unp_size && rar->offset_seek > rar->unp_size)
+ return rar->offset_seek;
+
+ /* Return the new offset */
+ rar->offset_seek = ret;
+ return rar->offset_seek;
+ }
+ else
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Seeking of compressed RAR files is unsupported");
+ }
+ return (ARCHIVE_FAILED);
+}
+
+static int
+archive_read_format_rar_cleanup(struct archive_read *a)
+{
+ struct rar *rar;
+
+ rar = (struct rar *)(a->format->data);
+ free_codes(a);
+ free(rar->filename);
+ free(rar->filename_save);
+ free(rar->dbo);
+ free(rar->unp_buffer);
+ free(rar->lzss.window);
+ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc);
+ free(rar);
+ (a->format->data) = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+read_header(struct archive_read *a, struct archive_entry *entry,
+ char head_type)
+{
+ const void *h;
+ const char *p, *endp;
+ struct rar *rar;
+ struct rar_header rar_header;
+ struct rar_file_header file_header;
+ int64_t header_size;
+ unsigned filename_size, end;
+ char *filename;
+ char *strp;
+ char packed_size[8];
+ char unp_size[8];
+ int ttime;
+ struct archive_string_conv *sconv, *fn_sconv;
+ unsigned long crc32_val;
+ int ret = (ARCHIVE_OK), ret2;
+
+ rar = (struct rar *)(a->format->data);
+
+ /* Setup a string conversion object for non-rar-unicode filenames. */
+ sconv = rar->opt_sconv;
+ if (sconv == NULL) {
+ if (!rar->init_default_conversion) {
+ rar->sconv_default =
+ archive_string_default_conversion_for_read(
+ &(a->archive));
+ rar->init_default_conversion = 1;
+ }
+ sconv = rar->sconv_default;
+ }
+
+
+ if ((h = __archive_read_ahead(a, 7, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+ memcpy(&rar_header, p, sizeof(rar_header));
+ rar->file_flags = archive_le16dec(rar_header.flags);
+ header_size = archive_le16dec(rar_header.size);
+ if (header_size < (int64_t)sizeof(file_header) + 7) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid header size");
+ return (ARCHIVE_FATAL);
+ }
+ crc32_val = crc32(0, (const unsigned char *)p + 2, 7 - 2);
+ __archive_read_consume(a, 7);
+
+ if (!(rar->file_flags & FHD_SOLID))
+ {
+ rar->compression_method = 0;
+ rar->packed_size = 0;
+ rar->unp_size = 0;
+ rar->mtime = 0;
+ rar->ctime = 0;
+ rar->atime = 0;
+ rar->arctime = 0;
+ rar->mode = 0;
+ memset(&rar->salt, 0, sizeof(rar->salt));
+ rar->atime = 0;
+ rar->ansec = 0;
+ rar->ctime = 0;
+ rar->cnsec = 0;
+ rar->mtime = 0;
+ rar->mnsec = 0;
+ rar->arctime = 0;
+ rar->arcnsec = 0;
+ }
+ else
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "RAR solid archive support unavailable.");
+ return (ARCHIVE_FATAL);
+ }
+
+ if ((h = __archive_read_ahead(a, (size_t)header_size - 7, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+
+ /* File Header CRC check. */
+ crc32_val = crc32(crc32_val, h, (unsigned)(header_size - 7));
+ if ((crc32_val & 0xffff) != archive_le16dec(rar_header.crc)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Header CRC error");
+ return (ARCHIVE_FATAL);
+ }
+ /* If no CRC error, Go on parsing File Header. */
+ p = h;
+ endp = p + header_size - 7;
+ memcpy(&file_header, p, sizeof(file_header));
+ p += sizeof(file_header);
+
+ rar->compression_method = file_header.method;
+
+ ttime = archive_le32dec(file_header.file_time);
+ rar->mtime = get_time(ttime);
+
+ rar->file_crc = archive_le32dec(file_header.file_crc);
+
+ if (rar->file_flags & FHD_PASSWORD)
+ {
+ archive_entry_set_is_data_encrypted(entry, 1);
+ rar->has_encrypted_entries = 1;
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "RAR encryption support unavailable.");
+ /* Since it is only the data part itself that is encrypted we can at least
+ extract information about the currently processed entry and don't need
+ to return ARCHIVE_FATAL here. */
+ /*return (ARCHIVE_FATAL);*/
+ }
+
+ if (rar->file_flags & FHD_LARGE)
+ {
+ memcpy(packed_size, file_header.pack_size, 4);
+ memcpy(packed_size + 4, p, 4); /* High pack size */
+ p += 4;
+ memcpy(unp_size, file_header.unp_size, 4);
+ memcpy(unp_size + 4, p, 4); /* High unpack size */
+ p += 4;
+ rar->packed_size = archive_le64dec(&packed_size);
+ rar->unp_size = archive_le64dec(&unp_size);
+ }
+ else
+ {
+ rar->packed_size = archive_le32dec(file_header.pack_size);
+ rar->unp_size = archive_le32dec(file_header.unp_size);
+ }
+
+ if (rar->packed_size < 0 || rar->unp_size < 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid sizes specified.");
+ return (ARCHIVE_FATAL);
+ }
+
+ rar->bytes_remaining = rar->packed_size;
+
+ /* TODO: RARv3 subblocks contain comments. For now the complete block is
+ * consumed at the end.
+ */
+ if (head_type == NEWSUB_HEAD) {
+ size_t distance = p - (const char *)h;
+ header_size += rar->packed_size;
+ /* Make sure we have the extended data. */
+ if ((h = __archive_read_ahead(a, (size_t)header_size - 7, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+ endp = p + header_size - 7;
+ p += distance;
+ }
+
+ filename_size = archive_le16dec(file_header.name_size);
+ if (p + filename_size > endp) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid filename size");
+ return (ARCHIVE_FATAL);
+ }
+ if (rar->filename_allocated < filename_size * 2 + 2) {
+ char *newptr;
+ size_t newsize = filename_size * 2 + 2;
+ newptr = realloc(rar->filename, newsize);
+ if (newptr == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't allocate memory.");
+ return (ARCHIVE_FATAL);
+ }
+ rar->filename = newptr;
+ rar->filename_allocated = newsize;
+ }
+ filename = rar->filename;
+ memcpy(filename, p, filename_size);
+ filename[filename_size] = '\0';
+ if (rar->file_flags & FHD_UNICODE)
+ {
+ if (filename_size != strlen(filename))
+ {
+ unsigned char highbyte, flagbits, flagbyte;
+ unsigned fn_end, offset;
+
+ end = filename_size;
+ fn_end = filename_size * 2;
+ filename_size = 0;
+ offset = (unsigned)strlen(filename) + 1;
+ highbyte = *(p + offset++);
+ flagbits = 0;
+ flagbyte = 0;
+ while (offset < end && filename_size < fn_end)
+ {
+ if (!flagbits)
+ {
+ flagbyte = *(p + offset++);
+ flagbits = 8;
+ }
+
+ flagbits -= 2;
+ switch((flagbyte >> flagbits) & 3)
+ {
+ case 0:
+ filename[filename_size++] = '\0';
+ filename[filename_size++] = *(p + offset++);
+ break;
+ case 1:
+ filename[filename_size++] = highbyte;
+ filename[filename_size++] = *(p + offset++);
+ break;
+ case 2:
+ filename[filename_size++] = *(p + offset + 1);
+ filename[filename_size++] = *(p + offset);
+ offset += 2;
+ break;
+ case 3:
+ {
+ char extra, high;
+ uint8_t length = *(p + offset++);
+
+ if (length & 0x80) {
+ extra = *(p + offset++);
+ high = (char)highbyte;
+ } else
+ extra = high = 0;
+ length = (length & 0x7f) + 2;
+ while (length && filename_size < fn_end) {
+ unsigned cp = filename_size >> 1;
+ filename[filename_size++] = high;
+ filename[filename_size++] = p[cp] + extra;
+ length--;
+ }
+ }
+ break;
+ }
+ }
+ if (filename_size > fn_end) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid filename");
+ return (ARCHIVE_FATAL);
+ }
+ filename[filename_size++] = '\0';
+ filename[filename_size++] = '\0';
+
+ /* Decoded unicode form is UTF-16BE, so we have to update a string
+ * conversion object for it. */
+ if (rar->sconv_utf16be == NULL) {
+ rar->sconv_utf16be = archive_string_conversion_from_charset(
+ &a->archive, "UTF-16BE", 1);
+ if (rar->sconv_utf16be == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ fn_sconv = rar->sconv_utf16be;
+
+ strp = filename;
+ while (memcmp(strp, "\x00\x00", 2))
+ {
+ if (!memcmp(strp, "\x00\\", 2))
+ *(strp + 1) = '/';
+ strp += 2;
+ }
+ p += offset;
+ } else {
+ /*
+ * If FHD_UNICODE is set but no unicode data, this file name form
+ * is UTF-8, so we have to update a string conversion object for
+ * it accordingly.
+ */
+ if (rar->sconv_utf8 == NULL) {
+ rar->sconv_utf8 = archive_string_conversion_from_charset(
+ &a->archive, "UTF-8", 1);
+ if (rar->sconv_utf8 == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ fn_sconv = rar->sconv_utf8;
+ while ((strp = strchr(filename, '\\')) != NULL)
+ *strp = '/';
+ p += filename_size;
+ }
+ }
+ else
+ {
+ fn_sconv = sconv;
+ while ((strp = strchr(filename, '\\')) != NULL)
+ *strp = '/';
+ p += filename_size;
+ }
+
+ /* Split file in multivolume RAR. No more need to process header. */
+ if (rar->filename_save &&
+ !memcmp(rar->filename, rar->filename_save, filename_size + 1))
+ {
+ __archive_read_consume(a, header_size - 7);
+ rar->cursor++;
+ if (rar->cursor >= rar->nodes)
+ {
+ rar->nodes++;
+ if ((rar->dbo =
+ realloc(rar->dbo, sizeof(*rar->dbo) * rar->nodes)) == NULL)
+ {
+ archive_set_error(&a->archive, ENOMEM, "Couldn't allocate memory.");
+ return (ARCHIVE_FATAL);
+ }
+ rar->dbo[rar->cursor].header_size = header_size;
+ rar->dbo[rar->cursor].start_offset = -1;
+ rar->dbo[rar->cursor].end_offset = -1;
+ }
+ if (rar->dbo[rar->cursor].start_offset < 0)
+ {
+ rar->dbo[rar->cursor].start_offset = a->filter->position;
+ rar->dbo[rar->cursor].end_offset = rar->dbo[rar->cursor].start_offset +
+ rar->packed_size;
+ }
+ return ret;
+ }
+
+ rar->filename_save = (char*)realloc(rar->filename_save,
+ filename_size + 1);
+ memcpy(rar->filename_save, rar->filename, filename_size + 1);
+
+ /* Set info for seeking */
+ free(rar->dbo);
+ if ((rar->dbo = calloc(1, sizeof(*rar->dbo))) == NULL)
+ {
+ archive_set_error(&a->archive, ENOMEM, "Couldn't allocate memory.");
+ return (ARCHIVE_FATAL);
+ }
+ rar->dbo[0].header_size = header_size;
+ rar->dbo[0].start_offset = -1;
+ rar->dbo[0].end_offset = -1;
+ rar->cursor = 0;
+ rar->nodes = 1;
+
+ if (rar->file_flags & FHD_SALT)
+ {
+ if (p + 8 > endp) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid header size");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(rar->salt, p, 8);
+ p += 8;
+ }
+
+ if (rar->file_flags & FHD_EXTTIME) {
+ if (read_exttime(p, rar, endp) < 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid header size");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ __archive_read_consume(a, header_size - 7);
+ rar->dbo[0].start_offset = a->filter->position;
+ rar->dbo[0].end_offset = rar->dbo[0].start_offset + rar->packed_size;
+
+ switch(file_header.host_os)
+ {
+ case OS_MSDOS:
+ case OS_OS2:
+ case OS_WIN32:
+ rar->mode = archive_le32dec(file_header.file_attr);
+ if (rar->mode & FILE_ATTRIBUTE_DIRECTORY)
+ rar->mode = AE_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
+ else
+ rar->mode = AE_IFREG;
+ rar->mode |= S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+ break;
+
+ case OS_UNIX:
+ case OS_MAC_OS:
+ case OS_BEOS:
+ rar->mode = archive_le32dec(file_header.file_attr);
+ break;
+
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unknown file attributes from RAR file's host OS");
+ return (ARCHIVE_FATAL);
+ }
+
+ rar->bytes_uncopied = rar->bytes_unconsumed = 0;
+ rar->lzss.position = rar->offset = 0;
+ rar->offset_seek = 0;
+ rar->dictionary_size = 0;
+ rar->offset_outgoing = 0;
+ rar->br.cache_avail = 0;
+ rar->br.avail_in = 0;
+ rar->crc_calculated = 0;
+ rar->entry_eof = 0;
+ rar->valid = 1;
+ rar->is_ppmd_block = 0;
+ rar->start_new_table = 1;
+ free(rar->unp_buffer);
+ rar->unp_buffer = NULL;
+ rar->unp_offset = 0;
+ rar->unp_buffer_size = UNP_BUFFER_SIZE;
+ memset(rar->lengthtable, 0, sizeof(rar->lengthtable));
+ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc);
+ rar->ppmd_valid = rar->ppmd_eod = 0;
+
+ /* Don't set any archive entries for non-file header types */
+ if (head_type == NEWSUB_HEAD)
+ return ret;
+
+ archive_entry_set_mtime(entry, rar->mtime, rar->mnsec);
+ archive_entry_set_ctime(entry, rar->ctime, rar->cnsec);
+ archive_entry_set_atime(entry, rar->atime, rar->ansec);
+ archive_entry_set_size(entry, rar->unp_size);
+ archive_entry_set_mode(entry, rar->mode);
+
+ if (archive_entry_copy_pathname_l(entry, filename, filename_size, fn_sconv))
+ {
+ if (errno == ENOMEM)
+ {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Pathname cannot be converted from %s to current locale.",
+ archive_string_conversion_charset_name(fn_sconv));
+ ret = (ARCHIVE_WARN);
+ }
+
+ if (((rar->mode) & AE_IFMT) == AE_IFLNK)
+ {
+ /* Make sure a symbolic-link file does not have its body. */
+ rar->bytes_remaining = 0;
+ archive_entry_set_size(entry, 0);
+
+ /* Read a symbolic-link name. */
+ if ((ret2 = read_symlink_stored(a, entry, sconv)) < (ARCHIVE_WARN))
+ return ret2;
+ if (ret > ret2)
+ ret = ret2;
+ }
+
+ if (rar->bytes_remaining == 0)
+ rar->entry_eof = 1;
+
+ return ret;
+}
+
+static time_t
+get_time(int ttime)
+{
+ struct tm tm;
+ tm.tm_sec = 2 * (ttime & 0x1f);
+ tm.tm_min = (ttime >> 5) & 0x3f;
+ tm.tm_hour = (ttime >> 11) & 0x1f;
+ tm.tm_mday = (ttime >> 16) & 0x1f;
+ tm.tm_mon = ((ttime >> 21) & 0x0f) - 1;
+ tm.tm_year = ((ttime >> 25) & 0x7f) + 80;
+ tm.tm_isdst = -1;
+ return mktime(&tm);
+}
+
+static int
+read_exttime(const char *p, struct rar *rar, const char *endp)
+{
+ unsigned rmode, flags, rem, j, count;
+ int ttime, i;
+ struct tm *tm;
+ time_t t;
+ long nsec;
+
+ if (p + 2 > endp)
+ return (-1);
+ flags = archive_le16dec(p);
+ p += 2;
+
+ for (i = 3; i >= 0; i--)
+ {
+ t = 0;
+ if (i == 3)
+ t = rar->mtime;
+ rmode = flags >> i * 4;
+ if (rmode & 8)
+ {
+ if (!t)
+ {
+ if (p + 4 > endp)
+ return (-1);
+ ttime = archive_le32dec(p);
+ t = get_time(ttime);
+ p += 4;
+ }
+ rem = 0;
+ count = rmode & 3;
+ if (p + count > endp)
+ return (-1);
+ for (j = 0; j < count; j++)
+ {
+ rem = ((*p) << 16) | (rem >> 8);
+ p++;
+ }
+ tm = localtime(&t);
+ nsec = tm->tm_sec + rem / NS_UNIT;
+ if (rmode & 4)
+ {
+ tm->tm_sec++;
+ t = mktime(tm);
+ }
+ if (i == 3)
+ {
+ rar->mtime = t;
+ rar->mnsec = nsec;
+ }
+ else if (i == 2)
+ {
+ rar->ctime = t;
+ rar->cnsec = nsec;
+ }
+ else if (i == 1)
+ {
+ rar->atime = t;
+ rar->ansec = nsec;
+ }
+ else
+ {
+ rar->arctime = t;
+ rar->arcnsec = nsec;
+ }
+ }
+ }
+ return (0);
+}
+
+static int
+read_symlink_stored(struct archive_read *a, struct archive_entry *entry,
+ struct archive_string_conv *sconv)
+{
+ const void *h;
+ const char *p;
+ struct rar *rar;
+ int ret = (ARCHIVE_OK);
+
+ rar = (struct rar *)(a->format->data);
+ if ((h = rar_read_ahead(a, (size_t)rar->packed_size, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+
+ if (archive_entry_copy_symlink_l(entry,
+ p, (size_t)rar->packed_size, sconv))
+ {
+ if (errno == ENOMEM)
+ {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for link");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "link cannot be converted from %s to current locale.",
+ archive_string_conversion_charset_name(sconv));
+ ret = (ARCHIVE_WARN);
+ }
+ __archive_read_consume(a, rar->packed_size);
+ return ret;
+}
+
+static int
+read_data_stored(struct archive_read *a, const void **buff, size_t *size,
+ int64_t *offset)
+{
+ struct rar *rar;
+ ssize_t bytes_avail;
+
+ rar = (struct rar *)(a->format->data);
+ if (rar->bytes_remaining == 0 &&
+ !(rar->main_flags & MHD_VOLUME && rar->file_flags & FHD_SPLIT_AFTER))
+ {
+ *buff = NULL;
+ *size = 0;
+ *offset = rar->offset;
+ if (rar->file_crc != rar->crc_calculated) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "File CRC error");
+ return (ARCHIVE_FATAL);
+ }
+ rar->entry_eof = 1;
+ return (ARCHIVE_EOF);
+ }
+
+ *buff = rar_read_ahead(a, 1, &bytes_avail);
+ if (bytes_avail <= 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated RAR file data");
+ return (ARCHIVE_FATAL);
+ }
+
+ *size = bytes_avail;
+ *offset = rar->offset;
+ rar->offset += bytes_avail;
+ rar->offset_seek += bytes_avail;
+ rar->bytes_remaining -= bytes_avail;
+ rar->bytes_unconsumed = bytes_avail;
+ /* Calculate File CRC. */
+ rar->crc_calculated = crc32(rar->crc_calculated, *buff,
+ (unsigned)bytes_avail);
+ return (ARCHIVE_OK);
+}
+
+static int
+read_data_compressed(struct archive_read *a, const void **buff, size_t *size,
+ int64_t *offset)
+{
+ struct rar *rar;
+ int64_t start, end, actualend;
+ size_t bs;
+ int ret = (ARCHIVE_OK), sym, code, lzss_offset, length, i;
+
+ rar = (struct rar *)(a->format->data);
+
+ do {
+ if (!rar->valid)
+ return (ARCHIVE_FATAL);
+ if (rar->ppmd_eod ||
+ (rar->dictionary_size && rar->offset >= rar->unp_size))
+ {
+ if (rar->unp_offset > 0) {
+ /*
+ * We have unprocessed extracted data. write it out.
+ */
+ *buff = rar->unp_buffer;
+ *size = rar->unp_offset;
+ *offset = rar->offset_outgoing;
+ rar->offset_outgoing += *size;
+ /* Calculate File CRC. */
+ rar->crc_calculated = crc32(rar->crc_calculated, *buff,
+ (unsigned)*size);
+ rar->unp_offset = 0;
+ return (ARCHIVE_OK);
+ }
+ *buff = NULL;
+ *size = 0;
+ *offset = rar->offset;
+ if (rar->file_crc != rar->crc_calculated) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "File CRC error");
+ return (ARCHIVE_FATAL);
+ }
+ rar->entry_eof = 1;
+ return (ARCHIVE_EOF);
+ }
+
+ if (!rar->is_ppmd_block && rar->dictionary_size && rar->bytes_uncopied > 0)
+ {
+ if (rar->bytes_uncopied > (rar->unp_buffer_size - rar->unp_offset))
+ bs = rar->unp_buffer_size - rar->unp_offset;
+ else
+ bs = (size_t)rar->bytes_uncopied;
+ ret = copy_from_lzss_window(a, buff, rar->offset, (int)bs);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ rar->offset += bs;
+ rar->bytes_uncopied -= bs;
+ if (*buff != NULL) {
+ rar->unp_offset = 0;
+ *size = rar->unp_buffer_size;
+ *offset = rar->offset_outgoing;
+ rar->offset_outgoing += *size;
+ /* Calculate File CRC. */
+ rar->crc_calculated = crc32(rar->crc_calculated, *buff,
+ (unsigned)*size);
+ return (ret);
+ }
+ continue;
+ }
+
+ if (!rar->br.next_in &&
+ (ret = rar_br_preparation(a, &(rar->br))) < ARCHIVE_WARN)
+ return (ret);
+ if (rar->start_new_table && ((ret = parse_codes(a)) < (ARCHIVE_WARN)))
+ return (ret);
+
+ if (rar->is_ppmd_block)
+ {
+ if ((sym = __archive_ppmd7_functions.Ppmd7_DecodeSymbol(
+ &rar->ppmd7_context, &rar->range_dec.p)) < 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid symbol");
+ return (ARCHIVE_FATAL);
+ }
+ if(sym != rar->ppmd_escape)
+ {
+ lzss_emit_literal(rar, sym);
+ rar->bytes_uncopied++;
+ }
+ else
+ {
+ if ((code = __archive_ppmd7_functions.Ppmd7_DecodeSymbol(
+ &rar->ppmd7_context, &rar->range_dec.p)) < 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid symbol");
+ return (ARCHIVE_FATAL);
+ }
+
+ switch(code)
+ {
+ case 0:
+ rar->start_new_table = 1;
+ return read_data_compressed(a, buff, size, offset);
+
+ case 2:
+ rar->ppmd_eod = 1;/* End Of ppmd Data. */
+ continue;
+
+ case 3:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Parsing filters is unsupported.");
+ return (ARCHIVE_FAILED);
+
+ case 4:
+ lzss_offset = 0;
+ for (i = 2; i >= 0; i--)
+ {
+ if ((code = __archive_ppmd7_functions.Ppmd7_DecodeSymbol(
+ &rar->ppmd7_context, &rar->range_dec.p)) < 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid symbol");
+ return (ARCHIVE_FATAL);
+ }
+ lzss_offset |= code << (i * 8);
+ }
+ if ((length = __archive_ppmd7_functions.Ppmd7_DecodeSymbol(
+ &rar->ppmd7_context, &rar->range_dec.p)) < 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid symbol");
+ return (ARCHIVE_FATAL);
+ }
+ lzss_emit_match(rar, lzss_offset + 2, length + 32);
+ rar->bytes_uncopied += length + 32;
+ break;
+
+ case 5:
+ if ((length = __archive_ppmd7_functions.Ppmd7_DecodeSymbol(
+ &rar->ppmd7_context, &rar->range_dec.p)) < 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid symbol");
+ return (ARCHIVE_FATAL);
+ }
+ lzss_emit_match(rar, 1, length + 4);
+ rar->bytes_uncopied += length + 4;
+ break;
+
+ default:
+ lzss_emit_literal(rar, sym);
+ rar->bytes_uncopied++;
+ }
+ }
+ }
+ else
+ {
+ start = rar->offset;
+ end = start + rar->dictionary_size;
+ rar->filterstart = INT64_MAX;
+
+ if ((actualend = expand(a, end)) < 0)
+ return ((int)actualend);
+
+ rar->bytes_uncopied = actualend - start;
+ if (rar->bytes_uncopied == 0) {
+ /* Broken RAR files cause this case.
+ * NOTE: If this case were possible on a normal RAR file
+ * we would find out where it was actually bad and
+ * what we would do to solve it. */
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Internal error extracting RAR file");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ if (rar->bytes_uncopied > (rar->unp_buffer_size - rar->unp_offset))
+ bs = rar->unp_buffer_size - rar->unp_offset;
+ else
+ bs = (size_t)rar->bytes_uncopied;
+ ret = copy_from_lzss_window(a, buff, rar->offset, (int)bs);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ rar->offset += bs;
+ rar->bytes_uncopied -= bs;
+ /*
+ * If *buff is NULL, it means unp_buffer is not full.
+ * So we have to continue extracting a RAR file.
+ */
+ } while (*buff == NULL);
+
+ rar->unp_offset = 0;
+ *size = rar->unp_buffer_size;
+ *offset = rar->offset_outgoing;
+ rar->offset_outgoing += *size;
+ /* Calculate File CRC. */
+ rar->crc_calculated = crc32(rar->crc_calculated, *buff, (unsigned)*size);
+ return ret;
+}
+
+static int
+parse_codes(struct archive_read *a)
+{
+ int i, j, val, n, r;
+ unsigned char bitlengths[MAX_SYMBOLS], zerocount, ppmd_flags;
+ unsigned int maxorder;
+ struct huffman_code precode;
+ struct rar *rar = (struct rar *)(a->format->data);
+ struct rar_br *br = &(rar->br);
+
+ free_codes(a);
+
+ /* Skip to the next byte */
+ rar_br_consume_unalined_bits(br);
+
+ /* PPMd block flag */
+ if (!rar_br_read_ahead(a, br, 1))
+ goto truncated_data;
+ if ((rar->is_ppmd_block = rar_br_bits(br, 1)) != 0)
+ {
+ rar_br_consume(br, 1);
+ if (!rar_br_read_ahead(a, br, 7))
+ goto truncated_data;
+ ppmd_flags = rar_br_bits(br, 7);
+ rar_br_consume(br, 7);
+
+ /* Memory is allocated in MB */
+ if (ppmd_flags & 0x20)
+ {
+ if (!rar_br_read_ahead(a, br, 8))
+ goto truncated_data;
+ rar->dictionary_size = (rar_br_bits(br, 8) + 1) << 20;
+ rar_br_consume(br, 8);
+ }
+
+ if (ppmd_flags & 0x40)
+ {
+ if (!rar_br_read_ahead(a, br, 8))
+ goto truncated_data;
+ rar->ppmd_escape = rar->ppmd7_context.InitEsc = rar_br_bits(br, 8);
+ rar_br_consume(br, 8);
+ }
+ else
+ rar->ppmd_escape = 2;
+
+ if (ppmd_flags & 0x20)
+ {
+ maxorder = (ppmd_flags & 0x1F) + 1;
+ if(maxorder > 16)
+ maxorder = 16 + (maxorder - 16) * 3;
+
+ if (maxorder == 1)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated RAR file data");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Make sure ppmd7_contest is freed before Ppmd7_Construct
+ * because reading a broken file cause this abnormal sequence. */
+ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc);
+
+ rar->bytein.a = a;
+ rar->bytein.Read = &ppmd_read;
+ __archive_ppmd7_functions.PpmdRAR_RangeDec_CreateVTable(&rar->range_dec);
+ rar->range_dec.Stream = &rar->bytein;
+ __archive_ppmd7_functions.Ppmd7_Construct(&rar->ppmd7_context);
+
+ if (!__archive_ppmd7_functions.Ppmd7_Alloc(&rar->ppmd7_context,
+ rar->dictionary_size, &g_szalloc))
+ {
+ archive_set_error(&a->archive, ENOMEM,
+ "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ if (!__archive_ppmd7_functions.PpmdRAR_RangeDec_Init(&rar->range_dec))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unable to initialize PPMd range decoder");
+ return (ARCHIVE_FATAL);
+ }
+ __archive_ppmd7_functions.Ppmd7_Init(&rar->ppmd7_context, maxorder);
+ rar->ppmd_valid = 1;
+ }
+ else
+ {
+ if (!rar->ppmd_valid) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid PPMd sequence");
+ return (ARCHIVE_FATAL);
+ }
+ if (!__archive_ppmd7_functions.PpmdRAR_RangeDec_Init(&rar->range_dec))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unable to initialize PPMd range decoder");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ }
+ else
+ {
+ rar_br_consume(br, 1);
+
+ /* Keep existing table flag */
+ if (!rar_br_read_ahead(a, br, 1))
+ goto truncated_data;
+ if (!rar_br_bits(br, 1))
+ memset(rar->lengthtable, 0, sizeof(rar->lengthtable));
+ rar_br_consume(br, 1);
+
+ memset(&bitlengths, 0, sizeof(bitlengths));
+ for (i = 0; i < MAX_SYMBOLS;)
+ {
+ if (!rar_br_read_ahead(a, br, 4))
+ goto truncated_data;
+ bitlengths[i++] = rar_br_bits(br, 4);
+ rar_br_consume(br, 4);
+ if (bitlengths[i-1] == 0xF)
+ {
+ if (!rar_br_read_ahead(a, br, 4))
+ goto truncated_data;
+ zerocount = rar_br_bits(br, 4);
+ rar_br_consume(br, 4);
+ if (zerocount)
+ {
+ i--;
+ for (j = 0; j < zerocount + 2 && i < MAX_SYMBOLS; j++)
+ bitlengths[i++] = 0;
+ }
+ }
+ }
+
+ memset(&precode, 0, sizeof(precode));
+ r = create_code(a, &precode, bitlengths, MAX_SYMBOLS, MAX_SYMBOL_LENGTH);
+ if (r != ARCHIVE_OK) {
+ free(precode.tree);
+ free(precode.table);
+ return (r);
+ }
+
+ for (i = 0; i < HUFFMAN_TABLE_SIZE;)
+ {
+ if ((val = read_next_symbol(a, &precode)) < 0) {
+ free(precode.tree);
+ free(precode.table);
+ return (ARCHIVE_FATAL);
+ }
+ if (val < 16)
+ {
+ rar->lengthtable[i] = (rar->lengthtable[i] + val) & 0xF;
+ i++;
+ }
+ else if (val < 18)
+ {
+ if (i == 0)
+ {
+ free(precode.tree);
+ free(precode.table);
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Internal error extracting RAR file.");
+ return (ARCHIVE_FATAL);
+ }
+
+ if(val == 16) {
+ if (!rar_br_read_ahead(a, br, 3)) {
+ free(precode.tree);
+ free(precode.table);
+ goto truncated_data;
+ }
+ n = rar_br_bits(br, 3) + 3;
+ rar_br_consume(br, 3);
+ } else {
+ if (!rar_br_read_ahead(a, br, 7)) {
+ free(precode.tree);
+ free(precode.table);
+ goto truncated_data;
+ }
+ n = rar_br_bits(br, 7) + 11;
+ rar_br_consume(br, 7);
+ }
+
+ for (j = 0; j < n && i < HUFFMAN_TABLE_SIZE; j++)
+ {
+ rar->lengthtable[i] = rar->lengthtable[i-1];
+ i++;
+ }
+ }
+ else
+ {
+ if(val == 18) {
+ if (!rar_br_read_ahead(a, br, 3)) {
+ free(precode.tree);
+ free(precode.table);
+ goto truncated_data;
+ }
+ n = rar_br_bits(br, 3) + 3;
+ rar_br_consume(br, 3);
+ } else {
+ if (!rar_br_read_ahead(a, br, 7)) {
+ free(precode.tree);
+ free(precode.table);
+ goto truncated_data;
+ }
+ n = rar_br_bits(br, 7) + 11;
+ rar_br_consume(br, 7);
+ }
+
+ for(j = 0; j < n && i < HUFFMAN_TABLE_SIZE; j++)
+ rar->lengthtable[i++] = 0;
+ }
+ }
+ free(precode.tree);
+ free(precode.table);
+
+ r = create_code(a, &rar->maincode, &rar->lengthtable[0], MAINCODE_SIZE,
+ MAX_SYMBOL_LENGTH);
+ if (r != ARCHIVE_OK)
+ return (r);
+ r = create_code(a, &rar->offsetcode, &rar->lengthtable[MAINCODE_SIZE],
+ OFFSETCODE_SIZE, MAX_SYMBOL_LENGTH);
+ if (r != ARCHIVE_OK)
+ return (r);
+ r = create_code(a, &rar->lowoffsetcode,
+ &rar->lengthtable[MAINCODE_SIZE + OFFSETCODE_SIZE],
+ LOWOFFSETCODE_SIZE, MAX_SYMBOL_LENGTH);
+ if (r != ARCHIVE_OK)
+ return (r);
+ r = create_code(a, &rar->lengthcode,
+ &rar->lengthtable[MAINCODE_SIZE + OFFSETCODE_SIZE +
+ LOWOFFSETCODE_SIZE], LENGTHCODE_SIZE, MAX_SYMBOL_LENGTH);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+
+ if (!rar->dictionary_size || !rar->lzss.window)
+ {
+ /* Seems as though dictionary sizes are not used. Even so, minimize
+ * memory usage as much as possible.
+ */
+ void *new_window;
+ unsigned int new_size;
+
+ if (rar->unp_size >= DICTIONARY_MAX_SIZE)
+ new_size = DICTIONARY_MAX_SIZE;
+ else
+ new_size = rar_fls((unsigned int)rar->unp_size) << 1;
+ new_window = realloc(rar->lzss.window, new_size);
+ if (new_window == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Unable to allocate memory for uncompressed data.");
+ return (ARCHIVE_FATAL);
+ }
+ rar->lzss.window = (unsigned char *)new_window;
+ rar->dictionary_size = new_size;
+ memset(rar->lzss.window, 0, rar->dictionary_size);
+ rar->lzss.mask = rar->dictionary_size - 1;
+ }
+
+ rar->start_new_table = 0;
+ return (ARCHIVE_OK);
+truncated_data:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated RAR file data");
+ rar->valid = 0;
+ return (ARCHIVE_FATAL);
+}
+
+static void
+free_codes(struct archive_read *a)
+{
+ struct rar *rar = (struct rar *)(a->format->data);
+ free(rar->maincode.tree);
+ free(rar->offsetcode.tree);
+ free(rar->lowoffsetcode.tree);
+ free(rar->lengthcode.tree);
+ free(rar->maincode.table);
+ free(rar->offsetcode.table);
+ free(rar->lowoffsetcode.table);
+ free(rar->lengthcode.table);
+ memset(&rar->maincode, 0, sizeof(rar->maincode));
+ memset(&rar->offsetcode, 0, sizeof(rar->offsetcode));
+ memset(&rar->lowoffsetcode, 0, sizeof(rar->lowoffsetcode));
+ memset(&rar->lengthcode, 0, sizeof(rar->lengthcode));
+}
+
+
+static int
+read_next_symbol(struct archive_read *a, struct huffman_code *code)
+{
+ unsigned char bit;
+ unsigned int bits;
+ int length, value, node;
+ struct rar *rar;
+ struct rar_br *br;
+
+ if (!code->table)
+ {
+ if (make_table(a, code) != (ARCHIVE_OK))
+ return -1;
+ }
+
+ rar = (struct rar *)(a->format->data);
+ br = &(rar->br);
+
+ /* Look ahead (peek) at bits */
+ if (!rar_br_read_ahead(a, br, code->tablesize)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated RAR file data");
+ rar->valid = 0;
+ return -1;
+ }
+ bits = rar_br_bits(br, code->tablesize);
+
+ length = code->table[bits].length;
+ value = code->table[bits].value;
+
+ if (length < 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid prefix code in bitstream");
+ return -1;
+ }
+
+ if (length <= code->tablesize)
+ {
+ /* Skip length bits */
+ rar_br_consume(br, length);
+ return value;
+ }
+
+ /* Skip tablesize bits */
+ rar_br_consume(br, code->tablesize);
+
+ node = value;
+ while (!(code->tree[node].branches[0] ==
+ code->tree[node].branches[1]))
+ {
+ if (!rar_br_read_ahead(a, br, 1)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated RAR file data");
+ rar->valid = 0;
+ return -1;
+ }
+ bit = rar_br_bits(br, 1);
+ rar_br_consume(br, 1);
+
+ if (code->tree[node].branches[bit] < 0)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid prefix code in bitstream");
+ return -1;
+ }
+ node = code->tree[node].branches[bit];
+ }
+
+ return code->tree[node].branches[0];
+}
+
+static int
+create_code(struct archive_read *a, struct huffman_code *code,
+ unsigned char *lengths, int numsymbols, char maxlength)
+{
+ int i, j, codebits = 0, symbolsleft = numsymbols;
+
+ if (new_node(code) < 0) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Unable to allocate memory for node data.");
+ return (ARCHIVE_FATAL);
+ }
+ code->numentries = 1;
+ code->minlength = INT_MAX;
+ code->maxlength = INT_MIN;
+ codebits = 0;
+ for(i = 1; i <= maxlength; i++)
+ {
+ for(j = 0; j < numsymbols; j++)
+ {
+ if (lengths[j] != i) continue;
+ if (add_value(a, code, j, codebits, i) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ codebits++;
+ if (--symbolsleft <= 0) { break; break; }
+ }
+ codebits <<= 1;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+add_value(struct archive_read *a, struct huffman_code *code, int value,
+ int codebits, int length)
+{
+ int repeatpos, lastnode, bitpos, bit, repeatnode, nextnode;
+
+ free(code->table);
+ code->table = NULL;
+
+ if(length > code->maxlength)
+ code->maxlength = length;
+ if(length < code->minlength)
+ code->minlength = length;
+
+ repeatpos = -1;
+ if (repeatpos == 0 || (repeatpos >= 0
+ && (((codebits >> (repeatpos - 1)) & 3) == 0
+ || ((codebits >> (repeatpos - 1)) & 3) == 3)))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid repeat position");
+ return (ARCHIVE_FATAL);
+ }
+
+ lastnode = 0;
+ for (bitpos = length - 1; bitpos >= 0; bitpos--)
+ {
+ bit = (codebits >> bitpos) & 1;
+
+ /* Leaf node check */
+ if (code->tree[lastnode].branches[0] ==
+ code->tree[lastnode].branches[1])
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Prefix found");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (bitpos == repeatpos)
+ {
+ /* Open branch check */
+ if (!(code->tree[lastnode].branches[bit] < 0))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid repeating code");
+ return (ARCHIVE_FATAL);
+ }
+
+ if ((repeatnode = new_node(code)) < 0) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Unable to allocate memory for node data.");
+ return (ARCHIVE_FATAL);
+ }
+ if ((nextnode = new_node(code)) < 0) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Unable to allocate memory for node data.");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Set branches */
+ code->tree[lastnode].branches[bit] = repeatnode;
+ code->tree[repeatnode].branches[bit] = repeatnode;
+ code->tree[repeatnode].branches[bit^1] = nextnode;
+ lastnode = nextnode;
+
+ bitpos++; /* terminating bit already handled, skip it */
+ }
+ else
+ {
+ /* Open branch check */
+ if (code->tree[lastnode].branches[bit] < 0)
+ {
+ if (new_node(code) < 0) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Unable to allocate memory for node data.");
+ return (ARCHIVE_FATAL);
+ }
+ code->tree[lastnode].branches[bit] = code->numentries++;
+ }
+
+ /* set to branch */
+ lastnode = code->tree[lastnode].branches[bit];
+ }
+ }
+
+ if (!(code->tree[lastnode].branches[0] == -1
+ && code->tree[lastnode].branches[1] == -2))
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Prefix found");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Set leaf value */
+ code->tree[lastnode].branches[0] = value;
+ code->tree[lastnode].branches[1] = value;
+
+ return (ARCHIVE_OK);
+}
+
+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;
+ code->tree[code->numentries].branches[0] = -1;
+ code->tree[code->numentries].branches[1] = -2;
+ return 1;
+}
+
+static int
+make_table(struct archive_read *a, struct huffman_code *code)
+{
+ if (code->maxlength < code->minlength || code->maxlength > 10)
+ code->tablesize = 10;
+ else
+ code->tablesize = code->maxlength;
+
+ code->table =
+ (struct huffman_table_entry *)calloc(1, sizeof(*code->table)
+ * ((size_t)1 << code->tablesize));
+
+ return make_table_recurse(a, code, 0, code->table, 0, code->tablesize);
+}
+
+static int
+make_table_recurse(struct archive_read *a, struct huffman_code *code, int node,
+ struct huffman_table_entry *table, int depth,
+ int maxdepth)
+{
+ int currtablesize, i, ret = (ARCHIVE_OK);
+
+ if (!code->tree)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Huffman tree was not created.");
+ return (ARCHIVE_FATAL);
+ }
+ if (node < 0 || node >= code->numentries)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid location to Huffman tree specified.");
+ return (ARCHIVE_FATAL);
+ }
+
+ currtablesize = 1 << (maxdepth - depth);
+
+ if (code->tree[node].branches[0] ==
+ code->tree[node].branches[1])
+ {
+ for(i = 0; i < currtablesize; i++)
+ {
+ table[i].length = depth;
+ table[i].value = code->tree[node].branches[0];
+ }
+ }
+ else if (node < 0)
+ {
+ for(i = 0; i < currtablesize; i++)
+ table[i].length = -1;
+ }
+ else
+ {
+ if(depth == maxdepth)
+ {
+ table[0].length = maxdepth + 1;
+ table[0].value = node;
+ }
+ else
+ {
+ ret |= make_table_recurse(a, code, code->tree[node].branches[0], table,
+ depth + 1, maxdepth);
+ ret |= make_table_recurse(a, code, code->tree[node].branches[1],
+ table + currtablesize / 2, depth + 1, maxdepth);
+ }
+ }
+ return ret;
+}
+
+static int64_t
+expand(struct archive_read *a, int64_t end)
+{
+ static const unsigned char lengthbases[] =
+ { 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 10, 12, 14, 16, 20,
+ 24, 28, 32, 40, 48, 56, 64,
+ 80, 96, 112, 128, 160, 192, 224 };
+ static const unsigned char lengthbits[] =
+ { 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 2, 2,
+ 2, 2, 3, 3, 3, 3, 4,
+ 4, 4, 4, 5, 5, 5, 5 };
+ static const unsigned int offsetbases[] =
+ { 0, 1, 2, 3, 4, 6,
+ 8, 12, 16, 24, 32, 48,
+ 64, 96, 128, 192, 256, 384,
+ 512, 768, 1024, 1536, 2048, 3072,
+ 4096, 6144, 8192, 12288, 16384, 24576,
+ 32768, 49152, 65536, 98304, 131072, 196608,
+ 262144, 327680, 393216, 458752, 524288, 589824,
+ 655360, 720896, 786432, 851968, 917504, 983040,
+ 1048576, 1310720, 1572864, 1835008, 2097152, 2359296,
+ 2621440, 2883584, 3145728, 3407872, 3670016, 3932160 };
+ static const unsigned char offsetbits[] =
+ { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4,
+ 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
+ 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 };
+ static const unsigned char shortbases[] =
+ { 0, 4, 8, 16, 32, 64, 128, 192 };
+ static const unsigned char shortbits[] =
+ { 2, 2, 3, 4, 5, 6, 6, 6 };
+
+ int symbol, offs, len, offsindex, lensymbol, i, offssymbol, lowoffsetsymbol;
+ unsigned char newfile;
+ struct rar *rar = (struct rar *)(a->format->data);
+ struct rar_br *br = &(rar->br);
+
+ if (rar->filterstart < end)
+ end = rar->filterstart;
+
+ while (1)
+ {
+ if (rar->output_last_match &&
+ lzss_position(&rar->lzss) + rar->lastlength <= end)
+ {
+ lzss_emit_match(rar, rar->lastoffset, rar->lastlength);
+ rar->output_last_match = 0;
+ }
+
+ if(rar->is_ppmd_block || rar->output_last_match ||
+ lzss_position(&rar->lzss) >= end)
+ return lzss_position(&rar->lzss);
+
+ if ((symbol = read_next_symbol(a, &rar->maincode)) < 0)
+ return (ARCHIVE_FATAL);
+ rar->output_last_match = 0;
+
+ if (symbol < 256)
+ {
+ lzss_emit_literal(rar, symbol);
+ continue;
+ }
+ else if (symbol == 256)
+ {
+ if (!rar_br_read_ahead(a, br, 1))
+ goto truncated_data;
+ newfile = !rar_br_bits(br, 1);
+ rar_br_consume(br, 1);
+
+ if(newfile)
+ {
+ rar->start_new_block = 1;
+ if (!rar_br_read_ahead(a, br, 1))
+ goto truncated_data;
+ rar->start_new_table = rar_br_bits(br, 1);
+ rar_br_consume(br, 1);
+ return lzss_position(&rar->lzss);
+ }
+ else
+ {
+ if (parse_codes(a) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ continue;
+ }
+ }
+ else if(symbol==257)
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Parsing filters is unsupported.");
+ return (ARCHIVE_FAILED);
+ }
+ else if(symbol==258)
+ {
+ if(rar->lastlength == 0)
+ continue;
+
+ offs = rar->lastoffset;
+ len = rar->lastlength;
+ }
+ else if (symbol <= 262)
+ {
+ offsindex = symbol - 259;
+ offs = rar->oldoffset[offsindex];
+
+ if ((lensymbol = read_next_symbol(a, &rar->lengthcode)) < 0)
+ goto bad_data;
+ if (lensymbol > (int)(sizeof(lengthbases)/sizeof(lengthbases[0])))
+ goto bad_data;
+ if (lensymbol > (int)(sizeof(lengthbits)/sizeof(lengthbits[0])))
+ goto bad_data;
+ len = lengthbases[lensymbol] + 2;
+ if (lengthbits[lensymbol] > 0) {
+ if (!rar_br_read_ahead(a, br, lengthbits[lensymbol]))
+ goto truncated_data;
+ len += rar_br_bits(br, lengthbits[lensymbol]);
+ rar_br_consume(br, lengthbits[lensymbol]);
+ }
+
+ for (i = offsindex; i > 0; i--)
+ rar->oldoffset[i] = rar->oldoffset[i-1];
+ rar->oldoffset[0] = offs;
+ }
+ else if(symbol<=270)
+ {
+ offs = shortbases[symbol-263] + 1;
+ if(shortbits[symbol-263] > 0) {
+ if (!rar_br_read_ahead(a, br, shortbits[symbol-263]))
+ goto truncated_data;
+ offs += rar_br_bits(br, shortbits[symbol-263]);
+ rar_br_consume(br, shortbits[symbol-263]);
+ }
+
+ len = 2;
+
+ for(i = 3; i > 0; i--)
+ rar->oldoffset[i] = rar->oldoffset[i-1];
+ rar->oldoffset[0] = offs;
+ }
+ else
+ {
+ if (symbol-271 > (int)(sizeof(lengthbases)/sizeof(lengthbases[0])))
+ goto bad_data;
+ if (symbol-271 > (int)(sizeof(lengthbits)/sizeof(lengthbits[0])))
+ goto bad_data;
+ len = lengthbases[symbol-271]+3;
+ if(lengthbits[symbol-271] > 0) {
+ if (!rar_br_read_ahead(a, br, lengthbits[symbol-271]))
+ goto truncated_data;
+ len += rar_br_bits(br, lengthbits[symbol-271]);
+ rar_br_consume(br, lengthbits[symbol-271]);
+ }
+
+ if ((offssymbol = read_next_symbol(a, &rar->offsetcode)) < 0)
+ goto bad_data;
+ if (offssymbol > (int)(sizeof(offsetbases)/sizeof(offsetbases[0])))
+ goto bad_data;
+ if (offssymbol > (int)(sizeof(offsetbits)/sizeof(offsetbits[0])))
+ goto bad_data;
+ offs = offsetbases[offssymbol]+1;
+ if(offsetbits[offssymbol] > 0)
+ {
+ if(offssymbol > 9)
+ {
+ if(offsetbits[offssymbol] > 4) {
+ if (!rar_br_read_ahead(a, br, offsetbits[offssymbol] - 4))
+ goto truncated_data;
+ offs += rar_br_bits(br, offsetbits[offssymbol] - 4) << 4;
+ rar_br_consume(br, offsetbits[offssymbol] - 4);
+ }
+
+ if(rar->numlowoffsetrepeats > 0)
+ {
+ rar->numlowoffsetrepeats--;
+ offs += rar->lastlowoffset;
+ }
+ else
+ {
+ if ((lowoffsetsymbol =
+ read_next_symbol(a, &rar->lowoffsetcode)) < 0)
+ return (ARCHIVE_FATAL);
+ if(lowoffsetsymbol == 16)
+ {
+ rar->numlowoffsetrepeats = 15;
+ offs += rar->lastlowoffset;
+ }
+ else
+ {
+ offs += lowoffsetsymbol;
+ rar->lastlowoffset = lowoffsetsymbol;
+ }
+ }
+ }
+ else {
+ if (!rar_br_read_ahead(a, br, offsetbits[offssymbol]))
+ goto truncated_data;
+ offs += rar_br_bits(br, offsetbits[offssymbol]);
+ rar_br_consume(br, offsetbits[offssymbol]);
+ }
+ }
+
+ if (offs >= 0x40000)
+ len++;
+ if (offs >= 0x2000)
+ len++;
+
+ for(i = 3; i > 0; i--)
+ rar->oldoffset[i] = rar->oldoffset[i-1];
+ rar->oldoffset[0] = offs;
+ }
+
+ rar->lastoffset = offs;
+ rar->lastlength = len;
+ rar->output_last_match = 1;
+ }
+truncated_data:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated RAR file data");
+ rar->valid = 0;
+ return (ARCHIVE_FATAL);
+bad_data:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Bad RAR file data");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+copy_from_lzss_window(struct archive_read *a, const void **buffer,
+ int64_t startpos, int length)
+{
+ int windowoffs, firstpart;
+ struct rar *rar = (struct rar *)(a->format->data);
+
+ if (!rar->unp_buffer)
+ {
+ if ((rar->unp_buffer = malloc(rar->unp_buffer_size)) == NULL)
+ {
+ archive_set_error(&a->archive, ENOMEM,
+ "Unable to allocate memory for uncompressed data.");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ windowoffs = lzss_offset_for_position(&rar->lzss, startpos);
+ if(windowoffs + length <= lzss_size(&rar->lzss))
+ memcpy(&rar->unp_buffer[rar->unp_offset], &rar->lzss.window[windowoffs],
+ length);
+ else
+ {
+ firstpart = lzss_size(&rar->lzss) - windowoffs;
+ if (firstpart < 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Bad RAR file data");
+ return (ARCHIVE_FATAL);
+ }
+ if (firstpart < length) {
+ memcpy(&rar->unp_buffer[rar->unp_offset],
+ &rar->lzss.window[windowoffs], firstpart);
+ memcpy(&rar->unp_buffer[rar->unp_offset + firstpart],
+ &rar->lzss.window[0], length - firstpart);
+ } else
+ memcpy(&rar->unp_buffer[rar->unp_offset],
+ &rar->lzss.window[windowoffs], length);
+ }
+ rar->unp_offset += length;
+ if (rar->unp_offset >= rar->unp_buffer_size)
+ *buffer = rar->unp_buffer;
+ else
+ *buffer = NULL;
+ return (ARCHIVE_OK);
+}
+
+static const void *
+rar_read_ahead(struct archive_read *a, size_t min, ssize_t *avail)
+{
+ struct rar *rar = (struct rar *)(a->format->data);
+ const void *h = __archive_read_ahead(a, min, 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 (*avail > rar->bytes_remaining)
+ *avail = (ssize_t)rar->bytes_remaining;
+ if (*avail < 0)
+ return NULL;
+ else if (*avail == 0 && rar->main_flags & MHD_VOLUME &&
+ rar->file_flags & FHD_SPLIT_AFTER)
+ {
+ ret = archive_read_format_rar_read_header(a, a->entry);
+ if (ret == (ARCHIVE_EOF))
+ {
+ rar->has_endarc_header = 1;
+ ret = archive_read_format_rar_read_header(a, a->entry);
+ }
+ if (ret != (ARCHIVE_OK))
+ return NULL;
+ return rar_read_ahead(a, min, avail);
+ }
+ }
+ return h;
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_raw.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_raw.c
new file mode 100644
index 0000000000..efa2c6a33c
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_raw.c
@@ -0,0 +1,190 @@
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * 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_read_support_format_raw.c 201107 2009-12-28 03:25:33Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+struct raw_info {
+ int64_t offset; /* Current position in the file. */
+ int64_t unconsumed;
+ int end_of_file;
+};
+
+static int archive_read_format_raw_bid(struct archive_read *, int);
+static int archive_read_format_raw_cleanup(struct archive_read *);
+static int archive_read_format_raw_read_data(struct archive_read *,
+ const void **, size_t *, int64_t *);
+static int archive_read_format_raw_read_data_skip(struct archive_read *);
+static int archive_read_format_raw_read_header(struct archive_read *,
+ struct archive_entry *);
+
+int
+archive_read_support_format_raw(struct archive *_a)
+{
+ struct raw_info *info;
+ struct archive_read *a = (struct archive_read *)_a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_raw");
+
+ info = (struct raw_info *)calloc(1, sizeof(*info));
+ if (info == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate raw_info data");
+ return (ARCHIVE_FATAL);
+ }
+
+ r = __archive_read_register_format(a,
+ info,
+ "raw",
+ archive_read_format_raw_bid,
+ NULL,
+ archive_read_format_raw_read_header,
+ archive_read_format_raw_read_data,
+ archive_read_format_raw_read_data_skip,
+ NULL,
+ archive_read_format_raw_cleanup,
+ NULL,
+ NULL);
+ if (r != ARCHIVE_OK)
+ free(info);
+ return (r);
+}
+
+/*
+ * Bid 1 if this is a non-empty file. Anyone who can really support
+ * this should outbid us, so it should generally be safe to use "raw"
+ * in conjunction with other formats. But, this could really confuse
+ * folks if there are bid errors or minor file damage, so we don't
+ * include "raw" as part of support_format_all().
+ */
+static int
+archive_read_format_raw_bid(struct archive_read *a, int best_bid)
+{
+ if (best_bid < 1 && __archive_read_ahead(a, 1, NULL) != NULL)
+ return (1);
+ return (-1);
+}
+
+/*
+ * Mock up a fake header.
+ */
+static int
+archive_read_format_raw_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ struct raw_info *info;
+
+ info = (struct raw_info *)(a->format->data);
+ if (info->end_of_file)
+ return (ARCHIVE_EOF);
+
+ a->archive.archive_format = ARCHIVE_FORMAT_RAW;
+ a->archive.archive_format_name = "raw";
+ archive_entry_set_pathname(entry, "data");
+ archive_entry_set_filetype(entry, AE_IFREG);
+ archive_entry_set_perm(entry, 0644);
+ /* I'm deliberately leaving most fields unset here. */
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_raw_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ struct raw_info *info;
+ ssize_t avail;
+
+ info = (struct raw_info *)(a->format->data);
+
+ /* Consume the bytes we read last time. */
+ if (info->unconsumed) {
+ __archive_read_consume(a, info->unconsumed);
+ info->unconsumed = 0;
+ }
+
+ if (info->end_of_file)
+ return (ARCHIVE_EOF);
+
+ /* Get whatever bytes are immediately available. */
+ *buff = __archive_read_ahead(a, 1, &avail);
+ if (avail > 0) {
+ /* Return the bytes we just read */
+ *size = avail;
+ *offset = info->offset;
+ info->offset += *size;
+ info->unconsumed = avail;
+ return (ARCHIVE_OK);
+ } else if (0 == avail) {
+ /* Record and return end-of-file. */
+ info->end_of_file = 1;
+ *size = 0;
+ *offset = info->offset;
+ return (ARCHIVE_EOF);
+ } else {
+ /* Record and return an error. */
+ *size = 0;
+ *offset = info->offset;
+ return ((int)avail);
+ }
+}
+
+static int
+archive_read_format_raw_read_data_skip(struct archive_read *a)
+{
+ struct raw_info *info = (struct raw_info *)(a->format->data);
+
+ /* Consume the bytes we read last time. */
+ if (info->unconsumed) {
+ __archive_read_consume(a, info->unconsumed);
+ info->unconsumed = 0;
+ }
+ info->end_of_file = 1;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_raw_cleanup(struct archive_read *a)
+{
+ struct raw_info *info;
+
+ info = (struct raw_info *)(a->format->data);
+ free(info);
+ a->format->data = NULL;
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c
new file mode 100644
index 0000000000..734424dd32
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c
@@ -0,0 +1,2752 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2011-2012 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: head/lib/libarchive/archive_read_support_format_tar.c 201161 2009-12-29 05:44:39Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <stddef.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_acl_private.h" /* For ACL parsing routines. */
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+#define tar_min(a,b) ((a) < (b) ? (a) : (b))
+
+/*
+ * Layout of POSIX 'ustar' tar header.
+ */
+struct archive_entry_header_ustar {
+ char name[100];
+ char mode[8];
+ char uid[8];
+ char gid[8];
+ char size[12];
+ char mtime[12];
+ char checksum[8];
+ char typeflag[1];
+ char linkname[100]; /* "old format" header ends here */
+ char magic[6]; /* For POSIX: "ustar\0" */
+ char version[2]; /* For POSIX: "00" */
+ char uname[32];
+ char gname[32];
+ char rdevmajor[8];
+ char rdevminor[8];
+ char prefix[155];
+};
+
+/*
+ * Structure of GNU tar header
+ */
+struct gnu_sparse {
+ char offset[12];
+ char numbytes[12];
+};
+
+struct archive_entry_header_gnutar {
+ char name[100];
+ char mode[8];
+ char uid[8];
+ char gid[8];
+ char size[12];
+ char mtime[12];
+ char checksum[8];
+ char typeflag[1];
+ char linkname[100];
+ char magic[8]; /* "ustar \0" (note blank/blank/null at end) */
+ char uname[32];
+ char gname[32];
+ char rdevmajor[8];
+ char rdevminor[8];
+ char atime[12];
+ char ctime[12];
+ char offset[12];
+ char longnames[4];
+ char unused[1];
+ struct gnu_sparse sparse[4];
+ char isextended[1];
+ char realsize[12];
+ /*
+ * Old GNU format doesn't use POSIX 'prefix' field; they use
+ * the 'L' (longname) entry instead.
+ */
+};
+
+/*
+ * Data specific to this format.
+ */
+struct sparse_block {
+ struct sparse_block *next;
+ int64_t offset;
+ int64_t remaining;
+ int hole;
+};
+
+struct tar {
+ struct archive_string acl_text;
+ struct archive_string entry_pathname;
+ /* For "GNU.sparse.name" and other similar path extensions. */
+ struct archive_string entry_pathname_override;
+ struct archive_string entry_linkpath;
+ struct archive_string entry_uname;
+ struct archive_string entry_gname;
+ struct archive_string longlink;
+ struct archive_string longname;
+ struct archive_string pax_header;
+ struct archive_string pax_global;
+ struct archive_string line;
+ int pax_hdrcharset_binary;
+ int header_recursion_depth;
+ int64_t entry_bytes_remaining;
+ int64_t entry_offset;
+ int64_t entry_padding;
+ int64_t entry_bytes_unconsumed;
+ int64_t realsize;
+ struct sparse_block *sparse_list;
+ struct sparse_block *sparse_last;
+ int64_t sparse_offset;
+ int64_t sparse_numbytes;
+ int sparse_gnu_major;
+ int sparse_gnu_minor;
+ char sparse_gnu_pending;
+
+ struct archive_string localname;
+ struct archive_string_conv *opt_sconv;
+ struct archive_string_conv *sconv;
+ struct archive_string_conv *sconv_acl;
+ struct archive_string_conv *sconv_default;
+ int init_default_conversion;
+ int compat_2x;
+ int process_mac_extensions;
+ int read_concatenated_archives;
+};
+
+static int archive_block_is_null(const char *p);
+static char *base64_decode(const char *, size_t, size_t *);
+static int gnu_add_sparse_entry(struct archive_read *, struct tar *,
+ int64_t offset, int64_t remaining);
+
+static void gnu_clear_sparse_list(struct tar *);
+static int gnu_sparse_old_read(struct archive_read *, struct tar *,
+ const struct archive_entry_header_gnutar *header, size_t *);
+static int gnu_sparse_old_parse(struct archive_read *, struct tar *,
+ const struct gnu_sparse *sparse, int length);
+static int gnu_sparse_01_parse(struct archive_read *, struct tar *,
+ const char *);
+static ssize_t gnu_sparse_10_read(struct archive_read *, struct tar *,
+ size_t *);
+static int header_Solaris_ACL(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *, size_t *);
+static int header_common(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *);
+static int header_old_tar(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *);
+static int header_pax_extensions(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *, size_t *);
+static int header_pax_global(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *h, size_t *);
+static int header_longlink(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *h, size_t *);
+static int header_longname(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *h, size_t *);
+static int read_mac_metadata_blob(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *h, size_t *);
+static int header_volume(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *h, size_t *);
+static int header_ustar(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *h);
+static int header_gnutar(struct archive_read *, struct tar *,
+ struct archive_entry *, const void *h, size_t *);
+static int archive_read_format_tar_bid(struct archive_read *, int);
+static int archive_read_format_tar_options(struct archive_read *,
+ const char *, const char *);
+static int archive_read_format_tar_cleanup(struct archive_read *);
+static int archive_read_format_tar_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset);
+static int archive_read_format_tar_skip(struct archive_read *a);
+static int archive_read_format_tar_read_header(struct archive_read *,
+ struct archive_entry *);
+static int checksum(struct archive_read *, const void *);
+static int pax_attribute(struct archive_read *, struct tar *,
+ struct archive_entry *, char *key, char *value);
+static int pax_header(struct archive_read *, struct tar *,
+ struct archive_entry *, char *attr);
+static void pax_time(const char *, int64_t *sec, long *nanos);
+static ssize_t readline(struct archive_read *, struct tar *, const char **,
+ ssize_t limit, size_t *);
+static int read_body_to_string(struct archive_read *, struct tar *,
+ struct archive_string *, const void *h, size_t *);
+static int solaris_sparse_parse(struct archive_read *, struct tar *,
+ struct archive_entry *, const char *);
+static int64_t tar_atol(const char *, size_t);
+static int64_t tar_atol10(const char *, size_t);
+static int64_t tar_atol256(const char *, size_t);
+static int64_t tar_atol8(const char *, size_t);
+static int tar_read_header(struct archive_read *, struct tar *,
+ struct archive_entry *, size_t *);
+static int tohex(int c);
+static char *url_decode(const char *);
+static void tar_flush_unconsumed(struct archive_read *, size_t *);
+
+
+int
+archive_read_support_format_gnutar(struct archive *a)
+{
+ archive_check_magic(a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_gnutar");
+ return (archive_read_support_format_tar(a));
+}
+
+
+int
+archive_read_support_format_tar(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct tar *tar;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_tar");
+
+ tar = (struct tar *)calloc(1, sizeof(*tar));
+#ifdef HAVE_COPYFILE_H
+ /* Set this by default on Mac OS. */
+ tar->process_mac_extensions = 1;
+#endif
+ if (tar == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate tar data");
+ return (ARCHIVE_FATAL);
+ }
+
+ r = __archive_read_register_format(a, tar, "tar",
+ archive_read_format_tar_bid,
+ archive_read_format_tar_options,
+ archive_read_format_tar_read_header,
+ archive_read_format_tar_read_data,
+ archive_read_format_tar_skip,
+ NULL,
+ archive_read_format_tar_cleanup,
+ NULL,
+ NULL);
+
+ if (r != ARCHIVE_OK)
+ free(tar);
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_tar_cleanup(struct archive_read *a)
+{
+ struct tar *tar;
+
+ tar = (struct tar *)(a->format->data);
+ gnu_clear_sparse_list(tar);
+ archive_string_free(&tar->acl_text);
+ archive_string_free(&tar->entry_pathname);
+ archive_string_free(&tar->entry_pathname_override);
+ archive_string_free(&tar->entry_linkpath);
+ archive_string_free(&tar->entry_uname);
+ archive_string_free(&tar->entry_gname);
+ archive_string_free(&tar->line);
+ archive_string_free(&tar->pax_global);
+ archive_string_free(&tar->pax_header);
+ archive_string_free(&tar->longname);
+ archive_string_free(&tar->longlink);
+ archive_string_free(&tar->localname);
+ free(tar);
+ (a->format->data) = NULL;
+ return (ARCHIVE_OK);
+}
+
+
+static int
+archive_read_format_tar_bid(struct archive_read *a, int best_bid)
+{
+ int bid;
+ const char *h;
+ const struct archive_entry_header_ustar *header;
+
+ (void)best_bid; /* UNUSED */
+
+ bid = 0;
+
+ /* Now let's look at the actual header and see if it matches. */
+ h = __archive_read_ahead(a, 512, NULL);
+ if (h == NULL)
+ return (-1);
+
+ /* If it's an end-of-archive mark, we can handle it. */
+ if (h[0] == 0 && archive_block_is_null(h)) {
+ /*
+ * Usually, I bid the number of bits verified, but
+ * in this case, 4096 seems excessive so I picked 10 as
+ * an arbitrary but reasonable-seeming value.
+ */
+ return (10);
+ }
+
+ /* If it's not an end-of-archive mark, it must have a valid checksum.*/
+ if (!checksum(a, h))
+ return (0);
+ bid += 48; /* Checksum is usually 6 octal digits. */
+
+ header = (const struct archive_entry_header_ustar *)h;
+
+ /* Recognize POSIX formats. */
+ if ((memcmp(header->magic, "ustar\0", 6) == 0)
+ && (memcmp(header->version, "00", 2) == 0))
+ bid += 56;
+
+ /* Recognize GNU tar format. */
+ if ((memcmp(header->magic, "ustar ", 6) == 0)
+ && (memcmp(header->version, " \0", 2) == 0))
+ bid += 56;
+
+ /* Type flag must be null, digit or A-Z, a-z. */
+ if (header->typeflag[0] != 0 &&
+ !( header->typeflag[0] >= '0' && header->typeflag[0] <= '9') &&
+ !( header->typeflag[0] >= 'A' && header->typeflag[0] <= 'Z') &&
+ !( header->typeflag[0] >= 'a' && header->typeflag[0] <= 'z') )
+ return (0);
+ bid += 2; /* 6 bits of variation in an 8-bit field leaves 2 bits. */
+
+ /* Sanity check: Look at first byte of mode field. */
+ switch (255 & (unsigned)header->mode[0]) {
+ case 0: case 255:
+ /* Base-256 value: No further verification possible! */
+ break;
+ case ' ': /* Not recommended, but not illegal, either. */
+ break;
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ /* Octal Value. */
+ /* TODO: Check format of remainder of this field. */
+ break;
+ default:
+ /* Not a valid mode; bail out here. */
+ return (0);
+ }
+ /* TODO: Sanity test uid/gid/size/mtime/rdevmajor/rdevminor fields. */
+
+ return (bid);
+}
+
+static int
+archive_read_format_tar_options(struct archive_read *a,
+ const char *key, const char *val)
+{
+ struct tar *tar;
+ int ret = ARCHIVE_FAILED;
+
+ tar = (struct tar *)(a->format->data);
+ if (strcmp(key, "compat-2x") == 0) {
+ /* Handle UTF-8 filnames as libarchive 2.x */
+ tar->compat_2x = (val != NULL && val[0] != 0);
+ tar->init_default_conversion = tar->compat_2x;
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "tar: hdrcharset option needs a character-set name");
+ else {
+ tar->opt_sconv =
+ archive_string_conversion_from_charset(
+ &a->archive, val, 0);
+ if (tar->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ } else if (strcmp(key, "mac-ext") == 0) {
+ tar->process_mac_extensions = (val != NULL && val[0] != 0);
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "read_concatenated_archives") == 0) {
+ tar->read_concatenated_archives = (val != NULL && val[0] != 0);
+ 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);
+}
+
+/* utility function- this exists to centralize the logic of tracking
+ * how much unconsumed data we have floating around, and to consume
+ * anything outstanding since we're going to do read_aheads
+ */
+static void
+tar_flush_unconsumed(struct archive_read *a, size_t *unconsumed)
+{
+ if (*unconsumed) {
+/*
+ void *data = (void *)__archive_read_ahead(a, *unconsumed, NULL);
+ * this block of code is to poison claimed unconsumed space, ensuring
+ * things break if it is in use still.
+ * currently it WILL break things, so enable it only for debugging this issue
+ if (data) {
+ memset(data, 0xff, *unconsumed);
+ }
+*/
+ __archive_read_consume(a, *unconsumed);
+ *unconsumed = 0;
+ }
+}
+
+/*
+ * The function invoked by archive_read_next_header(). This
+ * just sets up a few things and then calls the internal
+ * tar_read_header() function below.
+ */
+static int
+archive_read_format_tar_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ /*
+ * When converting tar archives to cpio archives, it is
+ * essential that each distinct file have a distinct inode
+ * number. To simplify this, we keep a static count here to
+ * assign fake dev/inode numbers to each tar entry. Note that
+ * pax format archives may overwrite this with something more
+ * useful.
+ *
+ * Ideally, we would track every file read from the archive so
+ * that we could assign the same dev/ino pair to hardlinks,
+ * but the memory required to store a complete lookup table is
+ * probably not worthwhile just to support the relatively
+ * obscure tar->cpio conversion case.
+ */
+ static int default_inode;
+ static int default_dev;
+ struct tar *tar;
+ const char *p;
+ int r;
+ size_t l, unconsumed = 0;
+
+ /* Assign default device/inode values. */
+ archive_entry_set_dev(entry, 1 + default_dev); /* Don't use zero. */
+ archive_entry_set_ino(entry, ++default_inode); /* Don't use zero. */
+ /* Limit generated st_ino number to 16 bits. */
+ if (default_inode >= 0xffff) {
+ ++default_dev;
+ default_inode = 0;
+ }
+
+ tar = (struct tar *)(a->format->data);
+ tar->entry_offset = 0;
+ gnu_clear_sparse_list(tar);
+ tar->realsize = -1; /* Mark this as "unset" */
+
+ /* Setup default string conversion. */
+ tar->sconv = tar->opt_sconv;
+ if (tar->sconv == NULL) {
+ if (!tar->init_default_conversion) {
+ tar->sconv_default =
+ archive_string_default_conversion_for_read(&(a->archive));
+ tar->init_default_conversion = 1;
+ }
+ tar->sconv = tar->sconv_default;
+ }
+
+ r = tar_read_header(a, tar, entry, &unconsumed);
+
+ tar_flush_unconsumed(a, &unconsumed);
+
+ /*
+ * "non-sparse" files are really just sparse files with
+ * a single block.
+ */
+ if (tar->sparse_list == NULL) {
+ if (gnu_add_sparse_entry(a, tar, 0, tar->entry_bytes_remaining)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } else {
+ struct sparse_block *sb;
+
+ for (sb = tar->sparse_list; sb != NULL; sb = sb->next) {
+ if (!sb->hole)
+ archive_entry_sparse_add_entry(entry,
+ sb->offset, sb->remaining);
+ }
+ }
+
+ if (r == ARCHIVE_OK) {
+ /*
+ * "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) {
+ l = wcslen(wp);
+ if (archive_entry_filetype(entry) == AE_IFREG
+ && wp[l-1] == L'/')
+ archive_entry_set_filetype(entry, AE_IFDIR);
+ } else {
+ p = archive_entry_pathname(entry);
+ if (p == NULL)
+ return (ARCHIVE_FAILED);
+ l = strlen(p);
+ if (archive_entry_filetype(entry) == AE_IFREG
+ && p[l-1] == '/')
+ archive_entry_set_filetype(entry, AE_IFDIR);
+ }
+ }
+ return (r);
+}
+
+static int
+archive_read_format_tar_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ ssize_t bytes_read;
+ struct tar *tar;
+ struct sparse_block *p;
+
+ tar = (struct tar *)(a->format->data);
+
+ for (;;) {
+ /* Remove exhausted entries from sparse list. */
+ while (tar->sparse_list != NULL &&
+ tar->sparse_list->remaining == 0) {
+ p = tar->sparse_list;
+ tar->sparse_list = p->next;
+ free(p);
+ }
+
+ if (tar->entry_bytes_unconsumed) {
+ __archive_read_consume(a, tar->entry_bytes_unconsumed);
+ tar->entry_bytes_unconsumed = 0;
+ }
+
+ /* If we're at end of file, return EOF. */
+ if (tar->sparse_list == NULL ||
+ tar->entry_bytes_remaining == 0) {
+ if (__archive_read_consume(a, tar->entry_padding) < 0)
+ return (ARCHIVE_FATAL);
+ tar->entry_padding = 0;
+ *buff = NULL;
+ *size = 0;
+ *offset = tar->realsize;
+ return (ARCHIVE_EOF);
+ }
+
+ *buff = __archive_read_ahead(a, 1, &bytes_read);
+ if (bytes_read < 0)
+ return (ARCHIVE_FATAL);
+ if (*buff == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Truncated tar archive");
+ return (ARCHIVE_FATAL);
+ }
+ if (bytes_read > tar->entry_bytes_remaining)
+ bytes_read = (ssize_t)tar->entry_bytes_remaining;
+ /* Don't read more than is available in the
+ * current sparse block. */
+ if (tar->sparse_list->remaining < bytes_read)
+ bytes_read = (ssize_t)tar->sparse_list->remaining;
+ *size = bytes_read;
+ *offset = tar->sparse_list->offset;
+ tar->sparse_list->remaining -= bytes_read;
+ tar->sparse_list->offset += bytes_read;
+ tar->entry_bytes_remaining -= bytes_read;
+ tar->entry_bytes_unconsumed = bytes_read;
+
+ if (!tar->sparse_list->hole)
+ return (ARCHIVE_OK);
+ /* Current is hole data and skip this. */
+ }
+}
+
+static int
+archive_read_format_tar_skip(struct archive_read *a)
+{
+ int64_t bytes_skipped;
+ 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);
+ if (bytes_skipped < 0)
+ return (ARCHIVE_FATAL);
+
+ tar->entry_bytes_remaining = 0;
+ tar->entry_bytes_unconsumed = 0;
+ tar->entry_padding = 0;
+
+ /* Free the sparse list. */
+ gnu_clear_sparse_list(tar);
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * This function recursively interprets all of the headers associated
+ * with a single entry.
+ */
+static int
+tar_read_header(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, size_t *unconsumed)
+{
+ ssize_t bytes;
+ int err;
+ const char *h;
+ const struct archive_entry_header_ustar *header;
+ const struct archive_entry_header_gnutar *gnuheader;
+
+ /* Loop until we find a workable header record. */
+ for (;;) {
+ tar_flush_unconsumed(a, unconsumed);
+
+ /* Read 512-byte header record */
+ h = __archive_read_ahead(a, 512, &bytes);
+ if (bytes < 0)
+ return ((int)bytes);
+ if (bytes == 0) { /* EOF at a block boundary. */
+ /* Some writers do omit the block of nulls. <sigh> */
+ return (ARCHIVE_EOF);
+ }
+ if (bytes < 512) { /* Short block at EOF; this is bad. */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated tar archive");
+ return (ARCHIVE_FATAL);
+ }
+ *unconsumed = 512;
+
+ /* Header is workable if it's not an end-of-archive mark. */
+ if (h[0] != 0 || !archive_block_is_null(h))
+ break;
+
+ /* Ensure format is set for archives with only null blocks. */
+ if (a->archive.archive_format_name == NULL) {
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR;
+ a->archive.archive_format_name = "tar";
+ }
+
+ if (!tar->read_concatenated_archives) {
+ /* Try to consume a second all-null record, as well. */
+ tar_flush_unconsumed(a, unconsumed);
+ h = __archive_read_ahead(a, 512, NULL);
+ if (h != NULL && h[0] == 0 && archive_block_is_null(h))
+ __archive_read_consume(a, 512);
+ archive_clear_error(&a->archive);
+ return (ARCHIVE_EOF);
+ }
+
+ /*
+ * We're reading concatenated archives, ignore this block and
+ * loop to get the next.
+ */
+ }
+
+ /*
+ * Note: If the checksum fails and we return ARCHIVE_RETRY,
+ * then the client is likely to just retry. This is a very
+ * crude way to search for the next valid header!
+ *
+ * TODO: Improve this by implementing a real header scan.
+ */
+ if (!checksum(a, h)) {
+ tar_flush_unconsumed(a, unconsumed);
+ archive_set_error(&a->archive, EINVAL, "Damaged tar archive");
+ return (ARCHIVE_RETRY); /* Retryable: Invalid header */
+ }
+
+ if (++tar->header_recursion_depth > 32) {
+ tar_flush_unconsumed(a, unconsumed);
+ archive_set_error(&a->archive, EINVAL, "Too many special headers");
+ return (ARCHIVE_WARN);
+ }
+
+ /* Determine the format variant. */
+ header = (const struct archive_entry_header_ustar *)h;
+
+ switch(header->typeflag[0]) {
+ case 'A': /* Solaris tar ACL */
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE;
+ a->archive.archive_format_name = "Solaris tar";
+ err = header_Solaris_ACL(a, tar, entry, h, unconsumed);
+ break;
+ case 'g': /* POSIX-standard 'g' header. */
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE;
+ a->archive.archive_format_name = "POSIX pax interchange format";
+ err = header_pax_global(a, tar, entry, h, unconsumed);
+ if (err == ARCHIVE_EOF)
+ return (err);
+ break;
+ case 'K': /* Long link name (GNU tar, others) */
+ err = header_longlink(a, tar, entry, h, unconsumed);
+ break;
+ case 'L': /* Long filename (GNU tar, others) */
+ err = header_longname(a, tar, entry, h, unconsumed);
+ break;
+ case 'V': /* GNU volume header */
+ err = header_volume(a, tar, entry, h, unconsumed);
+ break;
+ case 'X': /* Used by SUN tar; same as 'x'. */
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE;
+ a->archive.archive_format_name =
+ "POSIX pax interchange format (Sun variant)";
+ err = header_pax_extensions(a, tar, entry, h, unconsumed);
+ break;
+ case 'x': /* POSIX-standard 'x' header. */
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE;
+ a->archive.archive_format_name = "POSIX pax interchange format";
+ err = header_pax_extensions(a, tar, entry, h, unconsumed);
+ break;
+ default:
+ gnuheader = (const struct archive_entry_header_gnutar *)h;
+ if (memcmp(gnuheader->magic, "ustar \0", 8) == 0) {
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_GNUTAR;
+ a->archive.archive_format_name = "GNU tar format";
+ err = header_gnutar(a, tar, entry, h, unconsumed);
+ } else if (memcmp(header->magic, "ustar", 5) == 0) {
+ if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE) {
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_USTAR;
+ a->archive.archive_format_name = "POSIX ustar format";
+ }
+ err = header_ustar(a, tar, entry, h);
+ } else {
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR;
+ a->archive.archive_format_name = "tar (non-POSIX)";
+ err = header_old_tar(a, tar, entry, h);
+ }
+ }
+ if (err == ARCHIVE_FATAL)
+ return (err);
+
+ tar_flush_unconsumed(a, unconsumed);
+
+ h = NULL;
+ header = NULL;
+
+ --tar->header_recursion_depth;
+ /* Yuck. Apple's design here ends up storing long pathname
+ * extensions for both the AppleDouble extension entry and the
+ * regular entry.
+ */
+ if ((err == ARCHIVE_WARN || err == ARCHIVE_OK) &&
+ tar->header_recursion_depth == 0 &&
+ tar->process_mac_extensions) {
+ int err2 = read_mac_metadata_blob(a, tar, entry, h, unconsumed);
+ if (err2 < err)
+ err = err2;
+ }
+
+ /* We return warnings or success as-is. Anything else is fatal. */
+ if (err == ARCHIVE_WARN || err == ARCHIVE_OK) {
+ if (tar->sparse_gnu_pending) {
+ if (tar->sparse_gnu_major == 1 &&
+ tar->sparse_gnu_minor == 0) {
+ ssize_t bytes_read;
+
+ tar->sparse_gnu_pending = 0;
+ /* Read initial sparse map. */
+ bytes_read = gnu_sparse_10_read(a, tar, unconsumed);
+ tar->entry_bytes_remaining -= bytes_read;
+ if (bytes_read < 0)
+ return ((int)bytes_read);
+ } else {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Unrecognized GNU sparse file format");
+ return (ARCHIVE_WARN);
+ }
+ tar->sparse_gnu_pending = 0;
+ }
+ return (err);
+ }
+ if (err == ARCHIVE_EOF)
+ /* EOF when recursively reading a header is bad. */
+ archive_set_error(&a->archive, EINVAL, "Damaged tar archive");
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Return true if block checksum is correct.
+ */
+static int
+checksum(struct archive_read *a, const void *h)
+{
+ const unsigned char *bytes;
+ const struct archive_entry_header_ustar *header;
+ int check, sum;
+ size_t i;
+
+ (void)a; /* UNUSED */
+ bytes = (const unsigned char *)h;
+ header = (const struct archive_entry_header_ustar *)h;
+
+ /* Checksum field must hold an octal number */
+ for (i = 0; i < sizeof(header->checksum); ++i) {
+ char c = header->checksum[i];
+ if (c != ' ' && c != '\0' && (c < '0' || c > '7'))
+ return 0;
+ }
+
+ /*
+ * Test the checksum. Note that POSIX specifies _unsigned_
+ * bytes for this calculation.
+ */
+ sum = (int)tar_atol(header->checksum, sizeof(header->checksum));
+ check = 0;
+ for (i = 0; i < 148; i++)
+ check += (unsigned char)bytes[i];
+ for (; i < 156; i++)
+ check += 32;
+ for (; i < 512; i++)
+ check += (unsigned char)bytes[i];
+ if (sum == check)
+ return (1);
+
+ /*
+ * Repeat test with _signed_ bytes, just in case this archive
+ * was created by an old BSD, Solaris, or HP-UX tar with a
+ * broken checksum calculation.
+ */
+ check = 0;
+ for (i = 0; i < 148; i++)
+ check += (signed char)bytes[i];
+ for (; i < 156; i++)
+ check += 32;
+ for (; i < 512; i++)
+ check += (signed char)bytes[i];
+ if (sum == check)
+ return (1);
+
+ return (0);
+}
+
+/*
+ * Return true if this block contains only nulls.
+ */
+static int
+archive_block_is_null(const char *p)
+{
+ unsigned i;
+
+ for (i = 0; i < 512; i++)
+ if (*p++)
+ return (0);
+ return (1);
+}
+
+/*
+ * Interpret 'A' Solaris ACL header
+ */
+static int
+header_Solaris_ACL(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h, size_t *unconsumed)
+{
+ const struct archive_entry_header_ustar *header;
+ size_t size;
+ int err;
+ int64_t type;
+ char *acl, *p;
+
+ /*
+ * read_body_to_string adds a NUL terminator, but we need a little
+ * more to make sure that we don't overrun acl_text later.
+ */
+ header = (const struct archive_entry_header_ustar *)h;
+ size = (size_t)tar_atol(header->size, sizeof(header->size));
+ err = read_body_to_string(a, tar, &(tar->acl_text), h, unconsumed);
+ if (err != ARCHIVE_OK)
+ return (err);
+
+ /* Recursively read next header */
+ err = tar_read_header(a, tar, entry, unconsumed);
+ if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN))
+ return (err);
+
+ /* TODO: Examine the first characters to see if this
+ * is an AIX ACL descriptor. We'll likely never support
+ * them, but it would be polite to recognize and warn when
+ * we do see them. */
+
+ /* Leading octal number indicates ACL type and number of entries. */
+ p = acl = tar->acl_text.s;
+ type = 0;
+ while (*p != '\0' && p < acl + size) {
+ if (*p < '0' || *p > '7') {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Malformed Solaris ACL attribute (invalid digit)");
+ return(ARCHIVE_WARN);
+ }
+ type <<= 3;
+ type += *p - '0';
+ if (type > 077777777) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Malformed Solaris ACL attribute (count too large)");
+ return (ARCHIVE_WARN);
+ }
+ p++;
+ }
+ switch ((int)type & ~0777777) {
+ case 01000000:
+ /* POSIX.1e ACL */
+ break;
+ case 03000000:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Solaris NFSv4 ACLs not supported");
+ return (ARCHIVE_WARN);
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Malformed Solaris ACL attribute (unsupported type %o)",
+ (int)type);
+ return (ARCHIVE_WARN);
+ }
+ p++;
+
+ if (p >= acl + size) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Malformed Solaris ACL attribute (body overflow)");
+ return(ARCHIVE_WARN);
+ }
+
+ /* ACL text is null-terminated; find the end. */
+ size -= (p - acl);
+ acl = p;
+
+ while (*p != '\0' && p < acl + size)
+ p++;
+
+ if (tar->sconv_acl == NULL) {
+ tar->sconv_acl = archive_string_conversion_from_charset(
+ &(a->archive), "UTF-8", 1);
+ if (tar->sconv_acl == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ archive_strncpy(&(tar->localname), acl, p - acl);
+ err = archive_acl_parse_l(archive_entry_acl(entry),
+ tar->localname.s, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, tar->sconv_acl);
+ if (err != ARCHIVE_OK) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for ACL");
+ } else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Malformed Solaris ACL attribute (unparsable)");
+ }
+ return (err);
+}
+
+/*
+ * Interpret 'K' long linkname header.
+ */
+static int
+header_longlink(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h, size_t *unconsumed)
+{
+ int err;
+
+ err = read_body_to_string(a, tar, &(tar->longlink), h, unconsumed);
+ if (err != ARCHIVE_OK)
+ return (err);
+ err = tar_read_header(a, tar, entry, unconsumed);
+ if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN))
+ return (err);
+ /* Set symlink if symlink already set, else hardlink. */
+ archive_entry_copy_link(entry, tar->longlink.s);
+ return (ARCHIVE_OK);
+}
+
+static int
+set_conversion_failed_error(struct archive_read *a,
+ struct archive_string_conv *sconv, const char *name)
+{
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for %s", name);
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "%s can't be converted from %s to current locale.",
+ name, archive_string_conversion_charset_name(sconv));
+ return (ARCHIVE_WARN);
+}
+
+/*
+ * Interpret 'L' long filename header.
+ */
+static int
+header_longname(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h, size_t *unconsumed)
+{
+ int err;
+
+ err = read_body_to_string(a, tar, &(tar->longname), h, unconsumed);
+ if (err != ARCHIVE_OK)
+ return (err);
+ /* Read and parse "real" header, then override name. */
+ err = tar_read_header(a, tar, entry, unconsumed);
+ if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN))
+ return (err);
+ if (archive_entry_copy_pathname_l(entry, tar->longname.s,
+ archive_strlen(&(tar->longname)), tar->sconv) != 0)
+ err = set_conversion_failed_error(a, tar->sconv, "Pathname");
+ return (err);
+}
+
+
+/*
+ * Interpret 'V' GNU tar volume header.
+ */
+static int
+header_volume(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h, size_t *unconsumed)
+{
+ (void)h;
+
+ /* Just skip this and read the next header. */
+ return (tar_read_header(a, tar, entry, unconsumed));
+}
+
+/*
+ * Read body of an archive entry into an archive_string object.
+ */
+static int
+read_body_to_string(struct archive_read *a, struct tar *tar,
+ struct archive_string *as, const void *h, size_t *unconsumed)
+{
+ int64_t size;
+ const struct archive_entry_header_ustar *header;
+ const void *src;
+
+ (void)tar; /* UNUSED */
+ header = (const struct archive_entry_header_ustar *)h;
+ size = tar_atol(header->size, sizeof(header->size));
+ if ((size > 1048576) || (size < 0)) {
+ archive_set_error(&a->archive, EINVAL,
+ "Special header too large");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Fail if we can't make our buffer big enough. */
+ if (archive_string_ensure(as, (size_t)size+1) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ tar_flush_unconsumed(a, unconsumed);
+
+ /* Read the body into the string. */
+ *unconsumed = (size_t)((size + 511) & ~ 511);
+ src = __archive_read_ahead(a, *unconsumed, NULL);
+ if (src == NULL) {
+ *unconsumed = 0;
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(as->s, src, (size_t)size);
+ as->s[size] = '\0';
+ as->length = (size_t)size;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Parse out common header elements.
+ *
+ * This would be the same as header_old_tar, except that the
+ * filename is handled slightly differently for old and POSIX
+ * entries (POSIX entries support a 'prefix'). This factoring
+ * allows header_old_tar and header_ustar
+ * to handle filenames differently, while still putting most of the
+ * common parsing into one place.
+ */
+static int
+header_common(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h)
+{
+ const struct archive_entry_header_ustar *header;
+ char tartype;
+ int err = ARCHIVE_OK;
+
+ header = (const struct archive_entry_header_ustar *)h;
+ if (header->linkname[0])
+ archive_strncpy(&(tar->entry_linkpath),
+ header->linkname, sizeof(header->linkname));
+ else
+ archive_string_empty(&(tar->entry_linkpath));
+
+ /* Parse out the numeric fields (all are octal) */
+ archive_entry_set_mode(entry,
+ (mode_t)tar_atol(header->mode, sizeof(header->mode)));
+ archive_entry_set_uid(entry, tar_atol(header->uid, sizeof(header->uid)));
+ archive_entry_set_gid(entry, tar_atol(header->gid, sizeof(header->gid)));
+ tar->entry_bytes_remaining = tar_atol(header->size, sizeof(header->size));
+ if (tar->entry_bytes_remaining < 0) {
+ tar->entry_bytes_remaining = 0;
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Tar entry has negative size?");
+ err = ARCHIVE_WARN;
+ }
+ tar->realsize = tar->entry_bytes_remaining;
+ archive_entry_set_size(entry, tar->entry_bytes_remaining);
+ archive_entry_set_mtime(entry, tar_atol(header->mtime, sizeof(header->mtime)), 0);
+
+ /* Handle the tar type flag appropriately. */
+ tartype = header->typeflag[0];
+
+ switch (tartype) {
+ case '1': /* Hard link */
+ if (archive_entry_copy_hardlink_l(entry, tar->entry_linkpath.s,
+ archive_strlen(&(tar->entry_linkpath)), tar->sconv) != 0) {
+ err = set_conversion_failed_error(a, tar->sconv,
+ "Linkname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ }
+ /*
+ * The following may seem odd, but: Technically, tar
+ * does not store the file type for a "hard link"
+ * entry, only the fact that it is a hard link. So, I
+ * leave the type zero normally. But, pax interchange
+ * format allows hard links to have data, which
+ * implies that the underlying entry is a regular
+ * file.
+ */
+ if (archive_entry_size(entry) > 0)
+ archive_entry_set_filetype(entry, AE_IFREG);
+
+ /*
+ * A tricky point: Traditionally, tar readers have
+ * ignored the size field when reading hardlink
+ * entries, and some writers put non-zero sizes even
+ * though the body is empty. POSIX blessed this
+ * convention in the 1988 standard, but broke with
+ * this tradition in 2001 by permitting hardlink
+ * entries to store valid bodies in pax interchange
+ * format, but not in ustar format. Since there is no
+ * hard and fast way to distinguish pax interchange
+ * from earlier archives (the 'x' and 'g' entries are
+ * optional, after all), we need a heuristic.
+ */
+ if (archive_entry_size(entry) == 0) {
+ /* If the size is already zero, we're done. */
+ } else if (a->archive.archive_format
+ == ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE) {
+ /* Definitely pax extended; must obey hardlink size. */
+ } else if (a->archive.archive_format == ARCHIVE_FORMAT_TAR
+ || a->archive.archive_format == ARCHIVE_FORMAT_TAR_GNUTAR)
+ {
+ /* Old-style or GNU tar: we must ignore the size. */
+ archive_entry_set_size(entry, 0);
+ tar->entry_bytes_remaining = 0;
+ } else if (archive_read_format_tar_bid(a, 50) > 50) {
+ /*
+ * We don't know if it's pax: If the bid
+ * function sees a valid ustar header
+ * immediately following, then let's ignore
+ * the hardlink size.
+ */
+ archive_entry_set_size(entry, 0);
+ tar->entry_bytes_remaining = 0;
+ }
+ /*
+ * TODO: There are still two cases I'd like to handle:
+ * = a ustar non-pax archive with a hardlink entry at
+ * end-of-archive. (Look for block of nulls following?)
+ * = a pax archive that has not seen any pax headers
+ * and has an entry which is a hardlink entry storing
+ * a body containing an uncompressed tar archive.
+ * The first is worth addressing; I don't see any reliable
+ * way to deal with the second possibility.
+ */
+ break;
+ case '2': /* Symlink */
+ archive_entry_set_filetype(entry, AE_IFLNK);
+ archive_entry_set_size(entry, 0);
+ tar->entry_bytes_remaining = 0;
+ if (archive_entry_copy_symlink_l(entry, tar->entry_linkpath.s,
+ archive_strlen(&(tar->entry_linkpath)), tar->sconv) != 0) {
+ err = set_conversion_failed_error(a, tar->sconv,
+ "Linkname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ }
+ break;
+ case '3': /* Character device */
+ archive_entry_set_filetype(entry, AE_IFCHR);
+ archive_entry_set_size(entry, 0);
+ tar->entry_bytes_remaining = 0;
+ break;
+ case '4': /* Block device */
+ archive_entry_set_filetype(entry, AE_IFBLK);
+ archive_entry_set_size(entry, 0);
+ tar->entry_bytes_remaining = 0;
+ break;
+ case '5': /* Dir */
+ archive_entry_set_filetype(entry, AE_IFDIR);
+ archive_entry_set_size(entry, 0);
+ tar->entry_bytes_remaining = 0;
+ break;
+ case '6': /* FIFO device */
+ archive_entry_set_filetype(entry, AE_IFIFO);
+ archive_entry_set_size(entry, 0);
+ tar->entry_bytes_remaining = 0;
+ break;
+ case 'D': /* GNU incremental directory type */
+ /*
+ * No special handling is actually required here.
+ * It might be nice someday to preprocess the file list and
+ * provide it to the client, though.
+ */
+ archive_entry_set_filetype(entry, AE_IFDIR);
+ break;
+ case 'M': /* GNU "Multi-volume" (remainder of file from last archive)*/
+ /*
+ * As far as I can tell, this is just like a regular file
+ * entry, except that the contents should be _appended_ to
+ * the indicated file at the indicated offset. This may
+ * require some API work to fully support.
+ */
+ break;
+ case 'N': /* Old GNU "long filename" entry. */
+ /* The body of this entry is a script for renaming
+ * previously-extracted entries. Ugh. It will never
+ * be supported by libarchive. */
+ archive_entry_set_filetype(entry, AE_IFREG);
+ break;
+ case 'S': /* GNU sparse files */
+ /*
+ * Sparse files are really just regular files with
+ * sparse information in the extended area.
+ */
+ /* FALLTHROUGH */
+ default: /* Regular file and non-standard types */
+ /*
+ * Per POSIX: non-recognized types should always be
+ * treated as regular files.
+ */
+ archive_entry_set_filetype(entry, AE_IFREG);
+ break;
+ }
+ return (err);
+}
+
+/*
+ * Parse out header elements for "old-style" tar archives.
+ */
+static int
+header_old_tar(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h)
+{
+ const struct archive_entry_header_ustar *header;
+ int err = ARCHIVE_OK, err2;
+
+ /* Copy filename over (to ensure null termination). */
+ header = (const struct archive_entry_header_ustar *)h;
+ if (archive_entry_copy_pathname_l(entry,
+ header->name, sizeof(header->name), tar->sconv) != 0) {
+ err = set_conversion_failed_error(a, tar->sconv, "Pathname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ }
+
+ /* Grab rest of common fields */
+ err2 = header_common(a, tar, entry, h);
+ if (err > err2)
+ err = err2;
+
+ tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
+ return (err);
+}
+
+/*
+ * Read a Mac AppleDouble-encoded blob of file metadata,
+ * if there is one.
+ */
+static int
+read_mac_metadata_blob(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h, size_t *unconsumed)
+{
+ int64_t size;
+ const void *data;
+ const char *p, *name;
+ const wchar_t *wp, *wname;
+
+ (void)h; /* UNUSED */
+
+ wname = wp = archive_entry_pathname_w(entry);
+ if (wp != NULL) {
+ /* Find the last path element. */
+ for (; *wp != L'\0'; ++wp) {
+ if (wp[0] == '/' && wp[1] != L'\0')
+ wname = wp + 1;
+ }
+ /*
+ * If last path element starts with "._", then
+ * this is a Mac extension.
+ */
+ if (wname[0] != L'.' || wname[1] != L'_' || wname[2] == L'\0')
+ return ARCHIVE_OK;
+ } else {
+ /* Find the last path element. */
+ name = p = archive_entry_pathname(entry);
+ if (p == NULL)
+ return (ARCHIVE_FAILED);
+ for (; *p != '\0'; ++p) {
+ if (p[0] == '/' && p[1] != '\0')
+ name = p + 1;
+ }
+ /*
+ * If last path element starts with "._", then
+ * this is a Mac extension.
+ */
+ if (name[0] != '.' || name[1] != '_' || name[2] == '\0')
+ return ARCHIVE_OK;
+ }
+
+ /* Read the body as a Mac OS metadata blob. */
+ size = archive_entry_size(entry);
+
+ /*
+ * TODO: Look beyond the body here to peek at the next header.
+ * If it's a regular header (not an extension header)
+ * that has the wrong name, just return the current
+ * entry as-is, without consuming the body here.
+ * That would reduce the risk of us mis-identifying
+ * an ordinary file that just happened to have
+ * a name starting with "._".
+ *
+ * Q: Is the above idea really possible? Even
+ * when there are GNU or pax extension entries?
+ */
+ data = __archive_read_ahead(a, (size_t)size, NULL);
+ if (data == NULL) {
+ *unconsumed = 0;
+ return (ARCHIVE_FATAL);
+ }
+ archive_entry_copy_mac_metadata(entry, data, (size_t)size);
+ *unconsumed = (size_t)((size + 511) & ~ 511);
+ tar_flush_unconsumed(a, unconsumed);
+ return (tar_read_header(a, tar, entry, unconsumed));
+}
+
+/*
+ * Parse a file header for a pax extended archive entry.
+ */
+static int
+header_pax_global(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h, size_t *unconsumed)
+{
+ int err;
+
+ err = read_body_to_string(a, tar, &(tar->pax_global), h, unconsumed);
+ if (err != ARCHIVE_OK)
+ return (err);
+ err = tar_read_header(a, tar, entry, unconsumed);
+ return (err);
+}
+
+static int
+header_pax_extensions(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h, size_t *unconsumed)
+{
+ int err, err2;
+
+ err = read_body_to_string(a, tar, &(tar->pax_header), h, unconsumed);
+ if (err != ARCHIVE_OK)
+ return (err);
+
+ /* Parse the next header. */
+ err = tar_read_header(a, tar, entry, unconsumed);
+ if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN))
+ return (err);
+
+ /*
+ * TODO: Parse global/default options into 'entry' struct here
+ * before handling file-specific options.
+ *
+ * This design (parse standard header, then overwrite with pax
+ * extended attribute data) usually works well, but isn't ideal;
+ * it would be better to parse the pax extended attributes first
+ * and then skip any fields in the standard header that were
+ * defined in the pax header.
+ */
+ err2 = pax_header(a, tar, entry, tar->pax_header.s);
+ err = err_combine(err, err2);
+ tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
+ return (err);
+}
+
+
+/*
+ * Parse a file header for a Posix "ustar" archive entry. This also
+ * handles "pax" or "extended ustar" entries.
+ */
+static int
+header_ustar(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h)
+{
+ const struct archive_entry_header_ustar *header;
+ struct archive_string *as;
+ int err = ARCHIVE_OK, r;
+
+ header = (const struct archive_entry_header_ustar *)h;
+
+ /* Copy name into an internal buffer to ensure null-termination. */
+ as = &(tar->entry_pathname);
+ if (header->prefix[0]) {
+ archive_strncpy(as, header->prefix, sizeof(header->prefix));
+ if (as->s[archive_strlen(as) - 1] != '/')
+ archive_strappend_char(as, '/');
+ archive_strncat(as, header->name, sizeof(header->name));
+ } else {
+ archive_strncpy(as, header->name, sizeof(header->name));
+ }
+ if (archive_entry_copy_pathname_l(entry, as->s, archive_strlen(as),
+ tar->sconv) != 0) {
+ err = set_conversion_failed_error(a, tar->sconv, "Pathname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ }
+
+ /* Handle rest of common fields. */
+ r = header_common(a, tar, entry, h);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ if (r < err)
+ err = r;
+
+ /* Handle POSIX ustar fields. */
+ if (archive_entry_copy_uname_l(entry,
+ header->uname, sizeof(header->uname), tar->sconv) != 0) {
+ err = set_conversion_failed_error(a, tar->sconv, "Uname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ }
+
+ if (archive_entry_copy_gname_l(entry,
+ header->gname, sizeof(header->gname), tar->sconv) != 0) {
+ err = set_conversion_failed_error(a, tar->sconv, "Gname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ }
+
+ /* Parse out device numbers only for char and block specials. */
+ if (header->typeflag[0] == '3' || header->typeflag[0] == '4') {
+ archive_entry_set_rdevmajor(entry, (dev_t)
+ tar_atol(header->rdevmajor, sizeof(header->rdevmajor)));
+ archive_entry_set_rdevminor(entry, (dev_t)
+ tar_atol(header->rdevminor, sizeof(header->rdevminor)));
+ }
+
+ tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
+
+ return (err);
+}
+
+
+/*
+ * Parse the pax extended attributes record.
+ *
+ * Returns non-zero if there's an error in the data.
+ */
+static int
+pax_header(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, char *attr)
+{
+ size_t attr_length, l, line_length;
+ char *p;
+ char *key, *value;
+ struct archive_string *as;
+ struct archive_string_conv *sconv;
+ int err, err2;
+
+ attr_length = strlen(attr);
+ tar->pax_hdrcharset_binary = 0;
+ archive_string_empty(&(tar->entry_gname));
+ archive_string_empty(&(tar->entry_linkpath));
+ archive_string_empty(&(tar->entry_pathname));
+ archive_string_empty(&(tar->entry_pathname_override));
+ archive_string_empty(&(tar->entry_uname));
+ err = ARCHIVE_OK;
+ while (attr_length > 0) {
+ /* Parse decimal length field at start of line. */
+ line_length = 0;
+ l = attr_length;
+ p = attr; /* Record start of line. */
+ while (l>0) {
+ if (*p == ' ') {
+ p++;
+ l--;
+ break;
+ }
+ if (*p < '0' || *p > '9') {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Ignoring malformed pax extended attributes");
+ return (ARCHIVE_WARN);
+ }
+ line_length *= 10;
+ line_length += *p - '0';
+ if (line_length > 999999) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Rejecting pax extended attribute > 1MB");
+ return (ARCHIVE_WARN);
+ }
+ p++;
+ l--;
+ }
+
+ /*
+ * Parsed length must be no bigger than available data,
+ * at least 1, and the last character of the line must
+ * be '\n'.
+ */
+ if (line_length > attr_length
+ || line_length < 1
+ || attr[line_length - 1] != '\n')
+ {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Ignoring malformed pax extended attribute");
+ return (ARCHIVE_WARN);
+ }
+
+ /* Null-terminate the line. */
+ attr[line_length - 1] = '\0';
+
+ /* Find end of key and null terminate it. */
+ key = p;
+ if (key[0] == '=')
+ return (-1);
+ while (*p && *p != '=')
+ ++p;
+ if (*p == '\0') {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid pax extended attributes");
+ return (ARCHIVE_WARN);
+ }
+ *p = '\0';
+
+ /* Identify null-terminated 'value' portion. */
+ value = p + 1;
+
+ /* Identify this attribute and set it in the entry. */
+ err2 = pax_attribute(a, tar, entry, key, value);
+ if (err2 == ARCHIVE_FATAL)
+ return (err2);
+ err = err_combine(err, err2);
+
+ /* Skip to next line */
+ attr += line_length;
+ attr_length -= line_length;
+ }
+
+ /*
+ * PAX format uses UTF-8 as default charset for its metadata
+ * unless hdrcharset=BINARY is present in its header.
+ * We apply the charset specified by the hdrcharset option only
+ * when the hdrcharset attribute(in PAX header) is BINARY because
+ * we respect the charset described in PAX header and BINARY also
+ * means that metadata(filename,uname and gname) character-set
+ * is unknown.
+ */
+ if (tar->pax_hdrcharset_binary)
+ sconv = tar->opt_sconv;
+ else {
+ sconv = archive_string_conversion_from_charset(
+ &(a->archive), "UTF-8", 1);
+ if (sconv == NULL)
+ return (ARCHIVE_FATAL);
+ if (tar->compat_2x)
+ archive_string_conversion_set_opt(sconv,
+ SCONV_SET_OPT_UTF8_LIBARCHIVE2X);
+ }
+
+ if (archive_strlen(&(tar->entry_gname)) > 0) {
+ if (archive_entry_copy_gname_l(entry, tar->entry_gname.s,
+ archive_strlen(&(tar->entry_gname)), sconv) != 0) {
+ err = set_conversion_failed_error(a, sconv, "Gname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ /* Use a converted an original name. */
+ archive_entry_copy_gname(entry, tar->entry_gname.s);
+ }
+ }
+ if (archive_strlen(&(tar->entry_linkpath)) > 0) {
+ if (archive_entry_copy_link_l(entry, tar->entry_linkpath.s,
+ archive_strlen(&(tar->entry_linkpath)), sconv) != 0) {
+ err = set_conversion_failed_error(a, sconv, "Linkname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ /* Use a converted an original name. */
+ archive_entry_copy_link(entry, tar->entry_linkpath.s);
+ }
+ }
+ /*
+ * Some extensions (such as the GNU sparse file extensions)
+ * deliberately store a synthetic name under the regular 'path'
+ * attribute and the real file name under a different attribute.
+ * Since we're supposed to not care about the order, we
+ * have no choice but to store all of the various filenames
+ * we find and figure it all out afterwards. This is the
+ * figuring out part.
+ */
+ as = NULL;
+ if (archive_strlen(&(tar->entry_pathname_override)) > 0)
+ as = &(tar->entry_pathname_override);
+ else if (archive_strlen(&(tar->entry_pathname)) > 0)
+ as = &(tar->entry_pathname);
+ if (as != NULL) {
+ if (archive_entry_copy_pathname_l(entry, as->s,
+ archive_strlen(as), sconv) != 0) {
+ err = set_conversion_failed_error(a, sconv, "Pathname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ /* Use a converted an original name. */
+ archive_entry_copy_pathname(entry, as->s);
+ }
+ }
+ if (archive_strlen(&(tar->entry_uname)) > 0) {
+ if (archive_entry_copy_uname_l(entry, tar->entry_uname.s,
+ archive_strlen(&(tar->entry_uname)), sconv) != 0) {
+ err = set_conversion_failed_error(a, sconv, "Uname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ /* Use a converted an original name. */
+ archive_entry_copy_uname(entry, tar->entry_uname.s);
+ }
+ }
+ return (err);
+}
+
+static int
+pax_attribute_xattr(struct archive_entry *entry,
+ char *name, char *value)
+{
+ char *name_decoded;
+ void *value_decoded;
+ size_t value_len;
+
+ if (strlen(name) < 18 || (memcmp(name, "LIBARCHIVE.xattr.", 17)) != 0)
+ return 3;
+
+ name += 17;
+
+ /* URL-decode name */
+ name_decoded = url_decode(name);
+ if (name_decoded == NULL)
+ return 2;
+
+ /* Base-64 decode value */
+ value_decoded = base64_decode(value, strlen(value), &value_len);
+ if (value_decoded == NULL) {
+ free(name_decoded);
+ return 1;
+ }
+
+ archive_entry_xattr_add_entry(entry, name_decoded,
+ value_decoded, value_len);
+
+ free(name_decoded);
+ free(value_decoded);
+ return 0;
+}
+
+/*
+ * Parse a single key=value attribute. key/value pointers are
+ * assumed to point into reasonably long-lived storage.
+ *
+ * Note that POSIX reserves all-lowercase keywords. Vendor-specific
+ * extensions should always have keywords of the form "VENDOR.attribute"
+ * In particular, it's quite feasible to support many different
+ * vendor extensions here. I'm using "LIBARCHIVE" for extensions
+ * unique to this library.
+ *
+ * Investigate other vendor-specific extensions and see if
+ * any of them look useful.
+ */
+static int
+pax_attribute(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, char *key, char *value)
+{
+ int64_t s;
+ long n;
+ int err = ARCHIVE_OK, r;
+
+ if (value == NULL)
+ value = ""; /* Disable compiler warning; do not pass
+ * NULL pointer to strlen(). */
+ switch (key[0]) {
+ case 'G':
+ /* GNU "0.0" sparse pax format. */
+ if (strcmp(key, "GNU.sparse.numblocks") == 0) {
+ tar->sparse_offset = -1;
+ tar->sparse_numbytes = -1;
+ tar->sparse_gnu_major = 0;
+ tar->sparse_gnu_minor = 0;
+ }
+ if (strcmp(key, "GNU.sparse.offset") == 0) {
+ tar->sparse_offset = tar_atol10(value, strlen(value));
+ if (tar->sparse_numbytes != -1) {
+ if (gnu_add_sparse_entry(a, tar,
+ tar->sparse_offset, tar->sparse_numbytes)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ tar->sparse_offset = -1;
+ tar->sparse_numbytes = -1;
+ }
+ }
+ if (strcmp(key, "GNU.sparse.numbytes") == 0) {
+ tar->sparse_numbytes = tar_atol10(value, strlen(value));
+ if (tar->sparse_numbytes != -1) {
+ if (gnu_add_sparse_entry(a, tar,
+ tar->sparse_offset, tar->sparse_numbytes)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ tar->sparse_offset = -1;
+ tar->sparse_numbytes = -1;
+ }
+ }
+ if (strcmp(key, "GNU.sparse.size") == 0) {
+ tar->realsize = tar_atol10(value, strlen(value));
+ archive_entry_set_size(entry, tar->realsize);
+ }
+
+ /* GNU "0.1" sparse pax format. */
+ if (strcmp(key, "GNU.sparse.map") == 0) {
+ tar->sparse_gnu_major = 0;
+ tar->sparse_gnu_minor = 1;
+ if (gnu_sparse_01_parse(a, tar, value) != ARCHIVE_OK)
+ return (ARCHIVE_WARN);
+ }
+
+ /* GNU "1.0" sparse pax format */
+ if (strcmp(key, "GNU.sparse.major") == 0) {
+ tar->sparse_gnu_major = (int)tar_atol10(value, strlen(value));
+ tar->sparse_gnu_pending = 1;
+ }
+ if (strcmp(key, "GNU.sparse.minor") == 0) {
+ tar->sparse_gnu_minor = (int)tar_atol10(value, strlen(value));
+ tar->sparse_gnu_pending = 1;
+ }
+ if (strcmp(key, "GNU.sparse.name") == 0) {
+ /*
+ * The real filename; when storing sparse
+ * files, GNU tar puts a synthesized name into
+ * the regular 'path' attribute in an attempt
+ * to limit confusion. ;-)
+ */
+ archive_strcpy(&(tar->entry_pathname_override), value);
+ }
+ if (strcmp(key, "GNU.sparse.realsize") == 0) {
+ tar->realsize = tar_atol10(value, strlen(value));
+ archive_entry_set_size(entry, tar->realsize);
+ }
+ break;
+ case 'L':
+ /* Our extensions */
+/* TODO: Handle arbitrary extended attributes... */
+/*
+ if (strcmp(key, "LIBARCHIVE.xxxxxxx") == 0)
+ archive_entry_set_xxxxxx(entry, value);
+*/
+ if (strcmp(key, "LIBARCHIVE.creationtime") == 0) {
+ pax_time(value, &s, &n);
+ archive_entry_set_birthtime(entry, s, n);
+ }
+ if (memcmp(key, "LIBARCHIVE.xattr.", 17) == 0)
+ pax_attribute_xattr(entry, key, value);
+ break;
+ case 'S':
+ /* We support some keys used by the "star" archiver */
+ if (strcmp(key, "SCHILY.acl.access") == 0) {
+ if (tar->sconv_acl == NULL) {
+ tar->sconv_acl =
+ archive_string_conversion_from_charset(
+ &(a->archive), "UTF-8", 1);
+ if (tar->sconv_acl == NULL)
+ return (ARCHIVE_FATAL);
+ }
+
+ r = archive_acl_parse_l(archive_entry_acl(entry),
+ value, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
+ tar->sconv_acl);
+ if (r != ARCHIVE_OK) {
+ err = r;
+ if (err == ARCHIVE_FATAL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for "
+ "SCHILY.acl.access");
+ return (err);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Parse error: SCHILY.acl.access");
+ }
+ } else if (strcmp(key, "SCHILY.acl.default") == 0) {
+ if (tar->sconv_acl == NULL) {
+ tar->sconv_acl =
+ archive_string_conversion_from_charset(
+ &(a->archive), "UTF-8", 1);
+ if (tar->sconv_acl == NULL)
+ return (ARCHIVE_FATAL);
+ }
+
+ r = archive_acl_parse_l(archive_entry_acl(entry),
+ value, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT,
+ tar->sconv_acl);
+ if (r != ARCHIVE_OK) {
+ err = r;
+ if (err == ARCHIVE_FATAL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for "
+ "SCHILY.acl.default");
+ return (err);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Parse error: SCHILY.acl.default");
+ }
+ } else if (strcmp(key, "SCHILY.devmajor") == 0) {
+ archive_entry_set_rdevmajor(entry,
+ (dev_t)tar_atol10(value, strlen(value)));
+ } else if (strcmp(key, "SCHILY.devminor") == 0) {
+ archive_entry_set_rdevminor(entry,
+ (dev_t)tar_atol10(value, strlen(value)));
+ } else if (strcmp(key, "SCHILY.fflags") == 0) {
+ archive_entry_copy_fflags_text(entry, value);
+ } else if (strcmp(key, "SCHILY.dev") == 0) {
+ archive_entry_set_dev(entry,
+ (dev_t)tar_atol10(value, strlen(value)));
+ } else if (strcmp(key, "SCHILY.ino") == 0) {
+ archive_entry_set_ino(entry,
+ tar_atol10(value, strlen(value)));
+ } else if (strcmp(key, "SCHILY.nlink") == 0) {
+ archive_entry_set_nlink(entry, (unsigned)
+ tar_atol10(value, strlen(value)));
+ } else if (strcmp(key, "SCHILY.realsize") == 0) {
+ tar->realsize = tar_atol10(value, strlen(value));
+ archive_entry_set_size(entry, tar->realsize);
+ } else if (strcmp(key, "SUN.holesdata") == 0) {
+ /* A Solaris extension for sparse. */
+ r = solaris_sparse_parse(a, tar, entry, value);
+ if (r < err) {
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ err = r;
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Parse error: SUN.holesdata");
+ }
+ }
+ break;
+ case 'a':
+ if (strcmp(key, "atime") == 0) {
+ pax_time(value, &s, &n);
+ archive_entry_set_atime(entry, s, n);
+ }
+ break;
+ case 'c':
+ if (strcmp(key, "ctime") == 0) {
+ pax_time(value, &s, &n);
+ archive_entry_set_ctime(entry, s, n);
+ } else if (strcmp(key, "charset") == 0) {
+ /* TODO: Publish charset information in entry. */
+ } else if (strcmp(key, "comment") == 0) {
+ /* TODO: Publish comment in entry. */
+ }
+ break;
+ case 'g':
+ if (strcmp(key, "gid") == 0) {
+ archive_entry_set_gid(entry,
+ tar_atol10(value, strlen(value)));
+ } else if (strcmp(key, "gname") == 0) {
+ archive_strcpy(&(tar->entry_gname), value);
+ }
+ break;
+ case 'h':
+ if (strcmp(key, "hdrcharset") == 0) {
+ if (strcmp(value, "BINARY") == 0)
+ /* Binary mode. */
+ tar->pax_hdrcharset_binary = 1;
+ else if (strcmp(value, "ISO-IR 10646 2000 UTF-8") == 0)
+ tar->pax_hdrcharset_binary = 0;
+ }
+ break;
+ case 'l':
+ /* pax interchange doesn't distinguish hardlink vs. symlink. */
+ if (strcmp(key, "linkpath") == 0) {
+ archive_strcpy(&(tar->entry_linkpath), value);
+ }
+ break;
+ case 'm':
+ if (strcmp(key, "mtime") == 0) {
+ pax_time(value, &s, &n);
+ archive_entry_set_mtime(entry, s, n);
+ }
+ break;
+ case 'p':
+ if (strcmp(key, "path") == 0) {
+ archive_strcpy(&(tar->entry_pathname), value);
+ }
+ break;
+ case 'r':
+ /* POSIX has reserved 'realtime.*' */
+ break;
+ case 's':
+ /* POSIX has reserved 'security.*' */
+ /* Someday: if (strcmp(key, "security.acl") == 0) { ... } */
+ if (strcmp(key, "size") == 0) {
+ /* "size" is the size of the data in the entry. */
+ tar->entry_bytes_remaining
+ = tar_atol10(value, strlen(value));
+ /*
+ * But, "size" is not necessarily the size of
+ * the file on disk; if this is a sparse file,
+ * the disk size may have already been set from
+ * GNU.sparse.realsize or GNU.sparse.size or
+ * an old GNU header field or SCHILY.realsize
+ * or ....
+ */
+ if (tar->realsize < 0) {
+ archive_entry_set_size(entry,
+ tar->entry_bytes_remaining);
+ tar->realsize
+ = tar->entry_bytes_remaining;
+ }
+ }
+ break;
+ case 'u':
+ if (strcmp(key, "uid") == 0) {
+ archive_entry_set_uid(entry,
+ tar_atol10(value, strlen(value)));
+ } else if (strcmp(key, "uname") == 0) {
+ archive_strcpy(&(tar->entry_uname), value);
+ }
+ break;
+ }
+ return (err);
+}
+
+
+
+/*
+ * parse a decimal time value, which may include a fractional portion
+ */
+static void
+pax_time(const char *p, int64_t *ps, long *pn)
+{
+ char digit;
+ int64_t s;
+ unsigned long l;
+ int sign;
+ int64_t limit, last_digit_limit;
+
+ limit = INT64_MAX / 10;
+ last_digit_limit = INT64_MAX % 10;
+
+ s = 0;
+ sign = 1;
+ if (*p == '-') {
+ sign = -1;
+ p++;
+ }
+ while (*p >= '0' && *p <= '9') {
+ digit = *p - '0';
+ if (s > limit ||
+ (s == limit && digit > last_digit_limit)) {
+ s = INT64_MAX;
+ break;
+ }
+ s = (s * 10) + digit;
+ ++p;
+ }
+
+ *ps = s * sign;
+
+ /* Calculate nanoseconds. */
+ *pn = 0;
+
+ if (*p != '.')
+ return;
+
+ l = 100000000UL;
+ do {
+ ++p;
+ if (*p >= '0' && *p <= '9')
+ *pn += (*p - '0') * l;
+ else
+ break;
+ } while (l /= 10);
+}
+
+/*
+ * Parse GNU tar header
+ */
+static int
+header_gnutar(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const void *h, size_t *unconsumed)
+{
+ const struct archive_entry_header_gnutar *header;
+ int64_t t;
+ int err = ARCHIVE_OK;
+
+ /*
+ * GNU header is like POSIX ustar, except 'prefix' is
+ * replaced with some other fields. This also means the
+ * filename is stored as in old-style archives.
+ */
+
+ /* Grab fields common to all tar variants. */
+ err = header_common(a, tar, entry, h);
+ if (err == ARCHIVE_FATAL)
+ return (err);
+
+ /* Copy filename over (to ensure null termination). */
+ header = (const struct archive_entry_header_gnutar *)h;
+ if (archive_entry_copy_pathname_l(entry,
+ header->name, sizeof(header->name), tar->sconv) != 0) {
+ err = set_conversion_failed_error(a, tar->sconv, "Pathname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ }
+
+ /* Fields common to ustar and GNU */
+ /* XXX Can the following be factored out since it's common
+ * to ustar and gnu tar? Is it okay to move it down into
+ * header_common, perhaps? */
+ if (archive_entry_copy_uname_l(entry,
+ header->uname, sizeof(header->uname), tar->sconv) != 0) {
+ err = set_conversion_failed_error(a, tar->sconv, "Uname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ }
+
+ if (archive_entry_copy_gname_l(entry,
+ header->gname, sizeof(header->gname), tar->sconv) != 0) {
+ err = set_conversion_failed_error(a, tar->sconv, "Gname");
+ if (err == ARCHIVE_FATAL)
+ return (err);
+ }
+
+ /* Parse out device numbers only for char and block specials */
+ if (header->typeflag[0] == '3' || header->typeflag[0] == '4') {
+ archive_entry_set_rdevmajor(entry, (dev_t)
+ tar_atol(header->rdevmajor, sizeof(header->rdevmajor)));
+ archive_entry_set_rdevminor(entry, (dev_t)
+ tar_atol(header->rdevminor, sizeof(header->rdevminor)));
+ } else
+ archive_entry_set_rdev(entry, 0);
+
+ tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
+
+ /* Grab GNU-specific fields. */
+ t = tar_atol(header->atime, sizeof(header->atime));
+ if (t > 0)
+ archive_entry_set_atime(entry, t, 0);
+ t = tar_atol(header->ctime, sizeof(header->ctime));
+ if (t > 0)
+ archive_entry_set_ctime(entry, t, 0);
+
+ if (header->realsize[0] != 0) {
+ tar->realsize
+ = tar_atol(header->realsize, sizeof(header->realsize));
+ archive_entry_set_size(entry, tar->realsize);
+ }
+
+ if (header->sparse[0].offset[0] != 0) {
+ if (gnu_sparse_old_read(a, tar, header, unconsumed)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } else {
+ if (header->isextended[0] != 0) {
+ /* XXX WTF? XXX */
+ }
+ }
+
+ return (err);
+}
+
+static int
+gnu_add_sparse_entry(struct archive_read *a, struct tar *tar,
+ int64_t offset, int64_t remaining)
+{
+ struct sparse_block *p;
+
+ p = (struct sparse_block *)malloc(sizeof(*p));
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ memset(p, 0, sizeof(*p));
+ if (tar->sparse_last != NULL)
+ tar->sparse_last->next = p;
+ else
+ tar->sparse_list = p;
+ tar->sparse_last = p;
+ p->offset = offset;
+ p->remaining = remaining;
+ return (ARCHIVE_OK);
+}
+
+static void
+gnu_clear_sparse_list(struct tar *tar)
+{
+ struct sparse_block *p;
+
+ while (tar->sparse_list != NULL) {
+ p = tar->sparse_list;
+ tar->sparse_list = p->next;
+ free(p);
+ }
+ tar->sparse_last = NULL;
+}
+
+/*
+ * GNU tar old-format sparse data.
+ *
+ * GNU old-format sparse data is stored in a fixed-field
+ * format. Offset/size values are 11-byte octal fields (same
+ * format as 'size' field in ustart header). These are
+ * stored in the header, allocating subsequent header blocks
+ * as needed. Extending the header in this way is a pretty
+ * severe POSIX violation; this design has earned GNU tar a
+ * lot of criticism.
+ */
+
+static int
+gnu_sparse_old_read(struct archive_read *a, struct tar *tar,
+ const struct archive_entry_header_gnutar *header, size_t *unconsumed)
+{
+ ssize_t bytes_read;
+ const void *data;
+ struct extended {
+ struct gnu_sparse sparse[21];
+ char isextended[1];
+ char padding[7];
+ };
+ const struct extended *ext;
+
+ if (gnu_sparse_old_parse(a, tar, header->sparse, 4) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ if (header->isextended[0] == 0)
+ return (ARCHIVE_OK);
+
+ do {
+ tar_flush_unconsumed(a, unconsumed);
+ data = __archive_read_ahead(a, 512, &bytes_read);
+ if (bytes_read < 0)
+ return (ARCHIVE_FATAL);
+ if (bytes_read < 512) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated tar archive "
+ "detected while reading sparse file data");
+ return (ARCHIVE_FATAL);
+ }
+ *unconsumed = 512;
+ ext = (const struct extended *)data;
+ if (gnu_sparse_old_parse(a, tar, ext->sparse, 21) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } while (ext->isextended[0] != 0);
+ if (tar->sparse_list != NULL)
+ tar->entry_offset = tar->sparse_list->offset;
+ return (ARCHIVE_OK);
+}
+
+static int
+gnu_sparse_old_parse(struct archive_read *a, struct tar *tar,
+ const struct gnu_sparse *sparse, int length)
+{
+ while (length > 0 && sparse->offset[0] != 0) {
+ if (gnu_add_sparse_entry(a, tar,
+ tar_atol(sparse->offset, sizeof(sparse->offset)),
+ tar_atol(sparse->numbytes, sizeof(sparse->numbytes)))
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ sparse++;
+ length--;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * GNU tar sparse format 0.0
+ *
+ * Beginning with GNU tar 1.15, sparse files are stored using
+ * information in the pax extended header. The GNU tar maintainers
+ * have gone through a number of variations in the process of working
+ * out this scheme; fortunately, they're all numbered.
+ *
+ * Sparse format 0.0 uses attribute GNU.sparse.numblocks to store the
+ * number of blocks, and GNU.sparse.offset/GNU.sparse.numbytes to
+ * store offset/size for each block. The repeated instances of these
+ * latter fields violate the pax specification (which frowns on
+ * duplicate keys), so this format was quickly replaced.
+ */
+
+/*
+ * GNU tar sparse format 0.1
+ *
+ * This version replaced the offset/numbytes attributes with
+ * a single "map" attribute that stored a list of integers. This
+ * format had two problems: First, the "map" attribute could be very
+ * long, which caused problems for some implementations. More
+ * importantly, the sparse data was lost when extracted by archivers
+ * that didn't recognize this extension.
+ */
+
+static int
+gnu_sparse_01_parse(struct archive_read *a, struct tar *tar, const char *p)
+{
+ const char *e;
+ int64_t offset = -1, size = -1;
+
+ for (;;) {
+ e = p;
+ while (*e != '\0' && *e != ',') {
+ if (*e < '0' || *e > '9')
+ return (ARCHIVE_WARN);
+ e++;
+ }
+ if (offset < 0) {
+ offset = tar_atol10(p, e - p);
+ if (offset < 0)
+ return (ARCHIVE_WARN);
+ } else {
+ size = tar_atol10(p, e - p);
+ if (size < 0)
+ return (ARCHIVE_WARN);
+ if (gnu_add_sparse_entry(a, tar, offset, size)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ offset = -1;
+ }
+ if (*e == '\0')
+ return (ARCHIVE_OK);
+ p = e + 1;
+ }
+}
+
+/*
+ * GNU tar sparse format 1.0
+ *
+ * The idea: The offset/size data is stored as a series of base-10
+ * ASCII numbers prepended to the file data, so that dearchivers that
+ * don't support this format will extract the block map along with the
+ * data and a separate post-process can restore the sparseness.
+ *
+ * Unfortunately, GNU tar 1.16 had a bug that added unnecessary
+ * padding to the body of the file when using this format. GNU tar
+ * 1.17 corrected this bug without bumping the version number, so
+ * it's not possible to support both variants. This code supports
+ * the later variant at the expense of not supporting the former.
+ *
+ * This variant also replaced GNU.sparse.size with GNU.sparse.realsize
+ * and introduced the GNU.sparse.major/GNU.sparse.minor attributes.
+ */
+
+/*
+ * Read the next line from the input, and parse it as a decimal
+ * integer followed by '\n'. Returns positive integer value or
+ * negative on error.
+ */
+static int64_t
+gnu_sparse_10_atol(struct archive_read *a, struct tar *tar,
+ int64_t *remaining, size_t *unconsumed)
+{
+ int64_t l, limit, last_digit_limit;
+ const char *p;
+ ssize_t bytes_read;
+ int base, digit;
+
+ base = 10;
+ limit = INT64_MAX / base;
+ last_digit_limit = INT64_MAX % base;
+
+ /*
+ * Skip any lines starting with '#'; GNU tar specs
+ * don't require this, but they should.
+ */
+ do {
+ bytes_read = readline(a, tar, &p,
+ (ssize_t)tar_min(*remaining, 100), unconsumed);
+ if (bytes_read <= 0)
+ return (ARCHIVE_FATAL);
+ *remaining -= bytes_read;
+ } while (p[0] == '#');
+
+ l = 0;
+ while (bytes_read > 0) {
+ if (*p == '\n')
+ return (l);
+ if (*p < '0' || *p >= '0' + base)
+ return (ARCHIVE_WARN);
+ digit = *p - '0';
+ if (l > limit || (l == limit && digit > last_digit_limit))
+ l = INT64_MAX; /* Truncate on overflow. */
+ else
+ l = (l * base) + digit;
+ p++;
+ bytes_read--;
+ }
+ /* TODO: Error message. */
+ return (ARCHIVE_WARN);
+}
+
+/*
+ * Returns length (in bytes) of the sparse data description
+ * that was read.
+ */
+static ssize_t
+gnu_sparse_10_read(struct archive_read *a, struct tar *tar, size_t *unconsumed)
+{
+ ssize_t bytes_read;
+ int entries;
+ int64_t offset, size, to_skip, remaining;
+
+ /* Clear out the existing sparse list. */
+ gnu_clear_sparse_list(tar);
+
+ remaining = tar->entry_bytes_remaining;
+
+ /* Parse entries. */
+ entries = (int)gnu_sparse_10_atol(a, tar, &remaining, unconsumed);
+ if (entries < 0)
+ return (ARCHIVE_FATAL);
+ /* Parse the individual entries. */
+ while (entries-- > 0) {
+ /* Parse offset/size */
+ offset = gnu_sparse_10_atol(a, tar, &remaining, unconsumed);
+ if (offset < 0)
+ return (ARCHIVE_FATAL);
+ size = gnu_sparse_10_atol(a, tar, &remaining, unconsumed);
+ if (size < 0)
+ return (ARCHIVE_FATAL);
+ /* Add a new sparse entry. */
+ if (gnu_add_sparse_entry(a, tar, offset, size) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ /* Skip rest of block... */
+ tar_flush_unconsumed(a, unconsumed);
+ bytes_read = (ssize_t)(tar->entry_bytes_remaining - remaining);
+ to_skip = 0x1ff & -bytes_read;
+ if (to_skip != __archive_read_consume(a, to_skip))
+ return (ARCHIVE_FATAL);
+ return ((ssize_t)(bytes_read + to_skip));
+}
+
+/*
+ * Solaris pax extension for a sparse file. This is recorded with the
+ * data and hole pairs. The way recording sparse information by Solaris'
+ * pax simply indicates where data and sparse are, so the stored contents
+ * consist of both data and hole.
+ */
+static int
+solaris_sparse_parse(struct archive_read *a, struct tar *tar,
+ struct archive_entry *entry, const char *p)
+{
+ const char *e;
+ int64_t start, end;
+ int hole = 1;
+
+ (void)entry; /* UNUSED */
+
+ end = 0;
+ if (*p == ' ')
+ p++;
+ else
+ return (ARCHIVE_WARN);
+ for (;;) {
+ e = p;
+ while (*e != '\0' && *e != ' ') {
+ if (*e < '0' || *e > '9')
+ return (ARCHIVE_WARN);
+ e++;
+ }
+ start = end;
+ end = tar_atol10(p, e - p);
+ if (end < 0)
+ return (ARCHIVE_WARN);
+ if (start < end) {
+ if (gnu_add_sparse_entry(a, tar, start,
+ end - start) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ tar->sparse_last->hole = hole;
+ }
+ if (*e == '\0')
+ return (ARCHIVE_OK);
+ p = e + 1;
+ hole = hole == 0;
+ }
+}
+
+/*-
+ * Convert text->integer.
+ *
+ * Traditional tar formats (including POSIX) specify base-8 for
+ * all of the standard numeric fields. This is a significant limitation
+ * in practice:
+ * = file size is limited to 8GB
+ * = rdevmajor and rdevminor are limited to 21 bits
+ * = uid/gid are limited to 21 bits
+ *
+ * There are two workarounds for this:
+ * = pax extended headers, which use variable-length string fields
+ * = GNU tar and STAR both allow either base-8 or base-256 in
+ * most fields. The high bit is set to indicate base-256.
+ *
+ * On read, this implementation supports both extensions.
+ */
+static int64_t
+tar_atol(const char *p, size_t char_cnt)
+{
+ /*
+ * Technically, GNU tar considers a field to be in base-256
+ * only if the first byte is 0xff or 0x80.
+ */
+ if (*p & 0x80)
+ return (tar_atol256(p, char_cnt));
+ return (tar_atol8(p, char_cnt));
+}
+
+/*
+ * Note that this implementation does not (and should not!) obey
+ * locale settings; you cannot simply substitute strtol here, since
+ * it does obey locale.
+ */
+static int64_t
+tar_atol_base_n(const char *p, size_t char_cnt, int base)
+{
+ int64_t l, maxval, limit, last_digit_limit;
+ int digit, sign;
+
+ maxval = INT64_MAX;
+ limit = INT64_MAX / base;
+ last_digit_limit = INT64_MAX % base;
+
+ /* the pointer will not be dereferenced if char_cnt is zero
+ * due to the way the && operator is evaulated.
+ */
+ while (char_cnt != 0 && (*p == ' ' || *p == '\t')) {
+ p++;
+ char_cnt--;
+ }
+
+ sign = 1;
+ if (char_cnt != 0 && *p == '-') {
+ sign = -1;
+ p++;
+ char_cnt--;
+
+ maxval = INT64_MIN;
+ limit = -(INT64_MIN / base);
+ last_digit_limit = INT64_MIN % base;
+ }
+
+ l = 0;
+ if (char_cnt != 0) {
+ digit = *p - '0';
+ while (digit >= 0 && digit < base && char_cnt != 0) {
+ if (l>limit || (l == limit && digit > last_digit_limit)) {
+ return maxval; /* Truncate on overflow. */
+ }
+ l = (l * base) + digit;
+ digit = *++p - '0';
+ char_cnt--;
+ }
+ }
+ return (sign < 0) ? -l : l;
+}
+
+static int64_t
+tar_atol8(const char *p, size_t char_cnt)
+{
+ return tar_atol_base_n(p, char_cnt, 8);
+}
+
+static int64_t
+tar_atol10(const char *p, size_t char_cnt)
+{
+ return tar_atol_base_n(p, char_cnt, 10);
+}
+
+/*
+ * Parse a base-256 integer. This is just a variable-length
+ * twos-complement signed binary value in big-endian order, except
+ * that the high-order bit is ignored. The values here can be up to
+ * 12 bytes, so we need to be careful about overflowing 64-bit
+ * (8-byte) integers.
+ *
+ * This code unashamedly assumes that the local machine uses 8-bit
+ * bytes and twos-complement arithmetic.
+ */
+static int64_t
+tar_atol256(const char *_p, size_t char_cnt)
+{
+ uint64_t l;
+ const unsigned char *p = (const unsigned char *)_p;
+ unsigned char c, neg;
+
+ /* Extend 7-bit 2s-comp to 8-bit 2s-comp, decide sign. */
+ c = *p;
+ if (c & 0x40) {
+ neg = 0xff;
+ c |= 0x80;
+ l = ~ARCHIVE_LITERAL_ULL(0);
+ } else {
+ neg = 0;
+ c &= 0x7f;
+ l = 0;
+ }
+
+ /* If more than 8 bytes, check that we can ignore
+ * high-order bits without overflow. */
+ while (char_cnt > sizeof(int64_t)) {
+ --char_cnt;
+ if (c != neg)
+ return neg ? INT64_MIN : INT64_MAX;
+ c = *++p;
+ }
+
+ /* c is first byte that fits; if sign mismatch, return overflow */
+ if ((c ^ neg) & 0x80) {
+ return neg ? INT64_MIN : INT64_MAX;
+ }
+
+ /* Accumulate remaining bytes. */
+ while (--char_cnt > 0) {
+ l = (l << 8) | c;
+ c = *++p;
+ }
+ l = (l << 8) | c;
+ /* Return signed twos-complement value. */
+ return (int64_t)(l);
+}
+
+/*
+ * Returns length of line (including trailing newline)
+ * or negative on error. 'start' argument is updated to
+ * point to first character of line. This avoids copying
+ * when possible.
+ */
+static ssize_t
+readline(struct archive_read *a, struct tar *tar, const char **start,
+ ssize_t limit, size_t *unconsumed)
+{
+ ssize_t bytes_read;
+ ssize_t total_size = 0;
+ const void *t;
+ const char *s;
+ void *p;
+
+ tar_flush_unconsumed(a, unconsumed);
+
+ t = __archive_read_ahead(a, 1, &bytes_read);
+ if (bytes_read <= 0)
+ return (ARCHIVE_FATAL);
+ s = t; /* Start of line? */
+ p = memchr(t, '\n', bytes_read);
+ /* If we found '\n' in the read buffer, return pointer to that. */
+ if (p != NULL) {
+ bytes_read = 1 + ((const char *)p) - s;
+ if (bytes_read > limit) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Line too long");
+ return (ARCHIVE_FATAL);
+ }
+ *unconsumed = bytes_read;
+ *start = s;
+ return (bytes_read);
+ }
+ *unconsumed = bytes_read;
+ /* Otherwise, we need to accumulate in a line buffer. */
+ for (;;) {
+ if (total_size + bytes_read > limit) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Line too long");
+ return (ARCHIVE_FATAL);
+ }
+ if (archive_string_ensure(&tar->line, total_size + bytes_read) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate working buffer");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(tar->line.s + total_size, t, bytes_read);
+ tar_flush_unconsumed(a, unconsumed);
+ total_size += bytes_read;
+ /* If we found '\n', clean up and return. */
+ if (p != NULL) {
+ *start = tar->line.s;
+ return (total_size);
+ }
+ /* Read some more. */
+ t = __archive_read_ahead(a, 1, &bytes_read);
+ 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;
+ }
+ *unconsumed = bytes_read;
+ }
+}
+
+/*
+ * base64_decode - Base64 decode
+ *
+ * This accepts most variations of base-64 encoding, including:
+ * * with or without line breaks
+ * * with or without the final group padded with '=' or '_' characters
+ * (The most economical Base-64 variant does not pad the last group and
+ * omits line breaks; RFC1341 used for MIME requires both.)
+ */
+static char *
+base64_decode(const char *s, size_t len, size_t *out_len)
+{
+ static const unsigned char digits[64] = {
+ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N',
+ 'O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b',
+ 'c','d','e','f','g','h','i','j','k','l','m','n','o','p',
+ 'q','r','s','t','u','v','w','x','y','z','0','1','2','3',
+ '4','5','6','7','8','9','+','/' };
+ static unsigned char decode_table[128];
+ char *out, *d;
+ const unsigned char *src = (const unsigned char *)s;
+
+ /* If the decode table is not yet initialized, prepare it. */
+ if (decode_table[digits[1]] != 1) {
+ unsigned i;
+ memset(decode_table, 0xff, sizeof(decode_table));
+ for (i = 0; i < sizeof(digits); i++)
+ decode_table[digits[i]] = i;
+ }
+
+ /* Allocate enough space to hold the entire output. */
+ /* Note that we may not use all of this... */
+ out = (char *)malloc(len - len / 4 + 1);
+ if (out == NULL) {
+ *out_len = 0;
+ return (NULL);
+ }
+ d = out;
+
+ while (len > 0) {
+ /* Collect the next group of (up to) four characters. */
+ int v = 0;
+ int group_size = 0;
+ while (group_size < 4 && len > 0) {
+ /* '=' or '_' padding indicates final group. */
+ if (*src == '=' || *src == '_') {
+ len = 0;
+ break;
+ }
+ /* Skip illegal characters (including line breaks) */
+ if (*src > 127 || *src < 32
+ || decode_table[*src] == 0xff) {
+ len--;
+ src++;
+ continue;
+ }
+ v <<= 6;
+ v |= decode_table[*src++];
+ len --;
+ group_size++;
+ }
+ /* Align a short group properly. */
+ v <<= 6 * (4 - group_size);
+ /* Unpack the group we just collected. */
+ switch (group_size) {
+ case 4: d[2] = v & 0xff;
+ /* FALLTHROUGH */
+ case 3: d[1] = (v >> 8) & 0xff;
+ /* FALLTHROUGH */
+ case 2: d[0] = (v >> 16) & 0xff;
+ break;
+ case 1: /* this is invalid! */
+ break;
+ }
+ d += group_size * 3 / 4;
+ }
+
+ *out_len = d - out;
+ return (out);
+}
+
+static char *
+url_decode(const char *in)
+{
+ char *out, *d;
+ const char *s;
+
+ out = (char *)malloc(strlen(in) + 1);
+ if (out == NULL)
+ return (NULL);
+ for (s = in, d = out; *s != '\0'; ) {
+ if (s[0] == '%' && s[1] != '\0' && s[2] != '\0') {
+ /* Try to convert % escape */
+ int digit1 = tohex(s[1]);
+ int digit2 = tohex(s[2]);
+ if (digit1 >= 0 && digit2 >= 0) {
+ /* Looks good, consume three chars */
+ s += 3;
+ /* Convert output */
+ *d++ = ((digit1 << 4) | digit2);
+ continue;
+ }
+ /* Else fall through and treat '%' as normal char */
+ }
+ *d++ = *s++;
+ }
+ *d = '\0';
+ return (out);
+}
+
+static int
+tohex(int c)
+{
+ if (c >= '0' && c <= '9')
+ return (c - '0');
+ else if (c >= 'A' && c <= 'F')
+ return (c - 'A' + 10);
+ else if (c >= 'a' && c <= 'f')
+ return (c - 'a' + 10);
+ else
+ return (-1);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c
new file mode 100644
index 0000000000..68485d132e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c
@@ -0,0 +1,3337 @@
+/*-
+ * Copyright (c) 2009 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#if HAVE_LIBXML_XMLREADER_H
+#include <libxml/xmlreader.h>
+#elif HAVE_BSDXML_H
+#include <bsdxml.h>
+#elif HAVE_EXPAT_H
+#include <expat.h>
+#endif
+#ifdef HAVE_BZLIB_H
+#include <cm_bzlib.h>
+#endif
+#if HAVE_LZMA_H
+#include <cm_lzma.h>
+#elif HAVE_LZMADEC_H
+#include <lzmadec.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_crypto_private.h"
+#include "archive_endian.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+#if (!defined(HAVE_LIBXML_XMLREADER_H) && \
+ !defined(HAVE_BSDXML_H) && !defined(HAVE_EXPAT_H)) ||\
+ !defined(HAVE_ZLIB_H) || \
+ !defined(ARCHIVE_HAS_MD5) || !defined(ARCHIVE_HAS_SHA1)
+/*
+ * xar needs several external libraries.
+ * o libxml2 or expat --- XML parser
+ * o openssl or MD5/SHA1 hash function
+ * o zlib
+ * o bzlib2 (option)
+ * o liblzma (option)
+ */
+int
+archive_read_support_format_xar(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_xar");
+
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Xar not supported on this platform");
+ return (ARCHIVE_WARN);
+}
+
+#else /* Support xar format */
+
+/* #define DEBUG 1 */
+/* #define DEBUG_PRINT_TOC 1 */
+#if DEBUG_PRINT_TOC
+#define PRINT_TOC(d, outbytes) do { \
+ unsigned char *x = (unsigned char *)(uintptr_t)d; \
+ unsigned char c = x[outbytes-1]; \
+ x[outbytes - 1] = 0; \
+ fprintf(stderr, "%s", x); \
+ fprintf(stderr, "%c", c); \
+ x[outbytes - 1] = c; \
+} while (0)
+#else
+#define PRINT_TOC(d, outbytes)
+#endif
+
+#define HEADER_MAGIC 0x78617221
+#define HEADER_SIZE 28
+#define HEADER_VERSION 1
+#define CKSUM_NONE 0
+#define CKSUM_SHA1 1
+#define CKSUM_MD5 2
+
+#define MD5_SIZE 16
+#define SHA1_SIZE 20
+#define MAX_SUM_SIZE 20
+
+enum enctype {
+ NONE,
+ GZIP,
+ BZIP2,
+ LZMA,
+ XZ,
+};
+
+struct chksumval {
+ int alg;
+ size_t len;
+ unsigned char val[MAX_SUM_SIZE];
+};
+
+struct chksumwork {
+ int alg;
+#ifdef ARCHIVE_HAS_MD5
+ archive_md5_ctx md5ctx;
+#endif
+#ifdef ARCHIVE_HAS_SHA1
+ archive_sha1_ctx sha1ctx;
+#endif
+};
+
+struct xattr {
+ struct xattr *next;
+ struct archive_string name;
+ uint64_t id;
+ uint64_t length;
+ uint64_t offset;
+ uint64_t size;
+ enum enctype encoding;
+ struct chksumval a_sum;
+ struct chksumval e_sum;
+ struct archive_string fstype;
+};
+
+struct xar_file {
+ struct xar_file *next;
+ struct xar_file *hdnext;
+ struct xar_file *parent;
+ int subdirs;
+
+ unsigned int has;
+#define HAS_DATA 0x00001
+#define HAS_PATHNAME 0x00002
+#define HAS_SYMLINK 0x00004
+#define HAS_TIME 0x00008
+#define HAS_UID 0x00010
+#define HAS_GID 0x00020
+#define HAS_MODE 0x00040
+#define HAS_TYPE 0x00080
+#define HAS_DEV 0x00100
+#define HAS_DEVMAJOR 0x00200
+#define HAS_DEVMINOR 0x00400
+#define HAS_INO 0x00800
+#define HAS_FFLAGS 0x01000
+#define HAS_XATTR 0x02000
+#define HAS_ACL 0x04000
+
+ uint64_t id;
+ uint64_t length;
+ uint64_t offset;
+ uint64_t size;
+ enum enctype encoding;
+ struct chksumval a_sum;
+ struct chksumval e_sum;
+ struct archive_string pathname;
+ struct archive_string symlink;
+ time_t ctime;
+ time_t mtime;
+ time_t atime;
+ struct archive_string uname;
+ int64_t uid;
+ struct archive_string gname;
+ int64_t gid;
+ mode_t mode;
+ dev_t dev;
+ dev_t devmajor;
+ dev_t devminor;
+ int64_t ino64;
+ struct archive_string fflags_text;
+ unsigned int link;
+ unsigned int nlink;
+ struct archive_string hardlink;
+ struct xattr *xattr_list;
+};
+
+struct hdlink {
+ struct hdlink *next;
+
+ unsigned int id;
+ int cnt;
+ struct xar_file *files;
+};
+
+struct heap_queue {
+ struct xar_file **files;
+ int allocated;
+ int used;
+};
+
+enum xmlstatus {
+ INIT,
+ XAR,
+ TOC,
+ TOC_CREATION_TIME,
+ TOC_CHECKSUM,
+ TOC_CHECKSUM_OFFSET,
+ TOC_CHECKSUM_SIZE,
+ TOC_FILE,
+ FILE_DATA,
+ FILE_DATA_LENGTH,
+ FILE_DATA_OFFSET,
+ FILE_DATA_SIZE,
+ FILE_DATA_ENCODING,
+ FILE_DATA_A_CHECKSUM,
+ FILE_DATA_E_CHECKSUM,
+ FILE_DATA_CONTENT,
+ FILE_EA,
+ FILE_EA_LENGTH,
+ FILE_EA_OFFSET,
+ FILE_EA_SIZE,
+ FILE_EA_ENCODING,
+ FILE_EA_A_CHECKSUM,
+ FILE_EA_E_CHECKSUM,
+ FILE_EA_NAME,
+ FILE_EA_FSTYPE,
+ FILE_CTIME,
+ FILE_MTIME,
+ FILE_ATIME,
+ FILE_GROUP,
+ FILE_GID,
+ FILE_USER,
+ FILE_UID,
+ FILE_MODE,
+ FILE_DEVICE,
+ FILE_DEVICE_MAJOR,
+ FILE_DEVICE_MINOR,
+ FILE_DEVICENO,
+ FILE_INODE,
+ FILE_LINK,
+ FILE_TYPE,
+ FILE_NAME,
+ FILE_ACL,
+ FILE_ACL_DEFAULT,
+ FILE_ACL_ACCESS,
+ FILE_ACL_APPLEEXTENDED,
+ /* BSD file flags. */
+ FILE_FLAGS,
+ FILE_FLAGS_USER_NODUMP,
+ FILE_FLAGS_USER_IMMUTABLE,
+ FILE_FLAGS_USER_APPEND,
+ FILE_FLAGS_USER_OPAQUE,
+ FILE_FLAGS_USER_NOUNLINK,
+ FILE_FLAGS_SYS_ARCHIVED,
+ FILE_FLAGS_SYS_IMMUTABLE,
+ FILE_FLAGS_SYS_APPEND,
+ FILE_FLAGS_SYS_NOUNLINK,
+ FILE_FLAGS_SYS_SNAPSHOT,
+ /* Linux file flags. */
+ FILE_EXT2,
+ FILE_EXT2_SecureDeletion,
+ FILE_EXT2_Undelete,
+ FILE_EXT2_Compress,
+ FILE_EXT2_Synchronous,
+ FILE_EXT2_Immutable,
+ FILE_EXT2_AppendOnly,
+ FILE_EXT2_NoDump,
+ FILE_EXT2_NoAtime,
+ FILE_EXT2_CompDirty,
+ FILE_EXT2_CompBlock,
+ FILE_EXT2_NoCompBlock,
+ FILE_EXT2_CompError,
+ FILE_EXT2_BTree,
+ FILE_EXT2_HashIndexed,
+ FILE_EXT2_iMagic,
+ FILE_EXT2_Journaled,
+ FILE_EXT2_NoTail,
+ FILE_EXT2_DirSync,
+ FILE_EXT2_TopDir,
+ FILE_EXT2_Reserved,
+ UNKNOWN,
+};
+
+struct unknown_tag {
+ struct unknown_tag *next;
+ struct archive_string name;
+};
+
+struct xar {
+ uint64_t offset; /* Current position in the file. */
+ int64_t total;
+ uint64_t h_base;
+ int end_of_file;
+#define OUTBUFF_SIZE (1024 * 64)
+ unsigned char *outbuff;
+
+ enum xmlstatus xmlsts;
+ enum xmlstatus xmlsts_unknown;
+ struct unknown_tag *unknowntags;
+ int base64text;
+
+ /*
+ * TOC
+ */
+ uint64_t toc_remaining;
+ uint64_t toc_total;
+ uint64_t toc_chksum_offset;
+ uint64_t toc_chksum_size;
+
+ /*
+ * For Decoding data.
+ */
+ enum enctype rd_encoding;
+ z_stream stream;
+ int stream_valid;
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ bz_stream bzstream;
+ int bzstream_valid;
+#endif
+#if HAVE_LZMA_H && HAVE_LIBLZMA
+ lzma_stream lzstream;
+ int lzstream_valid;
+#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC
+ lzmadec_stream lzstream;
+ int lzstream_valid;
+#endif
+ /*
+ * For Checksum data.
+ */
+ struct chksumwork a_sumwrk;
+ struct chksumwork e_sumwrk;
+
+ struct xar_file *file; /* current reading file. */
+ struct xattr *xattr; /* current reading extended attribute. */
+ struct heap_queue file_queue;
+ struct xar_file *hdlink_orgs;
+ struct hdlink *hdlink_list;
+
+ int entry_init;
+ uint64_t entry_total;
+ uint64_t entry_remaining;
+ size_t entry_unconsumed;
+ uint64_t entry_size;
+ enum enctype entry_encoding;
+ struct chksumval entry_a_sum;
+ struct chksumval entry_e_sum;
+
+ struct archive_string_conv *sconv;
+};
+
+struct xmlattr {
+ struct xmlattr *next;
+ char *name;
+ char *value;
+};
+
+struct xmlattr_list {
+ struct xmlattr *first;
+ struct xmlattr **last;
+};
+
+static int xar_bid(struct archive_read *, int);
+static int xar_read_header(struct archive_read *,
+ struct archive_entry *);
+static int xar_read_data(struct archive_read *,
+ const void **, size_t *, int64_t *);
+static int xar_read_data_skip(struct archive_read *);
+static int xar_cleanup(struct archive_read *);
+static int move_reading_point(struct archive_read *, uint64_t);
+static int rd_contents_init(struct archive_read *,
+ enum enctype, int, int);
+static int rd_contents(struct archive_read *, const void **,
+ size_t *, size_t *, uint64_t);
+static uint64_t atol10(const char *, size_t);
+static int64_t atol8(const char *, size_t);
+static size_t atohex(unsigned char *, size_t, const char *, size_t);
+static time_t parse_time(const char *p, size_t n);
+static int heap_add_entry(struct archive_read *a,
+ struct heap_queue *, struct xar_file *);
+static struct xar_file *heap_get_entry(struct heap_queue *);
+static int add_link(struct archive_read *,
+ struct xar *, struct xar_file *);
+static void checksum_init(struct archive_read *, int, int);
+static void checksum_update(struct archive_read *, const void *,
+ size_t, const void *, size_t);
+static int checksum_final(struct archive_read *, const void *,
+ size_t, const void *, size_t);
+static int decompression_init(struct archive_read *, enum enctype);
+static int decompress(struct archive_read *, const void **,
+ size_t *, const void *, size_t *);
+static int decompression_cleanup(struct archive_read *);
+static void xmlattr_cleanup(struct xmlattr_list *);
+static int file_new(struct archive_read *,
+ struct xar *, struct xmlattr_list *);
+static void file_free(struct xar_file *);
+static int xattr_new(struct archive_read *,
+ struct xar *, struct xmlattr_list *);
+static void xattr_free(struct xattr *);
+static int getencoding(struct xmlattr_list *);
+static int getsumalgorithm(struct xmlattr_list *);
+static int unknowntag_start(struct archive_read *,
+ struct xar *, const char *);
+static void unknowntag_end(struct xar *, const char *);
+static int xml_start(struct archive_read *,
+ const char *, struct xmlattr_list *);
+static void xml_end(void *, const char *);
+static void xml_data(void *, const char *, int);
+static int xml_parse_file_flags(struct xar *, const char *);
+static int xml_parse_file_ext2(struct xar *, const char *);
+#if defined(HAVE_LIBXML_XMLREADER_H)
+static int xml2_xmlattr_setup(struct archive_read *,
+ struct xmlattr_list *, xmlTextReaderPtr);
+static int xml2_read_cb(void *, char *, int);
+static int xml2_close_cb(void *);
+static void xml2_error_hdr(void *, const char *, xmlParserSeverities,
+ xmlTextReaderLocatorPtr);
+static int xml2_read_toc(struct archive_read *);
+#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H)
+struct expat_userData {
+ int state;
+ struct archive_read *archive;
+};
+static int expat_xmlattr_setup(struct archive_read *,
+ struct xmlattr_list *, const XML_Char **);
+static void expat_start_cb(void *, const XML_Char *, const XML_Char **);
+static void expat_end_cb(void *, const XML_Char *);
+static void expat_data_cb(void *, const XML_Char *, int);
+static int expat_read_toc(struct archive_read *);
+#endif
+
+int
+archive_read_support_format_xar(struct archive *_a)
+{
+ struct xar *xar;
+ struct archive_read *a = (struct archive_read *)_a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_xar");
+
+ xar = (struct xar *)calloc(1, sizeof(*xar));
+ if (xar == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate xar data");
+ return (ARCHIVE_FATAL);
+ }
+
+ r = __archive_read_register_format(a,
+ xar,
+ "xar",
+ xar_bid,
+ NULL,
+ xar_read_header,
+ xar_read_data,
+ xar_read_data_skip,
+ NULL,
+ xar_cleanup,
+ NULL,
+ NULL);
+ if (r != ARCHIVE_OK)
+ free(xar);
+ return (r);
+}
+
+static int
+xar_bid(struct archive_read *a, int best_bid)
+{
+ const unsigned char *b;
+ int bid;
+
+ (void)best_bid; /* UNUSED */
+
+ b = __archive_read_ahead(a, HEADER_SIZE, NULL);
+ if (b == NULL)
+ return (-1);
+
+ bid = 0;
+ /*
+ * Verify magic code
+ */
+ if (archive_be32dec(b) != HEADER_MAGIC)
+ return (0);
+ bid += 32;
+ /*
+ * Verify header size
+ */
+ if (archive_be16dec(b+4) != HEADER_SIZE)
+ return (0);
+ bid += 16;
+ /*
+ * Verify header version
+ */
+ if (archive_be16dec(b+6) != HEADER_VERSION)
+ return (0);
+ bid += 16;
+ /*
+ * Verify type of checksum
+ */
+ switch (archive_be32dec(b+24)) {
+ case CKSUM_NONE:
+ case CKSUM_SHA1:
+ case CKSUM_MD5:
+ bid += 32;
+ break;
+ default:
+ return (0);
+ }
+
+ return (bid);
+}
+
+static int
+read_toc(struct archive_read *a)
+{
+ struct xar *xar;
+ struct xar_file *file;
+ const unsigned char *b;
+ uint64_t toc_compressed_size;
+ uint64_t toc_uncompressed_size;
+ uint32_t toc_chksum_alg;
+ ssize_t bytes;
+ int r;
+
+ xar = (struct xar *)(a->format->data);
+
+ /*
+ * Read xar header.
+ */
+ b = __archive_read_ahead(a, HEADER_SIZE, &bytes);
+ if (bytes < 0)
+ return ((int)bytes);
+ if (bytes < HEADER_SIZE) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated archive header");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (archive_be32dec(b) != HEADER_MAGIC) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid header magic");
+ return (ARCHIVE_FATAL);
+ }
+ if (archive_be16dec(b+6) != HEADER_VERSION) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unsupported header version(%d)",
+ archive_be16dec(b+6));
+ return (ARCHIVE_FATAL);
+ }
+ toc_compressed_size = archive_be64dec(b+8);
+ xar->toc_remaining = toc_compressed_size;
+ toc_uncompressed_size = archive_be64dec(b+16);
+ toc_chksum_alg = archive_be32dec(b+24);
+ __archive_read_consume(a, HEADER_SIZE);
+ xar->offset += HEADER_SIZE;
+ xar->toc_total = 0;
+
+ /*
+ * Read TOC(Table of Contents).
+ */
+ /* Initialize reading contents. */
+ r = move_reading_point(a, HEADER_SIZE);
+ if (r != ARCHIVE_OK)
+ return (r);
+ r = rd_contents_init(a, GZIP, toc_chksum_alg, CKSUM_NONE);
+ if (r != ARCHIVE_OK)
+ return (r);
+
+#ifdef HAVE_LIBXML_XMLREADER_H
+ r = xml2_read_toc(a);
+#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H)
+ r = expat_read_toc(a);
+#endif
+ if (r != ARCHIVE_OK)
+ return (r);
+
+ /* Set 'The HEAP' base. */
+ xar->h_base = xar->offset;
+ if (xar->toc_total != toc_uncompressed_size) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "TOC uncompressed size error");
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Checksum TOC
+ */
+ if (toc_chksum_alg != CKSUM_NONE) {
+ r = move_reading_point(a, xar->toc_chksum_offset);
+ if (r != ARCHIVE_OK)
+ return (r);
+ b = __archive_read_ahead(a,
+ (size_t)xar->toc_chksum_size, &bytes);
+ if (bytes < 0)
+ return ((int)bytes);
+ if ((uint64_t)bytes < xar->toc_chksum_size) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated archive file");
+ return (ARCHIVE_FATAL);
+ }
+ r = checksum_final(a, b,
+ (size_t)xar->toc_chksum_size, NULL, 0);
+ __archive_read_consume(a, xar->toc_chksum_size);
+ xar->offset += xar->toc_chksum_size;
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Connect hardlinked files.
+ */
+ for (file = xar->hdlink_orgs; file != NULL; file = file->hdnext) {
+ struct hdlink **hdlink;
+
+ for (hdlink = &(xar->hdlink_list); *hdlink != NULL;
+ hdlink = &((*hdlink)->next)) {
+ if ((*hdlink)->id == file->id) {
+ struct hdlink *hltmp;
+ struct xar_file *f2;
+ int nlink = (*hdlink)->cnt + 1;
+
+ file->nlink = nlink;
+ for (f2 = (*hdlink)->files; f2 != NULL;
+ f2 = f2->hdnext) {
+ f2->nlink = nlink;
+ archive_string_copy(
+ &(f2->hardlink), &(file->pathname));
+ }
+ /* Remove resolved files from hdlist_list. */
+ hltmp = *hdlink;
+ *hdlink = hltmp->next;
+ free(hltmp);
+ break;
+ }
+ }
+ }
+ a->archive.archive_format = ARCHIVE_FORMAT_XAR;
+ a->archive.archive_format_name = "xar";
+
+ return (ARCHIVE_OK);
+}
+
+static int
+xar_read_header(struct archive_read *a, struct archive_entry *entry)
+{
+ struct xar *xar;
+ struct xar_file *file;
+ struct xattr *xattr;
+ int r;
+
+ xar = (struct xar *)(a->format->data);
+ r = ARCHIVE_OK;
+
+ if (xar->offset == 0) {
+ /* Create a character conversion object. */
+ if (xar->sconv == NULL) {
+ xar->sconv = archive_string_conversion_from_charset(
+ &(a->archive), "UTF-8", 1);
+ if (xar->sconv == NULL)
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Read TOC. */
+ r = read_toc(a);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+
+ for (;;) {
+ file = xar->file = heap_get_entry(&(xar->file_queue));
+ if (file == NULL) {
+ xar->end_of_file = 1;
+ return (ARCHIVE_EOF);
+ }
+ if ((file->mode & AE_IFMT) != AE_IFDIR)
+ break;
+ if (file->has != (HAS_PATHNAME | HAS_TYPE))
+ break;
+ /*
+ * If a file type is a directory and it does not have
+ * any metadata, do not export.
+ */
+ file_free(file);
+ }
+ archive_entry_set_atime(entry, file->atime, 0);
+ archive_entry_set_ctime(entry, file->ctime, 0);
+ archive_entry_set_mtime(entry, file->mtime, 0);
+ archive_entry_set_gid(entry, file->gid);
+ if (file->gname.length > 0 &&
+ archive_entry_copy_gname_l(entry, file->gname.s,
+ archive_strlen(&(file->gname)), xar->sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Gname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Gname cannot be converted from %s to current locale.",
+ archive_string_conversion_charset_name(xar->sconv));
+ r = ARCHIVE_WARN;
+ }
+ archive_entry_set_uid(entry, file->uid);
+ if (file->uname.length > 0 &&
+ archive_entry_copy_uname_l(entry, file->uname.s,
+ archive_strlen(&(file->uname)), xar->sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Uname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Uname cannot be converted from %s to current locale.",
+ archive_string_conversion_charset_name(xar->sconv));
+ r = ARCHIVE_WARN;
+ }
+ archive_entry_set_mode(entry, file->mode);
+ if (archive_entry_copy_pathname_l(entry, file->pathname.s,
+ archive_strlen(&(file->pathname)), xar->sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Pathname cannot be converted from %s to current locale.",
+ archive_string_conversion_charset_name(xar->sconv));
+ r = ARCHIVE_WARN;
+ }
+
+
+ if (file->symlink.length > 0 &&
+ archive_entry_copy_symlink_l(entry, file->symlink.s,
+ archive_strlen(&(file->symlink)), xar->sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Linkname cannot be converted from %s to current locale.",
+ archive_string_conversion_charset_name(xar->sconv));
+ r = ARCHIVE_WARN;
+ }
+ /* Set proper nlink. */
+ if ((file->mode & AE_IFMT) == AE_IFDIR)
+ archive_entry_set_nlink(entry, file->subdirs + 2);
+ else
+ archive_entry_set_nlink(entry, file->nlink);
+ archive_entry_set_size(entry, file->size);
+ if (archive_strlen(&(file->hardlink)) > 0)
+ archive_entry_set_hardlink(entry, file->hardlink.s);
+ archive_entry_set_ino64(entry, file->ino64);
+ if (file->has & HAS_DEV)
+ archive_entry_set_dev(entry, file->dev);
+ if (file->has & HAS_DEVMAJOR)
+ archive_entry_set_devmajor(entry, file->devmajor);
+ if (file->has & HAS_DEVMINOR)
+ archive_entry_set_devminor(entry, file->devminor);
+ if (archive_strlen(&(file->fflags_text)) > 0)
+ archive_entry_copy_fflags_text(entry, file->fflags_text.s);
+
+ xar->entry_init = 1;
+ xar->entry_total = 0;
+ xar->entry_remaining = file->length;
+ xar->entry_size = file->size;
+ xar->entry_encoding = file->encoding;
+ xar->entry_a_sum = file->a_sum;
+ xar->entry_e_sum = file->e_sum;
+ /*
+ * Read extended attributes.
+ */
+ xattr = file->xattr_list;
+ while (xattr != NULL) {
+ const void *d;
+ size_t outbytes, used;
+
+ r = move_reading_point(a, xattr->offset);
+ if (r != ARCHIVE_OK)
+ break;
+ r = rd_contents_init(a, xattr->encoding,
+ xattr->a_sum.alg, xattr->e_sum.alg);
+ if (r != ARCHIVE_OK)
+ break;
+ d = NULL;
+ r = rd_contents(a, &d, &outbytes, &used, xattr->length);
+ if (r != ARCHIVE_OK)
+ break;
+ if (outbytes != xattr->size) {
+ archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC,
+ "Decompressed size error");
+ r = ARCHIVE_FATAL;
+ break;
+ }
+ r = checksum_final(a,
+ xattr->a_sum.val, xattr->a_sum.len,
+ xattr->e_sum.val, xattr->e_sum.len);
+ if (r != ARCHIVE_OK)
+ break;
+ archive_entry_xattr_add_entry(entry,
+ xattr->name.s, d, outbytes);
+ xattr = xattr->next;
+ }
+ if (r != ARCHIVE_OK) {
+ file_free(file);
+ return (r);
+ }
+
+ if (xar->entry_remaining > 0)
+ /* Move reading point to the beginning of current
+ * file contents. */
+ r = move_reading_point(a, file->offset);
+ else
+ r = ARCHIVE_OK;
+
+ file_free(file);
+ return (r);
+}
+
+static int
+xar_read_data(struct archive_read *a,
+ const void **buff, size_t *size, int64_t *offset)
+{
+ struct xar *xar;
+ size_t used;
+ int r;
+
+ xar = (struct xar *)(a->format->data);
+
+ if (xar->entry_unconsumed) {
+ __archive_read_consume(a, xar->entry_unconsumed);
+ xar->entry_unconsumed = 0;
+ }
+
+ if (xar->end_of_file || xar->entry_remaining <= 0) {
+ r = ARCHIVE_EOF;
+ goto abort_read_data;
+ }
+
+ if (xar->entry_init) {
+ r = rd_contents_init(a, xar->entry_encoding,
+ xar->entry_a_sum.alg, xar->entry_e_sum.alg);
+ if (r != ARCHIVE_OK) {
+ xar->entry_remaining = 0;
+ return (r);
+ }
+ xar->entry_init = 0;
+ }
+
+ *buff = NULL;
+ r = rd_contents(a, buff, size, &used, xar->entry_remaining);
+ if (r != ARCHIVE_OK)
+ goto abort_read_data;
+
+ *offset = xar->entry_total;
+ xar->entry_total += *size;
+ xar->total += *size;
+ xar->offset += used;
+ xar->entry_remaining -= used;
+ xar->entry_unconsumed = used;
+
+ if (xar->entry_remaining == 0) {
+ if (xar->entry_total != xar->entry_size) {
+ archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC,
+ "Decompressed size error");
+ r = ARCHIVE_FATAL;
+ goto abort_read_data;
+ }
+ r = checksum_final(a,
+ xar->entry_a_sum.val, xar->entry_a_sum.len,
+ xar->entry_e_sum.val, xar->entry_e_sum.len);
+ if (r != ARCHIVE_OK)
+ goto abort_read_data;
+ }
+
+ return (ARCHIVE_OK);
+abort_read_data:
+ *buff = NULL;
+ *size = 0;
+ *offset = xar->total;
+ return (r);
+}
+
+static int
+xar_read_data_skip(struct archive_read *a)
+{
+ struct xar *xar;
+ int64_t bytes_skipped;
+
+ xar = (struct xar *)(a->format->data);
+ if (xar->end_of_file)
+ return (ARCHIVE_EOF);
+ bytes_skipped = __archive_read_consume(a, xar->entry_remaining +
+ xar->entry_unconsumed);
+ if (bytes_skipped < 0)
+ return (ARCHIVE_FATAL);
+ xar->offset += bytes_skipped;
+ xar->entry_unconsumed = 0;
+ return (ARCHIVE_OK);
+}
+
+static int
+xar_cleanup(struct archive_read *a)
+{
+ struct xar *xar;
+ struct hdlink *hdlink;
+ int i;
+ int r;
+
+ xar = (struct xar *)(a->format->data);
+ r = decompression_cleanup(a);
+ hdlink = xar->hdlink_list;
+ while (hdlink != NULL) {
+ struct hdlink *next = hdlink->next;
+
+ free(hdlink);
+ hdlink = next;
+ }
+ for (i = 0; i < xar->file_queue.used; i++)
+ file_free(xar->file_queue.files[i]);
+ while (xar->unknowntags != NULL) {
+ struct unknown_tag *tag;
+
+ tag = xar->unknowntags;
+ xar->unknowntags = tag->next;
+ archive_string_free(&(tag->name));
+ free(tag);
+ }
+ free(xar->outbuff);
+ free(xar);
+ a->format->data = NULL;
+ return (r);
+}
+
+static int
+move_reading_point(struct archive_read *a, uint64_t offset)
+{
+ struct xar *xar;
+
+ xar = (struct xar *)(a->format->data);
+ if (xar->offset - xar->h_base != offset) {
+ /* Seek forward to the start of file contents. */
+ int64_t step;
+
+ step = offset - (xar->offset - xar->h_base);
+ if (step > 0) {
+ step = __archive_read_consume(a, step);
+ if (step < 0)
+ return ((int)step);
+ xar->offset += step;
+ } else {
+ int64_t pos = __archive_read_seek(a, offset, SEEK_SET);
+ if (pos == ARCHIVE_FAILED) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Cannot seek.");
+ return (ARCHIVE_FAILED);
+ }
+ xar->offset = pos;
+ }
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+rd_contents_init(struct archive_read *a, enum enctype encoding,
+ int a_sum_alg, int e_sum_alg)
+{
+ int r;
+
+ /* Init decompress library. */
+ if ((r = decompression_init(a, encoding)) != ARCHIVE_OK)
+ return (r);
+ /* Init checksum library. */
+ checksum_init(a, a_sum_alg, e_sum_alg);
+ return (ARCHIVE_OK);
+}
+
+static int
+rd_contents(struct archive_read *a, const void **buff, size_t *size,
+ size_t *used, uint64_t remaining)
+{
+ const unsigned char *b;
+ ssize_t bytes;
+
+ /* Get whatever bytes are immediately available. */
+ b = __archive_read_ahead(a, 1, &bytes);
+ if (bytes < 0)
+ return ((int)bytes);
+ if (bytes == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Truncated archive file");
+ return (ARCHIVE_FATAL);
+ }
+ if ((uint64_t)bytes > remaining)
+ bytes = (ssize_t)remaining;
+
+ /*
+ * Decompress contents of file.
+ */
+ *used = bytes;
+ if (decompress(a, buff, size, b, used) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /*
+ * Update checksum of a compressed data and a extracted data.
+ */
+ checksum_update(a, b, *used, *buff, *size);
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Note that this implementation does not (and should not!) obey
+ * locale settings; you cannot simply substitute strtol here, since
+ * it does obey locale.
+ */
+
+static uint64_t
+atol10(const char *p, size_t char_cnt)
+{
+ uint64_t l;
+ int digit;
+
+ l = 0;
+ digit = *p - '0';
+ while (digit >= 0 && digit < 10 && char_cnt-- > 0) {
+ l = (l * 10) + digit;
+ digit = *++p - '0';
+ }
+ return (l);
+}
+
+static int64_t
+atol8(const char *p, size_t char_cnt)
+{
+ int64_t l;
+ int digit;
+
+ l = 0;
+ while (char_cnt-- > 0) {
+ if (*p >= '0' && *p <= '7')
+ digit = *p - '0';
+ else
+ break;
+ p++;
+ l <<= 3;
+ l |= digit;
+ }
+ return (l);
+}
+
+static size_t
+atohex(unsigned char *b, size_t bsize, const char *p, size_t psize)
+{
+ size_t fbsize = bsize;
+
+ while (bsize && psize > 1) {
+ unsigned char x;
+
+ if (p[0] >= 'a' && p[0] <= 'z')
+ x = (p[0] - 'a' + 0x0a) << 4;
+ else if (p[0] >= 'A' && p[0] <= 'Z')
+ x = (p[0] - 'A' + 0x0a) << 4;
+ else if (p[0] >= '0' && p[0] <= '9')
+ x = (p[0] - '0') << 4;
+ else
+ return (-1);
+ if (p[1] >= 'a' && p[1] <= 'z')
+ x |= p[1] - 'a' + 0x0a;
+ else if (p[1] >= 'A' && p[1] <= 'Z')
+ x |= p[1] - 'A' + 0x0a;
+ else if (p[1] >= '0' && p[1] <= '9')
+ x |= p[1] - '0';
+ else
+ return (-1);
+
+ *b++ = x;
+ bsize--;
+ p += 2;
+ psize -= 2;
+ }
+ return (fbsize - bsize);
+}
+
+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. */
+ 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
+}
+
+static time_t
+parse_time(const char *p, size_t n)
+{
+ struct tm tm;
+ time_t t = 0;
+ int64_t data;
+
+ memset(&tm, 0, sizeof(tm));
+ if (n != 20)
+ return (t);
+ data = atol10(p, 4);
+ if (data < 1900)
+ return (t);
+ tm.tm_year = (int)data - 1900;
+ p += 4;
+ if (*p++ != '-')
+ return (t);
+ data = atol10(p, 2);
+ if (data < 1 || data > 12)
+ return (t);
+ tm.tm_mon = (int)data -1;
+ p += 2;
+ if (*p++ != '-')
+ return (t);
+ data = atol10(p, 2);
+ if (data < 1 || data > 31)
+ return (t);
+ tm.tm_mday = (int)data;
+ p += 2;
+ if (*p++ != 'T')
+ return (t);
+ data = atol10(p, 2);
+ if (data < 0 || data > 23)
+ return (t);
+ tm.tm_hour = (int)data;
+ p += 2;
+ if (*p++ != ':')
+ return (t);
+ data = atol10(p, 2);
+ if (data < 0 || data > 59)
+ return (t);
+ tm.tm_min = (int)data;
+ p += 2;
+ if (*p++ != ':')
+ return (t);
+ data = atol10(p, 2);
+ if (data < 0 || data > 60)
+ return (t);
+ tm.tm_sec = (int)data;
+#if 0
+ p += 2;
+ if (*p != 'Z')
+ return (t);
+#endif
+
+ t = time_from_tm(&tm);
+
+ return (t);
+}
+
+static int
+heap_add_entry(struct archive_read *a,
+ struct heap_queue *heap, struct xar_file *file)
+{
+ uint64_t file_id, parent_id;
+ int hole, parent;
+
+ /* Expand our pending files list as necessary. */
+ if (heap->used >= heap->allocated) {
+ struct xar_file **new_pending_files;
+ int new_size = heap->allocated * 2;
+
+ if (heap->allocated < 1024)
+ new_size = 1024;
+ /* Overflow might keep us from growing the list. */
+ if (new_size <= heap->allocated) {
+ archive_set_error(&a->archive,
+ ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ new_pending_files = (struct xar_file **)
+ malloc(new_size * sizeof(new_pending_files[0]));
+ if (new_pending_files == NULL) {
+ archive_set_error(&a->archive,
+ ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(new_pending_files, heap->files,
+ heap->allocated * sizeof(new_pending_files[0]));
+ if (heap->files != NULL)
+ free(heap->files);
+ heap->files = new_pending_files;
+ heap->allocated = new_size;
+ }
+
+ file_id = file->id;
+
+ /*
+ * Start with hole at end, walk it up tree to find insertion point.
+ */
+ hole = heap->used++;
+ while (hole > 0) {
+ parent = (hole - 1)/2;
+ parent_id = heap->files[parent]->id;
+ if (file_id >= parent_id) {
+ heap->files[hole] = file;
+ return (ARCHIVE_OK);
+ }
+ /* Move parent into hole <==> move hole up tree. */
+ heap->files[hole] = heap->files[parent];
+ hole = parent;
+ }
+ heap->files[0] = file;
+
+ return (ARCHIVE_OK);
+}
+
+static struct xar_file *
+heap_get_entry(struct heap_queue *heap)
+{
+ uint64_t a_id, b_id, c_id;
+ int a, b, c;
+ struct xar_file *r, *tmp;
+
+ if (heap->used < 1)
+ return (NULL);
+
+ /*
+ * The first file in the list is the earliest; we'll return this.
+ */
+ r = heap->files[0];
+
+ /*
+ * Move the last item in the heap to the root of the tree
+ */
+ heap->files[0] = heap->files[--(heap->used)];
+
+ /*
+ * Rebalance the heap.
+ */
+ a = 0; /* Starting element and its heap key */
+ a_id = heap->files[a]->id;
+ for (;;) {
+ b = a + a + 1; /* First child */
+ if (b >= heap->used)
+ return (r);
+ b_id = heap->files[b]->id;
+ c = b + 1; /* Use second child if it is smaller. */
+ if (c < heap->used) {
+ c_id = heap->files[c]->id;
+ if (c_id < b_id) {
+ b = c;
+ b_id = c_id;
+ }
+ }
+ if (a_id <= b_id)
+ return (r);
+ tmp = heap->files[a];
+ heap->files[a] = heap->files[b];
+ heap->files[b] = tmp;
+ a = b;
+ }
+}
+
+static int
+add_link(struct archive_read *a, struct xar *xar, struct xar_file *file)
+{
+ struct hdlink *hdlink;
+
+ for (hdlink = xar->hdlink_list; hdlink != NULL; hdlink = hdlink->next) {
+ if (hdlink->id == file->link) {
+ file->hdnext = hdlink->files;
+ hdlink->cnt++;
+ hdlink->files = file;
+ return (ARCHIVE_OK);
+ }
+ }
+ hdlink = malloc(sizeof(*hdlink));
+ if (hdlink == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ file->hdnext = NULL;
+ hdlink->id = file->link;
+ hdlink->cnt = 1;
+ hdlink->files = file;
+ hdlink->next = xar->hdlink_list;
+ xar->hdlink_list = hdlink;
+ return (ARCHIVE_OK);
+}
+
+static void
+_checksum_init(struct chksumwork *sumwrk, int sum_alg)
+{
+ sumwrk->alg = sum_alg;
+ switch (sum_alg) {
+ case CKSUM_NONE:
+ break;
+ case CKSUM_SHA1:
+ archive_sha1_init(&(sumwrk->sha1ctx));
+ break;
+ case CKSUM_MD5:
+ archive_md5_init(&(sumwrk->md5ctx));
+ break;
+ }
+}
+
+static void
+_checksum_update(struct chksumwork *sumwrk, const void *buff, size_t size)
+{
+
+ switch (sumwrk->alg) {
+ case CKSUM_NONE:
+ break;
+ case CKSUM_SHA1:
+ archive_sha1_update(&(sumwrk->sha1ctx), buff, size);
+ break;
+ case CKSUM_MD5:
+ archive_md5_update(&(sumwrk->md5ctx), buff, size);
+ break;
+ }
+}
+
+static int
+_checksum_final(struct chksumwork *sumwrk, const void *val, size_t len)
+{
+ unsigned char sum[MAX_SUM_SIZE];
+ int r = ARCHIVE_OK;
+
+ switch (sumwrk->alg) {
+ case CKSUM_NONE:
+ break;
+ case CKSUM_SHA1:
+ archive_sha1_final(&(sumwrk->sha1ctx), sum);
+ if (len != SHA1_SIZE ||
+ memcmp(val, sum, SHA1_SIZE) != 0)
+ r = ARCHIVE_FAILED;
+ break;
+ case CKSUM_MD5:
+ archive_md5_final(&(sumwrk->md5ctx), sum);
+ if (len != MD5_SIZE ||
+ memcmp(val, sum, MD5_SIZE) != 0)
+ r = ARCHIVE_FAILED;
+ break;
+ }
+ return (r);
+}
+
+static void
+checksum_init(struct archive_read *a, int a_sum_alg, int e_sum_alg)
+{
+ struct xar *xar;
+
+ xar = (struct xar *)(a->format->data);
+ _checksum_init(&(xar->a_sumwrk), a_sum_alg);
+ _checksum_init(&(xar->e_sumwrk), e_sum_alg);
+}
+
+static void
+checksum_update(struct archive_read *a, const void *abuff, size_t asize,
+ const void *ebuff, size_t esize)
+{
+ struct xar *xar;
+
+ xar = (struct xar *)(a->format->data);
+ _checksum_update(&(xar->a_sumwrk), abuff, asize);
+ _checksum_update(&(xar->e_sumwrk), ebuff, esize);
+}
+
+static int
+checksum_final(struct archive_read *a, const void *a_sum_val,
+ size_t a_sum_len, const void *e_sum_val, size_t e_sum_len)
+{
+ struct xar *xar;
+ int r;
+
+ xar = (struct xar *)(a->format->data);
+ r = _checksum_final(&(xar->a_sumwrk), a_sum_val, a_sum_len);
+ if (r == ARCHIVE_OK)
+ r = _checksum_final(&(xar->e_sumwrk), e_sum_val, e_sum_len);
+ if (r != ARCHIVE_OK)
+ archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC,
+ "Sumcheck error");
+ return (r);
+}
+
+static int
+decompression_init(struct archive_read *a, enum enctype encoding)
+{
+ struct xar *xar;
+ const char *detail;
+ int r;
+
+ xar = (struct xar *)(a->format->data);
+ xar->rd_encoding = encoding;
+ switch (encoding) {
+ case NONE:
+ break;
+ case GZIP:
+ if (xar->stream_valid)
+ r = inflateReset(&(xar->stream));
+ else
+ r = inflateInit(&(xar->stream));
+ if (r != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Couldn't initialize zlib stream.");
+ return (ARCHIVE_FATAL);
+ }
+ xar->stream_valid = 1;
+ xar->stream.total_in = 0;
+ xar->stream.total_out = 0;
+ break;
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ case BZIP2:
+ if (xar->bzstream_valid) {
+ BZ2_bzDecompressEnd(&(xar->bzstream));
+ xar->bzstream_valid = 0;
+ }
+ r = BZ2_bzDecompressInit(&(xar->bzstream), 0, 0);
+ if (r == BZ_MEM_ERROR)
+ r = BZ2_bzDecompressInit(&(xar->bzstream), 0, 1);
+ if (r != BZ_OK) {
+ int err = ARCHIVE_ERRNO_MISC;
+ detail = NULL;
+ switch (r) {
+ case BZ_PARAM_ERROR:
+ detail = "invalid setup parameter";
+ break;
+ case BZ_MEM_ERROR:
+ err = ENOMEM;
+ detail = "out of memory";
+ break;
+ case BZ_CONFIG_ERROR:
+ detail = "mis-compiled library";
+ break;
+ }
+ archive_set_error(&a->archive, err,
+ "Internal error initializing decompressor: %s",
+ detail == NULL ? "??" : detail);
+ xar->bzstream_valid = 0;
+ return (ARCHIVE_FATAL);
+ }
+ xar->bzstream_valid = 1;
+ xar->bzstream.total_in_lo32 = 0;
+ xar->bzstream.total_in_hi32 = 0;
+ xar->bzstream.total_out_lo32 = 0;
+ xar->bzstream.total_out_hi32 = 0;
+ break;
+#endif
+#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA)
+#if LZMA_VERSION_MAJOR >= 5
+/* Effectively disable the limiter. */
+#define LZMA_MEMLIMIT UINT64_MAX
+#else
+/* NOTE: This needs to check memory size which running system has. */
+#define LZMA_MEMLIMIT (1U << 30)
+#endif
+ case XZ:
+ case LZMA:
+ if (xar->lzstream_valid) {
+ lzma_end(&(xar->lzstream));
+ xar->lzstream_valid = 0;
+ }
+ if (xar->entry_encoding == XZ)
+ r = lzma_stream_decoder(&(xar->lzstream),
+ LZMA_MEMLIMIT,/* memlimit */
+ LZMA_CONCATENATED);
+ else
+ r = lzma_alone_decoder(&(xar->lzstream),
+ LZMA_MEMLIMIT);/* memlimit */
+ if (r != LZMA_OK) {
+ switch (r) {
+ case LZMA_MEM_ERROR:
+ archive_set_error(&a->archive,
+ ENOMEM,
+ "Internal error initializing "
+ "compression library: "
+ "Cannot allocate memory");
+ break;
+ case LZMA_OPTIONS_ERROR:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Internal error initializing "
+ "compression library: "
+ "Invalid or unsupported options");
+ break;
+ default:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Internal error initializing "
+ "lzma library");
+ break;
+ }
+ return (ARCHIVE_FATAL);
+ }
+ xar->lzstream_valid = 1;
+ xar->lzstream.total_in = 0;
+ xar->lzstream.total_out = 0;
+ break;
+#elif defined(HAVE_LZMADEC_H) && defined(HAVE_LIBLZMADEC)
+ case LZMA:
+ if (xar->lzstream_valid)
+ lzmadec_end(&(xar->lzstream));
+ r = lzmadec_init(&(xar->lzstream));
+ if (r != LZMADEC_OK) {
+ switch (r) {
+ case LZMADEC_HEADER_ERROR:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Internal error initializing "
+ "compression library: "
+ "invalid header");
+ break;
+ case LZMADEC_MEM_ERROR:
+ archive_set_error(&a->archive,
+ ENOMEM,
+ "Internal error initializing "
+ "compression library: "
+ "out of memory");
+ break;
+ }
+ return (ARCHIVE_FATAL);
+ }
+ xar->lzstream_valid = 1;
+ xar->lzstream.total_in = 0;
+ xar->lzstream.total_out = 0;
+ break;
+#endif
+ /*
+ * Unsupported compression.
+ */
+ default:
+#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR)
+ case BZIP2:
+#endif
+#if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA)
+#if !defined(HAVE_LZMADEC_H) || !defined(HAVE_LIBLZMADEC)
+ case LZMA:
+#endif
+ case XZ:
+#endif
+ switch (xar->entry_encoding) {
+ case BZIP2: detail = "bzip2"; break;
+ case LZMA: detail = "lzma"; break;
+ case XZ: detail = "xz"; break;
+ default: detail = "??"; break;
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s compression not supported on this platform",
+ detail);
+ return (ARCHIVE_FAILED);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+decompress(struct archive_read *a, const void **buff, size_t *outbytes,
+ const void *b, size_t *used)
+{
+ struct xar *xar;
+ void *outbuff;
+ size_t avail_in, avail_out;
+ int r;
+
+ xar = (struct xar *)(a->format->data);
+ avail_in = *used;
+ outbuff = (void *)(uintptr_t)*buff;
+ if (outbuff == NULL) {
+ if (xar->outbuff == NULL) {
+ xar->outbuff = malloc(OUTBUFF_SIZE);
+ if (xar->outbuff == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't allocate memory for out buffer");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ outbuff = xar->outbuff;
+ *buff = outbuff;
+ avail_out = OUTBUFF_SIZE;
+ } else
+ avail_out = *outbytes;
+ switch (xar->rd_encoding) {
+ case GZIP:
+ xar->stream.next_in = (Bytef *)(uintptr_t)b;
+ xar->stream.avail_in = avail_in;
+ xar->stream.next_out = (unsigned char *)outbuff;
+ xar->stream.avail_out = avail_out;
+ r = inflate(&(xar->stream), 0);
+ switch (r) {
+ case Z_OK: /* Decompressor made some progress.*/
+ case Z_STREAM_END: /* Found end of stream. */
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "File decompression failed (%d)", r);
+ return (ARCHIVE_FATAL);
+ }
+ *used = avail_in - xar->stream.avail_in;
+ *outbytes = avail_out - xar->stream.avail_out;
+ break;
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ case BZIP2:
+ xar->bzstream.next_in = (char *)(uintptr_t)b;
+ xar->bzstream.avail_in = avail_in;
+ xar->bzstream.next_out = (char *)outbuff;
+ xar->bzstream.avail_out = avail_out;
+ r = BZ2_bzDecompress(&(xar->bzstream));
+ switch (r) {
+ case BZ_STREAM_END: /* Found end of stream. */
+ switch (BZ2_bzDecompressEnd(&(xar->bzstream))) {
+ case BZ_OK:
+ break;
+ default:
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up decompressor");
+ return (ARCHIVE_FATAL);
+ }
+ xar->bzstream_valid = 0;
+ /* FALLTHROUGH */
+ case BZ_OK: /* Decompressor made some progress. */
+ break;
+ default:
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "bzip decompression failed");
+ return (ARCHIVE_FATAL);
+ }
+ *used = avail_in - xar->bzstream.avail_in;
+ *outbytes = avail_out - xar->bzstream.avail_out;
+ break;
+#endif
+#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA)
+ case LZMA:
+ case XZ:
+ xar->lzstream.next_in = b;
+ xar->lzstream.avail_in = avail_in;
+ xar->lzstream.next_out = (unsigned char *)outbuff;
+ xar->lzstream.avail_out = avail_out;
+ r = lzma_code(&(xar->lzstream), LZMA_RUN);
+ switch (r) {
+ case LZMA_STREAM_END: /* Found end of stream. */
+ lzma_end(&(xar->lzstream));
+ xar->lzstream_valid = 0;
+ /* FALLTHROUGH */
+ case LZMA_OK: /* Decompressor made some progress. */
+ break;
+ default:
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "%s decompression failed(%d)",
+ (xar->entry_encoding == XZ)?"xz":"lzma",
+ r);
+ return (ARCHIVE_FATAL);
+ }
+ *used = avail_in - xar->lzstream.avail_in;
+ *outbytes = avail_out - xar->lzstream.avail_out;
+ break;
+#elif defined(HAVE_LZMADEC_H) && defined(HAVE_LIBLZMADEC)
+ case LZMA:
+ xar->lzstream.next_in = (unsigned char *)(uintptr_t)b;
+ xar->lzstream.avail_in = avail_in;
+ xar->lzstream.next_out = (unsigned char *)outbuff;
+ xar->lzstream.avail_out = avail_out;
+ r = lzmadec_decode(&(xar->lzstream), 0);
+ switch (r) {
+ case LZMADEC_STREAM_END: /* Found end of stream. */
+ switch (lzmadec_end(&(xar->lzstream))) {
+ case LZMADEC_OK:
+ break;
+ default:
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up lzmadec decompressor");
+ return (ARCHIVE_FATAL);
+ }
+ xar->lzstream_valid = 0;
+ /* FALLTHROUGH */
+ case LZMADEC_OK: /* Decompressor made some progress. */
+ break;
+ default:
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "lzmadec decompression failed(%d)",
+ r);
+ return (ARCHIVE_FATAL);
+ }
+ *used = avail_in - xar->lzstream.avail_in;
+ *outbytes = avail_out - xar->lzstream.avail_out;
+ break;
+#endif
+#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR)
+ case BZIP2:
+#endif
+#if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA)
+#if !defined(HAVE_LZMADEC_H) || !defined(HAVE_LIBLZMADEC)
+ case LZMA:
+#endif
+ case XZ:
+#endif
+ case NONE:
+ default:
+ if (outbuff == xar->outbuff) {
+ *buff = b;
+ *used = avail_in;
+ *outbytes = avail_in;
+ } else {
+ if (avail_out > avail_in)
+ avail_out = avail_in;
+ memcpy(outbuff, b, avail_out);
+ *used = avail_out;
+ *outbytes = avail_out;
+ }
+ break;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+decompression_cleanup(struct archive_read *a)
+{
+ struct xar *xar;
+ int r;
+
+ xar = (struct xar *)(a->format->data);
+ r = ARCHIVE_OK;
+ if (xar->stream_valid) {
+ if (inflateEnd(&(xar->stream)) != Z_OK) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up zlib decompressor");
+ r = ARCHIVE_FATAL;
+ }
+ }
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ if (xar->bzstream_valid) {
+ if (BZ2_bzDecompressEnd(&(xar->bzstream)) != BZ_OK) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up bzip2 decompressor");
+ r = ARCHIVE_FATAL;
+ }
+ }
+#endif
+#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA)
+ if (xar->lzstream_valid)
+ lzma_end(&(xar->lzstream));
+#elif defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA)
+ if (xar->lzstream_valid) {
+ if (lzmadec_end(&(xar->lzstream)) != LZMADEC_OK) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to clean up lzmadec decompressor");
+ r = ARCHIVE_FATAL;
+ }
+ }
+#endif
+ return (r);
+}
+
+static void
+xmlattr_cleanup(struct xmlattr_list *list)
+{
+ struct xmlattr *attr, *next;
+
+ attr = list->first;
+ while (attr != NULL) {
+ next = attr->next;
+ free(attr->name);
+ free(attr->value);
+ free(attr);
+ attr = next;
+ }
+ list->first = NULL;
+ list->last = &(list->first);
+}
+
+static int
+file_new(struct archive_read *a, struct xar *xar, struct xmlattr_list *list)
+{
+ struct xar_file *file;
+ struct xmlattr *attr;
+
+ file = calloc(1, sizeof(*file));
+ if (file == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ file->parent = xar->file;
+ file->mode = 0777 | AE_IFREG;
+ file->atime = time(NULL);
+ file->mtime = time(NULL);
+ xar->file = file;
+ xar->xattr = NULL;
+ for (attr = list->first; attr != NULL; attr = attr->next) {
+ if (strcmp(attr->name, "id") == 0)
+ file->id = atol10(attr->value, strlen(attr->value));
+ }
+ file->nlink = 1;
+ if (heap_add_entry(a, &(xar->file_queue), file) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ return (ARCHIVE_OK);
+}
+
+static void
+file_free(struct xar_file *file)
+{
+ struct xattr *xattr;
+
+ archive_string_free(&(file->pathname));
+ archive_string_free(&(file->symlink));
+ archive_string_free(&(file->uname));
+ archive_string_free(&(file->gname));
+ archive_string_free(&(file->hardlink));
+ xattr = file->xattr_list;
+ while (xattr != NULL) {
+ struct xattr *next;
+
+ next = xattr->next;
+ xattr_free(xattr);
+ xattr = next;
+ }
+
+ free(file);
+}
+
+static int
+xattr_new(struct archive_read *a, struct xar *xar, struct xmlattr_list *list)
+{
+ struct xattr *xattr, **nx;
+ struct xmlattr *attr;
+
+ xattr = calloc(1, sizeof(*xattr));
+ if (xattr == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ xar->xattr = xattr;
+ for (attr = list->first; attr != NULL; attr = attr->next) {
+ if (strcmp(attr->name, "id") == 0)
+ xattr->id = atol10(attr->value, strlen(attr->value));
+ }
+ /* Chain to xattr list. */
+ for (nx = &(xar->file->xattr_list);
+ *nx != NULL; nx = &((*nx)->next)) {
+ if (xattr->id < (*nx)->id)
+ break;
+ }
+ xattr->next = *nx;
+ *nx = xattr;
+
+ return (ARCHIVE_OK);
+}
+
+static void
+xattr_free(struct xattr *xattr)
+{
+ archive_string_free(&(xattr->name));
+ free(xattr);
+}
+
+static int
+getencoding(struct xmlattr_list *list)
+{
+ struct xmlattr *attr;
+ enum enctype encoding = NONE;
+
+ for (attr = list->first; attr != NULL; attr = attr->next) {
+ if (strcmp(attr->name, "style") == 0) {
+ if (strcmp(attr->value, "application/octet-stream") == 0)
+ encoding = NONE;
+ else if (strcmp(attr->value, "application/x-gzip") == 0)
+ encoding = GZIP;
+ else if (strcmp(attr->value, "application/x-bzip2") == 0)
+ encoding = BZIP2;
+ else if (strcmp(attr->value, "application/x-lzma") == 0)
+ encoding = LZMA;
+ else if (strcmp(attr->value, "application/x-xz") == 0)
+ encoding = XZ;
+ }
+ }
+ return (encoding);
+}
+
+static int
+getsumalgorithm(struct xmlattr_list *list)
+{
+ struct xmlattr *attr;
+ int alg = CKSUM_NONE;
+
+ for (attr = list->first; attr != NULL; attr = attr->next) {
+ if (strcmp(attr->name, "style") == 0) {
+ const char *v = attr->value;
+ if ((v[0] == 'S' || v[0] == 's') &&
+ (v[1] == 'H' || v[1] == 'h') &&
+ (v[2] == 'A' || v[2] == 'a') &&
+ v[3] == '1' && v[4] == '\0')
+ alg = CKSUM_SHA1;
+ if ((v[0] == 'M' || v[0] == 'm') &&
+ (v[1] == 'D' || v[1] == 'd') &&
+ v[2] == '5' && v[3] == '\0')
+ alg = CKSUM_MD5;
+ }
+ }
+ return (alg);
+}
+
+static int
+unknowntag_start(struct archive_read *a, struct xar *xar, const char *name)
+{
+ struct unknown_tag *tag;
+
+#if DEBUG
+ fprintf(stderr, "unknowntag_start:%s\n", name);
+#endif
+ tag = malloc(sizeof(*tag));
+ if (tag == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ tag->next = xar->unknowntags;
+ archive_string_init(&(tag->name));
+ archive_strcpy(&(tag->name), name);
+ if (xar->unknowntags == NULL) {
+ xar->xmlsts_unknown = xar->xmlsts;
+ xar->xmlsts = UNKNOWN;
+ }
+ xar->unknowntags = tag;
+ return (ARCHIVE_OK);
+}
+
+static void
+unknowntag_end(struct xar *xar, const char *name)
+{
+ struct unknown_tag *tag;
+
+#if DEBUG
+ fprintf(stderr, "unknowntag_end:%s\n", name);
+#endif
+ tag = xar->unknowntags;
+ if (tag == NULL || name == NULL)
+ return;
+ if (strcmp(tag->name.s, name) == 0) {
+ xar->unknowntags = tag->next;
+ archive_string_free(&(tag->name));
+ free(tag);
+ if (xar->unknowntags == NULL)
+ xar->xmlsts = xar->xmlsts_unknown;
+ }
+}
+
+static int
+xml_start(struct archive_read *a, const char *name, struct xmlattr_list *list)
+{
+ struct xar *xar;
+ struct xmlattr *attr;
+
+ xar = (struct xar *)(a->format->data);
+
+#if DEBUG
+ fprintf(stderr, "xml_sta:[%s]\n", name);
+ for (attr = list->first; attr != NULL; attr = attr->next)
+ fprintf(stderr, " attr:\"%s\"=\"%s\"\n",
+ attr->name, attr->value);
+#endif
+ xar->base64text = 0;
+ switch (xar->xmlsts) {
+ case INIT:
+ if (strcmp(name, "xar") == 0)
+ xar->xmlsts = XAR;
+ else
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case XAR:
+ if (strcmp(name, "toc") == 0)
+ xar->xmlsts = TOC;
+ else
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case TOC:
+ if (strcmp(name, "creation-time") == 0)
+ xar->xmlsts = TOC_CREATION_TIME;
+ else if (strcmp(name, "checksum") == 0)
+ xar->xmlsts = TOC_CHECKSUM;
+ else if (strcmp(name, "file") == 0) {
+ if (file_new(a, xar, list) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ xar->xmlsts = TOC_FILE;
+ }
+ else
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case TOC_CHECKSUM:
+ if (strcmp(name, "offset") == 0)
+ xar->xmlsts = TOC_CHECKSUM_OFFSET;
+ else if (strcmp(name, "size") == 0)
+ xar->xmlsts = TOC_CHECKSUM_SIZE;
+ else
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case TOC_FILE:
+ if (strcmp(name, "file") == 0) {
+ if (file_new(a, xar, list) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ else if (strcmp(name, "data") == 0)
+ xar->xmlsts = FILE_DATA;
+ else if (strcmp(name, "ea") == 0) {
+ if (xattr_new(a, xar, list) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ xar->xmlsts = FILE_EA;
+ }
+ else if (strcmp(name, "ctime") == 0)
+ xar->xmlsts = FILE_CTIME;
+ else if (strcmp(name, "mtime") == 0)
+ xar->xmlsts = FILE_MTIME;
+ else if (strcmp(name, "atime") == 0)
+ xar->xmlsts = FILE_ATIME;
+ else if (strcmp(name, "group") == 0)
+ xar->xmlsts = FILE_GROUP;
+ else if (strcmp(name, "gid") == 0)
+ xar->xmlsts = FILE_GID;
+ else if (strcmp(name, "user") == 0)
+ xar->xmlsts = FILE_USER;
+ else if (strcmp(name, "uid") == 0)
+ xar->xmlsts = FILE_UID;
+ else if (strcmp(name, "mode") == 0)
+ xar->xmlsts = FILE_MODE;
+ else if (strcmp(name, "device") == 0)
+ xar->xmlsts = FILE_DEVICE;
+ else if (strcmp(name, "deviceno") == 0)
+ xar->xmlsts = FILE_DEVICENO;
+ else if (strcmp(name, "inode") == 0)
+ xar->xmlsts = FILE_INODE;
+ else if (strcmp(name, "link") == 0)
+ xar->xmlsts = FILE_LINK;
+ else if (strcmp(name, "type") == 0) {
+ xar->xmlsts = FILE_TYPE;
+ for (attr = list->first; attr != NULL;
+ attr = attr->next) {
+ if (strcmp(attr->name, "link") != 0)
+ continue;
+ if (strcmp(attr->value, "original") == 0) {
+ xar->file->hdnext = xar->hdlink_orgs;
+ xar->hdlink_orgs = xar->file;
+ } else {
+ xar->file->link = (unsigned)atol10(attr->value,
+ strlen(attr->value));
+ if (xar->file->link > 0)
+ if (add_link(a, xar, xar->file) != ARCHIVE_OK) {
+ return (ARCHIVE_FATAL);
+ };
+ }
+ }
+ }
+ else if (strcmp(name, "name") == 0) {
+ xar->xmlsts = FILE_NAME;
+ for (attr = list->first; attr != NULL;
+ attr = attr->next) {
+ if (strcmp(attr->name, "enctype") == 0 &&
+ strcmp(attr->value, "base64") == 0)
+ xar->base64text = 1;
+ }
+ }
+ else if (strcmp(name, "acl") == 0)
+ xar->xmlsts = FILE_ACL;
+ else if (strcmp(name, "flags") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ else if (strcmp(name, "ext2") == 0)
+ xar->xmlsts = FILE_EXT2;
+ else
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case FILE_DATA:
+ if (strcmp(name, "length") == 0)
+ xar->xmlsts = FILE_DATA_LENGTH;
+ else if (strcmp(name, "offset") == 0)
+ xar->xmlsts = FILE_DATA_OFFSET;
+ else if (strcmp(name, "size") == 0)
+ xar->xmlsts = FILE_DATA_SIZE;
+ else if (strcmp(name, "encoding") == 0) {
+ xar->xmlsts = FILE_DATA_ENCODING;
+ xar->file->encoding = getencoding(list);
+ }
+ else if (strcmp(name, "archived-checksum") == 0) {
+ xar->xmlsts = FILE_DATA_A_CHECKSUM;
+ xar->file->a_sum.alg = getsumalgorithm(list);
+ }
+ else if (strcmp(name, "extracted-checksum") == 0) {
+ xar->xmlsts = FILE_DATA_E_CHECKSUM;
+ xar->file->e_sum.alg = getsumalgorithm(list);
+ }
+ else if (strcmp(name, "content") == 0)
+ xar->xmlsts = FILE_DATA_CONTENT;
+ else
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case FILE_DEVICE:
+ if (strcmp(name, "major") == 0)
+ xar->xmlsts = FILE_DEVICE_MAJOR;
+ else if (strcmp(name, "minor") == 0)
+ xar->xmlsts = FILE_DEVICE_MINOR;
+ else
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case FILE_DATA_CONTENT:
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case FILE_EA:
+ if (strcmp(name, "length") == 0)
+ xar->xmlsts = FILE_EA_LENGTH;
+ else if (strcmp(name, "offset") == 0)
+ xar->xmlsts = FILE_EA_OFFSET;
+ else if (strcmp(name, "size") == 0)
+ xar->xmlsts = FILE_EA_SIZE;
+ else if (strcmp(name, "encoding") == 0) {
+ xar->xmlsts = FILE_EA_ENCODING;
+ xar->xattr->encoding = getencoding(list);
+ } else if (strcmp(name, "archived-checksum") == 0)
+ xar->xmlsts = FILE_EA_A_CHECKSUM;
+ else if (strcmp(name, "extracted-checksum") == 0)
+ xar->xmlsts = FILE_EA_E_CHECKSUM;
+ else if (strcmp(name, "name") == 0)
+ xar->xmlsts = FILE_EA_NAME;
+ else if (strcmp(name, "fstype") == 0)
+ xar->xmlsts = FILE_EA_FSTYPE;
+ else
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case FILE_ACL:
+ if (strcmp(name, "appleextended") == 0)
+ xar->xmlsts = FILE_ACL_APPLEEXTENDED;
+ if (strcmp(name, "default") == 0)
+ xar->xmlsts = FILE_ACL_DEFAULT;
+ else if (strcmp(name, "access") == 0)
+ xar->xmlsts = FILE_ACL_ACCESS;
+ else
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case FILE_FLAGS:
+ if (!xml_parse_file_flags(xar, name))
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case FILE_EXT2:
+ if (!xml_parse_file_ext2(xar, name))
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ case TOC_CREATION_TIME:
+ case TOC_CHECKSUM_OFFSET:
+ case TOC_CHECKSUM_SIZE:
+ case FILE_DATA_LENGTH:
+ case FILE_DATA_OFFSET:
+ case FILE_DATA_SIZE:
+ case FILE_DATA_ENCODING:
+ case FILE_DATA_A_CHECKSUM:
+ case FILE_DATA_E_CHECKSUM:
+ case FILE_EA_LENGTH:
+ case FILE_EA_OFFSET:
+ case FILE_EA_SIZE:
+ case FILE_EA_ENCODING:
+ case FILE_EA_A_CHECKSUM:
+ case FILE_EA_E_CHECKSUM:
+ case FILE_EA_NAME:
+ case FILE_EA_FSTYPE:
+ case FILE_CTIME:
+ case FILE_MTIME:
+ case FILE_ATIME:
+ case FILE_GROUP:
+ case FILE_GID:
+ case FILE_USER:
+ case FILE_UID:
+ case FILE_INODE:
+ case FILE_DEVICE_MAJOR:
+ case FILE_DEVICE_MINOR:
+ case FILE_DEVICENO:
+ case FILE_MODE:
+ case FILE_TYPE:
+ case FILE_LINK:
+ case FILE_NAME:
+ case FILE_ACL_DEFAULT:
+ case FILE_ACL_ACCESS:
+ case FILE_ACL_APPLEEXTENDED:
+ case FILE_FLAGS_USER_NODUMP:
+ case FILE_FLAGS_USER_IMMUTABLE:
+ case FILE_FLAGS_USER_APPEND:
+ case FILE_FLAGS_USER_OPAQUE:
+ case FILE_FLAGS_USER_NOUNLINK:
+ case FILE_FLAGS_SYS_ARCHIVED:
+ case FILE_FLAGS_SYS_IMMUTABLE:
+ case FILE_FLAGS_SYS_APPEND:
+ case FILE_FLAGS_SYS_NOUNLINK:
+ case FILE_FLAGS_SYS_SNAPSHOT:
+ case FILE_EXT2_SecureDeletion:
+ case FILE_EXT2_Undelete:
+ case FILE_EXT2_Compress:
+ case FILE_EXT2_Synchronous:
+ case FILE_EXT2_Immutable:
+ case FILE_EXT2_AppendOnly:
+ case FILE_EXT2_NoDump:
+ case FILE_EXT2_NoAtime:
+ case FILE_EXT2_CompDirty:
+ case FILE_EXT2_CompBlock:
+ case FILE_EXT2_NoCompBlock:
+ case FILE_EXT2_CompError:
+ case FILE_EXT2_BTree:
+ case FILE_EXT2_HashIndexed:
+ case FILE_EXT2_iMagic:
+ case FILE_EXT2_Journaled:
+ case FILE_EXT2_NoTail:
+ case FILE_EXT2_DirSync:
+ case FILE_EXT2_TopDir:
+ case FILE_EXT2_Reserved:
+ case UNKNOWN:
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ break;
+ }
+ return (ARCHIVE_OK);
+}
+
+static void
+xml_end(void *userData, const char *name)
+{
+ struct archive_read *a;
+ struct xar *xar;
+
+ a = (struct archive_read *)userData;
+ xar = (struct xar *)(a->format->data);
+
+#if DEBUG
+ fprintf(stderr, "xml_end:[%s]\n", name);
+#endif
+ switch (xar->xmlsts) {
+ case INIT:
+ break;
+ case XAR:
+ if (strcmp(name, "xar") == 0)
+ xar->xmlsts = INIT;
+ break;
+ case TOC:
+ if (strcmp(name, "toc") == 0)
+ xar->xmlsts = XAR;
+ break;
+ case TOC_CREATION_TIME:
+ if (strcmp(name, "creation-time") == 0)
+ xar->xmlsts = TOC;
+ break;
+ case TOC_CHECKSUM:
+ if (strcmp(name, "checksum") == 0)
+ xar->xmlsts = TOC;
+ break;
+ case TOC_CHECKSUM_OFFSET:
+ if (strcmp(name, "offset") == 0)
+ xar->xmlsts = TOC_CHECKSUM;
+ break;
+ case TOC_CHECKSUM_SIZE:
+ if (strcmp(name, "size") == 0)
+ xar->xmlsts = TOC_CHECKSUM;
+ break;
+ case TOC_FILE:
+ if (strcmp(name, "file") == 0) {
+ if (xar->file->parent != NULL &&
+ ((xar->file->mode & AE_IFMT) == AE_IFDIR))
+ xar->file->parent->subdirs++;
+ xar->file = xar->file->parent;
+ if (xar->file == NULL)
+ xar->xmlsts = TOC;
+ }
+ break;
+ case FILE_DATA:
+ if (strcmp(name, "data") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_DATA_LENGTH:
+ if (strcmp(name, "length") == 0)
+ xar->xmlsts = FILE_DATA;
+ break;
+ case FILE_DATA_OFFSET:
+ if (strcmp(name, "offset") == 0)
+ xar->xmlsts = FILE_DATA;
+ break;
+ case FILE_DATA_SIZE:
+ if (strcmp(name, "size") == 0)
+ xar->xmlsts = FILE_DATA;
+ break;
+ case FILE_DATA_ENCODING:
+ if (strcmp(name, "encoding") == 0)
+ xar->xmlsts = FILE_DATA;
+ break;
+ case FILE_DATA_A_CHECKSUM:
+ if (strcmp(name, "archived-checksum") == 0)
+ xar->xmlsts = FILE_DATA;
+ break;
+ case FILE_DATA_E_CHECKSUM:
+ if (strcmp(name, "extracted-checksum") == 0)
+ xar->xmlsts = FILE_DATA;
+ break;
+ case FILE_DATA_CONTENT:
+ if (strcmp(name, "content") == 0)
+ xar->xmlsts = FILE_DATA;
+ break;
+ case FILE_EA:
+ if (strcmp(name, "ea") == 0) {
+ xar->xmlsts = TOC_FILE;
+ xar->xattr = NULL;
+ }
+ break;
+ case FILE_EA_LENGTH:
+ if (strcmp(name, "length") == 0)
+ xar->xmlsts = FILE_EA;
+ break;
+ case FILE_EA_OFFSET:
+ if (strcmp(name, "offset") == 0)
+ xar->xmlsts = FILE_EA;
+ break;
+ case FILE_EA_SIZE:
+ if (strcmp(name, "size") == 0)
+ xar->xmlsts = FILE_EA;
+ break;
+ case FILE_EA_ENCODING:
+ if (strcmp(name, "encoding") == 0)
+ xar->xmlsts = FILE_EA;
+ break;
+ case FILE_EA_A_CHECKSUM:
+ if (strcmp(name, "archived-checksum") == 0)
+ xar->xmlsts = FILE_EA;
+ break;
+ case FILE_EA_E_CHECKSUM:
+ if (strcmp(name, "extracted-checksum") == 0)
+ xar->xmlsts = FILE_EA;
+ break;
+ case FILE_EA_NAME:
+ if (strcmp(name, "name") == 0)
+ xar->xmlsts = FILE_EA;
+ break;
+ case FILE_EA_FSTYPE:
+ if (strcmp(name, "fstype") == 0)
+ xar->xmlsts = FILE_EA;
+ break;
+ case FILE_CTIME:
+ if (strcmp(name, "ctime") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_MTIME:
+ if (strcmp(name, "mtime") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_ATIME:
+ if (strcmp(name, "atime") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_GROUP:
+ if (strcmp(name, "group") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_GID:
+ if (strcmp(name, "gid") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_USER:
+ if (strcmp(name, "user") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_UID:
+ if (strcmp(name, "uid") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_MODE:
+ if (strcmp(name, "mode") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_DEVICE:
+ if (strcmp(name, "device") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_DEVICE_MAJOR:
+ if (strcmp(name, "major") == 0)
+ xar->xmlsts = FILE_DEVICE;
+ break;
+ case FILE_DEVICE_MINOR:
+ if (strcmp(name, "minor") == 0)
+ xar->xmlsts = FILE_DEVICE;
+ break;
+ case FILE_DEVICENO:
+ if (strcmp(name, "deviceno") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_INODE:
+ if (strcmp(name, "inode") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_LINK:
+ if (strcmp(name, "link") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_TYPE:
+ if (strcmp(name, "type") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_NAME:
+ if (strcmp(name, "name") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_ACL:
+ if (strcmp(name, "acl") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_ACL_DEFAULT:
+ if (strcmp(name, "default") == 0)
+ xar->xmlsts = FILE_ACL;
+ break;
+ case FILE_ACL_ACCESS:
+ if (strcmp(name, "access") == 0)
+ xar->xmlsts = FILE_ACL;
+ break;
+ case FILE_ACL_APPLEEXTENDED:
+ if (strcmp(name, "appleextended") == 0)
+ xar->xmlsts = FILE_ACL;
+ break;
+ case FILE_FLAGS:
+ if (strcmp(name, "flags") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_FLAGS_USER_NODUMP:
+ if (strcmp(name, "UserNoDump") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_FLAGS_USER_IMMUTABLE:
+ if (strcmp(name, "UserImmutable") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_FLAGS_USER_APPEND:
+ if (strcmp(name, "UserAppend") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_FLAGS_USER_OPAQUE:
+ if (strcmp(name, "UserOpaque") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_FLAGS_USER_NOUNLINK:
+ if (strcmp(name, "UserNoUnlink") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_FLAGS_SYS_ARCHIVED:
+ if (strcmp(name, "SystemArchived") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_FLAGS_SYS_IMMUTABLE:
+ if (strcmp(name, "SystemImmutable") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_FLAGS_SYS_APPEND:
+ if (strcmp(name, "SystemAppend") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_FLAGS_SYS_NOUNLINK:
+ if (strcmp(name, "SystemNoUnlink") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_FLAGS_SYS_SNAPSHOT:
+ if (strcmp(name, "SystemSnapshot") == 0)
+ xar->xmlsts = FILE_FLAGS;
+ break;
+ case FILE_EXT2:
+ if (strcmp(name, "ext2") == 0)
+ xar->xmlsts = TOC_FILE;
+ break;
+ case FILE_EXT2_SecureDeletion:
+ if (strcmp(name, "SecureDeletion") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_Undelete:
+ if (strcmp(name, "Undelete") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_Compress:
+ if (strcmp(name, "Compress") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_Synchronous:
+ if (strcmp(name, "Synchronous") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_Immutable:
+ if (strcmp(name, "Immutable") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_AppendOnly:
+ if (strcmp(name, "AppendOnly") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_NoDump:
+ if (strcmp(name, "NoDump") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_NoAtime:
+ if (strcmp(name, "NoAtime") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_CompDirty:
+ if (strcmp(name, "CompDirty") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_CompBlock:
+ if (strcmp(name, "CompBlock") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_NoCompBlock:
+ if (strcmp(name, "NoCompBlock") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_CompError:
+ if (strcmp(name, "CompError") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_BTree:
+ if (strcmp(name, "BTree") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_HashIndexed:
+ if (strcmp(name, "HashIndexed") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_iMagic:
+ if (strcmp(name, "iMagic") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_Journaled:
+ if (strcmp(name, "Journaled") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_NoTail:
+ if (strcmp(name, "NoTail") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_DirSync:
+ if (strcmp(name, "DirSync") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_TopDir:
+ if (strcmp(name, "TopDir") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case FILE_EXT2_Reserved:
+ if (strcmp(name, "Reserved") == 0)
+ xar->xmlsts = FILE_EXT2;
+ break;
+ case UNKNOWN:
+ unknowntag_end(xar, name);
+ break;
+ }
+}
+
+static const int base64[256] = {
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 00 - 0F */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 10 - 1F */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 62, -1, -1, -1, 63, /* 20 - 2F */
+ 52, 53, 54, 55, 56, 57, 58, 59,
+ 60, 61, -1, -1, -1, -1, -1, -1, /* 30 - 3F */
+ -1, 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14, /* 40 - 4F */
+ 15, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, -1, -1, -1, -1, -1, /* 50 - 5F */
+ -1, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35, 36, 37, 38, 39, 40, /* 60 - 6F */
+ 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, -1, -1, -1, -1, -1, /* 70 - 7F */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 80 - 8F */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 90 - 9F */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* A0 - AF */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* B0 - BF */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* C0 - CF */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* D0 - DF */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* E0 - EF */
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, /* F0 - FF */
+};
+
+static void
+strappend_base64(struct xar *xar,
+ struct archive_string *as, const char *s, size_t l)
+{
+ unsigned char buff[256];
+ unsigned char *out;
+ const unsigned char *b;
+ size_t len;
+
+ (void)xar; /* UNUSED */
+ len = 0;
+ out = buff;
+ b = (const unsigned char *)s;
+ while (l > 0) {
+ int n = 0;
+
+ if (l > 0) {
+ if (base64[b[0]] < 0 || base64[b[1]] < 0)
+ break;
+ n = base64[*b++] << 18;
+ n |= base64[*b++] << 12;
+ *out++ = n >> 16;
+ len++;
+ l -= 2;
+ }
+ if (l > 0) {
+ if (base64[*b] < 0)
+ break;
+ n |= base64[*b++] << 6;
+ *out++ = (n >> 8) & 0xFF;
+ len++;
+ --l;
+ }
+ if (l > 0) {
+ if (base64[*b] < 0)
+ break;
+ n |= base64[*b++];
+ *out++ = n & 0xFF;
+ len++;
+ --l;
+ }
+ if (len+3 >= sizeof(buff)) {
+ archive_strncat(as, (const char *)buff, len);
+ len = 0;
+ out = buff;
+ }
+ }
+ if (len > 0)
+ archive_strncat(as, (const char *)buff, len);
+}
+
+static void
+xml_data(void *userData, const char *s, int len)
+{
+ struct archive_read *a;
+ struct xar *xar;
+
+ a = (struct archive_read *)userData;
+ xar = (struct xar *)(a->format->data);
+
+#if DEBUG
+ {
+ char buff[1024];
+ if (len > sizeof(buff)-1)
+ len = sizeof(buff)-1;
+ memcpy(buff, s, len);
+ buff[len] = 0;
+ fprintf(stderr, "\tlen=%d:\"%s\"\n", len, buff);
+ }
+#endif
+ switch (xar->xmlsts) {
+ case TOC_CHECKSUM_OFFSET:
+ xar->toc_chksum_offset = atol10(s, len);
+ break;
+ case TOC_CHECKSUM_SIZE:
+ xar->toc_chksum_size = atol10(s, len);
+ break;
+ default:
+ break;
+ }
+ if (xar->file == NULL)
+ return;
+
+ switch (xar->xmlsts) {
+ case FILE_NAME:
+ if (xar->file->parent != NULL) {
+ archive_string_concat(&(xar->file->pathname),
+ &(xar->file->parent->pathname));
+ archive_strappend_char(&(xar->file->pathname), '/');
+ }
+ xar->file->has |= HAS_PATHNAME;
+ if (xar->base64text) {
+ strappend_base64(xar,
+ &(xar->file->pathname), s, len);
+ } else
+ archive_strncat(&(xar->file->pathname), s, len);
+ break;
+ case FILE_LINK:
+ xar->file->has |= HAS_SYMLINK;
+ archive_strncpy(&(xar->file->symlink), s, len);
+ break;
+ case FILE_TYPE:
+ if (strncmp("file", s, len) == 0 ||
+ strncmp("hardlink", s, len) == 0)
+ xar->file->mode =
+ (xar->file->mode & ~AE_IFMT) | AE_IFREG;
+ if (strncmp("directory", s, len) == 0)
+ xar->file->mode =
+ (xar->file->mode & ~AE_IFMT) | AE_IFDIR;
+ if (strncmp("symlink", s, len) == 0)
+ xar->file->mode =
+ (xar->file->mode & ~AE_IFMT) | AE_IFLNK;
+ if (strncmp("character special", s, len) == 0)
+ xar->file->mode =
+ (xar->file->mode & ~AE_IFMT) | AE_IFCHR;
+ if (strncmp("block special", s, len) == 0)
+ xar->file->mode =
+ (xar->file->mode & ~AE_IFMT) | AE_IFBLK;
+ if (strncmp("socket", s, len) == 0)
+ xar->file->mode =
+ (xar->file->mode & ~AE_IFMT) | AE_IFSOCK;
+ if (strncmp("fifo", s, len) == 0)
+ xar->file->mode =
+ (xar->file->mode & ~AE_IFMT) | AE_IFIFO;
+ xar->file->has |= HAS_TYPE;
+ break;
+ case FILE_INODE:
+ xar->file->has |= HAS_INO;
+ xar->file->ino64 = atol10(s, len);
+ break;
+ case FILE_DEVICE_MAJOR:
+ xar->file->has |= HAS_DEVMAJOR;
+ xar->file->devmajor = (dev_t)atol10(s, len);
+ break;
+ case FILE_DEVICE_MINOR:
+ xar->file->has |= HAS_DEVMINOR;
+ xar->file->devminor = (dev_t)atol10(s, len);
+ break;
+ case FILE_DEVICENO:
+ xar->file->has |= HAS_DEV;
+ xar->file->dev = (dev_t)atol10(s, len);
+ break;
+ case FILE_MODE:
+ xar->file->has |= HAS_MODE;
+ xar->file->mode =
+ (xar->file->mode & AE_IFMT) |
+ ((mode_t)(atol8(s, len)) & ~AE_IFMT);
+ break;
+ case FILE_GROUP:
+ xar->file->has |= HAS_GID;
+ archive_strncpy(&(xar->file->gname), s, len);
+ break;
+ case FILE_GID:
+ xar->file->has |= HAS_GID;
+ xar->file->gid = atol10(s, len);
+ break;
+ case FILE_USER:
+ xar->file->has |= HAS_UID;
+ archive_strncpy(&(xar->file->uname), s, len);
+ break;
+ case FILE_UID:
+ xar->file->has |= HAS_UID;
+ xar->file->uid = atol10(s, len);
+ break;
+ case FILE_CTIME:
+ xar->file->has |= HAS_TIME;
+ xar->file->ctime = parse_time(s, len);
+ break;
+ case FILE_MTIME:
+ xar->file->has |= HAS_TIME;
+ xar->file->mtime = parse_time(s, len);
+ break;
+ case FILE_ATIME:
+ xar->file->has |= HAS_TIME;
+ xar->file->atime = parse_time(s, len);
+ break;
+ case FILE_DATA_LENGTH:
+ xar->file->has |= HAS_DATA;
+ xar->file->length = atol10(s, len);
+ break;
+ case FILE_DATA_OFFSET:
+ xar->file->has |= HAS_DATA;
+ xar->file->offset = atol10(s, len);
+ break;
+ case FILE_DATA_SIZE:
+ xar->file->has |= HAS_DATA;
+ xar->file->size = atol10(s, len);
+ break;
+ case FILE_DATA_A_CHECKSUM:
+ xar->file->a_sum.len = atohex(xar->file->a_sum.val,
+ sizeof(xar->file->a_sum.val), s, len);
+ break;
+ case FILE_DATA_E_CHECKSUM:
+ xar->file->e_sum.len = atohex(xar->file->e_sum.val,
+ sizeof(xar->file->e_sum.val), s, len);
+ break;
+ case FILE_EA_LENGTH:
+ xar->file->has |= HAS_XATTR;
+ xar->xattr->length = atol10(s, len);
+ break;
+ case FILE_EA_OFFSET:
+ xar->file->has |= HAS_XATTR;
+ xar->xattr->offset = atol10(s, len);
+ break;
+ case FILE_EA_SIZE:
+ xar->file->has |= HAS_XATTR;
+ xar->xattr->size = atol10(s, len);
+ break;
+ case FILE_EA_A_CHECKSUM:
+ xar->file->has |= HAS_XATTR;
+ xar->xattr->a_sum.len = atohex(xar->xattr->a_sum.val,
+ sizeof(xar->xattr->a_sum.val), s, len);
+ break;
+ case FILE_EA_E_CHECKSUM:
+ xar->file->has |= HAS_XATTR;
+ xar->xattr->e_sum.len = atohex(xar->xattr->e_sum.val,
+ sizeof(xar->xattr->e_sum.val), s, len);
+ break;
+ case FILE_EA_NAME:
+ xar->file->has |= HAS_XATTR;
+ archive_strncpy(&(xar->xattr->name), s, len);
+ break;
+ case FILE_EA_FSTYPE:
+ xar->file->has |= HAS_XATTR;
+ archive_strncpy(&(xar->xattr->fstype), s, len);
+ break;
+ break;
+ case FILE_ACL_DEFAULT:
+ case FILE_ACL_ACCESS:
+ case FILE_ACL_APPLEEXTENDED:
+ xar->file->has |= HAS_ACL;
+ /* TODO */
+ break;
+ case INIT:
+ case XAR:
+ case TOC:
+ case TOC_CREATION_TIME:
+ case TOC_CHECKSUM:
+ case TOC_CHECKSUM_OFFSET:
+ case TOC_CHECKSUM_SIZE:
+ case TOC_FILE:
+ case FILE_DATA:
+ case FILE_DATA_ENCODING:
+ case FILE_DATA_CONTENT:
+ case FILE_DEVICE:
+ case FILE_EA:
+ case FILE_EA_ENCODING:
+ case FILE_ACL:
+ case FILE_FLAGS:
+ case FILE_FLAGS_USER_NODUMP:
+ case FILE_FLAGS_USER_IMMUTABLE:
+ case FILE_FLAGS_USER_APPEND:
+ case FILE_FLAGS_USER_OPAQUE:
+ case FILE_FLAGS_USER_NOUNLINK:
+ case FILE_FLAGS_SYS_ARCHIVED:
+ case FILE_FLAGS_SYS_IMMUTABLE:
+ case FILE_FLAGS_SYS_APPEND:
+ case FILE_FLAGS_SYS_NOUNLINK:
+ case FILE_FLAGS_SYS_SNAPSHOT:
+ case FILE_EXT2:
+ case FILE_EXT2_SecureDeletion:
+ case FILE_EXT2_Undelete:
+ case FILE_EXT2_Compress:
+ case FILE_EXT2_Synchronous:
+ case FILE_EXT2_Immutable:
+ case FILE_EXT2_AppendOnly:
+ case FILE_EXT2_NoDump:
+ case FILE_EXT2_NoAtime:
+ case FILE_EXT2_CompDirty:
+ case FILE_EXT2_CompBlock:
+ case FILE_EXT2_NoCompBlock:
+ case FILE_EXT2_CompError:
+ case FILE_EXT2_BTree:
+ case FILE_EXT2_HashIndexed:
+ case FILE_EXT2_iMagic:
+ case FILE_EXT2_Journaled:
+ case FILE_EXT2_NoTail:
+ case FILE_EXT2_DirSync:
+ case FILE_EXT2_TopDir:
+ case FILE_EXT2_Reserved:
+ case UNKNOWN:
+ break;
+ }
+}
+
+/*
+ * BSD file flags.
+ */
+static int
+xml_parse_file_flags(struct xar *xar, const char *name)
+{
+ const char *flag = NULL;
+
+ if (strcmp(name, "UserNoDump") == 0) {
+ xar->xmlsts = FILE_FLAGS_USER_NODUMP;
+ flag = "nodump";
+ }
+ else if (strcmp(name, "UserImmutable") == 0) {
+ xar->xmlsts = FILE_FLAGS_USER_IMMUTABLE;
+ flag = "uimmutable";
+ }
+ else if (strcmp(name, "UserAppend") == 0) {
+ xar->xmlsts = FILE_FLAGS_USER_APPEND;
+ flag = "uappend";
+ }
+ else if (strcmp(name, "UserOpaque") == 0) {
+ xar->xmlsts = FILE_FLAGS_USER_OPAQUE;
+ flag = "opaque";
+ }
+ else if (strcmp(name, "UserNoUnlink") == 0) {
+ xar->xmlsts = FILE_FLAGS_USER_NOUNLINK;
+ flag = "nouunlink";
+ }
+ else if (strcmp(name, "SystemArchived") == 0) {
+ xar->xmlsts = FILE_FLAGS_SYS_ARCHIVED;
+ flag = "archived";
+ }
+ else if (strcmp(name, "SystemImmutable") == 0) {
+ xar->xmlsts = FILE_FLAGS_SYS_IMMUTABLE;
+ flag = "simmutable";
+ }
+ else if (strcmp(name, "SystemAppend") == 0) {
+ xar->xmlsts = FILE_FLAGS_SYS_APPEND;
+ flag = "sappend";
+ }
+ else if (strcmp(name, "SystemNoUnlink") == 0) {
+ xar->xmlsts = FILE_FLAGS_SYS_NOUNLINK;
+ flag = "nosunlink";
+ }
+ else if (strcmp(name, "SystemSnapshot") == 0) {
+ xar->xmlsts = FILE_FLAGS_SYS_SNAPSHOT;
+ flag = "snapshot";
+ }
+
+ if (flag == NULL)
+ return (0);
+ xar->file->has |= HAS_FFLAGS;
+ if (archive_strlen(&(xar->file->fflags_text)) > 0)
+ archive_strappend_char(&(xar->file->fflags_text), ',');
+ archive_strcat(&(xar->file->fflags_text), flag);
+ return (1);
+}
+
+/*
+ * Linux file flags.
+ */
+static int
+xml_parse_file_ext2(struct xar *xar, const char *name)
+{
+ const char *flag = NULL;
+
+ if (strcmp(name, "SecureDeletion") == 0) {
+ xar->xmlsts = FILE_EXT2_SecureDeletion;
+ flag = "securedeletion";
+ }
+ else if (strcmp(name, "Undelete") == 0) {
+ xar->xmlsts = FILE_EXT2_Undelete;
+ flag = "nouunlink";
+ }
+ else if (strcmp(name, "Compress") == 0) {
+ xar->xmlsts = FILE_EXT2_Compress;
+ flag = "compress";
+ }
+ else if (strcmp(name, "Synchronous") == 0) {
+ xar->xmlsts = FILE_EXT2_Synchronous;
+ flag = "sync";
+ }
+ else if (strcmp(name, "Immutable") == 0) {
+ xar->xmlsts = FILE_EXT2_Immutable;
+ flag = "simmutable";
+ }
+ else if (strcmp(name, "AppendOnly") == 0) {
+ xar->xmlsts = FILE_EXT2_AppendOnly;
+ flag = "sappend";
+ }
+ else if (strcmp(name, "NoDump") == 0) {
+ xar->xmlsts = FILE_EXT2_NoDump;
+ flag = "nodump";
+ }
+ else if (strcmp(name, "NoAtime") == 0) {
+ xar->xmlsts = FILE_EXT2_NoAtime;
+ flag = "noatime";
+ }
+ else if (strcmp(name, "CompDirty") == 0) {
+ xar->xmlsts = FILE_EXT2_CompDirty;
+ flag = "compdirty";
+ }
+ else if (strcmp(name, "CompBlock") == 0) {
+ xar->xmlsts = FILE_EXT2_CompBlock;
+ flag = "comprblk";
+ }
+ else if (strcmp(name, "NoCompBlock") == 0) {
+ xar->xmlsts = FILE_EXT2_NoCompBlock;
+ flag = "nocomprblk";
+ }
+ else if (strcmp(name, "CompError") == 0) {
+ xar->xmlsts = FILE_EXT2_CompError;
+ flag = "comperr";
+ }
+ else if (strcmp(name, "BTree") == 0) {
+ xar->xmlsts = FILE_EXT2_BTree;
+ flag = "btree";
+ }
+ else if (strcmp(name, "HashIndexed") == 0) {
+ xar->xmlsts = FILE_EXT2_HashIndexed;
+ flag = "hashidx";
+ }
+ else if (strcmp(name, "iMagic") == 0) {
+ xar->xmlsts = FILE_EXT2_iMagic;
+ flag = "imagic";
+ }
+ else if (strcmp(name, "Journaled") == 0) {
+ xar->xmlsts = FILE_EXT2_Journaled;
+ flag = "journal";
+ }
+ else if (strcmp(name, "NoTail") == 0) {
+ xar->xmlsts = FILE_EXT2_NoTail;
+ flag = "notail";
+ }
+ else if (strcmp(name, "DirSync") == 0) {
+ xar->xmlsts = FILE_EXT2_DirSync;
+ flag = "dirsync";
+ }
+ else if (strcmp(name, "TopDir") == 0) {
+ xar->xmlsts = FILE_EXT2_TopDir;
+ flag = "topdir";
+ }
+ else if (strcmp(name, "Reserved") == 0) {
+ xar->xmlsts = FILE_EXT2_Reserved;
+ flag = "reserved";
+ }
+
+ if (flag == NULL)
+ return (0);
+ if (archive_strlen(&(xar->file->fflags_text)) > 0)
+ archive_strappend_char(&(xar->file->fflags_text), ',');
+ archive_strcat(&(xar->file->fflags_text), flag);
+ return (1);
+}
+
+#ifdef HAVE_LIBXML_XMLREADER_H
+
+static int
+xml2_xmlattr_setup(struct archive_read *a,
+ struct xmlattr_list *list, xmlTextReaderPtr reader)
+{
+ struct xmlattr *attr;
+ int r;
+
+ list->first = NULL;
+ list->last = &(list->first);
+ r = xmlTextReaderMoveToFirstAttribute(reader);
+ while (r == 1) {
+ attr = malloc(sizeof*(attr));
+ if (attr == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ attr->name = strdup(
+ (const char *)xmlTextReaderConstLocalName(reader));
+ if (attr->name == NULL) {
+ free(attr);
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ attr->value = strdup(
+ (const char *)xmlTextReaderConstValue(reader));
+ if (attr->value == NULL) {
+ free(attr->name);
+ free(attr);
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ attr->next = NULL;
+ *list->last = attr;
+ list->last = &(attr->next);
+ r = xmlTextReaderMoveToNextAttribute(reader);
+ }
+ return (r);
+}
+
+static int
+xml2_read_cb(void *context, char *buffer, int len)
+{
+ struct archive_read *a;
+ struct xar *xar;
+ const void *d;
+ size_t outbytes;
+ size_t used;
+ int r;
+
+ a = (struct archive_read *)context;
+ xar = (struct xar *)(a->format->data);
+
+ if (xar->toc_remaining <= 0)
+ return (0);
+ d = buffer;
+ outbytes = len;
+ r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining);
+ if (r != ARCHIVE_OK)
+ return (r);
+ __archive_read_consume(a, used);
+ xar->toc_remaining -= used;
+ xar->offset += used;
+ xar->toc_total += outbytes;
+ PRINT_TOC(buffer, len);
+
+ return ((int)outbytes);
+}
+
+static int
+xml2_close_cb(void *context)
+{
+
+ (void)context; /* UNUSED */
+ return (0);
+}
+
+static void
+xml2_error_hdr(void *arg, const char *msg, xmlParserSeverities severity,
+ xmlTextReaderLocatorPtr locator)
+{
+ struct archive_read *a;
+
+ (void)locator; /* UNUSED */
+ a = (struct archive_read *)arg;
+ switch (severity) {
+ case XML_PARSER_SEVERITY_VALIDITY_WARNING:
+ case XML_PARSER_SEVERITY_WARNING:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "XML Parsing error: %s", msg);
+ break;
+ case XML_PARSER_SEVERITY_VALIDITY_ERROR:
+ case XML_PARSER_SEVERITY_ERROR:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "XML Parsing error: %s", msg);
+ break;
+ }
+}
+
+static int
+xml2_read_toc(struct archive_read *a)
+{
+ xmlTextReaderPtr reader;
+ struct xmlattr_list list;
+ int r;
+
+ reader = xmlReaderForIO(xml2_read_cb, xml2_close_cb, a, NULL, NULL, 0);
+ if (reader == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't allocate memory for xml parser");
+ return (ARCHIVE_FATAL);
+ }
+ xmlTextReaderSetErrorHandler(reader, xml2_error_hdr, a);
+
+ while ((r = xmlTextReaderRead(reader)) == 1) {
+ const char *name, *value;
+ int type, empty;
+
+ type = xmlTextReaderNodeType(reader);
+ name = (const char *)xmlTextReaderConstLocalName(reader);
+ switch (type) {
+ 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);
+ xmlattr_cleanup(&list);
+ if (r != ARCHIVE_OK)
+ return (r);
+ if (empty)
+ xml_end(a, name);
+ break;
+ case XML_READER_TYPE_END_ELEMENT:
+ xml_end(a, name);
+ break;
+ case XML_READER_TYPE_TEXT:
+ value = (const char *)xmlTextReaderConstValue(reader);
+ xml_data(a, value, strlen(value));
+ break;
+ case XML_READER_TYPE_SIGNIFICANT_WHITESPACE:
+ default:
+ break;
+ }
+ if (r < 0)
+ break;
+ }
+ xmlFreeTextReader(reader);
+ xmlCleanupParser();
+
+ return ((r == 0)?ARCHIVE_OK:ARCHIVE_FATAL);
+}
+
+#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H)
+
+static int
+expat_xmlattr_setup(struct archive_read *a,
+ struct xmlattr_list *list, const XML_Char **atts)
+{
+ struct xmlattr *attr;
+ char *name, *value;
+
+ list->first = NULL;
+ list->last = &(list->first);
+ if (atts == NULL)
+ return (ARCHIVE_OK);
+ while (atts[0] != NULL && atts[1] != NULL) {
+ attr = malloc(sizeof*(attr));
+ name = strdup(atts[0]);
+ value = strdup(atts[1]);
+ if (attr == NULL || name == NULL || value == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ attr->name = name;
+ attr->value = value;
+ attr->next = NULL;
+ *list->last = attr;
+ list->last = &(attr->next);
+ atts += 2;
+ }
+ return (ARCHIVE_OK);
+}
+
+static void
+expat_start_cb(void *userData, const XML_Char *name, const XML_Char **atts)
+{
+ struct expat_userData *ud = (struct expat_userData *)userData;
+ struct archive_read *a = ud->archive;
+ struct xmlattr_list list;
+ int r;
+
+ r = expat_xmlattr_setup(a, &list, atts);
+ if (r == ARCHIVE_OK)
+ r = xml_start(a, (const char *)name, &list);
+ xmlattr_cleanup(&list);
+ ud->state = r;
+}
+
+static void
+expat_end_cb(void *userData, const XML_Char *name)
+{
+ struct expat_userData *ud = (struct expat_userData *)userData;
+
+ xml_end(ud->archive, (const char *)name);
+}
+
+static void
+expat_data_cb(void *userData, const XML_Char *s, int len)
+{
+ struct expat_userData *ud = (struct expat_userData *)userData;
+
+ xml_data(ud->archive, s, len);
+}
+
+static int
+expat_read_toc(struct archive_read *a)
+{
+ struct xar *xar;
+ XML_Parser parser;
+ struct expat_userData ud;
+
+ ud.state = ARCHIVE_OK;
+ ud.archive = a;
+
+ xar = (struct xar *)(a->format->data);
+
+ /* Initialize XML Parser library. */
+ parser = XML_ParserCreate(NULL);
+ if (parser == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Couldn't allocate memory for xml parser");
+ return (ARCHIVE_FATAL);
+ }
+ XML_SetUserData(parser, &ud);
+ XML_SetElementHandler(parser, expat_start_cb, expat_end_cb);
+ XML_SetCharacterDataHandler(parser, expat_data_cb);
+ xar->xmlsts = INIT;
+
+ while (xar->toc_remaining && ud.state == ARCHIVE_OK) {
+ enum XML_Status xr;
+ const void *d;
+ size_t outbytes;
+ size_t used;
+ int r;
+
+ d = NULL;
+ r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining);
+ if (r != ARCHIVE_OK)
+ return (r);
+ xar->toc_remaining -= used;
+ xar->offset += used;
+ xar->toc_total += outbytes;
+ PRINT_TOC(d, outbytes);
+
+ xr = XML_Parse(parser, d, outbytes, xar->toc_remaining == 0);
+ __archive_read_consume(a, used);
+ if (xr == XML_STATUS_ERROR) {
+ XML_ParserFree(parser);
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "XML Parsing failed");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ XML_ParserFree(parser);
+ return (ud.state);
+}
+#endif /* defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) */
+
+#endif /* Support xar format */
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c
new file mode 100644
index 0000000000..5ef29523b9
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c
@@ -0,0 +1,2176 @@
+/*-
+ * Copyright (c) 2004-2013 Tim Kientzle
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
+ * Copyright (c) 2013 Konrad Kleine
+ * 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_read_support_format_zip.c 201102 2009-12-28 03:11:36Z kientzle $");
+
+/*
+ * The definitive documentation of the Zip file format is:
+ * http://www.pkware.com/documents/casestudies/APPNOTE.TXT
+ *
+ * The Info-Zip project has pioneered various extensions to better
+ * support Zip on Unix, including the 0x5455 "UT", 0x5855 "UX", 0x7855
+ * "Ux", and 0x7875 "ux" extensions for time and ownership
+ * information.
+ *
+ * History of this code: The streaming Zip reader was first added to
+ * libarchive in January 2005. Support for seekable input sources was
+ * added in Nov 2011.
+ */
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_endian.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_rb.h"
+#include "archive_read_private.h"
+
+#ifndef HAVE_ZLIB_H
+#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;
+ int64_t local_header_offset;
+ int64_t compressed_size;
+ int64_t uncompressed_size;
+ int64_t gid;
+ int64_t uid;
+ struct archive_string rsrcname;
+ time_t mtime;
+ time_t atime;
+ time_t ctime;
+ uint32_t crc32;
+ uint16_t mode;
+ uint16_t zip_flags; /* From GP Flags Field */
+ unsigned char compression;
+ unsigned char system; /* From "version written by" */
+ unsigned char flags; /* Our extra markers. */
+};
+
+/* Bits used in zip_flags. */
+#define ZIP_ENCRYPTED (1 << 0)
+#define ZIP_LENGTH_AT_END (1 << 3)
+#define ZIP_STRONG_ENCRYPTED (1 << 6)
+#define ZIP_UTF8_NAME (1 << 11)
+/* See "7.2 Single Password Symmetric Encryption Method"
+ in http://www.pkware.com/documents/casestudies/APPNOTE.TXT */
+#define ZIP_CENTRAL_DIRECTORY_ENCRYPTED (1 << 13)
+
+/* Bits used in flags. */
+#define LA_USED_ZIP64 (1 << 0)
+#define LA_FROM_CENTRAL_DIRECTORY (1 << 1)
+
+struct zip {
+ /* Structural information about the archive. */
+ char format_name[64];
+ int64_t central_directory_offset;
+ size_t central_directory_entries_total;
+ size_t central_directory_entries_on_this_disk;
+ int has_encrypted_entries;
+
+ /* List of entries (seekable Zip only) */
+ struct zip_entry *zip_entries;
+ struct archive_rb_tree tree;
+ struct archive_rb_tree tree_rsrc;
+
+ /* Bytes read but not yet consumed via __archive_read_consume() */
+ size_t unconsumed;
+
+ /* Information about entry we're currently reading. */
+ struct zip_entry *entry;
+ int64_t entry_bytes_remaining;
+
+ /* These count the number of bytes actually read for the entry. */
+ int64_t entry_compressed_bytes_read;
+ int64_t entry_uncompressed_bytes_read;
+
+ /* Running CRC32 of the decompressed data */
+ unsigned long entry_crc32;
+ unsigned long (*crc32func)(unsigned long, const void *, size_t);
+ char ignore_crc32;
+
+ /* Flags to mark progress of decompression. */
+ char decompress_init;
+ char end_of_entry;
+
+#ifdef HAVE_ZLIB_H
+ unsigned char *uncompressed_buffer;
+ size_t uncompressed_buffer_size;
+ z_stream stream;
+ char stream_valid;
+#endif
+
+ struct archive_string_conv *sconv;
+ struct archive_string_conv *sconv_default;
+ struct archive_string_conv *sconv_utf8;
+ int init_default_conversion;
+ int process_mac_extensions;
+};
+
+/* Many systems define min or MIN, but not all. */
+#define zipmin(a,b) ((a) < (b) ? (a) : (b))
+
+/* ------------------------------------------------------------------------ */
+
+/*
+ * Common code for streaming or seeking modes.
+ *
+ * Includes code to read local file headers, decompress data
+ * from entry bodies, and common API.
+ */
+
+static unsigned long
+real_crc32(unsigned long crc, const void *buff, size_t len)
+{
+ return crc32(crc, buff, len);
+}
+
+static unsigned long
+fake_crc32(unsigned long crc, const void *buff, size_t len)
+{
+ (void)crc; /* UNUSED */
+ (void)buff; /* UNUSED */
+ (void)len; /* UNUSED */
+ return 0;
+}
+
+static struct {
+ int id;
+ const char * name;
+} compression_methods[] = {
+ {0, "uncompressed"}, /* The file is stored (no compression) */
+ {1, "shrinking"}, /* The file is Shrunk */
+ {2, "reduced-1"}, /* The file is Reduced with compression factor 1 */
+ {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 */
+ {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) */
+ {11, "reserved"}, /* Reserved by PKWARE */
+ {12, "bzip"}, /* File is compressed using BZIP2 algorithm */
+ {13, "reserved"}, /* Reserved by PKWARE */
+ {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) */
+ {97, "wav-pack"}, /* WavPack compressed data */
+ {98, "ppmd-1"} /* PPMd version I, Rev 1 */
+};
+
+static const char *
+compression_name(const int compression)
+{
+ 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) {
+ return compression_methods[i].name;
+ }
+ i++;
+ }
+ return "??";
+}
+
+/* Convert an MSDOS-style date/time into Unix-style time. */
+static time_t
+zip_time(const char *p)
+{
+ int msTime, msDate;
+ struct tm ts;
+
+ msTime = (0xff & (unsigned)p[0]) + 256 * (0xff & (unsigned)p[1]);
+ msDate = (0xff & (unsigned)p[2]) + 256 * (0xff & (unsigned)p[3]);
+
+ memset(&ts, 0, sizeof(ts));
+ ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */
+ ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */
+ ts.tm_mday = msDate & 0x1f; /* Day of month. */
+ ts.tm_hour = (msTime >> 11) & 0x1f;
+ ts.tm_min = (msTime >> 5) & 0x3f;
+ ts.tm_sec = (msTime << 1) & 0x3e;
+ ts.tm_isdst = -1;
+ return mktime(&ts);
+}
+
+/*
+ * The extra data is stored as a list of
+ * id1+size1+data1 + id2+size2+data2 ...
+ * triplets. id and size are 2 bytes each.
+ */
+static void
+process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
+{
+ unsigned offset = 0;
+
+ 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",
+ headerid, datasize);
+#endif
+ switch (headerid) {
+ case 0x0001:
+ /* Zip64 extended information extra field. */
+ zip_entry->flags |= LA_USED_ZIP64;
+ if (zip_entry->uncompressed_size == 0xffffffff) {
+ if (datasize < 8)
+ break;
+ zip_entry->uncompressed_size =
+ archive_le64dec(p + offset);
+ offset += 8;
+ datasize -= 8;
+ }
+ if (zip_entry->compressed_size == 0xffffffff) {
+ if (datasize < 8)
+ break;
+ zip_entry->compressed_size =
+ archive_le64dec(p + offset);
+ offset += 8;
+ datasize -= 8;
+ }
+ if (zip_entry->local_header_offset == 0xffffffff) {
+ if (datasize < 8)
+ break;
+ zip_entry->local_header_offset =
+ archive_le64dec(p + offset);
+ offset += 8;
+ datasize -= 8;
+ }
+ /* archive_le32dec(p + offset) gives disk
+ * on which file starts, but we don't handle
+ * multi-volume Zip files. */
+ break;
+ case 0x5455:
+ {
+ /* Extended time field "UT". */
+ int flags = p[offset];
+ offset++;
+ datasize--;
+ /* Flag bits indicate which dates are present. */
+ if (flags & 0x01)
+ {
+#ifdef DEBUG
+ fprintf(stderr, "mtime: %lld -> %d\n",
+ (long long)zip_entry->mtime,
+ archive_le32dec(p + offset));
+#endif
+ if (datasize < 4)
+ break;
+ zip_entry->mtime = archive_le32dec(p + offset);
+ offset += 4;
+ datasize -= 4;
+ }
+ if (flags & 0x02)
+ {
+ if (datasize < 4)
+ break;
+ zip_entry->atime = archive_le32dec(p + offset);
+ offset += 4;
+ datasize -= 4;
+ }
+ if (flags & 0x04)
+ {
+ if (datasize < 4)
+ break;
+ zip_entry->ctime = archive_le32dec(p + offset);
+ offset += 4;
+ datasize -= 4;
+ }
+ break;
+ }
+ case 0x5855:
+ {
+ /* Info-ZIP Unix Extra Field (old version) "UX". */
+ if (datasize >= 8) {
+ zip_entry->atime = archive_le32dec(p + offset);
+ zip_entry->mtime =
+ archive_le32dec(p + offset + 4);
+ }
+ if (datasize >= 12) {
+ zip_entry->uid =
+ archive_le16dec(p + offset + 8);
+ zip_entry->gid =
+ archive_le16dec(p + offset + 10);
+ }
+ break;
+ }
+ case 0x6c65:
+ {
+ /* Experimental 'el' 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.
+ */
+ int bitmap, bitmap_last;
+
+ if (datasize < 1)
+ break;
+ bitmap_last = bitmap = 0xff & p[offset];
+ offset += 1;
+ datasize -= 1;
+
+ /* We only support first 7 bits of bitmap; skip rest. */
+ while ((bitmap_last & 0x80) != 0
+ && datasize >= 1) {
+ bitmap_last = p[offset];
+ offset += 1;
+ datasize -= 1;
+ }
+
+ if (bitmap & 1) {
+ // 2 byte "version made by"
+ if (datasize < 2)
+ break;
+ zip_entry->system
+ = archive_le16dec(p + offset) >> 8;
+ offset += 2;
+ datasize -= 2;
+ }
+ if (bitmap & 2) {
+ // 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.
+ (void)internal_attributes; /* UNUSED */
+ offset += 2;
+ datasize -= 2;
+ }
+ if (bitmap & 4) {
+ // 4 byte "external file attributes"
+ uint32_t external_attributes;
+ if (datasize < 4)
+ break;
+ external_attributes
+ = archive_le32dec(p + offset);
+ if (zip_entry->system == 3) {
+ zip_entry->mode
+ = external_attributes >> 16;
+ }
+ offset += 4;
+ datasize -= 4;
+ }
+ if (bitmap & 8) {
+ // 2 byte comment length + comment
+ uint32_t comment_length;
+ if (datasize < 2)
+ break;
+ comment_length
+ = archive_le16dec(p + offset);
+ offset += 2;
+ datasize -= 2;
+
+ if (datasize < comment_length)
+ break;
+ // Comment is not supported by libarchive
+ offset += comment_length;
+ datasize -= comment_length;
+ }
+ break;
+ }
+ case 0x7855:
+ /* Info-ZIP Unix Extra Field (type 2) "Ux". */
+#ifdef DEBUG
+ fprintf(stderr, "uid %d gid %d\n",
+ archive_le16dec(p + offset),
+ archive_le16dec(p + offset + 2));
+#endif
+ if (datasize >= 2)
+ zip_entry->uid = archive_le16dec(p + offset);
+ if (datasize >= 4)
+ zip_entry->gid =
+ archive_le16dec(p + offset + 2);
+ break;
+ case 0x7875:
+ {
+ /* Info-Zip Unix Extra Field (type 3) "ux". */
+ int uidsize = 0, gidsize = 0;
+
+ /* TODO: support arbitrary uidsize/gidsize. */
+ if (datasize >= 1 && p[offset] == 1) {/* version=1 */
+ if (datasize >= 4) {
+ /* get a uid size. */
+ uidsize = p[offset+1];
+ if (uidsize == 2)
+ zip_entry->uid =
+ archive_le16dec(
+ p + offset + 2);
+ else if (uidsize == 4 && datasize >= 6)
+ zip_entry->uid =
+ archive_le32dec(
+ p + offset + 2);
+ }
+ if (datasize >= (2 + uidsize + 3)) {
+ /* get a gid size. */
+ gidsize = p[offset+2+uidsize];
+ if (gidsize == 2)
+ zip_entry->gid =
+ archive_le16dec(
+ p+offset+2+uidsize+1);
+ else if (gidsize == 4 &&
+ datasize >= (2 + uidsize + 5))
+ zip_entry->gid =
+ archive_le32dec(
+ p+offset+2+uidsize+1);
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ offset += datasize;
+ }
+#ifdef DEBUG
+ if (offset != extra_length)
+ {
+ fprintf(stderr,
+ "Extra data field contents do not match reported size!\n");
+ }
+#endif
+}
+
+/*
+ * Assumes file pointer is at beginning of local file header.
+ */
+static int
+zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
+ struct zip *zip)
+{
+ const char *p;
+ const void *h;
+ const wchar_t *wp;
+ const char *cp;
+ size_t len, filename_length, extra_length;
+ struct archive_string_conv *sconv;
+ struct zip_entry *zip_entry = zip->entry;
+ struct zip_entry zip_entry_central_dir;
+ int ret = ARCHIVE_OK;
+ char version;
+
+ /* Save a copy of the original for consistency checks. */
+ zip_entry_central_dir = *zip_entry;
+
+ zip->decompress_init = 0;
+ zip->end_of_entry = 0;
+ zip->entry_uncompressed_bytes_read = 0;
+ zip->entry_compressed_bytes_read = 0;
+ zip->entry_crc32 = zip->crc32func(0, NULL, 0);
+
+ /* Setup default conversion. */
+ if (zip->sconv == NULL && !zip->init_default_conversion) {
+ zip->sconv_default =
+ archive_string_default_conversion_for_read(&(a->archive));
+ zip->init_default_conversion = 1;
+ }
+
+ if ((p = __archive_read_ahead(a, 30, NULL)) == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP file header");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (memcmp(p, "PK\003\004", 4) != 0) {
+ archive_set_error(&a->archive, -1, "Damaged Zip archive");
+ return ARCHIVE_FATAL;
+ }
+ version = p[4];
+ zip_entry->system = p[5];
+ zip_entry->zip_flags = archive_le16dec(p + 6);
+ if (zip_entry->zip_flags & (ZIP_ENCRYPTED | ZIP_STRONG_ENCRYPTED)) {
+ zip->has_encrypted_entries = 1;
+ archive_entry_set_is_data_encrypted(entry, 1);
+ if (zip_entry->zip_flags & ZIP_CENTRAL_DIRECTORY_ENCRYPTED &&
+ zip_entry->zip_flags & ZIP_ENCRYPTED &&
+ zip_entry->zip_flags & ZIP_STRONG_ENCRYPTED) {
+ archive_entry_set_is_metadata_encrypted(entry, 1);
+ return ARCHIVE_FATAL;
+ }
+ }
+ zip_entry->compression = (char)archive_le16dec(p + 8);
+ zip_entry->mtime = zip_time(p + 10);
+ zip_entry->crc32 = archive_le32dec(p + 14);
+ zip_entry->compressed_size = archive_le32dec(p + 18);
+ zip_entry->uncompressed_size = archive_le32dec(p + 22);
+ filename_length = archive_le16dec(p + 26);
+ extra_length = archive_le16dec(p + 28);
+
+ __archive_read_consume(a, 30);
+
+ /* Read the filename. */
+ if ((h = __archive_read_ahead(a, filename_length, NULL)) == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP file header");
+ return (ARCHIVE_FATAL);
+ }
+ if (zip_entry->zip_flags & ZIP_UTF8_NAME) {
+ /* The filename is stored to be UTF-8. */
+ if (zip->sconv_utf8 == NULL) {
+ zip->sconv_utf8 =
+ archive_string_conversion_from_charset(
+ &a->archive, "UTF-8", 1);
+ if (zip->sconv_utf8 == NULL)
+ return (ARCHIVE_FATAL);
+ }
+ sconv = zip->sconv_utf8;
+ } else if (zip->sconv != NULL)
+ sconv = zip->sconv;
+ else
+ sconv = zip->sconv_default;
+
+ if (archive_entry_copy_pathname_l(entry,
+ h, filename_length, sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Pathname cannot be converted "
+ "from %s to current locale.",
+ archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ }
+ __archive_read_consume(a, filename_length);
+
+ /* Work around a bug in Info-Zip: When reading from a pipe, it
+ * stats the pipe instead of synthesizing a file entry. */
+ if ((zip_entry->mode & AE_IFMT) == AE_IFIFO) {
+ zip_entry->mode &= ~ AE_IFMT;
+ zip_entry->mode |= AE_IFREG;
+ }
+
+ if ((zip_entry->mode & AE_IFMT) == 0) {
+ /* Especially in streaming mode, we can end up
+ here without having seen proper mode information.
+ Guess from the filename. */
+ wp = archive_entry_pathname_w(entry);
+ if (wp != NULL) {
+ len = wcslen(wp);
+ if (len > 0 && wp[len - 1] == L'/')
+ zip_entry->mode |= AE_IFDIR;
+ else
+ zip_entry->mode |= AE_IFREG;
+ } else {
+ cp = archive_entry_pathname(entry);
+ len = (cp != NULL)?strlen(cp):0;
+ if (len > 0 && cp[len - 1] == '/')
+ zip_entry->mode |= AE_IFDIR;
+ else
+ zip_entry->mode |= AE_IFREG;
+ }
+ if (zip_entry->mode == AE_IFDIR) {
+ zip_entry->mode |= 0775;
+ } else if (zip_entry->mode == AE_IFREG) {
+ zip_entry->mode |= 0664;
+ }
+ }
+
+ /* Read the extra data. */
+ if ((h = __archive_read_ahead(a, extra_length, NULL)) == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP file header");
+ return (ARCHIVE_FATAL);
+ }
+
+ process_extra(h, extra_length, zip_entry);
+ __archive_read_consume(a, extra_length);
+
+ if (zip_entry->flags & LA_FROM_CENTRAL_DIRECTORY) {
+ /* If this came from the central dir, it's size info
+ * is definitive, so ignore the length-at-end flag. */
+ zip_entry->zip_flags &= ~ZIP_LENGTH_AT_END;
+ /* If local header is missing a value, use the one from
+ the central directory. If both have it, warn about
+ mismatches. */
+ if (zip_entry->crc32 == 0) {
+ zip_entry->crc32 = zip_entry_central_dir.crc32;
+ } else if (!zip->ignore_crc32
+ && zip_entry->crc32 != zip_entry_central_dir.crc32) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Inconsistent CRC32 values");
+ ret = ARCHIVE_WARN;
+ }
+ if (zip_entry->compressed_size == 0) {
+ zip_entry->compressed_size
+ = zip_entry_central_dir.compressed_size;
+ } else if (zip_entry->compressed_size
+ != zip_entry_central_dir.compressed_size) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Inconsistent compressed size: "
+ "%jd in central directory, %jd in local header",
+ (intmax_t)zip_entry_central_dir.compressed_size,
+ (intmax_t)zip_entry->compressed_size);
+ ret = ARCHIVE_WARN;
+ }
+ if (zip_entry->uncompressed_size == 0) {
+ zip_entry->uncompressed_size
+ = zip_entry_central_dir.uncompressed_size;
+ } else if (zip_entry->uncompressed_size
+ != zip_entry_central_dir.uncompressed_size) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Inconsistent uncompressed size: "
+ "%jd in central directory, %jd in local header",
+ (intmax_t)zip_entry_central_dir.uncompressed_size,
+ (intmax_t)zip_entry->uncompressed_size);
+ ret = ARCHIVE_WARN;
+ }
+ }
+
+ /* Populate some additional entry fields: */
+ archive_entry_set_mode(entry, zip_entry->mode);
+ archive_entry_set_uid(entry, zip_entry->uid);
+ archive_entry_set_gid(entry, zip_entry->gid);
+ archive_entry_set_mtime(entry, zip_entry->mtime, 0);
+ archive_entry_set_ctime(entry, zip_entry->ctime, 0);
+ 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;
+
+ archive_entry_set_size(entry, 0);
+ p = __archive_read_ahead(a, linkname_length, NULL);
+ if (p == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "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))
+ sconv = zip->sconv_utf8;
+ if (sconv == NULL)
+ sconv = zip->sconv_default;
+ if (archive_entry_copy_symlink_l(entry, p, linkname_length,
+ sconv) != 0) {
+ if (errno != ENOMEM && sconv == zip->sconv_utf8 &&
+ (zip->entry->zip_flags & ZIP_UTF8_NAME))
+ archive_entry_copy_symlink_l(entry, p,
+ linkname_length, NULL);
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Symlink");
+ return (ARCHIVE_FATAL);
+ }
+ /*
+ * Since there is no character-set regulation for
+ * symlink name, do not report the conversion error
+ * in an automatic conversion.
+ */
+ if (sconv != zip->sconv_utf8 ||
+ (zip->entry->zip_flags & ZIP_UTF8_NAME) == 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Symlink cannot be converted "
+ "from %s to current locale.",
+ archive_string_conversion_charset_name(
+ sconv));
+ ret = ARCHIVE_WARN;
+ }
+ }
+ zip_entry->uncompressed_size = zip_entry->compressed_size = 0;
+ } else if (0 == (zip_entry->zip_flags & ZIP_LENGTH_AT_END)
+ || zip_entry->uncompressed_size > 0) {
+ /* Set the size only if it's meaningful. */
+ archive_entry_set_size(entry, zip_entry->uncompressed_size);
+ }
+ zip->entry_bytes_remaining = zip_entry->compressed_size;
+
+ /* If there's no body, force read_data() to return EOF immediately. */
+ if (0 == (zip_entry->zip_flags & ZIP_LENGTH_AT_END)
+ && zip->entry_bytes_remaining < 1)
+ zip->end_of_entry = 1;
+
+ /* Set up a more descriptive format name. */
+ snprintf(zip->format_name, sizeof(zip->format_name), "ZIP %d.%d (%s)",
+ version / 10, version % 10,
+ compression_name(zip->entry->compression));
+ a->archive.archive_format_name = zip->format_name;
+
+ return (ret);
+}
+
+/*
+ * Read "uncompressed" data. There are three cases:
+ * 1) We know the size of the data. This is always true for the
+ * seeking reader (we've examined the Central Directory already).
+ * 2) ZIP_LENGTH_AT_END was set, but only the CRC was deferred.
+ * Info-ZIP seems to do this; we know the size but have to grab
+ * the CRC from the data descriptor afterwards.
+ * 3) We're streaming and ZIP_LENGTH_AT_END was specified and
+ * we have no size information. In this case, we can do pretty
+ * well by watching for the data descriptor record. The data
+ * descriptor is 16 bytes and includes a computed CRC that should
+ * provide a strong check.
+ *
+ * TODO: Technically, the PK\007\010 signature is optional.
+ * In the original spec, the data descriptor contained CRC
+ * and size fields but had no leading signature. In practice,
+ * newer writers seem to provide the signature pretty consistently.
+ *
+ * For uncompressed data, the PK\007\010 marker seems essential
+ * to be sure we've actually seen the end of the entry.
+ *
+ * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets
+ * zip->end_of_entry if it consumes all of the data.
+ */
+static int
+zip_read_data_none(struct archive_read *a, const void **_buff,
+ size_t *size, int64_t *offset)
+{
+ struct zip *zip;
+ const char *buff;
+ ssize_t bytes_avail;
+
+ (void)offset; /* UNUSED */
+
+ zip = (struct zip *)(a->format->data);
+
+ if (zip->entry->zip_flags & ZIP_LENGTH_AT_END) {
+ const char *p;
+
+ /* Grab at least 24 bytes. */
+ buff = __archive_read_ahead(a, 24, &bytes_avail);
+ if (bytes_avail < 24) {
+ /* 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
+ file. */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP file data");
+ return (ARCHIVE_FATAL);
+ }
+ /* Check for a complete PK\007\010 signature, followed
+ * by the correct 4-byte CRC. */
+ p = buff;
+ if (p[0] == 'P' && p[1] == 'K'
+ && p[2] == '\007' && p[3] == '\010'
+ && (archive_le32dec(p + 4) == zip->entry_crc32
+ || zip->ignore_crc32)) {
+ 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->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->unconsumed = 16;
+ }
+ zip->end_of_entry = 1;
+ return (ARCHIVE_OK);
+ }
+ /* If not at EOF, ensure we consume at least one byte. */
+ ++p;
+
+ /* Scan forward until we see where a PK\007\010 signature
+ * might be. */
+ /* Return bytes up until that point. On the next call,
+ * the code above will verify the data descriptor. */
+ while (p < buff + bytes_avail - 4) {
+ if (p[3] == 'P') { p += 3; }
+ else if (p[3] == 'K') { p += 2; }
+ else if (p[3] == '\007') { p += 1; }
+ else if (p[3] == '\010' && p[2] == '\007'
+ && p[1] == 'K' && p[0] == 'P') {
+ break;
+ } else { p += 4; }
+ }
+ bytes_avail = p - buff;
+ } else {
+ if (zip->entry_bytes_remaining == 0) {
+ zip->end_of_entry = 1;
+ return (ARCHIVE_OK);
+ }
+ /* Grab a bunch of bytes. */
+ buff = __archive_read_ahead(a, 1, &bytes_avail);
+ if (bytes_avail <= 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP file data");
+ return (ARCHIVE_FATAL);
+ }
+ if (bytes_avail > zip->entry_bytes_remaining)
+ bytes_avail = (ssize_t)zip->entry_bytes_remaining;
+ }
+ *size = bytes_avail;
+ zip->entry_bytes_remaining -= bytes_avail;
+ zip->entry_uncompressed_bytes_read += bytes_avail;
+ zip->entry_compressed_bytes_read += bytes_avail;
+ zip->unconsumed += bytes_avail;
+ *_buff = buff;
+ return (ARCHIVE_OK);
+}
+
+#ifdef HAVE_ZLIB_H
+static int
+zip_deflate_init(struct archive_read *a, struct zip *zip)
+{
+ int r;
+
+ /* If we haven't yet read any data, initialize the decompressor. */
+ if (!zip->decompress_init) {
+ if (zip->stream_valid)
+ r = inflateReset(&zip->stream);
+ else
+ r = inflateInit2(&zip->stream,
+ -15 /* Don't check for zlib header */);
+ if (r != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't initialize ZIP decompression.");
+ return (ARCHIVE_FATAL);
+ }
+ /* Stream structure has been set up. */
+ zip->stream_valid = 1;
+ /* We've initialized decompression for this stream. */
+ zip->decompress_init = 1;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+zip_read_data_deflate(struct archive_read *a, const void **buff,
+ size_t *size, int64_t *offset)
+{
+ struct zip *zip;
+ ssize_t bytes_avail;
+ const void *compressed_buff;
+ int r;
+
+ (void)offset; /* UNUSED */
+
+ zip = (struct zip *)(a->format->data);
+
+ /* If the buffer hasn't been allocated, allocate it now. */
+ if (zip->uncompressed_buffer == NULL) {
+ zip->uncompressed_buffer_size = 256 * 1024;
+ zip->uncompressed_buffer
+ = (unsigned char *)malloc(zip->uncompressed_buffer_size);
+ if (zip->uncompressed_buffer == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for ZIP decompression");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ r = zip_deflate_init(a, zip);
+ if (r != ARCHIVE_OK)
+ return (r);
+
+ /*
+ * Note: '1' here is a performance optimization.
+ * Recall that the decompression layer returns a count of
+ * 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);
+ if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END)
+ && bytes_avail > zip->entry_bytes_remaining) {
+ bytes_avail = (ssize_t)zip->entry_bytes_remaining;
+ }
+ if (bytes_avail <= 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP file body");
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * A bug in zlib.h: stream.next_in should be marked 'const'
+ * but isn't (the library never alters data through the
+ * next_in pointer, only reads it). The result: this ugly
+ * cast to remove 'const'.
+ */
+ zip->stream.next_in = (Bytef *)(uintptr_t)(const void *)compressed_buff;
+ zip->stream.avail_in = (uInt)bytes_avail;
+ zip->stream.total_in = 0;
+ zip->stream.next_out = zip->uncompressed_buffer;
+ zip->stream.avail_out = (uInt)zip->uncompressed_buffer_size;
+ zip->stream.total_out = 0;
+
+ r = inflate(&zip->stream, 0);
+ switch (r) {
+ case Z_OK:
+ break;
+ case Z_STREAM_END:
+ zip->end_of_entry = 1;
+ break;
+ case Z_MEM_ERROR:
+ archive_set_error(&a->archive, ENOMEM,
+ "Out of memory for ZIP decompression");
+ return (ARCHIVE_FATAL);
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "ZIP decompression failed (%d)", r);
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Consume as much as the compressor actually used. */
+ bytes_avail = zip->stream.total_in;
+ __archive_read_consume(a, bytes_avail);
+ zip->entry_bytes_remaining -= bytes_avail;
+ zip->entry_compressed_bytes_read += bytes_avail;
+
+ *size = zip->stream.total_out;
+ zip->entry_uncompressed_bytes_read += zip->stream.total_out;
+ *buff = zip->uncompressed_buffer;
+
+ if (zip->end_of_entry && (zip->entry->zip_flags & ZIP_LENGTH_AT_END)) {
+ const char *p;
+
+ if (NULL == (p = __archive_read_ahead(a, 24, NULL))) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP end-of-file record");
+ return (ARCHIVE_FATAL);
+ }
+ /* Consume the optional PK\007\010 marker. */
+ if (p[0] == 'P' && p[1] == 'K' &&
+ p[2] == '\007' && p[3] == '\010') {
+ p += 4;
+ zip->unconsumed = 4;
+ }
+ if (zip->entry->flags & LA_USED_ZIP64) {
+ zip->entry->crc32 = archive_le32dec(p);
+ zip->entry->compressed_size = archive_le64dec(p + 4);
+ zip->entry->uncompressed_size = archive_le64dec(p + 12);
+ zip->unconsumed += 20;
+ } else {
+ zip->entry->crc32 = archive_le32dec(p);
+ zip->entry->compressed_size = archive_le32dec(p + 4);
+ zip->entry->uncompressed_size = archive_le32dec(p + 8);
+ zip->unconsumed += 12;
+ }
+ }
+
+ return (ARCHIVE_OK);
+}
+#endif
+
+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) {
+ zip->has_encrypted_entries = 0;
+ }
+
+ *offset = zip->entry_uncompressed_bytes_read;
+ *size = 0;
+ *buff = NULL;
+
+ /* If we hit end-of-entry last time, return ARCHIVE_EOF. */
+ if (zip->end_of_entry)
+ return (ARCHIVE_EOF);
+
+ /* Return EOF immediately if this is a non-regular file. */
+ 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;
+
+ switch(zip->entry->compression) {
+ case 0: /* No compression. */
+ r = zip_read_data_none(a, buff, size, offset);
+ break;
+#ifdef HAVE_ZLIB_H
+ case 8: /* Deflate compression. */
+ r = zip_read_data_deflate(a, buff, size, offset);
+ break;
+#endif
+ default: /* Unsupported compression. */
+ /* Return a warning. */
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unsupported ZIP compression method (%s)",
+ compression_name(zip->entry->compression));
+ /* We can't decompress this entry, but we will
+ * be able to skip() it and try the next entry. */
+ return (ARCHIVE_FAILED);
+ break;
+ }
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Update checksum */
+ if (*size)
+ zip->entry_crc32 = zip->crc32func(zip->entry_crc32, *buff,
+ (unsigned)*size);
+ /* If we hit the end, swallow any end-of-data marker. */
+ if (zip->end_of_entry) {
+ /* Check file size, CRC against these values. */
+ if (zip->entry->compressed_size !=
+ zip->entry_compressed_bytes_read) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "ZIP compressed data is wrong size "
+ "(read %jd, expected %jd)",
+ (intmax_t)zip->entry_compressed_bytes_read,
+ (intmax_t)zip->entry->compressed_size);
+ return (ARCHIVE_WARN);
+ }
+ /* Size field only stores the lower 32 bits of the actual
+ * size. */
+ if ((zip->entry->uncompressed_size & UINT32_MAX)
+ != (zip->entry_uncompressed_bytes_read & UINT32_MAX)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "ZIP uncompressed data is wrong size "
+ "(read %jd, expected %jd)\n",
+ (intmax_t)zip->entry_uncompressed_bytes_read,
+ (intmax_t)zip->entry->uncompressed_size);
+ return (ARCHIVE_WARN);
+ }
+ /* Check computed CRC against header */
+ if (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",
+ (unsigned long)zip->entry_crc32,
+ (unsigned long)zip->entry->crc32);
+ return (ARCHIVE_WARN);
+ }
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_zip_cleanup(struct archive_read *a)
+{
+ struct zip *zip;
+ struct zip_entry *zip_entry, *next_zip_entry;
+
+ zip = (struct zip *)(a->format->data);
+#ifdef HAVE_ZLIB_H
+ if (zip->stream_valid)
+ inflateEnd(&zip->stream);
+ free(zip->uncompressed_buffer);
+#endif
+ if (zip->zip_entries) {
+ zip_entry = zip->zip_entries;
+ while (zip_entry != NULL) {
+ next_zip_entry = zip_entry->next;
+ archive_string_free(&zip_entry->rsrcname);
+ free(zip_entry);
+ zip_entry = next_zip_entry;
+ }
+ }
+ free(zip);
+ (a->format->data) = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_read_format_zip_has_encrypted_entries(struct archive_read *_a)
+{
+ if (_a && _a->format) {
+ struct zip * zip = (struct zip *)_a->format->data;
+ if (zip) {
+ return zip->has_encrypted_entries;
+ }
+ }
+ return ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW;
+}
+
+static int
+archive_read_format_zip_options(struct archive_read *a,
+ const char *key, const char *val)
+{
+ struct zip *zip;
+ int ret = ARCHIVE_FAILED;
+
+ zip = (struct zip *)(a->format->data);
+ if (strcmp(key, "compat-2x") == 0) {
+ /* Handle filenames as libarchive 2.x */
+ zip->init_default_conversion = (val != NULL) ? 1 : 0;
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "zip: hdrcharset option needs a character-set name"
+ );
+ else {
+ zip->sconv = archive_string_conversion_from_charset(
+ &a->archive, val, 0);
+ if (zip->sconv != NULL) {
+ if (strcmp(val, "UTF-8") == 0)
+ zip->sconv_utf8 = zip->sconv;
+ ret = ARCHIVE_OK;
+ } else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ } else if (strcmp(key, "ignorecrc32") == 0) {
+ /* Mostly useful for testing. */
+ if (val == NULL || val[0] == 0) {
+ zip->crc32func = real_crc32;
+ zip->ignore_crc32 = 0;
+ } else {
+ zip->crc32func = fake_crc32;
+ zip->ignore_crc32 = 1;
+ }
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "mac-ext") == 0) {
+ zip->process_mac_extensions = (val != NULL && val[0] != 0);
+ 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);
+}
+
+int
+archive_read_support_format_zip(struct archive *a)
+{
+ int r;
+ r = archive_read_support_format_zip_streamable(a);
+ if (r != ARCHIVE_OK)
+ return r;
+ return (archive_read_support_format_zip_seekable(a));
+}
+
+/* ------------------------------------------------------------------------ */
+
+/*
+ * Streaming-mode support
+ */
+
+
+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);
+}
+
+static int
+archive_read_format_zip_streamable_bid(struct archive_read *a, int best_bid)
+{
+ const char *p;
+
+ (void)best_bid; /* UNUSED */
+
+ if ((p = __archive_read_ahead(a, 4, NULL)) == NULL)
+ return (-1);
+
+ /*
+ * Bid of 29 here comes from:
+ * + 16 bits for "PK",
+ * + next 16-bit field has 6 options so contributes
+ * about 16 - log_2(6) ~= 16 - 2.6 ~= 13 bits
+ *
+ * So we've effectively verified ~29 total bits of check data.
+ */
+ if (p[0] == 'P' && p[1] == 'K') {
+ if ((p[2] == '\001' && p[3] == '\002')
+ || (p[2] == '\003' && p[3] == '\004')
+ || (p[2] == '\005' && p[3] == '\006')
+ || (p[2] == '\006' && p[3] == '\006')
+ || (p[2] == '\007' && p[3] == '\010')
+ || (p[2] == '0' && p[3] == '0'))
+ return (29);
+ }
+
+ /* TODO: It's worth looking ahead a little bit for a valid
+ * PK signature. In particular, that would make it possible
+ * to read some UUEncoded SFX files or SFX files coming from
+ * a network socket. */
+
+ return (0);
+}
+
+static int
+archive_read_format_zip_streamable_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ struct zip *zip;
+
+ a->archive.archive_format = ARCHIVE_FORMAT_ZIP;
+ if (a->archive.archive_format_name == NULL)
+ a->archive.archive_format_name = "ZIP";
+
+ zip = (struct zip *)(a->format->data);
+
+ /*
+ * It should be sufficient to call archive_read_next_header() for
+ * a reader to determine if an entry is encrypted or not. If the
+ * encryption of an entry is only detectable when calling
+ * 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) {
+ zip->has_encrypted_entries = 0;
+ }
+
+ /* Make sure we have a zip_entry structure to use. */
+ if (zip->zip_entries == NULL) {
+ zip->zip_entries = malloc(sizeof(struct zip_entry));
+ if (zip->zip_entries == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Out of memory");
+ return ARCHIVE_FATAL;
+ }
+ }
+ zip->entry = zip->zip_entries;
+ memset(zip->entry, 0, sizeof(struct zip_entry));
+
+ /* Search ahead for the next local file header. */
+ __archive_read_consume(a, zip->unconsumed);
+ zip->unconsumed = 0;
+ for (;;) {
+ int64_t skipped = 0;
+ const char *p, *end;
+ ssize_t bytes;
+
+ p = __archive_read_ahead(a, 4, &bytes);
+ if (p == NULL)
+ return (ARCHIVE_FATAL);
+ end = p + bytes;
+
+ while (p + 4 <= end) {
+ if (p[0] == 'P' && p[1] == 'K') {
+ if (p[2] == '\003' && p[3] == '\004') {
+ /* Regular file entry. */
+ __archive_read_consume(a, skipped);
+ return zip_read_local_file_header(a,
+ entry, zip);
+ }
+
+ /*
+ * TODO: We cannot restore permissions
+ * based only on the local file headers.
+ * Consider scanning the central
+ * directory and returning additional
+ * entries for at least directories.
+ * This would allow us to properly set
+ * directory permissions.
+ *
+ * This won't help us fix symlinks
+ * and may not help with regular file
+ * permissions, either. <sigh>
+ */
+ if (p[2] == '\001' && p[3] == '\002') {
+ return (ARCHIVE_EOF);
+ }
+
+ /* End of central directory? Must be an
+ * empty archive. */
+ if ((p[2] == '\005' && p[3] == '\006')
+ || (p[2] == '\006' && p[3] == '\006'))
+ return (ARCHIVE_EOF);
+ }
+ ++p;
+ ++skipped;
+ }
+ __archive_read_consume(a, skipped);
+ }
+}
+
+static int
+archive_read_format_zip_read_data_skip_streamable(struct archive_read *a)
+{
+ struct zip *zip;
+ int64_t bytes_skipped;
+
+ zip = (struct zip *)(a->format->data);
+ bytes_skipped = __archive_read_consume(a, zip->unconsumed);
+ zip->unconsumed = 0;
+ if (bytes_skipped < 0)
+ return (ARCHIVE_FATAL);
+
+ /* If we've already read to end of data, we're done. */
+ if (zip->end_of_entry)
+ return (ARCHIVE_OK);
+
+ /* So we know we're streaming... */
+ 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);
+ if (bytes_skipped < 0)
+ return (ARCHIVE_FATAL);
+ return (ARCHIVE_OK);
+ }
+
+ /* 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. */
+ switch (zip->entry->compression) {
+#ifdef HAVE_ZLIB_H
+ case 8: /* Deflate compression. */
+ while (!zip->end_of_entry) {
+ int64_t offset = 0;
+ const void *buff = NULL;
+ size_t size = 0;
+ int r;
+ r = zip_read_data_deflate(a, &buff, &size, &offset);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+ return ARCHIVE_OK;
+#endif
+ default: /* Uncompressed or unknown. */
+ /* Scan for a PK\007\010 signature. */
+ for (;;) {
+ const char *p, *buff;
+ ssize_t bytes_avail;
+ buff = __archive_read_ahead(a, 16, &bytes_avail);
+ if (bytes_avail < 16) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP file data");
+ return (ARCHIVE_FATAL);
+ }
+ p = buff;
+ while (p <= buff + bytes_avail - 16) {
+ if (p[3] == 'P') { p += 3; }
+ else if (p[3] == 'K') { p += 2; }
+ else if (p[3] == '\007') { p += 1; }
+ 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);
+ else
+ __archive_read_consume(a, p - buff + 16);
+ return ARCHIVE_OK;
+ } else { p += 4; }
+ }
+ __archive_read_consume(a, p - buff);
+ }
+ }
+}
+
+int
+archive_read_support_format_zip_streamable(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct zip *zip;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_zip");
+
+ zip = (struct zip *)malloc(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;
+
+ /*
+ * Until enough data has been read, we cannot tell about
+ * any encrypted entries yet.
+ */
+ zip->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW;
+ zip->crc32func = real_crc32;
+
+ r = __archive_read_register_format(a,
+ zip,
+ "zip",
+ archive_read_format_zip_streamable_bid,
+ archive_read_format_zip_options,
+ archive_read_format_zip_streamable_read_header,
+ archive_read_format_zip_read_data,
+ archive_read_format_zip_read_data_skip_streamable,
+ NULL,
+ archive_read_format_zip_cleanup,
+ archive_read_support_format_zip_capabilities_streamable,
+ archive_read_format_zip_has_encrypted_entries);
+
+ if (r != ARCHIVE_OK)
+ free(zip);
+ return (ARCHIVE_OK);
+}
+
+/* ------------------------------------------------------------------------ */
+
+/*
+ * Seeking-mode support
+ */
+
+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);
+}
+
+/*
+ * TODO: This is a performance sink because it forces the read core to
+ * drop buffered data from the start of file, which will then have to
+ * be re-read again if this bidder loses.
+ *
+ * We workaround this a little by passing in the best bid so far so
+ * that later bidders can do nothing if they know they'll never
+ * outbid. But we can certainly do better...
+ */
+static int
+read_eocd(struct zip *zip, const char *p, int64_t current_offset)
+{
+ /* Sanity-check the EOCD we've found. */
+
+ /* This must be the first volume. */
+ if (archive_le16dec(p + 4) != 0)
+ return 0;
+ /* Central directory must be on this volume. */
+ if (archive_le16dec(p + 4) != archive_le16dec(p + 6))
+ return 0;
+ /* All central directory entries must be on this volume. */
+ if (archive_le16dec(p + 10) != archive_le16dec(p + 8))
+ return 0;
+ /* Central directory can't extend beyond start of EOCD record. */
+ if (archive_le32dec(p + 16) + archive_le32dec(p + 12)
+ > current_offset)
+ return 0;
+
+ /* Save the central directory location for later use. */
+ zip->central_directory_offset = archive_le32dec(p + 16);
+
+ /* This is just a tiny bit higher than the maximum
+ returned by the streaming Zip bidder. This ensures
+ that the more accurate seeking Zip parser wins
+ whenever seek is available. */
+ return 32;
+}
+
+static int
+read_zip64_eocd(struct archive_read *a, struct zip *zip, const char *p)
+{
+ int64_t eocd64_offset;
+ int64_t eocd64_size;
+
+ /* Sanity-check the locator record. */
+
+ /* Central dir must be on first volume. */
+ if (archive_le32dec(p + 4) != 0)
+ return 0;
+ /* Must be only a single volume. */
+ if (archive_le32dec(p + 16) != 1)
+ return 0;
+
+ /* Find the Zip64 EOCD record. */
+ eocd64_offset = archive_le64dec(p + 8);
+ if (__archive_read_seek(a, eocd64_offset, SEEK_SET) < 0)
+ return 0;
+ if ((p = __archive_read_ahead(a, 56, NULL)) == NULL)
+ return 0;
+ /* 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;
+
+ /* Sanity-check the EOCD64 */
+ if (archive_le32dec(p + 16) != 0) /* Must be disk #0 */
+ return 0;
+ if (archive_le32dec(p + 20) != 0) /* CD must be on disk #0 */
+ return 0;
+ /* CD can't be split. */
+ if (archive_le64dec(p + 24) != archive_le64dec(p + 32))
+ return 0;
+
+ /* Save the central directory offset for later use. */
+ zip->central_directory_offset = archive_le64dec(p + 48);
+
+ return 32;
+}
+
+static int
+archive_read_format_zip_seekable_bid(struct archive_read *a, int best_bid)
+{
+ struct zip *zip = (struct zip *)a->format->data;
+ int64_t file_size, current_offset;
+ const char *p;
+ int i, tail;
+
+ /* If someone has already bid more than 32, then avoid
+ trashing the look-ahead buffers with a seek. */
+ if (best_bid > 32)
+ return (-1);
+
+ file_size = __archive_read_seek(a, 0, SEEK_END);
+ if (file_size <= 0)
+ 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);
+ 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:
+ 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)
+ return (ret);
+ }
+ i += 4;
+ break;
+ default: i += 4; break;
+ }
+ }
+ return 0;
+}
+
+/* The red-black trees are only used in seeking mode to manage
+ * the in-memory copy of the central directory. */
+
+static int
+cmp_node(const struct archive_rb_node *n1, const struct archive_rb_node *n2)
+{
+ const struct zip_entry *e1 = (const struct zip_entry *)n1;
+ const struct zip_entry *e2 = (const struct zip_entry *)n2;
+
+ if (e1->local_header_offset > e2->local_header_offset)
+ return -1;
+ if (e1->local_header_offset < e2->local_header_offset)
+ return 1;
+ return 0;
+}
+
+static int
+cmp_key(const struct archive_rb_node *n, const void *key)
+{
+ /* This function won't be called */
+ (void)n; /* UNUSED */
+ (void)key; /* UNUSED */
+ return 1;
+}
+
+static const struct archive_rb_tree_ops rb_ops = {
+ &cmp_node, &cmp_key
+};
+
+static int
+rsrc_cmp_node(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ const struct zip_entry *e1 = (const struct zip_entry *)n1;
+ const struct zip_entry *e2 = (const struct zip_entry *)n2;
+
+ return (strcmp(e2->rsrcname.s, e1->rsrcname.s));
+}
+
+static int
+rsrc_cmp_key(const struct archive_rb_node *n, const void *key)
+{
+ const struct zip_entry *e = (const struct zip_entry *)n;
+ return (strcmp((const char *)key, e->rsrcname.s));
+}
+
+static const struct archive_rb_tree_ops rb_rsrc_ops = {
+ &rsrc_cmp_node, &rsrc_cmp_key
+};
+
+static const char *
+rsrc_basename(const char *name, size_t name_length)
+{
+ const char *s, *r;
+
+ r = s = name;
+ for (;;) {
+ s = memchr(s, '/', name_length - (s - name));
+ if (s == NULL)
+ break;
+ r = ++s;
+ }
+ return (r);
+}
+
+static void
+expose_parent_dirs(struct zip *zip, const char *name, size_t name_length)
+{
+ struct archive_string str;
+ struct zip_entry *dir;
+ char *s;
+
+ archive_string_init(&str);
+ archive_strncpy(&str, name, name_length);
+ for (;;) {
+ s = strrchr(str.s, '/');
+ if (s == NULL)
+ break;
+ *s = '\0';
+ /* Transfer the parent directory from zip->tree_rsrc RB
+ * tree to zip->tree RB tree to expose. */
+ dir = (struct zip_entry *)
+ __archive_rb_tree_find_node(&zip->tree_rsrc, str.s);
+ if (dir == NULL)
+ break;
+ __archive_rb_tree_remove_node(&zip->tree_rsrc, &dir->node);
+ archive_string_free(&dir->rsrcname);
+ __archive_rb_tree_insert_node(&zip->tree, &dir->node);
+ }
+ archive_string_free(&str);
+}
+
+static int
+slurp_central_directory(struct archive_read *a, struct zip *zip)
+{
+ ssize_t i;
+ unsigned found;
+ int64_t correction;
+ ssize_t bytes_avail;
+ const char *p;
+
+ /*
+ * Find the start of the central directory. The end-of-CD
+ * record has our starting point, but there are lots of
+ * Zip archives which have had other data prepended to the
+ * file, which makes the recorded offsets all too small.
+ * So we search forward from the specified offset until we
+ * find the real start of the central directory. Then we
+ * know the correction we need to apply to account for leading
+ * padding.
+ */
+ if (__archive_read_seek(a, zip->central_directory_offset, SEEK_SET) < 0)
+ return ARCHIVE_FATAL;
+
+ found = 0;
+ while (!found) {
+ if ((p = __archive_read_ahead(a, 20, &bytes_avail)) == NULL)
+ return ARCHIVE_FATAL;
+ for (found = 0, i = 0; !found && i < bytes_avail - 4;) {
+ switch (p[i + 3]) {
+ case 'P': i += 3; break;
+ case 'K': i += 2; break;
+ case 001: i += 1; break;
+ case 002:
+ if (memcmp(p + i, "PK\001\002", 4) == 0) {
+ p += i;
+ found = 1;
+ } else
+ i += 4;
+ break;
+ case 005: i += 1; break;
+ case 006:
+ if (memcmp(p + i, "PK\005\006", 4) == 0) {
+ p += i;
+ found = 1;
+ } else if (memcmp(p + i, "PK\006\006", 4) == 0) {
+ p += i;
+ found = 1;
+ } else
+ i += 1;
+ break;
+ default: i += 4; break;
+ }
+ }
+ __archive_read_consume(a, i);
+ }
+ 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);
+
+ zip->central_directory_entries_total = 0;
+ while (1) {
+ struct zip_entry *zip_entry;
+ size_t filename_length, extra_length, comment_length;
+ uint32_t external_attributes;
+ const char *name, *r;
+
+ if ((p = __archive_read_ahead(a, 4, NULL)) == NULL)
+ return ARCHIVE_FATAL;
+ if (memcmp(p, "PK\006\006", 4) == 0
+ || memcmp(p, "PK\005\006", 4) == 0) {
+ break;
+ } else if (memcmp(p, "PK\001\002", 4) != 0) {
+ archive_set_error(&a->archive,
+ -1, "Invalid central directory signature");
+ return ARCHIVE_FATAL;
+ }
+ if ((p = __archive_read_ahead(a, 46, NULL)) == NULL)
+ return ARCHIVE_FATAL;
+
+ zip_entry = calloc(1, sizeof(struct zip_entry));
+ zip_entry->next = zip->zip_entries;
+ zip_entry->flags |= LA_FROM_CENTRAL_DIRECTORY;
+ zip->zip_entries = zip_entry;
+ zip->central_directory_entries_total++;
+
+ /* version = p[4]; */
+ 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)){
+ 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);
+ zip_entry->compressed_size = archive_le32dec(p + 20);
+ zip_entry->uncompressed_size = archive_le32dec(p + 24);
+ filename_length = archive_le16dec(p + 28);
+ extra_length = archive_le16dec(p + 30);
+ comment_length = archive_le16dec(p + 32);
+ /* disk_start = archive_le16dec(p + 34); */ /* Better be zero. */
+ /* internal_attributes = archive_le16dec(p + 36); */ /* text bit */
+ external_attributes = archive_le32dec(p + 38);
+ zip_entry->local_header_offset =
+ archive_le32dec(p + 42) + correction;
+
+ /* If we can't guess the mode, leave it zero here;
+ when we read the local file header we might get
+ more information. */
+ zip_entry->mode = 0;
+ if (zip_entry->system == 3) {
+ zip_entry->mode = external_attributes >> 16;
+ }
+
+ /* 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,
+ "Truncated ZIP file header");
+ return ARCHIVE_FATAL;
+ }
+ process_extra(p + filename_length, extra_length, zip_entry);
+
+ /*
+ * Mac resource fork files are stored under the
+ * "__MACOSX/" directory, so we should check if
+ * it is.
+ */
+ if (!zip->process_mac_extensions) {
+ /* Treat every entry as a regular entry. */
+ __archive_rb_tree_insert_node(&zip->tree,
+ &zip_entry->node);
+ } else {
+ name = p;
+ r = rsrc_basename(name, filename_length);
+ if (filename_length >= 9 &&
+ strncmp("__MACOSX/", name, 9) == 0) {
+ /* If this file is not a resource fork nor
+ * a directory. We should treat it as a non
+ * 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);
+ /* Expose its parent directories. */
+ 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);
+ }
+ } 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);
+ archive_strcat(&(zip_entry->rsrcname), "._");
+ archive_strncat(&(zip_entry->rsrcname),
+ 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,
+ &zip_entry->node);
+ }
+ }
+
+ /* Skip the comment too ... */
+ __archive_read_consume(a,
+ filename_length + extra_length + comment_length);
+ }
+
+ return ARCHIVE_OK;
+}
+
+static ssize_t
+zip_get_local_file_header_size(struct archive_read *a, size_t extra)
+{
+ const char *p;
+ ssize_t filename_length, extra_length;
+
+ if ((p = __archive_read_ahead(a, extra + 30, NULL)) == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP file header");
+ return (ARCHIVE_WARN);
+ }
+ p += extra;
+
+ if (memcmp(p, "PK\003\004", 4) != 0) {
+ archive_set_error(&a->archive, -1, "Damaged Zip archive");
+ return ARCHIVE_WARN;
+ }
+ filename_length = archive_le16dec(p + 26);
+ extra_length = archive_le16dec(p + 28);
+
+ return (30 + filename_length + extra_length);
+}
+
+static int
+zip_read_mac_metadata(struct archive_read *a, struct archive_entry *entry,
+ struct zip_entry *rsrc)
+{
+ struct zip *zip = (struct zip *)a->format->data;
+ unsigned char *metadata, *mp;
+ int64_t offset = archive_filter_bytes(&a->archive, 0);
+ size_t remaining_bytes, metadata_bytes;
+ ssize_t hsize;
+ int ret = ARCHIVE_OK, eof;
+
+ switch(rsrc->compression) {
+ case 0: /* No compression. */
+#ifdef HAVE_ZLIB_H
+ case 8: /* Deflate compression. */
+#endif
+ break;
+ default: /* Unsupported compression. */
+ /* Return a warning. */
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Unsupported ZIP compression method (%s)",
+ compression_name(rsrc->compression));
+ /* We can't decompress this entry, but we will
+ * be able to skip() it and try the next entry. */
+ return (ARCHIVE_WARN);
+ }
+
+ if (rsrc->uncompressed_size > (4 * 1024 * 1024)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Mac metadata is too large: %jd > 4M bytes",
+ (intmax_t)rsrc->uncompressed_size);
+ return (ARCHIVE_WARN);
+ }
+
+ metadata = malloc((size_t)rsrc->uncompressed_size);
+ if (metadata == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Mac metadata");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (offset < rsrc->local_header_offset)
+ __archive_read_consume(a, rsrc->local_header_offset - offset);
+ else if (offset != rsrc->local_header_offset) {
+ __archive_read_seek(a, rsrc->local_header_offset, SEEK_SET);
+ }
+
+ hsize = zip_get_local_file_header_size(a, 0);
+ __archive_read_consume(a, hsize);
+
+ remaining_bytes = (size_t)rsrc->compressed_size;
+ metadata_bytes = (size_t)rsrc->uncompressed_size;
+ mp = metadata;
+ eof = 0;
+ while (!eof && remaining_bytes) {
+ const unsigned char *p;
+ ssize_t bytes_avail;
+ size_t bytes_used;
+
+ p = __archive_read_ahead(a, 1, &bytes_avail);
+ if (p == NULL) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Truncated ZIP file header");
+ ret = ARCHIVE_WARN;
+ goto exit_mac_metadata;
+ }
+ if ((size_t)bytes_avail > remaining_bytes)
+ bytes_avail = remaining_bytes;
+ switch(rsrc->compression) {
+ case 0: /* No compression. */
+ memcpy(mp, p, bytes_avail);
+ bytes_used = (size_t)bytes_avail;
+ metadata_bytes -= bytes_used;
+ mp += bytes_used;
+ if (metadata_bytes == 0)
+ eof = 1;
+ break;
+#ifdef HAVE_ZLIB_H
+ case 8: /* Deflate compression. */
+ {
+ int r;
+
+ ret = zip_deflate_init(a, zip);
+ if (ret != ARCHIVE_OK)
+ goto exit_mac_metadata;
+ zip->stream.next_in =
+ (Bytef *)(uintptr_t)(const void *)p;
+ zip->stream.avail_in = (uInt)bytes_avail;
+ zip->stream.total_in = 0;
+ zip->stream.next_out = mp;
+ zip->stream.avail_out = (uInt)metadata_bytes;
+ zip->stream.total_out = 0;
+
+ r = inflate(&zip->stream, 0);
+ switch (r) {
+ case Z_OK:
+ break;
+ case Z_STREAM_END:
+ eof = 1;
+ break;
+ case Z_MEM_ERROR:
+ archive_set_error(&a->archive, ENOMEM,
+ "Out of memory for ZIP decompression");
+ ret = ARCHIVE_FATAL;
+ goto exit_mac_metadata;
+ default:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "ZIP decompression failed (%d)", r);
+ ret = ARCHIVE_FATAL;
+ goto exit_mac_metadata;
+ }
+ bytes_used = zip->stream.total_in;
+ metadata_bytes -= zip->stream.total_out;
+ mp += zip->stream.total_out;
+ break;
+ }
+#endif
+ default:
+ bytes_used = 0;
+ break;
+ }
+ __archive_read_consume(a, bytes_used);
+ remaining_bytes -= bytes_used;
+ }
+ archive_entry_copy_mac_metadata(entry, metadata,
+ (size_t)rsrc->uncompressed_size - metadata_bytes);
+
+exit_mac_metadata:
+ __archive_read_seek(a, offset, SEEK_SET);
+ zip->decompress_init = 0;
+ free(metadata);
+ return (ret);
+}
+
+static int
+archive_read_format_zip_seekable_read_header(struct archive_read *a,
+ struct archive_entry *entry)
+{
+ struct zip *zip = (struct zip *)a->format->data;
+ struct zip_entry *rsrc;
+ int64_t offset;
+ int r, ret = ARCHIVE_OK;
+
+ /*
+ * It should be sufficient to call archive_read_next_header() for
+ * a reader to determine if an entry is encrypted or not. If the
+ * encryption of an entry is only detectable when calling
+ * 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) {
+ zip->has_encrypted_entries = 0;
+ }
+
+ a->archive.archive_format = ARCHIVE_FORMAT_ZIP;
+ if (a->archive.archive_format_name == NULL)
+ a->archive.archive_format_name = "ZIP";
+
+ if (zip->zip_entries == NULL) {
+ r = slurp_central_directory(a, zip);
+ if (r != ARCHIVE_OK)
+ return r;
+ /* Get first entry whose local header offset is lower than
+ * other entries in the archive file. */
+ zip->entry =
+ (struct zip_entry *)ARCHIVE_RB_TREE_MIN(&zip->tree);
+ } else if (zip->entry != NULL) {
+ /* Get next entry in local header offset order. */
+ zip->entry = (struct zip_entry *)__archive_rb_tree_iterate(
+ &zip->tree, &zip->entry->node, ARCHIVE_RB_DIR_RIGHT);
+ }
+
+ if (zip->entry == NULL)
+ return ARCHIVE_EOF;
+
+ if (zip->entry->rsrcname.s)
+ rsrc = (struct zip_entry *)__archive_rb_tree_find_node(
+ &zip->tree_rsrc, zip->entry->rsrcname.s);
+ else
+ rsrc = NULL;
+
+ /* 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. */
+ offset = archive_filter_bytes(&a->archive, 0);
+ if (offset < zip->entry->local_header_offset)
+ __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);
+ }
+ zip->unconsumed = 0;
+ r = zip_read_local_file_header(a, entry, zip);
+ if (r != ARCHIVE_OK)
+ return r;
+ if (rsrc) {
+ int ret2 = zip_read_mac_metadata(a, entry, rsrc);
+ if (ret2 < ret)
+ ret = ret2;
+ }
+ return (ret);
+}
+
+/*
+ * We're going to seek for the next header anyway, so we don't
+ * need to bother doing anything here.
+ */
+static int
+archive_read_format_zip_read_data_skip_seekable(struct archive_read *a)
+{
+ struct zip *zip;
+ zip = (struct zip *)(a->format->data);
+
+ zip->unconsumed = 0;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_read_support_format_zip_seekable(struct archive *_a)
+{
+ struct archive_read *a = (struct archive_read *)_a;
+ struct zip *zip;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_zip_seekable");
+
+ zip = (struct zip *)malloc(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. */
+ zip->process_mac_extensions = 1;
+#endif
+
+ /*
+ * Until enough data has been read, we cannot tell about
+ * any encrypted entries yet.
+ */
+ zip->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW;
+ zip->crc32func = real_crc32;
+
+ r = __archive_read_register_format(a,
+ zip,
+ "zip",
+ archive_read_format_zip_seekable_bid,
+ archive_read_format_zip_options,
+ archive_read_format_zip_seekable_read_header,
+ archive_read_format_zip_read_data,
+ archive_read_format_zip_read_data_skip_seekable,
+ NULL,
+ archive_read_format_zip_cleanup,
+ archive_read_support_format_zip_capabilities_seekable,
+ archive_read_format_zip_has_encrypted_entries);
+
+ if (r != ARCHIVE_OK)
+ free(zip);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_string.c b/Utilities/cmlibarchive/libarchive/archive_string.c
new file mode 100644
index 0000000000..87f9288f19
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_string.c
@@ -0,0 +1,4211 @@
+/*-
+ * Copyright (c) 2003-2011 Tim Kientzle
+ * Copyright (c) 2011-2012 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: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33:22Z kientzle $");
+
+/*
+ * Basic resizable string support, to simplify manipulating arbitrary-sized
+ * strings while minimizing heap activity.
+ *
+ * In particular, the buffer used by a string object is only grown, it
+ * never shrinks, so you can clear and reuse the same string object
+ * without incurring additional memory allocations.
+ */
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_ICONV_H
+#include <iconv.h>
+#endif
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#ifdef HAVE_LOCALCHARSET_H
+#include <localcharset.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <windows.h>
+#include <locale.h>
+#endif
+
+#include "archive_endian.h"
+#include "archive_private.h"
+#include "archive_string.h"
+#include "archive_string_composition.h"
+
+#if !defined(HAVE_WMEMCPY) && !defined(wmemcpy)
+#define wmemcpy(a,b,i) (wchar_t *)memcpy((a), (b), (i) * sizeof(wchar_t))
+#endif
+
+struct archive_string_conv {
+ struct archive_string_conv *next;
+ char *from_charset;
+ char *to_charset;
+ unsigned from_cp;
+ unsigned to_cp;
+ /* Set 1 if from_charset and to_charset are the same. */
+ int same;
+ int flag;
+#define SCONV_TO_CHARSET 1 /* MBS is being converted to specified
+ * charset. */
+#define SCONV_FROM_CHARSET (1<<1) /* MBS is being converted from
+ * specified charset. */
+#define SCONV_BEST_EFFORT (1<<2) /* Copy at least ASCII code. */
+#define SCONV_WIN_CP (1<<3) /* Use Windows API for converting
+ * MBS. */
+#define SCONV_UTF8_LIBARCHIVE_2 (1<<4) /* Incorrect UTF-8 made by libarchive
+ * 2.x in the wrong assumption. */
+#define SCONV_NORMALIZATION_C (1<<6) /* Need normalization to be Form C.
+ * Before UTF-8 characters are actually
+ * processed. */
+#define SCONV_NORMALIZATION_D (1<<7) /* Need normalization to be Form D.
+ * Before UTF-8 characters are actually
+ * processed.
+ * Currently this only for MAC OS X. */
+#define SCONV_TO_UTF8 (1<<8) /* "to charset" side is UTF-8. */
+#define SCONV_FROM_UTF8 (1<<9) /* "from charset" side is UTF-8. */
+#define SCONV_TO_UTF16BE (1<<10) /* "to charset" side is UTF-16BE. */
+#define SCONV_FROM_UTF16BE (1<<11) /* "from charset" side is UTF-16BE. */
+#define SCONV_TO_UTF16LE (1<<12) /* "to charset" side is UTF-16LE. */
+#define SCONV_FROM_UTF16LE (1<<13) /* "from charset" side is UTF-16LE. */
+#define SCONV_TO_UTF16 (SCONV_TO_UTF16BE | SCONV_TO_UTF16LE)
+#define SCONV_FROM_UTF16 (SCONV_FROM_UTF16BE | SCONV_FROM_UTF16LE)
+
+#if HAVE_ICONV
+ iconv_t cd;
+ iconv_t cd_w;/* Use at archive_mstring on
+ * Windows. */
+#endif
+ /* A temporary buffer for normalization. */
+ struct archive_string utftmp;
+ int (*converter[2])(struct archive_string *, const void *, size_t,
+ struct archive_string_conv *);
+ int nconverter;
+};
+
+#define CP_C_LOCALE 0 /* "C" locale only for this file. */
+#define CP_UTF16LE 1200
+#define CP_UTF16BE 1201
+
+#define IS_HIGH_SURROGATE_LA(uc) ((uc) >= 0xD800 && (uc) <= 0xDBFF)
+#define IS_LOW_SURROGATE_LA(uc) ((uc) >= 0xDC00 && (uc) <= 0xDFFF)
+#define IS_SURROGATE_PAIR_LA(uc) ((uc) >= 0xD800 && (uc) <= 0xDFFF)
+#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 struct archive_string_conv *find_sconv_object(struct archive *,
+ const char *, const char *);
+static void add_sconv_object(struct archive *, struct archive_string_conv *);
+static struct archive_string_conv *create_sconv_object(const char *,
+ const char *, unsigned, int);
+static void free_sconv_object(struct archive_string_conv *);
+static struct archive_string_conv *get_sconv_object(struct archive *,
+ const char *, const char *, int);
+static unsigned make_codepage_from_charset(const char *);
+static unsigned get_current_codepage(void);
+static unsigned get_current_oemcp(void);
+static size_t mbsnbytes(const void *, size_t);
+static size_t utf16nbytes(const void *, size_t);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+static int archive_wstring_append_from_mbs_in_codepage(
+ struct archive_wstring *, const char *, size_t,
+ struct archive_string_conv *);
+static int archive_string_append_from_wcs_in_codepage(struct archive_string *,
+ const wchar_t *, size_t, struct archive_string_conv *);
+static int is_big_endian(void);
+static int strncat_in_codepage(struct archive_string *, const void *,
+ size_t, struct archive_string_conv *);
+static int win_strncat_from_utf16be(struct archive_string *, const void *,
+ size_t, struct archive_string_conv *);
+static int win_strncat_from_utf16le(struct archive_string *, const void *,
+ size_t, struct archive_string_conv *);
+static int win_strncat_to_utf16be(struct archive_string *, const void *,
+ size_t, struct archive_string_conv *);
+static int win_strncat_to_utf16le(struct archive_string *, const void *,
+ size_t, struct archive_string_conv *);
+#endif
+static int best_effort_strncat_from_utf16be(struct archive_string *,
+ const void *, size_t, struct archive_string_conv *);
+static int best_effort_strncat_from_utf16le(struct archive_string *,
+ const void *, size_t, struct archive_string_conv *);
+static int best_effort_strncat_to_utf16be(struct archive_string *,
+ const void *, size_t, struct archive_string_conv *);
+static int best_effort_strncat_to_utf16le(struct archive_string *,
+ const void *, size_t, struct archive_string_conv *);
+#if defined(HAVE_ICONV)
+static int iconv_strncat_in_locale(struct archive_string *, const void *,
+ size_t, struct archive_string_conv *);
+#endif
+static int best_effort_strncat_in_locale(struct archive_string *,
+ const void *, size_t, struct archive_string_conv *);
+static int _utf8_to_unicode(uint32_t *, const char *, size_t);
+static int utf8_to_unicode(uint32_t *, const char *, size_t);
+static inline uint32_t combine_surrogate_pair(uint32_t, uint32_t);
+static int cesu8_to_unicode(uint32_t *, const char *, size_t);
+static size_t unicode_to_utf8(char *, size_t, uint32_t);
+static int utf16_to_unicode(uint32_t *, const char *, size_t, int);
+static size_t unicode_to_utf16be(char *, size_t, uint32_t);
+static size_t unicode_to_utf16le(char *, size_t, uint32_t);
+static int strncat_from_utf8_libarchive2(struct archive_string *,
+ const void *, size_t, struct archive_string_conv *);
+static int strncat_from_utf8_to_utf8(struct archive_string *, const void *,
+ size_t, struct archive_string_conv *);
+static int archive_string_normalize_C(struct archive_string *, const void *,
+ size_t, struct archive_string_conv *);
+static int archive_string_normalize_D(struct archive_string *, const void *,
+ size_t, struct archive_string_conv *);
+static int archive_string_append_unicode(struct archive_string *,
+ const void *, size_t, struct archive_string_conv *);
+
+static struct archive_string *
+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);
+ as->length += s;
+ as->s[as->length] = 0;
+ return (as);
+}
+
+static struct archive_wstring *
+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);
+ as->length += s;
+ as->s[as->length] = 0;
+ return (as);
+}
+
+void
+archive_string_concat(struct archive_string *dest, struct archive_string *src)
+{
+ if (archive_string_append(dest, src->s, src->length) == NULL)
+ __archive_errx(1, "Out of memory");
+}
+
+void
+archive_wstring_concat(struct archive_wstring *dest,
+ struct archive_wstring *src)
+{
+ if (archive_wstring_append(dest, src->s, src->length) == NULL)
+ __archive_errx(1, "Out of memory");
+}
+
+void
+archive_string_free(struct archive_string *as)
+{
+ as->length = 0;
+ as->buffer_length = 0;
+ free(as->s);
+ as->s = NULL;
+}
+
+void
+archive_wstring_free(struct archive_wstring *as)
+{
+ as->length = 0;
+ as->buffer_length = 0;
+ free(as->s);
+ as->s = NULL;
+}
+
+struct archive_wstring *
+archive_wstring_ensure(struct archive_wstring *as, size_t s)
+{
+ return (struct archive_wstring *)
+ archive_string_ensure((struct archive_string *)as,
+ s * sizeof(wchar_t));
+}
+
+/* Returns NULL on any allocation failure. */
+struct archive_string *
+archive_string_ensure(struct archive_string *as, size_t s)
+{
+ char *p;
+ size_t new_length;
+
+ /* If buffer is already big enough, don't reallocate. */
+ if (as->s && (s <= as->buffer_length))
+ return (as);
+
+ /*
+ * Growing the buffer at least exponentially ensures that
+ * append operations are always linear in the number of
+ * characters appended. Using a smaller growth rate for
+ * larger buffers reduces memory waste somewhat at the cost of
+ * a larger constant factor.
+ */
+ if (as->buffer_length < 32)
+ /* Start with a minimum 32-character buffer. */
+ new_length = 32;
+ else if (as->buffer_length < 8192)
+ /* Buffers under 8k are doubled for speed. */
+ new_length = as->buffer_length + as->buffer_length;
+ else {
+ /* Buffers 8k and over grow by at least 25% each time. */
+ new_length = as->buffer_length + as->buffer_length / 4;
+ /* Be safe: If size wraps, fail. */
+ if (new_length < as->buffer_length) {
+ /* On failure, wipe the string and return NULL. */
+ archive_string_free(as);
+ errno = ENOMEM;/* Make sure errno has ENOMEM. */
+ return (NULL);
+ }
+ }
+ /*
+ * The computation above is a lower limit to how much we'll
+ * grow the buffer. In any case, we have to grow it enough to
+ * hold the request.
+ */
+ if (new_length < s)
+ new_length = s;
+ /* Now we can reallocate the buffer. */
+ p = (char *)realloc(as->s, new_length);
+ if (p == NULL) {
+ /* On failure, wipe the string and return NULL. */
+ archive_string_free(as);
+ errno = ENOMEM;/* Make sure errno has ENOMEM. */
+ return (NULL);
+ }
+
+ as->s = p;
+ as->buffer_length = new_length;
+ return (as);
+}
+
+/*
+ * TODO: See if there's a way to avoid scanning
+ * the source string twice. Then test to see
+ * if it actually helps (remember that we're almost
+ * always called with pretty short arguments, so
+ * such an optimization might not help).
+ */
+struct archive_string *
+archive_strncat(struct archive_string *as, const void *_p, size_t n)
+{
+ size_t s;
+ const char *p, *pp;
+
+ p = (const char *)_p;
+
+ /* Like strlen(p), except won't examine positions beyond p[n]. */
+ s = 0;
+ pp = p;
+ while (s < n && *pp) {
+ pp++;
+ s++;
+ }
+ if ((as = archive_string_append(as, p, s)) == NULL)
+ __archive_errx(1, "Out of memory");
+ return (as);
+}
+
+struct archive_wstring *
+archive_wstrncat(struct archive_wstring *as, const wchar_t *p, size_t n)
+{
+ size_t s;
+ const wchar_t *pp;
+
+ /* Like strlen(p), except won't examine positions beyond p[n]. */
+ s = 0;
+ pp = p;
+ while (s < n && *pp) {
+ pp++;
+ s++;
+ }
+ if ((as = archive_wstring_append(as, p, s)) == NULL)
+ __archive_errx(1, "Out of memory");
+ return (as);
+}
+
+struct archive_string *
+archive_strcat(struct archive_string *as, const void *p)
+{
+ /* strcat is just strncat without an effective limit.
+ * Assert that we'll never get called with a source
+ * string over 16MB.
+ * TODO: Review all uses of strcat in the source
+ * and try to replace them with strncat().
+ */
+ return archive_strncat(as, p, 0x1000000);
+}
+
+struct archive_wstring *
+archive_wstrcat(struct archive_wstring *as, const wchar_t *p)
+{
+ /* Ditto. */
+ return archive_wstrncat(as, p, 0x1000000);
+}
+
+struct archive_string *
+archive_strappend_char(struct archive_string *as, char c)
+{
+ if ((as = archive_string_append(as, &c, 1)) == NULL)
+ __archive_errx(1, "Out of memory");
+ return (as);
+}
+
+struct archive_wstring *
+archive_wstrappend_wchar(struct archive_wstring *as, wchar_t c)
+{
+ if ((as = archive_wstring_append(as, &c, 1)) == NULL)
+ __archive_errx(1, "Out of memory");
+ return (as);
+}
+
+/*
+ * Get the "current character set" name to use with iconv.
+ * On FreeBSD, the empty character set name "" chooses
+ * the correct character encoding for the current locale,
+ * so this isn't necessary.
+ * But iconv on Mac OS 10.6 doesn't seem to handle this correctly;
+ * on that system, we have to explicitly call nl_langinfo()
+ * to get the right name. Not sure about other platforms.
+ *
+ * NOTE: GNU libiconv does not recognize the character-set name
+ * which some platform nl_langinfo(CODESET) returns, so we should
+ * use locale_charset() instead of nl_langinfo(CODESET) for GNU libiconv.
+ */
+static const char *
+default_iconv_charset(const char *charset) {
+ if (charset != NULL && charset[0] != '\0')
+ return charset;
+#if HAVE_LOCALE_CHARSET && !defined(__APPLE__)
+ /* locale_charset() is broken on Mac OS */
+ return locale_charset();
+#elif HAVE_NL_LANGINFO
+ return nl_langinfo(CODESET);
+#else
+ return "";
+#endif
+}
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+/*
+ * Convert MBS to WCS.
+ * Note: returns -1 if conversion fails.
+ */
+int
+archive_wstring_append_from_mbs(struct archive_wstring *dest,
+ const char *p, size_t len)
+{
+ return archive_wstring_append_from_mbs_in_codepage(dest, p, len, NULL);
+}
+
+static int
+archive_wstring_append_from_mbs_in_codepage(struct archive_wstring *dest,
+ const char *s, size_t length, struct archive_string_conv *sc)
+{
+ int count, ret = 0;
+ UINT from_cp;
+
+ if (sc != NULL)
+ from_cp = sc->from_cp;
+ else
+ from_cp = get_current_codepage();
+
+ if (from_cp == CP_C_LOCALE) {
+ /*
+ * "C" locale special process.
+ */
+ wchar_t *ws;
+ const unsigned char *mp;
+
+ if (NULL == archive_wstring_ensure(dest,
+ dest->length + length + 1))
+ return (-1);
+
+ ws = dest->s + dest->length;
+ mp = (const unsigned char *)s;
+ count = 0;
+ while (count < (int)length && *mp) {
+ *ws++ = (wchar_t)*mp++;
+ count++;
+ }
+ } else if (sc != NULL &&
+ (sc->flag & (SCONV_NORMALIZATION_C | SCONV_NORMALIZATION_D))) {
+ /*
+ * Normalize UTF-8 and UTF-16BE and convert it directly
+ * to UTF-16 as wchar_t.
+ */
+ struct archive_string u16;
+ int saved_flag = sc->flag;/* save current flag. */
+
+ if (is_big_endian())
+ sc->flag |= SCONV_TO_UTF16BE;
+ else
+ sc->flag |= SCONV_TO_UTF16LE;
+
+ if (sc->flag & SCONV_FROM_UTF16) {
+ /*
+ * UTF-16BE/LE NFD ===> UTF-16 NFC
+ * UTF-16BE/LE NFC ===> UTF-16 NFD
+ */
+ count = (int)utf16nbytes(s, length);
+ } else {
+ /*
+ * UTF-8 NFD ===> UTF-16 NFC
+ * UTF-8 NFC ===> UTF-16 NFD
+ */
+ count = (int)mbsnbytes(s, length);
+ }
+ u16.s = (char *)dest->s;
+ u16.length = dest->length << 1;;
+ u16.buffer_length = dest->buffer_length;
+ if (sc->flag & SCONV_NORMALIZATION_C)
+ ret = archive_string_normalize_C(&u16, s, count, sc);
+ else
+ ret = archive_string_normalize_D(&u16, s, count, sc);
+ dest->s = (wchar_t *)u16.s;
+ dest->length = u16.length >> 1;
+ dest->buffer_length = u16.buffer_length;
+ sc->flag = saved_flag;/* restore the saved flag. */
+ return (ret);
+ } else if (sc != NULL && (sc->flag & SCONV_FROM_UTF16)) {
+ count = (int)utf16nbytes(s, length);
+ count >>= 1; /* to be WCS length */
+ /* Allocate memory for WCS. */
+ if (NULL == archive_wstring_ensure(dest,
+ dest->length + count + 1))
+ return (-1);
+ wmemcpy(dest->s + dest->length, (const wchar_t *)s, count);
+ if ((sc->flag & SCONV_FROM_UTF16BE) && !is_big_endian()) {
+ uint16_t *u16 = (uint16_t *)(dest->s + dest->length);
+ int b;
+ for (b = 0; b < count; b++) {
+ uint16_t val = archive_le16dec(u16+b);
+ archive_be16enc(u16+b, val);
+ }
+ } else if ((sc->flag & SCONV_FROM_UTF16LE) && is_big_endian()) {
+ uint16_t *u16 = (uint16_t *)(dest->s + dest->length);
+ int b;
+ for (b = 0; b < count; b++) {
+ uint16_t val = archive_be16dec(u16+b);
+ archive_le16enc(u16+b, val);
+ }
+ }
+ } else {
+ DWORD mbflag;
+ size_t buffsize;
+
+ if (sc == NULL)
+ mbflag = 0;
+ else if (sc->flag & SCONV_FROM_CHARSET) {
+ /* Do not trust the length which comes from
+ * an archive file. */
+ length = mbsnbytes(s, length);
+ mbflag = 0;
+ } else
+ mbflag = MB_PRECOMPOSED;
+
+ buffsize = dest->length + length + 1;
+ do {
+ /* Allocate memory for WCS. */
+ if (NULL == archive_wstring_ensure(dest, buffsize))
+ return (-1);
+ /* Convert MBS to WCS. */
+ count = MultiByteToWideChar(from_cp,
+ mbflag, s, (int)length, dest->s + dest->length,
+ (int)(dest->buffer_length >> 1) -1);
+ if (count == 0 &&
+ GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ /* Expand the WCS buffer. */
+ buffsize = dest->buffer_length << 1;
+ continue;
+ }
+ if (count == 0 && length != 0)
+ ret = -1;
+ } while (0);
+ }
+ dest->length += count;
+ dest->s[dest->length] = L'\0';
+ return (ret);
+}
+
+#else
+
+/*
+ * Convert MBS to WCS.
+ * Note: returns -1 if conversion fails.
+ */
+int
+archive_wstring_append_from_mbs(struct archive_wstring *dest,
+ const char *p, size_t len)
+{
+ size_t r;
+ int ret_val = 0;
+ /*
+ * No single byte will be more than one wide character,
+ * so this length estimate will always be big enough.
+ */
+ size_t wcs_length = len;
+ size_t mbs_length = len;
+ const char *mbs = p;
+ wchar_t *wcs;
+#if HAVE_MBRTOWC
+ mbstate_t shift_state;
+
+ memset(&shift_state, 0, sizeof(shift_state));
+#endif
+ if (NULL == archive_wstring_ensure(dest, dest->length + wcs_length + 1))
+ return (-1);
+ wcs = dest->s + dest->length;
+ /*
+ * We cannot use mbsrtowcs/mbstowcs here because those may convert
+ * extra MBS when strlen(p) > len and one wide character consis of
+ * multi bytes.
+ */
+ while (*mbs && mbs_length > 0) {
+ if (wcs_length == 0) {
+ dest->length = wcs - dest->s;
+ dest->s[dest->length] = L'\0';
+ wcs_length = mbs_length;
+ if (NULL == archive_wstring_ensure(dest,
+ dest->length + wcs_length + 1))
+ return (-1);
+ wcs = dest->s + dest->length;
+ }
+#if HAVE_MBRTOWC
+ r = mbrtowc(wcs, mbs, wcs_length, &shift_state);
+#else
+ r = mbtowc(wcs, mbs, wcs_length);
+#endif
+ if (r == (size_t)-1 || r == (size_t)-2) {
+ ret_val = -1;
+ if (errno == EILSEQ) {
+ ++mbs;
+ --mbs_length;
+ continue;
+ } else
+ break;
+ }
+ if (r == 0 || r > mbs_length)
+ break;
+ wcs++;
+ wcs_length--;
+ mbs += r;
+ mbs_length -= r;
+ }
+ dest->length = wcs - dest->s;
+ dest->s[dest->length] = L'\0';
+ return (ret_val);
+}
+
+#endif
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+/*
+ * WCS ==> MBS.
+ * Note: returns -1 if conversion fails.
+ *
+ * Win32 builds use WideCharToMultiByte from the Windows API.
+ * (Maybe Cygwin should too? WideCharToMultiByte will know a
+ * lot more about local character encodings than the wcrtomb()
+ * wrapper is going to know.)
+ */
+int
+archive_string_append_from_wcs(struct archive_string *as,
+ const wchar_t *w, size_t len)
+{
+ return archive_string_append_from_wcs_in_codepage(as, w, len, NULL);
+}
+
+static int
+archive_string_append_from_wcs_in_codepage(struct archive_string *as,
+ const wchar_t *ws, size_t len, struct archive_string_conv *sc)
+{
+ BOOL defchar_used, *dp;
+ int count, ret = 0;
+ UINT to_cp;
+ int wslen = (int)len;
+
+ if (sc != NULL)
+ to_cp = sc->to_cp;
+ else
+ to_cp = get_current_codepage();
+
+ if (to_cp == CP_C_LOCALE) {
+ /*
+ * "C" locale special process.
+ */
+ const wchar_t *wp = ws;
+ char *p;
+
+ if (NULL == archive_string_ensure(as,
+ as->length + wslen +1))
+ return (-1);
+ p = as->s + as->length;
+ count = 0;
+ defchar_used = 0;
+ while (count < wslen && *wp) {
+ if (*wp > 255) {
+ *p++ = '?';
+ wp++;
+ defchar_used = 1;
+ } else
+ *p++ = (char)*wp++;
+ count++;
+ }
+ } else if (sc != NULL && (sc->flag & SCONV_TO_UTF16)) {
+ uint16_t *u16;
+
+ if (NULL ==
+ archive_string_ensure(as, as->length + len * 2 + 2))
+ return (-1);
+ u16 = (uint16_t *)(as->s + as->length);
+ count = 0;
+ defchar_used = 0;
+ if (sc->flag & SCONV_TO_UTF16BE) {
+ while (count < (int)len && *ws) {
+ archive_be16enc(u16+count, *ws);
+ ws++;
+ count++;
+ }
+ } else {
+ while (count < (int)len && *ws) {
+ archive_le16enc(u16+count, *ws);
+ ws++;
+ count++;
+ }
+ }
+ count <<= 1; /* to be byte size */
+ } else {
+ /* Make sure the MBS buffer has plenty to set. */
+ if (NULL ==
+ archive_string_ensure(as, as->length + len * 2 + 1))
+ return (-1);
+ do {
+ defchar_used = 0;
+ if (to_cp == CP_UTF8 || sc == NULL)
+ dp = NULL;
+ else
+ dp = &defchar_used;
+ count = WideCharToMultiByte(to_cp, 0, ws, wslen,
+ as->s + as->length, (int)as->buffer_length-1, NULL, dp);
+ if (count == 0 &&
+ GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ /* Expand the MBS buffer and retry. */
+ if (NULL == archive_string_ensure(as,
+ as->buffer_length + len))
+ return (-1);
+ continue;
+ }
+ if (count == 0)
+ ret = -1;
+ } while (0);
+ }
+ as->length += count;
+ as->s[as->length] = '\0';
+ return (defchar_used?-1:ret);
+}
+
+#elif defined(HAVE_WCTOMB) || defined(HAVE_WCRTOMB)
+
+/*
+ * Translates a wide character string into current locale character set
+ * and appends to the archive_string. Note: returns -1 if conversion
+ * fails.
+ */
+int
+archive_string_append_from_wcs(struct archive_string *as,
+ const wchar_t *w, size_t len)
+{
+ /* We cannot use the standard wcstombs() here because it
+ * cannot tell us how big the output buffer should be. So
+ * I've built a loop around wcrtomb() or wctomb() that
+ * converts a character at a time and resizes the string as
+ * needed. We prefer wcrtomb() when it's available because
+ * it's thread-safe. */
+ int n, ret_val = 0;
+ char *p;
+ char *end;
+#if HAVE_WCRTOMB
+ mbstate_t shift_state;
+
+ memset(&shift_state, 0, sizeof(shift_state));
+#else
+ /* Clear the shift state before starting. */
+ wctomb(NULL, L'\0');
+#endif
+ /*
+ * Allocate buffer for MBS.
+ * We need this allocation here since it is possible that
+ * as->s is still NULL.
+ */
+ if (archive_string_ensure(as, as->length + len + 1) == NULL)
+ return (-1);
+
+ p = as->s + as->length;
+ end = as->s + as->buffer_length - MB_CUR_MAX -1;
+ while (*w != L'\0' && len > 0) {
+ if (p >= end) {
+ as->length = p - as->s;
+ as->s[as->length] = '\0';
+ /* Re-allocate buffer for MBS. */
+ if (archive_string_ensure(as,
+ as->length + len * 2 + 1) == NULL)
+ return (-1);
+ p = as->s + as->length;
+ end = as->s + as->buffer_length - MB_CUR_MAX -1;
+ }
+#if HAVE_WCRTOMB
+ n = wcrtomb(p, *w++, &shift_state);
+#else
+ n = wctomb(p, *w++);
+#endif
+ if (n == -1) {
+ if (errno == EILSEQ) {
+ /* Skip an illegal wide char. */
+ *p++ = '?';
+ ret_val = -1;
+ } else {
+ ret_val = -1;
+ break;
+ }
+ } else
+ p += n;
+ len--;
+ }
+ as->length = p - as->s;
+ as->s[as->length] = '\0';
+ return (ret_val);
+}
+
+#else /* HAVE_WCTOMB || HAVE_WCRTOMB */
+
+/*
+ * TODO: Test if __STDC_ISO_10646__ is defined.
+ * Non-Windows uses ISO C wcrtomb() or wctomb() to perform the conversion
+ * one character at a time. If a non-Windows platform doesn't have
+ * either of these, fall back to the built-in UTF8 conversion.
+ */
+int
+archive_string_append_from_wcs(struct archive_string *as,
+ const wchar_t *w, size_t len)
+{
+ (void)as;/* UNUSED */
+ (void)w;/* UNUSED */
+ (void)len;/* UNUSED */
+ errno = ENOSYS;
+ return (-1);
+}
+
+#endif /* HAVE_WCTOMB || HAVE_WCRTOMB */
+
+/*
+ * Find a string conversion object by a pair of 'from' charset name
+ * and 'to' charset name from an archive object.
+ * Return NULL if not found.
+ */
+static struct archive_string_conv *
+find_sconv_object(struct archive *a, const char *fc, const char *tc)
+{
+ struct archive_string_conv *sc;
+
+ if (a == NULL)
+ return (NULL);
+
+ for (sc = a->sconv; sc != NULL; sc = sc->next) {
+ if (strcmp(sc->from_charset, fc) == 0 &&
+ strcmp(sc->to_charset, tc) == 0)
+ break;
+ }
+ return (sc);
+}
+
+/*
+ * Register a string object to an archive object.
+ */
+static void
+add_sconv_object(struct archive *a, struct archive_string_conv *sc)
+{
+ struct archive_string_conv **psc;
+
+ /* Add a new sconv to sconv list. */
+ psc = &(a->sconv);
+ while (*psc != NULL)
+ psc = &((*psc)->next);
+ *psc = sc;
+}
+
+static void
+add_converter(struct archive_string_conv *sc, int (*converter)
+ (struct archive_string *, const void *, size_t,
+ struct archive_string_conv *))
+{
+ if (sc == NULL || sc->nconverter >= 2)
+ __archive_errx(1, "Programing error");
+ sc->converter[sc->nconverter++] = converter;
+}
+
+static void
+setup_converter(struct archive_string_conv *sc)
+{
+
+ /* Reset. */
+ sc->nconverter = 0;
+
+ /*
+ * Perform special sequence for the incorrect UTF-8 filenames
+ * made by libarchive2.x.
+ */
+ if (sc->flag & SCONV_UTF8_LIBARCHIVE_2) {
+ add_converter(sc, strncat_from_utf8_libarchive2);
+ return;
+ }
+
+ /*
+ * Convert a string to UTF-16BE/LE.
+ */
+ if (sc->flag & SCONV_TO_UTF16) {
+ /*
+ * If the current locale is UTF-8, we can translate
+ * a UTF-8 string into a UTF-16BE string.
+ */
+ if (sc->flag & SCONV_FROM_UTF8) {
+ add_converter(sc, archive_string_append_unicode);
+ return;
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (sc->flag & SCONV_WIN_CP) {
+ if (sc->flag & SCONV_TO_UTF16BE)
+ add_converter(sc, win_strncat_to_utf16be);
+ else
+ add_converter(sc, win_strncat_to_utf16le);
+ return;
+ }
+#endif
+
+#if defined(HAVE_ICONV)
+ if (sc->cd != (iconv_t)-1) {
+ add_converter(sc, iconv_strncat_in_locale);
+ return;
+ }
+#endif
+
+ if (sc->flag & SCONV_BEST_EFFORT) {
+ if (sc->flag & SCONV_TO_UTF16BE)
+ add_converter(sc,
+ best_effort_strncat_to_utf16be);
+ else
+ add_converter(sc,
+ best_effort_strncat_to_utf16le);
+ } else
+ /* Make sure we have no converter. */
+ sc->nconverter = 0;
+ return;
+ }
+
+ /*
+ * Convert a string from UTF-16BE/LE.
+ */
+ if (sc->flag & SCONV_FROM_UTF16) {
+ /*
+ * At least we should normalize a UTF-16BE string.
+ */
+ if (sc->flag & SCONV_NORMALIZATION_D)
+ add_converter(sc,archive_string_normalize_D);
+ else if (sc->flag & SCONV_NORMALIZATION_C)
+ add_converter(sc, archive_string_normalize_C);
+
+ if (sc->flag & SCONV_TO_UTF8) {
+ /*
+ * If the current locale is UTF-8, we can translate
+ * a UTF-16BE/LE string into a UTF-8 string directly.
+ */
+ if (!(sc->flag &
+ (SCONV_NORMALIZATION_D |SCONV_NORMALIZATION_C)))
+ add_converter(sc,
+ archive_string_append_unicode);
+ return;
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (sc->flag & SCONV_WIN_CP) {
+ if (sc->flag & SCONV_FROM_UTF16BE)
+ add_converter(sc, win_strncat_from_utf16be);
+ else
+ add_converter(sc, win_strncat_from_utf16le);
+ return;
+ }
+#endif
+
+#if defined(HAVE_ICONV)
+ if (sc->cd != (iconv_t)-1) {
+ add_converter(sc, iconv_strncat_in_locale);
+ return;
+ }
+#endif
+
+ if ((sc->flag & (SCONV_BEST_EFFORT | SCONV_FROM_UTF16BE))
+ == (SCONV_BEST_EFFORT | SCONV_FROM_UTF16BE))
+ add_converter(sc, best_effort_strncat_from_utf16be);
+ else if ((sc->flag & (SCONV_BEST_EFFORT | SCONV_FROM_UTF16LE))
+ == (SCONV_BEST_EFFORT | SCONV_FROM_UTF16LE))
+ add_converter(sc, best_effort_strncat_from_utf16le);
+ else
+ /* Make sure we have no converter. */
+ sc->nconverter = 0;
+ return;
+ }
+
+ if (sc->flag & SCONV_FROM_UTF8) {
+ /*
+ * At least we should normalize a UTF-8 string.
+ */
+ if (sc->flag & SCONV_NORMALIZATION_D)
+ add_converter(sc,archive_string_normalize_D);
+ else if (sc->flag & SCONV_NORMALIZATION_C)
+ add_converter(sc, archive_string_normalize_C);
+
+ /*
+ * Copy UTF-8 string with a check of CESU-8.
+ * Apparently, iconv does not check surrogate pairs in UTF-8
+ * when both from-charset and to-charset are UTF-8, and then
+ * we use our UTF-8 copy code.
+ */
+ if (sc->flag & SCONV_TO_UTF8) {
+ /*
+ * If the current locale is UTF-8, we can translate
+ * a UTF-16BE string into a UTF-8 string directly.
+ */
+ if (!(sc->flag &
+ (SCONV_NORMALIZATION_D |SCONV_NORMALIZATION_C)))
+ add_converter(sc, strncat_from_utf8_to_utf8);
+ return;
+ }
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /*
+ * On Windows we can use Windows API for a string conversion.
+ */
+ if (sc->flag & SCONV_WIN_CP) {
+ add_converter(sc, strncat_in_codepage);
+ return;
+ }
+#endif
+
+#if HAVE_ICONV
+ if (sc->cd != (iconv_t)-1) {
+ add_converter(sc, iconv_strncat_in_locale);
+ /*
+ * iconv generally does not support UTF-8-MAC and so
+ * we have to the output of iconv from NFC to NFD if
+ * need.
+ */
+ if ((sc->flag & SCONV_FROM_CHARSET) &&
+ (sc->flag & SCONV_TO_UTF8)) {
+ if (sc->flag & SCONV_NORMALIZATION_D)
+ add_converter(sc, archive_string_normalize_D);
+ }
+ return;
+ }
+#endif
+
+ /*
+ * Try conversion in the best effort or no conversion.
+ */
+ if ((sc->flag & SCONV_BEST_EFFORT) || sc->same)
+ add_converter(sc, best_effort_strncat_in_locale);
+ else
+ /* Make sure we have no converter. */
+ sc->nconverter = 0;
+}
+
+/*
+ * Return canonicalized charset-name but this supports just UTF-8, UTF-16BE
+ * and CP932 which are referenced in create_sconv_object().
+ */
+static const char *
+canonical_charset_name(const char *charset)
+{
+ char cs[16];
+ char *p;
+ const char *s;
+
+ if (charset == NULL || charset[0] == '\0'
+ || strlen(charset) > 15)
+ return (charset);
+
+ /* Copy name to uppercase. */
+ p = cs;
+ s = charset;
+ while (*s) {
+ char c = *s++;
+ if (c >= 'a' && c <= 'z')
+ c -= 'a' - 'A';
+ *p++ = c;
+ }
+ *p++ = '\0';
+
+ if (strcmp(cs, "UTF-8") == 0 ||
+ strcmp(cs, "UTF8") == 0)
+ return ("UTF-8");
+ if (strcmp(cs, "UTF-16BE") == 0 ||
+ strcmp(cs, "UTF16BE") == 0)
+ return ("UTF-16BE");
+ if (strcmp(cs, "UTF-16LE") == 0 ||
+ strcmp(cs, "UTF16LE") == 0)
+ return ("UTF-16LE");
+ if (strcmp(cs, "CP932") == 0)
+ return ("CP932");
+ return (charset);
+}
+
+/*
+ * Create a string conversion object.
+ */
+static struct archive_string_conv *
+create_sconv_object(const char *fc, const char *tc,
+ unsigned current_codepage, int flag)
+{
+ struct archive_string_conv *sc;
+
+ sc = calloc(1, sizeof(*sc));
+ if (sc == NULL)
+ return (NULL);
+ sc->next = NULL;
+ sc->from_charset = strdup(fc);
+ if (sc->from_charset == NULL) {
+ free(sc);
+ return (NULL);
+ }
+ sc->to_charset = strdup(tc);
+ if (sc->to_charset == NULL) {
+ free(sc->from_charset);
+ free(sc);
+ return (NULL);
+ }
+ archive_string_init(&sc->utftmp);
+
+ if (flag & SCONV_TO_CHARSET) {
+ /*
+ * Convert characters from the current locale charset to
+ * a specified charset.
+ */
+ sc->from_cp = current_codepage;
+ sc->to_cp = make_codepage_from_charset(tc);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (IsValidCodePage(sc->to_cp))
+ flag |= SCONV_WIN_CP;
+#endif
+ } else if (flag & SCONV_FROM_CHARSET) {
+ /*
+ * Convert characters from a specified charset to
+ * the current locale charset.
+ */
+ sc->to_cp = current_codepage;
+ sc->from_cp = make_codepage_from_charset(fc);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (IsValidCodePage(sc->from_cp))
+ flag |= SCONV_WIN_CP;
+#endif
+ }
+
+ /*
+ * Check if "from charset" and "to charset" are the same.
+ */
+ if (strcmp(fc, tc) == 0 ||
+ (sc->from_cp != (unsigned)-1 && sc->from_cp == sc->to_cp))
+ sc->same = 1;
+ else
+ sc->same = 0;
+
+ /*
+ * Mark if "from charset" or "to charset" are UTF-8 or UTF-16BE/LE.
+ */
+ if (strcmp(tc, "UTF-8") == 0)
+ flag |= SCONV_TO_UTF8;
+ else if (strcmp(tc, "UTF-16BE") == 0)
+ flag |= SCONV_TO_UTF16BE;
+ else if (strcmp(tc, "UTF-16LE") == 0)
+ flag |= SCONV_TO_UTF16LE;
+ if (strcmp(fc, "UTF-8") == 0)
+ flag |= SCONV_FROM_UTF8;
+ else if (strcmp(fc, "UTF-16BE") == 0)
+ flag |= SCONV_FROM_UTF16BE;
+ else if (strcmp(fc, "UTF-16LE") == 0)
+ flag |= SCONV_FROM_UTF16LE;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (sc->to_cp == CP_UTF8)
+ flag |= SCONV_TO_UTF8;
+ else if (sc->to_cp == CP_UTF16BE)
+ flag |= SCONV_TO_UTF16BE | SCONV_WIN_CP;
+ else if (sc->to_cp == CP_UTF16LE)
+ flag |= SCONV_TO_UTF16LE | SCONV_WIN_CP;
+ if (sc->from_cp == CP_UTF8)
+ flag |= SCONV_FROM_UTF8;
+ else if (sc->from_cp == CP_UTF16BE)
+ flag |= SCONV_FROM_UTF16BE | SCONV_WIN_CP;
+ else if (sc->from_cp == CP_UTF16LE)
+ flag |= SCONV_FROM_UTF16LE | SCONV_WIN_CP;
+#endif
+
+ /*
+ * Set a flag for Unicode NFD. Usually iconv cannot correctly
+ * handle it. So we have to translate NFD characters to NFC ones
+ * ourselves before iconv handles. Another reason is to prevent
+ * that the same sight of two filenames, one is NFC and other
+ * is NFD, would be in its directory.
+ * On Mac OS X, although its filesystem layer automatically
+ * convert filenames to NFD, it would be useful for filename
+ * comparing to find out the same filenames that we normalize
+ * that to be NFD ourselves.
+ */
+ if ((flag & SCONV_FROM_CHARSET) &&
+ (flag & (SCONV_FROM_UTF16 | SCONV_FROM_UTF8))) {
+#if defined(__APPLE__)
+ if (flag & SCONV_TO_UTF8)
+ flag |= SCONV_NORMALIZATION_D;
+ else
+#endif
+ flag |= SCONV_NORMALIZATION_C;
+ }
+#if defined(__APPLE__)
+ /*
+ * In case writing an archive file, make sure that a filename
+ * going to be passed to iconv is a Unicode NFC string since
+ * a filename in HFS Plus filesystem is a Unicode NFD one and
+ * iconv cannot handle it with "UTF-8" charset. It is simpler
+ * than a use of "UTF-8-MAC" charset.
+ */
+ if ((flag & SCONV_TO_CHARSET) &&
+ (flag & (SCONV_FROM_UTF16 | SCONV_FROM_UTF8)) &&
+ !(flag & (SCONV_TO_UTF16 | SCONV_TO_UTF8)))
+ flag |= SCONV_NORMALIZATION_C;
+ /*
+ * In case reading an archive file. make sure that a filename
+ * will be passed to users is a Unicode NFD string in order to
+ * correctly compare the filename with other one which comes
+ * from HFS Plus filesystem.
+ */
+ if ((flag & SCONV_FROM_CHARSET) &&
+ !(flag & (SCONV_FROM_UTF16 | SCONV_FROM_UTF8)) &&
+ (flag & SCONV_TO_UTF8))
+ flag |= SCONV_NORMALIZATION_D;
+#endif
+
+#if defined(HAVE_ICONV)
+ sc->cd_w = (iconv_t)-1;
+ /*
+ * Create an iconv object.
+ */
+ if (((flag & (SCONV_TO_UTF8 | SCONV_TO_UTF16)) &&
+ (flag & (SCONV_FROM_UTF8 | SCONV_FROM_UTF16))) ||
+ (flag & SCONV_WIN_CP)) {
+ /* This case we won't use iconv. */
+ sc->cd = (iconv_t)-1;
+ } else {
+ sc->cd = iconv_open(tc, fc);
+ if (sc->cd == (iconv_t)-1 && (sc->flag & SCONV_BEST_EFFORT)) {
+ /*
+ * Unfortunaly, all of iconv implements do support
+ * "CP932" character-set, so we should use "SJIS"
+ * instead if iconv_open failed.
+ */
+ if (strcmp(tc, "CP932") == 0)
+ sc->cd = iconv_open("SJIS", fc);
+ else if (strcmp(fc, "CP932") == 0)
+ sc->cd = iconv_open(tc, "SJIS");
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /*
+ * archive_mstring on Windows directly convert multi-bytes
+ * into archive_wstring in order not to depend on locale
+ * so that you can do a I18N programing. This will be
+ * used only in archive_mstring_copy_mbs_len_l so far.
+ */
+ if (flag & SCONV_FROM_CHARSET) {
+ sc->cd_w = iconv_open("UTF-8", fc);
+ if (sc->cd_w == (iconv_t)-1 &&
+ (sc->flag & SCONV_BEST_EFFORT)) {
+ if (strcmp(fc, "CP932") == 0)
+ sc->cd_w = iconv_open("UTF-8", "SJIS");
+ }
+ }
+#endif /* _WIN32 && !__CYGWIN__ */
+ }
+#endif /* HAVE_ICONV */
+
+ sc->flag = flag;
+
+ /*
+ * Set up converters.
+ */
+ setup_converter(sc);
+
+ return (sc);
+}
+
+/*
+ * Free a string conversion object.
+ */
+static void
+free_sconv_object(struct archive_string_conv *sc)
+{
+ free(sc->from_charset);
+ free(sc->to_charset);
+ archive_string_free(&sc->utftmp);
+#if HAVE_ICONV
+ if (sc->cd != (iconv_t)-1)
+ iconv_close(sc->cd);
+ if (sc->cd_w != (iconv_t)-1)
+ iconv_close(sc->cd_w);
+#endif
+ free(sc);
+}
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+static unsigned
+my_atoi(const char *p)
+{
+ unsigned cp;
+
+ cp = 0;
+ while (*p) {
+ if (*p >= '0' && *p <= '9')
+ cp = cp * 10 + (*p - '0');
+ else
+ return (-1);
+ p++;
+ }
+ return (cp);
+}
+
+/*
+ * Translate Charset name (as used by iconv) into CodePage (as used by Windows)
+ * Return -1 if failed.
+ *
+ * Note: This translation code may be insufficient.
+ */
+static struct charset {
+ const char *name;
+ unsigned cp;
+} charsets[] = {
+ /* MUST BE SORTED! */
+ {"ASCII", 1252},
+ {"ASMO-708", 708},
+ {"BIG5", 950},
+ {"CHINESE", 936},
+ {"CP367", 1252},
+ {"CP819", 1252},
+ {"CP1025", 21025},
+ {"DOS-720", 720},
+ {"DOS-862", 862},
+ {"EUC-CN", 51936},
+ {"EUC-JP", 51932},
+ {"EUC-KR", 949},
+ {"EUCCN", 51936},
+ {"EUCJP", 51932},
+ {"EUCKR", 949},
+ {"GB18030", 54936},
+ {"GB2312", 936},
+ {"HEBREW", 1255},
+ {"HZ-GB-2312", 52936},
+ {"IBM273", 20273},
+ {"IBM277", 20277},
+ {"IBM278", 20278},
+ {"IBM280", 20280},
+ {"IBM284", 20284},
+ {"IBM285", 20285},
+ {"IBM290", 20290},
+ {"IBM297", 20297},
+ {"IBM367", 1252},
+ {"IBM420", 20420},
+ {"IBM423", 20423},
+ {"IBM424", 20424},
+ {"IBM819", 1252},
+ {"IBM871", 20871},
+ {"IBM880", 20880},
+ {"IBM905", 20905},
+ {"IBM924", 20924},
+ {"ISO-8859-1", 28591},
+ {"ISO-8859-13", 28603},
+ {"ISO-8859-15", 28605},
+ {"ISO-8859-2", 28592},
+ {"ISO-8859-3", 28593},
+ {"ISO-8859-4", 28594},
+ {"ISO-8859-5", 28595},
+ {"ISO-8859-6", 28596},
+ {"ISO-8859-7", 28597},
+ {"ISO-8859-8", 28598},
+ {"ISO-8859-9", 28599},
+ {"ISO8859-1", 28591},
+ {"ISO8859-13", 28603},
+ {"ISO8859-15", 28605},
+ {"ISO8859-2", 28592},
+ {"ISO8859-3", 28593},
+ {"ISO8859-4", 28594},
+ {"ISO8859-5", 28595},
+ {"ISO8859-6", 28596},
+ {"ISO8859-7", 28597},
+ {"ISO8859-8", 28598},
+ {"ISO8859-9", 28599},
+ {"JOHAB", 1361},
+ {"KOI8-R", 20866},
+ {"KOI8-U", 21866},
+ {"KS_C_5601-1987", 949},
+ {"LATIN1", 1252},
+ {"LATIN2", 28592},
+ {"MACINTOSH", 10000},
+ {"SHIFT-JIS", 932},
+ {"SHIFT_JIS", 932},
+ {"SJIS", 932},
+ {"US", 1252},
+ {"US-ASCII", 1252},
+ {"UTF-16", 1200},
+ {"UTF-16BE", 1201},
+ {"UTF-16LE", 1200},
+ {"UTF-8", CP_UTF8},
+ {"X-EUROPA", 29001},
+ {"X-MAC-ARABIC", 10004},
+ {"X-MAC-CE", 10029},
+ {"X-MAC-CHINESEIMP", 10008},
+ {"X-MAC-CHINESETRAD", 10002},
+ {"X-MAC-CROATIAN", 10082},
+ {"X-MAC-CYRILLIC", 10007},
+ {"X-MAC-GREEK", 10006},
+ {"X-MAC-HEBREW", 10005},
+ {"X-MAC-ICELANDIC", 10079},
+ {"X-MAC-JAPANESE", 10001},
+ {"X-MAC-KOREAN", 10003},
+ {"X-MAC-ROMANIAN", 10010},
+ {"X-MAC-THAI", 10021},
+ {"X-MAC-TURKISH", 10081},
+ {"X-MAC-UKRAINIAN", 10017},
+};
+static unsigned
+make_codepage_from_charset(const char *charset)
+{
+ char cs[16];
+ char *p;
+ unsigned cp;
+ int a, b;
+
+ if (charset == NULL || strlen(charset) > 15)
+ return -1;
+
+ /* Copy name to uppercase. */
+ p = cs;
+ while (*charset) {
+ char c = *charset++;
+ if (c >= 'a' && c <= 'z')
+ c -= 'a' - 'A';
+ *p++ = c;
+ }
+ *p++ = '\0';
+ cp = -1;
+
+ /* Look it up in the table first, so that we can easily
+ * override CP367, which we map to 1252 instead of 367. */
+ a = 0;
+ b = sizeof(charsets)/sizeof(charsets[0]);
+ while (b > a) {
+ int c = (b + a) / 2;
+ int r = strcmp(charsets[c].name, cs);
+ if (r < 0)
+ a = c + 1;
+ else if (r > 0)
+ b = c;
+ else
+ return charsets[c].cp;
+ }
+
+ /* If it's not in the table, try to parse it. */
+ switch (*cs) {
+ case 'C':
+ if (cs[1] == 'P' && cs[2] >= '0' && cs[2] <= '9') {
+ cp = my_atoi(cs + 2);
+ } else if (strcmp(cs, "CP_ACP") == 0)
+ cp = get_current_codepage();
+ else if (strcmp(cs, "CP_OEMCP") == 0)
+ cp = get_current_oemcp();
+ break;
+ case 'I':
+ if (cs[1] == 'B' && cs[2] == 'M' &&
+ cs[3] >= '0' && cs[3] <= '9') {
+ cp = my_atoi(cs + 3);
+ }
+ break;
+ case 'W':
+ if (strncmp(cs, "WINDOWS-", 8) == 0) {
+ cp = my_atoi(cs + 8);
+ if (cp != 874 && (cp < 1250 || cp > 1258))
+ cp = -1;/* This may invalid code. */
+ }
+ break;
+ }
+ return (cp);
+}
+
+/*
+ * Return ANSI Code Page of current locale set by setlocale().
+ */
+static unsigned
+get_current_codepage(void)
+{
+ char *locale, *p;
+ unsigned cp;
+
+ locale = setlocale(LC_CTYPE, NULL);
+ if (locale == NULL)
+ return (GetACP());
+ if (locale[0] == 'C' && locale[1] == '\0')
+ return (CP_C_LOCALE);
+ p = strrchr(locale, '.');
+ if (p == NULL)
+ return (GetACP());
+ cp = my_atoi(p+1);
+ if (cp <= 0)
+ return (GetACP());
+ return (cp);
+}
+
+/*
+ * Translation table between Locale Name and ACP/OEMCP.
+ */
+static struct {
+ unsigned acp;
+ unsigned ocp;
+ const char *locale;
+} acp_ocp_map[] = {
+ { 950, 950, "Chinese_Taiwan" },
+ { 936, 936, "Chinese_People's Republic of China" },
+ { 950, 950, "Chinese_Taiwan" },
+ { 1250, 852, "Czech_Czech Republic" },
+ { 1252, 850, "Danish_Denmark" },
+ { 1252, 850, "Dutch_Netherlands" },
+ { 1252, 850, "Dutch_Belgium" },
+ { 1252, 437, "English_United States" },
+ { 1252, 850, "English_Australia" },
+ { 1252, 850, "English_Canada" },
+ { 1252, 850, "English_New Zealand" },
+ { 1252, 850, "English_United Kingdom" },
+ { 1252, 437, "English_United States" },
+ { 1252, 850, "Finnish_Finland" },
+ { 1252, 850, "French_France" },
+ { 1252, 850, "French_Belgium" },
+ { 1252, 850, "French_Canada" },
+ { 1252, 850, "French_Switzerland" },
+ { 1252, 850, "German_Germany" },
+ { 1252, 850, "German_Austria" },
+ { 1252, 850, "German_Switzerland" },
+ { 1253, 737, "Greek_Greece" },
+ { 1250, 852, "Hungarian_Hungary" },
+ { 1252, 850, "Icelandic_Iceland" },
+ { 1252, 850, "Italian_Italy" },
+ { 1252, 850, "Italian_Switzerland" },
+ { 932, 932, "Japanese_Japan" },
+ { 949, 949, "Korean_Korea" },
+ { 1252, 850, "Norwegian (BokmOl)_Norway" },
+ { 1252, 850, "Norwegian (BokmOl)_Norway" },
+ { 1252, 850, "Norwegian-Nynorsk_Norway" },
+ { 1250, 852, "Polish_Poland" },
+ { 1252, 850, "Portuguese_Portugal" },
+ { 1252, 850, "Portuguese_Brazil" },
+ { 1251, 866, "Russian_Russia" },
+ { 1250, 852, "Slovak_Slovakia" },
+ { 1252, 850, "Spanish_Spain" },
+ { 1252, 850, "Spanish_Mexico" },
+ { 1252, 850, "Spanish_Spain" },
+ { 1252, 850, "Swedish_Sweden" },
+ { 1254, 857, "Turkish_Turkey" },
+ { 0, 0, NULL}
+};
+
+/*
+ * Return OEM Code Page of current locale set by setlocale().
+ */
+static unsigned
+get_current_oemcp(void)
+{
+ int i;
+ char *locale, *p;
+ size_t len;
+
+ locale = setlocale(LC_CTYPE, NULL);
+ if (locale == NULL)
+ return (GetOEMCP());
+ if (locale[0] == 'C' && locale[1] == '\0')
+ return (CP_C_LOCALE);
+
+ p = strrchr(locale, '.');
+ if (p == NULL)
+ return (GetOEMCP());
+ len = p - locale;
+ for (i = 0; acp_ocp_map[i].acp; i++) {
+ if (strncmp(acp_ocp_map[i].locale, locale, len) == 0)
+ return (acp_ocp_map[i].ocp);
+ }
+ return (GetOEMCP());
+}
+#else
+
+/*
+ * POSIX platform does not use CodePage.
+ */
+
+static unsigned
+get_current_codepage(void)
+{
+ return (-1);/* Unknown */
+}
+static unsigned
+make_codepage_from_charset(const char *charset)
+{
+ (void)charset; /* UNUSED */
+ return (-1);/* Unknown */
+}
+static unsigned
+get_current_oemcp(void)
+{
+ return (-1);/* Unknown */
+}
+
+#endif /* defined(_WIN32) && !defined(__CYGWIN__) */
+
+/*
+ * Return a string conversion object.
+ */
+static struct archive_string_conv *
+get_sconv_object(struct archive *a, const char *fc, const char *tc, int flag)
+{
+ struct archive_string_conv *sc;
+ unsigned current_codepage;
+
+ /* Check if we have made the sconv object. */
+ sc = find_sconv_object(a, fc, tc);
+ if (sc != NULL)
+ return (sc);
+
+ if (a == NULL)
+ current_codepage = get_current_codepage();
+ else
+ current_codepage = a->current_codepage;
+
+ sc = create_sconv_object(canonical_charset_name(fc),
+ canonical_charset_name(tc), current_codepage, flag);
+ if (sc == NULL) {
+ if (a != NULL)
+ archive_set_error(a, ENOMEM,
+ "Could not allocate memory for "
+ "a string conversion object");
+ return (NULL);
+ }
+
+ /*
+ * If there is no converter for current string conversion object,
+ * we cannot handle this conversion.
+ */
+ if (sc->nconverter == 0) {
+ if (a != NULL) {
+#if HAVE_ICONV
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "iconv_open failed : Cannot handle ``%s''",
+ (flag & SCONV_TO_CHARSET)?tc:fc);
+#else
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "A character-set conversion not fully supported "
+ "on this platform");
+#endif
+ }
+ /* Failed; free a sconv object. */
+ free_sconv_object(sc);
+ return (NULL);
+ }
+
+ /*
+ * Success!
+ */
+ if (a != NULL)
+ add_sconv_object(a, sc);
+ return (sc);
+}
+
+static const char *
+get_current_charset(struct archive *a)
+{
+ const char *cur_charset;
+
+ if (a == NULL)
+ cur_charset = default_iconv_charset("");
+ else {
+ cur_charset = default_iconv_charset(a->current_code);
+ if (a->current_code == NULL) {
+ a->current_code = strdup(cur_charset);
+ a->current_codepage = get_current_codepage();
+ a->current_oemcp = get_current_oemcp();
+ }
+ }
+ return (cur_charset);
+}
+
+/*
+ * Make and Return a string conversion object.
+ * Return NULL if the platform does not support the specified conversion
+ * and best_effort is 0.
+ * If best_effort is set, A string conversion object must be returned
+ * unless memory allocation for the object fails, but the conversion
+ * might fail when non-ASCII code is found.
+ */
+struct archive_string_conv *
+archive_string_conversion_to_charset(struct archive *a, const char *charset,
+ int best_effort)
+{
+ int flag = SCONV_TO_CHARSET;
+
+ if (best_effort)
+ flag |= SCONV_BEST_EFFORT;
+ return (get_sconv_object(a, get_current_charset(a), charset, flag));
+}
+
+struct archive_string_conv *
+archive_string_conversion_from_charset(struct archive *a, const char *charset,
+ int best_effort)
+{
+ int flag = SCONV_FROM_CHARSET;
+
+ if (best_effort)
+ flag |= SCONV_BEST_EFFORT;
+ return (get_sconv_object(a, charset, get_current_charset(a), flag));
+}
+
+/*
+ * archive_string_default_conversion_*_archive() are provided for Windows
+ * platform because other archiver application use CP_OEMCP for
+ * MultiByteToWideChar() and WideCharToMultiByte() for the filenames
+ * in tar or zip files. But mbstowcs/wcstombs(CRT) usually use CP_ACP
+ * unless you use setlocale(LC_ALL, ".OCP")(specify CP_OEMCP).
+ * So we should make a string conversion between CP_ACP and CP_OEMCP
+ * for compatibillty.
+ */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+struct archive_string_conv *
+archive_string_default_conversion_for_read(struct archive *a)
+{
+ const char *cur_charset = get_current_charset(a);
+ char oemcp[16];
+
+ /* NOTE: a check of cur_charset is unneeded but we need
+ * that get_current_charset() has been surely called at
+ * this time whatever C compiler optimized. */
+ if (cur_charset != NULL &&
+ (a->current_codepage == CP_C_LOCALE ||
+ a->current_codepage == a->current_oemcp))
+ return (NULL);/* no conversion. */
+
+ _snprintf(oemcp, sizeof(oemcp)-1, "CP%d", a->current_oemcp);
+ /* Make sure a null termination must be set. */
+ oemcp[sizeof(oemcp)-1] = '\0';
+ return (get_sconv_object(a, oemcp, cur_charset,
+ SCONV_FROM_CHARSET));
+}
+
+struct archive_string_conv *
+archive_string_default_conversion_for_write(struct archive *a)
+{
+ const char *cur_charset = get_current_charset(a);
+ char oemcp[16];
+
+ /* NOTE: a check of cur_charset is unneeded but we need
+ * that get_current_charset() has been surely called at
+ * this time whatever C compiler optimized. */
+ if (cur_charset != NULL &&
+ (a->current_codepage == CP_C_LOCALE ||
+ a->current_codepage == a->current_oemcp))
+ return (NULL);/* no conversion. */
+
+ _snprintf(oemcp, sizeof(oemcp)-1, "CP%d", a->current_oemcp);
+ /* Make sure a null termination must be set. */
+ oemcp[sizeof(oemcp)-1] = '\0';
+ return (get_sconv_object(a, cur_charset, oemcp,
+ SCONV_TO_CHARSET));
+}
+#else
+struct archive_string_conv *
+archive_string_default_conversion_for_read(struct archive *a)
+{
+ (void)a; /* UNUSED */
+ return (NULL);
+}
+
+struct archive_string_conv *
+archive_string_default_conversion_for_write(struct archive *a)
+{
+ (void)a; /* UNUSED */
+ return (NULL);
+}
+#endif
+
+/*
+ * Dispose of all character conversion objects in the archive object.
+ */
+void
+archive_string_conversion_free(struct archive *a)
+{
+ struct archive_string_conv *sc;
+ struct archive_string_conv *sc_next;
+
+ for (sc = a->sconv; sc != NULL; sc = sc_next) {
+ sc_next = sc->next;
+ free_sconv_object(sc);
+ }
+ a->sconv = NULL;
+ free(a->current_code);
+ a->current_code = NULL;
+}
+
+/*
+ * Return a conversion charset name.
+ */
+const char *
+archive_string_conversion_charset_name(struct archive_string_conv *sc)
+{
+ if (sc->flag & SCONV_TO_CHARSET)
+ return (sc->to_charset);
+ else
+ return (sc->from_charset);
+}
+
+/*
+ * Change the behavior of a string conversion.
+ */
+void
+archive_string_conversion_set_opt(struct archive_string_conv *sc, int opt)
+{
+ switch (opt) {
+ /*
+ * A filename in UTF-8 was made with libarchive 2.x in a wrong
+ * assumption that wchar_t was Unicode.
+ * This option enables simulating the assumption in order to read
+ * that filname correctly.
+ */
+ case SCONV_SET_OPT_UTF8_LIBARCHIVE2X:
+#if (defined(_WIN32) && !defined(__CYGWIN__)) \
+ || defined(__STDC_ISO_10646__) || defined(__APPLE__)
+ /*
+ * Nothing to do for it since wchar_t on these platforms
+ * is really Unicode.
+ */
+ (void)sc; /* UNUSED */
+#else
+ if ((sc->flag & SCONV_UTF8_LIBARCHIVE_2) == 0) {
+ sc->flag |= SCONV_UTF8_LIBARCHIVE_2;
+ /* Set up string converters. */
+ setup_converter(sc);
+ }
+#endif
+ break;
+ case SCONV_SET_OPT_NORMALIZATION_C:
+ if ((sc->flag & SCONV_NORMALIZATION_C) == 0) {
+ sc->flag |= SCONV_NORMALIZATION_C;
+ sc->flag &= ~SCONV_NORMALIZATION_D;
+ /* Set up string converters. */
+ setup_converter(sc);
+ }
+ break;
+ case SCONV_SET_OPT_NORMALIZATION_D:
+#if defined(HAVE_ICONV)
+ /*
+ * If iconv will take the string, do not change the
+ * setting of the normalization.
+ */
+ if (!(sc->flag & SCONV_WIN_CP) &&
+ (sc->flag & (SCONV_FROM_UTF16 | SCONV_FROM_UTF8)) &&
+ !(sc->flag & (SCONV_TO_UTF16 | SCONV_TO_UTF8)))
+ break;
+#endif
+ if ((sc->flag & SCONV_NORMALIZATION_D) == 0) {
+ sc->flag |= SCONV_NORMALIZATION_D;
+ sc->flag &= ~SCONV_NORMALIZATION_C;
+ /* Set up string converters. */
+ setup_converter(sc);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+/*
+ *
+ * Copy one archive_string to another in locale conversion.
+ *
+ * archive_strncat_l();
+ * archive_strncpy_l();
+ *
+ */
+
+static size_t
+mbsnbytes(const void *_p, size_t n)
+{
+ size_t s;
+ const char *p, *pp;
+
+ if (_p == NULL)
+ return (0);
+ p = (const char *)_p;
+
+ /* Like strlen(p), except won't examine positions beyond p[n]. */
+ s = 0;
+ pp = p;
+ while (s < n && *pp) {
+ pp++;
+ s++;
+ }
+ return (s);
+}
+
+static size_t
+utf16nbytes(const void *_p, size_t n)
+{
+ size_t s;
+ const char *p, *pp;
+
+ if (_p == NULL)
+ return (0);
+ p = (const char *)_p;
+
+ /* Like strlen(p), except won't examine positions beyond p[n]. */
+ s = 0;
+ pp = p;
+ n >>= 1;
+ while (s < n && (pp[0] || pp[1])) {
+ pp += 2;
+ s++;
+ }
+ return (s<<1);
+}
+
+int
+archive_strncpy_l(struct archive_string *as, const void *_p, size_t n,
+ struct archive_string_conv *sc)
+{
+ as->length = 0;
+ return (archive_strncat_l(as, _p, n, sc));
+}
+
+int
+archive_strncat_l(struct archive_string *as, const void *_p, size_t n,
+ struct archive_string_conv *sc)
+{
+ const void *s;
+ size_t length;
+ int i, r = 0, r2;
+
+ /* We must allocate memory even if there is no data for conversion
+ * or copy. This simulates archive_string_append behavior. */
+ if (_p == NULL || n == 0) {
+ int tn = 1;
+ if (sc != NULL && (sc->flag & SCONV_TO_UTF16))
+ tn = 2;
+ if (archive_string_ensure(as, as->length + tn) == NULL)
+ return (-1);
+ as->s[as->length] = 0;
+ if (tn == 2)
+ as->s[as->length+1] = 0;
+ return (0);
+ }
+
+ /*
+ * If sc is NULL, we just make a copy.
+ */
+ if (sc == NULL) {
+ length = mbsnbytes(_p, n);
+ if (archive_string_append(as, _p, length) == NULL)
+ return (-1);/* No memory */
+ return (0);
+ }
+
+ if (sc->flag & SCONV_FROM_UTF16)
+ length = utf16nbytes(_p, n);
+ else
+ length = mbsnbytes(_p, n);
+ s = _p;
+ i = 0;
+ if (sc->nconverter > 1) {
+ sc->utftmp.length = 0;
+ r2 = sc->converter[0](&(sc->utftmp), s, length, sc);
+ if (r2 != 0 && errno == ENOMEM)
+ return (r2);
+ if (r > r2)
+ r = r2;
+ s = sc->utftmp.s;
+ length = sc->utftmp.length;
+ ++i;
+ }
+ r2 = sc->converter[i](as, s, length, sc);
+ if (r > r2)
+ r = r2;
+ return (r);
+}
+
+#if HAVE_ICONV
+
+/*
+ * Return -1 if conversion failes.
+ */
+static int
+iconv_strncat_in_locale(struct archive_string *as, const void *_p,
+ size_t length, struct archive_string_conv *sc)
+{
+ ICONV_CONST char *itp;
+ size_t remaining;
+ iconv_t cd;
+ char *outp;
+ size_t avail, bs;
+ int return_value = 0; /* success */
+ int to_size, from_size;
+
+ if (sc->flag & SCONV_TO_UTF16)
+ to_size = 2;
+ else
+ to_size = 1;
+ if (sc->flag & SCONV_FROM_UTF16)
+ from_size = 2;
+ else
+ from_size = 1;
+
+ if (archive_string_ensure(as, as->length + length*2+to_size) == NULL)
+ return (-1);
+
+ cd = sc->cd;
+ itp = (char *)(uintptr_t)_p;
+ remaining = length;
+ outp = as->s + as->length;
+ avail = as->buffer_length - as->length - to_size;
+ while (remaining >= (size_t)from_size) {
+ size_t result = iconv(cd, &itp, &remaining, &outp, &avail);
+
+ if (result != (size_t)-1)
+ break; /* Conversion completed. */
+
+ if (errno == EILSEQ || errno == EINVAL) {
+ /*
+ * If an output charset is UTF-8 or UTF-16BE/LE,
+ * unknown character should be U+FFFD
+ * (replacement character).
+ */
+ if (sc->flag & (SCONV_TO_UTF8 | SCONV_TO_UTF16)) {
+ size_t rbytes;
+ if (sc->flag & SCONV_TO_UTF8)
+ rbytes = UTF8_R_CHAR_SIZE;
+ else
+ rbytes = 2;
+
+ if (avail < rbytes) {
+ as->length = outp - as->s;
+ bs = as->buffer_length +
+ (remaining * to_size) + rbytes;
+ if (NULL ==
+ archive_string_ensure(as, bs))
+ return (-1);
+ outp = as->s + as->length;
+ avail = as->buffer_length
+ - as->length - to_size;
+ }
+ if (sc->flag & SCONV_TO_UTF8)
+ UTF8_SET_R_CHAR(outp);
+ else if (sc->flag & SCONV_TO_UTF16BE)
+ archive_be16enc(outp, UNICODE_R_CHAR);
+ else
+ archive_le16enc(outp, UNICODE_R_CHAR);
+ outp += rbytes;
+ avail -= rbytes;
+ } else {
+ /* Skip the illegal input bytes. */
+ *outp++ = '?';
+ avail--;
+ }
+ itp += from_size;
+ remaining -= from_size;
+ return_value = -1; /* failure */
+ } else {
+ /* E2BIG no output buffer,
+ * Increase an output buffer. */
+ as->length = outp - as->s;
+ bs = as->buffer_length + remaining * 2;
+ if (NULL == archive_string_ensure(as, bs))
+ return (-1);
+ outp = as->s + as->length;
+ avail = as->buffer_length - as->length - to_size;
+ }
+ }
+ as->length = outp - as->s;
+ as->s[as->length] = 0;
+ if (to_size == 2)
+ as->s[as->length+1] = 0;
+ return (return_value);
+}
+
+#endif /* HAVE_ICONV */
+
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+/*
+ * Translate a string from a some CodePage to an another CodePage by
+ * Windows APIs, and copy the result. Return -1 if conversion failes.
+ */
+static int
+strncat_in_codepage(struct archive_string *as,
+ const void *_p, size_t length, struct archive_string_conv *sc)
+{
+ const char *s = (const char *)_p;
+ struct archive_wstring aws;
+ size_t l;
+ int r, saved_flag;
+
+ archive_string_init(&aws);
+ saved_flag = sc->flag;
+ sc->flag &= ~(SCONV_NORMALIZATION_D | SCONV_NORMALIZATION_C);
+ r = archive_wstring_append_from_mbs_in_codepage(&aws, s, length, sc);
+ sc->flag = saved_flag;
+ if (r != 0) {
+ archive_wstring_free(&aws);
+ if (errno != ENOMEM)
+ archive_string_append(as, s, length);
+ return (-1);
+ }
+
+ l = as->length;
+ r = archive_string_append_from_wcs_in_codepage(
+ as, aws.s, aws.length, sc);
+ if (r != 0 && errno != ENOMEM && l == as->length)
+ archive_string_append(as, s, length);
+ archive_wstring_free(&aws);
+ return (r);
+}
+
+/*
+ * Test whether MBS ==> WCS is okay.
+ */
+static int
+invalid_mbs(const void *_p, size_t n, struct archive_string_conv *sc)
+{
+ const char *p = (const char *)_p;
+ unsigned codepage;
+ DWORD mbflag = MB_ERR_INVALID_CHARS;
+
+ if (sc->flag & SCONV_FROM_CHARSET)
+ codepage = sc->to_cp;
+ else
+ codepage = sc->from_cp;
+
+ if (codepage == CP_C_LOCALE)
+ return (0);
+ if (codepage != CP_UTF8)
+ mbflag |= MB_PRECOMPOSED;
+
+ if (MultiByteToWideChar(codepage, mbflag, p, (int)n, NULL, 0) == 0)
+ return (-1); /* Invalid */
+ return (0); /* Okay */
+}
+
+#else
+
+/*
+ * Test whether MBS ==> WCS is okay.
+ */
+static int
+invalid_mbs(const void *_p, size_t n, struct archive_string_conv *sc)
+{
+ const char *p = (const char *)_p;
+ size_t r;
+
+#if HAVE_MBRTOWC
+ mbstate_t shift_state;
+
+ memset(&shift_state, 0, sizeof(shift_state));
+#else
+ /* Clear the shift state before starting. */
+ mbtowc(NULL, NULL, 0);
+#endif
+ while (n) {
+ wchar_t wc;
+
+#if HAVE_MBRTOWC
+ r = mbrtowc(&wc, p, n, &shift_state);
+#else
+ r = mbtowc(&wc, p, n);
+#endif
+ if (r == (size_t)-1 || r == (size_t)-2)
+ return (-1);/* Invalid. */
+ if (r == 0)
+ break;
+ p += r;
+ n -= r;
+ }
+ (void)sc; /* UNUSED */
+ return (0); /* All Okey. */
+}
+
+#endif /* defined(_WIN32) && !defined(__CYGWIN__) */
+
+/*
+ * Basically returns -1 because we cannot make a conversion of charset
+ * without iconv but in some cases this would return 0.
+ * Returns 0 if all copied characters are ASCII.
+ * Returns 0 if both from-locale and to-locale are the same and those
+ * can be WCS with no error.
+ */
+static int
+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 */
+
+ /*
+ * If both from-locale and to-locale is the same, this makes a copy.
+ * And then this checks all copied MBS can be WCS if so returns 0.
+ */
+ if (sc->same) {
+ if (archive_string_append(as, _p, length) == NULL)
+ return (-1);/* No memory */
+ return (invalid_mbs(_p, length, sc));
+ }
+
+ /*
+ * If a character is ASCII, this just copies it. If not, this
+ * assigns '?' charater instead but in UTF-8 locale this assigns
+ * 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;
+ }
+ /*
+ * 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--;
+ }
+ }
+ as->length = otp - as->s;
+ as->s[as->length] = '\0';
+ return (return_value);
+}
+
+
+/*
+ * Unicode conversion functions.
+ * - UTF-8 <===> UTF-8 in removing surrogate pairs.
+ * - UTF-8 NFD ===> UTF-8 NFC in removing surrogate pairs.
+ * - UTF-8 made by libarchive 2.x ===> UTF-8.
+ * - UTF-16BE <===> UTF-8.
+ *
+ */
+
+/*
+ * Utility to convert a single UTF-8 sequence.
+ *
+ * Usually return used bytes, return used byte in negative value when
+ * a unicode character is replaced with U+FFFD.
+ * See also http://unicode.org/review/pr-121.html Public Review Issue #121
+ * Recommended Practice for Replacement Characters.
+ */
+static int
+_utf8_to_unicode(uint32_t *pwc, const char *s, size_t n)
+{
+ static const char utf8_count[256] = {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 00 - 0F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 10 - 1F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 20 - 2F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 30 - 3F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40 - 4F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 50 - 5F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 60 - 6F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 70 - 7F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 80 - 8F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 90 - 9F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* A0 - AF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* B0 - BF */
+ 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,/* C0 - CF */
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,/* D0 - DF */
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,/* E0 - EF */
+ 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* F0 - FF */
+ };
+ int ch, i;
+ int cnt;
+ uint32_t wc;
+
+ /* Sanity check. */
+ if (n == 0)
+ return (0);
+ /*
+ * Decode 1-4 bytes depending on the value of the first byte.
+ */
+ ch = (unsigned char)*s;
+ if (ch == 0)
+ return (0); /* Standard: return 0 for end-of-string. */
+ cnt = utf8_count[ch];
+
+ /* Invalide sequence or there are not plenty bytes. */
+ if ((int)n < cnt) {
+ cnt = (int)n;
+ for (i = 1; i < cnt; i++) {
+ if ((s[i] & 0xc0) != 0x80) {
+ cnt = i;
+ break;
+ }
+ }
+ goto invalid_sequence;
+ }
+
+ /* Make a Unicode code point from a single UTF-8 sequence. */
+ switch (cnt) {
+ case 1: /* 1 byte sequence. */
+ *pwc = ch & 0x7f;
+ return (cnt);
+ case 2: /* 2 bytes sequence. */
+ if ((s[1] & 0xc0) != 0x80) {
+ cnt = 1;
+ goto invalid_sequence;
+ }
+ *pwc = ((ch & 0x1f) << 6) | (s[1] & 0x3f);
+ return (cnt);
+ case 3: /* 3 bytes sequence. */
+ if ((s[1] & 0xc0) != 0x80) {
+ cnt = 1;
+ goto invalid_sequence;
+ }
+ if ((s[2] & 0xc0) != 0x80) {
+ cnt = 2;
+ goto invalid_sequence;
+ }
+ wc = ((ch & 0x0f) << 12)
+ | ((s[1] & 0x3f) << 6)
+ | (s[2] & 0x3f);
+ if (wc < 0x800)
+ goto invalid_sequence;/* Overlong sequence. */
+ break;
+ case 4: /* 4 bytes sequence. */
+ if ((s[1] & 0xc0) != 0x80) {
+ cnt = 1;
+ goto invalid_sequence;
+ }
+ if ((s[2] & 0xc0) != 0x80) {
+ cnt = 2;
+ goto invalid_sequence;
+ }
+ if ((s[3] & 0xc0) != 0x80) {
+ cnt = 3;
+ goto invalid_sequence;
+ }
+ wc = ((ch & 0x07) << 18)
+ | ((s[1] & 0x3f) << 12)
+ | ((s[2] & 0x3f) << 6)
+ | (s[3] & 0x3f);
+ if (wc < 0x10000)
+ goto invalid_sequence;/* Overlong sequence. */
+ break;
+ default: /* Others are all invalid sequence. */
+ if (ch == 0xc0 || ch == 0xc1)
+ cnt = 2;
+ else if (ch >= 0xf5 && ch <= 0xf7)
+ cnt = 4;
+ else if (ch >= 0xf8 && ch <= 0xfb)
+ cnt = 5;
+ else if (ch == 0xfc || ch == 0xfd)
+ cnt = 6;
+ else
+ cnt = 1;
+ if ((int)n < cnt)
+ cnt = (int)n;
+ for (i = 1; i < cnt; i++) {
+ if ((s[i] & 0xc0) != 0x80) {
+ cnt = i;
+ break;
+ }
+ }
+ goto invalid_sequence;
+ }
+
+ /* The code point larger than 0x10FFFF is not leagal
+ * Unicode values. */
+ if (wc > UNICODE_MAX)
+ goto invalid_sequence;
+ /* Correctly gets a Unicode, returns used bytes. */
+ *pwc = wc;
+ return (cnt);
+invalid_sequence:
+ *pwc = UNICODE_R_CHAR;/* set the Replacement Character instead. */
+ return (cnt * -1);
+}
+
+static int
+utf8_to_unicode(uint32_t *pwc, const char *s, size_t n)
+{
+ int cnt;
+
+ cnt = _utf8_to_unicode(pwc, s, n);
+ /* Any of Surrogate pair is not leagal Unicode values. */
+ if (cnt == 3 && IS_SURROGATE_PAIR_LA(*pwc))
+ return (-3);
+ return (cnt);
+}
+
+static inline uint32_t
+combine_surrogate_pair(uint32_t uc, uint32_t uc2)
+{
+ uc -= 0xD800;
+ uc *= 0x400;
+ uc += uc2 - 0xDC00;
+ uc += 0x10000;
+ return (uc);
+}
+
+/*
+ * Convert a single UTF-8/CESU-8 sequence to a Unicode code point in
+ * removing surrogate pairs.
+ *
+ * CESU-8: The Compatibility Encoding Scheme for UTF-16.
+ *
+ * Usually return used bytes, return used byte in negative value when
+ * a unicode character is replaced with U+FFFD.
+ */
+static int
+cesu8_to_unicode(uint32_t *pwc, const char *s, size_t n)
+{
+ uint32_t wc = 0;
+ int cnt;
+
+ cnt = _utf8_to_unicode(&wc, s, n);
+ if (cnt == 3 && IS_HIGH_SURROGATE_LA(wc)) {
+ uint32_t wc2 = 0;
+ if (n - 3 < 3) {
+ /* Invalid byte sequence. */
+ goto invalid_sequence;
+ }
+ cnt = _utf8_to_unicode(&wc2, s+3, n-3);
+ if (cnt != 3 || !IS_LOW_SURROGATE_LA(wc2)) {
+ /* Invalid byte sequence. */
+ goto invalid_sequence;
+ }
+ wc = combine_surrogate_pair(wc, wc2);
+ cnt = 6;
+ } else if (cnt == 3 && IS_LOW_SURROGATE_LA(wc)) {
+ /* Invalid byte sequence. */
+ goto invalid_sequence;
+ }
+ *pwc = wc;
+ return (cnt);
+invalid_sequence:
+ *pwc = UNICODE_R_CHAR;/* set the Replacement Character instead. */
+ if (cnt > 0)
+ cnt *= -1;
+ return (cnt);
+}
+
+/*
+ * Convert a Unicode code point to a single UTF-8 sequence.
+ *
+ * NOTE:This function does not check if the Unicode is leagal or not.
+ * Please you definitely check it before calling this.
+ */
+static size_t
+unicode_to_utf8(char *p, size_t remaining, uint32_t uc)
+{
+ char *_p = p;
+
+ /* Translate code point to UTF8 */
+ if (uc <= 0x7f) {
+ if (remaining == 0)
+ return (0);
+ *p++ = (char)uc;
+ } else if (uc <= 0x7ff) {
+ if (remaining < 2)
+ return (0);
+ *p++ = 0xc0 | ((uc >> 6) & 0x1f);
+ *p++ = 0x80 | (uc & 0x3f);
+ } else if (uc <= 0xffff) {
+ if (remaining < 3)
+ return (0);
+ *p++ = 0xe0 | ((uc >> 12) & 0x0f);
+ *p++ = 0x80 | ((uc >> 6) & 0x3f);
+ *p++ = 0x80 | (uc & 0x3f);
+ } else if (uc <= UNICODE_MAX) {
+ 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);
+}
+
+static int
+utf16be_to_unicode(uint32_t *pwc, const char *s, size_t n)
+{
+ return (utf16_to_unicode(pwc, s, n, 1));
+}
+
+static int
+utf16le_to_unicode(uint32_t *pwc, const char *s, size_t n)
+{
+ return (utf16_to_unicode(pwc, s, n, 0));
+}
+
+static int
+utf16_to_unicode(uint32_t *pwc, const char *s, size_t n, int be)
+{
+ const char *utf16 = s;
+ unsigned uc;
+
+ if (n == 0)
+ return (0);
+ if (n == 1) {
+ /* set the Replacement Character instead. */
+ *pwc = UNICODE_R_CHAR;
+ return (-1);
+ }
+
+ if (be)
+ uc = archive_be16dec(utf16);
+ else
+ uc = archive_le16dec(utf16);
+ utf16 += 2;
+
+ /* If this is a surrogate pair, assemble the full code point.*/
+ if (IS_HIGH_SURROGATE_LA(uc)) {
+ unsigned uc2;
+
+ if (n >= 4) {
+ if (be)
+ uc2 = archive_be16dec(utf16);
+ else
+ uc2 = archive_le16dec(utf16);
+ } else
+ uc2 = 0;
+ if (IS_LOW_SURROGATE_LA(uc2)) {
+ uc = combine_surrogate_pair(uc, uc2);
+ utf16 += 2;
+ } else {
+ /* Undescribed code point should be U+FFFD
+ * (replacement character). */
+ *pwc = UNICODE_R_CHAR;
+ return (-2);
+ }
+ }
+
+ /*
+ * Surrogate pair values(0xd800 through 0xdfff) are only
+ * used by UTF-16, so, after above culculation, the code
+ * must not be surrogate values, and Unicode has no codes
+ * larger than 0x10ffff. Thus, those are not leagal Unicode
+ * values.
+ */
+ if (IS_SURROGATE_PAIR_LA(uc) || uc > UNICODE_MAX) {
+ /* Undescribed code point should be U+FFFD
+ * (replacement character). */
+ *pwc = UNICODE_R_CHAR;
+ return (((int)(utf16 - s)) * -1);
+ }
+ *pwc = uc;
+ return ((int)(utf16 - s));
+}
+
+static size_t
+unicode_to_utf16be(char *p, size_t remaining, uint32_t uc)
+{
+ char *utf16 = p;
+
+ if (uc > 0xffff) {
+ /* We have a code point that won't fit into a
+ * wchar_t; convert it to a surrogate pair. */
+ if (remaining < 4)
+ return (0);
+ uc -= 0x10000;
+ archive_be16enc(utf16, ((uc >> 10) & 0x3ff) + 0xD800);
+ archive_be16enc(utf16+2, (uc & 0x3ff) + 0xDC00);
+ return (4);
+ } else {
+ if (remaining < 2)
+ return (0);
+ archive_be16enc(utf16, uc);
+ return (2);
+ }
+}
+
+static size_t
+unicode_to_utf16le(char *p, size_t remaining, uint32_t uc)
+{
+ char *utf16 = p;
+
+ if (uc > 0xffff) {
+ /* We have a code point that won't fit into a
+ * wchar_t; convert it to a surrogate pair. */
+ if (remaining < 4)
+ return (0);
+ uc -= 0x10000;
+ archive_le16enc(utf16, ((uc >> 10) & 0x3ff) + 0xD800);
+ archive_le16enc(utf16+2, (uc & 0x3ff) + 0xDC00);
+ return (4);
+ } else {
+ if (remaining < 2)
+ return (0);
+ archive_le16enc(utf16, uc);
+ return (2);
+ }
+}
+
+/*
+ * Copy UTF-8 string in checking surrogate pair.
+ * If any surrogate pair are found, it would be canonicalized.
+ */
+static int
+strncat_from_utf8_to_utf8(struct archive_string *as, const void *_p,
+ size_t len, struct archive_string_conv *sc)
+{
+ const char *s;
+ char *p, *endp;
+ int n, ret = 0;
+
+ (void)sc; /* UNUSED */
+
+ if (archive_string_ensure(as, as->length + len + 1) == NULL)
+ return (-1);
+
+ s = (const char *)_p;
+ p = as->s + as->length;
+ endp = as->s + as->buffer_length -1;
+ do {
+ uint32_t uc;
+ const char *ss = s;
+ size_t w;
+
+ /*
+ * Forward byte sequence until a conversion of that is needed.
+ */
+ while ((n = utf8_to_unicode(&uc, s, len)) > 0) {
+ s += n;
+ len -= n;
+ }
+ if (ss < s) {
+ if (p + (s - ss) > endp) {
+ as->length = p - as->s;
+ if (archive_string_ensure(as,
+ as->buffer_length + len + 1) == NULL)
+ return (-1);
+ p = as->s + as->length;
+ endp = as->s + as->buffer_length -1;
+ }
+
+ memcpy(p, ss, s - ss);
+ p += s - ss;
+ }
+
+ /*
+ * If n is negative, current byte sequence needs a replacement.
+ */
+ if (n < 0) {
+ if (n == -3 && IS_SURROGATE_PAIR_LA(uc)) {
+ /* Current byte sequence may be CESU-8. */
+ n = cesu8_to_unicode(&uc, s, len);
+ }
+ if (n < 0) {
+ ret = -1;
+ n *= -1;/* Use a replaced unicode character. */
+ }
+
+ /* Rebuild UTF-8 byte sequence. */
+ while ((w = unicode_to_utf8(p, endp - p, uc)) == 0) {
+ as->length = p - as->s;
+ if (archive_string_ensure(as,
+ as->buffer_length + len + 1) == NULL)
+ return (-1);
+ p = as->s + as->length;
+ endp = as->s + as->buffer_length -1;
+ }
+ p += w;
+ s += n;
+ len -= n;
+ }
+ } while (n > 0);
+ as->length = p - as->s;
+ as->s[as->length] = '\0';
+ return (ret);
+}
+
+static int
+archive_string_append_unicode(struct archive_string *as, const void *_p,
+ size_t len, struct archive_string_conv *sc)
+{
+ const char *s;
+ char *p, *endp;
+ uint32_t uc;
+ size_t w;
+ int n, ret = 0, ts, tm;
+ int (*parse)(uint32_t *, const char *, size_t);
+ size_t (*unparse)(char *, size_t, uint32_t);
+
+ if (sc->flag & SCONV_TO_UTF16BE) {
+ unparse = unicode_to_utf16be;
+ ts = 2;
+ } else if (sc->flag & SCONV_TO_UTF16LE) {
+ unparse = unicode_to_utf16le;
+ ts = 2;
+ } else if (sc->flag & SCONV_TO_UTF8) {
+ unparse = unicode_to_utf8;
+ ts = 1;
+ } else {
+ /*
+ * This case is going to be converted to another
+ * character-set through iconv.
+ */
+ if (sc->flag & SCONV_FROM_UTF16BE) {
+ unparse = unicode_to_utf16be;
+ ts = 2;
+ } else if (sc->flag & SCONV_FROM_UTF16LE) {
+ unparse = unicode_to_utf16le;
+ ts = 2;
+ } else {
+ unparse = unicode_to_utf8;
+ ts = 1;
+ }
+ }
+
+ if (sc->flag & SCONV_FROM_UTF16BE) {
+ parse = utf16be_to_unicode;
+ tm = 1;
+ } else if (sc->flag & SCONV_FROM_UTF16LE) {
+ parse = utf16le_to_unicode;
+ tm = 1;
+ } else {
+ parse = cesu8_to_unicode;
+ tm = ts;
+ }
+
+ if (archive_string_ensure(as, as->length + len * tm + ts) == NULL)
+ return (-1);
+
+ s = (const char *)_p;
+ p = as->s + as->length;
+ endp = as->s + as->buffer_length - ts;
+ while ((n = parse(&uc, s, len)) != 0) {
+ if (n < 0) {
+ /* Use a replaced unicode character. */
+ n *= -1;
+ ret = -1;
+ }
+ s += n;
+ len -= n;
+ while ((w = unparse(p, endp - p, uc)) == 0) {
+ /* There is not enough output buffer so
+ * we have to expand it. */
+ as->length = p - as->s;
+ if (archive_string_ensure(as,
+ as->buffer_length + len * tm + ts) == NULL)
+ return (-1);
+ p = as->s + as->length;
+ endp = as->s + as->buffer_length - ts;
+ }
+ p += w;
+ }
+ as->length = p - as->s;
+ as->s[as->length] = '\0';
+ if (ts == 2)
+ as->s[as->length+1] = '\0';
+ return (ret);
+}
+
+/*
+ * Following Constants for Hangul compositions this information comes from
+ * Unicode Standard Annex #15 http://unicode.org/reports/tr15/
+ */
+#define HC_SBASE 0xAC00
+#define HC_LBASE 0x1100
+#define HC_VBASE 0x1161
+#define HC_TBASE 0x11A7
+#define HC_LCOUNT 19
+#define HC_VCOUNT 21
+#define HC_TCOUNT 28
+#define HC_NCOUNT (HC_VCOUNT * HC_TCOUNT)
+#define HC_SCOUNT (HC_LCOUNT * HC_NCOUNT)
+
+static uint32_t
+get_nfc(uint32_t uc, uint32_t uc2)
+{
+ int t, b;
+
+ t = 0;
+ b = sizeof(u_composition_table)/sizeof(u_composition_table[0]) -1;
+ while (b >= t) {
+ int m = (t + b) / 2;
+ if (u_composition_table[m].cp1 < uc)
+ t = m + 1;
+ else if (u_composition_table[m].cp1 > uc)
+ b = m - 1;
+ else if (u_composition_table[m].cp2 < uc2)
+ t = m + 1;
+ else if (u_composition_table[m].cp2 > uc2)
+ b = m - 1;
+ else
+ return (u_composition_table[m].nfc);
+ }
+ return (0);
+}
+
+#define FDC_MAX 10 /* The maximum number of Following Decomposable
+ * Characters. */
+
+/*
+ * Update first code point.
+ */
+#define UPDATE_UC(new_uc) do { \
+ uc = new_uc; \
+ ucptr = NULL; \
+} while (0)
+
+/*
+ * Replace first code point with second code point.
+ */
+#define REPLACE_UC_WITH_UC2() do { \
+ uc = uc2; \
+ ucptr = uc2ptr; \
+ n = n2; \
+} while (0)
+
+#define EXPAND_BUFFER() do { \
+ as->length = p - as->s; \
+ if (archive_string_ensure(as, \
+ as->buffer_length + len * tm + ts) == NULL)\
+ return (-1); \
+ p = as->s + as->length; \
+ endp = as->s + as->buffer_length - ts; \
+} while (0)
+
+#define UNPARSE(p, endp, uc) do { \
+ while ((w = unparse(p, (endp) - (p), uc)) == 0) {\
+ EXPAND_BUFFER(); \
+ } \
+ p += w; \
+} while (0)
+
+/*
+ * Write first code point.
+ * If the code point has not be changed from its original code,
+ * this just copies it from its original buffer pointer.
+ * If not, this converts it to UTF-8 byte sequence and copies it.
+ */
+#define WRITE_UC() do { \
+ if (ucptr) { \
+ if (p + n > endp) \
+ EXPAND_BUFFER(); \
+ switch (n) { \
+ case 4: \
+ *p++ = *ucptr++; \
+ /* FALL THROUGH */ \
+ case 3: \
+ *p++ = *ucptr++; \
+ /* FALL THROUGH */ \
+ case 2: \
+ *p++ = *ucptr++; \
+ /* FALL THROUGH */ \
+ case 1: \
+ *p++ = *ucptr; \
+ break; \
+ } \
+ ucptr = NULL; \
+ } else { \
+ UNPARSE(p, endp, uc); \
+ } \
+} while (0)
+
+/*
+ * Collect following decomposable code points.
+ */
+#define COLLECT_CPS(start) do { \
+ int _i; \
+ for (_i = start; _i < FDC_MAX ; _i++) { \
+ nx = parse(&ucx[_i], s, len); \
+ if (nx <= 0) \
+ break; \
+ cx = CCC(ucx[_i]); \
+ if (cl >= cx && cl != 228 && cx != 228)\
+ break; \
+ s += nx; \
+ len -= nx; \
+ cl = cx; \
+ ccx[_i] = cx; \
+ } \
+ if (_i >= FDC_MAX) { \
+ ret = -1; \
+ ucx_size = FDC_MAX; \
+ } else \
+ ucx_size = _i; \
+} while (0)
+
+/*
+ * Normalize UTF-8/UTF-16BE characters to Form C and copy the result.
+ *
+ * TODO: Convert composition exclusions,which are never converted
+ * from NFC,NFD,NFKC and NFKD, to Form C.
+ */
+static int
+archive_string_normalize_C(struct archive_string *as, const void *_p,
+ size_t len, struct archive_string_conv *sc)
+{
+ const char *s = (const char *)_p;
+ char *p, *endp;
+ uint32_t uc, uc2;
+ size_t w;
+ int always_replace, n, n2, ret = 0, spair, ts, tm;
+ int (*parse)(uint32_t *, const char *, size_t);
+ size_t (*unparse)(char *, size_t, uint32_t);
+
+ always_replace = 1;
+ ts = 1;/* text size. */
+ if (sc->flag & SCONV_TO_UTF16BE) {
+ unparse = unicode_to_utf16be;
+ ts = 2;
+ if (sc->flag & SCONV_FROM_UTF16BE)
+ always_replace = 0;
+ } else if (sc->flag & SCONV_TO_UTF16LE) {
+ unparse = unicode_to_utf16le;
+ ts = 2;
+ if (sc->flag & SCONV_FROM_UTF16LE)
+ always_replace = 0;
+ } else if (sc->flag & SCONV_TO_UTF8) {
+ unparse = unicode_to_utf8;
+ if (sc->flag & SCONV_FROM_UTF8)
+ always_replace = 0;
+ } else {
+ /*
+ * This case is going to be converted to another
+ * character-set through iconv.
+ */
+ always_replace = 0;
+ if (sc->flag & SCONV_FROM_UTF16BE) {
+ unparse = unicode_to_utf16be;
+ ts = 2;
+ } else if (sc->flag & SCONV_FROM_UTF16LE) {
+ unparse = unicode_to_utf16le;
+ ts = 2;
+ } else {
+ unparse = unicode_to_utf8;
+ }
+ }
+
+ if (sc->flag & SCONV_FROM_UTF16BE) {
+ parse = utf16be_to_unicode;
+ tm = 1;
+ spair = 4;/* surrogate pair size in UTF-16. */
+ } else if (sc->flag & SCONV_FROM_UTF16LE) {
+ parse = utf16le_to_unicode;
+ tm = 1;
+ spair = 4;/* surrogate pair size in UTF-16. */
+ } else {
+ parse = cesu8_to_unicode;
+ tm = ts;
+ spair = 6;/* surrogate pair size in UTF-8. */
+ }
+
+ if (archive_string_ensure(as, as->length + len * tm + ts) == NULL)
+ return (-1);
+
+ p = as->s + as->length;
+ endp = as->s + as->buffer_length - ts;
+ while ((n = parse(&uc, s, len)) != 0) {
+ const char *ucptr, *uc2ptr;
+
+ if (n < 0) {
+ /* Use a replaced unicode character. */
+ UNPARSE(p, endp, uc);
+ s += n*-1;
+ len -= n*-1;
+ ret = -1;
+ continue;
+ } else if (n == spair || always_replace)
+ /* uc is converted from a surrogate pair.
+ * this should be treated as a changed code. */
+ ucptr = NULL;
+ else
+ ucptr = s;
+ s += n;
+ len -= n;
+
+ /* Read second code point. */
+ while ((n2 = parse(&uc2, s, len)) > 0) {
+ uint32_t ucx[FDC_MAX];
+ int ccx[FDC_MAX];
+ int cl, cx, i, nx, ucx_size;
+ int LIndex,SIndex;
+ uint32_t nfc;
+
+ if (n2 == spair || always_replace)
+ /* uc2 is converted from a surrogate pair.
+ * this should be treated as a changed code. */
+ uc2ptr = NULL;
+ else
+ uc2ptr = s;
+ s += n2;
+ len -= n2;
+
+ /*
+ * If current second code point is out of decomposable
+ * code points, finding compositions is unneeded.
+ */
+ if (!IS_DECOMPOSABLE_BLOCK(uc2)) {
+ WRITE_UC();
+ REPLACE_UC_WITH_UC2();
+ continue;
+ }
+
+ /*
+ * Try to combine current code points.
+ */
+ /*
+ * We have to combine Hangul characters according to
+ * http://uniicode.org/reports/tr15/#Hangul
+ */
+ if (0 <= (LIndex = uc - HC_LBASE) &&
+ LIndex < HC_LCOUNT) {
+ /*
+ * Hangul Composition.
+ * 1. Two current code points are L and V.
+ */
+ int VIndex = uc2 - HC_VBASE;
+ if (0 <= VIndex && VIndex < HC_VCOUNT) {
+ /* Make syllable of form LV. */
+ UPDATE_UC(HC_SBASE +
+ (LIndex * HC_VCOUNT + VIndex) *
+ HC_TCOUNT);
+ } else {
+ WRITE_UC();
+ REPLACE_UC_WITH_UC2();
+ }
+ continue;
+ } else if (0 <= (SIndex = uc - HC_SBASE) &&
+ SIndex < HC_SCOUNT && (SIndex % HC_TCOUNT) == 0) {
+ /*
+ * Hangul Composition.
+ * 2. Two current code points are LV and T.
+ */
+ int TIndex = uc2 - HC_TBASE;
+ if (0 < TIndex && TIndex < HC_TCOUNT) {
+ /* Make syllable of form LVT. */
+ UPDATE_UC(uc + TIndex);
+ } else {
+ WRITE_UC();
+ REPLACE_UC_WITH_UC2();
+ }
+ continue;
+ } else if ((nfc = get_nfc(uc, uc2)) != 0) {
+ /* A composition to current code points
+ * is found. */
+ UPDATE_UC(nfc);
+ continue;
+ } else if ((cl = CCC(uc2)) == 0) {
+ /* Clearly 'uc2' the second code point is not
+ * a decomposable code. */
+ WRITE_UC();
+ REPLACE_UC_WITH_UC2();
+ continue;
+ }
+
+ /*
+ * Collect following decomposable code points.
+ */
+ cx = 0;
+ ucx[0] = uc2;
+ ccx[0] = cl;
+ COLLECT_CPS(1);
+
+ /*
+ * Find a composed code in the collected code points.
+ */
+ i = 1;
+ while (i < ucx_size) {
+ int j;
+
+ if ((nfc = get_nfc(uc, ucx[i])) == 0) {
+ i++;
+ continue;
+ }
+
+ /*
+ * nfc is composed of uc and ucx[i].
+ */
+ UPDATE_UC(nfc);
+
+ /*
+ * Remove ucx[i] by shifting
+ * following code points.
+ */
+ for (j = i; j+1 < ucx_size; j++) {
+ ucx[j] = ucx[j+1];
+ ccx[j] = ccx[j+1];
+ }
+ ucx_size --;
+
+ /*
+ * Collect following code points blocked
+ * by ucx[i] the removed code point.
+ */
+ if (ucx_size > 0 && i == ucx_size &&
+ nx > 0 && cx == cl) {
+ cl = ccx[ucx_size-1];
+ COLLECT_CPS(ucx_size);
+ }
+ /*
+ * Restart finding a composed code with
+ * the updated uc from the top of the
+ * collected code points.
+ */
+ i = 0;
+ }
+
+ /*
+ * Apparently the current code points are not
+ * decomposed characters or already composed.
+ */
+ WRITE_UC();
+ for (i = 0; i < ucx_size; i++)
+ UNPARSE(p, endp, ucx[i]);
+
+ /*
+ * Flush out remaining canonical combining characters.
+ */
+ if (nx > 0 && cx == cl && len > 0) {
+ while ((nx = parse(&ucx[0], s, len))
+ > 0) {
+ cx = CCC(ucx[0]);
+ if (cl > cx)
+ break;
+ s += nx;
+ len -= nx;
+ cl = cx;
+ UNPARSE(p, endp, ucx[0]);
+ }
+ }
+ break;
+ }
+ if (n2 < 0) {
+ WRITE_UC();
+ /* Use a replaced unicode character. */
+ UNPARSE(p, endp, uc2);
+ s += n2*-1;
+ len -= n2*-1;
+ ret = -1;
+ continue;
+ } else if (n2 == 0) {
+ WRITE_UC();
+ break;
+ }
+ }
+ as->length = p - as->s;
+ as->s[as->length] = '\0';
+ if (ts == 2)
+ as->s[as->length+1] = '\0';
+ return (ret);
+}
+
+static int
+get_nfd(uint32_t *cp1, uint32_t *cp2, uint32_t uc)
+{
+ int t, b;
+
+ /*
+ * These are not converted to NFD on Mac OS.
+ */
+ if ((uc >= 0x2000 && uc <= 0x2FFF) ||
+ (uc >= 0xF900 && uc <= 0xFAFF) ||
+ (uc >= 0x2F800 && uc <= 0x2FAFF))
+ return (0);
+ /*
+ * Those code points are not converted to NFD on Mac OS.
+ * I do not know the reason because it is undocumented.
+ * NFC NFD
+ * 1109A ==> 11099 110BA
+ * 1109C ==> 1109B 110BA
+ * 110AB ==> 110A5 110BA
+ */
+ if (uc == 0x1109A || uc == 0x1109C || uc == 0x110AB)
+ return (0);
+
+ t = 0;
+ b = sizeof(u_decomposition_table)/sizeof(u_decomposition_table[0]) -1;
+ while (b >= t) {
+ int m = (t + b) / 2;
+ if (u_decomposition_table[m].nfc < uc)
+ t = m + 1;
+ else if (u_decomposition_table[m].nfc > uc)
+ b = m - 1;
+ else {
+ *cp1 = u_decomposition_table[m].cp1;
+ *cp2 = u_decomposition_table[m].cp2;
+ return (1);
+ }
+ }
+ return (0);
+}
+
+#define REPLACE_UC_WITH(cp) do { \
+ uc = cp; \
+ ucptr = NULL; \
+} while (0)
+
+/*
+ * Normalize UTF-8 characters to Form D and copy the result.
+ */
+static int
+archive_string_normalize_D(struct archive_string *as, const void *_p,
+ size_t len, struct archive_string_conv *sc)
+{
+ const char *s = (const char *)_p;
+ char *p, *endp;
+ uint32_t uc, uc2;
+ size_t w;
+ int always_replace, n, n2, ret = 0, spair, ts, tm;
+ int (*parse)(uint32_t *, const char *, size_t);
+ size_t (*unparse)(char *, size_t, uint32_t);
+
+ always_replace = 1;
+ ts = 1;/* text size. */
+ if (sc->flag & SCONV_TO_UTF16BE) {
+ unparse = unicode_to_utf16be;
+ ts = 2;
+ if (sc->flag & SCONV_FROM_UTF16BE)
+ always_replace = 0;
+ } else if (sc->flag & SCONV_TO_UTF16LE) {
+ unparse = unicode_to_utf16le;
+ ts = 2;
+ if (sc->flag & SCONV_FROM_UTF16LE)
+ always_replace = 0;
+ } else if (sc->flag & SCONV_TO_UTF8) {
+ unparse = unicode_to_utf8;
+ if (sc->flag & SCONV_FROM_UTF8)
+ always_replace = 0;
+ } else {
+ /*
+ * This case is going to be converted to another
+ * character-set through iconv.
+ */
+ always_replace = 0;
+ if (sc->flag & SCONV_FROM_UTF16BE) {
+ unparse = unicode_to_utf16be;
+ ts = 2;
+ } else if (sc->flag & SCONV_FROM_UTF16LE) {
+ unparse = unicode_to_utf16le;
+ ts = 2;
+ } else {
+ unparse = unicode_to_utf8;
+ }
+ }
+
+ if (sc->flag & SCONV_FROM_UTF16BE) {
+ parse = utf16be_to_unicode;
+ tm = 1;
+ spair = 4;/* surrogate pair size in UTF-16. */
+ } else if (sc->flag & SCONV_FROM_UTF16LE) {
+ parse = utf16le_to_unicode;
+ tm = 1;
+ spair = 4;/* surrogate pair size in UTF-16. */
+ } else {
+ parse = cesu8_to_unicode;
+ tm = ts;
+ spair = 6;/* surrogate pair size in UTF-8. */
+ }
+
+ if (archive_string_ensure(as, as->length + len * tm + ts) == NULL)
+ return (-1);
+
+ p = as->s + as->length;
+ endp = as->s + as->buffer_length - ts;
+ while ((n = parse(&uc, s, len)) != 0) {
+ const char *ucptr;
+ uint32_t cp1, cp2;
+ int SIndex;
+ struct {
+ uint32_t uc;
+ int ccc;
+ } fdc[FDC_MAX];
+ int fdi, fdj;
+ int ccc;
+
+check_first_code:
+ if (n < 0) {
+ /* Use a replaced unicode character. */
+ UNPARSE(p, endp, uc);
+ s += n*-1;
+ len -= n*-1;
+ ret = -1;
+ continue;
+ } else if (n == spair || always_replace)
+ /* uc is converted from a surrogate pair.
+ * this should be treated as a changed code. */
+ ucptr = NULL;
+ else
+ ucptr = s;
+ s += n;
+ len -= n;
+
+ /* Hangul Decomposition. */
+ if ((SIndex = uc - HC_SBASE) >= 0 && SIndex < HC_SCOUNT) {
+ int L = HC_LBASE + SIndex / HC_NCOUNT;
+ int V = HC_VBASE + (SIndex % HC_NCOUNT) / HC_TCOUNT;
+ int T = HC_TBASE + SIndex % HC_TCOUNT;
+
+ REPLACE_UC_WITH(L);
+ WRITE_UC();
+ REPLACE_UC_WITH(V);
+ WRITE_UC();
+ if (T != HC_TBASE) {
+ REPLACE_UC_WITH(T);
+ WRITE_UC();
+ }
+ continue;
+ }
+ if (IS_DECOMPOSABLE_BLOCK(uc) && CCC(uc) != 0) {
+ WRITE_UC();
+ continue;
+ }
+
+ fdi = 0;
+ while (get_nfd(&cp1, &cp2, uc) && fdi < FDC_MAX) {
+ int k;
+
+ for (k = fdi; k > 0; k--)
+ fdc[k] = fdc[k-1];
+ fdc[0].ccc = CCC(cp2);
+ fdc[0].uc = cp2;
+ fdi++;
+ REPLACE_UC_WITH(cp1);
+ }
+
+ /* Read following code points. */
+ while ((n2 = parse(&uc2, s, len)) > 0 &&
+ (ccc = CCC(uc2)) != 0 && fdi < FDC_MAX) {
+ int j, k;
+
+ s += n2;
+ len -= n2;
+ for (j = 0; j < fdi; j++) {
+ if (fdc[j].ccc > ccc)
+ break;
+ }
+ if (j < fdi) {
+ for (k = fdi; k > j; k--)
+ fdc[k] = fdc[k-1];
+ fdc[j].ccc = ccc;
+ fdc[j].uc = uc2;
+ } else {
+ fdc[fdi].ccc = ccc;
+ fdc[fdi].uc = uc2;
+ }
+ fdi++;
+ }
+
+ WRITE_UC();
+ for (fdj = 0; fdj < fdi; fdj++) {
+ REPLACE_UC_WITH(fdc[fdj].uc);
+ WRITE_UC();
+ }
+
+ if (n2 == 0)
+ break;
+ REPLACE_UC_WITH(uc2);
+ n = n2;
+ goto check_first_code;
+ }
+ as->length = p - as->s;
+ as->s[as->length] = '\0';
+ if (ts == 2)
+ as->s[as->length+1] = '\0';
+ return (ret);
+}
+
+/*
+ * libarchive 2.x made incorrect UTF-8 strings in the wrong assumption
+ * that WCS is Unicode. It is true for several platforms but some are false.
+ * And then people who did not use UTF-8 locale on the non Unicode WCS
+ * platform and made a tar file with libarchive(mostly bsdtar) 2.x. Those
+ * now cannot get right filename from libarchive 3.x and later since we
+ * fixed the wrong assumption and it is incompatible to older its versions.
+ * So we provide special option, "compat-2x.x", for resolving it.
+ * That option enable the string conversion of libarchive 2.x.
+ *
+ * Translates the wrong UTF-8 string made by libarchive 2.x into current
+ * locale character set and appends to the archive_string.
+ * Note: returns -1 if conversion fails.
+ */
+static int
+strncat_from_utf8_libarchive2(struct archive_string *as,
+ const void *_p, size_t len, struct archive_string_conv *sc)
+{
+ const char *s;
+ int n;
+ char *p;
+ char *end;
+ uint32_t unicode;
+#if HAVE_WCRTOMB
+ mbstate_t shift_state;
+
+ memset(&shift_state, 0, sizeof(shift_state));
+#else
+ /* Clear the shift state before starting. */
+ wctomb(NULL, L'\0');
+#endif
+ (void)sc; /* UNUSED */
+ /*
+ * Allocate buffer for MBS.
+ * We need this allocation here since it is possible that
+ * as->s is still NULL.
+ */
+ if (archive_string_ensure(as, as->length + len + 1) == NULL)
+ return (-1);
+
+ s = (const char *)_p;
+ p = as->s + as->length;
+ end = as->s + as->buffer_length - MB_CUR_MAX -1;
+ while ((n = _utf8_to_unicode(&unicode, s, len)) != 0) {
+ wchar_t wc;
+
+ if (p >= end) {
+ as->length = p - as->s;
+ /* Re-allocate buffer for MBS. */
+ if (archive_string_ensure(as,
+ as->length + len * 2 + 1) == NULL)
+ return (-1);
+ p = as->s + as->length;
+ end = as->s + as->buffer_length - MB_CUR_MAX -1;
+ }
+
+ /*
+ * As libarchie 2.x, translates the UTF-8 characters into
+ * wide-characters in the assumption that WCS is Unicode.
+ */
+ if (n < 0) {
+ n *= -1;
+ wc = L'?';
+ } else
+ wc = (wchar_t)unicode;
+
+ s += n;
+ len -= n;
+ /*
+ * Translates the wide-character into the current locale MBS.
+ */
+#if HAVE_WCRTOMB
+ n = (int)wcrtomb(p, wc, &shift_state);
+#else
+ n = (int)wctomb(p, wc);
+#endif
+ if (n == -1)
+ return (-1);
+ p += n;
+ }
+ as->length = p - as->s;
+ as->s[as->length] = '\0';
+ return (0);
+}
+
+
+/*
+ * Conversion functions between current locale dependent MBS and UTF-16BE.
+ * strncat_from_utf16be() : UTF-16BE --> MBS
+ * strncat_to_utf16be() : MBS --> UTF16BE
+ */
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+/*
+ * Convert a UTF-16BE/LE string to current locale and copy the result.
+ * Return -1 if conversion failes.
+ */
+static int
+win_strncat_from_utf16(struct archive_string *as, const void *_p, size_t bytes,
+ struct archive_string_conv *sc, int be)
+{
+ struct archive_string tmp;
+ const char *u16;
+ int ll;
+ BOOL defchar;
+ char *mbs;
+ size_t mbs_size, b;
+ int ret = 0;
+
+ bytes &= ~1;
+ if (archive_string_ensure(as, as->length + bytes +1) == NULL)
+ return (-1);
+
+ mbs = as->s + as->length;
+ mbs_size = as->buffer_length - as->length -1;
+
+ if (sc->to_cp == CP_C_LOCALE) {
+ /*
+ * "C" locale special process.
+ */
+ u16 = _p;
+ ll = 0;
+ for (b = 0; b < bytes; b += 2) {
+ uint16_t val;
+ if (be)
+ val = archive_be16dec(u16+b);
+ else
+ val = archive_le16dec(u16+b);
+ if (val > 255) {
+ *mbs++ = '?';
+ ret = -1;
+ } else
+ *mbs++ = (char)(val&0xff);
+ ll++;
+ }
+ as->length += ll;
+ as->s[as->length] = '\0';
+ return (ret);
+ }
+
+ archive_string_init(&tmp);
+ if (be) {
+ if (is_big_endian()) {
+ u16 = _p;
+ } else {
+ if (archive_string_ensure(&tmp, bytes+2) == NULL)
+ return (-1);
+ memcpy(tmp.s, _p, bytes);
+ for (b = 0; b < bytes; b += 2) {
+ uint16_t val = archive_be16dec(tmp.s+b);
+ archive_le16enc(tmp.s+b, val);
+ }
+ u16 = tmp.s;
+ }
+ } else {
+ if (!is_big_endian()) {
+ u16 = _p;
+ } else {
+ if (archive_string_ensure(&tmp, bytes+2) == NULL)
+ return (-1);
+ memcpy(tmp.s, _p, bytes);
+ for (b = 0; b < bytes; b += 2) {
+ uint16_t val = archive_le16dec(tmp.s+b);
+ archive_be16enc(tmp.s+b, val);
+ }
+ u16 = tmp.s;
+ }
+ }
+
+ do {
+ defchar = 0;
+ ll = WideCharToMultiByte(sc->to_cp, 0,
+ (LPCWSTR)u16, (int)bytes>>1, mbs, (int)mbs_size,
+ NULL, &defchar);
+ if (ll == 0 &&
+ GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ /* Need more buffer for MBS. */
+ ll = WideCharToMultiByte(sc->to_cp, 0,
+ (LPCWSTR)u16, (int)bytes, NULL, 0, NULL, NULL);
+ if (archive_string_ensure(as, ll +1) == NULL)
+ return (-1);
+ mbs = as->s + as->length;
+ mbs_size = as->buffer_length - as->length -1;
+ continue;
+ }
+ } while (0);
+ archive_string_free(&tmp);
+ as->length += ll;
+ as->s[as->length] = '\0';
+ if (ll == 0 || defchar)
+ ret = -1;
+ return (ret);
+}
+
+static int
+win_strncat_from_utf16be(struct archive_string *as, const void *_p,
+ size_t bytes, struct archive_string_conv *sc)
+{
+ return (win_strncat_from_utf16(as, _p, bytes, sc, 1));
+}
+
+static int
+win_strncat_from_utf16le(struct archive_string *as, const void *_p,
+ size_t bytes, struct archive_string_conv *sc)
+{
+ return (win_strncat_from_utf16(as, _p, bytes, sc, 0));
+}
+
+static int
+is_big_endian(void)
+{
+ uint16_t d = 1;
+
+ return (archive_be16dec(&d) == 1);
+}
+
+/*
+ * Convert a current locale string to UTF-16BE/LE and copy the result.
+ * Return -1 if conversion failes.
+ */
+static int
+win_strncat_to_utf16(struct archive_string *as16, const void *_p,
+ size_t length, struct archive_string_conv *sc, int bigendian)
+{
+ const char *s = (const char *)_p;
+ char *u16;
+ size_t count, avail;
+
+ if (archive_string_ensure(as16,
+ as16->length + (length + 1) * 2) == NULL)
+ return (-1);
+
+ u16 = as16->s + as16->length;
+ avail = as16->buffer_length - 2;
+ if (sc->from_cp == CP_C_LOCALE) {
+ /*
+ * "C" locale special process.
+ */
+ count = 0;
+ while (count < length && *s) {
+ if (bigendian)
+ archive_be16enc(u16, *s);
+ else
+ archive_le16enc(u16, *s);
+ u16 += 2;
+ s++;
+ count++;
+ }
+ as16->length += count << 1;
+ as16->s[as16->length] = 0;
+ as16->s[as16->length+1] = 0;
+ return (0);
+ }
+ do {
+ count = MultiByteToWideChar(sc->from_cp,
+ MB_PRECOMPOSED, s, (int)length, (LPWSTR)u16, (int)avail>>1);
+ if (count == 0 &&
+ GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ /* Need more buffer for UTF-16 string */
+ count = MultiByteToWideChar(sc->from_cp,
+ MB_PRECOMPOSED, s, (int)length, NULL, 0);
+ if (archive_string_ensure(as16, (count +1) * 2)
+ == NULL)
+ return (-1);
+ u16 = as16->s + as16->length;
+ avail = as16->buffer_length - 2;
+ continue;
+ }
+ } while (0);
+ as16->length += count * 2;
+ as16->s[as16->length] = 0;
+ as16->s[as16->length+1] = 0;
+ if (count == 0)
+ return (-1);
+
+ if (is_big_endian()) {
+ if (!bigendian) {
+ while (count > 0) {
+ uint16_t v = archive_be16dec(u16);
+ archive_le16enc(u16, v);
+ u16 += 2;
+ count--;
+ }
+ }
+ } else {
+ if (bigendian) {
+ while (count > 0) {
+ uint16_t v = archive_le16dec(u16);
+ archive_be16enc(u16, v);
+ u16 += 2;
+ count--;
+ }
+ }
+ }
+ return (0);
+}
+
+static int
+win_strncat_to_utf16be(struct archive_string *as16, const void *_p,
+ size_t length, struct archive_string_conv *sc)
+{
+ return (win_strncat_to_utf16(as16, _p, length, sc, 1));
+}
+
+static int
+win_strncat_to_utf16le(struct archive_string *as16, const void *_p,
+ size_t length, struct archive_string_conv *sc)
+{
+ return (win_strncat_to_utf16(as16, _p, length, sc, 0));
+}
+
+#endif /* _WIN32 && !__CYGWIN__ */
+
+/*
+ * Do the best effort for conversions.
+ * We cannot handle UTF-16BE character-set without such iconv,
+ * but there is a chance if a string consists just ASCII code or
+ * a current locale is UTF-8.
+ */
+
+/*
+ * Convert a UTF-16BE string to current locale and copy the result.
+ * Return -1 if conversion failes.
+ */
+static int
+best_effort_strncat_from_utf16(struct archive_string *as, const void *_p,
+ size_t bytes, struct archive_string_conv *sc, int be)
+{
+ const char *utf16 = (const char *)_p;
+ char *mbs;
+ uint32_t uc;
+ int n, ret;
+
+ (void)sc; /* UNUSED */
+ /*
+ * Other case, we should do the best effort.
+ * If all character are ASCII(<0x7f), we can convert it.
+ * if not , we set a alternative character and return -1.
+ */
+ ret = 0;
+ if (archive_string_ensure(as, as->length + bytes +1) == NULL)
+ return (-1);
+ mbs = as->s + as->length;
+
+ while ((n = utf16_to_unicode(&uc, utf16, bytes, be)) != 0) {
+ if (n < 0) {
+ n *= -1;
+ ret = -1;
+ }
+ bytes -= n;
+ utf16 += n;
+
+ if (uc > 127) {
+ /* We cannot handle it. */
+ *mbs++ = '?';
+ ret = -1;
+ } else
+ *mbs++ = (char)uc;
+ }
+ as->length = mbs - as->s;
+ as->s[as->length] = '\0';
+ return (ret);
+}
+
+static int
+best_effort_strncat_from_utf16be(struct archive_string *as, const void *_p,
+ size_t bytes, struct archive_string_conv *sc)
+{
+ return (best_effort_strncat_from_utf16(as, _p, bytes, sc, 1));
+}
+
+static int
+best_effort_strncat_from_utf16le(struct archive_string *as, const void *_p,
+ size_t bytes, struct archive_string_conv *sc)
+{
+ return (best_effort_strncat_from_utf16(as, _p, bytes, sc, 0));
+}
+
+/*
+ * Convert a current locale string to UTF-16BE/LE and copy the result.
+ * Return -1 if conversion failes.
+ */
+static int
+best_effort_strncat_to_utf16(struct archive_string *as16, const void *_p,
+ size_t length, struct archive_string_conv *sc, int bigendian)
+{
+ const char *s = (const char *)_p;
+ char *utf16;
+ size_t remaining;
+ int ret;
+
+ (void)sc; /* UNUSED */
+ /*
+ * Other case, we should do the best effort.
+ * If all character are ASCII(<0x7f), we can convert it.
+ * if not , we set a alternative character and return -1.
+ */
+ ret = 0;
+ remaining = length;
+
+ if (archive_string_ensure(as16,
+ as16->length + (length + 1) * 2) == NULL)
+ return (-1);
+
+ utf16 = as16->s + as16->length;
+ while (remaining--) {
+ unsigned c = *s++;
+ if (c > 127) {
+ /* We cannot handle it. */
+ c = UNICODE_R_CHAR;
+ ret = -1;
+ }
+ if (bigendian)
+ archive_be16enc(utf16, c);
+ else
+ archive_le16enc(utf16, c);
+ utf16 += 2;
+ }
+ as16->length = utf16 - as16->s;
+ as16->s[as16->length] = 0;
+ as16->s[as16->length+1] = 0;
+ return (ret);
+}
+
+static int
+best_effort_strncat_to_utf16be(struct archive_string *as16, const void *_p,
+ size_t length, struct archive_string_conv *sc)
+{
+ return (best_effort_strncat_to_utf16(as16, _p, length, sc, 1));
+}
+
+static int
+best_effort_strncat_to_utf16le(struct archive_string *as16, const void *_p,
+ size_t length, struct archive_string_conv *sc)
+{
+ return (best_effort_strncat_to_utf16(as16, _p, length, sc, 0));
+}
+
+
+/*
+ * Multistring operations.
+ */
+
+void
+archive_mstring_clean(struct archive_mstring *aes)
+{
+ archive_wstring_free(&(aes->aes_wcs));
+ archive_string_free(&(aes->aes_mbs));
+ archive_string_free(&(aes->aes_utf8));
+ archive_string_free(&(aes->aes_mbs_in_locale));
+ aes->aes_set = 0;
+}
+
+void
+archive_mstring_copy(struct archive_mstring *dest, struct archive_mstring *src)
+{
+ dest->aes_set = src->aes_set;
+ archive_string_copy(&(dest->aes_mbs), &(src->aes_mbs));
+ archive_string_copy(&(dest->aes_utf8), &(src->aes_utf8));
+ archive_wstring_copy(&(dest->aes_wcs), &(src->aes_wcs));
+}
+
+int
+archive_mstring_get_utf8(struct archive *a, struct archive_mstring *aes,
+ const char **p)
+{
+ struct archive_string_conv *sc;
+ int r;
+
+ /* If we already have a UTF8 form, return that immediately. */
+ if (aes->aes_set & AES_SET_UTF8) {
+ *p = aes->aes_utf8.s;
+ return (0);
+ }
+
+ *p = NULL;
+ if (aes->aes_set & AES_SET_MBS) {
+ 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,
+ aes->aes_mbs.length, sc);
+ if (a == NULL)
+ free_sconv_object(sc);
+ if (r == 0) {
+ aes->aes_set |= AES_SET_UTF8;
+ *p = aes->aes_utf8.s;
+ return (0);/* success. */
+ } else
+ return (-1);/* failure. */
+ }
+ return (0);/* success. */
+}
+
+int
+archive_mstring_get_mbs(struct archive *a, struct archive_mstring *aes,
+ const char **p)
+{
+ int r, ret = 0;
+
+ (void)a; /* UNUSED */
+ /* If we already have an MBS form, return that immediately. */
+ if (aes->aes_set & AES_SET_MBS) {
+ *p = aes->aes_mbs.s;
+ return (ret);
+ }
+
+ *p = NULL;
+ /* If there's a WCS form, try converting with the native locale. */
+ if (aes->aes_set & AES_SET_WCS) {
+ archive_string_empty(&(aes->aes_mbs));
+ r = archive_string_append_from_wcs(&(aes->aes_mbs),
+ aes->aes_wcs.s, aes->aes_wcs.length);
+ *p = aes->aes_mbs.s;
+ if (r == 0) {
+ aes->aes_set |= AES_SET_MBS;
+ return (ret);
+ } else
+ ret = -1;
+ }
+
+ /*
+ * Only a UTF-8 form cannot avail because its conversion already
+ * failed at archive_mstring_update_utf8().
+ */
+ return (ret);
+}
+
+int
+archive_mstring_get_wcs(struct archive *a, struct archive_mstring *aes,
+ const wchar_t **wp)
+{
+ int r, ret = 0;
+
+ (void)a;/* UNUSED */
+ /* Return WCS form if we already have it. */
+ if (aes->aes_set & AES_SET_WCS) {
+ *wp = aes->aes_wcs.s;
+ return (ret);
+ }
+
+ *wp = NULL;
+ /* Try converting MBS to WCS using native locale. */
+ if (aes->aes_set & AES_SET_MBS) {
+ archive_wstring_empty(&(aes->aes_wcs));
+ r = archive_wstring_append_from_mbs(&(aes->aes_wcs),
+ aes->aes_mbs.s, aes->aes_mbs.length);
+ if (r == 0) {
+ aes->aes_set |= AES_SET_WCS;
+ *wp = aes->aes_wcs.s;
+ } else
+ ret = -1;/* failure. */
+ }
+ return (ret);
+}
+
+int
+archive_mstring_get_mbs_l(struct archive_mstring *aes,
+ const char **p, size_t *length, struct archive_string_conv *sc)
+{
+ int r, ret = 0;
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /*
+ * Internationalization programing on Windows must use Wide
+ * characters because Windows platform cannot make locale UTF-8.
+ */
+ if (sc != NULL && (aes->aes_set & AES_SET_WCS) != 0) {
+ archive_string_empty(&(aes->aes_mbs_in_locale));
+ r = archive_string_append_from_wcs_in_codepage(
+ &(aes->aes_mbs_in_locale), aes->aes_wcs.s,
+ aes->aes_wcs.length, sc);
+ if (r == 0) {
+ *p = aes->aes_mbs_in_locale.s;
+ if (length != NULL)
+ *length = aes->aes_mbs_in_locale.length;
+ return (0);
+ } else if (errno == ENOMEM)
+ return (-1);
+ else
+ ret = -1;
+ }
+#endif
+
+ /* If there is not an MBS form but is a WCS form, try converting
+ * with the native locale to be used for translating it to specified
+ * character-set. */
+ if ((aes->aes_set & AES_SET_MBS) == 0 &&
+ (aes->aes_set & AES_SET_WCS) != 0) {
+ archive_string_empty(&(aes->aes_mbs));
+ r = archive_string_append_from_wcs(&(aes->aes_mbs),
+ aes->aes_wcs.s, aes->aes_wcs.length);
+ if (r == 0)
+ aes->aes_set |= AES_SET_MBS;
+ else if (errno == ENOMEM)
+ return (-1);
+ else
+ ret = -1;
+ }
+ /* If we already have an MBS form, use it to be translated to
+ * specified character-set. */
+ if (aes->aes_set & AES_SET_MBS) {
+ if (sc == NULL) {
+ /* Conversion is unneeded. */
+ *p = aes->aes_mbs.s;
+ if (length != NULL)
+ *length = aes->aes_mbs.length;
+ return (0);
+ }
+ ret = archive_strncpy_l(&(aes->aes_mbs_in_locale),
+ aes->aes_mbs.s, aes->aes_mbs.length, sc);
+ *p = aes->aes_mbs_in_locale.s;
+ if (length != NULL)
+ *length = aes->aes_mbs_in_locale.length;
+ } else {
+ *p = NULL;
+ if (length != NULL)
+ *length = 0;
+ }
+ return (ret);
+}
+
+int
+archive_mstring_copy_mbs(struct archive_mstring *aes, const char *mbs)
+{
+ if (mbs == NULL) {
+ aes->aes_set = 0;
+ return (0);
+ }
+ return (archive_mstring_copy_mbs_len(aes, mbs, strlen(mbs)));
+}
+
+int
+archive_mstring_copy_mbs_len(struct archive_mstring *aes, const char *mbs,
+ size_t len)
+{
+ if (mbs == NULL) {
+ aes->aes_set = 0;
+ return (0);
+ }
+ aes->aes_set = AES_SET_MBS; /* Only MBS form is set now. */
+ archive_strncpy(&(aes->aes_mbs), mbs, len);
+ archive_string_empty(&(aes->aes_utf8));
+ archive_wstring_empty(&(aes->aes_wcs));
+ return (0);
+}
+
+int
+archive_mstring_copy_wcs(struct archive_mstring *aes, const wchar_t *wcs)
+{
+ return archive_mstring_copy_wcs_len(aes, wcs,
+ wcs == NULL ? 0 : wcslen(wcs));
+}
+
+int
+archive_mstring_copy_wcs_len(struct archive_mstring *aes, const wchar_t *wcs,
+ size_t len)
+{
+ if (wcs == NULL) {
+ aes->aes_set = 0;
+ }
+ aes->aes_set = AES_SET_WCS; /* Only WCS form set. */
+ archive_string_empty(&(aes->aes_mbs));
+ archive_string_empty(&(aes->aes_utf8));
+ archive_wstrncpy(&(aes->aes_wcs), wcs, len);
+ return (0);
+}
+
+int
+archive_mstring_copy_mbs_len_l(struct archive_mstring *aes,
+ const char *mbs, size_t len, struct archive_string_conv *sc)
+{
+ int r;
+
+ if (mbs == NULL) {
+ aes->aes_set = 0;
+ return (0);
+ }
+ archive_string_empty(&(aes->aes_mbs));
+ archive_wstring_empty(&(aes->aes_wcs));
+ archive_string_empty(&(aes->aes_utf8));
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /*
+ * Internationalization programing on Windows must use Wide
+ * characters because Windows platform cannot make locale UTF-8.
+ */
+ if (sc == NULL) {
+ if (archive_string_append(&(aes->aes_mbs),
+ mbs, mbsnbytes(mbs, len)) == NULL) {
+ aes->aes_set = 0;
+ r = -1;
+ } else {
+ aes->aes_set = AES_SET_MBS;
+ r = 0;
+ }
+#if defined(HAVE_ICONV)
+ } else if (sc != NULL && sc->cd_w != (iconv_t)-1) {
+ /*
+ * This case happens only when MultiByteToWideChar() cannot
+ * handle sc->from_cp, and we have to iconv in order to
+ * translate character-set to wchar_t,UTF-16.
+ */
+ iconv_t cd = sc->cd;
+ unsigned from_cp;
+ int flag;
+
+ /*
+ * Translate multi-bytes from some character-set to UTF-8.
+ */
+ sc->cd = sc->cd_w;
+ r = archive_strncpy_l(&(aes->aes_utf8), mbs, len, sc);
+ sc->cd = cd;
+ if (r != 0) {
+ aes->aes_set = 0;
+ return (r);
+ }
+ aes->aes_set = AES_SET_UTF8;
+
+ /*
+ * Append the UTF-8 string into wstring.
+ */
+ flag = sc->flag;
+ sc->flag &= ~(SCONV_NORMALIZATION_C
+ | SCONV_TO_UTF16| SCONV_FROM_UTF16);
+ from_cp = sc->from_cp;
+ sc->from_cp = CP_UTF8;
+ r = archive_wstring_append_from_mbs_in_codepage(&(aes->aes_wcs),
+ aes->aes_utf8.s, aes->aes_utf8.length, sc);
+ sc->flag = flag;
+ sc->from_cp = from_cp;
+ if (r == 0)
+ aes->aes_set |= AES_SET_WCS;
+#endif
+ } else {
+ r = archive_wstring_append_from_mbs_in_codepage(
+ &(aes->aes_wcs), mbs, len, sc);
+ if (r == 0)
+ aes->aes_set = AES_SET_WCS;
+ else
+ aes->aes_set = 0;
+ }
+#else
+ r = archive_strncpy_l(&(aes->aes_mbs), mbs, len, sc);
+ if (r == 0)
+ aes->aes_set = AES_SET_MBS; /* Only MBS form is set now. */
+ else
+ aes->aes_set = 0;
+#endif
+ return (r);
+}
+
+/*
+ * The 'update' form tries to proactively update all forms of
+ * this string (WCS and MBS) and returns an error if any of
+ * them fail. This is used by the 'pax' handler, for instance,
+ * to detect and report character-conversion failures early while
+ * still allowing clients to get potentially useful values from
+ * the more tolerant lazy conversions. (get_mbs and get_wcs will
+ * strive to give the user something useful, so you can get hopefully
+ * usable values even if some of the character conversions are failing.)
+ */
+int
+archive_mstring_update_utf8(struct archive *a, struct archive_mstring *aes,
+ const char *utf8)
+{
+ struct archive_string_conv *sc;
+ int r;
+
+ if (utf8 == NULL) {
+ aes->aes_set = 0;
+ return (0); /* Succeeded in clearing everything. */
+ }
+
+ /* Save the UTF8 string. */
+ archive_strcpy(&(aes->aes_utf8), utf8);
+
+ /* Empty the mbs and wcs strings. */
+ archive_string_empty(&(aes->aes_mbs));
+ archive_wstring_empty(&(aes->aes_wcs));
+
+ aes->aes_set = AES_SET_UTF8; /* Only UTF8 is set now. */
+
+ /* Try converting UTF-8 to MBS, return false on failure. */
+ sc = archive_string_conversion_from_charset(a, "UTF-8", 1);
+ if (sc == NULL)
+ return (-1);/* Couldn't allocate memory for sc. */
+ r = archive_strcpy_l(&(aes->aes_mbs), utf8, sc);
+ if (a == NULL)
+ free_sconv_object(sc);
+ if (r != 0)
+ return (-1);
+ aes->aes_set = AES_SET_UTF8 | AES_SET_MBS; /* Both UTF8 and MBS set. */
+
+ /* Try converting MBS to WCS, return false on failure. */
+ if (archive_wstring_append_from_mbs(&(aes->aes_wcs), aes->aes_mbs.s,
+ aes->aes_mbs.length))
+ return (-1);
+ aes->aes_set = AES_SET_UTF8 | AES_SET_WCS | AES_SET_MBS;
+
+ /* All conversions succeeded. */
+ return (0);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_string.h b/Utilities/cmlibarchive/libarchive/archive_string.h
new file mode 100644
index 0000000000..23f4916574
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_string.h
@@ -0,0 +1,239 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_string.h 201092 2009-12-28 02:26:06Z kientzle $
+ *
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#ifndef __LIBARCHIVE_TEST
+#error This header is only to be used internally to libarchive.
+#endif
+#endif
+
+#ifndef ARCHIVE_STRING_H_INCLUDED
+#define ARCHIVE_STRING_H_INCLUDED
+
+#include <stdarg.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* required for wchar_t on some systems */
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+
+#include "archive.h"
+
+/*
+ * Basic resizable/reusable string support similar to Java's "StringBuffer."
+ *
+ * Unlike sbuf(9), the buffers here are fully reusable and track the
+ * length throughout.
+ */
+
+struct archive_string {
+ char *s; /* Pointer to the storage */
+ size_t length; /* Length of 's' in characters */
+ size_t buffer_length; /* Length of malloc-ed storage in bytes. */
+};
+
+struct archive_wstring {
+ wchar_t *s; /* Pointer to the storage */
+ size_t length; /* Length of 's' in characters */
+ size_t buffer_length; /* Length of malloc-ed storage in bytes. */
+};
+
+struct archive_string_conv;
+
+/* Initialize an archive_string object on the stack or elsewhere. */
+#define archive_string_init(a) \
+ do { (a)->s = NULL; (a)->length = 0; (a)->buffer_length = 0; } while(0)
+
+/* Append a C char to an archive_string, resizing as necessary. */
+struct archive_string *
+archive_strappend_char(struct archive_string *, char);
+
+/* Ditto for a wchar_t and an archive_wstring. */
+struct archive_wstring *
+archive_wstrappend_wchar(struct archive_wstring *, wchar_t);
+
+/* Convert a Unicode string to current locale and append the result. */
+/* Returns -1 if conversion fails. */
+int
+archive_string_append_from_wcs(struct archive_string *, const wchar_t *, size_t);
+
+
+/* Create a string conversion object.
+ * Return NULL and set a error message if the conversion is not supported
+ * on the platform. */
+struct archive_string_conv *
+archive_string_conversion_to_charset(struct archive *, const char *, int);
+struct archive_string_conv *
+archive_string_conversion_from_charset(struct archive *, const char *, int);
+/* Create the default string conversion object for reading/writing an archive.
+ * Return NULL if the conversion is unneeded.
+ * Note: On non Windows platform this always returns NULL.
+ */
+struct archive_string_conv *
+archive_string_default_conversion_for_read(struct archive *);
+struct archive_string_conv *
+archive_string_default_conversion_for_write(struct archive *);
+/* Dispose of a string conversion object. */
+void
+archive_string_conversion_free(struct archive *);
+const char *
+archive_string_conversion_charset_name(struct archive_string_conv *);
+void
+archive_string_conversion_set_opt(struct archive_string_conv *, int);
+#define SCONV_SET_OPT_UTF8_LIBARCHIVE2X 1
+#define SCONV_SET_OPT_NORMALIZATION_C 2
+#define SCONV_SET_OPT_NORMALIZATION_D 4
+
+
+/* Copy one archive_string to another in locale conversion.
+ * Return -1 if conversion failes. */
+int
+archive_strncpy_l(struct archive_string *, const void *, size_t,
+ struct archive_string_conv *);
+
+/* Copy one archive_string to another in locale conversion.
+ * Return -1 if conversion failes. */
+int
+archive_strncat_l(struct archive_string *, const void *, size_t,
+ struct archive_string_conv *);
+
+
+/* Copy one archive_string to another */
+#define archive_string_copy(dest, src) \
+ ((dest)->length = 0, archive_string_concat((dest), (src)))
+#define archive_wstring_copy(dest, src) \
+ ((dest)->length = 0, archive_wstring_concat((dest), (src)))
+
+/* Concatenate one archive_string to another */
+void archive_string_concat(struct archive_string *dest, struct archive_string *src);
+void archive_wstring_concat(struct archive_wstring *dest, struct archive_wstring *src);
+
+/* Ensure that the underlying buffer is at least as large as the request. */
+struct archive_string *
+archive_string_ensure(struct archive_string *, size_t);
+struct archive_wstring *
+archive_wstring_ensure(struct archive_wstring *, size_t);
+
+/* Append C string, which may lack trailing \0. */
+/* The source is declared void * here because this gets used with
+ * "signed char *", "unsigned char *" and "char *" arguments.
+ * Declaring it "char *" as with some of the other functions just
+ * leads to a lot of extra casts. */
+struct archive_string *
+archive_strncat(struct archive_string *, const void *, size_t);
+struct archive_wstring *
+archive_wstrncat(struct archive_wstring *, const wchar_t *, size_t);
+
+/* Append a C string to an archive_string, resizing as necessary. */
+struct archive_string *
+archive_strcat(struct archive_string *, const void *);
+struct archive_wstring *
+archive_wstrcat(struct archive_wstring *, const wchar_t *);
+
+/* Copy a C string to an archive_string, resizing as necessary. */
+#define archive_strcpy(as,p) \
+ archive_strncpy((as), (p), ((p) == NULL ? 0 : strlen(p)))
+#define archive_wstrcpy(as,p) \
+ archive_wstrncpy((as), (p), ((p) == NULL ? 0 : wcslen(p)))
+#define archive_strcpy_l(as,p,lo) \
+ archive_strncpy_l((as), (p), ((p) == NULL ? 0 : strlen(p)), (lo))
+
+/* Copy a C string to an archive_string with limit, resizing as necessary. */
+#define archive_strncpy(as,p,l) \
+ ((as)->length=0, archive_strncat((as), (p), (l)))
+#define archive_wstrncpy(as,p,l) \
+ ((as)->length = 0, archive_wstrncat((as), (p), (l)))
+
+/* Return length of string. */
+#define archive_strlen(a) ((a)->length)
+
+/* Set string length to zero. */
+#define archive_string_empty(a) ((a)->length = 0)
+#define archive_wstring_empty(a) ((a)->length = 0)
+
+/* Release any allocated storage resources. */
+void archive_string_free(struct archive_string *);
+void archive_wstring_free(struct archive_wstring *);
+
+/* Like 'vsprintf', but resizes the underlying string as necessary. */
+/* Note: This only implements a small subset of standard printf functionality. */
+void archive_string_vsprintf(struct archive_string *, const char *,
+ va_list) __LA_PRINTF(2, 0);
+void archive_string_sprintf(struct archive_string *, const char *, ...)
+ __LA_PRINTF(2, 3);
+
+/* Translates from MBS to Unicode. */
+/* Returns non-zero if conversion failed in any way. */
+int archive_wstring_append_from_mbs(struct archive_wstring *dest,
+ const char *, size_t);
+
+
+/* A "multistring" can hold Unicode, UTF8, or MBS versions of
+ * the string. If you set and read the same version, no translation
+ * is done. If you set and read different versions, the library
+ * will attempt to transparently convert.
+ */
+struct archive_mstring {
+ struct archive_string aes_mbs;
+ struct archive_string aes_utf8;
+ struct archive_wstring aes_wcs;
+ struct archive_string aes_mbs_in_locale;
+ /* Bitmap of which of the above are valid. Because we're lazy
+ * about malloc-ing and reusing the underlying storage, we
+ * can't rely on NULL pointers to indicate whether a string
+ * has been set. */
+ int aes_set;
+#define AES_SET_MBS 1
+#define AES_SET_UTF8 2
+#define AES_SET_WCS 4
+};
+
+void archive_mstring_clean(struct archive_mstring *);
+void archive_mstring_copy(struct archive_mstring *dest, struct archive_mstring *src);
+int archive_mstring_get_mbs(struct archive *, struct archive_mstring *, const char **);
+int archive_mstring_get_utf8(struct archive *, struct archive_mstring *, const char **);
+int archive_mstring_get_wcs(struct archive *, struct archive_mstring *, const wchar_t **);
+int archive_mstring_get_mbs_l(struct archive_mstring *, const char **,
+ size_t *, struct archive_string_conv *);
+int archive_mstring_copy_mbs(struct archive_mstring *, const char *mbs);
+int archive_mstring_copy_mbs_len(struct archive_mstring *, const char *mbs,
+ size_t);
+int archive_mstring_copy_utf8(struct archive_mstring *, const char *utf8);
+int archive_mstring_copy_wcs(struct archive_mstring *, const wchar_t *wcs);
+int archive_mstring_copy_wcs_len(struct archive_mstring *,
+ const wchar_t *wcs, size_t);
+int archive_mstring_copy_mbs_len_l(struct archive_mstring *,
+ const char *mbs, size_t, struct archive_string_conv *);
+int archive_mstring_update_utf8(struct archive *, struct archive_mstring *aes, const char *utf8);
+
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_string_composition.h b/Utilities/cmlibarchive/libarchive/archive_string_composition.h
new file mode 100644
index 0000000000..be41e33651
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_string_composition.h
@@ -0,0 +1,2292 @@
+/*-
+ * Copyright (c) 2011-2012 libarchive Project
+ * 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.
+ *
+ * $FreeBSD$
+ *
+ */
+
+/*
+ * ATTENTION!
+ * This file is generated by build/utils/gen_archive_string_composition_h.sh
+ * from http://unicode.org/Public/6.0.0/ucd/UnicodeData.txt
+ *
+ * See also http://unicode.org/report/tr15/
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_STRING_COMPOSITION_H_INCLUDED
+#define ARCHIVE_STRING_COMPOSITION_H_INCLUDED
+
+struct unicode_composition_table {
+ uint32_t cp1;
+ uint32_t cp2;
+ uint32_t nfc;
+};
+
+static const struct unicode_composition_table u_composition_table[] = {
+ { 0x0003C , 0x00338 , 0x0226E },
+ { 0x0003D , 0x00338 , 0x02260 },
+ { 0x0003E , 0x00338 , 0x0226F },
+ { 0x00041 , 0x00300 , 0x000C0 },
+ { 0x00041 , 0x00301 , 0x000C1 },
+ { 0x00041 , 0x00302 , 0x000C2 },
+ { 0x00041 , 0x00303 , 0x000C3 },
+ { 0x00041 , 0x00304 , 0x00100 },
+ { 0x00041 , 0x00306 , 0x00102 },
+ { 0x00041 , 0x00307 , 0x00226 },
+ { 0x00041 , 0x00308 , 0x000C4 },
+ { 0x00041 , 0x00309 , 0x01EA2 },
+ { 0x00041 , 0x0030A , 0x000C5 },
+ { 0x00041 , 0x0030C , 0x001CD },
+ { 0x00041 , 0x0030F , 0x00200 },
+ { 0x00041 , 0x00311 , 0x00202 },
+ { 0x00041 , 0x00323 , 0x01EA0 },
+ { 0x00041 , 0x00325 , 0x01E00 },
+ { 0x00041 , 0x00328 , 0x00104 },
+ { 0x00042 , 0x00307 , 0x01E02 },
+ { 0x00042 , 0x00323 , 0x01E04 },
+ { 0x00042 , 0x00331 , 0x01E06 },
+ { 0x00043 , 0x00301 , 0x00106 },
+ { 0x00043 , 0x00302 , 0x00108 },
+ { 0x00043 , 0x00307 , 0x0010A },
+ { 0x00043 , 0x0030C , 0x0010C },
+ { 0x00043 , 0x00327 , 0x000C7 },
+ { 0x00044 , 0x00307 , 0x01E0A },
+ { 0x00044 , 0x0030C , 0x0010E },
+ { 0x00044 , 0x00323 , 0x01E0C },
+ { 0x00044 , 0x00327 , 0x01E10 },
+ { 0x00044 , 0x0032D , 0x01E12 },
+ { 0x00044 , 0x00331 , 0x01E0E },
+ { 0x00045 , 0x00300 , 0x000C8 },
+ { 0x00045 , 0x00301 , 0x000C9 },
+ { 0x00045 , 0x00302 , 0x000CA },
+ { 0x00045 , 0x00303 , 0x01EBC },
+ { 0x00045 , 0x00304 , 0x00112 },
+ { 0x00045 , 0x00306 , 0x00114 },
+ { 0x00045 , 0x00307 , 0x00116 },
+ { 0x00045 , 0x00308 , 0x000CB },
+ { 0x00045 , 0x00309 , 0x01EBA },
+ { 0x00045 , 0x0030C , 0x0011A },
+ { 0x00045 , 0x0030F , 0x00204 },
+ { 0x00045 , 0x00311 , 0x00206 },
+ { 0x00045 , 0x00323 , 0x01EB8 },
+ { 0x00045 , 0x00327 , 0x00228 },
+ { 0x00045 , 0x00328 , 0x00118 },
+ { 0x00045 , 0x0032D , 0x01E18 },
+ { 0x00045 , 0x00330 , 0x01E1A },
+ { 0x00046 , 0x00307 , 0x01E1E },
+ { 0x00047 , 0x00301 , 0x001F4 },
+ { 0x00047 , 0x00302 , 0x0011C },
+ { 0x00047 , 0x00304 , 0x01E20 },
+ { 0x00047 , 0x00306 , 0x0011E },
+ { 0x00047 , 0x00307 , 0x00120 },
+ { 0x00047 , 0x0030C , 0x001E6 },
+ { 0x00047 , 0x00327 , 0x00122 },
+ { 0x00048 , 0x00302 , 0x00124 },
+ { 0x00048 , 0x00307 , 0x01E22 },
+ { 0x00048 , 0x00308 , 0x01E26 },
+ { 0x00048 , 0x0030C , 0x0021E },
+ { 0x00048 , 0x00323 , 0x01E24 },
+ { 0x00048 , 0x00327 , 0x01E28 },
+ { 0x00048 , 0x0032E , 0x01E2A },
+ { 0x00049 , 0x00300 , 0x000CC },
+ { 0x00049 , 0x00301 , 0x000CD },
+ { 0x00049 , 0x00302 , 0x000CE },
+ { 0x00049 , 0x00303 , 0x00128 },
+ { 0x00049 , 0x00304 , 0x0012A },
+ { 0x00049 , 0x00306 , 0x0012C },
+ { 0x00049 , 0x00307 , 0x00130 },
+ { 0x00049 , 0x00308 , 0x000CF },
+ { 0x00049 , 0x00309 , 0x01EC8 },
+ { 0x00049 , 0x0030C , 0x001CF },
+ { 0x00049 , 0x0030F , 0x00208 },
+ { 0x00049 , 0x00311 , 0x0020A },
+ { 0x00049 , 0x00323 , 0x01ECA },
+ { 0x00049 , 0x00328 , 0x0012E },
+ { 0x00049 , 0x00330 , 0x01E2C },
+ { 0x0004A , 0x00302 , 0x00134 },
+ { 0x0004B , 0x00301 , 0x01E30 },
+ { 0x0004B , 0x0030C , 0x001E8 },
+ { 0x0004B , 0x00323 , 0x01E32 },
+ { 0x0004B , 0x00327 , 0x00136 },
+ { 0x0004B , 0x00331 , 0x01E34 },
+ { 0x0004C , 0x00301 , 0x00139 },
+ { 0x0004C , 0x0030C , 0x0013D },
+ { 0x0004C , 0x00323 , 0x01E36 },
+ { 0x0004C , 0x00327 , 0x0013B },
+ { 0x0004C , 0x0032D , 0x01E3C },
+ { 0x0004C , 0x00331 , 0x01E3A },
+ { 0x0004D , 0x00301 , 0x01E3E },
+ { 0x0004D , 0x00307 , 0x01E40 },
+ { 0x0004D , 0x00323 , 0x01E42 },
+ { 0x0004E , 0x00300 , 0x001F8 },
+ { 0x0004E , 0x00301 , 0x00143 },
+ { 0x0004E , 0x00303 , 0x000D1 },
+ { 0x0004E , 0x00307 , 0x01E44 },
+ { 0x0004E , 0x0030C , 0x00147 },
+ { 0x0004E , 0x00323 , 0x01E46 },
+ { 0x0004E , 0x00327 , 0x00145 },
+ { 0x0004E , 0x0032D , 0x01E4A },
+ { 0x0004E , 0x00331 , 0x01E48 },
+ { 0x0004F , 0x00300 , 0x000D2 },
+ { 0x0004F , 0x00301 , 0x000D3 },
+ { 0x0004F , 0x00302 , 0x000D4 },
+ { 0x0004F , 0x00303 , 0x000D5 },
+ { 0x0004F , 0x00304 , 0x0014C },
+ { 0x0004F , 0x00306 , 0x0014E },
+ { 0x0004F , 0x00307 , 0x0022E },
+ { 0x0004F , 0x00308 , 0x000D6 },
+ { 0x0004F , 0x00309 , 0x01ECE },
+ { 0x0004F , 0x0030B , 0x00150 },
+ { 0x0004F , 0x0030C , 0x001D1 },
+ { 0x0004F , 0x0030F , 0x0020C },
+ { 0x0004F , 0x00311 , 0x0020E },
+ { 0x0004F , 0x0031B , 0x001A0 },
+ { 0x0004F , 0x00323 , 0x01ECC },
+ { 0x0004F , 0x00328 , 0x001EA },
+ { 0x00050 , 0x00301 , 0x01E54 },
+ { 0x00050 , 0x00307 , 0x01E56 },
+ { 0x00052 , 0x00301 , 0x00154 },
+ { 0x00052 , 0x00307 , 0x01E58 },
+ { 0x00052 , 0x0030C , 0x00158 },
+ { 0x00052 , 0x0030F , 0x00210 },
+ { 0x00052 , 0x00311 , 0x00212 },
+ { 0x00052 , 0x00323 , 0x01E5A },
+ { 0x00052 , 0x00327 , 0x00156 },
+ { 0x00052 , 0x00331 , 0x01E5E },
+ { 0x00053 , 0x00301 , 0x0015A },
+ { 0x00053 , 0x00302 , 0x0015C },
+ { 0x00053 , 0x00307 , 0x01E60 },
+ { 0x00053 , 0x0030C , 0x00160 },
+ { 0x00053 , 0x00323 , 0x01E62 },
+ { 0x00053 , 0x00326 , 0x00218 },
+ { 0x00053 , 0x00327 , 0x0015E },
+ { 0x00054 , 0x00307 , 0x01E6A },
+ { 0x00054 , 0x0030C , 0x00164 },
+ { 0x00054 , 0x00323 , 0x01E6C },
+ { 0x00054 , 0x00326 , 0x0021A },
+ { 0x00054 , 0x00327 , 0x00162 },
+ { 0x00054 , 0x0032D , 0x01E70 },
+ { 0x00054 , 0x00331 , 0x01E6E },
+ { 0x00055 , 0x00300 , 0x000D9 },
+ { 0x00055 , 0x00301 , 0x000DA },
+ { 0x00055 , 0x00302 , 0x000DB },
+ { 0x00055 , 0x00303 , 0x00168 },
+ { 0x00055 , 0x00304 , 0x0016A },
+ { 0x00055 , 0x00306 , 0x0016C },
+ { 0x00055 , 0x00308 , 0x000DC },
+ { 0x00055 , 0x00309 , 0x01EE6 },
+ { 0x00055 , 0x0030A , 0x0016E },
+ { 0x00055 , 0x0030B , 0x00170 },
+ { 0x00055 , 0x0030C , 0x001D3 },
+ { 0x00055 , 0x0030F , 0x00214 },
+ { 0x00055 , 0x00311 , 0x00216 },
+ { 0x00055 , 0x0031B , 0x001AF },
+ { 0x00055 , 0x00323 , 0x01EE4 },
+ { 0x00055 , 0x00324 , 0x01E72 },
+ { 0x00055 , 0x00328 , 0x00172 },
+ { 0x00055 , 0x0032D , 0x01E76 },
+ { 0x00055 , 0x00330 , 0x01E74 },
+ { 0x00056 , 0x00303 , 0x01E7C },
+ { 0x00056 , 0x00323 , 0x01E7E },
+ { 0x00057 , 0x00300 , 0x01E80 },
+ { 0x00057 , 0x00301 , 0x01E82 },
+ { 0x00057 , 0x00302 , 0x00174 },
+ { 0x00057 , 0x00307 , 0x01E86 },
+ { 0x00057 , 0x00308 , 0x01E84 },
+ { 0x00057 , 0x00323 , 0x01E88 },
+ { 0x00058 , 0x00307 , 0x01E8A },
+ { 0x00058 , 0x00308 , 0x01E8C },
+ { 0x00059 , 0x00300 , 0x01EF2 },
+ { 0x00059 , 0x00301 , 0x000DD },
+ { 0x00059 , 0x00302 , 0x00176 },
+ { 0x00059 , 0x00303 , 0x01EF8 },
+ { 0x00059 , 0x00304 , 0x00232 },
+ { 0x00059 , 0x00307 , 0x01E8E },
+ { 0x00059 , 0x00308 , 0x00178 },
+ { 0x00059 , 0x00309 , 0x01EF6 },
+ { 0x00059 , 0x00323 , 0x01EF4 },
+ { 0x0005A , 0x00301 , 0x00179 },
+ { 0x0005A , 0x00302 , 0x01E90 },
+ { 0x0005A , 0x00307 , 0x0017B },
+ { 0x0005A , 0x0030C , 0x0017D },
+ { 0x0005A , 0x00323 , 0x01E92 },
+ { 0x0005A , 0x00331 , 0x01E94 },
+ { 0x00061 , 0x00300 , 0x000E0 },
+ { 0x00061 , 0x00301 , 0x000E1 },
+ { 0x00061 , 0x00302 , 0x000E2 },
+ { 0x00061 , 0x00303 , 0x000E3 },
+ { 0x00061 , 0x00304 , 0x00101 },
+ { 0x00061 , 0x00306 , 0x00103 },
+ { 0x00061 , 0x00307 , 0x00227 },
+ { 0x00061 , 0x00308 , 0x000E4 },
+ { 0x00061 , 0x00309 , 0x01EA3 },
+ { 0x00061 , 0x0030A , 0x000E5 },
+ { 0x00061 , 0x0030C , 0x001CE },
+ { 0x00061 , 0x0030F , 0x00201 },
+ { 0x00061 , 0x00311 , 0x00203 },
+ { 0x00061 , 0x00323 , 0x01EA1 },
+ { 0x00061 , 0x00325 , 0x01E01 },
+ { 0x00061 , 0x00328 , 0x00105 },
+ { 0x00062 , 0x00307 , 0x01E03 },
+ { 0x00062 , 0x00323 , 0x01E05 },
+ { 0x00062 , 0x00331 , 0x01E07 },
+ { 0x00063 , 0x00301 , 0x00107 },
+ { 0x00063 , 0x00302 , 0x00109 },
+ { 0x00063 , 0x00307 , 0x0010B },
+ { 0x00063 , 0x0030C , 0x0010D },
+ { 0x00063 , 0x00327 , 0x000E7 },
+ { 0x00064 , 0x00307 , 0x01E0B },
+ { 0x00064 , 0x0030C , 0x0010F },
+ { 0x00064 , 0x00323 , 0x01E0D },
+ { 0x00064 , 0x00327 , 0x01E11 },
+ { 0x00064 , 0x0032D , 0x01E13 },
+ { 0x00064 , 0x00331 , 0x01E0F },
+ { 0x00065 , 0x00300 , 0x000E8 },
+ { 0x00065 , 0x00301 , 0x000E9 },
+ { 0x00065 , 0x00302 , 0x000EA },
+ { 0x00065 , 0x00303 , 0x01EBD },
+ { 0x00065 , 0x00304 , 0x00113 },
+ { 0x00065 , 0x00306 , 0x00115 },
+ { 0x00065 , 0x00307 , 0x00117 },
+ { 0x00065 , 0x00308 , 0x000EB },
+ { 0x00065 , 0x00309 , 0x01EBB },
+ { 0x00065 , 0x0030C , 0x0011B },
+ { 0x00065 , 0x0030F , 0x00205 },
+ { 0x00065 , 0x00311 , 0x00207 },
+ { 0x00065 , 0x00323 , 0x01EB9 },
+ { 0x00065 , 0x00327 , 0x00229 },
+ { 0x00065 , 0x00328 , 0x00119 },
+ { 0x00065 , 0x0032D , 0x01E19 },
+ { 0x00065 , 0x00330 , 0x01E1B },
+ { 0x00066 , 0x00307 , 0x01E1F },
+ { 0x00067 , 0x00301 , 0x001F5 },
+ { 0x00067 , 0x00302 , 0x0011D },
+ { 0x00067 , 0x00304 , 0x01E21 },
+ { 0x00067 , 0x00306 , 0x0011F },
+ { 0x00067 , 0x00307 , 0x00121 },
+ { 0x00067 , 0x0030C , 0x001E7 },
+ { 0x00067 , 0x00327 , 0x00123 },
+ { 0x00068 , 0x00302 , 0x00125 },
+ { 0x00068 , 0x00307 , 0x01E23 },
+ { 0x00068 , 0x00308 , 0x01E27 },
+ { 0x00068 , 0x0030C , 0x0021F },
+ { 0x00068 , 0x00323 , 0x01E25 },
+ { 0x00068 , 0x00327 , 0x01E29 },
+ { 0x00068 , 0x0032E , 0x01E2B },
+ { 0x00068 , 0x00331 , 0x01E96 },
+ { 0x00069 , 0x00300 , 0x000EC },
+ { 0x00069 , 0x00301 , 0x000ED },
+ { 0x00069 , 0x00302 , 0x000EE },
+ { 0x00069 , 0x00303 , 0x00129 },
+ { 0x00069 , 0x00304 , 0x0012B },
+ { 0x00069 , 0x00306 , 0x0012D },
+ { 0x00069 , 0x00308 , 0x000EF },
+ { 0x00069 , 0x00309 , 0x01EC9 },
+ { 0x00069 , 0x0030C , 0x001D0 },
+ { 0x00069 , 0x0030F , 0x00209 },
+ { 0x00069 , 0x00311 , 0x0020B },
+ { 0x00069 , 0x00323 , 0x01ECB },
+ { 0x00069 , 0x00328 , 0x0012F },
+ { 0x00069 , 0x00330 , 0x01E2D },
+ { 0x0006A , 0x00302 , 0x00135 },
+ { 0x0006A , 0x0030C , 0x001F0 },
+ { 0x0006B , 0x00301 , 0x01E31 },
+ { 0x0006B , 0x0030C , 0x001E9 },
+ { 0x0006B , 0x00323 , 0x01E33 },
+ { 0x0006B , 0x00327 , 0x00137 },
+ { 0x0006B , 0x00331 , 0x01E35 },
+ { 0x0006C , 0x00301 , 0x0013A },
+ { 0x0006C , 0x0030C , 0x0013E },
+ { 0x0006C , 0x00323 , 0x01E37 },
+ { 0x0006C , 0x00327 , 0x0013C },
+ { 0x0006C , 0x0032D , 0x01E3D },
+ { 0x0006C , 0x00331 , 0x01E3B },
+ { 0x0006D , 0x00301 , 0x01E3F },
+ { 0x0006D , 0x00307 , 0x01E41 },
+ { 0x0006D , 0x00323 , 0x01E43 },
+ { 0x0006E , 0x00300 , 0x001F9 },
+ { 0x0006E , 0x00301 , 0x00144 },
+ { 0x0006E , 0x00303 , 0x000F1 },
+ { 0x0006E , 0x00307 , 0x01E45 },
+ { 0x0006E , 0x0030C , 0x00148 },
+ { 0x0006E , 0x00323 , 0x01E47 },
+ { 0x0006E , 0x00327 , 0x00146 },
+ { 0x0006E , 0x0032D , 0x01E4B },
+ { 0x0006E , 0x00331 , 0x01E49 },
+ { 0x0006F , 0x00300 , 0x000F2 },
+ { 0x0006F , 0x00301 , 0x000F3 },
+ { 0x0006F , 0x00302 , 0x000F4 },
+ { 0x0006F , 0x00303 , 0x000F5 },
+ { 0x0006F , 0x00304 , 0x0014D },
+ { 0x0006F , 0x00306 , 0x0014F },
+ { 0x0006F , 0x00307 , 0x0022F },
+ { 0x0006F , 0x00308 , 0x000F6 },
+ { 0x0006F , 0x00309 , 0x01ECF },
+ { 0x0006F , 0x0030B , 0x00151 },
+ { 0x0006F , 0x0030C , 0x001D2 },
+ { 0x0006F , 0x0030F , 0x0020D },
+ { 0x0006F , 0x00311 , 0x0020F },
+ { 0x0006F , 0x0031B , 0x001A1 },
+ { 0x0006F , 0x00323 , 0x01ECD },
+ { 0x0006F , 0x00328 , 0x001EB },
+ { 0x00070 , 0x00301 , 0x01E55 },
+ { 0x00070 , 0x00307 , 0x01E57 },
+ { 0x00072 , 0x00301 , 0x00155 },
+ { 0x00072 , 0x00307 , 0x01E59 },
+ { 0x00072 , 0x0030C , 0x00159 },
+ { 0x00072 , 0x0030F , 0x00211 },
+ { 0x00072 , 0x00311 , 0x00213 },
+ { 0x00072 , 0x00323 , 0x01E5B },
+ { 0x00072 , 0x00327 , 0x00157 },
+ { 0x00072 , 0x00331 , 0x01E5F },
+ { 0x00073 , 0x00301 , 0x0015B },
+ { 0x00073 , 0x00302 , 0x0015D },
+ { 0x00073 , 0x00307 , 0x01E61 },
+ { 0x00073 , 0x0030C , 0x00161 },
+ { 0x00073 , 0x00323 , 0x01E63 },
+ { 0x00073 , 0x00326 , 0x00219 },
+ { 0x00073 , 0x00327 , 0x0015F },
+ { 0x00074 , 0x00307 , 0x01E6B },
+ { 0x00074 , 0x00308 , 0x01E97 },
+ { 0x00074 , 0x0030C , 0x00165 },
+ { 0x00074 , 0x00323 , 0x01E6D },
+ { 0x00074 , 0x00326 , 0x0021B },
+ { 0x00074 , 0x00327 , 0x00163 },
+ { 0x00074 , 0x0032D , 0x01E71 },
+ { 0x00074 , 0x00331 , 0x01E6F },
+ { 0x00075 , 0x00300 , 0x000F9 },
+ { 0x00075 , 0x00301 , 0x000FA },
+ { 0x00075 , 0x00302 , 0x000FB },
+ { 0x00075 , 0x00303 , 0x00169 },
+ { 0x00075 , 0x00304 , 0x0016B },
+ { 0x00075 , 0x00306 , 0x0016D },
+ { 0x00075 , 0x00308 , 0x000FC },
+ { 0x00075 , 0x00309 , 0x01EE7 },
+ { 0x00075 , 0x0030A , 0x0016F },
+ { 0x00075 , 0x0030B , 0x00171 },
+ { 0x00075 , 0x0030C , 0x001D4 },
+ { 0x00075 , 0x0030F , 0x00215 },
+ { 0x00075 , 0x00311 , 0x00217 },
+ { 0x00075 , 0x0031B , 0x001B0 },
+ { 0x00075 , 0x00323 , 0x01EE5 },
+ { 0x00075 , 0x00324 , 0x01E73 },
+ { 0x00075 , 0x00328 , 0x00173 },
+ { 0x00075 , 0x0032D , 0x01E77 },
+ { 0x00075 , 0x00330 , 0x01E75 },
+ { 0x00076 , 0x00303 , 0x01E7D },
+ { 0x00076 , 0x00323 , 0x01E7F },
+ { 0x00077 , 0x00300 , 0x01E81 },
+ { 0x00077 , 0x00301 , 0x01E83 },
+ { 0x00077 , 0x00302 , 0x00175 },
+ { 0x00077 , 0x00307 , 0x01E87 },
+ { 0x00077 , 0x00308 , 0x01E85 },
+ { 0x00077 , 0x0030A , 0x01E98 },
+ { 0x00077 , 0x00323 , 0x01E89 },
+ { 0x00078 , 0x00307 , 0x01E8B },
+ { 0x00078 , 0x00308 , 0x01E8D },
+ { 0x00079 , 0x00300 , 0x01EF3 },
+ { 0x00079 , 0x00301 , 0x000FD },
+ { 0x00079 , 0x00302 , 0x00177 },
+ { 0x00079 , 0x00303 , 0x01EF9 },
+ { 0x00079 , 0x00304 , 0x00233 },
+ { 0x00079 , 0x00307 , 0x01E8F },
+ { 0x00079 , 0x00308 , 0x000FF },
+ { 0x00079 , 0x00309 , 0x01EF7 },
+ { 0x00079 , 0x0030A , 0x01E99 },
+ { 0x00079 , 0x00323 , 0x01EF5 },
+ { 0x0007A , 0x00301 , 0x0017A },
+ { 0x0007A , 0x00302 , 0x01E91 },
+ { 0x0007A , 0x00307 , 0x0017C },
+ { 0x0007A , 0x0030C , 0x0017E },
+ { 0x0007A , 0x00323 , 0x01E93 },
+ { 0x0007A , 0x00331 , 0x01E95 },
+ { 0x000A8 , 0x00300 , 0x01FED },
+ { 0x000A8 , 0x00301 , 0x00385 },
+ { 0x000A8 , 0x00342 , 0x01FC1 },
+ { 0x000C2 , 0x00300 , 0x01EA6 },
+ { 0x000C2 , 0x00301 , 0x01EA4 },
+ { 0x000C2 , 0x00303 , 0x01EAA },
+ { 0x000C2 , 0x00309 , 0x01EA8 },
+ { 0x000C4 , 0x00304 , 0x001DE },
+ { 0x000C5 , 0x00301 , 0x001FA },
+ { 0x000C6 , 0x00301 , 0x001FC },
+ { 0x000C6 , 0x00304 , 0x001E2 },
+ { 0x000C7 , 0x00301 , 0x01E08 },
+ { 0x000CA , 0x00300 , 0x01EC0 },
+ { 0x000CA , 0x00301 , 0x01EBE },
+ { 0x000CA , 0x00303 , 0x01EC4 },
+ { 0x000CA , 0x00309 , 0x01EC2 },
+ { 0x000CF , 0x00301 , 0x01E2E },
+ { 0x000D4 , 0x00300 , 0x01ED2 },
+ { 0x000D4 , 0x00301 , 0x01ED0 },
+ { 0x000D4 , 0x00303 , 0x01ED6 },
+ { 0x000D4 , 0x00309 , 0x01ED4 },
+ { 0x000D5 , 0x00301 , 0x01E4C },
+ { 0x000D5 , 0x00304 , 0x0022C },
+ { 0x000D5 , 0x00308 , 0x01E4E },
+ { 0x000D6 , 0x00304 , 0x0022A },
+ { 0x000D8 , 0x00301 , 0x001FE },
+ { 0x000DC , 0x00300 , 0x001DB },
+ { 0x000DC , 0x00301 , 0x001D7 },
+ { 0x000DC , 0x00304 , 0x001D5 },
+ { 0x000DC , 0x0030C , 0x001D9 },
+ { 0x000E2 , 0x00300 , 0x01EA7 },
+ { 0x000E2 , 0x00301 , 0x01EA5 },
+ { 0x000E2 , 0x00303 , 0x01EAB },
+ { 0x000E2 , 0x00309 , 0x01EA9 },
+ { 0x000E4 , 0x00304 , 0x001DF },
+ { 0x000E5 , 0x00301 , 0x001FB },
+ { 0x000E6 , 0x00301 , 0x001FD },
+ { 0x000E6 , 0x00304 , 0x001E3 },
+ { 0x000E7 , 0x00301 , 0x01E09 },
+ { 0x000EA , 0x00300 , 0x01EC1 },
+ { 0x000EA , 0x00301 , 0x01EBF },
+ { 0x000EA , 0x00303 , 0x01EC5 },
+ { 0x000EA , 0x00309 , 0x01EC3 },
+ { 0x000EF , 0x00301 , 0x01E2F },
+ { 0x000F4 , 0x00300 , 0x01ED3 },
+ { 0x000F4 , 0x00301 , 0x01ED1 },
+ { 0x000F4 , 0x00303 , 0x01ED7 },
+ { 0x000F4 , 0x00309 , 0x01ED5 },
+ { 0x000F5 , 0x00301 , 0x01E4D },
+ { 0x000F5 , 0x00304 , 0x0022D },
+ { 0x000F5 , 0x00308 , 0x01E4F },
+ { 0x000F6 , 0x00304 , 0x0022B },
+ { 0x000F8 , 0x00301 , 0x001FF },
+ { 0x000FC , 0x00300 , 0x001DC },
+ { 0x000FC , 0x00301 , 0x001D8 },
+ { 0x000FC , 0x00304 , 0x001D6 },
+ { 0x000FC , 0x0030C , 0x001DA },
+ { 0x00102 , 0x00300 , 0x01EB0 },
+ { 0x00102 , 0x00301 , 0x01EAE },
+ { 0x00102 , 0x00303 , 0x01EB4 },
+ { 0x00102 , 0x00309 , 0x01EB2 },
+ { 0x00103 , 0x00300 , 0x01EB1 },
+ { 0x00103 , 0x00301 , 0x01EAF },
+ { 0x00103 , 0x00303 , 0x01EB5 },
+ { 0x00103 , 0x00309 , 0x01EB3 },
+ { 0x00112 , 0x00300 , 0x01E14 },
+ { 0x00112 , 0x00301 , 0x01E16 },
+ { 0x00113 , 0x00300 , 0x01E15 },
+ { 0x00113 , 0x00301 , 0x01E17 },
+ { 0x0014C , 0x00300 , 0x01E50 },
+ { 0x0014C , 0x00301 , 0x01E52 },
+ { 0x0014D , 0x00300 , 0x01E51 },
+ { 0x0014D , 0x00301 , 0x01E53 },
+ { 0x0015A , 0x00307 , 0x01E64 },
+ { 0x0015B , 0x00307 , 0x01E65 },
+ { 0x00160 , 0x00307 , 0x01E66 },
+ { 0x00161 , 0x00307 , 0x01E67 },
+ { 0x00168 , 0x00301 , 0x01E78 },
+ { 0x00169 , 0x00301 , 0x01E79 },
+ { 0x0016A , 0x00308 , 0x01E7A },
+ { 0x0016B , 0x00308 , 0x01E7B },
+ { 0x0017F , 0x00307 , 0x01E9B },
+ { 0x001A0 , 0x00300 , 0x01EDC },
+ { 0x001A0 , 0x00301 , 0x01EDA },
+ { 0x001A0 , 0x00303 , 0x01EE0 },
+ { 0x001A0 , 0x00309 , 0x01EDE },
+ { 0x001A0 , 0x00323 , 0x01EE2 },
+ { 0x001A1 , 0x00300 , 0x01EDD },
+ { 0x001A1 , 0x00301 , 0x01EDB },
+ { 0x001A1 , 0x00303 , 0x01EE1 },
+ { 0x001A1 , 0x00309 , 0x01EDF },
+ { 0x001A1 , 0x00323 , 0x01EE3 },
+ { 0x001AF , 0x00300 , 0x01EEA },
+ { 0x001AF , 0x00301 , 0x01EE8 },
+ { 0x001AF , 0x00303 , 0x01EEE },
+ { 0x001AF , 0x00309 , 0x01EEC },
+ { 0x001AF , 0x00323 , 0x01EF0 },
+ { 0x001B0 , 0x00300 , 0x01EEB },
+ { 0x001B0 , 0x00301 , 0x01EE9 },
+ { 0x001B0 , 0x00303 , 0x01EEF },
+ { 0x001B0 , 0x00309 , 0x01EED },
+ { 0x001B0 , 0x00323 , 0x01EF1 },
+ { 0x001B7 , 0x0030C , 0x001EE },
+ { 0x001EA , 0x00304 , 0x001EC },
+ { 0x001EB , 0x00304 , 0x001ED },
+ { 0x00226 , 0x00304 , 0x001E0 },
+ { 0x00227 , 0x00304 , 0x001E1 },
+ { 0x00228 , 0x00306 , 0x01E1C },
+ { 0x00229 , 0x00306 , 0x01E1D },
+ { 0x0022E , 0x00304 , 0x00230 },
+ { 0x0022F , 0x00304 , 0x00231 },
+ { 0x00292 , 0x0030C , 0x001EF },
+ { 0x00391 , 0x00300 , 0x01FBA },
+ { 0x00391 , 0x00301 , 0x00386 },
+ { 0x00391 , 0x00304 , 0x01FB9 },
+ { 0x00391 , 0x00306 , 0x01FB8 },
+ { 0x00391 , 0x00313 , 0x01F08 },
+ { 0x00391 , 0x00314 , 0x01F09 },
+ { 0x00391 , 0x00345 , 0x01FBC },
+ { 0x00395 , 0x00300 , 0x01FC8 },
+ { 0x00395 , 0x00301 , 0x00388 },
+ { 0x00395 , 0x00313 , 0x01F18 },
+ { 0x00395 , 0x00314 , 0x01F19 },
+ { 0x00397 , 0x00300 , 0x01FCA },
+ { 0x00397 , 0x00301 , 0x00389 },
+ { 0x00397 , 0x00313 , 0x01F28 },
+ { 0x00397 , 0x00314 , 0x01F29 },
+ { 0x00397 , 0x00345 , 0x01FCC },
+ { 0x00399 , 0x00300 , 0x01FDA },
+ { 0x00399 , 0x00301 , 0x0038A },
+ { 0x00399 , 0x00304 , 0x01FD9 },
+ { 0x00399 , 0x00306 , 0x01FD8 },
+ { 0x00399 , 0x00308 , 0x003AA },
+ { 0x00399 , 0x00313 , 0x01F38 },
+ { 0x00399 , 0x00314 , 0x01F39 },
+ { 0x0039F , 0x00300 , 0x01FF8 },
+ { 0x0039F , 0x00301 , 0x0038C },
+ { 0x0039F , 0x00313 , 0x01F48 },
+ { 0x0039F , 0x00314 , 0x01F49 },
+ { 0x003A1 , 0x00314 , 0x01FEC },
+ { 0x003A5 , 0x00300 , 0x01FEA },
+ { 0x003A5 , 0x00301 , 0x0038E },
+ { 0x003A5 , 0x00304 , 0x01FE9 },
+ { 0x003A5 , 0x00306 , 0x01FE8 },
+ { 0x003A5 , 0x00308 , 0x003AB },
+ { 0x003A5 , 0x00314 , 0x01F59 },
+ { 0x003A9 , 0x00300 , 0x01FFA },
+ { 0x003A9 , 0x00301 , 0x0038F },
+ { 0x003A9 , 0x00313 , 0x01F68 },
+ { 0x003A9 , 0x00314 , 0x01F69 },
+ { 0x003A9 , 0x00345 , 0x01FFC },
+ { 0x003AC , 0x00345 , 0x01FB4 },
+ { 0x003AE , 0x00345 , 0x01FC4 },
+ { 0x003B1 , 0x00300 , 0x01F70 },
+ { 0x003B1 , 0x00301 , 0x003AC },
+ { 0x003B1 , 0x00304 , 0x01FB1 },
+ { 0x003B1 , 0x00306 , 0x01FB0 },
+ { 0x003B1 , 0x00313 , 0x01F00 },
+ { 0x003B1 , 0x00314 , 0x01F01 },
+ { 0x003B1 , 0x00342 , 0x01FB6 },
+ { 0x003B1 , 0x00345 , 0x01FB3 },
+ { 0x003B5 , 0x00300 , 0x01F72 },
+ { 0x003B5 , 0x00301 , 0x003AD },
+ { 0x003B5 , 0x00313 , 0x01F10 },
+ { 0x003B5 , 0x00314 , 0x01F11 },
+ { 0x003B7 , 0x00300 , 0x01F74 },
+ { 0x003B7 , 0x00301 , 0x003AE },
+ { 0x003B7 , 0x00313 , 0x01F20 },
+ { 0x003B7 , 0x00314 , 0x01F21 },
+ { 0x003B7 , 0x00342 , 0x01FC6 },
+ { 0x003B7 , 0x00345 , 0x01FC3 },
+ { 0x003B9 , 0x00300 , 0x01F76 },
+ { 0x003B9 , 0x00301 , 0x003AF },
+ { 0x003B9 , 0x00304 , 0x01FD1 },
+ { 0x003B9 , 0x00306 , 0x01FD0 },
+ { 0x003B9 , 0x00308 , 0x003CA },
+ { 0x003B9 , 0x00313 , 0x01F30 },
+ { 0x003B9 , 0x00314 , 0x01F31 },
+ { 0x003B9 , 0x00342 , 0x01FD6 },
+ { 0x003BF , 0x00300 , 0x01F78 },
+ { 0x003BF , 0x00301 , 0x003CC },
+ { 0x003BF , 0x00313 , 0x01F40 },
+ { 0x003BF , 0x00314 , 0x01F41 },
+ { 0x003C1 , 0x00313 , 0x01FE4 },
+ { 0x003C1 , 0x00314 , 0x01FE5 },
+ { 0x003C5 , 0x00300 , 0x01F7A },
+ { 0x003C5 , 0x00301 , 0x003CD },
+ { 0x003C5 , 0x00304 , 0x01FE1 },
+ { 0x003C5 , 0x00306 , 0x01FE0 },
+ { 0x003C5 , 0x00308 , 0x003CB },
+ { 0x003C5 , 0x00313 , 0x01F50 },
+ { 0x003C5 , 0x00314 , 0x01F51 },
+ { 0x003C5 , 0x00342 , 0x01FE6 },
+ { 0x003C9 , 0x00300 , 0x01F7C },
+ { 0x003C9 , 0x00301 , 0x003CE },
+ { 0x003C9 , 0x00313 , 0x01F60 },
+ { 0x003C9 , 0x00314 , 0x01F61 },
+ { 0x003C9 , 0x00342 , 0x01FF6 },
+ { 0x003C9 , 0x00345 , 0x01FF3 },
+ { 0x003CA , 0x00300 , 0x01FD2 },
+ { 0x003CA , 0x00301 , 0x00390 },
+ { 0x003CA , 0x00342 , 0x01FD7 },
+ { 0x003CB , 0x00300 , 0x01FE2 },
+ { 0x003CB , 0x00301 , 0x003B0 },
+ { 0x003CB , 0x00342 , 0x01FE7 },
+ { 0x003CE , 0x00345 , 0x01FF4 },
+ { 0x003D2 , 0x00301 , 0x003D3 },
+ { 0x003D2 , 0x00308 , 0x003D4 },
+ { 0x00406 , 0x00308 , 0x00407 },
+ { 0x00410 , 0x00306 , 0x004D0 },
+ { 0x00410 , 0x00308 , 0x004D2 },
+ { 0x00413 , 0x00301 , 0x00403 },
+ { 0x00415 , 0x00300 , 0x00400 },
+ { 0x00415 , 0x00306 , 0x004D6 },
+ { 0x00415 , 0x00308 , 0x00401 },
+ { 0x00416 , 0x00306 , 0x004C1 },
+ { 0x00416 , 0x00308 , 0x004DC },
+ { 0x00417 , 0x00308 , 0x004DE },
+ { 0x00418 , 0x00300 , 0x0040D },
+ { 0x00418 , 0x00304 , 0x004E2 },
+ { 0x00418 , 0x00306 , 0x00419 },
+ { 0x00418 , 0x00308 , 0x004E4 },
+ { 0x0041A , 0x00301 , 0x0040C },
+ { 0x0041E , 0x00308 , 0x004E6 },
+ { 0x00423 , 0x00304 , 0x004EE },
+ { 0x00423 , 0x00306 , 0x0040E },
+ { 0x00423 , 0x00308 , 0x004F0 },
+ { 0x00423 , 0x0030B , 0x004F2 },
+ { 0x00427 , 0x00308 , 0x004F4 },
+ { 0x0042B , 0x00308 , 0x004F8 },
+ { 0x0042D , 0x00308 , 0x004EC },
+ { 0x00430 , 0x00306 , 0x004D1 },
+ { 0x00430 , 0x00308 , 0x004D3 },
+ { 0x00433 , 0x00301 , 0x00453 },
+ { 0x00435 , 0x00300 , 0x00450 },
+ { 0x00435 , 0x00306 , 0x004D7 },
+ { 0x00435 , 0x00308 , 0x00451 },
+ { 0x00436 , 0x00306 , 0x004C2 },
+ { 0x00436 , 0x00308 , 0x004DD },
+ { 0x00437 , 0x00308 , 0x004DF },
+ { 0x00438 , 0x00300 , 0x0045D },
+ { 0x00438 , 0x00304 , 0x004E3 },
+ { 0x00438 , 0x00306 , 0x00439 },
+ { 0x00438 , 0x00308 , 0x004E5 },
+ { 0x0043A , 0x00301 , 0x0045C },
+ { 0x0043E , 0x00308 , 0x004E7 },
+ { 0x00443 , 0x00304 , 0x004EF },
+ { 0x00443 , 0x00306 , 0x0045E },
+ { 0x00443 , 0x00308 , 0x004F1 },
+ { 0x00443 , 0x0030B , 0x004F3 },
+ { 0x00447 , 0x00308 , 0x004F5 },
+ { 0x0044B , 0x00308 , 0x004F9 },
+ { 0x0044D , 0x00308 , 0x004ED },
+ { 0x00456 , 0x00308 , 0x00457 },
+ { 0x00474 , 0x0030F , 0x00476 },
+ { 0x00475 , 0x0030F , 0x00477 },
+ { 0x004D8 , 0x00308 , 0x004DA },
+ { 0x004D9 , 0x00308 , 0x004DB },
+ { 0x004E8 , 0x00308 , 0x004EA },
+ { 0x004E9 , 0x00308 , 0x004EB },
+ { 0x00627 , 0x00653 , 0x00622 },
+ { 0x00627 , 0x00654 , 0x00623 },
+ { 0x00627 , 0x00655 , 0x00625 },
+ { 0x00648 , 0x00654 , 0x00624 },
+ { 0x0064A , 0x00654 , 0x00626 },
+ { 0x006C1 , 0x00654 , 0x006C2 },
+ { 0x006D2 , 0x00654 , 0x006D3 },
+ { 0x006D5 , 0x00654 , 0x006C0 },
+ { 0x00928 , 0x0093C , 0x00929 },
+ { 0x00930 , 0x0093C , 0x00931 },
+ { 0x00933 , 0x0093C , 0x00934 },
+ { 0x009C7 , 0x009BE , 0x009CB },
+ { 0x009C7 , 0x009D7 , 0x009CC },
+ { 0x00B47 , 0x00B3E , 0x00B4B },
+ { 0x00B47 , 0x00B56 , 0x00B48 },
+ { 0x00B47 , 0x00B57 , 0x00B4C },
+ { 0x00B92 , 0x00BD7 , 0x00B94 },
+ { 0x00BC6 , 0x00BBE , 0x00BCA },
+ { 0x00BC6 , 0x00BD7 , 0x00BCC },
+ { 0x00BC7 , 0x00BBE , 0x00BCB },
+ { 0x00C46 , 0x00C56 , 0x00C48 },
+ { 0x00CBF , 0x00CD5 , 0x00CC0 },
+ { 0x00CC6 , 0x00CC2 , 0x00CCA },
+ { 0x00CC6 , 0x00CD5 , 0x00CC7 },
+ { 0x00CC6 , 0x00CD6 , 0x00CC8 },
+ { 0x00CCA , 0x00CD5 , 0x00CCB },
+ { 0x00D46 , 0x00D3E , 0x00D4A },
+ { 0x00D46 , 0x00D57 , 0x00D4C },
+ { 0x00D47 , 0x00D3E , 0x00D4B },
+ { 0x00DD9 , 0x00DCA , 0x00DDA },
+ { 0x00DD9 , 0x00DCF , 0x00DDC },
+ { 0x00DD9 , 0x00DDF , 0x00DDE },
+ { 0x00DDC , 0x00DCA , 0x00DDD },
+ { 0x01025 , 0x0102E , 0x01026 },
+ { 0x01B05 , 0x01B35 , 0x01B06 },
+ { 0x01B07 , 0x01B35 , 0x01B08 },
+ { 0x01B09 , 0x01B35 , 0x01B0A },
+ { 0x01B0B , 0x01B35 , 0x01B0C },
+ { 0x01B0D , 0x01B35 , 0x01B0E },
+ { 0x01B11 , 0x01B35 , 0x01B12 },
+ { 0x01B3A , 0x01B35 , 0x01B3B },
+ { 0x01B3C , 0x01B35 , 0x01B3D },
+ { 0x01B3E , 0x01B35 , 0x01B40 },
+ { 0x01B3F , 0x01B35 , 0x01B41 },
+ { 0x01B42 , 0x01B35 , 0x01B43 },
+ { 0x01E36 , 0x00304 , 0x01E38 },
+ { 0x01E37 , 0x00304 , 0x01E39 },
+ { 0x01E5A , 0x00304 , 0x01E5C },
+ { 0x01E5B , 0x00304 , 0x01E5D },
+ { 0x01E62 , 0x00307 , 0x01E68 },
+ { 0x01E63 , 0x00307 , 0x01E69 },
+ { 0x01EA0 , 0x00302 , 0x01EAC },
+ { 0x01EA0 , 0x00306 , 0x01EB6 },
+ { 0x01EA1 , 0x00302 , 0x01EAD },
+ { 0x01EA1 , 0x00306 , 0x01EB7 },
+ { 0x01EB8 , 0x00302 , 0x01EC6 },
+ { 0x01EB9 , 0x00302 , 0x01EC7 },
+ { 0x01ECC , 0x00302 , 0x01ED8 },
+ { 0x01ECD , 0x00302 , 0x01ED9 },
+ { 0x01F00 , 0x00300 , 0x01F02 },
+ { 0x01F00 , 0x00301 , 0x01F04 },
+ { 0x01F00 , 0x00342 , 0x01F06 },
+ { 0x01F00 , 0x00345 , 0x01F80 },
+ { 0x01F01 , 0x00300 , 0x01F03 },
+ { 0x01F01 , 0x00301 , 0x01F05 },
+ { 0x01F01 , 0x00342 , 0x01F07 },
+ { 0x01F01 , 0x00345 , 0x01F81 },
+ { 0x01F02 , 0x00345 , 0x01F82 },
+ { 0x01F03 , 0x00345 , 0x01F83 },
+ { 0x01F04 , 0x00345 , 0x01F84 },
+ { 0x01F05 , 0x00345 , 0x01F85 },
+ { 0x01F06 , 0x00345 , 0x01F86 },
+ { 0x01F07 , 0x00345 , 0x01F87 },
+ { 0x01F08 , 0x00300 , 0x01F0A },
+ { 0x01F08 , 0x00301 , 0x01F0C },
+ { 0x01F08 , 0x00342 , 0x01F0E },
+ { 0x01F08 , 0x00345 , 0x01F88 },
+ { 0x01F09 , 0x00300 , 0x01F0B },
+ { 0x01F09 , 0x00301 , 0x01F0D },
+ { 0x01F09 , 0x00342 , 0x01F0F },
+ { 0x01F09 , 0x00345 , 0x01F89 },
+ { 0x01F0A , 0x00345 , 0x01F8A },
+ { 0x01F0B , 0x00345 , 0x01F8B },
+ { 0x01F0C , 0x00345 , 0x01F8C },
+ { 0x01F0D , 0x00345 , 0x01F8D },
+ { 0x01F0E , 0x00345 , 0x01F8E },
+ { 0x01F0F , 0x00345 , 0x01F8F },
+ { 0x01F10 , 0x00300 , 0x01F12 },
+ { 0x01F10 , 0x00301 , 0x01F14 },
+ { 0x01F11 , 0x00300 , 0x01F13 },
+ { 0x01F11 , 0x00301 , 0x01F15 },
+ { 0x01F18 , 0x00300 , 0x01F1A },
+ { 0x01F18 , 0x00301 , 0x01F1C },
+ { 0x01F19 , 0x00300 , 0x01F1B },
+ { 0x01F19 , 0x00301 , 0x01F1D },
+ { 0x01F20 , 0x00300 , 0x01F22 },
+ { 0x01F20 , 0x00301 , 0x01F24 },
+ { 0x01F20 , 0x00342 , 0x01F26 },
+ { 0x01F20 , 0x00345 , 0x01F90 },
+ { 0x01F21 , 0x00300 , 0x01F23 },
+ { 0x01F21 , 0x00301 , 0x01F25 },
+ { 0x01F21 , 0x00342 , 0x01F27 },
+ { 0x01F21 , 0x00345 , 0x01F91 },
+ { 0x01F22 , 0x00345 , 0x01F92 },
+ { 0x01F23 , 0x00345 , 0x01F93 },
+ { 0x01F24 , 0x00345 , 0x01F94 },
+ { 0x01F25 , 0x00345 , 0x01F95 },
+ { 0x01F26 , 0x00345 , 0x01F96 },
+ { 0x01F27 , 0x00345 , 0x01F97 },
+ { 0x01F28 , 0x00300 , 0x01F2A },
+ { 0x01F28 , 0x00301 , 0x01F2C },
+ { 0x01F28 , 0x00342 , 0x01F2E },
+ { 0x01F28 , 0x00345 , 0x01F98 },
+ { 0x01F29 , 0x00300 , 0x01F2B },
+ { 0x01F29 , 0x00301 , 0x01F2D },
+ { 0x01F29 , 0x00342 , 0x01F2F },
+ { 0x01F29 , 0x00345 , 0x01F99 },
+ { 0x01F2A , 0x00345 , 0x01F9A },
+ { 0x01F2B , 0x00345 , 0x01F9B },
+ { 0x01F2C , 0x00345 , 0x01F9C },
+ { 0x01F2D , 0x00345 , 0x01F9D },
+ { 0x01F2E , 0x00345 , 0x01F9E },
+ { 0x01F2F , 0x00345 , 0x01F9F },
+ { 0x01F30 , 0x00300 , 0x01F32 },
+ { 0x01F30 , 0x00301 , 0x01F34 },
+ { 0x01F30 , 0x00342 , 0x01F36 },
+ { 0x01F31 , 0x00300 , 0x01F33 },
+ { 0x01F31 , 0x00301 , 0x01F35 },
+ { 0x01F31 , 0x00342 , 0x01F37 },
+ { 0x01F38 , 0x00300 , 0x01F3A },
+ { 0x01F38 , 0x00301 , 0x01F3C },
+ { 0x01F38 , 0x00342 , 0x01F3E },
+ { 0x01F39 , 0x00300 , 0x01F3B },
+ { 0x01F39 , 0x00301 , 0x01F3D },
+ { 0x01F39 , 0x00342 , 0x01F3F },
+ { 0x01F40 , 0x00300 , 0x01F42 },
+ { 0x01F40 , 0x00301 , 0x01F44 },
+ { 0x01F41 , 0x00300 , 0x01F43 },
+ { 0x01F41 , 0x00301 , 0x01F45 },
+ { 0x01F48 , 0x00300 , 0x01F4A },
+ { 0x01F48 , 0x00301 , 0x01F4C },
+ { 0x01F49 , 0x00300 , 0x01F4B },
+ { 0x01F49 , 0x00301 , 0x01F4D },
+ { 0x01F50 , 0x00300 , 0x01F52 },
+ { 0x01F50 , 0x00301 , 0x01F54 },
+ { 0x01F50 , 0x00342 , 0x01F56 },
+ { 0x01F51 , 0x00300 , 0x01F53 },
+ { 0x01F51 , 0x00301 , 0x01F55 },
+ { 0x01F51 , 0x00342 , 0x01F57 },
+ { 0x01F59 , 0x00300 , 0x01F5B },
+ { 0x01F59 , 0x00301 , 0x01F5D },
+ { 0x01F59 , 0x00342 , 0x01F5F },
+ { 0x01F60 , 0x00300 , 0x01F62 },
+ { 0x01F60 , 0x00301 , 0x01F64 },
+ { 0x01F60 , 0x00342 , 0x01F66 },
+ { 0x01F60 , 0x00345 , 0x01FA0 },
+ { 0x01F61 , 0x00300 , 0x01F63 },
+ { 0x01F61 , 0x00301 , 0x01F65 },
+ { 0x01F61 , 0x00342 , 0x01F67 },
+ { 0x01F61 , 0x00345 , 0x01FA1 },
+ { 0x01F62 , 0x00345 , 0x01FA2 },
+ { 0x01F63 , 0x00345 , 0x01FA3 },
+ { 0x01F64 , 0x00345 , 0x01FA4 },
+ { 0x01F65 , 0x00345 , 0x01FA5 },
+ { 0x01F66 , 0x00345 , 0x01FA6 },
+ { 0x01F67 , 0x00345 , 0x01FA7 },
+ { 0x01F68 , 0x00300 , 0x01F6A },
+ { 0x01F68 , 0x00301 , 0x01F6C },
+ { 0x01F68 , 0x00342 , 0x01F6E },
+ { 0x01F68 , 0x00345 , 0x01FA8 },
+ { 0x01F69 , 0x00300 , 0x01F6B },
+ { 0x01F69 , 0x00301 , 0x01F6D },
+ { 0x01F69 , 0x00342 , 0x01F6F },
+ { 0x01F69 , 0x00345 , 0x01FA9 },
+ { 0x01F6A , 0x00345 , 0x01FAA },
+ { 0x01F6B , 0x00345 , 0x01FAB },
+ { 0x01F6C , 0x00345 , 0x01FAC },
+ { 0x01F6D , 0x00345 , 0x01FAD },
+ { 0x01F6E , 0x00345 , 0x01FAE },
+ { 0x01F6F , 0x00345 , 0x01FAF },
+ { 0x01F70 , 0x00345 , 0x01FB2 },
+ { 0x01F74 , 0x00345 , 0x01FC2 },
+ { 0x01F7C , 0x00345 , 0x01FF2 },
+ { 0x01FB6 , 0x00345 , 0x01FB7 },
+ { 0x01FBF , 0x00300 , 0x01FCD },
+ { 0x01FBF , 0x00301 , 0x01FCE },
+ { 0x01FBF , 0x00342 , 0x01FCF },
+ { 0x01FC6 , 0x00345 , 0x01FC7 },
+ { 0x01FF6 , 0x00345 , 0x01FF7 },
+ { 0x01FFE , 0x00300 , 0x01FDD },
+ { 0x01FFE , 0x00301 , 0x01FDE },
+ { 0x01FFE , 0x00342 , 0x01FDF },
+ { 0x02190 , 0x00338 , 0x0219A },
+ { 0x02192 , 0x00338 , 0x0219B },
+ { 0x02194 , 0x00338 , 0x021AE },
+ { 0x021D0 , 0x00338 , 0x021CD },
+ { 0x021D2 , 0x00338 , 0x021CF },
+ { 0x021D4 , 0x00338 , 0x021CE },
+ { 0x02203 , 0x00338 , 0x02204 },
+ { 0x02208 , 0x00338 , 0x02209 },
+ { 0x0220B , 0x00338 , 0x0220C },
+ { 0x02223 , 0x00338 , 0x02224 },
+ { 0x02225 , 0x00338 , 0x02226 },
+ { 0x0223C , 0x00338 , 0x02241 },
+ { 0x02243 , 0x00338 , 0x02244 },
+ { 0x02245 , 0x00338 , 0x02247 },
+ { 0x02248 , 0x00338 , 0x02249 },
+ { 0x0224D , 0x00338 , 0x0226D },
+ { 0x02261 , 0x00338 , 0x02262 },
+ { 0x02264 , 0x00338 , 0x02270 },
+ { 0x02265 , 0x00338 , 0x02271 },
+ { 0x02272 , 0x00338 , 0x02274 },
+ { 0x02273 , 0x00338 , 0x02275 },
+ { 0x02276 , 0x00338 , 0x02278 },
+ { 0x02277 , 0x00338 , 0x02279 },
+ { 0x0227A , 0x00338 , 0x02280 },
+ { 0x0227B , 0x00338 , 0x02281 },
+ { 0x0227C , 0x00338 , 0x022E0 },
+ { 0x0227D , 0x00338 , 0x022E1 },
+ { 0x02282 , 0x00338 , 0x02284 },
+ { 0x02283 , 0x00338 , 0x02285 },
+ { 0x02286 , 0x00338 , 0x02288 },
+ { 0x02287 , 0x00338 , 0x02289 },
+ { 0x02291 , 0x00338 , 0x022E2 },
+ { 0x02292 , 0x00338 , 0x022E3 },
+ { 0x022A2 , 0x00338 , 0x022AC },
+ { 0x022A8 , 0x00338 , 0x022AD },
+ { 0x022A9 , 0x00338 , 0x022AE },
+ { 0x022AB , 0x00338 , 0x022AF },
+ { 0x022B2 , 0x00338 , 0x022EA },
+ { 0x022B3 , 0x00338 , 0x022EB },
+ { 0x022B4 , 0x00338 , 0x022EC },
+ { 0x022B5 , 0x00338 , 0x022ED },
+ { 0x03046 , 0x03099 , 0x03094 },
+ { 0x0304B , 0x03099 , 0x0304C },
+ { 0x0304D , 0x03099 , 0x0304E },
+ { 0x0304F , 0x03099 , 0x03050 },
+ { 0x03051 , 0x03099 , 0x03052 },
+ { 0x03053 , 0x03099 , 0x03054 },
+ { 0x03055 , 0x03099 , 0x03056 },
+ { 0x03057 , 0x03099 , 0x03058 },
+ { 0x03059 , 0x03099 , 0x0305A },
+ { 0x0305B , 0x03099 , 0x0305C },
+ { 0x0305D , 0x03099 , 0x0305E },
+ { 0x0305F , 0x03099 , 0x03060 },
+ { 0x03061 , 0x03099 , 0x03062 },
+ { 0x03064 , 0x03099 , 0x03065 },
+ { 0x03066 , 0x03099 , 0x03067 },
+ { 0x03068 , 0x03099 , 0x03069 },
+ { 0x0306F , 0x03099 , 0x03070 },
+ { 0x0306F , 0x0309A , 0x03071 },
+ { 0x03072 , 0x03099 , 0x03073 },
+ { 0x03072 , 0x0309A , 0x03074 },
+ { 0x03075 , 0x03099 , 0x03076 },
+ { 0x03075 , 0x0309A , 0x03077 },
+ { 0x03078 , 0x03099 , 0x03079 },
+ { 0x03078 , 0x0309A , 0x0307A },
+ { 0x0307B , 0x03099 , 0x0307C },
+ { 0x0307B , 0x0309A , 0x0307D },
+ { 0x0309D , 0x03099 , 0x0309E },
+ { 0x030A6 , 0x03099 , 0x030F4 },
+ { 0x030AB , 0x03099 , 0x030AC },
+ { 0x030AD , 0x03099 , 0x030AE },
+ { 0x030AF , 0x03099 , 0x030B0 },
+ { 0x030B1 , 0x03099 , 0x030B2 },
+ { 0x030B3 , 0x03099 , 0x030B4 },
+ { 0x030B5 , 0x03099 , 0x030B6 },
+ { 0x030B7 , 0x03099 , 0x030B8 },
+ { 0x030B9 , 0x03099 , 0x030BA },
+ { 0x030BB , 0x03099 , 0x030BC },
+ { 0x030BD , 0x03099 , 0x030BE },
+ { 0x030BF , 0x03099 , 0x030C0 },
+ { 0x030C1 , 0x03099 , 0x030C2 },
+ { 0x030C4 , 0x03099 , 0x030C5 },
+ { 0x030C6 , 0x03099 , 0x030C7 },
+ { 0x030C8 , 0x03099 , 0x030C9 },
+ { 0x030CF , 0x03099 , 0x030D0 },
+ { 0x030CF , 0x0309A , 0x030D1 },
+ { 0x030D2 , 0x03099 , 0x030D3 },
+ { 0x030D2 , 0x0309A , 0x030D4 },
+ { 0x030D5 , 0x03099 , 0x030D6 },
+ { 0x030D5 , 0x0309A , 0x030D7 },
+ { 0x030D8 , 0x03099 , 0x030D9 },
+ { 0x030D8 , 0x0309A , 0x030DA },
+ { 0x030DB , 0x03099 , 0x030DC },
+ { 0x030DB , 0x0309A , 0x030DD },
+ { 0x030EF , 0x03099 , 0x030F7 },
+ { 0x030F0 , 0x03099 , 0x030F8 },
+ { 0x030F1 , 0x03099 , 0x030F9 },
+ { 0x030F2 , 0x03099 , 0x030FA },
+ { 0x030FD , 0x03099 , 0x030FE },
+ { 0x11099 , 0x110BA , 0x1109A },
+ { 0x1109B , 0x110BA , 0x1109C },
+ { 0x110A5 , 0x110BA , 0x110AB },
+};
+
+#define CANONICAL_CLASS_MIN 0x0300
+#define CANONICAL_CLASS_MAX 0x1D244
+
+#define IS_DECOMPOSABLE_BLOCK(uc) \
+ (((uc)>>8) <= 0x1D2 && u_decomposable_blocks[(uc)>>8])
+static const char u_decomposable_blocks[0x1D2+1] = {
+ 0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,1,1,1,1,1,1,1,0,0,
+ 1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,1,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,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,
+ 0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
+};
+
+/* Get Canonical Combining Class(CCC). */
+#define CCC(uc) \
+ (((uc) > 0x1D244)?0:\
+ ccc_val[ccc_val_index[ccc_index[(uc)>>8]][((uc)>>4)&0x0F]][(uc)&0x0F])
+
+/* The table of the value of Canonical Cimbining Class */
+static const unsigned char ccc_val[][16] = {
+ /* idx=0: XXXX0 - XXXXF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=1: 00300 - 0030F */
+ {230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 },
+ /* idx=2: 00310 - 0031F */
+ {230, 230, 230, 230, 230, 232, 220, 220, 220, 220, 232, 216, 220, 220, 220, 220 },
+ /* idx=3: 00320 - 0032F */
+ {220, 202, 202, 220, 220, 220, 220, 202, 202, 220, 220, 220, 220, 220, 220, 220 },
+ /* idx=4: 00330 - 0033F */
+ {220, 220, 220, 220, 1, 1, 1, 1, 1, 220, 220, 220, 220, 230, 230, 230 },
+ /* idx=5: 00340 - 0034F */
+ {230, 230, 230, 230, 230, 240, 230, 220, 220, 220, 230, 230, 230, 220, 220, 0 },
+ /* idx=6: 00350 - 0035F */
+ {230, 230, 230, 220, 220, 220, 220, 230, 232, 220, 220, 230, 233, 234, 234, 233 },
+ /* idx=7: 00360 - 0036F */
+ {234, 234, 233, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 },
+ /* idx=8: 00480 - 0048F */
+ {0, 0, 0, 230, 230, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=9: 00590 - 0059F */
+ {0, 220, 230, 230, 230, 230, 220, 230, 230, 230, 222, 220, 230, 230, 230, 230 },
+ /* idx=10: 005A0 - 005AF */
+ {230, 230, 220, 220, 220, 220, 220, 220, 230, 230, 220, 230, 230, 222, 228, 230 },
+ /* idx=11: 005B0 - 005BF */
+ {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 0, 23 },
+ /* idx=12: 005C0 - 005CF */
+ {0, 24, 25, 0, 230, 220, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=13: 00610 - 0061F */
+ {230, 230, 230, 230, 230, 230, 230, 230, 30, 31, 32, 0, 0, 0, 0, 0 },
+ /* idx=14: 00640 - 0064F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 28, 29, 30, 31 },
+ /* idx=15: 00650 - 0065F */
+ {32, 33, 34, 230, 230, 220, 220, 230, 230, 230, 230, 230, 220, 230, 230, 220 },
+ /* idx=16: 00670 - 0067F */
+ {35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=17: 006D0 - 006DF */
+ {0, 0, 0, 0, 0, 0, 230, 230, 230, 230, 230, 230, 230, 0, 0, 230 },
+ /* idx=18: 006E0 - 006EF */
+ {230, 230, 230, 220, 230, 0, 0, 230, 230, 0, 220, 230, 230, 220, 0, 0 },
+ /* idx=19: 00710 - 0071F */
+ {0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=20: 00730 - 0073F */
+ {230, 220, 230, 230, 220, 230, 230, 220, 220, 220, 230, 220, 220, 230, 220, 230 },
+ /* idx=21: 00740 - 0074F */
+ {230, 230, 220, 230, 220, 230, 220, 230, 220, 230, 230, 0, 0, 0, 0, 0 },
+ /* idx=22: 007E0 - 007EF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 230, 230, 230, 230 },
+ /* idx=23: 007F0 - 007FF */
+ {230, 230, 220, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=24: 00810 - 0081F */
+ {0, 0, 0, 0, 0, 0, 230, 230, 230, 230, 0, 230, 230, 230, 230, 230 },
+ /* idx=25: 00820 - 0082F */
+ {230, 230, 230, 230, 0, 230, 230, 230, 0, 230, 230, 230, 230, 230, 0, 0 },
+ /* idx=26: 00850 - 0085F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 220, 220, 0, 0, 0, 0 },
+ /* idx=27: 00930 - 0093F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 },
+ /* idx=28: 00940 - 0094F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=29: 00950 - 0095F */
+ {0, 230, 220, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=30: 009B0 - 009BF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 },
+ /* idx=31: 009C0 - 009CF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=32: 00A30 - 00A3F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 },
+ /* idx=33: 00A40 - 00A4F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=34: 00AB0 - 00ABF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 },
+ /* idx=35: 00AC0 - 00ACF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=36: 00B30 - 00B3F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 },
+ /* idx=37: 00B40 - 00B4F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=38: 00BC0 - 00BCF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=39: 00C40 - 00C4F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=40: 00C50 - 00C5F */
+ {0, 0, 0, 0, 0, 84, 91, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=41: 00CB0 - 00CBF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 },
+ /* idx=42: 00CC0 - 00CCF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=43: 00D40 - 00D4F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=44: 00DC0 - 00DCF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0 },
+ /* idx=45: 00E30 - 00E3F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 103, 103, 9, 0, 0, 0, 0, 0 },
+ /* idx=46: 00E40 - 00E4F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 107, 107, 107, 107, 0, 0, 0, 0 },
+ /* idx=47: 00EB0 - 00EBF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 118, 118, 0, 0, 0, 0, 0, 0 },
+ /* idx=48: 00EC0 - 00ECF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 122, 122, 122, 122, 0, 0, 0, 0 },
+ /* idx=49: 00F10 - 00F1F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 220, 220, 0, 0, 0, 0, 0, 0 },
+ /* idx=50: 00F30 - 00F3F */
+ {0, 0, 0, 0, 0, 220, 0, 220, 0, 216, 0, 0, 0, 0, 0, 0 },
+ /* idx=51: 00F70 - 00F7F */
+ {0, 129, 130, 0, 132, 0, 0, 0, 0, 0, 130, 130, 130, 130, 0, 0 },
+ /* idx=52: 00F80 - 00F8F */
+ {130, 0, 230, 230, 9, 0, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=53: 00FC0 - 00FCF */
+ {0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=54: 01030 - 0103F */
+ {0, 0, 0, 0, 0, 0, 0, 7, 0, 9, 9, 0, 0, 0, 0, 0 },
+ /* idx=55: 01080 - 0108F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0 },
+ /* idx=56: 01350 - 0135F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 230, 230 },
+ /* idx=57: 01710 - 0171F */
+ {0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=58: 01730 - 0173F */
+ {0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=59: 017D0 - 017DF */
+ {0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 0, 0 },
+ /* idx=60: 018A0 - 018AF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, 0, 0 },
+ /* idx=61: 01930 - 0193F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 222, 230, 220, 0, 0, 0, 0 },
+ /* idx=62: 01A10 - 01A1F */
+ {0, 0, 0, 0, 0, 0, 0, 230, 220, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=63: 01A60 - 01A6F */
+ {9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=64: 01A70 - 01A7F */
+ {0, 0, 0, 0, 0, 230, 230, 230, 230, 230, 230, 230, 230, 0, 0, 220 },
+ /* idx=65: 01B30 - 01B3F */
+ {0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=66: 01B40 - 01B4F */
+ {0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=67: 01B60 - 01B6F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 220, 230, 230, 230 },
+ /* idx=68: 01B70 - 01B7F */
+ {230, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=69: 01BA0 - 01BAF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0 },
+ /* idx=70: 01BE0 - 01BEF */
+ {0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=71: 01BF0 - 01BFF */
+ {0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=72: 01C30 - 01C3F */
+ {0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=73: 01CD0 - 01CDF */
+ {230, 230, 230, 0, 1, 220, 220, 220, 220, 220, 230, 230, 220, 220, 220, 220 },
+ /* idx=74: 01CE0 - 01CEF */
+ {230, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 220, 0, 0 },
+ /* idx=75: 01DC0 - 01DCF */
+ {230, 230, 220, 230, 230, 230, 230, 230, 230, 230, 220, 230, 230, 234, 214, 220 },
+ /* idx=76: 01DD0 - 01DDF */
+ {202, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 },
+ /* idx=77: 01DE0 - 01DEF */
+ {230, 230, 230, 230, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=78: 01DF0 - 01DFF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 233, 220, 230, 220 },
+ /* idx=79: 020D0 - 020DF */
+ {230, 230, 1, 1, 230, 230, 230, 230, 1, 1, 1, 230, 230, 0, 0, 0 },
+ /* idx=80: 020E0 - 020EF */
+ {0, 230, 0, 0, 0, 1, 1, 230, 220, 230, 1, 1, 220, 220, 220, 220 },
+ /* idx=81: 020F0 - 020FF */
+ {230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=82: 02CE0 - 02CEF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230 },
+ /* idx=83: 02CF0 - 02CFF */
+ {230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=84: 02D70 - 02D7F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 },
+ /* idx=85: 02DE0 - 02DEF */
+ {230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 },
+ /* idx=86: 02DF0 - 02DFF */
+ {230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 },
+ /* idx=87: 03020 - 0302F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 218, 228, 232, 222, 224, 224 },
+ /* idx=88: 03090 - 0309F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0 },
+ /* idx=89: 0A660 - 0A66F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230 },
+ /* idx=90: 0A670 - 0A67F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 230, 0, 0 },
+ /* idx=91: 0A6F0 - 0A6FF */
+ {230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=92: 0A800 - 0A80F */
+ {0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=93: 0A8C0 - 0A8CF */
+ {0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=94: 0A8E0 - 0A8EF */
+ {230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 },
+ /* idx=95: 0A8F0 - 0A8FF */
+ {230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=96: 0A920 - 0A92F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 220, 220, 0, 0 },
+ /* idx=97: 0A950 - 0A95F */
+ {0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=98: 0A9B0 - 0A9BF */
+ {0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=99: 0A9C0 - 0A9CF */
+ {9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=100: 0AAB0 - 0AABF */
+ {230, 0, 230, 230, 220, 0, 0, 230, 230, 0, 0, 0, 0, 0, 230, 230 },
+ /* idx=101: 0AAC0 - 0AACF */
+ {0, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=102: 0ABE0 - 0ABEF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 },
+ /* idx=103: 0FB10 - 0FB1F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0 },
+ /* idx=104: 0FE20 - 0FE2F */
+ {230, 230, 230, 230, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=105: 101F0 - 101FF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0 },
+ /* idx=106: 10A00 - 10A0F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 0, 230 },
+ /* idx=107: 10A30 - 10A3F */
+ {0, 0, 0, 0, 0, 0, 0, 0, 230, 1, 220, 0, 0, 0, 0, 9 },
+ /* idx=108: 11040 - 1104F */
+ {0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=109: 110B0 - 110BF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 7, 0, 0, 0, 0, 0 },
+ /* idx=110: 1D160 - 1D16F */
+ {0, 0, 0, 0, 0, 216, 216, 1, 1, 1, 0, 0, 0, 226, 216, 216 },
+ /* idx=111: 1D170 - 1D17F */
+ {216, 216, 216, 0, 0, 0, 0, 0, 0, 0, 0, 220, 220, 220, 220, 220 },
+ /* idx=112: 1D180 - 1D18F */
+ {220, 220, 220, 0, 0, 230, 230, 230, 230, 230, 220, 220, 0, 0, 0, 0 },
+ /* idx=113: 1D1A0 - 1D1AF */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 230, 230, 230, 0, 0 },
+ /* idx=114: 1D240 - 1D24F */
+ {0, 0, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+};
+
+/* The index table to ccc_val[*][16] */
+static const unsigned char ccc_val_index[][16] = {
+ /* idx=0: XXX00 - XXXFF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=1: 00300 - 003FF */
+ { 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=2: 00400 - 004FF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=3: 00500 - 005FF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,10,11,12, 0, 0, 0 },
+ /* idx=4: 00600 - 006FF */
+ { 0,13, 0, 0,14,15, 0,16, 0, 0, 0, 0, 0,17,18, 0 },
+ /* idx=5: 00700 - 007FF */
+ { 0,19, 0,20,21, 0, 0, 0, 0, 0, 0, 0, 0, 0,22,23 },
+ /* idx=6: 00800 - 008FF */
+ { 0,24,25, 0, 0,26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=7: 00900 - 009FF */
+ { 0, 0, 0,27,28,29, 0, 0, 0, 0, 0,30,31, 0, 0, 0 },
+ /* idx=8: 00A00 - 00AFF */
+ { 0, 0, 0,32,33, 0, 0, 0, 0, 0, 0,34,35, 0, 0, 0 },
+ /* idx=9: 00B00 - 00BFF */
+ { 0, 0, 0,36,37, 0, 0, 0, 0, 0, 0, 0,38, 0, 0, 0 },
+ /* idx=10: 00C00 - 00CFF */
+ { 0, 0, 0, 0,39,40, 0, 0, 0, 0, 0,41,42, 0, 0, 0 },
+ /* idx=11: 00D00 - 00DFF */
+ { 0, 0, 0, 0,43, 0, 0, 0, 0, 0, 0, 0,44, 0, 0, 0 },
+ /* idx=12: 00E00 - 00EFF */
+ { 0, 0, 0,45,46, 0, 0, 0, 0, 0, 0,47,48, 0, 0, 0 },
+ /* idx=13: 00F00 - 00FFF */
+ { 0,49, 0,50, 0, 0, 0,51,52, 0, 0, 0,53, 0, 0, 0 },
+ /* idx=14: 01000 - 010FF */
+ { 0, 0, 0,54, 0, 0, 0, 0,55, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=15: 01300 - 013FF */
+ { 0, 0, 0, 0, 0,56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=16: 01700 - 017FF */
+ { 0,57, 0,58, 0, 0, 0, 0, 0, 0, 0, 0, 0,59, 0, 0 },
+ /* idx=17: 01800 - 018FF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,60, 0, 0, 0, 0, 0 },
+ /* idx=18: 01900 - 019FF */
+ { 0, 0, 0,61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=19: 01A00 - 01AFF */
+ { 0,62, 0, 0, 0, 0,63,64, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=20: 01B00 - 01BFF */
+ { 0, 0, 0,65,66, 0,67,68, 0, 0,69, 0, 0, 0,70,71 },
+ /* idx=21: 01C00 - 01CFF */
+ { 0, 0, 0,72, 0, 0, 0, 0, 0, 0, 0, 0, 0,73,74, 0 },
+ /* idx=22: 01D00 - 01DFF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,75,76,77,78 },
+ /* idx=23: 02000 - 020FF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,79,80,81 },
+ /* idx=24: 02C00 - 02CFF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,82,83 },
+ /* idx=25: 02D00 - 02DFF */
+ { 0, 0, 0, 0, 0, 0, 0,84, 0, 0, 0, 0, 0, 0,85,86 },
+ /* idx=26: 03000 - 030FF */
+ { 0, 0,87, 0, 0, 0, 0, 0, 0,88, 0, 0, 0, 0, 0, 0 },
+ /* idx=27: 0A600 - 0A6FF */
+ { 0, 0, 0, 0, 0, 0,89,90, 0, 0, 0, 0, 0, 0, 0,91 },
+ /* idx=28: 0A800 - 0A8FF */
+ {92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,93, 0,94,95 },
+ /* idx=29: 0A900 - 0A9FF */
+ { 0, 0,96, 0, 0,97, 0, 0, 0, 0, 0,98,99, 0, 0, 0 },
+ /* idx=30: 0AA00 - 0AAFF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,100,101, 0, 0, 0 },
+ /* idx=31: 0AB00 - 0ABFF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,102, 0 },
+ /* idx=32: 0FB00 - 0FBFF */
+ { 0,103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=33: 0FE00 - 0FEFF */
+ { 0, 0,104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=34: 10100 - 101FF */
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,105 },
+ /* idx=35: 10A00 - 10AFF */
+ {106, 0, 0,107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ /* idx=36: 11000 - 110FF */
+ { 0, 0, 0, 0,108, 0, 0, 0, 0, 0, 0,109, 0, 0, 0, 0 },
+ /* idx=37: 1D100 - 1D1FF */
+ { 0, 0, 0, 0, 0, 0,110,111,112, 0,113, 0, 0, 0, 0, 0 },
+ /* idx=38: 1D200 - 1D2FF */
+ { 0, 0, 0, 0,114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+};
+
+/* The index table to ccc_val_index[*][16] */
+static const unsigned char ccc_index[] = {
+ 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, 0, 0,15, 0, 0, 0,16,
+ 17,18,19,20,21,22, 0, 0,23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,24,25, 0, 0,
+ 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,27, 0,
+ 28,29,30,31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0, 0,33, 0, 0,34, 0, 0, 0, 0, 0, 0,
+ 0, 0,35, 0, 0, 0, 0, 0,36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0,37,38,};
+
+struct unicode_decomposition_table {
+ uint32_t nfc;
+ uint32_t cp1;
+ uint32_t cp2;
+};
+
+static const struct unicode_decomposition_table u_decomposition_table[] = {
+ { 0x000C0 , 0x00041 , 0x00300 },
+ { 0x000C1 , 0x00041 , 0x00301 },
+ { 0x000C2 , 0x00041 , 0x00302 },
+ { 0x000C3 , 0x00041 , 0x00303 },
+ { 0x000C4 , 0x00041 , 0x00308 },
+ { 0x000C5 , 0x00041 , 0x0030A },
+ { 0x000C7 , 0x00043 , 0x00327 },
+ { 0x000C8 , 0x00045 , 0x00300 },
+ { 0x000C9 , 0x00045 , 0x00301 },
+ { 0x000CA , 0x00045 , 0x00302 },
+ { 0x000CB , 0x00045 , 0x00308 },
+ { 0x000CC , 0x00049 , 0x00300 },
+ { 0x000CD , 0x00049 , 0x00301 },
+ { 0x000CE , 0x00049 , 0x00302 },
+ { 0x000CF , 0x00049 , 0x00308 },
+ { 0x000D1 , 0x0004E , 0x00303 },
+ { 0x000D2 , 0x0004F , 0x00300 },
+ { 0x000D3 , 0x0004F , 0x00301 },
+ { 0x000D4 , 0x0004F , 0x00302 },
+ { 0x000D5 , 0x0004F , 0x00303 },
+ { 0x000D6 , 0x0004F , 0x00308 },
+ { 0x000D9 , 0x00055 , 0x00300 },
+ { 0x000DA , 0x00055 , 0x00301 },
+ { 0x000DB , 0x00055 , 0x00302 },
+ { 0x000DC , 0x00055 , 0x00308 },
+ { 0x000DD , 0x00059 , 0x00301 },
+ { 0x000E0 , 0x00061 , 0x00300 },
+ { 0x000E1 , 0x00061 , 0x00301 },
+ { 0x000E2 , 0x00061 , 0x00302 },
+ { 0x000E3 , 0x00061 , 0x00303 },
+ { 0x000E4 , 0x00061 , 0x00308 },
+ { 0x000E5 , 0x00061 , 0x0030A },
+ { 0x000E7 , 0x00063 , 0x00327 },
+ { 0x000E8 , 0x00065 , 0x00300 },
+ { 0x000E9 , 0x00065 , 0x00301 },
+ { 0x000EA , 0x00065 , 0x00302 },
+ { 0x000EB , 0x00065 , 0x00308 },
+ { 0x000EC , 0x00069 , 0x00300 },
+ { 0x000ED , 0x00069 , 0x00301 },
+ { 0x000EE , 0x00069 , 0x00302 },
+ { 0x000EF , 0x00069 , 0x00308 },
+ { 0x000F1 , 0x0006E , 0x00303 },
+ { 0x000F2 , 0x0006F , 0x00300 },
+ { 0x000F3 , 0x0006F , 0x00301 },
+ { 0x000F4 , 0x0006F , 0x00302 },
+ { 0x000F5 , 0x0006F , 0x00303 },
+ { 0x000F6 , 0x0006F , 0x00308 },
+ { 0x000F9 , 0x00075 , 0x00300 },
+ { 0x000FA , 0x00075 , 0x00301 },
+ { 0x000FB , 0x00075 , 0x00302 },
+ { 0x000FC , 0x00075 , 0x00308 },
+ { 0x000FD , 0x00079 , 0x00301 },
+ { 0x000FF , 0x00079 , 0x00308 },
+ { 0x00100 , 0x00041 , 0x00304 },
+ { 0x00101 , 0x00061 , 0x00304 },
+ { 0x00102 , 0x00041 , 0x00306 },
+ { 0x00103 , 0x00061 , 0x00306 },
+ { 0x00104 , 0x00041 , 0x00328 },
+ { 0x00105 , 0x00061 , 0x00328 },
+ { 0x00106 , 0x00043 , 0x00301 },
+ { 0x00107 , 0x00063 , 0x00301 },
+ { 0x00108 , 0x00043 , 0x00302 },
+ { 0x00109 , 0x00063 , 0x00302 },
+ { 0x0010A , 0x00043 , 0x00307 },
+ { 0x0010B , 0x00063 , 0x00307 },
+ { 0x0010C , 0x00043 , 0x0030C },
+ { 0x0010D , 0x00063 , 0x0030C },
+ { 0x0010E , 0x00044 , 0x0030C },
+ { 0x0010F , 0x00064 , 0x0030C },
+ { 0x00112 , 0x00045 , 0x00304 },
+ { 0x00113 , 0x00065 , 0x00304 },
+ { 0x00114 , 0x00045 , 0x00306 },
+ { 0x00115 , 0x00065 , 0x00306 },
+ { 0x00116 , 0x00045 , 0x00307 },
+ { 0x00117 , 0x00065 , 0x00307 },
+ { 0x00118 , 0x00045 , 0x00328 },
+ { 0x00119 , 0x00065 , 0x00328 },
+ { 0x0011A , 0x00045 , 0x0030C },
+ { 0x0011B , 0x00065 , 0x0030C },
+ { 0x0011C , 0x00047 , 0x00302 },
+ { 0x0011D , 0x00067 , 0x00302 },
+ { 0x0011E , 0x00047 , 0x00306 },
+ { 0x0011F , 0x00067 , 0x00306 },
+ { 0x00120 , 0x00047 , 0x00307 },
+ { 0x00121 , 0x00067 , 0x00307 },
+ { 0x00122 , 0x00047 , 0x00327 },
+ { 0x00123 , 0x00067 , 0x00327 },
+ { 0x00124 , 0x00048 , 0x00302 },
+ { 0x00125 , 0x00068 , 0x00302 },
+ { 0x00128 , 0x00049 , 0x00303 },
+ { 0x00129 , 0x00069 , 0x00303 },
+ { 0x0012A , 0x00049 , 0x00304 },
+ { 0x0012B , 0x00069 , 0x00304 },
+ { 0x0012C , 0x00049 , 0x00306 },
+ { 0x0012D , 0x00069 , 0x00306 },
+ { 0x0012E , 0x00049 , 0x00328 },
+ { 0x0012F , 0x00069 , 0x00328 },
+ { 0x00130 , 0x00049 , 0x00307 },
+ { 0x00134 , 0x0004A , 0x00302 },
+ { 0x00135 , 0x0006A , 0x00302 },
+ { 0x00136 , 0x0004B , 0x00327 },
+ { 0x00137 , 0x0006B , 0x00327 },
+ { 0x00139 , 0x0004C , 0x00301 },
+ { 0x0013A , 0x0006C , 0x00301 },
+ { 0x0013B , 0x0004C , 0x00327 },
+ { 0x0013C , 0x0006C , 0x00327 },
+ { 0x0013D , 0x0004C , 0x0030C },
+ { 0x0013E , 0x0006C , 0x0030C },
+ { 0x00143 , 0x0004E , 0x00301 },
+ { 0x00144 , 0x0006E , 0x00301 },
+ { 0x00145 , 0x0004E , 0x00327 },
+ { 0x00146 , 0x0006E , 0x00327 },
+ { 0x00147 , 0x0004E , 0x0030C },
+ { 0x00148 , 0x0006E , 0x0030C },
+ { 0x0014C , 0x0004F , 0x00304 },
+ { 0x0014D , 0x0006F , 0x00304 },
+ { 0x0014E , 0x0004F , 0x00306 },
+ { 0x0014F , 0x0006F , 0x00306 },
+ { 0x00150 , 0x0004F , 0x0030B },
+ { 0x00151 , 0x0006F , 0x0030B },
+ { 0x00154 , 0x00052 , 0x00301 },
+ { 0x00155 , 0x00072 , 0x00301 },
+ { 0x00156 , 0x00052 , 0x00327 },
+ { 0x00157 , 0x00072 , 0x00327 },
+ { 0x00158 , 0x00052 , 0x0030C },
+ { 0x00159 , 0x00072 , 0x0030C },
+ { 0x0015A , 0x00053 , 0x00301 },
+ { 0x0015B , 0x00073 , 0x00301 },
+ { 0x0015C , 0x00053 , 0x00302 },
+ { 0x0015D , 0x00073 , 0x00302 },
+ { 0x0015E , 0x00053 , 0x00327 },
+ { 0x0015F , 0x00073 , 0x00327 },
+ { 0x00160 , 0x00053 , 0x0030C },
+ { 0x00161 , 0x00073 , 0x0030C },
+ { 0x00162 , 0x00054 , 0x00327 },
+ { 0x00163 , 0x00074 , 0x00327 },
+ { 0x00164 , 0x00054 , 0x0030C },
+ { 0x00165 , 0x00074 , 0x0030C },
+ { 0x00168 , 0x00055 , 0x00303 },
+ { 0x00169 , 0x00075 , 0x00303 },
+ { 0x0016A , 0x00055 , 0x00304 },
+ { 0x0016B , 0x00075 , 0x00304 },
+ { 0x0016C , 0x00055 , 0x00306 },
+ { 0x0016D , 0x00075 , 0x00306 },
+ { 0x0016E , 0x00055 , 0x0030A },
+ { 0x0016F , 0x00075 , 0x0030A },
+ { 0x00170 , 0x00055 , 0x0030B },
+ { 0x00171 , 0x00075 , 0x0030B },
+ { 0x00172 , 0x00055 , 0x00328 },
+ { 0x00173 , 0x00075 , 0x00328 },
+ { 0x00174 , 0x00057 , 0x00302 },
+ { 0x00175 , 0x00077 , 0x00302 },
+ { 0x00176 , 0x00059 , 0x00302 },
+ { 0x00177 , 0x00079 , 0x00302 },
+ { 0x00178 , 0x00059 , 0x00308 },
+ { 0x00179 , 0x0005A , 0x00301 },
+ { 0x0017A , 0x0007A , 0x00301 },
+ { 0x0017B , 0x0005A , 0x00307 },
+ { 0x0017C , 0x0007A , 0x00307 },
+ { 0x0017D , 0x0005A , 0x0030C },
+ { 0x0017E , 0x0007A , 0x0030C },
+ { 0x001A0 , 0x0004F , 0x0031B },
+ { 0x001A1 , 0x0006F , 0x0031B },
+ { 0x001AF , 0x00055 , 0x0031B },
+ { 0x001B0 , 0x00075 , 0x0031B },
+ { 0x001CD , 0x00041 , 0x0030C },
+ { 0x001CE , 0x00061 , 0x0030C },
+ { 0x001CF , 0x00049 , 0x0030C },
+ { 0x001D0 , 0x00069 , 0x0030C },
+ { 0x001D1 , 0x0004F , 0x0030C },
+ { 0x001D2 , 0x0006F , 0x0030C },
+ { 0x001D3 , 0x00055 , 0x0030C },
+ { 0x001D4 , 0x00075 , 0x0030C },
+ { 0x001D5 , 0x000DC , 0x00304 },
+ { 0x001D6 , 0x000FC , 0x00304 },
+ { 0x001D7 , 0x000DC , 0x00301 },
+ { 0x001D8 , 0x000FC , 0x00301 },
+ { 0x001D9 , 0x000DC , 0x0030C },
+ { 0x001DA , 0x000FC , 0x0030C },
+ { 0x001DB , 0x000DC , 0x00300 },
+ { 0x001DC , 0x000FC , 0x00300 },
+ { 0x001DE , 0x000C4 , 0x00304 },
+ { 0x001DF , 0x000E4 , 0x00304 },
+ { 0x001E0 , 0x00226 , 0x00304 },
+ { 0x001E1 , 0x00227 , 0x00304 },
+ { 0x001E2 , 0x000C6 , 0x00304 },
+ { 0x001E3 , 0x000E6 , 0x00304 },
+ { 0x001E6 , 0x00047 , 0x0030C },
+ { 0x001E7 , 0x00067 , 0x0030C },
+ { 0x001E8 , 0x0004B , 0x0030C },
+ { 0x001E9 , 0x0006B , 0x0030C },
+ { 0x001EA , 0x0004F , 0x00328 },
+ { 0x001EB , 0x0006F , 0x00328 },
+ { 0x001EC , 0x001EA , 0x00304 },
+ { 0x001ED , 0x001EB , 0x00304 },
+ { 0x001EE , 0x001B7 , 0x0030C },
+ { 0x001EF , 0x00292 , 0x0030C },
+ { 0x001F0 , 0x0006A , 0x0030C },
+ { 0x001F4 , 0x00047 , 0x00301 },
+ { 0x001F5 , 0x00067 , 0x00301 },
+ { 0x001F8 , 0x0004E , 0x00300 },
+ { 0x001F9 , 0x0006E , 0x00300 },
+ { 0x001FA , 0x000C5 , 0x00301 },
+ { 0x001FB , 0x000E5 , 0x00301 },
+ { 0x001FC , 0x000C6 , 0x00301 },
+ { 0x001FD , 0x000E6 , 0x00301 },
+ { 0x001FE , 0x000D8 , 0x00301 },
+ { 0x001FF , 0x000F8 , 0x00301 },
+ { 0x00200 , 0x00041 , 0x0030F },
+ { 0x00201 , 0x00061 , 0x0030F },
+ { 0x00202 , 0x00041 , 0x00311 },
+ { 0x00203 , 0x00061 , 0x00311 },
+ { 0x00204 , 0x00045 , 0x0030F },
+ { 0x00205 , 0x00065 , 0x0030F },
+ { 0x00206 , 0x00045 , 0x00311 },
+ { 0x00207 , 0x00065 , 0x00311 },
+ { 0x00208 , 0x00049 , 0x0030F },
+ { 0x00209 , 0x00069 , 0x0030F },
+ { 0x0020A , 0x00049 , 0x00311 },
+ { 0x0020B , 0x00069 , 0x00311 },
+ { 0x0020C , 0x0004F , 0x0030F },
+ { 0x0020D , 0x0006F , 0x0030F },
+ { 0x0020E , 0x0004F , 0x00311 },
+ { 0x0020F , 0x0006F , 0x00311 },
+ { 0x00210 , 0x00052 , 0x0030F },
+ { 0x00211 , 0x00072 , 0x0030F },
+ { 0x00212 , 0x00052 , 0x00311 },
+ { 0x00213 , 0x00072 , 0x00311 },
+ { 0x00214 , 0x00055 , 0x0030F },
+ { 0x00215 , 0x00075 , 0x0030F },
+ { 0x00216 , 0x00055 , 0x00311 },
+ { 0x00217 , 0x00075 , 0x00311 },
+ { 0x00218 , 0x00053 , 0x00326 },
+ { 0x00219 , 0x00073 , 0x00326 },
+ { 0x0021A , 0x00054 , 0x00326 },
+ { 0x0021B , 0x00074 , 0x00326 },
+ { 0x0021E , 0x00048 , 0x0030C },
+ { 0x0021F , 0x00068 , 0x0030C },
+ { 0x00226 , 0x00041 , 0x00307 },
+ { 0x00227 , 0x00061 , 0x00307 },
+ { 0x00228 , 0x00045 , 0x00327 },
+ { 0x00229 , 0x00065 , 0x00327 },
+ { 0x0022A , 0x000D6 , 0x00304 },
+ { 0x0022B , 0x000F6 , 0x00304 },
+ { 0x0022C , 0x000D5 , 0x00304 },
+ { 0x0022D , 0x000F5 , 0x00304 },
+ { 0x0022E , 0x0004F , 0x00307 },
+ { 0x0022F , 0x0006F , 0x00307 },
+ { 0x00230 , 0x0022E , 0x00304 },
+ { 0x00231 , 0x0022F , 0x00304 },
+ { 0x00232 , 0x00059 , 0x00304 },
+ { 0x00233 , 0x00079 , 0x00304 },
+ { 0x00385 , 0x000A8 , 0x00301 },
+ { 0x00386 , 0x00391 , 0x00301 },
+ { 0x00388 , 0x00395 , 0x00301 },
+ { 0x00389 , 0x00397 , 0x00301 },
+ { 0x0038A , 0x00399 , 0x00301 },
+ { 0x0038C , 0x0039F , 0x00301 },
+ { 0x0038E , 0x003A5 , 0x00301 },
+ { 0x0038F , 0x003A9 , 0x00301 },
+ { 0x00390 , 0x003CA , 0x00301 },
+ { 0x003AA , 0x00399 , 0x00308 },
+ { 0x003AB , 0x003A5 , 0x00308 },
+ { 0x003AC , 0x003B1 , 0x00301 },
+ { 0x003AD , 0x003B5 , 0x00301 },
+ { 0x003AE , 0x003B7 , 0x00301 },
+ { 0x003AF , 0x003B9 , 0x00301 },
+ { 0x003B0 , 0x003CB , 0x00301 },
+ { 0x003CA , 0x003B9 , 0x00308 },
+ { 0x003CB , 0x003C5 , 0x00308 },
+ { 0x003CC , 0x003BF , 0x00301 },
+ { 0x003CD , 0x003C5 , 0x00301 },
+ { 0x003CE , 0x003C9 , 0x00301 },
+ { 0x003D3 , 0x003D2 , 0x00301 },
+ { 0x003D4 , 0x003D2 , 0x00308 },
+ { 0x00400 , 0x00415 , 0x00300 },
+ { 0x00401 , 0x00415 , 0x00308 },
+ { 0x00403 , 0x00413 , 0x00301 },
+ { 0x00407 , 0x00406 , 0x00308 },
+ { 0x0040C , 0x0041A , 0x00301 },
+ { 0x0040D , 0x00418 , 0x00300 },
+ { 0x0040E , 0x00423 , 0x00306 },
+ { 0x00419 , 0x00418 , 0x00306 },
+ { 0x00439 , 0x00438 , 0x00306 },
+ { 0x00450 , 0x00435 , 0x00300 },
+ { 0x00451 , 0x00435 , 0x00308 },
+ { 0x00453 , 0x00433 , 0x00301 },
+ { 0x00457 , 0x00456 , 0x00308 },
+ { 0x0045C , 0x0043A , 0x00301 },
+ { 0x0045D , 0x00438 , 0x00300 },
+ { 0x0045E , 0x00443 , 0x00306 },
+ { 0x00476 , 0x00474 , 0x0030F },
+ { 0x00477 , 0x00475 , 0x0030F },
+ { 0x004C1 , 0x00416 , 0x00306 },
+ { 0x004C2 , 0x00436 , 0x00306 },
+ { 0x004D0 , 0x00410 , 0x00306 },
+ { 0x004D1 , 0x00430 , 0x00306 },
+ { 0x004D2 , 0x00410 , 0x00308 },
+ { 0x004D3 , 0x00430 , 0x00308 },
+ { 0x004D6 , 0x00415 , 0x00306 },
+ { 0x004D7 , 0x00435 , 0x00306 },
+ { 0x004DA , 0x004D8 , 0x00308 },
+ { 0x004DB , 0x004D9 , 0x00308 },
+ { 0x004DC , 0x00416 , 0x00308 },
+ { 0x004DD , 0x00436 , 0x00308 },
+ { 0x004DE , 0x00417 , 0x00308 },
+ { 0x004DF , 0x00437 , 0x00308 },
+ { 0x004E2 , 0x00418 , 0x00304 },
+ { 0x004E3 , 0x00438 , 0x00304 },
+ { 0x004E4 , 0x00418 , 0x00308 },
+ { 0x004E5 , 0x00438 , 0x00308 },
+ { 0x004E6 , 0x0041E , 0x00308 },
+ { 0x004E7 , 0x0043E , 0x00308 },
+ { 0x004EA , 0x004E8 , 0x00308 },
+ { 0x004EB , 0x004E9 , 0x00308 },
+ { 0x004EC , 0x0042D , 0x00308 },
+ { 0x004ED , 0x0044D , 0x00308 },
+ { 0x004EE , 0x00423 , 0x00304 },
+ { 0x004EF , 0x00443 , 0x00304 },
+ { 0x004F0 , 0x00423 , 0x00308 },
+ { 0x004F1 , 0x00443 , 0x00308 },
+ { 0x004F2 , 0x00423 , 0x0030B },
+ { 0x004F3 , 0x00443 , 0x0030B },
+ { 0x004F4 , 0x00427 , 0x00308 },
+ { 0x004F5 , 0x00447 , 0x00308 },
+ { 0x004F8 , 0x0042B , 0x00308 },
+ { 0x004F9 , 0x0044B , 0x00308 },
+ { 0x00622 , 0x00627 , 0x00653 },
+ { 0x00623 , 0x00627 , 0x00654 },
+ { 0x00624 , 0x00648 , 0x00654 },
+ { 0x00625 , 0x00627 , 0x00655 },
+ { 0x00626 , 0x0064A , 0x00654 },
+ { 0x006C0 , 0x006D5 , 0x00654 },
+ { 0x006C2 , 0x006C1 , 0x00654 },
+ { 0x006D3 , 0x006D2 , 0x00654 },
+ { 0x00929 , 0x00928 , 0x0093C },
+ { 0x00931 , 0x00930 , 0x0093C },
+ { 0x00934 , 0x00933 , 0x0093C },
+ { 0x009CB , 0x009C7 , 0x009BE },
+ { 0x009CC , 0x009C7 , 0x009D7 },
+ { 0x00B48 , 0x00B47 , 0x00B56 },
+ { 0x00B4B , 0x00B47 , 0x00B3E },
+ { 0x00B4C , 0x00B47 , 0x00B57 },
+ { 0x00B94 , 0x00B92 , 0x00BD7 },
+ { 0x00BCA , 0x00BC6 , 0x00BBE },
+ { 0x00BCB , 0x00BC7 , 0x00BBE },
+ { 0x00BCC , 0x00BC6 , 0x00BD7 },
+ { 0x00C48 , 0x00C46 , 0x00C56 },
+ { 0x00CC0 , 0x00CBF , 0x00CD5 },
+ { 0x00CC7 , 0x00CC6 , 0x00CD5 },
+ { 0x00CC8 , 0x00CC6 , 0x00CD6 },
+ { 0x00CCA , 0x00CC6 , 0x00CC2 },
+ { 0x00CCB , 0x00CCA , 0x00CD5 },
+ { 0x00D4A , 0x00D46 , 0x00D3E },
+ { 0x00D4B , 0x00D47 , 0x00D3E },
+ { 0x00D4C , 0x00D46 , 0x00D57 },
+ { 0x00DDA , 0x00DD9 , 0x00DCA },
+ { 0x00DDC , 0x00DD9 , 0x00DCF },
+ { 0x00DDD , 0x00DDC , 0x00DCA },
+ { 0x00DDE , 0x00DD9 , 0x00DDF },
+ { 0x01026 , 0x01025 , 0x0102E },
+ { 0x01B06 , 0x01B05 , 0x01B35 },
+ { 0x01B08 , 0x01B07 , 0x01B35 },
+ { 0x01B0A , 0x01B09 , 0x01B35 },
+ { 0x01B0C , 0x01B0B , 0x01B35 },
+ { 0x01B0E , 0x01B0D , 0x01B35 },
+ { 0x01B12 , 0x01B11 , 0x01B35 },
+ { 0x01B3B , 0x01B3A , 0x01B35 },
+ { 0x01B3D , 0x01B3C , 0x01B35 },
+ { 0x01B40 , 0x01B3E , 0x01B35 },
+ { 0x01B41 , 0x01B3F , 0x01B35 },
+ { 0x01B43 , 0x01B42 , 0x01B35 },
+ { 0x01E00 , 0x00041 , 0x00325 },
+ { 0x01E01 , 0x00061 , 0x00325 },
+ { 0x01E02 , 0x00042 , 0x00307 },
+ { 0x01E03 , 0x00062 , 0x00307 },
+ { 0x01E04 , 0x00042 , 0x00323 },
+ { 0x01E05 , 0x00062 , 0x00323 },
+ { 0x01E06 , 0x00042 , 0x00331 },
+ { 0x01E07 , 0x00062 , 0x00331 },
+ { 0x01E08 , 0x000C7 , 0x00301 },
+ { 0x01E09 , 0x000E7 , 0x00301 },
+ { 0x01E0A , 0x00044 , 0x00307 },
+ { 0x01E0B , 0x00064 , 0x00307 },
+ { 0x01E0C , 0x00044 , 0x00323 },
+ { 0x01E0D , 0x00064 , 0x00323 },
+ { 0x01E0E , 0x00044 , 0x00331 },
+ { 0x01E0F , 0x00064 , 0x00331 },
+ { 0x01E10 , 0x00044 , 0x00327 },
+ { 0x01E11 , 0x00064 , 0x00327 },
+ { 0x01E12 , 0x00044 , 0x0032D },
+ { 0x01E13 , 0x00064 , 0x0032D },
+ { 0x01E14 , 0x00112 , 0x00300 },
+ { 0x01E15 , 0x00113 , 0x00300 },
+ { 0x01E16 , 0x00112 , 0x00301 },
+ { 0x01E17 , 0x00113 , 0x00301 },
+ { 0x01E18 , 0x00045 , 0x0032D },
+ { 0x01E19 , 0x00065 , 0x0032D },
+ { 0x01E1A , 0x00045 , 0x00330 },
+ { 0x01E1B , 0x00065 , 0x00330 },
+ { 0x01E1C , 0x00228 , 0x00306 },
+ { 0x01E1D , 0x00229 , 0x00306 },
+ { 0x01E1E , 0x00046 , 0x00307 },
+ { 0x01E1F , 0x00066 , 0x00307 },
+ { 0x01E20 , 0x00047 , 0x00304 },
+ { 0x01E21 , 0x00067 , 0x00304 },
+ { 0x01E22 , 0x00048 , 0x00307 },
+ { 0x01E23 , 0x00068 , 0x00307 },
+ { 0x01E24 , 0x00048 , 0x00323 },
+ { 0x01E25 , 0x00068 , 0x00323 },
+ { 0x01E26 , 0x00048 , 0x00308 },
+ { 0x01E27 , 0x00068 , 0x00308 },
+ { 0x01E28 , 0x00048 , 0x00327 },
+ { 0x01E29 , 0x00068 , 0x00327 },
+ { 0x01E2A , 0x00048 , 0x0032E },
+ { 0x01E2B , 0x00068 , 0x0032E },
+ { 0x01E2C , 0x00049 , 0x00330 },
+ { 0x01E2D , 0x00069 , 0x00330 },
+ { 0x01E2E , 0x000CF , 0x00301 },
+ { 0x01E2F , 0x000EF , 0x00301 },
+ { 0x01E30 , 0x0004B , 0x00301 },
+ { 0x01E31 , 0x0006B , 0x00301 },
+ { 0x01E32 , 0x0004B , 0x00323 },
+ { 0x01E33 , 0x0006B , 0x00323 },
+ { 0x01E34 , 0x0004B , 0x00331 },
+ { 0x01E35 , 0x0006B , 0x00331 },
+ { 0x01E36 , 0x0004C , 0x00323 },
+ { 0x01E37 , 0x0006C , 0x00323 },
+ { 0x01E38 , 0x01E36 , 0x00304 },
+ { 0x01E39 , 0x01E37 , 0x00304 },
+ { 0x01E3A , 0x0004C , 0x00331 },
+ { 0x01E3B , 0x0006C , 0x00331 },
+ { 0x01E3C , 0x0004C , 0x0032D },
+ { 0x01E3D , 0x0006C , 0x0032D },
+ { 0x01E3E , 0x0004D , 0x00301 },
+ { 0x01E3F , 0x0006D , 0x00301 },
+ { 0x01E40 , 0x0004D , 0x00307 },
+ { 0x01E41 , 0x0006D , 0x00307 },
+ { 0x01E42 , 0x0004D , 0x00323 },
+ { 0x01E43 , 0x0006D , 0x00323 },
+ { 0x01E44 , 0x0004E , 0x00307 },
+ { 0x01E45 , 0x0006E , 0x00307 },
+ { 0x01E46 , 0x0004E , 0x00323 },
+ { 0x01E47 , 0x0006E , 0x00323 },
+ { 0x01E48 , 0x0004E , 0x00331 },
+ { 0x01E49 , 0x0006E , 0x00331 },
+ { 0x01E4A , 0x0004E , 0x0032D },
+ { 0x01E4B , 0x0006E , 0x0032D },
+ { 0x01E4C , 0x000D5 , 0x00301 },
+ { 0x01E4D , 0x000F5 , 0x00301 },
+ { 0x01E4E , 0x000D5 , 0x00308 },
+ { 0x01E4F , 0x000F5 , 0x00308 },
+ { 0x01E50 , 0x0014C , 0x00300 },
+ { 0x01E51 , 0x0014D , 0x00300 },
+ { 0x01E52 , 0x0014C , 0x00301 },
+ { 0x01E53 , 0x0014D , 0x00301 },
+ { 0x01E54 , 0x00050 , 0x00301 },
+ { 0x01E55 , 0x00070 , 0x00301 },
+ { 0x01E56 , 0x00050 , 0x00307 },
+ { 0x01E57 , 0x00070 , 0x00307 },
+ { 0x01E58 , 0x00052 , 0x00307 },
+ { 0x01E59 , 0x00072 , 0x00307 },
+ { 0x01E5A , 0x00052 , 0x00323 },
+ { 0x01E5B , 0x00072 , 0x00323 },
+ { 0x01E5C , 0x01E5A , 0x00304 },
+ { 0x01E5D , 0x01E5B , 0x00304 },
+ { 0x01E5E , 0x00052 , 0x00331 },
+ { 0x01E5F , 0x00072 , 0x00331 },
+ { 0x01E60 , 0x00053 , 0x00307 },
+ { 0x01E61 , 0x00073 , 0x00307 },
+ { 0x01E62 , 0x00053 , 0x00323 },
+ { 0x01E63 , 0x00073 , 0x00323 },
+ { 0x01E64 , 0x0015A , 0x00307 },
+ { 0x01E65 , 0x0015B , 0x00307 },
+ { 0x01E66 , 0x00160 , 0x00307 },
+ { 0x01E67 , 0x00161 , 0x00307 },
+ { 0x01E68 , 0x01E62 , 0x00307 },
+ { 0x01E69 , 0x01E63 , 0x00307 },
+ { 0x01E6A , 0x00054 , 0x00307 },
+ { 0x01E6B , 0x00074 , 0x00307 },
+ { 0x01E6C , 0x00054 , 0x00323 },
+ { 0x01E6D , 0x00074 , 0x00323 },
+ { 0x01E6E , 0x00054 , 0x00331 },
+ { 0x01E6F , 0x00074 , 0x00331 },
+ { 0x01E70 , 0x00054 , 0x0032D },
+ { 0x01E71 , 0x00074 , 0x0032D },
+ { 0x01E72 , 0x00055 , 0x00324 },
+ { 0x01E73 , 0x00075 , 0x00324 },
+ { 0x01E74 , 0x00055 , 0x00330 },
+ { 0x01E75 , 0x00075 , 0x00330 },
+ { 0x01E76 , 0x00055 , 0x0032D },
+ { 0x01E77 , 0x00075 , 0x0032D },
+ { 0x01E78 , 0x00168 , 0x00301 },
+ { 0x01E79 , 0x00169 , 0x00301 },
+ { 0x01E7A , 0x0016A , 0x00308 },
+ { 0x01E7B , 0x0016B , 0x00308 },
+ { 0x01E7C , 0x00056 , 0x00303 },
+ { 0x01E7D , 0x00076 , 0x00303 },
+ { 0x01E7E , 0x00056 , 0x00323 },
+ { 0x01E7F , 0x00076 , 0x00323 },
+ { 0x01E80 , 0x00057 , 0x00300 },
+ { 0x01E81 , 0x00077 , 0x00300 },
+ { 0x01E82 , 0x00057 , 0x00301 },
+ { 0x01E83 , 0x00077 , 0x00301 },
+ { 0x01E84 , 0x00057 , 0x00308 },
+ { 0x01E85 , 0x00077 , 0x00308 },
+ { 0x01E86 , 0x00057 , 0x00307 },
+ { 0x01E87 , 0x00077 , 0x00307 },
+ { 0x01E88 , 0x00057 , 0x00323 },
+ { 0x01E89 , 0x00077 , 0x00323 },
+ { 0x01E8A , 0x00058 , 0x00307 },
+ { 0x01E8B , 0x00078 , 0x00307 },
+ { 0x01E8C , 0x00058 , 0x00308 },
+ { 0x01E8D , 0x00078 , 0x00308 },
+ { 0x01E8E , 0x00059 , 0x00307 },
+ { 0x01E8F , 0x00079 , 0x00307 },
+ { 0x01E90 , 0x0005A , 0x00302 },
+ { 0x01E91 , 0x0007A , 0x00302 },
+ { 0x01E92 , 0x0005A , 0x00323 },
+ { 0x01E93 , 0x0007A , 0x00323 },
+ { 0x01E94 , 0x0005A , 0x00331 },
+ { 0x01E95 , 0x0007A , 0x00331 },
+ { 0x01E96 , 0x00068 , 0x00331 },
+ { 0x01E97 , 0x00074 , 0x00308 },
+ { 0x01E98 , 0x00077 , 0x0030A },
+ { 0x01E99 , 0x00079 , 0x0030A },
+ { 0x01E9B , 0x0017F , 0x00307 },
+ { 0x01EA0 , 0x00041 , 0x00323 },
+ { 0x01EA1 , 0x00061 , 0x00323 },
+ { 0x01EA2 , 0x00041 , 0x00309 },
+ { 0x01EA3 , 0x00061 , 0x00309 },
+ { 0x01EA4 , 0x000C2 , 0x00301 },
+ { 0x01EA5 , 0x000E2 , 0x00301 },
+ { 0x01EA6 , 0x000C2 , 0x00300 },
+ { 0x01EA7 , 0x000E2 , 0x00300 },
+ { 0x01EA8 , 0x000C2 , 0x00309 },
+ { 0x01EA9 , 0x000E2 , 0x00309 },
+ { 0x01EAA , 0x000C2 , 0x00303 },
+ { 0x01EAB , 0x000E2 , 0x00303 },
+ { 0x01EAC , 0x01EA0 , 0x00302 },
+ { 0x01EAD , 0x01EA1 , 0x00302 },
+ { 0x01EAE , 0x00102 , 0x00301 },
+ { 0x01EAF , 0x00103 , 0x00301 },
+ { 0x01EB0 , 0x00102 , 0x00300 },
+ { 0x01EB1 , 0x00103 , 0x00300 },
+ { 0x01EB2 , 0x00102 , 0x00309 },
+ { 0x01EB3 , 0x00103 , 0x00309 },
+ { 0x01EB4 , 0x00102 , 0x00303 },
+ { 0x01EB5 , 0x00103 , 0x00303 },
+ { 0x01EB6 , 0x01EA0 , 0x00306 },
+ { 0x01EB7 , 0x01EA1 , 0x00306 },
+ { 0x01EB8 , 0x00045 , 0x00323 },
+ { 0x01EB9 , 0x00065 , 0x00323 },
+ { 0x01EBA , 0x00045 , 0x00309 },
+ { 0x01EBB , 0x00065 , 0x00309 },
+ { 0x01EBC , 0x00045 , 0x00303 },
+ { 0x01EBD , 0x00065 , 0x00303 },
+ { 0x01EBE , 0x000CA , 0x00301 },
+ { 0x01EBF , 0x000EA , 0x00301 },
+ { 0x01EC0 , 0x000CA , 0x00300 },
+ { 0x01EC1 , 0x000EA , 0x00300 },
+ { 0x01EC2 , 0x000CA , 0x00309 },
+ { 0x01EC3 , 0x000EA , 0x00309 },
+ { 0x01EC4 , 0x000CA , 0x00303 },
+ { 0x01EC5 , 0x000EA , 0x00303 },
+ { 0x01EC6 , 0x01EB8 , 0x00302 },
+ { 0x01EC7 , 0x01EB9 , 0x00302 },
+ { 0x01EC8 , 0x00049 , 0x00309 },
+ { 0x01EC9 , 0x00069 , 0x00309 },
+ { 0x01ECA , 0x00049 , 0x00323 },
+ { 0x01ECB , 0x00069 , 0x00323 },
+ { 0x01ECC , 0x0004F , 0x00323 },
+ { 0x01ECD , 0x0006F , 0x00323 },
+ { 0x01ECE , 0x0004F , 0x00309 },
+ { 0x01ECF , 0x0006F , 0x00309 },
+ { 0x01ED0 , 0x000D4 , 0x00301 },
+ { 0x01ED1 , 0x000F4 , 0x00301 },
+ { 0x01ED2 , 0x000D4 , 0x00300 },
+ { 0x01ED3 , 0x000F4 , 0x00300 },
+ { 0x01ED4 , 0x000D4 , 0x00309 },
+ { 0x01ED5 , 0x000F4 , 0x00309 },
+ { 0x01ED6 , 0x000D4 , 0x00303 },
+ { 0x01ED7 , 0x000F4 , 0x00303 },
+ { 0x01ED8 , 0x01ECC , 0x00302 },
+ { 0x01ED9 , 0x01ECD , 0x00302 },
+ { 0x01EDA , 0x001A0 , 0x00301 },
+ { 0x01EDB , 0x001A1 , 0x00301 },
+ { 0x01EDC , 0x001A0 , 0x00300 },
+ { 0x01EDD , 0x001A1 , 0x00300 },
+ { 0x01EDE , 0x001A0 , 0x00309 },
+ { 0x01EDF , 0x001A1 , 0x00309 },
+ { 0x01EE0 , 0x001A0 , 0x00303 },
+ { 0x01EE1 , 0x001A1 , 0x00303 },
+ { 0x01EE2 , 0x001A0 , 0x00323 },
+ { 0x01EE3 , 0x001A1 , 0x00323 },
+ { 0x01EE4 , 0x00055 , 0x00323 },
+ { 0x01EE5 , 0x00075 , 0x00323 },
+ { 0x01EE6 , 0x00055 , 0x00309 },
+ { 0x01EE7 , 0x00075 , 0x00309 },
+ { 0x01EE8 , 0x001AF , 0x00301 },
+ { 0x01EE9 , 0x001B0 , 0x00301 },
+ { 0x01EEA , 0x001AF , 0x00300 },
+ { 0x01EEB , 0x001B0 , 0x00300 },
+ { 0x01EEC , 0x001AF , 0x00309 },
+ { 0x01EED , 0x001B0 , 0x00309 },
+ { 0x01EEE , 0x001AF , 0x00303 },
+ { 0x01EEF , 0x001B0 , 0x00303 },
+ { 0x01EF0 , 0x001AF , 0x00323 },
+ { 0x01EF1 , 0x001B0 , 0x00323 },
+ { 0x01EF2 , 0x00059 , 0x00300 },
+ { 0x01EF3 , 0x00079 , 0x00300 },
+ { 0x01EF4 , 0x00059 , 0x00323 },
+ { 0x01EF5 , 0x00079 , 0x00323 },
+ { 0x01EF6 , 0x00059 , 0x00309 },
+ { 0x01EF7 , 0x00079 , 0x00309 },
+ { 0x01EF8 , 0x00059 , 0x00303 },
+ { 0x01EF9 , 0x00079 , 0x00303 },
+ { 0x01F00 , 0x003B1 , 0x00313 },
+ { 0x01F01 , 0x003B1 , 0x00314 },
+ { 0x01F02 , 0x01F00 , 0x00300 },
+ { 0x01F03 , 0x01F01 , 0x00300 },
+ { 0x01F04 , 0x01F00 , 0x00301 },
+ { 0x01F05 , 0x01F01 , 0x00301 },
+ { 0x01F06 , 0x01F00 , 0x00342 },
+ { 0x01F07 , 0x01F01 , 0x00342 },
+ { 0x01F08 , 0x00391 , 0x00313 },
+ { 0x01F09 , 0x00391 , 0x00314 },
+ { 0x01F0A , 0x01F08 , 0x00300 },
+ { 0x01F0B , 0x01F09 , 0x00300 },
+ { 0x01F0C , 0x01F08 , 0x00301 },
+ { 0x01F0D , 0x01F09 , 0x00301 },
+ { 0x01F0E , 0x01F08 , 0x00342 },
+ { 0x01F0F , 0x01F09 , 0x00342 },
+ { 0x01F10 , 0x003B5 , 0x00313 },
+ { 0x01F11 , 0x003B5 , 0x00314 },
+ { 0x01F12 , 0x01F10 , 0x00300 },
+ { 0x01F13 , 0x01F11 , 0x00300 },
+ { 0x01F14 , 0x01F10 , 0x00301 },
+ { 0x01F15 , 0x01F11 , 0x00301 },
+ { 0x01F18 , 0x00395 , 0x00313 },
+ { 0x01F19 , 0x00395 , 0x00314 },
+ { 0x01F1A , 0x01F18 , 0x00300 },
+ { 0x01F1B , 0x01F19 , 0x00300 },
+ { 0x01F1C , 0x01F18 , 0x00301 },
+ { 0x01F1D , 0x01F19 , 0x00301 },
+ { 0x01F20 , 0x003B7 , 0x00313 },
+ { 0x01F21 , 0x003B7 , 0x00314 },
+ { 0x01F22 , 0x01F20 , 0x00300 },
+ { 0x01F23 , 0x01F21 , 0x00300 },
+ { 0x01F24 , 0x01F20 , 0x00301 },
+ { 0x01F25 , 0x01F21 , 0x00301 },
+ { 0x01F26 , 0x01F20 , 0x00342 },
+ { 0x01F27 , 0x01F21 , 0x00342 },
+ { 0x01F28 , 0x00397 , 0x00313 },
+ { 0x01F29 , 0x00397 , 0x00314 },
+ { 0x01F2A , 0x01F28 , 0x00300 },
+ { 0x01F2B , 0x01F29 , 0x00300 },
+ { 0x01F2C , 0x01F28 , 0x00301 },
+ { 0x01F2D , 0x01F29 , 0x00301 },
+ { 0x01F2E , 0x01F28 , 0x00342 },
+ { 0x01F2F , 0x01F29 , 0x00342 },
+ { 0x01F30 , 0x003B9 , 0x00313 },
+ { 0x01F31 , 0x003B9 , 0x00314 },
+ { 0x01F32 , 0x01F30 , 0x00300 },
+ { 0x01F33 , 0x01F31 , 0x00300 },
+ { 0x01F34 , 0x01F30 , 0x00301 },
+ { 0x01F35 , 0x01F31 , 0x00301 },
+ { 0x01F36 , 0x01F30 , 0x00342 },
+ { 0x01F37 , 0x01F31 , 0x00342 },
+ { 0x01F38 , 0x00399 , 0x00313 },
+ { 0x01F39 , 0x00399 , 0x00314 },
+ { 0x01F3A , 0x01F38 , 0x00300 },
+ { 0x01F3B , 0x01F39 , 0x00300 },
+ { 0x01F3C , 0x01F38 , 0x00301 },
+ { 0x01F3D , 0x01F39 , 0x00301 },
+ { 0x01F3E , 0x01F38 , 0x00342 },
+ { 0x01F3F , 0x01F39 , 0x00342 },
+ { 0x01F40 , 0x003BF , 0x00313 },
+ { 0x01F41 , 0x003BF , 0x00314 },
+ { 0x01F42 , 0x01F40 , 0x00300 },
+ { 0x01F43 , 0x01F41 , 0x00300 },
+ { 0x01F44 , 0x01F40 , 0x00301 },
+ { 0x01F45 , 0x01F41 , 0x00301 },
+ { 0x01F48 , 0x0039F , 0x00313 },
+ { 0x01F49 , 0x0039F , 0x00314 },
+ { 0x01F4A , 0x01F48 , 0x00300 },
+ { 0x01F4B , 0x01F49 , 0x00300 },
+ { 0x01F4C , 0x01F48 , 0x00301 },
+ { 0x01F4D , 0x01F49 , 0x00301 },
+ { 0x01F50 , 0x003C5 , 0x00313 },
+ { 0x01F51 , 0x003C5 , 0x00314 },
+ { 0x01F52 , 0x01F50 , 0x00300 },
+ { 0x01F53 , 0x01F51 , 0x00300 },
+ { 0x01F54 , 0x01F50 , 0x00301 },
+ { 0x01F55 , 0x01F51 , 0x00301 },
+ { 0x01F56 , 0x01F50 , 0x00342 },
+ { 0x01F57 , 0x01F51 , 0x00342 },
+ { 0x01F59 , 0x003A5 , 0x00314 },
+ { 0x01F5B , 0x01F59 , 0x00300 },
+ { 0x01F5D , 0x01F59 , 0x00301 },
+ { 0x01F5F , 0x01F59 , 0x00342 },
+ { 0x01F60 , 0x003C9 , 0x00313 },
+ { 0x01F61 , 0x003C9 , 0x00314 },
+ { 0x01F62 , 0x01F60 , 0x00300 },
+ { 0x01F63 , 0x01F61 , 0x00300 },
+ { 0x01F64 , 0x01F60 , 0x00301 },
+ { 0x01F65 , 0x01F61 , 0x00301 },
+ { 0x01F66 , 0x01F60 , 0x00342 },
+ { 0x01F67 , 0x01F61 , 0x00342 },
+ { 0x01F68 , 0x003A9 , 0x00313 },
+ { 0x01F69 , 0x003A9 , 0x00314 },
+ { 0x01F6A , 0x01F68 , 0x00300 },
+ { 0x01F6B , 0x01F69 , 0x00300 },
+ { 0x01F6C , 0x01F68 , 0x00301 },
+ { 0x01F6D , 0x01F69 , 0x00301 },
+ { 0x01F6E , 0x01F68 , 0x00342 },
+ { 0x01F6F , 0x01F69 , 0x00342 },
+ { 0x01F70 , 0x003B1 , 0x00300 },
+ { 0x01F72 , 0x003B5 , 0x00300 },
+ { 0x01F74 , 0x003B7 , 0x00300 },
+ { 0x01F76 , 0x003B9 , 0x00300 },
+ { 0x01F78 , 0x003BF , 0x00300 },
+ { 0x01F7A , 0x003C5 , 0x00300 },
+ { 0x01F7C , 0x003C9 , 0x00300 },
+ { 0x01F80 , 0x01F00 , 0x00345 },
+ { 0x01F81 , 0x01F01 , 0x00345 },
+ { 0x01F82 , 0x01F02 , 0x00345 },
+ { 0x01F83 , 0x01F03 , 0x00345 },
+ { 0x01F84 , 0x01F04 , 0x00345 },
+ { 0x01F85 , 0x01F05 , 0x00345 },
+ { 0x01F86 , 0x01F06 , 0x00345 },
+ { 0x01F87 , 0x01F07 , 0x00345 },
+ { 0x01F88 , 0x01F08 , 0x00345 },
+ { 0x01F89 , 0x01F09 , 0x00345 },
+ { 0x01F8A , 0x01F0A , 0x00345 },
+ { 0x01F8B , 0x01F0B , 0x00345 },
+ { 0x01F8C , 0x01F0C , 0x00345 },
+ { 0x01F8D , 0x01F0D , 0x00345 },
+ { 0x01F8E , 0x01F0E , 0x00345 },
+ { 0x01F8F , 0x01F0F , 0x00345 },
+ { 0x01F90 , 0x01F20 , 0x00345 },
+ { 0x01F91 , 0x01F21 , 0x00345 },
+ { 0x01F92 , 0x01F22 , 0x00345 },
+ { 0x01F93 , 0x01F23 , 0x00345 },
+ { 0x01F94 , 0x01F24 , 0x00345 },
+ { 0x01F95 , 0x01F25 , 0x00345 },
+ { 0x01F96 , 0x01F26 , 0x00345 },
+ { 0x01F97 , 0x01F27 , 0x00345 },
+ { 0x01F98 , 0x01F28 , 0x00345 },
+ { 0x01F99 , 0x01F29 , 0x00345 },
+ { 0x01F9A , 0x01F2A , 0x00345 },
+ { 0x01F9B , 0x01F2B , 0x00345 },
+ { 0x01F9C , 0x01F2C , 0x00345 },
+ { 0x01F9D , 0x01F2D , 0x00345 },
+ { 0x01F9E , 0x01F2E , 0x00345 },
+ { 0x01F9F , 0x01F2F , 0x00345 },
+ { 0x01FA0 , 0x01F60 , 0x00345 },
+ { 0x01FA1 , 0x01F61 , 0x00345 },
+ { 0x01FA2 , 0x01F62 , 0x00345 },
+ { 0x01FA3 , 0x01F63 , 0x00345 },
+ { 0x01FA4 , 0x01F64 , 0x00345 },
+ { 0x01FA5 , 0x01F65 , 0x00345 },
+ { 0x01FA6 , 0x01F66 , 0x00345 },
+ { 0x01FA7 , 0x01F67 , 0x00345 },
+ { 0x01FA8 , 0x01F68 , 0x00345 },
+ { 0x01FA9 , 0x01F69 , 0x00345 },
+ { 0x01FAA , 0x01F6A , 0x00345 },
+ { 0x01FAB , 0x01F6B , 0x00345 },
+ { 0x01FAC , 0x01F6C , 0x00345 },
+ { 0x01FAD , 0x01F6D , 0x00345 },
+ { 0x01FAE , 0x01F6E , 0x00345 },
+ { 0x01FAF , 0x01F6F , 0x00345 },
+ { 0x01FB0 , 0x003B1 , 0x00306 },
+ { 0x01FB1 , 0x003B1 , 0x00304 },
+ { 0x01FB2 , 0x01F70 , 0x00345 },
+ { 0x01FB3 , 0x003B1 , 0x00345 },
+ { 0x01FB4 , 0x003AC , 0x00345 },
+ { 0x01FB6 , 0x003B1 , 0x00342 },
+ { 0x01FB7 , 0x01FB6 , 0x00345 },
+ { 0x01FB8 , 0x00391 , 0x00306 },
+ { 0x01FB9 , 0x00391 , 0x00304 },
+ { 0x01FBA , 0x00391 , 0x00300 },
+ { 0x01FBC , 0x00391 , 0x00345 },
+ { 0x01FC1 , 0x000A8 , 0x00342 },
+ { 0x01FC2 , 0x01F74 , 0x00345 },
+ { 0x01FC3 , 0x003B7 , 0x00345 },
+ { 0x01FC4 , 0x003AE , 0x00345 },
+ { 0x01FC6 , 0x003B7 , 0x00342 },
+ { 0x01FC7 , 0x01FC6 , 0x00345 },
+ { 0x01FC8 , 0x00395 , 0x00300 },
+ { 0x01FCA , 0x00397 , 0x00300 },
+ { 0x01FCC , 0x00397 , 0x00345 },
+ { 0x01FCD , 0x01FBF , 0x00300 },
+ { 0x01FCE , 0x01FBF , 0x00301 },
+ { 0x01FCF , 0x01FBF , 0x00342 },
+ { 0x01FD0 , 0x003B9 , 0x00306 },
+ { 0x01FD1 , 0x003B9 , 0x00304 },
+ { 0x01FD2 , 0x003CA , 0x00300 },
+ { 0x01FD6 , 0x003B9 , 0x00342 },
+ { 0x01FD7 , 0x003CA , 0x00342 },
+ { 0x01FD8 , 0x00399 , 0x00306 },
+ { 0x01FD9 , 0x00399 , 0x00304 },
+ { 0x01FDA , 0x00399 , 0x00300 },
+ { 0x01FDD , 0x01FFE , 0x00300 },
+ { 0x01FDE , 0x01FFE , 0x00301 },
+ { 0x01FDF , 0x01FFE , 0x00342 },
+ { 0x01FE0 , 0x003C5 , 0x00306 },
+ { 0x01FE1 , 0x003C5 , 0x00304 },
+ { 0x01FE2 , 0x003CB , 0x00300 },
+ { 0x01FE4 , 0x003C1 , 0x00313 },
+ { 0x01FE5 , 0x003C1 , 0x00314 },
+ { 0x01FE6 , 0x003C5 , 0x00342 },
+ { 0x01FE7 , 0x003CB , 0x00342 },
+ { 0x01FE8 , 0x003A5 , 0x00306 },
+ { 0x01FE9 , 0x003A5 , 0x00304 },
+ { 0x01FEA , 0x003A5 , 0x00300 },
+ { 0x01FEC , 0x003A1 , 0x00314 },
+ { 0x01FED , 0x000A8 , 0x00300 },
+ { 0x01FF2 , 0x01F7C , 0x00345 },
+ { 0x01FF3 , 0x003C9 , 0x00345 },
+ { 0x01FF4 , 0x003CE , 0x00345 },
+ { 0x01FF6 , 0x003C9 , 0x00342 },
+ { 0x01FF7 , 0x01FF6 , 0x00345 },
+ { 0x01FF8 , 0x0039F , 0x00300 },
+ { 0x01FFA , 0x003A9 , 0x00300 },
+ { 0x01FFC , 0x003A9 , 0x00345 },
+ { 0x0219A , 0x02190 , 0x00338 },
+ { 0x0219B , 0x02192 , 0x00338 },
+ { 0x021AE , 0x02194 , 0x00338 },
+ { 0x021CD , 0x021D0 , 0x00338 },
+ { 0x021CE , 0x021D4 , 0x00338 },
+ { 0x021CF , 0x021D2 , 0x00338 },
+ { 0x02204 , 0x02203 , 0x00338 },
+ { 0x02209 , 0x02208 , 0x00338 },
+ { 0x0220C , 0x0220B , 0x00338 },
+ { 0x02224 , 0x02223 , 0x00338 },
+ { 0x02226 , 0x02225 , 0x00338 },
+ { 0x02241 , 0x0223C , 0x00338 },
+ { 0x02244 , 0x02243 , 0x00338 },
+ { 0x02247 , 0x02245 , 0x00338 },
+ { 0x02249 , 0x02248 , 0x00338 },
+ { 0x02260 , 0x0003D , 0x00338 },
+ { 0x02262 , 0x02261 , 0x00338 },
+ { 0x0226D , 0x0224D , 0x00338 },
+ { 0x0226E , 0x0003C , 0x00338 },
+ { 0x0226F , 0x0003E , 0x00338 },
+ { 0x02270 , 0x02264 , 0x00338 },
+ { 0x02271 , 0x02265 , 0x00338 },
+ { 0x02274 , 0x02272 , 0x00338 },
+ { 0x02275 , 0x02273 , 0x00338 },
+ { 0x02278 , 0x02276 , 0x00338 },
+ { 0x02279 , 0x02277 , 0x00338 },
+ { 0x02280 , 0x0227A , 0x00338 },
+ { 0x02281 , 0x0227B , 0x00338 },
+ { 0x02284 , 0x02282 , 0x00338 },
+ { 0x02285 , 0x02283 , 0x00338 },
+ { 0x02288 , 0x02286 , 0x00338 },
+ { 0x02289 , 0x02287 , 0x00338 },
+ { 0x022AC , 0x022A2 , 0x00338 },
+ { 0x022AD , 0x022A8 , 0x00338 },
+ { 0x022AE , 0x022A9 , 0x00338 },
+ { 0x022AF , 0x022AB , 0x00338 },
+ { 0x022E0 , 0x0227C , 0x00338 },
+ { 0x022E1 , 0x0227D , 0x00338 },
+ { 0x022E2 , 0x02291 , 0x00338 },
+ { 0x022E3 , 0x02292 , 0x00338 },
+ { 0x022EA , 0x022B2 , 0x00338 },
+ { 0x022EB , 0x022B3 , 0x00338 },
+ { 0x022EC , 0x022B4 , 0x00338 },
+ { 0x022ED , 0x022B5 , 0x00338 },
+ { 0x0304C , 0x0304B , 0x03099 },
+ { 0x0304E , 0x0304D , 0x03099 },
+ { 0x03050 , 0x0304F , 0x03099 },
+ { 0x03052 , 0x03051 , 0x03099 },
+ { 0x03054 , 0x03053 , 0x03099 },
+ { 0x03056 , 0x03055 , 0x03099 },
+ { 0x03058 , 0x03057 , 0x03099 },
+ { 0x0305A , 0x03059 , 0x03099 },
+ { 0x0305C , 0x0305B , 0x03099 },
+ { 0x0305E , 0x0305D , 0x03099 },
+ { 0x03060 , 0x0305F , 0x03099 },
+ { 0x03062 , 0x03061 , 0x03099 },
+ { 0x03065 , 0x03064 , 0x03099 },
+ { 0x03067 , 0x03066 , 0x03099 },
+ { 0x03069 , 0x03068 , 0x03099 },
+ { 0x03070 , 0x0306F , 0x03099 },
+ { 0x03071 , 0x0306F , 0x0309A },
+ { 0x03073 , 0x03072 , 0x03099 },
+ { 0x03074 , 0x03072 , 0x0309A },
+ { 0x03076 , 0x03075 , 0x03099 },
+ { 0x03077 , 0x03075 , 0x0309A },
+ { 0x03079 , 0x03078 , 0x03099 },
+ { 0x0307A , 0x03078 , 0x0309A },
+ { 0x0307C , 0x0307B , 0x03099 },
+ { 0x0307D , 0x0307B , 0x0309A },
+ { 0x03094 , 0x03046 , 0x03099 },
+ { 0x0309E , 0x0309D , 0x03099 },
+ { 0x030AC , 0x030AB , 0x03099 },
+ { 0x030AE , 0x030AD , 0x03099 },
+ { 0x030B0 , 0x030AF , 0x03099 },
+ { 0x030B2 , 0x030B1 , 0x03099 },
+ { 0x030B4 , 0x030B3 , 0x03099 },
+ { 0x030B6 , 0x030B5 , 0x03099 },
+ { 0x030B8 , 0x030B7 , 0x03099 },
+ { 0x030BA , 0x030B9 , 0x03099 },
+ { 0x030BC , 0x030BB , 0x03099 },
+ { 0x030BE , 0x030BD , 0x03099 },
+ { 0x030C0 , 0x030BF , 0x03099 },
+ { 0x030C2 , 0x030C1 , 0x03099 },
+ { 0x030C5 , 0x030C4 , 0x03099 },
+ { 0x030C7 , 0x030C6 , 0x03099 },
+ { 0x030C9 , 0x030C8 , 0x03099 },
+ { 0x030D0 , 0x030CF , 0x03099 },
+ { 0x030D1 , 0x030CF , 0x0309A },
+ { 0x030D3 , 0x030D2 , 0x03099 },
+ { 0x030D4 , 0x030D2 , 0x0309A },
+ { 0x030D6 , 0x030D5 , 0x03099 },
+ { 0x030D7 , 0x030D5 , 0x0309A },
+ { 0x030D9 , 0x030D8 , 0x03099 },
+ { 0x030DA , 0x030D8 , 0x0309A },
+ { 0x030DC , 0x030DB , 0x03099 },
+ { 0x030DD , 0x030DB , 0x0309A },
+ { 0x030F4 , 0x030A6 , 0x03099 },
+ { 0x030F7 , 0x030EF , 0x03099 },
+ { 0x030F8 , 0x030F0 , 0x03099 },
+ { 0x030F9 , 0x030F1 , 0x03099 },
+ { 0x030FA , 0x030F2 , 0x03099 },
+ { 0x030FE , 0x030FD , 0x03099 },
+ { 0x1109A , 0x11099 , 0x110BA },
+ { 0x1109C , 0x1109B , 0x110BA },
+ { 0x110AB , 0x110A5 , 0x110BA },
+};
+
+#endif /* ARCHIVE_STRING_COMPOSITION_H_INCLUDED */
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c b/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c
new file mode 100644
index 0000000000..964ea2bea1
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c
@@ -0,0 +1,192 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_string_sprintf.c 189435 2009-03-06 05:14:55Z kientzle $");
+
+/*
+ * The use of printf()-family functions can be troublesome
+ * for space-constrained applications. In addition, correctly
+ * implementing this function in terms of vsnprintf() requires
+ * two calls (one to determine the size, another to format the
+ * result), which in turn requires duplicating the argument list
+ * using va_copy, which isn't yet universally available. <sigh>
+ *
+ * So, I've implemented a bare minimum of printf()-like capability
+ * here. This is only used to format error messages, so doesn't
+ * require any floating-point support or field-width handling.
+ */
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <stdio.h>
+
+#include "archive_string.h"
+#include "archive_private.h"
+
+/*
+ * Utility functions to format signed/unsigned integers and append
+ * them to an archive_string.
+ */
+static void
+append_uint(struct archive_string *as, uintmax_t d, unsigned base)
+{
+ static const char *digits = "0123456789abcdef";
+ if (d >= base)
+ append_uint(as, d/base, base);
+ archive_strappend_char(as, digits[d % base]);
+}
+
+static void
+append_int(struct archive_string *as, intmax_t d, unsigned base)
+{
+ uintmax_t ud;
+
+ if (d < 0) {
+ archive_strappend_char(as, '-');
+ ud = (d == INTMAX_MIN) ? (uintmax_t)(INTMAX_MAX) + 1 : (uintmax_t)(-d);
+ } else
+ ud = d;
+ append_uint(as, ud, base);
+}
+
+
+void
+archive_string_sprintf(struct archive_string *as, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ archive_string_vsprintf(as, fmt, ap);
+ va_end(ap);
+}
+
+/*
+ * Like 'vsprintf', but ensures the target is big enough, resizing if
+ * necessary.
+ */
+void
+archive_string_vsprintf(struct archive_string *as, const char *fmt,
+ va_list ap)
+{
+ char long_flag;
+ intmax_t s; /* Signed integer temp. */
+ uintmax_t u; /* Unsigned integer temp. */
+ const char *p, *p2;
+ const wchar_t *pw;
+
+ if (archive_string_ensure(as, 64) == NULL)
+ __archive_errx(1, "Out of memory");
+
+ if (fmt == NULL) {
+ as->s[0] = 0;
+ return;
+ }
+
+ for (p = fmt; *p != '\0'; p++) {
+ const char *saved_p = p;
+
+ if (*p != '%') {
+ archive_strappend_char(as, *p);
+ continue;
+ }
+
+ p++;
+
+ long_flag = '\0';
+ switch(*p) {
+ case 'j':
+ case 'l':
+ case 'z':
+ long_flag = *p;
+ p++;
+ break;
+ }
+
+ switch (*p) {
+ case '%':
+ archive_strappend_char(as, '%');
+ break;
+ case 'c':
+ s = va_arg(ap, int);
+ archive_strappend_char(as, (char)s);
+ break;
+ case 'd':
+ switch(long_flag) {
+ case 'j': s = va_arg(ap, intmax_t); break;
+ case 'l': s = va_arg(ap, long); break;
+ case 'z': s = va_arg(ap, ssize_t); break;
+ default: s = va_arg(ap, int); break;
+ }
+ append_int(as, s, 10);
+ break;
+ case 's':
+ switch(long_flag) {
+ case 'l':
+ pw = va_arg(ap, wchar_t *);
+ if (pw == NULL)
+ pw = L"(null)";
+ if (archive_string_append_from_wcs(as, pw,
+ wcslen(pw)) != 0 && errno == ENOMEM)
+ __archive_errx(1, "Out of memory");
+ break;
+ default:
+ p2 = va_arg(ap, char *);
+ if (p2 == NULL)
+ p2 = "(null)";
+ archive_strcat(as, p2);
+ break;
+ }
+ break;
+ case 'S':
+ pw = va_arg(ap, wchar_t *);
+ if (pw == NULL)
+ pw = L"(null)";
+ if (archive_string_append_from_wcs(as, pw,
+ wcslen(pw)) != 0 && errno == ENOMEM)
+ __archive_errx(1, "Out of memory");
+ break;
+ case 'o': case 'u': case 'x': case 'X':
+ /* Common handling for unsigned integer formats. */
+ switch(long_flag) {
+ case 'j': u = va_arg(ap, uintmax_t); break;
+ case 'l': u = va_arg(ap, unsigned long); break;
+ case 'z': u = va_arg(ap, size_t); break;
+ default: u = va_arg(ap, unsigned int); break;
+ }
+ /* Format it in the correct base. */
+ switch (*p) {
+ case 'o': append_uint(as, u, 8); break;
+ case 'u': append_uint(as, u, 10); break;
+ default: append_uint(as, u, 16); break;
+ }
+ break;
+ default:
+ /* Rewind and print the initial '%' literally. */
+ p = saved_p;
+ archive_strappend_char(as, *p);
+ }
+ }
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_util.3 b/Utilities/cmlibarchive/libarchive/archive_util.3
new file mode 100644
index 0000000000..99ab842a28
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_util.3
@@ -0,0 +1,224 @@
+.\" Copyright (c) 2003-2007 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_UTIL 3
+.Os
+.Sh NAME
+.Nm archive_clear_error ,
+.Nm archive_compression ,
+.Nm archive_compression_name ,
+.Nm archive_copy_error ,
+.Nm archive_errno ,
+.Nm archive_error_string ,
+.Nm archive_file_count ,
+.Nm archive_filter_code ,
+.Nm archive_filter_count ,
+.Nm archive_filter_name ,
+.Nm archive_format ,
+.Nm archive_format_name ,
+.Nm archive_position ,
+.Nm archive_set_error
+.Nd libarchive utility functions
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft void
+.Fn archive_clear_error "struct archive *"
+.Ft int
+.Fn archive_compression "struct archive *"
+.Ft const char *
+.Fn archive_compression_name "struct archive *"
+.Ft void
+.Fn archive_copy_error "struct archive *" "struct archive *"
+.Ft int
+.Fn archive_errno "struct archive *"
+.Ft const char *
+.Fn archive_error_string "struct archive *"
+.Ft int
+.Fn archive_file_count "struct archive *"
+.Ft int
+.Fn archive_filter_code "struct archive *" "int"
+.Ft int
+.Fn archive_filter_count "struct archive *" "int"
+.Ft const char *
+.Fn archive_filter_name "struct archive *" "int"
+.Ft int
+.Fn archive_format "struct archive *"
+.Ft const char *
+.Fn archive_format_name "struct archive *"
+.Ft int64_t
+.Fn archive_position "struct archive *" "int"
+.Ft void
+.Fo archive_set_error
+.Fa "struct archive *"
+.Fa "int error_code"
+.Fa "const char *fmt"
+.Fa "..."
+.Fc
+.Sh DESCRIPTION
+These functions provide access to various information about the
+.Tn struct archive
+object used in the
+.Xr libarchive 3
+library.
+.Bl -tag -compact -width indent
+.It Fn archive_clear_error
+Clears any error information left over from a previous call.
+Not generally used in client code.
+.It Fn archive_compression
+Synonym for
+.Fn archive_filter_code(a, 0) .
+.It Fn archive_compression_name
+Synonym for
+.Fn archive_filter_name(a, 0) .
+.It Fn archive_copy_error
+Copies error information from one archive to another.
+.It Fn archive_errno
+Returns a numeric error code (see
+.Xr errno 2 )
+indicating the reason for the most recent error return.
+Note that this can not be reliably used to detect whether an
+error has occurred.
+It should be used only after another libarchive function
+has returned an error status.
+.It Fn archive_error_string
+Returns a textual error message suitable for display.
+The error message here is usually more specific than that
+obtained from passing the result of
+.Fn archive_errno
+to
+.Xr strerror 3 .
+.It Fn archive_file_count
+Returns a count of the number of files processed by this archive object.
+The count is incremented by calls to
+.Xr archive_write_header 3
+or
+.Xr archive_read_next_header 3 .
+.It Fn archive_filter_code
+Returns a numeric code identifying the indicated filter.
+See
+.Fn archive_filter_count
+for details of the numbering.
+.It Fn archive_filter_count
+Returns the number of filters in the current pipeline.
+For read archive handles, these filters are added automatically
+by the automatic format detection.
+For write archive handles, these filters are added by calls to the various
+.Fn archive_write_add_filter_XXX
+functions.
+Filters in the resulting pipeline are numbered so that filter 0
+is the filter closest to the format handler.
+As a convenience, functions that expect a filter number will
+accept -1 as a synonym for the highest-numbered filter.
+.Pp
+For example, when reading a uuencoded gzipped tar archive, there
+are three filters:
+filter 0 is the gunzip filter,
+filter 1 is the uudecode filter,
+and filter 2 is the pseudo-filter that wraps the archive read functions.
+In this case, requesting
+.Fn archive_position(a, -1)
+would be a synonym for
+.Fn archive_position(a, 2)
+which would return the number of bytes currently read from the archive, while
+.Fn archive_position(a, 1)
+would return the number of bytes after uudecoding, and
+.Fn archive_position(a, 0)
+would return the number of bytes after decompression.
+.It Fn archive_filter_name
+Returns a textual name identifying the indicated filter.
+See
+.Fn archive_filter_count
+for details of the numbering.
+.It Fn archive_format
+Returns a numeric code indicating the format of the current
+archive entry.
+This value is set by a successful call to
+.Fn archive_read_next_header .
+Note that it is common for this value to change from
+entry to entry.
+For example, a tar archive might have several entries that
+utilize GNU tar extensions and several entries that do not.
+These entries will have different format codes.
+.It Fn archive_format_name
+A textual description of the format of the current entry.
+.It Fn archive_position
+Returns the number of bytes read from or written to the indicated filter.
+In particular,
+.Fn archive_position(a, 0)
+returns the number of bytes read or written by the format handler, while
+.Fn archive_position(a, -1)
+returns the number of bytes read or written to the archive.
+See
+.Fn archive_filter_count
+for details of the numbering here.
+.It Fn archive_set_error
+Sets the numeric error code and error description that will be returned
+by
+.Fn archive_errno
+and
+.Fn archive_error_string .
+This function should be used within I/O callbacks to set system-specific
+error codes and error descriptions.
+This function accepts a printf-like format string and arguments.
+However, you should be careful to use only the following printf
+format specifiers:
+.Dq %c ,
+.Dq %d ,
+.Dq %jd ,
+.Dq %jo ,
+.Dq %ju ,
+.Dq %jx ,
+.Dq %ld ,
+.Dq %lo ,
+.Dq %lu ,
+.Dq %lx ,
+.Dq %o ,
+.Dq %u ,
+.Dq %s ,
+.Dq %x ,
+.Dq %% .
+Field-width specifiers and other printf features are
+not uniformly supported and should not be used.
+.El
+.Sh SEE ALSO
+.Xr archive_read 3 ,
+.Xr archive_write 3 ,
+.Xr libarchive 3 ,
+.Xr printf 3
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libarchive
+library was written by
+.An Tim Kientzle Aq kientzle@acm.org .
diff --git a/Utilities/cmlibarchive/libarchive/archive_util.c b/Utilities/cmlibarchive/libarchive/archive_util.c
new file mode 100644
index 0000000000..96b88d8640
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_util.c
@@ -0,0 +1,610 @@
+/*-
+ * Copyright (c) 2009-2012 Michihiro NAKAJIMA
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_util.c 201098 2009-12-28 02:58:14Z kientzle $");
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#if defined(HAVE_WINCRYPT_H) && !defined(__CYGWIN__)
+#include <wincrypt.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+#ifdef HAVE_LZMA_H
+#include <cm_lzma.h>
+#endif
+#ifdef HAVE_BZLIB_H
+#include <cm_bzlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_string.h"
+
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
+static int archive_utility_string_sort_helper(char **, unsigned int);
+
+/* Generic initialization of 'struct archive' objects. */
+int
+__archive_clean(struct archive *a)
+{
+ archive_string_conversion_free(a);
+ return (ARCHIVE_OK);
+}
+
+int
+archive_version_number(void)
+{
+ return (ARCHIVE_VERSION_NUMBER);
+}
+
+const char *
+archive_version_string(void)
+{
+ return (ARCHIVE_VERSION_STRING);
+}
+
+const char *
+archive_version_details(void)
+{
+ static struct archive_string str;
+ static int init = 0;
+
+ if (!init) {
+ archive_string_init(&str);
+
+ archive_strcat(&str, ARCHIVE_VERSION_STRING);
+#ifdef HAVE_ZLIB_H
+ archive_strcat(&str, " zlib/");
+ archive_strcat(&str, ZLIB_VERSION);
+#endif
+#ifdef HAVE_LZMA_H
+ archive_strcat(&str, " liblzma/");
+ archive_strcat(&str, LZMA_VERSION_STRING);
+#endif
+#ifdef HAVE_BZLIB_H
+ {
+ const char *p = BZ2_bzlibVersion();
+ const char *sep = strchr(p, ',');
+ if (sep == NULL)
+ sep = p + strlen(p);
+ archive_strcat(&str, " bz2lib/");
+ archive_strncat(&str, p, sep - p);
+ }
+#endif
+ }
+ return str.s;
+}
+
+int
+archive_errno(struct archive *a)
+{
+ return (a->archive_error_number);
+}
+
+const char *
+archive_error_string(struct archive *a)
+{
+
+ if (a->error != NULL && *a->error != '\0')
+ return (a->error);
+ else
+ return (NULL);
+}
+
+int
+archive_file_count(struct archive *a)
+{
+ return (a->file_count);
+}
+
+int
+archive_format(struct archive *a)
+{
+ return (a->archive_format);
+}
+
+const char *
+archive_format_name(struct archive *a)
+{
+ return (a->archive_format_name);
+}
+
+
+int
+archive_compression(struct archive *a)
+{
+ return archive_filter_code(a, 0);
+}
+
+const char *
+archive_compression_name(struct archive *a)
+{
+ return archive_filter_name(a, 0);
+}
+
+
+/*
+ * Return a count of the number of compressed bytes processed.
+ */
+int64_t
+archive_position_compressed(struct archive *a)
+{
+ return archive_filter_bytes(a, -1);
+}
+
+/*
+ * Return a count of the number of uncompressed bytes processed.
+ */
+int64_t
+archive_position_uncompressed(struct archive *a)
+{
+ return archive_filter_bytes(a, 0);
+}
+
+void
+archive_clear_error(struct archive *a)
+{
+ archive_string_empty(&a->error_string);
+ a->error = NULL;
+ a->archive_error_number = 0;
+}
+
+void
+archive_set_error(struct archive *a, int error_number, const char *fmt, ...)
+{
+ va_list ap;
+
+ a->archive_error_number = error_number;
+ if (fmt == NULL) {
+ a->error = NULL;
+ return;
+ }
+
+ archive_string_empty(&(a->error_string));
+ va_start(ap, fmt);
+ archive_string_vsprintf(&(a->error_string), fmt, ap);
+ va_end(ap);
+ a->error = a->error_string.s;
+}
+
+void
+archive_copy_error(struct archive *dest, struct archive *src)
+{
+ dest->archive_error_number = src->archive_error_number;
+
+ archive_string_copy(&dest->error_string, &src->error_string);
+ dest->error = dest->error_string.s;
+}
+
+void
+__archive_errx(int retvalue, const char *msg)
+{
+ static const char *msg1 = "Fatal Internal Error in libarchive: ";
+ size_t s;
+
+ s = write(2, msg1, strlen(msg1));
+ (void)s; /* UNUSED */
+ s = write(2, msg, strlen(msg));
+ (void)s; /* UNUSED */
+ s = write(2, "\n", 1);
+ (void)s; /* UNUSED */
+ exit(retvalue);
+}
+
+/*
+ * Create a temporary file
+ */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+/*
+ * Do not use Windows tmpfile() function.
+ * It will make a temporary file under the root directory
+ * and it'll cause permission error if a user who is
+ * non-Administrator creates temporary files.
+ * Also Windows version of mktemp family including _mktemp_s
+ * are not secure.
+ */
+int
+__archive_mktemp(const char *tmpdir)
+{
+ static const wchar_t num[] = {
+ L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7',
+ L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F',
+ L'G', L'H', L'I', L'J', L'K', L'L', L'M', L'N',
+ L'O', L'P', L'Q', L'R', L'S', L'T', L'U', L'V',
+ L'W', L'X', L'Y', L'Z', L'a', L'b', L'c', L'd',
+ L'e', L'f', L'g', L'h', L'i', L'j', L'k', L'l',
+ L'm', L'n', L'o', L'p', L'q', L'r', L's', L't',
+ L'u', L'v', L'w', L'x', L'y', L'z'
+ };
+ HCRYPTPROV hProv;
+ struct archive_wstring temp_name;
+ wchar_t *ws;
+ DWORD attr;
+ wchar_t *xp, *ep;
+ int fd;
+
+ hProv = (HCRYPTPROV)NULL;
+ fd = -1;
+ ws = NULL;
+ archive_string_init(&temp_name);
+
+ /* Get a temporary directory. */
+ if (tmpdir == NULL) {
+ size_t l;
+ wchar_t *tmp;
+
+ l = GetTempPathW(0, NULL);
+ if (l == 0) {
+ la_dosmaperr(GetLastError());
+ goto exit_tmpfile;
+ }
+ tmp = malloc(l*sizeof(wchar_t));
+ if (tmp == NULL) {
+ errno = ENOMEM;
+ goto exit_tmpfile;
+ }
+ GetTempPathW((DWORD)l, tmp);
+ archive_wstrcpy(&temp_name, tmp);
+ free(tmp);
+ } else {
+ if (archive_wstring_append_from_mbs(&temp_name, tmpdir,
+ strlen(tmpdir)) < 0)
+ goto exit_tmpfile;
+ if (temp_name.s[temp_name.length-1] != L'/')
+ archive_wstrappend_wchar(&temp_name, L'/');
+ }
+
+ /* Check if temp_name is a directory. */
+ attr = GetFileAttributesW(temp_name.s);
+ if (attr == (DWORD)-1) {
+ if (GetLastError() != ERROR_FILE_NOT_FOUND) {
+ la_dosmaperr(GetLastError());
+ goto exit_tmpfile;
+ }
+ ws = __la_win_permissive_name_w(temp_name.s);
+ if (ws == NULL) {
+ errno = EINVAL;
+ goto exit_tmpfile;
+ }
+ attr = GetFileAttributesW(ws);
+ if (attr == (DWORD)-1) {
+ la_dosmaperr(GetLastError());
+ goto exit_tmpfile;
+ }
+ }
+ if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) {
+ errno = ENOTDIR;
+ goto exit_tmpfile;
+ }
+
+ /*
+ * Create a temporary file.
+ */
+ archive_wstrcat(&temp_name, L"libarchive_");
+ xp = temp_name.s + archive_strlen(&temp_name);
+ archive_wstrcat(&temp_name, L"XXXXXXXXXX");
+ ep = temp_name.s + archive_strlen(&temp_name);
+
+ if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
+ CRYPT_VERIFYCONTEXT)) {
+ la_dosmaperr(GetLastError());
+ goto exit_tmpfile;
+ }
+
+ for (;;) {
+ wchar_t *p;
+ HANDLE h;
+
+ /* Generate a random file name through CryptGenRandom(). */
+ p = xp;
+ if (!CryptGenRandom(hProv, (DWORD)(ep - p)*sizeof(wchar_t),
+ (BYTE*)p)) {
+ la_dosmaperr(GetLastError());
+ goto exit_tmpfile;
+ }
+ for (; p < ep; p++)
+ *p = num[((DWORD)*p) % (sizeof(num)/sizeof(num[0]))];
+
+ free(ws);
+ ws = __la_win_permissive_name_w(temp_name.s);
+ if (ws == NULL) {
+ errno = EINVAL;
+ goto exit_tmpfile;
+ }
+ /* Specifies FILE_FLAG_DELETE_ON_CLOSE flag is to
+ * delete this temporary file immediately when this
+ * file closed. */
+ h = CreateFileW(ws,
+ GENERIC_READ | GENERIC_WRITE | DELETE,
+ 0,/* Not share */
+ NULL,
+ CREATE_NEW,/* Create a new file only */
+ FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
+ NULL);
+ if (h == INVALID_HANDLE_VALUE) {
+ /* The same file already exists. retry with
+ * a new filename. */
+ if (GetLastError() == ERROR_FILE_EXISTS)
+ continue;
+ /* Otherwise, fail creation temporary file. */
+ la_dosmaperr(GetLastError());
+ goto exit_tmpfile;
+ }
+ fd = _open_osfhandle((intptr_t)h, _O_BINARY | _O_RDWR);
+ if (fd == -1) {
+ CloseHandle(h);
+ goto exit_tmpfile;
+ } else
+ break;/* success! */
+ }
+exit_tmpfile:
+ if (hProv != (HCRYPTPROV)NULL)
+ CryptReleaseContext(hProv, 0);
+ free(ws);
+ archive_wstring_free(&temp_name);
+ return (fd);
+}
+
+#else
+
+static int
+get_tempdir(struct archive_string *temppath)
+{
+ const char *tmp;
+
+ tmp = getenv("TMPDIR");
+ if (tmp == NULL)
+#ifdef _PATH_TMP
+ tmp = _PATH_TMP;
+#else
+ tmp = "/tmp";
+#endif
+ archive_strcpy(temppath, tmp);
+ if (temppath->s[temppath->length-1] != '/')
+ archive_strappend_char(temppath, '/');
+ return (ARCHIVE_OK);
+}
+
+#if defined(HAVE_MKSTEMP)
+
+/*
+ * We can use mkstemp().
+ */
+
+int
+__archive_mktemp(const char *tmpdir)
+{
+ struct archive_string temp_name;
+ int fd = -1;
+
+ archive_string_init(&temp_name);
+ if (tmpdir == NULL) {
+ if (get_tempdir(&temp_name) != ARCHIVE_OK)
+ goto exit_tmpfile;
+ } else {
+ archive_strcpy(&temp_name, tmpdir);
+ if (temp_name.s[temp_name.length-1] != '/')
+ archive_strappend_char(&temp_name, '/');
+ }
+ archive_strcat(&temp_name, "libarchive_XXXXXX");
+ fd = mkstemp(temp_name.s);
+ if (fd < 0)
+ goto exit_tmpfile;
+ __archive_ensure_cloexec_flag(fd);
+ unlink(temp_name.s);
+exit_tmpfile:
+ archive_string_free(&temp_name);
+ return (fd);
+}
+
+#else
+
+/*
+ * We use a private routine.
+ */
+
+int
+__archive_mktemp(const char *tmpdir)
+{
+ static const char num[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
+ 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
+ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
+ 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
+ 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
+ 'u', 'v', 'w', 'x', 'y', 'z'
+ };
+ struct archive_string temp_name;
+ struct stat st;
+ int fd;
+ char *tp, *ep;
+ unsigned seed;
+
+ fd = -1;
+ archive_string_init(&temp_name);
+ if (tmpdir == NULL) {
+ if (get_tempdir(&temp_name) != ARCHIVE_OK)
+ goto exit_tmpfile;
+ } else
+ archive_strcpy(&temp_name, tmpdir);
+ if (temp_name.s[temp_name.length-1] == '/') {
+ temp_name.s[temp_name.length-1] = '\0';
+ temp_name.length --;
+ }
+ if (stat(temp_name.s, &st) < 0)
+ goto exit_tmpfile;
+ if (!S_ISDIR(st.st_mode)) {
+ errno = ENOTDIR;
+ goto exit_tmpfile;
+ }
+ archive_strcat(&temp_name, "/libarchive_");
+ tp = temp_name.s + archive_strlen(&temp_name);
+ 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)];
+ fd = open(temp_name.s, O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC,
+ 0600);
+ } while (fd < 0 && errno == EEXIST);
+ if (fd < 0)
+ goto exit_tmpfile;
+ __archive_ensure_cloexec_flag(fd);
+ unlink(temp_name.s);
+exit_tmpfile:
+ archive_string_free(&temp_name);
+ return (fd);
+}
+
+#endif /* HAVE_MKSTEMP */
+#endif /* !_WIN32 || __CYGWIN__ */
+
+/*
+ * Set FD_CLOEXEC flag to a file descriptor if it is not set.
+ * We have to set the flag if the platform does not provide O_CLOEXEC
+ * or F_DUPFD_CLOEXEC flags.
+ *
+ * Note: This function is absolutely called after creating a new file
+ * descriptor even if the platform seemingly provides O_CLOEXEC or
+ * F_DUPFD_CLOEXEC macros because it is possible that the platform
+ * merely declares those macros, especially Linux 2.6.18 - 2.6.24 do it.
+ */
+void
+__archive_ensure_cloexec_flag(int fd)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ (void)fd; /* UNSED */
+#else
+ int flags;
+
+ if (fd >= 0) {
+ flags = fcntl(fd, F_GETFD);
+ if (flags != -1 && (flags & FD_CLOEXEC) == 0)
+ fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+ }
+#endif
+}
+
+/*
+ * Utility function to sort a group of strings using quicksort.
+ */
+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;
+}
+
+int
+archive_utility_string_sort(char **strings)
+{
+ unsigned int size = 0;
+ while (strings[size] != NULL)
+ size++;
+ return archive_utility_string_sort_helper(strings, size);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_virtual.c b/Utilities/cmlibarchive/libarchive/archive_virtual.c
new file mode 100644
index 0000000000..de2595a9ea
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_virtual.c
@@ -0,0 +1,162 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_virtual.c 201098 2009-12-28 02:58:14Z kientzle $");
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+
+int
+archive_filter_code(struct archive *a, int n)
+{
+ return ((a->vtable->archive_filter_code)(a, n));
+}
+
+int
+archive_filter_count(struct archive *a)
+{
+ return ((a->vtable->archive_filter_count)(a));
+}
+
+const char *
+archive_filter_name(struct archive *a, int n)
+{
+ return ((a->vtable->archive_filter_name)(a, n));
+}
+
+int64_t
+archive_filter_bytes(struct archive *a, int n)
+{
+ return ((a->vtable->archive_filter_bytes)(a, n));
+}
+
+int
+archive_free(struct archive *a)
+{
+ if (a == NULL)
+ return (ARCHIVE_OK);
+ return ((a->vtable->archive_free)(a));
+}
+
+int
+archive_write_close(struct archive *a)
+{
+ return ((a->vtable->archive_close)(a));
+}
+
+int
+archive_read_close(struct archive *a)
+{
+ return ((a->vtable->archive_close)(a));
+}
+
+int
+archive_write_fail(struct archive *a)
+{
+ a->state = ARCHIVE_STATE_FATAL;
+ return a->state;
+}
+
+int
+archive_write_free(struct archive *a)
+{
+ return archive_free(a);
+}
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* For backwards compatibility; will be removed with libarchive 4.0. */
+int
+archive_write_finish(struct archive *a)
+{
+ return archive_write_free(a);
+}
+#endif
+
+int
+archive_read_free(struct archive *a)
+{
+ return archive_free(a);
+}
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+/* For backwards compatibility; will be removed with libarchive 4.0. */
+int
+archive_read_finish(struct archive *a)
+{
+ return archive_read_free(a);
+}
+#endif
+
+int
+archive_write_header(struct archive *a, struct archive_entry *entry)
+{
+ ++a->file_count;
+ return ((a->vtable->archive_write_header)(a, entry));
+}
+
+int
+archive_write_finish_entry(struct archive *a)
+{
+ return ((a->vtable->archive_write_finish_entry)(a));
+}
+
+ssize_t
+archive_write_data(struct archive *a, const void *buff, size_t s)
+{
+ return ((a->vtable->archive_write_data)(a, buff, s));
+}
+
+ssize_t
+archive_write_data_block(struct archive *a, const void *buff, size_t s, int64_t o)
+{
+ if (a->vtable->archive_write_data_block == NULL) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "archive_write_data_block not supported");
+ a->state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ return ((a->vtable->archive_write_data_block)(a, buff, s, o));
+}
+
+int
+archive_read_next_header(struct archive *a, struct archive_entry **entry)
+{
+ return ((a->vtable->archive_read_next_header)(a, entry));
+}
+
+int
+archive_read_next_header2(struct archive *a, struct archive_entry *entry)
+{
+ return ((a->vtable->archive_read_next_header2)(a, entry));
+}
+
+int
+archive_read_data_block(struct archive *a,
+ const void **buff, size_t *s, int64_t *o)
+{
+ return ((a->vtable->archive_read_data_block)(a, buff, s, o));
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_windows.c b/Utilities/cmlibarchive/libarchive/archive_windows.c
new file mode 100644
index 0000000000..d4e93fe78a
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_windows.c
@@ -0,0 +1,908 @@
+/*-
+ * Copyright (c) 2009-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2003-2007 Kees Zeelenberg
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * A set of compatibility glue for building libarchive on Windows platforms.
+ *
+ * Originally created as "libarchive-nonposix.c" by Kees Zeelenberg
+ * for the GnuWin32 project, trimmed significantly by Tim Kientzle.
+ *
+ * Much of the original file was unnecessary for libarchive, because
+ * many of the features it emulated were not strictly necessary for
+ * libarchive. I hope for this to shrink further as libarchive
+ * internals are gradually reworked to sit more naturally on both
+ * POSIX and Windows. Any ideas for this are greatly appreciated.
+ *
+ * The biggest remaining issue is the dev/ino emulation; libarchive
+ * has a couple of public APIs that rely on dev/ino uniquely
+ * identifying a file. This doesn't match well with Windows. I'm
+ * considering alternative APIs.
+ */
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+#include "archive_platform.h"
+#include "archive_private.h"
+#include "archive_entry.h"
+#include <ctype.h>
+#include <errno.h>
+#include <stddef.h>
+#ifdef HAVE_SYS_UTIME_H
+#include <sys/utime.h>
+#endif
+#include <sys/stat.h>
+#include <locale.h>
+#include <process.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <windows.h>
+#include <share.h>
+
+#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
+
+#if defined(__LA_LSEEK_NEEDED)
+static BOOL SetFilePointerEx_perso(HANDLE hFile,
+ LARGE_INTEGER liDistanceToMove,
+ PLARGE_INTEGER lpNewFilePointer,
+ DWORD dwMoveMethod)
+{
+ LARGE_INTEGER li;
+ li.QuadPart = liDistanceToMove.QuadPart;
+ li.LowPart = SetFilePointer(
+ hFile, li.LowPart, &li.HighPart, dwMoveMethod);
+ if(lpNewFilePointer) {
+ lpNewFilePointer->QuadPart = li.QuadPart;
+ }
+ return li.LowPart != -1 || GetLastError() == NO_ERROR;
+}
+#endif
+
+struct ustat {
+ int64_t st_atime;
+ uint32_t st_atime_nsec;
+ int64_t st_ctime;
+ uint32_t st_ctime_nsec;
+ int64_t st_mtime;
+ uint32_t st_mtime_nsec;
+ gid_t st_gid;
+ /* 64bits ino */
+ int64_t st_ino;
+ mode_t st_mode;
+ uint32_t st_nlink;
+ uint64_t st_size;
+ uid_t st_uid;
+ dev_t st_dev;
+ dev_t st_rdev;
+};
+
+/* Transform 64-bits ino into 32-bits by hashing.
+ * You do not forget that really unique number size is 64-bits.
+ */
+#define INOSIZE (8*sizeof(ino_t)) /* 32 */
+static __inline ino_t
+getino(struct ustat *ub)
+{
+ ULARGE_INTEGER ino64;
+ ino64.QuadPart = ub->st_ino;
+ /* I don't know this hashing is correct way */
+ return ((ino_t)(ino64.LowPart ^ (ino64.LowPart >> INOSIZE)));
+}
+
+/*
+ * Prepend "\\?\" to the path name and convert it to unicode to permit
+ * an extended-length path for a maximum total path length of 32767
+ * characters.
+ * see also http://msdn.microsoft.com/en-us/library/aa365247.aspx
+ */
+wchar_t *
+__la_win_permissive_name(const char *name)
+{
+ wchar_t *wn;
+ wchar_t *ws;
+ size_t ll;
+
+ ll = strlen(name);
+ wn = malloc((ll + 1) * sizeof(wchar_t));
+ if (wn == NULL)
+ return (NULL);
+ ll = mbstowcs(wn, name, ll);
+ if (ll == (size_t)-1) {
+ free(wn);
+ return (NULL);
+ }
+ wn[ll] = L'\0';
+ ws = __la_win_permissive_name_w(wn);
+ free(wn);
+ return (ws);
+}
+
+wchar_t *
+__la_win_permissive_name_w(const wchar_t *wname)
+{
+ wchar_t *wn, *wnp;
+ wchar_t *ws, *wsp;
+ DWORD l, len, slen;
+ int unc;
+
+ /* Get a full-pathname. */
+ l = GetFullPathNameW(wname, 0, NULL, NULL);
+ if (l == 0)
+ return (NULL);
+ /* NOTE: GetFullPathNameW has a bug that if the length of the file
+ * name is just 1 then it returns incomplete buffer size. Thus, we
+ * have to add three to the size to allocate a sufficient buffer
+ * size for the full-pathname of the file name. */
+ l += 3;
+ wnp = malloc(l * sizeof(wchar_t));
+ if (wnp == NULL)
+ return (NULL);
+ len = GetFullPathNameW(wname, l, wnp, NULL);
+ wn = wnp;
+
+ if (wnp[0] == L'\\' && wnp[1] == L'\\' &&
+ wnp[2] == L'?' && wnp[3] == L'\\')
+ /* We have already a permissive name. */
+ return (wn);
+
+ if (wnp[0] == L'\\' && wnp[1] == L'\\' &&
+ wnp[2] == L'.' && wnp[3] == L'\\') {
+ /* This is a device name */
+ if (((wnp[4] >= L'a' && wnp[4] <= L'z') ||
+ (wnp[4] >= L'A' && wnp[4] <= L'Z')) &&
+ wnp[5] == L':' && wnp[6] == L'\\')
+ wnp[2] = L'?';/* Not device name. */
+ return (wn);
+ }
+
+ unc = 0;
+ if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') {
+ wchar_t *p = &wnp[2];
+
+ /* Skip server-name letters. */
+ while (*p != L'\\' && *p != L'\0')
+ ++p;
+ if (*p == L'\\') {
+ wchar_t *rp = ++p;
+ /* Skip share-name letters. */
+ while (*p != L'\\' && *p != L'\0')
+ ++p;
+ if (*p == L'\\' && p != rp) {
+ /* Now, match patterns such as
+ * "\\server-name\share-name\" */
+ wnp += 2;
+ len -= 2;
+ unc = 1;
+ }
+ }
+ }
+
+ slen = 4 + (unc * 4) + len + 1;
+ ws = wsp = malloc(slen * sizeof(wchar_t));
+ if (ws == NULL) {
+ free(wn);
+ return (NULL);
+ }
+ /* prepend "\\?\" */
+ wcsncpy(wsp, L"\\\\?\\", 4);
+ wsp += 4;
+ slen -= 4;
+ if (unc) {
+ /* append "UNC\" ---> "\\?\UNC\" */
+ wcsncpy(wsp, L"UNC\\", 4);
+ wsp += 4;
+ slen -= 4;
+ }
+ wcsncpy(wsp, wnp, slen);
+ wsp[slen - 1] = L'\0'; /* Ensure null termination. */
+ free(wn);
+ return (ws);
+}
+
+/*
+ * Create a file handle.
+ * This can exceed MAX_PATH limitation.
+ */
+static HANDLE
+la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode,
+ LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
+ DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
+{
+ wchar_t *wpath;
+ HANDLE handle;
+
+ handle = CreateFileA(path, dwDesiredAccess, dwShareMode,
+ lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
+ hTemplateFile);
+ if (handle != INVALID_HANDLE_VALUE)
+ return (handle);
+ if (GetLastError() != ERROR_PATH_NOT_FOUND)
+ return (handle);
+ wpath = __la_win_permissive_name(path);
+ if (wpath == NULL)
+ return (handle);
+ handle = CreateFileW(wpath, dwDesiredAccess, dwShareMode,
+ lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
+ hTemplateFile);
+ free(wpath);
+ return (handle);
+}
+
+#if defined(__LA_LSEEK_NEEDED)
+__int64
+__la_lseek(int fd, __int64 offset, int whence)
+{
+ LARGE_INTEGER distance;
+ LARGE_INTEGER newpointer;
+ HANDLE handle;
+
+ if (fd < 0) {
+ errno = EBADF;
+ return (-1);
+ }
+ handle = (HANDLE)_get_osfhandle(fd);
+ if (GetFileType(handle) != FILE_TYPE_DISK) {
+ errno = EBADF;
+ return (-1);
+ }
+ distance.QuadPart = offset;
+ if (!SetFilePointerEx_perso(handle, distance, &newpointer, whence)) {
+ DWORD lasterr;
+
+ lasterr = GetLastError();
+ if (lasterr == ERROR_BROKEN_PIPE)
+ return (0);
+ if (lasterr == ERROR_ACCESS_DENIED)
+ errno = EBADF;
+ else
+ la_dosmaperr(lasterr);
+ return (-1);
+ }
+ return (newpointer.QuadPart);
+}
+#endif
+
+/* This can exceed MAX_PATH limitation. */
+int
+__la_open(const char *path, int flags, ...)
+{
+ va_list ap;
+ wchar_t *ws;
+ int r, pmode;
+ DWORD attr;
+
+ va_start(ap, flags);
+ pmode = va_arg(ap, int);
+ va_end(ap);
+ ws = NULL;
+ if ((flags & ~O_BINARY) == O_RDONLY) {
+ /*
+ * When we open a directory, _open function returns
+ * "Permission denied" error.
+ */
+ attr = GetFileAttributesA(path);
+ if (attr == (DWORD)-1 && GetLastError() == ERROR_PATH_NOT_FOUND) {
+ ws = __la_win_permissive_name(path);
+ if (ws == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+ attr = GetFileAttributesW(ws);
+ }
+ if (attr == (DWORD)-1) {
+ la_dosmaperr(GetLastError());
+ free(ws);
+ return (-1);
+ }
+ if (attr & FILE_ATTRIBUTE_DIRECTORY) {
+ HANDLE handle;
+
+ if (ws != NULL)
+ handle = CreateFileW(ws, 0, 0, NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS |
+ FILE_ATTRIBUTE_READONLY,
+ NULL);
+ else
+ handle = CreateFileA(path, 0, 0, NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS |
+ FILE_ATTRIBUTE_READONLY,
+ NULL);
+ free(ws);
+ if (handle == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+ r = _open_osfhandle((intptr_t)handle, _O_RDONLY);
+ return (r);
+ }
+ }
+ if (ws == NULL) {
+#if defined(__BORLANDC__)
+ /* Borland has no mode argument.
+ TODO: Fix mode of new file. */
+ r = _open(path, flags);
+#else
+ r = _open(path, flags, pmode);
+#endif
+ if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) {
+ /* Simulate other POSIX system action to pass our test suite. */
+ attr = GetFileAttributesA(path);
+ if (attr == (DWORD)-1)
+ la_dosmaperr(GetLastError());
+ else if (attr & FILE_ATTRIBUTE_DIRECTORY)
+ errno = EISDIR;
+ else
+ errno = EACCES;
+ return (-1);
+ }
+ if (r >= 0 || errno != ENOENT)
+ return (r);
+ ws = __la_win_permissive_name(path);
+ if (ws == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+ }
+ r = _wopen(ws, flags, pmode);
+ if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) {
+ /* Simulate other POSIX system action to pass our test suite. */
+ attr = GetFileAttributesW(ws);
+ if (attr == (DWORD)-1)
+ la_dosmaperr(GetLastError());
+ else if (attr & FILE_ATTRIBUTE_DIRECTORY)
+ errno = EISDIR;
+ else
+ errno = EACCES;
+ }
+ free(ws);
+ return (r);
+}
+
+ssize_t
+__la_read(int fd, void *buf, size_t nbytes)
+{
+ HANDLE handle;
+ DWORD bytes_read, lasterr;
+ int r;
+
+#ifdef _WIN64
+ if (nbytes > UINT32_MAX)
+ nbytes = UINT32_MAX;
+#endif
+ if (fd < 0) {
+ errno = EBADF;
+ return (-1);
+ }
+ /* Do not pass 0 to third parameter of ReadFile(), read bytes.
+ * This will not return to application side. */
+ if (nbytes == 0)
+ return (0);
+ handle = (HANDLE)_get_osfhandle(fd);
+ r = ReadFile(handle, buf, (uint32_t)nbytes,
+ &bytes_read, NULL);
+ if (r == 0) {
+ lasterr = GetLastError();
+ if (lasterr == ERROR_NO_DATA) {
+ errno = EAGAIN;
+ return (-1);
+ }
+ if (lasterr == ERROR_BROKEN_PIPE)
+ return (0);
+ if (lasterr == ERROR_ACCESS_DENIED)
+ errno = EBADF;
+ else
+ la_dosmaperr(lasterr);
+ return (-1);
+ }
+ return ((ssize_t)bytes_read);
+}
+
+/* Convert Windows FILETIME to UTC */
+__inline static void
+fileTimeToUTC(const FILETIME *filetime, time_t *t, long *ns)
+{
+ ULARGE_INTEGER utc;
+
+ utc.HighPart = filetime->dwHighDateTime;
+ utc.LowPart = filetime->dwLowDateTime;
+ if (utc.QuadPart >= EPOC_TIME) {
+ utc.QuadPart -= EPOC_TIME;
+ *t = (time_t)(utc.QuadPart / 10000000); /* milli seconds base */
+ *ns = (long)(utc.QuadPart % 10000000) * 100;/* nano seconds base */
+ } else {
+ *t = 0;
+ *ns = 0;
+ }
+}
+
+/* Stat by handle
+ * Windows' stat() does not accept the path added "\\?\" especially "?"
+ * character.
+ * It means we cannot access the long name path longer than MAX_PATH.
+ * So I've implemented simular Windows' stat() to access the long name path.
+ * And I've added some feature.
+ * 1. set st_ino by nFileIndexHigh and nFileIndexLow of
+ * BY_HANDLE_FILE_INFORMATION.
+ * 2. set st_nlink by nNumberOfLinks of BY_HANDLE_FILE_INFORMATION.
+ * 3. set st_dev by dwVolumeSerialNumber by BY_HANDLE_FILE_INFORMATION.
+ */
+static int
+__hstat(HANDLE handle, struct ustat *st)
+{
+ BY_HANDLE_FILE_INFORMATION info;
+ ULARGE_INTEGER ino64;
+ DWORD ftype;
+ mode_t mode;
+ time_t t;
+ long ns;
+
+ switch (ftype = GetFileType(handle)) {
+ case FILE_TYPE_UNKNOWN:
+ errno = EBADF;
+ return (-1);
+ case FILE_TYPE_CHAR:
+ case FILE_TYPE_PIPE:
+ if (ftype == FILE_TYPE_CHAR) {
+ st->st_mode = S_IFCHR;
+ st->st_size = 0;
+ } else {
+ DWORD avail;
+
+ st->st_mode = S_IFIFO;
+ if (PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL))
+ st->st_size = avail;
+ else
+ st->st_size = 0;
+ }
+ st->st_atime = 0;
+ st->st_atime_nsec = 0;
+ st->st_mtime = 0;
+ st->st_mtime_nsec = 0;
+ st->st_ctime = 0;
+ st->st_ctime_nsec = 0;
+ st->st_ino = 0;
+ st->st_nlink = 1;
+ st->st_uid = 0;
+ st->st_gid = 0;
+ st->st_rdev = 0;
+ st->st_dev = 0;
+ return (0);
+ case FILE_TYPE_DISK:
+ break;
+ default:
+ /* This ftype is undocumented type. */
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+
+ ZeroMemory(&info, sizeof(info));
+ if (!GetFileInformationByHandle (handle, &info)) {
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+
+ mode = S_IRUSR | S_IRGRP | S_IROTH;
+ if ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0)
+ mode |= S_IWUSR | S_IWGRP | S_IWOTH;
+ if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
+ else
+ mode |= S_IFREG;
+ st->st_mode = mode;
+
+ fileTimeToUTC(&info.ftLastAccessTime, &t, &ns);
+ st->st_atime = t;
+ st->st_atime_nsec = ns;
+ fileTimeToUTC(&info.ftLastWriteTime, &t, &ns);
+ st->st_mtime = t;
+ st->st_mtime_nsec = ns;
+ fileTimeToUTC(&info.ftCreationTime, &t, &ns);
+ st->st_ctime = t;
+ st->st_ctime_nsec = ns;
+ st->st_size =
+ ((int64_t)(info.nFileSizeHigh) * ((int64_t)MAXDWORD + 1))
+ + (int64_t)(info.nFileSizeLow);
+#ifdef SIMULATE_WIN_STAT
+ st->st_ino = 0;
+ st->st_nlink = 1;
+ st->st_dev = 0;
+#else
+ /* Getting FileIndex as i-node. We should remove a sequence which
+ * is high-16-bits of nFileIndexHigh. */
+ ino64.HighPart = info.nFileIndexHigh & 0x0000FFFFUL;
+ ino64.LowPart = info.nFileIndexLow;
+ st->st_ino = ino64.QuadPart;
+ st->st_nlink = info.nNumberOfLinks;
+ if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ ++st->st_nlink;/* Add parent directory. */
+ st->st_dev = info.dwVolumeSerialNumber;
+#endif
+ st->st_uid = 0;
+ st->st_gid = 0;
+ st->st_rdev = 0;
+ return (0);
+}
+
+static void
+copy_stat(struct stat *st, struct ustat *us)
+{
+ st->st_atime = us->st_atime;
+ st->st_ctime = us->st_ctime;
+ st->st_mtime = us->st_mtime;
+ st->st_gid = us->st_gid;
+ st->st_ino = getino(us);
+ st->st_mode = us->st_mode;
+ st->st_nlink = us->st_nlink;
+ st->st_size = (off_t)us->st_size;
+ st->st_uid = us->st_uid;
+ st->st_dev = us->st_dev;
+ st->st_rdev = us->st_rdev;
+}
+
+/*
+ * TODO: Remove a use of __la_fstat and __la_stat.
+ * We should use GetFileInformationByHandle in place
+ * where We still use the *stat functions.
+ */
+int
+__la_fstat(int fd, struct stat *st)
+{
+ struct ustat u;
+ int ret;
+
+ if (fd < 0) {
+ errno = EBADF;
+ return (-1);
+ }
+ ret = __hstat((HANDLE)_get_osfhandle(fd), &u);
+ if (ret >= 0) {
+ copy_stat(st, &u);
+ if (u.st_mode & (S_IFCHR | S_IFIFO)) {
+ st->st_dev = fd;
+ st->st_rdev = fd;
+ }
+ }
+ return (ret);
+}
+
+/* This can exceed MAX_PATH limitation. */
+int
+__la_stat(const char *path, struct stat *st)
+{
+ HANDLE handle;
+ struct ustat u;
+ int ret;
+
+ handle = la_CreateFile(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS,
+ NULL);
+ if (handle == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+ ret = __hstat(handle, &u);
+ CloseHandle(handle);
+ if (ret >= 0) {
+ char *p;
+
+ copy_stat(st, &u);
+ p = strrchr(path, '.');
+ if (p != NULL && strlen(p) == 4) {
+ char exttype[4];
+
+ ++ p;
+ exttype[0] = toupper(*p++);
+ exttype[1] = toupper(*p++);
+ exttype[2] = toupper(*p++);
+ exttype[3] = '\0';
+ if (!strcmp(exttype, "EXE") || !strcmp(exttype, "CMD") ||
+ !strcmp(exttype, "BAT") || !strcmp(exttype, "COM"))
+ st->st_mode |= S_IXUSR | S_IXGRP | S_IXOTH;
+ }
+ }
+ return (ret);
+}
+
+/*
+ * This waitpid is limited implementation.
+ */
+pid_t
+__la_waitpid(HANDLE child, int *status, int option)
+{
+ DWORD cs;
+
+ (void)option;/* UNUSED */
+ do {
+ if (GetExitCodeProcess(child, &cs) == 0) {
+ CloseHandle(child);
+ la_dosmaperr(GetLastError());
+ *status = 0;
+ return (-1);
+ }
+ } while (cs == STILL_ACTIVE);
+
+ *status = (int)(cs & 0xff);
+ return (0);
+}
+
+ssize_t
+__la_write(int fd, const void *buf, size_t nbytes)
+{
+ DWORD bytes_written;
+
+#ifdef _WIN64
+ if (nbytes > UINT32_MAX)
+ nbytes = UINT32_MAX;
+#endif
+ if (fd < 0) {
+ errno = EBADF;
+ return (-1);
+ }
+ if (!WriteFile((HANDLE)_get_osfhandle(fd), buf, (uint32_t)nbytes,
+ &bytes_written, NULL)) {
+ DWORD lasterr;
+
+ lasterr = GetLastError();
+ if (lasterr == ERROR_ACCESS_DENIED)
+ errno = EBADF;
+ else
+ la_dosmaperr(lasterr);
+ return (-1);
+ }
+ return (bytes_written);
+}
+
+/*
+ * Replace the Windows path separator '\' with '/'.
+ */
+static int
+replace_pathseparator(struct archive_wstring *ws, const wchar_t *wp)
+{
+ wchar_t *w;
+ size_t path_length;
+
+ if (wp == NULL)
+ return(0);
+ if (wcschr(wp, L'\\') == NULL)
+ return(0);
+ path_length = wcslen(wp);
+ if (archive_wstring_ensure(ws, path_length) == NULL)
+ return(-1);
+ archive_wstrncpy(ws, wp, path_length);
+ for (w = ws->s; *w; w++) {
+ if (*w == L'\\')
+ *w = L'/';
+ }
+ return(1);
+}
+
+static int
+fix_pathseparator(struct archive_entry *entry)
+{
+ struct archive_wstring ws;
+ const wchar_t *wp;
+ int ret = ARCHIVE_OK;
+
+ archive_string_init(&ws);
+ wp = archive_entry_pathname_w(entry);
+ switch (replace_pathseparator(&ws, wp)) {
+ case 0: /* Not replaced. */
+ break;
+ case 1: /* Replaced. */
+ archive_entry_copy_pathname_w(entry, ws.s);
+ break;
+ default:
+ ret = ARCHIVE_FAILED;
+ }
+ wp = archive_entry_hardlink_w(entry);
+ switch (replace_pathseparator(&ws, wp)) {
+ case 0: /* Not replaced. */
+ break;
+ case 1: /* Replaced. */
+ archive_entry_copy_hardlink_w(entry, ws.s);
+ break;
+ default:
+ ret = ARCHIVE_FAILED;
+ }
+ wp = archive_entry_symlink_w(entry);
+ switch (replace_pathseparator(&ws, wp)) {
+ case 0: /* Not replaced. */
+ break;
+ case 1: /* Replaced. */
+ archive_entry_copy_symlink_w(entry, ws.s);
+ break;
+ default:
+ ret = ARCHIVE_FAILED;
+ }
+ archive_wstring_free(&ws);
+ return(ret);
+}
+
+struct archive_entry *
+__la_win_entry_in_posix_pathseparator(struct archive_entry *entry)
+{
+ struct archive_entry *entry_main;
+ const wchar_t *wp;
+ int has_backslash = 0;
+ int ret;
+
+ wp = archive_entry_pathname_w(entry);
+ if (wp != NULL && wcschr(wp, L'\\') != NULL)
+ has_backslash = 1;
+ if (!has_backslash) {
+ wp = archive_entry_hardlink_w(entry);
+ if (wp != NULL && wcschr(wp, L'\\') != NULL)
+ has_backslash = 1;
+ }
+ if (!has_backslash) {
+ wp = archive_entry_symlink_w(entry);
+ if (wp != NULL && wcschr(wp, L'\\') != NULL)
+ has_backslash = 1;
+ }
+ /*
+ * If there is no backslach chars, return the original.
+ */
+ if (!has_backslash)
+ return (entry);
+
+ /* Copy entry so we can modify it as needed. */
+ entry_main = archive_entry_clone(entry);
+ if (entry_main == NULL)
+ return (NULL);
+ /* Replace the Windows path-separator '\' with '/'. */
+ ret = fix_pathseparator(entry_main);
+ if (ret < ARCHIVE_WARN) {
+ archive_entry_free(entry_main);
+ return (NULL);
+ }
+ return (entry_main);
+}
+
+
+/*
+ * The following function was modified from PostgreSQL sources and is
+ * subject to the copyright below.
+ */
+/*-------------------------------------------------------------------------
+ *
+ * win32error.c
+ * Map win32 error codes to errno values
+ *
+ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+/*
+PostgreSQL Database Management System
+(formerly known as Postgres, then as Postgres95)
+
+Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+
+Portions Copyright (c) 1994, The Regents of the University of California
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose, without fee, and without a written agreement
+is hereby granted, provided that the above copyright notice and this
+paragraph and the following two paragraphs appear in all copies.
+
+IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
+LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
+DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
+PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+*/
+
+static const struct {
+ DWORD winerr;
+ int doserr;
+} doserrors[] =
+{
+ { ERROR_INVALID_FUNCTION, EINVAL },
+ { ERROR_FILE_NOT_FOUND, ENOENT },
+ { ERROR_PATH_NOT_FOUND, ENOENT },
+ { ERROR_TOO_MANY_OPEN_FILES, EMFILE },
+ { ERROR_ACCESS_DENIED, EACCES },
+ { ERROR_INVALID_HANDLE, EBADF },
+ { ERROR_ARENA_TRASHED, ENOMEM },
+ { ERROR_NOT_ENOUGH_MEMORY, ENOMEM },
+ { ERROR_INVALID_BLOCK, ENOMEM },
+ { ERROR_BAD_ENVIRONMENT, E2BIG },
+ { ERROR_BAD_FORMAT, ENOEXEC },
+ { ERROR_INVALID_ACCESS, EINVAL },
+ { ERROR_INVALID_DATA, EINVAL },
+ { ERROR_INVALID_DRIVE, ENOENT },
+ { ERROR_CURRENT_DIRECTORY, EACCES },
+ { ERROR_NOT_SAME_DEVICE, EXDEV },
+ { ERROR_NO_MORE_FILES, ENOENT },
+ { ERROR_LOCK_VIOLATION, EACCES },
+ { ERROR_SHARING_VIOLATION, EACCES },
+ { ERROR_BAD_NETPATH, ENOENT },
+ { ERROR_NETWORK_ACCESS_DENIED, EACCES },
+ { ERROR_BAD_NET_NAME, ENOENT },
+ { ERROR_FILE_EXISTS, EEXIST },
+ { ERROR_CANNOT_MAKE, EACCES },
+ { ERROR_FAIL_I24, EACCES },
+ { ERROR_INVALID_PARAMETER, EINVAL },
+ { ERROR_NO_PROC_SLOTS, EAGAIN },
+ { ERROR_DRIVE_LOCKED, EACCES },
+ { ERROR_BROKEN_PIPE, EPIPE },
+ { ERROR_DISK_FULL, ENOSPC },
+ { ERROR_INVALID_TARGET_HANDLE, EBADF },
+ { ERROR_INVALID_HANDLE, EINVAL },
+ { ERROR_WAIT_NO_CHILDREN, ECHILD },
+ { ERROR_CHILD_NOT_COMPLETE, ECHILD },
+ { ERROR_DIRECT_ACCESS_HANDLE, EBADF },
+ { ERROR_NEGATIVE_SEEK, EINVAL },
+ { ERROR_SEEK_ON_DEVICE, EACCES },
+ { ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
+ { ERROR_NOT_LOCKED, EACCES },
+ { ERROR_BAD_PATHNAME, ENOENT },
+ { ERROR_MAX_THRDS_REACHED, EAGAIN },
+ { ERROR_LOCK_FAILED, EACCES },
+ { ERROR_ALREADY_EXISTS, EEXIST },
+ { ERROR_FILENAME_EXCED_RANGE, ENOENT },
+ { ERROR_NESTING_NOT_ALLOWED, EAGAIN },
+ { ERROR_NOT_ENOUGH_QUOTA, ENOMEM }
+};
+
+void
+__la_dosmaperr(unsigned long e)
+{
+ int i;
+
+ if (e == 0)
+ {
+ errno = 0;
+ return;
+ }
+
+ for (i = 0; i < (int)sizeof(doserrors); i++)
+ {
+ if (doserrors[i].winerr == e)
+ {
+ errno = doserrors[i].doserr;
+ return;
+ }
+ }
+
+ /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */
+ errno = EINVAL;
+ return;
+}
+
+#endif /* _WIN32 && !__CYGWIN__ */
diff --git a/Utilities/cmlibarchive/libarchive/archive_windows.h b/Utilities/cmlibarchive/libarchive/archive_windows.h
new file mode 100644
index 0000000000..dc2f24139c
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_windows.h
@@ -0,0 +1,318 @@
+/*-
+ * Copyright (c) 2009-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2003-2006 Tim Kientzle
+ * 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
+ * in this position and unchanged.
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+/*
+ * TODO: A lot of stuff in here isn't actually used by libarchive and
+ * can be trimmed out. Note that this file is used by libarchive and
+ * libarchive_test but nowhere else. (But note that it gets compiled
+ * with many different Windows environments, including MinGW, Visual
+ * Studio, and Cygwin. Significant changes should be tested in all three.)
+ */
+
+/*
+ * TODO: Don't use off_t in here. Use __int64 instead. Note that
+ * Visual Studio and the Windows SDK define off_t as 32 bits; Win32's
+ * more modern file handling APIs all use __int64 instead of off_t.
+ */
+
+#ifndef LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED
+#define LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED
+
+/* Start of configuration for native Win32 */
+#ifndef MINGW_HAS_SECURE_API
+#define MINGW_HAS_SECURE_API 1
+#endif
+
+#include <errno.h>
+#define set_errno(val) ((errno)=val)
+#include <io.h>
+#include <stdlib.h> //brings in NULL
+#if defined(HAVE_STDINT_H)
+#include <stdint.h>
+#endif
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <process.h>
+#include <direct.h>
+#if defined(__MINGW32__) && defined(HAVE_UNISTD_H)
+/* Prevent build error from a type mismatch of ftruncate().
+ * This unistd.h defines it as ftruncate(int, off_t). */
+#include <unistd.h>
+#endif
+#define NOCRYPT
+#include <windows.h>
+//#define EFTYPE 7
+
+#if defined(_MSC_VER)
+#pragma warning(push,1)
+#pragma warning(disable:4142) /* benign redefinition of type */
+#pragma warning(disable:4761) /* integral size mismatch in argument; conversion supplied */
+#endif
+#if defined(__BORLANDC__)
+#pragma warn -8068 /* Constant out of range in comparison. */
+#pragma warn -8072 /* Suspicious pointer arithmetic. */
+#endif
+
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else
+#define NULL ((void *)0)
+#endif
+#endif
+
+/* Alias the Windows _function to the POSIX equivalent. */
+#define close _close
+#define fcntl(fd, cmd, flg) /* No operation. */
+#ifndef fileno
+#define fileno _fileno
+#endif
+#ifdef fstat
+#undef fstat
+#endif
+#define fstat __la_fstat
+#if !defined(__BORLANDC__)
+#ifdef lseek
+#undef lseek
+#endif
+#define lseek _lseeki64
+#else
+#define lseek __la_lseek
+#define __LA_LSEEK_NEEDED
+#endif
+#define lstat __la_stat
+#define open __la_open
+#define read __la_read
+#if !defined(__BORLANDC__) && !defined(__WATCOMC__)
+#define setmode _setmode
+#endif
+#ifdef stat
+#undef stat
+#endif
+#define stat(path,stref) __la_stat(path,stref)
+#if !defined(__WATCOMC__)
+#if !defined(__BORLANDC__)
+#define strdup _strdup
+#endif
+#define tzset _tzset
+#if !defined(__BORLANDC__)
+#define umask _umask
+#endif
+#endif
+#define waitpid __la_waitpid
+#define write __la_write
+
+#if !defined(__WATCOMC__)
+
+#ifndef O_RDONLY
+#define O_RDONLY _O_RDONLY
+#define O_WRONLY _O_WRONLY
+#define O_TRUNC _O_TRUNC
+#define O_CREAT _O_CREAT
+#define O_EXCL _O_EXCL
+#define O_BINARY _O_BINARY
+#endif
+
+#ifndef _S_IFIFO
+ #define _S_IFIFO 0010000 /* pipe */
+#endif
+#ifndef _S_IFCHR
+ #define _S_IFCHR 0020000 /* character special */
+#endif
+#ifndef _S_IFDIR
+ #define _S_IFDIR 0040000 /* directory */
+#endif
+#ifndef _S_IFBLK
+ #define _S_IFBLK 0060000 /* block special */
+#endif
+#ifndef _S_IFLNK
+ #define _S_IFLNK 0120000 /* symbolic link */
+#endif
+#ifndef _S_IFSOCK
+ #define _S_IFSOCK 0140000 /* socket */
+#endif
+#ifndef _S_IFREG
+ #define _S_IFREG 0100000 /* regular */
+#endif
+#ifndef _S_IFMT
+ #define _S_IFMT 0170000 /* file type mask */
+#endif
+
+#ifndef S_IFIFO
+#define S_IFIFO _S_IFIFO
+#endif
+//#define S_IFCHR _S_IFCHR
+//#define S_IFDIR _S_IFDIR
+#ifndef S_IFBLK
+#define S_IFBLK _S_IFBLK
+#endif
+#ifndef S_IFLNK
+#define S_IFLNK _S_IFLNK
+#endif
+#ifndef S_IFSOCK
+#define S_IFSOCK _S_IFSOCK
+#endif
+//#define S_IFREG _S_IFREG
+//#define S_IFMT _S_IFMT
+
+#ifndef S_ISBLK
+#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) /* block special */
+#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) /* fifo or socket */
+#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) /* char special */
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) /* directory */
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) /* regular file */
+#endif
+
+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) /* Symbolic link */
+#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) /* Socket */
+
+#define _S_ISUID 0004000 /* set user id on execution */
+#define _S_ISGID 0002000 /* set group id on execution */
+#define _S_ISVTX 0001000 /* save swapped text even after use */
+
+#define S_ISUID _S_ISUID
+#define S_ISGID _S_ISGID
+#define S_ISVTX _S_ISVTX
+
+#define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
+#define _S_IXUSR _S_IEXEC /* read permission, user */
+#define _S_IWUSR _S_IWRITE /* write permission, user */
+#define _S_IRUSR _S_IREAD /* execute/search permission, user */
+#define _S_IRWXG (_S_IRWXU >> 3)
+#define _S_IXGRP (_S_IXUSR >> 3) /* read permission, group */
+#define _S_IWGRP (_S_IWUSR >> 3) /* write permission, group */
+#define _S_IRGRP (_S_IRUSR >> 3) /* execute/search permission, group */
+#define _S_IRWXO (_S_IRWXG >> 3)
+#define _S_IXOTH (_S_IXGRP >> 3) /* read permission, other */
+#define _S_IWOTH (_S_IWGRP >> 3) /* write permission, other */
+#define _S_IROTH (_S_IRGRP >> 3) /* execute/search permission, other */
+
+#ifndef S_IRWXU
+#define S_IRWXU _S_IRWXU
+#define S_IXUSR _S_IXUSR
+#define S_IWUSR _S_IWUSR
+#define S_IRUSR _S_IRUSR
+#endif
+#define S_IRWXG _S_IRWXG
+#define S_IXGRP _S_IXGRP
+#define S_IWGRP _S_IWGRP
+#define S_IRGRP _S_IRGRP
+#define S_IRWXO _S_IRWXO
+#define S_IXOTH _S_IXOTH
+#define S_IWOTH _S_IWOTH
+#define S_IROTH _S_IROTH
+
+#endif
+
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#define F_GETOWN 5 /* Get owner (receiver of SIGIO). */
+#define F_SETOWN 6 /* Set owner (receiver of SIGIO). */
+#define F_GETLK 7 /* Get record locking info. */
+#define F_SETLK 8 /* Set record locking info (non-blocking). */
+#define F_SETLKW 9 /* Set record locking info (blocking). */
+
+/* XXX missing */
+#define F_GETLK64 7 /* Get record locking info. */
+#define F_SETLK64 8 /* Set record locking info (non-blocking). */
+#define F_SETLKW64 9 /* Set record locking info (blocking). */
+
+/* File descriptor flags used with F_GETFD and F_SETFD. */
+#define FD_CLOEXEC 1 /* Close on exec. */
+
+//NOT SURE IF O_NONBLOCK is OK here but at least the 0x0004 flag is not used by anything else...
+#define O_NONBLOCK 0x0004 /* Non-blocking I/O. */
+//#define O_NDELAY O_NONBLOCK
+
+/* Symbolic constants for the access() function */
+#if !defined(F_OK)
+ #define R_OK 4 /* Test for read permission */
+ #define W_OK 2 /* Test for write permission */
+ #define X_OK 1 /* Test for execute permission */
+ #define F_OK 0 /* Test for existence of file */
+#endif
+
+
+/* Replacement POSIX function */
+extern int __la_fstat(int fd, struct stat *st);
+extern int __la_lstat(const char *path, struct stat *st);
+#if defined(__LA_LSEEK_NEEDED)
+extern __int64 __la_lseek(int fd, __int64 offset, int whence);
+#endif
+extern int __la_open(const char *path, int flags, ...);
+extern ssize_t __la_read(int fd, void *buf, size_t nbytes);
+extern int __la_stat(const char *path, struct stat *st);
+extern pid_t __la_waitpid(HANDLE child, int *status, int option);
+extern ssize_t __la_write(int fd, const void *buf, size_t nbytes);
+
+#define _stat64i32(path, st) __la_stat(path, st)
+#define _stat64(path, st) __la_stat(path, st)
+/* for status returned by la_waitpid */
+#define WIFEXITED(sts) ((sts & 0x100) == 0)
+#define WEXITSTATUS(sts) (sts & 0x0FF)
+
+extern wchar_t *__la_win_permissive_name(const char *name);
+extern wchar_t *__la_win_permissive_name_w(const wchar_t *wname);
+extern void __la_dosmaperr(unsigned long e);
+#define la_dosmaperr(e) __la_dosmaperr(e)
+extern struct archive_entry *__la_win_entry_in_posix_pathseparator(
+ struct archive_entry *);
+
+#if defined(HAVE_WCRTOMB) && defined(__BORLANDC__)
+typedef int mbstate_t;
+size_t wcrtomb(char *, wchar_t, mbstate_t *);
+#endif
+
+#if defined(_MSC_VER) && _MSC_VER < 1300
+WINBASEAPI BOOL WINAPI GetVolumePathNameW(
+ LPCWSTR lpszFileName,
+ LPWSTR lpszVolumePathName,
+ DWORD cchBufferLength
+ );
+# if _WIN32_WINNT < 0x0500 /* windows.h not providing 0x500 API */
+typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
+ LARGE_INTEGER FileOffset;
+ LARGE_INTEGER Length;
+} FILE_ALLOCATED_RANGE_BUFFER, *PFILE_ALLOCATED_RANGE_BUFFER;
+# define FSCTL_SET_SPARSE \
+ CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, METHOD_BUFFERED, FILE_WRITE_DATA)
+# define FSCTL_QUERY_ALLOCATED_RANGES \
+ CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 51, METHOD_NEITHER, FILE_READ_DATA)
+# endif
+#endif
+
+#endif /* LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_write.3 b/Utilities/cmlibarchive/libarchive/archive_write.3
new file mode 100644
index 0000000000..228bc2cb88
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write.3
@@ -0,0 +1,263 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE 3
+.Os
+.Sh NAME
+.Nm archive_write
+.Nd functions for creating archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Sh DESCRIPTION
+These functions provide a complete API for creating streaming
+archive files.
+The general process is to first create the
+.Tn struct archive
+object, set any desired options, initialize the archive, append entries, then
+close the archive and release all resources.
+.\"
+.Ss Create archive object
+See
+.Xr archive_write_new 3 .
+.Pp
+To write an archive, you must first obtain an initialized
+.Tn struct archive
+object from
+.Fn archive_write_new .
+.\"
+.Ss Enable filters and formats, configure block size and padding
+See
+.Xr archive_write_filter 3 ,
+.Xr archive_write_format 3
+and
+.Xr archive_write_blocksize 3 .
+.Pp
+You can then modify this object for the desired operations with the
+various
+.Fn archive_write_set_XXX
+functions.
+In particular, you will need to invoke appropriate
+.Fn archive_write_add_XXX
+and
+.Fn archive_write_set_XXX
+functions to enable the corresponding compression and format
+support.
+.\"
+.Ss Set options
+See
+.Xr archive_read_set_options 3 .
+.\"
+.Ss Open archive
+See
+.Xr archive_write_open 3 .
+.Pp
+Once you have prepared the
+.Tn struct archive
+object, you call
+.Fn archive_write_open
+to actually open the archive and prepare it for writing.
+There are several variants of this function;
+the most basic expects you to provide pointers to several
+functions that can provide blocks of bytes from the archive.
+There are convenience forms that allow you to
+specify a filename, file descriptor,
+.Ft "FILE *"
+object, or a block of memory from which to write the archive data.
+.\"
+.Ss Produce archive
+See
+.Xr archive_write_header 3
+and
+.Xr archive_write_data 3 .
+.Pp
+Individual archive entries are written in a three-step
+process:
+You first initialize a
+.Tn struct archive_entry
+structure with information about the new entry.
+At a minimum, you should set the pathname of the
+entry and provide a
+.Va struct stat
+with a valid
+.Va st_mode
+field, which specifies the type of object and
+.Va st_size
+field, which specifies the size of the data portion of the object.
+.\"
+.Ss Release resources
+See
+.Xr archive_write_free 3 .
+.Pp
+After all entries have been written, use the
+.Fn archive_write_free
+function to release all resources.
+.\"
+.Sh EXAMPLE
+The following sketch illustrates basic usage of the library.
+In this example,
+the callback functions are simply wrappers around the standard
+.Xr open 2 ,
+.Xr write 2 ,
+and
+.Xr close 2
+system calls.
+.Bd -literal -offset indent
+#ifdef __linux__
+#define _FILE_OFFSET_BITS 64
+#endif
+#include <sys/stat.h>
+#include <archive.h>
+#include <archive_entry.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+struct mydata {
+ const char *name;
+ int fd;
+};
+
+int
+myopen(struct archive *a, void *client_data)
+{
+ struct mydata *mydata = client_data;
+
+ mydata->fd = open(mydata->name, O_WRONLY | O_CREAT, 0644);
+ if (mydata->fd >= 0)
+ return (ARCHIVE_OK);
+ else
+ return (ARCHIVE_FATAL);
+}
+
+ssize_t
+mywrite(struct archive *a, void *client_data, const void *buff, size_t n)
+{
+ struct mydata *mydata = client_data;
+
+ return (write(mydata->fd, buff, n));
+}
+
+int
+myclose(struct archive *a, void *client_data)
+{
+ struct mydata *mydata = client_data;
+
+ if (mydata->fd > 0)
+ close(mydata->fd);
+ return (0);
+}
+
+void
+write_archive(const char *outname, const char **filename)
+{
+ struct mydata *mydata = malloc(sizeof(struct mydata));
+ struct archive *a;
+ struct archive_entry *entry;
+ struct stat st;
+ char buff[8192];
+ int len;
+ int fd;
+
+ a = archive_write_new();
+ mydata->name = outname;
+ 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);
+ entry = archive_entry_new();
+ archive_entry_copy_stat(entry, &st);
+ archive_entry_set_pathname(entry, *filename);
+ archive_write_header(a, entry);
+ if ((fd = open(*filename, O_RDONLY)) != -1) {
+ len = read(fd, buff, sizeof(buff));
+ while ( len > 0 ) {
+ archive_write_data(a, buff, len);
+ len = read(fd, buff, sizeof(buff));
+ }
+ close(fd);
+ }
+ archive_entry_free(entry);
+ filename++;
+ }
+ archive_write_free(a);
+}
+
+int main(int argc, const char **argv)
+{
+ const char *outname;
+ argv++;
+ outname = argv++;
+ write_archive(outname, argv);
+ return 0;
+}
+.Ed
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libarchive
+library was written by
+.An Tim Kientzle Aq kientzle@acm.org .
+.Sh BUGS
+There are many peculiar bugs in historic tar implementations that may cause
+certain programs to reject archives written by this library.
+For example, several historic implementations calculated header checksums
+incorrectly and will thus reject valid archives; GNU tar does not fully support
+pax interchange format; some old tar implementations required specific
+field terminations.
+.Pp
+The default pax interchange format eliminates most of the historic
+tar limitations and provides a generic key/value attribute facility
+for vendor-defined extensions.
+One oversight in POSIX is the failure to provide a standard attribute
+for large device numbers.
+This library uses
+.Dq SCHILY.devminor
+and
+.Dq SCHILY.devmajor
+for device numbers that exceed the range supported by the backwards-compatible
+ustar header.
+These keys are compatible with Joerg Schilling's
+.Nm star
+archiver.
+Other implementations may not recognize these keys and will thus be unable
+to correctly restore device nodes with large device numbers from archives
+created by this library.
diff --git a/Utilities/cmlibarchive/libarchive/archive_write.c b/Utilities/cmlibarchive/libarchive/archive_write.c
new file mode 100644
index 0000000000..8997193145
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write.c
@@ -0,0 +1,725 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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.c 201099 2009-12-28 03:03:00Z kientzle $");
+
+/*
+ * This file contains the "essential" portions of the write API, that
+ * is, stuff that will essentially always be used by any client that
+ * actually needs to write an archive. Optional pieces have been, as
+ * far as possible, separated out into separate files to reduce
+ * needlessly bloating statically-linked clients.
+ */
+
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <time.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+static struct archive_vtable *archive_write_vtable(void);
+
+static int _archive_filter_code(struct archive *, int);
+static const char *_archive_filter_name(struct archive *, int);
+static int64_t _archive_filter_bytes(struct archive *, int);
+static int _archive_write_filter_count(struct archive *);
+static int _archive_write_close(struct archive *);
+static int _archive_write_free(struct archive *);
+static int _archive_write_header(struct archive *, struct archive_entry *);
+static int _archive_write_finish_entry(struct archive *);
+static ssize_t _archive_write_data(struct archive *, const void *, size_t);
+
+struct archive_none {
+ size_t buffer_size;
+ size_t avail;
+ char *buffer;
+ char *next;
+};
+
+static struct archive_vtable *
+archive_write_vtable(void)
+{
+ static struct archive_vtable av;
+ static int inited = 0;
+
+ if (!inited) {
+ av.archive_close = _archive_write_close;
+ av.archive_filter_bytes = _archive_filter_bytes;
+ av.archive_filter_code = _archive_filter_code;
+ av.archive_filter_name = _archive_filter_name;
+ av.archive_filter_count = _archive_write_filter_count;
+ av.archive_free = _archive_write_free;
+ av.archive_write_header = _archive_write_header;
+ av.archive_write_finish_entry = _archive_write_finish_entry;
+ av.archive_write_data = _archive_write_data;
+ inited = 1;
+ }
+ return (&av);
+}
+
+/*
+ * Allocate, initialize and return an archive object.
+ */
+struct archive *
+archive_write_new(void)
+{
+ struct archive_write *a;
+ unsigned char *nulls;
+
+ a = (struct archive_write *)malloc(sizeof(*a));
+ if (a == NULL)
+ return (NULL);
+ memset(a, 0, sizeof(*a));
+ a->archive.magic = ARCHIVE_WRITE_MAGIC;
+ a->archive.state = ARCHIVE_STATE_NEW;
+ a->archive.vtable = archive_write_vtable();
+ /*
+ * The value 10240 here matches the traditional tar default,
+ * but is otherwise arbitrary.
+ * TODO: Set the default block size from the format selected.
+ */
+ a->bytes_per_block = 10240;
+ a->bytes_in_last_block = -1; /* Default */
+
+ /* Initialize a block of nulls for padding purposes. */
+ a->null_length = 1024;
+ nulls = (unsigned char *)malloc(a->null_length);
+ if (nulls == NULL) {
+ free(a);
+ return (NULL);
+ }
+ memset(nulls, 0, a->null_length);
+ a->nulls = nulls;
+ return (&a->archive);
+}
+
+/*
+ * Set the block size. Returns 0 if successful.
+ */
+int
+archive_write_set_bytes_per_block(struct archive *_a, int bytes_per_block)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_bytes_per_block");
+ a->bytes_per_block = bytes_per_block;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Get the current block size. -1 if it has never been set.
+ */
+int
+archive_write_get_bytes_per_block(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_get_bytes_per_block");
+ return (a->bytes_per_block);
+}
+
+/*
+ * Set the size for the last block.
+ * Returns 0 if successful.
+ */
+int
+archive_write_set_bytes_in_last_block(struct archive *_a, int bytes)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_set_bytes_in_last_block");
+ a->bytes_in_last_block = bytes;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Return the value set above. -1 indicates it has not been set.
+ */
+int
+archive_write_get_bytes_in_last_block(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_get_bytes_in_last_block");
+ return (a->bytes_in_last_block);
+}
+
+/*
+ * dev/ino of a file to be rejected. Used to prevent adding
+ * an archive to itself recursively.
+ */
+int
+archive_write_set_skip_file(struct archive *_a, int64_t d, int64_t i)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_set_skip_file");
+ a->skip_file_set = 1;
+ a->skip_file_dev = d;
+ a->skip_file_ino = i;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Allocate and return the next filter structure.
+ */
+struct archive_write_filter *
+__archive_write_allocate_filter(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct archive_write_filter *f;
+
+ f = calloc(1, sizeof(*f));
+ f->archive = _a;
+ if (a->filter_first == NULL)
+ a->filter_first = f;
+ else
+ a->filter_last->next_filter = f;
+ a->filter_last = f;
+ return f;
+}
+
+/*
+ * Write data to a particular filter.
+ */
+int
+__archive_write_filter(struct archive_write_filter *f,
+ const void *buff, size_t length)
+{
+ int r;
+ if (length == 0)
+ return(ARCHIVE_OK);
+ if (f->write == NULL)
+ /* If unset, a fatal error has already ocuured, so this filter
+ * didn't open. We cannot write anything. */
+ return(ARCHIVE_FATAL);
+ r = (f->write)(f, buff, length);
+ f->bytes_written += length;
+ return (r);
+}
+
+/*
+ * Open a filter.
+ */
+int
+__archive_write_open_filter(struct archive_write_filter *f)
+{
+ if (f->open == NULL)
+ return (ARCHIVE_OK);
+ return (f->open)(f);
+}
+
+/*
+ * Close a filter.
+ */
+int
+__archive_write_close_filter(struct archive_write_filter *f)
+{
+ if (f->close != NULL)
+ return (f->close)(f);
+ if (f->next_filter != NULL)
+ return (__archive_write_close_filter(f->next_filter));
+ return (ARCHIVE_OK);
+}
+
+int
+__archive_write_output(struct archive_write *a, const void *buff, size_t length)
+{
+ return (__archive_write_filter(a->filter_first, buff, length));
+}
+
+int
+__archive_write_nulls(struct archive_write *a, size_t length)
+{
+ if (length == 0)
+ return (ARCHIVE_OK);
+
+ while (length > 0) {
+ size_t to_write = length < a->null_length ? length : a->null_length;
+ int r = __archive_write_output(a, a->nulls, to_write);
+ if (r < ARCHIVE_OK)
+ return (r);
+ length -= to_write;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_client_open(struct archive_write_filter *f)
+{
+ struct archive_write *a = (struct archive_write *)f->archive;
+ struct archive_none *state;
+ void *buffer;
+ size_t buffer_size;
+
+ f->bytes_per_block = archive_write_get_bytes_per_block(f->archive);
+ f->bytes_in_last_block =
+ archive_write_get_bytes_in_last_block(f->archive);
+ buffer_size = f->bytes_per_block;
+
+ state = (struct archive_none *)calloc(1, sizeof(*state));
+ buffer = (char *)malloc(buffer_size);
+ if (state == NULL || buffer == NULL) {
+ free(state);
+ free(buffer);
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for output buffering");
+ return (ARCHIVE_FATAL);
+ }
+
+ state->buffer_size = buffer_size;
+ state->buffer = buffer;
+ state->next = state->buffer;
+ state->avail = state->buffer_size;
+ f->data = state;
+
+ if (a->client_opener == NULL)
+ return (ARCHIVE_OK);
+ return (a->client_opener(f->archive, a->client_data));
+}
+
+static int
+archive_write_client_write(struct archive_write_filter *f,
+ const void *_buff, size_t length)
+{
+ struct archive_write *a = (struct archive_write *)f->archive;
+ struct archive_none *state = (struct archive_none *)f->data;
+ const char *buff = (const char *)_buff;
+ ssize_t remaining, to_copy;
+ ssize_t bytes_written;
+
+ remaining = length;
+
+ /*
+ * If there is no buffer for blocking, just pass the data
+ * straight through to the client write callback. In
+ * particular, this supports "no write delay" operation for
+ * special applications. Just set the block size to zero.
+ */
+ if (state->buffer_size == 0) {
+ while (remaining > 0) {
+ bytes_written = (a->client_writer)(&a->archive,
+ a->client_data, buff, remaining);
+ if (bytes_written <= 0)
+ return (ARCHIVE_FATAL);
+ remaining -= bytes_written;
+ buff += bytes_written;
+ }
+ return (ARCHIVE_OK);
+ }
+
+ /* If the copy buffer isn't empty, try to fill it. */
+ if (state->avail < state->buffer_size) {
+ /* If buffer is not empty... */
+ /* ... copy data into buffer ... */
+ to_copy = ((size_t)remaining > state->avail) ?
+ state->avail : (size_t)remaining;
+ memcpy(state->next, buff, to_copy);
+ state->next += to_copy;
+ state->avail -= to_copy;
+ buff += to_copy;
+ remaining -= to_copy;
+ /* ... if it's full, write it out. */
+ if (state->avail == 0) {
+ char *p = state->buffer;
+ size_t to_write = state->buffer_size;
+ while (to_write > 0) {
+ bytes_written = (a->client_writer)(&a->archive,
+ a->client_data, p, to_write);
+ if (bytes_written <= 0)
+ return (ARCHIVE_FATAL);
+ if ((size_t)bytes_written > to_write) {
+ archive_set_error(&(a->archive),
+ -1, "write overrun");
+ return (ARCHIVE_FATAL);
+ }
+ p += bytes_written;
+ to_write -= bytes_written;
+ }
+ state->next = state->buffer;
+ state->avail = state->buffer_size;
+ }
+ }
+
+ while ((size_t)remaining >= state->buffer_size) {
+ /* Write out full blocks directly to client. */
+ bytes_written = (a->client_writer)(&a->archive,
+ a->client_data, buff, state->buffer_size);
+ if (bytes_written <= 0)
+ return (ARCHIVE_FATAL);
+ buff += bytes_written;
+ remaining -= bytes_written;
+ }
+
+ if (remaining > 0) {
+ /* Copy last bit into copy buffer. */
+ memcpy(state->next, buff, remaining);
+ state->next += remaining;
+ state->avail -= remaining;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_client_close(struct archive_write_filter *f)
+{
+ struct archive_write *a = (struct archive_write *)f->archive;
+ struct archive_none *state = (struct archive_none *)f->data;
+ ssize_t block_length;
+ ssize_t target_block_length;
+ ssize_t bytes_written;
+ int ret = ARCHIVE_OK;
+
+ /* If there's pending data, pad and write the last block */
+ if (state->next != state->buffer) {
+ block_length = state->buffer_size - state->avail;
+
+ /* Tricky calculation to determine size of last block */
+ if (a->bytes_in_last_block <= 0)
+ /* Default or Zero: pad to full block */
+ target_block_length = a->bytes_per_block;
+ else
+ /* Round to next multiple of bytes_in_last_block. */
+ target_block_length = a->bytes_in_last_block *
+ ( (block_length + a->bytes_in_last_block - 1) /
+ a->bytes_in_last_block);
+ if (target_block_length > a->bytes_per_block)
+ target_block_length = a->bytes_per_block;
+ if (block_length < target_block_length) {
+ memset(state->next, 0,
+ target_block_length - block_length);
+ block_length = target_block_length;
+ }
+ bytes_written = (a->client_writer)(&a->archive,
+ a->client_data, state->buffer, block_length);
+ ret = bytes_written <= 0 ? ARCHIVE_FATAL : ARCHIVE_OK;
+ }
+ if (a->client_closer)
+ (*a->client_closer)(&a->archive, a->client_data);
+ free(state->buffer);
+ free(state);
+ /* Clear the close handler myself not to be called again. */
+ f->close = NULL;
+ a->client_data = NULL;
+ return (ret);
+}
+
+/*
+ * Open the archive using the current settings.
+ */
+int
+archive_write_open(struct archive *_a, void *client_data,
+ archive_open_callback *opener, archive_write_callback *writer,
+ archive_close_callback *closer)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct archive_write_filter *client_filter;
+ int ret, r1;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_open");
+ archive_clear_error(&a->archive);
+
+ a->client_writer = writer;
+ a->client_opener = opener;
+ a->client_closer = closer;
+ a->client_data = client_data;
+
+ client_filter = __archive_write_allocate_filter(_a);
+ client_filter->open = archive_write_client_open;
+ client_filter->write = archive_write_client_write;
+ client_filter->close = archive_write_client_close;
+
+ ret = __archive_write_open_filter(a->filter_first);
+ if (ret < ARCHIVE_WARN) {
+ r1 = __archive_write_close_filter(a->filter_first);
+ return (r1 < ret ? r1 : ret);
+ }
+
+ a->archive.state = ARCHIVE_STATE_HEADER;
+ if (a->format_init)
+ ret = (a->format_init)(a);
+ return (ret);
+}
+
+/*
+ * Close out the archive.
+ */
+static int
+_archive_write_close(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ int r = ARCHIVE_OK, r1 = ARCHIVE_OK;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL,
+ "archive_write_close");
+ if (a->archive.state == ARCHIVE_STATE_NEW
+ || a->archive.state == ARCHIVE_STATE_CLOSED)
+ return (ARCHIVE_OK); /* Okay to close() when not open. */
+
+ archive_clear_error(&a->archive);
+
+ /* Finish the last entry if a finish callback is specified */
+ if (a->archive.state == ARCHIVE_STATE_DATA
+ && a->format_finish_entry != NULL)
+ r = ((a->format_finish_entry)(a));
+
+ /* Finish off the archive. */
+ /* TODO: have format closers invoke compression close. */
+ if (a->format_close != NULL) {
+ r1 = (a->format_close)(a);
+ if (r1 < r)
+ r = r1;
+ }
+
+ /* Finish the compression and close the stream. */
+ r1 = __archive_write_close_filter(a->filter_first);
+ if (r1 < r)
+ r = r1;
+
+ if (a->archive.state != ARCHIVE_STATE_FATAL)
+ a->archive.state = ARCHIVE_STATE_CLOSED;
+ return (r);
+}
+
+static int
+_archive_write_filter_count(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct archive_write_filter *p = a->filter_first;
+ int count = 0;
+ while(p) {
+ count++;
+ p = p->next_filter;
+ }
+ return count;
+}
+
+void
+__archive_write_filters_free(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ int r = ARCHIVE_OK, r1;
+
+ while (a->filter_first != NULL) {
+ struct archive_write_filter *next
+ = a->filter_first->next_filter;
+ if (a->filter_first->free != NULL) {
+ r1 = (*a->filter_first->free)(a->filter_first);
+ if (r > r1)
+ r = r1;
+ }
+ free(a->filter_first);
+ a->filter_first = next;
+ }
+ a->filter_last = NULL;
+}
+
+/*
+ * Destroy the archive structure.
+ *
+ * Be careful: user might just call write_new and then write_free.
+ * Don't assume we actually wrote anything or performed any non-trivial
+ * initialization.
+ */
+static int
+_archive_write_free(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ int r = ARCHIVE_OK, r1;
+
+ if (_a == NULL)
+ return (ARCHIVE_OK);
+ /* It is okay to call free() in state FATAL. */
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_write_free");
+ if (a->archive.state != ARCHIVE_STATE_FATAL)
+ r = archive_write_close(&a->archive);
+
+ /* Release format resources. */
+ if (a->format_free != NULL) {
+ r1 = (a->format_free)(a);
+ if (r1 < r)
+ r = r1;
+ }
+
+ __archive_write_filters_free(_a);
+
+ /* Release various dynamic buffers. */
+ free((void *)(uintptr_t)(const void *)a->nulls);
+ archive_string_free(&a->archive.error_string);
+ a->archive.magic = 0;
+ __archive_clean(&a->archive);
+ free(a);
+ return (r);
+}
+
+/*
+ * Write the appropriate header.
+ */
+static int
+_archive_write_header(struct archive *_a, struct archive_entry *entry)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ int ret, r2;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_DATA | ARCHIVE_STATE_HEADER, "archive_write_header");
+ archive_clear_error(&a->archive);
+
+ if (a->format_write_header == NULL) {
+ archive_set_error(&(a->archive), -1,
+ "Format must be set before you can write to an archive.");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+
+ /* In particular, "retry" and "fatal" get returned immediately. */
+ ret = archive_write_finish_entry(&a->archive);
+ if (ret == ARCHIVE_FATAL) {
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ if (ret < ARCHIVE_OK && ret != ARCHIVE_WARN)
+ return (ret);
+
+ if (a->skip_file_set &&
+ archive_entry_dev_is_set(entry) &&
+ archive_entry_ino_is_set(entry) &&
+ archive_entry_dev(entry) == (dev_t)a->skip_file_dev &&
+ archive_entry_ino64(entry) == a->skip_file_ino) {
+ archive_set_error(&a->archive, 0,
+ "Can't add archive to itself");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Format and write header. */
+ r2 = ((a->format_write_header)(a, entry));
+ if (r2 == ARCHIVE_FAILED) {
+ return (ARCHIVE_FAILED);
+ }
+ if (r2 == ARCHIVE_FATAL) {
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+ }
+ if (r2 < ret)
+ ret = r2;
+
+ a->archive.state = ARCHIVE_STATE_DATA;
+ return (ret);
+}
+
+static int
+_archive_write_finish_entry(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ int ret = ARCHIVE_OK;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_write_finish_entry");
+ if (a->archive.state & ARCHIVE_STATE_DATA
+ && a->format_finish_entry != NULL)
+ ret = (a->format_finish_entry)(a);
+ a->archive.state = ARCHIVE_STATE_HEADER;
+ return (ret);
+}
+
+/*
+ * Note that the compressor is responsible for blocking.
+ */
+static ssize_t
+_archive_write_data(struct archive *_a, const void *buff, size_t s)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ const size_t max_write = INT_MAX;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_DATA, "archive_write_data");
+ /* In particular, this catches attempts to pass negative values. */
+ if (s > max_write)
+ s = max_write;
+ archive_clear_error(&a->archive);
+ return ((a->format_write_data)(a, buff, s));
+}
+
+static struct archive_write_filter *
+filter_lookup(struct archive *_a, int n)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct archive_write_filter *f = a->filter_first;
+ if (n == -1)
+ return a->filter_last;
+ if (n < 0)
+ return NULL;
+ while (n > 0 && f != NULL) {
+ f = f->next_filter;
+ --n;
+ }
+ return f;
+}
+
+static int
+_archive_filter_code(struct archive *_a, int n)
+{
+ struct archive_write_filter *f = filter_lookup(_a, n);
+ return f == NULL ? -1 : f->code;
+}
+
+static const char *
+_archive_filter_name(struct archive *_a, int n)
+{
+ struct archive_write_filter *f = filter_lookup(_a, n);
+ return f != NULL ? f->name : NULL;
+}
+
+static int64_t
+_archive_filter_bytes(struct archive *_a, int n)
+{
+ struct archive_write_filter *f = filter_lookup(_a, n);
+ return f == NULL ? -1 : f->bytes_written;
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
new file mode 100644
index 0000000000..81dd683aac
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
@@ -0,0 +1,70 @@
+/*-
+ * Copyright (c) 2012 Ondrej Holy
+ * 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_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#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;
+
+ 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);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_b64encode.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_b64encode.c
new file mode 100644
index 0000000000..85eb087b05
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_b64encode.c
@@ -0,0 +1,314 @@
+/*-
+ * Copyright (c) 2012 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_string.h"
+#include "archive_write_private.h"
+
+#define LBYTES 57
+
+struct private_b64encode {
+ int mode;
+ struct archive_string name;
+ struct archive_string encoded_buff;
+ size_t bs;
+ size_t hold_len;
+ unsigned char hold[LBYTES];
+};
+
+static int archive_filter_b64encode_options(struct archive_write_filter *,
+ const char *, const char *);
+static int archive_filter_b64encode_open(struct archive_write_filter *);
+static int archive_filter_b64encode_write(struct archive_write_filter *,
+ const void *, size_t);
+static int archive_filter_b64encode_close(struct archive_write_filter *);
+static int archive_filter_b64encode_free(struct archive_write_filter *);
+static void b64_encode(struct archive_string *, const unsigned char *, size_t);
+static int64_t atol8(const char *, size_t);
+
+static const char base64[] = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3',
+ '4', '5', '6', '7', '8', '9', '+', '/'
+};
+
+/*
+ * Add a compress filter to this write handle.
+ */
+int
+archive_write_add_filter_b64encode(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct archive_write_filter *f = __archive_write_allocate_filter(_a);
+ struct private_b64encode *state;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_uu");
+
+ state = (struct private_b64encode *)calloc(1, sizeof(*state));
+ if (state == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for b64encode filter");
+ return (ARCHIVE_FATAL);
+ }
+ archive_strcpy(&state->name, "-");
+ state->mode = 0644;
+
+ f->data = state;
+ f->name = "b64encode";
+ f->code = ARCHIVE_FILTER_UU;
+ f->open = archive_filter_b64encode_open;
+ f->options = archive_filter_b64encode_options;
+ f->write = archive_filter_b64encode_write;
+ f->close = archive_filter_b64encode_close;
+ f->free = archive_filter_b64encode_free;
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Set write options.
+ */
+static int
+archive_filter_b64encode_options(struct archive_write_filter *f, const char *key,
+ const char *value)
+{
+ struct private_b64encode *state = (struct private_b64encode *)f->data;
+
+ if (strcmp(key, "mode") == 0) {
+ if (value == NULL) {
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "mode option requires octal digits");
+ return (ARCHIVE_FAILED);
+ }
+ state->mode = (int)atol8(value, strlen(value)) & 0777;
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "name") == 0) {
+ if (value == NULL) {
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "name option requires a string");
+ return (ARCHIVE_FAILED);
+ }
+ archive_strcpy(&state->name, value);
+ 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);
+}
+
+/*
+ * Setup callback.
+ */
+static int
+archive_filter_b64encode_open(struct archive_write_filter *f)
+{
+ struct private_b64encode *state = (struct private_b64encode *)f->data;
+ size_t bs = 65536, bpb;
+ int ret;
+
+ ret = __archive_write_open_filter(f->next_filter);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ 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 -= bs % bpb;
+ }
+
+ state->bs = bs;
+ if (archive_string_ensure(&state->encoded_buff, bs + 512) == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for b64encode buffer");
+ return (ARCHIVE_FATAL);
+ }
+
+ archive_string_sprintf(&state->encoded_buff, "begin-base64 %o %s\n",
+ state->mode, state->name.s);
+
+ f->data = state;
+ return (0);
+}
+
+static void
+b64_encode(struct archive_string *as, const unsigned char *p, size_t len)
+{
+ int c;
+
+ for (; len >= 3; p += 3, len -= 3) {
+ c = p[0] >> 2;
+ archive_strappend_char(as, base64[c]);
+ c = ((p[0] & 0x03) << 4) | ((p[1] & 0xf0) >> 4);
+ archive_strappend_char(as, base64[c]);
+ c = ((p[1] & 0x0f) << 2) | ((p[2] & 0xc0) >> 6);
+ archive_strappend_char(as, base64[c]);
+ c = p[2] & 0x3f;
+ archive_strappend_char(as, base64[c]);
+ }
+ if (len > 0) {
+ c = p[0] >> 2;
+ archive_strappend_char(as, base64[c]);
+ c = (p[0] & 0x03) << 4;
+ if (len == 1) {
+ archive_strappend_char(as, base64[c]);
+ archive_strappend_char(as, '=');
+ archive_strappend_char(as, '=');
+ } else {
+ c |= (p[1] & 0xf0) >> 4;
+ archive_strappend_char(as, base64[c]);
+ c = (p[1] & 0x0f) << 2;
+ archive_strappend_char(as, base64[c]);
+ archive_strappend_char(as, '=');
+ }
+ }
+ archive_strappend_char(as, '\n');
+}
+
+/*
+ * Write data to the encoded stream.
+ */
+static int
+archive_filter_b64encode_write(struct archive_write_filter *f, const void *buff,
+ size_t length)
+{
+ struct private_b64encode *state = (struct private_b64encode *)f->data;
+ const unsigned char *p = buff;
+ int ret = ARCHIVE_OK;
+
+ if (length == 0)
+ return (ret);
+
+ if (state->hold_len) {
+ while (state->hold_len < LBYTES && length > 0) {
+ state->hold[state->hold_len++] = *p++;
+ length--;
+ }
+ if (state->hold_len < LBYTES)
+ return (ret);
+ b64_encode(&state->encoded_buff, state->hold, LBYTES);
+ state->hold_len = 0;
+ }
+
+ for (; length >= LBYTES; length -= LBYTES, p += LBYTES)
+ b64_encode(&state->encoded_buff, p, LBYTES);
+
+ /* Save remaining bytes. */
+ if (length > 0) {
+ memcpy(state->hold, p, length);
+ state->hold_len = length;
+ }
+ while (archive_strlen(&state->encoded_buff) >= state->bs) {
+ ret = __archive_write_filter(f->next_filter,
+ state->encoded_buff.s, state->bs);
+ memmove(state->encoded_buff.s,
+ state->encoded_buff.s + state->bs,
+ state->encoded_buff.length - state->bs);
+ state->encoded_buff.length -= state->bs;
+ }
+
+ return (ret);
+}
+
+
+/*
+ * Finish the compression...
+ */
+static int
+archive_filter_b64encode_close(struct archive_write_filter *f)
+{
+ struct private_b64encode *state = (struct private_b64encode *)f->data;
+ int ret, ret2;
+
+ /* Flush remaining bytes. */
+ if (state->hold_len != 0)
+ b64_encode(&state->encoded_buff, state->hold, state->hold_len);
+ archive_string_sprintf(&state->encoded_buff, "====\n");
+ /* Write the last block */
+ archive_write_set_bytes_in_last_block(f->archive, 1);
+ ret = __archive_write_filter(f->next_filter,
+ state->encoded_buff.s, archive_strlen(&state->encoded_buff));
+ ret2 = __archive_write_close_filter(f->next_filter);
+ if (ret > ret2)
+ ret = ret2;
+ return (ret);
+}
+
+static int
+archive_filter_b64encode_free(struct archive_write_filter *f)
+{
+ struct private_b64encode *state = (struct private_b64encode *)f->data;
+
+ archive_string_free(&state->name);
+ archive_string_free(&state->encoded_buff);
+ free(state);
+ return (ARCHIVE_OK);
+}
+
+static int64_t
+atol8(const char *p, size_t char_cnt)
+{
+ int64_t l;
+ int digit;
+
+ l = 0;
+ while (char_cnt-- > 0) {
+ if (*p >= '0' && *p <= '7')
+ digit = *p - '0';
+ else
+ break;
+ p++;
+ l <<= 3;
+ l |= digit;
+ }
+ return (l);
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c
new file mode 100644
index 0000000000..e4cba4afa0
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c
@@ -0,0 +1,75 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 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_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 (*setter)(struct archive *); } names[] =
+{
+ { "b64encode", archive_write_add_filter_b64encode },
+ { "bzip2", archive_write_add_filter_bzip2 },
+ { "compress", archive_write_add_filter_compress },
+ { "grzip", archive_write_add_filter_grzip },
+ { "gzip", archive_write_add_filter_gzip },
+ { "lrzip", archive_write_add_filter_lrzip },
+ { "lzip", archive_write_add_filter_lzip },
+ { "lzma", archive_write_add_filter_lzma },
+ { "lzop", archive_write_add_filter_lzop },
+ { "uuencode", archive_write_add_filter_uuencode },
+ { "xz", archive_write_add_filter_xz },
+ { NULL, NULL }
+};
+
+int
+archive_write_add_filter_by_name(struct archive *a, const char *name)
+{
+ int i;
+
+ for (i = 0; names[i].name != NULL; i++) {
+ if (strcmp(name, names[i].name) == 0)
+ return ((names[i].setter)(a));
+ }
+
+ archive_set_error(a, EINVAL, "No such filter '%s'", name);
+ a->state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_bzip2.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_bzip2.c
new file mode 100644
index 0000000000..6526f5168a
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_bzip2.c
@@ -0,0 +1,407 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 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: head/lib/libarchive/archive_write_set_compression_bzip2.c 201091 2009-12-28 02:22:41Z kientzle $");
+
+#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_BZLIB_H
+#include <cm_bzlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+int
+archive_write_set_compression_bzip2(struct archive *a)
+{
+ __archive_write_filters_free(a);
+ return (archive_write_add_filter_bzip2(a));
+}
+#endif
+
+struct private_data {
+ int compression_level;
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ bz_stream stream;
+ int64_t total_in;
+ char *compressed;
+ size_t compressed_buffer_size;
+#else
+ struct archive_write_program_data *pdata;
+#endif
+};
+
+static int archive_compressor_bzip2_close(struct archive_write_filter *);
+static int archive_compressor_bzip2_free(struct archive_write_filter *);
+static int archive_compressor_bzip2_open(struct archive_write_filter *);
+static int archive_compressor_bzip2_options(struct archive_write_filter *,
+ const char *, const char *);
+static int archive_compressor_bzip2_write(struct archive_write_filter *,
+ const void *, size_t);
+
+/*
+ * Add a bzip2 compression filter to this write handle.
+ */
+int
+archive_write_add_filter_bzip2(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_bzip2");
+
+ data = calloc(1, sizeof(*data));
+ if (data == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ data->compression_level = 9; /* default */
+
+ f->data = data;
+ f->options = &archive_compressor_bzip2_options;
+ f->close = &archive_compressor_bzip2_close;
+ f->free = &archive_compressor_bzip2_free;
+ f->open = &archive_compressor_bzip2_open;
+ f->code = ARCHIVE_FILTER_BZIP2;
+ f->name = "bzip2";
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ return (ARCHIVE_OK);
+#else
+ 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 bzip2 program");
+ return (ARCHIVE_WARN);
+#endif
+}
+
+/*
+ * Set write options.
+ */
+static int
+archive_compressor_bzip2_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] >= '0' && value[0] <= '9') ||
+ value[1] != '\0')
+ return (ARCHIVE_WARN);
+ data->compression_level = value[0] - '0';
+ /* Make '0' be a synonym for '1'. */
+ /* This way, bzip2 compressor supports the same 0..9
+ * range of levels as gzip. */
+ if (data->compression_level < 1)
+ data->compression_level = 1;
+ 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_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+/* Don't compile this if we don't have bzlib. */
+
+/*
+ * Yuck. bzlib.h is not const-correct, so I need this one bit
+ * of ugly hackery to convert a const * pointer to a non-const pointer.
+ */
+#define SET_NEXT_IN(st,src) \
+ (st)->stream.next_in = (char *)(uintptr_t)(const void *)(src)
+static int drive_compressor(struct archive_write_filter *,
+ struct private_data *, int finishing);
+
+/*
+ * Setup callback.
+ */
+static int
+archive_compressor_bzip2_open(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+ int ret;
+
+ ret = __archive_write_open_filter(f->next_filter);
+ if (ret != 0)
+ return (ret);
+
+ if (data->compressed == NULL) {
+ size_t bs = 65536, bpb;
+ 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 -= bs % bpb;
+ }
+ data->compressed_buffer_size = bs;
+ data->compressed
+ = (char *)malloc(data->compressed_buffer_size);
+ if (data->compressed == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for compression buffer");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ memset(&data->stream, 0, sizeof(data->stream));
+ data->stream.next_out = data->compressed;
+ data->stream.avail_out = data->compressed_buffer_size;
+ f->write = archive_compressor_bzip2_write;
+
+ /* Initialize compression library */
+ ret = BZ2_bzCompressInit(&(data->stream),
+ data->compression_level, 0, 30);
+ if (ret == BZ_OK) {
+ f->data = data;
+ return (ARCHIVE_OK);
+ }
+
+ /* Library setup failed: clean up. */
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library");
+
+ /* Override the error message if we know what really went wrong. */
+ switch (ret) {
+ case BZ_PARAM_ERROR:
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ "invalid setup parameter");
+ break;
+ case BZ_MEM_ERROR:
+ archive_set_error(f->archive, ENOMEM,
+ "Internal error initializing compression library: "
+ "out of memory");
+ break;
+ case BZ_CONFIG_ERROR:
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ "mis-compiled library");
+ break;
+ }
+
+ return (ARCHIVE_FATAL);
+
+}
+
+/*
+ * Write data to the compressed stream.
+ *
+ * Returns ARCHIVE_OK if all data written, error otherwise.
+ */
+static int
+archive_compressor_bzip2_write(struct archive_write_filter *f,
+ const void *buff, size_t length)
+{
+ struct private_data *data = (struct private_data *)f->data;
+
+ /* Update statistics */
+ data->total_in += length;
+
+ /* Compress input data to output buffer */
+ SET_NEXT_IN(data, buff);
+ data->stream.avail_in = length;
+ if (drive_compressor(f, data, 0))
+ return (ARCHIVE_FATAL);
+ return (ARCHIVE_OK);
+}
+
+
+/*
+ * Finish the compression.
+ */
+static int
+archive_compressor_bzip2_close(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+ int ret, r1;
+
+ /* Finish compression cycle. */
+ ret = drive_compressor(f, data, 1);
+ if (ret == ARCHIVE_OK) {
+ /* Write the last block */
+ ret = __archive_write_filter(f->next_filter,
+ data->compressed,
+ data->compressed_buffer_size - data->stream.avail_out);
+ }
+
+ switch (BZ2_bzCompressEnd(&(data->stream))) {
+ case BZ_OK:
+ break;
+ default:
+ archive_set_error(f->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "Failed to clean up compressor");
+ ret = ARCHIVE_FATAL;
+ }
+
+ r1 = __archive_write_close_filter(f->next_filter);
+ return (r1 < ret ? r1 : ret);
+}
+
+static int
+archive_compressor_bzip2_free(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+ free(data->compressed);
+ free(data);
+ f->data = NULL;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * 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,
+ struct private_data *data, int finishing)
+{
+ int ret;
+
+ for (;;) {
+ if (data->stream.avail_out == 0) {
+ ret = __archive_write_filter(f->next_filter,
+ data->compressed,
+ data->compressed_buffer_size);
+ if (ret != ARCHIVE_OK) {
+ /* TODO: Handle this write failure */
+ return (ARCHIVE_FATAL);
+ }
+ data->stream.next_out = data->compressed;
+ data->stream.avail_out = data->compressed_buffer_size;
+ }
+
+ /* If there's nothing to do, we're done. */
+ if (!finishing && data->stream.avail_in == 0)
+ return (ARCHIVE_OK);
+
+ ret = BZ2_bzCompress(&(data->stream),
+ finishing ? BZ_FINISH : BZ_RUN);
+
+ switch (ret) {
+ case BZ_RUN_OK:
+ /* In non-finishing case, did compressor
+ * consume everything? */
+ if (!finishing && data->stream.avail_in == 0)
+ return (ARCHIVE_OK);
+ break;
+ case BZ_FINISH_OK: /* Finishing: There's more work to do */
+ break;
+ case BZ_STREAM_END: /* Finishing: all done */
+ /* Only occurs in finishing case */
+ return (ARCHIVE_OK);
+ default:
+ /* Any other return value indicates an error */
+ archive_set_error(f->archive,
+ ARCHIVE_ERRNO_PROGRAMMER,
+ "Bzip2 compression failed;"
+ " BZ2_bzCompress() returned %d",
+ ret);
+ return (ARCHIVE_FATAL);
+ }
+ }
+}
+
+#else /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */
+
+static int
+archive_compressor_bzip2_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, "bzip2");
+
+ /* Specify compression level. */
+ if (data->compression_level > 0) {
+ archive_strcat(&as, " -");
+ archive_strappend_char(&as, '0' + data->compression_level);
+ }
+ f->write = archive_compressor_bzip2_write;
+
+ r = __archive_write_program_open(f, data->pdata, as.s);
+ archive_string_free(&as);
+ return (r);
+}
+
+static int
+archive_compressor_bzip2_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_compressor_bzip2_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_compressor_bzip2_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_BZLIB_H && BZ_CONFIG_ERROR */
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_compress.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_compress.c
new file mode 100644
index 0000000000..26fcef4d42
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_compress.c
@@ -0,0 +1,455 @@
+/*-
+ * Copyright (c) 2008 Joerg Sonnenberger
+ * 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.
+ */
+
+/*-
+ * Copyright (c) 1985, 1986, 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Diomidis Spinellis and James A. Woods, derived from original
+ * work by Spencer Thomas and Joseph Orost.
+ *
+ * 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.
+ * 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+#include "archive_platform.h"
+
+__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_compress.c 201111 2009-12-28 03:33:05Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+#define HSIZE 69001 /* 95% occupancy */
+#define HSHIFT 8 /* 8 - trunc(log2(HSIZE / 65536)) */
+#define CHECK_GAP 10000 /* Ratio check interval. */
+
+#define MAXCODE(bits) ((1 << (bits)) - 1)
+
+/*
+ * the next two codes should not be changed lightly, as they must not
+ * lie within the contiguous general code space.
+ */
+#define FIRST 257 /* First free entry. */
+#define CLEAR 256 /* Table clear output code. */
+
+struct private_data {
+ int64_t in_count, out_count, checkpoint;
+
+ int code_len; /* Number of bits/code. */
+ int cur_maxcode; /* Maximum code, given n_bits. */
+ int max_maxcode; /* Should NEVER generate this code. */
+ int hashtab [HSIZE];
+ unsigned short codetab [HSIZE];
+ int first_free; /* First unused entry. */
+ int compress_ratio;
+
+ int cur_code, cur_fcode;
+
+ int bit_offset;
+ unsigned char bit_buf;
+
+ unsigned char *compressed;
+ size_t compressed_buffer_size;
+ size_t compressed_offset;
+};
+
+static int archive_compressor_compress_open(struct archive_write_filter *);
+static int archive_compressor_compress_write(struct archive_write_filter *,
+ const void *, size_t);
+static int archive_compressor_compress_close(struct archive_write_filter *);
+static int archive_compressor_compress_free(struct archive_write_filter *);
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+int
+archive_write_set_compression_compress(struct archive *a)
+{
+ __archive_write_filters_free(a);
+ return (archive_write_add_filter_compress(a));
+}
+#endif
+
+/*
+ * Add a compress filter to this write handle.
+ */
+int
+archive_write_add_filter_compress(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct archive_write_filter *f = __archive_write_allocate_filter(_a);
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_compress");
+ f->open = &archive_compressor_compress_open;
+ f->code = ARCHIVE_FILTER_COMPRESS;
+ f->name = "compress";
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Setup callback.
+ */
+static int
+archive_compressor_compress_open(struct archive_write_filter *f)
+{
+ int ret;
+ struct private_data *state;
+ size_t bs = 65536, bpb;
+
+ f->code = ARCHIVE_FILTER_COMPRESS;
+ f->name = "compress";
+
+ ret = __archive_write_open_filter(f->next_filter);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ state = (struct private_data *)calloc(1, sizeof(*state));
+ if (state == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for compression");
+ return (ARCHIVE_FATAL);
+ }
+
+ 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 -= bs % bpb;
+ }
+ state->compressed_buffer_size = bs;
+ state->compressed = malloc(state->compressed_buffer_size);
+
+ if (state->compressed == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for compression buffer");
+ free(state);
+ return (ARCHIVE_FATAL);
+ }
+
+ f->write = archive_compressor_compress_write;
+ f->close = archive_compressor_compress_close;
+ f->free = archive_compressor_compress_free;
+
+ state->max_maxcode = 0x10000; /* Should NEVER generate this code. */
+ state->in_count = 0; /* Length of input. */
+ state->bit_buf = 0;
+ state->bit_offset = 0;
+ state->out_count = 3; /* Includes 3-byte header mojo. */
+ state->compress_ratio = 0;
+ state->checkpoint = CHECK_GAP;
+ state->code_len = 9;
+ state->cur_maxcode = MAXCODE(state->code_len);
+ state->first_free = FIRST;
+
+ memset(state->hashtab, 0xff, sizeof(state->hashtab));
+
+ /* Prime output buffer with a gzip header. */
+ state->compressed[0] = 0x1f; /* Compress */
+ state->compressed[1] = 0x9d;
+ state->compressed[2] = 0x90; /* Block mode, 16bit max */
+ state->compressed_offset = 3;
+
+ f->data = state;
+ return (0);
+}
+
+/*-
+ * Output the given code.
+ * Inputs:
+ * code: A n_bits-bit integer. If == -1, then EOF. This assumes
+ * that n_bits <= (long)wordsize - 1.
+ * Outputs:
+ * Outputs code to the file.
+ * Assumptions:
+ * Chars are 8 bits long.
+ * Algorithm:
+ * Maintain a BITS character long buffer (so that 8 codes will
+ * fit in it exactly). Use the VAX insv instruction to insert each
+ * code in turn. When the buffer fills up empty it and start over.
+ */
+
+static const unsigned char rmask[9] =
+ {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
+
+static int
+output_byte(struct archive_write_filter *f, unsigned char c)
+{
+ struct private_data *state = f->data;
+
+ state->compressed[state->compressed_offset++] = c;
+ ++state->out_count;
+
+ if (state->compressed_buffer_size == state->compressed_offset) {
+ int ret = __archive_write_filter(f->next_filter,
+ state->compressed, state->compressed_buffer_size);
+ if (ret != ARCHIVE_OK)
+ return ARCHIVE_FATAL;
+ state->compressed_offset = 0;
+ }
+
+ return ARCHIVE_OK;
+}
+
+static int
+output_code(struct archive_write_filter *f, int ocode)
+{
+ struct private_data *state = f->data;
+ int bits, ret, clear_flg, bit_offset;
+
+ clear_flg = ocode == CLEAR;
+
+ /*
+ * Since ocode is always >= 8 bits, only need to mask the first
+ * hunk on the left.
+ */
+ bit_offset = state->bit_offset % 8;
+ state->bit_buf |= (ocode << bit_offset) & 0xff;
+ output_byte(f, state->bit_buf);
+
+ bits = state->code_len - (8 - bit_offset);
+ ocode >>= 8 - bit_offset;
+ /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
+ if (bits >= 8) {
+ output_byte(f, ocode & 0xff);
+ ocode >>= 8;
+ bits -= 8;
+ }
+ /* Last bits. */
+ state->bit_offset += state->code_len;
+ state->bit_buf = ocode & rmask[bits];
+ if (state->bit_offset == state->code_len * 8)
+ state->bit_offset = 0;
+
+ /*
+ * If the next entry is going to be too big for the ocode size,
+ * then increase it, if possible.
+ */
+ if (clear_flg || state->first_free > state->cur_maxcode) {
+ /*
+ * Write the whole buffer, because the input side won't
+ * discover the size increase until after it has read it.
+ */
+ if (state->bit_offset > 0) {
+ while (state->bit_offset < state->code_len * 8) {
+ ret = output_byte(f, state->bit_buf);
+ if (ret != ARCHIVE_OK)
+ return ret;
+ state->bit_offset += 8;
+ state->bit_buf = 0;
+ }
+ }
+ state->bit_buf = 0;
+ state->bit_offset = 0;
+
+ if (clear_flg) {
+ state->code_len = 9;
+ state->cur_maxcode = MAXCODE(state->code_len);
+ } else {
+ state->code_len++;
+ if (state->code_len == 16)
+ state->cur_maxcode = state->max_maxcode;
+ else
+ state->cur_maxcode = MAXCODE(state->code_len);
+ }
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static int
+output_flush(struct archive_write_filter *f)
+{
+ struct private_data *state = f->data;
+ int ret;
+
+ /* At EOF, write the rest of the buffer. */
+ if (state->bit_offset % 8) {
+ state->code_len = (state->bit_offset % 8 + 7) / 8;
+ ret = output_byte(f, state->bit_buf);
+ if (ret != ARCHIVE_OK)
+ return ret;
+ }
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Write data to the compressed stream.
+ */
+static int
+archive_compressor_compress_write(struct archive_write_filter *f,
+ const void *buff, size_t length)
+{
+ struct private_data *state = (struct private_data *)f->data;
+ int i;
+ int ratio;
+ int c, disp, ret;
+ const unsigned char *bp;
+
+ if (length == 0)
+ return ARCHIVE_OK;
+
+ bp = buff;
+
+ if (state->in_count == 0) {
+ state->cur_code = *bp++;
+ ++state->in_count;
+ --length;
+ }
+
+ while (length--) {
+ c = *bp++;
+ state->in_count++;
+ state->cur_fcode = (c << 16) + state->cur_code;
+ i = ((c << HSHIFT) ^ state->cur_code); /* Xor hashing. */
+
+ if (state->hashtab[i] == state->cur_fcode) {
+ state->cur_code = state->codetab[i];
+ continue;
+ }
+ if (state->hashtab[i] < 0) /* Empty slot. */
+ goto nomatch;
+ /* Secondary hash (after G. Knott). */
+ if (i == 0)
+ disp = 1;
+ else
+ disp = HSIZE - i;
+ probe:
+ if ((i -= disp) < 0)
+ i += HSIZE;
+
+ if (state->hashtab[i] == state->cur_fcode) {
+ state->cur_code = state->codetab[i];
+ continue;
+ }
+ if (state->hashtab[i] >= 0)
+ goto probe;
+ nomatch:
+ ret = output_code(f, state->cur_code);
+ if (ret != ARCHIVE_OK)
+ return ret;
+ state->cur_code = c;
+ if (state->first_free < state->max_maxcode) {
+ state->codetab[i] = state->first_free++; /* code -> hashtable */
+ state->hashtab[i] = state->cur_fcode;
+ continue;
+ }
+ if (state->in_count < state->checkpoint)
+ continue;
+
+ state->checkpoint = state->in_count + CHECK_GAP;
+
+ if (state->in_count <= 0x007fffff && state->out_count != 0)
+ ratio = (int)(state->in_count * 256 / state->out_count);
+ else if ((ratio = (int)(state->out_count / 256)) == 0)
+ ratio = 0x7fffffff;
+ else
+ ratio = (int)(state->in_count / ratio);
+
+ if (ratio > state->compress_ratio)
+ state->compress_ratio = ratio;
+ else {
+ state->compress_ratio = 0;
+ memset(state->hashtab, 0xff, sizeof(state->hashtab));
+ state->first_free = FIRST;
+ ret = output_code(f, CLEAR);
+ if (ret != ARCHIVE_OK)
+ return ret;
+ }
+ }
+
+ return (ARCHIVE_OK);
+}
+
+
+/*
+ * Finish the compression...
+ */
+static int
+archive_compressor_compress_close(struct archive_write_filter *f)
+{
+ struct private_data *state = (struct private_data *)f->data;
+ int ret, ret2;
+
+ ret = output_code(f, state->cur_code);
+ if (ret != ARCHIVE_OK)
+ goto cleanup;
+ ret = output_flush(f);
+ if (ret != ARCHIVE_OK)
+ goto cleanup;
+
+ /* Write the last block */
+ ret = __archive_write_filter(f->next_filter,
+ state->compressed, state->compressed_offset);
+cleanup:
+ ret2 = __archive_write_close_filter(f->next_filter);
+ if (ret > ret2)
+ ret = ret2;
+ free(state->compressed);
+ free(state);
+ return (ret);
+}
+
+static int
+archive_compressor_compress_free(struct archive_write_filter *f)
+{
+ (void)f; /* UNUSED */
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_grzip.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_grzip.c
new file mode 100644
index 0000000000..8dc287eae0
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_grzip.c
@@ -0,0 +1,135 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_write_private.h"
+
+struct write_grzip {
+ struct archive_write_program_data *pdata;
+};
+
+static int archive_write_grzip_open(struct archive_write_filter *);
+static int archive_write_grzip_options(struct archive_write_filter *,
+ const char *, const char *);
+static int archive_write_grzip_write(struct archive_write_filter *,
+ const void *, size_t);
+static int archive_write_grzip_close(struct archive_write_filter *);
+static int archive_write_grzip_free(struct archive_write_filter *);
+
+int
+archive_write_add_filter_grzip(struct archive *_a)
+{
+ struct archive_write_filter *f = __archive_write_allocate_filter(_a);
+ struct write_grzip *data;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_grzip");
+
+ data = calloc(1, sizeof(*data));
+ if (data == NULL) {
+ archive_set_error(_a, ENOMEM, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ data->pdata = __archive_write_program_allocate();
+ if (data->pdata == NULL) {
+ free(data);
+ archive_set_error(_a, ENOMEM, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ f->name = "grzip";
+ f->code = ARCHIVE_FILTER_GRZIP;
+ f->data = data;
+ f->open = archive_write_grzip_open;
+ f->options = archive_write_grzip_options;
+ f->write = archive_write_grzip_write;
+ f->close = archive_write_grzip_close;
+ f->free = archive_write_grzip_free;
+
+ /* Note: This filter always uses an external program, so we
+ * return "warn" to inform of the fact. */
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external grzip program for grzip compression");
+ return (ARCHIVE_WARN);
+}
+
+static int
+archive_write_grzip_options(struct archive_write_filter *f, const char *key,
+ const char *value)
+{
+ (void)f; /* UNUSED */
+ (void)key; /* UNUSED */
+ (void)value; /* UNUSED */
+ /* 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
+archive_write_grzip_open(struct archive_write_filter *f)
+{
+ struct write_grzip *data = (struct write_grzip *)f->data;
+
+ return __archive_write_program_open(f, data->pdata, "grzip");
+}
+
+static int
+archive_write_grzip_write(struct archive_write_filter *f,
+ const void *buff, size_t length)
+{
+ struct write_grzip *data = (struct write_grzip *)f->data;
+
+ return __archive_write_program_write(f, data->pdata, buff, length);
+}
+
+static int
+archive_write_grzip_close(struct archive_write_filter *f)
+{
+ struct write_grzip *data = (struct write_grzip *)f->data;
+
+ return __archive_write_program_close(f, data->pdata);
+}
+
+static int
+archive_write_grzip_free(struct archive_write_filter *f)
+{
+ struct write_grzip *data = (struct write_grzip *)f->data;
+
+ __archive_write_program_free(data->pdata);
+ free(data);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c
new file mode 100644
index 0000000000..db18fd94ac
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c
@@ -0,0 +1,442 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_compression_gzip.c 201081 2009-12-28 02:04:42Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <time.h>
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_string.h"
+#include "archive_write_private.h"
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+int
+archive_write_set_compression_gzip(struct archive *a)
+{
+ __archive_write_filters_free(a);
+ return (archive_write_add_filter_gzip(a));
+}
+#endif
+
+/* Don't compile this if we don't have zlib. */
+
+struct private_data {
+ int compression_level;
+ int timestamp;
+#ifdef HAVE_ZLIB_H
+ z_stream stream;
+ int64_t total_in;
+ unsigned char *compressed;
+ size_t compressed_buffer_size;
+ unsigned long crc;
+#else
+ struct archive_write_program_data *pdata;
+#endif
+};
+
+/*
+ * Yuck. zlib.h is not const-correct, so I need this one bit
+ * of ugly hackery to convert a const * pointer to a non-const pointer.
+ */
+#define SET_NEXT_IN(st,src) \
+ (st)->stream.next_in = (Bytef *)(uintptr_t)(const void *)(src)
+
+static int archive_compressor_gzip_options(struct archive_write_filter *,
+ const char *, const char *);
+static int archive_compressor_gzip_open(struct archive_write_filter *);
+static int archive_compressor_gzip_write(struct archive_write_filter *,
+ const void *, size_t);
+static int archive_compressor_gzip_close(struct archive_write_filter *);
+static int archive_compressor_gzip_free(struct archive_write_filter *);
+#ifdef HAVE_ZLIB_H
+static int drive_compressor(struct archive_write_filter *,
+ struct private_data *, int finishing);
+#endif
+
+
+/*
+ * Add a gzip compression filter to this write handle.
+ */
+int
+archive_write_add_filter_gzip(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_gzip");
+
+ data = calloc(1, sizeof(*data));
+ if (data == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ f->data = data;
+ f->open = &archive_compressor_gzip_open;
+ f->options = &archive_compressor_gzip_options;
+ f->close = &archive_compressor_gzip_close;
+ f->free = &archive_compressor_gzip_free;
+ f->code = ARCHIVE_FILTER_GZIP;
+ f->name = "gzip";
+#ifdef HAVE_ZLIB_H
+ data->compression_level = Z_DEFAULT_COMPRESSION;
+ return (ARCHIVE_OK);
+#else
+ 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 gzip program");
+ return (ARCHIVE_WARN);
+#endif
+}
+
+static int
+archive_compressor_gzip_free(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+
+#ifdef HAVE_ZLIB_H
+ free(data->compressed);
+#else
+ __archive_write_program_free(data->pdata);
+#endif
+ free(data);
+ f->data = NULL;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Set write options.
+ */
+static int
+archive_compressor_gzip_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] >= '0' && value[0] <= '9') ||
+ value[1] != '\0')
+ return (ARCHIVE_WARN);
+ data->compression_level = value[0] - '0';
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "timestamp") == 0) {
+ data->timestamp = (value == NULL)?-1:1;
+ 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);
+}
+
+#ifdef HAVE_ZLIB_H
+/*
+ * Setup callback.
+ */
+static int
+archive_compressor_gzip_open(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+ int ret;
+
+ ret = __archive_write_open_filter(f->next_filter);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ if (data->compressed == NULL) {
+ size_t bs = 65536, bpb;
+ 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 -= bs % bpb;
+ }
+ data->compressed_buffer_size = bs;
+ data->compressed
+ = (unsigned char *)malloc(data->compressed_buffer_size);
+ if (data->compressed == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for compression buffer");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ data->crc = crc32(0L, NULL, 0);
+ data->stream.next_out = data->compressed;
+ data->stream.avail_out = (uInt)data->compressed_buffer_size;
+
+ /* Prime output buffer with a gzip header. */
+ data->compressed[0] = 0x1f; /* GZip signature bytes */
+ data->compressed[1] = 0x8b;
+ data->compressed[2] = 0x08; /* "Deflate" compression */
+ data->compressed[3] = 0; /* No options */
+ if (data->timestamp >= 0) {
+ time_t t = time(NULL);
+ data->compressed[4] = (uint8_t)(t)&0xff; /* Timestamp */
+ data->compressed[5] = (uint8_t)(t>>8)&0xff;
+ data->compressed[6] = (uint8_t)(t>>16)&0xff;
+ data->compressed[7] = (uint8_t)(t>>24)&0xff;
+ } else
+ memset(&data->compressed[4], 0, 4);
+ data->compressed[8] = 0; /* No deflate options */
+ data->compressed[9] = 3; /* OS=Unix */
+ data->stream.next_out += 10;
+ data->stream.avail_out -= 10;
+
+ f->write = archive_compressor_gzip_write;
+
+ /* Initialize compression library. */
+ ret = deflateInit2(&(data->stream),
+ data->compression_level,
+ Z_DEFLATED,
+ -15 /* < 0 to suppress zlib header */,
+ 8,
+ Z_DEFAULT_STRATEGY);
+
+ if (ret == Z_OK) {
+ f->data = data;
+ return (ARCHIVE_OK);
+ }
+
+ /* Library setup failed: clean up. */
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, "Internal error "
+ "initializing compression library");
+
+ /* Override the error message if we know what really went wrong. */
+ switch (ret) {
+ case Z_STREAM_ERROR:
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing "
+ "compression library: invalid setup parameter");
+ break;
+ case Z_MEM_ERROR:
+ archive_set_error(f->archive, ENOMEM,
+ "Internal error initializing compression library");
+ break;
+ case Z_VERSION_ERROR:
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing "
+ "compression library: invalid library version");
+ break;
+ }
+
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Write data to the compressed stream.
+ */
+static int
+archive_compressor_gzip_write(struct archive_write_filter *f, const void *buff,
+ size_t length)
+{
+ struct private_data *data = (struct private_data *)f->data;
+ int ret;
+
+ /* Update statistics */
+ data->crc = crc32(data->crc, (const Bytef *)buff, (uInt)length);
+ data->total_in += length;
+
+ /* Compress input data to output buffer */
+ SET_NEXT_IN(data, buff);
+ data->stream.avail_in = (uInt)length;
+ if ((ret = drive_compressor(f, data, 0)) != ARCHIVE_OK)
+ return (ret);
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Finish the compression...
+ */
+static int
+archive_compressor_gzip_close(struct archive_write_filter *f)
+{
+ unsigned char trailer[8];
+ struct private_data *data = (struct private_data *)f->data;
+ int ret, r1;
+
+ /* Finish compression cycle */
+ ret = drive_compressor(f, data, 1);
+ if (ret == ARCHIVE_OK) {
+ /* Write the last compressed data. */
+ ret = __archive_write_filter(f->next_filter,
+ data->compressed,
+ data->compressed_buffer_size - data->stream.avail_out);
+ }
+ if (ret == ARCHIVE_OK) {
+ /* Build and write out 8-byte trailer. */
+ trailer[0] = (uint8_t)(data->crc)&0xff;
+ trailer[1] = (uint8_t)(data->crc >> 8)&0xff;
+ trailer[2] = (uint8_t)(data->crc >> 16)&0xff;
+ trailer[3] = (uint8_t)(data->crc >> 24)&0xff;
+ trailer[4] = (uint8_t)(data->total_in)&0xff;
+ trailer[5] = (uint8_t)(data->total_in >> 8)&0xff;
+ trailer[6] = (uint8_t)(data->total_in >> 16)&0xff;
+ trailer[7] = (uint8_t)(data->total_in >> 24)&0xff;
+ ret = __archive_write_filter(f->next_filter, trailer, 8);
+ }
+
+ switch (deflateEnd(&(data->stream))) {
+ case Z_OK:
+ break;
+ default:
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to clean up compressor");
+ ret = ARCHIVE_FATAL;
+ }
+ r1 = __archive_write_close_filter(f->next_filter);
+ return (r1 < ret ? r1 : ret);
+}
+
+/*
+ * 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,
+ struct private_data *data, int finishing)
+{
+ int ret;
+
+ for (;;) {
+ if (data->stream.avail_out == 0) {
+ ret = __archive_write_filter(f->next_filter,
+ data->compressed,
+ data->compressed_buffer_size);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ data->stream.next_out = data->compressed;
+ data->stream.avail_out =
+ (uInt)data->compressed_buffer_size;
+ }
+
+ /* If there's nothing to do, we're done. */
+ if (!finishing && data->stream.avail_in == 0)
+ return (ARCHIVE_OK);
+
+ ret = deflate(&(data->stream),
+ finishing ? Z_FINISH : Z_NO_FLUSH );
+
+ switch (ret) {
+ case Z_OK:
+ /* In non-finishing case, check if compressor
+ * consumed everything */
+ if (!finishing && data->stream.avail_in == 0)
+ return (ARCHIVE_OK);
+ /* In finishing case, this return always means
+ * there's more work */
+ break;
+ case Z_STREAM_END:
+ /* This return can only occur in finishing case. */
+ return (ARCHIVE_OK);
+ default:
+ /* Any other return value indicates an error. */
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "GZip compression failed:"
+ " deflate() call returned status %d",
+ ret);
+ return (ARCHIVE_FATAL);
+ }
+ }
+}
+
+#else /* HAVE_ZLIB_H */
+
+static int
+archive_compressor_gzip_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, "gzip");
+
+ /* Specify compression level. */
+ if (data->compression_level > 0) {
+ archive_strcat(&as, " -");
+ archive_strappend_char(&as, '0' + data->compression_level);
+ }
+ if (data->timestamp < 0)
+ /* Do not save timestamp. */
+ archive_strcat(&as, " -n");
+ else if (data->timestamp > 0)
+ /* Save timestamp. */
+ archive_strcat(&as, " -N");
+
+ f->write = archive_compressor_gzip_write;
+ r = __archive_write_program_open(f, data->pdata, as.s);
+ archive_string_free(&as);
+ return (r);
+}
+
+static int
+archive_compressor_gzip_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_compressor_gzip_close(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+
+ return __archive_write_program_close(f, data->pdata);
+}
+
+#endif /* HAVE_ZLIB_H */
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lrzip.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lrzip.c
new file mode 100644
index 0000000000..da1cf5e4c9
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lrzip.c
@@ -0,0 +1,197 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_string.h"
+#include "archive_write_private.h"
+
+struct write_lrzip {
+ struct archive_write_program_data *pdata;
+ int compression_level;
+ enum { lzma = 0, bzip2, gzip, lzo, none, zpaq } compression;
+};
+
+static int archive_write_lrzip_open(struct archive_write_filter *);
+static int archive_write_lrzip_options(struct archive_write_filter *,
+ const char *, const char *);
+static int archive_write_lrzip_write(struct archive_write_filter *,
+ const void *, size_t);
+static int archive_write_lrzip_close(struct archive_write_filter *);
+static int archive_write_lrzip_free(struct archive_write_filter *);
+
+int
+archive_write_add_filter_lrzip(struct archive *_a)
+{
+ struct archive_write_filter *f = __archive_write_allocate_filter(_a);
+ struct write_lrzip *data;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_lrzip");
+
+ data = calloc(1, sizeof(*data));
+ if (data == NULL) {
+ archive_set_error(_a, ENOMEM, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ data->pdata = __archive_write_program_allocate();
+ if (data->pdata == NULL) {
+ free(data);
+ archive_set_error(_a, ENOMEM, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ f->name = "lrzip";
+ f->code = ARCHIVE_FILTER_LRZIP;
+ f->data = data;
+ f->open = archive_write_lrzip_open;
+ f->options = archive_write_lrzip_options;
+ f->write = archive_write_lrzip_write;
+ f->close = archive_write_lrzip_close;
+ f->free = archive_write_lrzip_free;
+
+ /* Note: This filter always uses an external program, so we
+ * return "warn" to inform of the fact. */
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external lrzip program for lrzip compression");
+ return (ARCHIVE_WARN);
+}
+
+static int
+archive_write_lrzip_options(struct archive_write_filter *f, const char *key,
+ const char *value)
+{
+ struct write_lrzip *data = (struct write_lrzip *)f->data;
+
+ if (strcmp(key, "compression") == 0) {
+ if (value == NULL)
+ return (ARCHIVE_WARN);
+ else if (strcmp(value, "bzip2") == 0)
+ data->compression = bzip2;
+ else if (strcmp(value, "gzip") == 0)
+ data->compression = gzip;
+ else if (strcmp(value, "lzo") == 0)
+ data->compression = lzo;
+ else if (strcmp(value, "none") == 0)
+ data->compression = none;
+ else if (strcmp(value, "zpaq") == 0)
+ data->compression = zpaq;
+ else
+ return (ARCHIVE_WARN);
+ return (ARCHIVE_OK);
+ } else 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);
+ }
+ /* 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
+archive_write_lrzip_open(struct archive_write_filter *f)
+{
+ struct write_lrzip *data = (struct write_lrzip *)f->data;
+ struct archive_string as;
+ int r;
+
+ archive_string_init(&as);
+ archive_strcpy(&as, "lrzip -q");
+
+ /* Specify compression type. */
+ switch (data->compression) {
+ case lzma:/* default compression */
+ break;
+ case bzip2:
+ archive_strcat(&as, " -b");
+ break;
+ case gzip:
+ archive_strcat(&as, " -g");
+ break;
+ case lzo:
+ archive_strcat(&as, " -l");
+ break;
+ case none:
+ archive_strcat(&as, " -n");
+ break;
+ case zpaq:
+ archive_strcat(&as, " -z");
+ break;
+ }
+
+ /* Specify compression level. */
+ if (data->compression_level > 0) {
+ archive_strcat(&as, " -L ");
+ archive_strappend_char(&as, '0' + data->compression_level);
+ }
+
+ r = __archive_write_program_open(f, data->pdata, as.s);
+ archive_string_free(&as);
+ return (r);
+}
+
+static int
+archive_write_lrzip_write(struct archive_write_filter *f,
+ const void *buff, size_t length)
+{
+ struct write_lrzip *data = (struct write_lrzip *)f->data;
+
+ return __archive_write_program_write(f, data->pdata, buff, length);
+}
+
+static int
+archive_write_lrzip_close(struct archive_write_filter *f)
+{
+ struct write_lrzip *data = (struct write_lrzip *)f->data;
+
+ return __archive_write_program_close(f, data->pdata);
+}
+
+static int
+archive_write_lrzip_free(struct archive_write_filter *f)
+{
+ struct write_lrzip *data = (struct write_lrzip *)f->data;
+
+ __archive_write_program_free(data->pdata);
+ free(data);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lzop.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lzop.c
new file mode 100644
index 0000000000..c666551d1d
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lzop.c
@@ -0,0 +1,486 @@
+/*-
+ * Copyright (c) 2012 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$");
+//#undef HAVE_LZO_LZOCONF_H
+//#undef HAVE_LZO_LZO1X_H
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <time.h>
+#ifdef HAVE_LZO_LZOCONF_H
+#include <lzo/lzoconf.h>
+#endif
+#ifdef HAVE_LZO_LZO1X_H
+#include <lzo/lzo1x.h>
+#endif
+
+#include "archive.h"
+#include "archive_string.h"
+#include "archive_endian.h"
+#include "archive_write_private.h"
+
+enum lzo_method {
+ METHOD_LZO1X_1 = 1,
+ METHOD_LZO1X_1_15 = 2,
+ METHOD_LZO1X_999 = 3
+};
+struct write_lzop {
+ int compression_level;
+#if defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
+ unsigned char *uncompressed;
+ size_t uncompressed_buffer_size;
+ size_t uncompressed_avail_bytes;
+ unsigned char *compressed;
+ size_t compressed_buffer_size;
+ enum lzo_method method;
+ unsigned char level;
+ lzo_voidp work_buffer;
+ lzo_uint32 work_buffer_size;
+ char header_written;
+#else
+ struct archive_write_program_data *pdata;
+#endif
+};
+
+static int archive_write_lzop_open(struct archive_write_filter *);
+static int archive_write_lzop_options(struct archive_write_filter *,
+ const char *, const char *);
+static int archive_write_lzop_write(struct archive_write_filter *,
+ const void *, size_t);
+static int archive_write_lzop_close(struct archive_write_filter *);
+static int archive_write_lzop_free(struct archive_write_filter *);
+
+#if defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
+/* Maximum block size. */
+#define BLOCK_SIZE (256 * 1024)
+/* Block information is composed of uncompressed size(4 bytes),
+ * compressed size(4 bytes) and the checksum of uncompressed data(4 bytes)
+ * in this lzop writer. */
+#define BLOCK_INfO_SIZE 12
+
+#define HEADER_VERSION 9
+#define HEADER_LIBVERSION 11
+#define HEADER_METHOD 15
+#define HEADER_LEVEL 16
+#define HEADER_MTIME_LOW 25
+#define HEADER_MTIME_HIGH 29
+#define HEADER_H_CHECKSUM 34
+
+/*
+ * Header template.
+ */
+static const unsigned char header[] = {
+ /* LZOP Magic code 9 bytes */
+ 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a,
+ /* LZOP utility version(fake data) 2 bytes */
+ 0x10, 0x30,
+ /* LZO library version 2 bytes */
+ 0x09, 0x40,
+ /* Minimum required LZO library version 2 bytes */
+ 0x09, 0x40,
+ /* Method */
+ 1,
+ /* Level */
+ 5,
+ /* Flags 4 bytes
+ * -OS Unix
+ * -Stdout
+ * -Stdin
+ * -Adler32 used for uncompressed data 4 bytes */
+ 0x03, 0x00, 0x00, 0x0d,
+ /* Mode (AE_IFREG | 0644) 4 bytes */
+ 0x00, 0x00, 0x81, 0xa4,
+ /* Mtime low 4 bytes */
+ 0x00, 0x00, 0x00, 0x00,
+ /* Mtime high 4 bytes */
+ 0x00, 0x00, 0x00, 0x00,
+ /* Filename length */
+ 0x00,
+ /* Header checksum 4 bytes */
+ 0x00, 0x00, 0x00, 0x00,
+};
+#endif
+
+int
+archive_write_add_filter_lzop(struct archive *_a)
+{
+ struct archive_write_filter *f = __archive_write_allocate_filter(_a);
+ struct write_lzop *data;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_lzop");
+
+ data = calloc(1, sizeof(*data));
+ if (data == NULL) {
+ archive_set_error(_a, ENOMEM, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ f->name = "lzop";
+ f->code = ARCHIVE_FILTER_LZOP;
+ f->data = data;
+ f->open = archive_write_lzop_open;
+ f->options = archive_write_lzop_options;
+ f->write = archive_write_lzop_write;
+ f->close = archive_write_lzop_close;
+ f->free = archive_write_lzop_free;
+#if defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
+ if (lzo_init() != LZO_E_OK) {
+ free(data);
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "lzo_init(type check) failed");
+ return (ARCHIVE_FATAL);
+ }
+ if (lzo_version() < 0x940) {
+ free(data);
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "liblzo library is too old(%s < 0.940)",
+ lzo_version_string());
+ return (ARCHIVE_FATAL);
+ }
+ data->compression_level = 5;
+ return (ARCHIVE_OK);
+#else
+ data->pdata = __archive_write_program_allocate();
+ if (data->pdata == NULL) {
+ free(data);
+ archive_set_error(_a, ENOMEM, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ data->compression_level = 0;
+ /* Note: We return "warn" to inform of using an external lzop
+ * program. */
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+ "Using external lzop program for lzop compression");
+ return (ARCHIVE_WARN);
+#endif
+}
+
+static int
+archive_write_lzop_free(struct archive_write_filter *f)
+{
+ struct write_lzop *data = (struct write_lzop *)f->data;
+
+#if defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
+ free(data->uncompressed);
+ free(data->compressed);
+ free(data->work_buffer);
+#else
+ __archive_write_program_free(data->pdata);
+#endif
+ free(data);
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_lzop_options(struct archive_write_filter *f, const char *key,
+ const char *value)
+{
+ struct write_lzop *data = (struct write_lzop *)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);
+ }
+ /* 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_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
+static int
+archive_write_lzop_open(struct archive_write_filter *f)
+{
+ struct write_lzop *data = (struct write_lzop *)f->data;
+ int ret;
+
+ ret = __archive_write_open_filter(f->next_filter);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ switch (data->compression_level) {
+ case 1:
+ data->method = METHOD_LZO1X_1_15; data->level = 1; break;
+ default:
+ case 2: case 3: case 4: case 5: case 6:
+ data->method = METHOD_LZO1X_1; data->level = 5; break;
+ case 7:
+ data->method = METHOD_LZO1X_999; data->level = 7; break;
+ case 8:
+ data->method = METHOD_LZO1X_999; data->level = 8; break;
+ case 9:
+ data->method = METHOD_LZO1X_999; data->level = 9; break;
+ }
+ switch (data->method) {
+ case METHOD_LZO1X_1:
+ data->work_buffer_size = LZO1X_1_MEM_COMPRESS; break;
+ case METHOD_LZO1X_1_15:
+ data->work_buffer_size = LZO1X_1_15_MEM_COMPRESS; break;
+ case METHOD_LZO1X_999:
+ data->work_buffer_size = LZO1X_999_MEM_COMPRESS; break;
+ }
+ if (data->work_buffer == NULL) {
+ data->work_buffer = (lzo_voidp)malloc(data->work_buffer_size);
+ if (data->work_buffer == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for compression buffer");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ if (data->compressed == NULL) {
+ data->compressed_buffer_size = sizeof(header) +
+ BLOCK_SIZE + (BLOCK_SIZE >> 4) + 64 + 3;
+ data->compressed = (unsigned char *)
+ malloc(data->compressed_buffer_size);
+ if (data->compressed == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for compression buffer");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ if (data->uncompressed == NULL) {
+ data->uncompressed_buffer_size = BLOCK_SIZE;
+ data->uncompressed = (unsigned char *)
+ malloc(data->uncompressed_buffer_size);
+ if (data->uncompressed == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for compression buffer");
+ return (ARCHIVE_FATAL);
+ }
+ data->uncompressed_avail_bytes = BLOCK_SIZE;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+make_header(struct archive_write_filter *f)
+{
+ struct write_lzop *data = (struct write_lzop *)f->data;
+ int64_t t;
+ uint32_t checksum;
+
+ memcpy(data->compressed, header, sizeof(header));
+ /* Overwrite library version. */
+ data->compressed[HEADER_LIBVERSION] = (unsigned char )
+ (lzo_version() >> 8) & 0xff;
+ data->compressed[HEADER_LIBVERSION + 1] = (unsigned char )
+ lzo_version() & 0xff;
+ /* Overwrite method and level. */
+ data->compressed[HEADER_METHOD] = (unsigned char)data->method;
+ data->compressed[HEADER_LEVEL] = data->level;
+ /* Overwrite mtime with current time. */
+ t = (int64_t)time(NULL);
+ archive_be32enc(&data->compressed[HEADER_MTIME_LOW],
+ (uint32_t)(t & 0xffffffff));
+ archive_be32enc(&data->compressed[HEADER_MTIME_HIGH],
+ (uint32_t)((t >> 32) & 0xffffffff));
+ /* Overwrite header checksum with calculated value. */
+ checksum = lzo_adler32(1, data->compressed + HEADER_VERSION,
+ (lzo_uint)(HEADER_H_CHECKSUM - HEADER_VERSION));
+ archive_be32enc(&data->compressed[HEADER_H_CHECKSUM], checksum);
+ return (sizeof(header));
+}
+
+static int
+drive_compressor(struct archive_write_filter *f)
+{
+ struct write_lzop *data = (struct write_lzop *)f->data;
+ unsigned char *p;
+ const int block_info_bytes = 12;
+ int header_bytes, r;
+ lzo_uint usize, csize;
+ uint32_t checksum;
+
+ if (!data->header_written) {
+ header_bytes = make_header(f);
+ data->header_written = 1;
+ } else
+ header_bytes = 0;
+ p = data->compressed;
+
+ usize = (lzo_uint)
+ (data->uncompressed_buffer_size - data->uncompressed_avail_bytes);
+ csize = 0;
+ switch (data->method) {
+ default:
+ case METHOD_LZO1X_1:
+ r = lzo1x_1_compress(data->uncompressed, usize,
+ p + header_bytes + block_info_bytes, &csize,
+ data->work_buffer);
+ break;
+ case METHOD_LZO1X_1_15:
+ r = lzo1x_1_15_compress(data->uncompressed, usize,
+ p + header_bytes + block_info_bytes, &csize,
+ data->work_buffer);
+ break;
+ case METHOD_LZO1X_999:
+ r = lzo1x_999_compress_level(data->uncompressed, usize,
+ p + header_bytes + block_info_bytes, &csize,
+ data->work_buffer, NULL, 0, 0, data->level);
+ break;
+ }
+ if (r != LZO_E_OK) {
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "Lzop compression failed: returned status %d", r);
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Store uncompressed size. */
+ archive_be32enc(p + header_bytes, (uint32_t)usize);
+ /* Store the checksum of the uncompressed data. */
+ checksum = lzo_adler32(1, data->uncompressed, usize);
+ archive_be32enc(p + header_bytes + 8, checksum);
+
+ if (csize < usize) {
+ /* Store compressed size. */
+ archive_be32enc(p + header_bytes + 4, (uint32_t)csize);
+ r = __archive_write_filter(f->next_filter, data->compressed,
+ header_bytes + block_info_bytes + csize);
+ } else {
+ /*
+ * This case, we output uncompressed data instead.
+ */
+ /* Store uncompressed size as compressed size. */
+ archive_be32enc(p + header_bytes + 4, (uint32_t)usize);
+ r = __archive_write_filter(f->next_filter, data->compressed,
+ header_bytes + block_info_bytes);
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ r = __archive_write_filter(f->next_filter, data->uncompressed,
+ usize);
+ }
+
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_lzop_write(struct archive_write_filter *f,
+ const void *buff, size_t length)
+{
+ struct write_lzop *data = (struct write_lzop *)f->data;
+ const char *p = buff;
+ int r;
+
+ do {
+ if (data->uncompressed_avail_bytes > length) {
+ memcpy(data->uncompressed
+ + data->uncompressed_buffer_size
+ - data->uncompressed_avail_bytes,
+ p, length);
+ data->uncompressed_avail_bytes -= length;
+ return (ARCHIVE_OK);
+ }
+
+ memcpy(data->uncompressed + data->uncompressed_buffer_size
+ - data->uncompressed_avail_bytes,
+ p, data->uncompressed_avail_bytes);
+ length -= data->uncompressed_avail_bytes;
+ p += data->uncompressed_avail_bytes;
+ data->uncompressed_avail_bytes = 0;
+
+ r = drive_compressor(f);
+ if (r != ARCHIVE_OK) return (r);
+ data->uncompressed_avail_bytes = BLOCK_SIZE;
+ } while (length);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_lzop_close(struct archive_write_filter *f)
+{
+ struct write_lzop *data = (struct write_lzop *)f->data;
+ const uint32_t endmark = 0;
+ int r;
+
+ if (data->uncompressed_avail_bytes < BLOCK_SIZE) {
+ /* Compress and output remaining data. */
+ r = drive_compressor(f);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+ /* Write a zero uncompressed size as the end mark of the series of
+ * compressed block. */
+ r = __archive_write_filter(f->next_filter, &endmark, sizeof(endmark));
+ if (r != ARCHIVE_OK)
+ return (r);
+ return (__archive_write_close_filter(f->next_filter));
+}
+
+#else
+static int
+archive_write_lzop_open(struct archive_write_filter *f)
+{
+ struct write_lzop *data = (struct write_lzop *)f->data;
+ struct archive_string as;
+ int r;
+
+ archive_string_init(&as);
+ archive_strcpy(&as, "lzop");
+ /* Specify compression level. */
+ if (data->compression_level > 0) {
+ archive_strappend_char(&as, ' ');
+ archive_strappend_char(&as, '-');
+ archive_strappend_char(&as, '0' + data->compression_level);
+ }
+
+ r = __archive_write_program_open(f, data->pdata, as.s);
+ archive_string_free(&as);
+ return (r);
+}
+
+static int
+archive_write_lzop_write(struct archive_write_filter *f,
+ const void *buff, size_t length)
+{
+ struct write_lzop *data = (struct write_lzop *)f->data;
+
+ return __archive_write_program_write(f, data->pdata, buff, length);
+}
+
+static int
+archive_write_lzop_close(struct archive_write_filter *f)
+{
+ struct write_lzop *data = (struct write_lzop *)f->data;
+
+ return __archive_write_program_close(f, data->pdata);
+}
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_none.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_none.c
new file mode 100644
index 0000000000..3c06c642e7
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_none.c
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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_compression_none.c 201080 2009-12-28 02:03:54Z kientzle $");
+
+#include "archive.h"
+
+int
+archive_write_set_compression_none(struct archive *a)
+{
+ (void)a; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+int
+archive_write_add_filter_none(struct archive *a)
+{
+ (void)a; /* UNUSED */
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c
new file mode 100644
index 0000000000..fc232da0cb
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c
@@ -0,0 +1,412 @@
+/*-
+ * Copyright (c) 2007 Joerg Sonnenberger
+ * Copyright (c) 2012 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: head/lib/libarchive/archive_write_set_compression_program.c 201104 2009-12-28 03:14:30Z kientzle $");
+
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+#ifdef HAVE_ERRNO_H
+# include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_string.h"
+#include "archive_write_private.h"
+#include "filter_fork.h"
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+int
+archive_write_set_compression_program(struct archive *a, const char *cmd)
+{
+ __archive_write_filters_free(a);
+ return (archive_write_add_filter_program(a, cmd));
+}
+#endif
+
+struct archive_write_program_data {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ HANDLE child;
+#else
+ pid_t child;
+#endif
+ int child_stdin, child_stdout;
+
+ char *child_buf;
+ size_t child_buf_len, child_buf_avail;
+};
+
+struct private_data {
+ struct archive_write_program_data *pdata;
+ struct archive_string description;
+ char *cmd;
+};
+
+static int archive_compressor_program_open(struct archive_write_filter *);
+static int archive_compressor_program_write(struct archive_write_filter *,
+ const void *, size_t);
+static int archive_compressor_program_close(struct archive_write_filter *);
+static int archive_compressor_program_free(struct archive_write_filter *);
+
+/*
+ * Add a filter to this write handle that passes all data through an
+ * external program.
+ */
+int
+archive_write_add_filter_program(struct archive *_a, const char *cmd)
+{
+ struct archive_write_filter *f = __archive_write_allocate_filter(_a);
+ struct private_data *data;
+ static const char *prefix = "Program: ";
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_program");
+
+ f->data = calloc(1, sizeof(*data));
+ if (f->data == NULL)
+ goto memerr;
+ data = (struct private_data *)f->data;
+
+ data->cmd = strdup(cmd);
+ if (data->cmd == NULL)
+ goto memerr;
+
+ data->pdata = __archive_write_program_allocate();
+ if (data->pdata == NULL)
+ goto memerr;
+
+ /* Make up a description string. */
+ if (archive_string_ensure(&data->description,
+ strlen(prefix) + strlen(cmd) + 1) == NULL)
+ goto memerr;
+ archive_strcpy(&data->description, prefix);
+ archive_strcat(&data->description, cmd);
+
+ f->name = data->description.s;
+ f->code = ARCHIVE_FILTER_PROGRAM;
+ f->open = archive_compressor_program_open;
+ f->write = archive_compressor_program_write;
+ f->close = archive_compressor_program_close;
+ f->free = archive_compressor_program_free;
+ return (ARCHIVE_OK);
+memerr:
+ archive_compressor_program_free(f);
+ archive_set_error(_a, ENOMEM,
+ "Can't allocate memory for filter program");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+archive_compressor_program_open(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+
+ return __archive_write_program_open(f, data->pdata, data->cmd);
+}
+
+static int
+archive_compressor_program_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_compressor_program_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_compressor_program_free(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+
+ if (data) {
+ free(data->cmd);
+ archive_string_free(&data->description);
+ __archive_write_program_free(data->pdata);
+ free(data);
+ f->data = NULL;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Allocate resources for executing an external program.
+ */
+struct archive_write_program_data *
+__archive_write_program_allocate(void)
+{
+ struct archive_write_program_data *data;
+
+ data = calloc(1, sizeof(struct archive_write_program_data));
+ if (data == NULL)
+ return (data);
+ data->child_stdin = -1;
+ data->child_stdout = -1;
+ return (data);
+}
+
+/*
+ * Release the resources.
+ */
+int
+__archive_write_program_free(struct archive_write_program_data *data)
+{
+
+ if (data) {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (data->child)
+ CloseHandle(data->child);
+#endif
+ free(data->child_buf);
+ free(data);
+ }
+ return (ARCHIVE_OK);
+}
+
+int
+__archive_write_program_open(struct archive_write_filter *f,
+ struct archive_write_program_data *data, const char *cmd)
+{
+ pid_t child;
+ int ret;
+
+ ret = __archive_write_open_filter(f->next_filter);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ if (data->child_buf == NULL) {
+ data->child_buf_len = 65536;
+ data->child_buf_avail = 0;
+ data->child_buf = malloc(data->child_buf_len);
+
+ if (data->child_buf == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate compression buffer");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ child = __archive_create_child(cmd, &data->child_stdin,
+ &data->child_stdout);
+ if (child == -1) {
+ archive_set_error(f->archive, EINVAL,
+ "Can't initialise filter");
+ return (ARCHIVE_FATAL);
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ data->child = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, child);
+ if (data->child == NULL) {
+ close(data->child_stdin);
+ data->child_stdin = -1;
+ close(data->child_stdout);
+ data->child_stdout = -1;
+ archive_set_error(f->archive, EINVAL,
+ "Can't initialise filter");
+ return (ARCHIVE_FATAL);
+ }
+#else
+ data->child = child;
+#endif
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+child_write(struct archive_write_filter *f,
+ struct archive_write_program_data *data, const char *buf, size_t buf_len)
+{
+ ssize_t ret;
+
+ if (data->child_stdin == -1)
+ return (-1);
+
+ if (buf_len == 0)
+ return (-1);
+
+ for (;;) {
+ do {
+ ret = write(data->child_stdin, buf, buf_len);
+ } while (ret == -1 && errno == EINTR);
+
+ if (ret > 0)
+ return (ret);
+ if (ret == 0) {
+ close(data->child_stdin);
+ data->child_stdin = -1;
+ fcntl(data->child_stdout, F_SETFL, 0);
+ return (0);
+ }
+ if (ret == -1 && errno != EAGAIN)
+ return (-1);
+
+ if (data->child_stdout == -1) {
+ fcntl(data->child_stdin, F_SETFL, 0);
+ __archive_check_child(data->child_stdin,
+ data->child_stdout);
+ continue;
+ }
+
+ do {
+ ret = read(data->child_stdout,
+ data->child_buf + data->child_buf_avail,
+ data->child_buf_len - data->child_buf_avail);
+ } while (ret == -1 && errno == EINTR);
+
+ if (ret == 0 || (ret == -1 && errno == EPIPE)) {
+ close(data->child_stdout);
+ data->child_stdout = -1;
+ fcntl(data->child_stdin, F_SETFL, 0);
+ continue;
+ }
+ if (ret == -1 && errno == EAGAIN) {
+ __archive_check_child(data->child_stdin,
+ data->child_stdout);
+ continue;
+ }
+ if (ret == -1)
+ return (-1);
+
+ data->child_buf_avail += ret;
+
+ ret = __archive_write_filter(f->next_filter,
+ data->child_buf, data->child_buf_avail);
+ if (ret != ARCHIVE_OK)
+ return (-1);
+ data->child_buf_avail = 0;
+ }
+}
+
+/*
+ * Write data to the filter stream.
+ */
+int
+__archive_write_program_write(struct archive_write_filter *f,
+ struct archive_write_program_data *data, const void *buff, size_t length)
+{
+ ssize_t ret;
+ const char *buf;
+
+ if (data->child == 0)
+ return (ARCHIVE_OK);
+
+ buf = buff;
+ while (length > 0) {
+ ret = child_write(f, data, buf, length);
+ if (ret == -1 || ret == 0) {
+ archive_set_error(f->archive, EIO,
+ "Can't write to filter");
+ return (ARCHIVE_FATAL);
+ }
+ length -= ret;
+ buf += ret;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Finish the filtering...
+ */
+int
+__archive_write_program_close(struct archive_write_filter *f,
+ struct archive_write_program_data *data)
+{
+ int ret, r1, status;
+ ssize_t bytes_read;
+
+ if (data->child == 0)
+ return __archive_write_close_filter(f->next_filter);
+
+ ret = 0;
+ close(data->child_stdin);
+ data->child_stdin = -1;
+ fcntl(data->child_stdout, F_SETFL, 0);
+
+ for (;;) {
+ do {
+ bytes_read = read(data->child_stdout,
+ data->child_buf + data->child_buf_avail,
+ data->child_buf_len - data->child_buf_avail);
+ } while (bytes_read == -1 && errno == EINTR);
+
+ if (bytes_read == 0 || (bytes_read == -1 && errno == EPIPE))
+ break;
+
+ if (bytes_read == -1) {
+ archive_set_error(f->archive, errno,
+ "Read from filter failed unexpectedly.");
+ ret = ARCHIVE_FATAL;
+ goto cleanup;
+ }
+ data->child_buf_avail += bytes_read;
+
+ ret = __archive_write_filter(f->next_filter,
+ data->child_buf, data->child_buf_avail);
+ if (ret != ARCHIVE_OK) {
+ ret = ARCHIVE_FATAL;
+ goto cleanup;
+ }
+ data->child_buf_avail = 0;
+ }
+
+cleanup:
+ /* Shut down the child. */
+ if (data->child_stdin != -1)
+ close(data->child_stdin);
+ if (data->child_stdout != -1)
+ close(data->child_stdout);
+ while (waitpid(data->child, &status, 0) == -1 && errno == EINTR)
+ continue;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ CloseHandle(data->child);
+#endif
+ data->child = 0;
+
+ if (status != 0) {
+ archive_set_error(f->archive, EIO,
+ "Filter exited with failure.");
+ ret = ARCHIVE_FATAL;
+ }
+ r1 = __archive_write_close_filter(f->next_filter);
+ return (r1 < ret ? r1 : ret);
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_uuencode.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_uuencode.c
new file mode 100644
index 0000000000..23d9c150d1
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_uuencode.c
@@ -0,0 +1,305 @@
+/*-
+ * Copyright (c) 2012 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
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_string.h"
+#include "archive_write_private.h"
+
+#define LBYTES 45
+
+struct private_uuencode {
+ int mode;
+ struct archive_string name;
+ struct archive_string encoded_buff;
+ size_t bs;
+ size_t hold_len;
+ unsigned char hold[LBYTES];
+};
+
+static int archive_filter_uuencode_options(struct archive_write_filter *,
+ const char *, const char *);
+static int archive_filter_uuencode_open(struct archive_write_filter *);
+static int archive_filter_uuencode_write(struct archive_write_filter *,
+ const void *, size_t);
+static int archive_filter_uuencode_close(struct archive_write_filter *);
+static int archive_filter_uuencode_free(struct archive_write_filter *);
+static void uu_encode(struct archive_string *, const unsigned char *, size_t);
+static int64_t atol8(const char *, size_t);
+
+/*
+ * Add a compress filter to this write handle.
+ */
+int
+archive_write_add_filter_uuencode(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct archive_write_filter *f = __archive_write_allocate_filter(_a);
+ struct private_uuencode *state;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_uu");
+
+ state = (struct private_uuencode *)calloc(1, sizeof(*state));
+ if (state == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for uuencode filter");
+ return (ARCHIVE_FATAL);
+ }
+ archive_strcpy(&state->name, "-");
+ state->mode = 0644;
+
+ f->data = state;
+ f->name = "uuencode";
+ f->code = ARCHIVE_FILTER_UU;
+ f->open = archive_filter_uuencode_open;
+ f->options = archive_filter_uuencode_options;
+ f->write = archive_filter_uuencode_write;
+ f->close = archive_filter_uuencode_close;
+ f->free = archive_filter_uuencode_free;
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Set write options.
+ */
+static int
+archive_filter_uuencode_options(struct archive_write_filter *f, const char *key,
+ const char *value)
+{
+ struct private_uuencode *state = (struct private_uuencode *)f->data;
+
+ if (strcmp(key, "mode") == 0) {
+ if (value == NULL) {
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "mode option requires octal digits");
+ return (ARCHIVE_FAILED);
+ }
+ state->mode = (int)atol8(value, strlen(value)) & 0777;
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "name") == 0) {
+ if (value == NULL) {
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "name option requires a string");
+ return (ARCHIVE_FAILED);
+ }
+ archive_strcpy(&state->name, value);
+ 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);
+}
+
+/*
+ * Setup callback.
+ */
+static int
+archive_filter_uuencode_open(struct archive_write_filter *f)
+{
+ struct private_uuencode *state = (struct private_uuencode *)f->data;
+ size_t bs = 65536, bpb;
+ int ret;
+
+ ret = __archive_write_open_filter(f->next_filter);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ 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 -= bs % bpb;
+ }
+
+ state->bs = bs;
+ if (archive_string_ensure(&state->encoded_buff, bs + 512) == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for uuencode buffer");
+ return (ARCHIVE_FATAL);
+ }
+
+ archive_string_sprintf(&state->encoded_buff, "begin %o %s\n",
+ state->mode, state->name.s);
+
+ f->data = state;
+ return (0);
+}
+
+static void
+uu_encode(struct archive_string *as, const unsigned char *p, size_t len)
+{
+ int c;
+
+ c = (int)len;
+ archive_strappend_char(as, c?c + 0x20:'`');
+ for (; len >= 3; p += 3, len -= 3) {
+ c = p[0] >> 2;
+ archive_strappend_char(as, c?c + 0x20:'`');
+ c = ((p[0] & 0x03) << 4) | ((p[1] & 0xf0) >> 4);
+ archive_strappend_char(as, c?c + 0x20:'`');
+ c = ((p[1] & 0x0f) << 2) | ((p[2] & 0xc0) >> 6);
+ archive_strappend_char(as, c?c + 0x20:'`');
+ c = p[2] & 0x3f;
+ archive_strappend_char(as, c?c + 0x20:'`');
+ }
+ if (len > 0) {
+ c = p[0] >> 2;
+ archive_strappend_char(as, c?c + 0x20:'`');
+ c = (p[0] & 0x03) << 4;
+ if (len == 1) {
+ archive_strappend_char(as, c?c + 0x20:'`');
+ archive_strappend_char(as, '`');
+ archive_strappend_char(as, '`');
+ } else {
+ c |= (p[1] & 0xf0) >> 4;
+ archive_strappend_char(as, c?c + 0x20:'`');
+ c = (p[1] & 0x0f) << 2;
+ archive_strappend_char(as, c?c + 0x20:'`');
+ archive_strappend_char(as, '`');
+ }
+ }
+ archive_strappend_char(as, '\n');
+}
+
+/*
+ * Write data to the encoded stream.
+ */
+static int
+archive_filter_uuencode_write(struct archive_write_filter *f, const void *buff,
+ size_t length)
+{
+ struct private_uuencode *state = (struct private_uuencode *)f->data;
+ const unsigned char *p = buff;
+ int ret = ARCHIVE_OK;
+
+ if (length == 0)
+ return (ret);
+
+ if (state->hold_len) {
+ while (state->hold_len < LBYTES && length > 0) {
+ state->hold[state->hold_len++] = *p++;
+ length--;
+ }
+ if (state->hold_len < LBYTES)
+ return (ret);
+ uu_encode(&state->encoded_buff, state->hold, LBYTES);
+ state->hold_len = 0;
+ }
+
+ for (; length >= LBYTES; length -= LBYTES, p += LBYTES)
+ uu_encode(&state->encoded_buff, p, LBYTES);
+
+ /* Save remaining bytes. */
+ if (length > 0) {
+ memcpy(state->hold, p, length);
+ state->hold_len = length;
+ }
+ while (archive_strlen(&state->encoded_buff) >= state->bs) {
+ ret = __archive_write_filter(f->next_filter,
+ state->encoded_buff.s, state->bs);
+ memmove(state->encoded_buff.s,
+ state->encoded_buff.s + state->bs,
+ state->encoded_buff.length - state->bs);
+ state->encoded_buff.length -= state->bs;
+ }
+
+ return (ret);
+}
+
+
+/*
+ * Finish the compression...
+ */
+static int
+archive_filter_uuencode_close(struct archive_write_filter *f)
+{
+ struct private_uuencode *state = (struct private_uuencode *)f->data;
+ int ret, ret2;
+
+ /* Flush remaining bytes. */
+ if (state->hold_len != 0)
+ uu_encode(&state->encoded_buff, state->hold, state->hold_len);
+ archive_string_sprintf(&state->encoded_buff, "`\nend\n");
+ /* Write the last block */
+ archive_write_set_bytes_in_last_block(f->archive, 1);
+ ret = __archive_write_filter(f->next_filter,
+ state->encoded_buff.s, archive_strlen(&state->encoded_buff));
+ ret2 = __archive_write_close_filter(f->next_filter);
+ if (ret > ret2)
+ ret = ret2;
+ return (ret);
+}
+
+static int
+archive_filter_uuencode_free(struct archive_write_filter *f)
+{
+ struct private_uuencode *state = (struct private_uuencode *)f->data;
+
+ archive_string_free(&state->name);
+ archive_string_free(&state->encoded_buff);
+ free(state);
+ return (ARCHIVE_OK);
+}
+
+static int64_t
+atol8(const char *p, size_t char_cnt)
+{
+ int64_t l;
+ int digit;
+
+ l = 0;
+ while (char_cnt-- > 0) {
+ if (*p >= '0' && *p <= '7')
+ digit = *p - '0';
+ else
+ break;
+ p++;
+ l <<= 3;
+ l |= digit;
+ }
+ return (l);
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c
new file mode 100644
index 0000000000..a56673272e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c
@@ -0,0 +1,515 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * Copyright (c) 2009-2012 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: head/lib/libarchive/archive_write_set_compression_xz.c 201108 2009-12-28 03:28:21Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <time.h>
+#ifdef HAVE_LZMA_H
+#include <cm_lzma.h>
+#endif
+
+#include "archive.h"
+#include "archive_endian.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+#if ARCHIVE_VERSION_NUMBER < 4000000
+int
+archive_write_set_compression_lzip(struct archive *a)
+{
+ __archive_write_filters_free(a);
+ return (archive_write_add_filter_lzip(a));
+}
+
+int
+archive_write_set_compression_lzma(struct archive *a)
+{
+ __archive_write_filters_free(a);
+ return (archive_write_add_filter_lzma(a));
+}
+
+int
+archive_write_set_compression_xz(struct archive *a)
+{
+ __archive_write_filters_free(a);
+ return (archive_write_add_filter_xz(a));
+}
+
+#endif
+
+#ifndef HAVE_LZMA_H
+int
+archive_write_add_filter_xz(struct archive *a)
+{
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "xz compression not supported on this platform");
+ return (ARCHIVE_FATAL);
+}
+
+int
+archive_write_add_filter_lzma(struct archive *a)
+{
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "lzma compression not supported on this platform");
+ return (ARCHIVE_FATAL);
+}
+
+int
+archive_write_add_filter_lzip(struct archive *a)
+{
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "lzma compression not supported on this platform");
+ return (ARCHIVE_FATAL);
+}
+#else
+/* Don't compile this if we don't have liblzma. */
+
+struct private_data {
+ int compression_level;
+ lzma_stream stream;
+ lzma_filter lzmafilters[2];
+ lzma_options_lzma lzma_opt;
+ int64_t total_in;
+ unsigned char *compressed;
+ size_t compressed_buffer_size;
+ int64_t total_out;
+ /* the CRC32 value of uncompressed data for lzip */
+ uint32_t crc32;
+};
+
+static int archive_compressor_xz_options(struct archive_write_filter *,
+ const char *, const char *);
+static int archive_compressor_xz_open(struct archive_write_filter *);
+static int archive_compressor_xz_write(struct archive_write_filter *,
+ const void *, size_t);
+static int archive_compressor_xz_close(struct archive_write_filter *);
+static int archive_compressor_xz_free(struct archive_write_filter *);
+static int drive_compressor(struct archive_write_filter *,
+ struct private_data *, int finishing);
+
+struct option_value {
+ uint32_t dict_size;
+ uint32_t nice_len;
+ lzma_match_finder mf;
+};
+static const struct option_value option_values[] = {
+ { 1 << 16, 32, LZMA_MF_HC3},
+ { 1 << 20, 32, LZMA_MF_HC3},
+ { 3 << 19, 32, LZMA_MF_HC4},
+ { 1 << 21, 32, LZMA_MF_BT4},
+ { 3 << 20, 32, LZMA_MF_BT4},
+ { 1 << 22, 32, LZMA_MF_BT4},
+ { 1 << 23, 64, LZMA_MF_BT4},
+ { 1 << 24, 64, LZMA_MF_BT4},
+ { 3 << 23, 64, LZMA_MF_BT4},
+ { 1 << 25, 64, LZMA_MF_BT4}
+};
+
+static int
+common_setup(struct archive_write_filter *f)
+{
+ struct private_data *data;
+ struct archive_write *a = (struct archive_write *)f->archive;
+ data = calloc(1, sizeof(*data));
+ if (data == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+ f->data = data;
+ data->compression_level = LZMA_PRESET_DEFAULT;
+ f->open = &archive_compressor_xz_open;
+ f->close = archive_compressor_xz_close;
+ f->free = archive_compressor_xz_free;
+ f->options = &archive_compressor_xz_options;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Add an xz compression filter to this write handle.
+ */
+int
+archive_write_add_filter_xz(struct archive *_a)
+{
+ struct archive_write_filter *f;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_xz");
+ f = __archive_write_allocate_filter(_a);
+ r = common_setup(f);
+ if (r == ARCHIVE_OK) {
+ f->code = ARCHIVE_FILTER_XZ;
+ f->name = "xz";
+ }
+ return (r);
+}
+
+/* LZMA is handled identically, we just need a different compression
+ * code set. (The liblzma setup looks at the code to determine
+ * the one place that XZ and LZMA require different handling.) */
+int
+archive_write_add_filter_lzma(struct archive *_a)
+{
+ struct archive_write_filter *f;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_lzma");
+ f = __archive_write_allocate_filter(_a);
+ r = common_setup(f);
+ if (r == ARCHIVE_OK) {
+ f->code = ARCHIVE_FILTER_LZMA;
+ f->name = "lzma";
+ }
+ return (r);
+}
+
+int
+archive_write_add_filter_lzip(struct archive *_a)
+{
+ struct archive_write_filter *f;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_add_filter_lzip");
+ f = __archive_write_allocate_filter(_a);
+ r = common_setup(f);
+ if (r == ARCHIVE_OK) {
+ f->code = ARCHIVE_FILTER_LZIP;
+ f->name = "lzip";
+ }
+ return (r);
+}
+
+static int
+archive_compressor_xz_init_stream(struct archive_write_filter *f,
+ struct private_data *data)
+{
+ static const lzma_stream lzma_stream_init_data = LZMA_STREAM_INIT;
+ int ret;
+
+ 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)
+ ret = lzma_alone_encoder(&(data->stream), &data->lzma_opt);
+ 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",
+ dict_size);
+ return (ARCHIVE_FATAL);
+ }
+ for (log2dic = 27; log2dic >= 12; log2dic--) {
+ if (dict_size & (1 << log2dic))
+ break;
+ }
+ if (dict_size > (1 << log2dic)) {
+ log2dic++;
+ wedges =
+ ((1 << log2dic) - dict_size) / (1 << (log2dic - 4));
+ } else
+ wedges = 0;
+ ds = ((wedges << 5) & 0xe0) | (log2dic & 0x1f);
+
+ data->crc32 = 0;
+ /* Make a header */
+ data->compressed[0] = 0x4C;
+ data->compressed[1] = 0x5A;
+ data->compressed[2] = 0x49;
+ data->compressed[3] = 0x50;
+ data->compressed[4] = 1;/* Version */
+ data->compressed[5] = (unsigned char)ds;
+ data->stream.next_out += 6;
+ data->stream.avail_out -= 6;
+
+ ret = lzma_raw_encoder(&(data->stream), data->lzmafilters);
+ }
+ if (ret == LZMA_OK)
+ return (ARCHIVE_OK);
+
+ switch (ret) {
+ case LZMA_MEM_ERROR:
+ archive_set_error(f->archive, ENOMEM,
+ "Internal error initializing compression library: "
+ "Cannot allocate memory");
+ break;
+ default:
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ "It's a bug in liblzma");
+ break;
+ }
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Setup callback.
+ */
+static int
+archive_compressor_xz_open(struct archive_write_filter *f)
+{
+ struct private_data *data = f->data;
+ int ret;
+
+ ret = __archive_write_open_filter(f->next_filter);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ if (data->compressed == NULL) {
+ size_t bs = 65536, bpb;
+ 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 -= bs % bpb;
+ }
+ data->compressed_buffer_size = bs;
+ data->compressed
+ = (unsigned char *)malloc(data->compressed_buffer_size);
+ if (data->compressed == NULL) {
+ archive_set_error(f->archive, ENOMEM,
+ "Can't allocate data for compression buffer");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ f->write = archive_compressor_xz_write;
+
+ /* Initialize compression library. */
+ if (f->code == ARCHIVE_FILTER_LZIP) {
+ const struct option_value *val =
+ &option_values[data->compression_level];
+
+ data->lzma_opt.dict_size = val->dict_size;
+ data->lzma_opt.preset_dict = NULL;
+ data->lzma_opt.preset_dict_size = 0;
+ data->lzma_opt.lc = LZMA_LC_DEFAULT;
+ data->lzma_opt.lp = LZMA_LP_DEFAULT;
+ data->lzma_opt.pb = LZMA_PB_DEFAULT;
+ data->lzma_opt.mode =
+ data->compression_level<= 2? LZMA_MODE_FAST:LZMA_MODE_NORMAL;
+ data->lzma_opt.nice_len = val->nice_len;
+ data->lzma_opt.mf = val->mf;
+ data->lzma_opt.depth = 0;
+ data->lzmafilters[0].id = LZMA_FILTER_LZMA1;
+ data->lzmafilters[0].options = &data->lzma_opt;
+ data->lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */
+ } else {
+ if (lzma_lzma_preset(&data->lzma_opt, data->compression_level)) {
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library");
+ }
+ data->lzmafilters[0].id = LZMA_FILTER_LZMA2;
+ data->lzmafilters[0].options = &data->lzma_opt;
+ data->lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */
+ }
+ ret = archive_compressor_xz_init_stream(f, data);
+ if (ret == LZMA_OK) {
+ f->data = data;
+ return (0);
+ }
+ return (ARCHIVE_FATAL);
+}
+
+/*
+ * Set write options.
+ */
+static int
+archive_compressor_xz_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] >= '0' && value[0] <= '9') ||
+ value[1] != '\0')
+ return (ARCHIVE_WARN);
+ data->compression_level = value[0] - '0';
+ if (data->compression_level > 6)
+ data->compression_level = 6;
+ 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);
+}
+
+/*
+ * Write data to the compressed stream.
+ */
+static int
+archive_compressor_xz_write(struct archive_write_filter *f,
+ const void *buff, size_t length)
+{
+ struct private_data *data = (struct private_data *)f->data;
+ int ret;
+
+ /* Update statistics */
+ data->total_in += length;
+ if (f->code == ARCHIVE_FILTER_LZIP)
+ data->crc32 = lzma_crc32(buff, length, data->crc32);
+
+ /* Compress input data to output buffer */
+ data->stream.next_in = buff;
+ data->stream.avail_in = length;
+ if ((ret = drive_compressor(f, data, 0)) != ARCHIVE_OK)
+ return (ret);
+
+ return (ARCHIVE_OK);
+}
+
+
+/*
+ * Finish the compression...
+ */
+static int
+archive_compressor_xz_close(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+ int ret, r1;
+
+ ret = drive_compressor(f, data, 1);
+ if (ret == ARCHIVE_OK) {
+ data->total_out +=
+ data->compressed_buffer_size - data->stream.avail_out;
+ ret = __archive_write_filter(f->next_filter,
+ data->compressed,
+ data->compressed_buffer_size - data->stream.avail_out);
+ if (f->code == ARCHIVE_FILTER_LZIP && ret == ARCHIVE_OK) {
+ archive_le32enc(data->compressed, data->crc32);
+ archive_le64enc(data->compressed+4, data->total_in);
+ archive_le64enc(data->compressed+12, data->total_out + 20);
+ ret = __archive_write_filter(f->next_filter,
+ data->compressed, 20);
+ }
+ }
+ lzma_end(&(data->stream));
+ r1 = __archive_write_close_filter(f->next_filter);
+ return (r1 < ret ? r1 : ret);
+}
+
+static int
+archive_compressor_xz_free(struct archive_write_filter *f)
+{
+ struct private_data *data = (struct private_data *)f->data;
+ free(data->compressed);
+ free(data);
+ f->data = NULL;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * 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,
+ struct private_data *data, int finishing)
+{
+ int ret;
+
+ for (;;) {
+ if (data->stream.avail_out == 0) {
+ data->total_out += data->compressed_buffer_size;
+ ret = __archive_write_filter(f->next_filter,
+ data->compressed,
+ data->compressed_buffer_size);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ data->stream.next_out = data->compressed;
+ data->stream.avail_out = data->compressed_buffer_size;
+ }
+
+ /* If there's nothing to do, we're done. */
+ if (!finishing && data->stream.avail_in == 0)
+ return (ARCHIVE_OK);
+
+ ret = lzma_code(&(data->stream),
+ finishing ? LZMA_FINISH : LZMA_RUN );
+
+ switch (ret) {
+ case LZMA_OK:
+ /* In non-finishing case, check if compressor
+ * consumed everything */
+ if (!finishing && data->stream.avail_in == 0)
+ return (ARCHIVE_OK);
+ /* In finishing case, this return always means
+ * there's more work */
+ break;
+ case LZMA_STREAM_END:
+ /* This return can only occur in finishing case. */
+ if (finishing)
+ return (ARCHIVE_OK);
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "lzma compression data error");
+ return (ARCHIVE_FATAL);
+ case LZMA_MEMLIMIT_ERROR:
+ archive_set_error(f->archive, ENOMEM,
+ "lzma compression error: "
+ "%ju MiB would have been needed",
+ (uintmax_t)((lzma_memusage(&(data->stream))
+ + 1024 * 1024 -1)
+ / (1024 * 1024)));
+ return (ARCHIVE_FATAL);
+ default:
+ /* Any other return value indicates an error. */
+ archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
+ "lzma compression failed:"
+ " lzma_code() call returned status %d",
+ ret);
+ return (ARCHIVE_FATAL);
+ }
+ }
+}
+
+#endif /* HAVE_LZMA_H */
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_blocksize.3 b/Utilities/cmlibarchive/libarchive/archive_write_blocksize.3
new file mode 100644
index 0000000000..afd84ea4d3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_blocksize.3
@@ -0,0 +1,114 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_BLOCKSIZE 3
+.Os
+.Sh NAME
+.Nm archive_write_get_bytes_per_block ,
+.Nm archive_write_set_bytes_per_block ,
+.Nm archive_write_get_bytes_in_last_block ,
+.Nm archive_write_set_bytes_in_last_block
+.Nd functions for creating archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fn archive_write_get_bytes_per_block "struct archive *"
+.Ft int
+.Fn archive_write_set_bytes_per_block "struct archive *" "int bytes_per_block"
+.Ft int
+.Fn archive_write_get_bytes_in_last_block "struct archive *"
+.Ft int
+.Fn archive_write_set_bytes_in_last_block "struct archive *" "int"
+.Sh DESCRIPTION
+.Bl -tag -width indent
+.It Fn archive_write_set_bytes_per_block
+Sets the block size used for writing the archive data.
+Every call to the write callback function, except possibly the last one, will
+use this value for the length.
+The default is to use a block size of 10240 bytes.
+Note that a block size of zero will suppress internal blocking
+and cause writes to be sent directly to the write callback as they occur.
+.It Fn archive_write_get_bytes_per_block
+Retrieve the block size to be used for writing.
+A value of -1 here indicates that the library should use default values.
+A value of zero indicates that internal blocking is suppressed.
+.It Fn archive_write_set_bytes_in_last_block
+Sets the block size used for writing the last block.
+If this value is zero, the last block will be padded to the same size
+as the other blocks.
+Otherwise, the final block will be padded to a multiple of this size.
+In particular, setting it to 1 will cause the final block to not be padded.
+For compressed output, any padding generated by this option
+is applied only after the compression.
+The uncompressed data is always unpadded.
+The default is to pad the last block to the full block size (note that
+.Fn archive_write_open_filename
+will set this based on the file type).
+Unlike the other
+.Dq set
+functions, this function can be called after the archive is opened.
+.It Fn archive_write_get_bytes_in_last_block
+Retrieve the currently-set value for last block size.
+A value of -1 here indicates that the library should use default values.
+.El
+.\" .Sh EXAMPLE
+.Sh RETURN VALUES
+.Fn archive_write_set_bytes_per_block
+and
+.Fn archive_write_set_bytes_in_last_block
+return
+.Cm ARCHIVE_OK
+on success, or
+.Cm ARCHIVE_FATAL .
+.Pp
+.Fn archive_write_get_bytes_per_block
+and
+.Fn archive_write_get_bytes_in_last_block
+return currently configured block size
+.Po
+.Li -1
+indicates the default block size
+.Pc ,
+or
+.Cm ARCHIVE_FATAL .
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_data.3 b/Utilities/cmlibarchive/libarchive/archive_write_data.3
new file mode 100644
index 0000000000..cfd5cd552d
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_data.3
@@ -0,0 +1,62 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_DATA 3
+.Os
+.Sh NAME
+.Nm archive_write_data
+.Nd functions for creating 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"
+.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.
+.\"
+.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
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk.3 b/Utilities/cmlibarchive/libarchive/archive_write_disk.3
new file mode 100644
index 0000000000..fa925cc543
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk.3
@@ -0,0 +1,403 @@
+.\" Copyright (c) 2003-2007 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_DISK 3
+.Os
+.Sh NAME
+.Nm archive_write_disk_new ,
+.Nm archive_write_disk_set_options ,
+.Nm archive_write_disk_set_skip_file ,
+.Nm archive_write_disk_set_group_lookup ,
+.Nm archive_write_disk_set_standard_lookup ,
+.Nm archive_write_disk_set_user_lookup ,
+.Nm archive_write_header ,
+.Nm archive_write_data ,
+.Nm archive_write_data_block ,
+.Nm archive_write_finish_entry ,
+.Nm archive_write_close ,
+.Nm archive_write_finish
+.Nm archive_write_free
+.Nd functions for creating objects on disk
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft struct archive *
+.Fn archive_write_disk_new "void"
+.Ft int
+.Fn archive_write_disk_set_options "struct archive *" "int flags"
+.Ft int
+.Fn archive_write_disk_set_skip_file "struct archive *" "dev_t" "ino_t"
+.Ft int
+.Fo archive_write_disk_set_group_lookup
+.Fa "struct archive *"
+.Fa "void *"
+.Fa "gid_t (*)(void *, const char *gname, gid_t gid)"
+.Fa "void (*cleanup)(void *)"
+.Fc
+.Ft int
+.Fn archive_write_disk_set_standard_lookup "struct archive *"
+.Ft int
+.Fo archive_write_disk_set_user_lookup
+.Fa "struct archive *"
+.Fa "void *"
+.Fa "uid_t (*)(void *, const char *uname, uid_t uid)"
+.Fa "void (*cleanup)(void *)"
+.Fc
+.Ft int
+.Fn archive_write_header "struct archive *" "struct archive_entry *"
+.Ft ssize_t
+.Fn archive_write_data "struct archive *" "const void *" "size_t"
+.Ft 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 *"
+.Ft int
+.Fn archive_write_close "struct archive *"
+.Ft int
+.Fn archive_write_finish "struct archive *"
+.Ft int
+.Fn archive_write_free "struct archive *"
+.Sh DESCRIPTION
+These functions provide a complete API for creating objects on
+disk from
+.Tn struct archive_entry
+descriptions.
+They are most naturally used when extracting objects from an archive
+using the
+.Fn archive_read
+interface.
+The general process is to read
+.Tn struct archive_entry
+objects from an archive, then write those objects to a
+.Tn struct archive
+object created using the
+.Fn archive_write_disk
+family functions.
+This interface is deliberately very similar to the
+.Fn archive_write
+interface used to write objects to a streaming archive.
+.Bl -tag -width indent
+.It Fn archive_write_disk_new
+Allocates and initializes a
+.Tn struct archive
+object suitable for writing objects to disk.
+.It Fn archive_write_disk_set_skip_file
+Records the device and inode numbers of a file that should not be
+overwritten.
+This is typically used to ensure that an extraction process does not
+overwrite the archive from which objects are being read.
+This capability is technically unnecessary but can be a significant
+performance optimization in practice.
+.It Fn archive_write_disk_set_options
+The options field consists of a bitwise OR of one or more of the
+following values:
+.Bl -tag -compact -width "indent"
+.It Cm ARCHIVE_EXTRACT_OWNER
+The user and group IDs should be set on the restored file.
+By default, the user and group IDs are not restored.
+.It Cm ARCHIVE_EXTRACT_PERM
+Full permissions (including SGID, SUID, and sticky bits) should
+be restored exactly as specified, without obeying the
+current umask.
+Note that SUID and SGID bits can only be restored if the
+user and group ID of the object on disk are correct.
+If
+.Cm ARCHIVE_EXTRACT_OWNER
+is not specified, then SUID and SGID bits will only be restored
+if the default user and group IDs of newly-created objects on disk
+happen to match those specified in the archive entry.
+By default, only basic permissions are restored, and umask is obeyed.
+.It Cm ARCHIVE_EXTRACT_TIME
+The timestamps (mtime, ctime, and atime) should be restored.
+By default, they are ignored.
+Note that restoring of atime is not currently supported.
+.It Cm ARCHIVE_EXTRACT_NO_OVERWRITE
+Existing files on disk will not be overwritten.
+By default, existing regular files are truncated and overwritten;
+existing directories will have their permissions updated;
+other pre-existing objects are unlinked and recreated from scratch.
+.It Cm ARCHIVE_EXTRACT_UNLINK
+Existing files on disk will be unlinked before any attempt to
+create them.
+In some cases, this can prove to be a significant performance improvement.
+By default, existing files are truncated and rewritten, but
+the file is not recreated.
+In particular, the default behavior does not break existing hard links.
+.It Cm ARCHIVE_EXTRACT_ACL
+Attempt to restore ACLs.
+By default, extended ACLs are ignored.
+.It Cm ARCHIVE_EXTRACT_FFLAGS
+Attempt to restore extended file flags.
+By default, file flags are ignored.
+.It Cm ARCHIVE_EXTRACT_XATTR
+Attempt to restore POSIX.1e extended attributes.
+By default, they are ignored.
+.It Cm ARCHIVE_EXTRACT_SECURE_SYMLINKS
+Refuse to extract any object whose final location would be altered
+by a symlink on disk.
+This is intended to help guard against a variety of mischief
+caused by archives that (deliberately or otherwise) extract
+files outside of the current directory.
+The default is not to perform this check.
+If
+.Cm ARCHIVE_EXTRACT_UNLINK
+is specified together with this option, the library will
+remove any intermediate symlinks it finds and return an
+error only if such symlink could not be removed.
+.It Cm ARCHIVE_EXTRACT_SECURE_NODOTDOT
+Refuse to extract a path that contains a
+.Pa ..
+element anywhere within it.
+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_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.
+.El
+.It Xo
+.Fn archive_write_disk_set_group_lookup ,
+.Fn archive_write_disk_set_user_lookup
+.Xc
+The
+.Tn struct archive_entry
+objects contain both names and ids that can be used to identify users
+and groups.
+These names and ids describe the ownership of the file itself and
+also appear in ACL lists.
+By default, the library uses the ids and ignores the names, but
+this can be overridden by registering user and group lookup functions.
+To register, you must provide a lookup function which
+accepts both a name and id and returns a suitable id.
+You may also provide a
+.Tn void *
+pointer to a private data structure and a cleanup function for
+that data.
+The cleanup function will be invoked when the
+.Tn struct archive
+object is destroyed.
+.It Fn archive_write_disk_set_standard_lookup
+This convenience function installs a standard set of user
+and group lookup functions.
+These functions use
+.Xr getpwnam 3
+and
+.Xr getgrnam 3
+to convert names to ids, defaulting to the ids if the names cannot
+be looked up.
+These functions also implement a simple memory cache to reduce
+the number of calls to
+.Xr getpwnam 3
+and
+.Xr getgrnam 3 .
+.It Fn archive_write_header
+Build and write a header using the data in the provided
+.Tn struct archive_entry
+structure.
+See
+.Xr archive_entry 3
+for information on creating and populating
+.Tn struct archive_entry
+objects.
+.It Fn archive_write_data
+Write data corresponding to the header just written.
+Returns number of bytes written or -1 on error.
+.It Fn archive_write_data_block
+Write data corresponding to the header just written.
+This is like
+.Fn archive_write_data
+except that it performs a seek on the file being
+written to the specified offset before writing the data.
+This is useful when restoring sparse files from archive
+formats that support sparse files.
+Returns number of bytes written or -1 on error.
+(Note: This is currently not supported for
+.Tn archive_write
+handles, only for
+.Tn archive_write_disk
+handles.)
+.It Fn archive_write_finish_entry
+Close out the entry just written.
+Ordinarily, clients never need to call this, as it
+is called automatically by
+.Fn archive_write_next_header
+and
+.Fn archive_write_close
+as needed.
+However, some file attributes are written to disk only
+after the file is closed, so this can be necessary
+if you need to work with the file on disk right away.
+.It Fn archive_write_close
+Set any attributes that could not be set during the initial restore.
+For example, directory timestamps are not restored initially because
+restoring a subsequent file would alter that timestamp.
+Similarly, non-writable directories are initially created with
+write permissions (so that their contents can be restored).
+The
+.Nm
+library maintains a list of all such deferred attributes and
+sets them when this function is invoked.
+.It Fn archive_write_finish
+This is a deprecated synonym for
+.Fn archive_write_free .
+.It Fn archive_write_free
+Invokes
+.Fn archive_write_close
+if it was not invoked manually, then releases all resources.
+.El
+More information about the
+.Va struct archive
+object and the overall design of the library can be found in the
+.Xr libarchive 3
+overview.
+Many of these functions are also documented under
+.Xr archive_write 3 .
+.Sh RETURN VALUES
+Most functions return
+.Cm ARCHIVE_OK
+(zero) on success, or one of several non-zero
+error codes for errors.
+Specific error codes include:
+.Cm ARCHIVE_RETRY
+for operations that might succeed if retried,
+.Cm ARCHIVE_WARN
+for unusual conditions that do not prevent further operations, and
+.Cm ARCHIVE_FATAL
+for serious errors that make remaining operations impossible.
+.Pp
+.Fn archive_write_disk_new
+returns a pointer to a newly-allocated
+.Tn struct archive
+object.
+.Pp
+.Fn archive_write_data
+returns a count of 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.
+.\"
+.Sh SEE ALSO
+.Xr archive_read 3 ,
+.Xr archive_write 3 ,
+.Xr tar 1 ,
+.Xr libarchive 3
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+The
+.Nm archive_write_disk
+interface was added to
+.Nm libarchive 2.0
+and first appeared in
+.Fx 6.3 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libarchive
+library was written by
+.An Tim Kientzle Aq kientzle@acm.org .
+.Sh BUGS
+Directories are actually extracted in two distinct phases.
+Directories are created during
+.Fn archive_write_header ,
+but final permissions are not set until
+.Fn archive_write_close .
+This separation is necessary to correctly handle borderline
+cases such as a non-writable directory containing
+files, but can cause unexpected results.
+In particular, directory permissions are not fully
+restored until the archive is closed.
+If you use
+.Xr chdir 2
+to change the current directory between calls to
+.Fn archive_read_extract
+or before calling
+.Fn archive_read_close ,
+you may confuse the permission-setting logic with
+the result that directory permissions are restored
+incorrectly.
+.Pp
+The library attempts to create objects with filenames longer than
+.Cm PATH_MAX
+by creating prefixes of the full path and changing the current directory.
+Currently, this logic is limited in scope; the fixup pass does
+not work correctly for such objects and the symlink security check
+option disables the support for very long pathnames.
+.Pp
+Restoring the path
+.Pa aa/../bb
+does create each intermediate directory.
+In particular, the directory
+.Pa aa
+is created as well as the final object
+.Pa bb .
+In theory, this can be exploited to create an entire directory hierarchy
+with a single request.
+Of course, this does not work if the
+.Cm ARCHIVE_EXTRACT_NODOTDOT
+option is specified.
+.Pp
+Implicit directories are always created obeying the current umask.
+Explicit objects are created obeying the current umask unless
+.Cm ARCHIVE_EXTRACT_PERM
+is specified, in which case they current umask is ignored.
+.Pp
+SGID and SUID bits are restored only if the correct user and
+group could be set.
+If
+.Cm ARCHIVE_EXTRACT_OWNER
+is not specified, then no attempt is made to set the ownership.
+In this case, SGID and SUID bits are restored only if the
+user and group of the final object happen to match those specified
+in the entry.
+.Pp
+The
+.Dq standard
+user-id and group-id lookup functions are not the defaults because
+.Xr getgrnam 3
+and
+.Xr getpwnam 3
+are sometimes too large for particular applications.
+The current design allows the application author to use a more
+compact implementation when appropriate.
+.Pp
+There should be a corresponding
+.Nm archive_read_disk
+interface that walks a directory hierarchy and returns archive
+entry objects.
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_acl.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_acl.c
new file mode 100644
index 0000000000..5cbba54f08
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_acl.c
@@ -0,0 +1,263 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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
+ * in this position and unchanged.
+ * 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_disk.c 201159 2009-12-29 05:35:40Z kientzle $");
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_ACL_H
+#define _ACL_PRIVATE /* For debugging */
+#include <sys/acl.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_acl_private.h"
+#include "archive_write_disk_private.h"
+
+#ifndef HAVE_POSIX_ACL
+/* Default empty function body to satisfy mainline code. */
+int
+archive_write_disk_set_acls(struct archive *a, int fd, const char *name,
+ struct archive_acl *abstract_acl)
+{
+ (void)a; /* UNUSED */
+ (void)fd; /* UNUSED */
+ (void)name; /* UNUSED */
+ (void)abstract_acl; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+#else
+
+static int set_acl(struct archive *, int fd, const char *,
+ struct archive_acl *,
+ acl_type_t, int archive_entry_acl_type, const char *tn);
+
+/*
+ * XXX TODO: What about ACL types other than ACCESS and DEFAULT?
+ */
+int
+archive_write_disk_set_acls(struct archive *a, int fd, const char *name,
+ struct archive_acl *abstract_acl)
+{
+ int ret;
+
+ if (archive_acl_count(abstract_acl, ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) > 0) {
+ ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_ACCESS,
+ ARCHIVE_ENTRY_ACL_TYPE_ACCESS, "access");
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_DEFAULT,
+ ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, "default");
+ return (ret);
+#ifdef ACL_TYPE_NFS4
+ } else if (archive_acl_count(abstract_acl, ARCHIVE_ENTRY_ACL_TYPE_NFS4) > 0) {
+ ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_NFS4,
+ ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4");
+ return (ret);
+#endif
+ } else
+ return ARCHIVE_OK;
+}
+
+static struct {
+ int archive_perm;
+ int platform_perm;
+} acl_perm_map[] = {
+ {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE},
+ {ARCHIVE_ENTRY_ACL_WRITE, ACL_WRITE},
+ {ARCHIVE_ENTRY_ACL_READ, ACL_READ},
+#ifdef ACL_TYPE_NFS4
+ {ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA},
+ {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY},
+ {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA},
+ {ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE},
+ {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA},
+ {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY},
+ {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_NAMED_ATTRS},
+ {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_NAMED_ATTRS},
+ {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD},
+ {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES},
+ {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES},
+ {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE},
+ {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_ACL},
+ {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_ACL},
+ {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_WRITE_OWNER},
+ {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE}
+#endif
+};
+
+#ifdef ACL_TYPE_NFS4
+static struct {
+ int archive_inherit;
+ int platform_inherit;
+} acl_inherit_map[] = {
+ {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT},
+ {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT},
+ {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_NO_PROPAGATE_INHERIT},
+ {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_INHERIT_ONLY}
+};
+#endif
+
+static int
+set_acl(struct archive *a, int fd, const char *name,
+ struct archive_acl *abstract_acl,
+ acl_type_t acl_type, int ae_requested_type, const char *tname)
+{
+ acl_t acl;
+ acl_entry_t acl_entry;
+ acl_permset_t acl_permset;
+#ifdef ACL_TYPE_NFS4
+ acl_flagset_t acl_flagset;
+#endif
+ int ret;
+ int ae_type, ae_permset, ae_tag, ae_id;
+ uid_t ae_uid;
+ gid_t ae_gid;
+ const char *ae_name;
+ int entries;
+ int i;
+
+ ret = ARCHIVE_OK;
+ entries = archive_acl_reset(abstract_acl, ae_requested_type);
+ if (entries == 0)
+ return (ARCHIVE_OK);
+ acl = acl_init(entries);
+ while (archive_acl_next(a, abstract_acl, ae_requested_type, &ae_type,
+ &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) {
+ acl_create_entry(&acl, &acl_entry);
+
+ switch (ae_tag) {
+ case ARCHIVE_ENTRY_ACL_USER:
+ acl_set_tag_type(acl_entry, ACL_USER);
+ ae_uid = archive_write_disk_uid(a, ae_name, ae_id);
+ acl_set_qualifier(acl_entry, &ae_uid);
+ break;
+ case ARCHIVE_ENTRY_ACL_GROUP:
+ acl_set_tag_type(acl_entry, ACL_GROUP);
+ ae_gid = archive_write_disk_gid(a, ae_name, ae_id);
+ acl_set_qualifier(acl_entry, &ae_gid);
+ break;
+ case ARCHIVE_ENTRY_ACL_USER_OBJ:
+ acl_set_tag_type(acl_entry, ACL_USER_OBJ);
+ break;
+ case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
+ acl_set_tag_type(acl_entry, ACL_GROUP_OBJ);
+ break;
+ case ARCHIVE_ENTRY_ACL_MASK:
+ acl_set_tag_type(acl_entry, ACL_MASK);
+ break;
+ case ARCHIVE_ENTRY_ACL_OTHER:
+ acl_set_tag_type(acl_entry, ACL_OTHER);
+ break;
+#ifdef ACL_TYPE_NFS4
+ case ARCHIVE_ENTRY_ACL_EVERYONE:
+ acl_set_tag_type(acl_entry, ACL_EVERYONE);
+ break;
+#endif
+ default:
+ /* XXX */
+ break;
+ }
+
+#ifdef ACL_TYPE_NFS4
+ switch (ae_type) {
+ case ARCHIVE_ENTRY_ACL_TYPE_ALLOW:
+ acl_set_entry_type_np(acl_entry, ACL_ENTRY_TYPE_ALLOW);
+ break;
+ case ARCHIVE_ENTRY_ACL_TYPE_DENY:
+ acl_set_entry_type_np(acl_entry, ACL_ENTRY_TYPE_DENY);
+ break;
+ case ARCHIVE_ENTRY_ACL_TYPE_AUDIT:
+ acl_set_entry_type_np(acl_entry, ACL_ENTRY_TYPE_AUDIT);
+ break;
+ case ARCHIVE_ENTRY_ACL_TYPE_ALARM:
+ acl_set_entry_type_np(acl_entry, ACL_ENTRY_TYPE_ALARM);
+ break;
+ case ARCHIVE_ENTRY_ACL_TYPE_ACCESS:
+ case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT:
+ // These don't translate directly into the system ACL.
+ break;
+ default:
+ // XXX error handling here.
+ break;
+ }
+#endif
+
+ acl_get_permset(acl_entry, &acl_permset);
+ acl_clear_perms(acl_permset);
+
+ for (i = 0; i < (int)(sizeof(acl_perm_map) / sizeof(acl_perm_map[0])); ++i) {
+ if (ae_permset & acl_perm_map[i].archive_perm)
+ acl_add_perm(acl_permset,
+ acl_perm_map[i].platform_perm);
+ }
+
+#ifdef ACL_TYPE_NFS4
+ acl_get_flagset_np(acl_entry, &acl_flagset);
+ acl_clear_flags_np(acl_flagset);
+ for (i = 0; i < (int)(sizeof(acl_inherit_map) / sizeof(acl_inherit_map[0])); ++i) {
+ if (ae_permset & acl_inherit_map[i].archive_inherit)
+ acl_add_flag_np(acl_flagset,
+ acl_inherit_map[i].platform_inherit);
+ }
+#endif
+ }
+
+ /* Try restoring the ACL through 'fd' if we can. */
+#if HAVE_ACL_SET_FD
+ if (fd >= 0 && acl_type == ACL_TYPE_ACCESS && acl_set_fd(fd, acl) == 0)
+ ret = ARCHIVE_OK;
+ else
+#else
+#if HAVE_ACL_SET_FD_NP
+ if (fd >= 0 && acl_set_fd_np(fd, acl, acl_type) == 0)
+ ret = ARCHIVE_OK;
+ else
+#endif
+#endif
+#if HAVE_ACL_SET_LINK_NP
+ if (acl_set_link_np(name, acl_type, acl) != 0) {
+ archive_set_error(a, errno, "Failed to set %s acl", tname);
+ ret = ARCHIVE_WARN;
+ }
+#else
+ /* TODO: Skip this if 'name' is a symlink. */
+ if (acl_set_file(name, acl_type, acl) != 0) {
+ archive_set_error(a, errno, "Failed to set %s acl", tname);
+ ret = ARCHIVE_WARN;
+ }
+#endif
+ acl_free(acl);
+ return (ret);
+}
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c
new file mode 100644
index 0000000000..a3d350b549
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c
@@ -0,0 +1,3824 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * Copyright (c) 2012 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
+ * in this position and unchanged.
+ * 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$");
+
+#if !defined(_WIN32) || defined(__CYGWIN__)
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_ACL_H
+#include <sys/acl.h>
+#endif
+#ifdef HAVE_SYS_EXTATTR_H
+#include <sys/extattr.h>
+#endif
+#if defined(HAVE_SYS_XATTR_H)
+#include <sys/xattr.h>
+#elif defined(HAVE_ATTR_XATTR_H)
+#include <attr/xattr.h>
+#endif
+#ifdef HAVE_SYS_EA_H
+#include <sys/ea.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_UTIME_H
+#include <sys/utime.h>
+#endif
+#ifdef HAVE_COPYFILE_H
+#include <copyfile.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#ifdef HAVE_LINUX_FS_H
+#include <linux/fs.h> /* for Linux file flags */
+#endif
+/*
+ * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
+ * As the include guards don't agree, the order of include is important.
+ */
+#ifdef HAVE_LINUX_EXT2_FS_H
+#include <linux/ext2_fs.h> /* for Linux file flags */
+#endif
+#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
+#include <ext2fs/ext2_fs.h> /* Linux file flags, broken on Cygwin */
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.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_UTIME_H
+#include <utime.h>
+#endif
+#ifdef F_GETTIMES /* Tru64 specific */
+#include <sys/fcntl1.h>
+#endif
+
+#if __APPLE__
+#include <TargetConditionals.h>
+#if TARGET_OS_MAC && !TARGET_OS_EMBEDDED && HAVE_QUARANTINE_H
+#include <quarantine.h>
+#define HAVE_QUARANTINE 1
+#endif
+#endif
+
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+/* TODO: Support Mac OS 'quarantine' feature. This is really just a
+ * standard tag to mark files that have been downloaded as "tainted".
+ * On Mac OS, we should mark the extracted files as tainted if the
+ * archive being read was tainted. Windows has a similar feature; we
+ * should investigate ways to support this generically. */
+
+#include "archive.h"
+#include "archive_acl_private.h"
+#include "archive_string.h"
+#include "archive_endian.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_write_disk_private.h"
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
+struct fixup_entry {
+ struct fixup_entry *next;
+ struct archive_acl acl;
+ mode_t mode;
+ int64_t atime;
+ int64_t birthtime;
+ int64_t mtime;
+ int64_t ctime;
+ unsigned long atime_nanos;
+ unsigned long birthtime_nanos;
+ unsigned long mtime_nanos;
+ unsigned long ctime_nanos;
+ unsigned long fflags_set;
+ size_t mac_metadata_size;
+ void *mac_metadata;
+ int fixup; /* bitmask of what needs fixing */
+ char *name;
+};
+
+/*
+ * We use a bitmask to track which operations remain to be done for
+ * this file. In particular, this helps us avoid unnecessary
+ * operations when it's possible to take care of one step as a
+ * side-effect of another. For example, mkdir() can specify the mode
+ * for the newly-created object but symlink() cannot. This means we
+ * can skip chmod() if mkdir() succeeded, but we must explicitly
+ * chmod() if we're trying to create a directory that already exists
+ * (mkdir() failed) or if we're restoring a symlink. Similarly, we
+ * need to verify UID/GID before trying to restore SUID/SGID bits;
+ * that verification can occur explicitly through a stat() call or
+ * implicitly because of a successful chown() call.
+ */
+#define TODO_MODE_FORCE 0x40000000
+#define TODO_MODE_BASE 0x20000000
+#define TODO_SUID 0x10000000
+#define TODO_SUID_CHECK 0x08000000
+#define TODO_SGID 0x04000000
+#define TODO_SGID_CHECK 0x02000000
+#define TODO_APPLEDOUBLE 0x01000000
+#define TODO_MODE (TODO_MODE_BASE|TODO_SUID|TODO_SGID)
+#define TODO_TIMES ARCHIVE_EXTRACT_TIME
+#define TODO_OWNER ARCHIVE_EXTRACT_OWNER
+#define TODO_FFLAGS ARCHIVE_EXTRACT_FFLAGS
+#define TODO_ACLS ARCHIVE_EXTRACT_ACL
+#define TODO_XATTR ARCHIVE_EXTRACT_XATTR
+#define TODO_MAC_METADATA ARCHIVE_EXTRACT_MAC_METADATA
+#define TODO_HFS_COMPRESSION ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED
+
+struct archive_write_disk {
+ struct archive archive;
+
+ mode_t user_umask;
+ struct fixup_entry *fixup_list;
+ struct fixup_entry *current_fixup;
+ int64_t user_uid;
+ int skip_file_set;
+ int64_t skip_file_dev;
+ int64_t skip_file_ino;
+ time_t start_time;
+
+ int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid);
+ void (*cleanup_gid)(void *private);
+ void *lookup_gid_data;
+ int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid);
+ void (*cleanup_uid)(void *private);
+ void *lookup_uid_data;
+
+ /*
+ * Full path of last file to satisfy symlink checks.
+ */
+ struct archive_string path_safe;
+
+ /*
+ * Cached stat data from disk for the current entry.
+ * If this is valid, pst points to st. Otherwise,
+ * pst is null.
+ */
+ struct stat st;
+ struct stat *pst;
+
+ /* Information about the object being restored right now. */
+ struct archive_entry *entry; /* Entry being extracted. */
+ char *name; /* Name of entry, possibly edited. */
+ struct archive_string _name_data; /* backing store for 'name' */
+ /* Tasks remaining for this object. */
+ int todo;
+ /* Tasks deferred until end-of-archive. */
+ int deferred;
+ /* Options requested by the client. */
+ int flags;
+ /* Handle for the file we're restoring. */
+ int fd;
+ /* Current offset for writing data to the file. */
+ int64_t offset;
+ /* Last offset actually written to disk. */
+ int64_t fd_offset;
+ /* Total bytes actually written to files. */
+ int64_t total_bytes_written;
+ /* Maximum size of file, -1 if unknown. */
+ int64_t filesize;
+ /* Dir we were in before this restore; only for deep paths. */
+ int restore_pwd;
+ /* Mode we should use for this entry; affected by _PERM and umask. */
+ mode_t mode;
+ /* UID/GID to use in restoring this entry. */
+ int64_t uid;
+ int64_t gid;
+ /*
+ * HFS+ Compression.
+ */
+ /* Xattr "com.apple.decmpfs". */
+ uint32_t decmpfs_attr_size;
+ unsigned char *decmpfs_header_p;
+ /* ResourceFork set options used for fsetxattr. */
+ int rsrc_xattr_options;
+ /* Xattr "com.apple.ResourceFork". */
+ unsigned char *resource_fork;
+ size_t resource_fork_allocated_size;
+ unsigned int decmpfs_block_count;
+ uint32_t *decmpfs_block_info;
+ /* Buffer for compressed data. */
+ unsigned char *compressed_buffer;
+ size_t compressed_buffer_size;
+ size_t compressed_buffer_remaining;
+ /* The offset of the ResourceFork where compressed data will
+ * be placed. */
+ uint32_t compressed_rsrc_position;
+ uint32_t compressed_rsrc_position_v;
+ /* Buffer for uncompressed data. */
+ char *uncompressed_buffer;
+ size_t block_remaining_bytes;
+ size_t file_remaining_bytes;
+#ifdef HAVE_ZLIB_H
+ z_stream stream;
+ int stream_valid;
+ int decmpfs_compression_level;
+#endif
+};
+
+/*
+ * Default mode for dirs created automatically (will be modified by umask).
+ * Note that POSIX specifies 0777 for implicitly-created dirs, "modified
+ * by the process' file creation mask."
+ */
+#define DEFAULT_DIR_MODE 0777
+/*
+ * Dir modes are restored in two steps: During the extraction, the permissions
+ * in the archive are modified to match the following limits. During
+ * the post-extract fixup pass, the permissions from the archive are
+ * applied.
+ */
+#define MINIMUM_DIR_MODE 0700
+#define MAXIMUM_DIR_MODE 0775
+
+/*
+ * Maxinum uncompressed size of a decmpfs block.
+ */
+#define MAX_DECMPFS_BLOCK_SIZE (64 * 1024)
+/*
+ * HFS+ compression type.
+ */
+#define CMP_XATTR 3/* Compressed data in xattr. */
+#define CMP_RESOURCE_FORK 4/* Compressed data in resource fork. */
+/*
+ * HFS+ compression resource fork.
+ */
+#define RSRC_H_SIZE 260 /* Base size of Resource fork header. */
+#define RSRC_F_SIZE 50 /* Size of Resource fork footer. */
+/* Size to write compressed data to resource fork. */
+#define COMPRESSED_W_SIZE (64 * 1024)
+/* decmpfs difinitions. */
+#define MAX_DECMPFS_XATTR_SIZE 3802
+#ifndef DECMPFS_XATTR_NAME
+#define DECMPFS_XATTR_NAME "com.apple.decmpfs"
+#endif
+#define DECMPFS_MAGIC 0x636d7066
+#define DECMPFS_COMPRESSION_MAGIC 0
+#define DECMPFS_COMPRESSION_TYPE 4
+#define DECMPFS_UNCOMPRESSED_SIZE 8
+#define DECMPFS_HEADER_SIZE 16
+
+#define HFS_BLOCKS(s) ((s) >> 12)
+
+static int check_symlinks(struct archive_write_disk *);
+static int create_filesystem_object(struct archive_write_disk *);
+static struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname);
+#if defined(HAVE_FCHDIR) && defined(PATH_MAX)
+static void edit_deep_directories(struct archive_write_disk *ad);
+#endif
+static int cleanup_pathname(struct archive_write_disk *);
+static int create_dir(struct archive_write_disk *, char *);
+static int create_parent_dir(struct archive_write_disk *, char *);
+static ssize_t hfs_write_data_block(struct archive_write_disk *,
+ const char *, size_t);
+static int fixup_appledouble(struct archive_write_disk *, const char *);
+static int older(struct stat *, struct archive_entry *);
+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 set_fflags(struct archive_write_disk *);
+static int set_fflags_platform(struct archive_write_disk *, int fd,
+ const char *name, mode_t mode,
+ unsigned long fflags_set, unsigned long fflags_clear);
+static int set_ownership(struct archive_write_disk *);
+static int set_mode(struct archive_write_disk *, int mode);
+static int set_time(int, int, const char *, time_t, long, time_t, long);
+static int set_times(struct archive_write_disk *, int, int, const char *,
+ time_t, long, time_t, long, time_t, long, time_t, long);
+static int set_times_from_entry(struct archive_write_disk *);
+static struct fixup_entry *sort_dir_list(struct fixup_entry *p);
+static ssize_t write_data_block(struct archive_write_disk *,
+ const char *, size_t);
+
+static struct archive_vtable *archive_write_disk_vtable(void);
+
+static int _archive_write_disk_close(struct archive *);
+static int _archive_write_disk_free(struct archive *);
+static int _archive_write_disk_header(struct archive *, struct archive_entry *);
+static int64_t _archive_write_disk_filter_bytes(struct archive *, int);
+static int _archive_write_disk_finish_entry(struct archive *);
+static ssize_t _archive_write_disk_data(struct archive *, const void *, size_t);
+static ssize_t _archive_write_disk_data_block(struct archive *, const void *, size_t, int64_t);
+
+static int
+lazy_stat(struct archive_write_disk *a)
+{
+ if (a->pst != NULL) {
+ /* Already have stat() data available. */
+ return (ARCHIVE_OK);
+ }
+#ifdef HAVE_FSTAT
+ if (a->fd >= 0 && fstat(a->fd, &a->st) == 0) {
+ a->pst = &a->st;
+ return (ARCHIVE_OK);
+ }
+#endif
+ /*
+ * XXX At this point, symlinks should not be hit, otherwise
+ * XXX a race occurred. Do we want to check explicitly for that?
+ */
+ if (lstat(a->name, &a->st) == 0) {
+ a->pst = &a->st;
+ return (ARCHIVE_OK);
+ }
+ archive_set_error(&a->archive, errno, "Couldn't stat file");
+ return (ARCHIVE_WARN);
+}
+
+static struct archive_vtable *
+archive_write_disk_vtable(void)
+{
+ static struct archive_vtable av;
+ static int inited = 0;
+
+ if (!inited) {
+ av.archive_close = _archive_write_disk_close;
+ av.archive_filter_bytes = _archive_write_disk_filter_bytes;
+ av.archive_free = _archive_write_disk_free;
+ av.archive_write_header = _archive_write_disk_header;
+ av.archive_write_finish_entry
+ = _archive_write_disk_finish_entry;
+ av.archive_write_data = _archive_write_disk_data;
+ av.archive_write_data_block = _archive_write_disk_data_block;
+ inited = 1;
+ }
+ return (&av);
+}
+
+static int64_t
+_archive_write_disk_filter_bytes(struct archive *_a, int n)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ (void)n; /* UNUSED */
+ if (n == -1 || n == 0)
+ return (a->total_bytes_written);
+ return (-1);
+}
+
+
+int
+archive_write_disk_set_options(struct archive *_a, int flags)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+
+ a->flags = flags;
+ return (ARCHIVE_OK);
+}
+
+
+/*
+ * Extract this entry to disk.
+ *
+ * TODO: Validate hardlinks. According to the standards, we're
+ * supposed to check each extracted hardlink and squawk if it refers
+ * to a file that we didn't restore. I'm not entirely convinced this
+ * is a good idea, but more importantly: Is there any way to validate
+ * hardlinks without keeping a complete list of filenames from the
+ * entire archive?? Ugh.
+ *
+ */
+static int
+_archive_write_disk_header(struct archive *_a, struct archive_entry *entry)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ struct fixup_entry *fe;
+ int ret, r;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_write_disk_header");
+ archive_clear_error(&a->archive);
+ if (a->archive.state & ARCHIVE_STATE_DATA) {
+ r = _archive_write_disk_finish_entry(&a->archive);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ }
+
+ /* Set up for this particular entry. */
+ a->pst = NULL;
+ a->current_fixup = NULL;
+ a->deferred = 0;
+ if (a->entry) {
+ archive_entry_free(a->entry);
+ a->entry = NULL;
+ }
+ a->entry = archive_entry_clone(entry);
+ a->fd = -1;
+ a->fd_offset = 0;
+ a->offset = 0;
+ a->restore_pwd = -1;
+ a->uid = a->user_uid;
+ a->mode = archive_entry_mode(a->entry);
+ if (archive_entry_size_is_set(a->entry))
+ a->filesize = archive_entry_size(a->entry);
+ else
+ a->filesize = -1;
+ archive_strcpy(&(a->_name_data), archive_entry_pathname(a->entry));
+ a->name = a->_name_data.s;
+ archive_clear_error(&a->archive);
+
+ /*
+ * Clean up the requested path. This is necessary for correct
+ * dir restores; the dir restore logic otherwise gets messed
+ * up by nonsense like "dir/.".
+ */
+ ret = cleanup_pathname(a);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ /*
+ * Query the umask so we get predictable mode settings.
+ * This gets done on every call to _write_header in case the
+ * user edits their umask during the extraction for some
+ * reason.
+ */
+ umask(a->user_umask = umask(0));
+
+ /* Figure out what we need to do for this entry. */
+ a->todo = TODO_MODE_BASE;
+ if (a->flags & ARCHIVE_EXTRACT_PERM) {
+ a->todo |= TODO_MODE_FORCE; /* Be pushy about permissions. */
+ /*
+ * SGID requires an extra "check" step because we
+ * cannot easily predict the GID that the system will
+ * assign. (Different systems assign GIDs to files
+ * based on a variety of criteria, including process
+ * credentials and the gid of the enclosing
+ * directory.) We can only restore the SGID bit if
+ * the file has the right GID, and we only know the
+ * GID if we either set it (see set_ownership) or if
+ * we've actually called stat() on the file after it
+ * was restored. Since there are several places at
+ * which we might verify the GID, we need a TODO bit
+ * to keep track.
+ */
+ if (a->mode & S_ISGID)
+ a->todo |= TODO_SGID | TODO_SGID_CHECK;
+ /*
+ * Verifying the SUID is simpler, but can still be
+ * done in multiple ways, hence the separate "check" bit.
+ */
+ if (a->mode & S_ISUID)
+ a->todo |= TODO_SUID | TODO_SUID_CHECK;
+ } else {
+ /*
+ * User didn't request full permissions, so don't
+ * restore SUID, SGID bits and obey umask.
+ */
+ a->mode &= ~S_ISUID;
+ a->mode &= ~S_ISGID;
+ a->mode &= ~S_ISVTX;
+ a->mode &= ~a->user_umask;
+ }
+ if (a->flags & ARCHIVE_EXTRACT_OWNER)
+ a->todo |= TODO_OWNER;
+ if (a->flags & ARCHIVE_EXTRACT_TIME)
+ a->todo |= TODO_TIMES;
+ if (a->flags & ARCHIVE_EXTRACT_ACL) {
+ if (archive_entry_filetype(a->entry) == AE_IFDIR)
+ a->deferred |= TODO_ACLS;
+ else
+ a->todo |= TODO_ACLS;
+ }
+ if (a->flags & ARCHIVE_EXTRACT_MAC_METADATA) {
+ if (archive_entry_filetype(a->entry) == AE_IFDIR)
+ a->deferred |= TODO_MAC_METADATA;
+ else
+ a->todo |= TODO_MAC_METADATA;
+ }
+#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_ZLIB_H)
+ if ((a->flags & ARCHIVE_EXTRACT_NO_HFS_COMPRESSION) == 0) {
+ unsigned long set, clear;
+ archive_entry_fflags(a->entry, &set, &clear);
+ if ((set & ~clear) & UF_COMPRESSED) {
+ a->todo |= TODO_HFS_COMPRESSION;
+ a->decmpfs_block_count = (unsigned)-1;
+ }
+ }
+ if ((a->flags & ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED) != 0 &&
+ (a->mode & AE_IFMT) == AE_IFREG && a->filesize > 0) {
+ a->todo |= TODO_HFS_COMPRESSION;
+ a->decmpfs_block_count = (unsigned)-1;
+ }
+ {
+ const char *p;
+
+ /* Check if the current file name is a type of the
+ * resource fork file. */
+ p = strrchr(a->name, '/');
+ if (p == NULL)
+ p = a->name;
+ else
+ p++;
+ if (p[0] == '.' && p[1] == '_') {
+ /* Do not compress "._XXX" files. */
+ a->todo &= ~TODO_HFS_COMPRESSION;
+ if (a->filesize > 0)
+ a->todo |= TODO_APPLEDOUBLE;
+ }
+ }
+#endif
+
+ if (a->flags & ARCHIVE_EXTRACT_XATTR)
+ a->todo |= TODO_XATTR;
+ if (a->flags & ARCHIVE_EXTRACT_FFLAGS)
+ a->todo |= TODO_FFLAGS;
+ if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) {
+ ret = check_symlinks(a);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ }
+#if defined(HAVE_FCHDIR) && defined(PATH_MAX)
+ /* If path exceeds PATH_MAX, shorten the path. */
+ edit_deep_directories(a);
+#endif
+
+ ret = restore_entry(a);
+
+#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_ZLIB_H)
+ /*
+ * Check if the filesystem the file is restoring on supports
+ * HFS+ Compression. If not, cancel HFS+ Compression.
+ */
+ if (a->todo | TODO_HFS_COMPRESSION) {
+ /*
+ * NOTE: UF_COMPRESSED is ignored even if the filesystem
+ * supports HFS+ Compression because the file should
+ * have at least an extended attriute "com.apple.decmpfs"
+ * before the flag is set to indicate that the file have
+ * been compressed. If hte filesystem does not support
+ * HFS+ Compression the system call will fail.
+ */
+ if (a->fd < 0 || fchflags(a->fd, UF_COMPRESSED) != 0)
+ a->todo &= ~TODO_HFS_COMPRESSION;
+ }
+#endif
+
+ /*
+ * TODO: There are rumours that some extended attributes must
+ * be restored before file data is written. If this is true,
+ * then we either need to write all extended attributes both
+ * before and after restoring the data, or find some rule for
+ * determining which must go first and which last. Due to the
+ * many ways people are using xattrs, this may prove to be an
+ * intractable problem.
+ */
+
+#ifdef HAVE_FCHDIR
+ /* If we changed directory above, restore it here. */
+ if (a->restore_pwd >= 0) {
+ r = fchdir(a->restore_pwd);
+ if (r != 0) {
+ archive_set_error(&a->archive, errno, "chdir() failure");
+ ret = ARCHIVE_FATAL;
+ }
+ close(a->restore_pwd);
+ a->restore_pwd = -1;
+ }
+#endif
+
+ /*
+ * Fixup uses the unedited pathname from archive_entry_pathname(),
+ * because it is relative to the base dir and the edited path
+ * might be relative to some intermediate dir as a result of the
+ * deep restore logic.
+ */
+ if (a->deferred & TODO_MODE) {
+ fe = current_fixup(a, archive_entry_pathname(entry));
+ if (fe == NULL)
+ return (ARCHIVE_FATAL);
+ fe->fixup |= TODO_MODE_BASE;
+ fe->mode = a->mode;
+ }
+
+ if ((a->deferred & TODO_TIMES)
+ && (archive_entry_mtime_is_set(entry)
+ || archive_entry_atime_is_set(entry))) {
+ fe = current_fixup(a, archive_entry_pathname(entry));
+ if (fe == NULL)
+ return (ARCHIVE_FATAL);
+ fe->mode = a->mode;
+ fe->fixup |= TODO_TIMES;
+ if (archive_entry_atime_is_set(entry)) {
+ fe->atime = archive_entry_atime(entry);
+ fe->atime_nanos = archive_entry_atime_nsec(entry);
+ } else {
+ /* If atime is unset, use start time. */
+ fe->atime = a->start_time;
+ fe->atime_nanos = 0;
+ }
+ if (archive_entry_mtime_is_set(entry)) {
+ fe->mtime = archive_entry_mtime(entry);
+ fe->mtime_nanos = archive_entry_mtime_nsec(entry);
+ } else {
+ /* If mtime is unset, use start time. */
+ fe->mtime = a->start_time;
+ fe->mtime_nanos = 0;
+ }
+ if (archive_entry_birthtime_is_set(entry)) {
+ fe->birthtime = archive_entry_birthtime(entry);
+ fe->birthtime_nanos = archive_entry_birthtime_nsec(entry);
+ } else {
+ /* If birthtime is unset, use mtime. */
+ fe->birthtime = fe->mtime;
+ fe->birthtime_nanos = fe->mtime_nanos;
+ }
+ }
+
+ if (a->deferred & TODO_ACLS) {
+ fe = current_fixup(a, archive_entry_pathname(entry));
+ if (fe == NULL)
+ return (ARCHIVE_FATAL);
+ fe->fixup |= TODO_ACLS;
+ archive_acl_copy(&fe->acl, archive_entry_acl(entry));
+ }
+
+ if (a->deferred & TODO_MAC_METADATA) {
+ const void *metadata;
+ size_t metadata_size;
+ metadata = archive_entry_mac_metadata(a->entry, &metadata_size);
+ if (metadata != NULL && metadata_size > 0) {
+ fe = current_fixup(a, archive_entry_pathname(entry));
+ if (fe == NULL)
+ return (ARCHIVE_FATAL);
+ fe->mac_metadata = malloc(metadata_size);
+ if (fe->mac_metadata != NULL) {
+ memcpy(fe->mac_metadata, metadata, metadata_size);
+ fe->mac_metadata_size = metadata_size;
+ fe->fixup |= TODO_MAC_METADATA;
+ }
+ }
+ }
+
+ if (a->deferred & TODO_FFLAGS) {
+ fe = current_fixup(a, archive_entry_pathname(entry));
+ if (fe == NULL)
+ return (ARCHIVE_FATAL);
+ fe->fixup |= TODO_FFLAGS;
+ /* TODO: Complete this.. defer fflags from below. */
+ }
+
+ /* We've created the object and are ready to pour data into it. */
+ if (ret >= ARCHIVE_WARN)
+ a->archive.state = ARCHIVE_STATE_DATA;
+ /*
+ * If it's not open, tell our client not to try writing.
+ * In particular, dirs, links, etc, don't get written to.
+ */
+ if (a->fd < 0) {
+ archive_entry_set_size(entry, 0);
+ a->filesize = 0;
+ }
+
+ return (ret);
+}
+
+int
+archive_write_disk_set_skip_file(struct archive *_a, int64_t d, int64_t i)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_set_skip_file");
+ a->skip_file_set = 1;
+ a->skip_file_dev = d;
+ a->skip_file_ino = i;
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+write_data_block(struct archive_write_disk *a, const char *buff, size_t size)
+{
+ uint64_t start_size = size;
+ ssize_t bytes_written = 0;
+ ssize_t block_size = 0, bytes_to_write;
+
+ if (size == 0)
+ return (ARCHIVE_OK);
+
+ if (a->filesize == 0 || a->fd < 0) {
+ archive_set_error(&a->archive, 0,
+ "Attempt to write to an empty file");
+ return (ARCHIVE_WARN);
+ }
+
+ if (a->flags & ARCHIVE_EXTRACT_SPARSE) {
+#if HAVE_STRUCT_STAT_ST_BLKSIZE
+ int r;
+ if ((r = lazy_stat(a)) != ARCHIVE_OK)
+ return (r);
+ block_size = a->pst->st_blksize;
+#else
+ /* XXX TODO XXX Is there a more appropriate choice here ? */
+ /* This needn't match the filesystem allocation size. */
+ block_size = 16*1024;
+#endif
+ }
+
+ /* If this write would run beyond the file size, truncate it. */
+ if (a->filesize >= 0 && (int64_t)(a->offset + size) > a->filesize)
+ start_size = size = (size_t)(a->filesize - a->offset);
+
+ /* Write the data. */
+ while (size > 0) {
+ if (block_size == 0) {
+ bytes_to_write = size;
+ } else {
+ /* We're sparsifying the file. */
+ const char *p, *end;
+ int64_t block_end;
+
+ /* Skip leading zero bytes. */
+ for (p = buff, end = buff + size; p < end; ++p) {
+ if (*p != '\0')
+ break;
+ }
+ a->offset += p - buff;
+ size -= p - buff;
+ buff = p;
+ if (size == 0)
+ break;
+
+ /* Calculate next block boundary after offset. */
+ block_end
+ = (a->offset / block_size + 1) * block_size;
+
+ /* If the adjusted write would cross block boundary,
+ * truncate it to the block boundary. */
+ bytes_to_write = size;
+ if (a->offset + bytes_to_write > block_end)
+ bytes_to_write = block_end - a->offset;
+ }
+ /* Seek if necessary to the specified offset. */
+ if (a->offset != a->fd_offset) {
+ if (lseek(a->fd, a->offset, SEEK_SET) < 0) {
+ archive_set_error(&a->archive, errno,
+ "Seek failed");
+ return (ARCHIVE_FATAL);
+ }
+ a->fd_offset = a->offset;
+ }
+ bytes_written = write(a->fd, buff, bytes_to_write);
+ if (bytes_written < 0) {
+ archive_set_error(&a->archive, errno, "Write failed");
+ return (ARCHIVE_WARN);
+ }
+ buff += bytes_written;
+ size -= bytes_written;
+ a->total_bytes_written += bytes_written;
+ a->offset += bytes_written;
+ a->fd_offset = a->offset;
+ }
+ return (start_size - size);
+}
+
+#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_SYS_XATTR_H)\
+ && defined(HAVE_ZLIB_H)
+
+/*
+ * Set UF_COMPRESSED file flag.
+ * This have to be called after hfs_write_decmpfs() because if the
+ * file does not have "com.apple.decmpfs" xattr the flag is ignored.
+ */
+static int
+hfs_set_compressed_fflag(struct archive_write_disk *a)
+{
+ int r;
+
+ if ((r = lazy_stat(a)) != ARCHIVE_OK)
+ return (r);
+
+ a->st.st_flags |= UF_COMPRESSED;
+ if (fchflags(a->fd, a->st.st_flags) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Failed to set UF_COMPRESSED file flag");
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * HFS+ Compression decmpfs
+ *
+ * +------------------------------+ +0
+ * | Magic(LE 4 bytes) |
+ * +------------------------------+
+ * | Type(LE 4 bytes) |
+ * +------------------------------+
+ * | Uncompressed size(LE 8 bytes)|
+ * +------------------------------+ +16
+ * | |
+ * | Compressed data |
+ * | (Placed only if Type == 3) |
+ * | |
+ * +------------------------------+ +3802 = MAX_DECMPFS_XATTR_SIZE
+ *
+ * Type is 3: decmpfs has compressed data.
+ * Type is 4: Resource Fork has compressed data.
+ */
+/*
+ * Write "com.apple.decmpfs"
+ */
+static int
+hfs_write_decmpfs(struct archive_write_disk *a)
+{
+ int r;
+ uint32_t compression_type;
+
+ r = fsetxattr(a->fd, DECMPFS_XATTR_NAME, a->decmpfs_header_p,
+ a->decmpfs_attr_size, 0, 0);
+ if (r < 0) {
+ archive_set_error(&a->archive, errno,
+ "Cannot restore xattr:%s", DECMPFS_XATTR_NAME);
+ compression_type = archive_le32dec(
+ &a->decmpfs_header_p[DECMPFS_COMPRESSION_TYPE]);
+ if (compression_type == CMP_RESOURCE_FORK)
+ fremovexattr(a->fd, XATTR_RESOURCEFORK_NAME,
+ XATTR_SHOWCOMPRESSION);
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * HFS+ Compression Resource Fork
+ *
+ * +-----------------------------+
+ * | Header(260 bytes) |
+ * +-----------------------------+
+ * | Block count(LE 4 bytes) |
+ * +-----------------------------+ --+
+ * +-- | Offset (LE 4 bytes) | |
+ * | | [distance from Block count] | | Block 0
+ * | +-----------------------------+ |
+ * | | Compressed size(LE 4 bytes) | |
+ * | +-----------------------------+ --+
+ * | | |
+ * | | .................. |
+ * | | |
+ * | +-----------------------------+ --+
+ * | | Offset (LE 4 bytes) | |
+ * | +-----------------------------+ | Block (Block count -1)
+ * | | Compressed size(LE 4 bytes) | |
+ * +-> +-----------------------------+ --+
+ * | Compressed data(n bytes) | Block 0
+ * +-----------------------------+
+ * | |
+ * | .................. |
+ * | |
+ * +-----------------------------+
+ * | Compressed data(n bytes) | Block (Block count -1)
+ * +-----------------------------+
+ * | Footer(50 bytes) |
+ * +-----------------------------+
+ *
+ */
+/*
+ * Write the header of "com.apple.ResourceFork"
+ */
+static int
+hfs_write_resource_fork(struct archive_write_disk *a, unsigned char *buff,
+ size_t bytes, uint32_t position)
+{
+ int ret;
+
+ ret = fsetxattr(a->fd, XATTR_RESOURCEFORK_NAME, buff, bytes,
+ position, a->rsrc_xattr_options);
+ if (ret < 0) {
+ archive_set_error(&a->archive, errno,
+ "Cannot restore xattr: %s at %u pos %u bytes",
+ XATTR_RESOURCEFORK_NAME,
+ (unsigned)position,
+ (unsigned)bytes);
+ return (ARCHIVE_WARN);
+ }
+ a->rsrc_xattr_options &= ~XATTR_CREATE;
+ return (ARCHIVE_OK);
+}
+
+static int
+hfs_write_compressed_data(struct archive_write_disk *a, size_t bytes_compressed)
+{
+ int ret;
+
+ ret = hfs_write_resource_fork(a, a->compressed_buffer,
+ bytes_compressed, a->compressed_rsrc_position);
+ if (ret == ARCHIVE_OK)
+ a->compressed_rsrc_position += bytes_compressed;
+ return (ret);
+}
+
+static int
+hfs_write_resource_fork_header(struct archive_write_disk *a)
+{
+ unsigned char *buff;
+ uint32_t rsrc_bytes;
+ uint32_t rsrc_header_bytes;
+
+ /*
+ * Write resource fork header + block info.
+ */
+ buff = a->resource_fork;
+ rsrc_bytes = a->compressed_rsrc_position - RSRC_F_SIZE;
+ rsrc_header_bytes =
+ RSRC_H_SIZE + /* Header base size. */
+ 4 + /* Block count. */
+ (a->decmpfs_block_count * 8);/* Block info */
+ archive_be32enc(buff, 0x100);
+ archive_be32enc(buff + 4, rsrc_bytes);
+ archive_be32enc(buff + 8, rsrc_bytes - 256);
+ archive_be32enc(buff + 12, 0x32);
+ memset(buff + 16, 0, 240);
+ archive_be32enc(buff + 256, rsrc_bytes - 260);
+ return hfs_write_resource_fork(a, buff, rsrc_header_bytes, 0);
+}
+
+static size_t
+hfs_set_resource_fork_footer(unsigned char *buff, size_t buff_size)
+{
+ static const char rsrc_footer[RSRC_F_SIZE] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x1c, 0x00, 0x32, 0x00, 0x00, 'c', 'm',
+ 'p', 'f', 0x00, 0x00, 0x00, 0x0a, 0x00, 0x01,
+ 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00
+ };
+ if (buff_size < sizeof(rsrc_footer))
+ return (0);
+ memcpy(buff, rsrc_footer, sizeof(rsrc_footer));
+ return (sizeof(rsrc_footer));
+}
+
+static int
+hfs_reset_compressor(struct archive_write_disk *a)
+{
+ int ret;
+
+ if (a->stream_valid)
+ ret = deflateReset(&a->stream);
+ else
+ ret = deflateInit(&a->stream, a->decmpfs_compression_level);
+
+ if (ret != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to initialize compressor");
+ return (ARCHIVE_FATAL);
+ } else
+ a->stream_valid = 1;
+
+ return (ARCHIVE_OK);
+}
+
+static int
+hfs_decompress(struct archive_write_disk *a)
+{
+ uint32_t *block_info;
+ unsigned int block_count;
+ uint32_t data_pos, data_size;
+ ssize_t r;
+ ssize_t bytes_written, bytes_to_write;
+ unsigned char *b;
+
+ block_info = (uint32_t *)(a->resource_fork + RSRC_H_SIZE);
+ block_count = archive_le32dec(block_info++);
+ while (block_count--) {
+ data_pos = RSRC_H_SIZE + archive_le32dec(block_info++);
+ data_size = archive_le32dec(block_info++);
+ r = fgetxattr(a->fd, XATTR_RESOURCEFORK_NAME,
+ a->compressed_buffer, data_size, data_pos, 0);
+ if (r != data_size) {
+ archive_set_error(&a->archive,
+ (r < 0)?errno:ARCHIVE_ERRNO_MISC,
+ "Failed to read resource fork");
+ return (ARCHIVE_WARN);
+ }
+ if (a->compressed_buffer[0] == 0xff) {
+ bytes_to_write = data_size -1;
+ b = a->compressed_buffer + 1;
+ } else {
+ uLong dest_len = MAX_DECMPFS_BLOCK_SIZE;
+ int zr;
+
+ zr = uncompress((Bytef *)a->uncompressed_buffer,
+ &dest_len, a->compressed_buffer, data_size);
+ if (zr != Z_OK) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Failed to decompress resource fork");
+ return (ARCHIVE_WARN);
+ }
+ bytes_to_write = dest_len;
+ b = (unsigned char *)a->uncompressed_buffer;
+ }
+ do {
+ bytes_written = write(a->fd, b, bytes_to_write);
+ if (bytes_written < 0) {
+ archive_set_error(&a->archive, errno,
+ "Write failed");
+ return (ARCHIVE_WARN);
+ }
+ bytes_to_write -= bytes_written;
+ b += bytes_written;
+ } while (bytes_to_write > 0);
+ }
+ r = fremovexattr(a->fd, XATTR_RESOURCEFORK_NAME, 0);
+ if (r == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to remove resource fork");
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+hfs_drive_compressor(struct archive_write_disk *a, const char *buff,
+ size_t size)
+{
+ unsigned char *buffer_compressed;
+ size_t bytes_compressed;
+ size_t bytes_used;
+ int ret;
+
+ ret = hfs_reset_compressor(a);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ if (a->compressed_buffer == NULL) {
+ size_t block_size;
+
+ block_size = COMPRESSED_W_SIZE + RSRC_F_SIZE +
+ + compressBound(MAX_DECMPFS_BLOCK_SIZE);
+ a->compressed_buffer = malloc(block_size);
+ if (a->compressed_buffer == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Resource Fork");
+ return (ARCHIVE_FATAL);
+ }
+ a->compressed_buffer_size = block_size;
+ a->compressed_buffer_remaining = block_size;
+ }
+
+ buffer_compressed = a->compressed_buffer +
+ a->compressed_buffer_size - a->compressed_buffer_remaining;
+ a->stream.next_in = (Bytef *)(uintptr_t)(const void *)buff;
+ a->stream.avail_in = size;
+ a->stream.next_out = buffer_compressed;
+ a->stream.avail_out = a->compressed_buffer_remaining;
+ do {
+ ret = deflate(&a->stream, Z_FINISH);
+ switch (ret) {
+ case Z_OK:
+ case Z_STREAM_END:
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to compress data");
+ return (ARCHIVE_FAILED);
+ }
+ } while (ret == Z_OK);
+ bytes_compressed = a->compressed_buffer_remaining - a->stream.avail_out;
+
+ /*
+ * If the compressed size is larger than the original size,
+ * throw away compressed data, use uncompressed data instead.
+ */
+ if (bytes_compressed > size) {
+ buffer_compressed[0] = 0xFF;/* uncompressed marker. */
+ memcpy(buffer_compressed + 1, buff, size);
+ bytes_compressed = size + 1;
+ }
+ a->compressed_buffer_remaining -= bytes_compressed;
+
+ /*
+ * If the compressed size is smaller than MAX_DECMPFS_XATTR_SIZE
+ * and the block count in the file is only one, store compressed
+ * data to decmpfs xattr instead of the resource fork.
+ */
+ if (a->decmpfs_block_count == 1 &&
+ (a->decmpfs_attr_size + bytes_compressed)
+ <= MAX_DECMPFS_XATTR_SIZE) {
+ archive_le32enc(&a->decmpfs_header_p[DECMPFS_COMPRESSION_TYPE],
+ CMP_XATTR);
+ memcpy(a->decmpfs_header_p + DECMPFS_HEADER_SIZE,
+ buffer_compressed, bytes_compressed);
+ a->decmpfs_attr_size += bytes_compressed;
+ a->compressed_buffer_remaining = a->compressed_buffer_size;
+ /*
+ * Finish HFS+ Compression.
+ * - Write the decmpfs xattr.
+ * - Set the UF_COMPRESSED file flag.
+ */
+ ret = hfs_write_decmpfs(a);
+ if (ret == ARCHIVE_OK)
+ ret = hfs_set_compressed_fflag(a);
+ return (ret);
+ }
+
+ /* Update block info. */
+ archive_le32enc(a->decmpfs_block_info++,
+ a->compressed_rsrc_position_v - RSRC_H_SIZE);
+ archive_le32enc(a->decmpfs_block_info++, bytes_compressed);
+ a->compressed_rsrc_position_v += bytes_compressed;
+
+ /*
+ * Write the compressed data to the resource fork.
+ */
+ bytes_used = a->compressed_buffer_size - a->compressed_buffer_remaining;
+ while (bytes_used >= COMPRESSED_W_SIZE) {
+ ret = hfs_write_compressed_data(a, COMPRESSED_W_SIZE);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ bytes_used -= COMPRESSED_W_SIZE;
+ if (bytes_used > COMPRESSED_W_SIZE)
+ memmove(a->compressed_buffer,
+ a->compressed_buffer + COMPRESSED_W_SIZE,
+ bytes_used);
+ else
+ memcpy(a->compressed_buffer,
+ a->compressed_buffer + COMPRESSED_W_SIZE,
+ bytes_used);
+ }
+ a->compressed_buffer_remaining = a->compressed_buffer_size - bytes_used;
+
+ /*
+ * If the current block is the last block, write the remaining
+ * compressed data and the resource fork footer.
+ */
+ if (a->file_remaining_bytes == 0) {
+ size_t rsrc_size;
+ int64_t bk;
+
+ /* Append the resource footer. */
+ rsrc_size = hfs_set_resource_fork_footer(
+ a->compressed_buffer + bytes_used,
+ a->compressed_buffer_remaining);
+ ret = hfs_write_compressed_data(a, bytes_used + rsrc_size);
+ a->compressed_buffer_remaining = a->compressed_buffer_size;
+
+ /* If the compressed size is not enouph smaller than
+ * the uncompressed size. cancel HFS+ compression.
+ * TODO: study a behavior of ditto utility and improve
+ * the condition to fall back into no HFS+ compression. */
+ bk = HFS_BLOCKS(a->compressed_rsrc_position);
+ bk += bk >> 7;
+ if (bk > HFS_BLOCKS(a->filesize))
+ return hfs_decompress(a);
+ /*
+ * Write the resourcefork header.
+ */
+ if (ret == ARCHIVE_OK)
+ ret = hfs_write_resource_fork_header(a);
+ /*
+ * Finish HFS+ Compression.
+ * - Write the decmpfs xattr.
+ * - Set the UF_COMPRESSED file flag.
+ */
+ if (ret == ARCHIVE_OK)
+ ret = hfs_write_decmpfs(a);
+ if (ret == ARCHIVE_OK)
+ ret = hfs_set_compressed_fflag(a);
+ }
+ return (ret);
+}
+
+static ssize_t
+hfs_write_decmpfs_block(struct archive_write_disk *a, const char *buff,
+ size_t size)
+{
+ const char *buffer_to_write;
+ size_t bytes_to_write;
+ int ret;
+
+ if (a->decmpfs_block_count == (unsigned)-1) {
+ void *new_block;
+ size_t new_size;
+ unsigned int block_count;
+
+ if (a->decmpfs_header_p == NULL) {
+ new_block = malloc(MAX_DECMPFS_XATTR_SIZE
+ + sizeof(uint32_t));
+ if (new_block == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for decmpfs");
+ return (ARCHIVE_FATAL);
+ }
+ a->decmpfs_header_p = new_block;
+ }
+ a->decmpfs_attr_size = DECMPFS_HEADER_SIZE;
+ archive_le32enc(&a->decmpfs_header_p[DECMPFS_COMPRESSION_MAGIC],
+ DECMPFS_MAGIC);
+ archive_le32enc(&a->decmpfs_header_p[DECMPFS_COMPRESSION_TYPE],
+ CMP_RESOURCE_FORK);
+ archive_le64enc(&a->decmpfs_header_p[DECMPFS_UNCOMPRESSED_SIZE],
+ a->filesize);
+
+ /* Calculate a block count of the file. */
+ block_count =
+ (a->filesize + MAX_DECMPFS_BLOCK_SIZE -1) /
+ MAX_DECMPFS_BLOCK_SIZE;
+ /*
+ * Allocate buffer for resource fork.
+ * Set up related pointers;
+ */
+ new_size =
+ RSRC_H_SIZE + /* header */
+ 4 + /* Block count */
+ (block_count * sizeof(uint32_t) * 2) +
+ RSRC_F_SIZE; /* footer */
+ if (new_size > a->resource_fork_allocated_size) {
+ new_block = realloc(a->resource_fork, new_size);
+ if (new_block == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for ResourceFork");
+ return (ARCHIVE_FATAL);
+ }
+ a->resource_fork_allocated_size = new_size;
+ a->resource_fork = new_block;
+ }
+
+ /* Allocate uncompressed buffer */
+ if (a->uncompressed_buffer == NULL) {
+ new_block = malloc(MAX_DECMPFS_BLOCK_SIZE);
+ if (new_block == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for decmpfs");
+ return (ARCHIVE_FATAL);
+ }
+ a->uncompressed_buffer = new_block;
+ }
+ a->block_remaining_bytes = MAX_DECMPFS_BLOCK_SIZE;
+ a->file_remaining_bytes = a->filesize;
+ a->compressed_buffer_remaining = a->compressed_buffer_size;
+
+ /*
+ * Set up a resource fork.
+ */
+ a->rsrc_xattr_options = XATTR_CREATE;
+ /* Get the position where we are going to set a bunch
+ * of block info. */
+ a->decmpfs_block_info =
+ (uint32_t *)(a->resource_fork + RSRC_H_SIZE);
+ /* Set the block count to the resource fork. */
+ archive_le32enc(a->decmpfs_block_info++, block_count);
+ /* Get the position where we are goint to set compressed
+ * data. */
+ a->compressed_rsrc_position =
+ RSRC_H_SIZE + 4 + (block_count * 8);
+ a->compressed_rsrc_position_v = a->compressed_rsrc_position;
+ a->decmpfs_block_count = block_count;
+ }
+
+ /* Ignore redundant bytes. */
+ if (a->file_remaining_bytes == 0)
+ return ((ssize_t)size);
+
+ /* Do not overrun a block size. */
+ if (size > a->block_remaining_bytes)
+ bytes_to_write = a->block_remaining_bytes;
+ else
+ bytes_to_write = size;
+ /* Do not overrun the file size. */
+ if (bytes_to_write > a->file_remaining_bytes)
+ bytes_to_write = a->file_remaining_bytes;
+
+ /* For efficiency, if a copy length is full of the uncompressed
+ * buffer size, do not copy writing data to it. */
+ if (bytes_to_write == MAX_DECMPFS_BLOCK_SIZE)
+ buffer_to_write = buff;
+ else {
+ memcpy(a->uncompressed_buffer +
+ MAX_DECMPFS_BLOCK_SIZE - a->block_remaining_bytes,
+ buff, bytes_to_write);
+ buffer_to_write = a->uncompressed_buffer;
+ }
+ a->block_remaining_bytes -= bytes_to_write;
+ a->file_remaining_bytes -= bytes_to_write;
+
+ if (a->block_remaining_bytes == 0 || a->file_remaining_bytes == 0) {
+ ret = hfs_drive_compressor(a, buffer_to_write,
+ MAX_DECMPFS_BLOCK_SIZE - a->block_remaining_bytes);
+ if (ret < 0)
+ return (ret);
+ a->block_remaining_bytes = MAX_DECMPFS_BLOCK_SIZE;
+ }
+ /* Ignore redundant bytes. */
+ if (a->file_remaining_bytes == 0)
+ return ((ssize_t)size);
+ return (bytes_to_write);
+}
+
+static ssize_t
+hfs_write_data_block(struct archive_write_disk *a, const char *buff,
+ size_t size)
+{
+ uint64_t start_size = size;
+ ssize_t bytes_written = 0;
+ ssize_t bytes_to_write;
+
+ if (size == 0)
+ return (ARCHIVE_OK);
+
+ if (a->filesize == 0 || a->fd < 0) {
+ archive_set_error(&a->archive, 0,
+ "Attempt to write to an empty file");
+ return (ARCHIVE_WARN);
+ }
+
+ /* If this write would run beyond the file size, truncate it. */
+ if (a->filesize >= 0 && (int64_t)(a->offset + size) > a->filesize)
+ start_size = size = (size_t)(a->filesize - a->offset);
+
+ /* Write the data. */
+ while (size > 0) {
+ bytes_to_write = size;
+ /* Seek if necessary to the specified offset. */
+ if (a->offset < a->fd_offset) {
+ /* Can't support backword move. */
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Seek failed");
+ return (ARCHIVE_FATAL);
+ } else if (a->offset > a->fd_offset) {
+ int64_t skip = a->offset - a->fd_offset;
+ char nullblock[1024];
+
+ memset(nullblock, 0, sizeof(nullblock));
+ while (skip > 0) {
+ if (skip > (int64_t)sizeof(nullblock))
+ bytes_written = hfs_write_decmpfs_block(
+ a, nullblock, sizeof(nullblock));
+ else
+ bytes_written = hfs_write_decmpfs_block(
+ a, nullblock, skip);
+ if (bytes_written < 0) {
+ archive_set_error(&a->archive, errno,
+ "Write failed");
+ return (ARCHIVE_WARN);
+ }
+ skip -= bytes_written;
+ }
+
+ a->fd_offset = a->offset;
+ }
+ bytes_written =
+ hfs_write_decmpfs_block(a, buff, bytes_to_write);
+ if (bytes_written < 0)
+ return (bytes_written);
+ buff += bytes_written;
+ size -= bytes_written;
+ a->total_bytes_written += bytes_written;
+ a->offset += bytes_written;
+ a->fd_offset = a->offset;
+ }
+ return (start_size - size);
+}
+#else
+static ssize_t
+hfs_write_data_block(struct archive_write_disk *a, const char *buff,
+ size_t size)
+{
+ return (write_data_block(a, buff, size));
+}
+#endif
+
+static ssize_t
+_archive_write_disk_data_block(struct archive *_a,
+ const void *buff, size_t size, int64_t offset)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ ssize_t r;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_DATA, "archive_write_data_block");
+
+ a->offset = offset;
+ if (a->todo & TODO_HFS_COMPRESSION)
+ r = hfs_write_data_block(a, buff, size);
+ else
+ r = write_data_block(a, buff, size);
+ if (r < ARCHIVE_OK)
+ return (r);
+ if ((size_t)r < size) {
+ archive_set_error(&a->archive, 0,
+ "Write request too large");
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+_archive_write_disk_data(struct archive *_a, const void *buff, size_t size)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_DATA, "archive_write_data");
+
+ if (a->todo & TODO_HFS_COMPRESSION)
+ return (hfs_write_data_block(a, buff, size));
+ return (write_data_block(a, buff, size));
+}
+
+static int
+_archive_write_disk_finish_entry(struct archive *_a)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ int ret = ARCHIVE_OK;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_write_finish_entry");
+ if (a->archive.state & ARCHIVE_STATE_HEADER)
+ return (ARCHIVE_OK);
+ archive_clear_error(&a->archive);
+
+ /* Pad or truncate file to the right size. */
+ if (a->fd < 0) {
+ /* There's no file. */
+ } else if (a->filesize < 0) {
+ /* File size is unknown, so we can't set the size. */
+ } else if (a->fd_offset == a->filesize) {
+ /* Last write ended at exactly the filesize; we're done. */
+ /* Hopefully, this is the common case. */
+#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_ZLIB_H)
+ } else if (a->todo & TODO_HFS_COMPRESSION) {
+ char null_d[1024];
+ ssize_t r;
+
+ if (a->file_remaining_bytes)
+ memset(null_d, 0, sizeof(null_d));
+ while (a->file_remaining_bytes) {
+ if (a->file_remaining_bytes > sizeof(null_d))
+ r = hfs_write_data_block(
+ a, null_d, sizeof(null_d));
+ else
+ r = hfs_write_data_block(
+ a, null_d, a->file_remaining_bytes);
+ if (r < 0)
+ return ((int)r);
+ }
+#endif
+ } else {
+#if HAVE_FTRUNCATE
+ if (ftruncate(a->fd, a->filesize) == -1 &&
+ a->filesize == 0) {
+ archive_set_error(&a->archive, errno,
+ "File size could not be restored");
+ return (ARCHIVE_FAILED);
+ }
+#endif
+ /*
+ * Not all platforms implement the XSI option to
+ * extend files via ftruncate. Stat() the file again
+ * to see what happened.
+ */
+ a->pst = NULL;
+ if ((ret = lazy_stat(a)) != ARCHIVE_OK)
+ return (ret);
+ /* We can use lseek()/write() to extend the file if
+ * ftruncate didn't work or isn't available. */
+ if (a->st.st_size < a->filesize) {
+ const char nul = '\0';
+ if (lseek(a->fd, a->filesize - 1, SEEK_SET) < 0) {
+ archive_set_error(&a->archive, errno,
+ "Seek failed");
+ return (ARCHIVE_FATAL);
+ }
+ if (write(a->fd, &nul, 1) < 0) {
+ archive_set_error(&a->archive, errno,
+ "Write to restore size failed");
+ return (ARCHIVE_FATAL);
+ }
+ a->pst = NULL;
+ }
+ }
+
+ /* Restore metadata. */
+
+ /*
+ * This is specific to Mac OS X.
+ * If the current file is an AppleDouble file, it should be
+ * linked with the data fork file and remove it.
+ */
+ if (a->todo & TODO_APPLEDOUBLE) {
+ int r2 = fixup_appledouble(a, a->name);
+ if (r2 == ARCHIVE_EOF) {
+ /* The current file has been successfully linked
+ * with the data fork file and removed. So there
+ * is nothing to do on the current file. */
+ goto finish_metadata;
+ }
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * Look up the "real" UID only if we're going to need it.
+ * TODO: the TODO_SGID condition can be dropped here, can't it?
+ */
+ if (a->todo & (TODO_OWNER | TODO_SUID | TODO_SGID)) {
+ a->uid = archive_write_disk_uid(&a->archive,
+ archive_entry_uname(a->entry),
+ archive_entry_uid(a->entry));
+ }
+ /* Look up the "real" GID only if we're going to need it. */
+ /* TODO: the TODO_SUID condition can be dropped here, can't it? */
+ if (a->todo & (TODO_OWNER | TODO_SGID | TODO_SUID)) {
+ a->gid = archive_write_disk_gid(&a->archive,
+ archive_entry_gname(a->entry),
+ archive_entry_gid(a->entry));
+ }
+
+ /*
+ * Restore ownership before set_mode tries to restore suid/sgid
+ * bits. If we set the owner, we know what it is and can skip
+ * a stat() call to examine the ownership of the file on disk.
+ */
+ if (a->todo & TODO_OWNER) {
+ int r2 = set_ownership(a);
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * set_mode must precede ACLs on systems such as Solaris and
+ * FreeBSD where setting the mode implicitly clears extended ACLs
+ */
+ if (a->todo & TODO_MODE) {
+ int r2 = set_mode(a, a->mode);
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * Security-related extended attributes (such as
+ * security.capability on Linux) have to be restored last,
+ * since they're implicitly removed by other file changes.
+ */
+ if (a->todo & TODO_XATTR) {
+ int r2 = set_xattrs(a);
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * Some flags prevent file modification; they must be restored after
+ * file contents are written.
+ */
+ if (a->todo & TODO_FFLAGS) {
+ int r2 = set_fflags(a);
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * Time must follow most other metadata;
+ * otherwise atime will get changed.
+ */
+ if (a->todo & TODO_TIMES) {
+ int r2 = set_times_from_entry(a);
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * Mac extended metadata includes ACLs.
+ */
+ if (a->todo & TODO_MAC_METADATA) {
+ const void *metadata;
+ size_t metadata_size;
+ metadata = archive_entry_mac_metadata(a->entry, &metadata_size);
+ if (metadata != NULL && metadata_size > 0) {
+ int r2 = set_mac_metadata(a, archive_entry_pathname(
+ a->entry), metadata, metadata_size);
+ if (r2 < ret) ret = r2;
+ }
+ }
+
+ /*
+ * ACLs must be restored after timestamps because there are
+ * ACLs that prevent attribute changes (including time).
+ */
+ if (a->todo & TODO_ACLS) {
+ int r2 = archive_write_disk_set_acls(&a->archive, a->fd,
+ archive_entry_pathname(a->entry),
+ archive_entry_acl(a->entry));
+ if (r2 < ret) ret = r2;
+ }
+
+finish_metadata:
+ /* If there's an fd, we can close it now. */
+ if (a->fd >= 0) {
+ close(a->fd);
+ a->fd = -1;
+ }
+ /* If there's an entry, we can release it now. */
+ if (a->entry) {
+ archive_entry_free(a->entry);
+ a->entry = NULL;
+ }
+ a->archive.state = ARCHIVE_STATE_HEADER;
+ return (ret);
+}
+
+int
+archive_write_disk_set_group_lookup(struct archive *_a,
+ void *private_data,
+ int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid),
+ void (*cleanup_gid)(void *private))
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_set_group_lookup");
+
+ if (a->cleanup_gid != NULL && a->lookup_gid_data != NULL)
+ (a->cleanup_gid)(a->lookup_gid_data);
+
+ a->lookup_gid = lookup_gid;
+ a->cleanup_gid = cleanup_gid;
+ a->lookup_gid_data = private_data;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_write_disk_set_user_lookup(struct archive *_a,
+ void *private_data,
+ int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid),
+ void (*cleanup_uid)(void *private))
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_set_user_lookup");
+
+ if (a->cleanup_uid != NULL && a->lookup_uid_data != NULL)
+ (a->cleanup_uid)(a->lookup_uid_data);
+
+ a->lookup_uid = lookup_uid;
+ a->cleanup_uid = cleanup_uid;
+ a->lookup_uid_data = private_data;
+ return (ARCHIVE_OK);
+}
+
+int64_t
+archive_write_disk_gid(struct archive *_a, const char *name, int64_t id)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_gid");
+ if (a->lookup_gid)
+ return (a->lookup_gid)(a->lookup_gid_data, name, id);
+ return (id);
+}
+
+int64_t
+archive_write_disk_uid(struct archive *_a, const char *name, int64_t id)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_uid");
+ if (a->lookup_uid)
+ return (a->lookup_uid)(a->lookup_uid_data, name, id);
+ return (id);
+}
+
+/*
+ * Create a new archive_write_disk object and initialize it with global state.
+ */
+struct archive *
+archive_write_disk_new(void)
+{
+ struct archive_write_disk *a;
+
+ a = (struct archive_write_disk *)malloc(sizeof(*a));
+ if (a == NULL)
+ return (NULL);
+ memset(a, 0, sizeof(*a));
+ a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC;
+ /* We're ready to write a header immediately. */
+ a->archive.state = ARCHIVE_STATE_HEADER;
+ a->archive.vtable = archive_write_disk_vtable();
+ a->start_time = time(NULL);
+ /* Query and restore the umask. */
+ umask(a->user_umask = umask(0));
+#ifdef HAVE_GETEUID
+ a->user_uid = geteuid();
+#endif /* HAVE_GETEUID */
+ if (archive_string_ensure(&a->path_safe, 512) == NULL) {
+ free(a);
+ return (NULL);
+ }
+#ifdef HAVE_ZLIB_H
+ a->decmpfs_compression_level = 5;
+#endif
+ return (&a->archive);
+}
+
+
+/*
+ * If pathname is longer than PATH_MAX, chdir to a suitable
+ * intermediate dir and edit the path down to a shorter suffix. Note
+ * that this routine never returns an error; if the chdir() attempt
+ * fails for any reason, we just go ahead with the long pathname. The
+ * object creation is likely to fail, but any error will get handled
+ * at that time.
+ */
+#if defined(HAVE_FCHDIR) && defined(PATH_MAX)
+static void
+edit_deep_directories(struct archive_write_disk *a)
+{
+ int ret;
+ char *tail = a->name;
+
+ /* If path is short, avoid the open() below. */
+ if (strlen(tail) <= PATH_MAX)
+ return;
+
+ /* Try to record our starting dir. */
+ a->restore_pwd = open(".", O_RDONLY | O_BINARY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(a->restore_pwd);
+ if (a->restore_pwd < 0)
+ return;
+
+ /* As long as the path is too long... */
+ while (strlen(tail) > PATH_MAX) {
+ /* Locate a dir prefix shorter than PATH_MAX. */
+ tail += PATH_MAX - 8;
+ while (tail > a->name && *tail != '/')
+ tail--;
+ /* Exit if we find a too-long path component. */
+ if (tail <= a->name)
+ return;
+ /* Create the intermediate dir and chdir to it. */
+ *tail = '\0'; /* Terminate dir portion */
+ ret = create_dir(a, a->name);
+ if (ret == ARCHIVE_OK && chdir(a->name) != 0)
+ ret = ARCHIVE_FAILED;
+ *tail = '/'; /* Restore the / we removed. */
+ if (ret != ARCHIVE_OK)
+ return;
+ tail++;
+ /* The chdir() succeeded; we've now shortened the path. */
+ a->name = tail;
+ }
+ return;
+}
+#endif
+
+/*
+ * The main restore function.
+ */
+static int
+restore_entry(struct archive_write_disk *a)
+{
+ int ret = ARCHIVE_OK, en;
+
+ if (a->flags & ARCHIVE_EXTRACT_UNLINK && !S_ISDIR(a->mode)) {
+ /*
+ * TODO: Fix this. Apparently, there are platforms
+ * that still allow root to hose the entire filesystem
+ * by unlinking a dir. The S_ISDIR() test above
+ * prevents us from using unlink() here if the new
+ * object is a dir, but that doesn't mean the old
+ * object isn't a dir.
+ */
+ if (unlink(a->name) == 0) {
+ /* We removed it, reset cached stat. */
+ a->pst = NULL;
+ } else if (errno == ENOENT) {
+ /* File didn't exist, that's just as good. */
+ } else if (rmdir(a->name) == 0) {
+ /* It was a dir, but now it's gone. */
+ a->pst = NULL;
+ } else {
+ /* We tried, but couldn't get rid of it. */
+ archive_set_error(&a->archive, errno,
+ "Could not unlink");
+ return(ARCHIVE_FAILED);
+ }
+ }
+
+ /* Try creating it first; if this fails, we'll try to recover. */
+ en = create_filesystem_object(a);
+
+ if ((en == ENOTDIR || en == ENOENT)
+ && !(a->flags & ARCHIVE_EXTRACT_NO_AUTODIR)) {
+ /* If the parent dir doesn't exist, try creating it. */
+ create_parent_dir(a, a->name);
+ /* Now try to create the object again. */
+ en = create_filesystem_object(a);
+ }
+
+ if ((en == EISDIR || en == EEXIST)
+ && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) {
+ /* If we're not overwriting, we're done. */
+ archive_entry_unset_size(a->entry);
+ return (ARCHIVE_OK);
+ }
+
+ /*
+ * Some platforms return EISDIR if you call
+ * open(O_WRONLY | O_EXCL | O_CREAT) on a directory, some
+ * return EEXIST. POSIX is ambiguous, requiring EISDIR
+ * for open(O_WRONLY) on a dir and EEXIST for open(O_EXCL | O_CREAT)
+ * on an existing item.
+ */
+ if (en == EISDIR) {
+ /* A dir is in the way of a non-dir, rmdir it. */
+ if (rmdir(a->name) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't remove already-existing dir");
+ return (ARCHIVE_FAILED);
+ }
+ a->pst = NULL;
+ /* Try again. */
+ en = create_filesystem_object(a);
+ } else if (en == EEXIST) {
+ /*
+ * We know something is in the way, but we don't know what;
+ * we need to find out before we go any further.
+ */
+ int r = 0;
+ /*
+ * The SECURE_SYMLINKS logic has already removed a
+ * symlink to a dir if the client wants that. So
+ * follow the symlink if we're creating a dir.
+ */
+ if (S_ISDIR(a->mode))
+ r = stat(a->name, &a->st);
+ /*
+ * If it's not a dir (or it's a broken symlink),
+ * then don't follow it.
+ */
+ if (r != 0 || !S_ISDIR(a->mode))
+ r = lstat(a->name, &a->st);
+ if (r != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't stat existing object");
+ return (ARCHIVE_FAILED);
+ }
+
+ /*
+ * NO_OVERWRITE_NEWER doesn't apply to directories.
+ */
+ if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER)
+ && !S_ISDIR(a->st.st_mode)) {
+ if (!older(&(a->st), a->entry)) {
+ archive_entry_unset_size(a->entry);
+ return (ARCHIVE_OK);
+ }
+ }
+
+ /* If it's our archive, we're done. */
+ if (a->skip_file_set &&
+ a->st.st_dev == (dev_t)a->skip_file_dev &&
+ a->st.st_ino == (ino_t)a->skip_file_ino) {
+ archive_set_error(&a->archive, 0,
+ "Refusing to overwrite archive");
+ return (ARCHIVE_FAILED);
+ }
+
+ if (!S_ISDIR(a->st.st_mode)) {
+ /* A non-dir is in the way, unlink it. */
+ if (unlink(a->name) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't unlink already-existing object");
+ return (ARCHIVE_FAILED);
+ }
+ a->pst = NULL;
+ /* Try again. */
+ en = create_filesystem_object(a);
+ } else if (!S_ISDIR(a->mode)) {
+ /* A dir is in the way of a non-dir, rmdir it. */
+ if (rmdir(a->name) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't replace existing directory with non-directory");
+ return (ARCHIVE_FAILED);
+ }
+ /* Try again. */
+ en = create_filesystem_object(a);
+ } else {
+ /*
+ * There's a dir in the way of a dir. Don't
+ * waste time with rmdir()/mkdir(), just fix
+ * up the permissions on the existing dir.
+ * Note that we don't change perms on existing
+ * dirs unless _EXTRACT_PERM is specified.
+ */
+ if ((a->mode != a->st.st_mode)
+ && (a->todo & TODO_MODE_FORCE))
+ a->deferred |= (a->todo & TODO_MODE);
+ /* Ownership doesn't need deferred fixup. */
+ en = 0; /* Forget the EEXIST. */
+ }
+ }
+
+ if (en) {
+ /* Everything failed; give up here. */
+ archive_set_error(&a->archive, en, "Can't create '%s'",
+ a->name);
+ return (ARCHIVE_FAILED);
+ }
+
+ a->pst = NULL; /* Cached stat data no longer valid. */
+ return (ret);
+}
+
+/*
+ * Returns 0 if creation succeeds, or else returns errno value from
+ * the failed system call. Note: This function should only ever perform
+ * a single system call.
+ */
+static int
+create_filesystem_object(struct archive_write_disk *a)
+{
+ /* Create the entry. */
+ const char *linkname;
+ mode_t final_mode, mode;
+ int r;
+
+ /* We identify hard/symlinks according to the link names. */
+ /* Since link(2) and symlink(2) don't handle modes, we're done here. */
+ linkname = archive_entry_hardlink(a->entry);
+ if (linkname != NULL) {
+#if !HAVE_LINK
+ return (EPERM);
+#else
+ r = link(linkname, a->name) ? errno : 0;
+ /*
+ * New cpio and pax formats allow hardlink entries
+ * to carry data, so we may have to open the file
+ * for hardlink entries.
+ *
+ * If the hardlink was successfully created and
+ * the archive doesn't have carry data for it,
+ * consider it to be non-authoritative for meta data.
+ * This is consistent with GNU tar and BSD pax.
+ * If the hardlink does carry data, let the last
+ * archive entry decide ownership.
+ */
+ if (r == 0 && a->filesize <= 0) {
+ a->todo = 0;
+ a->deferred = 0;
+ } else if (r == 0 && a->filesize > 0) {
+ a->fd = open(a->name,
+ O_WRONLY | O_TRUNC | O_BINARY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(a->fd);
+ if (a->fd < 0)
+ r = errno;
+ }
+ return (r);
+#endif
+ }
+ linkname = archive_entry_symlink(a->entry);
+ if (linkname != NULL) {
+#if HAVE_SYMLINK
+ return symlink(linkname, a->name) ? errno : 0;
+#else
+ return (EPERM);
+#endif
+ }
+
+ /*
+ * The remaining system calls all set permissions, so let's
+ * try to take advantage of that to avoid an extra chmod()
+ * call. (Recall that umask is set to zero right now!)
+ */
+
+ /* Mode we want for the final restored object (w/o file type bits). */
+ final_mode = a->mode & 07777;
+ /*
+ * The mode that will actually be restored in this step. Note
+ * that SUID, SGID, etc, require additional work to ensure
+ * security, so we never restore them at this point.
+ */
+ mode = final_mode & 0777 & ~a->user_umask;
+
+ switch (a->mode & AE_IFMT) {
+ default:
+ /* POSIX requires that we fall through here. */
+ /* FALLTHROUGH */
+ case AE_IFREG:
+ a->fd = open(a->name,
+ O_WRONLY | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC, mode);
+ __archive_ensure_cloexec_flag(a->fd);
+ r = (a->fd < 0);
+ break;
+ case AE_IFCHR:
+#ifdef HAVE_MKNOD
+ /* Note: we use AE_IFCHR for the case label, and
+ * S_IFCHR for the mknod() call. This is correct. */
+ r = mknod(a->name, mode | S_IFCHR,
+ archive_entry_rdev(a->entry));
+ break;
+#else
+ /* TODO: Find a better way to warn about our inability
+ * to restore a char device node. */
+ return (EINVAL);
+#endif /* HAVE_MKNOD */
+ case AE_IFBLK:
+#ifdef HAVE_MKNOD
+ r = mknod(a->name, mode | S_IFBLK,
+ archive_entry_rdev(a->entry));
+ break;
+#else
+ /* TODO: Find a better way to warn about our inability
+ * to restore a block device node. */
+ return (EINVAL);
+#endif /* HAVE_MKNOD */
+ case AE_IFDIR:
+ mode = (mode | MINIMUM_DIR_MODE) & MAXIMUM_DIR_MODE;
+ r = mkdir(a->name, mode);
+ if (r == 0) {
+ /* Defer setting dir times. */
+ a->deferred |= (a->todo & TODO_TIMES);
+ a->todo &= ~TODO_TIMES;
+ /* Never use an immediate chmod(). */
+ /* We can't avoid the chmod() entirely if EXTRACT_PERM
+ * because of SysV SGID inheritance. */
+ if ((mode != final_mode)
+ || (a->flags & ARCHIVE_EXTRACT_PERM))
+ a->deferred |= (a->todo & TODO_MODE);
+ a->todo &= ~TODO_MODE;
+ }
+ break;
+ case AE_IFIFO:
+#ifdef HAVE_MKFIFO
+ r = mkfifo(a->name, mode);
+ break;
+#else
+ /* TODO: Find a better way to warn about our inability
+ * to restore a fifo. */
+ return (EINVAL);
+#endif /* HAVE_MKFIFO */
+ }
+
+ /* All the system calls above set errno on failure. */
+ if (r)
+ return (errno);
+
+ /* If we managed to set the final mode, we've avoided a chmod(). */
+ if (mode == final_mode)
+ a->todo &= ~TODO_MODE;
+ return (0);
+}
+
+/*
+ * Cleanup function for archive_extract. Mostly, this involves processing
+ * the fixup list, which is used to address a number of problems:
+ * * Dir permissions might prevent us from restoring a file in that
+ * dir, so we restore the dir with minimum 0700 permissions first,
+ * then correct the mode at the end.
+ * * Similarly, the act of restoring a file touches the directory
+ * and changes the timestamp on the dir, so we have to touch-up dir
+ * timestamps at the end as well.
+ * * Some file flags can interfere with the restore by, for example,
+ * preventing the creation of hardlinks to those files.
+ * * Mac OS extended metadata includes ACLs, so must be deferred on dirs.
+ *
+ * Note that tar/cpio do not require that archives be in a particular
+ * order; there is no way to know when the last file has been restored
+ * within a directory, so there's no way to optimize the memory usage
+ * here by fixing up the directory any earlier than the
+ * end-of-archive.
+ *
+ * XXX TODO: Directory ACLs should be restored here, for the same
+ * reason we set directory perms here. XXX
+ */
+static int
+_archive_write_disk_close(struct archive *_a)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ struct fixup_entry *next, *p;
+ int ret;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_write_disk_close");
+ ret = _archive_write_disk_finish_entry(&a->archive);
+
+ /* Sort dir list so directories are fixed up in depth-first order. */
+ p = sort_dir_list(a->fixup_list);
+
+ while (p != NULL) {
+ a->pst = NULL; /* Mark stat cache as out-of-date. */
+ if (p->fixup & TODO_TIMES) {
+ set_times(a, -1, p->mode, p->name,
+ p->atime, p->atime_nanos,
+ p->birthtime, p->birthtime_nanos,
+ p->mtime, p->mtime_nanos,
+ p->ctime, p->ctime_nanos);
+ }
+ if (p->fixup & TODO_MODE_BASE)
+ chmod(p->name, p->mode);
+ if (p->fixup & TODO_ACLS)
+ archive_write_disk_set_acls(&a->archive,
+ -1, p->name, &p->acl);
+ if (p->fixup & TODO_FFLAGS)
+ set_fflags_platform(a, -1, p->name,
+ p->mode, p->fflags_set, 0);
+ if (p->fixup & TODO_MAC_METADATA)
+ set_mac_metadata(a, p->name, p->mac_metadata,
+ p->mac_metadata_size);
+ next = p->next;
+ archive_acl_clear(&p->acl);
+ free(p->mac_metadata);
+ free(p->name);
+ free(p);
+ p = next;
+ }
+ a->fixup_list = NULL;
+ return (ret);
+}
+
+static int
+_archive_write_disk_free(struct archive *_a)
+{
+ struct archive_write_disk *a;
+ int ret;
+ if (_a == NULL)
+ return (ARCHIVE_OK);
+ archive_check_magic(_a, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_write_disk_free");
+ a = (struct archive_write_disk *)_a;
+ ret = _archive_write_disk_close(&a->archive);
+ archive_write_disk_set_group_lookup(&a->archive, NULL, NULL, NULL);
+ archive_write_disk_set_user_lookup(&a->archive, NULL, NULL, NULL);
+ if (a->entry)
+ archive_entry_free(a->entry);
+ archive_string_free(&a->_name_data);
+ archive_string_free(&a->archive.error_string);
+ archive_string_free(&a->path_safe);
+ a->archive.magic = 0;
+ __archive_clean(&a->archive);
+ free(a->decmpfs_header_p);
+ free(a->resource_fork);
+ free(a->compressed_buffer);
+ free(a->uncompressed_buffer);
+#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_SYS_XATTR_H)\
+ && defined(HAVE_ZLIB_H)
+ if (a->stream_valid) {
+ switch (deflateEnd(&a->stream)) {
+ case Z_OK:
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to clean up compressor");
+ ret = ARCHIVE_FATAL;
+ break;
+ }
+ }
+#endif
+ free(a);
+ return (ret);
+}
+
+/*
+ * Simple O(n log n) merge sort to order the fixup list. In
+ * particular, we want to restore dir timestamps depth-first.
+ */
+static struct fixup_entry *
+sort_dir_list(struct fixup_entry *p)
+{
+ struct fixup_entry *a, *b, *t;
+
+ if (p == NULL)
+ return (NULL);
+ /* A one-item list is already sorted. */
+ if (p->next == NULL)
+ return (p);
+
+ /* Step 1: split the list. */
+ t = p;
+ a = p->next->next;
+ while (a != NULL) {
+ /* Step a twice, t once. */
+ a = a->next;
+ if (a != NULL)
+ a = a->next;
+ t = t->next;
+ }
+ /* Now, t is at the mid-point, so break the list here. */
+ b = t->next;
+ t->next = NULL;
+ a = p;
+
+ /* Step 2: Recursively sort the two sub-lists. */
+ a = sort_dir_list(a);
+ b = sort_dir_list(b);
+
+ /* Step 3: Merge the returned lists. */
+ /* Pick the first element for the merged list. */
+ if (strcmp(a->name, b->name) > 0) {
+ t = p = a;
+ a = a->next;
+ } else {
+ t = p = b;
+ b = b->next;
+ }
+
+ /* Always put the later element on the list first. */
+ while (a != NULL && b != NULL) {
+ if (strcmp(a->name, b->name) > 0) {
+ t->next = a;
+ a = a->next;
+ } else {
+ t->next = b;
+ b = b->next;
+ }
+ t = t->next;
+ }
+
+ /* Only one list is non-empty, so just splice it on. */
+ if (a != NULL)
+ t->next = a;
+ if (b != NULL)
+ t->next = b;
+
+ return (p);
+}
+
+/*
+ * Returns a new, initialized fixup entry.
+ *
+ * TODO: Reduce the memory requirements for this list by using a tree
+ * structure rather than a simple list of names.
+ */
+static struct fixup_entry *
+new_fixup(struct archive_write_disk *a, const char *pathname)
+{
+ struct fixup_entry *fe;
+
+ fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry));
+ if (fe == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for a fixup");
+ return (NULL);
+ }
+ fe->next = a->fixup_list;
+ a->fixup_list = fe;
+ fe->fixup = 0;
+ fe->name = strdup(pathname);
+ return (fe);
+}
+
+/*
+ * Returns a fixup structure for the current entry.
+ */
+static struct fixup_entry *
+current_fixup(struct archive_write_disk *a, const char *pathname)
+{
+ if (a->current_fixup == NULL)
+ a->current_fixup = new_fixup(a, pathname);
+ return (a->current_fixup);
+}
+
+/* TODO: Make this work. */
+/*
+ * TODO: The deep-directory support bypasses this; disable deep directory
+ * support if we're doing symlink checks.
+ */
+/*
+ * TODO: Someday, integrate this with the deep dir support; they both
+ * scan the path and both can be optimized by comparing against other
+ * recent paths.
+ */
+/* TODO: Extend this to support symlinks on Windows Vista and later. */
+static int
+check_symlinks(struct archive_write_disk *a)
+{
+#if !defined(HAVE_LSTAT)
+ /* Platform doesn't have lstat, so we can't look for symlinks. */
+ (void)a; /* UNUSED */
+ return (ARCHIVE_OK);
+#else
+ char *pn;
+ char c;
+ int r;
+ struct stat st;
+
+ /*
+ * Guard against symlink tricks. Reject any archive entry whose
+ * destination would be altered by a symlink.
+ */
+ /* Whatever we checked last time doesn't need to be re-checked. */
+ pn = a->name;
+ if (archive_strlen(&(a->path_safe)) > 0) {
+ char *p = a->path_safe.s;
+ while ((*pn != '\0') && (*p == *pn))
+ ++p, ++pn;
+ }
+ c = pn[0];
+ /* Keep going until we've checked the entire name. */
+ while (pn[0] != '\0' && (pn[0] != '/' || pn[1] != '\0')) {
+ /* Skip the next path element. */
+ while (*pn != '\0' && *pn != '/')
+ ++pn;
+ c = pn[0];
+ pn[0] = '\0';
+ /* Check that we haven't hit a symlink. */
+ r = lstat(a->name, &st);
+ if (r != 0) {
+ /* We've hit a dir that doesn't exist; stop now. */
+ if (errno == ENOENT)
+ break;
+ } else if (S_ISLNK(st.st_mode)) {
+ if (c == '\0') {
+ /*
+ * Last element is symlink; remove it
+ * so we can overwrite it with the
+ * item being extracted.
+ */
+ if (unlink(a->name)) {
+ archive_set_error(&a->archive, errno,
+ "Could not remove symlink %s",
+ a->name);
+ pn[0] = c;
+ return (ARCHIVE_FAILED);
+ }
+ a->pst = NULL;
+ /*
+ * Even if we did remove it, a warning
+ * is in order. The warning is silly,
+ * though, if we're just replacing one
+ * symlink with another symlink.
+ */
+ if (!S_ISLNK(a->mode)) {
+ archive_set_error(&a->archive, 0,
+ "Removing symlink %s",
+ a->name);
+ }
+ /* Symlink gone. No more problem! */
+ pn[0] = c;
+ return (0);
+ } else if (a->flags & ARCHIVE_EXTRACT_UNLINK) {
+ /* User asked us to remove problems. */
+ if (unlink(a->name) != 0) {
+ archive_set_error(&a->archive, 0,
+ "Cannot remove intervening symlink %s",
+ a->name);
+ pn[0] = c;
+ return (ARCHIVE_FAILED);
+ }
+ a->pst = NULL;
+ } else {
+ archive_set_error(&a->archive, 0,
+ "Cannot extract through symlink %s",
+ a->name);
+ pn[0] = c;
+ return (ARCHIVE_FAILED);
+ }
+ }
+ }
+ pn[0] = c;
+ /* We've checked and/or cleaned the whole path, so remember it. */
+ archive_strcpy(&a->path_safe, a->name);
+ return (ARCHIVE_OK);
+#endif
+}
+
+#if defined(__CYGWIN__)
+/*
+ * 1. Convert a path separator from '\' to '/' .
+ * We shouldn't check multibyte character directly because some
+ * character-set have been using the '\' character for a part of
+ * its multibyte character code.
+ * 2. Replace unusable characters in Windows with underscore('_').
+ * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx
+ */
+static void
+cleanup_pathname_win(struct archive_write_disk *a)
+{
+ wchar_t wc;
+ char *p;
+ size_t alen, l;
+ int mb, complete, utf8;
+
+ alen = 0;
+ mb = 0;
+ complete = 1;
+ utf8 = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)? 1: 0;
+ for (p = a->name; *p != '\0'; p++) {
+ ++alen;
+ if (*p == '\\') {
+ /* If previous byte is smaller than 128,
+ * this is not second byte of multibyte characters,
+ * so we can replace '\' with '/'. */
+ if (utf8 || !mb)
+ *p = '/';
+ else
+ complete = 0;/* uncompleted. */
+ } else if (*(unsigned char *)p > 127)
+ mb = 1;
+ else
+ mb = 0;
+ /* Rewrite the path name if its next character is unusable. */
+ if (*p == ':' || *p == '*' || *p == '?' || *p == '"' ||
+ *p == '<' || *p == '>' || *p == '|')
+ *p = '_';
+ }
+ if (complete)
+ return;
+
+ /*
+ * Convert path separator in wide-character.
+ */
+ p = a->name;
+ while (*p != '\0' && alen) {
+ l = mbtowc(&wc, p, alen);
+ if (l == (size_t)-1) {
+ while (*p != '\0') {
+ if (*p == '\\')
+ *p = '/';
+ ++p;
+ }
+ break;
+ }
+ if (l == 1 && wc == L'\\')
+ *p = '/';
+ p += l;
+ alen -= l;
+ }
+}
+#endif
+
+/*
+ * 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.
+ */
+static int
+cleanup_pathname(struct archive_write_disk *a)
+{
+ char *dest, *src;
+ char separator = '\0';
+
+ dest = src = a->name;
+ if (*src == '\0') {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid empty pathname");
+ return (ARCHIVE_FAILED);
+ }
+
+#if defined(__CYGWIN__)
+ cleanup_pathname_win(a);
+#endif
+ /* Skip leading '/'. */
+ if (*src == '/')
+ separator = *src++;
+
+ /* Scan the pathname one element at a time. */
+ for (;;) {
+ /* src points to first char after '/' */
+ if (src[0] == '\0') {
+ break;
+ } else if (src[0] == '/') {
+ /* Found '//', ignore second one. */
+ src++;
+ continue;
+ } else if (src[0] == '.') {
+ if (src[1] == '\0') {
+ /* Ignore trailing '.' */
+ break;
+ } else if (src[1] == '/') {
+ /* Skip './'. */
+ src += 2;
+ continue;
+ } else if (src[1] == '.') {
+ if (src[2] == '/' || src[2] == '\0') {
+ /* Conditionally warn about '..' */
+ if (a->flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Path contains '..'");
+ return (ARCHIVE_FAILED);
+ }
+ }
+ /*
+ * Note: Under no circumstances do we
+ * remove '..' elements. In
+ * particular, restoring
+ * '/foo/../bar/' should create the
+ * 'foo' dir as a side-effect.
+ */
+ }
+ }
+
+ /* Copy current element, including leading '/'. */
+ if (separator)
+ *dest++ = '/';
+ while (*src != '\0' && *src != '/') {
+ *dest++ = *src++;
+ }
+
+ if (*src == '\0')
+ break;
+
+ /* Skip '/' separator. */
+ separator = *src++;
+ }
+ /*
+ * We've just copied zero or more path elements, not including the
+ * final '/'.
+ */
+ if (dest == a->name) {
+ /*
+ * Nothing got copied. The path must have been something
+ * like '.' or '/' or './' or '/././././/./'.
+ */
+ if (separator)
+ *dest++ = '/';
+ else
+ *dest++ = '.';
+ }
+ /* Terminate the result. */
+ *dest = '\0';
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Create the parent directory of the specified path, assuming path
+ * is already in mutable storage.
+ */
+static int
+create_parent_dir(struct archive_write_disk *a, char *path)
+{
+ char *slash;
+ int r;
+
+ /* Remove tail element to obtain parent name. */
+ slash = strrchr(path, '/');
+ if (slash == NULL)
+ return (ARCHIVE_OK);
+ *slash = '\0';
+ r = create_dir(a, path);
+ *slash = '/';
+ return (r);
+}
+
+/*
+ * Create the specified dir, recursing to create parents as necessary.
+ *
+ * Returns ARCHIVE_OK if the path exists when we're done here.
+ * Otherwise, returns ARCHIVE_FAILED.
+ * Assumes path is in mutable storage; path is unchanged on exit.
+ */
+static int
+create_dir(struct archive_write_disk *a, char *path)
+{
+ struct stat st;
+ struct fixup_entry *le;
+ char *slash, *base;
+ mode_t mode_final, mode;
+ int r;
+
+ /* Check for special names and just skip them. */
+ slash = strrchr(path, '/');
+ if (slash == NULL)
+ base = path;
+ else
+ base = slash + 1;
+
+ if (base[0] == '\0' ||
+ (base[0] == '.' && base[1] == '\0') ||
+ (base[0] == '.' && base[1] == '.' && base[2] == '\0')) {
+ /* Don't bother trying to create null path, '.', or '..'. */
+ if (slash != NULL) {
+ *slash = '\0';
+ r = create_dir(a, path);
+ *slash = '/';
+ return (r);
+ }
+ return (ARCHIVE_OK);
+ }
+
+ /*
+ * Yes, this should be stat() and not lstat(). Using lstat()
+ * here loses the ability to extract through symlinks. Also note
+ * that this should not use the a->st cache.
+ */
+ if (stat(path, &st) == 0) {
+ if (S_ISDIR(st.st_mode))
+ return (ARCHIVE_OK);
+ if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) {
+ archive_set_error(&a->archive, EEXIST,
+ "Can't create directory '%s'", path);
+ return (ARCHIVE_FAILED);
+ }
+ if (unlink(path) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't create directory '%s': "
+ "Conflicting file cannot be removed",
+ path);
+ return (ARCHIVE_FAILED);
+ }
+ } else if (errno != ENOENT && errno != ENOTDIR) {
+ /* Stat failed? */
+ archive_set_error(&a->archive, errno, "Can't test directory '%s'", path);
+ return (ARCHIVE_FAILED);
+ } else if (slash != NULL) {
+ *slash = '\0';
+ r = create_dir(a, path);
+ *slash = '/';
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+
+ /*
+ * Mode we want for the final restored directory. Per POSIX,
+ * implicitly-created dirs must be created obeying the umask.
+ * There's no mention whether this is different for privileged
+ * restores (which the rest of this code handles by pretending
+ * umask=0). I've chosen here to always obey the user's umask for
+ * implicit dirs, even if _EXTRACT_PERM was specified.
+ */
+ mode_final = DEFAULT_DIR_MODE & ~a->user_umask;
+ /* Mode we want on disk during the restore process. */
+ mode = mode_final;
+ mode |= MINIMUM_DIR_MODE;
+ mode &= MAXIMUM_DIR_MODE;
+ if (mkdir(path, mode) == 0) {
+ if (mode != mode_final) {
+ le = new_fixup(a, path);
+ if (le == NULL)
+ return (ARCHIVE_FATAL);
+ le->fixup |=TODO_MODE_BASE;
+ le->mode = mode_final;
+ }
+ return (ARCHIVE_OK);
+ }
+
+ /*
+ * Without the following check, a/b/../b/c/d fails at the
+ * second visit to 'b', so 'd' can't be created. Note that we
+ * don't add it to the fixup list here, as it's already been
+ * added.
+ */
+ if (stat(path, &st) == 0 && S_ISDIR(st.st_mode))
+ return (ARCHIVE_OK);
+
+ archive_set_error(&a->archive, errno, "Failed to create dir '%s'",
+ path);
+ return (ARCHIVE_FAILED);
+}
+
+/*
+ * Note: Although we can skip setting the user id if the desired user
+ * id matches the current user, we cannot skip setting the group, as
+ * many systems set the gid based on the containing directory. So
+ * we have to perform a chown syscall if we want to set the SGID
+ * bit. (The alternative is to stat() and then possibly chown(); it's
+ * more efficient to skip the stat() and just always chown().) Note
+ * that a successful chown() here clears the TODO_SGID_CHECK bit, which
+ * allows set_mode to skip the stat() check for the GID.
+ */
+static int
+set_ownership(struct archive_write_disk *a)
+{
+#ifndef __CYGWIN__
+/* unfortunately, on win32 there is no 'root' user with uid 0,
+ so we just have to try the chown and see if it works */
+
+ /* If we know we can't change it, don't bother trying. */
+ if (a->user_uid != 0 && a->user_uid != a->uid) {
+ archive_set_error(&a->archive, errno,
+ "Can't set UID=%jd", (intmax_t)a->uid);
+ return (ARCHIVE_WARN);
+ }
+#endif
+
+#ifdef HAVE_FCHOWN
+ /* If we have an fd, we can avoid a race. */
+ if (a->fd >= 0 && fchown(a->fd, a->uid, a->gid) == 0) {
+ /* We've set owner and know uid/gid are correct. */
+ a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK);
+ return (ARCHIVE_OK);
+ }
+#endif
+
+ /* We prefer lchown() but will use chown() if that's all we have. */
+ /* Of course, if we have neither, this will always fail. */
+#ifdef HAVE_LCHOWN
+ if (lchown(a->name, a->uid, a->gid) == 0) {
+ /* We've set owner and know uid/gid are correct. */
+ a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK);
+ return (ARCHIVE_OK);
+ }
+#elif HAVE_CHOWN
+ if (!S_ISLNK(a->mode) && chown(a->name, a->uid, a->gid) == 0) {
+ /* We've set owner and know uid/gid are correct. */
+ a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK);
+ return (ARCHIVE_OK);
+ }
+#endif
+
+ archive_set_error(&a->archive, errno,
+ "Can't set user=%jd/group=%jd for %s",
+ (intmax_t)a->uid, (intmax_t)a->gid, a->name);
+ return (ARCHIVE_WARN);
+}
+
+/*
+ * Note: Returns 0 on success, non-zero on failure.
+ */
+static int
+set_time(int fd, int mode, const char *name,
+ time_t atime, long atime_nsec,
+ time_t mtime, long mtime_nsec)
+{
+ /* Select the best implementation for this platform. */
+#if defined(HAVE_UTIMENSAT) && defined(HAVE_FUTIMENS)
+ /*
+ * utimensat() and futimens() are defined in
+ * POSIX.1-2008. They support ns resolution and setting times
+ * on fds and symlinks.
+ */
+ struct timespec ts[2];
+ (void)mode; /* UNUSED */
+ ts[0].tv_sec = atime;
+ ts[0].tv_nsec = atime_nsec;
+ ts[1].tv_sec = mtime;
+ ts[1].tv_nsec = mtime_nsec;
+ if (fd >= 0)
+ return futimens(fd, ts);
+ return utimensat(AT_FDCWD, name, ts, AT_SYMLINK_NOFOLLOW);
+
+#elif HAVE_UTIMES
+ /*
+ * The utimes()-family functions support µs-resolution and
+ * setting times fds and symlinks. utimes() is documented as
+ * LEGACY by POSIX, futimes() and lutimes() are not described
+ * in POSIX.
+ */
+ struct timeval times[2];
+
+ times[0].tv_sec = atime;
+ times[0].tv_usec = atime_nsec / 1000;
+ times[1].tv_sec = mtime;
+ times[1].tv_usec = mtime_nsec / 1000;
+
+#ifdef HAVE_FUTIMES
+ if (fd >= 0)
+ return (futimes(fd, times));
+#else
+ (void)fd; /* UNUSED */
+#endif
+#ifdef HAVE_LUTIMES
+ (void)mode; /* UNUSED */
+ return (lutimes(name, times));
+#else
+ if (S_ISLNK(mode))
+ return (0);
+ return (utimes(name, times));
+#endif
+
+#elif defined(HAVE_UTIME)
+ /*
+ * utime() is POSIX-standard but only supports 1s resolution and
+ * does not support fds or symlinks.
+ */
+ struct utimbuf times;
+ (void)fd; /* UNUSED */
+ (void)name; /* UNUSED */
+ (void)atime_nsec; /* UNUSED */
+ (void)mtime_nsec; /* UNUSED */
+ times.actime = atime;
+ times.modtime = mtime;
+ if (S_ISLNK(mode))
+ return (ARCHIVE_OK);
+ return (utime(name, &times));
+
+#else
+ /*
+ * We don't know how to set the time on this platform.
+ */
+ (void)fd; /* UNUSED */
+ (void)mode; /* UNUSED */
+ (void)name; /* UNUSED */
+ (void)atime_nsec; /* UNUSED */
+ (void)mtime_nsec; /* UNUSED */
+ return (ARCHIVE_WARN);
+#endif
+}
+
+#ifdef F_SETTIMES
+static int
+set_time_tru64(int fd, int mode, const char *name,
+ time_t atime, long atime_nsec,
+ time_t mtime, long mtime_nsec,
+ time_t ctime, long ctime_nsec)
+{
+ struct attr_timbuf tstamp;
+ tstamp.atime.tv_sec = atime;
+ tstamp.mtime.tv_sec = mtime;
+ tstamp.ctime.tv_sec = ctime;
+#if defined (__hpux) && defined (__ia64)
+ tstamp.atime.tv_nsec = atime_nsec;
+ tstamp.mtime.tv_nsec = mtime_nsec;
+ tstamp.ctime.tv_nsec = ctime_nsec;
+#else
+ tstamp.atime.tv_usec = atime_nsec / 1000;
+ tstamp.mtime.tv_usec = mtime_nsec / 1000;
+ tstamp.ctime.tv_usec = ctime_nsec / 1000;
+#endif
+ return (fcntl(fd,F_SETTIMES,&tstamp));
+}
+#endif /* F_SETTIMES */
+
+static int
+set_times(struct archive_write_disk *a,
+ int fd, int mode, const char *name,
+ time_t atime, long atime_nanos,
+ time_t birthtime, long birthtime_nanos,
+ time_t mtime, long mtime_nanos,
+ time_t cctime, long ctime_nanos)
+{
+ /* Note: set_time doesn't use libarchive return conventions!
+ * It uses syscall conventions. So 0 here instead of ARCHIVE_OK. */
+ int r1 = 0, r2 = 0;
+
+#ifdef F_SETTIMES
+ /*
+ * on Tru64 try own fcntl first which can restore even the
+ * ctime, fall back to default code path below if it fails
+ * or if we are not running as root
+ */
+ if (a->user_uid == 0 &&
+ set_time_tru64(fd, mode, name,
+ atime, atime_nanos, mtime,
+ mtime_nanos, cctime, ctime_nanos) == 0) {
+ return (ARCHIVE_OK);
+ }
+#else /* Tru64 */
+ (void)cctime; /* UNUSED */
+ (void)ctime_nanos; /* UNUSED */
+#endif /* Tru64 */
+
+#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
+ /*
+ * If you have struct stat.st_birthtime, we assume BSD
+ * birthtime semantics, in which {f,l,}utimes() updates
+ * birthtime to earliest mtime. So we set the time twice,
+ * first using the birthtime, then using the mtime. If
+ * birthtime == mtime, this isn't necessary, so we skip it.
+ * If birthtime > mtime, then this won't work, so we skip it.
+ */
+ if (birthtime < mtime
+ || (birthtime == mtime && birthtime_nanos < mtime_nanos))
+ r1 = set_time(fd, mode, name,
+ atime, atime_nanos,
+ birthtime, birthtime_nanos);
+#else
+ (void)birthtime; /* UNUSED */
+ (void)birthtime_nanos; /* UNUSED */
+#endif
+ r2 = set_time(fd, mode, name,
+ atime, atime_nanos,
+ mtime, mtime_nanos);
+ if (r1 != 0 || r2 != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't restore time");
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+set_times_from_entry(struct archive_write_disk *a)
+{
+ time_t atime, birthtime, mtime, cctime;
+ long atime_nsec, birthtime_nsec, mtime_nsec, ctime_nsec;
+
+ /* Suitable defaults. */
+ atime = birthtime = mtime = cctime = a->start_time;
+ atime_nsec = birthtime_nsec = mtime_nsec = ctime_nsec = 0;
+
+ /* If no time was provided, we're done. */
+ if (!archive_entry_atime_is_set(a->entry)
+#if HAVE_STRUCT_STAT_ST_BIRTHTIME
+ && !archive_entry_birthtime_is_set(a->entry)
+#endif
+ && !archive_entry_mtime_is_set(a->entry))
+ return (ARCHIVE_OK);
+
+ if (archive_entry_atime_is_set(a->entry)) {
+ atime = archive_entry_atime(a->entry);
+ atime_nsec = archive_entry_atime_nsec(a->entry);
+ }
+ if (archive_entry_birthtime_is_set(a->entry)) {
+ birthtime = archive_entry_birthtime(a->entry);
+ birthtime_nsec = archive_entry_birthtime_nsec(a->entry);
+ }
+ if (archive_entry_mtime_is_set(a->entry)) {
+ mtime = archive_entry_mtime(a->entry);
+ mtime_nsec = archive_entry_mtime_nsec(a->entry);
+ }
+ if (archive_entry_ctime_is_set(a->entry)) {
+ cctime = archive_entry_ctime(a->entry);
+ ctime_nsec = archive_entry_ctime_nsec(a->entry);
+ }
+
+ return set_times(a, a->fd, a->mode, a->name,
+ atime, atime_nsec,
+ birthtime, birthtime_nsec,
+ mtime, mtime_nsec,
+ cctime, ctime_nsec);
+}
+
+static int
+set_mode(struct archive_write_disk *a, int mode)
+{
+ int r = ARCHIVE_OK;
+ mode &= 07777; /* Strip off file type bits. */
+
+ if (a->todo & TODO_SGID_CHECK) {
+ /*
+ * If we don't know the GID is right, we must stat()
+ * to verify it. We can't just check the GID of this
+ * process, since systems sometimes set GID from
+ * the enclosing dir or based on ACLs.
+ */
+ if ((r = lazy_stat(a)) != ARCHIVE_OK)
+ return (r);
+ if (a->pst->st_gid != a->gid) {
+ mode &= ~ S_ISGID;
+ if (a->flags & ARCHIVE_EXTRACT_OWNER) {
+ /*
+ * This is only an error if you
+ * requested owner restore. If you
+ * didn't, we'll try to restore
+ * sgid/suid, but won't consider it a
+ * problem if we can't.
+ */
+ archive_set_error(&a->archive, -1,
+ "Can't restore SGID bit");
+ r = ARCHIVE_WARN;
+ }
+ }
+ /* While we're here, double-check the UID. */
+ if (a->pst->st_uid != a->uid
+ && (a->todo & TODO_SUID)) {
+ mode &= ~ S_ISUID;
+ if (a->flags & ARCHIVE_EXTRACT_OWNER) {
+ archive_set_error(&a->archive, -1,
+ "Can't restore SUID bit");
+ r = ARCHIVE_WARN;
+ }
+ }
+ a->todo &= ~TODO_SGID_CHECK;
+ a->todo &= ~TODO_SUID_CHECK;
+ } else if (a->todo & TODO_SUID_CHECK) {
+ /*
+ * If we don't know the UID is right, we can just check
+ * the user, since all systems set the file UID from
+ * the process UID.
+ */
+ if (a->user_uid != a->uid) {
+ mode &= ~ S_ISUID;
+ if (a->flags & ARCHIVE_EXTRACT_OWNER) {
+ archive_set_error(&a->archive, -1,
+ "Can't make file SUID");
+ r = ARCHIVE_WARN;
+ }
+ }
+ a->todo &= ~TODO_SUID_CHECK;
+ }
+
+ if (S_ISLNK(a->mode)) {
+#ifdef HAVE_LCHMOD
+ /*
+ * If this is a symlink, use lchmod(). If the
+ * platform doesn't support lchmod(), just skip it. A
+ * platform that doesn't provide a way to set
+ * permissions on symlinks probably ignores
+ * permissions on symlinks, so a failure here has no
+ * 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;
+ }
+#endif
+ } else if (!S_ISDIR(a->mode)) {
+ /*
+ * If it's not a symlink and not a dir, then use
+ * fchmod() or chmod(), depending on whether we have
+ * an fd. Dirs get their perms set during the
+ * post-extract fixup, which is handled elsewhere.
+ */
+#ifdef HAVE_FCHMOD
+ if (a->fd >= 0) {
+ if (fchmod(a->fd, mode) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't set permissions to 0%o", (int)mode);
+ r = ARCHIVE_WARN;
+ }
+ } else
+#endif
+ /* If this platform lacks fchmod(), then
+ * we'll just use chmod(). */
+ if (chmod(a->name, mode) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't set permissions to 0%o", (int)mode);
+ r = ARCHIVE_WARN;
+ }
+ }
+ return (r);
+}
+
+static int
+set_fflags(struct archive_write_disk *a)
+{
+ struct fixup_entry *le;
+ unsigned long set, clear;
+ int r;
+ int critical_flags;
+ mode_t mode = archive_entry_mode(a->entry);
+
+ /*
+ * Make 'critical_flags' hold all file flags that can't be
+ * immediately restored. For example, on BSD systems,
+ * SF_IMMUTABLE prevents hardlinks from being created, so
+ * should not be set until after any hardlinks are created. To
+ * preserve some semblance of portability, this uses #ifdef
+ * extensively. Ugly, but it works.
+ *
+ * Yes, Virginia, this does create a security race. It's mitigated
+ * somewhat by the practice of creating dirs 0700 until the extract
+ * is done, but it would be nice if we could do more than that.
+ * People restoring critical file systems should be wary of
+ * other programs that might try to muck with files as they're
+ * being restored.
+ */
+ /* Hopefully, the compiler will optimize this mess into a constant. */
+ critical_flags = 0;
+#ifdef SF_IMMUTABLE
+ critical_flags |= SF_IMMUTABLE;
+#endif
+#ifdef UF_IMMUTABLE
+ critical_flags |= UF_IMMUTABLE;
+#endif
+#ifdef SF_APPEND
+ critical_flags |= SF_APPEND;
+#endif
+#ifdef UF_APPEND
+ critical_flags |= UF_APPEND;
+#endif
+#ifdef EXT2_APPEND_FL
+ critical_flags |= EXT2_APPEND_FL;
+#endif
+#ifdef EXT2_IMMUTABLE_FL
+ critical_flags |= EXT2_IMMUTABLE_FL;
+#endif
+
+ if (a->todo & TODO_FFLAGS) {
+ archive_entry_fflags(a->entry, &set, &clear);
+
+ /*
+ * The first test encourages the compiler to eliminate
+ * all of this if it's not necessary.
+ */
+ if ((critical_flags != 0) && (set & critical_flags)) {
+ le = current_fixup(a, a->name);
+ if (le == NULL)
+ return (ARCHIVE_FATAL);
+ le->fixup |= TODO_FFLAGS;
+ le->fflags_set = set;
+ /* Store the mode if it's not already there. */
+ if ((le->fixup & TODO_MODE) == 0)
+ le->mode = mode;
+ } else {
+ r = set_fflags_platform(a, a->fd,
+ a->name, mode, set, clear);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+ }
+ return (ARCHIVE_OK);
+}
+
+
+#if ( defined(HAVE_LCHFLAGS) || defined(HAVE_CHFLAGS) || defined(HAVE_FCHFLAGS) ) && defined(HAVE_STRUCT_STAT_ST_FLAGS)
+/*
+ * BSD reads flags using stat() and sets them with one of {f,l,}chflags()
+ */
+static int
+set_fflags_platform(struct archive_write_disk *a, int fd, const char *name,
+ mode_t mode, unsigned long set, unsigned long clear)
+{
+ int r;
+
+ (void)mode; /* UNUSED */
+ if (set == 0 && clear == 0)
+ return (ARCHIVE_OK);
+
+ /*
+ * XXX Is the stat here really necessary? Or can I just use
+ * the 'set' flags directly? In particular, I'm not sure
+ * about the correct approach if we're overwriting an existing
+ * file that already has flags on it. XXX
+ */
+ if ((r = lazy_stat(a)) != ARCHIVE_OK)
+ return (r);
+
+ a->st.st_flags &= ~clear;
+ a->st.st_flags |= set;
+#ifdef HAVE_FCHFLAGS
+ /* If platform has fchflags() and we were given an fd, use it. */
+ if (fd >= 0 && fchflags(fd, a->st.st_flags) == 0)
+ return (ARCHIVE_OK);
+#endif
+ /*
+ * If we can't use the fd to set the flags, we'll use the
+ * pathname to set flags. We prefer lchflags() but will use
+ * chflags() if we must.
+ */
+#ifdef HAVE_LCHFLAGS
+ if (lchflags(name, a->st.st_flags) == 0)
+ return (ARCHIVE_OK);
+#elif defined(HAVE_CHFLAGS)
+ if (S_ISLNK(a->st.st_mode)) {
+ archive_set_error(&a->archive, errno,
+ "Can't set file flags on symlink.");
+ return (ARCHIVE_WARN);
+ }
+ if (chflags(name, a->st.st_flags) == 0)
+ return (ARCHIVE_OK);
+#endif
+ archive_set_error(&a->archive, errno,
+ "Failed to set file flags");
+ return (ARCHIVE_WARN);
+}
+
+#elif defined(EXT2_IOC_GETFLAGS) && defined(EXT2_IOC_SETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)
+/*
+ * Linux uses ioctl() to read and write file flags.
+ */
+static int
+set_fflags_platform(struct archive_write_disk *a, int fd, const char *name,
+ mode_t mode, unsigned long set, unsigned long clear)
+{
+ int ret;
+ int myfd = fd;
+ int newflags, oldflags;
+ int sf_mask = 0;
+
+ if (set == 0 && clear == 0)
+ return (ARCHIVE_OK);
+ /* Only regular files and dirs can have flags. */
+ if (!S_ISREG(mode) && !S_ISDIR(mode))
+ return (ARCHIVE_OK);
+
+ /* If we weren't given an fd, open it ourselves. */
+ if (myfd < 0) {
+ myfd = open(name, O_RDONLY | O_NONBLOCK | O_BINARY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(myfd);
+ }
+ if (myfd < 0)
+ return (ARCHIVE_OK);
+
+ /*
+ * Linux has no define for the flags that are only settable by
+ * the root user. This code may seem a little complex, but
+ * there seem to be some Linux systems that lack these
+ * defines. (?) The code below degrades reasonably gracefully
+ * if sf_mask is incomplete.
+ */
+#ifdef EXT2_IMMUTABLE_FL
+ sf_mask |= EXT2_IMMUTABLE_FL;
+#endif
+#ifdef EXT2_APPEND_FL
+ sf_mask |= EXT2_APPEND_FL;
+#endif
+ /*
+ * XXX As above, this would be way simpler if we didn't have
+ * to read the current flags from disk. XXX
+ */
+ ret = ARCHIVE_OK;
+
+ /* Read the current file flags. */
+ if (ioctl(myfd, EXT2_IOC_GETFLAGS, &oldflags) < 0)
+ goto fail;
+
+ /* Try setting the flags as given. */
+ newflags = (oldflags & ~clear) | set;
+ if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0)
+ goto cleanup;
+ if (errno != EPERM)
+ goto fail;
+
+ /* If we couldn't set all the flags, try again with a subset. */
+ newflags &= ~sf_mask;
+ oldflags &= sf_mask;
+ newflags |= oldflags;
+ if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0)
+ goto cleanup;
+
+ /* We couldn't set the flags, so report the failure. */
+fail:
+ archive_set_error(&a->archive, errno,
+ "Failed to set file flags");
+ ret = ARCHIVE_WARN;
+cleanup:
+ if (fd < 0)
+ close(myfd);
+ return (ret);
+}
+
+#else
+
+/*
+ * Of course, some systems have neither BSD chflags() nor Linux' flags
+ * support through ioctl().
+ */
+static int
+set_fflags_platform(struct archive_write_disk *a, int fd, const char *name,
+ mode_t mode, unsigned long set, unsigned long clear)
+{
+ (void)a; /* UNUSED */
+ (void)fd; /* UNUSED */
+ (void)name; /* UNUSED */
+ (void)mode; /* UNUSED */
+ (void)set; /* UNUSED */
+ (void)clear; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+#endif /* __linux */
+
+#ifndef HAVE_COPYFILE_H
+/* Default is to simply drop Mac extended metadata. */
+static int
+set_mac_metadata(struct archive_write_disk *a, const char *pathname,
+ const void *metadata, size_t metadata_size)
+{
+ (void)a; /* UNUSED */
+ (void)pathname; /* UNUSED */
+ (void)metadata; /* UNUSED */
+ (void)metadata_size; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+static int
+fixup_appledouble(struct archive_write_disk *a, const char *pathname)
+{
+ (void)a; /* UNUSED */
+ (void)pathname; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+#else
+
+/*
+ * On Mac OS, we use copyfile() to unpack the metadata and
+ * apply it to the target file.
+ */
+
+#if defined(HAVE_SYS_XATTR_H)
+static int
+copy_xattrs(struct archive_write_disk *a, int tmpfd, int dffd)
+{
+ ssize_t xattr_size;
+ char *xattr_names = NULL, *xattr_val = NULL;
+ int ret = ARCHIVE_OK, xattr_i;
+
+ xattr_size = flistxattr(tmpfd, NULL, 0, 0);
+ if (xattr_size == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to read metadata(xattr)");
+ ret = ARCHIVE_WARN;
+ goto exit_xattr;
+ }
+ xattr_names = malloc(xattr_size);
+ if (xattr_names == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for metadata(xattr)");
+ ret = ARCHIVE_FATAL;
+ goto exit_xattr;
+ }
+ xattr_size = flistxattr(tmpfd, xattr_names, xattr_size, 0);
+ if (xattr_size == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to read metadata(xattr)");
+ ret = ARCHIVE_WARN;
+ goto exit_xattr;
+ }
+ for (xattr_i = 0; xattr_i < xattr_size;
+ xattr_i += strlen(xattr_names + xattr_i) + 1) {
+ ssize_t s;
+ int f;
+
+ s = fgetxattr(tmpfd, xattr_names + xattr_i, NULL, 0, 0, 0);
+ if (s == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to get metadata(xattr)");
+ ret = ARCHIVE_WARN;
+ goto exit_xattr;
+ }
+ xattr_val = realloc(xattr_val, s);
+ if (xattr_val == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Failed to get metadata(xattr)");
+ ret = ARCHIVE_WARN;
+ goto exit_xattr;
+ }
+ s = fgetxattr(tmpfd, xattr_names + xattr_i, xattr_val, s, 0, 0);
+ if (s == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to get metadata(xattr)");
+ ret = ARCHIVE_WARN;
+ goto exit_xattr;
+ }
+ f = fsetxattr(dffd, xattr_names + xattr_i, xattr_val, s, 0, 0);
+ if (f == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to get metadata(xattr)");
+ ret = ARCHIVE_WARN;
+ goto exit_xattr;
+ }
+ }
+exit_xattr:
+ free(xattr_names);
+ free(xattr_val);
+ return (ret);
+}
+#endif
+
+static int
+copy_acls(struct archive_write_disk *a, int tmpfd, int dffd)
+{
+ acl_t acl, dfacl = NULL;
+ int acl_r, ret = ARCHIVE_OK;
+
+ acl = acl_get_fd(tmpfd);
+ if (acl == NULL) {
+ if (errno == ENOENT)
+ /* There are not any ACLs. */
+ return (ret);
+ archive_set_error(&a->archive, errno,
+ "Failed to get metadata(acl)");
+ ret = ARCHIVE_WARN;
+ goto exit_acl;
+ }
+ dfacl = acl_dup(acl);
+ acl_r = acl_set_fd(dffd, dfacl);
+ if (acl_r == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to get metadata(acl)");
+ ret = ARCHIVE_WARN;
+ goto exit_acl;
+ }
+exit_acl:
+ if (acl)
+ acl_free(acl);
+ if (dfacl)
+ acl_free(dfacl);
+ return (ret);
+}
+
+static int
+create_tempdatafork(struct archive_write_disk *a, const char *pathname)
+{
+ struct archive_string tmpdatafork;
+ int tmpfd;
+
+ archive_string_init(&tmpdatafork);
+ archive_strcpy(&tmpdatafork, "tar.md.XXXXXX");
+ tmpfd = mkstemp(tmpdatafork.s);
+ if (tmpfd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Failed to mkstemp");
+ archive_string_free(&tmpdatafork);
+ return (-1);
+ }
+ if (copyfile(pathname, tmpdatafork.s, 0,
+ COPYFILE_UNPACK | COPYFILE_NOFOLLOW
+ | COPYFILE_ACL | COPYFILE_XATTR) < 0) {
+ archive_set_error(&a->archive, errno,
+ "Failed to restore metadata");
+ close(tmpfd);
+ tmpfd = -1;
+ }
+ unlink(tmpdatafork.s);
+ archive_string_free(&tmpdatafork);
+ return (tmpfd);
+}
+
+static int
+copy_metadata(struct archive_write_disk *a, const char *metadata,
+ const char *datafork, int datafork_compressed)
+{
+ int ret = ARCHIVE_OK;
+
+ if (datafork_compressed) {
+ int dffd, tmpfd;
+
+ tmpfd = create_tempdatafork(a, metadata);
+ if (tmpfd == -1)
+ return (ARCHIVE_WARN);
+
+ /*
+ * Do not open the data fork compressed by HFS+ compression
+ * with at least a writing mode(O_RDWR or O_WRONLY). it
+ * makes the data fork uncompressed.
+ */
+ dffd = open(datafork, 0);
+ if (dffd == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to open the data fork for metadata");
+ close(tmpfd);
+ return (ARCHIVE_WARN);
+ }
+
+#if defined(HAVE_SYS_XATTR_H)
+ ret = copy_xattrs(a, tmpfd, dffd);
+ if (ret == ARCHIVE_OK)
+#endif
+ ret = copy_acls(a, tmpfd, dffd);
+ close(tmpfd);
+ close(dffd);
+ } else {
+ if (copyfile(metadata, datafork, 0,
+ COPYFILE_UNPACK | COPYFILE_NOFOLLOW
+ | COPYFILE_ACL | COPYFILE_XATTR) < 0) {
+ archive_set_error(&a->archive, errno,
+ "Failed to restore metadata");
+ ret = ARCHIVE_WARN;
+ }
+ }
+ return (ret);
+}
+
+static int
+set_mac_metadata(struct archive_write_disk *a, const char *pathname,
+ const void *metadata, size_t metadata_size)
+{
+ struct archive_string tmp;
+ ssize_t written;
+ int fd;
+ int ret = ARCHIVE_OK;
+
+ /* This would be simpler if copyfile() could just accept the
+ * metadata as a block of memory; then we could sidestep this
+ * silly dance of writing the data to disk just so that
+ * copyfile() can read it back in again. */
+ archive_string_init(&tmp);
+ archive_strcpy(&tmp, pathname);
+ archive_strcat(&tmp, ".XXXXXX");
+ fd = mkstemp(tmp.s);
+
+ if (fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Failed to restore metadata");
+ archive_string_free(&tmp);
+ return (ARCHIVE_WARN);
+ }
+ written = write(fd, metadata, metadata_size);
+ close(fd);
+ if ((size_t)written != metadata_size) {
+ archive_set_error(&a->archive, errno,
+ "Failed to restore metadata");
+ ret = ARCHIVE_WARN;
+ } else {
+ int compressed;
+
+#if defined(UF_COMPRESSED)
+ if ((a->todo & TODO_HFS_COMPRESSION) != 0 &&
+ (ret = lazy_stat(a)) == ARCHIVE_OK)
+ compressed = a->st.st_flags & UF_COMPRESSED;
+ else
+#endif
+ compressed = 0;
+ ret = copy_metadata(a, tmp.s, pathname, compressed);
+ }
+ unlink(tmp.s);
+ archive_string_free(&tmp);
+ return (ret);
+}
+
+static int
+fixup_appledouble(struct archive_write_disk *a, const char *pathname)
+{
+ char buff[8];
+ struct stat st;
+ const char *p;
+ struct archive_string datafork;
+ int fd = -1, ret = ARCHIVE_OK;
+
+ archive_string_init(&datafork);
+ /* Check if the current file name is a type of the resource
+ * fork file. */
+ p = strrchr(pathname, '/');
+ if (p == NULL)
+ p = pathname;
+ else
+ p++;
+ if (p[0] != '.' || p[1] != '_')
+ goto skip_appledouble;
+
+ /*
+ * Check if the data fork file exists.
+ *
+ * TODO: Check if this write disk object has handled it.
+ */
+ archive_strncpy(&datafork, pathname, p - pathname);
+ archive_strcat(&datafork, p + 2);
+ if (lstat(datafork.s, &st) == -1 ||
+ (st.st_mode & AE_IFMT) != AE_IFREG)
+ goto skip_appledouble;
+
+ /*
+ * Check if the file is in the AppleDouble form.
+ */
+ fd = open(pathname, O_RDONLY | O_BINARY | O_CLOEXEC);
+ __archive_ensure_cloexec_flag(fd);
+ if (fd == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to open a restoring file");
+ ret = ARCHIVE_WARN;
+ goto skip_appledouble;
+ }
+ if (read(fd, buff, 8) == -1) {
+ archive_set_error(&a->archive, errno,
+ "Failed to read a restoring file");
+ close(fd);
+ ret = ARCHIVE_WARN;
+ goto skip_appledouble;
+ }
+ close(fd);
+ /* Check AppleDouble Magic Code. */
+ if (archive_be32dec(buff) != 0x00051607)
+ goto skip_appledouble;
+ /* Check AppleDouble Version. */
+ if (archive_be32dec(buff+4) != 0x00020000)
+ goto skip_appledouble;
+
+ ret = copy_metadata(a, pathname, datafork.s,
+#if defined(UF_COMPRESSED)
+ st.st_flags & UF_COMPRESSED);
+#else
+ 0);
+#endif
+ if (ret == ARCHIVE_OK) {
+ unlink(pathname);
+ ret = ARCHIVE_EOF;
+ }
+skip_appledouble:
+ archive_string_free(&datafork);
+ return (ret);
+}
+#endif
+
+#if HAVE_LSETXATTR || HAVE_LSETEA
+/*
+ * Restore extended attributes - Linux and AIX implementations:
+ * AIX' ea interface is syntaxwise identical to the Linux xattr interface.
+ */
+static int
+set_xattrs(struct archive_write_disk *a)
+{
+ struct archive_entry *entry = a->entry;
+ static int warning_done = 0;
+ int ret = ARCHIVE_OK;
+ int i = archive_entry_xattr_reset(entry);
+
+ while (i--) {
+ const char *name;
+ const void *value;
+ size_t size;
+ archive_entry_xattr_next(entry, &name, &value, &size);
+ if (name != NULL &&
+ strncmp(name, "xfsroot.", 8) != 0 &&
+ strncmp(name, "system.", 7) != 0) {
+ int e;
+#if HAVE_FSETXATTR
+ if (a->fd >= 0)
+ e = fsetxattr(a->fd, name, value, size, 0);
+ else
+#elif HAVE_FSETEA
+ if (a->fd >= 0)
+ e = fsetea(a->fd, name, value, size, 0);
+ else
+#endif
+ {
+#if HAVE_LSETXATTR
+ e = lsetxattr(archive_entry_pathname(entry),
+ name, value, size, 0);
+#elif HAVE_LSETEA
+ e = lsetea(archive_entry_pathname(entry),
+ name, value, size, 0);
+#endif
+ }
+ if (e == -1) {
+ if (errno == ENOTSUP || errno == ENOSYS) {
+ if (!warning_done) {
+ warning_done = 1;
+ archive_set_error(&a->archive, errno,
+ "Cannot restore extended "
+ "attributes on this file "
+ "system");
+ }
+ } else
+ archive_set_error(&a->archive, errno,
+ "Failed to set extended attribute");
+ ret = ARCHIVE_WARN;
+ }
+ } else {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid extended attribute encountered");
+ ret = ARCHIVE_WARN;
+ }
+ }
+ return (ret);
+}
+#elif HAVE_EXTATTR_SET_FILE && HAVE_DECL_EXTATTR_NAMESPACE_USER
+/*
+ * Restore extended attributes - FreeBSD implementation
+ */
+static int
+set_xattrs(struct archive_write_disk *a)
+{
+ struct archive_entry *entry = a->entry;
+ static int warning_done = 0;
+ int ret = ARCHIVE_OK;
+ int i = archive_entry_xattr_reset(entry);
+
+ while (i--) {
+ const char *name;
+ const void *value;
+ size_t size;
+ archive_entry_xattr_next(entry, &name, &value, &size);
+ if (name != NULL) {
+ int e;
+ int namespace;
+
+ if (strncmp(name, "user.", 5) == 0) {
+ /* "user." attributes go to user namespace */
+ name += 5;
+ namespace = EXTATTR_NAMESPACE_USER;
+ } else {
+ /* Warn about other extended attributes. */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't restore extended attribute ``%s''",
+ name);
+ ret = ARCHIVE_WARN;
+ continue;
+ }
+ errno = 0;
+#if HAVE_EXTATTR_SET_FD
+ if (a->fd >= 0)
+ e = extattr_set_fd(a->fd, namespace, name, value, size);
+ else
+#endif
+ /* TODO: should we use extattr_set_link() instead? */
+ {
+ e = extattr_set_file(archive_entry_pathname(entry),
+ namespace, name, value, size);
+ }
+ if (e != (int)size) {
+ if (errno == ENOTSUP || errno == ENOSYS) {
+ if (!warning_done) {
+ warning_done = 1;
+ archive_set_error(&a->archive, errno,
+ "Cannot restore extended "
+ "attributes on this file "
+ "system");
+ }
+ } else {
+ archive_set_error(&a->archive, errno,
+ "Failed to set extended attribute");
+ }
+
+ ret = ARCHIVE_WARN;
+ }
+ }
+ }
+ return (ret);
+}
+#else
+/*
+ * Restore extended attributes - stub implementation for unsupported systems
+ */
+static int
+set_xattrs(struct archive_write_disk *a)
+{
+ static int warning_done = 0;
+
+ /* If there aren't any extended attributes, then it's okay not
+ * to extract them, otherwise, issue a single warning. */
+ if (archive_entry_xattr_count(a->entry) != 0 && !warning_done) {
+ warning_done = 1;
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Cannot restore extended attributes on this system");
+ return (ARCHIVE_WARN);
+ }
+ /* Warning was already emitted; suppress further warnings. */
+ return (ARCHIVE_OK);
+}
+#endif
+
+/*
+ * Test if file on disk is older than entry.
+ */
+static int
+older(struct stat *st, struct archive_entry *entry)
+{
+ /* First, test the seconds and return if we have a definite answer. */
+ /* Definitely older. */
+ if (st->st_mtime < archive_entry_mtime(entry))
+ return (1);
+ /* Definitely younger. */
+ if (st->st_mtime > archive_entry_mtime(entry))
+ return (0);
+ /* If this platform supports fractional seconds, try those. */
+#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
+ /* Definitely older. */
+ if (st->st_mtimespec.tv_nsec < archive_entry_mtime_nsec(entry))
+ return (1);
+#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+ /* Definitely older. */
+ if (st->st_mtim.tv_nsec < archive_entry_mtime_nsec(entry))
+ return (1);
+#elif HAVE_STRUCT_STAT_ST_MTIME_N
+ /* older. */
+ if (st->st_mtime_n < archive_entry_mtime_nsec(entry))
+ return (1);
+#elif HAVE_STRUCT_STAT_ST_UMTIME
+ /* older. */
+ if (st->st_umtime * 1000 < archive_entry_mtime_nsec(entry))
+ return (1);
+#elif HAVE_STRUCT_STAT_ST_MTIME_USEC
+ /* older. */
+ if (st->st_mtime_usec * 1000 < archive_entry_mtime_nsec(entry))
+ return (1);
+#else
+ /* This system doesn't have high-res timestamps. */
+#endif
+ /* Same age or newer, so not older. */
+ return (0);
+}
+
+#endif /* !_WIN32 || __CYGWIN__ */
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h b/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h
new file mode 100644
index 0000000000..d84e7e1cd6
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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
+ * in this position and unchanged.
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_write_disk_private.h 201086 2009-12-28 02:17:53Z kientzle $
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED
+#define ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED
+
+#include "archive_acl_private.h"
+
+struct archive_write_disk;
+
+int
+archive_write_disk_set_acls(struct archive *, int /* fd */, const char * /* pathname */, struct archive_acl *);
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c
new file mode 100644
index 0000000000..e79008ef6b
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c
@@ -0,0 +1,262 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_disk_set_standard_lookup.c 201083 2009-12-28 02:09:57Z kientzle $");
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+#include "archive_write_disk_private.h"
+
+struct bucket {
+ char *name;
+ int hash;
+ id_t id;
+};
+
+static const size_t cache_size = 127;
+static unsigned int hash(const char *);
+static int64_t lookup_gid(void *, const char *uname, int64_t);
+static int64_t lookup_uid(void *, const char *uname, int64_t);
+static void cleanup(void *);
+
+/*
+ * Installs functions that use getpwnam()/getgrnam()---along with
+ * 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
+ * it inappropriate for some space-constrained applications.
+ *
+ * Applications that are size-sensitive may want to just use the
+ * real default functions (defined in archive_write_disk.c) that just
+ * use the uid/gid without the lookup. Or define your own custom functions
+ * if you prefer.
+ *
+ * TODO: Replace these hash tables with simpler move-to-front LRU
+ * lists with a bounded size (128 items?). The hash is a bit faster,
+ * but has a bad pathology in which it thrashes a single bucket. Even
+ * walking a list of 128 items is a lot faster than calling
+ * getpwnam()!
+ */
+int
+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));
+ 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);
+ archive_write_disk_set_user_lookup(a, ucache, lookup_uid, cleanup);
+ return (ARCHIVE_OK);
+}
+
+static int64_t
+lookup_gid(void *private_data, const char *gname, int64_t gid)
+{
+ int h;
+ struct bucket *b;
+ struct bucket *gcache = (struct bucket *)private_data;
+
+ /* If no gname, just use the gid provided. */
+ if (gname == NULL || *gname == '\0')
+ return (gid);
+
+ /* Try to find gname in the cache. */
+ h = hash(gname);
+ b = &gcache[h % cache_size ];
+ if (b->name != NULL && b->hash == h && strcmp(gname, b->name) == 0)
+ return ((gid_t)b->id);
+
+ /* Free the cache slot for a new entry. */
+ if (b->name != NULL)
+ free(b->name);
+ b->name = strdup(gname);
+ /* Note: If strdup fails, that's okay; we just won't cache. */
+ b->hash = h;
+#if HAVE_GRP_H
+# if HAVE_GETGRNAM_R
+ {
+ char _buffer[128];
+ size_t bufsize = 128;
+ char *buffer = _buffer;
+ char *allocated = NULL;
+ struct group grent, *result;
+ int r;
+
+ for (;;) {
+ result = &grent; /* Old getgrnam_r ignores last arg. */
+ r = getgrnam_r(gname, &grent, buffer, bufsize, &result);
+ if (r == 0)
+ break;
+ if (r != ERANGE)
+ break;
+ bufsize *= 2;
+ free(allocated);
+ allocated = malloc(bufsize);
+ if (allocated == NULL)
+ break;
+ buffer = allocated;
+ }
+ if (result != NULL)
+ gid = result->gr_gid;
+ free(allocated);
+ }
+# else /* HAVE_GETGRNAM_R */
+ {
+ struct group *result;
+
+ result = getgrnam(gname);
+ if (result != NULL)
+ gid = result->gr_gid;
+ }
+# endif /* HAVE_GETGRNAM_R */
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ /* TODO: do a gname->gid lookup for Windows. */
+#else
+ #error No way to perform gid lookups on this platform
+#endif
+ b->id = (gid_t)gid;
+
+ return (gid);
+}
+
+static int64_t
+lookup_uid(void *private_data, const char *uname, int64_t uid)
+{
+ int h;
+ struct bucket *b;
+ struct bucket *ucache = (struct bucket *)private_data;
+
+ /* If no uname, just use the uid provided. */
+ if (uname == NULL || *uname == '\0')
+ return (uid);
+
+ /* Try to find uname in the cache. */
+ h = hash(uname);
+ b = &ucache[h % cache_size ];
+ if (b->name != NULL && b->hash == h && strcmp(uname, b->name) == 0)
+ return ((uid_t)b->id);
+
+ /* Free the cache slot for a new entry. */
+ if (b->name != NULL)
+ free(b->name);
+ b->name = strdup(uname);
+ /* Note: If strdup fails, that's okay; we just won't cache. */
+ b->hash = h;
+#if HAVE_PWD_H
+# if HAVE_GETPWNAM_R
+ {
+ char _buffer[128];
+ size_t bufsize = 128;
+ char *buffer = _buffer;
+ char *allocated = NULL;
+ struct passwd pwent, *result;
+ int r;
+
+ for (;;) {
+ result = &pwent; /* Old getpwnam_r ignores last arg. */
+ r = getpwnam_r(uname, &pwent, buffer, bufsize, &result);
+ if (r == 0)
+ break;
+ if (r != ERANGE)
+ break;
+ bufsize *= 2;
+ free(allocated);
+ allocated = malloc(bufsize);
+ if (allocated == NULL)
+ break;
+ buffer = allocated;
+ }
+ if (result != NULL)
+ uid = result->pw_uid;
+ free(allocated);
+ }
+# else /* HAVE_GETPWNAM_R */
+ {
+ struct passwd *result;
+
+ result = getpwnam(uname);
+ if (result != NULL)
+ uid = result->pw_uid;
+ }
+#endif /* HAVE_GETPWNAM_R */
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ /* TODO: do a uname->uid lookup for Windows. */
+#else
+ #error No way to look up uids on this platform
+#endif
+ b->id = (uid_t)uid;
+
+ return (uid);
+}
+
+static void
+cleanup(void *private)
+{
+ size_t i;
+ struct bucket *cache = (struct bucket *)private;
+
+ for (i = 0; i < cache_size; i++)
+ free(cache[i].name);
+ free(cache);
+}
+
+
+static unsigned int
+hash(const char *p)
+{
+ /* A 32-bit version of Peter Weinberger's (PJW) hash algorithm,
+ as used by ELF for hashing function names. */
+ unsigned g, h = 0;
+ while (*p != '\0') {
+ h = (h << 4) + *p++;
+ if ((g = h & 0xF0000000) != 0) {
+ h ^= g >> 24;
+ h &= 0x0FFFFFFF;
+ }
+ }
+ return h;
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c
new file mode 100644
index 0000000000..ed6200914f
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c
@@ -0,0 +1,2502 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * Copyright (c) 2011-2012 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
+ * in this position and unchanged.
+ * 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$");
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_UTIME_H
+#include <sys/utime.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include <winioctl.h>
+
+/* TODO: Support Mac OS 'quarantine' feature. This is really just a
+ * standard tag to mark files that have been downloaded as "tainted".
+ * On Mac OS, we should mark the extracted files as tainted if the
+ * archive being read was tainted. Windows has a similar feature; we
+ * should investigate ways to support this generically. */
+
+#include "archive.h"
+#include "archive_acl_private.h"
+#include "archive_string.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef IO_REPARSE_TAG_SYMLINK
+/* Old SDKs do not provide IO_REPARSE_TAG_SYMLINK */
+#define IO_REPARSE_TAG_SYMLINK 0xA000000CL
+#endif
+
+static BOOL SetFilePointerEx_perso(HANDLE hFile,
+ LARGE_INTEGER liDistanceToMove,
+ PLARGE_INTEGER lpNewFilePointer,
+ DWORD dwMoveMethod)
+{
+ LARGE_INTEGER li;
+ li.QuadPart = liDistanceToMove.QuadPart;
+ li.LowPart = SetFilePointer(
+ hFile, li.LowPart, &li.HighPart, dwMoveMethod);
+ if(lpNewFilePointer) {
+ lpNewFilePointer->QuadPart = li.QuadPart;
+ }
+ return li.LowPart != (DWORD)-1 || GetLastError() == NO_ERROR;
+}
+
+struct fixup_entry {
+ struct fixup_entry *next;
+ struct archive_acl acl;
+ mode_t mode;
+ int64_t atime;
+ int64_t birthtime;
+ int64_t mtime;
+ int64_t ctime;
+ unsigned long atime_nanos;
+ unsigned long birthtime_nanos;
+ unsigned long mtime_nanos;
+ unsigned long ctime_nanos;
+ unsigned long fflags_set;
+ int fixup; /* bitmask of what needs fixing */
+ wchar_t *name;
+};
+
+/*
+ * We use a bitmask to track which operations remain to be done for
+ * this file. In particular, this helps us avoid unnecessary
+ * operations when it's possible to take care of one step as a
+ * side-effect of another. For example, mkdir() can specify the mode
+ * for the newly-created object but symlink() cannot. This means we
+ * can skip chmod() if mkdir() succeeded, but we must explicitly
+ * chmod() if we're trying to create a directory that already exists
+ * (mkdir() failed) or if we're restoring a symlink. Similarly, we
+ * need to verify UID/GID before trying to restore SUID/SGID bits;
+ * that verification can occur explicitly through a stat() call or
+ * implicitly because of a successful chown() call.
+ */
+#define TODO_MODE_FORCE 0x40000000
+#define TODO_MODE_BASE 0x20000000
+#define TODO_SUID 0x10000000
+#define TODO_SUID_CHECK 0x08000000
+#define TODO_SGID 0x04000000
+#define TODO_SGID_CHECK 0x02000000
+#define TODO_MODE (TODO_MODE_BASE|TODO_SUID|TODO_SGID)
+#define TODO_TIMES ARCHIVE_EXTRACT_TIME
+#define TODO_OWNER ARCHIVE_EXTRACT_OWNER
+#define TODO_FFLAGS ARCHIVE_EXTRACT_FFLAGS
+#define TODO_ACLS ARCHIVE_EXTRACT_ACL
+#define TODO_XATTR ARCHIVE_EXTRACT_XATTR
+#define TODO_MAC_METADATA ARCHIVE_EXTRACT_MAC_METADATA
+
+struct archive_write_disk {
+ struct archive archive;
+
+ mode_t user_umask;
+ struct fixup_entry *fixup_list;
+ struct fixup_entry *current_fixup;
+ int64_t user_uid;
+ int skip_file_set;
+ int64_t skip_file_dev;
+ int64_t skip_file_ino;
+ time_t start_time;
+
+ int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid);
+ void (*cleanup_gid)(void *private);
+ void *lookup_gid_data;
+ int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid);
+ void (*cleanup_uid)(void *private);
+ void *lookup_uid_data;
+
+ /*
+ * Full path of last file to satisfy symlink checks.
+ */
+ struct archive_wstring path_safe;
+
+ /*
+ * Cached stat data from disk for the current entry.
+ * If this is valid, pst points to st. Otherwise,
+ * pst is null.
+ */
+ BY_HANDLE_FILE_INFORMATION st;
+ BY_HANDLE_FILE_INFORMATION *pst;
+
+ /* Information about the object being restored right now. */
+ struct archive_entry *entry; /* Entry being extracted. */
+ wchar_t *name; /* Name of entry, possibly edited. */
+ struct archive_wstring _name_data; /* backing store for 'name' */
+ /* Tasks remaining for this object. */
+ int todo;
+ /* Tasks deferred until end-of-archive. */
+ int deferred;
+ /* Options requested by the client. */
+ int flags;
+ /* Handle for the file we're restoring. */
+ HANDLE fh;
+ /* Current offset for writing data to the file. */
+ int64_t offset;
+ /* Last offset actually written to disk. */
+ int64_t fd_offset;
+ /* Total bytes actually written to files. */
+ int64_t total_bytes_written;
+ /* Maximum size of file, -1 if unknown. */
+ int64_t filesize;
+ /* Dir we were in before this restore; only for deep paths. */
+ int restore_pwd;
+ /* Mode we should use for this entry; affected by _PERM and umask. */
+ mode_t mode;
+ /* UID/GID to use in restoring this entry. */
+ int64_t uid;
+ int64_t gid;
+};
+
+/*
+ * Default mode for dirs created automatically (will be modified by umask).
+ * Note that POSIX specifies 0777 for implicity-created dirs, "modified
+ * by the process' file creation mask."
+ */
+#define DEFAULT_DIR_MODE 0777
+/*
+ * Dir modes are restored in two steps: During the extraction, the permissions
+ * in the archive are modified to match the following limits. During
+ * the post-extract fixup pass, the permissions from the archive are
+ * applied.
+ */
+#define MINIMUM_DIR_MODE 0700
+#define MAXIMUM_DIR_MODE 0775
+
+static int check_symlinks(struct archive_write_disk *);
+static int create_filesystem_object(struct archive_write_disk *);
+static struct fixup_entry *current_fixup(struct archive_write_disk *,
+ const wchar_t *pathname);
+static int cleanup_pathname(struct archive_write_disk *);
+static int create_dir(struct archive_write_disk *, wchar_t *);
+static int create_parent_dir(struct archive_write_disk *, wchar_t *);
+static int la_chmod(const wchar_t *, mode_t);
+static int older(BY_HANDLE_FILE_INFORMATION *, struct archive_entry *);
+static int permissive_name_w(struct archive_write_disk *);
+static int restore_entry(struct archive_write_disk *);
+static int set_acls(struct archive_write_disk *, HANDLE h,
+ const wchar_t *, struct archive_acl *);
+static int set_xattrs(struct archive_write_disk *);
+static int set_fflags(struct archive_write_disk *);
+static int set_ownership(struct archive_write_disk *);
+static int set_mode(struct archive_write_disk *, int mode);
+static int set_times(struct archive_write_disk *, HANDLE, int,
+ const wchar_t *, time_t, long, time_t, long, time_t,
+ long, time_t, long);
+static int set_times_from_entry(struct archive_write_disk *);
+static struct fixup_entry *sort_dir_list(struct fixup_entry *p);
+static ssize_t write_data_block(struct archive_write_disk *,
+ const char *, size_t);
+
+static struct archive_vtable *archive_write_disk_vtable(void);
+
+static int _archive_write_disk_close(struct archive *);
+static int _archive_write_disk_free(struct archive *);
+static int _archive_write_disk_header(struct archive *,
+ struct archive_entry *);
+static int64_t _archive_write_disk_filter_bytes(struct archive *, int);
+static int _archive_write_disk_finish_entry(struct archive *);
+static ssize_t _archive_write_disk_data(struct archive *, const void *,
+ size_t);
+static ssize_t _archive_write_disk_data_block(struct archive *, const void *,
+ size_t, int64_t);
+
+#define bhfi_dev(bhfi) ((bhfi)->dwVolumeSerialNumber)
+/* Treat FileIndex as i-node. We should remove a sequence number
+ * which is high-16-bits of nFileIndexHigh. */
+#define bhfi_ino(bhfi) \
+ ((((int64_t)((bhfi)->nFileIndexHigh & 0x0000FFFFUL)) << 32) \
+ + (bhfi)->nFileIndexLow)
+#define bhfi_size(bhfi) \
+ ((((int64_t)(bhfi)->nFileSizeHigh) << 32) + (bhfi)->nFileSizeLow)
+
+static int
+file_information(struct archive_write_disk *a, wchar_t *path,
+ BY_HANDLE_FILE_INFORMATION *st, mode_t *mode, int sim_lstat)
+{
+ HANDLE h;
+ int r;
+ DWORD flag = FILE_FLAG_BACKUP_SEMANTICS;
+ WIN32_FIND_DATAW findData;
+
+ if (sim_lstat || mode != NULL) {
+ h = FindFirstFileW(path, &findData);
+ if (h == INVALID_HANDLE_VALUE &&
+ GetLastError() == ERROR_INVALID_NAME) {
+ wchar_t *full;
+ full = __la_win_permissive_name_w(path);
+ h = FindFirstFileW(full, &findData);
+ free(full);
+ }
+ if (h == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+ FindClose(h);
+ }
+
+ /* Is symlink file ? */
+ if (sim_lstat &&
+ ((findData.dwFileAttributes
+ & FILE_ATTRIBUTE_REPARSE_POINT) &&
+ (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK)))
+ flag |= FILE_FLAG_OPEN_REPARSE_POINT;
+
+ h = CreateFileW(a->name, 0, 0, NULL,
+ OPEN_EXISTING, flag, NULL);
+ if (h == INVALID_HANDLE_VALUE &&
+ GetLastError() == ERROR_INVALID_NAME) {
+ wchar_t *full;
+ full = __la_win_permissive_name_w(path);
+ h = CreateFileW(full, 0, 0, NULL,
+ OPEN_EXISTING, flag, NULL);
+ free(full);
+ }
+ if (h == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+ r = GetFileInformationByHandle(h, st);
+ CloseHandle(h);
+ if (r == 0) {
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+
+ if (mode == NULL)
+ return (0);
+
+ *mode = S_IRUSR | S_IRGRP | S_IROTH;
+ if ((st->dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0)
+ *mode |= S_IWUSR | S_IWGRP | S_IWOTH;
+ if ((st->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
+ findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
+ *mode |= S_IFLNK;
+ else if (st->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ *mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
+ else {
+ const wchar_t *p;
+
+ *mode |= S_IFREG;
+ p = wcsrchr(path, L'.');
+ if (p != NULL && wcslen(p) == 4) {
+ switch (p[1]) {
+ case L'B': case L'b':
+ if ((p[2] == L'A' || p[2] == L'a' ) &&
+ (p[3] == L'T' || p[3] == L't' ))
+ *mode |= S_IXUSR | S_IXGRP | S_IXOTH;
+ 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;
+ case L'E': case L'e':
+ if ((p[2] == L'X' || p[2] == L'x' ) &&
+ (p[3] == L'E' || p[3] == L'e' ))
+ *mode |= S_IXUSR | S_IXGRP | S_IXOTH;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return (0);
+}
+
+/*
+ * Note: The path, for example, "aa/a/../b../c" will be converted to "aa/c"
+ * by GetFullPathNameW() W32 API, which __la_win_permissive_name_w uses.
+ * It means we cannot handle multiple dirs in one archive_entry.
+ * So we have to make the full-pathname in another way, which does not
+ * break "../" path string.
+ */
+static int
+permissive_name_w(struct archive_write_disk *a)
+{
+ wchar_t *wn, *wnp;
+ wchar_t *ws, *wsp;
+ DWORD l;
+
+ wnp = a->name;
+ if (wnp[0] == L'\\' && wnp[1] == L'\\' &&
+ wnp[2] == L'?' && wnp[3] == L'\\')
+ /* We have already a permissive name. */
+ return (0);
+
+ if (wnp[0] == L'\\' && wnp[1] == L'\\' &&
+ wnp[2] == L'.' && wnp[3] == L'\\') {
+ /* This is a device name */
+ if (((wnp[4] >= L'a' && wnp[4] <= L'z') ||
+ (wnp[4] >= L'A' && wnp[4] <= L'Z')) &&
+ wnp[5] == L':' && wnp[6] == L'\\') {
+ wnp[2] = L'?';/* Not device name. */
+ return (0);
+ }
+ }
+
+ /*
+ * A full-pathname starting with a drive name like "C:\abc".
+ */
+ if (((wnp[0] >= L'a' && wnp[0] <= L'z') ||
+ (wnp[0] >= L'A' && wnp[0] <= L'Z')) &&
+ wnp[1] == L':' && wnp[2] == L'\\') {
+ wn = _wcsdup(wnp);
+ if (wn == NULL)
+ return (-1);
+ archive_wstring_ensure(&(a->_name_data), 4 + wcslen(wn) + 1);
+ a->name = a->_name_data.s;
+ /* Prepend "\\?\" */
+ archive_wstrncpy(&(a->_name_data), L"\\\\?\\", 4);
+ archive_wstrcat(&(a->_name_data), wn);
+ free(wn);
+ return (0);
+ }
+
+ /*
+ * A full-pathname pointig a network drive
+ * like "\\<server-name>\<share-name>\file".
+ */
+ if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') {
+ const wchar_t *p = &wnp[2];
+
+ /* Skip server-name letters. */
+ while (*p != L'\\' && *p != L'\0')
+ ++p;
+ if (*p == L'\\') {
+ const wchar_t *rp = ++p;
+ /* Skip share-name letters. */
+ while (*p != L'\\' && *p != L'\0')
+ ++p;
+ if (*p == L'\\' && p != rp) {
+ /* Now, match patterns such as
+ * "\\server-name\share-name\" */
+ wn = _wcsdup(wnp);
+ if (wn == NULL)
+ return (-1);
+ archive_wstring_ensure(&(a->_name_data),
+ 8 + wcslen(wn) + 1);
+ a->name = a->_name_data.s;
+ /* Prepend "\\?\UNC\" */
+ archive_wstrncpy(&(a->_name_data),
+ L"\\\\?\\UNC\\", 8);
+ archive_wstrcat(&(a->_name_data), wn+2);
+ free(wn);
+ return (0);
+ }
+ }
+ return (0);
+ }
+
+ /*
+ * Get current working directory.
+ */
+ l = GetCurrentDirectoryW(0, NULL);
+ if (l == 0)
+ return (-1);
+ ws = malloc(l * sizeof(wchar_t));
+ l = GetCurrentDirectoryW(l, ws);
+ if (l == 0) {
+ free(ws);
+ return (-1);
+ }
+ wsp = ws;
+
+ /*
+ * A full-pathname starting without a drive name like "\abc".
+ */
+ if (wnp[0] == L'\\') {
+ wn = _wcsdup(wnp);
+ if (wn == NULL)
+ return (-1);
+ archive_wstring_ensure(&(a->_name_data),
+ 4 + 2 + wcslen(wn) + 1);
+ a->name = a->_name_data.s;
+ /* Prepend "\\?\" and drive name. */
+ archive_wstrncpy(&(a->_name_data), L"\\\\?\\", 4);
+ archive_wstrncat(&(a->_name_data), wsp, 2);
+ archive_wstrcat(&(a->_name_data), wn);
+ free(wsp);
+ free(wn);
+ return (0);
+ }
+
+ wn = _wcsdup(wnp);
+ if (wn == NULL)
+ return (-1);
+ archive_wstring_ensure(&(a->_name_data), 4 + l + 1 + wcslen(wn) + 1);
+ a->name = a->_name_data.s;
+ /* Prepend "\\?\" and drive name. */
+ archive_wstrncpy(&(a->_name_data), L"\\\\?\\", 4);
+ archive_wstrncat(&(a->_name_data), wsp, l);
+ archive_wstrncat(&(a->_name_data), L"\\", 1);
+ archive_wstrcat(&(a->_name_data), wn);
+ a->name = a->_name_data.s;
+ free(wsp);
+ free(wn);
+ return (0);
+}
+
+static int
+la_chmod(const wchar_t *path, mode_t mode)
+{
+ DWORD attr;
+ BOOL r;
+ wchar_t *fullname;
+ int ret = 0;
+
+ fullname = NULL;
+ attr = GetFileAttributesW(path);
+ if (attr == (DWORD)-1 &&
+ GetLastError() == ERROR_INVALID_NAME) {
+ fullname = __la_win_permissive_name_w(path);
+ attr = GetFileAttributesW(fullname);
+ }
+ if (attr == (DWORD)-1) {
+ la_dosmaperr(GetLastError());
+ ret = -1;
+ goto exit_chmode;
+ }
+ if (mode & _S_IWRITE)
+ attr &= ~FILE_ATTRIBUTE_READONLY;
+ else
+ attr |= FILE_ATTRIBUTE_READONLY;
+ if (fullname != NULL)
+ r = SetFileAttributesW(fullname, attr);
+ else
+ r = SetFileAttributesW(path, attr);
+ if (r == 0) {
+ la_dosmaperr(GetLastError());
+ ret = -1;
+ }
+exit_chmode:
+ free(fullname);
+ return (ret);
+}
+
+static void *
+la_GetFunctionKernel32(const char *name)
+{
+ static HINSTANCE lib;
+ static int set;
+ if (!set) {
+ set = 1;
+ lib = LoadLibrary(TEXT("kernel32.dll"));
+ }
+ if (lib == NULL) {
+ fprintf(stderr, "Can't load kernel32.dll?!\n");
+ exit(1);
+ }
+ return (void *)GetProcAddress(lib, name);
+}
+
+static int
+la_CreateHardLinkW(wchar_t *linkname, wchar_t *target)
+{
+ static BOOLEAN (WINAPI *f)(LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES);
+ static int set;
+ BOOL ret;
+
+ if (!set) {
+ set = 1;
+ f = la_GetFunctionKernel32("CreateHardLinkW");
+ }
+ if (!f)
+ return (0);
+ ret = (*f)(linkname, target, NULL);
+ if (!ret) {
+ /* Under windows 2000, it is necessary to remove
+ * the "\\?\" prefix. */
+#define IS_UNC(name) ((name[0] == L'U' || name[0] == L'u') && \
+ (name[1] == L'N' || name[1] == L'n') && \
+ (name[2] == L'C' || name[2] == L'c') && \
+ name[3] == L'\\')
+ if (!wcsncmp(linkname,L"\\\\?\\", 4)) {
+ linkname += 4;
+ if (IS_UNC(linkname))
+ linkname += 4;
+ }
+ if (!wcsncmp(target,L"\\\\?\\", 4)) {
+ target += 4;
+ if (IS_UNC(target))
+ target += 4;
+ }
+#undef IS_UNC
+ ret = (*f)(linkname, target, NULL);
+ }
+ return (ret);
+}
+
+static int
+la_ftruncate(HANDLE handle, int64_t length)
+{
+ LARGE_INTEGER distance;
+
+ if (GetFileType(handle) != FILE_TYPE_DISK) {
+ errno = EBADF;
+ return (-1);
+ }
+ distance.QuadPart = length;
+ if (!SetFilePointerEx_perso(handle, distance, NULL, FILE_BEGIN)) {
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+ if (!SetEndOfFile(handle)) {
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+ return (0);
+}
+
+static int
+lazy_stat(struct archive_write_disk *a)
+{
+ if (a->pst != NULL) {
+ /* Already have stat() data available. */
+ return (ARCHIVE_OK);
+ }
+ if (a->fh != INVALID_HANDLE_VALUE &&
+ GetFileInformationByHandle(a->fh, &a->st) == 0) {
+ a->pst = &a->st;
+ return (ARCHIVE_OK);
+ }
+
+ /*
+ * XXX At this point, symlinks should not be hit, otherwise
+ * XXX a race occurred. Do we want to check explicitly for that?
+ */
+ if (file_information(a, a->name, &a->st, NULL, 1) == 0) {
+ a->pst = &a->st;
+ return (ARCHIVE_OK);
+ }
+ archive_set_error(&a->archive, errno, "Couldn't stat file");
+ return (ARCHIVE_WARN);
+}
+
+static struct archive_vtable *
+archive_write_disk_vtable(void)
+{
+ static struct archive_vtable av;
+ static int inited = 0;
+
+ if (!inited) {
+ av.archive_close = _archive_write_disk_close;
+ av.archive_filter_bytes = _archive_write_disk_filter_bytes;
+ av.archive_free = _archive_write_disk_free;
+ av.archive_write_header = _archive_write_disk_header;
+ av.archive_write_finish_entry
+ = _archive_write_disk_finish_entry;
+ av.archive_write_data = _archive_write_disk_data;
+ av.archive_write_data_block = _archive_write_disk_data_block;
+ inited = 1;
+ }
+ return (&av);
+}
+
+static int64_t
+_archive_write_disk_filter_bytes(struct archive *_a, int n)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ (void)n; /* UNUSED */
+ if (n == -1 || n == 0)
+ return (a->total_bytes_written);
+ return (-1);
+}
+
+
+int
+archive_write_disk_set_options(struct archive *_a, int flags)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+
+ a->flags = flags;
+ return (ARCHIVE_OK);
+}
+
+
+/*
+ * Extract this entry to disk.
+ *
+ * TODO: Validate hardlinks. According to the standards, we're
+ * supposed to check each extracted hardlink and squawk if it refers
+ * to a file that we didn't restore. I'm not entirely convinced this
+ * is a good idea, but more importantly: Is there any way to validate
+ * hardlinks without keeping a complete list of filenames from the
+ * entire archive?? Ugh.
+ *
+ */
+static int
+_archive_write_disk_header(struct archive *_a, struct archive_entry *entry)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ struct fixup_entry *fe;
+ int ret, r;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_write_disk_header");
+ archive_clear_error(&a->archive);
+ if (a->archive.state & ARCHIVE_STATE_DATA) {
+ r = _archive_write_disk_finish_entry(&a->archive);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ }
+
+ /* Set up for this particular entry. */
+ a->pst = NULL;
+ a->current_fixup = NULL;
+ a->deferred = 0;
+ if (a->entry) {
+ archive_entry_free(a->entry);
+ a->entry = NULL;
+ }
+ a->entry = archive_entry_clone(entry);
+ a->fh = INVALID_HANDLE_VALUE;
+ a->fd_offset = 0;
+ a->offset = 0;
+ a->restore_pwd = -1;
+ a->uid = a->user_uid;
+ a->mode = archive_entry_mode(a->entry);
+ if (archive_entry_size_is_set(a->entry))
+ a->filesize = archive_entry_size(a->entry);
+ else
+ a->filesize = -1;
+ archive_wstrcpy(&(a->_name_data), archive_entry_pathname_w(a->entry));
+ a->name = a->_name_data.s;
+ archive_clear_error(&a->archive);
+
+ /*
+ * Clean up the requested path. This is necessary for correct
+ * dir restores; the dir restore logic otherwise gets messed
+ * up by nonsense like "dir/.".
+ */
+ ret = cleanup_pathname(a);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ /*
+ * Generate a full-pathname and use it from here.
+ */
+ if (permissive_name_w(a) < 0) {
+ errno = EINVAL;
+ return (ARCHIVE_FAILED);
+ }
+
+ /*
+ * Query the umask so we get predictable mode settings.
+ * This gets done on every call to _write_header in case the
+ * user edits their umask during the extraction for some
+ * reason.
+ */
+ umask(a->user_umask = umask(0));
+
+ /* Figure out what we need to do for this entry. */
+ a->todo = TODO_MODE_BASE;
+ if (a->flags & ARCHIVE_EXTRACT_PERM) {
+ a->todo |= TODO_MODE_FORCE; /* Be pushy about permissions. */
+ /*
+ * SGID requires an extra "check" step because we
+ * cannot easily predict the GID that the system will
+ * assign. (Different systems assign GIDs to files
+ * based on a variety of criteria, including process
+ * credentials and the gid of the enclosing
+ * directory.) We can only restore the SGID bit if
+ * the file has the right GID, and we only know the
+ * GID if we either set it (see set_ownership) or if
+ * we've actually called stat() on the file after it
+ * was restored. Since there are several places at
+ * which we might verify the GID, we need a TODO bit
+ * to keep track.
+ */
+ if (a->mode & S_ISGID)
+ a->todo |= TODO_SGID | TODO_SGID_CHECK;
+ /*
+ * Verifying the SUID is simpler, but can still be
+ * done in multiple ways, hence the separate "check" bit.
+ */
+ if (a->mode & S_ISUID)
+ a->todo |= TODO_SUID | TODO_SUID_CHECK;
+ } else {
+ /*
+ * User didn't request full permissions, so don't
+ * restore SUID, SGID bits and obey umask.
+ */
+ a->mode &= ~S_ISUID;
+ a->mode &= ~S_ISGID;
+ a->mode &= ~S_ISVTX;
+ a->mode &= ~a->user_umask;
+ }
+#if 0
+ if (a->flags & ARCHIVE_EXTRACT_OWNER)
+ a->todo |= TODO_OWNER;
+#endif
+ if (a->flags & ARCHIVE_EXTRACT_TIME)
+ a->todo |= TODO_TIMES;
+ if (a->flags & ARCHIVE_EXTRACT_ACL) {
+ if (archive_entry_filetype(a->entry) == AE_IFDIR)
+ a->deferred |= TODO_ACLS;
+ else
+ a->todo |= TODO_ACLS;
+ }
+ if (a->flags & ARCHIVE_EXTRACT_XATTR)
+ a->todo |= TODO_XATTR;
+ if (a->flags & ARCHIVE_EXTRACT_FFLAGS)
+ a->todo |= TODO_FFLAGS;
+ if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) {
+ ret = check_symlinks(a);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ }
+
+ ret = restore_entry(a);
+
+ /*
+ * TODO: There are rumours that some extended attributes must
+ * be restored before file data is written. If this is true,
+ * then we either need to write all extended attributes both
+ * before and after restoring the data, or find some rule for
+ * determining which must go first and which last. Due to the
+ * many ways people are using xattrs, this may prove to be an
+ * intractable problem.
+ */
+
+ /*
+ * Fixup uses the unedited pathname from archive_entry_pathname(),
+ * because it is relative to the base dir and the edited path
+ * might be relative to some intermediate dir as a result of the
+ * deep restore logic.
+ */
+ if (a->deferred & TODO_MODE) {
+ fe = current_fixup(a, archive_entry_pathname_w(entry));
+ fe->fixup |= TODO_MODE_BASE;
+ fe->mode = a->mode;
+ }
+
+ if ((a->deferred & TODO_TIMES)
+ && (archive_entry_mtime_is_set(entry)
+ || archive_entry_atime_is_set(entry))) {
+ fe = current_fixup(a, archive_entry_pathname_w(entry));
+ fe->mode = a->mode;
+ fe->fixup |= TODO_TIMES;
+ if (archive_entry_atime_is_set(entry)) {
+ fe->atime = archive_entry_atime(entry);
+ fe->atime_nanos = archive_entry_atime_nsec(entry);
+ } else {
+ /* If atime is unset, use start time. */
+ fe->atime = a->start_time;
+ fe->atime_nanos = 0;
+ }
+ if (archive_entry_mtime_is_set(entry)) {
+ fe->mtime = archive_entry_mtime(entry);
+ fe->mtime_nanos = archive_entry_mtime_nsec(entry);
+ } else {
+ /* If mtime is unset, use start time. */
+ fe->mtime = a->start_time;
+ fe->mtime_nanos = 0;
+ }
+ if (archive_entry_birthtime_is_set(entry)) {
+ fe->birthtime = archive_entry_birthtime(entry);
+ fe->birthtime_nanos = archive_entry_birthtime_nsec(entry);
+ } else {
+ /* If birthtime is unset, use mtime. */
+ fe->birthtime = fe->mtime;
+ fe->birthtime_nanos = fe->mtime_nanos;
+ }
+ }
+
+ if (a->deferred & TODO_ACLS) {
+ fe = current_fixup(a, archive_entry_pathname_w(entry));
+ archive_acl_copy(&fe->acl, archive_entry_acl(entry));
+ }
+
+ if (a->deferred & TODO_FFLAGS) {
+ fe = current_fixup(a, archive_entry_pathname_w(entry));
+ fe->fixup |= TODO_FFLAGS;
+ /* TODO: Complete this.. defer fflags from below. */
+ }
+
+ /*
+ * On Windows, A creating sparse file requires a special mark.
+ */
+ if (a->fh != INVALID_HANDLE_VALUE &&
+ archive_entry_sparse_count(entry) > 0) {
+ int64_t base = 0, offset, length;
+ int i, cnt = archive_entry_sparse_reset(entry);
+ int sparse = 0;
+
+ for (i = 0; i < cnt; i++) {
+ archive_entry_sparse_next(entry, &offset, &length);
+ if (offset - base >= 4096) {
+ sparse = 1;/* we have a hole. */
+ break;
+ }
+ base = offset + length;
+ }
+ if (sparse) {
+ DWORD dmy;
+ /* Mark this file as sparse. */
+ DeviceIoControl(a->fh, FSCTL_SET_SPARSE,
+ NULL, 0, NULL, 0, &dmy, NULL);
+ }
+ }
+
+ /* We've created the object and are ready to pour data into it. */
+ if (ret >= ARCHIVE_WARN)
+ a->archive.state = ARCHIVE_STATE_DATA;
+ /*
+ * If it's not open, tell our client not to try writing.
+ * In particular, dirs, links, etc, don't get written to.
+ */
+ if (a->fh == INVALID_HANDLE_VALUE) {
+ archive_entry_set_size(entry, 0);
+ a->filesize = 0;
+ }
+
+ return (ret);
+}
+
+int
+archive_write_disk_set_skip_file(struct archive *_a, int64_t d, int64_t i)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_set_skip_file");
+ a->skip_file_set = 1;
+ a->skip_file_dev = d;
+ a->skip_file_ino = i;
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+write_data_block(struct archive_write_disk *a, const char *buff, size_t size)
+{
+ OVERLAPPED ol;
+ uint64_t start_size = size;
+ DWORD bytes_written = 0;
+ ssize_t block_size = 0, bytes_to_write;
+
+ if (size == 0)
+ return (ARCHIVE_OK);
+
+ if (a->filesize == 0 || a->fh == INVALID_HANDLE_VALUE) {
+ archive_set_error(&a->archive, 0,
+ "Attempt to write to an empty file");
+ return (ARCHIVE_WARN);
+ }
+
+ if (a->flags & ARCHIVE_EXTRACT_SPARSE) {
+ /* XXX TODO XXX Is there a more appropriate choice here ? */
+ /* This needn't match the filesystem allocation size. */
+ block_size = 16*1024;
+ }
+
+ /* If this write would run beyond the file size, truncate it. */
+ if (a->filesize >= 0 && (int64_t)(a->offset + size) > a->filesize)
+ start_size = size = (size_t)(a->filesize - a->offset);
+
+ /* Write the data. */
+ while (size > 0) {
+ if (block_size == 0) {
+ bytes_to_write = size;
+ } else {
+ /* We're sparsifying the file. */
+ const char *p, *end;
+ int64_t block_end;
+
+ /* Skip leading zero bytes. */
+ for (p = buff, end = buff + size; p < end; ++p) {
+ if (*p != '\0')
+ break;
+ }
+ a->offset += p - buff;
+ size -= p - buff;
+ buff = p;
+ if (size == 0)
+ break;
+
+ /* Calculate next block boundary after offset. */
+ block_end
+ = (a->offset / block_size + 1) * block_size;
+
+ /* If the adjusted write would cross block boundary,
+ * truncate it to the block boundary. */
+ bytes_to_write = size;
+ if (a->offset + bytes_to_write > block_end)
+ bytes_to_write = (DWORD)(block_end - a->offset);
+ }
+ memset(&ol, 0, sizeof(ol));
+ ol.Offset = (DWORD)(a->offset & 0xFFFFFFFF);
+ ol.OffsetHigh = (DWORD)(a->offset >> 32);
+ if (!WriteFile(a->fh, buff, (uint32_t)bytes_to_write,
+ &bytes_written, &ol)) {
+ DWORD lasterr;
+
+ lasterr = GetLastError();
+ if (lasterr == ERROR_ACCESS_DENIED)
+ errno = EBADF;
+ else
+ la_dosmaperr(lasterr);
+ archive_set_error(&a->archive, errno, "Write failed");
+ return (ARCHIVE_WARN);
+ }
+ buff += bytes_written;
+ size -= bytes_written;
+ a->total_bytes_written += bytes_written;
+ a->offset += bytes_written;
+ a->fd_offset = a->offset;
+ }
+ return ((ssize_t)(start_size - size));
+}
+
+static ssize_t
+_archive_write_disk_data_block(struct archive *_a,
+ const void *buff, size_t size, int64_t offset)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ ssize_t r;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_DATA, "archive_write_data_block");
+
+ a->offset = offset;
+ r = write_data_block(a, buff, size);
+ if (r < ARCHIVE_OK)
+ return (r);
+ if ((size_t)r < size) {
+ archive_set_error(&a->archive, 0,
+ "Write request too large");
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+_archive_write_disk_data(struct archive *_a, const void *buff, size_t size)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_DATA, "archive_write_data");
+
+ return (write_data_block(a, buff, size));
+}
+
+static int
+_archive_write_disk_finish_entry(struct archive *_a)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ int ret = ARCHIVE_OK;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_write_finish_entry");
+ if (a->archive.state & ARCHIVE_STATE_HEADER)
+ return (ARCHIVE_OK);
+ archive_clear_error(&a->archive);
+
+ /* Pad or truncate file to the right size. */
+ if (a->fh == INVALID_HANDLE_VALUE) {
+ /* There's no file. */
+ } else if (a->filesize < 0) {
+ /* File size is unknown, so we can't set the size. */
+ } else if (a->fd_offset == a->filesize) {
+ /* Last write ended at exactly the filesize; we're done. */
+ /* Hopefully, this is the common case. */
+ } else {
+ if (la_ftruncate(a->fh, a->filesize) == -1) {
+ archive_set_error(&a->archive, errno,
+ "File size could not be restored");
+ return (ARCHIVE_FAILED);
+ }
+ }
+
+ /* Restore metadata. */
+
+ /*
+ * Look up the "real" UID only if we're going to need it.
+ * TODO: the TODO_SGID condition can be dropped here, can't it?
+ */
+ if (a->todo & (TODO_OWNER | TODO_SUID | TODO_SGID)) {
+ a->uid = archive_write_disk_uid(&a->archive,
+ archive_entry_uname(a->entry),
+ archive_entry_uid(a->entry));
+ }
+ /* Look up the "real" GID only if we're going to need it. */
+ /* TODO: the TODO_SUID condition can be dropped here, can't it? */
+ if (a->todo & (TODO_OWNER | TODO_SGID | TODO_SUID)) {
+ a->gid = archive_write_disk_gid(&a->archive,
+ archive_entry_gname(a->entry),
+ archive_entry_gid(a->entry));
+ }
+
+ /*
+ * Restore ownership before set_mode tries to restore suid/sgid
+ * bits. If we set the owner, we know what it is and can skip
+ * a stat() call to examine the ownership of the file on disk.
+ */
+ if (a->todo & TODO_OWNER)
+ ret = set_ownership(a);
+
+ /*
+ * set_mode must precede ACLs on systems such as Solaris and
+ * FreeBSD where setting the mode implicitly clears extended ACLs
+ */
+ if (a->todo & TODO_MODE) {
+ int r2 = set_mode(a, a->mode);
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * Security-related extended attributes (such as
+ * security.capability on Linux) have to be restored last,
+ * since they're implicitly removed by other file changes.
+ */
+ if (a->todo & TODO_XATTR) {
+ int r2 = set_xattrs(a);
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * Some flags prevent file modification; they must be restored after
+ * file contents are written.
+ */
+ if (a->todo & TODO_FFLAGS) {
+ int r2 = set_fflags(a);
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * Time must follow most other metadata;
+ * otherwise atime will get changed.
+ */
+ if (a->todo & TODO_TIMES) {
+ int r2 = set_times_from_entry(a);
+ if (r2 < ret) ret = r2;
+ }
+
+ /*
+ * ACLs must be restored after timestamps because there are
+ * ACLs that prevent attribute changes (including time).
+ */
+ if (a->todo & TODO_ACLS) {
+ int r2 = set_acls(a, a->fh,
+ archive_entry_pathname_w(a->entry),
+ archive_entry_acl(a->entry));
+ if (r2 < ret) ret = r2;
+ }
+
+ /* If there's an fd, we can close it now. */
+ if (a->fh != INVALID_HANDLE_VALUE) {
+ CloseHandle(a->fh);
+ a->fh = INVALID_HANDLE_VALUE;
+ }
+ /* If there's an entry, we can release it now. */
+ if (a->entry) {
+ archive_entry_free(a->entry);
+ a->entry = NULL;
+ }
+ a->archive.state = ARCHIVE_STATE_HEADER;
+ return (ret);
+}
+
+int
+archive_write_disk_set_group_lookup(struct archive *_a,
+ void *private_data,
+ int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid),
+ void (*cleanup_gid)(void *private))
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_set_group_lookup");
+
+ if (a->cleanup_gid != NULL && a->lookup_gid_data != NULL)
+ (a->cleanup_gid)(a->lookup_gid_data);
+
+ a->lookup_gid = lookup_gid;
+ a->cleanup_gid = cleanup_gid;
+ a->lookup_gid_data = private_data;
+ return (ARCHIVE_OK);
+}
+
+int
+archive_write_disk_set_user_lookup(struct archive *_a,
+ void *private_data,
+ int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid),
+ void (*cleanup_uid)(void *private))
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_set_user_lookup");
+
+ if (a->cleanup_uid != NULL && a->lookup_uid_data != NULL)
+ (a->cleanup_uid)(a->lookup_uid_data);
+
+ a->lookup_uid = lookup_uid;
+ a->cleanup_uid = cleanup_uid;
+ a->lookup_uid_data = private_data;
+ return (ARCHIVE_OK);
+}
+
+int64_t
+archive_write_disk_gid(struct archive *_a, const char *name, int64_t id)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_gid");
+ if (a->lookup_gid)
+ return (a->lookup_gid)(a->lookup_gid_data, name, id);
+ return (id);
+}
+
+int64_t
+archive_write_disk_uid(struct archive *_a, const char *name, int64_t id)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY, "archive_write_disk_uid");
+ if (a->lookup_uid)
+ return (a->lookup_uid)(a->lookup_uid_data, name, id);
+ return (id);
+}
+
+/*
+ * Create a new archive_write_disk object and initialize it with global state.
+ */
+struct archive *
+archive_write_disk_new(void)
+{
+ struct archive_write_disk *a;
+
+ a = (struct archive_write_disk *)malloc(sizeof(*a));
+ if (a == NULL)
+ return (NULL);
+ memset(a, 0, sizeof(*a));
+ a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC;
+ /* We're ready to write a header immediately. */
+ a->archive.state = ARCHIVE_STATE_HEADER;
+ a->archive.vtable = archive_write_disk_vtable();
+ a->start_time = time(NULL);
+ /* Query and restore the umask. */
+ umask(a->user_umask = umask(0));
+ if (archive_wstring_ensure(&a->path_safe, 512) == NULL) {
+ free(a);
+ return (NULL);
+ }
+ return (&a->archive);
+}
+
+static int
+disk_unlink(wchar_t *path)
+{
+ wchar_t *fullname;
+ int r;
+
+ r = _wunlink(path);
+ if (r != 0 && GetLastError() == ERROR_INVALID_NAME) {
+ fullname = __la_win_permissive_name_w(path);
+ r = _wunlink(fullname);
+ free(fullname);
+ }
+ return (r);
+}
+
+static int
+disk_rmdir(wchar_t *path)
+{
+ wchar_t *fullname;
+ int r;
+
+ r = _wrmdir(path);
+ if (r != 0 && GetLastError() == ERROR_INVALID_NAME) {
+ fullname = __la_win_permissive_name_w(path);
+ r = _wrmdir(fullname);
+ free(fullname);
+ }
+ return (r);
+}
+
+/*
+ * The main restore function.
+ */
+static int
+restore_entry(struct archive_write_disk *a)
+{
+ int ret = ARCHIVE_OK, en;
+
+ if (a->flags & ARCHIVE_EXTRACT_UNLINK && !S_ISDIR(a->mode)) {
+ /*
+ * TODO: Fix this. Apparently, there are platforms
+ * that still allow root to hose the entire filesystem
+ * by unlinking a dir. The S_ISDIR() test above
+ * prevents us from using unlink() here if the new
+ * object is a dir, but that doesn't mean the old
+ * object isn't a dir.
+ */
+ if (disk_unlink(a->name) == 0) {
+ /* We removed it, reset cached stat. */
+ a->pst = NULL;
+ } else if (errno == ENOENT) {
+ /* File didn't exist, that's just as good. */
+ } else if (disk_rmdir(a->name) == 0) {
+ /* It was a dir, but now it's gone. */
+ a->pst = NULL;
+ } else {
+ /* We tried, but couldn't get rid of it. */
+ archive_set_error(&a->archive, errno,
+ "Could not unlink");
+ return(ARCHIVE_FAILED);
+ }
+ }
+
+ /* Try creating it first; if this fails, we'll try to recover. */
+ en = create_filesystem_object(a);
+
+ if ((en == ENOTDIR || en == ENOENT)
+ && !(a->flags & ARCHIVE_EXTRACT_NO_AUTODIR)) {
+ wchar_t *full;
+ /* If the parent dir doesn't exist, try creating it. */
+ create_parent_dir(a, a->name);
+ /* Now try to create the object again. */
+ full = __la_win_permissive_name_w(a->name);
+ if (full == NULL) {
+ en = EINVAL;
+ } else {
+ /* Remove multiple directories such as "a/../b../c" */
+ archive_wstrcpy(&(a->_name_data), full);
+ a->name = a->_name_data.s;
+ free(full);
+ en = create_filesystem_object(a);
+ }
+ }
+
+ if ((en == EISDIR || en == EEXIST)
+ && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) {
+ /* If we're not overwriting, we're done. */
+ archive_entry_unset_size(a->entry);
+ return (ARCHIVE_OK);
+ }
+
+ /*
+ * Some platforms return EISDIR if you call
+ * open(O_WRONLY | O_EXCL | O_CREAT) on a directory, some
+ * return EEXIST. POSIX is ambiguous, requiring EISDIR
+ * for open(O_WRONLY) on a dir and EEXIST for open(O_EXCL | O_CREAT)
+ * on an existing item.
+ */
+ if (en == EISDIR) {
+ /* A dir is in the way of a non-dir, rmdir it. */
+ if (disk_rmdir(a->name) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't remove already-existing dir");
+ return (ARCHIVE_FAILED);
+ }
+ a->pst = NULL;
+ /* Try again. */
+ en = create_filesystem_object(a);
+ } else if (en == EEXIST) {
+ mode_t st_mode;
+ /*
+ * We know something is in the way, but we don't know what;
+ * we need to find out before we go any further.
+ */
+ int r = 0;
+ /*
+ * The SECURE_SYMLINK logic has already removed a
+ * symlink to a dir if the client wants that. So
+ * follow the symlink if we're creating a dir.
+ */
+ if (S_ISDIR(a->mode))
+ r = file_information(a, a->name, &a->st, &st_mode, 0);
+ /*
+ * If it's not a dir (or it's a broken symlink),
+ * then don't follow it.
+ */
+ if (r != 0 || !S_ISDIR(a->mode))
+ r = file_information(a, a->name, &a->st, &st_mode, 1);
+ if (r != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't stat existing object");
+ return (ARCHIVE_FAILED);
+ }
+
+ /*
+ * NO_OVERWRITE_NEWER doesn't apply to directories.
+ */
+ if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER)
+ && !S_ISDIR(st_mode)) {
+ if (!older(&(a->st), a->entry)) {
+ archive_entry_unset_size(a->entry);
+ return (ARCHIVE_OK);
+ }
+ }
+
+ /* If it's our archive, we're done. */
+ if (a->skip_file_set &&
+ bhfi_dev(&a->st) == a->skip_file_dev &&
+ bhfi_ino(&a->st) == a->skip_file_ino) {
+ archive_set_error(&a->archive, 0,
+ "Refusing to overwrite archive");
+ return (ARCHIVE_FAILED);
+ }
+
+ if (!S_ISDIR(st_mode)) {
+ /* A non-dir is in the way, unlink it. */
+ if (disk_unlink(a->name) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't unlink already-existing object");
+ return (ARCHIVE_FAILED);
+ }
+ a->pst = NULL;
+ /* Try again. */
+ en = create_filesystem_object(a);
+ } else if (!S_ISDIR(a->mode)) {
+ /* A dir is in the way of a non-dir, rmdir it. */
+ if (disk_rmdir(a->name) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't remove already-existing dir");
+ return (ARCHIVE_FAILED);
+ }
+ /* Try again. */
+ en = create_filesystem_object(a);
+ } else {
+ /*
+ * There's a dir in the way of a dir. Don't
+ * waste time with rmdir()/mkdir(), just fix
+ * up the permissions on the existing dir.
+ * Note that we don't change perms on existing
+ * dirs unless _EXTRACT_PERM is specified.
+ */
+ if ((a->mode != st_mode)
+ && (a->todo & TODO_MODE_FORCE))
+ a->deferred |= (a->todo & TODO_MODE);
+ /* Ownership doesn't need deferred fixup. */
+ en = 0; /* Forget the EEXIST. */
+ }
+ }
+
+ if (en) {
+ /* Everything failed; give up here. */
+ archive_set_error(&a->archive, en, "Can't create '%ls'",
+ a->name);
+ return (ARCHIVE_FAILED);
+ }
+
+ a->pst = NULL; /* Cached stat data no longer valid. */
+ return (ret);
+}
+
+/*
+ * Returns 0 if creation succeeds, or else returns errno value from
+ * the failed system call. Note: This function should only ever perform
+ * a single system call.
+ */
+static int
+create_filesystem_object(struct archive_write_disk *a)
+{
+ /* Create the entry. */
+ const wchar_t *linkname;
+ wchar_t *fullname;
+ mode_t final_mode, mode;
+ int r;
+
+ /* We identify hard/symlinks according to the link names. */
+ /* Since link(2) and symlink(2) don't handle modes, we're done here. */
+ linkname = archive_entry_hardlink_w(a->entry);
+ if (linkname != NULL) {
+ wchar_t *linkfull, *namefull;
+
+ linkfull = __la_win_permissive_name_w(linkname);
+ namefull = __la_win_permissive_name_w(a->name);
+ if (linkfull == NULL || namefull == NULL) {
+ errno = EINVAL;
+ r = -1;
+ } else {
+ r = la_CreateHardLinkW(namefull, linkfull);
+ if (r == 0) {
+ la_dosmaperr(GetLastError());
+ r = errno;
+ } else
+ r = 0;
+ }
+ /*
+ * New cpio and pax formats allow hardlink entries
+ * to carry data, so we may have to open the file
+ * for hardlink entries.
+ *
+ * If the hardlink was successfully created and
+ * the archive doesn't have carry data for it,
+ * consider it to be non-authoritative for meta data.
+ * This is consistent with GNU tar and BSD pax.
+ * If the hardlink does carry data, let the last
+ * archive entry decide ownership.
+ */
+ if (r == 0 && a->filesize <= 0) {
+ a->todo = 0;
+ a->deferred = 0;
+ } else if (r == 0 && a->filesize > 0) {
+ a->fh = CreateFileW(namefull, GENERIC_WRITE, 0, NULL,
+ TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (a->fh == INVALID_HANDLE_VALUE) {
+ la_dosmaperr(GetLastError());
+ r = errno;
+ }
+ }
+ free(linkfull);
+ free(namefull);
+ return (r);
+ }
+ linkname = archive_entry_symlink_w(a->entry);
+ if (linkname != NULL) {
+#if HAVE_SYMLINK
+ return symlink(linkname, a->name) ? errno : 0;
+#else
+ return (EPERM);
+#endif
+ }
+
+ /*
+ * The remaining system calls all set permissions, so let's
+ * try to take advantage of that to avoid an extra chmod()
+ * call. (Recall that umask is set to zero right now!)
+ */
+
+ /* Mode we want for the final restored object (w/o file type bits). */
+ final_mode = a->mode & 07777;
+ /*
+ * The mode that will actually be restored in this step. Note
+ * that SUID, SGID, etc, require additional work to ensure
+ * security, so we never restore them at this point.
+ */
+ mode = final_mode & 0777 & ~a->user_umask;
+
+ switch (a->mode & AE_IFMT) {
+ default:
+ /* POSIX requires that we fall through here. */
+ /* FALLTHROUGH */
+ case AE_IFREG:
+ fullname = a->name;
+ /* O_WRONLY | O_CREAT | O_EXCL */
+ a->fh = CreateFileW(fullname, GENERIC_WRITE, 0, NULL,
+ CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (a->fh == INVALID_HANDLE_VALUE &&
+ GetLastError() == ERROR_INVALID_NAME &&
+ fullname == a->name) {
+ fullname = __la_win_permissive_name_w(a->name);
+ a->fh = CreateFileW(fullname, GENERIC_WRITE, 0, NULL,
+ CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
+ }
+ if (a->fh == INVALID_HANDLE_VALUE) {
+ if (GetLastError() == ERROR_ACCESS_DENIED) {
+ DWORD attr;
+ /* Simulate an errno of POSIX system. */
+ attr = GetFileAttributesW(fullname);
+ if (attr == (DWORD)-1)
+ la_dosmaperr(GetLastError());
+ else if (attr & FILE_ATTRIBUTE_DIRECTORY)
+ errno = EISDIR;
+ else
+ errno = EACCES;
+ } else
+ la_dosmaperr(GetLastError());
+ r = 1;
+ } else
+ r = 0;
+ if (fullname != a->name)
+ free(fullname);
+ break;
+ case AE_IFCHR:
+ case AE_IFBLK:
+ /* TODO: Find a better way to warn about our inability
+ * to restore a block device node. */
+ return (EINVAL);
+ case AE_IFDIR:
+ mode = (mode | MINIMUM_DIR_MODE) & MAXIMUM_DIR_MODE;
+ fullname = a->name;
+ r = CreateDirectoryW(fullname, NULL);
+ if (r == 0 && GetLastError() == ERROR_INVALID_NAME &&
+ fullname == a->name) {
+ fullname = __la_win_permissive_name_w(a->name);
+ r = CreateDirectoryW(fullname, NULL);
+ }
+ if (r != 0) {
+ r = 0;
+ /* Defer setting dir times. */
+ a->deferred |= (a->todo & TODO_TIMES);
+ a->todo &= ~TODO_TIMES;
+ /* Never use an immediate chmod(). */
+ /* We can't avoid the chmod() entirely if EXTRACT_PERM
+ * because of SysV SGID inheritance. */
+ if ((mode != final_mode)
+ || (a->flags & ARCHIVE_EXTRACT_PERM))
+ a->deferred |= (a->todo & TODO_MODE);
+ a->todo &= ~TODO_MODE;
+ } else {
+ la_dosmaperr(GetLastError());
+ r = -1;
+ }
+ if (fullname != a->name)
+ free(fullname);
+ break;
+ case AE_IFIFO:
+ /* TODO: Find a better way to warn about our inability
+ * to restore a fifo. */
+ return (EINVAL);
+ }
+
+ /* All the system calls above set errno on failure. */
+ if (r)
+ return (errno);
+
+ /* If we managed to set the final mode, we've avoided a chmod(). */
+ if (mode == final_mode)
+ a->todo &= ~TODO_MODE;
+ return (0);
+}
+
+/*
+ * Cleanup function for archive_extract. Mostly, this involves processing
+ * the fixup list, which is used to address a number of problems:
+ * * Dir permissions might prevent us from restoring a file in that
+ * dir, so we restore the dir with minimum 0700 permissions first,
+ * then correct the mode at the end.
+ * * Similarly, the act of restoring a file touches the directory
+ * and changes the timestamp on the dir, so we have to touch-up dir
+ * timestamps at the end as well.
+ * * Some file flags can interfere with the restore by, for example,
+ * preventing the creation of hardlinks to those files.
+ * * Mac OS extended metadata includes ACLs, so must be deferred on dirs.
+ *
+ * Note that tar/cpio do not require that archives be in a particular
+ * order; there is no way to know when the last file has been restored
+ * within a directory, so there's no way to optimize the memory usage
+ * here by fixing up the directory any earlier than the
+ * end-of-archive.
+ *
+ * XXX TODO: Directory ACLs should be restored here, for the same
+ * reason we set directory perms here. XXX
+ */
+static int
+_archive_write_disk_close(struct archive *_a)
+{
+ struct archive_write_disk *a = (struct archive_write_disk *)_a;
+ struct fixup_entry *next, *p;
+ int ret;
+
+ archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_write_disk_close");
+ ret = _archive_write_disk_finish_entry(&a->archive);
+
+ /* Sort dir list so directories are fixed up in depth-first order. */
+ p = sort_dir_list(a->fixup_list);
+
+ while (p != NULL) {
+ a->pst = NULL; /* Mark stat cache as out-of-date. */
+ if (p->fixup & TODO_TIMES) {
+ set_times(a, INVALID_HANDLE_VALUE, p->mode, p->name,
+ p->atime, p->atime_nanos,
+ p->birthtime, p->birthtime_nanos,
+ p->mtime, p->mtime_nanos,
+ p->ctime, p->ctime_nanos);
+ }
+ if (p->fixup & TODO_MODE_BASE)
+ la_chmod(p->name, p->mode);
+ if (p->fixup & TODO_ACLS)
+ set_acls(a, INVALID_HANDLE_VALUE, p->name, &p->acl);
+ next = p->next;
+ archive_acl_clear(&p->acl);
+ free(p->name);
+ free(p);
+ p = next;
+ }
+ a->fixup_list = NULL;
+ return (ret);
+}
+
+static int
+_archive_write_disk_free(struct archive *_a)
+{
+ struct archive_write_disk *a;
+ int ret;
+ if (_a == NULL)
+ return (ARCHIVE_OK);
+ archive_check_magic(_a, ARCHIVE_WRITE_DISK_MAGIC,
+ ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_write_disk_free");
+ a = (struct archive_write_disk *)_a;
+ ret = _archive_write_disk_close(&a->archive);
+ archive_write_disk_set_group_lookup(&a->archive, NULL, NULL, NULL);
+ archive_write_disk_set_user_lookup(&a->archive, NULL, NULL, NULL);
+ if (a->entry)
+ archive_entry_free(a->entry);
+ archive_wstring_free(&a->_name_data);
+ archive_string_free(&a->archive.error_string);
+ archive_wstring_free(&a->path_safe);
+ a->archive.magic = 0;
+ __archive_clean(&a->archive);
+ free(a);
+ return (ret);
+}
+
+/*
+ * Simple O(n log n) merge sort to order the fixup list. In
+ * particular, we want to restore dir timestamps depth-first.
+ */
+static struct fixup_entry *
+sort_dir_list(struct fixup_entry *p)
+{
+ struct fixup_entry *a, *b, *t;
+
+ if (p == NULL)
+ return (NULL);
+ /* A one-item list is already sorted. */
+ if (p->next == NULL)
+ return (p);
+
+ /* Step 1: split the list. */
+ t = p;
+ a = p->next->next;
+ while (a != NULL) {
+ /* Step a twice, t once. */
+ a = a->next;
+ if (a != NULL)
+ a = a->next;
+ t = t->next;
+ }
+ /* Now, t is at the mid-point, so break the list here. */
+ b = t->next;
+ t->next = NULL;
+ a = p;
+
+ /* Step 2: Recursively sort the two sub-lists. */
+ a = sort_dir_list(a);
+ b = sort_dir_list(b);
+
+ /* Step 3: Merge the returned lists. */
+ /* Pick the first element for the merged list. */
+ if (wcscmp(a->name, b->name) > 0) {
+ t = p = a;
+ a = a->next;
+ } else {
+ t = p = b;
+ b = b->next;
+ }
+
+ /* Always put the later element on the list first. */
+ while (a != NULL && b != NULL) {
+ if (wcscmp(a->name, b->name) > 0) {
+ t->next = a;
+ a = a->next;
+ } else {
+ t->next = b;
+ b = b->next;
+ }
+ t = t->next;
+ }
+
+ /* Only one list is non-empty, so just splice it on. */
+ if (a != NULL)
+ t->next = a;
+ if (b != NULL)
+ t->next = b;
+
+ return (p);
+}
+
+/*
+ * Returns a new, initialized fixup entry.
+ *
+ * TODO: Reduce the memory requirements for this list by using a tree
+ * structure rather than a simple list of names.
+ */
+static struct fixup_entry *
+new_fixup(struct archive_write_disk *a, const wchar_t *pathname)
+{
+ struct fixup_entry *fe;
+
+ fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry));
+ if (fe == NULL)
+ return (NULL);
+ fe->next = a->fixup_list;
+ a->fixup_list = fe;
+ fe->fixup = 0;
+ fe->name = _wcsdup(pathname);
+ return (fe);
+}
+
+/*
+ * Returns a fixup structure for the current entry.
+ */
+static struct fixup_entry *
+current_fixup(struct archive_write_disk *a, const wchar_t *pathname)
+{
+ if (a->current_fixup == NULL)
+ a->current_fixup = new_fixup(a, pathname);
+ return (a->current_fixup);
+}
+
+/* TODO: Make this work. */
+/*
+ * TODO: The deep-directory support bypasses this; disable deep directory
+ * support if we're doing symlink checks.
+ */
+/*
+ * TODO: Someday, integrate this with the deep dir support; they both
+ * scan the path and both can be optimized by comparing against other
+ * recent paths.
+ */
+/* TODO: Extend this to support symlinks on Windows Vista and later. */
+static int
+check_symlinks(struct archive_write_disk *a)
+{
+ wchar_t *pn, *p;
+ wchar_t c;
+ int r;
+ BY_HANDLE_FILE_INFORMATION st;
+ mode_t st_mode;
+
+ /*
+ * Guard against symlink tricks. Reject any archive entry whose
+ * destination would be altered by a symlink.
+ */
+ /* Whatever we checked last time doesn't need to be re-checked. */
+ pn = a->name;
+ p = a->path_safe.s;
+ while ((*pn != '\0') && (*p == *pn))
+ ++p, ++pn;
+ c = pn[0];
+ /* Keep going until we've checked the entire name. */
+ while (pn[0] != '\0' && (pn[0] != '\\' || pn[1] != '\0')) {
+ /* Skip the next path element. */
+ while (*pn != '\0' && *pn != '\\')
+ ++pn;
+ c = pn[0];
+ pn[0] = '\0';
+ /* Check that we haven't hit a symlink. */
+ r = file_information(a, a->name, &st, &st_mode, 1);
+ if (r != 0) {
+ /* We've hit a dir that doesn't exist; stop now. */
+ if (errno == ENOENT)
+ break;
+ } else if (S_ISLNK(st_mode)) {
+ if (c == '\0') {
+ /*
+ * Last element is symlink; remove it
+ * so we can overwrite it with the
+ * item being extracted.
+ */
+ if (disk_unlink(a->name)) {
+ archive_set_error(&a->archive, errno,
+ "Could not remove symlink %ls",
+ a->name);
+ pn[0] = c;
+ return (ARCHIVE_FAILED);
+ }
+ a->pst = NULL;
+ /*
+ * Even if we did remove it, a warning
+ * is in order. The warning is silly,
+ * though, if we're just replacing one
+ * symlink with another symlink.
+ */
+ if (!S_ISLNK(a->mode)) {
+ archive_set_error(&a->archive, 0,
+ "Removing symlink %ls",
+ a->name);
+ }
+ /* Symlink gone. No more problem! */
+ pn[0] = c;
+ return (0);
+ } else if (a->flags & ARCHIVE_EXTRACT_UNLINK) {
+ /* User asked us to remove problems. */
+ if (disk_unlink(a->name) != 0) {
+ archive_set_error(&a->archive, 0,
+ "Cannot remove intervening "
+ "symlink %ls", a->name);
+ pn[0] = c;
+ return (ARCHIVE_FAILED);
+ }
+ a->pst = NULL;
+ } else {
+ archive_set_error(&a->archive, 0,
+ "Cannot extract through symlink %ls",
+ a->name);
+ pn[0] = c;
+ return (ARCHIVE_FAILED);
+ }
+ }
+ }
+ pn[0] = c;
+ /* We've checked and/or cleaned the whole path, so remember it. */
+ archive_wstrcpy(&a->path_safe, a->name);
+ return (ARCHIVE_OK);
+}
+
+static int
+guidword(wchar_t *p, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++) {
+ if ((*p >= L'0' && *p <= L'9') ||
+ (*p >= L'a' && *p <= L'f') ||
+ (*p >= L'A' && *p <= L'F'))
+ p++;
+ else
+ return (-1);
+ }
+ return (0);
+}
+
+/*
+ * 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.
+ */
+static int
+cleanup_pathname(struct archive_write_disk *a)
+{
+ wchar_t *dest, *src, *p, *top;
+ wchar_t separator = L'\0';
+
+ p = a->name;
+ if (*p == L'\0') {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid empty pathname");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Replace '/' by '\' */
+ for (; *p != L'\0'; p++) {
+ if (*p == L'/')
+ *p = L'\\';
+ }
+ p = a->name;
+
+ /* Skip leading "\\.\" or "\\?\" or "\\?\UNC\" or
+ * "\\?\Volume{GUID}\"
+ * (absolute path prefixes used by Windows API) */
+ if (p[0] == L'\\' && p[1] == L'\\' &&
+ (p[2] == L'.' || p[2] == L'?') && p[3] == L'\\')
+ {
+ /* A path begin with "\\?\UNC\" */
+ if (p[2] == L'?' &&
+ (p[4] == L'U' || p[4] == L'u') &&
+ (p[5] == L'N' || p[5] == L'n') &&
+ (p[6] == L'C' || p[6] == L'c') &&
+ p[7] == L'\\')
+ p += 8;
+ /* A path begin with "\\?\Volume{GUID}\" */
+ else if (p[2] == L'?' &&
+ (p[4] == L'V' || p[4] == L'v') &&
+ (p[5] == L'O' || p[5] == L'o') &&
+ (p[6] == L'L' || p[6] == L'l') &&
+ (p[7] == L'U' || p[7] == L'u') &&
+ (p[8] == L'M' || p[8] == L'm') &&
+ (p[9] == L'E' || p[9] == L'e') &&
+ p[10] == L'{') {
+ if (guidword(p+11, 8) == 0 && p[19] == L'-' &&
+ guidword(p+20, 4) == 0 && p[24] == L'-' &&
+ guidword(p+25, 4) == 0 && p[29] == L'-' &&
+ guidword(p+30, 4) == 0 && p[34] == L'-' &&
+ guidword(p+35, 12) == 0 && p[47] == L'}' &&
+ p[48] == L'\\')
+ p += 49;
+ else
+ p += 4;
+ /* A path begin with "\\.\PhysicalDriveX" */
+ } else if (p[2] == L'.' &&
+ (p[4] == L'P' || p[4] == L'p') &&
+ (p[5] == L'H' || p[5] == L'h') &&
+ (p[6] == L'Y' || p[6] == L'y') &&
+ (p[7] == L'S' || p[7] == L's') &&
+ (p[8] == L'I' || p[8] == L'i') &&
+ (p[9] == L'C' || p[9] == L'c') &&
+ (p[9] == L'A' || p[9] == L'a') &&
+ (p[9] == L'L' || p[9] == L'l') &&
+ (p[9] == L'D' || p[9] == L'd') &&
+ (p[9] == L'R' || p[9] == L'r') &&
+ (p[9] == L'I' || p[9] == L'i') &&
+ (p[9] == L'V' || p[9] == L'v') &&
+ (p[9] == L'E' || p[9] == L'e') &&
+ (p[10] >= L'0' && p[10] <= L'9') &&
+ p[11] == L'\0') {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Path is a physical drive name");
+ return (ARCHIVE_FAILED);
+ } else
+ p += 4;
+ }
+
+ /* Skip leading drive letter from archives created
+ * on Windows. */
+ if (((p[0] >= L'a' && p[0] <= L'z') ||
+ (p[0] >= L'A' && p[0] <= L'Z')) &&
+ p[1] == L':') {
+ if (p[2] == L'\0') {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Path is a drive name");
+ return (ARCHIVE_FAILED);
+ }
+ if (p[2] == L'\\')
+ p += 2;
+ }
+
+ top = dest = src = p;
+ /* Rewrite the path name if its character is a unusable. */
+ for (; *p != L'\0'; p++) {
+ if (*p == L':' || *p == L'*' || *p == L'?' || *p == L'"' ||
+ *p == L'<' || *p == L'>' || *p == L'|')
+ *p = L'_';
+ }
+ /* Skip leading '\'. */
+ if (*src == L'\\')
+ separator = *src++;
+
+ /* Scan the pathname one element at a time. */
+ for (;;) {
+ /* src points to first char after '\' */
+ if (src[0] == L'\0') {
+ break;
+ } else if (src[0] == L'\\') {
+ /* Found '\\'('//'), ignore second one. */
+ src++;
+ continue;
+ } else if (src[0] == L'.') {
+ if (src[1] == L'\0') {
+ /* Ignore trailing '.' */
+ break;
+ } else if (src[1] == L'\\') {
+ /* Skip '.\'. */
+ src += 2;
+ continue;
+ } else if (src[1] == L'.') {
+ if (src[2] == L'\\' || src[2] == L'\0') {
+ /* Conditionally warn about '..' */
+ if (a->flags &
+ ARCHIVE_EXTRACT_SECURE_NODOTDOT) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Path contains '..'");
+ return (ARCHIVE_FAILED);
+ }
+ }
+ /*
+ * Note: Under no circumstances do we
+ * remove '..' elements. In
+ * particular, restoring
+ * '\foo\..\bar\' should create the
+ * 'foo' dir as a side-effect.
+ */
+ }
+ }
+
+ /* Copy current element, including leading '\'. */
+ if (separator)
+ *dest++ = L'\\';
+ while (*src != L'\0' && *src != L'\\') {
+ *dest++ = *src++;
+ }
+
+ if (*src == L'\0')
+ break;
+
+ /* Skip '\' separator. */
+ separator = *src++;
+ }
+ /*
+ * We've just copied zero or more path elements, not including the
+ * final '\'.
+ */
+ if (dest == top) {
+ /*
+ * Nothing got copied. The path must have been something
+ * like '.' or '\' or './' or '/././././/./'.
+ */
+ if (separator)
+ *dest++ = L'\\';
+ else
+ *dest++ = L'.';
+ }
+ /* Terminate the result. */
+ *dest = L'\0';
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Create the parent directory of the specified path, assuming path
+ * is already in mutable storage.
+ */
+static int
+create_parent_dir(struct archive_write_disk *a, wchar_t *path)
+{
+ wchar_t *slash;
+ int r;
+
+ /* Remove tail element to obtain parent name. */
+ slash = wcsrchr(path, L'\\');
+ if (slash == NULL)
+ return (ARCHIVE_OK);
+ *slash = L'\0';
+ r = create_dir(a, path);
+ *slash = L'\\';
+ return (r);
+}
+
+/*
+ * Create the specified dir, recursing to create parents as necessary.
+ *
+ * Returns ARCHIVE_OK if the path exists when we're done here.
+ * Otherwise, returns ARCHIVE_FAILED.
+ * Assumes path is in mutable storage; path is unchanged on exit.
+ */
+static int
+create_dir(struct archive_write_disk *a, wchar_t *path)
+{
+ BY_HANDLE_FILE_INFORMATION st;
+ struct fixup_entry *le;
+ wchar_t *slash, *base, *full;
+ mode_t mode_final, mode, st_mode;
+ int r;
+
+ /* Check for special names and just skip them. */
+ slash = wcsrchr(path, L'\\');
+ if (slash == NULL)
+ base = path;
+ else
+ base = slash + 1;
+
+ if (base[0] == L'\0' ||
+ (base[0] == L'.' && base[1] == L'\0') ||
+ (base[0] == L'.' && base[1] == L'.' && base[2] == L'\0')) {
+ /* Don't bother trying to create null path, '.', or '..'. */
+ if (slash != NULL) {
+ *slash = L'\0';
+ r = create_dir(a, path);
+ *slash = L'\\';
+ return (r);
+ }
+ return (ARCHIVE_OK);
+ }
+
+ /*
+ * Yes, this should be stat() and not lstat(). Using lstat()
+ * here loses the ability to extract through symlinks. Also note
+ * that this should not use the a->st cache.
+ */
+ if (file_information(a, path, &st, &st_mode, 0) == 0) {
+ if (S_ISDIR(st_mode))
+ return (ARCHIVE_OK);
+ if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) {
+ archive_set_error(&a->archive, EEXIST,
+ "Can't create directory '%ls'", path);
+ return (ARCHIVE_FAILED);
+ }
+ if (disk_unlink(path) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't create directory '%ls': "
+ "Conflicting file cannot be removed",
+ path);
+ return (ARCHIVE_FAILED);
+ }
+ } else if (errno != ENOENT && errno != ENOTDIR) {
+ /* Stat failed? */
+ archive_set_error(&a->archive, errno,
+ "Can't test directory '%ls'", path);
+ return (ARCHIVE_FAILED);
+ } else if (slash != NULL) {
+ *slash = '\0';
+ r = create_dir(a, path);
+ *slash = '\\';
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+
+ /*
+ * Mode we want for the final restored directory. Per POSIX,
+ * implicitly-created dirs must be created obeying the umask.
+ * There's no mention whether this is different for privileged
+ * restores (which the rest of this code handles by pretending
+ * umask=0). I've chosen here to always obey the user's umask for
+ * implicit dirs, even if _EXTRACT_PERM was specified.
+ */
+ mode_final = DEFAULT_DIR_MODE & ~a->user_umask;
+ /* Mode we want on disk during the restore process. */
+ mode = mode_final;
+ mode |= MINIMUM_DIR_MODE;
+ mode &= MAXIMUM_DIR_MODE;
+ /*
+ * Apply __la_win_permissive_name_w to path in order to
+ * remove '../' path string.
+ */
+ full = __la_win_permissive_name_w(path);
+ if (full == NULL)
+ errno = EINVAL;
+ else if (CreateDirectoryW(full, NULL) != 0) {
+ if (mode != mode_final) {
+ le = new_fixup(a, path);
+ le->fixup |=TODO_MODE_BASE;
+ le->mode = mode_final;
+ }
+ free(full);
+ return (ARCHIVE_OK);
+ } else {
+ la_dosmaperr(GetLastError());
+ }
+ free(full);
+
+ /*
+ * Without the following check, a/b/../b/c/d fails at the
+ * second visit to 'b', so 'd' can't be created. Note that we
+ * don't add it to the fixup list here, as it's already been
+ * added.
+ */
+ if (file_information(a, path, &st, &st_mode, 0) == 0 &&
+ S_ISDIR(st_mode))
+ return (ARCHIVE_OK);
+
+ archive_set_error(&a->archive, errno, "Failed to create dir '%ls'",
+ path);
+ return (ARCHIVE_FAILED);
+}
+
+/*
+ * Note: Although we can skip setting the user id if the desired user
+ * id matches the current user, we cannot skip setting the group, as
+ * many systems set the gid based on the containing directory. So
+ * we have to perform a chown syscall if we want to set the SGID
+ * bit. (The alternative is to stat() and then possibly chown(); it's
+ * more efficient to skip the stat() and just always chown().) Note
+ * that a successful chown() here clears the TODO_SGID_CHECK bit, which
+ * allows set_mode to skip the stat() check for the GID.
+ */
+static int
+set_ownership(struct archive_write_disk *a)
+{
+/* unfortunately, on win32 there is no 'root' user with uid 0,
+ so we just have to try the chown and see if it works */
+
+ /* If we know we can't change it, don't bother trying. */
+ if (a->user_uid != 0 && a->user_uid != a->uid) {
+ archive_set_error(&a->archive, errno,
+ "Can't set UID=%jd", (intmax_t)a->uid);
+ return (ARCHIVE_WARN);
+ }
+
+ archive_set_error(&a->archive, errno,
+ "Can't set user=%jd/group=%jd for %ls",
+ (intmax_t)a->uid, (intmax_t)a->gid, a->name);
+ return (ARCHIVE_WARN);
+}
+
+static int
+set_times(struct archive_write_disk *a,
+ HANDLE h, int mode, const wchar_t *name,
+ time_t atime, long atime_nanos,
+ time_t birthtime, long birthtime_nanos,
+ time_t mtime, long mtime_nanos,
+ time_t ctime_sec, long ctime_nanos)
+{
+#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
+#define WINTIME(sec, nsec) ((Int32x32To64(sec, 10000000) + EPOC_TIME)\
+ + (((nsec)/1000)*10))
+
+ HANDLE hw = 0;
+ ULARGE_INTEGER wintm;
+ FILETIME *pfbtime;
+ FILETIME fatime, fbtime, fmtime;
+
+ (void)ctime_sec; /* UNUSED */
+ (void)ctime_nanos; /* UNUSED */
+
+ if (h != INVALID_HANDLE_VALUE) {
+ hw = NULL;
+ } else {
+ wchar_t *ws;
+
+ if (S_ISLNK(mode))
+ return (ARCHIVE_OK);
+ ws = __la_win_permissive_name_w(name);
+ if (ws == NULL)
+ goto settimes_failed;
+ hw = CreateFileW(ws, FILE_WRITE_ATTRIBUTES,
+ 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ free(ws);
+ if (hw == INVALID_HANDLE_VALUE)
+ goto settimes_failed;
+ h = hw;
+ }
+
+ wintm.QuadPart = WINTIME(atime, atime_nanos);
+ fatime.dwLowDateTime = wintm.LowPart;
+ fatime.dwHighDateTime = wintm.HighPart;
+ wintm.QuadPart = WINTIME(mtime, mtime_nanos);
+ fmtime.dwLowDateTime = wintm.LowPart;
+ fmtime.dwHighDateTime = wintm.HighPart;
+ /*
+ * SetFileTime() supports birthtime.
+ */
+ if (birthtime > 0 || birthtime_nanos > 0) {
+ wintm.QuadPart = WINTIME(birthtime, birthtime_nanos);
+ fbtime.dwLowDateTime = wintm.LowPart;
+ fbtime.dwHighDateTime = wintm.HighPart;
+ pfbtime = &fbtime;
+ } else
+ pfbtime = NULL;
+ if (SetFileTime(h, pfbtime, &fatime, &fmtime) == 0)
+ goto settimes_failed;
+ CloseHandle(hw);
+ return (ARCHIVE_OK);
+
+settimes_failed:
+ CloseHandle(hw);
+ archive_set_error(&a->archive, EINVAL, "Can't restore time");
+ return (ARCHIVE_WARN);
+}
+
+static int
+set_times_from_entry(struct archive_write_disk *a)
+{
+ time_t atime, birthtime, mtime, ctime_sec;
+ long atime_nsec, birthtime_nsec, mtime_nsec, ctime_nsec;
+
+ /* Suitable defaults. */
+ atime = birthtime = mtime = ctime_sec = a->start_time;
+ atime_nsec = birthtime_nsec = mtime_nsec = ctime_nsec = 0;
+
+ /* If no time was provided, we're done. */
+ if (!archive_entry_atime_is_set(a->entry)
+ && !archive_entry_birthtime_is_set(a->entry)
+ && !archive_entry_mtime_is_set(a->entry))
+ return (ARCHIVE_OK);
+
+ if (archive_entry_atime_is_set(a->entry)) {
+ atime = archive_entry_atime(a->entry);
+ atime_nsec = archive_entry_atime_nsec(a->entry);
+ }
+ if (archive_entry_birthtime_is_set(a->entry)) {
+ birthtime = archive_entry_birthtime(a->entry);
+ birthtime_nsec = archive_entry_birthtime_nsec(a->entry);
+ }
+ if (archive_entry_mtime_is_set(a->entry)) {
+ mtime = archive_entry_mtime(a->entry);
+ mtime_nsec = archive_entry_mtime_nsec(a->entry);
+ }
+ if (archive_entry_ctime_is_set(a->entry)) {
+ ctime_sec = archive_entry_ctime(a->entry);
+ ctime_nsec = archive_entry_ctime_nsec(a->entry);
+ }
+
+ return set_times(a, a->fh, a->mode, a->name,
+ atime, atime_nsec,
+ birthtime, birthtime_nsec,
+ mtime, mtime_nsec,
+ ctime_sec, ctime_nsec);
+}
+
+static int
+set_mode(struct archive_write_disk *a, int mode)
+{
+ int r = ARCHIVE_OK;
+ mode &= 07777; /* Strip off file type bits. */
+
+ if (a->todo & TODO_SGID_CHECK) {
+ /*
+ * If we don't know the GID is right, we must stat()
+ * to verify it. We can't just check the GID of this
+ * process, since systems sometimes set GID from
+ * the enclosing dir or based on ACLs.
+ */
+ if ((r = lazy_stat(a)) != ARCHIVE_OK)
+ return (r);
+ if (0 != a->gid) {
+ mode &= ~ S_ISGID;
+ }
+ /* While we're here, double-check the UID. */
+ if (0 != a->uid
+ && (a->todo & TODO_SUID)) {
+ mode &= ~ S_ISUID;
+ }
+ a->todo &= ~TODO_SGID_CHECK;
+ a->todo &= ~TODO_SUID_CHECK;
+ } else if (a->todo & TODO_SUID_CHECK) {
+ /*
+ * If we don't know the UID is right, we can just check
+ * the user, since all systems set the file UID from
+ * the process UID.
+ */
+ if (a->user_uid != a->uid) {
+ mode &= ~ S_ISUID;
+ }
+ a->todo &= ~TODO_SUID_CHECK;
+ }
+
+ if (S_ISLNK(a->mode)) {
+#ifdef HAVE_LCHMOD
+ /*
+ * If this is a symlink, use lchmod(). If the
+ * platform doesn't support lchmod(), just skip it. A
+ * platform that doesn't provide a way to set
+ * permissions on symlinks probably ignores
+ * permissions on symlinks, so a failure here has no
+ * 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;
+ }
+#endif
+ } else if (!S_ISDIR(a->mode)) {
+ /*
+ * If it's not a symlink and not a dir, then use
+ * fchmod() or chmod(), depending on whether we have
+ * an fd. Dirs get their perms set during the
+ * post-extract fixup, which is handled elsewhere.
+ */
+#ifdef HAVE_FCHMOD
+ if (a->fd >= 0) {
+ if (fchmod(a->fd, mode) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't set permissions to 0%o", (int)mode);
+ r = ARCHIVE_WARN;
+ }
+ } else
+#endif
+ /* If this platform lacks fchmod(), then
+ * we'll just use chmod(). */
+ if (la_chmod(a->name, mode) != 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't set permissions to 0%o", (int)mode);
+ r = ARCHIVE_WARN;
+ }
+ }
+ return (r);
+}
+
+static int
+set_fflags(struct archive_write_disk *a)
+{
+ (void)a; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+/* Default empty function body to satisfy mainline code. */
+static int
+set_acls(struct archive_write_disk *a, HANDLE h, const wchar_t *name,
+ struct archive_acl *acl)
+{
+ (void)a; /* UNUSED */
+ (void)h; /* UNUSED */
+ (void)name; /* UNUSED */
+ (void)acl; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Restore extended attributes - stub implementation for unsupported systems
+ */
+static int
+set_xattrs(struct archive_write_disk *a)
+{
+ static int warning_done = 0;
+
+ /* If there aren't any extended attributes, then it's okay not
+ * to extract them, otherwise, issue a single warning. */
+ if (archive_entry_xattr_count(a->entry) != 0 && !warning_done) {
+ warning_done = 1;
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Cannot restore extended attributes on this system");
+ return (ARCHIVE_WARN);
+ }
+ /* Warning was already emitted; suppress further warnings. */
+ return (ARCHIVE_OK);
+}
+
+static void
+fileTimeToUtc(const FILETIME *filetime, time_t *t, long *ns)
+{
+ ULARGE_INTEGER utc;
+
+ utc.HighPart = filetime->dwHighDateTime;
+ utc.LowPart = filetime->dwLowDateTime;
+ if (utc.QuadPart >= EPOC_TIME) {
+ utc.QuadPart -= EPOC_TIME;
+ /* milli seconds base */
+ *t = (time_t)(utc.QuadPart / 10000000);
+ /* nano seconds base */
+ *ns = (long)(utc.QuadPart % 10000000) * 100;
+ } else {
+ *t = 0;
+ *ns = 0;
+ }
+}
+/*
+ * Test if file on disk is older than entry.
+ */
+static int
+older(BY_HANDLE_FILE_INFORMATION *st, struct archive_entry *entry)
+{
+ time_t sec;
+ long nsec;
+
+ fileTimeToUtc(&st->ftLastWriteTime, &sec, &nsec);
+ /* First, test the seconds and return if we have a definite answer. */
+ /* Definitely older. */
+ if (sec < archive_entry_mtime(entry))
+ return (1);
+ /* Definitely younger. */
+ if (sec > archive_entry_mtime(entry))
+ return (0);
+ if (nsec < archive_entry_mtime_nsec(entry))
+ return (1);
+ /* Same age or newer, so not older. */
+ return (0);
+}
+
+#endif /* _WIN32 && !__CYGWIN__ */
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_filter.3 b/Utilities/cmlibarchive/libarchive/archive_write_filter.3
new file mode 100644
index 0000000000..3ca248b72a
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_filter.3
@@ -0,0 +1,100 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_FILTER 3
+.Os
+.Sh NAME
+.Nm archive_write_add_filter_bzip2 ,
+.Nm archive_write_add_filter_compress ,
+.Nm archive_write_add_filter_gzip ,
+.Nm archive_write_add_filter_lzip ,
+.Nm archive_write_add_filter_lzma ,
+.Nm archive_write_add_filter_none ,
+.Nm archive_write_add_filter_program ,
+.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_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_lzip "struct archive *"
+.Ft int
+.Fn archive_write_add_filter_lzma "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_xz "struct archive *"
+.Sh DESCRIPTION
+.Bl -tag -width indent
+.It Xo
+.Fn archive_write_add_filter_bzip2 ,
+.Fn archive_write_add_filter_compress ,
+.Fn archive_write_add_filter_gzip ,
+.Fn archive_write_add_filter_lzip ,
+.Fn archive_write_add_filter_lzma ,
+.Fn archive_write_add_filter_xz ,
+.Xc
+The resulting archive will be compressed as specified.
+Note that the compressed output is always properly blocked.
+.It Fn archive_write_add_filter_none
+This is never necessary.
+It is provided only for backwards compatibility.
+.It Fn archive_write_add_filter_program
+The archive will be fed into the specified compression program.
+The output of that program is blocked and written to the client
+write callbacks.
+.El
+.Sh RETURN VALUES
+These functions return
+.Cm ARCHIVE_OK
+on success, or
+.Cm ARCHIVE_FATAL .
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write 3 ,
+.Xr archive_write_format 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3
new file mode 100644
index 0000000000..d881c80ea4
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3
@@ -0,0 +1,76 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_FINISH_ENTRY 3
+.Os
+.Sh NAME
+.Nm archive_write_finish_entry
+.Nd functions for creating archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fn archive_write_finish_entry "struct archive *"
+.Sh DESCRIPTION
+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
+and
+.Fn archive_write_close
+as needed.
+.\" .Sh EXAMPLE
+.Sh RETURN VALUES
+This function returns
+.Cm ARCHIVE_OK
+on success, or one of several non-zero
+error codes for errors.
+Specific error codes include:
+.Cm ARCHIVE_RETRY
+for operations that might succeed if retried,
+.Cm ARCHIVE_WARN
+for unusual conditions that do not prevent further operations, and
+.Cm ARCHIVE_FATAL
+for serious errors that make remaining operations impossible.
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write_data 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_format.3 b/Utilities/cmlibarchive/libarchive/archive_write_format.3
new file mode 100644
index 0000000000..39d300646e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_format.3
@@ -0,0 +1,103 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 14, 2013
+.Dt ARCHIVE_WRITE_FORMAT 3
+.Os
+.Sh NAME
+.Nm archive_write_set_format_cpio ,
+.Nm archive_write_set_format_pax ,
+.Nm archive_write_set_format_pax_restricted ,
+.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
+.Nd functions for creating archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fn archive_write_set_format_cpio "struct archive *"
+.Ft int
+.Fn archive_write_set_format_pax "struct archive *"
+.Ft int
+.Fn archive_write_set_format_pax_restricted "struct archive *"
+.Ft int
+.Fn archive_write_set_format_raw "struct archive *"
+.Ft int
+.Fn archive_write_set_format_shar "struct archive *"
+.Ft int
+.Fn archive_write_set_format_shar_dump "struct archive *"
+.Ft int
+.Fn archive_write_set_format_ustar "struct archive *"
+.Sh DESCRIPTION
+These functions set the format that will be used for the archive.
+.Pp
+The library can write
+POSIX octet-oriented cpio format archives,
+POSIX-standard
+.Dq pax interchange
+format archives,
+traditional
+.Dq shar
+archives,
+enhanced
+.Dq dump
+shar archives that store a variety of file attributes and handle binary files,
+and
+POSIX-standard
+.Dq ustar
+archives.
+The pax interchange format is a backwards-compatible tar format that
+adds key/value attributes to each entry and supports arbitrary
+filenames, linknames, uids, sizes, etc.
+.Dq Restricted pax interchange format
+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.
+.\"
+.Sh RETURN VALUES
+These functions return
+.Cm ARCHIVE_OK
+on success, or
+.Cm ARCHIVE_FATAL .
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_free.3 b/Utilities/cmlibarchive/libarchive/archive_write_free.3
new file mode 100644
index 0000000000..1b2d07131d
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_free.3
@@ -0,0 +1,96 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_FREE 3
+.Os
+.Sh NAME
+.Nm archive_write_fail ,
+.Nm archive_write_close ,
+.Nm archive_write_finish ,
+.Nm archive_write_free
+.Nd functions for creating archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fn archive_write_fail "struct archive *"
+.Ft int
+.Fn archive_write_close "struct archive *"
+.Ft int
+.Fn archive_write_finish "struct archive *"
+.Ft int
+.Fn archive_write_free "struct archive *"
+.Sh DESCRIPTION
+.Bl -tag -width indent
+.It Fn archive_write_fail
+Always returns
+.Cm ARCHIVE_FATAL .
+This marks the archive object as being unusable;
+after calling this function, the only call that can succeed is
+.Fn archive_write_free
+to release the resources.
+This can be used to speed recovery when the archive creation
+must be aborted.
+Note that the created archive is likely to be malformed in this case;
+.It Fn archive_write_close
+Complete the archive and invoke the close callback.
+.It Fn archive_write_finish
+This is a deprecated synonym for
+.Fn archive_write_free .
+.It Fn archive_write_free
+Invokes
+.Fn archive_write_close
+if necessary, then releases all resources.
+If you need detailed information about
+.Fn archive_write_close
+failures, you should be careful to call it separately, as
+you cannot obtain error information after
+.Fn archive_write_free
+returns.
+.El
+.\" .Sh EXAMPLE
+.Sh RETURN VALUES
+These functions return
+.Cm ARCHIVE_OK
+on success, or
+.Cm ARCHIVE_FATAL .
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_header.3 b/Utilities/cmlibarchive/libarchive/archive_write_header.3
new file mode 100644
index 0000000000..4de58f3b9f
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_header.3
@@ -0,0 +1,73 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_HEADER 3
+.Os
+.Sh NAME
+.Nm archive_write_header
+.Nd functions for creating archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fn archive_write_header "struct archive *" "struct archive_entry *"
+.Sh DESCRIPTION
+Build and write a header using the data in the provided
+.Tn struct archive_entry
+structure.
+See
+.Xr archive_entry 3
+for information on creating and populating
+.Tn struct archive_entry
+objects.
+.\" .Sh EXAMPLE
+.Sh RETURN VALUES
+This function returns
+.Cm ARCHIVE_OK
+on success, or one of the following on error:
+.Cm ARCHIVE_RETRY
+for operations that might succeed if retried,
+.Cm ARCHIVE_WARN
+for unusual conditions that do not prevent further operations, and
+.Cm ARCHIVE_FATAL
+for serious errors that make remaining operations impossible.
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_new.3 b/Utilities/cmlibarchive/libarchive/archive_write_new.3
new file mode 100644
index 0000000000..f05d269d3e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_new.3
@@ -0,0 +1,58 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_NEW 3
+.Os
+.Sh NAME
+.Nm archive_write_new
+.Nd functions for creating archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft struct archive *
+.Fn archive_write_new "void"
+.Sh DESCRIPTION
+Allocates and initializes a
+.Tn struct archive
+object suitable for writing a tar archive.
+.Dv NULL
+is returned on error.
+.Pp
+A complete description of the
+.Tn struct archive
+object can be found in the overview manual page for
+.Xr libarchive 3 .
+.\" .Sh ERRORS
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open.3 b/Utilities/cmlibarchive/libarchive/archive_write_open.3
new file mode 100644
index 0000000000..4037248e0e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_open.3
@@ -0,0 +1,235 @@
+.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_OPEN 3
+.Os
+.Sh NAME
+.Nm archive_write_open ,
+.Nm archive_write_open_fd ,
+.Nm archive_write_open_FILE ,
+.Nm archive_write_open_filename ,
+.Nm archive_write_open_memory
+.Nd functions for creating archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.In archive.h
+.Ft int
+.Fo archive_write_open
+.Fa "struct archive *"
+.Fa "void *client_data"
+.Fa "archive_open_callback *"
+.Fa "archive_write_callback *"
+.Fa "archive_close_callback *"
+.Fc
+.Ft int
+.Fn archive_write_open_fd "struct archive *" "int fd"
+.Ft int
+.Fn archive_write_open_FILE "struct archive *" "FILE *file"
+.Ft int
+.Fn archive_write_open_filename "struct archive *" "const char *filename"
+.Ft int
+.Fo archive_write_open_memory
+.Fa "struct archive *"
+.Fa "void *buffer"
+.Fa "size_t bufferSize"
+.Fa "size_t *outUsed"
+.Fc
+.Sh DESCRIPTION
+.Bl -tag -width indent
+.It Fn archive_write_open
+Freeze the settings, open the archive, and prepare for writing entries.
+This is the most generic form of this function, which accepts
+pointers to three callback functions which will be invoked by
+the compression layer to write the constructed archive.
+.It Fn archive_write_open_fd
+A convenience form of
+.Fn archive_write_open
+that accepts a file descriptor.
+The
+.Fn archive_write_open_fd
+function is safe for use with tape drives or other
+block-oriented devices.
+.It Fn archive_write_open_FILE
+A convenience form of
+.Fn archive_write_open
+that accepts a
+.Ft "FILE *"
+pointer.
+Note that
+.Fn archive_write_open_FILE
+is not safe for writing to tape drives or other devices
+that require correct blocking.
+.It Fn archive_write_open_file
+A deprecated synonym for
+.Fn archive_write_open_filename .
+.It Fn archive_write_open_filename
+A convenience form of
+.Fn archive_write_open
+that accepts a filename.
+A NULL argument indicates that the output should be written to standard output;
+an argument of
+.Dq -
+will open a file with that name.
+If you have not invoked
+.Fn archive_write_set_bytes_in_last_block ,
+then
+.Fn archive_write_open_filename
+will adjust the last-block padding depending on the file:
+it will enable padding when writing to standard output or
+to a character or block device node, it will disable padding otherwise.
+You can override this by manually invoking
+.Fn archive_write_set_bytes_in_last_block
+before calling
+.Fn archive_write_open .
+The
+.Fn archive_write_open_filename
+function is safe for use with tape drives or other
+block-oriented devices.
+.It Fn archive_write_open_memory
+A convenience form of
+.Fn archive_write_open
+that accepts a pointer to a block of memory that will receive
+the archive.
+The final
+.Ft "size_t *"
+argument points to a variable that will be updated
+after each write to reflect how much of the buffer
+is currently in use.
+You should be careful to ensure that this variable
+remains allocated until after the archive is
+closed.
+.El
+More information about the
+.Va struct archive
+object and the overall design of the library can be found in the
+.Xr libarchive 3
+overview.
+.\"
+.Sh CLIENT CALLBACKS
+To use this library, you will need to define and register
+callback functions that will be invoked to write data to the
+resulting archive.
+These functions are registered by calling
+.Fn archive_write_open :
+.Bl -item -offset indent
+.It
+.Ft typedef int
+.Fn archive_open_callback "struct archive *" "void *client_data"
+.El
+.Pp
+The open callback is invoked by
+.Fn archive_write_open .
+It should return
+.Cm ARCHIVE_OK
+if the underlying file or data source is successfully
+opened.
+If the open fails, it should call
+.Fn archive_set_error
+to register an error code and message and return
+.Cm ARCHIVE_FATAL .
+.Bl -item -offset indent
+.It
+.Ft typedef ssize_t
+.Fo archive_write_callback
+.Fa "struct archive *"
+.Fa "void *client_data"
+.Fa "const void *buffer"
+.Fa "size_t length"
+.Fc
+.El
+.Pp
+The write callback is invoked whenever the library
+needs to write raw bytes to the archive.
+For correct blocking, each call to the write callback function
+should translate into a single
+.Xr write 2
+system call.
+This is especially critical when writing archives to tape drives.
+On success, the write callback should return the
+number of bytes actually written.
+On error, the callback should invoke
+.Fn archive_set_error
+to register an error code and message and return -1.
+.Bl -item -offset indent
+.It
+.Ft typedef int
+.Fn archive_close_callback "struct archive *" "void *client_data"
+.El
+.Pp
+The close callback is invoked by archive_close when
+the archive processing is complete.
+The callback should return
+.Cm ARCHIVE_OK
+on success.
+On failure, the callback should invoke
+.Fn archive_set_error
+to register an error code and message and
+return
+.Cm ARCHIVE_FATAL.
+.Pp
+Note that if the client-provided write callback function
+returns a non-zero value, that error will be propagated back to the caller
+through whatever API function resulted in that call, which
+may include
+.Fn archive_write_header ,
+.Fn archive_write_data ,
+.Fn archive_write_close ,
+.Fn archive_write_finish ,
+or
+.Fn archive_write_free .
+The client callback can call
+.Fn archive_set_error
+to provide values that can then be retrieved by
+.Fn archive_errno
+and
+.Fn archive_error_string .
+.\" .Sh EXAMPLE
+.Sh RETURN VALUES
+These functions return
+.Cm ARCHIVE_OK
+on success, or
+.Cm ARCHIVE_FATAL .
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_write 3 ,
+.Xr archive_write_filter 3 ,
+.Xr archive_write_format 3 ,
+.Xr archive_write_new 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c b/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c
new file mode 100644
index 0000000000..d5c426cf97
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c
@@ -0,0 +1,144 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_open_fd.c 201093 2009-12-28 02:28:44Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+
+struct write_fd_data {
+ int fd;
+};
+
+static int file_close(struct archive *, void *);
+static int file_open(struct archive *, void *);
+static ssize_t file_write(struct archive *, void *, const void *buff, size_t);
+
+int
+archive_write_open_fd(struct archive *a, int fd)
+{
+ struct write_fd_data *mine;
+
+ mine = (struct write_fd_data *)malloc(sizeof(*mine));
+ if (mine == NULL) {
+ archive_set_error(a, ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ mine->fd = fd;
+#if defined(__CYGWIN__) || defined(_WIN32)
+ setmode(mine->fd, O_BINARY);
+#endif
+ return (archive_write_open(a, mine,
+ file_open, file_write, file_close));
+}
+
+static int
+file_open(struct archive *a, void *client_data)
+{
+ struct write_fd_data *mine;
+ struct stat st;
+
+ mine = (struct write_fd_data *)client_data;
+
+ if (fstat(mine->fd, &st) != 0) {
+ archive_set_error(a, errno, "Couldn't stat fd %d", mine->fd);
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * If this is a regular file, don't add it to itself.
+ */
+ if (S_ISREG(st.st_mode))
+ archive_write_set_skip_file(a, st.st_dev, st.st_ino);
+
+ /*
+ * If client hasn't explicitly set the last block handling,
+ * then set it here.
+ */
+ if (archive_write_get_bytes_in_last_block(a) < 0) {
+ /* If the output is a block or character device, fifo,
+ * or stdout, pad the last block, otherwise leave it
+ * unpadded. */
+ if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) ||
+ S_ISFIFO(st.st_mode) || (mine->fd == 1))
+ /* Last block will be fully padded. */
+ archive_write_set_bytes_in_last_block(a, 0);
+ else
+ archive_write_set_bytes_in_last_block(a, 1);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+file_write(struct archive *a, void *client_data, const void *buff, size_t length)
+{
+ struct write_fd_data *mine;
+ ssize_t bytesWritten;
+
+ mine = (struct write_fd_data *)client_data;
+ for (;;) {
+ bytesWritten = write(mine->fd, buff, length);
+ if (bytesWritten <= 0) {
+ if (errno == EINTR)
+ continue;
+ archive_set_error(a, errno, "Write error");
+ return (-1);
+ }
+ return (bytesWritten);
+ }
+}
+
+static int
+file_close(struct archive *a, void *client_data)
+{
+ struct write_fd_data *mine = (struct write_fd_data *)client_data;
+
+ (void)a; /* UNUSED */
+ free(mine);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_file.c b/Utilities/cmlibarchive/libarchive/archive_write_open_file.c
new file mode 100644
index 0000000000..f6b141239f
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_open_file.c
@@ -0,0 +1,109 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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: src/lib/libarchive/archive_write_open_file.c,v 1.19 2007/01/09 08:05:56 kientzle Exp $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+
+struct write_FILE_data {
+ FILE *f;
+};
+
+static int file_close(struct archive *, void *);
+static int file_open(struct archive *, void *);
+static ssize_t file_write(struct archive *, void *, const void *buff, size_t);
+
+int
+archive_write_open_FILE(struct archive *a, FILE *f)
+{
+ struct write_FILE_data *mine;
+
+ mine = (struct write_FILE_data *)malloc(sizeof(*mine));
+ if (mine == NULL) {
+ archive_set_error(a, ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ mine->f = f;
+ return (archive_write_open(a, mine,
+ file_open, file_write, file_close));
+}
+
+static int
+file_open(struct archive *a, void *client_data)
+{
+ (void)a; /* UNUSED */
+ (void)client_data; /* UNUSED */
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+file_write(struct archive *a, void *client_data, const void *buff, size_t length)
+{
+ struct write_FILE_data *mine;
+ size_t bytesWritten;
+
+ mine = client_data;
+ for (;;) {
+ bytesWritten = fwrite(buff, 1, length, mine->f);
+ if (bytesWritten <= 0) {
+ if (errno == EINTR)
+ continue;
+ archive_set_error(a, errno, "Write error");
+ return (-1);
+ }
+ return (bytesWritten);
+ }
+}
+
+static int
+file_close(struct archive *a, void *client_data)
+{
+ struct write_FILE_data *mine = client_data;
+
+ (void)a; /* UNUSED */
+ free(mine);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c b/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c
new file mode 100644
index 0000000000..196b770e8e
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c
@@ -0,0 +1,250 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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_open_filename.c 191165 2009-04-17 00:39:35Z kientzle $");
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_string.h"
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
+struct write_file_data {
+ int fd;
+ struct archive_mstring filename;
+};
+
+static int file_close(struct archive *, void *);
+static int file_open(struct archive *, void *);
+static ssize_t file_write(struct archive *, void *, const void *buff, size_t);
+static int open_filename(struct archive *, int, const void *);
+
+int
+archive_write_open_file(struct archive *a, const char *filename)
+{
+ return (archive_write_open_filename(a, filename));
+}
+
+int
+archive_write_open_filename(struct archive *a, const char *filename)
+{
+
+ if (filename == NULL || filename[0] == '\0')
+ return (archive_write_open_fd(a, 1));
+
+ return (open_filename(a, 1, filename));
+}
+
+int
+archive_write_open_filename_w(struct archive *a, const wchar_t *filename)
+{
+
+ if (filename == NULL || filename[0] == L'\0')
+ return (archive_write_open_fd(a, 1));
+
+ return (open_filename(a, 0, filename));
+}
+
+static int
+open_filename(struct archive *a, int mbs_fn, const void *filename)
+{
+ struct write_file_data *mine;
+ int r;
+
+ mine = (struct write_file_data *)calloc(1, sizeof(*mine));
+ if (mine == NULL) {
+ archive_set_error(a, ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ if (mbs_fn)
+ r = archive_mstring_copy_mbs(&mine->filename, filename);
+ else
+ r = archive_mstring_copy_wcs(&mine->filename, filename);
+ if (r < 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(a, ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ if (mbs_fn)
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Can't convert '%s' to WCS",
+ (const char *)filename);
+ else
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Can't convert '%S' to MBS",
+ (const wchar_t *)filename);
+ return (ARCHIVE_FAILED);
+ }
+ mine->fd = -1;
+ return (archive_write_open(a, mine,
+ file_open, file_write, file_close));
+}
+
+static int
+file_open(struct archive *a, void *client_data)
+{
+ int flags;
+ struct write_file_data *mine;
+ struct stat st;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ wchar_t *fullpath;
+#endif
+ const wchar_t *wcs;
+ const char *mbs;
+
+ mine = (struct write_file_data *)client_data;
+ flags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_CLOEXEC;
+
+ /*
+ * Open the file.
+ */
+ mbs = NULL; wcs = NULL;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (archive_mstring_get_wcs(a, &mine->filename, &wcs) != 0) {
+ if (errno == ENOMEM)
+ archive_set_error(a, errno, "No memory");
+ else {
+ archive_mstring_get_mbs(a, &mine->filename, &mbs);
+ archive_set_error(a, errno,
+ "Can't convert '%s' to WCS", mbs);
+ }
+ return (ARCHIVE_FATAL);
+ }
+ fullpath = __la_win_permissive_name_w(wcs);
+ if (fullpath != NULL) {
+ mine->fd = _wopen(fullpath, flags, 0666);
+ free(fullpath);
+ } else
+ mine->fd = _wopen(wcs, flags, 0666);
+#else
+ if (archive_mstring_get_mbs(a, &mine->filename, &mbs) != 0) {
+ if (errno == ENOMEM)
+ archive_set_error(a, errno, "No memory");
+ else {
+ archive_mstring_get_wcs(a, &mine->filename, &wcs);
+ archive_set_error(a, errno,
+ "Can't convert '%S' to MBS", wcs);
+ }
+ return (ARCHIVE_FATAL);
+ }
+ mine->fd = open(mbs, flags, 0666);
+ __archive_ensure_cloexec_flag(mine->fd);
+#endif
+ if (mine->fd < 0) {
+ if (mbs != NULL)
+ archive_set_error(a, errno, "Failed to open '%s'", mbs);
+ else
+ archive_set_error(a, errno, "Failed to open '%S'", wcs);
+ return (ARCHIVE_FATAL);
+ }
+
+ if (fstat(mine->fd, &st) != 0) {
+ if (mbs != NULL)
+ archive_set_error(a, errno, "Couldn't stat '%s'", mbs);
+ else
+ archive_set_error(a, errno, "Couldn't stat '%S'", wcs);
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Set up default last block handling.
+ */
+ if (archive_write_get_bytes_in_last_block(a) < 0) {
+ if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) ||
+ S_ISFIFO(st.st_mode))
+ /* Pad last block when writing to device or FIFO. */
+ archive_write_set_bytes_in_last_block(a, 0);
+ else
+ /* Don't pad last block otherwise. */
+ archive_write_set_bytes_in_last_block(a, 1);
+ }
+
+ /*
+ * If the output file is a regular file, don't add it to
+ * itself. If it's a device file, it's okay to add the device
+ * entry to the output archive.
+ */
+ if (S_ISREG(st.st_mode))
+ archive_write_set_skip_file(a, st.st_dev, st.st_ino);
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+file_write(struct archive *a, void *client_data, const void *buff,
+ size_t length)
+{
+ struct write_file_data *mine;
+ ssize_t bytesWritten;
+
+ mine = (struct write_file_data *)client_data;
+ for (;;) {
+ bytesWritten = write(mine->fd, buff, length);
+ if (bytesWritten <= 0) {
+ if (errno == EINTR)
+ continue;
+ archive_set_error(a, errno, "Write error");
+ return (-1);
+ }
+ return (bytesWritten);
+ }
+}
+
+static int
+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);
+ archive_mstring_clean(&mine->filename);
+ free(mine);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_memory.c b/Utilities/cmlibarchive/libarchive/archive_write_open_memory.c
new file mode 100644
index 0000000000..4f8d679e58
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_open_memory.c
@@ -0,0 +1,114 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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: src/lib/libarchive/archive_write_open_memory.c,v 1.3 2007/01/09 08:05:56 kientzle Exp $");
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "archive.h"
+
+struct write_memory_data {
+ size_t used;
+ size_t size;
+ size_t * client_size;
+ unsigned char * buff;
+};
+
+static int memory_write_close(struct archive *, void *);
+static int memory_write_open(struct archive *, void *);
+static ssize_t memory_write(struct archive *, void *, const void *buff, size_t);
+
+/*
+ * Client provides a pointer to a block of memory to receive
+ * the data. The 'size' param both tells us the size of the
+ * client buffer and lets us tell the client the final size.
+ */
+int
+archive_write_open_memory(struct archive *a, void *buff, size_t buffSize, size_t *used)
+{
+ struct write_memory_data *mine;
+
+ mine = (struct write_memory_data *)malloc(sizeof(*mine));
+ if (mine == NULL) {
+ archive_set_error(a, ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ memset(mine, 0, sizeof(*mine));
+ mine->buff = buff;
+ mine->size = buffSize;
+ mine->client_size = used;
+ return (archive_write_open(a, mine,
+ memory_write_open, memory_write, memory_write_close));
+}
+
+static int
+memory_write_open(struct archive *a, void *client_data)
+{
+ struct write_memory_data *mine;
+ mine = client_data;
+ mine->used = 0;
+ if (mine->client_size != NULL)
+ *mine->client_size = mine->used;
+ /* Disable padding if it hasn't been set explicitly. */
+ if (-1 == archive_write_get_bytes_in_last_block(a))
+ archive_write_set_bytes_in_last_block(a, 1);
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Copy the data into the client buffer.
+ * Note that we update mine->client_size on every write.
+ * In particular, this means the client can follow exactly
+ * how much has been written into their buffer at any time.
+ */
+static ssize_t
+memory_write(struct archive *a, void *client_data, const void *buff, size_t length)
+{
+ struct write_memory_data *mine;
+ mine = client_data;
+
+ if (mine->used + length > mine->size) {
+ archive_set_error(a, ENOMEM, "Buffer exhausted");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(mine->buff + mine->used, buff, length);
+ mine->used += length;
+ if (mine->client_size != NULL)
+ *mine->client_size = mine->used;
+ return (length);
+}
+
+static int
+memory_write_close(struct archive *a, void *client_data)
+{
+ struct write_memory_data *mine;
+ (void)a; /* UNUSED */
+ mine = client_data;
+ free(mine);
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_private.h b/Utilities/cmlibarchive/libarchive/archive_write_private.h
new file mode 100644
index 0000000000..e600d54749
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_private.h
@@ -0,0 +1,145 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/archive_write_private.h 201155 2009-12-29 05:20:12Z kientzle $
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED
+#define ARCHIVE_WRITE_PRIVATE_H_INCLUDED
+
+#include "archive.h"
+#include "archive_string.h"
+#include "archive_private.h"
+
+struct archive_write;
+
+struct archive_write_filter {
+ int64_t bytes_written;
+ struct archive *archive; /* Associated archive. */
+ struct archive_write_filter *next_filter; /* Who I write to. */
+ int (*options)(struct archive_write_filter *,
+ const char *key, const char *value);
+ int (*open)(struct archive_write_filter *);
+ int (*write)(struct archive_write_filter *, const void *, size_t);
+ int (*close)(struct archive_write_filter *);
+ int (*free)(struct archive_write_filter *);
+ void *data;
+ const char *name;
+ int code;
+ int bytes_per_block;
+ int bytes_in_last_block;
+};
+
+#if ARCHIVE_VERSION < 4000000
+void __archive_write_filters_free(struct archive *);
+#endif
+
+struct archive_write_filter *__archive_write_allocate_filter(struct archive *);
+
+int __archive_write_output(struct archive_write *, const void *, size_t);
+int __archive_write_nulls(struct archive_write *, size_t);
+int __archive_write_filter(struct archive_write_filter *, const void *, size_t);
+int __archive_write_open_filter(struct archive_write_filter *);
+int __archive_write_close_filter(struct archive_write_filter *);
+
+struct archive_write {
+ struct archive archive;
+
+ /* Dev/ino of the archive being written. */
+ int skip_file_set;
+ int64_t skip_file_dev;
+ int64_t skip_file_ino;
+
+ /* Utility: Pointer to a block of nulls. */
+ const unsigned char *nulls;
+ size_t null_length;
+
+ /* Callbacks to open/read/write/close archive stream. */
+ archive_open_callback *client_opener;
+ archive_write_callback *client_writer;
+ archive_close_callback *client_closer;
+ void *client_data;
+
+ /*
+ * Blocking information. Note that bytes_in_last_block is
+ * misleadingly named; I should find a better name. These
+ * control the final output from all compressors, including
+ * compression_none.
+ */
+ int bytes_per_block;
+ int bytes_in_last_block;
+
+ /*
+ * First and last write filters in the pipeline.
+ */
+ struct archive_write_filter *filter_first;
+ struct archive_write_filter *filter_last;
+
+ /*
+ * Pointers to format-specific functions for writing. They're
+ * initialized by archive_write_set_format_XXX() calls.
+ */
+ void *format_data;
+ const char *format_name;
+ int (*format_init)(struct archive_write *);
+ int (*format_options)(struct archive_write *,
+ const char *key, const char *value);
+ int (*format_finish_entry)(struct archive_write *);
+ int (*format_write_header)(struct archive_write *,
+ struct archive_entry *);
+ ssize_t (*format_write_data)(struct archive_write *,
+ const void *buff, size_t);
+ int (*format_close)(struct archive_write *);
+ int (*format_free)(struct archive_write *);
+};
+
+/*
+ * Utility function to format a USTAR header into a buffer. If
+ * "strict" is set, this tries to create the absolutely most portable
+ * version of a ustar header. If "strict" is set to 0, then it will
+ * relax certain requirements.
+ *
+ * Generally, format-specific declarations don't belong in this
+ * header; this is a rare example of a function that is shared by
+ * two very similar formats (ustar and pax).
+ */
+int
+__archive_write_format_header_ustar(struct archive_write *, char buff[512],
+ struct archive_entry *, int tartype, int strict,
+ struct archive_string_conv *);
+
+struct archive_write_program_data;
+struct archive_write_program_data * __archive_write_program_allocate(void);
+int __archive_write_program_free(struct archive_write_program_data *);
+int __archive_write_program_open(struct archive_write_filter *,
+ struct archive_write_program_data *, const char *);
+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);
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c
new file mode 100644
index 0000000000..9055753b29
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c
@@ -0,0 +1,77 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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.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
+
+#include "archive.h"
+#include "archive_private.h"
+
+/* A table that maps format codes to functions. */
+static
+struct { int code; int (*setter)(struct archive *); } codes[] =
+{
+ { ARCHIVE_FORMAT_7ZIP, archive_write_set_format_7zip },
+ { ARCHIVE_FORMAT_CPIO, archive_write_set_format_cpio },
+ { ARCHIVE_FORMAT_CPIO_POSIX, archive_write_set_format_cpio },
+ { ARCHIVE_FORMAT_CPIO_SVR4_NOCRC, archive_write_set_format_cpio_newc },
+ { ARCHIVE_FORMAT_ISO9660, archive_write_set_format_iso9660 },
+ { ARCHIVE_FORMAT_MTREE, archive_write_set_format_mtree },
+ { ARCHIVE_FORMAT_RAW, archive_write_set_format_raw },
+ { ARCHIVE_FORMAT_SHAR, archive_write_set_format_shar },
+ { ARCHIVE_FORMAT_SHAR_BASE, archive_write_set_format_shar },
+ { ARCHIVE_FORMAT_SHAR_DUMP, archive_write_set_format_shar_dump },
+ { ARCHIVE_FORMAT_TAR, archive_write_set_format_pax_restricted },
+ { ARCHIVE_FORMAT_TAR_GNUTAR, archive_write_set_format_gnutar },
+ { ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, archive_write_set_format_pax },
+ { ARCHIVE_FORMAT_TAR_PAX_RESTRICTED,
+ archive_write_set_format_pax_restricted },
+ { ARCHIVE_FORMAT_TAR_USTAR, archive_write_set_format_ustar },
+ { ARCHIVE_FORMAT_XAR, archive_write_set_format_xar },
+ { ARCHIVE_FORMAT_ZIP, archive_write_set_format_zip },
+ { 0, NULL }
+};
+
+int
+archive_write_set_format(struct archive *a, int code)
+{
+ int i;
+
+ for (i = 0; codes[i].code != 0; i++) {
+ if (code == codes[i].code)
+ return ((codes[i].setter)(a));
+ }
+
+ archive_set_error(a, EINVAL, "No such format");
+ return (ARCHIVE_FATAL);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c
new file mode 100644
index 0000000000..5158854222
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c
@@ -0,0 +1,2324 @@
+/*-
+ * Copyright (c) 2011-2012 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 <stdlib.h>
+#ifdef HAVE_BZLIB_H
+#include <cm_bzlib.h>
+#endif
+#if HAVE_LZMA_H
+#include <cm_lzma.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#ifndef HAVE_ZLIB_H
+#include "archive_crc32.h"
+#endif
+#include "archive_endian.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_ppmd7_private.h"
+#include "archive_private.h"
+#include "archive_rb.h"
+#include "archive_string.h"
+#include "archive_write_private.h"
+
+/*
+ * Codec ID
+ */
+#define _7Z_COPY 0
+#define _7Z_LZMA1 0x030101
+#define _7Z_LZMA2 0x21
+#define _7Z_DEFLATE 0x040108
+#define _7Z_BZIP2 0x040202
+#define _7Z_PPMD 0x030401
+
+/*
+ * 7-Zip header property IDs.
+ */
+#define kEnd 0x00
+#define kHeader 0x01
+#define kArchiveProperties 0x02
+#define kAdditionalStreamsInfo 0x03
+#define kMainStreamsInfo 0x04
+#define kFilesInfo 0x05
+#define kPackInfo 0x06
+#define kUnPackInfo 0x07
+#define kSubStreamsInfo 0x08
+#define kSize 0x09
+#define kCRC 0x0A
+#define kFolder 0x0B
+#define kCodersUnPackSize 0x0C
+#define kNumUnPackStream 0x0D
+#define kEmptyStream 0x0E
+#define kEmptyFile 0x0F
+#define kAnti 0x10
+#define kName 0x11
+#define kCTime 0x12
+#define kATime 0x13
+#define kMTime 0x14
+#define kAttributes 0x15
+#define kEncodedHeader 0x17
+
+enum la_zaction {
+ ARCHIVE_Z_FINISH,
+ ARCHIVE_Z_RUN
+};
+
+/*
+ * A stream object of universal compressor.
+ */
+struct la_zstream {
+ const uint8_t *next_in;
+ size_t avail_in;
+ uint64_t total_in;
+
+ uint8_t *next_out;
+ size_t avail_out;
+ uint64_t total_out;
+
+ uint32_t prop_size;
+ uint8_t *props;
+
+ int valid;
+ void *real_stream;
+ int (*code) (struct archive *a,
+ struct la_zstream *lastrm,
+ enum la_zaction action);
+ int (*end)(struct archive *a,
+ struct la_zstream *lastrm);
+};
+
+#define PPMD7_DEFAULT_ORDER 6
+#define PPMD7_DEFAULT_MEM_SIZE (1 << 24)
+
+struct ppmd_stream {
+ int stat;
+ CPpmd7 ppmd7_context;
+ CPpmd7z_RangeEnc range_enc;
+ IByteOut byteout;
+ uint8_t *buff;
+ uint8_t *buff_ptr;
+ uint8_t *buff_end;
+ size_t buff_bytes;
+};
+
+struct coder {
+ unsigned codec;
+ size_t prop_size;
+ uint8_t *props;
+};
+
+struct file {
+ struct archive_rb_node rbnode;
+
+ struct file *next;
+ unsigned name_len;
+ uint8_t *utf16name;/* UTF16-LE name. */
+ uint64_t size;
+ unsigned flg;
+#define MTIME_IS_SET (1<<0)
+#define ATIME_IS_SET (1<<1)
+#define CTIME_IS_SET (1<<2)
+#define CRC32_IS_SET (1<<3)
+#define HAS_STREAM (1<<4)
+
+ struct {
+ time_t time;
+ long time_ns;
+ } times[3];
+#define MTIME 0
+#define ATIME 1
+#define CTIME 2
+
+ mode_t mode;
+ uint32_t crc32;
+
+ int dir:1;
+};
+
+struct _7zip {
+ int temp_fd;
+ uint64_t temp_offset;
+
+ struct file *cur_file;
+ size_t total_number_entry;
+ size_t total_number_nonempty_entry;
+ size_t total_number_empty_entry;
+ size_t total_number_dir_entry;
+ size_t total_bytes_entry_name;
+ size_t total_number_time_defined[3];
+ uint64_t total_bytes_compressed;
+ uint64_t total_bytes_uncompressed;
+ uint64_t entry_bytes_remaining;
+ uint32_t entry_crc32;
+ uint32_t precode_crc32;
+ uint32_t encoded_crc32;
+ int crc32flg;
+#define PRECODE_CRC32 1
+#define ENCODED_CRC32 2
+
+ unsigned opt_compression;
+ int opt_compression_level;
+
+ struct la_zstream stream;
+ struct coder coder;
+
+ struct archive_string_conv *sconv;
+
+ /*
+ * Compressed data buffer.
+ */
+ unsigned char wbuff[512 * 20 * 6];
+ size_t wbuff_remaining;
+
+ /*
+ * The list of the file entries which has its contents is used to
+ * manage struct file objects.
+ * We use 'next' a menber of struct file to chain.
+ */
+ struct {
+ struct file *first;
+ struct file **last;
+ } file_list, empty_list;
+ struct archive_rb_tree rbtree;/* for empty files */
+};
+
+static int _7z_options(struct archive_write *,
+ const char *, const char *);
+static int _7z_write_header(struct archive_write *,
+ struct archive_entry *);
+static ssize_t _7z_write_data(struct archive_write *,
+ const void *, size_t);
+static int _7z_finish_entry(struct archive_write *);
+static int _7z_close(struct archive_write *);
+static int _7z_free(struct archive_write *);
+static int file_cmp_node(const struct archive_rb_node *,
+ const struct archive_rb_node *);
+static int file_cmp_key(const struct archive_rb_node *, const void *);
+static int file_new(struct archive_write *a, struct archive_entry *,
+ struct file **);
+static void file_free(struct file *);
+static void file_register(struct _7zip *, struct file *);
+static void file_register_empty(struct _7zip *, struct file *);
+static void file_init_register(struct _7zip *);
+static void file_init_register_empty(struct _7zip *);
+static void file_free_register(struct _7zip *);
+static ssize_t compress_out(struct archive_write *, const void *, size_t ,
+ enum la_zaction);
+static int compression_init_encoder_copy(struct archive *,
+ struct la_zstream *);
+static int compression_code_copy(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end_copy(struct archive *, struct la_zstream *);
+static int compression_init_encoder_deflate(struct archive *,
+ struct la_zstream *, int, int);
+#ifdef HAVE_ZLIB_H
+static int compression_code_deflate(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end_deflate(struct archive *, struct la_zstream *);
+#endif
+static int compression_init_encoder_bzip2(struct archive *,
+ struct la_zstream *, int);
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+static int compression_code_bzip2(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end_bzip2(struct archive *, struct la_zstream *);
+#endif
+static int compression_init_encoder_lzma1(struct archive *,
+ struct la_zstream *, int);
+static int compression_init_encoder_lzma2(struct archive *,
+ struct la_zstream *, int);
+#if defined(HAVE_LZMA_H)
+static int compression_code_lzma(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end_lzma(struct archive *, struct la_zstream *);
+#endif
+static int compression_init_encoder_ppmd(struct archive *,
+ struct la_zstream *, unsigned, uint32_t);
+static int compression_code_ppmd(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end_ppmd(struct archive *, struct la_zstream *);
+static int _7z_compression_init_encoder(struct archive_write *, unsigned,
+ int);
+static int compression_code(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end(struct archive *,
+ struct la_zstream *);
+static int enc_uint64(struct archive_write *, uint64_t);
+static int make_header(struct archive_write *, uint64_t, uint64_t,
+ uint64_t, int, struct coder *);
+static int make_streamsInfo(struct archive_write *, uint64_t, uint64_t,
+ uint64_t, int, struct coder *, int, uint32_t);
+
+int
+archive_write_set_format_7zip(struct archive *_a)
+{
+ static const struct archive_rb_tree_ops rb_ops = {
+ file_cmp_node, file_cmp_key
+ };
+ struct archive_write *a = (struct archive_write *)_a;
+ struct _7zip *zip;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_7zip");
+
+ /* If another format was already registered, unregister it. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ zip = calloc(1, sizeof(*zip));
+ if (zip == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate 7-Zip data");
+ return (ARCHIVE_FATAL);
+ }
+ zip->temp_fd = -1;
+ __archive_rb_tree_init(&(zip->rbtree), &rb_ops);
+ file_init_register(zip);
+ file_init_register_empty(zip);
+
+ /* Set default compression type and its level. */
+#if HAVE_LZMA_H
+ zip->opt_compression = _7Z_LZMA1;
+#elif defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ zip->opt_compression = _7Z_BZIP2;
+#elif defined(HAVE_ZLIB_H)
+ zip->opt_compression = _7Z_DEFLATE;
+#else
+ zip->opt_compression = _7Z_COPY;
+#endif
+ zip->opt_compression_level = 6;
+
+ a->format_data = zip;
+
+ a->format_name = "7zip";
+ a->format_options = _7z_options;
+ a->format_write_header = _7z_write_header;
+ a->format_write_data = _7z_write_data;
+ a->format_finish_entry = _7z_finish_entry;
+ a->format_close = _7z_close;
+ a->format_free = _7z_free;
+ a->archive.archive_format = ARCHIVE_FORMAT_7ZIP;
+ a->archive.archive_format_name = "7zip";
+
+ return (ARCHIVE_OK);
+}
+
+static int
+_7z_options(struct archive_write *a, const char *key, const char *value)
+{
+ struct _7zip *zip;
+
+ zip = (struct _7zip *)a->format_data;
+
+ if (strcmp(key, "compression") == 0) {
+ const char *name = NULL;
+
+ if (value == NULL || strcmp(value, "copy") == 0 ||
+ strcmp(value, "COPY") == 0 ||
+ strcmp(value, "store") == 0 ||
+ strcmp(value, "STORE") == 0)
+ zip->opt_compression = _7Z_COPY;
+ else if (strcmp(value, "deflate") == 0 ||
+ strcmp(value, "DEFLATE") == 0)
+#if HAVE_ZLIB_H
+ zip->opt_compression = _7Z_DEFLATE;
+#else
+ name = "deflate";
+#endif
+ else if (strcmp(value, "bzip2") == 0 ||
+ strcmp(value, "BZIP2") == 0)
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ zip->opt_compression = _7Z_BZIP2;
+#else
+ name = "bzip2";
+#endif
+ else if (strcmp(value, "lzma1") == 0 ||
+ strcmp(value, "LZMA1") == 0)
+#if HAVE_LZMA_H
+ zip->opt_compression = _7Z_LZMA1;
+#else
+ name = "lzma1";
+#endif
+ else if (strcmp(value, "lzma2") == 0 ||
+ strcmp(value, "LZMA2") == 0)
+#if HAVE_LZMA_H
+ zip->opt_compression = _7Z_LZMA2;
+#else
+ name = "lzma2";
+#endif
+ else if (strcmp(value, "ppmd") == 0 ||
+ strcmp(value, "PPMD") == 0 ||
+ strcmp(value, "PPMd") == 0)
+ zip->opt_compression = _7Z_PPMD;
+ else {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Unknown compression name: `%s'",
+ value);
+ return (ARCHIVE_FAILED);
+ }
+ if (name != NULL) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "`%s' compression not supported "
+ "on this platform",
+ name);
+ return (ARCHIVE_FAILED);
+ }
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "compression-level") == 0) {
+ if (value == NULL ||
+ !(value[0] >= '0' && value[0] <= '9') ||
+ value[1] != '\0') {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Illegal value `%s'",
+ value);
+ return (ARCHIVE_FAILED);
+ }
+ zip->opt_compression_level = value[0] - '0';
+ 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
+_7z_write_header(struct archive_write *a, struct archive_entry *entry)
+{
+ struct _7zip *zip;
+ struct file *file;
+ int r;
+
+ zip = (struct _7zip *)a->format_data;
+ zip->cur_file = NULL;
+ zip->entry_bytes_remaining = 0;
+
+ if (zip->sconv == NULL) {
+ zip->sconv = archive_string_conversion_to_charset(
+ &a->archive, "UTF-16LE", 1);
+ if (zip->sconv == NULL)
+ return (ARCHIVE_FATAL);
+ }
+
+ r = file_new(a, entry, &file);
+ if (r < ARCHIVE_WARN) {
+ file_free(file);
+ return (r);
+ }
+ if (file->size == 0 && file->dir) {
+ if (!__archive_rb_tree_insert_node(&(zip->rbtree),
+ (struct archive_rb_node *)file)) {
+ /* We have already had the same file. */
+ file_free(file);
+ return (ARCHIVE_OK);
+ }
+ }
+
+ if (file->flg & MTIME_IS_SET)
+ zip->total_number_time_defined[MTIME]++;
+ if (file->flg & CTIME_IS_SET)
+ zip->total_number_time_defined[CTIME]++;
+ if (file->flg & ATIME_IS_SET)
+ zip->total_number_time_defined[ATIME]++;
+
+ zip->total_number_entry++;
+ zip->total_bytes_entry_name += file->name_len + 2;
+ if (file->size == 0) {
+ /* Count up the number of empty files. */
+ zip->total_number_empty_entry++;
+ if (file->dir)
+ zip->total_number_dir_entry++;
+ else
+ file_register_empty(zip, file);
+ return (r);
+ }
+
+ /*
+ * Init compression.
+ */
+ if ((zip->total_number_entry - zip->total_number_empty_entry) == 1) {
+ r = _7z_compression_init_encoder(a, zip->opt_compression,
+ zip->opt_compression_level);
+ if (r < 0) {
+ file_free(file);
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ /* Register a non-empty file. */
+ file_register(zip, file);
+
+ /*
+ * Set the current file to cur_file to read its contents.
+ */
+ zip->cur_file = file;
+
+
+ /* Save a offset of current file in temporary file. */
+ zip->entry_bytes_remaining = file->size;
+ zip->entry_crc32 = 0;
+
+ /*
+ * Store a symbolic link name as file contents.
+ */
+ if (archive_entry_filetype(entry) == AE_IFLNK) {
+ ssize_t bytes;
+ const void *p = (const void *)archive_entry_symlink(entry);
+ bytes = compress_out(a, p, (size_t)file->size, ARCHIVE_Z_RUN);
+ if (bytes < 0)
+ return ((int)bytes);
+ zip->entry_crc32 = crc32(zip->entry_crc32, p, (unsigned)bytes);
+ zip->entry_bytes_remaining -= bytes;
+ }
+
+ return (r);
+}
+
+/*
+ * Write data to a temporary file.
+ */
+static int
+write_to_temp(struct archive_write *a, const void *buff, size_t s)
+{
+ struct _7zip *zip;
+ const unsigned char *p;
+ ssize_t ws;
+
+ zip = (struct _7zip *)a->format_data;
+
+ /*
+ * Open a temporary file.
+ */
+ if (zip->temp_fd == -1) {
+ zip->temp_offset = 0;
+ zip->temp_fd = __archive_mktemp(NULL);
+ if (zip->temp_fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't create temporary file");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ p = (const unsigned char *)buff;
+ while (s) {
+ ws = write(zip->temp_fd, p, s);
+ if (ws < 0) {
+ archive_set_error(&(a->archive), errno,
+ "fwrite function failed");
+ return (ARCHIVE_FATAL);
+ }
+ s -= ws;
+ p += ws;
+ zip->temp_offset += ws;
+ }
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+compress_out(struct archive_write *a, const void *buff, size_t s,
+ enum la_zaction run)
+{
+ struct _7zip *zip = (struct _7zip *)a->format_data;
+ int r;
+
+ if (run == ARCHIVE_Z_FINISH && zip->stream.total_in == 0 && s == 0)
+ return (0);
+
+ if ((zip->crc32flg & PRECODE_CRC32) && s)
+ zip->precode_crc32 = crc32(zip->precode_crc32, buff,
+ (unsigned)s);
+ zip->stream.next_in = (const unsigned char *)buff;
+ zip->stream.avail_in = s;
+ for (;;) {
+ /* Compress file data. */
+ r = compression_code(&(a->archive), &(zip->stream), run);
+ if (r != ARCHIVE_OK && r != ARCHIVE_EOF)
+ return (ARCHIVE_FATAL);
+ if (zip->stream.avail_out == 0) {
+ if (write_to_temp(a, zip->wbuff, sizeof(zip->wbuff))
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ zip->stream.next_out = zip->wbuff;
+ zip->stream.avail_out = sizeof(zip->wbuff);
+ if (zip->crc32flg & ENCODED_CRC32)
+ zip->encoded_crc32 = crc32(zip->encoded_crc32,
+ zip->wbuff, sizeof(zip->wbuff));
+ if (run == ARCHIVE_Z_FINISH && r != ARCHIVE_EOF)
+ continue;
+ }
+ if (zip->stream.avail_in == 0)
+ break;
+ }
+ if (run == ARCHIVE_Z_FINISH) {
+ uint64_t bytes = sizeof(zip->wbuff) - zip->stream.avail_out;
+ if (write_to_temp(a, zip->wbuff, (size_t)bytes) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ if ((zip->crc32flg & ENCODED_CRC32) && bytes)
+ zip->encoded_crc32 = crc32(zip->encoded_crc32,
+ zip->wbuff, (unsigned)bytes);
+ }
+
+ return (s);
+}
+
+static ssize_t
+_7z_write_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct _7zip *zip;
+ ssize_t bytes;
+
+ zip = (struct _7zip *)a->format_data;
+
+ if (s > zip->entry_bytes_remaining)
+ s = (size_t)zip->entry_bytes_remaining;
+ if (s == 0 || zip->cur_file == NULL)
+ return (0);
+ bytes = compress_out(a, buff, s, ARCHIVE_Z_RUN);
+ if (bytes < 0)
+ return (bytes);
+ zip->entry_crc32 = crc32(zip->entry_crc32, buff, (unsigned)bytes);
+ zip->entry_bytes_remaining -= bytes;
+ return (bytes);
+}
+
+static int
+_7z_finish_entry(struct archive_write *a)
+{
+ struct _7zip *zip;
+ size_t s;
+ ssize_t r;
+
+ zip = (struct _7zip *)a->format_data;
+ if (zip->cur_file == NULL)
+ return (ARCHIVE_OK);
+
+ while (zip->entry_bytes_remaining > 0) {
+ s = (size_t)zip->entry_bytes_remaining;
+ if (s > a->null_length)
+ s = a->null_length;
+ r = _7z_write_data(a, a->nulls, s);
+ if (r < 0)
+ return ((int)r);
+ }
+ zip->total_bytes_compressed += zip->stream.total_in;
+ zip->total_bytes_uncompressed += zip->stream.total_out;
+ zip->cur_file->crc32 = zip->entry_crc32;
+ zip->cur_file = NULL;
+
+ return (ARCHIVE_OK);
+}
+
+static int
+flush_wbuff(struct archive_write *a)
+{
+ struct _7zip *zip;
+ int r;
+ size_t s;
+
+ zip = (struct _7zip *)a->format_data;
+ s = sizeof(zip->wbuff) - zip->wbuff_remaining;
+ r = __archive_write_output(a, zip->wbuff, s);
+ if (r != ARCHIVE_OK)
+ return (r);
+ zip->wbuff_remaining = sizeof(zip->wbuff);
+ return (r);
+}
+
+static int
+copy_out(struct archive_write *a, uint64_t offset, uint64_t length)
+{
+ struct _7zip *zip;
+ int r;
+
+ zip = (struct _7zip *)a->format_data;
+ if (zip->temp_offset > 0 &&
+ lseek(zip->temp_fd, offset, SEEK_SET) < 0) {
+ archive_set_error(&(a->archive), errno, "lseek failed");
+ return (ARCHIVE_FATAL);
+ }
+ while (length) {
+ size_t rsize;
+ ssize_t rs;
+ unsigned char *wb;
+
+ if (length > zip->wbuff_remaining)
+ rsize = zip->wbuff_remaining;
+ else
+ rsize = (size_t)length;
+ wb = zip->wbuff + (sizeof(zip->wbuff) - zip->wbuff_remaining);
+ rs = read(zip->temp_fd, wb, rsize);
+ if (rs < 0) {
+ archive_set_error(&(a->archive), errno,
+ "Can't read temporary file(%jd)",
+ (intmax_t)rs);
+ return (ARCHIVE_FATAL);
+ }
+ if (rs == 0) {
+ archive_set_error(&(a->archive), 0,
+ "Truncated 7-Zip archive");
+ return (ARCHIVE_FATAL);
+ }
+ zip->wbuff_remaining -= rs;
+ length -= rs;
+ if (zip->wbuff_remaining == 0) {
+ r = flush_wbuff(a);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+_7z_close(struct archive_write *a)
+{
+ struct _7zip *zip;
+ unsigned char *wb;
+ uint64_t header_offset, header_size, header_unpacksize;
+ uint64_t length;
+ uint32_t header_crc32;
+ int r;
+
+ zip = (struct _7zip *)a->format_data;
+
+ if (zip->total_number_entry > 0) {
+ struct archive_rb_node *n;
+ uint64_t data_offset, data_size, data_unpacksize;
+ unsigned header_compression;
+
+ r = (int)compress_out(a, NULL, 0, ARCHIVE_Z_FINISH);
+ if (r < 0)
+ return (r);
+ data_offset = 0;
+ data_size = zip->stream.total_out;
+ data_unpacksize = zip->stream.total_in;
+ zip->coder.codec = zip->opt_compression;
+ zip->coder.prop_size = zip->stream.prop_size;
+ zip->coder.props = zip->stream.props;
+ zip->stream.prop_size = 0;
+ zip->stream.props = NULL;
+ zip->total_number_nonempty_entry =
+ zip->total_number_entry - zip->total_number_empty_entry;
+
+ /* Connect an empty file list. */
+ if (zip->empty_list.first != NULL) {
+ *zip->file_list.last = zip->empty_list.first;
+ zip->file_list.last = zip->empty_list.last;
+ }
+ /* Connect a directory file list. */
+ ARCHIVE_RB_TREE_FOREACH(n, &(zip->rbtree)) {
+ file_register(zip, (struct file *)n);
+ }
+
+ /*
+ * NOTE: 7z command supports just LZMA1, LZMA2 and COPY for
+ * the compression type for encoding the header.
+ */
+#if HAVE_LZMA_H
+ header_compression = _7Z_LZMA1;
+ /* If the stored file is only one, do not encode the header.
+ * This is the same way 7z command does. */
+ if (zip->total_number_entry == 1)
+ header_compression = _7Z_COPY;
+#else
+ header_compression = _7Z_COPY;
+#endif
+ r = _7z_compression_init_encoder(a, header_compression, 6);
+ if (r < 0)
+ return (r);
+ zip->crc32flg = PRECODE_CRC32;
+ zip->precode_crc32 = 0;
+ r = make_header(a, data_offset, data_size, data_unpacksize,
+ 1, &(zip->coder));
+ if (r < 0)
+ return (r);
+ r = (int)compress_out(a, NULL, 0, ARCHIVE_Z_FINISH);
+ if (r < 0)
+ return (r);
+ header_offset = data_offset + data_size;
+ header_size = zip->stream.total_out;
+ header_crc32 = zip->precode_crc32;
+ header_unpacksize = zip->stream.total_in;
+
+ if (header_compression != _7Z_COPY) {
+ /*
+ * Encode the header in order to reduce the size
+ * of the archive.
+ */
+ free(zip->coder.props);
+ zip->coder.codec = header_compression;
+ zip->coder.prop_size = zip->stream.prop_size;
+ zip->coder.props = zip->stream.props;
+ zip->stream.prop_size = 0;
+ zip->stream.props = NULL;
+
+ r = _7z_compression_init_encoder(a, _7Z_COPY, 0);
+ if (r < 0)
+ return (r);
+ zip->crc32flg = ENCODED_CRC32;
+ zip->encoded_crc32 = 0;
+
+ /*
+ * Make EncodedHeader.
+ */
+ r = enc_uint64(a, kEncodedHeader);
+ if (r < 0)
+ return (r);
+ r = make_streamsInfo(a, header_offset, header_size,
+ header_unpacksize, 1, &(zip->coder), 0,
+ header_crc32);
+ if (r < 0)
+ return (r);
+ r = (int)compress_out(a, NULL, 0, ARCHIVE_Z_FINISH);
+ if (r < 0)
+ return (r);
+ header_offset = header_offset + header_size;
+ header_size = zip->stream.total_out;
+ header_crc32 = zip->encoded_crc32;
+ }
+ zip->crc32flg = 0;
+ } else {
+ header_offset = header_size = 0;
+ header_crc32 = 0;
+ }
+
+ length = zip->temp_offset;
+
+ /*
+ * Make the zip header on wbuff(write buffer).
+ */
+ wb = zip->wbuff;
+ zip->wbuff_remaining = sizeof(zip->wbuff);
+ memcpy(&wb[0], "7z\xBC\xAF\x27\x1C", 6);
+ wb[6] = 0;/* Major version. */
+ wb[7] = 3;/* Minor version. */
+ archive_le64enc(&wb[12], header_offset);/* Next Header Offset */
+ archive_le64enc(&wb[20], header_size);/* Next Header Size */
+ archive_le32enc(&wb[28], header_crc32);/* Next Header CRC */
+ archive_le32enc(&wb[8], crc32(0, &wb[12], 20));/* Start Header CRC */
+ zip->wbuff_remaining -= 32;
+
+ /*
+ * Read all file contents and an encoded header from the temporary
+ * file and write out it.
+ */
+ r = copy_out(a, 0, length);
+ if (r != ARCHIVE_OK)
+ return (r);
+ r = flush_wbuff(a);
+ return (r);
+}
+
+/*
+ * Encode 64 bits value into 7-Zip's encoded UINT64 value.
+ */
+static int
+enc_uint64(struct archive_write *a, uint64_t val)
+{
+ unsigned mask = 0x80;
+ uint8_t numdata[9];
+ int i;
+
+ numdata[0] = 0;
+ for (i = 1; i < (int)sizeof(numdata); i++) {
+ if (val < mask) {
+ numdata[0] |= (uint8_t)val;
+ break;
+ }
+ numdata[i] = (uint8_t)val;
+ val >>= 8;
+ numdata[0] |= mask;
+ mask >>= 1;
+ }
+ return ((int)compress_out(a, numdata, i, ARCHIVE_Z_RUN));
+}
+
+static int
+make_substreamsInfo(struct archive_write *a, struct coder *coders)
+{
+ struct _7zip *zip = (struct _7zip *)a->format_data;
+ struct file *file;
+ int r;
+
+ /*
+ * Make SubStreamsInfo.
+ */
+ r = enc_uint64(a, kSubStreamsInfo);
+ if (r < 0)
+ return (r);
+
+ if (zip->total_number_nonempty_entry > 1 && coders->codec != _7Z_COPY) {
+ /*
+ * Make NumUnPackStream.
+ */
+ r = enc_uint64(a, kNumUnPackStream);
+ if (r < 0)
+ return (r);
+
+ /* Write numUnpackStreams */
+ r = enc_uint64(a, zip->total_number_nonempty_entry);
+ if (r < 0)
+ return (r);
+
+ /*
+ * Make kSize.
+ */
+ r = enc_uint64(a, kSize);
+ if (r < 0)
+ return (r);
+ file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ if (file->next == NULL ||
+ file->next->size == 0)
+ break;
+ r = enc_uint64(a, file->size);
+ if (r < 0)
+ return (r);
+ }
+ }
+
+ /*
+ * Make CRC.
+ */
+ r = enc_uint64(a, kCRC);
+ if (r < 0)
+ return (r);
+
+
+ /* All are defined */
+ r = enc_uint64(a, 1);
+ if (r < 0)
+ return (r);
+ file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ uint8_t crc[4];
+ if (file->size == 0)
+ break;
+ archive_le32enc(crc, file->crc32);
+ r = (int)compress_out(a, crc, 4, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ }
+
+ /* Write End. */
+ r = enc_uint64(a, kEnd);
+ if (r < 0)
+ return (r);
+ return (ARCHIVE_OK);
+}
+
+static int
+make_streamsInfo(struct archive_write *a, uint64_t offset, uint64_t pack_size,
+ uint64_t unpack_size, int num_coder, struct coder *coders, int substrm,
+ uint32_t header_crc)
+{
+ struct _7zip *zip = (struct _7zip *)a->format_data;
+ uint8_t codec_buff[8];
+ int numFolders, fi;
+ int codec_size;
+ int i, r;
+
+ if (coders->codec == _7Z_COPY)
+ numFolders = (int)zip->total_number_nonempty_entry;
+ else
+ numFolders = 1;
+
+ /*
+ * Make PackInfo.
+ */
+ r = enc_uint64(a, kPackInfo);
+ if (r < 0)
+ return (r);
+
+ /* Write PackPos. */
+ r = enc_uint64(a, offset);
+ if (r < 0)
+ return (r);
+
+ /* Write NumPackStreams. */
+ r = enc_uint64(a, numFolders);
+ if (r < 0)
+ return (r);
+
+ /* Make Size. */
+ r = enc_uint64(a, kSize);
+ if (r < 0)
+ return (r);
+
+ if (numFolders > 1) {
+ struct file *file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ if (file->size == 0)
+ break;
+ r = enc_uint64(a, file->size);
+ if (r < 0)
+ return (r);
+ }
+ } else {
+ /* Write size. */
+ r = enc_uint64(a, pack_size);
+ if (r < 0)
+ return (r);
+ }
+
+ r = enc_uint64(a, kEnd);
+ if (r < 0)
+ return (r);
+
+ /*
+ * Make UnPackInfo.
+ */
+ r = enc_uint64(a, kUnPackInfo);
+ if (r < 0)
+ return (r);
+
+ /*
+ * Make Folder.
+ */
+ r = enc_uint64(a, kFolder);
+ if (r < 0)
+ return (r);
+
+ /* Write NumFolders. */
+ r = enc_uint64(a, numFolders);
+ if (r < 0)
+ return (r);
+
+ /* Write External. */
+ r = enc_uint64(a, 0);
+ if (r < 0)
+ return (r);
+
+ for (fi = 0; fi < numFolders; fi++) {
+ /* Write NumCoders. */
+ r = enc_uint64(a, num_coder);
+ if (r < 0)
+ return (r);
+
+ for (i = 0; i < num_coder; i++) {
+ unsigned codec_id = coders[i].codec;
+
+ /* Write Codec flag. */
+ archive_be64enc(codec_buff, codec_id);
+ for (codec_size = 8; codec_size > 0; codec_size--) {
+ if (codec_buff[8 - codec_size])
+ break;
+ }
+ if (codec_size == 0)
+ codec_size = 1;
+ if (coders[i].prop_size)
+ r = enc_uint64(a, codec_size | 0x20);
+ else
+ r = enc_uint64(a, codec_size);
+ if (r < 0)
+ return (r);
+
+ /* Write Codec ID. */
+ codec_size &= 0x0f;
+ r = (int)compress_out(a, &codec_buff[8-codec_size],
+ codec_size, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+
+ if (coders[i].prop_size) {
+ /* Write Codec property size. */
+ r = enc_uint64(a, coders[i].prop_size);
+ if (r < 0)
+ return (r);
+
+ /* Write Codec properties. */
+ r = (int)compress_out(a, coders[i].props,
+ coders[i].prop_size, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ }
+ }
+ }
+
+ /*
+ * Make CodersUnPackSize.
+ */
+ r = enc_uint64(a, kCodersUnPackSize);
+ if (r < 0)
+ return (r);
+
+ if (numFolders > 1) {
+ struct file *file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ if (file->size == 0)
+ break;
+ r = enc_uint64(a, file->size);
+ if (r < 0)
+ return (r);
+ }
+
+ } else {
+ /* Write UnPackSize. */
+ r = enc_uint64(a, unpack_size);
+ if (r < 0)
+ return (r);
+ }
+
+ if (!substrm) {
+ uint8_t crc[4];
+ /*
+ * Make CRC.
+ */
+ r = enc_uint64(a, kCRC);
+ if (r < 0)
+ return (r);
+
+ /* All are defined */
+ r = enc_uint64(a, 1);
+ if (r < 0)
+ return (r);
+ archive_le32enc(crc, header_crc);
+ r = (int)compress_out(a, crc, 4, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ }
+
+ /* Write End. */
+ r = enc_uint64(a, kEnd);
+ if (r < 0)
+ return (r);
+
+ if (substrm) {
+ /*
+ * Make SubStreamsInfo.
+ */
+ r = make_substreamsInfo(a, coders);
+ if (r < 0)
+ return (r);
+ }
+
+
+ /* Write End. */
+ r = enc_uint64(a, kEnd);
+ if (r < 0)
+ return (r);
+
+ return (ARCHIVE_OK);
+}
+
+
+#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
+static uint64_t
+utcToFiletime(time_t t, long ns)
+{
+ uint64_t fileTime;
+
+ fileTime = t;
+ fileTime *= 10000000;
+ fileTime += ns / 100;
+ fileTime += EPOC_TIME;
+ return (fileTime);
+}
+
+static int
+make_time(struct archive_write *a, uint8_t type, unsigned flg, int ti)
+{
+ uint8_t filetime[8];
+ struct _7zip *zip = (struct _7zip *)a->format_data;
+ struct file *file;
+ int r;
+ uint8_t b, mask;
+
+ /*
+ * Make Time Bools.
+ */
+ if (zip->total_number_time_defined[ti] == zip->total_number_entry) {
+ /* Write Time Type. */
+ r = enc_uint64(a, type);
+ if (r < 0)
+ return (r);
+ /* Write EmptyStream Size. */
+ r = enc_uint64(a, 2 + zip->total_number_entry * 8);
+ if (r < 0)
+ return (r);
+ /* All are defined. */
+ r = enc_uint64(a, 1);
+ if (r < 0)
+ return (r);
+ } else {
+ if (zip->total_number_time_defined[ti] == 0)
+ return (ARCHIVE_OK);
+
+ /* Write Time Type. */
+ r = enc_uint64(a, type);
+ if (r < 0)
+ return (r);
+ /* Write EmptyStream Size. */
+ r = enc_uint64(a, 2 + ((zip->total_number_entry + 7) >> 3)
+ + zip->total_number_time_defined[ti] * 8);
+ if (r < 0)
+ return (r);
+
+ /* All are not defined. */
+ r = enc_uint64(a, 0);
+ if (r < 0)
+ return (r);
+
+ b = 0;
+ mask = 0x80;
+ file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ if (file->flg & flg)
+ b |= mask;
+ mask >>= 1;
+ if (mask == 0) {
+ r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ mask = 0x80;
+ b = 0;
+ }
+ }
+ if (mask != 0x80) {
+ r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ }
+ }
+
+ /* External. */
+ r = enc_uint64(a, 0);
+ if (r < 0)
+ return (r);
+
+
+ /*
+ * Make Times.
+ */
+ file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ if ((file->flg & flg) == 0)
+ continue;
+ archive_le64enc(filetime, utcToFiletime(file->times[ti].time,
+ file->times[ti].time_ns));
+ r = (int)compress_out(a, filetime, 8, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static int
+make_header(struct archive_write *a, uint64_t offset, uint64_t pack_size,
+ uint64_t unpack_size, int codernum, struct coder *coders)
+{
+ struct _7zip *zip = (struct _7zip *)a->format_data;
+ struct file *file;
+ int r;
+ uint8_t b, mask;
+
+ /*
+ * Make FilesInfo.
+ */
+ r = enc_uint64(a, kHeader);
+ if (r < 0)
+ return (r);
+
+ /*
+ * If there are empty files only, do not write MainStreamInfo.
+ */
+ if (zip->total_number_nonempty_entry) {
+ /*
+ * Make MainStreamInfo.
+ */
+ r = enc_uint64(a, kMainStreamsInfo);
+ if (r < 0)
+ return (r);
+ r = make_streamsInfo(a, offset, pack_size, unpack_size,
+ codernum, coders, 1, 0);
+ if (r < 0)
+ return (r);
+ }
+
+ /*
+ * Make FilesInfo.
+ */
+ r = enc_uint64(a, kFilesInfo);
+ if (r < 0)
+ return (r);
+
+ /* Write numFiles. */
+ r = enc_uint64(a, zip->total_number_entry);
+ if (r < 0)
+ return (r);
+
+ if (zip->total_number_empty_entry > 0) {
+ /* Make EmptyStream. */
+ r = enc_uint64(a, kEmptyStream);
+ if (r < 0)
+ return (r);
+
+ /* Write EmptyStream Size. */
+ r = enc_uint64(a, (zip->total_number_entry+7)>>3);
+ if (r < 0)
+ return (r);
+
+ b = 0;
+ mask = 0x80;
+ file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ if (file->size == 0)
+ b |= mask;
+ mask >>= 1;
+ if (mask == 0) {
+ r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ mask = 0x80;
+ b = 0;
+ }
+ }
+ if (mask != 0x80) {
+ r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ }
+ }
+
+ if (zip->total_number_empty_entry > zip->total_number_dir_entry) {
+ /* Make EmptyFile. */
+ r = enc_uint64(a, kEmptyFile);
+ if (r < 0)
+ return (r);
+
+ /* Write EmptyFile Size. */
+ r = enc_uint64(a, (zip->total_number_empty_entry + 7) >> 3);
+ if (r < 0)
+ return (r);
+
+ b = 0;
+ mask = 0x80;
+ file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ if (file->size)
+ continue;
+ if (!file->dir)
+ b |= mask;
+ mask >>= 1;
+ if (mask == 0) {
+ r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ mask = 0x80;
+ b = 0;
+ }
+ }
+ if (mask != 0x80) {
+ r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ }
+ }
+
+ /* Make Name. */
+ r = enc_uint64(a, kName);
+ if (r < 0)
+ return (r);
+
+ /* Write Nume size. */
+ r = enc_uint64(a, zip->total_bytes_entry_name+1);
+ if (r < 0)
+ return (r);
+
+ /* Write dmy byte. */
+ r = enc_uint64(a, 0);
+ if (r < 0)
+ return (r);
+
+ file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ r = (int)compress_out(a, file->utf16name, file->name_len+2,
+ ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ }
+
+ /* Make MTime. */
+ r = make_time(a, kMTime, MTIME_IS_SET, MTIME);
+ if (r < 0)
+ return (r);
+
+ /* Make CTime. */
+ r = make_time(a, kCTime, CTIME_IS_SET, CTIME);
+ if (r < 0)
+ return (r);
+
+ /* Make ATime. */
+ r = make_time(a, kATime, ATIME_IS_SET, ATIME);
+ if (r < 0)
+ return (r);
+
+ /* Make Attributes. */
+ r = enc_uint64(a, kAttributes);
+ if (r < 0)
+ return (r);
+
+ /* Write Attributes size. */
+ r = enc_uint64(a, 2 + zip->total_number_entry * 4);
+ if (r < 0)
+ return (r);
+
+ /* Write "All Are Defined". */
+ r = enc_uint64(a, 1);
+ if (r < 0)
+ return (r);
+
+ /* Write dmy byte. */
+ r = enc_uint64(a, 0);
+ if (r < 0)
+ return (r);
+
+ file = zip->file_list.first;
+ for (;file != NULL; file = file->next) {
+ /*
+ * High 16bits is unix mode.
+ * Low 16bits is Windows attributes.
+ */
+ uint32_t encattr, attr;
+ if (file->dir)
+ attr = 0x8010;
+ else
+ attr = 0x8020;
+ if ((file->mode & 0222) == 0)
+ attr |= 1;/* Read Only. */
+ attr |= ((uint32_t)file->mode) << 16;
+ archive_le32enc(&encattr, attr);
+ r = (int)compress_out(a, &encattr, 4, ARCHIVE_Z_RUN);
+ if (r < 0)
+ return (r);
+ }
+
+ /* Write End. */
+ r = enc_uint64(a, kEnd);
+ if (r < 0)
+ return (r);
+
+ /* Write End. */
+ r = enc_uint64(a, kEnd);
+ if (r < 0)
+ return (r);
+
+ return (ARCHIVE_OK);
+}
+
+
+static int
+_7z_free(struct archive_write *a)
+{
+ struct _7zip *zip = (struct _7zip *)a->format_data;
+
+ file_free_register(zip);
+ compression_end(&(a->archive), &(zip->stream));
+ free(zip->coder.props);
+ free(zip);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+file_cmp_node(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ const struct file *f1 = (const struct file *)n1;
+ const struct file *f2 = (const struct file *)n2;
+
+ if (f1->name_len == f2->name_len)
+ return (memcmp(f1->utf16name, f2->utf16name, f1->name_len));
+ return (f1->name_len > f2->name_len)?1:-1;
+}
+
+static int
+file_cmp_key(const struct archive_rb_node *n, const void *key)
+{
+ const struct file *f = (const struct file *)n;
+
+ return (f->name_len - *(const char *)key);
+}
+
+static int
+file_new(struct archive_write *a, struct archive_entry *entry,
+ struct file **newfile)
+{
+ struct _7zip *zip;
+ struct file *file;
+ const char *u16;
+ size_t u16len;
+ int ret = ARCHIVE_OK;
+
+ zip = (struct _7zip *)a->format_data;
+ *newfile = NULL;
+
+ file = calloc(1, sizeof(*file));
+ if (file == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (0 > archive_entry_pathname_l(entry, &u16, &u16len, zip->sconv)) {
+ if (errno == ENOMEM) {
+ free(file);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for UTF-16LE");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "A filename cannot be converted to UTF-16LE;"
+ "You should disable making Joliet extension");
+ ret = ARCHIVE_WARN;
+ }
+ file->utf16name = malloc(u16len + 2);
+ if (file->utf16name == NULL) {
+ free(file);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Name");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(file->utf16name, u16, u16len);
+ file->utf16name[u16len+0] = 0;
+ file->utf16name[u16len+1] = 0;
+ file->name_len = (unsigned)u16len;
+ file->mode = archive_entry_mode(entry);
+ if (archive_entry_filetype(entry) == AE_IFREG)
+ file->size = archive_entry_size(entry);
+ else
+ archive_entry_set_size(entry, 0);
+ if (archive_entry_filetype(entry) == AE_IFDIR)
+ file->dir = 1;
+ else if (archive_entry_filetype(entry) == AE_IFLNK)
+ file->size = strlen(archive_entry_symlink(entry));
+ if (archive_entry_mtime_is_set(entry)) {
+ file->flg |= MTIME_IS_SET;
+ file->times[MTIME].time = archive_entry_mtime(entry);
+ file->times[MTIME].time_ns = archive_entry_mtime_nsec(entry);
+ }
+ if (archive_entry_atime_is_set(entry)) {
+ file->flg |= ATIME_IS_SET;
+ file->times[ATIME].time = archive_entry_atime(entry);
+ file->times[ATIME].time_ns = archive_entry_atime_nsec(entry);
+ }
+ if (archive_entry_ctime_is_set(entry)) {
+ file->flg |= CTIME_IS_SET;
+ file->times[CTIME].time = archive_entry_ctime(entry);
+ file->times[CTIME].time_ns = archive_entry_ctime_nsec(entry);
+ }
+
+ *newfile = file;
+ return (ret);
+}
+
+static void
+file_free(struct file *file)
+{
+ free(file->utf16name);
+ free(file);
+}
+
+static void
+file_register(struct _7zip *zip, struct file *file)
+{
+ file->next = NULL;
+ *zip->file_list.last = file;
+ zip->file_list.last = &(file->next);
+}
+
+static void
+file_init_register(struct _7zip *zip)
+{
+ zip->file_list.first = NULL;
+ zip->file_list.last = &(zip->file_list.first);
+}
+
+static void
+file_free_register(struct _7zip *zip)
+{
+ struct file *file, *file_next;
+
+ file = zip->file_list.first;
+ while (file != NULL) {
+ file_next = file->next;
+ file_free(file);
+ file = file_next;
+ }
+}
+
+static void
+file_register_empty(struct _7zip *zip, struct file *file)
+{
+ file->next = NULL;
+ *zip->empty_list.last = file;
+ zip->empty_list.last = &(file->next);
+}
+
+static void
+file_init_register_empty(struct _7zip *zip)
+{
+ zip->empty_list.first = NULL;
+ zip->empty_list.last = &(zip->empty_list.first);
+}
+
+#if !defined(HAVE_ZLIB_H) || !defined(HAVE_BZLIB_H) ||\
+ !defined(BZ_CONFIG_ERROR) || !defined(HAVE_LZMA_H)
+static int
+compression_unsupported_encoder(struct archive *a,
+ struct la_zstream *lastrm, const char *name)
+{
+
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "%s compression not supported on this platform", name);
+ lastrm->valid = 0;
+ lastrm->real_stream = NULL;
+ return (ARCHIVE_FAILED);
+}
+#endif
+
+/*
+ * _7_COPY compressor.
+ */
+static int
+compression_init_encoder_copy(struct archive *a, struct la_zstream *lastrm)
+{
+
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ lastrm->valid = 1;
+ lastrm->code = compression_code_copy;
+ lastrm->end = compression_end_copy;
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_code_copy(struct archive *a,
+ struct la_zstream *lastrm, enum la_zaction action)
+{
+ size_t bytes;
+
+ (void)a; /* UNUSED */
+ if (lastrm->avail_out > lastrm->avail_in)
+ bytes = lastrm->avail_in;
+ else
+ bytes = lastrm->avail_out;
+ if (bytes) {
+ memcpy(lastrm->next_out, lastrm->next_in, bytes);
+ lastrm->next_in += bytes;
+ lastrm->avail_in -= bytes;
+ lastrm->total_in += bytes;
+ lastrm->next_out += bytes;
+ lastrm->avail_out -= bytes;
+ lastrm->total_out += bytes;
+ }
+ if (action == ARCHIVE_Z_FINISH && lastrm->avail_in == 0)
+ return (ARCHIVE_EOF);
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_end_copy(struct archive *a, struct la_zstream *lastrm)
+{
+ (void)a; /* UNUSED */
+ lastrm->valid = 0;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * _7_DEFLATE compressor.
+ */
+#ifdef HAVE_ZLIB_H
+static int
+compression_init_encoder_deflate(struct archive *a,
+ struct la_zstream *lastrm, int level, int withheader)
+{
+ z_stream *strm;
+
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ strm = calloc(1, sizeof(*strm));
+ if (strm == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate memory for gzip stream");
+ return (ARCHIVE_FATAL);
+ }
+ /* zlib.h is not const-correct, so we need this one bit
+ * of ugly hackery to convert a const * pointer to
+ * a non-const pointer. */
+ strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in;
+ strm->avail_in = (uInt)lastrm->avail_in;
+ strm->total_in = (uLong)lastrm->total_in;
+ strm->next_out = lastrm->next_out;
+ strm->avail_out = (uInt)lastrm->avail_out;
+ strm->total_out = (uLong)lastrm->total_out;
+ if (deflateInit2(strm, level, Z_DEFLATED,
+ (withheader)?15:-15,
+ 8, Z_DEFAULT_STRATEGY) != Z_OK) {
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library");
+ return (ARCHIVE_FATAL);
+ }
+ lastrm->real_stream = strm;
+ lastrm->valid = 1;
+ lastrm->code = compression_code_deflate;
+ lastrm->end = compression_end_deflate;
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_code_deflate(struct archive *a,
+ struct la_zstream *lastrm, enum la_zaction action)
+{
+ z_stream *strm;
+ int r;
+
+ strm = (z_stream *)lastrm->real_stream;
+ /* zlib.h is not const-correct, so we need this one bit
+ * of ugly hackery to convert a const * pointer to
+ * a non-const pointer. */
+ strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in;
+ strm->avail_in = (uInt)lastrm->avail_in;
+ strm->total_in = (uLong)lastrm->total_in;
+ strm->next_out = lastrm->next_out;
+ strm->avail_out = (uInt)lastrm->avail_out;
+ strm->total_out = (uLong)lastrm->total_out;
+ r = deflate(strm,
+ (action == ARCHIVE_Z_FINISH)? Z_FINISH: Z_NO_FLUSH);
+ lastrm->next_in = strm->next_in;
+ lastrm->avail_in = strm->avail_in;
+ lastrm->total_in = strm->total_in;
+ lastrm->next_out = strm->next_out;
+ lastrm->avail_out = strm->avail_out;
+ lastrm->total_out = strm->total_out;
+ switch (r) {
+ case Z_OK:
+ return (ARCHIVE_OK);
+ case Z_STREAM_END:
+ return (ARCHIVE_EOF);
+ default:
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "GZip compression failed:"
+ " deflate() call returned status %d", r);
+ return (ARCHIVE_FATAL);
+ }
+}
+
+static int
+compression_end_deflate(struct archive *a, struct la_zstream *lastrm)
+{
+ z_stream *strm;
+ int r;
+
+ strm = (z_stream *)lastrm->real_stream;
+ r = deflateEnd(strm);
+ free(strm);
+ lastrm->real_stream = NULL;
+ lastrm->valid = 0;
+ if (r != Z_OK) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Failed to clean up compressor");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+#else
+static int
+compression_init_encoder_deflate(struct archive *a,
+ struct la_zstream *lastrm, int level, int withheader)
+{
+
+ (void) level; /* UNUSED */
+ (void) withheader; /* UNUSED */
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ return (compression_unsupported_encoder(a, lastrm, "deflate"));
+}
+#endif
+
+/*
+ * _7_BZIP2 compressor.
+ */
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+static int
+compression_init_encoder_bzip2(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+ bz_stream *strm;
+
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ strm = calloc(1, sizeof(*strm));
+ if (strm == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate memory for bzip2 stream");
+ return (ARCHIVE_FATAL);
+ }
+ /* bzlib.h is not const-correct, so we need this one bit
+ * of ugly hackery to convert a const * pointer to
+ * a non-const pointer. */
+ strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in;
+ strm->avail_in = lastrm->avail_in;
+ strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff);
+ strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32);
+ strm->next_out = (char *)lastrm->next_out;
+ strm->avail_out = lastrm->avail_out;
+ strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff);
+ strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32);
+ if (BZ2_bzCompressInit(strm, level, 0, 30) != BZ_OK) {
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library");
+ return (ARCHIVE_FATAL);
+ }
+ lastrm->real_stream = strm;
+ lastrm->valid = 1;
+ lastrm->code = compression_code_bzip2;
+ lastrm->end = compression_end_bzip2;
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_code_bzip2(struct archive *a,
+ struct la_zstream *lastrm, enum la_zaction action)
+{
+ bz_stream *strm;
+ int r;
+
+ strm = (bz_stream *)lastrm->real_stream;
+ /* bzlib.h is not const-correct, so we need this one bit
+ * of ugly hackery to convert a const * pointer to
+ * a non-const pointer. */
+ strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in;
+ strm->avail_in = lastrm->avail_in;
+ strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff);
+ strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32);
+ strm->next_out = (char *)lastrm->next_out;
+ strm->avail_out = lastrm->avail_out;
+ strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff);
+ strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32);
+ r = BZ2_bzCompress(strm,
+ (action == ARCHIVE_Z_FINISH)? BZ_FINISH: BZ_RUN);
+ lastrm->next_in = (const unsigned char *)strm->next_in;
+ lastrm->avail_in = strm->avail_in;
+ lastrm->total_in =
+ (((uint64_t)(uint32_t)strm->total_in_hi32) << 32)
+ + (uint64_t)(uint32_t)strm->total_in_lo32;
+ lastrm->next_out = (unsigned char *)strm->next_out;
+ lastrm->avail_out = strm->avail_out;
+ lastrm->total_out =
+ (((uint64_t)(uint32_t)strm->total_out_hi32) << 32)
+ + (uint64_t)(uint32_t)strm->total_out_lo32;
+ switch (r) {
+ case BZ_RUN_OK: /* Non-finishing */
+ case BZ_FINISH_OK: /* Finishing: There's more work to do */
+ return (ARCHIVE_OK);
+ case BZ_STREAM_END: /* Finishing: all done */
+ /* Only occurs in finishing case */
+ return (ARCHIVE_EOF);
+ default:
+ /* Any other return value indicates an error */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Bzip2 compression failed:"
+ " BZ2_bzCompress() call returned status %d", r);
+ return (ARCHIVE_FATAL);
+ }
+}
+
+static int
+compression_end_bzip2(struct archive *a, struct la_zstream *lastrm)
+{
+ bz_stream *strm;
+ int r;
+
+ strm = (bz_stream *)lastrm->real_stream;
+ r = BZ2_bzCompressEnd(strm);
+ free(strm);
+ lastrm->real_stream = NULL;
+ lastrm->valid = 0;
+ if (r != BZ_OK) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Failed to clean up compressor");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+
+#else
+static int
+compression_init_encoder_bzip2(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+
+ (void) level; /* UNUSED */
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ return (compression_unsupported_encoder(a, lastrm, "bzip2"));
+}
+#endif
+
+/*
+ * _7_LZMA1, _7_LZMA2 compressor.
+ */
+#if defined(HAVE_LZMA_H)
+static int
+compression_init_encoder_lzma(struct archive *a,
+ struct la_zstream *lastrm, int level, uint64_t filter_id)
+{
+ static const lzma_stream lzma_init_data = LZMA_STREAM_INIT;
+ lzma_stream *strm;
+ lzma_filter *lzmafilters;
+ lzma_options_lzma lzma_opt;
+ int r;
+
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ strm = calloc(1, sizeof(*strm) + sizeof(*lzmafilters) * 2);
+ if (strm == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate memory for lzma stream");
+ return (ARCHIVE_FATAL);
+ }
+ lzmafilters = (lzma_filter *)(strm+1);
+ if (level > 6)
+ level = 6;
+ if (lzma_lzma_preset(&lzma_opt, level)) {
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ENOMEM,
+ "Internal error initializing compression library");
+ return (ARCHIVE_FATAL);
+ }
+ lzmafilters[0].id = filter_id;
+ lzmafilters[0].options = &lzma_opt;
+ lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */
+
+ r = lzma_properties_size(&(lastrm->prop_size), lzmafilters);
+ if (r != LZMA_OK) {
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "lzma_properties_size failed");
+ return (ARCHIVE_FATAL);
+ }
+ if (lastrm->prop_size) {
+ lastrm->props = malloc(lastrm->prop_size);
+ if (lastrm->props == NULL) {
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ENOMEM,
+ "Cannot allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ r = lzma_properties_encode(lzmafilters, lastrm->props);
+ if (r != LZMA_OK) {
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "lzma_properties_encode failed");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ *strm = lzma_init_data;
+ r = lzma_raw_encoder(strm, lzmafilters);
+ switch (r) {
+ case LZMA_OK:
+ lastrm->real_stream = strm;
+ lastrm->valid = 1;
+ lastrm->code = compression_code_lzma;
+ lastrm->end = compression_end_lzma;
+ r = ARCHIVE_OK;
+ break;
+ case LZMA_MEM_ERROR:
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ENOMEM,
+ "Internal error initializing compression library: "
+ "Cannot allocate memory");
+ r = ARCHIVE_FATAL;
+ break;
+ default:
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ "It's a bug in liblzma");
+ r = ARCHIVE_FATAL;
+ break;
+ }
+ return (r);
+}
+
+static int
+compression_init_encoder_lzma1(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+ return compression_init_encoder_lzma(a, lastrm, level,
+ LZMA_FILTER_LZMA1);
+}
+
+static int
+compression_init_encoder_lzma2(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+ return compression_init_encoder_lzma(a, lastrm, level,
+ LZMA_FILTER_LZMA2);
+}
+
+static int
+compression_code_lzma(struct archive *a,
+ struct la_zstream *lastrm, enum la_zaction action)
+{
+ lzma_stream *strm;
+ int r;
+
+ strm = (lzma_stream *)lastrm->real_stream;
+ strm->next_in = lastrm->next_in;
+ strm->avail_in = lastrm->avail_in;
+ strm->total_in = lastrm->total_in;
+ strm->next_out = lastrm->next_out;
+ strm->avail_out = lastrm->avail_out;
+ strm->total_out = lastrm->total_out;
+ r = lzma_code(strm,
+ (action == ARCHIVE_Z_FINISH)? LZMA_FINISH: LZMA_RUN);
+ lastrm->next_in = strm->next_in;
+ lastrm->avail_in = strm->avail_in;
+ lastrm->total_in = strm->total_in;
+ lastrm->next_out = strm->next_out;
+ lastrm->avail_out = strm->avail_out;
+ lastrm->total_out = strm->total_out;
+ switch (r) {
+ case LZMA_OK:
+ /* Non-finishing case */
+ return (ARCHIVE_OK);
+ case LZMA_STREAM_END:
+ /* This return can only occur in finishing case. */
+ return (ARCHIVE_EOF);
+ case LZMA_MEMLIMIT_ERROR:
+ archive_set_error(a, ENOMEM,
+ "lzma compression error:"
+ " %ju MiB would have been needed",
+ (uintmax_t)((lzma_memusage(strm) + 1024 * 1024 -1)
+ / (1024 * 1024)));
+ return (ARCHIVE_FATAL);
+ default:
+ /* Any other return value indicates an error */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "lzma compression failed:"
+ " lzma_code() call returned status %d", r);
+ return (ARCHIVE_FATAL);
+ }
+}
+
+static int
+compression_end_lzma(struct archive *a, struct la_zstream *lastrm)
+{
+ lzma_stream *strm;
+
+ (void)a; /* UNUSED */
+ strm = (lzma_stream *)lastrm->real_stream;
+ lzma_end(strm);
+ free(strm);
+ lastrm->valid = 0;
+ lastrm->real_stream = NULL;
+ return (ARCHIVE_OK);
+}
+#else
+static int
+compression_init_encoder_lzma1(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+
+ (void) level; /* UNUSED */
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ return (compression_unsupported_encoder(a, lastrm, "lzma"));
+}
+static int
+compression_init_encoder_lzma2(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+
+ (void) level; /* UNUSED */
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ return (compression_unsupported_encoder(a, lastrm, "lzma"));
+}
+#endif
+
+/*
+ * _7_PPMD compressor.
+ */
+static void *
+ppmd_alloc(void *p, size_t size)
+{
+ (void)p;
+ return malloc(size);
+}
+static void
+ppmd_free(void *p, void *address)
+{
+ (void)p;
+ free(address);
+}
+static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free };
+static void
+ppmd_write(void *p, Byte b)
+{
+ struct archive_write *a = ((IByteOut *)p)->a;
+ struct _7zip *zip = (struct _7zip *)(a->format_data);
+ struct la_zstream *lastrm = &(zip->stream);
+ struct ppmd_stream *strm;
+
+ if (lastrm->avail_out) {
+ *lastrm->next_out++ = b;
+ lastrm->avail_out--;
+ lastrm->total_out++;
+ return;
+ }
+ strm = (struct ppmd_stream *)lastrm->real_stream;
+ if (strm->buff_ptr < strm->buff_end) {
+ *strm->buff_ptr++ = b;
+ strm->buff_bytes++;
+ }
+}
+
+static int
+compression_init_encoder_ppmd(struct archive *a,
+ struct la_zstream *lastrm, unsigned maxOrder, uint32_t msize)
+{
+ struct ppmd_stream *strm;
+ uint8_t *props;
+ int r;
+
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ strm = calloc(1, sizeof(*strm));
+ if (strm == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate memory for PPMd");
+ return (ARCHIVE_FATAL);
+ }
+ strm->buff = malloc(32);
+ if (strm->buff == NULL) {
+ free(strm);
+ archive_set_error(a, ENOMEM,
+ "Can't allocate memory for PPMd");
+ return (ARCHIVE_FATAL);
+ }
+ strm->buff_ptr = strm->buff;
+ strm->buff_end = strm->buff + 32;
+
+ props = malloc(1+4);
+ if (props == NULL) {
+ free(strm->buff);
+ free(strm);
+ archive_set_error(a, ENOMEM,
+ "Coludn't allocate memory for PPMd");
+ return (ARCHIVE_FATAL);
+ }
+ props[0] = maxOrder;
+ archive_le32enc(props+1, msize);
+ __archive_ppmd7_functions.Ppmd7_Construct(&strm->ppmd7_context);
+ r = __archive_ppmd7_functions.Ppmd7_Alloc(
+ &strm->ppmd7_context, msize, &g_szalloc);
+ if (r == 0) {
+ free(strm->buff);
+ free(strm);
+ free(props);
+ archive_set_error(a, ENOMEM,
+ "Coludn't allocate memory for PPMd");
+ return (ARCHIVE_FATAL);
+ }
+ __archive_ppmd7_functions.Ppmd7_Init(&(strm->ppmd7_context), maxOrder);
+ strm->byteout.a = (struct archive_write *)a;
+ strm->byteout.Write = ppmd_write;
+ strm->range_enc.Stream = &(strm->byteout);
+ __archive_ppmd7_functions.Ppmd7z_RangeEnc_Init(&(strm->range_enc));
+ strm->stat = 0;
+
+ lastrm->real_stream = strm;
+ lastrm->valid = 1;
+ lastrm->code = compression_code_ppmd;
+ lastrm->end = compression_end_ppmd;
+ lastrm->prop_size = 5;
+ lastrm->props = props;
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_code_ppmd(struct archive *a,
+ struct la_zstream *lastrm, enum la_zaction action)
+{
+ struct ppmd_stream *strm;
+
+ (void)a; /* UNUSED */
+
+ strm = (struct ppmd_stream *)lastrm->real_stream;
+
+ /* Copy encoded data if there are remaining bytes from previous call. */
+ if (strm->buff_bytes) {
+ uint8_t *p = strm->buff_ptr - strm->buff_bytes;
+ while (lastrm->avail_out && strm->buff_bytes) {
+ *lastrm->next_out++ = *p++;
+ lastrm->avail_out--;
+ lastrm->total_out++;
+ strm->buff_bytes--;
+ }
+ if (strm->buff_bytes)
+ return (ARCHIVE_OK);
+ if (strm->stat == 1)
+ return (ARCHIVE_EOF);
+ strm->buff_ptr = strm->buff;
+ }
+ while (lastrm->avail_in && lastrm->avail_out) {
+ __archive_ppmd7_functions.Ppmd7_EncodeSymbol(
+ &(strm->ppmd7_context), &(strm->range_enc),
+ *lastrm->next_in++);
+ lastrm->avail_in--;
+ lastrm->total_in++;
+ }
+ if (lastrm->avail_in == 0 && action == ARCHIVE_Z_FINISH) {
+ __archive_ppmd7_functions.Ppmd7z_RangeEnc_FlushData(
+ &(strm->range_enc));
+ strm->stat = 1;
+ /* Return EOF if there are no remaining bytes. */
+ if (strm->buff_bytes == 0)
+ return (ARCHIVE_EOF);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_end_ppmd(struct archive *a, struct la_zstream *lastrm)
+{
+ struct ppmd_stream *strm;
+
+ (void)a; /* UNUSED */
+
+ strm = (struct ppmd_stream *)lastrm->real_stream;
+ __archive_ppmd7_functions.Ppmd7_Free(&strm->ppmd7_context, &g_szalloc);
+ free(strm->buff);
+ free(strm);
+ lastrm->real_stream = NULL;
+ lastrm->valid = 0;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Universal compressor initializer.
+ */
+static int
+_7z_compression_init_encoder(struct archive_write *a, unsigned compression,
+ int compression_level)
+{
+ struct _7zip *zip;
+ int r;
+
+ zip = (struct _7zip *)a->format_data;
+ switch (compression) {
+ case _7Z_DEFLATE:
+ r = compression_init_encoder_deflate(
+ &(a->archive), &(zip->stream),
+ compression_level, 0);
+ break;
+ case _7Z_BZIP2:
+ r = compression_init_encoder_bzip2(
+ &(a->archive), &(zip->stream),
+ compression_level);
+ break;
+ case _7Z_LZMA1:
+ r = compression_init_encoder_lzma1(
+ &(a->archive), &(zip->stream),
+ compression_level);
+ break;
+ case _7Z_LZMA2:
+ r = compression_init_encoder_lzma2(
+ &(a->archive), &(zip->stream),
+ compression_level);
+ break;
+ case _7Z_PPMD:
+ r = compression_init_encoder_ppmd(
+ &(a->archive), &(zip->stream),
+ PPMD7_DEFAULT_ORDER, PPMD7_DEFAULT_MEM_SIZE);
+ break;
+ case _7Z_COPY:
+ default:
+ r = compression_init_encoder_copy(
+ &(a->archive), &(zip->stream));
+ break;
+ }
+ if (r == ARCHIVE_OK) {
+ zip->stream.total_in = 0;
+ zip->stream.next_out = zip->wbuff;
+ zip->stream.avail_out = sizeof(zip->wbuff);
+ zip->stream.total_out = 0;
+ }
+
+ return (r);
+}
+
+static int
+compression_code(struct archive *a, struct la_zstream *lastrm,
+ enum la_zaction action)
+{
+ if (lastrm->valid)
+ return (lastrm->code(a, lastrm, action));
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_end(struct archive *a, struct la_zstream *lastrm)
+{
+ if (lastrm->valid) {
+ lastrm->prop_size = 0;
+ free(lastrm->props);
+ lastrm->props = NULL;
+ return (lastrm->end(a, lastrm));
+ }
+ return (ARCHIVE_OK);
+}
+
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c
new file mode 100644
index 0000000000..9f17564c34
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c
@@ -0,0 +1,564 @@
+/*-
+ * Copyright (c) 2007 Kai Wang
+ * Copyright (c) 2007 Tim Kientzle
+ * 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
+ * in this position and unchanged.
+ * 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_ar.c 201108 2009-12-28 03:28:21Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+struct ar_w {
+ uint64_t entry_bytes_remaining;
+ uint64_t entry_padding;
+ int is_strtab;
+ int has_strtab;
+ char wrote_global_header;
+ char *strtab;
+};
+
+/*
+ * Define structure of the "ar" header.
+ */
+#define AR_name_offset 0
+#define AR_name_size 16
+#define AR_date_offset 16
+#define AR_date_size 12
+#define AR_uid_offset 28
+#define AR_uid_size 6
+#define AR_gid_offset 34
+#define AR_gid_size 6
+#define AR_mode_offset 40
+#define AR_mode_size 8
+#define AR_size_offset 48
+#define AR_size_size 10
+#define AR_fmag_offset 58
+#define AR_fmag_size 2
+
+static int archive_write_set_format_ar(struct archive_write *);
+static int archive_write_ar_header(struct archive_write *,
+ struct archive_entry *);
+static ssize_t archive_write_ar_data(struct archive_write *,
+ const void *buff, size_t s);
+static int archive_write_ar_free(struct archive_write *);
+static int archive_write_ar_close(struct archive_write *);
+static int archive_write_ar_finish_entry(struct archive_write *);
+static const char *ar_basename(const char *path);
+static int format_octal(int64_t v, char *p, int s);
+static int format_decimal(int64_t v, char *p, int s);
+
+int
+archive_write_set_format_ar_bsd(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_ar_bsd");
+ r = archive_write_set_format_ar(a);
+ if (r == ARCHIVE_OK) {
+ a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD;
+ a->archive.archive_format_name = "ar (BSD)";
+ }
+ return (r);
+}
+
+int
+archive_write_set_format_ar_svr4(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_ar_svr4");
+ r = archive_write_set_format_ar(a);
+ if (r == ARCHIVE_OK) {
+ a->archive.archive_format = ARCHIVE_FORMAT_AR_GNU;
+ a->archive.archive_format_name = "ar (GNU/SVR4)";
+ }
+ return (r);
+}
+
+/*
+ * Generic initialization.
+ */
+static int
+archive_write_set_format_ar(struct archive_write *a)
+{
+ struct ar_w *ar;
+
+ /* If someone else was already registered, unregister them. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ ar = (struct ar_w *)malloc(sizeof(*ar));
+ if (ar == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate ar data");
+ return (ARCHIVE_FATAL);
+ }
+ memset(ar, 0, sizeof(*ar));
+ a->format_data = ar;
+
+ a->format_name = "ar";
+ a->format_write_header = archive_write_ar_header;
+ a->format_write_data = archive_write_ar_data;
+ a->format_close = archive_write_ar_close;
+ a->format_free = archive_write_ar_free;
+ a->format_finish_entry = archive_write_ar_finish_entry;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_ar_header(struct archive_write *a, struct archive_entry *entry)
+{
+ int ret, append_fn;
+ char buff[60];
+ char *ss, *se;
+ struct ar_w *ar;
+ const char *pathname;
+ const char *filename;
+ int64_t size;
+
+ append_fn = 0;
+ ar = (struct ar_w *)a->format_data;
+ ar->is_strtab = 0;
+ filename = NULL;
+ size = archive_entry_size(entry);
+
+
+ /*
+ * Reject files with empty name.
+ */
+ pathname = archive_entry_pathname(entry);
+ if (pathname == NULL || *pathname == '\0') {
+ archive_set_error(&a->archive, EINVAL,
+ "Invalid filename");
+ return (ARCHIVE_WARN);
+ }
+
+ /*
+ * If we are now at the beginning of the archive,
+ * we need first write the ar global header.
+ */
+ if (!ar->wrote_global_header) {
+ __archive_write_output(a, "!<arch>\n", 8);
+ ar->wrote_global_header = 1;
+ }
+
+ memset(buff, ' ', 60);
+ strncpy(&buff[AR_fmag_offset], "`\n", 2);
+
+ if (strcmp(pathname, "/") == 0 ) {
+ /* Entry is archive symbol table in GNU format */
+ buff[AR_name_offset] = '/';
+ goto stat;
+ }
+ if (strcmp(pathname, "__.SYMDEF") == 0) {
+ /* Entry is archive symbol table in BSD format */
+ strncpy(buff + AR_name_offset, "__.SYMDEF", 9);
+ goto stat;
+ }
+ if (strcmp(pathname, "//") == 0) {
+ /*
+ * Entry is archive filename table, inform that we should
+ * collect strtab in next _data call.
+ */
+ ar->is_strtab = 1;
+ buff[AR_name_offset] = buff[AR_name_offset + 1] = '/';
+ /*
+ * For archive string table, only ar_size field should
+ * be set.
+ */
+ goto size;
+ }
+
+ /*
+ * Otherwise, entry is a normal archive member.
+ * Strip leading paths from filenames, if any.
+ */
+ if ((filename = ar_basename(pathname)) == NULL) {
+ /* Reject filenames with trailing "/" */
+ archive_set_error(&a->archive, EINVAL,
+ "Invalid filename");
+ return (ARCHIVE_WARN);
+ }
+
+ if (a->archive.archive_format == ARCHIVE_FORMAT_AR_GNU) {
+ /*
+ * SVR4/GNU variant use a "/" to mark then end of the filename,
+ * make it possible to have embedded spaces in the filename.
+ * So, the longest filename here (without extension) is
+ * actually 15 bytes.
+ */
+ if (strlen(filename) <= 15) {
+ strncpy(&buff[AR_name_offset],
+ filename, strlen(filename));
+ buff[AR_name_offset + strlen(filename)] = '/';
+ } else {
+ /*
+ * For filename longer than 15 bytes, GNU variant
+ * makes use of a string table and instead stores the
+ * offset of the real filename to in the ar_name field.
+ * The string table should have been written before.
+ */
+ if (ar->has_strtab <= 0) {
+ archive_set_error(&a->archive, EINVAL,
+ "Can't find string table");
+ return (ARCHIVE_WARN);
+ }
+
+ se = (char *)malloc(strlen(filename) + 3);
+ if (se == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate filename buffer");
+ return (ARCHIVE_FATAL);
+ }
+
+ strncpy(se, filename, strlen(filename));
+ strcpy(se + strlen(filename), "/\n");
+
+ ss = strstr(ar->strtab, se);
+ free(se);
+
+ if (ss == NULL) {
+ archive_set_error(&a->archive, EINVAL,
+ "Invalid string table");
+ return (ARCHIVE_WARN);
+ }
+
+ /*
+ * GNU variant puts "/" followed by digits into
+ * ar_name field. These digits indicates the real
+ * filename string's offset to the string table.
+ */
+ buff[AR_name_offset] = '/';
+ if (format_decimal(ss - ar->strtab,
+ buff + AR_name_offset + 1,
+ AR_name_size - 1)) {
+ archive_set_error(&a->archive, ERANGE,
+ "string table offset too large");
+ return (ARCHIVE_WARN);
+ }
+ }
+ } else if (a->archive.archive_format == ARCHIVE_FORMAT_AR_BSD) {
+ /*
+ * BSD variant: for any file name which is more than
+ * 16 chars or contains one or more embedded space(s), the
+ * string "#1/" followed by the ASCII length of the name is
+ * put into the ar_name field. The file size (stored in the
+ * ar_size field) is incremented by the length of the name.
+ * The name is then written immediately following the
+ * archive header.
+ */
+ if (strlen(filename) <= 16 && strchr(filename, ' ') == NULL) {
+ strncpy(&buff[AR_name_offset], filename, strlen(filename));
+ buff[AR_name_offset + strlen(filename)] = ' ';
+ }
+ else {
+ strncpy(buff + AR_name_offset, "#1/", 3);
+ if (format_decimal(strlen(filename),
+ buff + AR_name_offset + 3,
+ AR_name_size - 3)) {
+ archive_set_error(&a->archive, ERANGE,
+ "File name too long");
+ return (ARCHIVE_WARN);
+ }
+ append_fn = 1;
+ size += strlen(filename);
+ }
+ }
+
+stat:
+ if (format_decimal(archive_entry_mtime(entry), buff + AR_date_offset, AR_date_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "File modification time too large");
+ return (ARCHIVE_WARN);
+ }
+ if (format_decimal(archive_entry_uid(entry), buff + AR_uid_offset, AR_uid_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric user ID too large");
+ return (ARCHIVE_WARN);
+ }
+ if (format_decimal(archive_entry_gid(entry), buff + AR_gid_offset, AR_gid_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric group ID too large");
+ return (ARCHIVE_WARN);
+ }
+ if (format_octal(archive_entry_mode(entry), buff + AR_mode_offset, AR_mode_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric mode too large");
+ return (ARCHIVE_WARN);
+ }
+ /*
+ * Sanity Check: A non-pseudo archive member should always be
+ * a regular file.
+ */
+ if (filename != NULL && archive_entry_filetype(entry) != AE_IFREG) {
+ archive_set_error(&a->archive, EINVAL,
+ "Regular file required for non-pseudo member");
+ return (ARCHIVE_WARN);
+ }
+
+size:
+ if (format_decimal(size, buff + AR_size_offset, AR_size_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "File size out of range");
+ return (ARCHIVE_WARN);
+ }
+
+ ret = __archive_write_output(a, buff, 60);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ ar->entry_bytes_remaining = size;
+ ar->entry_padding = ar->entry_bytes_remaining % 2;
+
+ if (append_fn > 0) {
+ ret = __archive_write_output(a, filename, strlen(filename));
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ ar->entry_bytes_remaining -= strlen(filename);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+archive_write_ar_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct ar_w *ar;
+ int ret;
+
+ ar = (struct ar_w *)a->format_data;
+ if (s > ar->entry_bytes_remaining)
+ s = (size_t)ar->entry_bytes_remaining;
+
+ if (ar->is_strtab > 0) {
+ if (ar->has_strtab > 0) {
+ archive_set_error(&a->archive, EINVAL,
+ "More than one string tables exist");
+ return (ARCHIVE_WARN);
+ }
+
+ ar->strtab = (char *)malloc(s);
+ if (ar->strtab == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate strtab buffer");
+ return (ARCHIVE_FATAL);
+ }
+ strncpy(ar->strtab, buff, s);
+ ar->has_strtab = 1;
+ }
+
+ ret = __archive_write_output(a, buff, s);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+
+ ar->entry_bytes_remaining -= s;
+ return (s);
+}
+
+static int
+archive_write_ar_free(struct archive_write *a)
+{
+ struct ar_w *ar;
+
+ ar = (struct ar_w *)a->format_data;
+
+ if (ar == NULL)
+ return (ARCHIVE_OK);
+
+ if (ar->has_strtab > 0) {
+ free(ar->strtab);
+ ar->strtab = NULL;
+ }
+
+ free(ar);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_ar_close(struct archive_write *a)
+{
+ struct ar_w *ar;
+ int ret;
+
+ /*
+ * If we haven't written anything yet, we need to write
+ * the ar global header now to make it a valid ar archive.
+ */
+ ar = (struct ar_w *)a->format_data;
+ if (!ar->wrote_global_header) {
+ ar->wrote_global_header = 1;
+ ret = __archive_write_output(a, "!<arch>\n", 8);
+ return (ret);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_ar_finish_entry(struct archive_write *a)
+{
+ struct ar_w *ar;
+ int ret;
+
+ ar = (struct ar_w *)a->format_data;
+
+ if (ar->entry_bytes_remaining != 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Entry remaining bytes larger than 0");
+ return (ARCHIVE_WARN);
+ }
+
+ if (ar->entry_padding == 0) {
+ return (ARCHIVE_OK);
+ }
+
+ if (ar->entry_padding != 1) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Padding wrong size: %ju should be 1 or 0",
+ (uintmax_t)ar->entry_padding);
+ return (ARCHIVE_WARN);
+ }
+
+ ret = __archive_write_output(a, "\n", 1);
+ return (ret);
+}
+
+/*
+ * Format a number into the specified field using base-8.
+ * NB: This version is slightly different from the one in
+ * _ustar.c
+ */
+static int
+format_octal(int64_t v, char *p, int s)
+{
+ int len;
+ char *h;
+
+ len = s;
+ h = p;
+
+ /* Octal values can't be negative, so use 0. */
+ if (v < 0) {
+ while (len-- > 0)
+ *p++ = '0';
+ return (-1);
+ }
+
+ p += s; /* Start at the end and work backwards. */
+ do {
+ *--p = (char)('0' + (v & 7));
+ v >>= 3;
+ } while (--s > 0 && v > 0);
+
+ if (v == 0) {
+ memmove(h, p, len - s);
+ p = h + len - s;
+ while (s-- > 0)
+ *p++ = ' ';
+ return (0);
+ }
+ /* If it overflowed, fill field with max value. */
+ while (len-- > 0)
+ *p++ = '7';
+
+ return (-1);
+}
+
+/*
+ * Format a number into the specified field using base-10.
+ */
+static int
+format_decimal(int64_t v, char *p, int s)
+{
+ int len;
+ char *h;
+
+ len = s;
+ h = p;
+
+ /* Negative values in ar header are meaningless, so use 0. */
+ if (v < 0) {
+ while (len-- > 0)
+ *p++ = '0';
+ return (-1);
+ }
+
+ p += s;
+ do {
+ *--p = (char)('0' + (v % 10));
+ v /= 10;
+ } while (--s > 0 && v > 0);
+
+ if (v == 0) {
+ memmove(h, p, len - s);
+ p = h + len - s;
+ while (s-- > 0)
+ *p++ = ' ';
+ return (0);
+ }
+ /* If it overflowed, fill field with max value. */
+ while (len-- > 0)
+ *p++ = '9';
+
+ return (-1);
+}
+
+static const char *
+ar_basename(const char *path)
+{
+ const char *endp, *startp;
+
+ endp = path + strlen(path) - 1;
+ /*
+ * For filename with trailing slash(es), we return
+ * NULL indicating an error.
+ */
+ if (*endp == '/')
+ return (NULL);
+
+ /* Find the start of the base */
+ startp = endp;
+ while (startp > path && *(startp - 1) != '/')
+ startp--;
+
+ return (startp);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c
new file mode 100644
index 0000000000..4f3ce7d351
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c
@@ -0,0 +1,91 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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 (*setter)(struct archive *); } names[] =
+{
+ { "7zip", archive_write_set_format_7zip },
+ { "ar", archive_write_set_format_ar_bsd },
+ { "arbsd", archive_write_set_format_ar_bsd },
+ { "argnu", archive_write_set_format_ar_svr4 },
+ { "arsvr4", archive_write_set_format_ar_svr4 },
+ { "bsdtar", archive_write_set_format_pax_restricted },
+ { "cd9660", archive_write_set_format_iso9660 },
+ { "cpio", archive_write_set_format_cpio },
+ { "gnutar", archive_write_set_format_gnutar },
+ { "iso", archive_write_set_format_iso9660 },
+ { "iso9660", archive_write_set_format_iso9660 },
+ { "mtree", archive_write_set_format_mtree },
+ { "mtree-classic", archive_write_set_format_mtree_classic },
+ { "newc", archive_write_set_format_cpio_newc },
+ { "odc", archive_write_set_format_cpio },
+ { "oldtar", archive_write_set_format_v7tar },
+ { "pax", archive_write_set_format_pax },
+ { "paxr", archive_write_set_format_pax_restricted },
+ { "posix", archive_write_set_format_pax },
+ { "raw", archive_write_set_format_raw },
+ { "rpax", archive_write_set_format_pax_restricted },
+ { "shar", archive_write_set_format_shar },
+ { "shardump", archive_write_set_format_shar_dump },
+ { "ustar", archive_write_set_format_ustar },
+ { "v7tar", archive_write_set_format_v7tar },
+ { "v7", archive_write_set_format_v7tar },
+ { "xar", archive_write_set_format_xar },
+ { "zip", archive_write_set_format_zip },
+ { NULL, NULL }
+};
+
+int
+archive_write_set_format_by_name(struct archive *a, const char *name)
+{
+ int i;
+
+ for (i = 0; names[i].name != NULL; i++) {
+ if (strcmp(name, names[i].name) == 0)
+ return ((names[i].setter)(a));
+ }
+
+ archive_set_error(a, EINVAL, "No such format '%s'", name);
+ a->state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c
new file mode 100644
index 0000000000..352649365d
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c
@@ -0,0 +1,500 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2011-2012 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: head/lib/libarchive/archive_write_set_format_cpio.c 201170 2009-12-29 06:34:23Z kientzle $");
+
+#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
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+static ssize_t archive_write_cpio_data(struct archive_write *,
+ const void *buff, size_t s);
+static int archive_write_cpio_close(struct archive_write *);
+static int archive_write_cpio_free(struct archive_write *);
+static int archive_write_cpio_finish_entry(struct archive_write *);
+static int archive_write_cpio_header(struct archive_write *,
+ struct archive_entry *);
+static int archive_write_cpio_options(struct archive_write *,
+ const char *, const char *);
+static int format_octal(int64_t, void *, int);
+static int64_t format_octal_recursive(int64_t, char *, int);
+static int write_header(struct archive_write *, struct archive_entry *);
+
+struct cpio {
+ uint64_t entry_bytes_remaining;
+
+ int64_t ino_next;
+
+ struct { int64_t old; int new;} *ino_list;
+ size_t ino_list_size;
+ size_t ino_list_next;
+
+ struct archive_string_conv *opt_sconv;
+ struct archive_string_conv *sconv_default;
+ int init_default_conversion;
+};
+
+#define c_magic_offset 0
+#define c_magic_size 6
+#define c_dev_offset 6
+#define c_dev_size 6
+#define c_ino_offset 12
+#define c_ino_size 6
+#define c_mode_offset 18
+#define c_mode_size 6
+#define c_uid_offset 24
+#define c_uid_size 6
+#define c_gid_offset 30
+#define c_gid_size 6
+#define c_nlink_offset 36
+#define c_nlink_size 6
+#define c_rdev_offset 42
+#define c_rdev_size 6
+#define c_mtime_offset 48
+#define c_mtime_size 11
+#define c_namesize_offset 59
+#define c_namesize_size 6
+#define c_filesize_offset 65
+#define c_filesize_size 11
+
+/*
+ * Set output format to 'cpio' format.
+ */
+int
+archive_write_set_format_cpio(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct cpio *cpio;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_cpio");
+
+ /* If someone else was already registered, unregister them. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+ if (cpio == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
+ return (ARCHIVE_FATAL);
+ }
+ a->format_data = cpio;
+ a->format_name = "cpio";
+ a->format_options = archive_write_cpio_options;
+ a->format_write_header = archive_write_cpio_header;
+ a->format_write_data = archive_write_cpio_data;
+ a->format_finish_entry = archive_write_cpio_finish_entry;
+ a->format_close = archive_write_cpio_close;
+ a->format_free = archive_write_cpio_free;
+ a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX;
+ a->archive.archive_format_name = "POSIX cpio";
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_cpio_options(struct archive_write *a, const char *key,
+ const char *val)
+{
+ struct cpio *cpio = (struct cpio *)a->format_data;
+ int ret = ARCHIVE_FAILED;
+
+ if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s: hdrcharset option needs a character-set name",
+ a->format_name);
+ else {
+ cpio->opt_sconv = archive_string_conversion_to_charset(
+ &a->archive, val, 0);
+ if (cpio->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ }
+
+ /* 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);
+}
+
+/*
+ * Ino values are as long as 64 bits on some systems; cpio format
+ * only allows 18 bits and relies on the ino values to identify hardlinked
+ * files. So, we can't merely "hash" the ino numbers since collisions
+ * would corrupt the archive. Instead, we generate synthetic ino values
+ * to store in the archive and maintain a map of original ino values to
+ * synthetic ones so we can preserve hardlink information.
+ *
+ * TODO: Make this more efficient. It's not as bad as it looks (most
+ * files don't have any hardlinks and we don't do any work here for those),
+ * but it wouldn't be hard to do better.
+ *
+ * TODO: Work with dev/ino pairs here instead of just ino values.
+ */
+static int
+synthesize_ino_value(struct cpio *cpio, struct archive_entry *entry)
+{
+ int64_t ino = archive_entry_ino64(entry);
+ int ino_new;
+ size_t i;
+
+ /*
+ * If no index number was given, don't assign one. In
+ * particular, this handles the end-of-archive marker
+ * correctly by giving it a zero index value. (This is also
+ * why we start our synthetic index numbers with one below.)
+ */
+ if (ino == 0)
+ return (0);
+
+ /* Don't store a mapping if we don't need to. */
+ if (archive_entry_nlink(entry) < 2) {
+ return (int)(++cpio->ino_next);
+ }
+
+ /* Look up old ino; if we have it, this is a hardlink
+ * and we reuse the same value. */
+ for (i = 0; i < cpio->ino_list_next; ++i) {
+ if (cpio->ino_list[i].old == ino)
+ return (cpio->ino_list[i].new);
+ }
+
+ /* Assign a new index number. */
+ ino_new = (int)(++cpio->ino_next);
+
+ /* Ensure space for the new mapping. */
+ if (cpio->ino_list_size <= cpio->ino_list_next) {
+ size_t newsize = cpio->ino_list_size < 512
+ ? 512 : cpio->ino_list_size * 2;
+ void *newlist = realloc(cpio->ino_list,
+ sizeof(cpio->ino_list[0]) * newsize);
+ if (newlist == NULL)
+ return (-1);
+
+ cpio->ino_list_size = newsize;
+ cpio->ino_list = newlist;
+ }
+
+ /* Record and return the new value. */
+ cpio->ino_list[cpio->ino_list_next].old = ino;
+ cpio->ino_list[cpio->ino_list_next].new = ino_new;
+ ++cpio->ino_list_next;
+ return (ino_new);
+}
+
+
+static struct archive_string_conv *
+get_sconv(struct archive_write *a)
+{
+ struct cpio *cpio;
+ struct archive_string_conv *sconv;
+
+ cpio = (struct cpio *)a->format_data;
+ sconv = cpio->opt_sconv;
+ if (sconv == NULL) {
+ if (!cpio->init_default_conversion) {
+ cpio->sconv_default =
+ archive_string_default_conversion_for_write(
+ &(a->archive));
+ cpio->init_default_conversion = 1;
+ }
+ sconv = cpio->sconv_default;
+ }
+ return (sconv);
+}
+
+static int
+archive_write_cpio_header(struct archive_write *a, struct archive_entry *entry)
+{
+ const char *path;
+ size_t len;
+
+ if (archive_entry_filetype(entry) == 0) {
+ archive_set_error(&a->archive, -1, "Filetype required");
+ return (ARCHIVE_FAILED);
+ }
+
+ if (archive_entry_pathname_l(entry, &path, &len, get_sconv(a)) != 0
+ && errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ if (len == 0 || path == NULL || path[0] == '\0') {
+ archive_set_error(&a->archive, -1, "Pathname required");
+ return (ARCHIVE_FAILED);
+ }
+
+ if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) < 0) {
+ archive_set_error(&a->archive, -1, "Size required");
+ return (ARCHIVE_FAILED);
+ }
+ return write_header(a, entry);
+}
+
+static int
+write_header(struct archive_write *a, struct archive_entry *entry)
+{
+ struct cpio *cpio;
+ const char *p, *path;
+ int pathlength, ret, ret_final;
+ int64_t ino;
+ char h[76];
+ struct archive_string_conv *sconv;
+ struct archive_entry *entry_main;
+ size_t len;
+
+ cpio = (struct cpio *)a->format_data;
+ ret_final = ARCHIVE_OK;
+ sconv = get_sconv(a);
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Make sure the path separators in pahtname, hardlink and symlink
+ * are all slash '/', not the Windows path separator '\'. */
+ entry_main = __la_win_entry_in_posix_pathseparator(entry);
+ if (entry_main == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ustar data");
+ return(ARCHIVE_FATAL);
+ }
+ if (entry != entry_main)
+ entry = entry_main;
+ else
+ entry_main = NULL;
+#else
+ entry_main = NULL;
+#endif
+
+ ret = archive_entry_pathname_l(entry, &path, &len, sconv);
+ if (ret != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate pathname '%s' to %s",
+ archive_entry_pathname(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret_final = ARCHIVE_WARN;
+ }
+ /* Include trailing null. */
+ pathlength = (int)len + 1;
+
+ memset(h, 0, sizeof(h));
+ format_octal(070707, h + c_magic_offset, c_magic_size);
+ format_octal(archive_entry_dev(entry), h + c_dev_offset, c_dev_size);
+
+ ino = synthesize_ino_value(cpio, entry);
+ if (ino < 0) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for ino translation table");
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ } else if (ino > 0777777) {
+ archive_set_error(&a->archive, ERANGE,
+ "Too many files for this cpio format");
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ format_octal(ino & 0777777, h + c_ino_offset, c_ino_size);
+
+ /* TODO: Set ret_final to ARCHIVE_WARN if any of these overflow. */
+ format_octal(archive_entry_mode(entry), h + c_mode_offset, c_mode_size);
+ format_octal(archive_entry_uid(entry), h + c_uid_offset, c_uid_size);
+ format_octal(archive_entry_gid(entry), h + c_gid_offset, c_gid_size);
+ format_octal(archive_entry_nlink(entry), h + c_nlink_offset, c_nlink_size);
+ if (archive_entry_filetype(entry) == AE_IFBLK
+ || archive_entry_filetype(entry) == AE_IFCHR)
+ format_octal(archive_entry_dev(entry), h + c_rdev_offset, c_rdev_size);
+ else
+ format_octal(0, h + c_rdev_offset, c_rdev_size);
+ format_octal(archive_entry_mtime(entry), h + c_mtime_offset, c_mtime_size);
+ format_octal(pathlength, h + c_namesize_offset, c_namesize_size);
+
+ /* Non-regular files don't store bodies. */
+ if (archive_entry_filetype(entry) != AE_IFREG)
+ archive_entry_set_size(entry, 0);
+
+ /* Symlinks get the link written as the body of the entry. */
+ ret = archive_entry_symlink_l(entry, &p, &len, sconv);
+ if (ret != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s",
+ archive_entry_symlink(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret_final = ARCHIVE_WARN;
+ }
+ if (len > 0 && p != NULL && *p != '\0')
+ ret = format_octal(strlen(p), h + c_filesize_offset,
+ c_filesize_size);
+ else
+ ret = format_octal(archive_entry_size(entry),
+ h + c_filesize_offset, c_filesize_size);
+ if (ret) {
+ archive_set_error(&a->archive, ERANGE,
+ "File is too large for cpio format.");
+ ret_final = ARCHIVE_FAILED;
+ goto exit_write_header;
+ }
+
+ ret = __archive_write_output(a, h, sizeof(h));
+ if (ret != ARCHIVE_OK) {
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+
+ ret = __archive_write_output(a, path, pathlength);
+ if (ret != ARCHIVE_OK) {
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+
+ cpio->entry_bytes_remaining = archive_entry_size(entry);
+
+ /* Write the symlink now. */
+ if (p != NULL && *p != '\0') {
+ ret = __archive_write_output(a, p, strlen(p));
+ if (ret != ARCHIVE_OK) {
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ }
+exit_write_header:
+ if (entry_main)
+ archive_entry_free(entry_main);
+ return (ret_final);
+}
+
+static ssize_t
+archive_write_cpio_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct cpio *cpio;
+ int ret;
+
+ cpio = (struct cpio *)a->format_data;
+ if (s > cpio->entry_bytes_remaining)
+ s = (size_t)cpio->entry_bytes_remaining;
+
+ ret = __archive_write_output(a, buff, s);
+ cpio->entry_bytes_remaining -= s;
+ if (ret >= 0)
+ return (s);
+ else
+ return (ret);
+}
+
+/*
+ * Format a number into the specified field.
+ */
+static int
+format_octal(int64_t v, void *p, int digits)
+{
+ int64_t max;
+ int ret;
+
+ max = (((int64_t)1) << (digits * 3)) - 1;
+ if (v >= 0 && v <= max) {
+ format_octal_recursive(v, (char *)p, digits);
+ ret = 0;
+ } else {
+ format_octal_recursive(max, (char *)p, digits);
+ ret = -1;
+ }
+ return (ret);
+}
+
+static int64_t
+format_octal_recursive(int64_t v, char *p, int s)
+{
+ if (s == 0)
+ return (v);
+ v = format_octal_recursive(v, p+1, s-1);
+ *p = '0' + ((char)v & 7);
+ return (v >> 3);
+}
+
+static int
+archive_write_cpio_close(struct archive_write *a)
+{
+ int er;
+ struct archive_entry *trailer;
+
+ trailer = archive_entry_new2(NULL);
+ /* nlink = 1 here for GNU cpio compat. */
+ archive_entry_set_nlink(trailer, 1);
+ archive_entry_set_size(trailer, 0);
+ archive_entry_set_pathname(trailer, "TRAILER!!!");
+ er = write_header(a, trailer);
+ archive_entry_free(trailer);
+ return (er);
+}
+
+static int
+archive_write_cpio_free(struct archive_write *a)
+{
+ struct cpio *cpio;
+
+ cpio = (struct cpio *)a->format_data;
+ free(cpio->ino_list);
+ free(cpio);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_cpio_finish_entry(struct archive_write *a)
+{
+ struct cpio *cpio;
+
+ cpio = (struct cpio *)a->format_data;
+ return (__archive_write_nulls(a,
+ (size_t)cpio->entry_bytes_remaining));
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c
new file mode 100644
index 0000000000..a9bfa808cc
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c
@@ -0,0 +1,458 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2006 Rudolf Marek SYSGO s.r.o.
+ * Copyright (c) 2011-2012 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: head/lib/libarchive/archive_write_set_format_cpio_newc.c 201160 2009-12-29 05:41:57Z kientzle $");
+
+#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
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+static ssize_t archive_write_newc_data(struct archive_write *,
+ const void *buff, size_t s);
+static int archive_write_newc_close(struct archive_write *);
+static int archive_write_newc_free(struct archive_write *);
+static int archive_write_newc_finish_entry(struct archive_write *);
+static int archive_write_newc_header(struct archive_write *,
+ struct archive_entry *);
+static int archive_write_newc_options(struct archive_write *,
+ const char *, const char *);
+static int format_hex(int64_t, void *, int);
+static int64_t format_hex_recursive(int64_t, char *, int);
+static int write_header(struct archive_write *, struct archive_entry *);
+
+struct cpio {
+ uint64_t entry_bytes_remaining;
+ int padding;
+
+ struct archive_string_conv *opt_sconv;
+ struct archive_string_conv *sconv_default;
+ int init_default_conversion;
+};
+
+#define c_magic_offset 0
+#define c_magic_size 6
+#define c_ino_offset 6
+#define c_ino_size 8
+#define c_mode_offset 14
+#define c_mode_size 8
+#define c_uid_offset 22
+#define c_uid_size 8
+#define c_gid_offset 30
+#define c_gid_size 8
+#define c_nlink_offset 38
+#define c_nlink_size 8
+#define c_mtime_offset 46
+#define c_mtime_size 8
+#define c_filesize_offset 54
+#define c_filesize_size 8
+#define c_devmajor_offset 62
+#define c_devmajor_size 8
+#define c_devminor_offset 70
+#define c_devminor_size 8
+#define c_rdevmajor_offset 78
+#define c_rdevmajor_size 8
+#define c_rdevminor_offset 86
+#define c_rdevminor_size 8
+#define c_namesize_offset 94
+#define c_namesize_size 8
+#define c_checksum_offset 102
+#define c_checksum_size 8
+#define c_header_size 110
+
+/* Logic trick: difference between 'n' and next multiple of 4 */
+#define PAD4(n) (3 & (1 + ~(n)))
+
+/*
+ * Set output format to 'cpio' format.
+ */
+int
+archive_write_set_format_cpio_newc(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct cpio *cpio;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_cpio_newc");
+
+ /* If someone else was already registered, unregister them. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ cpio = (struct cpio *)malloc(sizeof(*cpio));
+ if (cpio == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
+ return (ARCHIVE_FATAL);
+ }
+ memset(cpio, 0, sizeof(*cpio));
+ a->format_data = cpio;
+ a->format_name = "cpio";
+ a->format_options = archive_write_newc_options;
+ a->format_write_header = archive_write_newc_header;
+ a->format_write_data = archive_write_newc_data;
+ a->format_finish_entry = archive_write_newc_finish_entry;
+ a->format_close = archive_write_newc_close;
+ a->format_free = archive_write_newc_free;
+ a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC;
+ a->archive.archive_format_name = "SVR4 cpio nocrc";
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_newc_options(struct archive_write *a, const char *key,
+ const char *val)
+{
+ struct cpio *cpio = (struct cpio *)a->format_data;
+ int ret = ARCHIVE_FAILED;
+
+ if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s: hdrcharset option needs a character-set name",
+ a->format_name);
+ else {
+ cpio->opt_sconv = archive_string_conversion_to_charset(
+ &a->archive, val, 0);
+ if (cpio->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ }
+
+ /* 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 struct archive_string_conv *
+get_sconv(struct archive_write *a)
+{
+ struct cpio *cpio;
+ struct archive_string_conv *sconv;
+
+ cpio = (struct cpio *)a->format_data;
+ sconv = cpio->opt_sconv;
+ if (sconv == NULL) {
+ if (!cpio->init_default_conversion) {
+ cpio->sconv_default =
+ archive_string_default_conversion_for_write(
+ &(a->archive));
+ cpio->init_default_conversion = 1;
+ }
+ sconv = cpio->sconv_default;
+ }
+ return (sconv);
+}
+
+static int
+archive_write_newc_header(struct archive_write *a, struct archive_entry *entry)
+{
+ const char *path;
+ size_t len;
+
+ if (archive_entry_filetype(entry) == 0) {
+ archive_set_error(&a->archive, -1, "Filetype required");
+ return (ARCHIVE_FAILED);
+ }
+
+ if (archive_entry_pathname_l(entry, &path, &len, get_sconv(a)) != 0
+ && errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ if (len == 0 || path == NULL || path[0] == '\0') {
+ archive_set_error(&a->archive, -1, "Pathname required");
+ return (ARCHIVE_FAILED);
+ }
+
+ if (archive_entry_hardlink(entry) == NULL
+ && (!archive_entry_size_is_set(entry) || archive_entry_size(entry) < 0)) {
+ archive_set_error(&a->archive, -1, "Size required");
+ return (ARCHIVE_FAILED);
+ }
+ return write_header(a, entry);
+}
+
+static int
+write_header(struct archive_write *a, struct archive_entry *entry)
+{
+ int64_t ino;
+ struct cpio *cpio;
+ const char *p, *path;
+ int pathlength, ret, ret_final;
+ char h[c_header_size];
+ struct archive_string_conv *sconv;
+ struct archive_entry *entry_main;
+ size_t len;
+ int pad;
+
+ cpio = (struct cpio *)a->format_data;
+ ret_final = ARCHIVE_OK;
+ sconv = get_sconv(a);
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Make sure the path separators in pahtname, hardlink and symlink
+ * are all slash '/', not the Windows path separator '\'. */
+ entry_main = __la_win_entry_in_posix_pathseparator(entry);
+ if (entry_main == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ustar data");
+ return(ARCHIVE_FATAL);
+ }
+ if (entry != entry_main)
+ entry = entry_main;
+ else
+ entry_main = NULL;
+#else
+ entry_main = NULL;
+#endif
+
+ ret = archive_entry_pathname_l(entry, &path, &len, sconv);
+ if (ret != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate pathname '%s' to %s",
+ archive_entry_pathname(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret_final = ARCHIVE_WARN;
+ }
+ pathlength = (int)len + 1; /* Include trailing null. */
+
+ memset(h, 0, c_header_size);
+ format_hex(0x070701, h + c_magic_offset, c_magic_size);
+ format_hex(archive_entry_devmajor(entry), h + c_devmajor_offset,
+ c_devmajor_size);
+ format_hex(archive_entry_devminor(entry), h + c_devminor_offset,
+ c_devminor_size);
+
+ ino = archive_entry_ino64(entry);
+ if (ino > 0xffffffff) {
+ archive_set_error(&a->archive, ERANGE,
+ "large inode number truncated");
+ ret_final = ARCHIVE_WARN;
+ }
+
+ /* TODO: Set ret_final to ARCHIVE_WARN if any of these overflow. */
+ format_hex(ino & 0xffffffff, h + c_ino_offset, c_ino_size);
+ format_hex(archive_entry_mode(entry), h + c_mode_offset, c_mode_size);
+ format_hex(archive_entry_uid(entry), h + c_uid_offset, c_uid_size);
+ format_hex(archive_entry_gid(entry), h + c_gid_offset, c_gid_size);
+ format_hex(archive_entry_nlink(entry), h + c_nlink_offset, c_nlink_size);
+ if (archive_entry_filetype(entry) == AE_IFBLK
+ || archive_entry_filetype(entry) == AE_IFCHR) {
+ format_hex(archive_entry_rdevmajor(entry), h + c_rdevmajor_offset, c_rdevmajor_size);
+ format_hex(archive_entry_rdevminor(entry), h + c_rdevminor_offset, c_rdevminor_size);
+ } else {
+ format_hex(0, h + c_rdevmajor_offset, c_rdevmajor_size);
+ format_hex(0, h + c_rdevminor_offset, c_rdevminor_size);
+ }
+ format_hex(archive_entry_mtime(entry), h + c_mtime_offset, c_mtime_size);
+ format_hex(pathlength, h + c_namesize_offset, c_namesize_size);
+ format_hex(0, h + c_checksum_offset, c_checksum_size);
+
+ /* Non-regular files don't store bodies. */
+ if (archive_entry_filetype(entry) != AE_IFREG)
+ archive_entry_set_size(entry, 0);
+
+ /* Symlinks get the link written as the body of the entry. */
+ ret = archive_entry_symlink_l(entry, &p, &len, sconv);
+ if (ret != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Likname");
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s",
+ archive_entry_symlink(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret_final = ARCHIVE_WARN;
+ }
+ if (len > 0 && p != NULL && *p != '\0')
+ ret = format_hex(strlen(p), h + c_filesize_offset,
+ c_filesize_size);
+ else
+ ret = format_hex(archive_entry_size(entry),
+ h + c_filesize_offset, c_filesize_size);
+ if (ret) {
+ archive_set_error(&a->archive, ERANGE,
+ "File is too large for this format.");
+ ret_final = ARCHIVE_FAILED;
+ goto exit_write_header;
+ }
+
+ ret = __archive_write_output(a, h, c_header_size);
+ if (ret != ARCHIVE_OK) {
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+
+ /* Pad pathname to even length. */
+ ret = __archive_write_output(a, path, pathlength);
+ if (ret != ARCHIVE_OK) {
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ pad = PAD4(pathlength + c_header_size);
+ if (pad) {
+ ret = __archive_write_output(a, "\0\0\0", pad);
+ if (ret != ARCHIVE_OK) {
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ }
+
+ cpio->entry_bytes_remaining = archive_entry_size(entry);
+ cpio->padding = (int)PAD4(cpio->entry_bytes_remaining);
+
+ /* Write the symlink now. */
+ if (p != NULL && *p != '\0') {
+ ret = __archive_write_output(a, p, strlen(p));
+ if (ret != ARCHIVE_OK) {
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ pad = PAD4(strlen(p));
+ ret = __archive_write_output(a, "\0\0\0", pad);
+ if (ret != ARCHIVE_OK) {
+ ret_final = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ }
+exit_write_header:
+ if (entry_main)
+ archive_entry_free(entry_main);
+ return (ret_final);
+}
+
+static ssize_t
+archive_write_newc_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct cpio *cpio;
+ int ret;
+
+ cpio = (struct cpio *)a->format_data;
+ if (s > cpio->entry_bytes_remaining)
+ s = (size_t)cpio->entry_bytes_remaining;
+
+ ret = __archive_write_output(a, buff, s);
+ cpio->entry_bytes_remaining -= s;
+ if (ret >= 0)
+ return (s);
+ else
+ return (ret);
+}
+
+/*
+ * Format a number into the specified field.
+ */
+static int
+format_hex(int64_t v, void *p, int digits)
+{
+ int64_t max;
+ int ret;
+
+ max = (((int64_t)1) << (digits * 4)) - 1;
+ if (v >= 0 && v <= max) {
+ format_hex_recursive(v, (char *)p, digits);
+ ret = 0;
+ } else {
+ format_hex_recursive(max, (char *)p, digits);
+ ret = -1;
+ }
+ return (ret);
+}
+
+static int64_t
+format_hex_recursive(int64_t v, char *p, int s)
+{
+ if (s == 0)
+ return (v);
+ v = format_hex_recursive(v, p+1, s-1);
+ *p = "0123456789abcdef"[v & 0xf];
+ return (v >> 4);
+}
+
+static int
+archive_write_newc_close(struct archive_write *a)
+{
+ int er;
+ struct archive_entry *trailer;
+
+ trailer = archive_entry_new();
+ archive_entry_set_nlink(trailer, 1);
+ archive_entry_set_size(trailer, 0);
+ archive_entry_set_pathname(trailer, "TRAILER!!!");
+ /* Bypass the required data checks. */
+ er = write_header(a, trailer);
+ archive_entry_free(trailer);
+ return (er);
+}
+
+static int
+archive_write_newc_free(struct archive_write *a)
+{
+ struct cpio *cpio;
+
+ cpio = (struct cpio *)a->format_data;
+ free(cpio);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_newc_finish_entry(struct archive_write *a)
+{
+ struct cpio *cpio;
+
+ cpio = (struct cpio *)a->format_data;
+ return (__archive_write_nulls(a,
+ (size_t)cpio->entry_bytes_remaining + cpio->padding));
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_gnutar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_gnutar.c
new file mode 100644
index 0000000000..13942c132b
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_gnutar.c
@@ -0,0 +1,761 @@
+/*-
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * Author: Jonas Gastal <jgastal@profusion.mobi>
+ * Copyright (c) 2011-2012 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: head/lib/libarchive/archive_write_set_format_gnu_tar.c 191579 2009-04-27 18:35:03Z gastal $");
+
+
+#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
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+struct gnutar {
+ uint64_t entry_bytes_remaining;
+ uint64_t entry_padding;
+ const char * linkname;
+ size_t linkname_length;
+ const char * pathname;
+ size_t pathname_length;
+ const char * uname;
+ size_t uname_length;
+ const char * gname;
+ size_t gname_length;
+ struct archive_string_conv *opt_sconv;
+ struct archive_string_conv *sconv_default;
+ int init_default_conversion;
+};
+
+/*
+ * Define structure of GNU tar header.
+ */
+#define GNUTAR_name_offset 0
+#define GNUTAR_name_size 100
+#define GNUTAR_mode_offset 100
+#define GNUTAR_mode_size 7
+#define GNUTAR_mode_max_size 8
+#define GNUTAR_uid_offset 108
+#define GNUTAR_uid_size 7
+#define GNUTAR_uid_max_size 8
+#define GNUTAR_gid_offset 116
+#define GNUTAR_gid_size 7
+#define GNUTAR_gid_max_size 8
+#define GNUTAR_size_offset 124
+#define GNUTAR_size_size 11
+#define GNUTAR_size_max_size 12
+#define GNUTAR_mtime_offset 136
+#define GNUTAR_mtime_size 11
+#define GNUTAR_mtime_max_size 11
+#define GNUTAR_checksum_offset 148
+#define GNUTAR_checksum_size 8
+#define GNUTAR_typeflag_offset 156
+#define GNUTAR_typeflag_size 1
+#define GNUTAR_linkname_offset 157
+#define GNUTAR_linkname_size 100
+#define GNUTAR_magic_offset 257
+#define GNUTAR_magic_size 6
+#define GNUTAR_version_offset 263
+#define GNUTAR_version_size 2
+#define GNUTAR_uname_offset 265
+#define GNUTAR_uname_size 32
+#define GNUTAR_gname_offset 297
+#define GNUTAR_gname_size 32
+#define GNUTAR_rdevmajor_offset 329
+#define GNUTAR_rdevmajor_size 6
+#define GNUTAR_rdevmajor_max_size 8
+#define GNUTAR_rdevminor_offset 337
+#define GNUTAR_rdevminor_size 6
+#define GNUTAR_rdevminor_max_size 8
+
+/*
+ * A filled-in copy of the header for initialization.
+ */
+static const char template_header[] = {
+ /* name: 100 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,
+ /* Mode, null termination: 8 bytes */
+ '0','0','0','0','0','0', '0','\0',
+ /* uid, null termination: 8 bytes */
+ '0','0','0','0','0','0', '0','\0',
+ /* gid, null termination: 8 bytes */
+ '0','0','0','0','0','0', '0','\0',
+ /* size, space termation: 12 bytes */
+ '0','0','0','0','0','0','0','0','0','0','0', '\0',
+ /* mtime, space termation: 12 bytes */
+ '0','0','0','0','0','0','0','0','0','0','0', '\0',
+ /* Initial checksum value: 8 spaces */
+ ' ',' ',' ',' ',' ',' ',' ',' ',
+ /* Typeflag: 1 byte */
+ '0', /* '0' = regular file */
+ /* Linkname: 100 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,
+ /* Magic: 8 bytes */
+ 'u','s','t','a','r',' ', ' ','\0',
+ /* Uname: 32 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ /* Gname: 32 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ /* rdevmajor + null padding: 8 bytes */
+ '\0','\0','\0','\0','\0','\0', '\0','\0',
+ /* rdevminor + null padding: 8 bytes */
+ '\0','\0','\0','\0','\0','\0', '\0','\0',
+ /* Padding: 167 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0
+};
+
+static int archive_write_gnutar_options(struct archive_write *,
+ const char *, const char *);
+static int archive_format_gnutar_header(struct archive_write *, char h[512],
+ struct archive_entry *, int tartype);
+static int archive_write_gnutar_header(struct archive_write *,
+ struct archive_entry *entry);
+static ssize_t archive_write_gnutar_data(struct archive_write *a, const void *buff,
+ size_t s);
+static int archive_write_gnutar_free(struct archive_write *);
+static int archive_write_gnutar_close(struct archive_write *);
+static int archive_write_gnutar_finish_entry(struct archive_write *);
+static int format_256(int64_t, char *, int);
+static int format_number(int64_t, char *, int size, int maxsize);
+static int format_octal(int64_t, char *, int);
+
+/*
+ * Set output format to 'GNU tar' format.
+ */
+int
+archive_write_set_format_gnutar(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct gnutar *gnutar;
+
+ gnutar = (struct gnutar *)calloc(1, sizeof(*gnutar));
+ if (gnutar == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate gnutar data");
+ return (ARCHIVE_FATAL);
+ }
+ a->format_data = gnutar;
+ a->format_name = "gnutar";
+ a->format_options = archive_write_gnutar_options;
+ a->format_write_header = archive_write_gnutar_header;
+ a->format_write_data = archive_write_gnutar_data;
+ a->format_close = archive_write_gnutar_close;
+ a->format_free = archive_write_gnutar_free;
+ a->format_finish_entry = archive_write_gnutar_finish_entry;
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_GNUTAR;
+ a->archive.archive_format_name = "GNU tar";
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_gnutar_options(struct archive_write *a, const char *key,
+ const char *val)
+{
+ struct gnutar *gnutar = (struct gnutar *)a->format_data;
+ int ret = ARCHIVE_FAILED;
+
+ if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s: hdrcharset option needs a character-set name",
+ a->format_name);
+ else {
+ gnutar->opt_sconv = archive_string_conversion_to_charset(
+ &a->archive, val, 0);
+ if (gnutar->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ }
+
+ /* 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
+archive_write_gnutar_close(struct archive_write *a)
+{
+ return (__archive_write_nulls(a, 512*2));
+}
+
+static int
+archive_write_gnutar_free(struct archive_write *a)
+{
+ struct gnutar *gnutar;
+
+ gnutar = (struct gnutar *)a->format_data;
+ free(gnutar);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_gnutar_finish_entry(struct archive_write *a)
+{
+ struct gnutar *gnutar;
+ int ret;
+
+ gnutar = (struct gnutar *)a->format_data;
+ ret = __archive_write_nulls(a, (size_t)
+ (gnutar->entry_bytes_remaining + gnutar->entry_padding));
+ gnutar->entry_bytes_remaining = gnutar->entry_padding = 0;
+ return (ret);
+}
+
+static ssize_t
+archive_write_gnutar_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct gnutar *gnutar;
+ int ret;
+
+ gnutar = (struct gnutar *)a->format_data;
+ if (s > gnutar->entry_bytes_remaining)
+ s = (size_t)gnutar->entry_bytes_remaining;
+ ret = __archive_write_output(a, buff, s);
+ gnutar->entry_bytes_remaining -= s;
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ return (s);
+}
+
+static int
+archive_write_gnutar_header(struct archive_write *a,
+ struct archive_entry *entry)
+{
+ char buff[512];
+ int r, ret, ret2 = ARCHIVE_OK;
+ int tartype;
+ struct gnutar *gnutar;
+ struct archive_string_conv *sconv;
+ struct archive_entry *entry_main;
+
+ gnutar = (struct gnutar *)a->format_data;
+
+ /* Setup default string conversion. */
+ if (gnutar->opt_sconv == NULL) {
+ if (!gnutar->init_default_conversion) {
+ gnutar->sconv_default =
+ archive_string_default_conversion_for_write(
+ &(a->archive));
+ gnutar->init_default_conversion = 1;
+ }
+ sconv = gnutar->sconv_default;
+ } else
+ sconv = gnutar->opt_sconv;
+
+ /* Only regular files (not hardlinks) have data. */
+ if (archive_entry_hardlink(entry) != NULL ||
+ archive_entry_symlink(entry) != NULL ||
+ !(archive_entry_filetype(entry) == AE_IFREG))
+ archive_entry_set_size(entry, 0);
+
+ if (AE_IFDIR == archive_entry_filetype(entry)) {
+ const char *p;
+ size_t path_length;
+ /*
+ * Ensure a trailing '/'. Modify the entry so
+ * the client sees the change.
+ */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ const wchar_t *wp;
+
+ wp = archive_entry_pathname_w(entry);
+ if (wp != NULL && wp[wcslen(wp) -1] != L'/') {
+ struct archive_wstring ws;
+
+ archive_string_init(&ws);
+ path_length = wcslen(wp);
+ if (archive_wstring_ensure(&ws,
+ path_length + 2) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ustar data");
+ archive_wstring_free(&ws);
+ return(ARCHIVE_FATAL);
+ }
+ /* Should we keep '\' ? */
+ if (wp[path_length -1] == L'\\')
+ path_length--;
+ archive_wstrncpy(&ws, wp, path_length);
+ archive_wstrappend_wchar(&ws, L'/');
+ archive_entry_copy_pathname_w(entry, ws.s);
+ archive_wstring_free(&ws);
+ p = NULL;
+ } else
+#endif
+ p = archive_entry_pathname(entry);
+ /*
+ * On Windows, this is a backup operation just in
+ * case getting WCS failed. On POSIX, this is a
+ * normal operation.
+ */
+ if (p != NULL && p[strlen(p) - 1] != '/') {
+ struct archive_string as;
+
+ archive_string_init(&as);
+ path_length = strlen(p);
+ if (archive_string_ensure(&as,
+ path_length + 2) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ustar data");
+ archive_string_free(&as);
+ return(ARCHIVE_FATAL);
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* NOTE: This might break the pathname
+ * if the current code page is CP932 and
+ * the pathname includes a character '\'
+ * as a part of its multibyte pathname. */
+ if (p[strlen(p) -1] == '\\')
+ path_length--;
+ else
+#endif
+ archive_strncpy(&as, p, path_length);
+ archive_strappend_char(&as, '/');
+ archive_entry_copy_pathname(entry, as.s);
+ archive_string_free(&as);
+ }
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Make sure the path separators in pahtname, hardlink and symlink
+ * are all slash '/', not the Windows path separator '\'. */
+ entry_main = __la_win_entry_in_posix_pathseparator(entry);
+ if (entry_main == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ustar data");
+ return(ARCHIVE_FATAL);
+ }
+ if (entry != entry_main)
+ entry = entry_main;
+ else
+ entry_main = NULL;
+#else
+ entry_main = NULL;
+#endif
+ r = archive_entry_pathname_l(entry, &(gnutar->pathname),
+ &(gnutar->pathname_length), sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathame");
+ ret = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate pathname '%s' to %s",
+ archive_entry_pathname(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret2 = ARCHIVE_WARN;
+ }
+ r = archive_entry_uname_l(entry, &(gnutar->uname),
+ &(gnutar->uname_length), sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Uname");
+ ret = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate uname '%s' to %s",
+ archive_entry_uname(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret2 = ARCHIVE_WARN;
+ }
+ r = archive_entry_gname_l(entry, &(gnutar->gname),
+ &(gnutar->gname_length), sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Gname");
+ ret = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate gname '%s' to %s",
+ archive_entry_gname(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret2 = ARCHIVE_WARN;
+ }
+
+ /* If linkname is longer than 100 chars we need to add a 'K' header. */
+ r = archive_entry_hardlink_l(entry, &(gnutar->linkname),
+ &(gnutar->linkname_length), sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ ret = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s",
+ archive_entry_hardlink(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret2 = ARCHIVE_WARN;
+ }
+ if (gnutar->linkname_length == 0) {
+ r = archive_entry_symlink_l(entry, &(gnutar->linkname),
+ &(gnutar->linkname_length), sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ ret = ARCHIVE_FATAL;
+ goto exit_write_header;
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s",
+ archive_entry_hardlink(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret2 = ARCHIVE_WARN;
+ }
+ }
+ if (gnutar->linkname_length > GNUTAR_linkname_size) {
+ size_t todo = gnutar->linkname_length;
+ struct archive_entry *temp = archive_entry_new2(&a->archive);
+
+ /* Uname/gname here don't really matter since no one reads them;
+ * these are the values that GNU tar happens to use on FreeBSD. */
+ archive_entry_set_uname(temp, "root");
+ archive_entry_set_gname(temp, "wheel");
+
+ archive_entry_set_pathname(temp, "././@LongLink");
+ archive_entry_set_size(temp, gnutar->linkname_length + 1);
+ ret = archive_format_gnutar_header(a, buff, temp, 'K');
+ if (ret < ARCHIVE_WARN)
+ goto exit_write_header;
+ ret = __archive_write_output(a, buff, 512);
+ if(ret < ARCHIVE_WARN)
+ goto exit_write_header;
+ archive_entry_free(temp);
+ /* Write as many 512 bytes blocks as needed to write full name. */
+ ret = __archive_write_output(a, gnutar->linkname, todo);
+ if(ret < ARCHIVE_WARN)
+ goto exit_write_header;
+ ret = __archive_write_nulls(a, 0x1ff & (-(ssize_t)todo));
+ if (ret < ARCHIVE_WARN)
+ goto exit_write_header;
+ }
+
+ /* If pathname is longer than 100 chars we need to add an 'L' header. */
+ if (gnutar->pathname_length > GNUTAR_name_size) {
+ const char *pathname = gnutar->pathname;
+ size_t todo = gnutar->pathname_length;
+ struct archive_entry *temp = archive_entry_new2(&a->archive);
+
+ /* Uname/gname here don't really matter since no one reads them;
+ * these are the values that GNU tar happens to use on FreeBSD. */
+ archive_entry_set_uname(temp, "root");
+ archive_entry_set_gname(temp, "wheel");
+
+ archive_entry_set_pathname(temp, "././@LongLink");
+ archive_entry_set_size(temp, gnutar->pathname_length + 1);
+ ret = archive_format_gnutar_header(a, buff, temp, 'L');
+ if (ret < ARCHIVE_WARN)
+ goto exit_write_header;
+ ret = __archive_write_output(a, buff, 512);
+ if(ret < ARCHIVE_WARN)
+ goto exit_write_header;
+ archive_entry_free(temp);
+ /* Write as many 512 bytes blocks as needed to write full name. */
+ ret = __archive_write_output(a, pathname, todo);
+ if(ret < ARCHIVE_WARN)
+ goto exit_write_header;
+ ret = __archive_write_nulls(a, 0x1ff & (-(ssize_t)todo));
+ if (ret < ARCHIVE_WARN)
+ goto exit_write_header;
+ }
+
+ if (archive_entry_hardlink(entry) != NULL) {
+ tartype = '1';
+ } else
+ switch (archive_entry_filetype(entry)) {
+ case AE_IFREG: tartype = '0' ; break;
+ case AE_IFLNK: tartype = '2' ; break;
+ case AE_IFCHR: tartype = '3' ; break;
+ case AE_IFBLK: tartype = '4' ; break;
+ case AE_IFDIR: tartype = '5' ; break;
+ case AE_IFIFO: tartype = '6' ; break;
+ case AE_IFSOCK:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive socket");
+ ret = ARCHIVE_FAILED;
+ goto exit_write_header;
+ default:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive this (mode=0%lo)",
+ (unsigned long)archive_entry_mode(entry));
+ ret = ARCHIVE_FAILED;
+ goto exit_write_header;
+ }
+
+ ret = archive_format_gnutar_header(a, buff, entry, tartype);
+ if (ret < ARCHIVE_WARN)
+ goto exit_write_header;
+ if (ret2 < ret)
+ ret = ret2;
+ ret2 = __archive_write_output(a, buff, 512);
+ if (ret2 < ARCHIVE_WARN) {
+ ret = ret2;
+ goto exit_write_header;
+ }
+ if (ret2 < ret)
+ ret = ret2;
+
+ gnutar->entry_bytes_remaining = archive_entry_size(entry);
+ gnutar->entry_padding = 0x1ff & (-(int64_t)gnutar->entry_bytes_remaining);
+exit_write_header:
+ if (entry_main)
+ archive_entry_free(entry_main);
+ return (ret);
+}
+
+static int
+archive_format_gnutar_header(struct archive_write *a, char h[512],
+ struct archive_entry *entry, int tartype)
+{
+ unsigned int checksum;
+ int i, ret;
+ size_t copy_length;
+ const char *p;
+ struct gnutar *gnutar;
+
+ gnutar = (struct gnutar *)a->format_data;
+
+ ret = 0;
+
+ /*
+ * The "template header" already includes the signature,
+ * various end-of-field markers, and other required elements.
+ */
+ memcpy(h, &template_header, 512);
+
+ /*
+ * Because the block is already null-filled, and strings
+ * are allowed to exactly fill their destination (without null),
+ * I use memcpy(dest, src, strlen()) here a lot to copy strings.
+ */
+
+ if (tartype == 'K' || tartype == 'L') {
+ p = archive_entry_pathname(entry);
+ copy_length = strlen(p);
+ } else {
+ p = gnutar->pathname;
+ copy_length = gnutar->pathname_length;
+ }
+ if (copy_length > GNUTAR_name_size)
+ copy_length = GNUTAR_name_size;
+ memcpy(h + GNUTAR_name_offset, p, copy_length);
+
+ if ((copy_length = gnutar->linkname_length) > 0) {
+ if (copy_length > GNUTAR_linkname_size)
+ copy_length = GNUTAR_linkname_size;
+ memcpy(h + GNUTAR_linkname_offset, gnutar->linkname,
+ copy_length);
+ }
+
+ /* TODO: How does GNU tar handle unames longer than GNUTAR_uname_size? */
+ if (tartype == 'K' || tartype == 'L') {
+ p = archive_entry_uname(entry);
+ copy_length = strlen(p);
+ } else {
+ p = gnutar->uname;
+ copy_length = gnutar->uname_length;
+ }
+ if (copy_length > 0) {
+ if (copy_length > GNUTAR_uname_size)
+ copy_length = GNUTAR_uname_size;
+ memcpy(h + GNUTAR_uname_offset, p, copy_length);
+ }
+
+ /* TODO: How does GNU tar handle gnames longer than GNUTAR_gname_size? */
+ if (tartype == 'K' || tartype == 'L') {
+ p = archive_entry_gname(entry);
+ copy_length = strlen(p);
+ } else {
+ p = gnutar->gname;
+ copy_length = gnutar->gname_length;
+ }
+ if (copy_length > 0) {
+ if (strlen(p) > GNUTAR_gname_size)
+ copy_length = GNUTAR_gname_size;
+ memcpy(h + GNUTAR_gname_offset, p, copy_length);
+ }
+
+ /* By truncating the mode here, we ensure it always fits. */
+ format_octal(archive_entry_mode(entry) & 07777,
+ h + GNUTAR_mode_offset, GNUTAR_mode_size);
+
+ /* TODO: How does GNU tar handle large UIDs? */
+ if (format_octal(archive_entry_uid(entry),
+ h + GNUTAR_uid_offset, GNUTAR_uid_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric user ID %jd too large",
+ (intmax_t)archive_entry_uid(entry));
+ ret = ARCHIVE_FAILED;
+ }
+
+ /* TODO: How does GNU tar handle large GIDs? */
+ if (format_octal(archive_entry_gid(entry),
+ h + GNUTAR_gid_offset, GNUTAR_gid_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric group ID %jd too large",
+ (intmax_t)archive_entry_gid(entry));
+ ret = ARCHIVE_FAILED;
+ }
+
+ /* GNU tar supports base-256 here, so should never overflow. */
+ if (format_number(archive_entry_size(entry), h + GNUTAR_size_offset,
+ GNUTAR_size_size, GNUTAR_size_max_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "File size out of range");
+ ret = ARCHIVE_FAILED;
+ }
+
+ /* Shouldn't overflow before 2106, since mtime field is 33 bits. */
+ format_octal(archive_entry_mtime(entry),
+ h + GNUTAR_mtime_offset, GNUTAR_mtime_size);
+
+ if (archive_entry_filetype(entry) == AE_IFBLK
+ || archive_entry_filetype(entry) == AE_IFCHR) {
+ if (format_octal(archive_entry_rdevmajor(entry),
+ h + GNUTAR_rdevmajor_offset,
+ GNUTAR_rdevmajor_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Major device number too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_octal(archive_entry_rdevminor(entry),
+ h + GNUTAR_rdevminor_offset,
+ GNUTAR_rdevminor_size)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Minor device number too large");
+ ret = ARCHIVE_FAILED;
+ }
+ }
+
+ h[GNUTAR_typeflag_offset] = tartype;
+
+ checksum = 0;
+ for (i = 0; i < 512; i++)
+ checksum += 255 & (unsigned int)h[i];
+ h[GNUTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */
+ /* h[GNUTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */
+ format_octal(checksum, h + GNUTAR_checksum_offset, 6);
+ return (ret);
+}
+
+/*
+ * Format a number into a field, falling back to base-256 if necessary.
+ */
+static int
+format_number(int64_t v, char *p, int s, int maxsize)
+{
+ int64_t limit = ((int64_t)1 << (s*3));
+
+ if (v < limit)
+ return (format_octal(v, p, s));
+ return (format_256(v, p, maxsize));
+}
+
+/*
+ * Format a number into the specified field using base-256.
+ */
+static int
+format_256(int64_t v, char *p, int s)
+{
+ p += s;
+ while (s-- > 0) {
+ *--p = (char)(v & 0xff);
+ v >>= 8;
+ }
+ *p |= 0x80; /* Set the base-256 marker bit. */
+ return (0);
+}
+
+/*
+ * Format a number into the specified field using octal.
+ */
+static int
+format_octal(int64_t v, char *p, int s)
+{
+ int len = s;
+
+ /* Octal values can't be negative, so use 0. */
+ if (v < 0)
+ v = 0;
+
+ p += s; /* Start at the end and work backwards. */
+ while (s-- > 0) {
+ *--p = (char)('0' + (v & 7));
+ v >>= 3;
+ }
+
+ if (v == 0)
+ return (0);
+
+ /* If it overflowed, fill field with max value. */
+ while (len-- > 0)
+ *p++ = '7';
+
+ return (-1);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c
new file mode 100644
index 0000000000..e7226256b1
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c
@@ -0,0 +1,8148 @@
+/*-
+ * Copyright (c) 2009-2012 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_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_UTSNAME_H
+#include <sys/utsname.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#include <stdio.h>
+#include <stdarg.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include <time.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_endian.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_rb.h"
+#include "archive_write_private.h"
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define getuid() 0
+#define getgid() 0
+#endif
+
+/*#define DEBUG 1*/
+#ifdef DEBUG
+/* To compare to the ISO image file made by mkisofs. */
+#define COMPAT_MKISOFS 1
+#endif
+
+#define LOGICAL_BLOCK_BITS 11
+#define LOGICAL_BLOCK_SIZE 2048
+#define PATH_TABLE_BLOCK_SIZE 4096
+
+#define SYSTEM_AREA_BLOCK 16
+#define PRIMARY_VOLUME_DESCRIPTOR_BLOCK 1
+#define SUPPLEMENTARY_VOLUME_DESCRIPTOR_BLOCK 1
+#define BOOT_RECORD_DESCRIPTOR_BLOCK 1
+#define VOLUME_DESCRIPTOR_SET_TERMINATOR_BLOCK 1
+#define NON_ISO_FILE_SYSTEM_INFORMATION_BLOCK 1
+#define RRIP_ER_BLOCK 1
+#define PADDING_BLOCK 150
+
+#define FD_1_2M_SIZE (1024 * 1200)
+#define FD_1_44M_SIZE (1024 * 1440)
+#define FD_2_88M_SIZE (1024 * 2880)
+#define MULTI_EXTENT_SIZE (ARCHIVE_LITERAL_LL(1) << 32) /* 4Gi bytes. */
+#define MAX_DEPTH 8
+#define RR_CE_SIZE 28 /* SUSP "CE" extension size */
+
+#define FILE_FLAG_EXISTENCE 0x01
+#define FILE_FLAG_DIRECTORY 0x02
+#define FILE_FLAG_ASSOCIATED 0x04
+#define FILE_FLAG_RECORD 0x08
+#define FILE_FLAG_PROTECTION 0x10
+#define FILE_FLAG_MULTI_EXTENT 0x80
+
+static const char rrip_identifier[] =
+ "RRIP_1991A";
+static const char rrip_descriptor[] =
+ "THE ROCK RIDGE INTERCHANGE PROTOCOL PROVIDES SUPPORT FOR "
+ "POSIX FILE SYSTEM SEMANTICS";
+static const char rrip_source[] =
+ "PLEASE CONTACT DISC PUBLISHER FOR SPECIFICATION SOURCE. "
+ "SEE PUBLISHER IDENTIFIER IN PRIMARY VOLUME DESCRIPTOR FOR "
+ "CONTACT INFORMATION.";
+#define RRIP_ER_ID_SIZE (sizeof(rrip_identifier)-1)
+#define RRIP_ER_DSC_SIZE (sizeof(rrip_descriptor)-1)
+#define RRIP_ER_SRC_SIZE (sizeof(rrip_source)-1)
+#define RRIP_ER_SIZE (8 + RRIP_ER_ID_SIZE + \
+ RRIP_ER_DSC_SIZE + RRIP_ER_SRC_SIZE)
+
+static const unsigned char zisofs_magic[8] = {
+ 0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07
+};
+
+#define ZF_HEADER_SIZE 16 /* zisofs header size. */
+#define ZF_LOG2_BS 15 /* log2 block size; 32K bytes. */
+#define ZF_BLOCK_SIZE (1UL << ZF_LOG2_BS)
+
+/*
+ * Manage extra records.
+ */
+struct extr_rec {
+ int location;
+ int offset;
+ unsigned char buf[LOGICAL_BLOCK_SIZE];
+ struct extr_rec *next;
+};
+
+struct ctl_extr_rec {
+ int use_extr;
+ unsigned char *bp;
+ struct isoent *isoent;
+ unsigned char *ce_ptr;
+ int cur_len;
+ int dr_len;
+ int limit;
+ int extr_off;
+ int extr_loc;
+};
+#define DR_SAFETY RR_CE_SIZE
+#define DR_LIMIT (254 - DR_SAFETY)
+
+/*
+ * The relation of struct isofile and isoent and archive_entry.
+ *
+ * Primary volume tree --> struct isoent
+ * |
+ * v
+ * struct isofile --> archive_entry
+ * ^
+ * |
+ * Joliet volume tree --> struct isoent
+ *
+ * struct isoent has specific information for volume.
+ */
+
+struct isofile {
+ /* Used for managing struct isofile list. */
+ struct isofile *allnext;
+ struct isofile *datanext;
+ /* Used for managing a hardlined struct isofile list. */
+ struct isofile *hlnext;
+ struct isofile *hardlink_target;
+
+ struct archive_entry *entry;
+
+ /*
+ * Used for making a directory tree.
+ */
+ struct archive_string parentdir;
+ struct archive_string basename;
+ struct archive_string basename_utf16;
+ struct archive_string symlink;
+ int dircnt; /* The number of elements of
+ * its parent directory */
+
+ /*
+ * Used for a Directory Record.
+ */
+ struct content {
+ int64_t offset_of_temp;
+ int64_t size;
+ int blocks;
+ uint32_t location;
+ /*
+ * One extent equals one content.
+ * If this entry has multi extent, `next' variable points
+ * next content data.
+ */
+ struct content *next; /* next content */
+ } content, *cur_content;
+ int write_content;
+
+ enum {
+ NO = 0,
+ BOOT_CATALOG,
+ BOOT_IMAGE
+ } boot;
+
+ /*
+ * Used for a zisofs.
+ */
+ struct {
+ unsigned char header_size;
+ unsigned char log2_bs;
+ uint32_t uncompressed_size;
+ } zisofs;
+};
+
+struct isoent {
+ /* Keep `rbnode' at the first member of struct isoent. */
+ struct archive_rb_node rbnode;
+
+ struct isofile *file;
+
+ struct isoent *parent;
+ /* A list of children.(use chnext) */
+ struct {
+ struct isoent *first;
+ struct isoent **last;
+ int cnt;
+ } children;
+ struct archive_rb_tree rbtree;
+
+ /* A list of sub directories.(use drnext) */
+ struct {
+ struct isoent *first;
+ struct isoent **last;
+ int cnt;
+ } subdirs;
+ /* A sorted list of sub directories. */
+ struct isoent **children_sorted;
+ /* Used for managing struct isoent list. */
+ struct isoent *chnext;
+ struct isoent *drnext;
+ struct isoent *ptnext;
+
+ /*
+ * Used for making a Directory Record.
+ */
+ int dir_number;
+ struct {
+ int vd;
+ int self;
+ int parent;
+ int normal;
+ } dr_len;
+ uint32_t dir_location;
+ int dir_block;
+
+ /*
+ * Identifier:
+ * on primary, ISO9660 file/directory name.
+ * on joliet, UCS2 file/directory name.
+ * ext_off : offset of identifier extension.
+ * ext_len : length of identifier extension.
+ * id_len : byte size of identifier.
+ * on primary, this is ext_off + ext_len + version length.
+ * on joliet, this is ext_off + ext_len.
+ * mb_len : length of multibyte-character of identifier.
+ * on primary, mb_len and id_len are always the same.
+ * on joliet, mb_len and id_len are different.
+ */
+ char *identifier;
+ int ext_off;
+ int ext_len;
+ int id_len;
+ int mb_len;
+
+ /*
+ * Used for making a Rockridge extension.
+ * This is a part of Directory Records.
+ */
+ struct isoent *rr_parent;
+ struct isoent *rr_child;
+
+ /* Extra Record.(which we call in this source file)
+ * A maximum size of the Directory Record is 254.
+ * so, if generated RRIP data of a file cannot into a Directory
+ * Record because of its size, that surplus data relocate this
+ * Extra Record.
+ */
+ struct {
+ struct extr_rec *first;
+ struct extr_rec **last;
+ struct extr_rec *current;
+ } extr_rec_list;
+
+ int virtual:1;
+ /* If set to one, this file type is a directory.
+ * A convenience flag to be used as
+ * "archive_entry_filetype(isoent->file->entry) == AE_IFDIR".
+ */
+ int dir:1;
+};
+
+struct hardlink {
+ struct archive_rb_node rbnode;
+ int nlink;
+ struct {
+ struct isofile *first;
+ struct isofile **last;
+ } file_list;
+};
+
+/*
+ * ISO writer options
+ */
+struct iso_option {
+ /*
+ * Usage : abstract-file=<value>
+ * Type : string, max 37 bytes
+ * Default: Not specified
+ * COMPAT : mkisofs -abstract <value>
+ *
+ * Specifies Abstract Filename.
+ * This file shall be described in the Root Directory
+ * and containing a abstract statement.
+ */
+ unsigned int abstract_file:1;
+#define OPT_ABSTRACT_FILE_DEFAULT 0 /* Not specified */
+#define ABSTRACT_FILE_SIZE 37
+
+ /*
+ * Usage : application-id=<value>
+ * Type : string, max 128 bytes
+ * Default: Not specified
+ * COMPAT : mkisofs -A/-appid <value>.
+ *
+ * Specifies Application Identifier.
+ * If the first byte is set to '_'(5F), the remaining
+ * bytes of this option shall specify an identifier
+ * for a file containing the identification of the
+ * application.
+ * This file shall be described in the Root Directory.
+ */
+ unsigned int application_id:1;
+#define OPT_APPLICATION_ID_DEFAULT 0 /* Use default identifier */
+#define APPLICATION_IDENTIFIER_SIZE 128
+
+ /*
+ * Usage : !allow-vernum
+ * Type : boolean
+ * Default: Enabled
+ * : Violates the ISO9660 standard if disable.
+ * COMPAT: mkisofs -N
+ *
+ * Allow filenames to use version numbers.
+ */
+ unsigned int allow_vernum:1;
+#define OPT_ALLOW_VERNUM_DEFAULT 1 /* Enabled */
+
+ /*
+ * Usage : biblio-file=<value>
+ * Type : string, max 37 bytes
+ * Default: Not specified
+ * COMPAT : mkisofs -biblio <value>
+ *
+ * Specifies Bibliographic Filename.
+ * This file shall be described in the Root Directory
+ * and containing bibliographic records.
+ */
+ unsigned int biblio_file:1;
+#define OPT_BIBLIO_FILE_DEFAULT 0 /* Not specified */
+#define BIBLIO_FILE_SIZE 37
+
+ /*
+ * Usage : boot=<value>
+ * Type : string
+ * Default: Not specified
+ * COMPAT : mkisofs -b/-eltorito-boot <value>
+ *
+ * Specifies "El Torito" boot image file to make
+ * a bootable CD.
+ */
+ unsigned int boot:1;
+#define OPT_BOOT_DEFAULT 0 /* Not specified */
+
+ /*
+ * Usage : boot-catalog=<value>
+ * Type : string
+ * Default: "boot.catalog"
+ * COMPAT : mkisofs -c/-eltorito-catalog <value>
+ *
+ * Specifies a fullpath of El Torito boot catalog.
+ */
+ unsigned int boot_catalog:1;
+#define OPT_BOOT_CATALOG_DEFAULT 0 /* Not specified */
+
+ /*
+ * Usage : boot-info-table
+ * Type : boolean
+ * Default: Disabled
+ * COMPAT : mkisofs -boot-info-table
+ *
+ * Modify the boot image file specified by `boot'
+ * option; ISO writer stores boot file information
+ * into the boot file in ISO image at offset 8
+ * through offset 64.
+ */
+ unsigned int boot_info_table:1;
+#define OPT_BOOT_INFO_TABLE_DEFAULT 0 /* Disabled */
+
+ /*
+ * Usage : boot-load-seg=<value>
+ * Type : hexadecimal
+ * Default: Not specified
+ * COMPAT : mkisofs -boot-load-seg <value>
+ *
+ * Specifies a load segment for boot image.
+ * This is used with no-emulation mode.
+ */
+ unsigned int boot_load_seg:1;
+#define OPT_BOOT_LOAD_SEG_DEFAULT 0 /* Not specified */
+
+ /*
+ * Usage : boot-load-size=<value>
+ * Type : decimal
+ * Default: Not specified
+ * COMPAT : mkisofs -boot-load-size <value>
+ *
+ * Specifies a sector count for boot image.
+ * This is used with no-emulation mode.
+ */
+ unsigned int boot_load_size:1;
+#define OPT_BOOT_LOAD_SIZE_DEFAULT 0 /* Not specified */
+
+ /*
+ * Usage : boot-type=<boot-media-type>
+ * : 'no-emulation' : 'no emulation' image
+ * : 'fd' : floppy disk image
+ * : 'hard-disk' : hard disk image
+ * Type : string
+ * Default: Auto detect
+ * : We check a size of boot image;
+ * : If ths size is just 1.22M/1.44M/2.88M,
+ * : we assume boot_type is 'fd';
+ * : otherwise boot_type is 'no-emulation'.
+ * COMPAT :
+ * boot=no-emulation
+ * mkisofs -no-emul-boot
+ * boot=fd
+ * This is a default on the mkisofs.
+ * boot=hard-disk
+ * mkisofs -hard-disk-boot
+ *
+ * Specifies a type of "El Torito" boot image.
+ */
+ unsigned int boot_type:2;
+#define OPT_BOOT_TYPE_AUTO 0 /* auto detect */
+#define OPT_BOOT_TYPE_NO_EMU 1 /* ``no emulation'' image */
+#define OPT_BOOT_TYPE_FD 2 /* floppy disk image */
+#define OPT_BOOT_TYPE_HARD_DISK 3 /* hard disk image */
+#define OPT_BOOT_TYPE_DEFAULT OPT_BOOT_TYPE_AUTO
+
+ /*
+ * Usage : compression-level=<value>
+ * Type : decimal
+ * Default: Not specified
+ * COMPAT : NONE
+ *
+ * Specifies compression level for option zisofs=direct.
+ */
+ unsigned int compression_level:1;
+#define OPT_COMPRESSION_LEVEL_DEFAULT 0 /* Not specified */
+
+ /*
+ * Usage : copyright-file=<value>
+ * Type : string, max 37 bytes
+ * Default: Not specified
+ * COMPAT : mkisofs -copyright <value>
+ *
+ * Specifies Copyright Filename.
+ * This file shall be described in the Root Directory
+ * and containing a copyright statement.
+ */
+ unsigned int copyright_file:1;
+#define OPT_COPYRIGHT_FILE_DEFAULT 0 /* Not specified */
+#define COPYRIGHT_FILE_SIZE 37
+
+ /*
+ * Usage : gid=<value>
+ * Type : decimal
+ * Default: Not specified
+ * COMPAT : mkisofs -gid <value>
+ *
+ * Specifies a group id to rewrite the group id of all files.
+ */
+ unsigned int gid:1;
+#define OPT_GID_DEFAULT 0 /* Not specified */
+
+ /*
+ * Usage : iso-level=[1234]
+ * Type : decimal
+ * Default: 1
+ * COMPAT : mkisofs -iso-level <value>
+ *
+ * Specifies ISO9600 Level.
+ * Level 1: [DEFAULT]
+ * - limits each file size less than 4Gi bytes;
+ * - a File Name shall not contain more than eight
+ * d-characters or eight d1-characters;
+ * - a File Name Extension shall not contain more than
+ * three d-characters or three d1-characters;
+ * - a Directory Identifier shall not contain more
+ * than eight d-characters or eight d1-characters.
+ * Level 2:
+ * - limits each file size less than 4Giga bytes;
+ * - a File Name shall not contain more than thirty
+ * d-characters or thirty d1-characters;
+ * - a File Name Extension shall not contain more than
+ * thirty d-characters or thirty d1-characters;
+ * - a Directory Identifier shall not contain more
+ * than thirty-one d-characters or thirty-one
+ * d1-characters.
+ * Level 3:
+ * - no limit of file size; use multi extent.
+ * Level 4:
+ * - this level 4 simulates mkisofs option
+ * '-iso-level 4';
+ * - crate a enhanced volume as mkisofs doing;
+ * - allow a File Name to have leading dot;
+ * - allow a File Name to have all ASCII letters;
+ * - allow a File Name to have multiple dots;
+ * - allow more then 8 depths of directory trees;
+ * - disable a version number to a File Name;
+ * - disable a forced period to the tail of a File Name;
+ * - the maxinum length of files and directories is raised to 193.
+ * if rockridge option is disabled, raised to 207.
+ */
+ unsigned int iso_level:3;
+#define OPT_ISO_LEVEL_DEFAULT 1 /* ISO Level 1 */
+
+ /*
+ * Usage : joliet[=long]
+ * : !joliet
+ * : Do not generate Joliet Volume and Records.
+ * : joliet [DEFAULT]
+ * : Generates Joliet Volume and Directory Records.
+ * : [COMPAT: mkisofs -J/-joliet]
+ * : joliet=long
+ * : The joliet filenames are up to 103 Unicode
+ * : characters.
+ * : This option breaks the Joliet specification.
+ * : [COMPAT: mkisofs -J -joliet-long]
+ * Type : boolean/string
+ * Default: Enabled
+ * COMPAT : mkisofs -J / -joliet-long
+ *
+ * Generates Joliet Volume and Directory Records.
+ */
+ unsigned int joliet:2;
+#define OPT_JOLIET_DISABLE 0 /* Not generate Joliet Records. */
+#define OPT_JOLIET_ENABLE 1 /* Generate Joliet Records. */
+#define OPT_JOLIET_LONGNAME 2 /* Use long joliet filenames.*/
+#define OPT_JOLIET_DEFAULT OPT_JOLIET_ENABLE
+
+ /*
+ * Usage : !limit-depth
+ * Type : boolean
+ * Default: Enabled
+ * : Violates the ISO9660 standard if disable.
+ * COMPAT : mkisofs -D/-disable-deep-relocation
+ *
+ * The number of levels in hierarchy cannot exceed eight.
+ */
+ unsigned int limit_depth:1;
+#define OPT_LIMIT_DEPTH_DEFAULT 1 /* Enabled */
+
+ /*
+ * Usage : !limit-dirs
+ * Type : boolean
+ * Default: Enabled
+ * : Violates the ISO9660 standard if disable.
+ * COMPAT : mkisofs -no-limit-pathtables
+ *
+ * Limits the number of directories less than 65536 due
+ * to the size of the Parent Directory Number of Path
+ * Table.
+ */
+ unsigned int limit_dirs:1;
+#define OPT_LIMIT_DIRS_DEFAULT 1 /* Enabled */
+
+ /*
+ * Usage : !pad
+ * Type : boolean
+ * Default: Enabled
+ * COMPAT : -pad/-no-pad
+ *
+ * Pads the end of the ISO image by null of 300Ki bytes.
+ */
+ unsigned int pad:1;
+#define OPT_PAD_DEFAULT 1 /* Enabled */
+
+ /*
+ * Usage : publisher=<value>
+ * Type : string, max 128 bytes
+ * Default: Not specified
+ * COMPAT : mkisofs -publisher <value>
+ *
+ * Specifies Publisher Identifier.
+ * If the first byte is set to '_'(5F), the remaining
+ * bytes of this option shall specify an identifier
+ * for a file containing the identification of the user.
+ * This file shall be described in the Root Directory.
+ */
+ unsigned int publisher:1;
+#define OPT_PUBLISHER_DEFAULT 0 /* Not specified */
+#define PUBLISHER_IDENTIFIER_SIZE 128
+
+ /*
+ * Usage : rockridge
+ * : !rockridge
+ * : disable to generate SUSP and RR records.
+ * : rockridge
+ * : the same as 'rockridge=useful'.
+ * : rockridge=strict
+ * : generate SUSP and RR records.
+ * : [COMPAT: mkisofs -R]
+ * : rockridge=useful [DEFAULT]
+ * : generate SUSP and RR records.
+ * : [COMPAT: mkisofs -r]
+ * : NOTE Our rockridge=useful option does not set a zero
+ * : to uid and gid, you should use application
+ * : option such as --gid,--gname,--uid and --uname
+ * : badtar options instead.
+ * Type : boolean/string
+ * Default: Enabled as rockridge=useful
+ * COMPAT : mkisofs -r / -R
+ *
+ * Generates SUSP and RR records.
+ */
+ unsigned int rr:2;
+#define OPT_RR_DISABLED 0
+#define OPT_RR_STRICT 1
+#define OPT_RR_USEFUL 2
+#define OPT_RR_DEFAULT OPT_RR_USEFUL
+
+ /*
+ * Usage : volume-id=<value>
+ * Type : string, max 32 bytes
+ * Default: Not specified
+ * COMPAT : mkisofs -V <value>
+ *
+ * Specifies Volume Identifier.
+ */
+ unsigned int volume_id:1;
+#define OPT_VOLUME_ID_DEFAULT 0 /* Use default identifier */
+#define VOLUME_IDENTIFIER_SIZE 32
+
+ /*
+ * Usage : !zisofs [DEFAULT]
+ * : Disable to generate RRIP 'ZF' extension.
+ * : zisofs
+ * : Make files zisofs file and generate RRIP 'ZF'
+ * : extension. So you do not need mkzftree utility
+ * : for making zisofs.
+ * : When the file size is less than one Logical Block
+ * : size, that file will not zisofs'ed since it does
+ * : reduece an ISO-image size.
+ * :
+ * : When you specify option 'boot=<boot-image>', that
+ * : 'boot-image' file won't be converted to zisofs file.
+ * Type : boolean
+ * Default: Disabled
+ *
+ * Generates RRIP 'ZF' System Use Entry.
+ */
+ unsigned int zisofs:1;
+#define OPT_ZISOFS_DISABLED 0
+#define OPT_ZISOFS_DIRECT 1
+#define OPT_ZISOFS_DEFAULT OPT_ZISOFS_DISABLED
+
+};
+
+struct iso9660 {
+ /* The creation time of ISO image. */
+ time_t birth_time;
+ /* A file stream of a temporary file, which file contents
+ * save to until ISO iamge can be created. */
+ int temp_fd;
+
+ struct isofile *cur_file;
+ struct isoent *cur_dirent;
+ struct archive_string cur_dirstr;
+ uint64_t bytes_remaining;
+ int need_multi_extent;
+
+ /* Temporary string buffer for Joliet extension. */
+ struct archive_string utf16be;
+ struct archive_string mbs;
+
+ struct archive_string_conv *sconv_to_utf16be;
+ struct archive_string_conv *sconv_from_utf16be;
+
+ /* A list of all of struct isofile entries. */
+ struct {
+ struct isofile *first;
+ struct isofile **last;
+ } all_file_list;
+
+ /* A list of struct isofile entries which have its
+ * contents and are not a directory, a hardlined file
+ * and a symlink file. */
+ struct {
+ struct isofile *first;
+ struct isofile **last;
+ } data_file_list;
+
+ /* Used for managing to find hardlinking files. */
+ struct archive_rb_tree hardlink_rbtree;
+
+ /* Used for making the Path Table Record. */
+ struct vdd {
+ /* the root of entry tree. */
+ struct isoent *rootent;
+ enum vdd_type {
+ VDD_PRIMARY,
+ VDD_JOLIET,
+ VDD_ENHANCED
+ } vdd_type;
+
+ struct path_table {
+ struct isoent *first;
+ struct isoent **last;
+ struct isoent **sorted;
+ int cnt;
+ } *pathtbl;
+ int max_depth;
+
+ int path_table_block;
+ int path_table_size;
+ int location_type_L_path_table;
+ int location_type_M_path_table;
+ int total_dir_block;
+ } primary, joliet;
+
+ /* Used for making a Volume Descriptor. */
+ int volume_space_size;
+ int volume_sequence_number;
+ int total_file_block;
+ struct archive_string volume_identifier;
+ struct archive_string publisher_identifier;
+ struct archive_string data_preparer_identifier;
+ struct archive_string application_identifier;
+ struct archive_string copyright_file_identifier;
+ struct archive_string abstract_file_identifier;
+ struct archive_string bibliographic_file_identifier;
+
+ /* Used for making rockridge extensions. */
+ int location_rrip_er;
+
+ /* Used for making zisofs. */
+ struct {
+ int detect_magic:1;
+ int making:1;
+ int allzero:1;
+ unsigned char magic_buffer[64];
+ int magic_cnt;
+
+#ifdef HAVE_ZLIB_H
+ /*
+ * Copy a compressed file to iso9660.zisofs.temp_fd
+ * and also copy a uncompressed file(original file) to
+ * iso9660.temp_fd . If the number of logical block
+ * of the compressed file is less than the number of
+ * logical block of the uncompressed file, use it and
+ * remove the copy of the uncompressed file.
+ * but if not, we use uncompressed file and remove
+ * the copy of the compressed file.
+ */
+ uint32_t *block_pointers;
+ size_t block_pointers_allocated;
+ int block_pointers_cnt;
+ int block_pointers_idx;
+ int64_t total_size;
+ int64_t block_offset;
+
+ z_stream stream;
+ int stream_valid;
+ int64_t remaining;
+ int compression_level;
+#endif
+ } zisofs;
+
+ struct isoent *directories_too_deep;
+ int dircnt_max;
+
+ /* Write buffer. */
+#define wb_buffmax() (LOGICAL_BLOCK_SIZE * 32)
+#define wb_remaining(a) (((struct iso9660 *)(a)->format_data)->wbuff_remaining)
+#define wb_offset(a) (((struct iso9660 *)(a)->format_data)->wbuff_offset \
+ + wb_buffmax() - wb_remaining(a))
+ unsigned char wbuff[LOGICAL_BLOCK_SIZE * 32];
+ size_t wbuff_remaining;
+ enum {
+ WB_TO_STREAM,
+ WB_TO_TEMP
+ } wbuff_type;
+ int64_t wbuff_offset;
+ int64_t wbuff_written;
+ int64_t wbuff_tail;
+
+ /* 'El Torito' boot data. */
+ struct {
+ /* boot catalog file */
+ struct archive_string catalog_filename;
+ struct isoent *catalog;
+ /* boot image file */
+ struct archive_string boot_filename;
+ struct isoent *boot;
+
+ unsigned char platform_id;
+#define BOOT_PLATFORM_X86 0
+#define BOOT_PLATFORM_PPC 1
+#define BOOT_PLATFORM_MAC 2
+ struct archive_string id;
+ unsigned char media_type;
+#define BOOT_MEDIA_NO_EMULATION 0
+#define BOOT_MEDIA_1_2M_DISKETTE 1
+#define BOOT_MEDIA_1_44M_DISKETTE 2
+#define BOOT_MEDIA_2_88M_DISKETTE 3
+#define BOOT_MEDIA_HARD_DISK 4
+ unsigned char system_type;
+ uint16_t boot_load_seg;
+ uint16_t boot_load_size;
+#define BOOT_LOAD_SIZE 4
+ } el_torito;
+
+ struct iso_option opt;
+};
+
+/*
+ * Types of Volume Descriptor
+ */
+enum VD_type {
+ VDT_BOOT_RECORD=0, /* Boot Record Volume Descriptor */
+ VDT_PRIMARY=1, /* Primary Volume Descriptor */
+ VDT_SUPPLEMENTARY=2, /* Supplementary Volume Descriptor */
+ VDT_TERMINATOR=255 /* Volume Descriptor Set Terminator */
+};
+
+/*
+ * Types of Directory Record
+ */
+enum dir_rec_type {
+ DIR_REC_VD, /* Stored in Volume Descriptor. */
+ DIR_REC_SELF, /* Stored as Current Directory. */
+ DIR_REC_PARENT, /* Stored as Parent Directory. */
+ DIR_REC_NORMAL /* Stored as Child. */
+};
+
+/*
+ * Kinds of Volume Descriptor Character
+ */
+enum vdc {
+ VDC_STD,
+ VDC_LOWERCASE,
+ VDC_UCS2,
+ VDC_UCS2_DIRECT
+};
+
+/*
+ * IDentifier Resolver.
+ * Used for resolving duplicated filenames.
+ */
+struct idr {
+ struct idrent {
+ struct archive_rb_node rbnode;
+ /* Used in wait_list. */
+ struct idrent *wnext;
+ struct idrent *avail;
+
+ struct isoent *isoent;
+ int weight;
+ int noff;
+ int rename_num;
+ } *idrent_pool;
+
+ struct archive_rb_tree rbtree;
+
+ struct {
+ struct idrent *first;
+ struct idrent **last;
+ } wait_list;
+
+ int pool_size;
+ int pool_idx;
+ int num_size;
+ int null_size;
+
+ char char_map[0x80];
+};
+
+enum char_type {
+ A_CHAR,
+ D_CHAR
+};
+
+
+static int iso9660_options(struct archive_write *,
+ const char *, const char *);
+static int iso9660_write_header(struct archive_write *,
+ struct archive_entry *);
+static ssize_t iso9660_write_data(struct archive_write *,
+ const void *, size_t);
+static int iso9660_finish_entry(struct archive_write *);
+static int iso9660_close(struct archive_write *);
+static int iso9660_free(struct archive_write *);
+
+static void get_system_identitier(char *, size_t);
+static void set_str(unsigned char *, const char *, size_t, char,
+ const char *);
+static inline int joliet_allowed_char(unsigned char, unsigned char);
+static int set_str_utf16be(struct archive_write *, unsigned char *,
+ const char *, size_t, uint16_t, enum vdc);
+static int set_str_a_characters_bp(struct archive_write *,
+ unsigned char *, int, int, const char *, enum vdc);
+static int set_str_d_characters_bp(struct archive_write *,
+ unsigned char *, int, int, const char *, enum vdc);
+static void set_VD_bp(unsigned char *, enum VD_type, unsigned char);
+static inline void set_unused_field_bp(unsigned char *, int, int);
+
+static unsigned char *extra_open_record(unsigned char *, int,
+ struct isoent *, struct ctl_extr_rec *);
+static void extra_close_record(struct ctl_extr_rec *, int);
+static unsigned char * extra_next_record(struct ctl_extr_rec *, int);
+static unsigned char *extra_get_record(struct isoent *, int *, int *, int *);
+static void extra_tell_used_size(struct ctl_extr_rec *, int);
+static int extra_setup_location(struct isoent *, int);
+static int set_directory_record_rr(unsigned char *, int,
+ struct isoent *, struct iso9660 *, enum dir_rec_type);
+static int set_directory_record(unsigned char *, size_t,
+ struct isoent *, struct iso9660 *, enum dir_rec_type,
+ enum vdd_type);
+static inline int get_dir_rec_size(struct iso9660 *, struct isoent *,
+ enum dir_rec_type, enum vdd_type);
+static inline unsigned char *wb_buffptr(struct archive_write *);
+static int wb_write_out(struct archive_write *);
+static int wb_consume(struct archive_write *, size_t);
+#ifdef HAVE_ZLIB_H
+static int wb_set_offset(struct archive_write *, int64_t);
+#endif
+static int write_null(struct archive_write *, size_t);
+static int write_VD_terminator(struct archive_write *);
+static int set_file_identifier(unsigned char *, int, int, enum vdc,
+ struct archive_write *, struct vdd *,
+ struct archive_string *, const char *, int,
+ enum char_type);
+static int write_VD(struct archive_write *, struct vdd *);
+static int write_VD_boot_record(struct archive_write *);
+static int write_information_block(struct archive_write *);
+static int write_path_table(struct archive_write *, int,
+ struct vdd *);
+static int write_directory_descriptors(struct archive_write *,
+ struct vdd *);
+static int write_file_descriptors(struct archive_write *);
+static int write_rr_ER(struct archive_write *);
+static void calculate_path_table_size(struct vdd *);
+
+static void isofile_init_entry_list(struct iso9660 *);
+static void isofile_add_entry(struct iso9660 *, struct isofile *);
+static void isofile_free_all_entries(struct iso9660 *);
+static void isofile_init_entry_data_file_list(struct iso9660 *);
+static void isofile_add_data_file(struct iso9660 *, struct isofile *);
+static struct isofile * isofile_new(struct archive_write *,
+ struct archive_entry *);
+static void isofile_free(struct isofile *);
+static int isofile_gen_utility_names(struct archive_write *,
+ struct isofile *);
+static int isofile_register_hardlink(struct archive_write *,
+ struct isofile *);
+static void isofile_connect_hardlink_files(struct iso9660 *);
+static void isofile_init_hardlinks(struct iso9660 *);
+static void isofile_free_hardlinks(struct iso9660 *);
+
+static struct isoent *isoent_new(struct isofile *);
+static int isoent_clone_tree(struct archive_write *,
+ struct isoent **, struct isoent *);
+static void _isoent_free(struct isoent *isoent);
+static void isoent_free_all(struct isoent *);
+static struct isoent * isoent_create_virtual_dir(struct archive_write *,
+ struct iso9660 *, const char *);
+static int isoent_cmp_node(const struct archive_rb_node *,
+ const struct archive_rb_node *);
+static int isoent_cmp_key(const struct archive_rb_node *,
+ const void *);
+static int isoent_add_child_head(struct isoent *, struct isoent *);
+static int isoent_add_child_tail(struct isoent *, struct isoent *);
+static void isoent_remove_child(struct isoent *, struct isoent *);
+static void isoent_setup_directory_location(struct iso9660 *,
+ int, struct vdd *);
+static void isoent_setup_file_location(struct iso9660 *, int);
+static int get_path_component(char *, size_t, const char *);
+static int isoent_tree(struct archive_write *, struct isoent **);
+static struct isoent *isoent_find_child(struct isoent *, const char *);
+static struct isoent *isoent_find_entry(struct isoent *, const char *);
+static void idr_relaxed_filenames(char *);
+static void idr_init(struct iso9660 *, struct vdd *, struct idr *);
+static void idr_cleanup(struct idr *);
+static int idr_ensure_poolsize(struct archive_write *, struct idr *,
+ int);
+static int idr_start(struct archive_write *, struct idr *,
+ int, int, int, int, const struct archive_rb_tree_ops *);
+static void idr_register(struct idr *, struct isoent *, int,
+ int);
+static void idr_extend_identifier(struct idrent *, int, int);
+static void idr_resolve(struct idr *, void (*)(unsigned char *, int));
+static void idr_set_num(unsigned char *, int);
+static void idr_set_num_beutf16(unsigned char *, int);
+static int isoent_gen_iso9660_identifier(struct archive_write *,
+ struct isoent *, struct idr *);
+static int isoent_gen_joliet_identifier(struct archive_write *,
+ struct isoent *, struct idr *);
+static int isoent_cmp_iso9660_identifier(const struct isoent *,
+ const struct isoent *);
+static int isoent_cmp_node_iso9660(const struct archive_rb_node *,
+ const struct archive_rb_node *);
+static int isoent_cmp_key_iso9660(const struct archive_rb_node *,
+ const void *);
+static int isoent_cmp_joliet_identifier(const struct isoent *,
+ const struct isoent *);
+static int isoent_cmp_node_joliet(const struct archive_rb_node *,
+ const struct archive_rb_node *);
+static int isoent_cmp_key_joliet(const struct archive_rb_node *,
+ const void *);
+static inline void path_table_add_entry(struct path_table *, struct isoent *);
+static inline struct isoent * path_table_last_entry(struct path_table *);
+static int isoent_make_path_table(struct archive_write *);
+static int isoent_find_out_boot_file(struct archive_write *,
+ struct isoent *);
+static int isoent_create_boot_catalog(struct archive_write *,
+ struct isoent *);
+static size_t fd_boot_image_size(int);
+static int make_boot_catalog(struct archive_write *);
+static int setup_boot_information(struct archive_write *);
+
+static int zisofs_init(struct archive_write *, struct isofile *);
+static void zisofs_detect_magic(struct archive_write *,
+ const void *, size_t);
+static int zisofs_write_to_temp(struct archive_write *,
+ const void *, size_t);
+static int zisofs_finish_entry(struct archive_write *);
+static int zisofs_rewind_boot_file(struct archive_write *);
+static int zisofs_free(struct archive_write *);
+
+int
+archive_write_set_format_iso9660(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct iso9660 *iso9660;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_iso9660");
+
+ /* If another format was already registered, unregister it. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ iso9660 = calloc(1, sizeof(*iso9660));
+ if (iso9660 == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate iso9660 data");
+ return (ARCHIVE_FATAL);
+ }
+ iso9660->birth_time = 0;
+ iso9660->temp_fd = -1;
+ iso9660->cur_file = NULL;
+ iso9660->primary.max_depth = 0;
+ iso9660->primary.vdd_type = VDD_PRIMARY;
+ iso9660->primary.pathtbl = NULL;
+ iso9660->joliet.rootent = NULL;
+ iso9660->joliet.max_depth = 0;
+ iso9660->joliet.vdd_type = VDD_JOLIET;
+ iso9660->joliet.pathtbl = NULL;
+ isofile_init_entry_list(iso9660);
+ isofile_init_entry_data_file_list(iso9660);
+ isofile_init_hardlinks(iso9660);
+ iso9660->directories_too_deep = NULL;
+ iso9660->dircnt_max = 1;
+ iso9660->wbuff_remaining = wb_buffmax();
+ iso9660->wbuff_type = WB_TO_TEMP;
+ iso9660->wbuff_offset = 0;
+ iso9660->wbuff_written = 0;
+ iso9660->wbuff_tail = 0;
+ archive_string_init(&(iso9660->utf16be));
+ archive_string_init(&(iso9660->mbs));
+
+ /*
+ * Init Identifiers used for PVD and SVD.
+ */
+ archive_string_init(&(iso9660->volume_identifier));
+ archive_strcpy(&(iso9660->volume_identifier), "CDROM");
+ archive_string_init(&(iso9660->publisher_identifier));
+ archive_string_init(&(iso9660->data_preparer_identifier));
+ archive_string_init(&(iso9660->application_identifier));
+ archive_strcpy(&(iso9660->application_identifier),
+ archive_version_string());
+ archive_string_init(&(iso9660->copyright_file_identifier));
+ archive_string_init(&(iso9660->abstract_file_identifier));
+ archive_string_init(&(iso9660->bibliographic_file_identifier));
+
+ /*
+ * Init El Torito bootable CD variables.
+ */
+ archive_string_init(&(iso9660->el_torito.catalog_filename));
+ iso9660->el_torito.catalog = NULL;
+ /* Set default file name of boot catalog */
+ archive_strcpy(&(iso9660->el_torito.catalog_filename),
+ "boot.catalog");
+ archive_string_init(&(iso9660->el_torito.boot_filename));
+ iso9660->el_torito.boot = NULL;
+ iso9660->el_torito.platform_id = BOOT_PLATFORM_X86;
+ archive_string_init(&(iso9660->el_torito.id));
+ iso9660->el_torito.boot_load_seg = 0;
+ iso9660->el_torito.boot_load_size = BOOT_LOAD_SIZE;
+
+ /*
+ * Init zisofs variables.
+ */
+#ifdef HAVE_ZLIB_H
+ iso9660->zisofs.block_pointers = NULL;
+ iso9660->zisofs.block_pointers_allocated = 0;
+ iso9660->zisofs.stream_valid = 0;
+ iso9660->zisofs.compression_level = 9;
+ memset(&(iso9660->zisofs.stream), 0,
+ sizeof(iso9660->zisofs.stream));
+#endif
+
+ /*
+ * Set default value of iso9660 options.
+ */
+ iso9660->opt.abstract_file = OPT_ABSTRACT_FILE_DEFAULT;
+ iso9660->opt.application_id = OPT_APPLICATION_ID_DEFAULT;
+ iso9660->opt.allow_vernum = OPT_ALLOW_VERNUM_DEFAULT;
+ iso9660->opt.biblio_file = OPT_BIBLIO_FILE_DEFAULT;
+ iso9660->opt.boot = OPT_BOOT_DEFAULT;
+ iso9660->opt.boot_catalog = OPT_BOOT_CATALOG_DEFAULT;
+ iso9660->opt.boot_info_table = OPT_BOOT_INFO_TABLE_DEFAULT;
+ iso9660->opt.boot_load_seg = OPT_BOOT_LOAD_SEG_DEFAULT;
+ iso9660->opt.boot_load_size = OPT_BOOT_LOAD_SIZE_DEFAULT;
+ iso9660->opt.boot_type = OPT_BOOT_TYPE_DEFAULT;
+ iso9660->opt.compression_level = OPT_COMPRESSION_LEVEL_DEFAULT;
+ iso9660->opt.copyright_file = OPT_COPYRIGHT_FILE_DEFAULT;
+ iso9660->opt.iso_level = OPT_ISO_LEVEL_DEFAULT;
+ iso9660->opt.joliet = OPT_JOLIET_DEFAULT;
+ iso9660->opt.limit_depth = OPT_LIMIT_DEPTH_DEFAULT;
+ iso9660->opt.limit_dirs = OPT_LIMIT_DIRS_DEFAULT;
+ iso9660->opt.pad = OPT_PAD_DEFAULT;
+ iso9660->opt.publisher = OPT_PUBLISHER_DEFAULT;
+ iso9660->opt.rr = OPT_RR_DEFAULT;
+ iso9660->opt.volume_id = OPT_VOLUME_ID_DEFAULT;
+ iso9660->opt.zisofs = OPT_ZISOFS_DEFAULT;
+
+ /* Create the root directory. */
+ iso9660->primary.rootent =
+ isoent_create_virtual_dir(a, iso9660, "");
+ if (iso9660->primary.rootent == NULL) {
+ free(iso9660);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ iso9660->primary.rootent->parent = iso9660->primary.rootent;
+ iso9660->cur_dirent = iso9660->primary.rootent;
+ archive_string_init(&(iso9660->cur_dirstr));
+ archive_string_ensure(&(iso9660->cur_dirstr), 1);
+ iso9660->cur_dirstr.s[0] = 0;
+ iso9660->sconv_to_utf16be = NULL;
+ iso9660->sconv_from_utf16be = NULL;
+
+ a->format_data = iso9660;
+ a->format_name = "iso9660";
+ a->format_options = iso9660_options;
+ a->format_write_header = iso9660_write_header;
+ a->format_write_data = iso9660_write_data;
+ a->format_finish_entry = iso9660_finish_entry;
+ a->format_close = iso9660_close;
+ a->format_free = iso9660_free;
+ a->archive.archive_format = ARCHIVE_FORMAT_ISO9660;
+ a->archive.archive_format_name = "ISO9660";
+
+ return (ARCHIVE_OK);
+}
+
+static int
+get_str_opt(struct archive_write *a, struct archive_string *s,
+ size_t maxsize, const char *key, const char *value)
+{
+
+ if (strlen(value) > maxsize) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Value is longer than %zu characters "
+ "for option ``%s''", maxsize, key);
+ return (ARCHIVE_FATAL);
+ }
+ archive_strcpy(s, value);
+ return (ARCHIVE_OK);
+}
+
+static int
+get_num_opt(struct archive_write *a, int *num, int high, int low,
+ const char *key, const char *value)
+{
+ const char *p = value;
+ int data = 0;
+ int neg = 0;
+
+ if (p == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid value(empty) for option ``%s''", key);
+ return (ARCHIVE_FATAL);
+ }
+ if (*p == '-') {
+ neg = 1;
+ p++;
+ }
+ while (*p) {
+ if (*p >= '0' && *p <= '9')
+ data = data * 10 + *p - '0';
+ else {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid value for option ``%s''", key);
+ return (ARCHIVE_FATAL);
+ }
+ if (data > high) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid value(over %d) for "
+ "option ``%s''", high, key);
+ return (ARCHIVE_FATAL);
+ }
+ if (data < low) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid value(under %d) for "
+ "option ``%s''", low, key);
+ return (ARCHIVE_FATAL);
+ }
+ p++;
+ }
+ if (neg)
+ data *= -1;
+ *num = data;
+
+ return (ARCHIVE_OK);
+}
+
+static int
+iso9660_options(struct archive_write *a, const char *key, const char *value)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ const char *p;
+ int r;
+
+ switch (key[0]) {
+ case 'a':
+ if (strcmp(key, "abstract-file") == 0) {
+ r = get_str_opt(a,
+ &(iso9660->abstract_file_identifier),
+ ABSTRACT_FILE_SIZE, key, value);
+ iso9660->opt.abstract_file = r == ARCHIVE_OK;
+ return (r);
+ }
+ if (strcmp(key, "application-id") == 0) {
+ r = get_str_opt(a,
+ &(iso9660->application_identifier),
+ APPLICATION_IDENTIFIER_SIZE, key, value);
+ iso9660->opt.application_id = r == ARCHIVE_OK;
+ return (r);
+ }
+ if (strcmp(key, "allow-vernum") == 0) {
+ iso9660->opt.allow_vernum = value != NULL;
+ return (ARCHIVE_OK);
+ }
+ break;
+ case 'b':
+ if (strcmp(key, "biblio-file") == 0) {
+ r = get_str_opt(a,
+ &(iso9660->bibliographic_file_identifier),
+ BIBLIO_FILE_SIZE, key, value);
+ iso9660->opt.biblio_file = r == ARCHIVE_OK;
+ return (r);
+ }
+ if (strcmp(key, "boot") == 0) {
+ if (value == NULL)
+ iso9660->opt.boot = 0;
+ else {
+ iso9660->opt.boot = 1;
+ archive_strcpy(
+ &(iso9660->el_torito.boot_filename),
+ value);
+ }
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "boot-catalog") == 0) {
+ r = get_str_opt(a,
+ &(iso9660->el_torito.catalog_filename),
+ 1024, key, value);
+ iso9660->opt.boot_catalog = r == ARCHIVE_OK;
+ return (r);
+ }
+ if (strcmp(key, "boot-info-table") == 0) {
+ iso9660->opt.boot_info_table = value != NULL;
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "boot-load-seg") == 0) {
+ uint32_t seg;
+
+ iso9660->opt.boot_load_seg = 0;
+ if (value == NULL)
+ goto invalid_value;
+ seg = 0;
+ p = value;
+ if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X'))
+ p += 2;
+ while (*p) {
+ if (seg)
+ seg <<= 4;
+ if (*p >= 'A' && *p <= 'F')
+ seg += *p - 'A' + 0x0a;
+ else if (*p >= 'a' && *p <= 'f')
+ seg += *p - 'a' + 0x0a;
+ else if (*p >= '0' && *p <= '9')
+ seg += *p - '0';
+ else
+ goto invalid_value;
+ if (seg > 0xffff) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Invalid value(over 0xffff) for "
+ "option ``%s''", key);
+ return (ARCHIVE_FATAL);
+ }
+ p++;
+ }
+ iso9660->el_torito.boot_load_seg = (uint16_t)seg;
+ iso9660->opt.boot_load_seg = 1;
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "boot-load-size") == 0) {
+ int num = 0;
+ r = get_num_opt(a, &num, 0xffff, 1, key, value);
+ iso9660->opt.boot_load_size = r == ARCHIVE_OK;
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ iso9660->el_torito.boot_load_size = (uint16_t)num;
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "boot-type") == 0) {
+ if (value == NULL)
+ goto invalid_value;
+ if (strcmp(value, "no-emulation") == 0)
+ iso9660->opt.boot_type = OPT_BOOT_TYPE_NO_EMU;
+ else if (strcmp(value, "fd") == 0)
+ iso9660->opt.boot_type = OPT_BOOT_TYPE_FD;
+ else if (strcmp(value, "hard-disk") == 0)
+ iso9660->opt.boot_type = OPT_BOOT_TYPE_HARD_DISK;
+ else
+ goto invalid_value;
+ return (ARCHIVE_OK);
+ }
+ break;
+ case 'c':
+ if (strcmp(key, "compression-level") == 0) {
+#ifdef HAVE_ZLIB_H
+ if (value == NULL ||
+ !(value[0] >= '0' && value[0] <= '9') ||
+ value[1] != '\0')
+ goto invalid_value;
+ iso9660->zisofs.compression_level = value[0] - '0';
+ iso9660->opt.compression_level = 1;
+ return (ARCHIVE_OK);
+#else
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Option ``%s'' "
+ "is not supported on this platform.", key);
+ return (ARCHIVE_FATAL);
+#endif
+ }
+ if (strcmp(key, "copyright-file") == 0) {
+ r = get_str_opt(a,
+ &(iso9660->copyright_file_identifier),
+ COPYRIGHT_FILE_SIZE, key, value);
+ iso9660->opt.copyright_file = r == ARCHIVE_OK;
+ return (r);
+ }
+#ifdef DEBUG
+ /* Specifies Volume creation date and time;
+ * year(4),month(2),day(2),hour(2),minute(2),second(2).
+ * e.g. "20090929033757"
+ */
+ if (strcmp(key, "creation") == 0) {
+ struct tm tm;
+ char buf[5];
+
+ p = value;
+ if (p == NULL || strlen(p) < 14)
+ goto invalid_value;
+ memset(&tm, 0, sizeof(tm));
+ memcpy(buf, p, 4); buf[4] = '\0'; p += 4;
+ tm.tm_year = strtol(buf, NULL, 10) - 1900;
+ memcpy(buf, p, 2); buf[2] = '\0'; p += 2;
+ tm.tm_mon = strtol(buf, NULL, 10) - 1;
+ memcpy(buf, p, 2); buf[2] = '\0'; p += 2;
+ tm.tm_mday = strtol(buf, NULL, 10);
+ memcpy(buf, p, 2); buf[2] = '\0'; p += 2;
+ tm.tm_hour = strtol(buf, NULL, 10);
+ memcpy(buf, p, 2); buf[2] = '\0'; p += 2;
+ tm.tm_min = strtol(buf, NULL, 10);
+ memcpy(buf, p, 2); buf[2] = '\0';
+ tm.tm_sec = strtol(buf, NULL, 10);
+ iso9660->birth_time = mktime(&tm);
+ return (ARCHIVE_OK);
+ }
+#endif
+ break;
+ case 'i':
+ if (strcmp(key, "iso-level") == 0) {
+ if (value != NULL && value[1] == '\0' &&
+ (value[0] >= '1' && value[0] <= '4')) {
+ iso9660->opt.iso_level = value[0]-'0';
+ return (ARCHIVE_OK);
+ }
+ goto invalid_value;
+ }
+ break;
+ case 'j':
+ if (strcmp(key, "joliet") == 0) {
+ if (value == NULL)
+ iso9660->opt.joliet = OPT_JOLIET_DISABLE;
+ else if (strcmp(value, "1") == 0)
+ iso9660->opt.joliet = OPT_JOLIET_ENABLE;
+ else if (strcmp(value, "long") == 0)
+ iso9660->opt.joliet = OPT_JOLIET_LONGNAME;
+ else
+ goto invalid_value;
+ return (ARCHIVE_OK);
+ }
+ break;
+ case 'l':
+ if (strcmp(key, "limit-depth") == 0) {
+ iso9660->opt.limit_depth = value != NULL;
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "limit-dirs") == 0) {
+ iso9660->opt.limit_dirs = value != NULL;
+ return (ARCHIVE_OK);
+ }
+ break;
+ case 'p':
+ if (strcmp(key, "pad") == 0) {
+ iso9660->opt.pad = value != NULL;
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "publisher") == 0) {
+ r = get_str_opt(a,
+ &(iso9660->publisher_identifier),
+ PUBLISHER_IDENTIFIER_SIZE, key, value);
+ iso9660->opt.publisher = r == ARCHIVE_OK;
+ return (r);
+ }
+ break;
+ case 'r':
+ if (strcmp(key, "rockridge") == 0 ||
+ strcmp(key, "Rockridge") == 0) {
+ if (value == NULL)
+ iso9660->opt.rr = OPT_RR_DISABLED;
+ else if (strcmp(value, "1") == 0)
+ iso9660->opt.rr = OPT_RR_USEFUL;
+ else if (strcmp(value, "strict") == 0)
+ iso9660->opt.rr = OPT_RR_STRICT;
+ else if (strcmp(value, "useful") == 0)
+ iso9660->opt.rr = OPT_RR_USEFUL;
+ else
+ goto invalid_value;
+ return (ARCHIVE_OK);
+ }
+ break;
+ case 'v':
+ if (strcmp(key, "volume-id") == 0) {
+ r = get_str_opt(a, &(iso9660->volume_identifier),
+ VOLUME_IDENTIFIER_SIZE, key, value);
+ iso9660->opt.volume_id = r == ARCHIVE_OK;
+ return (r);
+ }
+ break;
+ case 'z':
+ if (strcmp(key, "zisofs") == 0) {
+ if (value == NULL)
+ iso9660->opt.zisofs = OPT_ZISOFS_DISABLED;
+ else {
+#ifdef HAVE_ZLIB_H
+ iso9660->opt.zisofs = OPT_ZISOFS_DIRECT;
+#else
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "``zisofs'' "
+ "is not supported on this platform.");
+ return (ARCHIVE_FATAL);
+#endif
+ }
+ return (ARCHIVE_OK);
+ }
+ break;
+ }
+
+ /* 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);
+
+invalid_value:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid value for option ``%s''", key);
+ return (ARCHIVE_FAILED);
+}
+
+static int
+iso9660_write_header(struct archive_write *a, struct archive_entry *entry)
+{
+ struct iso9660 *iso9660;
+ struct isofile *file;
+ struct isoent *isoent;
+ int r, ret = ARCHIVE_OK;
+
+ iso9660 = a->format_data;
+
+ iso9660->cur_file = NULL;
+ iso9660->bytes_remaining = 0;
+ iso9660->need_multi_extent = 0;
+ if (archive_entry_filetype(entry) == AE_IFLNK
+ && iso9660->opt.rr == OPT_RR_DISABLED) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Ignore symlink file.");
+ iso9660->cur_file = NULL;
+ return (ARCHIVE_WARN);
+ }
+ if (archive_entry_filetype(entry) == AE_IFREG &&
+ archive_entry_size(entry) >= MULTI_EXTENT_SIZE) {
+ if (iso9660->opt.iso_level < 3) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Ignore over %lld bytes file. "
+ "This file too large.",
+ MULTI_EXTENT_SIZE);
+ iso9660->cur_file = NULL;
+ return (ARCHIVE_WARN);
+ }
+ iso9660->need_multi_extent = 1;
+ }
+
+ file = isofile_new(a, entry);
+ if (file == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate data");
+ return (ARCHIVE_FATAL);
+ }
+ r = isofile_gen_utility_names(a, file);
+ if (r < ARCHIVE_WARN) {
+ isofile_free(file);
+ return (r);
+ }
+ else if (r < ret)
+ ret = r;
+
+ /*
+ * Ignore a path which looks like the top of directory name
+ * since we have already made the root directory of an ISO image.
+ */
+ if (archive_strlen(&(file->parentdir)) == 0 &&
+ archive_strlen(&(file->basename)) == 0) {
+ isofile_free(file);
+ return (r);
+ }
+
+ isofile_add_entry(iso9660, file);
+ isoent = isoent_new(file);
+ if (isoent == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate data");
+ return (ARCHIVE_FATAL);
+ }
+ if (isoent->file->dircnt > iso9660->dircnt_max)
+ iso9660->dircnt_max = isoent->file->dircnt;
+
+ /* Add the current file into tree */
+ r = isoent_tree(a, &isoent);
+ if (r != ARCHIVE_OK)
+ return (r);
+
+ /* If there is the same file in tree and
+ * the current file is older than the file in tree.
+ * So we don't need the current file data anymore. */
+ if (isoent->file != file)
+ return (ARCHIVE_OK);
+
+ /* Non regular files contents are unneeded to be saved to
+ * temporary files. */
+ if (archive_entry_filetype(file->entry) != AE_IFREG)
+ return (ret);
+
+ /*
+ * Set the current file to cur_file to read its contents.
+ */
+ iso9660->cur_file = file;
+
+ if (archive_entry_nlink(file->entry) > 1) {
+ r = isofile_register_hardlink(a, file);
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Prepare to save the contents of the file.
+ */
+ if (iso9660->temp_fd < 0) {
+ iso9660->temp_fd = __archive_mktemp(NULL);
+ if (iso9660->temp_fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't create temporary file");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ /* Save an offset of current file in temporary file. */
+ file->content.offset_of_temp = wb_offset(a);
+ file->cur_content = &(file->content);
+ r = zisofs_init(a, file);
+ if (r < ret)
+ ret = r;
+ iso9660->bytes_remaining = archive_entry_size(file->entry);
+
+ return (ret);
+}
+
+static int
+write_to_temp(struct archive_write *a, const void *buff, size_t s)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ ssize_t written;
+ const unsigned char *b;
+
+ b = (const unsigned char *)buff;
+ while (s) {
+ written = write(iso9660->temp_fd, b, s);
+ if (written < 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't write to temporary file");
+ return (ARCHIVE_FATAL);
+ }
+ s -= written;
+ b += written;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+wb_write_to_temp(struct archive_write *a, const void *buff, size_t s)
+{
+ const char *xp = buff;
+ size_t xs = s;
+
+ /*
+ * If a written data size is big enough to use system-call
+ * and there is no waiting data, this calls write_to_temp() in
+ * order to reduce a extra memory copy.
+ */
+ if (wb_remaining(a) == wb_buffmax() && s > (1024 * 16)) {
+ struct iso9660 *iso9660 = (struct iso9660 *)a->format_data;
+ xs = s % LOGICAL_BLOCK_SIZE;
+ iso9660->wbuff_offset += s - xs;
+ if (write_to_temp(a, buff, s - xs) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ if (xs == 0)
+ return (ARCHIVE_OK);
+ xp += s - xs;
+ }
+
+ while (xs) {
+ size_t size = xs;
+ if (size > wb_remaining(a))
+ size = wb_remaining(a);
+ memcpy(wb_buffptr(a), xp, size);
+ if (wb_consume(a, size) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ xs -= size;
+ xp += size;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+wb_write_padding_to_temp(struct archive_write *a, int64_t csize)
+{
+ size_t ns;
+ int ret;
+
+ ns = (size_t)(csize % LOGICAL_BLOCK_SIZE);
+ if (ns != 0)
+ ret = write_null(a, LOGICAL_BLOCK_SIZE - ns);
+ else
+ ret = ARCHIVE_OK;
+ return (ret);
+}
+
+static ssize_t
+write_iso9660_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ size_t ws;
+
+ if (iso9660->temp_fd < 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Couldn't create temporary file");
+ return (ARCHIVE_FATAL);
+ }
+
+ ws = s;
+ if (iso9660->need_multi_extent &&
+ (iso9660->cur_file->cur_content->size + ws) >=
+ (MULTI_EXTENT_SIZE - LOGICAL_BLOCK_SIZE)) {
+ struct content *con;
+ size_t ts;
+
+ ts = (size_t)(MULTI_EXTENT_SIZE - LOGICAL_BLOCK_SIZE -
+ iso9660->cur_file->cur_content->size);
+
+ if (iso9660->zisofs.detect_magic)
+ zisofs_detect_magic(a, buff, ts);
+
+ if (iso9660->zisofs.making) {
+ if (zisofs_write_to_temp(a, buff, ts) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } else {
+ if (wb_write_to_temp(a, buff, ts) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ iso9660->cur_file->cur_content->size += ts;
+ }
+
+ /* Write padding. */
+ if (wb_write_padding_to_temp(a,
+ iso9660->cur_file->cur_content->size) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Compute the logical block number. */
+ iso9660->cur_file->cur_content->blocks = (int)
+ ((iso9660->cur_file->cur_content->size
+ + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS);
+
+ /*
+ * Make next extent.
+ */
+ ws -= ts;
+ buff = (const void *)(((const unsigned char *)buff) + ts);
+ /* Make a content for next extent. */
+ con = calloc(1, sizeof(*con));
+ if (con == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate content data");
+ return (ARCHIVE_FATAL);
+ }
+ con->offset_of_temp = wb_offset(a);
+ iso9660->cur_file->cur_content->next = con;
+ iso9660->cur_file->cur_content = con;
+#ifdef HAVE_ZLIB_H
+ iso9660->zisofs.block_offset = 0;
+#endif
+ }
+
+ if (iso9660->zisofs.detect_magic)
+ zisofs_detect_magic(a, buff, ws);
+
+ if (iso9660->zisofs.making) {
+ if (zisofs_write_to_temp(a, buff, ws) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } else {
+ if (wb_write_to_temp(a, buff, ws) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ iso9660->cur_file->cur_content->size += ws;
+ }
+
+ return (s);
+}
+
+static ssize_t
+iso9660_write_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ ssize_t r;
+
+ if (iso9660->cur_file == NULL)
+ return (0);
+ if (archive_entry_filetype(iso9660->cur_file->entry) != AE_IFREG)
+ return (0);
+ if (s > iso9660->bytes_remaining)
+ s = (size_t)iso9660->bytes_remaining;
+ if (s == 0)
+ return (0);
+
+ r = write_iso9660_data(a, buff, s);
+ if (r > 0)
+ iso9660->bytes_remaining -= r;
+ return (r);
+}
+
+static int
+iso9660_finish_entry(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+
+ if (iso9660->cur_file == NULL)
+ return (ARCHIVE_OK);
+ if (archive_entry_filetype(iso9660->cur_file->entry) != AE_IFREG)
+ return (ARCHIVE_OK);
+ if (iso9660->cur_file->content.size == 0)
+ return (ARCHIVE_OK);
+
+ /* If there are unwritten data, write null data instead. */
+ while (iso9660->bytes_remaining > 0) {
+ size_t s;
+
+ s = (iso9660->bytes_remaining > a->null_length)?
+ a->null_length: (size_t)iso9660->bytes_remaining;
+ if (write_iso9660_data(a, a->nulls, s) < 0)
+ return (ARCHIVE_FATAL);
+ iso9660->bytes_remaining -= s;
+ }
+
+ if (iso9660->zisofs.making && zisofs_finish_entry(a) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Write padding. */
+ if (wb_write_padding_to_temp(a, iso9660->cur_file->cur_content->size)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Compute the logical block number. */
+ iso9660->cur_file->cur_content->blocks = (int)
+ ((iso9660->cur_file->cur_content->size
+ + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS);
+
+ /* Add the current file to data file list. */
+ isofile_add_data_file(iso9660, iso9660->cur_file);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+iso9660_close(struct archive_write *a)
+{
+ struct iso9660 *iso9660;
+ int ret, blocks;
+
+ iso9660 = a->format_data;
+
+ /*
+ * Write remaining data out to the temporary file.
+ */
+ if (wb_remaining(a) > 0) {
+ ret = wb_write_out(a);
+ if (ret < 0)
+ return (ret);
+ }
+
+ /*
+ * Preparations...
+ */
+#ifdef DEBUG
+ if (iso9660->birth_time == 0)
+#endif
+ time(&(iso9660->birth_time));
+
+ /*
+ * Prepare a bootable ISO image.
+ */
+ if (iso9660->opt.boot) {
+ /* Find out the boot file entry. */
+ ret = isoent_find_out_boot_file(a, iso9660->primary.rootent);
+ if (ret < 0)
+ return (ret);
+ /* Reconvert the boot file from zisofs'ed form to
+ * plain form. */
+ ret = zisofs_rewind_boot_file(a);
+ if (ret < 0)
+ return (ret);
+ /* Write remaining data out to the temporary file. */
+ if (wb_remaining(a) > 0) {
+ ret = wb_write_out(a);
+ if (ret < 0)
+ return (ret);
+ }
+ /* Create the boot catalog. */
+ ret = isoent_create_boot_catalog(a, iso9660->primary.rootent);
+ if (ret < 0)
+ return (ret);
+ }
+
+ /*
+ * Prepare joliet extensions.
+ */
+ if (iso9660->opt.joliet) {
+ /* Make a new tree for joliet. */
+ ret = isoent_clone_tree(a, &(iso9660->joliet.rootent),
+ iso9660->primary.rootent);
+ if (ret < 0)
+ return (ret);
+ /* Make sure we have UTF-16BE convertors.
+ * if there is no file entry, convertors are still
+ * uninitilized. */
+ if (iso9660->sconv_to_utf16be == NULL) {
+ iso9660->sconv_to_utf16be =
+ archive_string_conversion_to_charset(
+ &(a->archive), "UTF-16BE", 1);
+ if (iso9660->sconv_to_utf16be == NULL)
+ /* Couldn't allocate memory */
+ return (ARCHIVE_FATAL);
+ iso9660->sconv_from_utf16be =
+ archive_string_conversion_from_charset(
+ &(a->archive), "UTF-16BE", 1);
+ if (iso9660->sconv_from_utf16be == NULL)
+ /* Couldn't allocate memory */
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ /*
+ * Make Path Tables.
+ */
+ ret = isoent_make_path_table(a);
+ if (ret < 0)
+ return (ret);
+
+ /*
+ * Calculate a total volume size and setup all locations of
+ * contents of an iso9660 image.
+ */
+ blocks = SYSTEM_AREA_BLOCK
+ + PRIMARY_VOLUME_DESCRIPTOR_BLOCK
+ + VOLUME_DESCRIPTOR_SET_TERMINATOR_BLOCK
+ + NON_ISO_FILE_SYSTEM_INFORMATION_BLOCK;
+ if (iso9660->opt.boot)
+ blocks += BOOT_RECORD_DESCRIPTOR_BLOCK;
+ if (iso9660->opt.joliet)
+ blocks += SUPPLEMENTARY_VOLUME_DESCRIPTOR_BLOCK;
+ if (iso9660->opt.iso_level == 4)
+ blocks += SUPPLEMENTARY_VOLUME_DESCRIPTOR_BLOCK;
+
+ /* Setup the locations of Path Table. */
+ iso9660->primary.location_type_L_path_table = blocks;
+ blocks += iso9660->primary.path_table_block;
+ iso9660->primary.location_type_M_path_table = blocks;
+ blocks += iso9660->primary.path_table_block;
+ if (iso9660->opt.joliet) {
+ iso9660->joliet.location_type_L_path_table = blocks;
+ blocks += iso9660->joliet.path_table_block;
+ iso9660->joliet.location_type_M_path_table = blocks;
+ blocks += iso9660->joliet.path_table_block;
+ }
+
+ /* Setup the locations of directories. */
+ isoent_setup_directory_location(iso9660, blocks,
+ &(iso9660->primary));
+ blocks += iso9660->primary.total_dir_block;
+ if (iso9660->opt.joliet) {
+ isoent_setup_directory_location(iso9660, blocks,
+ &(iso9660->joliet));
+ blocks += iso9660->joliet.total_dir_block;
+ }
+
+ if (iso9660->opt.rr) {
+ iso9660->location_rrip_er = blocks;
+ blocks += RRIP_ER_BLOCK;
+ }
+
+ /* Setup the locations of all file contents. */
+ isoent_setup_file_location(iso9660, blocks);
+ blocks += iso9660->total_file_block;
+ if (iso9660->opt.boot && iso9660->opt.boot_info_table) {
+ ret = setup_boot_information(a);
+ if (ret < 0)
+ return (ret);
+ }
+
+ /* Now we have a total volume size. */
+ iso9660->volume_space_size = blocks;
+ if (iso9660->opt.pad)
+ iso9660->volume_space_size += PADDING_BLOCK;
+ iso9660->volume_sequence_number = 1;
+
+
+ /*
+ * Write an ISO 9660 image.
+ */
+
+ /* Switc to start using wbuff as file buffer. */
+ iso9660->wbuff_remaining = wb_buffmax();
+ iso9660->wbuff_type = WB_TO_STREAM;
+ iso9660->wbuff_offset = 0;
+ iso9660->wbuff_written = 0;
+ iso9660->wbuff_tail = 0;
+
+ /* Write The System Area */
+ ret = write_null(a, SYSTEM_AREA_BLOCK * LOGICAL_BLOCK_SIZE);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Write Primary Volume Descriptor */
+ ret = write_VD(a, &(iso9660->primary));
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ if (iso9660->opt.boot) {
+ /* Write Boot Record Volume Descriptor */
+ ret = write_VD_boot_record(a);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ if (iso9660->opt.iso_level == 4) {
+ /* Write Enhanced Volume Descriptor */
+ iso9660->primary.vdd_type = VDD_ENHANCED;
+ ret = write_VD(a, &(iso9660->primary));
+ iso9660->primary.vdd_type = VDD_PRIMARY;
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ if (iso9660->opt.joliet) {
+ ret = write_VD(a, &(iso9660->joliet));
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Write Volume Descriptor Set Terminator */
+ ret = write_VD_terminator(a);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Write Non-ISO File System Information */
+ ret = write_information_block(a);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Write Type L Path Table */
+ ret = write_path_table(a, 0, &(iso9660->primary));
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Write Type M Path Table */
+ ret = write_path_table(a, 1, &(iso9660->primary));
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ if (iso9660->opt.joliet) {
+ /* Write Type L Path Table */
+ ret = write_path_table(a, 0, &(iso9660->joliet));
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Write Type M Path Table */
+ ret = write_path_table(a, 1, &(iso9660->joliet));
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Write Directory Descriptors */
+ ret = write_directory_descriptors(a, &(iso9660->primary));
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ if (iso9660->opt.joliet) {
+ ret = write_directory_descriptors(a, &(iso9660->joliet));
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ if (iso9660->opt.rr) {
+ /* Write Rockridge ER(Extensions Reference) */
+ ret = write_rr_ER(a);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Write File Descriptors */
+ ret = write_file_descriptors(a);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Write Padding */
+ if (iso9660->opt.pad) {
+ ret = write_null(a, PADDING_BLOCK * LOGICAL_BLOCK_SIZE);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ if (iso9660->directories_too_deep != NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s: Directories too deep.",
+ archive_entry_pathname(
+ iso9660->directories_too_deep->file->entry));
+ return (ARCHIVE_WARN);
+ }
+
+ /* Write remaining data out. */
+ ret = wb_write_out(a);
+
+ return (ret);
+}
+
+static int
+iso9660_free(struct archive_write *a)
+{
+ struct iso9660 *iso9660;
+ int i, ret;
+
+ iso9660 = a->format_data;
+
+ /* Close the temporary file. */
+ if (iso9660->temp_fd >= 0)
+ close(iso9660->temp_fd);
+
+ /* Free some stuff for zisofs operations. */
+ ret = zisofs_free(a);
+
+ /* Remove directory entries in tree which includes file entries. */
+ isoent_free_all(iso9660->primary.rootent);
+ for (i = 0; i < iso9660->primary.max_depth; i++)
+ free(iso9660->primary.pathtbl[i].sorted);
+ free(iso9660->primary.pathtbl);
+
+ if (iso9660->opt.joliet) {
+ isoent_free_all(iso9660->joliet.rootent);
+ for (i = 0; i < iso9660->joliet.max_depth; i++)
+ free(iso9660->joliet.pathtbl[i].sorted);
+ free(iso9660->joliet.pathtbl);
+ }
+
+ /* Remove isofile entries. */
+ isofile_free_all_entries(iso9660);
+ isofile_free_hardlinks(iso9660);
+
+ archive_string_free(&(iso9660->cur_dirstr));
+ archive_string_free(&(iso9660->volume_identifier));
+ archive_string_free(&(iso9660->publisher_identifier));
+ archive_string_free(&(iso9660->data_preparer_identifier));
+ archive_string_free(&(iso9660->application_identifier));
+ archive_string_free(&(iso9660->copyright_file_identifier));
+ archive_string_free(&(iso9660->abstract_file_identifier));
+ archive_string_free(&(iso9660->bibliographic_file_identifier));
+ archive_string_free(&(iso9660->el_torito.catalog_filename));
+ archive_string_free(&(iso9660->el_torito.boot_filename));
+ archive_string_free(&(iso9660->el_torito.id));
+ archive_string_free(&(iso9660->utf16be));
+ archive_string_free(&(iso9660->mbs));
+
+ free(iso9660);
+ a->format_data = NULL;
+
+ return (ret);
+}
+
+/*
+ * Get the System Identifier
+ */
+static void
+get_system_identitier(char *system_id, size_t size)
+{
+#if defined(HAVE_SYS_UTSNAME_H)
+ struct utsname u;
+
+ uname(&u);
+ strncpy(system_id, u.sysname, size-1);
+ system_id[size-1] = '\0';
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ strncpy(system_id, "Windows", size-1);
+ system_id[size-1] = '\0';
+#else
+#error no way to get the system identifier on your platform.
+#endif
+}
+
+static void
+set_str(unsigned char *p, const char *s, size_t l, char f, const char *map)
+{
+ unsigned char c;
+
+ if (s == NULL)
+ s = "";
+ while ((c = *s++) != 0 && l > 0) {
+ if (c >= 0x80 || map[c] == 0)
+ {
+ /* illegal character */
+ if (c >= 'a' && c <= 'z') {
+ /* convert c from a-z to A-Z */
+ c -= 0x20;
+ } else
+ c = 0x5f;
+ }
+ *p++ = c;
+ l--;
+ }
+ /* If l isn't zero, fill p buffer by the character
+ * which indicated by f. */
+ if (l > 0)
+ memset(p , f, l);
+}
+
+static inline int
+joliet_allowed_char(unsigned char high, unsigned char low)
+{
+ int utf16 = (high << 8) | low;
+
+ if (utf16 <= 0x001F)
+ return (0);
+
+ switch (utf16) {
+ case 0x002A: /* '*' */
+ case 0x002F: /* '/' */
+ case 0x003A: /* ':' */
+ case 0x003B: /* ';' */
+ case 0x003F: /* '?' */
+ case 0x005C: /* '\' */
+ return (0);/* Not allowed. */
+ }
+ return (1);
+}
+
+static int
+set_str_utf16be(struct archive_write *a, unsigned char *p, const char *s,
+ size_t l, uint16_t uf, enum vdc vdc)
+{
+ size_t size, i;
+ int onepad;
+
+ if (s == NULL)
+ s = "";
+ if (l & 0x01) {
+ onepad = 1;
+ l &= ~1;
+ } else
+ onepad = 0;
+ if (vdc == VDC_UCS2) {
+ struct iso9660 *iso9660 = a->format_data;
+ if (archive_strncpy_l(&iso9660->utf16be, s, strlen(s),
+ iso9660->sconv_to_utf16be) != 0 && errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for UTF-16BE");
+ return (ARCHIVE_FATAL);
+ }
+ size = iso9660->utf16be.length;
+ if (size > l)
+ size = l;
+ memcpy(p, iso9660->utf16be.s, size);
+ } else {
+ const uint16_t *u16 = (const uint16_t *)s;
+
+ size = 0;
+ while (*u16++)
+ size += 2;
+ if (size > l)
+ size = l;
+ memcpy(p, s, size);
+ }
+ for (i = 0; i < size; i += 2, p += 2) {
+ if (!joliet_allowed_char(p[0], p[1]))
+ archive_be16enc(p, 0x005F);/* '_' */
+ }
+ l -= size;
+ while (l > 0) {
+ archive_be16enc(p, uf);
+ p += 2;
+ l -= 2;
+ }
+ if (onepad)
+ *p = 0;
+ return (ARCHIVE_OK);
+}
+
+static const char a_characters_map[0x80] = {
+/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 00-0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 10-1F */
+ 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 20-2F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 30-3F */
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40-4F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,/* 50-5F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 60-6F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 70-7F */
+};
+
+static const char a1_characters_map[0x80] = {
+/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 00-0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 10-1F */
+ 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 20-2F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 30-3F */
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40-4F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,/* 50-5F */
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 60-6F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,/* 70-7F */
+};
+
+static const char d_characters_map[0x80] = {
+/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 00-0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 10-1F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 20-2F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,/* 30-3F */
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40-4F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,/* 50-5F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 60-6F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 70-7F */
+};
+
+static const char d1_characters_map[0x80] = {
+/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 00-0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 10-1F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 20-2F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,/* 30-3F */
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40-4F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,/* 50-5F */
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 60-6F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,/* 70-7F */
+};
+
+static int
+set_str_a_characters_bp(struct archive_write *a, unsigned char *bp,
+ int from, int to, const char *s, enum vdc vdc)
+{
+ int r;
+
+ switch (vdc) {
+ case VDC_STD:
+ set_str(bp+from, s, to - from + 1, 0x20,
+ a_characters_map);
+ r = ARCHIVE_OK;
+ break;
+ case VDC_LOWERCASE:
+ set_str(bp+from, s, to - from + 1, 0x20,
+ a1_characters_map);
+ r = ARCHIVE_OK;
+ break;
+ case VDC_UCS2:
+ case VDC_UCS2_DIRECT:
+ r = set_str_utf16be(a, bp+from, s, to - from + 1,
+ 0x0020, vdc);
+ break;
+ default:
+ r = ARCHIVE_FATAL;
+ }
+ return (r);
+}
+
+static int
+set_str_d_characters_bp(struct archive_write *a, unsigned char *bp,
+ int from, int to, const char *s, enum vdc vdc)
+{
+ int r;
+
+ switch (vdc) {
+ case VDC_STD:
+ set_str(bp+from, s, to - from + 1, 0x20,
+ d_characters_map);
+ r = ARCHIVE_OK;
+ break;
+ case VDC_LOWERCASE:
+ set_str(bp+from, s, to - from + 1, 0x20,
+ d1_characters_map);
+ r = ARCHIVE_OK;
+ break;
+ case VDC_UCS2:
+ case VDC_UCS2_DIRECT:
+ r = set_str_utf16be(a, bp+from, s, to - from + 1,
+ 0x0020, vdc);
+ break;
+ default:
+ r = ARCHIVE_FATAL;
+ }
+ return (r);
+}
+
+static void
+set_VD_bp(unsigned char *bp, enum VD_type type, unsigned char ver)
+{
+
+ /* Volume Descriptor Type */
+ bp[1] = (unsigned char)type;
+ /* Standard Identifier */
+ memcpy(bp + 2, "CD001", 5);
+ /* Volume Descriptor Version */
+ bp[7] = ver;
+}
+
+static inline void
+set_unused_field_bp(unsigned char *bp, int from, int to)
+{
+ memset(bp + from, 0, to - from + 1);
+}
+
+/*
+ * 8-bit unsigned numerical values.
+ * ISO9660 Standard 7.1.1
+ */
+static inline void
+set_num_711(unsigned char *p, unsigned char value)
+{
+ *p = value;
+}
+
+/*
+ * 8-bit signed numerical values.
+ * ISO9660 Standard 7.1.2
+ */
+static inline void
+set_num_712(unsigned char *p, char value)
+{
+ *((char *)p) = value;
+}
+
+/*
+ * Least significant byte first.
+ * ISO9660 Standard 7.2.1
+ */
+static inline void
+set_num_721(unsigned char *p, uint16_t value)
+{
+ archive_le16enc(p, value);
+}
+
+/*
+ * Most significant byte first.
+ * ISO9660 Standard 7.2.2
+ */
+static inline void
+set_num_722(unsigned char *p, uint16_t value)
+{
+ archive_be16enc(p, value);
+}
+
+/*
+ * Both-byte orders.
+ * ISO9660 Standard 7.2.3
+ */
+static void
+set_num_723(unsigned char *p, uint16_t value)
+{
+ archive_le16enc(p, value);
+ archive_be16enc(p+2, value);
+}
+
+/*
+ * Least significant byte first.
+ * ISO9660 Standard 7.3.1
+ */
+static inline void
+set_num_731(unsigned char *p, uint32_t value)
+{
+ archive_le32enc(p, value);
+}
+
+/*
+ * Most significant byte first.
+ * ISO9660 Standard 7.3.2
+ */
+static inline void
+set_num_732(unsigned char *p, uint32_t value)
+{
+ archive_be32enc(p, value);
+}
+
+/*
+ * Both-byte orders.
+ * ISO9660 Standard 7.3.3
+ */
+static inline void
+set_num_733(unsigned char *p, uint32_t value)
+{
+ archive_le32enc(p, value);
+ archive_be32enc(p+4, value);
+}
+
+static void
+set_digit(unsigned char *p, size_t s, int value)
+{
+
+ while (s--) {
+ p[s] = '0' + (value % 10);
+ value /= 10;
+ }
+}
+
+#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
+#define get_gmoffset(tm) ((tm)->tm_gmtoff)
+#elif defined(HAVE_STRUCT_TM___TM_GMTOFF)
+#define get_gmoffset(tm) ((tm)->__tm_gmtoff)
+#else
+static long
+get_gmoffset(struct tm *tm)
+{
+ long offset;
+
+#if defined(HAVE__GET_TIMEZONE)
+ _get_timezone(&offset);
+#elif defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
+ offset = _timezone;
+#else
+ offset = timezone;
+#endif
+ offset *= -1;
+ if (tm->tm_isdst)
+ offset += 3600;
+ return (offset);
+}
+#endif
+
+static void
+get_tmfromtime(struct tm *tm, time_t *t)
+{
+#if HAVE_LOCALTIME_R
+ tzset();
+ localtime_r(t, tm);
+#elif HAVE__LOCALTIME64_S
+ _localtime64_s(tm, t);
+#else
+ memcpy(tm, localtime(t), sizeof(*tm));
+#endif
+}
+
+/*
+ * Date and Time Format.
+ * ISO9660 Standard 8.4.26.1
+ */
+static void
+set_date_time(unsigned char *p, time_t t)
+{
+ struct tm tm;
+
+ get_tmfromtime(&tm, &t);
+ set_digit(p, 4, tm.tm_year + 1900);
+ set_digit(p+4, 2, tm.tm_mon + 1);
+ set_digit(p+6, 2, tm.tm_mday);
+ set_digit(p+8, 2, tm.tm_hour);
+ set_digit(p+10, 2, tm.tm_min);
+ set_digit(p+12, 2, tm.tm_sec);
+ set_digit(p+14, 2, 0);
+ set_num_712(p+16, (char)(get_gmoffset(&tm)/(60*15)));
+}
+
+static void
+set_date_time_null(unsigned char *p)
+{
+ memset(p, '0', 16);
+ p[16] = 0;
+}
+
+static void
+set_time_915(unsigned char *p, time_t t)
+{
+ struct tm tm;
+
+ get_tmfromtime(&tm, &t);
+ set_num_711(p+0, tm.tm_year);
+ set_num_711(p+1, tm.tm_mon+1);
+ set_num_711(p+2, tm.tm_mday);
+ set_num_711(p+3, tm.tm_hour);
+ set_num_711(p+4, tm.tm_min);
+ set_num_711(p+5, tm.tm_sec);
+ set_num_712(p+6, (char)(get_gmoffset(&tm)/(60*15)));
+}
+
+
+/*
+ * Write SUSP "CE" System Use Entry.
+ */
+static int
+set_SUSP_CE(unsigned char *p, int location, int offset, int size)
+{
+ unsigned char *bp = p -1;
+ /* Extend the System Use Area
+ * "CE" Format:
+ * len ver
+ * +----+----+----+----+-----------+-----------+
+ * | 'C'| 'E'| 1C | 01 | LOCATION1 | LOCATION2 |
+ * +----+----+----+----+-----------+-----------+
+ * 0 1 2 3 4 12 20
+ * +-----------+
+ * | LOCATION3 |
+ * +-----------+
+ * 20 28
+ * LOCATION1 : Location of Continuation of System Use Area.
+ * LOCATION2 : Offset to Start of Continuation.
+ * LOCATION3 : Length of the Continuation.
+ */
+
+ bp[1] = 'C';
+ bp[2] = 'E';
+ bp[3] = RR_CE_SIZE; /* length */
+ bp[4] = 1; /* version */
+ set_num_733(bp+5, location);
+ set_num_733(bp+13, offset);
+ set_num_733(bp+21, size);
+ return (RR_CE_SIZE);
+}
+
+/*
+ * The functions, which names are beginning with extra_, are used to
+ * control extra records.
+ * The maximum size of a Directory Record is 254. When a filename is
+ * very long, all of RRIP data of a file won't stored to the Directory
+ * Record and so remaining RRIP data store to an extra record instead.
+ */
+static unsigned char *
+extra_open_record(unsigned char *bp, int dr_len, struct isoent *isoent,
+ struct ctl_extr_rec *ctl)
+{
+ ctl->bp = bp;
+ if (bp != NULL)
+ bp += dr_len;
+ ctl->use_extr = 0;
+ ctl->isoent = isoent;
+ ctl->ce_ptr = NULL;
+ ctl->cur_len = ctl->dr_len = dr_len;
+ ctl->limit = DR_LIMIT;
+
+ return (bp);
+}
+
+static void
+extra_close_record(struct ctl_extr_rec *ctl, int ce_size)
+{
+ int padding = 0;
+
+ if (ce_size > 0)
+ extra_tell_used_size(ctl, ce_size);
+ /* Padding. */
+ if (ctl->cur_len & 0x01) {
+ ctl->cur_len++;
+ if (ctl->bp != NULL)
+ ctl->bp[ctl->cur_len] = 0;
+ padding = 1;
+ }
+ if (ctl->use_extr) {
+ if (ctl->ce_ptr != NULL)
+ set_SUSP_CE(ctl->ce_ptr, ctl->extr_loc,
+ ctl->extr_off, ctl->cur_len - padding);
+ } else
+ ctl->dr_len = ctl->cur_len;
+}
+
+#define extra_space(ctl) ((ctl)->limit - (ctl)->cur_len)
+
+static unsigned char *
+extra_next_record(struct ctl_extr_rec *ctl, int length)
+{
+ int cur_len = ctl->cur_len;/* save cur_len */
+
+ /* Close the current extra record or Directory Record. */
+ extra_close_record(ctl, RR_CE_SIZE);
+
+ /* Get a next extra record. */
+ ctl->use_extr = 1;
+ if (ctl->bp != NULL) {
+ /* Storing data into an extra record. */
+ unsigned char *p;
+
+ /* Save the pointer where a CE extension will be
+ * stored to. */
+ ctl->ce_ptr = &ctl->bp[cur_len+1];
+ p = extra_get_record(ctl->isoent,
+ &ctl->limit, &ctl->extr_off, &ctl->extr_loc);
+ ctl->bp = p - 1;/* the base of bp offset is 1. */
+ } else
+ /* Calculating the size of an extra record. */
+ (void)extra_get_record(ctl->isoent,
+ &ctl->limit, NULL, NULL);
+ ctl->cur_len = 0;
+ /* Check if an extra record is almost full.
+ * If so, get a next one. */
+ if (extra_space(ctl) < length)
+ (void)extra_next_record(ctl, length);
+
+ return (ctl->bp);
+}
+
+static inline struct extr_rec *
+extra_last_record(struct isoent *isoent)
+{
+ if (isoent->extr_rec_list.first == NULL)
+ return (NULL);
+ return ((struct extr_rec *)(void *)
+ ((char *)(isoent->extr_rec_list.last)
+ - offsetof(struct extr_rec, next)));
+}
+
+static unsigned char *
+extra_get_record(struct isoent *isoent, int *space, int *off, int *loc)
+{
+ struct extr_rec *rec;
+
+ isoent = isoent->parent;
+ if (off != NULL) {
+ /* Storing data into an extra record. */
+ rec = isoent->extr_rec_list.current;
+ if (DR_SAFETY > LOGICAL_BLOCK_SIZE - rec->offset)
+ rec = rec->next;
+ } else {
+ /* Calculating the size of an extra record. */
+ rec = extra_last_record(isoent);
+ if (rec == NULL ||
+ DR_SAFETY > LOGICAL_BLOCK_SIZE - rec->offset) {
+ rec = malloc(sizeof(*rec));
+ if (rec == NULL)
+ return (NULL);
+ rec->location = 0;
+ rec->offset = 0;
+ /* Insert `rec` into the tail of isoent->extr_rec_list */
+ rec->next = NULL;
+ *isoent->extr_rec_list.last = rec;
+ isoent->extr_rec_list.last = &(rec->next);
+ }
+ }
+ *space = LOGICAL_BLOCK_SIZE - rec->offset - DR_SAFETY;
+ if (*space & 0x01)
+ *space -= 1;/* Keep padding space. */
+ if (off != NULL)
+ *off = rec->offset;
+ if (loc != NULL)
+ *loc = rec->location;
+ isoent->extr_rec_list.current = rec;
+
+ return (&rec->buf[rec->offset]);
+}
+
+static void
+extra_tell_used_size(struct ctl_extr_rec *ctl, int size)
+{
+ struct isoent *isoent;
+ struct extr_rec *rec;
+
+ if (ctl->use_extr) {
+ isoent = ctl->isoent->parent;
+ rec = isoent->extr_rec_list.current;
+ if (rec != NULL)
+ rec->offset += size;
+ }
+ ctl->cur_len += size;
+}
+
+static int
+extra_setup_location(struct isoent *isoent, int location)
+{
+ struct extr_rec *rec;
+ int cnt;
+
+ cnt = 0;
+ rec = isoent->extr_rec_list.first;
+ isoent->extr_rec_list.current = rec;
+ while (rec) {
+ cnt++;
+ rec->location = location++;
+ rec->offset = 0;
+ rec = rec->next;
+ }
+ return (cnt);
+}
+
+/*
+ * Create the RRIP entries.
+ */
+static int
+set_directory_record_rr(unsigned char *bp, int dr_len,
+ struct isoent *isoent, struct iso9660 *iso9660, enum dir_rec_type t)
+{
+ /* Flags(BP 5) of the Rockridge "RR" System Use Field */
+ unsigned char rr_flag;
+#define RR_USE_PX 0x01
+#define RR_USE_PN 0x02
+#define RR_USE_SL 0x04
+#define RR_USE_NM 0x08
+#define RR_USE_CL 0x10
+#define RR_USE_PL 0x20
+#define RR_USE_RE 0x40
+#define RR_USE_TF 0x80
+ int length;
+ struct ctl_extr_rec ctl;
+ struct isoent *rr_parent, *pxent;
+ struct isofile *file;
+
+ bp = extra_open_record(bp, dr_len, isoent, &ctl);
+
+ if (t == DIR_REC_PARENT) {
+ rr_parent = isoent->rr_parent;
+ pxent = isoent->parent;
+ if (rr_parent != NULL)
+ isoent = rr_parent;
+ else
+ isoent = isoent->parent;
+ } else {
+ rr_parent = NULL;
+ pxent = isoent;
+ }
+ file = isoent->file;
+
+ if (t != DIR_REC_NORMAL) {
+ rr_flag = RR_USE_PX | RR_USE_TF;
+ if (rr_parent != NULL)
+ rr_flag |= RR_USE_PL;
+ } else {
+ rr_flag = RR_USE_PX | RR_USE_NM | RR_USE_TF;
+ if (archive_entry_filetype(file->entry) == AE_IFLNK)
+ rr_flag |= RR_USE_SL;
+ if (isoent->rr_parent != NULL)
+ rr_flag |= RR_USE_RE;
+ if (isoent->rr_child != NULL)
+ rr_flag |= RR_USE_CL;
+ if (archive_entry_filetype(file->entry) == AE_IFCHR ||
+ archive_entry_filetype(file->entry) == AE_IFBLK)
+ rr_flag |= RR_USE_PN;
+#ifdef COMPAT_MKISOFS
+ /*
+ * mkisofs 2.01.01a63 records "RE" extension to
+ * the entry of "rr_moved" directory.
+ * I don't understand this behavior.
+ */
+ if (isoent->virtual &&
+ isoent->parent == iso9660->primary.rootent &&
+ strcmp(isoent->file->basename.s, "rr_moved") == 0)
+ rr_flag |= RR_USE_RE;
+#endif
+ }
+
+ /* Write "SP" System Use Entry. */
+ if (t == DIR_REC_SELF && isoent == isoent->parent) {
+ length = 7;
+ if (bp != NULL) {
+ bp[1] = 'S';
+ bp[2] = 'P';
+ bp[3] = length;
+ bp[4] = 1; /* version */
+ bp[5] = 0xBE; /* Check Byte */
+ bp[6] = 0xEF; /* Check Byte */
+ bp[7] = 0;
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ }
+
+ /* Write "RR" System Use Entry. */
+ length = 5;
+ if (extra_space(&ctl) < length)
+ bp = extra_next_record(&ctl, length);
+ if (bp != NULL) {
+ bp[1] = 'R';
+ bp[2] = 'R';
+ bp[3] = length;
+ bp[4] = 1; /* version */
+ bp[5] = rr_flag;
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+
+ /* Write "NM" System Use Entry. */
+ if (rr_flag & RR_USE_NM) {
+ /*
+ * "NM" Format:
+ * e.g. a basename is 'foo'
+ * len ver flg
+ * +----+----+----+----+----+----+----+----+
+ * | 'N'| 'M'| 08 | 01 | 00 | 'f'| 'o'| 'o'|
+ * +----+----+----+----+----+----+----+----+
+ * <----------------- len ----------------->
+ */
+ size_t nmlen = file->basename.length;
+ const char *nm = file->basename.s;
+ size_t nmmax;
+
+ if (extra_space(&ctl) < 6)
+ bp = extra_next_record(&ctl, 6);
+ if (bp != NULL) {
+ bp[1] = 'N';
+ bp[2] = 'M';
+ bp[4] = 1; /* version */
+ }
+ nmmax = extra_space(&ctl);
+ if (nmmax > 0xff)
+ nmmax = 0xff;
+ while (nmlen + 5 > nmmax) {
+ length = (int)nmmax;
+ if (bp != NULL) {
+ bp[3] = length;
+ bp[5] = 0x01;/* Alternate Name continues
+ * in next "NM" field */
+ memcpy(bp+6, nm, length - 5);
+ bp += length;
+ }
+ nmlen -= length - 5;
+ nm += length - 5;
+ extra_tell_used_size(&ctl, length);
+ if (extra_space(&ctl) < 6) {
+ bp = extra_next_record(&ctl, 6);
+ nmmax = extra_space(&ctl);
+ if (nmmax > 0xff)
+ nmmax = 0xff;
+ }
+ if (bp != NULL) {
+ bp[1] = 'N';
+ bp[2] = 'M';
+ bp[4] = 1; /* version */
+ }
+ }
+ length = 5 + (int)nmlen;
+ if (bp != NULL) {
+ bp[3] = length;
+ bp[5] = 0;
+ memcpy(bp+6, nm, nmlen);
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ }
+
+ /* Write "PX" System Use Entry. */
+ if (rr_flag & RR_USE_PX) {
+ /*
+ * "PX" Format:
+ * len ver
+ * +----+----+----+----+-----------+-----------+
+ * | 'P'| 'X'| 2C | 01 | FILE MODE | LINKS |
+ * +----+----+----+----+-----------+-----------+
+ * 0 1 2 3 4 12 20
+ * +-----------+-----------+------------------+
+ * | USER ID | GROUP ID |FILE SERIAL NUMBER|
+ * +-----------+-----------+------------------+
+ * 20 28 36 44
+ */
+ length = 44;
+ if (extra_space(&ctl) < length)
+ bp = extra_next_record(&ctl, length);
+ if (bp != NULL) {
+ mode_t mode;
+ int64_t uid;
+ int64_t gid;
+
+ mode = archive_entry_mode(file->entry);
+ uid = archive_entry_uid(file->entry);
+ gid = archive_entry_gid(file->entry);
+ if (iso9660->opt.rr == OPT_RR_USEFUL) {
+ /*
+ * This action is simular mkisofs -r option
+ * but our rockridge=useful option does not
+ * set a zero to uid and gid.
+ */
+ /* set all read bit ON */
+ mode |= 0444;
+#if !defined(_WIN32) && !defined(__CYGWIN__)
+ if (mode & 0111)
+#endif
+ /* set all exec bit ON */
+ mode |= 0111;
+ /* clear all write bits. */
+ mode &= ~0222;
+ /* clear setuid,setgid,sticky bits. */
+ mode &= ~07000;
+ }
+
+ bp[1] = 'P';
+ bp[2] = 'X';
+ bp[3] = length;
+ bp[4] = 1; /* version */
+ /* file mode */
+ set_num_733(bp+5, mode);
+ /* file links (stat.st_nlink) */
+ set_num_733(bp+13,
+ archive_entry_nlink(file->entry));
+ set_num_733(bp+21, (uint32_t)uid);
+ set_num_733(bp+29, (uint32_t)gid);
+ /* File Serial Number */
+ if (pxent->dir)
+ set_num_733(bp+37, pxent->dir_location);
+ else if (file->hardlink_target != NULL)
+ set_num_733(bp+37,
+ file->hardlink_target->cur_content->location);
+ else
+ set_num_733(bp+37,
+ file->cur_content->location);
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ }
+
+ /* Write "SL" System Use Entry. */
+ if (rr_flag & RR_USE_SL) {
+ /*
+ * "SL" Format:
+ * e.g. a symbolic name is 'foo/bar'
+ * len ver flg
+ * +----+----+----+----+----+------------+
+ * | 'S'| 'L'| 0F | 01 | 00 | components |
+ * +----+----+----+----+----+-----+------+
+ * 0 1 2 3 4 5 ...|... 15
+ * <----------------- len --------+------>
+ * components : |
+ * cflg clen |
+ * +----+----+----+----+----+ |
+ * | 00 | 03 | 'f'| 'o'| 'o'| <---+
+ * +----+----+----+----+----+ |
+ * 5 6 7 8 9 10 |
+ * cflg clen |
+ * +----+----+----+----+----+ |
+ * | 00 | 03 | 'b'| 'a'| 'r'| <---+
+ * +----+----+----+----+----+
+ * 10 11 12 13 14 15
+ *
+ * - cflg : flag of componet
+ * - clen : length of componet
+ */
+ const char *sl;
+ char sl_last;
+
+ if (extra_space(&ctl) < 7)
+ bp = extra_next_record(&ctl, 7);
+ sl = file->symlink.s;
+ sl_last = '\0';
+ if (bp != NULL) {
+ bp[1] = 'S';
+ bp[2] = 'L';
+ bp[4] = 1; /* version */
+ }
+ for (;;) {
+ unsigned char *nc, *cf, *cl, cldmy = 0;
+ int sllen, slmax;
+
+ slmax = extra_space(&ctl);
+ if (slmax > 0xff)
+ slmax = 0xff;
+ if (bp != NULL)
+ nc = &bp[6];
+ else
+ nc = NULL;
+ cf = cl = NULL;
+ sllen = 0;
+ while (*sl && sllen + 11 < slmax) {
+ if (sl_last == '\0' && sl[0] == '/') {
+ /*
+ * flg len
+ * +----+----+
+ * | 08 | 00 | ROOT component.
+ * +----+----+ ("/")
+ *
+ * Root component has to appear
+ * at the first component only.
+ */
+ if (nc != NULL) {
+ cf = nc++;
+ *cf = 0x08; /* ROOT */
+ *nc++ = 0;
+ }
+ sllen += 2;
+ sl++;
+ sl_last = '/';
+ cl = NULL;
+ continue;
+ }
+ if (((sl_last == '\0' || sl_last == '/') &&
+ sl[0] == '.' && sl[1] == '.' &&
+ (sl[2] == '/' || sl[2] == '\0')) ||
+ (sl[0] == '/' &&
+ sl[1] == '.' && sl[2] == '.' &&
+ (sl[3] == '/' || sl[3] == '\0'))) {
+ /*
+ * flg len
+ * +----+----+
+ * | 04 | 00 | PARENT component.
+ * +----+----+ ("..")
+ */
+ if (nc != NULL) {
+ cf = nc++;
+ *cf = 0x04; /* PARENT */
+ *nc++ = 0;
+ }
+ sllen += 2;
+ if (sl[0] == '/')
+ sl += 3;/* skip "/.." */
+ else
+ sl += 2;/* skip ".." */
+ sl_last = '.';
+ cl = NULL;
+ continue;
+ }
+ if (((sl_last == '\0' || sl_last == '/') &&
+ sl[0] == '.' &&
+ (sl[1] == '/' || sl[1] == '\0')) ||
+ (sl[0] == '/' && sl[1] == '.' &&
+ (sl[2] == '/' || sl[2] == '\0'))) {
+ /*
+ * flg len
+ * +----+----+
+ * | 02 | 00 | CURREENT component.
+ * +----+----+ (".")
+ */
+ if (nc != NULL) {
+ cf = nc++;
+ *cf = 0x02; /* CURRENT */
+ *nc++ = 0;
+ }
+ sllen += 2;
+ if (sl[0] == '/')
+ sl += 2;/* skip "/." */
+ else
+ sl ++; /* skip "." */
+ sl_last = '.';
+ cl = NULL;
+ continue;
+ }
+ if (sl[0] == '/' || cl == NULL) {
+ if (nc != NULL) {
+ cf = nc++;
+ *cf = 0;
+ cl = nc++;
+ *cl = 0;
+ } else
+ cl = &cldmy;
+ sllen += 2;
+ if (sl[0] == '/') {
+ sl_last = *sl++;
+ continue;
+ }
+ }
+ sl_last = *sl++;
+ if (nc != NULL) {
+ *nc++ = sl_last;
+ (*cl) ++;
+ }
+ sllen++;
+ }
+ if (*sl) {
+ length = 5 + sllen;
+ if (bp != NULL) {
+ /*
+ * Mark flg as CONTINUE component.
+ */
+ *cf |= 0x01;
+ /*
+ * len ver flg
+ * +----+----+----+----+----+-
+ * | 'S'| 'L'| XX | 01 | 01 |
+ * +----+----+----+----+----+-
+ * ^
+ * continues in next "SL"
+ */
+ bp[3] = length;
+ bp[5] = 0x01;/* This Symbolic Link
+ * continues in next
+ * "SL" field */
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ if (extra_space(&ctl) < 11)
+ bp = extra_next_record(&ctl, 11);
+ if (bp != NULL) {
+ /* Next 'SL' */
+ bp[1] = 'S';
+ bp[2] = 'L';
+ bp[4] = 1; /* version */
+ }
+ } else {
+ length = 5 + sllen;
+ if (bp != NULL) {
+ bp[3] = length;
+ bp[5] = 0;
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ break;
+ }
+ }
+ }
+
+ /* Write "TF" System Use Entry. */
+ if (rr_flag & RR_USE_TF) {
+ /*
+ * "TF" Format:
+ * len ver
+ * +----+----+----+----+-----+-------------+
+ * | 'T'| 'F'| XX | 01 |FLAGS| TIME STAMPS |
+ * +----+----+----+----+-----+-------------+
+ * 0 1 2 3 4 5 XX
+ * TIME STAMPS : ISO 9660 Standard 9.1.5.
+ * If TF_LONG_FORM FLAGS is set,
+ * use ISO9660 Standard 8.4.26.1.
+ */
+#define TF_CREATION 0x01 /* Creation time recorded */
+#define TF_MODIFY 0x02 /* Modification time recorded */
+#define TF_ACCESS 0x04 /* Last Access time recorded */
+#define TF_ATTRIBUTES 0x08 /* Last Attribute Change time recorded */
+#define TF_BACKUP 0x10 /* Last Backup time recorded */
+#define TF_EXPIRATION 0x20 /* Expiration time recorded */
+#define TF_EFFECTIVE 0x40 /* Effective time recorded */
+#define TF_LONG_FORM 0x80 /* ISO 9660 17-byte time format used */
+ unsigned char tf_flags;
+
+ length = 5;
+ tf_flags = 0;
+#ifndef COMPAT_MKISOFS
+ if (archive_entry_birthtime_is_set(file->entry) &&
+ archive_entry_birthtime(file->entry) <=
+ archive_entry_mtime(file->entry)) {
+ length += 7;
+ tf_flags |= TF_CREATION;
+ }
+#endif
+ if (archive_entry_mtime_is_set(file->entry)) {
+ length += 7;
+ tf_flags |= TF_MODIFY;
+ }
+ if (archive_entry_atime_is_set(file->entry)) {
+ length += 7;
+ tf_flags |= TF_ACCESS;
+ }
+ if (archive_entry_ctime_is_set(file->entry)) {
+ length += 7;
+ tf_flags |= TF_ATTRIBUTES;
+ }
+ if (extra_space(&ctl) < length)
+ bp = extra_next_record(&ctl, length);
+ if (bp != NULL) {
+ bp[1] = 'T';
+ bp[2] = 'F';
+ bp[3] = length;
+ bp[4] = 1; /* version */
+ bp[5] = tf_flags;
+ bp += 5;
+ /* Creation time */
+ if (tf_flags & TF_CREATION) {
+ set_time_915(bp+1,
+ archive_entry_birthtime(file->entry));
+ bp += 7;
+ }
+ /* Modification time */
+ if (tf_flags & TF_MODIFY) {
+ set_time_915(bp+1,
+ archive_entry_mtime(file->entry));
+ bp += 7;
+ }
+ /* Last Access time */
+ if (tf_flags & TF_ACCESS) {
+ set_time_915(bp+1,
+ archive_entry_atime(file->entry));
+ bp += 7;
+ }
+ /* Last Attribute Change time */
+ if (tf_flags & TF_ATTRIBUTES) {
+ set_time_915(bp+1,
+ archive_entry_ctime(file->entry));
+ bp += 7;
+ }
+ }
+ extra_tell_used_size(&ctl, length);
+ }
+
+ /* Write "RE" System Use Entry. */
+ if (rr_flag & RR_USE_RE) {
+ /*
+ * "RE" Format:
+ * len ver
+ * +----+----+----+----+
+ * | 'R'| 'E'| 04 | 01 |
+ * +----+----+----+----+
+ * 0 1 2 3 4
+ */
+ length = 4;
+ if (extra_space(&ctl) < length)
+ bp = extra_next_record(&ctl, length);
+ if (bp != NULL) {
+ bp[1] = 'R';
+ bp[2] = 'E';
+ bp[3] = length;
+ bp[4] = 1; /* version */
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ }
+
+ /* Write "PL" System Use Entry. */
+ if (rr_flag & RR_USE_PL) {
+ /*
+ * "PL" Format:
+ * len ver
+ * +----+----+----+----+------------+
+ * | 'P'| 'L'| 0C | 01 | *LOCATION |
+ * +----+----+----+----+------------+
+ * 0 1 2 3 4 12
+ * *LOCATION: location of parent directory
+ */
+ length = 12;
+ if (extra_space(&ctl) < length)
+ bp = extra_next_record(&ctl, length);
+ if (bp != NULL) {
+ bp[1] = 'P';
+ bp[2] = 'L';
+ bp[3] = length;
+ bp[4] = 1; /* version */
+ set_num_733(bp + 5,
+ rr_parent->dir_location);
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ }
+
+ /* Write "CL" System Use Entry. */
+ if (rr_flag & RR_USE_CL) {
+ /*
+ * "CL" Format:
+ * len ver
+ * +----+----+----+----+------------+
+ * | 'C'| 'L'| 0C | 01 | *LOCATION |
+ * +----+----+----+----+------------+
+ * 0 1 2 3 4 12
+ * *LOCATION: location of child directory
+ */
+ length = 12;
+ if (extra_space(&ctl) < length)
+ bp = extra_next_record(&ctl, length);
+ if (bp != NULL) {
+ bp[1] = 'C';
+ bp[2] = 'L';
+ bp[3] = length;
+ bp[4] = 1; /* version */
+ set_num_733(bp + 5,
+ isoent->rr_child->dir_location);
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ }
+
+ /* Write "PN" System Use Entry. */
+ if (rr_flag & RR_USE_PN) {
+ /*
+ * "PN" Format:
+ * len ver
+ * +----+----+----+----+------------+------------+
+ * | 'P'| 'N'| 14 | 01 | dev_t high | dev_t low |
+ * +----+----+----+----+------------+------------+
+ * 0 1 2 3 4 12 20
+ */
+ length = 20;
+ if (extra_space(&ctl) < length)
+ bp = extra_next_record(&ctl, length);
+ if (bp != NULL) {
+ uint64_t dev;
+
+ bp[1] = 'P';
+ bp[2] = 'N';
+ bp[3] = length;
+ bp[4] = 1; /* version */
+ dev = (uint64_t)archive_entry_rdev(file->entry);
+ set_num_733(bp + 5, (uint32_t)(dev >> 32));
+ set_num_733(bp + 13, (uint32_t)(dev & 0xFFFFFFFF));
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ }
+
+ /* Write "ZF" System Use Entry. */
+ if (file->zisofs.header_size) {
+ /*
+ * "ZF" Format:
+ * len ver
+ * +----+----+----+----+----+----+-------------+
+ * | 'Z'| 'F'| 10 | 01 | 'p'| 'z'| Header Size |
+ * +----+----+----+----+----+----+-------------+
+ * 0 1 2 3 4 5 6 7
+ * +--------------------+-------------------+
+ * | Log2 of block Size | Uncompressed Size |
+ * +--------------------+-------------------+
+ * 7 8 16
+ */
+ length = 16;
+ if (extra_space(&ctl) < length)
+ bp = extra_next_record(&ctl, length);
+ if (bp != NULL) {
+ bp[1] = 'Z';
+ bp[2] = 'F';
+ bp[3] = length;
+ bp[4] = 1; /* version */
+ bp[5] = 'p';
+ bp[6] = 'z';
+ bp[7] = file->zisofs.header_size;
+ bp[8] = file->zisofs.log2_bs;
+ set_num_733(bp + 9, file->zisofs.uncompressed_size);
+ bp += length;
+ }
+ extra_tell_used_size(&ctl, length);
+ }
+
+ /* Write "CE" System Use Entry. */
+ if (t == DIR_REC_SELF && isoent == isoent->parent) {
+ length = RR_CE_SIZE;
+ if (bp != NULL)
+ set_SUSP_CE(bp+1, iso9660->location_rrip_er,
+ 0, RRIP_ER_SIZE);
+ extra_tell_used_size(&ctl, length);
+ }
+
+ extra_close_record(&ctl, 0);
+
+ return (ctl.dr_len);
+}
+
+/*
+ * Write data of a Directory Record or calculate writing bytes itself.
+ * If parameter `p' is NULL, calculates the size of writing data, which
+ * a Directory Record needs to write, then it saved and return
+ * the calculated size.
+ * Parameter `n' is a remaining size of buffer. when parameter `p' is
+ * not NULL, check whether that `n' is not less than the saved size.
+ * if that `n' is small, return zero.
+ *
+ * This format of the Directory Record is according to
+ * ISO9660 Standard 9.1
+ */
+static int
+set_directory_record(unsigned char *p, size_t n, struct isoent *isoent,
+ struct iso9660 *iso9660, enum dir_rec_type t,
+ enum vdd_type vdd_type)
+{
+ unsigned char *bp;
+ size_t dr_len;
+ size_t fi_len;
+
+ if (p != NULL) {
+ /*
+ * Check whether a write buffer size is less than the
+ * saved size which is needed to write this Directory
+ * Record.
+ */
+ switch (t) {
+ case DIR_REC_VD:
+ dr_len = isoent->dr_len.vd; break;
+ case DIR_REC_SELF:
+ dr_len = isoent->dr_len.self; break;
+ case DIR_REC_PARENT:
+ dr_len = isoent->dr_len.parent; break;
+ case DIR_REC_NORMAL:
+ default:
+ dr_len = isoent->dr_len.normal; break;
+ }
+ if (dr_len > n)
+ return (0);/* Needs more buffer size. */
+ }
+
+ if (t == DIR_REC_NORMAL && isoent->identifier != NULL)
+ fi_len = isoent->id_len;
+ else
+ fi_len = 1;
+
+ if (p != NULL) {
+ struct isoent *xisoent;
+ struct isofile *file;
+ unsigned char flag;
+
+ if (t == DIR_REC_PARENT)
+ xisoent = isoent->parent;
+ else
+ xisoent = isoent;
+ file = isoent->file;
+ if (file->hardlink_target != NULL)
+ file = file->hardlink_target;
+ /* Make a file flag. */
+ if (xisoent->dir)
+ flag = FILE_FLAG_DIRECTORY;
+ else {
+ if (file->cur_content->next != NULL)
+ flag = FILE_FLAG_MULTI_EXTENT;
+ else
+ flag = 0;
+ }
+
+ bp = p -1;
+ /* Extended Attribute Record Length */
+ set_num_711(bp+2, 0);
+ /* Location of Extent */
+ if (xisoent->dir)
+ set_num_733(bp+3, xisoent->dir_location);
+ else
+ set_num_733(bp+3, file->cur_content->location);
+ /* Data Length */
+ if (xisoent->dir)
+ set_num_733(bp+11,
+ xisoent->dir_block * LOGICAL_BLOCK_SIZE);
+ else
+ set_num_733(bp+11, (uint32_t)file->cur_content->size);
+ /* Recording Date and Time */
+ /* NOTE:
+ * If a file type is symbolic link, you are seeing this
+ * field value is different from a value mkisofs makes.
+ * libarchive uses lstat to get this one, but it
+ * seems mkisofs uses stat to get.
+ */
+ set_time_915(bp+19,
+ archive_entry_mtime(xisoent->file->entry));
+ /* File Flags */
+ bp[26] = flag;
+ /* File Unit Size */
+ set_num_711(bp+27, 0);
+ /* Interleave Gap Size */
+ set_num_711(bp+28, 0);
+ /* Volume Sequence Number */
+ set_num_723(bp+29, iso9660->volume_sequence_number);
+ /* Length of File Identifier */
+ set_num_711(bp+33, (unsigned char)fi_len);
+ /* File Identifier */
+ switch (t) {
+ case DIR_REC_VD:
+ case DIR_REC_SELF:
+ set_num_711(bp+34, 0);
+ break;
+ case DIR_REC_PARENT:
+ set_num_711(bp+34, 1);
+ break;
+ case DIR_REC_NORMAL:
+ if (isoent->identifier != NULL)
+ memcpy(bp+34, isoent->identifier, fi_len);
+ else
+ set_num_711(bp+34, 0);
+ break;
+ }
+ } else
+ bp = NULL;
+ dr_len = 33 + fi_len;
+ /* Padding Field */
+ if (dr_len & 0x01) {
+ dr_len ++;
+ if (p != NULL)
+ bp[dr_len] = 0;
+ }
+
+ /* Volume Descriptor does not record extension. */
+ if (t == DIR_REC_VD) {
+ if (p != NULL)
+ /* Length of Directory Record */
+ set_num_711(p, (unsigned char)dr_len);
+ else
+ isoent->dr_len.vd = (int)dr_len;
+ return ((int)dr_len);
+ }
+
+ /* Rockridge */
+ if (iso9660->opt.rr && vdd_type != VDD_JOLIET)
+ dr_len = set_directory_record_rr(bp, (int)dr_len,
+ isoent, iso9660, t);
+
+ if (p != NULL)
+ /* Length of Directory Record */
+ set_num_711(p, (unsigned char)dr_len);
+ else {
+ /*
+ * Save the size which is needed to write this
+ * Directory Record.
+ */
+ switch (t) {
+ case DIR_REC_VD:
+ /* This case does not come, but compiler
+ * complains that DIR_REC_VD not handled
+ * in switch .... */
+ break;
+ case DIR_REC_SELF:
+ isoent->dr_len.self = (int)dr_len; break;
+ case DIR_REC_PARENT:
+ isoent->dr_len.parent = (int)dr_len; break;
+ case DIR_REC_NORMAL:
+ isoent->dr_len.normal = (int)dr_len; break;
+ }
+ }
+
+ return ((int)dr_len);
+}
+
+/*
+ * Calculate the size of a directory record.
+ */
+static inline int
+get_dir_rec_size(struct iso9660 *iso9660, struct isoent *isoent,
+ enum dir_rec_type t, enum vdd_type vdd_type)
+{
+
+ return (set_directory_record(NULL, SIZE_MAX,
+ isoent, iso9660, t, vdd_type));
+}
+
+/*
+ * Manage to write ISO-image data with wbuff to reduce calling
+ * __archive_write_output() for performance.
+ */
+
+
+static inline unsigned char *
+wb_buffptr(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = (struct iso9660 *)a->format_data;
+
+ return (&(iso9660->wbuff[sizeof(iso9660->wbuff)
+ - iso9660->wbuff_remaining]));
+}
+
+static int
+wb_write_out(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = (struct iso9660 *)a->format_data;
+ size_t wsize, nw;
+ int r;
+
+ wsize = sizeof(iso9660->wbuff) - iso9660->wbuff_remaining;
+ nw = wsize % LOGICAL_BLOCK_SIZE;
+ if (iso9660->wbuff_type == WB_TO_STREAM)
+ r = __archive_write_output(a, iso9660->wbuff, wsize - nw);
+ else
+ r = write_to_temp(a, iso9660->wbuff, wsize - nw);
+ /* Increase the offset. */
+ iso9660->wbuff_offset += wsize - nw;
+ if (iso9660->wbuff_offset > iso9660->wbuff_written)
+ iso9660->wbuff_written = iso9660->wbuff_offset;
+ iso9660->wbuff_remaining = sizeof(iso9660->wbuff);
+ if (nw) {
+ iso9660->wbuff_remaining -= nw;
+ memmove(iso9660->wbuff, iso9660->wbuff + wsize - nw, nw);
+ }
+ return (r);
+}
+
+static int
+wb_consume(struct archive_write *a, size_t size)
+{
+ struct iso9660 *iso9660 = (struct iso9660 *)a->format_data;
+
+ if (size > iso9660->wbuff_remaining ||
+ iso9660->wbuff_remaining == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Internal Programing error: iso9660:wb_consume()"
+ " size=%jd, wbuff_remaining=%jd",
+ (intmax_t)size, (intmax_t)iso9660->wbuff_remaining);
+ return (ARCHIVE_FATAL);
+ }
+ iso9660->wbuff_remaining -= size;
+ if (iso9660->wbuff_remaining < LOGICAL_BLOCK_SIZE)
+ return (wb_write_out(a));
+ return (ARCHIVE_OK);
+}
+
+#ifdef HAVE_ZLIB_H
+
+static int
+wb_set_offset(struct archive_write *a, int64_t off)
+{
+ struct iso9660 *iso9660 = (struct iso9660 *)a->format_data;
+ int64_t used, ext_bytes;
+
+ if (iso9660->wbuff_type != WB_TO_TEMP) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Internal Programing error: iso9660:wb_set_offset()");
+ return (ARCHIVE_FATAL);
+ }
+
+ used = sizeof(iso9660->wbuff) - iso9660->wbuff_remaining;
+ if (iso9660->wbuff_offset + used > iso9660->wbuff_tail)
+ iso9660->wbuff_tail = iso9660->wbuff_offset + used;
+ if (iso9660->wbuff_offset < iso9660->wbuff_written) {
+ if (used > 0 &&
+ write_to_temp(a, iso9660->wbuff, (size_t)used) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ iso9660->wbuff_offset = iso9660->wbuff_written;
+ lseek(iso9660->temp_fd, iso9660->wbuff_offset, SEEK_SET);
+ iso9660->wbuff_remaining = sizeof(iso9660->wbuff);
+ used = 0;
+ }
+ if (off < iso9660->wbuff_offset) {
+ /*
+ * Write out waiting data.
+ */
+ if (used > 0) {
+ if (wb_write_out(a) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ lseek(iso9660->temp_fd, off, SEEK_SET);
+ iso9660->wbuff_offset = off;
+ iso9660->wbuff_remaining = sizeof(iso9660->wbuff);
+ } else if (off <= iso9660->wbuff_tail) {
+ iso9660->wbuff_remaining = (size_t)
+ (sizeof(iso9660->wbuff) - (off - iso9660->wbuff_offset));
+ } else {
+ ext_bytes = off - iso9660->wbuff_tail;
+ iso9660->wbuff_remaining = (size_t)(sizeof(iso9660->wbuff)
+ - (iso9660->wbuff_tail - iso9660->wbuff_offset));
+ while (ext_bytes >= (int64_t)iso9660->wbuff_remaining) {
+ if (write_null(a, (size_t)iso9660->wbuff_remaining)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ ext_bytes -= iso9660->wbuff_remaining;
+ }
+ if (ext_bytes > 0) {
+ if (write_null(a, (size_t)ext_bytes) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ }
+ return (ARCHIVE_OK);
+}
+
+#endif /* HAVE_ZLIB_H */
+
+static int
+write_null(struct archive_write *a, size_t size)
+{
+ size_t remaining;
+ unsigned char *p, *old;
+ int r;
+
+ remaining = wb_remaining(a);
+ p = wb_buffptr(a);
+ if (size <= remaining) {
+ memset(p, 0, size);
+ return (wb_consume(a, size));
+ }
+ memset(p, 0, remaining);
+ r = wb_consume(a, remaining);
+ if (r != ARCHIVE_OK)
+ return (r);
+ size -= remaining;
+ old = p;
+ p = wb_buffptr(a);
+ memset(p, 0, old - p);
+ remaining = wb_remaining(a);
+ while (size) {
+ size_t wsize = size;
+
+ if (wsize > remaining)
+ wsize = remaining;
+ r = wb_consume(a, wsize);
+ if (r != ARCHIVE_OK)
+ return (r);
+ size -= wsize;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Write Volume Descriptor Set Terminator
+ */
+static int
+write_VD_terminator(struct archive_write *a)
+{
+ unsigned char *bp;
+
+ bp = wb_buffptr(a) -1;
+ set_VD_bp(bp, VDT_TERMINATOR, 1);
+ set_unused_field_bp(bp, 8, LOGICAL_BLOCK_SIZE);
+
+ return (wb_consume(a, LOGICAL_BLOCK_SIZE));
+}
+
+static int
+set_file_identifier(unsigned char *bp, int from, int to, enum vdc vdc,
+ struct archive_write *a, struct vdd *vdd, struct archive_string *id,
+ const char *label, int leading_under, enum char_type char_type)
+{
+ char identifier[256];
+ struct isoent *isoent;
+ const char *ids;
+ size_t len;
+ int r;
+
+ if (id->length > 0 && leading_under && id->s[0] != '_') {
+ if (char_type == A_CHAR)
+ r = set_str_a_characters_bp(a, bp, from, to, id->s, vdc);
+ else
+ r = set_str_d_characters_bp(a, bp, from, to, id->s, vdc);
+ } else if (id->length > 0) {
+ ids = id->s;
+ if (leading_under)
+ ids++;
+ isoent = isoent_find_entry(vdd->rootent, ids);
+ if (isoent == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Not Found %s `%s'.",
+ label, ids);
+ return (ARCHIVE_FATAL);
+ }
+ len = isoent->ext_off + isoent->ext_len;
+ if (vdd->vdd_type == VDD_JOLIET) {
+ if (len > sizeof(identifier)-2)
+ len = sizeof(identifier)-2;
+ } else {
+ if (len > sizeof(identifier)-1)
+ len = sizeof(identifier)-1;
+ }
+ memcpy(identifier, isoent->identifier, len);
+ identifier[len] = '\0';
+ if (vdd->vdd_type == VDD_JOLIET) {
+ identifier[len+1] = 0;
+ vdc = VDC_UCS2_DIRECT;
+ }
+ if (char_type == A_CHAR)
+ r = set_str_a_characters_bp(a, bp, from, to,
+ identifier, vdc);
+ else
+ r = set_str_d_characters_bp(a, bp, from, to,
+ identifier, vdc);
+ } else {
+ if (char_type == A_CHAR)
+ r = set_str_a_characters_bp(a, bp, from, to, NULL, vdc);
+ else
+ r = set_str_d_characters_bp(a, bp, from, to, NULL, vdc);
+ }
+ return (r);
+}
+
+/*
+ * Write Primary/Supplementary Volume Descriptor
+ */
+static int
+write_VD(struct archive_write *a, struct vdd *vdd)
+{
+ struct iso9660 *iso9660;
+ unsigned char *bp;
+ uint16_t volume_set_size = 1;
+ char identifier[256];
+ enum VD_type vdt;
+ enum vdc vdc;
+ unsigned char vd_ver, fst_ver;
+ int r;
+
+ iso9660 = a->format_data;
+ switch (vdd->vdd_type) {
+ case VDD_JOLIET:
+ vdt = VDT_SUPPLEMENTARY;
+ vd_ver = fst_ver = 1;
+ vdc = VDC_UCS2;
+ break;
+ case VDD_ENHANCED:
+ vdt = VDT_SUPPLEMENTARY;
+ vd_ver = fst_ver = 2;
+ vdc = VDC_LOWERCASE;
+ break;
+ case VDD_PRIMARY:
+ default:
+ vdt = VDT_PRIMARY;
+ vd_ver = fst_ver = 1;
+#ifdef COMPAT_MKISOFS
+ vdc = VDC_LOWERCASE;
+#else
+ vdc = VDC_STD;
+#endif
+ break;
+ }
+
+ bp = wb_buffptr(a) -1;
+ /* Volume Descriptor Type */
+ set_VD_bp(bp, vdt, vd_ver);
+ /* Unused Field */
+ set_unused_field_bp(bp, 8, 8);
+ /* System Identifier */
+ get_system_identitier(identifier, sizeof(identifier));
+ r = set_str_a_characters_bp(a, bp, 9, 40, identifier, vdc);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Volume Identifier */
+ r = set_str_d_characters_bp(a, bp, 41, 72,
+ iso9660->volume_identifier.s, vdc);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Unused Field */
+ set_unused_field_bp(bp, 73, 80);
+ /* Volume Space Size */
+ set_num_733(bp+81, iso9660->volume_space_size);
+ if (vdd->vdd_type == VDD_JOLIET) {
+ /* Escape Sequences */
+ bp[89] = 0x25;/* UCS-2 Level 3 */
+ bp[90] = 0x2F;
+ bp[91] = 0x45;
+ memset(bp + 92, 0, 120 - 92 + 1);
+ } else {
+ /* Unused Field */
+ set_unused_field_bp(bp, 89, 120);
+ }
+ /* Volume Set Size */
+ set_num_723(bp+121, volume_set_size);
+ /* Volume Sequence Number */
+ set_num_723(bp+125, iso9660->volume_sequence_number);
+ /* Logical Block Size */
+ set_num_723(bp+129, LOGICAL_BLOCK_SIZE);
+ /* Path Table Size */
+ set_num_733(bp+133, vdd->path_table_size);
+ /* Location of Occurrence of Type L Path Table */
+ set_num_731(bp+141, vdd->location_type_L_path_table);
+ /* Location of Optional Occurrence of Type L Path Table */
+ set_num_731(bp+145, 0);
+ /* Location of Occurrence of Type M Path Table */
+ set_num_732(bp+149, vdd->location_type_M_path_table);
+ /* Location of Optional Occurrence of Type M Path Table */
+ set_num_732(bp+153, 0);
+ /* Directory Record for Root Directory(BP 157 to 190) */
+ set_directory_record(bp+157, 190-157+1, vdd->rootent,
+ iso9660, DIR_REC_VD, vdd->vdd_type);
+ /* Volume Set Identifier */
+ r = set_str_d_characters_bp(a, bp, 191, 318, "", vdc);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Publisher Identifier */
+ r = set_file_identifier(bp, 319, 446, vdc, a, vdd,
+ &(iso9660->publisher_identifier),
+ "Publisher File", 1, A_CHAR);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Data Preparer Identifier */
+ r = set_file_identifier(bp, 447, 574, vdc, a, vdd,
+ &(iso9660->data_preparer_identifier),
+ "Data Preparer File", 1, A_CHAR);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Application Identifier */
+ r = set_file_identifier(bp, 575, 702, vdc, a, vdd,
+ &(iso9660->application_identifier),
+ "Application File", 1, A_CHAR);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Copyright File Identifier */
+ r = set_file_identifier(bp, 703, 739, vdc, a, vdd,
+ &(iso9660->copyright_file_identifier),
+ "Copyright File", 0, D_CHAR);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Abstract File Identifier */
+ r = set_file_identifier(bp, 740, 776, vdc, a, vdd,
+ &(iso9660->abstract_file_identifier),
+ "Abstract File", 0, D_CHAR);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Bibliongraphic File Identifier */
+ r = set_file_identifier(bp, 777, 813, vdc, a, vdd,
+ &(iso9660->bibliographic_file_identifier),
+ "Bibliongraphic File", 0, D_CHAR);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* Volume Creation Date and Time */
+ set_date_time(bp+814, iso9660->birth_time);
+ /* Volume Modification Date and Time */
+ set_date_time(bp+831, iso9660->birth_time);
+ /* Volume Expiration Date and Time(obsolete) */
+ set_date_time_null(bp+848);
+ /* Volume Effective Date and Time */
+ set_date_time(bp+865, iso9660->birth_time);
+ /* File Structure Version */
+ bp[882] = fst_ver;
+ /* Reserved */
+ bp[883] = 0;
+ /* Application Use */
+ memset(bp + 884, 0x20, 1395 - 884 + 1);
+ /* Reserved */
+ set_unused_field_bp(bp, 1396, LOGICAL_BLOCK_SIZE);
+
+ return (wb_consume(a, LOGICAL_BLOCK_SIZE));
+}
+
+/*
+ * Write Boot Record Volume Descriptor
+ */
+static int
+write_VD_boot_record(struct archive_write *a)
+{
+ struct iso9660 *iso9660;
+ unsigned char *bp;
+
+ iso9660 = a->format_data;
+ bp = wb_buffptr(a) -1;
+ /* Volume Descriptor Type */
+ set_VD_bp(bp, VDT_BOOT_RECORD, 1);
+ /* Boot System Identifier */
+ memcpy(bp+8, "EL TORITO SPECIFICATION", 23);
+ set_unused_field_bp(bp, 8+23, 39);
+ /* Unused */
+ set_unused_field_bp(bp, 40, 71);
+ /* Absolute pointer to first sector of Boot Catalog */
+ set_num_731(bp+72,
+ iso9660->el_torito.catalog->file->content.location);
+ /* Unused */
+ set_unused_field_bp(bp, 76, LOGICAL_BLOCK_SIZE);
+
+ return (wb_consume(a, LOGICAL_BLOCK_SIZE));
+}
+
+enum keytype {
+ KEY_FLG,
+ KEY_STR,
+ KEY_INT,
+ KEY_HEX
+};
+static void
+set_option_info(struct archive_string *info, int *opt, const char *key,
+ enum keytype type, ...)
+{
+ va_list ap;
+ char prefix;
+ const char *s;
+ int d;
+
+ prefix = (*opt==0)? ' ':',';
+ va_start(ap, type);
+ switch (type) {
+ case KEY_FLG:
+ d = va_arg(ap, int);
+ archive_string_sprintf(info, "%c%s%s",
+ prefix, (d == 0)?"!":"", key);
+ break;
+ case KEY_STR:
+ s = va_arg(ap, const char *);
+ archive_string_sprintf(info, "%c%s=%s",
+ prefix, key, s);
+ break;
+ case KEY_INT:
+ d = va_arg(ap, int);
+ archive_string_sprintf(info, "%c%s=%d",
+ prefix, key, d);
+ break;
+ case KEY_HEX:
+ d = va_arg(ap, int);
+ archive_string_sprintf(info, "%c%s=%x",
+ prefix, key, d);
+ break;
+ }
+ va_end(ap);
+
+ *opt = 1;
+}
+
+/*
+ * Make Non-ISO File System Information
+ */
+static int
+write_information_block(struct archive_write *a)
+{
+ struct iso9660 *iso9660;
+ char buf[128];
+ const char *v;
+ int opt, r;
+ struct archive_string info;
+ size_t info_size = LOGICAL_BLOCK_SIZE *
+ NON_ISO_FILE_SYSTEM_INFORMATION_BLOCK;
+
+ iso9660 = (struct iso9660 *)a->format_data;
+ if (info_size > wb_remaining(a)) {
+ r = wb_write_out(a);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+ archive_string_init(&info);
+ if (archive_string_ensure(&info, info_size) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ memset(info.s, 0, info_size);
+ opt = 0;
+#if defined(HAVE__CTIME64_S)
+ _ctime64_s(buf, sizeof(buf), &(iso9660->birth_time));
+#elif defined(HAVE_CTIME_R)
+ ctime_r(&(iso9660->birth_time), buf);
+#else
+ strncpy(buf, ctime(&(iso9660->birth_time)), sizeof(buf)-1);
+ buf[sizeof(buf)-1] = '\0';
+#endif
+ archive_string_sprintf(&info,
+ "INFO %s%s", buf, archive_version_string());
+ if (iso9660->opt.abstract_file != OPT_ABSTRACT_FILE_DEFAULT)
+ set_option_info(&info, &opt, "abstract-file",
+ KEY_STR, iso9660->abstract_file_identifier.s);
+ if (iso9660->opt.application_id != OPT_APPLICATION_ID_DEFAULT)
+ set_option_info(&info, &opt, "application-id",
+ KEY_STR, iso9660->application_identifier.s);
+ if (iso9660->opt.allow_vernum != OPT_ALLOW_VERNUM_DEFAULT)
+ set_option_info(&info, &opt, "allow-vernum",
+ KEY_FLG, iso9660->opt.allow_vernum);
+ if (iso9660->opt.biblio_file != OPT_BIBLIO_FILE_DEFAULT)
+ set_option_info(&info, &opt, "biblio-file",
+ KEY_STR, iso9660->bibliographic_file_identifier.s);
+ if (iso9660->opt.boot != OPT_BOOT_DEFAULT)
+ set_option_info(&info, &opt, "boot",
+ KEY_STR, iso9660->el_torito.boot_filename.s);
+ if (iso9660->opt.boot_catalog != OPT_BOOT_CATALOG_DEFAULT)
+ set_option_info(&info, &opt, "boot-catalog",
+ KEY_STR, iso9660->el_torito.catalog_filename.s);
+ if (iso9660->opt.boot_info_table != OPT_BOOT_INFO_TABLE_DEFAULT)
+ set_option_info(&info, &opt, "boot-info-table",
+ KEY_FLG, iso9660->opt.boot_info_table);
+ if (iso9660->opt.boot_load_seg != OPT_BOOT_LOAD_SEG_DEFAULT)
+ set_option_info(&info, &opt, "boot-load-seg",
+ KEY_HEX, iso9660->el_torito.boot_load_seg);
+ if (iso9660->opt.boot_load_size != OPT_BOOT_LOAD_SIZE_DEFAULT)
+ set_option_info(&info, &opt, "boot-load-size",
+ KEY_INT, iso9660->el_torito.boot_load_size);
+ if (iso9660->opt.boot_type != OPT_BOOT_TYPE_DEFAULT) {
+ v = "no-emulation";
+ if (iso9660->opt.boot_type == OPT_BOOT_TYPE_FD)
+ v = "fd";
+ if (iso9660->opt.boot_type == OPT_BOOT_TYPE_HARD_DISK)
+ v = "hard-disk";
+ set_option_info(&info, &opt, "boot-type",
+ KEY_STR, v);
+ }
+#ifdef HAVE_ZLIB_H
+ if (iso9660->opt.compression_level != OPT_COMPRESSION_LEVEL_DEFAULT)
+ set_option_info(&info, &opt, "compression-level",
+ KEY_INT, iso9660->zisofs.compression_level);
+#endif
+ if (iso9660->opt.copyright_file != OPT_COPYRIGHT_FILE_DEFAULT)
+ set_option_info(&info, &opt, "copyright-file",
+ KEY_STR, iso9660->copyright_file_identifier.s);
+ if (iso9660->opt.iso_level != OPT_ISO_LEVEL_DEFAULT)
+ set_option_info(&info, &opt, "iso-level",
+ KEY_INT, iso9660->opt.iso_level);
+ if (iso9660->opt.joliet != OPT_JOLIET_DEFAULT) {
+ if (iso9660->opt.joliet == OPT_JOLIET_LONGNAME)
+ set_option_info(&info, &opt, "joliet",
+ KEY_STR, "long");
+ else
+ set_option_info(&info, &opt, "joliet",
+ KEY_FLG, iso9660->opt.joliet);
+ }
+ if (iso9660->opt.limit_depth != OPT_LIMIT_DEPTH_DEFAULT)
+ set_option_info(&info, &opt, "limit-depth",
+ KEY_FLG, iso9660->opt.limit_depth);
+ if (iso9660->opt.limit_dirs != OPT_LIMIT_DIRS_DEFAULT)
+ set_option_info(&info, &opt, "limit-dirs",
+ KEY_FLG, iso9660->opt.limit_dirs);
+ if (iso9660->opt.pad != OPT_PAD_DEFAULT)
+ set_option_info(&info, &opt, "pad",
+ KEY_FLG, iso9660->opt.pad);
+ if (iso9660->opt.publisher != OPT_PUBLISHER_DEFAULT)
+ set_option_info(&info, &opt, "publisher",
+ KEY_STR, iso9660->publisher_identifier.s);
+ if (iso9660->opt.rr != OPT_RR_DEFAULT) {
+ if (iso9660->opt.rr == OPT_RR_DISABLED)
+ set_option_info(&info, &opt, "rockridge",
+ KEY_FLG, iso9660->opt.rr);
+ else if (iso9660->opt.rr == OPT_RR_STRICT)
+ set_option_info(&info, &opt, "rockridge",
+ KEY_STR, "strict");
+ else if (iso9660->opt.rr == OPT_RR_USEFUL)
+ set_option_info(&info, &opt, "rockridge",
+ KEY_STR, "useful");
+ }
+ if (iso9660->opt.volume_id != OPT_VOLUME_ID_DEFAULT)
+ set_option_info(&info, &opt, "volume-id",
+ KEY_STR, iso9660->volume_identifier.s);
+ if (iso9660->opt.zisofs != OPT_ZISOFS_DEFAULT)
+ set_option_info(&info, &opt, "zisofs",
+ KEY_FLG, iso9660->opt.zisofs);
+
+ memcpy(wb_buffptr(a), info.s, info_size);
+ archive_string_free(&info);
+ return (wb_consume(a, info_size));
+}
+
+static int
+write_rr_ER(struct archive_write *a)
+{
+ unsigned char *p;
+
+ p = wb_buffptr(a);
+
+ memset(p, 0, LOGICAL_BLOCK_SIZE);
+ p[0] = 'E';
+ p[1] = 'R';
+ p[3] = 0x01;
+ p[2] = RRIP_ER_SIZE;
+ p[4] = RRIP_ER_ID_SIZE;
+ p[5] = RRIP_ER_DSC_SIZE;
+ p[6] = RRIP_ER_SRC_SIZE;
+ p[7] = 0x01;
+ memcpy(&p[8], rrip_identifier, p[4]);
+ memcpy(&p[8+p[4]], rrip_descriptor, p[5]);
+ memcpy(&p[8+p[4]+p[5]], rrip_source, p[6]);
+
+ return (wb_consume(a, LOGICAL_BLOCK_SIZE));
+}
+
+static void
+calculate_path_table_size(struct vdd *vdd)
+{
+ int depth, size;
+ struct path_table *pt;
+
+ pt = vdd->pathtbl;
+ size = 0;
+ for (depth = 0; depth < vdd->max_depth; depth++) {
+ struct isoent **ptbl;
+ int i, cnt;
+
+ if ((cnt = pt[depth].cnt) == 0)
+ break;
+
+ ptbl = pt[depth].sorted;
+ for (i = 0; i < cnt; i++) {
+ int len;
+
+ if (ptbl[i]->identifier == NULL)
+ len = 1; /* root directory */
+ else
+ len = ptbl[i]->id_len;
+ if (len & 0x01)
+ len++; /* Padding Field */
+ size += 8 + len;
+ }
+ }
+ vdd->path_table_size = size;
+ vdd->path_table_block =
+ ((size + PATH_TABLE_BLOCK_SIZE -1) /
+ PATH_TABLE_BLOCK_SIZE) *
+ (PATH_TABLE_BLOCK_SIZE / LOGICAL_BLOCK_SIZE);
+}
+
+static int
+_write_path_table(struct archive_write *a, int type_m, int depth,
+ struct vdd *vdd)
+{
+ unsigned char *bp, *wb;
+ struct isoent **ptbl;
+ size_t wbremaining;
+ int i, r, wsize;
+
+ if (vdd->pathtbl[depth].cnt == 0)
+ return (0);
+
+ wsize = 0;
+ wb = wb_buffptr(a);
+ wbremaining = wb_remaining(a);
+ bp = wb - 1;
+ ptbl = vdd->pathtbl[depth].sorted;
+ for (i = 0; i < vdd->pathtbl[depth].cnt; i++) {
+ struct isoent *np;
+ size_t len;
+
+ np = ptbl[i];
+ if (np->identifier == NULL)
+ len = 1; /* root directory */
+ else
+ len = np->id_len;
+ if (wbremaining - ((bp+1) - wb) < (len + 1 + 8)) {
+ r = wb_consume(a, (bp+1) - wb);
+ if (r < 0)
+ return (r);
+ wb = wb_buffptr(a);
+ wbremaining = wb_remaining(a);
+ bp = wb -1;
+ }
+ /* Length of Directory Identifier */
+ set_num_711(bp+1, (unsigned char)len);
+ /* Extended Attribute Record Length */
+ set_num_711(bp+2, 0);
+ /* Location of Extent */
+ if (type_m)
+ set_num_732(bp+3, np->dir_location);
+ else
+ set_num_731(bp+3, np->dir_location);
+ /* Parent Directory Number */
+ if (type_m)
+ set_num_722(bp+7, np->parent->dir_number);
+ else
+ set_num_721(bp+7, np->parent->dir_number);
+ /* Directory Identifier */
+ if (np->identifier == NULL)
+ bp[9] = 0;
+ else
+ memcpy(&bp[9], np->identifier, len);
+ if (len & 0x01) {
+ /* Padding Field */
+ bp[9+len] = 0;
+ len++;
+ }
+ wsize += 8 + (int)len;
+ bp += 8 + len;
+ }
+ if ((bp + 1) > wb) {
+ r = wb_consume(a, (bp+1)-wb);
+ if (r < 0)
+ return (r);
+ }
+ return (wsize);
+}
+
+static int
+write_path_table(struct archive_write *a, int type_m, struct vdd *vdd)
+{
+ int depth, r;
+ size_t path_table_size;
+
+ r = ARCHIVE_OK;
+ path_table_size = 0;
+ for (depth = 0; depth < vdd->max_depth; depth++) {
+ r = _write_path_table(a, type_m, depth, vdd);
+ if (r < 0)
+ return (r);
+ path_table_size += r;
+ }
+
+ /* Write padding data. */
+ path_table_size = path_table_size % PATH_TABLE_BLOCK_SIZE;
+ if (path_table_size > 0)
+ r = write_null(a, PATH_TABLE_BLOCK_SIZE - path_table_size);
+ return (r);
+}
+
+static int
+calculate_directory_descriptors(struct iso9660 *iso9660, struct vdd *vdd,
+ struct isoent *isoent, int depth)
+{
+ struct isoent **enttbl;
+ int bs, block, i;
+
+ block = 1;
+ bs = get_dir_rec_size(iso9660, isoent, DIR_REC_SELF, vdd->vdd_type);
+ bs += get_dir_rec_size(iso9660, isoent, DIR_REC_PARENT, vdd->vdd_type);
+
+ if (isoent->children.cnt <= 0 || (vdd->vdd_type != VDD_JOLIET &&
+ !iso9660->opt.rr && depth + 1 >= vdd->max_depth))
+ return (block);
+
+ enttbl = isoent->children_sorted;
+ for (i = 0; i < isoent->children.cnt; i++) {
+ struct isoent *np = enttbl[i];
+ struct isofile *file;
+
+ file = np->file;
+ if (file->hardlink_target != NULL)
+ file = file->hardlink_target;
+ file->cur_content = &(file->content);
+ do {
+ int dr_l;
+
+ dr_l = get_dir_rec_size(iso9660, np, DIR_REC_NORMAL,
+ vdd->vdd_type);
+ if ((bs + dr_l) > LOGICAL_BLOCK_SIZE) {
+ block ++;
+ bs = dr_l;
+ } else
+ bs += dr_l;
+ file->cur_content = file->cur_content->next;
+ } while (file->cur_content != NULL);
+ }
+ return (block);
+}
+
+static int
+_write_directory_descriptors(struct archive_write *a, struct vdd *vdd,
+ struct isoent *isoent, int depth)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isoent **enttbl;
+ unsigned char *p, *wb;
+ int i, r;
+ int dr_l;
+
+ p = wb = wb_buffptr(a);
+#define WD_REMAINING (LOGICAL_BLOCK_SIZE - (p - wb))
+ p += set_directory_record(p, WD_REMAINING, isoent,
+ iso9660, DIR_REC_SELF, vdd->vdd_type);
+ p += set_directory_record(p, WD_REMAINING, isoent,
+ iso9660, DIR_REC_PARENT, vdd->vdd_type);
+
+ if (isoent->children.cnt <= 0 || (vdd->vdd_type != VDD_JOLIET &&
+ !iso9660->opt.rr && depth + 1 >= vdd->max_depth)) {
+ memset(p, 0, WD_REMAINING);
+ return (wb_consume(a, LOGICAL_BLOCK_SIZE));
+ }
+
+ enttbl = isoent->children_sorted;
+ for (i = 0; i < isoent->children.cnt; i++) {
+ struct isoent *np = enttbl[i];
+ struct isofile *file = np->file;
+
+ if (file->hardlink_target != NULL)
+ file = file->hardlink_target;
+ file->cur_content = &(file->content);
+ do {
+ dr_l = set_directory_record(p, WD_REMAINING,
+ np, iso9660, DIR_REC_NORMAL,
+ vdd->vdd_type);
+ if (dr_l == 0) {
+ memset(p, 0, WD_REMAINING);
+ r = wb_consume(a, LOGICAL_BLOCK_SIZE);
+ if (r < 0)
+ return (r);
+ p = wb = wb_buffptr(a);
+ dr_l = set_directory_record(p,
+ WD_REMAINING, np, iso9660,
+ DIR_REC_NORMAL, vdd->vdd_type);
+ }
+ p += dr_l;
+ file->cur_content = file->cur_content->next;
+ } while (file->cur_content != NULL);
+ }
+ memset(p, 0, WD_REMAINING);
+ return (wb_consume(a, LOGICAL_BLOCK_SIZE));
+}
+
+static int
+write_directory_descriptors(struct archive_write *a, struct vdd *vdd)
+{
+ struct isoent *np;
+ int depth, r;
+
+ depth = 0;
+ np = vdd->rootent;
+ do {
+ struct extr_rec *extr;
+
+ r = _write_directory_descriptors(a, vdd, np, depth);
+ if (r < 0)
+ return (r);
+ if (vdd->vdd_type != VDD_JOLIET) {
+ /*
+ * This extract record is used by SUSP,RRIP.
+ * Not for joliet.
+ */
+ for (extr = np->extr_rec_list.first;
+ extr != NULL;
+ extr = extr->next) {
+ unsigned char *wb;
+
+ wb = wb_buffptr(a);
+ memcpy(wb, extr->buf, extr->offset);
+ memset(wb + extr->offset, 0,
+ LOGICAL_BLOCK_SIZE - extr->offset);
+ r = wb_consume(a, LOGICAL_BLOCK_SIZE);
+ if (r < 0)
+ return (r);
+ }
+ }
+
+ if (np->subdirs.first != NULL && depth + 1 < vdd->max_depth) {
+ /* Enter to sub directories. */
+ np = np->subdirs.first;
+ depth++;
+ continue;
+ }
+ while (np != np->parent) {
+ if (np->drnext == NULL) {
+ /* Return to the parent directory. */
+ np = np->parent;
+ depth--;
+ } else {
+ np = np->drnext;
+ break;
+ }
+ }
+ } while (np != np->parent);
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Read file contents from the temporary file, and write it.
+ */
+static int
+write_file_contents(struct archive_write *a, int64_t offset, int64_t size)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ int r;
+
+ lseek(iso9660->temp_fd, offset, SEEK_SET);
+
+ while (size) {
+ size_t rsize;
+ ssize_t rs;
+ unsigned char *wb;
+
+ wb = wb_buffptr(a);
+ rsize = wb_remaining(a);
+ if (rsize > (size_t)size)
+ rsize = (size_t)size;
+ rs = read(iso9660->temp_fd, wb, rsize);
+ if (rs <= 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't read temporary file(%jd)", (intmax_t)rs);
+ return (ARCHIVE_FATAL);
+ }
+ size -= rs;
+ r = wb_consume(a, rs);
+ if (r < 0)
+ return (r);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+write_file_descriptors(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isofile *file;
+ int64_t blocks, offset;
+ int r;
+
+ blocks = 0;
+ offset = 0;
+
+ /* Make the boot catalog contents, and write it. */
+ if (iso9660->el_torito.catalog != NULL) {
+ r = make_boot_catalog(a);
+ if (r < 0)
+ return (r);
+ }
+
+ /* Write the boot file contents. */
+ if (iso9660->el_torito.boot != NULL) {
+ file = iso9660->el_torito.boot->file;
+ blocks = file->content.blocks;
+ offset = file->content.offset_of_temp;
+ if (offset != 0) {
+ r = write_file_contents(a, offset,
+ blocks << LOGICAL_BLOCK_BITS);
+ if (r < 0)
+ return (r);
+ blocks = 0;
+ offset = 0;
+ }
+ }
+
+ /* Write out all file contents. */
+ for (file = iso9660->data_file_list.first;
+ file != NULL; file = file->datanext) {
+
+ if (!file->write_content)
+ continue;
+
+ if ((offset + (blocks << LOGICAL_BLOCK_BITS)) <
+ file->content.offset_of_temp) {
+ if (blocks > 0) {
+ r = write_file_contents(a, offset,
+ blocks << LOGICAL_BLOCK_BITS);
+ if (r < 0)
+ return (r);
+ }
+ blocks = 0;
+ offset = file->content.offset_of_temp;
+ }
+
+ file->cur_content = &(file->content);
+ do {
+ blocks += file->cur_content->blocks;
+ /* Next fragument */
+ file->cur_content = file->cur_content->next;
+ } while (file->cur_content != NULL);
+ }
+
+ /* Flush out remaining blocks. */
+ if (blocks > 0) {
+ r = write_file_contents(a, offset,
+ blocks << LOGICAL_BLOCK_BITS);
+ if (r < 0)
+ return (r);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static void
+isofile_init_entry_list(struct iso9660 *iso9660)
+{
+ iso9660->all_file_list.first = NULL;
+ iso9660->all_file_list.last = &(iso9660->all_file_list.first);
+}
+
+static void
+isofile_add_entry(struct iso9660 *iso9660, struct isofile *file)
+{
+ file->allnext = NULL;
+ *iso9660->all_file_list.last = file;
+ iso9660->all_file_list.last = &(file->allnext);
+}
+
+static void
+isofile_free_all_entries(struct iso9660 *iso9660)
+{
+ struct isofile *file, *file_next;
+
+ file = iso9660->all_file_list.first;
+ while (file != NULL) {
+ file_next = file->allnext;
+ isofile_free(file);
+ file = file_next;
+ }
+}
+
+static void
+isofile_init_entry_data_file_list(struct iso9660 *iso9660)
+{
+ iso9660->data_file_list.first = NULL;
+ iso9660->data_file_list.last = &(iso9660->data_file_list.first);
+}
+
+static void
+isofile_add_data_file(struct iso9660 *iso9660, struct isofile *file)
+{
+ file->datanext = NULL;
+ *iso9660->data_file_list.last = file;
+ iso9660->data_file_list.last = &(file->datanext);
+}
+
+
+static struct isofile *
+isofile_new(struct archive_write *a, struct archive_entry *entry)
+{
+ struct isofile *file;
+
+ file = calloc(1, sizeof(*file));
+ if (file == NULL)
+ return (NULL);
+
+ if (entry != NULL)
+ file->entry = archive_entry_clone(entry);
+ else
+ file->entry = archive_entry_new2(&a->archive);
+ if (file->entry == NULL) {
+ free(file);
+ return (NULL);
+ }
+ archive_string_init(&(file->parentdir));
+ archive_string_init(&(file->basename));
+ archive_string_init(&(file->basename_utf16));
+ archive_string_init(&(file->symlink));
+ file->cur_content = &(file->content);
+
+ return (file);
+}
+
+static void
+isofile_free(struct isofile *file)
+{
+ struct content *con, *tmp;
+
+ con = file->content.next;
+ while (con != NULL) {
+ tmp = con;
+ con = con->next;
+ free(tmp);
+ }
+ archive_entry_free(file->entry);
+ archive_string_free(&(file->parentdir));
+ archive_string_free(&(file->basename));
+ archive_string_free(&(file->basename_utf16));
+ archive_string_free(&(file->symlink));
+ free(file);
+}
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+static int
+cleanup_backslash_1(char *p)
+{
+ int mb, dos;
+
+ mb = dos = 0;
+ while (*p) {
+ if (*(unsigned char *)p > 127)
+ mb = 1;
+ if (*p == '\\') {
+ /* If we have not met any multi-byte characters,
+ * we can replace '\' with '/'. */
+ if (!mb)
+ *p = '/';
+ dos = 1;
+ }
+ p++;
+ }
+ if (!mb || !dos)
+ return (0);
+ return (-1);
+}
+
+static void
+cleanup_backslash_2(wchar_t *p)
+{
+
+ /* Convert a path-separator from '\' to '/' */
+ while (*p != L'\0') {
+ if (*p == L'\\')
+ *p = L'/';
+ p++;
+ }
+}
+#endif
+
+/*
+ * Generate a parent directory name and a base name from a pathname.
+ */
+static int
+isofile_gen_utility_names(struct archive_write *a, struct isofile *file)
+{
+ struct iso9660 *iso9660;
+ const char *pathname;
+ char *p, *dirname, *slash;
+ size_t len;
+ int ret = ARCHIVE_OK;
+
+ iso9660 = a->format_data;
+
+ archive_string_empty(&(file->parentdir));
+ archive_string_empty(&(file->basename));
+ archive_string_empty(&(file->basename_utf16));
+ archive_string_empty(&(file->symlink));
+
+ pathname = archive_entry_pathname(file->entry);
+ if (pathname == NULL || pathname[0] == '\0') {/* virtual root */
+ file->dircnt = 0;
+ return (ret);
+ }
+
+ /*
+ * Make a UTF-16BE basename if Joliet extension enabled.
+ */
+ if (iso9660->opt.joliet) {
+ const char *u16, *ulast;
+ size_t u16len, ulen_last;
+
+ if (iso9660->sconv_to_utf16be == NULL) {
+ iso9660->sconv_to_utf16be =
+ archive_string_conversion_to_charset(
+ &(a->archive), "UTF-16BE", 1);
+ if (iso9660->sconv_to_utf16be == NULL)
+ /* Couldn't allocate memory */
+ return (ARCHIVE_FATAL);
+ iso9660->sconv_from_utf16be =
+ archive_string_conversion_from_charset(
+ &(a->archive), "UTF-16BE", 1);
+ if (iso9660->sconv_from_utf16be == NULL)
+ /* Couldn't allocate memory */
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Converte a filename to UTF-16BE.
+ */
+ if (0 > archive_entry_pathname_l(file->entry, &u16, &u16len,
+ iso9660->sconv_to_utf16be)) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for UTF-16BE");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "A filename cannot be converted to UTF-16BE;"
+ "You should disable making Joliet extension");
+ ret = ARCHIVE_WARN;
+ }
+
+ /*
+ * Make sure a path separator is not in the last;
+ * Remove trailing '/'.
+ */
+ while (u16len >= 2) {
+#if defined(_WIN32) || defined(__CYGWIN__)
+ if (u16[u16len-2] == 0 &&
+ (u16[u16len-1] == '/' || u16[u16len-1] == '\\'))
+#else
+ if (u16[u16len-2] == 0 && u16[u16len-1] == '/')
+#endif
+ {
+ u16len -= 2;
+ } else
+ break;
+ }
+
+ /*
+ * Find a basename in UTF-16BE.
+ */
+ ulast = u16;
+ u16len >>= 1;
+ ulen_last = u16len;
+ while (u16len > 0) {
+#if defined(_WIN32) || defined(__CYGWIN__)
+ if (u16[0] == 0 && (u16[1] == '/' || u16[1] == '\\'))
+#else
+ if (u16[0] == 0 && u16[1] == '/')
+#endif
+ {
+ ulast = u16 + 2;
+ ulen_last = u16len -1;
+ }
+ u16 += 2;
+ u16len --;
+ }
+ ulen_last <<= 1;
+ if (archive_string_ensure(&(file->basename_utf16),
+ ulen_last) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for UTF-16BE");
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Set UTF-16BE basename.
+ */
+ memcpy(file->basename_utf16.s, ulast, ulen_last);
+ file->basename_utf16.length = ulen_last;
+ }
+
+ archive_strcpy(&(file->parentdir), pathname);
+#if defined(_WIN32) || defined(__CYGWIN__)
+ /*
+ * Convert a path-separator from '\' to '/'
+ */
+ if (cleanup_backslash_1(file->parentdir.s) != 0) {
+ const wchar_t *wp = archive_entry_pathname_w(file->entry);
+ struct archive_wstring ws;
+
+ if (wp != NULL) {
+ int r;
+ archive_string_init(&ws);
+ archive_wstrcpy(&ws, wp);
+ cleanup_backslash_2(ws.s);
+ archive_string_empty(&(file->parentdir));
+ r = archive_string_append_from_wcs(&(file->parentdir),
+ ws.s, ws.length);
+ archive_wstring_free(&ws);
+ if (r < 0 && errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ }
+#endif
+
+ len = file->parentdir.length;
+ p = dirname = file->parentdir.s;
+
+ /*
+ * Remove leading '/', '../' and './' elements
+ */
+ while (*p) {
+ if (p[0] == '/') {
+ p++;
+ len--;
+ } else if (p[0] != '.')
+ break;
+ else if (p[1] == '.' && p[2] == '/') {
+ p += 3;
+ len -= 3;
+ } else if (p[1] == '/' || (p[1] == '.' && p[2] == '\0')) {
+ p += 2;
+ len -= 2;
+ } else if (p[1] == '\0') {
+ p++;
+ len--;
+ } else
+ break;
+ }
+ if (p != dirname) {
+ memmove(dirname, p, len+1);
+ p = dirname;
+ }
+ /*
+ * Remove "/","/." and "/.." elements from tail.
+ */
+ while (len > 0) {
+ size_t ll = len;
+
+ if (len > 0 && p[len-1] == '/') {
+ p[len-1] = '\0';
+ len--;
+ }
+ if (len > 1 && p[len-2] == '/' && p[len-1] == '.') {
+ p[len-2] = '\0';
+ len -= 2;
+ }
+ if (len > 2 && p[len-3] == '/' && p[len-2] == '.' &&
+ p[len-1] == '.') {
+ p[len-3] = '\0';
+ len -= 3;
+ }
+ if (ll == len)
+ break;
+ }
+ while (*p) {
+ if (p[0] == '/') {
+ if (p[1] == '/')
+ /* Convert '//' --> '/' */
+ strcpy(p, p+1);
+ else if (p[1] == '.' && p[2] == '/')
+ /* Convert '/./' --> '/' */
+ strcpy(p, p+2);
+ else if (p[1] == '.' && p[2] == '.' && p[3] == '/') {
+ /* Convert 'dir/dir1/../dir2/'
+ * --> 'dir/dir2/'
+ */
+ char *rp = p -1;
+ while (rp >= dirname) {
+ if (*rp == '/')
+ break;
+ --rp;
+ }
+ if (rp > dirname) {
+ strcpy(rp, p+3);
+ p = rp;
+ } else {
+ strcpy(dirname, p+4);
+ p = dirname;
+ }
+ } else
+ p++;
+ } else
+ p++;
+ }
+ p = dirname;
+ len = strlen(p);
+
+ if (archive_entry_filetype(file->entry) == AE_IFLNK) {
+ /* Convert symlink name too. */
+ pathname = archive_entry_symlink(file->entry);
+ archive_strcpy(&(file->symlink), pathname);
+#if defined(_WIN32) || defined(__CYGWIN__)
+ /*
+ * Convert a path-separator from '\' to '/'
+ */
+ if (archive_strlen(&(file->symlink)) > 0 &&
+ cleanup_backslash_1(file->symlink.s) != 0) {
+ const wchar_t *wp =
+ archive_entry_symlink_w(file->entry);
+ struct archive_wstring ws;
+
+ if (wp != NULL) {
+ int r;
+ archive_string_init(&ws);
+ archive_wstrcpy(&ws, wp);
+ cleanup_backslash_2(ws.s);
+ archive_string_empty(&(file->symlink));
+ r = archive_string_append_from_wcs(
+ &(file->symlink),
+ ws.s, ws.length);
+ archive_wstring_free(&ws);
+ if (r < 0 && errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ }
+#endif
+ }
+ /*
+ * - Count up directory elements.
+ * - Find out the position which points the last position of
+ * path separator('/').
+ */
+ slash = NULL;
+ file->dircnt = 0;
+ for (; *p != '\0'; p++)
+ if (*p == '/') {
+ slash = p;
+ file->dircnt++;
+ }
+ if (slash == NULL) {
+ /* The pathname doesn't have a parent directory. */
+ file->parentdir.length = len;
+ archive_string_copy(&(file->basename), &(file->parentdir));
+ archive_string_empty(&(file->parentdir));
+ *file->parentdir.s = '\0';
+ return (ret);
+ }
+
+ /* Make a basename from dirname and slash */
+ *slash = '\0';
+ file->parentdir.length = slash - dirname;
+ archive_strcpy(&(file->basename), slash + 1);
+ if (archive_entry_filetype(file->entry) == AE_IFDIR)
+ file->dircnt ++;
+ return (ret);
+}
+
+/*
+ * Register a entry to get a hardlink target.
+ */
+static int
+isofile_register_hardlink(struct archive_write *a, struct isofile *file)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct hardlink *hl;
+ const char *pathname;
+
+ archive_entry_set_nlink(file->entry, 1);
+ pathname = archive_entry_hardlink(file->entry);
+ if (pathname == NULL) {
+ /* This `file` is a hardlink target. */
+ hl = malloc(sizeof(*hl));
+ if (hl == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ hl->nlink = 1;
+ /* A hardlink target must be the first position. */
+ file->hlnext = NULL;
+ hl->file_list.first = file;
+ hl->file_list.last = &(file->hlnext);
+ __archive_rb_tree_insert_node(&(iso9660->hardlink_rbtree),
+ (struct archive_rb_node *)hl);
+ } else {
+ hl = (struct hardlink *)__archive_rb_tree_find_node(
+ &(iso9660->hardlink_rbtree), pathname);
+ if (hl != NULL) {
+ /* Insert `file` entry into the tail. */
+ file->hlnext = NULL;
+ *hl->file_list.last = file;
+ hl->file_list.last = &(file->hlnext);
+ hl->nlink++;
+ }
+ archive_entry_unset_size(file->entry);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Hardlinked files have to have the same location of extent.
+ * We have to find out hardlink target entries for the entries
+ * which have a hardlink target name.
+ */
+static void
+isofile_connect_hardlink_files(struct iso9660 *iso9660)
+{
+ struct archive_rb_node *n;
+ struct hardlink *hl;
+ struct isofile *target, *nf;
+
+ ARCHIVE_RB_TREE_FOREACH(n, &(iso9660->hardlink_rbtree)) {
+ hl = (struct hardlink *)n;
+
+ /* The first entry must be a hardlink target. */
+ target = hl->file_list.first;
+ archive_entry_set_nlink(target->entry, hl->nlink);
+ /* Set a hardlink target to reference entries. */
+ for (nf = target->hlnext;
+ nf != NULL; nf = nf->hlnext) {
+ nf->hardlink_target = target;
+ archive_entry_set_nlink(nf->entry, hl->nlink);
+ }
+ }
+}
+
+static int
+isofile_hd_cmp_node(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ const struct hardlink *h1 = (const struct hardlink *)n1;
+ const struct hardlink *h2 = (const struct hardlink *)n2;
+
+ return (strcmp(archive_entry_pathname(h1->file_list.first->entry),
+ archive_entry_pathname(h2->file_list.first->entry)));
+}
+
+static int
+isofile_hd_cmp_key(const struct archive_rb_node *n, const void *key)
+{
+ const struct hardlink *h = (const struct hardlink *)n;
+
+ return (strcmp(archive_entry_pathname(h->file_list.first->entry),
+ (const char *)key));
+}
+
+static void
+isofile_init_hardlinks(struct iso9660 *iso9660)
+{
+ static const struct archive_rb_tree_ops rb_ops = {
+ isofile_hd_cmp_node, isofile_hd_cmp_key,
+ };
+
+ __archive_rb_tree_init(&(iso9660->hardlink_rbtree), &rb_ops);
+}
+
+static void
+isofile_free_hardlinks(struct iso9660 *iso9660)
+{
+ struct archive_rb_node *n, *next;
+
+ for (n = ARCHIVE_RB_TREE_MIN(&(iso9660->hardlink_rbtree)); n;) {
+ next = __archive_rb_tree_iterate(&(iso9660->hardlink_rbtree),
+ n, ARCHIVE_RB_DIR_RIGHT);
+ free(n);
+ n = next;
+ }
+}
+
+static struct isoent *
+isoent_new(struct isofile *file)
+{
+ struct isoent *isoent;
+ static const struct archive_rb_tree_ops rb_ops = {
+ isoent_cmp_node, isoent_cmp_key,
+ };
+
+ isoent = calloc(1, sizeof(*isoent));
+ if (isoent == NULL)
+ return (NULL);
+ isoent->file = file;
+ isoent->children.first = NULL;
+ isoent->children.last = &(isoent->children.first);
+ __archive_rb_tree_init(&(isoent->rbtree), &rb_ops);
+ isoent->subdirs.first = NULL;
+ isoent->subdirs.last = &(isoent->subdirs.first);
+ isoent->extr_rec_list.first = NULL;
+ isoent->extr_rec_list.last = &(isoent->extr_rec_list.first);
+ isoent->extr_rec_list.current = NULL;
+ if (archive_entry_filetype(file->entry) == AE_IFDIR)
+ isoent->dir = 1;
+
+ return (isoent);
+}
+
+static inline struct isoent *
+isoent_clone(struct isoent *src)
+{
+ return (isoent_new(src->file));
+}
+
+static void
+_isoent_free(struct isoent *isoent)
+{
+ struct extr_rec *er, *er_next;
+
+ free(isoent->children_sorted);
+ free(isoent->identifier);
+ er = isoent->extr_rec_list.first;
+ while (er != NULL) {
+ er_next = er->next;
+ free(er);
+ er = er_next;
+ }
+ free(isoent);
+}
+
+static void
+isoent_free_all(struct isoent *isoent)
+{
+ struct isoent *np, *np_temp;
+
+ if (isoent == NULL)
+ return;
+ np = isoent;
+ for (;;) {
+ if (np->dir) {
+ if (np->children.first != NULL) {
+ /* Enter to sub directories. */
+ np = np->children.first;
+ continue;
+ }
+ }
+ for (;;) {
+ np_temp = np;
+ if (np->chnext == NULL) {
+ /* Return to the parent directory. */
+ np = np->parent;
+ _isoent_free(np_temp);
+ if (np == np_temp)
+ return;
+ } else {
+ np = np->chnext;
+ _isoent_free(np_temp);
+ break;
+ }
+ }
+ }
+}
+
+static struct isoent *
+isoent_create_virtual_dir(struct archive_write *a, struct iso9660 *iso9660, const char *pathname)
+{
+ struct isofile *file;
+ struct isoent *isoent;
+
+ file = isofile_new(a, NULL);
+ if (file == NULL)
+ return (NULL);
+ archive_entry_set_pathname(file->entry, pathname);
+ archive_entry_unset_mtime(file->entry);
+ archive_entry_unset_atime(file->entry);
+ archive_entry_unset_ctime(file->entry);
+ archive_entry_set_uid(file->entry, getuid());
+ archive_entry_set_gid(file->entry, getgid());
+ archive_entry_set_mode(file->entry, 0555 | AE_IFDIR);
+ archive_entry_set_nlink(file->entry, 2);
+ if (isofile_gen_utility_names(a, file) < ARCHIVE_WARN) {
+ isofile_free(file);
+ return (NULL);
+ }
+ isofile_add_entry(iso9660, file);
+
+ isoent = isoent_new(file);
+ if (isoent == NULL)
+ return (NULL);
+ isoent->dir = 1;
+ isoent->virtual = 1;
+
+ return (isoent);
+}
+
+static int
+isoent_cmp_node(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ const struct isoent *e1 = (const struct isoent *)n1;
+ const struct isoent *e2 = (const struct isoent *)n2;
+
+ return (strcmp(e1->file->basename.s, e2->file->basename.s));
+}
+
+static int
+isoent_cmp_key(const struct archive_rb_node *n, const void *key)
+{
+ const struct isoent *e = (const struct isoent *)n;
+
+ return (strcmp(e->file->basename.s, (const char *)key));
+}
+
+static int
+isoent_add_child_head(struct isoent *parent, struct isoent *child)
+{
+
+ if (!__archive_rb_tree_insert_node(
+ &(parent->rbtree), (struct archive_rb_node *)child))
+ return (0);
+ if ((child->chnext = parent->children.first) == NULL)
+ parent->children.last = &(child->chnext);
+ parent->children.first = child;
+ parent->children.cnt++;
+ child->parent = parent;
+
+ /* Add a child to a sub-directory chain */
+ if (child->dir) {
+ if ((child->drnext = parent->subdirs.first) == NULL)
+ parent->subdirs.last = &(child->drnext);
+ parent->subdirs.first = child;
+ parent->subdirs.cnt++;
+ child->parent = parent;
+ } else
+ child->drnext = NULL;
+ return (1);
+}
+
+static int
+isoent_add_child_tail(struct isoent *parent, struct isoent *child)
+{
+
+ if (!__archive_rb_tree_insert_node(
+ &(parent->rbtree), (struct archive_rb_node *)child))
+ return (0);
+ child->chnext = NULL;
+ *parent->children.last = child;
+ parent->children.last = &(child->chnext);
+ parent->children.cnt++;
+ child->parent = parent;
+
+ /* Add a child to a sub-directory chain */
+ child->drnext = NULL;
+ if (child->dir) {
+ *parent->subdirs.last = child;
+ parent->subdirs.last = &(child->drnext);
+ parent->subdirs.cnt++;
+ child->parent = parent;
+ }
+ return (1);
+}
+
+static void
+isoent_remove_child(struct isoent *parent, struct isoent *child)
+{
+ struct isoent *ent;
+
+ /* Remove a child entry from children chain. */
+ ent = parent->children.first;
+ while (ent->chnext != child)
+ ent = ent->chnext;
+ if ((ent->chnext = ent->chnext->chnext) == NULL)
+ parent->children.last = &(ent->chnext);
+ parent->children.cnt--;
+
+ if (child->dir) {
+ /* Remove a child entry from sub-directory chain. */
+ ent = parent->subdirs.first;
+ while (ent->drnext != child)
+ ent = ent->drnext;
+ if ((ent->drnext = ent->drnext->drnext) == NULL)
+ parent->subdirs.last = &(ent->drnext);
+ parent->subdirs.cnt--;
+ }
+
+ __archive_rb_tree_remove_node(&(parent->rbtree),
+ (struct archive_rb_node *)child);
+}
+
+static int
+isoent_clone_tree(struct archive_write *a, struct isoent **nroot,
+ struct isoent *root)
+{
+ struct isoent *np, *xroot, *newent;
+
+ np = root;
+ xroot = NULL;
+ do {
+ newent = isoent_clone(np);
+ if (newent == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ if (xroot == NULL) {
+ *nroot = xroot = newent;
+ newent->parent = xroot;
+ } else
+ isoent_add_child_tail(xroot, newent);
+ if (np->dir && np->children.first != NULL) {
+ /* Enter to sub directories. */
+ np = np->children.first;
+ xroot = newent;
+ continue;
+ }
+ while (np != np->parent) {
+ if (np->chnext == NULL) {
+ /* Return to the parent directory. */
+ np = np->parent;
+ xroot = xroot->parent;
+ } else {
+ np = np->chnext;
+ break;
+ }
+ }
+ } while (np != np->parent);
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Setup directory locations.
+ */
+static void
+isoent_setup_directory_location(struct iso9660 *iso9660, int location,
+ struct vdd *vdd)
+{
+ struct isoent *np;
+ int depth;
+
+ vdd->total_dir_block = 0;
+ depth = 0;
+ np = vdd->rootent;
+ do {
+ int block;
+
+ np->dir_block = calculate_directory_descriptors(
+ iso9660, vdd, np, depth);
+ vdd->total_dir_block += np->dir_block;
+ np->dir_location = location;
+ location += np->dir_block;
+ block = extra_setup_location(np, location);
+ vdd->total_dir_block += block;
+ location += block;
+
+ if (np->subdirs.first != NULL && depth + 1 < vdd->max_depth) {
+ /* Enter to sub directories. */
+ np = np->subdirs.first;
+ depth++;
+ continue;
+ }
+ while (np != np->parent) {
+ if (np->drnext == NULL) {
+ /* Return to the parent directory. */
+ np = np->parent;
+ depth--;
+ } else {
+ np = np->drnext;
+ break;
+ }
+ }
+ } while (np != np->parent);
+}
+
+static void
+_isoent_file_location(struct iso9660 *iso9660, struct isoent *isoent,
+ int *symlocation)
+{
+ struct isoent **children;
+ int n;
+
+ if (isoent->children.cnt == 0)
+ return;
+
+ children = isoent->children_sorted;
+ for (n = 0; n < isoent->children.cnt; n++) {
+ struct isoent *np;
+ struct isofile *file;
+
+ np = children[n];
+ if (np->dir)
+ continue;
+ if (np == iso9660->el_torito.boot)
+ continue;
+ file = np->file;
+ if (file->boot || file->hardlink_target != NULL)
+ continue;
+ if (archive_entry_filetype(file->entry) == AE_IFLNK ||
+ file->content.size == 0) {
+ /*
+ * Do not point a valid location.
+ * Make sure entry is not hardlink file.
+ */
+ file->content.location = (*symlocation)--;
+ continue;
+ }
+
+ file->write_content = 1;
+ }
+}
+
+/*
+ * Setup file locations.
+ */
+static void
+isoent_setup_file_location(struct iso9660 *iso9660, int location)
+{
+ struct isoent *isoent;
+ struct isoent *np;
+ struct isofile *file;
+ size_t size;
+ int block;
+ int depth;
+ int joliet;
+ int symlocation;
+ int total_block;
+
+ iso9660->total_file_block = 0;
+ if ((isoent = iso9660->el_torito.catalog) != NULL) {
+ isoent->file->content.location = location;
+ block = (int)((archive_entry_size(isoent->file->entry) +
+ LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS);
+ location += block;
+ iso9660->total_file_block += block;
+ }
+ if ((isoent = iso9660->el_torito.boot) != NULL) {
+ isoent->file->content.location = location;
+ size = fd_boot_image_size(iso9660->el_torito.media_type);
+ if (size == 0)
+ size = (size_t)archive_entry_size(isoent->file->entry);
+ block = ((int)size + LOGICAL_BLOCK_SIZE -1)
+ >> LOGICAL_BLOCK_BITS;
+ location += block;
+ iso9660->total_file_block += block;
+ isoent->file->content.blocks = block;
+ }
+
+ depth = 0;
+ symlocation = -16;
+ if (!iso9660->opt.rr && iso9660->opt.joliet) {
+ joliet = 1;
+ np = iso9660->joliet.rootent;
+ } else {
+ joliet = 0;
+ np = iso9660->primary.rootent;
+ }
+ do {
+ _isoent_file_location(iso9660, np, &symlocation);
+
+ if (np->subdirs.first != NULL &&
+ (joliet ||
+ ((iso9660->opt.rr == OPT_RR_DISABLED &&
+ depth + 2 < iso9660->primary.max_depth) ||
+ (iso9660->opt.rr &&
+ depth + 1 < iso9660->primary.max_depth)))) {
+ /* Enter to sub directories. */
+ np = np->subdirs.first;
+ depth++;
+ continue;
+ }
+ while (np != np->parent) {
+ if (np->drnext == NULL) {
+ /* Return to the parent directory. */
+ np = np->parent;
+ depth--;
+ } else {
+ np = np->drnext;
+ break;
+ }
+ }
+ } while (np != np->parent);
+
+ total_block = 0;
+ for (file = iso9660->data_file_list.first;
+ file != NULL; file = file->datanext) {
+
+ if (!file->write_content)
+ continue;
+
+ file->cur_content = &(file->content);
+ do {
+ file->cur_content->location = location;
+ location += file->cur_content->blocks;
+ total_block += file->cur_content->blocks;
+ /* Next fragument */
+ file->cur_content = file->cur_content->next;
+ } while (file->cur_content != NULL);
+ }
+ iso9660->total_file_block += total_block;
+}
+
+static int
+get_path_component(char *name, size_t n, const char *fn)
+{
+ char *p;
+ size_t l;
+
+ p = strchr(fn, '/');
+ if (p == NULL) {
+ if ((l = strlen(fn)) == 0)
+ return (0);
+ } else
+ l = p - fn;
+ if (l > n -1)
+ return (-1);
+ memcpy(name, fn, l);
+ name[l] = '\0';
+
+ return ((int)l);
+}
+
+/*
+ * Add a new entry into the tree.
+ */
+static int
+isoent_tree(struct archive_write *a, struct isoent **isoentpp)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ char name[_MAX_FNAME];/* Included null terminator size. */
+#elif defined(NAME_MAX) && NAME_MAX >= 255
+ char name[NAME_MAX+1];
+#else
+ char name[256];
+#endif
+ struct iso9660 *iso9660 = a->format_data;
+ struct isoent *dent, *isoent, *np;
+ struct isofile *f1, *f2;
+ const char *fn, *p;
+ int l;
+
+ isoent = *isoentpp;
+ dent = iso9660->primary.rootent;
+ if (isoent->file->parentdir.length > 0)
+ fn = p = isoent->file->parentdir.s;
+ else
+ fn = p = "";
+
+ /*
+ * If the path of the parent directory of `isoent' entry is
+ * the same as the path of `cur_dirent', add isoent to
+ * `cur_dirent'.
+ */
+ if (archive_strlen(&(iso9660->cur_dirstr))
+ == archive_strlen(&(isoent->file->parentdir)) &&
+ strcmp(iso9660->cur_dirstr.s, fn) == 0) {
+ if (!isoent_add_child_tail(iso9660->cur_dirent, isoent)) {
+ np = (struct isoent *)__archive_rb_tree_find_node(
+ &(iso9660->cur_dirent->rbtree),
+ isoent->file->basename.s);
+ goto same_entry;
+ }
+ return (ARCHIVE_OK);
+ }
+
+ for (;;) {
+ l = get_path_component(name, sizeof(name), fn);
+ if (l == 0) {
+ np = NULL;
+ break;
+ }
+ if (l < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "A name buffer is too small");
+ _isoent_free(isoent);
+ return (ARCHIVE_FATAL);
+ }
+
+ np = isoent_find_child(dent, name);
+ if (np == NULL || fn[0] == '\0')
+ break;
+
+ /* Find next subdirectory. */
+ if (!np->dir) {
+ /* NOT Directory! */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "`%s' is not directory, we cannot insert `%s' ",
+ archive_entry_pathname(np->file->entry),
+ archive_entry_pathname(isoent->file->entry));
+ _isoent_free(isoent);
+ *isoentpp = NULL;
+ return (ARCHIVE_FAILED);
+ }
+ fn += l;
+ if (fn[0] == '/')
+ fn++;
+ dent = np;
+ }
+ if (np == NULL) {
+ /*
+ * Create virtual parent directories.
+ */
+ while (fn[0] != '\0') {
+ struct isoent *vp;
+ struct archive_string as;
+
+ archive_string_init(&as);
+ archive_strncat(&as, p, fn - p + l);
+ if (as.s[as.length-1] == '/') {
+ as.s[as.length-1] = '\0';
+ as.length--;
+ }
+ vp = isoent_create_virtual_dir(a, iso9660, as.s);
+ if (vp == NULL) {
+ archive_string_free(&as);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ _isoent_free(isoent);
+ *isoentpp = NULL;
+ return (ARCHIVE_FATAL);
+ }
+ archive_string_free(&as);
+
+ if (vp->file->dircnt > iso9660->dircnt_max)
+ iso9660->dircnt_max = vp->file->dircnt;
+ isoent_add_child_tail(dent, vp);
+ np = vp;
+
+ fn += l;
+ if (fn[0] == '/')
+ fn++;
+ l = get_path_component(name, sizeof(name), fn);
+ if (l < 0) {
+ archive_string_free(&as);
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "A name buffer is too small");
+ _isoent_free(isoent);
+ *isoentpp = NULL;
+ return (ARCHIVE_FATAL);
+ }
+ dent = np;
+ }
+
+ /* Found out the parent directory where isoent can be
+ * inserted. */
+ iso9660->cur_dirent = dent;
+ archive_string_empty(&(iso9660->cur_dirstr));
+ archive_string_ensure(&(iso9660->cur_dirstr),
+ archive_strlen(&(dent->file->parentdir)) +
+ archive_strlen(&(dent->file->basename)) + 2);
+ if (archive_strlen(&(dent->file->parentdir)) +
+ archive_strlen(&(dent->file->basename)) == 0)
+ iso9660->cur_dirstr.s[0] = 0;
+ else {
+ if (archive_strlen(&(dent->file->parentdir)) > 0) {
+ archive_string_copy(&(iso9660->cur_dirstr),
+ &(dent->file->parentdir));
+ archive_strappend_char(&(iso9660->cur_dirstr), '/');
+ }
+ archive_string_concat(&(iso9660->cur_dirstr),
+ &(dent->file->basename));
+ }
+
+ if (!isoent_add_child_tail(dent, isoent)) {
+ np = (struct isoent *)__archive_rb_tree_find_node(
+ &(dent->rbtree), isoent->file->basename.s);
+ goto same_entry;
+ }
+ return (ARCHIVE_OK);
+ }
+
+same_entry:
+ /*
+ * We have already has the entry the filename of which is
+ * the same.
+ */
+ f1 = np->file;
+ f2 = isoent->file;
+
+ /* If the file type of entries is different,
+ * we cannot handle it. */
+ if (archive_entry_filetype(f1->entry) !=
+ archive_entry_filetype(f2->entry)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Found duplicate entries `%s' and its file type is "
+ "different",
+ archive_entry_pathname(f1->entry));
+ _isoent_free(isoent);
+ *isoentpp = NULL;
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Swap file entries. */
+ np->file = f2;
+ isoent->file = f1;
+ np->virtual = 0;
+
+ _isoent_free(isoent);
+ *isoentpp = np;
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Find a entry from `isoent'
+ */
+static struct isoent *
+isoent_find_child(struct isoent *isoent, const char *child_name)
+{
+ struct isoent *np;
+
+ np = (struct isoent *)__archive_rb_tree_find_node(
+ &(isoent->rbtree), child_name);
+ return (np);
+}
+
+/*
+ * Find a entry full-path of which is specified by `fn' parameter,
+ * in the tree.
+ */
+static struct isoent *
+isoent_find_entry(struct isoent *rootent, const char *fn)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ char name[_MAX_FNAME];/* Included null terminator size. */
+#elif defined(NAME_MAX) && NAME_MAX >= 255
+ char name[NAME_MAX+1];
+#else
+ char name[256];
+#endif
+ struct isoent *isoent, *np;
+ int l;
+
+ isoent = rootent;
+ np = NULL;
+ for (;;) {
+ l = get_path_component(name, sizeof(name), fn);
+ if (l == 0)
+ break;
+ fn += l;
+ if (fn[0] == '/')
+ fn++;
+
+ np = isoent_find_child(isoent, name);
+ if (np == NULL)
+ break;
+ if (fn[0] == '\0')
+ break;/* We found out the entry */
+
+ /* Try sub directory. */
+ isoent = np;
+ np = NULL;
+ if (!isoent->dir)
+ break;/* Not directory */
+ }
+
+ return (np);
+}
+
+/*
+ * Following idr_* functions are used for resolving duplicated filenames
+ * and unreceivable filenames to generate ISO9660/Joliet Identifiers.
+ */
+
+static void
+idr_relaxed_filenames(char *map)
+{
+ int i;
+
+ for (i = 0x21; i <= 0x2F; i++)
+ map[i] = 1;
+ for (i = 0x3A; i <= 0x41; i++)
+ map[i] = 1;
+ for (i = 0x5B; i <= 0x5E; i++)
+ map[i] = 1;
+ map[0x60] = 1;
+ for (i = 0x7B; i <= 0x7E; i++)
+ map[i] = 1;
+}
+
+static void
+idr_init(struct iso9660 *iso9660, struct vdd *vdd, struct idr *idr)
+{
+
+ idr->idrent_pool = NULL;
+ idr->pool_size = 0;
+ if (vdd->vdd_type != VDD_JOLIET) {
+ if (iso9660->opt.iso_level <= 3) {
+ memcpy(idr->char_map, d_characters_map,
+ sizeof(idr->char_map));
+ } else {
+ memcpy(idr->char_map, d1_characters_map,
+ sizeof(idr->char_map));
+ idr_relaxed_filenames(idr->char_map);
+ }
+ }
+}
+
+static void
+idr_cleanup(struct idr *idr)
+{
+ free(idr->idrent_pool);
+}
+
+static int
+idr_ensure_poolsize(struct archive_write *a, struct idr *idr,
+ int cnt)
+{
+
+ if (idr->pool_size < cnt) {
+ void *p;
+ const int bk = (1 << 7) - 1;
+ int psize;
+
+ psize = (cnt + bk) & ~bk;
+ p = realloc(idr->idrent_pool, sizeof(struct idrent) * psize);
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ idr->idrent_pool = (struct idrent *)p;
+ idr->pool_size = psize;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+idr_start(struct archive_write *a, struct idr *idr, int cnt, int ffmax,
+ int num_size, int null_size, const struct archive_rb_tree_ops *rbt_ops)
+{
+ int r;
+
+ (void)ffmax; /* UNUSED */
+
+ r = idr_ensure_poolsize(a, idr, cnt);
+ if (r != ARCHIVE_OK)
+ return (r);
+ __archive_rb_tree_init(&(idr->rbtree), rbt_ops);
+ idr->wait_list.first = NULL;
+ idr->wait_list.last = &(idr->wait_list.first);
+ idr->pool_idx = 0;
+ idr->num_size = num_size;
+ idr->null_size = null_size;
+ return (ARCHIVE_OK);
+}
+
+static void
+idr_register(struct idr *idr, struct isoent *isoent, int weight, int noff)
+{
+ struct idrent *idrent, *n;
+
+ idrent = &(idr->idrent_pool[idr->pool_idx++]);
+ idrent->wnext = idrent->avail = NULL;
+ idrent->isoent = isoent;
+ idrent->weight = weight;
+ idrent->noff = noff;
+ idrent->rename_num = 0;
+
+ if (!__archive_rb_tree_insert_node(&(idr->rbtree), &(idrent->rbnode))) {
+ n = (struct idrent *)__archive_rb_tree_find_node(
+ &(idr->rbtree), idrent->isoent);
+ if (n != NULL) {
+ /* this `idrent' needs to rename. */
+ idrent->avail = n;
+ *idr->wait_list.last = idrent;
+ idr->wait_list.last = &(idrent->wnext);
+ }
+ }
+}
+
+static void
+idr_extend_identifier(struct idrent *wnp, int numsize, int nullsize)
+{
+ unsigned char *p;
+ int wnp_ext_off;
+
+ wnp_ext_off = wnp->isoent->ext_off;
+ if (wnp->noff + numsize != wnp_ext_off) {
+ p = (unsigned char *)wnp->isoent->identifier;
+ /* Extend the filename; foo.c --> foo___.c */
+ memmove(p + wnp->noff + numsize, p + wnp_ext_off,
+ wnp->isoent->ext_len + nullsize);
+ wnp->isoent->ext_off = wnp_ext_off = wnp->noff + numsize;
+ wnp->isoent->id_len = wnp_ext_off + wnp->isoent->ext_len;
+ }
+}
+
+static void
+idr_resolve(struct idr *idr, void (*fsetnum)(unsigned char *p, int num))
+{
+ struct idrent *n;
+ unsigned char *p;
+
+ for (n = idr->wait_list.first; n != NULL; n = n->wnext) {
+ idr_extend_identifier(n, idr->num_size, idr->null_size);
+ p = (unsigned char *)n->isoent->identifier + n->noff;
+ do {
+ fsetnum(p, n->avail->rename_num++);
+ } while (!__archive_rb_tree_insert_node(
+ &(idr->rbtree), &(n->rbnode)));
+ }
+}
+
+static void
+idr_set_num(unsigned char *p, int num)
+{
+ static const char xdig[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+ 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
+ 'U', 'V', 'W', 'X', 'Y', 'Z'
+ };
+
+ num %= sizeof(xdig) * sizeof(xdig) * sizeof(xdig);
+ p[0] = xdig[(num / (sizeof(xdig) * sizeof(xdig)))];
+ num %= sizeof(xdig) * sizeof(xdig);
+ p[1] = xdig[ (num / sizeof(xdig))];
+ num %= sizeof(xdig);
+ p[2] = xdig[num];
+}
+
+static void
+idr_set_num_beutf16(unsigned char *p, int num)
+{
+ static const uint16_t xdig[] = {
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
+ 0x0036, 0x0037, 0x0038, 0x0039,
+ 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046,
+ 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C,
+ 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052,
+ 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058,
+ 0x0059, 0x005A
+ };
+#define XDIG_CNT (sizeof(xdig)/sizeof(xdig[0]))
+
+ num %= XDIG_CNT * XDIG_CNT * XDIG_CNT;
+ archive_be16enc(p, xdig[(num / (XDIG_CNT * XDIG_CNT))]);
+ num %= XDIG_CNT * XDIG_CNT;
+ archive_be16enc(p+2, xdig[ (num / XDIG_CNT)]);
+ num %= XDIG_CNT;
+ archive_be16enc(p+4, xdig[num]);
+}
+
+/*
+ * Generate ISO9660 Identifier.
+ */
+static int
+isoent_gen_iso9660_identifier(struct archive_write *a, struct isoent *isoent,
+ struct idr *idr)
+{
+ struct iso9660 *iso9660;
+ struct isoent *np;
+ char *p;
+ int l, r;
+ const char *char_map;
+ char allow_ldots, allow_multidot, allow_period, allow_vernum;
+ int fnmax, ffmax, dnmax;
+ static const struct archive_rb_tree_ops rb_ops = {
+ isoent_cmp_node_iso9660, isoent_cmp_key_iso9660
+ };
+
+ if (isoent->children.cnt == 0)
+ return (0);
+
+ iso9660 = a->format_data;
+ char_map = idr->char_map;
+ if (iso9660->opt.iso_level <= 3) {
+ allow_ldots = 0;
+ allow_multidot = 0;
+ allow_period = 1;
+ allow_vernum = iso9660->opt.allow_vernum;
+ if (iso9660->opt.iso_level == 1) {
+ fnmax = 8;
+ ffmax = 12;/* fnmax + '.' + 3 */
+ dnmax = 8;
+ } else {
+ fnmax = 30;
+ ffmax = 31;
+ dnmax = 31;
+ }
+ } else {
+ allow_ldots = allow_multidot = 1;
+ allow_period = allow_vernum = 0;
+ if (iso9660->opt.rr)
+ /*
+ * MDR : The maximum size of Directory Record(254).
+ * DRL : A Directory Record Length(33).
+ * CE : A size of SUSP CE System Use Entry(28).
+ * MDR - DRL - CE = 254 - 33 - 28 = 193.
+ */
+ fnmax = ffmax = dnmax = 193;
+ else
+ /*
+ * XA : CD-ROM XA System Use Extension
+ * Information(14).
+ * MDR - DRL - XA = 254 - 33 -14 = 207.
+ */
+ fnmax = ffmax = dnmax = 207;
+ }
+
+ r = idr_start(a, idr, isoent->children.cnt, ffmax, 3, 1, &rb_ops);
+ if (r < 0)
+ return (r);
+
+ for (np = isoent->children.first; np != NULL; np = np->chnext) {
+ char *dot, *xdot;
+ int ext_off, noff, weight;
+
+ l = (int)np->file->basename.length;
+ p = malloc(l+31+2+1);
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(p, np->file->basename.s, l);
+ p[l] = '\0';
+ np->identifier = p;
+
+ dot = xdot = NULL;
+ if (!allow_ldots) {
+ /*
+ * If there is a '.' character at the first byte,
+ * it has to be replaced by '_' character.
+ */
+ if (*p == '.')
+ *p++ = '_';
+ }
+ for (;*p; p++) {
+ if (*p & 0x80) {
+ *p = '_';
+ continue;
+ }
+ if (char_map[(unsigned char)*p]) {
+ /* if iso-level is '4', a character '.' is
+ * allowed by char_map. */
+ if (*p == '.') {
+ xdot = dot;
+ dot = p;
+ }
+ continue;
+ }
+ if (*p >= 'a' && *p <= 'z') {
+ *p -= 'a' - 'A';
+ continue;
+ }
+ if (*p == '.') {
+ xdot = dot;
+ dot = p;
+ if (allow_multidot)
+ continue;
+ }
+ *p = '_';
+ }
+ p = np->identifier;
+ weight = -1;
+ if (dot == NULL) {
+ int nammax;
+
+ if (np->dir)
+ nammax = dnmax;
+ else
+ nammax = fnmax;
+
+ if (l > nammax) {
+ p[nammax] = '\0';
+ weight = nammax;
+ ext_off = nammax;
+ } else
+ ext_off = l;
+ } else {
+ *dot = '.';
+ ext_off = (int)(dot - p);
+
+ if (iso9660->opt.iso_level == 1) {
+ if (dot - p <= 8) {
+ if (strlen(dot) > 4) {
+ /* A length of a file extension
+ * must be less than 4 */
+ dot[4] = '\0';
+ weight = 0;
+ }
+ } else {
+ p[8] = dot[0];
+ p[9] = dot[1];
+ p[10] = dot[2];
+ p[11] = dot[3];
+ p[12] = '\0';
+ weight = 8;
+ ext_off = 8;
+ }
+ } else if (np->dir) {
+ if (l > dnmax) {
+ p[dnmax] = '\0';
+ weight = dnmax;
+ if (ext_off > dnmax)
+ ext_off = dnmax;
+ }
+ } else if (l > ffmax) {
+ int extlen = (int)strlen(dot);
+ int xdoff;
+
+ if (xdot != NULL)
+ xdoff = (int)(xdot - p);
+ else
+ xdoff = 0;
+
+ if (extlen > 1 && xdoff < fnmax-1) {
+ int off;
+
+ if (extlen > ffmax)
+ extlen = ffmax;
+ off = ffmax - extlen;
+ if (off == 0) {
+ /* A dot('.') character
+ * does't place to the first
+ * byte of identifier. */
+ off ++;
+ extlen --;
+ }
+ memmove(p+off, dot, extlen);
+ p[ffmax] = '\0';
+ ext_off = off;
+ weight = off;
+#ifdef COMPAT_MKISOFS
+ } else if (xdoff >= fnmax-1) {
+ /* Simulate a bug(?) of mkisofs. */
+ p[fnmax-1] = '\0';
+ ext_off = fnmax-1;
+ weight = fnmax-1;
+#endif
+ } else {
+ p[fnmax] = '\0';
+ ext_off = fnmax;
+ weight = fnmax;
+ }
+ }
+ }
+ /* Save an offset of a file name extension to sort files. */
+ np->ext_off = ext_off;
+ np->ext_len = (int)strlen(&p[ext_off]);
+ np->id_len = l = ext_off + np->ext_len;
+
+ /* Make an offset of the number which is used to be set
+ * hexadecimal number to avoid duplicate identififier. */
+ if (iso9660->opt.iso_level == 1) {
+ if (ext_off >= 5)
+ noff = 5;
+ else
+ noff = ext_off;
+ } else {
+ if (l == ffmax)
+ noff = ext_off - 3;
+ else if (l == ffmax-1)
+ noff = ext_off - 2;
+ else if (l == ffmax-2)
+ noff = ext_off - 1;
+ else
+ noff = ext_off;
+ }
+ /* Register entry to the identifier resolver. */
+ idr_register(idr, np, weight, noff);
+ }
+
+ /* Resolve duplicate identifier. */
+ idr_resolve(idr, idr_set_num);
+
+ /* Add a period and a version number to identifiers. */
+ for (np = isoent->children.first; np != NULL; np = np->chnext) {
+ if (!np->dir && np->rr_child == NULL) {
+ p = np->identifier + np->ext_off + np->ext_len;
+ if (np->ext_len == 0 && allow_period) {
+ *p++ = '.';
+ np->ext_len = 1;
+ }
+ if (np->ext_len == 1 && !allow_period) {
+ *--p = '\0';
+ np->ext_len = 0;
+ }
+ np->id_len = np->ext_off + np->ext_len;
+ if (allow_vernum) {
+ *p++ = ';';
+ *p++ = '1';
+ np->id_len += 2;
+ }
+ *p = '\0';
+ } else
+ np->id_len = np->ext_off + np->ext_len;
+ np->mb_len = np->id_len;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Generate Joliet Identifier.
+ */
+static int
+isoent_gen_joliet_identifier(struct archive_write *a, struct isoent *isoent,
+ struct idr *idr)
+{
+ struct iso9660 *iso9660;
+ struct isoent *np;
+ unsigned char *p;
+ size_t l;
+ int r;
+ int ffmax, parent_len;
+ static const struct archive_rb_tree_ops rb_ops = {
+ isoent_cmp_node_joliet, isoent_cmp_key_joliet
+ };
+
+ if (isoent->children.cnt == 0)
+ return (0);
+
+ iso9660 = a->format_data;
+ if (iso9660->opt.joliet == OPT_JOLIET_LONGNAME)
+ ffmax = 206;
+ else
+ ffmax = 128;
+
+ r = idr_start(a, idr, isoent->children.cnt, ffmax, 6, 2, &rb_ops);
+ if (r < 0)
+ return (r);
+
+ parent_len = 1;
+ for (np = isoent; np->parent != np; np = np->parent)
+ parent_len += np->mb_len + 1;
+
+ for (np = isoent->children.first; np != NULL; np = np->chnext) {
+ unsigned char *dot;
+ int ext_off, noff, weight;
+ size_t lt;
+
+ if ((int)(l = np->file->basename_utf16.length) > ffmax)
+ l = ffmax;
+
+ p = malloc((l+1)*2);
+ if (p == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(p, np->file->basename_utf16.s, l);
+ p[l] = 0;
+ p[l+1] = 0;
+
+ np->identifier = (char *)p;
+ lt = l;
+ dot = p + l;
+ weight = 0;
+ while (lt > 0) {
+ if (!joliet_allowed_char(p[0], p[1]))
+ archive_be16enc(p, 0x005F); /* '_' */
+ else if (p[0] == 0 && p[1] == 0x2E) /* '.' */
+ dot = p;
+ p += 2;
+ lt -= 2;
+ }
+ ext_off = (int)(dot - (unsigned char *)np->identifier);
+ np->ext_off = ext_off;
+ np->ext_len = (int)l - ext_off;
+ np->id_len = (int)l;
+
+ /*
+ * Get a length of MBS of a full-pathname.
+ */
+ if ((int)np->file->basename_utf16.length > ffmax) {
+ if (archive_strncpy_l(&iso9660->mbs,
+ (const char *)np->identifier, l,
+ iso9660->sconv_from_utf16be) != 0 &&
+ errno == ENOMEM) {
+ archive_set_error(&a->archive, errno,
+ "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ np->mb_len = (int)iso9660->mbs.length;
+ if (np->mb_len != (int)np->file->basename.length)
+ weight = np->mb_len;
+ } else
+ np->mb_len = (int)np->file->basename.length;
+
+ /* If a length of full-pathname is longer than 240 bytes,
+ * it violates Joliet extensions regulation. */
+ if (parent_len + np->mb_len > 240) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "The regulation of Joliet extensions;"
+ " A length of a full-pathname of `%s' is "
+ "longer than 240 bytes, (p=%d, b=%d)",
+ archive_entry_pathname(np->file->entry),
+ (int)parent_len, (int)np->mb_len);
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Make an offset of the number which is used to be set
+ * hexadecimal number to avoid duplicate identifier. */
+ if ((int)l == ffmax)
+ noff = ext_off - 6;
+ else if ((int)l == ffmax-2)
+ noff = ext_off - 4;
+ else if ((int)l == ffmax-4)
+ noff = ext_off - 2;
+ else
+ noff = ext_off;
+ /* Register entry to the identifier resolver. */
+ idr_register(idr, np, weight, noff);
+ }
+
+ /* Resolve duplicate identifier with Joliet Volume. */
+ idr_resolve(idr, idr_set_num_beutf16);
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * This comparing rule is according to ISO9660 Standard 9.3
+ */
+static int
+isoent_cmp_iso9660_identifier(const struct isoent *p1, const struct isoent *p2)
+{
+ const char *s1, *s2;
+ int cmp;
+ int l;
+
+ s1 = p1->identifier;
+ s2 = p2->identifier;
+
+ /* Compare File Name */
+ l = p1->ext_off;
+ if (l > p2->ext_off)
+ l = p2->ext_off;
+ cmp = memcmp(s1, s2, l);
+ if (cmp != 0)
+ return (cmp);
+ if (p1->ext_off < p2->ext_off) {
+ s2 += l;
+ l = p2->ext_off - p1->ext_off;
+ while (l--)
+ if (0x20 != *s2++)
+ return (0x20
+ - *(const unsigned char *)(s2 - 1));
+ } else if (p1->ext_off > p2->ext_off) {
+ s1 += l;
+ l = p1->ext_off - p2->ext_off;
+ while (l--)
+ if (0x20 != *s1++)
+ return (*(const unsigned char *)(s1 - 1)
+ - 0x20);
+ }
+ /* Compare File Name Extension */
+ if (p1->ext_len == 0 && p2->ext_len == 0)
+ return (0);
+ if (p1->ext_len == 1 && p2->ext_len == 1)
+ return (0);
+ if (p1->ext_len <= 1)
+ return (-1);
+ if (p2->ext_len <= 1)
+ return (1);
+ l = p1->ext_len;
+ if (l > p2->ext_len)
+ l = p2->ext_len;
+ s1 = p1->identifier + p1->ext_off;
+ s2 = p2->identifier + p2->ext_off;
+ if (l > 1) {
+ cmp = memcmp(s1, s2, l);
+ if (cmp != 0)
+ return (cmp);
+ }
+ if (p1->ext_len < p2->ext_len) {
+ s2 += l;
+ l = p2->ext_len - p1->ext_len;
+ while (l--)
+ if (0x20 != *s2++)
+ return (0x20
+ - *(const unsigned char *)(s2 - 1));
+ } else if (p1->ext_len > p2->ext_len) {
+ s1 += l;
+ l = p1->ext_len - p2->ext_len;
+ while (l--)
+ if (0x20 != *s1++)
+ return (*(const unsigned char *)(s1 - 1)
+ - 0x20);
+ }
+ /* Compare File Version Number */
+ /* No operation. The File Version Number is always one. */
+
+ return (cmp);
+}
+
+static int
+isoent_cmp_node_iso9660(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ const struct idrent *e1 = (const struct idrent *)n1;
+ const struct idrent *e2 = (const struct idrent *)n2;
+
+ return (isoent_cmp_iso9660_identifier(e2->isoent, e1->isoent));
+}
+
+static int
+isoent_cmp_key_iso9660(const struct archive_rb_node *node, const void *key)
+{
+ const struct isoent *isoent = (const struct isoent *)key;
+ const struct idrent *idrent = (const struct idrent *)node;
+
+ return (isoent_cmp_iso9660_identifier(isoent, idrent->isoent));
+}
+
+static int
+isoent_cmp_joliet_identifier(const struct isoent *p1, const struct isoent *p2)
+{
+ const unsigned char *s1, *s2;
+ int cmp;
+ int l;
+
+ s1 = (const unsigned char *)p1->identifier;
+ s2 = (const unsigned char *)p2->identifier;
+
+ /* Compare File Name */
+ l = p1->ext_off;
+ if (l > p2->ext_off)
+ l = p2->ext_off;
+ cmp = memcmp(s1, s2, l);
+ if (cmp != 0)
+ return (cmp);
+ if (p1->ext_off < p2->ext_off) {
+ s2 += l;
+ l = p2->ext_off - p1->ext_off;
+ while (l--)
+ if (0 != *s2++)
+ return (- *(const unsigned char *)(s2 - 1));
+ } else if (p1->ext_off > p2->ext_off) {
+ s1 += l;
+ l = p1->ext_off - p2->ext_off;
+ while (l--)
+ if (0 != *s1++)
+ return (*(const unsigned char *)(s1 - 1));
+ }
+ /* Compare File Name Extension */
+ if (p1->ext_len == 0 && p2->ext_len == 0)
+ return (0);
+ if (p1->ext_len == 2 && p2->ext_len == 2)
+ return (0);
+ if (p1->ext_len <= 2)
+ return (-1);
+ if (p2->ext_len <= 2)
+ return (1);
+ l = p1->ext_len;
+ if (l > p2->ext_len)
+ l = p2->ext_len;
+ s1 = (unsigned char *)(p1->identifier + p1->ext_off);
+ s2 = (unsigned char *)(p2->identifier + p2->ext_off);
+ if (l > 1) {
+ cmp = memcmp(s1, s2, l);
+ if (cmp != 0)
+ return (cmp);
+ }
+ if (p1->ext_len < p2->ext_len) {
+ s2 += l;
+ l = p2->ext_len - p1->ext_len;
+ while (l--)
+ if (0 != *s2++)
+ return (- *(const unsigned char *)(s2 - 1));
+ } else if (p1->ext_len > p2->ext_len) {
+ s1 += l;
+ l = p1->ext_len - p2->ext_len;
+ while (l--)
+ if (0 != *s1++)
+ return (*(const unsigned char *)(s1 - 1));
+ }
+ /* Compare File Version Number */
+ /* No operation. The File Version Number is always one. */
+
+ return (cmp);
+}
+
+static int
+isoent_cmp_node_joliet(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ const struct idrent *e1 = (const struct idrent *)n1;
+ const struct idrent *e2 = (const struct idrent *)n2;
+
+ return (isoent_cmp_joliet_identifier(e2->isoent, e1->isoent));
+}
+
+static int
+isoent_cmp_key_joliet(const struct archive_rb_node *node, const void *key)
+{
+ const struct isoent *isoent = (const struct isoent *)key;
+ const struct idrent *idrent = (const struct idrent *)node;
+
+ return (isoent_cmp_joliet_identifier(isoent, idrent->isoent));
+}
+
+static int
+isoent_make_sorted_files(struct archive_write *a, struct isoent *isoent,
+ struct idr *idr)
+{
+ struct archive_rb_node *rn;
+ struct isoent **children;
+
+ children = malloc(isoent->children.cnt * sizeof(struct isoent *));
+ if (children == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ isoent->children_sorted = children;
+
+ ARCHIVE_RB_TREE_FOREACH(rn, &(idr->rbtree)) {
+ struct idrent *idrent = (struct idrent *)rn;
+ *children ++ = idrent->isoent;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * - Generate ISO9660 and Joliet identifiers from basenames.
+ * - Sort files by each directory.
+ */
+static int
+isoent_traverse_tree(struct archive_write *a, struct vdd* vdd)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isoent *np;
+ struct idr idr;
+ int depth;
+ int r;
+ int (*genid)(struct archive_write *, struct isoent *, struct idr *);
+
+ idr_init(iso9660, vdd, &idr);
+ np = vdd->rootent;
+ depth = 0;
+ if (vdd->vdd_type == VDD_JOLIET)
+ genid = isoent_gen_joliet_identifier;
+ else
+ genid = isoent_gen_iso9660_identifier;
+ do {
+ if (np->virtual &&
+ !archive_entry_mtime_is_set(np->file->entry)) {
+ /* Set properly times to virtual directory */
+ archive_entry_set_mtime(np->file->entry,
+ iso9660->birth_time, 0);
+ archive_entry_set_atime(np->file->entry,
+ iso9660->birth_time, 0);
+ archive_entry_set_ctime(np->file->entry,
+ iso9660->birth_time, 0);
+ }
+ if (np->children.first != NULL) {
+ if (vdd->vdd_type != VDD_JOLIET &&
+ !iso9660->opt.rr && depth + 1 >= vdd->max_depth) {
+ if (np->children.cnt > 0)
+ iso9660->directories_too_deep = np;
+ } else {
+ /* Generate Identifier */
+ r = genid(a, np, &idr);
+ if (r < 0)
+ goto exit_traverse_tree;
+ r = isoent_make_sorted_files(a, np, &idr);
+ if (r < 0)
+ goto exit_traverse_tree;
+
+ if (np->subdirs.first != NULL &&
+ depth + 1 < vdd->max_depth) {
+ /* Enter to sub directories. */
+ np = np->subdirs.first;
+ depth++;
+ continue;
+ }
+ }
+ }
+ while (np != np->parent) {
+ if (np->drnext == NULL) {
+ /* Return to the parent directory. */
+ np = np->parent;
+ depth--;
+ } else {
+ np = np->drnext;
+ break;
+ }
+ }
+ } while (np != np->parent);
+
+ r = ARCHIVE_OK;
+exit_traverse_tree:
+ idr_cleanup(&idr);
+
+ return (r);
+}
+
+/*
+ * Collect directory entries into path_table by a directory depth.
+ */
+static int
+isoent_collect_dirs(struct vdd *vdd, struct isoent *rootent, int depth)
+{
+ struct isoent *np;
+
+ if (rootent == NULL)
+ rootent = vdd->rootent;
+ np = rootent;
+ do {
+ /* Register current directory to pathtable. */
+ path_table_add_entry(&(vdd->pathtbl[depth]), np);
+
+ if (np->subdirs.first != NULL && depth + 1 < vdd->max_depth) {
+ /* Enter to sub directories. */
+ np = np->subdirs.first;
+ depth++;
+ continue;
+ }
+ while (np != rootent) {
+ if (np->drnext == NULL) {
+ /* Return to the parent directory. */
+ np = np->parent;
+ depth--;
+ } else {
+ np = np->drnext;
+ break;
+ }
+ }
+ } while (np != rootent);
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * The entry whose number of levels in a directory hierarchy is
+ * large than eight relocate to rr_move directory.
+ */
+static int
+isoent_rr_move_dir(struct archive_write *a, struct isoent **rr_moved,
+ struct isoent *curent, struct isoent **newent)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isoent *rrmoved, *mvent, *np;
+
+ if ((rrmoved = *rr_moved) == NULL) {
+ struct isoent *rootent = iso9660->primary.rootent;
+ /* There isn't rr_move entry.
+ * Create rr_move entry and insert it into the root entry.
+ */
+ rrmoved = isoent_create_virtual_dir(a, iso9660, "rr_moved");
+ if (rrmoved == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ /* Add "rr_moved" entry to the root entry. */
+ isoent_add_child_head(rootent, rrmoved);
+ archive_entry_set_nlink(rootent->file->entry,
+ archive_entry_nlink(rootent->file->entry) + 1);
+ /* Register "rr_moved" entry to second level pathtable. */
+ path_table_add_entry(&(iso9660->primary.pathtbl[1]), rrmoved);
+ /* Save rr_moved. */
+ *rr_moved = rrmoved;
+ }
+ /*
+ * Make a clone of curent which is going to be relocated
+ * to rr_moved.
+ */
+ mvent = isoent_clone(curent);
+ if (mvent == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ /* linking.. and use for creating "CL", "PL" and "RE" */
+ mvent->rr_parent = curent->parent;
+ curent->rr_child = mvent;
+ /*
+ * Move subdirectories from the curent to mvent
+ */
+ if (curent->children.first != NULL) {
+ *mvent->children.last = curent->children.first;
+ mvent->children.last = curent->children.last;
+ }
+ for (np = mvent->children.first; np != NULL; np = np->chnext)
+ np->parent = mvent;
+ mvent->children.cnt = curent->children.cnt;
+ curent->children.cnt = 0;
+ curent->children.first = NULL;
+ curent->children.last = &curent->children.first;
+
+ if (curent->subdirs.first != NULL) {
+ *mvent->subdirs.last = curent->subdirs.first;
+ mvent->subdirs.last = curent->subdirs.last;
+ }
+ mvent->subdirs.cnt = curent->subdirs.cnt;
+ curent->subdirs.cnt = 0;
+ curent->subdirs.first = NULL;
+ curent->subdirs.last = &curent->subdirs.first;
+
+ /*
+ * The mvent becomes a child of the rr_moved entry.
+ */
+ isoent_add_child_tail(rrmoved, mvent);
+ archive_entry_set_nlink(rrmoved->file->entry,
+ archive_entry_nlink(rrmoved->file->entry) + 1);
+ /*
+ * This entry which relocated to the rr_moved directory
+ * has to set the flag as a file.
+ * See also RRIP 4.1.5.1 Description of the "CL" System Use Entry.
+ */
+ curent->dir = 0;
+
+ *newent = mvent;
+
+ return (ARCHIVE_OK);
+}
+
+static int
+isoent_rr_move(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct path_table *pt;
+ struct isoent *rootent, *rr_moved;
+ struct isoent *np, *last;
+ int r;
+
+ pt = &(iso9660->primary.pathtbl[MAX_DEPTH-1]);
+ /* Theare aren't level 8 directories reaching a deepr level. */
+ if (pt->cnt == 0)
+ return (ARCHIVE_OK);
+
+ rootent = iso9660->primary.rootent;
+ /* If "rr_moved" directory is already existing,
+ * we have to use it. */
+ rr_moved = isoent_find_child(rootent, "rr_moved");
+ if (rr_moved != NULL &&
+ rr_moved != rootent->children.first) {
+ /*
+ * It's necessary that rr_move is the first entry
+ * of the root.
+ */
+ /* Remove "rr_moved" entry from children chain. */
+ isoent_remove_child(rootent, rr_moved);
+
+ /* Add "rr_moved" entry into the head of children chain. */
+ isoent_add_child_head(rootent, rr_moved);
+ }
+
+ /*
+ * Check level 8 path_table.
+ * If find out sub directory entries, that entries move to rr_move.
+ */
+ np = pt->first;
+ while (np != NULL) {
+ last = path_table_last_entry(pt);
+ for (; np != NULL; np = np->ptnext) {
+ struct isoent *mvent;
+ struct isoent *newent;
+
+ if (!np->dir)
+ continue;
+ for (mvent = np->subdirs.first;
+ mvent != NULL; mvent = mvent->drnext) {
+ r = isoent_rr_move_dir(a, &rr_moved,
+ mvent, &newent);
+ if (r < 0)
+ return (r);
+ isoent_collect_dirs(&(iso9660->primary),
+ newent, 2);
+ }
+ }
+ /* If new entries are added to level 8 path_talbe,
+ * its sub directory entries move to rr_move too.
+ */
+ np = last->ptnext;
+ }
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * This comparing rule is according to ISO9660 Standard 6.9.1
+ */
+static int
+_compare_path_table(const void *v1, const void *v2)
+{
+ const struct isoent *p1, *p2;
+ const char *s1, *s2;
+ int cmp, l;
+
+ p1 = *((const struct isoent **)(uintptr_t)v1);
+ p2 = *((const struct isoent **)(uintptr_t)v2);
+
+ /* Compare parent directory number */
+ cmp = p1->parent->dir_number - p2->parent->dir_number;
+ if (cmp != 0)
+ return (cmp);
+
+ /* Compare indetifier */
+ s1 = p1->identifier;
+ s2 = p2->identifier;
+ l = p1->ext_off;
+ if (l > p2->ext_off)
+ l = p2->ext_off;
+ cmp = strncmp(s1, s2, l);
+ if (cmp != 0)
+ return (cmp);
+ if (p1->ext_off < p2->ext_off) {
+ s2 += l;
+ l = p2->ext_off - p1->ext_off;
+ while (l--)
+ if (0x20 != *s2++)
+ return (0x20
+ - *(const unsigned char *)(s2 - 1));
+ } else if (p1->ext_off > p2->ext_off) {
+ s1 += l;
+ l = p1->ext_off - p2->ext_off;
+ while (l--)
+ if (0x20 != *s1++)
+ return (*(const unsigned char *)(s1 - 1)
+ - 0x20);
+ }
+ return (0);
+}
+
+static int
+_compare_path_table_joliet(const void *v1, const void *v2)
+{
+ const struct isoent *p1, *p2;
+ const unsigned char *s1, *s2;
+ int cmp, l;
+
+ p1 = *((const struct isoent **)(uintptr_t)v1);
+ p2 = *((const struct isoent **)(uintptr_t)v2);
+
+ /* Compare parent directory number */
+ cmp = p1->parent->dir_number - p2->parent->dir_number;
+ if (cmp != 0)
+ return (cmp);
+
+ /* Compare indetifier */
+ s1 = (const unsigned char *)p1->identifier;
+ s2 = (const unsigned char *)p2->identifier;
+ l = p1->ext_off;
+ if (l > p2->ext_off)
+ l = p2->ext_off;
+ cmp = memcmp(s1, s2, l);
+ if (cmp != 0)
+ return (cmp);
+ if (p1->ext_off < p2->ext_off) {
+ s2 += l;
+ l = p2->ext_off - p1->ext_off;
+ while (l--)
+ if (0 != *s2++)
+ return (- *(const unsigned char *)(s2 - 1));
+ } else if (p1->ext_off > p2->ext_off) {
+ s1 += l;
+ l = p1->ext_off - p2->ext_off;
+ while (l--)
+ if (0 != *s1++)
+ return (*(const unsigned char *)(s1 - 1));
+ }
+ return (0);
+}
+
+static inline void
+path_table_add_entry(struct path_table *pathtbl, struct isoent *ent)
+{
+ ent->ptnext = NULL;
+ *pathtbl->last = ent;
+ pathtbl->last = &(ent->ptnext);
+ pathtbl->cnt ++;
+}
+
+static inline struct isoent *
+path_table_last_entry(struct path_table *pathtbl)
+{
+ if (pathtbl->first == NULL)
+ return (NULL);
+ return (((struct isoent *)(void *)
+ ((char *)(pathtbl->last) - offsetof(struct isoent, ptnext))));
+}
+
+/*
+ * Sort directory entries in path_table
+ * and assign directory number to each entries.
+ */
+static int
+isoent_make_path_table_2(struct archive_write *a, struct vdd *vdd,
+ int depth, int *dir_number)
+{
+ struct isoent *np;
+ struct isoent **enttbl;
+ struct path_table *pt;
+ int i;
+
+ pt = &vdd->pathtbl[depth];
+ if (pt->cnt == 0) {
+ pt->sorted = NULL;
+ return (ARCHIVE_OK);
+ }
+ enttbl = malloc(pt->cnt * sizeof(struct isoent *));
+ if (enttbl == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ pt->sorted = enttbl;
+ for (np = pt->first; np != NULL; np = np->ptnext)
+ *enttbl ++ = np;
+ enttbl = pt->sorted;
+
+ switch (vdd->vdd_type) {
+ case VDD_PRIMARY:
+ case VDD_ENHANCED:
+#ifdef __COMPAR_FN_T
+ qsort(enttbl, pt->cnt, sizeof(struct isoent *),
+ (__compar_fn_t)_compare_path_table);
+#else
+ qsort(enttbl, pt->cnt, sizeof(struct isoent *),
+ _compare_path_table);
+#endif
+ break;
+ case VDD_JOLIET:
+#ifdef __COMPAR_FN_T
+ qsort(enttbl, pt->cnt, sizeof(struct isoent *),
+ (__compar_fn_t)_compare_path_table_joliet);
+#else
+ qsort(enttbl, pt->cnt, sizeof(struct isoent *),
+ _compare_path_table_joliet);
+#endif
+ break;
+ }
+ for (i = 0; i < pt->cnt; i++)
+ enttbl[i]->dir_number = (*dir_number)++;
+
+ return (ARCHIVE_OK);
+}
+
+static int
+isoent_alloc_path_table(struct archive_write *a, struct vdd *vdd,
+ int max_depth)
+{
+ int i;
+
+ vdd->max_depth = max_depth;
+ vdd->pathtbl = malloc(sizeof(*vdd->pathtbl) * vdd->max_depth);
+ if (vdd->pathtbl == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ for (i = 0; i < vdd->max_depth; i++) {
+ vdd->pathtbl[i].first = NULL;
+ vdd->pathtbl[i].last = &(vdd->pathtbl[i].first);
+ vdd->pathtbl[i].sorted = NULL;
+ vdd->pathtbl[i].cnt = 0;
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Make Path Tables
+ */
+static int
+isoent_make_path_table(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ int depth, r;
+ int dir_number;
+
+ /*
+ * Init Path Table.
+ */
+ if (iso9660->dircnt_max >= MAX_DEPTH &&
+ (!iso9660->opt.limit_depth || iso9660->opt.iso_level == 4))
+ r = isoent_alloc_path_table(a, &(iso9660->primary),
+ iso9660->dircnt_max + 1);
+ else
+ /* The number of levels in the hierarchy cannot exceed
+ * eight. */
+ r = isoent_alloc_path_table(a, &(iso9660->primary),
+ MAX_DEPTH);
+ if (r < 0)
+ return (r);
+ if (iso9660->opt.joliet) {
+ r = isoent_alloc_path_table(a, &(iso9660->joliet),
+ iso9660->dircnt_max + 1);
+ if (r < 0)
+ return (r);
+ }
+
+ /* Step 0.
+ * - Collect directories for primary and joliet.
+ */
+ isoent_collect_dirs(&(iso9660->primary), NULL, 0);
+ if (iso9660->opt.joliet)
+ isoent_collect_dirs(&(iso9660->joliet), NULL, 0);
+ /*
+ * Rockridge; move deeper depth directories to rr_moved.
+ */
+ if (iso9660->opt.rr) {
+ r = isoent_rr_move(a);
+ if (r < 0)
+ return (r);
+ }
+
+ /* Update nlink. */
+ isofile_connect_hardlink_files(iso9660);
+
+ /* Step 1.
+ * - Renew a value of the depth of that directories.
+ * - Resolve hardlinks.
+ * - Convert pathnames to ISO9660 name or UCS2(joliet).
+ * - Sort files by each directory.
+ */
+ r = isoent_traverse_tree(a, &(iso9660->primary));
+ if (r < 0)
+ return (r);
+ if (iso9660->opt.joliet) {
+ r = isoent_traverse_tree(a, &(iso9660->joliet));
+ if (r < 0)
+ return (r);
+ }
+
+ /* Step 2.
+ * - Sort directories.
+ * - Assign all directory number.
+ */
+ dir_number = 1;
+ for (depth = 0; depth < iso9660->primary.max_depth; depth++) {
+ r = isoent_make_path_table_2(a, &(iso9660->primary),
+ depth, &dir_number);
+ if (r < 0)
+ return (r);
+ }
+ if (iso9660->opt.joliet) {
+ dir_number = 1;
+ for (depth = 0; depth < iso9660->joliet.max_depth; depth++) {
+ r = isoent_make_path_table_2(a, &(iso9660->joliet),
+ depth, &dir_number);
+ if (r < 0)
+ return (r);
+ }
+ }
+ if (iso9660->opt.limit_dirs && dir_number > 0xffff) {
+ /*
+ * Maximum number of directories is 65535(0xffff)
+ * doe to size(16bit) of Parent Directory Number of
+ * the Path Table.
+ * See also ISO9660 Standard 9.4.
+ */
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Too many directories(%d) over 65535.", dir_number);
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Get the size of the Path Table. */
+ calculate_path_table_size(&(iso9660->primary));
+ if (iso9660->opt.joliet)
+ calculate_path_table_size(&(iso9660->joliet));
+
+ return (ARCHIVE_OK);
+}
+
+static int
+isoent_find_out_boot_file(struct archive_write *a, struct isoent *rootent)
+{
+ struct iso9660 *iso9660 = a->format_data;
+
+ /* Find a isoent of the boot file. */
+ iso9660->el_torito.boot = isoent_find_entry(rootent,
+ iso9660->el_torito.boot_filename.s);
+ if (iso9660->el_torito.boot == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't find the boot image file ``%s''",
+ iso9660->el_torito.boot_filename.s);
+ return (ARCHIVE_FATAL);
+ }
+ iso9660->el_torito.boot->file->boot = BOOT_IMAGE;
+ return (ARCHIVE_OK);
+}
+
+static int
+isoent_create_boot_catalog(struct archive_write *a, struct isoent *rootent)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isofile *file;
+ struct isoent *isoent;
+ struct archive_entry *entry;
+
+ (void)rootent; /* UNUSED */
+ /*
+ * Create the entry which is the "boot.catalog" file.
+ */
+ file = isofile_new(a, NULL);
+ if (file == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ archive_entry_set_pathname(file->entry,
+ iso9660->el_torito.catalog_filename.s);
+ archive_entry_set_size(file->entry, LOGICAL_BLOCK_SIZE);
+ archive_entry_set_mtime(file->entry, iso9660->birth_time, 0);
+ archive_entry_set_atime(file->entry, iso9660->birth_time, 0);
+ archive_entry_set_ctime(file->entry, iso9660->birth_time, 0);
+ archive_entry_set_uid(file->entry, getuid());
+ archive_entry_set_gid(file->entry, getgid());
+ archive_entry_set_mode(file->entry, AE_IFREG | 0444);
+ archive_entry_set_nlink(file->entry, 1);
+
+ if (isofile_gen_utility_names(a, file) < ARCHIVE_WARN) {
+ isofile_free(file);
+ return (ARCHIVE_FATAL);
+ }
+ file->boot = BOOT_CATALOG;
+ file->content.size = LOGICAL_BLOCK_SIZE;
+ isofile_add_entry(iso9660, file);
+
+ isoent = isoent_new(file);
+ if (isoent == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ isoent->virtual = 1;
+
+ /* Add the "boot.catalog" entry into tree */
+ if (isoent_tree(a, &isoent) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ iso9660->el_torito.catalog = isoent;
+ /*
+ * Get a boot medai type.
+ */
+ switch (iso9660->opt.boot_type) {
+ default:
+ case OPT_BOOT_TYPE_AUTO:
+ /* Try detecting a media type of the boot image. */
+ entry = iso9660->el_torito.boot->file->entry;
+ if (archive_entry_size(entry) == FD_1_2M_SIZE)
+ iso9660->el_torito.media_type =
+ BOOT_MEDIA_1_2M_DISKETTE;
+ else if (archive_entry_size(entry) == FD_1_44M_SIZE)
+ iso9660->el_torito.media_type =
+ BOOT_MEDIA_1_44M_DISKETTE;
+ else if (archive_entry_size(entry) == FD_2_88M_SIZE)
+ iso9660->el_torito.media_type =
+ BOOT_MEDIA_2_88M_DISKETTE;
+ else
+ /* We cannot decide whether the boot image is
+ * hard-disk. */
+ iso9660->el_torito.media_type =
+ BOOT_MEDIA_NO_EMULATION;
+ break;
+ case OPT_BOOT_TYPE_NO_EMU:
+ iso9660->el_torito.media_type = BOOT_MEDIA_NO_EMULATION;
+ break;
+ case OPT_BOOT_TYPE_HARD_DISK:
+ iso9660->el_torito.media_type = BOOT_MEDIA_HARD_DISK;
+ break;
+ case OPT_BOOT_TYPE_FD:
+ entry = iso9660->el_torito.boot->file->entry;
+ if (archive_entry_size(entry) <= FD_1_2M_SIZE)
+ iso9660->el_torito.media_type =
+ BOOT_MEDIA_1_2M_DISKETTE;
+ else if (archive_entry_size(entry) <= FD_1_44M_SIZE)
+ iso9660->el_torito.media_type =
+ BOOT_MEDIA_1_44M_DISKETTE;
+ else if (archive_entry_size(entry) <= FD_2_88M_SIZE)
+ iso9660->el_torito.media_type =
+ BOOT_MEDIA_2_88M_DISKETTE;
+ else {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Boot image file(``%s'') size is too big "
+ "for fd type.",
+ iso9660->el_torito.boot_filename.s);
+ return (ARCHIVE_FATAL);
+ }
+ break;
+ }
+
+ /*
+ * Get a system type.
+ * TODO: `El Torito' specification says "A copy of byte 5 from the
+ * Partition Table found in the boot image".
+ */
+ iso9660->el_torito.system_type = 0;
+
+ /*
+ * Get an ID.
+ */
+ if (iso9660->opt.publisher)
+ archive_string_copy(&(iso9660->el_torito.id),
+ &(iso9660->publisher_identifier));
+
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * If a media type is floppy, return its image size.
+ * otherwise return 0.
+ */
+static size_t
+fd_boot_image_size(int media_type)
+{
+ switch (media_type) {
+ case BOOT_MEDIA_1_2M_DISKETTE:
+ return (FD_1_2M_SIZE);
+ case BOOT_MEDIA_1_44M_DISKETTE:
+ return (FD_1_44M_SIZE);
+ case BOOT_MEDIA_2_88M_DISKETTE:
+ return (FD_2_88M_SIZE);
+ default:
+ return (0);
+ }
+}
+
+/*
+ * Make a boot catalog image data.
+ */
+static int
+make_boot_catalog(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ unsigned char *block;
+ unsigned char *p;
+ uint16_t sum, *wp;
+
+ block = wb_buffptr(a);
+ memset(block, 0, LOGICAL_BLOCK_SIZE);
+ p = block;
+ /*
+ * Validation Entry
+ */
+ /* Header ID */
+ p[0] = 1;
+ /* Platform ID */
+ p[1] = iso9660->el_torito.platform_id;
+ /* Reserved */
+ p[2] = p[3] = 0;
+ /* ID */
+ if (archive_strlen(&(iso9660->el_torito.id)) > 0)
+ strncpy((char *)p+4, iso9660->el_torito.id.s, 23);
+ p[27] = 0;
+ /* Checksum */
+ p[28] = p[29] = 0;
+ /* Key */
+ p[30] = 0x55;
+ p[31] = 0xAA;
+
+ sum = 0;
+ wp = (uint16_t *)block;
+ while (wp < (uint16_t *)&block[32])
+ sum += archive_le16dec(wp++);
+ set_num_721(&block[28], (~sum) + 1);
+
+ /*
+ * Initial/Default Entry
+ */
+ p = &block[32];
+ /* Boot Indicator */
+ p[0] = 0x88;
+ /* Boot media type */
+ p[1] = iso9660->el_torito.media_type;
+ /* Load Segment */
+ if (iso9660->el_torito.media_type == BOOT_MEDIA_NO_EMULATION)
+ set_num_721(&p[2], iso9660->el_torito.boot_load_seg);
+ else
+ set_num_721(&p[2], 0);
+ /* System Type */
+ p[4] = iso9660->el_torito.system_type;
+ /* Unused */
+ p[5] = 0;
+ /* Sector Count */
+ if (iso9660->el_torito.media_type == BOOT_MEDIA_NO_EMULATION)
+ set_num_721(&p[6], iso9660->el_torito.boot_load_size);
+ else
+ set_num_721(&p[6], 1);
+ /* Load RBA */
+ set_num_731(&p[8],
+ iso9660->el_torito.boot->file->content.location);
+ /* Unused */
+ memset(&p[12], 0, 20);
+
+ return (wb_consume(a, LOGICAL_BLOCK_SIZE));
+}
+
+static int
+setup_boot_information(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isoent *np;
+ int64_t size;
+ uint32_t sum;
+ unsigned char buff[4096];
+
+ np = iso9660->el_torito.boot;
+ lseek(iso9660->temp_fd,
+ np->file->content.offset_of_temp + 64, SEEK_SET);
+ size = archive_entry_size(np->file->entry) - 64;
+ if (size <= 0) {
+ archive_set_error(&a->archive, errno,
+ "Boot file(%jd) is too small", (intmax_t)size + 64);
+ return (ARCHIVE_FATAL);
+ }
+ sum = 0;
+ while (size > 0) {
+ size_t rsize;
+ ssize_t i, rs;
+
+ if (size > (int64_t)sizeof(buff))
+ rsize = sizeof(buff);
+ else
+ rsize = (size_t)size;
+
+ rs = read(iso9660->temp_fd, buff, rsize);
+ if (rs <= 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't read temporary file(%jd)",
+ (intmax_t)rs);
+ return (ARCHIVE_FATAL);
+ }
+ for (i = 0; i < rs; i += 4)
+ sum += archive_le32dec(buff + i);
+ size -= rs;
+ }
+ /* Set the location of Primary Volume Descriptor. */
+ set_num_731(buff, SYSTEM_AREA_BLOCK);
+ /* Set the location of the boot file. */
+ set_num_731(buff+4, np->file->content.location);
+ /* Set the size of the boot file. */
+ size = fd_boot_image_size(iso9660->el_torito.media_type);
+ if (size == 0)
+ size = archive_entry_size(np->file->entry);
+ set_num_731(buff+8, (uint32_t)size);
+ /* Set the sum of the boot file. */
+ set_num_731(buff+12, sum);
+ /* Clear reserved bytes. */
+ memset(buff+16, 0, 40);
+
+ /* Overwrite the boot file. */
+ lseek(iso9660->temp_fd,
+ np->file->content.offset_of_temp + 8, SEEK_SET);
+ return (write_to_temp(a, buff, 56));
+}
+
+#ifdef HAVE_ZLIB_H
+
+static int
+zisofs_init_zstream(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ int r;
+
+ iso9660->zisofs.stream.next_in = NULL;
+ iso9660->zisofs.stream.avail_in = 0;
+ iso9660->zisofs.stream.total_in = 0;
+ iso9660->zisofs.stream.total_out = 0;
+ if (iso9660->zisofs.stream_valid)
+ r = deflateReset(&(iso9660->zisofs.stream));
+ else {
+ r = deflateInit(&(iso9660->zisofs.stream),
+ iso9660->zisofs.compression_level);
+ iso9660->zisofs.stream_valid = 1;
+ }
+ switch (r) {
+ case Z_OK:
+ break;
+ default:
+ case Z_STREAM_ERROR:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing "
+ "compression library: invalid setup parameter");
+ return (ARCHIVE_FATAL);
+ case Z_MEM_ERROR:
+ archive_set_error(&a->archive, ENOMEM,
+ "Internal error initializing "
+ "compression library");
+ return (ARCHIVE_FATAL);
+ case Z_VERSION_ERROR:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing "
+ "compression library: invalid library version");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+
+#endif /* HAVE_ZLIB_H */
+
+static int
+zisofs_init(struct archive_write *a, struct isofile *file)
+{
+ struct iso9660 *iso9660 = a->format_data;
+#ifdef HAVE_ZLIB_H
+ uint64_t tsize;
+ size_t _ceil, bpsize;
+ int r;
+#endif
+
+ iso9660->zisofs.detect_magic = 0;
+ iso9660->zisofs.making = 0;
+
+ if (!iso9660->opt.rr || !iso9660->opt.zisofs)
+ return (ARCHIVE_OK);
+
+ if (archive_entry_size(file->entry) >= 24 &&
+ archive_entry_size(file->entry) < MULTI_EXTENT_SIZE) {
+ /* Acceptable file size for zisofs. */
+ iso9660->zisofs.detect_magic = 1;
+ iso9660->zisofs.magic_cnt = 0;
+ }
+ if (!iso9660->zisofs.detect_magic)
+ return (ARCHIVE_OK);
+
+#ifdef HAVE_ZLIB_H
+ /* The number of Logical Blocks which uncompressed data
+ * will use in iso-image file is the same as the number of
+ * Logical Blocks which zisofs(compressed) data will use
+ * in ISO-image file. It won't reduce iso-image file size. */
+ if (archive_entry_size(file->entry) <= LOGICAL_BLOCK_SIZE)
+ return (ARCHIVE_OK);
+
+ /* Initialize compression library */
+ r = zisofs_init_zstream(a);
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Mark file->zisofs to create RRIP 'ZF' Use Entry. */
+ file->zisofs.header_size = ZF_HEADER_SIZE >> 2;
+ file->zisofs.log2_bs = ZF_LOG2_BS;
+ file->zisofs.uncompressed_size =
+ (uint32_t)archive_entry_size(file->entry);
+
+ /* Calculate a size of Block Pointers of zisofs. */
+ _ceil = (file->zisofs.uncompressed_size + ZF_BLOCK_SIZE -1)
+ >> file->zisofs.log2_bs;
+ iso9660->zisofs.block_pointers_cnt = (int)_ceil + 1;
+ iso9660->zisofs.block_pointers_idx = 0;
+
+ /* Ensure a buffer size used for Block Pointers */
+ bpsize = iso9660->zisofs.block_pointers_cnt *
+ sizeof(iso9660->zisofs.block_pointers[0]);
+ if (iso9660->zisofs.block_pointers_allocated < bpsize) {
+ free(iso9660->zisofs.block_pointers);
+ iso9660->zisofs.block_pointers = malloc(bpsize);
+ if (iso9660->zisofs.block_pointers == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate data");
+ return (ARCHIVE_FATAL);
+ }
+ iso9660->zisofs.block_pointers_allocated = bpsize;
+ }
+
+ /*
+ * Skip zisofs header and Block Pointers, which we will write
+ * after all compressed data of a file written to the temporary
+ * file.
+ */
+ tsize = ZF_HEADER_SIZE + bpsize;
+ if (write_null(a, (size_t)tsize) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /*
+ * Initialize some variables to make zisofs.
+ */
+ archive_le32enc(&(iso9660->zisofs.block_pointers[0]),
+ (uint32_t)tsize);
+ iso9660->zisofs.remaining = file->zisofs.uncompressed_size;
+ iso9660->zisofs.making = 1;
+ iso9660->zisofs.allzero = 1;
+ iso9660->zisofs.block_offset = tsize;
+ iso9660->zisofs.total_size = tsize;
+ iso9660->cur_file->cur_content->size = tsize;
+#endif
+
+ return (ARCHIVE_OK);
+}
+
+static void
+zisofs_detect_magic(struct archive_write *a, const void *buff, size_t s)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isofile *file = iso9660->cur_file;
+ const unsigned char *p, *endp;
+ const unsigned char *magic_buff;
+ uint32_t uncompressed_size;
+ unsigned char header_size;
+ unsigned char log2_bs;
+ size_t _ceil, doff;
+ uint32_t bst, bed;
+ int magic_max;
+ int64_t entry_size;
+
+ entry_size = archive_entry_size(file->entry);
+ if ((int64_t)sizeof(iso9660->zisofs.magic_buffer) > entry_size)
+ magic_max = (int)entry_size;
+ else
+ magic_max = sizeof(iso9660->zisofs.magic_buffer);
+
+ if (iso9660->zisofs.magic_cnt == 0 && s >= (size_t)magic_max)
+ /* It's unnecessary we copy buffer. */
+ magic_buff = buff;
+ else {
+ if (iso9660->zisofs.magic_cnt < magic_max) {
+ size_t l;
+
+ l = sizeof(iso9660->zisofs.magic_buffer)
+ - iso9660->zisofs.magic_cnt;
+ if (l > s)
+ l = s;
+ memcpy(iso9660->zisofs.magic_buffer
+ + iso9660->zisofs.magic_cnt, buff, l);
+ iso9660->zisofs.magic_cnt += (int)l;
+ if (iso9660->zisofs.magic_cnt < magic_max)
+ return;
+ }
+ magic_buff = iso9660->zisofs.magic_buffer;
+ }
+ iso9660->zisofs.detect_magic = 0;
+ p = magic_buff;
+
+ /* Check the magic code of zisofs. */
+ if (memcmp(p, zisofs_magic, sizeof(zisofs_magic)) != 0)
+ /* This is not zisofs file which made by mkzftree. */
+ return;
+ p += sizeof(zisofs_magic);
+
+ /* Read a zisofs header. */
+ uncompressed_size = archive_le32dec(p);
+ header_size = p[4];
+ log2_bs = p[5];
+ if (uncompressed_size < 24 || header_size != 4 ||
+ log2_bs > 30 || log2_bs < 7)
+ return;/* Invalid or not supported header. */
+
+ /* Calculate a size of Block Pointers of zisofs. */
+ _ceil = (uncompressed_size +
+ (ARCHIVE_LITERAL_LL(1) << log2_bs) -1) >> log2_bs;
+ doff = (_ceil + 1) * 4 + 16;
+ if (entry_size < (int64_t)doff)
+ return;/* Invalid data. */
+
+ /* Check every Block Pointer has valid value. */
+ p = magic_buff + 16;
+ endp = magic_buff + magic_max;
+ while (_ceil && p + 8 <= endp) {
+ bst = archive_le32dec(p);
+ if (bst != doff)
+ return;/* Invalid data. */
+ p += 4;
+ bed = archive_le32dec(p);
+ if (bed < bst || bed > entry_size)
+ return;/* Invalid data. */
+ doff += bed - bst;
+ _ceil--;
+ }
+
+ file->zisofs.uncompressed_size = uncompressed_size;
+ file->zisofs.header_size = header_size;
+ file->zisofs.log2_bs = log2_bs;
+
+ /* Disable making a zisofs image. */
+ iso9660->zisofs.making = 0;
+}
+
+#ifdef HAVE_ZLIB_H
+
+/*
+ * Compress data and write it to a temporary file.
+ */
+static int
+zisofs_write_to_temp(struct archive_write *a, const void *buff, size_t s)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isofile *file = iso9660->cur_file;
+ const unsigned char *b;
+ z_stream *zstrm;
+ size_t avail, csize;
+ int flush, r;
+
+ zstrm = &(iso9660->zisofs.stream);
+ zstrm->next_out = wb_buffptr(a);
+ zstrm->avail_out = (uInt)wb_remaining(a);
+ b = (const unsigned char *)buff;
+ do {
+ avail = ZF_BLOCK_SIZE - zstrm->total_in;
+ if (s < avail) {
+ avail = s;
+ flush = Z_NO_FLUSH;
+ } else
+ flush = Z_FINISH;
+ iso9660->zisofs.remaining -= avail;
+ if (iso9660->zisofs.remaining <= 0)
+ flush = Z_FINISH;
+
+ zstrm->next_in = (Bytef *)(uintptr_t)(const void *)b;
+ zstrm->avail_in = (uInt)avail;
+
+ /*
+ * Check if current data block are all zero.
+ */
+ if (iso9660->zisofs.allzero) {
+ const unsigned char *nonzero = b;
+ const unsigned char *nonzeroend = b + avail;
+
+ while (nonzero < nonzeroend)
+ if (*nonzero++) {
+ iso9660->zisofs.allzero = 0;
+ break;
+ }
+ }
+ b += avail;
+ s -= avail;
+
+ /*
+ * If current data block are all zero, we do not use
+ * compressed data.
+ */
+ if (flush == Z_FINISH && iso9660->zisofs.allzero &&
+ avail + zstrm->total_in == ZF_BLOCK_SIZE) {
+ if (iso9660->zisofs.block_offset !=
+ file->cur_content->size) {
+ int64_t diff;
+
+ r = wb_set_offset(a,
+ file->cur_content->offset_of_temp +
+ iso9660->zisofs.block_offset);
+ if (r != ARCHIVE_OK)
+ return (r);
+ diff = file->cur_content->size -
+ iso9660->zisofs.block_offset;
+ file->cur_content->size -= diff;
+ iso9660->zisofs.total_size -= diff;
+ }
+ zstrm->avail_in = 0;
+ }
+
+ /*
+ * Compress file data.
+ */
+ while (zstrm->avail_in > 0) {
+ csize = zstrm->total_out;
+ r = deflate(zstrm, flush);
+ switch (r) {
+ case Z_OK:
+ case Z_STREAM_END:
+ csize = zstrm->total_out - csize;
+ if (wb_consume(a, csize) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ iso9660->zisofs.total_size += csize;
+ iso9660->cur_file->cur_content->size += csize;
+ zstrm->next_out = wb_buffptr(a);
+ zstrm->avail_out = (uInt)wb_remaining(a);
+ break;
+ default:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "Compression failed:"
+ " deflate() call returned status %d",
+ r);
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ if (flush == Z_FINISH) {
+ /*
+ * Save the information of one zisofs block.
+ */
+ iso9660->zisofs.block_pointers_idx ++;
+ archive_le32enc(&(iso9660->zisofs.block_pointers[
+ iso9660->zisofs.block_pointers_idx]),
+ (uint32_t)iso9660->zisofs.total_size);
+ r = zisofs_init_zstream(a);
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ iso9660->zisofs.allzero = 1;
+ iso9660->zisofs.block_offset = file->cur_content->size;
+ }
+ } while (s);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+zisofs_finish_entry(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isofile *file = iso9660->cur_file;
+ unsigned char buff[16];
+ size_t s;
+ int64_t tail;
+
+ /* Direct temp file stream to zisofs temp file stream. */
+ archive_entry_set_size(file->entry, iso9660->zisofs.total_size);
+
+ /*
+ * Save a file pointer which points the end of current zisofs data.
+ */
+ tail = wb_offset(a);
+
+ /*
+ * Make a header.
+ *
+ * +-----------------+----------------+-----------------+
+ * | Header 16 bytes | Block Pointers | Compressed data |
+ * +-----------------+----------------+-----------------+
+ * 0 16 +X
+ * Block Pointers :
+ * 4 * (((Uncompressed file size + block_size -1) / block_size) + 1)
+ *
+ * Write zisofs header.
+ * Magic number
+ * +----+----+----+----+----+----+----+----+
+ * | 37 | E4 | 53 | 96 | C9 | DB | D6 | 07 |
+ * +----+----+----+----+----+----+----+----+
+ * 0 1 2 3 4 5 6 7 8
+ *
+ * +------------------------+------------------+
+ * | Uncompressed file size | header_size >> 2 |
+ * +------------------------+------------------+
+ * 8 12 13
+ *
+ * +-----------------+----------------+
+ * | log2 block_size | Reserved(0000) |
+ * +-----------------+----------------+
+ * 13 14 16
+ */
+ memcpy(buff, zisofs_magic, 8);
+ set_num_731(buff+8, file->zisofs.uncompressed_size);
+ buff[12] = file->zisofs.header_size;
+ buff[13] = file->zisofs.log2_bs;
+ buff[14] = buff[15] = 0;/* Reserved */
+
+ /* Move to the right position to write the header. */
+ wb_set_offset(a, file->content.offset_of_temp);
+
+ /* Write the header. */
+ if (wb_write_to_temp(a, buff, 16) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /*
+ * Write zisofs Block Pointers.
+ */
+ s = iso9660->zisofs.block_pointers_cnt *
+ sizeof(iso9660->zisofs.block_pointers[0]);
+ if (wb_write_to_temp(a, iso9660->zisofs.block_pointers, s)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Set a file pointer back to the end of the temporary file. */
+ wb_set_offset(a, tail);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+zisofs_free(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ int ret = ARCHIVE_OK;
+
+ free(iso9660->zisofs.block_pointers);
+ if (iso9660->zisofs.stream_valid &&
+ deflateEnd(&(iso9660->zisofs.stream)) != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to clean up compressor");
+ ret = ARCHIVE_FATAL;
+ }
+ iso9660->zisofs.block_pointers = NULL;
+ iso9660->zisofs.stream_valid = 0;
+ return (ret);
+}
+
+struct zisofs_extract {
+ int pz_log2_bs; /* Log2 of block size */
+ uint64_t pz_uncompressed_size;
+ size_t uncompressed_buffer_size;
+
+ int initialized:1;
+ int header_passed:1;
+
+ uint32_t pz_offset;
+ unsigned char *block_pointers;
+ size_t block_pointers_size;
+ size_t block_pointers_avail;
+ size_t block_off;
+ uint32_t block_avail;
+
+ z_stream stream;
+ int stream_valid;
+};
+
+static ssize_t
+zisofs_extract_init(struct archive_write *a, struct zisofs_extract *zisofs,
+ const unsigned char *p, size_t bytes)
+{
+ size_t avail = bytes;
+ size_t _ceil, xsize;
+
+ /* Allocate block pointers buffer. */
+ _ceil = (size_t)((zisofs->pz_uncompressed_size +
+ (((int64_t)1) << zisofs->pz_log2_bs) - 1)
+ >> zisofs->pz_log2_bs);
+ xsize = (_ceil + 1) * 4;
+ if (zisofs->block_pointers == NULL) {
+ size_t alloc = ((xsize >> 10) + 1) << 10;
+ zisofs->block_pointers = malloc(alloc);
+ if (zisofs->block_pointers == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "No memory for zisofs decompression");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ zisofs->block_pointers_size = xsize;
+
+ /* Allocate uncompressed data buffer. */
+ zisofs->uncompressed_buffer_size = (size_t)1UL << zisofs->pz_log2_bs;
+
+ /*
+ * Read the file header, and check the magic code of zisofs.
+ */
+ if (!zisofs->header_passed) {
+ int err = 0;
+ if (avail < 16) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Illegal zisofs file body");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (memcmp(p, zisofs_magic, sizeof(zisofs_magic)) != 0)
+ err = 1;
+ else if (archive_le32dec(p + 8) != zisofs->pz_uncompressed_size)
+ err = 1;
+ else if (p[12] != 4 || p[13] != zisofs->pz_log2_bs)
+ err = 1;
+ if (err) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Illegal zisofs file body");
+ return (ARCHIVE_FATAL);
+ }
+ avail -= 16;
+ p += 16;
+ zisofs->header_passed = 1;
+ }
+
+ /*
+ * Read block pointers.
+ */
+ if (zisofs->header_passed &&
+ zisofs->block_pointers_avail < zisofs->block_pointers_size) {
+ xsize = zisofs->block_pointers_size
+ - zisofs->block_pointers_avail;
+ if (avail < xsize)
+ xsize = avail;
+ memcpy(zisofs->block_pointers
+ + zisofs->block_pointers_avail, p, xsize);
+ zisofs->block_pointers_avail += xsize;
+ avail -= xsize;
+ if (zisofs->block_pointers_avail
+ == zisofs->block_pointers_size) {
+ /* We've got all block pointers and initialize
+ * related variables. */
+ zisofs->block_off = 0;
+ zisofs->block_avail = 0;
+ /* Complete a initialization */
+ zisofs->initialized = 1;
+ }
+ }
+ return ((ssize_t)avail);
+}
+
+static ssize_t
+zisofs_extract(struct archive_write *a, struct zisofs_extract *zisofs,
+ const unsigned char *p, size_t bytes)
+{
+ size_t avail;
+ int r;
+
+ if (!zisofs->initialized) {
+ ssize_t rs = zisofs_extract_init(a, zisofs, p, bytes);
+ if (rs < 0)
+ return (rs);
+ if (!zisofs->initialized) {
+ /* We need more data. */
+ zisofs->pz_offset += (uint32_t)bytes;
+ return (bytes);
+ }
+ avail = rs;
+ p += bytes - avail;
+ } else
+ avail = bytes;
+
+ /*
+ * Get block offsets from block pointers.
+ */
+ if (zisofs->block_avail == 0) {
+ uint32_t bst, bed;
+
+ if (zisofs->block_off + 4 >= zisofs->block_pointers_size) {
+ /* There isn't a pair of offsets. */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Illegal zisofs block pointers");
+ return (ARCHIVE_FATAL);
+ }
+ bst = archive_le32dec(
+ zisofs->block_pointers + zisofs->block_off);
+ if (bst != zisofs->pz_offset + (bytes - avail)) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Illegal zisofs block pointers(cannot seek)");
+ return (ARCHIVE_FATAL);
+ }
+ bed = archive_le32dec(
+ zisofs->block_pointers + zisofs->block_off + 4);
+ if (bed < bst) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Illegal zisofs block pointers");
+ return (ARCHIVE_FATAL);
+ }
+ zisofs->block_avail = bed - bst;
+ zisofs->block_off += 4;
+
+ /* Initialize compression library for new block. */
+ if (zisofs->stream_valid)
+ r = inflateReset(&zisofs->stream);
+ else
+ r = inflateInit(&zisofs->stream);
+ if (r != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't initialize zisofs decompression.");
+ return (ARCHIVE_FATAL);
+ }
+ zisofs->stream_valid = 1;
+ zisofs->stream.total_in = 0;
+ zisofs->stream.total_out = 0;
+ }
+
+ /*
+ * Make uncompressed data.
+ */
+ if (zisofs->block_avail == 0) {
+ /*
+ * It's basically 32K bytes NUL data.
+ */
+ unsigned char *wb;
+ size_t size, wsize;
+
+ size = zisofs->uncompressed_buffer_size;
+ while (size) {
+ wb = wb_buffptr(a);
+ if (size > wb_remaining(a))
+ wsize = wb_remaining(a);
+ else
+ wsize = size;
+ memset(wb, 0, wsize);
+ r = wb_consume(a, wsize);
+ if (r < 0)
+ return (r);
+ size -= wsize;
+ }
+ } else {
+ zisofs->stream.next_in = (Bytef *)(uintptr_t)(const void *)p;
+ if (avail > zisofs->block_avail)
+ zisofs->stream.avail_in = zisofs->block_avail;
+ else
+ zisofs->stream.avail_in = (uInt)avail;
+ zisofs->stream.next_out = wb_buffptr(a);
+ zisofs->stream.avail_out = (uInt)wb_remaining(a);
+
+ r = inflate(&zisofs->stream, 0);
+ switch (r) {
+ case Z_OK: /* Decompressor made some progress.*/
+ case Z_STREAM_END: /* Found end of stream. */
+ break;
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "zisofs decompression failed (%d)", r);
+ return (ARCHIVE_FATAL);
+ }
+ avail -= zisofs->stream.next_in - p;
+ zisofs->block_avail -= (uint32_t)(zisofs->stream.next_in - p);
+ r = wb_consume(a, wb_remaining(a) - zisofs->stream.avail_out);
+ if (r < 0)
+ return (r);
+ }
+ zisofs->pz_offset += (uint32_t)bytes;
+ return (bytes - avail);
+}
+
+static int
+zisofs_rewind_boot_file(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+ struct isofile *file;
+ unsigned char *rbuff;
+ ssize_t r;
+ size_t remaining, rbuff_size;
+ struct zisofs_extract zext;
+ int64_t read_offset, write_offset, new_offset;
+ int fd, ret = ARCHIVE_OK;
+
+ file = iso9660->el_torito.boot->file;
+ /*
+ * There is nothing to do if this boot file does not have
+ * zisofs header.
+ */
+ if (file->zisofs.header_size == 0)
+ return (ARCHIVE_OK);
+
+ /*
+ * Uncompress the zisofs'ed file contents.
+ */
+ memset(&zext, 0, sizeof(zext));
+ zext.pz_uncompressed_size = file->zisofs.uncompressed_size;
+ zext.pz_log2_bs = file->zisofs.log2_bs;
+
+ fd = iso9660->temp_fd;
+ new_offset = wb_offset(a);
+ read_offset = file->content.offset_of_temp;
+ remaining = (size_t)file->content.size;
+ if (remaining > 1024 * 32)
+ rbuff_size = 1024 * 32;
+ else
+ rbuff_size = remaining;
+
+ rbuff = malloc(rbuff_size);
+ if (rbuff == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ while (remaining) {
+ size_t rsize;
+ ssize_t rs;
+
+ /* Get the current file pointer. */
+ write_offset = lseek(fd, 0, SEEK_CUR);
+
+ /* Change the file pointer to read. */
+ lseek(fd, read_offset, SEEK_SET);
+
+ rsize = rbuff_size;
+ if (rsize > remaining)
+ rsize = remaining;
+ rs = read(iso9660->temp_fd, rbuff, rsize);
+ if (rs <= 0) {
+ archive_set_error(&a->archive, errno,
+ "Can't read temporary file(%jd)", (intmax_t)rs);
+ ret = ARCHIVE_FATAL;
+ break;
+ }
+ remaining -= rs;
+ read_offset += rs;
+
+ /* Put the file pointer back to write. */
+ lseek(fd, write_offset, SEEK_SET);
+
+ r = zisofs_extract(a, &zext, rbuff, rs);
+ if (r < 0) {
+ ret = (int)r;
+ break;
+ }
+ }
+
+ if (ret == ARCHIVE_OK) {
+ /*
+ * Change the boot file content from zisofs'ed data
+ * to plain data.
+ */
+ file->content.offset_of_temp = new_offset;
+ file->content.size = file->zisofs.uncompressed_size;
+ archive_entry_set_size(file->entry, file->content.size);
+ /* Set to be no zisofs. */
+ file->zisofs.header_size = 0;
+ file->zisofs.log2_bs = 0;
+ file->zisofs.uncompressed_size = 0;
+ r = wb_write_padding_to_temp(a, file->content.size);
+ if (r < 0)
+ ret = ARCHIVE_FATAL;
+ }
+
+ /*
+ * Free the resource we used in this function only.
+ */
+ free(rbuff);
+ free(zext.block_pointers);
+ if (zext.stream_valid && inflateEnd(&(zext.stream)) != Z_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Failed to clean up compressor");
+ ret = ARCHIVE_FATAL;
+ }
+
+ return (ret);
+}
+
+#else
+
+static int
+zisofs_write_to_temp(struct archive_write *a, const void *buff, size_t s)
+{
+ (void)buff; /* UNUSED */
+ (void)s; /* UNUSED */
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Programing error");
+ return (ARCHIVE_FATAL);
+}
+
+static int
+zisofs_rewind_boot_file(struct archive_write *a)
+{
+ struct iso9660 *iso9660 = a->format_data;
+
+ if (iso9660->el_torito.boot->file->zisofs.header_size != 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "We cannot extract the zisofs imaged boot file;"
+ " this may not boot in being zisofs imaged");
+ return (ARCHIVE_FAILED);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+zisofs_finish_entry(struct archive_write *a)
+{
+ (void)a; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+static int
+zisofs_free(struct archive_write *a)
+{
+ (void)a; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+
+#endif /* HAVE_ZLIB_H */
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c
new file mode 100644
index 0000000000..b0c8018cb3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c
@@ -0,0 +1,2228 @@
+/*-
+ * Copyright (c) 2008 Joerg Sonnenberger
+ * Copyright (c) 2009-2012 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: head/lib/libarchive/archive_write_set_format_mtree.c 201171 2009-12-29 06:39:07Z kientzle $");
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "archive.h"
+#include "archive_crypto_private.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_rb.h"
+#include "archive_string.h"
+#include "archive_write_private.h"
+
+#define INDENTNAMELEN 15
+#define MAXLINELEN 80
+#define SET_KEYS \
+ (F_FLAGS | F_GID | F_GNAME | F_MODE | F_TYPE | F_UID | F_UNAME)
+
+struct attr_counter {
+ struct attr_counter *prev;
+ struct attr_counter *next;
+ struct mtree_entry *m_entry;
+ int count;
+};
+
+struct att_counter_set {
+ struct attr_counter *uid_list;
+ struct attr_counter *gid_list;
+ struct attr_counter *mode_list;
+ struct attr_counter *flags_list;
+};
+
+struct mtree_chain {
+ struct mtree_entry *first;
+ struct mtree_entry **last;
+};
+
+/*
+ * The Data only for a directory file.
+ */
+struct dir_info {
+ struct archive_rb_tree rbtree;
+ struct mtree_chain children;
+ struct mtree_entry *chnext;
+ int virtual;
+};
+
+/*
+ * The Data only for a regular file.
+ */
+struct reg_info {
+ int compute_sum;
+ uint32_t crc;
+#ifdef ARCHIVE_HAS_MD5
+ unsigned char buf_md5[16];
+#endif
+#ifdef ARCHIVE_HAS_RMD160
+ unsigned char buf_rmd160[20];
+#endif
+#ifdef ARCHIVE_HAS_SHA1
+ unsigned char buf_sha1[20];
+#endif
+#ifdef ARCHIVE_HAS_SHA256
+ unsigned char buf_sha256[32];
+#endif
+#ifdef ARCHIVE_HAS_SHA384
+ unsigned char buf_sha384[48];
+#endif
+#ifdef ARCHIVE_HAS_SHA512
+ unsigned char buf_sha512[64];
+#endif
+};
+
+struct mtree_entry {
+ struct archive_rb_node rbnode;
+ struct mtree_entry *next;
+ struct mtree_entry *parent;
+ struct dir_info *dir_info;
+ struct reg_info *reg_info;
+
+ struct archive_string parentdir;
+ struct archive_string basename;
+ struct archive_string pathname;
+ struct archive_string symlink;
+ struct archive_string uname;
+ struct archive_string gname;
+ struct archive_string fflags_text;
+ unsigned int nlink;
+ mode_t filetype;
+ mode_t mode;
+ int64_t size;
+ int64_t uid;
+ int64_t gid;
+ time_t mtime;
+ long mtime_nsec;
+ unsigned long fflags_set;
+ unsigned long fflags_clear;
+ dev_t rdevmajor;
+ dev_t rdevminor;
+ dev_t devmajor;
+ dev_t devminor;
+ int64_t ino;
+};
+
+struct mtree_writer {
+ struct mtree_entry *mtree_entry;
+ struct mtree_entry *root;
+ struct mtree_entry *cur_dirent;
+ struct archive_string cur_dirstr;
+ struct mtree_chain file_list;
+
+ struct archive_string ebuf;
+ struct archive_string buf;
+ int first;
+ uint64_t entry_bytes_remaining;
+
+ /*
+ * Set global value.
+ */
+ struct {
+ int processing;
+ mode_t type;
+ int keys;
+ int64_t uid;
+ int64_t gid;
+ mode_t mode;
+ unsigned long fflags_set;
+ unsigned long fflags_clear;
+ } set;
+ struct att_counter_set acs;
+ int classic;
+ int depth;
+
+ /* check sum */
+ int compute_sum;
+ uint32_t crc;
+ uint64_t crc_len;
+#ifdef ARCHIVE_HAS_MD5
+ archive_md5_ctx md5ctx;
+#endif
+#ifdef ARCHIVE_HAS_RMD160
+ archive_rmd160_ctx rmd160ctx;
+#endif
+#ifdef ARCHIVE_HAS_SHA1
+ archive_sha1_ctx sha1ctx;
+#endif
+#ifdef ARCHIVE_HAS_SHA256
+ archive_sha256_ctx sha256ctx;
+#endif
+#ifdef ARCHIVE_HAS_SHA384
+ archive_sha384_ctx sha384ctx;
+#endif
+#ifdef ARCHIVE_HAS_SHA512
+ archive_sha512_ctx sha512ctx;
+#endif
+ /* Keyword options */
+ int keys;
+#define F_CKSUM 0x00000001 /* check sum */
+#define F_DEV 0x00000002 /* device type */
+#define F_DONE 0x00000004 /* directory done */
+#define F_FLAGS 0x00000008 /* file flags */
+#define F_GID 0x00000010 /* gid */
+#define F_GNAME 0x00000020 /* group name */
+#define F_IGN 0x00000040 /* ignore */
+#define F_MAGIC 0x00000080 /* name has magic chars */
+#define F_MD5 0x00000100 /* MD5 digest */
+#define F_MODE 0x00000200 /* mode */
+#define F_NLINK 0x00000400 /* number of links */
+#define F_NOCHANGE 0x00000800 /* If owner/mode "wrong", do
+ * not change */
+#define F_OPT 0x00001000 /* existence optional */
+#define F_RMD160 0x00002000 /* RIPEMD160 digest */
+#define F_SHA1 0x00004000 /* SHA-1 digest */
+#define F_SIZE 0x00008000 /* size */
+#define F_SLINK 0x00010000 /* symbolic link */
+#define F_TAGS 0x00020000 /* tags */
+#define F_TIME 0x00040000 /* modification time */
+#define F_TYPE 0x00080000 /* file type */
+#define F_UID 0x00100000 /* uid */
+#define F_UNAME 0x00200000 /* user name */
+#define F_VISIT 0x00400000 /* file visited */
+#define F_SHA256 0x00800000 /* SHA-256 digest */
+#define F_SHA384 0x01000000 /* SHA-384 digest */
+#define F_SHA512 0x02000000 /* SHA-512 digest */
+#define F_INO 0x04000000 /* inode number */
+#define F_RESDEV 0x08000000 /* device ID on which the
+ * entry resides */
+
+ /* Options */
+ int dironly; /* If it is set, ignore all files except
+ * directory files, like mtree(8) -d option. */
+ int indent; /* If it is set, indent output data. */
+ int output_global_set; /* If it is set, use /set keyword to set
+ * global values. When generating mtree
+ * classic format, it is set by default. */
+};
+
+#define DEFAULT_KEYS (F_DEV | F_FLAGS | F_GID | F_GNAME | F_SLINK | F_MODE\
+ | F_NLINK | F_SIZE | F_TIME | F_TYPE | F_UID\
+ | F_UNAME)
+#define attr_counter_set_reset attr_counter_set_free
+
+static void attr_counter_free(struct attr_counter **);
+static int attr_counter_inc(struct attr_counter **, struct attr_counter *,
+ struct attr_counter *, struct mtree_entry *);
+static struct attr_counter * attr_counter_new(struct mtree_entry *,
+ struct attr_counter *);
+static int attr_counter_set_collect(struct mtree_writer *,
+ struct mtree_entry *);
+static void attr_counter_set_free(struct mtree_writer *);
+static int get_global_set_keys(struct mtree_writer *, struct mtree_entry *);
+static int mtree_entry_add_child_tail(struct mtree_entry *,
+ struct mtree_entry *);
+static int mtree_entry_create_virtual_dir(struct archive_write *, const char *,
+ struct mtree_entry **);
+static int mtree_entry_cmp_node(const struct archive_rb_node *,
+ const struct archive_rb_node *);
+static int mtree_entry_cmp_key(const struct archive_rb_node *, const void *);
+static int mtree_entry_exchange_same_entry(struct archive_write *,
+ struct mtree_entry *, struct mtree_entry *);
+static void mtree_entry_free(struct mtree_entry *);
+static int mtree_entry_new(struct archive_write *, struct archive_entry *,
+ struct mtree_entry **);
+static void mtree_entry_register_free(struct mtree_writer *);
+static void mtree_entry_register_init(struct mtree_writer *);
+static int mtree_entry_setup_filenames(struct archive_write *,
+ struct mtree_entry *, struct archive_entry *);
+static int mtree_entry_tree_add(struct archive_write *, struct mtree_entry **);
+static void sum_init(struct mtree_writer *);
+static void sum_update(struct mtree_writer *, const void *, size_t);
+static void sum_final(struct mtree_writer *, struct reg_info *);
+static void sum_write(struct archive_string *, struct reg_info *);
+static int write_mtree_entry(struct archive_write *, struct mtree_entry *);
+static int write_dot_dot_entry(struct archive_write *, struct mtree_entry *);
+
+#define COMPUTE_CRC(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]
+static const uint32_t crctab[] = {
+ 0x0,
+ 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
+ 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
+ 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
+ 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
+ 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
+ 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
+ 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
+ 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58,
+ 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033,
+ 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe,
+ 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
+ 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4,
+ 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
+ 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5,
+ 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
+ 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07,
+ 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c,
+ 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1,
+ 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
+ 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b,
+ 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698,
+ 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d,
+ 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
+ 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f,
+ 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
+ 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80,
+ 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
+ 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a,
+ 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629,
+ 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c,
+ 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
+ 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e,
+ 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65,
+ 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8,
+ 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
+ 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2,
+ 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
+ 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74,
+ 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
+ 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21,
+ 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a,
+ 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087,
+ 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
+ 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d,
+ 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce,
+ 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb,
+ 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
+ 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09,
+ 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
+ 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf,
+ 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
+};
+
+static const unsigned char safe_char[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */
+ /* !"$%&'()*+,-./ EXCLUSION:0x20( ) 0x23(#) */
+ 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */
+ /* 0123456789:;<>? EXCLUSION:0x3d(=) */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, /* 30 - 3F */
+ /* @ABCDEFGHIJKLMNO */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */
+ /* PQRSTUVWXYZ[]^_ EXCLUSION:0x5c(\) */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, /* 50 - 5F */
+ /* `abcdefghijklmno */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */
+ /* pqrstuvwxyz{|}~ */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, /* 70 - 7F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */
+ 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 */
+};
+
+static void
+mtree_quote(struct archive_string *s, const char *str)
+{
+ const char *start;
+ char buf[4];
+ unsigned char c;
+
+ for (start = str; *str != '\0'; ++str) {
+ if (safe_char[*(const unsigned char *)str])
+ continue;
+ if (start != str)
+ archive_strncat(s, start, str - start);
+ c = (unsigned char)*str;
+ buf[0] = '\\';
+ buf[1] = (c / 64) + '0';
+ buf[2] = (c / 8 % 8) + '0';
+ buf[3] = (c % 8) + '0';
+ archive_strncat(s, buf, 4);
+ start = str + 1;
+ }
+
+ if (start != str)
+ archive_strncat(s, start, str - start);
+}
+
+/*
+ * Indent a line as mtree utility to be readable for people.
+ */
+static void
+mtree_indent(struct mtree_writer *mtree)
+{
+ int i, fn, nd, pd;
+ const char *r, *s, *x;
+
+ if (mtree->classic) {
+ if (mtree->indent) {
+ nd = 0;
+ pd = mtree->depth * 4;
+ } else {
+ nd = mtree->depth?4:0;
+ pd = 0;
+ }
+ } else
+ nd = pd = 0;
+ fn = 1;
+ s = r = mtree->ebuf.s;
+ x = NULL;
+ while (*r == ' ')
+ r++;
+ while ((r = strchr(r, ' ')) != NULL) {
+ if (fn) {
+ fn = 0;
+ for (i = 0; i < nd + pd; i++)
+ archive_strappend_char(&mtree->buf, ' ');
+ archive_strncat(&mtree->buf, s, r - s);
+ if (nd + (r -s) > INDENTNAMELEN) {
+ archive_strncat(&mtree->buf, " \\\n", 3);
+ for (i = 0; i < (INDENTNAMELEN + 1 + pd); i++)
+ archive_strappend_char(&mtree->buf, ' ');
+ } else {
+ for (i = (int)(r -s + nd);
+ i < (INDENTNAMELEN + 1); i++)
+ archive_strappend_char(&mtree->buf, ' ');
+ }
+ s = ++r;
+ x = NULL;
+ continue;
+ }
+ if (pd + (r - s) <= MAXLINELEN - 3 - INDENTNAMELEN)
+ x = r++;
+ else {
+ if (x == NULL)
+ x = r;
+ archive_strncat(&mtree->buf, s, x - s);
+ archive_strncat(&mtree->buf, " \\\n", 3);
+ for (i = 0; i < (INDENTNAMELEN + 1 + pd); i++)
+ archive_strappend_char(&mtree->buf, ' ');
+ s = r = ++x;
+ x = NULL;
+ }
+ }
+ if (fn) {
+ for (i = 0; i < nd + pd; i++)
+ archive_strappend_char(&mtree->buf, ' ');
+ archive_strcat(&mtree->buf, s);
+ s += strlen(s);
+ }
+ if (x != NULL && pd + strlen(s) > MAXLINELEN - 3 - INDENTNAMELEN) {
+ /* Last keyword is longer. */
+ archive_strncat(&mtree->buf, s, x - s);
+ archive_strncat(&mtree->buf, " \\\n", 3);
+ for (i = 0; i < (INDENTNAMELEN + 1 + pd); i++)
+ archive_strappend_char(&mtree->buf, ' ');
+ s = ++x;
+ }
+ archive_strcat(&mtree->buf, s);
+ archive_string_empty(&mtree->ebuf);
+}
+
+/*
+ * Write /set keyword.
+ * Set most used value of uid,gid,mode and fflags, which are
+ * collected by attr_counter_set_collect() function.
+ */
+static void
+write_global(struct mtree_writer *mtree)
+{
+ struct archive_string setstr;
+ struct archive_string unsetstr;
+ struct att_counter_set *acs;
+ int keys, oldkeys, effkeys;
+
+ archive_string_init(&setstr);
+ archive_string_init(&unsetstr);
+ keys = mtree->keys & SET_KEYS;
+ oldkeys = mtree->set.keys;
+ effkeys = keys;
+ acs = &mtree->acs;
+ if (mtree->set.processing) {
+ /*
+ * Check if the global data needs updating.
+ */
+ effkeys &= ~F_TYPE;
+ if (acs->uid_list == NULL)
+ effkeys &= ~(F_UNAME | F_UID);
+ else if (oldkeys & (F_UNAME | F_UID)) {
+ if (acs->uid_list->count < 2 ||
+ mtree->set.uid == acs->uid_list->m_entry->uid)
+ effkeys &= ~(F_UNAME | F_UID);
+ }
+ if (acs->gid_list == NULL)
+ effkeys &= ~(F_GNAME | F_GID);
+ else if (oldkeys & (F_GNAME | F_GID)) {
+ if (acs->gid_list->count < 2 ||
+ mtree->set.gid == acs->gid_list->m_entry->gid)
+ effkeys &= ~(F_GNAME | F_GID);
+ }
+ if (acs->mode_list == NULL)
+ effkeys &= ~F_MODE;
+ else if (oldkeys & F_MODE) {
+ if (acs->mode_list->count < 2 ||
+ mtree->set.mode == acs->mode_list->m_entry->mode)
+ effkeys &= ~F_MODE;
+ }
+ if (acs->flags_list == NULL)
+ effkeys &= ~F_FLAGS;
+ else if ((oldkeys & F_FLAGS) != 0) {
+ if (acs->flags_list->count < 2 ||
+ (acs->flags_list->m_entry->fflags_set ==
+ mtree->set.fflags_set &&
+ acs->flags_list->m_entry->fflags_clear ==
+ mtree->set.fflags_clear))
+ effkeys &= ~F_FLAGS;
+ }
+ } else {
+ if (acs->uid_list == NULL)
+ keys &= ~(F_UNAME | F_UID);
+ if (acs->gid_list == NULL)
+ keys &= ~(F_GNAME | F_GID);
+ if (acs->mode_list == NULL)
+ keys &= ~F_MODE;
+ if (acs->flags_list == NULL)
+ keys &= ~F_FLAGS;
+ }
+ if ((keys & effkeys & F_TYPE) != 0) {
+ if (mtree->dironly) {
+ archive_strcat(&setstr, " type=dir");
+ mtree->set.type = AE_IFDIR;
+ } else {
+ archive_strcat(&setstr, " type=file");
+ mtree->set.type = AE_IFREG;
+ }
+ }
+ if ((keys & effkeys & F_UNAME) != 0) {
+ if (archive_strlen(&(acs->uid_list->m_entry->uname)) > 0) {
+ archive_strcat(&setstr, " uname=");
+ mtree_quote(&setstr, acs->uid_list->m_entry->uname.s);
+ } else {
+ keys &= ~F_UNAME;
+ if ((oldkeys & F_UNAME) != 0)
+ archive_strcat(&unsetstr, " uname");
+ }
+ }
+ if ((keys & effkeys & F_UID) != 0) {
+ mtree->set.uid = acs->uid_list->m_entry->uid;
+ archive_string_sprintf(&setstr, " uid=%jd",
+ (intmax_t)mtree->set.uid);
+ }
+ if ((keys & effkeys & F_GNAME) != 0) {
+ if (archive_strlen(&(acs->gid_list->m_entry->gname)) > 0) {
+ archive_strcat(&setstr, " gname=");
+ mtree_quote(&setstr, acs->gid_list->m_entry->gname.s);
+ } else {
+ keys &= ~F_GNAME;
+ if ((oldkeys & F_GNAME) != 0)
+ archive_strcat(&unsetstr, " gname");
+ }
+ }
+ if ((keys & effkeys & F_GID) != 0) {
+ mtree->set.gid = acs->gid_list->m_entry->gid;
+ archive_string_sprintf(&setstr, " gid=%jd",
+ (intmax_t)mtree->set.gid);
+ }
+ if ((keys & effkeys & F_MODE) != 0) {
+ mtree->set.mode = acs->mode_list->m_entry->mode;
+ archive_string_sprintf(&setstr, " mode=%o",
+ (unsigned int)mtree->set.mode);
+ }
+ if ((keys & effkeys & F_FLAGS) != 0) {
+ if (archive_strlen(
+ &(acs->flags_list->m_entry->fflags_text)) > 0) {
+ archive_strcat(&setstr, " flags=");
+ mtree_quote(&setstr,
+ acs->flags_list->m_entry->fflags_text.s);
+ mtree->set.fflags_set =
+ acs->flags_list->m_entry->fflags_set;
+ mtree->set.fflags_clear =
+ acs->flags_list->m_entry->fflags_clear;
+ } else {
+ keys &= ~F_FLAGS;
+ if ((oldkeys & F_FLAGS) != 0)
+ archive_strcat(&unsetstr, " flags");
+ }
+ }
+ if (unsetstr.length > 0)
+ archive_string_sprintf(&mtree->buf, "/unset%s\n", unsetstr.s);
+ archive_string_free(&unsetstr);
+ if (setstr.length > 0)
+ archive_string_sprintf(&mtree->buf, "/set%s\n", setstr.s);
+ archive_string_free(&setstr);
+ mtree->set.keys = keys;
+ mtree->set.processing = 1;
+}
+
+static struct attr_counter *
+attr_counter_new(struct mtree_entry *me, struct attr_counter *prev)
+{
+ struct attr_counter *ac;
+
+ ac = malloc(sizeof(*ac));
+ if (ac != NULL) {
+ ac->prev = prev;
+ ac->next = NULL;
+ ac->count = 1;
+ ac->m_entry = me;
+ }
+ return (ac);
+}
+
+static void
+attr_counter_free(struct attr_counter **top)
+{
+ struct attr_counter *ac, *tac;
+
+ if (*top == NULL)
+ return;
+ ac = *top;
+ while (ac != NULL) {
+ tac = ac->next;
+ free(ac);
+ ac = tac;
+ }
+ *top = NULL;
+}
+
+static int
+attr_counter_inc(struct attr_counter **top, struct attr_counter *ac,
+ struct attr_counter *last, struct mtree_entry *me)
+{
+ struct attr_counter *pac;
+
+ if (ac != NULL) {
+ ac->count++;
+ if (*top == ac || ac->prev->count >= ac->count)
+ return (0);
+ for (pac = ac->prev; pac; pac = pac->prev) {
+ if (pac->count >= ac->count)
+ break;
+ }
+ ac->prev->next = ac->next;
+ if (ac->next != NULL)
+ ac->next->prev = ac->prev;
+ if (pac != NULL) {
+ ac->prev = pac;
+ ac->next = pac->next;
+ pac->next = ac;
+ if (ac->next != NULL)
+ ac->next->prev = ac;
+ } else {
+ ac->prev = NULL;
+ ac->next = *top;
+ *top = ac;
+ ac->next->prev = ac;
+ }
+ } else {
+ ac = attr_counter_new(me, last);
+ if (ac == NULL)
+ return (-1);
+ last->next = ac;
+ }
+ return (0);
+}
+
+/*
+ * Tabulate uid,gid,mode and fflags of a entry in order to be used for /set.
+ */
+static int
+attr_counter_set_collect(struct mtree_writer *mtree, struct mtree_entry *me)
+{
+ struct attr_counter *ac, *last;
+ struct att_counter_set *acs = &mtree->acs;
+ int keys = mtree->keys;
+
+ if (keys & (F_UNAME | F_UID)) {
+ if (acs->uid_list == NULL) {
+ acs->uid_list = attr_counter_new(me, NULL);
+ if (acs->uid_list == NULL)
+ return (-1);
+ } else {
+ last = NULL;
+ for (ac = acs->uid_list; ac; ac = ac->next) {
+ if (ac->m_entry->uid == me->uid)
+ break;
+ last = ac;
+ }
+ if (attr_counter_inc(&acs->uid_list, ac, last, me) < 0)
+ return (-1);
+ }
+ }
+ if (keys & (F_GNAME | F_GID)) {
+ if (acs->gid_list == NULL) {
+ acs->gid_list = attr_counter_new(me, NULL);
+ if (acs->gid_list == NULL)
+ return (-1);
+ } else {
+ last = NULL;
+ for (ac = acs->gid_list; ac; ac = ac->next) {
+ if (ac->m_entry->gid == me->gid)
+ break;
+ last = ac;
+ }
+ if (attr_counter_inc(&acs->gid_list, ac, last, me) < 0)
+ return (-1);
+ }
+ }
+ if (keys & F_MODE) {
+ if (acs->mode_list == NULL) {
+ acs->mode_list = attr_counter_new(me, NULL);
+ if (acs->mode_list == NULL)
+ return (-1);
+ } else {
+ last = NULL;
+ for (ac = acs->mode_list; ac; ac = ac->next) {
+ if (ac->m_entry->mode == me->mode)
+ break;
+ last = ac;
+ }
+ if (attr_counter_inc(&acs->mode_list, ac, last, me) < 0)
+ return (-1);
+ }
+ }
+ if (keys & F_FLAGS) {
+ if (acs->flags_list == NULL) {
+ acs->flags_list = attr_counter_new(me, NULL);
+ if (acs->flags_list == NULL)
+ return (-1);
+ } else {
+ last = NULL;
+ for (ac = acs->flags_list; ac; ac = ac->next) {
+ if (ac->m_entry->fflags_set == me->fflags_set &&
+ ac->m_entry->fflags_clear ==
+ me->fflags_clear)
+ break;
+ last = ac;
+ }
+ if (attr_counter_inc(&acs->flags_list, ac, last, me) < 0)
+ return (-1);
+ }
+ }
+
+ return (0);
+}
+
+static void
+attr_counter_set_free(struct mtree_writer *mtree)
+{
+ struct att_counter_set *acs = &mtree->acs;
+
+ attr_counter_free(&acs->uid_list);
+ attr_counter_free(&acs->gid_list);
+ attr_counter_free(&acs->mode_list);
+ attr_counter_free(&acs->flags_list);
+}
+
+static int
+get_global_set_keys(struct mtree_writer *mtree, struct mtree_entry *me)
+{
+ int keys;
+
+ keys = mtree->keys;
+
+ /*
+ * If a keyword has been set by /set, we do not need to
+ * output it.
+ */
+ if (mtree->set.keys == 0)
+ return (keys);/* /set is not used. */
+
+ if ((mtree->set.keys & (F_GNAME | F_GID)) != 0 &&
+ mtree->set.gid == me->gid)
+ keys &= ~(F_GNAME | F_GID);
+ if ((mtree->set.keys & (F_UNAME | F_UID)) != 0 &&
+ mtree->set.uid == me->uid)
+ keys &= ~(F_UNAME | F_UID);
+ if (mtree->set.keys & F_FLAGS) {
+ if (mtree->set.fflags_set == me->fflags_set &&
+ mtree->set.fflags_clear == me->fflags_clear)
+ keys &= ~F_FLAGS;
+ }
+ if ((mtree->set.keys & F_MODE) != 0 && mtree->set.mode == me->mode)
+ keys &= ~F_MODE;
+
+ switch (me->filetype) {
+ case AE_IFLNK: case AE_IFSOCK: case AE_IFCHR:
+ case AE_IFBLK: case AE_IFIFO:
+ break;
+ case AE_IFDIR:
+ if ((mtree->set.keys & F_TYPE) != 0 &&
+ mtree->set.type == AE_IFDIR)
+ keys &= ~F_TYPE;
+ break;
+ case AE_IFREG:
+ default: /* Handle unknown file types as regular files. */
+ if ((mtree->set.keys & F_TYPE) != 0 &&
+ mtree->set.type == AE_IFREG)
+ keys &= ~F_TYPE;
+ break;
+ }
+
+ return (keys);
+}
+
+static int
+mtree_entry_new(struct archive_write *a, struct archive_entry *entry,
+ struct mtree_entry **m_entry)
+{
+ struct mtree_entry *me;
+ const char *s;
+ int r;
+ static const struct archive_rb_tree_ops rb_ops = {
+ mtree_entry_cmp_node, mtree_entry_cmp_key
+ };
+
+ me = calloc(1, sizeof(*me));
+ if (me == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for a mtree entry");
+ *m_entry = NULL;
+ return (ARCHIVE_FATAL);
+ }
+
+ r = mtree_entry_setup_filenames(a, me, entry);
+ if (r < ARCHIVE_WARN) {
+ mtree_entry_free(me);
+ *m_entry = NULL;
+ return (r);
+ }
+
+ if ((s = archive_entry_symlink(entry)) != NULL)
+ archive_strcpy(&me->symlink, s);
+ me->nlink = archive_entry_nlink(entry);
+ me->filetype = archive_entry_filetype(entry);
+ me->mode = archive_entry_mode(entry) & 07777;
+ me->uid = archive_entry_uid(entry);
+ me->gid = archive_entry_gid(entry);
+ if ((s = archive_entry_uname(entry)) != NULL)
+ archive_strcpy(&me->uname, s);
+ if ((s = archive_entry_gname(entry)) != NULL)
+ archive_strcpy(&me->gname, s);
+ if ((s = archive_entry_fflags_text(entry)) != NULL)
+ archive_strcpy(&me->fflags_text, s);
+ archive_entry_fflags(entry, &me->fflags_set, &me->fflags_clear);
+ me->mtime = archive_entry_mtime(entry);
+ me->mtime_nsec = archive_entry_mtime_nsec(entry);
+ me->rdevmajor = archive_entry_rdevmajor(entry);
+ me->rdevminor = archive_entry_rdevminor(entry);
+ me->devmajor = archive_entry_devmajor(entry);
+ me->devminor = archive_entry_devminor(entry);
+ me->ino = archive_entry_ino(entry);
+ me->size = archive_entry_size(entry);
+ if (me->filetype == AE_IFDIR) {
+ me->dir_info = calloc(1, sizeof(*me->dir_info));
+ if (me->dir_info == NULL) {
+ mtree_entry_free(me);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for a mtree entry");
+ *m_entry = NULL;
+ return (ARCHIVE_FATAL);
+ }
+ __archive_rb_tree_init(&me->dir_info->rbtree, &rb_ops);
+ me->dir_info->children.first = NULL;
+ me->dir_info->children.last = &(me->dir_info->children.first);
+ me->dir_info->chnext = NULL;
+ } else if (me->filetype == AE_IFREG) {
+ me->reg_info = calloc(1, sizeof(*me->reg_info));
+ if (me->reg_info == NULL) {
+ mtree_entry_free(me);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for a mtree entry");
+ *m_entry = NULL;
+ return (ARCHIVE_FATAL);
+ }
+ me->reg_info->compute_sum = 0;
+ }
+
+ *m_entry = me;
+ return (ARCHIVE_OK);
+}
+
+static void
+mtree_entry_free(struct mtree_entry *me)
+{
+ archive_string_free(&me->parentdir);
+ archive_string_free(&me->basename);
+ archive_string_free(&me->pathname);
+ archive_string_free(&me->symlink);
+ archive_string_free(&me->uname);
+ archive_string_free(&me->gname);
+ archive_string_free(&me->fflags_text);
+ free(me->dir_info);
+ free(me->reg_info);
+ free(me);
+}
+
+static int
+archive_write_mtree_header(struct archive_write *a,
+ struct archive_entry *entry)
+{
+ struct mtree_writer *mtree= a->format_data;
+ struct mtree_entry *mtree_entry;
+ int r, r2;
+
+ if (mtree->first) {
+ mtree->first = 0;
+ archive_strcat(&mtree->buf, "#mtree\n");
+ if ((mtree->keys & SET_KEYS) == 0)
+ mtree->output_global_set = 0;/* Disabled. */
+ }
+
+ mtree->entry_bytes_remaining = archive_entry_size(entry);
+
+ /* While directory only mode, we do not handle non directory files. */
+ if (mtree->dironly && archive_entry_filetype(entry) != AE_IFDIR)
+ return (ARCHIVE_OK);
+
+ r2 = mtree_entry_new(a, entry, &mtree_entry);
+ if (r2 < ARCHIVE_WARN)
+ return (r2);
+ r = mtree_entry_tree_add(a, &mtree_entry);
+ if (r < ARCHIVE_WARN) {
+ mtree_entry_free(mtree_entry);
+ return (r);
+ }
+ mtree->mtree_entry = mtree_entry;
+
+ /* If the current file is a regular file, we have to
+ * compute the sum of its content.
+ * Initialize a bunch of sum check context. */
+ if (mtree_entry->reg_info)
+ sum_init(mtree);
+
+ return (r2);
+}
+
+static int
+write_mtree_entry(struct archive_write *a, struct mtree_entry *me)
+{
+ struct mtree_writer *mtree = a->format_data;
+ struct archive_string *str;
+ int keys, ret;
+
+ if (me->dir_info) {
+ if (mtree->classic) {
+ /*
+ * Output a comment line to describe the full
+ * pathname of the entry as mtree utility does
+ * while generating classic format.
+ */
+ if (!mtree->dironly)
+ archive_strappend_char(&mtree->buf, '\n');
+ if (me->parentdir.s)
+ archive_string_sprintf(&mtree->buf,
+ "# %s/%s\n",
+ me->parentdir.s, me->basename.s);
+ else
+ archive_string_sprintf(&mtree->buf,
+ "# %s\n",
+ me->basename.s);
+ }
+ if (mtree->output_global_set)
+ write_global(mtree);
+ }
+ archive_string_empty(&mtree->ebuf);
+ str = (mtree->indent || mtree->classic)? &mtree->ebuf : &mtree->buf;
+
+ if (!mtree->classic && me->parentdir.s) {
+ /*
+ * If generating format is not classic one(v1), output
+ * a full pathname.
+ */
+ mtree_quote(str, me->parentdir.s);
+ archive_strappend_char(str, '/');
+ }
+ mtree_quote(str, me->basename.s);
+
+ keys = get_global_set_keys(mtree, me);
+ if ((keys & F_NLINK) != 0 &&
+ me->nlink != 1 && me->filetype != AE_IFDIR)
+ archive_string_sprintf(str, " nlink=%u", me->nlink);
+
+ if ((keys & F_GNAME) != 0 && archive_strlen(&me->gname) > 0) {
+ archive_strcat(str, " gname=");
+ mtree_quote(str, me->gname.s);
+ }
+ if ((keys & F_UNAME) != 0 && archive_strlen(&me->uname) > 0) {
+ archive_strcat(str, " uname=");
+ mtree_quote(str, me->uname.s);
+ }
+ if ((keys & F_FLAGS) != 0) {
+ if (archive_strlen(&me->fflags_text) > 0) {
+ archive_strcat(str, " flags=");
+ mtree_quote(str, me->fflags_text.s);
+ } else if (mtree->set.processing &&
+ (mtree->set.keys & F_FLAGS) != 0)
+ /* Overwrite the global parameter. */
+ archive_strcat(str, " flags=none");
+ }
+ if ((keys & F_TIME) != 0)
+ archive_string_sprintf(str, " time=%jd.%jd",
+ (intmax_t)me->mtime, (intmax_t)me->mtime_nsec);
+ if ((keys & F_MODE) != 0)
+ archive_string_sprintf(str, " mode=%o", (unsigned int)me->mode);
+ if ((keys & F_GID) != 0)
+ archive_string_sprintf(str, " gid=%jd", (intmax_t)me->gid);
+ if ((keys & F_UID) != 0)
+ archive_string_sprintf(str, " uid=%jd", (intmax_t)me->uid);
+
+ if ((keys & F_INO) != 0)
+ archive_string_sprintf(str, " inode=%jd", (intmax_t)me->ino);
+ if ((keys & F_RESDEV) != 0) {
+ archive_string_sprintf(str,
+ " resdevice=native,%ju,%ju",
+ (uintmax_t)me->devmajor,
+ (uintmax_t)me->devminor);
+ }
+
+ switch (me->filetype) {
+ case AE_IFLNK:
+ if ((keys & F_TYPE) != 0)
+ archive_strcat(str, " type=link");
+ if ((keys & F_SLINK) != 0) {
+ archive_strcat(str, " link=");
+ mtree_quote(str, me->symlink.s);
+ }
+ break;
+ case AE_IFSOCK:
+ if ((keys & F_TYPE) != 0)
+ archive_strcat(str, " type=socket");
+ break;
+ case AE_IFCHR:
+ if ((keys & F_TYPE) != 0)
+ archive_strcat(str, " type=char");
+ if ((keys & F_DEV) != 0) {
+ archive_string_sprintf(str,
+ " device=native,%ju,%ju",
+ (uintmax_t)me->rdevmajor,
+ (uintmax_t)me->rdevminor);
+ }
+ break;
+ case AE_IFBLK:
+ if ((keys & F_TYPE) != 0)
+ archive_strcat(str, " type=block");
+ if ((keys & F_DEV) != 0) {
+ archive_string_sprintf(str,
+ " device=native,%ju,%ju",
+ (uintmax_t)me->rdevmajor,
+ (uintmax_t)me->rdevminor);
+ }
+ break;
+ case AE_IFDIR:
+ if ((keys & F_TYPE) != 0)
+ archive_strcat(str, " type=dir");
+ break;
+ case AE_IFIFO:
+ if ((keys & F_TYPE) != 0)
+ archive_strcat(str, " type=fifo");
+ break;
+ case AE_IFREG:
+ default: /* Handle unknown file types as regular files. */
+ if ((keys & F_TYPE) != 0)
+ archive_strcat(str, " type=file");
+ if ((keys & F_SIZE) != 0)
+ archive_string_sprintf(str, " size=%jd",
+ (intmax_t)me->size);
+ break;
+ }
+
+ /* Write a bunch of sum. */
+ if (me->reg_info)
+ sum_write(str, me->reg_info);
+
+ archive_strappend_char(str, '\n');
+ if (mtree->indent || mtree->classic)
+ mtree_indent(mtree);
+
+ if (mtree->buf.length > 32768) {
+ ret = __archive_write_output(
+ a, mtree->buf.s, mtree->buf.length);
+ archive_string_empty(&mtree->buf);
+ } else
+ ret = ARCHIVE_OK;
+ return (ret);
+}
+
+static int
+write_dot_dot_entry(struct archive_write *a, struct mtree_entry *n)
+{
+ struct mtree_writer *mtree = a->format_data;
+ int ret;
+
+ if (n->parentdir.s) {
+ if (mtree->indent) {
+ int i, pd = mtree->depth * 4;
+ for (i = 0; i < pd; i++)
+ archive_strappend_char(&mtree->buf, ' ');
+ }
+ archive_string_sprintf(&mtree->buf, "# %s/%s\n",
+ n->parentdir.s, n->basename.s);
+ }
+
+ if (mtree->indent) {
+ archive_string_empty(&mtree->ebuf);
+ archive_strncat(&mtree->ebuf, "..\n\n", (mtree->dironly)?3:4);
+ mtree_indent(mtree);
+ } else
+ archive_strncat(&mtree->buf, "..\n\n", (mtree->dironly)?3:4);
+
+ if (mtree->buf.length > 32768) {
+ ret = __archive_write_output(
+ a, mtree->buf.s, mtree->buf.length);
+ archive_string_empty(&mtree->buf);
+ } else
+ ret = ARCHIVE_OK;
+ return (ret);
+}
+
+/*
+ * Write mtree entries saved at attr_counter_set_collect() function.
+ */
+static int
+write_mtree_entry_tree(struct archive_write *a)
+{
+ struct mtree_writer *mtree = a->format_data;
+ struct mtree_entry *np = mtree->root;
+ struct archive_rb_node *n;
+ int ret;
+
+ do {
+ if (mtree->output_global_set) {
+ /*
+ * Collect attribute information to know which value
+ * is frequently used among the children.
+ */
+ attr_counter_set_reset(mtree);
+ ARCHIVE_RB_TREE_FOREACH(n, &(np->dir_info->rbtree)) {
+ struct mtree_entry *e = (struct mtree_entry *)n;
+ if (attr_counter_set_collect(mtree, e) < 0) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ }
+ if (!np->dir_info->virtual || mtree->classic) {
+ ret = write_mtree_entry(a, np);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } else {
+ /* Whenever output_global_set is enabled
+ * output global value(/set keywords)
+ * even if the directory entry is not allowed
+ * to be written because the global values
+ * can be used for the children. */
+ if (mtree->output_global_set)
+ write_global(mtree);
+ }
+ /*
+ * Output the attribute of all files except directory files.
+ */
+ mtree->depth++;
+ ARCHIVE_RB_TREE_FOREACH(n, &(np->dir_info->rbtree)) {
+ struct mtree_entry *e = (struct mtree_entry *)n;
+
+ if (e->dir_info)
+ mtree_entry_add_child_tail(np, e);
+ else {
+ ret = write_mtree_entry(a, e);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ }
+ mtree->depth--;
+
+ if (np->dir_info->children.first != NULL) {
+ /*
+ * Descend the tree.
+ */
+ np = np->dir_info->children.first;
+ if (mtree->indent)
+ mtree->depth++;
+ continue;
+ } else if (mtree->classic) {
+ /*
+ * While printing mtree classic, if there are not
+ * any directory files(except "." and "..") in the
+ * directory, output two dots ".." as returning
+ * the parent directory.
+ */
+ ret = write_dot_dot_entry(a, np);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ while (np != np->parent) {
+ if (np->dir_info->chnext == NULL) {
+ /*
+ * Ascend the tree; go back to the parent.
+ */
+ if (mtree->indent)
+ mtree->depth--;
+ if (mtree->classic) {
+ ret = write_dot_dot_entry(a,
+ np->parent);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ np = np->parent;
+ } else {
+ /*
+ * Switch to next mtree entry in the directory.
+ */
+ np = np->dir_info->chnext;
+ break;
+ }
+ }
+ } while (np != np->parent);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_mtree_finish_entry(struct archive_write *a)
+{
+ struct mtree_writer *mtree = a->format_data;
+ struct mtree_entry *me;
+
+ if ((me = mtree->mtree_entry) == NULL)
+ return (ARCHIVE_OK);
+ mtree->mtree_entry = NULL;
+
+ if (me->reg_info)
+ sum_final(mtree, me->reg_info);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_mtree_close(struct archive_write *a)
+{
+ struct mtree_writer *mtree= a->format_data;
+ int ret;
+
+ if (mtree->root != NULL) {
+ ret = write_mtree_entry_tree(a);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ archive_write_set_bytes_in_last_block(&a->archive, 1);
+
+ return __archive_write_output(a, mtree->buf.s, mtree->buf.length);
+}
+
+static ssize_t
+archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n)
+{
+ struct mtree_writer *mtree= a->format_data;
+
+ if (n > mtree->entry_bytes_remaining)
+ n = (size_t)mtree->entry_bytes_remaining;
+ mtree->entry_bytes_remaining -= n;
+
+ /* We don't need to compute a regular file sum */
+ if (mtree->mtree_entry == NULL)
+ return (n);
+
+ if (mtree->mtree_entry->filetype == AE_IFREG)
+ sum_update(mtree, buff, n);
+
+ return (n);
+}
+
+static int
+archive_write_mtree_free(struct archive_write *a)
+{
+ struct mtree_writer *mtree= a->format_data;
+
+ if (mtree == NULL)
+ return (ARCHIVE_OK);
+
+ /* Make sure we dot not leave any entries. */
+ mtree_entry_register_free(mtree);
+ archive_string_free(&mtree->cur_dirstr);
+ archive_string_free(&mtree->ebuf);
+ archive_string_free(&mtree->buf);
+ attr_counter_set_free(mtree);
+ free(mtree);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_mtree_options(struct archive_write *a, const char *key,
+ const char *value)
+{
+ struct mtree_writer *mtree= a->format_data;
+ int keybit = 0;
+
+ switch (key[0]) {
+ case 'a':
+ if (strcmp(key, "all") == 0)
+ keybit = ~0;
+ break;
+ case 'c':
+ if (strcmp(key, "cksum") == 0)
+ keybit = F_CKSUM;
+ break;
+ case 'd':
+ if (strcmp(key, "device") == 0)
+ keybit = F_DEV;
+ else if (strcmp(key, "dironly") == 0) {
+ mtree->dironly = (value != NULL)? 1: 0;
+ return (ARCHIVE_OK);
+ }
+ break;
+ case 'f':
+ if (strcmp(key, "flags") == 0)
+ keybit = F_FLAGS;
+ break;
+ case 'g':
+ if (strcmp(key, "gid") == 0)
+ keybit = F_GID;
+ else if (strcmp(key, "gname") == 0)
+ keybit = F_GNAME;
+ break;
+ case 'i':
+ if (strcmp(key, "indent") == 0) {
+ mtree->indent = (value != NULL)? 1: 0;
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "inode") == 0) {
+ keybit = F_INO;
+ }
+ break;
+ case 'l':
+ if (strcmp(key, "link") == 0)
+ keybit = F_SLINK;
+ break;
+ case 'm':
+ if (strcmp(key, "md5") == 0 ||
+ strcmp(key, "md5digest") == 0)
+ keybit = F_MD5;
+ if (strcmp(key, "mode") == 0)
+ keybit = F_MODE;
+ break;
+ case 'n':
+ if (strcmp(key, "nlink") == 0)
+ keybit = F_NLINK;
+ break;
+ case 'r':
+ if (strcmp(key, "resdevice") == 0) {
+ keybit = F_RESDEV;
+ } else if (strcmp(key, "ripemd160digest") == 0 ||
+ strcmp(key, "rmd160") == 0 ||
+ strcmp(key, "rmd160digest") == 0)
+ keybit = F_RMD160;
+ break;
+ case 's':
+ if (strcmp(key, "sha1") == 0 ||
+ strcmp(key, "sha1digest") == 0)
+ keybit = F_SHA1;
+ if (strcmp(key, "sha256") == 0 ||
+ strcmp(key, "sha256digest") == 0)
+ keybit = F_SHA256;
+ if (strcmp(key, "sha384") == 0 ||
+ strcmp(key, "sha384digest") == 0)
+ keybit = F_SHA384;
+ if (strcmp(key, "sha512") == 0 ||
+ strcmp(key, "sha512digest") == 0)
+ keybit = F_SHA512;
+ if (strcmp(key, "size") == 0)
+ keybit = F_SIZE;
+ break;
+ case 't':
+ if (strcmp(key, "time") == 0)
+ keybit = F_TIME;
+ else if (strcmp(key, "type") == 0)
+ keybit = F_TYPE;
+ break;
+ case 'u':
+ if (strcmp(key, "uid") == 0)
+ keybit = F_UID;
+ else if (strcmp(key, "uname") == 0)
+ keybit = F_UNAME;
+ else if (strcmp(key, "use-set") == 0) {
+ mtree->output_global_set = (value != NULL)? 1: 0;
+ return (ARCHIVE_OK);
+ }
+ break;
+ }
+ if (keybit != 0) {
+ if (value != NULL)
+ mtree->keys |= keybit;
+ else
+ mtree->keys &= ~keybit;
+ 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
+archive_write_set_format_mtree_default(struct archive *_a, const char *fn)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct mtree_writer *mtree;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, fn);
+
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ if ((mtree = calloc(1, sizeof(*mtree))) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate mtree data");
+ return (ARCHIVE_FATAL);
+ }
+
+ mtree->mtree_entry = NULL;
+ mtree->first = 1;
+ memset(&(mtree->set), 0, sizeof(mtree->set));
+ mtree->keys = DEFAULT_KEYS;
+ mtree->dironly = 0;
+ mtree->indent = 0;
+ archive_string_init(&mtree->ebuf);
+ archive_string_init(&mtree->buf);
+ mtree_entry_register_init(mtree);
+ a->format_data = mtree;
+ a->format_free = archive_write_mtree_free;
+ a->format_name = "mtree";
+ a->format_options = archive_write_mtree_options;
+ a->format_write_header = archive_write_mtree_header;
+ a->format_close = archive_write_mtree_close;
+ a->format_write_data = archive_write_mtree_data;
+ a->format_finish_entry = archive_write_mtree_finish_entry;
+ a->archive.archive_format = ARCHIVE_FORMAT_MTREE;
+ a->archive.archive_format_name = "mtree";
+
+ return (ARCHIVE_OK);
+}
+
+int
+archive_write_set_format_mtree(struct archive *_a)
+{
+ return archive_write_set_format_mtree_default(_a,
+ "archive_write_set_format_mtree");
+}
+
+int
+archive_write_set_format_mtree_classic(struct archive *_a)
+{
+ int r;
+
+ r = archive_write_set_format_mtree_default(_a,
+ "archive_write_set_format_mtree_classic");
+ if (r == ARCHIVE_OK) {
+ struct archive_write *a = (struct archive_write *)_a;
+ struct mtree_writer *mtree;
+
+ mtree = (struct mtree_writer *)a->format_data;
+
+ /* Set to output a mtree archive in classic format. */
+ mtree->classic = 1;
+ /* Basically, mtree classic format uses '/set' global
+ * value. */
+ mtree->output_global_set = 1;
+ }
+ return (r);
+}
+
+static void
+sum_init(struct mtree_writer *mtree)
+{
+
+ mtree->compute_sum = 0;
+
+ if (mtree->keys & F_CKSUM) {
+ mtree->compute_sum |= F_CKSUM;
+ mtree->crc = 0;
+ mtree->crc_len = 0;
+ }
+#ifdef ARCHIVE_HAS_MD5
+ if (mtree->keys & F_MD5) {
+ if (archive_md5_init(&mtree->md5ctx) == ARCHIVE_OK)
+ mtree->compute_sum |= F_MD5;
+ else
+ mtree->keys &= ~F_MD5;/* Not supported. */
+ }
+#endif
+#ifdef ARCHIVE_HAS_RMD160
+ if (mtree->keys & F_RMD160) {
+ if (archive_rmd160_init(&mtree->rmd160ctx) == ARCHIVE_OK)
+ mtree->compute_sum |= F_RMD160;
+ else
+ mtree->keys &= ~F_RMD160;/* Not supported. */
+ }
+#endif
+#ifdef ARCHIVE_HAS_SHA1
+ if (mtree->keys & F_SHA1) {
+ if (archive_sha1_init(&mtree->sha1ctx) == ARCHIVE_OK)
+ mtree->compute_sum |= F_SHA1;
+ else
+ mtree->keys &= ~F_SHA1;/* Not supported. */
+ }
+#endif
+#ifdef ARCHIVE_HAS_SHA256
+ if (mtree->keys & F_SHA256) {
+ if (archive_sha256_init(&mtree->sha256ctx) == ARCHIVE_OK)
+ mtree->compute_sum |= F_SHA256;
+ else
+ mtree->keys &= ~F_SHA256;/* Not supported. */
+ }
+#endif
+#ifdef ARCHIVE_HAS_SHA384
+ if (mtree->keys & F_SHA384) {
+ if (archive_sha384_init(&mtree->sha384ctx) == ARCHIVE_OK)
+ mtree->compute_sum |= F_SHA384;
+ else
+ mtree->keys &= ~F_SHA384;/* Not supported. */
+ }
+#endif
+#ifdef ARCHIVE_HAS_SHA512
+ if (mtree->keys & F_SHA512) {
+ if (archive_sha512_init(&mtree->sha512ctx) == ARCHIVE_OK)
+ mtree->compute_sum |= F_SHA512;
+ else
+ mtree->keys &= ~F_SHA512;/* Not supported. */
+ }
+#endif
+}
+
+static void
+sum_update(struct mtree_writer *mtree, const void *buff, size_t n)
+{
+ if (mtree->compute_sum & F_CKSUM) {
+ /*
+ * Compute a POSIX 1003.2 checksum
+ */
+ const unsigned char *p;
+ size_t nn;
+
+ for (nn = n, p = buff; nn--; ++p)
+ COMPUTE_CRC(mtree->crc, *p);
+ mtree->crc_len += n;
+ }
+#ifdef ARCHIVE_HAS_MD5
+ if (mtree->compute_sum & F_MD5)
+ archive_md5_update(&mtree->md5ctx, buff, n);
+#endif
+#ifdef ARCHIVE_HAS_RMD160
+ if (mtree->compute_sum & F_RMD160)
+ archive_rmd160_update(&mtree->rmd160ctx, buff, n);
+#endif
+#ifdef ARCHIVE_HAS_SHA1
+ if (mtree->compute_sum & F_SHA1)
+ archive_sha1_update(&mtree->sha1ctx, buff, n);
+#endif
+#ifdef ARCHIVE_HAS_SHA256
+ if (mtree->compute_sum & F_SHA256)
+ archive_sha256_update(&mtree->sha256ctx, buff, n);
+#endif
+#ifdef ARCHIVE_HAS_SHA384
+ if (mtree->compute_sum & F_SHA384)
+ archive_sha384_update(&mtree->sha384ctx, buff, n);
+#endif
+#ifdef ARCHIVE_HAS_SHA512
+ if (mtree->compute_sum & F_SHA512)
+ archive_sha512_update(&mtree->sha512ctx, buff, n);
+#endif
+}
+
+static void
+sum_final(struct mtree_writer *mtree, struct reg_info *reg)
+{
+
+ if (mtree->compute_sum & F_CKSUM) {
+ uint64_t len;
+ /* Include the length of the file. */
+ for (len = mtree->crc_len; len != 0; len >>= 8)
+ COMPUTE_CRC(mtree->crc, len & 0xff);
+ reg->crc = ~mtree->crc;
+ }
+#ifdef ARCHIVE_HAS_MD5
+ if (mtree->compute_sum & F_MD5)
+ archive_md5_final(&mtree->md5ctx, reg->buf_md5);
+#endif
+#ifdef ARCHIVE_HAS_RMD160
+ if (mtree->compute_sum & F_RMD160)
+ archive_rmd160_final(&mtree->rmd160ctx, reg->buf_rmd160);
+#endif
+#ifdef ARCHIVE_HAS_SHA1
+ if (mtree->compute_sum & F_SHA1)
+ archive_sha1_final(&mtree->sha1ctx, reg->buf_sha1);
+#endif
+#ifdef ARCHIVE_HAS_SHA256
+ if (mtree->compute_sum & F_SHA256)
+ archive_sha256_final(&mtree->sha256ctx, reg->buf_sha256);
+#endif
+#ifdef ARCHIVE_HAS_SHA384
+ if (mtree->compute_sum & F_SHA384)
+ archive_sha384_final(&mtree->sha384ctx, reg->buf_sha384);
+#endif
+#ifdef ARCHIVE_HAS_SHA512
+ if (mtree->compute_sum & F_SHA512)
+ archive_sha512_final(&mtree->sha512ctx, reg->buf_sha512);
+#endif
+ /* Save what types of sum are computed. */
+ reg->compute_sum = mtree->compute_sum;
+}
+
+#if defined(ARCHIVE_HAS_MD5) || defined(ARCHIVE_HAS_RMD160) || \
+ defined(ARCHIVE_HAS_SHA1) || defined(ARCHIVE_HAS_SHA256) || \
+ defined(ARCHIVE_HAS_SHA384) || defined(ARCHIVE_HAS_SHA512)
+static void
+strappend_bin(struct archive_string *s, const unsigned char *bin, int n)
+{
+ static const char hex[] = "0123456789abcdef";
+ int i;
+
+ for (i = 0; i < n; i++) {
+ archive_strappend_char(s, hex[bin[i] >> 4]);
+ archive_strappend_char(s, hex[bin[i] & 0x0f]);
+ }
+}
+#endif
+
+static void
+sum_write(struct archive_string *str, struct reg_info *reg)
+{
+
+ if (reg->compute_sum & F_CKSUM) {
+ archive_string_sprintf(str, " cksum=%ju",
+ (uintmax_t)reg->crc);
+ }
+#ifdef ARCHIVE_HAS_MD5
+ if (reg->compute_sum & F_MD5) {
+ archive_strcat(str, " md5digest=");
+ strappend_bin(str, reg->buf_md5, sizeof(reg->buf_md5));
+ }
+#endif
+#ifdef ARCHIVE_HAS_RMD160
+ if (reg->compute_sum & F_RMD160) {
+ archive_strcat(str, " rmd160digest=");
+ strappend_bin(str, reg->buf_rmd160, sizeof(reg->buf_rmd160));
+ }
+#endif
+#ifdef ARCHIVE_HAS_SHA1
+ if (reg->compute_sum & F_SHA1) {
+ archive_strcat(str, " sha1digest=");
+ strappend_bin(str, reg->buf_sha1, sizeof(reg->buf_sha1));
+ }
+#endif
+#ifdef ARCHIVE_HAS_SHA256
+ if (reg->compute_sum & F_SHA256) {
+ archive_strcat(str, " sha256digest=");
+ strappend_bin(str, reg->buf_sha256, sizeof(reg->buf_sha256));
+ }
+#endif
+#ifdef ARCHIVE_HAS_SHA384
+ if (reg->compute_sum & F_SHA384) {
+ archive_strcat(str, " sha384digest=");
+ strappend_bin(str, reg->buf_sha384, sizeof(reg->buf_sha384));
+ }
+#endif
+#ifdef ARCHIVE_HAS_SHA512
+ if (reg->compute_sum & F_SHA512) {
+ archive_strcat(str, " sha512digest=");
+ strappend_bin(str, reg->buf_sha512, sizeof(reg->buf_sha512));
+ }
+#endif
+}
+
+static int
+mtree_entry_cmp_node(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ const struct mtree_entry *e1 = (const struct mtree_entry *)n1;
+ const struct mtree_entry *e2 = (const struct mtree_entry *)n2;
+
+ return (strcmp(e2->basename.s, e1->basename.s));
+}
+
+static int
+mtree_entry_cmp_key(const struct archive_rb_node *n, const void *key)
+{
+ const struct mtree_entry *e = (const struct mtree_entry *)n;
+
+ return (strcmp((const char *)key, e->basename.s));
+}
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+static int
+cleanup_backslash_1(char *p)
+{
+ int mb, dos;
+
+ mb = dos = 0;
+ while (*p) {
+ if (*(unsigned char *)p > 127)
+ mb = 1;
+ if (*p == '\\') {
+ /* If we have not met any multi-byte characters,
+ * we can replace '\' with '/'. */
+ if (!mb)
+ *p = '/';
+ dos = 1;
+ }
+ p++;
+ }
+ if (!mb || !dos)
+ return (0);
+ return (-1);
+}
+
+static void
+cleanup_backslash_2(wchar_t *p)
+{
+
+ /* Convert a path-separator from '\' to '/' */
+ while (*p != L'\0') {
+ if (*p == L'\\')
+ *p = L'/';
+ p++;
+ }
+}
+#endif
+
+/*
+ * Generate a parent directory name and a base name from a pathname.
+ */
+static int
+mtree_entry_setup_filenames(struct archive_write *a, struct mtree_entry *file,
+ struct archive_entry *entry)
+{
+ const char *pathname;
+ char *p, *dirname, *slash;
+ size_t len;
+ int ret = ARCHIVE_OK;
+
+ archive_strcpy(&file->pathname, archive_entry_pathname(entry));
+#if defined(_WIN32) || defined(__CYGWIN__)
+ /*
+ * Convert a path-separator from '\' to '/'
+ */
+ if (cleanup_backslash_1(file->pathname.s) != 0) {
+ const wchar_t *wp = archive_entry_pathname_w(entry);
+ struct archive_wstring ws;
+
+ if (wp != NULL) {
+ int r;
+ archive_string_init(&ws);
+ archive_wstrcpy(&ws, wp);
+ cleanup_backslash_2(ws.s);
+ archive_string_empty(&(file->pathname));
+ r = archive_string_append_from_wcs(&(file->pathname),
+ ws.s, ws.length);
+ archive_wstring_free(&ws);
+ if (r < 0 && errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ }
+ }
+#else
+ (void)a; /* UNUSED */
+#endif
+ pathname = file->pathname.s;
+ if (strcmp(pathname, ".") == 0) {
+ archive_strcpy(&file->basename, ".");
+ return (ARCHIVE_OK);
+ }
+
+ archive_strcpy(&(file->parentdir), pathname);
+
+ len = file->parentdir.length;
+ p = dirname = file->parentdir.s;
+
+ /*
+ * Remove leading '/' and '../' elements
+ */
+ while (*p) {
+ if (p[0] == '/') {
+ p++;
+ len--;
+ } else if (p[0] != '.')
+ break;
+ else if (p[1] == '.' && p[2] == '/') {
+ p += 3;
+ len -= 3;
+ } else
+ break;
+ }
+ if (p != dirname) {
+ memmove(dirname, p, len+1);
+ p = dirname;
+ }
+ /*
+ * Remove "/","/." and "/.." elements from tail.
+ */
+ while (len > 0) {
+ size_t ll = len;
+
+ if (len > 0 && p[len-1] == '/') {
+ p[len-1] = '\0';
+ len--;
+ }
+ if (len > 1 && p[len-2] == '/' && p[len-1] == '.') {
+ p[len-2] = '\0';
+ len -= 2;
+ }
+ if (len > 2 && p[len-3] == '/' && p[len-2] == '.' &&
+ p[len-1] == '.') {
+ p[len-3] = '\0';
+ len -= 3;
+ }
+ if (ll == len)
+ break;
+ }
+ while (*p) {
+ if (p[0] == '/') {
+ if (p[1] == '/')
+ /* Convert '//' --> '/' */
+ strcpy(p, p+1);
+ else if (p[1] == '.' && p[2] == '/')
+ /* Convert '/./' --> '/' */
+ strcpy(p, p+2);
+ else if (p[1] == '.' && p[2] == '.' && p[3] == '/') {
+ /* Convert 'dir/dir1/../dir2/'
+ * --> 'dir/dir2/'
+ */
+ char *rp = p -1;
+ while (rp >= dirname) {
+ if (*rp == '/')
+ break;
+ --rp;
+ }
+ if (rp > dirname) {
+ strcpy(rp, p+3);
+ p = rp;
+ } else {
+ strcpy(dirname, p+4);
+ p = dirname;
+ }
+ } else
+ p++;
+ } else
+ p++;
+ }
+ p = dirname;
+ len = strlen(p);
+
+ /*
+ * Add "./" prefiex.
+ * NOTE: If the pathname does not have a path separator, we have
+ * to add "./" to the head of the pathename because mtree reader
+ * will suppose that it is v1(a.k.a classic) mtree format and
+ * change the directory unexpectedly and so it will make a wrong
+ * path.
+ */
+ if (strcmp(p, ".") != 0 && strncmp(p, "./", 2) != 0) {
+ struct archive_string as;
+ archive_string_init(&as);
+ archive_strcpy(&as, "./");
+ archive_strncat(&as, p, len);
+ archive_string_empty(&file->parentdir);
+ archive_string_concat(&file->parentdir, &as);
+ archive_string_free(&as);
+ p = file->parentdir.s;
+ len = archive_strlen(&file->parentdir);
+ }
+
+ /*
+ * Find out the position which points the last position of
+ * path separator('/').
+ */
+ slash = NULL;
+ for (; *p != '\0'; p++) {
+ if (*p == '/')
+ slash = p;
+ }
+ if (slash == NULL) {
+ /* The pathname doesn't have a parent directory. */
+ file->parentdir.length = len;
+ archive_string_copy(&(file->basename), &(file->parentdir));
+ archive_string_empty(&(file->parentdir));
+ *file->parentdir.s = '\0';
+ return (ret);
+ }
+
+ /* Make a basename from file->parentdir.s and slash */
+ *slash = '\0';
+ file->parentdir.length = slash - file->parentdir.s;
+ archive_strcpy(&(file->basename), slash + 1);
+ return (ret);
+}
+
+static int
+mtree_entry_create_virtual_dir(struct archive_write *a, const char *pathname,
+ struct mtree_entry **m_entry)
+{
+ struct archive_entry *entry;
+ struct mtree_entry *file;
+ int r;
+
+ entry = archive_entry_new();
+ if (entry == NULL) {
+ *m_entry = NULL;
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ archive_entry_copy_pathname(entry, pathname);
+ archive_entry_set_mode(entry, AE_IFDIR | 0755);
+ archive_entry_set_mtime(entry, time(NULL), 0);
+
+ r = mtree_entry_new(a, entry, &file);
+ archive_entry_free(entry);
+ if (r < ARCHIVE_WARN) {
+ *m_entry = NULL;
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ file->dir_info->virtual = 1;
+
+ *m_entry = file;
+ return (ARCHIVE_OK);
+}
+
+static void
+mtree_entry_register_add(struct mtree_writer *mtree, struct mtree_entry *file)
+{
+ file->next = NULL;
+ *mtree->file_list.last = file;
+ mtree->file_list.last = &(file->next);
+}
+
+static void
+mtree_entry_register_init(struct mtree_writer *mtree)
+{
+ mtree->file_list.first = NULL;
+ mtree->file_list.last = &(mtree->file_list.first);
+}
+
+static void
+mtree_entry_register_free(struct mtree_writer *mtree)
+{
+ struct mtree_entry *file, *file_next;
+
+ file = mtree->file_list.first;
+ while (file != NULL) {
+ file_next = file->next;
+ mtree_entry_free(file);
+ file = file_next;
+ }
+}
+
+static int
+mtree_entry_add_child_tail(struct mtree_entry *parent,
+ struct mtree_entry *child)
+{
+ child->dir_info->chnext = NULL;
+ *parent->dir_info->children.last = child;
+ parent->dir_info->children.last = &(child->dir_info->chnext);
+ return (1);
+}
+
+/*
+ * Find a entry from a parent entry with the name.
+ */
+static struct mtree_entry *
+mtree_entry_find_child(struct mtree_entry *parent, const char *child_name)
+{
+ struct mtree_entry *np;
+
+ if (parent == NULL)
+ return (NULL);
+ np = (struct mtree_entry *)__archive_rb_tree_find_node(
+ &(parent->dir_info->rbtree), child_name);
+ return (np);
+}
+
+static int
+get_path_component(char *name, size_t n, const char *fn)
+{
+ char *p;
+ size_t l;
+
+ p = strchr(fn, '/');
+ if (p == NULL) {
+ if ((l = strlen(fn)) == 0)
+ return (0);
+ } else
+ l = p - fn;
+ if (l > n -1)
+ return (-1);
+ memcpy(name, fn, l);
+ name[l] = '\0';
+
+ return ((int)l);
+}
+
+/*
+ * Add a new entry into the tree.
+ */
+static int
+mtree_entry_tree_add(struct archive_write *a, struct mtree_entry **filep)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ char name[_MAX_FNAME];/* Included null terminator size. */
+#elif defined(NAME_MAX) && NAME_MAX >= 255
+ char name[NAME_MAX+1];
+#else
+ char name[256];
+#endif
+ struct mtree_writer *mtree = (struct mtree_writer *)a->format_data;
+ struct mtree_entry *dent, *file, *np;
+ const char *fn, *p;
+ int l, r;
+
+ file = *filep;
+ if (file->parentdir.length == 0 && file->basename.length == 1 &&
+ file->basename.s[0] == '.') {
+ file->parent = file;
+ if (mtree->root != NULL) {
+ np = mtree->root;
+ goto same_entry;
+ }
+ mtree->root = file;
+ mtree_entry_register_add(mtree, file);
+ return (ARCHIVE_OK);
+ }
+
+ if (file->parentdir.length == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Internal programing error "
+ "in generating canonical name for %s",
+ file->pathname.s);
+ return (ARCHIVE_FAILED);
+ }
+
+ fn = p = file->parentdir.s;
+
+ /*
+ * If the path of the parent directory of `file' entry is
+ * the same as the path of `cur_dirent', add `file' entry to
+ * `cur_dirent'.
+ */
+ if (archive_strlen(&(mtree->cur_dirstr))
+ == archive_strlen(&(file->parentdir)) &&
+ strcmp(mtree->cur_dirstr.s, fn) == 0) {
+ if (!__archive_rb_tree_insert_node(
+ &(mtree->cur_dirent->dir_info->rbtree),
+ (struct archive_rb_node *)file)) {
+ /* There is the same name in the tree. */
+ np = (struct mtree_entry *)__archive_rb_tree_find_node(
+ &(mtree->cur_dirent->dir_info->rbtree),
+ file->basename.s);
+ goto same_entry;
+ }
+ file->parent = mtree->cur_dirent;
+ mtree_entry_register_add(mtree, file);
+ return (ARCHIVE_OK);
+ }
+
+ dent = mtree->root;
+ for (;;) {
+ l = get_path_component(name, sizeof(name), fn);
+ if (l == 0) {
+ np = NULL;
+ break;
+ }
+ if (l < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "A name buffer is too small");
+ return (ARCHIVE_FATAL);
+ }
+ if (l == 1 && name[0] == '.' && dent != NULL &&
+ dent == mtree->root) {
+ fn += l;
+ if (fn[0] == '/')
+ fn++;
+ continue;
+ }
+
+ np = mtree_entry_find_child(dent, name);
+ if (np == NULL || fn[0] == '\0')
+ break;
+
+ /* Find next sub directory. */
+ if (!np->dir_info) {
+ /* NOT Directory! */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "`%s' is not directory, we cannot insert `%s' ",
+ np->pathname.s, file->pathname.s);
+ return (ARCHIVE_FAILED);
+ }
+ fn += l;
+ if (fn[0] == '/')
+ fn++;
+ dent = np;
+ }
+ if (np == NULL) {
+ /*
+ * Create virtual parent directories.
+ */
+ while (fn[0] != '\0') {
+ struct mtree_entry *vp;
+ struct archive_string as;
+
+ archive_string_init(&as);
+ archive_strncat(&as, p, fn - p + l);
+ if (as.s[as.length-1] == '/') {
+ as.s[as.length-1] = '\0';
+ as.length--;
+ }
+ r = mtree_entry_create_virtual_dir(a, as.s, &vp);
+ archive_string_free(&as);
+ if (r < ARCHIVE_WARN)
+ return (r);
+
+ if (strcmp(vp->pathname.s, ".") == 0) {
+ vp->parent = vp;
+ mtree->root = vp;
+ } else {
+ __archive_rb_tree_insert_node(
+ &(dent->dir_info->rbtree),
+ (struct archive_rb_node *)vp);
+ vp->parent = dent;
+ }
+ mtree_entry_register_add(mtree, vp);
+ np = vp;
+
+ fn += l;
+ if (fn[0] == '/')
+ fn++;
+ l = get_path_component(name, sizeof(name), fn);
+ if (l < 0) {
+ archive_string_free(&as);
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "A name buffer is too small");
+ return (ARCHIVE_FATAL);
+ }
+ dent = np;
+ }
+
+ /* Found out the parent directory where `file' can be
+ * inserted. */
+ mtree->cur_dirent = dent;
+ archive_string_empty(&(mtree->cur_dirstr));
+ archive_string_ensure(&(mtree->cur_dirstr),
+ archive_strlen(&(dent->parentdir)) +
+ archive_strlen(&(dent->basename)) + 2);
+ if (archive_strlen(&(dent->parentdir)) +
+ archive_strlen(&(dent->basename)) == 0)
+ mtree->cur_dirstr.s[0] = 0;
+ else {
+ if (archive_strlen(&(dent->parentdir)) > 0) {
+ archive_string_copy(&(mtree->cur_dirstr),
+ &(dent->parentdir));
+ archive_strappend_char(
+ &(mtree->cur_dirstr), '/');
+ }
+ archive_string_concat(&(mtree->cur_dirstr),
+ &(dent->basename));
+ }
+
+ if (!__archive_rb_tree_insert_node(
+ &(dent->dir_info->rbtree),
+ (struct archive_rb_node *)file)) {
+ np = (struct mtree_entry *)__archive_rb_tree_find_node(
+ &(dent->dir_info->rbtree), file->basename.s);
+ goto same_entry;
+ }
+ file->parent = dent;
+ mtree_entry_register_add(mtree, file);
+ return (ARCHIVE_OK);
+ }
+
+same_entry:
+ /*
+ * We have already has the entry the filename of which is
+ * the same.
+ */
+ r = mtree_entry_exchange_same_entry(a, np, file);
+ if (r < ARCHIVE_WARN)
+ return (r);
+ if (np->dir_info)
+ np->dir_info->virtual = 0;
+ *filep = np;
+ mtree_entry_free(file);
+ return (ARCHIVE_WARN);
+}
+
+static int
+mtree_entry_exchange_same_entry(struct archive_write *a, struct mtree_entry *np,
+ struct mtree_entry *file)
+{
+
+ if ((np->mode & AE_IFMT) != (file->mode & AE_IFMT)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Found duplicate entries `%s' and its file type is "
+ "different",
+ np->pathname.s);
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Update the existent mtree entry's attributes by the new one's. */
+ archive_string_empty(&np->symlink);
+ archive_string_concat(&np->symlink, &file->symlink);
+ archive_string_empty(&np->uname);
+ archive_string_concat(&np->uname, &file->uname);
+ archive_string_empty(&np->gname);
+ archive_string_concat(&np->gname, &file->gname);
+ archive_string_empty(&np->fflags_text);
+ archive_string_concat(&np->fflags_text, &file->fflags_text);
+ np->nlink = file->nlink;
+ np->filetype = file->filetype;
+ np->mode = file->mode;
+ np->size = file->size;
+ np->uid = file->uid;
+ np->gid = file->gid;
+ np->fflags_set = file->fflags_set;
+ np->fflags_clear = file->fflags_clear;
+ np->mtime = file->mtime;
+ np->mtime_nsec = file->mtime_nsec;
+ np->rdevmajor = file->rdevmajor;
+ np->rdevminor = file->rdevminor;
+ np->devmajor = file->devmajor;
+ np->devminor = file->devminor;
+ np->ino = file->ino;
+
+ return (ARCHIVE_WARN);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c
new file mode 100644
index 0000000000..687f8e48a9
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c
@@ -0,0 +1,1900 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2010-2012 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: head/lib/libarchive/archive_write_set_format_pax.c 201162 2009-12-29 05:47:46Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+struct sparse_block {
+ struct sparse_block *next;
+ int is_hole;
+ uint64_t offset;
+ uint64_t remaining;
+};
+
+struct pax {
+ uint64_t entry_bytes_remaining;
+ uint64_t entry_padding;
+ struct archive_string l_url_encoded_name;
+ struct archive_string pax_header;
+ struct archive_string sparse_map;
+ size_t sparse_map_padding;
+ struct sparse_block *sparse_list;
+ struct sparse_block *sparse_tail;
+ struct archive_string_conv *sconv_utf8;
+ int opt_binary;
+};
+
+static void add_pax_attr(struct archive_string *, const char *key,
+ const char *value);
+static void add_pax_attr_int(struct archive_string *,
+ const char *key, int64_t value);
+static void add_pax_attr_time(struct archive_string *,
+ const char *key, int64_t sec,
+ unsigned long nanos);
+static ssize_t archive_write_pax_data(struct archive_write *,
+ const void *, size_t);
+static int archive_write_pax_close(struct archive_write *);
+static int archive_write_pax_free(struct archive_write *);
+static int archive_write_pax_finish_entry(struct archive_write *);
+static int archive_write_pax_header(struct archive_write *,
+ struct archive_entry *);
+static int archive_write_pax_options(struct archive_write *,
+ const char *, const char *);
+static char *base64_encode(const char *src, size_t len);
+static char *build_gnu_sparse_name(char *dest, const char *src);
+static char *build_pax_attribute_name(char *dest, const char *src);
+static char *build_ustar_entry_name(char *dest, const char *src,
+ size_t src_length, const char *insert);
+static char *format_int(char *dest, int64_t);
+static int has_non_ASCII(const char *);
+static void sparse_list_clear(struct pax *);
+static int sparse_list_add(struct pax *, int64_t, int64_t);
+static char *url_encode(const char *in);
+
+/*
+ * Set output format to 'restricted pax' format.
+ *
+ * This is the same as normal 'pax', but tries to suppress
+ * the pax header whenever possible. This is the default for
+ * bsdtar, for instance.
+ */
+int
+archive_write_set_format_pax_restricted(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ int r;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_pax_restricted");
+
+ r = archive_write_set_format_pax(&a->archive);
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
+ a->archive.archive_format_name = "restricted POSIX pax interchange";
+ return (r);
+}
+
+/*
+ * Set output format to 'pax' format.
+ */
+int
+archive_write_set_format_pax(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct pax *pax;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_pax");
+
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ pax = (struct pax *)malloc(sizeof(*pax));
+ if (pax == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate pax data");
+ return (ARCHIVE_FATAL);
+ }
+ memset(pax, 0, sizeof(*pax));
+ a->format_data = pax;
+ a->format_name = "pax";
+ a->format_options = archive_write_pax_options;
+ a->format_write_header = archive_write_pax_header;
+ a->format_write_data = archive_write_pax_data;
+ a->format_close = archive_write_pax_close;
+ a->format_free = archive_write_pax_free;
+ a->format_finish_entry = archive_write_pax_finish_entry;
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE;
+ a->archive.archive_format_name = "POSIX pax interchange";
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_pax_options(struct archive_write *a, const char *key,
+ const char *val)
+{
+ struct pax *pax = (struct pax *)a->format_data;
+ int ret = ARCHIVE_FAILED;
+
+ if (strcmp(key, "hdrcharset") == 0) {
+ /*
+ * The character-set we can use are defined in
+ * IEEE Std 1003.1-2001
+ */
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "pax: hdrcharset option needs a character-set name");
+ else if (strcmp(val, "BINARY") == 0 ||
+ strcmp(val, "binary") == 0) {
+ /*
+ * Specify binary mode. We will not convert
+ * filenames, uname and gname to any charsets.
+ */
+ pax->opt_binary = 1;
+ ret = ARCHIVE_OK;
+ } else if (strcmp(val, "UTF-8") == 0) {
+ /*
+ * Specify UTF-8 character-set to be used for
+ * filenames. This is almost the test that
+ * running platform supports the string conversion.
+ * Especially libarchive_test needs this trick for
+ * its test.
+ */
+ pax->sconv_utf8 = archive_string_conversion_to_charset(
+ &(a->archive), "UTF-8", 0);
+ if (pax->sconv_utf8 == NULL)
+ ret = ARCHIVE_FATAL;
+ else
+ ret = ARCHIVE_OK;
+ } else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "pax: invalid charset name");
+ return (ret);
+ }
+
+ /* 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);
+}
+
+/*
+ * Note: This code assumes that 'nanos' has the same sign as 'sec',
+ * which implies that sec=-1, nanos=200000000 represents -1.2 seconds
+ * and not -0.8 seconds. This is a pretty pedantic point, as we're
+ * unlikely to encounter many real files created before Jan 1, 1970,
+ * much less ones with timestamps recorded to sub-second resolution.
+ */
+static void
+add_pax_attr_time(struct archive_string *as, const char *key,
+ int64_t sec, unsigned long nanos)
+{
+ int digit, i;
+ char *t;
+ /*
+ * Note that each byte contributes fewer than 3 base-10
+ * digits, so this will always be big enough.
+ */
+ char tmp[1 + 3*sizeof(sec) + 1 + 3*sizeof(nanos)];
+
+ tmp[sizeof(tmp) - 1] = 0;
+ t = tmp + sizeof(tmp) - 1;
+
+ /* Skip trailing zeros in the fractional part. */
+ for (digit = 0, i = 10; i > 0 && digit == 0; i--) {
+ digit = nanos % 10;
+ nanos /= 10;
+ }
+
+ /* Only format the fraction if it's non-zero. */
+ if (i > 0) {
+ while (i > 0) {
+ *--t = "0123456789"[digit];
+ digit = nanos % 10;
+ nanos /= 10;
+ i--;
+ }
+ *--t = '.';
+ }
+ t = format_int(t, sec);
+
+ add_pax_attr(as, key, t);
+}
+
+static char *
+format_int(char *t, int64_t i)
+{
+ uint64_t ui;
+
+ if (i < 0)
+ ui = (i == INT64_MIN) ? (uint64_t)(INT64_MAX) + 1 : (uint64_t)(-i);
+ else
+ ui = i;
+
+ do {
+ *--t = "0123456789"[ui % 10];
+ } while (ui /= 10);
+ if (i < 0)
+ *--t = '-';
+ return (t);
+}
+
+static void
+add_pax_attr_int(struct archive_string *as, const char *key, int64_t value)
+{
+ char tmp[1 + 3 * sizeof(value)];
+
+ tmp[sizeof(tmp) - 1] = 0;
+ add_pax_attr(as, key, format_int(tmp + sizeof(tmp) - 1, value));
+}
+
+/*
+ * Add a key/value attribute to the pax header. This function handles
+ * the length field and various other syntactic requirements.
+ */
+static void
+add_pax_attr(struct archive_string *as, const char *key, const char *value)
+{
+ int digits, i, len, next_ten;
+ char tmp[1 + 3 * sizeof(int)]; /* < 3 base-10 digits per byte */
+
+ /*-
+ * PAX attributes have the following layout:
+ * <len> <space> <key> <=> <value> <nl>
+ */
+ len = 1 + (int)strlen(key) + 1 + (int)strlen(value) + 1;
+
+ /*
+ * The <len> field includes the length of the <len> field, so
+ * computing the correct length is tricky. I start by
+ * counting the number of base-10 digits in 'len' and
+ * computing the next higher power of 10.
+ */
+ next_ten = 1;
+ digits = 0;
+ i = len;
+ while (i > 0) {
+ i = i / 10;
+ digits++;
+ next_ten = next_ten * 10;
+ }
+ /*
+ * For example, if string without the length field is 99
+ * chars, then adding the 2 digit length "99" will force the
+ * total length past 100, requiring an extra digit. The next
+ * statement adjusts for this effect.
+ */
+ if (len + digits >= next_ten)
+ digits++;
+
+ /* Now, we have the right length so we can build the line. */
+ tmp[sizeof(tmp) - 1] = 0; /* Null-terminate the work area. */
+ archive_strcat(as, format_int(tmp + sizeof(tmp) - 1, len + digits));
+ archive_strappend_char(as, ' ');
+ archive_strcat(as, key);
+ archive_strappend_char(as, '=');
+ archive_strcat(as, value);
+ archive_strappend_char(as, '\n');
+}
+
+static int
+archive_write_pax_header_xattrs(struct archive_write *a,
+ struct pax *pax, struct archive_entry *entry)
+{
+ struct archive_string s;
+ int i = archive_entry_xattr_reset(entry);
+
+ while (i--) {
+ const char *name;
+ const void *value;
+ char *encoded_value;
+ char *url_encoded_name = NULL, *encoded_name = NULL;
+ size_t size;
+ int r;
+
+ archive_entry_xattr_next(entry, &name, &value, &size);
+ url_encoded_name = url_encode(name);
+ if (url_encoded_name != NULL) {
+ /* Convert narrow-character to UTF-8. */
+ r = archive_strcpy_l(&(pax->l_url_encoded_name),
+ url_encoded_name, pax->sconv_utf8);
+ free(url_encoded_name); /* Done with this. */
+ if (r == 0)
+ encoded_name = pax->l_url_encoded_name.s;
+ else if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ encoded_value = base64_encode((const char *)value, size);
+
+ if (encoded_name != NULL && encoded_value != NULL) {
+ archive_string_init(&s);
+ archive_strcpy(&s, "LIBARCHIVE.xattr.");
+ archive_strcat(&s, encoded_name);
+ add_pax_attr(&(pax->pax_header), s.s, encoded_value);
+ archive_string_free(&s);
+ }
+ free(encoded_value);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+get_entry_hardlink(struct archive_write *a, struct archive_entry *entry,
+ const char **name, size_t *length, struct archive_string_conv *sc)
+{
+ int r;
+
+ r = archive_entry_hardlink_l(entry, name, length, sc);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+get_entry_pathname(struct archive_write *a, struct archive_entry *entry,
+ const char **name, size_t *length, struct archive_string_conv *sc)
+{
+ int r;
+
+ r = archive_entry_pathname_l(entry, name, length, sc);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+get_entry_uname(struct archive_write *a, struct archive_entry *entry,
+ const char **name, size_t *length, struct archive_string_conv *sc)
+{
+ int r;
+
+ r = archive_entry_uname_l(entry, name, length, sc);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Uname");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+get_entry_gname(struct archive_write *a, struct archive_entry *entry,
+ const char **name, size_t *length, struct archive_string_conv *sc)
+{
+ int r;
+
+ r = archive_entry_gname_l(entry, name, length, sc);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Gname");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+get_entry_symlink(struct archive_write *a, struct archive_entry *entry,
+ const char **name, size_t *length, struct archive_string_conv *sc)
+{
+ int r;
+
+ r = archive_entry_symlink_l(entry, name, length, sc);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_WARN);
+ }
+ return (ARCHIVE_OK);
+}
+
+/*
+ * TODO: Consider adding 'comment' and 'charset' fields to
+ * archive_entry so that clients can specify them. Also, consider
+ * adding generic key/value tags so clients can add arbitrary
+ * key/value data.
+ *
+ * TODO: Break up this 700-line function!!!! Yowza!
+ */
+static int
+archive_write_pax_header(struct archive_write *a,
+ struct archive_entry *entry_original)
+{
+ struct archive_entry *entry_main;
+ const char *p;
+ const char *suffix;
+ int need_extension, r, ret;
+ int sparse_count;
+ uint64_t sparse_total, real_size;
+ struct pax *pax;
+ const char *hardlink;
+ const char *path = NULL, *linkpath = NULL;
+ const char *uname = NULL, *gname = NULL;
+ const void *mac_metadata;
+ size_t mac_metadata_size;
+ struct archive_string_conv *sconv;
+ size_t hardlink_length, path_length, linkpath_length;
+ size_t uname_length, gname_length;
+
+ char paxbuff[512];
+ char ustarbuff[512];
+ char ustar_entry_name[256];
+ char pax_entry_name[256];
+ char gnu_sparse_name[256];
+ struct archive_string entry_name;
+
+ ret = ARCHIVE_OK;
+ need_extension = 0;
+ pax = (struct pax *)a->format_data;
+
+ /* Sanity check. */
+ if (archive_entry_pathname(entry_original) == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't record entry in tar file without pathname");
+ return (ARCHIVE_FAILED);
+ }
+
+ /*
+ * Choose a header encoding.
+ */
+ if (pax->opt_binary)
+ sconv = NULL;/* Binary mode. */
+ else {
+ /* Header encoding is UTF-8. */
+ if (pax->sconv_utf8 == NULL) {
+ /* Initialize the string conversion object
+ * we must need */
+ pax->sconv_utf8 = archive_string_conversion_to_charset(
+ &(a->archive), "UTF-8", 1);
+ if (pax->sconv_utf8 == NULL)
+ /* Couldn't allocate memory */
+ return (ARCHIVE_FAILED);
+ }
+ sconv = pax->sconv_utf8;
+ }
+
+ r = get_entry_hardlink(a, entry_original, &hardlink,
+ &hardlink_length, sconv);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ else if (r != ARCHIVE_OK) {
+ r = get_entry_hardlink(a, entry_original, &hardlink,
+ &hardlink_length, NULL);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s", hardlink,
+ archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ sconv = NULL;/* The header charset switches to binary mode. */
+ }
+
+ /* Make sure this is a type of entry that we can handle here */
+ if (hardlink == NULL) {
+ switch (archive_entry_filetype(entry_original)) {
+ case AE_IFBLK:
+ case AE_IFCHR:
+ case AE_IFIFO:
+ case AE_IFLNK:
+ case AE_IFREG:
+ break;
+ case AE_IFDIR:
+ {
+ /*
+ * Ensure a trailing '/'. Modify the original
+ * entry so the client sees the change.
+ */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ const wchar_t *wp;
+
+ wp = archive_entry_pathname_w(entry_original);
+ if (wp != NULL && wp[wcslen(wp) -1] != L'/') {
+ struct archive_wstring ws;
+
+ archive_string_init(&ws);
+ path_length = wcslen(wp);
+ if (archive_wstring_ensure(&ws,
+ path_length + 2) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate pax data");
+ archive_wstring_free(&ws);
+ return(ARCHIVE_FATAL);
+ }
+ /* Should we keep '\' ? */
+ if (wp[path_length -1] == L'\\')
+ path_length--;
+ archive_wstrncpy(&ws, wp, path_length);
+ archive_wstrappend_wchar(&ws, L'/');
+ archive_entry_copy_pathname_w(
+ entry_original, ws.s);
+ archive_wstring_free(&ws);
+ p = NULL;
+ } else
+#endif
+ p = archive_entry_pathname(entry_original);
+ /*
+ * On Windows, this is a backup operation just in
+ * case getting WCS failed. On POSIX, this is a
+ * normal operation.
+ */
+ if (p != NULL && p[strlen(p) - 1] != '/') {
+ struct archive_string as;
+
+ archive_string_init(&as);
+ path_length = strlen(p);
+ if (archive_string_ensure(&as,
+ path_length + 2) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate pax data");
+ archive_string_free(&as);
+ return(ARCHIVE_FATAL);
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* NOTE: This might break the pathname
+ * if the current code page is CP932 and
+ * the pathname includes a character '\'
+ * as a part of its multibyte pathname. */
+ if (p[strlen(p) -1] == '\\')
+ path_length--;
+ else
+#endif
+ archive_strncpy(&as, p, path_length);
+ archive_strappend_char(&as, '/');
+ archive_entry_copy_pathname(
+ entry_original, as.s);
+ archive_string_free(&as);
+ }
+ break;
+ }
+ case AE_IFSOCK:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive socket");
+ return (ARCHIVE_FAILED);
+ default:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive this (type=0%lo)",
+ (unsigned long)
+ archive_entry_filetype(entry_original));
+ return (ARCHIVE_FAILED);
+ }
+ }
+
+ /*
+ * If Mac OS metadata blob is here, recurse to write that
+ * as a separate entry. This is really a pretty poor design:
+ * In particular, it doubles the overhead for long filenames.
+ * TODO: Help Apple folks design something better and figure
+ * out how to transition from this legacy format.
+ *
+ * Note that this code is present on every platform; clients
+ * on non-Mac are unlikely to ever provide this data, but
+ * applications that copy entries from one archive to another
+ * should not lose data just because the local filesystem
+ * can't store it.
+ */
+ mac_metadata =
+ archive_entry_mac_metadata(entry_original, &mac_metadata_size);
+ if (mac_metadata != NULL) {
+ const char *oname;
+ char *name, *bname;
+ size_t name_length;
+ struct archive_entry *extra = archive_entry_new2(&a->archive);
+
+ oname = archive_entry_pathname(entry_original);
+ name_length = strlen(oname);
+ name = malloc(name_length + 3);
+ if (name == NULL || extra == NULL) {
+ /* XXX error message */
+ archive_entry_free(extra);
+ free(name);
+ return (ARCHIVE_FAILED);
+ }
+ strcpy(name, oname);
+ /* Find last '/'; strip trailing '/' characters */
+ bname = strrchr(name, '/');
+ while (bname != NULL && bname[1] == '\0') {
+ *bname = '\0';
+ bname = strrchr(name, '/');
+ }
+ if (bname == NULL) {
+ memmove(name + 2, name, name_length + 1);
+ memmove(name, "._", 2);
+ } else {
+ bname += 1;
+ memmove(bname + 2, bname, strlen(bname) + 1);
+ memmove(bname, "._", 2);
+ }
+ archive_entry_copy_pathname(extra, name);
+ free(name);
+
+ archive_entry_set_size(extra, mac_metadata_size);
+ archive_entry_set_filetype(extra, AE_IFREG);
+ archive_entry_set_perm(extra,
+ archive_entry_perm(entry_original));
+ archive_entry_set_mtime(extra,
+ archive_entry_mtime(entry_original),
+ archive_entry_mtime_nsec(entry_original));
+ archive_entry_set_gid(extra,
+ archive_entry_gid(entry_original));
+ archive_entry_set_gname(extra,
+ archive_entry_gname(entry_original));
+ archive_entry_set_uid(extra,
+ archive_entry_uid(entry_original));
+ archive_entry_set_uname(extra,
+ archive_entry_uname(entry_original));
+
+ /* Recurse to write the special copyfile entry. */
+ r = archive_write_pax_header(a, extra);
+ archive_entry_free(extra);
+ if (r < ARCHIVE_WARN)
+ return (r);
+ if (r < ret)
+ ret = r;
+ r = (int)archive_write_pax_data(a, mac_metadata,
+ mac_metadata_size);
+ if (r < ARCHIVE_WARN)
+ return (r);
+ if (r < ret)
+ ret = r;
+ r = archive_write_pax_finish_entry(a);
+ if (r < ARCHIVE_WARN)
+ return (r);
+ if (r < ret)
+ ret = r;
+ }
+
+ /* Copy entry so we can modify it as needed. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Make sure the path separators in pahtname, hardlink and symlink
+ * are all slash '/', not the Windows path separator '\'. */
+ entry_main = __la_win_entry_in_posix_pathseparator(entry_original);
+ if (entry_main == entry_original)
+ entry_main = archive_entry_clone(entry_original);
+#else
+ entry_main = archive_entry_clone(entry_original);
+#endif
+ if (entry_main == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate pax data");
+ return(ARCHIVE_FATAL);
+ }
+ archive_string_empty(&(pax->pax_header)); /* Blank our work area. */
+ archive_string_empty(&(pax->sparse_map));
+ sparse_total = 0;
+ sparse_list_clear(pax);
+
+ if (hardlink == NULL &&
+ archive_entry_filetype(entry_main) == AE_IFREG)
+ sparse_count = archive_entry_sparse_reset(entry_main);
+ else
+ sparse_count = 0;
+ if (sparse_count) {
+ int64_t offset, length, last_offset = 0;
+ /* Get the last entry of sparse block. */
+ while (archive_entry_sparse_next(
+ entry_main, &offset, &length) == ARCHIVE_OK)
+ last_offset = offset + length;
+
+ /* If the last sparse block does not reach the end of file,
+ * We have to add a empty sparse block as the last entry to
+ * manage storing file data. */
+ if (last_offset < archive_entry_size(entry_main))
+ archive_entry_sparse_add_entry(entry_main,
+ archive_entry_size(entry_main), 0);
+ sparse_count = archive_entry_sparse_reset(entry_main);
+ }
+
+ /*
+ * First, check the name fields and see if any of them
+ * require binary coding. If any of them does, then all of
+ * them do.
+ */
+ r = get_entry_pathname(a, entry_main, &path, &path_length, sconv);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ else if (r != ARCHIVE_OK) {
+ r = get_entry_pathname(a, entry_main, &path,
+ &path_length, NULL);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate pathname '%s' to %s", path,
+ archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ sconv = NULL;/* The header charset switches to binary mode. */
+ }
+ r = get_entry_uname(a, entry_main, &uname, &uname_length, sconv);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ else if (r != ARCHIVE_OK) {
+ r = get_entry_uname(a, entry_main, &uname, &uname_length, NULL);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate uname '%s' to %s", uname,
+ archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ sconv = NULL;/* The header charset switches to binary mode. */
+ }
+ r = get_entry_gname(a, entry_main, &gname, &gname_length, sconv);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ else if (r != ARCHIVE_OK) {
+ r = get_entry_gname(a, entry_main, &gname, &gname_length, NULL);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate gname '%s' to %s", gname,
+ archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ sconv = NULL;/* The header charset switches to binary mode. */
+ }
+ linkpath = hardlink;
+ linkpath_length = hardlink_length;
+ if (linkpath == NULL) {
+ r = get_entry_symlink(a, entry_main, &linkpath,
+ &linkpath_length, sconv);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ else if (r != ARCHIVE_OK) {
+ r = get_entry_symlink(a, entry_main, &linkpath,
+ &linkpath_length, NULL);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s", linkpath,
+ archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ sconv = NULL;
+ }
+ }
+
+ /* If any string conversions failed, get all attributes
+ * in binary-mode. */
+ if (sconv == NULL && !pax->opt_binary) {
+ if (hardlink != NULL) {
+ r = get_entry_hardlink(a, entry_main, &hardlink,
+ &hardlink_length, NULL);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ linkpath = hardlink;
+ linkpath_length = hardlink_length;
+ }
+ r = get_entry_pathname(a, entry_main, &path,
+ &path_length, NULL);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ r = get_entry_uname(a, entry_main, &uname, &uname_length, NULL);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ r = get_entry_gname(a, entry_main, &gname, &gname_length, NULL);
+ if (r == ARCHIVE_FATAL)
+ return (r);
+ }
+
+ /* Store the header encoding first, to be nice to readers. */
+ if (sconv == NULL)
+ add_pax_attr(&(pax->pax_header), "hdrcharset", "BINARY");
+
+
+ /*
+ * If name is too long, or has non-ASCII characters, add
+ * 'path' to pax extended attrs. (Note that an unconvertible
+ * name must have non-ASCII characters.)
+ */
+ if (has_non_ASCII(path)) {
+ /* We have non-ASCII characters. */
+ add_pax_attr(&(pax->pax_header), "path", path);
+ archive_entry_set_pathname(entry_main,
+ build_ustar_entry_name(ustar_entry_name,
+ path, path_length, NULL));
+ need_extension = 1;
+ } else {
+ /* We have an all-ASCII path; we'd like to just store
+ * it in the ustar header if it will fit. Yes, this
+ * duplicates some of the logic in
+ * archive_write_set_format_ustar.c
+ */
+ if (path_length <= 100) {
+ /* Fits in the old 100-char tar name field. */
+ } else {
+ /* Find largest suffix that will fit. */
+ /* Note: strlen() > 100, so strlen() - 100 - 1 >= 0 */
+ suffix = strchr(path + path_length - 100 - 1, '/');
+ /* Don't attempt an empty prefix. */
+ if (suffix == path)
+ suffix = strchr(suffix + 1, '/');
+ /* We can put it in the ustar header if it's
+ * all ASCII and it's either <= 100 characters
+ * or can be split at a '/' into a prefix <=
+ * 155 chars and a suffix <= 100 chars. (Note
+ * the strchr() above will return NULL exactly
+ * when the path can't be split.)
+ */
+ if (suffix == NULL /* Suffix > 100 chars. */
+ || suffix[1] == '\0' /* empty suffix */
+ || suffix - path > 155) /* Prefix > 155 chars */
+ {
+ add_pax_attr(&(pax->pax_header), "path", path);
+ archive_entry_set_pathname(entry_main,
+ build_ustar_entry_name(ustar_entry_name,
+ path, path_length, NULL));
+ need_extension = 1;
+ }
+ }
+ }
+
+ if (linkpath != NULL) {
+ /* If link name is too long or has non-ASCII characters, add
+ * 'linkpath' to pax extended attrs. */
+ if (linkpath_length > 100 || has_non_ASCII(linkpath)) {
+ add_pax_attr(&(pax->pax_header), "linkpath", linkpath);
+ if (linkpath_length > 100) {
+ if (hardlink != NULL)
+ archive_entry_set_hardlink(entry_main,
+ "././@LongHardLink");
+ else
+ archive_entry_set_symlink(entry_main,
+ "././@LongSymLink");
+ }
+ need_extension = 1;
+ }
+ }
+ /* Save a pathname since it will be renamed if `entry_main` has
+ * sparse blocks. */
+ archive_string_init(&entry_name);
+ archive_strcpy(&entry_name, archive_entry_pathname(entry_main));
+
+ /* If file size is too large, add 'size' to pax extended attrs. */
+ if (archive_entry_size(entry_main) >= (((int64_t)1) << 33)) {
+ add_pax_attr_int(&(pax->pax_header), "size",
+ archive_entry_size(entry_main));
+ need_extension = 1;
+ }
+
+ /* If numeric GID is too large, add 'gid' to pax extended attrs. */
+ if ((unsigned int)archive_entry_gid(entry_main) >= (1 << 18)) {
+ add_pax_attr_int(&(pax->pax_header), "gid",
+ archive_entry_gid(entry_main));
+ need_extension = 1;
+ }
+
+ /* If group name is too large or has non-ASCII characters, add
+ * 'gname' to pax extended attrs. */
+ if (gname != NULL) {
+ if (gname_length > 31 || has_non_ASCII(gname)) {
+ add_pax_attr(&(pax->pax_header), "gname", gname);
+ need_extension = 1;
+ }
+ }
+
+ /* If numeric UID is too large, add 'uid' to pax extended attrs. */
+ if ((unsigned int)archive_entry_uid(entry_main) >= (1 << 18)) {
+ add_pax_attr_int(&(pax->pax_header), "uid",
+ archive_entry_uid(entry_main));
+ need_extension = 1;
+ }
+
+ /* Add 'uname' to pax extended attrs if necessary. */
+ if (uname != NULL) {
+ if (uname_length > 31 || has_non_ASCII(uname)) {
+ add_pax_attr(&(pax->pax_header), "uname", uname);
+ need_extension = 1;
+ }
+ }
+
+ /*
+ * POSIX/SUSv3 doesn't provide a standard key for large device
+ * numbers. I use the same keys here that Joerg Schilling
+ * used for 'star.' (Which, somewhat confusingly, are called
+ * "devXXX" even though they code "rdev" values.) No doubt,
+ * other implementations use other keys. Note that there's no
+ * reason we can't write the same information into a number of
+ * different keys.
+ *
+ * Of course, this is only needed for block or char device entries.
+ */
+ if (archive_entry_filetype(entry_main) == AE_IFBLK
+ || archive_entry_filetype(entry_main) == AE_IFCHR) {
+ /*
+ * If rdevmajor is too large, add 'SCHILY.devmajor' to
+ * extended attributes.
+ */
+ int rdevmajor, rdevminor;
+ rdevmajor = archive_entry_rdevmajor(entry_main);
+ rdevminor = archive_entry_rdevminor(entry_main);
+ if (rdevmajor >= (1 << 18)) {
+ add_pax_attr_int(&(pax->pax_header), "SCHILY.devmajor",
+ rdevmajor);
+ /*
+ * Non-strict formatting below means we don't
+ * have to truncate here. Not truncating improves
+ * the chance that some more modern tar archivers
+ * (such as GNU tar 1.13) can restore the full
+ * value even if they don't understand the pax
+ * extended attributes. See my rant below about
+ * file size fields for additional details.
+ */
+ /* archive_entry_set_rdevmajor(entry_main,
+ rdevmajor & ((1 << 18) - 1)); */
+ need_extension = 1;
+ }
+
+ /*
+ * If devminor is too large, add 'SCHILY.devminor' to
+ * extended attributes.
+ */
+ if (rdevminor >= (1 << 18)) {
+ add_pax_attr_int(&(pax->pax_header), "SCHILY.devminor",
+ rdevminor);
+ /* Truncation is not necessary here, either. */
+ /* archive_entry_set_rdevminor(entry_main,
+ rdevminor & ((1 << 18) - 1)); */
+ need_extension = 1;
+ }
+ }
+
+ /*
+ * Technically, the mtime field in the ustar header can
+ * support 33 bits, but many platforms use signed 32-bit time
+ * values. The cutoff of 0x7fffffff here is a compromise.
+ * Yes, this check is duplicated just below; this helps to
+ * avoid writing an mtime attribute just to handle a
+ * high-resolution timestamp in "restricted pax" mode.
+ */
+ if (!need_extension &&
+ ((archive_entry_mtime(entry_main) < 0)
+ || (archive_entry_mtime(entry_main) >= 0x7fffffff)))
+ need_extension = 1;
+
+ /* I use a star-compatible file flag attribute. */
+ p = archive_entry_fflags_text(entry_main);
+ if (!need_extension && p != NULL && *p != '\0')
+ need_extension = 1;
+
+ /* If there are non-trivial ACL entries, we need an extension. */
+ if (!need_extension && archive_entry_acl_count(entry_original,
+ ARCHIVE_ENTRY_ACL_TYPE_ACCESS) > 0)
+ need_extension = 1;
+
+ /* If there are non-trivial ACL entries, we need an extension. */
+ if (!need_extension && archive_entry_acl_count(entry_original,
+ ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) > 0)
+ need_extension = 1;
+
+ /* If there are extended attributes, we need an extension */
+ if (!need_extension && archive_entry_xattr_count(entry_original) > 0)
+ need_extension = 1;
+
+ /* If there are sparse info, we need an extension */
+ if (!need_extension && sparse_count > 0)
+ need_extension = 1;
+
+ /*
+ * The following items are handled differently in "pax
+ * restricted" format. In particular, in "pax restricted"
+ * format they won't be added unless need_extension is
+ * already set (we're already generating an extended header, so
+ * may as well include these).
+ */
+ if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_RESTRICTED ||
+ need_extension) {
+
+ if (archive_entry_mtime(entry_main) < 0 ||
+ archive_entry_mtime(entry_main) >= 0x7fffffff ||
+ archive_entry_mtime_nsec(entry_main) != 0)
+ add_pax_attr_time(&(pax->pax_header), "mtime",
+ archive_entry_mtime(entry_main),
+ archive_entry_mtime_nsec(entry_main));
+
+ if (archive_entry_ctime(entry_main) != 0 ||
+ archive_entry_ctime_nsec(entry_main) != 0)
+ add_pax_attr_time(&(pax->pax_header), "ctime",
+ archive_entry_ctime(entry_main),
+ archive_entry_ctime_nsec(entry_main));
+
+ if (archive_entry_atime(entry_main) != 0 ||
+ archive_entry_atime_nsec(entry_main) != 0)
+ add_pax_attr_time(&(pax->pax_header), "atime",
+ archive_entry_atime(entry_main),
+ archive_entry_atime_nsec(entry_main));
+
+ /* Store birth/creationtime only if it's earlier than mtime */
+ if (archive_entry_birthtime_is_set(entry_main) &&
+ archive_entry_birthtime(entry_main)
+ < archive_entry_mtime(entry_main))
+ add_pax_attr_time(&(pax->pax_header),
+ "LIBARCHIVE.creationtime",
+ archive_entry_birthtime(entry_main),
+ archive_entry_birthtime_nsec(entry_main));
+
+ /* I use a star-compatible file flag attribute. */
+ p = archive_entry_fflags_text(entry_main);
+ if (p != NULL && *p != '\0')
+ add_pax_attr(&(pax->pax_header), "SCHILY.fflags", p);
+
+ /* I use star-compatible ACL attributes. */
+ r = archive_entry_acl_text_l(entry_original,
+ ARCHIVE_ENTRY_ACL_TYPE_ACCESS |
+ ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID,
+ &p, NULL, pax->sconv_utf8);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for "
+ "ACL.access");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate ACL.access to UTF-8");
+ ret = ARCHIVE_WARN;
+ } else if (p != NULL && *p != '\0') {
+ add_pax_attr(&(pax->pax_header),
+ "SCHILY.acl.access", p);
+ }
+ r = archive_entry_acl_text_l(entry_original,
+ ARCHIVE_ENTRY_ACL_TYPE_DEFAULT |
+ ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID,
+ &p, NULL, pax->sconv_utf8);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for "
+ "ACL.default");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate ACL.default to UTF-8");
+ ret = ARCHIVE_WARN;
+ } else if (p != NULL && *p != '\0') {
+ add_pax_attr(&(pax->pax_header),
+ "SCHILY.acl.default", p);
+ }
+
+ /* We use GNU-tar-compatible sparse attributes. */
+ if (sparse_count > 0) {
+ int64_t soffset, slength;
+
+ add_pax_attr_int(&(pax->pax_header),
+ "GNU.sparse.major", 1);
+ add_pax_attr_int(&(pax->pax_header),
+ "GNU.sparse.minor", 0);
+ add_pax_attr(&(pax->pax_header),
+ "GNU.sparse.name", entry_name.s);
+ add_pax_attr_int(&(pax->pax_header),
+ "GNU.sparse.realsize",
+ archive_entry_size(entry_main));
+
+ /* Rename the file name which will be used for
+ * ustar header to a special name, which GNU
+ * PAX Format 1.0 requires */
+ archive_entry_set_pathname(entry_main,
+ build_gnu_sparse_name(gnu_sparse_name,
+ entry_name.s));
+
+ /*
+ * - Make a sparse map, which will precede a file data.
+ * - Get the total size of available data of sparse.
+ */
+ archive_string_sprintf(&(pax->sparse_map), "%d\n",
+ sparse_count);
+ while (archive_entry_sparse_next(entry_main,
+ &soffset, &slength) == ARCHIVE_OK) {
+ archive_string_sprintf(&(pax->sparse_map),
+ "%jd\n%jd\n",
+ (intmax_t)soffset,
+ (intmax_t)slength);
+ sparse_total += slength;
+ if (sparse_list_add(pax, soffset, slength)
+ != ARCHIVE_OK) {
+ archive_set_error(&a->archive,
+ ENOMEM,
+ "Can't allocate memory");
+ archive_entry_free(entry_main);
+ archive_string_free(&entry_name);
+ return (ARCHIVE_FATAL);
+ }
+ }
+ }
+
+ /* Store extended attributes */
+ if (archive_write_pax_header_xattrs(a, pax, entry_original)
+ == ARCHIVE_FATAL) {
+ archive_entry_free(entry_main);
+ archive_string_free(&entry_name);
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ /* Only regular files have data. */
+ if (archive_entry_filetype(entry_main) != AE_IFREG)
+ archive_entry_set_size(entry_main, 0);
+
+ /*
+ * Pax-restricted does not store data for hardlinks, in order
+ * to improve compatibility with ustar.
+ */
+ if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE &&
+ hardlink != NULL)
+ archive_entry_set_size(entry_main, 0);
+
+ /*
+ * XXX Full pax interchange format does permit a hardlink
+ * entry to have data associated with it. I'm not supporting
+ * that here because the client expects me to tell them whether
+ * or not this format expects data for hardlinks. If I
+ * don't check here, then every pax archive will end up with
+ * duplicated data for hardlinks. Someday, there may be
+ * need to select this behavior, in which case the following
+ * will need to be revisited. XXX
+ */
+ if (hardlink != NULL)
+ archive_entry_set_size(entry_main, 0);
+
+ /* Save a real file size. */
+ real_size = archive_entry_size(entry_main);
+ /*
+ * Overwrite a file size by the total size of sparse blocks and
+ * the size of sparse map info. That file size is the length of
+ * the data, which we will exactly store into an archive file.
+ */
+ if (archive_strlen(&(pax->sparse_map))) {
+ size_t mapsize = archive_strlen(&(pax->sparse_map));
+ pax->sparse_map_padding = 0x1ff & (-(ssize_t)mapsize);
+ archive_entry_set_size(entry_main,
+ mapsize + pax->sparse_map_padding + sparse_total);
+ }
+
+ /* Format 'ustar' header for main entry.
+ *
+ * The trouble with file size: If the reader can't understand
+ * the file size, they may not be able to locate the next
+ * entry and the rest of the archive is toast. Pax-compliant
+ * readers are supposed to ignore the file size in the main
+ * header, so the question becomes how to maximize portability
+ * for readers that don't support pax attribute extensions.
+ * For maximum compatibility, I permit numeric extensions in
+ * the main header so that the file size stored will always be
+ * correct, even if it's in a format that only some
+ * implementations understand. The technique used here is:
+ *
+ * a) If possible, follow the standard exactly. This handles
+ * files up to 8 gigabytes minus 1.
+ *
+ * b) If that fails, try octal but omit the field terminator.
+ * That handles files up to 64 gigabytes minus 1.
+ *
+ * c) Otherwise, use base-256 extensions. That handles files
+ * up to 2^63 in this implementation, with the potential to
+ * go up to 2^94. That should hold us for a while. ;-)
+ *
+ * The non-strict formatter uses similar logic for other
+ * numeric fields, though they're less critical.
+ */
+ if (__archive_write_format_header_ustar(a, ustarbuff, entry_main, -1, 0,
+ NULL) == ARCHIVE_FATAL)
+ return (ARCHIVE_FATAL);
+
+ /* If we built any extended attributes, write that entry first. */
+ if (archive_strlen(&(pax->pax_header)) > 0) {
+ struct archive_entry *pax_attr_entry;
+ time_t s;
+ int64_t uid, gid;
+ int mode;
+
+ pax_attr_entry = archive_entry_new2(&a->archive);
+ p = entry_name.s;
+ archive_entry_set_pathname(pax_attr_entry,
+ build_pax_attribute_name(pax_entry_name, p));
+ archive_entry_set_size(pax_attr_entry,
+ archive_strlen(&(pax->pax_header)));
+ /* Copy uid/gid (but clip to ustar limits). */
+ uid = archive_entry_uid(entry_main);
+ if (uid >= 1 << 18)
+ uid = (1 << 18) - 1;
+ archive_entry_set_uid(pax_attr_entry, uid);
+ gid = archive_entry_gid(entry_main);
+ if (gid >= 1 << 18)
+ gid = (1 << 18) - 1;
+ archive_entry_set_gid(pax_attr_entry, gid);
+ /* Copy mode over (but not setuid/setgid bits) */
+ mode = archive_entry_mode(entry_main);
+#ifdef S_ISUID
+ mode &= ~S_ISUID;
+#endif
+#ifdef S_ISGID
+ mode &= ~S_ISGID;
+#endif
+#ifdef S_ISVTX
+ mode &= ~S_ISVTX;
+#endif
+ archive_entry_set_mode(pax_attr_entry, mode);
+
+ /* Copy uname/gname. */
+ archive_entry_set_uname(pax_attr_entry,
+ archive_entry_uname(entry_main));
+ archive_entry_set_gname(pax_attr_entry,
+ archive_entry_gname(entry_main));
+
+ /* Copy mtime, but clip to ustar limits. */
+ s = archive_entry_mtime(entry_main);
+ if (s < 0) { s = 0; }
+ if (s >= 0x7fffffff) { s = 0x7fffffff; }
+ archive_entry_set_mtime(pax_attr_entry, s, 0);
+
+ /* Standard ustar doesn't support atime. */
+ archive_entry_set_atime(pax_attr_entry, 0, 0);
+
+ /* Standard ustar doesn't support ctime. */
+ archive_entry_set_ctime(pax_attr_entry, 0, 0);
+
+ r = __archive_write_format_header_ustar(a, paxbuff,
+ pax_attr_entry, 'x', 1, NULL);
+
+ archive_entry_free(pax_attr_entry);
+
+ /* Note that the 'x' header shouldn't ever fail to format */
+ if (r < ARCHIVE_WARN) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "archive_write_pax_header: "
+ "'x' header failed?! This can't happen.\n");
+ return (ARCHIVE_FATAL);
+ } else if (r < ret)
+ ret = r;
+ r = __archive_write_output(a, paxbuff, 512);
+ if (r != ARCHIVE_OK) {
+ sparse_list_clear(pax);
+ pax->entry_bytes_remaining = 0;
+ pax->entry_padding = 0;
+ return (ARCHIVE_FATAL);
+ }
+
+ pax->entry_bytes_remaining = archive_strlen(&(pax->pax_header));
+ pax->entry_padding =
+ 0x1ff & (-(int64_t)pax->entry_bytes_remaining);
+
+ r = __archive_write_output(a, pax->pax_header.s,
+ archive_strlen(&(pax->pax_header)));
+ if (r != ARCHIVE_OK) {
+ /* If a write fails, we're pretty much toast. */
+ return (ARCHIVE_FATAL);
+ }
+ /* Pad out the end of the entry. */
+ r = __archive_write_nulls(a, (size_t)pax->entry_padding);
+ if (r != ARCHIVE_OK) {
+ /* If a write fails, we're pretty much toast. */
+ return (ARCHIVE_FATAL);
+ }
+ pax->entry_bytes_remaining = pax->entry_padding = 0;
+ }
+
+ /* Write the header for main entry. */
+ r = __archive_write_output(a, ustarbuff, 512);
+ if (r != ARCHIVE_OK)
+ return (r);
+
+ /*
+ * Inform the client of the on-disk size we're using, so
+ * they can avoid unnecessarily writing a body for something
+ * that we're just going to ignore.
+ */
+ archive_entry_set_size(entry_original, real_size);
+ if (pax->sparse_list == NULL && real_size > 0) {
+ /* This is not a sparse file but we handle its data as
+ * a sparse block. */
+ sparse_list_add(pax, 0, real_size);
+ sparse_total = real_size;
+ }
+ pax->entry_padding = 0x1ff & (-(int64_t)sparse_total);
+ archive_entry_free(entry_main);
+ archive_string_free(&entry_name);
+
+ return (ret);
+}
+
+/*
+ * We need a valid name for the regular 'ustar' entry. This routine
+ * tries to hack something more-or-less reasonable.
+ *
+ * The approach here tries to preserve leading dir names. We do so by
+ * working with four sections:
+ * 1) "prefix" directory names,
+ * 2) "suffix" directory names,
+ * 3) inserted dir name (optional),
+ * 4) filename.
+ *
+ * These sections must satisfy the following requirements:
+ * * Parts 1 & 2 together form an initial portion of the dir name.
+ * * Part 3 is specified by the caller. (It should not contain a leading
+ * or trailing '/'.)
+ * * Part 4 forms an initial portion of the base filename.
+ * * The filename must be <= 99 chars to fit the ustar 'name' field.
+ * * Parts 2, 3, 4 together must be <= 99 chars to fit the ustar 'name' fld.
+ * * Part 1 must be <= 155 chars to fit the ustar 'prefix' field.
+ * * If the original name ends in a '/', the new name must also end in a '/'
+ * * Trailing '/.' sequences may be stripped.
+ *
+ * Note: Recall that the ustar format does not store the '/' separating
+ * parts 1 & 2, but does store the '/' separating parts 2 & 3.
+ */
+static char *
+build_ustar_entry_name(char *dest, const char *src, size_t src_length,
+ const char *insert)
+{
+ const char *prefix, *prefix_end;
+ const char *suffix, *suffix_end;
+ const char *filename, *filename_end;
+ char *p;
+ int need_slash = 0; /* Was there a trailing slash? */
+ size_t suffix_length = 99;
+ size_t insert_length;
+
+ /* Length of additional dir element to be added. */
+ if (insert == NULL)
+ insert_length = 0;
+ else
+ /* +2 here allows for '/' before and after the insert. */
+ insert_length = strlen(insert) + 2;
+
+ /* Step 0: Quick bailout in a common case. */
+ if (src_length < 100 && insert == NULL) {
+ strncpy(dest, src, src_length);
+ dest[src_length] = '\0';
+ return (dest);
+ }
+
+ /* Step 1: Locate filename and enforce the length restriction. */
+ filename_end = src + src_length;
+ /* Remove trailing '/' chars and '/.' pairs. */
+ for (;;) {
+ if (filename_end > src && filename_end[-1] == '/') {
+ filename_end --;
+ need_slash = 1; /* Remember to restore trailing '/'. */
+ continue;
+ }
+ if (filename_end > src + 1 && filename_end[-1] == '.'
+ && filename_end[-2] == '/') {
+ filename_end -= 2;
+ need_slash = 1; /* "foo/." will become "foo/" */
+ continue;
+ }
+ break;
+ }
+ if (need_slash)
+ suffix_length--;
+ /* Find start of filename. */
+ filename = filename_end - 1;
+ while ((filename > src) && (*filename != '/'))
+ filename --;
+ if ((*filename == '/') && (filename < filename_end - 1))
+ filename ++;
+ /* Adjust filename_end so that filename + insert fits in 99 chars. */
+ suffix_length -= insert_length;
+ if (filename_end > filename + suffix_length)
+ filename_end = filename + suffix_length;
+ /* Calculate max size for "suffix" section (#3 above). */
+ suffix_length -= filename_end - filename;
+
+ /* Step 2: Locate the "prefix" section of the dirname, including
+ * trailing '/'. */
+ prefix = src;
+ prefix_end = prefix + 155;
+ if (prefix_end > filename)
+ prefix_end = filename;
+ while (prefix_end > prefix && *prefix_end != '/')
+ prefix_end--;
+ if ((prefix_end < filename) && (*prefix_end == '/'))
+ prefix_end++;
+
+ /* Step 3: Locate the "suffix" section of the dirname,
+ * including trailing '/'. */
+ suffix = prefix_end;
+ suffix_end = suffix + suffix_length; /* Enforce limit. */
+ if (suffix_end > filename)
+ suffix_end = filename;
+ if (suffix_end < suffix)
+ suffix_end = suffix;
+ while (suffix_end > suffix && *suffix_end != '/')
+ suffix_end--;
+ if ((suffix_end < filename) && (*suffix_end == '/'))
+ suffix_end++;
+
+ /* Step 4: Build the new name. */
+ /* The OpenBSD strlcpy function is safer, but less portable. */
+ /* Rather than maintain two versions, just use the strncpy version. */
+ p = dest;
+ if (prefix_end > prefix) {
+ strncpy(p, prefix, prefix_end - prefix);
+ p += prefix_end - prefix;
+ }
+ if (suffix_end > suffix) {
+ strncpy(p, suffix, suffix_end - suffix);
+ p += suffix_end - suffix;
+ }
+ if (insert != NULL) {
+ /* Note: assume insert does not have leading or trailing '/' */
+ strcpy(p, insert);
+ p += strlen(insert);
+ *p++ = '/';
+ }
+ strncpy(p, filename, filename_end - filename);
+ p += filename_end - filename;
+ if (need_slash)
+ *p++ = '/';
+ *p = '\0';
+
+ return (dest);
+}
+
+/*
+ * The ustar header for the pax extended attributes must have a
+ * reasonable name: SUSv3 requires 'dirname'/PaxHeader.'pid'/'filename'
+ * where 'pid' is the PID of the archiving process. Unfortunately,
+ * that makes testing a pain since the output varies for each run,
+ * so I'm sticking with the simpler 'dirname'/PaxHeader/'filename'
+ * for now. (Someday, I'll make this settable. Then I can use the
+ * SUS recommendation as default and test harnesses can override it
+ * to get predictable results.)
+ *
+ * Joerg Schilling has argued that this is unnecessary because, in
+ * practice, if the pax extended attributes get extracted as regular
+ * files, no one is going to bother reading those attributes to
+ * manually restore them. Based on this, 'star' uses
+ * /tmp/PaxHeader/'basename' as the ustar header name. This is a
+ * tempting argument, in part because it's simpler than the SUSv3
+ * recommendation, but I'm not entirely convinced. I'm also
+ * uncomfortable with the fact that "/tmp" is a Unix-ism.
+ *
+ * The following routine leverages build_ustar_entry_name() above and
+ * so is simpler than you might think. It just needs to provide the
+ * additional path element and handle a few pathological cases).
+ */
+static char *
+build_pax_attribute_name(char *dest, const char *src)
+{
+ char buff[64];
+ const char *p;
+
+ /* Handle the null filename case. */
+ if (src == NULL || *src == '\0') {
+ strcpy(dest, "PaxHeader/blank");
+ return (dest);
+ }
+
+ /* Prune final '/' and other unwanted final elements. */
+ p = src + strlen(src);
+ for (;;) {
+ /* Ends in "/", remove the '/' */
+ if (p > src && p[-1] == '/') {
+ --p;
+ continue;
+ }
+ /* Ends in "/.", remove the '.' */
+ if (p > src + 1 && p[-1] == '.'
+ && p[-2] == '/') {
+ --p;
+ continue;
+ }
+ break;
+ }
+
+ /* Pathological case: After above, there was nothing left.
+ * This includes "/." "/./." "/.//./." etc. */
+ if (p == src) {
+ strcpy(dest, "/PaxHeader/rootdir");
+ return (dest);
+ }
+
+ /* Convert unadorned "." into a suitable filename. */
+ if (*src == '.' && p == src + 1) {
+ strcpy(dest, "PaxHeader/currentdir");
+ return (dest);
+ }
+
+ /*
+ * TODO: Push this string into the 'pax' structure to avoid
+ * recomputing it every time. That will also open the door
+ * to having clients override it.
+ */
+#if HAVE_GETPID && 0 /* Disable this for now; see above comment. */
+ sprintf(buff, "PaxHeader.%d", getpid());
+#else
+ /* If the platform can't fetch the pid, don't include it. */
+ strcpy(buff, "PaxHeader");
+#endif
+ /* General case: build a ustar-compatible name adding
+ * "/PaxHeader/". */
+ build_ustar_entry_name(dest, src, p - src, buff);
+
+ return (dest);
+}
+
+/*
+ * GNU PAX Format 1.0 requires the special name, which pattern is:
+ * <dir>/GNUSparseFile.<pid>/<original file name>
+ *
+ * This function is used for only Sparse file, a file type of which
+ * is regular file.
+ */
+static char *
+build_gnu_sparse_name(char *dest, const char *src)
+{
+ char buff[64];
+ const char *p;
+
+ /* Handle the null filename case. */
+ if (src == NULL || *src == '\0') {
+ strcpy(dest, "GNUSparseFile/blank");
+ return (dest);
+ }
+
+ /* Prune final '/' and other unwanted final elements. */
+ p = src + strlen(src);
+ for (;;) {
+ /* Ends in "/", remove the '/' */
+ if (p > src && p[-1] == '/') {
+ --p;
+ continue;
+ }
+ /* Ends in "/.", remove the '.' */
+ if (p > src + 1 && p[-1] == '.'
+ && p[-2] == '/') {
+ --p;
+ continue;
+ }
+ break;
+ }
+
+#if HAVE_GETPID && 0 /* Disable this as pax attribute name. */
+ sprintf(buff, "GNUSparseFile.%d", getpid());
+#else
+ /* If the platform can't fetch the pid, don't include it. */
+ strcpy(buff, "GNUSparseFile");
+#endif
+ /* General case: build a ustar-compatible name adding
+ * "/GNUSparseFile/". */
+ build_ustar_entry_name(dest, src, p - src, buff);
+
+ return (dest);
+}
+
+/* Write two null blocks for the end of archive */
+static int
+archive_write_pax_close(struct archive_write *a)
+{
+ return (__archive_write_nulls(a, 512 * 2));
+}
+
+static int
+archive_write_pax_free(struct archive_write *a)
+{
+ struct pax *pax;
+
+ pax = (struct pax *)a->format_data;
+ if (pax == NULL)
+ return (ARCHIVE_OK);
+
+ archive_string_free(&pax->pax_header);
+ archive_string_free(&pax->sparse_map);
+ archive_string_free(&pax->l_url_encoded_name);
+ sparse_list_clear(pax);
+ free(pax);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_pax_finish_entry(struct archive_write *a)
+{
+ struct pax *pax;
+ uint64_t remaining;
+ int ret;
+
+ pax = (struct pax *)a->format_data;
+ remaining = pax->entry_bytes_remaining;
+ if (remaining == 0) {
+ while (pax->sparse_list) {
+ struct sparse_block *sb;
+ if (!pax->sparse_list->is_hole)
+ remaining += pax->sparse_list->remaining;
+ sb = pax->sparse_list->next;
+ free(pax->sparse_list);
+ pax->sparse_list = sb;
+ }
+ }
+ ret = __archive_write_nulls(a, (size_t)(remaining + pax->entry_padding));
+ pax->entry_bytes_remaining = pax->entry_padding = 0;
+ return (ret);
+}
+
+static ssize_t
+archive_write_pax_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct pax *pax;
+ size_t ws;
+ size_t total;
+ int ret;
+
+ pax = (struct pax *)a->format_data;
+
+ /*
+ * According to GNU PAX format 1.0, write a sparse map
+ * before the body.
+ */
+ if (archive_strlen(&(pax->sparse_map))) {
+ ret = __archive_write_output(a, pax->sparse_map.s,
+ archive_strlen(&(pax->sparse_map)));
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ ret = __archive_write_nulls(a, pax->sparse_map_padding);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ archive_string_empty(&(pax->sparse_map));
+ }
+
+ total = 0;
+ while (total < s) {
+ const unsigned char *p;
+
+ while (pax->sparse_list != NULL &&
+ pax->sparse_list->remaining == 0) {
+ struct sparse_block *sb = pax->sparse_list->next;
+ free(pax->sparse_list);
+ pax->sparse_list = sb;
+ }
+
+ if (pax->sparse_list == NULL)
+ return (total);
+
+ p = ((const unsigned char *)buff) + total;
+ ws = s - total;
+ if (ws > pax->sparse_list->remaining)
+ ws = (size_t)pax->sparse_list->remaining;
+
+ if (pax->sparse_list->is_hole) {
+ /* Current block is hole thus we do not write
+ * the body. */
+ pax->sparse_list->remaining -= ws;
+ total += ws;
+ continue;
+ }
+
+ ret = __archive_write_output(a, p, ws);
+ pax->sparse_list->remaining -= ws;
+ total += ws;
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ }
+ return (total);
+}
+
+static int
+has_non_ASCII(const char *_p)
+{
+ const unsigned char *p = (const unsigned char *)_p;
+
+ if (p == NULL)
+ return (1);
+ while (*p != '\0' && *p < 128)
+ p++;
+ return (*p != '\0');
+}
+
+/*
+ * Used by extended attribute support; encodes the name
+ * so that there will be no '=' characters in the result.
+ */
+static char *
+url_encode(const char *in)
+{
+ const char *s;
+ char *d;
+ int out_len = 0;
+ char *out;
+
+ for (s = in; *s != '\0'; s++) {
+ if (*s < 33 || *s > 126 || *s == '%' || *s == '=')
+ out_len += 3;
+ else
+ out_len++;
+ }
+
+ out = (char *)malloc(out_len + 1);
+ if (out == NULL)
+ return (NULL);
+
+ for (s = in, d = out; *s != '\0'; s++) {
+ /* encode any non-printable ASCII character or '%' or '=' */
+ if (*s < 33 || *s > 126 || *s == '%' || *s == '=') {
+ /* URL encoding is '%' followed by two hex digits */
+ *d++ = '%';
+ *d++ = "0123456789ABCDEF"[0x0f & (*s >> 4)];
+ *d++ = "0123456789ABCDEF"[0x0f & *s];
+ } else {
+ *d++ = *s;
+ }
+ }
+ *d = '\0';
+ return (out);
+}
+
+/*
+ * Encode a sequence of bytes into a C string using base-64 encoding.
+ *
+ * Returns a null-terminated C string allocated with malloc(); caller
+ * is responsible for freeing the result.
+ */
+static char *
+base64_encode(const char *s, size_t len)
+{
+ static const char digits[64] =
+ { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
+ 'P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d',
+ 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s',
+ 't','u','v','w','x','y','z','0','1','2','3','4','5','6','7',
+ '8','9','+','/' };
+ int v;
+ char *d, *out;
+
+ /* 3 bytes becomes 4 chars, but round up and allow for trailing NUL */
+ out = (char *)malloc((len * 4 + 2) / 3 + 1);
+ if (out == NULL)
+ return (NULL);
+ d = out;
+
+ /* Convert each group of 3 bytes into 4 characters. */
+ while (len >= 3) {
+ v = (((int)s[0] << 16) & 0xff0000)
+ | (((int)s[1] << 8) & 0xff00)
+ | (((int)s[2]) & 0x00ff);
+ s += 3;
+ len -= 3;
+ *d++ = digits[(v >> 18) & 0x3f];
+ *d++ = digits[(v >> 12) & 0x3f];
+ *d++ = digits[(v >> 6) & 0x3f];
+ *d++ = digits[(v) & 0x3f];
+ }
+ /* Handle final group of 1 byte (2 chars) or 2 bytes (3 chars). */
+ switch (len) {
+ case 0: break;
+ case 1:
+ v = (((int)s[0] << 16) & 0xff0000);
+ *d++ = digits[(v >> 18) & 0x3f];
+ *d++ = digits[(v >> 12) & 0x3f];
+ break;
+ case 2:
+ v = (((int)s[0] << 16) & 0xff0000)
+ | (((int)s[1] << 8) & 0xff00);
+ *d++ = digits[(v >> 18) & 0x3f];
+ *d++ = digits[(v >> 12) & 0x3f];
+ *d++ = digits[(v >> 6) & 0x3f];
+ break;
+ }
+ /* Add trailing NUL character so output is a valid C string. */
+ *d = '\0';
+ return (out);
+}
+
+static void
+sparse_list_clear(struct pax *pax)
+{
+ while (pax->sparse_list != NULL) {
+ struct sparse_block *sb = pax->sparse_list;
+ pax->sparse_list = sb->next;
+ free(sb);
+ }
+ pax->sparse_tail = NULL;
+}
+
+static int
+_sparse_list_add_block(struct pax *pax, int64_t offset, int64_t length,
+ int is_hole)
+{
+ struct sparse_block *sb;
+
+ sb = (struct sparse_block *)malloc(sizeof(*sb));
+ if (sb == NULL)
+ return (ARCHIVE_FATAL);
+ sb->next = NULL;
+ sb->is_hole = is_hole;
+ sb->offset = offset;
+ sb->remaining = length;
+ if (pax->sparse_list == NULL || pax->sparse_tail == NULL)
+ pax->sparse_list = pax->sparse_tail = sb;
+ else {
+ pax->sparse_tail->next = sb;
+ pax->sparse_tail = sb;
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+sparse_list_add(struct pax *pax, int64_t offset, int64_t length)
+{
+ int64_t last_offset;
+ int r;
+
+ if (pax->sparse_tail == NULL)
+ last_offset = 0;
+ else {
+ last_offset = pax->sparse_tail->offset +
+ pax->sparse_tail->remaining;
+ }
+ if (last_offset < offset) {
+ /* Add a hole block. */
+ r = _sparse_list_add_block(pax, last_offset,
+ offset - last_offset, 1);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+ /* Add data block. */
+ return (_sparse_list_add_block(pax, offset, length, 0));
+}
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_raw.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_raw.c
new file mode 100644
index 0000000000..feff936977
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_raw.c
@@ -0,0 +1,125 @@
+/*-
+ * Copyright (c) 2013 Marek Kubica
+ * 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_ERRNO_H
+#include <errno.h>
+#endif
+
+#include "archive_entry.h"
+#include "archive_write_private.h"
+
+static ssize_t archive_write_raw_data(struct archive_write *,
+ const void *buff, size_t s);
+static int archive_write_raw_free(struct archive_write *);
+static int archive_write_raw_header(struct archive_write *,
+ struct archive_entry *);
+
+struct raw {
+ int entries_written;
+};
+
+/*
+ * Set output format to 'raw' format.
+ */
+int
+archive_write_set_format_raw(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct raw *raw;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_raw");
+
+ /* If someone else was already registered, unregister them. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ raw = (struct raw *)calloc(1, sizeof(*raw));
+ if (raw == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate raw data");
+ return (ARCHIVE_FATAL);
+ }
+ raw->entries_written = 0;
+ a->format_data = raw;
+ a->format_name = "raw";
+ /* no options exist for this format */
+ a->format_options = NULL;
+ a->format_write_header = archive_write_raw_header;
+ a->format_write_data = archive_write_raw_data;
+ a->format_finish_entry = NULL;
+ /* nothing needs to be done on closing */
+ a->format_close = NULL;
+ a->format_free = archive_write_raw_free;
+ a->archive.archive_format = ARCHIVE_FORMAT_RAW;
+ a->archive.archive_format_name = "RAW";
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_raw_header(struct archive_write *a, struct archive_entry *entry)
+{
+ struct raw *raw = (struct raw *)a->format_data;
+
+ if (archive_entry_filetype(entry) != AE_IFREG) {
+ archive_set_error(&a->archive, ERANGE,
+ "Raw format only supports filetype AE_IFREG");
+ return (ARCHIVE_FATAL);
+ }
+
+
+ if (raw->entries_written > 0) {
+ archive_set_error(&a->archive, ERANGE,
+ "Raw format only supports one entry per archive");
+ return (ARCHIVE_FATAL);
+ }
+ raw->entries_written++;
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+archive_write_raw_data(struct archive_write *a, const void *buff, size_t s)
+{
+ int ret;
+
+ ret = __archive_write_output(a, buff, s);
+ if (ret >= 0)
+ return (s);
+ else
+ return (ret);
+}
+
+static int
+archive_write_raw_free(struct archive_write *a)
+{
+ struct raw *raw;
+
+ raw = (struct raw *)a->format_data;
+ free(raw);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_shar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_shar.c
new file mode 100644
index 0000000000..c033fb32f7
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_shar.c
@@ -0,0 +1,643 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2008 Joerg Sonnenberger
+ * 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_shar.c 189438 2009-03-06 05:58:56Z kientzle $");
+
+#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
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+struct shar {
+ int dump;
+ int end_of_line;
+ struct archive_entry *entry;
+ int has_data;
+ char *last_dir;
+
+ /* Line buffer for uuencoded dump format */
+ char outbuff[45];
+ size_t outpos;
+
+ int wrote_header;
+ struct archive_string work;
+ struct archive_string quoted_name;
+};
+
+static int archive_write_shar_close(struct archive_write *);
+static int archive_write_shar_free(struct archive_write *);
+static int archive_write_shar_header(struct archive_write *,
+ struct archive_entry *);
+static ssize_t archive_write_shar_data_sed(struct archive_write *,
+ const void * buff, size_t);
+static ssize_t archive_write_shar_data_uuencode(struct archive_write *,
+ const void * buff, size_t);
+static int archive_write_shar_finish_entry(struct archive_write *);
+
+/*
+ * Copy the given string to the buffer, quoting all shell meta characters
+ * found.
+ */
+static void
+shar_quote(struct archive_string *buf, const char *str, int in_shell)
+{
+ static const char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
+ size_t len;
+
+ while (*str != '\0') {
+ if ((len = strcspn(str, meta)) != 0) {
+ archive_strncat(buf, str, len);
+ str += len;
+ } else if (*str == '\n') {
+ if (in_shell)
+ archive_strcat(buf, "\"\n\"");
+ else
+ archive_strcat(buf, "\\n");
+ ++str;
+ } else {
+ archive_strappend_char(buf, '\\');
+ archive_strappend_char(buf, *str);
+ ++str;
+ }
+ }
+}
+
+/*
+ * Set output format to 'shar' format.
+ */
+int
+archive_write_set_format_shar(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct shar *shar;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_shar");
+
+ /* If someone else was already registered, unregister them. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ shar = (struct shar *)malloc(sizeof(*shar));
+ if (shar == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data");
+ return (ARCHIVE_FATAL);
+ }
+ memset(shar, 0, sizeof(*shar));
+ archive_string_init(&shar->work);
+ archive_string_init(&shar->quoted_name);
+ a->format_data = shar;
+ a->format_name = "shar";
+ a->format_write_header = archive_write_shar_header;
+ a->format_close = archive_write_shar_close;
+ a->format_free = archive_write_shar_free;
+ a->format_write_data = archive_write_shar_data_sed;
+ a->format_finish_entry = archive_write_shar_finish_entry;
+ a->archive.archive_format = ARCHIVE_FORMAT_SHAR_BASE;
+ a->archive.archive_format_name = "shar";
+ return (ARCHIVE_OK);
+}
+
+/*
+ * An alternate 'shar' that uses uudecode instead of 'sed' to encode
+ * file contents and can therefore be used to archive binary files.
+ * In addition, this variant also attempts to restore ownership, file modes,
+ * and other extended file information.
+ */
+int
+archive_write_set_format_shar_dump(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct shar *shar;
+
+ archive_write_set_format_shar(&a->archive);
+ shar = (struct shar *)a->format_data;
+ shar->dump = 1;
+ a->format_write_data = archive_write_shar_data_uuencode;
+ a->archive.archive_format = ARCHIVE_FORMAT_SHAR_DUMP;
+ a->archive.archive_format_name = "shar dump";
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_shar_header(struct archive_write *a, struct archive_entry *entry)
+{
+ const char *linkname;
+ const char *name;
+ char *p, *pp;
+ struct shar *shar;
+
+ shar = (struct shar *)a->format_data;
+ if (!shar->wrote_header) {
+ archive_strcat(&shar->work, "#!/bin/sh\n");
+ archive_strcat(&shar->work, "# This is a shell archive\n");
+ shar->wrote_header = 1;
+ }
+
+ /* Save the entry for the closing. */
+ if (shar->entry)
+ archive_entry_free(shar->entry);
+ shar->entry = archive_entry_clone(entry);
+ name = archive_entry_pathname(entry);
+
+ /* Handle some preparatory issues. */
+ switch(archive_entry_filetype(entry)) {
+ case AE_IFREG:
+ /* Only regular files have non-zero size. */
+ break;
+ case AE_IFDIR:
+ archive_entry_set_size(entry, 0);
+ /* Don't bother trying to recreate '.' */
+ if (strcmp(name, ".") == 0 || strcmp(name, "./") == 0)
+ return (ARCHIVE_OK);
+ break;
+ case AE_IFIFO:
+ case AE_IFCHR:
+ case AE_IFBLK:
+ /* All other file types have zero size in the archive. */
+ archive_entry_set_size(entry, 0);
+ break;
+ default:
+ archive_entry_set_size(entry, 0);
+ if (archive_entry_hardlink(entry) == NULL &&
+ archive_entry_symlink(entry) == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "shar format cannot archive this");
+ return (ARCHIVE_WARN);
+ }
+ }
+
+ archive_string_empty(&shar->quoted_name);
+ shar_quote(&shar->quoted_name, name, 1);
+
+ /* Stock preparation for all file types. */
+ archive_string_sprintf(&shar->work, "echo x %s\n", shar->quoted_name.s);
+
+ if (archive_entry_filetype(entry) != AE_IFDIR) {
+ /* Try to create the dir. */
+ p = strdup(name);
+ pp = strrchr(p, '/');
+ /* If there is a / character, try to create the dir. */
+ if (pp != NULL) {
+ *pp = '\0';
+
+ /* Try to avoid a lot of redundant mkdir commands. */
+ if (strcmp(p, ".") == 0) {
+ /* Don't try to "mkdir ." */
+ free(p);
+ } else if (shar->last_dir == NULL) {
+ archive_strcat(&shar->work, "mkdir -p ");
+ shar_quote(&shar->work, p, 1);
+ archive_strcat(&shar->work,
+ " > /dev/null 2>&1\n");
+ shar->last_dir = p;
+ } else if (strcmp(p, shar->last_dir) == 0) {
+ /* We've already created this exact dir. */
+ free(p);
+ } else if (strlen(p) < strlen(shar->last_dir) &&
+ strncmp(p, shar->last_dir, strlen(p)) == 0) {
+ /* We've already created a subdir. */
+ free(p);
+ } else {
+ archive_strcat(&shar->work, "mkdir -p ");
+ shar_quote(&shar->work, p, 1);
+ archive_strcat(&shar->work,
+ " > /dev/null 2>&1\n");
+ shar->last_dir = p;
+ }
+ } else {
+ free(p);
+ }
+ }
+
+ /* Handle file-type specific issues. */
+ shar->has_data = 0;
+ if ((linkname = archive_entry_hardlink(entry)) != NULL) {
+ archive_strcat(&shar->work, "ln -f ");
+ shar_quote(&shar->work, linkname, 1);
+ archive_string_sprintf(&shar->work, " %s\n",
+ shar->quoted_name.s);
+ } else if ((linkname = archive_entry_symlink(entry)) != NULL) {
+ archive_strcat(&shar->work, "ln -fs ");
+ shar_quote(&shar->work, linkname, 1);
+ archive_string_sprintf(&shar->work, " %s\n",
+ shar->quoted_name.s);
+ } else {
+ switch(archive_entry_filetype(entry)) {
+ case AE_IFREG:
+ if (archive_entry_size(entry) == 0) {
+ /* More portable than "touch." */
+ archive_string_sprintf(&shar->work,
+ "test -e \"%s\" || :> \"%s\"\n",
+ shar->quoted_name.s, shar->quoted_name.s);
+ } else {
+ if (shar->dump) {
+ unsigned int mode = archive_entry_mode(entry) & 0777;
+ archive_string_sprintf(&shar->work,
+ "uudecode -p > %s << 'SHAR_END'\n",
+ shar->quoted_name.s);
+ archive_string_sprintf(&shar->work,
+ "begin %o ", mode);
+ shar_quote(&shar->work, name, 0);
+ archive_strcat(&shar->work, "\n");
+ } else {
+ archive_string_sprintf(&shar->work,
+ "sed 's/^X//' > %s << 'SHAR_END'\n",
+ shar->quoted_name.s);
+ }
+ shar->has_data = 1;
+ shar->end_of_line = 1;
+ shar->outpos = 0;
+ }
+ break;
+ case AE_IFDIR:
+ archive_string_sprintf(&shar->work,
+ "mkdir -p %s > /dev/null 2>&1\n",
+ shar->quoted_name.s);
+ /* Record that we just created this directory. */
+ if (shar->last_dir != NULL)
+ free(shar->last_dir);
+
+ shar->last_dir = strdup(name);
+ /* Trim a trailing '/'. */
+ pp = strrchr(shar->last_dir, '/');
+ if (pp != NULL && pp[1] == '\0')
+ *pp = '\0';
+ /*
+ * TODO: Put dir name/mode on a list to be fixed
+ * up at end of archive.
+ */
+ break;
+ case AE_IFIFO:
+ archive_string_sprintf(&shar->work,
+ "mkfifo %s\n", shar->quoted_name.s);
+ break;
+ case AE_IFCHR:
+ archive_string_sprintf(&shar->work,
+ "mknod %s c %ju %ju\n", shar->quoted_name.s,
+ (uintmax_t)archive_entry_rdevmajor(entry),
+ (uintmax_t)archive_entry_rdevminor(entry));
+ break;
+ case AE_IFBLK:
+ archive_string_sprintf(&shar->work,
+ "mknod %s b %ju %ju\n", shar->quoted_name.s,
+ (uintmax_t)archive_entry_rdevmajor(entry),
+ (uintmax_t)archive_entry_rdevminor(entry));
+ break;
+ default:
+ return (ARCHIVE_WARN);
+ }
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+archive_write_shar_data_sed(struct archive_write *a, const void *buff, size_t n)
+{
+ static const size_t ensured = 65533;
+ struct shar *shar;
+ const char *src;
+ char *buf, *buf_end;
+ int ret;
+ size_t written = n;
+
+ shar = (struct shar *)a->format_data;
+ if (!shar->has_data || n == 0)
+ return (0);
+
+ src = (const char *)buff;
+
+ /*
+ * ensure is the number of bytes in buffer before expanding the
+ * current character. Each operation writes the current character
+ * and optionally the start-of-new-line marker. This can happen
+ * twice before entering the loop, so make sure three additional
+ * bytes can be written.
+ */
+ if (archive_string_ensure(&shar->work, ensured + 3) == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (shar->work.length > ensured) {
+ ret = __archive_write_output(a, shar->work.s,
+ shar->work.length);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ archive_string_empty(&shar->work);
+ }
+ buf = shar->work.s + shar->work.length;
+ buf_end = shar->work.s + ensured;
+
+ if (shar->end_of_line) {
+ *buf++ = 'X';
+ shar->end_of_line = 0;
+ }
+
+ while (n-- != 0) {
+ if ((*buf++ = *src++) == '\n') {
+ if (n == 0)
+ shar->end_of_line = 1;
+ else
+ *buf++ = 'X';
+ }
+
+ if (buf >= buf_end) {
+ shar->work.length = buf - shar->work.s;
+ ret = __archive_write_output(a, shar->work.s,
+ shar->work.length);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ archive_string_empty(&shar->work);
+ buf = shar->work.s;
+ }
+ }
+
+ shar->work.length = buf - shar->work.s;
+
+ return (written);
+}
+
+#define UUENC(c) (((c)!=0) ? ((c) & 077) + ' ': '`')
+
+static void
+uuencode_group(const char _in[3], char out[4])
+{
+ const unsigned char *in = (const unsigned char *)_in;
+ int t;
+
+ t = (in[0] << 16) | (in[1] << 8) | in[2];
+ out[0] = UUENC( 0x3f & (t >> 18) );
+ out[1] = UUENC( 0x3f & (t >> 12) );
+ out[2] = UUENC( 0x3f & (t >> 6) );
+ out[3] = UUENC( 0x3f & t );
+}
+
+static int
+_uuencode_line(struct archive_write *a, struct shar *shar, const char *inbuf, size_t len)
+{
+ char *buf;
+ size_t alloc_len;
+
+ /* len <= 45 -> expanded to 60 + len byte + new line */
+ alloc_len = shar->work.length + 62;
+ if (archive_string_ensure(&shar->work, alloc_len) == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
+ return (ARCHIVE_FATAL);
+ }
+
+ buf = shar->work.s + shar->work.length;
+ *buf++ = UUENC(len);
+ while (len >= 3) {
+ uuencode_group(inbuf, buf);
+ len -= 3;
+ inbuf += 3;
+ buf += 4;
+ }
+ if (len != 0) {
+ char tmp_buf[3];
+ tmp_buf[0] = inbuf[0];
+ if (len == 1)
+ tmp_buf[1] = '\0';
+ else
+ tmp_buf[1] = inbuf[1];
+ tmp_buf[2] = '\0';
+ uuencode_group(tmp_buf, buf);
+ buf += 4;
+ }
+ *buf++ = '\n';
+ if ((buf - shar->work.s) > (ptrdiff_t)(shar->work.length + 62)) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC, "Buffer overflow");
+ return (ARCHIVE_FATAL);
+ }
+ shar->work.length = buf - shar->work.s;
+ return (ARCHIVE_OK);
+}
+
+#define uuencode_line(__a, __shar, __inbuf, __len) \
+ do { \
+ int r = _uuencode_line(__a, __shar, __inbuf, __len); \
+ if (r != ARCHIVE_OK) \
+ return (ARCHIVE_FATAL); \
+ } while (0)
+
+static ssize_t
+archive_write_shar_data_uuencode(struct archive_write *a, const void *buff,
+ size_t length)
+{
+ struct shar *shar;
+ const char *src;
+ size_t n;
+ int ret;
+
+ shar = (struct shar *)a->format_data;
+ if (!shar->has_data)
+ return (ARCHIVE_OK);
+ src = (const char *)buff;
+
+ if (shar->outpos != 0) {
+ n = 45 - shar->outpos;
+ if (n > length)
+ n = length;
+ memcpy(shar->outbuff + shar->outpos, src, n);
+ if (shar->outpos + n < 45) {
+ shar->outpos += n;
+ return length;
+ }
+ uuencode_line(a, shar, shar->outbuff, 45);
+ src += n;
+ n = length - n;
+ } else {
+ n = length;
+ }
+
+ while (n >= 45) {
+ uuencode_line(a, shar, src, 45);
+ src += 45;
+ n -= 45;
+
+ if (shar->work.length < 65536)
+ continue;
+ ret = __archive_write_output(a, shar->work.s,
+ shar->work.length);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ archive_string_empty(&shar->work);
+ }
+ if (n != 0) {
+ memcpy(shar->outbuff, src, n);
+ shar->outpos = n;
+ }
+ return (length);
+}
+
+static int
+archive_write_shar_finish_entry(struct archive_write *a)
+{
+ const char *g, *p, *u;
+ struct shar *shar;
+ int ret;
+
+ shar = (struct shar *)a->format_data;
+ if (shar->entry == NULL)
+ return (0);
+
+ if (shar->dump) {
+ /* Finish uuencoded data. */
+ if (shar->has_data) {
+ if (shar->outpos > 0)
+ uuencode_line(a, shar, shar->outbuff,
+ shar->outpos);
+ archive_strcat(&shar->work, "`\nend\n");
+ archive_strcat(&shar->work, "SHAR_END\n");
+ }
+ /* Restore file mode, owner, flags. */
+ /*
+ * TODO: Don't immediately restore mode for
+ * directories; defer that to end of script.
+ */
+ archive_string_sprintf(&shar->work, "chmod %o ",
+ (unsigned int)(archive_entry_mode(shar->entry) & 07777));
+ shar_quote(&shar->work, archive_entry_pathname(shar->entry), 1);
+ archive_strcat(&shar->work, "\n");
+
+ u = archive_entry_uname(shar->entry);
+ g = archive_entry_gname(shar->entry);
+ if (u != NULL || g != NULL) {
+ archive_strcat(&shar->work, "chown ");
+ if (u != NULL)
+ shar_quote(&shar->work, u, 1);
+ if (g != NULL) {
+ archive_strcat(&shar->work, ":");
+ shar_quote(&shar->work, g, 1);
+ }
+ archive_strcat(&shar->work, " ");
+ shar_quote(&shar->work,
+ archive_entry_pathname(shar->entry), 1);
+ archive_strcat(&shar->work, "\n");
+ }
+
+ if ((p = archive_entry_fflags_text(shar->entry)) != NULL) {
+ archive_string_sprintf(&shar->work, "chflags %s ", p);
+ shar_quote(&shar->work,
+ archive_entry_pathname(shar->entry), 1);
+ archive_strcat(&shar->work, "\n");
+ }
+
+ /* TODO: restore ACLs */
+
+ } else {
+ if (shar->has_data) {
+ /* Finish sed-encoded data: ensure last line ends. */
+ if (!shar->end_of_line)
+ archive_strappend_char(&shar->work, '\n');
+ archive_strcat(&shar->work, "SHAR_END\n");
+ }
+ }
+
+ archive_entry_free(shar->entry);
+ shar->entry = NULL;
+
+ if (shar->work.length < 65536)
+ return (ARCHIVE_OK);
+
+ ret = __archive_write_output(a, shar->work.s, shar->work.length);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ archive_string_empty(&shar->work);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_shar_close(struct archive_write *a)
+{
+ struct shar *shar;
+ int ret;
+
+ /*
+ * TODO: Accumulate list of directory names/modes and
+ * fix them all up at end-of-archive.
+ */
+
+ shar = (struct shar *)a->format_data;
+
+ /*
+ * Only write the end-of-archive markers if the archive was
+ * actually started. This avoids problems if someone sets
+ * shar format, then sets another format (which would invoke
+ * shar_finish to free the format-specific data).
+ */
+ if (shar->wrote_header == 0)
+ return (ARCHIVE_OK);
+
+ archive_strcat(&shar->work, "exit\n");
+
+ ret = __archive_write_output(a, shar->work.s, shar->work.length);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+
+ /* Shar output is never padded. */
+ archive_write_set_bytes_in_last_block(&a->archive, 1);
+ /*
+ * TODO: shar should also suppress padding of
+ * uncompressed data within gzip/bzip2 streams.
+ */
+
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_shar_free(struct archive_write *a)
+{
+ struct shar *shar;
+
+ shar = (struct shar *)a->format_data;
+ if (shar == NULL)
+ return (ARCHIVE_OK);
+
+ archive_entry_free(shar->entry);
+ free(shar->last_dir);
+ archive_string_free(&(shar->work));
+ archive_string_free(&(shar->quoted_name));
+ free(shar);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_ustar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ustar.c
new file mode 100644
index 0000000000..484ab34b23
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ustar.c
@@ -0,0 +1,764 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2011-2012 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: head/lib/libarchive/archive_write_set_format_ustar.c 191579 2009-04-27 18:35:03Z kientzle $");
+
+
+#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
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+struct ustar {
+ uint64_t entry_bytes_remaining;
+ uint64_t entry_padding;
+
+ struct archive_string_conv *opt_sconv;
+ struct archive_string_conv *sconv_default;
+ int init_default_conversion;
+};
+
+/*
+ * Define structure of POSIX 'ustar' tar header.
+ */
+#define USTAR_name_offset 0
+#define USTAR_name_size 100
+#define USTAR_mode_offset 100
+#define USTAR_mode_size 6
+#define USTAR_mode_max_size 8
+#define USTAR_uid_offset 108
+#define USTAR_uid_size 6
+#define USTAR_uid_max_size 8
+#define USTAR_gid_offset 116
+#define USTAR_gid_size 6
+#define USTAR_gid_max_size 8
+#define USTAR_size_offset 124
+#define USTAR_size_size 11
+#define USTAR_size_max_size 12
+#define USTAR_mtime_offset 136
+#define USTAR_mtime_size 11
+#define USTAR_mtime_max_size 11
+#define USTAR_checksum_offset 148
+#define USTAR_checksum_size 8
+#define USTAR_typeflag_offset 156
+#define USTAR_typeflag_size 1
+#define USTAR_linkname_offset 157
+#define USTAR_linkname_size 100
+#define USTAR_magic_offset 257
+#define USTAR_magic_size 6
+#define USTAR_version_offset 263
+#define USTAR_version_size 2
+#define USTAR_uname_offset 265
+#define USTAR_uname_size 32
+#define USTAR_gname_offset 297
+#define USTAR_gname_size 32
+#define USTAR_rdevmajor_offset 329
+#define USTAR_rdevmajor_size 6
+#define USTAR_rdevmajor_max_size 8
+#define USTAR_rdevminor_offset 337
+#define USTAR_rdevminor_size 6
+#define USTAR_rdevminor_max_size 8
+#define USTAR_prefix_offset 345
+#define USTAR_prefix_size 155
+#define USTAR_padding_offset 500
+#define USTAR_padding_size 12
+
+/*
+ * A filled-in copy of the header for initialization.
+ */
+static const char template_header[] = {
+ /* name: 100 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,
+ /* Mode, space-null termination: 8 bytes */
+ '0','0','0','0','0','0', ' ','\0',
+ /* uid, space-null termination: 8 bytes */
+ '0','0','0','0','0','0', ' ','\0',
+ /* gid, space-null termination: 8 bytes */
+ '0','0','0','0','0','0', ' ','\0',
+ /* size, space termation: 12 bytes */
+ '0','0','0','0','0','0','0','0','0','0','0', ' ',
+ /* mtime, space termation: 12 bytes */
+ '0','0','0','0','0','0','0','0','0','0','0', ' ',
+ /* Initial checksum value: 8 spaces */
+ ' ',' ',' ',' ',' ',' ',' ',' ',
+ /* Typeflag: 1 byte */
+ '0', /* '0' = regular file */
+ /* Linkname: 100 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,
+ /* Magic: 6 bytes, Version: 2 bytes */
+ 'u','s','t','a','r','\0', '0','0',
+ /* Uname: 32 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ /* Gname: 32 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ /* rdevmajor + space/null padding: 8 bytes */
+ '0','0','0','0','0','0', ' ','\0',
+ /* rdevminor + space/null padding: 8 bytes */
+ '0','0','0','0','0','0', ' ','\0',
+ /* Prefix: 155 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,
+ /* Padding: 12 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0
+};
+
+static ssize_t archive_write_ustar_data(struct archive_write *a, const void *buff,
+ size_t s);
+static int archive_write_ustar_free(struct archive_write *);
+static int archive_write_ustar_close(struct archive_write *);
+static int archive_write_ustar_finish_entry(struct archive_write *);
+static int archive_write_ustar_header(struct archive_write *,
+ struct archive_entry *entry);
+static int archive_write_ustar_options(struct archive_write *,
+ const char *, const char *);
+static int format_256(int64_t, char *, int);
+static int format_number(int64_t, char *, int size, int max, int strict);
+static int format_octal(int64_t, char *, int);
+
+/*
+ * Set output format to 'ustar' format.
+ */
+int
+archive_write_set_format_ustar(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct ustar *ustar;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_ustar");
+
+ /* If someone else was already registered, unregister them. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ /* Basic internal sanity test. */
+ if (sizeof(template_header) != 512) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Internal: template_header wrong size: %zu should be 512",
+ sizeof(template_header));
+ return (ARCHIVE_FATAL);
+ }
+
+ ustar = (struct ustar *)malloc(sizeof(*ustar));
+ if (ustar == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ustar data");
+ return (ARCHIVE_FATAL);
+ }
+ memset(ustar, 0, sizeof(*ustar));
+ a->format_data = ustar;
+ a->format_name = "ustar";
+ a->format_options = archive_write_ustar_options;
+ a->format_write_header = archive_write_ustar_header;
+ a->format_write_data = archive_write_ustar_data;
+ a->format_close = archive_write_ustar_close;
+ a->format_free = archive_write_ustar_free;
+ a->format_finish_entry = archive_write_ustar_finish_entry;
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR_USTAR;
+ a->archive.archive_format_name = "POSIX ustar";
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_ustar_options(struct archive_write *a, const char *key,
+ const char *val)
+{
+ struct ustar *ustar = (struct ustar *)a->format_data;
+ int ret = ARCHIVE_FAILED;
+
+ if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s: hdrcharset option needs a character-set name",
+ a->format_name);
+ else {
+ ustar->opt_sconv = archive_string_conversion_to_charset(
+ &a->archive, val, 0);
+ if (ustar->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ }
+
+ /* 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
+archive_write_ustar_header(struct archive_write *a, struct archive_entry *entry)
+{
+ char buff[512];
+ int ret, ret2;
+ struct ustar *ustar;
+ struct archive_entry *entry_main;
+ struct archive_string_conv *sconv;
+
+ ustar = (struct ustar *)a->format_data;
+
+ /* Setup default string conversion. */
+ if (ustar->opt_sconv == NULL) {
+ if (!ustar->init_default_conversion) {
+ ustar->sconv_default =
+ archive_string_default_conversion_for_write(&(a->archive));
+ ustar->init_default_conversion = 1;
+ }
+ sconv = ustar->sconv_default;
+ } else
+ sconv = ustar->opt_sconv;
+
+ /* Sanity check. */
+ if (archive_entry_pathname(entry) == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't record entry in tar file without pathname");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Only regular files (not hardlinks) have data. */
+ if (archive_entry_hardlink(entry) != NULL ||
+ archive_entry_symlink(entry) != NULL ||
+ !(archive_entry_filetype(entry) == AE_IFREG))
+ archive_entry_set_size(entry, 0);
+
+ if (AE_IFDIR == archive_entry_filetype(entry)) {
+ const char *p;
+ size_t path_length;
+ /*
+ * Ensure a trailing '/'. Modify the entry so
+ * the client sees the change.
+ */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ const wchar_t *wp;
+
+ wp = archive_entry_pathname_w(entry);
+ if (wp != NULL && wp[wcslen(wp) -1] != L'/') {
+ struct archive_wstring ws;
+
+ archive_string_init(&ws);
+ path_length = wcslen(wp);
+ if (archive_wstring_ensure(&ws,
+ path_length + 2) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ustar data");
+ archive_wstring_free(&ws);
+ return(ARCHIVE_FATAL);
+ }
+ /* Should we keep '\' ? */
+ if (wp[path_length -1] == L'\\')
+ path_length--;
+ archive_wstrncpy(&ws, wp, path_length);
+ archive_wstrappend_wchar(&ws, L'/');
+ archive_entry_copy_pathname_w(entry, ws.s);
+ archive_wstring_free(&ws);
+ p = NULL;
+ } else
+#endif
+ p = archive_entry_pathname(entry);
+ /*
+ * On Windows, this is a backup operation just in
+ * case getting WCS failed. On POSIX, this is a
+ * normal operation.
+ */
+ if (p != NULL && p[strlen(p) - 1] != '/') {
+ struct archive_string as;
+
+ archive_string_init(&as);
+ path_length = strlen(p);
+ if (archive_string_ensure(&as,
+ path_length + 2) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ustar data");
+ archive_string_free(&as);
+ return(ARCHIVE_FATAL);
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* NOTE: This might break the pathname
+ * if the current code page is CP932 and
+ * the pathname includes a character '\'
+ * as a part of its multibyte pathname. */
+ if (p[strlen(p) -1] == '\\')
+ path_length--;
+ else
+#endif
+ archive_strncpy(&as, p, path_length);
+ archive_strappend_char(&as, '/');
+ archive_entry_copy_pathname(entry, as.s);
+ archive_string_free(&as);
+ }
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Make sure the path separators in pahtname, hardlink and symlink
+ * are all slash '/', not the Windows path separator '\'. */
+ entry_main = __la_win_entry_in_posix_pathseparator(entry);
+ if (entry_main == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate ustar data");
+ return(ARCHIVE_FATAL);
+ }
+ if (entry != entry_main)
+ entry = entry_main;
+ else
+ entry_main = NULL;
+#else
+ entry_main = NULL;
+#endif
+ ret = __archive_write_format_header_ustar(a, buff, entry, -1, 1, sconv);
+ if (ret < ARCHIVE_WARN) {
+ if (entry_main)
+ archive_entry_free(entry_main);
+ return (ret);
+ }
+ ret2 = __archive_write_output(a, buff, 512);
+ if (ret2 < ARCHIVE_WARN) {
+ if (entry_main)
+ archive_entry_free(entry_main);
+ return (ret2);
+ }
+ if (ret2 < ret)
+ ret = ret2;
+
+ ustar->entry_bytes_remaining = archive_entry_size(entry);
+ ustar->entry_padding = 0x1ff & (-(int64_t)ustar->entry_bytes_remaining);
+ if (entry_main)
+ archive_entry_free(entry_main);
+ return (ret);
+}
+
+/*
+ * Format a basic 512-byte "ustar" header.
+ *
+ * Returns -1 if format failed (due to field overflow).
+ * Note that this always formats as much of the header as possible.
+ * If "strict" is set to zero, it will extend numeric fields as
+ * necessary (overwriting terminators or using base-256 extensions).
+ *
+ * This is exported so that other 'tar' formats can use it.
+ */
+int
+__archive_write_format_header_ustar(struct archive_write *a, char h[512],
+ struct archive_entry *entry, int tartype, int strict,
+ struct archive_string_conv *sconv)
+{
+ unsigned int checksum;
+ int i, r, ret;
+ size_t copy_length;
+ const char *p, *pp;
+ int mytartype;
+
+ ret = 0;
+ mytartype = -1;
+ /*
+ * The "template header" already includes the "ustar"
+ * signature, various end-of-field markers and other required
+ * elements.
+ */
+ memcpy(h, &template_header, 512);
+
+ /*
+ * Because the block is already null-filled, and strings
+ * are allowed to exactly fill their destination (without null),
+ * I use memcpy(dest, src, strlen()) here a lot to copy strings.
+ */
+ r = archive_entry_pathname_l(entry, &pp, &copy_length, sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate pathname '%s' to %s",
+ pp, archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ }
+ if (copy_length <= USTAR_name_size)
+ memcpy(h + USTAR_name_offset, pp, copy_length);
+ else {
+ /* Store in two pieces, splitting at a '/'. */
+ p = strchr(pp + copy_length - USTAR_name_size - 1, '/');
+ /*
+ * Look for the next '/' if we chose the first character
+ * as the separator. (ustar format doesn't permit
+ * an empty prefix.)
+ */
+ if (p == pp)
+ p = strchr(p + 1, '/');
+ /* Fail if the name won't fit. */
+ if (!p) {
+ /* No separator. */
+ archive_set_error(&a->archive, ENAMETOOLONG,
+ "Pathname too long");
+ ret = ARCHIVE_FAILED;
+ } else if (p[1] == '\0') {
+ /*
+ * The only feasible separator is a final '/';
+ * this would result in a non-empty prefix and
+ * an empty name, which POSIX doesn't
+ * explicitly forbid, but it just feels wrong.
+ */
+ archive_set_error(&a->archive, ENAMETOOLONG,
+ "Pathname too long");
+ ret = ARCHIVE_FAILED;
+ } else if (p > pp + USTAR_prefix_size) {
+ /* Prefix is too long. */
+ archive_set_error(&a->archive, ENAMETOOLONG,
+ "Pathname too long");
+ ret = ARCHIVE_FAILED;
+ } else {
+ /* Copy prefix and remainder to appropriate places */
+ memcpy(h + USTAR_prefix_offset, pp, p - pp);
+ memcpy(h + USTAR_name_offset, p + 1,
+ pp + copy_length - p - 1);
+ }
+ }
+
+ r = archive_entry_hardlink_l(entry, &p, &copy_length, sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s",
+ p, archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ }
+ if (copy_length > 0)
+ mytartype = '1';
+ else {
+ r = archive_entry_symlink_l(entry, &p, &copy_length, sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s",
+ p, archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ }
+ }
+ if (copy_length > 0) {
+ if (copy_length > USTAR_linkname_size) {
+ archive_set_error(&a->archive, ENAMETOOLONG,
+ "Link contents too long");
+ ret = ARCHIVE_FAILED;
+ copy_length = USTAR_linkname_size;
+ }
+ memcpy(h + USTAR_linkname_offset, p, copy_length);
+ }
+
+ r = archive_entry_uname_l(entry, &p, &copy_length, sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Uname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate uname '%s' to %s",
+ p, archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ }
+ if (copy_length > 0) {
+ if (copy_length > USTAR_uname_size) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Username too long");
+ ret = ARCHIVE_FAILED;
+ copy_length = USTAR_uname_size;
+ }
+ memcpy(h + USTAR_uname_offset, p, copy_length);
+ }
+
+ r = archive_entry_gname_l(entry, &p, &copy_length, sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Gname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate gname '%s' to %s",
+ p, archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ }
+ if (copy_length > 0) {
+ if (strlen(p) > USTAR_gname_size) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Group name too long");
+ ret = ARCHIVE_FAILED;
+ copy_length = USTAR_gname_size;
+ }
+ memcpy(h + USTAR_gname_offset, p, copy_length);
+ }
+
+ if (format_number(archive_entry_mode(entry) & 07777,
+ h + USTAR_mode_offset, USTAR_mode_size, USTAR_mode_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric mode too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_number(archive_entry_uid(entry),
+ h + USTAR_uid_offset, USTAR_uid_size, USTAR_uid_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric user ID too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_number(archive_entry_gid(entry),
+ h + USTAR_gid_offset, USTAR_gid_size, USTAR_gid_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric group ID too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_number(archive_entry_size(entry),
+ h + USTAR_size_offset, USTAR_size_size, USTAR_size_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "File size out of range");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_number(archive_entry_mtime(entry),
+ h + USTAR_mtime_offset, USTAR_mtime_size, USTAR_mtime_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "File modification time too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (archive_entry_filetype(entry) == AE_IFBLK
+ || archive_entry_filetype(entry) == AE_IFCHR) {
+ if (format_number(archive_entry_rdevmajor(entry),
+ h + USTAR_rdevmajor_offset, USTAR_rdevmajor_size,
+ USTAR_rdevmajor_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Major device number too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_number(archive_entry_rdevminor(entry),
+ h + USTAR_rdevminor_offset, USTAR_rdevminor_size,
+ USTAR_rdevminor_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Minor device number too large");
+ ret = ARCHIVE_FAILED;
+ }
+ }
+
+ if (tartype >= 0) {
+ h[USTAR_typeflag_offset] = tartype;
+ } else if (mytartype >= 0) {
+ h[USTAR_typeflag_offset] = mytartype;
+ } else {
+ switch (archive_entry_filetype(entry)) {
+ case AE_IFREG: h[USTAR_typeflag_offset] = '0' ; break;
+ case AE_IFLNK: h[USTAR_typeflag_offset] = '2' ; break;
+ case AE_IFCHR: h[USTAR_typeflag_offset] = '3' ; break;
+ case AE_IFBLK: h[USTAR_typeflag_offset] = '4' ; break;
+ case AE_IFDIR: h[USTAR_typeflag_offset] = '5' ; break;
+ case AE_IFIFO: h[USTAR_typeflag_offset] = '6' ; break;
+ case AE_IFSOCK:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive socket");
+ return (ARCHIVE_FAILED);
+ default:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive this (mode=0%lo)",
+ (unsigned long)archive_entry_mode(entry));
+ ret = ARCHIVE_FAILED;
+ }
+ }
+
+ checksum = 0;
+ for (i = 0; i < 512; i++)
+ checksum += 255 & (unsigned int)h[i];
+ h[USTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */
+ /* h[USTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */
+ format_octal(checksum, h + USTAR_checksum_offset, 6);
+ return (ret);
+}
+
+/*
+ * Format a number into a field, with some intelligence.
+ */
+static int
+format_number(int64_t v, char *p, int s, int maxsize, int strict)
+{
+ int64_t limit;
+
+ limit = ((int64_t)1 << (s*3));
+
+ /* "Strict" only permits octal values with proper termination. */
+ if (strict)
+ return (format_octal(v, p, s));
+
+ /*
+ * In non-strict mode, we allow the number to overwrite one or
+ * more bytes of the field termination. Even old tar
+ * implementations should be able to handle this with no
+ * problem.
+ */
+ if (v >= 0) {
+ while (s <= maxsize) {
+ if (v < limit)
+ return (format_octal(v, p, s));
+ s++;
+ limit <<= 3;
+ }
+ }
+
+ /* Base-256 can handle any number, positive or negative. */
+ return (format_256(v, p, maxsize));
+}
+
+/*
+ * Format a number into the specified field using base-256.
+ */
+static int
+format_256(int64_t v, char *p, int s)
+{
+ p += s;
+ while (s-- > 0) {
+ *--p = (char)(v & 0xff);
+ v >>= 8;
+ }
+ *p |= 0x80; /* Set the base-256 marker bit. */
+ return (0);
+}
+
+/*
+ * Format a number into the specified field.
+ */
+static int
+format_octal(int64_t v, char *p, int s)
+{
+ int len;
+
+ len = s;
+
+ /* Octal values can't be negative, so use 0. */
+ if (v < 0) {
+ while (len-- > 0)
+ *p++ = '0';
+ return (-1);
+ }
+
+ p += s; /* Start at the end and work backwards. */
+ while (s-- > 0) {
+ *--p = (char)('0' + (v & 7));
+ v >>= 3;
+ }
+
+ if (v == 0)
+ return (0);
+
+ /* If it overflowed, fill field with max value. */
+ while (len-- > 0)
+ *p++ = '7';
+
+ return (-1);
+}
+
+static int
+archive_write_ustar_close(struct archive_write *a)
+{
+ return (__archive_write_nulls(a, 512*2));
+}
+
+static int
+archive_write_ustar_free(struct archive_write *a)
+{
+ struct ustar *ustar;
+
+ ustar = (struct ustar *)a->format_data;
+ free(ustar);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_ustar_finish_entry(struct archive_write *a)
+{
+ struct ustar *ustar;
+ int ret;
+
+ ustar = (struct ustar *)a->format_data;
+ ret = __archive_write_nulls(a,
+ (size_t)(ustar->entry_bytes_remaining + ustar->entry_padding));
+ ustar->entry_bytes_remaining = ustar->entry_padding = 0;
+ return (ret);
+}
+
+static ssize_t
+archive_write_ustar_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct ustar *ustar;
+ int ret;
+
+ ustar = (struct ustar *)a->format_data;
+ if (s > ustar->entry_bytes_remaining)
+ s = (size_t)ustar->entry_bytes_remaining;
+ ret = __archive_write_output(a, buff, s);
+ ustar->entry_bytes_remaining -= s;
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ return (s);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_v7tar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_v7tar.c
new file mode 100644
index 0000000000..17efbaf753
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_v7tar.c
@@ -0,0 +1,661 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2011-2012 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
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+struct v7tar {
+ uint64_t entry_bytes_remaining;
+ uint64_t entry_padding;
+
+ struct archive_string_conv *opt_sconv;
+ struct archive_string_conv *sconv_default;
+ int init_default_conversion;
+};
+
+/*
+ * Define structure of POSIX 'v7tar' tar header.
+ */
+#define V7TAR_name_offset 0
+#define V7TAR_name_size 100
+#define V7TAR_mode_offset 100
+#define V7TAR_mode_size 6
+#define V7TAR_mode_max_size 8
+#define V7TAR_uid_offset 108
+#define V7TAR_uid_size 6
+#define V7TAR_uid_max_size 8
+#define V7TAR_gid_offset 116
+#define V7TAR_gid_size 6
+#define V7TAR_gid_max_size 8
+#define V7TAR_size_offset 124
+#define V7TAR_size_size 11
+#define V7TAR_size_max_size 12
+#define V7TAR_mtime_offset 136
+#define V7TAR_mtime_size 11
+#define V7TAR_mtime_max_size 12
+#define V7TAR_checksum_offset 148
+#define V7TAR_checksum_size 8
+#define V7TAR_typeflag_offset 156
+#define V7TAR_typeflag_size 1
+#define V7TAR_linkname_offset 157
+#define V7TAR_linkname_size 100
+#define V7TAR_padding_offset 257
+#define V7TAR_padding_size 255
+
+/*
+ * A filled-in copy of the header for initialization.
+ */
+static const char template_header[] = {
+ /* name: 100 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,
+ /* Mode, space-null termination: 8 bytes */
+ '0','0','0','0','0','0', ' ','\0',
+ /* uid, space-null termination: 8 bytes */
+ '0','0','0','0','0','0', ' ','\0',
+ /* gid, space-null termination: 8 bytes */
+ '0','0','0','0','0','0', ' ','\0',
+ /* size, space termation: 12 bytes */
+ '0','0','0','0','0','0','0','0','0','0','0', ' ',
+ /* mtime, space termation: 12 bytes */
+ '0','0','0','0','0','0','0','0','0','0','0', ' ',
+ /* Initial checksum value: 8 spaces */
+ ' ',' ',' ',' ',' ',' ',' ',' ',
+ /* Typeflag: 1 byte */
+ 0,
+ /* Linkname: 100 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,
+ /* Padding: 255 bytes */
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0
+};
+
+static ssize_t archive_write_v7tar_data(struct archive_write *a, const void *buff,
+ size_t s);
+static int archive_write_v7tar_free(struct archive_write *);
+static int archive_write_v7tar_close(struct archive_write *);
+static int archive_write_v7tar_finish_entry(struct archive_write *);
+static int archive_write_v7tar_header(struct archive_write *,
+ struct archive_entry *entry);
+static int archive_write_v7tar_options(struct archive_write *,
+ const char *, const char *);
+static int format_256(int64_t, char *, int);
+static int format_number(int64_t, char *, int size, int max, int strict);
+static int format_octal(int64_t, char *, int);
+static int format_header_v7tar(struct archive_write *, char h[512],
+ struct archive_entry *, int, struct archive_string_conv *);
+
+/*
+ * Set output format to 'v7tar' format.
+ */
+int
+archive_write_set_format_v7tar(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct v7tar *v7tar;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_v7tar");
+
+ /* If someone else was already registered, unregister them. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ /* Basic internal sanity test. */
+ if (sizeof(template_header) != 512) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Internal: template_header wrong size: %zu should be 512",
+ sizeof(template_header));
+ return (ARCHIVE_FATAL);
+ }
+
+ v7tar = (struct v7tar *)malloc(sizeof(*v7tar));
+ if (v7tar == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate v7tar data");
+ return (ARCHIVE_FATAL);
+ }
+ memset(v7tar, 0, sizeof(*v7tar));
+ a->format_data = v7tar;
+ a->format_name = "tar (non-POSIX)";
+ a->format_options = archive_write_v7tar_options;
+ a->format_write_header = archive_write_v7tar_header;
+ a->format_write_data = archive_write_v7tar_data;
+ a->format_close = archive_write_v7tar_close;
+ a->format_free = archive_write_v7tar_free;
+ a->format_finish_entry = archive_write_v7tar_finish_entry;
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR;
+ a->archive.archive_format_name = "tar (non-POSIX)";
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_v7tar_options(struct archive_write *a, const char *key,
+ const char *val)
+{
+ struct v7tar *v7tar = (struct v7tar *)a->format_data;
+ int ret = ARCHIVE_FAILED;
+
+ if (strcmp(key, "hdrcharset") == 0) {
+ if (val == NULL || val[0] == 0)
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s: hdrcharset option needs a character-set name",
+ a->format_name);
+ else {
+ v7tar->opt_sconv = archive_string_conversion_to_charset(
+ &a->archive, val, 0);
+ if (v7tar->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ }
+
+ /* 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
+archive_write_v7tar_header(struct archive_write *a, struct archive_entry *entry)
+{
+ char buff[512];
+ int ret, ret2;
+ struct v7tar *v7tar;
+ struct archive_entry *entry_main;
+ struct archive_string_conv *sconv;
+
+ v7tar = (struct v7tar *)a->format_data;
+
+ /* Setup default string conversion. */
+ if (v7tar->opt_sconv == NULL) {
+ if (!v7tar->init_default_conversion) {
+ v7tar->sconv_default =
+ archive_string_default_conversion_for_write(
+ &(a->archive));
+ v7tar->init_default_conversion = 1;
+ }
+ sconv = v7tar->sconv_default;
+ } else
+ sconv = v7tar->opt_sconv;
+
+ /* Sanity check. */
+ if (archive_entry_pathname(entry) == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can't record entry in tar file without pathname");
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Only regular files (not hardlinks) have data. */
+ if (archive_entry_hardlink(entry) != NULL ||
+ archive_entry_symlink(entry) != NULL ||
+ !(archive_entry_filetype(entry) == AE_IFREG))
+ archive_entry_set_size(entry, 0);
+
+ if (AE_IFDIR == archive_entry_filetype(entry)) {
+ const char *p;
+ size_t path_length;
+ /*
+ * Ensure a trailing '/'. Modify the entry so
+ * the client sees the change.
+ */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ const wchar_t *wp;
+
+ wp = archive_entry_pathname_w(entry);
+ if (wp != NULL && wp[wcslen(wp) -1] != L'/') {
+ struct archive_wstring ws;
+
+ archive_string_init(&ws);
+ path_length = wcslen(wp);
+ if (archive_wstring_ensure(&ws,
+ path_length + 2) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate v7tar data");
+ archive_wstring_free(&ws);
+ return(ARCHIVE_FATAL);
+ }
+ /* Should we keep '\' ? */
+ if (wp[path_length -1] == L'\\')
+ path_length--;
+ archive_wstrncpy(&ws, wp, path_length);
+ archive_wstrappend_wchar(&ws, L'/');
+ archive_entry_copy_pathname_w(entry, ws.s);
+ archive_wstring_free(&ws);
+ p = NULL;
+ } else
+#endif
+ p = archive_entry_pathname(entry);
+ /*
+ * On Windows, this is a backup operation just in
+ * case getting WCS failed. On POSIX, this is a
+ * normal operation.
+ */
+ if (p != NULL && p[strlen(p) - 1] != '/') {
+ struct archive_string as;
+
+ archive_string_init(&as);
+ path_length = strlen(p);
+ if (archive_string_ensure(&as,
+ path_length + 2) == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate v7tar data");
+ archive_string_free(&as);
+ return(ARCHIVE_FATAL);
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* NOTE: This might break the pathname
+ * if the current code page is CP932 and
+ * the pathname includes a character '\'
+ * as a part of its multibyte pathname. */
+ if (p[strlen(p) -1] == '\\')
+ path_length--;
+ else
+#endif
+ archive_strncpy(&as, p, path_length);
+ archive_strappend_char(&as, '/');
+ archive_entry_copy_pathname(entry, as.s);
+ archive_string_free(&as);
+ }
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Make sure the path separators in pahtname, hardlink and symlink
+ * are all slash '/', not the Windows path separator '\'. */
+ entry_main = __la_win_entry_in_posix_pathseparator(entry);
+ if (entry_main == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate v7tar data");
+ return(ARCHIVE_FATAL);
+ }
+ if (entry != entry_main)
+ entry = entry_main;
+ else
+ entry_main = NULL;
+#else
+ entry_main = NULL;
+#endif
+ ret = format_header_v7tar(a, buff, entry, 1, sconv);
+ if (ret < ARCHIVE_WARN) {
+ if (entry_main)
+ archive_entry_free(entry_main);
+ return (ret);
+ }
+ ret2 = __archive_write_output(a, buff, 512);
+ if (ret2 < ARCHIVE_WARN) {
+ if (entry_main)
+ archive_entry_free(entry_main);
+ return (ret2);
+ }
+ if (ret2 < ret)
+ ret = ret2;
+
+ v7tar->entry_bytes_remaining = archive_entry_size(entry);
+ v7tar->entry_padding = 0x1ff & (-(int64_t)v7tar->entry_bytes_remaining);
+ if (entry_main)
+ archive_entry_free(entry_main);
+ return (ret);
+}
+
+/*
+ * Format a basic 512-byte "v7tar" header.
+ *
+ * Returns -1 if format failed (due to field overflow).
+ * Note that this always formats as much of the header as possible.
+ * If "strict" is set to zero, it will extend numeric fields as
+ * necessary (overwriting terminators or using base-256 extensions).
+ *
+ */
+static int
+format_header_v7tar(struct archive_write *a, char h[512],
+ struct archive_entry *entry, int strict,
+ struct archive_string_conv *sconv)
+{
+ unsigned int checksum;
+ int i, r, ret;
+ size_t copy_length;
+ const char *p, *pp;
+ int mytartype;
+
+ ret = 0;
+ mytartype = -1;
+ /*
+ * The "template header" already includes the "v7tar"
+ * signature, various end-of-field markers and other required
+ * elements.
+ */
+ memcpy(h, &template_header, 512);
+
+ /*
+ * Because the block is already null-filled, and strings
+ * are allowed to exactly fill their destination (without null),
+ * I use memcpy(dest, src, strlen()) here a lot to copy strings.
+ */
+ r = archive_entry_pathname_l(entry, &pp, &copy_length, sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate pathname '%s' to %s",
+ pp, archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ }
+ if (strict && copy_length < V7TAR_name_size)
+ memcpy(h + V7TAR_name_offset, pp, copy_length);
+ else if (!strict && copy_length <= V7TAR_name_size)
+ memcpy(h + V7TAR_name_offset, pp, copy_length);
+ else {
+ /* Prefix is too long. */
+ archive_set_error(&a->archive, ENAMETOOLONG,
+ "Pathname too long");
+ ret = ARCHIVE_FAILED;
+ }
+
+ r = archive_entry_hardlink_l(entry, &p, &copy_length, sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s",
+ p, archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ }
+ if (copy_length > 0)
+ mytartype = '1';
+ else {
+ r = archive_entry_symlink_l(entry, &p, &copy_length, sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate linkname '%s' to %s",
+ p, archive_string_conversion_charset_name(sconv));
+ ret = ARCHIVE_WARN;
+ }
+ }
+ if (copy_length > 0) {
+ if (copy_length >= V7TAR_linkname_size) {
+ archive_set_error(&a->archive, ENAMETOOLONG,
+ "Link contents too long");
+ ret = ARCHIVE_FAILED;
+ copy_length = V7TAR_linkname_size;
+ }
+ memcpy(h + V7TAR_linkname_offset, p, copy_length);
+ }
+
+ if (format_number(archive_entry_mode(entry) & 07777,
+ h + V7TAR_mode_offset, V7TAR_mode_size,
+ V7TAR_mode_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric mode too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_number(archive_entry_uid(entry),
+ h + V7TAR_uid_offset, V7TAR_uid_size, V7TAR_uid_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric user ID too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_number(archive_entry_gid(entry),
+ h + V7TAR_gid_offset, V7TAR_gid_size, V7TAR_gid_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "Numeric group ID too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_number(archive_entry_size(entry),
+ h + V7TAR_size_offset, V7TAR_size_size,
+ V7TAR_size_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "File size out of range");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (format_number(archive_entry_mtime(entry),
+ h + V7TAR_mtime_offset, V7TAR_mtime_size,
+ V7TAR_mtime_max_size, strict)) {
+ archive_set_error(&a->archive, ERANGE,
+ "File modification time too large");
+ ret = ARCHIVE_FAILED;
+ }
+
+ if (mytartype >= 0) {
+ h[V7TAR_typeflag_offset] = mytartype;
+ } else {
+ switch (archive_entry_filetype(entry)) {
+ case AE_IFREG: case AE_IFDIR:
+ break;
+ case AE_IFLNK:
+ h[V7TAR_typeflag_offset] = '2';
+ break;
+ case AE_IFCHR:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive character device");
+ return (ARCHIVE_FAILED);
+ case AE_IFBLK:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive block device");
+ return (ARCHIVE_FAILED);
+ case AE_IFIFO:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive fifo");
+ return (ARCHIVE_FAILED);
+ case AE_IFSOCK:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive socket");
+ return (ARCHIVE_FAILED);
+ default:
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "tar format cannot archive this (mode=0%lo)",
+ (unsigned long)archive_entry_mode(entry));
+ ret = ARCHIVE_FAILED;
+ }
+ }
+
+ checksum = 0;
+ for (i = 0; i < 512; i++)
+ checksum += 255 & (unsigned int)h[i];
+ format_octal(checksum, h + V7TAR_checksum_offset, 6);
+ /* Can't be pre-set in the template. */
+ h[V7TAR_checksum_offset + 6] = '\0';
+ return (ret);
+}
+
+/*
+ * Format a number into a field, with some intelligence.
+ */
+static int
+format_number(int64_t v, char *p, int s, int maxsize, int strict)
+{
+ int64_t limit;
+
+ limit = ((int64_t)1 << (s*3));
+
+ /* "Strict" only permits octal values with proper termination. */
+ if (strict)
+ return (format_octal(v, p, s));
+
+ /*
+ * In non-strict mode, we allow the number to overwrite one or
+ * more bytes of the field termination. Even old tar
+ * implementations should be able to handle this with no
+ * problem.
+ */
+ if (v >= 0) {
+ while (s <= maxsize) {
+ if (v < limit)
+ return (format_octal(v, p, s));
+ s++;
+ limit <<= 3;
+ }
+ }
+
+ /* Base-256 can handle any number, positive or negative. */
+ return (format_256(v, p, maxsize));
+}
+
+/*
+ * Format a number into the specified field using base-256.
+ */
+static int
+format_256(int64_t v, char *p, int s)
+{
+ p += s;
+ while (s-- > 0) {
+ *--p = (char)(v & 0xff);
+ v >>= 8;
+ }
+ *p |= 0x80; /* Set the base-256 marker bit. */
+ return (0);
+}
+
+/*
+ * Format a number into the specified field.
+ */
+static int
+format_octal(int64_t v, char *p, int s)
+{
+ int len;
+
+ len = s;
+
+ /* Octal values can't be negative, so use 0. */
+ if (v < 0) {
+ while (len-- > 0)
+ *p++ = '0';
+ return (-1);
+ }
+
+ p += s; /* Start at the end and work backwards. */
+ while (s-- > 0) {
+ *--p = (char)('0' + (v & 7));
+ v >>= 3;
+ }
+
+ if (v == 0)
+ return (0);
+
+ /* If it overflowed, fill field with max value. */
+ while (len-- > 0)
+ *p++ = '7';
+
+ return (-1);
+}
+
+static int
+archive_write_v7tar_close(struct archive_write *a)
+{
+ return (__archive_write_nulls(a, 512*2));
+}
+
+static int
+archive_write_v7tar_free(struct archive_write *a)
+{
+ struct v7tar *v7tar;
+
+ v7tar = (struct v7tar *)a->format_data;
+ free(v7tar);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_v7tar_finish_entry(struct archive_write *a)
+{
+ struct v7tar *v7tar;
+ int ret;
+
+ v7tar = (struct v7tar *)a->format_data;
+ ret = __archive_write_nulls(a,
+ (size_t)(v7tar->entry_bytes_remaining + v7tar->entry_padding));
+ v7tar->entry_bytes_remaining = v7tar->entry_padding = 0;
+ return (ret);
+}
+
+static ssize_t
+archive_write_v7tar_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct v7tar *v7tar;
+ int ret;
+
+ v7tar = (struct v7tar *)a->format_data;
+ if (s > v7tar->entry_bytes_remaining)
+ s = (size_t)v7tar->entry_bytes_remaining;
+ ret = __archive_write_output(a, buff, s);
+ v7tar->entry_bytes_remaining -= s;
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ return (s);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c
new file mode 100644
index 0000000000..4cd2b9d7ff
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c
@@ -0,0 +1,3181 @@
+/*-
+ * Copyright (c) 2010-2012 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
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#include <stdlib.h>
+#if HAVE_LIBXML_XMLWRITER_H
+#include <libxml/xmlwriter.h>
+#endif
+#ifdef HAVE_BZLIB_H
+#include <cm_bzlib.h>
+#endif
+#if HAVE_LZMA_H
+#include <cm_lzma.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_crypto_private.h"
+#include "archive_endian.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_rb.h"
+#include "archive_string.h"
+#include "archive_write_private.h"
+
+/*
+ * Differences to xar utility.
+ * - Subdocument is not supported yet.
+ * - ACL is not supported yet.
+ * - When writing an XML element <link type="<file-type>">, <file-type>
+ * which is a file type a symbolic link is referencing is always marked
+ * as "broken". Xar utility uses stat(2) to get the file type, but, in
+ * libarcive format writer, we should not use it; if it is needed, we
+ * should get about it at archive_read_disk.c.
+ * - It is possible to appear both <flags> and <ext2> elements.
+ * Xar utility generates <flags> on BSD platform and <ext2> on Linux
+ * platform.
+ *
+ */
+
+#if !(defined(HAVE_LIBXML_XMLWRITER_H) && defined(LIBXML_VERSION) &&\
+ LIBXML_VERSION >= 20703) ||\
+ !defined(HAVE_ZLIB_H) || \
+ !defined(ARCHIVE_HAS_MD5) || !defined(ARCHIVE_HAS_SHA1)
+/*
+ * xar needs several external libraries.
+ * o libxml2
+ * o openssl or MD5/SHA1 hash function
+ * o zlib
+ * o bzlib2 (option)
+ * o liblzma (option)
+ */
+int
+archive_write_set_format_xar(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Xar not supported on this platform");
+ return (ARCHIVE_WARN);
+}
+
+#else /* Support xar format */
+
+/*#define DEBUG_PRINT_TOC 1 */
+
+#define BAD_CAST_CONST (const xmlChar *)
+
+#define HEADER_MAGIC 0x78617221
+#define HEADER_SIZE 28
+#define HEADER_VERSION 1
+
+enum sumalg {
+ CKSUM_NONE = 0,
+ CKSUM_SHA1 = 1,
+ CKSUM_MD5 = 2
+};
+
+#define MD5_SIZE 16
+#define SHA1_SIZE 20
+#define MAX_SUM_SIZE 20
+#define MD5_NAME "md5"
+#define SHA1_NAME "sha1"
+
+enum enctype {
+ NONE,
+ GZIP,
+ BZIP2,
+ LZMA,
+ XZ,
+};
+
+struct chksumwork {
+ enum sumalg alg;
+#ifdef ARCHIVE_HAS_MD5
+ archive_md5_ctx md5ctx;
+#endif
+#ifdef ARCHIVE_HAS_SHA1
+ archive_sha1_ctx sha1ctx;
+#endif
+};
+
+enum la_zaction {
+ ARCHIVE_Z_FINISH,
+ ARCHIVE_Z_RUN
+};
+
+/*
+ * Universal zstream.
+ */
+struct la_zstream {
+ const unsigned char *next_in;
+ size_t avail_in;
+ uint64_t total_in;
+
+ unsigned char *next_out;
+ size_t avail_out;
+ uint64_t total_out;
+
+ int valid;
+ void *real_stream;
+ int (*code) (struct archive *a,
+ struct la_zstream *lastrm,
+ enum la_zaction action);
+ int (*end)(struct archive *a,
+ struct la_zstream *lastrm);
+};
+
+struct chksumval {
+ enum sumalg alg;
+ size_t len;
+ unsigned char val[MAX_SUM_SIZE];
+};
+
+struct heap_data {
+ int id;
+ struct heap_data *next;
+ uint64_t temp_offset;
+ uint64_t length; /* archived size. */
+ uint64_t size; /* extracted size. */
+ enum enctype compression;
+ struct chksumval a_sum; /* archived checksum. */
+ struct chksumval e_sum; /* extracted checksum. */
+};
+
+struct file {
+ struct archive_rb_node rbnode;
+
+ int id;
+ struct archive_entry *entry;
+
+ struct archive_rb_tree rbtree;
+ struct file *next;
+ struct file *chnext;
+ struct file *hlnext;
+ /* For hardlinked files.
+ * Use only when archive_entry_nlink() > 1 */
+ struct file *hardlink_target;
+ struct file *parent; /* parent directory entry */
+ /*
+ * To manage sub directory files.
+ * We use 'chnext' a menber of struct file to chain.
+ */
+ struct {
+ struct file *first;
+ struct file **last;
+ } children;
+
+ /* For making a directory tree. */
+ struct archive_string parentdir;
+ struct archive_string basename;
+ struct archive_string symlink;
+
+ int ea_idx;
+ struct {
+ struct heap_data *first;
+ struct heap_data **last;
+ } xattr;
+ struct heap_data data;
+ struct archive_string script;
+
+ int virtual:1;
+ int dir:1;
+};
+
+struct hardlink {
+ struct archive_rb_node rbnode;
+ int nlink;
+ struct {
+ struct file *first;
+ struct file **last;
+ } file_list;
+};
+
+struct xar {
+ int temp_fd;
+ uint64_t temp_offset;
+
+ int file_idx;
+ struct file *root;
+ struct file *cur_dirent;
+ struct archive_string cur_dirstr;
+ struct file *cur_file;
+ uint64_t bytes_remaining;
+ struct archive_string tstr;
+ struct archive_string vstr;
+
+ enum sumalg opt_toc_sumalg;
+ enum sumalg opt_sumalg;
+ enum enctype opt_compression;
+ int opt_compression_level;
+
+ struct chksumwork a_sumwrk; /* archived checksum. */
+ struct chksumwork e_sumwrk; /* extracted checksum. */
+ struct la_zstream stream;
+ struct archive_string_conv *sconv;
+ /*
+ * Compressed data buffer.
+ */
+ unsigned char wbuff[1024 * 64];
+ size_t wbuff_remaining;
+
+ struct heap_data toc;
+ /*
+ * The list of all file entries is used to manage struct file
+ * objects.
+ * We use 'next' a menber of struct file to chain.
+ */
+ struct {
+ struct file *first;
+ struct file **last;
+ } file_list;
+ /*
+ * The list of hard-linked file entries.
+ * We use 'hlnext' a menber of struct file to chain.
+ */
+ struct archive_rb_tree hardlink_rbtree;
+};
+
+static int xar_options(struct archive_write *,
+ const char *, const char *);
+static int xar_write_header(struct archive_write *,
+ struct archive_entry *);
+static ssize_t xar_write_data(struct archive_write *,
+ const void *, size_t);
+static int xar_finish_entry(struct archive_write *);
+static int xar_close(struct archive_write *);
+static int xar_free(struct archive_write *);
+
+static struct file *file_new(struct archive_write *a, struct archive_entry *);
+static void file_free(struct file *);
+static struct file *file_create_virtual_dir(struct archive_write *a, struct xar *,
+ const char *);
+static int file_add_child_tail(struct file *, struct file *);
+static struct file *file_find_child(struct file *, const char *);
+static int file_gen_utility_names(struct archive_write *,
+ struct file *);
+static int get_path_component(char *, int, const char *);
+static int file_tree(struct archive_write *, struct file **);
+static void file_register(struct xar *, struct file *);
+static void file_init_register(struct xar *);
+static void file_free_register(struct xar *);
+static int file_register_hardlink(struct archive_write *,
+ struct file *);
+static void file_connect_hardlink_files(struct xar *);
+static void file_init_hardlinks(struct xar *);
+static void file_free_hardlinks(struct xar *);
+
+static void checksum_init(struct chksumwork *, enum sumalg);
+static void checksum_update(struct chksumwork *, const void *, size_t);
+static void checksum_final(struct chksumwork *, struct chksumval *);
+static int compression_init_encoder_gzip(struct archive *,
+ struct la_zstream *, int, int);
+static int compression_code_gzip(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end_gzip(struct archive *, struct la_zstream *);
+static int compression_init_encoder_bzip2(struct archive *,
+ struct la_zstream *, int);
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+static int compression_code_bzip2(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end_bzip2(struct archive *, struct la_zstream *);
+#endif
+static int compression_init_encoder_lzma(struct archive *,
+ struct la_zstream *, int);
+static int compression_init_encoder_xz(struct archive *,
+ struct la_zstream *, int);
+#if defined(HAVE_LZMA_H)
+static int compression_code_lzma(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end_lzma(struct archive *, struct la_zstream *);
+#endif
+static int xar_compression_init_encoder(struct archive_write *);
+static int compression_code(struct archive *,
+ struct la_zstream *, enum la_zaction);
+static int compression_end(struct archive *,
+ struct la_zstream *);
+static int save_xattrs(struct archive_write *, struct file *);
+static int getalgsize(enum sumalg);
+static const char *getalgname(enum sumalg);
+
+int
+archive_write_set_format_xar(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct xar *xar;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_xar");
+
+ /* If another format was already registered, unregister it. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ xar = calloc(1, sizeof(*xar));
+ if (xar == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate xar data");
+ return (ARCHIVE_FATAL);
+ }
+ xar->temp_fd = -1;
+ file_init_register(xar);
+ file_init_hardlinks(xar);
+ archive_string_init(&(xar->tstr));
+ archive_string_init(&(xar->vstr));
+
+ /*
+ * Create the root directory.
+ */
+ xar->root = file_create_virtual_dir(a, xar, "");
+ if (xar->root == NULL) {
+ free(xar);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate xar data");
+ return (ARCHIVE_FATAL);
+ }
+ xar->root->parent = xar->root;
+ file_register(xar, xar->root);
+ xar->cur_dirent = xar->root;
+ archive_string_init(&(xar->cur_dirstr));
+ archive_string_ensure(&(xar->cur_dirstr), 1);
+ xar->cur_dirstr.s[0] = 0;
+
+ /*
+ * Initialize option.
+ */
+ /* Set default checksum type. */
+ xar->opt_toc_sumalg = CKSUM_SHA1;
+ xar->opt_sumalg = CKSUM_SHA1;
+ /* Set default compression type and level. */
+ xar->opt_compression = GZIP;
+ xar->opt_compression_level = 6;
+
+ a->format_data = xar;
+
+ a->format_name = "xar";
+ a->format_options = xar_options;
+ a->format_write_header = xar_write_header;
+ a->format_write_data = xar_write_data;
+ a->format_finish_entry = xar_finish_entry;
+ a->format_close = xar_close;
+ a->format_free = xar_free;
+ a->archive.archive_format = ARCHIVE_FORMAT_XAR;
+ a->archive.archive_format_name = "xar";
+
+ return (ARCHIVE_OK);
+}
+
+static int
+xar_options(struct archive_write *a, const char *key, const char *value)
+{
+ struct xar *xar;
+
+ xar = (struct xar *)a->format_data;
+
+ if (strcmp(key, "checksum") == 0) {
+ if (value == NULL)
+ xar->opt_sumalg = CKSUM_NONE;
+ else if (strcmp(value, "sha1") == 0)
+ xar->opt_sumalg = CKSUM_SHA1;
+ else if (strcmp(value, "md5") == 0)
+ xar->opt_sumalg = CKSUM_MD5;
+ else {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Unknown checksum name: `%s'",
+ value);
+ return (ARCHIVE_FAILED);
+ }
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "compression") == 0) {
+ const char *name = NULL;
+
+ if (value == NULL)
+ xar->opt_compression = NONE;
+ else if (strcmp(value, "gzip") == 0)
+ xar->opt_compression = GZIP;
+ else if (strcmp(value, "bzip2") == 0)
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+ xar->opt_compression = BZIP2;
+#else
+ name = "bzip2";
+#endif
+ else if (strcmp(value, "lzma") == 0)
+#if HAVE_LZMA_H
+ xar->opt_compression = LZMA;
+#else
+ name = "lzma";
+#endif
+ else if (strcmp(value, "xz") == 0)
+#if HAVE_LZMA_H
+ xar->opt_compression = XZ;
+#else
+ name = "xz";
+#endif
+ else {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Unknown compression name: `%s'",
+ value);
+ return (ARCHIVE_FAILED);
+ }
+ if (name != NULL) {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "`%s' compression not supported "
+ "on this platform",
+ name);
+ return (ARCHIVE_FAILED);
+ }
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "compression-level") == 0) {
+ if (value == NULL ||
+ !(value[0] >= '0' && value[0] <= '9') ||
+ value[1] != '\0') {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Illegal value `%s'",
+ value);
+ return (ARCHIVE_FAILED);
+ }
+ xar->opt_compression_level = value[0] - '0';
+ return (ARCHIVE_OK);
+ }
+ if (strcmp(key, "toc-checksum") == 0) {
+ if (value == NULL)
+ xar->opt_toc_sumalg = CKSUM_NONE;
+ else if (strcmp(value, "sha1") == 0)
+ xar->opt_toc_sumalg = CKSUM_SHA1;
+ else if (strcmp(value, "md5") == 0)
+ xar->opt_toc_sumalg = CKSUM_MD5;
+ else {
+ archive_set_error(&(a->archive),
+ ARCHIVE_ERRNO_MISC,
+ "Unknown checksum name: `%s'",
+ value);
+ return (ARCHIVE_FAILED);
+ }
+ 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
+xar_write_header(struct archive_write *a, struct archive_entry *entry)
+{
+ struct xar *xar;
+ struct file *file;
+ struct archive_entry *file_entry;
+ int r, r2;
+
+ xar = (struct xar *)a->format_data;
+ xar->cur_file = NULL;
+ xar->bytes_remaining = 0;
+
+ if (xar->sconv == NULL) {
+ xar->sconv = archive_string_conversion_to_charset(
+ &a->archive, "UTF-8", 1);
+ if (xar->sconv == NULL)
+ return (ARCHIVE_FATAL);
+ }
+
+ file = file_new(a, entry);
+ if (file == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate data");
+ return (ARCHIVE_FATAL);
+ }
+ r2 = file_gen_utility_names(a, file);
+ if (r2 < ARCHIVE_WARN)
+ return (r2);
+
+ /*
+ * Ignore a path which looks like the top of directory name
+ * since we have already made the root directory of an Xar archive.
+ */
+ if (archive_strlen(&(file->parentdir)) == 0 &&
+ archive_strlen(&(file->basename)) == 0) {
+ file_free(file);
+ return (r2);
+ }
+
+ /* Add entry into tree */
+ file_entry = file->entry;
+ r = file_tree(a, &file);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /* There is the same file in tree and
+ * the current file is older than the file in tree.
+ * So we don't need the current file data anymore. */
+ if (file->entry != file_entry)
+ return (r2);
+ if (file->id == 0)
+ file_register(xar, file);
+
+ /* A virtual file, which is a directory, does not have
+ * any contents and we won't store it into a archive
+ * file other than its name. */
+ if (file->virtual)
+ return (r2);
+
+ /*
+ * Prepare to save the contents of the file.
+ */
+ if (xar->temp_fd == -1) {
+ int algsize;
+ xar->temp_offset = 0;
+ xar->temp_fd = __archive_mktemp(NULL);
+ if (xar->temp_fd < 0) {
+ archive_set_error(&a->archive, errno,
+ "Couldn't create temporary file");
+ return (ARCHIVE_FATAL);
+ }
+ algsize = getalgsize(xar->opt_toc_sumalg);
+ if (algsize > 0) {
+ if (lseek(xar->temp_fd, algsize, SEEK_SET) < 0) {
+ archive_set_error(&(a->archive), errno,
+ "lseek failed");
+ return (ARCHIVE_FATAL);
+ }
+ xar->temp_offset = algsize;
+ }
+ }
+
+ if (archive_entry_hardlink(file->entry) == NULL) {
+ r = save_xattrs(a, file);
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Non regular files contents are unneeded to be saved to
+ * a temporary file. */
+ if (archive_entry_filetype(file->entry) != AE_IFREG)
+ return (r2);
+
+ /*
+ * Set the current file to cur_file to read its contents.
+ */
+ xar->cur_file = file;
+
+ if (archive_entry_nlink(file->entry) > 1) {
+ r = file_register_hardlink(a, file);
+ if (r != ARCHIVE_OK)
+ return (r);
+ if (archive_entry_hardlink(file->entry) != NULL) {
+ archive_entry_unset_size(file->entry);
+ return (r2);
+ }
+ }
+
+ /* Save a offset of current file in temporary file. */
+ file->data.temp_offset = xar->temp_offset;
+ file->data.size = archive_entry_size(file->entry);
+ file->data.compression = xar->opt_compression;
+ xar->bytes_remaining = archive_entry_size(file->entry);
+ checksum_init(&(xar->a_sumwrk), xar->opt_sumalg);
+ checksum_init(&(xar->e_sumwrk), xar->opt_sumalg);
+ r = xar_compression_init_encoder(a);
+
+ if (r != ARCHIVE_OK)
+ return (r);
+ else
+ return (r2);
+}
+
+static int
+write_to_temp(struct archive_write *a, const void *buff, size_t s)
+{
+ struct xar *xar;
+ const unsigned char *p;
+ ssize_t ws;
+
+ xar = (struct xar *)a->format_data;
+ p = (const unsigned char *)buff;
+ while (s) {
+ ws = write(xar->temp_fd, p, s);
+ if (ws < 0) {
+ archive_set_error(&(a->archive), errno,
+ "fwrite function failed");
+ return (ARCHIVE_FATAL);
+ }
+ s -= ws;
+ p += ws;
+ xar->temp_offset += ws;
+ }
+ return (ARCHIVE_OK);
+}
+
+static ssize_t
+xar_write_data(struct archive_write *a, const void *buff, size_t s)
+{
+ struct xar *xar;
+ enum la_zaction run;
+ size_t size, rsize;
+ int r;
+
+ xar = (struct xar *)a->format_data;
+
+ if (s > xar->bytes_remaining)
+ s = (size_t)xar->bytes_remaining;
+ if (s == 0 || xar->cur_file == NULL)
+ return (0);
+ if (xar->cur_file->data.compression == NONE) {
+ checksum_update(&(xar->e_sumwrk), buff, s);
+ checksum_update(&(xar->a_sumwrk), buff, s);
+ size = rsize = s;
+ } else {
+ xar->stream.next_in = (const unsigned char *)buff;
+ xar->stream.avail_in = s;
+ if (xar->bytes_remaining > s)
+ run = ARCHIVE_Z_RUN;
+ else
+ run = ARCHIVE_Z_FINISH;
+ /* Compress file data. */
+ r = compression_code(&(a->archive), &(xar->stream), run);
+ if (r != ARCHIVE_OK && r != ARCHIVE_EOF)
+ return (ARCHIVE_FATAL);
+ rsize = s - xar->stream.avail_in;
+ checksum_update(&(xar->e_sumwrk), buff, rsize);
+ size = sizeof(xar->wbuff) - xar->stream.avail_out;
+ checksum_update(&(xar->a_sumwrk), xar->wbuff, size);
+ }
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ if (xar->bytes_remaining ==
+ (uint64_t)archive_entry_size(xar->cur_file->entry)) {
+ /*
+ * Get the path of a shell script if so.
+ */
+ const unsigned char *b = (const unsigned char *)buff;
+
+ archive_string_empty(&(xar->cur_file->script));
+ if (rsize > 2 && b[0] == '#' && b[1] == '!') {
+ size_t i, end, off;
+
+ off = 2;
+ if (b[off] == ' ')
+ off++;
+#ifdef PATH_MAX
+ if ((rsize - off) > PATH_MAX)
+ end = off + PATH_MAX;
+ else
+#endif
+ end = rsize;
+ /* Find the end of a script path. */
+ for (i = off; i < end && b[i] != '\0' &&
+ b[i] != '\n' && b[i] != '\r' &&
+ b[i] != ' ' && b[i] != '\t'; i++)
+ ;
+ archive_strncpy(&(xar->cur_file->script), b + off,
+ i - off);
+ }
+ }
+#endif
+
+ if (xar->cur_file->data.compression == NONE) {
+ if (write_to_temp(a, buff, size) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ } else {
+ if (write_to_temp(a, xar->wbuff, size) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ xar->bytes_remaining -= rsize;
+ xar->cur_file->data.length += size;
+
+ return (rsize);
+}
+
+static int
+xar_finish_entry(struct archive_write *a)
+{
+ struct xar *xar;
+ struct file *file;
+ size_t s;
+ ssize_t w;
+
+ xar = (struct xar *)a->format_data;
+ if (xar->cur_file == NULL)
+ return (ARCHIVE_OK);
+
+ while (xar->bytes_remaining > 0) {
+ s = (size_t)xar->bytes_remaining;
+ if (s > a->null_length)
+ s = a->null_length;
+ w = xar_write_data(a, a->nulls, s);
+ if (w > 0)
+ xar->bytes_remaining -= w;
+ else
+ return (w);
+ }
+ file = xar->cur_file;
+ checksum_final(&(xar->e_sumwrk), &(file->data.e_sum));
+ checksum_final(&(xar->a_sumwrk), &(file->data.a_sum));
+ xar->cur_file = NULL;
+
+ return (ARCHIVE_OK);
+}
+
+static int
+xmlwrite_string_attr(struct archive_write *a, xmlTextWriterPtr writer,
+ const char *key, const char *value,
+ const char *attrkey, const char *attrvalue)
+{
+ int r;
+
+ r = xmlTextWriterStartElement(writer, BAD_CAST_CONST(key));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ if (attrkey != NULL && attrvalue != NULL) {
+ r = xmlTextWriterWriteAttribute(writer,
+ BAD_CAST_CONST(attrkey), BAD_CAST_CONST(attrvalue));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterWriteAttribute() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ }
+ if (value != NULL) {
+ r = xmlTextWriterWriteString(writer, BAD_CAST_CONST(value));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterWriteString() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ }
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+xmlwrite_string(struct archive_write *a, xmlTextWriterPtr writer,
+ const char *key, const char *value)
+{
+ int r;
+
+ if (value == NULL)
+ return (ARCHIVE_OK);
+
+ r = xmlTextWriterStartElement(writer, BAD_CAST_CONST(key));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ if (value != NULL) {
+ r = xmlTextWriterWriteString(writer, BAD_CAST_CONST(value));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterWriteString() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ }
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+xmlwrite_fstring(struct archive_write *a, xmlTextWriterPtr writer,
+ const char *key, const char *fmt, ...)
+{
+ struct xar *xar;
+ va_list ap;
+
+ xar = (struct xar *)a->format_data;
+ va_start(ap, fmt);
+ archive_string_empty(&xar->vstr);
+ archive_string_vsprintf(&xar->vstr, fmt, ap);
+ va_end(ap);
+ return (xmlwrite_string(a, writer, key, xar->vstr.s));
+}
+
+static int
+xmlwrite_time(struct archive_write *a, xmlTextWriterPtr writer,
+ const char *key, time_t t, int z)
+{
+ char timestr[100];
+ struct tm tm;
+
+#if defined(HAVE_GMTIME_R)
+ gmtime_r(&t, &tm);
+#elif defined(HAVE__GMTIME64_S)
+ _gmtime64_s(&tm, &t);
+#else
+ memcpy(&tm, gmtime(&t), sizeof(tm));
+#endif
+ memset(&timestr, 0, sizeof(timestr));
+ /* Do not use %F and %T for portability. */
+ strftime(timestr, sizeof(timestr), "%Y-%m-%dT%H:%M:%S", &tm);
+ if (z)
+ strcat(timestr, "Z");
+ return (xmlwrite_string(a, writer, key, timestr));
+}
+
+static int
+xmlwrite_mode(struct archive_write *a, xmlTextWriterPtr writer,
+ const char *key, mode_t mode)
+{
+ char ms[5];
+
+ ms[0] = '0';
+ ms[1] = '0' + ((mode >> 6) & 07);
+ ms[2] = '0' + ((mode >> 3) & 07);
+ ms[3] = '0' + (mode & 07);
+ ms[4] = '\0';
+
+ return (xmlwrite_string(a, writer, key, ms));
+}
+
+static int
+xmlwrite_sum(struct archive_write *a, xmlTextWriterPtr writer,
+ const char *key, struct chksumval *sum)
+{
+ const char *algname;
+ int algsize;
+ char buff[MAX_SUM_SIZE*2 + 1];
+ char *p;
+ unsigned char *s;
+ int i, r;
+
+ if (sum->len > 0) {
+ algname = getalgname(sum->alg);
+ algsize = getalgsize(sum->alg);
+ if (algname != NULL) {
+ const char *hex = "0123456789abcdef";
+ p = buff;
+ s = sum->val;
+ for (i = 0; i < algsize; i++) {
+ *p++ = hex[(*s >> 4)];
+ *p++ = hex[(*s & 0x0f)];
+ s++;
+ }
+ *p = '\0';
+ r = xmlwrite_string_attr(a, writer,
+ key, buff,
+ "style", algname);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ }
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+xmlwrite_heap(struct archive_write *a, xmlTextWriterPtr writer,
+ struct heap_data *heap)
+{
+ const char *encname;
+ int r;
+
+ r = xmlwrite_fstring(a, writer, "length", "%ju", heap->length);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ r = xmlwrite_fstring(a, writer, "offset", "%ju", heap->temp_offset);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ r = xmlwrite_fstring(a, writer, "size", "%ju", heap->size);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ switch (heap->compression) {
+ case GZIP:
+ encname = "application/x-gzip"; break;
+ case BZIP2:
+ encname = "application/x-bzip2"; break;
+ case LZMA:
+ encname = "application/x-lzma"; break;
+ case XZ:
+ encname = "application/x-xz"; break;
+ default:
+ encname = "application/octet-stream"; break;
+ }
+ r = xmlwrite_string_attr(a, writer, "encoding", NULL,
+ "style", encname);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ r = xmlwrite_sum(a, writer, "archived-checksum", &(heap->a_sum));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ r = xmlwrite_sum(a, writer, "extracted-checksum", &(heap->e_sum));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ return (ARCHIVE_OK);
+}
+
+/*
+ * xar utility records fflags as following xml elements:
+ * <flags>
+ * <UserNoDump/>
+ * .....
+ * </flags>
+ * or
+ * <ext2>
+ * <NoDump/>
+ * .....
+ * </ext2>
+ * If xar is running on BSD platform, records <flags>..</flags>;
+ * if xar is running on linux platform, records <ext2>..</ext2>;
+ * otherwise does not record.
+ *
+ * Our implements records both <flags> and <ext2> if it's necessary.
+ */
+static int
+make_fflags_entry(struct archive_write *a, xmlTextWriterPtr writer,
+ const char *element, const char *fflags_text)
+{
+ static const struct flagentry {
+ const char *name;
+ const char *xarname;
+ }
+ flagbsd[] = {
+ { "sappnd", "SystemAppend"},
+ { "sappend", "SystemAppend"},
+ { "arch", "SystemArchived"},
+ { "archived", "SystemArchived"},
+ { "schg", "SystemImmutable"},
+ { "schange", "SystemImmutable"},
+ { "simmutable", "SystemImmutable"},
+ { "nosunlnk", "SystemNoUnlink"},
+ { "nosunlink", "SystemNoUnlink"},
+ { "snapshot", "SystemSnapshot"},
+ { "uappnd", "UserAppend"},
+ { "uappend", "UserAppend"},
+ { "uchg", "UserImmutable"},
+ { "uchange", "UserImmutable"},
+ { "uimmutable", "UserImmutable"},
+ { "nodump", "UserNoDump"},
+ { "noopaque", "UserOpaque"},
+ { "nouunlnk", "UserNoUnlink"},
+ { "nouunlink", "UserNoUnlink"},
+ { NULL, NULL}
+ },
+ flagext2[] = {
+ { "sappnd", "AppendOnly"},
+ { "sappend", "AppendOnly"},
+ { "schg", "Immutable"},
+ { "schange", "Immutable"},
+ { "simmutable", "Immutable"},
+ { "nodump", "NoDump"},
+ { "nouunlnk", "Undelete"},
+ { "nouunlink", "Undelete"},
+ { "btree", "BTree"},
+ { "comperr", "CompError"},
+ { "compress", "Compress"},
+ { "noatime", "NoAtime"},
+ { "compdirty", "CompDirty"},
+ { "comprblk", "CompBlock"},
+ { "dirsync", "DirSync"},
+ { "hashidx", "HashIndexed"},
+ { "imagic", "iMagic"},
+ { "journal", "Journaled"},
+ { "securedeletion", "SecureDeletion"},
+ { "sync", "Synchronous"},
+ { "notail", "NoTail"},
+ { "topdir", "TopDir"},
+ { "reserved", "Reserved"},
+ { NULL, NULL}
+ };
+ const struct flagentry *fe, *flagentry;
+#define FLAGENTRY_MAXSIZE ((sizeof(flagbsd)+sizeof(flagext2))/sizeof(flagbsd))
+ const struct flagentry *avail[FLAGENTRY_MAXSIZE];
+ const char *p;
+ int i, n, r;
+
+ if (strcmp(element, "ext2") == 0)
+ flagentry = flagext2;
+ else
+ flagentry = flagbsd;
+ n = 0;
+ p = fflags_text;
+ do {
+ const char *cp;
+
+ cp = strchr(p, ',');
+ if (cp == NULL)
+ cp = p + strlen(p);
+
+ for (fe = flagentry; fe->name != NULL; fe++) {
+ if (fe->name[cp - p] != '\0'
+ || p[0] != fe->name[0])
+ continue;
+ if (strncmp(p, fe->name, cp - p) == 0) {
+ avail[n++] = fe;
+ break;
+ }
+ }
+ if (*cp == ',')
+ p = cp + 1;
+ else
+ p = NULL;
+ } while (p != NULL);
+
+ if (n > 0) {
+ r = xmlTextWriterStartElement(writer, BAD_CAST_CONST(element));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ for (i = 0; i < n; i++) {
+ r = xmlwrite_string(a, writer,
+ avail[i]->xarname, NULL);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+make_file_entry(struct archive_write *a, xmlTextWriterPtr writer,
+ struct file *file)
+{
+ struct xar *xar;
+ const char *filetype, *filelink, *fflags;
+ struct archive_string linkto;
+ struct heap_data *heap;
+ unsigned char *tmp;
+ const char *p;
+ size_t len;
+ int r, r2, l, ll;
+
+ xar = (struct xar *)a->format_data;
+ r2 = ARCHIVE_OK;
+
+ /*
+ * Make a file name entry, "<name>".
+ */
+ l = ll = archive_strlen(&(file->basename));
+ tmp = malloc(l);
+ if (tmp == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ r = UTF8Toisolat1(tmp, &l, BAD_CAST(file->basename.s), &ll);
+ free(tmp);
+ if (r < 0) {
+ r = xmlTextWriterStartElement(writer, BAD_CAST("name"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ r = xmlTextWriterWriteAttribute(writer,
+ BAD_CAST("enctype"), BAD_CAST("base64"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterWriteAttribute() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ r = xmlTextWriterWriteBase64(writer, file->basename.s,
+ 0, archive_strlen(&(file->basename)));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterWriteBase64() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ } else {
+ r = xmlwrite_string(a, writer, "name", file->basename.s);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Make a file type entry, "<type>".
+ */
+ filelink = NULL;
+ archive_string_init(&linkto);
+ switch (archive_entry_filetype(file->entry)) {
+ case AE_IFDIR:
+ filetype = "directory"; break;
+ case AE_IFLNK:
+ filetype = "symlink"; break;
+ case AE_IFCHR:
+ filetype = "character special"; break;
+ case AE_IFBLK:
+ filetype = "block special"; break;
+ case AE_IFSOCK:
+ filetype = "socket"; break;
+ case AE_IFIFO:
+ filetype = "fifo"; break;
+ case AE_IFREG:
+ default:
+ if (file->hardlink_target != NULL) {
+ filetype = "hardlink";
+ filelink = "link";
+ if (file->hardlink_target == file)
+ archive_strcpy(&linkto, "original");
+ else
+ archive_string_sprintf(&linkto, "%d",
+ file->hardlink_target->id);
+ } else
+ filetype = "file";
+ break;
+ }
+ r = xmlwrite_string_attr(a, writer, "type", filetype,
+ filelink, linkto.s);
+ archive_string_free(&linkto);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+
+ /*
+ * On a virtual directory, we record "name" and "type" only.
+ */
+ if (file->virtual)
+ return (ARCHIVE_OK);
+
+ switch (archive_entry_filetype(file->entry)) {
+ case AE_IFLNK:
+ /*
+ * xar utility has checked a file type, which
+ * a symblic-link file has referenced.
+ * For example:
+ * <link type="directory">../ref/</link>
+ * The symlink target file is "../ref/" and its
+ * file type is a directory.
+ *
+ * <link type="file">../f</link>
+ * The symlink target file is "../f" and its
+ * file type is a regular file.
+ *
+ * But our implemention cannot do it, and then we
+ * always record that a attribute "type" is "borken",
+ * for example:
+ * <link type="broken">foo/bar</link>
+ * It means "foo/bar" is not reachable.
+ */
+ r = xmlwrite_string_attr(a, writer, "link",
+ file->symlink.s,
+ "type", "broken");
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ break;
+ case AE_IFCHR:
+ case AE_IFBLK:
+ r = xmlTextWriterStartElement(writer, BAD_CAST("device"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ r = xmlwrite_fstring(a, writer, "major",
+ "%d", archive_entry_rdevmajor(file->entry));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ r = xmlwrite_fstring(a, writer, "minor",
+ "%d", archive_entry_rdevminor(file->entry));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ break;
+ default:
+ break;
+ }
+
+ /*
+ * Make a inode entry, "<inode>".
+ */
+ r = xmlwrite_fstring(a, writer, "inode",
+ "%jd", archive_entry_ino64(file->entry));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ if (archive_entry_dev(file->entry) != 0) {
+ r = xmlwrite_fstring(a, writer, "deviceno",
+ "%d", archive_entry_dev(file->entry));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Make a file mode entry, "<mode>".
+ */
+ r = xmlwrite_mode(a, writer, "mode",
+ archive_entry_mode(file->entry));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+
+ /*
+ * Make a user entry, "<uid>" and "<user>.
+ */
+ r = xmlwrite_fstring(a, writer, "uid",
+ "%d", archive_entry_uid(file->entry));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ r = archive_entry_uname_l(file->entry, &p, &len, xar->sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Uname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate uname '%s' to UTF-8",
+ archive_entry_uname(file->entry));
+ r2 = ARCHIVE_WARN;
+ }
+ if (len > 0) {
+ r = xmlwrite_string(a, writer, "user", p);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Make a group entry, "<gid>" and "<group>.
+ */
+ r = xmlwrite_fstring(a, writer, "gid",
+ "%d", archive_entry_gid(file->entry));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ r = archive_entry_gname_l(file->entry, &p, &len, xar->sconv);
+ if (r != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Gname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate gname '%s' to UTF-8",
+ archive_entry_gname(file->entry));
+ r2 = ARCHIVE_WARN;
+ }
+ if (len > 0) {
+ r = xmlwrite_string(a, writer, "group", p);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Make a ctime entry, "<ctime>".
+ */
+ if (archive_entry_ctime_is_set(file->entry)) {
+ r = xmlwrite_time(a, writer, "ctime",
+ archive_entry_ctime(file->entry), 1);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Make a mtime entry, "<mtime>".
+ */
+ if (archive_entry_mtime_is_set(file->entry)) {
+ r = xmlwrite_time(a, writer, "mtime",
+ archive_entry_mtime(file->entry), 1);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Make a atime entry, "<atime>".
+ */
+ if (archive_entry_atime_is_set(file->entry)) {
+ r = xmlwrite_time(a, writer, "atime",
+ archive_entry_atime(file->entry), 1);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ }
+
+ /*
+ * Make fflags entries, "<flags>" and "<ext2>".
+ */
+ fflags = archive_entry_fflags_text(file->entry);
+ if (fflags != NULL) {
+ r = make_fflags_entry(a, writer, "flags", fflags);
+ if (r < 0)
+ return (r);
+ r = make_fflags_entry(a, writer, "ext2", fflags);
+ if (r < 0)
+ return (r);
+ }
+
+ /*
+ * Make extended attribute entries, "<ea>".
+ */
+ archive_entry_xattr_reset(file->entry);
+ for (heap = file->xattr.first; heap != NULL; heap = heap->next) {
+ const char *name;
+ const void *value;
+ size_t size;
+
+ archive_entry_xattr_next(file->entry,
+ &name, &value, &size);
+ r = xmlTextWriterStartElement(writer, BAD_CAST("ea"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ r = xmlTextWriterWriteFormatAttribute(writer,
+ BAD_CAST("id"), "%d", heap->id);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterWriteAttribute() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ r = xmlwrite_heap(a, writer, heap);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+ r = xmlwrite_string(a, writer, "name", name);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ /*
+ * Make a file data entry, "<data>".
+ */
+ if (file->data.length > 0) {
+ r = xmlTextWriterStartElement(writer, BAD_CAST("data"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+
+ r = xmlwrite_heap(a, writer, &(file->data));
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ if (archive_strlen(&file->script) > 0) {
+ r = xmlTextWriterStartElement(writer, BAD_CAST("content"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+
+ r = xmlwrite_string(a, writer,
+ "interpreter", file->script.s);
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+
+ r = xmlwrite_string(a, writer, "type", "script");
+ if (r < 0)
+ return (ARCHIVE_FATAL);
+
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() failed: %d", r);
+ return (ARCHIVE_FATAL);
+ }
+ }
+
+ return (r2);
+}
+
+/*
+ * Make the TOC
+ */
+static int
+make_toc(struct archive_write *a)
+{
+ struct xar *xar;
+ struct file *np;
+ xmlBufferPtr bp;
+ xmlTextWriterPtr writer;
+ int algsize;
+ int r, ret;
+
+ xar = (struct xar *)a->format_data;
+
+ ret = ARCHIVE_FATAL;
+
+ /*
+ * Initialize xml writer.
+ */
+ writer = NULL;
+ bp = xmlBufferCreate();
+ if (bp == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "xmlBufferCreate() "
+ "couldn't create xml buffer");
+ goto exit_toc;
+ }
+ writer = xmlNewTextWriterMemory(bp, 0);
+ if (writer == NULL) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlNewTextWriterMemory() "
+ "couldn't create xml writer");
+ goto exit_toc;
+ }
+ r = xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartDocument() failed: %d", r);
+ goto exit_toc;
+ }
+ r = xmlTextWriterSetIndent(writer, 4);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterSetIndent() failed: %d", r);
+ goto exit_toc;
+ }
+
+ /*
+ * Start recoding TOC
+ */
+ r = xmlTextWriterStartElement(writer, BAD_CAST("xar"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ goto exit_toc;
+ }
+ r = xmlTextWriterStartElement(writer, BAD_CAST("toc"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartDocument() failed: %d", r);
+ goto exit_toc;
+ }
+
+ /*
+ * Record the creation time of the archive file.
+ */
+ r = xmlwrite_time(a, writer, "creation-time", time(NULL), 0);
+ if (r < 0)
+ goto exit_toc;
+
+ /*
+ * Record the checksum value of TOC
+ */
+ algsize = getalgsize(xar->opt_toc_sumalg);
+ if (algsize) {
+ /*
+ * Record TOC checksum
+ */
+ r = xmlTextWriterStartElement(writer, BAD_CAST("checksum"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() failed: %d", r);
+ goto exit_toc;
+ }
+ r = xmlTextWriterWriteAttribute(writer, BAD_CAST("style"),
+ BAD_CAST_CONST(getalgname(xar->opt_toc_sumalg)));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterWriteAttribute() failed: %d", r);
+ goto exit_toc;
+ }
+
+ /*
+ * Record the offset of the value of checksum of TOC
+ */
+ r = xmlwrite_string(a, writer, "offset", "0");
+ if (r < 0)
+ goto exit_toc;
+
+ /*
+ * Record the size of the value of checksum of TOC
+ */
+ r = xmlwrite_fstring(a, writer, "size", "%d", algsize);
+ if (r < 0)
+ goto exit_toc;
+
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() failed: %d", r);
+ goto exit_toc;
+ }
+ }
+
+ np = xar->root;
+ do {
+ if (np != np->parent) {
+ r = make_file_entry(a, writer, np);
+ if (r != ARCHIVE_OK)
+ goto exit_toc;
+ }
+
+ if (np->dir && np->children.first != NULL) {
+ /* Enter to sub directories. */
+ np = np->children.first;
+ r = xmlTextWriterStartElement(writer,
+ BAD_CAST("file"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() "
+ "failed: %d", r);
+ goto exit_toc;
+ }
+ r = xmlTextWriterWriteFormatAttribute(
+ writer, BAD_CAST("id"), "%d", np->id);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterWriteAttribute() "
+ "failed: %d", r);
+ goto exit_toc;
+ }
+ continue;
+ }
+ while (np != np->parent) {
+ r = xmlTextWriterEndElement(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndElement() "
+ "failed: %d", r);
+ goto exit_toc;
+ }
+ if (np->chnext == NULL) {
+ /* Return to the parent directory. */
+ np = np->parent;
+ } else {
+ np = np->chnext;
+ r = xmlTextWriterStartElement(writer,
+ BAD_CAST("file"));
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterStartElement() "
+ "failed: %d", r);
+ goto exit_toc;
+ }
+ r = xmlTextWriterWriteFormatAttribute(
+ writer, BAD_CAST("id"), "%d", np->id);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterWriteAttribute() "
+ "failed: %d", r);
+ goto exit_toc;
+ }
+ break;
+ }
+ }
+ } while (np != np->parent);
+
+ r = xmlTextWriterEndDocument(writer);
+ if (r < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "xmlTextWriterEndDocument() failed: %d", r);
+ goto exit_toc;
+ }
+#if DEBUG_PRINT_TOC
+ fprintf(stderr, "\n---TOC-- %d bytes --\n%s\n",
+ strlen((const char *)bp->content), bp->content);
+#endif
+
+ /*
+ * Compress the TOC and calculate the sum of the TOC.
+ */
+ xar->toc.temp_offset = xar->temp_offset;
+ xar->toc.size = bp->use;
+ checksum_init(&(xar->a_sumwrk), xar->opt_toc_sumalg);
+
+ r = compression_init_encoder_gzip(&(a->archive),
+ &(xar->stream), 6, 1);
+ if (r != ARCHIVE_OK)
+ goto exit_toc;
+ xar->stream.next_in = bp->content;
+ xar->stream.avail_in = bp->use;
+ xar->stream.total_in = 0;
+ xar->stream.next_out = xar->wbuff;
+ xar->stream.avail_out = sizeof(xar->wbuff);
+ xar->stream.total_out = 0;
+ for (;;) {
+ size_t size;
+
+ r = compression_code(&(a->archive),
+ &(xar->stream), ARCHIVE_Z_FINISH);
+ if (r != ARCHIVE_OK && r != ARCHIVE_EOF)
+ goto exit_toc;
+ size = sizeof(xar->wbuff) - xar->stream.avail_out;
+ checksum_update(&(xar->a_sumwrk), xar->wbuff, size);
+ if (write_to_temp(a, xar->wbuff, size) != ARCHIVE_OK)
+ goto exit_toc;
+ if (r == ARCHIVE_EOF)
+ break;
+ xar->stream.next_out = xar->wbuff;
+ xar->stream.avail_out = sizeof(xar->wbuff);
+ }
+ r = compression_end(&(a->archive), &(xar->stream));
+ if (r != ARCHIVE_OK)
+ goto exit_toc;
+ xar->toc.length = xar->stream.total_out;
+ xar->toc.compression = GZIP;
+ checksum_final(&(xar->a_sumwrk), &(xar->toc.a_sum));
+
+ ret = ARCHIVE_OK;
+exit_toc:
+ if (writer)
+ xmlFreeTextWriter(writer);
+ if (bp)
+ xmlBufferFree(bp);
+
+ return (ret);
+}
+
+static int
+flush_wbuff(struct archive_write *a)
+{
+ struct xar *xar;
+ int r;
+ size_t s;
+
+ xar = (struct xar *)a->format_data;
+ s = sizeof(xar->wbuff) - xar->wbuff_remaining;
+ r = __archive_write_output(a, xar->wbuff, s);
+ if (r != ARCHIVE_OK)
+ return (r);
+ xar->wbuff_remaining = sizeof(xar->wbuff);
+ return (r);
+}
+
+static int
+copy_out(struct archive_write *a, uint64_t offset, uint64_t length)
+{
+ struct xar *xar;
+ int r;
+
+ xar = (struct xar *)a->format_data;
+ if (lseek(xar->temp_fd, offset, SEEK_SET) < 0) {
+ archive_set_error(&(a->archive), errno, "lseek failed");
+ return (ARCHIVE_FATAL);
+ }
+ while (length) {
+ size_t rsize;
+ ssize_t rs;
+ unsigned char *wb;
+
+ if (length > xar->wbuff_remaining)
+ rsize = xar->wbuff_remaining;
+ else
+ rsize = (size_t)length;
+ wb = xar->wbuff + (sizeof(xar->wbuff) - xar->wbuff_remaining);
+ rs = read(xar->temp_fd, wb, rsize);
+ if (rs < 0) {
+ archive_set_error(&(a->archive), errno,
+ "Can't read temporary file(%jd)",
+ (intmax_t)rs);
+ return (ARCHIVE_FATAL);
+ }
+ if (rs == 0) {
+ archive_set_error(&(a->archive), 0,
+ "Truncated xar archive");
+ return (ARCHIVE_FATAL);
+ }
+ xar->wbuff_remaining -= rs;
+ length -= rs;
+ if (xar->wbuff_remaining == 0) {
+ r = flush_wbuff(a);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+xar_close(struct archive_write *a)
+{
+ struct xar *xar;
+ unsigned char *wb;
+ uint64_t length;
+ int r;
+
+ xar = (struct xar *)a->format_data;
+
+ /* Empty! */
+ if (xar->root->children.first == NULL)
+ return (ARCHIVE_OK);
+
+ /* Save the length of all file extended attributes and contents. */
+ length = xar->temp_offset;
+
+ /* Connect hardlinked files */
+ file_connect_hardlink_files(xar);
+
+ /* Make the TOC */
+ r = make_toc(a);
+ if (r != ARCHIVE_OK)
+ return (r);
+ /*
+ * Make the xar header on wbuff(write buffer).
+ */
+ wb = xar->wbuff;
+ xar->wbuff_remaining = sizeof(xar->wbuff);
+ archive_be32enc(&wb[0], HEADER_MAGIC);
+ archive_be16enc(&wb[4], HEADER_SIZE);
+ archive_be16enc(&wb[6], HEADER_VERSION);
+ archive_be64enc(&wb[8], xar->toc.length);
+ archive_be64enc(&wb[16], xar->toc.size);
+ archive_be32enc(&wb[24], xar->toc.a_sum.alg);
+ xar->wbuff_remaining -= HEADER_SIZE;
+
+ /*
+ * Write the TOC
+ */
+ r = copy_out(a, xar->toc.temp_offset, xar->toc.length);
+ if (r != ARCHIVE_OK)
+ return (r);
+
+ /* Write the checksum value of the TOC. */
+ if (xar->toc.a_sum.len) {
+ if (xar->wbuff_remaining < xar->toc.a_sum.len) {
+ r = flush_wbuff(a);
+ if (r != ARCHIVE_OK)
+ return (r);
+ }
+ wb = xar->wbuff + (sizeof(xar->wbuff) - xar->wbuff_remaining);
+ memcpy(wb, xar->toc.a_sum.val, xar->toc.a_sum.len);
+ xar->wbuff_remaining -= xar->toc.a_sum.len;
+ }
+
+ /*
+ * Write all file extended attributes and contents.
+ */
+ r = copy_out(a, xar->toc.a_sum.len, length);
+ if (r != ARCHIVE_OK)
+ return (r);
+ r = flush_wbuff(a);
+ return (r);
+}
+
+static int
+xar_free(struct archive_write *a)
+{
+ struct xar *xar;
+
+ xar = (struct xar *)a->format_data;
+ archive_string_free(&(xar->cur_dirstr));
+ archive_string_free(&(xar->tstr));
+ archive_string_free(&(xar->vstr));
+ file_free_hardlinks(xar);
+ file_free_register(xar);
+ compression_end(&(a->archive), &(xar->stream));
+ free(xar);
+
+ return (ARCHIVE_OK);
+}
+
+static int
+file_cmp_node(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ const struct file *f1 = (const struct file *)n1;
+ const struct file *f2 = (const struct file *)n2;
+
+ return (strcmp(f1->basename.s, f2->basename.s));
+}
+
+static int
+file_cmp_key(const struct archive_rb_node *n, const void *key)
+{
+ const struct file *f = (const struct file *)n;
+
+ return (strcmp(f->basename.s, (const char *)key));
+}
+
+static struct file *
+file_new(struct archive_write *a, struct archive_entry *entry)
+{
+ struct file *file;
+ static const struct archive_rb_tree_ops rb_ops = {
+ file_cmp_node, file_cmp_key
+ };
+
+ file = calloc(1, sizeof(*file));
+ if (file == NULL)
+ return (NULL);
+
+ if (entry != NULL)
+ file->entry = archive_entry_clone(entry);
+ else
+ file->entry = archive_entry_new2(&a->archive);
+ if (file->entry == NULL) {
+ free(file);
+ return (NULL);
+ }
+ __archive_rb_tree_init(&(file->rbtree), &rb_ops);
+ file->children.first = NULL;
+ file->children.last = &(file->children.first);
+ file->xattr.first = NULL;
+ file->xattr.last = &(file->xattr.first);
+ archive_string_init(&(file->parentdir));
+ archive_string_init(&(file->basename));
+ archive_string_init(&(file->symlink));
+ archive_string_init(&(file->script));
+ if (entry != NULL && archive_entry_filetype(entry) == AE_IFDIR)
+ file->dir = 1;
+
+ return (file);
+}
+
+static void
+file_free(struct file *file)
+{
+ struct heap_data *heap, *next_heap;
+
+ heap = file->xattr.first;
+ while (heap != NULL) {
+ next_heap = heap->next;
+ free(heap);
+ heap = next_heap;
+ }
+ archive_string_free(&(file->parentdir));
+ archive_string_free(&(file->basename));
+ archive_string_free(&(file->symlink));
+ archive_string_free(&(file->script));
+ free(file);
+}
+
+static struct file *
+file_create_virtual_dir(struct archive_write *a, struct xar *xar,
+ const char *pathname)
+{
+ struct file *file;
+
+ (void)xar; /* UNUSED */
+
+ file = file_new(a, NULL);
+ if (file == NULL)
+ return (NULL);
+ archive_entry_set_pathname(file->entry, pathname);
+ archive_entry_set_mode(file->entry, 0555 | AE_IFDIR);
+
+ file->dir = 1;
+ file->virtual = 1;
+
+ return (file);
+}
+
+static int
+file_add_child_tail(struct file *parent, struct file *child)
+{
+ if (!__archive_rb_tree_insert_node(
+ &(parent->rbtree), (struct archive_rb_node *)child))
+ return (0);
+ child->chnext = NULL;
+ *parent->children.last = child;
+ parent->children.last = &(child->chnext);
+ child->parent = parent;
+ return (1);
+}
+
+/*
+ * Find a entry from `parent'
+ */
+static struct file *
+file_find_child(struct file *parent, const char *child_name)
+{
+ struct file *np;
+
+ np = (struct file *)__archive_rb_tree_find_node(
+ &(parent->rbtree), child_name);
+ return (np);
+}
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+static void
+cleanup_backslash(char *utf8, size_t len)
+{
+
+ /* Convert a path-separator from '\' to '/' */
+ while (*utf8 != '\0' && len) {
+ if (*utf8 == '\\')
+ *utf8 = '/';
+ ++utf8;
+ --len;
+ }
+}
+#else
+#define cleanup_backslash(p, len) /* nop */
+#endif
+
+/*
+ * Generate a parent directory name and a base name from a pathname.
+ */
+static int
+file_gen_utility_names(struct archive_write *a, struct file *file)
+{
+ struct xar *xar;
+ const char *pp;
+ char *p, *dirname, *slash;
+ size_t len;
+ int r = ARCHIVE_OK;
+
+ xar = (struct xar *)a->format_data;
+ archive_string_empty(&(file->parentdir));
+ archive_string_empty(&(file->basename));
+ archive_string_empty(&(file->symlink));
+
+ if (file->parent == file)/* virtual root */
+ return (ARCHIVE_OK);
+
+ if (archive_entry_pathname_l(file->entry, &pp, &len, xar->sconv)
+ != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate pathname '%s' to UTF-8",
+ archive_entry_pathname(file->entry));
+ r = ARCHIVE_WARN;
+ }
+ archive_strncpy(&(file->parentdir), pp, len);
+ len = file->parentdir.length;
+ p = dirname = file->parentdir.s;
+ /*
+ * Convert a path-separator from '\' to '/'
+ */
+ cleanup_backslash(p, len);
+
+ /*
+ * Remove leading '/', '../' and './' elements
+ */
+ while (*p) {
+ if (p[0] == '/') {
+ p++;
+ len--;
+ } else if (p[0] != '.')
+ break;
+ else if (p[1] == '.' && p[2] == '/') {
+ p += 3;
+ len -= 3;
+ } else if (p[1] == '/' || (p[1] == '.' && p[2] == '\0')) {
+ p += 2;
+ len -= 2;
+ } else if (p[1] == '\0') {
+ p++;
+ len--;
+ } else
+ break;
+ }
+ if (p != dirname) {
+ memmove(dirname, p, len+1);
+ p = dirname;
+ }
+ /*
+ * Remove "/","/." and "/.." elements from tail.
+ */
+ while (len > 0) {
+ size_t ll = len;
+
+ if (len > 0 && p[len-1] == '/') {
+ p[len-1] = '\0';
+ len--;
+ }
+ if (len > 1 && p[len-2] == '/' && p[len-1] == '.') {
+ p[len-2] = '\0';
+ len -= 2;
+ }
+ if (len > 2 && p[len-3] == '/' && p[len-2] == '.' &&
+ p[len-1] == '.') {
+ p[len-3] = '\0';
+ len -= 3;
+ }
+ if (ll == len)
+ break;
+ }
+ while (*p) {
+ if (p[0] == '/') {
+ if (p[1] == '/')
+ /* Convert '//' --> '/' */
+ strcpy(p, p+1);
+ else if (p[1] == '.' && p[2] == '/')
+ /* Convert '/./' --> '/' */
+ strcpy(p, p+2);
+ else if (p[1] == '.' && p[2] == '.' && p[3] == '/') {
+ /* Convert 'dir/dir1/../dir2/'
+ * --> 'dir/dir2/'
+ */
+ char *rp = p -1;
+ while (rp >= dirname) {
+ if (*rp == '/')
+ break;
+ --rp;
+ }
+ if (rp > dirname) {
+ strcpy(rp, p+3);
+ p = rp;
+ } else {
+ strcpy(dirname, p+4);
+ p = dirname;
+ }
+ } else
+ p++;
+ } else
+ p++;
+ }
+ p = dirname;
+ len = strlen(p);
+
+ if (archive_entry_filetype(file->entry) == AE_IFLNK) {
+ size_t len2;
+ /* Convert symlink name too. */
+ if (archive_entry_symlink_l(file->entry, &pp, &len2,
+ xar->sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Linkname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate symlink '%s' to UTF-8",
+ archive_entry_symlink(file->entry));
+ r = ARCHIVE_WARN;
+ }
+ archive_strncpy(&(file->symlink), pp, len2);
+ cleanup_backslash(file->symlink.s, file->symlink.length);
+ }
+ /*
+ * - Count up directory elements.
+ * - Find out the position which points the last position of
+ * path separator('/').
+ */
+ slash = NULL;
+ for (; *p != '\0'; p++)
+ if (*p == '/')
+ slash = p;
+ if (slash == NULL) {
+ /* The pathname doesn't have a parent directory. */
+ file->parentdir.length = len;
+ archive_string_copy(&(file->basename), &(file->parentdir));
+ archive_string_empty(&(file->parentdir));
+ file->parentdir.s = '\0';
+ return (r);
+ }
+
+ /* Make a basename from dirname and slash */
+ *slash = '\0';
+ file->parentdir.length = slash - dirname;
+ archive_strcpy(&(file->basename), slash + 1);
+ return (r);
+}
+
+static int
+get_path_component(char *name, int n, const char *fn)
+{
+ char *p;
+ int l;
+
+ p = strchr(fn, '/');
+ if (p == NULL) {
+ if ((l = strlen(fn)) == 0)
+ return (0);
+ } else
+ l = p - fn;
+ if (l > n -1)
+ return (-1);
+ memcpy(name, fn, l);
+ name[l] = '\0';
+
+ return (l);
+}
+
+/*
+ * Add a new entry into the tree.
+ */
+static int
+file_tree(struct archive_write *a, struct file **filepp)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ char name[_MAX_FNAME];/* Included null terminator size. */
+#elif defined(NAME_MAX) && NAME_MAX >= 255
+ char name[NAME_MAX+1];
+#else
+ char name[256];
+#endif
+ struct xar *xar = (struct xar *)a->format_data;
+ struct file *dent, *file, *np;
+ struct archive_entry *ent;
+ const char *fn, *p;
+ int l;
+
+ file = *filepp;
+ dent = xar->root;
+ if (file->parentdir.length > 0)
+ fn = p = file->parentdir.s;
+ else
+ fn = p = "";
+
+ /*
+ * If the path of the parent directory of `file' entry is
+ * the same as the path of `cur_dirent', add isoent to
+ * `cur_dirent'.
+ */
+ if (archive_strlen(&(xar->cur_dirstr))
+ == archive_strlen(&(file->parentdir)) &&
+ strcmp(xar->cur_dirstr.s, fn) == 0) {
+ if (!file_add_child_tail(xar->cur_dirent, file)) {
+ np = (struct file *)__archive_rb_tree_find_node(
+ &(xar->cur_dirent->rbtree),
+ file->basename.s);
+ goto same_entry;
+ }
+ return (ARCHIVE_OK);
+ }
+
+ for (;;) {
+ l = get_path_component(name, sizeof(name), fn);
+ if (l == 0) {
+ np = NULL;
+ break;
+ }
+ if (l < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "A name buffer is too small");
+ file_free(file);
+ *filepp = NULL;
+ return (ARCHIVE_FATAL);
+ }
+
+ np = file_find_child(dent, name);
+ if (np == NULL || fn[0] == '\0')
+ break;
+
+ /* Find next subdirectory. */
+ if (!np->dir) {
+ /* NOT Directory! */
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "`%s' is not directory, we cannot insert `%s' ",
+ archive_entry_pathname(np->entry),
+ archive_entry_pathname(file->entry));
+ file_free(file);
+ *filepp = NULL;
+ return (ARCHIVE_FAILED);
+ }
+ fn += l;
+ if (fn[0] == '/')
+ fn++;
+ dent = np;
+ }
+ if (np == NULL) {
+ /*
+ * Create virtual parent directories.
+ */
+ while (fn[0] != '\0') {
+ struct file *vp;
+ struct archive_string as;
+
+ archive_string_init(&as);
+ archive_strncat(&as, p, fn - p + l);
+ if (as.s[as.length-1] == '/') {
+ as.s[as.length-1] = '\0';
+ as.length--;
+ }
+ vp = file_create_virtual_dir(a, xar, as.s);
+ if (vp == NULL) {
+ archive_string_free(&as);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ file_free(file);
+ *filepp = NULL;
+ return (ARCHIVE_FATAL);
+ }
+ archive_string_free(&as);
+ if (file_gen_utility_names(a, vp) <= ARCHIVE_FAILED)
+ return (ARCHIVE_FATAL);
+ file_add_child_tail(dent, vp);
+ file_register(xar, vp);
+ np = vp;
+
+ fn += l;
+ if (fn[0] == '/')
+ fn++;
+ l = get_path_component(name, sizeof(name), fn);
+ if (l < 0) {
+ archive_string_free(&as);
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_MISC,
+ "A name buffer is too small");
+ file_free(file);
+ *filepp = NULL;
+ return (ARCHIVE_FATAL);
+ }
+ dent = np;
+ }
+
+ /* Found out the parent directory where isoent can be
+ * inserted. */
+ xar->cur_dirent = dent;
+ archive_string_empty(&(xar->cur_dirstr));
+ archive_string_ensure(&(xar->cur_dirstr),
+ archive_strlen(&(dent->parentdir)) +
+ archive_strlen(&(dent->basename)) + 2);
+ if (archive_strlen(&(dent->parentdir)) +
+ archive_strlen(&(dent->basename)) == 0)
+ xar->cur_dirstr.s[0] = 0;
+ else {
+ if (archive_strlen(&(dent->parentdir)) > 0) {
+ archive_string_copy(&(xar->cur_dirstr),
+ &(dent->parentdir));
+ archive_strappend_char(&(xar->cur_dirstr), '/');
+ }
+ archive_string_concat(&(xar->cur_dirstr),
+ &(dent->basename));
+ }
+
+ if (!file_add_child_tail(dent, file)) {
+ np = (struct file *)__archive_rb_tree_find_node(
+ &(dent->rbtree), file->basename.s);
+ goto same_entry;
+ }
+ return (ARCHIVE_OK);
+ }
+
+same_entry:
+ /*
+ * We have already has the entry the filename of which is
+ * the same.
+ */
+ if (archive_entry_filetype(np->entry) !=
+ archive_entry_filetype(file->entry)) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Found duplicate entries `%s' and its file type is "
+ "different",
+ archive_entry_pathname(np->entry));
+ file_free(file);
+ *filepp = NULL;
+ return (ARCHIVE_FAILED);
+ }
+
+ /* Swap files. */
+ ent = np->entry;
+ np->entry = file->entry;
+ file->entry = ent;
+ np->virtual = 0;
+
+ file_free(file);
+ *filepp = np;
+ return (ARCHIVE_OK);
+}
+
+static void
+file_register(struct xar *xar, struct file *file)
+{
+ file->id = xar->file_idx++;
+ file->next = NULL;
+ *xar->file_list.last = file;
+ xar->file_list.last = &(file->next);
+}
+
+static void
+file_init_register(struct xar *xar)
+{
+ xar->file_list.first = NULL;
+ xar->file_list.last = &(xar->file_list.first);
+}
+
+static void
+file_free_register(struct xar *xar)
+{
+ struct file *file, *file_next;
+
+ file = xar->file_list.first;
+ while (file != NULL) {
+ file_next = file->next;
+ file_free(file);
+ file = file_next;
+ }
+}
+
+/*
+ * Register entry to get a hardlink target.
+ */
+static int
+file_register_hardlink(struct archive_write *a, struct file *file)
+{
+ struct xar *xar = (struct xar *)a->format_data;
+ struct hardlink *hl;
+ const char *pathname;
+
+ archive_entry_set_nlink(file->entry, 1);
+ pathname = archive_entry_hardlink(file->entry);
+ if (pathname == NULL) {
+ /* This `file` is a hardlink target. */
+ hl = malloc(sizeof(*hl));
+ if (hl == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory");
+ return (ARCHIVE_FATAL);
+ }
+ hl->nlink = 1;
+ /* A hardlink target must be the first position. */
+ file->hlnext = NULL;
+ hl->file_list.first = file;
+ hl->file_list.last = &(file->hlnext);
+ __archive_rb_tree_insert_node(&(xar->hardlink_rbtree),
+ (struct archive_rb_node *)hl);
+ } else {
+ hl = (struct hardlink *)__archive_rb_tree_find_node(
+ &(xar->hardlink_rbtree), pathname);
+ if (hl != NULL) {
+ /* Insert `file` entry into the tail. */
+ file->hlnext = NULL;
+ *hl->file_list.last = file;
+ hl->file_list.last = &(file->hlnext);
+ hl->nlink++;
+ }
+ archive_entry_unset_size(file->entry);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+/*
+ * Hardlinked files have to have the same location of extent.
+ * We have to find out hardlink target entries for entries which
+ * have a hardlink target name.
+ */
+static void
+file_connect_hardlink_files(struct xar *xar)
+{
+ struct archive_rb_node *n;
+ struct hardlink *hl;
+ struct file *target, *nf;
+
+ ARCHIVE_RB_TREE_FOREACH(n, &(xar->hardlink_rbtree)) {
+ hl = (struct hardlink *)n;
+
+ /* The first entry must be a hardlink target. */
+ target = hl->file_list.first;
+ archive_entry_set_nlink(target->entry, hl->nlink);
+ if (hl->nlink > 1)
+ /* It means this file is a hardlink
+ * targe itself. */
+ target->hardlink_target = target;
+ for (nf = target->hlnext;
+ nf != NULL; nf = nf->hlnext) {
+ nf->hardlink_target = target;
+ archive_entry_set_nlink(nf->entry, hl->nlink);
+ }
+ }
+}
+
+static int
+file_hd_cmp_node(const struct archive_rb_node *n1,
+ const struct archive_rb_node *n2)
+{
+ const struct hardlink *h1 = (const struct hardlink *)n1;
+ const struct hardlink *h2 = (const struct hardlink *)n2;
+
+ return (strcmp(archive_entry_pathname(h1->file_list.first->entry),
+ archive_entry_pathname(h2->file_list.first->entry)));
+}
+
+static int
+file_hd_cmp_key(const struct archive_rb_node *n, const void *key)
+{
+ const struct hardlink *h = (const struct hardlink *)n;
+
+ return (strcmp(archive_entry_pathname(h->file_list.first->entry),
+ (const char *)key));
+}
+
+
+static void
+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);
+}
+
+static void
+file_free_hardlinks(struct xar *xar)
+{
+ struct archive_rb_node *n, *next;
+
+ for (n = ARCHIVE_RB_TREE_MIN(&(xar->hardlink_rbtree)); n;) {
+ next = __archive_rb_tree_iterate(&(xar->hardlink_rbtree),
+ n, ARCHIVE_RB_DIR_RIGHT);
+ free(n);
+ n = next;
+ }
+}
+
+static void
+checksum_init(struct chksumwork *sumwrk, enum sumalg sum_alg)
+{
+ sumwrk->alg = sum_alg;
+ switch (sum_alg) {
+ case CKSUM_NONE:
+ break;
+ case CKSUM_SHA1:
+ archive_sha1_init(&(sumwrk->sha1ctx));
+ break;
+ case CKSUM_MD5:
+ archive_md5_init(&(sumwrk->md5ctx));
+ break;
+ }
+}
+
+static void
+checksum_update(struct chksumwork *sumwrk, const void *buff, size_t size)
+{
+
+ switch (sumwrk->alg) {
+ case CKSUM_NONE:
+ break;
+ case CKSUM_SHA1:
+ archive_sha1_update(&(sumwrk->sha1ctx), buff, size);
+ break;
+ case CKSUM_MD5:
+ archive_md5_update(&(sumwrk->md5ctx), buff, size);
+ break;
+ }
+}
+
+static void
+checksum_final(struct chksumwork *sumwrk, struct chksumval *sumval)
+{
+
+ switch (sumwrk->alg) {
+ case CKSUM_NONE:
+ sumval->len = 0;
+ break;
+ case CKSUM_SHA1:
+ archive_sha1_final(&(sumwrk->sha1ctx), sumval->val);
+ sumval->len = SHA1_SIZE;
+ break;
+ case CKSUM_MD5:
+ archive_md5_final(&(sumwrk->md5ctx), sumval->val);
+ sumval->len = MD5_SIZE;
+ break;
+ }
+ sumval->alg = sumwrk->alg;
+}
+
+#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) || !defined(HAVE_LZMA_H)
+static int
+compression_unsupported_encoder(struct archive *a,
+ struct la_zstream *lastrm, const char *name)
+{
+
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "%s compression not supported on this platform", name);
+ lastrm->valid = 0;
+ lastrm->real_stream = NULL;
+ return (ARCHIVE_FAILED);
+}
+#endif
+
+static int
+compression_init_encoder_gzip(struct archive *a,
+ struct la_zstream *lastrm, int level, int withheader)
+{
+ z_stream *strm;
+
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ strm = calloc(1, sizeof(*strm));
+ if (strm == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate memory for gzip stream");
+ return (ARCHIVE_FATAL);
+ }
+ /* zlib.h is not const-correct, so we need this one bit
+ * of ugly hackery to convert a const * pointer to
+ * a non-const pointer. */
+ strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in;
+ strm->avail_in = lastrm->avail_in;
+ strm->total_in = (uLong)lastrm->total_in;
+ strm->next_out = lastrm->next_out;
+ strm->avail_out = lastrm->avail_out;
+ strm->total_out = (uLong)lastrm->total_out;
+ if (deflateInit2(strm, level, Z_DEFLATED,
+ (withheader)?15:-15,
+ 8, Z_DEFAULT_STRATEGY) != Z_OK) {
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library");
+ return (ARCHIVE_FATAL);
+ }
+ lastrm->real_stream = strm;
+ lastrm->valid = 1;
+ lastrm->code = compression_code_gzip;
+ lastrm->end = compression_end_gzip;
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_code_gzip(struct archive *a,
+ struct la_zstream *lastrm, enum la_zaction action)
+{
+ z_stream *strm;
+ int r;
+
+ strm = (z_stream *)lastrm->real_stream;
+ /* zlib.h is not const-correct, so we need this one bit
+ * of ugly hackery to convert a const * pointer to
+ * a non-const pointer. */
+ strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in;
+ strm->avail_in = lastrm->avail_in;
+ strm->total_in = (uLong)lastrm->total_in;
+ strm->next_out = lastrm->next_out;
+ strm->avail_out = lastrm->avail_out;
+ strm->total_out = (uLong)lastrm->total_out;
+ r = deflate(strm,
+ (action == ARCHIVE_Z_FINISH)? Z_FINISH: Z_NO_FLUSH);
+ lastrm->next_in = strm->next_in;
+ lastrm->avail_in = strm->avail_in;
+ lastrm->total_in = strm->total_in;
+ lastrm->next_out = strm->next_out;
+ lastrm->avail_out = strm->avail_out;
+ lastrm->total_out = strm->total_out;
+ switch (r) {
+ case Z_OK:
+ return (ARCHIVE_OK);
+ case Z_STREAM_END:
+ return (ARCHIVE_EOF);
+ default:
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "GZip compression failed:"
+ " deflate() call returned status %d", r);
+ return (ARCHIVE_FATAL);
+ }
+}
+
+static int
+compression_end_gzip(struct archive *a, struct la_zstream *lastrm)
+{
+ z_stream *strm;
+ int r;
+
+ strm = (z_stream *)lastrm->real_stream;
+ r = deflateEnd(strm);
+ free(strm);
+ lastrm->real_stream = NULL;
+ lastrm->valid = 0;
+ if (r != Z_OK) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Failed to clean up compressor");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+static int
+compression_init_encoder_bzip2(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+ bz_stream *strm;
+
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ strm = calloc(1, sizeof(*strm));
+ if (strm == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate memory for bzip2 stream");
+ return (ARCHIVE_FATAL);
+ }
+ /* bzlib.h is not const-correct, so we need this one bit
+ * of ugly hackery to convert a const * pointer to
+ * a non-const pointer. */
+ strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in;
+ strm->avail_in = lastrm->avail_in;
+ strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff);
+ strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32);
+ strm->next_out = (char *)lastrm->next_out;
+ strm->avail_out = lastrm->avail_out;
+ strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff);
+ strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32);
+ if (BZ2_bzCompressInit(strm, level, 0, 30) != BZ_OK) {
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library");
+ return (ARCHIVE_FATAL);
+ }
+ lastrm->real_stream = strm;
+ lastrm->valid = 1;
+ lastrm->code = compression_code_bzip2;
+ lastrm->end = compression_end_bzip2;
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_code_bzip2(struct archive *a,
+ struct la_zstream *lastrm, enum la_zaction action)
+{
+ bz_stream *strm;
+ int r;
+
+ strm = (bz_stream *)lastrm->real_stream;
+ /* bzlib.h is not const-correct, so we need this one bit
+ * of ugly hackery to convert a const * pointer to
+ * a non-const pointer. */
+ strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in;
+ strm->avail_in = lastrm->avail_in;
+ strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff);
+ strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32);
+ strm->next_out = (char *)lastrm->next_out;
+ strm->avail_out = lastrm->avail_out;
+ strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff);
+ strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32);
+ r = BZ2_bzCompress(strm,
+ (action == ARCHIVE_Z_FINISH)? BZ_FINISH: BZ_RUN);
+ lastrm->next_in = (const unsigned char *)strm->next_in;
+ lastrm->avail_in = strm->avail_in;
+ lastrm->total_in =
+ (((uint64_t)(uint32_t)strm->total_in_hi32) << 32)
+ + (uint64_t)(uint32_t)strm->total_in_lo32;
+ lastrm->next_out = (unsigned char *)strm->next_out;
+ lastrm->avail_out = strm->avail_out;
+ lastrm->total_out =
+ (((uint64_t)(uint32_t)strm->total_out_hi32) << 32)
+ + (uint64_t)(uint32_t)strm->total_out_lo32;
+ switch (r) {
+ case BZ_RUN_OK: /* Non-finishing */
+ case BZ_FINISH_OK: /* Finishing: There's more work to do */
+ return (ARCHIVE_OK);
+ case BZ_STREAM_END: /* Finishing: all done */
+ /* Only occurs in finishing case */
+ return (ARCHIVE_EOF);
+ default:
+ /* Any other return value indicates an error */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Bzip2 compression failed:"
+ " BZ2_bzCompress() call returned status %d", r);
+ return (ARCHIVE_FATAL);
+ }
+}
+
+static int
+compression_end_bzip2(struct archive *a, struct la_zstream *lastrm)
+{
+ bz_stream *strm;
+ int r;
+
+ strm = (bz_stream *)lastrm->real_stream;
+ r = BZ2_bzCompressEnd(strm);
+ free(strm);
+ lastrm->real_stream = NULL;
+ lastrm->valid = 0;
+ if (r != BZ_OK) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Failed to clean up compressor");
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+
+#else
+static int
+compression_init_encoder_bzip2(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+
+ (void) level; /* UNUSED */
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ return (compression_unsupported_encoder(a, lastrm, "bzip2"));
+}
+#endif
+
+#if defined(HAVE_LZMA_H)
+static int
+compression_init_encoder_lzma(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+ static const lzma_stream lzma_init_data = LZMA_STREAM_INIT;
+ lzma_stream *strm;
+ lzma_options_lzma lzma_opt;
+ int r;
+
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ if (lzma_lzma_preset(&lzma_opt, level)) {
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ENOMEM,
+ "Internal error initializing compression library");
+ return (ARCHIVE_FATAL);
+ }
+ strm = calloc(1, sizeof(*strm));
+ if (strm == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate memory for lzma stream");
+ return (ARCHIVE_FATAL);
+ }
+ *strm = lzma_init_data;
+ r = lzma_alone_encoder(strm, &lzma_opt);
+ switch (r) {
+ case LZMA_OK:
+ lastrm->real_stream = strm;
+ lastrm->valid = 1;
+ lastrm->code = compression_code_lzma;
+ lastrm->end = compression_end_lzma;
+ r = ARCHIVE_OK;
+ break;
+ case LZMA_MEM_ERROR:
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ENOMEM,
+ "Internal error initializing compression library: "
+ "Cannot allocate memory");
+ r = ARCHIVE_FATAL;
+ break;
+ default:
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ "It's a bug in liblzma");
+ r = ARCHIVE_FATAL;
+ break;
+ }
+ return (r);
+}
+
+static int
+compression_init_encoder_xz(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+ static const lzma_stream lzma_init_data = LZMA_STREAM_INIT;
+ lzma_stream *strm;
+ lzma_filter *lzmafilters;
+ lzma_options_lzma lzma_opt;
+ int r;
+
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ strm = calloc(1, sizeof(*strm) + sizeof(*lzmafilters) * 2);
+ if (strm == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate memory for xz stream");
+ return (ARCHIVE_FATAL);
+ }
+ lzmafilters = (lzma_filter *)(strm+1);
+ if (level > 6)
+ level = 6;
+ if (lzma_lzma_preset(&lzma_opt, level)) {
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ENOMEM,
+ "Internal error initializing compression library");
+ return (ARCHIVE_FATAL);
+ }
+ lzmafilters[0].id = LZMA_FILTER_LZMA2;
+ lzmafilters[0].options = &lzma_opt;
+ lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */
+
+ *strm = lzma_init_data;
+ r = lzma_stream_encoder(strm, lzmafilters, LZMA_CHECK_CRC64);
+ switch (r) {
+ case LZMA_OK:
+ lastrm->real_stream = strm;
+ lastrm->valid = 1;
+ lastrm->code = compression_code_lzma;
+ lastrm->end = compression_end_lzma;
+ r = ARCHIVE_OK;
+ break;
+ case LZMA_MEM_ERROR:
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ENOMEM,
+ "Internal error initializing compression library: "
+ "Cannot allocate memory");
+ r = ARCHIVE_FATAL;
+ break;
+ default:
+ free(strm);
+ lastrm->real_stream = NULL;
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Internal error initializing compression library: "
+ "It's a bug in liblzma");
+ r = ARCHIVE_FATAL;
+ break;
+ }
+ return (r);
+}
+
+static int
+compression_code_lzma(struct archive *a,
+ struct la_zstream *lastrm, enum la_zaction action)
+{
+ lzma_stream *strm;
+ int r;
+
+ strm = (lzma_stream *)lastrm->real_stream;
+ strm->next_in = lastrm->next_in;
+ strm->avail_in = lastrm->avail_in;
+ strm->total_in = lastrm->total_in;
+ strm->next_out = lastrm->next_out;
+ strm->avail_out = lastrm->avail_out;
+ strm->total_out = lastrm->total_out;
+ r = lzma_code(strm,
+ (action == ARCHIVE_Z_FINISH)? LZMA_FINISH: LZMA_RUN);
+ lastrm->next_in = strm->next_in;
+ lastrm->avail_in = strm->avail_in;
+ lastrm->total_in = strm->total_in;
+ lastrm->next_out = strm->next_out;
+ lastrm->avail_out = strm->avail_out;
+ lastrm->total_out = strm->total_out;
+ switch (r) {
+ case LZMA_OK:
+ /* Non-finishing case */
+ return (ARCHIVE_OK);
+ case LZMA_STREAM_END:
+ /* This return can only occur in finishing case. */
+ return (ARCHIVE_EOF);
+ case LZMA_MEMLIMIT_ERROR:
+ archive_set_error(a, ENOMEM,
+ "lzma compression error:"
+ " %ju MiB would have been needed",
+ (uintmax_t)((lzma_memusage(strm) + 1024 * 1024 -1)
+ / (1024 * 1024)));
+ return (ARCHIVE_FATAL);
+ default:
+ /* Any other return value indicates an error */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "lzma compression failed:"
+ " lzma_code() call returned status %d", r);
+ return (ARCHIVE_FATAL);
+ }
+}
+
+static int
+compression_end_lzma(struct archive *a, struct la_zstream *lastrm)
+{
+ lzma_stream *strm;
+
+ (void)a; /* UNUSED */
+ strm = (lzma_stream *)lastrm->real_stream;
+ lzma_end(strm);
+ free(strm);
+ lastrm->valid = 0;
+ lastrm->real_stream = NULL;
+ return (ARCHIVE_OK);
+}
+#else
+static int
+compression_init_encoder_lzma(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+
+ (void) level; /* UNUSED */
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ return (compression_unsupported_encoder(a, lastrm, "lzma"));
+}
+static int
+compression_init_encoder_xz(struct archive *a,
+ struct la_zstream *lastrm, int level)
+{
+
+ (void) level; /* UNUSED */
+ if (lastrm->valid)
+ compression_end(a, lastrm);
+ return (compression_unsupported_encoder(a, lastrm, "xz"));
+}
+#endif
+
+static int
+xar_compression_init_encoder(struct archive_write *a)
+{
+ struct xar *xar;
+ int r;
+
+ xar = (struct xar *)a->format_data;
+ switch (xar->opt_compression) {
+ case GZIP:
+ r = compression_init_encoder_gzip(
+ &(a->archive), &(xar->stream),
+ xar->opt_compression_level, 1);
+ break;
+ case BZIP2:
+ r = compression_init_encoder_bzip2(
+ &(a->archive), &(xar->stream),
+ xar->opt_compression_level);
+ break;
+ case LZMA:
+ r = compression_init_encoder_lzma(
+ &(a->archive), &(xar->stream),
+ xar->opt_compression_level);
+ break;
+ case XZ:
+ r = compression_init_encoder_xz(
+ &(a->archive), &(xar->stream),
+ xar->opt_compression_level);
+ break;
+ default:
+ r = ARCHIVE_OK;
+ break;
+ }
+ if (r == ARCHIVE_OK) {
+ xar->stream.total_in = 0;
+ xar->stream.next_out = xar->wbuff;
+ xar->stream.avail_out = sizeof(xar->wbuff);
+ xar->stream.total_out = 0;
+ }
+
+ return (r);
+}
+
+static int
+compression_code(struct archive *a, struct la_zstream *lastrm,
+ enum la_zaction action)
+{
+ if (lastrm->valid)
+ return (lastrm->code(a, lastrm, action));
+ return (ARCHIVE_OK);
+}
+
+static int
+compression_end(struct archive *a, struct la_zstream *lastrm)
+{
+ if (lastrm->valid)
+ return (lastrm->end(a, lastrm));
+ return (ARCHIVE_OK);
+}
+
+
+static int
+save_xattrs(struct archive_write *a, struct file *file)
+{
+ struct xar *xar;
+ const char *name;
+ const void *value;
+ struct heap_data *heap;
+ size_t size;
+ int count, r;
+
+ xar = (struct xar *)a->format_data;
+ count = archive_entry_xattr_reset(file->entry);
+ if (count == 0)
+ return (ARCHIVE_OK);
+ while (count--) {
+ archive_entry_xattr_next(file->entry,
+ &name, &value, &size);
+ checksum_init(&(xar->a_sumwrk), xar->opt_sumalg);
+ checksum_init(&(xar->e_sumwrk), xar->opt_sumalg);
+
+ heap = calloc(1, sizeof(*heap));
+ if (heap == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for xattr");
+ return (ARCHIVE_FATAL);
+ }
+ heap->id = file->ea_idx++;
+ heap->temp_offset = xar->temp_offset;
+ heap->size = size;/* save a extracted size */
+ heap->compression = xar->opt_compression;
+ /* Get a extracted sumcheck value. */
+ checksum_update(&(xar->e_sumwrk), value, size);
+ checksum_final(&(xar->e_sumwrk), &(heap->e_sum));
+
+ /*
+ * Not compression to xattr is simple way.
+ */
+ if (heap->compression == NONE) {
+ checksum_update(&(xar->a_sumwrk), value, size);
+ checksum_final(&(xar->a_sumwrk), &(heap->a_sum));
+ if (write_to_temp(a, value, size)
+ != ARCHIVE_OK) {
+ free(heap);
+ return (ARCHIVE_FATAL);
+ }
+ heap->length = size;
+ /* Add heap to the tail of file->xattr. */
+ heap->next = NULL;
+ *file->xattr.last = heap;
+ file->xattr.last = &(heap->next);
+ /* Next xattr */
+ continue;
+ }
+
+ /*
+ * Init compression library.
+ */
+ r = xar_compression_init_encoder(a);
+ if (r != ARCHIVE_OK) {
+ free(heap);
+ return (ARCHIVE_FATAL);
+ }
+
+ xar->stream.next_in = (const unsigned char *)value;
+ xar->stream.avail_in = size;
+ for (;;) {
+ r = compression_code(&(a->archive),
+ &(xar->stream), ARCHIVE_Z_FINISH);
+ if (r != ARCHIVE_OK && r != ARCHIVE_EOF) {
+ free(heap);
+ return (ARCHIVE_FATAL);
+ }
+ size = sizeof(xar->wbuff) - xar->stream.avail_out;
+ checksum_update(&(xar->a_sumwrk),
+ xar->wbuff, size);
+ if (write_to_temp(a, xar->wbuff, size)
+ != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ if (r == ARCHIVE_OK) {
+ xar->stream.next_out = xar->wbuff;
+ xar->stream.avail_out = sizeof(xar->wbuff);
+ } else {
+ checksum_final(&(xar->a_sumwrk),
+ &(heap->a_sum));
+ heap->length = xar->stream.total_out;
+ /* Add heap to the tail of file->xattr. */
+ heap->next = NULL;
+ *file->xattr.last = heap;
+ file->xattr.last = &(heap->next);
+ break;
+ }
+ }
+ /* Clean up compression library. */
+ r = compression_end(&(a->archive), &(xar->stream));
+ if (r != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+ return (ARCHIVE_OK);
+}
+
+static int
+getalgsize(enum sumalg sumalg)
+{
+ switch (sumalg) {
+ default:
+ case CKSUM_NONE:
+ return (0);
+ case CKSUM_SHA1:
+ return (SHA1_SIZE);
+ case CKSUM_MD5:
+ return (MD5_SIZE);
+ }
+}
+
+static const char *
+getalgname(enum sumalg sumalg)
+{
+ switch (sumalg) {
+ default:
+ case CKSUM_NONE:
+ return (NULL);
+ case CKSUM_SHA1:
+ return (SHA1_NAME);
+ case CKSUM_MD5:
+ return (MD5_NAME);
+ }
+}
+
+#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
new file mode 100644
index 0000000000..3b07e35ba3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c
@@ -0,0 +1,1126 @@
+/*-
+ * Copyright (c) 2008 Anselm Strauss
+ * Copyright (c) 2009 Joerg Sonnenberger
+ * Copyright (c) 2011-2012 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.
+ */
+
+/*
+ * Development supported by Google Summer of Code 2008.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_zip.c 201168 2009-12-29 06:15:32Z kientzle $");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <cm_zlib.h>
+#endif
+
+#include "archive.h"
+#include "archive_endian.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+
+#ifndef HAVE_ZLIB_H
+#include "archive_crc32.h"
+#endif
+
+#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,
+ COMPRESSION_DEFLATE = 8
+};
+
+#ifdef HAVE_ZLIB_H
+#define COMPRESSION_DEFAULT COMPRESSION_DEFLATE
+#else
+#define COMPRESSION_DEFAULT COMPRESSION_STORE
+#endif
+
+struct cd_segment {
+ struct cd_segment *next;
+ size_t buff_size;
+ unsigned char *buff;
+ unsigned char *p;
+};
+
+/* Bits used to enable/disable certain experimental features. */
+#define EXPERIMENT_LA 1
+#define EXPERIMENTS_ALL 0xffff
+
+struct zip {
+
+ int64_t entry_offset;
+ int64_t entry_compressed_size;
+ int64_t entry_uncompressed_size;
+ int64_t entry_compressed_written;
+ int64_t entry_uncompressed_written;
+ int64_t entry_uncompressed_limit;
+ struct archive_entry *entry;
+ uint32_t entry_crc32;
+ enum compression entry_compression;
+ int entry_flags;
+ int entry_uses_zip64;
+ int experiments;
+
+ unsigned char *file_header;
+ size_t file_header_extra_offset;
+ unsigned long (*crc32func)(unsigned long crc, const void *buff, size_t len);
+
+ struct cd_segment *central_directory;
+ struct cd_segment *central_directory_last;
+ size_t central_directory_bytes;
+ size_t central_directory_entries;
+
+ int64_t written_bytes; /* Overall position in file. */
+
+ struct archive_string_conv *opt_sconv;
+ struct archive_string_conv *sconv_default;
+ enum compression requested_compression;
+ int init_default_conversion;
+
+#define ZIP_FLAG_AVOID_ZIP64 1
+#define ZIP_FLAG_FORCE_ZIP64 2
+#define ZIP_FLAG_EXPERIMENT_EL 4
+ int flags;
+
+#ifdef HAVE_ZLIB_H
+ z_stream stream;
+ size_t len_buf;
+ unsigned char *buf;
+#endif
+};
+
+/* Don't call this min or MIN, since those are already defined
+ on lots of platforms (but not all). */
+#define zipmin(a, b) ((a) > (b) ? (b) : (a))
+
+static ssize_t archive_write_zip_data(struct archive_write *,
+ const void *buff, size_t s);
+static int archive_write_zip_close(struct archive_write *);
+static int archive_write_zip_free(struct archive_write *);
+static int archive_write_zip_finish_entry(struct archive_write *);
+static int archive_write_zip_header(struct archive_write *,
+ struct archive_entry *);
+static int archive_write_zip_options(struct archive_write *,
+ const char *, const char *);
+static unsigned int dos_time(const time_t);
+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 unsigned char *
+cd_alloc(struct zip *zip, size_t length)
+{
+ unsigned char *p;
+
+ if (zip->central_directory == NULL
+ || (zip->central_directory_last->p + length
+ > zip->central_directory_last->buff + zip->central_directory_last->buff_size)) {
+ struct cd_segment *segment = calloc(1, sizeof(*segment));
+ if (segment == NULL)
+ return NULL;
+ segment->buff_size = 64 * 1024;
+ segment->buff = malloc(segment->buff_size);
+ if (segment->buff == NULL) {
+ free(segment);
+ return NULL;
+ }
+ segment->p = segment->buff;
+
+ if (zip->central_directory == NULL) {
+ zip->central_directory
+ = zip->central_directory_last
+ = segment;
+ } else {
+ zip->central_directory_last->next = segment;
+ zip->central_directory_last = segment;
+ }
+ }
+
+ p = zip->central_directory_last->p;
+ zip->central_directory_last->p += length;
+ zip->central_directory_bytes += length;
+ return (p);
+}
+
+static unsigned long
+real_crc32(unsigned long crc, const void *buff, size_t len)
+{
+ return crc32(crc, buff, len);
+}
+
+static unsigned long
+fake_crc32(unsigned long crc, const void *buff, size_t len)
+{
+ (void)crc; /* UNUSED */
+ (void)buff; /* UNUSED */
+ (void)len; /* UNUSED */
+ return 0;
+}
+
+static int
+archive_write_zip_options(struct archive_write *a, const char *key,
+ const char *val)
+{
+ struct zip *zip = a->format_data;
+ int ret = ARCHIVE_FAILED;
+
+ if (strcmp(key, "compression") == 0) {
+ /*
+ * Set compression to use on all future entries.
+ * This only affects regular files.
+ */
+ if (val == NULL || val[0] == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s: compression option needs a compression name",
+ a->format_name);
+ } else if (strcmp(val, "deflate") == 0) {
+#ifdef HAVE_ZLIB_H
+ zip->requested_compression = COMPRESSION_DEFLATE;
+ ret = ARCHIVE_OK;
+#else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "deflate compression not supported");
+#endif
+ } else if (strcmp(val, "store") == 0) {
+ zip->requested_compression = COMPRESSION_STORE;
+ ret = ARCHIVE_OK;
+ }
+ return (ret);
+ } else if (strcmp(key, "experimental") == 0) {
+ if (val == NULL || val[0] == 0) {
+ zip->flags &= ~ ZIP_FLAG_EXPERIMENT_EL;
+ } else {
+ zip->flags |= ZIP_FLAG_EXPERIMENT_EL;
+ }
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "fakecrc32") == 0) {
+ /*
+ * FOR TESTING ONLY: disable CRC calculation to speed up
+ * certain complex tests.
+ */
+ if (val == NULL || val[0] == 0) {
+ zip->crc32func = real_crc32;
+ } else {
+ zip->crc32func = fake_crc32;
+ }
+ return (ARCHIVE_OK);
+ } else if (strcmp(key, "hdrcharset") == 0) {
+ /*
+ * Set the character set used in translating filenames.
+ */
+ if (val == NULL || val[0] == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "%s: hdrcharset option needs a character-set name",
+ a->format_name);
+ } else {
+ zip->opt_sconv = archive_string_conversion_to_charset(
+ &a->archive, val, 0);
+ if (zip->opt_sconv != NULL)
+ ret = ARCHIVE_OK;
+ else
+ ret = ARCHIVE_FATAL;
+ }
+ return (ret);
+ } else if (strcmp(key, "zip64") == 0) {
+ /*
+ * Bias decisions about Zip64: force them to be
+ * generated in certain cases where they are not
+ * forbidden or avoid them in certain cases where they
+ * are not strictly required.
+ */
+ if (val != NULL && *val != '\0') {
+ zip->flags |= ZIP_FLAG_FORCE_ZIP64;
+ zip->flags &= ~ZIP_FLAG_AVOID_ZIP64;
+ } else {
+ zip->flags &= ~ZIP_FLAG_FORCE_ZIP64;
+ zip->flags |= ZIP_FLAG_AVOID_ZIP64;
+ }
+ 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);
+}
+
+int
+archive_write_zip_set_compression_deflate(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ int ret = ARCHIVE_FAILED;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW | ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_write_zip_set_compression_deflate");
+ if (a->archive.archive_format != ARCHIVE_FORMAT_ZIP) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can only use archive_write_zip_set_compression_deflate"
+ " with zip format");
+ ret = ARCHIVE_FATAL;
+ } else {
+#ifdef HAVE_ZLIB_H
+ struct zip *zip = a->format_data;
+ zip->requested_compression = COMPRESSION_DEFLATE;
+ ret = ARCHIVE_OK;
+#else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "deflate compression not supported");
+ ret = ARCHIVE_FAILED;
+#endif
+ }
+ return (ret);
+}
+
+int
+archive_write_zip_set_compression_store(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct zip *zip = a->format_data;
+ int ret = ARCHIVE_FAILED;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW | ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
+ "archive_write_zip_set_compression_deflate");
+ if (a->archive.archive_format != ARCHIVE_FORMAT_ZIP) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Can only use archive_write_zip_set_compression_store"
+ " with zip format");
+ ret = ARCHIVE_FATAL;
+ } else {
+ zip->requested_compression = COMPRESSION_STORE;
+ ret = ARCHIVE_OK;
+ }
+ return (ret);
+}
+
+int
+archive_write_set_format_zip(struct archive *_a)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct zip *zip;
+
+ archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_write_set_format_zip");
+
+ /* If another format was already registered, unregister it. */
+ if (a->format_free != NULL)
+ (a->format_free)(a);
+
+ zip = (struct zip *) calloc(1, sizeof(*zip));
+ if (zip == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate zip data");
+ return (ARCHIVE_FATAL);
+ }
+
+ /* "Unspecified" lets us choose the appropriate compression. */
+ zip->requested_compression = COMPRESSION_UNSPECIFIED;
+ zip->crc32func = real_crc32;
+
+#ifdef HAVE_ZLIB_H
+ zip->len_buf = 65536;
+ zip->buf = malloc(zip->len_buf);
+ if (zip->buf == NULL) {
+ free(zip);
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate compression buffer");
+ return (ARCHIVE_FATAL);
+ }
+#endif
+
+ a->format_data = zip;
+ a->format_name = "zip";
+ a->format_options = archive_write_zip_options;
+ a->format_write_header = archive_write_zip_header;
+ a->format_write_data = archive_write_zip_data;
+ a->format_finish_entry = archive_write_zip_finish_entry;
+ a->format_close = archive_write_zip_close;
+ a->format_free = archive_write_zip_free;
+ a->archive.archive_format = ARCHIVE_FORMAT_ZIP;
+ a->archive.archive_format_name = "ZIP";
+
+ return (ARCHIVE_OK);
+}
+
+static int
+is_all_ascii(const char *p)
+{
+ const unsigned char *pp = (const unsigned char *)p;
+
+ while (*pp) {
+ if (*pp++ > 127)
+ return (0);
+ }
+ return (1);
+}
+
+static int
+archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
+{
+ unsigned char local_header[32];
+ unsigned char local_extra[128];
+ struct zip *zip = a->format_data;
+ unsigned char *e;
+ unsigned char *cd_extra;
+ size_t filename_length;
+ const char *slink = NULL;
+ 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;
+
+ /* Ignore types of entries that we don't support. */
+ type = archive_entry_filetype(entry);
+ if (type != AE_IFREG && type != AE_IFDIR && type != AE_IFLNK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Filetype not supported");
+ return ARCHIVE_FAILED;
+ };
+
+ /* If we're not using Zip64, reject large files. */
+ if (zip->flags & ZIP_FLAG_AVOID_ZIP64) {
+ /* Reject entries over 4GB. */
+ if (archive_entry_size_is_set(entry)
+ && (archive_entry_size(entry) > 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) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Archives > 4GB require Zip64 extensions");
+ return ARCHIVE_FAILED;
+ }
+ }
+
+ /* Only regular files can have size > 0. */
+ if (type != AE_IFREG)
+ archive_entry_set_size(entry, 0);
+
+
+ /* Reset information from last entry. */
+ zip->entry_offset = zip->written_bytes;
+ zip->entry_uncompressed_limit = INT64_MAX;
+ zip->entry_compressed_size = 0;
+ zip->entry_uncompressed_size = 0;
+ zip->entry_compressed_written = 0;
+ zip->entry_uncompressed_written = 0;
+ zip->entry_flags = 0;
+ zip->entry_uses_zip64 = 0;
+ zip->entry_crc32 = zip->crc32func(0, NULL, 0);
+ if (zip->entry != NULL) {
+ archive_entry_free(zip->entry);
+ zip->entry = NULL;
+ }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Make sure the path separators in pahtname, hardlink and symlink
+ * are all slash '/', not the Windows path separator '\'. */
+ zip->entry = __la_win_entry_in_posix_pathseparator(entry);
+ if (zip->entry == entry)
+ zip->entry = archive_entry_clone(entry);
+#else
+ zip->entry = archive_entry_clone(entry);
+#endif
+ if (zip->entry == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate zip header data");
+ return (ARCHIVE_FATAL);
+ }
+
+ if (sconv != NULL) {
+ const char *p;
+ size_t len;
+
+ if (archive_entry_pathname_l(entry, &p, &len, sconv) != 0) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory for Pathname");
+ return (ARCHIVE_FATAL);
+ }
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Can't translate Pathname '%s' to %s",
+ archive_entry_pathname(entry),
+ archive_string_conversion_charset_name(sconv));
+ ret2 = ARCHIVE_WARN;
+ }
+ if (len > 0)
+ archive_entry_set_pathname(zip->entry, p);
+
+ /*
+ * There is no standard for symlink handling; we convert
+ * it using the same character-set translation that we use
+ * for filename.
+ */
+ if (type == AE_IFLNK) {
+ if (archive_entry_symlink_l(entry, &p, &len, sconv)) {
+ if (errno == ENOMEM) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate memory "
+ " for Symlink");
+ return (ARCHIVE_FATAL);
+ }
+ /* No error if we can't convert. */
+ } else if (len > 0)
+ archive_entry_set_symlink(zip->entry, p);
+ }
+ }
+
+ /* If filename isn't ASCII and we can use UTF-8, set the UTF-8 flag. */
+ if (!is_all_ascii(archive_entry_pathname(zip->entry))) {
+ if (zip->opt_sconv != NULL) {
+ if (strcmp(archive_string_conversion_charset_name(
+ zip->opt_sconv), "UTF-8") == 0)
+ zip->entry_flags |= ZIP_ENTRY_FLAG_UTF8_NAME;
+#if HAVE_NL_LANGINFO
+ } else if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0) {
+ zip->entry_flags |= ZIP_ENTRY_FLAG_UTF8_NAME;
+#endif
+ }
+ }
+ filename_length = path_length(zip->entry);
+
+ /* Determine appropriate compression and size for this entry. */
+ if (type == AE_IFLNK) {
+ slink = archive_entry_symlink(zip->entry);
+ if (slink != NULL)
+ slink_size = strlen(slink);
+ else
+ slink_size = 0;
+ zip->entry_uncompressed_limit = slink_size;
+ zip->entry_compressed_size = slink_size;
+ zip->entry_uncompressed_size = slink_size;
+ zip->entry_crc32 = zip->crc32func(zip->entry_crc32,
+ (const unsigned char *)slink, slink_size);
+ zip->entry_compression = COMPRESSION_STORE;
+ version_needed = 20;
+ } 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);
+ zip->entry_uncompressed_limit = size;
+ zip->entry_compression = zip->requested_compression;
+ if (zip->entry_compression == COMPRESSION_UNSPECIFIED) {
+ zip->entry_compression = COMPRESSION_DEFAULT;
+ }
+ if (zip->entry_compression == COMPRESSION_STORE) {
+ zip->entry_compressed_size = size;
+ zip->entry_uncompressed_size = size;
+ version_needed = 10;
+ } else {
+ 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. */
+ zip->entry_uses_zip64 = 1;
+ version_needed = 45;
+ }
+
+ /* 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. */
+ zip->entry_compression = COMPRESSION_DEFAULT;
+ zip->entry_flags |= ZIP_ENTRY_FLAG_LENGTH_AT_END;
+ if ((zip->flags & ZIP_FLAG_AVOID_ZIP64) == 0) {
+ zip->entry_uses_zip64 = 1;
+ version_needed = 45;
+ } else if (zip->entry_compression == COMPRESSION_STORE) {
+ version_needed = 10;
+ } else {
+ version_needed = 20;
+ }
+ }
+
+ /* Format the local header. */
+ memset(local_header, 0, sizeof(local_header));
+ 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)));
+ archive_le32enc(local_header + 14, zip->entry_crc32);
+ if (zip->entry_uses_zip64) {
+ /* Zip64 data in the local header "must" include both
+ * compressed and uncompressed sizes AND those fields
+ * are included only if these are 0xffffffff;
+ * THEREFORE these must be set this way, even if we
+ * know one of them is smaller. */
+ 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_le16enc(local_header + 26, filename_length);
+
+ /* Format as much of central directory file header as we can: */
+ zip->file_header = cd_alloc(zip, 46);
+ /* If (zip->file_header == NULL) XXXX */
+ ++zip->central_directory_entries;
+ memset(zip->file_header, 0, 46);
+ memcpy(zip->file_header, "PK\001\002", 4);
+ /* "Made by PKZip 2.0 on Unix." */
+ 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);
+ /* Following Info-Zip, store mode in the "external attributes" field. */
+ archive_le32enc(zip->file_header + 38,
+ ((uint32_t)archive_entry_mode(zip->entry)) << 16);
+ e = cd_alloc(zip, filename_length);
+ /* If (e == NULL) XXXX */
+ copy_path(zip->entry, e);
+
+ /* Format extra data. */
+ memset(local_extra, 0, sizeof(local_extra));
+ e = local_extra;
+
+ /* First, extra blocks that are the same between
+ * the local file header and the central directory.
+ * We format them once and then duplicate them. */
+
+ /* UT timestamp, length depends on what timestamps are set. */
+ memcpy(e, "UT", 2);
+ archive_le16enc(e + 2,
+ 1
+ + (archive_entry_mtime_is_set(entry) ? 4 : 0)
+ + (archive_entry_atime_is_set(entry) ? 4 : 0)
+ + (archive_entry_ctime_is_set(entry) ? 4 : 0));
+ e += 4;
+ *e++ =
+ (archive_entry_mtime_is_set(entry) ? 1 : 0)
+ | (archive_entry_atime_is_set(entry) ? 2 : 0)
+ | (archive_entry_ctime_is_set(entry) ? 4 : 0);
+ if (archive_entry_mtime_is_set(entry)) {
+ archive_le32enc(e, (uint32_t)archive_entry_mtime(entry));
+ e += 4;
+ }
+ if (archive_entry_atime_is_set(entry)) {
+ archive_le32enc(e, (uint32_t)archive_entry_atime(entry));
+ e += 4;
+ }
+ if (archive_entry_ctime_is_set(entry)) {
+ archive_le32enc(e, (uint32_t)archive_entry_ctime(entry));
+ e += 4;
+ }
+
+ /* ux Unix extra data, length 11, version 1 */
+ /* TODO: If uid < 64k, use 2 bytes, ditto for gid. */
+ memcpy(e, "ux\013\000\001", 5);
+ e += 5;
+ *e++ = 4; /* Length of following UID */
+ archive_le32enc(e, (uint32_t)archive_entry_uid(entry));
+ e += 4;
+ *e++ = 4; /* Length of following GID */
+ archive_le32enc(e, (uint32_t)archive_entry_gid(entry));
+ e += 4;
+
+ /* Copy UT and ux 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);
+
+ /*
+ * Following extra blocks vary between local header and
+ * central directory. These are the local header versions.
+ * Central directory versions get formatted in
+ * archive_write_zip_finish_entry() below.
+ */
+
+ /* "[Zip64 entry] in the local header MUST include BOTH
+ * original [uncompressed] and compressed size fields." */
+ if (zip->entry_uses_zip64) {
+ unsigned char *zip64_start = e;
+ memcpy(e, "\001\000\020\000", 4);
+ e += 4;
+ archive_le64enc(e, zip->entry_uncompressed_size);
+ e += 8;
+ archive_le64enc(e, zip->entry_compressed_size);
+ e += 8;
+ archive_le16enc(zip64_start + 2, e - (zip64_start + 4));
+ }
+
+ if (zip->flags & ZIP_FLAG_EXPERIMENT_EL) {
+ /* Experimental 'el' extension to improve streaming. */
+ unsigned char *external_info = e;
+ int included = 7;
+ memcpy(e, "el\000\000", 4); // 0x6c65 + 2-byte length
+ e += 4;
+ e[0] = included; /* bitmap of included fields */
+ e += 1;
+ if (included & 1) {
+ archive_le16enc(e, /* "Version created by" */
+ 3 * 256 + version_needed);
+ e += 2;
+ }
+ if (included & 2) {
+ archive_le16enc(e, 0); /* internal file attributes */
+ e += 2;
+ }
+ if (included & 4) {
+ archive_le32enc(e, /* external file attributes */
+ ((uint32_t)archive_entry_mode(zip->entry)) << 16);
+ e += 4;
+ }
+ if (included & 8) {
+ // Libarchive does not currently support file comments.
+ }
+ archive_le16enc(external_info + 2, 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);
+
+ ret = __archive_write_output(a, local_header, 30);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ zip->written_bytes += 30;
+
+ ret = write_path(zip->entry, a);
+ if (ret <= ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ zip->written_bytes += ret;
+
+ ret = __archive_write_output(a, local_extra, e - local_extra);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ zip->written_bytes += e - local_extra;
+
+ /* For symlinks, write the body now. */
+ if (slink != NULL) {
+ ret = __archive_write_output(a, slink, slink_size);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ zip->entry_compressed_written += slink_size;
+ zip->entry_uncompressed_written += slink_size;
+ zip->written_bytes += slink_size;
+ }
+
+#ifdef HAVE_ZLIB_H
+ if (zip->entry_compression == COMPRESSION_DEFLATE) {
+ zip->stream.zalloc = Z_NULL;
+ zip->stream.zfree = Z_NULL;
+ 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,
+ Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't init deflate compressor");
+ return (ARCHIVE_FATAL);
+ }
+ }
+#endif
+
+ return (ret2);
+}
+
+static ssize_t
+archive_write_zip_data(struct archive_write *a, const void *buff, size_t s)
+{
+ int ret;
+ struct zip *zip = a->format_data;
+
+ if ((int64_t)s > zip->entry_uncompressed_limit)
+ s = (size_t)zip->entry_uncompressed_limit;
+ zip->entry_uncompressed_written += s;
+
+ if (s == 0) return 0;
+
+ 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;
+ break;
+#if HAVE_ZLIB_H
+ case COMPRESSION_DEFLATE:
+ zip->stream.next_in = (unsigned char*)(uintptr_t)buff;
+ zip->stream.avail_in = (uInt)s;
+ do {
+ ret = deflate(&zip->stream, Z_NO_FLUSH);
+ if (ret == Z_STREAM_ERROR)
+ return (ARCHIVE_FATAL);
+ if (zip->stream.avail_out == 0) {
+ ret = __archive_write_output(a, zip->buf,
+ zip->len_buf);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ zip->entry_compressed_written += zip->len_buf;
+ zip->written_bytes += zip->len_buf;
+ zip->stream.next_out = zip->buf;
+ zip->stream.avail_out = (uInt)zip->len_buf;
+ }
+ } while (zip->stream.avail_in != 0);
+ break;
+#endif
+
+ default:
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Invalid ZIP compression type");
+ return ARCHIVE_FATAL;
+ }
+
+ zip->entry_uncompressed_limit -= s;
+ zip->entry_crc32 = zip->crc32func(zip->entry_crc32, buff, (unsigned)s);
+ return (s);
+
+}
+
+static int
+archive_write_zip_finish_entry(struct archive_write *a)
+{
+ struct zip *zip = a->format_data;
+ int ret;
+
+#if HAVE_ZLIB_H
+ 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;
+ ret = __archive_write_output(a, zip->buf, remainder);
+ if (ret != ARCHIVE_OK)
+ return (ret);
+ zip->entry_compressed_written += remainder;
+ zip->written_bytes += remainder;
+ zip->stream.next_out = zip->buf;
+ if (zip->stream.avail_out != 0)
+ break;
+ zip->stream.avail_out = (uInt)zip->len_buf;
+ }
+ deflateEnd(&zip->stream);
+ }
+#endif
+
+ /* 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->entry_uses_zip64) {
+ 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);
+ ret = __archive_write_output(a, d, 16);
+ zip->written_bytes += 16;
+ }
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ }
+
+ /* Append Zip64 extra data to central directory information. */
+ if (zip->entry_compressed_written > ARCHIVE_LITERAL_LL(0xffffffff)
+ || zip->entry_uncompressed_written > ARCHIVE_LITERAL_LL(0xffffffff)
+ || zip->entry_offset > ARCHIVE_LITERAL_LL(0xffffffff)) {
+ unsigned char zip64[32];
+ unsigned char *z = zip64, *zd;
+ memcpy(z, "\001\000\000\000", 4);
+ z += 4;
+ if (zip->entry_uncompressed_written >= ARCHIVE_LITERAL_LL(0xffffffff)) {
+ archive_le64enc(z, zip->entry_uncompressed_written);
+ z += 8;
+ }
+ if (zip->entry_compressed_written >= ARCHIVE_LITERAL_LL(0xffffffff)) {
+ archive_le64enc(z, zip->entry_compressed_written);
+ z += 8;
+ }
+ if (zip->entry_offset >= ARCHIVE_LITERAL_LL(0xffffffff)) {
+ archive_le64enc(z, zip->entry_offset);
+ z += 8;
+ }
+ archive_le16enc(zip64 + 2, z - (zip64 + 4));
+ zd = cd_alloc(zip, z - zip64);
+ if (zd == NULL) {
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate zip data");
+ return (ARCHIVE_FATAL);
+ }
+ memcpy(zd, zip64, z - zip64);
+ /* Zip64 means version needs to be set to at least 4.5 */
+ if (archive_le16dec(zip->file_header + 6) < 45)
+ archive_le16enc(zip->file_header + 6, 45);
+ }
+
+ /* Fix up central directory file header. */
+ archive_le32enc(zip->file_header + 16, zip->entry_crc32);
+ archive_le32enc(zip->file_header + 20,
+ zipmin(zip->entry_compressed_written, ARCHIVE_LITERAL_LL(0xffffffff)));
+ archive_le32enc(zip->file_header + 24,
+ zipmin(zip->entry_uncompressed_written, ARCHIVE_LITERAL_LL(0xffffffff)));
+ archive_le16enc(zip->file_header + 30,
+ zip->central_directory_bytes - zip->file_header_extra_offset);
+ archive_le32enc(zip->file_header + 42,
+ zipmin(zip->entry_offset, ARCHIVE_LITERAL_LL(0xffffffff)));
+
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_zip_close(struct archive_write *a)
+{
+ uint8_t buff[64];
+ int64_t offset_start, offset_end;
+ struct zip *zip = a->format_data;
+ struct cd_segment *segment;
+ int ret;
+
+ offset_start = zip->written_bytes;
+ segment = zip->central_directory;
+ while (segment != NULL) {
+ ret = __archive_write_output(a,
+ segment->buff, segment->p - segment->buff);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ zip->written_bytes += segment->p - segment->buff;
+ segment = segment->next;
+ }
+ offset_end = zip->written_bytes;
+
+ /* If central dir info is too large, write Zip64 end-of-cd */
+ if (offset_end - offset_start > ARCHIVE_LITERAL_LL(0xffffffff)
+ || offset_start > ARCHIVE_LITERAL_LL(0xffffffff)
+ || zip->central_directory_entries > 0xffffUL
+ || (zip->flags & ZIP_FLAG_FORCE_ZIP64)) {
+ /* Zip64 end-of-cd record */
+ memset(buff, 0, 56);
+ memcpy(buff, "PK\006\006", 4);
+ archive_le64enc(buff + 4, 44);
+ archive_le16enc(buff + 12, 45);
+ archive_le16enc(buff + 14, 45);
+ /* This is disk 0 of 0. */
+ archive_le64enc(buff + 24, zip->central_directory_entries);
+ archive_le64enc(buff + 32, zip->central_directory_entries);
+ archive_le64enc(buff + 40, offset_end - offset_start);
+ archive_le64enc(buff + 48, offset_start);
+ ret = __archive_write_output(a, buff, 56);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ zip->written_bytes += 56;
+
+ /* Zip64 end-of-cd locator record. */
+ memset(buff, 0, 20);
+ memcpy(buff, "PK\006\007", 4);
+ archive_le32enc(buff + 4, 0);
+ archive_le64enc(buff + 8, offset_end);
+ archive_le32enc(buff + 16, 1);
+ ret = __archive_write_output(a, buff, 20);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ zip->written_bytes += 20;
+
+ }
+
+ /* 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));
+ ret = __archive_write_output(a, buff, 22);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ zip->written_bytes += 22;
+ return (ARCHIVE_OK);
+}
+
+static int
+archive_write_zip_free(struct archive_write *a)
+{
+ struct zip *zip;
+ struct cd_segment *segment;
+
+ zip = a->format_data;
+ while (zip->central_directory != NULL) {
+ segment = zip->central_directory;
+ zip->central_directory = segment->next;
+ free(segment->buff);
+ free(segment);
+ }
+#ifdef HAVE_ZLIB_H
+ free(zip->buf);
+#endif
+ archive_entry_free(zip->entry);
+ /* TODO: Free opt_sconv, sconv_default */
+
+ free(zip);
+ a->format_data = NULL;
+ return (ARCHIVE_OK);
+}
+
+/* Convert into MSDOS-style date/time. */
+static unsigned int
+dos_time(const time_t unix_time)
+{
+ struct tm *t;
+ unsigned int dt;
+
+ /* This will not preserve time when creating/extracting the archive
+ * on two systems with different time zones. */
+ t = localtime(&unix_time);
+
+ /* MSDOS-style date/time is only between 1980-01-01 and 2107-12-31 */
+ if (t->tm_year < 1980 - 1900)
+ /* Set minimum date/time '1980-01-01 00:00:00'. */
+ dt = 0x00210000U;
+ else if (t->tm_year > 2107 - 1900)
+ /* Set maximum date/time '2107-12-31 23:59:58'. */
+ dt = 0xff9fbf7dU;
+ else {
+ dt = 0;
+ dt += ((t->tm_year - 80) & 0x7f) << 9;
+ dt += ((t->tm_mon + 1) & 0x0f) << 5;
+ dt += (t->tm_mday & 0x1f);
+ dt <<= 16;
+ dt += (t->tm_hour & 0x1f) << 11;
+ dt += (t->tm_min & 0x3f) << 5;
+ dt += (t->tm_sec & 0x3e) >> 1; /* Only counting every 2 seconds. */
+ }
+ return dt;
+}
+
+static size_t
+path_length(struct archive_entry *entry)
+{
+ mode_t type;
+ const char *path;
+
+ type = archive_entry_filetype(entry);
+ path = archive_entry_pathname(entry);
+
+ if (path == NULL)
+ return (0);
+ if (type == AE_IFDIR &&
+ (path[0] == '\0' || path[strlen(path) - 1] != '/')) {
+ return strlen(path) + 1;
+ } else {
+ return strlen(path);
+ }
+}
+
+static int
+write_path(struct archive_entry *entry, struct archive_write *archive)
+{
+ int ret;
+ const char *path;
+ mode_t type;
+ size_t written_bytes;
+
+ path = archive_entry_pathname(entry);
+ type = archive_entry_filetype(entry);
+ written_bytes = 0;
+
+ ret = __archive_write_output(archive, path, strlen(path));
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ written_bytes += strlen(path);
+
+ /* Folders are recognized by a trailing slash. */
+ if ((type == AE_IFDIR) & (path[strlen(path) - 1] != '/')) {
+ ret = __archive_write_output(archive, "/", 1);
+ if (ret != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ written_bytes += 1;
+ }
+
+ return ((int)written_bytes);
+}
+
+static void
+copy_path(struct archive_entry *entry, unsigned char *p)
+{
+ const char *path;
+ size_t pathlen;
+ mode_t type;
+
+ path = archive_entry_pathname(entry);
+ pathlen = strlen(path);
+ type = archive_entry_filetype(entry);
+
+ memcpy(p, path, pathlen);
+
+ /* Folders are recognized by a trailing slash. */
+ if ((type == AE_IFDIR) & (path[pathlen - 1] != '/')) {
+ p[pathlen] = '/';
+ p[pathlen + 1] = '\0';
+ }
+}
+
+
+static struct archive_string_conv *
+get_sconv(struct archive_write *a, struct zip *zip)
+{
+ if (zip->opt_sconv != NULL)
+ return (zip->opt_sconv);
+
+ if (!zip->init_default_conversion) {
+ zip->sconv_default =
+ archive_string_default_conversion_for_write(&(a->archive));
+ zip->init_default_conversion = 1;
+ }
+ return (zip->sconv_default);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_options.3 b/Utilities/cmlibarchive/libarchive/archive_write_set_options.3
new file mode 100644
index 0000000000..f8fb039acc
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_options.3
@@ -0,0 +1,437 @@
+.\" Copyright (c) 2003-2010 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 2, 2012
+.Dt ARCHIVE_WRITE_OPTIONS 3
+.Os
+.Sh NAME
+.Nm archive_write_set_filter_option ,
+.Nm archive_write_set_format_option ,
+.Nm archive_write_set_option ,
+.Nm archive_write_set_options
+.Nd functions controlling options for reading archives
+.Sh LIBRARY
+Streaming Archive Library (libarchive, -larchive)
+.Sh SYNOPSIS
+.Ft int
+.Fo archive_write_set_filter_option
+.Fa "struct archive *"
+.Fa "const char *module"
+.Fa "const char *option"
+.Fa "const char *value"
+.Fc
+.Ft int
+.Fo archive_write_set_format_option
+.Fa "struct archive *"
+.Fa "const char *module"
+.Fa "const char *option"
+.Fa "const char *value"
+.Fc
+.Ft int
+.Fo archive_write_set_option
+.Fa "struct archive *"
+.Fa "const char *module"
+.Fa "const char *option"
+.Fa "const char *value"
+.Fc
+.Ft int
+.Fo archive_write_set_options
+.Fa "struct archive *"
+.Fa "const char *options"
+.Fc
+.Sh DESCRIPTION
+These functions provide a way for libarchive clients to configure
+specific write modules.
+.Bl -tag -width indent
+.It Xo
+.Fn archive_write_set_filter_option ,
+.Fn archive_write_set_format_option
+.Xc
+Specifies an option that will be passed to currently-registered
+filters (including decompression filters) or format readers.
+.Pp
+If
+.Ar option
+and
+.Ar value
+are both
+.Dv NULL ,
+these functions will do nothing and
+.Cm ARCHIVE_OK
+will be returned.
+If
+.Ar option
+is
+.Dv NULL
+but
+.Ar value
+is not, these functions will do nothing and
+.Cm ARCHIVE_FAILED
+will be returned.
+.Pp
+If
+.Ar module
+is not
+.Dv NULL ,
+.Ar option
+and
+.Ar value
+will be provided to the filter or reader named
+.Ar module .
+The return value will be that of the module.
+If there is no such module,
+.Cm ARCHIVE_FAILED
+will be returned.
+.Pp
+If
+.Ar module
+is
+.Dv NULL ,
+.Ar option
+and
+.Ar value
+will be provided to every registered module.
+If any module returns
+.Cm ARCHIVE_FATAL ,
+this value will be returned immediately.
+Otherwise,
+.Cm ARCHIVE_OK
+will be returned if any module accepts the option, and
+.Cm ARCHIVE_FAILED
+in all other cases.
+.\"
+.It Xo
+.Fn archive_write_set_option
+.Xc
+Calls
+.Fn archive_write_set_format_option ,
+then
+.Fn archive_write_set_filter_option .
+If either function returns
+.Cm ARCHIVE_FATAL ,
+.Cm ARCHIVE_FATAL
+will be returned
+immediately.
+Otherwise, greater of the two values will be returned.
+.\"
+.It Xo
+.Fn archive_write_set_options
+.Xc
+.Ar options
+is a comma-separated list of options.
+If
+.Ar options
+is
+.Dv NULL
+or empty,
+.Cm ARCHIVE_OK
+will be returned immediately.
+.Pp
+Individual options have one of the following forms:
+.Bl -tag -compact -width indent
+.It Ar option=value
+The option/value pair will be provided to every module.
+Modules that do not accept an option with this name will ignore it.
+.It Ar option
+The option will be provided to every module with a value of
+.Dq 1 .
+.It Ar !option
+The option will be provided to every module with a NULL value.
+.It Ar module:option=value , Ar module:option , Ar module:!option
+As above, but the corresponding option and value will be provided
+only to modules whose name matches
+.Ar module .
+.El
+.El
+.\"
+.Sh OPTIONS
+.Bl -tag -compact -width indent
+.It Filter gzip
+.Bl -tag -compact -width indent
+.It Cm compression-level
+The value is interpreted as a decimal integer specifying the
+gzip compression level.
+.El
+.It Filter xz
+.Bl -tag -compact -width indent
+.It Cm compression-level
+The value is interpreted as a decimal integer specifying the
+compression level.
+.El
+.It Format mtree
+.Bl -tag -compact -width indent
+.It Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent , Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 , Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname
+Enable a particular keyword in the mtree output.
+Prefix with an exclamation mark to disable the corresponding keyword.
+The default is equivalent to
+.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname .
+.It Cm all
+Enables all of the above keywords.
+.It Cm use-set
+Enables generation of
+.Cm /set
+lines that specify default values for the following files and/or directories.
+.It Cm indent
+XXX needs explanation XXX
+.El
+.It Format iso9660 - volume metadata
+These options are used to set standard ISO9660 metadata.
+.Bl -tag -compact -width indent
+.It Cm abstract-file Ns = Ns Ar filename
+The file with the specified name will be identified in the ISO9660 metadata
+as holding the abstract for this volume. Default: none.
+.It Cm application-id Ns = Ns Ar filename
+The file with the specified name will be identified in the ISO9660 metadata
+as holding the application identifier for this volume. Default: none.
+.It Cm biblio-file Ns = Ns Ar filename
+The file with the specified name will be identified in the ISO9660 metadata
+as holding the bibliography for this volume. Default: none.
+.It Cm copyright-file Ns = Ns Ar filename
+The file with the specified name will be identified in the ISO9660 metadata
+as holding the copyright for this volume. Default: none.
+.It Cm publisher Ns = Ns Ar filename
+The file with the specified name will be identified in the ISO9660 metadata
+as holding the publisher information for this volume. Default: none.
+.It Cm volume-id Ns = Ns Ar string
+The specified string will be used as the Volume Identifier in the ISO9660 metadata.
+It is limited to 32 bytes. Default: none.
+.El
+.It Format iso9660 - boot support
+These options are used to make an ISO9660 image that can be directly
+booted on various systems.
+.Bl -tag -compact -width indent
+.It Cm boot Ns = Ns Ar filename
+The file matching this name will be used as the El Torito boot image file.
+.It Cm boot-catalog Ns = Ns Ar name
+The name that will be used for the El Torito boot catalog.
+Default:
+.Ar boot.catalog
+.It Cm boot-info-table
+The boot image file provided by the
+.Cm boot Ns = Ns Ar filename
+option will be edited with appropriate boot information in bytes 8 through 64.
+Default: disabled
+.It Cm boot-load-seg Ns = Ns Ar hexadecimal-number
+The load segment for a no-emulation boot image.
+.It Cm boot-load-size Ns = Ns Ar decimal-number
+The number of "virtual" 512-byte sectors to be loaded from a no-emulation boot image.
+Some very old BIOSes can only load very small images, setting this
+value to 4 will often allow such BIOSes to load the first part of
+the boot image (which will then need to be intelligent enough to
+load the rest of itself).
+This should not be needed unless you are trying to support systems with very old BIOSes.
+This defaults to the full size of the image.
+.It Cm boot-type Ns = Ns Ar value
+Specifies the boot semantics used by the El Torito boot image:
+If the
+.Ar value
+is
+.Cm fd ,
+then the boot image is assumed to be a bootable floppy image.
+If the
+.Ar value
+is
+.Cm hd ,
+then the boot image is assumed to be a bootable hard disk image.
+If the
+.Ar value
+is
+.Cm no-emulation ,
+the boot image is used without floppy or hard disk emulation.
+If the boot image is exactly 1.2MB, 1.44MB, or 2.88MB, then
+the default is
+.Cm fd ,
+otherwise the default is
+.Cm no-emulation.
+.El
+.It Format iso9660 - filename and size extensions
+Various extensions to the base ISO9660 format.
+.Bl -tag -compact -width indent
+.It Cm allow-ldots
+If enabled, allows filenames to begin with a leading period.
+If disabled, filenames that begin with a leading period will have
+that period replaced by an underscore character in the standard ISO9660
+namespace.
+This does not impact names stored in the Rockridge or Joliet extension area.
+Default: disabled.
+.It Cm allow-lowercase
+If enabled, allows filenames to contain lowercase characters.
+If disabled, filenames will be forced to uppercase.
+This does not impact names stored in the Rockridge or Joliet extension area.
+Default: disabled.
+.It Cm allow-multidot
+If enabled, allows filenames to contain multiple period characters, in violation of the ISO9660 specification.
+If disabled, additional periods will be converted to underscore characters.
+This does not impact names stored in the Rockridge or Joliet extension area.
+Default: disabled.
+.It Cm allow-period
+If enabled, allows filenames to contain trailing period characters, in violation of the ISO9660 specification.
+If disabled,trailing periods will be converted to underscore characters.
+This does not impact names stored in the Rockridge or Joliet extension area.
+Default: disabled.
+.It Cm allow-pvd-lowercase
+If enabled, the Primary Volume Descriptor may contain lowercase ASCII characters, in violation of the ISO9660 specification.
+If disabled, characters will be converted to uppercase ASCII.
+Default: disabled.
+.It Cm allow-sharp-tilde
+If enabled, sharp and tilde characters will be permitted in filenames, in violation if the ISO9660 specification.
+If disabled, such characters will be converted to underscore characters.
+Default: disabled.
+.It Cm allow-vernum
+If enabled, version numbers will be included with files.
+If disabled, version numbers will be suppressed, in violation of the ISO9660 standard.
+This does not impact names stored in the Rockridge or Joliet extension area.
+Default: enabled.
+.It Cm iso-level
+This enables support for file size and file name extensions in the
+core ISO9660 area.
+The name extensions specified here do not affect the names stored in the Rockridge or Joliet extension areas.
+.Bl -tag -compact -width indent
+.It Cm iso-level=1
+The most compliant form of ISO9660 image.
+Filenames are limited to 8.3 uppercase format,
+directory names are limited to 8 uppercase characters,
+files are limited to 4 GiB,
+the complete ISO9660 image cannot exceed 4 GiB.
+.It Cm iso-level=2
+Filenames are limited to 30 uppercase characters with a 30-character extension,
+directory names are limited to 30 characters,
+files are limited to 4 GiB.
+.It Cm iso-level=3
+As with
+.Cm iso-level=2 ,
+except that files may exceed 4 GiB.
+.It Cm iso-level=4
+As with
+.Cm iso-level=3 ,
+except that filenames may be up to 193 characters
+and may include arbitrary 8-bit characters.
+.El
+.It Cm joliet
+Microsoft's Joliet extensions store a completely separate set of directory information about each file.
+In particular, this information includes Unicode filenames of up to 255 characters.
+Default: enabled.
+.It Cm limit-depth
+If enabled, libarchive will use directory relocation records to ensure that
+no pathname exceeds the ISO9660 limit of 8 directory levels.
+If disabled, no relocation will occur.
+Default: enabled.
+.It Cm limit-dirs
+If enabled, libarchive will cause an error if there are more than
+65536 directories.
+If disabled, there is no limit on the number of directories.
+Default: enabled
+.It Cm pad
+If enabled, 300 kiB of zero bytes will be appended to the end of the archive.
+Default: enabled
+.It Cm relaxed-filenames
+If enabled, all 7-bit ASCII characters are permitted in filenames
+(except lowercase characters unless
+.Cm allow-lowercase
+is also specified).
+This violates ISO9660 standards.
+This does not impact names stored in the Rockridge or Joliet extension area.
+Default: disabled.
+.It Cm rockridge
+The Rockridge extensions store an additional set of POSIX-style file
+information with each file, including mtime, atime, ctime, permissions,
+and long filenames with arbitrary 8-bit characters.
+These extensions also support symbolic links and other POSIX file types.
+Default: enabled.
+.El
+.It Format iso9660 - zisofs support
+The zisofs extensions permit each file to be independently compressed
+using a gzip-compatible compression.
+This can provide significant size savings, but requires the reading
+system to have support for these extensions.
+These extensions are disabled by default.
+.Bl -tag -compact -width indent
+.It Cm compression-level Ns = Ns number
+The compression level used by the deflate compressor.
+Ranges from 0 (least effort) to 9 (most effort).
+Default: 6
+.It Cm zisofs
+Synonym for
+.Cm zisofs=direct .
+.It Cm zisofs=direct
+Compress each file in the archive.
+Unlike
+.Cm zisofs=indirect ,
+this is handled entirely within libarchive and does not require a
+separate utility.
+For best results, libarchive tests each file and will store
+the file uncompressed if the compression does not actually save any space.
+In particular, files under 2k will never be compressed.
+Note that boot image files are never compressed.
+.It Cm zisofs=indirect
+Recognizes files that have already been compressed with the
+.Cm mkzftree
+utility and sets up the necessary file metadata so that
+readers will correctly identify these as zisofs-compressed files.
+.It Cm zisofs-exclude Ns = Ns Ar filename
+Specifies a filename that should not be compressed when using
+.Cm zisofs=direct .
+This option can be provided multiple times to suppress compression
+on many files.
+.El
+.El
+.Sh EXAMPLES
+The following example creates an archive write handle to
+create a gzip-compressed ISO9660 format image.
+The two options here specify that the ISO9660 archive will use
+.Ar kernel.img
+as the boot image for El Torito booting, and that the gzip
+compressor should use the maximum compression level.
+.Bd -literal -offset indent
+a = archive_write_new();
+archive_write_add_filter_gzip(a);
+archive_write_set_format_iso9660(a);
+archive_write_set_options(a, "boot=kernel.img,compression=9");
+archive_write_open_filename(a, filename, blocksize);
+.Ed
+.\"
+.Sh ERRORS
+Detailed error codes and textual descriptions are available from the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions.
+.\"
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_write 3
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+.Sh AUTHORS
+.An -nosplit
+The options support for libarchive was originally implemented by
+.An Michihiro NAKAJIMA .
+.Sh BUGS
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_options.c b/Utilities/cmlibarchive/libarchive/archive_write_set_options.c
new file mode 100644
index 0000000000..962309ada5
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_options.c
@@ -0,0 +1,130 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * 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$");
+
+#include "archive_write_private.h"
+#include "archive_options_private.h"
+
+static int archive_set_format_option(struct archive *a,
+ const char *m, const char *o, const char *v);
+static int archive_set_filter_option(struct archive *a,
+ const char *m, const char *o, const char *v);
+static int archive_set_option(struct archive *a,
+ const char *m, const char *o, const char *v);
+
+int
+archive_write_set_format_option(struct archive *a, const char *m, const char *o,
+ const char *v)
+{
+ return _archive_set_option(a, m, o, v,
+ ARCHIVE_WRITE_MAGIC, "archive_write_set_format_option",
+ archive_set_format_option);
+}
+
+int
+archive_write_set_filter_option(struct archive *a, const char *m, const char *o,
+ const char *v)
+{
+ return _archive_set_option(a, m, o, v,
+ ARCHIVE_WRITE_MAGIC, "archive_write_set_filter_option",
+ archive_set_filter_option);
+}
+
+int
+archive_write_set_option(struct archive *a, const char *m, const char *o,
+ const char *v)
+{
+ return _archive_set_option(a, m, o, v,
+ ARCHIVE_WRITE_MAGIC, "archive_write_set_option",
+ archive_set_option);
+}
+
+int
+archive_write_set_options(struct archive *a, const char *options)
+{
+ return _archive_set_options(a, options,
+ ARCHIVE_WRITE_MAGIC, "archive_write_set_options",
+ archive_set_option);
+}
+
+static int
+archive_set_format_option(struct archive *_a, const char *m, const char *o,
+ const char *v)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+
+ if (a->format_name == NULL)
+ return (m == NULL)?ARCHIVE_FAILED:ARCHIVE_WARN - 1;
+ /* If the format name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (m != NULL && strcmp(m, a->format_name) != 0)
+ return (ARCHIVE_WARN - 1);
+ if (a->format_options == NULL)
+ return (ARCHIVE_WARN);
+ return a->format_options(a, o, v);
+}
+
+static int
+archive_set_filter_option(struct archive *_a, const char *m, const char *o,
+ const char *v)
+{
+ struct archive_write *a = (struct archive_write *)_a;
+ struct archive_write_filter *filter;
+ int r, rv = ARCHIVE_WARN;
+
+ for (filter = a->filter_first; filter != NULL; filter = filter->next_filter) {
+ if (filter->options == NULL)
+ continue;
+ if (m != NULL && strcmp(filter->name, m) != 0)
+ continue;
+
+ r = filter->options(filter, o, v);
+
+ if (r == ARCHIVE_FATAL)
+ return (ARCHIVE_FATAL);
+
+ if (m != NULL)
+ return (r);
+
+ if (r == ARCHIVE_OK)
+ rv = ARCHIVE_OK;
+ }
+ /* If the filter name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (rv == ARCHIVE_WARN && m != NULL)
+ rv = ARCHIVE_WARN - 1;
+ return (rv);
+}
+
+static int
+archive_set_option(struct archive *a, const char *m, const char *o,
+ const char *v)
+{
+ return _archive_set_either_option(a, m, o, v,
+ archive_set_format_option,
+ archive_set_filter_option);
+}
diff --git a/Utilities/cmlibarchive/libarchive/config_freebsd.h b/Utilities/cmlibarchive/libarchive/config_freebsd.h
new file mode 100644
index 0000000000..2073431635
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/config_freebsd.h
@@ -0,0 +1,160 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/config_freebsd.h 201079 2009-12-28 02:01:42Z kientzle $
+ */
+
+/* FreeBSD 5.0 and later have ACL and extattr support. */
+#if __FreeBSD__ > 4
+#define HAVE_ACL_CREATE_ENTRY 1
+#define HAVE_ACL_GET_LINK_NP 1
+#define HAVE_ACL_GET_PERM_NP 1
+#define HAVE_ACL_INIT 1
+#define HAVE_ACL_SET_FD 1
+#define HAVE_ACL_SET_FD_NP 1
+#define HAVE_ACL_SET_FILE 1
+#define HAVE_ACL_USER 1
+#define HAVE_EXTATTR_GET_FILE 1
+#define HAVE_EXTATTR_LIST_FILE 1
+#define HAVE_EXTATTR_SET_FD 1
+#define HAVE_EXTATTR_SET_FILE 1
+#define HAVE_SYS_ACL_H 1
+#define HAVE_SYS_EXTATTR_H 1
+#endif
+
+#ifdef WITH_OPENSSL
+#define HAVE_OPENSSL_MD5_H 1
+#define HAVE_OPENSSL_RIPEMD_H 1
+#define HAVE_OPENSSL_SHA_H 1
+#define HAVE_SHA384 1
+#define HAVE_SHA512 1
+#endif
+
+#define HAVE_BSDXML_H 1
+#define HAVE_BZLIB_H 1
+#define HAVE_CHFLAGS 1
+#define HAVE_CHOWN 1
+#define HAVE_DECL_INT64_MAX 1
+#define HAVE_DECL_INT64_MIN 1
+#define HAVE_DECL_SIZE_MAX 1
+#define HAVE_DECL_SSIZE_MAX 1
+#define HAVE_DECL_STRERROR_R 1
+#define HAVE_DECL_UINT32_MAX 1
+#define HAVE_DECL_UINT64_MAX 1
+#define HAVE_DIRENT_H 1
+#define HAVE_EFTYPE 1
+#define HAVE_EILSEQ 1
+#define HAVE_ERRNO_H 1
+#define HAVE_FCHDIR 1
+#define HAVE_FCHFLAGS 1
+#define HAVE_FCHMOD 1
+#define HAVE_FCHOWN 1
+#define HAVE_FCNTL 1
+#define HAVE_FCNTL_H 1
+#define HAVE_FSEEKO 1
+#define HAVE_FSTAT 1
+#define HAVE_FTRUNCATE 1
+#define HAVE_FUTIMES 1
+#define HAVE_GETEUID 1
+#define HAVE_GETGRGID_R 1
+#define HAVE_GETPID 1
+#define HAVE_GETPWUID_R 1
+#define HAVE_GRP_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LCHFLAGS 1
+#define HAVE_LCHMOD 1
+#define HAVE_LCHOWN 1
+#define HAVE_LIMITS_H 1
+#define HAVE_LINK 1
+#define HAVE_LSTAT 1
+#define HAVE_LUTIMES 1
+#define HAVE_MALLOC 1
+#define HAVE_MD5 1
+#define HAVE_MD5_H 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MKDIR 1
+#define HAVE_MKFIFO 1
+#define HAVE_MKNOD 1
+#define HAVE_PIPE 1
+#define HAVE_POLL 1
+#define HAVE_POLL_H 1
+#define HAVE_PWD_H 1
+#define HAVE_READLINK 1
+#define HAVE_RMD160 1
+#define HAVE_SELECT 1
+#define HAVE_SETENV 1
+#define HAVE_SHA_H 1
+#define HAVE_SHA1 1
+#define HAVE_SHA256 1
+#define HAVE_SHA256_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STRCHR 1
+#define HAVE_STRDUP 1
+#define HAVE_STRERROR 1
+#define HAVE_STRERROR_R 1
+#define HAVE_STRINGS_H 1
+#define HAVE_STRING_H 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
+#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
+#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1
+#define HAVE_STRUCT_STAT_ST_FLAGS 1
+#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
+#define HAVE_STRUCT_TM_TM_GMTOFF 1
+#define HAVE_SYMLINK 1
+#define HAVE_SYS_CDEFS_H 1
+#define HAVE_SYS_IOCTL_H 1
+#define HAVE_SYS_MOUNT_H 1
+#define HAVE_SYS_PARAM_H 1
+#define HAVE_SYS_SELECT_H 1
+#define HAVE_SYS_STAT_H 1
+#define HAVE_SYS_TIME_H 1
+#define HAVE_SYS_TYPES_H 1
+#undef HAVE_SYS_UTIME_H
+#define HAVE_SYS_UTSNAME_H 1
+#define HAVE_SYS_WAIT_H 1
+#define HAVE_TIMEGM 1
+#define HAVE_TZSET 1
+#define HAVE_UNISTD_H 1
+#define HAVE_UNSETENV 1
+#define HAVE_UTIME 1
+#define HAVE_UTIMES 1
+#define HAVE_UTIME_H 1
+#define HAVE_VFORK 1
+#define HAVE_WCHAR_H 1
+#define HAVE_WCSCPY 1
+#define HAVE_WCSLEN 1
+#define HAVE_WCTOMB 1
+#define HAVE_WMEMCMP 1
+#define HAVE_WMEMCPY 1
+#define HAVE_ZLIB_H 1
+#define TIME_WITH_SYS_TIME 1
+
+/* FreeBSD 4 and earlier lack intmax_t/uintmax_t */
+#if __FreeBSD__ < 5
+#define intmax_t int64_t
+#define uintmax_t uint64_t
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/cpio.5 b/Utilities/cmlibarchive/libarchive/cpio.5
new file mode 100644
index 0000000000..1a2886f086
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/cpio.5
@@ -0,0 +1,325 @@
+.\" Copyright (c) 2007 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd December 23, 2011
+.Dt CPIO 5
+.Os
+.Sh NAME
+.Nm cpio
+.Nd format of cpio archive files
+.Sh DESCRIPTION
+The
+.Nm
+archive format collects any number of files, directories, and other
+file system objects (symbolic links, device nodes, etc.) into a single
+stream of bytes.
+.Ss General Format
+Each file system object in a
+.Nm
+archive comprises a header record with basic numeric metadata
+followed by the full pathname of the entry and the file data.
+The header record stores a series of integer values that generally
+follow the fields in
+.Va struct stat .
+(See
+.Xr stat 2
+for details.)
+The variants differ primarily in how they store those integers
+(binary, octal, or hexadecimal).
+The header is followed by the pathname of the
+entry (the length of the pathname is stored in the header)
+and any file data.
+The end of the archive is indicated by a special record with
+the pathname
+.Dq TRAILER!!! .
+.Ss PWB format
+XXX Any documentation of the original PWB/UNIX 1.0 format? XXX
+.Ss Old Binary Format
+The old binary
+.Nm
+format stores numbers as 2-byte and 4-byte binary values.
+Each entry begins with a header in the following format:
+.Bd -literal -offset indent
+struct header_old_cpio {
+ unsigned short c_magic;
+ unsigned short c_dev;
+ unsigned short c_ino;
+ unsigned short c_mode;
+ unsigned short c_uid;
+ unsigned short c_gid;
+ unsigned short c_nlink;
+ unsigned short c_rdev;
+ unsigned short c_mtime[2];
+ unsigned short c_namesize;
+ unsigned short c_filesize[2];
+};
+.Ed
+.Pp
+The
+.Va unsigned short
+fields here are 16-bit integer values; the
+.Va unsigned int
+fields are 32-bit integer values.
+The fields are as follows
+.Bl -tag -width indent
+.It Va magic
+The integer value octal 070707.
+This value can be used to determine whether this archive is
+written with little-endian or big-endian integers.
+.It Va dev , Va ino
+The device and inode numbers from the disk.
+These are used by programs that read
+.Nm
+archives to determine when two entries refer to the same file.
+Programs that synthesize
+.Nm
+archives should be careful to set these to distinct values for each entry.
+.It Va mode
+The mode specifies both the regular permissions and the file type.
+It consists of several bit fields as follows:
+.Bl -tag -width "MMMMMMM" -compact
+.It 0170000
+This masks the file type bits.
+.It 0140000
+File type value for sockets.
+.It 0120000
+File type value for symbolic links.
+For symbolic links, the link body is stored as file data.
+.It 0100000
+File type value for regular files.
+.It 0060000
+File type value for block special devices.
+.It 0040000
+File type value for directories.
+.It 0020000
+File type value for character special devices.
+.It 0010000
+File type value for named pipes or FIFOs.
+.It 0004000
+SUID bit.
+.It 0002000
+SGID bit.
+.It 0001000
+Sticky bit.
+On some systems, this modifies the behavior of executables and/or directories.
+.It 0000777
+The lower 9 bits specify read/write/execute permissions
+for world, group, and user following standard POSIX conventions.
+.El
+.It Va uid , Va gid
+The numeric user id and group id of the owner.
+.It Va nlink
+The number of links to this file.
+Directories always have a value of at least two here.
+Note that hardlinked files include file data with every copy in the archive.
+.It Va rdev
+For block special and character special entries,
+this field contains the associated device number.
+For all other entry types, it should be set to zero by writers
+and ignored by readers.
+.It Va mtime
+Modification time of the file, indicated as the number
+of seconds since the start of the epoch,
+00:00:00 UTC January 1, 1970.
+The four-byte integer is stored with the most-significant 16 bits first
+followed by the least-significant 16 bits.
+Each of the two 16 bit values are stored in machine-native byte order.
+.It Va namesize
+The number of bytes in the pathname that follows the header.
+This count includes the trailing NUL byte.
+.It Va filesize
+The size of the file.
+Note that this archive format is limited to
+four gigabyte file sizes.
+See
+.Va mtime
+above for a description of the storage of four-byte integers.
+.El
+.Pp
+The pathname immediately follows the fixed header.
+If the
+.Cm namesize
+is odd, an additional NUL byte is added after the pathname.
+The file data is then appended, padded with NUL
+bytes to an even length.
+.Pp
+Hardlinked files are not given special treatment;
+the full file contents are included with each copy of the
+file.
+.Ss Portable ASCII Format
+.St -susv2
+standardized an ASCII variant that is portable across all
+platforms.
+It is commonly known as the
+.Dq old character
+format or as the
+.Dq odc
+format.
+It stores the same numeric fields as the old binary format, but
+represents them as 6-character or 11-character octal values.
+.Bd -literal -offset indent
+struct cpio_odc_header {
+ char c_magic[6];
+ char c_dev[6];
+ char c_ino[6];
+ char c_mode[6];
+ char c_uid[6];
+ char c_gid[6];
+ char c_nlink[6];
+ char c_rdev[6];
+ char c_mtime[11];
+ char c_namesize[6];
+ char c_filesize[11];
+};
+.Ed
+.Pp
+The fields are identical to those in the old binary format.
+The name and file body follow the fixed header.
+Unlike the old binary format, there is no additional padding
+after the pathname or file contents.
+If the files being archived are themselves entirely ASCII, then
+the resulting archive will be entirely ASCII, except for the
+NUL byte that terminates the name field.
+.Ss New ASCII Format
+The "new" ASCII format uses 8-byte hexadecimal fields for
+all numbers and separates device numbers into separate fields
+for major and minor numbers.
+.Bd -literal -offset indent
+struct cpio_newc_header {
+ char c_magic[6];
+ char c_ino[8];
+ char c_mode[8];
+ char c_uid[8];
+ char c_gid[8];
+ char c_nlink[8];
+ char c_mtime[8];
+ char c_filesize[8];
+ char c_devmajor[8];
+ char c_devminor[8];
+ char c_rdevmajor[8];
+ char c_rdevminor[8];
+ char c_namesize[8];
+ char c_check[8];
+};
+.Ed
+.Pp
+Except as specified below, the fields here match those specified
+for the old binary format above.
+.Bl -tag -width indent
+.It Va magic
+The string
+.Dq 070701 .
+.It Va check
+This field is always set to zero by writers and ignored by readers.
+See the next section for more details.
+.El
+.Pp
+The pathname is followed by NUL bytes so that the total size
+of the fixed header plus pathname is a multiple of four.
+Likewise, the file data is padded to a multiple of four bytes.
+Note that this format supports only 4 gigabyte files (unlike the
+older ASCII format, which supports 8 gigabyte files).
+.Pp
+In this format, hardlinked files are handled by setting the
+filesize to zero for each entry except the last one that
+appears in the archive.
+.Ss New CRC Format
+The CRC format is identical to the new ASCII format described
+in the previous section except that the magic field is set
+to
+.Dq 070702
+and the
+.Va check
+field is set to the sum of all bytes in the file data.
+This sum is computed treating all bytes as unsigned values
+and using unsigned arithmetic.
+Only the least-significant 32 bits of the sum are stored.
+.Ss HP variants
+The
+.Nm cpio
+implementation distributed with HPUX used XXXX but stored
+device numbers differently XXX.
+.Ss Other Extensions and Variants
+Sun Solaris uses additional file types to store extended file
+data, including ACLs and extended attributes, as special
+entries in cpio archives.
+.Pp
+XXX Others? XXX
+.Sh SEE ALSO
+.Xr cpio 1 ,
+.Xr tar 5
+.Sh STANDARDS
+The
+.Nm cpio
+utility is no longer a part of POSIX or the Single Unix Standard.
+It last appeared in
+.St -susv2 .
+It has been supplanted in subsequent standards by
+.Xr pax 1 .
+The portable ASCII format is currently part of the specification for the
+.Xr pax 1
+utility.
+.Sh HISTORY
+The original cpio utility was written by Dick Haight
+while working in AT&T's Unix Support Group.
+It appeared in 1977 as part of PWB/UNIX 1.0, the
+.Dq Programmer's Work Bench
+derived from
+.At v6
+that was used internally at AT&T.
+Both the old binary and old character formats were in use
+by 1980, according to the System III source released
+by SCO under their
+.Dq Ancient Unix
+license.
+The character format was adopted as part of
+.St -p1003.1-88 .
+XXX when did "newc" appear? Who invented it? When did HP come out with their variant? When did Sun introduce ACLs and extended attributes? XXX
+.Sh BUGS
+The
+.Dq CRC
+format is mis-named, as it uses a simple checksum and
+not a cyclic redundancy check.
+.Pp
+The old binary format is limited to 16 bits for user id,
+group id, device, and inode numbers.
+It is limited to 4 gigabyte file sizes.
+.Pp
+The old ASCII format is limited to 18 bits for
+the user id, group id, device, and inode numbers.
+It is limited to 8 gigabyte file sizes.
+.Pp
+The new ASCII format is limited to 4 gigabyte file sizes.
+.Pp
+None of the cpio formats store user or group names,
+which are essential when moving files between systems with
+dissimilar user or group numbering.
+.Pp
+Especially when writing older cpio variants, it may be necessary
+to map actual device/inode values to synthesized values that
+fit the available fields.
+With very large filesystems, this may be necessary even for
+the newer formats.
diff --git a/Utilities/cmlibarchive/libarchive/filter_fork.h b/Utilities/cmlibarchive/libarchive/filter_fork.h
new file mode 100644
index 0000000000..a28272bee3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/filter_fork.h
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2007 Joerg Sonnenberger
+ * 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.
+ *
+ * $FreeBSD: head/lib/libarchive/filter_fork.h 201087 2009-12-28 02:18:26Z kientzle $
+ */
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef FILTER_FORK_H
+#define FILTER_FORK_H
+
+pid_t
+__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout);
+
+void
+__archive_check_child(int in, int out);
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/filter_fork_posix.c b/Utilities/cmlibarchive/libarchive/filter_fork_posix.c
new file mode 100644
index 0000000000..02dbd4bb43
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/filter_fork_posix.c
@@ -0,0 +1,238 @@
+/*-
+ * Copyright (c) 2007 Joerg Sonnenberger
+ * Copyright (c) 2012 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"
+
+/* This capability is only available on POSIX systems. */
+#if defined(HAVE_PIPE) && defined(HAVE_FCNTL) && \
+ (defined(HAVE_FORK) || defined(HAVE_VFORK) || defined(HAVE_POSIX_SPAWNP))
+
+__FBSDID("$FreeBSD: head/lib/libarchive/filter_fork.c 182958 2008-09-12 05:33:00Z kientzle $");
+
+#if defined(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
+#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H))
+# if defined(HAVE_POLL_H)
+# include <poll.h>
+# elif defined(HAVE_SYS_POLL_H)
+# include <sys/poll.h>
+# endif
+#elif defined(HAVE_SELECT)
+# if defined(HAVE_SYS_SELECT_H)
+# include <sys/select.h>
+# elif defined(HAVE_UNISTD_H)
+# include <unistd.h>
+# endif
+#endif
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#ifdef HAVE_SPAWN_H
+# include <spawn.h>
+#endif
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include "archive.h"
+#include "archive_cmdline_private.h"
+
+#include "filter_fork.h"
+
+pid_t
+__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout)
+{
+ pid_t child;
+ int stdin_pipe[2], stdout_pipe[2], tmp;
+#if HAVE_POSIX_SPAWNP
+ posix_spawn_file_actions_t actions;
+ int r;
+#endif
+ struct archive_cmdline *cmdline;
+
+ cmdline = __archive_cmdline_allocate();
+ if (cmdline == NULL)
+ goto state_allocated;
+ if (__archive_cmdline_parse(cmdline, cmd) != ARCHIVE_OK)
+ goto state_allocated;
+
+ if (pipe(stdin_pipe) == -1)
+ goto state_allocated;
+ if (stdin_pipe[0] == 1 /* stdout */) {
+ if ((tmp = dup(stdin_pipe[0])) == -1)
+ goto stdin_opened;
+ close(stdin_pipe[0]);
+ stdin_pipe[0] = tmp;
+ }
+ if (pipe(stdout_pipe) == -1)
+ goto stdin_opened;
+ if (stdout_pipe[1] == 0 /* stdin */) {
+ if ((tmp = dup(stdout_pipe[1])) == -1)
+ goto stdout_opened;
+ close(stdout_pipe[1]);
+ stdout_pipe[1] = tmp;
+ }
+
+#if HAVE_POSIX_SPAWNP
+
+ r = posix_spawn_file_actions_init(&actions);
+ if (r != 0) {
+ errno = r;
+ goto stdout_opened;
+ }
+ r = posix_spawn_file_actions_addclose(&actions, stdin_pipe[1]);
+ if (r != 0)
+ goto actions_inited;
+ r = posix_spawn_file_actions_addclose(&actions, stdout_pipe[0]);
+ if (r != 0)
+ goto actions_inited;
+ /* Setup for stdin. */
+ r = posix_spawn_file_actions_adddup2(&actions, stdin_pipe[0], 0);
+ if (r != 0)
+ goto actions_inited;
+ if (stdin_pipe[0] != 0 /* stdin */) {
+ r = posix_spawn_file_actions_addclose(&actions, stdin_pipe[0]);
+ if (r != 0)
+ goto actions_inited;
+ }
+ /* Setup for stdout. */
+ r = posix_spawn_file_actions_adddup2(&actions, stdout_pipe[1], 1);
+ if (r != 0)
+ goto actions_inited;
+ if (stdout_pipe[1] != 1 /* stdout */) {
+ r = posix_spawn_file_actions_addclose(&actions, stdout_pipe[1]);
+ if (r != 0)
+ goto actions_inited;
+ }
+ r = posix_spawnp(&child, cmdline->path, &actions, NULL,
+ cmdline->argv, NULL);
+ if (r != 0)
+ goto actions_inited;
+ posix_spawn_file_actions_destroy(&actions);
+
+#else /* HAVE_POSIX_SPAWNP */
+
+#if HAVE_VFORK
+ child = vfork();
+#else
+ child = fork();
+#endif
+ if (child == -1)
+ goto stdout_opened;
+ if (child == 0) {
+ close(stdin_pipe[1]);
+ close(stdout_pipe[0]);
+ if (dup2(stdin_pipe[0], 0 /* stdin */) == -1)
+ _exit(254);
+ if (stdin_pipe[0] != 0 /* stdin */)
+ close(stdin_pipe[0]);
+ if (dup2(stdout_pipe[1], 1 /* stdout */) == -1)
+ _exit(254);
+ if (stdout_pipe[1] != 1 /* stdout */)
+ close(stdout_pipe[1]);
+ execvp(cmdline->path, cmdline->argv);
+ _exit(254);
+ }
+#endif /* HAVE_POSIX_SPAWNP */
+
+ close(stdin_pipe[0]);
+ close(stdout_pipe[1]);
+
+ *child_stdin = stdin_pipe[1];
+ fcntl(*child_stdin, F_SETFL, O_NONBLOCK);
+ *child_stdout = stdout_pipe[0];
+ fcntl(*child_stdout, F_SETFL, O_NONBLOCK);
+ __archive_cmdline_free(cmdline);
+
+ return child;
+
+#if HAVE_POSIX_SPAWNP
+actions_inited:
+ errno = r;
+ posix_spawn_file_actions_destroy(&actions);
+#endif
+stdout_opened:
+ close(stdout_pipe[0]);
+ close(stdout_pipe[1]);
+stdin_opened:
+ close(stdin_pipe[0]);
+ close(stdin_pipe[1]);
+state_allocated:
+ __archive_cmdline_free(cmdline);
+ return -1;
+}
+
+void
+__archive_check_child(int in, int out)
+{
+#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H))
+ struct pollfd fds[2];
+ int idx;
+
+ idx = 0;
+ if (in != -1) {
+ fds[idx].fd = in;
+ fds[idx].events = POLLOUT;
+ ++idx;
+ }
+ if (out != -1) {
+ fds[idx].fd = out;
+ fds[idx].events = POLLIN;
+ ++idx;
+ }
+
+ poll(fds, idx, -1); /* -1 == INFTIM, wait forever */
+#elif defined(HAVE_SELECT)
+ fd_set fds_in, fds_out, fds_error;
+
+ FD_ZERO(&fds_in);
+ FD_ZERO(&fds_out);
+ FD_ZERO(&fds_error);
+ if (out != -1) {
+ FD_SET(out, &fds_in);
+ FD_SET(out, &fds_error);
+ }
+ if (in != -1) {
+ FD_SET(in, &fds_out);
+ FD_SET(in, &fds_error);
+ }
+ select(in < out ? out + 1 : in + 1, &fds_in, &fds_out, &fds_error, NULL);
+#else
+ sleep(1);
+#endif
+}
+
+#endif /* defined(HAVE_PIPE) && defined(HAVE_VFORK) && defined(HAVE_FCNTL) */
diff --git a/Utilities/cmlibarchive/libarchive/filter_fork_windows.c b/Utilities/cmlibarchive/libarchive/filter_fork_windows.c
new file mode 100644
index 0000000000..ad271fe68a
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/filter_fork_windows.c
@@ -0,0 +1,190 @@
+/*-
+ * Copyright (c) 2009-2012 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"
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include "archive_cmdline_private.h"
+#include "archive_string.h"
+
+#include "filter_fork.h"
+
+pid_t
+__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout)
+{
+ HANDLE childStdout[2], childStdin[2],childStderr;
+ SECURITY_ATTRIBUTES secAtts;
+ STARTUPINFOA staInfo;
+ PROCESS_INFORMATION childInfo;
+ struct archive_string cmdline;
+ struct archive_string fullpath;
+ struct archive_cmdline *acmd;
+ char *arg0, *ext;
+ int i, l;
+ DWORD fl, fl_old;
+
+ childStdout[0] = childStdout[1] = INVALID_HANDLE_VALUE;
+ childStdin[0] = childStdin[1] = INVALID_HANDLE_VALUE;
+ childStderr = INVALID_HANDLE_VALUE;
+ archive_string_init(&cmdline);
+ archive_string_init(&fullpath);
+
+ acmd = __archive_cmdline_allocate();
+ if (acmd == NULL)
+ goto fail;
+ if (__archive_cmdline_parse(acmd, cmd) != ARCHIVE_OK)
+ goto fail;
+
+ /*
+ * Search the full path of 'path'.
+ * NOTE: This does not need if we give CreateProcessA 'path' as
+ * a part of the cmdline and give CreateProcessA NULL as first
+ * parameter, but I do not like that way.
+ */
+ ext = strrchr(acmd->path, '.');
+ if (ext == NULL || strlen(ext) > 4)
+ /* 'path' does not have a proper extension, so we have to
+ * give SearchPath() ".exe" as the extension. */
+ ext = ".exe";
+ else
+ ext = NULL;/* 'path' has an extension. */
+
+ fl = MAX_PATH;
+ do {
+ if (archive_string_ensure(&fullpath, fl) == NULL)
+ goto fail;
+ fl_old = fl;
+ fl = SearchPathA(NULL, acmd->path, ext, fl, fullpath.s,
+ &arg0);
+ } while (fl != 0 && fl > fl_old);
+ if (fl == 0)
+ goto fail;
+
+ /*
+ * Make a command line.
+ */
+ for (l = 0, i = 0; acmd->argv[i] != NULL; i++) {
+ if (i == 0)
+ continue;
+ l += (int)strlen(acmd->argv[i]) + 1;
+ }
+ if (archive_string_ensure(&cmdline, l + 1) == NULL)
+ goto fail;
+ for (i = 0; acmd->argv[i] != NULL; i++) {
+ if (i == 0) {
+ const char *p, *sp;
+
+ if ((p = strchr(acmd->argv[i], '/')) != NULL ||
+ (p = strchr(acmd->argv[i], '\\')) != NULL)
+ p++;
+ else
+ p = acmd->argv[i];
+ if ((sp = strchr(p, ' ')) != NULL)
+ archive_strappend_char(&cmdline, '"');
+ archive_strcat(&cmdline, p);
+ if (sp != NULL)
+ archive_strappend_char(&cmdline, '"');
+ } else {
+ archive_strappend_char(&cmdline, ' ');
+ archive_strcat(&cmdline, acmd->argv[i]);
+ }
+ }
+ if (i <= 1) {
+ const char *sp;
+
+ if ((sp = strchr(arg0, ' ')) != NULL)
+ archive_strappend_char(&cmdline, '"');
+ archive_strcat(&cmdline, arg0);
+ if (sp != NULL)
+ archive_strappend_char(&cmdline, '"');
+ }
+
+ secAtts.nLength = sizeof(SECURITY_ATTRIBUTES);
+ secAtts.bInheritHandle = TRUE;
+ secAtts.lpSecurityDescriptor = NULL;
+ if (CreatePipe(&childStdout[0], &childStdout[1], &secAtts, 0) == 0)
+ goto fail;
+ if (!SetHandleInformation(childStdout[0], HANDLE_FLAG_INHERIT, 0))
+ goto fail;
+ if (CreatePipe(&childStdin[0], &childStdin[1], &secAtts, 0) == 0)
+ goto fail;
+ if (!SetHandleInformation(childStdin[1], HANDLE_FLAG_INHERIT, 0))
+ goto fail;
+ if (DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE),
+ GetCurrentProcess(), &childStderr, 0, TRUE,
+ DUPLICATE_SAME_ACCESS) == 0)
+ goto fail;
+
+ memset(&staInfo, 0, sizeof(staInfo));
+ staInfo.cb = sizeof(staInfo);
+ staInfo.hStdError = childStderr;
+ staInfo.hStdOutput = childStdout[1];
+ staInfo.hStdInput = childStdin[0];
+ staInfo.wShowWindow = SW_HIDE;
+ staInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+ if (CreateProcessA(fullpath.s, cmdline.s, NULL, NULL, TRUE, 0,
+ NULL, NULL, &staInfo, &childInfo) == 0)
+ goto fail;
+ WaitForInputIdle(childInfo.hProcess, INFINITE);
+ CloseHandle(childInfo.hProcess);
+ CloseHandle(childInfo.hThread);
+
+ *child_stdout = _open_osfhandle((intptr_t)childStdout[0], _O_RDONLY);
+ *child_stdin = _open_osfhandle((intptr_t)childStdin[1], _O_WRONLY);
+
+ CloseHandle(childStdout[1]);
+ CloseHandle(childStdin[0]);
+
+ archive_string_free(&cmdline);
+ archive_string_free(&fullpath);
+ __archive_cmdline_free(acmd);
+ return (childInfo.dwProcessId);
+
+fail:
+ if (childStdout[0] != INVALID_HANDLE_VALUE)
+ CloseHandle(childStdout[0]);
+ if (childStdout[1] != INVALID_HANDLE_VALUE)
+ CloseHandle(childStdout[1]);
+ if (childStdin[0] != INVALID_HANDLE_VALUE)
+ CloseHandle(childStdin[0]);
+ if (childStdin[1] != INVALID_HANDLE_VALUE)
+ CloseHandle(childStdin[1]);
+ if (childStderr != INVALID_HANDLE_VALUE)
+ CloseHandle(childStderr);
+ archive_string_free(&cmdline);
+ archive_string_free(&fullpath);
+ __archive_cmdline_free(acmd);
+ return (-1);
+}
+
+void
+__archive_check_child(int in, int out)
+{
+ (void)in; /* UNUSED */
+ (void)out; /* UNUSED */
+ Sleep(100);
+}
+
+#endif /* _WIN32 && !__CYGWIN__ */
diff --git a/Utilities/cmlibarchive/libarchive/libarchive-formats.5 b/Utilities/cmlibarchive/libarchive/libarchive-formats.5
new file mode 100644
index 0000000000..4a709b33c9
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/libarchive-formats.5
@@ -0,0 +1,431 @@
+.\" Copyright (c) 2003-2009 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd March 18, 2012
+.Dt LIBARCHIVE-FORMATS 5
+.Os
+.Sh NAME
+.Nm libarchive-formats
+.Nd archive formats supported by the libarchive library
+.Sh DESCRIPTION
+The
+.Xr libarchive 3
+library reads and writes a variety of streaming archive formats.
+Generally speaking, all of these archive formats consist of a series of
+.Dq entries .
+Each entry stores a single file system object, such as a file, directory,
+or symbolic link.
+.Pp
+The following provides a brief description of each format supported
+by libarchive, with some information about recognized extensions or
+limitations of the current library support.
+Note that just because a format is supported by libarchive does not
+imply that a program that uses libarchive will support that format.
+Applications that use libarchive specify which formats they wish
+to support, though many programs do use libarchive convenience
+functions to enable all supported formats.
+.Ss Tar Formats
+The
+.Xr libarchive 3
+library can read most tar archives.
+It can write POSIX-standard
+.Dq ustar
+and
+.Dq pax interchange
+formats and a subset of the legacy GNU tar format.
+.Pp
+All tar formats store each entry in one or more 512-byte records.
+The first record is used for file metadata, including filename,
+timestamp, and mode information, and the file data is stored in
+subsequent records.
+Later variants have extended this by either appropriating undefined
+areas of the header record, extending the header to multiple records,
+or by storing special entries that modify the interpretation of
+subsequent entries.
+.Pp
+.Bl -tag -width indent
+.It Cm gnutar
+The
+.Xr libarchive 3
+library can read most GNU-format tar archives.
+It currently supports the most popular GNU extensions, including
+modern long filename and linkname support, as well as atime and ctime data.
+The libarchive library does not support multi-volume
+archives, nor the old GNU long filename format.
+It can read GNU sparse file entries, including the new POSIX-based
+formats.
+.Pp
+The
+.Xr libarchive 3
+library can write GNU tar format, including long filename
+and linkname support, as well as atime and ctime data.
+.It Cm pax
+The
+.Xr libarchive 3
+library can read and write POSIX-compliant pax interchange format
+archives.
+Pax interchange format archives are an extension of the older ustar
+format that adds a separate entry with additional attributes stored
+as key/value pairs immediately before each regular entry.
+The presence of these additional entries is the only difference between
+pax interchange format and the older ustar format.
+The extended attributes are of unlimited length and are stored
+as UTF-8 Unicode strings.
+Keywords defined in the standard are in all lowercase; vendors are allowed
+to define custom keys by preceding them with the vendor name in all uppercase.
+When writing pax archives, libarchive uses many of the SCHILY keys
+defined by Joerg Schilling's
+.Dq star
+archiver and a few LIBARCHIVE keys.
+The libarchive library can read most of the SCHILY keys
+and most of the GNU keys introduced by GNU tar.
+It silently ignores any keywords that it does not understand.
+.Pp
+The pax interchange format converts filenames to Unicode
+and stores them using the UTF-8 encoding.
+Prior to libarchive 3.0, libarchive erroneously assumed
+that the system wide-character routines natively supported
+Unicode.
+This caused it to mis-handle non-ASCII filenames on systems
+that did not satisfy this assumption.
+.It Cm restricted pax
+The libarchive library can also write pax archives in which it
+attempts to suppress the extended attributes entry whenever
+possible.
+The result will be identical to a ustar archive unless the
+extended attributes entry is required to store a long file
+name, long linkname, extended ACL, file flags, or if any of the standard
+ustar data (user name, group name, UID, GID, etc) cannot be fully
+represented in the ustar header.
+In all cases, the result can be dearchived by any program that
+can read POSIX-compliant pax interchange format archives.
+Programs that correctly read ustar format (see below) will also be
+able to read this format; any extended attributes will be extracted as
+separate files stored in
+.Pa PaxHeader
+directories.
+.It Cm ustar
+The libarchive library can both read and write this format.
+This format has the following limitations:
+.Bl -bullet -compact
+.It
+Device major and minor numbers are limited to 21 bits.
+Nodes with larger numbers will not be added to the archive.
+.It
+Path names in the archive are limited to 255 bytes.
+(Shorter if there is no / character in exactly the right place.)
+.It
+Symbolic links and hard links are stored in the archive with
+the name of the referenced file.
+This name is limited to 100 bytes.
+.It
+Extended attributes, file flags, and other extended
+security information cannot be stored.
+.It
+Archive entries are limited to 8 gigabytes in size.
+.El
+Note that the pax interchange format has none of these restrictions.
+The ustar format is old and widely supported.
+It is recommended when compatibility is the primary concern.
+.El
+.Pp
+The libarchive library also reads a variety of commonly-used extensions to
+the basic tar format.
+These extensions are recognized automatically whenever they appear.
+.Bl -tag -width indent
+.It Numeric extensions.
+The POSIX standards require fixed-length numeric fields to be written with
+some character position reserved for terminators.
+Libarchive allows these fields to be written without terminator characters.
+This extends the allowable range; in particular, ustar archives with this
+extension can support entries up to 64 gigabytes in size.
+Libarchive also recognizes base-256 values in most numeric fields.
+This essentially removes all limitations on file size, modification time,
+and device numbers.
+.It Solaris extensions
+Libarchive recognizes ACL and extended attribute records written
+by Solaris tar.
+Currently, libarchive only has support for old-style ACLs; the
+newer NFSv4 ACLs are recognized but discarded.
+.El
+.Pp
+The first tar program appeared in Seventh Edition Unix in 1979.
+The first official standard for the tar file format was the
+.Dq ustar
+(Unix Standard Tar) format defined by POSIX in 1988.
+POSIX.1-2001 extended the ustar format to create the
+.Dq pax interchange
+format.
+.Ss Cpio Formats
+The libarchive library can read a number of common cpio variants and can write
+.Dq odc
+and
+.Dq newc
+format archives.
+A cpio archive stores each entry as a fixed-size header followed
+by a variable-length filename and variable-length data.
+Unlike the tar format, the cpio format does only minimal padding
+of the header or file data.
+There are several cpio variants, which differ primarily in
+how they store the initial header: some store the values as
+octal or hexadecimal numbers in ASCII, others as binary values of
+varying byte order and length.
+.Bl -tag -width indent
+.It Cm binary
+The libarchive library transparently reads both big-endian and little-endian
+variants of the original binary cpio format.
+This format used 32-bit binary values for file size and mtime,
+and 16-bit binary values for the other fields.
+.It Cm odc
+The libarchive library can both read and write this
+POSIX-standard format, which is officially known as the
+.Dq cpio interchange format
+or the
+.Dq octet-oriented cpio archive format
+and sometimes unofficially referred to as the
+.Dq old character format .
+This format stores the header contents as octal values in ASCII.
+It is standard, portable, and immune from byte-order confusion.
+File sizes and mtime are limited to 33 bits (8GB file size),
+other fields are limited to 18 bits.
+.It Cm SVR4
+The libarchive library can read both CRC and non-CRC variants of
+this format.
+The SVR4 format uses eight-digit hexadecimal values for
+all header fields.
+This limits file size to 4GB, and also limits the mtime and
+other fields to 32 bits.
+The SVR4 format can optionally include a CRC of the file
+contents, although libarchive does not currently verify this CRC.
+.El
+.Pp
+Cpio first appeared in PWB/UNIX 1.0, which was released within
+AT&T in 1977.
+PWB/UNIX 1.0 formed the basis of System III Unix, released outside
+of AT&T in 1981.
+This makes cpio older than tar, although cpio was not included
+in Version 7 AT&T Unix.
+As a result, the tar command became much better known in universities
+and research groups that used Version 7.
+The combination of the
+.Nm find
+and
+.Nm cpio
+utilities provided very precise control over file selection.
+Unfortunately, the format has many limitations that make it unsuitable
+for widespread use.
+Only the POSIX format permits files over 4GB, and its 18-bit
+limit for most other fields makes it unsuitable for modern systems.
+In addition, cpio formats only store numeric UID/GID values (not
+usernames and group names), which can make it very difficult to correctly
+transfer archives across systems with dissimilar user numbering.
+.Ss Shar Formats
+A
+.Dq shell archive
+is a shell script that, when executed on a POSIX-compliant
+system, will recreate a collection of file system objects.
+The libarchive library can write two different kinds of shar archives:
+.Bl -tag -width indent
+.It Cm shar
+The traditional shar format uses a limited set of POSIX
+commands, including
+.Xr echo 1 ,
+.Xr mkdir 1 ,
+and
+.Xr sed 1 .
+It is suitable for portably archiving small collections of plain text files.
+However, it is not generally well-suited for large archives
+(many implementations of
+.Xr sh 1
+have limits on the size of a script) nor should it be used with non-text files.
+.It Cm shardump
+This format is similar to shar but encodes files using
+.Xr uuencode 1
+so that the result will be a plain text file regardless of the file contents.
+It also includes additional shell commands that attempt to reproduce as
+many file attributes as possible, including owner, mode, and flags.
+The additional commands used to restore file attributes make
+shardump archives less portable than plain shar archives.
+.El
+.Ss ISO9660 format
+Libarchive can read and extract from files containing ISO9660-compliant
+CDROM images.
+In many cases, this can remove the need to burn a physical CDROM
+just in order to read the files contained in an ISO9660 image.
+It also avoids security and complexity issues that come with
+virtual mounts and loopback devices.
+Libarchive supports the most common Rockridge extensions and has partial
+support for Joliet extensions.
+If both extensions are present, the Joliet extensions will be
+used and the Rockridge extensions will be ignored.
+In particular, this can create problems with hardlinks and symlinks,
+which are supported by Rockridge but not by Joliet.
+.Pp
+Libarchive reads ISO9660 images using a streaming strategy.
+This allows it to read compressed images directly
+(decompressing on the fly) and allows it to read images
+directly from network sockets, pipes, and other non-seekable
+data sources.
+This strategy works well for optimized ISO9660 images created
+by many popular programs.
+Such programs collect all directory information at the beginning
+of the ISO9660 image so it can be read from a physical disk
+with a minimum of seeking.
+However, not all ISO9660 images can be read in this fashion.
+.Pp
+Libarchive can also write ISO9660 images.
+Such images are fully optimized with the directory information
+preceding all file data.
+This is done by storing all file data to a temporary file
+while collecting directory information in memory.
+When the image is finished, libarchive writes out the
+directory structure followed by the file data.
+The location used for the temporary file can be changed
+by the usual environment variables.
+.Ss Zip format
+Libarchive can read and write zip format archives that have
+uncompressed entries and entries compressed with the
+.Dq deflate
+algorithm.
+Other zip compression algorithms are not supported.
+It can extract jar archives, archives that use Zip64 extensions and
+self-extracting zip archives.
+Libarchive can use either of two different strategies for
+reading Zip archives:
+a streaming strategy which is fast and can handle extremely
+large archives, and a seeking strategy which can correctly
+process self-extracting Zip archives and archives with
+deleted members or other in-place modifications.
+.Pp
+The streaming reader processes Zip archives as they are read.
+It can read archives of arbitrary size from tape or
+network sockets, and can decode Zip archives that have
+been separately compressed or encoded.
+However, self-extracting Zip archives and archives with
+certain types of modifications cannot be correctly
+handled.
+Such archives require that the reader first process the
+Central Directory, which is ordinarily located
+at the end of a Zip archive and is thus inaccessible
+to the streaming reader.
+If the program using libarchive has enabled seek support, then
+libarchive will use this to processes the central directory first.
+.Pp
+In particular, the seeking reader must be used to
+correctly handle self-extracting archives.
+Such archives consist of a program followed by a regular
+Zip archive.
+The streaming reader cannot parse the initial program
+portion, but the seeking reader starts by reading the
+Central Directory from the end of the archive.
+Similarly, Zip archives that have been modified in-place
+can have deleted entries or other garbage data that
+can only be accurately detected by first reading the
+Central Directory.
+.Ss Archive (library) file format
+The Unix archive format (commonly created by the
+.Xr ar 1
+archiver) is a general-purpose format which is
+used almost exclusively for object files to be
+read by the link editor
+.Xr ld 1 .
+The ar format has never been standardised.
+There are two common variants:
+the GNU format derived from SVR4,
+and the BSD format, which first appeared in 4.4BSD.
+The two differ primarily in their handling of filenames
+longer than 15 characters:
+the GNU/SVR4 variant writes a filename table at the beginning of the archive;
+the BSD format stores each long filename in an extension
+area adjacent to the entry.
+Libarchive can read both extensions,
+including archives that may include both types of long filenames.
+Programs using libarchive can write GNU/SVR4 format
+if they provide a filename table to be written into
+the archive before any of the entries.
+Any entries whose names are not in the filename table
+will be written using BSD-style long filenames.
+This can cause problems for programs such as
+GNU ld that do not support the BSD-style long filenames.
+.Ss mtree
+Libarchive can read and write files in
+.Xr mtree 5
+format.
+This format is not a true archive format, but rather a textual description
+of a file hierarchy in which each line specifies the name of a file and
+provides specific metadata about that file.
+Libarchive can read all of the keywords supported by both
+the NetBSD and FreeBSD versions of
+.Xr mtree 8 ,
+although many of the keywords cannot currently be stored in an
+.Tn archive_entry
+object.
+When writing, libarchive supports use of the
+.Xr archive_write_set_options 3
+interface to specify which keywords should be included in the
+output.
+If libarchive was compiled with access to suitable
+cryptographic libraries (such as the OpenSSL libraries),
+it can compute hash entries such as
+.Cm sha512
+or
+.Cm md5
+from file data being written to the mtree writer.
+.Pp
+When reading an mtree file, libarchive will locate the corresponding
+files on disk using the
+.Cm contents
+keyword if present or the regular filename.
+If it can locate and open the file on disk, it will use that
+to fill in any metadata that is missing from the mtree file
+and will read the file contents and return those to the program
+using libarchive.
+If it cannot locate and open the file on disk, libarchive
+will return an error for any attempt to read the entry
+body.
+.Ss LHA
+XXX Information about libarchive's LHA support XXX
+.Ss CAB
+XXX Information about libarchive's CAB support XXX
+.Ss XAR
+XXX Information about libarchive's XAR support XXX
+.Ss RAR
+Libarchive has limited support for reading RAR format archives.
+Currently, libarchive can read RARv3 format archives
+which have been either created uncompressed, or compressed using
+any of the compression methods supported by the RARv3 format.
+Libarchive can also read self-extracting RAR archives.
+.Sh SEE ALSO
+.Xr ar 1 ,
+.Xr cpio 1 ,
+.Xr mkisofs 1 ,
+.Xr shar 1 ,
+.Xr tar 1 ,
+.Xr zip 1 ,
+.Xr zlib 3 ,
+.Xr cpio 5 ,
+.Xr mtree 5 ,
+.Xr tar 5
diff --git a/Utilities/cmlibarchive/libarchive/libarchive.3 b/Utilities/cmlibarchive/libarchive/libarchive.3
new file mode 100644
index 0000000000..3a9a841d3b
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/libarchive.3
@@ -0,0 +1,289 @@
+.\" Copyright (c) 2003-2007 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd March 18, 2012
+.Dt LIBARCHIVE 3
+.Os
+.Sh NAME
+.Nm libarchive
+.Nd functions for reading and writing streaming archives
+.Sh OVERVIEW
+The
+.Nm
+library provides a flexible interface for reading and writing
+archives in various formats such as tar and cpio.
+.Nm
+also supports reading and writing archives compressed using
+various compression filters such as gzip and bzip2.
+The library is inherently stream-oriented; readers serially iterate through
+the archive, writers serially add things to the archive.
+In particular, note that there is currently no built-in support for
+random access nor for in-place modification.
+.Pp
+When reading an archive, the library automatically detects the
+format and the compression.
+The library currently has read support for:
+.Bl -bullet -compact
+.It
+old-style tar archives,
+.It
+most variants of the POSIX
+.Dq ustar
+format,
+.It
+the POSIX
+.Dq pax interchange
+format,
+.It
+GNU-format tar archives,
+.It
+most common cpio archive formats,
+.It
+ISO9660 CD images (including RockRidge and Joliet extensions),
+.It
+Zip archives,
+.It
+ar archives (including GNU/SysV and BSD extensions),
+.It
+Microsoft CAB archives,
+.It
+LHA archives,
+.It
+mtree file tree descriptions,
+.It
+RAR archives,
+.It
+XAR archives.
+.El
+The library automatically detects archives compressed with
+.Xr gzip 1 ,
+.Xr bzip2 1 ,
+.Xr xz 1 ,
+.Xr lzip 1 ,
+or
+.Xr compress 1
+and decompresses them transparently.
+It can similarly detect and decode archives processed with
+.Xr uuencode 1
+or which have an
+.Xr rpm 1
+header.
+.Pp
+When writing an archive, you can specify the compression
+to be used and the format to use.
+The library can write
+.Bl -bullet -compact
+.It
+POSIX-standard
+.Dq ustar
+archives,
+.It
+POSIX
+.Dq pax interchange format
+archives,
+.It
+POSIX octet-oriented cpio archives,
+.It
+Zip archive,
+.It
+two different variants of shar archives,
+.It
+ISO9660 CD images,
+.It
+7-Zip archives,
+.It
+ar archives,
+.It
+mtree file tree descriptions,
+.It
+XAR archives.
+.El
+Pax interchange format is an extension of the tar archive format that
+eliminates essentially all of the limitations of historic tar formats
+in a standard fashion that is supported
+by POSIX-compliant
+.Xr pax 1
+implementations on many systems as well as several newer implementations of
+.Xr tar 1 .
+Note that the default write format will suppress the pax extended
+attributes for most entries; explicitly requesting pax format will
+enable those attributes for all entries.
+.Pp
+The read and write APIs are accessed through the
+.Fn archive_read_XXX
+functions and the
+.Fn archive_write_XXX
+functions, respectively, and either can be used independently
+of the other.
+.Pp
+The rest of this manual page provides an overview of the library
+operation.
+More detailed information can be found in the individual manual
+pages for each API or utility function.
+.\"
+.Sh READING AN ARCHIVE
+See
+.Xr libarchive_read 3 .
+.\"
+.Sh WRITING AN ARCHIVE
+See
+.Xr libarchive_write 3 .
+.\"
+.Sh WRITING ENTRIES TO DISK
+The
+.Xr archive_write_disk 3
+API allows you to write
+.Xr archive_entry 3
+objects to disk using the same API used by
+.Xr archive_write 3 .
+The
+.Xr archive_write_disk 3
+API is used internally by
+.Fn archive_read_extract ;
+using it directly can provide greater control over how entries
+get written to disk.
+This API also makes it possible to share code between
+archive-to-archive copy and archive-to-disk extraction
+operations.
+.Sh READING ENTRIES FROM DISK
+The
+.Xr archive_read_disk 3
+supports for populating
+.Xr archive_entry 3
+objects from information in the filesystem.
+This includes the information accessible from the
+.Xr stat 2
+system call as well as ACLs, extended attributes,
+and other metadata.
+The
+.Xr archive_read_disk 3
+API also supports iterating over directory trees,
+which allows directories of files to be read using
+an API compatible with
+the
+.Xr archive_read 3
+API.
+.Sh DESCRIPTION
+Detailed descriptions of each function are provided by the
+corresponding manual pages.
+.Pp
+All of the functions utilize an opaque
+.Tn struct archive
+datatype that provides access to the archive contents.
+.Pp
+The
+.Tn struct archive_entry
+structure contains a complete description of a single archive
+entry.
+It uses an opaque interface that is fully documented in
+.Xr archive_entry 3 .
+.Pp
+Users familiar with historic formats should be aware that the newer
+variants have eliminated most restrictions on the length of textual fields.
+Clients should not assume that filenames, link names, user names, or
+group names are limited in length.
+In particular, pax interchange format can easily accommodate pathnames
+in arbitrary character sets that exceed
+.Va PATH_MAX .
+.Sh RETURN VALUES
+Most functions return
+.Cm ARCHIVE_OK
+(zero) on success, non-zero on error.
+The return value indicates the general severity of the error, ranging
+from
+.Cm ARCHIVE_WARN ,
+which indicates a minor problem that should probably be reported
+to the user, to
+.Cm ARCHIVE_FATAL ,
+which indicates a serious problem that will prevent any further
+operations on this archive.
+On error, the
+.Fn archive_errno
+function can be used to retrieve a numeric error code (see
+.Xr errno 2 ) .
+The
+.Fn archive_error_string
+returns a textual error message suitable for display.
+.Pp
+.Fn archive_read_new
+and
+.Fn archive_write_new
+return pointers to an allocated and initialized
+.Tn struct archive
+object.
+.Pp
+.Fn archive_read_data
+and
+.Fn archive_write_data
+return a count of the number of bytes actually read or written.
+A value of zero indicates the end of the data for this entry.
+A negative value indicates an error, in which case the
+.Fn archive_errno
+and
+.Fn archive_error_string
+functions can be used to obtain more information.
+.Sh ENVIRONMENT
+There are character set conversions within the
+.Xr archive_entry 3
+functions that are impacted by the currently-selected locale.
+.Sh SEE ALSO
+.Xr tar 1 ,
+.Xr archive_entry 3 ,
+.Xr archive_read 3 ,
+.Xr archive_util 3 ,
+.Xr archive_write 3 ,
+.Xr tar 5
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libarchive
+library was originally written by
+.An Tim Kientzle Aq kientzle@acm.org .
+.Sh BUGS
+Some archive formats support information that is not supported by
+.Tn struct archive_entry .
+Such information cannot be fully archived or restored using this library.
+This includes, for example, comments, character sets,
+or the arbitrary key/value pairs that can appear in
+pax interchange format archives.
+.Pp
+Conversely, of course, not all of the information that can be
+stored in an
+.Tn struct archive_entry
+is supported by all formats.
+For example, cpio formats do not support nanosecond timestamps;
+old tar formats do not support large device numbers.
+.Pp
+The ISO9660 reader cannot yet read all ISO9660 images;
+it should learn how to seek.
+.Pp
+The AR writer requires the client program to use
+two passes, unlike all other libarchive writers.
diff --git a/Utilities/cmlibarchive/libarchive/libarchive_changes.3 b/Utilities/cmlibarchive/libarchive/libarchive_changes.3
new file mode 100644
index 0000000000..bacd6e123a
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/libarchive_changes.3
@@ -0,0 +1,341 @@
+.\" Copyright (c) 2011 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd December 23, 2011
+.Dt LIBARCHIVE_CHANGES 3
+.Os
+.Sh NAME
+.Nm changes in libarchive interface
+.\"
+.Sh CHANGES IN LIBARCHIVE 3
+This page describes user-visible changes in libarchive3, and lists
+public functions and other symbols changed, deprecated or removed
+in libarchive3, along with their replacements if any.
+.Pp
+.\"
+.Ss Multiple Filters
+.\"
+Libarchive2 permitted a single (input or output) filter active
+on an archive.
+Libarchive3 extends this into a variable-length stack.
+Where
+.Fn archive_write_set_compression_XXX
+would replace any existing filter,
+.Fn archive_write_add_filter_XXX
+extends the write pipeline with another filter.
+.\"
+.Ss Character Set Handling
+.\"
+Libarchive2 assumed that the local platform uses
+.Tn Unicode
+as the native
+.Tn wchar_t
+encoding, which is true on
+.Tn Windows ,
+modern
+.Tn Linux ,
+and a few other systems, but is certainly not universal.
+As a result, pax format archives were written incorrectly on some
+systems, since pax format requires
+.Tn UTF-8
+and libarchive 2 incorrectly
+assumed that
+.Tn wchar_t
+strings can be easily converted to
+.Tn UTF-8 .
+.Pp
+Libarchive3 uses the standard iconv library to convert between character
+sets and is introducing the notion of a
+.Dq default character set for the archive .
+To support this,
+.Tn archive_entry
+objects can now be bound to a particular archive when they are created.
+The automatic character set conversions performed by
+.Tn archive_entry
+objects when reading and writing filenames, usernames, and other strings
+will now use an appropriate default character set:
+.Pp
+If the
+.Tn archive_entry
+object is bound to an archive, it will use the
+default character set for that archive.
+.Pp
+The platform default character encoding (as returned by
+.Fn nl_langinfo CHARSET )
+will be used if nothing else is specified.
+.Pp
+Libarchive3 also introduces charset options to many of the archive
+readers and writers to control the character set that will be used for
+filenames written in those archives.
+When possible, this will be set automatically based on information in
+the archive itself.
+Combining this with the notion of a default character set for the
+archive should allow you to configure libarchive to read archives from
+other platforms and have the filenames and other information
+transparently converted to the character encoding suitable for your
+application.
+.\"
+.Ss Prototype Changes
+.\"
+These changes break binary compatibility; libarchive3 has a new shared
+library version to reflect these changes.
+The library now uses portable wide types such as
+.Tn int64_t
+instead of less-portable types such as
+.Tn off_t ,
+.Tn gid_t ,
+.Tn uid_t ,
+and
+.Tn ino_t .
+.Pp
+There are a few cases where these changes will affect your source code:
+.Bl -bullet -width ind
+.It
+In some cases, libarchive's wider types will introduce the possibility
+of truncation: for example, on a system with a 16-bit
+.Tn uid_t , you risk having uid
+.Li 65536
+be truncated to uid
+.Li 0 ,
+which can cause serious security problems.
+.It
+Typedef function pointer types will be incompatible.
+For example, if you define custom skip callbacks, you may have to use
+code similar to the following if you want to support building against
+libarchive2 and libarchive3:
+.Bd -literal
+#if ARCHIVE_VERSION_NUMBER < 3000000
+typedef off_t myoff_t;
+#else
+typedef int64_t myoff_t;
+#endif
+
+myoff_t
+my_skip_function(struct archive *a, void *v, myoff_t o)
+{
+ ... implementation ...
+}
+.Ed
+.El
+.Pp
+Affected functions:
+.Pp
+.Bl -bullet -compact
+.It
+.Xo
+.Fn archive_entry_gid ,
+.Fn archive_entry_set_gid
+.Xc
+.It
+.Xo
+.Fn archive_entry_uid ,
+.Fn archive_entry_set_uid
+.Xc
+.It
+.Xo
+.Fn archive_entry_ino ,
+.Fn archive_entry_set_ino
+.Xc
+.It
+.Xo
+.Fn archive_read_data_block ,
+.Fn archive_write_data_block
+.Xc
+.It
+.Xo
+.Fn archive_read_disk_gname ,
+.Fn archive_read_disk_uname
+.Xc
+.It
+.Xo
+.Fn archive_read_disk_set_gname_lookup ,
+.Fn archive_read_disk_set_group_lookup ,
+.Fn archive_read_disk_set_uname_lookup ,
+.Fn archive_read_disk_set_user_lookup
+.Xc
+.It
+.Fn archive_skip_callback
+.It
+.Xo
+.Fn archive_read_extract_set_skip_file ,
+.Fn archive_write_disk_set_skip_file ,
+.Fn archive_write_set_skip_file
+.Xc
+.It
+.Xo
+.Fn archive_write_disk_set_group_lookup ,
+.Fn archive_write_disk_set_user_lookup
+.Xc
+.El
+.Pp
+Where these functions or their arguments took or returned
+.Tn gid_t ,
+.Tn ino_t ,
+.Tn off_t ,
+or
+.Tn uid_t
+they now take or return
+.Tn int64_t
+or equivalent.
+.\"
+.Ss Deprecated Symbols
+.\"
+Symbols deprecated in libarchive3 will be removed in libarchive4.
+These symbols, along with their replacements if any, are listed below:
+.\"
+.Bl -tag -width ind
+.It Fn archive_position_compressed , Fn archive_position_uncompressed
+.Fn archive_filter_bytes
+.It Fn archive_compression
+.Fn archive_filter_code
+.It Fn archive_compression_name
+.Fn archive_filter_name
+.It Fn archive_read_finish , Fn archive_write_finish
+.Fn archive_read_free ,
+.Fn archive_write_free
+.It Fn archive_read_open_file , Fn archive_write_open_file
+.Fn archive_read_open_filename ,
+.Fn archive_write_open_filename
+.It Fn archive_read_support_compression_all
+.\" archive_read_support_compression_* -> archive_read_support_filter_*
+.Fn archive_read_support_filter_all
+.It Fn archive_read_support_compression_bzip2
+.Fn archive_read_support_filter_bzip2
+.It Fn archive_read_support_compression_compress
+.Fn archive_read_support_filter_compress
+.It Fn archive_read_support_compression_gzip
+.Fn archive_read_support_filter_gzip
+.It Fn archive_read_support_compression_lzip
+.Fn archive_read_support_filter_lzip
+.It Fn archive_read_support_compression_lzma
+.Fn archive_read_support_filter_lzma
+.It Fn archive_read_support_compression_none
+.Fn archive_read_support_filter_none
+.It Fn archive_read_support_compression_program
+.Fn archive_read_support_filter_program
+.It Fn archive_read_support_compression_program_signature
+.Fn archive_read_support_filter_program_signature
+.It Fn archive_read_support_compression_rpm
+.Fn archive_read_support_filter_rpm
+.It Fn archive_read_support_compression_uu
+.Fn archive_read_support_filter_uu
+.It Fn archive_read_support_compression_xz
+.Fn archive_read_support_filter_xz
+.\" archive_write_set_compression_* -> archive_write_add_filter_*
+.It Fn archive_write_set_compression_bzip2
+.Fn archive_write_add_filter_bzip2
+.It Fn archive_write_set_compression_compress
+.Fn archive_write_add_filter_compress
+.It Fn archive_write_set_compression_gzip
+.Fn archive_write_add_filter_gzip
+.It Fn archive_write_set_compression_lzip
+.Fn archive_write_add_filter_lzip
+.It Fn archive_write_set_compression_lzma
+.Fn archive_write_add_filter_lzma
+.It Fn archive_write_set_compression_none
+.Fn archive_write_add_filter_none
+.It Fn archive_write_set_compression_program
+.Fn archive_write_add_filter_program
+.It Fn archive_write_set_compression_filter
+.Fn archive_write_add_filter_filter
+.El
+.\"
+.Ss Removed Symbols
+.\"
+These symbols, listed below along with their replacements if any,
+were deprecated in libarchive2, and are not part of libarchive3.
+.\"
+.Bl -tag -width ind
+.It Fn archive_api_feature
+.Fn archive_version_number
+.It Fn archive_api_version
+.Fn archive_version_number
+.It Fn archive_version
+.Fn archive_version_string
+.It Fn archive_version_stamp
+.Fn archive_version_number
+.It Fn archive_read_set_filter_options
+.Fn archive_read_set_options
+or
+.Fn archive_read_set_filter_option
+.It Fn archive_read_set_format_options
+.Fn archive_read_set_options
+or
+.Fn archive_read_set_format_option
+.It Fn archive_write_set_filter_options
+.Fn archive_write_set_options
+or
+.Fn archive_write_set_filter_option
+.It Fn archive_write_set_format_options
+.Fn archive_write_set_options
+or
+.Fn archive_write_set_format_option
+.It Dv ARCHIVE_API_FEATURE
+.Dv ARCHIVE_VERSION_NUMBER
+.It Dv ARCHIVE_API_VERSION
+.Dv ARCHIVE_VERSION_NUMBER
+.It Dv ARCHIVE_VERSION_STAMP
+.Dv ARCHIVE_VERSION_NUMBER
+.It Dv ARCHIVE_LIBRARY_VERSION
+.Dv ARCHIVE_VERSION_STRING
+.\"
+.It Dv ARCHIVE_COMPRESSION_NONE
+.Dv ARCHIVE_FILTER_NONE
+.It Dv ARCHIVE_COMPRESSION_GZIP
+.Dv ARCHIVE_FILTER_GZIP
+.It Dv ARCHIVE_COMPRESSION_BZIP2
+.Dv ARCHIVE_FILTER_BZIP2
+.It Dv ARCHIVE_COMPRESSION_COMPRESS
+.Dv ARCHIVE_FILTER_COMPRESS
+.It Dv ARCHIVE_COMPRESSION_PROGRAM
+.Dv ARCHIVE_FILTER_PROGRAM
+.It Dv ARCHIVE_COMPRESSION_LZMA
+.Dv ARCHIVE_FILTER_LZMA
+.It Dv ARCHIVE_COMPRESSION_XZ
+.Dv ARCHIVE_FILTER_XZ
+.It Dv ARCHIVE_COMPRESSION_UU
+.Dv ARCHIVE_FILTER_UU
+.It Dv ARCHIVE_COMPRESSION_RPM
+.Dv ARCHIVE_FILTER_RPM
+.It Dv ARCHIVE_COMPRESSION_LZIP
+.Dv ARCHIVE_FILTER_LZIP
+.\"
+.It Dv ARCHIVE_BYTES_PER_RECORD
+.Li 512
+.It Dv ARCHIVE_DEFAULT_BYTES_PER_BLOCK
+.Li 10240
+.El
+.Sh SEE ALSO
+.Xr libarchive 3 ,
+.Xr archive_read 3 ,
+.Xr archive_read_filter 3 ,
+.Xr archive_read_format 3 ,
+.Xr archive_read_set_options 3 ,
+.Xr archive_write 3 ,
+.Xr archive_write_filter 3 ,
+.Xr archive_write_format 3 ,
+.Xr archive_write_set_options 3 ,
+.Xr archive_util 3
diff --git a/Utilities/cmlibarchive/libarchive/libarchive_internals.3 b/Utilities/cmlibarchive/libarchive/libarchive_internals.3
new file mode 100644
index 0000000000..4aa09f93ea
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/libarchive_internals.3
@@ -0,0 +1,365 @@
+.\" Copyright (c) 2003-2007 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd January 26, 2011
+.Dt LIBARCHIVE_INTERNALS 3
+.Os
+.Sh NAME
+.Nm libarchive_internals
+.Nd description of libarchive internal interfaces
+.Sh OVERVIEW
+The
+.Nm libarchive
+library provides a flexible interface for reading and writing
+streaming archive files such as tar and cpio.
+Internally, it follows a modular layered design that should
+make it easy to add new archive and compression formats.
+.Sh GENERAL ARCHITECTURE
+Externally, libarchive exposes most operations through an
+opaque, object-style interface.
+The
+.Xr archive_entry 3
+objects store information about a single filesystem object.
+The rest of the library provides facilities to write
+.Xr archive_entry 3
+objects to archive files,
+read them from archive files,
+and write them to disk.
+(There are plans to add a facility to read
+.Xr archive_entry 3
+objects from disk as well.)
+.Pp
+The read and write APIs each have four layers: a public API
+layer, a format layer that understands the archive file format,
+a compression layer, and an I/O layer.
+The I/O layer is completely exposed to clients who can replace
+it entirely with their own functions.
+.Pp
+In order to provide as much consistency as possible for clients,
+some public functions are virtualized.
+Eventually, it should be possible for clients to open
+an archive or disk writer, and then use a single set of
+code to select and write entries, regardless of the target.
+.Sh READ ARCHITECTURE
+From the outside, clients use the
+.Xr archive_read 3
+API to manipulate an
+.Nm archive
+object to read entries and bodies from an archive stream.
+Internally, the
+.Nm archive
+object is cast to an
+.Nm archive_read
+object, which holds all read-specific data.
+The API has four layers:
+The lowest layer is the I/O layer.
+This layer can be overridden by clients, but most clients use
+the packaged I/O callbacks provided, for example, by
+.Xr archive_read_open_memory 3 ,
+and
+.Xr archive_read_open_fd 3 .
+The compression layer calls the I/O layer to
+read bytes and decompresses them for the format layer.
+The format layer unpacks a stream of uncompressed bytes and
+creates
+.Nm archive_entry
+objects from the incoming data.
+The API layer tracks overall state
+(for example, it prevents clients from reading data before reading a header)
+and invokes the format and compression layer operations
+through registered function pointers.
+In particular, the API layer drives the format-detection process:
+When opening the archive, it reads an initial block of data
+and offers it to each registered compression handler.
+The one with the highest bid is initialized with the first block.
+Similarly, the format handlers are polled to see which handler
+is the best for each archive.
+(Prior to 2.4.0, the format bidders were invoked for each
+entry, but this design hindered error recovery.)
+.Ss I/O Layer and Client Callbacks
+The read API goes to some lengths to be nice to clients.
+As a result, there are few restrictions on the behavior of
+the client callbacks.
+.Pp
+The client read callback is expected to provide a block
+of data on each call.
+A zero-length return does indicate end of file, but otherwise
+blocks may be as small as one byte or as large as the entire file.
+In particular, blocks may be of different sizes.
+.Pp
+The client skip callback returns the number of bytes actually
+skipped, which may be much smaller than the skip requested.
+The only requirement is that the skip not be larger.
+In particular, clients are allowed to return zero for any
+skip that they don't want to handle.
+The skip callback must never be invoked with a negative value.
+.Pp
+Keep in mind that not all clients are reading from disk:
+clients reading from networks may provide different-sized
+blocks on every request and cannot skip at all;
+advanced clients may use
+.Xr mmap 2
+to read the entire file into memory at once and return the
+entire file to libarchive as a single block;
+other clients may begin asynchronous I/O operations for the
+next block on each request.
+.Ss Decompresssion Layer
+The decompression layer not only handles decompression,
+it also buffers data so that the format handlers see a
+much nicer I/O model.
+The decompression API is a two stage peek/consume model.
+A read_ahead request specifies a minimum read amount;
+the decompression layer must provide a pointer to at least
+that much data.
+If more data is immediately available, it should return more:
+the format layer handles bulk data reads by asking for a minimum
+of one byte and then copying as much data as is available.
+.Pp
+A subsequent call to the
+.Fn consume
+function advances the read pointer.
+Note that data returned from a
+.Fn read_ahead
+call is guaranteed to remain in place until
+the next call to
+.Fn read_ahead .
+Intervening calls to
+.Fn consume
+should not cause the data to move.
+.Pp
+Skip requests must always be handled exactly.
+Decompression handlers that cannot seek forward should
+not register a skip handler;
+the API layer fills in a generic skip handler that reads and discards data.
+.Pp
+A decompression handler has a specific lifecycle:
+.Bl -tag -compact -width indent
+.It Registration/Configuration
+When the client invokes the public support function,
+the decompression handler invokes the internal
+.Fn __archive_read_register_compression
+function to provide bid and initialization functions.
+This function returns
+.Cm NULL
+on error or else a pointer to a
+.Cm struct decompressor_t .
+This structure contains a
+.Va void * config
+slot that can be used for storing any customization information.
+.It Bid
+The bid function is invoked with a pointer and size of a block of data.
+The decompressor can access its config data
+through the
+.Va decompressor
+element of the
+.Cm archive_read
+object.
+The bid function is otherwise stateless.
+In particular, it must not perform any I/O operations.
+.Pp
+The value returned by the bid function indicates its suitability
+for handling this data stream.
+A bid of zero will ensure that this decompressor is never invoked.
+Return zero if magic number checks fail.
+Otherwise, your initial implementation should return the number of bits
+actually checked.
+For example, if you verify two full bytes and three bits of another
+byte, bid 19.
+Note that the initial block may be very short;
+be careful to only inspect the data you are given.
+(The current decompressors require two bytes for correct bidding.)
+.It Initialize
+The winning bidder will have its init function called.
+This function should initialize the remaining slots of the
+.Va struct decompressor_t
+object pointed to by the
+.Va decompressor
+element of the
+.Va archive_read
+object.
+In particular, it should allocate any working data it needs
+in the
+.Va data
+slot of that structure.
+The init function is called with the block of data that
+was used for tasting.
+At this point, the decompressor is responsible for all I/O
+requests to the client callbacks.
+The decompressor is free to read more data as and when
+necessary.
+.It Satisfy I/O requests
+The format handler will invoke the
+.Va read_ahead ,
+.Va consume ,
+and
+.Va skip
+functions as needed.
+.It Finish
+The finish method is called only once when the archive is closed.
+It should release anything stored in the
+.Va data
+and
+.Va config
+slots of the
+.Va decompressor
+object.
+It should not invoke the client close callback.
+.El
+.Ss Format Layer
+The read formats have a similar lifecycle to the decompression handlers:
+.Bl -tag -compact -width indent
+.It Registration
+Allocate your private data and initialize your pointers.
+.It Bid
+Formats bid by invoking the
+.Fn read_ahead
+decompression method but not calling the
+.Fn consume
+method.
+This allows each bidder to look ahead in the input stream.
+Bidders should not look further ahead than necessary, as long
+look aheads put pressure on the decompression layer to buffer
+lots of data.
+Most formats only require a few hundred bytes of look ahead;
+look aheads of a few kilobytes are reasonable.
+(The ISO9660 reader sometimes looks ahead by 48k, which
+should be considered an upper limit.)
+.It Read header
+The header read is usually the most complex part of any format.
+There are a few strategies worth mentioning:
+For formats such as tar or cpio, reading and parsing the header is
+straightforward since headers alternate with data.
+For formats that store all header data at the beginning of the file,
+the first header read request may have to read all headers into
+memory and store that data, sorted by the location of the file
+data.
+Subsequent header read requests will skip forward to the
+beginning of the file data and return the corresponding header.
+.It Read Data
+The read data interface supports sparse files; this requires that
+each call return a block of data specifying the file offset and
+size.
+This may require you to carefully track the location so that you
+can return accurate file offsets for each read.
+Remember that the decompressor will return as much data as it has.
+Generally, you will want to request one byte,
+examine the return value to see how much data is available, and
+possibly trim that to the amount you can use.
+You should invoke consume for each block just before you return it.
+.It Skip All Data
+The skip data call should skip over all file data and trailing padding.
+This is called automatically by the API layer just before each
+header read.
+It is also called in response to the client calling the public
+.Fn data_skip
+function.
+.It Cleanup
+On cleanup, the format should release all of its allocated memory.
+.El
+.Ss API Layer
+XXX to do XXX
+.Sh WRITE ARCHITECTURE
+The write API has a similar set of four layers:
+an API layer, a format layer, a compression layer, and an I/O layer.
+The registration here is much simpler because only
+one format and one compression can be registered at a time.
+.Ss I/O Layer and Client Callbacks
+XXX To be written XXX
+.Ss Compression Layer
+XXX To be written XXX
+.Ss Format Layer
+XXX To be written XXX
+.Ss API Layer
+XXX To be written XXX
+.Sh WRITE_DISK ARCHITECTURE
+The write_disk API is intended to look just like the write API
+to clients.
+Since it does not handle multiple formats or compression, it
+is not layered internally.
+.Sh GENERAL SERVICES
+The
+.Nm archive_read ,
+.Nm archive_write ,
+and
+.Nm archive_write_disk
+objects all contain an initial
+.Nm archive
+object which provides common support for a set of standard services.
+(Recall that ANSI/ISO C90 guarantees that you can cast freely between
+a pointer to a structure and a pointer to the first element of that
+structure.)
+The
+.Nm archive
+object has a magic value that indicates which API this object
+is associated with,
+slots for storing error information,
+and function pointers for virtualized API functions.
+.Sh MISCELLANEOUS NOTES
+Connecting existing archiving libraries into libarchive is generally
+quite difficult.
+In particular, many existing libraries strongly assume that you
+are reading from a file; they seek forwards and backwards as necessary
+to locate various pieces of information.
+In contrast, libarchive never seeks backwards in its input, which
+sometimes requires very different approaches.
+.Pp
+For example, libarchive's ISO9660 support operates very differently
+from most ISO9660 readers.
+The libarchive support utilizes a work-queue design that
+keeps a list of known entries sorted by their location in the input.
+Whenever libarchive's ISO9660 implementation is asked for the next
+header, checks this list to find the next item on the disk.
+Directories are parsed when they are encountered and new
+items are added to the list.
+This design relies heavily on the ISO9660 image being optimized so that
+directories always occur earlier on the disk than the files they
+describe.
+.Pp
+Depending on the specific format, such approaches may not be possible.
+The ZIP format specification, for example, allows archivers to store
+key information only at the end of the file.
+In theory, it is possible to create ZIP archives that cannot
+be read without seeking.
+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
+.Sh HISTORY
+The
+.Nm libarchive
+library first appeared in
+.Fx 5.3 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libarchive
+library was written by
+.An Tim Kientzle Aq kientzle@acm.org .
diff --git a/Utilities/cmlibarchive/libarchive/mtree.5 b/Utilities/cmlibarchive/libarchive/mtree.5
new file mode 100644
index 0000000000..8c45a7ded0
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/mtree.5
@@ -0,0 +1,345 @@
+.\" Copyright (c) 1989, 1990, 1993
+.\" The Regents of the University of California. 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.
+.\" 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+.\"
+.\" From: @(#)mtree.8 8.2 (Berkeley) 12/11/93
+.\" $FreeBSD$
+.\"
+.Dd September 4, 2013
+.Dt MTREE 5
+.Os
+.Sh NAME
+.Nm mtree
+.Nd format of mtree dir hierarchy files
+.Sh DESCRIPTION
+The
+.Nm
+format is a textual format that describes a collection of filesystem objects.
+Such files are typically used to create or verify directory hierarchies.
+.Ss General Format
+An
+.Nm
+file consists of a series of lines, each providing information
+about a single filesystem object.
+Leading whitespace is always ignored.
+.Pp
+When encoding file or pathnames, any backslash character or
+character outside of the 95 printable ASCII characters must be
+encoded as a a backslash followed by three
+octal digits.
+When reading mtree files, any appearance of a backslash
+followed by three octal digits should be converted into the
+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
+Lines beginning with
+.Cm #
+are ignored.
+.It Special
+Lines beginning with
+.Cm /
+are special commands that influence
+the interpretation of later lines.
+.It Relative
+If the first whitespace-delimited word has no
+.Cm /
+characters,
+it is the name of a file in the current directory.
+Any relative entry that describes a directory changes the
+current directory.
+.It dot-dot
+As a special case, a relative entry with the filename
+.Pa ..
+changes the current directory to the parent directory.
+Options on dot-dot entries are always ignored.
+.It Full
+If the first whitespace-delimited word has a
+.Cm /
+character after
+the first character, it is the pathname of a file relative to the
+starting directory.
+There can be multiple full entries describing the same file.
+.El
+.Pp
+Some tools that process
+.Nm
+files may require that multiple lines describing the same file
+occur consecutively.
+It is not permitted for the same file to be mentioned using
+both a relative and a full file specification.
+.Ss Special commands
+Two special commands are currently defined:
+.Bl -tag -width Cm
+.It Cm /set
+This command defines default values for one or more keywords.
+It is followed on the same line by one or more whitespace-separated
+keyword definitions.
+These definitions apply to all following files that do not specify
+a value for that keyword.
+.It Cm /unset
+This command removes any default value set by a previous
+.Cm /set
+command.
+It is followed on the same line by one or more keywords
+separated by whitespace.
+.El
+.Ss Keywords
+After the filename, a full or relative entry consists of zero
+or more whitespace-separated keyword definitions.
+Each such definition consists of a key from the following
+list immediately followed by an '=' sign
+and a value.
+Software programs reading mtree files should warn about
+unrecognized keywords.
+.Pp
+Currently supported keywords are as follows:
+.Bl -tag -width Cm
+.It Cm cksum
+The checksum of the file using the default algorithm specified by
+the
+.Xr cksum 1
+utility.
+.It Cm device
+The device number for
+.Sy block
+or
+.Sy char
+file types.
+The value must be one of the following forms:
+.Pp
+.Bl -tag -width 4n
+.It Ar format , Ns Ar major , Ns Ar minor Ns Bo , Ns Ar subunit Bc
+A device with
+.Ar major , minor
+and optional
+.Ar subunit
+fields.
+Their meaning is specified by the operating's system
+.Ar format .
+See below for valid formats.
+.It Ar number
+Opaque number (as stored on the file system).
+.El
+.Pp
+The following values for
+.Ar format
+are recognized:
+.Sy native ,
+.Sy 386bsd ,
+.Sy 4bsd ,
+.Sy bsdos ,
+.Sy freebsd ,
+.Sy hpux ,
+.Sy isc ,
+.Sy linux ,
+.Sy netbsd ,
+.Sy osf1 ,
+.Sy sco ,
+.Sy solaris ,
+.Sy sunos ,
+.Sy svr3 ,
+.Sy svr4 ,
+and
+.Sy ultrix .
+.Pp
+See
+.Xr mknod 8
+for more details.
+.It Cm contents
+The full pathname of a file that holds the contents of this file.
+.It Cm flags
+The file flags as a symbolic name.
+See
+.Xr chflags 1
+for information on these names.
+If no flags are to be set the string
+.Dq none
+may be used to override the current default.
+.It Cm gid
+The file group as a numeric value.
+.It Cm gname
+The file group as a symbolic name.
+.It Cm ignore
+Ignore any file hierarchy below this file.
+.It Cm inode
+The inode number.
+.It Cm link
+The target of the symbolic link when type=link.
+.It Cm md5
+The MD5 message digest of the file.
+.It Cm md5digest
+A synonym for
+.Cm md5 .
+.It Cm mode
+The current file's permissions as a numeric (octal) or symbolic
+value.
+.It Cm nlink
+The number of hard links the file is expected to have.
+.It Cm nochange
+Make sure this file or directory exists but otherwise ignore all attributes.
+.It Cm optional
+The file is optional; do not complain about the file if it is not in
+the file hierarchy.
+.It Cm resdevice
+The
+.Dq resident
+device number of the file, e.g. the ID of the device that
+contains the file.
+Its format is the same as the one for
+.Cm device .
+.It Cm ripemd160digest
+The
+.Tn RIPEMD160
+message digest of the file.
+.It Cm rmd160
+A synonym for
+.Cm ripemd160digest .
+.It Cm rmd160digest
+A synonym for
+.Cm ripemd160digest .
+.It Cm sha1
+The
+.Tn FIPS
+160-1
+.Pq Dq Tn SHA-1
+message digest of the file.
+.It Cm sha1digest
+A synonym for
+.Cm sha1 .
+.It Cm sha256
+The
+.Tn FIPS
+180-2
+.Pq Dq Tn SHA-256
+message digest of the file.
+.It Cm sha256digest
+A synonym for
+.Cm sha256 .
+.It Cm sha384
+The
+.Tn FIPS
+180-2
+.Pq Dq Tn SHA-384
+message digest of the file.
+.It Cm sha384digest
+A synonym for
+.Cm sha384 .
+.It Cm sha512
+The
+.Tn FIPS
+180-2
+.Pq Dq Tn SHA-512
+message digest of the file.
+.It Cm sha512digest
+A synonym for
+.Cm sha512 .
+.It Cm size
+The size, in bytes, of the file.
+.It Cm time
+The last modification time of the file.
+.It Cm type
+The type of the file; may be set to any one of the following:
+.Pp
+.Bl -tag -width Cm -compact
+.It Cm block
+block special device
+.It Cm char
+character special device
+.It Cm dir
+directory
+.It Cm fifo
+fifo
+.It Cm file
+regular file
+.It Cm link
+symbolic link
+.It Cm socket
+socket
+.El
+.It Cm uid
+The file owner as a numeric value.
+.It Cm uname
+The file owner as a symbolic name.
+.El
+.Pp
+.Sh SEE ALSO
+.Xr cksum 1 ,
+.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
+utility appeared in
+.Bx 4.3 Reno .
+The
+.Tn MD5
+digest capability was added in
+.Fx 2.1 ,
+in response to the widespread use of programs which can spoof
+.Xr cksum 1 .
+The
+.Tn SHA-1
+and
+.Tn RIPEMD160
+digests were added in
+.Fx 4.0 ,
+as new attacks have demonstrated weaknesses in
+.Tn MD5 .
+The
+.Tn SHA-256
+digest was added in
+.Fx 6.0 .
+Support for file flags was added in
+.Fx 4.0 ,
+and mostly comes from
+.Nx .
+The
+.Dq full
+entry format was added by
+.Nx .
diff --git a/Utilities/cmlibarchive/libarchive/tar.5 b/Utilities/cmlibarchive/libarchive/tar.5
new file mode 100644
index 0000000000..688bb922c3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/tar.5
@@ -0,0 +1,947 @@
+.\" Copyright (c) 2003-2009 Tim Kientzle
+.\" 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 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd December 23, 2011
+.Dt TAR 5
+.Os
+.Sh NAME
+.Nm tar
+.Nd format of tape archive files
+.Sh DESCRIPTION
+The
+.Nm
+archive format collects any number of files, directories, and other
+file system objects (symbolic links, device nodes, etc.) into a single
+stream of bytes.
+The format was originally designed to be used with
+tape drives that operate with fixed-size blocks, but is widely used as
+a general packaging mechanism.
+.Ss General Format
+A
+.Nm
+archive consists of a series of 512-byte records.
+Each file system object requires a header record which stores basic metadata
+(pathname, owner, permissions, etc.) and zero or more records containing any
+file data.
+The end of the archive is indicated by two records consisting
+entirely of zero bytes.
+.Pp
+For compatibility with tape drives that use fixed block sizes,
+programs that read or write tar files always read or write a fixed
+number of records with each I/O operation.
+These
+.Dq blocks
+are always a multiple of the record size.
+The maximum block size supported by early
+implementations was 10240 bytes or 20 records.
+This is still the default for most implementations
+although block sizes of 1MiB (2048 records) or larger are
+commonly used with modern high-speed tape drives.
+(Note: the terms
+.Dq block
+and
+.Dq record
+here are not entirely standard; this document follows the
+convention established by John Gilmore in documenting
+.Nm pdtar . )
+.Ss Old-Style Archive Format
+The original tar archive format has been extended many times to
+include additional information that various implementors found
+necessary.
+This section describes the variant implemented by the tar command
+included in
+.At v7 ,
+which seems to be the earliest widely-used version of the tar program.
+.Pp
+The header record for an old-style
+.Nm
+archive consists of the following:
+.Bd -literal -offset indent
+struct header_old_tar {
+ char name[100];
+ char mode[8];
+ char uid[8];
+ char gid[8];
+ char size[12];
+ char mtime[12];
+ char checksum[8];
+ char linkflag[1];
+ char linkname[100];
+ char pad[255];
+};
+.Ed
+All unused bytes in the header record are filled with nulls.
+.Bl -tag -width indent
+.It Va name
+Pathname, stored as a null-terminated string.
+Early tar implementations only stored regular files (including
+hardlinks to those files).
+One common early convention used a trailing "/" character to indicate
+a directory name, allowing directory permissions and owner information
+to be archived and restored.
+.It Va mode
+File mode, stored as an octal number in ASCII.
+.It Va uid , Va gid
+User id and group id of owner, as octal numbers in ASCII.
+.It Va size
+Size of file, as octal number in ASCII.
+For regular files only, this indicates the amount of data
+that follows the header.
+In particular, this field was ignored by early tar implementations
+when extracting hardlinks.
+Modern writers should always store a zero length for hardlink entries.
+.It Va mtime
+Modification time of file, as an octal number in ASCII.
+This indicates the number of seconds since the start of the epoch,
+00:00:00 UTC January 1, 1970.
+Note that negative values should be avoided
+here, as they are handled inconsistently.
+.It Va checksum
+Header checksum, stored as an octal number in ASCII.
+To compute the checksum, set the checksum field to all spaces,
+then sum all bytes in the header using unsigned arithmetic.
+This field should be stored as six octal digits followed by a null and a space
+character.
+Note that many early implementations of tar used signed arithmetic
+for the checksum field, which can cause interoperability problems
+when transferring archives between systems.
+Modern robust readers compute the checksum both ways and accept the
+header if either computation matches.
+.It Va linkflag , Va linkname
+In order to preserve hardlinks and conserve tape, a file
+with multiple links is only written to the archive the first
+time it is encountered.
+The next time it is encountered, the
+.Va linkflag
+is set to an ASCII
+.Sq 1
+and the
+.Va linkname
+field holds the first name under which this file appears.
+(Note that regular files have a null value in the
+.Va linkflag
+field.)
+.El
+.Pp
+Early tar implementations varied in how they terminated these fields.
+The tar command in
+.At v7
+used the following conventions (this is also documented in early BSD manpages):
+the pathname must be null-terminated;
+the mode, uid, and gid fields must end in a space and a null byte;
+the size and mtime fields must end in a space;
+the checksum is terminated by a null and a space.
+Early implementations filled the numeric fields with leading spaces.
+This seems to have been common practice until the
+.St -p1003.1-88
+standard was released.
+For best portability, modern implementations should fill the numeric
+fields with leading zeros.
+.Ss Pre-POSIX Archives
+An early draft of
+.St -p1003.1-88
+served as the basis for John Gilmore's
+.Nm pdtar
+program and many system implementations from the late 1980s
+and early 1990s.
+These archives generally follow the POSIX ustar
+format described below with the following variations:
+.Bl -bullet -compact -width indent
+.It
+The magic value consists of the five characters
+.Dq ustar
+followed by a space.
+The version field contains a space character followed by a null.
+.It
+The numeric fields are generally filled with leading spaces
+(not leading zeros as recommended in the final standard).
+.It
+The prefix field is often not used, limiting pathnames to
+the 100 characters of old-style archives.
+.El
+.Ss POSIX ustar Archives
+.St -p1003.1-88
+defined a standard tar file format to be read and written
+by compliant implementations of
+.Xr tar 1 .
+This format is often called the
+.Dq ustar
+format, after the magic value used
+in the header.
+(The name is an acronym for
+.Dq Unix Standard TAR . )
+It extends the historic format with new fields:
+.Bd -literal -offset indent
+struct header_posix_ustar {
+ char name[100];
+ char mode[8];
+ char uid[8];
+ char gid[8];
+ char size[12];
+ char mtime[12];
+ char checksum[8];
+ char typeflag[1];
+ char linkname[100];
+ char magic[6];
+ char version[2];
+ char uname[32];
+ char gname[32];
+ char devmajor[8];
+ char devminor[8];
+ char prefix[155];
+ char pad[12];
+};
+.Ed
+.Bl -tag -width indent
+.It Va typeflag
+Type of entry.
+POSIX extended the earlier
+.Va linkflag
+field with several new type values:
+.Bl -tag -width indent -compact
+.It Dq 0
+Regular file.
+NUL should be treated as a synonym, for compatibility purposes.
+.It Dq 1
+Hard link.
+.It Dq 2
+Symbolic link.
+.It Dq 3
+Character device node.
+.It Dq 4
+Block device node.
+.It Dq 5
+Directory.
+.It Dq 6
+FIFO node.
+.It Dq 7
+Reserved.
+.It Other
+A POSIX-compliant implementation must treat any unrecognized typeflag value
+as a regular file.
+In particular, writers should ensure that all entries
+have a valid filename so that they can be restored by readers that do not
+support the corresponding extension.
+Uppercase letters "A" through "Z" are reserved for custom extensions.
+Note that sockets and whiteout entries are not archivable.
+.El
+It is worth noting that the
+.Va size
+field, in particular, has different meanings depending on the type.
+For regular files, of course, it indicates the amount of data
+following the header.
+For directories, it may be used to indicate the total size of all
+files in the directory, for use by operating systems that pre-allocate
+directory space.
+For all other types, it should be set to zero by writers and ignored
+by readers.
+.It Va magic
+Contains the magic value
+.Dq ustar
+followed by a NUL byte to indicate that this is a POSIX standard archive.
+Full compliance requires the uname and gname fields be properly set.
+.It Va version
+Version.
+This should be
+.Dq 00
+(two copies of the ASCII digit zero) for POSIX standard archives.
+.It Va uname , Va gname
+User and group names, as null-terminated ASCII strings.
+These should be used in preference to the uid/gid values
+when they are set and the corresponding names exist on
+the system.
+.It Va devmajor , Va devminor
+Major and minor numbers for character device or block device entry.
+.It Va name , Va prefix
+If the pathname is too long to fit in the 100 bytes provided by the standard
+format, it can be split at any
+.Pa /
+character with the first portion going into the prefix field.
+If the prefix field is not empty, the reader will prepend
+the prefix value and a
+.Pa /
+character to the regular name field to obtain the full pathname.
+The standard does not require a trailing
+.Pa /
+character on directory names, though most implementations still
+include this for compatibility reasons.
+.El
+.Pp
+Note that all unused bytes must be set to
+.Dv NUL .
+.Pp
+Field termination is specified slightly differently by POSIX
+than by previous implementations.
+The
+.Va magic ,
+.Va uname ,
+and
+.Va gname
+fields must have a trailing
+.Dv NUL .
+The
+.Va pathname ,
+.Va linkname ,
+and
+.Va prefix
+fields must have a trailing
+.Dv NUL
+unless they fill the entire field.
+(In particular, it is possible to store a 256-character pathname if it
+happens to have a
+.Pa /
+as the 156th character.)
+POSIX requires numeric fields to be zero-padded in the front, and requires
+them to be terminated with either space or
+.Dv NUL
+characters.
+.Pp
+Currently, most tar implementations comply with the ustar
+format, occasionally extending it by adding new fields to the
+blank area at the end of the header record.
+.Ss Numeric Extensions
+There have been several attempts to extend the range of sizes
+or times supported by modifying how numbers are stored in the
+header.
+.Pp
+One obvious extension to increase the size of files is to
+eliminate the terminating characters from the various
+numeric fields.
+For example, the standard only allows the size field to contain
+11 octal digits, reserving the twelfth byte for a trailing
+NUL character.
+Allowing 12 octal digits allows file sizes up to 64 GB.
+.Pp
+Another extension, utilized by GNU tar, star, and other newer
+.Nm
+implementations, permits binary numbers in the standard numeric fields.
+This is flagged by setting the high bit of the first byte.
+The remainder of the field is treated as a signed twos-complement
+value.
+This permits 95-bit values for the length and time fields
+and 63-bit values for the uid, gid, and device numbers.
+In particular, this provides a consistent way to handle
+negative time values.
+GNU tar supports this extension for the
+length, mtime, ctime, and atime fields.
+Joerg Schilling's star program and the libarchive library support
+this extension for all numeric fields.
+Note that this extension is largely obsoleted by the extended
+attribute record provided by the pax interchange format.
+.Pp
+Another early GNU extension allowed base-64 values rather than octal.
+This extension was short-lived and is no longer supported by any
+implementation.
+.Ss Pax Interchange Format
+There are many attributes that cannot be portably stored in a
+POSIX ustar archive.
+.St -p1003.1-2001
+defined a
+.Dq pax interchange format
+that uses two new types of entries to hold text-formatted
+metadata that applies to following entries.
+Note that a pax interchange format archive is a ustar archive in every
+respect.
+The new data is stored in ustar-compatible archive entries that use the
+.Dq x
+or
+.Dq g
+typeflag.
+In particular, older implementations that do not fully support these
+extensions will extract the metadata into regular files, where the
+metadata can be examined as necessary.
+.Pp
+An entry in a pax interchange format archive consists of one or
+two standard ustar entries, each with its own header and data.
+The first optional entry stores the extended attributes
+for the following entry.
+This optional first entry has an "x" typeflag and a size field that
+indicates the total size of the extended attributes.
+The extended attributes themselves are stored as a series of text-format
+lines encoded in the portable UTF-8 encoding.
+Each line consists of a decimal number, a space, a key string, an equals
+sign, a value string, and a new line.
+The decimal number indicates the length of the entire line, including the
+initial length field and the trailing newline.
+An example of such a field is:
+.Dl 25 ctime=1084839148.1212\en
+Keys in all lowercase are standard keys.
+Vendors can add their own keys by prefixing them with an all uppercase
+vendor name and a period.
+Note that, unlike the historic header, numeric values are stored using
+decimal, not octal.
+A description of some common keys follows:
+.Bl -tag -width indent
+.It Cm atime , Cm ctime , Cm mtime
+File access, inode change, and modification times.
+These fields can be negative or include a decimal point and a fractional value.
+.It Cm hdrcharset
+The character set used by the pax extension values.
+By default, all textual values in the pax extended attributes
+are assumed to be in UTF-8, including pathnames, user names,
+and group names.
+In some cases, it is not possible to translate local
+conventions into UTF-8.
+If this key is present and the value is the six-character ASCII string
+.Dq BINARY ,
+then all textual values are assumed to be in a platform-dependent
+multi-byte encoding.
+Note that there are only two valid values for this key:
+.Dq BINARY
+or
+.Dq ISO-IR\ 10646\ 2000\ UTF-8 .
+No other values are permitted by the standard, and
+the latter value should generally not be used as it is the
+default when this key is not specified.
+In particular, this flag should not be used as a general
+mechanism to allow filenames to be stored in arbitrary
+encodings.
+.It Cm uname , Cm uid , Cm gname , Cm gid
+User name, group name, and numeric UID and GID values.
+The user name and group name stored here are encoded in UTF8
+and can thus include non-ASCII characters.
+The UID and GID fields can be of arbitrary length.
+.It Cm linkpath
+The full path of the linked-to file.
+Note that this is encoded in UTF8 and can thus include non-ASCII characters.
+.It Cm path
+The full pathname of the entry.
+Note that this is encoded in UTF8 and can thus include non-ASCII characters.
+.It Cm realtime.* , Cm security.*
+These keys are reserved and may be used for future standardization.
+.It Cm size
+The size of the file.
+Note that there is no length limit on this field, allowing conforming
+archives to store files much larger than the historic 8GB limit.
+.It Cm SCHILY.*
+Vendor-specific attributes used by Joerg Schilling's
+.Nm star
+implementation.
+.It Cm SCHILY.acl.access , Cm SCHILY.acl.default
+Stores the access and default ACLs as textual strings in a format
+that is an extension of the format specified by POSIX.1e draft 17.
+In particular, each user or group access specification can include a fourth
+colon-separated field with the numeric UID or GID.
+This allows ACLs to be restored on systems that may not have complete
+user or group information available (such as when NIS/YP or LDAP services
+are temporarily unavailable).
+.It Cm SCHILY.devminor , Cm SCHILY.devmajor
+The full minor and major numbers for device nodes.
+.It Cm SCHILY.fflags
+The file flags.
+.It Cm SCHILY.realsize
+The full size of the file on disk.
+XXX explain? XXX
+.It Cm SCHILY.dev, Cm SCHILY.ino , Cm SCHILY.nlinks
+The device number, inode number, and link count for the entry.
+In particular, note that a pax interchange format archive using Joerg
+Schilling's
+.Cm SCHILY.*
+extensions can store all of the data from
+.Va struct stat .
+.It Cm LIBARCHIVE.*
+Vendor-specific attributes used by the
+.Nm libarchive
+library and programs that use it.
+.It Cm LIBARCHIVE.creationtime
+The time when the file was created.
+(This should not be confused with the POSIX
+.Dq ctime
+attribute, which refers to the time when the file
+metadata was last changed.)
+.It Cm LIBARCHIVE.xattr. Ns Ar namespace Ns . Ns Ar key
+Libarchive stores POSIX.1e-style extended attributes using
+keys of this form.
+The
+.Ar key
+value is URL-encoded:
+All non-ASCII characters and the two special characters
+.Dq =
+and
+.Dq %
+are encoded as
+.Dq %
+followed by two uppercase hexadecimal digits.
+The value of this key is the extended attribute value
+encoded in base 64.
+XXX Detail the base-64 format here XXX
+.It Cm VENDOR.*
+XXX document other vendor-specific extensions XXX
+.El
+.Pp
+Any values stored in an extended attribute override the corresponding
+values in the regular tar header.
+Note that compliant readers should ignore the regular fields when they
+are overridden.
+This is important, as existing archivers are known to store non-compliant
+values in the standard header fields in this situation.
+There are no limits on length for any of these fields.
+In particular, numeric fields can be arbitrarily large.
+All text fields are encoded in UTF8.
+Compliant writers should store only portable 7-bit ASCII characters in
+the standard ustar header and use extended
+attributes whenever a text value contains non-ASCII characters.
+.Pp
+In addition to the
+.Cm x
+entry described above, the pax interchange format
+also supports a
+.Cm g
+entry.
+The
+.Cm g
+entry is identical in format, but specifies attributes that serve as
+defaults for all subsequent archive entries.
+The
+.Cm g
+entry is not widely used.
+.Pp
+Besides the new
+.Cm x
+and
+.Cm g
+entries, the pax interchange format has a few other minor variations
+from the earlier ustar format.
+The most troubling one is that hardlinks are permitted to have
+data following them.
+This allows readers to restore any hardlink to a file without
+having to rewind the archive to find an earlier entry.
+However, it creates complications for robust readers, as it is no longer
+clear whether or not they should ignore the size field for hardlink entries.
+.Ss GNU Tar Archives
+The GNU tar program started with a pre-POSIX format similar to that
+described earlier and has extended it using several different mechanisms:
+It added new fields to the empty space in the header (some of which was later
+used by POSIX for conflicting purposes);
+it allowed the header to be continued over multiple records;
+and it defined new entries that modify following entries
+(similar in principle to the
+.Cm x
+entry described above, but each GNU special entry is single-purpose,
+unlike the general-purpose
+.Cm x
+entry).
+As a result, GNU tar archives are not POSIX compatible, although
+more lenient POSIX-compliant readers can successfully extract most
+GNU tar archives.
+.Bd -literal -offset indent
+struct header_gnu_tar {
+ char name[100];
+ char mode[8];
+ char uid[8];
+ char gid[8];
+ char size[12];
+ char mtime[12];
+ char checksum[8];
+ char typeflag[1];
+ char linkname[100];
+ char magic[6];
+ char version[2];
+ char uname[32];
+ char gname[32];
+ char devmajor[8];
+ char devminor[8];
+ char atime[12];
+ char ctime[12];
+ char offset[12];
+ char longnames[4];
+ char unused[1];
+ struct {
+ char offset[12];
+ char numbytes[12];
+ } sparse[4];
+ char isextended[1];
+ char realsize[12];
+ char pad[17];
+};
+.Ed
+.Bl -tag -width indent
+.It Va typeflag
+GNU tar uses the following special entry types, in addition to
+those defined by POSIX:
+.Bl -tag -width indent
+.It "7"
+GNU tar treats type "7" records identically to type "0" records,
+except on one obscure RTOS where they are used to indicate the
+pre-allocation of a contiguous file on disk.
+.It "D"
+This indicates a directory entry.
+Unlike the POSIX-standard "5"
+typeflag, the header is followed by data records listing the names
+of files in this directory.
+Each name is preceded by an ASCII "Y"
+if the file is stored in this archive or "N" if the file is not
+stored in this archive.
+Each name is terminated with a null, and
+an extra null marks the end of the name list.
+The purpose of this
+entry is to support incremental backups; a program restoring from
+such an archive may wish to delete files on disk that did not exist
+in the directory when the archive was made.
+.Pp
+Note that the "D" typeflag specifically violates POSIX, which requires
+that unrecognized typeflags be restored as normal files.
+In this case, restoring the "D" entry as a file could interfere
+with subsequent creation of the like-named directory.
+.It "K"
+The data for this entry is a long linkname for the following regular entry.
+.It "L"
+The data for this entry is a long pathname for the following regular entry.
+.It "M"
+This is a continuation of the last file on the previous volume.
+GNU multi-volume archives guarantee that each volume begins with a valid
+entry header.
+To ensure this, a file may be split, with part stored at the end of one volume,
+and part stored at the beginning of the next volume.
+The "M" typeflag indicates that this entry continues an existing file.
+Such entries can only occur as the first or second entry
+in an archive (the latter only if the first entry is a volume label).
+The
+.Va size
+field specifies the size of this entry.
+The
+.Va offset
+field at bytes 369-380 specifies the offset where this file fragment
+begins.
+The
+.Va realsize
+field specifies the total size of the file (which must equal
+.Va size
+plus
+.Va offset ) .
+When extracting, GNU tar checks that the header file name is the one it is
+expecting, that the header offset is in the correct sequence, and that
+the sum of offset and size is equal to realsize.
+.It "N"
+Type "N" records are no longer generated by GNU tar.
+They contained a
+list of files to be renamed or symlinked after extraction; this was
+originally used to support long names.
+The contents of this record
+are a text description of the operations to be done, in the form
+.Dq Rename %s to %s\en
+or
+.Dq Symlink %s to %s\en ;
+in either case, both
+filenames are escaped using K&R C syntax.
+Due to security concerns, "N" records are now generally ignored
+when reading archives.
+.It "S"
+This is a
+.Dq sparse
+regular file.
+Sparse files are stored as a series of fragments.
+The header contains a list of fragment offset/length pairs.
+If more than four such entries are required, the header is
+extended as necessary with
+.Dq extra
+header extensions (an older format that is no longer used), or
+.Dq sparse
+extensions.
+.It "V"
+The
+.Va name
+field should be interpreted as a tape/volume header name.
+This entry should generally be ignored on extraction.
+.El
+.It Va magic
+The magic field holds the five characters
+.Dq ustar
+followed by a space.
+Note that POSIX ustar archives have a trailing null.
+.It Va version
+The version field holds a space character followed by a null.
+Note that POSIX ustar archives use two copies of the ASCII digit
+.Dq 0 .
+.It Va atime , Va ctime
+The time the file was last accessed and the time of
+last change of file information, stored in octal as with
+.Va mtime .
+.It Va longnames
+This field is apparently no longer used.
+.It Sparse Va offset / Va numbytes
+Each such structure specifies a single fragment of a sparse
+file.
+The two fields store values as octal numbers.
+The fragments are each padded to a multiple of 512 bytes
+in the archive.
+On extraction, the list of fragments is collected from the
+header (including any extension headers), and the data
+is then read and written to the file at appropriate offsets.
+.It Va isextended
+If this is set to non-zero, the header will be followed by additional
+.Dq sparse header
+records.
+Each such record contains information about as many as 21 additional
+sparse blocks as shown here:
+.Bd -literal -offset indent
+struct gnu_sparse_header {
+ struct {
+ char offset[12];
+ char numbytes[12];
+ } sparse[21];
+ char isextended[1];
+ char padding[7];
+};
+.Ed
+.It Va realsize
+A binary representation of the file's complete size, with a much larger range
+than the POSIX file size.
+In particular, with
+.Cm M
+type files, the current entry is only a portion of the file.
+In that case, the POSIX size field will indicate the size of this
+entry; the
+.Va realsize
+field will indicate the total size of the file.
+.El
+.Ss GNU tar pax archives
+GNU tar 1.14 (XXX check this XXX) and later will write
+pax interchange format archives when you specify the
+.Fl -posix
+flag.
+This format follows the pax interchange format closely,
+using some
+.Cm SCHILY
+tags and introducing new keywords to store sparse file information.
+There have been three iterations of the sparse file support, referred to
+as
+.Dq 0.0 ,
+.Dq 0.1 ,
+and
+.Dq 1.0 .
+.Bl -tag -width indent
+.It Cm GNU.sparse.numblocks , Cm GNU.sparse.offset , Cm GNU.sparse.numbytes , Cm GNU.sparse.size
+The
+.Dq 0.0
+format used an initial
+.Cm GNU.sparse.numblocks
+attribute to indicate the number of blocks in the file, a pair of
+.Cm GNU.sparse.offset
+and
+.Cm GNU.sparse.numbytes
+to indicate the offset and size of each block,
+and a single
+.Cm GNU.sparse.size
+to indicate the full size of the file.
+This is not the same as the size in the tar header because the
+latter value does not include the size of any holes.
+This format required that the order of attributes be preserved and
+relied on readers accepting multiple appearances of the same attribute
+names, which is not officially permitted by the standards.
+.It Cm GNU.sparse.map
+The
+.Dq 0.1
+format used a single attribute that stored a comma-separated
+list of decimal numbers.
+Each pair of numbers indicated the offset and size, respectively,
+of a block of data.
+This does not work well if the archive is extracted by an archiver
+that does not recognize this extension, since many pax implementations
+simply discard unrecognized attributes.
+.It Cm GNU.sparse.major , Cm GNU.sparse.minor , Cm GNU.sparse.name , Cm GNU.sparse.realsize
+The
+.Dq 1.0
+format stores the sparse block map in one or more 512-byte blocks
+prepended to the file data in the entry body.
+The pax attributes indicate the existence of this map
+(via the
+.Cm GNU.sparse.major
+and
+.Cm GNU.sparse.minor
+fields)
+and the full size of the file.
+The
+.Cm GNU.sparse.name
+holds the true name of the file.
+To avoid confusion, the name stored in the regular tar header
+is a modified name so that extraction errors will be apparent
+to users.
+.El
+.Ss Solaris Tar
+XXX More Details Needed XXX
+.Pp
+Solaris tar (beginning with SunOS XXX 5.7 ?? XXX) supports an
+.Dq extended
+format that is fundamentally similar to pax interchange format,
+with the following differences:
+.Bl -bullet -compact -width indent
+.It
+Extended attributes are stored in an entry whose type is
+.Cm X ,
+not
+.Cm x ,
+as used by pax interchange format.
+The detailed format of this entry appears to be the same
+as detailed above for the
+.Cm x
+entry.
+.It
+An additional
+.Cm A
+header is used to store an ACL for the following regular entry.
+The body of this entry contains a seven-digit octal number
+followed by a zero byte, followed by the
+textual ACL description.
+The octal value is the number of ACL entries
+plus a constant that indicates the ACL type: 01000000
+for POSIX.1e ACLs and 03000000 for NFSv4 ACLs.
+.El
+.Ss AIX Tar
+XXX More details needed XXX
+.Pp
+AIX Tar uses a ustar-formatted header with the type
+.Cm A
+for storing coded ACL information.
+Unlike the Solaris format, AIX tar writes this header after the
+regular file body to which it applies.
+The pathname in this header is either
+.Cm NFS4
+or
+.Cm AIXC
+to indicate the type of ACL stored.
+The actual ACL is stored in platform-specific binary format.
+.Ss Mac OS X Tar
+The tar distributed with Apple's Mac OS X stores most regular files
+as two separate files in the tar archive.
+The two files have the same name except that the first
+one has
+.Dq ._
+prepended to the last path element.
+This special file stores an AppleDouble-encoded
+binary blob with additional metadata about the second file,
+including ACL, extended attributes, and resources.
+To recreate the original file on disk, each
+separate file can be extracted and the Mac OS X
+.Fn copyfile
+function can be used to unpack the separate
+metadata file and apply it to th regular file.
+Conversely, the same function provides a
+.Dq pack
+option to encode the extended metadata from
+a file into a separate file whose contents
+can then be put into a tar archive.
+.Pp
+Note that the Apple extended attributes interact
+badly with long filenames.
+Since each file is stored with the full name,
+a separate set of extensions needs to be included
+in the archive for each one, doubling the overhead
+required for files with long names.
+.Ss Summary of tar type codes
+The following list is a condensed summary of the type codes
+used in tar header records generated by different tar implementations.
+More details about specific implementations can be found above:
+.Bl -tag -compact -width XXX
+.It NUL
+Early tar programs stored a zero byte for regular files.
+.It Cm 0
+POSIX standard type code for a regular file.
+.It Cm 1
+POSIX standard type code for a hard link description.
+.It Cm 2
+POSIX standard type code for a symbolic link description.
+.It Cm 3
+POSIX standard type code for a character device node.
+.It Cm 4
+POSIX standard type code for a block device node.
+.It Cm 5
+POSIX standard type code for a directory.
+.It Cm 6
+POSIX standard type code for a FIFO.
+.It Cm 7
+POSIX reserved.
+.It Cm 7
+GNU tar used for pre-allocated files on some systems.
+.It Cm A
+Solaris tar ACL description stored prior to a regular file header.
+.It Cm A
+AIX tar ACL description stored after the file body.
+.It Cm D
+GNU tar directory dump.
+.It Cm K
+GNU tar long linkname for the following header.
+.It Cm L
+GNU tar long pathname for the following header.
+.It Cm M
+GNU tar multivolume marker, indicating the file is a continuation of a file from the previous volume.
+.It Cm N
+GNU tar long filename support. Deprecated.
+.It Cm S
+GNU tar sparse regular file.
+.It Cm V
+GNU tar tape/volume header name.
+.It Cm X
+Solaris tar general-purpose extension header.
+.It Cm g
+POSIX pax interchange format global extensions.
+.It Cm x
+POSIX pax interchange format per-file extensions.
+.El
+.Sh SEE ALSO
+.Xr ar 1 ,
+.Xr pax 1 ,
+.Xr tar 1
+.Sh STANDARDS
+The
+.Nm tar
+utility is no longer a part of POSIX or the Single Unix Standard.
+It last appeared in
+.St -susv2 .
+It has been supplanted in subsequent standards by
+.Xr pax 1 .
+The ustar format is currently part of the specification for the
+.Xr pax 1
+utility.
+The pax interchange file format is new with
+.St -p1003.1-2001 .
+.Sh HISTORY
+A
+.Nm tar
+command appeared in Seventh Edition Unix, which was released in January, 1979.
+It replaced the
+.Nm tp
+program from Fourth Edition Unix which in turn replaced the
+.Nm tap
+program from First Edition Unix.
+John Gilmore's
+.Nm pdtar
+public-domain implementation (circa 1987) was highly influential
+and formed the basis of
+.Nm GNU tar
+(circa 1988).
+Joerg Shilling's
+.Nm star
+archiver is another open-source (GPL) archiver (originally developed
+circa 1985) which features complete support for pax interchange
+format.
+.Pp
+This documentation was written as part of the
+.Nm libarchive
+and
+.Nm bsdtar
+project by
+.An Tim Kientzle Aq kientzle@FreeBSD.org .
diff --git a/Utilities/cmliblzma/.gitattributes b/Utilities/cmliblzma/.gitattributes
new file mode 100644
index 0000000000..562b12e16e
--- /dev/null
+++ b/Utilities/cmliblzma/.gitattributes
@@ -0,0 +1 @@
+* -whitespace
diff --git a/Utilities/cmliblzma/CMakeLists.txt b/Utilities/cmliblzma/CMakeLists.txt
new file mode 100644
index 0000000000..23549c586f
--- /dev/null
+++ b/Utilities/cmliblzma/CMakeLists.txt
@@ -0,0 +1,215 @@
+PROJECT(CMLIBLZMA C)
+
+include(CheckCSourceCompiles)
+include(CheckIncludeFile)
+include(CheckSymbolExists)
+include(CheckTypeSize)
+include(TestBigEndian)
+
+CHECK_C_SOURCE_COMPILES(
+ "int test (void *restrict x);\nint main (void) {return 0;}"
+ HAVE_RESTRICT)
+
+CHECK_C_SOURCE_COMPILES(
+"typedef struct abc *d;\nint test (d __restrict x);\nint main (void) {return 0;}"
+ HAVE___RESTRICT)
+
+CHECK_C_SOURCE_COMPILES(
+ "inline int test (void) {return 0;}\nint main (void) {return test();}"
+ HAVE_INLINE)
+
+CHECK_C_SOURCE_COMPILES (
+ "__inline int test (void) {return 0;}\nint main (void) {return test();}"
+ HAVE___INLINE)
+
+CHECK_INCLUDE_FILE(byteswap.h HAVE_BYTESWAP_H)
+CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
+CHECK_INCLUDE_FILE(limits.h HAVE_LIMITS_H)
+CHECK_INCLUDE_FILE(memory.h HAVE_MEMORY_H)
+CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
+CHECK_INCLUDE_FILE(string.h HAVE_STRING_H)
+CHECK_INCLUDE_FILE(sys/sysctl.h HAVE_SYS_SYSCTL_H)
+
+CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
+if(NOT HAVE_STDBOOL_H)
+ CHECK_TYPE_SIZE(_Bool _BOOL)
+endif()
+
+CHECK_C_SOURCE_COMPILES (
+ "#include<byteswap.h>\nint main(void){bswap_16(0);return 0;}"
+ HAVE_BSWAP_16)
+CHECK_C_SOURCE_COMPILES (
+ "#include<byteswap.h>\nint main(void){bswap_32(0);return 0;}"
+ HAVE_BSWAP_32)
+CHECK_C_SOURCE_COMPILES (
+ "#include<byteswap.h>\nint main(void){bswap_64(0);return 0;}"
+ HAVE_BSWAP_64)
+
+TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
+
+set(HAVE_CHECK_CRC64 1)
+set(HAVE_CHECK_SHA256 1)
+
+set(HAVE_DECODER_ARM 1)
+set(HAVE_DECODER_ARMTHUMB 1)
+set(HAVE_DECODER_DELTA 1)
+set(HAVE_DECODER_IA64 1)
+set(HAVE_DECODER_LZMA1 1)
+set(HAVE_DECODER_LZMA2 1)
+set(HAVE_DECODER_POWERPC 1)
+set(HAVE_DECODER_SPARC 1)
+set(HAVE_DECODER_X86 1)
+
+set(HAVE_ENCODER_ARM 1)
+set(HAVE_ENCODER_ARMTHUMB 1)
+set(HAVE_ENCODER_DELTA 1)
+set(HAVE_ENCODER_IA64 1)
+set(HAVE_ENCODER_LZMA1 1)
+set(HAVE_ENCODER_LZMA2 1)
+set(HAVE_ENCODER_POWERPC 1)
+set(HAVE_ENCODER_SPARC 1)
+set(HAVE_ENCODER_X86 1)
+
+set(HAVE_MF_BT2 1)
+set(HAVE_MF_BT3 1)
+set(HAVE_MF_BT4 1)
+set(HAVE_MF_HC3 1)
+set(HAVE_MF_HC4 1)
+
+CHECK_TYPE_SIZE(int16_t INT16_T)
+CHECK_TYPE_SIZE(int32_t INT32_T)
+CHECK_TYPE_SIZE(int64_t INT64_T)
+CHECK_TYPE_SIZE(intmax_t INTMAX_T)
+CHECK_TYPE_SIZE(uint8_t UINT8_T)
+CHECK_TYPE_SIZE(uint16_t UINT16_T)
+CHECK_TYPE_SIZE(uint32_t UINT32_T)
+CHECK_TYPE_SIZE(uint64_t UINT64_T)
+CHECK_TYPE_SIZE(uintmax_t UINTMAX_T)
+
+CHECK_TYPE_SIZE("short" SIZE_OF_SHORT)
+CHECK_TYPE_SIZE("int" SIZE_OF_INT)
+CHECK_TYPE_SIZE("long" SIZE_OF_LONG)
+CHECK_TYPE_SIZE("long long" SIZE_OF_LONG_LONG)
+
+CHECK_TYPE_SIZE("unsigned short" SIZE_OF_UNSIGNED_SHORT)
+CHECK_TYPE_SIZE("unsigned" SIZE_OF_UNSIGNED)
+CHECK_TYPE_SIZE("unsigned long" SIZE_OF_UNSIGNED_LONG)
+CHECK_TYPE_SIZE("unsigned long long" SIZE_OF_UNSIGNED_LONG_LONG)
+
+CHECK_TYPE_SIZE("__int64" __INT64)
+CHECK_TYPE_SIZE("unsigned __int64" UNSIGNED___INT64)
+
+CHECK_TYPE_SIZE(uintptr_t UINTPTR_T)
+IF(NOT HAVE_UINTPTR_T)
+ IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ SET(uintptr_t "uint64_t")
+ ELSE()
+ SET(uintptr_t "uint32_t")
+ ENDIF()
+ENDIF()
+
+
+SET(LZMA_SRCS
+ common/sysdefs.h
+ common/tuklib_integer.h
+ liblzma/check/check.c
+ liblzma/check/crc32_fast.c
+ liblzma/check/crc32_table.c
+ liblzma/check/crc64_fast.c
+ liblzma/check/crc64_table.c
+ liblzma/check/sha256.c
+ liblzma/common/alone_decoder.c
+ liblzma/common/alone_encoder.c
+ liblzma/common/auto_decoder.c
+ liblzma/common/block_buffer_decoder.c
+ liblzma/common/block_buffer_encoder.c
+ liblzma/common/block_decoder.c
+ liblzma/common/block_encoder.c
+ liblzma/common/block_header_decoder.c
+ liblzma/common/block_header_encoder.c
+ liblzma/common/block_util.c
+ liblzma/common/common.c
+ liblzma/common/easy_buffer_encoder.c
+ liblzma/common/easy_decoder_memusage.c
+ liblzma/common/easy_encoder.c
+ liblzma/common/easy_encoder_memusage.c
+ liblzma/common/easy_preset.c
+ liblzma/common/filter_buffer_decoder.c
+ liblzma/common/filter_buffer_encoder.c
+ liblzma/common/filter_common.c
+ liblzma/common/filter_decoder.c
+ liblzma/common/filter_encoder.c
+ liblzma/common/filter_flags_decoder.c
+ liblzma/common/filter_flags_encoder.c
+ liblzma/common/index.c
+ liblzma/common/index_decoder.c
+ liblzma/common/index_encoder.c
+ liblzma/common/index_hash.c
+ liblzma/common/stream_buffer_decoder.c
+ liblzma/common/stream_buffer_encoder.c
+ liblzma/common/stream_decoder.c
+ liblzma/common/stream_encoder.c
+ liblzma/common/stream_flags_common.c
+ liblzma/common/stream_flags_decoder.c
+ liblzma/common/stream_flags_encoder.c
+ liblzma/common/vli_decoder.c
+ liblzma/common/vli_encoder.c
+ liblzma/common/vli_size.c
+ liblzma/delta/delta_common.c
+ liblzma/delta/delta_decoder.c
+ liblzma/delta/delta_encoder.c
+ liblzma/lz/lz_decoder.c
+ liblzma/lz/lz_encoder.c
+ liblzma/lz/lz_encoder_mf.c
+ liblzma/lzma/fastpos_table.c
+ liblzma/lzma/lzma2_decoder.c
+ liblzma/lzma/lzma2_encoder.c
+ liblzma/lzma/lzma_decoder.c
+ liblzma/lzma/lzma_encoder.c
+ liblzma/lzma/lzma_encoder_optimum_fast.c
+ liblzma/lzma/lzma_encoder_optimum_normal.c
+ liblzma/lzma/lzma_encoder_presets.c
+ liblzma/rangecoder/price_table.c
+ liblzma/simple/arm.c
+ liblzma/simple/armthumb.c
+ liblzma/simple/ia64.c
+ liblzma/simple/powerpc.c
+ liblzma/simple/simple_coder.c
+ liblzma/simple/simple_decoder.c
+ liblzma/simple/simple_encoder.c
+ liblzma/simple/sparc.c
+ liblzma/simple/x86.c
+ )
+
+IF(WIN32 AND BUILD_SHARED_LIBS)
+ SET(LZMA_SRCS ${LZMA_SRCS} liblzma/liblzma_w32res.rc)
+ENDIF()
+
+CONFIGURE_FILE(config.h.in config.h @ONLY)
+
+INCLUDE_DIRECTORIES(
+ "${CMLIBLZMA_SOURCE_DIR}/common"
+ "${CMLIBLZMA_SOURCE_DIR}/liblzma/api"
+ "${CMLIBLZMA_SOURCE_DIR}/liblzma/check"
+ "${CMLIBLZMA_SOURCE_DIR}/liblzma/common"
+ "${CMLIBLZMA_SOURCE_DIR}/liblzma/delta"
+ "${CMLIBLZMA_SOURCE_DIR}/liblzma/lz"
+ "${CMLIBLZMA_SOURCE_DIR}/liblzma/lzma"
+ "${CMLIBLZMA_SOURCE_DIR}/liblzma/rangecoder"
+ "${CMLIBLZMA_SOURCE_DIR}/liblzma/simple"
+ "${CMLIBLZMA_BINARY_DIR}"
+ )
+
+# Disable warnings to avoid changing 3rd party code.
+IF("${CMAKE_C_COMPILER_ID}" MATCHES
+ "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
+ELSEIF("${CMAKE_C_COMPILER_ID}" MATCHES "^(PathScale)$")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
+ELSEIF(BORLAND)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
+ENDIF()
+
+ADD_LIBRARY(cmliblzma ${LZMA_SRCS})
+
+INSTALL(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmliblzma)
diff --git a/Utilities/cmliblzma/COPYING b/Utilities/cmliblzma/COPYING
new file mode 100644
index 0000000000..43c90d0598
--- /dev/null
+++ b/Utilities/cmliblzma/COPYING
@@ -0,0 +1,65 @@
+
+XZ Utils Licensing
+==================
+
+ Different licenses apply to different files in this package. Here
+ is a rough summary of which licenses apply to which parts of this
+ package (but check the individual files to be sure!):
+
+ - liblzma is in the public domain.
+
+ - xz, xzdec, and lzmadec command line tools are in the public
+ domain unless GNU getopt_long had to be compiled and linked
+ in from the lib directory. The getopt_long code is under
+ GNU LGPLv2.1+.
+
+ - The scripts to grep, diff, and view compressed files have been
+ adapted from gzip. These scripts and their documentation are
+ under GNU GPLv2+.
+
+ - All the documentation in the doc directory and most of the
+ XZ Utils specific documentation files in other directories
+ are in the public domain.
+
+ - Translated messages are in the public domain.
+
+ - The build system contains public domain files, and files that
+ are under GNU GPLv2+ or GNU GPLv3+. None of these files end up
+ in the binaries being built.
+
+ - Test files and test code in the tests directory, and debugging
+ utilities in the debug directory are in the public domain.
+
+ - The extra directory may contain public domain files, and files
+ that are under various free software licenses.
+
+ You can do whatever you want with the files that have been put into
+ the public domain. If you find public domain legally problematic,
+ take the previous sentence as a license grant. If you still find
+ the lack of copyright legally problematic, you have too many
+ lawyers.
+
+ As usual, this software is provided "as is", without any warranty.
+
+ If you copy significant amounts of public domain code from XZ Utils
+ into your project, acknowledging this somewhere in your software is
+ polite (especially if it is proprietary, non-free software), but
+ naturally it is not legally required. Here is an example of a good
+ notice to put into "about box" or into documentation:
+
+ This software includes code from XZ Utils <http://tukaani.org/xz/>.
+
+ The following license texts are included in the following files:
+ - COPYING.LGPLv2.1: GNU Lesser General Public License version 2.1
+ - COPYING.GPLv2: GNU General Public License version 2
+ - COPYING.GPLv3: GNU General Public License version 3
+
+ Note that the toolchain (compiler, linker etc.) may add some code
+ pieces that are copyrighted. Thus, it is possible that e.g. liblzma
+ binary wouldn't actually be in the public domain in its entirety
+ even though it contains no copyrighted code from the XZ Utils source
+ package.
+
+ If you have questions, don't hesitate to ask the author(s) for more
+ information.
+
diff --git a/Utilities/cmliblzma/README-CMake.txt b/Utilities/cmliblzma/README-CMake.txt
new file mode 100644
index 0000000000..b512997074
--- /dev/null
+++ b/Utilities/cmliblzma/README-CMake.txt
@@ -0,0 +1,66 @@
+The Utilities/cmliblzma directory contains a reduced distribution
+of the liblzma source tree with only the library source code and
+CMake build system. It is not a submodule; the actual content is part
+of our source tree and changes can be made and committed directly.
+
+We update from upstream using Git's "subtree" merge strategy. A
+special branch contains commits of upstream liblzma snapshots and
+nothing else. No Git ref points explicitly to the head of this
+branch, but it is merged into our history.
+
+Update liblzma from upstream as follows. Create a local branch to
+explicitly reference the upstream snapshot branch head:
+
+ git branch liblzma-upstream c289e634
+
+Use a temporary directory to checkout the branch:
+
+ mkdir liblzma-tmp
+ cd liblzma-tmp
+ git init
+ git pull .. liblzma-upstream
+ rm -rf *
+
+Now place the (reduced) liblzma content in this directory. See
+instructions shown by
+
+ git log c289e634
+
+for help extracting the content from the upstream svn repo. Then run
+the following commands to commit the new version. Substitute the
+appropriate date and version number:
+
+ git add --all
+
+ GIT_AUTHOR_NAME='liblzma upstream' \
+ GIT_AUTHOR_EMAIL='xz-devel@tukaani.org' \
+ GIT_AUTHOR_DATE='Sun Jun 30 19:55:49 2013 +0300' \
+ git commit -m 'liblzma 5.0.5-gb69900ed (reduced)' &&
+ git commit --amend
+
+Edit the commit message to describe the procedure used to obtain the
+content. Then push the changes back up to the main local repository:
+
+ git push .. HEAD:liblzma-upstream
+ cd ..
+ rm -rf liblzma-tmp
+
+Create a topic in the main repository on which to perform the update:
+
+ git checkout -b update-liblzma master
+
+Merge the liblzma-upstream branch as a subtree:
+
+ git merge -s recursive -X subtree=Utilities/cmliblzma \
+ liblzma-upstream
+
+If there are conflicts, resolve them and commit. Build and test the
+tree. Commit any additional changes needed to succeed.
+
+Finally, run
+
+ git rev-parse --short=8 liblzma-upstream
+
+to get the commit from which the liblzma-upstream branch must be started
+on the next update. Edit the "git branch liblzma-upstream" line above to
+record it, and commit this file.
diff --git a/Utilities/cmliblzma/common/common_w32res.rc b/Utilities/cmliblzma/common/common_w32res.rc
new file mode 100644
index 0000000000..fdb88d184a
--- /dev/null
+++ b/Utilities/cmliblzma/common/common_w32res.rc
@@ -0,0 +1,50 @@
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include <winresrc.h>
+#include "config.h"
+#define LZMA_H_INTERNAL
+#define LZMA_H_INTERNAL_RC
+#include "lzma/version.h"
+
+#ifndef MY_BUILD
+# define MY_BUILD 0
+#endif
+#define MY_VERSION LZMA_VERSION_MAJOR,LZMA_VERSION_MINOR,LZMA_VERSION_PATCH,MY_BUILD
+
+#define MY_FILENAME MY_NAME MY_SUFFIX
+#define MY_COMPANY "The Tukaani Project <http://tukaani.org/>"
+#define MY_PRODUCT PACKAGE_NAME " <" PACKAGE_URL ">"
+
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION MY_VERSION
+ PRODUCTVERSION MY_VERSION
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+ FILEFLAGS 0
+ FILEOS VOS_NT_WINDOWS32
+ FILETYPE MY_TYPE
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", MY_COMPANY
+ VALUE "FileDescription", MY_DESC
+ VALUE "FileVersion", LZMA_VERSION_STRING
+ VALUE "InternalName", MY_NAME
+ VALUE "OriginalFilename", MY_FILENAME
+ VALUE "ProductName", MY_PRODUCT
+ VALUE "ProductVersion", LZMA_VERSION_STRING
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
diff --git a/Utilities/cmliblzma/common/sysdefs.h b/Utilities/cmliblzma/common/sysdefs.h
new file mode 100644
index 0000000000..c84f01c227
--- /dev/null
+++ b/Utilities/cmliblzma/common/sysdefs.h
@@ -0,0 +1,202 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file sysdefs.h
+/// \brief Common includes, definitions, system-specific things etc.
+///
+/// This file is used also by the lzma command line tool, that's why this
+/// file is separate from common.h.
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_SYSDEFS_H
+#define LZMA_SYSDEFS_H
+
+#if defined(_MSC_VER)
+# pragma warning(push,1)
+# pragma warning(disable: 4142) /* benign redefinition of type */
+# pragma warning(disable: 4761) /* integral size mismatch in argument */
+#endif
+
+//////////////
+// Includes //
+//////////////
+
+#include "config.h"
+
+// Get standard-compliant stdio functions under MinGW and MinGW-w64.
+#ifdef __MINGW32__
+# define __USE_MINGW_ANSI_STDIO 1
+#endif
+
+// size_t and NULL
+#include <stddef.h>
+
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+
+// C99 says that inttypes.h always includes stdint.h, but some systems
+// don't do that, and require including stdint.h separately.
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
+// Some pre-C99 systems have SIZE_MAX in limits.h instead of stdint.h. The
+// limits are also used to figure out some macros missing from pre-C99 systems.
+#ifdef HAVE_LIMITS_H
+# include <limits.h>
+#endif
+
+
+#if defined(_MSC_VER) && (_MSC_VER < 1310)
+# define UINT64_C(n) n ## ui64
+#endif
+
+
+// Be more compatible with systems that have non-conforming inttypes.h.
+// We assume that int is 32-bit and that long is either 32-bit or 64-bit.
+// Full Autoconf test could be more correct, but this should work well enough.
+// Note that this duplicates some code from lzma.h, but this is better since
+// we can work without inttypes.h thanks to Autoconf tests.
+#ifndef UINT32_C
+# if UINT_MAX != 4294967295U
+# error UINT32_C is not defined and unsigned int is not 32-bit.
+# endif
+# define UINT32_C(n) n ## U
+#endif
+#ifndef UINT32_MAX
+# define UINT32_MAX UINT32_C(4294967295)
+#endif
+#ifndef PRIu32
+# define PRIu32 "u"
+#endif
+#ifndef PRIx32
+# define PRIx32 "x"
+#endif
+#ifndef PRIX32
+# define PRIX32 "X"
+#endif
+
+#if ULONG_MAX == 4294967295UL
+# ifndef UINT64_C
+# define UINT64_C(n) n ## ULL
+# endif
+# ifndef PRIu64
+# define PRIu64 "llu"
+# endif
+# ifndef PRIx64
+# define PRIx64 "llx"
+# endif
+# ifndef PRIX64
+# define PRIX64 "llX"
+# endif
+#else
+# ifndef UINT64_C
+# define UINT64_C(n) n ## UL
+# endif
+# ifndef PRIu64
+# define PRIu64 "lu"
+# endif
+# ifndef PRIx64
+# define PRIx64 "lx"
+# endif
+# ifndef PRIX64
+# define PRIX64 "lX"
+# endif
+#endif
+#ifndef UINT64_MAX
+# define UINT64_MAX UINT64_C(18446744073709551615)
+#endif
+
+// Incorrect(?) SIZE_MAX:
+// - Interix headers typedef size_t to unsigned long,
+// but a few lines later define SIZE_MAX to INT32_MAX.
+// - SCO OpenServer (x86) headers typedef size_t to unsigned int
+// but define SIZE_MAX to INT32_MAX.
+#if defined(__INTERIX) || defined(_SCO_DS)
+# undef SIZE_MAX
+#endif
+
+// The code currently assumes that size_t is either 32-bit or 64-bit.
+#ifndef SIZE_MAX
+# if SIZEOF_SIZE_T == 4
+# define SIZE_MAX UINT32_MAX
+# elif SIZEOF_SIZE_T == 8
+# define SIZE_MAX UINT64_MAX
+# else
+# error size_t is not 32-bit or 64-bit
+# endif
+#endif
+#if SIZE_MAX != UINT32_MAX && SIZE_MAX != UINT64_MAX
+# error size_t is not 32-bit or 64-bit
+#endif
+
+#include <stdlib.h>
+#include <assert.h>
+
+// Pre-C99 systems lack stdbool.h. All the code in LZMA Utils must be written
+// so that it works with fake bool type, for example:
+//
+// bool foo = (flags & 0x100) != 0;
+// bool bar = !!(flags & 0x100);
+//
+// This works with the real C99 bool but breaks with fake bool:
+//
+// bool baz = (flags & 0x100);
+//
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+# if ! HAVE__BOOL
+typedef unsigned char _Bool;
+# endif
+# define bool _Bool
+# define false 0
+# define true 1
+# define __bool_true_false_are_defined 1
+#endif
+
+// string.h should be enough but let's include strings.h and memory.h too if
+// they exists, since that shouldn't do any harm, but may improve portability.
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#ifdef HAVE_MEMORY_H
+# include <memory.h>
+#endif
+
+
+////////////
+// Macros //
+////////////
+
+#undef memzero
+#define memzero(s, n) memset(s, 0, n)
+
+// NOTE: Avoid using MIN() and MAX(), because even conditionally defining
+// those macros can cause some portability trouble, since on some systems
+// the system headers insist defining their own versions.
+#define my_min(x, y) ((x) < (y) ? (x) : (y))
+#define my_max(x, y) ((x) > (y) ? (x) : (y))
+
+#ifndef ARRAY_SIZE
+# define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+#endif
+
+#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
+# define lzma_attr_alloc_size(x) __attribute__((__alloc_size__(x)))
+#else
+# define lzma_attr_alloc_size(x)
+#endif
+
+#endif
diff --git a/Utilities/cmliblzma/common/tuklib_integer.h b/Utilities/cmliblzma/common/tuklib_integer.h
new file mode 100644
index 0000000000..5e8262a114
--- /dev/null
+++ b/Utilities/cmliblzma/common/tuklib_integer.h
@@ -0,0 +1,514 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file tuklib_integer.h
+/// \brief Various integer and bit operations
+///
+/// This file provides macros or functions to do some basic integer and bit
+/// operations.
+///
+/// Endianness related integer operations (XX = 16, 32, or 64; Y = b or l):
+/// - Byte swapping: bswapXX(num)
+/// - Byte order conversions to/from native: convXXYe(num)
+/// - Aligned reads: readXXYe(ptr)
+/// - Aligned writes: writeXXYe(ptr, num)
+/// - Unaligned reads (16/32-bit only): unaligned_readXXYe(ptr)
+/// - Unaligned writes (16/32-bit only): unaligned_writeXXYe(ptr, num)
+///
+/// Since they can macros, the arguments should have no side effects since
+/// they may be evaluated more than once.
+///
+/// \todo PowerPC and possibly some other architectures support
+/// byte swapping load and store instructions. This file
+/// doesn't take advantage of those instructions.
+///
+/// Bit scan operations for non-zero 32-bit integers:
+/// - Bit scan reverse (find highest non-zero bit): bsr32(num)
+/// - Count leading zeros: clz32(num)
+/// - Count trailing zeros: ctz32(num)
+/// - Bit scan forward (simply an alias for ctz32()): bsf32(num)
+///
+/// The above bit scan operations return 0-31. If num is zero,
+/// the result is undefined.
+//
+// Authors: Lasse Collin
+// Joachim Henke
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef TUKLIB_INTEGER_H
+#define TUKLIB_INTEGER_H
+
+#include "sysdefs.h"
+
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)
+# define TUKLIB_GNUC_REQ(major, minor) \
+ ((__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)) \
+ || __GNUC__ > (major))
+#else
+# define TUKLIB_GNUC_REQ(major, minor) 0
+#endif
+
+
+////////////////////////////////////////
+// Operating system specific features //
+////////////////////////////////////////
+
+#if defined(HAVE_BYTESWAP_H)
+ // glibc, uClibc, dietlibc
+# include <byteswap.h>
+# ifdef HAVE_BSWAP_16
+# define bswap16(num) bswap_16(num)
+# endif
+# ifdef HAVE_BSWAP_32
+# define bswap32(num) bswap_32(num)
+# endif
+# ifdef HAVE_BSWAP_64
+# define bswap64(num) bswap_64(num)
+# endif
+
+#elif defined(HAVE_SYS_ENDIAN_H)
+ // *BSDs and Darwin
+# include <sys/endian.h>
+
+#elif defined(HAVE_SYS_BYTEORDER_H)
+ // Solaris
+# include <sys/byteorder.h>
+# ifdef BSWAP_16
+# define bswap16(num) BSWAP_16(num)
+# endif
+# ifdef BSWAP_32
+# define bswap32(num) BSWAP_32(num)
+# endif
+# ifdef BSWAP_64
+# define bswap64(num) BSWAP_64(num)
+# endif
+# ifdef BE_16
+# define conv16be(num) BE_16(num)
+# endif
+# ifdef BE_32
+# define conv32be(num) BE_32(num)
+# endif
+# ifdef BE_64
+# define conv64be(num) BE_64(num)
+# endif
+# ifdef LE_16
+# define conv16le(num) LE_16(num)
+# endif
+# ifdef LE_32
+# define conv32le(num) LE_32(num)
+# endif
+# ifdef LE_64
+# define conv64le(num) LE_64(num)
+# endif
+#endif
+
+
+///////////////////
+// Byte swapping //
+///////////////////
+
+#ifndef bswap16
+# define bswap16(num) \
+ (((uint16_t)(num) << 8) | ((uint16_t)(num) >> 8))
+#endif
+
+#ifndef bswap32
+# define bswap32(num) \
+ ( (((uint32_t)(num) << 24) ) \
+ | (((uint32_t)(num) << 8) & UINT32_C(0x00FF0000)) \
+ | (((uint32_t)(num) >> 8) & UINT32_C(0x0000FF00)) \
+ | (((uint32_t)(num) >> 24) ) )
+#endif
+
+#ifndef bswap64
+# define bswap64(num) \
+ ( (((uint64_t)(num) << 56) ) \
+ | (((uint64_t)(num) << 40) & UINT64_C(0x00FF000000000000)) \
+ | (((uint64_t)(num) << 24) & UINT64_C(0x0000FF0000000000)) \
+ | (((uint64_t)(num) << 8) & UINT64_C(0x000000FF00000000)) \
+ | (((uint64_t)(num) >> 8) & UINT64_C(0x00000000FF000000)) \
+ | (((uint64_t)(num) >> 24) & UINT64_C(0x0000000000FF0000)) \
+ | (((uint64_t)(num) >> 40) & UINT64_C(0x000000000000FF00)) \
+ | (((uint64_t)(num) >> 56) ) )
+#endif
+
+// Define conversion macros using the basic byte swapping macros.
+#ifdef WORDS_BIGENDIAN
+# ifndef conv16be
+# define conv16be(num) ((uint16_t)(num))
+# endif
+# ifndef conv32be
+# define conv32be(num) ((uint32_t)(num))
+# endif
+# ifndef conv64be
+# define conv64be(num) ((uint64_t)(num))
+# endif
+# ifndef conv16le
+# define conv16le(num) bswap16(num)
+# endif
+# ifndef conv32le
+# define conv32le(num) bswap32(num)
+# endif
+# ifndef conv64le
+# define conv64le(num) bswap64(num)
+# endif
+#else
+# ifndef conv16be
+# define conv16be(num) bswap16(num)
+# endif
+# ifndef conv32be
+# define conv32be(num) bswap32(num)
+# endif
+# ifndef conv64be
+# define conv64be(num) bswap64(num)
+# endif
+# ifndef conv16le
+# define conv16le(num) ((uint16_t)(num))
+# endif
+# ifndef conv32le
+# define conv32le(num) ((uint32_t)(num))
+# endif
+# ifndef conv64le
+# define conv64le(num) ((uint64_t)(num))
+# endif
+#endif
+
+
+//////////////////////////////
+// Aligned reads and writes //
+//////////////////////////////
+
+static inline uint16_t
+read16be(const uint8_t *buf)
+{
+ uint16_t num = *(const uint16_t *)buf;
+ return conv16be(num);
+}
+
+
+static inline uint16_t
+read16le(const uint8_t *buf)
+{
+ uint16_t num = *(const uint16_t *)buf;
+ return conv16le(num);
+}
+
+
+static inline uint32_t
+read32be(const uint8_t *buf)
+{
+ uint32_t num = *(const uint32_t *)buf;
+ return conv32be(num);
+}
+
+
+static inline uint32_t
+read32le(const uint8_t *buf)
+{
+ uint32_t num = *(const uint32_t *)buf;
+ return conv32le(num);
+}
+
+
+static inline uint64_t
+read64be(const uint8_t *buf)
+{
+ uint64_t num = *(const uint64_t *)buf;
+ return conv64be(num);
+}
+
+
+static inline uint64_t
+read64le(const uint8_t *buf)
+{
+ uint64_t num = *(const uint64_t *)buf;
+ return conv64le(num);
+}
+
+
+// NOTE: Possible byte swapping must be done in a macro to allow GCC
+// to optimize byte swapping of constants when using glibc's or *BSD's
+// byte swapping macros. The actual write is done in an inline function
+// to make type checking of the buf pointer possible similarly to readXXYe()
+// functions.
+
+#define write16be(buf, num) write16ne((buf), conv16be(num))
+#define write16le(buf, num) write16ne((buf), conv16le(num))
+#define write32be(buf, num) write32ne((buf), conv32be(num))
+#define write32le(buf, num) write32ne((buf), conv32le(num))
+#define write64be(buf, num) write64ne((buf), conv64be(num))
+#define write64le(buf, num) write64ne((buf), conv64le(num))
+
+
+static inline void
+write16ne(uint8_t *buf, uint16_t num)
+{
+ *(uint16_t *)buf = num;
+ return;
+}
+
+
+static inline void
+write32ne(uint8_t *buf, uint32_t num)
+{
+ *(uint32_t *)buf = num;
+ return;
+}
+
+
+static inline void
+write64ne(uint8_t *buf, uint64_t num)
+{
+ *(uint64_t *)buf = num;
+ return;
+}
+
+
+////////////////////////////////
+// Unaligned reads and writes //
+////////////////////////////////
+
+// NOTE: TUKLIB_FAST_UNALIGNED_ACCESS indicates only support for 16-bit and
+// 32-bit unaligned integer loads and stores. It's possible that 64-bit
+// unaligned access doesn't work or is slower than byte-by-byte access.
+// Since unaligned 64-bit is probably not needed as often as 16-bit or
+// 32-bit, we simply don't support 64-bit unaligned access for now.
+#ifdef TUKLIB_FAST_UNALIGNED_ACCESS
+# define unaligned_read16be read16be
+# define unaligned_read16le read16le
+# define unaligned_read32be read32be
+# define unaligned_read32le read32le
+# define unaligned_write16be write16be
+# define unaligned_write16le write16le
+# define unaligned_write32be write32be
+# define unaligned_write32le write32le
+
+#else
+
+static inline uint16_t
+unaligned_read16be(const uint8_t *buf)
+{
+ uint16_t num = ((uint16_t)buf[0] << 8) | (uint16_t)buf[1];
+ return num;
+}
+
+
+static inline uint16_t
+unaligned_read16le(const uint8_t *buf)
+{
+ uint16_t num = ((uint16_t)buf[0]) | ((uint16_t)buf[1] << 8);
+ return num;
+}
+
+
+static inline uint32_t
+unaligned_read32be(const uint8_t *buf)
+{
+ uint32_t num = (uint32_t)buf[0] << 24;
+ num |= (uint32_t)buf[1] << 16;
+ num |= (uint32_t)buf[2] << 8;
+ num |= (uint32_t)buf[3];
+ return num;
+}
+
+
+static inline uint32_t
+unaligned_read32le(const uint8_t *buf)
+{
+ uint32_t num = (uint32_t)buf[0];
+ num |= (uint32_t)buf[1] << 8;
+ num |= (uint32_t)buf[2] << 16;
+ num |= (uint32_t)buf[3] << 24;
+ return num;
+}
+
+
+static inline void
+unaligned_write16be(uint8_t *buf, uint16_t num)
+{
+ buf[0] = num >> 8;
+ buf[1] = num;
+ return;
+}
+
+
+static inline void
+unaligned_write16le(uint8_t *buf, uint16_t num)
+{
+ buf[0] = num;
+ buf[1] = num >> 8;
+ return;
+}
+
+
+static inline void
+unaligned_write32be(uint8_t *buf, uint32_t num)
+{
+ buf[0] = num >> 24;
+ buf[1] = num >> 16;
+ buf[2] = num >> 8;
+ buf[3] = num;
+ return;
+}
+
+
+static inline void
+unaligned_write32le(uint8_t *buf, uint32_t num)
+{
+ buf[0] = num;
+ buf[1] = num >> 8;
+ buf[2] = num >> 16;
+ buf[3] = num >> 24;
+ return;
+}
+
+#endif
+
+
+static inline uint32_t
+bsr32(uint32_t n)
+{
+ // Check for ICC first, since it tends to define __GNUC__ too.
+#if defined(__INTEL_COMPILER)
+ return _bit_scan_reverse(n);
+
+#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX
+ // GCC >= 3.4 has __builtin_clz(), which gives good results on
+ // multiple architectures. On x86, __builtin_clz() ^ 31U becomes
+ // either plain BSR (so the XOR gets optimized away) or LZCNT and
+ // XOR (if -march indicates that SSE4a instructions are supported).
+ return __builtin_clz(n) ^ 31U;
+
+#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+ uint32_t i;
+ __asm__("bsrl %1, %0" : "=r" (i) : "rm" (n));
+ return i;
+
+#else
+ uint32_t i = 31;
+
+ if ((n & UINT32_C(0xFFFF0000)) == 0) {
+ n <<= 16;
+ i = 15;
+ }
+
+ if ((n & UINT32_C(0xFF000000)) == 0) {
+ n <<= 8;
+ i -= 8;
+ }
+
+ if ((n & UINT32_C(0xF0000000)) == 0) {
+ n <<= 4;
+ i -= 4;
+ }
+
+ if ((n & UINT32_C(0xC0000000)) == 0) {
+ n <<= 2;
+ i -= 2;
+ }
+
+ if ((n & UINT32_C(0x80000000)) == 0)
+ --i;
+
+ return i;
+#endif
+}
+
+
+static inline uint32_t
+clz32(uint32_t n)
+{
+#if defined(__INTEL_COMPILER)
+ return _bit_scan_reverse(n) ^ 31U;
+
+#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX
+ return __builtin_clz(n);
+
+#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+ uint32_t i;
+ __asm__("bsrl %1, %0\n\t"
+ "xorl $31, %0"
+ : "=r" (i) : "rm" (n));
+ return i;
+
+#else
+ uint32_t i = 0;
+
+ if ((n & UINT32_C(0xFFFF0000)) == 0) {
+ n <<= 16;
+ i = 16;
+ }
+
+ if ((n & UINT32_C(0xFF000000)) == 0) {
+ n <<= 8;
+ i += 8;
+ }
+
+ if ((n & UINT32_C(0xF0000000)) == 0) {
+ n <<= 4;
+ i += 4;
+ }
+
+ if ((n & UINT32_C(0xC0000000)) == 0) {
+ n <<= 2;
+ i += 2;
+ }
+
+ if ((n & UINT32_C(0x80000000)) == 0)
+ ++i;
+
+ return i;
+#endif
+}
+
+
+static inline uint32_t
+ctz32(uint32_t n)
+{
+#if defined(__INTEL_COMPILER)
+ return _bit_scan_forward(n);
+
+#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX >= UINT32_MAX
+ return __builtin_ctz(n);
+
+#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+ uint32_t i;
+ __asm__("bsfl %1, %0" : "=r" (i) : "rm" (n));
+ return i;
+
+#else
+ uint32_t i = 0;
+
+ if ((n & UINT32_C(0x0000FFFF)) == 0) {
+ n >>= 16;
+ i = 16;
+ }
+
+ if ((n & UINT32_C(0x000000FF)) == 0) {
+ n >>= 8;
+ i += 8;
+ }
+
+ if ((n & UINT32_C(0x0000000F)) == 0) {
+ n >>= 4;
+ i += 4;
+ }
+
+ if ((n & UINT32_C(0x00000003)) == 0) {
+ n >>= 2;
+ i += 2;
+ }
+
+ if ((n & UINT32_C(0x00000001)) == 0)
+ ++i;
+
+ return i;
+#endif
+}
+
+#define bsf32 ctz32
+
+#endif
diff --git a/Utilities/cmliblzma/config.h.in b/Utilities/cmliblzma/config.h.in
new file mode 100644
index 0000000000..b197f2786a
--- /dev/null
+++ b/Utilities/cmliblzma/config.h.in
@@ -0,0 +1,285 @@
+
+/*
+ * Ensure we have C99-style int64_t, etc, all defined.
+ */
+
+/* First, we need to know if the system has already defined them. */
+#cmakedefine HAVE_INT16_T
+#cmakedefine HAVE_INT32_T
+#cmakedefine HAVE_INT64_T
+#cmakedefine HAVE_INTMAX_T
+
+#cmakedefine HAVE_UINT8_T
+#cmakedefine HAVE_UINT16_T
+#cmakedefine HAVE_UINT32_T
+#cmakedefine HAVE_UINT64_T
+#cmakedefine HAVE_UINTMAX_T
+
+/* We might have the types we want under other spellings. */
+#cmakedefine HAVE___INT64
+#cmakedefine HAVE_U_INT64_T
+#cmakedefine HAVE_UNSIGNED___INT64
+
+/* The sizes of various standard integer types. */
+@SIZE_OF_SHORT_CODE@
+@SIZE_OF_INT_CODE@
+@SIZE_OF_LONG_CODE@
+@SIZE_OF_LONG_LONG_CODE@
+@SIZE_OF_UNSIGNED_SHORT_CODE@
+@SIZE_OF_UNSIGNED_CODE@
+@SIZE_OF_UNSIGNED_LONG_CODE@
+@SIZE_OF_UNSIGNED_LONG_LONG_CODE@
+
+/*
+ * If we lack int64_t, define it to the first of __int64, int, long, and long long
+ * that exists and is the right size.
+ */
+#if !defined(HAVE_INT64_T) && defined(HAVE___INT64)
+typedef __int64 int64_t;
+#define HAVE_INT64_T
+#endif
+
+#if !defined(HAVE_INT64_T) && SIZE_OF_INT == 8
+typedef int int64_t;
+#define HAVE_INT64_T
+#endif
+
+#if !defined(HAVE_INT64_T) && SIZE_OF_LONG == 8
+typedef long int64_t;
+#define HAVE_INT64_T
+#endif
+
+#if !defined(HAVE_INT64_T) && SIZE_OF_LONG_LONG == 8
+typedef long long int64_t;
+#define HAVE_INT64_T
+#endif
+
+#if !defined(HAVE_INT64_T)
+#error No 64-bit integer type was found.
+#endif
+
+/*
+ * Similarly for int32_t
+ */
+#if !defined(HAVE_INT32_T) && SIZE_OF_INT == 4
+typedef int int32_t;
+#define HAVE_INT32_T
+#endif
+
+#if !defined(HAVE_INT32_T) && SIZE_OF_LONG == 4
+typedef long int32_t;
+#define HAVE_INT32_T
+#endif
+
+#if !defined(HAVE_INT32_T)
+#error No 32-bit integer type was found.
+#endif
+
+/*
+ * Similarly for int16_t
+ */
+#if !defined(HAVE_INT16_T) && SIZE_OF_INT == 2
+typedef int int16_t;
+#define HAVE_INT16_T
+#endif
+
+#if !defined(HAVE_INT16_T) && SIZE_OF_SHORT == 2
+typedef short int16_t;
+#define HAVE_INT16_T
+#endif
+
+#if !defined(HAVE_INT16_T)
+#error No 16-bit integer type was found.
+#endif
+
+/*
+ * Similarly for uint64_t
+ */
+#if !defined(HAVE_UINT64_T) && defined(HAVE_UNSIGNED___INT64)
+typedef unsigned __int64 uint64_t;
+#define HAVE_UINT64_T
+#endif
+
+#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED == 8
+typedef unsigned uint64_t;
+#define HAVE_UINT64_T
+#endif
+
+#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG == 8
+typedef unsigned long uint64_t;
+#define HAVE_UINT64_T
+#endif
+
+#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG_LONG == 8
+typedef unsigned long long uint64_t;
+#define HAVE_UINT64_T
+#endif
+
+#if !defined(HAVE_UINT64_T)
+#error No 64-bit unsigned integer type was found.
+#endif
+
+/*
+ * Similarly for uint32_t
+ */
+#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED == 4
+typedef unsigned uint32_t;
+#define HAVE_UINT32_T
+#endif
+
+#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED_LONG == 4
+typedef unsigned long uint32_t;
+#define HAVE_UINT32_T
+#endif
+
+#if !defined(HAVE_UINT32_T)
+#error No 32-bit unsigned integer type was found.
+#endif
+
+/*
+ * Similarly for uint16_t
+ */
+#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED == 2
+typedef unsigned uint16_t;
+#define HAVE_UINT16_T
+#endif
+
+#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED_SHORT == 2
+typedef unsigned short uint16_t;
+#define HAVE_UINT16_T
+#endif
+
+#if !defined(HAVE_UINT16_T)
+#error No 16-bit unsigned integer type was found.
+#endif
+
+/*
+ * Similarly for uint8_t
+ */
+#if !defined(HAVE_UINT8_T)
+typedef unsigned char uint8_t;
+#define HAVE_UINT8_T
+#endif
+
+#if !defined(HAVE_UINT16_T)
+#error No 8-bit unsigned integer type was found.
+#endif
+
+/* Define intmax_t and uintmax_t if they are not already defined. */
+#if !defined(HAVE_INTMAX_T)
+typedef int64_t intmax_t;
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#endif
+
+#if !defined(HAVE_UINTMAX_T)
+typedef uint64_t uintmax_t;
+#endif
+
+
+#cmakedefine uintptr_t @uintptr_t@
+
+
+#cmakedefine HAVE_RESTRICT
+#cmakedefine HAVE___RESTRICT
+
+#cmakedefine HAVE_INLINE
+#cmakedefine HAVE___INLINE
+
+#ifndef HAVE_RESTRICT
+# ifdef HAVE___RESTRICT
+# define LZMA_RESTRICT __restrict
+# else
+# define LZMA_RESTRICT
+# endif
+#else
+# define LZMA_RESTRICT restrict
+#endif /* HAVE_RESTRICT */
+
+#ifndef HAVE_INLINE
+# ifdef HAVE___INLINE
+# define inline __inline
+# else
+# define inline
+# endif
+#endif /* HAVE_INLINE */
+
+
+#cmakedefine WORDS_BIGENDIAN 1
+
+#cmakedefine HAVE_BYTESWAP_H 1
+#cmakedefine HAVE_BSWAP_16 1
+#cmakedefine HAVE_BSWAP_32 1
+#cmakedefine HAVE_BSWAP_64 1
+
+
+#define HAVE_CHECK_CRC32 1
+#define HAVE_CHECK_CRC64 1
+#define HAVE_CHECK_SHA256 1
+
+#define HAVE_DECODER_ARM 1
+#define HAVE_DECODER_ARMTHUMB 1
+#define HAVE_DECODER_DELTA 1
+#define HAVE_DECODER_IA64 1
+#define HAVE_DECODER_LZMA1 1
+#define HAVE_DECODER_LZMA2 1
+#define HAVE_DECODER_POWERPC 1
+#define HAVE_DECODER_SPARC 1
+#define HAVE_DECODER_X86 1
+
+#define HAVE_ENCODER_ARM 1
+#define HAVE_ENCODER_ARMTHUMB 1
+#define HAVE_ENCODER_DELTA 1
+#define HAVE_ENCODER_IA64 1
+#define HAVE_ENCODER_LZMA1 1
+#define HAVE_ENCODER_LZMA2 1
+#define HAVE_ENCODER_POWERPC 1
+#define HAVE_ENCODER_SPARC 1
+#define HAVE_ENCODER_X86 1
+
+#define HAVE_MF_BT2 1
+#define HAVE_MF_BT3 1
+#define HAVE_MF_BT4 1
+#define HAVE_MF_HC3 1
+#define HAVE_MF_HC4 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#cmakedefine HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <limits.h> header file. */
+#cmakedefine HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#cmakedefine HAVE_MEMORY_H 1
+
+/* Define to 1 if stdbool.h conforms to C99. */
+#cmakedefine HAVE_STDBOOL_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#cmakedefine HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#cmakedefine HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#cmakedefine HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/byteorder.h> header file. */
+#cmakedefine HAVE_SYS_BYTEORDER_H 1
+
+/* Define to 1 if you have the <sys/endian.h> header file. */
+#cmakedefine HAVE_SYS_ENDIAN_H 1
+
+/* Define to 1 or 0, depending whether the compiler supports simple visibility
+ declarations. */
+#cmakedefine HAVE_VISIBILITY 1
+
+/* Define to 1 if the system has the type `_Bool'. */
+#cmakedefine HAVE__BOOL 1
+
+/* The size of `size_t', as computed by sizeof. */
+#cmakedefine SIZEOF_SIZE_T @SIZEOF_SIZE_T@
+
+/* Define to 1 if the system supports fast unaligned access to 16-bit and
+ 32-bit integers. */
+#define TUKLIB_FAST_UNALIGNED_ACCESS 1
diff --git a/Utilities/cmliblzma/liblzma/api/lzma.h b/Utilities/cmliblzma/liblzma/api/lzma.h
new file mode 100644
index 0000000000..fb874c3e13
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma.h
@@ -0,0 +1,313 @@
+/**
+ * \file api/lzma.h
+ * \brief The public API of liblzma data compression library
+ *
+ * liblzma is a public domain general-purpose data compression library with
+ * a zlib-like API. The native file format is .xz, but also the old .lzma
+ * format and raw (no headers) streams are supported. Multiple compression
+ * algorithms (filters) are supported. Currently LZMA2 is the primary filter.
+ *
+ * liblzma is part of XZ Utils <http://tukaani.org/xz/>. XZ Utils includes
+ * a gzip-like command line tool named xz and some other tools. XZ Utils
+ * is developed and maintained by Lasse Collin.
+ *
+ * Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK
+ * <http://7-zip.org/sdk.html>.
+ *
+ * The SHA-256 implementation is based on the public domain code found from
+ * 7-Zip <http://7-zip.org/>, which has a modified version of the public
+ * domain SHA-256 code found from Crypto++ <http://www.cryptopp.com/>.
+ * The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai.
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#ifndef LZMA_H
+#define LZMA_H
+
+/*****************************
+ * Required standard headers *
+ *****************************/
+
+/*
+ * liblzma API headers need some standard types and macros. To allow
+ * including lzma.h without requiring the application to include other
+ * headers first, lzma.h includes the required standard headers unless
+ * they already seem to be included already or if LZMA_MANUAL_HEADERS
+ * has been defined.
+ *
+ * Here's what types and macros are needed and from which headers:
+ * - stddef.h: size_t, NULL
+ * - stdint.h: uint8_t, uint32_t, uint64_t, UINT32_C(n), uint64_C(n),
+ * UINT32_MAX, UINT64_MAX
+ *
+ * However, inttypes.h is a little more portable than stdint.h, although
+ * inttypes.h declares some unneeded things compared to plain stdint.h.
+ *
+ * The hacks below aren't perfect, specifically they assume that inttypes.h
+ * exists and that it typedefs at least uint8_t, uint32_t, and uint64_t,
+ * and that, in case of incomplete inttypes.h, unsigned int is 32-bit.
+ * If the application already takes care of setting up all the types and
+ * macros properly (for example by using gnulib's stdint.h or inttypes.h),
+ * we try to detect that the macros are already defined and don't include
+ * inttypes.h here again. However, you may define LZMA_MANUAL_HEADERS to
+ * force this file to never include any system headers.
+ *
+ * Some could argue that liblzma API should provide all the required types,
+ * for example lzma_uint64, LZMA_UINT64_C(n), and LZMA_UINT64_MAX. This was
+ * seen as an unnecessary mess, since most systems already provide all the
+ * necessary types and macros in the standard headers.
+ *
+ * Note that liblzma API still has lzma_bool, because using stdbool.h would
+ * break C89 and C++ programs on many systems. sizeof(bool) in C99 isn't
+ * necessarily the same as sizeof(bool) in C++.
+ */
+
+#ifndef LZMA_MANUAL_HEADERS
+ /*
+ * I suppose this works portably also in C++. Note that in C++,
+ * we need to get size_t into the global namespace.
+ */
+# include <stddef.h>
+
+ /*
+ * Skip inttypes.h if we already have all the required macros. If we
+ * have the macros, we assume that we have the matching typedefs too.
+ */
+# if !defined(UINT32_C) || !defined(UINT64_C) \
+ || !defined(UINT32_MAX) || !defined(UINT64_MAX)
+ /*
+ * MSVC has no C99 support, and thus it cannot be used to
+ * compile liblzma. The liblzma API has to still be usable
+ * from MSVC, so we need to define the required standard
+ * integer types here.
+ */
+# if defined(_WIN32) && defined(_MSC_VER)
+ typedef unsigned __int8 uint8_t;
+ typedef unsigned __int32 uint32_t;
+ typedef unsigned __int64 uint64_t;
+# else
+ /* Use the standard inttypes.h. */
+# ifdef __cplusplus
+ /*
+ * C99 sections 7.18.2 and 7.18.4 specify
+ * that C++ implementations define the limit
+ * and constant macros only if specifically
+ * requested. Note that if you want the
+ * format macros (PRIu64 etc.) too, you need
+ * to define __STDC_FORMAT_MACROS before
+ * including lzma.h, since re-including
+ * inttypes.h with __STDC_FORMAT_MACROS
+ * defined doesn't necessarily work.
+ */
+# ifndef __STDC_LIMIT_MACROS
+# define __STDC_LIMIT_MACROS 1
+# endif
+# ifndef __STDC_CONSTANT_MACROS
+# define __STDC_CONSTANT_MACROS 1
+# endif
+# endif
+
+# include <inttypes.h>
+# endif
+
+ /*
+ * Some old systems have only the typedefs in inttypes.h, and
+ * lack all the macros. For those systems, we need a few more
+ * hacks. We assume that unsigned int is 32-bit and unsigned
+ * long is either 32-bit or 64-bit. If these hacks aren't
+ * enough, the application has to setup the types manually
+ * before including lzma.h.
+ */
+# ifndef UINT32_C
+# if defined(_WIN32) && defined(_MSC_VER)
+# define UINT32_C(n) n ## UI32
+# else
+# define UINT32_C(n) n ## U
+# endif
+# endif
+
+# ifndef UINT64_C
+# if defined(_WIN32) && defined(_MSC_VER)
+# define UINT64_C(n) n ## UI64
+# else
+ /* Get ULONG_MAX. */
+# include <limits.h>
+# if ULONG_MAX == 4294967295UL
+# define UINT64_C(n) n ## ULL
+# else
+# define UINT64_C(n) n ## UL
+# endif
+# endif
+# endif
+
+# ifndef UINT32_MAX
+# define UINT32_MAX (UINT32_C(4294967295))
+# endif
+
+# ifndef UINT64_MAX
+# define UINT64_MAX (UINT64_C(18446744073709551615))
+# endif
+# endif
+#endif /* ifdef LZMA_MANUAL_HEADERS */
+
+
+/******************
+ * LZMA_API macro *
+ ******************/
+
+/*
+ * Some systems require that the functions and function pointers are
+ * declared specially in the headers. LZMA_API_IMPORT is for importing
+ * symbols and LZMA_API_CALL is to specify the calling convention.
+ *
+ * By default it is assumed that the application will link dynamically
+ * against liblzma. #define LZMA_API_STATIC in your application if you
+ * want to link against static liblzma. If you don't care about portability
+ * to operating systems like Windows, or at least don't care about linking
+ * against static liblzma on them, don't worry about LZMA_API_STATIC. That
+ * is, most developers will never need to use LZMA_API_STATIC.
+ *
+ * The GCC variants are a special case on Windows (Cygwin and MinGW).
+ * We rely on GCC doing the right thing with its auto-import feature,
+ * and thus don't use __declspec(dllimport). This way developers don't
+ * need to worry about LZMA_API_STATIC. Also the calling convention is
+ * omitted on Cygwin but not on MinGW.
+ */
+#ifndef LZMA_API_IMPORT
+# if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__)
+# define LZMA_API_IMPORT __declspec(dllimport)
+# else
+# define LZMA_API_IMPORT
+# endif
+#endif
+
+#ifndef LZMA_API_CALL
+# if defined(_WIN32) && !defined(__CYGWIN__)
+# define LZMA_API_CALL __cdecl
+# else
+# define LZMA_API_CALL
+# endif
+#endif
+
+#ifndef LZMA_API
+# define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL
+#endif
+
+
+/***********
+ * nothrow *
+ ***********/
+
+/*
+ * None of the functions in liblzma may throw an exception. Even
+ * the functions that use callback functions won't throw exceptions,
+ * because liblzma would break if a callback function threw an exception.
+ */
+#ifndef lzma_nothrow
+# if defined(__cplusplus)
+# define lzma_nothrow throw()
+# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+# define lzma_nothrow __attribute__((__nothrow__))
+# else
+# define lzma_nothrow
+# endif
+#endif
+
+
+/********************
+ * GNU C extensions *
+ ********************/
+
+/*
+ * GNU C extensions are used conditionally in the public API. It doesn't
+ * break anything if these are sometimes enabled and sometimes not, only
+ * affects warnings and optimizations.
+ */
+#if __GNUC__ >= 3
+# ifndef lzma_attribute
+# define lzma_attribute(attr) __attribute__(attr)
+# endif
+
+ /* warn_unused_result was added in GCC 3.4. */
+# ifndef lzma_attr_warn_unused_result
+# if __GNUC__ == 3 && __GNUC_MINOR__ < 4
+# define lzma_attr_warn_unused_result
+# endif
+# endif
+
+#else
+# ifndef lzma_attribute
+# define lzma_attribute(attr)
+# endif
+#endif
+
+
+#ifndef lzma_attr_pure
+# define lzma_attr_pure lzma_attribute((__pure__))
+#endif
+
+#ifndef lzma_attr_const
+# define lzma_attr_const lzma_attribute((__const__))
+#endif
+
+#ifndef lzma_attr_warn_unused_result
+# define lzma_attr_warn_unused_result \
+ lzma_attribute((__warn_unused_result__))
+#endif
+
+
+/**************
+ * Subheaders *
+ **************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Subheaders check that this is defined. It is to prevent including
+ * them directly from applications.
+ */
+#define LZMA_H_INTERNAL 1
+
+/* Basic features */
+#include "lzma/version.h"
+#include "lzma/base.h"
+#include "lzma/vli.h"
+#include "lzma/check.h"
+
+/* Filters */
+#include "lzma/filter.h"
+#include "lzma/bcj.h"
+#include "lzma/delta.h"
+#include "lzma/lzma.h"
+
+/* Container formats */
+#include "lzma/container.h"
+
+/* Advanced features */
+#include "lzma/stream_flags.h"
+#include "lzma/block.h"
+#include "lzma/index.h"
+#include "lzma/index_hash.h"
+
+/* Hardware information */
+#include "lzma/hardware.h"
+
+/*
+ * All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications
+ * re-including the subheaders.
+ */
+#undef LZMA_H_INTERNAL
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ifndef LZMA_H */
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/base.h b/Utilities/cmliblzma/liblzma/api/lzma/base.h
new file mode 100644
index 0000000000..43dde8d60f
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/base.h
@@ -0,0 +1,601 @@
+/**
+ * \file lzma/base.h
+ * \brief Data types and functions used in many places in liblzma API
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Boolean
+ *
+ * This is here because C89 doesn't have stdbool.h. To set a value for
+ * variables having type lzma_bool, you can use
+ * - C99's `true' and `false' from stdbool.h;
+ * - C++'s internal `true' and `false'; or
+ * - integers one (true) and zero (false).
+ */
+typedef unsigned char lzma_bool;
+
+
+/**
+ * \brief Type of reserved enumeration variable in structures
+ *
+ * To avoid breaking library ABI when new features are added, several
+ * structures contain extra variables that may be used in future. Since
+ * sizeof(enum) can be different than sizeof(int), and sizeof(enum) may
+ * even vary depending on the range of enumeration constants, we specify
+ * a separate type to be used for reserved enumeration variables. All
+ * enumeration constants in liblzma API will be non-negative and less
+ * than 128, which should guarantee that the ABI won't break even when
+ * new constants are added to existing enumerations.
+ */
+typedef enum {
+ LZMA_RESERVED_ENUM = 0
+} lzma_reserved_enum;
+
+
+/**
+ * \brief Return values used by several functions in liblzma
+ *
+ * Check the descriptions of specific functions to find out which return
+ * values they can return. With some functions the return values may have
+ * more specific meanings than described here; those differences are
+ * described per-function basis.
+ */
+typedef enum {
+ LZMA_OK = 0,
+ /**<
+ * \brief Operation completed successfully
+ */
+
+ LZMA_STREAM_END = 1,
+ /**<
+ * \brief End of stream was reached
+ *
+ * In encoder, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or
+ * LZMA_FINISH was finished. In decoder, this indicates
+ * that all the data was successfully decoded.
+ *
+ * In all cases, when LZMA_STREAM_END is returned, the last
+ * output bytes should be picked from strm->next_out.
+ */
+
+ LZMA_NO_CHECK = 2,
+ /**<
+ * \brief Input stream has no integrity check
+ *
+ * This return value can be returned only if the
+ * LZMA_TELL_NO_CHECK flag was used when initializing
+ * the decoder. LZMA_NO_CHECK is just a warning, and
+ * the decoding can be continued normally.
+ *
+ * It is possible to call lzma_get_check() immediately after
+ * lzma_code has returned LZMA_NO_CHECK. The result will
+ * naturally be LZMA_CHECK_NONE, but the possibility to call
+ * lzma_get_check() may be convenient in some applications.
+ */
+
+ LZMA_UNSUPPORTED_CHECK = 3,
+ /**<
+ * \brief Cannot calculate the integrity check
+ *
+ * The usage of this return value is different in encoders
+ * and decoders.
+ *
+ * Encoders can return this value only from the initialization
+ * function. If initialization fails with this value, the
+ * encoding cannot be done, because there's no way to produce
+ * output with the correct integrity check.
+ *
+ * Decoders can return this value only from lzma_code() and
+ * only if the LZMA_TELL_UNSUPPORTED_CHECK flag was used when
+ * initializing the decoder. The decoding can still be
+ * continued normally even if the check type is unsupported,
+ * but naturally the check will not be validated, and possible
+ * errors may go undetected.
+ *
+ * With decoder, it is possible to call lzma_get_check()
+ * immediately after lzma_code() has returned
+ * LZMA_UNSUPPORTED_CHECK. This way it is possible to find
+ * out what the unsupported Check ID was.
+ */
+
+ LZMA_GET_CHECK = 4,
+ /**<
+ * \brief Integrity check type is now available
+ *
+ * This value can be returned only by the lzma_code() function
+ * and only if the decoder was initialized with the
+ * LZMA_TELL_ANY_CHECK flag. LZMA_GET_CHECK tells the
+ * application that it may now call lzma_get_check() to find
+ * out the Check ID. This can be used, for example, to
+ * implement a decoder that accepts only files that have
+ * strong enough integrity check.
+ */
+
+ LZMA_MEM_ERROR = 5,
+ /**<
+ * \brief Cannot allocate memory
+ *
+ * Memory allocation failed, or the size of the allocation
+ * would be greater than SIZE_MAX.
+ *
+ * Due to internal implementation reasons, the coding cannot
+ * be continued even if more memory were made available after
+ * LZMA_MEM_ERROR.
+ */
+
+ LZMA_MEMLIMIT_ERROR = 6,
+ /**
+ * \brief Memory usage limit was reached
+ *
+ * Decoder would need more memory than allowed by the
+ * specified memory usage limit. To continue decoding,
+ * the memory usage limit has to be increased with
+ * lzma_memlimit_set().
+ */
+
+ LZMA_FORMAT_ERROR = 7,
+ /**<
+ * \brief File format not recognized
+ *
+ * The decoder did not recognize the input as supported file
+ * format. This error can occur, for example, when trying to
+ * decode .lzma format file with lzma_stream_decoder,
+ * because lzma_stream_decoder accepts only the .xz format.
+ */
+
+ LZMA_OPTIONS_ERROR = 8,
+ /**<
+ * \brief Invalid or unsupported options
+ *
+ * Invalid or unsupported options, for example
+ * - unsupported filter(s) or filter options; or
+ * - reserved bits set in headers (decoder only).
+ *
+ * Rebuilding liblzma with more features enabled, or
+ * upgrading to a newer version of liblzma may help.
+ */
+
+ LZMA_DATA_ERROR = 9,
+ /**<
+ * \brief Data is corrupt
+ *
+ * The usage of this return value is different in encoders
+ * and decoders. In both encoder and decoder, the coding
+ * cannot continue after this error.
+ *
+ * Encoders return this if size limits of the target file
+ * format would be exceeded. These limits are huge, thus
+ * getting this error from an encoder is mostly theoretical.
+ * For example, the maximum compressed and uncompressed
+ * size of a .xz Stream is roughly 8 EiB (2^63 bytes).
+ *
+ * Decoders return this error if the input data is corrupt.
+ * This can mean, for example, invalid CRC32 in headers
+ * or invalid check of uncompressed data.
+ */
+
+ LZMA_BUF_ERROR = 10,
+ /**<
+ * \brief No progress is possible
+ *
+ * This error code is returned when the coder cannot consume
+ * any new input and produce any new output. The most common
+ * reason for this error is that the input stream being
+ * decoded is truncated or corrupt.
+ *
+ * This error is not fatal. Coding can be continued normally
+ * by providing more input and/or more output space, if
+ * possible.
+ *
+ * Typically the first call to lzma_code() that can do no
+ * progress returns LZMA_OK instead of LZMA_BUF_ERROR. Only
+ * the second consecutive call doing no progress will return
+ * LZMA_BUF_ERROR. This is intentional.
+ *
+ * With zlib, Z_BUF_ERROR may be returned even if the
+ * application is doing nothing wrong, so apps will need
+ * to handle Z_BUF_ERROR specially. The above hack
+ * guarantees that liblzma never returns LZMA_BUF_ERROR
+ * to properly written applications unless the input file
+ * is truncated or corrupt. This should simplify the
+ * applications a little.
+ */
+
+ LZMA_PROG_ERROR = 11,
+ /**<
+ * \brief Programming error
+ *
+ * This indicates that the arguments given to the function are
+ * invalid or the internal state of the decoder is corrupt.
+ * - Function arguments are invalid or the structures
+ * pointed by the argument pointers are invalid
+ * e.g. if strm->next_out has been set to NULL and
+ * strm->avail_out > 0 when calling lzma_code().
+ * - lzma_* functions have been called in wrong order
+ * e.g. lzma_code() was called right after lzma_end().
+ * - If errors occur randomly, the reason might be flaky
+ * hardware.
+ *
+ * If you think that your code is correct, this error code
+ * can be a sign of a bug in liblzma. See the documentation
+ * how to report bugs.
+ */
+} lzma_ret;
+
+
+/**
+ * \brief The `action' argument for lzma_code()
+ *
+ * After the first use of LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or LZMA_FINISH,
+ * the same `action' must is used until lzma_code() returns LZMA_STREAM_END.
+ * Also, the amount of input (that is, strm->avail_in) must not be modified
+ * by the application until lzma_code() returns LZMA_STREAM_END. Changing the
+ * `action' or modifying the amount of input will make lzma_code() return
+ * LZMA_PROG_ERROR.
+ */
+typedef enum {
+ LZMA_RUN = 0,
+ /**<
+ * \brief Continue coding
+ *
+ * Encoder: Encode as much input as possible. Some internal
+ * buffering will probably be done (depends on the filter
+ * chain in use), which causes latency: the input used won't
+ * usually be decodeable from the output of the same
+ * lzma_code() call.
+ *
+ * Decoder: Decode as much input as possible and produce as
+ * much output as possible.
+ */
+
+ LZMA_SYNC_FLUSH = 1,
+ /**<
+ * \brief Make all the input available at output
+ *
+ * Normally the encoder introduces some latency.
+ * LZMA_SYNC_FLUSH forces all the buffered data to be
+ * available at output without resetting the internal
+ * state of the encoder. This way it is possible to use
+ * compressed stream for example for communication over
+ * network.
+ *
+ * Only some filters support LZMA_SYNC_FLUSH. Trying to use
+ * LZMA_SYNC_FLUSH with filters that don't support it will
+ * make lzma_code() return LZMA_OPTIONS_ERROR. For example,
+ * LZMA1 doesn't support LZMA_SYNC_FLUSH but LZMA2 does.
+ *
+ * Using LZMA_SYNC_FLUSH very often can dramatically reduce
+ * the compression ratio. With some filters (for example,
+ * LZMA2), fine-tuning the compression options may help
+ * mitigate this problem significantly (for example,
+ * match finder with LZMA2).
+ *
+ * Decoders don't support LZMA_SYNC_FLUSH.
+ */
+
+ LZMA_FULL_FLUSH = 2,
+ /**<
+ * \brief Finish encoding of the current Block
+ *
+ * All the input data going to the current Block must have
+ * been given to the encoder (the last bytes can still be
+ * pending in* next_in). Call lzma_code() with LZMA_FULL_FLUSH
+ * until it returns LZMA_STREAM_END. Then continue normally
+ * with LZMA_RUN or finish the Stream with LZMA_FINISH.
+ *
+ * This action is currently supported only by Stream encoder
+ * and easy encoder (which uses Stream encoder). If there is
+ * no unfinished Block, no empty Block is created.
+ */
+
+ LZMA_FINISH = 3
+ /**<
+ * \brief Finish the coding operation
+ *
+ * All the input data must have been given to the encoder
+ * (the last bytes can still be pending in next_in).
+ * Call lzma_code() with LZMA_FINISH until it returns
+ * LZMA_STREAM_END. Once LZMA_FINISH has been used,
+ * the amount of input must no longer be changed by
+ * the application.
+ *
+ * When decoding, using LZMA_FINISH is optional unless the
+ * LZMA_CONCATENATED flag was used when the decoder was
+ * initialized. When LZMA_CONCATENATED was not used, the only
+ * effect of LZMA_FINISH is that the amount of input must not
+ * be changed just like in the encoder.
+ */
+} lzma_action;
+
+
+/**
+ * \brief Custom functions for memory handling
+ *
+ * A pointer to lzma_allocator may be passed via lzma_stream structure
+ * to liblzma, and some advanced functions take a pointer to lzma_allocator
+ * as a separate function argument. The library will use the functions
+ * specified in lzma_allocator for memory handling instead of the default
+ * malloc() and free(). C++ users should note that the custom memory
+ * handling functions must not throw exceptions.
+ *
+ * liblzma doesn't make an internal copy of lzma_allocator. Thus, it is
+ * OK to change these function pointers in the middle of the coding
+ * process, but obviously it must be done carefully to make sure that the
+ * replacement `free' can deallocate memory allocated by the earlier
+ * `alloc' function(s).
+ */
+typedef struct {
+ /**
+ * \brief Pointer to a custom memory allocation function
+ *
+ * If you don't want a custom allocator, but still want
+ * custom free(), set this to NULL and liblzma will use
+ * the standard malloc().
+ *
+ * \param opaque lzma_allocator.opaque (see below)
+ * \param nmemb Number of elements like in calloc(). liblzma
+ * will always set nmemb to 1, so it is safe to
+ * ignore nmemb in a custom allocator if you like.
+ * The nmemb argument exists only for
+ * compatibility with zlib and libbzip2.
+ * \param size Size of an element in bytes.
+ * liblzma never sets this to zero.
+ *
+ * \return Pointer to the beginning of a memory block of
+ * `size' bytes, or NULL if allocation fails
+ * for some reason. When allocation fails, functions
+ * of liblzma return LZMA_MEM_ERROR.
+ *
+ * The allocator should not waste time zeroing the allocated buffers.
+ * This is not only about speed, but also memory usage, since the
+ * operating system kernel doesn't necessarily allocate the requested
+ * memory in physical memory until it is actually used. With small
+ * input files, liblzma may actually need only a fraction of the
+ * memory that it requested for allocation.
+ *
+ * \note LZMA_MEM_ERROR is also used when the size of the
+ * allocation would be greater than SIZE_MAX. Thus,
+ * don't assume that the custom allocator must have
+ * returned NULL if some function from liblzma
+ * returns LZMA_MEM_ERROR.
+ */
+ void *(LZMA_API_CALL *alloc)(void *opaque, size_t nmemb, size_t size);
+
+ /**
+ * \brief Pointer to a custom memory freeing function
+ *
+ * If you don't want a custom freeing function, but still
+ * want a custom allocator, set this to NULL and liblzma
+ * will use the standard free().
+ *
+ * \param opaque lzma_allocator.opaque (see below)
+ * \param ptr Pointer returned by lzma_allocator.alloc(),
+ * or when it is set to NULL, a pointer returned
+ * by the standard malloc().
+ */
+ void (LZMA_API_CALL *free)(void *opaque, void *ptr);
+
+ /**
+ * \brief Pointer passed to .alloc() and .free()
+ *
+ * opaque is passed as the first argument to lzma_allocator.alloc()
+ * and lzma_allocator.free(). This intended to ease implementing
+ * custom memory allocation functions for use with liblzma.
+ *
+ * If you don't need this, you should set this to NULL.
+ */
+ void *opaque;
+
+} lzma_allocator;
+
+
+/**
+ * \brief Internal data structure
+ *
+ * The contents of this structure is not visible outside the library.
+ */
+typedef struct lzma_internal_s lzma_internal;
+
+
+/**
+ * \brief Passing data to and from liblzma
+ *
+ * The lzma_stream structure is used for
+ * - passing pointers to input and output buffers to liblzma;
+ * - defining custom memory hander functions; and
+ * - holding a pointer to coder-specific internal data structures.
+ *
+ * Typical usage:
+ *
+ * - After allocating lzma_stream (on stack or with malloc()), it must be
+ * initialized to LZMA_STREAM_INIT (see LZMA_STREAM_INIT for details).
+ *
+ * - Initialize a coder to the lzma_stream, for example by using
+ * lzma_easy_encoder() or lzma_auto_decoder(). Some notes:
+ * - In contrast to zlib, strm->next_in and strm->next_out are
+ * ignored by all initialization functions, thus it is safe
+ * to not initialize them yet.
+ * - The initialization functions always set strm->total_in and
+ * strm->total_out to zero.
+ * - If the initialization function fails, no memory is left allocated
+ * that would require freeing with lzma_end() even if some memory was
+ * associated with the lzma_stream structure when the initialization
+ * function was called.
+ *
+ * - Use lzma_code() to do the actual work.
+ *
+ * - Once the coding has been finished, the existing lzma_stream can be
+ * reused. It is OK to reuse lzma_stream with different initialization
+ * function without calling lzma_end() first. Old allocations are
+ * automatically freed.
+ *
+ * - Finally, use lzma_end() to free the allocated memory. lzma_end() never
+ * frees the lzma_stream structure itself.
+ *
+ * Application may modify the values of total_in and total_out as it wants.
+ * They are updated by liblzma to match the amount of data read and
+ * written, but aren't used for anything else.
+ */
+typedef struct {
+ const uint8_t *next_in; /**< Pointer to the next input byte. */
+ size_t avail_in; /**< Number of available input bytes in next_in. */
+ uint64_t total_in; /**< Total number of bytes read by liblzma. */
+
+ uint8_t *next_out; /**< Pointer to the next output position. */
+ size_t avail_out; /**< Amount of free space in next_out. */
+ uint64_t total_out; /**< Total number of bytes written by liblzma. */
+
+ /**
+ * \brief Custom memory allocation functions
+ *
+ * In most cases this is NULL which makes liblzma use
+ * the standard malloc() and free().
+ */
+ lzma_allocator *allocator;
+
+ /** Internal state is not visible to applications. */
+ lzma_internal *internal;
+
+ /*
+ * Reserved space to allow possible future extensions without
+ * breaking the ABI. Excluding the initialization of this structure,
+ * you should not touch these, because the names of these variables
+ * may change.
+ */
+ void *reserved_ptr1;
+ void *reserved_ptr2;
+ void *reserved_ptr3;
+ void *reserved_ptr4;
+ uint64_t reserved_int1;
+ uint64_t reserved_int2;
+ size_t reserved_int3;
+ size_t reserved_int4;
+ lzma_reserved_enum reserved_enum1;
+ lzma_reserved_enum reserved_enum2;
+
+} lzma_stream;
+
+
+/**
+ * \brief Initialization for lzma_stream
+ *
+ * When you declare an instance of lzma_stream, you can immediately
+ * initialize it so that initialization functions know that no memory
+ * has been allocated yet:
+ *
+ * lzma_stream strm = LZMA_STREAM_INIT;
+ *
+ * If you need to initialize a dynamically allocated lzma_stream, you can use
+ * memset(strm_pointer, 0, sizeof(lzma_stream)). Strictly speaking, this
+ * violates the C standard since NULL may have different internal
+ * representation than zero, but it should be portable enough in practice.
+ * Anyway, for maximum portability, you can use something like this:
+ *
+ * lzma_stream tmp = LZMA_STREAM_INIT;
+ * *strm = tmp;
+ */
+#define LZMA_STREAM_INIT \
+ { NULL, 0, 0, NULL, 0, 0, NULL, NULL, \
+ NULL, NULL, NULL, NULL, 0, 0, 0, 0, \
+ LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM }
+
+
+/**
+ * \brief Encode or decode data
+ *
+ * Once the lzma_stream has been successfully initialized (e.g. with
+ * lzma_stream_encoder()), the actual encoding or decoding is done
+ * using this function. The application has to update strm->next_in,
+ * strm->avail_in, strm->next_out, and strm->avail_out to pass input
+ * to and get output from liblzma.
+ *
+ * See the description of the coder-specific initialization function to find
+ * out what `action' values are supported by the coder.
+ */
+extern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Free memory allocated for the coder data structures
+ *
+ * \param strm Pointer to lzma_stream that is at least initialized
+ * with LZMA_STREAM_INIT.
+ *
+ * After lzma_end(strm), strm->internal is guaranteed to be NULL. No other
+ * members of the lzma_stream structure are touched.
+ *
+ * \note zlib indicates an error if application end()s unfinished
+ * stream structure. liblzma doesn't do this, and assumes that
+ * application knows what it is doing.
+ */
+extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow;
+
+
+/**
+ * \brief Get the memory usage of decoder filter chain
+ *
+ * This function is currently supported only when *strm has been initialized
+ * with a function that takes a memlimit argument. With other functions, you
+ * should use e.g. lzma_raw_encoder_memusage() or lzma_raw_decoder_memusage()
+ * to estimate the memory requirements.
+ *
+ * This function is useful e.g. after LZMA_MEMLIMIT_ERROR to find out how big
+ * the memory usage limit should have been to decode the input. Note that
+ * this may give misleading information if decoding .xz Streams that have
+ * multiple Blocks, because each Block can have different memory requirements.
+ *
+ * \return How much memory is currently allocated for the filter
+ * decoders. If no filter chain is currently allocated,
+ * some non-zero value is still returned, which is less than
+ * or equal to what any filter chain would indicate as its
+ * memory requirement.
+ *
+ * If this function isn't supported by *strm or some other error
+ * occurs, zero is returned.
+ */
+extern LZMA_API(uint64_t) lzma_memusage(const lzma_stream *strm)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Get the current memory usage limit
+ *
+ * This function is supported only when *strm has been initialized with
+ * a function that takes a memlimit argument.
+ *
+ * \return On success, the current memory usage limit is returned
+ * (always non-zero). On error, zero is returned.
+ */
+extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Set the memory usage limit
+ *
+ * This function is supported only when *strm has been initialized with
+ * a function that takes a memlimit argument.
+ *
+ * \return - LZMA_OK: New memory usage limit successfully set.
+ * - LZMA_MEMLIMIT_ERROR: The new limit is too small.
+ * The limit was not changed.
+ * - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't
+ * support memory usage limit or memlimit was zero.
+ */
+extern LZMA_API(lzma_ret) lzma_memlimit_set(
+ lzma_stream *strm, uint64_t memlimit) lzma_nothrow;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/bcj.h b/Utilities/cmliblzma/liblzma/api/lzma/bcj.h
new file mode 100644
index 0000000000..8e37538ad4
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/bcj.h
@@ -0,0 +1,90 @@
+/**
+ * \file lzma/bcj.h
+ * \brief Branch/Call/Jump conversion filters
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/* Filter IDs for lzma_filter.id */
+
+#define LZMA_FILTER_X86 LZMA_VLI_C(0x04)
+ /**<
+ * Filter for x86 binaries
+ */
+
+#define LZMA_FILTER_POWERPC LZMA_VLI_C(0x05)
+ /**<
+ * Filter for Big endian PowerPC binaries
+ */
+
+#define LZMA_FILTER_IA64 LZMA_VLI_C(0x06)
+ /**<
+ * Filter for IA-64 (Itanium) binaries.
+ */
+
+#define LZMA_FILTER_ARM LZMA_VLI_C(0x07)
+ /**<
+ * Filter for ARM binaries.
+ */
+
+#define LZMA_FILTER_ARMTHUMB LZMA_VLI_C(0x08)
+ /**<
+ * Filter for ARM-Thumb binaries.
+ */
+
+#define LZMA_FILTER_SPARC LZMA_VLI_C(0x09)
+ /**<
+ * Filter for SPARC binaries.
+ */
+
+
+/**
+ * \brief Options for BCJ filters
+ *
+ * The BCJ filters never change the size of the data. Specifying options
+ * for them is optional: if pointer to options is NULL, default value is
+ * used. You probably never need to specify options to BCJ filters, so just
+ * set the options pointer to NULL and be happy.
+ *
+ * If options with non-default values have been specified when encoding,
+ * the same options must also be specified when decoding.
+ *
+ * \note At the moment, none of the BCJ filters support
+ * LZMA_SYNC_FLUSH. If LZMA_SYNC_FLUSH is specified,
+ * LZMA_OPTIONS_ERROR will be returned. If there is need,
+ * partial support for LZMA_SYNC_FLUSH can be added in future.
+ * Partial means that flushing would be possible only at
+ * offsets that are multiple of 2, 4, or 16 depending on
+ * the filter, except x86 which cannot be made to support
+ * LZMA_SYNC_FLUSH predictably.
+ */
+typedef struct {
+ /**
+ * \brief Start offset for conversions
+ *
+ * This setting is useful only when the same filter is used
+ * _separately_ for multiple sections of the same executable file,
+ * and the sections contain cross-section branch/call/jump
+ * instructions. In that case it is beneficial to set the start
+ * offset of the non-first sections so that the relative addresses
+ * of the cross-section branch/call/jump instructions will use the
+ * same absolute addresses as in the first section.
+ *
+ * When the pointer to options is NULL, the default value (zero)
+ * is used.
+ */
+ uint32_t start_offset;
+
+} lzma_options_bcj;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/block.h b/Utilities/cmliblzma/liblzma/api/lzma/block.h
new file mode 100644
index 0000000000..8a4bf2323c
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/block.h
@@ -0,0 +1,530 @@
+/**
+ * \file lzma/block.h
+ * \brief .xz Block handling
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Options for the Block and Block Header encoders and decoders
+ *
+ * Different Block handling functions use different parts of this structure.
+ * Some read some members, other functions write, and some do both. Only the
+ * members listed for reading need to be initialized when the specified
+ * functions are called. The members marked for writing will be assigned
+ * new values at some point either by calling the given function or by
+ * later calls to lzma_code().
+ */
+typedef struct {
+ /**
+ * \brief Block format version
+ *
+ * To prevent API and ABI breakages if new features are needed in
+ * the Block field, a version number is used to indicate which
+ * fields in this structure are in use. For now, version must always
+ * be zero. With non-zero version, most Block related functions will
+ * return LZMA_OPTIONS_ERROR.
+ *
+ * Read by:
+ * - All functions that take pointer to lzma_block as argument,
+ * including lzma_block_header_decode().
+ *
+ * Written by:
+ * - lzma_block_header_decode()
+ */
+ uint32_t version;
+
+ /**
+ * \brief Size of the Block Header field
+ *
+ * This is always a multiple of four.
+ *
+ * Read by:
+ * - lzma_block_header_encode()
+ * - lzma_block_header_decode()
+ * - lzma_block_compressed_size()
+ * - lzma_block_unpadded_size()
+ * - lzma_block_total_size()
+ * - lzma_block_decoder()
+ * - lzma_block_buffer_decode()
+ *
+ * Written by:
+ * - lzma_block_header_size()
+ * - lzma_block_buffer_encode()
+ */
+ uint32_t header_size;
+# define LZMA_BLOCK_HEADER_SIZE_MIN 8
+# define LZMA_BLOCK_HEADER_SIZE_MAX 1024
+
+ /**
+ * \brief Type of integrity Check
+ *
+ * The Check ID is not stored into the Block Header, thus its value
+ * must be provided also when decoding.
+ *
+ * Read by:
+ * - lzma_block_header_encode()
+ * - lzma_block_header_decode()
+ * - lzma_block_compressed_size()
+ * - lzma_block_unpadded_size()
+ * - lzma_block_total_size()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ * - lzma_block_buffer_encode()
+ * - lzma_block_buffer_decode()
+ */
+ lzma_check check;
+
+ /**
+ * \brief Size of the Compressed Data in bytes
+ *
+ * Encoding: If this is not LZMA_VLI_UNKNOWN, Block Header encoder
+ * will store this value to the Block Header. Block encoder doesn't
+ * care about this value, but will set it once the encoding has been
+ * finished.
+ *
+ * Decoding: If this is not LZMA_VLI_UNKNOWN, Block decoder will
+ * verify that the size of the Compressed Data field matches
+ * compressed_size.
+ *
+ * Usually you don't know this value when encoding in streamed mode,
+ * and thus cannot write this field into the Block Header.
+ *
+ * In non-streamed mode you can reserve space for this field before
+ * encoding the actual Block. After encoding the data, finish the
+ * Block by encoding the Block Header. Steps in detail:
+ *
+ * - Set compressed_size to some big enough value. If you don't know
+ * better, use LZMA_VLI_MAX, but remember that bigger values take
+ * more space in Block Header.
+ *
+ * - Call lzma_block_header_size() to see how much space you need to
+ * reserve for the Block Header.
+ *
+ * - Encode the Block using lzma_block_encoder() and lzma_code().
+ * It sets compressed_size to the correct value.
+ *
+ * - Use lzma_block_header_encode() to encode the Block Header.
+ * Because space was reserved in the first step, you don't need
+ * to call lzma_block_header_size() anymore, because due to
+ * reserving, header_size has to be big enough. If it is "too big",
+ * lzma_block_header_encode() will add enough Header Padding to
+ * make Block Header to match the size specified by header_size.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encode()
+ * - lzma_block_compressed_size()
+ * - lzma_block_unpadded_size()
+ * - lzma_block_total_size()
+ * - lzma_block_decoder()
+ * - lzma_block_buffer_decode()
+ *
+ * Written by:
+ * - lzma_block_header_decode()
+ * - lzma_block_compressed_size()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ * - lzma_block_buffer_encode()
+ * - lzma_block_buffer_decode()
+ */
+ lzma_vli compressed_size;
+
+ /**
+ * \brief Uncompressed Size in bytes
+ *
+ * This is handled very similarly to compressed_size above.
+ *
+ * uncompressed_size is needed by fewer functions than
+ * compressed_size. This is because uncompressed_size isn't
+ * needed to validate that Block stays within proper limits.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encode()
+ * - lzma_block_decoder()
+ * - lzma_block_buffer_decode()
+ *
+ * Written by:
+ * - lzma_block_header_decode()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ * - lzma_block_buffer_encode()
+ * - lzma_block_buffer_decode()
+ */
+ lzma_vli uncompressed_size;
+
+ /**
+ * \brief Array of filters
+ *
+ * There can be 1-4 filters. The end of the array is marked with
+ * .id = LZMA_VLI_UNKNOWN.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encode()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ * - lzma_block_buffer_encode()
+ * - lzma_block_buffer_decode()
+ *
+ * Written by:
+ * - lzma_block_header_decode(): Note that this does NOT free()
+ * the old filter options structures. All unused filters[] will
+ * have .id == LZMA_VLI_UNKNOWN and .options == NULL. If
+ * decoding fails, all filters[] are guaranteed to be
+ * LZMA_VLI_UNKNOWN and NULL.
+ *
+ * \note Because of the array is terminated with
+ * .id = LZMA_VLI_UNKNOWN, the actual array must
+ * have LZMA_FILTERS_MAX + 1 members or the Block
+ * Header decoder will overflow the buffer.
+ */
+ lzma_filter *filters;
+
+ /**
+ * \brief Raw value stored in the Check field
+ *
+ * After successful coding, the first lzma_check_size(check) bytes
+ * of this array contain the raw value stored in the Check field.
+ *
+ * Note that CRC32 and CRC64 are stored in little endian byte order.
+ * Take it into account if you display the Check values to the user.
+ *
+ * Written by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ * - lzma_block_buffer_encode()
+ * - lzma_block_buffer_decode()
+ */
+ uint8_t raw_check[LZMA_CHECK_SIZE_MAX];
+
+ /*
+ * Reserved space to allow possible future extensions without
+ * breaking the ABI. You should not touch these, because the names
+ * of these variables may change. These are and will never be used
+ * with the currently supported options, so it is safe to leave these
+ * uninitialized.
+ */
+ void *reserved_ptr1;
+ void *reserved_ptr2;
+ void *reserved_ptr3;
+ uint32_t reserved_int1;
+ uint32_t reserved_int2;
+ lzma_vli reserved_int3;
+ lzma_vli reserved_int4;
+ lzma_vli reserved_int5;
+ lzma_vli reserved_int6;
+ lzma_vli reserved_int7;
+ lzma_vli reserved_int8;
+ lzma_reserved_enum reserved_enum1;
+ lzma_reserved_enum reserved_enum2;
+ lzma_reserved_enum reserved_enum3;
+ lzma_reserved_enum reserved_enum4;
+ lzma_bool reserved_bool1;
+ lzma_bool reserved_bool2;
+ lzma_bool reserved_bool3;
+ lzma_bool reserved_bool4;
+ lzma_bool reserved_bool5;
+ lzma_bool reserved_bool6;
+ lzma_bool reserved_bool7;
+ lzma_bool reserved_bool8;
+
+} lzma_block;
+
+
+/**
+ * \brief Decode the Block Header Size field
+ *
+ * To decode Block Header using lzma_block_header_decode(), the size of the
+ * Block Header has to be known and stored into lzma_block.header_size.
+ * The size can be calculated from the first byte of a Block using this macro.
+ * Note that if the first byte is 0x00, it indicates beginning of Index; use
+ * this macro only when the byte is not 0x00.
+ *
+ * There is no encoding macro, because Block Header encoder is enough for that.
+ */
+#define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4)
+
+
+/**
+ * \brief Calculate Block Header Size
+ *
+ * Calculate the minimum size needed for the Block Header field using the
+ * settings specified in the lzma_block structure. Note that it is OK to
+ * increase the calculated header_size value as long as it is a multiple of
+ * four and doesn't exceed LZMA_BLOCK_HEADER_SIZE_MAX. Increasing header_size
+ * just means that lzma_block_header_encode() will add Header Padding.
+ *
+ * \return - LZMA_OK: Size calculated successfully and stored to
+ * block->header_size.
+ * - LZMA_OPTIONS_ERROR: Unsupported version, filters or
+ * filter options.
+ * - LZMA_PROG_ERROR: Invalid values like compressed_size == 0.
+ *
+ * \note This doesn't check that all the options are valid i.e. this
+ * may return LZMA_OK even if lzma_block_header_encode() or
+ * lzma_block_encoder() would fail. If you want to validate the
+ * filter chain, consider using lzma_memlimit_encoder() which as
+ * a side-effect validates the filter chain.
+ */
+extern LZMA_API(lzma_ret) lzma_block_header_size(lzma_block *block)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Encode Block Header
+ *
+ * The caller must have calculated the size of the Block Header already with
+ * lzma_block_header_size(). If a value larger than the one calculated by
+ * lzma_block_header_size() is used, the Block Header will be padded to the
+ * specified size.
+ *
+ * \param out Beginning of the output buffer. This must be
+ * at least block->header_size bytes.
+ * \param block Block options to be encoded.
+ *
+ * \return - LZMA_OK: Encoding was successful. block->header_size
+ * bytes were written to output buffer.
+ * - LZMA_OPTIONS_ERROR: Invalid or unsupported options.
+ * - LZMA_PROG_ERROR: Invalid arguments, for example
+ * block->header_size is invalid or block->filters is NULL.
+ */
+extern LZMA_API(lzma_ret) lzma_block_header_encode(
+ const lzma_block *block, uint8_t *out)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Decode Block Header
+ *
+ * block->version should be set to the highest value supported by the
+ * application; currently the only possible version is zero. This function
+ * will set version to the lowest value that still supports all the features
+ * required by the Block Header.
+ *
+ * The size of the Block Header must have already been decoded with
+ * lzma_block_header_size_decode() macro and stored to block->header_size.
+ *
+ * block->filters must have been allocated, but they don't need to be
+ * initialized (possible existing filter options are not freed).
+ *
+ * \param block Destination for Block options.
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc() (and also free()
+ * if an error occurs).
+ * \param in Beginning of the input buffer. This must be
+ * at least block->header_size bytes.
+ *
+ * \return - LZMA_OK: Decoding was successful. block->header_size
+ * bytes were read from the input buffer.
+ * - LZMA_OPTIONS_ERROR: The Block Header specifies some
+ * unsupported options such as unsupported filters. This can
+ * happen also if block->version was set to a too low value
+ * compared to what would be required to properly represent
+ * the information stored in the Block Header.
+ * - LZMA_DATA_ERROR: Block Header is corrupt, for example,
+ * the CRC32 doesn't match.
+ * - LZMA_PROG_ERROR: Invalid arguments, for example
+ * block->header_size is invalid or block->filters is NULL.
+ */
+extern LZMA_API(lzma_ret) lzma_block_header_decode(lzma_block *block,
+ lzma_allocator *allocator, const uint8_t *in)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Validate and set Compressed Size according to Unpadded Size
+ *
+ * Block Header stores Compressed Size, but Index has Unpadded Size. If the
+ * application has already parsed the Index and is now decoding Blocks,
+ * it can calculate Compressed Size from Unpadded Size. This function does
+ * exactly that with error checking:
+ *
+ * - Compressed Size calculated from Unpadded Size must be positive integer,
+ * that is, Unpadded Size must be big enough that after Block Header and
+ * Check fields there's still at least one byte for Compressed Size.
+ *
+ * - If Compressed Size was present in Block Header, the new value
+ * calculated from Unpadded Size is compared against the value
+ * from Block Header.
+ *
+ * \note This function must be called _after_ decoding the Block Header
+ * field so that it can properly validate Compressed Size if it
+ * was present in Block Header.
+ *
+ * \return - LZMA_OK: block->compressed_size was set successfully.
+ * - LZMA_DATA_ERROR: unpadded_size is too small compared to
+ * block->header_size and lzma_check_size(block->check).
+ * - LZMA_PROG_ERROR: Some values are invalid. For example,
+ * block->header_size must be a multiple of four and
+ * between 8 and 1024 inclusive.
+ */
+extern LZMA_API(lzma_ret) lzma_block_compressed_size(
+ lzma_block *block, lzma_vli unpadded_size)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Calculate Unpadded Size
+ *
+ * The Index field stores Unpadded Size and Uncompressed Size. The latter
+ * can be taken directly from the lzma_block structure after coding a Block,
+ * but Unpadded Size needs to be calculated from Block Header Size,
+ * Compressed Size, and size of the Check field. This is where this function
+ * is needed.
+ *
+ * \return Unpadded Size on success, or zero on error.
+ */
+extern LZMA_API(lzma_vli) lzma_block_unpadded_size(const lzma_block *block)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Calculate the total encoded size of a Block
+ *
+ * This is equivalent to lzma_block_unpadded_size() except that the returned
+ * value includes the size of the Block Padding field.
+ *
+ * \return On success, total encoded size of the Block. On error,
+ * zero is returned.
+ */
+extern LZMA_API(lzma_vli) lzma_block_total_size(const lzma_block *block)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Initialize .xz Block encoder
+ *
+ * Valid actions for lzma_code() are LZMA_RUN, LZMA_SYNC_FLUSH (only if the
+ * filter chain supports it), and LZMA_FINISH.
+ *
+ * \return - LZMA_OK: All good, continue with lzma_code().
+ * - LZMA_MEM_ERROR
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_UNSUPPORTED_CHECK: block->check specifies a Check ID
+ * that is not supported by this buid of liblzma. Initializing
+ * the encoder failed.
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_block_encoder(
+ lzma_stream *strm, lzma_block *block)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Initialize .xz Block decoder
+ *
+ * Valid actions for lzma_code() are LZMA_RUN and LZMA_FINISH. Using
+ * LZMA_FINISH is not required. It is supported only for convenience.
+ *
+ * \return - LZMA_OK: All good, continue with lzma_code().
+ * - LZMA_UNSUPPORTED_CHECK: Initialization was successful, but
+ * the given Check ID is not supported, thus Check will be
+ * ignored.
+ * - LZMA_PROG_ERROR
+ * - LZMA_MEM_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_block_decoder(
+ lzma_stream *strm, lzma_block *block)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Calculate maximum output size for single-call Block encoding
+ *
+ * This is equivalent to lzma_stream_buffer_bound() but for .xz Blocks.
+ * See the documentation of lzma_stream_buffer_bound().
+ */
+extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size)
+ lzma_nothrow;
+
+
+/**
+ * \brief Single-call .xz Block encoder
+ *
+ * In contrast to the multi-call encoder initialized with
+ * lzma_block_encoder(), this function encodes also the Block Header. This
+ * is required to make it possible to write appropriate Block Header also
+ * in case the data isn't compressible, and different filter chain has to be
+ * used to encode the data in uncompressed form using uncompressed chunks
+ * of the LZMA2 filter.
+ *
+ * When the data isn't compressible, header_size, compressed_size, and
+ * uncompressed_size are set just like when the data was compressible, but
+ * it is possible that header_size is too small to hold the filter chain
+ * specified in block->filters, because that isn't necessarily the filter
+ * chain that was actually used to encode the data. lzma_block_unpadded_size()
+ * still works normally, because it doesn't read the filters array.
+ *
+ * \param block Block options: block->version, block->check,
+ * and block->filters must have been initialized.
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc() and free().
+ * \param in Beginning of the input buffer
+ * \param in_size Size of the input buffer
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * *out_pos is updated only if encoding succeeds.
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_BUF_ERROR: Not enough output buffer space.
+ * - LZMA_UNSUPPORTED_CHECK
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_MEM_ERROR
+ * - LZMA_DATA_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_block_buffer_encode(
+ lzma_block *block, lzma_allocator *allocator,
+ const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Single-call .xz Block decoder
+ *
+ * This is single-call equivalent of lzma_block_decoder(), and requires that
+ * the caller has already decoded Block Header and checked its memory usage.
+ *
+ * \param block Block options just like with lzma_block_decoder().
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc() and free().
+ * \param in Beginning of the input buffer
+ * \param in_pos The next byte will be read from in[*in_pos].
+ * *in_pos is updated only if decoding succeeds.
+ * \param in_size Size of the input buffer; the first byte that
+ * won't be read is in[in_size].
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * *out_pos is updated only if encoding succeeds.
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ *
+ * \return - LZMA_OK: Decoding was successful.
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_DATA_ERROR
+ * - LZMA_MEM_ERROR
+ * - LZMA_BUF_ERROR: Output buffer was too small.
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_block_buffer_decode(
+ lzma_block *block, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+ lzma_nothrow;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/check.h b/Utilities/cmliblzma/liblzma/api/lzma/check.h
new file mode 100644
index 0000000000..6a243db0d7
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/check.h
@@ -0,0 +1,150 @@
+/**
+ * \file lzma/check.h
+ * \brief Integrity checks
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Type of the integrity check (Check ID)
+ *
+ * The .xz format supports multiple types of checks that are calculated
+ * from the uncompressed data. They vary in both speed and ability to
+ * detect errors.
+ */
+typedef enum {
+ LZMA_CHECK_NONE = 0,
+ /**<
+ * No Check is calculated.
+ *
+ * Size of the Check field: 0 bytes
+ */
+
+ LZMA_CHECK_CRC32 = 1,
+ /**<
+ * CRC32 using the polynomial from the IEEE 802.3 standard
+ *
+ * Size of the Check field: 4 bytes
+ */
+
+ LZMA_CHECK_CRC64 = 4,
+ /**<
+ * CRC64 using the polynomial from the ECMA-182 standard
+ *
+ * Size of the Check field: 8 bytes
+ */
+
+ LZMA_CHECK_SHA256 = 10
+ /**<
+ * SHA-256
+ *
+ * Size of the Check field: 32 bytes
+ */
+} lzma_check;
+
+
+/**
+ * \brief Maximum valid Check ID
+ *
+ * The .xz file format specification specifies 16 Check IDs (0-15). Some
+ * of them are only reserved, that is, no actual Check algorithm has been
+ * assigned. When decoding, liblzma still accepts unknown Check IDs for
+ * future compatibility. If a valid but unsupported Check ID is detected,
+ * liblzma can indicate a warning; see the flags LZMA_TELL_NO_CHECK,
+ * LZMA_TELL_UNSUPPORTED_CHECK, and LZMA_TELL_ANY_CHECK in container.h.
+ */
+#define LZMA_CHECK_ID_MAX 15
+
+
+/**
+ * \brief Test if the given Check ID is supported
+ *
+ * Return true if the given Check ID is supported by this liblzma build.
+ * Otherwise false is returned. It is safe to call this with a value that
+ * is not in the range [0, 15]; in that case the return value is always false.
+ *
+ * You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always
+ * supported (even if liblzma is built with limited features).
+ */
+extern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check)
+ lzma_nothrow lzma_attr_const;
+
+
+/**
+ * \brief Get the size of the Check field with the given Check ID
+ *
+ * Although not all Check IDs have a check algorithm associated, the size of
+ * every Check is already frozen. This function returns the size (in bytes) of
+ * the Check field with the specified Check ID. The values are:
+ * { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 }
+ *
+ * If the argument is not in the range [0, 15], UINT32_MAX is returned.
+ */
+extern LZMA_API(uint32_t) lzma_check_size(lzma_check check)
+ lzma_nothrow lzma_attr_const;
+
+
+/**
+ * \brief Maximum size of a Check field
+ */
+#define LZMA_CHECK_SIZE_MAX 64
+
+
+/**
+ * \brief Calculate CRC32
+ *
+ * Calculate CRC32 using the polynomial from the IEEE 802.3 standard.
+ *
+ * \param buf Pointer to the input buffer
+ * \param size Size of the input buffer
+ * \param crc Previously returned CRC value. This is used to
+ * calculate the CRC of a big buffer in smaller chunks.
+ * Set to zero when starting a new calculation.
+ *
+ * \return Updated CRC value, which can be passed to this function
+ * again to continue CRC calculation.
+ */
+extern LZMA_API(uint32_t) lzma_crc32(
+ const uint8_t *buf, size_t size, uint32_t crc)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Calculate CRC64
+ *
+ * Calculate CRC64 using the polynomial from the ECMA-182 standard.
+ *
+ * This function is used similarly to lzma_crc32(). See its documentation.
+ */
+extern LZMA_API(uint64_t) lzma_crc64(
+ const uint8_t *buf, size_t size, uint64_t crc)
+ lzma_nothrow lzma_attr_pure;
+
+
+/*
+ * SHA-256 functions are currently not exported to public API.
+ * Contact Lasse Collin if you think it should be.
+ */
+
+
+/**
+ * \brief Get the type of the integrity check
+ *
+ * This function can be called only immediately after lzma_code() has
+ * returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK.
+ * Calling this function in any other situation has undefined behavior.
+ */
+extern LZMA_API(lzma_check) lzma_get_check(const lzma_stream *strm)
+ lzma_nothrow;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/container.h b/Utilities/cmliblzma/liblzma/api/lzma/container.h
new file mode 100644
index 0000000000..7a9ffc6457
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/container.h
@@ -0,0 +1,424 @@
+/**
+ * \file lzma/container.h
+ * \brief File formats
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/************
+ * Encoding *
+ ************/
+
+/**
+ * \brief Default compression preset
+ *
+ * It's not straightforward to recommend a default preset, because in some
+ * cases keeping the resource usage relatively low is more important that
+ * getting the maximum compression ratio.
+ */
+#define LZMA_PRESET_DEFAULT UINT32_C(6)
+
+
+/**
+ * \brief Mask for preset level
+ *
+ * This is useful only if you need to extract the level from the preset
+ * variable. That should be rare.
+ */
+#define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F)
+
+
+/*
+ * Preset flags
+ *
+ * Currently only one flag is defined.
+ */
+
+/**
+ * \brief Extreme compression preset
+ *
+ * This flag modifies the preset to make the encoding significantly slower
+ * while improving the compression ratio only marginally. This is useful
+ * when you don't mind wasting time to get as small result as possible.
+ *
+ * This flag doesn't affect the memory usage requirements of the decoder (at
+ * least not significantly). The memory usage of the encoder may be increased
+ * a little but only at the lowest preset levels (0-3).
+ */
+#define LZMA_PRESET_EXTREME (UINT32_C(1) << 31)
+
+
+/**
+ * \brief Calculate approximate memory usage of easy encoder
+ *
+ * This function is a wrapper for lzma_raw_encoder_memusage().
+ *
+ * \param preset Compression preset (level and possible flags)
+ *
+ * \return Number of bytes of memory required for the given
+ * preset when encoding. If an error occurs, for example
+ * due to unsupported preset, UINT64_MAX is returned.
+ */
+extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Calculate approximate decoder memory usage of a preset
+ *
+ * This function is a wrapper for lzma_raw_decoder_memusage().
+ *
+ * \param preset Compression preset (level and possible flags)
+ *
+ * \return Number of bytes of memory required to decompress a file
+ * that was compressed using the given preset. If an error
+ * occurs, for example due to unsupported preset, UINT64_MAX
+ * is returned.
+ */
+extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Initialize .xz Stream encoder using a preset number
+ *
+ * This function is intended for those who just want to use the basic features
+ * if liblzma (that is, most developers out there).
+ *
+ * \param strm Pointer to lzma_stream that is at least initialized
+ * with LZMA_STREAM_INIT.
+ * \param preset Compression preset to use. A preset consist of level
+ * number and zero or more flags. Usually flags aren't
+ * used, so preset is simply a number [0, 9] which match
+ * the options -0 ... -9 of the xz command line tool.
+ * Additional flags can be be set using bitwise-or with
+ * the preset level number, e.g. 6 | LZMA_PRESET_EXTREME.
+ * \param check Integrity check type to use. See check.h for available
+ * checks. The xz command line tool defaults to
+ * LZMA_CHECK_CRC64, which is a good choice if you are
+ * unsure. LZMA_CHECK_CRC32 is good too as long as the
+ * uncompressed file is not many gigabytes.
+ *
+ * \return - LZMA_OK: Initialization succeeded. Use lzma_code() to
+ * encode your data.
+ * - LZMA_MEM_ERROR: Memory allocation failed.
+ * - LZMA_OPTIONS_ERROR: The given compression preset is not
+ * supported by this build of liblzma.
+ * - LZMA_UNSUPPORTED_CHECK: The given check type is not
+ * supported by this liblzma build.
+ * - LZMA_PROG_ERROR: One or more of the parameters have values
+ * that will never be valid. For example, strm == NULL.
+ *
+ * If initialization fails (return value is not LZMA_OK), all the memory
+ * allocated for *strm by liblzma is always freed. Thus, there is no need
+ * to call lzma_end() after failed initialization.
+ *
+ * If initialization succeeds, use lzma_code() to do the actual encoding.
+ * Valid values for `action' (the second argument of lzma_code()) are
+ * LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,
+ * there may be compression levels or flags that don't support LZMA_SYNC_FLUSH.
+ */
+extern LZMA_API(lzma_ret) lzma_easy_encoder(
+ lzma_stream *strm, uint32_t preset, lzma_check check)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Single-call .xz Stream encoding using a preset number
+ *
+ * The maximum required output buffer size can be calculated with
+ * lzma_stream_buffer_bound().
+ *
+ * \param preset Compression preset to use. See the description
+ * in lzma_easy_encoder().
+ * \param check Type of the integrity check to calculate from
+ * uncompressed data.
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc() and free().
+ * \param in Beginning of the input buffer
+ * \param in_size Size of the input buffer
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * *out_pos is updated only if encoding succeeds.
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_BUF_ERROR: Not enough output buffer space.
+ * - LZMA_UNSUPPORTED_CHECK
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_MEM_ERROR
+ * - LZMA_DATA_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_easy_buffer_encode(
+ uint32_t preset, lzma_check check,
+ lzma_allocator *allocator, const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
+
+
+/**
+ * \brief Initialize .xz Stream encoder using a custom filter chain
+ *
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param filters Array of filters. This must be terminated with
+ * filters[n].id = LZMA_VLI_UNKNOWN. See filter.h for
+ * more information.
+ * \param check Type of the integrity check to calculate from
+ * uncompressed data.
+ *
+ * \return - LZMA_OK: Initialization was successful.
+ * - LZMA_MEM_ERROR
+ * - LZMA_UNSUPPORTED_CHECK
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm,
+ const lzma_filter *filters, lzma_check check)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Initialize .lzma encoder (legacy file format)
+ *
+ * The .lzma format is sometimes called the LZMA_Alone format, which is the
+ * reason for the name of this function. The .lzma format supports only the
+ * LZMA1 filter. There is no support for integrity checks like CRC32.
+ *
+ * Use this function if and only if you need to create files readable by
+ * legacy LZMA tools such as LZMA Utils 4.32.x. Moving to the .xz format
+ * is strongly recommended.
+ *
+ * The valid action values for lzma_code() are LZMA_RUN and LZMA_FINISH.
+ * No kind of flushing is supported, because the file format doesn't make
+ * it possible.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_alone_encoder(
+ lzma_stream *strm, const lzma_options_lzma *options)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Calculate output buffer size for single-call Stream encoder
+ *
+ * When trying to compress uncompressible data, the encoded size will be
+ * slightly bigger than the input data. This function calculates how much
+ * output buffer space is required to be sure that lzma_stream_buffer_encode()
+ * doesn't return LZMA_BUF_ERROR.
+ *
+ * The calculated value is not exact, but it is guaranteed to be big enough.
+ * The actual maximum output space required may be slightly smaller (up to
+ * about 100 bytes). This should not be a problem in practice.
+ *
+ * If the calculated maximum size doesn't fit into size_t or would make the
+ * Stream grow past LZMA_VLI_MAX (which should never happen in practice),
+ * zero is returned to indicate the error.
+ *
+ * \note The limit calculated by this function applies only to
+ * single-call encoding. Multi-call encoding may (and probably
+ * will) have larger maximum expansion when encoding
+ * uncompressible data. Currently there is no function to
+ * calculate the maximum expansion of multi-call encoding.
+ */
+extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size)
+ lzma_nothrow;
+
+
+/**
+ * \brief Single-call .xz Stream encoder
+ *
+ * \param filters Array of filters. This must be terminated with
+ * filters[n].id = LZMA_VLI_UNKNOWN. See filter.h
+ * for more information.
+ * \param check Type of the integrity check to calculate from
+ * uncompressed data.
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc() and free().
+ * \param in Beginning of the input buffer
+ * \param in_size Size of the input buffer
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * *out_pos is updated only if encoding succeeds.
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_BUF_ERROR: Not enough output buffer space.
+ * - LZMA_UNSUPPORTED_CHECK
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_MEM_ERROR
+ * - LZMA_DATA_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
+ lzma_filter *filters, lzma_check check,
+ lzma_allocator *allocator, const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/************
+ * Decoding *
+ ************/
+
+/**
+ * This flag makes lzma_code() return LZMA_NO_CHECK if the input stream
+ * being decoded has no integrity check. Note that when used with
+ * lzma_auto_decoder(), all .lzma files will trigger LZMA_NO_CHECK
+ * if LZMA_TELL_NO_CHECK is used.
+ */
+#define LZMA_TELL_NO_CHECK UINT32_C(0x01)
+
+
+/**
+ * This flag makes lzma_code() return LZMA_UNSUPPORTED_CHECK if the input
+ * stream has an integrity check, but the type of the integrity check is not
+ * supported by this liblzma version or build. Such files can still be
+ * decoded, but the integrity check cannot be verified.
+ */
+#define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02)
+
+
+/**
+ * This flag makes lzma_code() return LZMA_GET_CHECK as soon as the type
+ * of the integrity check is known. The type can then be got with
+ * lzma_get_check().
+ */
+#define LZMA_TELL_ANY_CHECK UINT32_C(0x04)
+
+
+/**
+ * This flag enables decoding of concatenated files with file formats that
+ * allow concatenating compressed files as is. From the formats currently
+ * supported by liblzma, only the .xz format allows concatenated files.
+ * Concatenated files are not allowed with the legacy .lzma format.
+ *
+ * This flag also affects the usage of the `action' argument for lzma_code().
+ * When LZMA_CONCATENATED is used, lzma_code() won't return LZMA_STREAM_END
+ * unless LZMA_FINISH is used as `action'. Thus, the application has to set
+ * LZMA_FINISH in the same way as it does when encoding.
+ *
+ * If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH
+ * as `action' for lzma_code(), but the usage of LZMA_FINISH isn't required.
+ */
+#define LZMA_CONCATENATED UINT32_C(0x08)
+
+
+/**
+ * \brief Initialize .xz Stream decoder
+ *
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
+ * to effectively disable the limiter.
+ * \param flags Bitwise-or of zero or more of the decoder flags:
+ * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
+ * LZMA_TELL_ANY_CHECK, LZMA_CONCATENATED
+ *
+ * \return - LZMA_OK: Initialization was successful.
+ * - LZMA_MEM_ERROR: Cannot allocate memory.
+ * - LZMA_OPTIONS_ERROR: Unsupported flags
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_stream_decoder(
+ lzma_stream *strm, uint64_t memlimit, uint32_t flags)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Decode .xz Streams and .lzma files with autodetection
+ *
+ * This decoder autodetects between the .xz and .lzma file formats, and
+ * calls lzma_stream_decoder() or lzma_alone_decoder() once the type
+ * of the input file has been detected.
+ *
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
+ * to effectively disable the limiter.
+ * \param flags Bitwise-or of flags, or zero for no flags.
+ *
+ * \return - LZMA_OK: Initialization was successful.
+ * - LZMA_MEM_ERROR: Cannot allocate memory.
+ * - LZMA_OPTIONS_ERROR: Unsupported flags
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_auto_decoder(
+ lzma_stream *strm, uint64_t memlimit, uint32_t flags)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Initialize .lzma decoder (legacy file format)
+ *
+ * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
+ * There is no need to use LZMA_FINISH, but allowing it may simplify
+ * certain types of applications.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_alone_decoder(
+ lzma_stream *strm, uint64_t memlimit)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Single-call .xz Stream decoder
+ *
+ * \param memlimit Pointer to how much memory the decoder is allowed
+ * to allocate. The value pointed by this pointer is
+ * modified if and only if LZMA_MEMLIMIT_ERROR is
+ * returned.
+ * \param flags Bitwise-or of zero or more of the decoder flags:
+ * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
+ * LZMA_CONCATENATED. Note that LZMA_TELL_ANY_CHECK
+ * is not allowed and will return LZMA_PROG_ERROR.
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc() and free().
+ * \param in Beginning of the input buffer
+ * \param in_pos The next byte will be read from in[*in_pos].
+ * *in_pos is updated only if decoding succeeds.
+ * \param in_size Size of the input buffer; the first byte that
+ * won't be read is in[in_size].
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * *out_pos is updated only if decoding succeeds.
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ *
+ * \return - LZMA_OK: Decoding was successful.
+ * - LZMA_FORMAT_ERROR
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_DATA_ERROR
+ * - LZMA_NO_CHECK: This can be returned only if using
+ * the LZMA_TELL_NO_CHECK flag.
+ * - LZMA_UNSUPPORTED_CHECK: This can be returned only if using
+ * the LZMA_TELL_UNSUPPORTED_CHECK flag.
+ * - LZMA_MEM_ERROR
+ * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
+ * The minimum required memlimit value was stored to *memlimit.
+ * - LZMA_BUF_ERROR: Output buffer was too small.
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_stream_buffer_decode(
+ uint64_t *memlimit, uint32_t flags, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+ lzma_nothrow lzma_attr_warn_unused_result;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/delta.h b/Utilities/cmliblzma/liblzma/api/lzma/delta.h
new file mode 100644
index 0000000000..592fc4f849
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/delta.h
@@ -0,0 +1,77 @@
+/**
+ * \file lzma/delta.h
+ * \brief Delta filter
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Filter ID
+ *
+ * Filter ID of the Delta filter. This is used as lzma_filter.id.
+ */
+#define LZMA_FILTER_DELTA LZMA_VLI_C(0x03)
+
+
+/**
+ * \brief Type of the delta calculation
+ *
+ * Currently only byte-wise delta is supported. Other possible types could
+ * be, for example, delta of 16/32/64-bit little/big endian integers, but
+ * these are not currently planned since byte-wise delta is almost as good.
+ */
+typedef enum {
+ LZMA_DELTA_TYPE_BYTE
+} lzma_delta_type;
+
+
+/**
+ * \brief Options for the Delta filter
+ *
+ * These options are needed by both encoder and decoder.
+ */
+typedef struct {
+ /** For now, this must always be LZMA_DELTA_TYPE_BYTE. */
+ lzma_delta_type type;
+
+ /**
+ * \brief Delta distance
+ *
+ * With the only currently supported type, LZMA_DELTA_TYPE_BYTE,
+ * the distance is as bytes.
+ *
+ * Examples:
+ * - 16-bit stereo audio: distance = 4 bytes
+ * - 24-bit RGB image data: distance = 3 bytes
+ */
+ uint32_t dist;
+# define LZMA_DELTA_DIST_MIN 1
+# define LZMA_DELTA_DIST_MAX 256
+
+ /*
+ * Reserved space to allow possible future extensions without
+ * breaking the ABI. You should not touch these, because the names
+ * of these variables may change. These are and will never be used
+ * when type is LZMA_DELTA_TYPE_BYTE, so it is safe to leave these
+ * uninitialized.
+ */
+ uint32_t reserved_int1;
+ uint32_t reserved_int2;
+ uint32_t reserved_int3;
+ uint32_t reserved_int4;
+ void *reserved_ptr1;
+ void *reserved_ptr2;
+
+} lzma_options_delta;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/filter.h b/Utilities/cmliblzma/liblzma/api/lzma/filter.h
new file mode 100644
index 0000000000..e0bc163ad3
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/filter.h
@@ -0,0 +1,424 @@
+/**
+ * \file lzma/filter.h
+ * \brief Common filter related types and functions
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Maximum number of filters in a chain
+ *
+ * A filter chain can have 1-4 filters, of which three are allowed to change
+ * the size of the data. Usually only one or two filters are needed.
+ */
+#define LZMA_FILTERS_MAX 4
+
+
+/**
+ * \brief Filter options
+ *
+ * This structure is used to pass Filter ID and a pointer filter's
+ * options to liblzma. A few functions work with a single lzma_filter
+ * structure, while most functions expect a filter chain.
+ *
+ * A filter chain is indicated with an array of lzma_filter structures.
+ * The array is terminated with .id = LZMA_VLI_UNKNOWN. Thus, the filter
+ * array must have LZMA_FILTERS_MAX + 1 elements (that is, five) to
+ * be able to hold any arbitrary filter chain. This is important when
+ * using lzma_block_header_decode() from block.h, because too small
+ * array would make liblzma write past the end of the filters array.
+ */
+typedef struct {
+ /**
+ * \brief Filter ID
+ *
+ * Use constants whose name begin with `LZMA_FILTER_' to specify
+ * different filters. In an array of lzma_filter structures, use
+ * LZMA_VLI_UNKNOWN to indicate end of filters.
+ *
+ * \note This is not an enum, because on some systems enums
+ * cannot be 64-bit.
+ */
+ lzma_vli id;
+
+ /**
+ * \brief Pointer to filter-specific options structure
+ *
+ * If the filter doesn't need options, set this to NULL. If id is
+ * set to LZMA_VLI_UNKNOWN, options is ignored, and thus
+ * doesn't need be initialized.
+ */
+ void *options;
+
+} lzma_filter;
+
+
+/**
+ * \brief Test if the given Filter ID is supported for encoding
+ *
+ * Return true if the give Filter ID is supported for encoding by this
+ * liblzma build. Otherwise false is returned.
+ *
+ * There is no way to list which filters are available in this particular
+ * liblzma version and build. It would be useless, because the application
+ * couldn't know what kind of options the filter would need.
+ */
+extern LZMA_API(lzma_bool) lzma_filter_encoder_is_supported(lzma_vli id)
+ lzma_nothrow lzma_attr_const;
+
+
+/**
+ * \brief Test if the given Filter ID is supported for decoding
+ *
+ * Return true if the give Filter ID is supported for decoding by this
+ * liblzma build. Otherwise false is returned.
+ */
+extern LZMA_API(lzma_bool) lzma_filter_decoder_is_supported(lzma_vli id)
+ lzma_nothrow lzma_attr_const;
+
+
+/**
+ * \brief Copy the filters array
+ *
+ * Copy the Filter IDs and filter-specific options from src to dest.
+ * Up to LZMA_FILTERS_MAX filters are copied, plus the terminating
+ * .id == LZMA_VLI_UNKNOWN. Thus, dest should have at least
+ * LZMA_FILTERS_MAX + 1 elements space unless the caller knows that
+ * src is smaller than that.
+ *
+ * Unless the filter-specific options is NULL, the Filter ID has to be
+ * supported by liblzma, because liblzma needs to know the size of every
+ * filter-specific options structure. The filter-specific options are not
+ * validated. If options is NULL, any unsupported Filter IDs are copied
+ * without returning an error.
+ *
+ * Old filter-specific options in dest are not freed, so dest doesn't
+ * need to be initialized by the caller in any way.
+ *
+ * If an error occurs, memory possibly already allocated by this function
+ * is always freed.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_OPTIONS_ERROR: Unsupported Filter ID and its options
+ * is not NULL.
+ * - LZMA_PROG_ERROR: src or dest is NULL.
+ */
+extern LZMA_API(lzma_ret) lzma_filters_copy(const lzma_filter *src,
+ lzma_filter *dest, lzma_allocator *allocator) lzma_nothrow;
+
+
+/**
+ * \brief Calculate approximate memory requirements for raw encoder
+ *
+ * This function can be used to calculate the memory requirements for
+ * Block and Stream encoders too because Block and Stream encoders don't
+ * need significantly more memory than raw encoder.
+ *
+ * \param filters Array of filters terminated with
+ * .id == LZMA_VLI_UNKNOWN.
+ *
+ * \return Number of bytes of memory required for the given
+ * filter chain when encoding. If an error occurs,
+ * for example due to unsupported filter chain,
+ * UINT64_MAX is returned.
+ */
+extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Calculate approximate memory requirements for raw decoder
+ *
+ * This function can be used to calculate the memory requirements for
+ * Block and Stream decoders too because Block and Stream decoders don't
+ * need significantly more memory than raw decoder.
+ *
+ * \param filters Array of filters terminated with
+ * .id == LZMA_VLI_UNKNOWN.
+ *
+ * \return Number of bytes of memory required for the given
+ * filter chain when decoding. If an error occurs,
+ * for example due to unsupported filter chain,
+ * UINT64_MAX is returned.
+ */
+extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Initialize raw encoder
+ *
+ * This function may be useful when implementing custom file formats.
+ *
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param filters Array of lzma_filter structures. The end of the
+ * array must be marked with .id = LZMA_VLI_UNKNOWN.
+ *
+ * The `action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the
+ * filter chain supports it), or LZMA_FINISH.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_raw_encoder(
+ lzma_stream *strm, const lzma_filter *filters)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Initialize raw decoder
+ *
+ * The initialization of raw decoder goes similarly to raw encoder.
+ *
+ * The `action' with lzma_code() can be LZMA_RUN or LZMA_FINISH. Using
+ * LZMA_FINISH is not required, it is supported just for convenience.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_raw_decoder(
+ lzma_stream *strm, const lzma_filter *filters)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Update the filter chain in the encoder
+ *
+ * This function is for advanced users only. This function has two slightly
+ * different purposes:
+ *
+ * - After LZMA_FULL_FLUSH when using Stream encoder: Set a new filter
+ * chain, which will be used starting from the next Block.
+ *
+ * - After LZMA_SYNC_FLUSH using Raw, Block, or Stream encoder: Change
+ * the filter-specific options in the middle of encoding. The actual
+ * filters in the chain (Filter IDs) cannot be changed. In the future,
+ * it might become possible to change the filter options without
+ * using LZMA_SYNC_FLUSH.
+ *
+ * While rarely useful, this function may be called also when no data has
+ * been compressed yet. In that case, this function will behave as if
+ * LZMA_FULL_FLUSH (Stream encoder) or LZMA_SYNC_FLUSH (Raw or Block
+ * encoder) had been used right before calling this function.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_MEMLIMIT_ERROR
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_filters_update(
+ lzma_stream *strm, const lzma_filter *filters) lzma_nothrow;
+
+
+/**
+ * \brief Single-call raw encoder
+ *
+ * \param filters Array of lzma_filter structures. The end of the
+ * array must be marked with .id = LZMA_VLI_UNKNOWN.
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc() and free().
+ * \param in Beginning of the input buffer
+ * \param in_size Size of the input buffer
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * *out_pos is updated only if encoding succeeds.
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_BUF_ERROR: Not enough output buffer space.
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_MEM_ERROR
+ * - LZMA_DATA_ERROR
+ * - LZMA_PROG_ERROR
+ *
+ * \note There is no function to calculate how big output buffer
+ * would surely be big enough. (lzma_stream_buffer_bound()
+ * works only for lzma_stream_buffer_encode(); raw encoder
+ * won't necessarily meet that bound.)
+ */
+extern LZMA_API(lzma_ret) lzma_raw_buffer_encode(
+ const lzma_filter *filters, lzma_allocator *allocator,
+ const uint8_t *in, size_t in_size, uint8_t *out,
+ size_t *out_pos, size_t out_size) lzma_nothrow;
+
+
+/**
+ * \brief Single-call raw decoder
+ *
+ * \param filters Array of lzma_filter structures. The end of the
+ * array must be marked with .id = LZMA_VLI_UNKNOWN.
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc() and free().
+ * \param in Beginning of the input buffer
+ * \param in_pos The next byte will be read from in[*in_pos].
+ * *in_pos is updated only if decoding succeeds.
+ * \param in_size Size of the input buffer; the first byte that
+ * won't be read is in[in_size].
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * *out_pos is updated only if encoding succeeds.
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ */
+extern LZMA_API(lzma_ret) lzma_raw_buffer_decode(
+ const lzma_filter *filters, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
+
+
+/**
+ * \brief Get the size of the Filter Properties field
+ *
+ * This function may be useful when implementing custom file formats
+ * using the raw encoder and decoder.
+ *
+ * \param size Pointer to uint32_t to hold the size of the properties
+ * \param filter Filter ID and options (the size of the properties may
+ * vary depending on the options)
+ *
+ * \return - LZMA_OK
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_PROG_ERROR
+ *
+ * \note This function validates the Filter ID, but does not
+ * necessarily validate the options. Thus, it is possible
+ * that this returns LZMA_OK while the following call to
+ * lzma_properties_encode() returns LZMA_OPTIONS_ERROR.
+ */
+extern LZMA_API(lzma_ret) lzma_properties_size(
+ uint32_t *size, const lzma_filter *filter) lzma_nothrow;
+
+
+/**
+ * \brief Encode the Filter Properties field
+ *
+ * \param filter Filter ID and options
+ * \param props Buffer to hold the encoded options. The size of
+ * buffer must have been already determined with
+ * lzma_properties_size().
+ *
+ * \return - LZMA_OK
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_PROG_ERROR
+ *
+ * \note Even this function won't validate more options than actually
+ * necessary. Thus, it is possible that encoding the properties
+ * succeeds but using the same options to initialize the encoder
+ * will fail.
+ *
+ * \note If lzma_properties_size() indicated that the size
+ * of the Filter Properties field is zero, calling
+ * lzma_properties_encode() is not required, but it
+ * won't do any harm either.
+ */
+extern LZMA_API(lzma_ret) lzma_properties_encode(
+ const lzma_filter *filter, uint8_t *props) lzma_nothrow;
+
+
+/**
+ * \brief Decode the Filter Properties field
+ *
+ * \param filter filter->id must have been set to the correct
+ * Filter ID. filter->options doesn't need to be
+ * initialized (it's not freed by this function). The
+ * decoded options will be stored to filter->options.
+ * filter->options is set to NULL if there are no
+ * properties or if an error occurs.
+ * \param allocator Custom memory allocator used to allocate the
+ * options. Set to NULL to use the default malloc(),
+ * and in case of an error, also free().
+ * \param props Input buffer containing the properties.
+ * \param props_size Size of the properties. This must be the exact
+ * size; giving too much or too little input will
+ * return LZMA_OPTIONS_ERROR.
+ *
+ * \return - LZMA_OK
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_MEM_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_properties_decode(
+ lzma_filter *filter, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size) lzma_nothrow;
+
+
+/**
+ * \brief Calculate encoded size of a Filter Flags field
+ *
+ * Knowing the size of Filter Flags is useful to know when allocating
+ * memory to hold the encoded Filter Flags.
+ *
+ * \param size Pointer to integer to hold the calculated size
+ * \param filter Filter ID and associated options whose encoded
+ * size is to be calculated
+ *
+ * \return - LZMA_OK: *size set successfully. Note that this doesn't
+ * guarantee that filter->options is valid, thus
+ * lzma_filter_flags_encode() may still fail.
+ * - LZMA_OPTIONS_ERROR: Unknown Filter ID or unsupported options.
+ * - LZMA_PROG_ERROR: Invalid options
+ *
+ * \note If you need to calculate size of List of Filter Flags,
+ * you need to loop over every lzma_filter entry.
+ */
+extern LZMA_API(lzma_ret) lzma_filter_flags_size(
+ uint32_t *size, const lzma_filter *filter)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Encode Filter Flags into given buffer
+ *
+ * In contrast to some functions, this doesn't allocate the needed buffer.
+ * This is due to how this function is used internally by liblzma.
+ *
+ * \param filter Filter ID and options to be encoded
+ * \param out Beginning of the output buffer
+ * \param out_pos out[*out_pos] is the next write position. This
+ * is updated by the encoder.
+ * \param out_size out[out_size] is the first byte to not write.
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_OPTIONS_ERROR: Invalid or unsupported options.
+ * - LZMA_PROG_ERROR: Invalid options or not enough output
+ * buffer space (you should have checked it with
+ * lzma_filter_flags_size()).
+ */
+extern LZMA_API(lzma_ret) lzma_filter_flags_encode(const lzma_filter *filter,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Decode Filter Flags from given buffer
+ *
+ * The decoded result is stored into *filter. The old value of
+ * filter->options is not free()d.
+ *
+ * \return - LZMA_OK
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_MEM_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_filter_flags_decode(
+ lzma_filter *filter, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size)
+ lzma_nothrow lzma_attr_warn_unused_result;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/hardware.h b/Utilities/cmliblzma/liblzma/api/lzma/hardware.h
new file mode 100644
index 0000000000..e7dd03c3e8
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/hardware.h
@@ -0,0 +1,50 @@
+/**
+ * \file lzma/hardware.h
+ * \brief Hardware information
+ *
+ * Since liblzma can consume a lot of system resources, it also provides
+ * ways to limit the resource usage. Applications linking against liblzma
+ * need to do the actual decisions how much resources to let liblzma to use.
+ * To ease making these decisions, liblzma provides functions to find out
+ * the relevant capabilities of the underlaying hardware. Currently there
+ * is only a function to find out the amount of RAM, but in the future there
+ * will be also a function to detect how many concurrent threads the system
+ * can run.
+ *
+ * \note On some operating systems, these function may temporarily
+ * load a shared library or open file descriptor(s) to find out
+ * the requested hardware information. Unless the application
+ * assumes that specific file descriptors are not touched by
+ * other threads, this should have no effect on thread safety.
+ * Possible operations involving file descriptors will restart
+ * the syscalls if they return EINTR.
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Get the total amount of physical memory (RAM) in bytes
+ *
+ * This function may be useful when determining a reasonable memory
+ * usage limit for decompressing or how much memory it is OK to use
+ * for compressing.
+ *
+ * \return On success, the total amount of physical memory in bytes
+ * is returned. If the amount of RAM cannot be determined,
+ * zero is returned. This can happen if an error occurs
+ * or if there is no code in liblzma to detect the amount
+ * of RAM on the specific operating system.
+ */
+extern LZMA_API(uint64_t) lzma_physmem(void) lzma_nothrow;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/index.h b/Utilities/cmliblzma/liblzma/api/lzma/index.h
new file mode 100644
index 0000000000..16bacc287d
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/index.h
@@ -0,0 +1,682 @@
+/**
+ * \file lzma/index.h
+ * \brief Handling of .xz Index and related information
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Opaque data type to hold the Index(es) and other information
+ *
+ * lzma_index often holds just one .xz Index and possibly the Stream Flags
+ * of the same Stream and size of the Stream Padding field. However,
+ * multiple lzma_indexes can be concatenated with lzma_index_cat() and then
+ * there may be information about multiple Streams in the same lzma_index.
+ *
+ * Notes about thread safety: Only one thread may modify lzma_index at
+ * a time. All functions that take non-const pointer to lzma_index
+ * modify it. As long as no thread is modifying the lzma_index, getting
+ * information from the same lzma_index can be done from multiple threads
+ * at the same time with functions that take a const pointer to
+ * lzma_index or use lzma_index_iter. The same iterator must be used
+ * only by one thread at a time, of course, but there can be as many
+ * iterators for the same lzma_index as needed.
+ */
+typedef struct lzma_index_s lzma_index;
+
+
+/**
+ * \brief Iterator to get information about Blocks and Streams
+ */
+typedef struct {
+ struct {
+ /**
+ * \brief Pointer to Stream Flags
+ *
+ * This is NULL if Stream Flags have not been set for
+ * this Stream with lzma_index_stream_flags().
+ */
+ const lzma_stream_flags *flags;
+
+ const void *reserved_ptr1;
+ const void *reserved_ptr2;
+ const void *reserved_ptr3;
+
+ /**
+ * \brief Stream number in the lzma_index
+ *
+ * The first Stream is 1.
+ */
+ lzma_vli number;
+
+ /**
+ * \brief Number of Blocks in the Stream
+ *
+ * If this is zero, the block structure below has
+ * undefined values.
+ */
+ lzma_vli block_count;
+
+ /**
+ * \brief Compressed start offset of this Stream
+ *
+ * The offset is relative to the beginning of the lzma_index
+ * (i.e. usually the beginning of the .xz file).
+ */
+ lzma_vli compressed_offset;
+
+ /**
+ * \brief Uncompressed start offset of this Stream
+ *
+ * The offset is relative to the beginning of the lzma_index
+ * (i.e. usually the beginning of the .xz file).
+ */
+ lzma_vli uncompressed_offset;
+
+ /**
+ * \brief Compressed size of this Stream
+ *
+ * This includes all headers except the possible
+ * Stream Padding after this Stream.
+ */
+ lzma_vli compressed_size;
+
+ /**
+ * \brief Uncompressed size of this Stream
+ */
+ lzma_vli uncompressed_size;
+
+ /**
+ * \brief Size of Stream Padding after this Stream
+ *
+ * If it hasn't been set with lzma_index_stream_padding(),
+ * this defaults to zero. Stream Padding is always
+ * a multiple of four bytes.
+ */
+ lzma_vli padding;
+
+ lzma_vli reserved_vli1;
+ lzma_vli reserved_vli2;
+ lzma_vli reserved_vli3;
+ lzma_vli reserved_vli4;
+ } stream;
+
+ struct {
+ /**
+ * \brief Block number in the file
+ *
+ * The first Block is 1.
+ */
+ lzma_vli number_in_file;
+
+ /**
+ * \brief Compressed start offset of this Block
+ *
+ * This offset is relative to the beginning of the
+ * lzma_index (i.e. usually the beginning of the .xz file).
+ * Normally this is where you should seek in the .xz file
+ * to start decompressing this Block.
+ */
+ lzma_vli compressed_file_offset;
+
+ /**
+ * \brief Uncompressed start offset of this Block
+ *
+ * This offset is relative to the beginning of the lzma_index
+ * (i.e. usually the beginning of the .xz file).
+ *
+ * When doing random-access reading, it is possible that
+ * the target offset is not exactly at Block boundary. One
+ * will need to compare the target offset against
+ * uncompressed_file_offset or uncompressed_stream_offset,
+ * and possibly decode and throw away some amount of data
+ * before reaching the target offset.
+ */
+ lzma_vli uncompressed_file_offset;
+
+ /**
+ * \brief Block number in this Stream
+ *
+ * The first Block is 1.
+ */
+ lzma_vli number_in_stream;
+
+ /**
+ * \brief Compressed start offset of this Block
+ *
+ * This offset is relative to the beginning of the Stream
+ * containing this Block.
+ */
+ lzma_vli compressed_stream_offset;
+
+ /**
+ * \brief Uncompressed start offset of this Block
+ *
+ * This offset is relative to the beginning of the Stream
+ * containing this Block.
+ */
+ lzma_vli uncompressed_stream_offset;
+
+ /**
+ * \brief Uncompressed size of this Block
+ *
+ * You should pass this to the Block decoder if you will
+ * decode this Block. It will allow the Block decoder to
+ * validate the uncompressed size.
+ */
+ lzma_vli uncompressed_size;
+
+ /**
+ * \brief Unpadded size of this Block
+ *
+ * You should pass this to the Block decoder if you will
+ * decode this Block. It will allow the Block decoder to
+ * validate the unpadded size.
+ */
+ lzma_vli unpadded_size;
+
+ /**
+ * \brief Total compressed size
+ *
+ * This includes all headers and padding in this Block.
+ * This is useful if you need to know how many bytes
+ * the Block decoder will actually read.
+ */
+ lzma_vli total_size;
+
+ lzma_vli reserved_vli1;
+ lzma_vli reserved_vli2;
+ lzma_vli reserved_vli3;
+ lzma_vli reserved_vli4;
+
+ const void *reserved_ptr1;
+ const void *reserved_ptr2;
+ const void *reserved_ptr3;
+ const void *reserved_ptr4;
+ } block;
+
+ /*
+ * Internal data which is used to store the state of the iterator.
+ * The exact format may vary between liblzma versions, so don't
+ * touch these in any way.
+ */
+ union {
+ const void *p;
+ size_t s;
+ lzma_vli v;
+ } internal[6];
+} lzma_index_iter;
+
+
+/**
+ * \brief Operation mode for lzma_index_iter_next()
+ */
+typedef enum {
+ LZMA_INDEX_ITER_ANY = 0,
+ /**<
+ * \brief Get the next Block or Stream
+ *
+ * Go to the next Block if the current Stream has at least
+ * one Block left. Otherwise go to the next Stream even if
+ * it has no Blocks. If the Stream has no Blocks
+ * (lzma_index_iter.stream.block_count == 0),
+ * lzma_index_iter.block will have undefined values.
+ */
+
+ LZMA_INDEX_ITER_STREAM = 1,
+ /**<
+ * \brief Get the next Stream
+ *
+ * Go to the next Stream even if the current Stream has
+ * unread Blocks left. If the next Stream has at least one
+ * Block, the iterator will point to the first Block.
+ * If there are no Blocks, lzma_index_iter.block will have
+ * undefined values.
+ */
+
+ LZMA_INDEX_ITER_BLOCK = 2,
+ /**<
+ * \brief Get the next Block
+ *
+ * Go to the next Block if the current Stream has at least
+ * one Block left. If the current Stream has no Blocks left,
+ * the next Stream with at least one Block is located and
+ * the iterator will be made to point to the first Block of
+ * that Stream.
+ */
+
+ LZMA_INDEX_ITER_NONEMPTY_BLOCK = 3
+ /**<
+ * \brief Get the next non-empty Block
+ *
+ * This is like LZMA_INDEX_ITER_BLOCK except that it will
+ * skip Blocks whose Uncompressed Size is zero.
+ */
+
+} lzma_index_iter_mode;
+
+
+/**
+ * \brief Calculate memory usage of lzma_index
+ *
+ * On disk, the size of the Index field depends on both the number of Records
+ * stored and how big values the Records store (due to variable-length integer
+ * encoding). When the Index is kept in lzma_index structure, the memory usage
+ * depends only on the number of Records/Blocks stored in the Index(es), and
+ * in case of concatenated lzma_indexes, the number of Streams. The size in
+ * RAM is almost always significantly bigger than in the encoded form on disk.
+ *
+ * This function calculates an approximate amount of memory needed hold
+ * the given number of Streams and Blocks in lzma_index structure. This
+ * value may vary between CPU architectures and also between liblzma versions
+ * if the internal implementation is modified.
+ */
+extern LZMA_API(uint64_t) lzma_index_memusage(
+ lzma_vli streams, lzma_vli blocks) lzma_nothrow;
+
+
+/**
+ * \brief Calculate the memory usage of an existing lzma_index
+ *
+ * This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i),
+ * lzma_index_block_count(i)).
+ */
+extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i)
+ lzma_nothrow;
+
+
+/**
+ * \brief Allocate and initialize a new lzma_index structure
+ *
+ * \return On success, a pointer to an empty initialized lzma_index is
+ * returned. If allocation fails, NULL is returned.
+ */
+extern LZMA_API(lzma_index *) lzma_index_init(lzma_allocator *allocator)
+ lzma_nothrow;
+
+
+/**
+ * \brief Deallocate lzma_index
+ *
+ * If i is NULL, this does nothing.
+ */
+extern LZMA_API(void) lzma_index_end(lzma_index *i, lzma_allocator *allocator)
+ lzma_nothrow;
+
+
+/**
+ * \brief Add a new Block to lzma_index
+ *
+ * \param i Pointer to a lzma_index structure
+ * \param allocator Pointer to lzma_allocator, or NULL to
+ * use malloc()
+ * \param unpadded_size Unpadded Size of a Block. This can be
+ * calculated with lzma_block_unpadded_size()
+ * after encoding or decoding the Block.
+ * \param uncompressed_size Uncompressed Size of a Block. This can be
+ * taken directly from lzma_block structure
+ * after encoding or decoding the Block.
+ *
+ * Appending a new Block does not invalidate iterators. For example,
+ * if an iterator was pointing to the end of the lzma_index, after
+ * lzma_index_append() it is possible to read the next Block with
+ * an existing iterator.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
+ * Stream or size of the Index field would grow too big.
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_index_append(
+ lzma_index *i, lzma_allocator *allocator,
+ lzma_vli unpadded_size, lzma_vli uncompressed_size)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Set the Stream Flags
+ *
+ * Set the Stream Flags of the last (and typically the only) Stream
+ * in lzma_index. This can be useful when reading information from the
+ * lzma_index, because to decode Blocks, knowing the integrity check type
+ * is needed.
+ *
+ * The given Stream Flags are copied into internal preallocated structure
+ * in the lzma_index, thus the caller doesn't need to keep the *stream_flags
+ * available after calling this function.
+ *
+ * \return - LZMA_OK
+ * - LZMA_OPTIONS_ERROR: Unsupported stream_flags->version.
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_index_stream_flags(
+ lzma_index *i, const lzma_stream_flags *stream_flags)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Get the types of integrity Checks
+ *
+ * If lzma_index_stream_flags() is used to set the Stream Flags for
+ * every Stream, lzma_index_checks() can be used to get a bitmask to
+ * indicate which Check types have been used. It can be useful e.g. if
+ * showing the Check types to the user.
+ *
+ * The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10.
+ */
+extern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Set the amount of Stream Padding
+ *
+ * Set the amount of Stream Padding of the last (and typically the only)
+ * Stream in the lzma_index. This is needed when planning to do random-access
+ * reading within multiple concatenated Streams.
+ *
+ * By default, the amount of Stream Padding is assumed to be zero bytes.
+ *
+ * \return - LZMA_OK
+ * - LZMA_DATA_ERROR: The file size would grow too big.
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_index_stream_padding(
+ lzma_index *i, lzma_vli stream_padding)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Get the number of Streams
+ */
+extern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Get the number of Blocks
+ *
+ * This returns the total number of Blocks in lzma_index. To get number
+ * of Blocks in individual Streams, use lzma_index_iter.
+ */
+extern LZMA_API(lzma_vli) lzma_index_block_count(const lzma_index *i)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Get the size of the Index field as bytes
+ *
+ * This is needed to verify the Backward Size field in the Stream Footer.
+ */
+extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Get the total size of the Stream
+ *
+ * If multiple lzma_indexes have been combined, this works as if the Blocks
+ * were in a single Stream. This is useful if you are going to combine
+ * Blocks from multiple Streams into a single new Stream.
+ */
+extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Get the total size of the Blocks
+ *
+ * This doesn't include the Stream Header, Stream Footer, Stream Padding,
+ * or Index fields.
+ */
+extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Get the total size of the file
+ *
+ * When no lzma_indexes have been combined with lzma_index_cat() and there is
+ * no Stream Padding, this function is identical to lzma_index_stream_size().
+ * If multiple lzma_indexes have been combined, this includes also the headers
+ * of each separate Stream and the possible Stream Padding fields.
+ */
+extern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Get the uncompressed size of the file
+ */
+extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i)
+ lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Initialize an iterator
+ *
+ * \param iter Pointer to a lzma_index_iter structure
+ * \param i lzma_index to which the iterator will be associated
+ *
+ * This function associates the iterator with the given lzma_index, and calls
+ * lzma_index_iter_rewind() on the iterator.
+ *
+ * This function doesn't allocate any memory, thus there is no
+ * lzma_index_iter_end(). The iterator is valid as long as the
+ * associated lzma_index is valid, that is, until lzma_index_end() or
+ * using it as source in lzma_index_cat(). Specifically, lzma_index doesn't
+ * become invalid if new Blocks are added to it with lzma_index_append() or
+ * if it is used as the destination in lzma_index_cat().
+ *
+ * It is safe to make copies of an initialized lzma_index_iter, for example,
+ * to easily restart reading at some particular position.
+ */
+extern LZMA_API(void) lzma_index_iter_init(
+ lzma_index_iter *iter, const lzma_index *i) lzma_nothrow;
+
+
+/**
+ * \brief Rewind the iterator
+ *
+ * Rewind the iterator so that next call to lzma_index_iter_next() will
+ * return the first Block or Stream.
+ */
+extern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter)
+ lzma_nothrow;
+
+
+/**
+ * \brief Get the next Block or Stream
+ *
+ * \param iter Iterator initialized with lzma_index_iter_init()
+ * \param mode Specify what kind of information the caller wants
+ * to get. See lzma_index_iter_mode for details.
+ *
+ * \return If next Block or Stream matching the mode was found, *iter
+ * is updated and this function returns false. If no Block or
+ * Stream matching the mode is found, *iter is not modified
+ * and this function returns true. If mode is set to an unknown
+ * value, *iter is not modified and this function returns true.
+ */
+extern LZMA_API(lzma_bool) lzma_index_iter_next(
+ lzma_index_iter *iter, lzma_index_iter_mode mode)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Locate a Block
+ *
+ * If it is possible to seek in the .xz file, it is possible to parse
+ * the Index field(s) and use lzma_index_iter_locate() to do random-access
+ * reading with granularity of Block size.
+ *
+ * \param iter Iterator that was earlier initialized with
+ * lzma_index_iter_init().
+ * \param target Uncompressed target offset which the caller would
+ * like to locate from the Stream
+ *
+ * If the target is smaller than the uncompressed size of the Stream (can be
+ * checked with lzma_index_uncompressed_size()):
+ * - Information about the Stream and Block containing the requested
+ * uncompressed offset is stored into *iter.
+ * - Internal state of the iterator is adjusted so that
+ * lzma_index_iter_next() can be used to read subsequent Blocks or Streams.
+ * - This function returns false.
+ *
+ * If target is greater than the uncompressed size of the Stream, *iter
+ * is not modified, and this function returns true.
+ */
+extern LZMA_API(lzma_bool) lzma_index_iter_locate(
+ lzma_index_iter *iter, lzma_vli target) lzma_nothrow;
+
+
+/**
+ * \brief Concatenate lzma_indexes
+ *
+ * Concatenating lzma_indexes is useful when doing random-access reading in
+ * multi-Stream .xz file, or when combining multiple Streams into single
+ * Stream.
+ *
+ * \param dest lzma_index after which src is appended
+ * \param src lzma_index to be appended after dest. If this
+ * function succeeds, the memory allocated for src
+ * is freed or moved to be part of dest, and all
+ * iterators pointing to src will become invalid.
+ * \param allocator Custom memory allocator; can be NULL to use
+ * malloc() and free().
+ *
+ * \return - LZMA_OK: lzma_indexes were concatenated successfully.
+ * src is now a dangling pointer.
+ * - LZMA_DATA_ERROR: *dest would grow too big.
+ * - LZMA_MEM_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_index_cat(
+ lzma_index *dest, lzma_index *src, lzma_allocator *allocator)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Duplicate lzma_index
+ *
+ * \return A copy of the lzma_index, or NULL if memory allocation failed.
+ */
+extern LZMA_API(lzma_index *) lzma_index_dup(
+ const lzma_index *i, lzma_allocator *allocator)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Initialize .xz Index encoder
+ *
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param i Pointer to lzma_index which should be encoded.
+ *
+ * The valid `action' values for lzma_code() are LZMA_RUN and LZMA_FINISH.
+ * It is enough to use only one of them (you can choose freely; use LZMA_RUN
+ * to support liblzma versions older than 5.0.0).
+ *
+ * \return - LZMA_OK: Initialization succeeded, continue with lzma_code().
+ * - LZMA_MEM_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_index_encoder(
+ lzma_stream *strm, const lzma_index *i)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Initialize .xz Index decoder
+ *
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param i The decoded Index will be made available via
+ * this pointer. Initially this function will
+ * set *i to NULL (the old value is ignored). If
+ * decoding succeeds (lzma_code() returns
+ * LZMA_STREAM_END), *i will be set to point
+ * to a new lzma_index, which the application
+ * has to later free with lzma_index_end().
+ * \param memlimit How much memory the resulting lzma_index is
+ * allowed to require.
+ *
+ * The valid `action' values for lzma_code() are LZMA_RUN and LZMA_FINISH.
+ * It is enough to use only one of them (you can choose freely; use LZMA_RUN
+ * to support liblzma versions older than 5.0.0).
+ *
+ * \return - LZMA_OK: Initialization succeeded, continue with lzma_code().
+ * - LZMA_MEM_ERROR
+ * - LZMA_MEMLIMIT_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_index_decoder(
+ lzma_stream *strm, lzma_index **i, uint64_t memlimit)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Single-call .xz Index encoder
+ *
+ * \param i lzma_index to be encoded
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * *out_pos is updated only if encoding succeeds.
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_BUF_ERROR: Output buffer is too small. Use
+ * lzma_index_size() to find out how much output
+ * space is needed.
+ * - LZMA_PROG_ERROR
+ *
+ * \note This function doesn't take allocator argument since all
+ * the internal data is allocated on stack.
+ */
+extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i,
+ uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
+
+
+/**
+ * \brief Single-call .xz Index decoder
+ *
+ * \param i If decoding succeeds, *i will point to a new
+ * lzma_index, which the application has to
+ * later free with lzma_index_end(). If an error
+ * occurs, *i will be NULL. The old value of *i
+ * is always ignored and thus doesn't need to be
+ * initialized by the caller.
+ * \param memlimit Pointer to how much memory the resulting
+ * lzma_index is allowed to require. The value
+ * pointed by this pointer is modified if and only
+ * if LZMA_MEMLIMIT_ERROR is returned.
+ * \param allocator Pointer to lzma_allocator, or NULL to use malloc()
+ * \param in Beginning of the input buffer
+ * \param in_pos The next byte will be read from in[*in_pos].
+ * *in_pos is updated only if decoding succeeds.
+ * \param in_size Size of the input buffer; the first byte that
+ * won't be read is in[in_size].
+ *
+ * \return - LZMA_OK: Decoding was successful.
+ * - LZMA_MEM_ERROR
+ * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
+ * The minimum required memlimit value was stored to *memlimit.
+ * - LZMA_DATA_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i,
+ uint64_t *memlimit, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size)
+ lzma_nothrow;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/index_hash.h b/Utilities/cmliblzma/liblzma/api/lzma/index_hash.h
new file mode 100644
index 0000000000..fa2e048d55
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/index_hash.h
@@ -0,0 +1,107 @@
+/**
+ * \file lzma/index_hash.h
+ * \brief Validate Index by using a hash function
+ *
+ * Hashing makes it possible to use constant amount of memory to validate
+ * Index of arbitrary size.
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+/**
+ * \brief Opaque data type to hold the Index hash
+ */
+typedef struct lzma_index_hash_s lzma_index_hash;
+
+
+/**
+ * \brief Allocate and initialize a new lzma_index_hash structure
+ *
+ * If index_hash is NULL, a new lzma_index_hash structure is allocated,
+ * initialized, and a pointer to it returned. If allocation fails, NULL
+ * is returned.
+ *
+ * If index_hash is non-NULL, it is reinitialized and the same pointer
+ * returned. In this case, return value cannot be NULL or a different
+ * pointer than the index_hash that was given as an argument.
+ */
+extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
+ lzma_index_hash *index_hash, lzma_allocator *allocator)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Deallocate lzma_index_hash structure
+ */
+extern LZMA_API(void) lzma_index_hash_end(
+ lzma_index_hash *index_hash, lzma_allocator *allocator)
+ lzma_nothrow;
+
+
+/**
+ * \brief Add a new Record to an Index hash
+ *
+ * \param index Pointer to a lzma_index_hash structure
+ * \param unpadded_size Unpadded Size of a Block
+ * \param uncompressed_size Uncompressed Size of a Block
+ *
+ * \return - LZMA_OK
+ * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
+ * Stream or size of the Index field would grow too big.
+ * - LZMA_PROG_ERROR: Invalid arguments or this function is being
+ * used when lzma_index_hash_decode() has already been used.
+ */
+extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
+ lzma_vli unpadded_size, lzma_vli uncompressed_size)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Decode and validate the Index field
+ *
+ * After telling the sizes of all Blocks with lzma_index_hash_append(),
+ * the actual Index field is decoded with this function. Specifically,
+ * once decoding of the Index field has been started, no more Records
+ * can be added using lzma_index_hash_append().
+ *
+ * This function doesn't use lzma_stream structure to pass the input data.
+ * Instead, the input buffer is specified using three arguments. This is
+ * because it matches better the internal APIs of liblzma.
+ *
+ * \param index_hash Pointer to a lzma_index_hash structure
+ * \param in Pointer to the beginning of the input buffer
+ * \param in_pos in[*in_pos] is the next byte to process
+ * \param in_size in[in_size] is the first byte not to process
+ *
+ * \return - LZMA_OK: So far good, but more input is needed.
+ * - LZMA_STREAM_END: Index decoded successfully and it matches
+ * the Records given with lzma_index_hash_append().
+ * - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
+ * information given with lzma_index_hash_append().
+ * - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
+ const uint8_t *in, size_t *in_pos, size_t in_size)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Get the size of the Index field as bytes
+ *
+ * This is needed to verify the Backward Size field in the Stream Footer.
+ */
+extern LZMA_API(lzma_vli) lzma_index_hash_size(
+ const lzma_index_hash *index_hash)
+ lzma_nothrow lzma_attr_pure;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/lzma.h b/Utilities/cmliblzma/liblzma/api/lzma/lzma.h
new file mode 100644
index 0000000000..3f8e095f70
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/lzma.h
@@ -0,0 +1,420 @@
+/**
+ * \file lzma/lzma.h
+ * \brief LZMA1 and LZMA2 filters
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief LZMA1 Filter ID
+ *
+ * LZMA1 is the very same thing as what was called just LZMA in LZMA Utils,
+ * 7-Zip, and LZMA SDK. It's called LZMA1 here to prevent developers from
+ * accidentally using LZMA when they actually want LZMA2.
+ *
+ * LZMA1 shouldn't be used for new applications unless you _really_ know
+ * what you are doing. LZMA2 is almost always a better choice.
+ */
+#define LZMA_FILTER_LZMA1 LZMA_VLI_C(0x4000000000000001)
+
+/**
+ * \brief LZMA2 Filter ID
+ *
+ * Usually you want this instead of LZMA1. Compared to LZMA1, LZMA2 adds
+ * support for LZMA_SYNC_FLUSH, uncompressed chunks (smaller expansion
+ * when trying to compress uncompressible data), possibility to change
+ * lc/lp/pb in the middle of encoding, and some other internal improvements.
+ */
+#define LZMA_FILTER_LZMA2 LZMA_VLI_C(0x21)
+
+
+/**
+ * \brief Match finders
+ *
+ * Match finder has major effect on both speed and compression ratio.
+ * Usually hash chains are faster than binary trees.
+ *
+ * If you will use LZMA_SYNC_FLUSH often, the hash chains may be a better
+ * choice, because binary trees get much higher compression ratio penalty
+ * with LZMA_SYNC_FLUSH.
+ *
+ * The memory usage formulas are only rough estimates, which are closest to
+ * reality when dict_size is a power of two. The formulas are more complex
+ * in reality, and can also change a little between liblzma versions. Use
+ * lzma_raw_encoder_memusage() to get more accurate estimate of memory usage.
+ */
+typedef enum {
+ LZMA_MF_HC3 = 0x03,
+ /**<
+ * \brief Hash Chain with 2- and 3-byte hashing
+ *
+ * Minimum nice_len: 3
+ *
+ * Memory usage:
+ * - dict_size <= 16 MiB: dict_size * 7.5
+ * - dict_size > 16 MiB: dict_size * 5.5 + 64 MiB
+ */
+
+ LZMA_MF_HC4 = 0x04,
+ /**<
+ * \brief Hash Chain with 2-, 3-, and 4-byte hashing
+ *
+ * Minimum nice_len: 4
+ *
+ * Memory usage:
+ * - dict_size <= 32 MiB: dict_size * 7.5
+ * - dict_size > 32 MiB: dict_size * 6.5
+ */
+
+ LZMA_MF_BT2 = 0x12,
+ /**<
+ * \brief Binary Tree with 2-byte hashing
+ *
+ * Minimum nice_len: 2
+ *
+ * Memory usage: dict_size * 9.5
+ */
+
+ LZMA_MF_BT3 = 0x13,
+ /**<
+ * \brief Binary Tree with 2- and 3-byte hashing
+ *
+ * Minimum nice_len: 3
+ *
+ * Memory usage:
+ * - dict_size <= 16 MiB: dict_size * 11.5
+ * - dict_size > 16 MiB: dict_size * 9.5 + 64 MiB
+ */
+
+ LZMA_MF_BT4 = 0x14
+ /**<
+ * \brief Binary Tree with 2-, 3-, and 4-byte hashing
+ *
+ * Minimum nice_len: 4
+ *
+ * Memory usage:
+ * - dict_size <= 32 MiB: dict_size * 11.5
+ * - dict_size > 32 MiB: dict_size * 10.5
+ */
+} lzma_match_finder;
+
+
+/**
+ * \brief Test if given match finder is supported
+ *
+ * Return true if the given match finder is supported by this liblzma build.
+ * Otherwise false is returned. It is safe to call this with a value that
+ * isn't listed in lzma_match_finder enumeration; the return value will be
+ * false.
+ *
+ * There is no way to list which match finders are available in this
+ * particular liblzma version and build. It would be useless, because
+ * a new match finder, which the application developer wasn't aware,
+ * could require giving additional options to the encoder that the older
+ * match finders don't need.
+ */
+extern LZMA_API(lzma_bool) lzma_mf_is_supported(lzma_match_finder match_finder)
+ lzma_nothrow lzma_attr_const;
+
+
+/**
+ * \brief Compression modes
+ *
+ * This selects the function used to analyze the data produced by the match
+ * finder.
+ */
+typedef enum {
+ LZMA_MODE_FAST = 1,
+ /**<
+ * \brief Fast compression
+ *
+ * Fast mode is usually at its best when combined with
+ * a hash chain match finder.
+ */
+
+ LZMA_MODE_NORMAL = 2
+ /**<
+ * \brief Normal compression
+ *
+ * This is usually notably slower than fast mode. Use this
+ * together with binary tree match finders to expose the
+ * full potential of the LZMA1 or LZMA2 encoder.
+ */
+} lzma_mode;
+
+
+/**
+ * \brief Test if given compression mode is supported
+ *
+ * Return true if the given compression mode is supported by this liblzma
+ * build. Otherwise false is returned. It is safe to call this with a value
+ * that isn't listed in lzma_mode enumeration; the return value will be false.
+ *
+ * There is no way to list which modes are available in this particular
+ * liblzma version and build. It would be useless, because a new compression
+ * mode, which the application developer wasn't aware, could require giving
+ * additional options to the encoder that the older modes don't need.
+ */
+extern LZMA_API(lzma_bool) lzma_mode_is_supported(lzma_mode mode)
+ lzma_nothrow lzma_attr_const;
+
+
+/**
+ * \brief Options specific to the LZMA1 and LZMA2 filters
+ *
+ * Since LZMA1 and LZMA2 share most of the code, it's simplest to share
+ * the options structure too. For encoding, all but the reserved variables
+ * need to be initialized unless specifically mentioned otherwise.
+ * lzma_lzma_preset() can be used to get a good starting point.
+ *
+ * For raw decoding, both LZMA1 and LZMA2 need dict_size, preset_dict, and
+ * preset_dict_size (if preset_dict != NULL). LZMA1 needs also lc, lp, and pb.
+ */
+typedef struct {
+ /**
+ * \brief Dictionary size in bytes
+ *
+ * Dictionary size indicates how many bytes of the recently processed
+ * uncompressed data is kept in memory. One method to reduce size of
+ * the uncompressed data is to store distance-length pairs, which
+ * indicate what data to repeat from the dictionary buffer. Thus,
+ * the bigger the dictionary, the better the compression ratio
+ * usually is.
+ *
+ * Maximum size of the dictionary depends on multiple things:
+ * - Memory usage limit
+ * - Available address space (not a problem on 64-bit systems)
+ * - Selected match finder (encoder only)
+ *
+ * Currently the maximum dictionary size for encoding is 1.5 GiB
+ * (i.e. (UINT32_C(1) << 30) + (UINT32_C(1) << 29)) even on 64-bit
+ * systems for certain match finder implementation reasons. In the
+ * future, there may be match finders that support bigger
+ * dictionaries.
+ *
+ * Decoder already supports dictionaries up to 4 GiB - 1 B (i.e.
+ * UINT32_MAX), so increasing the maximum dictionary size of the
+ * encoder won't cause problems for old decoders.
+ *
+ * Because extremely small dictionaries sizes would have unneeded
+ * overhead in the decoder, the minimum dictionary size is 4096 bytes.
+ *
+ * \note When decoding, too big dictionary does no other harm
+ * than wasting memory.
+ */
+ uint32_t dict_size;
+# define LZMA_DICT_SIZE_MIN UINT32_C(4096)
+# define LZMA_DICT_SIZE_DEFAULT (UINT32_C(1) << 23)
+
+ /**
+ * \brief Pointer to an initial dictionary
+ *
+ * It is possible to initialize the LZ77 history window using
+ * a preset dictionary. It is useful when compressing many
+ * similar, relatively small chunks of data independently from
+ * each other. The preset dictionary should contain typical
+ * strings that occur in the files being compressed. The most
+ * probable strings should be near the end of the preset dictionary.
+ *
+ * This feature should be used only in special situations. For
+ * now, it works correctly only with raw encoding and decoding.
+ * Currently none of the container formats supported by
+ * liblzma allow preset dictionary when decoding, thus if
+ * you create a .xz or .lzma file with preset dictionary, it
+ * cannot be decoded with the regular decoder functions. In the
+ * future, the .xz format will likely get support for preset
+ * dictionary though.
+ */
+ const uint8_t *preset_dict;
+
+ /**
+ * \brief Size of the preset dictionary
+ *
+ * Specifies the size of the preset dictionary. If the size is
+ * bigger than dict_size, only the last dict_size bytes are
+ * processed.
+ *
+ * This variable is read only when preset_dict is not NULL.
+ * If preset_dict is not NULL but preset_dict_size is zero,
+ * no preset dictionary is used (identical to only setting
+ * preset_dict to NULL).
+ */
+ uint32_t preset_dict_size;
+
+ /**
+ * \brief Number of literal context bits
+ *
+ * How many of the highest bits of the previous uncompressed
+ * eight-bit byte (also known as `literal') are taken into
+ * account when predicting the bits of the next literal.
+ *
+ * E.g. in typical English text, an upper-case letter is
+ * often followed by a lower-case letter, and a lower-case
+ * letter is usually followed by another lower-case letter.
+ * In the US-ASCII character set, the highest three bits are 010
+ * for upper-case letters and 011 for lower-case letters.
+ * When lc is at least 3, the literal coding can take advantage of
+ * this property in the uncompressed data.
+ *
+ * There is a limit that applies to literal context bits and literal
+ * position bits together: lc + lp <= 4. Without this limit the
+ * decoding could become very slow, which could have security related
+ * results in some cases like email servers doing virus scanning.
+ * This limit also simplifies the internal implementation in liblzma.
+ *
+ * There may be LZMA1 streams that have lc + lp > 4 (maximum possible
+ * lc would be 8). It is not possible to decode such streams with
+ * liblzma.
+ */
+ uint32_t lc;
+# define LZMA_LCLP_MIN 0
+# define LZMA_LCLP_MAX 4
+# define LZMA_LC_DEFAULT 3
+
+ /**
+ * \brief Number of literal position bits
+ *
+ * lp affects what kind of alignment in the uncompressed data is
+ * assumed when encoding literals. A literal is a single 8-bit byte.
+ * See pb below for more information about alignment.
+ */
+ uint32_t lp;
+# define LZMA_LP_DEFAULT 0
+
+ /**
+ * \brief Number of position bits
+ *
+ * pb affects what kind of alignment in the uncompressed data is
+ * assumed in general. The default means four-byte alignment
+ * (2^ pb =2^2=4), which is often a good choice when there's
+ * no better guess.
+ *
+ * When the aligment is known, setting pb accordingly may reduce
+ * the file size a little. E.g. with text files having one-byte
+ * alignment (US-ASCII, ISO-8859-*, UTF-8), setting pb=0 can
+ * improve compression slightly. For UTF-16 text, pb=1 is a good
+ * choice. If the alignment is an odd number like 3 bytes, pb=0
+ * might be the best choice.
+ *
+ * Even though the assumed alignment can be adjusted with pb and
+ * lp, LZMA1 and LZMA2 still slightly favor 16-byte alignment.
+ * It might be worth taking into account when designing file formats
+ * that are likely to be often compressed with LZMA1 or LZMA2.
+ */
+ uint32_t pb;
+# define LZMA_PB_MIN 0
+# define LZMA_PB_MAX 4
+# define LZMA_PB_DEFAULT 2
+
+ /** Compression mode */
+ lzma_mode mode;
+
+ /**
+ * \brief Nice length of a match
+ *
+ * This determines how many bytes the encoder compares from the match
+ * candidates when looking for the best match. Once a match of at
+ * least nice_len bytes long is found, the encoder stops looking for
+ * better candidates and encodes the match. (Naturally, if the found
+ * match is actually longer than nice_len, the actual length is
+ * encoded; it's not truncated to nice_len.)
+ *
+ * Bigger values usually increase the compression ratio and
+ * compression time. For most files, 32 to 128 is a good value,
+ * which gives very good compression ratio at good speed.
+ *
+ * The exact minimum value depends on the match finder. The maximum
+ * is 273, which is the maximum length of a match that LZMA1 and
+ * LZMA2 can encode.
+ */
+ uint32_t nice_len;
+
+ /** Match finder ID */
+ lzma_match_finder mf;
+
+ /**
+ * \brief Maximum search depth in the match finder
+ *
+ * For every input byte, match finder searches through the hash chain
+ * or binary tree in a loop, each iteration going one step deeper in
+ * the chain or tree. The searching stops if
+ * - a match of at least nice_len bytes long is found;
+ * - all match candidates from the hash chain or binary tree have
+ * been checked; or
+ * - maximum search depth is reached.
+ *
+ * Maximum search depth is needed to prevent the match finder from
+ * wasting too much time in case there are lots of short match
+ * candidates. On the other hand, stopping the search before all
+ * candidates have been checked can reduce compression ratio.
+ *
+ * Setting depth to zero tells liblzma to use an automatic default
+ * value, that depends on the selected match finder and nice_len.
+ * The default is in the range [4, 200] or so (it may vary between
+ * liblzma versions).
+ *
+ * Using a bigger depth value than the default can increase
+ * compression ratio in some cases. There is no strict maximum value,
+ * but high values (thousands or millions) should be used with care:
+ * the encoder could remain fast enough with typical input, but
+ * malicious input could cause the match finder to slow down
+ * dramatically, possibly creating a denial of service attack.
+ */
+ uint32_t depth;
+
+ /*
+ * Reserved space to allow possible future extensions without
+ * breaking the ABI. You should not touch these, because the names
+ * of these variables may change. These are and will never be used
+ * with the currently supported options, so it is safe to leave these
+ * uninitialized.
+ */
+ uint32_t reserved_int1;
+ uint32_t reserved_int2;
+ uint32_t reserved_int3;
+ uint32_t reserved_int4;
+ uint32_t reserved_int5;
+ uint32_t reserved_int6;
+ uint32_t reserved_int7;
+ uint32_t reserved_int8;
+ lzma_reserved_enum reserved_enum1;
+ lzma_reserved_enum reserved_enum2;
+ lzma_reserved_enum reserved_enum3;
+ lzma_reserved_enum reserved_enum4;
+ void *reserved_ptr1;
+ void *reserved_ptr2;
+
+} lzma_options_lzma;
+
+
+/**
+ * \brief Set a compression preset to lzma_options_lzma structure
+ *
+ * 0 is the fastest and 9 is the slowest. These match the switches -0 .. -9
+ * of the xz command line tool. In addition, it is possible to bitwise-or
+ * flags to the preset. Currently only LZMA_PRESET_EXTREME is supported.
+ * The flags are defined in container.h, because the flags are used also
+ * with lzma_easy_encoder().
+ *
+ * The preset values are subject to changes between liblzma versions.
+ *
+ * This function is available only if LZMA1 or LZMA2 encoder has been enabled
+ * when building liblzma.
+ *
+ * \return On success, false is returned. If the preset is not
+ * supported, true is returned.
+ */
+extern LZMA_API(lzma_bool) lzma_lzma_preset(
+ lzma_options_lzma *options, uint32_t preset) lzma_nothrow;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/stream_flags.h b/Utilities/cmliblzma/liblzma/api/lzma/stream_flags.h
new file mode 100644
index 0000000000..bbdd408263
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/stream_flags.h
@@ -0,0 +1,223 @@
+/**
+ * \file lzma/stream_flags.h
+ * \brief .xz Stream Header and Stream Footer encoder and decoder
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Size of Stream Header and Stream Footer
+ *
+ * Stream Header and Stream Footer have the same size and they are not
+ * going to change even if a newer version of the .xz file format is
+ * developed in future.
+ */
+#define LZMA_STREAM_HEADER_SIZE 12
+
+
+/**
+ * \brief Options for encoding/decoding Stream Header and Stream Footer
+ */
+typedef struct {
+ /**
+ * \brief Stream Flags format version
+ *
+ * To prevent API and ABI breakages if new features are needed in
+ * Stream Header or Stream Footer, a version number is used to
+ * indicate which fields in this structure are in use. For now,
+ * version must always be zero. With non-zero version, the
+ * lzma_stream_header_encode() and lzma_stream_footer_encode()
+ * will return LZMA_OPTIONS_ERROR.
+ *
+ * lzma_stream_header_decode() and lzma_stream_footer_decode()
+ * will always set this to the lowest value that supports all the
+ * features indicated by the Stream Flags field. The application
+ * must check that the version number set by the decoding functions
+ * is supported by the application. Otherwise it is possible that
+ * the application will decode the Stream incorrectly.
+ */
+ uint32_t version;
+
+ /**
+ * \brief Backward Size
+ *
+ * Backward Size must be a multiple of four bytes. In this Stream
+ * format version, Backward Size is the size of the Index field.
+ *
+ * Backward Size isn't actually part of the Stream Flags field, but
+ * it is convenient to include in this structure anyway. Backward
+ * Size is present only in the Stream Footer. There is no need to
+ * initialize backward_size when encoding Stream Header.
+ *
+ * lzma_stream_header_decode() always sets backward_size to
+ * LZMA_VLI_UNKNOWN so that it is convenient to use
+ * lzma_stream_flags_compare() when both Stream Header and Stream
+ * Footer have been decoded.
+ */
+ lzma_vli backward_size;
+# define LZMA_BACKWARD_SIZE_MIN 4
+# define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34)
+
+ /**
+ * \brief Check ID
+ *
+ * This indicates the type of the integrity check calculated from
+ * uncompressed data.
+ */
+ lzma_check check;
+
+ /*
+ * Reserved space to allow possible future extensions without
+ * breaking the ABI. You should not touch these, because the
+ * names of these variables may change.
+ *
+ * (We will never be able to use all of these since Stream Flags
+ * is just two bytes plus Backward Size of four bytes. But it's
+ * nice to have the proper types when they are needed.)
+ */
+ lzma_reserved_enum reserved_enum1;
+ lzma_reserved_enum reserved_enum2;
+ lzma_reserved_enum reserved_enum3;
+ lzma_reserved_enum reserved_enum4;
+ lzma_bool reserved_bool1;
+ lzma_bool reserved_bool2;
+ lzma_bool reserved_bool3;
+ lzma_bool reserved_bool4;
+ lzma_bool reserved_bool5;
+ lzma_bool reserved_bool6;
+ lzma_bool reserved_bool7;
+ lzma_bool reserved_bool8;
+ uint32_t reserved_int1;
+ uint32_t reserved_int2;
+
+} lzma_stream_flags;
+
+
+/**
+ * \brief Encode Stream Header
+ *
+ * \param options Stream Header options to be encoded.
+ * options->backward_size is ignored and doesn't
+ * need to be initialized.
+ * \param out Beginning of the output buffer of
+ * LZMA_STREAM_HEADER_SIZE bytes.
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_OPTIONS_ERROR: options->version is not supported by
+ * this liblzma version.
+ * - LZMA_PROG_ERROR: Invalid options.
+ */
+extern LZMA_API(lzma_ret) lzma_stream_header_encode(
+ const lzma_stream_flags *options, uint8_t *out)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Encode Stream Footer
+ *
+ * \param options Stream Footer options to be encoded.
+ * \param out Beginning of the output buffer of
+ * LZMA_STREAM_HEADER_SIZE bytes.
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_OPTIONS_ERROR: options->version is not supported by
+ * this liblzma version.
+ * - LZMA_PROG_ERROR: Invalid options.
+ */
+extern LZMA_API(lzma_ret) lzma_stream_footer_encode(
+ const lzma_stream_flags *options, uint8_t *out)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Decode Stream Header
+ *
+ * \param options Target for the decoded Stream Header options.
+ * \param in Beginning of the input buffer of
+ * LZMA_STREAM_HEADER_SIZE bytes.
+ *
+ * options->backward_size is always set to LZMA_VLI_UNKNOWN. This is to
+ * help comparing Stream Flags from Stream Header and Stream Footer with
+ * lzma_stream_flags_compare().
+ *
+ * \return - LZMA_OK: Decoding was successful.
+ * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
+ * buffer cannot be Stream Header.
+ * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the header
+ * is corrupt.
+ * - LZMA_OPTIONS_ERROR: Unsupported options are present
+ * in the header.
+ *
+ * \note When decoding .xz files that contain multiple Streams, it may
+ * make sense to print "file format not recognized" only if
+ * decoding of the Stream Header of the _first_ Stream gives
+ * LZMA_FORMAT_ERROR. If non-first Stream Header gives
+ * LZMA_FORMAT_ERROR, the message used for LZMA_DATA_ERROR is
+ * probably more appropriate.
+ *
+ * For example, Stream decoder in liblzma uses LZMA_DATA_ERROR if
+ * LZMA_FORMAT_ERROR is returned by lzma_stream_header_decode()
+ * when decoding non-first Stream.
+ */
+extern LZMA_API(lzma_ret) lzma_stream_header_decode(
+ lzma_stream_flags *options, const uint8_t *in)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Decode Stream Footer
+ *
+ * \param options Target for the decoded Stream Header options.
+ * \param in Beginning of the input buffer of
+ * LZMA_STREAM_HEADER_SIZE bytes.
+ *
+ * \return - LZMA_OK: Decoding was successful.
+ * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
+ * buffer cannot be Stream Footer.
+ * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the Stream Footer
+ * is corrupt.
+ * - LZMA_OPTIONS_ERROR: Unsupported options are present
+ * in Stream Footer.
+ *
+ * \note If Stream Header was already decoded successfully, but
+ * decoding Stream Footer returns LZMA_FORMAT_ERROR, the
+ * application should probably report some other error message
+ * than "file format not recognized", since the file more likely
+ * is corrupt (possibly truncated). Stream decoder in liblzma
+ * uses LZMA_DATA_ERROR in this situation.
+ */
+extern LZMA_API(lzma_ret) lzma_stream_footer_decode(
+ lzma_stream_flags *options, const uint8_t *in)
+ lzma_nothrow lzma_attr_warn_unused_result;
+
+
+/**
+ * \brief Compare two lzma_stream_flags structures
+ *
+ * backward_size values are compared only if both are not
+ * LZMA_VLI_UNKNOWN.
+ *
+ * \return - LZMA_OK: Both are equal. If either had backward_size set
+ * to LZMA_VLI_UNKNOWN, backward_size values were not
+ * compared or validated.
+ * - LZMA_DATA_ERROR: The structures differ.
+ * - LZMA_OPTIONS_ERROR: version in either structure is greater
+ * than the maximum supported version (currently zero).
+ * - LZMA_PROG_ERROR: Invalid value, e.g. invalid check or
+ * backward_size.
+ */
+extern LZMA_API(lzma_ret) lzma_stream_flags_compare(
+ const lzma_stream_flags *a, const lzma_stream_flags *b)
+ lzma_nothrow lzma_attr_pure;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/version.h b/Utilities/cmliblzma/liblzma/api/lzma/version.h
new file mode 100644
index 0000000000..66e93965dc
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/version.h
@@ -0,0 +1,121 @@
+/**
+ * \file lzma/version.h
+ * \brief Version number
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/*
+ * Version number split into components
+ */
+#define LZMA_VERSION_MAJOR 5
+#define LZMA_VERSION_MINOR 0
+#define LZMA_VERSION_PATCH 5
+#define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE
+
+#ifndef LZMA_VERSION_COMMIT
+# define LZMA_VERSION_COMMIT ""
+#endif
+
+
+/*
+ * Map symbolic stability levels to integers.
+ */
+#define LZMA_VERSION_STABILITY_ALPHA 0
+#define LZMA_VERSION_STABILITY_BETA 1
+#define LZMA_VERSION_STABILITY_STABLE 2
+
+
+/**
+ * \brief Compile-time version number
+ *
+ * The version number is of format xyyyzzzs where
+ * - x = major
+ * - yyy = minor
+ * - zzz = revision
+ * - s indicates stability: 0 = alpha, 1 = beta, 2 = stable
+ *
+ * The same xyyyzzz triplet is never reused with different stability levels.
+ * For example, if 5.1.0alpha has been released, there will never be 5.1.0beta
+ * or 5.1.0 stable.
+ *
+ * \note The version number of liblzma has nothing to with
+ * the version number of Igor Pavlov's LZMA SDK.
+ */
+#define LZMA_VERSION (LZMA_VERSION_MAJOR * UINT32_C(10000000) \
+ + LZMA_VERSION_MINOR * UINT32_C(10000) \
+ + LZMA_VERSION_PATCH * UINT32_C(10) \
+ + LZMA_VERSION_STABILITY)
+
+
+/*
+ * Macros to construct the compile-time version string
+ */
+#if LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_ALPHA
+# define LZMA_VERSION_STABILITY_STRING "alpha"
+#elif LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_BETA
+# define LZMA_VERSION_STABILITY_STRING "beta"
+#elif LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_STABLE
+# define LZMA_VERSION_STABILITY_STRING ""
+#else
+# error Incorrect LZMA_VERSION_STABILITY
+#endif
+
+#define LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit) \
+ #major "." #minor "." #patch stability commit
+
+#define LZMA_VERSION_STRING_C(major, minor, patch, stability, commit) \
+ LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit)
+
+
+/**
+ * \brief Compile-time version as a string
+ *
+ * This can be for example "4.999.5alpha", "4.999.8beta", or "5.0.0" (stable
+ * versions don't have any "stable" suffix). In future, a snapshot built
+ * from source code repository may include an additional suffix, for example
+ * "4.999.8beta-21-g1d92". The commit ID won't be available in numeric form
+ * in LZMA_VERSION macro.
+ */
+#define LZMA_VERSION_STRING LZMA_VERSION_STRING_C( \
+ LZMA_VERSION_MAJOR, LZMA_VERSION_MINOR, \
+ LZMA_VERSION_PATCH, LZMA_VERSION_STABILITY_STRING, \
+ LZMA_VERSION_COMMIT)
+
+
+/* #ifndef is needed for use with windres (MinGW or Cygwin). */
+#ifndef LZMA_H_INTERNAL_RC
+
+/**
+ * \brief Run-time version number as an integer
+ *
+ * Return the value of LZMA_VERSION macro at the compile time of liblzma.
+ * This allows the application to compare if it was built against the same,
+ * older, or newer version of liblzma that is currently running.
+ */
+extern LZMA_API(uint32_t) lzma_version_number(void)
+ lzma_nothrow lzma_attr_const;
+
+
+/**
+ * \brief Run-time version as a string
+ *
+ * This function may be useful if you want to display which version of
+ * liblzma your application is currently using.
+ */
+extern LZMA_API(const char *) lzma_version_string(void)
+ lzma_nothrow lzma_attr_const;
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/vli.h b/Utilities/cmliblzma/liblzma/api/lzma/vli.h
new file mode 100644
index 0000000000..9ad13f2e2f
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/api/lzma/vli.h
@@ -0,0 +1,166 @@
+/**
+ * \file lzma/vli.h
+ * \brief Variable-length integer handling
+ *
+ * In the .xz format, most integers are encoded in a variable-length
+ * representation, which is sometimes called little endian base-128 encoding.
+ * This saves space when smaller values are more likely than bigger values.
+ *
+ * The encoding scheme encodes seven bits to every byte, using minimum
+ * number of bytes required to represent the given value. Encodings that use
+ * non-minimum number of bytes are invalid, thus every integer has exactly
+ * one encoded representation. The maximum number of bits in a VLI is 63,
+ * thus the vli argument must be less than or equal to UINT64_MAX / 2. You
+ * should use LZMA_VLI_MAX for clarity.
+ */
+
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * See ../lzma.h for information about liblzma as a whole.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Maximum supported value of a variable-length integer
+ */
+#define LZMA_VLI_MAX (UINT64_MAX / 2)
+
+/**
+ * \brief VLI value to denote that the value is unknown
+ */
+#define LZMA_VLI_UNKNOWN UINT64_MAX
+
+/**
+ * \brief Maximum supported encoded length of variable length integers
+ */
+#define LZMA_VLI_BYTES_MAX 9
+
+/**
+ * \brief VLI constant suffix
+ */
+#define LZMA_VLI_C(n) UINT64_C(n)
+
+
+/**
+ * \brief Variable-length integer type
+ *
+ * Valid VLI values are in the range [0, LZMA_VLI_MAX]. Unknown value is
+ * indicated with LZMA_VLI_UNKNOWN, which is the maximum value of the
+ * underlaying integer type.
+ *
+ * lzma_vli will be uint64_t for the foreseeable future. If a bigger size
+ * is needed in the future, it is guaranteed that 2 * LZMA_VLI_MAX will
+ * not overflow lzma_vli. This simplifies integer overflow detection.
+ */
+typedef uint64_t lzma_vli;
+
+
+/**
+ * \brief Validate a variable-length integer
+ *
+ * This is useful to test that application has given acceptable values
+ * for example in the uncompressed_size and compressed_size variables.
+ *
+ * \return True if the integer is representable as VLI or if it
+ * indicates unknown value.
+ */
+#define lzma_vli_is_valid(vli) \
+ ((vli) <= LZMA_VLI_MAX || (vli) == LZMA_VLI_UNKNOWN)
+
+
+/**
+ * \brief Encode a variable-length integer
+ *
+ * This function has two modes: single-call and multi-call. Single-call mode
+ * encodes the whole integer at once; it is an error if the output buffer is
+ * too small. Multi-call mode saves the position in *vli_pos, and thus it is
+ * possible to continue encoding if the buffer becomes full before the whole
+ * integer has been encoded.
+ *
+ * \param vli Integer to be encoded
+ * \param vli_pos How many VLI-encoded bytes have already been written
+ * out. When starting to encode a new integer in
+ * multi-call mode, *vli_pos must be set to zero.
+ * To use single-call encoding, set vli_pos to NULL.
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ *
+ * \return Slightly different return values are used in multi-call and
+ * single-call modes.
+ *
+ * Single-call (vli_pos == NULL):
+ * - LZMA_OK: Integer successfully encoded.
+ * - LZMA_PROG_ERROR: Arguments are not sane. This can be due
+ * to too little output space; single-call mode doesn't use
+ * LZMA_BUF_ERROR, since the application should have checked
+ * the encoded size with lzma_vli_size().
+ *
+ * Multi-call (vli_pos != NULL):
+ * - LZMA_OK: So far all OK, but the integer is not
+ * completely written out yet.
+ * - LZMA_STREAM_END: Integer successfully encoded.
+ * - LZMA_BUF_ERROR: No output space was provided.
+ * - LZMA_PROG_ERROR: Arguments are not sane.
+ */
+extern LZMA_API(lzma_ret) lzma_vli_encode(lzma_vli vli, size_t *vli_pos,
+ uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
+
+
+/**
+ * \brief Decode a variable-length integer
+ *
+ * Like lzma_vli_encode(), this function has single-call and multi-call modes.
+ *
+ * \param vli Pointer to decoded integer. The decoder will
+ * initialize it to zero when *vli_pos == 0, so
+ * application isn't required to initialize *vli.
+ * \param vli_pos How many bytes have already been decoded. When
+ * starting to decode a new integer in multi-call
+ * mode, *vli_pos must be initialized to zero. To
+ * use single-call decoding, set vli_pos to NULL.
+ * \param in Beginning of the input buffer
+ * \param in_pos The next byte will be read from in[*in_pos].
+ * \param in_size Size of the input buffer; the first byte that
+ * won't be read is in[in_size].
+ *
+ * \return Slightly different return values are used in multi-call and
+ * single-call modes.
+ *
+ * Single-call (vli_pos == NULL):
+ * - LZMA_OK: Integer successfully decoded.
+ * - LZMA_DATA_ERROR: Integer is corrupt. This includes hitting
+ * the end of the input buffer before the whole integer was
+ * decoded; providing no input at all will use LZMA_DATA_ERROR.
+ * - LZMA_PROG_ERROR: Arguments are not sane.
+ *
+ * Multi-call (vli_pos != NULL):
+ * - LZMA_OK: So far all OK, but the integer is not
+ * completely decoded yet.
+ * - LZMA_STREAM_END: Integer successfully decoded.
+ * - LZMA_DATA_ERROR: Integer is corrupt.
+ * - LZMA_BUF_ERROR: No input was provided.
+ * - LZMA_PROG_ERROR: Arguments are not sane.
+ */
+extern LZMA_API(lzma_ret) lzma_vli_decode(lzma_vli *vli, size_t *vli_pos,
+ const uint8_t *in, size_t *in_pos, size_t in_size)
+ lzma_nothrow;
+
+
+/**
+ * \brief Get the number of bytes required to encode a VLI
+ *
+ * \return Number of bytes on success (1-9). If vli isn't valid,
+ * zero is returned.
+ */
+extern LZMA_API(uint32_t) lzma_vli_size(lzma_vli vli)
+ lzma_nothrow lzma_attr_pure;
diff --git a/Utilities/cmliblzma/liblzma/check/check.c b/Utilities/cmliblzma/liblzma/check/check.c
new file mode 100644
index 0000000000..979b0a8180
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/check.c
@@ -0,0 +1,174 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file check.c
+/// \brief Single API to access different integrity checks
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "check.h"
+
+
+extern LZMA_API(lzma_bool)
+lzma_check_is_supported(lzma_check type)
+{
+ static const lzma_bool available_checks[LZMA_CHECK_ID_MAX + 1] = {
+ true, // LZMA_CHECK_NONE
+
+#ifdef HAVE_CHECK_CRC32
+ true,
+#else
+ false,
+#endif
+
+ false, // Reserved
+ false, // Reserved
+
+#ifdef HAVE_CHECK_CRC64
+ true,
+#else
+ false,
+#endif
+
+ false, // Reserved
+ false, // Reserved
+ false, // Reserved
+ false, // Reserved
+ false, // Reserved
+
+#ifdef HAVE_CHECK_SHA256
+ true,
+#else
+ false,
+#endif
+
+ false, // Reserved
+ false, // Reserved
+ false, // Reserved
+ false, // Reserved
+ false, // Reserved
+ };
+
+ if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
+ return false;
+
+ return available_checks[(unsigned int)(type)];
+}
+
+
+extern LZMA_API(uint32_t)
+lzma_check_size(lzma_check type)
+{
+ // See file-format.txt section 2.1.1.2.
+ static const uint8_t check_sizes[LZMA_CHECK_ID_MAX + 1] = {
+ 0,
+ 4, 4, 4,
+ 8, 8, 8,
+ 16, 16, 16,
+ 32, 32, 32,
+ 64, 64, 64
+ };
+
+ if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
+ return UINT32_MAX;
+
+ return check_sizes[(unsigned int)(type)];
+}
+
+
+extern void
+lzma_check_init(lzma_check_state *check, lzma_check type)
+{
+ switch (type) {
+ case LZMA_CHECK_NONE:
+ break;
+
+#ifdef HAVE_CHECK_CRC32
+ case LZMA_CHECK_CRC32:
+ check->state.crc32 = 0;
+ break;
+#endif
+
+#ifdef HAVE_CHECK_CRC64
+ case LZMA_CHECK_CRC64:
+ check->state.crc64 = 0;
+ break;
+#endif
+
+#ifdef HAVE_CHECK_SHA256
+ case LZMA_CHECK_SHA256:
+ lzma_sha256_init(check);
+ break;
+#endif
+
+ default:
+ break;
+ }
+
+ return;
+}
+
+
+extern void
+lzma_check_update(lzma_check_state *check, lzma_check type,
+ const uint8_t *buf, size_t size)
+{
+ switch (type) {
+#ifdef HAVE_CHECK_CRC32
+ case LZMA_CHECK_CRC32:
+ check->state.crc32 = lzma_crc32(buf, size, check->state.crc32);
+ break;
+#endif
+
+#ifdef HAVE_CHECK_CRC64
+ case LZMA_CHECK_CRC64:
+ check->state.crc64 = lzma_crc64(buf, size, check->state.crc64);
+ break;
+#endif
+
+#ifdef HAVE_CHECK_SHA256
+ case LZMA_CHECK_SHA256:
+ lzma_sha256_update(buf, size, check);
+ break;
+#endif
+
+ default:
+ break;
+ }
+
+ return;
+}
+
+
+extern void
+lzma_check_finish(lzma_check_state *check, lzma_check type)
+{
+ switch (type) {
+#ifdef HAVE_CHECK_CRC32
+ case LZMA_CHECK_CRC32:
+ check->buffer.u32[0] = conv32le(check->state.crc32);
+ break;
+#endif
+
+#ifdef HAVE_CHECK_CRC64
+ case LZMA_CHECK_CRC64:
+ check->buffer.u64[0] = conv64le(check->state.crc64);
+ break;
+#endif
+
+#ifdef HAVE_CHECK_SHA256
+ case LZMA_CHECK_SHA256:
+ lzma_sha256_finish(check);
+ break;
+#endif
+
+ default:
+ break;
+ }
+
+ return;
+}
diff --git a/Utilities/cmliblzma/liblzma/check/check.h b/Utilities/cmliblzma/liblzma/check/check.h
new file mode 100644
index 0000000000..e100d2b853
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/check.h
@@ -0,0 +1,95 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file check.h
+/// \brief Internal API to different integrity check functions
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_CHECK_H
+#define LZMA_CHECK_H
+
+#include "common.h"
+
+
+// Index hashing needs the best possible hash function (preferably
+// a cryptographic hash) for maximum reliability.
+#if defined(HAVE_CHECK_SHA256)
+# define LZMA_CHECK_BEST LZMA_CHECK_SHA256
+#elif defined(HAVE_CHECK_CRC64)
+# define LZMA_CHECK_BEST LZMA_CHECK_CRC64
+#else
+# define LZMA_CHECK_BEST LZMA_CHECK_CRC32
+#endif
+
+
+/// \brief Structure to hold internal state of the check being calculated
+///
+/// \note This is not in the public API because this structure may
+/// change in future if new integrity check algorithms are added.
+typedef struct {
+ /// Buffer to hold the final result and a temporary buffer for SHA256.
+ union {
+ uint8_t u8[64];
+ uint32_t u32[16];
+ uint64_t u64[8];
+ } buffer;
+
+ /// Check-specific data
+ union {
+ uint32_t crc32;
+ uint64_t crc64;
+
+ struct {
+ /// Internal state
+ uint32_t state[8];
+
+ /// Size of the message excluding padding
+ uint64_t size;
+ } sha256;
+ } state;
+
+} lzma_check_state;
+
+
+/// lzma_crc32_table[0] is needed by LZ encoder so we need to keep
+/// the array two-dimensional.
+#ifdef HAVE_SMALL
+extern uint32_t lzma_crc32_table[1][256];
+extern void lzma_crc32_init(void);
+#else
+extern const uint32_t lzma_crc32_table[8][256];
+extern const uint64_t lzma_crc64_table[4][256];
+#endif
+
+
+/// \brief Initialize *check depending on type
+///
+/// \return LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not
+/// supported by the current version or build of liblzma.
+/// LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
+extern void lzma_check_init(lzma_check_state *check, lzma_check type);
+
+/// Update the check state
+extern void lzma_check_update(lzma_check_state *check, lzma_check type,
+ const uint8_t *buf, size_t size);
+
+/// Finish the check calculation and store the result to check->buffer.u8.
+extern void lzma_check_finish(lzma_check_state *check, lzma_check type);
+
+
+/// Prepare SHA-256 state for new input.
+extern void lzma_sha256_init(lzma_check_state *check);
+
+/// Update the SHA-256 hash state
+extern void lzma_sha256_update(
+ const uint8_t *buf, size_t size, lzma_check_state *check);
+
+/// Finish the SHA-256 calculation and store the result to check->buffer.u8.
+extern void lzma_sha256_finish(lzma_check_state *check);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/check/crc32_fast.c b/Utilities/cmliblzma/liblzma/check/crc32_fast.c
new file mode 100644
index 0000000000..13f65b4978
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc32_fast.c
@@ -0,0 +1,86 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file crc32.c
+/// \brief CRC32 calculation
+///
+/// Calculate the CRC32 using the slice-by-eight algorithm.
+/// It is explained in this document:
+/// http://www.intel.com/technology/comms/perfnet/download/CRC_generators.pdf
+/// The code in this file is not the same as in Intel's paper, but
+/// the basic principle is identical.
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "check.h"
+#include "crc_macros.h"
+
+
+// If you make any changes, do some bench marking! Seemingly unrelated
+// changes can very easily ruin the performance (and very probably is
+// very compiler dependent).
+extern LZMA_API(uint32_t)
+lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
+{
+ crc = ~crc;
+
+#ifdef WORDS_BIGENDIAN
+ crc = bswap32(crc);
+#endif
+
+ if (size > 8) {
+ const uint8_t * limit;
+
+ // Fix the alignment, if needed. The if statement above
+ // ensures that this won't read past the end of buf[].
+ while ((uintptr_t)(buf) & 7) {
+ crc = lzma_crc32_table[0][*buf++ ^ A(crc)] ^ S8(crc);
+ --size;
+ }
+
+ // Calculate the position where to stop.
+ limit = buf + (size & ~(size_t)(7));
+
+ // Calculate how many bytes must be calculated separately
+ // before returning the result.
+ size &= (size_t)(7);
+
+ // Calculate the CRC32 using the slice-by-eight algorithm.
+ while (buf < limit) {
+ uint32_t tmp;
+
+ crc ^= *(const uint32_t *)(buf);
+ buf += 4;
+
+ crc = lzma_crc32_table[7][A(crc)]
+ ^ lzma_crc32_table[6][B(crc)]
+ ^ lzma_crc32_table[5][C(crc)]
+ ^ lzma_crc32_table[4][D(crc)];
+
+ tmp = *(const uint32_t *)(buf);
+ buf += 4;
+
+ // At least with some compilers, it is critical for
+ // performance, that the crc variable is XORed
+ // between the two table-lookup pairs.
+ crc = lzma_crc32_table[3][A(tmp)]
+ ^ lzma_crc32_table[2][B(tmp)]
+ ^ crc
+ ^ lzma_crc32_table[1][C(tmp)]
+ ^ lzma_crc32_table[0][D(tmp)];
+ }
+ }
+
+ while (size-- != 0)
+ crc = lzma_crc32_table[0][*buf++ ^ A(crc)] ^ S8(crc);
+
+#ifdef WORDS_BIGENDIAN
+ crc = bswap32(crc);
+#endif
+
+ return ~crc;
+}
diff --git a/Utilities/cmliblzma/liblzma/check/crc32_small.c b/Utilities/cmliblzma/liblzma/check/crc32_small.c
new file mode 100644
index 0000000000..5f8a328687
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc32_small.c
@@ -0,0 +1,61 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file crc32_small.c
+/// \brief CRC32 calculation (size-optimized)
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "check.h"
+
+
+uint32_t lzma_crc32_table[1][256];
+
+
+static void
+crc32_init(void)
+{
+ static const uint32_t poly32 = UINT32_C(0xEDB88320);
+
+ for (size_t b = 0; b < 256; ++b) {
+ uint32_t r = b;
+ for (size_t i = 0; i < 8; ++i) {
+ if (r & 1)
+ r = (r >> 1) ^ poly32;
+ else
+ r >>= 1;
+ }
+
+ lzma_crc32_table[0][b] = r;
+ }
+
+ return;
+}
+
+
+extern void
+lzma_crc32_init(void)
+{
+ mythread_once(crc32_init);
+ return;
+}
+
+
+extern LZMA_API(uint32_t)
+lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
+{
+ lzma_crc32_init();
+
+ crc = ~crc;
+
+ while (size != 0) {
+ crc = lzma_crc32_table[0][*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
+ --size;
+ }
+
+ return ~crc;
+}
diff --git a/Utilities/cmliblzma/liblzma/check/crc32_table.c b/Utilities/cmliblzma/liblzma/check/crc32_table.c
new file mode 100644
index 0000000000..368874eb79
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc32_table.c
@@ -0,0 +1,19 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file crc32_table.c
+/// \brief Precalculated CRC32 table with correct endianness
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+
+#ifdef WORDS_BIGENDIAN
+# include "crc32_table_be.h"
+#else
+# include "crc32_table_le.h"
+#endif
diff --git a/Utilities/cmliblzma/liblzma/check/crc32_table_be.h b/Utilities/cmliblzma/liblzma/check/crc32_table_be.h
new file mode 100644
index 0000000000..c483cb670d
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc32_table_be.h
@@ -0,0 +1,525 @@
+/* This file has been automatically generated by crc32_tablegen.c. */
+
+const uint32_t lzma_crc32_table[8][256] = {
+ {
+ 0x00000000, 0x96300777, 0x2C610EEE, 0xBA510999,
+ 0x19C46D07, 0x8FF46A70, 0x35A563E9, 0xA395649E,
+ 0x3288DB0E, 0xA4B8DC79, 0x1EE9D5E0, 0x88D9D297,
+ 0x2B4CB609, 0xBD7CB17E, 0x072DB8E7, 0x911DBF90,
+ 0x6410B71D, 0xF220B06A, 0x4871B9F3, 0xDE41BE84,
+ 0x7DD4DA1A, 0xEBE4DD6D, 0x51B5D4F4, 0xC785D383,
+ 0x56986C13, 0xC0A86B64, 0x7AF962FD, 0xECC9658A,
+ 0x4F5C0114, 0xD96C0663, 0x633D0FFA, 0xF50D088D,
+ 0xC8206E3B, 0x5E10694C, 0xE44160D5, 0x727167A2,
+ 0xD1E4033C, 0x47D4044B, 0xFD850DD2, 0x6BB50AA5,
+ 0xFAA8B535, 0x6C98B242, 0xD6C9BBDB, 0x40F9BCAC,
+ 0xE36CD832, 0x755CDF45, 0xCF0DD6DC, 0x593DD1AB,
+ 0xAC30D926, 0x3A00DE51, 0x8051D7C8, 0x1661D0BF,
+ 0xB5F4B421, 0x23C4B356, 0x9995BACF, 0x0FA5BDB8,
+ 0x9EB80228, 0x0888055F, 0xB2D90CC6, 0x24E90BB1,
+ 0x877C6F2F, 0x114C6858, 0xAB1D61C1, 0x3D2D66B6,
+ 0x9041DC76, 0x0671DB01, 0xBC20D298, 0x2A10D5EF,
+ 0x8985B171, 0x1FB5B606, 0xA5E4BF9F, 0x33D4B8E8,
+ 0xA2C90778, 0x34F9000F, 0x8EA80996, 0x18980EE1,
+ 0xBB0D6A7F, 0x2D3D6D08, 0x976C6491, 0x015C63E6,
+ 0xF4516B6B, 0x62616C1C, 0xD8306585, 0x4E0062F2,
+ 0xED95066C, 0x7BA5011B, 0xC1F40882, 0x57C40FF5,
+ 0xC6D9B065, 0x50E9B712, 0xEAB8BE8B, 0x7C88B9FC,
+ 0xDF1DDD62, 0x492DDA15, 0xF37CD38C, 0x654CD4FB,
+ 0x5861B24D, 0xCE51B53A, 0x7400BCA3, 0xE230BBD4,
+ 0x41A5DF4A, 0xD795D83D, 0x6DC4D1A4, 0xFBF4D6D3,
+ 0x6AE96943, 0xFCD96E34, 0x468867AD, 0xD0B860DA,
+ 0x732D0444, 0xE51D0333, 0x5F4C0AAA, 0xC97C0DDD,
+ 0x3C710550, 0xAA410227, 0x10100BBE, 0x86200CC9,
+ 0x25B56857, 0xB3856F20, 0x09D466B9, 0x9FE461CE,
+ 0x0EF9DE5E, 0x98C9D929, 0x2298D0B0, 0xB4A8D7C7,
+ 0x173DB359, 0x810DB42E, 0x3B5CBDB7, 0xAD6CBAC0,
+ 0x2083B8ED, 0xB6B3BF9A, 0x0CE2B603, 0x9AD2B174,
+ 0x3947D5EA, 0xAF77D29D, 0x1526DB04, 0x8316DC73,
+ 0x120B63E3, 0x843B6494, 0x3E6A6D0D, 0xA85A6A7A,
+ 0x0BCF0EE4, 0x9DFF0993, 0x27AE000A, 0xB19E077D,
+ 0x44930FF0, 0xD2A30887, 0x68F2011E, 0xFEC20669,
+ 0x5D5762F7, 0xCB676580, 0x71366C19, 0xE7066B6E,
+ 0x761BD4FE, 0xE02BD389, 0x5A7ADA10, 0xCC4ADD67,
+ 0x6FDFB9F9, 0xF9EFBE8E, 0x43BEB717, 0xD58EB060,
+ 0xE8A3D6D6, 0x7E93D1A1, 0xC4C2D838, 0x52F2DF4F,
+ 0xF167BBD1, 0x6757BCA6, 0xDD06B53F, 0x4B36B248,
+ 0xDA2B0DD8, 0x4C1B0AAF, 0xF64A0336, 0x607A0441,
+ 0xC3EF60DF, 0x55DF67A8, 0xEF8E6E31, 0x79BE6946,
+ 0x8CB361CB, 0x1A8366BC, 0xA0D26F25, 0x36E26852,
+ 0x95770CCC, 0x03470BBB, 0xB9160222, 0x2F260555,
+ 0xBE3BBAC5, 0x280BBDB2, 0x925AB42B, 0x046AB35C,
+ 0xA7FFD7C2, 0x31CFD0B5, 0x8B9ED92C, 0x1DAEDE5B,
+ 0xB0C2649B, 0x26F263EC, 0x9CA36A75, 0x0A936D02,
+ 0xA906099C, 0x3F360EEB, 0x85670772, 0x13570005,
+ 0x824ABF95, 0x147AB8E2, 0xAE2BB17B, 0x381BB60C,
+ 0x9B8ED292, 0x0DBED5E5, 0xB7EFDC7C, 0x21DFDB0B,
+ 0xD4D2D386, 0x42E2D4F1, 0xF8B3DD68, 0x6E83DA1F,
+ 0xCD16BE81, 0x5B26B9F6, 0xE177B06F, 0x7747B718,
+ 0xE65A0888, 0x706A0FFF, 0xCA3B0666, 0x5C0B0111,
+ 0xFF9E658F, 0x69AE62F8, 0xD3FF6B61, 0x45CF6C16,
+ 0x78E20AA0, 0xEED20DD7, 0x5483044E, 0xC2B30339,
+ 0x612667A7, 0xF71660D0, 0x4D476949, 0xDB776E3E,
+ 0x4A6AD1AE, 0xDC5AD6D9, 0x660BDF40, 0xF03BD837,
+ 0x53AEBCA9, 0xC59EBBDE, 0x7FCFB247, 0xE9FFB530,
+ 0x1CF2BDBD, 0x8AC2BACA, 0x3093B353, 0xA6A3B424,
+ 0x0536D0BA, 0x9306D7CD, 0x2957DE54, 0xBF67D923,
+ 0x2E7A66B3, 0xB84A61C4, 0x021B685D, 0x942B6F2A,
+ 0x37BE0BB4, 0xA18E0CC3, 0x1BDF055A, 0x8DEF022D
+ }, {
+ 0x00000000, 0x41311B19, 0x82623632, 0xC3532D2B,
+ 0x04C56C64, 0x45F4777D, 0x86A75A56, 0xC796414F,
+ 0x088AD9C8, 0x49BBC2D1, 0x8AE8EFFA, 0xCBD9F4E3,
+ 0x0C4FB5AC, 0x4D7EAEB5, 0x8E2D839E, 0xCF1C9887,
+ 0x5112C24A, 0x1023D953, 0xD370F478, 0x9241EF61,
+ 0x55D7AE2E, 0x14E6B537, 0xD7B5981C, 0x96848305,
+ 0x59981B82, 0x18A9009B, 0xDBFA2DB0, 0x9ACB36A9,
+ 0x5D5D77E6, 0x1C6C6CFF, 0xDF3F41D4, 0x9E0E5ACD,
+ 0xA2248495, 0xE3159F8C, 0x2046B2A7, 0x6177A9BE,
+ 0xA6E1E8F1, 0xE7D0F3E8, 0x2483DEC3, 0x65B2C5DA,
+ 0xAAAE5D5D, 0xEB9F4644, 0x28CC6B6F, 0x69FD7076,
+ 0xAE6B3139, 0xEF5A2A20, 0x2C09070B, 0x6D381C12,
+ 0xF33646DF, 0xB2075DC6, 0x715470ED, 0x30656BF4,
+ 0xF7F32ABB, 0xB6C231A2, 0x75911C89, 0x34A00790,
+ 0xFBBC9F17, 0xBA8D840E, 0x79DEA925, 0x38EFB23C,
+ 0xFF79F373, 0xBE48E86A, 0x7D1BC541, 0x3C2ADE58,
+ 0x054F79F0, 0x447E62E9, 0x872D4FC2, 0xC61C54DB,
+ 0x018A1594, 0x40BB0E8D, 0x83E823A6, 0xC2D938BF,
+ 0x0DC5A038, 0x4CF4BB21, 0x8FA7960A, 0xCE968D13,
+ 0x0900CC5C, 0x4831D745, 0x8B62FA6E, 0xCA53E177,
+ 0x545DBBBA, 0x156CA0A3, 0xD63F8D88, 0x970E9691,
+ 0x5098D7DE, 0x11A9CCC7, 0xD2FAE1EC, 0x93CBFAF5,
+ 0x5CD76272, 0x1DE6796B, 0xDEB55440, 0x9F844F59,
+ 0x58120E16, 0x1923150F, 0xDA703824, 0x9B41233D,
+ 0xA76BFD65, 0xE65AE67C, 0x2509CB57, 0x6438D04E,
+ 0xA3AE9101, 0xE29F8A18, 0x21CCA733, 0x60FDBC2A,
+ 0xAFE124AD, 0xEED03FB4, 0x2D83129F, 0x6CB20986,
+ 0xAB2448C9, 0xEA1553D0, 0x29467EFB, 0x687765E2,
+ 0xF6793F2F, 0xB7482436, 0x741B091D, 0x352A1204,
+ 0xF2BC534B, 0xB38D4852, 0x70DE6579, 0x31EF7E60,
+ 0xFEF3E6E7, 0xBFC2FDFE, 0x7C91D0D5, 0x3DA0CBCC,
+ 0xFA368A83, 0xBB07919A, 0x7854BCB1, 0x3965A7A8,
+ 0x4B98833B, 0x0AA99822, 0xC9FAB509, 0x88CBAE10,
+ 0x4F5DEF5F, 0x0E6CF446, 0xCD3FD96D, 0x8C0EC274,
+ 0x43125AF3, 0x022341EA, 0xC1706CC1, 0x804177D8,
+ 0x47D73697, 0x06E62D8E, 0xC5B500A5, 0x84841BBC,
+ 0x1A8A4171, 0x5BBB5A68, 0x98E87743, 0xD9D96C5A,
+ 0x1E4F2D15, 0x5F7E360C, 0x9C2D1B27, 0xDD1C003E,
+ 0x120098B9, 0x533183A0, 0x9062AE8B, 0xD153B592,
+ 0x16C5F4DD, 0x57F4EFC4, 0x94A7C2EF, 0xD596D9F6,
+ 0xE9BC07AE, 0xA88D1CB7, 0x6BDE319C, 0x2AEF2A85,
+ 0xED796BCA, 0xAC4870D3, 0x6F1B5DF8, 0x2E2A46E1,
+ 0xE136DE66, 0xA007C57F, 0x6354E854, 0x2265F34D,
+ 0xE5F3B202, 0xA4C2A91B, 0x67918430, 0x26A09F29,
+ 0xB8AEC5E4, 0xF99FDEFD, 0x3ACCF3D6, 0x7BFDE8CF,
+ 0xBC6BA980, 0xFD5AB299, 0x3E099FB2, 0x7F3884AB,
+ 0xB0241C2C, 0xF1150735, 0x32462A1E, 0x73773107,
+ 0xB4E17048, 0xF5D06B51, 0x3683467A, 0x77B25D63,
+ 0x4ED7FACB, 0x0FE6E1D2, 0xCCB5CCF9, 0x8D84D7E0,
+ 0x4A1296AF, 0x0B238DB6, 0xC870A09D, 0x8941BB84,
+ 0x465D2303, 0x076C381A, 0xC43F1531, 0x850E0E28,
+ 0x42984F67, 0x03A9547E, 0xC0FA7955, 0x81CB624C,
+ 0x1FC53881, 0x5EF42398, 0x9DA70EB3, 0xDC9615AA,
+ 0x1B0054E5, 0x5A314FFC, 0x996262D7, 0xD85379CE,
+ 0x174FE149, 0x567EFA50, 0x952DD77B, 0xD41CCC62,
+ 0x138A8D2D, 0x52BB9634, 0x91E8BB1F, 0xD0D9A006,
+ 0xECF37E5E, 0xADC26547, 0x6E91486C, 0x2FA05375,
+ 0xE836123A, 0xA9070923, 0x6A542408, 0x2B653F11,
+ 0xE479A796, 0xA548BC8F, 0x661B91A4, 0x272A8ABD,
+ 0xE0BCCBF2, 0xA18DD0EB, 0x62DEFDC0, 0x23EFE6D9,
+ 0xBDE1BC14, 0xFCD0A70D, 0x3F838A26, 0x7EB2913F,
+ 0xB924D070, 0xF815CB69, 0x3B46E642, 0x7A77FD5B,
+ 0xB56B65DC, 0xF45A7EC5, 0x370953EE, 0x763848F7,
+ 0xB1AE09B8, 0xF09F12A1, 0x33CC3F8A, 0x72FD2493
+ }, {
+ 0x00000000, 0x376AC201, 0x6ED48403, 0x59BE4602,
+ 0xDCA80907, 0xEBC2CB06, 0xB27C8D04, 0x85164F05,
+ 0xB851130E, 0x8F3BD10F, 0xD685970D, 0xE1EF550C,
+ 0x64F91A09, 0x5393D808, 0x0A2D9E0A, 0x3D475C0B,
+ 0x70A3261C, 0x47C9E41D, 0x1E77A21F, 0x291D601E,
+ 0xAC0B2F1B, 0x9B61ED1A, 0xC2DFAB18, 0xF5B56919,
+ 0xC8F23512, 0xFF98F713, 0xA626B111, 0x914C7310,
+ 0x145A3C15, 0x2330FE14, 0x7A8EB816, 0x4DE47A17,
+ 0xE0464D38, 0xD72C8F39, 0x8E92C93B, 0xB9F80B3A,
+ 0x3CEE443F, 0x0B84863E, 0x523AC03C, 0x6550023D,
+ 0x58175E36, 0x6F7D9C37, 0x36C3DA35, 0x01A91834,
+ 0x84BF5731, 0xB3D59530, 0xEA6BD332, 0xDD011133,
+ 0x90E56B24, 0xA78FA925, 0xFE31EF27, 0xC95B2D26,
+ 0x4C4D6223, 0x7B27A022, 0x2299E620, 0x15F32421,
+ 0x28B4782A, 0x1FDEBA2B, 0x4660FC29, 0x710A3E28,
+ 0xF41C712D, 0xC376B32C, 0x9AC8F52E, 0xADA2372F,
+ 0xC08D9A70, 0xF7E75871, 0xAE591E73, 0x9933DC72,
+ 0x1C259377, 0x2B4F5176, 0x72F11774, 0x459BD575,
+ 0x78DC897E, 0x4FB64B7F, 0x16080D7D, 0x2162CF7C,
+ 0xA4748079, 0x931E4278, 0xCAA0047A, 0xFDCAC67B,
+ 0xB02EBC6C, 0x87447E6D, 0xDEFA386F, 0xE990FA6E,
+ 0x6C86B56B, 0x5BEC776A, 0x02523168, 0x3538F369,
+ 0x087FAF62, 0x3F156D63, 0x66AB2B61, 0x51C1E960,
+ 0xD4D7A665, 0xE3BD6464, 0xBA032266, 0x8D69E067,
+ 0x20CBD748, 0x17A11549, 0x4E1F534B, 0x7975914A,
+ 0xFC63DE4F, 0xCB091C4E, 0x92B75A4C, 0xA5DD984D,
+ 0x989AC446, 0xAFF00647, 0xF64E4045, 0xC1248244,
+ 0x4432CD41, 0x73580F40, 0x2AE64942, 0x1D8C8B43,
+ 0x5068F154, 0x67023355, 0x3EBC7557, 0x09D6B756,
+ 0x8CC0F853, 0xBBAA3A52, 0xE2147C50, 0xD57EBE51,
+ 0xE839E25A, 0xDF53205B, 0x86ED6659, 0xB187A458,
+ 0x3491EB5D, 0x03FB295C, 0x5A456F5E, 0x6D2FAD5F,
+ 0x801B35E1, 0xB771F7E0, 0xEECFB1E2, 0xD9A573E3,
+ 0x5CB33CE6, 0x6BD9FEE7, 0x3267B8E5, 0x050D7AE4,
+ 0x384A26EF, 0x0F20E4EE, 0x569EA2EC, 0x61F460ED,
+ 0xE4E22FE8, 0xD388EDE9, 0x8A36ABEB, 0xBD5C69EA,
+ 0xF0B813FD, 0xC7D2D1FC, 0x9E6C97FE, 0xA90655FF,
+ 0x2C101AFA, 0x1B7AD8FB, 0x42C49EF9, 0x75AE5CF8,
+ 0x48E900F3, 0x7F83C2F2, 0x263D84F0, 0x115746F1,
+ 0x944109F4, 0xA32BCBF5, 0xFA958DF7, 0xCDFF4FF6,
+ 0x605D78D9, 0x5737BAD8, 0x0E89FCDA, 0x39E33EDB,
+ 0xBCF571DE, 0x8B9FB3DF, 0xD221F5DD, 0xE54B37DC,
+ 0xD80C6BD7, 0xEF66A9D6, 0xB6D8EFD4, 0x81B22DD5,
+ 0x04A462D0, 0x33CEA0D1, 0x6A70E6D3, 0x5D1A24D2,
+ 0x10FE5EC5, 0x27949CC4, 0x7E2ADAC6, 0x494018C7,
+ 0xCC5657C2, 0xFB3C95C3, 0xA282D3C1, 0x95E811C0,
+ 0xA8AF4DCB, 0x9FC58FCA, 0xC67BC9C8, 0xF1110BC9,
+ 0x740744CC, 0x436D86CD, 0x1AD3C0CF, 0x2DB902CE,
+ 0x4096AF91, 0x77FC6D90, 0x2E422B92, 0x1928E993,
+ 0x9C3EA696, 0xAB546497, 0xF2EA2295, 0xC580E094,
+ 0xF8C7BC9F, 0xCFAD7E9E, 0x9613389C, 0xA179FA9D,
+ 0x246FB598, 0x13057799, 0x4ABB319B, 0x7DD1F39A,
+ 0x3035898D, 0x075F4B8C, 0x5EE10D8E, 0x698BCF8F,
+ 0xEC9D808A, 0xDBF7428B, 0x82490489, 0xB523C688,
+ 0x88649A83, 0xBF0E5882, 0xE6B01E80, 0xD1DADC81,
+ 0x54CC9384, 0x63A65185, 0x3A181787, 0x0D72D586,
+ 0xA0D0E2A9, 0x97BA20A8, 0xCE0466AA, 0xF96EA4AB,
+ 0x7C78EBAE, 0x4B1229AF, 0x12AC6FAD, 0x25C6ADAC,
+ 0x1881F1A7, 0x2FEB33A6, 0x765575A4, 0x413FB7A5,
+ 0xC429F8A0, 0xF3433AA1, 0xAAFD7CA3, 0x9D97BEA2,
+ 0xD073C4B5, 0xE71906B4, 0xBEA740B6, 0x89CD82B7,
+ 0x0CDBCDB2, 0x3BB10FB3, 0x620F49B1, 0x55658BB0,
+ 0x6822D7BB, 0x5F4815BA, 0x06F653B8, 0x319C91B9,
+ 0xB48ADEBC, 0x83E01CBD, 0xDA5E5ABF, 0xED3498BE
+ }, {
+ 0x00000000, 0x6567BCB8, 0x8BC809AA, 0xEEAFB512,
+ 0x5797628F, 0x32F0DE37, 0xDC5F6B25, 0xB938D79D,
+ 0xEF28B4C5, 0x8A4F087D, 0x64E0BD6F, 0x018701D7,
+ 0xB8BFD64A, 0xDDD86AF2, 0x3377DFE0, 0x56106358,
+ 0x9F571950, 0xFA30A5E8, 0x149F10FA, 0x71F8AC42,
+ 0xC8C07BDF, 0xADA7C767, 0x43087275, 0x266FCECD,
+ 0x707FAD95, 0x1518112D, 0xFBB7A43F, 0x9ED01887,
+ 0x27E8CF1A, 0x428F73A2, 0xAC20C6B0, 0xC9477A08,
+ 0x3EAF32A0, 0x5BC88E18, 0xB5673B0A, 0xD00087B2,
+ 0x6938502F, 0x0C5FEC97, 0xE2F05985, 0x8797E53D,
+ 0xD1878665, 0xB4E03ADD, 0x5A4F8FCF, 0x3F283377,
+ 0x8610E4EA, 0xE3775852, 0x0DD8ED40, 0x68BF51F8,
+ 0xA1F82BF0, 0xC49F9748, 0x2A30225A, 0x4F579EE2,
+ 0xF66F497F, 0x9308F5C7, 0x7DA740D5, 0x18C0FC6D,
+ 0x4ED09F35, 0x2BB7238D, 0xC518969F, 0xA07F2A27,
+ 0x1947FDBA, 0x7C204102, 0x928FF410, 0xF7E848A8,
+ 0x3D58149B, 0x583FA823, 0xB6901D31, 0xD3F7A189,
+ 0x6ACF7614, 0x0FA8CAAC, 0xE1077FBE, 0x8460C306,
+ 0xD270A05E, 0xB7171CE6, 0x59B8A9F4, 0x3CDF154C,
+ 0x85E7C2D1, 0xE0807E69, 0x0E2FCB7B, 0x6B4877C3,
+ 0xA20F0DCB, 0xC768B173, 0x29C70461, 0x4CA0B8D9,
+ 0xF5986F44, 0x90FFD3FC, 0x7E5066EE, 0x1B37DA56,
+ 0x4D27B90E, 0x284005B6, 0xC6EFB0A4, 0xA3880C1C,
+ 0x1AB0DB81, 0x7FD76739, 0x9178D22B, 0xF41F6E93,
+ 0x03F7263B, 0x66909A83, 0x883F2F91, 0xED589329,
+ 0x546044B4, 0x3107F80C, 0xDFA84D1E, 0xBACFF1A6,
+ 0xECDF92FE, 0x89B82E46, 0x67179B54, 0x027027EC,
+ 0xBB48F071, 0xDE2F4CC9, 0x3080F9DB, 0x55E74563,
+ 0x9CA03F6B, 0xF9C783D3, 0x176836C1, 0x720F8A79,
+ 0xCB375DE4, 0xAE50E15C, 0x40FF544E, 0x2598E8F6,
+ 0x73888BAE, 0x16EF3716, 0xF8408204, 0x9D273EBC,
+ 0x241FE921, 0x41785599, 0xAFD7E08B, 0xCAB05C33,
+ 0x3BB659ED, 0x5ED1E555, 0xB07E5047, 0xD519ECFF,
+ 0x6C213B62, 0x094687DA, 0xE7E932C8, 0x828E8E70,
+ 0xD49EED28, 0xB1F95190, 0x5F56E482, 0x3A31583A,
+ 0x83098FA7, 0xE66E331F, 0x08C1860D, 0x6DA63AB5,
+ 0xA4E140BD, 0xC186FC05, 0x2F294917, 0x4A4EF5AF,
+ 0xF3762232, 0x96119E8A, 0x78BE2B98, 0x1DD99720,
+ 0x4BC9F478, 0x2EAE48C0, 0xC001FDD2, 0xA566416A,
+ 0x1C5E96F7, 0x79392A4F, 0x97969F5D, 0xF2F123E5,
+ 0x05196B4D, 0x607ED7F5, 0x8ED162E7, 0xEBB6DE5F,
+ 0x528E09C2, 0x37E9B57A, 0xD9460068, 0xBC21BCD0,
+ 0xEA31DF88, 0x8F566330, 0x61F9D622, 0x049E6A9A,
+ 0xBDA6BD07, 0xD8C101BF, 0x366EB4AD, 0x53090815,
+ 0x9A4E721D, 0xFF29CEA5, 0x11867BB7, 0x74E1C70F,
+ 0xCDD91092, 0xA8BEAC2A, 0x46111938, 0x2376A580,
+ 0x7566C6D8, 0x10017A60, 0xFEAECF72, 0x9BC973CA,
+ 0x22F1A457, 0x479618EF, 0xA939ADFD, 0xCC5E1145,
+ 0x06EE4D76, 0x6389F1CE, 0x8D2644DC, 0xE841F864,
+ 0x51792FF9, 0x341E9341, 0xDAB12653, 0xBFD69AEB,
+ 0xE9C6F9B3, 0x8CA1450B, 0x620EF019, 0x07694CA1,
+ 0xBE519B3C, 0xDB362784, 0x35999296, 0x50FE2E2E,
+ 0x99B95426, 0xFCDEE89E, 0x12715D8C, 0x7716E134,
+ 0xCE2E36A9, 0xAB498A11, 0x45E63F03, 0x208183BB,
+ 0x7691E0E3, 0x13F65C5B, 0xFD59E949, 0x983E55F1,
+ 0x2106826C, 0x44613ED4, 0xAACE8BC6, 0xCFA9377E,
+ 0x38417FD6, 0x5D26C36E, 0xB389767C, 0xD6EECAC4,
+ 0x6FD61D59, 0x0AB1A1E1, 0xE41E14F3, 0x8179A84B,
+ 0xD769CB13, 0xB20E77AB, 0x5CA1C2B9, 0x39C67E01,
+ 0x80FEA99C, 0xE5991524, 0x0B36A036, 0x6E511C8E,
+ 0xA7166686, 0xC271DA3E, 0x2CDE6F2C, 0x49B9D394,
+ 0xF0810409, 0x95E6B8B1, 0x7B490DA3, 0x1E2EB11B,
+ 0x483ED243, 0x2D596EFB, 0xC3F6DBE9, 0xA6916751,
+ 0x1FA9B0CC, 0x7ACE0C74, 0x9461B966, 0xF10605DE
+ }, {
+ 0x00000000, 0xB029603D, 0x6053C07A, 0xD07AA047,
+ 0xC0A680F5, 0x708FE0C8, 0xA0F5408F, 0x10DC20B2,
+ 0xC14B7030, 0x7162100D, 0xA118B04A, 0x1131D077,
+ 0x01EDF0C5, 0xB1C490F8, 0x61BE30BF, 0xD1975082,
+ 0x8297E060, 0x32BE805D, 0xE2C4201A, 0x52ED4027,
+ 0x42316095, 0xF21800A8, 0x2262A0EF, 0x924BC0D2,
+ 0x43DC9050, 0xF3F5F06D, 0x238F502A, 0x93A63017,
+ 0x837A10A5, 0x33537098, 0xE329D0DF, 0x5300B0E2,
+ 0x042FC1C1, 0xB406A1FC, 0x647C01BB, 0xD4556186,
+ 0xC4894134, 0x74A02109, 0xA4DA814E, 0x14F3E173,
+ 0xC564B1F1, 0x754DD1CC, 0xA537718B, 0x151E11B6,
+ 0x05C23104, 0xB5EB5139, 0x6591F17E, 0xD5B89143,
+ 0x86B821A1, 0x3691419C, 0xE6EBE1DB, 0x56C281E6,
+ 0x461EA154, 0xF637C169, 0x264D612E, 0x96640113,
+ 0x47F35191, 0xF7DA31AC, 0x27A091EB, 0x9789F1D6,
+ 0x8755D164, 0x377CB159, 0xE706111E, 0x572F7123,
+ 0x4958F358, 0xF9719365, 0x290B3322, 0x9922531F,
+ 0x89FE73AD, 0x39D71390, 0xE9ADB3D7, 0x5984D3EA,
+ 0x88138368, 0x383AE355, 0xE8404312, 0x5869232F,
+ 0x48B5039D, 0xF89C63A0, 0x28E6C3E7, 0x98CFA3DA,
+ 0xCBCF1338, 0x7BE67305, 0xAB9CD342, 0x1BB5B37F,
+ 0x0B6993CD, 0xBB40F3F0, 0x6B3A53B7, 0xDB13338A,
+ 0x0A846308, 0xBAAD0335, 0x6AD7A372, 0xDAFEC34F,
+ 0xCA22E3FD, 0x7A0B83C0, 0xAA712387, 0x1A5843BA,
+ 0x4D773299, 0xFD5E52A4, 0x2D24F2E3, 0x9D0D92DE,
+ 0x8DD1B26C, 0x3DF8D251, 0xED827216, 0x5DAB122B,
+ 0x8C3C42A9, 0x3C152294, 0xEC6F82D3, 0x5C46E2EE,
+ 0x4C9AC25C, 0xFCB3A261, 0x2CC90226, 0x9CE0621B,
+ 0xCFE0D2F9, 0x7FC9B2C4, 0xAFB31283, 0x1F9A72BE,
+ 0x0F46520C, 0xBF6F3231, 0x6F159276, 0xDF3CF24B,
+ 0x0EABA2C9, 0xBE82C2F4, 0x6EF862B3, 0xDED1028E,
+ 0xCE0D223C, 0x7E244201, 0xAE5EE246, 0x1E77827B,
+ 0x92B0E6B1, 0x2299868C, 0xF2E326CB, 0x42CA46F6,
+ 0x52166644, 0xE23F0679, 0x3245A63E, 0x826CC603,
+ 0x53FB9681, 0xE3D2F6BC, 0x33A856FB, 0x838136C6,
+ 0x935D1674, 0x23747649, 0xF30ED60E, 0x4327B633,
+ 0x102706D1, 0xA00E66EC, 0x7074C6AB, 0xC05DA696,
+ 0xD0818624, 0x60A8E619, 0xB0D2465E, 0x00FB2663,
+ 0xD16C76E1, 0x614516DC, 0xB13FB69B, 0x0116D6A6,
+ 0x11CAF614, 0xA1E39629, 0x7199366E, 0xC1B05653,
+ 0x969F2770, 0x26B6474D, 0xF6CCE70A, 0x46E58737,
+ 0x5639A785, 0xE610C7B8, 0x366A67FF, 0x864307C2,
+ 0x57D45740, 0xE7FD377D, 0x3787973A, 0x87AEF707,
+ 0x9772D7B5, 0x275BB788, 0xF72117CF, 0x470877F2,
+ 0x1408C710, 0xA421A72D, 0x745B076A, 0xC4726757,
+ 0xD4AE47E5, 0x648727D8, 0xB4FD879F, 0x04D4E7A2,
+ 0xD543B720, 0x656AD71D, 0xB510775A, 0x05391767,
+ 0x15E537D5, 0xA5CC57E8, 0x75B6F7AF, 0xC59F9792,
+ 0xDBE815E9, 0x6BC175D4, 0xBBBBD593, 0x0B92B5AE,
+ 0x1B4E951C, 0xAB67F521, 0x7B1D5566, 0xCB34355B,
+ 0x1AA365D9, 0xAA8A05E4, 0x7AF0A5A3, 0xCAD9C59E,
+ 0xDA05E52C, 0x6A2C8511, 0xBA562556, 0x0A7F456B,
+ 0x597FF589, 0xE95695B4, 0x392C35F3, 0x890555CE,
+ 0x99D9757C, 0x29F01541, 0xF98AB506, 0x49A3D53B,
+ 0x983485B9, 0x281DE584, 0xF86745C3, 0x484E25FE,
+ 0x5892054C, 0xE8BB6571, 0x38C1C536, 0x88E8A50B,
+ 0xDFC7D428, 0x6FEEB415, 0xBF941452, 0x0FBD746F,
+ 0x1F6154DD, 0xAF4834E0, 0x7F3294A7, 0xCF1BF49A,
+ 0x1E8CA418, 0xAEA5C425, 0x7EDF6462, 0xCEF6045F,
+ 0xDE2A24ED, 0x6E0344D0, 0xBE79E497, 0x0E5084AA,
+ 0x5D503448, 0xED795475, 0x3D03F432, 0x8D2A940F,
+ 0x9DF6B4BD, 0x2DDFD480, 0xFDA574C7, 0x4D8C14FA,
+ 0x9C1B4478, 0x2C322445, 0xFC488402, 0x4C61E43F,
+ 0x5CBDC48D, 0xEC94A4B0, 0x3CEE04F7, 0x8CC764CA
+ }, {
+ 0x00000000, 0xA5D35CCB, 0x0BA1C84D, 0xAE729486,
+ 0x1642919B, 0xB391CD50, 0x1DE359D6, 0xB830051D,
+ 0x6D8253EC, 0xC8510F27, 0x66239BA1, 0xC3F0C76A,
+ 0x7BC0C277, 0xDE139EBC, 0x70610A3A, 0xD5B256F1,
+ 0x9B02D603, 0x3ED18AC8, 0x90A31E4E, 0x35704285,
+ 0x8D404798, 0x28931B53, 0x86E18FD5, 0x2332D31E,
+ 0xF68085EF, 0x5353D924, 0xFD214DA2, 0x58F21169,
+ 0xE0C21474, 0x451148BF, 0xEB63DC39, 0x4EB080F2,
+ 0x3605AC07, 0x93D6F0CC, 0x3DA4644A, 0x98773881,
+ 0x20473D9C, 0x85946157, 0x2BE6F5D1, 0x8E35A91A,
+ 0x5B87FFEB, 0xFE54A320, 0x502637A6, 0xF5F56B6D,
+ 0x4DC56E70, 0xE81632BB, 0x4664A63D, 0xE3B7FAF6,
+ 0xAD077A04, 0x08D426CF, 0xA6A6B249, 0x0375EE82,
+ 0xBB45EB9F, 0x1E96B754, 0xB0E423D2, 0x15377F19,
+ 0xC08529E8, 0x65567523, 0xCB24E1A5, 0x6EF7BD6E,
+ 0xD6C7B873, 0x7314E4B8, 0xDD66703E, 0x78B52CF5,
+ 0x6C0A580F, 0xC9D904C4, 0x67AB9042, 0xC278CC89,
+ 0x7A48C994, 0xDF9B955F, 0x71E901D9, 0xD43A5D12,
+ 0x01880BE3, 0xA45B5728, 0x0A29C3AE, 0xAFFA9F65,
+ 0x17CA9A78, 0xB219C6B3, 0x1C6B5235, 0xB9B80EFE,
+ 0xF7088E0C, 0x52DBD2C7, 0xFCA94641, 0x597A1A8A,
+ 0xE14A1F97, 0x4499435C, 0xEAEBD7DA, 0x4F388B11,
+ 0x9A8ADDE0, 0x3F59812B, 0x912B15AD, 0x34F84966,
+ 0x8CC84C7B, 0x291B10B0, 0x87698436, 0x22BAD8FD,
+ 0x5A0FF408, 0xFFDCA8C3, 0x51AE3C45, 0xF47D608E,
+ 0x4C4D6593, 0xE99E3958, 0x47ECADDE, 0xE23FF115,
+ 0x378DA7E4, 0x925EFB2F, 0x3C2C6FA9, 0x99FF3362,
+ 0x21CF367F, 0x841C6AB4, 0x2A6EFE32, 0x8FBDA2F9,
+ 0xC10D220B, 0x64DE7EC0, 0xCAACEA46, 0x6F7FB68D,
+ 0xD74FB390, 0x729CEF5B, 0xDCEE7BDD, 0x793D2716,
+ 0xAC8F71E7, 0x095C2D2C, 0xA72EB9AA, 0x02FDE561,
+ 0xBACDE07C, 0x1F1EBCB7, 0xB16C2831, 0x14BF74FA,
+ 0xD814B01E, 0x7DC7ECD5, 0xD3B57853, 0x76662498,
+ 0xCE562185, 0x6B857D4E, 0xC5F7E9C8, 0x6024B503,
+ 0xB596E3F2, 0x1045BF39, 0xBE372BBF, 0x1BE47774,
+ 0xA3D47269, 0x06072EA2, 0xA875BA24, 0x0DA6E6EF,
+ 0x4316661D, 0xE6C53AD6, 0x48B7AE50, 0xED64F29B,
+ 0x5554F786, 0xF087AB4D, 0x5EF53FCB, 0xFB266300,
+ 0x2E9435F1, 0x8B47693A, 0x2535FDBC, 0x80E6A177,
+ 0x38D6A46A, 0x9D05F8A1, 0x33776C27, 0x96A430EC,
+ 0xEE111C19, 0x4BC240D2, 0xE5B0D454, 0x4063889F,
+ 0xF8538D82, 0x5D80D149, 0xF3F245CF, 0x56211904,
+ 0x83934FF5, 0x2640133E, 0x883287B8, 0x2DE1DB73,
+ 0x95D1DE6E, 0x300282A5, 0x9E701623, 0x3BA34AE8,
+ 0x7513CA1A, 0xD0C096D1, 0x7EB20257, 0xDB615E9C,
+ 0x63515B81, 0xC682074A, 0x68F093CC, 0xCD23CF07,
+ 0x189199F6, 0xBD42C53D, 0x133051BB, 0xB6E30D70,
+ 0x0ED3086D, 0xAB0054A6, 0x0572C020, 0xA0A19CEB,
+ 0xB41EE811, 0x11CDB4DA, 0xBFBF205C, 0x1A6C7C97,
+ 0xA25C798A, 0x078F2541, 0xA9FDB1C7, 0x0C2EED0C,
+ 0xD99CBBFD, 0x7C4FE736, 0xD23D73B0, 0x77EE2F7B,
+ 0xCFDE2A66, 0x6A0D76AD, 0xC47FE22B, 0x61ACBEE0,
+ 0x2F1C3E12, 0x8ACF62D9, 0x24BDF65F, 0x816EAA94,
+ 0x395EAF89, 0x9C8DF342, 0x32FF67C4, 0x972C3B0F,
+ 0x429E6DFE, 0xE74D3135, 0x493FA5B3, 0xECECF978,
+ 0x54DCFC65, 0xF10FA0AE, 0x5F7D3428, 0xFAAE68E3,
+ 0x821B4416, 0x27C818DD, 0x89BA8C5B, 0x2C69D090,
+ 0x9459D58D, 0x318A8946, 0x9FF81DC0, 0x3A2B410B,
+ 0xEF9917FA, 0x4A4A4B31, 0xE438DFB7, 0x41EB837C,
+ 0xF9DB8661, 0x5C08DAAA, 0xF27A4E2C, 0x57A912E7,
+ 0x19199215, 0xBCCACEDE, 0x12B85A58, 0xB76B0693,
+ 0x0F5B038E, 0xAA885F45, 0x04FACBC3, 0xA1299708,
+ 0x749BC1F9, 0xD1489D32, 0x7F3A09B4, 0xDAE9557F,
+ 0x62D95062, 0xC70A0CA9, 0x6978982F, 0xCCABC4E4
+ }, {
+ 0x00000000, 0xB40B77A6, 0x29119F97, 0x9D1AE831,
+ 0x13244FF4, 0xA72F3852, 0x3A35D063, 0x8E3EA7C5,
+ 0x674EEF33, 0xD3459895, 0x4E5F70A4, 0xFA540702,
+ 0x746AA0C7, 0xC061D761, 0x5D7B3F50, 0xE97048F6,
+ 0xCE9CDE67, 0x7A97A9C1, 0xE78D41F0, 0x53863656,
+ 0xDDB89193, 0x69B3E635, 0xF4A90E04, 0x40A279A2,
+ 0xA9D23154, 0x1DD946F2, 0x80C3AEC3, 0x34C8D965,
+ 0xBAF67EA0, 0x0EFD0906, 0x93E7E137, 0x27EC9691,
+ 0x9C39BDCF, 0x2832CA69, 0xB5282258, 0x012355FE,
+ 0x8F1DF23B, 0x3B16859D, 0xA60C6DAC, 0x12071A0A,
+ 0xFB7752FC, 0x4F7C255A, 0xD266CD6B, 0x666DBACD,
+ 0xE8531D08, 0x5C586AAE, 0xC142829F, 0x7549F539,
+ 0x52A563A8, 0xE6AE140E, 0x7BB4FC3F, 0xCFBF8B99,
+ 0x41812C5C, 0xF58A5BFA, 0x6890B3CB, 0xDC9BC46D,
+ 0x35EB8C9B, 0x81E0FB3D, 0x1CFA130C, 0xA8F164AA,
+ 0x26CFC36F, 0x92C4B4C9, 0x0FDE5CF8, 0xBBD52B5E,
+ 0x79750B44, 0xCD7E7CE2, 0x506494D3, 0xE46FE375,
+ 0x6A5144B0, 0xDE5A3316, 0x4340DB27, 0xF74BAC81,
+ 0x1E3BE477, 0xAA3093D1, 0x372A7BE0, 0x83210C46,
+ 0x0D1FAB83, 0xB914DC25, 0x240E3414, 0x900543B2,
+ 0xB7E9D523, 0x03E2A285, 0x9EF84AB4, 0x2AF33D12,
+ 0xA4CD9AD7, 0x10C6ED71, 0x8DDC0540, 0x39D772E6,
+ 0xD0A73A10, 0x64AC4DB6, 0xF9B6A587, 0x4DBDD221,
+ 0xC38375E4, 0x77880242, 0xEA92EA73, 0x5E999DD5,
+ 0xE54CB68B, 0x5147C12D, 0xCC5D291C, 0x78565EBA,
+ 0xF668F97F, 0x42638ED9, 0xDF7966E8, 0x6B72114E,
+ 0x820259B8, 0x36092E1E, 0xAB13C62F, 0x1F18B189,
+ 0x9126164C, 0x252D61EA, 0xB83789DB, 0x0C3CFE7D,
+ 0x2BD068EC, 0x9FDB1F4A, 0x02C1F77B, 0xB6CA80DD,
+ 0x38F42718, 0x8CFF50BE, 0x11E5B88F, 0xA5EECF29,
+ 0x4C9E87DF, 0xF895F079, 0x658F1848, 0xD1846FEE,
+ 0x5FBAC82B, 0xEBB1BF8D, 0x76AB57BC, 0xC2A0201A,
+ 0xF2EA1688, 0x46E1612E, 0xDBFB891F, 0x6FF0FEB9,
+ 0xE1CE597C, 0x55C52EDA, 0xC8DFC6EB, 0x7CD4B14D,
+ 0x95A4F9BB, 0x21AF8E1D, 0xBCB5662C, 0x08BE118A,
+ 0x8680B64F, 0x328BC1E9, 0xAF9129D8, 0x1B9A5E7E,
+ 0x3C76C8EF, 0x887DBF49, 0x15675778, 0xA16C20DE,
+ 0x2F52871B, 0x9B59F0BD, 0x0643188C, 0xB2486F2A,
+ 0x5B3827DC, 0xEF33507A, 0x7229B84B, 0xC622CFED,
+ 0x481C6828, 0xFC171F8E, 0x610DF7BF, 0xD5068019,
+ 0x6ED3AB47, 0xDAD8DCE1, 0x47C234D0, 0xF3C94376,
+ 0x7DF7E4B3, 0xC9FC9315, 0x54E67B24, 0xE0ED0C82,
+ 0x099D4474, 0xBD9633D2, 0x208CDBE3, 0x9487AC45,
+ 0x1AB90B80, 0xAEB27C26, 0x33A89417, 0x87A3E3B1,
+ 0xA04F7520, 0x14440286, 0x895EEAB7, 0x3D559D11,
+ 0xB36B3AD4, 0x07604D72, 0x9A7AA543, 0x2E71D2E5,
+ 0xC7019A13, 0x730AEDB5, 0xEE100584, 0x5A1B7222,
+ 0xD425D5E7, 0x602EA241, 0xFD344A70, 0x493F3DD6,
+ 0x8B9F1DCC, 0x3F946A6A, 0xA28E825B, 0x1685F5FD,
+ 0x98BB5238, 0x2CB0259E, 0xB1AACDAF, 0x05A1BA09,
+ 0xECD1F2FF, 0x58DA8559, 0xC5C06D68, 0x71CB1ACE,
+ 0xFFF5BD0B, 0x4BFECAAD, 0xD6E4229C, 0x62EF553A,
+ 0x4503C3AB, 0xF108B40D, 0x6C125C3C, 0xD8192B9A,
+ 0x56278C5F, 0xE22CFBF9, 0x7F3613C8, 0xCB3D646E,
+ 0x224D2C98, 0x96465B3E, 0x0B5CB30F, 0xBF57C4A9,
+ 0x3169636C, 0x856214CA, 0x1878FCFB, 0xAC738B5D,
+ 0x17A6A003, 0xA3ADD7A5, 0x3EB73F94, 0x8ABC4832,
+ 0x0482EFF7, 0xB0899851, 0x2D937060, 0x999807C6,
+ 0x70E84F30, 0xC4E33896, 0x59F9D0A7, 0xEDF2A701,
+ 0x63CC00C4, 0xD7C77762, 0x4ADD9F53, 0xFED6E8F5,
+ 0xD93A7E64, 0x6D3109C2, 0xF02BE1F3, 0x44209655,
+ 0xCA1E3190, 0x7E154636, 0xE30FAE07, 0x5704D9A1,
+ 0xBE749157, 0x0A7FE6F1, 0x97650EC0, 0x236E7966,
+ 0xAD50DEA3, 0x195BA905, 0x84414134, 0x304A3692
+ }, {
+ 0x00000000, 0x9E00AACC, 0x7D072542, 0xE3078F8E,
+ 0xFA0E4A84, 0x640EE048, 0x87096FC6, 0x1909C50A,
+ 0xB51BE5D3, 0x2B1B4F1F, 0xC81CC091, 0x561C6A5D,
+ 0x4F15AF57, 0xD115059B, 0x32128A15, 0xAC1220D9,
+ 0x2B31BB7C, 0xB53111B0, 0x56369E3E, 0xC83634F2,
+ 0xD13FF1F8, 0x4F3F5B34, 0xAC38D4BA, 0x32387E76,
+ 0x9E2A5EAF, 0x002AF463, 0xE32D7BED, 0x7D2DD121,
+ 0x6424142B, 0xFA24BEE7, 0x19233169, 0x87239BA5,
+ 0x566276F9, 0xC862DC35, 0x2B6553BB, 0xB565F977,
+ 0xAC6C3C7D, 0x326C96B1, 0xD16B193F, 0x4F6BB3F3,
+ 0xE379932A, 0x7D7939E6, 0x9E7EB668, 0x007E1CA4,
+ 0x1977D9AE, 0x87777362, 0x6470FCEC, 0xFA705620,
+ 0x7D53CD85, 0xE3536749, 0x0054E8C7, 0x9E54420B,
+ 0x875D8701, 0x195D2DCD, 0xFA5AA243, 0x645A088F,
+ 0xC8482856, 0x5648829A, 0xB54F0D14, 0x2B4FA7D8,
+ 0x324662D2, 0xAC46C81E, 0x4F414790, 0xD141ED5C,
+ 0xEDC29D29, 0x73C237E5, 0x90C5B86B, 0x0EC512A7,
+ 0x17CCD7AD, 0x89CC7D61, 0x6ACBF2EF, 0xF4CB5823,
+ 0x58D978FA, 0xC6D9D236, 0x25DE5DB8, 0xBBDEF774,
+ 0xA2D7327E, 0x3CD798B2, 0xDFD0173C, 0x41D0BDF0,
+ 0xC6F32655, 0x58F38C99, 0xBBF40317, 0x25F4A9DB,
+ 0x3CFD6CD1, 0xA2FDC61D, 0x41FA4993, 0xDFFAE35F,
+ 0x73E8C386, 0xEDE8694A, 0x0EEFE6C4, 0x90EF4C08,
+ 0x89E68902, 0x17E623CE, 0xF4E1AC40, 0x6AE1068C,
+ 0xBBA0EBD0, 0x25A0411C, 0xC6A7CE92, 0x58A7645E,
+ 0x41AEA154, 0xDFAE0B98, 0x3CA98416, 0xA2A92EDA,
+ 0x0EBB0E03, 0x90BBA4CF, 0x73BC2B41, 0xEDBC818D,
+ 0xF4B54487, 0x6AB5EE4B, 0x89B261C5, 0x17B2CB09,
+ 0x909150AC, 0x0E91FA60, 0xED9675EE, 0x7396DF22,
+ 0x6A9F1A28, 0xF49FB0E4, 0x17983F6A, 0x899895A6,
+ 0x258AB57F, 0xBB8A1FB3, 0x588D903D, 0xC68D3AF1,
+ 0xDF84FFFB, 0x41845537, 0xA283DAB9, 0x3C837075,
+ 0xDA853B53, 0x4485919F, 0xA7821E11, 0x3982B4DD,
+ 0x208B71D7, 0xBE8BDB1B, 0x5D8C5495, 0xC38CFE59,
+ 0x6F9EDE80, 0xF19E744C, 0x1299FBC2, 0x8C99510E,
+ 0x95909404, 0x0B903EC8, 0xE897B146, 0x76971B8A,
+ 0xF1B4802F, 0x6FB42AE3, 0x8CB3A56D, 0x12B30FA1,
+ 0x0BBACAAB, 0x95BA6067, 0x76BDEFE9, 0xE8BD4525,
+ 0x44AF65FC, 0xDAAFCF30, 0x39A840BE, 0xA7A8EA72,
+ 0xBEA12F78, 0x20A185B4, 0xC3A60A3A, 0x5DA6A0F6,
+ 0x8CE74DAA, 0x12E7E766, 0xF1E068E8, 0x6FE0C224,
+ 0x76E9072E, 0xE8E9ADE2, 0x0BEE226C, 0x95EE88A0,
+ 0x39FCA879, 0xA7FC02B5, 0x44FB8D3B, 0xDAFB27F7,
+ 0xC3F2E2FD, 0x5DF24831, 0xBEF5C7BF, 0x20F56D73,
+ 0xA7D6F6D6, 0x39D65C1A, 0xDAD1D394, 0x44D17958,
+ 0x5DD8BC52, 0xC3D8169E, 0x20DF9910, 0xBEDF33DC,
+ 0x12CD1305, 0x8CCDB9C9, 0x6FCA3647, 0xF1CA9C8B,
+ 0xE8C35981, 0x76C3F34D, 0x95C47CC3, 0x0BC4D60F,
+ 0x3747A67A, 0xA9470CB6, 0x4A408338, 0xD44029F4,
+ 0xCD49ECFE, 0x53494632, 0xB04EC9BC, 0x2E4E6370,
+ 0x825C43A9, 0x1C5CE965, 0xFF5B66EB, 0x615BCC27,
+ 0x7852092D, 0xE652A3E1, 0x05552C6F, 0x9B5586A3,
+ 0x1C761D06, 0x8276B7CA, 0x61713844, 0xFF719288,
+ 0xE6785782, 0x7878FD4E, 0x9B7F72C0, 0x057FD80C,
+ 0xA96DF8D5, 0x376D5219, 0xD46ADD97, 0x4A6A775B,
+ 0x5363B251, 0xCD63189D, 0x2E649713, 0xB0643DDF,
+ 0x6125D083, 0xFF257A4F, 0x1C22F5C1, 0x82225F0D,
+ 0x9B2B9A07, 0x052B30CB, 0xE62CBF45, 0x782C1589,
+ 0xD43E3550, 0x4A3E9F9C, 0xA9391012, 0x3739BADE,
+ 0x2E307FD4, 0xB030D518, 0x53375A96, 0xCD37F05A,
+ 0x4A146BFF, 0xD414C133, 0x37134EBD, 0xA913E471,
+ 0xB01A217B, 0x2E1A8BB7, 0xCD1D0439, 0x531DAEF5,
+ 0xFF0F8E2C, 0x610F24E0, 0x8208AB6E, 0x1C0801A2,
+ 0x0501C4A8, 0x9B016E64, 0x7806E1EA, 0xE6064B26
+ }
+};
diff --git a/Utilities/cmliblzma/liblzma/check/crc32_table_le.h b/Utilities/cmliblzma/liblzma/check/crc32_table_le.h
new file mode 100644
index 0000000000..25f4fc4435
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc32_table_le.h
@@ -0,0 +1,525 @@
+/* This file has been automatically generated by crc32_tablegen.c. */
+
+const uint32_t lzma_crc32_table[8][256] = {
+ {
+ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
+ 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
+ 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
+ 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
+ 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
+ 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
+ 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
+ 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
+ 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
+ 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
+ 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
+ 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
+ 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
+ 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
+ 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
+ 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
+ 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
+ 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
+ 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
+ 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
+ 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
+ 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
+ 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
+ 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
+ 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
+ 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
+ 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
+ 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
+ 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
+ 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
+ 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
+ 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
+ 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
+ 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
+ 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
+ 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
+ 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
+ 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
+ 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
+ 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
+ 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
+ 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
+ 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
+ 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
+ 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
+ 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
+ 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
+ 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
+ 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
+ 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
+ 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
+ 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
+ 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
+ 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
+ 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
+ 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
+ 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
+ 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
+ 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
+ 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
+ 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
+ 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
+ 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
+ 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
+ }, {
+ 0x00000000, 0x191B3141, 0x32366282, 0x2B2D53C3,
+ 0x646CC504, 0x7D77F445, 0x565AA786, 0x4F4196C7,
+ 0xC8D98A08, 0xD1C2BB49, 0xFAEFE88A, 0xE3F4D9CB,
+ 0xACB54F0C, 0xB5AE7E4D, 0x9E832D8E, 0x87981CCF,
+ 0x4AC21251, 0x53D92310, 0x78F470D3, 0x61EF4192,
+ 0x2EAED755, 0x37B5E614, 0x1C98B5D7, 0x05838496,
+ 0x821B9859, 0x9B00A918, 0xB02DFADB, 0xA936CB9A,
+ 0xE6775D5D, 0xFF6C6C1C, 0xD4413FDF, 0xCD5A0E9E,
+ 0x958424A2, 0x8C9F15E3, 0xA7B24620, 0xBEA97761,
+ 0xF1E8E1A6, 0xE8F3D0E7, 0xC3DE8324, 0xDAC5B265,
+ 0x5D5DAEAA, 0x44469FEB, 0x6F6BCC28, 0x7670FD69,
+ 0x39316BAE, 0x202A5AEF, 0x0B07092C, 0x121C386D,
+ 0xDF4636F3, 0xC65D07B2, 0xED705471, 0xF46B6530,
+ 0xBB2AF3F7, 0xA231C2B6, 0x891C9175, 0x9007A034,
+ 0x179FBCFB, 0x0E848DBA, 0x25A9DE79, 0x3CB2EF38,
+ 0x73F379FF, 0x6AE848BE, 0x41C51B7D, 0x58DE2A3C,
+ 0xF0794F05, 0xE9627E44, 0xC24F2D87, 0xDB541CC6,
+ 0x94158A01, 0x8D0EBB40, 0xA623E883, 0xBF38D9C2,
+ 0x38A0C50D, 0x21BBF44C, 0x0A96A78F, 0x138D96CE,
+ 0x5CCC0009, 0x45D73148, 0x6EFA628B, 0x77E153CA,
+ 0xBABB5D54, 0xA3A06C15, 0x888D3FD6, 0x91960E97,
+ 0xDED79850, 0xC7CCA911, 0xECE1FAD2, 0xF5FACB93,
+ 0x7262D75C, 0x6B79E61D, 0x4054B5DE, 0x594F849F,
+ 0x160E1258, 0x0F152319, 0x243870DA, 0x3D23419B,
+ 0x65FD6BA7, 0x7CE65AE6, 0x57CB0925, 0x4ED03864,
+ 0x0191AEA3, 0x188A9FE2, 0x33A7CC21, 0x2ABCFD60,
+ 0xAD24E1AF, 0xB43FD0EE, 0x9F12832D, 0x8609B26C,
+ 0xC94824AB, 0xD05315EA, 0xFB7E4629, 0xE2657768,
+ 0x2F3F79F6, 0x362448B7, 0x1D091B74, 0x04122A35,
+ 0x4B53BCF2, 0x52488DB3, 0x7965DE70, 0x607EEF31,
+ 0xE7E6F3FE, 0xFEFDC2BF, 0xD5D0917C, 0xCCCBA03D,
+ 0x838A36FA, 0x9A9107BB, 0xB1BC5478, 0xA8A76539,
+ 0x3B83984B, 0x2298A90A, 0x09B5FAC9, 0x10AECB88,
+ 0x5FEF5D4F, 0x46F46C0E, 0x6DD93FCD, 0x74C20E8C,
+ 0xF35A1243, 0xEA412302, 0xC16C70C1, 0xD8774180,
+ 0x9736D747, 0x8E2DE606, 0xA500B5C5, 0xBC1B8484,
+ 0x71418A1A, 0x685ABB5B, 0x4377E898, 0x5A6CD9D9,
+ 0x152D4F1E, 0x0C367E5F, 0x271B2D9C, 0x3E001CDD,
+ 0xB9980012, 0xA0833153, 0x8BAE6290, 0x92B553D1,
+ 0xDDF4C516, 0xC4EFF457, 0xEFC2A794, 0xF6D996D5,
+ 0xAE07BCE9, 0xB71C8DA8, 0x9C31DE6B, 0x852AEF2A,
+ 0xCA6B79ED, 0xD37048AC, 0xF85D1B6F, 0xE1462A2E,
+ 0x66DE36E1, 0x7FC507A0, 0x54E85463, 0x4DF36522,
+ 0x02B2F3E5, 0x1BA9C2A4, 0x30849167, 0x299FA026,
+ 0xE4C5AEB8, 0xFDDE9FF9, 0xD6F3CC3A, 0xCFE8FD7B,
+ 0x80A96BBC, 0x99B25AFD, 0xB29F093E, 0xAB84387F,
+ 0x2C1C24B0, 0x350715F1, 0x1E2A4632, 0x07317773,
+ 0x4870E1B4, 0x516BD0F5, 0x7A468336, 0x635DB277,
+ 0xCBFAD74E, 0xD2E1E60F, 0xF9CCB5CC, 0xE0D7848D,
+ 0xAF96124A, 0xB68D230B, 0x9DA070C8, 0x84BB4189,
+ 0x03235D46, 0x1A386C07, 0x31153FC4, 0x280E0E85,
+ 0x674F9842, 0x7E54A903, 0x5579FAC0, 0x4C62CB81,
+ 0x8138C51F, 0x9823F45E, 0xB30EA79D, 0xAA1596DC,
+ 0xE554001B, 0xFC4F315A, 0xD7626299, 0xCE7953D8,
+ 0x49E14F17, 0x50FA7E56, 0x7BD72D95, 0x62CC1CD4,
+ 0x2D8D8A13, 0x3496BB52, 0x1FBBE891, 0x06A0D9D0,
+ 0x5E7EF3EC, 0x4765C2AD, 0x6C48916E, 0x7553A02F,
+ 0x3A1236E8, 0x230907A9, 0x0824546A, 0x113F652B,
+ 0x96A779E4, 0x8FBC48A5, 0xA4911B66, 0xBD8A2A27,
+ 0xF2CBBCE0, 0xEBD08DA1, 0xC0FDDE62, 0xD9E6EF23,
+ 0x14BCE1BD, 0x0DA7D0FC, 0x268A833F, 0x3F91B27E,
+ 0x70D024B9, 0x69CB15F8, 0x42E6463B, 0x5BFD777A,
+ 0xDC656BB5, 0xC57E5AF4, 0xEE530937, 0xF7483876,
+ 0xB809AEB1, 0xA1129FF0, 0x8A3FCC33, 0x9324FD72
+ }, {
+ 0x00000000, 0x01C26A37, 0x0384D46E, 0x0246BE59,
+ 0x0709A8DC, 0x06CBC2EB, 0x048D7CB2, 0x054F1685,
+ 0x0E1351B8, 0x0FD13B8F, 0x0D9785D6, 0x0C55EFE1,
+ 0x091AF964, 0x08D89353, 0x0A9E2D0A, 0x0B5C473D,
+ 0x1C26A370, 0x1DE4C947, 0x1FA2771E, 0x1E601D29,
+ 0x1B2F0BAC, 0x1AED619B, 0x18ABDFC2, 0x1969B5F5,
+ 0x1235F2C8, 0x13F798FF, 0x11B126A6, 0x10734C91,
+ 0x153C5A14, 0x14FE3023, 0x16B88E7A, 0x177AE44D,
+ 0x384D46E0, 0x398F2CD7, 0x3BC9928E, 0x3A0BF8B9,
+ 0x3F44EE3C, 0x3E86840B, 0x3CC03A52, 0x3D025065,
+ 0x365E1758, 0x379C7D6F, 0x35DAC336, 0x3418A901,
+ 0x3157BF84, 0x3095D5B3, 0x32D36BEA, 0x331101DD,
+ 0x246BE590, 0x25A98FA7, 0x27EF31FE, 0x262D5BC9,
+ 0x23624D4C, 0x22A0277B, 0x20E69922, 0x2124F315,
+ 0x2A78B428, 0x2BBADE1F, 0x29FC6046, 0x283E0A71,
+ 0x2D711CF4, 0x2CB376C3, 0x2EF5C89A, 0x2F37A2AD,
+ 0x709A8DC0, 0x7158E7F7, 0x731E59AE, 0x72DC3399,
+ 0x7793251C, 0x76514F2B, 0x7417F172, 0x75D59B45,
+ 0x7E89DC78, 0x7F4BB64F, 0x7D0D0816, 0x7CCF6221,
+ 0x798074A4, 0x78421E93, 0x7A04A0CA, 0x7BC6CAFD,
+ 0x6CBC2EB0, 0x6D7E4487, 0x6F38FADE, 0x6EFA90E9,
+ 0x6BB5866C, 0x6A77EC5B, 0x68315202, 0x69F33835,
+ 0x62AF7F08, 0x636D153F, 0x612BAB66, 0x60E9C151,
+ 0x65A6D7D4, 0x6464BDE3, 0x662203BA, 0x67E0698D,
+ 0x48D7CB20, 0x4915A117, 0x4B531F4E, 0x4A917579,
+ 0x4FDE63FC, 0x4E1C09CB, 0x4C5AB792, 0x4D98DDA5,
+ 0x46C49A98, 0x4706F0AF, 0x45404EF6, 0x448224C1,
+ 0x41CD3244, 0x400F5873, 0x4249E62A, 0x438B8C1D,
+ 0x54F16850, 0x55330267, 0x5775BC3E, 0x56B7D609,
+ 0x53F8C08C, 0x523AAABB, 0x507C14E2, 0x51BE7ED5,
+ 0x5AE239E8, 0x5B2053DF, 0x5966ED86, 0x58A487B1,
+ 0x5DEB9134, 0x5C29FB03, 0x5E6F455A, 0x5FAD2F6D,
+ 0xE1351B80, 0xE0F771B7, 0xE2B1CFEE, 0xE373A5D9,
+ 0xE63CB35C, 0xE7FED96B, 0xE5B86732, 0xE47A0D05,
+ 0xEF264A38, 0xEEE4200F, 0xECA29E56, 0xED60F461,
+ 0xE82FE2E4, 0xE9ED88D3, 0xEBAB368A, 0xEA695CBD,
+ 0xFD13B8F0, 0xFCD1D2C7, 0xFE976C9E, 0xFF5506A9,
+ 0xFA1A102C, 0xFBD87A1B, 0xF99EC442, 0xF85CAE75,
+ 0xF300E948, 0xF2C2837F, 0xF0843D26, 0xF1465711,
+ 0xF4094194, 0xF5CB2BA3, 0xF78D95FA, 0xF64FFFCD,
+ 0xD9785D60, 0xD8BA3757, 0xDAFC890E, 0xDB3EE339,
+ 0xDE71F5BC, 0xDFB39F8B, 0xDDF521D2, 0xDC374BE5,
+ 0xD76B0CD8, 0xD6A966EF, 0xD4EFD8B6, 0xD52DB281,
+ 0xD062A404, 0xD1A0CE33, 0xD3E6706A, 0xD2241A5D,
+ 0xC55EFE10, 0xC49C9427, 0xC6DA2A7E, 0xC7184049,
+ 0xC25756CC, 0xC3953CFB, 0xC1D382A2, 0xC011E895,
+ 0xCB4DAFA8, 0xCA8FC59F, 0xC8C97BC6, 0xC90B11F1,
+ 0xCC440774, 0xCD866D43, 0xCFC0D31A, 0xCE02B92D,
+ 0x91AF9640, 0x906DFC77, 0x922B422E, 0x93E92819,
+ 0x96A63E9C, 0x976454AB, 0x9522EAF2, 0x94E080C5,
+ 0x9FBCC7F8, 0x9E7EADCF, 0x9C381396, 0x9DFA79A1,
+ 0x98B56F24, 0x99770513, 0x9B31BB4A, 0x9AF3D17D,
+ 0x8D893530, 0x8C4B5F07, 0x8E0DE15E, 0x8FCF8B69,
+ 0x8A809DEC, 0x8B42F7DB, 0x89044982, 0x88C623B5,
+ 0x839A6488, 0x82580EBF, 0x801EB0E6, 0x81DCDAD1,
+ 0x8493CC54, 0x8551A663, 0x8717183A, 0x86D5720D,
+ 0xA9E2D0A0, 0xA820BA97, 0xAA6604CE, 0xABA46EF9,
+ 0xAEEB787C, 0xAF29124B, 0xAD6FAC12, 0xACADC625,
+ 0xA7F18118, 0xA633EB2F, 0xA4755576, 0xA5B73F41,
+ 0xA0F829C4, 0xA13A43F3, 0xA37CFDAA, 0xA2BE979D,
+ 0xB5C473D0, 0xB40619E7, 0xB640A7BE, 0xB782CD89,
+ 0xB2CDDB0C, 0xB30FB13B, 0xB1490F62, 0xB08B6555,
+ 0xBBD72268, 0xBA15485F, 0xB853F606, 0xB9919C31,
+ 0xBCDE8AB4, 0xBD1CE083, 0xBF5A5EDA, 0xBE9834ED
+ }, {
+ 0x00000000, 0xB8BC6765, 0xAA09C88B, 0x12B5AFEE,
+ 0x8F629757, 0x37DEF032, 0x256B5FDC, 0x9DD738B9,
+ 0xC5B428EF, 0x7D084F8A, 0x6FBDE064, 0xD7018701,
+ 0x4AD6BFB8, 0xF26AD8DD, 0xE0DF7733, 0x58631056,
+ 0x5019579F, 0xE8A530FA, 0xFA109F14, 0x42ACF871,
+ 0xDF7BC0C8, 0x67C7A7AD, 0x75720843, 0xCDCE6F26,
+ 0x95AD7F70, 0x2D111815, 0x3FA4B7FB, 0x8718D09E,
+ 0x1ACFE827, 0xA2738F42, 0xB0C620AC, 0x087A47C9,
+ 0xA032AF3E, 0x188EC85B, 0x0A3B67B5, 0xB28700D0,
+ 0x2F503869, 0x97EC5F0C, 0x8559F0E2, 0x3DE59787,
+ 0x658687D1, 0xDD3AE0B4, 0xCF8F4F5A, 0x7733283F,
+ 0xEAE41086, 0x525877E3, 0x40EDD80D, 0xF851BF68,
+ 0xF02BF8A1, 0x48979FC4, 0x5A22302A, 0xE29E574F,
+ 0x7F496FF6, 0xC7F50893, 0xD540A77D, 0x6DFCC018,
+ 0x359FD04E, 0x8D23B72B, 0x9F9618C5, 0x272A7FA0,
+ 0xBAFD4719, 0x0241207C, 0x10F48F92, 0xA848E8F7,
+ 0x9B14583D, 0x23A83F58, 0x311D90B6, 0x89A1F7D3,
+ 0x1476CF6A, 0xACCAA80F, 0xBE7F07E1, 0x06C36084,
+ 0x5EA070D2, 0xE61C17B7, 0xF4A9B859, 0x4C15DF3C,
+ 0xD1C2E785, 0x697E80E0, 0x7BCB2F0E, 0xC377486B,
+ 0xCB0D0FA2, 0x73B168C7, 0x6104C729, 0xD9B8A04C,
+ 0x446F98F5, 0xFCD3FF90, 0xEE66507E, 0x56DA371B,
+ 0x0EB9274D, 0xB6054028, 0xA4B0EFC6, 0x1C0C88A3,
+ 0x81DBB01A, 0x3967D77F, 0x2BD27891, 0x936E1FF4,
+ 0x3B26F703, 0x839A9066, 0x912F3F88, 0x299358ED,
+ 0xB4446054, 0x0CF80731, 0x1E4DA8DF, 0xA6F1CFBA,
+ 0xFE92DFEC, 0x462EB889, 0x549B1767, 0xEC277002,
+ 0x71F048BB, 0xC94C2FDE, 0xDBF98030, 0x6345E755,
+ 0x6B3FA09C, 0xD383C7F9, 0xC1366817, 0x798A0F72,
+ 0xE45D37CB, 0x5CE150AE, 0x4E54FF40, 0xF6E89825,
+ 0xAE8B8873, 0x1637EF16, 0x048240F8, 0xBC3E279D,
+ 0x21E91F24, 0x99557841, 0x8BE0D7AF, 0x335CB0CA,
+ 0xED59B63B, 0x55E5D15E, 0x47507EB0, 0xFFEC19D5,
+ 0x623B216C, 0xDA874609, 0xC832E9E7, 0x708E8E82,
+ 0x28ED9ED4, 0x9051F9B1, 0x82E4565F, 0x3A58313A,
+ 0xA78F0983, 0x1F336EE6, 0x0D86C108, 0xB53AA66D,
+ 0xBD40E1A4, 0x05FC86C1, 0x1749292F, 0xAFF54E4A,
+ 0x322276F3, 0x8A9E1196, 0x982BBE78, 0x2097D91D,
+ 0x78F4C94B, 0xC048AE2E, 0xD2FD01C0, 0x6A4166A5,
+ 0xF7965E1C, 0x4F2A3979, 0x5D9F9697, 0xE523F1F2,
+ 0x4D6B1905, 0xF5D77E60, 0xE762D18E, 0x5FDEB6EB,
+ 0xC2098E52, 0x7AB5E937, 0x680046D9, 0xD0BC21BC,
+ 0x88DF31EA, 0x3063568F, 0x22D6F961, 0x9A6A9E04,
+ 0x07BDA6BD, 0xBF01C1D8, 0xADB46E36, 0x15080953,
+ 0x1D724E9A, 0xA5CE29FF, 0xB77B8611, 0x0FC7E174,
+ 0x9210D9CD, 0x2AACBEA8, 0x38191146, 0x80A57623,
+ 0xD8C66675, 0x607A0110, 0x72CFAEFE, 0xCA73C99B,
+ 0x57A4F122, 0xEF189647, 0xFDAD39A9, 0x45115ECC,
+ 0x764DEE06, 0xCEF18963, 0xDC44268D, 0x64F841E8,
+ 0xF92F7951, 0x41931E34, 0x5326B1DA, 0xEB9AD6BF,
+ 0xB3F9C6E9, 0x0B45A18C, 0x19F00E62, 0xA14C6907,
+ 0x3C9B51BE, 0x842736DB, 0x96929935, 0x2E2EFE50,
+ 0x2654B999, 0x9EE8DEFC, 0x8C5D7112, 0x34E11677,
+ 0xA9362ECE, 0x118A49AB, 0x033FE645, 0xBB838120,
+ 0xE3E09176, 0x5B5CF613, 0x49E959FD, 0xF1553E98,
+ 0x6C820621, 0xD43E6144, 0xC68BCEAA, 0x7E37A9CF,
+ 0xD67F4138, 0x6EC3265D, 0x7C7689B3, 0xC4CAEED6,
+ 0x591DD66F, 0xE1A1B10A, 0xF3141EE4, 0x4BA87981,
+ 0x13CB69D7, 0xAB770EB2, 0xB9C2A15C, 0x017EC639,
+ 0x9CA9FE80, 0x241599E5, 0x36A0360B, 0x8E1C516E,
+ 0x866616A7, 0x3EDA71C2, 0x2C6FDE2C, 0x94D3B949,
+ 0x090481F0, 0xB1B8E695, 0xA30D497B, 0x1BB12E1E,
+ 0x43D23E48, 0xFB6E592D, 0xE9DBF6C3, 0x516791A6,
+ 0xCCB0A91F, 0x740CCE7A, 0x66B96194, 0xDE0506F1
+ }, {
+ 0x00000000, 0x3D6029B0, 0x7AC05360, 0x47A07AD0,
+ 0xF580A6C0, 0xC8E08F70, 0x8F40F5A0, 0xB220DC10,
+ 0x30704BC1, 0x0D106271, 0x4AB018A1, 0x77D03111,
+ 0xC5F0ED01, 0xF890C4B1, 0xBF30BE61, 0x825097D1,
+ 0x60E09782, 0x5D80BE32, 0x1A20C4E2, 0x2740ED52,
+ 0x95603142, 0xA80018F2, 0xEFA06222, 0xD2C04B92,
+ 0x5090DC43, 0x6DF0F5F3, 0x2A508F23, 0x1730A693,
+ 0xA5107A83, 0x98705333, 0xDFD029E3, 0xE2B00053,
+ 0xC1C12F04, 0xFCA106B4, 0xBB017C64, 0x866155D4,
+ 0x344189C4, 0x0921A074, 0x4E81DAA4, 0x73E1F314,
+ 0xF1B164C5, 0xCCD14D75, 0x8B7137A5, 0xB6111E15,
+ 0x0431C205, 0x3951EBB5, 0x7EF19165, 0x4391B8D5,
+ 0xA121B886, 0x9C419136, 0xDBE1EBE6, 0xE681C256,
+ 0x54A11E46, 0x69C137F6, 0x2E614D26, 0x13016496,
+ 0x9151F347, 0xAC31DAF7, 0xEB91A027, 0xD6F18997,
+ 0x64D15587, 0x59B17C37, 0x1E1106E7, 0x23712F57,
+ 0x58F35849, 0x659371F9, 0x22330B29, 0x1F532299,
+ 0xAD73FE89, 0x9013D739, 0xD7B3ADE9, 0xEAD38459,
+ 0x68831388, 0x55E33A38, 0x124340E8, 0x2F236958,
+ 0x9D03B548, 0xA0639CF8, 0xE7C3E628, 0xDAA3CF98,
+ 0x3813CFCB, 0x0573E67B, 0x42D39CAB, 0x7FB3B51B,
+ 0xCD93690B, 0xF0F340BB, 0xB7533A6B, 0x8A3313DB,
+ 0x0863840A, 0x3503ADBA, 0x72A3D76A, 0x4FC3FEDA,
+ 0xFDE322CA, 0xC0830B7A, 0x872371AA, 0xBA43581A,
+ 0x9932774D, 0xA4525EFD, 0xE3F2242D, 0xDE920D9D,
+ 0x6CB2D18D, 0x51D2F83D, 0x167282ED, 0x2B12AB5D,
+ 0xA9423C8C, 0x9422153C, 0xD3826FEC, 0xEEE2465C,
+ 0x5CC29A4C, 0x61A2B3FC, 0x2602C92C, 0x1B62E09C,
+ 0xF9D2E0CF, 0xC4B2C97F, 0x8312B3AF, 0xBE729A1F,
+ 0x0C52460F, 0x31326FBF, 0x7692156F, 0x4BF23CDF,
+ 0xC9A2AB0E, 0xF4C282BE, 0xB362F86E, 0x8E02D1DE,
+ 0x3C220DCE, 0x0142247E, 0x46E25EAE, 0x7B82771E,
+ 0xB1E6B092, 0x8C869922, 0xCB26E3F2, 0xF646CA42,
+ 0x44661652, 0x79063FE2, 0x3EA64532, 0x03C66C82,
+ 0x8196FB53, 0xBCF6D2E3, 0xFB56A833, 0xC6368183,
+ 0x74165D93, 0x49767423, 0x0ED60EF3, 0x33B62743,
+ 0xD1062710, 0xEC660EA0, 0xABC67470, 0x96A65DC0,
+ 0x248681D0, 0x19E6A860, 0x5E46D2B0, 0x6326FB00,
+ 0xE1766CD1, 0xDC164561, 0x9BB63FB1, 0xA6D61601,
+ 0x14F6CA11, 0x2996E3A1, 0x6E369971, 0x5356B0C1,
+ 0x70279F96, 0x4D47B626, 0x0AE7CCF6, 0x3787E546,
+ 0x85A73956, 0xB8C710E6, 0xFF676A36, 0xC2074386,
+ 0x4057D457, 0x7D37FDE7, 0x3A978737, 0x07F7AE87,
+ 0xB5D77297, 0x88B75B27, 0xCF1721F7, 0xF2770847,
+ 0x10C70814, 0x2DA721A4, 0x6A075B74, 0x576772C4,
+ 0xE547AED4, 0xD8278764, 0x9F87FDB4, 0xA2E7D404,
+ 0x20B743D5, 0x1DD76A65, 0x5A7710B5, 0x67173905,
+ 0xD537E515, 0xE857CCA5, 0xAFF7B675, 0x92979FC5,
+ 0xE915E8DB, 0xD475C16B, 0x93D5BBBB, 0xAEB5920B,
+ 0x1C954E1B, 0x21F567AB, 0x66551D7B, 0x5B3534CB,
+ 0xD965A31A, 0xE4058AAA, 0xA3A5F07A, 0x9EC5D9CA,
+ 0x2CE505DA, 0x11852C6A, 0x562556BA, 0x6B457F0A,
+ 0x89F57F59, 0xB49556E9, 0xF3352C39, 0xCE550589,
+ 0x7C75D999, 0x4115F029, 0x06B58AF9, 0x3BD5A349,
+ 0xB9853498, 0x84E51D28, 0xC34567F8, 0xFE254E48,
+ 0x4C059258, 0x7165BBE8, 0x36C5C138, 0x0BA5E888,
+ 0x28D4C7DF, 0x15B4EE6F, 0x521494BF, 0x6F74BD0F,
+ 0xDD54611F, 0xE03448AF, 0xA794327F, 0x9AF41BCF,
+ 0x18A48C1E, 0x25C4A5AE, 0x6264DF7E, 0x5F04F6CE,
+ 0xED242ADE, 0xD044036E, 0x97E479BE, 0xAA84500E,
+ 0x4834505D, 0x755479ED, 0x32F4033D, 0x0F942A8D,
+ 0xBDB4F69D, 0x80D4DF2D, 0xC774A5FD, 0xFA148C4D,
+ 0x78441B9C, 0x4524322C, 0x028448FC, 0x3FE4614C,
+ 0x8DC4BD5C, 0xB0A494EC, 0xF704EE3C, 0xCA64C78C
+ }, {
+ 0x00000000, 0xCB5CD3A5, 0x4DC8A10B, 0x869472AE,
+ 0x9B914216, 0x50CD91B3, 0xD659E31D, 0x1D0530B8,
+ 0xEC53826D, 0x270F51C8, 0xA19B2366, 0x6AC7F0C3,
+ 0x77C2C07B, 0xBC9E13DE, 0x3A0A6170, 0xF156B2D5,
+ 0x03D6029B, 0xC88AD13E, 0x4E1EA390, 0x85427035,
+ 0x9847408D, 0x531B9328, 0xD58FE186, 0x1ED33223,
+ 0xEF8580F6, 0x24D95353, 0xA24D21FD, 0x6911F258,
+ 0x7414C2E0, 0xBF481145, 0x39DC63EB, 0xF280B04E,
+ 0x07AC0536, 0xCCF0D693, 0x4A64A43D, 0x81387798,
+ 0x9C3D4720, 0x57619485, 0xD1F5E62B, 0x1AA9358E,
+ 0xEBFF875B, 0x20A354FE, 0xA6372650, 0x6D6BF5F5,
+ 0x706EC54D, 0xBB3216E8, 0x3DA66446, 0xF6FAB7E3,
+ 0x047A07AD, 0xCF26D408, 0x49B2A6A6, 0x82EE7503,
+ 0x9FEB45BB, 0x54B7961E, 0xD223E4B0, 0x197F3715,
+ 0xE82985C0, 0x23755665, 0xA5E124CB, 0x6EBDF76E,
+ 0x73B8C7D6, 0xB8E41473, 0x3E7066DD, 0xF52CB578,
+ 0x0F580A6C, 0xC404D9C9, 0x4290AB67, 0x89CC78C2,
+ 0x94C9487A, 0x5F959BDF, 0xD901E971, 0x125D3AD4,
+ 0xE30B8801, 0x28575BA4, 0xAEC3290A, 0x659FFAAF,
+ 0x789ACA17, 0xB3C619B2, 0x35526B1C, 0xFE0EB8B9,
+ 0x0C8E08F7, 0xC7D2DB52, 0x4146A9FC, 0x8A1A7A59,
+ 0x971F4AE1, 0x5C439944, 0xDAD7EBEA, 0x118B384F,
+ 0xE0DD8A9A, 0x2B81593F, 0xAD152B91, 0x6649F834,
+ 0x7B4CC88C, 0xB0101B29, 0x36846987, 0xFDD8BA22,
+ 0x08F40F5A, 0xC3A8DCFF, 0x453CAE51, 0x8E607DF4,
+ 0x93654D4C, 0x58399EE9, 0xDEADEC47, 0x15F13FE2,
+ 0xE4A78D37, 0x2FFB5E92, 0xA96F2C3C, 0x6233FF99,
+ 0x7F36CF21, 0xB46A1C84, 0x32FE6E2A, 0xF9A2BD8F,
+ 0x0B220DC1, 0xC07EDE64, 0x46EAACCA, 0x8DB67F6F,
+ 0x90B34FD7, 0x5BEF9C72, 0xDD7BEEDC, 0x16273D79,
+ 0xE7718FAC, 0x2C2D5C09, 0xAAB92EA7, 0x61E5FD02,
+ 0x7CE0CDBA, 0xB7BC1E1F, 0x31286CB1, 0xFA74BF14,
+ 0x1EB014D8, 0xD5ECC77D, 0x5378B5D3, 0x98246676,
+ 0x852156CE, 0x4E7D856B, 0xC8E9F7C5, 0x03B52460,
+ 0xF2E396B5, 0x39BF4510, 0xBF2B37BE, 0x7477E41B,
+ 0x6972D4A3, 0xA22E0706, 0x24BA75A8, 0xEFE6A60D,
+ 0x1D661643, 0xD63AC5E6, 0x50AEB748, 0x9BF264ED,
+ 0x86F75455, 0x4DAB87F0, 0xCB3FF55E, 0x006326FB,
+ 0xF135942E, 0x3A69478B, 0xBCFD3525, 0x77A1E680,
+ 0x6AA4D638, 0xA1F8059D, 0x276C7733, 0xEC30A496,
+ 0x191C11EE, 0xD240C24B, 0x54D4B0E5, 0x9F886340,
+ 0x828D53F8, 0x49D1805D, 0xCF45F2F3, 0x04192156,
+ 0xF54F9383, 0x3E134026, 0xB8873288, 0x73DBE12D,
+ 0x6EDED195, 0xA5820230, 0x2316709E, 0xE84AA33B,
+ 0x1ACA1375, 0xD196C0D0, 0x5702B27E, 0x9C5E61DB,
+ 0x815B5163, 0x4A0782C6, 0xCC93F068, 0x07CF23CD,
+ 0xF6999118, 0x3DC542BD, 0xBB513013, 0x700DE3B6,
+ 0x6D08D30E, 0xA65400AB, 0x20C07205, 0xEB9CA1A0,
+ 0x11E81EB4, 0xDAB4CD11, 0x5C20BFBF, 0x977C6C1A,
+ 0x8A795CA2, 0x41258F07, 0xC7B1FDA9, 0x0CED2E0C,
+ 0xFDBB9CD9, 0x36E74F7C, 0xB0733DD2, 0x7B2FEE77,
+ 0x662ADECF, 0xAD760D6A, 0x2BE27FC4, 0xE0BEAC61,
+ 0x123E1C2F, 0xD962CF8A, 0x5FF6BD24, 0x94AA6E81,
+ 0x89AF5E39, 0x42F38D9C, 0xC467FF32, 0x0F3B2C97,
+ 0xFE6D9E42, 0x35314DE7, 0xB3A53F49, 0x78F9ECEC,
+ 0x65FCDC54, 0xAEA00FF1, 0x28347D5F, 0xE368AEFA,
+ 0x16441B82, 0xDD18C827, 0x5B8CBA89, 0x90D0692C,
+ 0x8DD55994, 0x46898A31, 0xC01DF89F, 0x0B412B3A,
+ 0xFA1799EF, 0x314B4A4A, 0xB7DF38E4, 0x7C83EB41,
+ 0x6186DBF9, 0xAADA085C, 0x2C4E7AF2, 0xE712A957,
+ 0x15921919, 0xDECECABC, 0x585AB812, 0x93066BB7,
+ 0x8E035B0F, 0x455F88AA, 0xC3CBFA04, 0x089729A1,
+ 0xF9C19B74, 0x329D48D1, 0xB4093A7F, 0x7F55E9DA,
+ 0x6250D962, 0xA90C0AC7, 0x2F987869, 0xE4C4ABCC
+ }, {
+ 0x00000000, 0xA6770BB4, 0x979F1129, 0x31E81A9D,
+ 0xF44F2413, 0x52382FA7, 0x63D0353A, 0xC5A73E8E,
+ 0x33EF4E67, 0x959845D3, 0xA4705F4E, 0x020754FA,
+ 0xC7A06A74, 0x61D761C0, 0x503F7B5D, 0xF64870E9,
+ 0x67DE9CCE, 0xC1A9977A, 0xF0418DE7, 0x56368653,
+ 0x9391B8DD, 0x35E6B369, 0x040EA9F4, 0xA279A240,
+ 0x5431D2A9, 0xF246D91D, 0xC3AEC380, 0x65D9C834,
+ 0xA07EF6BA, 0x0609FD0E, 0x37E1E793, 0x9196EC27,
+ 0xCFBD399C, 0x69CA3228, 0x582228B5, 0xFE552301,
+ 0x3BF21D8F, 0x9D85163B, 0xAC6D0CA6, 0x0A1A0712,
+ 0xFC5277FB, 0x5A257C4F, 0x6BCD66D2, 0xCDBA6D66,
+ 0x081D53E8, 0xAE6A585C, 0x9F8242C1, 0x39F54975,
+ 0xA863A552, 0x0E14AEE6, 0x3FFCB47B, 0x998BBFCF,
+ 0x5C2C8141, 0xFA5B8AF5, 0xCBB39068, 0x6DC49BDC,
+ 0x9B8CEB35, 0x3DFBE081, 0x0C13FA1C, 0xAA64F1A8,
+ 0x6FC3CF26, 0xC9B4C492, 0xF85CDE0F, 0x5E2BD5BB,
+ 0x440B7579, 0xE27C7ECD, 0xD3946450, 0x75E36FE4,
+ 0xB044516A, 0x16335ADE, 0x27DB4043, 0x81AC4BF7,
+ 0x77E43B1E, 0xD19330AA, 0xE07B2A37, 0x460C2183,
+ 0x83AB1F0D, 0x25DC14B9, 0x14340E24, 0xB2430590,
+ 0x23D5E9B7, 0x85A2E203, 0xB44AF89E, 0x123DF32A,
+ 0xD79ACDA4, 0x71EDC610, 0x4005DC8D, 0xE672D739,
+ 0x103AA7D0, 0xB64DAC64, 0x87A5B6F9, 0x21D2BD4D,
+ 0xE47583C3, 0x42028877, 0x73EA92EA, 0xD59D995E,
+ 0x8BB64CE5, 0x2DC14751, 0x1C295DCC, 0xBA5E5678,
+ 0x7FF968F6, 0xD98E6342, 0xE86679DF, 0x4E11726B,
+ 0xB8590282, 0x1E2E0936, 0x2FC613AB, 0x89B1181F,
+ 0x4C162691, 0xEA612D25, 0xDB8937B8, 0x7DFE3C0C,
+ 0xEC68D02B, 0x4A1FDB9F, 0x7BF7C102, 0xDD80CAB6,
+ 0x1827F438, 0xBE50FF8C, 0x8FB8E511, 0x29CFEEA5,
+ 0xDF879E4C, 0x79F095F8, 0x48188F65, 0xEE6F84D1,
+ 0x2BC8BA5F, 0x8DBFB1EB, 0xBC57AB76, 0x1A20A0C2,
+ 0x8816EAF2, 0x2E61E146, 0x1F89FBDB, 0xB9FEF06F,
+ 0x7C59CEE1, 0xDA2EC555, 0xEBC6DFC8, 0x4DB1D47C,
+ 0xBBF9A495, 0x1D8EAF21, 0x2C66B5BC, 0x8A11BE08,
+ 0x4FB68086, 0xE9C18B32, 0xD82991AF, 0x7E5E9A1B,
+ 0xEFC8763C, 0x49BF7D88, 0x78576715, 0xDE206CA1,
+ 0x1B87522F, 0xBDF0599B, 0x8C184306, 0x2A6F48B2,
+ 0xDC27385B, 0x7A5033EF, 0x4BB82972, 0xEDCF22C6,
+ 0x28681C48, 0x8E1F17FC, 0xBFF70D61, 0x198006D5,
+ 0x47ABD36E, 0xE1DCD8DA, 0xD034C247, 0x7643C9F3,
+ 0xB3E4F77D, 0x1593FCC9, 0x247BE654, 0x820CEDE0,
+ 0x74449D09, 0xD23396BD, 0xE3DB8C20, 0x45AC8794,
+ 0x800BB91A, 0x267CB2AE, 0x1794A833, 0xB1E3A387,
+ 0x20754FA0, 0x86024414, 0xB7EA5E89, 0x119D553D,
+ 0xD43A6BB3, 0x724D6007, 0x43A57A9A, 0xE5D2712E,
+ 0x139A01C7, 0xB5ED0A73, 0x840510EE, 0x22721B5A,
+ 0xE7D525D4, 0x41A22E60, 0x704A34FD, 0xD63D3F49,
+ 0xCC1D9F8B, 0x6A6A943F, 0x5B828EA2, 0xFDF58516,
+ 0x3852BB98, 0x9E25B02C, 0xAFCDAAB1, 0x09BAA105,
+ 0xFFF2D1EC, 0x5985DA58, 0x686DC0C5, 0xCE1ACB71,
+ 0x0BBDF5FF, 0xADCAFE4B, 0x9C22E4D6, 0x3A55EF62,
+ 0xABC30345, 0x0DB408F1, 0x3C5C126C, 0x9A2B19D8,
+ 0x5F8C2756, 0xF9FB2CE2, 0xC813367F, 0x6E643DCB,
+ 0x982C4D22, 0x3E5B4696, 0x0FB35C0B, 0xA9C457BF,
+ 0x6C636931, 0xCA146285, 0xFBFC7818, 0x5D8B73AC,
+ 0x03A0A617, 0xA5D7ADA3, 0x943FB73E, 0x3248BC8A,
+ 0xF7EF8204, 0x519889B0, 0x6070932D, 0xC6079899,
+ 0x304FE870, 0x9638E3C4, 0xA7D0F959, 0x01A7F2ED,
+ 0xC400CC63, 0x6277C7D7, 0x539FDD4A, 0xF5E8D6FE,
+ 0x647E3AD9, 0xC209316D, 0xF3E12BF0, 0x55962044,
+ 0x90311ECA, 0x3646157E, 0x07AE0FE3, 0xA1D90457,
+ 0x579174BE, 0xF1E67F0A, 0xC00E6597, 0x66796E23,
+ 0xA3DE50AD, 0x05A95B19, 0x34414184, 0x92364A30
+ }, {
+ 0x00000000, 0xCCAA009E, 0x4225077D, 0x8E8F07E3,
+ 0x844A0EFA, 0x48E00E64, 0xC66F0987, 0x0AC50919,
+ 0xD3E51BB5, 0x1F4F1B2B, 0x91C01CC8, 0x5D6A1C56,
+ 0x57AF154F, 0x9B0515D1, 0x158A1232, 0xD92012AC,
+ 0x7CBB312B, 0xB01131B5, 0x3E9E3656, 0xF23436C8,
+ 0xF8F13FD1, 0x345B3F4F, 0xBAD438AC, 0x767E3832,
+ 0xAF5E2A9E, 0x63F42A00, 0xED7B2DE3, 0x21D12D7D,
+ 0x2B142464, 0xE7BE24FA, 0x69312319, 0xA59B2387,
+ 0xF9766256, 0x35DC62C8, 0xBB53652B, 0x77F965B5,
+ 0x7D3C6CAC, 0xB1966C32, 0x3F196BD1, 0xF3B36B4F,
+ 0x2A9379E3, 0xE639797D, 0x68B67E9E, 0xA41C7E00,
+ 0xAED97719, 0x62737787, 0xECFC7064, 0x205670FA,
+ 0x85CD537D, 0x496753E3, 0xC7E85400, 0x0B42549E,
+ 0x01875D87, 0xCD2D5D19, 0x43A25AFA, 0x8F085A64,
+ 0x562848C8, 0x9A824856, 0x140D4FB5, 0xD8A74F2B,
+ 0xD2624632, 0x1EC846AC, 0x9047414F, 0x5CED41D1,
+ 0x299DC2ED, 0xE537C273, 0x6BB8C590, 0xA712C50E,
+ 0xADD7CC17, 0x617DCC89, 0xEFF2CB6A, 0x2358CBF4,
+ 0xFA78D958, 0x36D2D9C6, 0xB85DDE25, 0x74F7DEBB,
+ 0x7E32D7A2, 0xB298D73C, 0x3C17D0DF, 0xF0BDD041,
+ 0x5526F3C6, 0x998CF358, 0x1703F4BB, 0xDBA9F425,
+ 0xD16CFD3C, 0x1DC6FDA2, 0x9349FA41, 0x5FE3FADF,
+ 0x86C3E873, 0x4A69E8ED, 0xC4E6EF0E, 0x084CEF90,
+ 0x0289E689, 0xCE23E617, 0x40ACE1F4, 0x8C06E16A,
+ 0xD0EBA0BB, 0x1C41A025, 0x92CEA7C6, 0x5E64A758,
+ 0x54A1AE41, 0x980BAEDF, 0x1684A93C, 0xDA2EA9A2,
+ 0x030EBB0E, 0xCFA4BB90, 0x412BBC73, 0x8D81BCED,
+ 0x8744B5F4, 0x4BEEB56A, 0xC561B289, 0x09CBB217,
+ 0xAC509190, 0x60FA910E, 0xEE7596ED, 0x22DF9673,
+ 0x281A9F6A, 0xE4B09FF4, 0x6A3F9817, 0xA6959889,
+ 0x7FB58A25, 0xB31F8ABB, 0x3D908D58, 0xF13A8DC6,
+ 0xFBFF84DF, 0x37558441, 0xB9DA83A2, 0x7570833C,
+ 0x533B85DA, 0x9F918544, 0x111E82A7, 0xDDB48239,
+ 0xD7718B20, 0x1BDB8BBE, 0x95548C5D, 0x59FE8CC3,
+ 0x80DE9E6F, 0x4C749EF1, 0xC2FB9912, 0x0E51998C,
+ 0x04949095, 0xC83E900B, 0x46B197E8, 0x8A1B9776,
+ 0x2F80B4F1, 0xE32AB46F, 0x6DA5B38C, 0xA10FB312,
+ 0xABCABA0B, 0x6760BA95, 0xE9EFBD76, 0x2545BDE8,
+ 0xFC65AF44, 0x30CFAFDA, 0xBE40A839, 0x72EAA8A7,
+ 0x782FA1BE, 0xB485A120, 0x3A0AA6C3, 0xF6A0A65D,
+ 0xAA4DE78C, 0x66E7E712, 0xE868E0F1, 0x24C2E06F,
+ 0x2E07E976, 0xE2ADE9E8, 0x6C22EE0B, 0xA088EE95,
+ 0x79A8FC39, 0xB502FCA7, 0x3B8DFB44, 0xF727FBDA,
+ 0xFDE2F2C3, 0x3148F25D, 0xBFC7F5BE, 0x736DF520,
+ 0xD6F6D6A7, 0x1A5CD639, 0x94D3D1DA, 0x5879D144,
+ 0x52BCD85D, 0x9E16D8C3, 0x1099DF20, 0xDC33DFBE,
+ 0x0513CD12, 0xC9B9CD8C, 0x4736CA6F, 0x8B9CCAF1,
+ 0x8159C3E8, 0x4DF3C376, 0xC37CC495, 0x0FD6C40B,
+ 0x7AA64737, 0xB60C47A9, 0x3883404A, 0xF42940D4,
+ 0xFEEC49CD, 0x32464953, 0xBCC94EB0, 0x70634E2E,
+ 0xA9435C82, 0x65E95C1C, 0xEB665BFF, 0x27CC5B61,
+ 0x2D095278, 0xE1A352E6, 0x6F2C5505, 0xA386559B,
+ 0x061D761C, 0xCAB77682, 0x44387161, 0x889271FF,
+ 0x825778E6, 0x4EFD7878, 0xC0727F9B, 0x0CD87F05,
+ 0xD5F86DA9, 0x19526D37, 0x97DD6AD4, 0x5B776A4A,
+ 0x51B26353, 0x9D1863CD, 0x1397642E, 0xDF3D64B0,
+ 0x83D02561, 0x4F7A25FF, 0xC1F5221C, 0x0D5F2282,
+ 0x079A2B9B, 0xCB302B05, 0x45BF2CE6, 0x89152C78,
+ 0x50353ED4, 0x9C9F3E4A, 0x121039A9, 0xDEBA3937,
+ 0xD47F302E, 0x18D530B0, 0x965A3753, 0x5AF037CD,
+ 0xFF6B144A, 0x33C114D4, 0xBD4E1337, 0x71E413A9,
+ 0x7B211AB0, 0xB78B1A2E, 0x39041DCD, 0xF5AE1D53,
+ 0x2C8E0FFF, 0xE0240F61, 0x6EAB0882, 0xA201081C,
+ 0xA8C40105, 0x646E019B, 0xEAE10678, 0x264B06E6
+ }
+};
diff --git a/Utilities/cmliblzma/liblzma/check/crc32_tablegen.c b/Utilities/cmliblzma/liblzma/check/crc32_tablegen.c
new file mode 100644
index 0000000000..31a4d2751d
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc32_tablegen.c
@@ -0,0 +1,117 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file crc32_tablegen.c
+/// \brief Generate crc32_table_le.h and crc32_table_be.h
+///
+/// Compiling: gcc -std=c99 -o crc32_tablegen crc32_tablegen.c
+/// Add -DWORDS_BIGENDIAN to generate big endian table.
+/// Add -DLZ_HASH_TABLE to generate lz_encoder_hash_table.h (little endian).
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <stdio.h>
+#include "../../common/tuklib_integer.h"
+
+
+static uint32_t crc32_table[8][256];
+
+
+static void
+init_crc32_table(void)
+{
+ static const uint32_t poly32 = UINT32_C(0xEDB88320);
+
+ for (size_t s = 0; s < 8; ++s) {
+ for (size_t b = 0; b < 256; ++b) {
+ uint32_t r = s == 0 ? b : crc32_table[s - 1][b];
+
+ for (size_t i = 0; i < 8; ++i) {
+ if (r & 1)
+ r = (r >> 1) ^ poly32;
+ else
+ r >>= 1;
+ }
+
+ crc32_table[s][b] = r;
+ }
+ }
+
+#ifdef WORDS_BIGENDIAN
+ for (size_t s = 0; s < 8; ++s)
+ for (size_t b = 0; b < 256; ++b)
+ crc32_table[s][b] = bswap32(crc32_table[s][b]);
+#endif
+
+ return;
+}
+
+
+static void
+print_crc32_table(void)
+{
+ printf("/* This file has been automatically generated by "
+ "crc32_tablegen.c. */\n\n"
+ "const uint32_t lzma_crc32_table[8][256] = {\n\t{");
+
+ for (size_t s = 0; s < 8; ++s) {
+ for (size_t b = 0; b < 256; ++b) {
+ if ((b % 4) == 0)
+ printf("\n\t\t");
+
+ printf("0x%08" PRIX32, crc32_table[s][b]);
+
+ if (b != 255)
+ printf(",%s", (b+1) % 4 == 0 ? "" : " ");
+ }
+
+ if (s == 7)
+ printf("\n\t}\n};\n");
+ else
+ printf("\n\t}, {");
+ }
+
+ return;
+}
+
+
+static void
+print_lz_table(void)
+{
+ printf("/* This file has been automatically generated by "
+ "crc32_tablegen.c. */\n\n"
+ "const uint32_t lzma_lz_hash_table[256] = {");
+
+ for (size_t b = 0; b < 256; ++b) {
+ if ((b % 4) == 0)
+ printf("\n\t");
+
+ printf("0x%08" PRIX32, crc32_table[0][b]);
+
+ if (b != 255)
+ printf(",%s", (b+1) % 4 == 0 ? "" : " ");
+ }
+
+ printf("\n};\n");
+
+ return;
+}
+
+
+int
+main(void)
+{
+ init_crc32_table();
+
+#ifdef LZ_HASH_TABLE
+ print_lz_table();
+#else
+ print_crc32_table();
+#endif
+
+ return 0;
+}
diff --git a/Utilities/cmliblzma/liblzma/check/crc32_x86.S b/Utilities/cmliblzma/liblzma/check/crc32_x86.S
new file mode 100644
index 0000000000..67f68a4145
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc32_x86.S
@@ -0,0 +1,304 @@
+/*
+ * Speed-optimized CRC32 using slicing-by-eight algorithm
+ *
+ * This uses only i386 instructions, but it is optimized for i686 and later
+ * (including e.g. Pentium II/III/IV, Athlon XP, and Core 2). For i586
+ * (e.g. Pentium), slicing-by-four would be better, and even the C version
+ * of slicing-by-eight built with gcc -march=i586 tends to be a little bit
+ * better than this. Very few probably run this code on i586 or older x86
+ * so this shouldn't be a problem in practice.
+ *
+ * Authors: Igor Pavlov (original version)
+ * Lasse Collin (AT&T syntax, PIC support, better portability)
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * This code needs lzma_crc32_table, which can be created using the
+ * following C code:
+
+uint32_t lzma_crc32_table[8][256];
+
+void
+init_table(void)
+{
+ // IEEE-802.3
+ static const uint32_t poly32 = UINT32_C(0xEDB88320);
+
+ // Castagnoli
+ // static const uint32_t poly32 = UINT32_C(0x82F63B78);
+
+ // Koopman
+ // static const uint32_t poly32 = UINT32_C(0xEB31D82E);
+
+ for (size_t s = 0; s < 8; ++s) {
+ for (size_t b = 0; b < 256; ++b) {
+ uint32_t r = s == 0 ? b : lzma_crc32_table[s - 1][b];
+
+ for (size_t i = 0; i < 8; ++i) {
+ if (r & 1)
+ r = (r >> 1) ^ poly32;
+ else
+ r >>= 1;
+ }
+
+ lzma_crc32_table[s][b] = r;
+ }
+ }
+}
+
+ * The prototype of the CRC32 function:
+ * extern uint32_t lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc);
+ */
+
+/*
+ * On some systems, the functions need to be prefixed. The prefix is
+ * usually an underscore.
+ */
+#ifndef __USER_LABEL_PREFIX__
+# define __USER_LABEL_PREFIX__
+#endif
+#define MAKE_SYM_CAT(prefix, sym) prefix ## sym
+#define MAKE_SYM(prefix, sym) MAKE_SYM_CAT(prefix, sym)
+#define LZMA_CRC32 MAKE_SYM(__USER_LABEL_PREFIX__, lzma_crc32)
+#define LZMA_CRC32_TABLE MAKE_SYM(__USER_LABEL_PREFIX__, lzma_crc32_table)
+
+/*
+ * Solaris assembler doesn't have .p2align, and Darwin uses .align
+ * differently than GNU/Linux and Solaris.
+ */
+#if defined(__APPLE__) || defined(__MSDOS__)
+# define ALIGN(pow2, abs) .align pow2
+#else
+# define ALIGN(pow2, abs) .align abs
+#endif
+
+ .text
+ .globl LZMA_CRC32
+
+#if !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) \
+ && !defined(__MSDOS__)
+ .type LZMA_CRC32, @function
+#endif
+
+ ALIGN(4, 16)
+LZMA_CRC32:
+ /*
+ * Register usage:
+ * %eax crc
+ * %esi buf
+ * %edi size or buf + size
+ * %ebx lzma_crc32_table
+ * %ebp Table index
+ * %ecx Temporary
+ * %edx Temporary
+ */
+ pushl %ebx
+ pushl %esi
+ pushl %edi
+ pushl %ebp
+ movl 0x14(%esp), %esi /* buf */
+ movl 0x18(%esp), %edi /* size */
+ movl 0x1C(%esp), %eax /* crc */
+
+ /*
+ * Store the address of lzma_crc32_table to %ebx. This is needed to
+ * get position-independent code (PIC).
+ *
+ * The PIC macro is defined by libtool, while __PIC__ is defined
+ * by GCC but only on some systems. Testing for both makes it simpler
+ * to test this code without libtool, and keeps the code working also
+ * when built with libtool but using something else than GCC.
+ *
+ * I understood that libtool may define PIC on Windows even though
+ * the code in Windows DLLs is not PIC in sense that it is in ELF
+ * binaries, so we need a separate check to always use the non-PIC
+ * code on Windows.
+ */
+#if (!defined(PIC) && !defined(__PIC__)) \
+ || (defined(_WIN32) || defined(__CYGWIN__))
+ /* Not PIC */
+ movl $ LZMA_CRC32_TABLE, %ebx
+#elif defined(__APPLE__)
+ /* Mach-O */
+ call .L_get_pc
+.L_pic:
+ leal .L_lzma_crc32_table$non_lazy_ptr-.L_pic(%ebx), %ebx
+ movl (%ebx), %ebx
+#else
+ /* ELF */
+ call .L_get_pc
+ addl $_GLOBAL_OFFSET_TABLE_, %ebx
+ movl LZMA_CRC32_TABLE@GOT(%ebx), %ebx
+#endif
+
+ /* Complement the initial value. */
+ notl %eax
+
+ ALIGN(4, 16)
+.L_align:
+ /*
+ * Check if there is enough input to use slicing-by-eight.
+ * We need 16 bytes, because the loop pre-reads eight bytes.
+ */
+ cmpl $16, %edi
+ jb .L_rest
+
+ /* Check if we have reached alignment of eight bytes. */
+ testl $7, %esi
+ jz .L_slice
+
+ /* Calculate CRC of the next input byte. */
+ movzbl (%esi), %ebp
+ incl %esi
+ movzbl %al, %ecx
+ xorl %ecx, %ebp
+ shrl $8, %eax
+ xorl (%ebx, %ebp, 4), %eax
+ decl %edi
+ jmp .L_align
+
+ ALIGN(2, 4)
+.L_slice:
+ /*
+ * If we get here, there's at least 16 bytes of aligned input
+ * available. Make %edi multiple of eight bytes. Store the possible
+ * remainder over the "size" variable in the argument stack.
+ */
+ movl %edi, 0x18(%esp)
+ andl $-8, %edi
+ subl %edi, 0x18(%esp)
+
+ /*
+ * Let %edi be buf + size - 8 while running the main loop. This way
+ * we can compare for equality to determine when exit the loop.
+ */
+ addl %esi, %edi
+ subl $8, %edi
+
+ /* Read in the first eight aligned bytes. */
+ xorl (%esi), %eax
+ movl 4(%esi), %ecx
+ movzbl %cl, %ebp
+
+.L_loop:
+ movl 0x0C00(%ebx, %ebp, 4), %edx
+ movzbl %ch, %ebp
+ xorl 0x0800(%ebx, %ebp, 4), %edx
+ shrl $16, %ecx
+ xorl 8(%esi), %edx
+ movzbl %cl, %ebp
+ xorl 0x0400(%ebx, %ebp, 4), %edx
+ movzbl %ch, %ebp
+ xorl (%ebx, %ebp, 4), %edx
+ movzbl %al, %ebp
+
+ /*
+ * Read the next four bytes, for which the CRC is calculated
+ * on the next interation of the loop.
+ */
+ movl 12(%esi), %ecx
+
+ xorl 0x1C00(%ebx, %ebp, 4), %edx
+ movzbl %ah, %ebp
+ shrl $16, %eax
+ xorl 0x1800(%ebx, %ebp, 4), %edx
+ movzbl %ah, %ebp
+ movzbl %al, %eax
+ movl 0x1400(%ebx, %eax, 4), %eax
+ addl $8, %esi
+ xorl %edx, %eax
+ xorl 0x1000(%ebx, %ebp, 4), %eax
+
+ /* Check for end of aligned input. */
+ cmpl %edi, %esi
+ movzbl %cl, %ebp
+ jne .L_loop
+
+ /*
+ * Process the remaining eight bytes, which we have already
+ * copied to %ecx and %edx.
+ */
+ movl 0x0C00(%ebx, %ebp, 4), %edx
+ movzbl %ch, %ebp
+ xorl 0x0800(%ebx, %ebp, 4), %edx
+ shrl $16, %ecx
+ movzbl %cl, %ebp
+ xorl 0x0400(%ebx, %ebp, 4), %edx
+ movzbl %ch, %ebp
+ xorl (%ebx, %ebp, 4), %edx
+ movzbl %al, %ebp
+
+ xorl 0x1C00(%ebx, %ebp, 4), %edx
+ movzbl %ah, %ebp
+ shrl $16, %eax
+ xorl 0x1800(%ebx, %ebp, 4), %edx
+ movzbl %ah, %ebp
+ movzbl %al, %eax
+ movl 0x1400(%ebx, %eax, 4), %eax
+ addl $8, %esi
+ xorl %edx, %eax
+ xorl 0x1000(%ebx, %ebp, 4), %eax
+
+ /* Copy the number of remaining bytes to %edi. */
+ movl 0x18(%esp), %edi
+
+.L_rest:
+ /* Check for end of input. */
+ testl %edi, %edi
+ jz .L_return
+
+ /* Calculate CRC of the next input byte. */
+ movzbl (%esi), %ebp
+ incl %esi
+ movzbl %al, %ecx
+ xorl %ecx, %ebp
+ shrl $8, %eax
+ xorl (%ebx, %ebp, 4), %eax
+ decl %edi
+ jmp .L_rest
+
+.L_return:
+ /* Complement the final value. */
+ notl %eax
+
+ popl %ebp
+ popl %edi
+ popl %esi
+ popl %ebx
+ ret
+
+#if defined(PIC) || defined(__PIC__)
+ ALIGN(4, 16)
+.L_get_pc:
+ movl (%esp), %ebx
+ ret
+#endif
+
+#if defined(__APPLE__) && (defined(PIC) || defined(__PIC__))
+ /* Mach-O PIC */
+ .section __IMPORT,__pointers,non_lazy_symbol_pointers
+.L_lzma_crc32_table$non_lazy_ptr:
+ .indirect_symbol LZMA_CRC32_TABLE
+ .long 0
+
+#elif defined(_WIN32) || defined(__CYGWIN__)
+# ifdef DLL_EXPORT
+ /* This is equivalent of __declspec(dllexport). */
+ .section .drectve
+ .ascii " -export:lzma_crc32"
+# endif
+
+#elif !defined(__MSDOS__)
+ /* ELF */
+ .size LZMA_CRC32, .-LZMA_CRC32
+#endif
+
+/*
+ * This is needed to support non-executable stack. It's ugly to
+ * use __linux__ here, but I don't know a way to detect when
+ * we are using GNU assembler.
+ */
+#if defined(__ELF__) && defined(__linux__)
+ .section .note.GNU-stack,"",@progbits
+#endif
diff --git a/Utilities/cmliblzma/liblzma/check/crc64_fast.c b/Utilities/cmliblzma/liblzma/check/crc64_fast.c
new file mode 100644
index 0000000000..1436557af3
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc64_fast.c
@@ -0,0 +1,74 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file crc64.c
+/// \brief CRC64 calculation
+///
+/// Calculate the CRC64 using the slice-by-four algorithm. This is the same
+/// idea that is used in crc32_fast.c, but for CRC64 we use only four tables
+/// instead of eight to avoid increasing CPU cache usage.
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "check.h"
+#include "crc_macros.h"
+
+
+#ifdef WORDS_BIGENDIAN
+# define A1(x) ((x) >> 56)
+#else
+# define A1 A
+#endif
+
+
+// See the comments in crc32_fast.c. They aren't duplicated here.
+extern LZMA_API(uint64_t)
+lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
+{
+ crc = ~crc;
+
+#ifdef WORDS_BIGENDIAN
+ crc = bswap64(crc);
+#endif
+
+ if (size > 4) {
+ const uint8_t *limit;
+
+ while ((uintptr_t)(buf) & 3) {
+ crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
+ --size;
+ }
+
+ limit = buf + (size & ~(size_t)(3));
+ size &= (size_t)(3);
+
+ while (buf < limit) {
+#ifdef WORDS_BIGENDIAN
+ const uint32_t tmp = (crc >> 32)
+ ^ *(const uint32_t *)(buf);
+#else
+ const uint32_t tmp = crc ^ *(const uint32_t *)(buf);
+#endif
+ buf += 4;
+
+ crc = lzma_crc64_table[3][A(tmp)]
+ ^ lzma_crc64_table[2][B(tmp)]
+ ^ S32(crc)
+ ^ lzma_crc64_table[1][C(tmp)]
+ ^ lzma_crc64_table[0][D(tmp)];
+ }
+ }
+
+ while (size-- != 0)
+ crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
+
+#ifdef WORDS_BIGENDIAN
+ crc = bswap64(crc);
+#endif
+
+ return ~crc;
+}
diff --git a/Utilities/cmliblzma/liblzma/check/crc64_small.c b/Utilities/cmliblzma/liblzma/check/crc64_small.c
new file mode 100644
index 0000000000..55d72316bc
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc64_small.c
@@ -0,0 +1,53 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file crc64_small.c
+/// \brief CRC64 calculation (size-optimized)
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "check.h"
+
+
+static uint64_t crc64_table[256];
+
+
+static void
+crc64_init(void)
+{
+ static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
+
+ for (size_t b = 0; b < 256; ++b) {
+ uint64_t r = b;
+ for (size_t i = 0; i < 8; ++i) {
+ if (r & 1)
+ r = (r >> 1) ^ poly64;
+ else
+ r >>= 1;
+ }
+
+ crc64_table[b] = r;
+ }
+
+ return;
+}
+
+
+extern LZMA_API(uint64_t)
+lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
+{
+ mythread_once(crc64_init);
+
+ crc = ~crc;
+
+ while (size != 0) {
+ crc = crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
+ --size;
+ }
+
+ return ~crc;
+}
diff --git a/Utilities/cmliblzma/liblzma/check/crc64_table.c b/Utilities/cmliblzma/liblzma/check/crc64_table.c
new file mode 100644
index 0000000000..1fbcd94703
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc64_table.c
@@ -0,0 +1,19 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file crc64_table.c
+/// \brief Precalculated CRC64 table with correct endianness
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+
+#ifdef WORDS_BIGENDIAN
+# include "crc64_table_be.h"
+#else
+# include "crc64_table_le.h"
+#endif
diff --git a/Utilities/cmliblzma/liblzma/check/crc64_table_be.h b/Utilities/cmliblzma/liblzma/check/crc64_table_be.h
new file mode 100644
index 0000000000..ea074f397a
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc64_table_be.h
@@ -0,0 +1,521 @@
+/* This file has been automatically generated by crc64_tablegen.c. */
+
+const uint64_t lzma_crc64_table[4][256] = {
+ {
+ UINT64_C(0x0000000000000000), UINT64_C(0x6F5FA703BE4C2EB3),
+ UINT64_C(0x5BA040A8573684F4), UINT64_C(0x34FFE7ABE97AAA47),
+ UINT64_C(0x335E8FFF84C3D07B), UINT64_C(0x5C0128FC3A8FFEC8),
+ UINT64_C(0x68FECF57D3F5548F), UINT64_C(0x07A168546DB97A3C),
+ UINT64_C(0x66BC1EFF0987A1F7), UINT64_C(0x09E3B9FCB7CB8F44),
+ UINT64_C(0x3D1C5E575EB12503), UINT64_C(0x5243F954E0FD0BB0),
+ UINT64_C(0x55E291008D44718C), UINT64_C(0x3ABD360333085F3F),
+ UINT64_C(0x0E42D1A8DA72F578), UINT64_C(0x611D76AB643EDBCB),
+ UINT64_C(0x4966335138A19B7D), UINT64_C(0x2639945286EDB5CE),
+ UINT64_C(0x12C673F96F971F89), UINT64_C(0x7D99D4FAD1DB313A),
+ UINT64_C(0x7A38BCAEBC624B06), UINT64_C(0x15671BAD022E65B5),
+ UINT64_C(0x2198FC06EB54CFF2), UINT64_C(0x4EC75B055518E141),
+ UINT64_C(0x2FDA2DAE31263A8A), UINT64_C(0x40858AAD8F6A1439),
+ UINT64_C(0x747A6D066610BE7E), UINT64_C(0x1B25CA05D85C90CD),
+ UINT64_C(0x1C84A251B5E5EAF1), UINT64_C(0x73DB05520BA9C442),
+ UINT64_C(0x4724E2F9E2D36E05), UINT64_C(0x287B45FA5C9F40B6),
+ UINT64_C(0x92CC66A2704237FB), UINT64_C(0xFD93C1A1CE0E1948),
+ UINT64_C(0xC96C260A2774B30F), UINT64_C(0xA633810999389DBC),
+ UINT64_C(0xA192E95DF481E780), UINT64_C(0xCECD4E5E4ACDC933),
+ UINT64_C(0xFA32A9F5A3B76374), UINT64_C(0x956D0EF61DFB4DC7),
+ UINT64_C(0xF470785D79C5960C), UINT64_C(0x9B2FDF5EC789B8BF),
+ UINT64_C(0xAFD038F52EF312F8), UINT64_C(0xC08F9FF690BF3C4B),
+ UINT64_C(0xC72EF7A2FD064677), UINT64_C(0xA87150A1434A68C4),
+ UINT64_C(0x9C8EB70AAA30C283), UINT64_C(0xF3D11009147CEC30),
+ UINT64_C(0xDBAA55F348E3AC86), UINT64_C(0xB4F5F2F0F6AF8235),
+ UINT64_C(0x800A155B1FD52872), UINT64_C(0xEF55B258A19906C1),
+ UINT64_C(0xE8F4DA0CCC207CFD), UINT64_C(0x87AB7D0F726C524E),
+ UINT64_C(0xB3549AA49B16F809), UINT64_C(0xDC0B3DA7255AD6BA),
+ UINT64_C(0xBD164B0C41640D71), UINT64_C(0xD249EC0FFF2823C2),
+ UINT64_C(0xE6B60BA416528985), UINT64_C(0x89E9ACA7A81EA736),
+ UINT64_C(0x8E48C4F3C5A7DD0A), UINT64_C(0xE11763F07BEBF3B9),
+ UINT64_C(0xD5E8845B929159FE), UINT64_C(0xBAB723582CDD774D),
+ UINT64_C(0xA187C3EBCA2BB664), UINT64_C(0xCED864E8746798D7),
+ UINT64_C(0xFA2783439D1D3290), UINT64_C(0x9578244023511C23),
+ UINT64_C(0x92D94C144EE8661F), UINT64_C(0xFD86EB17F0A448AC),
+ UINT64_C(0xC9790CBC19DEE2EB), UINT64_C(0xA626ABBFA792CC58),
+ UINT64_C(0xC73BDD14C3AC1793), UINT64_C(0xA8647A177DE03920),
+ UINT64_C(0x9C9B9DBC949A9367), UINT64_C(0xF3C43ABF2AD6BDD4),
+ UINT64_C(0xF46552EB476FC7E8), UINT64_C(0x9B3AF5E8F923E95B),
+ UINT64_C(0xAFC512431059431C), UINT64_C(0xC09AB540AE156DAF),
+ UINT64_C(0xE8E1F0BAF28A2D19), UINT64_C(0x87BE57B94CC603AA),
+ UINT64_C(0xB341B012A5BCA9ED), UINT64_C(0xDC1E17111BF0875E),
+ UINT64_C(0xDBBF7F457649FD62), UINT64_C(0xB4E0D846C805D3D1),
+ UINT64_C(0x801F3FED217F7996), UINT64_C(0xEF4098EE9F335725),
+ UINT64_C(0x8E5DEE45FB0D8CEE), UINT64_C(0xE10249464541A25D),
+ UINT64_C(0xD5FDAEEDAC3B081A), UINT64_C(0xBAA209EE127726A9),
+ UINT64_C(0xBD0361BA7FCE5C95), UINT64_C(0xD25CC6B9C1827226),
+ UINT64_C(0xE6A3211228F8D861), UINT64_C(0x89FC861196B4F6D2),
+ UINT64_C(0x334BA549BA69819F), UINT64_C(0x5C14024A0425AF2C),
+ UINT64_C(0x68EBE5E1ED5F056B), UINT64_C(0x07B442E253132BD8),
+ UINT64_C(0x00152AB63EAA51E4), UINT64_C(0x6F4A8DB580E67F57),
+ UINT64_C(0x5BB56A1E699CD510), UINT64_C(0x34EACD1DD7D0FBA3),
+ UINT64_C(0x55F7BBB6B3EE2068), UINT64_C(0x3AA81CB50DA20EDB),
+ UINT64_C(0x0E57FB1EE4D8A49C), UINT64_C(0x61085C1D5A948A2F),
+ UINT64_C(0x66A93449372DF013), UINT64_C(0x09F6934A8961DEA0),
+ UINT64_C(0x3D0974E1601B74E7), UINT64_C(0x5256D3E2DE575A54),
+ UINT64_C(0x7A2D961882C81AE2), UINT64_C(0x1572311B3C843451),
+ UINT64_C(0x218DD6B0D5FE9E16), UINT64_C(0x4ED271B36BB2B0A5),
+ UINT64_C(0x497319E7060BCA99), UINT64_C(0x262CBEE4B847E42A),
+ UINT64_C(0x12D3594F513D4E6D), UINT64_C(0x7D8CFE4CEF7160DE),
+ UINT64_C(0x1C9188E78B4FBB15), UINT64_C(0x73CE2FE4350395A6),
+ UINT64_C(0x4731C84FDC793FE1), UINT64_C(0x286E6F4C62351152),
+ UINT64_C(0x2FCF07180F8C6B6E), UINT64_C(0x4090A01BB1C045DD),
+ UINT64_C(0x746F47B058BAEF9A), UINT64_C(0x1B30E0B3E6F6C129),
+ UINT64_C(0x420F87D795576CC9), UINT64_C(0x2D5020D42B1B427A),
+ UINT64_C(0x19AFC77FC261E83D), UINT64_C(0x76F0607C7C2DC68E),
+ UINT64_C(0x715108281194BCB2), UINT64_C(0x1E0EAF2BAFD89201),
+ UINT64_C(0x2AF1488046A23846), UINT64_C(0x45AEEF83F8EE16F5),
+ UINT64_C(0x24B399289CD0CD3E), UINT64_C(0x4BEC3E2B229CE38D),
+ UINT64_C(0x7F13D980CBE649CA), UINT64_C(0x104C7E8375AA6779),
+ UINT64_C(0x17ED16D718131D45), UINT64_C(0x78B2B1D4A65F33F6),
+ UINT64_C(0x4C4D567F4F2599B1), UINT64_C(0x2312F17CF169B702),
+ UINT64_C(0x0B69B486ADF6F7B4), UINT64_C(0x6436138513BAD907),
+ UINT64_C(0x50C9F42EFAC07340), UINT64_C(0x3F96532D448C5DF3),
+ UINT64_C(0x38373B79293527CF), UINT64_C(0x57689C7A9779097C),
+ UINT64_C(0x63977BD17E03A33B), UINT64_C(0x0CC8DCD2C04F8D88),
+ UINT64_C(0x6DD5AA79A4715643), UINT64_C(0x028A0D7A1A3D78F0),
+ UINT64_C(0x3675EAD1F347D2B7), UINT64_C(0x592A4DD24D0BFC04),
+ UINT64_C(0x5E8B258620B28638), UINT64_C(0x31D482859EFEA88B),
+ UINT64_C(0x052B652E778402CC), UINT64_C(0x6A74C22DC9C82C7F),
+ UINT64_C(0xD0C3E175E5155B32), UINT64_C(0xBF9C46765B597581),
+ UINT64_C(0x8B63A1DDB223DFC6), UINT64_C(0xE43C06DE0C6FF175),
+ UINT64_C(0xE39D6E8A61D68B49), UINT64_C(0x8CC2C989DF9AA5FA),
+ UINT64_C(0xB83D2E2236E00FBD), UINT64_C(0xD762892188AC210E),
+ UINT64_C(0xB67FFF8AEC92FAC5), UINT64_C(0xD920588952DED476),
+ UINT64_C(0xEDDFBF22BBA47E31), UINT64_C(0x8280182105E85082),
+ UINT64_C(0x8521707568512ABE), UINT64_C(0xEA7ED776D61D040D),
+ UINT64_C(0xDE8130DD3F67AE4A), UINT64_C(0xB1DE97DE812B80F9),
+ UINT64_C(0x99A5D224DDB4C04F), UINT64_C(0xF6FA752763F8EEFC),
+ UINT64_C(0xC205928C8A8244BB), UINT64_C(0xAD5A358F34CE6A08),
+ UINT64_C(0xAAFB5DDB59771034), UINT64_C(0xC5A4FAD8E73B3E87),
+ UINT64_C(0xF15B1D730E4194C0), UINT64_C(0x9E04BA70B00DBA73),
+ UINT64_C(0xFF19CCDBD43361B8), UINT64_C(0x90466BD86A7F4F0B),
+ UINT64_C(0xA4B98C738305E54C), UINT64_C(0xCBE62B703D49CBFF),
+ UINT64_C(0xCC47432450F0B1C3), UINT64_C(0xA318E427EEBC9F70),
+ UINT64_C(0x97E7038C07C63537), UINT64_C(0xF8B8A48FB98A1B84),
+ UINT64_C(0xE388443C5F7CDAAD), UINT64_C(0x8CD7E33FE130F41E),
+ UINT64_C(0xB8280494084A5E59), UINT64_C(0xD777A397B60670EA),
+ UINT64_C(0xD0D6CBC3DBBF0AD6), UINT64_C(0xBF896CC065F32465),
+ UINT64_C(0x8B768B6B8C898E22), UINT64_C(0xE4292C6832C5A091),
+ UINT64_C(0x85345AC356FB7B5A), UINT64_C(0xEA6BFDC0E8B755E9),
+ UINT64_C(0xDE941A6B01CDFFAE), UINT64_C(0xB1CBBD68BF81D11D),
+ UINT64_C(0xB66AD53CD238AB21), UINT64_C(0xD935723F6C748592),
+ UINT64_C(0xEDCA9594850E2FD5), UINT64_C(0x829532973B420166),
+ UINT64_C(0xAAEE776D67DD41D0), UINT64_C(0xC5B1D06ED9916F63),
+ UINT64_C(0xF14E37C530EBC524), UINT64_C(0x9E1190C68EA7EB97),
+ UINT64_C(0x99B0F892E31E91AB), UINT64_C(0xF6EF5F915D52BF18),
+ UINT64_C(0xC210B83AB428155F), UINT64_C(0xAD4F1F390A643BEC),
+ UINT64_C(0xCC5269926E5AE027), UINT64_C(0xA30DCE91D016CE94),
+ UINT64_C(0x97F2293A396C64D3), UINT64_C(0xF8AD8E3987204A60),
+ UINT64_C(0xFF0CE66DEA99305C), UINT64_C(0x9053416E54D51EEF),
+ UINT64_C(0xA4ACA6C5BDAFB4A8), UINT64_C(0xCBF301C603E39A1B),
+ UINT64_C(0x7144229E2F3EED56), UINT64_C(0x1E1B859D9172C3E5),
+ UINT64_C(0x2AE46236780869A2), UINT64_C(0x45BBC535C6444711),
+ UINT64_C(0x421AAD61ABFD3D2D), UINT64_C(0x2D450A6215B1139E),
+ UINT64_C(0x19BAEDC9FCCBB9D9), UINT64_C(0x76E54ACA4287976A),
+ UINT64_C(0x17F83C6126B94CA1), UINT64_C(0x78A79B6298F56212),
+ UINT64_C(0x4C587CC9718FC855), UINT64_C(0x2307DBCACFC3E6E6),
+ UINT64_C(0x24A6B39EA27A9CDA), UINT64_C(0x4BF9149D1C36B269),
+ UINT64_C(0x7F06F336F54C182E), UINT64_C(0x105954354B00369D),
+ UINT64_C(0x382211CF179F762B), UINT64_C(0x577DB6CCA9D35898),
+ UINT64_C(0x6382516740A9F2DF), UINT64_C(0x0CDDF664FEE5DC6C),
+ UINT64_C(0x0B7C9E30935CA650), UINT64_C(0x642339332D1088E3),
+ UINT64_C(0x50DCDE98C46A22A4), UINT64_C(0x3F83799B7A260C17),
+ UINT64_C(0x5E9E0F301E18D7DC), UINT64_C(0x31C1A833A054F96F),
+ UINT64_C(0x053E4F98492E5328), UINT64_C(0x6A61E89BF7627D9B),
+ UINT64_C(0x6DC080CF9ADB07A7), UINT64_C(0x029F27CC24972914),
+ UINT64_C(0x3660C067CDED8353), UINT64_C(0x593F676473A1ADE0)
+ }, {
+ UINT64_C(0x0000000000000000), UINT64_C(0x0DF1D05C9279E954),
+ UINT64_C(0x1AE2A1B924F3D2A9), UINT64_C(0x171371E5B68A3BFD),
+ UINT64_C(0xB1DA4DDC62497DC1), UINT64_C(0xBC2B9D80F0309495),
+ UINT64_C(0xAB38EC6546BAAF68), UINT64_C(0xA6C93C39D4C3463C),
+ UINT64_C(0xE7AB9517EE3D2210), UINT64_C(0xEA5A454B7C44CB44),
+ UINT64_C(0xFD4934AECACEF0B9), UINT64_C(0xF0B8E4F258B719ED),
+ UINT64_C(0x5671D8CB8C745FD1), UINT64_C(0x5B8008971E0DB685),
+ UINT64_C(0x4C937972A8878D78), UINT64_C(0x4162A92E3AFE642C),
+ UINT64_C(0xCE572B2FDC7B4420), UINT64_C(0xC3A6FB734E02AD74),
+ UINT64_C(0xD4B58A96F8889689), UINT64_C(0xD9445ACA6AF17FDD),
+ UINT64_C(0x7F8D66F3BE3239E1), UINT64_C(0x727CB6AF2C4BD0B5),
+ UINT64_C(0x656FC74A9AC1EB48), UINT64_C(0x689E171608B8021C),
+ UINT64_C(0x29FCBE3832466630), UINT64_C(0x240D6E64A03F8F64),
+ UINT64_C(0x331E1F8116B5B499), UINT64_C(0x3EEFCFDD84CC5DCD),
+ UINT64_C(0x9826F3E4500F1BF1), UINT64_C(0x95D723B8C276F2A5),
+ UINT64_C(0x82C4525D74FCC958), UINT64_C(0x8F358201E685200C),
+ UINT64_C(0x9CAF565EB8F78840), UINT64_C(0x915E86022A8E6114),
+ UINT64_C(0x864DF7E79C045AE9), UINT64_C(0x8BBC27BB0E7DB3BD),
+ UINT64_C(0x2D751B82DABEF581), UINT64_C(0x2084CBDE48C71CD5),
+ UINT64_C(0x3797BA3BFE4D2728), UINT64_C(0x3A666A676C34CE7C),
+ UINT64_C(0x7B04C34956CAAA50), UINT64_C(0x76F51315C4B34304),
+ UINT64_C(0x61E662F0723978F9), UINT64_C(0x6C17B2ACE04091AD),
+ UINT64_C(0xCADE8E953483D791), UINT64_C(0xC72F5EC9A6FA3EC5),
+ UINT64_C(0xD03C2F2C10700538), UINT64_C(0xDDCDFF708209EC6C),
+ UINT64_C(0x52F87D71648CCC60), UINT64_C(0x5F09AD2DF6F52534),
+ UINT64_C(0x481ADCC8407F1EC9), UINT64_C(0x45EB0C94D206F79D),
+ UINT64_C(0xE32230AD06C5B1A1), UINT64_C(0xEED3E0F194BC58F5),
+ UINT64_C(0xF9C0911422366308), UINT64_C(0xF4314148B04F8A5C),
+ UINT64_C(0xB553E8668AB1EE70), UINT64_C(0xB8A2383A18C80724),
+ UINT64_C(0xAFB149DFAE423CD9), UINT64_C(0xA24099833C3BD58D),
+ UINT64_C(0x0489A5BAE8F893B1), UINT64_C(0x097875E67A817AE5),
+ UINT64_C(0x1E6B0403CC0B4118), UINT64_C(0x139AD45F5E72A84C),
+ UINT64_C(0x385FADBC70EF1181), UINT64_C(0x35AE7DE0E296F8D5),
+ UINT64_C(0x22BD0C05541CC328), UINT64_C(0x2F4CDC59C6652A7C),
+ UINT64_C(0x8985E06012A66C40), UINT64_C(0x8474303C80DF8514),
+ UINT64_C(0x936741D93655BEE9), UINT64_C(0x9E969185A42C57BD),
+ UINT64_C(0xDFF438AB9ED23391), UINT64_C(0xD205E8F70CABDAC5),
+ UINT64_C(0xC5169912BA21E138), UINT64_C(0xC8E7494E2858086C),
+ UINT64_C(0x6E2E7577FC9B4E50), UINT64_C(0x63DFA52B6EE2A704),
+ UINT64_C(0x74CCD4CED8689CF9), UINT64_C(0x793D04924A1175AD),
+ UINT64_C(0xF6088693AC9455A1), UINT64_C(0xFBF956CF3EEDBCF5),
+ UINT64_C(0xECEA272A88678708), UINT64_C(0xE11BF7761A1E6E5C),
+ UINT64_C(0x47D2CB4FCEDD2860), UINT64_C(0x4A231B135CA4C134),
+ UINT64_C(0x5D306AF6EA2EFAC9), UINT64_C(0x50C1BAAA7857139D),
+ UINT64_C(0x11A3138442A977B1), UINT64_C(0x1C52C3D8D0D09EE5),
+ UINT64_C(0x0B41B23D665AA518), UINT64_C(0x06B06261F4234C4C),
+ UINT64_C(0xA0795E5820E00A70), UINT64_C(0xAD888E04B299E324),
+ UINT64_C(0xBA9BFFE10413D8D9), UINT64_C(0xB76A2FBD966A318D),
+ UINT64_C(0xA4F0FBE2C81899C1), UINT64_C(0xA9012BBE5A617095),
+ UINT64_C(0xBE125A5BECEB4B68), UINT64_C(0xB3E38A077E92A23C),
+ UINT64_C(0x152AB63EAA51E400), UINT64_C(0x18DB666238280D54),
+ UINT64_C(0x0FC817878EA236A9), UINT64_C(0x0239C7DB1CDBDFFD),
+ UINT64_C(0x435B6EF52625BBD1), UINT64_C(0x4EAABEA9B45C5285),
+ UINT64_C(0x59B9CF4C02D66978), UINT64_C(0x54481F1090AF802C),
+ UINT64_C(0xF2812329446CC610), UINT64_C(0xFF70F375D6152F44),
+ UINT64_C(0xE8638290609F14B9), UINT64_C(0xE59252CCF2E6FDED),
+ UINT64_C(0x6AA7D0CD1463DDE1), UINT64_C(0x67560091861A34B5),
+ UINT64_C(0x7045717430900F48), UINT64_C(0x7DB4A128A2E9E61C),
+ UINT64_C(0xDB7D9D11762AA020), UINT64_C(0xD68C4D4DE4534974),
+ UINT64_C(0xC19F3CA852D97289), UINT64_C(0xCC6EECF4C0A09BDD),
+ UINT64_C(0x8D0C45DAFA5EFFF1), UINT64_C(0x80FD9586682716A5),
+ UINT64_C(0x97EEE463DEAD2D58), UINT64_C(0x9A1F343F4CD4C40C),
+ UINT64_C(0x3CD6080698178230), UINT64_C(0x3127D85A0A6E6B64),
+ UINT64_C(0x2634A9BFBCE45099), UINT64_C(0x2BC579E32E9DB9CD),
+ UINT64_C(0xF5A054D6CA71FB90), UINT64_C(0xF851848A580812C4),
+ UINT64_C(0xEF42F56FEE822939), UINT64_C(0xE2B325337CFBC06D),
+ UINT64_C(0x447A190AA8388651), UINT64_C(0x498BC9563A416F05),
+ UINT64_C(0x5E98B8B38CCB54F8), UINT64_C(0x536968EF1EB2BDAC),
+ UINT64_C(0x120BC1C1244CD980), UINT64_C(0x1FFA119DB63530D4),
+ UINT64_C(0x08E9607800BF0B29), UINT64_C(0x0518B02492C6E27D),
+ UINT64_C(0xA3D18C1D4605A441), UINT64_C(0xAE205C41D47C4D15),
+ UINT64_C(0xB9332DA462F676E8), UINT64_C(0xB4C2FDF8F08F9FBC),
+ UINT64_C(0x3BF77FF9160ABFB0), UINT64_C(0x3606AFA5847356E4),
+ UINT64_C(0x2115DE4032F96D19), UINT64_C(0x2CE40E1CA080844D),
+ UINT64_C(0x8A2D32257443C271), UINT64_C(0x87DCE279E63A2B25),
+ UINT64_C(0x90CF939C50B010D8), UINT64_C(0x9D3E43C0C2C9F98C),
+ UINT64_C(0xDC5CEAEEF8379DA0), UINT64_C(0xD1AD3AB26A4E74F4),
+ UINT64_C(0xC6BE4B57DCC44F09), UINT64_C(0xCB4F9B0B4EBDA65D),
+ UINT64_C(0x6D86A7329A7EE061), UINT64_C(0x6077776E08070935),
+ UINT64_C(0x7764068BBE8D32C8), UINT64_C(0x7A95D6D72CF4DB9C),
+ UINT64_C(0x690F0288728673D0), UINT64_C(0x64FED2D4E0FF9A84),
+ UINT64_C(0x73EDA3315675A179), UINT64_C(0x7E1C736DC40C482D),
+ UINT64_C(0xD8D54F5410CF0E11), UINT64_C(0xD5249F0882B6E745),
+ UINT64_C(0xC237EEED343CDCB8), UINT64_C(0xCFC63EB1A64535EC),
+ UINT64_C(0x8EA4979F9CBB51C0), UINT64_C(0x835547C30EC2B894),
+ UINT64_C(0x94463626B8488369), UINT64_C(0x99B7E67A2A316A3D),
+ UINT64_C(0x3F7EDA43FEF22C01), UINT64_C(0x328F0A1F6C8BC555),
+ UINT64_C(0x259C7BFADA01FEA8), UINT64_C(0x286DABA6487817FC),
+ UINT64_C(0xA75829A7AEFD37F0), UINT64_C(0xAAA9F9FB3C84DEA4),
+ UINT64_C(0xBDBA881E8A0EE559), UINT64_C(0xB04B584218770C0D),
+ UINT64_C(0x1682647BCCB44A31), UINT64_C(0x1B73B4275ECDA365),
+ UINT64_C(0x0C60C5C2E8479898), UINT64_C(0x0191159E7A3E71CC),
+ UINT64_C(0x40F3BCB040C015E0), UINT64_C(0x4D026CECD2B9FCB4),
+ UINT64_C(0x5A111D096433C749), UINT64_C(0x57E0CD55F64A2E1D),
+ UINT64_C(0xF129F16C22896821), UINT64_C(0xFCD82130B0F08175),
+ UINT64_C(0xEBCB50D5067ABA88), UINT64_C(0xE63A8089940353DC),
+ UINT64_C(0xCDFFF96ABA9EEA11), UINT64_C(0xC00E293628E70345),
+ UINT64_C(0xD71D58D39E6D38B8), UINT64_C(0xDAEC888F0C14D1EC),
+ UINT64_C(0x7C25B4B6D8D797D0), UINT64_C(0x71D464EA4AAE7E84),
+ UINT64_C(0x66C7150FFC244579), UINT64_C(0x6B36C5536E5DAC2D),
+ UINT64_C(0x2A546C7D54A3C801), UINT64_C(0x27A5BC21C6DA2155),
+ UINT64_C(0x30B6CDC470501AA8), UINT64_C(0x3D471D98E229F3FC),
+ UINT64_C(0x9B8E21A136EAB5C0), UINT64_C(0x967FF1FDA4935C94),
+ UINT64_C(0x816C801812196769), UINT64_C(0x8C9D504480608E3D),
+ UINT64_C(0x03A8D24566E5AE31), UINT64_C(0x0E590219F49C4765),
+ UINT64_C(0x194A73FC42167C98), UINT64_C(0x14BBA3A0D06F95CC),
+ UINT64_C(0xB2729F9904ACD3F0), UINT64_C(0xBF834FC596D53AA4),
+ UINT64_C(0xA8903E20205F0159), UINT64_C(0xA561EE7CB226E80D),
+ UINT64_C(0xE403475288D88C21), UINT64_C(0xE9F2970E1AA16575),
+ UINT64_C(0xFEE1E6EBAC2B5E88), UINT64_C(0xF31036B73E52B7DC),
+ UINT64_C(0x55D90A8EEA91F1E0), UINT64_C(0x5828DAD278E818B4),
+ UINT64_C(0x4F3BAB37CE622349), UINT64_C(0x42CA7B6B5C1BCA1D),
+ UINT64_C(0x5150AF3402696251), UINT64_C(0x5CA17F6890108B05),
+ UINT64_C(0x4BB20E8D269AB0F8), UINT64_C(0x4643DED1B4E359AC),
+ UINT64_C(0xE08AE2E860201F90), UINT64_C(0xED7B32B4F259F6C4),
+ UINT64_C(0xFA68435144D3CD39), UINT64_C(0xF799930DD6AA246D),
+ UINT64_C(0xB6FB3A23EC544041), UINT64_C(0xBB0AEA7F7E2DA915),
+ UINT64_C(0xAC199B9AC8A792E8), UINT64_C(0xA1E84BC65ADE7BBC),
+ UINT64_C(0x072177FF8E1D3D80), UINT64_C(0x0AD0A7A31C64D4D4),
+ UINT64_C(0x1DC3D646AAEEEF29), UINT64_C(0x1032061A3897067D),
+ UINT64_C(0x9F07841BDE122671), UINT64_C(0x92F654474C6BCF25),
+ UINT64_C(0x85E525A2FAE1F4D8), UINT64_C(0x8814F5FE68981D8C),
+ UINT64_C(0x2EDDC9C7BC5B5BB0), UINT64_C(0x232C199B2E22B2E4),
+ UINT64_C(0x343F687E98A88919), UINT64_C(0x39CEB8220AD1604D),
+ UINT64_C(0x78AC110C302F0461), UINT64_C(0x755DC150A256ED35),
+ UINT64_C(0x624EB0B514DCD6C8), UINT64_C(0x6FBF60E986A53F9C),
+ UINT64_C(0xC9765CD0526679A0), UINT64_C(0xC4878C8CC01F90F4),
+ UINT64_C(0xD394FD697695AB09), UINT64_C(0xDE652D35E4EC425D)
+ }, {
+ UINT64_C(0x0000000000000000), UINT64_C(0xCB6D6A914AE10B3F),
+ UINT64_C(0x96DBD42295C2177E), UINT64_C(0x5DB6BEB3DF231C41),
+ UINT64_C(0x2CB7A9452A852FFC), UINT64_C(0xE7DAC3D4606424C3),
+ UINT64_C(0xBA6C7D67BF473882), UINT64_C(0x710117F6F5A633BD),
+ UINT64_C(0xDD705D247FA5876A), UINT64_C(0x161D37B535448C55),
+ UINT64_C(0x4BAB8906EA679014), UINT64_C(0x80C6E397A0869B2B),
+ UINT64_C(0xF1C7F4615520A896), UINT64_C(0x3AAA9EF01FC1A3A9),
+ UINT64_C(0x671C2043C0E2BFE8), UINT64_C(0xAC714AD28A03B4D7),
+ UINT64_C(0xBAE1BA48FE4A0FD5), UINT64_C(0x718CD0D9B4AB04EA),
+ UINT64_C(0x2C3A6E6A6B8818AB), UINT64_C(0xE75704FB21691394),
+ UINT64_C(0x9656130DD4CF2029), UINT64_C(0x5D3B799C9E2E2B16),
+ UINT64_C(0x008DC72F410D3757), UINT64_C(0xCBE0ADBE0BEC3C68),
+ UINT64_C(0x6791E76C81EF88BF), UINT64_C(0xACFC8DFDCB0E8380),
+ UINT64_C(0xF14A334E142D9FC1), UINT64_C(0x3A2759DF5ECC94FE),
+ UINT64_C(0x4B264E29AB6AA743), UINT64_C(0x804B24B8E18BAC7C),
+ UINT64_C(0xDDFD9A0B3EA8B03D), UINT64_C(0x1690F09A7449BB02),
+ UINT64_C(0xF1DD7B3ED73AC638), UINT64_C(0x3AB011AF9DDBCD07),
+ UINT64_C(0x6706AF1C42F8D146), UINT64_C(0xAC6BC58D0819DA79),
+ UINT64_C(0xDD6AD27BFDBFE9C4), UINT64_C(0x1607B8EAB75EE2FB),
+ UINT64_C(0x4BB10659687DFEBA), UINT64_C(0x80DC6CC8229CF585),
+ UINT64_C(0x2CAD261AA89F4152), UINT64_C(0xE7C04C8BE27E4A6D),
+ UINT64_C(0xBA76F2383D5D562C), UINT64_C(0x711B98A977BC5D13),
+ UINT64_C(0x001A8F5F821A6EAE), UINT64_C(0xCB77E5CEC8FB6591),
+ UINT64_C(0x96C15B7D17D879D0), UINT64_C(0x5DAC31EC5D3972EF),
+ UINT64_C(0x4B3CC1762970C9ED), UINT64_C(0x8051ABE76391C2D2),
+ UINT64_C(0xDDE71554BCB2DE93), UINT64_C(0x168A7FC5F653D5AC),
+ UINT64_C(0x678B683303F5E611), UINT64_C(0xACE602A24914ED2E),
+ UINT64_C(0xF150BC119637F16F), UINT64_C(0x3A3DD680DCD6FA50),
+ UINT64_C(0x964C9C5256D54E87), UINT64_C(0x5D21F6C31C3445B8),
+ UINT64_C(0x00974870C31759F9), UINT64_C(0xCBFA22E189F652C6),
+ UINT64_C(0xBAFB35177C50617B), UINT64_C(0x71965F8636B16A44),
+ UINT64_C(0x2C20E135E9927605), UINT64_C(0xE74D8BA4A3737D3A),
+ UINT64_C(0xE2BBF77CAE758C71), UINT64_C(0x29D69DEDE494874E),
+ UINT64_C(0x7460235E3BB79B0F), UINT64_C(0xBF0D49CF71569030),
+ UINT64_C(0xCE0C5E3984F0A38D), UINT64_C(0x056134A8CE11A8B2),
+ UINT64_C(0x58D78A1B1132B4F3), UINT64_C(0x93BAE08A5BD3BFCC),
+ UINT64_C(0x3FCBAA58D1D00B1B), UINT64_C(0xF4A6C0C99B310024),
+ UINT64_C(0xA9107E7A44121C65), UINT64_C(0x627D14EB0EF3175A),
+ UINT64_C(0x137C031DFB5524E7), UINT64_C(0xD811698CB1B42FD8),
+ UINT64_C(0x85A7D73F6E973399), UINT64_C(0x4ECABDAE247638A6),
+ UINT64_C(0x585A4D34503F83A4), UINT64_C(0x933727A51ADE889B),
+ UINT64_C(0xCE819916C5FD94DA), UINT64_C(0x05ECF3878F1C9FE5),
+ UINT64_C(0x74EDE4717ABAAC58), UINT64_C(0xBF808EE0305BA767),
+ UINT64_C(0xE2363053EF78BB26), UINT64_C(0x295B5AC2A599B019),
+ UINT64_C(0x852A10102F9A04CE), UINT64_C(0x4E477A81657B0FF1),
+ UINT64_C(0x13F1C432BA5813B0), UINT64_C(0xD89CAEA3F0B9188F),
+ UINT64_C(0xA99DB955051F2B32), UINT64_C(0x62F0D3C44FFE200D),
+ UINT64_C(0x3F466D7790DD3C4C), UINT64_C(0xF42B07E6DA3C3773),
+ UINT64_C(0x13668C42794F4A49), UINT64_C(0xD80BE6D333AE4176),
+ UINT64_C(0x85BD5860EC8D5D37), UINT64_C(0x4ED032F1A66C5608),
+ UINT64_C(0x3FD1250753CA65B5), UINT64_C(0xF4BC4F96192B6E8A),
+ UINT64_C(0xA90AF125C60872CB), UINT64_C(0x62679BB48CE979F4),
+ UINT64_C(0xCE16D16606EACD23), UINT64_C(0x057BBBF74C0BC61C),
+ UINT64_C(0x58CD05449328DA5D), UINT64_C(0x93A06FD5D9C9D162),
+ UINT64_C(0xE2A178232C6FE2DF), UINT64_C(0x29CC12B2668EE9E0),
+ UINT64_C(0x747AAC01B9ADF5A1), UINT64_C(0xBF17C690F34CFE9E),
+ UINT64_C(0xA987360A8705459C), UINT64_C(0x62EA5C9BCDE44EA3),
+ UINT64_C(0x3F5CE22812C752E2), UINT64_C(0xF43188B9582659DD),
+ UINT64_C(0x85309F4FAD806A60), UINT64_C(0x4E5DF5DEE761615F),
+ UINT64_C(0x13EB4B6D38427D1E), UINT64_C(0xD88621FC72A37621),
+ UINT64_C(0x74F76B2EF8A0C2F6), UINT64_C(0xBF9A01BFB241C9C9),
+ UINT64_C(0xE22CBF0C6D62D588), UINT64_C(0x2941D59D2783DEB7),
+ UINT64_C(0x5840C26BD225ED0A), UINT64_C(0x932DA8FA98C4E635),
+ UINT64_C(0xCE9B164947E7FA74), UINT64_C(0x05F67CD80D06F14B),
+ UINT64_C(0xC477EFF95CEB18E3), UINT64_C(0x0F1A8568160A13DC),
+ UINT64_C(0x52AC3BDBC9290F9D), UINT64_C(0x99C1514A83C804A2),
+ UINT64_C(0xE8C046BC766E371F), UINT64_C(0x23AD2C2D3C8F3C20),
+ UINT64_C(0x7E1B929EE3AC2061), UINT64_C(0xB576F80FA94D2B5E),
+ UINT64_C(0x1907B2DD234E9F89), UINT64_C(0xD26AD84C69AF94B6),
+ UINT64_C(0x8FDC66FFB68C88F7), UINT64_C(0x44B10C6EFC6D83C8),
+ UINT64_C(0x35B01B9809CBB075), UINT64_C(0xFEDD7109432ABB4A),
+ UINT64_C(0xA36BCFBA9C09A70B), UINT64_C(0x6806A52BD6E8AC34),
+ UINT64_C(0x7E9655B1A2A11736), UINT64_C(0xB5FB3F20E8401C09),
+ UINT64_C(0xE84D819337630048), UINT64_C(0x2320EB027D820B77),
+ UINT64_C(0x5221FCF4882438CA), UINT64_C(0x994C9665C2C533F5),
+ UINT64_C(0xC4FA28D61DE62FB4), UINT64_C(0x0F9742475707248B),
+ UINT64_C(0xA3E60895DD04905C), UINT64_C(0x688B620497E59B63),
+ UINT64_C(0x353DDCB748C68722), UINT64_C(0xFE50B62602278C1D),
+ UINT64_C(0x8F51A1D0F781BFA0), UINT64_C(0x443CCB41BD60B49F),
+ UINT64_C(0x198A75F26243A8DE), UINT64_C(0xD2E71F6328A2A3E1),
+ UINT64_C(0x35AA94C78BD1DEDB), UINT64_C(0xFEC7FE56C130D5E4),
+ UINT64_C(0xA37140E51E13C9A5), UINT64_C(0x681C2A7454F2C29A),
+ UINT64_C(0x191D3D82A154F127), UINT64_C(0xD2705713EBB5FA18),
+ UINT64_C(0x8FC6E9A03496E659), UINT64_C(0x44AB83317E77ED66),
+ UINT64_C(0xE8DAC9E3F47459B1), UINT64_C(0x23B7A372BE95528E),
+ UINT64_C(0x7E011DC161B64ECF), UINT64_C(0xB56C77502B5745F0),
+ UINT64_C(0xC46D60A6DEF1764D), UINT64_C(0x0F000A3794107D72),
+ UINT64_C(0x52B6B4844B336133), UINT64_C(0x99DBDE1501D26A0C),
+ UINT64_C(0x8F4B2E8F759BD10E), UINT64_C(0x4426441E3F7ADA31),
+ UINT64_C(0x1990FAADE059C670), UINT64_C(0xD2FD903CAAB8CD4F),
+ UINT64_C(0xA3FC87CA5F1EFEF2), UINT64_C(0x6891ED5B15FFF5CD),
+ UINT64_C(0x352753E8CADCE98C), UINT64_C(0xFE4A3979803DE2B3),
+ UINT64_C(0x523B73AB0A3E5664), UINT64_C(0x9956193A40DF5D5B),
+ UINT64_C(0xC4E0A7899FFC411A), UINT64_C(0x0F8DCD18D51D4A25),
+ UINT64_C(0x7E8CDAEE20BB7998), UINT64_C(0xB5E1B07F6A5A72A7),
+ UINT64_C(0xE8570ECCB5796EE6), UINT64_C(0x233A645DFF9865D9),
+ UINT64_C(0x26CC1885F29E9492), UINT64_C(0xEDA17214B87F9FAD),
+ UINT64_C(0xB017CCA7675C83EC), UINT64_C(0x7B7AA6362DBD88D3),
+ UINT64_C(0x0A7BB1C0D81BBB6E), UINT64_C(0xC116DB5192FAB051),
+ UINT64_C(0x9CA065E24DD9AC10), UINT64_C(0x57CD0F730738A72F),
+ UINT64_C(0xFBBC45A18D3B13F8), UINT64_C(0x30D12F30C7DA18C7),
+ UINT64_C(0x6D67918318F90486), UINT64_C(0xA60AFB1252180FB9),
+ UINT64_C(0xD70BECE4A7BE3C04), UINT64_C(0x1C668675ED5F373B),
+ UINT64_C(0x41D038C6327C2B7A), UINT64_C(0x8ABD5257789D2045),
+ UINT64_C(0x9C2DA2CD0CD49B47), UINT64_C(0x5740C85C46359078),
+ UINT64_C(0x0AF676EF99168C39), UINT64_C(0xC19B1C7ED3F78706),
+ UINT64_C(0xB09A0B882651B4BB), UINT64_C(0x7BF761196CB0BF84),
+ UINT64_C(0x2641DFAAB393A3C5), UINT64_C(0xED2CB53BF972A8FA),
+ UINT64_C(0x415DFFE973711C2D), UINT64_C(0x8A30957839901712),
+ UINT64_C(0xD7862BCBE6B30B53), UINT64_C(0x1CEB415AAC52006C),
+ UINT64_C(0x6DEA56AC59F433D1), UINT64_C(0xA6873C3D131538EE),
+ UINT64_C(0xFB31828ECC3624AF), UINT64_C(0x305CE81F86D72F90),
+ UINT64_C(0xD71163BB25A452AA), UINT64_C(0x1C7C092A6F455995),
+ UINT64_C(0x41CAB799B06645D4), UINT64_C(0x8AA7DD08FA874EEB),
+ UINT64_C(0xFBA6CAFE0F217D56), UINT64_C(0x30CBA06F45C07669),
+ UINT64_C(0x6D7D1EDC9AE36A28), UINT64_C(0xA610744DD0026117),
+ UINT64_C(0x0A613E9F5A01D5C0), UINT64_C(0xC10C540E10E0DEFF),
+ UINT64_C(0x9CBAEABDCFC3C2BE), UINT64_C(0x57D7802C8522C981),
+ UINT64_C(0x26D697DA7084FA3C), UINT64_C(0xEDBBFD4B3A65F103),
+ UINT64_C(0xB00D43F8E546ED42), UINT64_C(0x7B602969AFA7E67D),
+ UINT64_C(0x6DF0D9F3DBEE5D7F), UINT64_C(0xA69DB362910F5640),
+ UINT64_C(0xFB2B0DD14E2C4A01), UINT64_C(0x3046674004CD413E),
+ UINT64_C(0x414770B6F16B7283), UINT64_C(0x8A2A1A27BB8A79BC),
+ UINT64_C(0xD79CA49464A965FD), UINT64_C(0x1CF1CE052E486EC2),
+ UINT64_C(0xB08084D7A44BDA15), UINT64_C(0x7BEDEE46EEAAD12A),
+ UINT64_C(0x265B50F53189CD6B), UINT64_C(0xED363A647B68C654),
+ UINT64_C(0x9C372D928ECEF5E9), UINT64_C(0x575A4703C42FFED6),
+ UINT64_C(0x0AECF9B01B0CE297), UINT64_C(0xC181932151EDE9A8)
+ }, {
+ UINT64_C(0x0000000000000000), UINT64_C(0xDCA12C225E8AEE1D),
+ UINT64_C(0xB8435944BC14DD3B), UINT64_C(0x64E27566E29E3326),
+ UINT64_C(0x7087B2887829BA77), UINT64_C(0xAC269EAA26A3546A),
+ UINT64_C(0xC8C4EBCCC43D674C), UINT64_C(0x1465C7EE9AB78951),
+ UINT64_C(0xE00E6511F15274EF), UINT64_C(0x3CAF4933AFD89AF2),
+ UINT64_C(0x584D3C554D46A9D4), UINT64_C(0x84EC107713CC47C9),
+ UINT64_C(0x9089D799897BCE98), UINT64_C(0x4C28FBBBD7F12085),
+ UINT64_C(0x28CA8EDD356F13A3), UINT64_C(0xF46BA2FF6BE5FDBE),
+ UINT64_C(0x4503C48DC90A304C), UINT64_C(0x99A2E8AF9780DE51),
+ UINT64_C(0xFD409DC9751EED77), UINT64_C(0x21E1B1EB2B94036A),
+ UINT64_C(0x35847605B1238A3B), UINT64_C(0xE9255A27EFA96426),
+ UINT64_C(0x8DC72F410D375700), UINT64_C(0x5166036353BDB91D),
+ UINT64_C(0xA50DA19C385844A3), UINT64_C(0x79AC8DBE66D2AABE),
+ UINT64_C(0x1D4EF8D8844C9998), UINT64_C(0xC1EFD4FADAC67785),
+ UINT64_C(0xD58A13144071FED4), UINT64_C(0x092B3F361EFB10C9),
+ UINT64_C(0x6DC94A50FC6523EF), UINT64_C(0xB1686672A2EFCDF2),
+ UINT64_C(0x8A06881B93156098), UINT64_C(0x56A7A439CD9F8E85),
+ UINT64_C(0x3245D15F2F01BDA3), UINT64_C(0xEEE4FD7D718B53BE),
+ UINT64_C(0xFA813A93EB3CDAEF), UINT64_C(0x262016B1B5B634F2),
+ UINT64_C(0x42C263D7572807D4), UINT64_C(0x9E634FF509A2E9C9),
+ UINT64_C(0x6A08ED0A62471477), UINT64_C(0xB6A9C1283CCDFA6A),
+ UINT64_C(0xD24BB44EDE53C94C), UINT64_C(0x0EEA986C80D92751),
+ UINT64_C(0x1A8F5F821A6EAE00), UINT64_C(0xC62E73A044E4401D),
+ UINT64_C(0xA2CC06C6A67A733B), UINT64_C(0x7E6D2AE4F8F09D26),
+ UINT64_C(0xCF054C965A1F50D4), UINT64_C(0x13A460B40495BEC9),
+ UINT64_C(0x774615D2E60B8DEF), UINT64_C(0xABE739F0B88163F2),
+ UINT64_C(0xBF82FE1E2236EAA3), UINT64_C(0x6323D23C7CBC04BE),
+ UINT64_C(0x07C1A75A9E223798), UINT64_C(0xDB608B78C0A8D985),
+ UINT64_C(0x2F0B2987AB4D243B), UINT64_C(0xF3AA05A5F5C7CA26),
+ UINT64_C(0x974870C31759F900), UINT64_C(0x4BE95CE149D3171D),
+ UINT64_C(0x5F8C9B0FD3649E4C), UINT64_C(0x832DB72D8DEE7051),
+ UINT64_C(0xE7CFC24B6F704377), UINT64_C(0x3B6EEE6931FAAD6A),
+ UINT64_C(0x91131E980D8418A2), UINT64_C(0x4DB232BA530EF6BF),
+ UINT64_C(0x295047DCB190C599), UINT64_C(0xF5F16BFEEF1A2B84),
+ UINT64_C(0xE194AC1075ADA2D5), UINT64_C(0x3D3580322B274CC8),
+ UINT64_C(0x59D7F554C9B97FEE), UINT64_C(0x8576D976973391F3),
+ UINT64_C(0x711D7B89FCD66C4D), UINT64_C(0xADBC57ABA25C8250),
+ UINT64_C(0xC95E22CD40C2B176), UINT64_C(0x15FF0EEF1E485F6B),
+ UINT64_C(0x019AC90184FFD63A), UINT64_C(0xDD3BE523DA753827),
+ UINT64_C(0xB9D9904538EB0B01), UINT64_C(0x6578BC676661E51C),
+ UINT64_C(0xD410DA15C48E28EE), UINT64_C(0x08B1F6379A04C6F3),
+ UINT64_C(0x6C538351789AF5D5), UINT64_C(0xB0F2AF7326101BC8),
+ UINT64_C(0xA497689DBCA79299), UINT64_C(0x783644BFE22D7C84),
+ UINT64_C(0x1CD431D900B34FA2), UINT64_C(0xC0751DFB5E39A1BF),
+ UINT64_C(0x341EBF0435DC5C01), UINT64_C(0xE8BF93266B56B21C),
+ UINT64_C(0x8C5DE64089C8813A), UINT64_C(0x50FCCA62D7426F27),
+ UINT64_C(0x44990D8C4DF5E676), UINT64_C(0x983821AE137F086B),
+ UINT64_C(0xFCDA54C8F1E13B4D), UINT64_C(0x207B78EAAF6BD550),
+ UINT64_C(0x1B1596839E91783A), UINT64_C(0xC7B4BAA1C01B9627),
+ UINT64_C(0xA356CFC72285A501), UINT64_C(0x7FF7E3E57C0F4B1C),
+ UINT64_C(0x6B92240BE6B8C24D), UINT64_C(0xB7330829B8322C50),
+ UINT64_C(0xD3D17D4F5AAC1F76), UINT64_C(0x0F70516D0426F16B),
+ UINT64_C(0xFB1BF3926FC30CD5), UINT64_C(0x27BADFB03149E2C8),
+ UINT64_C(0x4358AAD6D3D7D1EE), UINT64_C(0x9FF986F48D5D3FF3),
+ UINT64_C(0x8B9C411A17EAB6A2), UINT64_C(0x573D6D38496058BF),
+ UINT64_C(0x33DF185EABFE6B99), UINT64_C(0xEF7E347CF5748584),
+ UINT64_C(0x5E16520E579B4876), UINT64_C(0x82B77E2C0911A66B),
+ UINT64_C(0xE6550B4AEB8F954D), UINT64_C(0x3AF42768B5057B50),
+ UINT64_C(0x2E91E0862FB2F201), UINT64_C(0xF230CCA471381C1C),
+ UINT64_C(0x96D2B9C293A62F3A), UINT64_C(0x4A7395E0CD2CC127),
+ UINT64_C(0xBE18371FA6C93C99), UINT64_C(0x62B91B3DF843D284),
+ UINT64_C(0x065B6E5B1ADDE1A2), UINT64_C(0xDAFA427944570FBF),
+ UINT64_C(0xCE9F8597DEE086EE), UINT64_C(0x123EA9B5806A68F3),
+ UINT64_C(0x76DCDCD362F45BD5), UINT64_C(0xAA7DF0F13C7EB5C8),
+ UINT64_C(0xA739329F30A7E9D6), UINT64_C(0x7B981EBD6E2D07CB),
+ UINT64_C(0x1F7A6BDB8CB334ED), UINT64_C(0xC3DB47F9D239DAF0),
+ UINT64_C(0xD7BE8017488E53A1), UINT64_C(0x0B1FAC351604BDBC),
+ UINT64_C(0x6FFDD953F49A8E9A), UINT64_C(0xB35CF571AA106087),
+ UINT64_C(0x4737578EC1F59D39), UINT64_C(0x9B967BAC9F7F7324),
+ UINT64_C(0xFF740ECA7DE14002), UINT64_C(0x23D522E8236BAE1F),
+ UINT64_C(0x37B0E506B9DC274E), UINT64_C(0xEB11C924E756C953),
+ UINT64_C(0x8FF3BC4205C8FA75), UINT64_C(0x535290605B421468),
+ UINT64_C(0xE23AF612F9ADD99A), UINT64_C(0x3E9BDA30A7273787),
+ UINT64_C(0x5A79AF5645B904A1), UINT64_C(0x86D883741B33EABC),
+ UINT64_C(0x92BD449A818463ED), UINT64_C(0x4E1C68B8DF0E8DF0),
+ UINT64_C(0x2AFE1DDE3D90BED6), UINT64_C(0xF65F31FC631A50CB),
+ UINT64_C(0x0234930308FFAD75), UINT64_C(0xDE95BF2156754368),
+ UINT64_C(0xBA77CA47B4EB704E), UINT64_C(0x66D6E665EA619E53),
+ UINT64_C(0x72B3218B70D61702), UINT64_C(0xAE120DA92E5CF91F),
+ UINT64_C(0xCAF078CFCCC2CA39), UINT64_C(0x165154ED92482424),
+ UINT64_C(0x2D3FBA84A3B2894E), UINT64_C(0xF19E96A6FD386753),
+ UINT64_C(0x957CE3C01FA65475), UINT64_C(0x49DDCFE2412CBA68),
+ UINT64_C(0x5DB8080CDB9B3339), UINT64_C(0x8119242E8511DD24),
+ UINT64_C(0xE5FB5148678FEE02), UINT64_C(0x395A7D6A3905001F),
+ UINT64_C(0xCD31DF9552E0FDA1), UINT64_C(0x1190F3B70C6A13BC),
+ UINT64_C(0x757286D1EEF4209A), UINT64_C(0xA9D3AAF3B07ECE87),
+ UINT64_C(0xBDB66D1D2AC947D6), UINT64_C(0x6117413F7443A9CB),
+ UINT64_C(0x05F5345996DD9AED), UINT64_C(0xD954187BC85774F0),
+ UINT64_C(0x683C7E096AB8B902), UINT64_C(0xB49D522B3432571F),
+ UINT64_C(0xD07F274DD6AC6439), UINT64_C(0x0CDE0B6F88268A24),
+ UINT64_C(0x18BBCC8112910375), UINT64_C(0xC41AE0A34C1BED68),
+ UINT64_C(0xA0F895C5AE85DE4E), UINT64_C(0x7C59B9E7F00F3053),
+ UINT64_C(0x88321B189BEACDED), UINT64_C(0x5493373AC56023F0),
+ UINT64_C(0x3071425C27FE10D6), UINT64_C(0xECD06E7E7974FECB),
+ UINT64_C(0xF8B5A990E3C3779A), UINT64_C(0x241485B2BD499987),
+ UINT64_C(0x40F6F0D45FD7AAA1), UINT64_C(0x9C57DCF6015D44BC),
+ UINT64_C(0x362A2C073D23F174), UINT64_C(0xEA8B002563A91F69),
+ UINT64_C(0x8E69754381372C4F), UINT64_C(0x52C85961DFBDC252),
+ UINT64_C(0x46AD9E8F450A4B03), UINT64_C(0x9A0CB2AD1B80A51E),
+ UINT64_C(0xFEEEC7CBF91E9638), UINT64_C(0x224FEBE9A7947825),
+ UINT64_C(0xD6244916CC71859B), UINT64_C(0x0A85653492FB6B86),
+ UINT64_C(0x6E671052706558A0), UINT64_C(0xB2C63C702EEFB6BD),
+ UINT64_C(0xA6A3FB9EB4583FEC), UINT64_C(0x7A02D7BCEAD2D1F1),
+ UINT64_C(0x1EE0A2DA084CE2D7), UINT64_C(0xC2418EF856C60CCA),
+ UINT64_C(0x7329E88AF429C138), UINT64_C(0xAF88C4A8AAA32F25),
+ UINT64_C(0xCB6AB1CE483D1C03), UINT64_C(0x17CB9DEC16B7F21E),
+ UINT64_C(0x03AE5A028C007B4F), UINT64_C(0xDF0F7620D28A9552),
+ UINT64_C(0xBBED03463014A674), UINT64_C(0x674C2F646E9E4869),
+ UINT64_C(0x93278D9B057BB5D7), UINT64_C(0x4F86A1B95BF15BCA),
+ UINT64_C(0x2B64D4DFB96F68EC), UINT64_C(0xF7C5F8FDE7E586F1),
+ UINT64_C(0xE3A03F137D520FA0), UINT64_C(0x3F01133123D8E1BD),
+ UINT64_C(0x5BE36657C146D29B), UINT64_C(0x87424A759FCC3C86),
+ UINT64_C(0xBC2CA41CAE3691EC), UINT64_C(0x608D883EF0BC7FF1),
+ UINT64_C(0x046FFD5812224CD7), UINT64_C(0xD8CED17A4CA8A2CA),
+ UINT64_C(0xCCAB1694D61F2B9B), UINT64_C(0x100A3AB68895C586),
+ UINT64_C(0x74E84FD06A0BF6A0), UINT64_C(0xA84963F2348118BD),
+ UINT64_C(0x5C22C10D5F64E503), UINT64_C(0x8083ED2F01EE0B1E),
+ UINT64_C(0xE4619849E3703838), UINT64_C(0x38C0B46BBDFAD625),
+ UINT64_C(0x2CA57385274D5F74), UINT64_C(0xF0045FA779C7B169),
+ UINT64_C(0x94E62AC19B59824F), UINT64_C(0x484706E3C5D36C52),
+ UINT64_C(0xF92F6091673CA1A0), UINT64_C(0x258E4CB339B64FBD),
+ UINT64_C(0x416C39D5DB287C9B), UINT64_C(0x9DCD15F785A29286),
+ UINT64_C(0x89A8D2191F151BD7), UINT64_C(0x5509FE3B419FF5CA),
+ UINT64_C(0x31EB8B5DA301C6EC), UINT64_C(0xED4AA77FFD8B28F1),
+ UINT64_C(0x19210580966ED54F), UINT64_C(0xC58029A2C8E43B52),
+ UINT64_C(0xA1625CC42A7A0874), UINT64_C(0x7DC370E674F0E669),
+ UINT64_C(0x69A6B708EE476F38), UINT64_C(0xB5079B2AB0CD8125),
+ UINT64_C(0xD1E5EE4C5253B203), UINT64_C(0x0D44C26E0CD95C1E)
+ }
+};
diff --git a/Utilities/cmliblzma/liblzma/check/crc64_table_le.h b/Utilities/cmliblzma/liblzma/check/crc64_table_le.h
new file mode 100644
index 0000000000..1196b31e13
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc64_table_le.h
@@ -0,0 +1,521 @@
+/* This file has been automatically generated by crc64_tablegen.c. */
+
+const uint64_t lzma_crc64_table[4][256] = {
+ {
+ UINT64_C(0x0000000000000000), UINT64_C(0xB32E4CBE03A75F6F),
+ UINT64_C(0xF4843657A840A05B), UINT64_C(0x47AA7AE9ABE7FF34),
+ UINT64_C(0x7BD0C384FF8F5E33), UINT64_C(0xC8FE8F3AFC28015C),
+ UINT64_C(0x8F54F5D357CFFE68), UINT64_C(0x3C7AB96D5468A107),
+ UINT64_C(0xF7A18709FF1EBC66), UINT64_C(0x448FCBB7FCB9E309),
+ UINT64_C(0x0325B15E575E1C3D), UINT64_C(0xB00BFDE054F94352),
+ UINT64_C(0x8C71448D0091E255), UINT64_C(0x3F5F08330336BD3A),
+ UINT64_C(0x78F572DAA8D1420E), UINT64_C(0xCBDB3E64AB761D61),
+ UINT64_C(0x7D9BA13851336649), UINT64_C(0xCEB5ED8652943926),
+ UINT64_C(0x891F976FF973C612), UINT64_C(0x3A31DBD1FAD4997D),
+ UINT64_C(0x064B62BCAEBC387A), UINT64_C(0xB5652E02AD1B6715),
+ UINT64_C(0xF2CF54EB06FC9821), UINT64_C(0x41E11855055BC74E),
+ UINT64_C(0x8A3A2631AE2DDA2F), UINT64_C(0x39146A8FAD8A8540),
+ UINT64_C(0x7EBE1066066D7A74), UINT64_C(0xCD905CD805CA251B),
+ UINT64_C(0xF1EAE5B551A2841C), UINT64_C(0x42C4A90B5205DB73),
+ UINT64_C(0x056ED3E2F9E22447), UINT64_C(0xB6409F5CFA457B28),
+ UINT64_C(0xFB374270A266CC92), UINT64_C(0x48190ECEA1C193FD),
+ UINT64_C(0x0FB374270A266CC9), UINT64_C(0xBC9D3899098133A6),
+ UINT64_C(0x80E781F45DE992A1), UINT64_C(0x33C9CD4A5E4ECDCE),
+ UINT64_C(0x7463B7A3F5A932FA), UINT64_C(0xC74DFB1DF60E6D95),
+ UINT64_C(0x0C96C5795D7870F4), UINT64_C(0xBFB889C75EDF2F9B),
+ UINT64_C(0xF812F32EF538D0AF), UINT64_C(0x4B3CBF90F69F8FC0),
+ UINT64_C(0x774606FDA2F72EC7), UINT64_C(0xC4684A43A15071A8),
+ UINT64_C(0x83C230AA0AB78E9C), UINT64_C(0x30EC7C140910D1F3),
+ UINT64_C(0x86ACE348F355AADB), UINT64_C(0x3582AFF6F0F2F5B4),
+ UINT64_C(0x7228D51F5B150A80), UINT64_C(0xC10699A158B255EF),
+ UINT64_C(0xFD7C20CC0CDAF4E8), UINT64_C(0x4E526C720F7DAB87),
+ UINT64_C(0x09F8169BA49A54B3), UINT64_C(0xBAD65A25A73D0BDC),
+ UINT64_C(0x710D64410C4B16BD), UINT64_C(0xC22328FF0FEC49D2),
+ UINT64_C(0x85895216A40BB6E6), UINT64_C(0x36A71EA8A7ACE989),
+ UINT64_C(0x0ADDA7C5F3C4488E), UINT64_C(0xB9F3EB7BF06317E1),
+ UINT64_C(0xFE5991925B84E8D5), UINT64_C(0x4D77DD2C5823B7BA),
+ UINT64_C(0x64B62BCAEBC387A1), UINT64_C(0xD7986774E864D8CE),
+ UINT64_C(0x90321D9D438327FA), UINT64_C(0x231C512340247895),
+ UINT64_C(0x1F66E84E144CD992), UINT64_C(0xAC48A4F017EB86FD),
+ UINT64_C(0xEBE2DE19BC0C79C9), UINT64_C(0x58CC92A7BFAB26A6),
+ UINT64_C(0x9317ACC314DD3BC7), UINT64_C(0x2039E07D177A64A8),
+ UINT64_C(0x67939A94BC9D9B9C), UINT64_C(0xD4BDD62ABF3AC4F3),
+ UINT64_C(0xE8C76F47EB5265F4), UINT64_C(0x5BE923F9E8F53A9B),
+ UINT64_C(0x1C4359104312C5AF), UINT64_C(0xAF6D15AE40B59AC0),
+ UINT64_C(0x192D8AF2BAF0E1E8), UINT64_C(0xAA03C64CB957BE87),
+ UINT64_C(0xEDA9BCA512B041B3), UINT64_C(0x5E87F01B11171EDC),
+ UINT64_C(0x62FD4976457FBFDB), UINT64_C(0xD1D305C846D8E0B4),
+ UINT64_C(0x96797F21ED3F1F80), UINT64_C(0x2557339FEE9840EF),
+ UINT64_C(0xEE8C0DFB45EE5D8E), UINT64_C(0x5DA24145464902E1),
+ UINT64_C(0x1A083BACEDAEFDD5), UINT64_C(0xA9267712EE09A2BA),
+ UINT64_C(0x955CCE7FBA6103BD), UINT64_C(0x267282C1B9C65CD2),
+ UINT64_C(0x61D8F8281221A3E6), UINT64_C(0xD2F6B4961186FC89),
+ UINT64_C(0x9F8169BA49A54B33), UINT64_C(0x2CAF25044A02145C),
+ UINT64_C(0x6B055FEDE1E5EB68), UINT64_C(0xD82B1353E242B407),
+ UINT64_C(0xE451AA3EB62A1500), UINT64_C(0x577FE680B58D4A6F),
+ UINT64_C(0x10D59C691E6AB55B), UINT64_C(0xA3FBD0D71DCDEA34),
+ UINT64_C(0x6820EEB3B6BBF755), UINT64_C(0xDB0EA20DB51CA83A),
+ UINT64_C(0x9CA4D8E41EFB570E), UINT64_C(0x2F8A945A1D5C0861),
+ UINT64_C(0x13F02D374934A966), UINT64_C(0xA0DE61894A93F609),
+ UINT64_C(0xE7741B60E174093D), UINT64_C(0x545A57DEE2D35652),
+ UINT64_C(0xE21AC88218962D7A), UINT64_C(0x5134843C1B317215),
+ UINT64_C(0x169EFED5B0D68D21), UINT64_C(0xA5B0B26BB371D24E),
+ UINT64_C(0x99CA0B06E7197349), UINT64_C(0x2AE447B8E4BE2C26),
+ UINT64_C(0x6D4E3D514F59D312), UINT64_C(0xDE6071EF4CFE8C7D),
+ UINT64_C(0x15BB4F8BE788911C), UINT64_C(0xA6950335E42FCE73),
+ UINT64_C(0xE13F79DC4FC83147), UINT64_C(0x521135624C6F6E28),
+ UINT64_C(0x6E6B8C0F1807CF2F), UINT64_C(0xDD45C0B11BA09040),
+ UINT64_C(0x9AEFBA58B0476F74), UINT64_C(0x29C1F6E6B3E0301B),
+ UINT64_C(0xC96C5795D7870F42), UINT64_C(0x7A421B2BD420502D),
+ UINT64_C(0x3DE861C27FC7AF19), UINT64_C(0x8EC62D7C7C60F076),
+ UINT64_C(0xB2BC941128085171), UINT64_C(0x0192D8AF2BAF0E1E),
+ UINT64_C(0x4638A2468048F12A), UINT64_C(0xF516EEF883EFAE45),
+ UINT64_C(0x3ECDD09C2899B324), UINT64_C(0x8DE39C222B3EEC4B),
+ UINT64_C(0xCA49E6CB80D9137F), UINT64_C(0x7967AA75837E4C10),
+ UINT64_C(0x451D1318D716ED17), UINT64_C(0xF6335FA6D4B1B278),
+ UINT64_C(0xB199254F7F564D4C), UINT64_C(0x02B769F17CF11223),
+ UINT64_C(0xB4F7F6AD86B4690B), UINT64_C(0x07D9BA1385133664),
+ UINT64_C(0x4073C0FA2EF4C950), UINT64_C(0xF35D8C442D53963F),
+ UINT64_C(0xCF273529793B3738), UINT64_C(0x7C0979977A9C6857),
+ UINT64_C(0x3BA3037ED17B9763), UINT64_C(0x888D4FC0D2DCC80C),
+ UINT64_C(0x435671A479AAD56D), UINT64_C(0xF0783D1A7A0D8A02),
+ UINT64_C(0xB7D247F3D1EA7536), UINT64_C(0x04FC0B4DD24D2A59),
+ UINT64_C(0x3886B22086258B5E), UINT64_C(0x8BA8FE9E8582D431),
+ UINT64_C(0xCC0284772E652B05), UINT64_C(0x7F2CC8C92DC2746A),
+ UINT64_C(0x325B15E575E1C3D0), UINT64_C(0x8175595B76469CBF),
+ UINT64_C(0xC6DF23B2DDA1638B), UINT64_C(0x75F16F0CDE063CE4),
+ UINT64_C(0x498BD6618A6E9DE3), UINT64_C(0xFAA59ADF89C9C28C),
+ UINT64_C(0xBD0FE036222E3DB8), UINT64_C(0x0E21AC88218962D7),
+ UINT64_C(0xC5FA92EC8AFF7FB6), UINT64_C(0x76D4DE52895820D9),
+ UINT64_C(0x317EA4BB22BFDFED), UINT64_C(0x8250E80521188082),
+ UINT64_C(0xBE2A516875702185), UINT64_C(0x0D041DD676D77EEA),
+ UINT64_C(0x4AAE673FDD3081DE), UINT64_C(0xF9802B81DE97DEB1),
+ UINT64_C(0x4FC0B4DD24D2A599), UINT64_C(0xFCEEF8632775FAF6),
+ UINT64_C(0xBB44828A8C9205C2), UINT64_C(0x086ACE348F355AAD),
+ UINT64_C(0x34107759DB5DFBAA), UINT64_C(0x873E3BE7D8FAA4C5),
+ UINT64_C(0xC094410E731D5BF1), UINT64_C(0x73BA0DB070BA049E),
+ UINT64_C(0xB86133D4DBCC19FF), UINT64_C(0x0B4F7F6AD86B4690),
+ UINT64_C(0x4CE50583738CB9A4), UINT64_C(0xFFCB493D702BE6CB),
+ UINT64_C(0xC3B1F050244347CC), UINT64_C(0x709FBCEE27E418A3),
+ UINT64_C(0x3735C6078C03E797), UINT64_C(0x841B8AB98FA4B8F8),
+ UINT64_C(0xADDA7C5F3C4488E3), UINT64_C(0x1EF430E13FE3D78C),
+ UINT64_C(0x595E4A08940428B8), UINT64_C(0xEA7006B697A377D7),
+ UINT64_C(0xD60ABFDBC3CBD6D0), UINT64_C(0x6524F365C06C89BF),
+ UINT64_C(0x228E898C6B8B768B), UINT64_C(0x91A0C532682C29E4),
+ UINT64_C(0x5A7BFB56C35A3485), UINT64_C(0xE955B7E8C0FD6BEA),
+ UINT64_C(0xAEFFCD016B1A94DE), UINT64_C(0x1DD181BF68BDCBB1),
+ UINT64_C(0x21AB38D23CD56AB6), UINT64_C(0x9285746C3F7235D9),
+ UINT64_C(0xD52F0E859495CAED), UINT64_C(0x6601423B97329582),
+ UINT64_C(0xD041DD676D77EEAA), UINT64_C(0x636F91D96ED0B1C5),
+ UINT64_C(0x24C5EB30C5374EF1), UINT64_C(0x97EBA78EC690119E),
+ UINT64_C(0xAB911EE392F8B099), UINT64_C(0x18BF525D915FEFF6),
+ UINT64_C(0x5F1528B43AB810C2), UINT64_C(0xEC3B640A391F4FAD),
+ UINT64_C(0x27E05A6E926952CC), UINT64_C(0x94CE16D091CE0DA3),
+ UINT64_C(0xD3646C393A29F297), UINT64_C(0x604A2087398EADF8),
+ UINT64_C(0x5C3099EA6DE60CFF), UINT64_C(0xEF1ED5546E415390),
+ UINT64_C(0xA8B4AFBDC5A6ACA4), UINT64_C(0x1B9AE303C601F3CB),
+ UINT64_C(0x56ED3E2F9E224471), UINT64_C(0xE5C372919D851B1E),
+ UINT64_C(0xA26908783662E42A), UINT64_C(0x114744C635C5BB45),
+ UINT64_C(0x2D3DFDAB61AD1A42), UINT64_C(0x9E13B115620A452D),
+ UINT64_C(0xD9B9CBFCC9EDBA19), UINT64_C(0x6A978742CA4AE576),
+ UINT64_C(0xA14CB926613CF817), UINT64_C(0x1262F598629BA778),
+ UINT64_C(0x55C88F71C97C584C), UINT64_C(0xE6E6C3CFCADB0723),
+ UINT64_C(0xDA9C7AA29EB3A624), UINT64_C(0x69B2361C9D14F94B),
+ UINT64_C(0x2E184CF536F3067F), UINT64_C(0x9D36004B35545910),
+ UINT64_C(0x2B769F17CF112238), UINT64_C(0x9858D3A9CCB67D57),
+ UINT64_C(0xDFF2A94067518263), UINT64_C(0x6CDCE5FE64F6DD0C),
+ UINT64_C(0x50A65C93309E7C0B), UINT64_C(0xE388102D33392364),
+ UINT64_C(0xA4226AC498DEDC50), UINT64_C(0x170C267A9B79833F),
+ UINT64_C(0xDCD7181E300F9E5E), UINT64_C(0x6FF954A033A8C131),
+ UINT64_C(0x28532E49984F3E05), UINT64_C(0x9B7D62F79BE8616A),
+ UINT64_C(0xA707DB9ACF80C06D), UINT64_C(0x14299724CC279F02),
+ UINT64_C(0x5383EDCD67C06036), UINT64_C(0xE0ADA17364673F59)
+ }, {
+ UINT64_C(0x0000000000000000), UINT64_C(0x54E979925CD0F10D),
+ UINT64_C(0xA9D2F324B9A1E21A), UINT64_C(0xFD3B8AB6E5711317),
+ UINT64_C(0xC17D4962DC4DDAB1), UINT64_C(0x959430F0809D2BBC),
+ UINT64_C(0x68AFBA4665EC38AB), UINT64_C(0x3C46C3D4393CC9A6),
+ UINT64_C(0x10223DEE1795ABE7), UINT64_C(0x44CB447C4B455AEA),
+ UINT64_C(0xB9F0CECAAE3449FD), UINT64_C(0xED19B758F2E4B8F0),
+ UINT64_C(0xD15F748CCBD87156), UINT64_C(0x85B60D1E9708805B),
+ UINT64_C(0x788D87A87279934C), UINT64_C(0x2C64FE3A2EA96241),
+ UINT64_C(0x20447BDC2F2B57CE), UINT64_C(0x74AD024E73FBA6C3),
+ UINT64_C(0x899688F8968AB5D4), UINT64_C(0xDD7FF16ACA5A44D9),
+ UINT64_C(0xE13932BEF3668D7F), UINT64_C(0xB5D04B2CAFB67C72),
+ UINT64_C(0x48EBC19A4AC76F65), UINT64_C(0x1C02B80816179E68),
+ UINT64_C(0x3066463238BEFC29), UINT64_C(0x648F3FA0646E0D24),
+ UINT64_C(0x99B4B516811F1E33), UINT64_C(0xCD5DCC84DDCFEF3E),
+ UINT64_C(0xF11B0F50E4F32698), UINT64_C(0xA5F276C2B823D795),
+ UINT64_C(0x58C9FC745D52C482), UINT64_C(0x0C2085E60182358F),
+ UINT64_C(0x4088F7B85E56AF9C), UINT64_C(0x14618E2A02865E91),
+ UINT64_C(0xE95A049CE7F74D86), UINT64_C(0xBDB37D0EBB27BC8B),
+ UINT64_C(0x81F5BEDA821B752D), UINT64_C(0xD51CC748DECB8420),
+ UINT64_C(0x28274DFE3BBA9737), UINT64_C(0x7CCE346C676A663A),
+ UINT64_C(0x50AACA5649C3047B), UINT64_C(0x0443B3C41513F576),
+ UINT64_C(0xF9783972F062E661), UINT64_C(0xAD9140E0ACB2176C),
+ UINT64_C(0x91D78334958EDECA), UINT64_C(0xC53EFAA6C95E2FC7),
+ UINT64_C(0x380570102C2F3CD0), UINT64_C(0x6CEC098270FFCDDD),
+ UINT64_C(0x60CC8C64717DF852), UINT64_C(0x3425F5F62DAD095F),
+ UINT64_C(0xC91E7F40C8DC1A48), UINT64_C(0x9DF706D2940CEB45),
+ UINT64_C(0xA1B1C506AD3022E3), UINT64_C(0xF558BC94F1E0D3EE),
+ UINT64_C(0x086336221491C0F9), UINT64_C(0x5C8A4FB0484131F4),
+ UINT64_C(0x70EEB18A66E853B5), UINT64_C(0x2407C8183A38A2B8),
+ UINT64_C(0xD93C42AEDF49B1AF), UINT64_C(0x8DD53B3C839940A2),
+ UINT64_C(0xB193F8E8BAA58904), UINT64_C(0xE57A817AE6757809),
+ UINT64_C(0x18410BCC03046B1E), UINT64_C(0x4CA8725E5FD49A13),
+ UINT64_C(0x8111EF70BCAD5F38), UINT64_C(0xD5F896E2E07DAE35),
+ UINT64_C(0x28C31C54050CBD22), UINT64_C(0x7C2A65C659DC4C2F),
+ UINT64_C(0x406CA61260E08589), UINT64_C(0x1485DF803C307484),
+ UINT64_C(0xE9BE5536D9416793), UINT64_C(0xBD572CA48591969E),
+ UINT64_C(0x9133D29EAB38F4DF), UINT64_C(0xC5DAAB0CF7E805D2),
+ UINT64_C(0x38E121BA129916C5), UINT64_C(0x6C0858284E49E7C8),
+ UINT64_C(0x504E9BFC77752E6E), UINT64_C(0x04A7E26E2BA5DF63),
+ UINT64_C(0xF99C68D8CED4CC74), UINT64_C(0xAD75114A92043D79),
+ UINT64_C(0xA15594AC938608F6), UINT64_C(0xF5BCED3ECF56F9FB),
+ UINT64_C(0x088767882A27EAEC), UINT64_C(0x5C6E1E1A76F71BE1),
+ UINT64_C(0x6028DDCE4FCBD247), UINT64_C(0x34C1A45C131B234A),
+ UINT64_C(0xC9FA2EEAF66A305D), UINT64_C(0x9D135778AABAC150),
+ UINT64_C(0xB177A9428413A311), UINT64_C(0xE59ED0D0D8C3521C),
+ UINT64_C(0x18A55A663DB2410B), UINT64_C(0x4C4C23F46162B006),
+ UINT64_C(0x700AE020585E79A0), UINT64_C(0x24E399B2048E88AD),
+ UINT64_C(0xD9D81304E1FF9BBA), UINT64_C(0x8D316A96BD2F6AB7),
+ UINT64_C(0xC19918C8E2FBF0A4), UINT64_C(0x9570615ABE2B01A9),
+ UINT64_C(0x684BEBEC5B5A12BE), UINT64_C(0x3CA2927E078AE3B3),
+ UINT64_C(0x00E451AA3EB62A15), UINT64_C(0x540D28386266DB18),
+ UINT64_C(0xA936A28E8717C80F), UINT64_C(0xFDDFDB1CDBC73902),
+ UINT64_C(0xD1BB2526F56E5B43), UINT64_C(0x85525CB4A9BEAA4E),
+ UINT64_C(0x7869D6024CCFB959), UINT64_C(0x2C80AF90101F4854),
+ UINT64_C(0x10C66C44292381F2), UINT64_C(0x442F15D675F370FF),
+ UINT64_C(0xB9149F60908263E8), UINT64_C(0xEDFDE6F2CC5292E5),
+ UINT64_C(0xE1DD6314CDD0A76A), UINT64_C(0xB5341A8691005667),
+ UINT64_C(0x480F903074714570), UINT64_C(0x1CE6E9A228A1B47D),
+ UINT64_C(0x20A02A76119D7DDB), UINT64_C(0x744953E44D4D8CD6),
+ UINT64_C(0x8972D952A83C9FC1), UINT64_C(0xDD9BA0C0F4EC6ECC),
+ UINT64_C(0xF1FF5EFADA450C8D), UINT64_C(0xA51627688695FD80),
+ UINT64_C(0x582DADDE63E4EE97), UINT64_C(0x0CC4D44C3F341F9A),
+ UINT64_C(0x308217980608D63C), UINT64_C(0x646B6E0A5AD82731),
+ UINT64_C(0x9950E4BCBFA93426), UINT64_C(0xCDB99D2EE379C52B),
+ UINT64_C(0x90FB71CAD654A0F5), UINT64_C(0xC41208588A8451F8),
+ UINT64_C(0x392982EE6FF542EF), UINT64_C(0x6DC0FB7C3325B3E2),
+ UINT64_C(0x518638A80A197A44), UINT64_C(0x056F413A56C98B49),
+ UINT64_C(0xF854CB8CB3B8985E), UINT64_C(0xACBDB21EEF686953),
+ UINT64_C(0x80D94C24C1C10B12), UINT64_C(0xD43035B69D11FA1F),
+ UINT64_C(0x290BBF007860E908), UINT64_C(0x7DE2C69224B01805),
+ UINT64_C(0x41A405461D8CD1A3), UINT64_C(0x154D7CD4415C20AE),
+ UINT64_C(0xE876F662A42D33B9), UINT64_C(0xBC9F8FF0F8FDC2B4),
+ UINT64_C(0xB0BF0A16F97FF73B), UINT64_C(0xE4567384A5AF0636),
+ UINT64_C(0x196DF93240DE1521), UINT64_C(0x4D8480A01C0EE42C),
+ UINT64_C(0x71C2437425322D8A), UINT64_C(0x252B3AE679E2DC87),
+ UINT64_C(0xD810B0509C93CF90), UINT64_C(0x8CF9C9C2C0433E9D),
+ UINT64_C(0xA09D37F8EEEA5CDC), UINT64_C(0xF4744E6AB23AADD1),
+ UINT64_C(0x094FC4DC574BBEC6), UINT64_C(0x5DA6BD4E0B9B4FCB),
+ UINT64_C(0x61E07E9A32A7866D), UINT64_C(0x350907086E777760),
+ UINT64_C(0xC8328DBE8B066477), UINT64_C(0x9CDBF42CD7D6957A),
+ UINT64_C(0xD073867288020F69), UINT64_C(0x849AFFE0D4D2FE64),
+ UINT64_C(0x79A1755631A3ED73), UINT64_C(0x2D480CC46D731C7E),
+ UINT64_C(0x110ECF10544FD5D8), UINT64_C(0x45E7B682089F24D5),
+ UINT64_C(0xB8DC3C34EDEE37C2), UINT64_C(0xEC3545A6B13EC6CF),
+ UINT64_C(0xC051BB9C9F97A48E), UINT64_C(0x94B8C20EC3475583),
+ UINT64_C(0x698348B826364694), UINT64_C(0x3D6A312A7AE6B799),
+ UINT64_C(0x012CF2FE43DA7E3F), UINT64_C(0x55C58B6C1F0A8F32),
+ UINT64_C(0xA8FE01DAFA7B9C25), UINT64_C(0xFC177848A6AB6D28),
+ UINT64_C(0xF037FDAEA72958A7), UINT64_C(0xA4DE843CFBF9A9AA),
+ UINT64_C(0x59E50E8A1E88BABD), UINT64_C(0x0D0C771842584BB0),
+ UINT64_C(0x314AB4CC7B648216), UINT64_C(0x65A3CD5E27B4731B),
+ UINT64_C(0x989847E8C2C5600C), UINT64_C(0xCC713E7A9E159101),
+ UINT64_C(0xE015C040B0BCF340), UINT64_C(0xB4FCB9D2EC6C024D),
+ UINT64_C(0x49C73364091D115A), UINT64_C(0x1D2E4AF655CDE057),
+ UINT64_C(0x216889226CF129F1), UINT64_C(0x7581F0B03021D8FC),
+ UINT64_C(0x88BA7A06D550CBEB), UINT64_C(0xDC53039489803AE6),
+ UINT64_C(0x11EA9EBA6AF9FFCD), UINT64_C(0x4503E72836290EC0),
+ UINT64_C(0xB8386D9ED3581DD7), UINT64_C(0xECD1140C8F88ECDA),
+ UINT64_C(0xD097D7D8B6B4257C), UINT64_C(0x847EAE4AEA64D471),
+ UINT64_C(0x794524FC0F15C766), UINT64_C(0x2DAC5D6E53C5366B),
+ UINT64_C(0x01C8A3547D6C542A), UINT64_C(0x5521DAC621BCA527),
+ UINT64_C(0xA81A5070C4CDB630), UINT64_C(0xFCF329E2981D473D),
+ UINT64_C(0xC0B5EA36A1218E9B), UINT64_C(0x945C93A4FDF17F96),
+ UINT64_C(0x6967191218806C81), UINT64_C(0x3D8E608044509D8C),
+ UINT64_C(0x31AEE56645D2A803), UINT64_C(0x65479CF41902590E),
+ UINT64_C(0x987C1642FC734A19), UINT64_C(0xCC956FD0A0A3BB14),
+ UINT64_C(0xF0D3AC04999F72B2), UINT64_C(0xA43AD596C54F83BF),
+ UINT64_C(0x59015F20203E90A8), UINT64_C(0x0DE826B27CEE61A5),
+ UINT64_C(0x218CD888524703E4), UINT64_C(0x7565A11A0E97F2E9),
+ UINT64_C(0x885E2BACEBE6E1FE), UINT64_C(0xDCB7523EB73610F3),
+ UINT64_C(0xE0F191EA8E0AD955), UINT64_C(0xB418E878D2DA2858),
+ UINT64_C(0x492362CE37AB3B4F), UINT64_C(0x1DCA1B5C6B7BCA42),
+ UINT64_C(0x5162690234AF5051), UINT64_C(0x058B1090687FA15C),
+ UINT64_C(0xF8B09A268D0EB24B), UINT64_C(0xAC59E3B4D1DE4346),
+ UINT64_C(0x901F2060E8E28AE0), UINT64_C(0xC4F659F2B4327BED),
+ UINT64_C(0x39CDD344514368FA), UINT64_C(0x6D24AAD60D9399F7),
+ UINT64_C(0x414054EC233AFBB6), UINT64_C(0x15A92D7E7FEA0ABB),
+ UINT64_C(0xE892A7C89A9B19AC), UINT64_C(0xBC7BDE5AC64BE8A1),
+ UINT64_C(0x803D1D8EFF772107), UINT64_C(0xD4D4641CA3A7D00A),
+ UINT64_C(0x29EFEEAA46D6C31D), UINT64_C(0x7D0697381A063210),
+ UINT64_C(0x712612DE1B84079F), UINT64_C(0x25CF6B4C4754F692),
+ UINT64_C(0xD8F4E1FAA225E585), UINT64_C(0x8C1D9868FEF51488),
+ UINT64_C(0xB05B5BBCC7C9DD2E), UINT64_C(0xE4B2222E9B192C23),
+ UINT64_C(0x1989A8987E683F34), UINT64_C(0x4D60D10A22B8CE39),
+ UINT64_C(0x61042F300C11AC78), UINT64_C(0x35ED56A250C15D75),
+ UINT64_C(0xC8D6DC14B5B04E62), UINT64_C(0x9C3FA586E960BF6F),
+ UINT64_C(0xA0796652D05C76C9), UINT64_C(0xF4901FC08C8C87C4),
+ UINT64_C(0x09AB957669FD94D3), UINT64_C(0x5D42ECE4352D65DE)
+ }, {
+ UINT64_C(0x0000000000000000), UINT64_C(0x3F0BE14A916A6DCB),
+ UINT64_C(0x7E17C29522D4DB96), UINT64_C(0x411C23DFB3BEB65D),
+ UINT64_C(0xFC2F852A45A9B72C), UINT64_C(0xC3246460D4C3DAE7),
+ UINT64_C(0x823847BF677D6CBA), UINT64_C(0xBD33A6F5F6170171),
+ UINT64_C(0x6A87A57F245D70DD), UINT64_C(0x558C4435B5371D16),
+ UINT64_C(0x149067EA0689AB4B), UINT64_C(0x2B9B86A097E3C680),
+ UINT64_C(0x96A8205561F4C7F1), UINT64_C(0xA9A3C11FF09EAA3A),
+ UINT64_C(0xE8BFE2C043201C67), UINT64_C(0xD7B4038AD24A71AC),
+ UINT64_C(0xD50F4AFE48BAE1BA), UINT64_C(0xEA04ABB4D9D08C71),
+ UINT64_C(0xAB18886B6A6E3A2C), UINT64_C(0x94136921FB0457E7),
+ UINT64_C(0x2920CFD40D135696), UINT64_C(0x162B2E9E9C793B5D),
+ UINT64_C(0x57370D412FC78D00), UINT64_C(0x683CEC0BBEADE0CB),
+ UINT64_C(0xBF88EF816CE79167), UINT64_C(0x80830ECBFD8DFCAC),
+ UINT64_C(0xC19F2D144E334AF1), UINT64_C(0xFE94CC5EDF59273A),
+ UINT64_C(0x43A76AAB294E264B), UINT64_C(0x7CAC8BE1B8244B80),
+ UINT64_C(0x3DB0A83E0B9AFDDD), UINT64_C(0x02BB49749AF09016),
+ UINT64_C(0x38C63AD73E7BDDF1), UINT64_C(0x07CDDB9DAF11B03A),
+ UINT64_C(0x46D1F8421CAF0667), UINT64_C(0x79DA19088DC56BAC),
+ UINT64_C(0xC4E9BFFD7BD26ADD), UINT64_C(0xFBE25EB7EAB80716),
+ UINT64_C(0xBAFE7D685906B14B), UINT64_C(0x85F59C22C86CDC80),
+ UINT64_C(0x52419FA81A26AD2C), UINT64_C(0x6D4A7EE28B4CC0E7),
+ UINT64_C(0x2C565D3D38F276BA), UINT64_C(0x135DBC77A9981B71),
+ UINT64_C(0xAE6E1A825F8F1A00), UINT64_C(0x9165FBC8CEE577CB),
+ UINT64_C(0xD079D8177D5BC196), UINT64_C(0xEF72395DEC31AC5D),
+ UINT64_C(0xEDC9702976C13C4B), UINT64_C(0xD2C29163E7AB5180),
+ UINT64_C(0x93DEB2BC5415E7DD), UINT64_C(0xACD553F6C57F8A16),
+ UINT64_C(0x11E6F50333688B67), UINT64_C(0x2EED1449A202E6AC),
+ UINT64_C(0x6FF1379611BC50F1), UINT64_C(0x50FAD6DC80D63D3A),
+ UINT64_C(0x874ED556529C4C96), UINT64_C(0xB845341CC3F6215D),
+ UINT64_C(0xF95917C370489700), UINT64_C(0xC652F689E122FACB),
+ UINT64_C(0x7B61507C1735FBBA), UINT64_C(0x446AB136865F9671),
+ UINT64_C(0x057692E935E1202C), UINT64_C(0x3A7D73A3A48B4DE7),
+ UINT64_C(0x718C75AE7CF7BBE2), UINT64_C(0x4E8794E4ED9DD629),
+ UINT64_C(0x0F9BB73B5E236074), UINT64_C(0x30905671CF490DBF),
+ UINT64_C(0x8DA3F084395E0CCE), UINT64_C(0xB2A811CEA8346105),
+ UINT64_C(0xF3B432111B8AD758), UINT64_C(0xCCBFD35B8AE0BA93),
+ UINT64_C(0x1B0BD0D158AACB3F), UINT64_C(0x2400319BC9C0A6F4),
+ UINT64_C(0x651C12447A7E10A9), UINT64_C(0x5A17F30EEB147D62),
+ UINT64_C(0xE72455FB1D037C13), UINT64_C(0xD82FB4B18C6911D8),
+ UINT64_C(0x9933976E3FD7A785), UINT64_C(0xA6387624AEBDCA4E),
+ UINT64_C(0xA4833F50344D5A58), UINT64_C(0x9B88DE1AA5273793),
+ UINT64_C(0xDA94FDC5169981CE), UINT64_C(0xE59F1C8F87F3EC05),
+ UINT64_C(0x58ACBA7A71E4ED74), UINT64_C(0x67A75B30E08E80BF),
+ UINT64_C(0x26BB78EF533036E2), UINT64_C(0x19B099A5C25A5B29),
+ UINT64_C(0xCE049A2F10102A85), UINT64_C(0xF10F7B65817A474E),
+ UINT64_C(0xB01358BA32C4F113), UINT64_C(0x8F18B9F0A3AE9CD8),
+ UINT64_C(0x322B1F0555B99DA9), UINT64_C(0x0D20FE4FC4D3F062),
+ UINT64_C(0x4C3CDD90776D463F), UINT64_C(0x73373CDAE6072BF4),
+ UINT64_C(0x494A4F79428C6613), UINT64_C(0x7641AE33D3E60BD8),
+ UINT64_C(0x375D8DEC6058BD85), UINT64_C(0x08566CA6F132D04E),
+ UINT64_C(0xB565CA530725D13F), UINT64_C(0x8A6E2B19964FBCF4),
+ UINT64_C(0xCB7208C625F10AA9), UINT64_C(0xF479E98CB49B6762),
+ UINT64_C(0x23CDEA0666D116CE), UINT64_C(0x1CC60B4CF7BB7B05),
+ UINT64_C(0x5DDA28934405CD58), UINT64_C(0x62D1C9D9D56FA093),
+ UINT64_C(0xDFE26F2C2378A1E2), UINT64_C(0xE0E98E66B212CC29),
+ UINT64_C(0xA1F5ADB901AC7A74), UINT64_C(0x9EFE4CF390C617BF),
+ UINT64_C(0x9C4505870A3687A9), UINT64_C(0xA34EE4CD9B5CEA62),
+ UINT64_C(0xE252C71228E25C3F), UINT64_C(0xDD592658B98831F4),
+ UINT64_C(0x606A80AD4F9F3085), UINT64_C(0x5F6161E7DEF55D4E),
+ UINT64_C(0x1E7D42386D4BEB13), UINT64_C(0x2176A372FC2186D8),
+ UINT64_C(0xF6C2A0F82E6BF774), UINT64_C(0xC9C941B2BF019ABF),
+ UINT64_C(0x88D5626D0CBF2CE2), UINT64_C(0xB7DE83279DD54129),
+ UINT64_C(0x0AED25D26BC24058), UINT64_C(0x35E6C498FAA82D93),
+ UINT64_C(0x74FAE74749169BCE), UINT64_C(0x4BF1060DD87CF605),
+ UINT64_C(0xE318EB5CF9EF77C4), UINT64_C(0xDC130A1668851A0F),
+ UINT64_C(0x9D0F29C9DB3BAC52), UINT64_C(0xA204C8834A51C199),
+ UINT64_C(0x1F376E76BC46C0E8), UINT64_C(0x203C8F3C2D2CAD23),
+ UINT64_C(0x6120ACE39E921B7E), UINT64_C(0x5E2B4DA90FF876B5),
+ UINT64_C(0x899F4E23DDB20719), UINT64_C(0xB694AF694CD86AD2),
+ UINT64_C(0xF7888CB6FF66DC8F), UINT64_C(0xC8836DFC6E0CB144),
+ UINT64_C(0x75B0CB09981BB035), UINT64_C(0x4ABB2A430971DDFE),
+ UINT64_C(0x0BA7099CBACF6BA3), UINT64_C(0x34ACE8D62BA50668),
+ UINT64_C(0x3617A1A2B155967E), UINT64_C(0x091C40E8203FFBB5),
+ UINT64_C(0x4800633793814DE8), UINT64_C(0x770B827D02EB2023),
+ UINT64_C(0xCA382488F4FC2152), UINT64_C(0xF533C5C265964C99),
+ UINT64_C(0xB42FE61DD628FAC4), UINT64_C(0x8B2407574742970F),
+ UINT64_C(0x5C9004DD9508E6A3), UINT64_C(0x639BE59704628B68),
+ UINT64_C(0x2287C648B7DC3D35), UINT64_C(0x1D8C270226B650FE),
+ UINT64_C(0xA0BF81F7D0A1518F), UINT64_C(0x9FB460BD41CB3C44),
+ UINT64_C(0xDEA84362F2758A19), UINT64_C(0xE1A3A228631FE7D2),
+ UINT64_C(0xDBDED18BC794AA35), UINT64_C(0xE4D530C156FEC7FE),
+ UINT64_C(0xA5C9131EE54071A3), UINT64_C(0x9AC2F254742A1C68),
+ UINT64_C(0x27F154A1823D1D19), UINT64_C(0x18FAB5EB135770D2),
+ UINT64_C(0x59E69634A0E9C68F), UINT64_C(0x66ED777E3183AB44),
+ UINT64_C(0xB15974F4E3C9DAE8), UINT64_C(0x8E5295BE72A3B723),
+ UINT64_C(0xCF4EB661C11D017E), UINT64_C(0xF045572B50776CB5),
+ UINT64_C(0x4D76F1DEA6606DC4), UINT64_C(0x727D1094370A000F),
+ UINT64_C(0x3361334B84B4B652), UINT64_C(0x0C6AD20115DEDB99),
+ UINT64_C(0x0ED19B758F2E4B8F), UINT64_C(0x31DA7A3F1E442644),
+ UINT64_C(0x70C659E0ADFA9019), UINT64_C(0x4FCDB8AA3C90FDD2),
+ UINT64_C(0xF2FE1E5FCA87FCA3), UINT64_C(0xCDF5FF155BED9168),
+ UINT64_C(0x8CE9DCCAE8532735), UINT64_C(0xB3E23D8079394AFE),
+ UINT64_C(0x64563E0AAB733B52), UINT64_C(0x5B5DDF403A195699),
+ UINT64_C(0x1A41FC9F89A7E0C4), UINT64_C(0x254A1DD518CD8D0F),
+ UINT64_C(0x9879BB20EEDA8C7E), UINT64_C(0xA7725A6A7FB0E1B5),
+ UINT64_C(0xE66E79B5CC0E57E8), UINT64_C(0xD96598FF5D643A23),
+ UINT64_C(0x92949EF28518CC26), UINT64_C(0xAD9F7FB81472A1ED),
+ UINT64_C(0xEC835C67A7CC17B0), UINT64_C(0xD388BD2D36A67A7B),
+ UINT64_C(0x6EBB1BD8C0B17B0A), UINT64_C(0x51B0FA9251DB16C1),
+ UINT64_C(0x10ACD94DE265A09C), UINT64_C(0x2FA73807730FCD57),
+ UINT64_C(0xF8133B8DA145BCFB), UINT64_C(0xC718DAC7302FD130),
+ UINT64_C(0x8604F9188391676D), UINT64_C(0xB90F185212FB0AA6),
+ UINT64_C(0x043CBEA7E4EC0BD7), UINT64_C(0x3B375FED7586661C),
+ UINT64_C(0x7A2B7C32C638D041), UINT64_C(0x45209D785752BD8A),
+ UINT64_C(0x479BD40CCDA22D9C), UINT64_C(0x789035465CC84057),
+ UINT64_C(0x398C1699EF76F60A), UINT64_C(0x0687F7D37E1C9BC1),
+ UINT64_C(0xBBB45126880B9AB0), UINT64_C(0x84BFB06C1961F77B),
+ UINT64_C(0xC5A393B3AADF4126), UINT64_C(0xFAA872F93BB52CED),
+ UINT64_C(0x2D1C7173E9FF5D41), UINT64_C(0x121790397895308A),
+ UINT64_C(0x530BB3E6CB2B86D7), UINT64_C(0x6C0052AC5A41EB1C),
+ UINT64_C(0xD133F459AC56EA6D), UINT64_C(0xEE3815133D3C87A6),
+ UINT64_C(0xAF2436CC8E8231FB), UINT64_C(0x902FD7861FE85C30),
+ UINT64_C(0xAA52A425BB6311D7), UINT64_C(0x9559456F2A097C1C),
+ UINT64_C(0xD44566B099B7CA41), UINT64_C(0xEB4E87FA08DDA78A),
+ UINT64_C(0x567D210FFECAA6FB), UINT64_C(0x6976C0456FA0CB30),
+ UINT64_C(0x286AE39ADC1E7D6D), UINT64_C(0x176102D04D7410A6),
+ UINT64_C(0xC0D5015A9F3E610A), UINT64_C(0xFFDEE0100E540CC1),
+ UINT64_C(0xBEC2C3CFBDEABA9C), UINT64_C(0x81C922852C80D757),
+ UINT64_C(0x3CFA8470DA97D626), UINT64_C(0x03F1653A4BFDBBED),
+ UINT64_C(0x42ED46E5F8430DB0), UINT64_C(0x7DE6A7AF6929607B),
+ UINT64_C(0x7F5DEEDBF3D9F06D), UINT64_C(0x40560F9162B39DA6),
+ UINT64_C(0x014A2C4ED10D2BFB), UINT64_C(0x3E41CD0440674630),
+ UINT64_C(0x83726BF1B6704741), UINT64_C(0xBC798ABB271A2A8A),
+ UINT64_C(0xFD65A96494A49CD7), UINT64_C(0xC26E482E05CEF11C),
+ UINT64_C(0x15DA4BA4D78480B0), UINT64_C(0x2AD1AAEE46EEED7B),
+ UINT64_C(0x6BCD8931F5505B26), UINT64_C(0x54C6687B643A36ED),
+ UINT64_C(0xE9F5CE8E922D379C), UINT64_C(0xD6FE2FC403475A57),
+ UINT64_C(0x97E20C1BB0F9EC0A), UINT64_C(0xA8E9ED51219381C1)
+ }, {
+ UINT64_C(0x0000000000000000), UINT64_C(0x1DEE8A5E222CA1DC),
+ UINT64_C(0x3BDD14BC445943B8), UINT64_C(0x26339EE26675E264),
+ UINT64_C(0x77BA297888B28770), UINT64_C(0x6A54A326AA9E26AC),
+ UINT64_C(0x4C673DC4CCEBC4C8), UINT64_C(0x5189B79AEEC76514),
+ UINT64_C(0xEF7452F111650EE0), UINT64_C(0xF29AD8AF3349AF3C),
+ UINT64_C(0xD4A9464D553C4D58), UINT64_C(0xC947CC137710EC84),
+ UINT64_C(0x98CE7B8999D78990), UINT64_C(0x8520F1D7BBFB284C),
+ UINT64_C(0xA3136F35DD8ECA28), UINT64_C(0xBEFDE56BFFA26BF4),
+ UINT64_C(0x4C300AC98DC40345), UINT64_C(0x51DE8097AFE8A299),
+ UINT64_C(0x77ED1E75C99D40FD), UINT64_C(0x6A03942BEBB1E121),
+ UINT64_C(0x3B8A23B105768435), UINT64_C(0x2664A9EF275A25E9),
+ UINT64_C(0x0057370D412FC78D), UINT64_C(0x1DB9BD5363036651),
+ UINT64_C(0xA34458389CA10DA5), UINT64_C(0xBEAAD266BE8DAC79),
+ UINT64_C(0x98994C84D8F84E1D), UINT64_C(0x8577C6DAFAD4EFC1),
+ UINT64_C(0xD4FE714014138AD5), UINT64_C(0xC910FB1E363F2B09),
+ UINT64_C(0xEF2365FC504AC96D), UINT64_C(0xF2CDEFA2726668B1),
+ UINT64_C(0x986015931B88068A), UINT64_C(0x858E9FCD39A4A756),
+ UINT64_C(0xA3BD012F5FD14532), UINT64_C(0xBE538B717DFDE4EE),
+ UINT64_C(0xEFDA3CEB933A81FA), UINT64_C(0xF234B6B5B1162026),
+ UINT64_C(0xD4072857D763C242), UINT64_C(0xC9E9A209F54F639E),
+ UINT64_C(0x771447620AED086A), UINT64_C(0x6AFACD3C28C1A9B6),
+ UINT64_C(0x4CC953DE4EB44BD2), UINT64_C(0x5127D9806C98EA0E),
+ UINT64_C(0x00AE6E1A825F8F1A), UINT64_C(0x1D40E444A0732EC6),
+ UINT64_C(0x3B737AA6C606CCA2), UINT64_C(0x269DF0F8E42A6D7E),
+ UINT64_C(0xD4501F5A964C05CF), UINT64_C(0xC9BE9504B460A413),
+ UINT64_C(0xEF8D0BE6D2154677), UINT64_C(0xF26381B8F039E7AB),
+ UINT64_C(0xA3EA36221EFE82BF), UINT64_C(0xBE04BC7C3CD22363),
+ UINT64_C(0x9837229E5AA7C107), UINT64_C(0x85D9A8C0788B60DB),
+ UINT64_C(0x3B244DAB87290B2F), UINT64_C(0x26CAC7F5A505AAF3),
+ UINT64_C(0x00F95917C3704897), UINT64_C(0x1D17D349E15CE94B),
+ UINT64_C(0x4C9E64D30F9B8C5F), UINT64_C(0x5170EE8D2DB72D83),
+ UINT64_C(0x7743706F4BC2CFE7), UINT64_C(0x6AADFA3169EE6E3B),
+ UINT64_C(0xA218840D981E1391), UINT64_C(0xBFF60E53BA32B24D),
+ UINT64_C(0x99C590B1DC475029), UINT64_C(0x842B1AEFFE6BF1F5),
+ UINT64_C(0xD5A2AD7510AC94E1), UINT64_C(0xC84C272B3280353D),
+ UINT64_C(0xEE7FB9C954F5D759), UINT64_C(0xF391339776D97685),
+ UINT64_C(0x4D6CD6FC897B1D71), UINT64_C(0x50825CA2AB57BCAD),
+ UINT64_C(0x76B1C240CD225EC9), UINT64_C(0x6B5F481EEF0EFF15),
+ UINT64_C(0x3AD6FF8401C99A01), UINT64_C(0x273875DA23E53BDD),
+ UINT64_C(0x010BEB384590D9B9), UINT64_C(0x1CE5616667BC7865),
+ UINT64_C(0xEE288EC415DA10D4), UINT64_C(0xF3C6049A37F6B108),
+ UINT64_C(0xD5F59A785183536C), UINT64_C(0xC81B102673AFF2B0),
+ UINT64_C(0x9992A7BC9D6897A4), UINT64_C(0x847C2DE2BF443678),
+ UINT64_C(0xA24FB300D931D41C), UINT64_C(0xBFA1395EFB1D75C0),
+ UINT64_C(0x015CDC3504BF1E34), UINT64_C(0x1CB2566B2693BFE8),
+ UINT64_C(0x3A81C88940E65D8C), UINT64_C(0x276F42D762CAFC50),
+ UINT64_C(0x76E6F54D8C0D9944), UINT64_C(0x6B087F13AE213898),
+ UINT64_C(0x4D3BE1F1C854DAFC), UINT64_C(0x50D56BAFEA787B20),
+ UINT64_C(0x3A78919E8396151B), UINT64_C(0x27961BC0A1BAB4C7),
+ UINT64_C(0x01A58522C7CF56A3), UINT64_C(0x1C4B0F7CE5E3F77F),
+ UINT64_C(0x4DC2B8E60B24926B), UINT64_C(0x502C32B8290833B7),
+ UINT64_C(0x761FAC5A4F7DD1D3), UINT64_C(0x6BF126046D51700F),
+ UINT64_C(0xD50CC36F92F31BFB), UINT64_C(0xC8E24931B0DFBA27),
+ UINT64_C(0xEED1D7D3D6AA5843), UINT64_C(0xF33F5D8DF486F99F),
+ UINT64_C(0xA2B6EA171A419C8B), UINT64_C(0xBF586049386D3D57),
+ UINT64_C(0x996BFEAB5E18DF33), UINT64_C(0x848574F57C347EEF),
+ UINT64_C(0x76489B570E52165E), UINT64_C(0x6BA611092C7EB782),
+ UINT64_C(0x4D958FEB4A0B55E6), UINT64_C(0x507B05B56827F43A),
+ UINT64_C(0x01F2B22F86E0912E), UINT64_C(0x1C1C3871A4CC30F2),
+ UINT64_C(0x3A2FA693C2B9D296), UINT64_C(0x27C12CCDE095734A),
+ UINT64_C(0x993CC9A61F3718BE), UINT64_C(0x84D243F83D1BB962),
+ UINT64_C(0xA2E1DD1A5B6E5B06), UINT64_C(0xBF0F57447942FADA),
+ UINT64_C(0xEE86E0DE97859FCE), UINT64_C(0xF3686A80B5A93E12),
+ UINT64_C(0xD55BF462D3DCDC76), UINT64_C(0xC8B57E3CF1F07DAA),
+ UINT64_C(0xD6E9A7309F3239A7), UINT64_C(0xCB072D6EBD1E987B),
+ UINT64_C(0xED34B38CDB6B7A1F), UINT64_C(0xF0DA39D2F947DBC3),
+ UINT64_C(0xA1538E481780BED7), UINT64_C(0xBCBD041635AC1F0B),
+ UINT64_C(0x9A8E9AF453D9FD6F), UINT64_C(0x876010AA71F55CB3),
+ UINT64_C(0x399DF5C18E573747), UINT64_C(0x24737F9FAC7B969B),
+ UINT64_C(0x0240E17DCA0E74FF), UINT64_C(0x1FAE6B23E822D523),
+ UINT64_C(0x4E27DCB906E5B037), UINT64_C(0x53C956E724C911EB),
+ UINT64_C(0x75FAC80542BCF38F), UINT64_C(0x6814425B60905253),
+ UINT64_C(0x9AD9ADF912F63AE2), UINT64_C(0x873727A730DA9B3E),
+ UINT64_C(0xA104B94556AF795A), UINT64_C(0xBCEA331B7483D886),
+ UINT64_C(0xED6384819A44BD92), UINT64_C(0xF08D0EDFB8681C4E),
+ UINT64_C(0xD6BE903DDE1DFE2A), UINT64_C(0xCB501A63FC315FF6),
+ UINT64_C(0x75ADFF0803933402), UINT64_C(0x6843755621BF95DE),
+ UINT64_C(0x4E70EBB447CA77BA), UINT64_C(0x539E61EA65E6D666),
+ UINT64_C(0x0217D6708B21B372), UINT64_C(0x1FF95C2EA90D12AE),
+ UINT64_C(0x39CAC2CCCF78F0CA), UINT64_C(0x24244892ED545116),
+ UINT64_C(0x4E89B2A384BA3F2D), UINT64_C(0x536738FDA6969EF1),
+ UINT64_C(0x7554A61FC0E37C95), UINT64_C(0x68BA2C41E2CFDD49),
+ UINT64_C(0x39339BDB0C08B85D), UINT64_C(0x24DD11852E241981),
+ UINT64_C(0x02EE8F674851FBE5), UINT64_C(0x1F0005396A7D5A39),
+ UINT64_C(0xA1FDE05295DF31CD), UINT64_C(0xBC136A0CB7F39011),
+ UINT64_C(0x9A20F4EED1867275), UINT64_C(0x87CE7EB0F3AAD3A9),
+ UINT64_C(0xD647C92A1D6DB6BD), UINT64_C(0xCBA943743F411761),
+ UINT64_C(0xED9ADD965934F505), UINT64_C(0xF07457C87B1854D9),
+ UINT64_C(0x02B9B86A097E3C68), UINT64_C(0x1F5732342B529DB4),
+ UINT64_C(0x3964ACD64D277FD0), UINT64_C(0x248A26886F0BDE0C),
+ UINT64_C(0x7503911281CCBB18), UINT64_C(0x68ED1B4CA3E01AC4),
+ UINT64_C(0x4EDE85AEC595F8A0), UINT64_C(0x53300FF0E7B9597C),
+ UINT64_C(0xEDCDEA9B181B3288), UINT64_C(0xF02360C53A379354),
+ UINT64_C(0xD610FE275C427130), UINT64_C(0xCBFE74797E6ED0EC),
+ UINT64_C(0x9A77C3E390A9B5F8), UINT64_C(0x879949BDB2851424),
+ UINT64_C(0xA1AAD75FD4F0F640), UINT64_C(0xBC445D01F6DC579C),
+ UINT64_C(0x74F1233D072C2A36), UINT64_C(0x691FA96325008BEA),
+ UINT64_C(0x4F2C37814375698E), UINT64_C(0x52C2BDDF6159C852),
+ UINT64_C(0x034B0A458F9EAD46), UINT64_C(0x1EA5801BADB20C9A),
+ UINT64_C(0x38961EF9CBC7EEFE), UINT64_C(0x257894A7E9EB4F22),
+ UINT64_C(0x9B8571CC164924D6), UINT64_C(0x866BFB923465850A),
+ UINT64_C(0xA05865705210676E), UINT64_C(0xBDB6EF2E703CC6B2),
+ UINT64_C(0xEC3F58B49EFBA3A6), UINT64_C(0xF1D1D2EABCD7027A),
+ UINT64_C(0xD7E24C08DAA2E01E), UINT64_C(0xCA0CC656F88E41C2),
+ UINT64_C(0x38C129F48AE82973), UINT64_C(0x252FA3AAA8C488AF),
+ UINT64_C(0x031C3D48CEB16ACB), UINT64_C(0x1EF2B716EC9DCB17),
+ UINT64_C(0x4F7B008C025AAE03), UINT64_C(0x52958AD220760FDF),
+ UINT64_C(0x74A614304603EDBB), UINT64_C(0x69489E6E642F4C67),
+ UINT64_C(0xD7B57B059B8D2793), UINT64_C(0xCA5BF15BB9A1864F),
+ UINT64_C(0xEC686FB9DFD4642B), UINT64_C(0xF186E5E7FDF8C5F7),
+ UINT64_C(0xA00F527D133FA0E3), UINT64_C(0xBDE1D8233113013F),
+ UINT64_C(0x9BD246C15766E35B), UINT64_C(0x863CCC9F754A4287),
+ UINT64_C(0xEC9136AE1CA42CBC), UINT64_C(0xF17FBCF03E888D60),
+ UINT64_C(0xD74C221258FD6F04), UINT64_C(0xCAA2A84C7AD1CED8),
+ UINT64_C(0x9B2B1FD69416ABCC), UINT64_C(0x86C59588B63A0A10),
+ UINT64_C(0xA0F60B6AD04FE874), UINT64_C(0xBD188134F26349A8),
+ UINT64_C(0x03E5645F0DC1225C), UINT64_C(0x1E0BEE012FED8380),
+ UINT64_C(0x383870E3499861E4), UINT64_C(0x25D6FABD6BB4C038),
+ UINT64_C(0x745F4D278573A52C), UINT64_C(0x69B1C779A75F04F0),
+ UINT64_C(0x4F82599BC12AE694), UINT64_C(0x526CD3C5E3064748),
+ UINT64_C(0xA0A13C6791602FF9), UINT64_C(0xBD4FB639B34C8E25),
+ UINT64_C(0x9B7C28DBD5396C41), UINT64_C(0x8692A285F715CD9D),
+ UINT64_C(0xD71B151F19D2A889), UINT64_C(0xCAF59F413BFE0955),
+ UINT64_C(0xECC601A35D8BEB31), UINT64_C(0xF1288BFD7FA74AED),
+ UINT64_C(0x4FD56E9680052119), UINT64_C(0x523BE4C8A22980C5),
+ UINT64_C(0x74087A2AC45C62A1), UINT64_C(0x69E6F074E670C37D),
+ UINT64_C(0x386F47EE08B7A669), UINT64_C(0x2581CDB02A9B07B5),
+ UINT64_C(0x03B253524CEEE5D1), UINT64_C(0x1E5CD90C6EC2440D)
+ }
+};
diff --git a/Utilities/cmliblzma/liblzma/check/crc64_tablegen.c b/Utilities/cmliblzma/liblzma/check/crc64_tablegen.c
new file mode 100644
index 0000000000..fddaa7ed14
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc64_tablegen.c
@@ -0,0 +1,88 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file crc64_tablegen.c
+/// \brief Generate crc64_table_le.h and crc64_table_be.h
+///
+/// Compiling: gcc -std=c99 -o crc64_tablegen crc64_tablegen.c
+/// Add -DWORDS_BIGENDIAN to generate big endian table.
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <stdio.h>
+#include "../../common/tuklib_integer.h"
+
+
+static uint64_t crc64_table[4][256];
+
+
+extern void
+init_crc64_table(void)
+{
+ static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
+
+ for (size_t s = 0; s < 4; ++s) {
+ for (size_t b = 0; b < 256; ++b) {
+ uint64_t r = s == 0 ? b : crc64_table[s - 1][b];
+
+ for (size_t i = 0; i < 8; ++i) {
+ if (r & 1)
+ r = (r >> 1) ^ poly64;
+ else
+ r >>= 1;
+ }
+
+ crc64_table[s][b] = r;
+ }
+ }
+
+#ifdef WORDS_BIGENDIAN
+ for (size_t s = 0; s < 4; ++s)
+ for (size_t b = 0; b < 256; ++b)
+ crc64_table[s][b] = bswap64(crc64_table[s][b]);
+#endif
+
+ return;
+}
+
+
+static void
+print_crc64_table(void)
+{
+ printf("/* This file has been automatically generated by "
+ "crc64_tablegen.c. */\n\n"
+ "const uint64_t lzma_crc64_table[4][256] = {\n\t{");
+
+ for (size_t s = 0; s < 4; ++s) {
+ for (size_t b = 0; b < 256; ++b) {
+ if ((b % 2) == 0)
+ printf("\n\t\t");
+
+ printf("UINT64_C(0x%016" PRIX64 ")",
+ crc64_table[s][b]);
+
+ if (b != 255)
+ printf(",%s", (b+1) % 2 == 0 ? "" : " ");
+ }
+
+ if (s == 3)
+ printf("\n\t}\n};\n");
+ else
+ printf("\n\t}, {");
+ }
+
+ return;
+}
+
+
+int
+main(void)
+{
+ init_crc64_table();
+ print_crc64_table();
+ return 0;
+}
diff --git a/Utilities/cmliblzma/liblzma/check/crc64_x86.S b/Utilities/cmliblzma/liblzma/check/crc64_x86.S
new file mode 100644
index 0000000000..f5bb84b97e
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc64_x86.S
@@ -0,0 +1,287 @@
+/*
+ * Speed-optimized CRC64 using slicing-by-four algorithm
+ *
+ * This uses only i386 instructions, but it is optimized for i686 and later
+ * (including e.g. Pentium II/III/IV, Athlon XP, and Core 2).
+ *
+ * Authors: Igor Pavlov (original CRC32 assembly code)
+ * Lasse Collin (CRC64 adaptation of the modified CRC32 code)
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ *
+ * This code needs lzma_crc64_table, which can be created using the
+ * following C code:
+
+uint64_t lzma_crc64_table[4][256];
+
+void
+init_table(void)
+{
+ // ECMA-182
+ static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
+
+ for (size_t s = 0; s < 4; ++s) {
+ for (size_t b = 0; b < 256; ++b) {
+ uint64_t r = s == 0 ? b : lzma_crc64_table[s - 1][b];
+
+ for (size_t i = 0; i < 8; ++i) {
+ if (r & 1)
+ r = (r >> 1) ^ poly64;
+ else
+ r >>= 1;
+ }
+
+ lzma_crc64_table[s][b] = r;
+ }
+ }
+}
+
+ * The prototype of the CRC64 function:
+ * extern uint64_t lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc);
+ */
+
+/*
+ * On some systems, the functions need to be prefixed. The prefix is
+ * usually an underscore.
+ */
+#ifndef __USER_LABEL_PREFIX__
+# define __USER_LABEL_PREFIX__
+#endif
+#define MAKE_SYM_CAT(prefix, sym) prefix ## sym
+#define MAKE_SYM(prefix, sym) MAKE_SYM_CAT(prefix, sym)
+#define LZMA_CRC64 MAKE_SYM(__USER_LABEL_PREFIX__, lzma_crc64)
+#define LZMA_CRC64_TABLE MAKE_SYM(__USER_LABEL_PREFIX__, lzma_crc64_table)
+
+/*
+ * Solaris assembler doesn't have .p2align, and Darwin uses .align
+ * differently than GNU/Linux and Solaris.
+ */
+#if defined(__APPLE__) || defined(__MSDOS__)
+# define ALIGN(pow2, abs) .align pow2
+#else
+# define ALIGN(pow2, abs) .align abs
+#endif
+
+ .text
+ .globl LZMA_CRC64
+
+#if !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) \
+ && !defined(__MSDOS__)
+ .type LZMA_CRC64, @function
+#endif
+
+ ALIGN(4, 16)
+LZMA_CRC64:
+ /*
+ * Register usage:
+ * %eax crc LSB
+ * %edx crc MSB
+ * %esi buf
+ * %edi size or buf + size
+ * %ebx lzma_crc64_table
+ * %ebp Table index
+ * %ecx Temporary
+ */
+ pushl %ebx
+ pushl %esi
+ pushl %edi
+ pushl %ebp
+ movl 0x14(%esp), %esi /* buf */
+ movl 0x18(%esp), %edi /* size */
+ movl 0x1C(%esp), %eax /* crc LSB */
+ movl 0x20(%esp), %edx /* crc MSB */
+
+ /*
+ * Store the address of lzma_crc64_table to %ebx. This is needed to
+ * get position-independent code (PIC).
+ *
+ * The PIC macro is defined by libtool, while __PIC__ is defined
+ * by GCC but only on some systems. Testing for both makes it simpler
+ * to test this code without libtool, and keeps the code working also
+ * when built with libtool but using something else than GCC.
+ *
+ * I understood that libtool may define PIC on Windows even though
+ * the code in Windows DLLs is not PIC in sense that it is in ELF
+ * binaries, so we need a separate check to always use the non-PIC
+ * code on Windows.
+ */
+#if (!defined(PIC) && !defined(__PIC__)) \
+ || (defined(_WIN32) || defined(__CYGWIN__))
+ /* Not PIC */
+ movl $ LZMA_CRC64_TABLE, %ebx
+#elif defined(__APPLE__)
+ /* Mach-O */
+ call .L_get_pc
+.L_pic:
+ leal .L_lzma_crc64_table$non_lazy_ptr-.L_pic(%ebx), %ebx
+ movl (%ebx), %ebx
+#else
+ /* ELF */
+ call .L_get_pc
+ addl $_GLOBAL_OFFSET_TABLE_, %ebx
+ movl LZMA_CRC64_TABLE@GOT(%ebx), %ebx
+#endif
+
+ /* Complement the initial value. */
+ notl %eax
+ notl %edx
+
+.L_align:
+ /*
+ * Check if there is enough input to use slicing-by-four.
+ * We need eight bytes, because the loop pre-reads four bytes.
+ */
+ cmpl $8, %edi
+ jb .L_rest
+
+ /* Check if we have reached alignment of four bytes. */
+ testl $3, %esi
+ jz .L_slice
+
+ /* Calculate CRC of the next input byte. */
+ movzbl (%esi), %ebp
+ incl %esi
+ movzbl %al, %ecx
+ xorl %ecx, %ebp
+ shrdl $8, %edx, %eax
+ xorl (%ebx, %ebp, 8), %eax
+ shrl $8, %edx
+ xorl 4(%ebx, %ebp, 8), %edx
+ decl %edi
+ jmp .L_align
+
+.L_slice:
+ /*
+ * If we get here, there's at least eight bytes of aligned input
+ * available. Make %edi multiple of four bytes. Store the possible
+ * remainder over the "size" variable in the argument stack.
+ */
+ movl %edi, 0x18(%esp)
+ andl $-4, %edi
+ subl %edi, 0x18(%esp)
+
+ /*
+ * Let %edi be buf + size - 4 while running the main loop. This way
+ * we can compare for equality to determine when exit the loop.
+ */
+ addl %esi, %edi
+ subl $4, %edi
+
+ /* Read in the first four aligned bytes. */
+ movl (%esi), %ecx
+
+.L_loop:
+ xorl %eax, %ecx
+ movzbl %cl, %ebp
+ movl 0x1800(%ebx, %ebp, 8), %eax
+ xorl %edx, %eax
+ movl 0x1804(%ebx, %ebp, 8), %edx
+ movzbl %ch, %ebp
+ xorl 0x1000(%ebx, %ebp, 8), %eax
+ xorl 0x1004(%ebx, %ebp, 8), %edx
+ shrl $16, %ecx
+ movzbl %cl, %ebp
+ xorl 0x0800(%ebx, %ebp, 8), %eax
+ xorl 0x0804(%ebx, %ebp, 8), %edx
+ movzbl %ch, %ebp
+ addl $4, %esi
+ xorl (%ebx, %ebp, 8), %eax
+ xorl 4(%ebx, %ebp, 8), %edx
+
+ /* Check for end of aligned input. */
+ cmpl %edi, %esi
+
+ /*
+ * Copy the next input byte to %ecx. It is slightly faster to
+ * read it here than at the top of the loop.
+ */
+ movl (%esi), %ecx
+ jb .L_loop
+
+ /*
+ * Process the remaining four bytes, which we have already
+ * copied to %ecx.
+ */
+ xorl %eax, %ecx
+ movzbl %cl, %ebp
+ movl 0x1800(%ebx, %ebp, 8), %eax
+ xorl %edx, %eax
+ movl 0x1804(%ebx, %ebp, 8), %edx
+ movzbl %ch, %ebp
+ xorl 0x1000(%ebx, %ebp, 8), %eax
+ xorl 0x1004(%ebx, %ebp, 8), %edx
+ shrl $16, %ecx
+ movzbl %cl, %ebp
+ xorl 0x0800(%ebx, %ebp, 8), %eax
+ xorl 0x0804(%ebx, %ebp, 8), %edx
+ movzbl %ch, %ebp
+ addl $4, %esi
+ xorl (%ebx, %ebp, 8), %eax
+ xorl 4(%ebx, %ebp, 8), %edx
+
+ /* Copy the number of remaining bytes to %edi. */
+ movl 0x18(%esp), %edi
+
+.L_rest:
+ /* Check for end of input. */
+ testl %edi, %edi
+ jz .L_return
+
+ /* Calculate CRC of the next input byte. */
+ movzbl (%esi), %ebp
+ incl %esi
+ movzbl %al, %ecx
+ xorl %ecx, %ebp
+ shrdl $8, %edx, %eax
+ xorl (%ebx, %ebp, 8), %eax
+ shrl $8, %edx
+ xorl 4(%ebx, %ebp, 8), %edx
+ decl %edi
+ jmp .L_rest
+
+.L_return:
+ /* Complement the final value. */
+ notl %eax
+ notl %edx
+
+ popl %ebp
+ popl %edi
+ popl %esi
+ popl %ebx
+ ret
+
+#if defined(PIC) || defined(__PIC__)
+ ALIGN(4, 16)
+.L_get_pc:
+ movl (%esp), %ebx
+ ret
+#endif
+
+#if defined(__APPLE__) && (defined(PIC) || defined(__PIC__))
+ /* Mach-O PIC */
+ .section __IMPORT,__pointers,non_lazy_symbol_pointers
+.L_lzma_crc64_table$non_lazy_ptr:
+ .indirect_symbol LZMA_CRC64_TABLE
+ .long 0
+
+#elif defined(_WIN32) || defined(__CYGWIN__)
+# ifdef DLL_EXPORT
+ /* This is equivalent of __declspec(dllexport). */
+ .section .drectve
+ .ascii " -export:lzma_crc64"
+# endif
+
+#elif !defined(__MSDOS__)
+ /* ELF */
+ .size LZMA_CRC64, .-LZMA_CRC64
+#endif
+
+/*
+ * This is needed to support non-executable stack. It's ugly to
+ * use __linux__ here, but I don't know a way to detect when
+ * we are using GNU assembler.
+ */
+#if defined(__ELF__) && defined(__linux__)
+ .section .note.GNU-stack,"",@progbits
+#endif
diff --git a/Utilities/cmliblzma/liblzma/check/crc_macros.h b/Utilities/cmliblzma/liblzma/check/crc_macros.h
new file mode 100644
index 0000000000..a7c21b765d
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/crc_macros.h
@@ -0,0 +1,30 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file crc_macros.h
+/// \brief Some endian-dependent macros for CRC32 and CRC64
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifdef WORDS_BIGENDIAN
+# define A(x) ((x) >> 24)
+# define B(x) (((x) >> 16) & 0xFF)
+# define C(x) (((x) >> 8) & 0xFF)
+# define D(x) ((x) & 0xFF)
+
+# define S8(x) ((x) << 8)
+# define S32(x) ((x) << 32)
+
+#else
+# define A(x) ((x) & 0xFF)
+# define B(x) (((x) >> 8) & 0xFF)
+# define C(x) (((x) >> 16) & 0xFF)
+# define D(x) ((x) >> 24)
+
+# define S8(x) ((x) >> 8)
+# define S32(x) ((x) >> 32)
+#endif
diff --git a/Utilities/cmliblzma/liblzma/check/sha256.c b/Utilities/cmliblzma/liblzma/check/sha256.c
new file mode 100644
index 0000000000..c2c85eb238
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/check/sha256.c
@@ -0,0 +1,204 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file sha256.c
+/// \brief SHA-256
+///
+/// \todo Crypto++ has x86 ASM optimizations. They use SSE so if they
+/// are imported to liblzma, SSE instructions need to be used
+/// conditionally to keep the code working on older boxes.
+//
+// This code is based on the code found from 7-Zip, which has a modified
+// version of the SHA-256 found from Crypto++ <http://www.cryptopp.com/>.
+// The code was modified a little to fit into liblzma.
+//
+// Authors: Kevin Springle
+// Wei Dai
+// Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+// Avoid bogus warnings in transform().
+#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) || __GNUC__ > 4
+# pragma GCC diagnostic ignored "-Wuninitialized"
+#endif
+
+#include "check.h"
+
+// At least on x86, GCC is able to optimize this to a rotate instruction.
+#define rotr_32(num, amount) ((num) >> (amount) | (num) << (32 - (amount)))
+
+#define blk0(i) (W[i] = data[i])
+#define blk2(i) (W[i & 15] += s1(W[(i - 2) & 15]) + W[(i - 7) & 15] \
+ + s0(W[(i - 15) & 15]))
+
+#define Ch(x, y, z) (z ^ (x & (y ^ z)))
+#define Maj(x, y, z) ((x & y) | (z & (x | y)))
+
+#define a(i) T[(0 - i) & 7]
+#define b(i) T[(1 - i) & 7]
+#define c(i) T[(2 - i) & 7]
+#define d(i) T[(3 - i) & 7]
+#define e(i) T[(4 - i) & 7]
+#define f(i) T[(5 - i) & 7]
+#define g(i) T[(6 - i) & 7]
+#define h(i) T[(7 - i) & 7]
+
+#define R(i) \
+ h(i) += S1(e(i)) + Ch(e(i), f(i), g(i)) + SHA256_K[i + j] \
+ + (j ? blk2(i) : blk0(i)); \
+ d(i) += h(i); \
+ h(i) += S0(a(i)) + Maj(a(i), b(i), c(i))
+
+#define S0(x) (rotr_32(x, 2) ^ rotr_32(x, 13) ^ rotr_32(x, 22))
+#define S1(x) (rotr_32(x, 6) ^ rotr_32(x, 11) ^ rotr_32(x, 25))
+#define s0(x) (rotr_32(x, 7) ^ rotr_32(x, 18) ^ (x >> 3))
+#define s1(x) (rotr_32(x, 17) ^ rotr_32(x, 19) ^ (x >> 10))
+
+
+static const uint32_t SHA256_K[64] = {
+ 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
+ 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
+ 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
+ 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
+ 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
+ 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
+ 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
+ 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
+ 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
+ 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
+ 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
+ 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
+ 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
+ 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
+ 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
+ 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
+};
+
+
+static void
+transform(uint32_t state[], const uint32_t data[])
+{
+ uint32_t W[16];
+ uint32_t T[8];
+ unsigned int j;
+
+ // Copy state[] to working vars.
+ memcpy(T, state, sizeof(T));
+
+ // 64 operations, partially loop unrolled
+ for (j = 0; j < 64; j += 16) {
+ R( 0); R( 1); R( 2); R( 3);
+ R( 4); R( 5); R( 6); R( 7);
+ R( 8); R( 9); R(10); R(11);
+ R(12); R(13); R(14); R(15);
+ }
+
+ // Add the working vars back into state[].
+ state[0] += a(0);
+ state[1] += b(0);
+ state[2] += c(0);
+ state[3] += d(0);
+ state[4] += e(0);
+ state[5] += f(0);
+ state[6] += g(0);
+ state[7] += h(0);
+}
+
+
+static void
+process(lzma_check_state *check)
+{
+#ifdef WORDS_BIGENDIAN
+ transform(check->state.sha256.state, check->buffer.u32);
+
+#else
+ uint32_t data[16];
+ size_t i;
+
+ for (i = 0; i < 16; ++i)
+ data[i] = bswap32(check->buffer.u32[i]);
+
+ transform(check->state.sha256.state, data);
+#endif
+
+ return;
+}
+
+
+extern void
+lzma_sha256_init(lzma_check_state *check)
+{
+ static const uint32_t s[8] = {
+ 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
+ 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19,
+ };
+
+ memcpy(check->state.sha256.state, s, sizeof(s));
+ check->state.sha256.size = 0;
+
+ return;
+}
+
+
+extern void
+lzma_sha256_update(const uint8_t *buf, size_t size, lzma_check_state *check)
+{
+ // Copy the input data into a properly aligned temporary buffer.
+ // This way we can be called with arbitrarily sized buffers
+ // (no need to be multiple of 64 bytes), and the code works also
+ // on architectures that don't allow unaligned memory access.
+ while (size > 0) {
+ const size_t copy_start = check->state.sha256.size & 0x3F;
+ size_t copy_size = 64 - copy_start;
+ if (copy_size > size)
+ copy_size = size;
+
+ memcpy(check->buffer.u8 + copy_start, buf, copy_size);
+
+ buf += copy_size;
+ size -= copy_size;
+ check->state.sha256.size += copy_size;
+
+ if ((check->state.sha256.size & 0x3F) == 0)
+ process(check);
+ }
+
+ return;
+}
+
+
+extern void
+lzma_sha256_finish(lzma_check_state *check)
+{
+ size_t i;
+
+ // Add padding as described in RFC 3174 (it describes SHA-1 but
+ // the same padding style is used for SHA-256 too).
+ size_t pos = check->state.sha256.size & 0x3F;
+ check->buffer.u8[pos++] = 0x80;
+
+ while (pos != 64 - 8) {
+ if (pos == 64) {
+ process(check);
+ pos = 0;
+ }
+
+ check->buffer.u8[pos++] = 0x00;
+ }
+
+ // Convert the message size from bytes to bits.
+ check->state.sha256.size *= 8;
+
+ check->buffer.u64[(64 - 8) / 8] = conv64be(check->state.sha256.size);
+
+ process(check);
+
+ for (i = 0; i < 8; ++i)
+ check->buffer.u32[i] = conv32be(check->state.sha256.state[i]);
+
+ return;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/alone_decoder.c b/Utilities/cmliblzma/liblzma/common/alone_decoder.c
new file mode 100644
index 0000000000..5f5e564ab6
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/alone_decoder.c
@@ -0,0 +1,236 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file alone_decoder.c
+/// \brief Decoder for LZMA_Alone files
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "alone_decoder.h"
+#include "lzma_decoder.h"
+#include "lz_decoder.h"
+
+
+struct lzma_coder_s {
+ lzma_next_coder next;
+
+ enum {
+ SEQ_PROPERTIES,
+ SEQ_DICTIONARY_SIZE,
+ SEQ_UNCOMPRESSED_SIZE,
+ SEQ_CODER_INIT,
+ SEQ_CODE,
+ } sequence;
+
+ /// If true, reject files that are unlikely to be .lzma files.
+ /// If false, more non-.lzma files get accepted and will give
+ /// LZMA_DATA_ERROR either immediately or after a few output bytes.
+ bool picky;
+
+ /// Position in the header fields
+ size_t pos;
+
+ /// Uncompressed size decoded from the header
+ lzma_vli uncompressed_size;
+
+ /// Memory usage limit
+ uint64_t memlimit;
+
+ /// Amount of memory actually needed (only an estimate)
+ uint64_t memusage;
+
+ /// Options decoded from the header needed to initialize
+ /// the LZMA decoder
+ lzma_options_lzma options;
+};
+
+
+static lzma_ret
+alone_decode(lzma_coder *coder,
+ lzma_allocator *allocator lzma_attribute((__unused__)),
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size,
+ lzma_action action)
+{
+ while (*out_pos < out_size
+ && (coder->sequence == SEQ_CODE || *in_pos < in_size))
+ switch (coder->sequence) {
+ case SEQ_PROPERTIES:
+ if (lzma_lzma_lclppb_decode(&coder->options, in[*in_pos]))
+ return LZMA_FORMAT_ERROR;
+
+ coder->sequence = SEQ_DICTIONARY_SIZE;
+ ++*in_pos;
+ break;
+
+ case SEQ_DICTIONARY_SIZE:
+ coder->options.dict_size
+ |= (size_t)(in[*in_pos]) << (coder->pos * 8);
+
+ if (++coder->pos == 4) {
+ if (coder->picky && coder->options.dict_size
+ != UINT32_MAX) {
+ // A hack to ditch tons of false positives:
+ // We allow only dictionary sizes that are
+ // 2^n or 2^n + 2^(n-1). LZMA_Alone created
+ // only files with 2^n, but accepts any
+ // dictionary size.
+ uint32_t d = coder->options.dict_size - 1;
+ d |= d >> 2;
+ d |= d >> 3;
+ d |= d >> 4;
+ d |= d >> 8;
+ d |= d >> 16;
+ ++d;
+
+ if (d != coder->options.dict_size)
+ return LZMA_FORMAT_ERROR;
+ }
+
+ coder->pos = 0;
+ coder->sequence = SEQ_UNCOMPRESSED_SIZE;
+ }
+
+ ++*in_pos;
+ break;
+
+ case SEQ_UNCOMPRESSED_SIZE:
+ coder->uncompressed_size
+ |= (lzma_vli)(in[*in_pos]) << (coder->pos * 8);
+ ++*in_pos;
+ if (++coder->pos < 8)
+ break;
+
+ // Another hack to ditch false positives: Assume that
+ // if the uncompressed size is known, it must be less
+ // than 256 GiB.
+ if (coder->picky
+ && coder->uncompressed_size != LZMA_VLI_UNKNOWN
+ && coder->uncompressed_size
+ >= (LZMA_VLI_C(1) << 38))
+ return LZMA_FORMAT_ERROR;
+
+ // Calculate the memory usage so that it is ready
+ // for SEQ_CODER_INIT.
+ coder->memusage = lzma_lzma_decoder_memusage(&coder->options)
+ + LZMA_MEMUSAGE_BASE;
+
+ coder->pos = 0;
+ coder->sequence = SEQ_CODER_INIT;
+
+ // Fall through
+
+ case SEQ_CODER_INIT: {
+ lzma_ret ret;
+
+ lzma_filter_info filters[2] = {
+ { 0, &lzma_lzma_decoder_init, &coder->options },
+ { 0, NULL, NULL }
+ };
+
+ if (coder->memusage > coder->memlimit)
+ return LZMA_MEMLIMIT_ERROR;
+
+ ret = lzma_next_filter_init(&coder->next,
+ allocator, filters);
+ if (ret != LZMA_OK)
+ return ret;
+
+ // Use a hack to set the uncompressed size.
+ lzma_lz_decoder_uncompressed(coder->next.coder,
+ coder->uncompressed_size);
+
+ coder->sequence = SEQ_CODE;
+ break;
+ }
+
+ case SEQ_CODE: {
+ return coder->next.code(coder->next.coder,
+ allocator, in, in_pos, in_size,
+ out, out_pos, out_size, action);
+ }
+
+ default:
+ return LZMA_PROG_ERROR;
+ }
+
+ return LZMA_OK;
+}
+
+
+static void
+alone_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->next, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static lzma_ret
+alone_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
+ uint64_t *old_memlimit, uint64_t new_memlimit)
+{
+ *memusage = coder->memusage;
+ *old_memlimit = coder->memlimit;
+
+ if (new_memlimit != 0) {
+ if (new_memlimit < coder->memusage)
+ return LZMA_MEMLIMIT_ERROR;
+
+ coder->memlimit = new_memlimit;
+ }
+
+ return LZMA_OK;
+}
+
+
+extern lzma_ret
+lzma_alone_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ uint64_t memlimit, bool picky)
+{
+ lzma_next_coder_init(&lzma_alone_decoder_init, next, allocator);
+
+ if (memlimit == 0)
+ return LZMA_PROG_ERROR;
+
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &alone_decode;
+ next->end = &alone_decoder_end;
+ next->memconfig = &alone_decoder_memconfig;
+ next->coder->next = LZMA_NEXT_CODER_INIT;
+ }
+
+ next->coder->sequence = SEQ_PROPERTIES;
+ next->coder->picky = picky;
+ next->coder->pos = 0;
+ next->coder->options.dict_size = 0;
+ next->coder->options.preset_dict = NULL;
+ next->coder->options.preset_dict_size = 0;
+ next->coder->uncompressed_size = 0;
+ next->coder->memlimit = memlimit;
+ next->coder->memusage = LZMA_MEMUSAGE_BASE;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_alone_decoder(lzma_stream *strm, uint64_t memlimit)
+{
+ lzma_next_strm_init2(lzma_alone_decoder_init, strm, memlimit, false);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/alone_decoder.h b/Utilities/cmliblzma/liblzma/common/alone_decoder.h
new file mode 100644
index 0000000000..f666fc3823
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/alone_decoder.h
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file alone_decoder.h
+/// \brief Decoder for LZMA_Alone files
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_ALONE_DECODER_H
+#define LZMA_ALONE_DECODER_H
+
+#include "common.h"
+
+
+extern lzma_ret lzma_alone_decoder_init(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ uint64_t memlimit, bool picky);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/alone_encoder.c b/Utilities/cmliblzma/liblzma/common/alone_encoder.c
new file mode 100644
index 0000000000..4207b4a52d
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/alone_encoder.c
@@ -0,0 +1,155 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file alone_decoder.c
+/// \brief Decoder for LZMA_Alone files
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+#include "lzma_encoder.h"
+
+
+#define ALONE_HEADER_SIZE (1 + 4 + 8)
+
+
+struct lzma_coder_s {
+ lzma_next_coder next;
+
+ enum {
+ SEQ_HEADER,
+ SEQ_CODE,
+ } sequence;
+
+ size_t header_pos;
+ uint8_t header[ALONE_HEADER_SIZE];
+};
+
+
+static lzma_ret
+alone_encode(lzma_coder *coder,
+ lzma_allocator *allocator lzma_attribute((__unused__)),
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size,
+ lzma_action action)
+{
+ while (*out_pos < out_size)
+ switch (coder->sequence) {
+ case SEQ_HEADER:
+ lzma_bufcpy(coder->header, &coder->header_pos,
+ ALONE_HEADER_SIZE,
+ out, out_pos, out_size);
+ if (coder->header_pos < ALONE_HEADER_SIZE)
+ return LZMA_OK;
+
+ coder->sequence = SEQ_CODE;
+ break;
+
+ case SEQ_CODE:
+ return coder->next.code(coder->next.coder,
+ allocator, in, in_pos, in_size,
+ out, out_pos, out_size, action);
+
+ default:
+ assert(0);
+ return LZMA_PROG_ERROR;
+ }
+
+ return LZMA_OK;
+}
+
+
+static void
+alone_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->next, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+// At least for now, this is not used by any internal function.
+static lzma_ret
+alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_options_lzma *options)
+{
+ uint32_t d;
+
+ // Initialize the LZMA encoder.
+ const lzma_filter_info filters[2] = {
+ { 0, &lzma_lzma_encoder_init, (void *)(options) },
+ { 0, NULL, NULL }
+ };
+
+ lzma_next_coder_init(&alone_encoder_init, next, allocator);
+
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &alone_encode;
+ next->end = &alone_encoder_end;
+ next->coder->next = LZMA_NEXT_CODER_INIT;
+ }
+
+ // Basic initializations
+ next->coder->sequence = SEQ_HEADER;
+ next->coder->header_pos = 0;
+
+ // Encode the header:
+ // - Properties (1 byte)
+ if (lzma_lzma_lclppb_encode(options, next->coder->header))
+ return LZMA_OPTIONS_ERROR;
+
+ // - Dictionary size (4 bytes)
+ if (options->dict_size < LZMA_DICT_SIZE_MIN)
+ return LZMA_OPTIONS_ERROR;
+
+ // Round up to the next 2^n or 2^n + 2^(n - 1) depending on which
+ // one is the next unless it is UINT32_MAX. While the header would
+ // allow any 32-bit integer, we do this to keep the decoder of liblzma
+ // accepting the resulting files.
+ d = options->dict_size - 1;
+ d |= d >> 2;
+ d |= d >> 3;
+ d |= d >> 4;
+ d |= d >> 8;
+ d |= d >> 16;
+ if (d != UINT32_MAX)
+ ++d;
+
+ unaligned_write32le(next->coder->header + 1, d);
+
+ // - Uncompressed size (always unknown and using EOPM)
+ memset(next->coder->header + 1 + 4, 0xFF, 8);
+
+ return lzma_next_filter_init(&next->coder->next, allocator, filters);
+}
+
+
+/*
+extern lzma_ret
+lzma_alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_options_alone *options)
+{
+ lzma_next_coder_init(&alone_encoder_init, next, allocator, options);
+}
+*/
+
+
+extern LZMA_API(lzma_ret)
+lzma_alone_encoder(lzma_stream *strm, const lzma_options_lzma *options)
+{
+ lzma_next_strm_init1(alone_encoder_init, strm, options);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/auto_decoder.c b/Utilities/cmliblzma/liblzma/common/auto_decoder.c
new file mode 100644
index 0000000000..24cf48905d
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/auto_decoder.c
@@ -0,0 +1,186 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file auto_decoder.c
+/// \brief Autodetect between .xz Stream and .lzma (LZMA_Alone) formats
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "stream_decoder.h"
+#include "alone_decoder.h"
+
+
+struct lzma_coder_s {
+ /// Stream decoder or LZMA_Alone decoder
+ lzma_next_coder next;
+
+ uint64_t memlimit;
+ uint32_t flags;
+
+ enum {
+ SEQ_INIT,
+ SEQ_CODE,
+ SEQ_FINISH,
+ } sequence;
+};
+
+
+static lzma_ret
+auto_decode(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
+{
+ switch (coder->sequence) {
+ case SEQ_INIT:
+ if (*in_pos >= in_size)
+ return LZMA_OK;
+
+ // Update the sequence now, because we want to continue from
+ // SEQ_CODE even if we return some LZMA_*_CHECK.
+ coder->sequence = SEQ_CODE;
+
+ // Detect the file format. For now this is simple, since if
+ // it doesn't start with 0xFD (the first magic byte of the
+ // new format), it has to be LZMA_Alone, or something that
+ // we don't support at all.
+ if (in[*in_pos] == 0xFD) {
+ return_if_error(lzma_stream_decoder_init(
+ &coder->next, allocator,
+ coder->memlimit, coder->flags));
+ } else {
+ return_if_error(lzma_alone_decoder_init(&coder->next,
+ allocator, coder->memlimit, true));
+
+ // If the application wants to know about missing
+ // integrity check or about the check in general, we
+ // need to handle it here, because LZMA_Alone decoder
+ // doesn't accept any flags.
+ if (coder->flags & LZMA_TELL_NO_CHECK)
+ return LZMA_NO_CHECK;
+
+ if (coder->flags & LZMA_TELL_ANY_CHECK)
+ return LZMA_GET_CHECK;
+ }
+
+ // Fall through
+
+ case SEQ_CODE: {
+ const lzma_ret ret = coder->next.code(
+ coder->next.coder, allocator,
+ in, in_pos, in_size,
+ out, out_pos, out_size, action);
+ if (ret != LZMA_STREAM_END
+ || (coder->flags & LZMA_CONCATENATED) == 0)
+ return ret;
+
+ coder->sequence = SEQ_FINISH;
+ }
+
+ // Fall through
+
+ case SEQ_FINISH:
+ // When LZMA_DECODE_CONCATENATED was used and we were decoding
+ // LZMA_Alone file, we need to check check that there is no
+ // trailing garbage and wait for LZMA_FINISH.
+ if (*in_pos < in_size)
+ return LZMA_DATA_ERROR;
+
+ return action == LZMA_FINISH ? LZMA_STREAM_END : LZMA_OK;
+
+ default:
+ assert(0);
+ return LZMA_PROG_ERROR;
+ }
+}
+
+
+static void
+auto_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->next, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static lzma_check
+auto_decoder_get_check(const lzma_coder *coder)
+{
+ // It is LZMA_Alone if get_check is NULL.
+ return coder->next.get_check == NULL ? LZMA_CHECK_NONE
+ : coder->next.get_check(coder->next.coder);
+}
+
+
+static lzma_ret
+auto_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
+ uint64_t *old_memlimit, uint64_t new_memlimit)
+{
+ lzma_ret ret;
+
+ if (coder->next.memconfig != NULL) {
+ ret = coder->next.memconfig(coder->next.coder,
+ memusage, old_memlimit, new_memlimit);
+ assert(*old_memlimit == coder->memlimit);
+ } else {
+ // No coder is configured yet. Use the base value as
+ // the current memory usage.
+ *memusage = LZMA_MEMUSAGE_BASE;
+ *old_memlimit = coder->memlimit;
+ ret = LZMA_OK;
+ }
+
+ if (ret == LZMA_OK && new_memlimit != 0)
+ coder->memlimit = new_memlimit;
+
+ return ret;
+}
+
+
+static lzma_ret
+auto_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ uint64_t memlimit, uint32_t flags)
+{
+ lzma_next_coder_init(&auto_decoder_init, next, allocator);
+
+ if (memlimit == 0)
+ return LZMA_PROG_ERROR;
+
+ if (flags & ~LZMA_SUPPORTED_FLAGS)
+ return LZMA_OPTIONS_ERROR;
+
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &auto_decode;
+ next->end = &auto_decoder_end;
+ next->get_check = &auto_decoder_get_check;
+ next->memconfig = &auto_decoder_memconfig;
+ next->coder->next = LZMA_NEXT_CODER_INIT;
+ }
+
+ next->coder->memlimit = memlimit;
+ next->coder->flags = flags;
+ next->coder->sequence = SEQ_INIT;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_auto_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags)
+{
+ lzma_next_strm_init2(auto_decoder_init, strm, memlimit, flags);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c b/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c
new file mode 100644
index 0000000000..b4bd388eb5
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c
@@ -0,0 +1,82 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file block_buffer_decoder.c
+/// \brief Single-call .xz Block decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "block_decoder.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_buffer_decode(lzma_block *block, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ lzma_next_coder block_decoder;
+ lzma_ret ret;
+
+ if (in_pos == NULL || (in == NULL && *in_pos != in_size)
+ || *in_pos > in_size || out_pos == NULL
+ || (out == NULL && *out_pos != out_size)
+ || *out_pos > out_size)
+ return LZMA_PROG_ERROR;
+
+ // Initialize the Block decoder.
+ block_decoder = LZMA_NEXT_CODER_INIT;
+ ret = lzma_block_decoder_init(&block_decoder, allocator, block);
+
+ if (ret == LZMA_OK) {
+ // Save the positions so that we can restore them in case
+ // an error occurs.
+ const size_t in_start = *in_pos;
+ const size_t out_start = *out_pos;
+
+ // Do the actual decoding.
+ ret = block_decoder.code(block_decoder.coder, allocator,
+ in, in_pos, in_size, out, out_pos, out_size,
+ LZMA_FINISH);
+
+ if (ret == LZMA_STREAM_END) {
+ ret = LZMA_OK;
+ } else {
+ if (ret == LZMA_OK) {
+ // Either the input was truncated or the
+ // output buffer was too small.
+ assert(*in_pos == in_size
+ || *out_pos == out_size);
+
+ // If all the input was consumed, then the
+ // input is truncated, even if the output
+ // buffer is also full. This is because
+ // processing the last byte of the Block
+ // never produces output.
+ //
+ // NOTE: This assumption may break when new
+ // filters are added, if the end marker of
+ // the filter doesn't consume at least one
+ // complete byte.
+ if (*in_pos == in_size)
+ ret = LZMA_DATA_ERROR;
+ else
+ ret = LZMA_BUF_ERROR;
+ }
+
+ // Restore the positions.
+ *in_pos = in_start;
+ *out_pos = out_start;
+ }
+ }
+
+ // Free the decoder memory. This needs to be done even if
+ // initialization fails, because the internal API doesn't
+ // require the initialization function to free its memory on error.
+ lzma_next_end(&block_decoder, allocator);
+
+ return ret;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c
new file mode 100644
index 0000000000..136f7f5737
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c
@@ -0,0 +1,315 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file block_buffer_encoder.c
+/// \brief Single-call .xz Block encoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "block_encoder.h"
+#include "filter_encoder.h"
+#include "lzma2_encoder.h"
+#include "check.h"
+
+
+/// Estimate the maximum size of the Block Header and Check fields for
+/// a Block that uses LZMA2 uncompressed chunks. We could use
+/// lzma_block_header_size() but this is simpler.
+///
+/// Block Header Size + Block Flags + Compressed Size
+/// + Uncompressed Size + Filter Flags for LZMA2 + CRC32 + Check
+/// and round up to the next multiple of four to take Header Padding
+/// into account.
+#define HEADERS_BOUND ((1 + 1 + 2 * LZMA_VLI_BYTES_MAX + 3 + 4 \
+ + LZMA_CHECK_SIZE_MAX + 3) & ~3)
+
+
+static lzma_vli
+lzma2_bound(lzma_vli uncompressed_size)
+{
+ lzma_vli overhead;
+
+ // Prevent integer overflow in overhead calculation.
+ if (uncompressed_size > COMPRESSED_SIZE_MAX)
+ return 0;
+
+ // Calculate the exact overhead of the LZMA2 headers: Round
+ // uncompressed_size up to the next multiple of LZMA2_CHUNK_MAX,
+ // multiply by the size of per-chunk header, and add one byte for
+ // the end marker.
+ overhead = ((uncompressed_size + LZMA2_CHUNK_MAX - 1)
+ / LZMA2_CHUNK_MAX)
+ * LZMA2_HEADER_UNCOMPRESSED + 1;
+
+ // Catch the possible integer overflow.
+ if (COMPRESSED_SIZE_MAX - overhead < uncompressed_size)
+ return 0;
+
+ return uncompressed_size + overhead;
+}
+
+
+extern LZMA_API(size_t)
+lzma_block_buffer_bound(size_t uncompressed_size)
+{
+ // For now, if the data doesn't compress, we always use uncompressed
+ // chunks of LZMA2. In future we may use Subblock filter too, but
+ // but for simplicity we probably will still use the same bound
+ // calculation even though Subblock filter would have slightly less
+ // overhead.
+ lzma_vli lzma2_size = lzma2_bound(uncompressed_size);
+ if (lzma2_size == 0)
+ return 0;
+
+ // Take Block Padding into account.
+ lzma2_size = (lzma2_size + 3) & ~LZMA_VLI_C(3);
+
+#if SIZE_MAX < LZMA_VLI_MAX
+ // Catch the possible integer overflow on 32-bit systems. There's no
+ // overflow on 64-bit systems, because lzma2_bound() already takes
+ // into account the size of the headers in the Block.
+ if (SIZE_MAX - HEADERS_BOUND < lzma2_size)
+ return 0;
+#endif
+
+ return HEADERS_BOUND + lzma2_size;
+}
+
+
+static lzma_ret
+block_encode_uncompressed(lzma_block *block, const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ size_t in_pos = 0;
+ uint8_t control = 0x01; // Dictionary reset
+ lzma_filter *filters_orig;
+
+ // TODO: Figure out if the last filter is LZMA2 or Subblock and use
+ // that filter to encode the uncompressed chunks.
+
+ // Use LZMA2 uncompressed chunks. We wouldn't need a dictionary at
+ // all, but LZMA2 always requires a dictionary, so use the minimum
+ // value to minimize memory usage of the decoder.
+ lzma_options_lzma lzma2 = { LZMA_DICT_SIZE_MIN };
+
+ lzma_filter filters[2];
+ filters[0].id = LZMA_FILTER_LZMA2;
+ filters[0].options = &lzma2;
+ filters[1].id = LZMA_VLI_UNKNOWN;
+
+ // Set the above filter options to *block temporarily so that we can
+ // encode the Block Header.
+ filters_orig = block->filters;
+ block->filters = filters;
+
+ if (lzma_block_header_size(block) != LZMA_OK) {
+ block->filters = filters_orig;
+ return LZMA_PROG_ERROR;
+ }
+
+ // Check that there's enough output space. The caller has already
+ // set block->compressed_size to what lzma2_bound() has returned,
+ // so we can reuse that value. We know that compressed_size is a
+ // known valid VLI and header_size is a small value so their sum
+ // will never overflow.
+ assert(block->compressed_size == lzma2_bound(in_size));
+ if (out_size - *out_pos
+ < block->header_size + block->compressed_size) {
+ block->filters = filters_orig;
+ return LZMA_BUF_ERROR;
+ }
+
+ if (lzma_block_header_encode(block, out + *out_pos) != LZMA_OK) {
+ block->filters = filters_orig;
+ return LZMA_PROG_ERROR;
+ }
+
+ block->filters = filters_orig;
+ *out_pos += block->header_size;
+
+ // Encode the data using LZMA2 uncompressed chunks.
+
+ while (in_pos < in_size) {
+ size_t copy_size;
+
+ // Control byte: Indicate uncompressed chunk, of which
+ // the first resets the dictionary.
+ out[(*out_pos)++] = control;
+ control = 0x02; // No dictionary reset
+
+ // Size of the uncompressed chunk
+ copy_size = my_min(in_size - in_pos, LZMA2_CHUNK_MAX);
+ out[(*out_pos)++] = (copy_size - 1) >> 8;
+ out[(*out_pos)++] = (copy_size - 1) & 0xFF;
+
+ // The actual data
+ assert(*out_pos + copy_size <= out_size);
+ memcpy(out + *out_pos, in + in_pos, copy_size);
+
+ in_pos += copy_size;
+ *out_pos += copy_size;
+ }
+
+ // End marker
+ out[(*out_pos)++] = 0x00;
+ assert(*out_pos <= out_size);
+
+ return LZMA_OK;
+}
+
+
+static lzma_ret
+block_encode_normal(lzma_block *block, lzma_allocator *allocator,
+ const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ size_t out_start;
+ lzma_next_coder raw_encoder = LZMA_NEXT_CODER_INIT;
+ lzma_ret ret;
+
+ // Find out the size of the Block Header.
+ block->compressed_size = lzma2_bound(in_size);
+ if (block->compressed_size == 0)
+ return LZMA_DATA_ERROR;
+
+ block->uncompressed_size = in_size;
+ return_if_error(lzma_block_header_size(block));
+
+ // Reserve space for the Block Header and skip it for now.
+ if (out_size - *out_pos <= block->header_size)
+ return LZMA_BUF_ERROR;
+
+ out_start = *out_pos;
+ *out_pos += block->header_size;
+
+ // Limit out_size so that we stop encoding if the output would grow
+ // bigger than what uncompressed Block would be.
+ if (out_size - *out_pos > block->compressed_size)
+ out_size = *out_pos + block->compressed_size;
+
+ // TODO: In many common cases this could be optimized to use
+ // significantly less memory.
+ ret = lzma_raw_encoder_init(
+ &raw_encoder, allocator, block->filters);
+
+ if (ret == LZMA_OK) {
+ size_t in_pos = 0;
+ ret = raw_encoder.code(raw_encoder.coder, allocator,
+ in, &in_pos, in_size, out, out_pos, out_size,
+ LZMA_FINISH);
+ }
+
+ // NOTE: This needs to be run even if lzma_raw_encoder_init() failed.
+ lzma_next_end(&raw_encoder, allocator);
+
+ if (ret == LZMA_STREAM_END) {
+ // Compression was successful. Write the Block Header.
+ block->compressed_size
+ = *out_pos - (out_start + block->header_size);
+ ret = lzma_block_header_encode(block, out + out_start);
+ if (ret != LZMA_OK)
+ ret = LZMA_PROG_ERROR;
+
+ } else if (ret == LZMA_OK) {
+ // Output buffer became full.
+ ret = LZMA_BUF_ERROR;
+ }
+
+ // Reset *out_pos if something went wrong.
+ if (ret != LZMA_OK)
+ *out_pos = out_start;
+
+ return ret;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
+ const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ size_t check_size;
+ lzma_ret ret;
+ size_t i;
+
+ // Validate the arguments.
+ if (block == NULL || (in == NULL && in_size != 0) || out == NULL
+ || out_pos == NULL || *out_pos > out_size)
+ return LZMA_PROG_ERROR;
+
+ // The contents of the structure may depend on the version so
+ // check the version before validating the contents of *block.
+ if (block->version != 0)
+ return LZMA_OPTIONS_ERROR;
+
+ if ((unsigned int)(block->check) > LZMA_CHECK_ID_MAX
+ || block->filters == NULL)
+ return LZMA_PROG_ERROR;
+
+ if (!lzma_check_is_supported(block->check))
+ return LZMA_UNSUPPORTED_CHECK;
+
+ // Size of a Block has to be a multiple of four, so limit the size
+ // here already. This way we don't need to check it again when adding
+ // Block Padding.
+ out_size -= (out_size - *out_pos) & 3;
+
+ // Get the size of the Check field.
+ check_size = lzma_check_size(block->check);
+ assert(check_size != UINT32_MAX);
+
+ // Reserve space for the Check field.
+ if (out_size - *out_pos <= check_size)
+ return LZMA_BUF_ERROR;
+
+ out_size -= check_size;
+
+ // Do the actual compression.
+ ret = block_encode_normal(block, allocator,
+ in, in_size, out, out_pos, out_size);
+ if (ret != LZMA_OK) {
+ // If the error was something else than output buffer
+ // becoming full, return the error now.
+ if (ret != LZMA_BUF_ERROR)
+ return ret;
+
+ // The data was uncompressible (at least with the options
+ // given to us) or the output buffer was too small. Use the
+ // uncompressed chunks of LZMA2 to wrap the data into a valid
+ // Block. If we haven't been given enough output space, even
+ // this may fail.
+ return_if_error(block_encode_uncompressed(block, in, in_size,
+ out, out_pos, out_size));
+ }
+
+ assert(*out_pos <= out_size);
+
+ // Block Padding. No buffer overflow here, because we already adjusted
+ // out_size so that (out_size - out_start) is a multiple of four.
+ // Thus, if the buffer is full, the loop body can never run.
+ for (i = (size_t)(block->compressed_size); i & 3; ++i) {
+ assert(*out_pos < out_size);
+ out[(*out_pos)++] = 0x00;
+ }
+
+ // If there's no Check field, we are done now.
+ if (check_size > 0) {
+ // Calculate the integrity check. We reserved space for
+ // the Check field earlier so we don't need to check for
+ // available output space here.
+ lzma_check_state check;
+ lzma_check_init(&check, block->check);
+ lzma_check_update(&check, block->check, in, in_size);
+ lzma_check_finish(&check, block->check);
+
+ memcpy(block->raw_check, check.buffer.u8, check_size);
+ memcpy(out + *out_pos, check.buffer.u8, check_size);
+ *out_pos += check_size;
+ }
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/block_decoder.c b/Utilities/cmliblzma/liblzma/common/block_decoder.c
new file mode 100644
index 0000000000..35996e7cf0
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/block_decoder.c
@@ -0,0 +1,242 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file block_decoder.c
+/// \brief Decodes .xz Blocks
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "block_decoder.h"
+#include "filter_decoder.h"
+#include "check.h"
+
+
+struct lzma_coder_s {
+ enum {
+ SEQ_CODE,
+ SEQ_PADDING,
+ SEQ_CHECK,
+ } sequence;
+
+ /// The filters in the chain; initialized with lzma_raw_decoder_init().
+ lzma_next_coder next;
+
+ /// Decoding options; we also write Compressed Size and Uncompressed
+ /// Size back to this structure when the decoding has been finished.
+ lzma_block *block;
+
+ /// Compressed Size calculated while decoding
+ lzma_vli compressed_size;
+
+ /// Uncompressed Size calculated while decoding
+ lzma_vli uncompressed_size;
+
+ /// Maximum allowed Compressed Size; this takes into account the
+ /// size of the Block Header and Check fields when Compressed Size
+ /// is unknown.
+ lzma_vli compressed_limit;
+
+ /// Position when reading the Check field
+ size_t check_pos;
+
+ /// Check of the uncompressed data
+ lzma_check_state check;
+};
+
+
+static inline bool
+update_size(lzma_vli *size, lzma_vli add, lzma_vli limit)
+{
+ if (limit > LZMA_VLI_MAX)
+ limit = LZMA_VLI_MAX;
+
+ if (limit < *size || limit - *size < add)
+ return true;
+
+ *size += add;
+
+ return false;
+}
+
+
+static inline bool
+is_size_valid(lzma_vli size, lzma_vli reference)
+{
+ return reference == LZMA_VLI_UNKNOWN || reference == size;
+}
+
+
+static lzma_ret
+block_decode(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
+{
+ switch (coder->sequence) {
+ case SEQ_CODE: {
+ const size_t in_start = *in_pos;
+ const size_t out_start = *out_pos;
+
+ const lzma_ret ret = coder->next.code(coder->next.coder,
+ allocator, in, in_pos, in_size,
+ out, out_pos, out_size, action);
+
+ const size_t in_used = *in_pos - in_start;
+ const size_t out_used = *out_pos - out_start;
+
+ // NOTE: We compare to compressed_limit here, which prevents
+ // the total size of the Block growing past LZMA_VLI_MAX.
+ if (update_size(&coder->compressed_size, in_used,
+ coder->compressed_limit)
+ || update_size(&coder->uncompressed_size,
+ out_used,
+ coder->block->uncompressed_size))
+ return LZMA_DATA_ERROR;
+
+ lzma_check_update(&coder->check, coder->block->check,
+ out + out_start, out_used);
+
+ if (ret != LZMA_STREAM_END)
+ return ret;
+
+ // Compressed and Uncompressed Sizes are now at their final
+ // values. Verify that they match the values given to us.
+ if (!is_size_valid(coder->compressed_size,
+ coder->block->compressed_size)
+ || !is_size_valid(coder->uncompressed_size,
+ coder->block->uncompressed_size))
+ return LZMA_DATA_ERROR;
+
+ // Copy the values into coder->block. The caller
+ // may use this information to construct Index.
+ coder->block->compressed_size = coder->compressed_size;
+ coder->block->uncompressed_size = coder->uncompressed_size;
+
+ coder->sequence = SEQ_PADDING;
+ }
+
+ // Fall through
+
+ case SEQ_PADDING:
+ // Compressed Data is padded to a multiple of four bytes.
+ while (coder->compressed_size & 3) {
+ if (*in_pos >= in_size)
+ return LZMA_OK;
+
+ // We use compressed_size here just get the Padding
+ // right. The actual Compressed Size was stored to
+ // coder->block already, and won't be modified by
+ // us anymore.
+ ++coder->compressed_size;
+
+ if (in[(*in_pos)++] != 0x00)
+ return LZMA_DATA_ERROR;
+ }
+
+ if (coder->block->check == LZMA_CHECK_NONE)
+ return LZMA_STREAM_END;
+
+ lzma_check_finish(&coder->check, coder->block->check);
+ coder->sequence = SEQ_CHECK;
+
+ // Fall through
+
+ case SEQ_CHECK: {
+ const size_t check_size = lzma_check_size(coder->block->check);
+ lzma_bufcpy(in, in_pos, in_size, coder->block->raw_check,
+ &coder->check_pos, check_size);
+ if (coder->check_pos < check_size)
+ return LZMA_OK;
+
+ // Validate the Check only if we support it.
+ // coder->check.buffer may be uninitialized
+ // when the Check ID is not supported.
+ if (lzma_check_is_supported(coder->block->check)
+ && memcmp(coder->block->raw_check,
+ coder->check.buffer.u8,
+ check_size) != 0)
+ return LZMA_DATA_ERROR;
+
+ return LZMA_STREAM_END;
+ }
+ }
+
+ return LZMA_PROG_ERROR;
+}
+
+
+static void
+block_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->next, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+extern lzma_ret
+lzma_block_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ lzma_block *block)
+{
+ lzma_next_coder_init(&lzma_block_decoder_init, next, allocator);
+
+ // Validate the options. lzma_block_unpadded_size() does that for us
+ // except for Uncompressed Size and filters. Filters are validated
+ // by the raw decoder.
+ if (lzma_block_unpadded_size(block) == 0
+ || !lzma_vli_is_valid(block->uncompressed_size))
+ return LZMA_PROG_ERROR;
+
+ // Allocate and initialize *next->coder if needed.
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &block_decode;
+ next->end = &block_decoder_end;
+ next->coder->next = LZMA_NEXT_CODER_INIT;
+ }
+
+ // Basic initializations
+ next->coder->sequence = SEQ_CODE;
+ next->coder->block = block;
+ next->coder->compressed_size = 0;
+ next->coder->uncompressed_size = 0;
+
+ // If Compressed Size is not known, we calculate the maximum allowed
+ // value so that encoded size of the Block (including Block Padding)
+ // is still a valid VLI and a multiple of four.
+ next->coder->compressed_limit
+ = block->compressed_size == LZMA_VLI_UNKNOWN
+ ? (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
+ - block->header_size
+ - lzma_check_size(block->check)
+ : block->compressed_size;
+
+ // Initialize the check. It's caller's problem if the Check ID is not
+ // supported, and the Block decoder cannot verify the Check field.
+ // Caller can test lzma_check_is_supported(block->check).
+ next->coder->check_pos = 0;
+ lzma_check_init(&next->coder->check, block->check);
+
+ // Initialize the filter chain.
+ return lzma_raw_decoder_init(&next->coder->next, allocator,
+ block->filters);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_decoder(lzma_stream *strm, lzma_block *block)
+{
+ lzma_next_strm_init1(lzma_block_decoder_init, strm, block);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/block_decoder.h b/Utilities/cmliblzma/liblzma/common/block_decoder.h
new file mode 100644
index 0000000000..7da9df63f7
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/block_decoder.h
@@ -0,0 +1,22 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file block_decoder.h
+/// \brief Decodes .xz Blocks
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_BLOCK_DECODER_H
+#define LZMA_BLOCK_DECODER_H
+
+#include "common.h"
+
+
+extern lzma_ret lzma_block_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, lzma_block *block);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/block_encoder.c b/Utilities/cmliblzma/liblzma/common/block_encoder.c
new file mode 100644
index 0000000000..ed748273eb
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/block_encoder.c
@@ -0,0 +1,217 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file block_encoder.c
+/// \brief Encodes .xz Blocks
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "block_encoder.h"
+#include "filter_encoder.h"
+#include "check.h"
+
+
+struct lzma_coder_s {
+ /// The filters in the chain; initialized with lzma_raw_decoder_init().
+ lzma_next_coder next;
+
+ /// Encoding options; we also write Unpadded Size, Compressed Size,
+ /// and Uncompressed Size back to this structure when the encoding
+ /// has been finished.
+ lzma_block *block;
+
+ enum {
+ SEQ_CODE,
+ SEQ_PADDING,
+ SEQ_CHECK,
+ } sequence;
+
+ /// Compressed Size calculated while encoding
+ lzma_vli compressed_size;
+
+ /// Uncompressed Size calculated while encoding
+ lzma_vli uncompressed_size;
+
+ /// Position in the Check field
+ size_t pos;
+
+ /// Check of the uncompressed data
+ lzma_check_state check;
+};
+
+
+static lzma_ret
+block_encode(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
+{
+ // Check that our amount of input stays in proper limits.
+ if (LZMA_VLI_MAX - coder->uncompressed_size < in_size - *in_pos)
+ return LZMA_DATA_ERROR;
+
+ switch (coder->sequence) {
+ case SEQ_CODE: {
+ const size_t in_start = *in_pos;
+ const size_t out_start = *out_pos;
+
+ const lzma_ret ret = coder->next.code(coder->next.coder,
+ allocator, in, in_pos, in_size,
+ out, out_pos, out_size, action);
+
+ const size_t in_used = *in_pos - in_start;
+ const size_t out_used = *out_pos - out_start;
+
+ if (COMPRESSED_SIZE_MAX - coder->compressed_size < out_used)
+ return LZMA_DATA_ERROR;
+
+ coder->compressed_size += out_used;
+
+ // No need to check for overflow because we have already
+ // checked it at the beginning of this function.
+ coder->uncompressed_size += in_used;
+
+ lzma_check_update(&coder->check, coder->block->check,
+ in + in_start, in_used);
+
+ if (ret != LZMA_STREAM_END || action == LZMA_SYNC_FLUSH)
+ return ret;
+
+ assert(*in_pos == in_size);
+ assert(action == LZMA_FINISH);
+
+ // Copy the values into coder->block. The caller
+ // may use this information to construct Index.
+ coder->block->compressed_size = coder->compressed_size;
+ coder->block->uncompressed_size = coder->uncompressed_size;
+
+ coder->sequence = SEQ_PADDING;
+ }
+
+ // Fall through
+
+ case SEQ_PADDING:
+ // Pad Compressed Data to a multiple of four bytes. We can
+ // use coder->compressed_size for this since we don't need
+ // it for anything else anymore.
+ while (coder->compressed_size & 3) {
+ if (*out_pos >= out_size)
+ return LZMA_OK;
+
+ out[*out_pos] = 0x00;
+ ++*out_pos;
+ ++coder->compressed_size;
+ }
+
+ if (coder->block->check == LZMA_CHECK_NONE)
+ return LZMA_STREAM_END;
+
+ lzma_check_finish(&coder->check, coder->block->check);
+
+ coder->sequence = SEQ_CHECK;
+
+ // Fall through
+
+ case SEQ_CHECK: {
+ const size_t check_size = lzma_check_size(coder->block->check);
+ lzma_bufcpy(coder->check.buffer.u8, &coder->pos, check_size,
+ out, out_pos, out_size);
+ if (coder->pos < check_size)
+ return LZMA_OK;
+
+ memcpy(coder->block->raw_check, coder->check.buffer.u8,
+ check_size);
+ return LZMA_STREAM_END;
+ }
+ }
+
+ return LZMA_PROG_ERROR;
+}
+
+
+static void
+block_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->next, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static lzma_ret
+block_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
+ const lzma_filter *filters lzma_attribute((__unused__)),
+ const lzma_filter *reversed_filters)
+{
+ if (coder->sequence != SEQ_CODE)
+ return LZMA_PROG_ERROR;
+
+ return lzma_next_filter_update(
+ &coder->next, allocator, reversed_filters);
+}
+
+
+extern lzma_ret
+lzma_block_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ lzma_block *block)
+{
+ lzma_next_coder_init(&lzma_block_encoder_init, next, allocator);
+
+ if (block == NULL)
+ return LZMA_PROG_ERROR;
+
+ // The contents of the structure may depend on the version so
+ // check the version first.
+ if (block->version != 0)
+ return LZMA_OPTIONS_ERROR;
+
+ // If the Check ID is not supported, we cannot calculate the check and
+ // thus not create a proper Block.
+ if ((unsigned int)(block->check) > LZMA_CHECK_ID_MAX)
+ return LZMA_PROG_ERROR;
+
+ if (!lzma_check_is_supported(block->check))
+ return LZMA_UNSUPPORTED_CHECK;
+
+ // Allocate and initialize *next->coder if needed.
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &block_encode;
+ next->end = &block_encoder_end;
+ next->update = &block_encoder_update;
+ next->coder->next = LZMA_NEXT_CODER_INIT;
+ }
+
+ // Basic initializations
+ next->coder->sequence = SEQ_CODE;
+ next->coder->block = block;
+ next->coder->compressed_size = 0;
+ next->coder->uncompressed_size = 0;
+ next->coder->pos = 0;
+
+ // Initialize the check
+ lzma_check_init(&next->coder->check, block->check);
+
+ // Initialize the requested filters.
+ return lzma_raw_encoder_init(&next->coder->next, allocator,
+ block->filters);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_encoder(lzma_stream *strm, lzma_block *block)
+{
+ lzma_next_strm_init1(lzma_block_encoder_init, strm, block);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/block_encoder.h b/Utilities/cmliblzma/liblzma/common/block_encoder.h
new file mode 100644
index 0000000000..b9eff0be27
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/block_encoder.h
@@ -0,0 +1,47 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file block_encoder.h
+/// \brief Encodes .xz Blocks
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_BLOCK_ENCODER_H
+#define LZMA_BLOCK_ENCODER_H
+
+#include "common.h"
+
+
+/// \brief Biggest Compressed Size value that the Block encoder supports
+///
+/// The maximum size of a single Block is limited by the maximum size of
+/// a Stream, which in theory is 2^63 - 3 bytes (i.e. LZMA_VLI_MAX - 3).
+/// While the size is really big and no one should hit it in practice, we
+/// take it into account in some places anyway to catch some errors e.g. if
+/// application passes insanely big value to some function.
+///
+/// We could take into account the headers etc. to determine the exact
+/// maximum size of the Compressed Data field, but the complexity would give
+/// us nothing useful. Instead, limit the size of Compressed Data so that
+/// even with biggest possible Block Header and Check fields the total
+/// encoded size of the Block stays as a valid VLI. This doesn't guarantee
+/// that the size of the Stream doesn't grow too big, but that problem is
+/// taken care outside the Block handling code.
+///
+/// ~LZMA_VLI_C(3) is to guarantee that if we need padding at the end of
+/// the Compressed Data field, it will still stay in the proper limit.
+///
+/// This constant is in this file because it is needed in both
+/// block_encoder.c and block_buffer_encoder.c.
+#define COMPRESSED_SIZE_MAX ((LZMA_VLI_MAX - LZMA_BLOCK_HEADER_SIZE_MAX \
+ - LZMA_CHECK_SIZE_MAX) & ~LZMA_VLI_C(3))
+
+
+extern lzma_ret lzma_block_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, lzma_block *block);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/block_header_decoder.c b/Utilities/cmliblzma/liblzma/common/block_header_decoder.c
new file mode 100644
index 0000000000..f6e470e696
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/block_header_decoder.c
@@ -0,0 +1,121 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file block_header_decoder.c
+/// \brief Decodes Block Header from .xz files
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+#include "check.h"
+
+
+static void
+free_properties(lzma_block *block, lzma_allocator *allocator)
+{
+ size_t i;
+
+ // Free allocated filter options. The last array member is not
+ // touched after the initialization in the beginning of
+ // lzma_block_header_decode(), so we don't need to touch that here.
+ for (i = 0; i < LZMA_FILTERS_MAX; ++i) {
+ lzma_free(block->filters[i].options, allocator);
+ block->filters[i].id = LZMA_VLI_UNKNOWN;
+ block->filters[i].options = NULL;
+ }
+
+ return;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_header_decode(lzma_block *block,
+ lzma_allocator *allocator, const uint8_t *in)
+{
+ const size_t filter_count = (in[1] & 3) + 1;
+ size_t in_size;
+ size_t i;
+
+ // Start after the Block Header Size and Block Flags fields.
+ size_t in_pos = 2;
+
+ // NOTE: We consider the header to be corrupt not only when the
+ // CRC32 doesn't match, but also when variable-length integers
+ // are invalid or over 63 bits, or if the header is too small
+ // to contain the claimed information.
+
+ // Initialize the filter options array. This way the caller can
+ // safely free() the options even if an error occurs in this function.
+ for (i = 0; i <= LZMA_FILTERS_MAX; ++i) {
+ block->filters[i].id = LZMA_VLI_UNKNOWN;
+ block->filters[i].options = NULL;
+ }
+
+ // Always zero for now.
+ block->version = 0;
+
+ // Validate Block Header Size and Check type. The caller must have
+ // already set these, so it is a programming error if this test fails.
+ if (lzma_block_header_size_decode(in[0]) != block->header_size
+ || (unsigned int)(block->check) > LZMA_CHECK_ID_MAX)
+ return LZMA_PROG_ERROR;
+
+ // Exclude the CRC32 field.
+ in_size = block->header_size - 4;
+
+ // Verify CRC32
+ if (lzma_crc32(in, in_size, 0) != unaligned_read32le(in + in_size))
+ return LZMA_DATA_ERROR;
+
+ // Check for unsupported flags.
+ if (in[1] & 0x3C)
+ return LZMA_OPTIONS_ERROR;
+
+ // Compressed Size
+ if (in[1] & 0x40) {
+ return_if_error(lzma_vli_decode(&block->compressed_size,
+ NULL, in, &in_pos, in_size));
+
+ // Validate Compressed Size. This checks that it isn't zero
+ // and that the total size of the Block is a valid VLI.
+ if (lzma_block_unpadded_size(block) == 0)
+ return LZMA_DATA_ERROR;
+ } else {
+ block->compressed_size = LZMA_VLI_UNKNOWN;
+ }
+
+ // Uncompressed Size
+ if (in[1] & 0x80)
+ return_if_error(lzma_vli_decode(&block->uncompressed_size,
+ NULL, in, &in_pos, in_size));
+ else
+ block->uncompressed_size = LZMA_VLI_UNKNOWN;
+
+ // Filter Flags
+ for (i = 0; i < filter_count; ++i) {
+ const lzma_ret ret = lzma_filter_flags_decode(
+ &block->filters[i], allocator,
+ in, &in_pos, in_size);
+ if (ret != LZMA_OK) {
+ free_properties(block, allocator);
+ return ret;
+ }
+ }
+
+ // Padding
+ while (in_pos < in_size) {
+ if (in[in_pos++] != 0x00) {
+ free_properties(block, allocator);
+
+ // Possibly some new field present so use
+ // LZMA_OPTIONS_ERROR instead of LZMA_DATA_ERROR.
+ return LZMA_OPTIONS_ERROR;
+ }
+ }
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/block_header_encoder.c b/Utilities/cmliblzma/liblzma/common/block_header_encoder.c
new file mode 100644
index 0000000000..650295c009
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/block_header_encoder.c
@@ -0,0 +1,137 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file block_header_encoder.c
+/// \brief Encodes Block Header for .xz files
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+#include "check.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_header_size(lzma_block *block)
+{
+ size_t i;
+
+ // Block Header Size + Block Flags + CRC32.
+ uint32_t size = 1 + 1 + 4;
+
+ if (block->version != 0)
+ return LZMA_OPTIONS_ERROR;
+
+ // Compressed Size
+ if (block->compressed_size != LZMA_VLI_UNKNOWN) {
+ const uint32_t add = lzma_vli_size(block->compressed_size);
+ if (add == 0 || block->compressed_size == 0)
+ return LZMA_PROG_ERROR;
+
+ size += add;
+ }
+
+ // Uncompressed Size
+ if (block->uncompressed_size != LZMA_VLI_UNKNOWN) {
+ const uint32_t add = lzma_vli_size(block->uncompressed_size);
+ if (add == 0)
+ return LZMA_PROG_ERROR;
+
+ size += add;
+ }
+
+ // List of Filter Flags
+ if (block->filters == NULL || block->filters[0].id == LZMA_VLI_UNKNOWN)
+ return LZMA_PROG_ERROR;
+
+ for (i = 0; block->filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
+ uint32_t add;
+
+ // Don't allow too many filters.
+ if (i == LZMA_FILTERS_MAX)
+ return LZMA_PROG_ERROR;
+
+ return_if_error(lzma_filter_flags_size(&add,
+ block->filters + i));
+
+ size += add;
+ }
+
+ // Pad to a multiple of four bytes.
+ block->header_size = (size + 3) & ~UINT32_C(3);
+
+ // NOTE: We don't verify that the encoded size of the Block stays
+ // within limits. This is because it is possible that we are called
+ // with exaggerated Compressed Size (e.g. LZMA_VLI_MAX) to reserve
+ // space for Block Header, and later called again with lower,
+ // real values.
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_header_encode(const lzma_block *block, uint8_t *out)
+{
+ size_t out_size;
+ size_t out_pos = 2;
+ size_t filter_count = 0;
+
+ // Validate everything but filters.
+ if (lzma_block_unpadded_size(block) == 0
+ || !lzma_vli_is_valid(block->uncompressed_size))
+ return LZMA_PROG_ERROR;
+
+ // Indicate the size of the buffer _excluding_ the CRC32 field.
+ out_size = block->header_size - 4;
+
+ // Store the Block Header Size.
+ out[0] = out_size / 4;
+
+ // We write Block Flags in pieces.
+ out[1] = 0x00;
+
+ // Compressed Size
+ if (block->compressed_size != LZMA_VLI_UNKNOWN) {
+ return_if_error(lzma_vli_encode(block->compressed_size, NULL,
+ out, &out_pos, out_size));
+
+ out[1] |= 0x40;
+ }
+
+ // Uncompressed Size
+ if (block->uncompressed_size != LZMA_VLI_UNKNOWN) {
+ return_if_error(lzma_vli_encode(block->uncompressed_size, NULL,
+ out, &out_pos, out_size));
+
+ out[1] |= 0x80;
+ }
+
+ // Filter Flags
+ if (block->filters == NULL || block->filters[0].id == LZMA_VLI_UNKNOWN)
+ return LZMA_PROG_ERROR;
+
+ do {
+ // There can be a maximum of four filters.
+ if (filter_count == LZMA_FILTERS_MAX)
+ return LZMA_PROG_ERROR;
+
+ return_if_error(lzma_filter_flags_encode(
+ block->filters + filter_count,
+ out, &out_pos, out_size));
+
+ } while (block->filters[++filter_count].id != LZMA_VLI_UNKNOWN);
+
+ out[1] |= filter_count - 1;
+
+ // Padding
+ memzero(out + out_pos, out_size - out_pos);
+
+ // CRC32
+ unaligned_write32le(out + out_size, lzma_crc32(out, out_size, 0));
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/block_util.c b/Utilities/cmliblzma/liblzma/common/block_util.c
new file mode 100644
index 0000000000..4cd34d1004
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/block_util.c
@@ -0,0 +1,95 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file block_header.c
+/// \brief Utility functions to handle lzma_block
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+#include "index.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_compressed_size(lzma_block *block, lzma_vli unpadded_size)
+{
+ uint32_t container_size;
+ lzma_vli compressed_size;
+
+ // Validate everything but Uncompressed Size and filters.
+ if (lzma_block_unpadded_size(block) == 0)
+ return LZMA_PROG_ERROR;
+
+ container_size = block->header_size
+ + lzma_check_size(block->check);
+
+ // Validate that Compressed Size will be greater than zero.
+ if (unpadded_size <= container_size)
+ return LZMA_DATA_ERROR;
+
+ // Calculate what Compressed Size is supposed to be.
+ // If Compressed Size was present in Block Header,
+ // compare that the new value matches it.
+ compressed_size = unpadded_size - container_size;
+ if (block->compressed_size != LZMA_VLI_UNKNOWN
+ && block->compressed_size != compressed_size)
+ return LZMA_DATA_ERROR;
+
+ block->compressed_size = compressed_size;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_block_unpadded_size(const lzma_block *block)
+{
+ lzma_vli unpadded_size;
+
+ // Validate the values that we are interested in i.e. all but
+ // Uncompressed Size and the filters.
+ //
+ // NOTE: This function is used for validation too, so it is
+ // essential that these checks are always done even if
+ // Compressed Size is unknown.
+ if (block == NULL || block->version != 0
+ || block->header_size < LZMA_BLOCK_HEADER_SIZE_MIN
+ || block->header_size > LZMA_BLOCK_HEADER_SIZE_MAX
+ || (block->header_size & 3)
+ || !lzma_vli_is_valid(block->compressed_size)
+ || block->compressed_size == 0
+ || (unsigned int)(block->check) > LZMA_CHECK_ID_MAX)
+ return 0;
+
+ // If Compressed Size is unknown, return that we cannot know
+ // size of the Block either.
+ if (block->compressed_size == LZMA_VLI_UNKNOWN)
+ return LZMA_VLI_UNKNOWN;
+
+ // Calculate Unpadded Size and validate it.
+ unpadded_size = block->compressed_size
+ + block->header_size
+ + lzma_check_size(block->check);
+
+ assert(unpadded_size >= UNPADDED_SIZE_MIN);
+ if (unpadded_size > UNPADDED_SIZE_MAX)
+ return 0;
+
+ return unpadded_size;
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_block_total_size(const lzma_block *block)
+{
+ lzma_vli unpadded_size = lzma_block_unpadded_size(block);
+
+ if (unpadded_size != LZMA_VLI_UNKNOWN)
+ unpadded_size = vli_ceil4(unpadded_size);
+
+ return unpadded_size;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/common.c b/Utilities/cmliblzma/liblzma/common/common.c
new file mode 100644
index 0000000000..2e723c8fee
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/common.c
@@ -0,0 +1,390 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file common.h
+/// \brief Common functions needed in many places in liblzma
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+
+
+/////////////
+// Version //
+/////////////
+
+extern LZMA_API(uint32_t)
+lzma_version_number(void)
+{
+ return LZMA_VERSION;
+}
+
+
+extern LZMA_API(const char *)
+lzma_version_string(void)
+{
+ return LZMA_VERSION_STRING;
+}
+
+
+///////////////////////
+// Memory allocation //
+///////////////////////
+
+extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
+lzma_alloc(size_t size, lzma_allocator *allocator)
+{
+ void *ptr;
+
+ // Some malloc() variants return NULL if called with size == 0.
+ if (size == 0)
+ size = 1;
+
+ if (allocator != NULL && allocator->alloc != NULL)
+ ptr = allocator->alloc(allocator->opaque, 1, size);
+ else
+ ptr = malloc(size);
+
+ return ptr;
+}
+
+
+extern void
+lzma_free(void *ptr, lzma_allocator *allocator)
+{
+ if (allocator != NULL && allocator->free != NULL)
+ allocator->free(allocator->opaque, ptr);
+ else
+ free(ptr);
+
+ return;
+}
+
+
+//////////
+// Misc //
+//////////
+
+extern size_t
+lzma_bufcpy(const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size)
+{
+ const size_t in_avail = in_size - *in_pos;
+ const size_t out_avail = out_size - *out_pos;
+ const size_t copy_size = my_min(in_avail, out_avail);
+
+ memcpy(out + *out_pos, in + *in_pos, copy_size);
+
+ *in_pos += copy_size;
+ *out_pos += copy_size;
+
+ return copy_size;
+}
+
+
+extern lzma_ret
+lzma_next_filter_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ lzma_next_coder_init(filters[0].init, next, allocator);
+ next->id = filters[0].id;
+ return filters[0].init == NULL
+ ? LZMA_OK : filters[0].init(next, allocator, filters);
+}
+
+
+extern lzma_ret
+lzma_next_filter_update(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *reversed_filters)
+{
+ // Check that the application isn't trying to change the Filter ID.
+ // End of filters is indicated with LZMA_VLI_UNKNOWN in both
+ // reversed_filters[0].id and next->id.
+ if (reversed_filters[0].id != next->id)
+ return LZMA_PROG_ERROR;
+
+ if (reversed_filters[0].id == LZMA_VLI_UNKNOWN)
+ return LZMA_OK;
+
+ assert(next->update != NULL);
+ return next->update(next->coder, allocator, NULL, reversed_filters);
+}
+
+
+extern void
+lzma_next_end(lzma_next_coder *next, lzma_allocator *allocator)
+{
+ if (next->init != (uintptr_t)(NULL)) {
+ // To avoid tiny end functions that simply call
+ // lzma_free(coder, allocator), we allow leaving next->end
+ // NULL and call lzma_free() here.
+ if (next->end != NULL)
+ next->end(next->coder, allocator);
+ else
+ lzma_free(next->coder, allocator);
+
+ // Reset the variables so the we don't accidentally think
+ // that it is an already initialized coder.
+ *next = LZMA_NEXT_CODER_INIT;
+ }
+
+ return;
+}
+
+
+//////////////////////////////////////
+// External to internal API wrapper //
+//////////////////////////////////////
+
+extern lzma_ret
+lzma_strm_init(lzma_stream *strm)
+{
+ if (strm == NULL)
+ return LZMA_PROG_ERROR;
+
+ if (strm->internal == NULL) {
+ strm->internal = lzma_alloc(sizeof(lzma_internal),
+ strm->allocator);
+ if (strm->internal == NULL)
+ return LZMA_MEM_ERROR;
+
+ strm->internal->next = LZMA_NEXT_CODER_INIT;
+ }
+
+ strm->internal->supported_actions[LZMA_RUN] = false;
+ strm->internal->supported_actions[LZMA_SYNC_FLUSH] = false;
+ strm->internal->supported_actions[LZMA_FULL_FLUSH] = false;
+ strm->internal->supported_actions[LZMA_FINISH] = false;
+ strm->internal->sequence = ISEQ_RUN;
+ strm->internal->allow_buf_error = false;
+
+ strm->total_in = 0;
+ strm->total_out = 0;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_code(lzma_stream *strm, lzma_action action)
+{
+ size_t in_pos = 0;
+ size_t out_pos = 0;
+ lzma_ret ret;
+
+ // Sanity checks
+ if ((strm->next_in == NULL && strm->avail_in != 0)
+ || (strm->next_out == NULL && strm->avail_out != 0)
+ || strm->internal == NULL
+ || strm->internal->next.code == NULL
+ || (unsigned int)(action) > LZMA_FINISH
+ || !strm->internal->supported_actions[action])
+ return LZMA_PROG_ERROR;
+
+ // Check if unsupported members have been set to non-zero or non-NULL,
+ // which would indicate that some new feature is wanted.
+ if (strm->reserved_ptr1 != NULL
+ || strm->reserved_ptr2 != NULL
+ || strm->reserved_ptr3 != NULL
+ || strm->reserved_ptr4 != NULL
+ || strm->reserved_int1 != 0
+ || strm->reserved_int2 != 0
+ || strm->reserved_int3 != 0
+ || strm->reserved_int4 != 0
+ || strm->reserved_enum1 != LZMA_RESERVED_ENUM
+ || strm->reserved_enum2 != LZMA_RESERVED_ENUM)
+ return LZMA_OPTIONS_ERROR;
+
+ switch (strm->internal->sequence) {
+ case ISEQ_RUN:
+ switch (action) {
+ case LZMA_RUN:
+ break;
+
+ case LZMA_SYNC_FLUSH:
+ strm->internal->sequence = ISEQ_SYNC_FLUSH;
+ break;
+
+ case LZMA_FULL_FLUSH:
+ strm->internal->sequence = ISEQ_FULL_FLUSH;
+ break;
+
+ case LZMA_FINISH:
+ strm->internal->sequence = ISEQ_FINISH;
+ break;
+ }
+
+ break;
+
+ case ISEQ_SYNC_FLUSH:
+ // The same action must be used until we return
+ // LZMA_STREAM_END, and the amount of input must not change.
+ if (action != LZMA_SYNC_FLUSH
+ || strm->internal->avail_in != strm->avail_in)
+ return LZMA_PROG_ERROR;
+
+ break;
+
+ case ISEQ_FULL_FLUSH:
+ if (action != LZMA_FULL_FLUSH
+ || strm->internal->avail_in != strm->avail_in)
+ return LZMA_PROG_ERROR;
+
+ break;
+
+ case ISEQ_FINISH:
+ if (action != LZMA_FINISH
+ || strm->internal->avail_in != strm->avail_in)
+ return LZMA_PROG_ERROR;
+
+ break;
+
+ case ISEQ_END:
+ return LZMA_STREAM_END;
+
+ case ISEQ_ERROR:
+ default:
+ return LZMA_PROG_ERROR;
+ }
+
+ ret = strm->internal->next.code(
+ strm->internal->next.coder, strm->allocator,
+ strm->next_in, &in_pos, strm->avail_in,
+ strm->next_out, &out_pos, strm->avail_out, action);
+
+ strm->next_in += in_pos;
+ strm->avail_in -= in_pos;
+ strm->total_in += in_pos;
+
+ strm->next_out += out_pos;
+ strm->avail_out -= out_pos;
+ strm->total_out += out_pos;
+
+ strm->internal->avail_in = strm->avail_in;
+
+ switch (ret) {
+ case LZMA_OK:
+ // Don't return LZMA_BUF_ERROR when it happens the first time.
+ // This is to avoid returning LZMA_BUF_ERROR when avail_out
+ // was zero but still there was no more data left to written
+ // to next_out.
+ if (out_pos == 0 && in_pos == 0) {
+ if (strm->internal->allow_buf_error)
+ ret = LZMA_BUF_ERROR;
+ else
+ strm->internal->allow_buf_error = true;
+ } else {
+ strm->internal->allow_buf_error = false;
+ }
+ break;
+
+ case LZMA_STREAM_END:
+ if (strm->internal->sequence == ISEQ_SYNC_FLUSH
+ || strm->internal->sequence == ISEQ_FULL_FLUSH)
+ strm->internal->sequence = ISEQ_RUN;
+ else
+ strm->internal->sequence = ISEQ_END;
+
+ // Fall through
+
+ case LZMA_NO_CHECK:
+ case LZMA_UNSUPPORTED_CHECK:
+ case LZMA_GET_CHECK:
+ case LZMA_MEMLIMIT_ERROR:
+ // Something else than LZMA_OK, but not a fatal error,
+ // that is, coding may be continued (except if ISEQ_END).
+ strm->internal->allow_buf_error = false;
+ break;
+
+ default:
+ // All the other errors are fatal; coding cannot be continued.
+ assert(ret != LZMA_BUF_ERROR);
+ strm->internal->sequence = ISEQ_ERROR;
+ break;
+ }
+
+ return ret;
+}
+
+
+extern LZMA_API(void)
+lzma_end(lzma_stream *strm)
+{
+ if (strm != NULL && strm->internal != NULL) {
+ lzma_next_end(&strm->internal->next, strm->allocator);
+ lzma_free(strm->internal, strm->allocator);
+ strm->internal = NULL;
+ }
+
+ return;
+}
+
+
+extern LZMA_API(lzma_check)
+lzma_get_check(const lzma_stream *strm)
+{
+ // Return LZMA_CHECK_NONE if we cannot know the check type.
+ // It's a bug in the application if this happens.
+ if (strm->internal->next.get_check == NULL)
+ return LZMA_CHECK_NONE;
+
+ return strm->internal->next.get_check(strm->internal->next.coder);
+}
+
+
+extern LZMA_API(uint64_t)
+lzma_memusage(const lzma_stream *strm)
+{
+ uint64_t memusage;
+ uint64_t old_memlimit;
+
+ if (strm == NULL || strm->internal == NULL
+ || strm->internal->next.memconfig == NULL
+ || strm->internal->next.memconfig(
+ strm->internal->next.coder,
+ &memusage, &old_memlimit, 0) != LZMA_OK)
+ return 0;
+
+ return memusage;
+}
+
+
+extern LZMA_API(uint64_t)
+lzma_memlimit_get(const lzma_stream *strm)
+{
+ uint64_t old_memlimit;
+ uint64_t memusage;
+
+ if (strm == NULL || strm->internal == NULL
+ || strm->internal->next.memconfig == NULL
+ || strm->internal->next.memconfig(
+ strm->internal->next.coder,
+ &memusage, &old_memlimit, 0) != LZMA_OK)
+ return 0;
+
+ return old_memlimit;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_memlimit_set(lzma_stream *strm, uint64_t new_memlimit)
+{
+ // Dummy variables to simplify memconfig functions
+ uint64_t old_memlimit;
+ uint64_t memusage;
+
+ if (strm == NULL || strm->internal == NULL
+ || strm->internal->next.memconfig == NULL)
+ return LZMA_PROG_ERROR;
+
+ if (new_memlimit != 0 && new_memlimit < LZMA_MEMUSAGE_BASE)
+ return LZMA_MEMLIMIT_ERROR;
+
+ return strm->internal->next.memconfig(strm->internal->next.coder,
+ &memusage, &old_memlimit, new_memlimit);
+}
diff --git a/Utilities/cmliblzma/liblzma/common/common.h b/Utilities/cmliblzma/liblzma/common/common.h
new file mode 100644
index 0000000000..a6a28189e1
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/common.h
@@ -0,0 +1,305 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file common.h
+/// \brief Definitions common to the whole liblzma library
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_COMMON_H
+#define LZMA_COMMON_H
+
+#include "sysdefs.h"
+#include "tuklib_integer.h"
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+# ifdef DLL_EXPORT
+# define LZMA_API_EXPORT __declspec(dllexport)
+# else
+# define LZMA_API_EXPORT
+# endif
+// Don't use ifdef or defined() below.
+#elif HAVE_VISIBILITY
+# define LZMA_API_EXPORT __attribute__((__visibility__("default")))
+#else
+# define LZMA_API_EXPORT
+#endif
+
+#define LZMA_API(type) LZMA_API_EXPORT type LZMA_API_CALL
+
+#include "lzma.h"
+
+// These allow helping the compiler in some often-executed branches, whose
+// result is almost always the same.
+#ifdef __GNUC__
+# define likely(expr) __builtin_expect(expr, true)
+# define unlikely(expr) __builtin_expect(expr, false)
+#else
+# define likely(expr) (expr)
+# define unlikely(expr) (expr)
+#endif
+
+
+/// Size of temporary buffers needed in some filters
+#define LZMA_BUFFER_SIZE 4096
+
+
+/// Starting value for memory usage estimates. Instead of calculating size
+/// of _every_ structure and taking into account malloc() overhead etc., we
+/// add a base size to all memory usage estimates. It's not very accurate
+/// but should be easily good enough.
+#define LZMA_MEMUSAGE_BASE (UINT64_C(1) << 15)
+
+/// Start of internal Filter ID space. These IDs must never be used
+/// in Streams.
+#define LZMA_FILTER_RESERVED_START (LZMA_VLI_C(1) << 62)
+
+
+/// Supported flags that can be passed to lzma_stream_decoder()
+/// or lzma_auto_decoder().
+#define LZMA_SUPPORTED_FLAGS \
+ ( LZMA_TELL_NO_CHECK \
+ | LZMA_TELL_UNSUPPORTED_CHECK \
+ | LZMA_TELL_ANY_CHECK \
+ | LZMA_CONCATENATED )
+
+
+/// Type of encoder/decoder specific data; the actual structure is defined
+/// differently in different coders.
+typedef struct lzma_coder_s lzma_coder;
+
+typedef struct lzma_next_coder_s lzma_next_coder;
+
+typedef struct lzma_filter_info_s lzma_filter_info;
+
+
+/// Type of a function used to initialize a filter encoder or decoder
+typedef lzma_ret (*lzma_init_function)(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters);
+
+/// Type of a function to do some kind of coding work (filters, Stream,
+/// Block encoders/decoders etc.). Some special coders use don't use both
+/// input and output buffers, but for simplicity they still use this same
+/// function prototype.
+typedef lzma_ret (*lzma_code_function)(
+ lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size,
+ lzma_action action);
+
+/// Type of a function to free the memory allocated for the coder
+typedef void (*lzma_end_function)(
+ lzma_coder *coder, lzma_allocator *allocator);
+
+
+/// Raw coder validates and converts an array of lzma_filter structures to
+/// an array of lzma_filter_info structures. This array is used with
+/// lzma_next_filter_init to initialize the filter chain.
+struct lzma_filter_info_s {
+ /// Filter ID. This is used only by the encoder
+ /// with lzma_filters_update().
+ lzma_vli id;
+
+ /// Pointer to function used to initialize the filter.
+ /// This is NULL to indicate end of array.
+ lzma_init_function init;
+
+ /// Pointer to filter's options structure
+ void *options;
+};
+
+
+/// Hold data and function pointers of the next filter in the chain.
+struct lzma_next_coder_s {
+ /// Pointer to coder-specific data
+ lzma_coder *coder;
+
+ /// Filter ID. This is LZMA_VLI_UNKNOWN when this structure doesn't
+ /// point to a filter coder.
+ lzma_vli id;
+
+ /// "Pointer" to init function. This is never called here.
+ /// We need only to detect if we are initializing a coder
+ /// that was allocated earlier. See lzma_next_coder_init and
+ /// lzma_next_strm_init macros in this file.
+ uintptr_t init;
+
+ /// Pointer to function to do the actual coding
+ lzma_code_function code;
+
+ /// Pointer to function to free lzma_next_coder.coder. This can
+ /// be NULL; in that case, lzma_free is called to free
+ /// lzma_next_coder.coder.
+ lzma_end_function end;
+
+ /// Pointer to function to return the type of the integrity check.
+ /// Most coders won't support this.
+ lzma_check (*get_check)(const lzma_coder *coder);
+
+ /// Pointer to function to get and/or change the memory usage limit.
+ /// If new_memlimit == 0, the limit is not changed.
+ lzma_ret (*memconfig)(lzma_coder *coder, uint64_t *memusage,
+ uint64_t *old_memlimit, uint64_t new_memlimit);
+
+ /// Update the filter-specific options or the whole filter chain
+ /// in the encoder.
+ lzma_ret (*update)(lzma_coder *coder, lzma_allocator *allocator,
+ const lzma_filter *filters,
+ const lzma_filter *reversed_filters);
+};
+
+
+/// Constant to initialize lzma_next_coder structure
+static const lzma_next_coder LZMA_NEXT_CODER_INIT =
+ {
+ NULL,
+ LZMA_VLI_UNKNOWN,
+ (uintptr_t)(NULL),
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ };
+
+
+/// Internal data for lzma_strm_init, lzma_code, and lzma_end. A pointer to
+/// this is stored in lzma_stream.
+struct lzma_internal_s {
+ /// The actual coder that should do something useful
+ lzma_next_coder next;
+
+ /// Track the state of the coder. This is used to validate arguments
+ /// so that the actual coders can rely on e.g. that LZMA_SYNC_FLUSH
+ /// is used on every call to lzma_code until next.code has returned
+ /// LZMA_STREAM_END.
+ enum {
+ ISEQ_RUN,
+ ISEQ_SYNC_FLUSH,
+ ISEQ_FULL_FLUSH,
+ ISEQ_FINISH,
+ ISEQ_END,
+ ISEQ_ERROR,
+ } sequence;
+
+ /// A copy of lzma_stream avail_in. This is used to verify that the
+ /// amount of input doesn't change once e.g. LZMA_FINISH has been
+ /// used.
+ size_t avail_in;
+
+ /// Indicates which lzma_action values are allowed by next.code.
+ bool supported_actions[4];
+
+ /// If true, lzma_code will return LZMA_BUF_ERROR if no progress was
+ /// made (no input consumed and no output produced by next.code).
+ bool allow_buf_error;
+};
+
+
+/// Allocates memory
+extern void *lzma_alloc(size_t size, lzma_allocator *allocator)
+ lzma_attribute((__malloc__)) lzma_attr_alloc_size(1);
+
+/// Frees memory
+extern void lzma_free(void *ptr, lzma_allocator *allocator);
+
+
+/// Allocates strm->internal if it is NULL, and initializes *strm and
+/// strm->internal. This function is only called via lzma_next_strm_init2 macro.
+extern lzma_ret lzma_strm_init(lzma_stream *strm);
+
+/// Initializes the next filter in the chain, if any. This takes care of
+/// freeing the memory of previously initialized filter if it is different
+/// than the filter being initialized now. This way the actual filter
+/// initialization functions don't need to use lzma_next_coder_init macro.
+extern lzma_ret lzma_next_filter_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+/// Update the next filter in the chain, if any. This checks that
+/// the application is not trying to change the Filter IDs.
+extern lzma_ret lzma_next_filter_update(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *reversed_filters);
+
+/// Frees the memory allocated for next->coder either using next->end or,
+/// if next->end is NULL, using lzma_free.
+extern void lzma_next_end(lzma_next_coder *next, lzma_allocator *allocator);
+
+
+/// Copy as much data as possible from in[] to out[] and update *in_pos
+/// and *out_pos accordingly. Returns the number of bytes copied.
+extern size_t lzma_bufcpy(const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size);
+
+
+/// \brief Return if expression doesn't evaluate to LZMA_OK
+///
+/// There are several situations where we want to return immediately
+/// with the value of expr if it isn't LZMA_OK. This macro shortens
+/// the code a little.
+#define return_if_error(expr) \
+do { \
+ const lzma_ret ret_ = (expr); \
+ if (ret_ != LZMA_OK) \
+ return ret_; \
+} while (0)
+
+
+/// If next isn't already initialized, free the previous coder. Then mark
+/// that next is _possibly_ initialized for the coder using this macro.
+/// "Possibly" means that if e.g. allocation of next->coder fails, the
+/// structure isn't actually initialized for this coder, but leaving
+/// next->init to func is still OK.
+#define lzma_next_coder_init(func, next, allocator) \
+do { \
+ if ((uintptr_t)(func) != (next)->init) \
+ lzma_next_end(next, allocator); \
+ (next)->init = (uintptr_t)(func); \
+} while (0)
+
+
+/// Initializes lzma_strm and calls func() to initialize strm->internal->next.
+/// (The function being called will use lzma_next_coder_init()). If
+/// initialization fails, memory that wasn't freed by func() is freed
+/// along strm->internal.
+#define lzma_next_strm_init1(func, strm, arg1) \
+do { \
+ lzma_ret ret_; \
+ return_if_error(lzma_strm_init(strm)); \
+ ret_ = func(&(strm)->internal->next, (strm)->allocator, arg1); \
+ if (ret_ != LZMA_OK) { \
+ lzma_end(strm); \
+ return ret_; \
+ } \
+} while (0)
+
+#define lzma_next_strm_init2(func, strm, arg1, arg2) \
+do { \
+ lzma_ret ret_; \
+ return_if_error(lzma_strm_init(strm)); \
+ ret_ = func(&(strm)->internal->next, (strm)->allocator, arg1, arg2); \
+ if (ret_ != LZMA_OK) { \
+ lzma_end(strm); \
+ return ret_; \
+ } \
+} while (0)
+
+#define lzma_next_strm_init3(func, strm, arg1, arg2, arg3) \
+do { \
+ lzma_ret ret_; \
+ return_if_error(lzma_strm_init(strm)); \
+ ret_ = func(&(strm)->internal->next, (strm)->allocator, arg1, arg2, arg3); \
+ if (ret_ != LZMA_OK) { \
+ lzma_end(strm); \
+ return ret_; \
+ } \
+} while (0)
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/easy_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/easy_buffer_encoder.c
new file mode 100644
index 0000000000..c4be34ccfa
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/easy_buffer_encoder.c
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file easy_buffer_encoder.c
+/// \brief Easy single-call .xz Stream encoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "easy_preset.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_easy_buffer_encode(uint32_t preset, lzma_check check,
+ lzma_allocator *allocator, const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ lzma_options_easy opt_easy;
+ if (lzma_easy_preset(&opt_easy, preset))
+ return LZMA_OPTIONS_ERROR;
+
+ return lzma_stream_buffer_encode(opt_easy.filters, check,
+ allocator, in, in_size, out, out_pos, out_size);
+}
diff --git a/Utilities/cmliblzma/liblzma/common/easy_decoder_memusage.c b/Utilities/cmliblzma/liblzma/common/easy_decoder_memusage.c
new file mode 100644
index 0000000000..20bcd5b717
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/easy_decoder_memusage.c
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file easy_decoder_memusage.c
+/// \brief Decoder memory usage calculation to match easy encoder presets
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "easy_preset.h"
+
+
+extern LZMA_API(uint64_t)
+lzma_easy_decoder_memusage(uint32_t preset)
+{
+ lzma_options_easy opt_easy;
+ if (lzma_easy_preset(&opt_easy, preset))
+ return UINT32_MAX;
+
+ return lzma_raw_decoder_memusage(opt_easy.filters);
+}
diff --git a/Utilities/cmliblzma/liblzma/common/easy_encoder.c b/Utilities/cmliblzma/liblzma/common/easy_encoder.c
new file mode 100644
index 0000000000..d13ccd7351
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/easy_encoder.c
@@ -0,0 +1,25 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file easy_encoder.c
+/// \brief Easy .xz Stream encoder initialization
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "easy_preset.h"
+#include "stream_encoder.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_easy_encoder(lzma_stream *strm, uint32_t preset, lzma_check check)
+{
+ lzma_options_easy opt_easy;
+ if (lzma_easy_preset(&opt_easy, preset))
+ return LZMA_OPTIONS_ERROR;
+
+ return lzma_stream_encoder(strm, opt_easy.filters, check);
+}
diff --git a/Utilities/cmliblzma/liblzma/common/easy_encoder_memusage.c b/Utilities/cmliblzma/liblzma/common/easy_encoder_memusage.c
new file mode 100644
index 0000000000..e910575842
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/easy_encoder_memusage.c
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file easy_encoder_memusage.c
+/// \brief Easy .xz Stream encoder memory usage calculation
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "easy_preset.h"
+
+
+extern LZMA_API(uint64_t)
+lzma_easy_encoder_memusage(uint32_t preset)
+{
+ lzma_options_easy opt_easy;
+ if (lzma_easy_preset(&opt_easy, preset))
+ return UINT32_MAX;
+
+ return lzma_raw_encoder_memusage(opt_easy.filters);
+}
diff --git a/Utilities/cmliblzma/liblzma/common/easy_preset.c b/Utilities/cmliblzma/liblzma/common/easy_preset.c
new file mode 100644
index 0000000000..2f9859860a
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/easy_preset.c
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file easy_preset.c
+/// \brief Preset handling for easy encoder and decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "easy_preset.h"
+
+
+extern bool
+lzma_easy_preset(lzma_options_easy *opt_easy, uint32_t preset)
+{
+ if (lzma_lzma_preset(&opt_easy->opt_lzma, preset))
+ return true;
+
+ opt_easy->filters[0].id = LZMA_FILTER_LZMA2;
+ opt_easy->filters[0].options = &opt_easy->opt_lzma;
+ opt_easy->filters[1].id = LZMA_VLI_UNKNOWN;
+
+ return false;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/easy_preset.h b/Utilities/cmliblzma/liblzma/common/easy_preset.h
new file mode 100644
index 0000000000..382ade8940
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/easy_preset.h
@@ -0,0 +1,32 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file easy_preset.h
+/// \brief Preset handling for easy encoder and decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+
+
+typedef struct {
+ /// We need to keep the filters array available in case
+ /// LZMA_FULL_FLUSH is used.
+ lzma_filter filters[LZMA_FILTERS_MAX + 1];
+
+ /// Options for LZMA2
+ lzma_options_lzma opt_lzma;
+
+ // Options for more filters can be added later, so this struct
+ // is not ready to be put into the public API.
+
+} lzma_options_easy;
+
+
+/// Set *easy to the settings given by the preset. Returns true on error,
+/// false on success.
+extern bool lzma_easy_preset(lzma_options_easy *easy, uint32_t preset);
diff --git a/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c b/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c
new file mode 100644
index 0000000000..65665c17df
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c
@@ -0,0 +1,91 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_buffer_decoder.c
+/// \brief Single-call raw decoding
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "filter_decoder.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_raw_buffer_decode(const lzma_filter *filters, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ lzma_next_coder next = LZMA_NEXT_CODER_INIT;
+ size_t in_start;
+ size_t out_start;
+ lzma_ret ret;
+
+ // Validate what isn't validated later in filter_common.c.
+ if (in == NULL || in_pos == NULL || *in_pos > in_size || out == NULL
+ || out_pos == NULL || *out_pos > out_size)
+ return LZMA_PROG_ERROR;
+
+ // Initialize the decoer.
+ return_if_error(lzma_raw_decoder_init(&next, allocator, filters));
+
+ // Store the positions so that we can restore them if something
+ // goes wrong.
+ in_start = *in_pos;
+ out_start = *out_pos;
+
+ // Do the actual decoding and free decoder's memory.
+ ret = next.code(next.coder, allocator, in, in_pos, in_size,
+ out, out_pos, out_size, LZMA_FINISH);
+
+ if (ret == LZMA_STREAM_END) {
+ ret = LZMA_OK;
+ } else {
+ if (ret == LZMA_OK) {
+ // Either the input was truncated or the
+ // output buffer was too small.
+ assert(*in_pos == in_size || *out_pos == out_size);
+
+ if (*in_pos != in_size) {
+ // Since input wasn't consumed completely,
+ // the output buffer became full and is
+ // too small.
+ ret = LZMA_BUF_ERROR;
+
+ } else if (*out_pos != out_size) {
+ // Since output didn't became full, the input
+ // has to be truncated.
+ ret = LZMA_DATA_ERROR;
+
+ } else {
+ // All the input was consumed and output
+ // buffer is full. Now we don't immediately
+ // know the reason for the error. Try
+ // decoding one more byte. If it succeeds,
+ // then the output buffer was too small. If
+ // we cannot get a new output byte, the input
+ // is truncated.
+ uint8_t tmp[1];
+ size_t tmp_pos = 0;
+ (void)next.code(next.coder, allocator,
+ in, in_pos, in_size,
+ tmp, &tmp_pos, 1, LZMA_FINISH);
+
+ if (tmp_pos == 1)
+ ret = LZMA_BUF_ERROR;
+ else
+ ret = LZMA_DATA_ERROR;
+ }
+ }
+
+ // Restore the positions.
+ *in_pos = in_start;
+ *out_pos = out_start;
+ }
+
+ lzma_next_end(&next, allocator);
+
+ return ret;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c
new file mode 100644
index 0000000000..b23329f3e4
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_buffer_encoder.c
+/// \brief Single-call raw encoding
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "filter_encoder.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_raw_buffer_encode(const lzma_filter *filters, lzma_allocator *allocator,
+ const uint8_t *in, size_t in_size, uint8_t *out,
+ size_t *out_pos, size_t out_size)
+{
+ lzma_next_coder next = LZMA_NEXT_CODER_INIT;
+ size_t out_start;
+ size_t in_pos = 0;
+ lzma_ret ret;
+
+ // Validate what isn't validated later in filter_common.c.
+ if ((in == NULL && in_size != 0) || out == NULL
+ || out_pos == NULL || *out_pos > out_size)
+ return LZMA_PROG_ERROR;
+
+ // Initialize the encoder
+ return_if_error(lzma_raw_encoder_init(&next, allocator, filters));
+
+ // Store the output position so that we can restore it if
+ // something goes wrong.
+ out_start = *out_pos;
+
+ // Do the actual encoding and free coder's memory.
+ ret = next.code(next.coder, allocator, in, &in_pos, in_size,
+ out, out_pos, out_size, LZMA_FINISH);
+ lzma_next_end(&next, allocator);
+
+ if (ret == LZMA_STREAM_END) {
+ ret = LZMA_OK;
+ } else {
+ if (ret == LZMA_OK) {
+ // Output buffer was too small.
+ assert(*out_pos == out_size);
+ ret = LZMA_BUF_ERROR;
+ }
+
+ // Restore the output position.
+ *out_pos = out_start;
+ }
+
+ return ret;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/filter_common.c b/Utilities/cmliblzma/liblzma/common/filter_common.c
new file mode 100644
index 0000000000..d2b9e086ed
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_common.c
@@ -0,0 +1,342 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_common.c
+/// \brief Filter-specific stuff common for both encoder and decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "filter_common.h"
+
+
+static const struct {
+ /// Filter ID
+ lzma_vli id;
+
+ /// Size of the filter-specific options structure
+ size_t options_size;
+
+ /// True if it is OK to use this filter as non-last filter in
+ /// the chain.
+ bool non_last_ok;
+
+ /// True if it is OK to use this filter as the last filter in
+ /// the chain.
+ bool last_ok;
+
+ /// True if the filter may change the size of the data (that is, the
+ /// amount of encoded output can be different than the amount of
+ /// uncompressed input).
+ bool changes_size;
+
+} features[] = {
+#if defined (HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1)
+ {
+ LZMA_FILTER_LZMA1,
+ sizeof(lzma_options_lzma),
+ false,
+ true,
+ true,
+ },
+#endif
+#if defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2)
+ {
+ LZMA_FILTER_LZMA2,
+ sizeof(lzma_options_lzma),
+ false,
+ true,
+ true,
+ },
+#endif
+#if defined(HAVE_ENCODER_X86) || defined(HAVE_DECODER_X86)
+ {
+ LZMA_FILTER_X86,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
+ },
+#endif
+#if defined(HAVE_ENCODER_POWERPC) || defined(HAVE_DECODER_POWERPC)
+ {
+ LZMA_FILTER_POWERPC,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
+ },
+#endif
+#if defined(HAVE_ENCODER_IA64) || defined(HAVE_DECODER_IA64)
+ {
+ LZMA_FILTER_IA64,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
+ },
+#endif
+#if defined(HAVE_ENCODER_ARM) || defined(HAVE_DECODER_ARM)
+ {
+ LZMA_FILTER_ARM,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
+ },
+#endif
+#if defined(HAVE_ENCODER_ARMTHUMB) || defined(HAVE_DECODER_ARMTHUMB)
+ {
+ LZMA_FILTER_ARMTHUMB,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
+ },
+#endif
+#if defined(HAVE_ENCODER_SPARC) || defined(HAVE_DECODER_SPARC)
+ {
+ LZMA_FILTER_SPARC,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
+ },
+#endif
+#if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
+ {
+ LZMA_FILTER_DELTA,
+ sizeof(lzma_options_delta),
+ true,
+ false,
+ false,
+ },
+#endif
+ {
+ LZMA_VLI_UNKNOWN
+ }
+};
+
+
+extern LZMA_API(lzma_ret)
+lzma_filters_copy(const lzma_filter *src, lzma_filter *dest,
+ lzma_allocator *allocator)
+{
+ size_t i;
+ lzma_ret ret;
+
+ if (src == NULL || dest == NULL)
+ return LZMA_PROG_ERROR;
+
+ for (i = 0; src[i].id != LZMA_VLI_UNKNOWN; ++i) {
+ // There must be a maximum of four filters plus
+ // the array terminator.
+ if (i == LZMA_FILTERS_MAX) {
+ ret = LZMA_OPTIONS_ERROR;
+ goto error;
+ }
+
+ dest[i].id = src[i].id;
+
+ if (src[i].options == NULL) {
+ dest[i].options = NULL;
+ } else {
+ // See if the filter is supported only when the
+ // options is not NULL. This might be convenient
+ // sometimes if the app is actually copying only
+ // a partial filter chain with a place holder ID.
+ //
+ // When options is not NULL, the Filter ID must be
+ // supported by us, because otherwise we don't know
+ // how big the options are.
+ size_t j;
+ for (j = 0; src[i].id != features[j].id; ++j) {
+ if (features[j].id == LZMA_VLI_UNKNOWN) {
+ ret = LZMA_OPTIONS_ERROR;
+ goto error;
+ }
+ }
+
+ // Allocate and copy the options.
+ dest[i].options = lzma_alloc(features[j].options_size,
+ allocator);
+ if (dest[i].options == NULL) {
+ ret = LZMA_MEM_ERROR;
+ goto error;
+ }
+
+ memcpy(dest[i].options, src[i].options,
+ features[j].options_size);
+ }
+ }
+
+ // Terminate the filter array.
+ assert(i <= LZMA_FILTERS_MAX + 1);
+ dest[i].id = LZMA_VLI_UNKNOWN;
+ dest[i].options = NULL;
+
+ return LZMA_OK;
+
+error:
+ // Free the options which we have already allocated.
+ while (i-- > 0) {
+ lzma_free(dest[i].options, allocator);
+ dest[i].options = NULL;
+ }
+
+ return ret;
+}
+
+
+static lzma_ret
+validate_chain(const lzma_filter *filters, size_t *count)
+{
+ // Number of non-last filters that may change the size of the data
+ // significantly (that is, more than 1-2 % or so).
+ size_t changes_size_count = 0;
+
+ // True if it is OK to add a new filter after the current filter.
+ bool non_last_ok = true;
+
+ // True if the last filter in the given chain is actually usable as
+ // the last filter. Only filters that support embedding End of Payload
+ // Marker can be used as the last filter in the chain.
+ bool last_ok = false;
+
+ size_t i = 0;
+
+ // There must be at least one filter.
+ if (filters == NULL || filters[0].id == LZMA_VLI_UNKNOWN)
+ return LZMA_PROG_ERROR;
+
+ do {
+ size_t j;
+ for (j = 0; filters[i].id != features[j].id; ++j)
+ if (features[j].id == LZMA_VLI_UNKNOWN)
+ return LZMA_OPTIONS_ERROR;
+
+ // If the previous filter in the chain cannot be a non-last
+ // filter, the chain is invalid.
+ if (!non_last_ok)
+ return LZMA_OPTIONS_ERROR;
+
+ non_last_ok = features[j].non_last_ok;
+ last_ok = features[j].last_ok;
+ changes_size_count += features[j].changes_size;
+
+ } while (filters[++i].id != LZMA_VLI_UNKNOWN);
+
+ // There must be 1-4 filters. The last filter must be usable as
+ // the last filter in the chain. A maximum of three filters are
+ // allowed to change the size of the data.
+ if (i > LZMA_FILTERS_MAX || !last_ok || changes_size_count > 3)
+ return LZMA_OPTIONS_ERROR;
+
+ *count = i;
+ return LZMA_OK;
+}
+
+
+extern lzma_ret
+lzma_raw_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *options,
+ lzma_filter_find coder_find, bool is_encoder)
+{
+ lzma_filter_info filters[LZMA_FILTERS_MAX + 1];
+ size_t count;
+ size_t i;
+ lzma_ret ret;
+
+ // Do some basic validation and get the number of filters.
+ return_if_error(validate_chain(options, &count));
+
+ // Set the filter functions and copy the options pointer.
+ if (is_encoder) {
+ for (i = 0; i < count; ++i) {
+ // The order of the filters is reversed in the
+ // encoder. It allows more efficient handling
+ // of the uncompressed data.
+ const size_t j = count - i - 1;
+
+ const lzma_filter_coder *const fc
+ = coder_find(options[i].id);
+ if (fc == NULL || fc->init == NULL)
+ return LZMA_OPTIONS_ERROR;
+
+ filters[j].id = options[i].id;
+ filters[j].init = fc->init;
+ filters[j].options = options[i].options;
+ }
+ } else {
+ for (i = 0; i < count; ++i) {
+ const lzma_filter_coder *const fc
+ = coder_find(options[i].id);
+ if (fc == NULL || fc->init == NULL)
+ return LZMA_OPTIONS_ERROR;
+
+ filters[i].id = options[i].id;
+ filters[i].init = fc->init;
+ filters[i].options = options[i].options;
+ }
+ }
+
+ // Terminate the array.
+ filters[count].id = LZMA_VLI_UNKNOWN;
+ filters[count].init = NULL;
+
+ // Initialize the filters.
+ ret = lzma_next_filter_init(next, allocator, filters);
+ if (ret != LZMA_OK)
+ lzma_next_end(next, allocator);
+
+ return ret;
+}
+
+
+extern uint64_t
+lzma_raw_coder_memusage(lzma_filter_find coder_find,
+ const lzma_filter *filters)
+{
+ uint64_t total = 0;
+ size_t i = 0;
+
+ // The chain has to have at least one filter.
+ {
+ size_t tmp;
+ if (validate_chain(filters, &tmp) != LZMA_OK)
+ return UINT64_MAX;
+ }
+
+ do {
+ const lzma_filter_coder *const fc
+ = coder_find(filters[i].id);
+ if (fc == NULL)
+ return UINT64_MAX; // Unsupported Filter ID
+
+ if (fc->memusage == NULL) {
+ // This filter doesn't have a function to calculate
+ // the memory usage and validate the options. Such
+ // filters need only little memory, so we use 1 KiB
+ // as a good estimate. They also accept all possible
+ // options, so there's no need to worry about lack
+ // of validation.
+ total += 1024;
+ } else {
+ // Call the filter-specific memory usage calculation
+ // function.
+ const uint64_t usage
+ = fc->memusage(filters[i].options);
+ if (usage == UINT64_MAX)
+ return UINT64_MAX; // Invalid options
+
+ total += usage;
+ }
+ } while (filters[++i].id != LZMA_VLI_UNKNOWN);
+
+ // Add some fixed amount of extra. It's to compensate memory usage
+ // of Stream, Block etc. coders, malloc() overhead, stack etc.
+ return total + LZMA_MEMUSAGE_BASE;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/filter_common.h b/Utilities/cmliblzma/liblzma/common/filter_common.h
new file mode 100644
index 0000000000..cd61fc0724
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_common.h
@@ -0,0 +1,48 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_common.c
+/// \brief Filter-specific stuff common for both encoder and decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_FILTER_COMMON_H
+#define LZMA_FILTER_COMMON_H
+
+#include "common.h"
+
+
+/// Both lzma_filter_encoder and lzma_filter_decoder begin with these members.
+typedef struct {
+ /// Filter ID
+ lzma_vli id;
+
+ /// Initializes the filter encoder and calls lzma_next_filter_init()
+ /// for filters + 1.
+ lzma_init_function init;
+
+ /// Calculates memory usage of the encoder. If the options are
+ /// invalid, UINT64_MAX is returned.
+ uint64_t (*memusage)(const void *options);
+
+} lzma_filter_coder;
+
+
+typedef const lzma_filter_coder *(*lzma_filter_find)(lzma_vli id);
+
+
+extern lzma_ret lzma_raw_coder_init(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *filters,
+ lzma_filter_find coder_find, bool is_encoder);
+
+
+extern uint64_t lzma_raw_coder_memusage(lzma_filter_find coder_find,
+ const lzma_filter *filters);
+
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/filter_decoder.c b/Utilities/cmliblzma/liblzma/common/filter_decoder.c
new file mode 100644
index 0000000000..cce2b30ea8
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_decoder.c
@@ -0,0 +1,185 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_decoder.c
+/// \brief Filter ID mapping to filter-specific functions
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "filter_decoder.h"
+#include "filter_common.h"
+#include "lzma_decoder.h"
+#include "lzma2_decoder.h"
+#include "simple_decoder.h"
+#include "delta_decoder.h"
+
+
+typedef struct {
+ /// Filter ID
+ lzma_vli id;
+
+ /// Initializes the filter encoder and calls lzma_next_filter_init()
+ /// for filters + 1.
+ lzma_init_function init;
+
+ /// Calculates memory usage of the encoder. If the options are
+ /// invalid, UINT64_MAX is returned.
+ uint64_t (*memusage)(const void *options);
+
+ /// Decodes Filter Properties.
+ ///
+ /// \return - LZMA_OK: Properties decoded successfully.
+ /// - LZMA_OPTIONS_ERROR: Unsupported properties
+ /// - LZMA_MEM_ERROR: Memory allocation failed.
+ lzma_ret (*props_decode)(void **options, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size);
+
+} lzma_filter_decoder;
+
+
+static const lzma_filter_decoder decoders[] = {
+#ifdef HAVE_DECODER_LZMA1
+ {
+ LZMA_FILTER_LZMA1,
+ &lzma_lzma_decoder_init,
+ &lzma_lzma_decoder_memusage,
+ &lzma_lzma_props_decode,
+ },
+#endif
+#ifdef HAVE_DECODER_LZMA2
+ {
+ LZMA_FILTER_LZMA2,
+ &lzma_lzma2_decoder_init,
+ &lzma_lzma2_decoder_memusage,
+ &lzma_lzma2_props_decode,
+ },
+#endif
+#ifdef HAVE_DECODER_X86
+ {
+ LZMA_FILTER_X86,
+ &lzma_simple_x86_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
+ },
+#endif
+#ifdef HAVE_DECODER_POWERPC
+ {
+ LZMA_FILTER_POWERPC,
+ &lzma_simple_powerpc_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
+ },
+#endif
+#ifdef HAVE_DECODER_IA64
+ {
+ LZMA_FILTER_IA64,
+ &lzma_simple_ia64_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
+ },
+#endif
+#ifdef HAVE_DECODER_ARM
+ {
+ LZMA_FILTER_ARM,
+ &lzma_simple_arm_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
+ },
+#endif
+#ifdef HAVE_DECODER_ARMTHUMB
+ {
+ LZMA_FILTER_ARMTHUMB,
+ &lzma_simple_armthumb_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
+ },
+#endif
+#ifdef HAVE_DECODER_SPARC
+ {
+ LZMA_FILTER_SPARC,
+ &lzma_simple_sparc_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
+ },
+#endif
+#ifdef HAVE_DECODER_DELTA
+ {
+ LZMA_FILTER_DELTA,
+ &lzma_delta_decoder_init,
+ &lzma_delta_coder_memusage,
+ &lzma_delta_props_decode,
+ },
+#endif
+};
+
+
+static const lzma_filter_decoder *
+decoder_find(lzma_vli id)
+{
+ size_t i;
+ for (i = 0; i < ARRAY_SIZE(decoders); ++i)
+ if (decoders[i].id == id)
+ return decoders + i;
+
+ return NULL;
+}
+
+
+extern LZMA_API(lzma_bool)
+lzma_filter_decoder_is_supported(lzma_vli id)
+{
+ return decoder_find(id) != NULL;
+}
+
+
+extern lzma_ret
+lzma_raw_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *options)
+{
+ return lzma_raw_coder_init(next, allocator,
+ options, (lzma_filter_find)(&decoder_find), false);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_raw_decoder(lzma_stream *strm, const lzma_filter *options)
+{
+ lzma_next_strm_init1(lzma_raw_decoder_init, strm, options);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(uint64_t)
+lzma_raw_decoder_memusage(const lzma_filter *filters)
+{
+ return lzma_raw_coder_memusage(
+ (lzma_filter_find)(&decoder_find), filters);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_properties_decode(lzma_filter *filter, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size)
+{
+ const lzma_filter_decoder *const fd = decoder_find(filter->id);
+
+ // Make it always NULL so that the caller can always safely free() it.
+ filter->options = NULL;
+
+ if (fd == NULL)
+ return LZMA_OPTIONS_ERROR;
+
+ if (fd->props_decode == NULL)
+ return props_size == 0 ? LZMA_OK : LZMA_OPTIONS_ERROR;
+
+ return fd->props_decode(
+ &filter->options, allocator, props, props_size);
+}
diff --git a/Utilities/cmliblzma/liblzma/common/filter_decoder.h b/Utilities/cmliblzma/liblzma/common/filter_decoder.h
new file mode 100644
index 0000000000..d5c68bdd4a
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_decoder.h
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_decoder.c
+/// \brief Filter ID mapping to filter-specific functions
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_FILTER_DECODER_H
+#define LZMA_FILTER_DECODER_H
+
+#include "common.h"
+
+
+extern lzma_ret lzma_raw_decoder_init(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *options);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/filter_encoder.c b/Utilities/cmliblzma/liblzma/common/filter_encoder.c
new file mode 100644
index 0000000000..9fdb100086
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_encoder.c
@@ -0,0 +1,297 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_decoder.c
+/// \brief Filter ID mapping to filter-specific functions
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "filter_encoder.h"
+#include "filter_common.h"
+#include "lzma_encoder.h"
+#include "lzma2_encoder.h"
+#include "simple_encoder.h"
+#include "delta_encoder.h"
+
+
+typedef struct {
+ /// Filter ID
+ lzma_vli id;
+
+ /// Initializes the filter encoder and calls lzma_next_filter_init()
+ /// for filters + 1.
+ lzma_init_function init;
+
+ /// Calculates memory usage of the encoder. If the options are
+ /// invalid, UINT64_MAX is returned.
+ uint64_t (*memusage)(const void *options);
+
+ /// Calculates the minimum sane size for Blocks (or other types of
+ /// chunks) to which the input data can be split to make
+ /// multithreaded encoding possible. If this is NULL, it is assumed
+ /// that the encoder is fast enough with single thread.
+ lzma_vli (*chunk_size)(const void *options);
+
+ /// Tells the size of the Filter Properties field. If options are
+ /// invalid, UINT32_MAX is returned. If this is NULL, props_size_fixed
+ /// is used.
+ lzma_ret (*props_size_get)(uint32_t *size, const void *options);
+ uint32_t props_size_fixed;
+
+ /// Encodes Filter Properties.
+ ///
+ /// \return - LZMA_OK: Properties encoded successfully.
+ /// - LZMA_OPTIONS_ERROR: Unsupported options
+ /// - LZMA_PROG_ERROR: Invalid options or not enough
+ /// output space
+ lzma_ret (*props_encode)(const void *options, uint8_t *out);
+
+} lzma_filter_encoder;
+
+
+static const lzma_filter_encoder encoders[] = {
+#ifdef HAVE_ENCODER_LZMA1
+ {
+ LZMA_FILTER_LZMA1,
+ &lzma_lzma_encoder_init,
+ &lzma_lzma_encoder_memusage,
+ NULL, // FIXME
+ NULL,
+ 5,
+ &lzma_lzma_props_encode,
+ },
+#endif
+#ifdef HAVE_ENCODER_LZMA2
+ {
+ LZMA_FILTER_LZMA2,
+ &lzma_lzma2_encoder_init,
+ &lzma_lzma2_encoder_memusage,
+ NULL, // FIXME
+ NULL,
+ 1,
+ &lzma_lzma2_props_encode,
+ },
+#endif
+#ifdef HAVE_ENCODER_X86
+ {
+ LZMA_FILTER_X86,
+ &lzma_simple_x86_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
+ },
+#endif
+#ifdef HAVE_ENCODER_POWERPC
+ {
+ LZMA_FILTER_POWERPC,
+ &lzma_simple_powerpc_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
+ },
+#endif
+#ifdef HAVE_ENCODER_IA64
+ {
+ LZMA_FILTER_IA64,
+ &lzma_simple_ia64_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
+ },
+#endif
+#ifdef HAVE_ENCODER_ARM
+ {
+ LZMA_FILTER_ARM,
+ &lzma_simple_arm_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
+ },
+#endif
+#ifdef HAVE_ENCODER_ARMTHUMB
+ {
+ LZMA_FILTER_ARMTHUMB,
+ &lzma_simple_armthumb_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
+ },
+#endif
+#ifdef HAVE_ENCODER_SPARC
+ {
+ LZMA_FILTER_SPARC,
+ &lzma_simple_sparc_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
+ },
+#endif
+#ifdef HAVE_ENCODER_DELTA
+ {
+ LZMA_FILTER_DELTA,
+ &lzma_delta_encoder_init,
+ &lzma_delta_coder_memusage,
+ NULL,
+ NULL,
+ 1,
+ &lzma_delta_props_encode,
+ },
+#endif
+};
+
+
+static const lzma_filter_encoder *
+encoder_find(lzma_vli id)
+{
+ size_t i;
+ for (i = 0; i < ARRAY_SIZE(encoders); ++i)
+ if (encoders[i].id == id)
+ return encoders + i;
+
+ return NULL;
+}
+
+
+extern LZMA_API(lzma_bool)
+lzma_filter_encoder_is_supported(lzma_vli id)
+{
+ return encoder_find(id) != NULL;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_filters_update(lzma_stream *strm, const lzma_filter *filters)
+{
+ size_t i;
+ size_t count = 1;
+ lzma_filter reversed_filters[LZMA_FILTERS_MAX + 1];
+
+ if (strm->internal->next.update == NULL)
+ return LZMA_PROG_ERROR;
+
+ // Validate the filter chain.
+ if (lzma_raw_encoder_memusage(filters) == UINT64_MAX)
+ return LZMA_OPTIONS_ERROR;
+
+ // The actual filter chain in the encoder is reversed. Some things
+ // still want the normal order chain, so we provide both.
+ while (filters[count].id != LZMA_VLI_UNKNOWN)
+ ++count;
+
+ for (i = 0; i < count; ++i)
+ reversed_filters[count - i - 1] = filters[i];
+
+ reversed_filters[count].id = LZMA_VLI_UNKNOWN;
+
+ return strm->internal->next.update(strm->internal->next.coder,
+ strm->allocator, filters, reversed_filters);
+}
+
+
+extern lzma_ret
+lzma_raw_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *options)
+{
+ return lzma_raw_coder_init(next, allocator,
+ options, (lzma_filter_find)(&encoder_find), true);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_raw_encoder(lzma_stream *strm, const lzma_filter *options)
+{
+ lzma_next_strm_init3(lzma_raw_coder_init, strm, options,
+ (lzma_filter_find)(&encoder_find), true);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(uint64_t)
+lzma_raw_encoder_memusage(const lzma_filter *filters)
+{
+ return lzma_raw_coder_memusage(
+ (lzma_filter_find)(&encoder_find), filters);
+}
+
+
+/*
+extern LZMA_API(lzma_vli)
+lzma_chunk_size(const lzma_filter *filters)
+{
+ lzma_vli max = 0;
+
+ for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
+ const lzma_filter_encoder *const fe
+ = encoder_find(filters[i].id);
+ if (fe->chunk_size != NULL) {
+ const lzma_vli size
+ = fe->chunk_size(filters[i].options);
+ if (size == LZMA_VLI_UNKNOWN)
+ return LZMA_VLI_UNKNOWN;
+
+ if (size > max)
+ max = size;
+ }
+ }
+
+ return max;
+}
+*/
+
+
+extern LZMA_API(lzma_ret)
+lzma_properties_size(uint32_t *size, const lzma_filter *filter)
+{
+ const lzma_filter_encoder *const fe = encoder_find(filter->id);
+ if (fe == NULL) {
+ // Unknown filter - if the Filter ID is a proper VLI,
+ // return LZMA_OPTIONS_ERROR instead of LZMA_PROG_ERROR,
+ // because it's possible that we just don't have support
+ // compiled in for the requested filter.
+ return filter->id <= LZMA_VLI_MAX
+ ? LZMA_OPTIONS_ERROR : LZMA_PROG_ERROR;
+ }
+
+ if (fe->props_size_get == NULL) {
+ // No props_size_get() function, use props_size_fixed.
+ *size = fe->props_size_fixed;
+ return LZMA_OK;
+ }
+
+ return fe->props_size_get(size, filter->options);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_properties_encode(const lzma_filter *filter, uint8_t *props)
+{
+ const lzma_filter_encoder *const fe = encoder_find(filter->id);
+ if (fe == NULL)
+ return LZMA_PROG_ERROR;
+
+ if (fe->props_encode == NULL)
+ return LZMA_OK;
+
+ return fe->props_encode(filter->options, props);
+}
diff --git a/Utilities/cmliblzma/liblzma/common/filter_encoder.h b/Utilities/cmliblzma/liblzma/common/filter_encoder.h
new file mode 100644
index 0000000000..5bc137f645
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_encoder.h
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_encoder.c
+/// \brief Filter ID mapping to filter-specific functions
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_FILTER_ENCODER_H
+#define LZMA_FILTER_ENCODER_H
+
+#include "common.h"
+
+
+// FIXME: Might become a part of the public API once finished.
+// extern lzma_vli lzma_chunk_size(const lzma_filter *filters);
+
+
+extern lzma_ret lzma_raw_encoder_init(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *filters);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c b/Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c
new file mode 100644
index 0000000000..aa2dbd560a
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c
@@ -0,0 +1,48 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_flags_decoder.c
+/// \brief Decodes a Filter Flags field
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "filter_decoder.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_filter_flags_decode(
+ lzma_filter *filter, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size)
+{
+ lzma_vli props_size;
+ lzma_ret ret;
+
+ // Set the pointer to NULL so the caller can always safely free it.
+ filter->options = NULL;
+
+ // Filter ID
+ return_if_error(lzma_vli_decode(&filter->id, NULL,
+ in, in_pos, in_size));
+
+ if (filter->id >= LZMA_FILTER_RESERVED_START)
+ return LZMA_DATA_ERROR;
+
+ // Size of Properties
+ return_if_error(lzma_vli_decode(&props_size, NULL,
+ in, in_pos, in_size));
+
+ // Filter Properties
+ if (in_size - *in_pos < props_size)
+ return LZMA_DATA_ERROR;
+
+ ret = lzma_properties_decode(
+ filter, allocator, in + *in_pos, props_size);
+
+ *in_pos += props_size;
+
+ return ret;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c b/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c
new file mode 100644
index 0000000000..755c407f61
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file filter_flags_encoder.c
+/// \brief Decodes a Filter Flags field
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "filter_encoder.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_filter_flags_size(uint32_t *size, const lzma_filter *filter)
+{
+ if (filter->id >= LZMA_FILTER_RESERVED_START)
+ return LZMA_PROG_ERROR;
+
+ return_if_error(lzma_properties_size(size, filter));
+
+ *size += lzma_vli_size(filter->id) + lzma_vli_size(*size);
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_filter_flags_encode(const lzma_filter *filter,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ uint32_t props_size;
+
+ // Filter ID
+ if (filter->id >= LZMA_FILTER_RESERVED_START)
+ return LZMA_PROG_ERROR;
+
+ return_if_error(lzma_vli_encode(filter->id, NULL,
+ out, out_pos, out_size));
+
+ // Size of Properties
+ return_if_error(lzma_properties_size(&props_size, filter));
+ return_if_error(lzma_vli_encode(props_size, NULL,
+ out, out_pos, out_size));
+
+ // Filter Properties
+ if (out_size - *out_pos < props_size)
+ return LZMA_PROG_ERROR;
+
+ return_if_error(lzma_properties_encode(filter, out + *out_pos));
+
+ *out_pos += props_size;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/hardware_physmem.c b/Utilities/cmliblzma/liblzma/common/hardware_physmem.c
new file mode 100644
index 0000000000..7405b658af
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/hardware_physmem.c
@@ -0,0 +1,25 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file hardware_physmem.c
+/// \brief Get the total amount of physical memory (RAM)
+//
+// Author: Jonathan Nieder
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+
+#include "tuklib_physmem.h"
+
+
+extern LZMA_API(uint64_t)
+lzma_physmem(void)
+{
+ // It is simpler to make lzma_physmem() a wrapper for
+ // tuklib_physmem() than to hack appropriate symbol visiblity
+ // support for the tuklib modules.
+ return tuklib_physmem();
+}
diff --git a/Utilities/cmliblzma/liblzma/common/index.c b/Utilities/cmliblzma/liblzma/common/index.c
new file mode 100644
index 0000000000..26135d22c6
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/index.c
@@ -0,0 +1,1276 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file index.c
+/// \brief Handling of .xz Indexes and some other Stream information
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "index.h"
+#include "stream_flags_common.h"
+
+
+/// \brief How many Records to allocate at once
+///
+/// This should be big enough to avoid making lots of tiny allocations
+/// but small enough to avoid too much unused memory at once.
+#define INDEX_GROUP_SIZE 512
+
+
+/// \brief How many Records can be allocated at once at maximum
+#define PREALLOC_MAX ((SIZE_MAX - sizeof(index_group)) / sizeof(index_record))
+
+
+/// \brief Base structure for index_stream and index_group structures
+typedef struct index_tree_node_s index_tree_node;
+struct index_tree_node_s {
+ /// Uncompressed start offset of this Stream (relative to the
+ /// beginning of the file) or Block (relative to the beginning
+ /// of the Stream)
+ lzma_vli uncompressed_base;
+
+ /// Compressed start offset of this Stream or Block
+ lzma_vli compressed_base;
+
+ index_tree_node *parent;
+ index_tree_node *left;
+ index_tree_node *right;
+};
+
+
+/// \brief AVL tree to hold index_stream or index_group structures
+typedef struct {
+ /// Root node
+ index_tree_node *root;
+
+ /// Leftmost node. Since the tree will be filled sequentially,
+ /// this won't change after the first node has been added to
+ /// the tree.
+ index_tree_node *leftmost;
+
+ /// The rightmost node in the tree. Since the tree is filled
+ /// sequentially, this is always the node where to add the new data.
+ index_tree_node *rightmost;
+
+ /// Number of nodes in the tree
+ uint32_t count;
+
+} index_tree;
+
+
+typedef struct {
+ lzma_vli uncompressed_sum;
+ lzma_vli unpadded_sum;
+} index_record;
+
+
+typedef struct {
+ /// Every Record group is part of index_stream.groups tree.
+ index_tree_node node;
+
+ /// Number of Blocks in this Stream before this group.
+ lzma_vli number_base;
+
+ /// Number of Records that can be put in records[].
+ size_t allocated;
+
+ /// Index of the last Record in use.
+ size_t last;
+
+ /// The sizes in this array are stored as cumulative sums relative
+ /// to the beginning of the Stream. This makes it possible to
+ /// use binary search in lzma_index_locate().
+ ///
+ /// Note that the cumulative summing is done specially for
+ /// unpadded_sum: The previous value is rounded up to the next
+ /// multiple of four before adding the Unpadded Size of the new
+ /// Block. The total encoded size of the Blocks in the Stream
+ /// is records[last].unpadded_sum in the last Record group of
+ /// the Stream.
+ ///
+ /// For example, if the Unpadded Sizes are 39, 57, and 81, the
+ /// stored values are 39, 97 (40 + 57), and 181 (100 + 181).
+ /// The total encoded size of these Blocks is 184.
+ ///
+ /// This is a flexible array, because it makes easy to optimize
+ /// memory usage in case someone concatenates many Streams that
+ /// have only one or few Blocks.
+ index_record records[];
+
+} index_group;
+
+
+typedef struct {
+ /// Every index_stream is a node in the tree of Sreams.
+ index_tree_node node;
+
+ /// Number of this Stream (first one is 1)
+ uint32_t number;
+
+ /// Total number of Blocks before this Stream
+ lzma_vli block_number_base;
+
+ /// Record groups of this Stream are stored in a tree.
+ /// It's a T-tree with AVL-tree balancing. There are
+ /// INDEX_GROUP_SIZE Records per node by default.
+ /// This keeps the number of memory allocations reasonable
+ /// and finding a Record is fast.
+ index_tree groups;
+
+ /// Number of Records in this Stream
+ lzma_vli record_count;
+
+ /// Size of the List of Records field in this Stream. This is used
+ /// together with record_count to calculate the size of the Index
+ /// field and thus the total size of the Stream.
+ lzma_vli index_list_size;
+
+ /// Stream Flags of this Stream. This is meaningful only if
+ /// the Stream Flags have been told us with lzma_index_stream_flags().
+ /// Initially stream_flags.version is set to UINT32_MAX to indicate
+ /// that the Stream Flags are unknown.
+ lzma_stream_flags stream_flags;
+
+ /// Amount of Stream Padding after this Stream. This defaults to
+ /// zero and can be set with lzma_index_stream_padding().
+ lzma_vli stream_padding;
+
+} index_stream;
+
+
+struct lzma_index_s {
+ /// AVL-tree containing the Stream(s). Often there is just one
+ /// Stream, but using a tree keeps lookups fast even when there
+ /// are many concatenated Streams.
+ index_tree streams;
+
+ /// Uncompressed size of all the Blocks in the Stream(s)
+ lzma_vli uncompressed_size;
+
+ /// Total size of all the Blocks in the Stream(s)
+ lzma_vli total_size;
+
+ /// Total number of Records in all Streams in this lzma_index
+ lzma_vli record_count;
+
+ /// Size of the List of Records field if all the Streams in this
+ /// lzma_index were packed into a single Stream (makes it simpler to
+ /// take many .xz files and combine them into a single Stream).
+ ///
+ /// This value together with record_count is needed to calculate
+ /// Backward Size that is stored into Stream Footer.
+ lzma_vli index_list_size;
+
+ /// How many Records to allocate at once in lzma_index_append().
+ /// This defaults to INDEX_GROUP_SIZE but can be overriden with
+ /// lzma_index_prealloc().
+ size_t prealloc;
+
+ /// Bitmask indicating what integrity check types have been used
+ /// as set by lzma_index_stream_flags(). The bit of the last Stream
+ /// is not included here, since it is possible to change it by
+ /// calling lzma_index_stream_flags() again.
+ uint32_t checks;
+};
+
+
+static void
+index_tree_init(index_tree *tree)
+{
+ tree->root = NULL;
+ tree->leftmost = NULL;
+ tree->rightmost = NULL;
+ tree->count = 0;
+ return;
+}
+
+
+/// Helper for index_tree_end()
+static void
+index_tree_node_end(index_tree_node *node, lzma_allocator *allocator,
+ void (*free_func)(void *node, lzma_allocator *allocator))
+{
+ // The tree won't ever be very huge, so recursion should be fine.
+ // 20 levels in the tree is likely quite a lot already in practice.
+ if (node->left != NULL)
+ index_tree_node_end(node->left, allocator, free_func);
+
+ if (node->right != NULL)
+ index_tree_node_end(node->right, allocator, free_func);
+
+ if (free_func != NULL)
+ free_func(node, allocator);
+
+ lzma_free(node, allocator);
+ return;
+}
+
+
+/// Free the meory allocated for a tree. If free_func is not NULL,
+/// it is called on each node before freeing the node. This is used
+/// to free the Record groups from each index_stream before freeing
+/// the index_stream itself.
+static void
+index_tree_end(index_tree *tree, lzma_allocator *allocator,
+ void (*free_func)(void *node, lzma_allocator *allocator))
+{
+ if (tree->root != NULL)
+ index_tree_node_end(tree->root, allocator, free_func);
+
+ return;
+}
+
+
+/// Add a new node to the tree. node->uncompressed_base and
+/// node->compressed_base must have been set by the caller already.
+static void
+index_tree_append(index_tree *tree, index_tree_node *node)
+{
+ uint32_t up;
+ node->parent = tree->rightmost;
+ node->left = NULL;
+ node->right = NULL;
+
+ ++tree->count;
+
+ // Handle the special case of adding the first node.
+ if (tree->root == NULL) {
+ tree->root = node;
+ tree->leftmost = node;
+ tree->rightmost = node;
+ return;
+ }
+
+ // The tree is always filled sequentially.
+ assert(tree->rightmost->uncompressed_base <= node->uncompressed_base);
+ assert(tree->rightmost->compressed_base < node->compressed_base);
+
+ // Add the new node after the rightmost node. It's the correct
+ // place due to the reason above.
+ tree->rightmost->right = node;
+ tree->rightmost = node;
+
+ // Balance the AVL-tree if needed. We don't need to keep the balance
+ // factors in nodes, because we always fill the tree sequentially,
+ // and thus know the state of the tree just by looking at the node
+ // count. From the node count we can calculate how many steps to go
+ // up in the tree to find the rotation root.
+ up = tree->count ^ (UINT32_C(1) << bsr32(tree->count));
+ if (up != 0) {
+ index_tree_node *pivot;
+
+ // Locate the root node for the rotation.
+ up = ctz32(tree->count) + 2;
+ do {
+ node = node->parent;
+ } while (--up > 0);
+
+ // Rotate left using node as the rotation root.
+ pivot = node->right;
+
+ if (node->parent == NULL) {
+ tree->root = pivot;
+ } else {
+ assert(node->parent->right == node);
+ node->parent->right = pivot;
+ }
+
+ pivot->parent = node->parent;
+
+ node->right = pivot->left;
+ if (node->right != NULL)
+ node->right->parent = node;
+
+ pivot->left = node;
+ node->parent = pivot;
+ }
+
+ return;
+}
+
+
+/// Get the next node in the tree. Return NULL if there are no more nodes.
+static void *
+index_tree_next(const index_tree_node *node)
+{
+ if (node->right != NULL) {
+ node = node->right;
+ while (node->left != NULL)
+ node = node->left;
+
+ return (void *)(node);
+ }
+
+ while (node->parent != NULL && node->parent->right == node)
+ node = node->parent;
+
+ return (void *)(node->parent);
+}
+
+
+/// Locate a node that contains the given uncompressed offset. It is
+/// caller's job to check that target is not bigger than the uncompressed
+/// size of the tree (the last node would be returned in that case still).
+static void *
+index_tree_locate(const index_tree *tree, lzma_vli target)
+{
+ const index_tree_node *result = NULL;
+ const index_tree_node *node = tree->root;
+
+ assert(tree->leftmost == NULL
+ || tree->leftmost->uncompressed_base == 0);
+
+ // Consecutive nodes may have the same uncompressed_base.
+ // We must pick the rightmost one.
+ while (node != NULL) {
+ if (node->uncompressed_base > target) {
+ node = node->left;
+ } else {
+ result = node;
+ node = node->right;
+ }
+ }
+
+ return (void *)(result);
+}
+
+
+/// Allocate and initialize a new Stream using the given base offsets.
+static index_stream *
+index_stream_init(lzma_vli compressed_base, lzma_vli uncompressed_base,
+ lzma_vli stream_number, lzma_vli block_number_base,
+ lzma_allocator *allocator)
+{
+ index_stream *s = lzma_alloc(sizeof(index_stream), allocator);
+ if (s == NULL)
+ return NULL;
+
+ s->node.uncompressed_base = uncompressed_base;
+ s->node.compressed_base = compressed_base;
+ s->node.parent = NULL;
+ s->node.left = NULL;
+ s->node.right = NULL;
+
+ s->number = stream_number;
+ s->block_number_base = block_number_base;
+
+ index_tree_init(&s->groups);
+
+ s->record_count = 0;
+ s->index_list_size = 0;
+ s->stream_flags.version = UINT32_MAX;
+ s->stream_padding = 0;
+
+ return s;
+}
+
+
+/// Free the memory allocated for a Stream and its Record groups.
+static void
+index_stream_end(void *node, lzma_allocator *allocator)
+{
+ index_stream *s = node;
+ index_tree_end(&s->groups, allocator, NULL);
+ return;
+}
+
+
+static lzma_index *
+index_init_plain(lzma_allocator *allocator)
+{
+ lzma_index *i = lzma_alloc(sizeof(lzma_index), allocator);
+ if (i != NULL) {
+ index_tree_init(&i->streams);
+ i->uncompressed_size = 0;
+ i->total_size = 0;
+ i->record_count = 0;
+ i->index_list_size = 0;
+ i->prealloc = INDEX_GROUP_SIZE;
+ i->checks = 0;
+ }
+
+ return i;
+}
+
+
+extern LZMA_API(lzma_index *)
+lzma_index_init(lzma_allocator *allocator)
+{
+ index_stream *s;
+
+ lzma_index *i = index_init_plain(allocator);
+ if (i == NULL)
+ return NULL;
+
+ s = index_stream_init(0, 0, 1, 0, allocator);
+ if (s == NULL) {
+ lzma_free(i, allocator);
+ return NULL;
+ }
+
+ index_tree_append(&i->streams, &s->node);
+
+ return i;
+}
+
+
+extern LZMA_API(void)
+lzma_index_end(lzma_index *i, lzma_allocator *allocator)
+{
+ // NOTE: If you modify this function, check also the bottom
+ // of lzma_index_cat().
+ if (i != NULL) {
+ index_tree_end(&i->streams, allocator, &index_stream_end);
+ lzma_free(i, allocator);
+ }
+
+ return;
+}
+
+
+extern void
+lzma_index_prealloc(lzma_index *i, lzma_vli records)
+{
+ if (records > PREALLOC_MAX)
+ records = PREALLOC_MAX;
+
+ i->prealloc = (size_t)(records);
+ return;
+}
+
+
+extern LZMA_API(uint64_t)
+lzma_index_memusage(lzma_vli streams, lzma_vli blocks)
+{
+ // This calculates an upper bound that is only a little bit
+ // bigger than the exact maximum memory usage with the given
+ // parameters.
+
+ // Typical malloc() overhead is 2 * sizeof(void *) but we take
+ // a little bit extra just in case. Using LZMA_MEMUSAGE_BASE
+ // instead would give too inaccurate estimate.
+ const size_t alloc_overhead = 4 * sizeof(void *);
+
+ // Amount of memory needed for each Stream base structures.
+ // We assume that every Stream has at least one Block and
+ // thus at least one group.
+ const size_t stream_base = sizeof(index_stream)
+ + sizeof(index_group) + 2 * alloc_overhead;
+
+ // Amount of memory needed per group.
+ const size_t group_base = sizeof(index_group)
+ + INDEX_GROUP_SIZE * sizeof(index_record)
+ + alloc_overhead;
+
+ // Number of groups. There may actually be more, but that overhead
+ // has been taken into account in stream_base already.
+ const lzma_vli groups
+ = (blocks + INDEX_GROUP_SIZE - 1) / INDEX_GROUP_SIZE;
+
+ // Memory used by index_stream and index_group structures.
+ const uint64_t streams_mem = streams * stream_base;
+ const uint64_t groups_mem = groups * group_base;
+
+ // Memory used by the base structure.
+ const uint64_t index_base = sizeof(lzma_index) + alloc_overhead;
+
+ // Validate the arguments and catch integer overflows.
+ // Maximum number of Streams is "only" UINT32_MAX, because
+ // that limit is used by the tree containing the Streams.
+ const uint64_t limit = UINT64_MAX - index_base;
+ if (streams == 0 || streams > UINT32_MAX || blocks > LZMA_VLI_MAX
+ || streams > limit / stream_base
+ || groups > limit / group_base
+ || limit - streams_mem < groups_mem)
+ return UINT64_MAX;
+
+ return index_base + streams_mem + groups_mem;
+}
+
+
+extern LZMA_API(uint64_t)
+lzma_index_memused(const lzma_index *i)
+{
+ return lzma_index_memusage(i->streams.count, i->record_count);
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_index_block_count(const lzma_index *i)
+{
+ return i->record_count;
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_index_stream_count(const lzma_index *i)
+{
+ return i->streams.count;
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_index_size(const lzma_index *i)
+{
+ return index_size(i->record_count, i->index_list_size);
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_index_total_size(const lzma_index *i)
+{
+ return i->total_size;
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_index_stream_size(const lzma_index *i)
+{
+ // Stream Header + Blocks + Index + Stream Footer
+ return LZMA_STREAM_HEADER_SIZE + i->total_size
+ + index_size(i->record_count, i->index_list_size)
+ + LZMA_STREAM_HEADER_SIZE;
+}
+
+
+static lzma_vli
+index_file_size(lzma_vli compressed_base, lzma_vli unpadded_sum,
+ lzma_vli record_count, lzma_vli index_list_size,
+ lzma_vli stream_padding)
+{
+ // Earlier Streams and Stream Paddings + Stream Header
+ // + Blocks + Index + Stream Footer + Stream Padding
+ //
+ // This might go over LZMA_VLI_MAX due to too big unpadded_sum
+ // when this function is used in lzma_index_append().
+ lzma_vli file_size = compressed_base + 2 * LZMA_STREAM_HEADER_SIZE
+ + stream_padding + vli_ceil4(unpadded_sum);
+ if (file_size > LZMA_VLI_MAX)
+ return LZMA_VLI_UNKNOWN;
+
+ // The same applies here.
+ file_size += index_size(record_count, index_list_size);
+ if (file_size > LZMA_VLI_MAX)
+ return LZMA_VLI_UNKNOWN;
+
+ return file_size;
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_index_file_size(const lzma_index *i)
+{
+ const index_stream *s = (const index_stream *)(i->streams.rightmost);
+ const index_group *g = (const index_group *)(s->groups.rightmost);
+ return index_file_size(s->node.compressed_base,
+ g == NULL ? 0 : g->records[g->last].unpadded_sum,
+ s->record_count, s->index_list_size,
+ s->stream_padding);
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_index_uncompressed_size(const lzma_index *i)
+{
+ return i->uncompressed_size;
+}
+
+
+extern LZMA_API(uint32_t)
+lzma_index_checks(const lzma_index *i)
+{
+ uint32_t checks = i->checks;
+
+ // Get the type of the Check of the last Stream too.
+ const index_stream *s = (const index_stream *)(i->streams.rightmost);
+ if (s->stream_flags.version != UINT32_MAX)
+ checks |= UINT32_C(1) << s->stream_flags.check;
+
+ return checks;
+}
+
+
+extern uint32_t
+lzma_index_padding_size(const lzma_index *i)
+{
+ return (LZMA_VLI_C(4) - index_size_unpadded(
+ i->record_count, i->index_list_size)) & 3;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_stream_flags(lzma_index *i, const lzma_stream_flags *stream_flags)
+{
+ index_stream *s;
+
+ if (i == NULL || stream_flags == NULL)
+ return LZMA_PROG_ERROR;
+
+ // Validate the Stream Flags.
+ return_if_error(lzma_stream_flags_compare(
+ stream_flags, stream_flags));
+
+ s = (index_stream *)(i->streams.rightmost);
+ s->stream_flags = *stream_flags;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_stream_padding(lzma_index *i, lzma_vli stream_padding)
+{
+ index_stream *s;
+ lzma_vli old_stream_padding;
+
+ if (i == NULL || stream_padding > LZMA_VLI_MAX
+ || (stream_padding & 3) != 0)
+ return LZMA_PROG_ERROR;
+
+ s = (index_stream *)(i->streams.rightmost);
+
+ // Check that the new value won't make the file grow too big.
+ old_stream_padding = s->stream_padding;
+ s->stream_padding = 0;
+ if (lzma_index_file_size(i) + stream_padding > LZMA_VLI_MAX) {
+ s->stream_padding = old_stream_padding;
+ return LZMA_DATA_ERROR;
+ }
+
+ s->stream_padding = stream_padding;
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_append(lzma_index *i, lzma_allocator *allocator,
+ lzma_vli unpadded_size, lzma_vli uncompressed_size)
+{
+ index_stream *s;
+ index_group *g;
+ lzma_vli compressed_base;
+ lzma_vli uncompressed_base;
+ uint32_t index_list_size_add;
+
+ // Validate.
+ if (i == NULL || unpadded_size < UNPADDED_SIZE_MIN
+ || unpadded_size > UNPADDED_SIZE_MAX
+ || uncompressed_size > LZMA_VLI_MAX)
+ return LZMA_PROG_ERROR;
+
+ s = (index_stream *)(i->streams.rightmost);
+ g = (index_group *)(s->groups.rightmost);
+
+ compressed_base = g == NULL ? 0
+ : vli_ceil4(g->records[g->last].unpadded_sum);
+ uncompressed_base = g == NULL ? 0
+ : g->records[g->last].uncompressed_sum;
+ index_list_size_add = lzma_vli_size(unpadded_size)
+ + lzma_vli_size(uncompressed_size);
+
+ // Check that the file size will stay within limits.
+ if (index_file_size(s->node.compressed_base,
+ compressed_base + unpadded_size, s->record_count + 1,
+ s->index_list_size + index_list_size_add,
+ s->stream_padding) == LZMA_VLI_UNKNOWN)
+ return LZMA_DATA_ERROR;
+
+ // The size of the Index field must not exceed the maximum value
+ // that can be stored in the Backward Size field.
+ if (index_size(i->record_count + 1,
+ i->index_list_size + index_list_size_add)
+ > LZMA_BACKWARD_SIZE_MAX)
+ return LZMA_DATA_ERROR;
+
+ if (g != NULL && g->last + 1 < g->allocated) {
+ // There is space in the last group at least for one Record.
+ ++g->last;
+ } else {
+ // We need to allocate a new group.
+ g = lzma_alloc(sizeof(index_group)
+ + i->prealloc * sizeof(index_record),
+ allocator);
+ if (g == NULL)
+ return LZMA_MEM_ERROR;
+
+ g->last = 0;
+ g->allocated = i->prealloc;
+
+ // Reset prealloc so that if the application happens to
+ // add new Records, the allocation size will be sane.
+ i->prealloc = INDEX_GROUP_SIZE;
+
+ // Set the start offsets of this group.
+ g->node.uncompressed_base = uncompressed_base;
+ g->node.compressed_base = compressed_base;
+ g->number_base = s->record_count + 1;
+
+ // Add the new group to the Stream.
+ index_tree_append(&s->groups, &g->node);
+ }
+
+ // Add the new Record to the group.
+ g->records[g->last].uncompressed_sum
+ = uncompressed_base + uncompressed_size;
+ g->records[g->last].unpadded_sum
+ = compressed_base + unpadded_size;
+
+ // Update the totals.
+ ++s->record_count;
+ s->index_list_size += index_list_size_add;
+
+ i->total_size += vli_ceil4(unpadded_size);
+ i->uncompressed_size += uncompressed_size;
+ ++i->record_count;
+ i->index_list_size += index_list_size_add;
+
+ return LZMA_OK;
+}
+
+
+/// Structure to pass info to index_cat_helper()
+typedef struct {
+ /// Uncompressed size of the destination
+ lzma_vli uncompressed_size;
+
+ /// Compressed file size of the destination
+ lzma_vli file_size;
+
+ /// Same as above but for Block numbers
+ lzma_vli block_number_add;
+
+ /// Number of Streams that were in the destination index before we
+ /// started appending new Streams from the source index. This is
+ /// used to fix the Stream numbering.
+ uint32_t stream_number_add;
+
+ /// Destination index' Stream tree
+ index_tree *streams;
+
+} index_cat_info;
+
+
+/// Add the Stream nodes from the source index to dest using recursion.
+/// Simplest iterative traversal of the source tree wouldn't work, because
+/// we update the pointers in nodes when moving them to the destination tree.
+static void
+index_cat_helper(const index_cat_info *info, index_stream *this)
+{
+ index_stream *left = (index_stream *)(this->node.left);
+ index_stream *right = (index_stream *)(this->node.right);
+
+ if (left != NULL)
+ index_cat_helper(info, left);
+
+ this->node.uncompressed_base += info->uncompressed_size;
+ this->node.compressed_base += info->file_size;
+ this->number += info->stream_number_add;
+ this->block_number_base += info->block_number_add;
+ index_tree_append(info->streams, &this->node);
+
+ if (right != NULL)
+ index_cat_helper(info, right);
+
+ return;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_cat(lzma_index *LZMA_RESTRICT dest, lzma_index *LZMA_RESTRICT src,
+ lzma_allocator *allocator)
+{
+ index_cat_info info;
+ const lzma_vli dest_file_size = lzma_index_file_size(dest);
+
+ // Check that we don't exceed the file size limits.
+ if (dest_file_size + lzma_index_file_size(src) > LZMA_VLI_MAX
+ || dest->uncompressed_size + src->uncompressed_size
+ > LZMA_VLI_MAX)
+ return LZMA_DATA_ERROR;
+
+ // Check that the encoded size of the combined lzma_indexes stays
+ // within limits. In theory, this should be done only if we know
+ // that the user plans to actually combine the Streams and thus
+ // construct a single Index (probably rare). However, exceeding
+ // this limit is quite theoretical, so we do this check always
+ // to simplify things elsewhere.
+ {
+ const lzma_vli dest_size = index_size_unpadded(
+ dest->record_count, dest->index_list_size);
+ const lzma_vli src_size = index_size_unpadded(
+ src->record_count, src->index_list_size);
+ if (vli_ceil4(dest_size + src_size) > LZMA_BACKWARD_SIZE_MAX)
+ return LZMA_DATA_ERROR;
+ }
+
+ // Optimize the last group to minimize memory usage. Allocation has
+ // to be done before modifying dest or src.
+ {
+ index_stream *s = (index_stream *)(dest->streams.rightmost);
+ index_group *g = (index_group *)(s->groups.rightmost);
+ if (g != NULL && g->last + 1 < g->allocated) {
+ index_group *newg;
+
+ assert(g->node.left == NULL);
+ assert(g->node.right == NULL);
+
+ newg = lzma_alloc(sizeof(index_group)
+ + (g->last + 1)
+ * sizeof(index_record),
+ allocator);
+ if (newg == NULL)
+ return LZMA_MEM_ERROR;
+
+ newg->node = g->node;
+ newg->allocated = g->last + 1;
+ newg->last = g->last;
+ newg->number_base = g->number_base;
+
+ memcpy(newg->records, g->records, newg->allocated
+ * sizeof(index_record));
+
+ if (g->node.parent != NULL) {
+ assert(g->node.parent->right == &g->node);
+ g->node.parent->right = &newg->node;
+ }
+
+ if (s->groups.leftmost == &g->node) {
+ assert(s->groups.root == &g->node);
+ s->groups.leftmost = &newg->node;
+ s->groups.root = &newg->node;
+ }
+
+ if (s->groups.rightmost == &g->node)
+ s->groups.rightmost = &newg->node;
+
+ lzma_free(g, allocator);
+ }
+ }
+
+ // Add all the Streams from src to dest. Update the base offsets
+ // of each Stream from src.
+ info.uncompressed_size = dest->uncompressed_size;
+ info.file_size = dest_file_size;
+ info.stream_number_add = dest->streams.count;
+ info.block_number_add = dest->record_count;
+ info.streams = &dest->streams;
+
+ index_cat_helper(&info, (index_stream *)(src->streams.root));
+
+ // Update info about all the combined Streams.
+ dest->uncompressed_size += src->uncompressed_size;
+ dest->total_size += src->total_size;
+ dest->record_count += src->record_count;
+ dest->index_list_size += src->index_list_size;
+ dest->checks = lzma_index_checks(dest) | src->checks;
+
+ // There's nothing else left in src than the base structure.
+ lzma_free(src, allocator);
+
+ return LZMA_OK;
+}
+
+
+/// Duplicate an index_stream.
+static index_stream *
+index_dup_stream(const index_stream *src, lzma_allocator *allocator)
+{
+ index_stream *dest;
+ index_group *destg;
+ index_group *srcg;
+ size_t i = 0;
+
+ // Catch a somewhat theoretical integer overflow.
+ if (src->record_count > PREALLOC_MAX)
+ return NULL;
+
+ // Allocate and initialize a new Stream.
+ dest = index_stream_init(src->node.compressed_base,
+ src->node.uncompressed_base, src->number,
+ src->block_number_base, allocator);
+
+ // Return immediately if allocation failed or if there are
+ // no groups to duplicate.
+ if (dest == NULL || src->groups.leftmost == NULL)
+ return dest;
+
+ // Copy the overall information.
+ dest->record_count = src->record_count;
+ dest->index_list_size = src->index_list_size;
+ dest->stream_flags = src->stream_flags;
+ dest->stream_padding = src->stream_padding;
+
+ // Allocate memory for the Records. We put all the Records into
+ // a single group. It's simplest and also tends to make
+ // lzma_index_locate() a little bit faster with very big Indexes.
+ destg = lzma_alloc(sizeof(index_group)
+ + src->record_count * sizeof(index_record),
+ allocator);
+ if (destg == NULL) {
+ index_stream_end(dest, allocator);
+ return NULL;
+ }
+
+ // Initialize destg.
+ destg->node.uncompressed_base = 0;
+ destg->node.compressed_base = 0;
+ destg->number_base = 1;
+ destg->allocated = src->record_count;
+ destg->last = src->record_count - 1;
+
+ // Go through all the groups in src and copy the Records into destg.
+ srcg = (index_group *)(src->groups.leftmost);
+ do {
+ memcpy(destg->records + i, srcg->records,
+ (srcg->last + 1) * sizeof(index_record));
+ i += srcg->last + 1;
+ srcg = index_tree_next(&srcg->node);
+ } while (srcg != NULL);
+
+ assert(i == destg->allocated);
+
+ // Add the group to the new Stream.
+ index_tree_append(&dest->groups, &destg->node);
+
+ return dest;
+}
+
+
+extern LZMA_API(lzma_index *)
+lzma_index_dup(const lzma_index *src, lzma_allocator *allocator)
+{
+ index_stream *srcstream;
+ index_stream *deststream;
+
+ // Allocate the base structure (no initial Stream).
+ lzma_index *dest = index_init_plain(allocator);
+ if (dest == NULL)
+ return NULL;
+
+ // Copy the totals.
+ dest->uncompressed_size = src->uncompressed_size;
+ dest->total_size = src->total_size;
+ dest->record_count = src->record_count;
+ dest->index_list_size = src->index_list_size;
+
+ // Copy the Streams and the groups in them.
+ srcstream = (index_stream *)(src->streams.leftmost);
+ do {
+ deststream = index_dup_stream(srcstream, allocator);
+ if (deststream == NULL) {
+ lzma_index_end(dest, allocator);
+ return NULL;
+ }
+
+ index_tree_append(&dest->streams, &deststream->node);
+
+ srcstream = index_tree_next(&srcstream->node);
+ } while (srcstream != NULL);
+
+ return dest;
+}
+
+
+/// Indexing for lzma_index_iter.internal[]
+enum {
+ ITER_INDEX,
+ ITER_STREAM,
+ ITER_GROUP,
+ ITER_RECORD,
+ ITER_METHOD,
+};
+
+
+/// Values for lzma_index_iter.internal[ITER_METHOD].s
+enum {
+ ITER_METHOD_NORMAL,
+ ITER_METHOD_NEXT,
+ ITER_METHOD_LEFTMOST,
+};
+
+
+static void
+iter_set_info(lzma_index_iter *iter)
+{
+ const lzma_index *i = iter->internal[ITER_INDEX].p;
+ const index_stream *stream = iter->internal[ITER_STREAM].p;
+ const index_group *group = iter->internal[ITER_GROUP].p;
+ const size_t record = iter->internal[ITER_RECORD].s;
+
+ // lzma_index_iter.internal must not contain a pointer to the last
+ // group in the index, because that may be reallocated by
+ // lzma_index_cat().
+ if (group == NULL) {
+ // There are no groups.
+ assert(stream->groups.root == NULL);
+ iter->internal[ITER_METHOD].s = ITER_METHOD_LEFTMOST;
+
+ } else if (i->streams.rightmost != &stream->node
+ || stream->groups.rightmost != &group->node) {
+ // The group is not not the last group in the index.
+ iter->internal[ITER_METHOD].s = ITER_METHOD_NORMAL;
+
+ } else if (stream->groups.leftmost != &group->node) {
+ // The group isn't the only group in the Stream, thus we
+ // know that it must have a parent group i.e. it's not
+ // the root node.
+ assert(stream->groups.root != &group->node);
+ assert(group->node.parent->right == &group->node);
+ iter->internal[ITER_METHOD].s = ITER_METHOD_NEXT;
+ iter->internal[ITER_GROUP].p = group->node.parent;
+
+ } else {
+ // The Stream has only one group.
+ assert(stream->groups.root == &group->node);
+ assert(group->node.parent == NULL);
+ iter->internal[ITER_METHOD].s = ITER_METHOD_LEFTMOST;
+ iter->internal[ITER_GROUP].p = NULL;
+ }
+
+ iter->stream.number = stream->number;
+ iter->stream.block_count = stream->record_count;
+ iter->stream.compressed_offset = stream->node.compressed_base;
+ iter->stream.uncompressed_offset = stream->node.uncompressed_base;
+
+ // iter->stream.flags will be NULL if the Stream Flags haven't been
+ // set with lzma_index_stream_flags().
+ iter->stream.flags = stream->stream_flags.version == UINT32_MAX
+ ? NULL : &stream->stream_flags;
+ iter->stream.padding = stream->stream_padding;
+
+ if (stream->groups.rightmost == NULL) {
+ // Stream has no Blocks.
+ iter->stream.compressed_size = index_size(0, 0)
+ + 2 * LZMA_STREAM_HEADER_SIZE;
+ iter->stream.uncompressed_size = 0;
+ } else {
+ const index_group *g = (const index_group *)(
+ stream->groups.rightmost);
+
+ // Stream Header + Stream Footer + Index + Blocks
+ iter->stream.compressed_size = 2 * LZMA_STREAM_HEADER_SIZE
+ + index_size(stream->record_count,
+ stream->index_list_size)
+ + vli_ceil4(g->records[g->last].unpadded_sum);
+ iter->stream.uncompressed_size
+ = g->records[g->last].uncompressed_sum;
+ }
+
+ if (group != NULL) {
+ iter->block.number_in_stream = group->number_base + record;
+ iter->block.number_in_file = iter->block.number_in_stream
+ + stream->block_number_base;
+
+ iter->block.compressed_stream_offset
+ = record == 0 ? group->node.compressed_base
+ : vli_ceil4(group->records[
+ record - 1].unpadded_sum);
+ iter->block.uncompressed_stream_offset
+ = record == 0 ? group->node.uncompressed_base
+ : group->records[record - 1].uncompressed_sum;
+
+ iter->block.uncompressed_size
+ = group->records[record].uncompressed_sum
+ - iter->block.uncompressed_stream_offset;
+ iter->block.unpadded_size
+ = group->records[record].unpadded_sum
+ - iter->block.compressed_stream_offset;
+ iter->block.total_size = vli_ceil4(iter->block.unpadded_size);
+
+ iter->block.compressed_stream_offset
+ += LZMA_STREAM_HEADER_SIZE;
+
+ iter->block.compressed_file_offset
+ = iter->block.compressed_stream_offset
+ + iter->stream.compressed_offset;
+ iter->block.uncompressed_file_offset
+ = iter->block.uncompressed_stream_offset
+ + iter->stream.uncompressed_offset;
+ }
+
+ return;
+}
+
+
+extern LZMA_API(void)
+lzma_index_iter_init(lzma_index_iter *iter, const lzma_index *i)
+{
+ iter->internal[ITER_INDEX].p = i;
+ lzma_index_iter_rewind(iter);
+ return;
+}
+
+
+extern LZMA_API(void)
+lzma_index_iter_rewind(lzma_index_iter *iter)
+{
+ iter->internal[ITER_STREAM].p = NULL;
+ iter->internal[ITER_GROUP].p = NULL;
+ iter->internal[ITER_RECORD].s = 0;
+ iter->internal[ITER_METHOD].s = ITER_METHOD_NORMAL;
+ return;
+}
+
+
+extern LZMA_API(lzma_bool)
+lzma_index_iter_next(lzma_index_iter *iter, lzma_index_iter_mode mode)
+{
+ const lzma_index *i;
+ const index_stream *stream;
+ const index_group *group;
+ size_t record;
+
+ // Catch unsupported mode values.
+ if ((unsigned int)(mode) > LZMA_INDEX_ITER_NONEMPTY_BLOCK)
+ return true;
+
+ i = iter->internal[ITER_INDEX].p;
+ stream = iter->internal[ITER_STREAM].p;
+ group = NULL;
+ record = iter->internal[ITER_RECORD].s;
+
+ // If we are being asked for the next Stream, leave group to NULL
+ // so that the rest of the this function thinks that this Stream
+ // has no groups and will thus go to the next Stream.
+ if (mode != LZMA_INDEX_ITER_STREAM) {
+ // Get the pointer to the current group. See iter_set_inf()
+ // for explanation.
+ switch (iter->internal[ITER_METHOD].s) {
+ case ITER_METHOD_NORMAL:
+ group = iter->internal[ITER_GROUP].p;
+ break;
+
+ case ITER_METHOD_NEXT:
+ group = index_tree_next(iter->internal[ITER_GROUP].p);
+ break;
+
+ case ITER_METHOD_LEFTMOST:
+ group = (const index_group *)(
+ stream->groups.leftmost);
+ break;
+ }
+ }
+
+again:
+ if (stream == NULL) {
+ // We at the beginning of the lzma_index.
+ // Locate the first Stream.
+ stream = (const index_stream *)(i->streams.leftmost);
+ if (mode >= LZMA_INDEX_ITER_BLOCK) {
+ // Since we are being asked to return information
+ // about the first a Block, skip Streams that have
+ // no Blocks.
+ while (stream->groups.leftmost == NULL) {
+ stream = index_tree_next(&stream->node);
+ if (stream == NULL)
+ return true;
+ }
+ }
+
+ // Start from the first Record in the Stream.
+ group = (const index_group *)(stream->groups.leftmost);
+ record = 0;
+
+ } else if (group != NULL && record < group->last) {
+ // The next Record is in the same group.
+ ++record;
+
+ } else {
+ // This group has no more Records or this Stream has
+ // no Blocks at all.
+ record = 0;
+
+ // If group is not NULL, this Stream has at least one Block
+ // and thus at least one group. Find the next group.
+ if (group != NULL)
+ group = index_tree_next(&group->node);
+
+ if (group == NULL) {
+ // This Stream has no more Records. Find the next
+ // Stream. If we are being asked to return information
+ // about a Block, we skip empty Streams.
+ do {
+ stream = index_tree_next(&stream->node);
+ if (stream == NULL)
+ return true;
+ } while (mode >= LZMA_INDEX_ITER_BLOCK
+ && stream->groups.leftmost == NULL);
+
+ group = (const index_group *)(
+ stream->groups.leftmost);
+ }
+ }
+
+ if (mode == LZMA_INDEX_ITER_NONEMPTY_BLOCK) {
+ // We need to look for the next Block again if this Block
+ // is empty.
+ if (record == 0) {
+ if (group->node.uncompressed_base
+ == group->records[0].uncompressed_sum)
+ goto again;
+ } else if (group->records[record - 1].uncompressed_sum
+ == group->records[record].uncompressed_sum) {
+ goto again;
+ }
+ }
+
+ iter->internal[ITER_STREAM].p = stream;
+ iter->internal[ITER_GROUP].p = group;
+ iter->internal[ITER_RECORD].s = record;
+
+ iter_set_info(iter);
+
+ return false;
+}
+
+
+extern LZMA_API(lzma_bool)
+lzma_index_iter_locate(lzma_index_iter *iter, lzma_vli target)
+{
+ const index_stream *stream;
+ const index_group *group;
+ size_t left, right;
+
+ const lzma_index *i = iter->internal[ITER_INDEX].p;
+
+ // If the target is past the end of the file, return immediately.
+ if (i->uncompressed_size <= target)
+ return true;
+
+ // Locate the Stream containing the target offset.
+ stream = index_tree_locate(&i->streams, target);
+ assert(stream != NULL);
+ target -= stream->node.uncompressed_base;
+
+ // Locate the group containing the target offset.
+ group = index_tree_locate(&stream->groups, target);
+ assert(group != NULL);
+
+ // Use binary search to locate the exact Record. It is the first
+ // Record whose uncompressed_sum is greater than target.
+ // This is because we want the rightmost Record that fullfills the
+ // search criterion. It is possible that there are empty Blocks;
+ // we don't want to return them.
+ left = 0;
+ right = group->last;
+
+ while (left < right) {
+ const size_t pos = left + (right - left) / 2;
+ if (group->records[pos].uncompressed_sum <= target)
+ left = pos + 1;
+ else
+ right = pos;
+ }
+
+ iter->internal[ITER_STREAM].p = stream;
+ iter->internal[ITER_GROUP].p = group;
+ iter->internal[ITER_RECORD].s = left;
+
+ iter_set_info(iter);
+
+ return false;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/index.h b/Utilities/cmliblzma/liblzma/common/index.h
new file mode 100644
index 0000000000..64e97247dd
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/index.h
@@ -0,0 +1,73 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file index.h
+/// \brief Handling of Index
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_INDEX_H
+#define LZMA_INDEX_H
+
+#include "common.h"
+
+
+/// Minimum Unpadded Size
+#define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
+
+/// Maximum Unpadded Size
+#define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
+
+
+/// Get the size of the Index Padding field. This is needed by Index encoder
+/// and decoder, but applications should have no use for this.
+extern uint32_t lzma_index_padding_size(const lzma_index *i);
+
+
+/// Set for how many Records to allocate memory the next time
+/// lzma_index_append() needs to allocate space for a new Record.
+/// This is used only by the Index decoder.
+extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);
+
+
+/// Round the variable-length integer to the next multiple of four.
+static inline lzma_vli
+vli_ceil4(lzma_vli vli)
+{
+ assert(vli <= LZMA_VLI_MAX);
+ return (vli + 3) & ~LZMA_VLI_C(3);
+}
+
+
+/// Calculate the size of the Index field excluding Index Padding
+static inline lzma_vli
+index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
+{
+ // Index Indicator + Number of Records + List of Records + CRC32
+ return 1 + lzma_vli_size(count) + index_list_size + 4;
+}
+
+
+/// Calculate the size of the Index field including Index Padding
+static inline lzma_vli
+index_size(lzma_vli count, lzma_vli index_list_size)
+{
+ return vli_ceil4(index_size_unpadded(count, index_list_size));
+}
+
+
+/// Calculate the total size of the Stream
+static inline lzma_vli
+index_stream_size(lzma_vli blocks_size,
+ lzma_vli count, lzma_vli index_list_size)
+{
+ return LZMA_STREAM_HEADER_SIZE + blocks_size
+ + index_size(count, index_list_size)
+ + LZMA_STREAM_HEADER_SIZE;
+}
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/index_decoder.c b/Utilities/cmliblzma/liblzma/common/index_decoder.c
new file mode 100644
index 0000000000..943cfd58a4
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/index_decoder.c
@@ -0,0 +1,347 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file index_decoder.c
+/// \brief Decodes the Index field
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "index.h"
+#include "check.h"
+
+
+struct lzma_coder_s {
+ enum {
+ SEQ_INDICATOR,
+ SEQ_COUNT,
+ SEQ_MEMUSAGE,
+ SEQ_UNPADDED,
+ SEQ_UNCOMPRESSED,
+ SEQ_PADDING_INIT,
+ SEQ_PADDING,
+ SEQ_CRC32,
+ } sequence;
+
+ /// Memory usage limit
+ uint64_t memlimit;
+
+ /// Target Index
+ lzma_index *index;
+
+ /// Pointer give by the application, which is set after
+ /// successful decoding.
+ lzma_index **index_ptr;
+
+ /// Number of Records left to decode.
+ lzma_vli count;
+
+ /// The most recent Unpadded Size field
+ lzma_vli unpadded_size;
+
+ /// The most recent Uncompressed Size field
+ lzma_vli uncompressed_size;
+
+ /// Position in integers
+ size_t pos;
+
+ /// CRC32 of the List of Records field
+ uint32_t crc32;
+};
+
+
+static lzma_ret
+index_decode(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size,
+ uint8_t *LZMA_RESTRICT out lzma_attribute((__unused__)),
+ size_t *LZMA_RESTRICT out_pos lzma_attribute((__unused__)),
+ size_t out_size lzma_attribute((__unused__)),
+ lzma_action action lzma_attribute((__unused__)))
+{
+ // Similar optimization as in index_encoder.c
+ const size_t in_start = *in_pos;
+ lzma_ret ret = LZMA_OK;
+
+ while (*in_pos < in_size)
+ switch (coder->sequence) {
+ case SEQ_INDICATOR:
+ // Return LZMA_DATA_ERROR instead of e.g. LZMA_PROG_ERROR or
+ // LZMA_FORMAT_ERROR, because a typical usage case for Index
+ // decoder is when parsing the Stream backwards. If seeking
+ // backward from the Stream Footer gives us something that
+ // doesn't begin with Index Indicator, the file is considered
+ // corrupt, not "programming error" or "unrecognized file
+ // format". One could argue that the application should
+ // verify the Index Indicator before trying to decode the
+ // Index, but well, I suppose it is simpler this way.
+ if (in[(*in_pos)++] != 0x00)
+ return LZMA_DATA_ERROR;
+
+ coder->sequence = SEQ_COUNT;
+ break;
+
+ case SEQ_COUNT:
+ ret = lzma_vli_decode(&coder->count, &coder->pos,
+ in, in_pos, in_size);
+ if (ret != LZMA_STREAM_END)
+ goto out;
+
+ coder->pos = 0;
+ coder->sequence = SEQ_MEMUSAGE;
+
+ // Fall through
+
+ case SEQ_MEMUSAGE:
+ if (lzma_index_memusage(1, coder->count) > coder->memlimit) {
+ ret = LZMA_MEMLIMIT_ERROR;
+ goto out;
+ }
+
+ // Tell the Index handling code how many Records this
+ // Index has to allow it to allocate memory more efficiently.
+ lzma_index_prealloc(coder->index, coder->count);
+
+ ret = LZMA_OK;
+ coder->sequence = coder->count == 0
+ ? SEQ_PADDING_INIT : SEQ_UNPADDED;
+ break;
+
+ case SEQ_UNPADDED:
+ case SEQ_UNCOMPRESSED: {
+ lzma_vli *size = coder->sequence == SEQ_UNPADDED
+ ? &coder->unpadded_size
+ : &coder->uncompressed_size;
+
+ ret = lzma_vli_decode(size, &coder->pos,
+ in, in_pos, in_size);
+ if (ret != LZMA_STREAM_END)
+ goto out;
+
+ ret = LZMA_OK;
+ coder->pos = 0;
+
+ if (coder->sequence == SEQ_UNPADDED) {
+ // Validate that encoded Unpadded Size isn't too small
+ // or too big.
+ if (coder->unpadded_size < UNPADDED_SIZE_MIN
+ || coder->unpadded_size
+ > UNPADDED_SIZE_MAX)
+ return LZMA_DATA_ERROR;
+
+ coder->sequence = SEQ_UNCOMPRESSED;
+ } else {
+ // Add the decoded Record to the Index.
+ return_if_error(lzma_index_append(
+ coder->index, allocator,
+ coder->unpadded_size,
+ coder->uncompressed_size));
+
+ // Check if this was the last Record.
+ coder->sequence = --coder->count == 0
+ ? SEQ_PADDING_INIT
+ : SEQ_UNPADDED;
+ }
+
+ break;
+ }
+
+ case SEQ_PADDING_INIT:
+ coder->pos = lzma_index_padding_size(coder->index);
+ coder->sequence = SEQ_PADDING;
+
+ // Fall through
+
+ case SEQ_PADDING:
+ if (coder->pos > 0) {
+ --coder->pos;
+ if (in[(*in_pos)++] != 0x00)
+ return LZMA_DATA_ERROR;
+
+ break;
+ }
+
+ // Finish the CRC32 calculation.
+ coder->crc32 = lzma_crc32(in + in_start,
+ *in_pos - in_start, coder->crc32);
+
+ coder->sequence = SEQ_CRC32;
+
+ // Fall through
+
+ case SEQ_CRC32:
+ do {
+ if (*in_pos == in_size)
+ return LZMA_OK;
+
+ if (((coder->crc32 >> (coder->pos * 8)) & 0xFF)
+ != in[(*in_pos)++])
+ return LZMA_DATA_ERROR;
+
+ } while (++coder->pos < 4);
+
+ // Decoding was successful, now we can let the application
+ // see the decoded Index.
+ *coder->index_ptr = coder->index;
+
+ // Make index NULL so we don't free it unintentionally.
+ coder->index = NULL;
+
+ return LZMA_STREAM_END;
+
+ default:
+ assert(0);
+ return LZMA_PROG_ERROR;
+ }
+
+out:
+ // Update the CRC32,
+ coder->crc32 = lzma_crc32(in + in_start,
+ *in_pos - in_start, coder->crc32);
+
+ return ret;
+}
+
+
+static void
+index_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_index_end(coder->index, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static lzma_ret
+index_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
+ uint64_t *old_memlimit, uint64_t new_memlimit)
+{
+ *memusage = lzma_index_memusage(1, coder->count);
+ *old_memlimit = coder->memlimit;
+
+ if (new_memlimit != 0) {
+ if (new_memlimit < *memusage)
+ return LZMA_MEMLIMIT_ERROR;
+
+ coder->memlimit = new_memlimit;
+ }
+
+ return LZMA_OK;
+}
+
+
+static lzma_ret
+index_decoder_reset(lzma_coder *coder, lzma_allocator *allocator,
+ lzma_index **i, uint64_t memlimit)
+{
+ // Remember the pointer given by the application. We will set it
+ // to point to the decoded Index only if decoding is successful.
+ // Before that, keep it NULL so that applications can always safely
+ // pass it to lzma_index_end() no matter did decoding succeed or not.
+ coder->index_ptr = i;
+ *i = NULL;
+
+ // We always allocate a new lzma_index.
+ coder->index = lzma_index_init(allocator);
+ if (coder->index == NULL)
+ return LZMA_MEM_ERROR;
+
+ // Initialize the rest.
+ coder->sequence = SEQ_INDICATOR;
+ coder->memlimit = memlimit;
+ coder->count = 0; // Needs to be initialized due to _memconfig().
+ coder->pos = 0;
+ coder->crc32 = 0;
+
+ return LZMA_OK;
+}
+
+
+static lzma_ret
+index_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ lzma_index **i, uint64_t memlimit)
+{
+ lzma_next_coder_init(&index_decoder_init, next, allocator);
+
+ if (i == NULL || memlimit == 0)
+ return LZMA_PROG_ERROR;
+
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &index_decode;
+ next->end = &index_decoder_end;
+ next->memconfig = &index_decoder_memconfig;
+ next->coder->index = NULL;
+ } else {
+ lzma_index_end(next->coder->index, allocator);
+ }
+
+ return index_decoder_reset(next->coder, allocator, i, memlimit);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_decoder(lzma_stream *strm, lzma_index **i, uint64_t memlimit)
+{
+ lzma_next_strm_init2(index_decoder_init, strm, i, memlimit);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_buffer_decode(
+ lzma_index **i, uint64_t *memlimit, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size)
+{
+ lzma_coder coder;
+ lzma_ret ret;
+
+ // Store the input start position so that we can restore it in case
+ // of an error.
+ const size_t in_start = *in_pos;
+
+ // Sanity checks
+ if (i == NULL || memlimit == NULL
+ || in == NULL || in_pos == NULL || *in_pos > in_size)
+ return LZMA_PROG_ERROR;
+
+ // Initialize the decoder.
+ return_if_error(index_decoder_reset(&coder, allocator, i, *memlimit));
+
+ // Do the actual decoding.
+ ret = index_decode(&coder, allocator, in, in_pos, in_size,
+ NULL, NULL, 0, LZMA_RUN);
+
+ if (ret == LZMA_STREAM_END) {
+ ret = LZMA_OK;
+ } else {
+ // Something went wrong, free the Index structure and restore
+ // the input position.
+ lzma_index_end(coder.index, allocator);
+ *in_pos = in_start;
+
+ if (ret == LZMA_OK) {
+ // The input is truncated or otherwise corrupt.
+ // Use LZMA_DATA_ERROR instead of LZMA_BUF_ERROR
+ // like lzma_vli_decode() does in single-call mode.
+ ret = LZMA_DATA_ERROR;
+
+ } else if (ret == LZMA_MEMLIMIT_ERROR) {
+ // Tell the caller how much memory would have
+ // been needed.
+ *memlimit = lzma_index_memusage(1, coder.count);
+ }
+ }
+
+ return ret;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/index_encoder.c b/Utilities/cmliblzma/liblzma/common/index_encoder.c
new file mode 100644
index 0000000000..194bf21131
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/index_encoder.c
@@ -0,0 +1,257 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file index_encoder.c
+/// \brief Encodes the Index field
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "index_encoder.h"
+#include "index.h"
+#include "check.h"
+
+
+struct lzma_coder_s {
+ enum {
+ SEQ_INDICATOR,
+ SEQ_COUNT,
+ SEQ_UNPADDED,
+ SEQ_UNCOMPRESSED,
+ SEQ_NEXT,
+ SEQ_PADDING,
+ SEQ_CRC32,
+ } sequence;
+
+ /// Index being encoded
+ const lzma_index *index;
+
+ /// Iterator for the Index being encoded
+ lzma_index_iter iter;
+
+ /// Position in integers
+ size_t pos;
+
+ /// CRC32 of the List of Records field
+ uint32_t crc32;
+};
+
+
+static lzma_ret
+index_encode(lzma_coder *coder,
+ lzma_allocator *allocator lzma_attribute((__unused__)),
+ const uint8_t *LZMA_RESTRICT in lzma_attribute((__unused__)),
+ size_t *LZMA_RESTRICT in_pos lzma_attribute((__unused__)),
+ size_t in_size lzma_attribute((__unused__)),
+ uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
+ size_t out_size,
+ lzma_action action lzma_attribute((__unused__)))
+{
+ // Position where to start calculating CRC32. The idea is that we
+ // need to call lzma_crc32() only once per call to index_encode().
+ const size_t out_start = *out_pos;
+
+ // Return value to use if we return at the end of this function.
+ // We use "goto out" to jump out of the while-switch construct
+ // instead of returning directly, because that way we don't need
+ // to copypaste the lzma_crc32() call to many places.
+ lzma_ret ret = LZMA_OK;
+
+ while (*out_pos < out_size)
+ switch (coder->sequence) {
+ case SEQ_INDICATOR:
+ out[*out_pos] = 0x00;
+ ++*out_pos;
+ coder->sequence = SEQ_COUNT;
+ break;
+
+ case SEQ_COUNT: {
+ const lzma_vli count = lzma_index_block_count(coder->index);
+ ret = lzma_vli_encode(count, &coder->pos,
+ out, out_pos, out_size);
+ if (ret != LZMA_STREAM_END)
+ goto out;
+
+ ret = LZMA_OK;
+ coder->pos = 0;
+ coder->sequence = SEQ_NEXT;
+ break;
+ }
+
+ case SEQ_NEXT:
+ if (lzma_index_iter_next(
+ &coder->iter, LZMA_INDEX_ITER_BLOCK)) {
+ // Get the size of the Index Padding field.
+ coder->pos = lzma_index_padding_size(coder->index);
+ assert(coder->pos <= 3);
+ coder->sequence = SEQ_PADDING;
+ break;
+ }
+
+ coder->sequence = SEQ_UNPADDED;
+
+ // Fall through
+
+ case SEQ_UNPADDED:
+ case SEQ_UNCOMPRESSED: {
+ const lzma_vli size = coder->sequence == SEQ_UNPADDED
+ ? coder->iter.block.unpadded_size
+ : coder->iter.block.uncompressed_size;
+
+ ret = lzma_vli_encode(size, &coder->pos,
+ out, out_pos, out_size);
+ if (ret != LZMA_STREAM_END)
+ goto out;
+
+ ret = LZMA_OK;
+ coder->pos = 0;
+
+ // Advance to SEQ_UNCOMPRESSED or SEQ_NEXT.
+ ++coder->sequence;
+ break;
+ }
+
+ case SEQ_PADDING:
+ if (coder->pos > 0) {
+ --coder->pos;
+ out[(*out_pos)++] = 0x00;
+ break;
+ }
+
+ // Finish the CRC32 calculation.
+ coder->crc32 = lzma_crc32(out + out_start,
+ *out_pos - out_start, coder->crc32);
+
+ coder->sequence = SEQ_CRC32;
+
+ // Fall through
+
+ case SEQ_CRC32:
+ // We don't use the main loop, because we don't want
+ // coder->crc32 to be touched anymore.
+ do {
+ if (*out_pos == out_size)
+ return LZMA_OK;
+
+ out[*out_pos] = (coder->crc32 >> (coder->pos * 8))
+ & 0xFF;
+ ++*out_pos;
+
+ } while (++coder->pos < 4);
+
+ return LZMA_STREAM_END;
+
+ default:
+ assert(0);
+ return LZMA_PROG_ERROR;
+ }
+
+out:
+ // Update the CRC32.
+ coder->crc32 = lzma_crc32(out + out_start,
+ *out_pos - out_start, coder->crc32);
+
+ return ret;
+}
+
+
+static void
+index_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static void
+index_encoder_reset(lzma_coder *coder, const lzma_index *i)
+{
+ lzma_index_iter_init(&coder->iter, i);
+
+ coder->sequence = SEQ_INDICATOR;
+ coder->index = i;
+ coder->pos = 0;
+ coder->crc32 = 0;
+
+ return;
+}
+
+
+extern lzma_ret
+lzma_index_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_index *i)
+{
+ lzma_next_coder_init(&lzma_index_encoder_init, next, allocator);
+
+ if (i == NULL)
+ return LZMA_PROG_ERROR;
+
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &index_encode;
+ next->end = &index_encoder_end;
+ }
+
+ index_encoder_reset(next->coder, i);
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_encoder(lzma_stream *strm, const lzma_index *i)
+{
+ lzma_next_strm_init1(lzma_index_encoder_init, strm, i);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_buffer_encode(const lzma_index *i,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ lzma_coder coder;
+ size_t out_start;
+ lzma_ret ret;
+
+ // Validate the arguments.
+ if (i == NULL || out == NULL || out_pos == NULL || *out_pos > out_size)
+ return LZMA_PROG_ERROR;
+
+ // Don't try to encode if there's not enough output space.
+ if (out_size - *out_pos < lzma_index_size(i))
+ return LZMA_BUF_ERROR;
+
+ // The Index encoder needs just one small data structure so we can
+ // allocate it on stack.
+ index_encoder_reset(&coder, i);
+
+ // Do the actual encoding. This should never fail, but store
+ // the original *out_pos just in case.
+ out_start = *out_pos;
+ ret = index_encode(&coder, NULL, NULL, NULL, 0,
+ out, out_pos, out_size, LZMA_RUN);
+
+ if (ret == LZMA_STREAM_END) {
+ ret = LZMA_OK;
+ } else {
+ // We should never get here, but just in case, restore the
+ // output position and set the error accordingly if something
+ // goes wrong and debugging isn't enabled.
+ assert(0);
+ *out_pos = out_start;
+ ret = LZMA_PROG_ERROR;
+ }
+
+ return ret;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/index_encoder.h b/Utilities/cmliblzma/liblzma/common/index_encoder.h
new file mode 100644
index 0000000000..a13c94dcd0
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/index_encoder.h
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file index_encoder.h
+/// \brief Encodes the Index field
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_INDEX_ENCODER_H
+#define LZMA_INDEX_ENCODER_H
+
+#include "common.h"
+
+
+extern lzma_ret lzma_index_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_index *i);
+
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/index_hash.c b/Utilities/cmliblzma/liblzma/common/index_hash.c
new file mode 100644
index 0000000000..0cf86b3070
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/index_hash.c
@@ -0,0 +1,336 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file index_hash.c
+/// \brief Validates Index by using a hash function
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+#include "index.h"
+#include "check.h"
+
+
+typedef struct {
+ /// Sum of the Block sizes (including Block Padding)
+ lzma_vli blocks_size;
+
+ /// Sum of the Uncompressed Size fields
+ lzma_vli uncompressed_size;
+
+ /// Number of Records
+ lzma_vli count;
+
+ /// Size of the List of Index Records as bytes
+ lzma_vli index_list_size;
+
+ /// Check calculated from Unpadded Sizes and Uncompressed Sizes.
+ lzma_check_state check;
+
+} lzma_index_hash_info;
+
+
+struct lzma_index_hash_s {
+ enum {
+ SEQ_BLOCK,
+ SEQ_COUNT,
+ SEQ_UNPADDED,
+ SEQ_UNCOMPRESSED,
+ SEQ_PADDING_INIT,
+ SEQ_PADDING,
+ SEQ_CRC32,
+ } sequence;
+
+ /// Information collected while decoding the actual Blocks.
+ lzma_index_hash_info blocks;
+
+ /// Information collected from the Index field.
+ lzma_index_hash_info records;
+
+ /// Number of Records not fully decoded
+ lzma_vli remaining;
+
+ /// Unpadded Size currently being read from an Index Record.
+ lzma_vli unpadded_size;
+
+ /// Uncompressed Size currently being read from an Index Record.
+ lzma_vli uncompressed_size;
+
+ /// Position in variable-length integers when decoding them from
+ /// the List of Records.
+ size_t pos;
+
+ /// CRC32 of the Index
+ uint32_t crc32;
+};
+
+
+extern LZMA_API(lzma_index_hash *)
+lzma_index_hash_init(lzma_index_hash *index_hash, lzma_allocator *allocator)
+{
+ if (index_hash == NULL) {
+ index_hash = lzma_alloc(sizeof(lzma_index_hash), allocator);
+ if (index_hash == NULL)
+ return NULL;
+ }
+
+ index_hash->sequence = SEQ_BLOCK;
+ index_hash->blocks.blocks_size = 0;
+ index_hash->blocks.uncompressed_size = 0;
+ index_hash->blocks.count = 0;
+ index_hash->blocks.index_list_size = 0;
+ index_hash->records.blocks_size = 0;
+ index_hash->records.uncompressed_size = 0;
+ index_hash->records.count = 0;
+ index_hash->records.index_list_size = 0;
+ index_hash->unpadded_size = 0;
+ index_hash->uncompressed_size = 0;
+ index_hash->pos = 0;
+ index_hash->crc32 = 0;
+
+ // These cannot fail because LZMA_CHECK_BEST is known to be supported.
+ (void)lzma_check_init(&index_hash->blocks.check, LZMA_CHECK_BEST);
+ (void)lzma_check_init(&index_hash->records.check, LZMA_CHECK_BEST);
+
+ return index_hash;
+}
+
+
+extern LZMA_API(void)
+lzma_index_hash_end(lzma_index_hash *index_hash, lzma_allocator *allocator)
+{
+ lzma_free(index_hash, allocator);
+ return;
+}
+
+
+extern LZMA_API(lzma_vli)
+lzma_index_hash_size(const lzma_index_hash *index_hash)
+{
+ // Get the size of the Index from ->blocks instead of ->records for
+ // cases where application wants to know the Index Size before
+ // decoding the Index.
+ return index_size(index_hash->blocks.count,
+ index_hash->blocks.index_list_size);
+}
+
+
+/// Updates the sizes and the hash without any validation.
+static lzma_ret
+hash_append(lzma_index_hash_info *info, lzma_vli unpadded_size,
+ lzma_vli uncompressed_size)
+{
+ const lzma_vli sizes[2] = { unpadded_size, uncompressed_size };
+
+ info->blocks_size += vli_ceil4(unpadded_size);
+ info->uncompressed_size += uncompressed_size;
+ info->index_list_size += lzma_vli_size(unpadded_size)
+ + lzma_vli_size(uncompressed_size);
+ ++info->count;
+
+ lzma_check_update(&info->check, LZMA_CHECK_BEST,
+ (const uint8_t *)(sizes), sizeof(sizes));
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_hash_append(lzma_index_hash *index_hash, lzma_vli unpadded_size,
+ lzma_vli uncompressed_size)
+{
+ // Validate the arguments.
+ if (index_hash->sequence != SEQ_BLOCK
+ || unpadded_size < UNPADDED_SIZE_MIN
+ || unpadded_size > UNPADDED_SIZE_MAX
+ || uncompressed_size > LZMA_VLI_MAX)
+ return LZMA_PROG_ERROR;
+
+ // Update the hash.
+ return_if_error(hash_append(&index_hash->blocks,
+ unpadded_size, uncompressed_size));
+
+ // Validate the properties of *info are still in allowed limits.
+ if (index_hash->blocks.blocks_size > LZMA_VLI_MAX
+ || index_hash->blocks.uncompressed_size > LZMA_VLI_MAX
+ || index_size(index_hash->blocks.count,
+ index_hash->blocks.index_list_size)
+ > LZMA_BACKWARD_SIZE_MAX
+ || index_stream_size(index_hash->blocks.blocks_size,
+ index_hash->blocks.count,
+ index_hash->blocks.index_list_size)
+ > LZMA_VLI_MAX)
+ return LZMA_DATA_ERROR;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_index_hash_decode(lzma_index_hash *index_hash, const uint8_t *in,
+ size_t *in_pos, size_t in_size)
+{
+ size_t in_start;
+ lzma_ret ret;
+
+ // Catch zero input buffer here, because in contrast to Index encoder
+ // and decoder functions, applications call this function directly
+ // instead of via lzma_code(), which does the buffer checking.
+ if (*in_pos >= in_size)
+ return LZMA_BUF_ERROR;
+
+ // NOTE: This function has many similarities to index_encode() and
+ // index_decode() functions found from index_encoder.c and
+ // index_decoder.c. See the comments especially in index_encoder.c.
+ in_start = *in_pos;
+ ret = LZMA_OK;
+
+ while (*in_pos < in_size)
+ switch (index_hash->sequence) {
+ case SEQ_BLOCK:
+ // Check the Index Indicator is present.
+ if (in[(*in_pos)++] != 0x00)
+ return LZMA_DATA_ERROR;
+
+ index_hash->sequence = SEQ_COUNT;
+ break;
+
+ case SEQ_COUNT: {
+ ret = lzma_vli_decode(&index_hash->remaining,
+ &index_hash->pos, in, in_pos, in_size);
+ if (ret != LZMA_STREAM_END)
+ goto out;
+
+ // The count must match the count of the Blocks decoded.
+ if (index_hash->remaining != index_hash->blocks.count)
+ return LZMA_DATA_ERROR;
+
+ ret = LZMA_OK;
+ index_hash->pos = 0;
+
+ // Handle the special case when there are no Blocks.
+ index_hash->sequence = index_hash->remaining == 0
+ ? SEQ_PADDING_INIT : SEQ_UNPADDED;
+ break;
+ }
+
+ case SEQ_UNPADDED:
+ case SEQ_UNCOMPRESSED: {
+ lzma_vli *size = index_hash->sequence == SEQ_UNPADDED
+ ? &index_hash->unpadded_size
+ : &index_hash->uncompressed_size;
+
+ ret = lzma_vli_decode(size, &index_hash->pos,
+ in, in_pos, in_size);
+ if (ret != LZMA_STREAM_END)
+ goto out;
+
+ ret = LZMA_OK;
+ index_hash->pos = 0;
+
+ if (index_hash->sequence == SEQ_UNPADDED) {
+ if (index_hash->unpadded_size < UNPADDED_SIZE_MIN
+ || index_hash->unpadded_size
+ > UNPADDED_SIZE_MAX)
+ return LZMA_DATA_ERROR;
+
+ index_hash->sequence = SEQ_UNCOMPRESSED;
+ } else {
+ // Update the hash.
+ return_if_error(hash_append(&index_hash->records,
+ index_hash->unpadded_size,
+ index_hash->uncompressed_size));
+
+ // Verify that we don't go over the known sizes. Note
+ // that this validation is simpler than the one used
+ // in lzma_index_hash_append(), because here we know
+ // that values in index_hash->blocks are already
+ // validated and we are fine as long as we don't
+ // exceed them in index_hash->records.
+ if (index_hash->blocks.blocks_size
+ < index_hash->records.blocks_size
+ || index_hash->blocks.uncompressed_size
+ < index_hash->records.uncompressed_size
+ || index_hash->blocks.index_list_size
+ < index_hash->records.index_list_size)
+ return LZMA_DATA_ERROR;
+
+ // Check if this was the last Record.
+ index_hash->sequence = --index_hash->remaining == 0
+ ? SEQ_PADDING_INIT : SEQ_UNPADDED;
+ }
+
+ break;
+ }
+
+ case SEQ_PADDING_INIT:
+ index_hash->pos = (LZMA_VLI_C(4) - index_size_unpadded(
+ index_hash->records.count,
+ index_hash->records.index_list_size)) & 3;
+ index_hash->sequence = SEQ_PADDING;
+
+ // Fall through
+
+ case SEQ_PADDING:
+ if (index_hash->pos > 0) {
+ --index_hash->pos;
+ if (in[(*in_pos)++] != 0x00)
+ return LZMA_DATA_ERROR;
+
+ break;
+ }
+
+ // Compare the sizes.
+ if (index_hash->blocks.blocks_size
+ != index_hash->records.blocks_size
+ || index_hash->blocks.uncompressed_size
+ != index_hash->records.uncompressed_size
+ || index_hash->blocks.index_list_size
+ != index_hash->records.index_list_size)
+ return LZMA_DATA_ERROR;
+
+ // Finish the hashes and compare them.
+ lzma_check_finish(&index_hash->blocks.check, LZMA_CHECK_BEST);
+ lzma_check_finish(&index_hash->records.check, LZMA_CHECK_BEST);
+ if (memcmp(index_hash->blocks.check.buffer.u8,
+ index_hash->records.check.buffer.u8,
+ lzma_check_size(LZMA_CHECK_BEST)) != 0)
+ return LZMA_DATA_ERROR;
+
+ // Finish the CRC32 calculation.
+ index_hash->crc32 = lzma_crc32(in + in_start,
+ *in_pos - in_start, index_hash->crc32);
+
+ index_hash->sequence = SEQ_CRC32;
+
+ // Fall through
+
+ case SEQ_CRC32:
+ do {
+ if (*in_pos == in_size)
+ return LZMA_OK;
+
+ if (((index_hash->crc32 >> (index_hash->pos * 8))
+ & 0xFF) != in[(*in_pos)++])
+ return LZMA_DATA_ERROR;
+
+ } while (++index_hash->pos < 4);
+
+ return LZMA_STREAM_END;
+
+ default:
+ assert(0);
+ return LZMA_PROG_ERROR;
+ }
+
+out:
+ // Update the CRC32,
+ index_hash->crc32 = lzma_crc32(in + in_start,
+ *in_pos - in_start, index_hash->crc32);
+
+ return ret;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c b/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c
new file mode 100644
index 0000000000..9e2e1da83e
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c
@@ -0,0 +1,93 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_buffer_decoder.c
+/// \brief Single-call .xz Stream decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "stream_decoder.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_stream_buffer_decode(uint64_t *memlimit, uint32_t flags,
+ lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ lzma_next_coder stream_decoder = LZMA_NEXT_CODER_INIT;
+ lzma_ret ret;
+
+ // Sanity checks
+ if (in_pos == NULL || (in == NULL && *in_pos != in_size)
+ || *in_pos > in_size || out_pos == NULL
+ || (out == NULL && *out_pos != out_size)
+ || *out_pos > out_size)
+ return LZMA_PROG_ERROR;
+
+ // Catch flags that are not allowed in buffer-to-buffer decoding.
+ if (flags & LZMA_TELL_ANY_CHECK)
+ return LZMA_PROG_ERROR;
+
+ // Initialize the Stream decoder.
+ // TODO: We need something to tell the decoder that it can use the
+ // output buffer as workspace, and thus save significant amount of RAM.
+ ret = lzma_stream_decoder_init(
+ &stream_decoder, allocator, *memlimit, flags);
+
+ if (ret == LZMA_OK) {
+ // Save the positions so that we can restore them in case
+ // an error occurs.
+ const size_t in_start = *in_pos;
+ const size_t out_start = *out_pos;
+
+ // Do the actual decoding.
+ ret = stream_decoder.code(stream_decoder.coder, allocator,
+ in, in_pos, in_size, out, out_pos, out_size,
+ LZMA_FINISH);
+
+ if (ret == LZMA_STREAM_END) {
+ ret = LZMA_OK;
+ } else {
+ // Something went wrong, restore the positions.
+ *in_pos = in_start;
+ *out_pos = out_start;
+
+ if (ret == LZMA_OK) {
+ // Either the input was truncated or the
+ // output buffer was too small.
+ assert(*in_pos == in_size
+ || *out_pos == out_size);
+
+ // If all the input was consumed, then the
+ // input is truncated, even if the output
+ // buffer is also full. This is because
+ // processing the last byte of the Stream
+ // never produces output.
+ if (*in_pos == in_size)
+ ret = LZMA_DATA_ERROR;
+ else
+ ret = LZMA_BUF_ERROR;
+
+ } else if (ret == LZMA_MEMLIMIT_ERROR) {
+ // Let the caller know how much memory would
+ // have been needed.
+ uint64_t memusage;
+ (void)stream_decoder.memconfig(
+ stream_decoder.coder,
+ memlimit, &memusage, 0);
+ }
+ }
+ }
+
+ // Free the decoder memory. This needs to be done even if
+ // initialization fails, because the internal API doesn't
+ // require the initialization function to free its memory on error.
+ lzma_next_end(&stream_decoder, allocator);
+
+ return ret;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c
new file mode 100644
index 0000000000..8bca87f475
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c
@@ -0,0 +1,140 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_buffer_encoder.c
+/// \brief Single-call .xz Stream encoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "index.h"
+
+
+/// Maximum size of Index that has exactly one Record.
+/// Index Indicator + Number of Records + Record + CRC32 rounded up to
+/// the next multiple of four.
+#define INDEX_BOUND ((1 + 1 + 2 * LZMA_VLI_BYTES_MAX + 4 + 3) & ~3)
+
+/// Stream Header, Stream Footer, and Index
+#define HEADERS_BOUND (2 * LZMA_STREAM_HEADER_SIZE + INDEX_BOUND)
+
+
+extern LZMA_API(size_t)
+lzma_stream_buffer_bound(size_t uncompressed_size)
+{
+ // Get the maximum possible size of a Block.
+ const size_t block_bound = lzma_block_buffer_bound(uncompressed_size);
+ if (block_bound == 0)
+ return 0;
+
+ // Catch the possible integer overflow and also prevent the size of
+ // the Stream exceeding LZMA_VLI_MAX (theoretically possible on
+ // 64-bit systems).
+ if (my_min(SIZE_MAX, LZMA_VLI_MAX) - block_bound < HEADERS_BOUND)
+ return 0;
+
+ return block_bound + HEADERS_BOUND;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
+ lzma_allocator *allocator, const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos_ptr, size_t out_size)
+{
+ lzma_stream_flags stream_flags = { 0 };
+ lzma_block block = { 0 };
+ size_t out_pos;
+
+ // Sanity checks
+ if (filters == NULL || (unsigned int)(check) > LZMA_CHECK_ID_MAX
+ || (in == NULL && in_size != 0) || out == NULL
+ || out_pos_ptr == NULL || *out_pos_ptr > out_size)
+ return LZMA_PROG_ERROR;
+
+ if (!lzma_check_is_supported(check))
+ return LZMA_UNSUPPORTED_CHECK;
+
+ // Note for the paranoids: Index encoder prevents the Stream from
+ // getting too big and still being accepted with LZMA_OK, and Block
+ // encoder catches if the input is too big. So we don't need to
+ // separately check if the buffers are too big.
+
+ // Use a local copy. We update *out_pos_ptr only if everything
+ // succeeds.
+ out_pos = *out_pos_ptr;
+
+ // Check that there's enough space for both Stream Header and
+ // Stream Footer.
+ if (out_size - out_pos <= 2 * LZMA_STREAM_HEADER_SIZE)
+ return LZMA_BUF_ERROR;
+
+ // Reserve space for Stream Footer so we don't need to check for
+ // available space again before encoding Stream Footer.
+ out_size -= LZMA_STREAM_HEADER_SIZE;
+
+ // Encode the Stream Header.
+ stream_flags.check = check;
+
+ if (lzma_stream_header_encode(&stream_flags, out + out_pos)
+ != LZMA_OK)
+ return LZMA_PROG_ERROR;
+
+ out_pos += LZMA_STREAM_HEADER_SIZE;
+
+ // Encode a Block but only if there is at least one byte of input.
+ block.check = check;
+ block.filters = filters;
+
+ if (in_size > 0)
+ return_if_error(lzma_block_buffer_encode(&block, allocator,
+ in, in_size, out, &out_pos, out_size));
+
+ // Index
+ {
+ lzma_ret ret;
+
+ // Create an Index. It will have one Record if there was
+ // at least one byte of input to encode. Otherwise the
+ // Index will be empty.
+ lzma_index *i = lzma_index_init(allocator);
+ if (i == NULL)
+ return LZMA_MEM_ERROR;
+
+ ret = LZMA_OK;
+
+ if (in_size > 0)
+ ret = lzma_index_append(i, allocator,
+ lzma_block_unpadded_size(&block),
+ block.uncompressed_size);
+
+ // If adding the Record was successful, encode the Index
+ // and get its size which will be stored into Stream Footer.
+ if (ret == LZMA_OK) {
+ ret = lzma_index_buffer_encode(
+ i, out, &out_pos, out_size);
+
+ stream_flags.backward_size = lzma_index_size(i);
+ }
+
+ lzma_index_end(i, allocator);
+
+ if (ret != LZMA_OK)
+ return ret;
+ }
+
+ // Stream Footer. We have already reserved space for this.
+ if (lzma_stream_footer_encode(&stream_flags, out + out_pos)
+ != LZMA_OK)
+ return LZMA_PROG_ERROR;
+
+ out_pos += LZMA_STREAM_HEADER_SIZE;
+
+ // Everything went fine, make the new output position available
+ // to the application.
+ *out_pos_ptr = out_pos;
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/stream_decoder.c b/Utilities/cmliblzma/liblzma/common/stream_decoder.c
new file mode 100644
index 0000000000..5e9a220699
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_decoder.c
@@ -0,0 +1,459 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_decoder.c
+/// \brief Decodes .xz Streams
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "stream_decoder.h"
+#include "block_decoder.h"
+
+
+struct lzma_coder_s {
+ enum {
+ SEQ_STREAM_HEADER,
+ SEQ_BLOCK_HEADER,
+ SEQ_BLOCK,
+ SEQ_INDEX,
+ SEQ_STREAM_FOOTER,
+ SEQ_STREAM_PADDING,
+ } sequence;
+
+ /// Block or Metadata decoder. This takes little memory and the same
+ /// data structure can be used to decode every Block Header, so it's
+ /// a good idea to have a separate lzma_next_coder structure for it.
+ lzma_next_coder block_decoder;
+
+ /// Block options decoded by the Block Header decoder and used by
+ /// the Block decoder.
+ lzma_block block_options;
+
+ /// Stream Flags from Stream Header
+ lzma_stream_flags stream_flags;
+
+ /// Index is hashed so that it can be compared to the sizes of Blocks
+ /// with O(1) memory usage.
+ lzma_index_hash *index_hash;
+
+ /// Memory usage limit
+ uint64_t memlimit;
+
+ /// Amount of memory actually needed (only an estimate)
+ uint64_t memusage;
+
+ /// If true, LZMA_NO_CHECK is returned if the Stream has
+ /// no integrity check.
+ bool tell_no_check;
+
+ /// If true, LZMA_UNSUPPORTED_CHECK is returned if the Stream has
+ /// an integrity check that isn't supported by this liblzma build.
+ bool tell_unsupported_check;
+
+ /// If true, LZMA_GET_CHECK is returned after decoding Stream Header.
+ bool tell_any_check;
+
+ /// If true, we will decode concatenated Streams that possibly have
+ /// Stream Padding between or after them. LZMA_STREAM_END is returned
+ /// once the application isn't giving us any new input, and we aren't
+ /// in the middle of a Stream, and possible Stream Padding is a
+ /// multiple of four bytes.
+ bool concatenated;
+
+ /// When decoding concatenated Streams, this is true as long as we
+ /// are decoding the first Stream. This is needed to avoid misleading
+ /// LZMA_FORMAT_ERROR in case the later Streams don't have valid magic
+ /// bytes.
+ bool first_stream;
+
+ /// Write position in buffer[] and position in Stream Padding
+ size_t pos;
+
+ /// Buffer to hold Stream Header, Block Header, and Stream Footer.
+ /// Block Header has biggest maximum size.
+ uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX];
+};
+
+
+static lzma_ret
+stream_decoder_reset(lzma_coder *coder, lzma_allocator *allocator)
+{
+ // Initialize the Index hash used to verify the Index.
+ coder->index_hash = lzma_index_hash_init(coder->index_hash, allocator);
+ if (coder->index_hash == NULL)
+ return LZMA_MEM_ERROR;
+
+ // Reset the rest of the variables.
+ coder->sequence = SEQ_STREAM_HEADER;
+ coder->pos = 0;
+
+ return LZMA_OK;
+}
+
+
+static lzma_ret
+stream_decode(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
+{
+ // When decoding the actual Block, it may be able to produce more
+ // output even if we don't give it any new input.
+ while (true)
+ switch (coder->sequence) {
+ case SEQ_STREAM_HEADER: {
+ lzma_ret ret;
+
+ // Copy the Stream Header to the internal buffer.
+ lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos,
+ LZMA_STREAM_HEADER_SIZE);
+
+ // Return if we didn't get the whole Stream Header yet.
+ if (coder->pos < LZMA_STREAM_HEADER_SIZE)
+ return LZMA_OK;
+
+ coder->pos = 0;
+
+ // Decode the Stream Header.
+ ret = lzma_stream_header_decode(
+ &coder->stream_flags, coder->buffer);
+ if (ret != LZMA_OK)
+ return ret == LZMA_FORMAT_ERROR && !coder->first_stream
+ ? LZMA_DATA_ERROR : ret;
+
+ // If we are decoding concatenated Streams, and the later
+ // Streams have invalid Header Magic Bytes, we give
+ // LZMA_DATA_ERROR instead of LZMA_FORMAT_ERROR.
+ coder->first_stream = false;
+
+ // Copy the type of the Check so that Block Header and Block
+ // decoders see it.
+ coder->block_options.check = coder->stream_flags.check;
+
+ // Even if we return LZMA_*_CHECK below, we want
+ // to continue from Block Header decoding.
+ coder->sequence = SEQ_BLOCK_HEADER;
+
+ // Detect if there's no integrity check or if it is
+ // unsupported if those were requested by the application.
+ if (coder->tell_no_check && coder->stream_flags.check
+ == LZMA_CHECK_NONE)
+ return LZMA_NO_CHECK;
+
+ if (coder->tell_unsupported_check
+ && !lzma_check_is_supported(
+ coder->stream_flags.check))
+ return LZMA_UNSUPPORTED_CHECK;
+
+ if (coder->tell_any_check)
+ return LZMA_GET_CHECK;
+ }
+
+ // Fall through
+
+ case SEQ_BLOCK_HEADER: {
+ lzma_filter filters[LZMA_FILTERS_MAX + 1];
+ uint64_t memusage;
+ lzma_ret ret;
+ size_t i;
+
+ if (*in_pos >= in_size)
+ return LZMA_OK;
+
+ if (coder->pos == 0) {
+ // Detect if it's Index.
+ if (in[*in_pos] == 0x00) {
+ coder->sequence = SEQ_INDEX;
+ break;
+ }
+
+ // Calculate the size of the Block Header. Note that
+ // Block Header decoder wants to see this byte too
+ // so don't advance *in_pos.
+ coder->block_options.header_size
+ = lzma_block_header_size_decode(
+ in[*in_pos]);
+ }
+
+ // Copy the Block Header to the internal buffer.
+ lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos,
+ coder->block_options.header_size);
+
+ // Return if we didn't get the whole Block Header yet.
+ if (coder->pos < coder->block_options.header_size)
+ return LZMA_OK;
+
+ coder->pos = 0;
+
+ // Version 0 is currently the only possible version.
+ coder->block_options.version = 0;
+
+ // Set up a buffer to hold the filter chain. Block Header
+ // decoder will initialize all members of this array so
+ // we don't need to do it here.
+ coder->block_options.filters = filters;
+
+ // Decode the Block Header.
+ return_if_error(lzma_block_header_decode(&coder->block_options,
+ allocator, coder->buffer));
+
+ // Check the memory usage limit.
+ memusage = lzma_raw_decoder_memusage(filters);
+ if (memusage == UINT64_MAX) {
+ // One or more unknown Filter IDs.
+ ret = LZMA_OPTIONS_ERROR;
+ } else {
+ // Now we can set coder->memusage since we know that
+ // the filter chain is valid. We don't want
+ // lzma_memusage() to return UINT64_MAX in case of
+ // invalid filter chain.
+ coder->memusage = memusage;
+
+ if (memusage > coder->memlimit) {
+ // The chain would need too much memory.
+ ret = LZMA_MEMLIMIT_ERROR;
+ } else {
+ // Memory usage is OK.
+ // Initialize the Block decoder.
+ ret = lzma_block_decoder_init(
+ &coder->block_decoder,
+ allocator,
+ &coder->block_options);
+ }
+ }
+
+ // Free the allocated filter options since they are needed
+ // only to initialize the Block decoder.
+ for (i = 0; i < LZMA_FILTERS_MAX; ++i)
+ lzma_free(filters[i].options, allocator);
+
+ coder->block_options.filters = NULL;
+
+ // Check if memory usage calculation and Block enocoder
+ // initialization succeeded.
+ if (ret != LZMA_OK)
+ return ret;
+
+ coder->sequence = SEQ_BLOCK;
+ }
+
+ // Fall through
+
+ case SEQ_BLOCK: {
+ const lzma_ret ret = coder->block_decoder.code(
+ coder->block_decoder.coder, allocator,
+ in, in_pos, in_size, out, out_pos, out_size,
+ action);
+
+ if (ret != LZMA_STREAM_END)
+ return ret;
+
+ // Block decoded successfully. Add the new size pair to
+ // the Index hash.
+ return_if_error(lzma_index_hash_append(coder->index_hash,
+ lzma_block_unpadded_size(
+ &coder->block_options),
+ coder->block_options.uncompressed_size));
+
+ coder->sequence = SEQ_BLOCK_HEADER;
+ break;
+ }
+
+ case SEQ_INDEX: {
+ lzma_ret ret;
+
+ // If we don't have any input, don't call
+ // lzma_index_hash_decode() since it would return
+ // LZMA_BUF_ERROR, which we must not do here.
+ if (*in_pos >= in_size)
+ return LZMA_OK;
+
+ // Decode the Index and compare it to the hash calculated
+ // from the sizes of the Blocks (if any).
+ ret = lzma_index_hash_decode(coder->index_hash,
+ in, in_pos, in_size);
+ if (ret != LZMA_STREAM_END)
+ return ret;
+
+ coder->sequence = SEQ_STREAM_FOOTER;
+ }
+
+ // Fall through
+
+ case SEQ_STREAM_FOOTER: {
+ lzma_stream_flags footer_flags;
+ lzma_ret ret;
+
+ // Copy the Stream Footer to the internal buffer.
+ lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos,
+ LZMA_STREAM_HEADER_SIZE);
+
+ // Return if we didn't get the whole Stream Footer yet.
+ if (coder->pos < LZMA_STREAM_HEADER_SIZE)
+ return LZMA_OK;
+
+ coder->pos = 0;
+
+ // Decode the Stream Footer. The decoder gives
+ // LZMA_FORMAT_ERROR if the magic bytes don't match,
+ // so convert that return code to LZMA_DATA_ERROR.
+ ret = lzma_stream_footer_decode(
+ &footer_flags, coder->buffer);
+ if (ret != LZMA_OK)
+ return ret == LZMA_FORMAT_ERROR
+ ? LZMA_DATA_ERROR : ret;
+
+ // Check that Index Size stored in the Stream Footer matches
+ // the real size of the Index field.
+ if (lzma_index_hash_size(coder->index_hash)
+ != footer_flags.backward_size)
+ return LZMA_DATA_ERROR;
+
+ // Compare that the Stream Flags fields are identical in
+ // both Stream Header and Stream Footer.
+ return_if_error(lzma_stream_flags_compare(
+ &coder->stream_flags, &footer_flags));
+
+ if (!coder->concatenated)
+ return LZMA_STREAM_END;
+
+ coder->sequence = SEQ_STREAM_PADDING;
+ }
+
+ // Fall through
+
+ case SEQ_STREAM_PADDING:
+ assert(coder->concatenated);
+
+ // Skip over possible Stream Padding.
+ while (true) {
+ if (*in_pos >= in_size) {
+ // Unless LZMA_FINISH was used, we cannot
+ // know if there's more input coming later.
+ if (action != LZMA_FINISH)
+ return LZMA_OK;
+
+ // Stream Padding must be a multiple of
+ // four bytes.
+ return coder->pos == 0
+ ? LZMA_STREAM_END
+ : LZMA_DATA_ERROR;
+ }
+
+ // If the byte is not zero, it probably indicates
+ // beginning of a new Stream (or the file is corrupt).
+ if (in[*in_pos] != 0x00)
+ break;
+
+ ++*in_pos;
+ coder->pos = (coder->pos + 1) & 3;
+ }
+
+ // Stream Padding must be a multiple of four bytes (empty
+ // Stream Padding is OK).
+ if (coder->pos != 0) {
+ ++*in_pos;
+ return LZMA_DATA_ERROR;
+ }
+
+ // Prepare to decode the next Stream.
+ return_if_error(stream_decoder_reset(coder, allocator));
+ break;
+
+ default:
+ assert(0);
+ return LZMA_PROG_ERROR;
+ }
+
+ // Never reached
+}
+
+
+static void
+stream_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->block_decoder, allocator);
+ lzma_index_hash_end(coder->index_hash, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static lzma_check
+stream_decoder_get_check(const lzma_coder *coder)
+{
+ return coder->stream_flags.check;
+}
+
+
+static lzma_ret
+stream_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
+ uint64_t *old_memlimit, uint64_t new_memlimit)
+{
+ *memusage = coder->memusage;
+ *old_memlimit = coder->memlimit;
+
+ if (new_memlimit != 0) {
+ if (new_memlimit < coder->memusage)
+ return LZMA_MEMLIMIT_ERROR;
+
+ coder->memlimit = new_memlimit;
+ }
+
+ return LZMA_OK;
+}
+
+
+extern lzma_ret
+lzma_stream_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ uint64_t memlimit, uint32_t flags)
+{
+ lzma_next_coder_init(&lzma_stream_decoder_init, next, allocator);
+
+ if (memlimit == 0)
+ return LZMA_PROG_ERROR;
+
+ if (flags & ~LZMA_SUPPORTED_FLAGS)
+ return LZMA_OPTIONS_ERROR;
+
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &stream_decode;
+ next->end = &stream_decoder_end;
+ next->get_check = &stream_decoder_get_check;
+ next->memconfig = &stream_decoder_memconfig;
+
+ next->coder->block_decoder = LZMA_NEXT_CODER_INIT;
+ next->coder->index_hash = NULL;
+ }
+
+ next->coder->memlimit = memlimit;
+ next->coder->memusage = LZMA_MEMUSAGE_BASE;
+ next->coder->tell_no_check = (flags & LZMA_TELL_NO_CHECK) != 0;
+ next->coder->tell_unsupported_check
+ = (flags & LZMA_TELL_UNSUPPORTED_CHECK) != 0;
+ next->coder->tell_any_check = (flags & LZMA_TELL_ANY_CHECK) != 0;
+ next->coder->concatenated = (flags & LZMA_CONCATENATED) != 0;
+ next->coder->first_stream = true;
+
+ return stream_decoder_reset(next->coder, allocator);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_stream_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags)
+{
+ lzma_next_strm_init2(lzma_stream_decoder_init, strm, memlimit, flags);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/stream_decoder.h b/Utilities/cmliblzma/liblzma/common/stream_decoder.h
new file mode 100644
index 0000000000..e54ac28f44
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_decoder.h
@@ -0,0 +1,21 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_decoder.h
+/// \brief Decodes .xz Streams
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_STREAM_DECODER_H
+#define LZMA_STREAM_DECODER_H
+
+#include "common.h"
+
+extern lzma_ret lzma_stream_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, uint64_t memlimit, uint32_t flags);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/stream_encoder.c b/Utilities/cmliblzma/liblzma/common/stream_encoder.c
new file mode 100644
index 0000000000..1ba45acec7
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_encoder.c
@@ -0,0 +1,338 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_encoder.c
+/// \brief Encodes .xz Streams
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "stream_encoder.h"
+#include "block_encoder.h"
+#include "index_encoder.h"
+
+
+struct lzma_coder_s {
+ enum {
+ SEQ_STREAM_HEADER,
+ SEQ_BLOCK_INIT,
+ SEQ_BLOCK_HEADER,
+ SEQ_BLOCK_ENCODE,
+ SEQ_INDEX_ENCODE,
+ SEQ_STREAM_FOOTER,
+ } sequence;
+
+ /// True if Block encoder has been initialized by
+ /// lzma_stream_encoder_init() or stream_encoder_update()
+ /// and thus doesn't need to be initialized in stream_encode().
+ bool block_encoder_is_initialized;
+
+ /// Block
+ lzma_next_coder block_encoder;
+
+ /// Options for the Block encoder
+ lzma_block block_options;
+
+ /// The filter chain currently in use
+ lzma_filter filters[LZMA_FILTERS_MAX + 1];
+
+ /// Index encoder. This is separate from Block encoder, because this
+ /// doesn't take much memory, and when encoding multiple Streams
+ /// with the same encoding options we avoid reallocating memory.
+ lzma_next_coder index_encoder;
+
+ /// Index to hold sizes of the Blocks
+ lzma_index *index;
+
+ /// Read position in buffer[]
+ size_t buffer_pos;
+
+ /// Total number of bytes in buffer[]
+ size_t buffer_size;
+
+ /// Buffer to hold Stream Header, Block Header, and Stream Footer.
+ /// Block Header has biggest maximum size.
+ uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX];
+};
+
+
+static lzma_ret
+block_encoder_init(lzma_coder *coder, lzma_allocator *allocator)
+{
+ // Prepare the Block options. Even though Block encoder doesn't need
+ // compressed_size, uncompressed_size, and header_size to be
+ // initialized, it is a good idea to do it here, because this way
+ // we catch if someone gave us Filter ID that cannot be used in
+ // Blocks/Streams.
+ coder->block_options.compressed_size = LZMA_VLI_UNKNOWN;
+ coder->block_options.uncompressed_size = LZMA_VLI_UNKNOWN;
+
+ return_if_error(lzma_block_header_size(&coder->block_options));
+
+ // Initialize the actual Block encoder.
+ return lzma_block_encoder_init(&coder->block_encoder, allocator,
+ &coder->block_options);
+}
+
+
+static lzma_ret
+stream_encode(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
+{
+ // Main loop
+ while (*out_pos < out_size)
+ switch (coder->sequence) {
+ case SEQ_STREAM_HEADER:
+ case SEQ_BLOCK_HEADER:
+ case SEQ_STREAM_FOOTER:
+ lzma_bufcpy(coder->buffer, &coder->buffer_pos,
+ coder->buffer_size, out, out_pos, out_size);
+ if (coder->buffer_pos < coder->buffer_size)
+ return LZMA_OK;
+
+ if (coder->sequence == SEQ_STREAM_FOOTER)
+ return LZMA_STREAM_END;
+
+ coder->buffer_pos = 0;
+ ++coder->sequence;
+ break;
+
+ case SEQ_BLOCK_INIT: {
+ if (*in_pos == in_size) {
+ // If we are requested to flush or finish the current
+ // Block, return LZMA_STREAM_END immediately since
+ // there's nothing to do.
+ if (action != LZMA_FINISH)
+ return action == LZMA_RUN
+ ? LZMA_OK : LZMA_STREAM_END;
+
+ // The application had used LZMA_FULL_FLUSH to finish
+ // the previous Block, but now wants to finish without
+ // encoding new data, or it is simply creating an
+ // empty Stream with no Blocks.
+ //
+ // Initialize the Index encoder, and continue to
+ // actually encoding the Index.
+ return_if_error(lzma_index_encoder_init(
+ &coder->index_encoder, allocator,
+ coder->index));
+ coder->sequence = SEQ_INDEX_ENCODE;
+ break;
+ }
+
+ // Initialize the Block encoder unless it was already
+ // initialized by lzma_stream_encoder_init() or
+ // stream_encoder_update().
+ if (!coder->block_encoder_is_initialized)
+ return_if_error(block_encoder_init(coder, allocator));
+
+ // Make it false so that we don't skip the initialization
+ // with the next Block.
+ coder->block_encoder_is_initialized = false;
+
+ // Encode the Block Header. This shouldn't fail since we have
+ // already initialized the Block encoder.
+ if (lzma_block_header_encode(&coder->block_options,
+ coder->buffer) != LZMA_OK)
+ return LZMA_PROG_ERROR;
+
+ coder->buffer_size = coder->block_options.header_size;
+ coder->sequence = SEQ_BLOCK_HEADER;
+ break;
+ }
+
+ case SEQ_BLOCK_ENCODE: {
+ lzma_vli unpadded_size;
+
+ static const lzma_action convert[4] = {
+ LZMA_RUN,
+ LZMA_SYNC_FLUSH,
+ LZMA_FINISH,
+ LZMA_FINISH,
+ };
+
+ const lzma_ret ret = coder->block_encoder.code(
+ coder->block_encoder.coder, allocator,
+ in, in_pos, in_size,
+ out, out_pos, out_size, convert[action]);
+ if (ret != LZMA_STREAM_END || action == LZMA_SYNC_FLUSH)
+ return ret;
+
+ // Add a new Index Record.
+ unpadded_size = lzma_block_unpadded_size(
+ &coder->block_options);
+ assert(unpadded_size != 0);
+ return_if_error(lzma_index_append(coder->index, allocator,
+ unpadded_size,
+ coder->block_options.uncompressed_size));
+
+ coder->sequence = SEQ_BLOCK_INIT;
+ break;
+ }
+
+ case SEQ_INDEX_ENCODE: {
+ const lzma_stream_flags stream_flags = {
+ 0,
+ lzma_index_size(coder->index),
+ coder->block_options.check,
+ };
+
+ // Call the Index encoder. It doesn't take any input, so
+ // those pointers can be NULL.
+ const lzma_ret ret = coder->index_encoder.code(
+ coder->index_encoder.coder, allocator,
+ NULL, NULL, 0,
+ out, out_pos, out_size, LZMA_RUN);
+ if (ret != LZMA_STREAM_END)
+ return ret;
+
+ // Encode the Stream Footer into coder->buffer.
+
+ if (lzma_stream_footer_encode(&stream_flags, coder->buffer)
+ != LZMA_OK)
+ return LZMA_PROG_ERROR;
+
+ coder->buffer_size = LZMA_STREAM_HEADER_SIZE;
+ coder->sequence = SEQ_STREAM_FOOTER;
+ break;
+ }
+
+ default:
+ assert(0);
+ return LZMA_PROG_ERROR;
+ }
+
+ return LZMA_OK;
+}
+
+
+static void
+stream_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ size_t i;
+
+ lzma_next_end(&coder->block_encoder, allocator);
+ lzma_next_end(&coder->index_encoder, allocator);
+ lzma_index_end(coder->index, allocator);
+
+ for (i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i)
+ lzma_free(coder->filters[i].options, allocator);
+
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static lzma_ret
+stream_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
+ const lzma_filter *filters,
+ const lzma_filter *reversed_filters)
+{
+ size_t i;
+
+ if (coder->sequence <= SEQ_BLOCK_INIT) {
+ lzma_ret ret;
+
+ // There is no incomplete Block waiting to be finished,
+ // thus we can change the whole filter chain. Start by
+ // trying to initialize the Block encoder with the new
+ // chain. This way we detect if the chain is valid.
+ coder->block_encoder_is_initialized = false;
+ coder->block_options.filters = (lzma_filter *)(filters);
+ ret = block_encoder_init(coder, allocator);
+ coder->block_options.filters = coder->filters;
+ if (ret != LZMA_OK)
+ return ret;
+
+ coder->block_encoder_is_initialized = true;
+
+ } else if (coder->sequence <= SEQ_BLOCK_ENCODE) {
+ // We are in the middle of a Block. Try to update only
+ // the filter-specific options.
+ return_if_error(coder->block_encoder.update(
+ coder->block_encoder.coder, allocator,
+ filters, reversed_filters));
+ } else {
+ // Trying to update the filter chain when we are already
+ // encoding Index or Stream Footer.
+ return LZMA_PROG_ERROR;
+ }
+
+ // Free the copy of the old chain and make a copy of the new chain.
+ for (i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i)
+ lzma_free(coder->filters[i].options, allocator);
+
+ return lzma_filters_copy(filters, coder->filters, allocator);
+}
+
+
+extern lzma_ret
+lzma_stream_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *filters, lzma_check check)
+{
+ lzma_stream_flags stream_flags = { 0, 0, check };
+
+ lzma_next_coder_init(&lzma_stream_encoder_init, next, allocator);
+
+ if (filters == NULL)
+ return LZMA_PROG_ERROR;
+
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &stream_encode;
+ next->end = &stream_encoder_end;
+ next->update = &stream_encoder_update;
+
+ next->coder->filters[0].id = LZMA_VLI_UNKNOWN;
+ next->coder->block_encoder = LZMA_NEXT_CODER_INIT;
+ next->coder->index_encoder = LZMA_NEXT_CODER_INIT;
+ next->coder->index = NULL;
+ }
+
+ // Basic initializations
+ next->coder->sequence = SEQ_STREAM_HEADER;
+ next->coder->block_options.version = 0;
+ next->coder->block_options.check = check;
+
+ // Initialize the Index
+ lzma_index_end(next->coder->index, allocator);
+ next->coder->index = lzma_index_init(allocator);
+ if (next->coder->index == NULL)
+ return LZMA_MEM_ERROR;
+
+ // Encode the Stream Header
+ return_if_error(lzma_stream_header_encode(
+ &stream_flags, next->coder->buffer));
+
+ next->coder->buffer_pos = 0;
+ next->coder->buffer_size = LZMA_STREAM_HEADER_SIZE;
+
+ // Initialize the Block encoder. This way we detect unsupported
+ // filter chains when initializing the Stream encoder instead of
+ // giving an error after Stream Header has already written out.
+ return stream_encoder_update(
+ next->coder, allocator, filters, NULL);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_stream_encoder(lzma_stream *strm,
+ const lzma_filter *filters, lzma_check check)
+{
+ lzma_next_strm_init2(lzma_stream_encoder_init, strm, filters, check);
+
+ strm->internal->supported_actions[LZMA_RUN] = true;
+ strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
+ strm->internal->supported_actions[LZMA_FULL_FLUSH] = true;
+ strm->internal->supported_actions[LZMA_FINISH] = true;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/stream_encoder.h b/Utilities/cmliblzma/liblzma/common/stream_encoder.h
new file mode 100644
index 0000000000..46a7aed72e
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_encoder.h
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_encoder.h
+/// \brief Encodes .xz Streams
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_STREAM_ENCODER_H
+#define LZMA_STREAM_ENCODER_H
+
+#include "common.h"
+
+
+extern lzma_ret lzma_stream_encoder_init(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *filters, lzma_check check);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/stream_flags_common.c b/Utilities/cmliblzma/liblzma/common/stream_flags_common.c
new file mode 100644
index 0000000000..fbe8eb8abd
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_flags_common.c
@@ -0,0 +1,47 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_flags_common.c
+/// \brief Common stuff for Stream flags coders
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "stream_flags_common.h"
+
+
+const uint8_t lzma_header_magic[6] = { 0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00 };
+const uint8_t lzma_footer_magic[2] = { 0x59, 0x5A };
+
+
+extern LZMA_API(lzma_ret)
+lzma_stream_flags_compare(
+ const lzma_stream_flags *a, const lzma_stream_flags *b)
+{
+ // We can compare only version 0 structures.
+ if (a->version != 0 || b->version != 0)
+ return LZMA_OPTIONS_ERROR;
+
+ // Check type
+ if ((unsigned int)(a->check) > LZMA_CHECK_ID_MAX
+ || (unsigned int)(b->check) > LZMA_CHECK_ID_MAX)
+ return LZMA_PROG_ERROR;
+
+ if (a->check != b->check)
+ return LZMA_DATA_ERROR;
+
+ // Backward Sizes are compared only if they are known in both.
+ if (a->backward_size != LZMA_VLI_UNKNOWN
+ && b->backward_size != LZMA_VLI_UNKNOWN) {
+ if (!is_backward_size_valid(a) || !is_backward_size_valid(b))
+ return LZMA_PROG_ERROR;
+
+ if (a->backward_size != b->backward_size)
+ return LZMA_DATA_ERROR;
+ }
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/stream_flags_common.h b/Utilities/cmliblzma/liblzma/common/stream_flags_common.h
new file mode 100644
index 0000000000..9f3122a3b1
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_flags_common.h
@@ -0,0 +1,33 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_flags_common.h
+/// \brief Common stuff for Stream flags coders
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_STREAM_FLAGS_COMMON_H
+#define LZMA_STREAM_FLAGS_COMMON_H
+
+#include "common.h"
+
+/// Size of the Stream Flags field
+#define LZMA_STREAM_FLAGS_SIZE 2
+
+extern const uint8_t lzma_header_magic[6];
+extern const uint8_t lzma_footer_magic[2];
+
+
+static inline bool
+is_backward_size_valid(const lzma_stream_flags *options)
+{
+ return options->backward_size >= LZMA_BACKWARD_SIZE_MIN
+ && options->backward_size <= LZMA_BACKWARD_SIZE_MAX
+ && (options->backward_size & 3) == 0;
+}
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c b/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c
new file mode 100644
index 0000000000..8cf48a4ca9
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c
@@ -0,0 +1,86 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_flags_decoder.c
+/// \brief Decodes Stream Header and Stream Footer from .xz files
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "stream_flags_common.h"
+
+
+static bool
+stream_flags_decode(lzma_stream_flags *options, const uint8_t *in)
+{
+ // Reserved bits must be unset.
+ if (in[0] != 0x00 || (in[1] & 0xF0))
+ return true;
+
+ options->version = 0;
+ options->check = in[1] & 0x0F;
+
+ return false;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_stream_header_decode(lzma_stream_flags *options, const uint8_t *in)
+{
+ uint32_t crc;
+
+ // Magic
+ if (memcmp(in, lzma_header_magic, sizeof(lzma_header_magic)) != 0)
+ return LZMA_FORMAT_ERROR;
+
+ // Verify the CRC32 so we can distinguish between corrupt
+ // and unsupported files.
+ crc = lzma_crc32(in + sizeof(lzma_header_magic),
+ LZMA_STREAM_FLAGS_SIZE, 0);
+ if (crc != unaligned_read32le(in + sizeof(lzma_header_magic)
+ + LZMA_STREAM_FLAGS_SIZE))
+ return LZMA_DATA_ERROR;
+
+ // Stream Flags
+ if (stream_flags_decode(options, in + sizeof(lzma_header_magic)))
+ return LZMA_OPTIONS_ERROR;
+
+ // Set Backward Size to indicate unknown value. That way
+ // lzma_stream_flags_compare() can be used to compare Stream Header
+ // and Stream Footer while keeping it useful also for comparing
+ // two Stream Footers.
+ options->backward_size = LZMA_VLI_UNKNOWN;
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_stream_footer_decode(lzma_stream_flags *options, const uint8_t *in)
+{
+ uint32_t crc;
+
+ // Magic
+ if (memcmp(in + sizeof(uint32_t) * 2 + LZMA_STREAM_FLAGS_SIZE,
+ lzma_footer_magic, sizeof(lzma_footer_magic)) != 0)
+ return LZMA_FORMAT_ERROR;
+
+ // CRC32
+ crc = lzma_crc32(in + sizeof(uint32_t),
+ sizeof(uint32_t) + LZMA_STREAM_FLAGS_SIZE, 0);
+ if (crc != unaligned_read32le(in))
+ return LZMA_DATA_ERROR;
+
+ // Stream Flags
+ if (stream_flags_decode(options, in + sizeof(uint32_t) * 2))
+ return LZMA_OPTIONS_ERROR;
+
+ // Backward Size
+ options->backward_size = unaligned_read32le(in + sizeof(uint32_t));
+ options->backward_size = (options->backward_size + 1) * 4;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c b/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c
new file mode 100644
index 0000000000..290339e080
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c
@@ -0,0 +1,90 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file stream_flags_encoder.c
+/// \brief Encodes Stream Header and Stream Footer for .xz files
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "stream_flags_common.h"
+
+
+static bool
+stream_flags_encode(const lzma_stream_flags *options, uint8_t *out)
+{
+ if ((unsigned int)(options->check) > LZMA_CHECK_ID_MAX)
+ return true;
+
+ out[0] = 0x00;
+ out[1] = options->check;
+
+ return false;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out)
+{
+ uint32_t crc;
+
+ assert(sizeof(lzma_header_magic) + LZMA_STREAM_FLAGS_SIZE
+ + 4 == LZMA_STREAM_HEADER_SIZE);
+
+ if (options->version != 0)
+ return LZMA_OPTIONS_ERROR;
+
+ // Magic
+ memcpy(out, lzma_header_magic, sizeof(lzma_header_magic));
+
+ // Stream Flags
+ if (stream_flags_encode(options, out + sizeof(lzma_header_magic)))
+ return LZMA_PROG_ERROR;
+
+ // CRC32 of the Stream Header
+ crc = lzma_crc32(out + sizeof(lzma_header_magic),
+ LZMA_STREAM_FLAGS_SIZE, 0);
+
+ unaligned_write32le(out + sizeof(lzma_header_magic)
+ + LZMA_STREAM_FLAGS_SIZE, crc);
+
+ return LZMA_OK;
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_stream_footer_encode(const lzma_stream_flags *options, uint8_t *out)
+{
+ uint32_t crc;
+
+ assert(2 * 4 + LZMA_STREAM_FLAGS_SIZE + sizeof(lzma_footer_magic)
+ == LZMA_STREAM_HEADER_SIZE);
+
+ if (options->version != 0)
+ return LZMA_OPTIONS_ERROR;
+
+ // Backward Size
+ if (!is_backward_size_valid(options))
+ return LZMA_PROG_ERROR;
+
+ unaligned_write32le(out + 4, options->backward_size / 4 - 1);
+
+ // Stream Flags
+ if (stream_flags_encode(options, out + 2 * 4))
+ return LZMA_PROG_ERROR;
+
+ // CRC32
+ crc = lzma_crc32(
+ out + 4, 4 + LZMA_STREAM_FLAGS_SIZE, 0);
+
+ unaligned_write32le(out, crc);
+
+ // Magic
+ memcpy(out + 2 * 4 + LZMA_STREAM_FLAGS_SIZE,
+ lzma_footer_magic, sizeof(lzma_footer_magic));
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/vli_decoder.c b/Utilities/cmliblzma/liblzma/common/vli_decoder.c
new file mode 100644
index 0000000000..1c663844fd
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/vli_decoder.c
@@ -0,0 +1,86 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file vli_decoder.c
+/// \brief Decodes variable-length integers
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_vli_decode(lzma_vli *LZMA_RESTRICT vli, size_t *vli_pos,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size)
+{
+ // If we haven't been given vli_pos, work in single-call mode.
+ size_t vli_pos_internal = 0;
+ if (vli_pos == NULL) {
+ vli_pos = &vli_pos_internal;
+ *vli = 0;
+
+ // If there's no input, use LZMA_DATA_ERROR. This way it is
+ // easy to decode VLIs from buffers that have known size,
+ // and get the correct error code in case the buffer is
+ // too short.
+ if (*in_pos >= in_size)
+ return LZMA_DATA_ERROR;
+
+ } else {
+ // Initialize *vli when starting to decode a new integer.
+ if (*vli_pos == 0)
+ *vli = 0;
+
+ // Validate the arguments.
+ if (*vli_pos >= LZMA_VLI_BYTES_MAX
+ || (*vli >> (*vli_pos * 7)) != 0)
+ return LZMA_PROG_ERROR;;
+
+ if (*in_pos >= in_size)
+ return LZMA_BUF_ERROR;
+ }
+
+ do {
+ // Read the next byte. Use a temporary variable so that we
+ // can update *in_pos immediately.
+ const uint8_t byte = in[*in_pos];
+ ++*in_pos;
+
+ // Add the newly read byte to *vli.
+ *vli += (lzma_vli)(byte & 0x7F) << (*vli_pos * 7);
+ ++*vli_pos;
+
+ // Check if this is the last byte of a multibyte integer.
+ if ((byte & 0x80) == 0) {
+ // We don't allow using variable-length integers as
+ // padding i.e. the encoding must use the most the
+ // compact form.
+ if (byte == 0x00 && *vli_pos > 1)
+ return LZMA_DATA_ERROR;
+
+ return vli_pos == &vli_pos_internal
+ ? LZMA_OK : LZMA_STREAM_END;
+ }
+
+ // There is at least one more byte coming. If we have already
+ // read maximum number of bytes, the integer is considered
+ // corrupt.
+ //
+ // If we need bigger integers in future, old versions liblzma
+ // will confusingly indicate the file being corrupt istead of
+ // unsupported. I suppose it's still better this way, because
+ // in the foreseeable future (writing this in 2008) the only
+ // reason why files would appear having over 63-bit integers
+ // is that the files are simply corrupt.
+ if (*vli_pos == LZMA_VLI_BYTES_MAX)
+ return LZMA_DATA_ERROR;
+
+ } while (*in_pos < in_size);
+
+ return vli_pos == &vli_pos_internal ? LZMA_DATA_ERROR : LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/common/vli_encoder.c b/Utilities/cmliblzma/liblzma/common/vli_encoder.c
new file mode 100644
index 0000000000..09e90cbd71
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/vli_encoder.c
@@ -0,0 +1,69 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file vli_encoder.c
+/// \brief Encodes variable-length integers
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+
+
+extern LZMA_API(lzma_ret)
+lzma_vli_encode(lzma_vli vli, size_t *vli_pos,
+ uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
+ size_t out_size)
+{
+ // If we haven't been given vli_pos, work in single-call mode.
+ size_t vli_pos_internal = 0;
+ if (vli_pos == NULL) {
+ vli_pos = &vli_pos_internal;
+
+ // In single-call mode, we expect that the caller has
+ // reserved enough output space.
+ if (*out_pos >= out_size)
+ return LZMA_PROG_ERROR;
+ } else {
+ // This never happens when we are called by liblzma, but
+ // may happen if called directly from an application.
+ if (*out_pos >= out_size)
+ return LZMA_BUF_ERROR;
+ }
+
+ // Validate the arguments.
+ if (*vli_pos >= LZMA_VLI_BYTES_MAX || vli > LZMA_VLI_MAX)
+ return LZMA_PROG_ERROR;
+
+ // Shift vli so that the next bits to encode are the lowest. In
+ // single-call mode this never changes vli since *vli_pos is zero.
+ vli >>= *vli_pos * 7;
+
+ // Write the non-last bytes in a loop.
+ while (vli >= 0x80) {
+ // We don't need *vli_pos during this function call anymore,
+ // but update it here so that it is ready if we need to
+ // return before the whole integer has been decoded.
+ ++*vli_pos;
+ assert(*vli_pos < LZMA_VLI_BYTES_MAX);
+
+ // Write the next byte.
+ out[*out_pos] = (uint8_t)(vli) | 0x80;
+ vli >>= 7;
+
+ if (++*out_pos == out_size)
+ return vli_pos == &vli_pos_internal
+ ? LZMA_PROG_ERROR : LZMA_OK;
+ }
+
+ // Write the last byte.
+ out[*out_pos] = (uint8_t)(vli);
+ ++*out_pos;
+ ++*vli_pos;
+
+ return vli_pos == &vli_pos_internal ? LZMA_OK : LZMA_STREAM_END;
+
+}
diff --git a/Utilities/cmliblzma/liblzma/common/vli_size.c b/Utilities/cmliblzma/liblzma/common/vli_size.c
new file mode 100644
index 0000000000..8b931e40bb
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/common/vli_size.c
@@ -0,0 +1,31 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file vli_size.c
+/// \brief Calculates the encoded size of a variable-length integer
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+
+
+extern LZMA_API(uint32_t)
+lzma_vli_size(lzma_vli vli)
+{
+ uint32_t i = 0;
+
+ if (vli > LZMA_VLI_MAX)
+ return 0;
+
+ do {
+ vli >>= 7;
+ ++i;
+ } while (vli != 0);
+
+ assert(i <= LZMA_VLI_BYTES_MAX);
+ return i;
+}
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_common.c b/Utilities/cmliblzma/liblzma/delta/delta_common.c
new file mode 100644
index 0000000000..803e674a1e
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/delta/delta_common.c
@@ -0,0 +1,72 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file delta_common.c
+/// \brief Common stuff for Delta encoder and decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "delta_common.h"
+#include "delta_private.h"
+
+
+static void
+delta_coder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->next, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+extern lzma_ret
+lzma_delta_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ const lzma_options_delta *opt;
+
+ // Allocate memory for the decoder if needed.
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ // End function is the same for encoder and decoder.
+ next->end = &delta_coder_end;
+ next->coder->next = LZMA_NEXT_CODER_INIT;
+ }
+
+ // Validate the options.
+ if (lzma_delta_coder_memusage(filters[0].options) == UINT64_MAX)
+ return LZMA_OPTIONS_ERROR;
+
+ // Set the delta distance.
+ opt = filters[0].options;
+ next->coder->distance = opt->dist;
+
+ // Initialize the rest of the variables.
+ next->coder->pos = 0;
+ memzero(next->coder->history, LZMA_DELTA_DIST_MAX);
+
+ // Initialize the next decoder in the chain, if any.
+ return lzma_next_filter_init(&next->coder->next,
+ allocator, filters + 1);
+}
+
+
+extern uint64_t
+lzma_delta_coder_memusage(const void *options)
+{
+ const lzma_options_delta *opt = options;
+
+ if (opt == NULL || opt->type != LZMA_DELTA_TYPE_BYTE
+ || opt->dist < LZMA_DELTA_DIST_MIN
+ || opt->dist > LZMA_DELTA_DIST_MAX)
+ return UINT64_MAX;
+
+ return sizeof(lzma_coder);
+}
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_common.h b/Utilities/cmliblzma/liblzma/delta/delta_common.h
new file mode 100644
index 0000000000..7e7e1baaf6
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/delta/delta_common.h
@@ -0,0 +1,20 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file delta_common.h
+/// \brief Common stuff for Delta encoder and decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_DELTA_COMMON_H
+#define LZMA_DELTA_COMMON_H
+
+#include "common.h"
+
+extern uint64_t lzma_delta_coder_memusage(const void *options);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_decoder.c b/Utilities/cmliblzma/liblzma/delta/delta_decoder.c
new file mode 100644
index 0000000000..28df727354
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/delta/delta_decoder.c
@@ -0,0 +1,79 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file delta_decoder.c
+/// \brief Delta filter decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "delta_decoder.h"
+#include "delta_private.h"
+
+
+static void
+decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
+{
+ size_t i;
+ const size_t distance = coder->distance;
+
+ for (i = 0; i < size; ++i) {
+ buffer[i] += coder->history[(distance + coder->pos) & 0xFF];
+ coder->history[coder->pos-- & 0xFF] = buffer[i];
+ }
+}
+
+
+static lzma_ret
+delta_decode(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
+{
+ const size_t out_start = *out_pos;
+ lzma_ret ret;
+
+ assert(coder->next.code != NULL);
+
+ ret = coder->next.code(coder->next.coder, allocator,
+ in, in_pos, in_size, out, out_pos, out_size,
+ action);
+
+ decode_buffer(coder, out + out_start, *out_pos - out_start);
+
+ return ret;
+}
+
+
+extern lzma_ret
+lzma_delta_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ next->code = &delta_decode;
+ return lzma_delta_coder_init(next, allocator, filters);
+}
+
+
+extern lzma_ret
+lzma_delta_props_decode(void **options, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size)
+{
+ lzma_options_delta *opt;
+
+ if (props_size != 1)
+ return LZMA_OPTIONS_ERROR;
+
+ opt = lzma_alloc(sizeof(lzma_options_delta), allocator);
+ if (opt == NULL)
+ return LZMA_MEM_ERROR;
+
+ opt->type = LZMA_DELTA_TYPE_BYTE;
+ opt->dist = props[0] + 1;
+
+ *options = opt;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_decoder.h b/Utilities/cmliblzma/liblzma/delta/delta_decoder.h
new file mode 100644
index 0000000000..ae89acc59f
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/delta/delta_decoder.h
@@ -0,0 +1,25 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file delta_decoder.h
+/// \brief Delta filter decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_DELTA_DECODER_H
+#define LZMA_DELTA_DECODER_H
+
+#include "delta_common.h"
+
+extern lzma_ret lzma_delta_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern lzma_ret lzma_delta_props_decode(
+ void **options, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_encoder.c b/Utilities/cmliblzma/liblzma/delta/delta_encoder.c
new file mode 100644
index 0000000000..a39c154f12
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/delta/delta_encoder.c
@@ -0,0 +1,124 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file delta_encoder.c
+/// \brief Delta filter encoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "delta_encoder.h"
+#include "delta_private.h"
+
+
+/// Copies and encodes the data at the same time. This is used when Delta
+/// is the first filter in the chain (and thus the last filter in the
+/// encoder's filter stack).
+static void
+copy_and_encode(lzma_coder *coder,
+ const uint8_t *LZMA_RESTRICT in, uint8_t *LZMA_RESTRICT out, size_t size)
+{
+ size_t i;
+ const size_t distance = coder->distance;
+
+ for (i = 0; i < size; ++i) {
+ const uint8_t tmp = coder->history[
+ (distance + coder->pos) & 0xFF];
+ coder->history[coder->pos-- & 0xFF] = in[i];
+ out[i] = in[i] - tmp;
+ }
+}
+
+
+/// Encodes the data in place. This is used when we are the last filter
+/// in the chain (and thus non-last filter in the encoder's filter stack).
+static void
+encode_in_place(lzma_coder *coder, uint8_t *buffer, size_t size)
+{
+ size_t i;
+ const size_t distance = coder->distance;
+
+ for (i = 0; i < size; ++i) {
+ const uint8_t tmp = coder->history[
+ (distance + coder->pos) & 0xFF];
+ coder->history[coder->pos-- & 0xFF] = buffer[i];
+ buffer[i] -= tmp;
+ }
+}
+
+
+static lzma_ret
+delta_encode(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
+{
+ lzma_ret ret;
+
+ if (coder->next.code == NULL) {
+ const size_t in_avail = in_size - *in_pos;
+ const size_t out_avail = out_size - *out_pos;
+ const size_t size = my_min(in_avail, out_avail);
+
+ copy_and_encode(coder, in + *in_pos, out + *out_pos, size);
+
+ *in_pos += size;
+ *out_pos += size;
+
+ ret = action != LZMA_RUN && *in_pos == in_size
+ ? LZMA_STREAM_END : LZMA_OK;
+
+ } else {
+ const size_t out_start = *out_pos;
+
+ ret = coder->next.code(coder->next.coder, allocator,
+ in, in_pos, in_size, out, out_pos, out_size,
+ action);
+
+ encode_in_place(coder, out + out_start, *out_pos - out_start);
+ }
+
+ return ret;
+}
+
+
+static lzma_ret
+delta_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
+ const lzma_filter *filters_null lzma_attribute((__unused__)),
+ const lzma_filter *reversed_filters)
+{
+ // Delta doesn't and will never support changing the options in
+ // the middle of encoding. If the app tries to change them, we
+ // simply ignore them.
+ return lzma_next_filter_update(
+ &coder->next, allocator, reversed_filters + 1);
+}
+
+
+extern lzma_ret
+lzma_delta_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ next->code = &delta_encode;
+ next->update = &delta_encoder_update;
+ return lzma_delta_coder_init(next, allocator, filters);
+}
+
+
+extern lzma_ret
+lzma_delta_props_encode(const void *options, uint8_t *out)
+{
+ const lzma_options_delta *opt = options;
+
+ // The caller must have already validated the options, so it's
+ // LZMA_PROG_ERROR if they are invalid.
+ if (lzma_delta_coder_memusage(options) == UINT64_MAX)
+ return LZMA_PROG_ERROR;
+
+ out[0] = opt->dist - LZMA_DELTA_DIST_MIN;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_encoder.h b/Utilities/cmliblzma/liblzma/delta/delta_encoder.h
new file mode 100644
index 0000000000..a447862f20
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/delta/delta_encoder.h
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file delta_encoder.h
+/// \brief Delta filter encoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_DELTA_ENCODER_H
+#define LZMA_DELTA_ENCODER_H
+
+#include "delta_common.h"
+
+extern lzma_ret lzma_delta_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern lzma_ret lzma_delta_props_encode(const void *options, uint8_t *out);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_private.h b/Utilities/cmliblzma/liblzma/delta/delta_private.h
new file mode 100644
index 0000000000..62b7fed86e
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/delta/delta_private.h
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file delta_private.h
+/// \brief Private common stuff for Delta encoder and decoder
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_DELTA_PRIVATE_H
+#define LZMA_DELTA_PRIVATE_H
+
+#include "delta_common.h"
+
+struct lzma_coder_s {
+ /// Next coder in the chain
+ lzma_next_coder next;
+
+ /// Delta distance
+ size_t distance;
+
+ /// Position in history[]
+ uint8_t pos;
+
+ /// Buffer to hold history of the original data
+ uint8_t history[LZMA_DELTA_DIST_MAX];
+};
+
+
+extern lzma_ret lzma_delta_coder_init(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/liblzma.pc.in b/Utilities/cmliblzma/liblzma/liblzma.pc.in
new file mode 100644
index 0000000000..7f11f1a200
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/liblzma.pc.in
@@ -0,0 +1,19 @@
+#
+# Author: Lasse Collin
+#
+# This file has been put into the public domain.
+# You can do whatever you want with this file.
+#
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: liblzma
+Description: General purpose data compression library
+URL: @PACKAGE_URL@
+Version: @PACKAGE_VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -llzma
+Libs.private: @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
diff --git a/Utilities/cmliblzma/liblzma/liblzma_w32res.rc b/Utilities/cmliblzma/liblzma/liblzma_w32res.rc
new file mode 100644
index 0000000000..773caf8b41
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/liblzma_w32res.rc
@@ -0,0 +1,14 @@
+/*
+ * Author: Lasse Collin
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#define MY_TYPE VFT_DLL
+#define MY_NAME "liblzma"
+#define MY_SUFFIX ".dll"
+#define MY_DESC "liblzma data compression library"
+#define PACKAGE_NAME "XZ Utils"
+#define PACKAGE_URL "http://tukaani.org/xz/"
+#include "common_w32res.rc"
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_decoder.c b/Utilities/cmliblzma/liblzma/lz/lz_decoder.c
new file mode 100644
index 0000000000..9fa1bdc3a9
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lz/lz_decoder.c
@@ -0,0 +1,307 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lz_decoder.c
+/// \brief LZ out window
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+// liblzma supports multiple LZ77-based filters. The LZ part is shared
+// between these filters. The LZ code takes care of dictionary handling
+// and passing the data between filters in the chain. The filter-specific
+// part decodes from the input buffer to the dictionary.
+
+
+#include "lz_decoder.h"
+
+
+struct lzma_coder_s {
+ /// Dictionary (history buffer)
+ lzma_dict dict;
+
+ /// The actual LZ-based decoder e.g. LZMA
+ lzma_lz_decoder lz;
+
+ /// Next filter in the chain, if any. Note that LZMA and LZMA2 are
+ /// only allowed as the last filter, but the long-range filter in
+ /// future can be in the middle of the chain.
+ lzma_next_coder next;
+
+ /// True if the next filter in the chain has returned LZMA_STREAM_END.
+ bool next_finished;
+
+ /// True if the LZ decoder (e.g. LZMA) has detected end of payload
+ /// marker. This may become true before next_finished becomes true.
+ bool this_finished;
+
+ /// Temporary buffer needed when the LZ-based filter is not the last
+ /// filter in the chain. The output of the next filter is first
+ /// decoded into buffer[], which is then used as input for the actual
+ /// LZ-based decoder.
+ struct {
+ size_t pos;
+ size_t size;
+ uint8_t buffer[LZMA_BUFFER_SIZE];
+ } temp;
+};
+
+
+static void
+lz_decoder_reset(lzma_coder *coder)
+{
+ coder->dict.pos = 0;
+ coder->dict.full = 0;
+ coder->dict.buf[coder->dict.size - 1] = '\0';
+ coder->dict.need_reset = false;
+ return;
+}
+
+
+static lzma_ret
+decode_buffer(lzma_coder *coder,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size)
+{
+ while (true) {
+ size_t copy_size;
+ size_t dict_start;
+ lzma_ret ret;
+
+ // Wrap the dictionary if needed.
+ if (coder->dict.pos == coder->dict.size)
+ coder->dict.pos = 0;
+
+ // Store the current dictionary position. It is needed to know
+ // where to start copying to the out[] buffer.
+ dict_start = coder->dict.pos;
+
+ // Calculate how much we allow coder->lz.code() to decode.
+ // It must not decode past the end of the dictionary
+ // buffer, and we don't want it to decode more than is
+ // actually needed to fill the out[] buffer.
+ coder->dict.limit = coder->dict.pos
+ + my_min(out_size - *out_pos,
+ coder->dict.size - coder->dict.pos);
+
+ // Call the coder->lz.code() to do the actual decoding.
+ ret = coder->lz.code(
+ coder->lz.coder, &coder->dict,
+ in, in_pos, in_size);
+
+ // Copy the decoded data from the dictionary to the out[]
+ // buffer.
+ copy_size = coder->dict.pos - dict_start;
+ assert(copy_size <= out_size - *out_pos);
+ memcpy(out + *out_pos, coder->dict.buf + dict_start,
+ copy_size);
+ *out_pos += copy_size;
+
+ // Reset the dictionary if so requested by coder->lz.code().
+ if (coder->dict.need_reset) {
+ lz_decoder_reset(coder);
+
+ // Since we reset dictionary, we don't check if
+ // dictionary became full.
+ if (ret != LZMA_OK || *out_pos == out_size)
+ return ret;
+ } else {
+ // Return if everything got decoded or an error
+ // occurred, or if there's no more data to decode.
+ //
+ // Note that detecting if there's something to decode
+ // is done by looking if dictionary become full
+ // instead of looking if *in_pos == in_size. This
+ // is because it is possible that all the input was
+ // consumed already but some data is pending to be
+ // written to the dictionary.
+ if (ret != LZMA_OK || *out_pos == out_size
+ || coder->dict.pos < coder->dict.size)
+ return ret;
+ }
+ }
+}
+
+
+static lzma_ret
+lz_decode(lzma_coder *coder,
+ lzma_allocator *allocator lzma_attribute((__unused__)),
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size,
+ lzma_action action)
+{
+ if (coder->next.code == NULL)
+ return decode_buffer(coder, in, in_pos, in_size,
+ out, out_pos, out_size);
+
+ // We aren't the last coder in the chain, we need to decode
+ // our input to a temporary buffer.
+ while (*out_pos < out_size) {
+ lzma_ret ret;
+
+ // Fill the temporary buffer if it is empty.
+ if (!coder->next_finished
+ && coder->temp.pos == coder->temp.size) {
+ coder->temp.pos = 0;
+ coder->temp.size = 0;
+
+ ret = coder->next.code(
+ coder->next.coder,
+ allocator, in, in_pos, in_size,
+ coder->temp.buffer, &coder->temp.size,
+ LZMA_BUFFER_SIZE, action);
+
+ if (ret == LZMA_STREAM_END)
+ coder->next_finished = true;
+ else if (ret != LZMA_OK || coder->temp.size == 0)
+ return ret;
+ }
+
+ if (coder->this_finished) {
+ if (coder->temp.size != 0)
+ return LZMA_DATA_ERROR;
+
+ if (coder->next_finished)
+ return LZMA_STREAM_END;
+
+ return LZMA_OK;
+ }
+
+ ret = decode_buffer(coder, coder->temp.buffer,
+ &coder->temp.pos, coder->temp.size,
+ out, out_pos, out_size);
+
+ if (ret == LZMA_STREAM_END)
+ coder->this_finished = true;
+ else if (ret != LZMA_OK)
+ return ret;
+ else if (coder->next_finished && *out_pos < out_size)
+ return LZMA_DATA_ERROR;
+ }
+
+ return LZMA_OK;
+}
+
+
+static void
+lz_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->next, allocator);
+ lzma_free(coder->dict.buf, allocator);
+
+ if (coder->lz.end != NULL)
+ coder->lz.end(coder->lz.coder, allocator);
+ else
+ lzma_free(coder->lz.coder, allocator);
+
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+extern lzma_ret
+lzma_lz_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters,
+ lzma_ret (*lz_init)(lzma_lz_decoder *lz,
+ lzma_allocator *allocator, const void *options,
+ lzma_lz_options *lz_options))
+{
+ lzma_lz_options lz_options;
+
+ // Allocate the base structure if it isn't already allocated.
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &lz_decode;
+ next->end = &lz_decoder_end;
+
+ next->coder->dict.buf = NULL;
+ next->coder->dict.size = 0;
+ next->coder->lz = LZMA_LZ_DECODER_INIT;
+ next->coder->next = LZMA_NEXT_CODER_INIT;
+ }
+
+ // Allocate and initialize the LZ-based decoder. It will also give
+ // us the dictionary size.
+ return_if_error(lz_init(&next->coder->lz, allocator,
+ filters[0].options, &lz_options));
+
+ // If the dictionary size is very small, increase it to 4096 bytes.
+ // This is to prevent constant wrapping of the dictionary, which
+ // would slow things down. The downside is that since we don't check
+ // separately for the real dictionary size, we may happily accept
+ // corrupt files.
+ if (lz_options.dict_size < 4096)
+ lz_options.dict_size = 4096;
+
+ // Make dictionary size a multipe of 16. Some LZ-based decoders like
+ // LZMA use the lowest bits lzma_dict.pos to know the alignment of the
+ // data. Aligned buffer is also good when memcpying from the
+ // dictionary to the output buffer, since applications are
+ // recommended to give aligned buffers to liblzma.
+ //
+ // Avoid integer overflow.
+ if (lz_options.dict_size > SIZE_MAX - 15)
+ return LZMA_MEM_ERROR;
+
+ lz_options.dict_size = (lz_options.dict_size + 15) & ~((size_t)(15));
+
+ // Allocate and initialize the dictionary.
+ if (next->coder->dict.size != lz_options.dict_size) {
+ lzma_free(next->coder->dict.buf, allocator);
+ next->coder->dict.buf
+ = lzma_alloc(lz_options.dict_size, allocator);
+ if (next->coder->dict.buf == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->coder->dict.size = lz_options.dict_size;
+ }
+
+ lz_decoder_reset(next->coder);
+
+ // Use the preset dictionary if it was given to us.
+ if (lz_options.preset_dict != NULL
+ && lz_options.preset_dict_size > 0) {
+ // If the preset dictionary is bigger than the actual
+ // dictionary, copy only the tail.
+ const size_t copy_size = my_min(lz_options.preset_dict_size,
+ lz_options.dict_size);
+ const size_t offset = lz_options.preset_dict_size - copy_size;
+ memcpy(next->coder->dict.buf, lz_options.preset_dict + offset,
+ copy_size);
+ next->coder->dict.pos = copy_size;
+ next->coder->dict.full = copy_size;
+ }
+
+ // Miscellaneous initializations
+ next->coder->next_finished = false;
+ next->coder->this_finished = false;
+ next->coder->temp.pos = 0;
+ next->coder->temp.size = 0;
+
+ // Initialize the next filter in the chain, if any.
+ return lzma_next_filter_init(&next->coder->next, allocator,
+ filters + 1);
+}
+
+
+extern uint64_t
+lzma_lz_decoder_memusage(size_t dictionary_size)
+{
+ return sizeof(lzma_coder) + (uint64_t)(dictionary_size);
+}
+
+
+extern void
+lzma_lz_decoder_uncompressed(lzma_coder *coder, lzma_vli uncompressed_size)
+{
+ coder->lz.set_uncompressed(coder->lz.coder, uncompressed_size);
+}
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_decoder.h b/Utilities/cmliblzma/liblzma/lz/lz_decoder.h
new file mode 100644
index 0000000000..76011f2adc
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lz/lz_decoder.h
@@ -0,0 +1,236 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lz_decoder.h
+/// \brief LZ out window
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_LZ_DECODER_H
+#define LZMA_LZ_DECODER_H
+
+#include "common.h"
+
+
+typedef struct {
+ /// Pointer to the dictionary buffer. It can be an allocated buffer
+ /// internal to liblzma, or it can a be a buffer given by the
+ /// application when in single-call mode (not implemented yet).
+ uint8_t *buf;
+
+ /// Write position in dictionary. The next byte will be written to
+ /// buf[pos].
+ size_t pos;
+
+ /// Indicates how full the dictionary is. This is used by
+ /// dict_is_distance_valid() to detect corrupt files that would
+ /// read beyond the beginning of the dictionary.
+ size_t full;
+
+ /// Write limit
+ size_t limit;
+
+ /// Size of the dictionary
+ size_t size;
+
+ /// True when dictionary should be reset before decoding more data.
+ bool need_reset;
+
+} lzma_dict;
+
+
+typedef struct {
+ size_t dict_size;
+ const uint8_t *preset_dict;
+ size_t preset_dict_size;
+} lzma_lz_options;
+
+
+typedef struct {
+ /// Data specific to the LZ-based decoder
+ lzma_coder *coder;
+
+ /// Function to decode from in[] to *dict
+ lzma_ret (*code)(lzma_coder *LZMA_RESTRICT coder,
+ lzma_dict *LZMA_RESTRICT dict, const uint8_t *LZMA_RESTRICT in,
+ size_t *LZMA_RESTRICT in_pos, size_t in_size);
+
+ void (*reset)(lzma_coder *coder, const void *options);
+
+ /// Set the uncompressed size
+ void (*set_uncompressed)(lzma_coder *coder,
+ lzma_vli uncompressed_size);
+
+ /// Free allocated resources
+ void (*end)(lzma_coder *coder, lzma_allocator *allocator);
+
+} lzma_lz_decoder;
+
+
+static const lzma_lz_decoder LZMA_LZ_DECODER_INIT =
+ {
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ };
+
+
+extern lzma_ret lzma_lz_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters,
+ lzma_ret (*lz_init)(lzma_lz_decoder *lz,
+ lzma_allocator *allocator, const void *options,
+ lzma_lz_options *lz_options));
+
+extern uint64_t lzma_lz_decoder_memusage(size_t dictionary_size);
+
+extern void lzma_lz_decoder_uncompressed(
+ lzma_coder *coder, lzma_vli uncompressed_size);
+
+
+//////////////////////
+// Inline functions //
+//////////////////////
+
+/// Get a byte from the history buffer.
+static inline uint8_t
+dict_get(const lzma_dict *const dict, const uint32_t distance)
+{
+ return dict->buf[dict->pos - distance - 1
+ + (distance < dict->pos ? 0 : dict->size)];
+}
+
+
+/// Test if dictionary is empty.
+static inline bool
+dict_is_empty(const lzma_dict *const dict)
+{
+ return dict->full == 0;
+}
+
+
+/// Validate the match distance
+static inline bool
+dict_is_distance_valid(const lzma_dict *const dict, const size_t distance)
+{
+ return dict->full > distance;
+}
+
+
+/// Repeat *len bytes at distance.
+static inline bool
+dict_repeat(lzma_dict *dict, uint32_t distance, uint32_t *len)
+{
+ // Don't write past the end of the dictionary.
+ const size_t dict_avail = dict->limit - dict->pos;
+ uint32_t left = my_min(dict_avail, *len);
+ *len -= left;
+
+ // Repeat a block of data from the history. Because memcpy() is faster
+ // than copying byte by byte in a loop, the copying process gets split
+ // into three cases.
+ if (distance < left) {
+ // Source and target areas overlap, thus we can't use
+ // memcpy() nor even memmove() safely.
+ do {
+ dict->buf[dict->pos] = dict_get(dict, distance);
+ ++dict->pos;
+ } while (--left > 0);
+
+ } else if (distance < dict->pos) {
+ // The easiest and fastest case
+ memcpy(dict->buf + dict->pos,
+ dict->buf + dict->pos - distance - 1,
+ left);
+ dict->pos += left;
+
+ } else {
+ uint32_t copy_pos;
+ uint32_t copy_size;
+
+ // The bigger the dictionary, the more rare this
+ // case occurs. We need to "wrap" the dict, thus
+ // we might need two memcpy() to copy all the data.
+ assert(dict->full == dict->size);
+ copy_pos = dict->pos - distance - 1 + dict->size;
+ copy_size = dict->size - copy_pos;
+
+ if (copy_size < left) {
+ memmove(dict->buf + dict->pos, dict->buf + copy_pos,
+ copy_size);
+ dict->pos += copy_size;
+ copy_size = left - copy_size;
+ memcpy(dict->buf + dict->pos, dict->buf, copy_size);
+ dict->pos += copy_size;
+ } else {
+ memmove(dict->buf + dict->pos, dict->buf + copy_pos,
+ left);
+ dict->pos += left;
+ }
+ }
+
+ // Update how full the dictionary is.
+ if (dict->full < dict->pos)
+ dict->full = dict->pos;
+
+ return unlikely(*len != 0);
+}
+
+
+/// Puts one byte into the dictionary. Returns true if the dictionary was
+/// already full and the byte couldn't be added.
+static inline bool
+dict_put(lzma_dict *dict, uint8_t byte)
+{
+ if (unlikely(dict->pos == dict->limit))
+ return true;
+
+ dict->buf[dict->pos++] = byte;
+
+ if (dict->pos > dict->full)
+ dict->full = dict->pos;
+
+ return false;
+}
+
+
+/// Copies arbitrary amount of data into the dictionary.
+static inline void
+dict_write(lzma_dict *LZMA_RESTRICT dict, const uint8_t *LZMA_RESTRICT in,
+ size_t *LZMA_RESTRICT in_pos, size_t in_size,
+ size_t *LZMA_RESTRICT left)
+{
+ // NOTE: If we are being given more data than the size of the
+ // dictionary, it could be possible to optimize the LZ decoder
+ // so that not everything needs to go through the dictionary.
+ // This shouldn't be very common thing in practice though, and
+ // the slowdown of one extra memcpy() isn't bad compared to how
+ // much time it would have taken if the data were compressed.
+
+ if (in_size - *in_pos > *left)
+ in_size = *in_pos + *left;
+
+ *left -= lzma_bufcpy(in, in_pos, in_size,
+ dict->buf, &dict->pos, dict->limit);
+
+ if (dict->pos > dict->full)
+ dict->full = dict->pos;
+
+ return;
+}
+
+
+static inline void
+dict_reset(lzma_dict *dict)
+{
+ dict->need_reset = true;
+ return;
+}
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder.c b/Utilities/cmliblzma/liblzma/lz/lz_encoder.c
new file mode 100644
index 0000000000..1dae924b40
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder.c
@@ -0,0 +1,594 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lz_encoder.c
+/// \brief LZ in window
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "lz_encoder.h"
+#include "lz_encoder_hash.h"
+
+// See lz_encoder_hash.h. This is a bit hackish but avoids making
+// endianness a conditional in makefiles.
+#if defined(WORDS_BIGENDIAN) && !defined(HAVE_SMALL)
+# include "lz_encoder_hash_table.h"
+#endif
+
+
+struct lzma_coder_s {
+ /// LZ-based encoder e.g. LZMA
+ lzma_lz_encoder lz;
+
+ /// History buffer and match finder
+ lzma_mf mf;
+
+ /// Next coder in the chain
+ lzma_next_coder next;
+};
+
+
+/// \brief Moves the data in the input window to free space for new data
+///
+/// mf->buffer is a sliding input window, which keeps mf->keep_size_before
+/// bytes of input history available all the time. Now and then we need to
+/// "slide" the buffer to make space for the new data to the end of the
+/// buffer. At the same time, data older than keep_size_before is dropped.
+///
+static void
+move_window(lzma_mf *mf)
+{
+ uint32_t move_offset;
+ size_t move_size;
+
+ // Align the move to a multiple of 16 bytes. Some LZ-based encoders
+ // like LZMA use the lowest bits of mf->read_pos to know the
+ // alignment of the uncompressed data. We also get better speed
+ // for memmove() with aligned buffers.
+ assert(mf->read_pos > mf->keep_size_before);
+ move_offset = (mf->read_pos - mf->keep_size_before) & ~UINT32_C(15);
+
+ assert(mf->write_pos > move_offset);
+ move_size = mf->write_pos - move_offset;
+
+ assert(move_offset + move_size <= mf->size);
+
+ memmove(mf->buffer, mf->buffer + move_offset, move_size);
+
+ mf->offset += move_offset;
+ mf->read_pos -= move_offset;
+ mf->read_limit -= move_offset;
+ mf->write_pos -= move_offset;
+
+ return;
+}
+
+
+/// \brief Tries to fill the input window (mf->buffer)
+///
+/// If we are the last encoder in the chain, our input data is in in[].
+/// Otherwise we call the next filter in the chain to process in[] and
+/// write its output to mf->buffer.
+///
+/// This function must not be called once it has returned LZMA_STREAM_END.
+///
+static lzma_ret
+fill_window(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *in,
+ size_t *in_pos, size_t in_size, lzma_action action)
+{
+ size_t write_pos;
+ lzma_ret ret;
+
+ assert(coder->mf.read_pos <= coder->mf.write_pos);
+
+ // Move the sliding window if needed.
+ if (coder->mf.read_pos >= coder->mf.size - coder->mf.keep_size_after)
+ move_window(&coder->mf);
+
+ // Maybe this is ugly, but lzma_mf uses uint32_t for most things
+ // (which I find cleanest), but we need size_t here when filling
+ // the history window.
+ write_pos = coder->mf.write_pos;
+ if (coder->next.code == NULL) {
+ // Not using a filter, simply memcpy() as much as possible.
+ lzma_bufcpy(in, in_pos, in_size, coder->mf.buffer,
+ &write_pos, coder->mf.size);
+
+ ret = action != LZMA_RUN && *in_pos == in_size
+ ? LZMA_STREAM_END : LZMA_OK;
+
+ } else {
+ ret = coder->next.code(coder->next.coder, allocator,
+ in, in_pos, in_size,
+ coder->mf.buffer, &write_pos,
+ coder->mf.size, action);
+ }
+
+ coder->mf.write_pos = write_pos;
+
+ // If end of stream has been reached or flushing completed, we allow
+ // the encoder to process all the input (that is, read_pos is allowed
+ // to reach write_pos). Otherwise we keep keep_size_after bytes
+ // available as prebuffer.
+ if (ret == LZMA_STREAM_END) {
+ assert(*in_pos == in_size);
+ ret = LZMA_OK;
+ coder->mf.action = action;
+ coder->mf.read_limit = coder->mf.write_pos;
+
+ } else if (coder->mf.write_pos > coder->mf.keep_size_after) {
+ // This needs to be done conditionally, because if we got
+ // only little new input, there may be too little input
+ // to do any encoding yet.
+ coder->mf.read_limit = coder->mf.write_pos
+ - coder->mf.keep_size_after;
+ }
+
+ // Restart the match finder after finished LZMA_SYNC_FLUSH.
+ if (coder->mf.pending > 0
+ && coder->mf.read_pos < coder->mf.read_limit) {
+ // Match finder may update coder->pending and expects it to
+ // start from zero, so use a temporary variable.
+ const size_t pending = coder->mf.pending;
+ coder->mf.pending = 0;
+
+ // Rewind read_pos so that the match finder can hash
+ // the pending bytes.
+ assert(coder->mf.read_pos >= pending);
+ coder->mf.read_pos -= pending;
+
+ // Call the skip function directly instead of using
+ // mf_skip(), since we don't want to touch mf->read_ahead.
+ coder->mf.skip(&coder->mf, pending);
+ }
+
+ return ret;
+}
+
+
+static lzma_ret
+lz_encode(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size,
+ uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
+ size_t out_size, lzma_action action)
+{
+ while (*out_pos < out_size
+ && (*in_pos < in_size || action != LZMA_RUN)) {
+ lzma_ret ret;
+
+ // Read more data to coder->mf.buffer if needed.
+ if (coder->mf.action == LZMA_RUN && coder->mf.read_pos
+ >= coder->mf.read_limit)
+ return_if_error(fill_window(coder, allocator,
+ in, in_pos, in_size, action));
+
+ // Encode
+ ret = coder->lz.code(coder->lz.coder,
+ &coder->mf, out, out_pos, out_size);
+ if (ret != LZMA_OK) {
+ // Setting this to LZMA_RUN for cases when we are
+ // flushing. It doesn't matter when finishing or if
+ // an error occurred.
+ coder->mf.action = LZMA_RUN;
+ return ret;
+ }
+ }
+
+ return LZMA_OK;
+}
+
+
+static bool
+lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
+ const lzma_lz_options *lz_options)
+{
+ bool is_bt;
+ uint32_t new_count;
+ uint32_t reserve;
+ uint32_t old_size;
+ uint32_t hash_bytes;
+ uint32_t hs;
+ uint32_t old_count;
+
+ // For now, the dictionary size is limited to 1.5 GiB. This may grow
+ // in the future if needed, but it needs a little more work than just
+ // changing this check.
+ if (lz_options->dict_size < LZMA_DICT_SIZE_MIN
+ || lz_options->dict_size
+ > (UINT32_C(1) << 30) + (UINT32_C(1) << 29)
+ || lz_options->nice_len > lz_options->match_len_max)
+ return true;
+
+ mf->keep_size_before = lz_options->before_size + lz_options->dict_size;
+
+ mf->keep_size_after = lz_options->after_size
+ + lz_options->match_len_max;
+
+ // To avoid constant memmove()s, allocate some extra space. Since
+ // memmove()s become more expensive when the size of the buffer
+ // increases, we reserve more space when a large dictionary is
+ // used to make the memmove() calls rarer.
+ //
+ // This works with dictionaries up to about 3 GiB. If bigger
+ // dictionary is wanted, some extra work is needed:
+ // - Several variables in lzma_mf have to be changed from uint32_t
+ // to size_t.
+ // - Memory usage calculation needs something too, e.g. use uint64_t
+ // for mf->size.
+ reserve = lz_options->dict_size / 2;
+ if (reserve > (UINT32_C(1) << 30))
+ reserve /= 2;
+
+ reserve += (lz_options->before_size + lz_options->match_len_max
+ + lz_options->after_size) / 2 + (UINT32_C(1) << 19);
+
+ old_size = mf->size;
+ mf->size = mf->keep_size_before + reserve + mf->keep_size_after;
+
+ // Deallocate the old history buffer if it exists but has different
+ // size than what is needed now.
+ if (mf->buffer != NULL && old_size != mf->size) {
+ lzma_free(mf->buffer, allocator);
+ mf->buffer = NULL;
+ }
+
+ // Match finder options
+ mf->match_len_max = lz_options->match_len_max;
+ mf->nice_len = lz_options->nice_len;
+
+ // cyclic_size has to stay smaller than 2 Gi. Note that this doesn't
+ // mean limiting dictionary size to less than 2 GiB. With a match
+ // finder that uses multibyte resolution (hashes start at e.g. every
+ // fourth byte), cyclic_size would stay below 2 Gi even when
+ // dictionary size is greater than 2 GiB.
+ //
+ // It would be possible to allow cyclic_size >= 2 Gi, but then we
+ // would need to be careful to use 64-bit types in various places
+ // (size_t could do since we would need bigger than 32-bit address
+ // space anyway). It would also require either zeroing a multigigabyte
+ // buffer at initialization (waste of time and RAM) or allow
+ // normalization in lz_encoder_mf.c to access uninitialized
+ // memory to keep the code simpler. The current way is simple and
+ // still allows pretty big dictionaries, so I don't expect these
+ // limits to change.
+ mf->cyclic_size = lz_options->dict_size + 1;
+
+ // Validate the match finder ID and setup the function pointers.
+ switch (lz_options->match_finder) {
+#ifdef HAVE_MF_HC3
+ case LZMA_MF_HC3:
+ mf->find = &lzma_mf_hc3_find;
+ mf->skip = &lzma_mf_hc3_skip;
+ break;
+#endif
+#ifdef HAVE_MF_HC4
+ case LZMA_MF_HC4:
+ mf->find = &lzma_mf_hc4_find;
+ mf->skip = &lzma_mf_hc4_skip;
+ break;
+#endif
+#ifdef HAVE_MF_BT2
+ case LZMA_MF_BT2:
+ mf->find = &lzma_mf_bt2_find;
+ mf->skip = &lzma_mf_bt2_skip;
+ break;
+#endif
+#ifdef HAVE_MF_BT3
+ case LZMA_MF_BT3:
+ mf->find = &lzma_mf_bt3_find;
+ mf->skip = &lzma_mf_bt3_skip;
+ break;
+#endif
+#ifdef HAVE_MF_BT4
+ case LZMA_MF_BT4:
+ mf->find = &lzma_mf_bt4_find;
+ mf->skip = &lzma_mf_bt4_skip;
+ break;
+#endif
+
+ default:
+ return true;
+ }
+
+ // Calculate the sizes of mf->hash and mf->son and check that
+ // nice_len is big enough for the selected match finder.
+ hash_bytes = lz_options->match_finder & 0x0F;
+ if (hash_bytes > mf->nice_len)
+ return true;
+
+ is_bt = (lz_options->match_finder & 0x10) != 0;
+
+ if (hash_bytes == 2) {
+ hs = 0xFFFF;
+ } else {
+ // Round dictionary size up to the next 2^n - 1 so it can
+ // be used as a hash mask.
+ hs = lz_options->dict_size - 1;
+ hs |= hs >> 1;
+ hs |= hs >> 2;
+ hs |= hs >> 4;
+ hs |= hs >> 8;
+ hs >>= 1;
+ hs |= 0xFFFF;
+
+ if (hs > (UINT32_C(1) << 24)) {
+ if (hash_bytes == 3)
+ hs = (UINT32_C(1) << 24) - 1;
+ else
+ hs >>= 1;
+ }
+ }
+
+ mf->hash_mask = hs;
+
+ ++hs;
+ if (hash_bytes > 2)
+ hs += HASH_2_SIZE;
+ if (hash_bytes > 3)
+ hs += HASH_3_SIZE;
+/*
+ No match finder uses this at the moment.
+ if (mf->hash_bytes > 4)
+ hs += HASH_4_SIZE;
+*/
+
+ // If the above code calculating hs is modified, make sure that
+ // this assertion stays valid (UINT32_MAX / 5 is not strictly the
+ // exact limit). If it doesn't, you need to calculate that
+ // hash_size_sum + sons_count cannot overflow.
+ assert(hs < UINT32_MAX / 5);
+
+ old_count = mf->hash_size_sum + mf->sons_count;
+ mf->hash_size_sum = hs;
+ mf->sons_count = mf->cyclic_size;
+ if (is_bt)
+ mf->sons_count *= 2;
+
+ new_count = mf->hash_size_sum + mf->sons_count;
+
+ // Deallocate the old hash array if it exists and has different size
+ // than what is needed now.
+ if (old_count != new_count) {
+ lzma_free(mf->hash, allocator);
+ mf->hash = NULL;
+ }
+
+ // Maximum number of match finder cycles
+ mf->depth = lz_options->depth;
+ if (mf->depth == 0) {
+ if (is_bt)
+ mf->depth = 16 + mf->nice_len / 2;
+ else
+ mf->depth = 4 + mf->nice_len / 4;
+ }
+
+ return false;
+}
+
+
+static bool
+lz_encoder_init(lzma_mf *mf, lzma_allocator *allocator,
+ const lzma_lz_options *lz_options)
+{
+ size_t alloc_count;
+
+ // Allocate the history buffer.
+ if (mf->buffer == NULL) {
+ mf->buffer = lzma_alloc(mf->size, allocator);
+ if (mf->buffer == NULL)
+ return true;
+ }
+
+ // Use cyclic_size as initial mf->offset. This allows
+ // avoiding a few branches in the match finders. The downside is
+ // that match finder needs to be normalized more often, which may
+ // hurt performance with huge dictionaries.
+ mf->offset = mf->cyclic_size;
+ mf->read_pos = 0;
+ mf->read_ahead = 0;
+ mf->read_limit = 0;
+ mf->write_pos = 0;
+ mf->pending = 0;
+
+ // Allocate match finder's hash array.
+ alloc_count = mf->hash_size_sum + mf->sons_count;
+
+#if UINT32_MAX >= SIZE_MAX / 4
+ // Check for integer overflow. (Huge dictionaries are not
+ // possible on 32-bit CPU.)
+ if (alloc_count > SIZE_MAX / sizeof(uint32_t))
+ return true;
+#endif
+
+ if (mf->hash == NULL) {
+ mf->hash = lzma_alloc(alloc_count * sizeof(uint32_t),
+ allocator);
+ if (mf->hash == NULL)
+ return true;
+ }
+
+ mf->son = mf->hash + mf->hash_size_sum;
+ mf->cyclic_pos = 0;
+
+ // Initialize the hash table. Since EMPTY_HASH_VALUE is zero, we
+ // can use memset().
+/*
+ for (uint32_t i = 0; i < hash_size_sum; ++i)
+ mf->hash[i] = EMPTY_HASH_VALUE;
+*/
+ memzero(mf->hash, (size_t)(mf->hash_size_sum) * sizeof(uint32_t));
+
+ // We don't need to initialize mf->son, but not doing that will
+ // make Valgrind complain in normalization (see normalize() in
+ // lz_encoder_mf.c).
+ //
+ // Skipping this initialization is *very* good when big dictionary is
+ // used but only small amount of data gets actually compressed: most
+ // of the mf->hash won't get actually allocated by the kernel, so
+ // we avoid wasting RAM and improve initialization speed a lot.
+ //memzero(mf->son, (size_t)(mf->sons_count) * sizeof(uint32_t));
+
+ // Handle preset dictionary.
+ if (lz_options->preset_dict != NULL
+ && lz_options->preset_dict_size > 0) {
+ // If the preset dictionary is bigger than the actual
+ // dictionary, use only the tail.
+ mf->write_pos = my_min(lz_options->preset_dict_size, mf->size);
+ memcpy(mf->buffer, lz_options->preset_dict
+ + lz_options->preset_dict_size - mf->write_pos,
+ mf->write_pos);
+ mf->action = LZMA_SYNC_FLUSH;
+ mf->skip(mf, mf->write_pos);
+ }
+
+ mf->action = LZMA_RUN;
+
+ return false;
+}
+
+
+extern uint64_t
+lzma_lz_encoder_memusage(const lzma_lz_options *lz_options)
+{
+ // Old buffers must not exist when calling lz_encoder_prepare().
+ lzma_mf mf = { NULL };
+
+ // Setup the size information into mf.
+ if (lz_encoder_prepare(&mf, NULL, lz_options))
+ return UINT64_MAX;
+
+ // Calculate the memory usage.
+ return (uint64_t)(mf.hash_size_sum + mf.sons_count)
+ * sizeof(uint32_t)
+ + (uint64_t)(mf.size) + sizeof(lzma_coder);
+}
+
+
+static void
+lz_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->next, allocator);
+
+ lzma_free(coder->mf.hash, allocator);
+ lzma_free(coder->mf.buffer, allocator);
+
+ if (coder->lz.end != NULL)
+ coder->lz.end(coder->lz.coder, allocator);
+ else
+ lzma_free(coder->lz.coder, allocator);
+
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static lzma_ret
+lz_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
+ const lzma_filter *filters_null lzma_attribute((__unused__)),
+ const lzma_filter *reversed_filters)
+{
+ if (coder->lz.options_update == NULL)
+ return LZMA_PROG_ERROR;
+
+ return_if_error(coder->lz.options_update(
+ coder->lz.coder, reversed_filters));
+
+ return lzma_next_filter_update(
+ &coder->next, allocator, reversed_filters + 1);
+}
+
+
+extern lzma_ret
+lzma_lz_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters,
+ lzma_ret (*lz_init)(lzma_lz_encoder *lz,
+ lzma_allocator *allocator, const void *options,
+ lzma_lz_options *lz_options))
+{
+ lzma_lz_options lz_options;
+
+#ifdef HAVE_SMALL
+ // We need that the CRC32 table has been initialized.
+ lzma_crc32_init();
+#endif
+
+ // Allocate and initialize the base data structure.
+ if (next->coder == NULL) {
+ next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &lz_encode;
+ next->end = &lz_encoder_end;
+ next->update = &lz_encoder_update;
+
+ next->coder->lz.coder = NULL;
+ next->coder->lz.code = NULL;
+ next->coder->lz.end = NULL;
+
+ next->coder->mf.buffer = NULL;
+ next->coder->mf.hash = NULL;
+ next->coder->mf.hash_size_sum = 0;
+ next->coder->mf.sons_count = 0;
+
+ next->coder->next = LZMA_NEXT_CODER_INIT;
+ }
+
+ // Initialize the LZ-based encoder.
+ return_if_error(lz_init(&next->coder->lz, allocator,
+ filters[0].options, &lz_options));
+
+ // Setup the size information into next->coder->mf and deallocate
+ // old buffers if they have wrong size.
+ if (lz_encoder_prepare(&next->coder->mf, allocator, &lz_options))
+ return LZMA_OPTIONS_ERROR;
+
+ // Allocate new buffers if needed, and do the rest of
+ // the initialization.
+ if (lz_encoder_init(&next->coder->mf, allocator, &lz_options))
+ return LZMA_MEM_ERROR;
+
+ // Initialize the next filter in the chain, if any.
+ return lzma_next_filter_init(&next->coder->next, allocator,
+ filters + 1);
+}
+
+
+extern LZMA_API(lzma_bool)
+lzma_mf_is_supported(lzma_match_finder mf)
+{
+ bool ret = false;
+
+#ifdef HAVE_MF_HC3
+ if (mf == LZMA_MF_HC3)
+ ret = true;
+#endif
+
+#ifdef HAVE_MF_HC4
+ if (mf == LZMA_MF_HC4)
+ ret = true;
+#endif
+
+#ifdef HAVE_MF_BT2
+ if (mf == LZMA_MF_BT2)
+ ret = true;
+#endif
+
+#ifdef HAVE_MF_BT3
+ if (mf == LZMA_MF_BT3)
+ ret = true;
+#endif
+
+#ifdef HAVE_MF_BT4
+ if (mf == LZMA_MF_BT4)
+ ret = true;
+#endif
+
+ return ret;
+}
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder.h b/Utilities/cmliblzma/liblzma/lz/lz_encoder.h
new file mode 100644
index 0000000000..dcb4b2c5bb
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder.h
@@ -0,0 +1,328 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lz_encoder.h
+/// \brief LZ in window and match finder API
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_LZ_ENCODER_H
+#define LZMA_LZ_ENCODER_H
+
+#include "common.h"
+
+
+/// A table of these is used by the LZ-based encoder to hold
+/// the length-distance pairs found by the match finder.
+typedef struct {
+ uint32_t len;
+ uint32_t dist;
+} lzma_match;
+
+
+typedef struct lzma_mf_s lzma_mf;
+struct lzma_mf_s {
+ ///////////////
+ // In Window //
+ ///////////////
+
+ /// Pointer to buffer with data to be compressed
+ uint8_t *buffer;
+
+ /// Total size of the allocated buffer (that is, including all
+ /// the extra space)
+ uint32_t size;
+
+ /// Number of bytes that must be kept available in our input history.
+ /// That is, once keep_size_before bytes have been processed,
+ /// buffer[read_pos - keep_size_before] is the oldest byte that
+ /// must be available for reading.
+ uint32_t keep_size_before;
+
+ /// Number of bytes that must be kept in buffer after read_pos.
+ /// That is, read_pos <= write_pos - keep_size_after as long as
+ /// action is LZMA_RUN; when action != LZMA_RUN, read_pos is allowed
+ /// to reach write_pos so that the last bytes get encoded too.
+ uint32_t keep_size_after;
+
+ /// Match finders store locations of matches using 32-bit integers.
+ /// To avoid adjusting several megabytes of integers every time the
+ /// input window is moved with move_window, we only adjust the
+ /// offset of the buffer. Thus, buffer[value_in_hash_table - offset]
+ /// is the byte pointed by value_in_hash_table.
+ uint32_t offset;
+
+ /// buffer[read_pos] is the next byte to run through the match
+ /// finder. This is incremented in the match finder once the byte
+ /// has been processed.
+ uint32_t read_pos;
+
+ /// Number of bytes that have been ran through the match finder, but
+ /// which haven't been encoded by the LZ-based encoder yet.
+ uint32_t read_ahead;
+
+ /// As long as read_pos is less than read_limit, there is enough
+ /// input available in buffer for at least one encoding loop.
+ ///
+ /// Because of the stateful API, read_limit may and will get greater
+ /// than read_pos quite often. This is taken into account when
+ /// calculating the value for keep_size_after.
+ uint32_t read_limit;
+
+ /// buffer[write_pos] is the first byte that doesn't contain valid
+ /// uncompressed data; that is, the next input byte will be copied
+ /// to buffer[write_pos].
+ uint32_t write_pos;
+
+ /// Number of bytes not hashed before read_pos. This is needed to
+ /// restart the match finder after LZMA_SYNC_FLUSH.
+ uint32_t pending;
+
+ //////////////////
+ // Match Finder //
+ //////////////////
+
+ /// Find matches. Returns the number of distance-length pairs written
+ /// to the matches array. This is called only via lzma_mf_find().
+ uint32_t (*find)(lzma_mf *mf, lzma_match *matches);
+
+ /// Skips num bytes. This is like find() but doesn't make the
+ /// distance-length pairs available, thus being a little faster.
+ /// This is called only via mf_skip().
+ void (*skip)(lzma_mf *mf, uint32_t num);
+
+ uint32_t *hash;
+ uint32_t *son;
+ uint32_t cyclic_pos;
+ uint32_t cyclic_size; // Must be dictionary size + 1.
+ uint32_t hash_mask;
+
+ /// Maximum number of loops in the match finder
+ uint32_t depth;
+
+ /// Maximum length of a match that the match finder will try to find.
+ uint32_t nice_len;
+
+ /// Maximum length of a match supported by the LZ-based encoder.
+ /// If the longest match found by the match finder is nice_len,
+ /// mf_find() tries to expand it up to match_len_max bytes.
+ uint32_t match_len_max;
+
+ /// When running out of input, binary tree match finders need to know
+ /// if it is due to flushing or finishing. The action is used also
+ /// by the LZ-based encoders themselves.
+ lzma_action action;
+
+ /// Number of elements in hash[]
+ uint32_t hash_size_sum;
+
+ /// Number of elements in son[]
+ uint32_t sons_count;
+};
+
+
+typedef struct {
+ /// Extra amount of data to keep available before the "actual"
+ /// dictionary.
+ size_t before_size;
+
+ /// Size of the history buffer
+ size_t dict_size;
+
+ /// Extra amount of data to keep available after the "actual"
+ /// dictionary.
+ size_t after_size;
+
+ /// Maximum length of a match that the LZ-based encoder can accept.
+ /// This is used to extend matches of length nice_len to the
+ /// maximum possible length.
+ size_t match_len_max;
+
+ /// Match finder will search matches up to this length.
+ /// This must be less than or equal to match_len_max.
+ size_t nice_len;
+
+ /// Type of the match finder to use
+ lzma_match_finder match_finder;
+
+ /// Maximum search depth
+ uint32_t depth;
+
+ /// TODO: Comment
+ const uint8_t *preset_dict;
+
+ uint32_t preset_dict_size;
+
+} lzma_lz_options;
+
+
+// The total usable buffer space at any moment outside the match finder:
+// before_size + dict_size + after_size + match_len_max
+//
+// In reality, there's some extra space allocated to prevent the number of
+// memmove() calls reasonable. The bigger the dict_size is, the bigger
+// this extra buffer will be since with bigger dictionaries memmove() would
+// also take longer.
+//
+// A single encoder loop in the LZ-based encoder may call the match finder
+// (mf_find() or mf_skip()) at most after_size times. In other words,
+// a single encoder loop may increment lzma_mf.read_pos at most after_size
+// times. Since matches are looked up to
+// lzma_mf.buffer[lzma_mf.read_pos + match_len_max - 1], the total
+// amount of extra buffer needed after dict_size becomes
+// after_size + match_len_max.
+//
+// before_size has two uses. The first one is to keep literals available
+// in cases when the LZ-based encoder has made some read ahead.
+// TODO: Maybe this could be changed by making the LZ-based encoders to
+// store the actual literals as they do with length-distance pairs.
+//
+// Algorithms such as LZMA2 first try to compress a chunk, and then check
+// if the encoded result is smaller than the uncompressed one. If the chunk
+// was uncompressible, it is better to store it in uncompressed form in
+// the output stream. To do this, the whole uncompressed chunk has to be
+// still available in the history buffer. before_size achieves that.
+
+
+typedef struct {
+ /// Data specific to the LZ-based encoder
+ lzma_coder *coder;
+
+ /// Function to encode from *dict to out[]
+ lzma_ret (*code)(lzma_coder *LZMA_RESTRICT coder,
+ lzma_mf *LZMA_RESTRICT mf, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size);
+
+ /// Free allocated resources
+ void (*end)(lzma_coder *coder, lzma_allocator *allocator);
+
+ /// Update the options in the middle of the encoding.
+ lzma_ret (*options_update)(lzma_coder *coder,
+ const lzma_filter *filter);
+
+} lzma_lz_encoder;
+
+
+// Basic steps:
+// 1. Input gets copied into the dictionary.
+// 2. Data in dictionary gets run through the match finder byte by byte.
+// 3. The literals and matches are encoded using e.g. LZMA.
+//
+// The bytes that have been ran through the match finder, but not encoded yet,
+// are called `read ahead'.
+
+
+/// Get pointer to the first byte not ran through the match finder
+static inline uint8_t *
+mf_ptr(const lzma_mf *mf)
+{
+ return mf->buffer + mf->read_pos;
+}
+
+
+/// Get the number of bytes that haven't been ran through the match finder yet.
+static inline uint32_t
+mf_avail(const lzma_mf *mf)
+{
+ return mf->write_pos - mf->read_pos;
+}
+
+
+/// Get the number of bytes that haven't been encoded yet (some of these
+/// bytes may have been ran through the match finder though).
+static inline uint32_t
+mf_unencoded(const lzma_mf *mf)
+{
+ return mf->write_pos - mf->read_pos + mf->read_ahead;
+}
+
+
+/// Calculate the absolute offset from the beginning of the most recent
+/// dictionary reset. Only the lowest four bits are important, so there's no
+/// problem that we don't know the 64-bit size of the data encoded so far.
+///
+/// NOTE: When moving the input window, we need to do it so that the lowest
+/// bits of dict->read_pos are not modified to keep this macro working
+/// as intended.
+static inline uint32_t
+mf_position(const lzma_mf *mf)
+{
+ return mf->read_pos - mf->read_ahead;
+}
+
+
+/// Since everything else begins with mf_, use it also for lzma_mf_find().
+#define mf_find lzma_mf_find
+
+
+/// Skip the given number of bytes. This is used when a good match was found.
+/// For example, if mf_find() finds a match of 200 bytes long, the first byte
+/// of that match was already consumed by mf_find(), and the rest 199 bytes
+/// have to be skipped with mf_skip(mf, 199).
+static inline void
+mf_skip(lzma_mf *mf, uint32_t amount)
+{
+ if (amount != 0) {
+ mf->skip(mf, amount);
+ mf->read_ahead += amount;
+ }
+}
+
+
+/// Copies at most *left number of bytes from the history buffer
+/// to out[]. This is needed by LZMA2 to encode uncompressed chunks.
+static inline void
+mf_read(lzma_mf *mf, uint8_t *out, size_t *out_pos, size_t out_size,
+ size_t *left)
+{
+ const size_t out_avail = out_size - *out_pos;
+ const size_t copy_size = my_min(out_avail, *left);
+
+ assert(mf->read_ahead == 0);
+ assert(mf->read_pos >= *left);
+
+ memcpy(out + *out_pos, mf->buffer + mf->read_pos - *left,
+ copy_size);
+
+ *out_pos += copy_size;
+ *left -= copy_size;
+ return;
+}
+
+
+extern lzma_ret lzma_lz_encoder_init(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters,
+ lzma_ret (*lz_init)(lzma_lz_encoder *lz,
+ lzma_allocator *allocator, const void *options,
+ lzma_lz_options *lz_options));
+
+
+extern uint64_t lzma_lz_encoder_memusage(const lzma_lz_options *lz_options);
+
+
+// These are only for LZ encoder's internal use.
+extern uint32_t lzma_mf_find(
+ lzma_mf *mf, uint32_t *count, lzma_match *matches);
+
+extern uint32_t lzma_mf_hc3_find(lzma_mf *dict, lzma_match *matches);
+extern void lzma_mf_hc3_skip(lzma_mf *dict, uint32_t amount);
+
+extern uint32_t lzma_mf_hc4_find(lzma_mf *dict, lzma_match *matches);
+extern void lzma_mf_hc4_skip(lzma_mf *dict, uint32_t amount);
+
+extern uint32_t lzma_mf_bt2_find(lzma_mf *dict, lzma_match *matches);
+extern void lzma_mf_bt2_skip(lzma_mf *dict, uint32_t amount);
+
+extern uint32_t lzma_mf_bt3_find(lzma_mf *dict, lzma_match *matches);
+extern void lzma_mf_bt3_skip(lzma_mf *dict, uint32_t amount);
+
+extern uint32_t lzma_mf_bt4_find(lzma_mf *dict, lzma_match *matches);
+extern void lzma_mf_bt4_skip(lzma_mf *dict, uint32_t amount);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h b/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h
new file mode 100644
index 0000000000..de17c54fc3
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h
@@ -0,0 +1,105 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lz_encoder_hash.h
+/// \brief Hash macros for match finders
+//
+// Author: Igor Pavlov
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_LZ_ENCODER_HASH_H
+#define LZMA_LZ_ENCODER_HASH_H
+
+#if defined(WORDS_BIGENDIAN) && !defined(HAVE_SMALL)
+ // This is to make liblzma produce the same output on big endian
+ // systems that it does on little endian systems. lz_encoder.c
+ // takes care of including the actual table.
+ extern const uint32_t lzma_lz_hash_table[256];
+# define hash_table lzma_lz_hash_table
+#else
+# include "check.h"
+# define hash_table lzma_crc32_table[0]
+#endif
+
+#define HASH_2_SIZE (UINT32_C(1) << 10)
+#define HASH_3_SIZE (UINT32_C(1) << 16)
+#define HASH_4_SIZE (UINT32_C(1) << 20)
+
+#define HASH_2_MASK (HASH_2_SIZE - 1)
+#define HASH_3_MASK (HASH_3_SIZE - 1)
+#define HASH_4_MASK (HASH_4_SIZE - 1)
+
+#define FIX_3_HASH_SIZE (HASH_2_SIZE)
+#define FIX_4_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE)
+#define FIX_5_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE + HASH_4_SIZE)
+
+// Endianness doesn't matter in hash_2_calc() (no effect on the output).
+#ifdef TUKLIB_FAST_UNALIGNED_ACCESS
+# define hash_2_calc() \
+ hash_value = *(const uint16_t *)(cur)
+#else
+# define hash_2_calc() \
+ hash_value = (uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)
+#endif
+
+#define hash_3_calc() \
+ temp = hash_table[cur[0]] ^ cur[1]; \
+ hash_2_value = temp & HASH_2_MASK; \
+ hash_value = (temp ^ ((uint32_t)(cur[2]) << 8)) & mf->hash_mask
+
+#define hash_4_calc() \
+ temp = hash_table[cur[0]] ^ cur[1]; \
+ hash_2_value = temp & HASH_2_MASK; \
+ hash_3_value = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \
+ hash_value = (temp ^ ((uint32_t)(cur[2]) << 8) \
+ ^ (hash_table[cur[3]] << 5)) & mf->hash_mask
+
+
+// The following are not currently used.
+
+#define hash_5_calc() \
+ const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \
+ const uint32_t hash_2_value = temp & HASH_2_MASK; \
+ const uint32_t hash_3_value \
+ = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \
+ uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \
+ ^ hash_table[cur[3]] << 5); \
+ const uint32_t hash_value \
+ = (hash_4_value ^ (hash_table[cur[4]] << 3)) \
+ & mf->hash_mask; \
+ hash_4_value &= HASH_4_MASK
+
+/*
+#define hash_zip_calc() \
+ const uint32_t hash_value \
+ = (((uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)) \
+ ^ hash_table[cur[2]]) & 0xFFFF
+*/
+
+#define hash_zip_calc() \
+ const uint32_t hash_value \
+ = (((uint32_t)(cur[2]) | ((uint32_t)(cur[0]) << 8)) \
+ ^ hash_table[cur[1]]) & 0xFFFF
+
+#define mt_hash_2_calc() \
+ const uint32_t hash_2_value \
+ = (hash_table[cur[0]] ^ cur[1]) & HASH_2_MASK
+
+#define mt_hash_3_calc() \
+ const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \
+ const uint32_t hash_2_value = temp & HASH_2_MASK; \
+ const uint32_t hash_3_value \
+ = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK
+
+#define mt_hash_4_calc() \
+ const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \
+ const uint32_t hash_2_value = temp & HASH_2_MASK; \
+ const uint32_t hash_3_value \
+ = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \
+ const uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \
+ (hash_table[cur[3]] << 5)) & HASH_4_MASK
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash_table.h b/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash_table.h
new file mode 100644
index 0000000000..8c51717d70
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash_table.h
@@ -0,0 +1,68 @@
+/* This file has been automatically generated by crc32_tablegen.c. */
+
+const uint32_t lzma_lz_hash_table[256] = {
+ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
+ 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
+ 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
+ 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
+ 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
+ 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
+ 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
+ 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
+ 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
+ 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
+ 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
+ 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
+ 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
+ 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
+ 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
+ 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
+ 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
+ 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
+ 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
+ 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
+ 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
+ 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
+ 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
+ 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
+ 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
+ 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
+ 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
+ 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
+ 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
+ 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
+ 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
+ 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
+ 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
+ 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
+ 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
+ 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
+ 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
+ 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
+ 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
+ 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
+ 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
+ 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
+ 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
+ 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
+ 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
+ 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
+ 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
+ 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
+ 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
+ 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
+ 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
+ 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
+ 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
+ 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
+ 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
+ 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
+ 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
+ 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
+ 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
+ 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
+ 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
+ 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
+ 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
+ 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
+};
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c b/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c
new file mode 100644
index 0000000000..50c3459aae
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c
@@ -0,0 +1,814 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lz_encoder_mf.c
+/// \brief Match finders
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "lz_encoder.h"
+#include "lz_encoder_hash.h"
+
+
+/// \brief Find matches starting from the current byte
+///
+/// \return The length of the longest match found
+extern uint32_t
+lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
+{
+ // Call the match finder. It returns the number of length-distance
+ // pairs found.
+ // FIXME: Minimum count is zero, what _exactly_ is the maximum?
+ const uint32_t count = mf->find(mf, matches);
+
+ // Length of the longest match; assume that no matches were found
+ // and thus the maximum length is zero.
+ uint32_t len_best = 0;
+
+ if (count > 0) {
+#ifndef NDEBUG
+ uint32_t i;
+ // Validate the matches.
+ for (i = 0; i < count; ++i) {
+ assert(matches[i].len <= mf->nice_len);
+ assert(matches[i].dist < mf->read_pos);
+ assert(memcmp(mf_ptr(mf) - 1,
+ mf_ptr(mf) - matches[i].dist - 2,
+ matches[i].len) == 0);
+ }
+#endif
+
+ // The last used element in the array contains
+ // the longest match.
+ len_best = matches[count - 1].len;
+
+ // If a match of maximum search length was found, try to
+ // extend the match to maximum possible length.
+ if (len_best == mf->nice_len) {
+ uint8_t *p1;
+ uint8_t *p2;
+
+ // The limit for the match length is either the
+ // maximum match length supported by the LZ-based
+ // encoder or the number of bytes left in the
+ // dictionary, whichever is smaller.
+ uint32_t limit = mf_avail(mf) + 1;
+ if (limit > mf->match_len_max)
+ limit = mf->match_len_max;
+
+ // Pointer to the byte we just ran through
+ // the match finder.
+ p1 = mf_ptr(mf) - 1;
+
+ // Pointer to the beginning of the match. We need -1
+ // here because the match distances are zero based.
+ p2 = p1 - matches[count - 1].dist - 1;
+
+ while (len_best < limit
+ && p1[len_best] == p2[len_best])
+ ++len_best;
+ }
+ }
+
+ *count_ptr = count;
+
+ // Finally update the read position to indicate that match finder was
+ // run for this dictionary offset.
+ ++mf->read_ahead;
+
+ return len_best;
+}
+
+
+/// Hash value to indicate unused element in the hash. Since we start the
+/// positions from dict_size + 1, zero is always too far to qualify
+/// as usable match position.
+#define EMPTY_HASH_VALUE 0
+
+
+/// Normalization must be done when lzma_mf.offset + lzma_mf.read_pos
+/// reaches MUST_NORMALIZE_POS.
+#define MUST_NORMALIZE_POS UINT32_MAX
+
+
+/// \brief Normalizes hash values
+///
+/// The hash arrays store positions of match candidates. The positions are
+/// relative to an arbitrary offset that is not the same as the absolute
+/// offset in the input stream. The relative position of the current byte
+/// is lzma_mf.offset + lzma_mf.read_pos. The distances of the matches are
+/// the differences of the current read position and the position found from
+/// the hash.
+///
+/// To prevent integer overflows of the offsets stored in the hash arrays,
+/// we need to "normalize" the stored values now and then. During the
+/// normalization, we drop values that indicate distance greater than the
+/// dictionary size, thus making space for new values.
+static void
+normalize(lzma_mf *mf)
+{
+ uint32_t i;
+ uint32_t subvalue;
+ uint32_t count;
+ uint32_t *hash;
+
+ assert(mf->read_pos + mf->offset == MUST_NORMALIZE_POS);
+
+ // In future we may not want to touch the lowest bits, because there
+ // may be match finders that use larger resolution than one byte.
+ subvalue = (MUST_NORMALIZE_POS - mf->cyclic_size);
+ // & (~(UINT32_C(1) << 10) - 1);
+
+ count = mf->hash_size_sum + mf->sons_count;
+ hash = mf->hash;
+
+ for (i = 0; i < count; ++i) {
+ // If the distance is greater than the dictionary size,
+ // we can simply mark the hash element as empty.
+ //
+ // NOTE: Only the first mf->hash_size_sum elements are
+ // initialized for sure. There may be uninitialized elements
+ // in mf->son. Since we go through both mf->hash and
+ // mf->son here in normalization, Valgrind may complain
+ // that the "if" below depends on uninitialized value. In
+ // this case it is safe to ignore the warning. See also the
+ // comments in lz_encoder_init() in lz_encoder.c.
+ if (hash[i] <= subvalue)
+ hash[i] = EMPTY_HASH_VALUE;
+ else
+ hash[i] -= subvalue;
+ }
+
+ // Update offset to match the new locations.
+ mf->offset -= subvalue;
+
+ return;
+}
+
+
+/// Mark the current byte as processed from point of view of the match finder.
+static void
+move_pos(lzma_mf *mf)
+{
+ if (++mf->cyclic_pos == mf->cyclic_size)
+ mf->cyclic_pos = 0;
+
+ ++mf->read_pos;
+ assert(mf->read_pos <= mf->write_pos);
+
+ if (unlikely(mf->read_pos + mf->offset == UINT32_MAX))
+ normalize(mf);
+}
+
+
+/// When flushing, we cannot run the match finder unless there is nice_len
+/// bytes available in the dictionary. Instead, we skip running the match
+/// finder (indicating that no match was found), and count how many bytes we
+/// have ignored this way.
+///
+/// When new data is given after the flushing was completed, the match finder
+/// is restarted by rewinding mf->read_pos backwards by mf->pending. Then
+/// the missed bytes are added to the hash using the match finder's skip
+/// function (with small amount of input, it may start using mf->pending
+/// again if flushing).
+///
+/// Due to this rewinding, we don't touch cyclic_pos or test for
+/// normalization. It will be done when the match finder's skip function
+/// catches up after a flush.
+static void
+move_pending(lzma_mf *mf)
+{
+ ++mf->read_pos;
+ assert(mf->read_pos <= mf->write_pos);
+ ++mf->pending;
+}
+
+
+/// Calculate len_limit and determine if there is enough input to run
+/// the actual match finder code. Sets up "cur" and "pos". This macro
+/// is used by all find functions and binary tree skip functions. Hash
+/// chain skip function doesn't need len_limit so a simpler code is used
+/// in them.
+#define header(is_bt, len_min, ret_op) \
+ uint32_t len_limit = mf_avail(mf); \
+ if (mf->nice_len <= len_limit) { \
+ len_limit = mf->nice_len; \
+ } else if (len_limit < (len_min) \
+ || (is_bt && mf->action == LZMA_SYNC_FLUSH)) { \
+ assert(mf->action != LZMA_RUN); \
+ move_pending(mf); \
+ ret_op; \
+ } \
+ cur = mf_ptr(mf); \
+ pos = mf->read_pos + mf->offset
+
+
+/// Header for find functions. "return 0" indicates that zero matches
+/// were found.
+#define header_find(is_bt, len_min) \
+ header(is_bt, len_min, return 0)
+
+
+/// Header for a loop in a skip function. "continue" tells to skip the rest
+/// of the code in the loop.
+#define header_skip(is_bt, len_min) \
+ header(is_bt, len_min, continue)
+
+
+/// Calls hc_find_func() or bt_find_func() and calculates the total number
+/// of matches found. Updates the dictionary position and returns the number
+/// of matches found.
+#define call_find(func, len_best) \
+do { \
+ matches_count = func(len_limit, pos, cur, cur_match, mf->depth, \
+ mf->son, mf->cyclic_pos, mf->cyclic_size, \
+ matches + matches_count, len_best) \
+ - matches; \
+ move_pos(mf); \
+ return matches_count; \
+} while (0)
+
+
+////////////////
+// Hash Chain //
+////////////////
+
+#if defined(HAVE_MF_HC3) || defined(HAVE_MF_HC4)
+///
+///
+/// \param len_limit Don't look for matches longer than len_limit.
+/// \param pos lzma_mf.read_pos + lzma_mf.offset
+/// \param cur Pointer to current byte (mf_ptr(mf))
+/// \param cur_match Start position of the current match candidate
+/// \param depth Maximum length of the hash chain
+/// \param son lzma_mf.son (contains the hash chain)
+/// \param cyclic_pos
+/// \param cyclic_size
+/// \param matches Array to hold the matches.
+/// \param len_best The length of the longest match found so far.
+static lzma_match *
+hc_find_func(
+ const uint32_t len_limit,
+ const uint32_t pos,
+ const uint8_t *const cur,
+ uint32_t cur_match,
+ uint32_t depth,
+ uint32_t *const son,
+ const uint32_t cyclic_pos,
+ const uint32_t cyclic_size,
+ lzma_match *matches,
+ uint32_t len_best)
+{
+ son[cyclic_pos] = cur_match;
+
+ while (true) {
+ const uint32_t delta = pos - cur_match;
+ const uint8_t *pb;
+ if (depth-- == 0 || delta >= cyclic_size)
+ return matches;
+
+ pb = cur - delta;
+ cur_match = son[cyclic_pos - delta
+ + (delta > cyclic_pos ? cyclic_size : 0)];
+
+ if (pb[len_best] == cur[len_best] && pb[0] == cur[0]) {
+ uint32_t len = 0;
+ while (++len != len_limit)
+ if (pb[len] != cur[len])
+ break;
+
+ if (len_best < len) {
+ len_best = len;
+ matches->len = len;
+ matches->dist = delta - 1;
+ ++matches;
+
+ if (len == len_limit)
+ return matches;
+ }
+ }
+ }
+}
+
+
+#define hc_find(len_best) \
+ call_find(hc_find_func, len_best)
+
+
+#define hc_skip() \
+do { \
+ mf->son[mf->cyclic_pos] = cur_match; \
+ move_pos(mf); \
+} while (0)
+
+#endif
+
+
+#ifdef HAVE_MF_HC3
+extern uint32_t
+lzma_mf_hc3_find(lzma_mf *mf, lzma_match *matches)
+{
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t temp, hash_value, hash_2_value; /* hash_3_calc */
+ uint32_t delta2, cur_match;
+ uint32_t len_best = 2;
+ uint32_t matches_count = 0;
+
+ header_find(false, 3);
+
+ hash_3_calc();
+
+ delta2 = pos - mf->hash[hash_2_value];
+ cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value];
+
+ mf->hash[hash_2_value] = pos;
+ mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;
+
+ if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
+ for ( ; len_best != len_limit; ++len_best)
+ if (*(cur + len_best - delta2) != cur[len_best])
+ break;
+
+ matches[0].len = len_best;
+ matches[0].dist = delta2 - 1;
+ matches_count = 1;
+
+ if (len_best == len_limit) {
+ hc_skip();
+ return 1; // matches_count
+ }
+ }
+
+ hc_find(len_best);
+}
+
+
+extern void
+lzma_mf_hc3_skip(lzma_mf *mf, uint32_t amount)
+{
+ do {
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t temp, hash_value, hash_2_value; /* hash_3_calc */
+ uint32_t cur_match;
+
+ if (mf_avail(mf) < 3) {
+ move_pending(mf);
+ continue;
+ }
+
+ cur = mf_ptr(mf);
+ pos = mf->read_pos + mf->offset;
+
+ hash_3_calc();
+
+ cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value];
+
+ mf->hash[hash_2_value] = pos;
+ mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;
+
+ hc_skip();
+
+ } while (--amount != 0);
+}
+#endif
+
+
+#ifdef HAVE_MF_HC4
+extern uint32_t
+lzma_mf_hc4_find(lzma_mf *mf, lzma_match *matches)
+{
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t temp, hash_value, hash_2_value, hash_3_value; /* hash_4_calc */
+ uint32_t delta2, delta3, cur_match;
+ uint32_t len_best = 1;
+ uint32_t matches_count = 0;
+
+ header_find(false, 4);
+
+ hash_4_calc();
+
+ delta2 = pos - mf->hash[hash_2_value];
+ delta3 = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value];
+ cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value];
+
+ mf->hash[hash_2_value ] = pos;
+ mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
+ mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;
+
+ if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
+ len_best = 2;
+ matches[0].len = 2;
+ matches[0].dist = delta2 - 1;
+ matches_count = 1;
+ }
+
+ if (delta2 != delta3 && delta3 < mf->cyclic_size
+ && *(cur - delta3) == *cur) {
+ len_best = 3;
+ matches[matches_count++].dist = delta3 - 1;
+ delta2 = delta3;
+ }
+
+ if (matches_count != 0) {
+ for ( ; len_best != len_limit; ++len_best)
+ if (*(cur + len_best - delta2) != cur[len_best])
+ break;
+
+ matches[matches_count - 1].len = len_best;
+
+ if (len_best == len_limit) {
+ hc_skip();
+ return matches_count;
+ }
+ }
+
+ if (len_best < 3)
+ len_best = 3;
+
+ hc_find(len_best);
+}
+
+
+extern void
+lzma_mf_hc4_skip(lzma_mf *mf, uint32_t amount)
+{
+ do {
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t temp, hash_value, hash_2_value, hash_3_value; /* hash_4_calc */
+ uint32_t cur_match;
+
+ if (mf_avail(mf) < 4) {
+ move_pending(mf);
+ continue;
+ }
+
+ cur = mf_ptr(mf);
+ pos = mf->read_pos + mf->offset;
+
+ hash_4_calc();
+
+ cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value];
+
+ mf->hash[hash_2_value] = pos;
+ mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
+ mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;
+
+ hc_skip();
+
+ } while (--amount != 0);
+}
+#endif
+
+
+/////////////////
+// Binary Tree //
+/////////////////
+
+#if defined(HAVE_MF_BT2) || defined(HAVE_MF_BT3) || defined(HAVE_MF_BT4)
+static lzma_match *
+bt_find_func(
+ const uint32_t len_limit,
+ const uint32_t pos,
+ const uint8_t *const cur,
+ uint32_t cur_match,
+ uint32_t depth,
+ uint32_t *const son,
+ const uint32_t cyclic_pos,
+ const uint32_t cyclic_size,
+ lzma_match *matches,
+ uint32_t len_best)
+{
+ uint32_t *ptr0 = son + (cyclic_pos << 1) + 1;
+ uint32_t *ptr1 = son + (cyclic_pos << 1);
+
+ uint32_t len0 = 0;
+ uint32_t len1 = 0;
+
+ while (true) {
+ uint32_t *pair;
+ const uint8_t *pb;
+ uint32_t len;
+
+ const uint32_t delta = pos - cur_match;
+ if (depth-- == 0 || delta >= cyclic_size) {
+ *ptr0 = EMPTY_HASH_VALUE;
+ *ptr1 = EMPTY_HASH_VALUE;
+ return matches;
+ }
+
+ pair = son + ((cyclic_pos - delta
+ + (delta > cyclic_pos ? cyclic_size : 0))
+ << 1);
+
+ pb = cur - delta;
+ len = my_min(len0, len1);
+
+ if (pb[len] == cur[len]) {
+ while (++len != len_limit)
+ if (pb[len] != cur[len])
+ break;
+
+ if (len_best < len) {
+ len_best = len;
+ matches->len = len;
+ matches->dist = delta - 1;
+ ++matches;
+
+ if (len == len_limit) {
+ *ptr1 = pair[0];
+ *ptr0 = pair[1];
+ return matches;
+ }
+ }
+ }
+
+ if (pb[len] < cur[len]) {
+ *ptr1 = cur_match;
+ ptr1 = pair + 1;
+ cur_match = *ptr1;
+ len1 = len;
+ } else {
+ *ptr0 = cur_match;
+ ptr0 = pair;
+ cur_match = *ptr0;
+ len0 = len;
+ }
+ }
+}
+
+
+static void
+bt_skip_func(
+ const uint32_t len_limit,
+ const uint32_t pos,
+ const uint8_t *const cur,
+ uint32_t cur_match,
+ uint32_t depth,
+ uint32_t *const son,
+ const uint32_t cyclic_pos,
+ const uint32_t cyclic_size)
+{
+ uint32_t *ptr0 = son + (cyclic_pos << 1) + 1;
+ uint32_t *ptr1 = son + (cyclic_pos << 1);
+
+ uint32_t len0 = 0;
+ uint32_t len1 = 0;
+
+ while (true) {
+ uint32_t *pair;
+ const uint8_t *pb;
+ uint32_t len;
+
+ const uint32_t delta = pos - cur_match;
+ if (depth-- == 0 || delta >= cyclic_size) {
+ *ptr0 = EMPTY_HASH_VALUE;
+ *ptr1 = EMPTY_HASH_VALUE;
+ return;
+ }
+
+ pair = son + ((cyclic_pos - delta
+ + (delta > cyclic_pos ? cyclic_size : 0))
+ << 1);
+ pb = cur - delta;
+ len = my_min(len0, len1);
+
+ if (pb[len] == cur[len]) {
+ while (++len != len_limit)
+ if (pb[len] != cur[len])
+ break;
+
+ if (len == len_limit) {
+ *ptr1 = pair[0];
+ *ptr0 = pair[1];
+ return;
+ }
+ }
+
+ if (pb[len] < cur[len]) {
+ *ptr1 = cur_match;
+ ptr1 = pair + 1;
+ cur_match = *ptr1;
+ len1 = len;
+ } else {
+ *ptr0 = cur_match;
+ ptr0 = pair;
+ cur_match = *ptr0;
+ len0 = len;
+ }
+ }
+}
+
+
+#define bt_find(len_best) \
+ call_find(bt_find_func, len_best)
+
+#define bt_skip() \
+do { \
+ bt_skip_func(len_limit, pos, cur, cur_match, mf->depth, \
+ mf->son, mf->cyclic_pos, \
+ mf->cyclic_size); \
+ move_pos(mf); \
+} while (0)
+
+#endif
+
+
+#ifdef HAVE_MF_BT2
+extern uint32_t
+lzma_mf_bt2_find(lzma_mf *mf, lzma_match *matches)
+{
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t hash_value; /* hash_2_calc */
+ uint32_t cur_match;
+ uint32_t matches_count = 0;
+
+ header_find(true, 2);
+
+ hash_2_calc();
+
+ cur_match = mf->hash[hash_value];
+ mf->hash[hash_value] = pos;
+
+ bt_find(1);
+}
+
+
+extern void
+lzma_mf_bt2_skip(lzma_mf *mf, uint32_t amount)
+{
+ do {
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t hash_value; /* hash_2_calc */
+ uint32_t cur_match;
+
+ header_skip(true, 2);
+
+ hash_2_calc();
+
+ cur_match = mf->hash[hash_value];
+ mf->hash[hash_value] = pos;
+
+ bt_skip();
+
+ } while (--amount != 0);
+}
+#endif
+
+
+#ifdef HAVE_MF_BT3
+extern uint32_t
+lzma_mf_bt3_find(lzma_mf *mf, lzma_match *matches)
+{
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t temp, hash_value, hash_2_value; /* hash_3_calc */
+ uint32_t delta2, cur_match;
+ uint32_t len_best = 2;
+ uint32_t matches_count = 0;
+
+ header_find(true, 3);
+
+ hash_3_calc();
+
+ delta2 = pos - mf->hash[hash_2_value];
+ cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value];
+
+ mf->hash[hash_2_value] = pos;
+ mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;
+
+ if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
+ for ( ; len_best != len_limit; ++len_best)
+ if (*(cur + len_best - delta2) != cur[len_best])
+ break;
+
+ matches[0].len = len_best;
+ matches[0].dist = delta2 - 1;
+ matches_count = 1;
+
+ if (len_best == len_limit) {
+ bt_skip();
+ return 1; // matches_count
+ }
+ }
+
+ bt_find(len_best);
+}
+
+
+extern void
+lzma_mf_bt3_skip(lzma_mf *mf, uint32_t amount)
+{
+ do {
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t temp, hash_value, hash_2_value; /* hash_3_calc */
+ uint32_t cur_match;
+
+ header_skip(true, 3);
+
+ hash_3_calc();
+
+ cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value];
+
+ mf->hash[hash_2_value] = pos;
+ mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;
+
+ bt_skip();
+
+ } while (--amount != 0);
+}
+#endif
+
+
+#ifdef HAVE_MF_BT4
+extern uint32_t
+lzma_mf_bt4_find(lzma_mf *mf, lzma_match *matches)
+{
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t temp, hash_value, hash_2_value, hash_3_value; /* hash_4_calc */
+ uint32_t delta2, delta3, cur_match;
+ uint32_t len_best = 1;
+ uint32_t matches_count = 0;
+
+ header_find(true, 4);
+
+ hash_4_calc();
+
+ delta2 = pos - mf->hash[hash_2_value];
+ delta3 = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value];
+ cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value];
+
+ mf->hash[hash_2_value] = pos;
+ mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
+ mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;
+
+ if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
+ len_best = 2;
+ matches[0].len = 2;
+ matches[0].dist = delta2 - 1;
+ matches_count = 1;
+ }
+
+ if (delta2 != delta3 && delta3 < mf->cyclic_size
+ && *(cur - delta3) == *cur) {
+ len_best = 3;
+ matches[matches_count++].dist = delta3 - 1;
+ delta2 = delta3;
+ }
+
+ if (matches_count != 0) {
+ for ( ; len_best != len_limit; ++len_best)
+ if (*(cur + len_best - delta2) != cur[len_best])
+ break;
+
+ matches[matches_count - 1].len = len_best;
+
+ if (len_best == len_limit) {
+ bt_skip();
+ return matches_count;
+ }
+ }
+
+ if (len_best < 3)
+ len_best = 3;
+
+ bt_find(len_best);
+}
+
+
+extern void
+lzma_mf_bt4_skip(lzma_mf *mf, uint32_t amount)
+{
+ do {
+ const uint8_t *cur;
+ uint32_t pos;
+ uint32_t temp, hash_value, hash_2_value, hash_3_value; /* hash_4_calc */
+ uint32_t cur_match;
+
+ header_skip(true, 4);
+
+ hash_4_calc();
+
+ cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value];
+
+ mf->hash[hash_2_value] = pos;
+ mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
+ mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;
+
+ bt_skip();
+
+ } while (--amount != 0);
+}
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/fastpos.h b/Utilities/cmliblzma/liblzma/lzma/fastpos.h
new file mode 100644
index 0000000000..5a834d68d0
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/fastpos.h
@@ -0,0 +1,142 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file fastpos.h
+/// \brief Kind of two-bit version of bit scan reverse
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_FASTPOS_H
+#define LZMA_FASTPOS_H
+
+// LZMA encodes match distances (positions) by storing the highest two
+// bits using a six-bit value [0, 63], and then the missing lower bits.
+// Dictionary size is also stored using this encoding in the new .lzma
+// file format header.
+//
+// fastpos.h provides a way to quickly find out the correct six-bit
+// values. The following table gives some examples of this encoding:
+//
+// pos return
+// 0 0
+// 1 1
+// 2 2
+// 3 3
+// 4 4
+// 5 4
+// 6 5
+// 7 5
+// 8 6
+// 11 6
+// 12 7
+// ... ...
+// 15 7
+// 16 8
+// 17 8
+// ... ...
+// 23 8
+// 24 9
+// 25 9
+// ... ...
+//
+//
+// Provided functions or macros
+// ----------------------------
+//
+// get_pos_slot(pos) is the basic version. get_pos_slot_2(pos)
+// assumes that pos >= FULL_DISTANCES, thus the result is at least
+// FULL_DISTANCES_BITS * 2. Using get_pos_slot(pos) instead of
+// get_pos_slot_2(pos) would give the same result, but get_pos_slot_2(pos)
+// should be tiny bit faster due to the assumption being made.
+//
+//
+// Size vs. speed
+// --------------
+//
+// With some CPUs that have fast BSR (bit scan reverse) instruction, the
+// size optimized version is slightly faster than the bigger table based
+// approach. Such CPUs include Intel Pentium Pro, Pentium II, Pentium III
+// and Core 2 (possibly others). AMD K7 seems to have slower BSR, but that
+// would still have speed roughly comparable to the table version. Older
+// x86 CPUs like the original Pentium have very slow BSR; on those systems
+// the table version is a lot faster.
+//
+// On some CPUs, the table version is a lot faster when using position
+// dependent code, but with position independent code the size optimized
+// version is slightly faster. This occurs at least on 32-bit SPARC (no
+// ASM optimizations).
+//
+// I'm making the table version the default, because that has good speed
+// on all systems I have tried. The size optimized version is sometimes
+// slightly faster, but sometimes it is a lot slower.
+
+#include "config.h"
+
+#ifdef HAVE_SMALL
+# define get_pos_slot(pos) ((pos) <= 4 ? (pos) : get_pos_slot_2(pos))
+
+static inline uint32_t
+get_pos_slot_2(uint32_t pos)
+{
+ const uint32_t i = bsr32(pos);
+ return (i + i) + ((pos >> (i - 1)) & 1);
+}
+
+
+#else
+
+#define FASTPOS_BITS 13
+
+extern const uint8_t lzma_fastpos[1 << FASTPOS_BITS];
+
+
+#define fastpos_shift(extra, n) \
+ ((extra) + (n) * (FASTPOS_BITS - 1))
+
+#define fastpos_limit(extra, n) \
+ (UINT32_C(1) << (FASTPOS_BITS + fastpos_shift(extra, n)))
+
+#define fastpos_result(pos, extra, n) \
+ lzma_fastpos[(pos) >> fastpos_shift(extra, n)] \
+ + 2 * fastpos_shift(extra, n)
+
+
+static inline uint32_t
+get_pos_slot(uint32_t pos)
+{
+ // If it is small enough, we can pick the result directly from
+ // the precalculated table.
+ if (pos < fastpos_limit(0, 0))
+ return lzma_fastpos[pos];
+
+ if (pos < fastpos_limit(0, 1))
+ return fastpos_result(pos, 0, 1);
+
+ return fastpos_result(pos, 0, 2);
+}
+
+
+#ifdef FULL_DISTANCES_BITS
+static inline uint32_t
+get_pos_slot_2(uint32_t pos)
+{
+ assert(pos >= FULL_DISTANCES);
+
+ if (pos < fastpos_limit(FULL_DISTANCES_BITS - 1, 0))
+ return fastpos_result(pos, FULL_DISTANCES_BITS - 1, 0);
+
+ if (pos < fastpos_limit(FULL_DISTANCES_BITS - 1, 1))
+ return fastpos_result(pos, FULL_DISTANCES_BITS - 1, 1);
+
+ return fastpos_result(pos, FULL_DISTANCES_BITS - 1, 2);
+}
+#endif
+
+#endif
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/fastpos_table.c b/Utilities/cmliblzma/liblzma/lzma/fastpos_table.c
new file mode 100644
index 0000000000..6a3ceac0e9
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/fastpos_table.c
@@ -0,0 +1,519 @@
+/* This file has been automatically generated by fastpos_tablegen.c. */
+
+#include "common.h"
+#include "fastpos.h"
+
+const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {
+ 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
+ 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
+ 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,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25
+};
diff --git a/Utilities/cmliblzma/liblzma/lzma/fastpos_tablegen.c b/Utilities/cmliblzma/liblzma/lzma/fastpos_tablegen.c
new file mode 100644
index 0000000000..c97e6f411c
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/fastpos_tablegen.c
@@ -0,0 +1,56 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file fastpos_tablegen.c
+/// \brief Generates the lzma_fastpos[] lookup table
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include "fastpos.h"
+
+
+int
+main(void)
+{
+ uint8_t fastpos[1 << FASTPOS_BITS];
+
+ const uint8_t fast_slots = 2 * FASTPOS_BITS;
+ uint32_t c = 2;
+
+ fastpos[0] = 0;
+ fastpos[1] = 1;
+
+ for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) {
+ const uint32_t k = 1 << ((slot_fast >> 1) - 1);
+ for (uint32_t j = 0; j < k; ++j, ++c)
+ fastpos[c] = slot_fast;
+ }
+
+ printf("/* This file has been automatically generated "
+ "by fastpos_tablegen.c. */\n\n"
+ "#include \"common.h\"\n"
+ "#include \"fastpos.h\"\n\n"
+ "const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {");
+
+ for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) {
+ if (i % 16 == 0)
+ printf("\n\t");
+
+ printf("%3u", (unsigned int)(fastpos[i]));
+
+ if (i != (1 << FASTPOS_BITS) - 1)
+ printf(",");
+ }
+
+ printf("\n};\n");
+
+ return 0;
+}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c b/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c
new file mode 100644
index 0000000000..bd2a737823
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c
@@ -0,0 +1,305 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma2_decoder.c
+/// \brief LZMA2 decoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "lzma2_decoder.h"
+#include "lz_decoder.h"
+#include "lzma_decoder.h"
+
+
+struct lzma_coder_s {
+ enum sequence {
+ SEQ_CONTROL,
+ SEQ_UNCOMPRESSED_1,
+ SEQ_UNCOMPRESSED_2,
+ SEQ_COMPRESSED_0,
+ SEQ_COMPRESSED_1,
+ SEQ_PROPERTIES,
+ SEQ_LZMA,
+ SEQ_COPY,
+ } sequence;
+
+ /// Sequence after the size fields have been decoded.
+ enum sequence next_sequence;
+
+ /// LZMA decoder
+ lzma_lz_decoder lzma;
+
+ /// Uncompressed size of LZMA chunk
+ size_t uncompressed_size;
+
+ /// Compressed size of the chunk (naturally equals to uncompressed
+ /// size of uncompressed chunk)
+ size_t compressed_size;
+
+ /// True if properties are needed. This is false before the
+ /// first LZMA chunk.
+ bool need_properties;
+
+ /// True if dictionary reset is needed. This is false before the
+ /// first chunk (LZMA or uncompressed).
+ bool need_dictionary_reset;
+
+ lzma_options_lzma options;
+};
+
+
+static lzma_ret
+lzma2_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dict,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size)
+{
+ // With SEQ_LZMA it is possible that no new input is needed to do
+ // some progress. The rest of the sequences assume that there is
+ // at least one byte of input.
+ while (*in_pos < in_size || coder->sequence == SEQ_LZMA)
+ switch (coder->sequence) {
+ case SEQ_CONTROL: {
+ const uint32_t control = in[*in_pos];
+ ++*in_pos;
+
+ // End marker
+ if (control == 0x00)
+ return LZMA_STREAM_END;
+
+ if (control >= 0xE0 || control == 1) {
+ // Dictionary reset implies that next LZMA chunk has
+ // to set new properties.
+ coder->need_properties = true;
+ coder->need_dictionary_reset = true;
+ } else if (coder->need_dictionary_reset) {
+ return LZMA_DATA_ERROR;
+ }
+
+ if (control >= 0x80) {
+ // LZMA chunk. The highest five bits of the
+ // uncompressed size are taken from the control byte.
+ coder->uncompressed_size = (control & 0x1F) << 16;
+ coder->sequence = SEQ_UNCOMPRESSED_1;
+
+ // See if there are new properties or if we need to
+ // reset the state.
+ if (control >= 0xC0) {
+ // When there are new properties, state reset
+ // is done at SEQ_PROPERTIES.
+ coder->need_properties = false;
+ coder->next_sequence = SEQ_PROPERTIES;
+
+ } else if (coder->need_properties) {
+ return LZMA_DATA_ERROR;
+
+ } else {
+ coder->next_sequence = SEQ_LZMA;
+
+ // If only state reset is wanted with old
+ // properties, do the resetting here for
+ // simplicity.
+ if (control >= 0xA0)
+ coder->lzma.reset(coder->lzma.coder,
+ &coder->options);
+ }
+ } else {
+ // Invalid control values
+ if (control > 2)
+ return LZMA_DATA_ERROR;
+
+ // It's uncompressed chunk
+ coder->sequence = SEQ_COMPRESSED_0;
+ coder->next_sequence = SEQ_COPY;
+ }
+
+ if (coder->need_dictionary_reset) {
+ // Finish the dictionary reset and let the caller
+ // flush the dictionary to the actual output buffer.
+ coder->need_dictionary_reset = false;
+ dict_reset(dict);
+ return LZMA_OK;
+ }
+
+ break;
+ }
+
+ case SEQ_UNCOMPRESSED_1:
+ coder->uncompressed_size += (uint32_t)(in[(*in_pos)++]) << 8;
+ coder->sequence = SEQ_UNCOMPRESSED_2;
+ break;
+
+ case SEQ_UNCOMPRESSED_2:
+ coder->uncompressed_size += in[(*in_pos)++] + 1;
+ coder->sequence = SEQ_COMPRESSED_0;
+ coder->lzma.set_uncompressed(coder->lzma.coder,
+ coder->uncompressed_size);
+ break;
+
+ case SEQ_COMPRESSED_0:
+ coder->compressed_size = (uint32_t)(in[(*in_pos)++]) << 8;
+ coder->sequence = SEQ_COMPRESSED_1;
+ break;
+
+ case SEQ_COMPRESSED_1:
+ coder->compressed_size += in[(*in_pos)++] + 1;
+ coder->sequence = coder->next_sequence;
+ break;
+
+ case SEQ_PROPERTIES:
+ if (lzma_lzma_lclppb_decode(&coder->options, in[(*in_pos)++]))
+ return LZMA_DATA_ERROR;
+
+ coder->lzma.reset(coder->lzma.coder, &coder->options);
+
+ coder->sequence = SEQ_LZMA;
+ break;
+
+ case SEQ_LZMA: {
+ // Store the start offset so that we can update
+ // coder->compressed_size later.
+ const size_t in_start = *in_pos;
+
+ // Decode from in[] to *dict.
+ const lzma_ret ret = coder->lzma.code(coder->lzma.coder,
+ dict, in, in_pos, in_size);
+
+ // Validate and update coder->compressed_size.
+ const size_t in_used = *in_pos - in_start;
+ if (in_used > coder->compressed_size)
+ return LZMA_DATA_ERROR;
+
+ coder->compressed_size -= in_used;
+
+ // Return if we didn't finish the chunk, or an error occurred.
+ if (ret != LZMA_STREAM_END)
+ return ret;
+
+ // The LZMA decoder must have consumed the whole chunk now.
+ // We don't need to worry about uncompressed size since it
+ // is checked by the LZMA decoder.
+ if (coder->compressed_size != 0)
+ return LZMA_DATA_ERROR;
+
+ coder->sequence = SEQ_CONTROL;
+ break;
+ }
+
+ case SEQ_COPY: {
+ // Copy from input to the dictionary as is.
+ dict_write(dict, in, in_pos, in_size, &coder->compressed_size);
+ if (coder->compressed_size != 0)
+ return LZMA_OK;
+
+ coder->sequence = SEQ_CONTROL;
+ break;
+ }
+
+ default:
+ assert(0);
+ return LZMA_PROG_ERROR;
+ }
+
+ return LZMA_OK;
+}
+
+
+static void
+lzma2_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ assert(coder->lzma.end == NULL);
+ lzma_free(coder->lzma.coder, allocator);
+
+ lzma_free(coder, allocator);
+
+ return;
+}
+
+
+static lzma_ret
+lzma2_decoder_init(lzma_lz_decoder *lz, lzma_allocator *allocator,
+ const void *opt, lzma_lz_options *lz_options)
+{
+ const lzma_options_lzma *options = opt;
+
+ if (lz->coder == NULL) {
+ lz->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (lz->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ lz->code = &lzma2_decode;
+ lz->end = &lzma2_decoder_end;
+
+ lz->coder->lzma = LZMA_LZ_DECODER_INIT;
+ }
+
+ lz->coder->sequence = SEQ_CONTROL;
+ lz->coder->need_properties = true;
+ lz->coder->need_dictionary_reset = options->preset_dict == NULL
+ || options->preset_dict_size == 0;
+
+ return lzma_lzma_decoder_create(&lz->coder->lzma,
+ allocator, options, lz_options);
+}
+
+
+extern lzma_ret
+lzma_lzma2_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ // LZMA2 can only be the last filter in the chain. This is enforced
+ // by the raw_decoder initialization.
+ assert(filters[1].init == NULL);
+
+ return lzma_lz_decoder_init(next, allocator, filters,
+ &lzma2_decoder_init);
+}
+
+
+extern uint64_t
+lzma_lzma2_decoder_memusage(const void *options)
+{
+ return sizeof(lzma_coder)
+ + lzma_lzma_decoder_memusage_nocheck(options);
+}
+
+
+extern lzma_ret
+lzma_lzma2_props_decode(void **options, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size)
+{
+ lzma_options_lzma *opt;
+
+ if (props_size != 1)
+ return LZMA_OPTIONS_ERROR;
+
+ // Check that reserved bits are unset.
+ if (props[0] & 0xC0)
+ return LZMA_OPTIONS_ERROR;
+
+ // Decode the dictionary size.
+ if (props[0] > 40)
+ return LZMA_OPTIONS_ERROR;
+
+ opt = lzma_alloc(sizeof(lzma_options_lzma), allocator);
+ if (opt == NULL)
+ return LZMA_MEM_ERROR;
+
+ if (props[0] == 40) {
+ opt->dict_size = UINT32_MAX;
+ } else {
+ opt->dict_size = 2 | (props[0] & 1);
+ opt->dict_size <<= props[0] / 2 + 11;
+ }
+
+ opt->preset_dict = NULL;
+ opt->preset_dict_size = 0;
+
+ *options = opt;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h b/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h
new file mode 100644
index 0000000000..fac4ac487b
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h
@@ -0,0 +1,28 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma2_decoder.h
+/// \brief LZMA2 decoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_LZMA2_DECODER_H
+#define LZMA_LZMA2_DECODER_H
+
+#include "common.h"
+
+extern lzma_ret lzma_lzma2_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern uint64_t lzma_lzma2_decoder_memusage(const void *options);
+
+extern lzma_ret lzma_lzma2_props_decode(
+ void **options, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.c b/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.c
new file mode 100644
index 0000000000..a3651a7c6f
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.c
@@ -0,0 +1,399 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma2_encoder.c
+/// \brief LZMA2 encoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "lz_encoder.h"
+#include "lzma_encoder.h"
+#include "fastpos.h"
+#include "lzma2_encoder.h"
+
+
+struct lzma_coder_s {
+ enum {
+ SEQ_INIT,
+ SEQ_LZMA_ENCODE,
+ SEQ_LZMA_COPY,
+ SEQ_UNCOMPRESSED_HEADER,
+ SEQ_UNCOMPRESSED_COPY,
+ } sequence;
+
+ /// LZMA encoder
+ lzma_coder *lzma;
+
+ /// LZMA options currently in use.
+ lzma_options_lzma opt_cur;
+
+ bool need_properties;
+ bool need_state_reset;
+ bool need_dictionary_reset;
+
+ /// Uncompressed size of a chunk
+ size_t uncompressed_size;
+
+ /// Compressed size of a chunk (excluding headers); this is also used
+ /// to indicate the end of buf[] in SEQ_LZMA_COPY.
+ size_t compressed_size;
+
+ /// Read position in buf[]
+ size_t buf_pos;
+
+ /// Buffer to hold the chunk header and LZMA compressed data
+ uint8_t buf[LZMA2_HEADER_MAX + LZMA2_CHUNK_MAX];
+};
+
+
+static void
+lzma2_header_lzma(lzma_coder *coder)
+{
+ size_t pos;
+ size_t size;
+
+ assert(coder->uncompressed_size > 0);
+ assert(coder->uncompressed_size <= LZMA2_UNCOMPRESSED_MAX);
+ assert(coder->compressed_size > 0);
+ assert(coder->compressed_size <= LZMA2_CHUNK_MAX);
+
+ if (coder->need_properties) {
+ pos = 0;
+
+ if (coder->need_dictionary_reset)
+ coder->buf[pos] = 0x80 + (3 << 5);
+ else
+ coder->buf[pos] = 0x80 + (2 << 5);
+ } else {
+ pos = 1;
+
+ if (coder->need_state_reset)
+ coder->buf[pos] = 0x80 + (1 << 5);
+ else
+ coder->buf[pos] = 0x80;
+ }
+
+ // Set the start position for copying.
+ coder->buf_pos = pos;
+
+ // Uncompressed size
+ size = coder->uncompressed_size - 1;
+ coder->buf[pos++] += size >> 16;
+ coder->buf[pos++] = (size >> 8) & 0xFF;
+ coder->buf[pos++] = size & 0xFF;
+
+ // Compressed size
+ size = coder->compressed_size - 1;
+ coder->buf[pos++] = size >> 8;
+ coder->buf[pos++] = size & 0xFF;
+
+ // Properties, if needed
+ if (coder->need_properties)
+ lzma_lzma_lclppb_encode(&coder->opt_cur, coder->buf + pos);
+
+ coder->need_properties = false;
+ coder->need_state_reset = false;
+ coder->need_dictionary_reset = false;
+
+ // The copying code uses coder->compressed_size to indicate the end
+ // of coder->buf[], so we need add the maximum size of the header here.
+ coder->compressed_size += LZMA2_HEADER_MAX;
+
+ return;
+}
+
+
+static void
+lzma2_header_uncompressed(lzma_coder *coder)
+{
+ assert(coder->uncompressed_size > 0);
+ assert(coder->uncompressed_size <= LZMA2_CHUNK_MAX);
+
+ // If this is the first chunk, we need to include dictionary
+ // reset indicator.
+ if (coder->need_dictionary_reset)
+ coder->buf[0] = 1;
+ else
+ coder->buf[0] = 2;
+
+ coder->need_dictionary_reset = false;
+
+ // "Compressed" size
+ coder->buf[1] = (coder->uncompressed_size - 1) >> 8;
+ coder->buf[2] = (coder->uncompressed_size - 1) & 0xFF;
+
+ // Set the start position for copying.
+ coder->buf_pos = 0;
+ return;
+}
+
+
+static lzma_ret
+lzma2_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
+ uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
+ size_t out_size)
+{
+ while (*out_pos < out_size)
+ switch (coder->sequence) {
+ case SEQ_INIT:
+ // If there's no input left and we are flushing or finishing,
+ // don't start a new chunk.
+ if (mf_unencoded(mf) == 0) {
+ // Write end of payload marker if finishing.
+ if (mf->action == LZMA_FINISH)
+ out[(*out_pos)++] = 0;
+
+ return mf->action == LZMA_RUN
+ ? LZMA_OK : LZMA_STREAM_END;
+ }
+
+ if (coder->need_state_reset)
+ return_if_error(lzma_lzma_encoder_reset(
+ coder->lzma, &coder->opt_cur));
+
+ coder->uncompressed_size = 0;
+ coder->compressed_size = 0;
+ coder->sequence = SEQ_LZMA_ENCODE;
+
+ // Fall through
+
+ case SEQ_LZMA_ENCODE: {
+ uint32_t read_start;
+ lzma_ret ret;
+
+ // Calculate how much more uncompressed data this chunk
+ // could accept.
+ const uint32_t left = LZMA2_UNCOMPRESSED_MAX
+ - coder->uncompressed_size;
+ uint32_t limit;
+
+ if (left < mf->match_len_max) {
+ // Must flush immediately since the next LZMA symbol
+ // could make the uncompressed size of the chunk too
+ // big.
+ limit = 0;
+ } else {
+ // Calculate maximum read_limit that is OK from point
+ // of view of LZMA2 chunk size.
+ limit = mf->read_pos - mf->read_ahead
+ + left - mf->match_len_max;
+ }
+
+ // Save the start position so that we can update
+ // coder->uncompressed_size.
+ read_start = mf->read_pos - mf->read_ahead;
+
+ // Call the LZMA encoder until the chunk is finished.
+ ret = lzma_lzma_encode(coder->lzma, mf,
+ coder->buf + LZMA2_HEADER_MAX,
+ &coder->compressed_size,
+ LZMA2_CHUNK_MAX, limit);
+
+ coder->uncompressed_size += mf->read_pos - mf->read_ahead
+ - read_start;
+
+ assert(coder->compressed_size <= LZMA2_CHUNK_MAX);
+ assert(coder->uncompressed_size <= LZMA2_UNCOMPRESSED_MAX);
+
+ if (ret != LZMA_STREAM_END)
+ return LZMA_OK;
+
+ // See if the chunk compressed. If it didn't, we encode it
+ // as uncompressed chunk. This saves a few bytes of space
+ // and makes decoding faster.
+ if (coder->compressed_size >= coder->uncompressed_size) {
+ coder->uncompressed_size += mf->read_ahead;
+ assert(coder->uncompressed_size
+ <= LZMA2_UNCOMPRESSED_MAX);
+ mf->read_ahead = 0;
+ lzma2_header_uncompressed(coder);
+ coder->need_state_reset = true;
+ coder->sequence = SEQ_UNCOMPRESSED_HEADER;
+ break;
+ }
+
+ // The chunk did compress at least by one byte, so we store
+ // the chunk as LZMA.
+ lzma2_header_lzma(coder);
+
+ coder->sequence = SEQ_LZMA_COPY;
+ }
+
+ // Fall through
+
+ case SEQ_LZMA_COPY:
+ // Copy the compressed chunk along its headers to the
+ // output buffer.
+ lzma_bufcpy(coder->buf, &coder->buf_pos,
+ coder->compressed_size,
+ out, out_pos, out_size);
+ if (coder->buf_pos != coder->compressed_size)
+ return LZMA_OK;
+
+ coder->sequence = SEQ_INIT;
+ break;
+
+ case SEQ_UNCOMPRESSED_HEADER:
+ // Copy the three-byte header to indicate uncompressed chunk.
+ lzma_bufcpy(coder->buf, &coder->buf_pos,
+ LZMA2_HEADER_UNCOMPRESSED,
+ out, out_pos, out_size);
+ if (coder->buf_pos != LZMA2_HEADER_UNCOMPRESSED)
+ return LZMA_OK;
+
+ coder->sequence = SEQ_UNCOMPRESSED_COPY;
+
+ // Fall through
+
+ case SEQ_UNCOMPRESSED_COPY:
+ // Copy the uncompressed data as is from the dictionary
+ // to the output buffer.
+ mf_read(mf, out, out_pos, out_size, &coder->uncompressed_size);
+ if (coder->uncompressed_size != 0)
+ return LZMA_OK;
+
+ coder->sequence = SEQ_INIT;
+ break;
+ }
+
+ return LZMA_OK;
+}
+
+
+static void
+lzma2_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_free(coder->lzma, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static lzma_ret
+lzma2_encoder_options_update(lzma_coder *coder, const lzma_filter *filter)
+{
+ lzma_options_lzma *opt;
+
+ // New options can be set only when there is no incomplete chunk.
+ // This is the case at the beginning of the raw stream and right
+ // after LZMA_SYNC_FLUSH.
+ if (filter->options == NULL || coder->sequence != SEQ_INIT)
+ return LZMA_PROG_ERROR;
+
+ // Look if there are new options. At least for now,
+ // only lc/lp/pb can be changed.
+ opt = filter->options;
+ if (coder->opt_cur.lc != opt->lc || coder->opt_cur.lp != opt->lp
+ || coder->opt_cur.pb != opt->pb) {
+ // Validate the options.
+ if (opt->lc > LZMA_LCLP_MAX || opt->lp > LZMA_LCLP_MAX
+ || opt->lc + opt->lp > LZMA_LCLP_MAX
+ || opt->pb > LZMA_PB_MAX)
+ return LZMA_OPTIONS_ERROR;
+
+ // The new options will be used when the encoder starts
+ // a new LZMA2 chunk.
+ coder->opt_cur.lc = opt->lc;
+ coder->opt_cur.lp = opt->lp;
+ coder->opt_cur.pb = opt->pb;
+ coder->need_properties = true;
+ coder->need_state_reset = true;
+ }
+
+ return LZMA_OK;
+}
+
+
+static lzma_ret
+lzma2_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator,
+ const void *options, lzma_lz_options *lz_options)
+{
+ if (options == NULL)
+ return LZMA_PROG_ERROR;
+
+ if (lz->coder == NULL) {
+ lz->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (lz->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ lz->code = &lzma2_encode;
+ lz->end = &lzma2_encoder_end;
+ lz->options_update = &lzma2_encoder_options_update;
+
+ lz->coder->lzma = NULL;
+ }
+
+ lz->coder->opt_cur = *(const lzma_options_lzma *)(options);
+
+ lz->coder->sequence = SEQ_INIT;
+ lz->coder->need_properties = true;
+ lz->coder->need_state_reset = false;
+ lz->coder->need_dictionary_reset
+ = lz->coder->opt_cur.preset_dict == NULL
+ || lz->coder->opt_cur.preset_dict_size == 0;
+
+ // Initialize LZMA encoder
+ return_if_error(lzma_lzma_encoder_create(&lz->coder->lzma, allocator,
+ &lz->coder->opt_cur, lz_options));
+
+ // Make sure that we will always have enough history available in
+ // case we need to use uncompressed chunks. They are used when the
+ // compressed size of a chunk is not smaller than the uncompressed
+ // size, so we need to have at least LZMA2_COMPRESSED_MAX bytes
+ // history available.
+ if (lz_options->before_size + lz_options->dict_size < LZMA2_CHUNK_MAX)
+ lz_options->before_size
+ = LZMA2_CHUNK_MAX - lz_options->dict_size;
+
+ return LZMA_OK;
+}
+
+
+extern lzma_ret
+lzma_lzma2_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ return lzma_lz_encoder_init(
+ next, allocator, filters, &lzma2_encoder_init);
+}
+
+
+extern uint64_t
+lzma_lzma2_encoder_memusage(const void *options)
+{
+ const uint64_t lzma_mem = lzma_lzma_encoder_memusage(options);
+ if (lzma_mem == UINT64_MAX)
+ return UINT64_MAX;
+
+ return sizeof(lzma_coder) + lzma_mem;
+}
+
+
+extern lzma_ret
+lzma_lzma2_props_encode(const void *options, uint8_t *out)
+{
+ const lzma_options_lzma *const opt = options;
+ uint32_t d = my_max(opt->dict_size, LZMA_DICT_SIZE_MIN);
+
+ // Round up to the next 2^n - 1 or 2^n + 2^(n - 1) - 1 depending
+ // on which one is the next:
+ --d;
+ d |= d >> 2;
+ d |= d >> 3;
+ d |= d >> 4;
+ d |= d >> 8;
+ d |= d >> 16;
+
+ // Get the highest two bits using the proper encoding:
+ if (d == UINT32_MAX)
+ out[0] = 40;
+ else
+ out[0] = get_pos_slot(d + 1) - 24;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.h b/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.h
new file mode 100644
index 0000000000..ca19ef4691
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.h
@@ -0,0 +1,41 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma2_encoder.h
+/// \brief LZMA2 encoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_LZMA2_ENCODER_H
+#define LZMA_LZMA2_ENCODER_H
+
+#include "common.h"
+
+
+/// Maximum number of bytes of actual data per chunk (no headers)
+#define LZMA2_CHUNK_MAX (UINT32_C(1) << 16)
+
+/// Maximum uncompressed size of LZMA chunk (no headers)
+#define LZMA2_UNCOMPRESSED_MAX (UINT32_C(1) << 21)
+
+/// Maximum size of LZMA2 headers
+#define LZMA2_HEADER_MAX 6
+
+/// Size of a header for uncompressed chunk
+#define LZMA2_HEADER_UNCOMPRESSED 3
+
+
+extern lzma_ret lzma_lzma2_encoder_init(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters);
+
+extern uint64_t lzma_lzma2_encoder_memusage(const void *options);
+
+extern lzma_ret lzma_lzma2_props_encode(const void *options, uint8_t *out);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_common.h b/Utilities/cmliblzma/liblzma/lzma/lzma_common.h
new file mode 100644
index 0000000000..36267dc88a
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_common.h
@@ -0,0 +1,226 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma_common.h
+/// \brief Private definitions common to LZMA encoder and decoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_LZMA_COMMON_H
+#define LZMA_LZMA_COMMON_H
+
+#include "common.h"
+#include "range_common.h"
+
+
+///////////////////
+// Miscellaneous //
+///////////////////
+
+/// Maximum number of position states. A position state is the lowest pos bits
+/// number of bits of the current uncompressed offset. In some places there
+/// are different sets of probabilities for different pos states.
+#define POS_STATES_MAX (1 << LZMA_PB_MAX)
+
+
+/// Validates lc, lp, and pb.
+static inline bool
+is_lclppb_valid(const lzma_options_lzma *options)
+{
+ return options->lc <= LZMA_LCLP_MAX && options->lp <= LZMA_LCLP_MAX
+ && options->lc + options->lp <= LZMA_LCLP_MAX
+ && options->pb <= LZMA_PB_MAX;
+}
+
+
+///////////
+// State //
+///////////
+
+/// This enum is used to track which events have occurred most recently and
+/// in which order. This information is used to predict the next event.
+///
+/// Events:
+/// - Literal: One 8-bit byte
+/// - Match: Repeat a chunk of data at some distance
+/// - Long repeat: Multi-byte match at a recently seen distance
+/// - Short repeat: One-byte repeat at a recently seen distance
+///
+/// The event names are in from STATE_oldest_older_previous. REP means
+/// either short or long repeated match, and NONLIT means any non-literal.
+typedef enum {
+ STATE_LIT_LIT,
+ STATE_MATCH_LIT_LIT,
+ STATE_REP_LIT_LIT,
+ STATE_SHORTREP_LIT_LIT,
+ STATE_MATCH_LIT,
+ STATE_REP_LIT,
+ STATE_SHORTREP_LIT,
+ STATE_LIT_MATCH,
+ STATE_LIT_LONGREP,
+ STATE_LIT_SHORTREP,
+ STATE_NONLIT_MATCH,
+ STATE_NONLIT_REP,
+} lzma_lzma_state;
+
+
+/// Total number of states
+#define STATES 12
+
+/// The lowest 7 states indicate that the previous state was a literal.
+#define LIT_STATES 7
+
+
+/// Indicate that the latest state was a literal.
+#define update_literal(state) \
+ state = ((state) <= STATE_SHORTREP_LIT_LIT \
+ ? STATE_LIT_LIT \
+ : ((state) <= STATE_LIT_SHORTREP \
+ ? (state) - 3 \
+ : (state) - 6))
+
+/// Indicate that the latest state was a match.
+#define update_match(state) \
+ state = ((state) < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH)
+
+/// Indicate that the latest state was a long repeated match.
+#define update_long_rep(state) \
+ state = ((state) < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP)
+
+/// Indicate that the latest state was a short match.
+#define update_short_rep(state) \
+ state = ((state) < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP)
+
+/// Test if the previous state was a literal.
+#define is_literal_state(state) \
+ ((state) < LIT_STATES)
+
+
+/////////////
+// Literal //
+/////////////
+
+/// Each literal coder is divided in three sections:
+/// - 0x001-0x0FF: Without match byte
+/// - 0x101-0x1FF: With match byte; match bit is 0
+/// - 0x201-0x2FF: With match byte; match bit is 1
+///
+/// Match byte is used when the previous LZMA symbol was something else than
+/// a literal (that is, it was some kind of match).
+#define LITERAL_CODER_SIZE 0x300
+
+/// Maximum number of literal coders
+#define LITERAL_CODERS_MAX (1 << LZMA_LCLP_MAX)
+
+/// Locate the literal coder for the next literal byte. The choice depends on
+/// - the lowest literal_pos_bits bits of the position of the current
+/// byte; and
+/// - the highest literal_context_bits bits of the previous byte.
+#define literal_subcoder(probs, lc, lp_mask, pos, prev_byte) \
+ ((probs)[(((pos) & lp_mask) << lc) + ((prev_byte) >> (8 - lc))])
+
+
+static inline void
+literal_init(probability (*probs)[LITERAL_CODER_SIZE],
+ uint32_t lc, uint32_t lp)
+{
+ uint32_t coders;
+ uint32_t i, j;
+
+ assert(lc + lp <= LZMA_LCLP_MAX);
+
+ coders = 1U << (lc + lp);
+
+ for (i = 0; i < coders; ++i)
+ for (j = 0; j < LITERAL_CODER_SIZE; ++j)
+ bit_reset(probs[i][j]);
+
+ return;
+}
+
+
+//////////////////
+// Match length //
+//////////////////
+
+// Minimum length of a match is two bytes.
+#define MATCH_LEN_MIN 2
+
+// Match length is encoded with 4, 5, or 10 bits.
+//
+// Length Bits
+// 2-9 4 = Choice=0 + 3 bits
+// 10-17 5 = Choice=1 + Choice2=0 + 3 bits
+// 18-273 10 = Choice=1 + Choice2=1 + 8 bits
+#define LEN_LOW_BITS 3
+#define LEN_LOW_SYMBOLS (1 << LEN_LOW_BITS)
+#define LEN_MID_BITS 3
+#define LEN_MID_SYMBOLS (1 << LEN_MID_BITS)
+#define LEN_HIGH_BITS 8
+#define LEN_HIGH_SYMBOLS (1 << LEN_HIGH_BITS)
+#define LEN_SYMBOLS (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS)
+
+// Maximum length of a match is 273 which is a result of the encoding
+// described above.
+#define MATCH_LEN_MAX (MATCH_LEN_MIN + LEN_SYMBOLS - 1)
+
+
+////////////////////
+// Match distance //
+////////////////////
+
+// Different set of probabilities is used for match distances that have very
+// short match length: Lengths of 2, 3, and 4 bytes have a separate set of
+// probabilities for each length. The matches with longer length use a shared
+// set of probabilities.
+#define LEN_TO_POS_STATES 4
+
+// Macro to get the index of the appropriate probability array.
+#define get_len_to_pos_state(len) \
+ ((len) < LEN_TO_POS_STATES + MATCH_LEN_MIN \
+ ? (len) - MATCH_LEN_MIN \
+ : LEN_TO_POS_STATES - 1)
+
+// The highest two bits of a match distance (pos slot) are encoded using six
+// bits. See fastpos.h for more explanation.
+#define POS_SLOT_BITS 6
+#define POS_SLOTS (1 << POS_SLOT_BITS)
+
+// Match distances up to 127 are fully encoded using probabilities. Since
+// the highest two bits (pos slot) are always encoded using six bits, the
+// distances 0-3 don't need any additional bits to encode, since the pos
+// slot itself is the same as the actual distance. START_POS_MODEL_INDEX
+// indicates the first pos slot where at least one additional bit is needed.
+#define START_POS_MODEL_INDEX 4
+
+// Match distances greater than 127 are encoded in three pieces:
+// - pos slot: the highest two bits
+// - direct bits: 2-26 bits below the highest two bits
+// - alignment bits: four lowest bits
+//
+// Direct bits don't use any probabilities.
+//
+// The pos slot value of 14 is for distances 128-191 (see the table in
+// fastpos.h to understand why).
+#define END_POS_MODEL_INDEX 14
+
+// Pos slots that indicate a distance <= 127.
+#define FULL_DISTANCES_BITS (END_POS_MODEL_INDEX / 2)
+#define FULL_DISTANCES (1 << FULL_DISTANCES_BITS)
+
+// For match distances greater than 127, only the highest two bits and the
+// lowest four bits (alignment) is encoded using probabilities.
+#define ALIGN_BITS 4
+#define ALIGN_TABLE_SIZE (1 << ALIGN_BITS)
+#define ALIGN_MASK (ALIGN_TABLE_SIZE - 1)
+
+// LZMA remembers the four most recent match distances. Reusing these distances
+// tends to take less space than re-encoding the actual distance value.
+#define REP_DISTANCES 4
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c
new file mode 100644
index 0000000000..3c0f393310
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c
@@ -0,0 +1,1075 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma_decoder.c
+/// \brief LZMA decoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "lz_decoder.h"
+#include "lzma_common.h"
+#include "lzma_decoder.h"
+#include "range_decoder.h"
+
+
+#ifdef HAVE_SMALL
+
+// Macros for (somewhat) size-optimized code.
+#define seq_4(seq) seq
+
+#define seq_6(seq) seq
+
+#define seq_8(seq) seq
+
+#define seq_len(seq) \
+ seq ## _CHOICE, \
+ seq ## _CHOICE2, \
+ seq ## _BITTREE
+
+#define len_decode(target, ld, pos_state, seq) \
+do { \
+case seq ## _CHOICE: \
+ rc_if_0(ld.choice, seq ## _CHOICE) { \
+ rc_update_0(ld.choice); \
+ probs = ld.low[pos_state];\
+ limit = LEN_LOW_SYMBOLS; \
+ target = MATCH_LEN_MIN; \
+ } else { \
+ rc_update_1(ld.choice); \
+case seq ## _CHOICE2: \
+ rc_if_0(ld.choice2, seq ## _CHOICE2) { \
+ rc_update_0(ld.choice2); \
+ probs = ld.mid[pos_state]; \
+ limit = LEN_MID_SYMBOLS; \
+ target = MATCH_LEN_MIN + LEN_LOW_SYMBOLS; \
+ } else { \
+ rc_update_1(ld.choice2); \
+ probs = ld.high; \
+ limit = LEN_HIGH_SYMBOLS; \
+ target = MATCH_LEN_MIN + LEN_LOW_SYMBOLS \
+ + LEN_MID_SYMBOLS; \
+ } \
+ } \
+ symbol = 1; \
+case seq ## _BITTREE: \
+ do { \
+ rc_bit(probs[symbol], , , seq ## _BITTREE); \
+ } while (symbol < limit); \
+ target += symbol - limit; \
+} while (0)
+
+#else // HAVE_SMALL
+
+// Unrolled versions
+#define seq_4(seq) \
+ seq ## 0, \
+ seq ## 1, \
+ seq ## 2, \
+ seq ## 3
+
+#define seq_6(seq) \
+ seq ## 0, \
+ seq ## 1, \
+ seq ## 2, \
+ seq ## 3, \
+ seq ## 4, \
+ seq ## 5
+
+#define seq_8(seq) \
+ seq ## 0, \
+ seq ## 1, \
+ seq ## 2, \
+ seq ## 3, \
+ seq ## 4, \
+ seq ## 5, \
+ seq ## 6, \
+ seq ## 7
+
+#define seq_len(seq) \
+ seq ## _CHOICE, \
+ seq ## _LOW0, \
+ seq ## _LOW1, \
+ seq ## _LOW2, \
+ seq ## _CHOICE2, \
+ seq ## _MID0, \
+ seq ## _MID1, \
+ seq ## _MID2, \
+ seq ## _HIGH0, \
+ seq ## _HIGH1, \
+ seq ## _HIGH2, \
+ seq ## _HIGH3, \
+ seq ## _HIGH4, \
+ seq ## _HIGH5, \
+ seq ## _HIGH6, \
+ seq ## _HIGH7
+
+#define len_decode(target, ld, pos_state, seq) \
+do { \
+ symbol = 1; \
+case seq ## _CHOICE: \
+ rc_if_0(ld.choice, seq ## _CHOICE) { \
+ rc_update_0(ld.choice); \
+ rc_bit_case(ld.low[pos_state][symbol], 0, 0, seq ## _LOW0); \
+ rc_bit_case(ld.low[pos_state][symbol], 0, 0, seq ## _LOW1); \
+ rc_bit_case(ld.low[pos_state][symbol], 0, 0, seq ## _LOW2); \
+ target = symbol - LEN_LOW_SYMBOLS + MATCH_LEN_MIN; \
+ } else { \
+ rc_update_1(ld.choice); \
+case seq ## _CHOICE2: \
+ rc_if_0(ld.choice2, seq ## _CHOICE2) { \
+ rc_update_0(ld.choice2); \
+ rc_bit_case(ld.mid[pos_state][symbol], 0, 0, \
+ seq ## _MID0); \
+ rc_bit_case(ld.mid[pos_state][symbol], 0, 0, \
+ seq ## _MID1); \
+ rc_bit_case(ld.mid[pos_state][symbol], 0, 0, \
+ seq ## _MID2); \
+ target = symbol - LEN_MID_SYMBOLS \
+ + MATCH_LEN_MIN + LEN_LOW_SYMBOLS; \
+ } else { \
+ rc_update_1(ld.choice2); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH0); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH1); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH2); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH3); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH4); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH5); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH6); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH7); \
+ target = symbol - LEN_HIGH_SYMBOLS \
+ + MATCH_LEN_MIN \
+ + LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS; \
+ } \
+ } \
+} while (0)
+
+#endif // HAVE_SMALL
+
+
+/// Length decoder probabilities; see comments in lzma_common.h.
+typedef struct {
+ probability choice;
+ probability choice2;
+ probability low[POS_STATES_MAX][LEN_LOW_SYMBOLS];
+ probability mid[POS_STATES_MAX][LEN_MID_SYMBOLS];
+ probability high[LEN_HIGH_SYMBOLS];
+} lzma_length_decoder;
+
+
+struct lzma_coder_s {
+ ///////////////////
+ // Probabilities //
+ ///////////////////
+
+ /// Literals; see comments in lzma_common.h.
+ probability literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE];
+
+ /// If 1, it's a match. Otherwise it's a single 8-bit literal.
+ probability is_match[STATES][POS_STATES_MAX];
+
+ /// If 1, it's a repeated match. The distance is one of rep0 .. rep3.
+ probability is_rep[STATES];
+
+ /// If 0, distance of a repeated match is rep0.
+ /// Otherwise check is_rep1.
+ probability is_rep0[STATES];
+
+ /// If 0, distance of a repeated match is rep1.
+ /// Otherwise check is_rep2.
+ probability is_rep1[STATES];
+
+ /// If 0, distance of a repeated match is rep2. Otherwise it is rep3.
+ probability is_rep2[STATES];
+
+ /// If 1, the repeated match has length of one byte. Otherwise
+ /// the length is decoded from rep_len_decoder.
+ probability is_rep0_long[STATES][POS_STATES_MAX];
+
+ /// Probability tree for the highest two bits of the match distance.
+ /// There is a separate probability tree for match lengths of
+ /// 2 (i.e. MATCH_LEN_MIN), 3, 4, and [5, 273].
+ probability pos_slot[LEN_TO_POS_STATES][POS_SLOTS];
+
+ /// Probability trees for additional bits for match distance when the
+ /// distance is in the range [4, 127].
+ probability pos_special[FULL_DISTANCES - END_POS_MODEL_INDEX];
+
+ /// Probability tree for the lowest four bits of a match distance
+ /// that is equal to or greater than 128.
+ probability pos_align[ALIGN_TABLE_SIZE];
+
+ /// Length of a normal match
+ lzma_length_decoder match_len_decoder;
+
+ /// Length of a repeated match
+ lzma_length_decoder rep_len_decoder;
+
+ ///////////////////
+ // Decoder state //
+ ///////////////////
+
+ // Range coder
+ lzma_range_decoder rc;
+
+ // Types of the most recently seen LZMA symbols
+ lzma_lzma_state state;
+
+ uint32_t rep0; ///< Distance of the latest match
+ uint32_t rep1; ///< Distance of second latest match
+ uint32_t rep2; ///< Distance of third latest match
+ uint32_t rep3; ///< Distance of fourth latest match
+
+ uint32_t pos_mask; // (1U << pb) - 1
+ uint32_t literal_context_bits;
+ uint32_t literal_pos_mask;
+
+ /// Uncompressed size as bytes, or LZMA_VLI_UNKNOWN if end of
+ /// payload marker is expected.
+ lzma_vli uncompressed_size;
+
+ ////////////////////////////////
+ // State of incomplete symbol //
+ ////////////////////////////////
+
+ /// Position where to continue the decoder loop
+ enum {
+ SEQ_NORMALIZE,
+ SEQ_IS_MATCH,
+ seq_8(SEQ_LITERAL),
+ seq_8(SEQ_LITERAL_MATCHED),
+ SEQ_LITERAL_WRITE,
+ SEQ_IS_REP,
+ seq_len(SEQ_MATCH_LEN),
+ seq_6(SEQ_POS_SLOT),
+ SEQ_POS_MODEL,
+ SEQ_DIRECT,
+ seq_4(SEQ_ALIGN),
+ SEQ_EOPM,
+ SEQ_IS_REP0,
+ SEQ_SHORTREP,
+ SEQ_IS_REP0_LONG,
+ SEQ_IS_REP1,
+ SEQ_IS_REP2,
+ seq_len(SEQ_REP_LEN),
+ SEQ_COPY,
+ } sequence;
+
+ /// Base of the current probability tree
+ probability *probs;
+
+ /// Symbol being decoded. This is also used as an index variable in
+ /// bittree decoders: probs[symbol]
+ uint32_t symbol;
+
+ /// Used as a loop termination condition on bittree decoders and
+ /// direct bits decoder.
+ uint32_t limit;
+
+ /// Matched literal decoder: 0x100 or 0 to help avoiding branches.
+ /// Bittree reverse decoders: Offset of the next bit: 1 << offset
+ uint32_t offset;
+
+ /// If decoding a literal: match byte.
+ /// If decoding a match: length of the match.
+ uint32_t len;
+};
+
+
+static lzma_ret
+lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
+ const uint8_t *LZMA_RESTRICT in,
+ size_t *LZMA_RESTRICT in_pos, size_t in_size)
+{
+ ///////////////
+ // Variables //
+ ///////////////
+
+ // Making local copies of often-used variables improves both
+ // speed and readability.
+
+ lzma_dict dict = *dictptr;
+
+ const size_t dict_start = dict.pos;
+
+ // Range decoder
+ rc_to_local(coder->rc, *in_pos);
+
+ // State
+ uint32_t state = coder->state;
+ uint32_t rep0 = coder->rep0;
+ uint32_t rep1 = coder->rep1;
+ uint32_t rep2 = coder->rep2;
+ uint32_t rep3 = coder->rep3;
+
+ const uint32_t pos_mask = coder->pos_mask;
+
+ // These variables are actually needed only if we last time ran
+ // out of input in the middle of the decoder loop.
+ probability *probs = coder->probs;
+ uint32_t symbol = coder->symbol;
+ uint32_t limit = coder->limit;
+ uint32_t offset = coder->offset;
+ uint32_t len = coder->len;
+
+ const uint32_t literal_pos_mask = coder->literal_pos_mask;
+ const uint32_t literal_context_bits = coder->literal_context_bits;
+
+ // Temporary variables
+ uint32_t pos_state = dict.pos & pos_mask;
+
+ lzma_ret ret = LZMA_OK;
+
+ // If uncompressed size is known, there must be no end of payload
+ // marker.
+ const bool no_eopm = coder->uncompressed_size
+ != LZMA_VLI_UNKNOWN;
+ if (no_eopm && coder->uncompressed_size < dict.limit - dict.pos)
+ dict.limit = dict.pos + (size_t)(coder->uncompressed_size);
+
+ ////////////////////
+ // Initialization //
+ ////////////////////
+
+ if (!rc_read_init(&coder->rc, in, in_pos, in_size))
+ return LZMA_OK;
+
+ rc = coder->rc;
+ rc_in_pos = *in_pos;
+
+ // The main decoder loop. The "switch" is used to restart the decoder at
+ // correct location. Once restarted, the "switch" is no longer used.
+ switch (coder->sequence)
+ while (true) {
+ // Calculate new pos_state. This is skipped on the first loop
+ // since we already calculated it when setting up the local
+ // variables.
+ pos_state = dict.pos & pos_mask;
+
+ case SEQ_NORMALIZE:
+ case SEQ_IS_MATCH:
+ if (unlikely(no_eopm && dict.pos == dict.limit))
+ break;
+
+ rc_if_0(coder->is_match[state][pos_state], SEQ_IS_MATCH) {
+ static const lzma_lzma_state next_state[] = {
+ STATE_LIT_LIT,
+ STATE_LIT_LIT,
+ STATE_LIT_LIT,
+ STATE_LIT_LIT,
+ STATE_MATCH_LIT_LIT,
+ STATE_REP_LIT_LIT,
+ STATE_SHORTREP_LIT_LIT,
+ STATE_MATCH_LIT,
+ STATE_REP_LIT,
+ STATE_SHORTREP_LIT,
+ STATE_MATCH_LIT,
+ STATE_REP_LIT
+ };
+
+ rc_update_0(coder->is_match[state][pos_state]);
+
+ // It's a literal i.e. a single 8-bit byte.
+
+ probs = literal_subcoder(coder->literal,
+ literal_context_bits, literal_pos_mask,
+ dict.pos, dict_get(&dict, 0));
+ symbol = 1;
+
+ if (is_literal_state(state)) {
+ // Decode literal without match byte.
+#ifdef HAVE_SMALL
+ case SEQ_LITERAL:
+ do {
+ rc_bit(probs[symbol], , , SEQ_LITERAL);
+ } while (symbol < (1 << 8));
+#else
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL0);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL1);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL2);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL3);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL4);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL5);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL6);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL7);
+#endif
+ } else {
+#ifndef HAVE_SMALL
+ uint32_t match_bit;
+ uint32_t subcoder_index;
+#endif
+
+ // Decode literal with match byte.
+ //
+ // We store the byte we compare against
+ // ("match byte") to "len" to minimize the
+ // number of variables we need to store
+ // between decoder calls.
+ len = dict_get(&dict, rep0) << 1;
+
+ // The usage of "offset" allows omitting some
+ // branches, which should give tiny speed
+ // improvement on some CPUs. "offset" gets
+ // set to zero if match_bit didn't match.
+ offset = 0x100;
+
+#ifdef HAVE_SMALL
+ case SEQ_LITERAL_MATCHED:
+ do {
+ const uint32_t match_bit
+ = len & offset;
+ const uint32_t subcoder_index
+ = offset + match_bit
+ + symbol;
+
+ rc_bit(probs[subcoder_index],
+ offset &= ~match_bit,
+ offset &= match_bit,
+ SEQ_LITERAL_MATCHED);
+
+ // It seems to be faster to do this
+ // here instead of putting it to the
+ // beginning of the loop and then
+ // putting the "case" in the middle
+ // of the loop.
+ len <<= 1;
+
+ } while (symbol < (1 << 8));
+#else
+ // Unroll the loop.
+
+# define d(seq) \
+ case seq: \
+ match_bit = len & offset; \
+ subcoder_index = offset + match_bit + symbol; \
+ rc_bit(probs[subcoder_index], \
+ offset &= ~match_bit, \
+ offset &= match_bit, \
+ seq)
+
+ d(SEQ_LITERAL_MATCHED0);
+ len <<= 1;
+ d(SEQ_LITERAL_MATCHED1);
+ len <<= 1;
+ d(SEQ_LITERAL_MATCHED2);
+ len <<= 1;
+ d(SEQ_LITERAL_MATCHED3);
+ len <<= 1;
+ d(SEQ_LITERAL_MATCHED4);
+ len <<= 1;
+ d(SEQ_LITERAL_MATCHED5);
+ len <<= 1;
+ d(SEQ_LITERAL_MATCHED6);
+ len <<= 1;
+ d(SEQ_LITERAL_MATCHED7);
+# undef d
+#endif
+ }
+
+ //update_literal(state);
+ // Use a lookup table to update to literal state,
+ // since compared to other state updates, this would
+ // need two branches.
+ state = next_state[state];
+
+ case SEQ_LITERAL_WRITE:
+ if (unlikely(dict_put(&dict, symbol))) {
+ coder->sequence = SEQ_LITERAL_WRITE;
+ goto out;
+ }
+
+ continue;
+ }
+
+ // Instead of a new byte we are going to get a byte range
+ // (distance and length) which will be repeated from our
+ // output history.
+
+ rc_update_1(coder->is_match[state][pos_state]);
+
+ case SEQ_IS_REP:
+ rc_if_0(coder->is_rep[state], SEQ_IS_REP) {
+ // Not a repeated match
+ rc_update_0(coder->is_rep[state]);
+ update_match(state);
+
+ // The latest three match distances are kept in
+ // memory in case there are repeated matches.
+ rep3 = rep2;
+ rep2 = rep1;
+ rep1 = rep0;
+
+ // Decode the length of the match.
+ len_decode(len, coder->match_len_decoder,
+ pos_state, SEQ_MATCH_LEN);
+
+ // Prepare to decode the highest two bits of the
+ // match distance.
+ probs = coder->pos_slot[get_len_to_pos_state(len)];
+ symbol = 1;
+
+#ifdef HAVE_SMALL
+ case SEQ_POS_SLOT:
+ do {
+ rc_bit(probs[symbol], , , SEQ_POS_SLOT);
+ } while (symbol < POS_SLOTS);
+#else
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT0);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT1);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT2);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT3);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT4);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT5);
+#endif
+ // Get rid of the highest bit that was needed for
+ // indexing of the probability array.
+ symbol -= POS_SLOTS;
+ assert(symbol <= 63);
+
+ if (symbol < START_POS_MODEL_INDEX) {
+ // Match distances [0, 3] have only two bits.
+ rep0 = symbol;
+ } else {
+ // Decode the lowest [1, 29] bits of
+ // the match distance.
+ limit = (symbol >> 1) - 1;
+ assert(limit >= 1 && limit <= 30);
+ rep0 = 2 + (symbol & 1);
+
+ if (symbol < END_POS_MODEL_INDEX) {
+ // Prepare to decode the low bits for
+ // a distance of [4, 127].
+ assert(limit <= 5);
+ rep0 <<= limit;
+ assert(rep0 <= 96);
+ // -1 is fine, because we start
+ // decoding at probs[1], not probs[0].
+ // NOTE: This violates the C standard,
+ // since we are doing pointer
+ // arithmetic past the beginning of
+ // the array.
+ assert((int32_t)(rep0 - symbol - 1)
+ >= -1);
+ assert((int32_t)(rep0 - symbol - 1)
+ <= 82);
+ probs = coder->pos_special + rep0
+ - symbol - 1;
+ symbol = 1;
+ offset = 0;
+ case SEQ_POS_MODEL:
+#ifdef HAVE_SMALL
+ do {
+ rc_bit(probs[symbol], ,
+ rep0 += 1 << offset,
+ SEQ_POS_MODEL);
+ } while (++offset < limit);
+#else
+ switch (limit) {
+ case 5:
+ assert(offset == 0);
+ rc_bit(probs[symbol], 0,
+ rep0 += 1,
+ SEQ_POS_MODEL);
+ ++offset;
+ --limit;
+ case 4:
+ rc_bit(probs[symbol], 0,
+ rep0 += 1 << offset,
+ SEQ_POS_MODEL);
+ ++offset;
+ --limit;
+ case 3:
+ rc_bit(probs[symbol], 0,
+ rep0 += 1 << offset,
+ SEQ_POS_MODEL);
+ ++offset;
+ --limit;
+ case 2:
+ rc_bit(probs[symbol], 0,
+ rep0 += 1 << offset,
+ SEQ_POS_MODEL);
+ ++offset;
+ --limit;
+ case 1:
+ // We need "symbol" only for
+ // indexing the probability
+ // array, thus we can use
+ // rc_bit_last() here to omit
+ // the unneeded updating of
+ // "symbol".
+ rc_bit_last(probs[symbol], 0,
+ rep0 += 1 << offset,
+ SEQ_POS_MODEL);
+ }
+#endif
+ } else {
+ // The distance is >= 128. Decode the
+ // lower bits without probabilities
+ // except the lowest four bits.
+ assert(symbol >= 14);
+ assert(limit >= 6);
+ limit -= ALIGN_BITS;
+ assert(limit >= 2);
+ case SEQ_DIRECT:
+ // Not worth manual unrolling
+ do {
+ rc_direct(rep0, SEQ_DIRECT);
+ } while (--limit > 0);
+
+ // Decode the lowest four bits using
+ // probabilities.
+ rep0 <<= ALIGN_BITS;
+ symbol = 1;
+#ifdef HAVE_SMALL
+ offset = 0;
+ case SEQ_ALIGN:
+ do {
+ rc_bit(coder->pos_align[
+ symbol], ,
+ rep0 += 1 << offset,
+ SEQ_ALIGN);
+ } while (++offset < ALIGN_BITS);
+#else
+ case SEQ_ALIGN0:
+ rc_bit(coder->pos_align[symbol], 0,
+ rep0 += 1, SEQ_ALIGN0);
+ case SEQ_ALIGN1:
+ rc_bit(coder->pos_align[symbol], 0,
+ rep0 += 2, SEQ_ALIGN1);
+ case SEQ_ALIGN2:
+ rc_bit(coder->pos_align[symbol], 0,
+ rep0 += 4, SEQ_ALIGN2);
+ case SEQ_ALIGN3:
+ // Like in SEQ_POS_MODEL, we don't
+ // need "symbol" for anything else
+ // than indexing the probability array.
+ rc_bit_last(coder->pos_align[symbol], 0,
+ rep0 += 8, SEQ_ALIGN3);
+#endif
+
+ if (rep0 == UINT32_MAX) {
+ // End of payload marker was
+ // found. It must not be
+ // present if uncompressed
+ // size is known.
+ if (coder->uncompressed_size
+ != LZMA_VLI_UNKNOWN) {
+ ret = LZMA_DATA_ERROR;
+ goto out;
+ }
+
+ case SEQ_EOPM:
+ // LZMA1 stream with
+ // end-of-payload marker.
+ rc_normalize(SEQ_EOPM);
+ ret = LZMA_STREAM_END;
+ goto out;
+ }
+ }
+ }
+
+ // Validate the distance we just decoded.
+ if (unlikely(!dict_is_distance_valid(&dict, rep0))) {
+ ret = LZMA_DATA_ERROR;
+ goto out;
+ }
+
+ } else {
+ rc_update_1(coder->is_rep[state]);
+
+ // Repeated match
+ //
+ // The match distance is a value that we have had
+ // earlier. The latest four match distances are
+ // available as rep0, rep1, rep2 and rep3. We will
+ // now decode which of them is the new distance.
+ //
+ // There cannot be a match if we haven't produced
+ // any output, so check that first.
+ if (unlikely(!dict_is_distance_valid(&dict, 0))) {
+ ret = LZMA_DATA_ERROR;
+ goto out;
+ }
+
+ case SEQ_IS_REP0:
+ rc_if_0(coder->is_rep0[state], SEQ_IS_REP0) {
+ rc_update_0(coder->is_rep0[state]);
+ // The distance is rep0.
+
+ case SEQ_IS_REP0_LONG:
+ rc_if_0(coder->is_rep0_long[state][pos_state],
+ SEQ_IS_REP0_LONG) {
+ rc_update_0(coder->is_rep0_long[
+ state][pos_state]);
+
+ update_short_rep(state);
+
+ case SEQ_SHORTREP:
+ if (unlikely(dict_put(&dict, dict_get(
+ &dict, rep0)))) {
+ coder->sequence = SEQ_SHORTREP;
+ goto out;
+ }
+
+ continue;
+ }
+
+ // Repeating more than one byte at
+ // distance of rep0.
+ rc_update_1(coder->is_rep0_long[
+ state][pos_state]);
+
+ } else {
+ rc_update_1(coder->is_rep0[state]);
+
+ case SEQ_IS_REP1:
+ // The distance is rep1, rep2 or rep3. Once
+ // we find out which one of these three, it
+ // is stored to rep0 and rep1, rep2 and rep3
+ // are updated accordingly.
+ rc_if_0(coder->is_rep1[state], SEQ_IS_REP1) {
+ uint32_t distance;
+
+ rc_update_0(coder->is_rep1[state]);
+
+ distance = rep1;
+ rep1 = rep0;
+ rep0 = distance;
+
+ } else {
+ rc_update_1(coder->is_rep1[state]);
+ case SEQ_IS_REP2:
+ rc_if_0(coder->is_rep2[state],
+ SEQ_IS_REP2) {
+ uint32_t distance;
+
+ rc_update_0(coder->is_rep2[
+ state]);
+
+ distance = rep2;
+ rep2 = rep1;
+ rep1 = rep0;
+ rep0 = distance;
+
+ } else {
+ uint32_t distance;
+
+ rc_update_1(coder->is_rep2[
+ state]);
+
+ distance = rep3;
+ rep3 = rep2;
+ rep2 = rep1;
+ rep1 = rep0;
+ rep0 = distance;
+ }
+ }
+ }
+
+ update_long_rep(state);
+
+ // Decode the length of the repeated match.
+ len_decode(len, coder->rep_len_decoder,
+ pos_state, SEQ_REP_LEN);
+ }
+
+ /////////////////////////////////
+ // Repeat from history buffer. //
+ /////////////////////////////////
+
+ // The length is always between these limits. There is no way
+ // to trigger the algorithm to set len outside this range.
+ assert(len >= MATCH_LEN_MIN);
+ assert(len <= MATCH_LEN_MAX);
+
+ case SEQ_COPY:
+ // Repeat len bytes from distance of rep0.
+ if (unlikely(dict_repeat(&dict, rep0, &len))) {
+ coder->sequence = SEQ_COPY;
+ goto out;
+ }
+ }
+
+ rc_normalize(SEQ_NORMALIZE);
+ coder->sequence = SEQ_IS_MATCH;
+
+out:
+ // Save state
+
+ // NOTE: Must not copy dict.limit.
+ dictptr->pos = dict.pos;
+ dictptr->full = dict.full;
+
+ rc_from_local(coder->rc, *in_pos);
+
+ coder->state = state;
+ coder->rep0 = rep0;
+ coder->rep1 = rep1;
+ coder->rep2 = rep2;
+ coder->rep3 = rep3;
+
+ coder->probs = probs;
+ coder->symbol = symbol;
+ coder->limit = limit;
+ coder->offset = offset;
+ coder->len = len;
+
+ // Update the remaining amount of uncompressed data if uncompressed
+ // size was known.
+ if (coder->uncompressed_size != LZMA_VLI_UNKNOWN) {
+ coder->uncompressed_size -= dict.pos - dict_start;
+
+ // Since there cannot be end of payload marker if the
+ // uncompressed size was known, we check here if we
+ // finished decoding.
+ if (coder->uncompressed_size == 0 && ret == LZMA_OK
+ && coder->sequence != SEQ_NORMALIZE)
+ ret = coder->sequence == SEQ_IS_MATCH
+ ? LZMA_STREAM_END : LZMA_DATA_ERROR;
+ }
+
+ // We can do an additional check in the range decoder to catch some
+ // corrupted files.
+ if (ret == LZMA_STREAM_END) {
+ if (!rc_is_finished(coder->rc))
+ ret = LZMA_DATA_ERROR;
+
+ // Reset the range decoder so that it is ready to reinitialize
+ // for a new LZMA2 chunk.
+ rc_reset(coder->rc);
+ }
+
+ return ret;
+}
+
+
+
+static void
+lzma_decoder_uncompressed(lzma_coder *coder, lzma_vli uncompressed_size)
+{
+ coder->uncompressed_size = uncompressed_size;
+}
+
+/*
+extern void
+lzma_lzma_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size)
+{
+ // This is hack.
+ (*(lzma_coder **)(coder))->uncompressed_size = uncompressed_size;
+}
+*/
+
+static void
+lzma_decoder_reset(lzma_coder *coder, const void *opt)
+{
+ uint32_t i, j, pos_state;
+ uint32_t num_pos_states;
+
+ const lzma_options_lzma *options = opt;
+
+ // NOTE: We assume that lc/lp/pb are valid since they were
+ // successfully decoded with lzma_lzma_decode_properties().
+
+ // Calculate pos_mask. We don't need pos_bits as is for anything.
+ coder->pos_mask = (1U << options->pb) - 1;
+
+ // Initialize the literal decoder.
+ literal_init(coder->literal, options->lc, options->lp);
+
+ coder->literal_context_bits = options->lc;
+ coder->literal_pos_mask = (1U << options->lp) - 1;
+
+ // State
+ coder->state = STATE_LIT_LIT;
+ coder->rep0 = 0;
+ coder->rep1 = 0;
+ coder->rep2 = 0;
+ coder->rep3 = 0;
+ coder->pos_mask = (1U << options->pb) - 1;
+
+ // Range decoder
+ rc_reset(coder->rc);
+
+ // Bit and bittree decoders
+ for (i = 0; i < STATES; ++i) {
+ for (j = 0; j <= coder->pos_mask; ++j) {
+ bit_reset(coder->is_match[i][j]);
+ bit_reset(coder->is_rep0_long[i][j]);
+ }
+
+ bit_reset(coder->is_rep[i]);
+ bit_reset(coder->is_rep0[i]);
+ bit_reset(coder->is_rep1[i]);
+ bit_reset(coder->is_rep2[i]);
+ }
+
+ for (i = 0; i < LEN_TO_POS_STATES; ++i)
+ bittree_reset(coder->pos_slot[i], POS_SLOT_BITS);
+
+ for (i = 0; i < FULL_DISTANCES - END_POS_MODEL_INDEX; ++i)
+ bit_reset(coder->pos_special[i]);
+
+ bittree_reset(coder->pos_align, ALIGN_BITS);
+
+ // Len decoders (also bit/bittree)
+ num_pos_states = 1U << options->pb;
+ bit_reset(coder->match_len_decoder.choice);
+ bit_reset(coder->match_len_decoder.choice2);
+ bit_reset(coder->rep_len_decoder.choice);
+ bit_reset(coder->rep_len_decoder.choice2);
+
+ for (pos_state = 0; pos_state < num_pos_states; ++pos_state) {
+ bittree_reset(coder->match_len_decoder.low[pos_state],
+ LEN_LOW_BITS);
+ bittree_reset(coder->match_len_decoder.mid[pos_state],
+ LEN_MID_BITS);
+
+ bittree_reset(coder->rep_len_decoder.low[pos_state],
+ LEN_LOW_BITS);
+ bittree_reset(coder->rep_len_decoder.mid[pos_state],
+ LEN_MID_BITS);
+ }
+
+ bittree_reset(coder->match_len_decoder.high, LEN_HIGH_BITS);
+ bittree_reset(coder->rep_len_decoder.high, LEN_HIGH_BITS);
+
+ coder->sequence = SEQ_IS_MATCH;
+ coder->probs = NULL;
+ coder->symbol = 0;
+ coder->limit = 0;
+ coder->offset = 0;
+ coder->len = 0;
+
+ return;
+}
+
+
+extern lzma_ret
+lzma_lzma_decoder_create(lzma_lz_decoder *lz, lzma_allocator *allocator,
+ const void *opt, lzma_lz_options *lz_options)
+{
+ const lzma_options_lzma *options = opt;
+
+ if (lz->coder == NULL) {
+ lz->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (lz->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ lz->code = &lzma_decode;
+ lz->reset = &lzma_decoder_reset;
+ lz->set_uncompressed = &lzma_decoder_uncompressed;
+ }
+
+ // All dictionary sizes are OK here. LZ decoder will take care of
+ // the special cases.
+ lz_options->dict_size = options->dict_size;
+ lz_options->preset_dict = options->preset_dict;
+ lz_options->preset_dict_size = options->preset_dict_size;
+
+ return LZMA_OK;
+}
+
+
+/// Allocate and initialize LZMA decoder. This is used only via LZ
+/// initialization (lzma_lzma_decoder_init() passes function pointer to
+/// the LZ initialization).
+static lzma_ret
+lzma_decoder_init(lzma_lz_decoder *lz, lzma_allocator *allocator,
+ const void *options, lzma_lz_options *lz_options)
+{
+ if (!is_lclppb_valid(options))
+ return LZMA_PROG_ERROR;
+
+ return_if_error(lzma_lzma_decoder_create(
+ lz, allocator, options, lz_options));
+
+ lzma_decoder_reset(lz->coder, options);
+ lzma_decoder_uncompressed(lz->coder, LZMA_VLI_UNKNOWN);
+
+ return LZMA_OK;
+}
+
+
+extern lzma_ret
+lzma_lzma_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ // LZMA can only be the last filter in the chain. This is enforced
+ // by the raw_decoder initialization.
+ assert(filters[1].init == NULL);
+
+ return lzma_lz_decoder_init(next, allocator, filters,
+ &lzma_decoder_init);
+}
+
+
+extern bool
+lzma_lzma_lclppb_decode(lzma_options_lzma *options, uint8_t byte)
+{
+ if (byte > (4 * 5 + 4) * 9 + 8)
+ return true;
+
+ // See the file format specification to understand this.
+ options->pb = byte / (9 * 5);
+ byte -= options->pb * 9 * 5;
+ options->lp = byte / 9;
+ options->lc = byte - options->lp * 9;
+
+ return options->lc + options->lp > LZMA_LCLP_MAX;
+}
+
+
+extern uint64_t
+lzma_lzma_decoder_memusage_nocheck(const void *options)
+{
+ const lzma_options_lzma *const opt = options;
+ return sizeof(lzma_coder) + lzma_lz_decoder_memusage(opt->dict_size);
+}
+
+
+extern uint64_t
+lzma_lzma_decoder_memusage(const void *options)
+{
+ if (!is_lclppb_valid(options))
+ return UINT64_MAX;
+
+ return lzma_lzma_decoder_memusage_nocheck(options);
+}
+
+
+extern lzma_ret
+lzma_lzma_props_decode(void **options, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size)
+{
+ lzma_options_lzma *opt;
+
+ if (props_size != 5)
+ return LZMA_OPTIONS_ERROR;
+
+ opt = lzma_alloc(sizeof(lzma_options_lzma), allocator);
+ if (opt == NULL)
+ return LZMA_MEM_ERROR;
+
+ if (lzma_lzma_lclppb_decode(opt, props[0]))
+ goto error;
+
+ // All dictionary sizes are accepted, including zero. LZ decoder
+ // will automatically use a dictionary at least a few KiB even if
+ // a smaller dictionary is requested.
+ opt->dict_size = unaligned_read32le(props + 1);
+
+ opt->preset_dict = NULL;
+ opt->preset_dict_size = 0;
+
+ *options = opt;
+
+ return LZMA_OK;
+
+error:
+ lzma_free(opt, allocator);
+ return LZMA_OPTIONS_ERROR;
+}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.h b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.h
new file mode 100644
index 0000000000..a463a76fc6
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.h
@@ -0,0 +1,52 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma_decoder.h
+/// \brief LZMA decoder API
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_LZMA_DECODER_H
+#define LZMA_LZMA_DECODER_H
+
+#include "common.h"
+
+
+/// Allocates and initializes LZMA decoder
+extern lzma_ret lzma_lzma_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern uint64_t lzma_lzma_decoder_memusage(const void *options);
+
+extern lzma_ret lzma_lzma_props_decode(
+ void **options, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size);
+
+
+/// \brief Decodes the LZMA Properties byte (lc/lp/pb)
+///
+/// \return true if error occurred, false on success
+///
+extern bool lzma_lzma_lclppb_decode(
+ lzma_options_lzma *options, uint8_t byte);
+
+
+#ifdef LZMA_LZ_DECODER_H
+/// Allocate and setup function pointers only. This is used by LZMA1 and
+/// LZMA2 decoders.
+extern lzma_ret lzma_lzma_decoder_create(
+ lzma_lz_decoder *lz, lzma_allocator *allocator,
+ const void *opt, lzma_lz_options *lz_options);
+
+/// Gets memory usage without validating lc/lp/pb. This is used by LZMA2
+/// decoder, because raw LZMA2 decoding doesn't need lc/lp/pb.
+extern uint64_t lzma_lzma_decoder_memusage_nocheck(const void *options);
+
+#endif
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.c b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.c
new file mode 100644
index 0000000000..e8738f4112
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.c
@@ -0,0 +1,695 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma_encoder.c
+/// \brief LZMA encoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "lzma2_encoder.h"
+#include "lzma_encoder_private.h"
+#include "fastpos.h"
+
+
+/////////////
+// Literal //
+/////////////
+
+static inline void
+literal_matched(lzma_range_encoder *rc, probability *subcoder,
+ uint32_t match_byte, uint32_t symbol)
+{
+ uint32_t offset = 0x100;
+ symbol += UINT32_C(1) << 8;
+
+ do {
+ uint32_t match_bit;
+ uint32_t subcoder_index;
+ uint32_t bit;
+
+ match_byte <<= 1;
+ match_bit = match_byte & offset;
+ subcoder_index = offset + match_bit + (symbol >> 8);
+ bit = (symbol >> 7) & 1;
+ rc_bit(rc, &subcoder[subcoder_index], bit);
+
+ symbol <<= 1;
+ offset &= ~(match_byte ^ symbol);
+
+ } while (symbol < (UINT32_C(1) << 16));
+}
+
+
+static inline void
+literal(lzma_coder *coder, lzma_mf *mf, uint32_t position)
+{
+ // Locate the literal byte to be encoded and the subcoder.
+ const uint8_t cur_byte = mf->buffer[
+ mf->read_pos - mf->read_ahead];
+ probability *subcoder = literal_subcoder(coder->literal,
+ coder->literal_context_bits, coder->literal_pos_mask,
+ position, mf->buffer[mf->read_pos - mf->read_ahead - 1]);
+
+ if (is_literal_state(coder->state)) {
+ // Previous LZMA-symbol was a literal. Encode a normal
+ // literal without a match byte.
+ rc_bittree(&coder->rc, subcoder, 8, cur_byte);
+ } else {
+ // Previous LZMA-symbol was a match. Use the last byte of
+ // the match as a "match byte". That is, compare the bits
+ // of the current literal and the match byte.
+ const uint8_t match_byte = mf->buffer[
+ mf->read_pos - coder->reps[0] - 1
+ - mf->read_ahead];
+ literal_matched(&coder->rc, subcoder, match_byte, cur_byte);
+ }
+
+ update_literal(coder->state);
+}
+
+
+//////////////////
+// Match length //
+//////////////////
+
+static void
+length_update_prices(lzma_length_encoder *lc, const uint32_t pos_state)
+{
+ uint32_t a0, a1, b0, b1;
+ uint32_t *prices;
+ uint32_t i;
+
+ const uint32_t table_size = lc->table_size;
+ lc->counters[pos_state] = table_size;
+
+ a0 = rc_bit_0_price(lc->choice);
+ a1 = rc_bit_1_price(lc->choice);
+ b0 = a1 + rc_bit_0_price(lc->choice2);
+ b1 = a1 + rc_bit_1_price(lc->choice2);
+ prices = lc->prices[pos_state];
+
+ for (i = 0; i < table_size && i < LEN_LOW_SYMBOLS; ++i)
+ prices[i] = a0 + rc_bittree_price(lc->low[pos_state],
+ LEN_LOW_BITS, i);
+
+ for (; i < table_size && i < LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS; ++i)
+ prices[i] = b0 + rc_bittree_price(lc->mid[pos_state],
+ LEN_MID_BITS, i - LEN_LOW_SYMBOLS);
+
+ for (; i < table_size; ++i)
+ prices[i] = b1 + rc_bittree_price(lc->high, LEN_HIGH_BITS,
+ i - LEN_LOW_SYMBOLS - LEN_MID_SYMBOLS);
+
+ return;
+}
+
+
+static inline void
+length(lzma_range_encoder *rc, lzma_length_encoder *lc,
+ const uint32_t pos_state, uint32_t len, const bool fast_mode)
+{
+ assert(len <= MATCH_LEN_MAX);
+ len -= MATCH_LEN_MIN;
+
+ if (len < LEN_LOW_SYMBOLS) {
+ rc_bit(rc, &lc->choice, 0);
+ rc_bittree(rc, lc->low[pos_state], LEN_LOW_BITS, len);
+ } else {
+ rc_bit(rc, &lc->choice, 1);
+ len -= LEN_LOW_SYMBOLS;
+
+ if (len < LEN_MID_SYMBOLS) {
+ rc_bit(rc, &lc->choice2, 0);
+ rc_bittree(rc, lc->mid[pos_state], LEN_MID_BITS, len);
+ } else {
+ rc_bit(rc, &lc->choice2, 1);
+ len -= LEN_MID_SYMBOLS;
+ rc_bittree(rc, lc->high, LEN_HIGH_BITS, len);
+ }
+ }
+
+ // Only getoptimum uses the prices so don't update the table when
+ // in fast mode.
+ if (!fast_mode)
+ if (--lc->counters[pos_state] == 0)
+ length_update_prices(lc, pos_state);
+}
+
+
+///////////
+// Match //
+///////////
+
+static inline void
+match(lzma_coder *coder, const uint32_t pos_state,
+ const uint32_t distance, const uint32_t len)
+{
+ uint32_t pos_slot;
+ uint32_t len_to_pos_state;
+
+ update_match(coder->state);
+
+ length(&coder->rc, &coder->match_len_encoder, pos_state, len,
+ coder->fast_mode);
+
+ pos_slot = get_pos_slot(distance);
+ len_to_pos_state = get_len_to_pos_state(len);
+ rc_bittree(&coder->rc, coder->pos_slot[len_to_pos_state],
+ POS_SLOT_BITS, pos_slot);
+
+ if (pos_slot >= START_POS_MODEL_INDEX) {
+ const uint32_t footer_bits = (pos_slot >> 1) - 1;
+ const uint32_t base = (2 | (pos_slot & 1)) << footer_bits;
+ const uint32_t pos_reduced = distance - base;
+
+ if (pos_slot < END_POS_MODEL_INDEX) {
+ // Careful here: base - pos_slot - 1 can be -1, but
+ // rc_bittree_reverse starts at probs[1], not probs[0].
+ rc_bittree_reverse(&coder->rc,
+ coder->pos_special + base - pos_slot - 1,
+ footer_bits, pos_reduced);
+ } else {
+ rc_direct(&coder->rc, pos_reduced >> ALIGN_BITS,
+ footer_bits - ALIGN_BITS);
+ rc_bittree_reverse(
+ &coder->rc, coder->pos_align,
+ ALIGN_BITS, pos_reduced & ALIGN_MASK);
+ ++coder->align_price_count;
+ }
+ }
+
+ coder->reps[3] = coder->reps[2];
+ coder->reps[2] = coder->reps[1];
+ coder->reps[1] = coder->reps[0];
+ coder->reps[0] = distance;
+ ++coder->match_price_count;
+}
+
+
+////////////////////
+// Repeated match //
+////////////////////
+
+static inline void
+rep_match(lzma_coder *coder, const uint32_t pos_state,
+ const uint32_t rep, const uint32_t len)
+{
+ if (rep == 0) {
+ rc_bit(&coder->rc, &coder->is_rep0[coder->state], 0);
+ rc_bit(&coder->rc,
+ &coder->is_rep0_long[coder->state][pos_state],
+ len != 1);
+ } else {
+ const uint32_t distance = coder->reps[rep];
+ rc_bit(&coder->rc, &coder->is_rep0[coder->state], 1);
+
+ if (rep == 1) {
+ rc_bit(&coder->rc, &coder->is_rep1[coder->state], 0);
+ } else {
+ rc_bit(&coder->rc, &coder->is_rep1[coder->state], 1);
+ rc_bit(&coder->rc, &coder->is_rep2[coder->state],
+ rep - 2);
+
+ if (rep == 3)
+ coder->reps[3] = coder->reps[2];
+
+ coder->reps[2] = coder->reps[1];
+ }
+
+ coder->reps[1] = coder->reps[0];
+ coder->reps[0] = distance;
+ }
+
+ if (len == 1) {
+ update_short_rep(coder->state);
+ } else {
+ length(&coder->rc, &coder->rep_len_encoder, pos_state, len,
+ coder->fast_mode);
+ update_long_rep(coder->state);
+ }
+}
+
+
+//////////
+// Main //
+//////////
+
+static void
+encode_symbol(lzma_coder *coder, lzma_mf *mf,
+ uint32_t back, uint32_t len, uint32_t position)
+{
+ const uint32_t pos_state = position & coder->pos_mask;
+
+ if (back == UINT32_MAX) {
+ // Literal i.e. eight-bit byte
+ assert(len == 1);
+ rc_bit(&coder->rc,
+ &coder->is_match[coder->state][pos_state], 0);
+ literal(coder, mf, position);
+ } else {
+ // Some type of match
+ rc_bit(&coder->rc,
+ &coder->is_match[coder->state][pos_state], 1);
+
+ if (back < REP_DISTANCES) {
+ // It's a repeated match i.e. the same distance
+ // has been used earlier.
+ rc_bit(&coder->rc, &coder->is_rep[coder->state], 1);
+ rep_match(coder, pos_state, back, len);
+ } else {
+ // Normal match
+ rc_bit(&coder->rc, &coder->is_rep[coder->state], 0);
+ match(coder, pos_state, back - REP_DISTANCES, len);
+ }
+ }
+
+ assert(mf->read_ahead >= len);
+ mf->read_ahead -= len;
+}
+
+
+static bool
+encode_init(lzma_coder *coder, lzma_mf *mf)
+{
+ assert(mf_position(mf) == 0);
+
+ if (mf->read_pos == mf->read_limit) {
+ if (mf->action == LZMA_RUN)
+ return false; // We cannot do anything.
+
+ // We are finishing (we cannot get here when flushing).
+ assert(mf->write_pos == mf->read_pos);
+ assert(mf->action == LZMA_FINISH);
+ } else {
+ // Do the actual initialization. The first LZMA symbol must
+ // always be a literal.
+ mf_skip(mf, 1);
+ mf->read_ahead = 0;
+ rc_bit(&coder->rc, &coder->is_match[0][0], 0);
+ rc_bittree(&coder->rc, coder->literal[0], 8, mf->buffer[0]);
+ }
+
+ // Initialization is done (except if empty file).
+ coder->is_initialized = true;
+
+ return true;
+}
+
+
+static void
+encode_eopm(lzma_coder *coder, uint32_t position)
+{
+ const uint32_t pos_state = position & coder->pos_mask;
+ rc_bit(&coder->rc, &coder->is_match[coder->state][pos_state], 1);
+ rc_bit(&coder->rc, &coder->is_rep[coder->state], 0);
+ match(coder, pos_state, UINT32_MAX, MATCH_LEN_MIN);
+}
+
+
+/// Number of bytes that a single encoding loop in lzma_lzma_encode() can
+/// consume from the dictionary. This limit comes from lzma_lzma_optimum()
+/// and may need to be updated if that function is significantly modified.
+#define LOOP_INPUT_MAX (OPTS + 1)
+
+
+extern lzma_ret
+lzma_lzma_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
+ uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
+ size_t out_size, uint32_t limit)
+{
+ uint32_t position;
+
+ // Initialize the stream if no data has been encoded yet.
+ if (!coder->is_initialized && !encode_init(coder, mf))
+ return LZMA_OK;
+
+ // Get the lowest bits of the uncompressed offset from the LZ layer.
+ position = mf_position(mf);
+
+ while (true) {
+ uint32_t len;
+ uint32_t back;
+
+ // Encode pending bits, if any. Calling this before encoding
+ // the next symbol is needed only with plain LZMA, since
+ // LZMA2 always provides big enough buffer to flush
+ // everything out from the range encoder. For the same reason,
+ // rc_encode() never returns true when this function is used
+ // as part of LZMA2 encoder.
+ if (rc_encode(&coder->rc, out, out_pos, out_size)) {
+ assert(limit == UINT32_MAX);
+ return LZMA_OK;
+ }
+
+ // With LZMA2 we need to take care that compressed size of
+ // a chunk doesn't get too big.
+ // FIXME? Check if this could be improved.
+ if (limit != UINT32_MAX
+ && (mf->read_pos - mf->read_ahead >= limit
+ || *out_pos + rc_pending(&coder->rc)
+ >= LZMA2_CHUNK_MAX
+ - LOOP_INPUT_MAX))
+ break;
+
+ // Check that there is some input to process.
+ if (mf->read_pos >= mf->read_limit) {
+ if (mf->action == LZMA_RUN)
+ return LZMA_OK;
+
+ if (mf->read_ahead == 0)
+ break;
+ }
+
+ // Get optimal match (repeat position and length).
+ // Value ranges for pos:
+ // - [0, REP_DISTANCES): repeated match
+ // - [REP_DISTANCES, UINT32_MAX):
+ // match at (pos - REP_DISTANCES)
+ // - UINT32_MAX: not a match but a literal
+ // Value ranges for len:
+ // - [MATCH_LEN_MIN, MATCH_LEN_MAX]
+
+ if (coder->fast_mode)
+ lzma_lzma_optimum_fast(coder, mf, &back, &len);
+ else
+ lzma_lzma_optimum_normal(
+ coder, mf, &back, &len, position);
+
+ encode_symbol(coder, mf, back, len, position);
+
+ position += len;
+ }
+
+ if (!coder->is_flushed) {
+ coder->is_flushed = true;
+
+ // We don't support encoding plain LZMA streams without EOPM,
+ // and LZMA2 doesn't use EOPM at LZMA level.
+ if (limit == UINT32_MAX)
+ encode_eopm(coder, position);
+
+ // Flush the remaining bytes from the range encoder.
+ rc_flush(&coder->rc);
+
+ // Copy the remaining bytes to the output buffer. If there
+ // isn't enough output space, we will copy out the remaining
+ // bytes on the next call to this function by using
+ // the rc_encode() call in the encoding loop above.
+ if (rc_encode(&coder->rc, out, out_pos, out_size)) {
+ assert(limit == UINT32_MAX);
+ return LZMA_OK;
+ }
+ }
+
+ // Make it ready for the next LZMA2 chunk.
+ coder->is_flushed = false;
+
+ return LZMA_STREAM_END;
+}
+
+
+static lzma_ret
+lzma_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
+ uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
+ size_t out_size)
+{
+ // Plain LZMA has no support for sync-flushing.
+ if (unlikely(mf->action == LZMA_SYNC_FLUSH))
+ return LZMA_OPTIONS_ERROR;
+
+ return lzma_lzma_encode(coder, mf, out, out_pos, out_size, UINT32_MAX);
+}
+
+
+////////////////////
+// Initialization //
+////////////////////
+
+static bool
+is_options_valid(const lzma_options_lzma *options)
+{
+ // Validate some of the options. LZ encoder validates nice_len too
+ // but we need a valid value here earlier.
+ return is_lclppb_valid(options)
+ && options->nice_len >= MATCH_LEN_MIN
+ && options->nice_len <= MATCH_LEN_MAX
+ && (options->mode == LZMA_MODE_FAST
+ || options->mode == LZMA_MODE_NORMAL);
+}
+
+
+static void
+set_lz_options(lzma_lz_options *lz_options, const lzma_options_lzma *options)
+{
+ // LZ encoder initialization does the validation for these so we
+ // don't need to validate here.
+ lz_options->before_size = OPTS;
+ lz_options->dict_size = options->dict_size;
+ lz_options->after_size = LOOP_INPUT_MAX;
+ lz_options->match_len_max = MATCH_LEN_MAX;
+ lz_options->nice_len = options->nice_len;
+ lz_options->match_finder = options->mf;
+ lz_options->depth = options->depth;
+ lz_options->preset_dict = options->preset_dict;
+ lz_options->preset_dict_size = options->preset_dict_size;
+ return;
+}
+
+
+static void
+length_encoder_reset(lzma_length_encoder *lencoder,
+ const uint32_t num_pos_states, const bool fast_mode)
+{
+ size_t pos_state;
+
+ bit_reset(lencoder->choice);
+ bit_reset(lencoder->choice2);
+
+ for (pos_state = 0; pos_state < num_pos_states; ++pos_state) {
+ bittree_reset(lencoder->low[pos_state], LEN_LOW_BITS);
+ bittree_reset(lencoder->mid[pos_state], LEN_MID_BITS);
+ }
+
+ bittree_reset(lencoder->high, LEN_HIGH_BITS);
+
+ if (!fast_mode)
+ for (pos_state = 0; pos_state < num_pos_states;
+ ++pos_state)
+ length_update_prices(lencoder, pos_state);
+
+ return;
+}
+
+
+extern lzma_ret
+lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
+{
+ size_t i, j;
+
+ if (!is_options_valid(options))
+ return LZMA_OPTIONS_ERROR;
+
+ coder->pos_mask = (1U << options->pb) - 1;
+ coder->literal_context_bits = options->lc;
+ coder->literal_pos_mask = (1U << options->lp) - 1;
+
+ // Range coder
+ rc_reset(&coder->rc);
+
+ // State
+ coder->state = STATE_LIT_LIT;
+ for (i = 0; i < REP_DISTANCES; ++i)
+ coder->reps[i] = 0;
+
+ literal_init(coder->literal, options->lc, options->lp);
+
+ // Bit encoders
+ for (i = 0; i < STATES; ++i) {
+ for (j = 0; j <= coder->pos_mask; ++j) {
+ bit_reset(coder->is_match[i][j]);
+ bit_reset(coder->is_rep0_long[i][j]);
+ }
+
+ bit_reset(coder->is_rep[i]);
+ bit_reset(coder->is_rep0[i]);
+ bit_reset(coder->is_rep1[i]);
+ bit_reset(coder->is_rep2[i]);
+ }
+
+ for (i = 0; i < FULL_DISTANCES - END_POS_MODEL_INDEX; ++i)
+ bit_reset(coder->pos_special[i]);
+
+ // Bit tree encoders
+ for (i = 0; i < LEN_TO_POS_STATES; ++i)
+ bittree_reset(coder->pos_slot[i], POS_SLOT_BITS);
+
+ bittree_reset(coder->pos_align, ALIGN_BITS);
+
+ // Length encoders
+ length_encoder_reset(&coder->match_len_encoder,
+ 1U << options->pb, coder->fast_mode);
+
+ length_encoder_reset(&coder->rep_len_encoder,
+ 1U << options->pb, coder->fast_mode);
+
+ // Price counts are incremented every time appropriate probabilities
+ // are changed. price counts are set to zero when the price tables
+ // are updated, which is done when the appropriate price counts have
+ // big enough value, and lzma_mf.read_ahead == 0 which happens at
+ // least every OPTS (a few thousand) possible price count increments.
+ //
+ // By resetting price counts to UINT32_MAX / 2, we make sure that the
+ // price tables will be initialized before they will be used (since
+ // the value is definitely big enough), and that it is OK to increment
+ // price counts without risk of integer overflow (since UINT32_MAX / 2
+ // is small enough). The current code doesn't increment price counts
+ // before initializing price tables, but it maybe done in future if
+ // we add support for saving the state between LZMA2 chunks.
+ coder->match_price_count = UINT32_MAX / 2;
+ coder->align_price_count = UINT32_MAX / 2;
+
+ coder->opts_end_index = 0;
+ coder->opts_current_index = 0;
+
+ return LZMA_OK;
+}
+
+
+extern lzma_ret
+lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator,
+ const lzma_options_lzma *options, lzma_lz_options *lz_options)
+{
+ lzma_coder *coder;
+ uint32_t log_size = 0;
+
+ // Allocate lzma_coder if it wasn't already allocated.
+ if (*coder_ptr == NULL) {
+ *coder_ptr = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (*coder_ptr == NULL)
+ return LZMA_MEM_ERROR;
+ }
+
+ coder = *coder_ptr;
+
+ // Set compression mode. We haven't validates the options yet,
+ // but it's OK here, since nothing bad happens with invalid
+ // options in the code below, and they will get rejected by
+ // lzma_lzma_encoder_reset() call at the end of this function.
+ switch (options->mode) {
+ case LZMA_MODE_FAST:
+ coder->fast_mode = true;
+ break;
+
+ case LZMA_MODE_NORMAL: {
+ coder->fast_mode = false;
+
+ // Set dist_table_size.
+ // Round the dictionary size up to next 2^n.
+ while ((UINT32_C(1) << log_size) < options->dict_size)
+ ++log_size;
+
+ coder->dist_table_size = log_size * 2;
+
+ // Length encoders' price table size
+ coder->match_len_encoder.table_size
+ = options->nice_len + 1 - MATCH_LEN_MIN;
+ coder->rep_len_encoder.table_size
+ = options->nice_len + 1 - MATCH_LEN_MIN;
+ break;
+ }
+
+ default:
+ return LZMA_OPTIONS_ERROR;
+ }
+
+ // We don't need to write the first byte as literal if there is
+ // a non-empty preset dictionary. encode_init() wouldn't even work
+ // if there is a non-empty preset dictionary, because encode_init()
+ // assumes that position is zero and previous byte is also zero.
+ coder->is_initialized = options->preset_dict != NULL
+ && options->preset_dict_size > 0;
+ coder->is_flushed = false;
+
+ set_lz_options(lz_options, options);
+
+ return lzma_lzma_encoder_reset(coder, options);
+}
+
+
+static lzma_ret
+lzma_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator,
+ const void *options, lzma_lz_options *lz_options)
+{
+ lz->code = &lzma_encode;
+ return lzma_lzma_encoder_create(
+ &lz->coder, allocator, options, lz_options);
+}
+
+
+extern lzma_ret
+lzma_lzma_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ return lzma_lz_encoder_init(
+ next, allocator, filters, &lzma_encoder_init);
+}
+
+
+extern uint64_t
+lzma_lzma_encoder_memusage(const void *options)
+{
+ lzma_lz_options lz_options;
+ uint64_t lz_memusage;
+
+ if (!is_options_valid(options))
+ return UINT64_MAX;
+
+ set_lz_options(&lz_options, options);
+
+ lz_memusage = lzma_lz_encoder_memusage(&lz_options);
+ if (lz_memusage == UINT64_MAX)
+ return UINT64_MAX;
+
+ return (uint64_t)(sizeof(lzma_coder)) + lz_memusage;
+}
+
+
+extern bool
+lzma_lzma_lclppb_encode(const lzma_options_lzma *options, uint8_t *byte)
+{
+ if (!is_lclppb_valid(options))
+ return true;
+
+ *byte = (options->pb * 5 + options->lp) * 9 + options->lc;
+ assert(*byte <= (4 * 5 + 4) * 9 + 8);
+
+ return false;
+}
+
+
+#ifdef HAVE_ENCODER_LZMA1
+extern lzma_ret
+lzma_lzma_props_encode(const void *options, uint8_t *out)
+{
+ const lzma_options_lzma *const opt = options;
+
+ if (lzma_lzma_lclppb_encode(opt, out))
+ return LZMA_PROG_ERROR;
+
+ unaligned_write32le(out + 1, opt->dict_size);
+
+ return LZMA_OK;
+}
+#endif
+
+
+extern LZMA_API(lzma_bool)
+lzma_mode_is_supported(lzma_mode mode)
+{
+ return mode == LZMA_MODE_FAST || mode == LZMA_MODE_NORMAL;
+}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.h b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.h
new file mode 100644
index 0000000000..abb8d8b469
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.h
@@ -0,0 +1,54 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma_encoder.h
+/// \brief LZMA encoder API
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_LZMA_ENCODER_H
+#define LZMA_LZMA_ENCODER_H
+
+#include "common.h"
+
+
+extern lzma_ret lzma_lzma_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+
+extern uint64_t lzma_lzma_encoder_memusage(const void *options);
+
+extern lzma_ret lzma_lzma_props_encode(const void *options, uint8_t *out);
+
+
+/// Encodes lc/lp/pb into one byte. Returns false on success and true on error.
+extern bool lzma_lzma_lclppb_encode(
+ const lzma_options_lzma *options, uint8_t *byte);
+
+
+#ifdef LZMA_LZ_ENCODER_H
+
+/// Initializes raw LZMA encoder; this is used by LZMA2.
+extern lzma_ret lzma_lzma_encoder_create(
+ lzma_coder **coder_ptr, lzma_allocator *allocator,
+ const lzma_options_lzma *options, lzma_lz_options *lz_options);
+
+
+/// Resets an already initialized LZMA encoder; this is used by LZMA2.
+extern lzma_ret lzma_lzma_encoder_reset(
+ lzma_coder *coder, const lzma_options_lzma *options);
+
+
+extern lzma_ret lzma_lzma_encode(lzma_coder *LZMA_RESTRICT coder,
+ lzma_mf *LZMA_RESTRICT mf, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size,
+ uint32_t read_limit);
+
+#endif
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_fast.c b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_fast.c
new file mode 100644
index 0000000000..f983126433
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_fast.c
@@ -0,0 +1,185 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma_encoder_optimum_fast.c
+//
+// Author: Igor Pavlov
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "lzma_encoder_private.h"
+
+
+#define change_pair(small_dist, big_dist) \
+ (((big_dist) >> 7) > (small_dist))
+
+
+extern void
+lzma_lzma_optimum_fast(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
+ uint32_t *LZMA_RESTRICT back_res, uint32_t *LZMA_RESTRICT len_res)
+{
+ const uint8_t *buf;
+ uint32_t buf_avail;
+ uint32_t i;
+ uint32_t rep_len = 0;
+ uint32_t rep_index = 0;
+ uint32_t back_main = 0;
+ uint32_t limit;
+
+ const uint32_t nice_len = mf->nice_len;
+
+ uint32_t len_main;
+ uint32_t matches_count;
+ if (mf->read_ahead == 0) {
+ len_main = mf_find(mf, &matches_count, coder->matches);
+ } else {
+ assert(mf->read_ahead == 1);
+ len_main = coder->longest_match_length;
+ matches_count = coder->matches_count;
+ }
+
+ buf = mf_ptr(mf) - 1;
+ buf_avail = my_min(mf_avail(mf) + 1, MATCH_LEN_MAX);
+
+ if (buf_avail < 2) {
+ // There's not enough input left to encode a match.
+ *back_res = UINT32_MAX;
+ *len_res = 1;
+ return;
+ }
+
+ // Look for repeated matches; scan the previous four match distances
+ for (i = 0; i < REP_DISTANCES; ++i) {
+ uint32_t len;
+
+ // Pointer to the beginning of the match candidate
+ const uint8_t *const buf_back = buf - coder->reps[i] - 1;
+
+ // If the first two bytes (2 == MATCH_LEN_MIN) do not match,
+ // this rep is not useful.
+ if (not_equal_16(buf, buf_back))
+ continue;
+
+ // The first two bytes matched.
+ // Calculate the length of the match.
+ for (len = 2; len < buf_avail
+ && buf[len] == buf_back[len]; ++len) ;
+
+ // If we have found a repeated match that is at least
+ // nice_len long, return it immediately.
+ if (len >= nice_len) {
+ *back_res = i;
+ *len_res = len;
+ mf_skip(mf, len - 1);
+ return;
+ }
+
+ if (len > rep_len) {
+ rep_index = i;
+ rep_len = len;
+ }
+ }
+
+ // We didn't find a long enough repeated match. Encode it as a normal
+ // match if the match length is at least nice_len.
+ if (len_main >= nice_len) {
+ *back_res = coder->matches[matches_count - 1].dist
+ + REP_DISTANCES;
+ *len_res = len_main;
+ mf_skip(mf, len_main - 1);
+ return;
+ }
+
+ if (len_main >= 2) {
+ back_main = coder->matches[matches_count - 1].dist;
+
+ while (matches_count > 1 && len_main ==
+ coder->matches[matches_count - 2].len + 1) {
+ if (!change_pair(coder->matches[
+ matches_count - 2].dist,
+ back_main))
+ break;
+
+ --matches_count;
+ len_main = coder->matches[matches_count - 1].len;
+ back_main = coder->matches[matches_count - 1].dist;
+ }
+
+ if (len_main == 2 && back_main >= 0x80)
+ len_main = 1;
+ }
+
+ if (rep_len >= 2) {
+ if (rep_len + 1 >= len_main
+ || (rep_len + 2 >= len_main
+ && back_main > (UINT32_C(1) << 9))
+ || (rep_len + 3 >= len_main
+ && back_main > (UINT32_C(1) << 15))) {
+ *back_res = rep_index;
+ *len_res = rep_len;
+ mf_skip(mf, rep_len - 1);
+ return;
+ }
+ }
+
+ if (len_main < 2 || buf_avail <= 2) {
+ *back_res = UINT32_MAX;
+ *len_res = 1;
+ return;
+ }
+
+ // Get the matches for the next byte. If we find a better match,
+ // the current byte is encoded as a literal.
+ coder->longest_match_length = mf_find(mf,
+ &coder->matches_count, coder->matches);
+
+ if (coder->longest_match_length >= 2) {
+ const uint32_t new_dist = coder->matches[
+ coder->matches_count - 1].dist;
+
+ if ((coder->longest_match_length >= len_main
+ && new_dist < back_main)
+ || (coder->longest_match_length == len_main + 1
+ && !change_pair(back_main, new_dist))
+ || (coder->longest_match_length > len_main + 1)
+ || (coder->longest_match_length + 1 >= len_main
+ && len_main >= 3
+ && change_pair(new_dist, back_main))) {
+ *back_res = UINT32_MAX;
+ *len_res = 1;
+ return;
+ }
+ }
+
+ // In contrast to LZMA SDK, dictionary could not have been moved
+ // between mf_find() calls, thus it is safe to just increment
+ // the old buf pointer instead of recalculating it with mf_ptr().
+ ++buf;
+
+ limit = len_main - 1;
+
+ for (i = 0; i < REP_DISTANCES; ++i) {
+ uint32_t len;
+
+ const uint8_t *const buf_back = buf - coder->reps[i] - 1;
+
+ if (not_equal_16(buf, buf_back))
+ continue;
+
+ for (len = 2; len < limit
+ && buf[len] == buf_back[len]; ++len) ;
+
+ if (len >= limit) {
+ *back_res = UINT32_MAX;
+ *len_res = 1;
+ return;
+ }
+ }
+
+ *back_res = back_main + REP_DISTANCES;
+ *len_res = len_main;
+ mf_skip(mf, len_main - 2);
+ return;
+}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_normal.c b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_normal.c
new file mode 100644
index 0000000000..d3a63485cd
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_normal.c
@@ -0,0 +1,925 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma_encoder_optimum_normal.c
+//
+// Author: Igor Pavlov
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "lzma_encoder_private.h"
+#include "fastpos.h"
+
+
+////////////
+// Prices //
+////////////
+
+static uint32_t
+get_literal_price(const lzma_coder *const coder, const uint32_t pos,
+ const uint32_t prev_byte, const bool match_mode,
+ uint32_t match_byte, uint32_t symbol)
+{
+ const probability *const subcoder = literal_subcoder(coder->literal,
+ coder->literal_context_bits, coder->literal_pos_mask,
+ pos, prev_byte);
+
+ uint32_t price = 0;
+
+ if (!match_mode) {
+ price = rc_bittree_price(subcoder, 8, symbol);
+ } else {
+ uint32_t offset = 0x100;
+ symbol += UINT32_C(1) << 8;
+
+ do {
+ uint32_t match_bit;
+ uint32_t subcoder_index;
+ uint32_t bit;
+
+ match_byte <<= 1;
+
+ match_bit = match_byte & offset;
+ subcoder_index = offset + match_bit + (symbol >> 8);
+ bit = (symbol >> 7) & 1;
+ price += rc_bit_price(subcoder[subcoder_index], bit);
+
+ symbol <<= 1;
+ offset &= ~(match_byte ^ symbol);
+
+ } while (symbol < (UINT32_C(1) << 16));
+ }
+
+ return price;
+}
+
+
+static inline uint32_t
+get_len_price(const lzma_length_encoder *const lencoder,
+ const uint32_t len, const uint32_t pos_state)
+{
+ // NOTE: Unlike the other price tables, length prices are updated
+ // in lzma_encoder.c
+ return lencoder->prices[pos_state][len - MATCH_LEN_MIN];
+}
+
+
+static inline uint32_t
+get_short_rep_price(const lzma_coder *const coder,
+ const lzma_lzma_state state, const uint32_t pos_state)
+{
+ return rc_bit_0_price(coder->is_rep0[state])
+ + rc_bit_0_price(coder->is_rep0_long[state][pos_state]);
+}
+
+
+static inline uint32_t
+get_pure_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
+ const lzma_lzma_state state, uint32_t pos_state)
+{
+ uint32_t price;
+
+ if (rep_index == 0) {
+ price = rc_bit_0_price(coder->is_rep0[state]);
+ price += rc_bit_1_price(coder->is_rep0_long[state][pos_state]);
+ } else {
+ price = rc_bit_1_price(coder->is_rep0[state]);
+
+ if (rep_index == 1) {
+ price += rc_bit_0_price(coder->is_rep1[state]);
+ } else {
+ price += rc_bit_1_price(coder->is_rep1[state]);
+ price += rc_bit_price(coder->is_rep2[state],
+ rep_index - 2);
+ }
+ }
+
+ return price;
+}
+
+
+static inline uint32_t
+get_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
+ const uint32_t len, const lzma_lzma_state state,
+ const uint32_t pos_state)
+{
+ return get_len_price(&coder->rep_len_encoder, len, pos_state)
+ + get_pure_rep_price(coder, rep_index, state, pos_state);
+}
+
+
+static inline uint32_t
+get_pos_len_price(const lzma_coder *const coder, const uint32_t pos,
+ const uint32_t len, const uint32_t pos_state)
+{
+ const uint32_t len_to_pos_state = get_len_to_pos_state(len);
+ uint32_t price;
+
+ if (pos < FULL_DISTANCES) {
+ price = coder->distances_prices[len_to_pos_state][pos];
+ } else {
+ const uint32_t pos_slot = get_pos_slot_2(pos);
+ price = coder->pos_slot_prices[len_to_pos_state][pos_slot]
+ + coder->align_prices[pos & ALIGN_MASK];
+ }
+
+ price += get_len_price(&coder->match_len_encoder, len, pos_state);
+
+ return price;
+}
+
+
+static void
+fill_distances_prices(lzma_coder *coder)
+{
+ uint32_t len_to_pos_state;
+ uint32_t pos_slot;
+ uint32_t i;
+
+ for (len_to_pos_state = 0;
+ len_to_pos_state < LEN_TO_POS_STATES;
+ ++len_to_pos_state) {
+
+ uint32_t *const pos_slot_prices
+ = coder->pos_slot_prices[len_to_pos_state];
+
+ // Price to encode the pos_slot.
+ for (pos_slot = 0;
+ pos_slot < coder->dist_table_size; ++pos_slot)
+ pos_slot_prices[pos_slot] = rc_bittree_price(
+ coder->pos_slot[len_to_pos_state],
+ POS_SLOT_BITS, pos_slot);
+
+ // For matches with distance >= FULL_DISTANCES, add the price
+ // of the direct bits part of the match distance. (Align bits
+ // are handled by fill_align_prices()).
+ for (pos_slot = END_POS_MODEL_INDEX;
+ pos_slot < coder->dist_table_size; ++pos_slot)
+ pos_slot_prices[pos_slot] += rc_direct_price(
+ ((pos_slot >> 1) - 1) - ALIGN_BITS);
+
+ // Distances in the range [0, 3] are fully encoded with
+ // pos_slot, so they are used for coder->distances_prices
+ // as is.
+ for (i = 0; i < START_POS_MODEL_INDEX; ++i)
+ coder->distances_prices[len_to_pos_state][i]
+ = pos_slot_prices[i];
+ }
+
+ // Distances in the range [4, 127] depend on pos_slot and pos_special.
+ // We do this in a loop separate from the above loop to avoid
+ // redundant calls to get_pos_slot().
+ for (i = START_POS_MODEL_INDEX; i < FULL_DISTANCES; ++i) {
+ const uint32_t pos_slot = get_pos_slot(i);
+ const uint32_t footer_bits = ((pos_slot >> 1) - 1);
+ const uint32_t base = (2 | (pos_slot & 1)) << footer_bits;
+ const uint32_t price = rc_bittree_reverse_price(
+ coder->pos_special + base - pos_slot - 1,
+ footer_bits, i - base);
+
+ for (len_to_pos_state = 0;
+ len_to_pos_state < LEN_TO_POS_STATES;
+ ++len_to_pos_state)
+ coder->distances_prices[len_to_pos_state][i]
+ = price + coder->pos_slot_prices[
+ len_to_pos_state][pos_slot];
+ }
+
+ coder->match_price_count = 0;
+ return;
+}
+
+
+static void
+fill_align_prices(lzma_coder *coder)
+{
+ uint32_t i;
+ for (i = 0; i < ALIGN_TABLE_SIZE; ++i)
+ coder->align_prices[i] = rc_bittree_reverse_price(
+ coder->pos_align, ALIGN_BITS, i);
+
+ coder->align_price_count = 0;
+ return;
+}
+
+
+/////////////
+// Optimal //
+/////////////
+
+static inline void
+make_literal(lzma_optimal *optimal)
+{
+ optimal->back_prev = UINT32_MAX;
+ optimal->prev_1_is_literal = false;
+}
+
+
+static inline void
+make_short_rep(lzma_optimal *optimal)
+{
+ optimal->back_prev = 0;
+ optimal->prev_1_is_literal = false;
+}
+
+
+#define is_short_rep(optimal) \
+ ((optimal).back_prev == 0)
+
+
+static void
+backward(lzma_coder *LZMA_RESTRICT coder, uint32_t *LZMA_RESTRICT len_res,
+ uint32_t *LZMA_RESTRICT back_res, uint32_t cur)
+{
+ uint32_t pos_mem = coder->opts[cur].pos_prev;
+ uint32_t back_mem = coder->opts[cur].back_prev;
+
+ coder->opts_end_index = cur;
+
+ do {
+ const uint32_t pos_prev = pos_mem;
+ const uint32_t back_cur = back_mem;
+
+ if (coder->opts[cur].prev_1_is_literal) {
+ make_literal(&coder->opts[pos_mem]);
+ coder->opts[pos_mem].pos_prev = pos_mem - 1;
+
+ if (coder->opts[cur].prev_2) {
+ coder->opts[pos_mem - 1].prev_1_is_literal
+ = false;
+ coder->opts[pos_mem - 1].pos_prev
+ = coder->opts[cur].pos_prev_2;
+ coder->opts[pos_mem - 1].back_prev
+ = coder->opts[cur].back_prev_2;
+ }
+ }
+
+ back_mem = coder->opts[pos_prev].back_prev;
+ pos_mem = coder->opts[pos_prev].pos_prev;
+
+ coder->opts[pos_prev].back_prev = back_cur;
+ coder->opts[pos_prev].pos_prev = cur;
+ cur = pos_prev;
+
+ } while (cur != 0);
+
+ coder->opts_current_index = coder->opts[0].pos_prev;
+ *len_res = coder->opts[0].pos_prev;
+ *back_res = coder->opts[0].back_prev;
+
+ return;
+}
+
+
+//////////
+// Main //
+//////////
+
+static inline uint32_t
+helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
+ uint32_t *LZMA_RESTRICT back_res, uint32_t *LZMA_RESTRICT len_res,
+ uint32_t position)
+{
+ uint32_t buf_avail;
+ const uint8_t *buf;
+ uint32_t rep_lens[REP_DISTANCES];
+ uint32_t rep_max_index = 0;
+ uint32_t i;
+
+ uint8_t current_byte;
+ uint8_t match_byte;
+
+ uint32_t pos_state;
+ uint32_t match_price;
+ uint32_t rep_match_price;
+ uint32_t len_end;
+ uint32_t len;
+
+ uint32_t normal_match_price;
+
+ const uint32_t nice_len = mf->nice_len;
+
+ uint32_t len_main;
+ uint32_t matches_count;
+
+ if (mf->read_ahead == 0) {
+ len_main = mf_find(mf, &matches_count, coder->matches);
+ } else {
+ assert(mf->read_ahead == 1);
+ len_main = coder->longest_match_length;
+ matches_count = coder->matches_count;
+ }
+
+ buf_avail = my_min(mf_avail(mf) + 1, MATCH_LEN_MAX);
+ if (buf_avail < 2) {
+ *back_res = UINT32_MAX;
+ *len_res = 1;
+ return UINT32_MAX;
+ }
+
+ buf = mf_ptr(mf) - 1;
+
+ for (i = 0; i < REP_DISTANCES; ++i) {
+ uint32_t len_test;
+
+ const uint8_t *const buf_back = buf - coder->reps[i] - 1;
+
+ if (not_equal_16(buf, buf_back)) {
+ rep_lens[i] = 0;
+ continue;
+ }
+
+ for (len_test = 2; len_test < buf_avail
+ && buf[len_test] == buf_back[len_test];
+ ++len_test) ;
+
+ rep_lens[i] = len_test;
+ if (len_test > rep_lens[rep_max_index])
+ rep_max_index = i;
+ }
+
+ if (rep_lens[rep_max_index] >= nice_len) {
+ *back_res = rep_max_index;
+ *len_res = rep_lens[rep_max_index];
+ mf_skip(mf, *len_res - 1);
+ return UINT32_MAX;
+ }
+
+
+ if (len_main >= nice_len) {
+ *back_res = coder->matches[matches_count - 1].dist
+ + REP_DISTANCES;
+ *len_res = len_main;
+ mf_skip(mf, len_main - 1);
+ return UINT32_MAX;
+ }
+
+ current_byte = *buf;
+ match_byte = *(buf - coder->reps[0] - 1);
+
+ if (len_main < 2 && current_byte != match_byte
+ && rep_lens[rep_max_index] < 2) {
+ *back_res = UINT32_MAX;
+ *len_res = 1;
+ return UINT32_MAX;
+ }
+
+ coder->opts[0].state = coder->state;
+
+ pos_state = position & coder->pos_mask;
+
+ coder->opts[1].price = rc_bit_0_price(
+ coder->is_match[coder->state][pos_state])
+ + get_literal_price(coder, position, buf[-1],
+ !is_literal_state(coder->state),
+ match_byte, current_byte);
+
+ make_literal(&coder->opts[1]);
+
+ match_price = rc_bit_1_price(
+ coder->is_match[coder->state][pos_state]);
+ rep_match_price = match_price
+ + rc_bit_1_price(coder->is_rep[coder->state]);
+
+ if (match_byte == current_byte) {
+ const uint32_t short_rep_price = rep_match_price
+ + get_short_rep_price(
+ coder, coder->state, pos_state);
+
+ if (short_rep_price < coder->opts[1].price) {
+ coder->opts[1].price = short_rep_price;
+ make_short_rep(&coder->opts[1]);
+ }
+ }
+
+ len_end = my_max(len_main, rep_lens[rep_max_index]);
+
+ if (len_end < 2) {
+ *back_res = coder->opts[1].back_prev;
+ *len_res = 1;
+ return UINT32_MAX;
+ }
+
+ coder->opts[1].pos_prev = 0;
+
+ for (i = 0; i < REP_DISTANCES; ++i)
+ coder->opts[0].backs[i] = coder->reps[i];
+
+ len = len_end;
+ do {
+ coder->opts[len].price = RC_INFINITY_PRICE;
+ } while (--len >= 2);
+
+
+ for (i = 0; i < REP_DISTANCES; ++i) {
+ uint32_t price;
+
+ uint32_t rep_len = rep_lens[i];
+ if (rep_len < 2)
+ continue;
+
+ price = rep_match_price + get_pure_rep_price(
+ coder, i, coder->state, pos_state);
+
+ do {
+ const uint32_t cur_and_len_price = price
+ + get_len_price(
+ &coder->rep_len_encoder,
+ rep_len, pos_state);
+
+ if (cur_and_len_price < coder->opts[rep_len].price) {
+ coder->opts[rep_len].price = cur_and_len_price;
+ coder->opts[rep_len].pos_prev = 0;
+ coder->opts[rep_len].back_prev = i;
+ coder->opts[rep_len].prev_1_is_literal = false;
+ }
+ } while (--rep_len >= 2);
+ }
+
+
+ normal_match_price = match_price
+ + rc_bit_0_price(coder->is_rep[coder->state]);
+
+ len = rep_lens[0] >= 2 ? rep_lens[0] + 1 : 2;
+ if (len <= len_main) {
+ uint32_t i = 0;
+ while (len > coder->matches[i].len)
+ ++i;
+
+ for(; ; ++len) {
+ const uint32_t dist = coder->matches[i].dist;
+ const uint32_t cur_and_len_price = normal_match_price
+ + get_pos_len_price(coder,
+ dist, len, pos_state);
+
+ if (cur_and_len_price < coder->opts[len].price) {
+ coder->opts[len].price = cur_and_len_price;
+ coder->opts[len].pos_prev = 0;
+ coder->opts[len].back_prev
+ = dist + REP_DISTANCES;
+ coder->opts[len].prev_1_is_literal = false;
+ }
+
+ if (len == coder->matches[i].len)
+ if (++i == matches_count)
+ break;
+ }
+ }
+
+ return len_end;
+}
+
+
+static inline uint32_t
+helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
+ uint32_t len_end, uint32_t position, const uint32_t cur,
+ const uint32_t nice_len, const uint32_t buf_avail_full)
+{
+ uint32_t matches_count = coder->matches_count;
+ uint32_t new_len = coder->longest_match_length;
+ uint32_t pos_prev = coder->opts[cur].pos_prev;
+ lzma_lzma_state state;
+ uint32_t buf_avail;
+ uint32_t rep_index;
+ uint32_t i;
+
+ uint32_t cur_price;
+ uint8_t current_byte;
+ uint8_t match_byte;
+ uint32_t pos_state;
+ uint32_t cur_and_1_price;
+ bool next_is_literal = false;
+ uint32_t match_price;
+ uint32_t rep_match_price;
+ uint32_t start_len = 2;
+
+ if (coder->opts[cur].prev_1_is_literal) {
+ --pos_prev;
+
+ if (coder->opts[cur].prev_2) {
+ state = coder->opts[coder->opts[cur].pos_prev_2].state;
+
+ if (coder->opts[cur].back_prev_2 < REP_DISTANCES)
+ update_long_rep(state);
+ else
+ update_match(state);
+
+ } else {
+ state = coder->opts[pos_prev].state;
+ }
+
+ update_literal(state);
+
+ } else {
+ state = coder->opts[pos_prev].state;
+ }
+
+ if (pos_prev == cur - 1) {
+ if (is_short_rep(coder->opts[cur]))
+ update_short_rep(state);
+ else
+ update_literal(state);
+ } else {
+ uint32_t pos;
+ if (coder->opts[cur].prev_1_is_literal
+ && coder->opts[cur].prev_2) {
+ pos_prev = coder->opts[cur].pos_prev_2;
+ pos = coder->opts[cur].back_prev_2;
+ update_long_rep(state);
+ } else {
+ pos = coder->opts[cur].back_prev;
+ if (pos < REP_DISTANCES)
+ update_long_rep(state);
+ else
+ update_match(state);
+ }
+
+ if (pos < REP_DISTANCES) {
+ uint32_t i;
+
+ reps[0] = coder->opts[pos_prev].backs[pos];
+
+ for (i = 1; i <= pos; ++i)
+ reps[i] = coder->opts[pos_prev].backs[i - 1];
+
+ for (; i < REP_DISTANCES; ++i)
+ reps[i] = coder->opts[pos_prev].backs[i];
+
+ } else {
+ reps[0] = pos - REP_DISTANCES;
+
+ for (i = 1; i < REP_DISTANCES; ++i)
+ reps[i] = coder->opts[pos_prev].backs[i - 1];
+ }
+ }
+
+ coder->opts[cur].state = state;
+
+ for (i = 0; i < REP_DISTANCES; ++i)
+ coder->opts[cur].backs[i] = reps[i];
+
+ cur_price = coder->opts[cur].price;
+
+ current_byte = *buf;
+ match_byte = *(buf - reps[0] - 1);
+
+ pos_state = position & coder->pos_mask;
+
+ cur_and_1_price = cur_price
+ + rc_bit_0_price(coder->is_match[state][pos_state])
+ + get_literal_price(coder, position, buf[-1],
+ !is_literal_state(state), match_byte, current_byte);
+
+ if (cur_and_1_price < coder->opts[cur + 1].price) {
+ coder->opts[cur + 1].price = cur_and_1_price;
+ coder->opts[cur + 1].pos_prev = cur;
+ make_literal(&coder->opts[cur + 1]);
+ next_is_literal = true;
+ }
+
+ match_price = cur_price
+ + rc_bit_1_price(coder->is_match[state][pos_state]);
+ rep_match_price = match_price
+ + rc_bit_1_price(coder->is_rep[state]);
+
+ if (match_byte == current_byte
+ && !(coder->opts[cur + 1].pos_prev < cur
+ && coder->opts[cur + 1].back_prev == 0)) {
+
+ const uint32_t short_rep_price = rep_match_price
+ + get_short_rep_price(coder, state, pos_state);
+
+ if (short_rep_price <= coder->opts[cur + 1].price) {
+ coder->opts[cur + 1].price = short_rep_price;
+ coder->opts[cur + 1].pos_prev = cur;
+ make_short_rep(&coder->opts[cur + 1]);
+ next_is_literal = true;
+ }
+ }
+
+ if (buf_avail_full < 2)
+ return len_end;
+
+ buf_avail = my_min(buf_avail_full, nice_len);
+
+ if (!next_is_literal && match_byte != current_byte) { // speed optimization
+ // try literal + rep0
+ const uint8_t *const buf_back = buf - reps[0] - 1;
+ const uint32_t limit = my_min(buf_avail_full, nice_len + 1);
+
+ uint32_t len_test = 1;
+ while (len_test < limit && buf[len_test] == buf_back[len_test])
+ ++len_test;
+
+ --len_test;
+
+ if (len_test >= 2) {
+ uint32_t pos_state_next;
+ uint32_t next_rep_match_price;
+ uint32_t offset;
+ uint32_t cur_and_len_price;
+
+ lzma_lzma_state state_2 = state;
+ update_literal(state_2);
+
+ pos_state_next = (position + 1) & coder->pos_mask;
+ next_rep_match_price = cur_and_1_price
+ + rc_bit_1_price(coder->is_match[state_2][pos_state_next])
+ + rc_bit_1_price(coder->is_rep[state_2]);
+
+ //for (; len_test >= 2; --len_test) {
+ offset = cur + 1 + len_test;
+
+ while (len_end < offset)
+ coder->opts[++len_end].price = RC_INFINITY_PRICE;
+
+ cur_and_len_price = next_rep_match_price
+ + get_rep_price(coder, 0, len_test,
+ state_2, pos_state_next);
+
+ if (cur_and_len_price < coder->opts[offset].price) {
+ coder->opts[offset].price = cur_and_len_price;
+ coder->opts[offset].pos_prev = cur + 1;
+ coder->opts[offset].back_prev = 0;
+ coder->opts[offset].prev_1_is_literal = true;
+ coder->opts[offset].prev_2 = false;
+ }
+ //}
+ }
+ }
+
+
+ for (rep_index = 0; rep_index < REP_DISTANCES; ++rep_index) {
+ uint32_t len_test, len_test_2, len_test_temp;
+ uint32_t price, limit;
+
+ const uint8_t *const buf_back = buf - reps[rep_index] - 1;
+ if (not_equal_16(buf, buf_back))
+ continue;
+
+ for (len_test = 2; len_test < buf_avail
+ && buf[len_test] == buf_back[len_test];
+ ++len_test) ;
+
+ while (len_end < cur + len_test)
+ coder->opts[++len_end].price = RC_INFINITY_PRICE;
+
+ len_test_temp = len_test;
+ price = rep_match_price + get_pure_rep_price(
+ coder, rep_index, state, pos_state);
+
+ do {
+ const uint32_t cur_and_len_price = price
+ + get_len_price(&coder->rep_len_encoder,
+ len_test, pos_state);
+
+ if (cur_and_len_price < coder->opts[cur + len_test].price) {
+ coder->opts[cur + len_test].price = cur_and_len_price;
+ coder->opts[cur + len_test].pos_prev = cur;
+ coder->opts[cur + len_test].back_prev = rep_index;
+ coder->opts[cur + len_test].prev_1_is_literal = false;
+ }
+ } while (--len_test >= 2);
+
+ len_test = len_test_temp;
+
+ if (rep_index == 0)
+ start_len = len_test + 1;
+
+
+ len_test_2 = len_test + 1;
+ limit = my_min(buf_avail_full,
+ len_test_2 + nice_len);
+ for (; len_test_2 < limit
+ && buf[len_test_2] == buf_back[len_test_2];
+ ++len_test_2) ;
+
+ len_test_2 -= len_test + 1;
+
+ if (len_test_2 >= 2) {
+ uint32_t pos_state_next;
+ uint32_t cur_and_len_literal_price;
+ uint32_t next_rep_match_price;
+ uint32_t offset;
+ uint32_t cur_and_len_price;
+
+ lzma_lzma_state state_2 = state;
+ update_long_rep(state_2);
+
+ pos_state_next = (position + len_test) & coder->pos_mask;
+
+ cur_and_len_literal_price = price
+ + get_len_price(&coder->rep_len_encoder,
+ len_test, pos_state)
+ + rc_bit_0_price(coder->is_match[state_2][pos_state_next])
+ + get_literal_price(coder, position + len_test,
+ buf[len_test - 1], true,
+ buf_back[len_test], buf[len_test]);
+
+ update_literal(state_2);
+
+ pos_state_next = (position + len_test + 1) & coder->pos_mask;
+
+ next_rep_match_price = cur_and_len_literal_price
+ + rc_bit_1_price(coder->is_match[state_2][pos_state_next])
+ + rc_bit_1_price(coder->is_rep[state_2]);
+
+ //for(; len_test_2 >= 2; len_test_2--) {
+ offset = cur + len_test + 1 + len_test_2;
+
+ while (len_end < offset)
+ coder->opts[++len_end].price = RC_INFINITY_PRICE;
+
+ cur_and_len_price = next_rep_match_price
+ + get_rep_price(coder, 0, len_test_2,
+ state_2, pos_state_next);
+
+ if (cur_and_len_price < coder->opts[offset].price) {
+ coder->opts[offset].price = cur_and_len_price;
+ coder->opts[offset].pos_prev = cur + len_test + 1;
+ coder->opts[offset].back_prev = 0;
+ coder->opts[offset].prev_1_is_literal = true;
+ coder->opts[offset].prev_2 = true;
+ coder->opts[offset].pos_prev_2 = cur;
+ coder->opts[offset].back_prev_2 = rep_index;
+ }
+ //}
+ }
+ }
+
+
+ //for (uint32_t len_test = 2; len_test <= new_len; ++len_test)
+ if (new_len > buf_avail) {
+ new_len = buf_avail;
+
+ matches_count = 0;
+ while (new_len > coder->matches[matches_count].len)
+ ++matches_count;
+
+ coder->matches[matches_count++].len = new_len;
+ }
+
+
+ if (new_len >= start_len) {
+ uint32_t len_test;
+ uint32_t i = 0;
+
+ const uint32_t normal_match_price = match_price
+ + rc_bit_0_price(coder->is_rep[state]);
+
+ while (len_end < cur + new_len)
+ coder->opts[++len_end].price = RC_INFINITY_PRICE;
+
+ while (start_len > coder->matches[i].len)
+ ++i;
+
+ for (len_test = start_len; ; ++len_test) {
+ const uint32_t cur_back = coder->matches[i].dist;
+ uint32_t cur_and_len_price = normal_match_price
+ + get_pos_len_price(coder,
+ cur_back, len_test, pos_state);
+
+ if (cur_and_len_price < coder->opts[cur + len_test].price) {
+ coder->opts[cur + len_test].price = cur_and_len_price;
+ coder->opts[cur + len_test].pos_prev = cur;
+ coder->opts[cur + len_test].back_prev
+ = cur_back + REP_DISTANCES;
+ coder->opts[cur + len_test].prev_1_is_literal = false;
+ }
+
+ if (len_test == coder->matches[i].len) {
+ // Try Match + Literal + Rep0
+ const uint8_t *const buf_back = buf - cur_back - 1;
+ uint32_t len_test_2 = len_test + 1;
+ const uint32_t limit = my_min(buf_avail_full,
+ len_test_2 + nice_len);
+
+ for (; len_test_2 < limit &&
+ buf[len_test_2] == buf_back[len_test_2];
+ ++len_test_2) ;
+
+ len_test_2 -= len_test + 1;
+
+ if (len_test_2 >= 2) {
+ uint32_t pos_state_next;
+ uint32_t cur_and_len_literal_price;
+ uint32_t next_rep_match_price;
+ uint32_t offset;
+
+ lzma_lzma_state state_2 = state;
+ update_match(state_2);
+ pos_state_next = (position + len_test) & coder->pos_mask;
+
+ cur_and_len_literal_price = cur_and_len_price
+ + rc_bit_0_price(
+ coder->is_match[state_2][pos_state_next])
+ + get_literal_price(coder,
+ position + len_test,
+ buf[len_test - 1],
+ true,
+ buf_back[len_test],
+ buf[len_test]);
+
+ update_literal(state_2);
+ pos_state_next = (pos_state_next + 1) & coder->pos_mask;
+
+ next_rep_match_price
+ = cur_and_len_literal_price
+ + rc_bit_1_price(
+ coder->is_match[state_2][pos_state_next])
+ + rc_bit_1_price(coder->is_rep[state_2]);
+
+ // for(; len_test_2 >= 2; --len_test_2) {
+ offset = cur + len_test + 1 + len_test_2;
+
+ while (len_end < offset)
+ coder->opts[++len_end].price = RC_INFINITY_PRICE;
+
+ cur_and_len_price = next_rep_match_price
+ + get_rep_price(coder, 0, len_test_2,
+ state_2, pos_state_next);
+
+ if (cur_and_len_price < coder->opts[offset].price) {
+ coder->opts[offset].price = cur_and_len_price;
+ coder->opts[offset].pos_prev = cur + len_test + 1;
+ coder->opts[offset].back_prev = 0;
+ coder->opts[offset].prev_1_is_literal = true;
+ coder->opts[offset].prev_2 = true;
+ coder->opts[offset].pos_prev_2 = cur;
+ coder->opts[offset].back_prev_2
+ = cur_back + REP_DISTANCES;
+ }
+ //}
+ }
+
+ if (++i == matches_count)
+ break;
+ }
+ }
+ }
+
+ return len_end;
+}
+
+
+extern void
+lzma_lzma_optimum_normal(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
+ uint32_t *LZMA_RESTRICT back_res, uint32_t *LZMA_RESTRICT len_res,
+ uint32_t position)
+{
+ uint32_t reps[REP_DISTANCES];
+ uint32_t len_end;
+ uint32_t cur;
+
+ // If we have symbols pending, return the next pending symbol.
+ if (coder->opts_end_index != coder->opts_current_index) {
+ assert(mf->read_ahead > 0);
+ *len_res = coder->opts[coder->opts_current_index].pos_prev
+ - coder->opts_current_index;
+ *back_res = coder->opts[coder->opts_current_index].back_prev;
+ coder->opts_current_index = coder->opts[
+ coder->opts_current_index].pos_prev;
+ return;
+ }
+
+ // Update the price tables. In LZMA SDK <= 4.60 (and possibly later)
+ // this was done in both initialization function and in the main loop.
+ // In liblzma they were moved into this single place.
+ if (mf->read_ahead == 0) {
+ if (coder->match_price_count >= (1 << 7))
+ fill_distances_prices(coder);
+
+ if (coder->align_price_count >= ALIGN_TABLE_SIZE)
+ fill_align_prices(coder);
+ }
+
+ // TODO: This needs quite a bit of cleaning still. But splitting
+ // the original function into two pieces makes it at least a little
+ // more readable, since those two parts don't share many variables.
+
+ len_end = helper1(coder, mf, back_res, len_res, position);
+ if (len_end == UINT32_MAX)
+ return;
+
+
+ memcpy(reps, coder->reps, sizeof(reps));
+
+ for (cur = 1; cur < len_end; ++cur) {
+ assert(cur < OPTS);
+
+ coder->longest_match_length = mf_find(
+ mf, &coder->matches_count, coder->matches);
+
+ if (coder->longest_match_length >= mf->nice_len)
+ break;
+
+ len_end = helper2(coder, reps, mf_ptr(mf) - 1, len_end,
+ position + cur, cur, mf->nice_len,
+ my_min(mf_avail(mf) + 1, OPTS - 1 - cur));
+ }
+
+ backward(coder, len_res, back_res, cur);
+ return;
+}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_presets.c b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_presets.c
new file mode 100644
index 0000000000..8af9b9fc48
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_presets.c
@@ -0,0 +1,63 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma_encoder_presets.c
+/// \brief Encoder presets
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "common.h"
+
+
+extern LZMA_API(lzma_bool)
+lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
+{
+ static const uint8_t dict_size_values[] = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
+ static const uint8_t depth_values[] = { 4, 8, 24, 48 };
+
+ const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK;
+ const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK;
+ const uint32_t supported_flags = LZMA_PRESET_EXTREME;
+
+ if (level > 9 || (flags & ~supported_flags))
+ return true;
+
+ options->preset_dict = NULL;
+ options->preset_dict_size = 0;
+
+ options->lc = LZMA_LC_DEFAULT;
+ options->lp = LZMA_LP_DEFAULT;
+ options->pb = LZMA_PB_DEFAULT;
+
+ options->dict_size = UINT32_C(1) << dict_size_values[level];
+
+ if (level <= 3) {
+ options->mode = LZMA_MODE_FAST;
+ options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4;
+ options->nice_len = level <= 1 ? 128 : 273;
+ options->depth = depth_values[level];
+ } else {
+ options->mode = LZMA_MODE_NORMAL;
+ options->mf = LZMA_MF_BT4;
+ options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64;
+ options->depth = 0;
+ }
+
+ if (flags & LZMA_PRESET_EXTREME) {
+ options->mode = LZMA_MODE_NORMAL;
+ options->mf = LZMA_MF_BT4;
+ if (level == 3 || level == 5) {
+ options->nice_len = 192;
+ options->depth = 0;
+ } else {
+ options->nice_len = 273;
+ options->depth = 512;
+ }
+ }
+
+ return false;
+}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h
new file mode 100644
index 0000000000..04fb29e90c
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h
@@ -0,0 +1,148 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file lzma_encoder_private.h
+/// \brief Private definitions for LZMA encoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_LZMA_ENCODER_PRIVATE_H
+#define LZMA_LZMA_ENCODER_PRIVATE_H
+
+#include "lz_encoder.h"
+#include "range_encoder.h"
+#include "lzma_common.h"
+#include "lzma_encoder.h"
+
+
+// Macro to compare if the first two bytes in two buffers differ. This is
+// needed in lzma_lzma_optimum_*() to test if the match is at least
+// MATCH_LEN_MIN bytes. Unaligned access gives tiny gain so there's no
+// reason to not use it when it is supported.
+#ifdef TUKLIB_FAST_UNALIGNED_ACCESS
+# define not_equal_16(a, b) \
+ (*(const uint16_t *)(a) != *(const uint16_t *)(b))
+#else
+# define not_equal_16(a, b) \
+ ((a)[0] != (b)[0] || (a)[1] != (b)[1])
+#endif
+
+
+// Optimal - Number of entries in the optimum array.
+#define OPTS (1 << 12)
+
+
+typedef struct {
+ probability choice;
+ probability choice2;
+ probability low[POS_STATES_MAX][LEN_LOW_SYMBOLS];
+ probability mid[POS_STATES_MAX][LEN_MID_SYMBOLS];
+ probability high[LEN_HIGH_SYMBOLS];
+
+ uint32_t prices[POS_STATES_MAX][LEN_SYMBOLS];
+ uint32_t table_size;
+ uint32_t counters[POS_STATES_MAX];
+
+} lzma_length_encoder;
+
+
+typedef struct {
+ lzma_lzma_state state;
+
+ bool prev_1_is_literal;
+ bool prev_2;
+
+ uint32_t pos_prev_2;
+ uint32_t back_prev_2;
+
+ uint32_t price;
+ uint32_t pos_prev; // pos_next;
+ uint32_t back_prev;
+
+ uint32_t backs[REP_DISTANCES];
+
+} lzma_optimal;
+
+
+struct lzma_coder_s {
+ /// Range encoder
+ lzma_range_encoder rc;
+
+ /// State
+ lzma_lzma_state state;
+
+ /// The four most recent match distances
+ uint32_t reps[REP_DISTANCES];
+
+ /// Array of match candidates
+ lzma_match matches[MATCH_LEN_MAX + 1];
+
+ /// Number of match candidates in matches[]
+ uint32_t matches_count;
+
+ /// Variable to hold the length of the longest match between calls
+ /// to lzma_lzma_optimum_*().
+ uint32_t longest_match_length;
+
+ /// True if using getoptimumfast
+ bool fast_mode;
+
+ /// True if the encoder has been initialized by encoding the first
+ /// byte as a literal.
+ bool is_initialized;
+
+ /// True if the range encoder has been flushed, but not all bytes
+ /// have been written to the output buffer yet.
+ bool is_flushed;
+
+ uint32_t pos_mask; ///< (1 << pos_bits) - 1
+ uint32_t literal_context_bits;
+ uint32_t literal_pos_mask;
+
+ // These are the same as in lzma_decoder.c. See comments there.
+ probability literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE];
+ probability is_match[STATES][POS_STATES_MAX];
+ probability is_rep[STATES];
+ probability is_rep0[STATES];
+ probability is_rep1[STATES];
+ probability is_rep2[STATES];
+ probability is_rep0_long[STATES][POS_STATES_MAX];
+ probability pos_slot[LEN_TO_POS_STATES][POS_SLOTS];
+ probability pos_special[FULL_DISTANCES - END_POS_MODEL_INDEX];
+ probability pos_align[ALIGN_TABLE_SIZE];
+
+ // These are the same as in lzma_decoder.c except that the encoders
+ // include also price tables.
+ lzma_length_encoder match_len_encoder;
+ lzma_length_encoder rep_len_encoder;
+
+ // Price tables
+ uint32_t pos_slot_prices[LEN_TO_POS_STATES][POS_SLOTS];
+ uint32_t distances_prices[LEN_TO_POS_STATES][FULL_DISTANCES];
+ uint32_t dist_table_size;
+ uint32_t match_price_count;
+
+ uint32_t align_prices[ALIGN_TABLE_SIZE];
+ uint32_t align_price_count;
+
+ // Optimal
+ uint32_t opts_end_index;
+ uint32_t opts_current_index;
+ lzma_optimal opts[OPTS];
+};
+
+
+extern void lzma_lzma_optimum_fast(
+ lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
+ uint32_t *LZMA_RESTRICT back_res, uint32_t *LZMA_RESTRICT len_res);
+
+extern void lzma_lzma_optimum_normal(lzma_coder *LZMA_RESTRICT coder,
+ lzma_mf *LZMA_RESTRICT mf, uint32_t *LZMA_RESTRICT back_res,
+ uint32_t *LZMA_RESTRICT len_res, uint32_t position);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/rangecoder/price.h b/Utilities/cmliblzma/liblzma/rangecoder/price.h
new file mode 100644
index 0000000000..8ae02ca747
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/rangecoder/price.h
@@ -0,0 +1,92 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file price.h
+/// \brief Probability price calculation
+//
+// Author: Igor Pavlov
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_PRICE_H
+#define LZMA_PRICE_H
+
+
+#define RC_MOVE_REDUCING_BITS 4
+#define RC_BIT_PRICE_SHIFT_BITS 4
+#define RC_PRICE_TABLE_SIZE (RC_BIT_MODEL_TOTAL >> RC_MOVE_REDUCING_BITS)
+
+#define RC_INFINITY_PRICE (UINT32_C(1) << 30)
+
+
+/// Lookup table for the inline functions defined in this file.
+extern const uint8_t lzma_rc_prices[RC_PRICE_TABLE_SIZE];
+
+
+static inline uint32_t
+rc_bit_price(const probability prob, const uint32_t bit)
+{
+ return lzma_rc_prices[(prob ^ ((UINT32_C(0) - bit)
+ & (RC_BIT_MODEL_TOTAL - 1))) >> RC_MOVE_REDUCING_BITS];
+}
+
+
+static inline uint32_t
+rc_bit_0_price(const probability prob)
+{
+ return lzma_rc_prices[prob >> RC_MOVE_REDUCING_BITS];
+}
+
+
+static inline uint32_t
+rc_bit_1_price(const probability prob)
+{
+ return lzma_rc_prices[(prob ^ (RC_BIT_MODEL_TOTAL - 1))
+ >> RC_MOVE_REDUCING_BITS];
+}
+
+
+static inline uint32_t
+rc_bittree_price(const probability *const probs,
+ const uint32_t bit_levels, uint32_t symbol)
+{
+ uint32_t price = 0;
+ symbol += UINT32_C(1) << bit_levels;
+
+ do {
+ const uint32_t bit = symbol & 1;
+ symbol >>= 1;
+ price += rc_bit_price(probs[symbol], bit);
+ } while (symbol != 1);
+
+ return price;
+}
+
+
+static inline uint32_t
+rc_bittree_reverse_price(const probability *const probs,
+ uint32_t bit_levels, uint32_t symbol)
+{
+ uint32_t price = 0;
+ uint32_t model_index = 1;
+
+ do {
+ const uint32_t bit = symbol & 1;
+ symbol >>= 1;
+ price += rc_bit_price(probs[model_index], bit);
+ model_index = (model_index << 1) + bit;
+ } while (--bit_levels != 0);
+
+ return price;
+}
+
+
+static inline uint32_t
+rc_direct_price(const uint32_t bits)
+{
+ return bits << RC_BIT_PRICE_SHIFT_BITS;
+}
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/rangecoder/price_table.c b/Utilities/cmliblzma/liblzma/rangecoder/price_table.c
new file mode 100644
index 0000000000..ac64bf62c7
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/rangecoder/price_table.c
@@ -0,0 +1,22 @@
+/* This file has been automatically generated by price_tablegen.c. */
+
+#include "range_encoder.h"
+
+const uint8_t lzma_rc_prices[RC_PRICE_TABLE_SIZE] = {
+ 128, 103, 91, 84, 78, 73, 69, 66,
+ 63, 61, 58, 56, 54, 52, 51, 49,
+ 48, 46, 45, 44, 43, 42, 41, 40,
+ 39, 38, 37, 36, 35, 34, 34, 33,
+ 32, 31, 31, 30, 29, 29, 28, 28,
+ 27, 26, 26, 25, 25, 24, 24, 23,
+ 23, 22, 22, 22, 21, 21, 20, 20,
+ 19, 19, 19, 18, 18, 17, 17, 17,
+ 16, 16, 16, 15, 15, 15, 14, 14,
+ 14, 13, 13, 13, 12, 12, 12, 11,
+ 11, 11, 11, 10, 10, 10, 10, 9,
+ 9, 9, 9, 8, 8, 8, 8, 7,
+ 7, 7, 7, 6, 6, 6, 6, 5,
+ 5, 5, 5, 5, 4, 4, 4, 4,
+ 3, 3, 3, 3, 3, 2, 2, 2,
+ 2, 2, 2, 1, 1, 1, 1, 1
+};
diff --git a/Utilities/cmliblzma/liblzma/rangecoder/price_tablegen.c b/Utilities/cmliblzma/liblzma/rangecoder/price_tablegen.c
new file mode 100644
index 0000000000..bf08ce39d7
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/rangecoder/price_tablegen.c
@@ -0,0 +1,87 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file price_tablegen.c
+/// \brief Probability price table generator
+///
+/// Compiling: gcc -std=c99 -o price_tablegen price_tablegen.c
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <inttypes.h>
+#include <stdio.h>
+#include "range_common.h"
+#include "price.h"
+
+
+static uint32_t rc_prices[RC_PRICE_TABLE_SIZE];
+
+
+static void
+init_price_table(void)
+{
+ for (uint32_t i = (UINT32_C(1) << RC_MOVE_REDUCING_BITS) / 2;
+ i < RC_BIT_MODEL_TOTAL;
+ i += (UINT32_C(1) << RC_MOVE_REDUCING_BITS)) {
+ const uint32_t cycles_bits = RC_BIT_PRICE_SHIFT_BITS;
+ uint32_t w = i;
+ uint32_t bit_count = 0;
+
+ for (uint32_t j = 0; j < cycles_bits; ++j) {
+ w *= w;
+ bit_count <<= 1;
+
+ while (w >= (UINT32_C(1) << 16)) {
+ w >>= 1;
+ ++bit_count;
+ }
+ }
+
+ rc_prices[i >> RC_MOVE_REDUCING_BITS]
+ = (RC_BIT_MODEL_TOTAL_BITS << cycles_bits)
+ - 15 - bit_count;
+ }
+
+ return;
+}
+
+
+static void
+print_price_table(void)
+{
+ printf("/* This file has been automatically generated by "
+ "price_tablegen.c. */\n\n"
+ "#include \"range_encoder.h\"\n\n"
+ "const uint8_t lzma_rc_prices["
+ "RC_PRICE_TABLE_SIZE] = {");
+
+ const size_t array_size = sizeof(lzma_rc_prices)
+ / sizeof(lzma_rc_prices[0]);
+ for (size_t i = 0; i < array_size; ++i) {
+ if (i % 8 == 0)
+ printf("\n\t");
+
+ printf("%4" PRIu32, rc_prices[i]);
+
+ if (i != array_size - 1)
+ printf(",");
+ }
+
+ printf("\n};\n");
+
+ return;
+}
+
+
+int
+main(void)
+{
+ init_price_table();
+ print_price_table();
+ return 0;
+}
diff --git a/Utilities/cmliblzma/liblzma/rangecoder/range_common.h b/Utilities/cmliblzma/liblzma/rangecoder/range_common.h
new file mode 100644
index 0000000000..f15623ea68
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/rangecoder/range_common.h
@@ -0,0 +1,74 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file range_common.h
+/// \brief Common things for range encoder and decoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_RANGE_COMMON_H
+#define LZMA_RANGE_COMMON_H
+
+#include "common.h"
+
+
+///////////////
+// Constants //
+///////////////
+
+#define RC_SHIFT_BITS 8
+#define RC_TOP_BITS 24
+#define RC_TOP_VALUE (UINT32_C(1) << RC_TOP_BITS)
+#define RC_BIT_MODEL_TOTAL_BITS 11
+#define RC_BIT_MODEL_TOTAL (UINT32_C(1) << RC_BIT_MODEL_TOTAL_BITS)
+#define RC_MOVE_BITS 5
+
+
+////////////
+// Macros //
+////////////
+
+// Resets the probability so that both 0 and 1 have probability of 50 %
+#define bit_reset(prob) \
+ prob = RC_BIT_MODEL_TOTAL >> 1
+
+// This does the same for a complete bit tree.
+// (A tree represented as an array.)
+#define bittree_reset(probs, bit_levels) \
+ do { \
+ uint32_t bt_i; \
+ for (bt_i = 0; bt_i < (1 << (bit_levels)); ++bt_i) \
+ bit_reset((probs)[bt_i]); \
+ } while (0)
+
+
+//////////////////////
+// Type definitions //
+//////////////////////
+
+/// \brief Type of probabilities used with range coder
+///
+/// This needs to be at least 12-bit integer, so uint16_t is a logical choice.
+/// However, on some architecture and compiler combinations, a bigger type
+/// may give better speed, because the probability variables are accessed
+/// a lot. On the other hand, bigger probability type increases cache
+/// footprint, since there are 2 to 14 thousand probability variables in
+/// LZMA (assuming the limit of lc + lp <= 4; with lc + lp <= 12 there
+/// would be about 1.5 million variables).
+///
+/// With malicious files, the initialization speed of the LZMA decoder can
+/// become important. In that case, smaller probability variables mean that
+/// there is less bytes to write to RAM, which makes initialization faster.
+/// With big probability type, the initialization can become so slow that it
+/// can be a problem e.g. for email servers doing virus scanning.
+///
+/// I will be sticking to uint16_t unless some specific architectures
+/// are *much* faster (20-50 %) with uint32_t.
+typedef uint16_t probability;
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/rangecoder/range_decoder.h b/Utilities/cmliblzma/liblzma/rangecoder/range_decoder.h
new file mode 100644
index 0000000000..199e7b5a6d
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/rangecoder/range_decoder.h
@@ -0,0 +1,179 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file range_decoder.h
+/// \brief Range Decoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_RANGE_DECODER_H
+#define LZMA_RANGE_DECODER_H
+
+#include "range_common.h"
+
+
+typedef struct {
+ uint32_t range;
+ uint32_t code;
+ uint32_t init_bytes_left;
+} lzma_range_decoder;
+
+
+/// Reads the first five bytes to initialize the range decoder.
+static inline bool
+rc_read_init(lzma_range_decoder *rc, const uint8_t *LZMA_RESTRICT in,
+ size_t *LZMA_RESTRICT in_pos, size_t in_size)
+{
+ while (rc->init_bytes_left > 0) {
+ if (*in_pos == in_size)
+ return false;
+
+ rc->code = (rc->code << 8) | in[*in_pos];
+ ++*in_pos;
+ --rc->init_bytes_left;
+ }
+
+ return true;
+}
+
+
+/// Makes local copies of range decoder and *in_pos variables. Doing this
+/// improves speed significantly. The range decoder macros expect also
+/// variables `in' and `in_size' to be defined.
+#define rc_to_local(range_decoder, in_pos) \
+ lzma_range_decoder rc = range_decoder; \
+ size_t rc_in_pos = (in_pos); \
+ uint32_t rc_bound
+
+
+/// Stores the local copes back to the range decoder structure.
+#define rc_from_local(range_decoder, in_pos) \
+do { \
+ range_decoder = rc; \
+ in_pos = rc_in_pos; \
+} while (0)
+
+
+/// Resets the range decoder structure.
+#define rc_reset(range_decoder) \
+do { \
+ (range_decoder).range = UINT32_MAX; \
+ (range_decoder).code = 0; \
+ (range_decoder).init_bytes_left = 5; \
+} while (0)
+
+
+/// When decoding has been properly finished, rc.code is always zero unless
+/// the input stream is corrupt. So checking this can catch some corrupt
+/// files especially if they don't have any other integrity check.
+#define rc_is_finished(range_decoder) \
+ ((range_decoder).code == 0)
+
+
+/// Read the next input byte if needed. If more input is needed but there is
+/// no more input available, "goto out" is used to jump out of the main
+/// decoder loop.
+#define rc_normalize(seq) \
+do { \
+ if (rc.range < RC_TOP_VALUE) { \
+ if (unlikely(rc_in_pos == in_size)) { \
+ coder->sequence = seq; \
+ goto out; \
+ } \
+ rc.range <<= RC_SHIFT_BITS; \
+ rc.code = (rc.code << RC_SHIFT_BITS) | in[rc_in_pos++]; \
+ } \
+} while (0)
+
+
+/// Start decoding a bit. This must be used together with rc_update_0()
+/// and rc_update_1():
+///
+/// rc_if_0(prob, seq) {
+/// rc_update_0(prob);
+/// // Do something
+/// } else {
+/// rc_update_1(prob);
+/// // Do something else
+/// }
+///
+#define rc_if_0(prob, seq) \
+ rc_normalize(seq); \
+ rc_bound = (rc.range >> RC_BIT_MODEL_TOTAL_BITS) * (prob); \
+ if (rc.code < rc_bound)
+
+
+/// Update the range decoder state and the used probability variable to
+/// match a decoded bit of 0.
+#define rc_update_0(prob) \
+do { \
+ rc.range = rc_bound; \
+ prob += (RC_BIT_MODEL_TOTAL - (prob)) >> RC_MOVE_BITS; \
+} while (0)
+
+
+/// Update the range decoder state and the used probability variable to
+/// match a decoded bit of 1.
+#define rc_update_1(prob) \
+do { \
+ rc.range -= rc_bound; \
+ rc.code -= rc_bound; \
+ prob -= (prob) >> RC_MOVE_BITS; \
+} while (0)
+
+
+/// Decodes one bit and runs action0 or action1 depending on the decoded bit.
+/// This macro is used as the last step in bittree reverse decoders since
+/// those don't use "symbol" for anything else than indexing the probability
+/// arrays.
+#define rc_bit_last(prob, action0, action1, seq) \
+do { \
+ rc_if_0(prob, seq) { \
+ rc_update_0(prob); \
+ action0; \
+ } else { \
+ rc_update_1(prob); \
+ action1; \
+ } \
+} while (0)
+
+
+/// Decodes one bit, updates "symbol", and runs action0 or action1 depending
+/// on the decoded bit.
+#define rc_bit(prob, action0, action1, seq) \
+ rc_bit_last(prob, \
+ symbol <<= 1; action0, \
+ symbol = (symbol << 1) + 1; action1, \
+ seq);
+
+
+/// Like rc_bit() but add "case seq:" as a prefix. This makes the unrolled
+/// loops more readable because the code isn't littered with "case"
+/// statements. On the other hand this also makes it less readable, since
+/// spotting the places where the decoder loop may be restarted is less
+/// obvious.
+#define rc_bit_case(prob, action0, action1, seq) \
+ case seq: rc_bit(prob, action0, action1, seq)
+
+
+/// Decode a bit without using a probability.
+#define rc_direct(dest, seq) \
+do { \
+ rc_normalize(seq); \
+ rc.range >>= 1; \
+ rc.code -= rc.range; \
+ rc_bound = UINT32_C(0) - (rc.code >> 31); \
+ rc.code += rc.range & rc_bound; \
+ dest = (dest << 1) + (rc_bound + 1); \
+} while (0)
+
+
+// NOTE: No macros are provided for bittree decoding. It seems to be simpler
+// to just write them open in the code.
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/rangecoder/range_encoder.h b/Utilities/cmliblzma/liblzma/rangecoder/range_encoder.h
new file mode 100644
index 0000000000..e9614f252b
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/rangecoder/range_encoder.h
@@ -0,0 +1,232 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file range_encoder.h
+/// \brief Range Encoder
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_RANGE_ENCODER_H
+#define LZMA_RANGE_ENCODER_H
+
+#include "range_common.h"
+#include "price.h"
+
+
+/// Maximum number of symbols that can be put pending into lzma_range_encoder
+/// structure between calls to lzma_rc_encode(). For LZMA, 52+5 is enough
+/// (match with big distance and length followed by range encoder flush).
+#define RC_SYMBOLS_MAX 58
+
+
+typedef struct {
+ uint64_t low;
+ uint64_t cache_size;
+ uint32_t range;
+ uint8_t cache;
+
+ /// Number of symbols in the tables
+ size_t count;
+
+ /// rc_encode()'s position in the tables
+ size_t pos;
+
+ /// Symbols to encode
+ enum {
+ RC_BIT_0,
+ RC_BIT_1,
+ RC_DIRECT_0,
+ RC_DIRECT_1,
+ RC_FLUSH,
+ } symbols[RC_SYMBOLS_MAX];
+
+ /// Probabilities associated with RC_BIT_0 or RC_BIT_1
+ probability *probs[RC_SYMBOLS_MAX];
+
+} lzma_range_encoder;
+
+
+static inline void
+rc_reset(lzma_range_encoder *rc)
+{
+ rc->low = 0;
+ rc->cache_size = 1;
+ rc->range = UINT32_MAX;
+ rc->cache = 0;
+ rc->count = 0;
+ rc->pos = 0;
+}
+
+
+static inline void
+rc_bit(lzma_range_encoder *rc, probability *prob, uint32_t bit)
+{
+ rc->symbols[rc->count] = bit;
+ rc->probs[rc->count] = prob;
+ ++rc->count;
+}
+
+
+static inline void
+rc_bittree(lzma_range_encoder *rc, probability *probs,
+ uint32_t bit_count, uint32_t symbol)
+{
+ uint32_t model_index = 1;
+
+ do {
+ const uint32_t bit = (symbol >> --bit_count) & 1;
+ rc_bit(rc, &probs[model_index], bit);
+ model_index = (model_index << 1) + bit;
+ } while (bit_count != 0);
+}
+
+
+static inline void
+rc_bittree_reverse(lzma_range_encoder *rc, probability *probs,
+ uint32_t bit_count, uint32_t symbol)
+{
+ uint32_t model_index = 1;
+
+ do {
+ const uint32_t bit = symbol & 1;
+ symbol >>= 1;
+ rc_bit(rc, &probs[model_index], bit);
+ model_index = (model_index << 1) + bit;
+ } while (--bit_count != 0);
+}
+
+
+static inline void
+rc_direct(lzma_range_encoder *rc,
+ uint32_t value, uint32_t bit_count)
+{
+ do {
+ rc->symbols[rc->count++]
+ = RC_DIRECT_0 + ((value >> --bit_count) & 1);
+ } while (bit_count != 0);
+}
+
+
+static inline void
+rc_flush(lzma_range_encoder *rc)
+{
+ size_t i;
+ for (i = 0; i < 5; ++i)
+ rc->symbols[rc->count++] = RC_FLUSH;
+}
+
+
+static inline bool
+rc_shift_low(lzma_range_encoder *rc,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ if ((uint32_t)(rc->low) < (uint32_t)(0xFF000000)
+ || (uint32_t)(rc->low >> 32) != 0) {
+ do {
+ if (*out_pos == out_size)
+ return true;
+
+ out[*out_pos] = rc->cache + (uint8_t)(rc->low >> 32);
+ ++*out_pos;
+ rc->cache = 0xFF;
+
+ } while (--rc->cache_size != 0);
+
+ rc->cache = (rc->low >> 24) & 0xFF;
+ }
+
+ ++rc->cache_size;
+ rc->low = (rc->low & 0x00FFFFFF) << RC_SHIFT_BITS;
+
+ return false;
+}
+
+
+static inline bool
+rc_encode(lzma_range_encoder *rc,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ assert(rc->count <= RC_SYMBOLS_MAX);
+
+ while (rc->pos < rc->count) {
+ // Normalize
+ if (rc->range < RC_TOP_VALUE) {
+ if (rc_shift_low(rc, out, out_pos, out_size))
+ return true;
+
+ rc->range <<= RC_SHIFT_BITS;
+ }
+
+ // Encode a bit
+ switch (rc->symbols[rc->pos]) {
+ case RC_BIT_0: {
+ probability prob = *rc->probs[rc->pos];
+ rc->range = (rc->range >> RC_BIT_MODEL_TOTAL_BITS)
+ * prob;
+ prob += (RC_BIT_MODEL_TOTAL - prob) >> RC_MOVE_BITS;
+ *rc->probs[rc->pos] = prob;
+ break;
+ }
+
+ case RC_BIT_1: {
+ probability prob = *rc->probs[rc->pos];
+ const uint32_t bound = prob * (rc->range
+ >> RC_BIT_MODEL_TOTAL_BITS);
+ rc->low += bound;
+ rc->range -= bound;
+ prob -= prob >> RC_MOVE_BITS;
+ *rc->probs[rc->pos] = prob;
+ break;
+ }
+
+ case RC_DIRECT_0:
+ rc->range >>= 1;
+ break;
+
+ case RC_DIRECT_1:
+ rc->range >>= 1;
+ rc->low += rc->range;
+ break;
+
+ case RC_FLUSH:
+ // Prevent further normalizations.
+ rc->range = UINT32_MAX;
+
+ // Flush the last five bytes (see rc_flush()).
+ do {
+ if (rc_shift_low(rc, out, out_pos, out_size))
+ return true;
+ } while (++rc->pos < rc->count);
+
+ // Reset the range encoder so we are ready to continue
+ // encoding if we weren't finishing the stream.
+ rc_reset(rc);
+ return false;
+
+ default:
+ assert(0);
+ break;
+ }
+
+ ++rc->pos;
+ }
+
+ rc->count = 0;
+ rc->pos = 0;
+
+ return false;
+}
+
+
+static inline uint64_t
+rc_pending(const lzma_range_encoder *rc)
+{
+ return rc->cache_size + 5 - 1;
+}
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/simple/arm.c b/Utilities/cmliblzma/liblzma/simple/arm.c
new file mode 100644
index 0000000000..8dcba39fdf
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/arm.c
@@ -0,0 +1,69 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file arm.c
+/// \brief Filter for ARM binaries
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_private.h"
+
+
+static size_t
+arm_code(lzma_simple *simple lzma_attribute((__unused__)),
+ uint32_t now_pos, bool is_encoder,
+ uint8_t *buffer, size_t size)
+{
+ size_t i;
+ for (i = 0; i + 4 <= size; i += 4) {
+ if (buffer[i + 3] == 0xEB) {
+ uint32_t dest;
+ uint32_t src = (buffer[i + 2] << 16)
+ | (buffer[i + 1] << 8)
+ | (buffer[i + 0]);
+ src <<= 2;
+
+ if (is_encoder)
+ dest = now_pos + (uint32_t)(i) + 8 + src;
+ else
+ dest = src - (now_pos + (uint32_t)(i) + 8);
+
+ dest >>= 2;
+ buffer[i + 2] = (dest >> 16);
+ buffer[i + 1] = (dest >> 8);
+ buffer[i + 0] = dest;
+ }
+ }
+
+ return i;
+}
+
+
+static lzma_ret
+arm_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters, bool is_encoder)
+{
+ return lzma_simple_coder_init(next, allocator, filters,
+ &arm_code, 0, 4, 4, is_encoder);
+}
+
+
+extern lzma_ret
+lzma_simple_arm_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ return arm_coder_init(next, allocator, filters, true);
+}
+
+
+extern lzma_ret
+lzma_simple_arm_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ return arm_coder_init(next, allocator, filters, false);
+}
diff --git a/Utilities/cmliblzma/liblzma/simple/armthumb.c b/Utilities/cmliblzma/liblzma/simple/armthumb.c
new file mode 100644
index 0000000000..4b890a3954
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/armthumb.c
@@ -0,0 +1,74 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file armthumb.c
+/// \brief Filter for ARM-Thumb binaries
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_private.h"
+
+
+static size_t
+armthumb_code(lzma_simple *simple lzma_attribute((__unused__)),
+ uint32_t now_pos, bool is_encoder,
+ uint8_t *buffer, size_t size)
+{
+ size_t i;
+ for (i = 0; i + 4 <= size; i += 2) {
+ if ((buffer[i + 1] & 0xF8) == 0xF0
+ && (buffer[i + 3] & 0xF8) == 0xF8) {
+ uint32_t dest;
+ uint32_t src = ((buffer[i + 1] & 0x7) << 19)
+ | (buffer[i + 0] << 11)
+ | ((buffer[i + 3] & 0x7) << 8)
+ | (buffer[i + 2]);
+
+ src <<= 1;
+
+ if (is_encoder)
+ dest = now_pos + (uint32_t)(i) + 4 + src;
+ else
+ dest = src - (now_pos + (uint32_t)(i) + 4);
+
+ dest >>= 1;
+ buffer[i + 1] = 0xF0 | ((dest >> 19) & 0x7);
+ buffer[i + 0] = (dest >> 11);
+ buffer[i + 3] = 0xF8 | ((dest >> 8) & 0x7);
+ buffer[i + 2] = (dest);
+ i += 2;
+ }
+ }
+
+ return i;
+}
+
+
+static lzma_ret
+armthumb_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters, bool is_encoder)
+{
+ return lzma_simple_coder_init(next, allocator, filters,
+ &armthumb_code, 0, 4, 2, is_encoder);
+}
+
+
+extern lzma_ret
+lzma_simple_armthumb_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters)
+{
+ return armthumb_coder_init(next, allocator, filters, true);
+}
+
+
+extern lzma_ret
+lzma_simple_armthumb_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters)
+{
+ return armthumb_coder_init(next, allocator, filters, false);
+}
diff --git a/Utilities/cmliblzma/liblzma/simple/ia64.c b/Utilities/cmliblzma/liblzma/simple/ia64.c
new file mode 100644
index 0000000000..c537caca1e
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/ia64.c
@@ -0,0 +1,116 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file ia64.c
+/// \brief Filter for IA64 (Itanium) binaries
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_private.h"
+
+
+static size_t
+ia64_code(lzma_simple *simple lzma_attribute((__unused__)),
+ uint32_t now_pos, bool is_encoder,
+ uint8_t *buffer, size_t size)
+{
+ static const uint32_t BRANCH_TABLE[32] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 4, 4, 6, 6, 0, 0, 7, 7,
+ 4, 4, 0, 0, 4, 4, 0, 0
+ };
+
+ size_t i;
+ for (i = 0; i + 16 <= size; i += 16) {
+ size_t slot;
+
+ const uint32_t instr_template = buffer[i] & 0x1F;
+ const uint32_t mask = BRANCH_TABLE[instr_template];
+ uint32_t bit_pos = 5;
+
+ for (slot = 0; slot < 3; ++slot, bit_pos += 41) {
+ const size_t byte_pos = (bit_pos >> 3);
+ const uint32_t bit_res = bit_pos & 0x7;
+ uint64_t instruction = 0;
+ uint64_t inst_norm;
+ size_t j;
+
+ if (((mask >> slot) & 1) == 0)
+ continue;
+
+ for (j = 0; j < 6; ++j)
+ instruction += (uint64_t)(
+ buffer[i + j + byte_pos])
+ << (8 * j);
+
+ inst_norm = instruction >> bit_res;
+
+ if (((inst_norm >> 37) & 0xF) == 0x5
+ && ((inst_norm >> 9) & 0x7) == 0
+ /* && (inst_norm & 0x3F)== 0 */
+ ) {
+ uint32_t dest;
+ size_t j;
+
+ uint32_t src = (uint32_t)(
+ (inst_norm >> 13) & 0xFFFFF);
+ src |= ((inst_norm >> 36) & 1) << 20;
+
+ src <<= 4;
+
+ if (is_encoder)
+ dest = now_pos + (uint32_t)(i) + src;
+ else
+ dest = src - (now_pos + (uint32_t)(i));
+
+ dest >>= 4;
+
+ inst_norm &= ~((uint64_t)(0x8FFFFF) << 13);
+ inst_norm |= (uint64_t)(dest & 0xFFFFF) << 13;
+ inst_norm |= (uint64_t)(dest & 0x100000)
+ << (36 - 20);
+
+ instruction &= (1 << bit_res) - 1;
+ instruction |= (inst_norm << bit_res);
+
+ for (j = 0; j < 6; j++)
+ buffer[i + j + byte_pos] = (uint8_t)(
+ instruction
+ >> (8 * j));
+ }
+ }
+ }
+
+ return i;
+}
+
+
+static lzma_ret
+ia64_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters, bool is_encoder)
+{
+ return lzma_simple_coder_init(next, allocator, filters,
+ &ia64_code, 0, 16, 16, is_encoder);
+}
+
+
+extern lzma_ret
+lzma_simple_ia64_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters)
+{
+ return ia64_coder_init(next, allocator, filters, true);
+}
+
+
+extern lzma_ret
+lzma_simple_ia64_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters)
+{
+ return ia64_coder_init(next, allocator, filters, false);
+}
diff --git a/Utilities/cmliblzma/liblzma/simple/powerpc.c b/Utilities/cmliblzma/liblzma/simple/powerpc.c
new file mode 100644
index 0000000000..6f8351176c
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/powerpc.c
@@ -0,0 +1,73 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file powerpc.c
+/// \brief Filter for PowerPC (big endian) binaries
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_private.h"
+
+
+static size_t
+powerpc_code(lzma_simple *simple lzma_attribute((__unused__)),
+ uint32_t now_pos, bool is_encoder,
+ uint8_t *buffer, size_t size)
+{
+ size_t i;
+ for (i = 0; i + 4 <= size; i += 4) {
+ // PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link)
+ if ((buffer[i] >> 2) == 0x12
+ && ((buffer[i + 3] & 3) == 1)) {
+
+ const uint32_t src = ((buffer[i + 0] & 3) << 24)
+ | (buffer[i + 1] << 16)
+ | (buffer[i + 2] << 8)
+ | (buffer[i + 3] & (~3));
+
+ uint32_t dest;
+ if (is_encoder)
+ dest = now_pos + (uint32_t)(i) + src;
+ else
+ dest = src - (now_pos + (uint32_t)(i));
+
+ buffer[i + 0] = 0x48 | ((dest >> 24) & 0x03);
+ buffer[i + 1] = (dest >> 16);
+ buffer[i + 2] = (dest >> 8);
+ buffer[i + 3] &= 0x03;
+ buffer[i + 3] |= dest;
+ }
+ }
+
+ return i;
+}
+
+
+static lzma_ret
+powerpc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters, bool is_encoder)
+{
+ return lzma_simple_coder_init(next, allocator, filters,
+ &powerpc_code, 0, 4, 4, is_encoder);
+}
+
+
+extern lzma_ret
+lzma_simple_powerpc_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters)
+{
+ return powerpc_coder_init(next, allocator, filters, true);
+}
+
+
+extern lzma_ret
+lzma_simple_powerpc_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters)
+{
+ return powerpc_coder_init(next, allocator, filters, false);
+}
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_coder.c b/Utilities/cmliblzma/liblzma/simple/simple_coder.c
new file mode 100644
index 0000000000..f3bbdd7a7c
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/simple_coder.c
@@ -0,0 +1,283 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file simple_coder.c
+/// \brief Wrapper for simple filters
+///
+/// Simple filters don't change the size of the data i.e. number of bytes
+/// in equals the number of bytes out.
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_private.h"
+
+
+/// Copied or encodes/decodes more data to out[].
+static lzma_ret
+copy_or_code(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
+{
+ assert(!coder->end_was_reached);
+
+ if (coder->next.code == NULL) {
+ lzma_bufcpy(in, in_pos, in_size, out, out_pos, out_size);
+
+ // Check if end of stream was reached.
+ if (coder->is_encoder && action == LZMA_FINISH
+ && *in_pos == in_size)
+ coder->end_was_reached = true;
+
+ } else {
+ // Call the next coder in the chain to provide us some data.
+ const lzma_ret ret = coder->next.code(
+ coder->next.coder, allocator,
+ in, in_pos, in_size,
+ out, out_pos, out_size, action);
+
+ if (ret == LZMA_STREAM_END) {
+ assert(!coder->is_encoder
+ || action == LZMA_FINISH);
+ coder->end_was_reached = true;
+
+ } else if (ret != LZMA_OK) {
+ return ret;
+ }
+ }
+
+ return LZMA_OK;
+}
+
+
+static size_t
+call_filter(lzma_coder *coder, uint8_t *buffer, size_t size)
+{
+ const size_t filtered = coder->filter(coder->simple,
+ coder->now_pos, coder->is_encoder,
+ buffer, size);
+ coder->now_pos += filtered;
+ return filtered;
+}
+
+
+static lzma_ret
+simple_code(lzma_coder *coder, lzma_allocator *allocator,
+ const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+ size_t in_size, uint8_t *LZMA_RESTRICT out,
+ size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
+{
+ size_t out_avail;
+ size_t buf_avail;
+
+ // TODO: Add partial support for LZMA_SYNC_FLUSH. We can support it
+ // in cases when the filter is able to filter everything. With most
+ // simple filters it can be done at offset that is a multiple of 2,
+ // 4, or 16. With x86 filter, it needs good luck, and thus cannot
+ // be made to work predictably.
+ if (action == LZMA_SYNC_FLUSH)
+ return LZMA_OPTIONS_ERROR;
+
+ // Flush already filtered data from coder->buffer[] to out[].
+ if (coder->pos < coder->filtered) {
+ lzma_bufcpy(coder->buffer, &coder->pos, coder->filtered,
+ out, out_pos, out_size);
+
+ // If we couldn't flush all the filtered data, return to
+ // application immediately.
+ if (coder->pos < coder->filtered)
+ return LZMA_OK;
+
+ if (coder->end_was_reached) {
+ assert(coder->filtered == coder->size);
+ return LZMA_STREAM_END;
+ }
+ }
+
+ // If we get here, there is no filtered data left in the buffer.
+ coder->filtered = 0;
+
+ assert(!coder->end_was_reached);
+
+ // If there is more output space left than there is unfiltered data
+ // in coder->buffer[], flush coder->buffer[] to out[], and copy/code
+ // more data to out[] hopefully filling it completely. Then filter
+ // the data in out[]. This step is where most of the data gets
+ // filtered if the buffer sizes used by the application are reasonable.
+ out_avail = out_size - *out_pos;
+ buf_avail = coder->size - coder->pos;
+ if (out_avail > buf_avail || buf_avail == 0) {
+ size_t size;
+ size_t filtered;
+ size_t unfiltered;
+
+ // Store the old position so that we know from which byte
+ // to start filtering.
+ const size_t out_start = *out_pos;
+
+ // Flush data from coder->buffer[] to out[], but don't reset
+ // coder->pos and coder->size yet. This way the coder can be
+ // restarted if the next filter in the chain returns e.g.
+ // LZMA_MEM_ERROR.
+ memcpy(out + *out_pos, coder->buffer + coder->pos, buf_avail);
+ *out_pos += buf_avail;
+
+ // Copy/Encode/Decode more data to out[].
+ {
+ const lzma_ret ret = copy_or_code(coder, allocator,
+ in, in_pos, in_size,
+ out, out_pos, out_size, action);
+ assert(ret != LZMA_STREAM_END);
+ if (ret != LZMA_OK)
+ return ret;
+ }
+
+ // Filter out[].
+ size = *out_pos - out_start;
+ filtered = call_filter(coder, out + out_start, size);
+
+ unfiltered = size - filtered;
+ assert(unfiltered <= coder->allocated / 2);
+
+ // Now we can update coder->pos and coder->size, because
+ // the next coder in the chain (if any) was successful.
+ coder->pos = 0;
+ coder->size = unfiltered;
+
+ if (coder->end_was_reached) {
+ // The last byte has been copied to out[] already.
+ // They are left as is.
+ coder->size = 0;
+
+ } else if (unfiltered > 0) {
+ // There is unfiltered data left in out[]. Copy it to
+ // coder->buffer[] and rewind *out_pos appropriately.
+ *out_pos -= unfiltered;
+ memcpy(coder->buffer, out + *out_pos, unfiltered);
+ }
+ } else if (coder->pos > 0) {
+ memmove(coder->buffer, coder->buffer + coder->pos, buf_avail);
+ coder->size -= coder->pos;
+ coder->pos = 0;
+ }
+
+ assert(coder->pos == 0);
+
+ // If coder->buffer[] isn't empty, try to fill it by copying/decoding
+ // more data. Then filter coder->buffer[] and copy the successfully
+ // filtered data to out[]. It is probable, that some filtered and
+ // unfiltered data will be left to coder->buffer[].
+ if (coder->size > 0) {
+ {
+ const lzma_ret ret = copy_or_code(coder, allocator,
+ in, in_pos, in_size,
+ coder->buffer, &coder->size,
+ coder->allocated, action);
+ assert(ret != LZMA_STREAM_END);
+ if (ret != LZMA_OK)
+ return ret;
+ }
+
+ coder->filtered = call_filter(
+ coder, coder->buffer, coder->size);
+
+ // Everything is considered to be filtered if coder->buffer[]
+ // contains the last bytes of the data.
+ if (coder->end_was_reached)
+ coder->filtered = coder->size;
+
+ // Flush as much as possible.
+ lzma_bufcpy(coder->buffer, &coder->pos, coder->filtered,
+ out, out_pos, out_size);
+ }
+
+ // Check if we got everything done.
+ if (coder->end_was_reached && coder->pos == coder->size)
+ return LZMA_STREAM_END;
+
+ return LZMA_OK;
+}
+
+
+static void
+simple_coder_end(lzma_coder *coder, lzma_allocator *allocator)
+{
+ lzma_next_end(&coder->next, allocator);
+ lzma_free(coder->simple, allocator);
+ lzma_free(coder, allocator);
+ return;
+}
+
+
+static lzma_ret
+simple_coder_update(lzma_coder *coder, lzma_allocator *allocator,
+ const lzma_filter *filters_null lzma_attribute((__unused__)),
+ const lzma_filter *reversed_filters)
+{
+ // No update support, just call the next filter in the chain.
+ return lzma_next_filter_update(
+ &coder->next, allocator, reversed_filters + 1);
+}
+
+
+extern lzma_ret
+lzma_simple_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters,
+ size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
+ bool is_encoder, uint8_t *buffer, size_t size),
+ size_t simple_size, size_t unfiltered_max,
+ uint32_t alignment, bool is_encoder)
+{
+ // Allocate memory for the lzma_coder structure if needed.
+ if (next->coder == NULL) {
+ // Here we allocate space also for the temporary buffer. We
+ // need twice the size of unfiltered_max, because then it
+ // is always possible to filter at least unfiltered_max bytes
+ // more data in coder->buffer[] if it can be filled completely.
+ next->coder = lzma_alloc(sizeof(lzma_coder)
+ + 2 * unfiltered_max, allocator);
+ if (next->coder == NULL)
+ return LZMA_MEM_ERROR;
+
+ next->code = &simple_code;
+ next->end = &simple_coder_end;
+ next->update = &simple_coder_update;
+
+ next->coder->next = LZMA_NEXT_CODER_INIT;
+ next->coder->filter = filter;
+ next->coder->allocated = 2 * unfiltered_max;
+
+ // Allocate memory for filter-specific data structure.
+ if (simple_size > 0) {
+ next->coder->simple = lzma_alloc(
+ simple_size, allocator);
+ if (next->coder->simple == NULL)
+ return LZMA_MEM_ERROR;
+ } else {
+ next->coder->simple = NULL;
+ }
+ }
+
+ if (filters[0].options != NULL) {
+ const lzma_options_bcj *simple = filters[0].options;
+ next->coder->now_pos = simple->start_offset;
+ if (next->coder->now_pos & (alignment - 1))
+ return LZMA_OPTIONS_ERROR;
+ } else {
+ next->coder->now_pos = 0;
+ }
+
+ // Reset variables.
+ next->coder->is_encoder = is_encoder;
+ next->coder->end_was_reached = false;
+ next->coder->pos = 0;
+ next->coder->filtered = 0;
+ next->coder->size = 0;
+
+ return lzma_next_filter_init(
+ &next->coder->next, allocator, filters + 1);
+}
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_coder.h b/Utilities/cmliblzma/liblzma/simple/simple_coder.h
new file mode 100644
index 0000000000..0952fad33b
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/simple_coder.h
@@ -0,0 +1,60 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file simple_coder.h
+/// \brief Wrapper for simple filters
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_SIMPLE_CODER_H
+#define LZMA_SIMPLE_CODER_H
+
+#include "common.h"
+
+
+extern lzma_ret lzma_simple_x86_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern lzma_ret lzma_simple_x86_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+
+extern lzma_ret lzma_simple_powerpc_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern lzma_ret lzma_simple_powerpc_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+
+extern lzma_ret lzma_simple_ia64_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern lzma_ret lzma_simple_ia64_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+
+extern lzma_ret lzma_simple_arm_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern lzma_ret lzma_simple_arm_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+
+extern lzma_ret lzma_simple_armthumb_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern lzma_ret lzma_simple_armthumb_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+
+extern lzma_ret lzma_simple_sparc_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+extern lzma_ret lzma_simple_sparc_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_decoder.c b/Utilities/cmliblzma/liblzma/simple/simple_decoder.c
new file mode 100644
index 0000000000..034e158ffa
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/simple_decoder.c
@@ -0,0 +1,41 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file simple_decoder.c
+/// \brief Properties decoder for simple filters
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_decoder.h"
+
+
+extern lzma_ret
+lzma_simple_props_decode(void **options, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size)
+{
+ lzma_options_bcj *opt;
+
+ if (props_size == 0)
+ return LZMA_OK;
+
+ if (props_size != 4)
+ return LZMA_OPTIONS_ERROR;
+
+ opt = lzma_alloc(sizeof(lzma_options_bcj), allocator);
+ if (opt == NULL)
+ return LZMA_MEM_ERROR;
+
+ opt->start_offset = unaligned_read32le(props);
+
+ // Don't leave an options structure allocated if start_offset is zero.
+ if (opt->start_offset == 0)
+ lzma_free(opt, allocator);
+ else
+ *options = opt;
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_decoder.h b/Utilities/cmliblzma/liblzma/simple/simple_decoder.h
new file mode 100644
index 0000000000..b8bf590f76
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/simple_decoder.h
@@ -0,0 +1,22 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file simple_decoder.h
+/// \brief Properties decoder for simple filters
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_SIMPLE_DECODER_H
+#define LZMA_SIMPLE_DECODER_H
+
+#include "simple_coder.h"
+
+extern lzma_ret lzma_simple_props_decode(
+ void **options, lzma_allocator *allocator,
+ const uint8_t *props, size_t props_size);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_encoder.c b/Utilities/cmliblzma/liblzma/simple/simple_encoder.c
new file mode 100644
index 0000000000..8aa463bed2
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/simple_encoder.c
@@ -0,0 +1,38 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file simple_encoder.c
+/// \brief Properties encoder for simple filters
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_encoder.h"
+
+
+extern lzma_ret
+lzma_simple_props_size(uint32_t *size, const void *options)
+{
+ const lzma_options_bcj *const opt = options;
+ *size = (opt == NULL || opt->start_offset == 0) ? 0 : 4;
+ return LZMA_OK;
+}
+
+
+extern lzma_ret
+lzma_simple_props_encode(const void *options, uint8_t *out)
+{
+ const lzma_options_bcj *const opt = options;
+
+ // The default start offset is zero, so we don't need to store any
+ // options unless the start offset is non-zero.
+ if (opt == NULL || opt->start_offset == 0)
+ return LZMA_OK;
+
+ unaligned_write32le(out, opt->start_offset);
+
+ return LZMA_OK;
+}
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_encoder.h b/Utilities/cmliblzma/liblzma/simple/simple_encoder.h
new file mode 100644
index 0000000000..1cee4823a4
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/simple_encoder.h
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file simple_encoder.c
+/// \brief Properties encoder for simple filters
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_SIMPLE_ENCODER_H
+#define LZMA_SIMPLE_ENCODER_H
+
+#include "simple_coder.h"
+
+
+extern lzma_ret lzma_simple_props_size(uint32_t *size, const void *options);
+
+extern lzma_ret lzma_simple_props_encode(const void *options, uint8_t *out);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_private.h b/Utilities/cmliblzma/liblzma/simple/simple_private.h
new file mode 100644
index 0000000000..fcf9f7c198
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/simple_private.h
@@ -0,0 +1,75 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file simple_private.h
+/// \brief Private definitions for so called simple filters
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LZMA_SIMPLE_PRIVATE_H
+#define LZMA_SIMPLE_PRIVATE_H
+
+#include "simple_coder.h"
+
+
+typedef struct lzma_simple_s lzma_simple;
+
+struct lzma_coder_s {
+ /// Next filter in the chain
+ lzma_next_coder next;
+
+ /// True if the next coder in the chain has returned LZMA_STREAM_END.
+ bool end_was_reached;
+
+ /// True if filter() should encode the data; false to decode.
+ /// Currently all simple filters use the same function for encoding
+ /// and decoding, because the difference between encoders and decoders
+ /// is very small.
+ bool is_encoder;
+
+ /// Pointer to filter-specific function, which does
+ /// the actual filtering.
+ size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
+ bool is_encoder, uint8_t *buffer, size_t size);
+
+ /// Pointer to filter-specific data, or NULL if filter doesn't need
+ /// any extra data.
+ lzma_simple *simple;
+
+ /// The lowest 32 bits of the current position in the data. Most
+ /// filters need this to do conversions between absolute and relative
+ /// addresses.
+ uint32_t now_pos;
+
+ /// Size of the memory allocated for the buffer.
+ size_t allocated;
+
+ /// Flushing position in the temporary buffer. buffer[pos] is the
+ /// next byte to be copied to out[].
+ size_t pos;
+
+ /// buffer[filtered] is the first unfiltered byte. When pos is smaller
+ /// than filtered, there is unflushed filtered data in the buffer.
+ size_t filtered;
+
+ /// Total number of bytes (both filtered and unfiltered) currently
+ /// in the temporary buffer.
+ size_t size;
+
+ /// Temporary buffer
+ uint8_t buffer[];
+};
+
+
+extern lzma_ret lzma_simple_coder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters,
+ size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
+ bool is_encoder, uint8_t *buffer, size_t size),
+ size_t simple_size, size_t unfiltered_max,
+ uint32_t alignment, bool is_encoder);
+
+#endif
diff --git a/Utilities/cmliblzma/liblzma/simple/sparc.c b/Utilities/cmliblzma/liblzma/simple/sparc.c
new file mode 100644
index 0000000000..0ddd2ac9de
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/sparc.c
@@ -0,0 +1,82 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file sparc.c
+/// \brief Filter for SPARC binaries
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_private.h"
+
+
+static size_t
+sparc_code(lzma_simple *simple lzma_attribute((__unused__)),
+ uint32_t now_pos, bool is_encoder,
+ uint8_t *buffer, size_t size)
+{
+ size_t i;
+ for (i = 0; i + 4 <= size; i += 4) {
+
+ if ((buffer[i] == 0x40 && (buffer[i + 1] & 0xC0) == 0x00)
+ || (buffer[i] == 0x7F
+ && (buffer[i + 1] & 0xC0) == 0xC0)) {
+
+ uint32_t dest;
+
+ uint32_t src = ((uint32_t)buffer[i + 0] << 24)
+ | ((uint32_t)buffer[i + 1] << 16)
+ | ((uint32_t)buffer[i + 2] << 8)
+ | ((uint32_t)buffer[i + 3]);
+
+ src <<= 2;
+
+ if (is_encoder)
+ dest = now_pos + (uint32_t)(i) + src;
+ else
+ dest = src - (now_pos + (uint32_t)(i));
+
+ dest >>= 2;
+
+ dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF)
+ | (dest & 0x3FFFFF)
+ | 0x40000000;
+
+ buffer[i + 0] = (uint8_t)(dest >> 24);
+ buffer[i + 1] = (uint8_t)(dest >> 16);
+ buffer[i + 2] = (uint8_t)(dest >> 8);
+ buffer[i + 3] = (uint8_t)(dest);
+ }
+ }
+
+ return i;
+}
+
+
+static lzma_ret
+sparc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters, bool is_encoder)
+{
+ return lzma_simple_coder_init(next, allocator, filters,
+ &sparc_code, 0, 4, 4, is_encoder);
+}
+
+
+extern lzma_ret
+lzma_simple_sparc_encoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters)
+{
+ return sparc_coder_init(next, allocator, filters, true);
+}
+
+
+extern lzma_ret
+lzma_simple_sparc_decoder_init(lzma_next_coder *next,
+ lzma_allocator *allocator, const lzma_filter_info *filters)
+{
+ return sparc_coder_init(next, allocator, filters, false);
+}
diff --git a/Utilities/cmliblzma/liblzma/simple/x86.c b/Utilities/cmliblzma/liblzma/simple/x86.c
new file mode 100644
index 0000000000..101d8edff9
--- /dev/null
+++ b/Utilities/cmliblzma/liblzma/simple/x86.c
@@ -0,0 +1,161 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file x86.c
+/// \brief Filter for x86 binaries (BCJ filter)
+///
+// Authors: Igor Pavlov
+// Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_private.h"
+
+
+#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
+
+
+struct lzma_simple_s {
+ uint32_t prev_mask;
+ uint32_t prev_pos;
+};
+
+
+static size_t
+x86_code(lzma_simple *simple, uint32_t now_pos, bool is_encoder,
+ uint8_t *buffer, size_t size)
+{
+ static const bool MASK_TO_ALLOWED_STATUS[8]
+ = { true, true, true, false, true, false, false, false };
+
+ static const uint32_t MASK_TO_BIT_NUMBER[8]
+ = { 0, 1, 2, 2, 3, 3, 3, 3 };
+
+ uint32_t prev_mask = simple->prev_mask;
+ uint32_t prev_pos = simple->prev_pos;
+
+ size_t limit;
+ size_t buffer_pos;
+
+ if (size < 5)
+ return 0;
+
+ if (now_pos - prev_pos > 5)
+ prev_pos = now_pos - 5;
+
+ limit = size - 5;
+ buffer_pos = 0;
+
+ while (buffer_pos <= limit) {
+ uint32_t offset;
+ uint32_t i;
+
+ uint8_t b = buffer[buffer_pos];
+ if (b != 0xE8 && b != 0xE9) {
+ ++buffer_pos;
+ continue;
+ }
+
+ offset = now_pos + (uint32_t)(buffer_pos)
+ - prev_pos;
+ prev_pos = now_pos + (uint32_t)(buffer_pos);
+
+ if (offset > 5) {
+ prev_mask = 0;
+ } else {
+ for (i = 0; i < offset; ++i) {
+ prev_mask &= 0x77;
+ prev_mask <<= 1;
+ }
+ }
+
+ b = buffer[buffer_pos + 4];
+
+ if (Test86MSByte(b)
+ && MASK_TO_ALLOWED_STATUS[(prev_mask >> 1) & 0x7]
+ && (prev_mask >> 1) < 0x10) {
+
+ uint32_t src = ((uint32_t)(b) << 24)
+ | ((uint32_t)(buffer[buffer_pos + 3]) << 16)
+ | ((uint32_t)(buffer[buffer_pos + 2]) << 8)
+ | (buffer[buffer_pos + 1]);
+
+ uint32_t dest;
+ while (true) {
+ uint32_t i;
+
+ if (is_encoder)
+ dest = src + (now_pos + (uint32_t)(
+ buffer_pos) + 5);
+ else
+ dest = src - (now_pos + (uint32_t)(
+ buffer_pos) + 5);
+
+ if (prev_mask == 0)
+ break;
+
+ i = MASK_TO_BIT_NUMBER[prev_mask >> 1];
+
+ b = (uint8_t)(dest >> (24 - i * 8));
+
+ if (!Test86MSByte(b))
+ break;
+
+ src = dest ^ ((1 << (32 - i * 8)) - 1);
+ }
+
+ buffer[buffer_pos + 4]
+ = (uint8_t)(~(((dest >> 24) & 1) - 1));
+ buffer[buffer_pos + 3] = (uint8_t)(dest >> 16);
+ buffer[buffer_pos + 2] = (uint8_t)(dest >> 8);
+ buffer[buffer_pos + 1] = (uint8_t)(dest);
+ buffer_pos += 5;
+ prev_mask = 0;
+
+ } else {
+ ++buffer_pos;
+ prev_mask |= 1;
+ if (Test86MSByte(b))
+ prev_mask |= 0x10;
+ }
+ }
+
+ simple->prev_mask = prev_mask;
+ simple->prev_pos = prev_pos;
+
+ return buffer_pos;
+}
+
+
+static lzma_ret
+x86_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters, bool is_encoder)
+{
+ const lzma_ret ret = lzma_simple_coder_init(next, allocator, filters,
+ &x86_code, sizeof(lzma_simple), 5, 1, is_encoder);
+
+ if (ret == LZMA_OK) {
+ next->coder->simple->prev_mask = 0;
+ next->coder->simple->prev_pos = (uint32_t)(-5);
+ }
+
+ return ret;
+}
+
+
+extern lzma_ret
+lzma_simple_x86_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ return x86_coder_init(next, allocator, filters, true);
+}
+
+
+extern lzma_ret
+lzma_simple_x86_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ return x86_coder_init(next, allocator, filters, false);
+}
diff --git a/Utilities/cmzlib/.NoDartCoverage b/Utilities/cmzlib/.NoDartCoverage
new file mode 100644
index 0000000000..3c99729386
--- /dev/null
+++ b/Utilities/cmzlib/.NoDartCoverage
@@ -0,0 +1 @@
+# do not do coverage in this directory
diff --git a/Utilities/cmzlib/CMakeLists.txt b/Utilities/cmzlib/CMakeLists.txt
new file mode 100644
index 0000000000..f161056e52
--- /dev/null
+++ b/Utilities/cmzlib/CMakeLists.txt
@@ -0,0 +1,43 @@
+PROJECT(CMZLIB)
+
+INCLUDE_DIRECTORIES(
+ "${CMZLIB_SOURCE_DIR}"
+ "${CMZLIB_SOURCE_DIR}/.."
+ "${CMZLIB_BINARY_DIR}/.."
+ )
+
+# source files for zlib
+SET(ZLIB_SRCS
+ adler32.c compress.c crc32.c deflate.c gzio.c inffast.c
+ inflate.c inftrees.c trees.c uncompr.c zutil.c
+ )
+
+# for windows add the .def and .rc files to the source list
+# if building shared libs
+IF(WIN32)
+ IF(BUILD_SHARED_LIBS)
+ SET(ZLIB_DLL 1)
+ IF(NOT UNIX)
+ IF(NOT BORLAND)
+ IF(NOT MINGW)
+ SET(ZLIB_SRCS ${ZLIB_SRCS} zlib.def zlib.rc )
+ ENDIF(NOT MINGW)
+ ENDIF(NOT BORLAND)
+ ENDIF(NOT UNIX)
+ ENDIF(BUILD_SHARED_LIBS)
+ENDIF(WIN32)
+
+CONFIGURE_FILE(${CMZLIB_SOURCE_DIR}/.NoDartCoverage
+ ${CMZLIB_BINARY_DIR}/.NoDartCoverage)
+CONFIGURE_FILE(${CMZLIB_SOURCE_DIR}/zlibDllConfig.h.in
+ ${CMZLIB_BINARY_DIR}/zlibDllConfig.h)
+
+FOREACH(name zlib zconf cm_zlib_mangle)
+ CONFIGURE_FILE(${CMZLIB_SOURCE_DIR}/${name}.h
+ ${CMZLIB_BINARY_DIR}/${name}.h COPYONLY)
+ENDFOREACH(name)
+
+
+ADD_LIBRARY(cmzlib ${ZLIB_SRCS})
+
+INSTALL(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR}/cmzlib)
diff --git a/Utilities/cmzlib/ChangeLog b/Utilities/cmzlib/ChangeLog
new file mode 100644
index 0000000000..7f6869d323
--- /dev/null
+++ b/Utilities/cmzlib/ChangeLog
@@ -0,0 +1,855 @@
+
+ ChangeLog file for zlib
+
+Changes in 1.2.3 (18 July 2005)
+- Apply security vulnerability fixes to contrib/infback9 as well
+- Clean up some text files (carriage returns, trailing space)
+- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant]
+
+Changes in 1.2.2.4 (11 July 2005)
+- Add inflatePrime() function for starting inflation at bit boundary
+- Avoid some Visual C warnings in deflate.c
+- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit
+ compile
+- Fix some spelling errors in comments [Betts]
+- Correct inflateInit2() error return documentation in zlib.h
+- Added zran.c example of compressed data random access to examples
+ directory, shows use of inflatePrime()
+- Fix cast for assignments to strm->state in inflate.c and infback.c
+- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer]
+- Move declarations of gf2 functions to right place in crc32.c [Oberhumer]
+- Add cast in trees.c t avoid a warning [Oberhumer]
+- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer]
+- Update make_vms.com [Zinser]
+- Initialize state->write in inflateReset() since copied in inflate_fast()
+- Be more strict on incomplete code sets in inflate_table() and increase
+ ENOUGH and MAXD -- this repairs a possible security vulnerability for
+ invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for
+ discovering the vulnerability and providing test cases.
+- Add ia64 support to configure for HP-UX [Smith]
+- Add error return to gzread() for format or i/o error [Levin]
+- Use malloc.h for OS/2 [Necasek]
+
+Changes in 1.2.2.3 (27 May 2005)
+- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile
+- Typecast fread() return values in gzio.c [Vollant]
+- Remove trailing space in minigzip.c outmode (VC++ can't deal with it)
+- Fix crc check bug in gzread() after gzungetc() [Heiner]
+- Add the deflateTune() function to adjust internal compression parameters
+- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack)
+- Remove an incorrect assertion in examples/zpipe.c
+- Add C++ wrapper in infback9.h [Donais]
+- Fix bug in inflateCopy() when decoding fixed codes
+- Note in zlib.h how much deflateSetDictionary() actually uses
+- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used)
+- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer]
+- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer]
+- Add gzdirect() function to indicate transparent reads
+- Update contrib/minizip [Vollant]
+- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer]
+- Add casts in crc32.c to avoid warnings [Oberhumer]
+- Add contrib/masmx64 [Vollant]
+- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant]
+
+Changes in 1.2.2.2 (30 December 2004)
+- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
+ avoid implicit memcpy calls (portability for no-library compilation)
+- Increase sprintf() buffer size in gzdopen() to allow for large numbers
+- Add INFLATE_STRICT to check distances against zlib header
+- Improve WinCE errno handling and comments [Chang]
+- Remove comment about no gzip header processing in FAQ
+- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
+- Add updated make_vms.com [Coghlan], update README
+- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
+ fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
+- Add FAQ entry and comments in deflate.c on uninitialized memory access
+- Add Solaris 9 make options in configure [Gilbert]
+- Allow strerror() usage in gzio.c for STDC
+- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
+- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
+- Use z_off_t for adler32_combine() and crc32_combine() lengths
+- Make adler32() much faster for small len
+- Use OS_CODE in deflate() default gzip header
+
+Changes in 1.2.2.1 (31 October 2004)
+- Allow inflateSetDictionary() call for raw inflate
+- Fix inflate header crc check bug for file names and comments
+- Add deflateSetHeader() and gz_header structure for custom gzip headers
+- Add inflateGetheader() to retrieve gzip headers
+- Add crc32_combine() and adler32_combine() functions
+- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list
+- Use zstreamp consistently in zlib.h (inflate_back functions)
+- Remove GUNZIP condition from definition of inflate_mode in inflate.h
+ and in contrib/inflate86/inffast.S [Truta, Anderson]
+- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson]
+- Update projects/README.projects and projects/visualc6 [Truta]
+- Update win32/DLL_FAQ.txt [Truta]
+- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta]
+- Deprecate Z_ASCII; use Z_TEXT instead [Truta]
+- Use a new algorithm for setting strm->data_type in trees.c [Truta]
+- Do not define an exit() prototype in zutil.c unless DEBUG defined
+- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
+- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
+- Fix Darwin build version identification [Peterson]
+
+Changes in 1.2.2 (3 October 2004)
+- Update zlib.h comments on gzip in-memory processing
+- Set adler to 1 in inflateReset() to support Java test suite [Walles]
+- Add contrib/dotzlib [Ravn]
+- Update win32/DLL_FAQ.txt [Truta]
+- Update contrib/minizip [Vollant]
+- Move contrib/visual-basic.txt to old/ [Truta]
+- Fix assembler builds in projects/visualc6/ [Truta]
+
+Changes in 1.2.1.2 (9 September 2004)
+- Update INDEX file
+- Fix trees.c to update strm->data_type (no one ever noticed!)
+- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown]
+- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE)
+- Add limited multitasking protection to DYNAMIC_CRC_TABLE
+- Add NO_vsnprintf for VMS in zutil.h [Mozilla]
+- Don't declare strerror() under VMS [Mozilla]
+- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize
+- Update contrib/ada [Anisimkov]
+- Update contrib/minizip [Vollant]
+- Fix configure to not hardcode directories for Darwin [Peterson]
+- Fix gzio.c to not return error on empty files [Brown]
+- Fix indentation; update version in contrib/delphi/ZLib.pas and
+ contrib/pascal/zlibpas.pas [Truta]
+- Update mkasm.bat in contrib/masmx86 [Truta]
+- Update contrib/untgz [Truta]
+- Add projects/README.projects [Truta]
+- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta]
+- Update win32/DLL_FAQ.txt [Truta]
+- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta]
+- Remove an unnecessary assignment to curr in inftrees.c [Truta]
+- Add OS/2 to exe builds in configure [Poltorak]
+- Remove err dummy parameter in zlib.h [Kientzle]
+
+Changes in 1.2.1.1 (9 January 2004)
+- Update email address in README
+- Several FAQ updates
+- Fix a big fat bug in inftrees.c that prevented decoding valid
+ dynamic blocks with only literals and no distance codes --
+ Thanks to "Hot Emu" for the bug report and sample file
+- Add a note to puff.c on no distance codes case.
+
+Changes in 1.2.1 (17 November 2003)
+- Remove a tab in contrib/gzappend/gzappend.c
+- Update some interfaces in contrib for new zlib functions
+- Update zlib version number in some contrib entries
+- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta]
+- Support shared libraries on Hurd and KFreeBSD [Brown]
+- Fix error in NO_DIVIDE option of adler32.c
+
+Changes in 1.2.0.8 (4 November 2003)
+- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas
+- Add experimental NO_DIVIDE #define in adler32.c
+ - Possibly faster on some processors (let me know if it is)
+- Correct Z_BLOCK to not return on first inflate call if no wrap
+- Fix strm->data_type on inflate() return to correctly indicate EOB
+- Add deflatePrime() function for appending in the middle of a byte
+- Add contrib/gzappend for an example of appending to a stream
+- Update win32/DLL_FAQ.txt [Truta]
+- Delete Turbo C comment in README [Truta]
+- Improve some indentation in zconf.h [Truta]
+- Fix infinite loop on bad input in configure script [Church]
+- Fix gzeof() for concatenated gzip files [Johnson]
+- Add example to contrib/visual-basic.txt [Michael B.]
+- Add -p to mkdir's in Makefile.in [vda]
+- Fix configure to properly detect presence or lack of printf functions
+- Add AS400 support [Monnerat]
+- Add a little Cygwin support [Wilson]
+
+Changes in 1.2.0.7 (21 September 2003)
+- Correct some debug formats in contrib/infback9
+- Cast a type in a debug statement in trees.c
+- Change search and replace delimiter in configure from % to # [Beebe]
+- Update contrib/untgz to 0.2 with various fixes [Truta]
+- Add build support for Amiga [Nikl]
+- Remove some directories in old that have been updated to 1.2
+- Add dylib building for Mac OS X in configure and Makefile.in
+- Remove old distribution stuff from Makefile
+- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X
+- Update links in README
+
+Changes in 1.2.0.6 (13 September 2003)
+- Minor FAQ updates
+- Update contrib/minizip to 1.00 [Vollant]
+- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta]
+- Update POSTINC comment for 68060 [Nikl]
+- Add contrib/infback9 with deflate64 decoding (unsupported)
+- For MVS define NO_vsnprintf and undefine FAR [van Burik]
+- Add pragma for fdopen on MVS [van Burik]
+
+Changes in 1.2.0.5 (8 September 2003)
+- Add OF to inflateBackEnd() declaration in zlib.h
+- Remember start when using gzdopen in the middle of a file
+- Use internal off_t counters in gz* functions to properly handle seeks
+- Perform more rigorous check for distance-too-far in inffast.c
+- Add Z_BLOCK flush option to return from inflate at block boundary
+- Set strm->data_type on return from inflate
+ - Indicate bits unused, if at block boundary, and if in last block
+- Replace size_t with ptrdiff_t in crc32.c, and check for correct size
+- Add condition so old NO_DEFLATE define still works for compatibility
+- FAQ update regarding the Windows DLL [Truta]
+- INDEX update: add qnx entry, remove aix entry [Truta]
+- Install zlib.3 into mandir [Wilson]
+- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta]
+- Adapt the zlib interface to the new DLL convention guidelines [Truta]
+- Introduce ZLIB_WINAPI macro to allow the export of functions using
+ the WINAPI calling convention, for Visual Basic [Vollant, Truta]
+- Update msdos and win32 scripts and makefiles [Truta]
+- Export symbols by name, not by ordinal, in win32/zlib.def [Truta]
+- Add contrib/ada [Anisimkov]
+- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta]
+- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant]
+- Add contrib/masm686 [Truta]
+- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm
+ [Truta, Vollant]
+- Update contrib/delphi; rename to contrib/pascal; add example [Truta]
+- Remove contrib/delphi2; add a new contrib/delphi [Truta]
+- Avoid inclusion of the nonstandard <memory.h> in contrib/iostream,
+ and fix some method prototypes [Truta]
+- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip
+ [Truta]
+- Avoid the use of backslash (\) in contrib/minizip [Vollant]
+- Fix file time handling in contrib/untgz; update makefiles [Truta]
+- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines
+ [Vollant]
+- Remove contrib/vstudio/vc15_16 [Vollant]
+- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta]
+- Update README.contrib [Truta]
+- Invert the assignment order of match_head and s->prev[...] in
+ INSERT_STRING [Truta]
+- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings
+ [Truta]
+- Compare function pointers with 0, not with NULL or Z_NULL [Truta]
+- Fix prototype of syncsearch in inflate.c [Truta]
+- Introduce ASMINF macro to be enabled when using an ASM implementation
+ of inflate_fast [Truta]
+- Change NO_DEFLATE to NO_GZCOMPRESS [Truta]
+- Modify test_gzio in example.c to take a single file name as a
+ parameter [Truta]
+- Exit the example.c program if gzopen fails [Truta]
+- Add type casts around strlen in example.c [Truta]
+- Remove casting to sizeof in minigzip.c; give a proper type
+ to the variable compared with SUFFIX_LEN [Truta]
+- Update definitions of STDC and STDC99 in zconf.h [Truta]
+- Synchronize zconf.h with the new Windows DLL interface [Truta]
+- Use SYS16BIT instead of __32BIT__ to distinguish between
+ 16- and 32-bit platforms [Truta]
+- Use far memory allocators in small 16-bit memory models for
+ Turbo C [Truta]
+- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in
+ zlibCompileFlags [Truta]
+- Cygwin has vsnprintf [Wilson]
+- In Windows16, OS_CODE is 0, as in MSDOS [Truta]
+- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson]
+
+Changes in 1.2.0.4 (10 August 2003)
+- Minor FAQ updates
+- Be more strict when checking inflateInit2's windowBits parameter
+- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well
+- Add gzip wrapper option to deflateInit2 using windowBits
+- Add updated QNX rule in configure and qnx directory [Bonnefoy]
+- Make inflate distance-too-far checks more rigorous
+- Clean up FAR usage in inflate
+- Add casting to sizeof() in gzio.c and minigzip.c
+
+Changes in 1.2.0.3 (19 July 2003)
+- Fix silly error in gzungetc() implementation [Vollant]
+- Update contrib/minizip and contrib/vstudio [Vollant]
+- Fix printf format in example.c
+- Correct cdecl support in zconf.in.h [Anisimkov]
+- Minor FAQ updates
+
+Changes in 1.2.0.2 (13 July 2003)
+- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons
+- Attempt to avoid warnings in crc32.c for pointer-int conversion
+- Add AIX to configure, remove aix directory [Bakker]
+- Add some casts to minigzip.c
+- Improve checking after insecure sprintf() or vsprintf() calls
+- Remove #elif's from crc32.c
+- Change leave label to inf_leave in inflate.c and infback.c to avoid
+ library conflicts
+- Remove inflate gzip decoding by default--only enable gzip decoding by
+ special request for stricter backward compatibility
+- Add zlibCompileFlags() function to return compilation information
+- More typecasting in deflate.c to avoid warnings
+- Remove leading underscore from _Capital #defines [Truta]
+- Fix configure to link shared library when testing
+- Add some Windows CE target adjustments [Mai]
+- Remove #define ZLIB_DLL in zconf.h [Vollant]
+- Add zlib.3 [Rodgers]
+- Update RFC URL in deflate.c and algorithm.txt [Mai]
+- Add zlib_dll_FAQ.txt to contrib [Truta]
+- Add UL to some constants [Truta]
+- Update minizip and vstudio [Vollant]
+- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h
+- Expand use of NO_DUMMY_DECL to avoid all dummy structures
+- Added iostream3 to contrib [Schwardt]
+- Replace rewind() with fseek() for WinCE [Truta]
+- Improve setting of zlib format compression level flags
+ - Report 0 for huffman and rle strategies and for level == 0 or 1
+ - Report 2 only for level == 6
+- Only deal with 64K limit when necessary at compile time [Truta]
+- Allow TOO_FAR check to be turned off at compile time [Truta]
+- Add gzclearerr() function [Souza]
+- Add gzungetc() function
+
+Changes in 1.2.0.1 (17 March 2003)
+- Add Z_RLE strategy for run-length encoding [Truta]
+ - When Z_RLE requested, restrict matches to distance one
+ - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE
+- Correct FASTEST compilation to allow level == 0
+- Clean up what gets compiled for FASTEST
+- Incorporate changes to zconf.in.h [Vollant]
+ - Refine detection of Turbo C need for dummy returns
+ - Refine ZLIB_DLL compilation
+ - Include additional header file on VMS for off_t typedef
+- Try to use _vsnprintf where it supplants vsprintf [Vollant]
+- Add some casts in inffast.c
+- Enchance comments in zlib.h on what happens if gzprintf() tries to
+ write more than 4095 bytes before compression
+- Remove unused state from inflateBackEnd()
+- Remove exit(0) from minigzip.c, example.c
+- Get rid of all those darn tabs
+- Add "check" target to Makefile.in that does the same thing as "test"
+- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in
+- Update contrib/inflate86 [Anderson]
+- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant]
+- Add msdos and win32 directories with makefiles [Truta]
+- More additions and improvements to the FAQ
+
+Changes in 1.2.0 (9 March 2003)
+- New and improved inflate code
+ - About 20% faster
+ - Does not allocate 32K window unless and until needed
+ - Automatically detects and decompresses gzip streams
+ - Raw inflate no longer needs an extra dummy byte at end
+ - Added inflateBack functions using a callback interface--even faster
+ than inflate, useful for file utilities (gzip, zip)
+ - Added inflateCopy() function to record state for random access on
+ externally generated deflate streams (e.g. in gzip files)
+ - More readable code (I hope)
+- New and improved crc32()
+ - About 50% faster, thanks to suggestions from Rodney Brown
+- Add deflateBound() and compressBound() functions
+- Fix memory leak in deflateInit2()
+- Permit setting dictionary for raw deflate (for parallel deflate)
+- Fix const declaration for gzwrite()
+- Check for some malloc() failures in gzio.c
+- Fix bug in gzopen() on single-byte file 0x1f
+- Fix bug in gzread() on concatenated file with 0x1f at end of buffer
+ and next buffer doesn't start with 0x8b
+- Fix uncompress() to return Z_DATA_ERROR on truncated input
+- Free memory at end of example.c
+- Remove MAX #define in trees.c (conflicted with some libraries)
+- Fix static const's in deflate.c, gzio.c, and zutil.[ch]
+- Declare malloc() and free() in gzio.c if STDC not defined
+- Use malloc() instead of calloc() in zutil.c if int big enough
+- Define STDC for AIX
+- Add aix/ with approach for compiling shared library on AIX
+- Add HP-UX support for shared libraries in configure
+- Add OpenUNIX support for shared libraries in configure
+- Use $cc instead of gcc to build shared library
+- Make prefix directory if needed when installing
+- Correct Macintosh avoidance of typedef Byte in zconf.h
+- Correct Turbo C memory allocation when under Linux
+- Use libz.a instead of -lz in Makefile (assure use of compiled library)
+- Update configure to check for snprintf or vsnprintf functions and their
+ return value, warn during make if using an insecure function
+- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that
+ is lost when library is used--resolution is to build new zconf.h
+- Documentation improvements (in zlib.h):
+ - Document raw deflate and inflate
+ - Update RFCs URL
+ - Point out that zlib and gzip formats are different
+ - Note that Z_BUF_ERROR is not fatal
+ - Document string limit for gzprintf() and possible buffer overflow
+ - Note requirement on avail_out when flushing
+ - Note permitted values of flush parameter of inflate()
+- Add some FAQs (and even answers) to the FAQ
+- Add contrib/inflate86/ for x86 faster inflate
+- Add contrib/blast/ for PKWare Data Compression Library decompression
+- Add contrib/puff/ simple inflate for deflate format description
+
+Changes in 1.1.4 (11 March 2002)
+- ZFREE was repeated on same allocation on some error conditions.
+ This creates a security problem described in
+ http://www.zlib.org/advisory-2002-03-11.txt
+- Returned incorrect error (Z_MEM_ERROR) on some invalid data
+- Avoid accesses before window for invalid distances with inflate window
+ less than 32K.
+- force windowBits > 8 to avoid a bug in the encoder for a window size
+ of 256 bytes. (A complete fix will be available in 1.1.5).
+
+Changes in 1.1.3 (9 July 1998)
+- fix "an inflate input buffer bug that shows up on rare but persistent
+ occasions" (Mark)
+- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
+- fix gzseek(..., SEEK_SET) in write mode
+- fix crc check after a gzeek (Frank Faubert)
+- fix miniunzip when the last entry in a zip file is itself a zip file
+ (J Lillge)
+- add contrib/asm586 and contrib/asm686 (Brian Raiter)
+ See http://www.muppetlabs.com/~breadbox/software/assembly.html
+- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
+- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
+- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
+- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
+- added a FAQ file
+
+- Support gzdopen on Mac with Metrowerks (Jason Linhart)
+- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart)
+- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young)
+- avoid some warnings with Borland C (Tom Tanner)
+- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant)
+- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant)
+- allow several arguments to configure (Tim Mooney, Frodo Looijaard)
+- use libdir and includedir in Makefile.in (Tim Mooney)
+- support shared libraries on OSF1 V4 (Tim Mooney)
+- remove so_locations in "make clean" (Tim Mooney)
+- fix maketree.c compilation error (Glenn, Mark)
+- Python interface to zlib now in Python 1.5 (Jeremy Hylton)
+- new Makefile.riscos (Rich Walker)
+- initialize static descriptors in trees.c for embedded targets (Nick Smith)
+- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith)
+- add the OS/2 files in Makefile.in too (Andrew Zabolotny)
+- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane)
+- fix maketree.c to allow clean compilation of inffixed.h (Mark)
+- fix parameter check in deflateCopy (Gunther Nikl)
+- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler)
+- Many portability patches by Christian Spieler:
+ . zutil.c, zutil.h: added "const" for zmem*
+ . Make_vms.com: fixed some typos
+ . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists
+ . msdos/Makefile.msc: remove "default rtl link library" info from obj files
+ . msdos/Makefile.*: use model-dependent name for the built zlib library
+ . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc:
+ new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT)
+- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane)
+- replace __far with _far for better portability (Christian Spieler, Tom Lane)
+- fix test for errno.h in configure (Tim Newsham)
+
+Changes in 1.1.2 (19 March 98)
+- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant)
+ See http://www.winimage.com/zLibDll/unzip.html
+- preinitialize the inflate tables for fixed codes, to make the code
+ completely thread safe (Mark)
+- some simplifications and slight speed-up to the inflate code (Mark)
+- fix gzeof on non-compressed files (Allan Schrum)
+- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs)
+- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn)
+- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny)
+- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori)
+- do not wrap extern "C" around system includes (Tom Lane)
+- mention zlib binding for TCL in README (Andreas Kupries)
+- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert)
+- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson)
+- allow "configure --prefix $HOME" (Tim Mooney)
+- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson)
+- move Makefile.sas to amiga/Makefile.sas
+
+Changes in 1.1.1 (27 Feb 98)
+- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson)
+- remove block truncation heuristic which had very marginal effect for zlib
+ (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
+ compression ratio on some files. This also allows inlining _tr_tally for
+ matches in deflate_slow.
+- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
+
+Changes in 1.1.0 (24 Feb 98)
+- do not return STREAM_END prematurely in inflate (John Bowler)
+- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
+- compile with -DFASTEST to get compression code optimized for speed only
+- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
+- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
+ on Sun but significant on HP)
+
+- add a pointer to experimental unzip library in README (Gilles Vollant)
+- initialize variable gcc in configure (Chris Herborth)
+
+Changes in 1.0.9 (17 Feb 1998)
+- added gzputs and gzgets functions
+- do not clear eof flag in gzseek (Mark Diekhans)
+- fix gzseek for files in transparent mode (Mark Diekhans)
+- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
+- replace EXPORT with ZEXPORT to avoid conflict with other programs
+- added compress2 in zconf.h, zlib.def, zlib.dnt
+- new asm code from Gilles Vollant in contrib/asm386
+- simplify the inflate code (Mark):
+ . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
+ . ZALLOC the length list in inflate_trees_fixed() instead of using stack
+ . ZALLOC the value area for huft_build() instead of using stack
+ . Simplify Z_FINISH check in inflate()
+
+- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
+- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
+- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
+ the declaration of FAR (Gilles VOllant)
+- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
+- read_buf buf parameter of type Bytef* instead of charf*
+- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
+- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
+- fix check for presence of directories in "make install" (Ian Willis)
+
+Changes in 1.0.8 (27 Jan 1998)
+- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
+- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
+- added compress2() to allow setting the compression level
+- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
+- use constant arrays for the static trees in trees.c instead of computing
+ them at run time (thanks to Ken Raeburn for this suggestion). To create
+ trees.h, compile with GEN_TREES_H and run "make test".
+- check return code of example in "make test" and display result
+- pass minigzip command line options to file_compress
+- simplifying code of inflateSync to avoid gcc 2.8 bug
+
+- support CC="gcc -Wall" in configure -s (QingLong)
+- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
+- fix test for shared library support to avoid compiler warnings
+- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
+- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
+- do not use fdopen for Metrowerks on Mac (Brad Pettit))
+- add checks for gzputc and gzputc in example.c
+- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
+- use const for the CRC table (Ken Raeburn)
+- fixed "make uninstall" for shared libraries
+- use Tracev instead of Trace in infblock.c
+- in example.c use correct compressed length for test_sync
+- suppress +vnocompatwarnings in configure for HPUX (not always supported)
+
+Changes in 1.0.7 (20 Jan 1998)
+- fix gzseek which was broken in write mode
+- return error for gzseek to negative absolute position
+- fix configure for Linux (Chun-Chung Chen)
+- increase stack space for MSC (Tim Wegner)
+- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
+- define EXPORTVA for gzprintf (Gilles Vollant)
+- added man page zlib.3 (Rick Rodgers)
+- for contrib/untgz, fix makedir() and improve Makefile
+
+- check gzseek in write mode in example.c
+- allocate extra buffer for seeks only if gzseek is actually called
+- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
+- add inflateSyncPoint in zconf.h
+- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
+
+Changes in 1.0.6 (19 Jan 1998)
+- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
+ gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
+- Fix a deflate bug occurring only with compression level 0 (thanks to
+ Andy Buckler for finding this one).
+- In minigzip, pass transparently also the first byte for .Z files.
+- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
+- check Z_FINISH in inflate (thanks to Marc Schluper)
+- Implement deflateCopy (thanks to Adam Costello)
+- make static libraries by default in configure, add --shared option.
+- move MSDOS or Windows specific files to directory msdos
+- suppress the notion of partial flush to simplify the interface
+ (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
+- suppress history buffer provided by application to simplify the interface
+ (this feature was not implemented anyway in 1.0.4)
+- next_in and avail_in must be initialized before calling inflateInit or
+ inflateInit2
+- add EXPORT in all exported functions (for Windows DLL)
+- added Makefile.nt (thanks to Stephen Williams)
+- added the unsupported "contrib" directory:
+ contrib/asm386/ by Gilles Vollant <info@winimage.com>
+ 386 asm code replacing longest_match().
+ contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
+ A C++ I/O streams interface to the zlib gz* functions
+ contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
+ Another C++ I/O streams interface
+ contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
+ A very simple tar.gz file extractor using zlib
+ contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
+ How to use compress(), uncompress() and the gz* functions from VB.
+- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
+ level) in minigzip (thanks to Tom Lane)
+
+- use const for rommable constants in deflate
+- added test for gzseek and gztell in example.c
+- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
+- add undocumented function zError to convert error code to string
+ (for Tim Smithers)
+- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
+- Use default memcpy for Symantec MSDOS compiler.
+- Add EXPORT keyword for check_func (needed for Windows DLL)
+- add current directory to LD_LIBRARY_PATH for "make test"
+- create also a link for libz.so.1
+- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
+- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
+- added -soname for Linux in configure (Chun-Chung Chen,
+- assign numbers to the exported functions in zlib.def (for Windows DLL)
+- add advice in zlib.h for best usage of deflateSetDictionary
+- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
+- allow compilation with ANSI keywords only enabled for TurboC in large model
+- avoid "versionString"[0] (Borland bug)
+- add NEED_DUMMY_RETURN for Borland
+- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
+- allow compilation with CC
+- defined STDC for OS/2 (David Charlap)
+- limit external names to 8 chars for MVS (Thomas Lund)
+- in minigzip.c, use static buffers only for 16-bit systems
+- fix suffix check for "minigzip -d foo.gz"
+- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
+- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
+- added makelcc.bat for lcc-win32 (Tom St Denis)
+- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
+- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
+- check for unistd.h in configure (for off_t)
+- remove useless check parameter in inflate_blocks_free
+- avoid useless assignment of s->check to itself in inflate_blocks_new
+- do not flush twice in gzclose (thanks to Ken Raeburn)
+- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
+- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
+- work around buggy fclose on pipes for HP/UX
+- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
+- fix configure if CC is already equal to gcc
+
+Changes in 1.0.5 (3 Jan 98)
+- Fix inflate to terminate gracefully when fed corrupted or invalid data
+- Use const for rommable constants in inflate
+- Eliminate memory leaks on error conditions in inflate
+- Removed some vestigial code in inflate
+- Update web address in README
+
+Changes in 1.0.4 (24 Jul 96)
+- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
+ bit, so the decompressor could decompress all the correct data but went
+ on to attempt decompressing extra garbage data. This affected minigzip too.
+- zlibVersion and gzerror return const char* (needed for DLL)
+- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
+- use z_error only for DEBUG (avoid problem with DLLs)
+
+Changes in 1.0.3 (2 Jul 96)
+- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS
+ small and medium models; this makes the library incompatible with previous
+ versions for these models. (No effect in large model or on other systems.)
+- return OK instead of BUF_ERROR if previous deflate call returned with
+ avail_out as zero but there is nothing to do
+- added memcmp for non STDC compilers
+- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly)
+- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO)
+- better check for 16-bit mode MSC (avoids problem with Symantec)
+
+Changes in 1.0.2 (23 May 96)
+- added Windows DLL support
+- added a function zlibVersion (for the DLL support)
+- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model)
+- Bytef is define's instead of typedef'd only for Borland C
+- avoid reading uninitialized memory in example.c
+- mention in README that the zlib format is now RFC1950
+- updated Makefile.dj2
+- added algorithm.doc
+
+Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
+- fix array overlay in deflate.c which sometimes caused bad compressed data
+- fix inflate bug with empty stored block
+- fix MSDOS medium model which was broken in 0.99
+- fix deflateParams() which could generated bad compressed data.
+- Bytef is define'd instead of typedef'ed (work around Borland bug)
+- added an INDEX file
+- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
+ Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
+- speed up adler32 for modern machines without auto-increment
+- added -ansi for IRIX in configure
+- static_init_done in trees.c is an int
+- define unlink as delete for VMS
+- fix configure for QNX
+- add configure branch for SCO and HPUX
+- avoid many warnings (unused variables, dead assignments, etc...)
+- no fdopen for BeOS
+- fix the Watcom fix for 32 bit mode (define FAR as empty)
+- removed redefinition of Byte for MKWERKS
+- work around an MWKERKS bug (incorrect merge of all .h files)
+
+Changes in 0.99 (27 Jan 96)
+- allow preset dictionary shared between compressor and decompressor
+- allow compression level 0 (no compression)
+- add deflateParams in zlib.h: allow dynamic change of compression level
+ and compression strategy.
+- test large buffers and deflateParams in example.c
+- add optional "configure" to build zlib as a shared library
+- suppress Makefile.qnx, use configure instead
+- fixed deflate for 64-bit systems (detected on Cray)
+- fixed inflate_blocks for 64-bit systems (detected on Alpha)
+- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2)
+- always return Z_BUF_ERROR when deflate() has nothing to do
+- deflateInit and inflateInit are now macros to allow version checking
+- prefix all global functions and types with z_ with -DZ_PREFIX
+- make falloc completely reentrant (inftrees.c)
+- fixed very unlikely race condition in ct_static_init
+- free in reverse order of allocation to help memory manager
+- use zlib-1.0/* instead of zlib/* inside the tar.gz
+- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
+ -Wconversion -Wstrict-prototypes -Wmissing-prototypes"
+- allow gzread on concatenated .gz files
+- deflateEnd now returns Z_DATA_ERROR if it was premature
+- deflate is finally (?) fully deterministic (no matches beyond end of input)
+- Document Z_SYNC_FLUSH
+- add uninstall in Makefile
+- Check for __cpluplus in zlib.h
+- Better test in ct_align for partial flush
+- avoid harmless warnings for Borland C++
+- initialize hash_head in deflate.c
+- avoid warning on fdopen (gzio.c) for HP cc -Aa
+- include stdlib.h for STDC compilers
+- include errno.h for Cray
+- ignore error if ranlib doesn't exist
+- call ranlib twice for NeXTSTEP
+- use exec_prefix instead of prefix for libz.a
+- renamed ct_* as _tr_* to avoid conflict with applications
+- clear z->msg in inflateInit2 before any error return
+- initialize opaque in example.c, gzio.c, deflate.c and inflate.c
+- fixed typo in zconf.h (_GNUC__ => __GNUC__)
+- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
+- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
+- in fcalloc, normalize pointer if size > 65520 bytes
+- don't use special fcalloc for 32 bit Borland C++
+- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
+- use Z_BINARY instead of BINARY
+- document that gzclose after gzdopen will close the file
+- allow "a" as mode in gzopen.
+- fix error checking in gzread
+- allow skipping .gz extra-field on pipes
+- added reference to Perl interface in README
+- put the crc table in FAR data (I dislike more and more the medium model :)
+- added get_crc_table
+- added a dimension to all arrays (Borland C can't count).
+- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
+- guard against multiple inclusion of *.h (for precompiled header on Mac)
+- Watcom C pretends to be Microsoft C small model even in 32 bit mode.
+- don't use unsized arrays to avoid silly warnings by Visual C++:
+ warning C4746: 'inflate_mask' : unsized array treated as '__far'
+ (what's wrong with far data in far model?).
+- define enum out of inflate_blocks_state to allow compilation with C++
+
+Changes in 0.95 (16 Aug 95)
+- fix MSDOS small and medium model (now easier to adapt to any compiler)
+- inlined send_bits
+- fix the final (:-) bug for deflate with flush (output was correct but
+ not completely flushed in rare occasions).
+- default window size is same for compression and decompression
+ (it's now sufficient to set MAX_WBITS in zconf.h).
+- voidp -> voidpf and voidnp -> voidp (for consistency with other
+ typedefs and because voidnp was not near in large model).
+
+Changes in 0.94 (13 Aug 95)
+- support MSDOS medium model
+- fix deflate with flush (could sometimes generate bad output)
+- fix deflateReset (zlib header was incorrectly suppressed)
+- added support for VMS
+- allow a compression level in gzopen()
+- gzflush now calls fflush
+- For deflate with flush, flush even if no more input is provided.
+- rename libgz.a as libz.a
+- avoid complex expression in infcodes.c triggering Turbo C bug
+- work around a problem with gcc on Alpha (in INSERT_STRING)
+- don't use inline functions (problem with some gcc versions)
+- allow renaming of Byte, uInt, etc... with #define.
+- avoid warning about (unused) pointer before start of array in deflate.c
+- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
+- avoid reserved word 'new' in trees.c
+
+Changes in 0.93 (25 June 95)
+- temporarily disable inline functions
+- make deflate deterministic
+- give enough lookahead for PARTIAL_FLUSH
+- Set binary mode for stdin/stdout in minigzip.c for OS/2
+- don't even use signed char in inflate (not portable enough)
+- fix inflate memory leak for segmented architectures
+
+Changes in 0.92 (3 May 95)
+- don't assume that char is signed (problem on SGI)
+- Clear bit buffer when starting a stored block
+- no memcpy on Pyramid
+- suppressed inftest.c
+- optimized fill_window, put longest_match inline for gcc
+- optimized inflate on stored blocks.
+- untabify all sources to simplify patches
+
+Changes in 0.91 (2 May 95)
+- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
+- Document the memory requirements in zconf.h
+- added "make install"
+- fix sync search logic in inflateSync
+- deflate(Z_FULL_FLUSH) now works even if output buffer too short
+- after inflateSync, don't scare people with just "lo world"
+- added support for DJGPP
+
+Changes in 0.9 (1 May 95)
+- don't assume that zalloc clears the allocated memory (the TurboC bug
+ was Mark's bug after all :)
+- let again gzread copy uncompressed data unchanged (was working in 0.71)
+- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
+- added a test of inflateSync in example.c
+- moved MAX_WBITS to zconf.h because users might want to change that.
+- document explicitly that zalloc(64K) on MSDOS must return a normalized
+ pointer (zero offset)
+- added Makefiles for Microsoft C, Turbo C, Borland C++
+- faster crc32()
+
+Changes in 0.8 (29 April 95)
+- added fast inflate (inffast.c)
+- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
+ is incompatible with previous versions of zlib which returned Z_OK.
+- work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
+ (actually that was not a compiler bug, see 0.81 above)
+- gzread no longer reads one extra byte in certain cases
+- In gzio destroy(), don't reference a freed structure
+- avoid many warnings for MSDOS
+- avoid the ERROR symbol which is used by MS Windows
+
+Changes in 0.71 (14 April 95)
+- Fixed more MSDOS compilation problems :( There is still a bug with
+ TurboC large model.
+
+Changes in 0.7 (14 April 95)
+- Added full inflate support.
+- Simplified the crc32() interface. The pre- and post-conditioning
+ (one's complement) is now done inside crc32(). WARNING: this is
+ incompatible with previous versions; see zlib.h for the new usage.
+
+Changes in 0.61 (12 April 95)
+- workaround for a bug in TurboC. example and minigzip now work on MSDOS.
+
+Changes in 0.6 (11 April 95)
+- added minigzip.c
+- added gzdopen to reopen a file descriptor as gzFile
+- added transparent reading of non-gziped files in gzread.
+- fixed bug in gzread (don't read crc as data)
+- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose).
+- don't allocate big arrays in the stack (for MSDOS)
+- fix some MSDOS compilation problems
+
+Changes in 0.5:
+- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
+ not yet Z_FULL_FLUSH.
+- support decompression but only in a single step (forced Z_FINISH)
+- added opaque object for zalloc and zfree.
+- added deflateReset and inflateReset
+- added a variable zlib_version for consistency checking.
+- renamed the 'filter' parameter of deflateInit2 as 'strategy'.
+ Added Z_FILTERED and Z_HUFFMAN_ONLY constants.
+
+Changes in 0.4:
+- avoid "zip" everywhere, use zlib instead of ziplib.
+- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
+ if compression method == 8.
+- added adler32 and crc32
+- renamed deflateOptions as deflateInit2, call one or the other but not both
+- added the method parameter for deflateInit2.
+- added inflateInit2
+- simplied considerably deflateInit and inflateInit by not supporting
+ user-provided history buffer. This is supported only in deflateInit2
+ and inflateInit2.
+
+Changes in 0.3:
+- prefix all macro names with Z_
+- use Z_FINISH instead of deflateEnd to finish compression.
+- added Z_HUFFMAN_ONLY
+- added gzerror()
diff --git a/Utilities/cmzlib/Copyright.txt b/Utilities/cmzlib/Copyright.txt
new file mode 100644
index 0000000000..db0beaea5f
--- /dev/null
+++ b/Utilities/cmzlib/Copyright.txt
@@ -0,0 +1,23 @@
+'zlib' general purpose compression library
+version 1.2.3, July 18th, 2005
+
+Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+
+Jean-loup Gailly Mark Adler
+jloup@gzip.org madler@alumni.caltech.edu
diff --git a/Utilities/cmzlib/FAQ b/Utilities/cmzlib/FAQ
new file mode 100644
index 0000000000..441d910daa
--- /dev/null
+++ b/Utilities/cmzlib/FAQ
@@ -0,0 +1,339 @@
+
+ Frequently Asked Questions about zlib
+
+
+If your question is not there, please check the zlib home page
+http://www.zlib.org which may have more recent information.
+The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
+
+
+ 1. Is zlib Y2K-compliant?
+
+ Yes. zlib doesn't handle dates.
+
+ 2. Where can I get a Windows DLL version?
+
+ The zlib sources can be compiled without change to produce a DLL.
+ See the file win32/DLL_FAQ.txt in the zlib distribution.
+ Pointers to the precompiled DLL are found in the zlib web site at
+ http://www.zlib.org.
+
+ 3. Where can I get a Visual Basic interface to zlib?
+
+ See
+ * http://www.dogma.net/markn/articles/zlibtool/zlibtool.htm
+ * contrib/visual-basic.txt in the zlib distribution
+ * win32/DLL_FAQ.txt in the zlib distribution
+
+ 4. compress() returns Z_BUF_ERROR.
+
+ Make sure that before the call of compress, the length of the compressed
+ buffer is equal to the total size of the compressed buffer and not
+ zero. For Visual Basic, check that this parameter is passed by reference
+ ("as any"), not by value ("as long").
+
+ 5. deflate() or inflate() returns Z_BUF_ERROR.
+
+ Before making the call, make sure that avail_in and avail_out are not
+ zero. When setting the parameter flush equal to Z_FINISH, also make sure
+ that avail_out is big enough to allow processing all pending input.
+ Note that a Z_BUF_ERROR is not fatal--another call to deflate() or
+ inflate() can be made with more input or output space. A Z_BUF_ERROR
+ may in fact be unavoidable depending on how the functions are used, since
+ it is not possible to tell whether or not there is more output pending
+ when strm.avail_out returns with zero.
+
+ 6. Where's the zlib documentation (man pages, etc.)?
+
+ It's in zlib.h for the moment, and Francis S. Lin has converted it to a
+ web page zlib.html. Volunteers to transform this to Unix-style man pages,
+ please contact us (zlib@gzip.org). Examples of zlib usage are in the files
+ example.c and minigzip.c.
+
+ 7. Why don't you use GNU autoconf or libtool or ...?
+
+ Because we would like to keep zlib as a very small and simple
+ package. zlib is rather portable and doesn't need much configuration.
+
+ 8. I found a bug in zlib.
+
+ Most of the time, such problems are due to an incorrect usage of
+ zlib. Please try to reproduce the problem with a small program and send
+ the corresponding source to us at zlib@gzip.org . Do not send
+ multi-megabyte data files without prior agreement.
+
+ 9. Why do I get "undefined reference to gzputc"?
+
+ If "make test" produces something like
+
+ example.o(.text+0x154): undefined reference to `gzputc'
+
+ check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
+ /usr/X11R6/lib. Remove any old versions, then do "make install".
+
+10. I need a Delphi interface to zlib.
+
+ See the contrib/delphi directory in the zlib distribution.
+
+11. Can zlib handle .zip archives?
+
+ Not by itself, no. See the directory contrib/minizip in the zlib
+ distribution.
+
+12. Can zlib handle .Z files?
+
+ No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt
+ the code of uncompress on your own.
+
+13. How can I make a Unix shared library?
+
+ make clean
+ ./configure -s
+ make
+
+14. How do I install a shared zlib library on Unix?
+
+ After the above, then:
+
+ make install
+
+ However, many flavors of Unix come with a shared zlib already installed.
+ Before going to the trouble of compiling a shared version of zlib and
+ trying to install it, you may want to check if it's already there! If you
+ can #include <zlib.h>, it's there. The -lz option will probably link to it.
+
+15. I have a question about OttoPDF.
+
+ We are not the authors of OttoPDF. The real author is on the OttoPDF web
+ site: Joel Hainley, jhainley@myndkryme.com.
+
+16. Can zlib decode Flate data in an Adobe PDF file?
+
+ Yes. See http://www.fastio.com/ (ClibPDF), or http://www.pdflib.com/ .
+ To modify PDF forms, see http://sourceforge.net/projects/acroformtool/ .
+
+17. Why am I getting this "register_frame_info not found" error on Solaris?
+
+ After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
+ generates an error such as:
+
+ ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
+ symbol __register_frame_info: referenced symbol not found
+
+ The symbol __register_frame_info is not part of zlib, it is generated by
+ the C compiler (cc or gcc). You must recompile applications using zlib
+ which have this problem. This problem is specific to Solaris. See
+ http://www.sunfreeware.com for Solaris versions of zlib and applications
+ using zlib.
+
+18. Why does gzip give an error on a file I make with compress/deflate?
+
+ The compress and deflate functions produce data in the zlib format, which
+ is different and incompatible with the gzip format. The gz* functions in
+ zlib on the other hand use the gzip format. Both the zlib and gzip
+ formats use the same compressed data format internally, but have different
+ headers and trailers around the compressed data.
+
+19. Ok, so why are there two different formats?
+
+ The gzip format was designed to retain the directory information about
+ a single file, such as the name and last modification date. The zlib
+ format on the other hand was designed for in-memory and communication
+ channel applications, and has a much more compact header and trailer and
+ uses a faster integrity check than gzip.
+
+20. Well that's nice, but how do I make a gzip file in memory?
+
+ You can request that deflate write the gzip format instead of the zlib
+ format using deflateInit2(). You can also request that inflate decode
+ the gzip format using inflateInit2(). Read zlib.h for more details.
+
+21. Is zlib thread-safe?
+
+ Yes. However any library routines that zlib uses and any application-
+ provided memory allocation routines must also be thread-safe. zlib's gz*
+ functions use stdio library routines, and most of zlib's functions use the
+ library memory allocation routines by default. zlib's Init functions allow
+ for the application to provide custom memory allocation routines.
+
+ Of course, you should only operate on any given zlib or gzip stream from a
+ single thread at a time.
+
+22. Can I use zlib in my commercial application?
+
+ Yes. Please read the license in zlib.h.
+
+23. Is zlib under the GNU license?
+
+ No. Please read the license in zlib.h.
+
+24. The license says that altered source versions must be "plainly marked". So
+ what exactly do I need to do to meet that requirement?
+
+ You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In
+ particular, the final version number needs to be changed to "f", and an
+ identification string should be appended to ZLIB_VERSION. Version numbers
+ x.x.x.f are reserved for modifications to zlib by others than the zlib
+ maintainers. For example, if the version of the base zlib you are altering
+ is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
+ ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also
+ update the version strings in deflate.c and inftrees.c.
+
+ For altered source distributions, you should also note the origin and
+ nature of the changes in zlib.h, as well as in ChangeLog and README, along
+ with the dates of the alterations. The origin should include at least your
+ name (or your company's name), and an email address to contact for help or
+ issues with the library.
+
+ Note that distributing a compiled zlib library along with zlib.h and
+ zconf.h is also a source distribution, and so you should change
+ ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
+ in zlib.h as you would for a full source distribution.
+
+25. Will zlib work on a big-endian or little-endian architecture, and can I
+ exchange compressed data between them?
+
+ Yes and yes.
+
+26. Will zlib work on a 64-bit machine?
+
+ It should. It has been tested on 64-bit machines, and has no dependence
+ on any data types being limited to 32-bits in length. If you have any
+ difficulties, please provide a complete problem report to zlib@gzip.org
+
+27. Will zlib decompress data from the PKWare Data Compression Library?
+
+ No. The PKWare DCL uses a completely different compressed data format
+ than does PKZIP and zlib. However, you can look in zlib's contrib/blast
+ directory for a possible solution to your problem.
+
+28. Can I access data randomly in a compressed stream?
+
+ No, not without some preparation. If when compressing you periodically
+ use Z_FULL_FLUSH, carefully write all the pending data at those points,
+ and keep an index of those locations, then you can start decompression
+ at those points. You have to be careful to not use Z_FULL_FLUSH too
+ often, since it can significantly degrade compression.
+
+29. Does zlib work on MVS, OS/390, CICS, etc.?
+
+ We don't know for sure. We have heard occasional reports of success on
+ these systems. If you do use it on one of these, please provide us with
+ a report, instructions, and patches that we can reference when we get
+ these questions. Thanks.
+
+30. Is there some simpler, easier to read version of inflate I can look at
+ to understand the deflate format?
+
+ First off, you should read RFC 1951. Second, yes. Look in zlib's
+ contrib/puff directory.
+
+31. Does zlib infringe on any patents?
+
+ As far as we know, no. In fact, that was originally the whole point behind
+ zlib. Look here for some more information:
+
+ http://www.gzip.org/#faq11
+
+32. Can zlib work with greater than 4 GB of data?
+
+ Yes. inflate() and deflate() will process any amount of data correctly.
+ Each call of inflate() or deflate() is limited to input and output chunks
+ of the maximum value that can be stored in the compiler's "unsigned int"
+ type, but there is no limit to the number of chunks. Note however that the
+ strm.total_in and strm_total_out counters may be limited to 4 GB. These
+ counters are provided as a convenience and are not used internally by
+ inflate() or deflate(). The application can easily set up its own counters
+ updated after each call of inflate() or deflate() to count beyond 4 GB.
+ compress() and uncompress() may be limited to 4 GB, since they operate in a
+ single call. gzseek() and gztell() may be limited to 4 GB depending on how
+ zlib is compiled. See the zlibCompileFlags() function in zlib.h.
+
+ The word "may" appears several times above since there is a 4 GB limit
+ only if the compiler's "long" type is 32 bits. If the compiler's "long"
+ type is 64 bits, then the limit is 16 exabytes.
+
+33. Does zlib have any security vulnerabilities?
+
+ The only one that we are aware of is potentially in gzprintf(). If zlib
+ is compiled to use sprintf() or vsprintf(), then there is no protection
+ against a buffer overflow of a 4K string space, other than the caller of
+ gzprintf() assuring that the output will not exceed 4K. On the other
+ hand, if zlib is compiled to use snprintf() or vsnprintf(), which should
+ normally be the case, then there is no vulnerability. The ./configure
+ script will display warnings if an insecure variation of sprintf() will
+ be used by gzprintf(). Also the zlibCompileFlags() function will return
+ information on what variant of sprintf() is used by gzprintf().
+
+ If you don't have snprintf() or vsnprintf() and would like one, you can
+ find a portable implementation here:
+
+ http://www.ijs.si/software/snprintf/
+
+ Note that you should be using the most recent version of zlib. Versions
+ 1.1.3 and before were subject to a double-free vulnerability.
+
+34. Is there a Java version of zlib?
+
+ Probably what you want is to use zlib in Java. zlib is already included
+ as part of the Java SDK in the java.util.zip package. If you really want
+ a version of zlib written in the Java language, look on the zlib home
+ page for links: http://www.zlib.org/
+
+35. I get this or that compiler or source-code scanner warning when I crank it
+ up to maximally-pedantic. Can't you guys write proper code?
+
+ Many years ago, we gave up attempting to avoid warnings on every compiler
+ in the universe. It just got to be a waste of time, and some compilers
+ were downright silly. So now, we simply make sure that the code always
+ works.
+
+36. Valgrind (or some similar memory access checker) says that deflate is
+ performing a conditional jump that depends on an uninitialized value.
+ Isn't that a bug?
+
+ No. That is intentional for performance reasons, and the output of
+ deflate is not affected. This only started showing up recently since
+ zlib 1.2.x uses malloc() by default for allocations, whereas earlier
+ versions used calloc(), which zeros out the allocated memory.
+
+37. Will zlib read the (insert any ancient or arcane format here) compressed
+ data format?
+
+ Probably not. Look in the comp.compression FAQ for pointers to various
+ formats and associated software.
+
+38. How can I encrypt/decrypt zip files with zlib?
+
+ zlib doesn't support encryption. The original PKZIP encryption is very weak
+ and can be broken with freely available programs. To get strong encryption,
+ use GnuPG, http://www.gnupg.org/ , which already includes zlib compression.
+ For PKZIP compatible "encryption", look at http://www.info-zip.org/
+
+39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
+
+ "gzip" is the gzip format, and "deflate" is the zlib format. They should
+ probably have called the second one "zlib" instead to avoid confusion
+ with the raw deflate compressed data format. While the HTTP 1.1 RFC 2616
+ correctly points to the zlib specification in RFC 1950 for the "deflate"
+ transfer encoding, there have been reports of servers and browsers that
+ incorrectly produce or expect raw deflate data per the deflate
+ specficiation in RFC 1951, most notably Microsoft. So even though the
+ "deflate" transfer encoding using the zlib format would be the more
+ efficient approach (and in fact exactly what the zlib format was designed
+ for), using the "gzip" transfer encoding is probably more reliable due to
+ an unfortunate choice of name on the part of the HTTP 1.1 authors.
+
+ Bottom line: use the gzip format for HTTP 1.1 encoding.
+
+40. Does zlib support the new "Deflate64" format introduced by PKWare?
+
+ No. PKWare has apparently decided to keep that format proprietary, since
+ they have not documented it as they have previous compression formats.
+ In any case, the compression improvements are so modest compared to other
+ more modern approaches, that it's not worth the effort to implement.
+
+41. Can you please sign these lengthy legal documents and fax them back to us
+ so that we can use your software in our product?
+
+ No. Go away. Shoo.
diff --git a/Utilities/cmzlib/INDEX b/Utilities/cmzlib/INDEX
new file mode 100644
index 0000000000..0587e5902b
--- /dev/null
+++ b/Utilities/cmzlib/INDEX
@@ -0,0 +1,51 @@
+ChangeLog history of changes
+FAQ Frequently Asked Questions about zlib
+INDEX this file
+Makefile makefile for Unix (generated by configure)
+Makefile.in makefile for Unix (template for configure)
+README guess what
+algorithm.txt description of the (de)compression algorithm
+configure configure script for Unix
+zconf.in.h template for zconf.h (used by configure)
+
+amiga/ makefiles for Amiga SAS C
+as400/ makefiles for IBM AS/400
+msdos/ makefiles for MSDOS
+old/ makefiles for various architectures and zlib documentation
+ files that have not yet been updated for zlib 1.2.x
+projects/ projects for various Integrated Development Environments
+qnx/ makefiles for QNX
+win32/ makefiles for Windows
+
+ zlib public header files (must be kept):
+zconf.h
+zlib.h
+
+ private source files used to build the zlib library:
+adler32.c
+compress.c
+crc32.c
+crc32.h
+deflate.c
+deflate.h
+gzio.c
+infback.c
+inffast.c
+inffast.h
+inffixed.h
+inflate.c
+inflate.h
+inftrees.c
+inftrees.h
+trees.c
+trees.h
+uncompr.c
+zutil.c
+zutil.h
+
+ source files for sample programs:
+example.c
+minigzip.c
+
+ unsupported contribution by third parties
+See contrib/README.contrib
diff --git a/Utilities/cmzlib/README b/Utilities/cmzlib/README
new file mode 100644
index 0000000000..758cc50020
--- /dev/null
+++ b/Utilities/cmzlib/README
@@ -0,0 +1,125 @@
+ZLIB DATA COMPRESSION LIBRARY
+
+zlib 1.2.3 is a general purpose data compression library. All the code is
+thread safe. The data format used by the zlib library is described by RFCs
+(Request for Comments) 1950 to 1952 in the files
+http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
+and rfc1952.txt (gzip format). These documents are also available in other
+formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
+
+All functions of the compression library are documented in the file zlib.h
+(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
+of the library is given in the file example.c which also tests that the library
+is working correctly. Another example is given in the file minigzip.c. The
+compression library itself is composed of all source files except example.c and
+minigzip.c.
+
+To compile all files and run the test program, follow the instructions given at
+the top of Makefile. In short "make test; make install" should work for most
+machines. For Unix: "./configure; make test; make install". For MSDOS, use one
+of the special makefiles such as Makefile.msc. For VMS, use make_vms.com.
+
+Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
+<info@winimage.com> for the Windows DLL version. The zlib home page is
+http://www.zlib.org or http://www.gzip.org/zlib/ Before reporting a problem,
+please check this site to verify that you have the latest version of zlib;
+otherwise get the latest version and check whether the problem still exists or
+not.
+
+PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html before asking
+for help.
+
+Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
+issue of Dr. Dobb's Journal; a copy of the article is available in
+http://dogma.net/markn/articles/zlibtool/zlibtool.htm
+
+The changes made in version 1.2.3 are documented in the file ChangeLog.
+
+Unsupported third party contributions are provided in directory "contrib".
+
+A Java implementation of zlib is available in the Java Development Kit
+http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/package-summary.html
+See the zlib home page http://www.zlib.org for details.
+
+A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is in the
+CPAN (Comprehensive Perl Archive Network) sites
+http://www.cpan.org/modules/by-module/Compress/
+
+A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
+available in Python 1.5 and later versions, see
+http://www.python.org/doc/lib/module-zlib.html
+
+A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com> is
+availlable at http://www.oche.de/~akupries/soft/trf/trf_zip.html
+
+An experimental package to read and write files in .zip format, written on top
+of zlib by Gilles Vollant <info@winimage.com>, is available in the
+contrib/minizip directory of zlib.
+
+
+Notes for some targets:
+
+- For Windows DLL versions, please see win32/DLL_FAQ.txt
+
+- For 64-bit Irix, deflate.c must be compiled without any optimization. With
+ -O, one libpng test fails. The test works in 32 bit mode (with the -n32
+ compiler flag). The compiler bug has been reported to SGI.
+
+- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
+ when compiled with cc.
+
+- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
+ necessary to get gzprintf working correctly. This is done by configure.
+
+- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
+ other compilers. Use "make test" to check your compiler.
+
+- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
+
+- For PalmOs, see http://palmzlib.sourceforge.net/
+
+- When building a shared, i.e. dynamic library on Mac OS X, the library must be
+ installed before testing (do "make install" before "make test"), since the
+ library location is specified in the library.
+
+
+Acknowledgments:
+
+ The deflate format used by zlib was defined by Phil Katz. The deflate
+ and zlib specifications were written by L. Peter Deutsch. Thanks to all the
+ people who reported problems and suggested various improvements in zlib;
+ they are too numerous to cite here.
+
+Copyright notice:
+
+ (C) 1995-2004 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+If you use the zlib library in a product, we would appreciate *not*
+receiving lengthy legal documents to sign. The sources are provided
+for free but without warranty of any kind. The library has been
+entirely written by Jean-loup Gailly and Mark Adler; it does not
+include third-party code.
+
+If you redistribute modified sources, we would appreciate that you include
+in the file ChangeLog history information documenting your changes. Please
+read the FAQ for more information on the distribution of modified source
+versions.
diff --git a/Utilities/cmzlib/README.Kitware.txt b/Utilities/cmzlib/README.Kitware.txt
new file mode 100644
index 0000000000..77a1e165f8
--- /dev/null
+++ b/Utilities/cmzlib/README.Kitware.txt
@@ -0,0 +1,40 @@
+This directory contains a subset of the zlib library (1.2.3) and
+some custom changes.
+
+We only include enough of the distribution to provide the functionalities
+required.
+
+We would like to thank the zlib team for distributing this library.
+http://www.zlib.net
+
+Added Files
+-----------
+
+CMakeLists.txt
+ -Support building with CMake.
+
+zlib.rc
+ -For MS Windows only: provide a version resource in a dll build so that
+ when you look at the dll file in Windows explorer, it will show you the
+ version in the "Version" tab of the file's properties view.
+
+zlib.def
+ -For MS Windows only: used to explicitly list the exports from dll builds.
+
+cm_zlib_mangle.h
+ -Mangles symbols exported from the zlib library for use by CMake.
+
+zlibDllConfig.h.in
+ -Configures the correct value of the ZLIB_DLL define based on the
+ BUILD_SHARED_LIBS CMake option.
+
+Changed Files
+-------------
+You can search the code for "KITWARE_ZLIB_CHANGE" to find modifications
+vs the original zlib code
+
+zconf.h
+ -Include cm_zlib_mangle.h (at the top)
+ -Include cmzlib/zlibDllConfig.h (at the top)
+ -Changed an #if 0 to #ifdef HAVE_UNISTD_H (near middle)
+ -Suppress selected compiler warnings (at the bottom)
diff --git a/Utilities/cmzlib/adler32.c b/Utilities/cmzlib/adler32.c
new file mode 100644
index 0000000000..007ba26277
--- /dev/null
+++ b/Utilities/cmzlib/adler32.c
@@ -0,0 +1,149 @@
+/* adler32.c -- compute the Adler-32 checksum of a data stream
+ * Copyright (C) 1995-2004 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+#define BASE 65521UL /* largest prime smaller than 65536 */
+#define NMAX 5552
+/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
+
+#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
+#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
+#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
+#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
+#define DO16(buf) DO8(buf,0); DO8(buf,8);
+
+/* use NO_DIVIDE if your processor does not do division in hardware */
+#ifdef NO_DIVIDE
+# define MOD(a) \
+ do { \
+ if (a >= (BASE << 16)) a -= (BASE << 16); \
+ if (a >= (BASE << 15)) a -= (BASE << 15); \
+ if (a >= (BASE << 14)) a -= (BASE << 14); \
+ if (a >= (BASE << 13)) a -= (BASE << 13); \
+ if (a >= (BASE << 12)) a -= (BASE << 12); \
+ if (a >= (BASE << 11)) a -= (BASE << 11); \
+ if (a >= (BASE << 10)) a -= (BASE << 10); \
+ if (a >= (BASE << 9)) a -= (BASE << 9); \
+ if (a >= (BASE << 8)) a -= (BASE << 8); \
+ if (a >= (BASE << 7)) a -= (BASE << 7); \
+ if (a >= (BASE << 6)) a -= (BASE << 6); \
+ if (a >= (BASE << 5)) a -= (BASE << 5); \
+ if (a >= (BASE << 4)) a -= (BASE << 4); \
+ if (a >= (BASE << 3)) a -= (BASE << 3); \
+ if (a >= (BASE << 2)) a -= (BASE << 2); \
+ if (a >= (BASE << 1)) a -= (BASE << 1); \
+ if (a >= BASE) a -= BASE; \
+ } while (0)
+# define MOD4(a) \
+ do { \
+ if (a >= (BASE << 4)) a -= (BASE << 4); \
+ if (a >= (BASE << 3)) a -= (BASE << 3); \
+ if (a >= (BASE << 2)) a -= (BASE << 2); \
+ if (a >= (BASE << 1)) a -= (BASE << 1); \
+ if (a >= BASE) a -= BASE; \
+ } while (0)
+#else
+# define MOD(a) a %= BASE
+# define MOD4(a) a %= BASE
+#endif
+
+/* ========================================================================= */
+uLong ZEXPORT adler32(adler, buf, len)
+ uLong adler;
+ const Bytef *buf;
+ uInt len;
+{
+ unsigned long sum2;
+ unsigned n;
+
+ /* split Adler-32 into component sums */
+ sum2 = (adler >> 16) & 0xffff;
+ adler &= 0xffff;
+
+ /* in case user likes doing a byte at a time, keep it fast */
+ if (len == 1) {
+ adler += buf[0];
+ if (adler >= BASE)
+ adler -= BASE;
+ sum2 += adler;
+ if (sum2 >= BASE)
+ sum2 -= BASE;
+ return adler | (sum2 << 16);
+ }
+
+ /* initial Adler-32 value (deferred check for len == 1 speed) */
+ if (buf == Z_NULL)
+ return 1L;
+
+ /* in case short lengths are provided, keep it somewhat fast */
+ if (len < 16) {
+ while (len--) {
+ adler += *buf++;
+ sum2 += adler;
+ }
+ if (adler >= BASE)
+ adler -= BASE;
+ MOD4(sum2); /* only added so many BASE's */
+ return adler | (sum2 << 16);
+ }
+
+ /* do length NMAX blocks -- requires just one modulo operation */
+ while (len >= NMAX) {
+ len -= NMAX;
+ n = NMAX / 16; /* NMAX is divisible by 16 */
+ do {
+ DO16(buf); /* 16 sums unrolled */
+ buf += 16;
+ } while (--n);
+ MOD(adler);
+ MOD(sum2);
+ }
+
+ /* do remaining bytes (less than NMAX, still just one modulo) */
+ if (len) { /* avoid modulos if none remaining */
+ while (len >= 16) {
+ len -= 16;
+ DO16(buf);
+ buf += 16;
+ }
+ while (len--) {
+ adler += *buf++;
+ sum2 += adler;
+ }
+ MOD(adler);
+ MOD(sum2);
+ }
+
+ /* return recombined sums */
+ return adler | (sum2 << 16);
+}
+
+/* ========================================================================= */
+uLong ZEXPORT adler32_combine(adler1, adler2, len2)
+ uLong adler1;
+ uLong adler2;
+ z_off_t len2;
+{
+ unsigned long sum1;
+ unsigned long sum2;
+ unsigned rem;
+
+ /* the derivation of this formula is left as an exercise for the reader */
+ rem = (unsigned)(len2 % BASE);
+ sum1 = adler1 & 0xffff;
+ sum2 = rem * sum1;
+ MOD(sum2);
+ sum1 += (adler2 & 0xffff) + BASE - 1;
+ sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
+ if (sum1 > BASE) sum1 -= BASE;
+ if (sum1 > BASE) sum1 -= BASE;
+ if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
+ if (sum2 > BASE) sum2 -= BASE;
+ return sum1 | (sum2 << 16);
+}
diff --git a/Utilities/cmzlib/cm_zlib_mangle.h b/Utilities/cmzlib/cm_zlib_mangle.h
new file mode 100644
index 0000000000..7f001a5966
--- /dev/null
+++ b/Utilities/cmzlib/cm_zlib_mangle.h
@@ -0,0 +1,93 @@
+#ifndef cm_zlib_mangle_h
+#define cm_zlib_mangle_h
+
+/*
+
+This header file mangles all symbols exported from the zlib library.
+It is included in all files while building the zlib library. Due to
+namespace pollution, no zlib headers should be included in .h files in
+cm.
+
+The following command was used to obtain the symbol list:
+
+nm libcmzlib.so |grep " [TRD] "
+
+This is the way to recreate the whole list:
+
+nm libcmzlib.so |grep " [TRD] " | awk '{ print "#define "$3" cm_zlib_"$3 }'
+
+REMOVE the "_init" and "_fini" entries.
+
+*/
+
+#define adler32 cm_zlib_adler32
+#define adler32_combine cm_zlib_adler32_combine
+#define compress cm_zlib_compress
+#define compress2 cm_zlib_compress2
+#define compressBound cm_zlib_compressBound
+#define crc32 cm_zlib_crc32
+#define crc32_combine cm_zlib_crc32_combine
+#define get_crc_table cm_zlib_get_crc_table
+#define deflate cm_zlib_deflate
+#define deflateBound cm_zlib_deflateBound
+#define deflateCopy cm_zlib_deflateCopy
+#define deflateEnd cm_zlib_deflateEnd
+#define deflateInit2_ cm_zlib_deflateInit2_
+#define deflateInit_ cm_zlib_deflateInit_
+#define deflateParams cm_zlib_deflateParams
+#define deflatePrime cm_zlib_deflatePrime
+#define deflateReset cm_zlib_deflateReset
+#define deflateSetDictionary cm_zlib_deflateSetDictionary
+#define deflateSetHeader cm_zlib_deflateSetHeader
+#define deflateTune cm_zlib_deflateTune
+#define deflate_copyright cm_zlib_deflate_copyright
+#define gzclearerr cm_zlib_gzclearerr
+#define gzclose cm_zlib_gzclose
+#define gzdirect cm_zlib_gzdirect
+#define gzdopen cm_zlib_gzdopen
+#define gzeof cm_zlib_gzeof
+#define gzerror cm_zlib_gzerror
+#define gzflush cm_zlib_gzflush
+#define gzgetc cm_zlib_gzgetc
+#define gzgets cm_zlib_gzgets
+#define gzopen cm_zlib_gzopen
+#define gzprintf cm_zlib_gzprintf
+#define gzputc cm_zlib_gzputc
+#define gzputs cm_zlib_gzputs
+#define gzread cm_zlib_gzread
+#define gzrewind cm_zlib_gzrewind
+#define gzseek cm_zlib_gzseek
+#define gzsetparams cm_zlib_gzsetparams
+#define gztell cm_zlib_gztell
+#define gzungetc cm_zlib_gzungetc
+#define gzwrite cm_zlib_gzwrite
+#define inflate_fast cm_zlib_inflate_fast
+#define inflate cm_zlib_inflate
+#define inflateCopy cm_zlib_inflateCopy
+#define inflateEnd cm_zlib_inflateEnd
+#define inflateGetHeader cm_zlib_inflateGetHeader
+#define inflateInit2_ cm_zlib_inflateInit2_
+#define inflateInit_ cm_zlib_inflateInit_
+#define inflatePrime cm_zlib_inflatePrime
+#define inflateReset cm_zlib_inflateReset
+#define inflateSetDictionary cm_zlib_inflateSetDictionary
+#define inflateSync cm_zlib_inflateSync
+#define inflateSyncPoint cm_zlib_inflateSyncPoint
+#define inflate_copyright cm_zlib_inflate_copyright
+#define inflate_table cm_zlib_inflate_table
+#define _dist_code cm_zlib__dist_code
+#define _length_code cm_zlib__length_code
+#define _tr_align cm_zlib__tr_align
+#define _tr_flush_block cm_zlib__tr_flush_block
+#define _tr_init cm_zlib__tr_init
+#define _tr_stored_block cm_zlib__tr_stored_block
+#define _tr_tally cm_zlib__tr_tally
+#define uncompress cm_zlib_uncompress
+#define zError cm_zlib_zError
+#define z_errmsg cm_zlib_z_errmsg
+#define zcalloc cm_zlib_zcalloc
+#define zcfree cm_zlib_zcfree
+#define zlibCompileFlags cm_zlib_zlibCompileFlags
+#define zlibVersion cm_zlib_zlibVersion
+
+#endif
diff --git a/Utilities/cmzlib/compress.c b/Utilities/cmzlib/compress.c
new file mode 100644
index 0000000000..df04f0148e
--- /dev/null
+++ b/Utilities/cmzlib/compress.c
@@ -0,0 +1,79 @@
+/* compress.c -- compress a memory buffer
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+/* ===========================================================================
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least 0.1% larger than sourceLen plus
+ 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+*/
+int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+ int level;
+{
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+#ifdef MAXSEG_64K
+ /* Check for source > 64K on 16-bit machine: */
+ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
+#endif
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+ stream.opaque = (voidpf)0;
+
+ err = deflateInit(&stream, level);
+ if (err != Z_OK) return err;
+
+ err = deflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ deflateEnd(&stream);
+ return err == Z_OK ? Z_BUF_ERROR : err;
+ }
+ *destLen = stream.total_out;
+
+ err = deflateEnd(&stream);
+ return err;
+}
+
+/* ===========================================================================
+ */
+int ZEXPORT compress (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+{
+ return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
+}
+
+/* ===========================================================================
+ If the default memLevel or windowBits for deflateInit() is changed, then
+ this function needs to be updated.
+ */
+uLong ZEXPORT compressBound (sourceLen)
+ uLong sourceLen;
+{
+ return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
+}
diff --git a/Utilities/cmzlib/crc32.c b/Utilities/cmzlib/crc32.c
new file mode 100644
index 0000000000..f658a9ef55
--- /dev/null
+++ b/Utilities/cmzlib/crc32.c
@@ -0,0 +1,423 @@
+/* crc32.c -- compute the CRC-32 of a data stream
+ * Copyright (C) 1995-2005 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ *
+ * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
+ * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
+ * tables for updating the shift register in one step with three exclusive-ors
+ * instead of four steps with four exclusive-ors. This results in about a
+ * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
+ */
+
+/* @(#) $Id$ */
+
+/*
+ Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
+ protection on the static variables used to control the first-use generation
+ of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
+ first call get_crc_table() to initialize the tables before allowing more than
+ one thread to use crc32().
+ */
+
+#ifdef MAKECRCH
+# include <stdio.h>
+# ifndef DYNAMIC_CRC_TABLE
+# define DYNAMIC_CRC_TABLE
+# endif /* !DYNAMIC_CRC_TABLE */
+#endif /* MAKECRCH */
+
+#include "zutil.h" /* for STDC and FAR definitions */
+
+#define local static
+
+/* Find a four-byte integer type for crc32_little() and crc32_big(). */
+#ifndef NOBYFOUR
+# ifdef STDC /* need ANSI C limits.h to determine sizes */
+# include <limits.h>
+# define BYFOUR
+# if (UINT_MAX == 0xffffffffUL)
+ typedef unsigned int u4;
+# else
+# if (ULONG_MAX == 0xffffffffUL)
+ typedef unsigned long u4;
+# else
+# if (USHRT_MAX == 0xffffffffUL)
+ typedef unsigned short u4;
+# else
+# undef BYFOUR /* can't find a four-byte integer type! */
+# endif
+# endif
+# endif
+# endif /* STDC */
+#endif /* !NOBYFOUR */
+
+/* Definitions for doing the crc four data bytes at a time. */
+#ifdef BYFOUR
+# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
+ (((w)&0xff00)<<8)+(((w)&0xff)<<24))
+ local unsigned long crc32_little OF((unsigned long,
+ const unsigned char FAR *, unsigned));
+ local unsigned long crc32_big OF((unsigned long,
+ const unsigned char FAR *, unsigned));
+# define TBLS 8
+#else
+# define TBLS 1
+#endif /* BYFOUR */
+
+/* Local functions for crc concatenation */
+local unsigned long gf2_matrix_times OF((unsigned long *mat,
+ unsigned long vec));
+local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
+
+#ifdef DYNAMIC_CRC_TABLE
+
+local volatile int crc_table_empty = 1;
+local unsigned long FAR crc_table[TBLS][256];
+local void make_crc_table OF((void));
+#ifdef MAKECRCH
+ local void write_table OF((FILE *, const unsigned long FAR *));
+#endif /* MAKECRCH */
+/*
+ Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
+ x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
+
+ Polynomials over GF(2) are represented in binary, one bit per coefficient,
+ with the lowest powers in the most significant bit. Then adding polynomials
+ is just exclusive-or, and multiplying a polynomial by x is a right shift by
+ one. If we call the above polynomial p, and represent a byte as the
+ polynomial q, also with the lowest power in the most significant bit (so the
+ byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
+ where a mod b means the remainder after dividing a by b.
+
+ This calculation is done using the shift-register method of multiplying and
+ taking the remainder. The register is initialized to zero, and for each
+ incoming bit, x^32 is added mod p to the register if the bit is a one (where
+ x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
+ x (which is shifting right by one and adding x^32 mod p if the bit shifted
+ out is a one). We start with the highest power (least significant bit) of
+ q and repeat for all eight bits of q.
+
+ The first table is simply the CRC of all possible eight bit values. This is
+ all the information needed to generate CRCs on data a byte at a time for all
+ combinations of CRC register values and incoming bytes. The remaining tables
+ allow for word-at-a-time CRC calculation for both big-endian and little-
+ endian machines, where a word is four bytes.
+*/
+local void make_crc_table()
+{
+ unsigned long c;
+ int n, k;
+ unsigned long poly; /* polynomial exclusive-or pattern */
+ /* terms of polynomial defining this crc (except x^32): */
+ static volatile int first = 1; /* flag to limit concurrent making */
+ static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
+
+ /* See if another task is already doing this (not thread-safe, but better
+ than nothing -- significantly reduces duration of vulnerability in
+ case the advice about DYNAMIC_CRC_TABLE is ignored) */
+ if (first) {
+ first = 0;
+
+ /* make exclusive-or pattern from polynomial (0xedb88320UL) */
+ poly = 0UL;
+ for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
+ poly |= 1UL << (31 - p[n]);
+
+ /* generate a crc for every 8-bit value */
+ for (n = 0; n < 256; n++) {
+ c = (unsigned long)n;
+ for (k = 0; k < 8; k++)
+ c = c & 1 ? poly ^ (c >> 1) : c >> 1;
+ crc_table[0][n] = c;
+ }
+
+#ifdef BYFOUR
+ /* generate crc for each value followed by one, two, and three zeros,
+ and then the byte reversal of those as well as the first table */
+ for (n = 0; n < 256; n++) {
+ c = crc_table[0][n];
+ crc_table[4][n] = REV(c);
+ for (k = 1; k < 4; k++) {
+ c = crc_table[0][c & 0xff] ^ (c >> 8);
+ crc_table[k][n] = c;
+ crc_table[k + 4][n] = REV(c);
+ }
+ }
+#endif /* BYFOUR */
+
+ crc_table_empty = 0;
+ }
+ else { /* not first */
+ /* wait for the other guy to finish (not efficient, but rare) */
+ while (crc_table_empty)
+ ;
+ }
+
+#ifdef MAKECRCH
+ /* write out CRC tables to crc32.h */
+ {
+ FILE *out;
+
+ out = fopen("crc32.h", "w");
+ if (out == NULL) return;
+ fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
+ fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
+ fprintf(out, "local const unsigned long FAR ");
+ fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
+ write_table(out, crc_table[0]);
+# ifdef BYFOUR
+ fprintf(out, "#ifdef BYFOUR\n");
+ for (k = 1; k < 8; k++) {
+ fprintf(out, " },\n {\n");
+ write_table(out, crc_table[k]);
+ }
+ fprintf(out, "#endif\n");
+# endif /* BYFOUR */
+ fprintf(out, " }\n};\n");
+ fclose(out);
+ }
+#endif /* MAKECRCH */
+}
+
+#ifdef MAKECRCH
+local void write_table(out, table)
+ FILE *out;
+ const unsigned long FAR *table;
+{
+ int n;
+
+ for (n = 0; n < 256; n++)
+ fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
+ n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
+}
+#endif /* MAKECRCH */
+
+#else /* !DYNAMIC_CRC_TABLE */
+/* ========================================================================
+ * Tables of CRC-32s of all single-byte values, made by make_crc_table().
+ */
+#include "crc32.h"
+#endif /* DYNAMIC_CRC_TABLE */
+
+/* =========================================================================
+ * This function can be used by asm versions of crc32()
+ */
+const unsigned long FAR * ZEXPORT get_crc_table()
+{
+#ifdef DYNAMIC_CRC_TABLE
+ if (crc_table_empty)
+ make_crc_table();
+#endif /* DYNAMIC_CRC_TABLE */
+ return (const unsigned long FAR *)crc_table;
+}
+
+/* ========================================================================= */
+#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
+#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
+
+/* ========================================================================= */
+unsigned long ZEXPORT crc32(crc, buf, len)
+ unsigned long crc;
+ const unsigned char FAR *buf;
+ unsigned len;
+{
+ if (buf == Z_NULL) return 0UL;
+
+#ifdef DYNAMIC_CRC_TABLE
+ if (crc_table_empty)
+ make_crc_table();
+#endif /* DYNAMIC_CRC_TABLE */
+
+#ifdef BYFOUR
+ if (sizeof(void *) == sizeof(ptrdiff_t)) {
+ u4 endian;
+
+ endian = 1;
+ if (*((unsigned char *)(&endian)))
+ return crc32_little(crc, buf, len);
+ else
+ return crc32_big(crc, buf, len);
+ }
+#endif /* BYFOUR */
+ crc = crc ^ 0xffffffffUL;
+ while (len >= 8) {
+ DO8;
+ len -= 8;
+ }
+ if (len) do {
+ DO1;
+ } while (--len);
+ return crc ^ 0xffffffffUL;
+}
+
+#ifdef BYFOUR
+
+/* ========================================================================= */
+#define DOLIT4 c ^= *buf4++; \
+ c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
+ crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
+#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
+
+/* ========================================================================= */
+local unsigned long crc32_little(crc, buf, len)
+ unsigned long crc;
+ const unsigned char FAR *buf;
+ unsigned len;
+{
+ register u4 c;
+ register const u4 FAR *buf4;
+
+ c = (u4)crc;
+ c = ~c;
+ while (len && ((ptrdiff_t)buf & 3)) {
+ c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
+ len--;
+ }
+
+ buf4 = (const u4 FAR *)(const void FAR *)buf;
+ while (len >= 32) {
+ DOLIT32;
+ len -= 32;
+ }
+ while (len >= 4) {
+ DOLIT4;
+ len -= 4;
+ }
+ buf = (const unsigned char FAR *)buf4;
+
+ if (len) do {
+ c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
+ } while (--len);
+ c = ~c;
+ return (unsigned long)c;
+}
+
+/* ========================================================================= */
+#define DOBIG4 c ^= *++buf4; \
+ c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
+ crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
+#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
+
+/* ========================================================================= */
+local unsigned long crc32_big(crc, buf, len)
+ unsigned long crc;
+ const unsigned char FAR *buf;
+ unsigned len;
+{
+ register u4 c;
+ register const u4 FAR *buf4;
+
+ c = REV((u4)crc);
+ c = ~c;
+ while (len && ((ptrdiff_t)buf & 3)) {
+ c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
+ len--;
+ }
+
+ buf4 = (const u4 FAR *)(const void FAR *)buf;
+ buf4--;
+ while (len >= 32) {
+ DOBIG32;
+ len -= 32;
+ }
+ while (len >= 4) {
+ DOBIG4;
+ len -= 4;
+ }
+ buf4++;
+ buf = (const unsigned char FAR *)buf4;
+
+ if (len) do {
+ c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
+ } while (--len);
+ c = ~c;
+ return (unsigned long)(REV(c));
+}
+
+#endif /* BYFOUR */
+
+#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
+
+/* ========================================================================= */
+local unsigned long gf2_matrix_times(mat, vec)
+ unsigned long *mat;
+ unsigned long vec;
+{
+ unsigned long sum;
+
+ sum = 0;
+ while (vec) {
+ if (vec & 1)
+ sum ^= *mat;
+ vec >>= 1;
+ mat++;
+ }
+ return sum;
+}
+
+/* ========================================================================= */
+local void gf2_matrix_square(square, mat)
+ unsigned long *square;
+ unsigned long *mat;
+{
+ int n;
+
+ for (n = 0; n < GF2_DIM; n++)
+ square[n] = gf2_matrix_times(mat, mat[n]);
+}
+
+/* ========================================================================= */
+uLong ZEXPORT crc32_combine(crc1, crc2, len2)
+ uLong crc1;
+ uLong crc2;
+ z_off_t len2;
+{
+ int n;
+ unsigned long row;
+ unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
+ unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
+
+ /* degenerate case */
+ if (len2 == 0)
+ return crc1;
+
+ /* put operator for one zero bit in odd */
+ odd[0] = 0xedb88320L; /* CRC-32 polynomial */
+ row = 1;
+ for (n = 1; n < GF2_DIM; n++) {
+ odd[n] = row;
+ row <<= 1;
+ }
+
+ /* put operator for two zero bits in even */
+ gf2_matrix_square(even, odd);
+
+ /* put operator for four zero bits in odd */
+ gf2_matrix_square(odd, even);
+
+ /* apply len2 zeros to crc1 (first square will put the operator for one
+ zero byte, eight zero bits, in even) */
+ do {
+ /* apply zeros operator for this bit of len2 */
+ gf2_matrix_square(even, odd);
+ if (len2 & 1)
+ crc1 = gf2_matrix_times(even, crc1);
+ len2 >>= 1;
+
+ /* if no more bits set, then done */
+ if (len2 == 0)
+ break;
+
+ /* another iteration of the loop with odd and even swapped */
+ gf2_matrix_square(odd, even);
+ if (len2 & 1)
+ crc1 = gf2_matrix_times(odd, crc1);
+ len2 >>= 1;
+
+ /* if no more bits set, then done */
+ } while (len2 != 0);
+
+ /* return combined crc */
+ crc1 ^= crc2;
+ return crc1;
+}
diff --git a/Utilities/cmzlib/crc32.h b/Utilities/cmzlib/crc32.h
new file mode 100644
index 0000000000..8053b6117c
--- /dev/null
+++ b/Utilities/cmzlib/crc32.h
@@ -0,0 +1,441 @@
+/* crc32.h -- tables for rapid CRC calculation
+ * Generated automatically by crc32.c
+ */
+
+local const unsigned long FAR crc_table[TBLS][256] =
+{
+ {
+ 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
+ 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
+ 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
+ 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
+ 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
+ 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
+ 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
+ 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
+ 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
+ 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
+ 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
+ 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
+ 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
+ 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
+ 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
+ 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
+ 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
+ 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
+ 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
+ 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
+ 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
+ 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
+ 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
+ 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
+ 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
+ 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
+ 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
+ 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
+ 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
+ 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
+ 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
+ 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
+ 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
+ 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
+ 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
+ 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
+ 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
+ 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
+ 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
+ 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
+ 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
+ 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
+ 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
+ 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
+ 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
+ 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
+ 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
+ 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
+ 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
+ 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
+ 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
+ 0x2d02ef8dUL
+#ifdef BYFOUR
+ },
+ {
+ 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
+ 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
+ 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
+ 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
+ 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
+ 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
+ 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
+ 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
+ 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
+ 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
+ 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
+ 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
+ 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
+ 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
+ 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
+ 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
+ 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
+ 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
+ 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
+ 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
+ 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
+ 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
+ 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
+ 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
+ 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
+ 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
+ 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
+ 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
+ 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
+ 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
+ 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
+ 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
+ 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
+ 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
+ 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
+ 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
+ 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
+ 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
+ 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
+ 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
+ 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
+ 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
+ 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
+ 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
+ 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
+ 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
+ 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
+ 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
+ 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
+ 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
+ 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
+ 0x9324fd72UL
+ },
+ {
+ 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
+ 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
+ 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
+ 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
+ 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
+ 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
+ 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
+ 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
+ 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
+ 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
+ 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
+ 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
+ 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
+ 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
+ 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
+ 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
+ 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
+ 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
+ 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
+ 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
+ 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
+ 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
+ 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
+ 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
+ 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
+ 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
+ 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
+ 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
+ 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
+ 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
+ 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
+ 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
+ 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
+ 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
+ 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
+ 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
+ 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
+ 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
+ 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
+ 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
+ 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
+ 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
+ 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
+ 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
+ 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
+ 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
+ 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
+ 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
+ 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
+ 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
+ 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
+ 0xbe9834edUL
+ },
+ {
+ 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
+ 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
+ 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
+ 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
+ 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
+ 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
+ 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
+ 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
+ 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
+ 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
+ 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
+ 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
+ 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
+ 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
+ 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
+ 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
+ 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
+ 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
+ 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
+ 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
+ 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
+ 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
+ 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
+ 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
+ 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
+ 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
+ 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
+ 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
+ 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
+ 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
+ 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
+ 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
+ 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
+ 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
+ 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
+ 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
+ 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
+ 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
+ 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
+ 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
+ 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
+ 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
+ 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
+ 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
+ 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
+ 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
+ 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
+ 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
+ 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
+ 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
+ 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
+ 0xde0506f1UL
+ },
+ {
+ 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
+ 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
+ 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
+ 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
+ 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
+ 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
+ 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
+ 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
+ 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
+ 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
+ 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
+ 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
+ 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
+ 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
+ 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
+ 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
+ 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
+ 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
+ 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
+ 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
+ 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
+ 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
+ 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
+ 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
+ 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
+ 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
+ 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
+ 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
+ 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
+ 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
+ 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
+ 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
+ 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
+ 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
+ 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
+ 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
+ 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
+ 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
+ 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
+ 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
+ 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
+ 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
+ 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
+ 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
+ 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
+ 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
+ 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
+ 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
+ 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
+ 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
+ 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
+ 0x8def022dUL
+ },
+ {
+ 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
+ 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
+ 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
+ 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
+ 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
+ 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
+ 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
+ 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
+ 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
+ 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
+ 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
+ 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
+ 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
+ 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
+ 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
+ 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
+ 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
+ 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
+ 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
+ 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
+ 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
+ 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
+ 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
+ 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
+ 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
+ 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
+ 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
+ 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
+ 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
+ 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
+ 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
+ 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
+ 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
+ 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
+ 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
+ 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
+ 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
+ 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
+ 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
+ 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
+ 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
+ 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
+ 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
+ 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
+ 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
+ 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
+ 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
+ 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
+ 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
+ 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
+ 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
+ 0x72fd2493UL
+ },
+ {
+ 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
+ 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
+ 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
+ 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
+ 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
+ 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
+ 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
+ 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
+ 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
+ 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
+ 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
+ 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
+ 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
+ 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
+ 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
+ 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
+ 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
+ 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
+ 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
+ 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
+ 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
+ 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
+ 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
+ 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
+ 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
+ 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
+ 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
+ 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
+ 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
+ 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
+ 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
+ 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
+ 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
+ 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
+ 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
+ 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
+ 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
+ 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
+ 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
+ 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
+ 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
+ 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
+ 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
+ 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
+ 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
+ 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
+ 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
+ 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
+ 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
+ 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
+ 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
+ 0xed3498beUL
+ },
+ {
+ 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
+ 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
+ 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
+ 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
+ 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
+ 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
+ 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
+ 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
+ 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
+ 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
+ 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
+ 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
+ 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
+ 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
+ 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
+ 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
+ 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
+ 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
+ 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
+ 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
+ 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
+ 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
+ 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
+ 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
+ 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
+ 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
+ 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
+ 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
+ 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
+ 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
+ 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
+ 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
+ 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
+ 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
+ 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
+ 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
+ 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
+ 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
+ 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
+ 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
+ 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
+ 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
+ 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
+ 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
+ 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
+ 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
+ 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
+ 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
+ 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
+ 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
+ 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
+ 0xf10605deUL
+#endif
+ }
+};
diff --git a/Utilities/cmzlib/deflate.c b/Utilities/cmzlib/deflate.c
new file mode 100644
index 0000000000..5ec8374331
--- /dev/null
+++ b/Utilities/cmzlib/deflate.c
@@ -0,0 +1,1743 @@
+/* deflate.c -- compress data using the deflation algorithm
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * ALGORITHM
+ *
+ * The "deflation" process depends on being able to identify portions
+ * of the input text which are identical to earlier input (within a
+ * sliding window trailing behind the input currently being processed).
+ *
+ * The most straightforward technique turns out to be the fastest for
+ * most input files: try all possible matches and select the longest.
+ * The key feature of this algorithm is that insertions into the string
+ * dictionary are very simple and thus fast, and deletions are avoided
+ * completely. Insertions are performed at each input character, whereas
+ * string matches are performed only when the previous match ends. So it
+ * is preferable to spend more time in matches to allow very fast string
+ * insertions and avoid deletions. The matching algorithm for small
+ * strings is inspired from that of Rabin & Karp. A brute force approach
+ * is used to find longer strings when a small match has been found.
+ * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
+ * (by Leonid Broukhis).
+ * A previous version of this file used a more sophisticated algorithm
+ * (by Fiala and Greene) which is guaranteed to run in linear amortized
+ * time, but has a larger average cost, uses more memory and is patented.
+ * However the F&G algorithm may be faster for some highly redundant
+ * files if the parameter max_chain_length (described below) is too large.
+ *
+ * ACKNOWLEDGEMENTS
+ *
+ * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
+ * I found it in 'freeze' written by Leonid Broukhis.
+ * Thanks to many people for bug reports and testing.
+ *
+ * REFERENCES
+ *
+ * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
+ * Available in http://www.ietf.org/rfc/rfc1951.txt
+ *
+ * A description of the Rabin and Karp algorithm is given in the book
+ * "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
+ *
+ * Fiala,E.R., and Greene,D.H.
+ * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
+ *
+ */
+
+/* @(#) $Id$ */
+
+#include "deflate.h"
+
+const char deflate_copyright[] =
+ " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
+/*
+ If you use the zlib library in a product, an acknowledgment is welcome
+ in the documentation of your product. If for some reason you cannot
+ include such an acknowledgment, I would appreciate that you keep this
+ copyright string in the executable of your product.
+ */
+
+/* ===========================================================================
+ * Function prototypes.
+ */
+typedef enum {
+ need_more, /* block not completed, need more input or more output */
+ block_done, /* block flush performed */
+ finish_started, /* finish started, need only more output at next deflate */
+ finish_done /* finish done, accept no more input or output */
+} block_state;
+
+typedef block_state (*compress_func) OF((deflate_state *s, int flush));
+/* Compression function. Returns the block state after the call. */
+
+local void fill_window OF((deflate_state *s));
+local block_state deflate_stored OF((deflate_state *s, int flush));
+local block_state deflate_fast OF((deflate_state *s, int flush));
+#ifndef FASTEST
+local block_state deflate_slow OF((deflate_state *s, int flush));
+#endif
+local void lm_init OF((deflate_state *s));
+local void putShortMSB OF((deflate_state *s, uInt b));
+local void flush_pending OF((z_streamp strm));
+local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
+#ifndef FASTEST
+#ifdef ASMV
+ void match_init OF((void)); /* asm code initialization */
+ uInt longest_match OF((deflate_state *s, IPos cur_match));
+#else
+local uInt longest_match OF((deflate_state *s, IPos cur_match));
+#endif
+#endif
+local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
+
+#ifdef DEBUG
+local void check_match OF((deflate_state *s, IPos start, IPos match,
+ int length));
+#endif
+
+/* ===========================================================================
+ * Local data
+ */
+
+#define NIL 0
+/* Tail of hash chains */
+
+#ifndef TOO_FAR
+# define TOO_FAR 4096
+#endif
+/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
+
+#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
+/* Minimum amount of lookahead, except at the end of the input file.
+ * See deflate.c for comments about the MIN_MATCH+1.
+ */
+
+/* Values for max_lazy_match, good_match and max_chain_length, depending on
+ * the desired pack level (0..9). The values given below have been tuned to
+ * exclude worst case performance for pathological files. Better values may be
+ * found for specific files.
+ */
+typedef struct config_s {
+ ush good_length; /* reduce lazy search above this match length */
+ ush max_lazy; /* do not perform lazy search above this match length */
+ ush nice_length; /* quit search above this match length */
+ ush max_chain;
+ compress_func func;
+} config;
+
+#ifdef FASTEST
+local const config configuration_table[2] = {
+/* good lazy nice chain */
+/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
+/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
+#else
+local const config configuration_table[10] = {
+/* good lazy nice chain */
+/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
+/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
+/* 2 */ {4, 5, 16, 8, deflate_fast},
+/* 3 */ {4, 6, 32, 32, deflate_fast},
+
+/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */
+/* 5 */ {8, 16, 32, 32, deflate_slow},
+/* 6 */ {8, 16, 128, 128, deflate_slow},
+/* 7 */ {8, 32, 128, 256, deflate_slow},
+/* 8 */ {32, 128, 258, 1024, deflate_slow},
+/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
+#endif
+
+/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
+ * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
+ * meaning.
+ */
+
+#define EQUAL 0
+/* result of memcmp for equal strings */
+
+#ifndef NO_DUMMY_DECL
+struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
+#endif
+
+/* ===========================================================================
+ * Update a hash value with the given input byte
+ * IN assertion: all calls to to UPDATE_HASH are made with consecutive
+ * input characters, so that a running hash key can be computed from the
+ * previous key instead of complete recalculation each time.
+ */
+#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
+
+
+/* ===========================================================================
+ * Insert string str in the dictionary and set match_head to the previous head
+ * of the hash chain (the most recent string with same hash key). Return
+ * the previous length of the hash chain.
+ * If this file is compiled with -DFASTEST, the compression level is forced
+ * to 1, and no hash chains are maintained.
+ * IN assertion: all calls to to INSERT_STRING are made with consecutive
+ * input characters and the first MIN_MATCH bytes of str are valid
+ * (except for the last MIN_MATCH-1 bytes of the input file).
+ */
+#ifdef FASTEST
+#define INSERT_STRING(s, str, match_head) \
+ (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
+ match_head = s->head[s->ins_h], \
+ s->head[s->ins_h] = (Pos)(str))
+#else
+#define INSERT_STRING(s, str, match_head) \
+ (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
+ match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
+ s->head[s->ins_h] = (Pos)(str))
+#endif
+
+/* ===========================================================================
+ * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
+ * prev[] will be initialized on the fly.
+ */
+#define CLEAR_HASH(s) \
+ s->head[s->hash_size-1] = NIL; \
+ zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
+
+/* ========================================================================= */
+int ZEXPORT deflateInit_(strm, level, version, stream_size)
+ z_streamp strm;
+ int level;
+ const char *version;
+ int stream_size;
+{
+ return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
+ Z_DEFAULT_STRATEGY, version, stream_size);
+ /* To do: ignore strm->next_in if we use it as window */
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
+ version, stream_size)
+ z_streamp strm;
+ int level;
+ int method;
+ int windowBits;
+ int memLevel;
+ int strategy;
+ const char *version;
+ int stream_size;
+{
+ deflate_state *s;
+ int wrap = 1;
+ static const char my_version[] = ZLIB_VERSION;
+
+ ushf *overlay;
+ /* We overlay pending_buf and d_buf+l_buf. This works since the average
+ * output size for (length,distance) codes is <= 24 bits.
+ */
+
+ if (version == Z_NULL || version[0] != my_version[0] ||
+ stream_size != sizeof(z_stream)) {
+ return Z_VERSION_ERROR;
+ }
+ if (strm == Z_NULL) return Z_STREAM_ERROR;
+
+ strm->msg = Z_NULL;
+ if (strm->zalloc == (alloc_func)0) {
+ strm->zalloc = zcalloc;
+ strm->opaque = (voidpf)0;
+ }
+ if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+
+#ifdef FASTEST
+ if (level != 0) level = 1;
+#else
+ if (level == Z_DEFAULT_COMPRESSION) level = 6;
+#endif
+
+ if (windowBits < 0) { /* suppress zlib wrapper */
+ wrap = 0;
+ windowBits = -windowBits;
+ }
+#ifdef GZIP
+ else if (windowBits > 15) {
+ wrap = 2; /* write gzip wrapper instead */
+ windowBits -= 16;
+ }
+#endif
+ if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
+ windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
+ strategy < 0 || strategy > Z_FIXED) {
+ return Z_STREAM_ERROR;
+ }
+ if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
+ s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
+ if (s == Z_NULL) return Z_MEM_ERROR;
+ strm->state = (struct internal_state FAR *)s;
+ s->strm = strm;
+
+ s->wrap = wrap;
+ s->gzhead = Z_NULL;
+ s->w_bits = windowBits;
+ s->w_size = 1 << s->w_bits;
+ s->w_mask = s->w_size - 1;
+
+ s->hash_bits = memLevel + 7;
+ s->hash_size = 1 << s->hash_bits;
+ s->hash_mask = s->hash_size - 1;
+ s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
+
+ s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
+
+ /* The following memset eliminates the valgrind uninitialized warning
+ "swept under the carpet" here:
+ http://www.zlib.net/zlib_faq.html#faq36 */
+
+ memset(s->window, 0, s->w_size*2*sizeof(Byte));
+
+ s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
+ s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
+
+ s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
+
+ overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
+ s->pending_buf = (uchf *) overlay;
+ s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
+
+ if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
+ s->pending_buf == Z_NULL) {
+ s->status = FINISH_STATE;
+ strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
+ deflateEnd (strm);
+ return Z_MEM_ERROR;
+ }
+ s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
+ s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
+
+ s->level = level;
+ s->strategy = strategy;
+ s->method = (Byte)method;
+
+ return deflateReset(strm);
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
+ z_streamp strm;
+ const Bytef *dictionary;
+ uInt dictLength;
+{
+ deflate_state *s;
+ uInt length = dictLength;
+ uInt n;
+ IPos hash_head = 0;
+
+ if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
+ strm->state->wrap == 2 ||
+ (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
+ return Z_STREAM_ERROR;
+
+ s = strm->state;
+ if (s->wrap)
+ strm->adler = adler32(strm->adler, dictionary, dictLength);
+
+ if (length < MIN_MATCH) return Z_OK;
+ if (length > MAX_DIST(s)) {
+ length = MAX_DIST(s);
+ dictionary += dictLength - length; /* use the tail of the dictionary */
+ }
+ zmemcpy(s->window, dictionary, length);
+ s->strstart = length;
+ s->block_start = (long)length;
+
+ /* Insert all strings in the hash table (except for the last two bytes).
+ * s->lookahead stays null, so s->ins_h will be recomputed at the next
+ * call of fill_window.
+ */
+ s->ins_h = s->window[0];
+ UPDATE_HASH(s, s->ins_h, s->window[1]);
+ for (n = 0; n <= length - MIN_MATCH; n++) {
+ INSERT_STRING(s, n, hash_head);
+ }
+ if (hash_head) hash_head = 0; /* to make compiler happy */
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateReset (strm)
+ z_streamp strm;
+{
+ deflate_state *s;
+
+ if (strm == Z_NULL || strm->state == Z_NULL ||
+ strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
+ return Z_STREAM_ERROR;
+ }
+
+ strm->total_in = strm->total_out = 0;
+ strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
+ strm->data_type = Z_UNKNOWN;
+
+ s = (deflate_state *)strm->state;
+ s->pending = 0;
+ s->pending_out = s->pending_buf;
+
+ if (s->wrap < 0) {
+ s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
+ }
+ s->status = s->wrap ? INIT_STATE : BUSY_STATE;
+ strm->adler =
+#ifdef GZIP
+ s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
+#endif
+ adler32(0L, Z_NULL, 0);
+ s->last_flush = Z_NO_FLUSH;
+
+ _tr_init(s);
+ lm_init(s);
+
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateSetHeader (strm, head)
+ z_streamp strm;
+ gz_headerp head;
+{
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm->state->wrap != 2) return Z_STREAM_ERROR;
+ strm->state->gzhead = head;
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflatePrime (strm, bits, value)
+ z_streamp strm;
+ int bits;
+ int value;
+{
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ strm->state->bi_valid = bits;
+ strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateParams(strm, level, strategy)
+ z_streamp strm;
+ int level;
+ int strategy;
+{
+ deflate_state *s;
+ compress_func func;
+ int err = Z_OK;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ s = strm->state;
+
+#ifdef FASTEST
+ if (level != 0) level = 1;
+#else
+ if (level == Z_DEFAULT_COMPRESSION) level = 6;
+#endif
+ if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
+ return Z_STREAM_ERROR;
+ }
+ func = configuration_table[s->level].func;
+
+ if (func != configuration_table[level].func && strm->total_in != 0) {
+ /* Flush the last buffer: */
+ err = deflate(strm, Z_PARTIAL_FLUSH);
+ }
+ if (s->level != level) {
+ s->level = level;
+ s->max_lazy_match = configuration_table[level].max_lazy;
+ s->good_match = configuration_table[level].good_length;
+ s->nice_match = configuration_table[level].nice_length;
+ s->max_chain_length = configuration_table[level].max_chain;
+ }
+ s->strategy = strategy;
+ return err;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
+ z_streamp strm;
+ int good_length;
+ int max_lazy;
+ int nice_length;
+ int max_chain;
+{
+ deflate_state *s;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ s = strm->state;
+ s->good_match = good_length;
+ s->max_lazy_match = max_lazy;
+ s->nice_match = nice_length;
+ s->max_chain_length = max_chain;
+ return Z_OK;
+}
+
+/* =========================================================================
+ * For the default windowBits of 15 and memLevel of 8, this function returns
+ * a close to exact, as well as small, upper bound on the compressed size.
+ * They are coded as constants here for a reason--if the #define's are
+ * changed, then this function needs to be changed as well. The return
+ * value for 15 and 8 only works for those exact settings.
+ *
+ * For any setting other than those defaults for windowBits and memLevel,
+ * the value returned is a conservative worst case for the maximum expansion
+ * resulting from using fixed blocks instead of stored blocks, which deflate
+ * can emit on compressed data for some combinations of the parameters.
+ *
+ * This function could be more sophisticated to provide closer upper bounds
+ * for every combination of windowBits and memLevel, as well as wrap.
+ * But even the conservative upper bound of about 14% expansion does not
+ * seem onerous for output buffer allocation.
+ */
+uLong ZEXPORT deflateBound(strm, sourceLen)
+ z_streamp strm;
+ uLong sourceLen;
+{
+ deflate_state *s;
+ uLong destLen;
+
+ /* conservative upper bound */
+ destLen = sourceLen +
+ ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
+
+ /* if can't get parameters, return conservative bound */
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return destLen;
+
+ /* if not default parameters, return conservative bound */
+ s = strm->state;
+ if (s->w_bits != 15 || s->hash_bits != 8 + 7)
+ return destLen;
+
+ /* default settings: return tight bound for that case */
+ return compressBound(sourceLen);
+}
+
+/* =========================================================================
+ * Put a short in the pending buffer. The 16-bit value is put in MSB order.
+ * IN assertion: the stream state is correct and there is enough room in
+ * pending_buf.
+ */
+local void putShortMSB (s, b)
+ deflate_state *s;
+ uInt b;
+{
+ put_byte(s, (Byte)(b >> 8));
+ put_byte(s, (Byte)(b & 0xff));
+}
+
+/* =========================================================================
+ * Flush as much pending output as possible. All deflate() output goes
+ * through this function so some applications may wish to modify it
+ * to avoid allocating a large strm->next_out buffer and copying into it.
+ * (See also read_buf()).
+ */
+local void flush_pending(strm)
+ z_streamp strm;
+{
+ unsigned len = strm->state->pending;
+
+ if (len > strm->avail_out) len = strm->avail_out;
+ if (len == 0) return;
+
+ zmemcpy(strm->next_out, strm->state->pending_out, len);
+ strm->next_out += len;
+ strm->state->pending_out += len;
+ strm->total_out += len;
+ strm->avail_out -= len;
+ strm->state->pending -= len;
+ if (strm->state->pending == 0) {
+ strm->state->pending_out = strm->state->pending_buf;
+ }
+}
+
+/* ========================================================================= */
+int ZEXPORT deflate (strm, flush)
+ z_streamp strm;
+ int flush;
+{
+ int old_flush; /* value of flush param for previous deflate call */
+ deflate_state *s;
+
+ if (strm == Z_NULL || strm->state == Z_NULL ||
+ flush > Z_FINISH || flush < 0) {
+ return Z_STREAM_ERROR;
+ }
+ s = strm->state;
+
+ if (strm->next_out == Z_NULL ||
+ (strm->next_in == Z_NULL && strm->avail_in != 0) ||
+ (s->status == FINISH_STATE && flush != Z_FINISH)) {
+ ERR_RETURN(strm, Z_STREAM_ERROR);
+ }
+ if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
+
+ s->strm = strm; /* just in case */
+ old_flush = s->last_flush;
+ s->last_flush = flush;
+
+ /* Write the header */
+ if (s->status == INIT_STATE) {
+#ifdef GZIP
+ if (s->wrap == 2) {
+ strm->adler = crc32(0L, Z_NULL, 0);
+ put_byte(s, 31);
+ put_byte(s, 139);
+ put_byte(s, 8);
+ if (s->gzhead == NULL) {
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, s->level == 9 ? 2 :
+ (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+ 4 : 0));
+ put_byte(s, OS_CODE);
+ s->status = BUSY_STATE;
+ }
+ else {
+ put_byte(s, (s->gzhead->text ? 1 : 0) +
+ (s->gzhead->hcrc ? 2 : 0) +
+ (s->gzhead->extra == Z_NULL ? 0 : 4) +
+ (s->gzhead->name == Z_NULL ? 0 : 8) +
+ (s->gzhead->comment == Z_NULL ? 0 : 16)
+ );
+ put_byte(s, (Byte)(s->gzhead->time & 0xff));
+ put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
+ put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
+ put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
+ put_byte(s, s->level == 9 ? 2 :
+ (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+ 4 : 0));
+ put_byte(s, s->gzhead->os & 0xff);
+ if (s->gzhead->extra != NULL) {
+ put_byte(s, s->gzhead->extra_len & 0xff);
+ put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
+ }
+ if (s->gzhead->hcrc)
+ strm->adler = crc32(strm->adler, s->pending_buf,
+ s->pending);
+ s->gzindex = 0;
+ s->status = EXTRA_STATE;
+ }
+ }
+ else
+#endif
+ {
+ uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
+ uInt level_flags;
+
+ if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
+ level_flags = 0;
+ else if (s->level < 6)
+ level_flags = 1;
+ else if (s->level == 6)
+ level_flags = 2;
+ else
+ level_flags = 3;
+ header |= (level_flags << 6);
+ if (s->strstart != 0) header |= PRESET_DICT;
+ header += 31 - (header % 31);
+
+ s->status = BUSY_STATE;
+ putShortMSB(s, header);
+
+ /* Save the adler32 of the preset dictionary: */
+ if (s->strstart != 0) {
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ }
+ strm->adler = adler32(0L, Z_NULL, 0);
+ }
+ }
+#ifdef GZIP
+ if (s->status == EXTRA_STATE) {
+ if (s->gzhead->extra != NULL) {
+ uInt beg = s->pending; /* start of bytes to update crc */
+
+ while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
+ if (s->pending == s->pending_buf_size) {
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ flush_pending(strm);
+ beg = s->pending;
+ if (s->pending == s->pending_buf_size)
+ break;
+ }
+ put_byte(s, s->gzhead->extra[s->gzindex]);
+ s->gzindex++;
+ }
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ if (s->gzindex == s->gzhead->extra_len) {
+ s->gzindex = 0;
+ s->status = NAME_STATE;
+ }
+ }
+ else
+ s->status = NAME_STATE;
+ }
+ if (s->status == NAME_STATE) {
+ if (s->gzhead->name != NULL) {
+ uInt beg = s->pending; /* start of bytes to update crc */
+ int val;
+
+ do {
+ if (s->pending == s->pending_buf_size) {
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ flush_pending(strm);
+ beg = s->pending;
+ if (s->pending == s->pending_buf_size) {
+ val = 1;
+ break;
+ }
+ }
+ val = s->gzhead->name[s->gzindex++];
+ put_byte(s, val);
+ } while (val != 0);
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ if (val == 0) {
+ s->gzindex = 0;
+ s->status = COMMENT_STATE;
+ }
+ }
+ else
+ s->status = COMMENT_STATE;
+ }
+ if (s->status == COMMENT_STATE) {
+ if (s->gzhead->comment != NULL) {
+ uInt beg = s->pending; /* start of bytes to update crc */
+ int val;
+
+ do {
+ if (s->pending == s->pending_buf_size) {
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ flush_pending(strm);
+ beg = s->pending;
+ if (s->pending == s->pending_buf_size) {
+ val = 1;
+ break;
+ }
+ }
+ val = s->gzhead->comment[s->gzindex++];
+ put_byte(s, val);
+ } while (val != 0);
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ if (val == 0)
+ s->status = HCRC_STATE;
+ }
+ else
+ s->status = HCRC_STATE;
+ }
+ if (s->status == HCRC_STATE) {
+ if (s->gzhead->hcrc) {
+ if (s->pending + 2 > s->pending_buf_size)
+ flush_pending(strm);
+ if (s->pending + 2 <= s->pending_buf_size) {
+ put_byte(s, (Byte)(strm->adler & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
+ strm->adler = crc32(0L, Z_NULL, 0);
+ s->status = BUSY_STATE;
+ }
+ }
+ else
+ s->status = BUSY_STATE;
+ }
+#endif
+
+ /* Flush as much pending output as possible */
+ if (s->pending != 0) {
+ flush_pending(strm);
+ if (strm->avail_out == 0) {
+ /* Since avail_out is 0, deflate will be called again with
+ * more output space, but possibly with both pending and
+ * avail_in equal to zero. There won't be anything to do,
+ * but this is not an error situation so make sure we
+ * return OK instead of BUF_ERROR at next call of deflate:
+ */
+ s->last_flush = -1;
+ return Z_OK;
+ }
+
+ /* Make sure there is something to do and avoid duplicate consecutive
+ * flushes. For repeated and useless calls with Z_FINISH, we keep
+ * returning Z_STREAM_END instead of Z_BUF_ERROR.
+ */
+ } else if (strm->avail_in == 0 && flush <= old_flush &&
+ flush != Z_FINISH) {
+ ERR_RETURN(strm, Z_BUF_ERROR);
+ }
+
+ /* User must not provide more input after the first FINISH: */
+ if (s->status == FINISH_STATE && strm->avail_in != 0) {
+ ERR_RETURN(strm, Z_BUF_ERROR);
+ }
+
+ /* Start a new block or continue the current one.
+ */
+ if (strm->avail_in != 0 || s->lookahead != 0 ||
+ (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
+ block_state bstate;
+
+ bstate = (*(configuration_table[s->level].func))(s, flush);
+
+ if (bstate == finish_started || bstate == finish_done) {
+ s->status = FINISH_STATE;
+ }
+ if (bstate == need_more || bstate == finish_started) {
+ if (strm->avail_out == 0) {
+ s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
+ }
+ return Z_OK;
+ /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
+ * of deflate should use the same flush parameter to make sure
+ * that the flush is complete. So we don't have to output an
+ * empty block here, this will be done at next call. This also
+ * ensures that for a very small output buffer, we emit at most
+ * one empty block.
+ */
+ }
+ if (bstate == block_done) {
+ if (flush == Z_PARTIAL_FLUSH) {
+ _tr_align(s);
+ } else { /* FULL_FLUSH or SYNC_FLUSH */
+ _tr_stored_block(s, (char*)0, 0L, 0);
+ /* For a full flush, this empty block will be recognized
+ * as a special marker by inflate_sync().
+ */
+ if (flush == Z_FULL_FLUSH) {
+ CLEAR_HASH(s); /* forget history */
+ }
+ }
+ flush_pending(strm);
+ if (strm->avail_out == 0) {
+ s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
+ return Z_OK;
+ }
+ }
+ }
+ Assert(strm->avail_out > 0, "bug2");
+
+ if (flush != Z_FINISH) return Z_OK;
+ if (s->wrap <= 0) return Z_STREAM_END;
+
+ /* Write the trailer */
+#ifdef GZIP
+ if (s->wrap == 2) {
+ put_byte(s, (Byte)(strm->adler & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
+ put_byte(s, (Byte)(strm->total_in & 0xff));
+ put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
+ put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
+ put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
+ }
+ else
+#endif
+ {
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ }
+ flush_pending(strm);
+ /* If avail_out is zero, the application will call deflate again
+ * to flush the rest.
+ */
+ if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
+ return s->pending != 0 ? Z_OK : Z_STREAM_END;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateEnd (strm)
+ z_streamp strm;
+{
+ int status;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+
+ status = strm->state->status;
+ if (status != INIT_STATE &&
+ status != EXTRA_STATE &&
+ status != NAME_STATE &&
+ status != COMMENT_STATE &&
+ status != HCRC_STATE &&
+ status != BUSY_STATE &&
+ status != FINISH_STATE) {
+ return Z_STREAM_ERROR;
+ }
+
+ /* Deallocate in reverse order of allocations: */
+ TRY_FREE(strm, strm->state->pending_buf);
+ TRY_FREE(strm, strm->state->head);
+ TRY_FREE(strm, strm->state->prev);
+ TRY_FREE(strm, strm->state->window);
+
+ ZFREE(strm, strm->state);
+ strm->state = Z_NULL;
+
+ return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
+}
+
+/* =========================================================================
+ * Copy the source state to the destination state.
+ * To simplify the source, this is not supported for 16-bit MSDOS (which
+ * doesn't have enough memory anyway to duplicate compression states).
+ */
+int ZEXPORT deflateCopy (dest, source)
+ z_streamp dest;
+ z_streamp source;
+{
+#ifdef MAXSEG_64K
+ return Z_STREAM_ERROR;
+#else
+ deflate_state *ds;
+ deflate_state *ss;
+ ushf *overlay;
+
+
+ if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
+ return Z_STREAM_ERROR;
+ }
+
+ ss = source->state;
+
+ zmemcpy(dest, source, sizeof(z_stream));
+
+ ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
+ if (ds == Z_NULL) return Z_MEM_ERROR;
+ dest->state = (struct internal_state FAR *) ds;
+ zmemcpy(ds, ss, sizeof(deflate_state));
+ ds->strm = dest;
+
+ ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
+ ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
+ ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
+ overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
+ ds->pending_buf = (uchf *) overlay;
+
+ if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
+ ds->pending_buf == Z_NULL) {
+ deflateEnd (dest);
+ return Z_MEM_ERROR;
+ }
+ /* following zmemcpy do not work for 16-bit MSDOS */
+ zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
+ zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
+ zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
+ zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
+
+ ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
+ ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
+ ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
+
+ ds->l_desc.dyn_tree = ds->dyn_ltree;
+ ds->d_desc.dyn_tree = ds->dyn_dtree;
+ ds->bl_desc.dyn_tree = ds->bl_tree;
+
+ return Z_OK;
+#endif /* MAXSEG_64K */
+}
+
+/* ===========================================================================
+ * Read a new buffer from the current input stream, update the adler32
+ * and total number of bytes read. All deflate() input goes through
+ * this function so some applications may wish to modify it to avoid
+ * allocating a large strm->next_in buffer and copying from it.
+ * (See also flush_pending()).
+ */
+local int read_buf(strm, buf, size)
+ z_streamp strm;
+ Bytef *buf;
+ unsigned size;
+{
+ unsigned len = strm->avail_in;
+
+ if (len > size) len = size;
+ if (len == 0) return 0;
+
+ strm->avail_in -= len;
+
+ if (strm->state->wrap == 1) {
+ strm->adler = adler32(strm->adler, strm->next_in, len);
+ }
+#ifdef GZIP
+ else if (strm->state->wrap == 2) {
+ strm->adler = crc32(strm->adler, strm->next_in, len);
+ }
+#endif
+ zmemcpy(buf, strm->next_in, len);
+ strm->next_in += len;
+ strm->total_in += len;
+
+ return (int)len;
+}
+
+/* ===========================================================================
+ * Initialize the "longest match" routines for a new zlib stream
+ */
+local void lm_init (s)
+ deflate_state *s;
+{
+ s->window_size = (ulg)2L*s->w_size;
+
+ CLEAR_HASH(s);
+
+ /* Set the default configuration parameters:
+ */
+ s->max_lazy_match = configuration_table[s->level].max_lazy;
+ s->good_match = configuration_table[s->level].good_length;
+ s->nice_match = configuration_table[s->level].nice_length;
+ s->max_chain_length = configuration_table[s->level].max_chain;
+
+ s->strstart = 0;
+ s->block_start = 0L;
+ s->lookahead = 0;
+ s->match_length = s->prev_length = MIN_MATCH-1;
+ s->match_available = 0;
+ s->ins_h = 0;
+#ifndef FASTEST
+#ifdef ASMV
+ match_init(); /* initialize the asm code */
+#endif
+#endif
+}
+
+#ifndef FASTEST
+/* ===========================================================================
+ * Set match_start to the longest match starting at the given string and
+ * return its length. Matches shorter or equal to prev_length are discarded,
+ * in which case the result is equal to prev_length and match_start is
+ * garbage.
+ * IN assertions: cur_match is the head of the hash chain for the current
+ * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
+ * OUT assertion: the match length is not greater than s->lookahead.
+ */
+#ifndef ASMV
+/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
+ * match.S. The code will be functionally equivalent.
+ */
+local uInt longest_match(s, cur_match)
+ deflate_state *s;
+ IPos cur_match; /* current match */
+{
+ unsigned chain_length = s->max_chain_length;/* max hash chain length */
+ register Bytef *scan = s->window + s->strstart; /* current string */
+ register Bytef *match; /* matched string */
+ register int len; /* length of current match */
+ int best_len = s->prev_length; /* best match length so far */
+ int nice_match = s->nice_match; /* stop if match long enough */
+ IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
+ s->strstart - (IPos)MAX_DIST(s) : NIL;
+ /* Stop when cur_match becomes <= limit. To simplify the code,
+ * we prevent matches with the string of window index 0.
+ */
+ Posf *prev = s->prev;
+ uInt wmask = s->w_mask;
+
+#ifdef UNALIGNED_OK
+ /* Compare two bytes at a time. Note: this is not always beneficial.
+ * Try with and without -DUNALIGNED_OK to check.
+ */
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
+ register ush scan_start = *(ushf*)scan;
+ register ush scan_end = *(ushf*)(scan+best_len-1);
+#else
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH;
+ register Byte scan_end1 = scan[best_len-1];
+ register Byte scan_end = scan[best_len];
+#endif
+
+ /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
+ * It is easy to get rid of this optimization if necessary.
+ */
+ Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+
+ /* Do not waste too much time if we already have a good match: */
+ if (s->prev_length >= s->good_match) {
+ chain_length >>= 2;
+ }
+ /* Do not look for matches beyond the end of the input. This is necessary
+ * to make deflate deterministic.
+ */
+ if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
+
+ Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+
+ do {
+ Assert(cur_match < s->strstart, "no future");
+ match = s->window + cur_match;
+
+ /* Skip to next match if the match length cannot increase
+ * or if the match length is less than 2. Note that the checks below
+ * for insufficient lookahead only occur occasionally for performance
+ * reasons. Therefore uninitialized memory will be accessed, and
+ * conditional jumps will be made that depend on those values.
+ * However the length of the match is limited to the lookahead, so
+ * the output of deflate is not affected by the uninitialized values.
+ */
+#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
+ /* This code assumes sizeof(unsigned short) == 2. Do not use
+ * UNALIGNED_OK if your compiler uses a different size.
+ */
+ if (*(ushf*)(match+best_len-1) != scan_end ||
+ *(ushf*)match != scan_start) continue;
+
+ /* It is not necessary to compare scan[2] and match[2] since they are
+ * always equal when the other bytes match, given that the hash keys
+ * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
+ * strstart+3, +5, ... up to strstart+257. We check for insufficient
+ * lookahead only every 4th comparison; the 128th check will be made
+ * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
+ * necessary to put more guard bytes at the end of the window, or
+ * to check more often for insufficient lookahead.
+ */
+ Assert(scan[2] == match[2], "scan[2]?");
+ scan++, match++;
+ do {
+ } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ scan < strend);
+ /* The funny "do {}" generates better code on most compilers */
+
+ /* Here, scan <= window+strstart+257 */
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+ if (*scan == *match) scan++;
+
+ len = (MAX_MATCH - 1) - (int)(strend-scan);
+ scan = strend - (MAX_MATCH-1);
+
+#else /* UNALIGNED_OK */
+
+ if (match[best_len] != scan_end ||
+ match[best_len-1] != scan_end1 ||
+ *match != *scan ||
+ *++match != scan[1]) continue;
+
+ /* The check at best_len-1 can be removed because it will be made
+ * again later. (This heuristic is not always a win.)
+ * It is not necessary to compare scan[2] and match[2] since they
+ * are always equal when the other bytes match, given that
+ * the hash keys are equal and that HASH_BITS >= 8.
+ */
+ scan += 2, match++;
+ Assert(*scan == *match, "match[2]?");
+
+ /* We check for insufficient lookahead only every 8th comparison;
+ * the 256th check will be made at strstart+258.
+ */
+ do {
+ } while (*++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ scan < strend);
+
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+
+ len = MAX_MATCH - (int)(strend - scan);
+ scan = strend - MAX_MATCH;
+
+#endif /* UNALIGNED_OK */
+
+ if (len > best_len) {
+ s->match_start = cur_match;
+ best_len = len;
+ if (len >= nice_match) break;
+#ifdef UNALIGNED_OK
+ scan_end = *(ushf*)(scan+best_len-1);
+#else
+ scan_end1 = scan[best_len-1];
+ scan_end = scan[best_len];
+#endif
+ }
+ } while ((cur_match = prev[cur_match & wmask]) > limit
+ && --chain_length != 0);
+
+ if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
+ return s->lookahead;
+}
+#endif /* ASMV */
+#endif /* FASTEST */
+
+/* ---------------------------------------------------------------------------
+ * Optimized version for level == 1 or strategy == Z_RLE only
+ */
+local uInt longest_match_fast(s, cur_match)
+ deflate_state *s;
+ IPos cur_match; /* current match */
+{
+ register Bytef *scan = s->window + s->strstart; /* current string */
+ register Bytef *match; /* matched string */
+ register int len; /* length of current match */
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH;
+
+ /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
+ * It is easy to get rid of this optimization if necessary.
+ */
+ Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+
+ Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+
+ Assert(cur_match < s->strstart, "no future");
+
+ match = s->window + cur_match;
+
+ /* Return failure if the match length is less than 2:
+ */
+ if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
+
+ /* The check at best_len-1 can be removed because it will be made
+ * again later. (This heuristic is not always a win.)
+ * It is not necessary to compare scan[2] and match[2] since they
+ * are always equal when the other bytes match, given that
+ * the hash keys are equal and that HASH_BITS >= 8.
+ */
+ scan += 2, match += 2;
+ Assert(*scan == *match, "match[2]?");
+
+ /* We check for insufficient lookahead only every 8th comparison;
+ * the 256th check will be made at strstart+258.
+ */
+ do {
+ } while (*++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ scan < strend);
+
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+
+ len = MAX_MATCH - (int)(strend - scan);
+
+ if (len < MIN_MATCH) return MIN_MATCH - 1;
+
+ s->match_start = cur_match;
+ return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
+}
+
+#ifdef DEBUG
+/* ===========================================================================
+ * Check that the match at match_start is indeed a match.
+ */
+local void check_match(s, start, match, length)
+ deflate_state *s;
+ IPos start, match;
+ int length;
+{
+ /* check that the match is indeed a match */
+ if (zmemcmp(s->window + match,
+ s->window + start, length) != EQUAL) {
+ fprintf(stderr, " start %u, match %u, length %d\n",
+ start, match, length);
+ do {
+ fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
+ } while (--length != 0);
+ z_error("invalid match");
+ }
+ if (z_verbose > 1) {
+ fprintf(stderr,"\\[%d,%d]", start-match, length);
+ do { putc(s->window[start++], stderr); } while (--length != 0);
+ }
+}
+#else
+# define check_match(s, start, match, length)
+#endif /* DEBUG */
+
+/* ===========================================================================
+ * Fill the window when the lookahead becomes insufficient.
+ * Updates strstart and lookahead.
+ *
+ * IN assertion: lookahead < MIN_LOOKAHEAD
+ * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
+ * At least one byte has been read, or avail_in == 0; reads are
+ * performed for at least two bytes (required for the zip translate_eol
+ * option -- not supported here).
+ */
+local void fill_window(s)
+ deflate_state *s;
+{
+ register unsigned n, m;
+ register Posf *p;
+ unsigned more; /* Amount of free space at the end of the window. */
+ uInt wsize = s->w_size;
+
+ do {
+ more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
+
+ /* Deal with !@#$% 64K limit: */
+ if (sizeof(int) <= 2) {
+ if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
+ more = wsize;
+
+ } else if (more == (unsigned)(-1)) {
+ /* Very unlikely, but possible on 16 bit machine if
+ * strstart == 0 && lookahead == 1 (input done a byte at time)
+ */
+ more--;
+ }
+ }
+
+ /* If the window is almost full and there is insufficient lookahead,
+ * move the upper half to the lower one to make room in the upper half.
+ */
+ if (s->strstart >= wsize+MAX_DIST(s)) {
+
+ zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
+ s->match_start -= wsize;
+ s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
+ s->block_start -= (long) wsize;
+
+ /* Slide the hash table (could be avoided with 32 bit values
+ at the expense of memory usage). We slide even when level == 0
+ to keep the hash table consistent if we switch back to level > 0
+ later. (Using level 0 permanently is not an optimal usage of
+ zlib, so we don't care about this pathological case.)
+ */
+ /* %%% avoid this when Z_RLE */
+ n = s->hash_size;
+ p = &s->head[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ } while (--n);
+
+ n = wsize;
+#ifndef FASTEST
+ p = &s->prev[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ /* If n is not on any hash chain, prev[n] is garbage but
+ * its value will never be used.
+ */
+ } while (--n);
+#endif
+ more += wsize;
+ }
+ if (s->strm->avail_in == 0) return;
+
+ /* If there was no sliding:
+ * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
+ * more == window_size - lookahead - strstart
+ * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
+ * => more >= window_size - 2*WSIZE + 2
+ * In the BIG_MEM or MMAP case (not yet supported),
+ * window_size == input_size + MIN_LOOKAHEAD &&
+ * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
+ * Otherwise, window_size == 2*WSIZE so more >= 2.
+ * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
+ */
+ Assert(more >= 2, "more < 2");
+
+ n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
+ s->lookahead += n;
+
+ /* Initialize the hash value now that we have some input: */
+ if (s->lookahead >= MIN_MATCH) {
+ s->ins_h = s->window[s->strstart];
+ UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+#if MIN_MATCH != 3
+ Call UPDATE_HASH() MIN_MATCH-3 more times
+#endif
+ }
+ /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
+ * but this is not important since only literal bytes will be emitted.
+ */
+
+ } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
+}
+
+/* ===========================================================================
+ * Flush the current block, with given end-of-file flag.
+ * IN assertion: strstart is set to the end of the current match.
+ */
+#define FLUSH_BLOCK_ONLY(s, eof) { \
+ _tr_flush_block(s, (s->block_start >= 0L ? \
+ (charf *)&s->window[(unsigned)s->block_start] : \
+ (charf *)Z_NULL), \
+ (ulg)((long)s->strstart - s->block_start), \
+ (eof)); \
+ s->block_start = s->strstart; \
+ flush_pending(s->strm); \
+ Tracev((stderr,"[FLUSH]")); \
+}
+
+/* Same but force premature exit if necessary. */
+#define FLUSH_BLOCK(s, eof) { \
+ FLUSH_BLOCK_ONLY(s, eof); \
+ if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
+}
+
+/* ===========================================================================
+ * Copy without compression as much as possible from the input stream, return
+ * the current block state.
+ * This function does not insert new strings in the dictionary since
+ * uncompressible data is probably not useful. This function is used
+ * only for the level=0 compression option.
+ * NOTE: this function should be optimized to avoid extra copying from
+ * window to pending_buf.
+ */
+local block_state deflate_stored(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
+ * to pending_buf_size, and each stored block has a 5 byte header:
+ */
+ ulg max_block_size = 0xffff;
+ ulg max_start;
+
+ if (max_block_size > s->pending_buf_size - 5) {
+ max_block_size = s->pending_buf_size - 5;
+ }
+
+ /* Copy as much as possible from input to output: */
+ for (;;) {
+ /* Fill the window as much as possible: */
+ if (s->lookahead <= 1) {
+
+ Assert(s->strstart < s->w_size+MAX_DIST(s) ||
+ s->block_start >= (long)s->w_size, "slide too late");
+
+ fill_window(s);
+ if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
+
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+ Assert(s->block_start >= 0L, "block gone");
+
+ s->strstart += s->lookahead;
+ s->lookahead = 0;
+
+ /* Emit a stored block if pending_buf will be full: */
+ max_start = s->block_start + max_block_size;
+ if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
+ /* strstart == 0 is possible when wraparound on 16-bit machine */
+ s->lookahead = (uInt)(s->strstart - max_start);
+ s->strstart = (uInt)max_start;
+ FLUSH_BLOCK(s, 0);
+ }
+ /* Flush if we may have to slide, otherwise block_start may become
+ * negative and the data will be gone:
+ */
+ if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
+ FLUSH_BLOCK(s, 0);
+ }
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+
+/* ===========================================================================
+ * Compress as much as possible from the input stream, return the current
+ * block state.
+ * This function does not perform lazy evaluation of matches and inserts
+ * new strings in the dictionary only for unmatched strings or for short
+ * matches. It is used only for the fast compression options.
+ */
+local block_state deflate_fast(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ IPos hash_head = NIL; /* head of the hash chain */
+ int bflush; /* set if current block must be flushed */
+
+ for (;;) {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the next match, plus MIN_MATCH bytes to insert the
+ * string following the next match.
+ */
+ if (s->lookahead < MIN_LOOKAHEAD) {
+ fill_window(s);
+ if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+ return need_more;
+ }
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+
+ /* Insert the string window[strstart .. strstart+2] in the
+ * dictionary, and set hash_head to the head of the hash chain:
+ */
+ if (s->lookahead >= MIN_MATCH) {
+ INSERT_STRING(s, s->strstart, hash_head);
+ }
+
+ /* Find the longest match, discarding those <= prev_length.
+ * At this point we have always match_length < MIN_MATCH
+ */
+ if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
+ /* To simplify the code, we prevent matches with the string
+ * of window index 0 (in particular we have to avoid a match
+ * of the string with itself at the start of the input file).
+ */
+#ifdef FASTEST
+ if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
+ (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
+ s->match_length = longest_match_fast (s, hash_head);
+ }
+#else
+ if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
+ s->match_length = longest_match (s, hash_head);
+ } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
+ s->match_length = longest_match_fast (s, hash_head);
+ }
+#endif
+ /* longest_match() or longest_match_fast() sets match_start */
+ }
+ if (s->match_length >= MIN_MATCH) {
+ check_match(s, s->strstart, s->match_start, s->match_length);
+
+ _tr_tally_dist(s, s->strstart - s->match_start,
+ s->match_length - MIN_MATCH, bflush);
+
+ s->lookahead -= s->match_length;
+
+ /* Insert new strings in the hash table only if the match length
+ * is not too large. This saves time but degrades compression.
+ */
+#ifndef FASTEST
+ if (s->match_length <= s->max_insert_length &&
+ s->lookahead >= MIN_MATCH) {
+ s->match_length--; /* string at strstart already in table */
+ do {
+ s->strstart++;
+ INSERT_STRING(s, s->strstart, hash_head);
+ /* strstart never exceeds WSIZE-MAX_MATCH, so there are
+ * always MIN_MATCH bytes ahead.
+ */
+ } while (--s->match_length != 0);
+ s->strstart++;
+ } else
+#endif
+ {
+ s->strstart += s->match_length;
+ s->match_length = 0;
+ s->ins_h = s->window[s->strstart];
+ UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+#if MIN_MATCH != 3
+ Call UPDATE_HASH() MIN_MATCH-3 more times
+#endif
+ /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
+ * matter since it will be recomputed at next deflate call.
+ */
+ }
+ } else {
+ /* No match, output a literal byte */
+ Tracevv((stderr,"%c", s->window[s->strstart]));
+ _tr_tally_lit (s, s->window[s->strstart], bflush);
+ s->lookahead--;
+ s->strstart++;
+ }
+ if (bflush) FLUSH_BLOCK(s, 0);
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+
+#ifndef FASTEST
+/* ===========================================================================
+ * Same as above, but achieves better compression. We use a lazy
+ * evaluation for matches: a match is finally adopted only if there is
+ * no better match at the next window position.
+ */
+local block_state deflate_slow(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ IPos hash_head = NIL; /* head of hash chain */
+ int bflush; /* set if current block must be flushed */
+
+ /* Process the input block. */
+ for (;;) {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the next match, plus MIN_MATCH bytes to insert the
+ * string following the next match.
+ */
+ if (s->lookahead < MIN_LOOKAHEAD) {
+ fill_window(s);
+ if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+ return need_more;
+ }
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+
+ /* Insert the string window[strstart .. strstart+2] in the
+ * dictionary, and set hash_head to the head of the hash chain:
+ */
+ if (s->lookahead >= MIN_MATCH) {
+ INSERT_STRING(s, s->strstart, hash_head);
+ }
+
+ /* Find the longest match, discarding those <= prev_length.
+ */
+ s->prev_length = s->match_length, s->prev_match = s->match_start;
+ s->match_length = MIN_MATCH-1;
+
+ if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
+ s->strstart - hash_head <= MAX_DIST(s)) {
+ /* To simplify the code, we prevent matches with the string
+ * of window index 0 (in particular we have to avoid a match
+ * of the string with itself at the start of the input file).
+ */
+ if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
+ s->match_length = longest_match (s, hash_head);
+ } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
+ s->match_length = longest_match_fast (s, hash_head);
+ }
+ /* longest_match() or longest_match_fast() sets match_start */
+
+ if (s->match_length <= 5 && (s->strategy == Z_FILTERED
+#if TOO_FAR <= 32767
+ || (s->match_length == MIN_MATCH &&
+ s->strstart - s->match_start > TOO_FAR)
+#endif
+ )) {
+
+ /* If prev_match is also MIN_MATCH, match_start is garbage
+ * but we will ignore the current match anyway.
+ */
+ s->match_length = MIN_MATCH-1;
+ }
+ }
+ /* If there was a match at the previous step and the current
+ * match is not better, output the previous match:
+ */
+ if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
+ uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
+ /* Do not insert strings in hash table beyond this. */
+
+ check_match(s, s->strstart-1, s->prev_match, s->prev_length);
+
+ _tr_tally_dist(s, s->strstart -1 - s->prev_match,
+ s->prev_length - MIN_MATCH, bflush);
+
+ /* Insert in hash table all strings up to the end of the match.
+ * strstart-1 and strstart are already inserted. If there is not
+ * enough lookahead, the last two strings are not inserted in
+ * the hash table.
+ */
+ s->lookahead -= s->prev_length-1;
+ s->prev_length -= 2;
+ do {
+ if (++s->strstart <= max_insert) {
+ INSERT_STRING(s, s->strstart, hash_head);
+ }
+ } while (--s->prev_length != 0);
+ s->match_available = 0;
+ s->match_length = MIN_MATCH-1;
+ s->strstart++;
+
+ if (bflush) FLUSH_BLOCK(s, 0);
+
+ } else if (s->match_available) {
+ /* If there was no match at the previous position, output a
+ * single literal. If there was a match but the current match
+ * is longer, truncate the previous match to a single literal.
+ */
+ Tracevv((stderr,"%c", s->window[s->strstart-1]));
+ _tr_tally_lit(s, s->window[s->strstart-1], bflush);
+ if (bflush) {
+ FLUSH_BLOCK_ONLY(s, 0);
+ }
+ s->strstart++;
+ s->lookahead--;
+ if (s->strm->avail_out == 0) return need_more;
+ } else {
+ /* There is no previous match to compare with, wait for
+ * the next step to decide.
+ */
+ s->match_available = 1;
+ s->strstart++;
+ s->lookahead--;
+ }
+ }
+ Assert (flush != Z_NO_FLUSH, "no flush?");
+ if (s->match_available) {
+ Tracevv((stderr,"%c", s->window[s->strstart-1]));
+ _tr_tally_lit(s, s->window[s->strstart-1], bflush);
+ s->match_available = 0;
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+#endif /* FASTEST */
+
+#if 0
+/* ===========================================================================
+ * For Z_RLE, simply look for runs of bytes, generate matches only of distance
+ * one. Do not maintain a hash table. (It will be regenerated if this run of
+ * deflate switches away from Z_RLE.)
+ */
+local block_state deflate_rle(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ int bflush; /* set if current block must be flushed */
+ uInt run; /* length of run */
+ uInt max; /* maximum length of run */
+ uInt prev; /* byte at distance one to match */
+ Bytef *scan; /* scan for end of run */
+
+ for (;;) {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the longest encodable run.
+ */
+ if (s->lookahead < MAX_MATCH) {
+ fill_window(s);
+ if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
+ return need_more;
+ }
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+
+ /* See how many times the previous byte repeats */
+ run = 0;
+ if (s->strstart > 0) { /* if there is a previous byte, that is */
+ max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
+ scan = s->window + s->strstart - 1;
+ prev = *scan++;
+ do {
+ if (*scan++ != prev)
+ break;
+ } while (++run < max);
+ }
+
+ /* Emit match if have run of MIN_MATCH or longer, else emit literal */
+ if (run >= MIN_MATCH) {
+ check_match(s, s->strstart, s->strstart - 1, run);
+ _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
+ s->lookahead -= run;
+ s->strstart += run;
+ } else {
+ /* No match, output a literal byte */
+ Tracevv((stderr,"%c", s->window[s->strstart]));
+ _tr_tally_lit (s, s->window[s->strstart], bflush);
+ s->lookahead--;
+ s->strstart++;
+ }
+ if (bflush) FLUSH_BLOCK(s, 0);
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+#endif
diff --git a/Utilities/cmzlib/deflate.h b/Utilities/cmzlib/deflate.h
new file mode 100644
index 0000000000..05a5ab3a2c
--- /dev/null
+++ b/Utilities/cmzlib/deflate.h
@@ -0,0 +1,331 @@
+/* deflate.h -- internal compression state
+ * Copyright (C) 1995-2004 Jean-loup Gailly
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* @(#) $Id$ */
+
+#ifndef DEFLATE_H
+#define DEFLATE_H
+
+#include "zutil.h"
+
+/* define NO_GZIP when compiling if you want to disable gzip header and
+ trailer creation by deflate(). NO_GZIP would be used to avoid linking in
+ the crc code when it is not needed. For shared libraries, gzip encoding
+ should be left enabled. */
+#ifndef NO_GZIP
+# define GZIP
+#endif
+
+/* ===========================================================================
+ * Internal compression state.
+ */
+
+#define LENGTH_CODES 29
+/* number of length codes, not counting the special END_BLOCK code */
+
+#define LITERALS 256
+/* number of literal bytes 0..255 */
+
+#define L_CODES (LITERALS+1+LENGTH_CODES)
+/* number of Literal or Length codes, including the END_BLOCK code */
+
+#define D_CODES 30
+/* number of distance codes */
+
+#define BL_CODES 19
+/* number of codes used to transfer the bit lengths */
+
+#define HEAP_SIZE (2*L_CODES+1)
+/* maximum heap size */
+
+#define MAX_BITS 15
+/* All codes must not exceed MAX_BITS bits */
+
+#define INIT_STATE 42
+#define EXTRA_STATE 69
+#define NAME_STATE 73
+#define COMMENT_STATE 91
+#define HCRC_STATE 103
+#define BUSY_STATE 113
+#define FINISH_STATE 666
+/* Stream status */
+
+
+/* Data structure describing a single value and its code string. */
+typedef struct ct_data_s {
+ union {
+ ush freq; /* frequency count */
+ ush code; /* bit string */
+ } fc;
+ union {
+ ush dad; /* father node in Huffman tree */
+ ush len; /* length of bit string */
+ } dl;
+} FAR ct_data;
+
+#define Freq fc.freq
+#define Code fc.code
+#define Dad dl.dad
+#define Len dl.len
+
+typedef struct static_tree_desc_s static_tree_desc;
+
+typedef struct tree_desc_s {
+ ct_data *dyn_tree; /* the dynamic tree */
+ int max_code; /* largest code with non zero frequency */
+ static_tree_desc *stat_desc; /* the corresponding static tree */
+} FAR tree_desc;
+
+typedef ush Pos;
+typedef Pos FAR Posf;
+typedef unsigned IPos;
+
+/* A Pos is an index in the character window. We use short instead of int to
+ * save space in the various tables. IPos is used only for parameter passing.
+ */
+
+typedef struct internal_state {
+ z_streamp strm; /* pointer back to this zlib stream */
+ int status; /* as the name implies */
+ Bytef *pending_buf; /* output still pending */
+ ulg pending_buf_size; /* size of pending_buf */
+ Bytef *pending_out; /* next pending byte to output to the stream */
+ uInt pending; /* nb of bytes in the pending buffer */
+ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
+ gz_headerp gzhead; /* gzip header information to write */
+ uInt gzindex; /* where in extra, name, or comment */
+ Byte method; /* STORED (for zip only) or DEFLATED */
+ int last_flush; /* value of flush param for previous deflate call */
+
+ /* used by deflate.c: */
+
+ uInt w_size; /* LZ77 window size (32K by default) */
+ uInt w_bits; /* log2(w_size) (8..16) */
+ uInt w_mask; /* w_size - 1 */
+
+ Bytef *window;
+ /* Sliding window. Input bytes are read into the second half of the window,
+ * and move to the first half later to keep a dictionary of at least wSize
+ * bytes. With this organization, matches are limited to a distance of
+ * wSize-MAX_MATCH bytes, but this ensures that IO is always
+ * performed with a length multiple of the block size. Also, it limits
+ * the window size to 64K, which is quite useful on MSDOS.
+ * To do: use the user input buffer as sliding window.
+ */
+
+ ulg window_size;
+ /* Actual size of window: 2*wSize, except when the user input buffer
+ * is directly used as sliding window.
+ */
+
+ Posf *prev;
+ /* Link to older string with same hash index. To limit the size of this
+ * array to 64K, this link is maintained only for the last 32K strings.
+ * An index in this array is thus a window index modulo 32K.
+ */
+
+ Posf *head; /* Heads of the hash chains or NIL. */
+
+ uInt ins_h; /* hash index of string to be inserted */
+ uInt hash_size; /* number of elements in hash table */
+ uInt hash_bits; /* log2(hash_size) */
+ uInt hash_mask; /* hash_size-1 */
+
+ uInt hash_shift;
+ /* Number of bits by which ins_h must be shifted at each input
+ * step. It must be such that after MIN_MATCH steps, the oldest
+ * byte no longer takes part in the hash key, that is:
+ * hash_shift * MIN_MATCH >= hash_bits
+ */
+
+ long block_start;
+ /* Window position at the beginning of the current output block. Gets
+ * negative when the window is moved backwards.
+ */
+
+ uInt match_length; /* length of best match */
+ IPos prev_match; /* previous match */
+ int match_available; /* set if previous match exists */
+ uInt strstart; /* start of string to insert */
+ uInt match_start; /* start of matching string */
+ uInt lookahead; /* number of valid bytes ahead in window */
+
+ uInt prev_length;
+ /* Length of the best match at previous step. Matches not greater than this
+ * are discarded. This is used in the lazy match evaluation.
+ */
+
+ uInt max_chain_length;
+ /* To speed up deflation, hash chains are never searched beyond this
+ * length. A higher limit improves compression ratio but degrades the
+ * speed.
+ */
+
+ uInt max_lazy_match;
+ /* Attempt to find a better match only when the current match is strictly
+ * smaller than this value. This mechanism is used only for compression
+ * levels >= 4.
+ */
+# define max_insert_length max_lazy_match
+ /* Insert new strings in the hash table only if the match length is not
+ * greater than this length. This saves time but degrades compression.
+ * max_insert_length is used only for compression levels <= 3.
+ */
+
+ int level; /* compression level (1..9) */
+ int strategy; /* favor or force Huffman coding*/
+
+ uInt good_match;
+ /* Use a faster search when the previous match is longer than this */
+
+ int nice_match; /* Stop searching when current match exceeds this */
+
+ /* used by trees.c: */
+ /* Didn't use ct_data typedef below to supress compiler warning */
+ struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
+ struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
+ struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
+
+ struct tree_desc_s l_desc; /* desc. for literal tree */
+ struct tree_desc_s d_desc; /* desc. for distance tree */
+ struct tree_desc_s bl_desc; /* desc. for bit length tree */
+
+ ush bl_count[MAX_BITS+1];
+ /* number of codes at each bit length for an optimal tree */
+
+ int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
+ int heap_len; /* number of elements in the heap */
+ int heap_max; /* element of largest frequency */
+ /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
+ * The same heap array is used to build all trees.
+ */
+
+ uch depth[2*L_CODES+1];
+ /* Depth of each subtree used as tie breaker for trees of equal frequency
+ */
+
+ uchf *l_buf; /* buffer for literals or lengths */
+
+ uInt lit_bufsize;
+ /* Size of match buffer for literals/lengths. There are 4 reasons for
+ * limiting lit_bufsize to 64K:
+ * - frequencies can be kept in 16 bit counters
+ * - if compression is not successful for the first block, all input
+ * data is still in the window so we can still emit a stored block even
+ * when input comes from standard input. (This can also be done for
+ * all blocks if lit_bufsize is not greater than 32K.)
+ * - if compression is not successful for a file smaller than 64K, we can
+ * even emit a stored file instead of a stored block (saving 5 bytes).
+ * This is applicable only for zip (not gzip or zlib).
+ * - creating new Huffman trees less frequently may not provide fast
+ * adaptation to changes in the input data statistics. (Take for
+ * example a binary file with poorly compressible code followed by
+ * a highly compressible string table.) Smaller buffer sizes give
+ * fast adaptation but have of course the overhead of transmitting
+ * trees more frequently.
+ * - I can't count above 4
+ */
+
+ uInt last_lit; /* running index in l_buf */
+
+ ushf *d_buf;
+ /* Buffer for distances. To simplify the code, d_buf and l_buf have
+ * the same number of elements. To use different lengths, an extra flag
+ * array would be necessary.
+ */
+
+ ulg opt_len; /* bit length of current block with optimal trees */
+ ulg static_len; /* bit length of current block with static trees */
+ uInt matches; /* number of string matches in current block */
+ int last_eob_len; /* bit length of EOB code for last block */
+
+#ifdef DEBUG
+ ulg compressed_len; /* total bit length of compressed file mod 2^32 */
+ ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
+#endif
+
+ ush bi_buf;
+ /* Output buffer. bits are inserted starting at the bottom (least
+ * significant bits).
+ */
+ int bi_valid;
+ /* Number of valid bits in bi_buf. All bits above the last valid bit
+ * are always zero.
+ */
+
+} FAR deflate_state;
+
+/* Output a byte on the stream.
+ * IN assertion: there is enough room in pending_buf.
+ */
+#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
+
+
+#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
+/* Minimum amount of lookahead, except at the end of the input file.
+ * See deflate.c for comments about the MIN_MATCH+1.
+ */
+
+#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
+/* In order to simplify the code, particularly on 16 bit machines, match
+ * distances are limited to MAX_DIST instead of WSIZE.
+ */
+
+ /* in trees.c */
+void _tr_init OF((deflate_state *s));
+int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
+void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
+ int eof));
+void _tr_align OF((deflate_state *s));
+void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
+ int eof));
+
+#define d_code(dist) \
+ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
+/* Mapping from a distance to a distance code. dist is the distance - 1 and
+ * must not have side effects. _dist_code[256] and _dist_code[257] are never
+ * used.
+ */
+
+#ifndef DEBUG
+/* Inline versions of _tr_tally for speed: */
+
+#if defined(GEN_TREES_H) || !defined(STDC)
+ extern uch _length_code[];
+ extern uch _dist_code[];
+#else
+ extern const uch _length_code[];
+ extern const uch _dist_code[];
+#endif
+
+# define _tr_tally_lit(s, c, flush) \
+ { uch cc = (c); \
+ s->d_buf[s->last_lit] = 0; \
+ s->l_buf[s->last_lit++] = cc; \
+ s->dyn_ltree[cc].Freq++; \
+ flush = (s->last_lit == s->lit_bufsize-1); \
+ }
+# define _tr_tally_dist(s, distance, length, flush) \
+ { uch len = (length); \
+ ush dist = (distance); \
+ s->d_buf[s->last_lit] = dist; \
+ s->l_buf[s->last_lit++] = len; \
+ dist--; \
+ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
+ s->dyn_dtree[d_code(dist)].Freq++; \
+ flush = (s->last_lit == s->lit_bufsize-1); \
+ }
+#else
+# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
+# define _tr_tally_dist(s, distance, length, flush) \
+ flush = _tr_tally(s, distance, length)
+#endif
+
+#endif /* DEFLATE_H */
diff --git a/Utilities/cmzlib/gzio.c b/Utilities/cmzlib/gzio.c
new file mode 100644
index 0000000000..7e90f4928f
--- /dev/null
+++ b/Utilities/cmzlib/gzio.c
@@ -0,0 +1,1026 @@
+/* gzio.c -- IO on .gz files
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ *
+ * Compile this file with -DNO_GZCOMPRESS to avoid the compression code.
+ */
+
+/* @(#) $Id$ */
+
+#include <stdio.h>
+
+#include "zutil.h"
+
+#ifdef NO_DEFLATE /* for compatibility with old definition */
+# define NO_GZCOMPRESS
+#endif
+
+#ifndef NO_DUMMY_DECL
+struct internal_state {int dummy;}; /* for buggy compilers */
+#endif
+
+#ifndef Z_BUFSIZE
+# ifdef MAXSEG_64K
+# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
+# else
+# define Z_BUFSIZE 16384
+# endif
+#endif
+#ifndef Z_PRINTF_BUFSIZE
+# define Z_PRINTF_BUFSIZE 4096
+#endif
+
+#ifdef __MVS__
+# pragma map (fdopen , "\174\174FDOPEN")
+ FILE *fdopen(int, const char *);
+#endif
+
+#ifndef STDC
+extern voidp malloc OF((uInt size));
+extern void free OF((voidpf ptr));
+#endif
+
+#define ALLOC(size) malloc(size)
+#define TRYFREE(p) {if (p) free(p);}
+
+static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
+
+/* gzip flag byte */
+#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
+#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define COMMENT 0x10 /* bit 4 set: file comment present */
+#define RESERVED 0xE0 /* bits 5..7: reserved */
+
+typedef struct gz_stream {
+ z_stream stream;
+ int z_err; /* error code for last stream operation */
+ int z_eof; /* set if end of input file */
+ FILE *file; /* .gz file */
+ Byte *inbuf; /* input buffer */
+ Byte *outbuf; /* output buffer */
+ uLong crc; /* crc32 of uncompressed data */
+ char *msg; /* error message */
+ char *path; /* path name for debugging only */
+ int transparent; /* 1 if input file is not a .gz file */
+ char mode; /* 'w' or 'r' */
+ z_off_t start; /* start of compressed data in file (header skipped) */
+ z_off_t in; /* bytes into deflate or inflate */
+ z_off_t out; /* bytes out of deflate or inflate */
+ int back; /* one character push-back */
+ int last; /* true if push-back is last character */
+} gz_stream;
+
+
+local gzFile gz_open OF((const char *path, const char *mode, int fd));
+local int do_flush OF((gzFile file, int flush));
+local int get_byte OF((gz_stream *s));
+local void check_header OF((gz_stream *s));
+local int destroy OF((gz_stream *s));
+local void putLong OF((FILE *file, uLong x));
+local uLong getLong OF((gz_stream *s));
+
+/* ===========================================================================
+ Opens a gzip (.gz) file for reading or writing. The mode parameter
+ is as in fopen ("rb" or "wb"). The file is given either by file descriptor
+ or path name (if fd == -1).
+ gz_open returns NULL if the file could not be opened or if there was
+ insufficient memory to allocate the (de)compression state; errno
+ can be checked to distinguish the two cases (if errno is zero, the
+ zlib error is Z_MEM_ERROR).
+*/
+local gzFile gz_open (path, mode, fd)
+ const char *path;
+ const char *mode;
+ int fd;
+{
+ int err;
+ int level = Z_DEFAULT_COMPRESSION; /* compression level */
+ int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
+ char *p = (char*)mode;
+ gz_stream *s;
+ char fmode[80]; /* copy of mode, without the compression level */
+ char *m = fmode;
+
+ if (!path || !mode) return Z_NULL;
+
+ s = (gz_stream *)ALLOC(sizeof(gz_stream));
+ if (!s) return Z_NULL;
+
+ s->stream.zalloc = (alloc_func)0;
+ s->stream.zfree = (free_func)0;
+ s->stream.opaque = (voidpf)0;
+ s->stream.next_in = s->inbuf = Z_NULL;
+ s->stream.next_out = s->outbuf = Z_NULL;
+ s->stream.avail_in = s->stream.avail_out = 0;
+ s->file = NULL;
+ s->z_err = Z_OK;
+ s->z_eof = 0;
+ s->in = 0;
+ s->out = 0;
+ s->back = EOF;
+ s->crc = crc32(0L, Z_NULL, 0);
+ s->msg = NULL;
+ s->transparent = 0;
+
+ s->path = (char*)ALLOC(strlen(path)+1);
+ if (s->path == NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ strcpy(s->path, path); /* do this early for debugging */
+
+ s->mode = '\0';
+ do {
+ if (*p == 'r') s->mode = 'r';
+ if (*p == 'w' || *p == 'a') s->mode = 'w';
+ if (*p >= '0' && *p <= '9') {
+ level = *p - '0';
+ } else if (*p == 'f') {
+ strategy = Z_FILTERED;
+ } else if (*p == 'h') {
+ strategy = Z_HUFFMAN_ONLY;
+ } else if (*p == 'R') {
+ strategy = Z_RLE;
+ } else {
+ *m++ = *p; /* copy the mode */
+ }
+ } while (*p++ && m != fmode + sizeof(fmode));
+ if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
+
+ if (s->mode == 'w') {
+#ifdef NO_GZCOMPRESS
+ err = Z_STREAM_ERROR;
+#else
+ err = deflateInit2(&(s->stream), level,
+ Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
+ /* windowBits is passed < 0 to suppress zlib header */
+
+ s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
+#endif
+ if (err != Z_OK || s->outbuf == Z_NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ } else {
+ s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
+
+ err = inflateInit2(&(s->stream), -MAX_WBITS);
+ /* windowBits is passed < 0 to tell that there is no zlib header.
+ * Note that in this case inflate *requires* an extra "dummy" byte
+ * after the compressed stream in order to complete decompression and
+ * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
+ * present after the compressed stream.
+ */
+ if (err != Z_OK || s->inbuf == Z_NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ }
+ s->stream.avail_out = Z_BUFSIZE;
+
+ errno = 0;
+ s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
+
+ if (s->file == NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ if (s->mode == 'w') {
+ /* Write a very simple .gz header:
+ */
+ fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
+ Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
+ s->start = 10L;
+ /* We use 10L instead of ftell(s->file) to because ftell causes an
+ * fflush on some systems. This version of the library doesn't use
+ * start anyway in write mode, so this initialization is not
+ * necessary.
+ */
+ } else {
+ check_header(s); /* skip the .gz header */
+ s->start = ftell(s->file) - s->stream.avail_in;
+ }
+
+ return (gzFile)s;
+}
+
+/* ===========================================================================
+ Opens a gzip (.gz) file for reading or writing.
+*/
+gzFile ZEXPORT gzopen (path, mode)
+ const char *path;
+ const char *mode;
+{
+ return gz_open (path, mode, -1);
+}
+
+/* ===========================================================================
+ Associate a gzFile with the file descriptor fd. fd is not dup'ed here
+ to mimic the behavio(u)r of fdopen.
+*/
+gzFile ZEXPORT gzdopen (fd, mode)
+ int fd;
+ const char *mode;
+{
+ char name[46]; /* allow for up to 128-bit integers */
+
+ if (fd < 0) return (gzFile)Z_NULL;
+ sprintf(name, "<fd:%d>", fd); /* for debugging */
+
+ return gz_open (name, mode, fd);
+}
+
+/* ===========================================================================
+ * Update the compression level and strategy
+ */
+int ZEXPORT gzsetparams (file, level, strategy)
+ gzFile file;
+ int level;
+ int strategy;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
+
+ /* Make room to allow flushing */
+ if (s->stream.avail_out == 0) {
+
+ s->stream.next_out = s->outbuf;
+ if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
+ s->z_err = Z_ERRNO;
+ }
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+
+ return deflateParams (&(s->stream), level, strategy);
+}
+
+/* ===========================================================================
+ Read a byte from a gz_stream; update next_in and avail_in. Return EOF
+ for end of file.
+ IN assertion: the stream s has been sucessfully opened for reading.
+*/
+local int get_byte(s)
+ gz_stream *s;
+{
+ if (s->z_eof) return EOF;
+ if (s->stream.avail_in == 0) {
+ errno = 0;
+ s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
+ if (s->stream.avail_in == 0) {
+ s->z_eof = 1;
+ if (ferror(s->file)) s->z_err = Z_ERRNO;
+ return EOF;
+ }
+ s->stream.next_in = s->inbuf;
+ }
+ s->stream.avail_in--;
+ return *(s->stream.next_in)++;
+}
+
+/* ===========================================================================
+ Check the gzip header of a gz_stream opened for reading. Set the stream
+ mode to transparent if the gzip magic header is not present; set s->err
+ to Z_DATA_ERROR if the magic header is present but the rest of the header
+ is incorrect.
+ IN assertion: the stream s has already been created sucessfully;
+ s->stream.avail_in is zero for the first time, but may be non-zero
+ for concatenated .gz files.
+*/
+local void check_header(s)
+ gz_stream *s;
+{
+ int method; /* method byte */
+ int flags; /* flags byte */
+ uInt len;
+ int c;
+
+ /* Assure two bytes in the buffer so we can peek ahead -- handle case
+ where first byte of header is at the end of the buffer after the last
+ gzip segment */
+ len = s->stream.avail_in;
+ if (len < 2) {
+ if (len) s->inbuf[0] = s->stream.next_in[0];
+ errno = 0;
+ len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
+ if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
+ s->stream.avail_in += len;
+ s->stream.next_in = s->inbuf;
+ if (s->stream.avail_in < 2) {
+ s->transparent = s->stream.avail_in;
+ return;
+ }
+ }
+
+ /* Peek ahead to check the gzip magic header */
+ if (s->stream.next_in[0] != gz_magic[0] ||
+ s->stream.next_in[1] != gz_magic[1]) {
+ s->transparent = 1;
+ return;
+ }
+ s->stream.avail_in -= 2;
+ s->stream.next_in += 2;
+
+ /* Check the rest of the gzip header */
+ method = get_byte(s);
+ flags = get_byte(s);
+ if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
+ s->z_err = Z_DATA_ERROR;
+ return;
+ }
+
+ /* Discard time, xflags and OS code: */
+ for (len = 0; len < 6; len++) (void)get_byte(s);
+
+ if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
+ len = (uInt)get_byte(s);
+ len += ((uInt)get_byte(s))<<8;
+ /* len is garbage if EOF but the loop below will quit anyway */
+ while (len-- != 0 && get_byte(s) != EOF) ;
+ }
+ if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
+ while ((c = get_byte(s)) != 0 && c != EOF) ;
+ }
+ if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
+ while ((c = get_byte(s)) != 0 && c != EOF) ;
+ }
+ if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
+ for (len = 0; len < 2; len++) (void)get_byte(s);
+ }
+ s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
+}
+
+ /* ===========================================================================
+ * Cleanup then free the given gz_stream. Return a zlib error code.
+ Try freeing in the reverse order of allocations.
+ */
+local int destroy (s)
+ gz_stream *s;
+{
+ int err = Z_OK;
+
+ if (!s) return Z_STREAM_ERROR;
+
+ TRYFREE(s->msg);
+
+ if (s->stream.state != NULL) {
+ if (s->mode == 'w') {
+#ifdef NO_GZCOMPRESS
+ err = Z_STREAM_ERROR;
+#else
+ err = deflateEnd(&(s->stream));
+#endif
+ } else if (s->mode == 'r') {
+ err = inflateEnd(&(s->stream));
+ }
+ }
+ if (s->file != NULL && fclose(s->file)) {
+#ifdef ESPIPE
+ if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
+#endif
+ err = Z_ERRNO;
+ }
+ if (s->z_err < 0) err = s->z_err;
+
+ TRYFREE(s->inbuf);
+ TRYFREE(s->outbuf);
+ TRYFREE(s->path);
+ TRYFREE(s);
+ return err;
+}
+
+/* ===========================================================================
+ Reads the given number of uncompressed bytes from the compressed file.
+ gzread returns the number of bytes actually read (0 for end of file).
+*/
+int ZEXPORT gzread (file, buf, len)
+ gzFile file;
+ voidp buf;
+ unsigned len;
+{
+ gz_stream *s = (gz_stream*)file;
+ Bytef *start = (Bytef*)buf; /* starting point for crc computation */
+ Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */
+
+ if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
+
+ if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
+ if (s->z_err == Z_STREAM_END) return 0; /* EOF */
+
+ next_out = (Byte*)buf;
+ s->stream.next_out = (Bytef*)buf;
+ s->stream.avail_out = len;
+
+ if (s->stream.avail_out && s->back != EOF) {
+ *next_out++ = s->back;
+ s->stream.next_out++;
+ s->stream.avail_out--;
+ s->back = EOF;
+ s->out++;
+ start++;
+ if (s->last) {
+ s->z_err = Z_STREAM_END;
+ return 1;
+ }
+ }
+
+ while (s->stream.avail_out != 0) {
+
+ if (s->transparent) {
+ /* Copy first the lookahead bytes: */
+ uInt n = s->stream.avail_in;
+ if (n > s->stream.avail_out) n = s->stream.avail_out;
+ if (n > 0) {
+ zmemcpy(s->stream.next_out, s->stream.next_in, n);
+ next_out += n;
+ s->stream.next_out = next_out;
+ s->stream.next_in += n;
+ s->stream.avail_out -= n;
+ s->stream.avail_in -= n;
+ }
+ if (s->stream.avail_out > 0) {
+ s->stream.avail_out -=
+ (uInt)fread(next_out, 1, s->stream.avail_out, s->file);
+ }
+ len -= s->stream.avail_out;
+ s->in += len;
+ s->out += len;
+ if (len == 0) s->z_eof = 1;
+ return (int)len;
+ }
+ if (s->stream.avail_in == 0 && !s->z_eof) {
+
+ errno = 0;
+ s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
+ if (s->stream.avail_in == 0) {
+ s->z_eof = 1;
+ if (ferror(s->file)) {
+ s->z_err = Z_ERRNO;
+ break;
+ }
+ }
+ s->stream.next_in = s->inbuf;
+ }
+ s->in += s->stream.avail_in;
+ s->out += s->stream.avail_out;
+ s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
+ s->in -= s->stream.avail_in;
+ s->out -= s->stream.avail_out;
+
+ if (s->z_err == Z_STREAM_END) {
+ /* Check CRC and original size */
+ s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
+ start = s->stream.next_out;
+
+ if (getLong(s) != s->crc) {
+ s->z_err = Z_DATA_ERROR;
+ } else {
+ (void)getLong(s);
+ /* The uncompressed length returned by above getlong() may be
+ * different from s->out in case of concatenated .gz files.
+ * Check for such files:
+ */
+ check_header(s);
+ if (s->z_err == Z_OK) {
+ inflateReset(&(s->stream));
+ s->crc = crc32(0L, Z_NULL, 0);
+ }
+ }
+ }
+ if (s->z_err != Z_OK || s->z_eof) break;
+ }
+ s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
+
+ if (len == s->stream.avail_out &&
+ (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO))
+ return -1;
+ return (int)(len - s->stream.avail_out);
+}
+
+
+/* ===========================================================================
+ Reads one byte from the compressed file. gzgetc returns this byte
+ or -1 in case of end of file or error.
+*/
+int ZEXPORT gzgetc(file)
+ gzFile file;
+{
+ unsigned char c;
+
+ return gzread(file, &c, 1) == 1 ? c : -1;
+}
+
+
+/* ===========================================================================
+ Push one byte back onto the stream.
+*/
+int ZEXPORT gzungetc(c, file)
+ int c;
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'r' || c == EOF || s->back != EOF) return EOF;
+ s->back = c;
+ s->out--;
+ s->last = (s->z_err == Z_STREAM_END);
+ if (s->last) s->z_err = Z_OK;
+ s->z_eof = 0;
+ return c;
+}
+
+
+/* ===========================================================================
+ Reads bytes from the compressed file until len-1 characters are
+ read, or a newline character is read and transferred to buf, or an
+ end-of-file condition is encountered. The string is then terminated
+ with a null character.
+ gzgets returns buf, or Z_NULL in case of error.
+
+ The current implementation is not optimized at all.
+*/
+char * ZEXPORT gzgets(file, buf, len)
+ gzFile file;
+ char *buf;
+ int len;
+{
+ char *b = buf;
+ if (buf == Z_NULL || len <= 0) return Z_NULL;
+
+ while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
+ *buf = '\0';
+ return b == buf && len > 0 ? Z_NULL : b;
+}
+
+
+#ifndef NO_GZCOMPRESS
+/* ===========================================================================
+ Writes the given number of uncompressed bytes into the compressed file.
+ gzwrite returns the number of bytes actually written (0 in case of error).
+*/
+int ZEXPORT gzwrite (file, buf, len)
+ gzFile file;
+ voidpc buf;
+ unsigned len;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
+
+ s->stream.next_in = (Bytef*)buf;
+ s->stream.avail_in = len;
+
+ while (s->stream.avail_in != 0) {
+
+ if (s->stream.avail_out == 0) {
+
+ s->stream.next_out = s->outbuf;
+ if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
+ s->z_err = Z_ERRNO;
+ break;
+ }
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+ s->in += s->stream.avail_in;
+ s->out += s->stream.avail_out;
+ s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
+ s->in -= s->stream.avail_in;
+ s->out -= s->stream.avail_out;
+ if (s->z_err != Z_OK) break;
+ }
+ s->crc = crc32(s->crc, (const Bytef *)buf, len);
+
+ return (int)(len - s->stream.avail_in);
+}
+
+
+/* ===========================================================================
+ Converts, formats, and writes the args to the compressed file under
+ control of the format string, as in fprintf. gzprintf returns the number of
+ uncompressed bytes actually written (0 in case of error).
+*/
+#ifdef STDC
+#include <stdarg.h>
+
+int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
+{
+ char buf[Z_PRINTF_BUFSIZE];
+ va_list va;
+ int len;
+
+ buf[sizeof(buf) - 1] = 0;
+ va_start(va, format);
+#ifdef NO_vsnprintf
+# ifdef HAS_vsprintf_void
+ (void)vsprintf(buf, format, va);
+ va_end(va);
+ for (len = 0; len < sizeof(buf); len++)
+ if (buf[len] == 0) break;
+# else
+ len = vsprintf(buf, format, va);
+ va_end(va);
+# endif
+#else
+# ifdef HAS_vsnprintf_void
+ (void)vsnprintf(buf, sizeof(buf), format, va);
+ va_end(va);
+ len = strlen(buf);
+# else
+ len = vsnprintf(buf, sizeof(buf), format, va);
+ va_end(va);
+# endif
+#endif
+ if (len <= 0 || len >= (int)sizeof(buf) || buf[sizeof(buf) - 1] != 0)
+ return 0;
+ return gzwrite(file, buf, (unsigned)len);
+}
+#else /* not ANSI C */
+
+int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
+ a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
+ gzFile file;
+ const char *format;
+ int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
+ a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
+{
+ char buf[Z_PRINTF_BUFSIZE];
+ int len;
+
+ buf[sizeof(buf) - 1] = 0;
+#ifdef NO_snprintf
+# ifdef HAS_sprintf_void
+ sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+ for (len = 0; len < sizeof(buf); len++)
+ if (buf[len] == 0) break;
+# else
+ len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+# endif
+#else
+# ifdef HAS_snprintf_void
+ snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+ len = strlen(buf);
+# else
+ len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+# endif
+#endif
+ if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0)
+ return 0;
+ return gzwrite(file, buf, len);
+}
+#endif
+
+/* ===========================================================================
+ Writes c, converted to an unsigned char, into the compressed file.
+ gzputc returns the value that was written, or -1 in case of error.
+*/
+int ZEXPORT gzputc(file, c)
+ gzFile file;
+ int c;
+{
+ unsigned char cc = (unsigned char) c; /* required for big endian systems */
+
+ return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1;
+}
+
+
+/* ===========================================================================
+ Writes the given null-terminated string to the compressed file, excluding
+ the terminating null character.
+ gzputs returns the number of characters written, or -1 in case of error.
+*/
+int ZEXPORT gzputs(file, s)
+ gzFile file;
+ const char *s;
+{
+ return gzwrite(file, (char*)s, (unsigned)strlen(s));
+}
+
+
+/* ===========================================================================
+ Flushes all pending output into the compressed file. The parameter
+ flush is as in the deflate() function.
+*/
+local int do_flush (file, flush)
+ gzFile file;
+ int flush;
+{
+ uInt len;
+ int done = 0;
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
+
+ s->stream.avail_in = 0; /* should be zero already anyway */
+
+ for (;;) {
+ len = Z_BUFSIZE - s->stream.avail_out;
+
+ if (len != 0) {
+ if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
+ s->z_err = Z_ERRNO;
+ return Z_ERRNO;
+ }
+ s->stream.next_out = s->outbuf;
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+ if (done) break;
+ s->out += s->stream.avail_out;
+ s->z_err = deflate(&(s->stream), flush);
+ s->out -= s->stream.avail_out;
+
+ /* Ignore the second of two consecutive flushes: */
+ if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
+
+ /* deflate has finished flushing only when it hasn't used up
+ * all the available space in the output buffer:
+ */
+ done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
+
+ if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
+ }
+ return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
+}
+
+int ZEXPORT gzflush (file, flush)
+ gzFile file;
+ int flush;
+{
+ gz_stream *s = (gz_stream*)file;
+ int err = do_flush (file, flush);
+
+ if (err) return err;
+ fflush(s->file);
+ return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
+}
+#endif /* NO_GZCOMPRESS */
+
+/* ===========================================================================
+ Sets the starting position for the next gzread or gzwrite on the given
+ compressed file. The offset represents a number of bytes in the
+ gzseek returns the resulting offset location as measured in bytes from
+ the beginning of the uncompressed stream, or -1 in case of error.
+ SEEK_END is not implemented, returns error.
+ In this version of the library, gzseek can be extremely slow.
+*/
+z_off_t ZEXPORT gzseek (file, offset, whence)
+ gzFile file;
+ z_off_t offset;
+ int whence;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || whence == SEEK_END ||
+ s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
+ return -1L;
+ }
+
+ if (s->mode == 'w') {
+#ifdef NO_GZCOMPRESS
+ return -1L;
+#else
+ if (whence == SEEK_SET) {
+ offset -= s->in;
+ }
+ if (offset < 0) return -1L;
+
+ /* At this point, offset is the number of zero bytes to write. */
+ if (s->inbuf == Z_NULL) {
+ s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
+ if (s->inbuf == Z_NULL) return -1L;
+ zmemzero(s->inbuf, Z_BUFSIZE);
+ }
+ while (offset > 0) {
+ uInt size = Z_BUFSIZE;
+ if (offset < Z_BUFSIZE) size = (uInt)offset;
+
+ size = gzwrite(file, s->inbuf, size);
+ if (size == 0) return -1L;
+
+ offset -= size;
+ }
+ return s->in;
+#endif
+ }
+ /* Rest of function is for reading only */
+
+ /* compute absolute position */
+ if (whence == SEEK_CUR) {
+ offset += s->out;
+ }
+ if (offset < 0) return -1L;
+
+ if (s->transparent) {
+ /* map to fseek */
+ s->back = EOF;
+ s->stream.avail_in = 0;
+ s->stream.next_in = s->inbuf;
+ if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
+
+ s->in = s->out = offset;
+ return offset;
+ }
+
+ /* For a negative seek, rewind and use positive seek */
+ if (offset >= s->out) {
+ offset -= s->out;
+ } else if (gzrewind(file) < 0) {
+ return -1L;
+ }
+ /* offset is now the number of bytes to skip. */
+
+ if (offset != 0 && s->outbuf == Z_NULL) {
+ s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
+ if (s->outbuf == Z_NULL) return -1L;
+ }
+ if (offset && s->back != EOF) {
+ s->back = EOF;
+ s->out++;
+ offset--;
+ if (s->last) s->z_err = Z_STREAM_END;
+ }
+ while (offset > 0) {
+ int size = Z_BUFSIZE;
+ if (offset < Z_BUFSIZE) size = (int)offset;
+
+ size = gzread(file, s->outbuf, (uInt)size);
+ if (size <= 0) return -1L;
+ offset -= size;
+ }
+ return s->out;
+}
+
+/* ===========================================================================
+ Rewinds input file.
+*/
+int ZEXPORT gzrewind (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'r') return -1;
+
+ s->z_err = Z_OK;
+ s->z_eof = 0;
+ s->back = EOF;
+ s->stream.avail_in = 0;
+ s->stream.next_in = s->inbuf;
+ s->crc = crc32(0L, Z_NULL, 0);
+ if (!s->transparent) (void)inflateReset(&s->stream);
+ s->in = 0;
+ s->out = 0;
+ return fseek(s->file, s->start, SEEK_SET);
+}
+
+/* ===========================================================================
+ Returns the starting position for the next gzread or gzwrite on the
+ given compressed file. This position represents a number of bytes in the
+ uncompressed data stream.
+*/
+z_off_t ZEXPORT gztell (file)
+ gzFile file;
+{
+ return gzseek(file, 0L, SEEK_CUR);
+}
+
+/* ===========================================================================
+ Returns 1 when EOF has previously been detected reading the given
+ input stream, otherwise zero.
+*/
+int ZEXPORT gzeof (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ /* With concatenated compressed files that can have embedded
+ * crc trailers, z_eof is no longer the only/best indicator of EOF
+ * on a gz_stream. Handle end-of-stream error explicitly here.
+ */
+ if (s == NULL || s->mode != 'r') return 0;
+ if (s->z_eof) return 1;
+ return s->z_err == Z_STREAM_END;
+}
+
+/* ===========================================================================
+ Returns 1 if reading and doing so transparently, otherwise zero.
+*/
+int ZEXPORT gzdirect (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'r') return 0;
+ return s->transparent;
+}
+
+/* ===========================================================================
+ Outputs a long in LSB order to the given file
+*/
+local void putLong (file, x)
+ FILE *file;
+ uLong x;
+{
+ int n;
+ for (n = 0; n < 4; n++) {
+ fputc((int)(x & 0xff), file);
+ x >>= 8;
+ }
+}
+
+/* ===========================================================================
+ Reads a long in LSB order from the given gz_stream. Sets z_err in case
+ of error.
+*/
+local uLong getLong (s)
+ gz_stream *s;
+{
+ uLong x = (uLong)get_byte(s);
+ int c;
+
+ x += ((uLong)get_byte(s))<<8;
+ x += ((uLong)get_byte(s))<<16;
+ c = get_byte(s);
+ if (c == EOF) s->z_err = Z_DATA_ERROR;
+ x += ((uLong)c)<<24;
+ return x;
+}
+
+/* ===========================================================================
+ Flushes all pending output if necessary, closes the compressed file
+ and deallocates all the (de)compression state.
+*/
+int ZEXPORT gzclose (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL) return Z_STREAM_ERROR;
+
+ if (s->mode == 'w') {
+#ifdef NO_GZCOMPRESS
+ return Z_STREAM_ERROR;
+#else
+ if (do_flush (file, Z_FINISH) != Z_OK)
+ return destroy((gz_stream*)file);
+
+ putLong (s->file, s->crc);
+ putLong (s->file, (uLong)(s->in & 0xffffffff));
+#endif
+ }
+ return destroy((gz_stream*)file);
+}
+
+#ifdef STDC
+# define zstrerror(errnum) strerror(errnum)
+#else
+# define zstrerror(errnum) ""
+#endif
+
+/* ===========================================================================
+ Returns the error message for the last error which occurred on the
+ given compressed file. errnum is set to zlib error number. If an
+ error occurred in the file system and not in the compression library,
+ errnum is set to Z_ERRNO and the application may consult errno
+ to get the exact error code.
+*/
+const char * ZEXPORT gzerror (file, errnum)
+ gzFile file;
+ int *errnum;
+{
+ char *m;
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL) {
+ *errnum = Z_STREAM_ERROR;
+ return (const char*)ERR_MSG(Z_STREAM_ERROR);
+ }
+ *errnum = s->z_err;
+ if (*errnum == Z_OK) return (const char*)"";
+
+ m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
+
+ if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
+
+ TRYFREE(s->msg);
+ s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
+ if (s->msg == Z_NULL) return (const char*)ERR_MSG(Z_MEM_ERROR);
+ strcpy(s->msg, s->path);
+ strcat(s->msg, ": ");
+ strcat(s->msg, m);
+ return (const char*)s->msg;
+}
+
+/* ===========================================================================
+ Clear the error and end-of-file flags, and do the same for the real file.
+*/
+void ZEXPORT gzclearerr (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL) return;
+ if (s->z_err != Z_STREAM_END) s->z_err = Z_OK;
+ s->z_eof = 0;
+ clearerr(s->file);
+}
diff --git a/Utilities/cmzlib/inffast.c b/Utilities/cmzlib/inffast.c
new file mode 100644
index 0000000000..bbee92ed1e
--- /dev/null
+++ b/Utilities/cmzlib/inffast.c
@@ -0,0 +1,318 @@
+/* inffast.c -- fast decoding
+ * Copyright (C) 1995-2004 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+#include "inffast.h"
+
+#ifndef ASMINF
+
+/* Allow machine dependent optimization for post-increment or pre-increment.
+ Based on testing to date,
+ Pre-increment preferred for:
+ - PowerPC G3 (Adler)
+ - MIPS R5000 (Randers-Pehrson)
+ Post-increment preferred for:
+ - none
+ No measurable difference:
+ - Pentium III (Anderson)
+ - M68060 (Nikl)
+ */
+#ifdef POSTINC
+# define OFF 0
+# define PUP(a) *(a)++
+#else
+# define OFF 1
+# define PUP(a) *++(a)
+#endif
+
+/*
+ Decode literal, length, and distance codes and write out the resulting
+ literal and match bytes until either not enough input or output is
+ available, an end-of-block is encountered, or a data error is encountered.
+ When large enough input and output buffers are supplied to inflate(), for
+ example, a 16K input buffer and a 64K output buffer, more than 95% of the
+ inflate execution time is spent in this routine.
+
+ Entry assumptions:
+
+ state->mode == LEN
+ strm->avail_in >= 6
+ strm->avail_out >= 258
+ start >= strm->avail_out
+ state->bits < 8
+
+ On return, state->mode is one of:
+
+ LEN -- ran out of enough output space or enough available input
+ TYPE -- reached end of block code, inflate() to interpret next block
+ BAD -- error in block data
+
+ Notes:
+
+ - The maximum input bits used by a length/distance pair is 15 bits for the
+ length code, 5 bits for the length extra, 15 bits for the distance code,
+ and 13 bits for the distance extra. This totals 48 bits, or six bytes.
+ Therefore if strm->avail_in >= 6, then there is enough input to avoid
+ checking for available input while decoding.
+
+ - The maximum bytes that a single length/distance pair can output is 258
+ bytes, which is the maximum length that can be coded. inflate_fast()
+ requires strm->avail_out >= 258 for each loop to avoid checking for
+ output space.
+ */
+void inflate_fast(strm, start)
+z_streamp strm;
+unsigned start; /* inflate()'s starting value for strm->avail_out */
+{
+ struct inflate_state FAR *state;
+ unsigned char FAR *in; /* local strm->next_in */
+ unsigned char FAR *last; /* while in < last, enough input available */
+ unsigned char FAR *out; /* local strm->next_out */
+ unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
+ unsigned char FAR *end; /* while out < end, enough space available */
+#ifdef INFLATE_STRICT
+ unsigned dmax; /* maximum distance from zlib header */
+#endif
+ unsigned wsize; /* window size or zero if not using window */
+ unsigned whave; /* valid bytes in the window */
+ unsigned write; /* window write index */
+ unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
+ unsigned long hold; /* local strm->hold */
+ unsigned bits; /* local strm->bits */
+ code const FAR *lcode; /* local strm->lencode */
+ code const FAR *dcode; /* local strm->distcode */
+ unsigned lmask; /* mask for first level of length codes */
+ unsigned dmask; /* mask for first level of distance codes */
+ code this; /* retrieved table entry */
+ unsigned op; /* code bits, operation, extra bits, or */
+ /* window position, window bytes to copy */
+ unsigned len; /* match length, unused bytes */
+ unsigned dist; /* match distance */
+ unsigned char FAR *from; /* where to copy match from */
+
+ /* copy state to local variables */
+ state = (struct inflate_state FAR *)strm->state;
+ in = strm->next_in - OFF;
+ last = in + (strm->avail_in - 5);
+ out = strm->next_out - OFF;
+ beg = out - (start - strm->avail_out);
+ end = out + (strm->avail_out - 257);
+#ifdef INFLATE_STRICT
+ dmax = state->dmax;
+#endif
+ wsize = state->wsize;
+ whave = state->whave;
+ write = state->write;
+ window = state->window;
+ hold = state->hold;
+ bits = state->bits;
+ lcode = state->lencode;
+ dcode = state->distcode;
+ lmask = (1U << state->lenbits) - 1;
+ dmask = (1U << state->distbits) - 1;
+
+ /* decode literals and length/distances until end-of-block or not enough
+ input data or output space */
+ do {
+ if (bits < 15) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ }
+ this = lcode[hold & lmask];
+ dolen:
+ op = (unsigned)(this.bits);
+ hold >>= op;
+ bits -= op;
+ op = (unsigned)(this.op);
+ if (op == 0) { /* literal */
+ Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
+ "inflate: literal '%c'\n" :
+ "inflate: literal 0x%02x\n", this.val));
+ PUP(out) = (unsigned char)(this.val);
+ }
+ else if (op & 16) { /* length base */
+ len = (unsigned)(this.val);
+ op &= 15; /* number of extra bits */
+ if (op) {
+ if (bits < op) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ }
+ len += (unsigned)hold & ((1U << op) - 1);
+ hold >>= op;
+ bits -= op;
+ }
+ Tracevv((stderr, "inflate: length %u\n", len));
+ if (bits < 15) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ }
+ this = dcode[hold & dmask];
+ dodist:
+ op = (unsigned)(this.bits);
+ hold >>= op;
+ bits -= op;
+ op = (unsigned)(this.op);
+ if (op & 16) { /* distance base */
+ dist = (unsigned)(this.val);
+ op &= 15; /* number of extra bits */
+ if (bits < op) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ if (bits < op) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ }
+ }
+ dist += (unsigned)hold & ((1U << op) - 1);
+#ifdef INFLATE_STRICT
+ if (dist > dmax) {
+ strm->msg = (char *)"invalid distance too far back";
+ state->mode = BAD;
+ break;
+ }
+#endif
+ hold >>= op;
+ bits -= op;
+ Tracevv((stderr, "inflate: distance %u\n", dist));
+ op = (unsigned)(out - beg); /* max distance in output */
+ if (dist > op) { /* see if copy from window */
+ op = dist - op; /* distance back in window */
+ if (op > whave) {
+ strm->msg = (char *)"invalid distance too far back";
+ state->mode = BAD;
+ break;
+ }
+ from = window - OFF;
+ if (write == 0) { /* very common case */
+ from += wsize - op;
+ if (op < len) { /* some from window */
+ len -= op;
+ do {
+ PUP(out) = PUP(from);
+ } while (--op);
+ from = out - dist; /* rest from output */
+ }
+ }
+ else if (write < op) { /* wrap around window */
+ from += wsize + write - op;
+ op -= write;
+ if (op < len) { /* some from end of window */
+ len -= op;
+ do {
+ PUP(out) = PUP(from);
+ } while (--op);
+ from = window - OFF;
+ if (write < len) { /* some from start of window */
+ op = write;
+ len -= op;
+ do {
+ PUP(out) = PUP(from);
+ } while (--op);
+ from = out - dist; /* rest from output */
+ }
+ }
+ }
+ else { /* contiguous in window */
+ from += write - op;
+ if (op < len) { /* some from window */
+ len -= op;
+ do {
+ PUP(out) = PUP(from);
+ } while (--op);
+ from = out - dist; /* rest from output */
+ }
+ }
+ while (len > 2) {
+ PUP(out) = PUP(from);
+ PUP(out) = PUP(from);
+ PUP(out) = PUP(from);
+ len -= 3;
+ }
+ if (len) {
+ PUP(out) = PUP(from);
+ if (len > 1)
+ PUP(out) = PUP(from);
+ }
+ }
+ else {
+ from = out - dist; /* copy direct from output */
+ do { /* minimum length is three */
+ PUP(out) = PUP(from);
+ PUP(out) = PUP(from);
+ PUP(out) = PUP(from);
+ len -= 3;
+ } while (len > 2);
+ if (len) {
+ PUP(out) = PUP(from);
+ if (len > 1)
+ PUP(out) = PUP(from);
+ }
+ }
+ }
+ else if ((op & 64) == 0) { /* 2nd level distance code */
+ this = dcode[this.val + (hold & ((1U << op) - 1))];
+ goto dodist;
+ }
+ else {
+ strm->msg = (char *)"invalid distance code";
+ state->mode = BAD;
+ break;
+ }
+ }
+ else if ((op & 64) == 0) { /* 2nd level length code */
+ this = lcode[this.val + (hold & ((1U << op) - 1))];
+ goto dolen;
+ }
+ else if (op & 32) { /* end-of-block */
+ Tracevv((stderr, "inflate: end of block\n"));
+ state->mode = TYPE;
+ break;
+ }
+ else {
+ strm->msg = (char *)"invalid literal/length code";
+ state->mode = BAD;
+ break;
+ }
+ } while (in < last && out < end);
+
+ /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
+ len = bits >> 3;
+ in -= len;
+ bits -= len << 3;
+ hold &= (1U << bits) - 1;
+
+ /* update state and return */
+ strm->next_in = in + OFF;
+ strm->next_out = out + OFF;
+ strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
+ strm->avail_out = (unsigned)(out < end ?
+ 257 + (end - out) : 257 - (out - end));
+ state->hold = hold;
+ state->bits = bits;
+ return;
+}
+
+/*
+ inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
+ - Using bit fields for code structure
+ - Different op definition to avoid & for extra bits (do & for table bits)
+ - Three separate decoding do-loops for direct, window, and write == 0
+ - Special case for distance > 1 copies to do overlapped load and store copy
+ - Explicit branch predictions (based on measured branch probabilities)
+ - Deferring match copy and interspersed it with decoding subsequent codes
+ - Swapping literal/length else
+ - Swapping window/direct else
+ - Larger unrolled copy loops (three is about right)
+ - Moving len -= 3 statement into middle of loop
+ */
+
+#endif /* !ASMINF */
diff --git a/Utilities/cmzlib/inffast.h b/Utilities/cmzlib/inffast.h
new file mode 100644
index 0000000000..1e88d2d97b
--- /dev/null
+++ b/Utilities/cmzlib/inffast.h
@@ -0,0 +1,11 @@
+/* inffast.h -- header to use inffast.c
+ * Copyright (C) 1995-2003 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+void inflate_fast OF((z_streamp strm, unsigned start));
diff --git a/Utilities/cmzlib/inffixed.h b/Utilities/cmzlib/inffixed.h
new file mode 100644
index 0000000000..75ed4b5978
--- /dev/null
+++ b/Utilities/cmzlib/inffixed.h
@@ -0,0 +1,94 @@
+ /* inffixed.h -- table for decoding fixed codes
+ * Generated automatically by makefixed().
+ */
+
+ /* WARNING: this file should *not* be used by applications. It
+ is part of the implementation of the compression library and
+ is subject to change. Applications should only use zlib.h.
+ */
+
+ static const code lenfix[512] = {
+ {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
+ {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
+ {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
+ {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
+ {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
+ {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
+ {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
+ {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
+ {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
+ {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
+ {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
+ {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
+ {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
+ {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
+ {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
+ {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
+ {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
+ {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
+ {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
+ {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
+ {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
+ {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
+ {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
+ {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
+ {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
+ {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
+ {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
+ {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
+ {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
+ {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
+ {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
+ {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
+ {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
+ {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
+ {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
+ {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
+ {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
+ {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
+ {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
+ {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
+ {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
+ {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
+ {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
+ {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
+ {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
+ {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
+ {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
+ {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
+ {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
+ {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
+ {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
+ {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
+ {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
+ {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
+ {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
+ {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
+ {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
+ {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
+ {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
+ {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
+ {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
+ {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
+ {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
+ {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
+ {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
+ {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
+ {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
+ {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
+ {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
+ {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
+ {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
+ {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
+ {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
+ {0,9,255}
+ };
+
+ static const code distfix[32] = {
+ {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
+ {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
+ {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
+ {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
+ {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
+ {22,5,193},{64,5,0}
+ };
diff --git a/Utilities/cmzlib/inflate.c b/Utilities/cmzlib/inflate.c
new file mode 100644
index 0000000000..792fdee8e9
--- /dev/null
+++ b/Utilities/cmzlib/inflate.c
@@ -0,0 +1,1368 @@
+/* inflate.c -- zlib decompression
+ * Copyright (C) 1995-2005 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * Change history:
+ *
+ * 1.2.beta0 24 Nov 2002
+ * - First version -- complete rewrite of inflate to simplify code, avoid
+ * creation of window when not needed, minimize use of window when it is
+ * needed, make inffast.c even faster, implement gzip decoding, and to
+ * improve code readability and style over the previous zlib inflate code
+ *
+ * 1.2.beta1 25 Nov 2002
+ * - Use pointers for available input and output checking in inffast.c
+ * - Remove input and output counters in inffast.c
+ * - Change inffast.c entry and loop from avail_in >= 7 to >= 6
+ * - Remove unnecessary second byte pull from length extra in inffast.c
+ * - Unroll direct copy to three copies per loop in inffast.c
+ *
+ * 1.2.beta2 4 Dec 2002
+ * - Change external routine names to reduce potential conflicts
+ * - Correct filename to inffixed.h for fixed tables in inflate.c
+ * - Make hbuf[] unsigned char to match parameter type in inflate.c
+ * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
+ * to avoid negation problem on Alphas (64 bit) in inflate.c
+ *
+ * 1.2.beta3 22 Dec 2002
+ * - Add comments on state->bits assertion in inffast.c
+ * - Add comments on op field in inftrees.h
+ * - Fix bug in reuse of allocated window after inflateReset()
+ * - Remove bit fields--back to byte structure for speed
+ * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths
+ * - Change post-increments to pre-increments in inflate_fast(), PPC biased?
+ * - Add compile time option, POSTINC, to use post-increments instead (Intel?)
+ * - Make MATCH copy in inflate() much faster for when inflate_fast() not used
+ * - Use local copies of stream next and avail values, as well as local bit
+ * buffer and bit count in inflate()--for speed when inflate_fast() not used
+ *
+ * 1.2.beta4 1 Jan 2003
+ * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings
+ * - Move a comment on output buffer sizes from inffast.c to inflate.c
+ * - Add comments in inffast.c to introduce the inflate_fast() routine
+ * - Rearrange window copies in inflate_fast() for speed and simplification
+ * - Unroll last copy for window match in inflate_fast()
+ * - Use local copies of window variables in inflate_fast() for speed
+ * - Pull out common write == 0 case for speed in inflate_fast()
+ * - Make op and len in inflate_fast() unsigned for consistency
+ * - Add FAR to lcode and dcode declarations in inflate_fast()
+ * - Simplified bad distance check in inflate_fast()
+ * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new
+ * source file infback.c to provide a call-back interface to inflate for
+ * programs like gzip and unzip -- uses window as output buffer to avoid
+ * window copying
+ *
+ * 1.2.beta5 1 Jan 2003
+ * - Improved inflateBack() interface to allow the caller to provide initial
+ * input in strm.
+ * - Fixed stored blocks bug in inflateBack()
+ *
+ * 1.2.beta6 4 Jan 2003
+ * - Added comments in inffast.c on effectiveness of POSTINC
+ * - Typecasting all around to reduce compiler warnings
+ * - Changed loops from while (1) or do {} while (1) to for (;;), again to
+ * make compilers happy
+ * - Changed type of window in inflateBackInit() to unsigned char *
+ *
+ * 1.2.beta7 27 Jan 2003
+ * - Changed many types to unsigned or unsigned short to avoid warnings
+ * - Added inflateCopy() function
+ *
+ * 1.2.0 9 Mar 2003
+ * - Changed inflateBack() interface to provide separate opaque descriptors
+ * for the in() and out() functions
+ * - Changed inflateBack() argument and in_func typedef to swap the length
+ * and buffer address return values for the input function
+ * - Check next_in and next_out for Z_NULL on entry to inflate()
+ *
+ * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+#include "inffast.h"
+
+#ifdef MAKEFIXED
+# ifndef BUILDFIXED
+# define BUILDFIXED
+# endif
+#endif
+
+/* function prototypes */
+local void fixedtables OF((struct inflate_state FAR *state));
+local int updatewindow OF((z_streamp strm, unsigned out));
+#ifdef BUILDFIXED
+ void makefixed OF((void));
+#endif
+local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
+ unsigned len));
+
+int ZEXPORT inflateReset(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ strm->total_in = strm->total_out = state->total = 0;
+ strm->msg = Z_NULL;
+ strm->adler = 1; /* to support ill-conceived Java test suite */
+ state->mode = HEAD;
+ state->last = 0;
+ state->havedict = 0;
+ state->dmax = 32768U;
+ state->head = Z_NULL;
+ state->wsize = 0;
+ state->whave = 0;
+ state->write = 0;
+ state->hold = 0;
+ state->bits = 0;
+ state->lencode = state->distcode = state->next = state->codes;
+ Tracev((stderr, "inflate: reset\n"));
+ return Z_OK;
+}
+
+int ZEXPORT inflatePrime(strm, bits, value)
+z_streamp strm;
+int bits;
+int value;
+{
+ struct inflate_state FAR *state;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
+ value &= (1L << bits) - 1;
+ state->hold += value << state->bits;
+ state->bits += bits;
+ return Z_OK;
+}
+
+int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
+z_streamp strm;
+int windowBits;
+const char *version;
+int stream_size;
+{
+ struct inflate_state FAR *state;
+
+ if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
+ stream_size != (int)(sizeof(z_stream)))
+ return Z_VERSION_ERROR;
+ if (strm == Z_NULL) return Z_STREAM_ERROR;
+ strm->msg = Z_NULL; /* in case we return an error */
+ if (strm->zalloc == (alloc_func)0) {
+ strm->zalloc = zcalloc;
+ strm->opaque = (voidpf)0;
+ }
+ if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+ state = (struct inflate_state FAR *)
+ ZALLOC(strm, 1, sizeof(struct inflate_state));
+ if (state == Z_NULL) return Z_MEM_ERROR;
+ Tracev((stderr, "inflate: allocated\n"));
+ strm->state = (struct internal_state FAR *)state;
+ if (windowBits < 0) {
+ state->wrap = 0;
+ windowBits = -windowBits;
+ }
+ else {
+ state->wrap = (windowBits >> 4) + 1;
+#ifdef GUNZIP
+ if (windowBits < 48) windowBits &= 15;
+#endif
+ }
+ if (windowBits < 8 || windowBits > 15) {
+ ZFREE(strm, state);
+ strm->state = Z_NULL;
+ return Z_STREAM_ERROR;
+ }
+ state->wbits = (unsigned)windowBits;
+ state->window = Z_NULL;
+ return inflateReset(strm);
+}
+
+int ZEXPORT inflateInit_(strm, version, stream_size)
+z_streamp strm;
+const char *version;
+int stream_size;
+{
+ return inflateInit2_(strm, DEF_WBITS, version, stream_size);
+}
+
+/*
+ Return state with length and distance decoding tables and index sizes set to
+ fixed code decoding. Normally this returns fixed tables from inffixed.h.
+ If BUILDFIXED is defined, then instead this routine builds the tables the
+ first time it's called, and returns those tables the first time and
+ thereafter. This reduces the size of the code by about 2K bytes, in
+ exchange for a little execution time. However, BUILDFIXED should not be
+ used for threaded applications, since the rewriting of the tables and virgin
+ may not be thread-safe.
+ */
+local void fixedtables(state)
+struct inflate_state FAR *state;
+{
+#ifdef BUILDFIXED
+ static int virgin = 1;
+ static code *lenfix, *distfix;
+ static code fixed[544];
+
+ /* build fixed huffman tables if first call (may not be thread safe) */
+ if (virgin) {
+ unsigned sym, bits;
+ static code *next;
+
+ /* literal/length table */
+ sym = 0;
+ while (sym < 144) state->lens[sym++] = 8;
+ while (sym < 256) state->lens[sym++] = 9;
+ while (sym < 280) state->lens[sym++] = 7;
+ while (sym < 288) state->lens[sym++] = 8;
+ next = fixed;
+ lenfix = next;
+ bits = 9;
+ inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
+
+ /* distance table */
+ sym = 0;
+ while (sym < 32) state->lens[sym++] = 5;
+ distfix = next;
+ bits = 5;
+ inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
+
+ /* do this just once */
+ virgin = 0;
+ }
+#else /* !BUILDFIXED */
+# include "inffixed.h"
+#endif /* BUILDFIXED */
+ state->lencode = lenfix;
+ state->lenbits = 9;
+ state->distcode = distfix;
+ state->distbits = 5;
+}
+
+#ifdef MAKEFIXED
+#include <stdio.h>
+
+/*
+ Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also
+ defines BUILDFIXED, so the tables are built on the fly. makefixed() writes
+ those tables to stdout, which would be piped to inffixed.h. A small program
+ can simply call makefixed to do this:
+
+ void makefixed(void);
+
+ int main(void)
+ {
+ makefixed();
+ return 0;
+ }
+
+ Then that can be linked with zlib built with MAKEFIXED defined and run:
+
+ a.out > inffixed.h
+ */
+void makefixed()
+{
+ unsigned low, size;
+ struct inflate_state state;
+
+ fixedtables(&state);
+ puts(" /* inffixed.h -- table for decoding fixed codes");
+ puts(" * Generated automatically by makefixed().");
+ puts(" */");
+ puts("");
+ puts(" /* WARNING: this file should *not* be used by applications.");
+ puts(" It is part of the implementation of this library and is");
+ puts(" subject to change. Applications should only use zlib.h.");
+ puts(" */");
+ puts("");
+ size = 1U << 9;
+ printf(" static const code lenfix[%u] = {", size);
+ low = 0;
+ for (;;) {
+ if ((low % 7) == 0) printf("\n ");
+ printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
+ state.lencode[low].val);
+ if (++low == size) break;
+ putchar(',');
+ }
+ puts("\n };");
+ size = 1U << 5;
+ printf("\n static const code distfix[%u] = {", size);
+ low = 0;
+ for (;;) {
+ if ((low % 6) == 0) printf("\n ");
+ printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
+ state.distcode[low].val);
+ if (++low == size) break;
+ putchar(',');
+ }
+ puts("\n };");
+}
+#endif /* MAKEFIXED */
+
+/*
+ Update the window with the last wsize (normally 32K) bytes written before
+ returning. If window does not exist yet, create it. This is only called
+ when a window is already in use, or when output has been written during this
+ inflate call, but the end of the deflate stream has not been reached yet.
+ It is also called to create a window for dictionary data when a dictionary
+ is loaded.
+
+ Providing output buffers larger than 32K to inflate() should provide a speed
+ advantage, since only the last 32K of output is copied to the sliding window
+ upon return from inflate(), and since all distances after the first 32K of
+ output will fall in the output data, making match copies simpler and faster.
+ The advantage may be dependent on the size of the processor's data caches.
+ */
+local int updatewindow(strm, out)
+z_streamp strm;
+unsigned out;
+{
+ struct inflate_state FAR *state;
+ unsigned copy, dist;
+
+ state = (struct inflate_state FAR *)strm->state;
+
+ /* if it hasn't been done already, allocate space for the window */
+ if (state->window == Z_NULL) {
+ state->window = (unsigned char FAR *)
+ ZALLOC(strm, 1U << state->wbits,
+ sizeof(unsigned char));
+ if (state->window == Z_NULL) return 1;
+ }
+
+ /* if window not in use yet, initialize */
+ if (state->wsize == 0) {
+ state->wsize = 1U << state->wbits;
+ state->write = 0;
+ state->whave = 0;
+ }
+
+ /* copy state->wsize or less output bytes into the circular window */
+ copy = out - strm->avail_out;
+ if (copy >= state->wsize) {
+ zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
+ state->write = 0;
+ state->whave = state->wsize;
+ }
+ else {
+ dist = state->wsize - state->write;
+ if (dist > copy) dist = copy;
+ zmemcpy(state->window + state->write, strm->next_out - copy, dist);
+ copy -= dist;
+ if (copy) {
+ zmemcpy(state->window, strm->next_out - copy, copy);
+ state->write = copy;
+ state->whave = state->wsize;
+ }
+ else {
+ state->write += dist;
+ if (state->write == state->wsize) state->write = 0;
+ if (state->whave < state->wsize) state->whave += dist;
+ }
+ }
+ return 0;
+}
+
+/* Macros for inflate(): */
+
+/* check function to use adler32() for zlib or crc32() for gzip */
+#ifdef GUNZIP
+# define UPDATE(check, buf, len) \
+ (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
+#else
+# define UPDATE(check, buf, len) adler32(check, buf, len)
+#endif
+
+/* check macros for header crc */
+#ifdef GUNZIP
+# define CRC2(check, word) \
+ do { \
+ hbuf[0] = (unsigned char)(word); \
+ hbuf[1] = (unsigned char)((word) >> 8); \
+ check = crc32(check, hbuf, 2); \
+ } while (0)
+
+# define CRC4(check, word) \
+ do { \
+ hbuf[0] = (unsigned char)(word); \
+ hbuf[1] = (unsigned char)((word) >> 8); \
+ hbuf[2] = (unsigned char)((word) >> 16); \
+ hbuf[3] = (unsigned char)((word) >> 24); \
+ check = crc32(check, hbuf, 4); \
+ } while (0)
+#endif
+
+/* Load registers with state in inflate() for speed */
+#define LOAD() \
+ do { \
+ put = strm->next_out; \
+ left = strm->avail_out; \
+ next = strm->next_in; \
+ have = strm->avail_in; \
+ hold = state->hold; \
+ bits = state->bits; \
+ } while (0)
+
+/* Restore state from registers in inflate() */
+#define RESTORE() \
+ do { \
+ strm->next_out = put; \
+ strm->avail_out = left; \
+ strm->next_in = next; \
+ strm->avail_in = have; \
+ state->hold = hold; \
+ state->bits = bits; \
+ } while (0)
+
+/* Clear the input bit accumulator */
+#define INITBITS() \
+ do { \
+ hold = 0; \
+ bits = 0; \
+ } while (0)
+
+/* Get a byte of input into the bit accumulator, or return from inflate()
+ if there is no input available. */
+#define PULLBYTE() \
+ do { \
+ if (have == 0) goto inf_leave; \
+ have--; \
+ hold += (unsigned long)(*next++) << bits; \
+ bits += 8; \
+ } while (0)
+
+/* Assure that there are at least n bits in the bit accumulator. If there is
+ not enough available input to do that, then return from inflate(). */
+#define NEEDBITS(n) \
+ do { \
+ while (bits < (unsigned)(n)) \
+ PULLBYTE(); \
+ } while (0)
+
+/* Return the low n bits of the bit accumulator (n < 16) */
+#define BITS(n) \
+ ((unsigned)hold & ((1U << (n)) - 1))
+
+/* Remove n bits from the bit accumulator */
+#define DROPBITS(n) \
+ do { \
+ hold >>= (n); \
+ bits -= (unsigned)(n); \
+ } while (0)
+
+/* Remove zero to seven bits as needed to go to a byte boundary */
+#define BYTEBITS() \
+ do { \
+ hold >>= bits & 7; \
+ bits -= bits & 7; \
+ } while (0)
+
+/* Reverse the bytes in a 32-bit value */
+#define REVERSE(q) \
+ ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
+ (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
+
+/*
+ inflate() uses a state machine to process as much input data and generate as
+ much output data as possible before returning. The state machine is
+ structured roughly as follows:
+
+ for (;;) switch (state) {
+ ...
+ case STATEn:
+ if (not enough input data or output space to make progress)
+ return;
+ ... make progress ...
+ state = STATEm;
+ break;
+ ...
+ }
+
+ so when inflate() is called again, the same case is attempted again, and
+ if the appropriate resources are provided, the machine proceeds to the
+ next state. The NEEDBITS() macro is usually the way the state evaluates
+ whether it can proceed or should return. NEEDBITS() does the return if
+ the requested bits are not available. The typical use of the BITS macros
+ is:
+
+ NEEDBITS(n);
+ ... do something with BITS(n) ...
+ DROPBITS(n);
+
+ where NEEDBITS(n) either returns from inflate() if there isn't enough
+ input left to load n bits into the accumulator, or it continues. BITS(n)
+ gives the low n bits in the accumulator. When done, DROPBITS(n) drops
+ the low n bits off the accumulator. INITBITS() clears the accumulator
+ and sets the number of available bits to zero. BYTEBITS() discards just
+ enough bits to put the accumulator on a byte boundary. After BYTEBITS()
+ and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
+
+ NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
+ if there is no input available. The decoding of variable length codes uses
+ PULLBYTE() directly in order to pull just enough bytes to decode the next
+ code, and no more.
+
+ Some states loop until they get enough input, making sure that enough
+ state information is maintained to continue the loop where it left off
+ if NEEDBITS() returns in the loop. For example, want, need, and keep
+ would all have to actually be part of the saved state in case NEEDBITS()
+ returns:
+
+ case STATEw:
+ while (want < need) {
+ NEEDBITS(n);
+ keep[want++] = BITS(n);
+ DROPBITS(n);
+ }
+ state = STATEx;
+ case STATEx:
+
+ As shown above, if the next state is also the next case, then the break
+ is omitted.
+
+ A state may also return if there is not enough output space available to
+ complete that state. Those states are copying stored data, writing a
+ literal byte, and copying a matching string.
+
+ When returning, a "goto inf_leave" is used to update the total counters,
+ update the check value, and determine whether any progress has been made
+ during that inflate() call in order to return the proper return code.
+ Progress is defined as a change in either strm->avail_in or strm->avail_out.
+ When there is a window, goto inf_leave will update the window with the last
+ output written. If a goto inf_leave occurs in the middle of decompression
+ and there is no window currently, goto inf_leave will create one and copy
+ output to the window for the next call of inflate().
+
+ In this implementation, the flush parameter of inflate() only affects the
+ return code (per zlib.h). inflate() always writes as much as possible to
+ strm->next_out, given the space available and the provided input--the effect
+ documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers
+ the allocation of and copying into a sliding window until necessary, which
+ provides the effect documented in zlib.h for Z_FINISH when the entire input
+ stream available. So the only thing the flush parameter actually does is:
+ when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
+ will return Z_BUF_ERROR if it has not reached the end of the stream.
+ */
+
+int ZEXPORT inflate(strm, flush)
+z_streamp strm;
+int flush;
+{
+ struct inflate_state FAR *state;
+ unsigned char FAR *next; /* next input */
+ unsigned char FAR *put; /* next output */
+ unsigned have, left; /* available input and output */
+ unsigned long hold; /* bit buffer */
+ unsigned bits; /* bits in bit buffer */
+ unsigned in, out; /* save starting available input and output */
+ unsigned copy; /* number of stored or match bytes to copy */
+ unsigned char FAR *from; /* where to copy match bytes from */
+ code this; /* current decoding table entry */
+ code last; /* parent table entry */
+ unsigned len; /* length to copy for repeats, bits to drop */
+ int ret; /* return code */
+#ifdef GUNZIP
+ unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
+#endif
+ static const unsigned short order[19] = /* permutation of code lengths */
+ {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+
+ if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
+ (strm->next_in == Z_NULL && strm->avail_in != 0))
+ return Z_STREAM_ERROR;
+
+ state = (struct inflate_state FAR *)strm->state;
+ if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
+ LOAD();
+ in = have;
+ out = left;
+ ret = Z_OK;
+ for (;;)
+ switch (state->mode) {
+ case HEAD:
+ if (state->wrap == 0) {
+ state->mode = TYPEDO;
+ break;
+ }
+ NEEDBITS(16);
+#ifdef GUNZIP
+ if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
+ state->check = crc32(0L, Z_NULL, 0);
+ CRC2(state->check, hold);
+ INITBITS();
+ state->mode = FLAGS;
+ break;
+ }
+ state->flags = 0; /* expect zlib header */
+ if (state->head != Z_NULL)
+ state->head->done = -1;
+ if (!(state->wrap & 1) || /* check if zlib header allowed */
+#else
+ if (
+#endif
+ ((BITS(8) << 8) + (hold >> 8)) % 31) {
+ strm->msg = (char *)"incorrect header check";
+ state->mode = BAD;
+ break;
+ }
+ if (BITS(4) != Z_DEFLATED) {
+ strm->msg = (char *)"unknown compression method";
+ state->mode = BAD;
+ break;
+ }
+ DROPBITS(4);
+ len = BITS(4) + 8;
+ if (len > state->wbits) {
+ strm->msg = (char *)"invalid window size";
+ state->mode = BAD;
+ break;
+ }
+ state->dmax = 1U << len;
+ Tracev((stderr, "inflate: zlib header ok\n"));
+ strm->adler = state->check = adler32(0L, Z_NULL, 0);
+ state->mode = hold & 0x200 ? DICTID : TYPE;
+ INITBITS();
+ break;
+#ifdef GUNZIP
+ case FLAGS:
+ NEEDBITS(16);
+ state->flags = (int)(hold);
+ if ((state->flags & 0xff) != Z_DEFLATED) {
+ strm->msg = (char *)"unknown compression method";
+ state->mode = BAD;
+ break;
+ }
+ if (state->flags & 0xe000) {
+ strm->msg = (char *)"unknown header flags set";
+ state->mode = BAD;
+ break;
+ }
+ if (state->head != Z_NULL)
+ state->head->text = (int)((hold >> 8) & 1);
+ if (state->flags & 0x0200) CRC2(state->check, hold);
+ INITBITS();
+ state->mode = TIME;
+ case TIME:
+ NEEDBITS(32);
+ if (state->head != Z_NULL)
+ state->head->time = hold;
+ if (state->flags & 0x0200) CRC4(state->check, hold);
+ INITBITS();
+ state->mode = OS;
+ case OS:
+ NEEDBITS(16);
+ if (state->head != Z_NULL) {
+ state->head->xflags = (int)(hold & 0xff);
+ state->head->os = (int)(hold >> 8);
+ }
+ if (state->flags & 0x0200) CRC2(state->check, hold);
+ INITBITS();
+ state->mode = EXLEN;
+ case EXLEN:
+ if (state->flags & 0x0400) {
+ NEEDBITS(16);
+ state->length = (unsigned)(hold);
+ if (state->head != Z_NULL)
+ state->head->extra_len = (unsigned)hold;
+ if (state->flags & 0x0200) CRC2(state->check, hold);
+ INITBITS();
+ }
+ else if (state->head != Z_NULL)
+ state->head->extra = Z_NULL;
+ state->mode = EXTRA;
+ case EXTRA:
+ if (state->flags & 0x0400) {
+ copy = state->length;
+ if (copy > have) copy = have;
+ if (copy) {
+ if (state->head != Z_NULL &&
+ state->head->extra != Z_NULL) {
+ len = state->head->extra_len - state->length;
+ zmemcpy(state->head->extra + len, next,
+ len + copy > state->head->extra_max ?
+ state->head->extra_max - len : copy);
+ }
+ if (state->flags & 0x0200)
+ state->check = crc32(state->check, next, copy);
+ have -= copy;
+ next += copy;
+ state->length -= copy;
+ }
+ if (state->length) goto inf_leave;
+ }
+ state->length = 0;
+ state->mode = NAME;
+ case NAME:
+ if (state->flags & 0x0800) {
+ if (have == 0) goto inf_leave;
+ copy = 0;
+ do {
+ len = (unsigned)(next[copy++]);
+ if (state->head != Z_NULL &&
+ state->head->name != Z_NULL &&
+ state->length < state->head->name_max)
+ state->head->name[state->length++] = len;
+ } while (len && copy < have);
+ if (state->flags & 0x0200)
+ state->check = crc32(state->check, next, copy);
+ have -= copy;
+ next += copy;
+ if (len) goto inf_leave;
+ }
+ else if (state->head != Z_NULL)
+ state->head->name = Z_NULL;
+ state->length = 0;
+ state->mode = COMMENT;
+ case COMMENT:
+ if (state->flags & 0x1000) {
+ if (have == 0) goto inf_leave;
+ copy = 0;
+ do {
+ len = (unsigned)(next[copy++]);
+ if (state->head != Z_NULL &&
+ state->head->comment != Z_NULL &&
+ state->length < state->head->comm_max)
+ state->head->comment[state->length++] = len;
+ } while (len && copy < have);
+ if (state->flags & 0x0200)
+ state->check = crc32(state->check, next, copy);
+ have -= copy;
+ next += copy;
+ if (len) goto inf_leave;
+ }
+ else if (state->head != Z_NULL)
+ state->head->comment = Z_NULL;
+ state->mode = HCRC;
+ case HCRC:
+ if (state->flags & 0x0200) {
+ NEEDBITS(16);
+ if (hold != (state->check & 0xffff)) {
+ strm->msg = (char *)"header crc mismatch";
+ state->mode = BAD;
+ break;
+ }
+ INITBITS();
+ }
+ if (state->head != Z_NULL) {
+ state->head->hcrc = (int)((state->flags >> 9) & 1);
+ state->head->done = 1;
+ }
+ strm->adler = state->check = crc32(0L, Z_NULL, 0);
+ state->mode = TYPE;
+ break;
+#endif
+ case DICTID:
+ NEEDBITS(32);
+ strm->adler = state->check = REVERSE(hold);
+ INITBITS();
+ state->mode = DICT;
+ case DICT:
+ if (state->havedict == 0) {
+ RESTORE();
+ return Z_NEED_DICT;
+ }
+ strm->adler = state->check = adler32(0L, Z_NULL, 0);
+ state->mode = TYPE;
+ case TYPE:
+ if (flush == Z_BLOCK) goto inf_leave;
+ case TYPEDO:
+ if (state->last) {
+ BYTEBITS();
+ state->mode = CHECK;
+ break;
+ }
+ NEEDBITS(3);
+ state->last = BITS(1);
+ DROPBITS(1);
+ switch (BITS(2)) {
+ case 0: /* stored block */
+ Tracev((stderr, "inflate: stored block%s\n",
+ state->last ? " (last)" : ""));
+ state->mode = STORED;
+ break;
+ case 1: /* fixed block */
+ fixedtables(state);
+ Tracev((stderr, "inflate: fixed codes block%s\n",
+ state->last ? " (last)" : ""));
+ state->mode = LEN; /* decode codes */
+ break;
+ case 2: /* dynamic block */
+ Tracev((stderr, "inflate: dynamic codes block%s\n",
+ state->last ? " (last)" : ""));
+ state->mode = TABLE;
+ break;
+ case 3:
+ strm->msg = (char *)"invalid block type";
+ state->mode = BAD;
+ }
+ DROPBITS(2);
+ break;
+ case STORED:
+ BYTEBITS(); /* go to byte boundary */
+ NEEDBITS(32);
+ if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
+ strm->msg = (char *)"invalid stored block lengths";
+ state->mode = BAD;
+ break;
+ }
+ state->length = (unsigned)hold & 0xffff;
+ Tracev((stderr, "inflate: stored length %u\n",
+ state->length));
+ INITBITS();
+ state->mode = COPY;
+ case COPY:
+ copy = state->length;
+ if (copy) {
+ if (copy > have) copy = have;
+ if (copy > left) copy = left;
+ if (copy == 0) goto inf_leave;
+ zmemcpy(put, next, copy);
+ have -= copy;
+ next += copy;
+ left -= copy;
+ put += copy;
+ state->length -= copy;
+ break;
+ }
+ Tracev((stderr, "inflate: stored end\n"));
+ state->mode = TYPE;
+ break;
+ case TABLE:
+ NEEDBITS(14);
+ state->nlen = BITS(5) + 257;
+ DROPBITS(5);
+ state->ndist = BITS(5) + 1;
+ DROPBITS(5);
+ state->ncode = BITS(4) + 4;
+ DROPBITS(4);
+#ifndef PKZIP_BUG_WORKAROUND
+ if (state->nlen > 286 || state->ndist > 30) {
+ strm->msg = (char *)"too many length or distance symbols";
+ state->mode = BAD;
+ break;
+ }
+#endif
+ Tracev((stderr, "inflate: table sizes ok\n"));
+ state->have = 0;
+ state->mode = LENLENS;
+ case LENLENS:
+ while (state->have < state->ncode) {
+ NEEDBITS(3);
+ state->lens[order[state->have++]] = (unsigned short)BITS(3);
+ DROPBITS(3);
+ }
+ while (state->have < 19)
+ state->lens[order[state->have++]] = 0;
+ state->next = state->codes;
+ state->lencode = (code const FAR *)(state->next);
+ state->lenbits = 7;
+ ret = inflate_table(CODES, state->lens, 19, &(state->next),
+ &(state->lenbits), state->work);
+ if (ret) {
+ strm->msg = (char *)"invalid code lengths set";
+ state->mode = BAD;
+ break;
+ }
+ Tracev((stderr, "inflate: code lengths ok\n"));
+ state->have = 0;
+ state->mode = CODELENS;
+ case CODELENS:
+ while (state->have < state->nlen + state->ndist) {
+ for (;;) {
+ this = state->lencode[BITS(state->lenbits)];
+ if ((unsigned)(this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ if (this.val < 16) {
+ NEEDBITS(this.bits);
+ DROPBITS(this.bits);
+ state->lens[state->have++] = this.val;
+ }
+ else {
+ if (this.val == 16) {
+ NEEDBITS(this.bits + 2);
+ DROPBITS(this.bits);
+ if (state->have == 0) {
+ strm->msg = (char *)"invalid bit length repeat";
+ state->mode = BAD;
+ break;
+ }
+ len = state->lens[state->have - 1];
+ copy = 3 + BITS(2);
+ DROPBITS(2);
+ }
+ else if (this.val == 17) {
+ NEEDBITS(this.bits + 3);
+ DROPBITS(this.bits);
+ len = 0;
+ copy = 3 + BITS(3);
+ DROPBITS(3);
+ }
+ else {
+ NEEDBITS(this.bits + 7);
+ DROPBITS(this.bits);
+ len = 0;
+ copy = 11 + BITS(7);
+ DROPBITS(7);
+ }
+ if (state->have + copy > state->nlen + state->ndist) {
+ strm->msg = (char *)"invalid bit length repeat";
+ state->mode = BAD;
+ break;
+ }
+ while (copy--)
+ state->lens[state->have++] = (unsigned short)len;
+ }
+ }
+
+ /* handle error breaks in while */
+ if (state->mode == BAD) break;
+
+ /* build code tables */
+ state->next = state->codes;
+ state->lencode = (code const FAR *)(state->next);
+ state->lenbits = 9;
+ ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
+ &(state->lenbits), state->work);
+ if (ret) {
+ strm->msg = (char *)"invalid literal/lengths set";
+ state->mode = BAD;
+ break;
+ }
+ state->distcode = (code const FAR *)(state->next);
+ state->distbits = 6;
+ ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
+ &(state->next), &(state->distbits), state->work);
+ if (ret) {
+ strm->msg = (char *)"invalid distances set";
+ state->mode = BAD;
+ break;
+ }
+ Tracev((stderr, "inflate: codes ok\n"));
+ state->mode = LEN;
+ case LEN:
+ if (have >= 6 && left >= 258) {
+ RESTORE();
+ inflate_fast(strm, out);
+ LOAD();
+ break;
+ }
+ for (;;) {
+ this = state->lencode[BITS(state->lenbits)];
+ if ((unsigned)(this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ if (this.op && (this.op & 0xf0) == 0) {
+ last = this;
+ for (;;) {
+ this = state->lencode[last.val +
+ (BITS(last.bits + last.op) >> last.bits)];
+ if ((unsigned)(last.bits + this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ DROPBITS(last.bits);
+ }
+ DROPBITS(this.bits);
+ state->length = (unsigned)this.val;
+ if ((int)(this.op) == 0) {
+ Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
+ "inflate: literal '%c'\n" :
+ "inflate: literal 0x%02x\n", this.val));
+ state->mode = LIT;
+ break;
+ }
+ if (this.op & 32) {
+ Tracevv((stderr, "inflate: end of block\n"));
+ state->mode = TYPE;
+ break;
+ }
+ if (this.op & 64) {
+ strm->msg = (char *)"invalid literal/length code";
+ state->mode = BAD;
+ break;
+ }
+ state->extra = (unsigned)(this.op) & 15;
+ state->mode = LENEXT;
+ case LENEXT:
+ if (state->extra) {
+ NEEDBITS(state->extra);
+ state->length += BITS(state->extra);
+ DROPBITS(state->extra);
+ }
+ Tracevv((stderr, "inflate: length %u\n", state->length));
+ state->mode = DIST;
+ case DIST:
+ for (;;) {
+ this = state->distcode[BITS(state->distbits)];
+ if ((unsigned)(this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ if ((this.op & 0xf0) == 0) {
+ last = this;
+ for (;;) {
+ this = state->distcode[last.val +
+ (BITS(last.bits + last.op) >> last.bits)];
+ if ((unsigned)(last.bits + this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ DROPBITS(last.bits);
+ }
+ DROPBITS(this.bits);
+ if (this.op & 64) {
+ strm->msg = (char *)"invalid distance code";
+ state->mode = BAD;
+ break;
+ }
+ state->offset = (unsigned)this.val;
+ state->extra = (unsigned)(this.op) & 15;
+ state->mode = DISTEXT;
+ case DISTEXT:
+ if (state->extra) {
+ NEEDBITS(state->extra);
+ state->offset += BITS(state->extra);
+ DROPBITS(state->extra);
+ }
+#ifdef INFLATE_STRICT
+ if (state->offset > state->dmax) {
+ strm->msg = (char *)"invalid distance too far back";
+ state->mode = BAD;
+ break;
+ }
+#endif
+ if (state->offset > state->whave + out - left) {
+ strm->msg = (char *)"invalid distance too far back";
+ state->mode = BAD;
+ break;
+ }
+ Tracevv((stderr, "inflate: distance %u\n", state->offset));
+ state->mode = MATCH;
+ case MATCH:
+ if (left == 0) goto inf_leave;
+ copy = out - left;
+ if (state->offset > copy) { /* copy from window */
+ copy = state->offset - copy;
+ if (copy > state->write) {
+ copy -= state->write;
+ from = state->window + (state->wsize - copy);
+ }
+ else
+ from = state->window + (state->write - copy);
+ if (copy > state->length) copy = state->length;
+ }
+ else { /* copy from output */
+ from = put - state->offset;
+ copy = state->length;
+ }
+ if (copy > left) copy = left;
+ left -= copy;
+ state->length -= copy;
+ do {
+ *put++ = *from++;
+ } while (--copy);
+ if (state->length == 0) state->mode = LEN;
+ break;
+ case LIT:
+ if (left == 0) goto inf_leave;
+ *put++ = (unsigned char)(state->length);
+ left--;
+ state->mode = LEN;
+ break;
+ case CHECK:
+ if (state->wrap) {
+ NEEDBITS(32);
+ out -= left;
+ strm->total_out += out;
+ state->total += out;
+ if (out)
+ strm->adler = state->check =
+ UPDATE(state->check, put - out, out);
+ out = left;
+ if ((
+#ifdef GUNZIP
+ state->flags ? hold :
+#endif
+ REVERSE(hold)) != state->check) {
+ strm->msg = (char *)"incorrect data check";
+ state->mode = BAD;
+ break;
+ }
+ INITBITS();
+ Tracev((stderr, "inflate: check matches trailer\n"));
+ }
+#ifdef GUNZIP
+ state->mode = LENGTH;
+ case LENGTH:
+ if (state->wrap && state->flags) {
+ NEEDBITS(32);
+ if (hold != (state->total & 0xffffffffUL)) {
+ strm->msg = (char *)"incorrect length check";
+ state->mode = BAD;
+ break;
+ }
+ INITBITS();
+ Tracev((stderr, "inflate: length matches trailer\n"));
+ }
+#endif
+ state->mode = DONE;
+ case DONE:
+ ret = Z_STREAM_END;
+ goto inf_leave;
+ case BAD:
+ ret = Z_DATA_ERROR;
+ goto inf_leave;
+ case MEM:
+ return Z_MEM_ERROR;
+ case SYNC:
+ default:
+ return Z_STREAM_ERROR;
+ }
+
+ /*
+ Return from inflate(), updating the total counts and the check value.
+ If there was no progress during the inflate() call, return a buffer
+ error. Call updatewindow() to create and/or update the window state.
+ Note: a memory error from inflate() is non-recoverable.
+ */
+ inf_leave:
+ RESTORE();
+ if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
+ if (updatewindow(strm, out)) {
+ state->mode = MEM;
+ return Z_MEM_ERROR;
+ }
+ in -= strm->avail_in;
+ out -= strm->avail_out;
+ strm->total_in += in;
+ strm->total_out += out;
+ state->total += out;
+ if (state->wrap && out)
+ strm->adler = state->check =
+ UPDATE(state->check, strm->next_out - out, out);
+ strm->data_type = state->bits + (state->last ? 64 : 0) +
+ (state->mode == TYPE ? 128 : 0);
+ if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
+ ret = Z_BUF_ERROR;
+ return ret;
+}
+
+int ZEXPORT inflateEnd(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+ if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
+ return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (state->window != Z_NULL) ZFREE(strm, state->window);
+ ZFREE(strm, strm->state);
+ strm->state = Z_NULL;
+ Tracev((stderr, "inflate: end\n"));
+ return Z_OK;
+}
+
+int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
+z_streamp strm;
+const Bytef *dictionary;
+uInt dictLength;
+{
+ struct inflate_state FAR *state;
+ unsigned long id;
+
+ /* check state */
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (state->wrap != 0 && state->mode != DICT)
+ return Z_STREAM_ERROR;
+
+ /* check for correct dictionary id */
+ if (state->mode == DICT) {
+ id = adler32(0L, Z_NULL, 0);
+ id = adler32(id, dictionary, dictLength);
+ if (id != state->check)
+ return Z_DATA_ERROR;
+ }
+
+ /* copy dictionary to window */
+ if (updatewindow(strm, strm->avail_out)) {
+ state->mode = MEM;
+ return Z_MEM_ERROR;
+ }
+ if (dictLength > state->wsize) {
+ zmemcpy(state->window, dictionary + dictLength - state->wsize,
+ state->wsize);
+ state->whave = state->wsize;
+ }
+ else {
+ zmemcpy(state->window + state->wsize - dictLength, dictionary,
+ dictLength);
+ state->whave = dictLength;
+ }
+ state->havedict = 1;
+ Tracev((stderr, "inflate: dictionary set\n"));
+ return Z_OK;
+}
+
+int ZEXPORT inflateGetHeader(strm, head)
+z_streamp strm;
+gz_headerp head;
+{
+ struct inflate_state FAR *state;
+
+ /* check state */
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
+
+ /* save header structure */
+ state->head = head;
+ head->done = 0;
+ return Z_OK;
+}
+
+/*
+ Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found
+ or when out of input. When called, *have is the number of pattern bytes
+ found in order so far, in 0..3. On return *have is updated to the new
+ state. If on return *have equals four, then the pattern was found and the
+ return value is how many bytes were read including the last byte of the
+ pattern. If *have is less than four, then the pattern has not been found
+ yet and the return value is len. In the latter case, syncsearch() can be
+ called again with more data and the *have state. *have is initialized to
+ zero for the first call.
+ */
+local unsigned syncsearch(have, buf, len)
+unsigned FAR *have;
+unsigned char FAR *buf;
+unsigned len;
+{
+ unsigned got;
+ unsigned next;
+
+ got = *have;
+ next = 0;
+ while (next < len && got < 4) {
+ if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
+ got++;
+ else if (buf[next])
+ got = 0;
+ else
+ got = 4 - got;
+ next++;
+ }
+ *have = got;
+ return next;
+}
+
+int ZEXPORT inflateSync(strm)
+z_streamp strm;
+{
+ unsigned len; /* number of bytes to look at or looked at */
+ unsigned long in, out; /* temporary to save total_in and total_out */
+ unsigned char buf[4]; /* to restore bit buffer to byte string */
+ struct inflate_state FAR *state;
+
+ /* check parameters */
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
+
+ /* if first time, start search in bit buffer */
+ if (state->mode != SYNC) {
+ state->mode = SYNC;
+ state->hold <<= state->bits & 7;
+ state->bits -= state->bits & 7;
+ len = 0;
+ while (state->bits >= 8) {
+ buf[len++] = (unsigned char)(state->hold);
+ state->hold >>= 8;
+ state->bits -= 8;
+ }
+ state->have = 0;
+ syncsearch(&(state->have), buf, len);
+ }
+
+ /* search available input */
+ len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
+ strm->avail_in -= len;
+ strm->next_in += len;
+ strm->total_in += len;
+
+ /* return no joy or set up to restart inflate() on a new block */
+ if (state->have != 4) return Z_DATA_ERROR;
+ in = strm->total_in; out = strm->total_out;
+ inflateReset(strm);
+ strm->total_in = in; strm->total_out = out;
+ state->mode = TYPE;
+ return Z_OK;
+}
+
+/*
+ Returns true if inflate is currently at the end of a block generated by
+ Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
+ implementation to provide an additional safety check. PPP uses
+ Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
+ block. When decompressing, PPP checks that at the end of input packet,
+ inflate is waiting for these length bytes.
+ */
+int ZEXPORT inflateSyncPoint(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ return state->mode == STORED && state->bits == 0;
+}
+
+int ZEXPORT inflateCopy(dest, source)
+z_streamp dest;
+z_streamp source;
+{
+ struct inflate_state FAR *state;
+ struct inflate_state FAR *copy;
+ unsigned char FAR *window;
+ unsigned wsize;
+
+ /* check input */
+ if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
+ source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
+ return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)source->state;
+
+ /* allocate space */
+ copy = (struct inflate_state FAR *)
+ ZALLOC(source, 1, sizeof(struct inflate_state));
+ if (copy == Z_NULL) return Z_MEM_ERROR;
+ window = Z_NULL;
+ if (state->window != Z_NULL) {
+ window = (unsigned char FAR *)
+ ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
+ if (window == Z_NULL) {
+ ZFREE(source, copy);
+ return Z_MEM_ERROR;
+ }
+ }
+
+ /* copy state */
+ zmemcpy(dest, source, sizeof(z_stream));
+ zmemcpy(copy, state, sizeof(struct inflate_state));
+ if (state->lencode >= state->codes &&
+ state->lencode <= state->codes + ENOUGH - 1) {
+ copy->lencode = copy->codes + (state->lencode - state->codes);
+ copy->distcode = copy->codes + (state->distcode - state->codes);
+ }
+ copy->next = copy->codes + (state->next - state->codes);
+ if (window != Z_NULL) {
+ wsize = 1U << state->wbits;
+ zmemcpy(window, state->window, wsize);
+ }
+ copy->window = window;
+ dest->state = (struct internal_state FAR *)copy;
+ return Z_OK;
+}
diff --git a/Utilities/cmzlib/inflate.h b/Utilities/cmzlib/inflate.h
new file mode 100644
index 0000000000..07bd3e78a7
--- /dev/null
+++ b/Utilities/cmzlib/inflate.h
@@ -0,0 +1,115 @@
+/* inflate.h -- internal inflate state definition
+ * Copyright (C) 1995-2004 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* define NO_GZIP when compiling if you want to disable gzip header and
+ trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
+ the crc code when it is not needed. For shared libraries, gzip decoding
+ should be left enabled. */
+#ifndef NO_GZIP
+# define GUNZIP
+#endif
+
+/* Possible inflate modes between inflate() calls */
+typedef enum {
+ HEAD, /* i: waiting for magic header */
+ FLAGS, /* i: waiting for method and flags (gzip) */
+ TIME, /* i: waiting for modification time (gzip) */
+ OS, /* i: waiting for extra flags and operating system (gzip) */
+ EXLEN, /* i: waiting for extra length (gzip) */
+ EXTRA, /* i: waiting for extra bytes (gzip) */
+ NAME, /* i: waiting for end of file name (gzip) */
+ COMMENT, /* i: waiting for end of comment (gzip) */
+ HCRC, /* i: waiting for header crc (gzip) */
+ DICTID, /* i: waiting for dictionary check value */
+ DICT, /* waiting for inflateSetDictionary() call */
+ TYPE, /* i: waiting for type bits, including last-flag bit */
+ TYPEDO, /* i: same, but skip check to exit inflate on new block */
+ STORED, /* i: waiting for stored size (length and complement) */
+ COPY, /* i/o: waiting for input or output to copy stored block */
+ TABLE, /* i: waiting for dynamic block table lengths */
+ LENLENS, /* i: waiting for code length code lengths */
+ CODELENS, /* i: waiting for length/lit and distance code lengths */
+ LEN, /* i: waiting for length/lit code */
+ LENEXT, /* i: waiting for length extra bits */
+ DIST, /* i: waiting for distance code */
+ DISTEXT, /* i: waiting for distance extra bits */
+ MATCH, /* o: waiting for output space to copy string */
+ LIT, /* o: waiting for output space to write literal */
+ CHECK, /* i: waiting for 32-bit check value */
+ LENGTH, /* i: waiting for 32-bit length (gzip) */
+ DONE, /* finished check, done -- remain here until reset */
+ BAD, /* got a data error -- remain here until reset */
+ MEM, /* got an inflate() memory error -- remain here until reset */
+ SYNC /* looking for synchronization bytes to restart inflate() */
+} inflate_mode;
+
+/*
+ State transitions between above modes -
+
+ (most modes can go to the BAD or MEM mode -- not shown for clarity)
+
+ Process header:
+ HEAD -> (gzip) or (zlib)
+ (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
+ NAME -> COMMENT -> HCRC -> TYPE
+ (zlib) -> DICTID or TYPE
+ DICTID -> DICT -> TYPE
+ Read deflate blocks:
+ TYPE -> STORED or TABLE or LEN or CHECK
+ STORED -> COPY -> TYPE
+ TABLE -> LENLENS -> CODELENS -> LEN
+ Read deflate codes:
+ LEN -> LENEXT or LIT or TYPE
+ LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
+ LIT -> LEN
+ Process trailer:
+ CHECK -> LENGTH -> DONE
+ */
+
+/* state maintained between inflate() calls. Approximately 7K bytes. */
+struct inflate_state {
+ inflate_mode mode; /* current inflate mode */
+ int last; /* true if processing last block */
+ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
+ int havedict; /* true if dictionary provided */
+ int flags; /* gzip header method and flags (0 if zlib) */
+ unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
+ unsigned long check; /* protected copy of check value */
+ unsigned long total; /* protected copy of output count */
+ gz_headerp head; /* where to save gzip header information */
+ /* sliding window */
+ unsigned wbits; /* log base 2 of requested window size */
+ unsigned wsize; /* window size or zero if not using window */
+ unsigned whave; /* valid bytes in the window */
+ unsigned write; /* window write index */
+ unsigned char FAR *window; /* allocated sliding window, if needed */
+ /* bit accumulator */
+ unsigned long hold; /* input bit accumulator */
+ unsigned bits; /* number of bits in "in" */
+ /* for string and stored block copying */
+ unsigned length; /* literal or length of data to copy */
+ unsigned offset; /* distance back to copy string from */
+ /* for table and code decoding */
+ unsigned extra; /* extra bits needed */
+ /* fixed and dynamic code tables */
+ code const FAR *lencode; /* starting table for length/literal codes */
+ code const FAR *distcode; /* starting table for distance codes */
+ unsigned lenbits; /* index bits for lencode */
+ unsigned distbits; /* index bits for distcode */
+ /* dynamic table building */
+ unsigned ncode; /* number of code length code lengths */
+ unsigned nlen; /* number of length code lengths */
+ unsigned ndist; /* number of distance code lengths */
+ unsigned have; /* number of code lengths in lens[] */
+ code FAR *next; /* next available space in codes[] */
+ unsigned short lens[320]; /* temporary storage for code lengths */
+ unsigned short work[288]; /* work area for code table building */
+ code codes[ENOUGH]; /* space for code tables */
+};
diff --git a/Utilities/cmzlib/inftrees.c b/Utilities/cmzlib/inftrees.c
new file mode 100644
index 0000000000..8a9c13ff03
--- /dev/null
+++ b/Utilities/cmzlib/inftrees.c
@@ -0,0 +1,329 @@
+/* inftrees.c -- generate Huffman trees for efficient decoding
+ * Copyright (C) 1995-2005 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+
+#define MAXBITS 15
+
+const char inflate_copyright[] =
+ " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
+/*
+ If you use the zlib library in a product, an acknowledgment is welcome
+ in the documentation of your product. If for some reason you cannot
+ include such an acknowledgment, I would appreciate that you keep this
+ copyright string in the executable of your product.
+ */
+
+/*
+ Build a set of tables to decode the provided canonical Huffman code.
+ The code lengths are lens[0..codes-1]. The result starts at *table,
+ whose indices are 0..2^bits-1. work is a writable array of at least
+ lens shorts, which is used as a work area. type is the type of code
+ to be generated, CODES, LENS, or DISTS. On return, zero is success,
+ -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
+ on return points to the next available entry's address. bits is the
+ requested root table index bits, and on return it is the actual root
+ table index bits. It will differ if the request is greater than the
+ longest code or if it is less than the shortest code.
+ */
+int inflate_table(type, lens, codes, table, bits, work)
+codetype type;
+unsigned short FAR *lens;
+unsigned codes;
+code FAR * FAR *table;
+unsigned FAR *bits;
+unsigned short FAR *work;
+{
+ unsigned len; /* a code's length in bits */
+ unsigned sym; /* index of code symbols */
+ unsigned min, max; /* minimum and maximum code lengths */
+ unsigned root; /* number of index bits for root table */
+ unsigned curr; /* number of index bits for current table */
+ unsigned drop; /* code bits to drop for sub-table */
+ int left; /* number of prefix codes available */
+ unsigned used; /* code entries in table used */
+ unsigned huff; /* Huffman code */
+ unsigned incr; /* for incrementing code, index */
+ unsigned fill; /* index for replicating entries */
+ unsigned low; /* low bits for current root entry */
+ unsigned mask; /* mask for low root bits */
+ code this; /* table entry for duplication */
+ code FAR *next; /* next available space in table */
+ const unsigned short FAR *base; /* base value table to use */
+ const unsigned short FAR *extra; /* extra bits table to use */
+ int end; /* use base and extra for symbol > end */
+ unsigned short count[MAXBITS+1]; /* number of codes of each length */
+ unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
+ static const unsigned short lbase[31] = { /* Length codes 257..285 base */
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
+ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
+ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
+ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
+ 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
+ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
+ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
+ 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
+ 8193, 12289, 16385, 24577, 0, 0};
+ static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
+ 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
+ 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
+ 28, 28, 29, 29, 64, 64};
+
+ /*
+ Process a set of code lengths to create a canonical Huffman code. The
+ code lengths are lens[0..codes-1]. Each length corresponds to the
+ symbols 0..codes-1. The Huffman code is generated by first sorting the
+ symbols by length from short to long, and retaining the symbol order
+ for codes with equal lengths. Then the code starts with all zero bits
+ for the first code of the shortest length, and the codes are integer
+ increments for the same length, and zeros are appended as the length
+ increases. For the deflate format, these bits are stored backwards
+ from their more natural integer increment ordering, and so when the
+ decoding tables are built in the large loop below, the integer codes
+ are incremented backwards.
+
+ This routine assumes, but does not check, that all of the entries in
+ lens[] are in the range 0..MAXBITS. The caller must assure this.
+ 1..MAXBITS is interpreted as that code length. zero means that that
+ symbol does not occur in this code.
+
+ The codes are sorted by computing a count of codes for each length,
+ creating from that a table of starting indices for each length in the
+ sorted table, and then entering the symbols in order in the sorted
+ table. The sorted table is work[], with that space being provided by
+ the caller.
+
+ The length counts are used for other purposes as well, i.e. finding
+ the minimum and maximum length codes, determining if there are any
+ codes at all, checking for a valid set of lengths, and looking ahead
+ at length counts to determine sub-table sizes when building the
+ decoding tables.
+ */
+
+ /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
+ for (len = 0; len <= MAXBITS; len++)
+ count[len] = 0;
+ for (sym = 0; sym < codes; sym++)
+ count[lens[sym]]++;
+
+ /* bound code lengths, force root to be within code lengths */
+ root = *bits;
+ for (max = MAXBITS; max >= 1; max--)
+ if (count[max] != 0) break;
+ if (root > max) root = max;
+ if (max == 0) { /* no symbols to code at all */
+ this.op = (unsigned char)64; /* invalid code marker */
+ this.bits = (unsigned char)1;
+ this.val = (unsigned short)0;
+ *(*table)++ = this; /* make a table to force an error */
+ *(*table)++ = this;
+ *bits = 1;
+ return 0; /* no symbols, but wait for decoding to report error */
+ }
+ for (min = 1; min <= MAXBITS; min++)
+ if (count[min] != 0) break;
+ if (root < min) root = min;
+
+ /* check for an over-subscribed or incomplete set of lengths */
+ left = 1;
+ for (len = 1; len <= MAXBITS; len++) {
+ left <<= 1;
+ left -= count[len];
+ if (left < 0) return -1; /* over-subscribed */
+ }
+ if (left > 0 && (type == CODES || max != 1))
+ return -1; /* incomplete set */
+
+ /* generate offsets into symbol table for each length for sorting */
+ offs[1] = 0;
+ for (len = 1; len < MAXBITS; len++)
+ offs[len + 1] = offs[len] + count[len];
+
+ /* sort symbols by length, by symbol order within each length */
+ for (sym = 0; sym < codes; sym++)
+ if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
+
+ /*
+ Create and fill in decoding tables. In this loop, the table being
+ filled is at next and has curr index bits. The code being used is huff
+ with length len. That code is converted to an index by dropping drop
+ bits off of the bottom. For codes where len is less than drop + curr,
+ those top drop + curr - len bits are incremented through all values to
+ fill the table with replicated entries.
+
+ root is the number of index bits for the root table. When len exceeds
+ root, sub-tables are created pointed to by the root entry with an index
+ of the low root bits of huff. This is saved in low to check for when a
+ new sub-table should be started. drop is zero when the root table is
+ being filled, and drop is root when sub-tables are being filled.
+
+ When a new sub-table is needed, it is necessary to look ahead in the
+ code lengths to determine what size sub-table is needed. The length
+ counts are used for this, and so count[] is decremented as codes are
+ entered in the tables.
+
+ used keeps track of how many table entries have been allocated from the
+ provided *table space. It is checked when a LENS table is being made
+ against the space in *table, ENOUGH, minus the maximum space needed by
+ the worst case distance code, MAXD. This should never happen, but the
+ sufficiency of ENOUGH has not been proven exhaustively, hence the check.
+ This assumes that when type == LENS, bits == 9.
+
+ sym increments through all symbols, and the loop terminates when
+ all codes of length max, i.e. all codes, have been processed. This
+ routine permits incomplete codes, so another loop after this one fills
+ in the rest of the decoding tables with invalid code markers.
+ */
+
+ /* set up for code type */
+ switch (type) {
+ case CODES:
+ base = extra = work; /* dummy value--not used */
+ end = 19;
+ break;
+ case LENS:
+ base = lbase;
+ base -= 257;
+ extra = lext;
+ extra -= 257;
+ end = 256;
+ break;
+ default: /* DISTS */
+ base = dbase;
+ extra = dext;
+ end = -1;
+ }
+
+ /* initialize state for loop */
+ huff = 0; /* starting code */
+ sym = 0; /* starting code symbol */
+ len = min; /* starting code length */
+ next = *table; /* current table to fill in */
+ curr = root; /* current table index bits */
+ drop = 0; /* current bits to drop from code for index */
+ low = (unsigned)(-1); /* trigger new sub-table when len > root */
+ used = 1U << root; /* use root table entries */
+ mask = used - 1; /* mask for comparing low */
+
+ /* check available table space */
+ if (type == LENS && used >= ENOUGH - MAXD)
+ return 1;
+
+ /* process all codes and make table entries */
+ for (;;) {
+ /* create table entry */
+ this.bits = (unsigned char)(len - drop);
+ if ((int)(work[sym]) < end) {
+ this.op = (unsigned char)0;
+ this.val = work[sym];
+ }
+ else if ((int)(work[sym]) > end) {
+ this.op = (unsigned char)(extra[work[sym]]);
+ this.val = base[work[sym]];
+ }
+ else {
+ this.op = (unsigned char)(32 + 64); /* end of block */
+ this.val = 0;
+ }
+
+ /* replicate for those indices with low len bits equal to huff */
+ incr = 1U << (len - drop);
+ fill = 1U << curr;
+ min = fill; /* save offset to next table */
+ do {
+ fill -= incr;
+ next[(huff >> drop) + fill] = this;
+ } while (fill != 0);
+
+ /* backwards increment the len-bit code huff */
+ incr = 1U << (len - 1);
+ while (huff & incr)
+ incr >>= 1;
+ if (incr != 0) {
+ huff &= incr - 1;
+ huff += incr;
+ }
+ else
+ huff = 0;
+
+ /* go to next symbol, update count, len */
+ sym++;
+ if (--(count[len]) == 0) {
+ if (len == max) break;
+ len = lens[work[sym]];
+ }
+
+ /* create new sub-table if needed */
+ if (len > root && (huff & mask) != low) {
+ /* if first time, transition to sub-tables */
+ if (drop == 0)
+ drop = root;
+
+ /* increment past last table */
+ next += min; /* here min is 1 << curr */
+
+ /* determine length of next table */
+ curr = len - drop;
+ left = (int)(1 << curr);
+ while (curr + drop < max) {
+ left -= count[curr + drop];
+ if (left <= 0) break;
+ curr++;
+ left <<= 1;
+ }
+
+ /* check for enough space */
+ used += 1U << curr;
+ if (type == LENS && used >= ENOUGH - MAXD)
+ return 1;
+
+ /* point entry in root table to sub-table */
+ low = huff & mask;
+ (*table)[low].op = (unsigned char)curr;
+ (*table)[low].bits = (unsigned char)root;
+ (*table)[low].val = (unsigned short)(next - *table);
+ }
+ }
+
+ /*
+ Fill in rest of table for incomplete codes. This loop is similar to the
+ loop above in incrementing huff for table indices. It is assumed that
+ len is equal to curr + drop, so there is no loop needed to increment
+ through high index bits. When the current sub-table is filled, the loop
+ drops back to the root table to fill in any remaining entries there.
+ */
+ this.op = (unsigned char)64; /* invalid code marker */
+ this.bits = (unsigned char)(len - drop);
+ this.val = (unsigned short)0;
+ while (huff != 0) {
+ /* when done with sub-table, drop back to root table */
+ if (drop != 0 && (huff & mask) != low) {
+ drop = 0;
+ len = root;
+ next = *table;
+ this.bits = (unsigned char)len;
+ }
+
+ /* put invalid code marker in table */
+ next[huff >> drop] = this;
+
+ /* backwards increment the len-bit code huff */
+ incr = 1U << (len - 1);
+ while (huff & incr)
+ incr >>= 1;
+ if (incr != 0) {
+ huff &= incr - 1;
+ huff += incr;
+ }
+ else
+ huff = 0;
+ }
+
+ /* set return parameters */
+ *table += used;
+ *bits = root;
+ return 0;
+}
diff --git a/Utilities/cmzlib/inftrees.h b/Utilities/cmzlib/inftrees.h
new file mode 100644
index 0000000000..b1104c87e7
--- /dev/null
+++ b/Utilities/cmzlib/inftrees.h
@@ -0,0 +1,55 @@
+/* inftrees.h -- header to use inftrees.c
+ * Copyright (C) 1995-2005 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* Structure for decoding tables. Each entry provides either the
+ information needed to do the operation requested by the code that
+ indexed that table entry, or it provides a pointer to another
+ table that indexes more bits of the code. op indicates whether
+ the entry is a pointer to another table, a literal, a length or
+ distance, an end-of-block, or an invalid code. For a table
+ pointer, the low four bits of op is the number of index bits of
+ that table. For a length or distance, the low four bits of op
+ is the number of extra bits to get after the code. bits is
+ the number of bits in this code or part of the code to drop off
+ of the bit buffer. val is the actual byte to output in the case
+ of a literal, the base length or distance, or the offset from
+ the current table to the next table. Each entry is four bytes. */
+typedef struct {
+ unsigned char op; /* operation, extra bits, table bits */
+ unsigned char bits; /* bits in this part of the code */
+ unsigned short val; /* offset in table or code value */
+} code;
+
+/* op values as set by inflate_table():
+ 00000000 - literal
+ 0000tttt - table link, tttt != 0 is the number of table index bits
+ 0001eeee - length or distance, eeee is the number of extra bits
+ 01100000 - end of block
+ 01000000 - invalid code
+ */
+
+/* Maximum size of dynamic tree. The maximum found in a long but non-
+ exhaustive search was 1444 code structures (852 for length/literals
+ and 592 for distances, the latter actually the result of an
+ exhaustive search). The true maximum is not known, but the value
+ below is more than safe. */
+#define ENOUGH 2048
+#define MAXD 592
+
+/* Type of code to build for inftable() */
+typedef enum {
+ CODES,
+ LENS,
+ DISTS
+} codetype;
+
+extern int inflate_table OF((codetype type, unsigned short FAR *lens,
+ unsigned codes, code FAR * FAR *table,
+ unsigned FAR *bits, unsigned short FAR *work));
diff --git a/Utilities/cmzlib/trees.c b/Utilities/cmzlib/trees.c
new file mode 100644
index 0000000000..395e4e1681
--- /dev/null
+++ b/Utilities/cmzlib/trees.c
@@ -0,0 +1,1219 @@
+/* trees.c -- output deflated data using Huffman coding
+ * Copyright (C) 1995-2005 Jean-loup Gailly
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * ALGORITHM
+ *
+ * The "deflation" process uses several Huffman trees. The more
+ * common source values are represented by shorter bit sequences.
+ *
+ * Each code tree is stored in a compressed form which is itself
+ * a Huffman encoding of the lengths of all the code strings (in
+ * ascending order by source values). The actual code strings are
+ * reconstructed from the lengths in the inflate process, as described
+ * in the deflate specification.
+ *
+ * REFERENCES
+ *
+ * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
+ * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
+ *
+ * Storer, James A.
+ * Data Compression: Methods and Theory, pp. 49-50.
+ * Computer Science Press, 1988. ISBN 0-7167-8156-5.
+ *
+ * Sedgewick, R.
+ * Algorithms, p290.
+ * Addison-Wesley, 1983. ISBN 0-201-06672-6.
+ */
+
+/* @(#) $Id$ */
+
+/* #define GEN_TREES_H */
+
+#include "deflate.h"
+
+#ifdef DEBUG
+# include <ctype.h>
+#endif
+
+/* ===========================================================================
+ * Constants
+ */
+
+#define MAX_BL_BITS 7
+/* Bit length codes must not exceed MAX_BL_BITS bits */
+
+#define END_BLOCK 256
+/* end of block literal code */
+
+#define REP_3_6 16
+/* repeat previous bit length 3-6 times (2 bits of repeat count) */
+
+#define REPZ_3_10 17
+/* repeat a zero length 3-10 times (3 bits of repeat count) */
+
+#define REPZ_11_138 18
+/* repeat a zero length 11-138 times (7 bits of repeat count) */
+
+local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
+ = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
+
+local const int extra_dbits[D_CODES] /* extra bits for each distance code */
+ = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
+
+local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
+ = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
+
+local const uch bl_order[BL_CODES]
+ = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
+/* The lengths of the bit length codes are sent in order of decreasing
+ * probability, to avoid transmitting the lengths for unused bit length codes.
+ */
+
+#define Buf_size (8 * 2*sizeof(char))
+/* Number of bits used within bi_buf. (bi_buf might be implemented on
+ * more than 16 bits on some systems.)
+ */
+
+/* ===========================================================================
+ * Local data. These are initialized only once.
+ */
+
+#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
+
+#if defined(GEN_TREES_H) || !defined(STDC)
+/* non ANSI compilers may not accept trees.h */
+
+local ct_data static_ltree[L_CODES+2];
+/* The static literal tree. Since the bit lengths are imposed, there is no
+ * need for the L_CODES extra codes used during heap construction. However
+ * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
+ * below).
+ */
+
+local ct_data static_dtree[D_CODES];
+/* The static distance tree. (Actually a trivial tree since all codes use
+ * 5 bits.)
+ */
+
+uch _dist_code[DIST_CODE_LEN];
+/* Distance codes. The first 256 values correspond to the distances
+ * 3 .. 258, the last 256 values correspond to the top 8 bits of
+ * the 15 bit distances.
+ */
+
+uch _length_code[MAX_MATCH-MIN_MATCH+1];
+/* length code for each normalized match length (0 == MIN_MATCH) */
+
+local int base_length[LENGTH_CODES];
+/* First normalized length for each code (0 = MIN_MATCH) */
+
+local int base_dist[D_CODES];
+/* First normalized distance for each code (0 = distance of 1) */
+
+#else
+# include "trees.h"
+#endif /* GEN_TREES_H */
+
+struct static_tree_desc_s {
+ const ct_data *static_tree; /* static tree or NULL */
+ const intf *extra_bits; /* extra bits for each code or NULL */
+ int extra_base; /* base index for extra_bits */
+ int elems; /* max number of elements in the tree */
+ int max_length; /* max bit length for the codes */
+};
+
+local static_tree_desc static_l_desc =
+{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
+
+local static_tree_desc static_d_desc =
+{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
+
+local static_tree_desc static_bl_desc =
+{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
+
+/* ===========================================================================
+ * Local (static) routines in this file.
+ */
+
+local void tr_static_init OF((void));
+local void init_block OF((deflate_state *s));
+local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
+local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
+local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
+local void build_tree OF((deflate_state *s, tree_desc *desc));
+local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
+local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
+local int build_bl_tree OF((deflate_state *s));
+local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
+ int blcodes));
+local void compress_block OF((deflate_state *s, ct_data *ltree,
+ ct_data *dtree));
+local void set_data_type OF((deflate_state *s));
+local unsigned bi_reverse OF((unsigned value, int length));
+local void bi_windup OF((deflate_state *s));
+local void bi_flush OF((deflate_state *s));
+local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
+ int header));
+
+#ifdef GEN_TREES_H
+local void gen_trees_header OF((void));
+#endif
+
+#ifndef DEBUG
+# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
+ /* Send a code of the given tree. c and tree must not have side effects */
+
+#else /* DEBUG */
+# define send_code(s, c, tree) \
+ { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
+ send_bits(s, tree[c].Code, tree[c].Len); }
+#endif
+
+/* ===========================================================================
+ * Output a short LSB first on the stream.
+ * IN assertion: there is enough room in pendingBuf.
+ */
+#define put_short(s, w) { \
+ put_byte(s, (uch)((w) & 0xff)); \
+ put_byte(s, (uch)((ush)(w) >> 8)); \
+}
+
+/* ===========================================================================
+ * Send a value on a given number of bits.
+ * IN assertion: length <= 16 and value fits in length bits.
+ */
+#ifdef DEBUG
+local void send_bits OF((deflate_state *s, int value, int length));
+
+local void send_bits(s, value, length)
+ deflate_state *s;
+ int value; /* value to send */
+ int length; /* number of bits */
+{
+ Tracevv((stderr," l %2d v %4x ", length, value));
+ Assert(length > 0 && length <= 15, "invalid length");
+ s->bits_sent += (ulg)length;
+
+ /* If not enough room in bi_buf, use (valid) bits from bi_buf and
+ * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
+ * unused bits in value.
+ */
+ if (s->bi_valid > (int)Buf_size - length) {
+ s->bi_buf |= (value << s->bi_valid);
+ put_short(s, s->bi_buf);
+ s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
+ s->bi_valid += length - Buf_size;
+ } else {
+ s->bi_buf |= value << s->bi_valid;
+ s->bi_valid += length;
+ }
+}
+#else /* !DEBUG */
+
+#define send_bits(s, value, length) \
+{ int len = length;\
+ if (s->bi_valid > (int)Buf_size - len) {\
+ int val = value;\
+ s->bi_buf |= (val << s->bi_valid);\
+ put_short(s, s->bi_buf);\
+ s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
+ s->bi_valid += len - Buf_size;\
+ } else {\
+ s->bi_buf |= (value) << s->bi_valid;\
+ s->bi_valid += len;\
+ }\
+}
+#endif /* DEBUG */
+
+
+/* the arguments must not have side effects */
+
+/* ===========================================================================
+ * Initialize the various 'constant' tables.
+ */
+local void tr_static_init()
+{
+#if defined(GEN_TREES_H) || !defined(STDC)
+ static int static_init_done = 0;
+ int n; /* iterates over tree elements */
+ int bits; /* bit counter */
+ int length; /* length value */
+ int code; /* code value */
+ int dist; /* distance index */
+ ush bl_count[MAX_BITS+1];
+ /* number of codes at each bit length for an optimal tree */
+
+ if (static_init_done) return;
+
+ /* For some embedded targets, global variables are not initialized: */
+ static_l_desc.static_tree = static_ltree;
+ static_l_desc.extra_bits = extra_lbits;
+ static_d_desc.static_tree = static_dtree;
+ static_d_desc.extra_bits = extra_dbits;
+ static_bl_desc.extra_bits = extra_blbits;
+
+ /* Initialize the mapping length (0..255) -> length code (0..28) */
+ length = 0;
+ for (code = 0; code < LENGTH_CODES-1; code++) {
+ base_length[code] = length;
+ for (n = 0; n < (1<<extra_lbits[code]); n++) {
+ _length_code[length++] = (uch)code;
+ }
+ }
+ Assert (length == 256, "tr_static_init: length != 256");
+ /* Note that the length 255 (match length 258) can be represented
+ * in two different ways: code 284 + 5 bits or code 285, so we
+ * overwrite length_code[255] to use the best encoding:
+ */
+ _length_code[length-1] = (uch)code;
+
+ /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
+ dist = 0;
+ for (code = 0 ; code < 16; code++) {
+ base_dist[code] = dist;
+ for (n = 0; n < (1<<extra_dbits[code]); n++) {
+ _dist_code[dist++] = (uch)code;
+ }
+ }
+ Assert (dist == 256, "tr_static_init: dist != 256");
+ dist >>= 7; /* from now on, all distances are divided by 128 */
+ for ( ; code < D_CODES; code++) {
+ base_dist[code] = dist << 7;
+ for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
+ _dist_code[256 + dist++] = (uch)code;
+ }
+ }
+ Assert (dist == 256, "tr_static_init: 256+dist != 512");
+
+ /* Construct the codes of the static literal tree */
+ for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
+ n = 0;
+ while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
+ while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
+ while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
+ while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
+ /* Codes 286 and 287 do not exist, but we must include them in the
+ * tree construction to get a canonical Huffman tree (longest code
+ * all ones)
+ */
+ gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
+
+ /* The static distance tree is trivial: */
+ for (n = 0; n < D_CODES; n++) {
+ static_dtree[n].Len = 5;
+ static_dtree[n].Code = bi_reverse((unsigned)n, 5);
+ }
+ static_init_done = 1;
+
+# ifdef GEN_TREES_H
+ gen_trees_header();
+# endif
+#endif /* defined(GEN_TREES_H) || !defined(STDC) */
+}
+
+/* ===========================================================================
+ * Genererate the file trees.h describing the static trees.
+ */
+#ifdef GEN_TREES_H
+# ifndef DEBUG
+# include <stdio.h>
+# endif
+
+# define SEPARATOR(i, last, width) \
+ ((i) == (last)? "\n};\n\n" : \
+ ((i) % (width) == (width)-1 ? ",\n" : ", "))
+
+void gen_trees_header()
+{
+ FILE *header = fopen("trees.h", "w");
+ int i;
+
+ Assert (header != NULL, "Can't open trees.h");
+ fprintf(header,
+ "/* header created automatically with -DGEN_TREES_H */\n\n");
+
+ fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
+ for (i = 0; i < L_CODES+2; i++) {
+ fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
+ static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
+ }
+
+ fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
+ for (i = 0; i < D_CODES; i++) {
+ fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
+ static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
+ }
+
+ fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
+ for (i = 0; i < DIST_CODE_LEN; i++) {
+ fprintf(header, "%2u%s", _dist_code[i],
+ SEPARATOR(i, DIST_CODE_LEN-1, 20));
+ }
+
+ fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
+ for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
+ fprintf(header, "%2u%s", _length_code[i],
+ SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
+ }
+
+ fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
+ for (i = 0; i < LENGTH_CODES; i++) {
+ fprintf(header, "%1u%s", base_length[i],
+ SEPARATOR(i, LENGTH_CODES-1, 20));
+ }
+
+ fprintf(header, "local const int base_dist[D_CODES] = {\n");
+ for (i = 0; i < D_CODES; i++) {
+ fprintf(header, "%5u%s", base_dist[i],
+ SEPARATOR(i, D_CODES-1, 10));
+ }
+
+ fclose(header);
+}
+#endif /* GEN_TREES_H */
+
+/* ===========================================================================
+ * Initialize the tree data structures for a new zlib stream.
+ */
+void _tr_init(s)
+ deflate_state *s;
+{
+ tr_static_init();
+
+ s->l_desc.dyn_tree = s->dyn_ltree;
+ s->l_desc.stat_desc = &static_l_desc;
+
+ s->d_desc.dyn_tree = s->dyn_dtree;
+ s->d_desc.stat_desc = &static_d_desc;
+
+ s->bl_desc.dyn_tree = s->bl_tree;
+ s->bl_desc.stat_desc = &static_bl_desc;
+
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+ s->last_eob_len = 8; /* enough lookahead for inflate */
+#ifdef DEBUG
+ s->compressed_len = 0L;
+ s->bits_sent = 0L;
+#endif
+
+ /* Initialize the first block of the first file: */
+ init_block(s);
+}
+
+/* ===========================================================================
+ * Initialize a new block.
+ */
+local void init_block(s)
+ deflate_state *s;
+{
+ int n; /* iterates over tree elements */
+
+ /* Initialize the trees. */
+ for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
+ for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
+ for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
+
+ s->dyn_ltree[END_BLOCK].Freq = 1;
+ s->opt_len = s->static_len = 0L;
+ s->last_lit = s->matches = 0;
+}
+
+#define SMALLEST 1
+/* Index within the heap array of least frequent node in the Huffman tree */
+
+
+/* ===========================================================================
+ * Remove the smallest element from the heap and recreate the heap with
+ * one less element. Updates heap and heap_len.
+ */
+#define pqremove(s, tree, top) \
+{\
+ top = s->heap[SMALLEST]; \
+ s->heap[SMALLEST] = s->heap[s->heap_len--]; \
+ pqdownheap(s, tree, SMALLEST); \
+}
+
+/* ===========================================================================
+ * Compares to subtrees, using the tree depth as tie breaker when
+ * the subtrees have equal frequency. This minimizes the worst case length.
+ */
+#define smaller(tree, n, m, depth) \
+ (tree[n].Freq < tree[m].Freq || \
+ (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
+
+/* ===========================================================================
+ * Restore the heap property by moving down the tree starting at node k,
+ * exchanging a node with the smallest of its two sons if necessary, stopping
+ * when the heap property is re-established (each father smaller than its
+ * two sons).
+ */
+local void pqdownheap(s, tree, k)
+ deflate_state *s;
+ ct_data *tree; /* the tree to restore */
+ int k; /* node to move down */
+{
+ int v = s->heap[k];
+ int j = k << 1; /* left son of k */
+ while (j <= s->heap_len) {
+ /* Set j to the smallest of the two sons: */
+ if (j < s->heap_len &&
+ smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
+ j++;
+ }
+ /* Exit if v is smaller than both sons */
+ if (smaller(tree, v, s->heap[j], s->depth)) break;
+
+ /* Exchange v with the smallest son */
+ s->heap[k] = s->heap[j]; k = j;
+
+ /* And continue down the tree, setting j to the left son of k */
+ j <<= 1;
+ }
+ s->heap[k] = v;
+}
+
+/* ===========================================================================
+ * Compute the optimal bit lengths for a tree and update the total bit length
+ * for the current block.
+ * IN assertion: the fields freq and dad are set, heap[heap_max] and
+ * above are the tree nodes sorted by increasing frequency.
+ * OUT assertions: the field len is set to the optimal bit length, the
+ * array bl_count contains the frequencies for each bit length.
+ * The length opt_len is updated; static_len is also updated if stree is
+ * not null.
+ */
+local void gen_bitlen(s, desc)
+ deflate_state *s;
+ tree_desc *desc; /* the tree descriptor */
+{
+ ct_data *tree = desc->dyn_tree;
+ int max_code = desc->max_code;
+ const ct_data *stree = desc->stat_desc->static_tree;
+ const intf *extra = desc->stat_desc->extra_bits;
+ int base = desc->stat_desc->extra_base;
+ int max_length = desc->stat_desc->max_length;
+ int h; /* heap index */
+ int n, m; /* iterate over the tree elements */
+ int bits; /* bit length */
+ int xbits; /* extra bits */
+ ush f; /* frequency */
+ int overflow = 0; /* number of elements with bit length too large */
+
+ for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
+
+ /* In a first pass, compute the optimal bit lengths (which may
+ * overflow in the case of the bit length tree).
+ */
+ tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
+
+ for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
+ n = s->heap[h];
+ bits = tree[tree[n].Dad].Len + 1;
+ if (bits > max_length) bits = max_length, overflow++;
+ tree[n].Len = (ush)bits;
+ /* We overwrite tree[n].Dad which is no longer needed */
+
+ if (n > max_code) continue; /* not a leaf node */
+
+ s->bl_count[bits]++;
+ xbits = 0;
+ if (n >= base) xbits = extra[n-base];
+ f = tree[n].Freq;
+ s->opt_len += (ulg)f * (bits + xbits);
+ if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
+ }
+ if (overflow == 0) return;
+
+ Trace((stderr,"\nbit length overflow\n"));
+ /* This happens for example on obj2 and pic of the Calgary corpus */
+
+ /* Find the first bit length which could increase: */
+ do {
+ bits = max_length-1;
+ while (s->bl_count[bits] == 0) bits--;
+ s->bl_count[bits]--; /* move one leaf down the tree */
+ s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
+ s->bl_count[max_length]--;
+ /* The brother of the overflow item also moves one step up,
+ * but this does not affect bl_count[max_length]
+ */
+ overflow -= 2;
+ } while (overflow > 0);
+
+ /* Now recompute all bit lengths, scanning in increasing frequency.
+ * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
+ * lengths instead of fixing only the wrong ones. This idea is taken
+ * from 'ar' written by Haruhiko Okumura.)
+ */
+ for (bits = max_length; bits != 0; bits--) {
+ n = s->bl_count[bits];
+ while (n != 0) {
+ m = s->heap[--h];
+ if (m > max_code) continue;
+ if ((unsigned) tree[m].Len != (unsigned) bits) {
+ Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
+ s->opt_len += ((long)bits - (long)tree[m].Len)
+ *(long)tree[m].Freq;
+ tree[m].Len = (ush)bits;
+ }
+ n--;
+ }
+ }
+}
+
+/* ===========================================================================
+ * Generate the codes for a given tree and bit counts (which need not be
+ * optimal).
+ * IN assertion: the array bl_count contains the bit length statistics for
+ * the given tree and the field len is set for all tree elements.
+ * OUT assertion: the field code is set for all tree elements of non
+ * zero code length.
+ */
+local void gen_codes (tree, max_code, bl_count)
+ ct_data *tree; /* the tree to decorate */
+ int max_code; /* largest code with non zero frequency */
+ ushf *bl_count; /* number of codes at each bit length */
+{
+ ush next_code[MAX_BITS+1]; /* next code value for each bit length */
+ ush code = 0; /* running code value */
+ int bits; /* bit index */
+ int n; /* code index */
+
+ /* The distribution counts are first used to generate the code values
+ * without bit reversal.
+ */
+ for (bits = 1; bits <= MAX_BITS; bits++) {
+ next_code[bits] = code = (code + bl_count[bits-1]) << 1;
+ }
+ /* Check that the bit counts in bl_count are consistent. The last code
+ * must be all ones.
+ */
+ Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
+ "inconsistent bit counts");
+ Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
+
+ for (n = 0; n <= max_code; n++) {
+ int len = tree[n].Len;
+ if (len == 0) continue;
+ /* Now reverse the bits */
+ tree[n].Code = bi_reverse(next_code[len]++, len);
+
+ Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
+ n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
+ }
+}
+
+/* ===========================================================================
+ * Construct one Huffman tree and assigns the code bit strings and lengths.
+ * Update the total bit length for the current block.
+ * IN assertion: the field freq is set for all tree elements.
+ * OUT assertions: the fields len and code are set to the optimal bit length
+ * and corresponding code. The length opt_len is updated; static_len is
+ * also updated if stree is not null. The field max_code is set.
+ */
+local void build_tree(s, desc)
+ deflate_state *s;
+ tree_desc *desc; /* the tree descriptor */
+{
+ ct_data *tree = desc->dyn_tree;
+ const ct_data *stree = desc->stat_desc->static_tree;
+ int elems = desc->stat_desc->elems;
+ int n, m; /* iterate over heap elements */
+ int max_code = -1; /* largest code with non zero frequency */
+ int node; /* new node being created */
+
+ /* Construct the initial heap, with least frequent element in
+ * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
+ * heap[0] is not used.
+ */
+ s->heap_len = 0, s->heap_max = HEAP_SIZE;
+
+ for (n = 0; n < elems; n++) {
+ if (tree[n].Freq != 0) {
+ s->heap[++(s->heap_len)] = max_code = n;
+ s->depth[n] = 0;
+ } else {
+ tree[n].Len = 0;
+ }
+ }
+
+ /* The pkzip format requires that at least one distance code exists,
+ * and that at least one bit should be sent even if there is only one
+ * possible code. So to avoid special checks later on we force at least
+ * two codes of non zero frequency.
+ */
+ while (s->heap_len < 2) {
+ node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
+ tree[node].Freq = 1;
+ s->depth[node] = 0;
+ s->opt_len--; if (stree) s->static_len -= stree[node].Len;
+ /* node is 0 or 1 so it does not have extra bits */
+ }
+ desc->max_code = max_code;
+
+ /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
+ * establish sub-heaps of increasing lengths:
+ */
+ for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
+
+ /* Construct the Huffman tree by repeatedly combining the least two
+ * frequent nodes.
+ */
+ node = elems; /* next internal node of the tree */
+ do {
+ pqremove(s, tree, n); /* n = node of least frequency */
+ m = s->heap[SMALLEST]; /* m = node of next least frequency */
+
+ s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
+ s->heap[--(s->heap_max)] = m;
+
+ /* Create a new node father of n and m */
+ tree[node].Freq = tree[n].Freq + tree[m].Freq;
+ s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
+ s->depth[n] : s->depth[m]) + 1);
+ tree[n].Dad = tree[m].Dad = (ush)node;
+#ifdef DUMP_BL_TREE
+ if (tree == s->bl_tree) {
+ fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
+ node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
+ }
+#endif
+ /* and insert the new node in the heap */
+ s->heap[SMALLEST] = node++;
+ pqdownheap(s, tree, SMALLEST);
+
+ } while (s->heap_len >= 2);
+
+ s->heap[--(s->heap_max)] = s->heap[SMALLEST];
+
+ /* At this point, the fields freq and dad are set. We can now
+ * generate the bit lengths.
+ */
+ gen_bitlen(s, (tree_desc *)desc);
+
+ /* The field len is now set, we can generate the bit codes */
+ gen_codes ((ct_data *)tree, max_code, s->bl_count);
+}
+
+/* ===========================================================================
+ * Scan a literal or distance tree to determine the frequencies of the codes
+ * in the bit length tree.
+ */
+local void scan_tree (s, tree, max_code)
+ deflate_state *s;
+ ct_data *tree; /* the tree to be scanned */
+ int max_code; /* and its largest code of non zero frequency */
+{
+ int n; /* iterates over all tree elements */
+ int prevlen = -1; /* last emitted length */
+ int curlen; /* length of current code */
+ int nextlen = tree[0].Len; /* length of next code */
+ int count = 0; /* repeat count of the current code */
+ int max_count = 7; /* max repeat count */
+ int min_count = 4; /* min repeat count */
+
+ if (nextlen == 0) max_count = 138, min_count = 3;
+ tree[max_code+1].Len = (ush)0xffff; /* guard */
+
+ for (n = 0; n <= max_code; n++) {
+ curlen = nextlen; nextlen = tree[n+1].Len;
+ if (++count < max_count && curlen == nextlen) {
+ continue;
+ } else if (count < min_count) {
+ s->bl_tree[curlen].Freq += count;
+ } else if (curlen != 0) {
+ if (curlen != prevlen) s->bl_tree[curlen].Freq++;
+ s->bl_tree[REP_3_6].Freq++;
+ } else if (count <= 10) {
+ s->bl_tree[REPZ_3_10].Freq++;
+ } else {
+ s->bl_tree[REPZ_11_138].Freq++;
+ }
+ count = 0; prevlen = curlen;
+ if (nextlen == 0) {
+ max_count = 138, min_count = 3;
+ } else if (curlen == nextlen) {
+ max_count = 6, min_count = 3;
+ } else {
+ max_count = 7, min_count = 4;
+ }
+ }
+}
+
+/* ===========================================================================
+ * Send a literal or distance tree in compressed form, using the codes in
+ * bl_tree.
+ */
+local void send_tree (s, tree, max_code)
+ deflate_state *s;
+ ct_data *tree; /* the tree to be scanned */
+ int max_code; /* and its largest code of non zero frequency */
+{
+ int n; /* iterates over all tree elements */
+ int prevlen = -1; /* last emitted length */
+ int curlen; /* length of current code */
+ int nextlen = tree[0].Len; /* length of next code */
+ int count = 0; /* repeat count of the current code */
+ int max_count = 7; /* max repeat count */
+ int min_count = 4; /* min repeat count */
+
+ /* tree[max_code+1].Len = -1; */ /* guard already set */
+ if (nextlen == 0) max_count = 138, min_count = 3;
+
+ for (n = 0; n <= max_code; n++) {
+ curlen = nextlen; nextlen = tree[n+1].Len;
+ if (++count < max_count && curlen == nextlen) {
+ continue;
+ } else if (count < min_count) {
+ do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
+
+ } else if (curlen != 0) {
+ if (curlen != prevlen) {
+ send_code(s, curlen, s->bl_tree); count--;
+ }
+ Assert(count >= 3 && count <= 6, " 3_6?");
+ send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
+
+ } else if (count <= 10) {
+ send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
+
+ } else {
+ send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
+ }
+ count = 0; prevlen = curlen;
+ if (nextlen == 0) {
+ max_count = 138, min_count = 3;
+ } else if (curlen == nextlen) {
+ max_count = 6, min_count = 3;
+ } else {
+ max_count = 7, min_count = 4;
+ }
+ }
+}
+
+/* ===========================================================================
+ * Construct the Huffman tree for the bit lengths and return the index in
+ * bl_order of the last bit length code to send.
+ */
+local int build_bl_tree(s)
+ deflate_state *s;
+{
+ int max_blindex; /* index of last bit length code of non zero freq */
+
+ /* Determine the bit length frequencies for literal and distance trees */
+ scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
+ scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
+
+ /* Build the bit length tree: */
+ build_tree(s, (tree_desc *)(&(s->bl_desc)));
+ /* opt_len now includes the length of the tree representations, except
+ * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
+ */
+
+ /* Determine the number of bit length codes to send. The pkzip format
+ * requires that at least 4 bit length codes be sent. (appnote.txt says
+ * 3 but the actual value used is 4.)
+ */
+ for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
+ if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
+ }
+ /* Update opt_len to include the bit length tree and counts */
+ s->opt_len += 3*(max_blindex+1) + 5+5+4;
+ Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
+ s->opt_len, s->static_len));
+
+ return max_blindex;
+}
+
+/* ===========================================================================
+ * Send the header for a block using dynamic Huffman trees: the counts, the
+ * lengths of the bit length codes, the literal tree and the distance tree.
+ * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
+ */
+local void send_all_trees(s, lcodes, dcodes, blcodes)
+ deflate_state *s;
+ int lcodes, dcodes, blcodes; /* number of codes for each tree */
+{
+ int rank; /* index in bl_order */
+
+ Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
+ Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
+ "too many codes");
+ Tracev((stderr, "\nbl counts: "));
+ send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
+ send_bits(s, dcodes-1, 5);
+ send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
+ for (rank = 0; rank < blcodes; rank++) {
+ Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
+ send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
+ }
+ Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
+
+ send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
+ Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
+
+ send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
+ Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
+}
+
+/* ===========================================================================
+ * Send a stored block
+ */
+void _tr_stored_block(s, buf, stored_len, eof)
+ deflate_state *s;
+ charf *buf; /* input block */
+ ulg stored_len; /* length of input block */
+ int eof; /* true if this is the last block for a file */
+{
+ send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
+#ifdef DEBUG
+ s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
+ s->compressed_len += (stored_len + 4) << 3;
+#endif
+ copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
+}
+
+/* ===========================================================================
+ * Send one empty static block to give enough lookahead for inflate.
+ * This takes 10 bits, of which 7 may remain in the bit buffer.
+ * The current inflate code requires 9 bits of lookahead. If the
+ * last two codes for the previous block (real code plus EOB) were coded
+ * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
+ * the last real code. In this case we send two empty static blocks instead
+ * of one. (There are no problems if the previous block is stored or fixed.)
+ * To simplify the code, we assume the worst case of last real code encoded
+ * on one bit only.
+ */
+void _tr_align(s)
+ deflate_state *s;
+{
+ send_bits(s, STATIC_TREES<<1, 3);
+ send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG
+ s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
+#endif
+ bi_flush(s);
+ /* Of the 10 bits for the empty block, we have already sent
+ * (10 - bi_valid) bits. The lookahead for the last real code (before
+ * the EOB of the previous block) was thus at least one plus the length
+ * of the EOB plus what we have just sent of the empty static block.
+ */
+ if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
+ send_bits(s, STATIC_TREES<<1, 3);
+ send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG
+ s->compressed_len += 10L;
+#endif
+ bi_flush(s);
+ }
+ s->last_eob_len = 7;
+}
+
+/* ===========================================================================
+ * Determine the best encoding for the current block: dynamic trees, static
+ * trees or store, and output the encoded block to the zip file.
+ */
+void _tr_flush_block(s, buf, stored_len, eof)
+ deflate_state *s;
+ charf *buf; /* input block, or NULL if too old */
+ ulg stored_len; /* length of input block */
+ int eof; /* true if this is the last block for a file */
+{
+ ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
+ int max_blindex = 0; /* index of last bit length code of non zero freq */
+
+ /* Build the Huffman trees unless a stored block is forced */
+ if (s->level > 0) {
+
+ /* Check if the file is binary or text */
+ if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
+ set_data_type(s);
+
+ /* Construct the literal and distance trees */
+ build_tree(s, (tree_desc *)(&(s->l_desc)));
+ Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
+ s->static_len));
+
+ build_tree(s, (tree_desc *)(&(s->d_desc)));
+ Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
+ s->static_len));
+ /* At this point, opt_len and static_len are the total bit lengths of
+ * the compressed block data, excluding the tree representations.
+ */
+
+ /* Build the bit length tree for the above two trees, and get the index
+ * in bl_order of the last bit length code to send.
+ */
+ max_blindex = build_bl_tree(s);
+
+ /* Determine the best encoding. Compute the block lengths in bytes. */
+ opt_lenb = (s->opt_len+3+7)>>3;
+ static_lenb = (s->static_len+3+7)>>3;
+
+ Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
+ opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
+ s->last_lit));
+
+ if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
+
+ } else {
+ Assert(buf != (char*)0, "lost buf");
+ opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
+ }
+
+#ifdef FORCE_STORED
+ if (buf != (char*)0) { /* force stored block */
+#else
+ if (stored_len+4 <= opt_lenb && buf != (char*)0) {
+ /* 4: two words for the lengths */
+#endif
+ /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
+ * Otherwise we can't have processed more than WSIZE input bytes since
+ * the last block flush, because compression would have been
+ * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
+ * transform a block into a stored block.
+ */
+ _tr_stored_block(s, buf, stored_len, eof);
+
+#ifdef FORCE_STATIC
+ } else if (static_lenb >= 0) { /* force static trees */
+#else
+ } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
+#endif
+ send_bits(s, (STATIC_TREES<<1)+eof, 3);
+ compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
+#ifdef DEBUG
+ s->compressed_len += 3 + s->static_len;
+#endif
+ } else {
+ send_bits(s, (DYN_TREES<<1)+eof, 3);
+ send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
+ max_blindex+1);
+ compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
+#ifdef DEBUG
+ s->compressed_len += 3 + s->opt_len;
+#endif
+ }
+ Assert (s->compressed_len == s->bits_sent, "bad compressed size");
+ /* The above check is made mod 2^32, for files larger than 512 MB
+ * and uLong implemented on 32 bits.
+ */
+ init_block(s);
+
+ if (eof) {
+ bi_windup(s);
+#ifdef DEBUG
+ s->compressed_len += 7; /* align on byte boundary */
+#endif
+ }
+ Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
+ s->compressed_len-7*eof));
+}
+
+/* ===========================================================================
+ * Save the match info and tally the frequency counts. Return true if
+ * the current block must be flushed.
+ */
+int _tr_tally (s, dist, lc)
+ deflate_state *s;
+ unsigned dist; /* distance of matched string */
+ unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
+{
+ s->d_buf[s->last_lit] = (ush)dist;
+ s->l_buf[s->last_lit++] = (uch)lc;
+ if (dist == 0) {
+ /* lc is the unmatched char */
+ s->dyn_ltree[lc].Freq++;
+ } else {
+ s->matches++;
+ /* Here, lc is the match length - MIN_MATCH */
+ dist--; /* dist = match distance - 1 */
+ Assert((ush)dist < (ush)MAX_DIST(s) &&
+ (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
+ (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
+
+ s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
+ s->dyn_dtree[d_code(dist)].Freq++;
+ }
+
+#ifdef TRUNCATE_BLOCK
+ /* Try to guess if it is profitable to stop the current block here */
+ if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
+ /* Compute an upper bound for the compressed length */
+ ulg out_length = (ulg)s->last_lit*8L;
+ ulg in_length = (ulg)((long)s->strstart - s->block_start);
+ int dcode;
+ for (dcode = 0; dcode < D_CODES; dcode++) {
+ out_length += (ulg)s->dyn_dtree[dcode].Freq *
+ (5L+extra_dbits[dcode]);
+ }
+ out_length >>= 3;
+ Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
+ s->last_lit, in_length, out_length,
+ 100L - out_length*100L/in_length));
+ if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
+ }
+#endif
+ return (s->last_lit == s->lit_bufsize-1);
+ /* We avoid equality with lit_bufsize because of wraparound at 64K
+ * on 16 bit machines and because stored blocks are restricted to
+ * 64K-1 bytes.
+ */
+}
+
+/* ===========================================================================
+ * Send the block data compressed using the given Huffman trees
+ */
+local void compress_block(s, ltree, dtree)
+ deflate_state *s;
+ ct_data *ltree; /* literal tree */
+ ct_data *dtree; /* distance tree */
+{
+ unsigned dist; /* distance of matched string */
+ int lc; /* match length or unmatched char (if dist == 0) */
+ unsigned lx = 0; /* running index in l_buf */
+ unsigned code; /* the code to send */
+ int extra; /* number of extra bits to send */
+
+ if (s->last_lit != 0) do {
+ dist = s->d_buf[lx];
+ lc = s->l_buf[lx++];
+ if (dist == 0) {
+ send_code(s, lc, ltree); /* send a literal byte */
+ Tracecv(isgraph(lc), (stderr," '%c' ", lc));
+ } else {
+ /* Here, lc is the match length - MIN_MATCH */
+ code = _length_code[lc];
+ send_code(s, code+LITERALS+1, ltree); /* send the length code */
+ extra = extra_lbits[code];
+ if (extra != 0) {
+ lc -= base_length[code];
+ send_bits(s, lc, extra); /* send the extra length bits */
+ }
+ dist--; /* dist is now the match distance - 1 */
+ code = d_code(dist);
+ Assert (code < D_CODES, "bad d_code");
+
+ send_code(s, code, dtree); /* send the distance code */
+ extra = extra_dbits[code];
+ if (extra != 0) {
+ dist -= base_dist[code];
+ send_bits(s, dist, extra); /* send the extra distance bits */
+ }
+ } /* literal or match pair ? */
+
+ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
+ Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
+ "pendingBuf overflow");
+
+ } while (lx < s->last_lit);
+
+ send_code(s, END_BLOCK, ltree);
+ s->last_eob_len = ltree[END_BLOCK].Len;
+}
+
+/* ===========================================================================
+ * Set the data type to BINARY or TEXT, using a crude approximation:
+ * set it to Z_TEXT if all symbols are either printable characters (33 to 255)
+ * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise.
+ * IN assertion: the fields Freq of dyn_ltree are set.
+ */
+local void set_data_type(s)
+ deflate_state *s;
+{
+ int n;
+
+ for (n = 0; n < 9; n++)
+ if (s->dyn_ltree[n].Freq != 0)
+ break;
+ if (n == 9)
+ for (n = 14; n < 32; n++)
+ if (s->dyn_ltree[n].Freq != 0)
+ break;
+ s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
+}
+
+/* ===========================================================================
+ * Reverse the first len bits of a code, using straightforward code (a faster
+ * method would use a table)
+ * IN assertion: 1 <= len <= 15
+ */
+local unsigned bi_reverse(code, len)
+ unsigned code; /* the value to invert */
+ int len; /* its bit length */
+{
+ register unsigned res = 0;
+ do {
+ res |= code & 1;
+ code >>= 1, res <<= 1;
+ } while (--len > 0);
+ return res >> 1;
+}
+
+/* ===========================================================================
+ * Flush the bit buffer, keeping at most 7 bits in it.
+ */
+local void bi_flush(s)
+ deflate_state *s;
+{
+ if (s->bi_valid == 16) {
+ put_short(s, s->bi_buf);
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+ } else if (s->bi_valid >= 8) {
+ put_byte(s, (Byte)s->bi_buf);
+ s->bi_buf >>= 8;
+ s->bi_valid -= 8;
+ }
+}
+
+/* ===========================================================================
+ * Flush the bit buffer and align the output on a byte boundary
+ */
+local void bi_windup(s)
+ deflate_state *s;
+{
+ if (s->bi_valid > 8) {
+ put_short(s, s->bi_buf);
+ } else if (s->bi_valid > 0) {
+ put_byte(s, (Byte)s->bi_buf);
+ }
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+#ifdef DEBUG
+ s->bits_sent = (s->bits_sent+7) & ~7;
+#endif
+}
+
+/* ===========================================================================
+ * Copy a stored block, storing first the length and its
+ * one's complement if requested.
+ */
+local void copy_block(s, buf, len, header)
+ deflate_state *s;
+ charf *buf; /* the input data */
+ unsigned len; /* its length */
+ int header; /* true if block header must be written */
+{
+ bi_windup(s); /* align on byte boundary */
+ s->last_eob_len = 8; /* enough lookahead for inflate */
+
+ if (header) {
+ put_short(s, (ush)len);
+ put_short(s, (ush)~len);
+#ifdef DEBUG
+ s->bits_sent += 2*16;
+#endif
+ }
+#ifdef DEBUG
+ s->bits_sent += (ulg)len<<3;
+#endif
+ while (len--) {
+ put_byte(s, *buf++);
+ }
+}
diff --git a/Utilities/cmzlib/trees.h b/Utilities/cmzlib/trees.h
new file mode 100644
index 0000000000..72facf900f
--- /dev/null
+++ b/Utilities/cmzlib/trees.h
@@ -0,0 +1,128 @@
+/* header created automatically with -DGEN_TREES_H */
+
+local const ct_data static_ltree[L_CODES+2] = {
+{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
+{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
+{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
+{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
+{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
+{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
+{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
+{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
+{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
+{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
+{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
+{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
+{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
+{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
+{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
+{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
+{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
+{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
+{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
+{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
+{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
+{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
+{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
+{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
+{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
+{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
+{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
+{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
+{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
+{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
+{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
+{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
+{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
+{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
+{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
+{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
+{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
+{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
+{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
+{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
+{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
+{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
+{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
+{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
+{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
+{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
+{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
+{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
+{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
+{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
+{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
+{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
+{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
+{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
+{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
+{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
+{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
+{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
+};
+
+local const ct_data static_dtree[D_CODES] = {
+{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
+{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
+{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
+{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
+{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
+{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
+};
+
+const uch _dist_code[DIST_CODE_LEN] = {
+ 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
+ 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 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, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
+13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
+15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
+18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
+23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
+27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
+};
+
+const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
+13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
+17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
+19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
+26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
+};
+
+local const int base_length[LENGTH_CODES] = {
+0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
+64, 80, 96, 112, 128, 160, 192, 224, 0
+};
+
+local const int base_dist[D_CODES] = {
+ 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
+ 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
+ 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
+};
+
diff --git a/Utilities/cmzlib/uncompr.c b/Utilities/cmzlib/uncompr.c
new file mode 100644
index 0000000000..b59e3d0def
--- /dev/null
+++ b/Utilities/cmzlib/uncompr.c
@@ -0,0 +1,61 @@
+/* uncompr.c -- decompress a memory buffer
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+/* ===========================================================================
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be large enough to hold the
+ entire uncompressed data. (The size of the uncompressed data must have
+ been saved previously by the compressor and transmitted to the decompressor
+ by some mechanism outside the scope of this compression library.)
+ Upon exit, destLen is the actual size of the compressed buffer.
+ This function can be used to decompress a whole file at once if the
+ input file is mmap'ed.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted.
+*/
+int ZEXPORT uncompress (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+{
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+ /* Check for source > 64K on 16-bit machine: */
+ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
+
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+
+ err = inflateInit(&stream);
+ if (err != Z_OK) return err;
+
+ err = inflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ inflateEnd(&stream);
+ if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
+ return Z_DATA_ERROR;
+ return err;
+ }
+ *destLen = stream.total_out;
+
+ err = inflateEnd(&stream);
+ return err;
+}
diff --git a/Utilities/cmzlib/zconf.h b/Utilities/cmzlib/zconf.h
new file mode 100644
index 0000000000..7a3b6fdc1f
--- /dev/null
+++ b/Utilities/cmzlib/zconf.h
@@ -0,0 +1,351 @@
+/* zconf.h -- configuration of the zlib compression library
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#ifndef ZCONF_H
+#define ZCONF_H
+
+/* KITWARE_ZLIB_CHANGE - Added to mangle function names */
+#include "cm_zlib_mangle.h"
+
+/* KITWARE_ZLIB_CHANGE - Added to get the correct definition of ZLIB_DLL */
+#include "cmzlib/zlibDllConfig.h"
+
+/*
+ * If you *really* need a unique prefix for all types and library functions,
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
+ */
+#ifdef Z_PREFIX
+# define deflateInit_ z_deflateInit_
+# define deflate z_deflate
+# define deflateEnd z_deflateEnd
+# define inflateInit_ z_inflateInit_
+# define inflate z_inflate
+# define inflateEnd z_inflateEnd
+# define deflateInit2_ z_deflateInit2_
+# define deflateSetDictionary z_deflateSetDictionary
+# define deflateCopy z_deflateCopy
+# define deflateReset z_deflateReset
+# define deflateParams z_deflateParams
+# define deflateBound z_deflateBound
+# define deflatePrime z_deflatePrime
+# define inflateInit2_ z_inflateInit2_
+# define inflateSetDictionary z_inflateSetDictionary
+# define inflateSync z_inflateSync
+# define inflateSyncPoint z_inflateSyncPoint
+# define inflateCopy z_inflateCopy
+# define inflateReset z_inflateReset
+# define inflateBack z_inflateBack
+# define inflateBackEnd z_inflateBackEnd
+# define compress z_compress
+# define compress2 z_compress2
+# define compressBound z_compressBound
+# define uncompress z_uncompress
+# define adler32 z_adler32
+# define crc32 z_crc32
+# define get_crc_table z_get_crc_table
+# define zError z_zError
+
+# define alloc_func z_alloc_func
+# define free_func z_free_func
+# define in_func z_in_func
+# define out_func z_out_func
+# define Byte z_Byte
+# define uInt z_uInt
+# define uLong z_uLong
+# define Bytef z_Bytef
+# define charf z_charf
+# define intf z_intf
+# define uIntf z_uIntf
+# define uLongf z_uLongf
+# define voidpf z_voidpf
+# define voidp z_voidp
+#endif
+
+#if defined(__MSDOS__) && !defined(MSDOS)
+# define MSDOS
+#endif
+#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
+# define OS2
+#endif
+#if defined(_WINDOWS) && !defined(WINDOWS)
+# define WINDOWS
+#endif
+#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
+# ifndef WIN32
+# define WIN32
+# endif
+#endif
+#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
+# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
+# ifndef SYS16BIT
+# define SYS16BIT
+# endif
+# endif
+#endif
+
+/*
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
+ * than 64k bytes at a time (needed on systems with 16-bit int).
+ */
+#ifdef SYS16BIT
+# define MAXSEG_64K
+#endif
+#ifdef MSDOS
+# define UNALIGNED_OK
+#endif
+
+#ifdef __STDC_VERSION__
+# ifndef STDC
+# define STDC
+# endif
+# if __STDC_VERSION__ >= 199901L
+# ifndef STDC99
+# define STDC99
+# endif
+# endif
+#endif
+#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
+# define STDC
+#endif
+
+#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
+# define STDC
+#endif
+
+#ifndef STDC
+# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
+# define const /* note: need a more gentle solution here */
+# endif
+#endif
+
+/* Some Mac compilers merge all .h files incorrectly: */
+#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
+# define NO_DUMMY_DECL
+#endif
+
+/* Maximum value for memLevel in deflateInit2 */
+#ifndef MAX_MEM_LEVEL
+# ifdef MAXSEG_64K
+# define MAX_MEM_LEVEL 8
+# else
+# define MAX_MEM_LEVEL 9
+# endif
+#endif
+
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
+ * created by gzip. (Files created by minigzip can still be extracted by
+ * gzip.)
+ */
+#ifndef MAX_WBITS
+# define MAX_WBITS 15 /* 32K LZ77 window */
+#endif
+
+/* The memory requirements for deflate are (in bytes):
+ (1 << (windowBits+2)) + (1 << (memLevel+9))
+ that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
+ plus a few kilobytes for small objects. For example, if you want to reduce
+ the default memory requirements from 256K to 128K, compile with
+ make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
+ Of course this will generally degrade compression (there's no free lunch).
+
+ The memory requirements for inflate are (in bytes) 1 << windowBits
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ for small objects.
+*/
+
+ /* Type declarations */
+
+#ifndef OF /* function prototypes */
+# ifdef STDC
+# define OF(args) args
+# else
+# define OF(args) ()
+# endif
+#endif
+
+/* The following definitions for FAR are needed only for MSDOS mixed
+ * model programming (small or medium model with some far allocations).
+ * This was tested only with MSC; for other MSDOS compilers you may have
+ * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
+ * just define FAR to be empty.
+ */
+#ifdef SYS16BIT
+# if defined(M_I86SM) || defined(M_I86MM)
+ /* MSC small or medium model */
+# define SMALL_MEDIUM
+# ifdef _MSC_VER
+# define FAR _far
+# else
+# define FAR far
+# endif
+# endif
+# if (defined(__SMALL__) || defined(__MEDIUM__))
+ /* Turbo C small or medium model */
+# define SMALL_MEDIUM
+# ifdef __BORLANDC__
+# define FAR _far
+# else
+# define FAR far
+# endif
+# endif
+#endif
+
+#if defined(WINDOWS) || defined(WIN32)
+ /* If building or using zlib as a DLL, define ZLIB_DLL.
+ * This is not mandatory, but it offers a little performance increase.
+ */
+# ifdef ZLIB_DLL
+# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
+# ifdef ZLIB_INTERNAL
+# define ZEXTERN extern __declspec(dllexport)
+# else
+# define ZEXTERN extern __declspec(dllimport)
+# endif
+# endif
+# endif /* ZLIB_DLL */
+ /* If building or using zlib with the WINAPI/WINAPIV calling convention,
+ * define ZLIB_WINAPI.
+ * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
+ */
+# ifdef ZLIB_WINAPI
+# ifdef FAR
+# undef FAR
+# endif
+# include <windows.h>
+ /* No need for _export, use ZLIB.DEF instead. */
+ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
+# define ZEXPORT WINAPI
+# ifdef WIN32
+# define ZEXPORTVA WINAPIV
+# else
+# define ZEXPORTVA FAR CDECL
+# endif
+# endif
+#endif
+
+#if defined (__BEOS__)
+# ifdef ZLIB_DLL
+# ifdef ZLIB_INTERNAL
+# define ZEXPORT __declspec(dllexport)
+# define ZEXPORTVA __declspec(dllexport)
+# else
+# define ZEXPORT __declspec(dllimport)
+# define ZEXPORTVA __declspec(dllimport)
+# endif
+# endif
+#endif
+
+#ifndef ZEXTERN
+# define ZEXTERN extern
+#endif
+#ifndef ZEXPORT
+# define ZEXPORT
+#endif
+#ifndef ZEXPORTVA
+# define ZEXPORTVA
+#endif
+
+#ifndef FAR
+# define FAR
+#endif
+
+#if !defined(__MACTYPES__)
+typedef unsigned char Byte; /* 8 bits */
+#endif
+typedef unsigned int uInt; /* 16 bits or more */
+typedef unsigned long uLong; /* 32 bits or more */
+
+#ifdef SMALL_MEDIUM
+ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
+# define Bytef Byte FAR
+#else
+ typedef Byte FAR Bytef;
+#endif
+typedef char FAR charf;
+typedef int FAR intf;
+typedef uInt FAR uIntf;
+typedef uLong FAR uLongf;
+
+#ifdef STDC
+ typedef void const *voidpc;
+ typedef void FAR *voidpf;
+ typedef void *voidp;
+#else
+ typedef Byte const *voidpc;
+ typedef Byte FAR *voidpf;
+ typedef Byte *voidp;
+#endif
+
+/* KITWARE_ZLIB_CHANGE - Since VTK/ITK/CMake use CMake, not ./configure, we can go ahead and test HAVE_UNISTD_H */
+#ifdef HAVE_UNISTD_H
+# include <sys/types.h> /* for off_t */
+# include <unistd.h> /* for SEEK_* and off_t */
+# ifdef VMS
+# include <unixio.h> /* for off_t */
+# endif
+# define z_off_t off_t
+#endif
+#ifndef SEEK_SET
+# define SEEK_SET 0 /* Seek from beginning of file. */
+# define SEEK_CUR 1 /* Seek from current position. */
+# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
+#endif
+#ifndef z_off_t
+# define z_off_t long
+#endif
+
+#if defined(__OS400__)
+# define NO_vsnprintf
+#endif
+
+#if defined(__MVS__)
+# define NO_vsnprintf
+# ifdef FAR
+# undef FAR
+# endif
+#endif
+
+/* MVS linker does not support external names larger than 8 bytes */
+#if defined(__MVS__)
+# pragma map(deflateInit_,"DEIN")
+# pragma map(deflateInit2_,"DEIN2")
+# pragma map(deflateEnd,"DEEND")
+# pragma map(deflateBound,"DEBND")
+# pragma map(inflateInit_,"ININ")
+# pragma map(inflateInit2_,"ININ2")
+# pragma map(inflateEnd,"INEND")
+# pragma map(inflateSync,"INSY")
+# pragma map(inflateSetDictionary,"INSEDI")
+# pragma map(compressBound,"CMBND")
+# pragma map(inflate_table,"INTABL")
+# pragma map(inflate_fast,"INFA")
+# pragma map(inflate_copyright,"INCOPY")
+#endif
+
+/* KITWARE_ZLIB_CHANGE - Added to suppress complier warnings */
+#if defined(_MSC_VER)
+#pragma warning ( disable : 4127 ) /* cond expr is constant */
+#pragma warning ( disable : 4131 ) /* old style declaration */
+#pragma warning ( disable : 4244 ) /* conversion loss of data */
+#endif
+#if defined(__BORLANDC__)
+#pragma warn -8004 /* assigned a value that is never used */
+#pragma warn -8008 /* condition is always true */
+#pragma warn -8066 /* unreachable code */
+#endif
+
+#endif /* ZCONF_H */
diff --git a/Utilities/cmzlib/zlib.def b/Utilities/cmzlib/zlib.def
new file mode 100644
index 0000000000..e351899c82
--- /dev/null
+++ b/Utilities/cmzlib/zlib.def
@@ -0,0 +1,47 @@
+
+VERSION 1.23
+
+HEAPSIZE 1048576,4096
+
+EXPORTS
+ cm_zlib_adler32 @1
+ cm_zlib_compress @2
+ cm_zlib_crc32 @3
+ cm_zlib_deflate @4
+ cm_zlib_deflateCopy @5
+ cm_zlib_deflateEnd @6
+ cm_zlib_deflateInit2_ @7
+ cm_zlib_deflateInit_ @8
+ cm_zlib_deflateParams @9
+ cm_zlib_deflateReset @10
+ cm_zlib_deflateSetDictionary @11
+ cm_zlib_gzclose @12
+ cm_zlib_gzdopen @13
+ cm_zlib_gzerror @14
+ cm_zlib_gzflush @15
+ cm_zlib_gzopen @16
+ cm_zlib_gzread @17
+ cm_zlib_gzwrite @18
+ cm_zlib_inflate @19
+ cm_zlib_inflateEnd @20
+ cm_zlib_inflateInit2_ @21
+ cm_zlib_inflateInit_ @22
+ cm_zlib_inflateReset @23
+ cm_zlib_inflateSetDictionary @24
+ cm_zlib_inflateSync @25
+ cm_zlib_uncompress @26
+ cm_zlib_zlibVersion @27
+ cm_zlib_gzprintf @28
+ cm_zlib_gzputc @29
+ cm_zlib_gzgetc @30
+ cm_zlib_gzseek @31
+ cm_zlib_gzrewind @32
+ cm_zlib_gztell @33
+ cm_zlib_gzeof @34
+ cm_zlib_gzsetparams @35
+ cm_zlib_zError @36
+ cm_zlib_inflateSyncPoint @37
+ cm_zlib_get_crc_table @38
+ cm_zlib_compress2 @39
+ cm_zlib_gzputs @40
+ cm_zlib_gzgets @41
diff --git a/Utilities/cmzlib/zlib.h b/Utilities/cmzlib/zlib.h
new file mode 100644
index 0000000000..46e2db4908
--- /dev/null
+++ b/Utilities/cmzlib/zlib.h
@@ -0,0 +1,1357 @@
+/* zlib.h -- interface of the 'zlib' general purpose compression library
+ version 1.2.3, July 18th, 2005
+
+ Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+
+ The data format used by the zlib library is described by RFCs (Request for
+ Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
+ (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
+*/
+
+#ifndef ZLIB_H
+#define ZLIB_H
+
+#include "zconf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ZLIB_VERSION "1.2.3"
+#define ZLIB_VERNUM 0x1230
+
+/*
+ The 'zlib' compression library provides in-memory compression and
+ decompression functions, including integrity checks of the uncompressed
+ data. This version of the library supports only one compression method
+ (deflation) but other algorithms will be added later and will have the same
+ stream interface.
+
+ Compression can be done in a single step if the buffers are large
+ enough (for example if an input file is mmap'ed), or can be done by
+ repeated calls of the compression function. In the latter case, the
+ application must provide more input and/or consume the output
+ (providing more output space) before each call.
+
+ The compressed data format used by default by the in-memory functions is
+ the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
+ around a deflate stream, which is itself documented in RFC 1951.
+
+ The library also supports reading and writing files in gzip (.gz) format
+ with an interface similar to that of stdio using the functions that start
+ with "gz". The gzip format is different from the zlib format. gzip is a
+ gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
+
+ This library can optionally read and write gzip streams in memory as well.
+
+ The zlib format was designed to be compact and fast for use in memory
+ and on communications channels. The gzip format was designed for single-
+ file compression on file systems, has a larger header than zlib to maintain
+ directory information, and uses a different, slower check method than zlib.
+
+ The library does not install any signal handler. The decoder checks
+ the consistency of the compressed data, so the library should never
+ crash even in case of corrupted input.
+*/
+
+typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
+typedef void (*free_func) OF((voidpf opaque, voidpf address));
+
+struct internal_state;
+
+typedef struct z_stream_s {
+ Bytef *next_in; /* next input byte */
+ uInt avail_in; /* number of bytes available at next_in */
+ uLong total_in; /* total nb of input bytes read so far */
+
+ Bytef *next_out; /* next output byte should be put there */
+ uInt avail_out; /* remaining free space at next_out */
+ uLong total_out; /* total nb of bytes output so far */
+
+ char *msg; /* last error message, NULL if no error */
+ struct internal_state FAR *state; /* not visible by applications */
+
+ alloc_func zalloc; /* used to allocate the internal state */
+ free_func zfree; /* used to free the internal state */
+ voidpf opaque; /* private data object passed to zalloc and zfree */
+
+ int data_type; /* best guess about the data type: binary or text */
+ uLong adler; /* adler32 value of the uncompressed data */
+ uLong reserved; /* reserved for future use */
+} z_stream;
+
+typedef z_stream FAR *z_streamp;
+
+/*
+ gzip header information passed to and from zlib routines. See RFC 1952
+ for more details on the meanings of these fields.
+*/
+typedef struct gz_header_s {
+ int text; /* true if compressed data believed to be text */
+ uLong time; /* modification time */
+ int xflags; /* extra flags (not used when writing a gzip file) */
+ int os; /* operating system */
+ Bytef *extra; /* pointer to extra field or Z_NULL if none */
+ uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
+ uInt extra_max; /* space at extra (only when reading header) */
+ Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
+ uInt name_max; /* space at name (only when reading header) */
+ Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
+ uInt comm_max; /* space at comment (only when reading header) */
+ int hcrc; /* true if there was or will be a header crc */
+ int done; /* true when done reading gzip header (not used
+ when writing a gzip file) */
+} gz_header;
+
+typedef gz_header FAR *gz_headerp;
+
+/*
+ The application must update next_in and avail_in when avail_in has
+ dropped to zero. It must update next_out and avail_out when avail_out
+ has dropped to zero. The application must initialize zalloc, zfree and
+ opaque before calling the init function. All other fields are set by the
+ compression library and must not be updated by the application.
+
+ The opaque value provided by the application will be passed as the first
+ parameter for calls of zalloc and zfree. This can be useful for custom
+ memory management. The compression library attaches no meaning to the
+ opaque value.
+
+ zalloc must return Z_NULL if there is not enough memory for the object.
+ If zlib is used in a multi-threaded application, zalloc and zfree must be
+ thread safe.
+
+ On 16-bit systems, the functions zalloc and zfree must be able to allocate
+ exactly 65536 bytes, but will not be required to allocate more than this
+ if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
+ pointers returned by zalloc for objects of exactly 65536 bytes *must*
+ have their offset normalized to zero. The default allocation function
+ provided by this library ensures this (see zutil.c). To reduce memory
+ requirements and avoid any allocation of 64K objects, at the expense of
+ compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
+
+ The fields total_in and total_out can be used for statistics or
+ progress reports. After compression, total_in holds the total size of
+ the uncompressed data and may be saved for use in the decompressor
+ (particularly if the decompressor wants to decompress everything in
+ a single step).
+*/
+
+ /* constants */
+
+#define Z_NO_FLUSH 0
+#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
+#define Z_SYNC_FLUSH 2
+#define Z_FULL_FLUSH 3
+#define Z_FINISH 4
+#define Z_BLOCK 5
+/* Allowed flush values; see deflate() and inflate() below for details */
+
+#define Z_OK 0
+#define Z_STREAM_END 1
+#define Z_NEED_DICT 2
+#define Z_ERRNO (-1)
+#define Z_STREAM_ERROR (-2)
+#define Z_DATA_ERROR (-3)
+#define Z_MEM_ERROR (-4)
+#define Z_BUF_ERROR (-5)
+#define Z_VERSION_ERROR (-6)
+/* Return codes for the compression/decompression functions. Negative
+ * values are errors, positive values are used for special but normal events.
+ */
+
+#define Z_NO_COMPRESSION 0
+#define Z_BEST_SPEED 1
+#define Z_BEST_COMPRESSION 9
+#define Z_DEFAULT_COMPRESSION (-1)
+/* compression levels */
+
+#define Z_FILTERED 1
+#define Z_HUFFMAN_ONLY 2
+#define Z_RLE 3
+#define Z_FIXED 4
+#define Z_DEFAULT_STRATEGY 0
+/* compression strategy; see deflateInit2() below for details */
+
+#define Z_BINARY 0
+#define Z_TEXT 1
+#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
+#define Z_UNKNOWN 2
+/* Possible values of the data_type field (though see inflate()) */
+
+#define Z_DEFLATED 8
+/* The deflate compression method (the only one supported in this version) */
+
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
+
+#define zlib_version zlibVersion()
+/* for compatibility with versions < 1.0.2 */
+
+ /* basic functions */
+
+ZEXTERN const char * ZEXPORT zlibVersion OF((void));
+/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
+ If the first character differs, the library code actually used is
+ not compatible with the zlib.h header file used by the application.
+ This check is automatically made by deflateInit and inflateInit.
+ */
+
+/*
+ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
+
+ Initializes the internal stream state for compression. The fields
+ zalloc, zfree and opaque must be initialized before by the caller.
+ If zalloc and zfree are set to Z_NULL, deflateInit updates them to
+ use default allocation functions.
+
+ The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
+ 1 gives best speed, 9 gives best compression, 0 gives no compression at
+ all (the input data is simply copied a block at a time).
+ Z_DEFAULT_COMPRESSION requests a default compromise between speed and
+ compression (currently equivalent to level 6).
+
+ deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if level is not a valid compression level,
+ Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
+ with the version assumed by the caller (ZLIB_VERSION).
+ msg is set to null if there is no error message. deflateInit does not
+ perform any compression: this will be done by deflate().
+*/
+
+
+ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
+/*
+ deflate compresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce some
+ output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. deflate performs one or both of the
+ following actions:
+
+ - Compress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in and avail_in are updated and
+ processing will resume at this point for the next call of deflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. This action is forced if the parameter flush is non zero.
+ Forcing flush frequently degrades the compression ratio, so this parameter
+ should be set only when necessary (in interactive applications).
+ Some output may be provided even if flush is not set.
+
+ Before the call of deflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming
+ more output, and updating avail_in or avail_out accordingly; avail_out
+ should never be zero before the call. The application can consume the
+ compressed output when it wants, for example when the output buffer is full
+ (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
+ and with zero avail_out, it must be called again after making room in the
+ output buffer because there might be more output pending.
+
+ Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
+ decide how much data to accumualte before producing output, in order to
+ maximize compression.
+
+ If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
+ flushed to the output buffer and the output is aligned on a byte boundary, so
+ that the decompressor can get all input data available so far. (In particular
+ avail_in is zero after the call if enough output space has been provided
+ before the call.) Flushing may degrade compression for some compression
+ algorithms and so it should be used only when necessary.
+
+ If flush is set to Z_FULL_FLUSH, all output is flushed as with
+ Z_SYNC_FLUSH, and the compression state is reset so that decompression can
+ restart from this point if previous compressed data has been damaged or if
+ random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
+ compression.
+
+ If deflate returns with avail_out == 0, this function must be called again
+ with the same value of the flush parameter and more output space (updated
+ avail_out), until the flush is complete (deflate returns with non-zero
+ avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
+ avail_out is greater than six to avoid repeated flush markers due to
+ avail_out == 0 on return.
+
+ If the parameter flush is set to Z_FINISH, pending input is processed,
+ pending output is flushed and deflate returns with Z_STREAM_END if there
+ was enough output space; if deflate returns with Z_OK, this function must be
+ called again with Z_FINISH and more output space (updated avail_out) but no
+ more input data, until it returns with Z_STREAM_END or an error. After
+ deflate has returned Z_STREAM_END, the only possible operations on the
+ stream are deflateReset or deflateEnd.
+
+ Z_FINISH can be used immediately after deflateInit if all the compression
+ is to be done in a single step. In this case, avail_out must be at least
+ the value returned by deflateBound (see below). If deflate does not return
+ Z_STREAM_END, then it must be called again as described above.
+
+ deflate() sets strm->adler to the adler32 checksum of all input read
+ so far (that is, total_in bytes).
+
+ deflate() may update strm->data_type if it can make a good guess about
+ the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
+ binary. This field is only for information purposes and does not affect
+ the compression algorithm in any manner.
+
+ deflate() returns Z_OK if some progress has been made (more input
+ processed or more output produced), Z_STREAM_END if all input has been
+ consumed and all output has been produced (only when flush is set to
+ Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
+ if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
+ (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
+ fatal, and deflate() can be called again with more input and more output
+ space to continue compressing.
+*/
+
+
+ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any
+ pending output.
+
+ deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
+ stream state was inconsistent, Z_DATA_ERROR if the stream was freed
+ prematurely (some input or output was discarded). In the error case,
+ msg may be set but then points to a static string (which must not be
+ deallocated).
+*/
+
+
+/*
+ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
+
+ Initializes the internal stream state for decompression. The fields
+ next_in, avail_in, zalloc, zfree and opaque must be initialized before by
+ the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
+ value depends on the compression method), inflateInit determines the
+ compression method from the zlib header and allocates all data structures
+ accordingly; otherwise the allocation will be deferred to the first call of
+ inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
+ use default allocation functions.
+
+ inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
+ version assumed by the caller. msg is set to null if there is no error
+ message. inflateInit does not perform any decompression apart from reading
+ the zlib header if present: this will be done by inflate(). (So next_in and
+ avail_in may be modified, but next_out and avail_out are unchanged.)
+*/
+
+
+ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
+/*
+ inflate decompresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce
+ some output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. inflate performs one or both of the
+ following actions:
+
+ - Decompress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in is updated and processing
+ will resume at this point for the next call of inflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. inflate() provides as much output as possible, until there
+ is no more input data or no more space in the output buffer (see below
+ about the flush parameter).
+
+ Before the call of inflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming
+ more output, and updating the next_* and avail_* values accordingly.
+ The application can consume the uncompressed output when it wants, for
+ example when the output buffer is full (avail_out == 0), or after each
+ call of inflate(). If inflate returns Z_OK and with zero avail_out, it
+ must be called again after making room in the output buffer because there
+ might be more output pending.
+
+ The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
+ Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
+ output as possible to the output buffer. Z_BLOCK requests that inflate() stop
+ if and when it gets to the next deflate block boundary. When decoding the
+ zlib or gzip format, this will cause inflate() to return immediately after
+ the header and before the first block. When doing a raw inflate, inflate()
+ will go ahead and process the first block, and will return when it gets to
+ the end of that block, or when it runs out of data.
+
+ The Z_BLOCK option assists in appending to or combining deflate streams.
+ Also to assist in this, on return inflate() will set strm->data_type to the
+ number of unused bits in the last byte taken from strm->next_in, plus 64
+ if inflate() is currently decoding the last block in the deflate stream,
+ plus 128 if inflate() returned immediately after decoding an end-of-block
+ code or decoding the complete header up to just before the first byte of the
+ deflate stream. The end-of-block will not be indicated until all of the
+ uncompressed data from that block has been written to strm->next_out. The
+ number of unused bits may in general be greater than seven, except when
+ bit 7 of data_type is set, in which case the number of unused bits will be
+ less than eight.
+
+ inflate() should normally be called until it returns Z_STREAM_END or an
+ error. However if all decompression is to be performed in a single step
+ (a single call of inflate), the parameter flush should be set to
+ Z_FINISH. In this case all pending input is processed and all pending
+ output is flushed; avail_out must be large enough to hold all the
+ uncompressed data. (The size of the uncompressed data may have been saved
+ by the compressor for this purpose.) The next operation on this stream must
+ be inflateEnd to deallocate the decompression state. The use of Z_FINISH
+ is never required, but can be used to inform inflate that a faster approach
+ may be used for the single inflate() call.
+
+ In this implementation, inflate() always flushes as much output as
+ possible to the output buffer, and always uses the faster approach on the
+ first call. So the only effect of the flush parameter in this implementation
+ is on the return value of inflate(), as noted below, or when it returns early
+ because Z_BLOCK is used.
+
+ If a preset dictionary is needed after this call (see inflateSetDictionary
+ below), inflate sets strm->adler to the adler32 checksum of the dictionary
+ chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
+ strm->adler to the adler32 checksum of all output produced so far (that is,
+ total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
+ below. At the end of the stream, inflate() checks that its computed adler32
+ checksum is equal to that saved by the compressor and returns Z_STREAM_END
+ only if the checksum is correct.
+
+ inflate() will decompress and check either zlib-wrapped or gzip-wrapped
+ deflate data. The header type is detected automatically. Any information
+ contained in the gzip header is not retained, so applications that need that
+ information should instead use raw inflate, see inflateInit2() below, or
+ inflateBack() and perform their own processing of the gzip header and
+ trailer.
+
+ inflate() returns Z_OK if some progress has been made (more input processed
+ or more output produced), Z_STREAM_END if the end of the compressed data has
+ been reached and all uncompressed output has been produced, Z_NEED_DICT if a
+ preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
+ corrupted (input stream not conforming to the zlib format or incorrect check
+ value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
+ if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
+ Z_BUF_ERROR if no progress is possible or if there was not enough room in the
+ output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
+ inflate() can be called again with more input and more output space to
+ continue decompressing. If Z_DATA_ERROR is returned, the application may then
+ call inflateSync() to look for a good compression block if a partial recovery
+ of the data is desired.
+*/
+
+
+ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any
+ pending output.
+
+ inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
+ was inconsistent. In the error case, msg may be set but then points to a
+ static string (which must not be deallocated).
+*/
+
+ /* Advanced functions */
+
+/*
+ The following functions are needed only in some special applications.
+*/
+
+/*
+ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
+ int level,
+ int method,
+ int windowBits,
+ int memLevel,
+ int strategy));
+
+ This is another version of deflateInit with more compression options. The
+ fields next_in, zalloc, zfree and opaque must be initialized before by
+ the caller.
+
+ The method parameter is the compression method. It must be Z_DEFLATED in
+ this version of the library.
+
+ The windowBits parameter is the base two logarithm of the window size
+ (the size of the history buffer). It should be in the range 8..15 for this
+ version of the library. Larger values of this parameter result in better
+ compression at the expense of memory usage. The default value is 15 if
+ deflateInit is used instead.
+
+ windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
+ determines the window size. deflate() will then generate raw deflate data
+ with no zlib header or trailer, and will not compute an adler32 check value.
+
+ windowBits can also be greater than 15 for optional gzip encoding. Add
+ 16 to windowBits to write a simple gzip header and trailer around the
+ compressed data instead of a zlib wrapper. The gzip header will have no
+ file name, no extra data, no comment, no modification time (set to zero),
+ no header crc, and the operating system will be set to 255 (unknown). If a
+ gzip stream is being written, strm->adler is a crc32 instead of an adler32.
+
+ The memLevel parameter specifies how much memory should be allocated
+ for the internal compression state. memLevel=1 uses minimum memory but
+ is slow and reduces compression ratio; memLevel=9 uses maximum memory
+ for optimal speed. The default value is 8. See zconf.h for total memory
+ usage as a function of windowBits and memLevel.
+
+ The strategy parameter is used to tune the compression algorithm. Use the
+ value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
+ filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
+ string match), or Z_RLE to limit match distances to one (run-length
+ encoding). Filtered data consists mostly of small values with a somewhat
+ random distribution. In this case, the compression algorithm is tuned to
+ compress them better. The effect of Z_FILTERED is to force more Huffman
+ coding and less string matching; it is somewhat intermediate between
+ Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
+ Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
+ parameter only affects the compression ratio but not the correctness of the
+ compressed output even if it is not set appropriately. Z_FIXED prevents the
+ use of dynamic Huffman codes, allowing for a simpler decoder for special
+ applications.
+
+ deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
+ method). msg is set to null if there is no error message. deflateInit2 does
+ not perform any compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the compression dictionary from the given byte sequence
+ without producing any compressed output. This function must be called
+ immediately after deflateInit, deflateInit2 or deflateReset, before any
+ call of deflate. The compressor and decompressor must use exactly the same
+ dictionary (see inflateSetDictionary).
+
+ The dictionary should consist of strings (byte sequences) that are likely
+ to be encountered later in the data to be compressed, with the most commonly
+ used strings preferably put towards the end of the dictionary. Using a
+ dictionary is most useful when the data to be compressed is short and can be
+ predicted with good accuracy; the data can then be compressed better than
+ with the default empty dictionary.
+
+ Depending on the size of the compression data structures selected by
+ deflateInit or deflateInit2, a part of the dictionary may in effect be
+ discarded, for example if the dictionary is larger than the window size in
+ deflate or deflate2. Thus the strings most likely to be useful should be
+ put at the end of the dictionary, not at the front. In addition, the
+ current implementation of deflate will use at most the window size minus
+ 262 bytes of the provided dictionary.
+
+ Upon return of this function, strm->adler is set to the adler32 value
+ of the dictionary; the decompressor may later use this value to determine
+ which dictionary has been used by the compressor. (The adler32 value
+ applies to the whole dictionary even if only a subset of the dictionary is
+ actually used by the compressor.) If a raw deflate was requested, then the
+ adler32 value is not computed and strm->adler is not set.
+
+ deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
+ parameter is invalid (such as NULL dictionary) or the stream state is
+ inconsistent (for example if deflate has already been called for this stream
+ or if the compression method is bsort). deflateSetDictionary does not
+ perform any compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
+ z_streamp source));
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when several compression strategies will be
+ tried, for example when there are several ways of pre-processing the input
+ data with a filter. The streams that will be discarded should then be freed
+ by calling deflateEnd. Note that deflateCopy duplicates the internal
+ compression state which can be quite large, so this strategy is slow and
+ can consume lots of memory.
+
+ deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being NULL). msg is left unchanged in both source and
+ destination.
+*/
+
+ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to deflateEnd followed by deflateInit,
+ but does not free and reallocate all the internal compression state.
+ The stream will keep the same compression level and any other attributes
+ that may have been set by deflateInit2.
+
+ deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being NULL).
+*/
+
+ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
+ int level,
+ int strategy));
+/*
+ Dynamically update the compression level and compression strategy. The
+ interpretation of level and strategy is as in deflateInit2. This can be
+ used to switch between compression and straight copy of the input data, or
+ to switch to a different kind of input data requiring a different
+ strategy. If the compression level is changed, the input available so far
+ is compressed with the old level (and may be flushed); the new level will
+ take effect only at the next call of deflate().
+
+ Before the call of deflateParams, the stream state must be set as for
+ a call of deflate(), since the currently available input may have to
+ be compressed and flushed. In particular, strm->avail_out must be non-zero.
+
+ deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
+ stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
+ if strm->avail_out was zero.
+*/
+
+ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
+ int good_length,
+ int max_lazy,
+ int nice_length,
+ int max_chain));
+/*
+ Fine tune deflate's internal compression parameters. This should only be
+ used by someone who understands the algorithm used by zlib's deflate for
+ searching for the best matching string, and even then only by the most
+ fanatic optimizer trying to squeeze out the last compressed bit for their
+ specific input data. Read the deflate.c source code for the meaning of the
+ max_lazy, good_length, nice_length, and max_chain parameters.
+
+ deflateTune() can be called after deflateInit() or deflateInit2(), and
+ returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
+ */
+
+ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
+ uLong sourceLen));
+/*
+ deflateBound() returns an upper bound on the compressed size after
+ deflation of sourceLen bytes. It must be called after deflateInit()
+ or deflateInit2(). This would be used to allocate an output buffer
+ for deflation in a single pass, and so would be called before deflate().
+*/
+
+ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
+ int bits,
+ int value));
+/*
+ deflatePrime() inserts bits in the deflate output stream. The intent
+ is that this function is used to start off the deflate output with the
+ bits leftover from a previous deflate stream when appending to it. As such,
+ this function can only be used for raw deflate, and must be used before the
+ first deflate() call after a deflateInit2() or deflateReset(). bits must be
+ less than or equal to 16, and that many of the least significant bits of
+ value will be inserted in the output.
+
+ deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
+ gz_headerp head));
+/*
+ deflateSetHeader() provides gzip header information for when a gzip
+ stream is requested by deflateInit2(). deflateSetHeader() may be called
+ after deflateInit2() or deflateReset() and before the first call of
+ deflate(). The text, time, os, extra field, name, and comment information
+ in the provided gz_header structure are written to the gzip header (xflag is
+ ignored -- the extra flags are set according to the compression level). The
+ caller must assure that, if not Z_NULL, name and comment are terminated with
+ a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
+ available there. If hcrc is true, a gzip header crc is included. Note that
+ the current versions of the command-line version of gzip (up through version
+ 1.3.x) do not support header crc's, and will report that it is a "multi-part
+ gzip file" and give up.
+
+ If deflateSetHeader is not used, the default gzip header has text false,
+ the time set to zero, and os set to 255, with no extra, name, or comment
+ fields. The gzip header is returned to the default state by deflateReset().
+
+ deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+/*
+ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
+ int windowBits));
+
+ This is another version of inflateInit with an extra parameter. The
+ fields next_in, avail_in, zalloc, zfree and opaque must be initialized
+ before by the caller.
+
+ The windowBits parameter is the base two logarithm of the maximum window
+ size (the size of the history buffer). It should be in the range 8..15 for
+ this version of the library. The default value is 15 if inflateInit is used
+ instead. windowBits must be greater than or equal to the windowBits value
+ provided to deflateInit2() while compressing, or it must be equal to 15 if
+ deflateInit2() was not used. If a compressed stream with a larger window
+ size is given as input, inflate() will return with the error code
+ Z_DATA_ERROR instead of trying to allocate a larger window.
+
+ windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
+ determines the window size. inflate() will then process raw deflate data,
+ not looking for a zlib or gzip header, not generating a check value, and not
+ looking for any check values for comparison at the end of the stream. This
+ is for use with other formats that use the deflate compressed data format
+ such as zip. Those formats provide their own check values. If a custom
+ format is developed using the raw deflate format for compressed data, it is
+ recommended that a check value such as an adler32 or a crc32 be applied to
+ the uncompressed data as is done in the zlib, gzip, and zip formats. For
+ most applications, the zlib format should be used as is. Note that comments
+ above on the use in deflateInit2() applies to the magnitude of windowBits.
+
+ windowBits can also be greater than 15 for optional gzip decoding. Add
+ 32 to windowBits to enable zlib and gzip decoding with automatic header
+ detection, or add 16 to decode only the gzip format (the zlib format will
+ return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is
+ a crc32 instead of an adler32.
+
+ inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
+ is set to null if there is no error message. inflateInit2 does not perform
+ any decompression apart from reading the zlib header if present: this will
+ be done by inflate(). (So next_in and avail_in may be modified, but next_out
+ and avail_out are unchanged.)
+*/
+
+ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the decompression dictionary from the given uncompressed byte
+ sequence. This function must be called immediately after a call of inflate,
+ if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
+ can be determined from the adler32 value returned by that call of inflate.
+ The compressor and decompressor must use exactly the same dictionary (see
+ deflateSetDictionary). For raw inflate, this function can be called
+ immediately after inflateInit2() or inflateReset() and before any call of
+ inflate() to set the dictionary. The application must insure that the
+ dictionary that was used for compression is provided.
+
+ inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
+ parameter is invalid (such as NULL dictionary) or the stream state is
+ inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
+ expected one (incorrect adler32 value). inflateSetDictionary does not
+ perform any decompression: this will be done by subsequent calls of
+ inflate().
+*/
+
+ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
+/*
+ Skips invalid compressed data until a full flush point (see above the
+ description of deflate with Z_FULL_FLUSH) can be found, or until all
+ available input is skipped. No output is provided.
+
+ inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
+ if no more input was provided, Z_DATA_ERROR if no flush point has been found,
+ or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
+ case, the application may save the current current value of total_in which
+ indicates where valid compressed data was found. In the error case, the
+ application may repeatedly call inflateSync, providing more input each time,
+ until success or end of the input data.
+*/
+
+ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
+ z_streamp source));
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when randomly accessing a large stream. The
+ first pass through the stream can periodically record the inflate state,
+ allowing restarting inflate at those points when randomly accessing the
+ stream.
+
+ inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being NULL). msg is left unchanged in both source and
+ destination.
+*/
+
+ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to inflateEnd followed by inflateInit,
+ but does not free and reallocate all the internal decompression state.
+ The stream will keep attributes that may have been set by inflateInit2.
+
+ inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being NULL).
+*/
+
+ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
+ int bits,
+ int value));
+/*
+ This function inserts bits in the inflate input stream. The intent is
+ that this function is used to start inflating at a bit position in the
+ middle of a byte. The provided bits will be used before any bytes are used
+ from next_in. This function should only be used with raw inflate, and
+ should be used before the first inflate() call after inflateInit2() or
+ inflateReset(). bits must be less than or equal to 16, and that many of the
+ least significant bits of value will be inserted in the input.
+
+ inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
+ gz_headerp head));
+/*
+ inflateGetHeader() requests that gzip header information be stored in the
+ provided gz_header structure. inflateGetHeader() may be called after
+ inflateInit2() or inflateReset(), and before the first call of inflate().
+ As inflate() processes the gzip stream, head->done is zero until the header
+ is completed, at which time head->done is set to one. If a zlib stream is
+ being decoded, then head->done is set to -1 to indicate that there will be
+ no gzip header information forthcoming. Note that Z_BLOCK can be used to
+ force inflate() to return immediately after header processing is complete
+ and before any actual data is decompressed.
+
+ The text, time, xflags, and os fields are filled in with the gzip header
+ contents. hcrc is set to true if there is a header CRC. (The header CRC
+ was valid if done is set to one.) If extra is not Z_NULL, then extra_max
+ contains the maximum number of bytes to write to extra. Once done is true,
+ extra_len contains the actual extra field length, and extra contains the
+ extra field, or that field truncated if extra_max is less than extra_len.
+ If name is not Z_NULL, then up to name_max characters are written there,
+ terminated with a zero unless the length is greater than name_max. If
+ comment is not Z_NULL, then up to comm_max characters are written there,
+ terminated with a zero unless the length is greater than comm_max. When
+ any of extra, name, or comment are not Z_NULL and the respective field is
+ not present in the header, then that field is set to Z_NULL to signal its
+ absence. This allows the use of deflateSetHeader() with the returned
+ structure to duplicate the header. However if those fields are set to
+ allocated memory, then the application will need to save those pointers
+ elsewhere so that they can be eventually freed.
+
+ If inflateGetHeader is not used, then the header information is simply
+ discarded. The header is always checked for validity, including the header
+ CRC if present. inflateReset() will reset the process to discard the header
+ information. The application would need to call inflateGetHeader() again to
+ retrieve the header from the next gzip stream.
+
+ inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+/*
+ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
+ unsigned char FAR *window));
+
+ Initialize the internal stream state for decompression using inflateBack()
+ calls. The fields zalloc, zfree and opaque in strm must be initialized
+ before the call. If zalloc and zfree are Z_NULL, then the default library-
+ derived memory allocation routines are used. windowBits is the base two
+ logarithm of the window size, in the range 8..15. window is a caller
+ supplied buffer of that size. Except for special applications where it is
+ assured that deflate was used with small window sizes, windowBits must be 15
+ and a 32K byte window must be supplied to be able to decompress general
+ deflate streams.
+
+ See inflateBack() for the usage of these routines.
+
+ inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
+ the parameters are invalid, Z_MEM_ERROR if the internal state could not
+ be allocated, or Z_VERSION_ERROR if the version of the library does not
+ match the version of the header file.
+*/
+
+typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
+typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
+
+ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
+ in_func in, void FAR *in_desc,
+ out_func out, void FAR *out_desc));
+/*
+ inflateBack() does a raw inflate with a single call using a call-back
+ interface for input and output. This is more efficient than inflate() for
+ file i/o applications in that it avoids copying between the output and the
+ sliding window by simply making the window itself the output buffer. This
+ function trusts the application to not change the output buffer passed by
+ the output function, at least until inflateBack() returns.
+
+ inflateBackInit() must be called first to allocate the internal state
+ and to initialize the state with the user-provided window buffer.
+ inflateBack() may then be used multiple times to inflate a complete, raw
+ deflate stream with each call. inflateBackEnd() is then called to free
+ the allocated state.
+
+ A raw deflate stream is one with no zlib or gzip header or trailer.
+ This routine would normally be used in a utility that reads zip or gzip
+ files and writes out uncompressed files. The utility would decode the
+ header and process the trailer on its own, hence this routine expects
+ only the raw deflate stream to decompress. This is different from the
+ normal behavior of inflate(), which expects either a zlib or gzip header and
+ trailer around the deflate stream.
+
+ inflateBack() uses two subroutines supplied by the caller that are then
+ called by inflateBack() for input and output. inflateBack() calls those
+ routines until it reads a complete deflate stream and writes out all of the
+ uncompressed data, or until it encounters an error. The function's
+ parameters and return types are defined above in the in_func and out_func
+ typedefs. inflateBack() will call in(in_desc, &buf) which should return the
+ number of bytes of provided input, and a pointer to that input in buf. If
+ there is no input available, in() must return zero--buf is ignored in that
+ case--and inflateBack() will return a buffer error. inflateBack() will call
+ out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
+ should return zero on success, or non-zero on failure. If out() returns
+ non-zero, inflateBack() will return with an error. Neither in() nor out()
+ are permitted to change the contents of the window provided to
+ inflateBackInit(), which is also the buffer that out() uses to write from.
+ The length written by out() will be at most the window size. Any non-zero
+ amount of input may be provided by in().
+
+ For convenience, inflateBack() can be provided input on the first call by
+ setting strm->next_in and strm->avail_in. If that input is exhausted, then
+ in() will be called. Therefore strm->next_in must be initialized before
+ calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
+ immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
+ must also be initialized, and then if strm->avail_in is not zero, input will
+ initially be taken from strm->next_in[0 .. strm->avail_in - 1].
+
+ The in_desc and out_desc parameters of inflateBack() is passed as the
+ first parameter of in() and out() respectively when they are called. These
+ descriptors can be optionally used to pass any information that the caller-
+ supplied in() and out() functions need to do their job.
+
+ On return, inflateBack() will set strm->next_in and strm->avail_in to
+ pass back any unused input that was provided by the last in() call. The
+ return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
+ if in() or out() returned an error, Z_DATA_ERROR if there was a format
+ error in the deflate stream (in which case strm->msg is set to indicate the
+ nature of the error), or Z_STREAM_ERROR if the stream was not properly
+ initialized. In the case of Z_BUF_ERROR, an input or output error can be
+ distinguished using strm->next_in which will be Z_NULL only if in() returned
+ an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
+ out() returning non-zero. (in() will always be called before out(), so
+ strm->next_in is assured to be defined if out() returns non-zero.) Note
+ that inflateBack() cannot return Z_OK.
+*/
+
+ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
+/*
+ All memory allocated by inflateBackInit() is freed.
+
+ inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
+ state was inconsistent.
+*/
+
+ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
+/* Return flags indicating compile-time options.
+
+ Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
+ 1.0: size of uInt
+ 3.2: size of uLong
+ 5.4: size of voidpf (pointer)
+ 7.6: size of z_off_t
+
+ Compiler, assembler, and debug options:
+ 8: DEBUG
+ 9: ASMV or ASMINF -- use ASM code
+ 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
+ 11: 0 (reserved)
+
+ One-time table building (smaller code, but not thread-safe if true):
+ 12: BUILDFIXED -- build static block decoding tables when needed
+ 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
+ 14,15: 0 (reserved)
+
+ Library content (indicates missing functionality):
+ 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
+ deflate code when not needed)
+ 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
+ and decode gzip streams (to avoid linking crc code)
+ 18-19: 0 (reserved)
+
+ Operation variations (changes in library functionality):
+ 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
+ 21: FASTEST -- deflate algorithm with only one, lowest compression level
+ 22,23: 0 (reserved)
+
+ The sprintf variant used by gzprintf (zero is best):
+ 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
+ 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
+ 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
+
+ Remainder:
+ 27-31: 0 (reserved)
+ */
+
+
+ /* utility functions */
+
+/*
+ The following utility functions are implemented on top of the
+ basic stream-oriented functions. To simplify the interface, some
+ default options are assumed (compression level and memory usage,
+ standard memory allocation functions). The source code of these
+ utility functions can easily be modified if you need special options.
+*/
+
+ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Compresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be at least the value returned
+ by compressBound(sourceLen). Upon exit, destLen is the actual size of the
+ compressed buffer.
+ This function can be used to compress a whole file at once if the
+ input file is mmap'ed.
+ compress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer.
+*/
+
+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen,
+ int level));
+/*
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least the value returned by
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
+ compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+*/
+
+ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
+/*
+ compressBound() returns an upper bound on the compressed size after
+ compress() or compress2() on sourceLen bytes. It would be used before
+ a compress() or compress2() call to allocate the destination buffer.
+*/
+
+ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be large enough to hold the
+ entire uncompressed data. (The size of the uncompressed data must have
+ been saved previously by the compressor and transmitted to the decompressor
+ by some mechanism outside the scope of this compression library.)
+ Upon exit, destLen is the actual size of the compressed buffer.
+ This function can be used to decompress a whole file at once if the
+ input file is mmap'ed.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
+*/
+
+
+typedef voidp gzFile;
+
+ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
+/*
+ Opens a gzip (.gz) file for reading or writing. The mode parameter
+ is as in fopen ("rb" or "wb") but can also include a compression level
+ ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
+ Huffman only compression as in "wb1h", or 'R' for run-length encoding
+ as in "wb1R". (See the description of deflateInit2 for more information
+ about the strategy parameter.)
+
+ gzopen can be used to read a file which is not in gzip format; in this
+ case gzread will directly read from the file without decompression.
+
+ gzopen returns NULL if the file could not be opened or if there was
+ insufficient memory to allocate the (de)compression state; errno
+ can be checked to distinguish the two cases (if errno is zero, the
+ zlib error is Z_MEM_ERROR). */
+
+ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
+/*
+ gzdopen() associates a gzFile with the file descriptor fd. File
+ descriptors are obtained from calls like open, dup, creat, pipe or
+ fileno (in the file has been previously opened with fopen).
+ The mode parameter is as in gzopen.
+ The next call of gzclose on the returned gzFile will also close the
+ file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
+ descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
+ gzdopen returns NULL if there was insufficient memory to allocate
+ the (de)compression state.
+*/
+
+ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
+/*
+ Dynamically update the compression level or strategy. See the description
+ of deflateInit2 for the meaning of these parameters.
+ gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
+ opened for writing.
+*/
+
+ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
+/*
+ Reads the given number of uncompressed bytes from the compressed file.
+ If the input file was not in gzip format, gzread copies the given number
+ of bytes into the buffer.
+ gzread returns the number of uncompressed bytes actually read (0 for
+ end of file, -1 for error). */
+
+ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
+ voidpc buf, unsigned len));
+/*
+ Writes the given number of uncompressed bytes into the compressed file.
+ gzwrite returns the number of uncompressed bytes actually written
+ (0 in case of error).
+*/
+
+ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
+/*
+ Converts, formats, and writes the args to the compressed file under
+ control of the format string, as in fprintf. gzprintf returns the number of
+ uncompressed bytes actually written (0 in case of error). The number of
+ uncompressed bytes written is limited to 4095. The caller should assure that
+ this limit is not exceeded. If it is exceeded, then gzprintf() will return
+ return an error (0) with nothing written. In this case, there may also be a
+ buffer overflow with unpredictable consequences, which is possible only if
+ zlib was compiled with the insecure functions sprintf() or vsprintf()
+ because the secure snprintf() or vsnprintf() functions were not available.
+*/
+
+ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
+/*
+ Writes the given null-terminated string to the compressed file, excluding
+ the terminating null character.
+ gzputs returns the number of characters written, or -1 in case of error.
+*/
+
+ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
+/*
+ Reads bytes from the compressed file until len-1 characters are read, or
+ a newline character is read and transferred to buf, or an end-of-file
+ condition is encountered. The string is then terminated with a null
+ character.
+ gzgets returns buf, or Z_NULL in case of error.
+*/
+
+ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
+/*
+ Writes c, converted to an unsigned char, into the compressed file.
+ gzputc returns the value that was written, or -1 in case of error.
+*/
+
+ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
+/*
+ Reads one byte from the compressed file. gzgetc returns this byte
+ or -1 in case of end of file or error.
+*/
+
+ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
+/*
+ Push one character back onto the stream to be read again later.
+ Only one character of push-back is allowed. gzungetc() returns the
+ character pushed, or -1 on failure. gzungetc() will fail if a
+ character has been pushed but not read yet, or if c is -1. The pushed
+ character will be discarded if the stream is repositioned with gzseek()
+ or gzrewind().
+*/
+
+ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
+/*
+ Flushes all pending output into the compressed file. The parameter
+ flush is as in the deflate() function. The return value is the zlib
+ error number (see function gzerror below). gzflush returns Z_OK if
+ the flush parameter is Z_FINISH and all output could be flushed.
+ gzflush should be called only when strictly necessary because it can
+ degrade compression.
+*/
+
+ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
+ z_off_t offset, int whence));
+/*
+ Sets the starting position for the next gzread or gzwrite on the
+ given compressed file. The offset represents a number of bytes in the
+ uncompressed data stream. The whence parameter is defined as in lseek(2);
+ the value SEEK_END is not supported.
+ If the file is opened for reading, this function is emulated but can be
+ extremely slow. If the file is opened for writing, only forward seeks are
+ supported; gzseek then compresses a sequence of zeroes up to the new
+ starting position.
+
+ gzseek returns the resulting offset location as measured in bytes from
+ the beginning of the uncompressed stream, or -1 in case of error, in
+ particular if the file is opened for writing and the new starting position
+ would be before the current position.
+*/
+
+ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
+/*
+ Rewinds the given file. This function is supported only for reading.
+
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
+*/
+
+ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
+/*
+ Returns the starting position for the next gzread or gzwrite on the
+ given compressed file. This position represents a number of bytes in the
+ uncompressed data stream.
+
+ gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
+*/
+
+ZEXTERN int ZEXPORT gzeof OF((gzFile file));
+/*
+ Returns 1 when EOF has previously been detected reading the given
+ input stream, otherwise zero.
+*/
+
+ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
+/*
+ Returns 1 if file is being read directly without decompression, otherwise
+ zero.
+*/
+
+ZEXTERN int ZEXPORT gzclose OF((gzFile file));
+/*
+ Flushes all pending output if necessary, closes the compressed file
+ and deallocates all the (de)compression state. The return value is the zlib
+ error number (see function gzerror below).
+*/
+
+ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
+/*
+ Returns the error message for the last error which occurred on the
+ given compressed file. errnum is set to zlib error number. If an
+ error occurred in the file system and not in the compression library,
+ errnum is set to Z_ERRNO and the application may consult errno
+ to get the exact error code.
+*/
+
+ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
+/*
+ Clears the error and end-of-file flags for file. This is analogous to the
+ clearerr() function in stdio. This is useful for continuing to read a gzip
+ file that is being written concurrently.
+*/
+
+ /* checksum functions */
+
+/*
+ These functions are not related to compression but are exported
+ anyway because they might be useful in applications using the
+ compression library.
+*/
+
+ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
+/*
+ Update a running Adler-32 checksum with the bytes buf[0..len-1] and
+ return the updated checksum. If buf is NULL, this function returns
+ the required initial value for the checksum.
+ An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
+ much faster. Usage example:
+
+ uLong adler = adler32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ adler = adler32(adler, buffer, length);
+ }
+ if (adler != original_adler) error();
+*/
+
+ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
+ z_off_t len2));
+/*
+ Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
+ and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
+ each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
+ seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
+*/
+
+ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
+/*
+ Update a running CRC-32 with the bytes buf[0..len-1] and return the
+ updated CRC-32. If buf is NULL, this function returns the required initial
+ value for the for the crc. Pre- and post-conditioning (one's complement) is
+ performed within this function so it shouldn't be done by the application.
+ Usage example:
+
+ uLong crc = crc32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ crc = crc32(crc, buffer, length);
+ }
+ if (crc != original_crc) error();
+*/
+
+ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
+
+/*
+ Combine two CRC-32 check values into one. For two sequences of bytes,
+ seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
+ calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
+ check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
+ len2.
+*/
+
+
+ /* various hacks, don't look :) */
+
+/* deflateInit and inflateInit are macros to allow checking the zlib version
+ * and the compiler's view of z_stream:
+ */
+ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
+ int windowBits, int memLevel,
+ int strategy, const char *version,
+ int stream_size));
+ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
+ unsigned char FAR *window,
+ const char *version,
+ int stream_size));
+#define deflateInit(strm, level) \
+ deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
+#define inflateInit(strm) \
+ inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
+#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
+ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
+ (strategy), ZLIB_VERSION, sizeof(z_stream))
+#define inflateInit2(strm, windowBits) \
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
+#define inflateBackInit(strm, windowBits, window) \
+ inflateBackInit_((strm), (windowBits), (window), \
+ ZLIB_VERSION, sizeof(z_stream))
+
+
+#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
+ struct internal_state {int dummy;}; /* hack for buggy compilers */
+#endif
+
+ZEXTERN const char * ZEXPORT zError OF((int));
+ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
+ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ZLIB_H */
diff --git a/Utilities/cmzlib/zlib.rc b/Utilities/cmzlib/zlib.rc
new file mode 100644
index 0000000000..aabc59b681
--- /dev/null
+++ b/Utilities/cmzlib/zlib.rc
@@ -0,0 +1,32 @@
+#include <windows.h>
+
+#define IDR_VERSION1 1
+IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
+ FILEVERSION 1,2,3,0
+ PRODUCTVERSION 1,2,3,0
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+ FILEFLAGS 0
+ FILEOS VOS_DOS_WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0 // not used
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904E4"
+ //language ID = U.S. English, char set = Windows, Multilingual
+
+ BEGIN
+ VALUE "FileDescription", "zlib data compression library\0"
+ VALUE "FileVersion", "1.2.3\0"
+ VALUE "InternalName", "zlib\0"
+ VALUE "OriginalFilename", "zlib.dll\0"
+ VALUE "ProductName", "ZLib.DLL\0"
+ VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
+ VALUE "LegalCopyright", "(C) 1995-2005 Jean-loup Gailly & Mark Adler\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x0409, 1252
+ END
+END
diff --git a/Utilities/cmzlib/zlibDllConfig.h.in b/Utilities/cmzlib/zlibDllConfig.h.in
new file mode 100644
index 0000000000..3dceb8c5d1
--- /dev/null
+++ b/Utilities/cmzlib/zlibDllConfig.h.in
@@ -0,0 +1,6 @@
+#ifndef _zlibDllConfig_h
+#define _zlibDllConfig_h
+
+#cmakedefine ZLIB_DLL
+
+#endif
diff --git a/Utilities/cmzlib/zutil.c b/Utilities/cmzlib/zutil.c
new file mode 100644
index 0000000000..d55f5948a3
--- /dev/null
+++ b/Utilities/cmzlib/zutil.c
@@ -0,0 +1,318 @@
+/* zutil.c -- target dependent utility functions for the compression library
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#include "zutil.h"
+
+#ifndef NO_DUMMY_DECL
+struct internal_state {int dummy;}; /* for buggy compilers */
+#endif
+
+const char * const z_errmsg[10] = {
+"need dictionary", /* Z_NEED_DICT 2 */
+"stream end", /* Z_STREAM_END 1 */
+"", /* Z_OK 0 */
+"file error", /* Z_ERRNO (-1) */
+"stream error", /* Z_STREAM_ERROR (-2) */
+"data error", /* Z_DATA_ERROR (-3) */
+"insufficient memory", /* Z_MEM_ERROR (-4) */
+"buffer error", /* Z_BUF_ERROR (-5) */
+"incompatible version",/* Z_VERSION_ERROR (-6) */
+""};
+
+
+const char * ZEXPORT zlibVersion()
+{
+ return ZLIB_VERSION;
+}
+
+uLong ZEXPORT zlibCompileFlags()
+{
+ uLong flags;
+
+ flags = 0;
+ switch (sizeof(uInt)) {
+ case 2: break;
+ case 4: flags += 1; break;
+ case 8: flags += 2; break;
+ default: flags += 3;
+ }
+ switch (sizeof(uLong)) {
+ case 2: break;
+ case 4: flags += 1 << 2; break;
+ case 8: flags += 2 << 2; break;
+ default: flags += 3 << 2;
+ }
+ switch (sizeof(voidpf)) {
+ case 2: break;
+ case 4: flags += 1 << 4; break;
+ case 8: flags += 2 << 4; break;
+ default: flags += 3 << 4;
+ }
+ switch (sizeof(z_off_t)) {
+ case 2: break;
+ case 4: flags += 1 << 6; break;
+ case 8: flags += 2 << 6; break;
+ default: flags += 3 << 6;
+ }
+#ifdef DEBUG
+ flags += 1 << 8;
+#endif
+#if defined(ASMV) || defined(ASMINF)
+ flags += 1 << 9;
+#endif
+#ifdef ZLIB_WINAPI
+ flags += 1 << 10;
+#endif
+#ifdef BUILDFIXED
+ flags += 1 << 12;
+#endif
+#ifdef DYNAMIC_CRC_TABLE
+ flags += 1 << 13;
+#endif
+#ifdef NO_GZCOMPRESS
+ flags += 1L << 16;
+#endif
+#ifdef NO_GZIP
+ flags += 1L << 17;
+#endif
+#ifdef PKZIP_BUG_WORKAROUND
+ flags += 1L << 20;
+#endif
+#ifdef FASTEST
+ flags += 1L << 21;
+#endif
+#ifdef STDC
+# ifdef NO_vsnprintf
+ flags += 1L << 25;
+# ifdef HAS_vsprintf_void
+ flags += 1L << 26;
+# endif
+# else
+# ifdef HAS_vsnprintf_void
+ flags += 1L << 26;
+# endif
+# endif
+#else
+ flags += 1L << 24;
+# ifdef NO_snprintf
+ flags += 1L << 25;
+# ifdef HAS_sprintf_void
+ flags += 1L << 26;
+# endif
+# else
+# ifdef HAS_snprintf_void
+ flags += 1L << 26;
+# endif
+# endif
+#endif
+ return flags;
+}
+
+#ifdef DEBUG
+
+# ifndef verbose
+# define verbose 0
+# endif
+int z_verbose = verbose;
+
+void z_error (m)
+ char *m;
+{
+ fprintf(stderr, "%s\n", m);
+ exit(1);
+}
+#endif
+
+/* exported to allow conversion of error code to string for compress() and
+ * uncompress()
+ */
+const char * ZEXPORT zError(err)
+ int err;
+{
+ return ERR_MSG(err);
+}
+
+#if defined(_WIN32_WCE)
+ /* The Microsoft C Run-Time Library for Windows CE doesn't have
+ * errno. We define it as a global variable to simplify porting.
+ * Its value is always 0 and should not be used.
+ */
+ int errno = 0;
+#endif
+
+#ifndef HAVE_MEMCPY
+
+void zmemcpy(dest, source, len)
+ Bytef* dest;
+ const Bytef* source;
+ uInt len;
+{
+ if (len == 0) return;
+ do {
+ *dest++ = *source++; /* ??? to be unrolled */
+ } while (--len != 0);
+}
+
+int zmemcmp(s1, s2, len)
+ const Bytef* s1;
+ const Bytef* s2;
+ uInt len;
+{
+ uInt j;
+
+ for (j = 0; j < len; j++) {
+ if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
+ }
+ return 0;
+}
+
+void zmemzero(dest, len)
+ Bytef* dest;
+ uInt len;
+{
+ if (len == 0) return;
+ do {
+ *dest++ = 0; /* ??? to be unrolled */
+ } while (--len != 0);
+}
+#endif
+
+
+#ifdef SYS16BIT
+
+#ifdef __TURBOC__
+/* Turbo C in 16-bit mode */
+
+# define MY_ZCALLOC
+
+/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
+ * and farmalloc(64K) returns a pointer with an offset of 8, so we
+ * must fix the pointer. Warning: the pointer must be put back to its
+ * original form in order to free it, use zcfree().
+ */
+
+#define MAX_PTR 10
+/* 10*64K = 640K */
+
+local int next_ptr = 0;
+
+typedef struct ptr_table_s {
+ voidpf org_ptr;
+ voidpf new_ptr;
+} ptr_table;
+
+local ptr_table table[MAX_PTR];
+/* This table is used to remember the original form of pointers
+ * to large buffers (64K). Such pointers are normalized with a zero offset.
+ * Since MSDOS is not a preemptive multitasking OS, this table is not
+ * protected from concurrent access. This hack doesn't work anyway on
+ * a protected system like OS/2. Use Microsoft C instead.
+ */
+
+voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
+{
+ voidpf buf = opaque; /* just to make some compilers happy */
+ ulg bsize = (ulg)items*size;
+
+ /* If we allocate less than 65520 bytes, we assume that farmalloc
+ * will return a usable pointer which doesn't have to be normalized.
+ */
+ if (bsize < 65520L) {
+ buf = farmalloc(bsize);
+ if (*(ush*)&buf != 0) return buf;
+ } else {
+ buf = farmalloc(bsize + 16L);
+ }
+ if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
+ table[next_ptr].org_ptr = buf;
+
+ /* Normalize the pointer to seg:0 */
+ *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
+ *(ush*)&buf = 0;
+ table[next_ptr++].new_ptr = buf;
+ return buf;
+}
+
+void zcfree (voidpf opaque, voidpf ptr)
+{
+ int n;
+ if (*(ush*)&ptr != 0) { /* object < 64K */
+ farfree(ptr);
+ return;
+ }
+ /* Find the original pointer */
+ for (n = 0; n < next_ptr; n++) {
+ if (ptr != table[n].new_ptr) continue;
+
+ farfree(table[n].org_ptr);
+ while (++n < next_ptr) {
+ table[n-1] = table[n];
+ }
+ next_ptr--;
+ return;
+ }
+ ptr = opaque; /* just to make some compilers happy */
+ Assert(0, "zcfree: ptr not found");
+}
+
+#endif /* __TURBOC__ */
+
+
+#ifdef M_I86
+/* Microsoft C in 16-bit mode */
+
+# define MY_ZCALLOC
+
+#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
+# define _halloc halloc
+# define _hfree hfree
+#endif
+
+voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
+{
+ if (opaque) opaque = 0; /* to make compiler happy */
+ return _halloc((long)items, size);
+}
+
+void zcfree (voidpf opaque, voidpf ptr)
+{
+ if (opaque) opaque = 0; /* to make compiler happy */
+ _hfree(ptr);
+}
+
+#endif /* M_I86 */
+
+#endif /* SYS16BIT */
+
+
+#ifndef MY_ZCALLOC /* Any system without a special alloc function */
+
+#ifndef STDC
+extern voidp malloc OF((uInt size));
+extern voidp calloc OF((uInt items, uInt size));
+extern void free OF((voidpf ptr));
+#endif
+
+voidpf zcalloc (opaque, items, size)
+ voidpf opaque;
+ unsigned items;
+ unsigned size;
+{
+ if (opaque) items += size - size; /* make compiler happy */
+ return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
+ (voidpf)calloc(items, size);
+}
+
+void zcfree (opaque, ptr)
+ voidpf opaque;
+ voidpf ptr;
+{
+ free(ptr);
+ if (opaque) return; /* make compiler happy */
+}
+
+#endif /* MY_ZCALLOC */
diff --git a/Utilities/cmzlib/zutil.h b/Utilities/cmzlib/zutil.h
new file mode 100644
index 0000000000..3053cd8eea
--- /dev/null
+++ b/Utilities/cmzlib/zutil.h
@@ -0,0 +1,269 @@
+/* zutil.h -- internal interface and configuration of the compression library
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* @(#) $Id$ */
+
+#ifndef ZUTIL_H
+#define ZUTIL_H
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+#ifdef STDC
+# ifndef _WIN32_WCE
+# include <stddef.h>
+# endif
+# include <string.h>
+# include <stdlib.h>
+#endif
+#ifdef NO_ERRNO_H
+# ifdef _WIN32_WCE
+ /* The Microsoft C Run-Time Library for Windows CE doesn't have
+ * errno. We define it as a global variable to simplify porting.
+ * Its value is always 0 and should not be used. We rename it to
+ * avoid conflict with other libraries that use the same workaround.
+ */
+# define errno z_errno
+# endif
+ extern int errno;
+#else
+# ifndef _WIN32_WCE
+# include <errno.h>
+# endif
+#endif
+
+#ifndef local
+# define local static
+#endif
+/* compile with -Dlocal if your debugger can't find static symbols */
+
+typedef unsigned char uch;
+typedef uch FAR uchf;
+typedef unsigned short ush;
+typedef ush FAR ushf;
+typedef unsigned long ulg;
+
+extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
+/* (size given to avoid silly warnings with Visual C++) */
+
+#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
+
+#define ERR_RETURN(strm,err) \
+ return (strm->msg = (char*)ERR_MSG(err), (err))
+/* To be used only when the state is known to be valid */
+
+ /* common constants */
+
+#ifndef DEF_WBITS
+# define DEF_WBITS MAX_WBITS
+#endif
+/* default windowBits for decompression. MAX_WBITS is for compression only */
+
+#if MAX_MEM_LEVEL >= 8
+# define DEF_MEM_LEVEL 8
+#else
+# define DEF_MEM_LEVEL MAX_MEM_LEVEL
+#endif
+/* default memLevel */
+
+#define STORED_BLOCK 0
+#define STATIC_TREES 1
+#define DYN_TREES 2
+/* The three kinds of block type */
+
+#define MIN_MATCH 3
+#define MAX_MATCH 258
+/* The minimum and maximum match lengths */
+
+#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
+
+ /* target dependencies */
+
+#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
+# define OS_CODE 0x00
+# if defined(__TURBOC__) || defined(__BORLANDC__)
+# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
+ /* Allow compilation with ANSI keywords only enabled */
+ void _Cdecl farfree( void *block );
+ void *_Cdecl farmalloc( unsigned long nbytes );
+# else
+# include <alloc.h>
+# endif
+# else /* MSC or DJGPP */
+# include <malloc.h>
+# endif
+#endif
+
+#ifdef AMIGA
+# define OS_CODE 0x01
+#endif
+
+#if defined(VAXC) || defined(VMS)
+# define OS_CODE 0x02
+# define F_OPEN(name, mode) \
+ fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
+#endif
+
+#if defined(ATARI) || defined(atarist)
+# define OS_CODE 0x05
+#endif
+
+#ifdef OS2
+# define OS_CODE 0x06
+# ifdef M_I86
+ #include <malloc.h>
+# endif
+#endif
+
+#if defined(MACOS) || defined(TARGET_OS_MAC)
+# define OS_CODE 0x07
+# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+# include <unix.h> /* for fdopen */
+# else
+# ifndef fdopen
+# define fdopen(fd,mode) NULL /* No fdopen() */
+# endif
+# endif
+#endif
+
+#ifdef TOPS20
+# define OS_CODE 0x0a
+#endif
+
+#ifdef WIN32
+# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
+# define OS_CODE 0x0b
+# endif
+#endif
+
+#ifdef __50SERIES /* Prime/PRIMOS */
+# define OS_CODE 0x0f
+#endif
+
+#if defined(_BEOS_) || defined(RISCOS)
+# define fdopen(fd,mode) NULL /* No fdopen() */
+#endif
+
+#if (defined(_MSC_VER) && (_MSC_VER > 600))
+# if defined(_WIN32_WCE)
+# define fdopen(fd,mode) NULL /* No fdopen() */
+# ifndef _PTRDIFF_T_DEFINED
+ typedef int ptrdiff_t;
+# define _PTRDIFF_T_DEFINED
+# endif
+# else
+# define fdopen(fd,type) _fdopen(fd,type)
+# endif
+#endif
+
+ /* common defaults */
+
+#ifndef OS_CODE
+# define OS_CODE 0x03 /* assume Unix */
+#endif
+
+#ifndef F_OPEN
+# define F_OPEN(name, mode) fopen((name), (mode))
+#endif
+
+ /* functions */
+
+#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+#if defined(__CYGWIN__)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+#ifndef HAVE_VSNPRINTF
+# ifdef MSDOS
+ /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
+ but for now we just assume it doesn't. */
+# define NO_vsnprintf
+# endif
+# ifdef __TURBOC__
+# define NO_vsnprintf
+# endif
+# ifdef WIN32
+ /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
+# if !defined(vsnprintf) && !defined(NO_vsnprintf)
+# define vsnprintf _vsnprintf
+# endif
+# endif
+# ifdef __SASC
+# define NO_vsnprintf
+# endif
+#endif
+#ifdef VMS
+# define NO_vsnprintf
+#endif
+
+#if defined(pyr)
+# define NO_MEMCPY
+#endif
+#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
+ /* Use our own functions for small and medium model with MSC <= 5.0.
+ * You may have to use the same strategy for Borland C (untested).
+ * The __SC__ check is for Symantec.
+ */
+# define NO_MEMCPY
+#endif
+#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
+# define HAVE_MEMCPY
+#endif
+#ifdef HAVE_MEMCPY
+# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
+# define zmemcpy _fmemcpy
+# define zmemcmp _fmemcmp
+# define zmemzero(dest, len) _fmemset(dest, 0, len)
+# else
+# define zmemcpy memcpy
+# define zmemcmp memcmp
+# define zmemzero(dest, len) memset(dest, 0, len)
+# endif
+#else
+ extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
+ extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
+ extern void zmemzero OF((Bytef* dest, uInt len));
+#endif
+
+/* Diagnostic functions */
+#ifdef DEBUG
+# include <stdio.h>
+ extern int z_verbose;
+ extern void z_error OF((char *m));
+# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
+# define Trace(x) {if (z_verbose>=0) fprintf x ;}
+# define Tracev(x) {if (z_verbose>0) fprintf x ;}
+# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
+# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
+# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
+#else
+# define Assert(cond,msg)
+# define Trace(x)
+# define Tracev(x)
+# define Tracevv(x)
+# define Tracec(c,x)
+# define Tracecv(c,x)
+#endif
+
+
+voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
+void zcfree OF((voidpf opaque, voidpf ptr));
+
+#define ZALLOC(strm, items, size) \
+ (*((strm)->zalloc))((strm)->opaque, (items), (size))
+#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
+#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
+
+#endif /* ZUTIL_H */
diff --git a/bootstrap b/bootstrap
new file mode 100755
index 0000000000..b09023dbf0
--- /dev/null
+++ b/bootstrap
@@ -0,0 +1,1704 @@
+#!/bin/sh
+#=============================================================================
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2011 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.
+#=============================================================================
+
+die() {
+ echo "$@" 1>&2 ; exit 1
+}
+
+# Version number extraction function.
+cmake_version_component()
+{
+ cat "${cmake_source_dir}/Source/CMakeVersion.cmake" | sed -n "
+/^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;}
+"
+}
+
+# Install destination extraction function.
+cmake_install_dest_default()
+{
+ cat "${cmake_source_dir}/Source/CMakeInstallDestinations.cmake" | sed -n '
+/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT.*) # '"${2}"'$/ {
+ s/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT *"\([^"]*\)").*$/\1/
+ s/${CMake_VERSION_MAJOR}/'"${cmake_version_major}"'/
+ s/${CMake_VERSION_MINOR}/'"${cmake_version_minor}"'/
+ s/${CMake_VERSION_PATCH}/'"${cmake_version_patch}"'/
+ p
+ q
+}
+'
+}
+
+cmake_toupper()
+{
+ echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
+}
+
+# Detect system and directory information.
+cmake_system=`uname`
+cmake_source_dir=`cd "\`dirname \"$0\"\`";pwd`
+cmake_binary_dir=`pwd`
+
+# Load version information.
+cmake_version_major="`cmake_version_component MAJOR`"
+cmake_version_minor="`cmake_version_component MINOR`"
+cmake_version_patch="`cmake_version_component PATCH`"
+cmake_version="${cmake_version_major}.${cmake_version_minor}.${cmake_version_patch}"
+cmake_version_rc="`cmake_version_component RC`"
+if [ "$cmake_version_rc" != "" ]; then
+ cmake_version="${cmake_version}-rc${cmake_version_rc}"
+fi
+
+cmake_copyright="`grep '^Copyright .* Kitware' "${cmake_source_dir}/Copyright.txt"`"
+
+cmake_data_dir_keyword="OTHER"
+cmake_doc_dir_keyword="OTHER"
+cmake_man_dir_keyword="OTHER"
+cmake_data_dir=""
+cmake_doc_dir=""
+cmake_man_dir=""
+cmake_init_file=""
+cmake_bootstrap_system_libs=""
+cmake_bootstrap_qt_gui=""
+cmake_bootstrap_qt_qmake=""
+cmake_sphinx_man=""
+cmake_sphinx_html=""
+cmake_sphinx_build=""
+
+# Determine whether this is a Cygwin environment.
+if echo "${cmake_system}" | grep CYGWIN >/dev/null 2>&1; then
+ cmake_system_cygwin=true
+ cmake_doc_dir_keyword="CYGWIN"
+ cmake_man_dir_keyword="CYGWIN"
+else
+ cmake_system_cygwin=false
+fi
+
+# Determine whether this is a MinGW environment.
+if echo "${cmake_system}" | grep MINGW >/dev/null 2>&1; then
+ cmake_system_mingw=true
+else
+ cmake_system_mingw=false
+fi
+
+# Determine whether this is OS X
+if echo "${cmake_system}" | grep Darwin >/dev/null 2>&1; then
+ cmake_system_darwin=true
+else
+ cmake_system_darwin=false
+fi
+
+# Determine whether this is BeOS
+if echo "${cmake_system}" | grep BeOS >/dev/null 2>&1; then
+ cmake_system_beos=true
+ cmake_doc_dir_keyword="HAIKU"
+ cmake_man_dir_keyword="HAIKU"
+else
+ cmake_system_beos=false
+fi
+
+# Determine whether this is Haiku
+if echo "${cmake_system}" | grep Haiku >/dev/null 2>&1; then
+ cmake_system_haiku=true
+ cmake_doc_dir_keyword="HAIKU"
+ cmake_man_dir_keyword="HAIKU"
+else
+ cmake_system_haiku=false
+fi
+
+# Determine whether this is OpenVMS
+if echo "${cmake_system}" | grep OpenVMS >/dev/null 2>&1; then
+ cmake_system_openvms=true
+else
+ cmake_system_openvms=false
+fi
+
+# Determine whether this is Linux
+if echo "${cmake_system}" | grep Linux >/dev/null 2>&1; then
+ cmake_system_linux=true
+ # find out if it is a HP PA-RISC machine
+ if uname -m | grep parisc >/dev/null 2>&1; then
+ cmake_machine_parisc=true
+ else
+ cmake_machine_parisc=false
+ fi
+else
+ cmake_system_linux=false
+fi
+
+# Choose the generator to use for bootstrapping.
+if ${cmake_system_mingw}; then
+ # Bootstrapping from an MSYS prompt.
+ cmake_bootstrap_generator="MSYS Makefiles"
+else
+ # Bootstrapping from a standard UNIX prompt.
+ cmake_bootstrap_generator="Unix Makefiles"
+fi
+
+# Choose tools and extensions for this platform.
+if ${cmake_system_openvms}; then
+ _tmp="_tmp"
+ _cmk="_cmk"
+ _diff=`which diff`
+else
+ _tmp=".tmp"
+ _cmk=".cmk"
+ _diff="diff"
+fi
+
+# Construct bootstrap directory name.
+cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap${_cmk}"
+
+# Helper function to fix windows paths.
+case "${cmake_system}" in
+*MINGW*)
+ cmake_fix_slashes()
+ {
+ cmd //c echo "$(echo "$1" | sed 's/\\/\//g')" | sed 's/^"//;s/" *$//'
+ }
+ ;;
+*)
+ cmake_fix_slashes()
+ {
+ echo "$1" | sed 's/\\/\//g'
+ }
+ ;;
+esac
+
+# Choose the default install prefix.
+if ${cmake_system_mingw}; then
+ if [ "x${PROGRAMFILES}" != "x" ]; then
+ cmake_default_prefix=`cmake_fix_slashes "${PROGRAMFILES}/CMake"`
+ elif [ "x${ProgramFiles}" != "x" ]; then
+ cmake_default_prefix=`cmake_fix_slashes "${ProgramFiles}/CMake"`
+ elif [ "x${SYSTEMDRIVE}" != "x" ]; then
+ cmake_default_prefix=`cmake_fix_slashes "${SYSTEMDRIVE}/Program Files/CMake"`
+ elif [ "x${SystemDrive}" != "x" ]; then
+ cmake_default_prefix=`cmake_fix_slashes "${SystemDrive}/Program Files/CMake"`
+ else
+ cmake_default_prefix="c:/Program Files/CMake"
+ fi
+elif ${cmake_system_haiku}; then
+ cmake_default_prefix=`finddir B_COMMON_DIRECTORY`
+else
+ cmake_default_prefix="/usr/local"
+fi
+
+# Lookup default install destinations.
+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_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
+CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
+CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"
+
+CMAKE_PROBLEMATIC_FILES="\
+ CMakeCache.txt \
+ CMakeSystem.cmake \
+ CMakeCCompiler.cmake \
+ CMakeCXXCompiler.cmake \
+ */CMakeSystem.cmake \
+ */CMakeCCompiler.cmake \
+ */CMakeCXXCompiler.cmake \
+ Source/cmConfigure.h \
+ Source/CTest/Curl/config.h \
+ Utilities/cmexpat/expatConfig.h \
+ Utilities/cmexpat/expatDllConfig.h \
+ "
+
+CMAKE_UNUSED_SOURCES="\
+ cmGlobalXCodeGenerator \
+ cmLocalXCodeGenerator \
+ cmXCodeObject \
+ cmXCode21Object \
+ cmSourceGroup \
+"
+
+CMAKE_CXX_SOURCES="\
+ cmStandardIncludes \
+ cmake \
+ cmakemain \
+ cmcmd \
+ cmCommandArgumentLexer \
+ cmCommandArgumentParser \
+ cmCommandArgumentParserHelper \
+ cmCPackPropertiesGenerator \
+ cmDefinitions \
+ cmDepends \
+ cmDependsC \
+ cmDocumentationFormatter \
+ cmPolicies \
+ cmProperty \
+ cmPropertyMap \
+ cmPropertyDefinition \
+ cmPropertyDefinitionMap \
+ cmMakeDepend \
+ cmMakefile \
+ cmExportFileGenerator \
+ cmExportInstallFileGenerator \
+ cmExportTryCompileFileGenerator \
+ cmExportSet \
+ cmExportSetMap \
+ cmInstallDirectoryGenerator \
+ cmGeneratedFileStream \
+ cmGeneratorTarget \
+ cmGeneratorExpressionDAGChecker \
+ cmGeneratorExpressionEvaluator \
+ cmGeneratorExpressionLexer \
+ cmGeneratorExpressionParser \
+ cmGeneratorExpression \
+ cmGlobalGenerator \
+ cmLocalGenerator \
+ cmInstalledFile \
+ cmInstallGenerator \
+ cmInstallExportGenerator \
+ cmInstallFilesGenerator \
+ cmInstallScriptGenerator \
+ cmInstallTargetGenerator \
+ cmScriptGenerator \
+ cmSourceFile \
+ cmSourceFileLocation \
+ cmSystemTools \
+ cmTestGenerator \
+ cmVersion \
+ cmFileTimeComparison \
+ cmGlobalUnixMakefileGenerator3 \
+ cmLocalUnixMakefileGenerator3 \
+ cmMakefileExecutableTargetGenerator \
+ cmMakefileLibraryTargetGenerator \
+ cmMakefileTargetGenerator \
+ cmMakefileUtilityTargetGenerator \
+ cmOSXBundleGenerator \
+ cmNewLineStyle \
+ cmBootstrapCommands1 \
+ cmBootstrapCommands2 \
+ cmCommandsForBootstrap \
+ cmTarget \
+ cmTest \
+ cmCustomCommand \
+ cmCustomCommandGenerator \
+ cmCacheManager \
+ cmListFileCache \
+ cmComputeLinkDepends \
+ cmComputeLinkInformation \
+ cmOrderDirectories \
+ cmComputeTargetDepends \
+ cmComputeComponentGraph \
+ cmExprLexer \
+ cmExprParser \
+ cmExprParserHelper \
+ cmGlobalNinjaGenerator \
+ cmLocalNinjaGenerator \
+ cmNinjaTargetGenerator \
+ cmNinjaNormalTargetGenerator \
+ cmNinjaUtilityTargetGenerator \
+"
+
+if ${cmake_system_mingw}; then
+ CMAKE_CXX_SOURCES="${CMAKE_CXX_SOURCES}\
+ cmGlobalMSYSMakefileGenerator \
+ cmGlobalMinGWMakefileGenerator"
+fi
+
+CMAKE_C_SOURCES="\
+ cmListFileLexer \
+ "
+
+if ${cmake_system_mingw}; then
+ KWSYS_C_SOURCES="\
+ EncodingC \
+ ProcessWin32 \
+ String \
+ System"
+else
+ KWSYS_C_SOURCES="\
+ EncodingC \
+ ProcessUNIX \
+ String \
+ System"
+fi
+
+KWSYS_CXX_SOURCES="\
+ Directory \
+ EncodingCXX \
+ FStream \
+ Glob \
+ RegularExpression \
+ SystemTools"
+
+KWSYS_FILES="\
+ auto_ptr.hxx \
+ Directory.hxx \
+ Encoding.h \
+ Encoding.hxx \
+ FStream.hxx \
+ Glob.hxx \
+ Process.h \
+ RegularExpression.hxx \
+ String.h \
+ String.hxx \
+ System.h \
+ SystemTools.hxx"
+
+KWSYS_IOS_FILES="
+ fstream \
+ iosfwd \
+ iostream \
+ sstream"
+
+KWIML_FILES='
+ ABI.h
+ INT.h
+'
+
+# Display CMake bootstrap usage
+cmake_usage()
+{
+echo '
+Usage: '"$0"' [<options>...] [-- <cmake-options>...]
+Options: [defaults in brackets after descriptions]
+Configuration:
+ --help print this message
+ --version only print version information
+ --verbose display more information
+ --parallel=n bootstrap cmake in parallel, where n is
+ number of nodes [1]
+ --enable-ccache Enable ccache when building cmake
+ --init=FILE load FILE as script to populate cache
+ --system-libs use all system-installed third-party libraries
+ (for use only by package maintainers)
+ --no-system-libs use all cmake-provided third-party libraries
+ (default)
+ --system-curl use system-installed curl library
+ --no-system-curl use cmake-provided curl library (default)
+ --system-expat use system-installed expat library
+ --no-system-expat use cmake-provided expat library (default)
+ --system-zlib use system-installed zlib library
+ --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-libarchive use system-installed libarchive library
+ --no-system-libarchive use cmake-provided libarchive library (default)
+
+ --qt-gui build the Qt-based GUI (requires Qt >= 4.2)
+ --no-qt-gui do not build the Qt-based GUI (default)
+ --qt-qmake=<qmake> use <qmake> as the qmake executable to find Qt
+
+ --sphinx-man build man pages with Sphinx
+ --sphinx-html build html help with Sphinx
+ --sphinx-build=<sb> use <sb> as the sphinx-build executable
+
+Directory and file names:
+ --prefix=PREFIX install files in tree rooted at PREFIX
+ ['"${cmake_default_prefix}"']
+ --datadir=DIR install data files in PREFIX/DIR
+ ['"${cmake_data_dir_default}"']
+ --docdir=DIR install documentation files in PREFIX/DIR
+ ['"${cmake_doc_dir_default}"']
+ --mandir=DIR install man pages files in PREFIX/DIR/manN
+ ['"${cmake_man_dir_default}"']
+'
+ exit 10
+}
+
+# Display CMake bootstrap usage
+cmake_version_display()
+{
+ echo "CMake ${cmake_version}, ${cmake_copyright}"
+}
+
+# Display CMake bootstrap error, display the log file and exit
+cmake_error()
+{
+ res=$1
+ shift 1
+ echo "---------------------------------------------"
+ echo "Error when bootstrapping CMake:"
+ echo "$*"
+ echo "---------------------------------------------"
+ if [ -f cmake_bootstrap.log ]; then
+ echo "Log of errors: `pwd`/cmake_bootstrap.log"
+ #cat cmake_bootstrap.log
+ echo "---------------------------------------------"
+ fi
+ exit ${res}
+}
+
+# Replace KWSYS_NAMESPACE with cmsys
+cmake_replace_string ()
+{
+ INFILE="$1"
+ OUTFILE="$2"
+ SEARCHFOR="$3"
+ REPLACEWITH="$4"
+ if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
+ cat "${INFILE}" |
+ sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" > "${OUTFILE}${_tmp}"
+ if [ -f "${OUTFILE}${_tmp}" ]; then
+ if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
+ #echo "Files are the same"
+ rm -f "${OUTFILE}${_tmp}"
+ else
+ mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
+ fi
+ fi
+ else
+ cmake_error 1 "Cannot find file ${INFILE}"
+ fi
+}
+
+cmake_kwsys_config_replace_string ()
+{
+ INFILE="$1"
+ OUTFILE="$2"
+ shift 2
+ APPEND="$*"
+ if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
+ echo "${APPEND}" > "${OUTFILE}${_tmp}"
+ cat "${INFILE}" |
+ sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g;
+ s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g;
+ s/@KWSYS_LFS_AVAILABLE@/${KWSYS_LFS_AVAILABLE}/g;
+ s/@KWSYS_LFS_REQUESTED@/${KWSYS_LFS_REQUESTED}/g;
+ s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g;
+ s/@KWSYS_IOS_USE_ANSI@/${KWSYS_IOS_USE_ANSI}/g;
+ s/@KWSYS_IOS_HAVE_STD@/${KWSYS_IOS_HAVE_STD}/g;
+ s/@KWSYS_IOS_USE_SSTREAM@/${KWSYS_IOS_USE_SSTREAM}/g;
+ s/@KWSYS_IOS_USE_STRSTREAM_H@/${KWSYS_IOS_USE_STRSTREAM_H}/g;
+ s/@KWSYS_IOS_USE_STRSTREA_H@/${KWSYS_IOS_USE_STRSTREA_H}/g;
+ s/@KWSYS_IOS_HAVE_BINARY@/${KWSYS_IOS_HAVE_BINARY}/g;
+ s/@KWSYS_STL_HAVE_STD@/${KWSYS_STL_HAVE_STD}/g;
+ s/@KWSYS_STL_STRING_HAVE_ISTREAM@/${KWSYS_STL_STRING_HAVE_ISTREAM}/g;
+ s/@KWSYS_STL_STRING_HAVE_OSTREAM@/${KWSYS_STL_STRING_HAVE_OSTREAM}/g;
+ s/@KWSYS_STL_STRING_HAVE_NEQ_CHAR@/${KWSYS_STL_STRING_HAVE_NEQ_CHAR}/g;
+ s/@KWSYS_STL_HAS_ITERATOR_TRAITS@/${KWSYS_STL_HAS_ITERATOR_TRAITS}/g;
+ s/@KWSYS_STL_HAS_ITERATOR_CATEGORY@/${KWSYS_STL_HAS_ITERATOR_CATEGORY}/g;
+ s/@KWSYS_STL_HAS___ITERATOR_CATEGORY@/${KWSYS_STL_HAS___ITERATOR_CATEGORY}/g;
+ s/@KWSYS_STL_HAS_ALLOCATOR_TEMPLATE@/${KWSYS_STL_HAS_ALLOCATOR_TEMPLATE}/g;
+ s/@KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE@/${KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE}/g;
+ s/@KWSYS_STL_HAS_ALLOCATOR_REBIND@/${KWSYS_STL_HAS_ALLOCATOR_REBIND}/g;
+ s/@KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT@/${KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT}/g;
+ s/@KWSYS_STL_HAS_ALLOCATOR_OBJECTS@/${KWSYS_STL_HAS_ALLOCATOR_OBJECTS}/g;
+ s/@KWSYS_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g;
+ s/@KWSYS_CXX_HAS_CSTDDEF@/${KWSYS_CXX_HAS_CSTDDEF}/g;
+ s/@KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS@/${KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS}/g;
+ s/@KWSYS_CXX_HAS_MEMBER_TEMPLATES@/${KWSYS_CXX_HAS_MEMBER_TEMPLATES}/g;
+ s/@KWSYS_CXX_HAS_FULL_SPECIALIZATION@/${KWSYS_CXX_HAS_FULL_SPECIALIZATION}/g;
+ s/@KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP@/${KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP}/g;
+ s/@KWSYS_STAT_HAS_ST_MTIM@/${KWSYS_STAT_HAS_ST_MTIM}/g;}" >> "${OUTFILE}${_tmp}"
+ if [ -f "${OUTFILE}${_tmp}" ]; then
+ if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
+ #echo "Files are the same"
+ rm -f "${OUTFILE}${_tmp}"
+ else
+ mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
+ fi
+ fi
+ else
+ cmake_error 2 "Cannot find file ${INFILE}"
+ fi
+}
+# Write string into a file
+cmake_report ()
+{
+ FILE=$1
+ shift
+ echo "$*" >> ${FILE}
+}
+
+# Escape spaces in strings
+cmake_escape ()
+{
+ echo $1 | sed "s/ /\\\\ /g"
+}
+
+# Strip prefix from argument
+cmake_arg ()
+{
+ echo "$1" | sed "s/^${2-[^=]*=}//"
+}
+
+# Write message to the log
+cmake_log ()
+{
+ echo "$*" >> cmake_bootstrap.log
+}
+
+# Return temp file
+cmake_tmp_file ()
+{
+ echo "cmake_bootstrap_$$_test"
+}
+
+# Run a compiler test. First argument is compiler, second one are compiler
+# flags, third one is test source file to be compiled
+cmake_try_run ()
+{
+ COMPILER=$1
+ FLAGS=$2
+ TESTFILE=$3
+ if [ ! -f "${TESTFILE}" ]; then
+ echo "Test file ${TESTFILE} missing. Please verify your CMake source tree."
+ exit 4
+ fi
+ TMPFILE=`cmake_tmp_file`
+ echo "Try: ${COMPILER}"
+ echo "Line: ${COMPILER} ${FLAGS} ${TESTFILE} -o ${TMPFILE}"
+ echo "---------- file -----------------------"
+ cat "${TESTFILE}"
+ echo "------------------------------------------"
+ "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
+ RES=$?
+ if [ "${RES}" -ne "0" ]; then
+ echo "Test failed to compile"
+ return 1
+ fi
+ if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
+ echo "Test failed to produce executable"
+ return 2
+ fi
+ ./${TMPFILE}
+ RES=$?
+ rm -f "${TMPFILE}"
+ if [ "${RES}" -ne "0" ]; then
+ echo "Test produced non-zero return code"
+ return 3
+ fi
+ echo "Test succeded"
+ return 0
+}
+
+# Run a make test. First argument is the make interpreter.
+cmake_try_make ()
+{
+ MAKE_PROC="$1"
+ MAKE_FLAGS="$2"
+ echo "Try: ${MAKE_PROC}"
+ "${MAKE_PROC}" ${MAKE_FLAGS}
+ RES=$?
+ if [ "${RES}" -ne "0" ]; then
+ echo "${MAKE_PROC} does not work"
+ return 1
+ fi
+ if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
+ echo "${COMPILER} does not produce output"
+ return 2
+ fi
+ ./test
+ RES=$?
+ rm -f "test"
+ if [ "${RES}" -ne "0" ]; then
+ echo "${MAKE_PROC} produces strange executable"
+ return 3
+ fi
+ echo "${MAKE_PROC} works"
+ return 0
+}
+
+# Parse arguments
+cmake_verbose=
+cmake_parallel_make=
+cmake_ccache_enabled=
+cmake_prefix_dir="${cmake_default_prefix}"
+while test $# != 0; do
+ case "$1" in
+ --prefix=*) dir=`cmake_arg "$1"`
+ cmake_prefix_dir=`cmake_fix_slashes "$dir"` ;;
+ --parallel=*) cmake_parallel_make=`cmake_arg "$1"` ;;
+ --datadir=*) cmake_data_dir=`cmake_arg "$1"` ;;
+ --docdir=*) cmake_doc_dir=`cmake_arg "$1"` ;;
+ --mandir=*) cmake_man_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-libarchive|--system-zlib)
+ 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-libarchive|--no-system-zlib)
+ 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" ;;
+ --no-qt-gui) cmake_bootstrap_qt_gui="0" ;;
+ --qt-qmake=*) cmake_bootstrap_qt_qmake=`cmake_arg "$1"` ;;
+ --sphinx-man) cmake_sphinx_man="1" ;;
+ --sphinx-html) cmake_sphinx_html="1" ;;
+ --sphinx-build=*) cmake_sphinx_build=`cmake_arg "$1"` ;;
+ --help) cmake_usage ;;
+ --version) cmake_version_display ; exit 2 ;;
+ --verbose) cmake_verbose=TRUE ;;
+ --enable-ccache) cmake_ccache_enabled=TRUE ;;
+ --) shift; break ;;
+ *) die "Unknown option: $1" ;;
+ esac
+ shift
+done
+
+# If verbose, display some information about bootstrap
+if [ -n "${cmake_verbose}" ]; then
+ echo "---------------------------------------------"
+ echo "Source directory: ${cmake_source_dir}"
+ echo "Binary directory: ${cmake_binary_dir}"
+ echo "Prefix directory: ${cmake_prefix_dir}"
+ echo "System: ${cmake_system}"
+ if [ "x${cmake_parallel_make}" != "x" ]; then
+ echo "Doing parallel make: ${cmake_parallel_make}"
+ fi
+ echo ""
+fi
+
+echo "---------------------------------------------"
+# Get CMake version
+echo "`cmake_version_display`"
+
+# Check for in-source build
+cmake_in_source_build=
+if [ -f "${cmake_binary_dir}/Source/cmake.cxx" -a \
+ -f "${cmake_binary_dir}/Source/cmake.h" ]; then
+ if [ -n "${cmake_verbose}" ]; then
+ echo "Warning: This is an in-source build"
+ fi
+ cmake_in_source_build=TRUE
+fi
+
+# If this is not an in-source build, then Bootstrap stuff should not exist.
+if [ -z "${cmake_in_source_build}" ]; then
+ # Did somebody bootstrap in the source tree?
+ if [ -d "${cmake_source_dir}/Bootstrap${_cmk}" ]; then
+ cmake_error 10 "Found directory \"${cmake_source_dir}/Bootstrap${_cmk}\".
+Looks like somebody did bootstrap CMake in the source tree, but now you are
+trying to do bootstrap in the binary tree. Please remove Bootstrap${_cmk}
+directory from the source tree."
+ fi
+ # Is there a cache in the source tree?
+ for cmake_problematic_file in ${CMAKE_PROBLEMATIC_FILES}; do
+ if [ -f "${cmake_source_dir}/${cmake_problematic_file}" ]; then
+ cmake_error 10 "Found \"${cmake_source_dir}/${cmake_problematic_file}\".
+Looks like somebody tried to build CMake in the source tree, but now you are
+trying to do bootstrap in the binary tree. Please remove \"${cmake_problematic_file}\"
+from the source tree."
+ fi
+ done
+fi
+
+# Make bootstrap directory
+[ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
+if [ ! -d "${cmake_bootstrap_dir}" ]; then
+ cmake_error 3 "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
+fi
+cd "${cmake_bootstrap_dir}"
+
+[ -d "cmsys" ] || mkdir "cmsys"
+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}"
+rm -f "${cmake_bootstrap_dir}/cmVersionConfig.h${_tmp}"
+
+# If exist compiler flags, set them
+cmake_c_flags=${CFLAGS}
+cmake_cxx_flags=${CXXFLAGS}
+cmake_ld_flags=${LDFLAGS}
+
+# Add Cygwin-specific flags
+if ${cmake_system_cygwin}; then
+ cmake_ld_flags="${LDFLAGS} -Wl,--enable-auto-import"
+fi
+
+# Add CoreFoundation framework on Darwin
+if ${cmake_system_darwin}; then
+ cmake_ld_flags="${LDFLAGS} -framework CoreFoundation"
+fi
+
+# Add BeOS toolkits...
+if ${cmake_system_beos}; then
+ cmake_ld_flags="${LDFLAGS} -lroot -lbe"
+fi
+
+# Add Haiku toolkits...
+if ${cmake_system_haiku}; then
+ cmake_ld_flags="${LDFLAGS} -lroot -lbe"
+fi
+
+if ${cmake_system_linux}; then
+ # avoid binutils problem with large binaries, e.g. when building CMake in debug mode
+ # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50230
+ if ${cmake_machine_parisc}; then
+ cmake_ld_flags="${LDFLAGS} -Wl,--unique=.text._*"
+ fi
+fi
+
+#-----------------------------------------------------------------------------
+# Detect known toolchains on some platforms.
+cmake_toolchains=''
+case "${cmake_system}" in
+ *AIX*) cmake_toolchains='XL GNU' ;;
+ *CYGWIN*) cmake_toolchains='GNU' ;;
+ *Darwin*) cmake_toolchains='GNU Clang' ;;
+ *Linux*) cmake_toolchains='GNU Clang XL PGI PathScale' ;;
+ *MINGW*) cmake_toolchains='GNU' ;;
+esac
+
+# Toolchain compiler name table.
+cmake_toolchain_Clang_CC='clang'
+cmake_toolchain_Clang_CXX='clang++'
+cmake_toolchain_GNU_CC='gcc'
+cmake_toolchain_GNU_CXX='g++'
+cmake_toolchain_PGI_CC='pgcc'
+cmake_toolchain_PGI_CXX='pgCC'
+cmake_toolchain_PathScale_CC='pathcc'
+cmake_toolchain_PathScale_CXX='pathCC'
+cmake_toolchain_XL_CC='xlc'
+cmake_toolchain_XL_CXX='xlC'
+
+cmake_toolchain_try()
+{
+ tc="$1"
+ TMPFILE=`cmake_tmp_file`
+
+ eval "tc_CC=\${cmake_toolchain_${tc}_CC}"
+ echo 'int main() { return 0; }' > "${TMPFILE}.c"
+ cmake_try_run "$tc_CC" "" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1
+ tc_result_CC="$?"
+ rm -f "${TMPFILE}.c"
+ test "${tc_result_CC}" = "0" || return 1
+
+ eval "tc_CXX=\${cmake_toolchain_${tc}_CXX}"
+ echo 'int main() { return 0; }' > "${TMPFILE}.cpp"
+ cmake_try_run "$tc_CXX" "" "${TMPFILE}.cpp" >> cmake_bootstrap.log 2>&1
+ tc_result_CXX="$?"
+ rm -f "${TMPFILE}.cpp"
+ test "${tc_result_CXX}" = "0" || return 1
+
+ cmake_toolchain="$tc"
+}
+
+cmake_toolchain_detect()
+{
+ cmake_toolchain=
+ for tc in ${cmake_toolchains}; do
+ echo "Checking for $tc toolchain" >> cmake_bootstrap.log 2>&1
+ cmake_toolchain_try "$tc" &&
+ echo "Found $tc toolchain" &&
+ break
+ done
+}
+
+if [ -z "${CC}" -a -z "${CXX}" ]; then
+ cmake_toolchain_detect
+fi
+
+#-----------------------------------------------------------------------------
+# Test C compiler
+cmake_c_compiler=
+
+# If CC is set, use that for compiler, otherwise use list of known compilers
+if [ -n "${cmake_toolchain}" ]; then
+ eval cmake_c_compilers="\${cmake_toolchain_${cmake_toolchain}_CC}"
+elif [ -n "${CC}" ]; then
+ cmake_c_compilers="${CC}"
+else
+ cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
+fi
+
+# Check if C compiler works
+TMPFILE=`cmake_tmp_file`
+echo '
+#ifdef __cplusplus
+# error "The CMAKE_C_COMPILER is set to a C++ compiler"
+#endif
+
+#include<stdio.h>
+
+#if defined(__CLASSIC_C__)
+int main(argc, argv)
+ int argc;
+ char* argv[];
+#else
+int main(int argc, char* argv[])
+#endif
+{
+ printf("%d%c", (argv != 0), (char)0x0a);
+ return argc-1;
+}
+' > "${TMPFILE}.c"
+for a in ${cmake_c_compilers}; do
+ if [ -z "${cmake_c_compiler}" ] && \
+ cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
+ cmake_c_compiler="${a}"
+ fi
+done
+rm -f "${TMPFILE}.c"
+
+if [ -z "${cmake_c_compiler}" ]; then
+ cmake_error 6 "Cannot find appropriate C compiler on this system.
+Please specify one using environment variable CC.
+See cmake_bootstrap.log for compilers attempted.
+"
+fi
+echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"
+
+#-----------------------------------------------------------------------------
+# Test CXX compiler
+cmake_cxx_compiler=
+
+# On Mac OSX, CC is the same as cc, so make sure not to try CC as c++ compiler.
+
+# If CC is set, use that for compiler, otherwise use list of known compilers
+if [ -n "${cmake_toolchain}" ]; then
+ eval cmake_cxx_compilers="\${cmake_toolchain_${cmake_toolchain}_CXX}"
+elif [ -n "${CXX}" ]; then
+ cmake_cxx_compilers="${CXX}"
+else
+ cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
+fi
+
+# Check if C++ compiler works
+TMPFILE=`cmake_tmp_file`
+echo '
+#if defined(TEST1)
+# include <iostream>
+#else
+# include <iostream.h>
+#endif
+
+class NeedCXX
+{
+public:
+ NeedCXX() { this->Foo = 1; }
+ int GetFoo() { return this->Foo; }
+private:
+ int Foo;
+};
+int main()
+{
+ NeedCXX c;
+#ifdef TEST3
+ cout << c.GetFoo() << endl;
+#else
+ std::cout << c.GetFoo() << std::endl;
+#endif
+ return 0;
+}
+' > "${TMPFILE}.cxx"
+for a in ${cmake_cxx_compilers}; do
+ for b in 1 2 3; do
+ if [ -z "${cmake_cxx_compiler}" ] && \
+ cmake_try_run "${a}" "${cmake_cxx_flags} -DTEST${b}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
+ cmake_cxx_compiler="${a}"
+ fi
+ done
+done
+rm -f "${TMPFILE}.cxx"
+
+if [ -z "${cmake_cxx_compiler}" ]; then
+ cmake_error 7 "Cannot find appropriate C++ compiler on this system.
+Please specify one using environment variable CXX.
+See cmake_bootstrap.log for compilers attempted."
+fi
+echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
+
+#-----------------------------------------------------------------------------
+# Test Make
+
+cmake_make_processor=
+cmake_make_flags=
+
+# If MAKE is set, use that for make processor, otherwise use list of known make
+if [ -n "${MAKE}" ]; then
+ cmake_make_processors="${MAKE}"
+else
+ cmake_make_processors="${CMAKE_KNOWN_MAKE_PROCESSORS}"
+fi
+
+TMPFILE="`cmake_tmp_file`_dir"
+rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
+mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
+cd "${cmake_bootstrap_dir}/${TMPFILE}"
+echo '
+test: test.c
+ "'"${cmake_c_compiler}"'" '"${cmake_ld_flags} ${cmake_c_flags}"' -o test test.c
+'>"Makefile"
+echo '
+#include <stdio.h>
+int main(){ printf("1%c", (char)0x0a); return 0; }
+' > "test.c"
+cmake_original_make_flags="${cmake_make_flags}"
+if [ "x${cmake_parallel_make}" != "x" ]; then
+ cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
+fi
+for a in ${cmake_make_processors}; do
+ if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
+ cmake_make_processor="${a}"
+ fi
+done
+cmake_full_make_flags="${cmake_make_flags}"
+if [ "x${cmake_original_make_flags}" != "x${cmake_make_flags}" ]; then
+ if [ -z "${cmake_make_processor}" ]; then
+ cmake_make_flags="${cmake_original_make_flags}"
+ for a in ${cmake_make_processors}; do
+ if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
+ cmake_make_processor="${a}"
+ fi
+ done
+ fi
+fi
+cd "${cmake_bootstrap_dir}"
+
+if [ -z "${cmake_make_processor}" ]; then
+ cmake_error 8 "Cannot find appropriate Makefile processor on this system.
+Please specify one using environment variable MAKE."
+fi
+rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
+echo "Makefile processor on this system is: ${cmake_make_processor}"
+if [ "x${cmake_full_make_flags}" != "x${cmake_make_flags}" ]; then
+ echo "---------------------------------------------"
+ echo "Makefile processor ${cmake_make_processor} does not support parallel build"
+ echo "---------------------------------------------"
+fi
+
+# Ok, we have CC, CXX, and MAKE.
+
+# Test C++ compiler features
+
+# Are we GCC?
+
+TMPFILE=`cmake_tmp_file`
+echo '
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
+#include <iostream>
+int main() { std::cout << "This is GNU" << std::endl; return 0;}
+#endif
+' > ${TMPFILE}.cxx
+cmake_cxx_compiler_is_gnu=0
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
+ cmake_cxx_compiler_is_gnu=1
+fi
+if [ "x${cmake_cxx_compiler_is_gnu}" = "x1" ]; then
+ echo "${cmake_cxx_compiler} is GNU compiler"
+else
+ echo "${cmake_cxx_compiler} is not GNU compiler"
+fi
+rm -f "${TMPFILE}.cxx"
+
+if [ "x${cmake_cxx_compiler_is_gnu}" != "x1" ]; then
+ # Check for non-GNU compiler flags
+
+ # If we are on IRIX, check for -LANG:std
+ cmake_test_flags="-LANG:std"
+ if [ "x${cmake_system}" = "xIRIX64" ]; then
+ TMPFILE=`cmake_tmp_file`
+ echo '
+ #include <iostream>
+ int main() { std::cout << "No need for '"${cmake_test_flags}"'" << std::endl; return 0;}
+' > ${TMPFILE}.cxx
+ cmake_need_lang_std=0
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
+ :
+ else
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
+ cmake_need_lang_std=1
+ fi
+ fi
+ if [ "x${cmake_need_lang_std}" = "x1" ]; then
+ cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
+ echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
+ else
+ echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
+ fi
+ rm -f "${TMPFILE}.cxx"
+ fi
+ cmake_test_flags=
+
+ # If we are on OSF, check for -timplicit_local -no_implicit_include
+ cmake_test_flags="-timplicit_local -no_implicit_include"
+ if [ "x${cmake_system}" = "xOSF1" ]; then
+ TMPFILE=`cmake_tmp_file`
+ echo '
+ #include <iostream>
+ int main() { std::cout << "We need '"${cmake_test_flags}"'" << std::endl; return 0;}
+' > ${TMPFILE}.cxx
+ cmake_need_flags=1
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
+ :
+ else
+ cmake_need_flags=0
+ fi
+ if [ "x${cmake_need_flags}" = "x1" ]; then
+ cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
+ echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
+ else
+ echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
+ fi
+ rm -f "${TMPFILE}.cxx"
+ fi
+ cmake_test_flags=
+
+ # If we are on OSF, check for -std strict_ansi -nopure_cname
+ cmake_test_flags="-std strict_ansi -nopure_cname"
+ if [ "x${cmake_system}" = "xOSF1" ]; then
+ TMPFILE=`cmake_tmp_file`
+ echo '
+ #include <iostream>
+ int main() { std::cout << "We need '"${cmake_test_flags}"'" << std::endl; return 0;}
+' > ${TMPFILE}.cxx
+ cmake_need_flags=1
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
+ :
+ else
+ cmake_need_flags=0
+ fi
+ if [ "x${cmake_need_flags}" = "x1" ]; then
+ cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
+ echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
+ else
+ echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
+ fi
+ rm -f "${TMPFILE}.cxx"
+ fi
+ cmake_test_flags=
+
+ # If we are on HP-UX, check for -Ae for the C compiler.
+ if [ "x${cmake_system}" = "xHP-UX" ]; then
+ cmake_test_flags="-Ae"
+ TMPFILE=`cmake_tmp_file`
+ echo '
+ int main(int argc, char** argv) { (void)argc; (void)argv; return 0; }
+' > ${TMPFILE}.c
+ cmake_need_Ae=0
+ if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
+ :
+ else
+ if cmake_try_run "${cmake_c_compiler}" \
+ "${cmake_c_flags} ${cmake_test_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
+ cmake_need_Ae=1
+ fi
+ fi
+ if [ "x${cmake_need_Ae}" = "x1" ]; then
+ cmake_c_flags="${cmake_c_flags} ${cmake_test_flags}"
+ echo "${cmake_c_compiler} needs ${cmake_test_flags}"
+ else
+ echo "${cmake_c_compiler} does not need ${cmake_test_flags}"
+ fi
+ rm -f "${TMPFILE}.c"
+ echo '
+ #include <iostream>
+ int main(int argc, char** argv) {
+ for(int i=0; i < 1; ++i);
+ for(int i=0; i < 1; ++i);
+ (void)argc; (void)argv; return 0; }
+' > ${TMPFILE}.cxx
+ cmake_need_AAstd98=0
+ cmake_test_flags="-AA +hpxstd98"
+ if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
+ :
+ else
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
+ cmake_need_AAstd98=1
+ fi
+ fi
+ if [ "x${cmake_need_AAstd98}" = "x1" ]; then
+ cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
+ echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
+ else
+ echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
+ fi
+ fi
+ cmake_test_flags=
+fi
+
+# Test for kwsys features
+KWSYS_NAME_IS_KWSYS=0
+KWSYS_BUILD_SHARED=0
+KWSYS_LFS_AVAILABLE=0
+KWSYS_LFS_REQUESTED=0
+KWSYS_IOS_USE_STRSTREAM_H=0
+KWSYS_IOS_USE_STRSTREA_H=0
+KWSYS_IOS_HAVE_STD=0
+KWSYS_IOS_USE_SSTREAM=0
+KWSYS_IOS_USE_ANSI=0
+KWSYS_IOS_HAVE_BINARY=0
+KWSYS_STL_HAVE_STD=0
+KWSYS_STAT_HAS_ST_MTIM=0
+KWSYS_STL_STRING_HAVE_NEQ_CHAR=0
+KWSYS_STL_HAS_ITERATOR_TRAITS=0
+KWSYS_STL_HAS_ITERATOR_CATEGORY=0
+KWSYS_STL_HAS___ITERATOR_CATEGORY=0
+KWSYS_STL_HAS_ALLOCATOR_TEMPLATE=0
+KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE=0
+KWSYS_STL_HAS_ALLOCATOR_REBIND=0
+KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT=0
+KWSYS_STL_HAS_ALLOCATOR_OBJECTS=0
+KWSYS_STL_HAS_WSTRING=0
+KWSYS_CXX_HAS_SETENV=0
+KWSYS_CXX_HAS_UNSETENV=0
+KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=0
+KWSYS_CXX_HAS_UTIMENSAT=0
+KWSYS_CXX_HAS_UTIMES=0
+KWSYS_CXX_HAS_CSTDDEF=0
+KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS=0
+KWSYS_CXX_HAS_MEMBER_TEMPLATES=0
+KWSYS_CXX_HAS_FULL_SPECIALIZATION=0
+KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP=0
+
+# Hardcode these kwsys features. They work on all known UNIX compilers anyway.
+KWSYS_STL_STRING_HAVE_ISTREAM=1
+KWSYS_STL_STRING_HAVE_OSTREAM=1
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_SETENV" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_CXX_HAS_SETENV=1
+ echo "${cmake_cxx_compiler} has setenv"
+else
+ echo "${cmake_cxx_compiler} does not have setenv"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_UNSETENV" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_CXX_HAS_UNSETENV=1
+ echo "${cmake_cxx_compiler} has unsetenv"
+else
+ echo "${cmake_cxx_compiler} does not have unsetenv"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=1
+ echo "${cmake_cxx_compiler} has environ in stdlib.h"
+else
+ echo "${cmake_cxx_compiler} does not have environ in stdlib.h"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAVE_STD" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAVE_STD=1
+ echo "${cmake_cxx_compiler} has STL in std:: namespace"
+else
+ echo "${cmake_cxx_compiler} does not have STL in std:: namespace"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_ANSI" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_IOS_USE_ANSI=1
+ echo "${cmake_cxx_compiler} has ANSI streams"
+else
+ echo "${cmake_cxx_compiler} does not have ANSI streams"
+fi
+
+if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_IOS_HAVE_STD" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_IOS_HAVE_STD=1
+ echo "${cmake_cxx_compiler} has streams in std:: namespace"
+ else
+ echo "${cmake_cxx_compiler} does not have streams in std:: namespace"
+ fi
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_SSTREAM" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_IOS_USE_SSTREAM=1
+ echo "${cmake_cxx_compiler} has sstream"
+ else
+ echo "${cmake_cxx_compiler} does not have sstream"
+ fi
+fi
+
+if [ "x$KWSYS_IOS_USE_SSTREAM" = "x0" ]; then
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREAM_H" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_IOS_USE_STRSTREAM_H=1
+ echo "${cmake_cxx_compiler} has strstream.h"
+ else
+ echo "${cmake_cxx_compiler} does not have strstream.h"
+ fi
+ if [ "x$KWSYS_IOS_USE_STRSTREAM_H" = "x0" ]; then
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREA_H" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_IOS_USE_STRSTREA_H=1
+ echo "${cmake_cxx_compiler} has strstrea.h"
+ else
+ echo "${cmake_cxx_compiler} does not have strstrea.h"
+ fi
+ fi
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_STRING_HAVE_NEQ_CHAR -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_STRING_HAVE_NEQ_CHAR=1
+ echo "${cmake_cxx_compiler} has operator!=(string, char*)"
+else
+ echo "${cmake_cxx_compiler} does not have operator!=(string, char*)"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_ITERATOR_TRAITS -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAS_ITERATOR_TRAITS=1
+ echo "${cmake_cxx_compiler} has stl iterator_traits"
+else
+ echo "${cmake_cxx_compiler} does not have stl iterator_traits"
+fi
+
+if [ "x${KWSYS_STL_HAS_ITERATOR_TRAITS}" = "x0" ]; then
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_ITERATOR_CATEGORY -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAS_ITERATOR_CATEGORY=1
+ echo "${cmake_cxx_compiler} has old iterator_category"
+ else
+ echo "${cmake_cxx_compiler} does not have old iterator_category"
+ fi
+ if [ "x${KWSYS_STL_HAS_ITERATOR_CATEGORY}" = "x0" ]; then
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS___ITERATOR_CATEGORY -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAS___ITERATOR_CATEGORY=1
+ echo "${cmake_cxx_compiler} has old __iterator_category"
+ else
+ echo "${cmake_cxx_compiler} does not have old __iterator_category"
+ fi
+ fi
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_ALLOCATOR_TEMPLATE -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAS_ALLOCATOR_TEMPLATE=1
+ echo "${cmake_cxx_compiler} has standard template allocator"
+else
+ echo "${cmake_cxx_compiler} does not have standard template allocator"
+fi
+
+if [ "x${KWSYS_STL_HAS_ALLOCATOR_TEMPLATE}" = "x1" ]; then
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_ALLOCATOR_REBIND -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAS_ALLOCATOR_REBIND=1
+ echo "${cmake_cxx_compiler} has allocator<>::rebind<>"
+ else
+ echo "${cmake_cxx_compiler} does not have allocator<>::rebind<>"
+ fi
+
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT=1
+ echo "${cmake_cxx_compiler} has non-standard allocator<>::max_size argument"
+ else
+ echo "${cmake_cxx_compiler} does not have non-standard allocator<>::max_size argument"
+ fi
+else
+ if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE=1
+ echo "${cmake_cxx_compiler} has old non-template allocator"
+ else
+ echo "${cmake_cxx_compiler} does not have old non-template allocator"
+ fi
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_ALLOCATOR_OBJECTS -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAS_ALLOCATOR_OBJECTS=1
+ echo "${cmake_cxx_compiler} has stl containers supporting allocator objects"
+else
+ echo "${cmake_cxx_compiler} does not have stl containers supporting allocator objects"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_WSTRING -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_STL_HAS_WSTRING=1
+ echo "${cmake_cxx_compiler} has stl wstring"
+else
+ echo "${cmake_cxx_compiler} does not have stl wstring"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_CSTDDEF" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_CXX_HAS_CSTDDEF=1
+ echo "${cmake_cxx_compiler} has header cstddef"
+else
+ echo "${cmake_cxx_compiler} does not have header cstddef"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ echo "${cmake_cxx_compiler} does not require template friends to use <>"
+else
+ KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS=1
+ echo "${cmake_cxx_compiler} requires template friends to use <>"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_MEMBER_TEMPLATES" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_CXX_HAS_MEMBER_TEMPLATES=1
+ echo "${cmake_cxx_compiler} supports member templates"
+else
+ echo "${cmake_cxx_compiler} does not support member templates"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_FULL_SPECIALIZATION" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_CXX_HAS_FULL_SPECIALIZATION=1
+ echo "${cmake_cxx_compiler} has standard template specialization syntax"
+else
+ echo "${cmake_cxx_compiler} does not have standard template specialization syntax"
+fi
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP=1
+ echo "${cmake_cxx_compiler} has argument dependent lookup"
+else
+ echo "${cmake_cxx_compiler} does not have argument dependent lookup"
+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
+
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags} -DTEST_KWSYS_IOS_HAVE_BINARY -DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI} -DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD}" \
+ "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
+ KWSYS_IOS_HAVE_BINARY=1
+ echo "${cmake_cxx_compiler} has ios::binary openmode"
+else
+ echo "${cmake_cxx_compiler} does not have ios::binary openmode"
+fi
+
+# Just to be safe, let us store compiler and flags to the header file
+
+cmake_bootstrap_version='$Revision$'
+cmake_compiler_settings_comment="/*
+ * Generated by ${cmake_source_dir}/bootstrap
+ * Version: ${cmake_bootstrap_version}
+ *
+ * Source directory: ${cmake_source_dir}
+ * Binary directory: ${cmake_bootstrap_dir}
+ *
+ * C compiler: ${cmake_c_compiler}
+ * C flags: ${cmake_c_flags}
+ *
+ * C++ compiler: ${cmake_cxx_compiler}
+ * C++ flags: ${cmake_cxx_flags}
+ *
+ * Make: ${cmake_make_processor}
+ *
+ * Sources:
+ * ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES}
+ * kwSys Sources:
+ * ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}
+ */
+"
+
+cmake_report cmConfigure.h${_tmp} "${cmake_compiler_settings_comment}"
+
+if [ "x$KWSYS_STL_HAVE_STD" = "x1" ]; then
+ cmake_report cmConfigure.h${_tmp} "/* #undef CMAKE_NO_STD_NAMESPACE */"
+else
+ cmake_report cmConfigure.h${_tmp} "#define CMAKE_NO_STD_NAMESPACE 1"
+fi
+
+if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
+ cmake_report cmConfigure.h${_tmp} "/* #undef CMAKE_NO_ANSI_STREAM_HEADERS */"
+else
+ cmake_report cmConfigure.h${_tmp} "#define CMAKE_NO_ANSI_STREAM_HEADERS 1"
+fi
+
+if [ "x$KWSYS_IOS_USE_SSTREAM" = "x1" ]; then
+ cmake_report cmConfigure.h${_tmp} "/* #undef CMAKE_NO_ANSI_STRING_STREAM */"
+else
+ cmake_report cmConfigure.h${_tmp} "#define CMAKE_NO_ANSI_STRING_STREAM 1"
+fi
+
+# Test for ansi FOR scope
+if cmake_try_run "${cmake_cxx_compiler}" \
+ "${cmake_cxx_flags}" \
+ "${cmake_source_dir}/Modules/TestForAnsiForScope.cxx" >> cmake_bootstrap.log 2>&1; then
+ cmake_report cmConfigure.h${_tmp} "/* #undef CMAKE_NO_ANSI_FOR_SCOPE */"
+ echo "${cmake_cxx_compiler} has ANSI for scoping"
+else
+ cmake_report cmConfigure.h${_tmp} "#define CMAKE_NO_ANSI_FOR_SCOPE 1"
+ echo "${cmake_cxx_compiler} does not have ANSI for scoping"
+fi
+
+# When bootstrapping on MinGW with MSYS we must convert the source
+# directory to a windows path.
+if ${cmake_system_mingw}; then
+ CMAKE_BOOTSTRAP_SOURCE_DIR=`cd "${cmake_source_dir}"; pwd -W`
+ CMAKE_BOOTSTRAP_BINARY_DIR=`cd "${cmake_binary_dir}"; pwd -W`
+else
+ CMAKE_BOOTSTRAP_SOURCE_DIR="${cmake_source_dir}"
+ CMAKE_BOOTSTRAP_BINARY_DIR="${cmake_binary_dir}"
+fi
+
+# Write CMake version
+cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_MAJOR ${cmake_version_major}"
+cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_MINOR ${cmake_version_minor}"
+cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_PATCH ${cmake_version_patch}"
+cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION \"${cmake_version}\""
+cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP_SOURCE_DIR \"${CMAKE_BOOTSTRAP_SOURCE_DIR}\""
+cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP_BINARY_DIR \"${CMAKE_BOOTSTRAP_BINARY_DIR}\""
+cmake_report cmConfigure.h${_tmp} "#define CMAKE_DATA_DIR \"/bootstrap-not-insalled\""
+cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP"
+
+# Regenerate configured headers
+for h in Configure VersionConfig; do
+ if "${_diff}" cm${h}.h cm${h}.h${_tmp} > /dev/null 2> /dev/null; then
+ rm -f cm${h}.h${_tmp}
+ else
+ mv -f cm${h}.h${_tmp} cm${h}.h
+ fi
+done
+
+# Prepare KWSYS
+cmake_kwsys_config_replace_string \
+ "${cmake_source_dir}/Source/kwsys/Configure.hxx.in" \
+ "${cmake_bootstrap_dir}/cmsys/Configure.hxx" \
+ "${cmake_compiler_settings_comment}"
+cmake_kwsys_config_replace_string \
+ "${cmake_source_dir}/Source/kwsys/Configure.h.in" \
+ "${cmake_bootstrap_dir}/cmsys/Configure.h" \
+ "${cmake_compiler_settings_comment}"
+
+for a in ${KWSYS_FILES}; do
+ cmake_replace_string "${cmake_source_dir}/Source/kwsys/${a}.in" \
+ "${cmake_bootstrap_dir}/cmsys/${a}" KWSYS_NAMESPACE cmsys
+done
+
+for a in ${KWSYS_IOS_FILES}; do
+ cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_ios_${a}.h.in" \
+ "${cmake_bootstrap_dir}/cmsys/ios/${a}" KWSYS_NAMESPACE cmsys
+done
+
+cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_stl.hxx.in" \
+ "${cmake_bootstrap_dir}/cmsys/stl/stl.hxx_a" KWSYS_STL_HEADER_EXTRA ""
+
+cmake_replace_string "${cmake_bootstrap_dir}/cmsys/stl/stl.hxx_a" \
+ "${cmake_bootstrap_dir}/cmsys/stl/stl.hxx_b" KWSYS_NAMESPACE cmsys
+
+for a in string vector set map algorithm; do
+ cmake_replace_string "${cmake_bootstrap_dir}/cmsys/stl/stl.hxx_b" \
+ "${cmake_bootstrap_dir}/cmsys/stl/${a}" KWSYS_STL_HEADER ${a}
+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
+
+# Generate Makefile
+dep="cmConfigure.h cmsys/*.hxx cmsys/*.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
+objs=""
+for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
+ objs="${objs} ${a}.o"
+done
+
+# Generate dependencies for cmBootstrapCommands1.cxx
+for file in `grep "#include.*cm[^.]*.cxx" "${cmake_source_dir}/Source/cmBootstrapCommands1.cxx" | sed "s/.* \"\(.*\)\"/\1/"`; do
+ cmBootstrapCommands1Deps="${cmBootstrapCommands1Deps} `cmake_escape "${cmake_source_dir}/Source/$file"`"
+done
+cmBootstrapCommands1Deps=`echo $cmBootstrapCommands1Deps`
+for file in `grep "#include.*cm[^.]*.cxx" "${cmake_source_dir}/Source/cmBootstrapCommands2.cxx" | sed "s/.* \"\(.*\)\"/\1/"`; do
+ cmBootstrapCommands2Deps="${cmBootstrapCommands2Deps} `cmake_escape "${cmake_source_dir}/Source/$file"`"
+done
+cmBootstrapCommands2Deps=`echo $cmBootstrapCommands2Deps`
+
+if [ "x${cmake_ansi_cxx_flags}" != "x" ]; then
+ cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags}"
+fi
+
+if [ "x${cmake_c_flags}" != "x" ]; then
+ cmake_c_flags="${cmake_c_flags} "
+fi
+
+if [ "x${cmake_cxx_flags}" != "x" ]; then
+ cmake_cxx_flags="${cmake_cxx_flags} "
+fi
+
+cmake_c_flags_String="-DKWSYS_STRING_C"
+if ${cmake_system_mingw}; then
+ cmake_c_flags_EncodingC="-DKWSYS_ENCODING_DEFAULT_CODEPAGE=CP_ACP"
+fi
+cmake_cxx_flags_SystemTools="
+ -DKWSYS_CXX_HAS_SETENV=${KWSYS_CXX_HAS_SETENV}
+ -DKWSYS_CXX_HAS_UNSETENV=${KWSYS_CXX_HAS_UNSETENV}
+ -DKWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=${KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H}
+ -DKWSYS_CXX_HAS_UTIMENSAT=${KWSYS_CXX_HAS_UTIMENSAT}
+ -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}\"`"
+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}\"`"
+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
+ src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
+ echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
+ echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
+done
+echo "cmBootstrapCommands1.o : $cmBootstrapCommands1Deps" >> "${cmake_bootstrap_dir}/Makefile"
+echo "cmBootstrapCommands2.o : $cmBootstrapCommands2Deps" >> "${cmake_bootstrap_dir}/Makefile"
+for a in ${CMAKE_C_SOURCES}; do
+ src=`cmake_escape "${cmake_source_dir}/Source/${a}.c"`
+ echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
+ echo " ${cmake_c_compiler} ${cmake_c_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
+done
+for a in ${KWSYS_C_SOURCES}; do
+ src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.c"`
+ src_flags=`eval echo \\${cmake_c_flags_\${a}}`
+ echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
+ echo " ${cmake_c_compiler} ${cmake_c_flags} -DKWSYS_NAMESPACE=cmsys ${src_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
+done
+for a in ${KWSYS_CXX_SOURCES}; do
+ src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.cxx"`
+ src_flags=`eval echo \\${cmake_cxx_flags_\${a}}`
+ echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
+ echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -DKWSYS_NAMESPACE=cmsys ${src_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
+done
+echo '
+rebuild_cache:
+ cd "${cmake_binary_dir}" && "${cmake_source_dir}/bootstrap"
+' >> "${cmake_bootstrap_dir}/Makefile"
+
+# Write our default settings to Bootstrap${_cmk}/InitialCacheFlags.cmake.
+echo '
+# Generated by '"${cmake_source_dir}"'/bootstrap
+# Default cmake settings. These may be overridden any settings below.
+set (CMAKE_INSTALL_PREFIX "'"${cmake_prefix_dir}"'" CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
+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)
+' > "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
+
+# Add configuration settings given as command-line options.
+if [ "x${cmake_bootstrap_qt_gui}" != "x" ]; then
+ echo '
+set (BUILD_QtDialog '"${cmake_bootstrap_qt_gui}"' CACHE BOOL "Build Qt dialog for CMake" FORCE)
+' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
+fi
+if [ "x${cmake_bootstrap_qt_qmake}" != "x" ]; then
+ echo '
+set (QT_QMAKE_EXECUTABLE "'"${cmake_bootstrap_qt_qmake}"'" CACHE FILEPATH "Location of Qt qmake" FORCE)
+' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
+fi
+if [ "x${cmake_sphinx_man}" != "x" ]; then
+ echo '
+set (SPHINX_MAN "'"${cmake_sphinx_man}"'" CACHE FILEPATH "Build man pages with Sphinx" FORCE)
+' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
+fi
+if [ "x${cmake_sphinx_html}" != "x" ]; then
+ echo '
+set (SPHINX_HTML "'"${cmake_sphinx_html}"'" CACHE FILEPATH "Build html help with Sphinx" FORCE)
+' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
+fi
+if [ "x${cmake_sphinx_build}" != "x" ]; then
+ echo '
+set (SPHINX_EXECUTABLE "'"${cmake_sphinx_build}"'" CACHE FILEPATH "Location of Qt sphinx-build" FORCE)
+' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
+fi
+
+# Add user-specified settings. Handle relative-path case for
+# specification of cmake_init_file.
+(
+cd "${cmake_binary_dir}"
+if [ -f "${cmake_init_file}" ]; then
+ cat "${cmake_init_file}" >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
+fi
+)
+
+echo "---------------------------------------------"
+
+# Run make to build bootstrap cmake
+if [ "x${cmake_parallel_make}" != "x" ]; then
+ ${cmake_make_processor} ${cmake_make_flags}
+else
+ ${cmake_make_processor}
+fi
+RES=$?
+if [ "${RES}" -ne "0" ]; then
+ cmake_error 9 "Problem while running ${cmake_make_processor}"
+fi
+cd "${cmake_binary_dir}"
+
+# Set C, CXX, and MAKE environment variables, so that real real cmake will be
+# build with same compiler and make
+CC="${cmake_c_compiler}"
+CXX="${cmake_cxx_compiler}"
+if [ -n "${cmake_ccache_enabled}" ]; then
+ CC="ccache ${CC}"
+ CXX="ccache ${CXX}"
+fi
+MAKE="${cmake_make_processor}"
+export CC
+export CXX
+export MAKE
+
+# Run bootstrap CMake to configure real CMake
+cmake_options="-DCMAKE_BOOTSTRAP=1"
+if [ -n "${cmake_verbose}" ]; then
+ cmake_options="${cmake_options} -DCMAKE_VERBOSE_MAKEFILE=1"
+fi
+"${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}" "-C${cmake_bootstrap_dir}/InitialCacheFlags.cmake" "-G${cmake_bootstrap_generator}" ${cmake_options} ${cmake_bootstrap_system_libs} "$@"
+RES=$?
+if [ "${RES}" -ne "0" ]; then
+ cmake_error 11 "Problem while running initial CMake"
+fi
+
+echo "---------------------------------------------"
+
+# And we are done. Now just run make
+echo "CMake has bootstrapped. Now run ${cmake_make_processor}."
diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in
new file mode 100644
index 0000000000..d81f62a217
--- /dev/null
+++ b/cmake_uninstall.cmake.in
@@ -0,0 +1,22 @@
+if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+ message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
+endif()
+
+file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
+string(REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+ message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
+ if(EXISTS "$ENV{DESTDIR}${file}")
+ exec_program(
+ "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
+ OUTPUT_VARIABLE rm_out
+ RETURN_VALUE rm_retval
+ )
+ if("${rm_retval}" STREQUAL 0)
+ else()
+ message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
+ endif()
+ else()
+ message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
+ endif()
+endforeach()
diff --git a/configure b/configure
new file mode 100755
index 0000000000..116221602c
--- /dev/null
+++ b/configure
@@ -0,0 +1,3 @@
+#!/bin/sh
+cmake_source_dir=`cd "\`dirname \"$0\"\`";pwd`
+exec "${cmake_source_dir}/bootstrap" "$@"
diff --git a/doxygen.config b/doxygen.config
new file mode 100644
index 0000000000..82add731e6
--- /dev/null
+++ b/doxygen.config
@@ -0,0 +1,697 @@
+# Doxyfile 1.1.4-20000625
+
+# This file describes the settings to be used by doxygen for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+# TAG = value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# General configuration options
+#---------------------------------------------------------------------------
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
+# by quotes) that should identify the project.
+
+PROJECT_NAME = CMAKE
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER = 0.0.1
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = ./Doxygen
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Dutch, French, Italian, Czech, Swedish, German, Finnish, Japanese,
+# Spanish and Russian
+
+OUTPUT_LANGUAGE = English
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it.
+
+DISABLE_INDEX = NO
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC = YES
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSESS tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these class will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF = YES
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path.
+
+STRIP_FROM_PATH =
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS = NO
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a class diagram (in Html and LaTeX) for classes with base or
+# super classes. Setting the tag to NO turns the diagrams off.
+
+CLASS_DIAGRAMS = YES
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+
+SOURCE_BROWSER = YES
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the CASE_SENSE_NAMES tag is set to NO (the default) then Doxygen
+# will only generate file names in lower case letters. If set to
+# YES upper case letters are also allowed. This is useful if you have
+# classes or files whose names only differ in case and if your file system
+# supports case sensitive file names.
+
+CASE_SENSE_NAMES = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS = YES
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES (the default) then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the Javadoc-style will
+# behave just like the Qt-style comments.
+
+JAVADOC_AUTOBRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# reimplements.
+
+INHERIT_DOCS = YES
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS = YES
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE = 8
+
+# The ENABLE_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text.
+
+WARN_FORMAT = "$file:$line: $text"
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT = "Source"
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+FILE_PATTERNS = *.h *.txx *.cxx
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE =
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories.
+
+EXCLUDE_PATTERNS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS =
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output.
+
+INPUT_FILTER =
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX = YES
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX = 3
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT = html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet
+
+HTML_STYLESHEET =
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS = YES
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX = YES
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT = latex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, a4wide, letter, legal and
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS = NO
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# For now this is experimental and is disabled by default. The RTF output
+# is optimised for Word 97 and may not look too pretty with other readers
+# or editors.
+
+GENERATE_RTF = YES
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using a WORD or other.
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN = YES
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION = .3
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed.
+
+MACRO_EXPANSION = YES
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES = NO
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed.
+
+PREDEFINED = "itkNotUsed(x)="\
+ "itkSetMacro(name,type)= \
+ virtual void Set##name (type _arg);" \
+ "itkGetMacro(name,type)= \
+ virtual type Get##name ();" \
+ "itkGetConstMacro(name,type)= \
+ virtual type Get##name () const;" \
+ "itkSetStringMacro(name)= \
+ virtual void Set##name (const char* _arg);" \
+ "itkGetStringMacro(name)= \
+ virtual const char* Get##name () const;" \
+ "itkSetClampMacro(name,type,min,max)= \
+ virtual void Set##name (type _arg);" \
+ "itkSetObjectMacro(name,type)= \
+ virtual void Set##name (type* _arg);" \
+ "itkGetObjectMacro(name,type)= \
+ virtual type* Get##name ();" \
+ "itkBooleanMacro(name)= \
+ virtual void name##On (); \
+ virtual void name##Off ();" \
+ "itkSetVector2Macro(name,type)= \
+ virtual void Set##name (type _arg1, type _arg2) \
+ virtual void Set##name (type _arg[2]);" \
+ "itkGetVector2Macro(name,type)= \
+ virtual type* Get##name () const; \
+ virtual void Get##name (type& _arg1, type& _arg2) const; \
+ virtual void Get##name (type _arg[2]) const;" \
+ "itkSetVector3Macro(name,type)= \
+ virtual void Set##name (type _arg1, type _arg2, type _arg3) \
+ virtual void Set##name (type _arg[3]);" \
+ "itkGetVector3Macro(name,type)= \
+ virtual type* Get##name () const; \
+ virtual void Get##name (type& _arg1, type& _arg2, type& _arg3) const; \
+ virtual void Get##name (type _arg[3]) const;" \
+ "itkSetVector4Macro(name,type)= \
+ virtual void Set##name (type _arg1, type _arg2, type _arg3, type _arg4) \
+ virtual void Set##name (type _arg[4]);" \
+ "itkGetVector4Macro(name,type)= \
+ virtual type* Get##name () const; \
+ virtual void Get##name (type& _arg1, type& _arg2, type& _arg3, type& _arg4) const; \
+ virtual void Get##name (type _arg[4]) const;" \
+ "itkSetVector6Macro(name,type)= \
+ virtual void Set##name (type _arg1, type _arg2, type _arg3, type _arg4, type _arg5, type _arg6) \
+ virtual void Set##name (type _arg[6]);" \
+ "itkGetVector6Macro(name,type)= \
+ virtual type* Get##name () const; \
+ virtual void Get##name (type& _arg1, type& _arg2, type& _arg3, type& _arg4, type& _arg5, type& _arg6) const; \
+ virtual void Get##name (type _arg[6]) const;" \
+ "itkSetVectorMacro(name,type,count)= \
+ virtual void Set##name(type data[]);" \
+ "itkGetVectorMacro(name,type,count)= \
+ virtual type* Get##name () const;" \
+ "itkNewMacro(type)= \
+ static Pointer New();" \
+ "itkTypeMacro(thisClass,superclass)= \
+ virtual const char *GetClassName() const;" \
+ "ITK_NUMERIC_LIMITS= \
+ std::numeric_limits"
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED tag.
+
+EXPAND_ONLY_PREDEF = YES
+
+#---------------------------------------------------------------------------
+# Configuration::addtions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES tag can be used to specify one or more tagfiles.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS = NO
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT = YES
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH = YES
+
+# If the ENABLE_PREPROCESSING, INCLUDE_GRAPH, and HAVE_DOT tags are set to
+# YES then doxygen will generate a graph for each documented file showing
+# the direct and indirect include dependencies of the file with other
+# documented files.
+
+INCLUDE_GRAPH = YES
+
+# If the ENABLE_PREPROCESSING, INCLUDED_BY_GRAPH, and HAVE_DOT tags are set to
+# YES then doxygen will generate a graph for each documented header file showing
+# the documented files that directly or indirectly include this file
+
+INCLUDED_BY_GRAPH = YES
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY = YES
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found on the path.
+
+DOT_PATH =
+
+# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than
+# this value, doxygen will try to truncate the graph, so that it fits within
+# the specified constraint. Beware that most browsers cannot cope with very
+# large images.
+
+MAX_DOT_GRAPH_WIDTH = 1024
+
+# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than
+# this value, doxygen will try to truncate the graph, so that it fits within
+# the specified constraint. Beware that most browsers cannot cope with very
+# large images.
+
+MAX_DOT_GRAPH_HEIGHT = 1024
+
+#---------------------------------------------------------------------------
+# Configuration::addtions related to the search engine
+#---------------------------------------------------------------------------
+
+# The SEARCHENGINE tag specifies whether or not a search engine should be
+# used. If set to NO the values of all tags below this one will be ignored.
+
+SEARCHENGINE = NO
+
+# The CGI_NAME tag should be the name of the CGI script that
+# starts the search engine (doxysearch) with the correct parameters.
+# A script with this name will be generated by doxygen.
+
+CGI_NAME = search.cgi
+
+# The CGI_URL tag should be the absolute URL to the directory where the
+# cgi binaries are located. See the documentation of your http daemon for
+# details.
+
+CGI_URL =
+
+# The DOC_URL tag should be the absolute URL to the directory where the
+# documentation is located. If left blank the absolute path to the
+# documentation, with file:// prepended to it, will be used.
+
+DOC_URL =
+
+# The DOC_ABSPATH tag should be the absolute path to the directory where the
+# documentation is located. If left blank the directory on the local machine
+# will be used.
+
+DOC_ABSPATH =
+
+# The BIN_ABSPATH tag must point to the directory where the doxysearch binary
+# is installed.
+
+BIN_ABSPATH = /usr/local/bin/
+
+# The EXT_DOC_PATHS tag can be used to specify one or more paths to
+# documentation generated for other projects. This allows doxysearch to search
+# the documentation for these projects as well.
+
+EXT_DOC_PATHS =